wip fix copy paste
This commit is contained in:
parent
122aba4339
commit
5249eb7deb
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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:")) {
|
||||
|
|
|
|||
|
|
@ -126,7 +126,8 @@ export const EdTreeCtxMenu = ({
|
|||
)}
|
||||
{local.allowCopy &&
|
||||
local.allowPaste &&
|
||||
!isComponent &&
|
||||
(!isComponent ||
|
||||
(isComponent && (item as IItem).component?.props.child)) &&
|
||||
item.type !== "text" && (
|
||||
<MenuItem label="Paste" onClick={() => edActionPaste(p, item)} />
|
||||
)}
|
||||
|
|
|
|||
Loading…
Reference in New Issue