diff --git a/app/web/src/nova/ed/panel/tree/node/item/action/copy.tsx b/app/web/src/nova/ed/panel/tree/node/item/action/copy.tsx index 6e292843..99c2d37a 100644 --- a/app/web/src/nova/ed/panel/tree/node/item/action/copy.tsx +++ b/app/web/src/nova/ed/panel/tree/node/item/action/copy.tsx @@ -1,6 +1,7 @@ import { deepClone } from "web-utils"; import { IContent } from "../../../../../../../utils/types/general"; import { PG } from "../../../../../logic/ed-global"; +import { getMetaById } from "../../../../../logic/active/get-meta"; export const edActionCopy = async (p: PG, item: IContent) => { const perm = await navigator.permissions.query({ @@ -9,9 +10,18 @@ export const edActionCopy = async (p: PG, item: IContent) => { } as any); const new_item = deepClone(item); + const walk = (_item: IContent) => { + let item = _item; - const walk = (item: IContent) => { if (item.type !== "text") { + if (item.type === "item" && item.component?.props) { + for (const [k, v] of Object.entries(item.component.props)) { + if (v.content) { + walk(v.content); + } + } + } + for (const [key, child] of Object.entries(item.childs)) { if (child && Object.keys(child).length === 1) { const meta = p.page.meta[child.id]; @@ -19,14 +29,6 @@ export const edActionCopy = async (p: PG, item: IContent) => { 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); - } - } - } } } } diff --git a/app/web/src/nova/ed/panel/tree/node/item/action/cut.tsx b/app/web/src/nova/ed/panel/tree/node/item/action/cut.tsx index 9f43ff90..f30a40f6 100644 --- a/app/web/src/nova/ed/panel/tree/node/item/action/cut.tsx +++ b/app/web/src/nova/ed/panel/tree/node/item/action/cut.tsx @@ -1,3 +1,4 @@ +import { deepClone } from "web-utils"; import { IContent } from "../../../../../../../utils/types/general"; import { getMetaById } from "../../../../../logic/active/get-meta"; import { PG } from "../../../../../logic/ed-global"; @@ -8,9 +9,34 @@ export const edActionCut = async (p: PG, item: IContent) => { name: "clipboard-read", allowWithoutGesture: false, } as any); - if (perm.state !== "granted") { - await navigator.clipboard.read(); - } + + const new_item = deepClone(item); + const walk = (_item: IContent) => { + let item = _item; + + if (item.type !== "text") { + if (item.type === "item" && item.component?.props) { + for (const [k, v] of Object.entries(item.component.props)) { + if (v.content) { + walk(v.content); + } + } + } + + 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); + } + } + } + } + }; + walk(new_item); + let str = `prasi-clipboard:` + JSON.stringify(item); navigator.clipboard.writeText(str); diff --git a/app/web/src/nova/ed/panel/tree/node/item/action/paste.tsx b/app/web/src/nova/ed/panel/tree/node/item/action/paste.tsx index 0d0f49db..0ca6729c 100644 --- a/app/web/src/nova/ed/panel/tree/node/item/action/paste.tsx +++ b/app/web/src/nova/ed/panel/tree/node/item/action/paste.tsx @@ -11,6 +11,12 @@ import { loadComponent } from "../../../../../logic/comp/load"; export const edActionPaste = async (p: PG, item: IContent) => { let mitem = getMetaById(p, item.id)?.mitem; + + if ((item as IItem).component?.props["child"]) { + const content_id = (item as IItem).component?.props["child"]?.content?.id; + if (content_id) mitem = getMetaById(p, content_id)?.mitem; + } + if (mitem) { const res = await navigator.clipboard.readText(); if (typeof res === "string" && res.startsWith("prasi-clipboard:")) { diff --git a/app/web/src/nova/ed/panel/tree/node/item/ctx-menu.tsx b/app/web/src/nova/ed/panel/tree/node/item/ctx-menu.tsx index 58afccc9..532aa98a 100644 --- a/app/web/src/nova/ed/panel/tree/node/item/ctx-menu.tsx +++ b/app/web/src/nova/ed/panel/tree/node/item/ctx-menu.tsx @@ -126,7 +126,8 @@ export const EdTreeCtxMenu = ({ )} {local.allowCopy && local.allowPaste && - !isComponent && + (!isComponent || + (isComponent && (item as IItem).component?.props.child)) && item.type !== "text" && ( edActionPaste(p, item)} /> )}