wip fix script
This commit is contained in:
parent
e23c11d198
commit
1b347cdd76
|
|
@ -57,39 +57,55 @@ const EmptyComp = {
|
||||||
const target = {
|
const target = {
|
||||||
active_id: false as any,
|
active_id: false as any,
|
||||||
comp_id: false as any,
|
comp_id: false as any,
|
||||||
comp_item_id: false as any,
|
instance_comp_id: false as any,
|
||||||
|
instance_item_id: false as any,
|
||||||
};
|
};
|
||||||
export const active = {
|
export const active = {
|
||||||
hover_id: "",
|
hover_id: "",
|
||||||
|
prop_name: "",
|
||||||
get item_id() {
|
get item_id() {
|
||||||
if (target.active_id === false) {
|
if (target.active_id === false) {
|
||||||
target.active_id = localStorage.getItem("prasi-active-id") || "";
|
target.active_id = localStorage.getItem("prasi-active-id") || "";
|
||||||
}
|
}
|
||||||
return target.active_id;
|
return target.active_id || "";
|
||||||
},
|
},
|
||||||
set item_id(val: string) {
|
set item_id(val: string) {
|
||||||
localStorage.setItem("prasi-active-id", val);
|
localStorage.setItem("prasi-active-id", val || "");
|
||||||
target.active_id = val;
|
target.active_id = val || "";
|
||||||
},
|
},
|
||||||
get comp_id() {
|
get comp_id() {
|
||||||
if (target.comp_id === false) {
|
if (target.comp_id === false) {
|
||||||
target.comp_id = localStorage.getItem("prasi-comp-id") || "";
|
target.comp_id = localStorage.getItem("prasi-comp-id") || "";
|
||||||
}
|
}
|
||||||
return target.comp_id;
|
return target.comp_id || "";
|
||||||
},
|
},
|
||||||
set comp_id(val: string) {
|
set comp_id(val: string) {
|
||||||
localStorage.setItem("prasi-comp-id", val);
|
localStorage.setItem("prasi-comp-id", val || "");
|
||||||
target.comp_id = val;
|
target.comp_id = val || "";
|
||||||
},
|
},
|
||||||
get comp_item_id() {
|
instance: {
|
||||||
if (target.comp_item_id === false) {
|
get comp_id() {
|
||||||
target.comp_item_id = localStorage.getItem("prasi-comp-item-id") || "";
|
if (target.instance_comp_id === false) {
|
||||||
}
|
target.instance_comp_id =
|
||||||
return target.comp_item_id;
|
localStorage.getItem("prasi-instance-comp-id") || "";
|
||||||
},
|
}
|
||||||
set comp_item_id(val: string) {
|
return target.instance_comp_id || "";
|
||||||
localStorage.setItem("prasi-comp-item-id", val);
|
},
|
||||||
target.comp_item_id = val;
|
set comp_id(val: string) {
|
||||||
|
localStorage.setItem("prasi-instance-comp-id", val || "");
|
||||||
|
target.instance_comp_id = val || "";
|
||||||
|
},
|
||||||
|
get item_id() {
|
||||||
|
if (target.instance_item_id === false) {
|
||||||
|
target.instance_item_id =
|
||||||
|
localStorage.getItem("prasi-instance-item-id") || "";
|
||||||
|
}
|
||||||
|
return target.instance_item_id || "";
|
||||||
|
},
|
||||||
|
set item_id(val: string) {
|
||||||
|
localStorage.setItem("prasi-instance-item-id", val || "");
|
||||||
|
target.instance_item_id = val || "";
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,19 @@ export const ScriptMonaco = () => {
|
||||||
|
|
||||||
const item = meta.item;
|
const item = meta.item;
|
||||||
const adv = item.adv || {};
|
const adv = item.adv || {};
|
||||||
const val: string = (
|
let val: string = (
|
||||||
typeof adv[p.ui.popup.script.mode] === "string"
|
typeof adv[p.ui.popup.script.mode] === "string"
|
||||||
? adv[p.ui.popup.script.mode]
|
? adv[p.ui.popup.script.mode]
|
||||||
: ""
|
: ""
|
||||||
) as any;
|
) as any;
|
||||||
|
|
||||||
|
if (active.prop_name && item.type === "item" && item.component) {
|
||||||
|
const prop = item.component.props[active.prop_name];
|
||||||
|
if (prop) {
|
||||||
|
val = prop.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const doEdit = async (newval: string, all?: boolean) => {
|
const doEdit = async (newval: string, all?: boolean) => {
|
||||||
if (local.editor && jscript.prettier.standalone) {
|
if (local.editor && jscript.prettier.standalone) {
|
||||||
const text = trim(
|
const text = trim(
|
||||||
|
|
@ -155,40 +162,8 @@ export const ScriptMonaco = () => {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
editor.setModel(model);
|
editor.setModel(model);
|
||||||
monaco.editor.registerEditorOpener({
|
|
||||||
openCodeEditor(source, r, selectionOrPosition) {
|
|
||||||
const cpath = r.path.substring(`scope~`.length).split("__");
|
|
||||||
const comp_id = cpath[0];
|
|
||||||
if (cpath[1]) {
|
|
||||||
const path = cpath[1].split("~");
|
|
||||||
const type = path[0] as "prop" | "passprop" | "local";
|
|
||||||
const id = path[path.length - 1].replace(".d.ts", "");
|
|
||||||
|
|
||||||
if (type === "prop") {
|
await jsMount(editor, monaco, p);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comp_id) {
|
|
||||||
let meta = p.page.meta[id];
|
|
||||||
if (active.comp_id) {
|
|
||||||
meta = p.comp.list[active.comp_id].meta[id];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (meta && meta.item.originalId) {
|
|
||||||
active.item_id = meta.item.originalId;
|
|
||||||
}
|
|
||||||
active.comp_id = comp_id;
|
|
||||||
} else {
|
|
||||||
active.item_id = id;
|
|
||||||
}
|
|
||||||
p.render();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await jsMount(editor, monaco);
|
|
||||||
await monacoTypings(
|
await monacoTypings(
|
||||||
{
|
{
|
||||||
site_dts: p.site_dts,
|
site_dts: p.site_dts,
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,13 @@ export const declareScope = async (
|
||||||
});
|
});
|
||||||
|
|
||||||
spreadScope(p, s, (arg) => {
|
spreadScope(p, s, (arg) => {
|
||||||
|
let { prev } = arg;
|
||||||
if (arg.type !== "local") {
|
if (arg.type !== "local") {
|
||||||
addScope(
|
addScope(
|
||||||
monaco,
|
monaco,
|
||||||
`${arg.comp_id || ""}__${arg.type}~${arg.name}~${arg.id}`,
|
`${arg.comp_id || ""}~${prev?.comp_id || ""}~${prev?.item_id || ""}__${
|
||||||
|
arg.type
|
||||||
|
}~${arg.name}~${arg.id}`,
|
||||||
`\
|
`\
|
||||||
export const {};
|
export const {};
|
||||||
declare global {
|
declare global {
|
||||||
|
|
@ -58,7 +61,9 @@ declare global {
|
||||||
} else {
|
} else {
|
||||||
addScope(
|
addScope(
|
||||||
monaco,
|
monaco,
|
||||||
`${arg.comp_id || ""}__${arg.type}~${arg.id}`,
|
`${arg.comp_id || ""}~${prev?.comp_id || ""}~${prev?.item_id || ""}__${
|
||||||
|
arg.type
|
||||||
|
}~${arg.id}`,
|
||||||
`\
|
`\
|
||||||
export const {};
|
export const {};
|
||||||
const __val = ${arg.value};
|
const __val = ${arg.value};
|
||||||
|
|
@ -81,6 +86,7 @@ type IEachArgScope = {
|
||||||
index?: number;
|
index?: number;
|
||||||
is_prop?: boolean;
|
is_prop?: boolean;
|
||||||
comp_id?: string;
|
comp_id?: string;
|
||||||
|
prev?: { comp_id: string; item_id: string };
|
||||||
};
|
};
|
||||||
const spreadScope = (
|
const spreadScope = (
|
||||||
p: PG,
|
p: PG,
|
||||||
|
|
@ -115,8 +121,9 @@ const spreadScope = (
|
||||||
const mergeScopes = (
|
const mergeScopes = (
|
||||||
parents: string[],
|
parents: string[],
|
||||||
each: (arg: IEachArgScope) => void,
|
each: (arg: IEachArgScope) => void,
|
||||||
comp_id?: string
|
arg: { comp_id?: string; prev?: { comp_id: string; item_id: string } }
|
||||||
) => {
|
) => {
|
||||||
|
let { comp_id, prev } = arg;
|
||||||
for (const parent_id of parents) {
|
for (const parent_id of parents) {
|
||||||
let item = null as null | ISingleScope;
|
let item = null as null | ISingleScope;
|
||||||
if (layout && layout_scope[layout_id]) {
|
if (layout && layout_scope[layout_id]) {
|
||||||
|
|
@ -138,7 +145,10 @@ const spreadScope = (
|
||||||
if (item) {
|
if (item) {
|
||||||
if (item.c) {
|
if (item.c) {
|
||||||
comp_id = item.c;
|
comp_id = item.c;
|
||||||
mergeScopes(item.p, each, item.c);
|
mergeScopes(item.p, each, {
|
||||||
|
comp_id: item.c,
|
||||||
|
prev: { item_id: parent_id, comp_id: arg.comp_id || "" },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const scope = item.s;
|
const scope = item.s;
|
||||||
|
|
@ -152,6 +162,7 @@ const spreadScope = (
|
||||||
name: scope.local.name,
|
name: scope.local.name,
|
||||||
value: scope.local?.value,
|
value: scope.local?.value,
|
||||||
index: scope.local?.index,
|
index: scope.local?.index,
|
||||||
|
prev,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (scope.passprop) {
|
if (scope.passprop) {
|
||||||
|
|
@ -164,6 +175,7 @@ const spreadScope = (
|
||||||
name: k,
|
name: k,
|
||||||
value: v.value,
|
value: v.value,
|
||||||
index: v.index,
|
index: v.index,
|
||||||
|
prev,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -178,6 +190,7 @@ const spreadScope = (
|
||||||
name: k,
|
name: k,
|
||||||
value: v.value,
|
value: v.value,
|
||||||
is_prop: true,
|
is_prop: true,
|
||||||
|
prev,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +199,7 @@ const spreadScope = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
mergeScopes(parents, each);
|
mergeScopes(parents, each, {});
|
||||||
};
|
};
|
||||||
|
|
||||||
const addScope = (monaco: Monaco, id: string, source: string) => {
|
const addScope = (monaco: Monaco, id: string, source: string) => {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { useGlobal } from "web-utils";
|
||||||
import { jscript } from "../../../../../utils/script/jscript";
|
import { jscript } from "../../../../../utils/script/jscript";
|
||||||
import { Loading } from "../../../../../utils/ui/loading";
|
import { Loading } from "../../../../../utils/ui/loading";
|
||||||
import { Modal } from "../../../../../utils/ui/modal";
|
import { Modal } from "../../../../../utils/ui/modal";
|
||||||
import { EDGlobal } from "../../../logic/ed-global";
|
import { EDGlobal, active } from "../../../logic/ed-global";
|
||||||
import { ScriptWorkbench } from "./workbench";
|
import { ScriptWorkbench } from "./workbench";
|
||||||
|
|
||||||
export const EdPopScript = () => {
|
export const EdPopScript = () => {
|
||||||
|
|
@ -14,6 +14,7 @@ export const EdPopScript = () => {
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) {
|
if (!open) {
|
||||||
p.ui.popup.script.open = false;
|
p.ui.popup.script.open = false;
|
||||||
|
active.prop_name = "";
|
||||||
p.render();
|
p.render();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { useGlobal } from "web-utils";
|
import { useGlobal } from "web-utils";
|
||||||
import { ScriptMonaco } from "./monaco";
|
import { ScriptMonaco } from "./monaco";
|
||||||
import { EDGlobal } from "../../../logic/ed-global";
|
import { EDGlobal, active } from "../../../logic/ed-global";
|
||||||
|
|
||||||
export const ScriptWorkbench = () => {
|
export const ScriptWorkbench = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
|
|
@ -8,36 +8,42 @@ export const ScriptWorkbench = () => {
|
||||||
<div className="flex flex-1 items-stretch">
|
<div className="flex flex-1 items-stretch">
|
||||||
<div className="flex flex-1 flex-col ">
|
<div className="flex flex-1 flex-col ">
|
||||||
<div className="flex p-2 border-b space-x-2">
|
<div className="flex p-2 border-b space-x-2">
|
||||||
{[
|
{active.prop_name ? (
|
||||||
{ type: "js", color: "#e9522c" },
|
<div className="text-[12px]">{active.prop_name}</div>
|
||||||
{ type: "css", color: "#188228" },
|
) : (
|
||||||
{ type: "html", color: "#2c3e83" },
|
<>
|
||||||
].map((e) => {
|
{[
|
||||||
return (
|
{ type: "js", color: "#e9522c" },
|
||||||
<div
|
{ type: "css", color: "#188228" },
|
||||||
key={e.type}
|
{ type: "html", color: "#2c3e83" },
|
||||||
className={cx(
|
].map((e) => {
|
||||||
css`
|
return (
|
||||||
color: ${e.color};
|
<div
|
||||||
border: 1px solid ${e.color};
|
key={e.type}
|
||||||
`,
|
className={cx(
|
||||||
"uppercase text-white text-[12px] cursor-pointer transition-all hover:opacity-100 w-[40px] text-center",
|
css`
|
||||||
p.ui.popup.script.mode === e.type
|
color: ${e.color};
|
||||||
? css`
|
border: 1px solid ${e.color};
|
||||||
background: ${e.color};
|
`,
|
||||||
color: white;
|
"uppercase text-white text-[12px] cursor-pointer transition-all hover:opacity-100 w-[40px] text-center",
|
||||||
`
|
p.ui.popup.script.mode === e.type
|
||||||
: "opacity-30"
|
? css`
|
||||||
)}
|
background: ${e.color};
|
||||||
onClick={() => {
|
color: white;
|
||||||
p.ui.popup.script.mode = e.type as any;
|
`
|
||||||
p.render();
|
: "opacity-30"
|
||||||
}}
|
)}
|
||||||
>
|
onClick={() => {
|
||||||
{e.type}
|
p.ui.popup.script.mode = e.type as any;
|
||||||
</div>
|
p.render();
|
||||||
);
|
}}
|
||||||
})}
|
>
|
||||||
|
{e.type}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="relative flex flex-1">
|
<div className="relative flex flex-1">
|
||||||
<ScriptMonaco />
|
<ScriptMonaco />
|
||||||
|
|
|
||||||
|
|
@ -75,13 +75,19 @@ export const EdTreeAction = ({
|
||||||
|
|
||||||
const comp_id = comp.id;
|
const comp_id = comp.id;
|
||||||
if (comp_id) {
|
if (comp_id) {
|
||||||
active.comp_id = comp_id;
|
active.instance.item_id = item.id;
|
||||||
active.comp_item_id = item.id;
|
active.instance.comp_id = active.comp_id;
|
||||||
|
console.log(
|
||||||
|
active.instance.comp_id,
|
||||||
|
active.instance.item_id
|
||||||
|
);
|
||||||
|
|
||||||
|
active.comp_id = comp_id || "";
|
||||||
const root = p.comp.list[comp_id].tree.find(
|
const root = p.comp.list[comp_id].tree.find(
|
||||||
(e) => e.parent === "root"
|
(e) => e.parent === "root"
|
||||||
);
|
);
|
||||||
if (root && typeof root.id === "string") {
|
if (root && typeof root.id === "string") {
|
||||||
active.item_id = root.id;
|
active.item_id = root.id || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
p.render();
|
p.render();
|
||||||
|
|
@ -102,9 +108,10 @@ export const EdTreeAction = ({
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (active.comp_id) {
|
if (active.comp_id) {
|
||||||
active.comp_id = "";
|
active.comp_id = active.instance.comp_id || "";
|
||||||
active.item_id = active.comp_item_id;
|
active.item_id = active.instance.item_id || "";
|
||||||
active.comp_item_id = "";
|
active.instance.comp_id = "";
|
||||||
|
active.instance.item_id = "";
|
||||||
p.render();
|
p.render();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import {
|
||||||
getWorker,
|
getWorker,
|
||||||
} from "monaco-jsx-syntax-highlight-v2";
|
} from "monaco-jsx-syntax-highlight-v2";
|
||||||
import { jscript } from "./jscript";
|
import { jscript } from "./jscript";
|
||||||
|
import { PG, active } from "../../nova/ed/logic/ed-global";
|
||||||
|
|
||||||
export type MonacoEditor = Parameters<OnMount>[0];
|
export type MonacoEditor = Parameters<OnMount>[0];
|
||||||
type Monaco = Parameters<OnMount>[1];
|
type Monaco = Parameters<OnMount>[1];
|
||||||
|
|
@ -12,7 +13,7 @@ type CompilerOptions = Parameters<
|
||||||
Parameters<OnMount>[1]["languages"]["typescript"]["typescriptDefaults"]["setCompilerOptions"]
|
Parameters<OnMount>[1]["languages"]["typescript"]["typescriptDefaults"]["setCompilerOptions"]
|
||||||
>[0];
|
>[0];
|
||||||
|
|
||||||
export const jsMount = async (editor: MonacoEditor, monaco: Monaco) => {
|
export const jsMount = async (editor: MonacoEditor, monaco: Monaco, p: PG) => {
|
||||||
const m = monaco as any;
|
const m = monaco as any;
|
||||||
if (!m.customJSMounted) {
|
if (!m.customJSMounted) {
|
||||||
m.customJSMounted = true;
|
m.customJSMounted = true;
|
||||||
|
|
@ -32,6 +33,58 @@ export const jsMount = async (editor: MonacoEditor, monaco: Monaco) => {
|
||||||
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
|
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
monaco.editor.registerEditorOpener({
|
||||||
|
openCodeEditor(source, r, selectionOrPosition) {
|
||||||
|
p.ui.popup.script.mode === "js";
|
||||||
|
const cpath = r.path.substring(`scope~`.length).split("__");
|
||||||
|
const [comp_id, prev_comp_id, prev_item_id] = cpath[0].split("~");
|
||||||
|
if (cpath[1]) {
|
||||||
|
const path = cpath[1].split("~");
|
||||||
|
const type = path[0] as "prop" | "passprop" | "local";
|
||||||
|
const id = path[path.length - 1].replace(".d.ts", "");
|
||||||
|
|
||||||
|
if (type === "prop") {
|
||||||
|
active.prop_name = path[1];
|
||||||
|
|
||||||
|
if (
|
||||||
|
!prev_comp_id &&
|
||||||
|
!prev_item_id &&
|
||||||
|
active.instance.item_id &&
|
||||||
|
active.comp_id
|
||||||
|
) {
|
||||||
|
active.item_id = active.instance.item_id;
|
||||||
|
active.comp_id = active.instance.comp_id;
|
||||||
|
active.instance.item_id = "";
|
||||||
|
active.instance.comp_id = "";
|
||||||
|
p.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comp_id) {
|
||||||
|
let meta = p.page.meta[id];
|
||||||
|
if (active.comp_id) {
|
||||||
|
meta = p.comp.list[active.comp_id].meta[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
active.instance.comp_id = prev_comp_id;
|
||||||
|
active.instance.item_id = prev_item_id;
|
||||||
|
|
||||||
|
if (meta && meta.item.originalId) {
|
||||||
|
active.item_id = meta.item.originalId;
|
||||||
|
}
|
||||||
|
active.comp_id = comp_id;
|
||||||
|
} else {
|
||||||
|
active.item_id = id;
|
||||||
|
}
|
||||||
|
p.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
monaco.languages.registerDocumentFormattingEditProvider("typescript", {
|
monaco.languages.registerDocumentFormattingEditProvider("typescript", {
|
||||||
async provideDocumentFormattingEdits(model, options, token) {
|
async provideDocumentFormattingEdits(model, options, token) {
|
||||||
const prettier = jscript.prettier.standalone;
|
const prettier = jscript.prettier.standalone;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue