wip fix copy paste etc
This commit is contained in:
parent
713ac3e6f6
commit
ca7d469a8e
|
|
@ -1,4 +1,4 @@
|
||||||
import { transform } from "esbuild";
|
import { TransformResult, transform } from "esbuild";
|
||||||
import { g } from "utils/global";
|
import { g } from "utils/global";
|
||||||
import { Doc } from "yjs";
|
import { Doc } from "yjs";
|
||||||
import { MContent } from "../../../../web/src/utils/types/general";
|
import { MContent } from "../../../../web/src/utils/types/general";
|
||||||
|
|
@ -41,14 +41,17 @@ export const code_edit: SAction["code"]["edit"] = async function (
|
||||||
|
|
||||||
if (mitem) {
|
if (mitem) {
|
||||||
if (arg.type === "adv") {
|
if (arg.type === "adv") {
|
||||||
|
const mode = arg.mode;
|
||||||
try {
|
try {
|
||||||
const res = await transform(`render(${src})`, {
|
let res = undefined as undefined | TransformResult;
|
||||||
|
if (mode === "js") {
|
||||||
|
res = await transform(`render(${src})`, {
|
||||||
jsx: "transform",
|
jsx: "transform",
|
||||||
format: "cjs",
|
format: "cjs",
|
||||||
loader: "tsx",
|
loader: "tsx",
|
||||||
});
|
});
|
||||||
|
}
|
||||||
doc?.transact(() => {
|
doc?.transact(() => {
|
||||||
const mode = arg.mode;
|
|
||||||
let adv = mitem.get("adv");
|
let adv = mitem.get("adv");
|
||||||
if (!adv) {
|
if (!adv) {
|
||||||
mitem.set("adv", new Y.Map() as any);
|
mitem.set("adv", new Y.Map() as any);
|
||||||
|
|
@ -59,7 +62,7 @@ export const code_edit: SAction["code"]["edit"] = async function (
|
||||||
try {
|
try {
|
||||||
if (adv) {
|
if (adv) {
|
||||||
adv.set(mode, src);
|
adv.set(mode, src);
|
||||||
if (mode === "js") {
|
if (mode === "js" && res) {
|
||||||
adv.set("jsBuilt", res.code);
|
adv.set("jsBuilt", res.code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -236,6 +236,7 @@ export const EDGlobal = {
|
||||||
script: {
|
script: {
|
||||||
open: false,
|
open: false,
|
||||||
mode: "js" as "js" | "css" | "html",
|
mode: "js" as "js" | "css" | "html",
|
||||||
|
lastMode: "js" as "js" | "css" | "html",
|
||||||
type: "item" as "item" | "prop-master" | "prop-instance",
|
type: "item" as "item" | "prop-master" | "prop-instance",
|
||||||
prop_kind: "" as PropFieldKind,
|
prop_kind: "" as PropFieldKind,
|
||||||
prop_name: "",
|
prop_name: "",
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { FC, ReactNode } from "react";
|
||||||
import { useGlobal, useLocal } from "web-utils";
|
import { useGlobal, useLocal } from "web-utils";
|
||||||
import { EDGlobal } from "../../../logic/ed-global";
|
import { EDGlobal } from "../../../logic/ed-global";
|
||||||
import { pagePicker, reloadPagePicker } from "./page-reload";
|
import { pagePicker, reloadPagePicker } from "./page-reload";
|
||||||
|
import { validate } from "uuid";
|
||||||
export type PageItem = {
|
export type PageItem = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -76,7 +76,7 @@ export const edPageTreeRender: NodeRender<PageItem> = (
|
||||||
data: {
|
data: {
|
||||||
name: local.rename_to,
|
name: local.rename_to,
|
||||||
id_site: p.site.id,
|
id_site: p.site.id,
|
||||||
parent_id: rename_id,
|
parent_id: validate(rename_id) ? rename_id : null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,17 @@ export const EdScriptWorkbench = () => {
|
||||||
canBack: active.script_nav.list.length > 0,
|
canBack: active.script_nav.list.length > 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (p.ui.popup.script.type === "item") {
|
||||||
|
setTimeout(() => {
|
||||||
|
p.ui.popup.script.mode = p.ui.popup.script.lastMode;
|
||||||
|
p.render();
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
|
||||||
const is_error =
|
const is_error =
|
||||||
p.ui.popup.script.typings.status === "error" &&
|
p.ui.popup.script.typings.status === "error" &&
|
||||||
p.ui.popup.script.mode === "js";
|
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 ">
|
||||||
|
|
@ -115,7 +123,7 @@ export const EdScriptWorkbench = () => {
|
||||||
border: 1px solid ${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",
|
"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
|
p.ui.popup.script.lastMode === e.type
|
||||||
? css`
|
? css`
|
||||||
background: ${e.color};
|
background: ${e.color};
|
||||||
color: white;
|
color: white;
|
||||||
|
|
@ -124,6 +132,7 @@ export const EdScriptWorkbench = () => {
|
||||||
)}
|
)}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
p.ui.popup.script.mode = e.type as any;
|
p.ui.popup.script.mode = e.type as any;
|
||||||
|
p.ui.popup.script.lastMode = e.type as any;
|
||||||
p.render();
|
p.render();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ export const FieldNumUnit: FC<{
|
||||||
}) => {
|
}) => {
|
||||||
const local = useLocal({
|
const local = useLocal({
|
||||||
val: 0,
|
val: 0,
|
||||||
|
val_str: "",
|
||||||
|
focus: false,
|
||||||
unit: "",
|
unit: "",
|
||||||
drag: { clientX: 0, old: 0 },
|
drag: { clientX: 0, old: 0 },
|
||||||
dragging: false,
|
dragging: false,
|
||||||
|
|
@ -57,6 +59,9 @@ export const FieldNumUnit: FC<{
|
||||||
}
|
}
|
||||||
if (!parseInt(val)) unt = "";
|
if (!parseInt(val)) unt = "";
|
||||||
}
|
}
|
||||||
|
if (!local.focus) {
|
||||||
|
local.val_str = val;
|
||||||
|
}
|
||||||
local.val = parseInt(val) || 0;
|
local.val = parseInt(val) || 0;
|
||||||
if (positiveOnly && local.val < 0) {
|
if (positiveOnly && local.val < 0) {
|
||||||
local.val = Math.max(0, local.val);
|
local.val = Math.max(0, local.val);
|
||||||
|
|
@ -154,9 +159,18 @@ export const FieldNumUnit: FC<{
|
||||||
!!disabled && "text-center text-gray-400"
|
!!disabled && "text-center text-gray-400"
|
||||||
)}
|
)}
|
||||||
disabled={!!disabled}
|
disabled={!!disabled}
|
||||||
value={typeof disabled === "string" ? disabled : local.val}
|
value={typeof disabled === "string" ? disabled : local.val_str}
|
||||||
|
onFocus={() => {
|
||||||
|
local.focus = true;
|
||||||
|
local.render();
|
||||||
|
}}
|
||||||
|
onBlur={() => {
|
||||||
|
local.focus = false;
|
||||||
|
local.render();
|
||||||
|
}}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
local.val = parseInt(e.currentTarget.value) || 0;
|
local.val_str = e.currentTarget.value;
|
||||||
|
local.val = parseInt(local.val_str) || 0;
|
||||||
local.render();
|
local.render();
|
||||||
update(local.val + local.unit);
|
update(local.val + local.unit);
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { deepClone } from "web-utils";
|
||||||
import { IContent } from "../../../../../../../utils/types/general";
|
import { IContent } from "../../../../../../../utils/types/general";
|
||||||
import { PG } from "../../../../../logic/ed-global";
|
import { PG } from "../../../../../logic/ed-global";
|
||||||
|
|
||||||
|
|
@ -6,9 +7,37 @@ export const edActionCopy = async (p: PG, item: IContent) => {
|
||||||
name: "clipboard-read",
|
name: "clipboard-read",
|
||||||
allowWithoutGesture: false,
|
allowWithoutGesture: false,
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
|
const new_item = deepClone(item);
|
||||||
|
|
||||||
|
const walk = (item: IContent) => {
|
||||||
|
if (item.type !== "text") {
|
||||||
|
for (const [key, child] of Object.entries(item.childs)) {
|
||||||
|
if (child && Object.keys(child).length === 1) {
|
||||||
|
const meta = p.page.meta[child.id];
|
||||||
|
if (meta) {
|
||||||
|
const new_child = deepClone(meta.item);
|
||||||
|
item.childs[key as any] = new_child;
|
||||||
|
walk(new_child);
|
||||||
|
|
||||||
|
if (new_child.component?.props) {
|
||||||
|
for (const [k, v] of Object.entries(new_child.component.props)) {
|
||||||
|
if (v.meta?.type === "content-element" && v.content) {
|
||||||
|
walk(v.content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
walk(new_item);
|
||||||
|
|
||||||
if (perm.state !== "granted") {
|
if (perm.state !== "granted") {
|
||||||
await navigator.clipboard.read();
|
await navigator.clipboard.read();
|
||||||
}
|
}
|
||||||
let str = `prasi-clipboard:` + JSON.stringify(item);
|
let str = `prasi-clipboard:` + JSON.stringify(new_item);
|
||||||
navigator.clipboard.writeText(str);
|
navigator.clipboard.writeText(str);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,68 @@
|
||||||
import { syncronize } from "y-pojo";
|
import { syncronize } from "y-pojo";
|
||||||
import { fillID } from "../../../../../../../render/editor/tools/fill-id";
|
import { fillID } from "../../../../../../../render/editor/tools/fill-id";
|
||||||
import { IContent } from "../../../../../../../utils/types/general";
|
import { IContent } from "../../../../../../../utils/types/general";
|
||||||
import { MItem } from "../../../../../../../utils/types/item";
|
import { IItem, MItem } from "../../../../../../../utils/types/item";
|
||||||
|
import { MSection } from "../../../../../../../utils/types/section";
|
||||||
import { getMetaById } from "../../../../../logic/active/get-meta";
|
import { getMetaById } from "../../../../../logic/active/get-meta";
|
||||||
import { PG, active } from "../../../../../logic/ed-global";
|
import { PG, active } from "../../../../../logic/ed-global";
|
||||||
import { treeRebuild } from "../../../../../logic/tree/build";
|
import { treeRebuild } from "../../../../../logic/tree/build";
|
||||||
|
import { TypedArray } from "yjs-types";
|
||||||
|
import { loadComponent } from "../../../../../logic/comp/load";
|
||||||
|
|
||||||
export const edActionPaste = async (p: PG, item: IContent) => {
|
export const edActionPaste = async (p: PG, item: IContent) => {
|
||||||
const mitem = getMetaById(p, item.id)?.mitem;
|
let mitem = getMetaById(p, item.id)?.mitem;
|
||||||
if (mitem) {
|
if (mitem) {
|
||||||
const res = await navigator.clipboard.readText();
|
const res = await navigator.clipboard.readText();
|
||||||
if (typeof res === "string" && res.startsWith("prasi-clipboard:")) {
|
if (typeof res === "string" && res.startsWith("prasi-clipboard:")) {
|
||||||
const clip = JSON.parse(
|
const clip = JSON.parse(
|
||||||
res.substring("prasi-clipboard:".length)
|
res.substring("prasi-clipboard:".length)
|
||||||
) as IContent;
|
) as IItem;
|
||||||
|
|
||||||
|
const load_comp_ids = new Set<string>();
|
||||||
|
const walk = (item: IItem) => {
|
||||||
|
if (item.component?.id && !p.comp.list[item.component.id]) {
|
||||||
|
load_comp_ids.add(item.component.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.component?.props) {
|
||||||
|
for (const [k, v] of Object.entries(item.component.props)) {
|
||||||
|
if (v.meta?.type === "content-element" && v.content) {
|
||||||
|
walk(v.content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.childs) {
|
||||||
|
for (const child of item.childs) {
|
||||||
|
if (child.type === "item") walk(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
walk(clip);
|
||||||
|
if (load_comp_ids.size > 0) {
|
||||||
|
for (const id of load_comp_ids) {
|
||||||
|
await loadComponent(p, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mchilds = mitem.get("childs") as
|
||||||
|
| TypedArray<MItem | MSection>
|
||||||
|
| undefined;
|
||||||
|
|
||||||
|
if ((clip as any).type === "section") {
|
||||||
|
const mroot = p.page.doc?.getMap("map").get("root");
|
||||||
|
if (mroot) {
|
||||||
|
mchilds = mroot.get("childs") as any;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mitem.doc?.transact(() => {
|
mitem.doc?.transact(() => {
|
||||||
const mchilds = mitem.get("childs");
|
|
||||||
if (mchilds) {
|
if (mchilds) {
|
||||||
let child: any = { ...clip };
|
let child: any = { ...clip };
|
||||||
if (item.type === "section") {
|
|
||||||
child = { ...clip, type: "item" };
|
|
||||||
} else {
|
|
||||||
if (item.type === "text") {
|
if (item.type === "text") {
|
||||||
(mitem as MItem).set("type", "item");
|
(mitem as MItem).set("type", "item");
|
||||||
item.type = "item" as any;
|
item.type = "item" as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clip.type === "section") {
|
|
||||||
child = { ...clip, type: "item" };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const map = new Y.Map();
|
const map = new Y.Map();
|
||||||
const newchild = fillID(child);
|
const newchild = fillID(child);
|
||||||
syncronize(map, newchild);
|
syncronize(map, newchild);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue