wip fix
This commit is contained in:
parent
0532332a3a
commit
1f8ad5fd32
|
|
@ -21,6 +21,7 @@ export const addScope = (
|
||||||
);
|
);
|
||||||
model.onDidChangeContent((e) => {
|
model.onDidChangeContent((e) => {
|
||||||
const text = model.getValue();
|
const text = model.getValue();
|
||||||
|
console.log(filename, text);
|
||||||
// const models = monaco.editor.getModels().filter((e) => {
|
// const models = monaco.editor.getModels().filter((e) => {
|
||||||
// return e.uri.toString().startsWith("ts:scope~");
|
// return e.uri.toString().startsWith("ts:scope~");
|
||||||
// });
|
// });
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,7 @@
|
||||||
import { IMeta, PG, active } from "../../../../logic/ed-global";
|
import { IMeta, PG, active } from "../../../../logic/ed-global";
|
||||||
import { extractExportImport } from "./extract-exim";
|
import { extractExportImport } from "./extract-exim";
|
||||||
|
|
||||||
export const defineScopeParent = (p: PG, meta: IMeta) => {
|
export const scopeMapExportImport = (p: PG, meta: IMeta, parents: IMeta[]) => {
|
||||||
const metas = active.comp_id
|
|
||||||
? p.comp.list[active.comp_id]?.meta
|
|
||||||
: p.page.meta;
|
|
||||||
|
|
||||||
const parents: IMeta[] = [];
|
|
||||||
let cur = meta;
|
|
||||||
if (cur && cur.parent) {
|
|
||||||
while (cur && cur.parent && cur.parent.id) {
|
|
||||||
if (cur.mitem) {
|
|
||||||
parents.unshift(cur);
|
|
||||||
}
|
|
||||||
cur = metas[cur.parent.id];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
let next_parent = parents[i + 1];
|
let next_parent = parents[i + 1];
|
||||||
const imports = {} as Record<string, string>;
|
const imports = {} as Record<string, string>;
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
import { IMeta, PG, active } from "../../../../logic/ed-global";
|
|
||||||
import { extractExportImport } from "./extract-exim";
|
|
||||||
import { defineScopeParent } from "./scope-parent";
|
|
||||||
|
|
||||||
export const defineScopeChildren = (
|
|
||||||
p: PG,
|
|
||||||
meta: IMeta,
|
|
||||||
imports: Record<string, { usage_id: string; source_file: string }>
|
|
||||||
) => {
|
|
||||||
const metas = active.comp_id
|
|
||||||
? p.comp.list[active.comp_id]?.meta
|
|
||||||
: p.page.meta;
|
|
||||||
|
|
||||||
const result = {} as Record<string, string>;
|
|
||||||
let cur_id = meta.item.id;
|
|
||||||
const childs = findChilds(metas, cur_id);
|
|
||||||
for (const child of childs) {
|
|
||||||
result[child.item.id] = `\
|
|
||||||
${Object.entries(imports)
|
|
||||||
.map(([k, v]) => {
|
|
||||||
return `import { ${k} } from "${v.source_file}";`;
|
|
||||||
})
|
|
||||||
.join("\n")}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
const findChilds = (metas: Record<string, IMeta>, id: string) => {
|
|
||||||
const childs = [] as IMeta[];
|
|
||||||
for (const [k, v] of Object.entries(metas)) {
|
|
||||||
if (v.parent?.id === id) {
|
|
||||||
childs.push(metas[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return childs;
|
|
||||||
};
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import type { OnMount } from "@monaco-editor/react";
|
import type { OnMount } from "@monaco-editor/react";
|
||||||
import { IMeta, PG } from "../../../../logic/ed-global";
|
import { IMeta, PG, active } from "../../../../logic/ed-global";
|
||||||
import { addScope } from "./add-scope";
|
import { addScope } from "./add-scope";
|
||||||
import { defineScopeChildren } from "./scope-children";
|
import { scopeMapExportImport } from "./map-exim";
|
||||||
import { defineScopeParent } from "./scope-parent";
|
import { IItem } from "../../../../../../utils/types/item";
|
||||||
|
import { IContent } from "../../../../../../utils/types/general";
|
||||||
|
|
||||||
type Monaco = Parameters<OnMount>[1];
|
type Monaco = Parameters<OnMount>[1];
|
||||||
export type MonacoEditor = Parameters<OnMount>[0];
|
export type MonacoEditor = Parameters<OnMount>[0];
|
||||||
|
|
@ -13,12 +14,68 @@ export const declareScope = async (
|
||||||
editor: MonacoEditor,
|
editor: MonacoEditor,
|
||||||
monaco: Monaco
|
monaco: Monaco
|
||||||
) => {
|
) => {
|
||||||
const parent = defineScopeParent(p, meta);
|
const metas = active.comp_id
|
||||||
|
? p.comp.list[active.comp_id]?.meta
|
||||||
|
: p.page.meta;
|
||||||
|
const parents: IMeta[] = [];
|
||||||
|
let cur = meta;
|
||||||
|
if (cur && cur.parent) {
|
||||||
|
while (cur && cur.parent && cur.parent.id) {
|
||||||
|
if (cur.mitem) {
|
||||||
|
parents.unshift(cur);
|
||||||
|
}
|
||||||
|
cur = metas[cur.parent.id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const [k, v] of Object.entries(parent.exports)) {
|
const last_parent = parents[parents.length - 1];
|
||||||
if (k !== meta.item.id) {
|
if (
|
||||||
for (const [i, j] of Object.entries(v)) {
|
last_parent &&
|
||||||
addScope(p, monaco, i, j);
|
Array.isArray(last_parent.item.childs) &&
|
||||||
|
last_parent.item.childs.length > 0
|
||||||
|
) {
|
||||||
|
const paths: IMeta[][] = [];
|
||||||
|
const childs = last_parent.item.childs;
|
||||||
|
|
||||||
|
const map_childs = (
|
||||||
|
childs: IContent[],
|
||||||
|
paths: IMeta[][],
|
||||||
|
parent?: IMeta
|
||||||
|
) => {
|
||||||
|
for (const m of childs) {
|
||||||
|
const meta = metas[m.id];
|
||||||
|
if (meta) {
|
||||||
|
let cur: null | IMeta[] = null;
|
||||||
|
for (const path of paths) {
|
||||||
|
if (path[path.length - 1] === parent) {
|
||||||
|
cur = path;
|
||||||
|
cur.push(meta);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cur) {
|
||||||
|
paths.push([meta]);
|
||||||
|
cur = paths[paths.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cur) {
|
||||||
|
if (Array.isArray(meta.item.childs)) {
|
||||||
|
map_childs(meta.item.childs, paths, meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
map_childs(childs, paths);
|
||||||
|
} else {
|
||||||
|
const exim = scopeMapExportImport(p, meta, parents);
|
||||||
|
|
||||||
|
for (const [k, v] of Object.entries(exim.exports)) {
|
||||||
|
if (k !== meta.item.id) {
|
||||||
|
for (const [i, j] of Object.entries(v)) {
|
||||||
|
addScope(p, monaco, i, j);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue