wip fix
This commit is contained in:
parent
c83e459a4c
commit
0bcbac81d4
|
|
@ -125,7 +125,7 @@ export const SyncActions = {
|
||||||
prop_name: string;
|
prop_name: string;
|
||||||
value: Uint8Array;
|
value: Uint8Array;
|
||||||
}
|
}
|
||||||
) => ({}) as boolean | ParsedScope,
|
) => ({}) as boolean | ParsedScope | string,
|
||||||
parse: async (code: string | Record<string, string>) =>
|
parse: async (code: string | Record<string, string>) =>
|
||||||
({}) as Record<string, ReturnType<typeof parseJs>>,
|
({}) as Record<string, ReturnType<typeof parseJs>>,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -41,41 +41,45 @@ export const code_edit: SAction["code"]["edit"] = async function (
|
||||||
|
|
||||||
if (mitem) {
|
if (mitem) {
|
||||||
if (arg.type === "adv") {
|
if (arg.type === "adv") {
|
||||||
const res = await transform(`render(${src})`, {
|
try {
|
||||||
jsx: "transform",
|
const res = await transform(`render(${src})`, {
|
||||||
format: "cjs",
|
jsx: "transform",
|
||||||
loader: "tsx",
|
format: "cjs",
|
||||||
});
|
loader: "tsx",
|
||||||
doc?.transact(() => {
|
});
|
||||||
const mode = arg.mode;
|
doc?.transact(() => {
|
||||||
let adv = mitem.get("adv");
|
const mode = arg.mode;
|
||||||
if (!adv) {
|
let adv = mitem.get("adv");
|
||||||
mitem.set("adv", new Y.Map() as any);
|
if (!adv) {
|
||||||
adv = mitem.get("adv");
|
mitem.set("adv", new Y.Map() as any);
|
||||||
}
|
adv = mitem.get("adv");
|
||||||
|
}
|
||||||
|
|
||||||
if (adv) {
|
if (adv) {
|
||||||
try {
|
try {
|
||||||
if (adv) {
|
if (adv) {
|
||||||
adv.set(mode, src);
|
adv.set(mode, src);
|
||||||
if (mode === "js") {
|
if (mode === "js") {
|
||||||
adv.set("jsBuilt", res.code);
|
adv.set("jsBuilt", res.code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
g.log.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode === "js") {
|
||||||
|
const res = parseJs(adv.get("js")) || false;
|
||||||
|
if (res) {
|
||||||
|
mitem.set("script", res);
|
||||||
|
} else {
|
||||||
|
mitem.delete("script");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
g.log.error(e);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
if (mode === "js") {
|
} catch (e: any) {
|
||||||
const res = parseJs(adv.get("js")) || false;
|
return e.message.toString();
|
||||||
if (res) {
|
}
|
||||||
mitem.set("script", res);
|
|
||||||
} else {
|
|
||||||
mitem.delete("script");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
const mprop = mitem
|
const mprop = mitem
|
||||||
.get("component")
|
.get("component")
|
||||||
|
|
@ -94,7 +98,9 @@ export const code_edit: SAction["code"]["edit"] = async function (
|
||||||
mprop.set("value", src);
|
mprop.set("value", src);
|
||||||
mprop.set("valueBuilt", res.code.substring(6));
|
mprop.set("valueBuilt", res.code.substring(6));
|
||||||
});
|
});
|
||||||
} catch (e) {}
|
} catch (e: any) {
|
||||||
|
return e.message.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,8 +140,8 @@ export const code_edit: SAction["code"]["edit"] = async function (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
g.log.error(e);
|
return e.message.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ export const EdBase = () => {
|
||||||
|
|
||||||
edRoute(p);
|
edRoute(p);
|
||||||
|
|
||||||
if (p.status === "post-init") {
|
if (p.status === "load-site") {
|
||||||
return <Loading note={`page-${p.status}`} />;
|
return <Loading note={`page-${p.status}`} />;
|
||||||
}
|
}
|
||||||
if (p.status === "site-not-found" || p.status === "page-not-found") {
|
if (p.status === "site-not-found" || p.status === "page-not-found") {
|
||||||
|
|
@ -47,7 +47,12 @@ export const EdBase = () => {
|
||||||
<EdPane type="left" min_size={200} />
|
<EdPane type="left" min_size={200} />
|
||||||
<div className="flex flex-1 flex-col items-stretch">
|
<div className="flex flex-1 flex-col items-stretch">
|
||||||
<EdMid />
|
<EdMid />
|
||||||
<div className="flex flex-1 items-stretch">
|
<div
|
||||||
|
className={cx(
|
||||||
|
"flex flex-1 items-stretch",
|
||||||
|
p.mode === "mobile" ? mobileCSS : "bg-white"
|
||||||
|
)}
|
||||||
|
>
|
||||||
<EdMain />
|
<EdMain />
|
||||||
<EdPane type="right" min_size={240} />
|
<EdPane type="right" min_size={240} />
|
||||||
<EdRight />
|
<EdRight />
|
||||||
|
|
@ -138,3 +143,18 @@ const style = css`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const mobileCSS = css`
|
||||||
|
background-color: white;
|
||||||
|
background-image: linear-gradient(45deg, #fafafa 25%, transparent 25%),
|
||||||
|
linear-gradient(-45deg, #fafafa 25%, transparent 25%),
|
||||||
|
linear-gradient(45deg, transparent 75%, #fafafa 75%),
|
||||||
|
linear-gradient(-45deg, transparent 75%, #fafafa 75%);
|
||||||
|
|
||||||
|
background-size: 20px 20px;
|
||||||
|
background-position:
|
||||||
|
0 0,
|
||||||
|
0 10px,
|
||||||
|
10px -10px,
|
||||||
|
-10px 0px;
|
||||||
|
`;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export const EdRight = () => {
|
||||||
css`
|
css`
|
||||||
width: ${p.ui.layout.right}px;
|
width: ${p.ui.layout.right}px;
|
||||||
`,
|
`,
|
||||||
"border-l flex flex-col"
|
"border-l flex flex-col bg-white"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{!meta ? (
|
{!meta ? (
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ export const EDGlobal = {
|
||||||
clients: {} as Record<string, { id: string; username: string }>,
|
clients: {} as Record<string, { id: string; username: string }>,
|
||||||
status: "init" as
|
status: "init" as
|
||||||
| "init"
|
| "init"
|
||||||
| "post-init"
|
| "load-site"
|
||||||
| "reload"
|
| "reload"
|
||||||
| "site-not-found"
|
| "site-not-found"
|
||||||
| "page-not-found"
|
| "page-not-found"
|
||||||
|
|
@ -228,6 +228,8 @@ export const EDGlobal = {
|
||||||
prop_kind: "" as PropFieldKind,
|
prop_kind: "" as PropFieldKind,
|
||||||
prop_name: "",
|
prop_name: "",
|
||||||
on_close: () => {},
|
on_close: () => {},
|
||||||
|
typings: { status: "ok" as "ok" | "loading" | "error", err_msg: "" },
|
||||||
|
wb_render: () => {},
|
||||||
},
|
},
|
||||||
site: null as null | ((site_id: string) => void | Promise<void>),
|
site: null as null | ((site_id: string) => void | Promise<void>),
|
||||||
site_form: null as null | {
|
site_form: null as null | {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import { treeRebuild } from "./tree/build";
|
||||||
export const edRoute = async (p: PG) => {
|
export const edRoute = async (p: PG) => {
|
||||||
if (p.status === "ready" || p.status === "init") {
|
if (p.status === "ready" || p.status === "init") {
|
||||||
if (!p.site.domain && !p.site.name) {
|
if (!p.site.domain && !p.site.name) {
|
||||||
p.status = "post-init";
|
p.status = "load-site";
|
||||||
const site = await p.sync.site.load(p.site.id);
|
const site = await p.sync.site.load(p.site.id);
|
||||||
if (!site) {
|
if (!site) {
|
||||||
p.status = "site-not-found";
|
p.status = "site-not-found";
|
||||||
|
|
|
||||||
|
|
@ -7,63 +7,70 @@ export const ResponsiveToggle = () => {
|
||||||
const c = useGlobal(EDGlobal, "EDITOR");
|
const c = useGlobal(EDGlobal, "EDITOR");
|
||||||
const mode = c.mode;
|
const mode = c.mode;
|
||||||
const activeModeClassName = "border-b-2 border-blue-500";
|
const activeModeClassName = "border-b-2 border-blue-500";
|
||||||
return (
|
|
||||||
<ToolbarBox
|
const box = {
|
||||||
className="flex"
|
mobile: {
|
||||||
items={[
|
onClick() {
|
||||||
{
|
c.mode = "mobile";
|
||||||
onClick() {
|
w.isMobile = true;
|
||||||
c.mode = "mobile";
|
w.isDesktop = false;
|
||||||
w.isMobile = true;
|
localStorage.setItem("prasi-editor-mode", "mobile");
|
||||||
w.isDesktop = false;
|
c.render();
|
||||||
localStorage.setItem("prasi-editor-mode", "mobile");
|
},
|
||||||
c.render();
|
className: cx(mode === "mobile" && activeModeClassName),
|
||||||
},
|
content: (
|
||||||
className: cx(mode === "mobile" && activeModeClassName),
|
<svg
|
||||||
content: (
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
<svg
|
width="15"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
height="15"
|
||||||
width="15"
|
fill="none"
|
||||||
height="15"
|
viewBox="0 0 15 15"
|
||||||
fill="none"
|
>
|
||||||
viewBox="0 0 15 15"
|
<path
|
||||||
>
|
fill="currentColor"
|
||||||
<path
|
fillRule="evenodd"
|
||||||
fill="currentColor"
|
d="M4 2.5a.5.5 0 01.5-.5h6a.5.5 0 01.5.5v10a.5.5 0 01-.5.5h-6a.5.5 0 01-.5-.5v-10zM4.5 1A1.5 1.5 0 003 2.5v10A1.5 1.5 0 004.5 14h6a1.5 1.5 0 001.5-1.5v-10A1.5 1.5 0 0010.5 1h-6zM6 11.65a.35.35 0 100 .7h3a.35.35 0 100-.7H6z"
|
||||||
fillRule="evenodd"
|
clipRule="evenodd"
|
||||||
d="M4 2.5a.5.5 0 01.5-.5h6a.5.5 0 01.5.5v10a.5.5 0 01-.5.5h-6a.5.5 0 01-.5-.5v-10zM4.5 1A1.5 1.5 0 003 2.5v10A1.5 1.5 0 004.5 14h6a1.5 1.5 0 001.5-1.5v-10A1.5 1.5 0 0010.5 1h-6zM6 11.65a.35.35 0 100 .7h3a.35.35 0 100-.7H6z"
|
></path>
|
||||||
clipRule="evenodd"
|
</svg>
|
||||||
></path>
|
),
|
||||||
</svg>
|
},
|
||||||
),
|
desktop: {
|
||||||
},
|
onClick() {
|
||||||
{
|
c.mode = "desktop";
|
||||||
onClick() {
|
w.isMobile = false;
|
||||||
c.mode = "desktop";
|
w.isDesktop = true;
|
||||||
w.isMobile = false;
|
localStorage.setItem("prasi-editor-mode", "desktop");
|
||||||
w.isDesktop = true;
|
c.render();
|
||||||
localStorage.setItem("prasi-editor-mode", "desktop");
|
},
|
||||||
c.render();
|
className: cx(mode === "desktop" && activeModeClassName),
|
||||||
},
|
content: (
|
||||||
className: cx(mode === "desktop" && activeModeClassName),
|
<svg
|
||||||
content: (
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
<svg
|
width="15"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
height="15"
|
||||||
width="15"
|
fill="none"
|
||||||
height="15"
|
viewBox="0 0 15 15"
|
||||||
fill="none"
|
>
|
||||||
viewBox="0 0 15 15"
|
<path
|
||||||
>
|
fill="currentColor"
|
||||||
<path
|
fillRule="evenodd"
|
||||||
fill="currentColor"
|
d="M1 3.25A.25.25 0 011.25 3h12.5a.25.25 0 01.25.25v7.5a.25.25 0 01-.25.25H1.25a.25.25 0 01-.25-.25v-7.5zM1.25 2C.56 2 0 2.56 0 3.25v7.5C0 11.44.56 12 1.25 12h3.823l-.243 1.299a.55.55 0 00.54.651h4.26a.55.55 0 00.54-.651L9.927 12h3.823c.69 0 1.25-.56 1.25-1.25v-7.5C15 2.56 14.44 2 13.75 2H1.25zm7.76 10H5.99l-.198 1.05h3.416L9.01 12z"
|
||||||
fillRule="evenodd"
|
clipRule="evenodd"
|
||||||
d="M1 3.25A.25.25 0 011.25 3h12.5a.25.25 0 01.25.25v7.5a.25.25 0 01-.25.25H1.25a.25.25 0 01-.25-.25v-7.5zM1.25 2C.56 2 0 2.56 0 3.25v7.5C0 11.44.56 12 1.25 12h3.823l-.243 1.299a.55.55 0 00.54.651h4.26a.55.55 0 00.54-.651L9.927 12h3.823c.69 0 1.25-.56 1.25-1.25v-7.5C15 2.56 14.44 2 13.75 2H1.25zm7.76 10H5.99l-.198 1.05h3.416L9.01 12z"
|
></path>
|
||||||
clipRule="evenodd"
|
</svg>
|
||||||
></path>
|
),
|
||||||
</svg>
|
},
|
||||||
),
|
};
|
||||||
},
|
const items: any[] = [];
|
||||||
]}
|
if (c.site.responsive === "mobile-only") {
|
||||||
/>
|
items.push(box.mobile);
|
||||||
);
|
} else if (c.site.responsive === "desktop-only") {
|
||||||
|
items.push(box.desktop);
|
||||||
|
} else {
|
||||||
|
items.push(box.mobile);
|
||||||
|
items.push(box.desktop);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <ToolbarBox className="flex" items={items} />;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,9 @@ export const mainPerItemVisit = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (parts.props.className && !parts.props.className.includes("el-active")) {
|
||||||
|
parts.props.className += " el-active";
|
||||||
|
}
|
||||||
|
|
||||||
prop.onInput = (e) => {
|
prop.onInput = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
@ -160,10 +163,6 @@ export const mainPerItemVisit = (
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function getCaret(el: any) {
|
|
||||||
return getSelectionOffset(el);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setCaret(el: any, offset: any) {
|
function setCaret(el: any, offset: any) {
|
||||||
setSelectionOffset(el, offset[0], offset[1]);
|
setSelectionOffset(el, offset[0], offset[1]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,7 @@ export const EdMain = () => {
|
||||||
<div
|
<div
|
||||||
className={cx(
|
className={cx(
|
||||||
"flex flex-1 relative overflow-auto",
|
"flex flex-1 relative overflow-auto",
|
||||||
css`
|
p.mode === "mobile" ? "flex-col items-center" : ""
|
||||||
contain: content;
|
|
||||||
`
|
|
||||||
)}
|
)}
|
||||||
ref={(el) => {
|
ref={(el) => {
|
||||||
if (el) {
|
if (el) {
|
||||||
|
|
@ -75,23 +73,39 @@ export const EdMain = () => {
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{meta && <div className={mainStyle(p, meta, local)}>{local.cache}</div>}
|
<div className={mainStyle(p, meta)}>{local.cache}</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const mainStyle = (
|
const mainStyle = (p: PG, meta?: IMeta) => {
|
||||||
p: PG,
|
|
||||||
meta: IMeta,
|
|
||||||
local: { width: number; height: number }
|
|
||||||
) => {
|
|
||||||
let is_active = meta ? isMetaActive(p, meta) : false;
|
let is_active = meta ? isMetaActive(p, meta) : false;
|
||||||
|
|
||||||
const scale = parseInt(p.ui.zoom.replace("%", "")) / 100;
|
const scale = parseInt(p.ui.zoom.replace("%", "")) / 100;
|
||||||
|
|
||||||
|
let width = `${(1 / scale) * 100}%`;
|
||||||
|
if (p.mode === "mobile") {
|
||||||
|
width = `${(1 / scale) * 375}px`;
|
||||||
|
}
|
||||||
|
|
||||||
return cx(
|
return cx(
|
||||||
"absolute inset-0 flex",
|
"absolute flex",
|
||||||
css`
|
css`
|
||||||
width: ${(1 / scale) * 100}%;
|
contain: content;
|
||||||
|
`,
|
||||||
|
p.mode === "mobile"
|
||||||
|
? css`
|
||||||
|
border-left: 1px solid #ccc;
|
||||||
|
border-right: 1px solid #ccc;
|
||||||
|
background: white;
|
||||||
|
top: 0px;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: auto;
|
||||||
|
bottom: 0px;
|
||||||
|
`
|
||||||
|
: "inset-0",
|
||||||
|
css`
|
||||||
|
width: ${width};
|
||||||
transform: scale(${scale});
|
transform: scale(${scale});
|
||||||
transform-origin: 0% 0% 0px;
|
transform-origin: 0% 0% 0px;
|
||||||
`,
|
`,
|
||||||
|
|
|
||||||
|
|
@ -288,6 +288,8 @@ export const EdScriptMonaco: FC<{}> = () => {
|
||||||
}
|
}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
const stype = p.ui.popup.script.type;
|
const stype = p.ui.popup.script.type;
|
||||||
|
p.ui.popup.script.typings.status = "loading";
|
||||||
|
p.ui.popup.script.wb_render();
|
||||||
if ((value || "").includes(IMPORT_SEPARATOR)) {
|
if ((value || "").includes(IMPORT_SEPARATOR)) {
|
||||||
const valparts = (value || "").split(IMPORT_SEPARATOR + "\n");
|
const valparts = (value || "").split(IMPORT_SEPARATOR + "\n");
|
||||||
if (valparts.length === 2) local.value = valparts[1];
|
if (valparts.length === 2) local.value = valparts[1];
|
||||||
|
|
@ -318,6 +320,8 @@ export const EdScriptMonaco: FC<{}> = () => {
|
||||||
arg.page_id = p.page.cur.id;
|
arg.page_id = p.page.cur.id;
|
||||||
}
|
}
|
||||||
let scope: boolean | ParsedScope = false;
|
let scope: boolean | ParsedScope = false;
|
||||||
|
p.ui.popup.script.typings.status = "ok";
|
||||||
|
p.ui.popup.script.typings.err_msg = "";
|
||||||
if (stype === "prop-master") {
|
if (stype === "prop-master") {
|
||||||
p.sync.code.edit({
|
p.sync.code.edit({
|
||||||
type: "prop-master",
|
type: "prop-master",
|
||||||
|
|
@ -327,7 +331,7 @@ export const EdScriptMonaco: FC<{}> = () => {
|
||||||
...arg,
|
...arg,
|
||||||
});
|
});
|
||||||
} else if (stype === "prop-instance") {
|
} else if (stype === "prop-instance") {
|
||||||
scope = await p.sync.code.edit({
|
const code_result = await p.sync.code.edit({
|
||||||
type: "prop-instance",
|
type: "prop-instance",
|
||||||
mode: mode,
|
mode: mode,
|
||||||
prop_name: p.ui.popup.script.prop_name,
|
prop_name: p.ui.popup.script.prop_name,
|
||||||
|
|
@ -335,18 +339,32 @@ export const EdScriptMonaco: FC<{}> = () => {
|
||||||
value: compress(encode.encode(value || "")),
|
value: compress(encode.encode(value || "")),
|
||||||
...arg,
|
...arg,
|
||||||
});
|
});
|
||||||
|
if (typeof code_result === "string") {
|
||||||
|
p.ui.popup.script.typings.status = "error";
|
||||||
|
p.ui.popup.script.typings.err_msg = code_result;
|
||||||
|
} else if (typeof code_result === "object") {
|
||||||
|
scope = code_result;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
scope = await p.sync.code.edit({
|
const code_result = await p.sync.code.edit({
|
||||||
type: "adv",
|
type: "adv",
|
||||||
mode: mode,
|
mode: mode,
|
||||||
item_id: active.item_id,
|
item_id: active.item_id,
|
||||||
value: compress(encode.encode(value || "")),
|
value: compress(encode.encode(value || "")),
|
||||||
...arg,
|
...arg,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (typeof code_result === "string") {
|
||||||
|
p.ui.popup.script.typings.status = "error";
|
||||||
|
p.ui.popup.script.typings.err_msg = code_result;
|
||||||
|
} else if (typeof code_result === "object") {
|
||||||
|
scope = code_result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (typeof scope === "object") {
|
if (typeof scope === "object") {
|
||||||
meta.item.script = scope;
|
meta.item.script = scope;
|
||||||
}
|
}
|
||||||
|
p.ui.popup.script.wb_render();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
p.ui.popup.script.on_close = () => {
|
p.ui.popup.script.on_close = () => {
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,12 @@ import { EdScriptMonaco } from "./monaco";
|
||||||
import { EdScriptSnippet } from "./snippet";
|
import { EdScriptSnippet } from "./snippet";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { Loading } from "../../../../../utils/ui/loading";
|
import { Loading } from "../../../../../utils/ui/loading";
|
||||||
|
import { Tooltip } from "../../../../../utils/ui/tooltip";
|
||||||
|
|
||||||
export const EdScriptWorkbench = () => {
|
export const EdScriptWorkbench = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
const local = useLocal({ active_id: "" });
|
const local = useLocal({ active_id: "" });
|
||||||
|
p.ui.popup.script.wb_render = local.render;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!local.active_id) {
|
if (!local.active_id) {
|
||||||
|
|
@ -27,103 +29,144 @@ export const EdScriptWorkbench = () => {
|
||||||
canBack: active.script_nav.list.length > 0,
|
canBack: active.script_nav.list.length > 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const is_error =
|
||||||
|
p.ui.popup.script.typings.status === "error" &&
|
||||||
|
p.ui.popup.script.mode === "js";
|
||||||
return (
|
return (
|
||||||
<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 border-b items-stretch">
|
<div
|
||||||
<div className="border-r px-2 flex items-center">
|
className={cx(
|
||||||
<div
|
"flex border-b items-stretch justify-between",
|
||||||
className={cx(
|
is_error && "bg-red-100"
|
||||||
scriptNav.canBack
|
|
||||||
? "cursor-pointer hover:text-blue-400"
|
|
||||||
: "text-slate-200"
|
|
||||||
)}
|
|
||||||
onClick={() => {
|
|
||||||
if (scriptNav.canBack) {
|
|
||||||
active.script_nav.idx = active.script_nav.idx - 1;
|
|
||||||
const item = active.script_nav.list[active.script_nav.idx];
|
|
||||||
|
|
||||||
if (item) {
|
|
||||||
active.item_id = item.item_id;
|
|
||||||
active.comp_id = item.comp_id || "";
|
|
||||||
active.instance = {
|
|
||||||
item_id: item.instance?.item_id || "",
|
|
||||||
comp_id: item.instance?.comp_id || "",
|
|
||||||
};
|
|
||||||
p.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ChevronLeft />
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={cx(
|
|
||||||
scriptNav.canNext
|
|
||||||
? "cursor-pointer hover:text-blue-400"
|
|
||||||
: "text-slate-200"
|
|
||||||
)}
|
|
||||||
onClick={() => {
|
|
||||||
if (scriptNav.canNext) {
|
|
||||||
active.script_nav.idx = active.script_nav.idx + 1;
|
|
||||||
const item = active.script_nav.list[active.script_nav.idx];
|
|
||||||
|
|
||||||
if (item) {
|
|
||||||
active.item_id = item.item_id;
|
|
||||||
active.comp_id = item.comp_id || "";
|
|
||||||
active.instance = {
|
|
||||||
item_id: item.instance?.item_id || "",
|
|
||||||
comp_id: item.instance?.comp_id || "",
|
|
||||||
};
|
|
||||||
p.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ChevronRight />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{p.ui.popup.script.type === "prop-master" && <CompTitleMaster />}
|
|
||||||
{p.ui.popup.script.type === "prop-instance" && <CompTitleInstance />}
|
|
||||||
{p.ui.popup.script.type === "item" && (
|
|
||||||
<>
|
|
||||||
<div className="flex p-2 space-x-1">
|
|
||||||
{[
|
|
||||||
{ type: "js", color: "#e9522c" },
|
|
||||||
{ type: "css", color: "#188228" },
|
|
||||||
{ type: "html", color: "#2c3e83" },
|
|
||||||
].map((e) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
key={e.type}
|
|
||||||
className={cx(
|
|
||||||
css`
|
|
||||||
color: ${e.color};
|
|
||||||
border: 1px solid ${e.color};
|
|
||||||
`,
|
|
||||||
"uppercase text-white text-[12px] cursor-pointer flex items-center justify-center transition-all hover:opacity-100 w-[40px] text-center",
|
|
||||||
p.ui.popup.script.mode === e.type
|
|
||||||
? css`
|
|
||||||
background: ${e.color};
|
|
||||||
color: white;
|
|
||||||
`
|
|
||||||
: "opacity-30"
|
|
||||||
)}
|
|
||||||
onClick={() => {
|
|
||||||
p.ui.popup.script.mode = e.type as any;
|
|
||||||
p.render();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{e.type}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
{p.ui.popup.script.mode === "js" &&
|
|
||||||
p.ui.popup.script.type === "item" && <EdScriptSnippet />}
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
|
>
|
||||||
|
<div className={cx("flex items-stretch")}>
|
||||||
|
<div className="border-r px-2 flex items-center">
|
||||||
|
<div
|
||||||
|
className={cx(
|
||||||
|
scriptNav.canBack
|
||||||
|
? "cursor-pointer hover:text-blue-400"
|
||||||
|
: "text-slate-200"
|
||||||
|
)}
|
||||||
|
onClick={() => {
|
||||||
|
if (scriptNav.canBack) {
|
||||||
|
active.script_nav.idx = active.script_nav.idx - 1;
|
||||||
|
const item = active.script_nav.list[active.script_nav.idx];
|
||||||
|
|
||||||
|
if (item) {
|
||||||
|
active.item_id = item.item_id;
|
||||||
|
active.comp_id = item.comp_id || "";
|
||||||
|
active.instance = {
|
||||||
|
item_id: item.instance?.item_id || "",
|
||||||
|
comp_id: item.instance?.comp_id || "",
|
||||||
|
};
|
||||||
|
p.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ChevronLeft />
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={cx(
|
||||||
|
scriptNav.canNext
|
||||||
|
? "cursor-pointer hover:text-blue-400"
|
||||||
|
: "text-slate-200"
|
||||||
|
)}
|
||||||
|
onClick={() => {
|
||||||
|
if (scriptNav.canNext) {
|
||||||
|
active.script_nav.idx = active.script_nav.idx + 1;
|
||||||
|
const item = active.script_nav.list[active.script_nav.idx];
|
||||||
|
|
||||||
|
if (item) {
|
||||||
|
active.item_id = item.item_id;
|
||||||
|
active.comp_id = item.comp_id || "";
|
||||||
|
active.instance = {
|
||||||
|
item_id: item.instance?.item_id || "",
|
||||||
|
comp_id: item.instance?.comp_id || "",
|
||||||
|
};
|
||||||
|
p.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ChevronRight />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{p.ui.popup.script.type === "prop-master" && <CompTitleMaster />}
|
||||||
|
{p.ui.popup.script.type === "prop-instance" && (
|
||||||
|
<CompTitleInstance />
|
||||||
|
)}
|
||||||
|
{p.ui.popup.script.type === "item" && (
|
||||||
|
<>
|
||||||
|
<div className="flex p-2 space-x-1">
|
||||||
|
{[
|
||||||
|
{ type: "js", color: "#e9522c" },
|
||||||
|
{ type: "css", color: "#188228" },
|
||||||
|
{ type: "html", color: "#2c3e83" },
|
||||||
|
].map((e) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={e.type}
|
||||||
|
className={cx(
|
||||||
|
css`
|
||||||
|
color: ${e.color};
|
||||||
|
border: 1px solid ${e.color};
|
||||||
|
`,
|
||||||
|
"uppercase text-white text-[12px] cursor-pointer flex items-center justify-center transition-all hover:opacity-100 w-[40px] text-center",
|
||||||
|
p.ui.popup.script.mode === e.type
|
||||||
|
? css`
|
||||||
|
background: ${e.color};
|
||||||
|
color: white;
|
||||||
|
`
|
||||||
|
: "opacity-30"
|
||||||
|
)}
|
||||||
|
onClick={() => {
|
||||||
|
p.ui.popup.script.mode = e.type as any;
|
||||||
|
p.render();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{e.type}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
{p.ui.popup.script.mode === "js" &&
|
||||||
|
p.ui.popup.script.type === "item" && <EdScriptSnippet />}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center text-xs pr-2">
|
||||||
|
{p.ui.popup.script.mode === "js" && (
|
||||||
|
<div>
|
||||||
|
{
|
||||||
|
(
|
||||||
|
{
|
||||||
|
ok: <div className="text-green-700">Typings: OK</div>,
|
||||||
|
loading: <div className="text-slate-500">Loading ⌛</div>,
|
||||||
|
error: (
|
||||||
|
<Tooltip
|
||||||
|
content={
|
||||||
|
<div className="font-mono whitespace-pre-wrap text-[11px]">
|
||||||
|
{p.ui.popup.script.typings.err_msg}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
delay={0}
|
||||||
|
>
|
||||||
|
<div className="text-red-700 border-red-700 border bg-white bg-opacity-80 p-1">
|
||||||
|
⚠️ Typings: ERROR
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
),
|
||||||
|
} as any
|
||||||
|
)[p.ui.popup.script.typings.status]
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="relative flex flex-1">
|
<div className="relative flex flex-1">
|
||||||
{local.active_id === active.item_id ? (
|
{local.active_id === active.item_id ? (
|
||||||
<EdScriptMonaco />
|
<EdScriptMonaco />
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,15 @@ export const edActionDelete = async (p: PG, item: IContent) => {
|
||||||
if (meta) {
|
if (meta) {
|
||||||
const mitem = meta.mitem;
|
const mitem = meta.mitem;
|
||||||
if (mitem) {
|
if (mitem) {
|
||||||
mitem.parent.forEach((e, k) => {
|
mitem.doc?.transact(() => {
|
||||||
if (e == mitem) {
|
mitem.parent.forEach((e, k) => {
|
||||||
deleteByParent(p, mitem, k);
|
if (e == mitem) {
|
||||||
}
|
deleteByParent(p, mitem, k);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
await treeRebuild(p);
|
||||||
|
p.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -23,17 +27,19 @@ export const edActionDeleteById = async (p: PG, id: string) => {
|
||||||
if (meta) {
|
if (meta) {
|
||||||
const mitem = meta.mitem;
|
const mitem = meta.mitem;
|
||||||
if (mitem) {
|
if (mitem) {
|
||||||
mitem.parent.forEach((e, k) => {
|
mitem.doc?.transact(() => {
|
||||||
if (e == mitem) {
|
mitem.parent.forEach((e, k) => {
|
||||||
deleteByParent(p, mitem, k);
|
if (e == mitem) {
|
||||||
}
|
deleteByParent(p, mitem, k);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
await treeRebuild(p);
|
||||||
|
p.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteByParent = (p: PG, mitem: MItem, index: number) => {
|
const deleteByParent = (p: PG, mitem: MItem, index: number) => {
|
||||||
const mchild = mitem.parent.get(index);
|
|
||||||
mitem.parent.delete(index);
|
mitem.parent.delete(index);
|
||||||
treeRebuild(p);
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -122,12 +122,14 @@ export const nodeRender: NodeRender<IMeta> = (node, prm) => {
|
||||||
active.item_id = item.id;
|
active.item_id = item.id;
|
||||||
p.ui.tree.search = "";
|
p.ui.tree.search = "";
|
||||||
p.render();
|
p.render();
|
||||||
|
|
||||||
if ((item as IContent).type === "text") {
|
if ((item as IContent).type === "text") {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (document.activeElement?.tagName === "INPUT") {
|
if (document.activeElement?.tagName === "INPUT") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const el_active = document.querySelector(".el-active") as any;
|
const el_active = document.querySelector(".el-active") as any;
|
||||||
|
|
||||||
if (el_active) {
|
if (el_active) {
|
||||||
setEndOfContenteditable(el_active);
|
setEndOfContenteditable(el_active);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue