wip fix
This commit is contained in:
parent
715848602f
commit
aa1d4e4e5e
|
|
@ -85,19 +85,24 @@ export const EdScriptMonaco: FC<{}> = () => {
|
||||||
if (meta) {
|
if (meta) {
|
||||||
const imports = declareScope(p, meta, editor, monaco);
|
const imports = declareScope(p, meta, editor, monaco);
|
||||||
|
|
||||||
let model = monaco.editor.createModel(
|
let cur = "page";
|
||||||
`\
|
monaco.editor.getModels().forEach((model) => {
|
||||||
// #region imports
|
if (
|
||||||
${imports}
|
model.uri.path === `/${cur}_${active.item_id}_src_src.tsx`
|
||||||
// #endregion
|
) {
|
||||||
|
|
||||||
${val}
|
|
||||||
`,
|
|
||||||
"typescript",
|
|
||||||
monaco.Uri.parse(`file:///active.tsx`)
|
|
||||||
);
|
|
||||||
editor.setModel(model);
|
editor.setModel(model);
|
||||||
editor.trigger("fold", "editor.foldAllMarkerRegions", {});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (imports) {
|
||||||
|
const range = new monaco.Range(
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
imports.split("\n").length + 1,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
(editor as any).setHiddenAreas([range]);
|
||||||
|
}
|
||||||
|
|
||||||
await jsMount(editor, monaco, p);
|
await jsMount(editor, monaco, p);
|
||||||
}
|
}
|
||||||
|
|
@ -184,13 +189,20 @@ ${val}
|
||||||
language={
|
language={
|
||||||
{ css: "scss", js: "typescript", html: "html" }[p.ui.popup.script.mode]
|
{ css: "scss", js: "typescript", html: "html" }[p.ui.popup.script.mode]
|
||||||
}
|
}
|
||||||
onChange={(val) => {
|
onChange={(value) => {
|
||||||
return;
|
return;
|
||||||
local.value = val || "";
|
if ((value || "").includes("/** IMPORT BOUNDARY **/")) {
|
||||||
|
const valparts = (value || "").split("/** IMPORT BOUNDARY **/\n");
|
||||||
|
if (valparts.length === 2) local.value = valparts[1];
|
||||||
|
} else {
|
||||||
|
local.value = value || "";
|
||||||
|
}
|
||||||
|
|
||||||
local.render();
|
local.render();
|
||||||
clearTimeout(scriptEdit.timeout);
|
clearTimeout(scriptEdit.timeout);
|
||||||
|
|
||||||
const applyChanges = async () => {
|
const applyChanges = async () => {
|
||||||
|
const value = local.value;
|
||||||
const meta = getActiveMeta(p);
|
const meta = getActiveMeta(p);
|
||||||
const type = p.ui.popup.script.mode;
|
const type = p.ui.popup.script.mode;
|
||||||
if (meta && meta.mitem) {
|
if (meta && meta.mitem) {
|
||||||
|
|
@ -207,7 +219,7 @@ ${val}
|
||||||
type: "prop",
|
type: "prop",
|
||||||
prop_kind: p.ui.popup.script.prop_kind,
|
prop_kind: p.ui.popup.script.prop_kind,
|
||||||
prop_name: p.ui.popup.script.prop_name,
|
prop_name: p.ui.popup.script.prop_name,
|
||||||
value: compress(encode.encode(val || "")),
|
value: compress(encode.encode(value || "")),
|
||||||
...arg,
|
...arg,
|
||||||
});
|
});
|
||||||
} else if (p.ui.popup.script.type === "prop-instance") {
|
} else if (p.ui.popup.script.type === "prop-instance") {
|
||||||
|
|
@ -216,7 +228,7 @@ ${val}
|
||||||
mode: type,
|
mode: type,
|
||||||
prop_name: p.ui.popup.script.prop_name,
|
prop_name: p.ui.popup.script.prop_name,
|
||||||
item_id: active.item_id,
|
item_id: active.item_id,
|
||||||
value: compress(encode.encode(val || "")),
|
value: compress(encode.encode(value || "")),
|
||||||
...arg,
|
...arg,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -224,7 +236,7 @@ ${val}
|
||||||
type: "adv",
|
type: "adv",
|
||||||
mode: type,
|
mode: type,
|
||||||
item_id: active.item_id,
|
item_id: active.item_id,
|
||||||
value: compress(encode.encode(val || "")),
|
value: compress(encode.encode(value || "")),
|
||||||
...arg,
|
...arg,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,8 @@ export const addScope = (
|
||||||
const arg = extractLoc(uri.path.split("_"), p);
|
const arg = extractLoc(uri.path.split("_"), p);
|
||||||
model.onDidChangeContent((e) => {
|
model.onDidChangeContent((e) => {
|
||||||
const text = model.getValue();
|
const text = model.getValue();
|
||||||
console.log(arg, text);
|
console.log(arg);
|
||||||
// const models = monaco.editor.getModels().filter((e) => {
|
console.warn(text);
|
||||||
// return e.uri.toString().startsWith("ts:scope~");
|
|
||||||
// });
|
|
||||||
// models.forEach((model) => {
|
|
||||||
// console.log(model?.getValue());
|
|
||||||
// });
|
|
||||||
// modifyJS(p, type, arg.loc, text);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,55 @@ export const declareScope = (
|
||||||
const paths: IMeta[][] = [];
|
const paths: IMeta[][] = [];
|
||||||
|
|
||||||
map_childs(metas, entry, paths);
|
map_childs(metas, entry, paths);
|
||||||
const import_map = extract_import_map(paths, meta, p, monaco);
|
|
||||||
|
let cur = "page";
|
||||||
|
const import_map = extract_import_map(cur, paths, meta, p, monaco);
|
||||||
|
gen_content(cur, p, paths, import_map, monaco);
|
||||||
return import_map[active.item_id];
|
return import_map[active.item_id];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const gen_content = (
|
||||||
|
cur: string,
|
||||||
|
p: PG,
|
||||||
|
paths: IMeta[][],
|
||||||
|
import_map: Record<string, string>,
|
||||||
|
monaco: Monaco
|
||||||
|
) => {
|
||||||
|
const added = new Set<string>();
|
||||||
|
for (const path of paths) {
|
||||||
|
let idx = 0;
|
||||||
|
let last_import = "";
|
||||||
|
for (const m of path) {
|
||||||
|
if (!import_map[m.item.id]) {
|
||||||
|
if (idx === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
last_import = import_map[m.item.id];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!added.has(m.item.id) && m.item.adv?.js) {
|
||||||
|
added.add(m.item.id);
|
||||||
|
const content = `\
|
||||||
|
${last_import}
|
||||||
|
/** IMPORT BOUNDARY **/
|
||||||
|
${m.item.adv.js}
|
||||||
|
`;
|
||||||
|
|
||||||
|
addScope(
|
||||||
|
p,
|
||||||
|
monaco,
|
||||||
|
`file:///${cur}_${m.item.id}_src_src.tsx`,
|
||||||
|
content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const extract_import_map = (
|
const extract_import_map = (
|
||||||
|
cur: string,
|
||||||
paths: IMeta[][],
|
paths: IMeta[][],
|
||||||
meta: IMeta,
|
meta: IMeta,
|
||||||
p: PG,
|
p: PG,
|
||||||
|
|
@ -47,8 +91,6 @@ const extract_import_map = (
|
||||||
) => {
|
) => {
|
||||||
const added = new Set<string>();
|
const added = new Set<string>();
|
||||||
|
|
||||||
let cur = "page";
|
|
||||||
|
|
||||||
const import_map = {} as Record<string, string>;
|
const import_map = {} as Record<string, string>;
|
||||||
for (const path of paths) {
|
for (const path of paths) {
|
||||||
const imports = new Set<string>();
|
const imports = new Set<string>();
|
||||||
|
|
@ -75,9 +117,10 @@ export const ${k}: typeof _local & { render: ()=>void } = _local;
|
||||||
addScope(
|
addScope(
|
||||||
p,
|
p,
|
||||||
monaco,
|
monaco,
|
||||||
`file:///${cur}_${v.id}_${v.type}_${k}.d.ts`,
|
`file:///${cur}_${v.id}_${v.type}_${k}.tsx`,
|
||||||
`\
|
`\
|
||||||
${[...imports].join("\n")}
|
${[...imports].join("\n")}
|
||||||
|
/** IMPORT BOUNDARY **/
|
||||||
${src}`
|
${src}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ export const jsMount = async (editor: MonacoEditor, monaco: Monaco, p?: PG) => {
|
||||||
const args = r.path.split("_");
|
const args = r.path.split("_");
|
||||||
if (args.length === 4) {
|
if (args.length === 4) {
|
||||||
const { cur, id, meta } = extractLoc(args, p);
|
const { cur, id, meta } = extractLoc(args, p);
|
||||||
|
console.log(cur, id, meta.item.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +184,7 @@ export const jsMount = async (editor: MonacoEditor, monaco: Monaco, p?: PG) => {
|
||||||
export const extractLoc = (args: string[], p: PG) => {
|
export const extractLoc = (args: string[], p: PG) => {
|
||||||
const [_cur, id, type, _varname] = args;
|
const [_cur, id, type, _varname] = args;
|
||||||
const cur = _cur.substring(1);
|
const cur = _cur.substring(1);
|
||||||
const varname = _varname.substring(0, _varname.length - ".d.ts".length);
|
const varname = _varname.substring(0, _varname.length - ".tsx".length);
|
||||||
|
|
||||||
let meta = p.page.meta[id];
|
let meta = p.page.meta[id];
|
||||||
if (cur !== "page") {
|
if (cur !== "page") {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue