This commit is contained in:
rizrmd 2024-05-19 16:00:04 +07:00
parent 572e1b3cc8
commit 649802aa66
17 changed files with 196 additions and 202 deletions

View File

@ -46,9 +46,8 @@ export const _ = {
`\
import React from "react";
import {
FC as ReactFC,
ReactNode as RNode,
ReactElement as RElement,
ReactNode,
ReactElement,
} from "react";
import * as prisma from "./prisma";
${iftext(

File diff suppressed because one or more lines are too long

View File

@ -29,21 +29,26 @@ export const initTypings = async (
const typings_file = Bun.file(typings_path);
if (!(await typings_file.exists())) {
return false;
await Bun.write(typings_file, "");
}
const typings_log = Bun.file(
dir.data(`/code/${id_site}/site/src/typings.log`)
);
await Bun.write(typings_log, "");
code.internal.typings[id_site] = {
timeout: Date.now(),
watch: watch(typings_path),
spawn: Bun.spawn({
cmd: [
...`${dir.path(
"node_modules/tsc"
"node_modules/.bin/tsc"
)} --watch --moduleResolution node --emitDeclarationOnly --outFile ../typings.d.ts --declaration --noEmit false`.split(
" "
),
],
cwd: dir.data(`/code/${id_site}/site/src`),
stdio: ["ignore", "ignore", "ignore"],
stdio: [typings_log, typings_log, "ignore"],
}),
};
let timeout = null as any;

View File

@ -0,0 +1,4 @@
*.log
node_modules
lib
typings

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,9 @@
import type { OnMount } from "@monaco-editor/react";
import trim from "lodash.trim";
import {
MonacoJsxSyntaxHighlight,
getWorker,
} from "monaco-jsx-syntax-highlight-v2";
// import {
// MonacoJsxSyntaxHighlight,
// getWorker,
// } from "monaco-jsx-syntax-highlight-v2";
import { PG, active } from "../../nova/ed/logic/ed-global";
import { jscript } from "./jscript";
@ -16,28 +16,28 @@ type CompilerOptions = Parameters<
export const jsMount = async (editor: MonacoEditor, monaco: Monaco, p?: PG) => {
const m = monaco as any;
if (editor.getModel()) {
const jsxHgController = new MonacoJsxSyntaxHighlight(getWorker(), monaco);
const { highlighter } = jsxHgController.highlighterBuilder({
editor: editor,
});
// if (editor.getModel()) {
// const jsxHgController = new MonacoJsxSyntaxHighlight(getWorker(), monaco);
// const { highlighter } = jsxHgController.highlighterBuilder({
// editor: editor,
// });
if (typeof editor.getModel === "function") {
highlighter();
}
editor.onDidChangeModelContent(() => {
if (typeof editor.getModel === "function") {
try {
highlighter();
} catch (e) {}
}
});
}
if (!m.customJSMounted) {
m.customJSMounted = true;
} else {
return;
}
// if (typeof editor.getModel === "function") {
// highlighter();
// }
// editor.onDidChangeModelContent(() => {
// if (typeof editor.getModel === "function") {
// try {
// highlighter();
// } catch (e) {}
// }
// });
// }
// if (!m.customJSMounted) {
// m.customJSMounted = true;
// } else {
// return;
// }
const compilerOptions: CompilerOptions = {
jsx: monaco.languages.typescript.JsxEmit.ReactJSX,

View File

@ -1,10 +1,10 @@
export const baseTypings = `
type FC<T> = ReactFC<T>;
type FC<T> = React.FC<T>;
const Fragment: typeof React.Fragment;
const ReactNode: RNode;
const ReactNode: typeo React.ReactNode;
const useCallback: typeof React.useCallback;
const useMemo: typeof React.useMemo;
const ReactElement: RElement;
const ReactElement: typeof React.ReactElement;
const isValidElement: typeof React.isValidElement;
const useEffect: typeof React.useEffect;
const useState: typeof React.useState;
@ -45,7 +45,7 @@ export const baseTypings = `
className: string
}
};
const children: RElement;
const children: ReactElement;
type IItem = {
id: string;
@ -101,7 +101,7 @@ export const baseTypings = `
const _item: undefined | PrasiItem;
const PassProp: (arg:Record<string, any> & { children: RNode }>) => RElement;
const PassProp: (arg:Record<string, any> & { children: ReactNode }>) => ReactElement;
const mobile: {
notif: {
register: (user_id: string) => void;
@ -140,5 +140,5 @@ export const baseTypings = `
local: T & { render: () => void }
) => void | (() => void) | Promise<void | (() => void)>;
cache?: boolean;
}) => RElement
}) => ReactElement
`;

View File

@ -111,46 +111,18 @@ declare module "ts:prisma_ext" {
monaco.languages.typescript.typescriptDefaults.setExtraLibs([
{
filePath: "jsx-runtime.d.ts",
content: `declare module "react/jsx-runtime" {
import * as React from "react";
export { Fragment } from "react";
export namespace JSX {
type ElementType = React.JSX.ElementType;
interface Element extends React.JSX.Element {}
interface ElementClass extends React.JSX.ElementClass {}
interface ElementAttributesProperty extends React.JSX.ElementAttributesProperty {}
interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {}
type LibraryManagedAttributes<C, P> = React.JSX.LibraryManagedAttributes<C, P>;
interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {}
interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {}
interface IntrinsicElements extends React.JSX.IntrinsicElements {}
}
/**
* Create a React element.
*
* You should not use this function directly. Use JSX and a transpiler instead.
*/
export function jsx(
type: React.ElementType,
props: unknown,
key?: React.Key,
): React.ReactElement;
/**
* Create a React element.
*
* You should not use this function directly. Use JSX and a transpiler instead.
*/
export function jsxs(
type: React.ElementType,
props: unknown,
key?: React.Key,
): React.ReactElement;
}
`,
filePath: "csstype.d.ts",
content: `declare module "csstype" {
${await loadText("https://cdn.jsdelivr.net/npm/csstype@3.1.3/index.d.ts")}
}`,
},
{
filePath: "prop-types.d.ts",
content: `declare module "prop-types" {
${await loadText(
"https://cdn.jsdelivr.net/npm/@types/prop-types@15.7.12/index.d.ts"
)}
}`,
},
{
filePath: "react.d.ts",
@ -158,6 +130,39 @@ export function jsxs(
${await loadText("https://cdn.jsdelivr.net/npm/@types/react@18.3.1/index.d.ts")}
}`,
},
{
filePath: "jsx-runtime.d.ts",
content: `declare module "react/jsx-runtime" {
import * as React from "react";
export { Fragment } from "react";
export namespace JSX {
type ElementType = React.JSX.ElementType;
}
/**
* Create a React element.
*
* You should not use this function directly. Use JSX and a transpiler instead.
*/
export function jsx(
type: React.ElementType,
props: unknown,
key?: React.Key,
): React.ReactElement;
/**
* Create a React element.
*
* You should not use this function directly. Use JSX and a transpiler instead.
*/
export function jsxs(
type: React.ElementType,
props: unknown,
key?: React.Key,
): React.ReactElement;
`,
},
]);
const propText = extractProp({
@ -177,12 +182,7 @@ ${await loadText("https://cdn.jsdelivr.net/npm/@types/react@18.3.1/index.d.ts")}
register(
monaco,
`\
import React from "react";
import {
FC as ReactFC,
ReactNode as RNode,
ReactElement as RElement,
} from "react";
import * as React from "react";
import prisma from 'ts:prisma';
import { PrismaExtend } from "ts:prisma_ext"
@ -210,7 +210,7 @@ declare global {
}
`,
"ts:global.d.ts"
"ts:prasi-global.d.ts"
);
register(monaco, propText.join("\n"), "ts:typings.d.ts");