From 8484a6a930c0759b38351ee3aa4955d5f9acf945 Mon Sep 17 00:00:00 2001 From: rizrmd Date: Mon, 3 Jun 2024 20:37:58 +0700 Subject: [PATCH] fix --- app/web/src/nova/ed/ed-base.tsx | 7 +++- .../src/nova/ed/panel/popup/script/monaco.tsx | 4 +- .../ed/panel/popup/script/scope/scope.tsx | 42 ++++++++++++------- app/web/src/utils/script/types/prop.tsx | 2 +- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/app/web/src/nova/ed/ed-base.tsx b/app/web/src/nova/ed/ed-base.tsx index 25777f86..d9d108d0 100644 --- a/app/web/src/nova/ed/ed-base.tsx +++ b/app/web/src/nova/ed/ed-base.tsx @@ -19,6 +19,7 @@ import { EdPopPage } from "./panel/popup/page/page-popup"; import { EdPopScript } from "./panel/popup/script/pop-script"; import { EdPopSite } from "./panel/popup/site/site-popup"; import { iconVSCode } from "./panel/popup/code/icons"; +import { isLocalhost } from "../../utils/ui/is-localhost"; export const EdBase = () => { const p = useGlobal(EDGlobal, "EDITOR"); @@ -31,6 +32,10 @@ export const EdBase = () => { edRoute(p); + const vscode_url = isLocalhost() + ? "http://localhost:8443?" + : "https://prasi-vsc.avolut.com/?tkn=prasi&"; + if (p.status === "load-site") { return ( { {p.site.id && (
= () => { break; case "prop-instance": { - types._raw = declareScope(p, meta, monaco); + declareScope(p, meta, monaco); const nmodel = monaco.editor.createModel( trim(val), "typescript", @@ -172,7 +172,7 @@ export const EdScriptMonaco: FC<{}> = () => { break; case "item": { - types._raw = declareScope(p, meta, monaco); + declareScope(p, meta, monaco); const model = monaco.editor.createModel( trim(val), "typescript", diff --git a/app/web/src/nova/ed/panel/popup/script/scope/scope.tsx b/app/web/src/nova/ed/panel/popup/script/scope/scope.tsx index 5d37adad..738f2237 100644 --- a/app/web/src/nova/ed/panel/popup/script/scope/scope.tsx +++ b/app/web/src/nova/ed/panel/popup/script/scope/scope.tsx @@ -2,6 +2,7 @@ import type { OnMount } from "@monaco-editor/react"; import { IContent } from "../../../../../../utils/types/general"; import { IMeta, PG, active } from "../../../../logic/ed-global"; import { TypedArray } from "yjs-types"; +import { register } from "../../../../../../utils/script/typings"; type Monaco = Parameters[1]; export type MonacoEditor = Parameters[0]; @@ -144,29 +145,42 @@ return typings; m_prev = m; } - const raw_types: string[] = []; + const tree_types: string[] = []; + const tree_usage: string[] = []; for (const [k, v] of Object.entries(vars)) { if (v.mode === "local") { - raw_types.push(`\ -const \$\$_${k} = ${v.val}; -const ${k} = null as unknown as (typeof \$\$_${k} & { render: ()=> void }); + const im = tree_types.length; + tree_types.push(`\ +declare module "item-${im}" { + export const \$\$_${k} = ${v.val}; +} +`); + tree_usage.push(` +import { \$\$_${k} } from "item-${im}"; +const ${k} = null as unknown as (typeof \$\$_${k} & { render: ()=> void }); `); } else if (v.mode === "prop") { - raw_types.push(`\ -const \$\$_${k} = ${v.val}; -const ${k} = null as unknown as typeof \$\$_${k};`); + const im = tree_types.length; + tree_types.push(`\ + +declare module "item-${im}" { + export const \$\$_${k} = ${v.val}; +} +`); + tree_usage.push(` +import { \$\$_${k} } from "item-${im}"; +const ${k} = null as unknown as typeof \$\$_${k}; +`); } else if (v.mode === "type") { - raw_types.push(` -const ${k} = null as unknown as ${v.val}; + tree_types.push(` +export const ${k} = null as unknown as ${v.val}; `); } } - for (const [k, v] of Object.entries(comp_types)) { - raw_types.push(v); - } - - return raw_types.join("\n"); + register(monaco, tree_usage.join("\n"), "ts:tree_usage.d.ts"); + register(monaco, tree_types.join("\n"), "ts:tree_types.d.ts"); + register(monaco, Object.values(comp_types).join("\n"), "ts:comp_types.d.ts"); }; const map_childs = ( diff --git a/app/web/src/utils/script/types/prop.tsx b/app/web/src/utils/script/types/prop.tsx index fa6722c3..14b5db78 100644 --- a/app/web/src/utils/script/types/prop.tsx +++ b/app/web/src/utils/script/types/prop.tsx @@ -47,7 +47,7 @@ export const extractProp = (prop: { for (const [k, v] of Object.entries(props)) { if (v.type) { - if (k === "_raw") { + if (k.startsWith("_raw")) { propTypes.push(v.type); } else { let const_or_type = "const";