@nookuio/iframe 1.0.0 → 1.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +11 -2
- package/dist/constants.mjs +9 -1
- package/dist/drag-drop/dragEnd.d.ts +2 -0
- package/dist/drag-drop/dragEnd.js +27 -0
- package/dist/drag-drop/dragEnd.mjs +23 -0
- package/dist/drag-drop/dragMove.d.ts +2 -0
- package/dist/drag-drop/dragMove.js +46 -0
- package/dist/drag-drop/dragMove.mjs +40 -0
- package/dist/drag-drop/dragReorder.d.ts +3 -0
- package/dist/drag-drop/dragReorder.js +60 -0
- package/dist/drag-drop/dragReorder.mjs +64 -0
- package/dist/drag-drop/dragStart.d.ts +9 -0
- package/dist/drag-drop/dragStart.js +60 -0
- package/dist/drag-drop/dragStart.mjs +55 -0
- package/dist/drag-drop/helpers.d.ts +42 -0
- package/dist/drag-drop/helpers.js +205 -0
- package/dist/drag-drop/helpers.mjs +188 -0
- package/dist/drag-drop/highlight.d.ts +16 -0
- package/dist/drag-drop/highlight.js +32 -0
- package/dist/drag-drop/highlight.mjs +22 -0
- package/dist/drag-drop/index.d.ts +24 -0
- package/dist/drag-drop/index.js +106 -0
- package/dist/drag-drop/index.mjs +83 -0
- package/dist/drag-drop/types.d.ts +123 -0
- package/dist/drag-drop/types.js +1 -0
- package/dist/drag-drop/types.mjs +0 -0
- package/dist/drag-drop backup/dragDropManager.d.ts +101 -0
- package/dist/drag-drop backup/dragDropManager.js +204 -0
- package/dist/drag-drop backup/dragDropManager.mjs +183 -0
- package/dist/drag-drop backup/index.d.ts +3 -0
- package/dist/drag-drop backup/index.js +38 -0
- package/dist/drag-drop backup/index.mjs +3 -0
- package/dist/drag-drop backup/types.d.ts +80 -0
- package/dist/drag-drop backup/types.js +1 -0
- package/dist/drag-drop backup/types.mjs +0 -0
- package/dist/drag-drop backup/utils.d.ts +41 -0
- package/dist/drag-drop backup/utils.js +93 -0
- package/dist/drag-drop backup/utils.mjs +68 -0
- package/dist/editor.d.ts +1 -7
- package/dist/editor.js +2 -2
- package/dist/editor.mjs +1 -1
- package/dist/iframe.d.ts +2 -8
- package/dist/iframe.js +46 -43
- package/dist/iframe.mjs +48 -46
- package/dist/types.d.ts +17 -3
- package/package.json +3 -2
- package/dist/createClient.d.ts +0 -51
- package/dist/createClient.js +0 -118
- package/dist/createClient.mjs +0 -114
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export interface DragDropContext {
|
|
2
|
+
/**
|
|
3
|
+
* Start dragging an element
|
|
4
|
+
*/
|
|
5
|
+
startDrag: (options: {
|
|
6
|
+
elementId: string;
|
|
7
|
+
path: string;
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
}) => Promise<{
|
|
11
|
+
dragId: string;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Update drag position
|
|
15
|
+
*/
|
|
16
|
+
updateDragPosition: (options: {
|
|
17
|
+
dragId: string;
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
}) => Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* End drag operation
|
|
23
|
+
*/
|
|
24
|
+
endDrag: (options: {
|
|
25
|
+
dragId: string;
|
|
26
|
+
canceled?: boolean;
|
|
27
|
+
}) => Promise<{
|
|
28
|
+
dropped: boolean;
|
|
29
|
+
targetId?: string;
|
|
30
|
+
targetPath?: string;
|
|
31
|
+
insertIndex?: number;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Get drop zones at current position
|
|
35
|
+
*/
|
|
36
|
+
getDropZones: (options: {
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
}) => Promise<Array<{
|
|
40
|
+
elementId: string;
|
|
41
|
+
path: string;
|
|
42
|
+
rect: {
|
|
43
|
+
top: number;
|
|
44
|
+
left: number;
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
};
|
|
48
|
+
canDrop: boolean;
|
|
49
|
+
}>>;
|
|
50
|
+
/**
|
|
51
|
+
* Highlight drop zone
|
|
52
|
+
*/
|
|
53
|
+
highlightDropZone: (options: {
|
|
54
|
+
elementId?: string;
|
|
55
|
+
path?: string;
|
|
56
|
+
clear?: boolean;
|
|
57
|
+
}) => Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
export interface DragDropEvents {
|
|
60
|
+
'drag-start': (data: {
|
|
61
|
+
elementId: string;
|
|
62
|
+
path: string;
|
|
63
|
+
}) => void;
|
|
64
|
+
'drag-move': (data: {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
}) => void;
|
|
68
|
+
'drag-end': (data: {
|
|
69
|
+
dropped: boolean;
|
|
70
|
+
targetId?: string;
|
|
71
|
+
}) => void;
|
|
72
|
+
'drop-zone-enter': (data: {
|
|
73
|
+
elementId: string;
|
|
74
|
+
path: string;
|
|
75
|
+
}) => void;
|
|
76
|
+
'drop-zone-leave': (data: {
|
|
77
|
+
elementId: string;
|
|
78
|
+
path: string;
|
|
79
|
+
}) => void;
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get element by data attributes (Nooku uses data-node-id and data-node-path)
|
|
3
|
+
*/
|
|
4
|
+
export declare function getElement(id: string, path: string): HTMLElement | null;
|
|
5
|
+
/**
|
|
6
|
+
* Get all potential drop zones (elements that can accept drops)
|
|
7
|
+
*/
|
|
8
|
+
export declare function getDropZones(): HTMLElement[];
|
|
9
|
+
/**
|
|
10
|
+
* Check if element can accept drops
|
|
11
|
+
*/
|
|
12
|
+
export declare function canAcceptDrop(element: HTMLElement): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Get element at position
|
|
15
|
+
*/
|
|
16
|
+
export declare function getElementAtPosition(x: number, y: number, path: string): HTMLElement | null;
|
|
17
|
+
/**
|
|
18
|
+
* Calculate insert index based on cursor position
|
|
19
|
+
*/
|
|
20
|
+
export declare function calculateInsertIndex(container: HTMLElement, x: number, y: number, draggedElement?: HTMLElement): {
|
|
21
|
+
index: number;
|
|
22
|
+
before: boolean;
|
|
23
|
+
layout: 'block' | 'inline';
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Create drop indicator element
|
|
27
|
+
*/
|
|
28
|
+
export declare function createDropIndicator(color?: string): HTMLElement;
|
|
29
|
+
/**
|
|
30
|
+
* Position drop indicator
|
|
31
|
+
*/
|
|
32
|
+
export declare function positionDropIndicator(indicator: HTMLElement, rect: {
|
|
33
|
+
top: number;
|
|
34
|
+
left: number;
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
}, layout?: 'block' | 'inline'): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get parent container of an element
|
|
40
|
+
*/
|
|
41
|
+
export declare function getParentContainer(element: HTMLElement): HTMLElement | null;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calculateInsertIndex = calculateInsertIndex;
|
|
7
|
+
exports.canAcceptDrop = canAcceptDrop;
|
|
8
|
+
exports.createDropIndicator = createDropIndicator;
|
|
9
|
+
exports.getDropZones = getDropZones;
|
|
10
|
+
exports.getElement = getElement;
|
|
11
|
+
exports.getElementAtPosition = getElementAtPosition;
|
|
12
|
+
exports.getParentContainer = getParentContainer;
|
|
13
|
+
exports.positionDropIndicator = positionDropIndicator;
|
|
14
|
+
function getElement(t, e) {
|
|
15
|
+
return document.querySelector(`[data-node-id="${t}"][data-node-path="${e}"]`);
|
|
16
|
+
}
|
|
17
|
+
function getDropZones() {
|
|
18
|
+
return Array.from(document.querySelectorAll('[data-node-id]:not([data-node-id=""])'));
|
|
19
|
+
}
|
|
20
|
+
function canAcceptDrop(t) {
|
|
21
|
+
return t.getAttribute("data-node-type") !== "text";
|
|
22
|
+
}
|
|
23
|
+
function getElementAtPosition(t, e, i) {
|
|
24
|
+
let o = document.elementFromPoint(t, e);
|
|
25
|
+
if (!o) return null;
|
|
26
|
+
let r = o.getAttribute("data-node-path");
|
|
27
|
+
for (; o && r !== i;) {
|
|
28
|
+
if (o = o.parentElement, !o) return null;
|
|
29
|
+
r = o.getAttribute("data-node-path");
|
|
30
|
+
}
|
|
31
|
+
return o;
|
|
32
|
+
}
|
|
33
|
+
function calculateInsertIndex(t, e, i, o) {
|
|
34
|
+
const r = Array.from(t.children).filter(n => n.hasAttribute("data-node-id") && n !== o && !n.classList.contains("__nooku-drag-clone"));
|
|
35
|
+
if (r.length === 0) return {
|
|
36
|
+
index: 0,
|
|
37
|
+
before: !0,
|
|
38
|
+
layout: "block"
|
|
39
|
+
};
|
|
40
|
+
const s = r.every((n, d) => {
|
|
41
|
+
if (d === 0) return !0;
|
|
42
|
+
const l = r[d - 1].getBoundingClientRect(),
|
|
43
|
+
u = n.getBoundingClientRect();
|
|
44
|
+
return Math.abs(l.bottom - u.top) < 10;
|
|
45
|
+
}),
|
|
46
|
+
a = s ? "block" : "inline";
|
|
47
|
+
for (let n = 0; n < r.length; n++) {
|
|
48
|
+
const l = r[n].getBoundingClientRect();
|
|
49
|
+
if (s) {
|
|
50
|
+
const u = l.top + l.height / 2;
|
|
51
|
+
if (i < u) return {
|
|
52
|
+
index: n,
|
|
53
|
+
before: !0,
|
|
54
|
+
layout: a
|
|
55
|
+
};
|
|
56
|
+
} else {
|
|
57
|
+
const u = l.left + l.width / 2;
|
|
58
|
+
if (e < u) return {
|
|
59
|
+
index: n,
|
|
60
|
+
before: !0,
|
|
61
|
+
layout: a
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
index: r.length,
|
|
67
|
+
before: !1,
|
|
68
|
+
layout: a
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function createDropIndicator(t = "2563EB") {
|
|
72
|
+
const e = document.createElement("div");
|
|
73
|
+
return e.className = "__nooku-drop-indicator", e.style.cssText = `
|
|
74
|
+
position: fixed;
|
|
75
|
+
pointer-events: none;
|
|
76
|
+
z-index: 9999;
|
|
77
|
+
background: #${t};
|
|
78
|
+
border-radius: 2px;
|
|
79
|
+
transition: all 0.1s ease-out;
|
|
80
|
+
box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.3);
|
|
81
|
+
`, e;
|
|
82
|
+
}
|
|
83
|
+
function positionDropIndicator(t, e, i = "block") {
|
|
84
|
+
i === "block" ? (t.style.left = `${e.left}px`, t.style.top = `${e.top}px`, t.style.width = `${e.width}px`, t.style.height = "2px") : (t.style.left = `${e.left}px`, t.style.top = `${e.top}px`, t.style.width = "2px", t.style.height = `${e.height}px`);
|
|
85
|
+
}
|
|
86
|
+
function getParentContainer(t) {
|
|
87
|
+
let e = t.parentElement;
|
|
88
|
+
for (; e;) {
|
|
89
|
+
if (e.hasAttribute("data-node-id") && canAcceptDrop(e)) return e;
|
|
90
|
+
e = e.parentElement;
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export function getElement(t, e) {
|
|
2
|
+
return document.querySelector(`[data-node-id="${t}"][data-node-path="${e}"]`);
|
|
3
|
+
}
|
|
4
|
+
export function getDropZones() {
|
|
5
|
+
return Array.from(document.querySelectorAll('[data-node-id]:not([data-node-id=""])'));
|
|
6
|
+
}
|
|
7
|
+
export function canAcceptDrop(t) {
|
|
8
|
+
return t.getAttribute("data-node-type") !== "text";
|
|
9
|
+
}
|
|
10
|
+
export function getElementAtPosition(t, e, i) {
|
|
11
|
+
let o = document.elementFromPoint(t, e);
|
|
12
|
+
if (!o) return null;
|
|
13
|
+
let r = o.getAttribute("data-node-path");
|
|
14
|
+
for (; o && r !== i; ) {
|
|
15
|
+
if (o = o.parentElement, !o) return null;
|
|
16
|
+
r = o.getAttribute("data-node-path");
|
|
17
|
+
}
|
|
18
|
+
return o;
|
|
19
|
+
}
|
|
20
|
+
export function calculateInsertIndex(t, e, i, o) {
|
|
21
|
+
const r = Array.from(t.children).filter(
|
|
22
|
+
(n) => n.hasAttribute("data-node-id") && n !== o && !n.classList.contains("__nooku-drag-clone")
|
|
23
|
+
);
|
|
24
|
+
if (r.length === 0)
|
|
25
|
+
return { index: 0, before: !0, layout: "block" };
|
|
26
|
+
const s = r.every((n, d) => {
|
|
27
|
+
if (d === 0) return !0;
|
|
28
|
+
const l = r[d - 1].getBoundingClientRect(), u = n.getBoundingClientRect();
|
|
29
|
+
return Math.abs(l.bottom - u.top) < 10;
|
|
30
|
+
}), a = s ? "block" : "inline";
|
|
31
|
+
for (let n = 0; n < r.length; n++) {
|
|
32
|
+
const l = r[n].getBoundingClientRect();
|
|
33
|
+
if (s) {
|
|
34
|
+
const u = l.top + l.height / 2;
|
|
35
|
+
if (i < u)
|
|
36
|
+
return { index: n, before: !0, layout: a };
|
|
37
|
+
} else {
|
|
38
|
+
const u = l.left + l.width / 2;
|
|
39
|
+
if (e < u)
|
|
40
|
+
return { index: n, before: !0, layout: a };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { index: r.length, before: !1, layout: a };
|
|
44
|
+
}
|
|
45
|
+
export function createDropIndicator(t = "2563EB") {
|
|
46
|
+
const e = document.createElement("div");
|
|
47
|
+
return e.className = "__nooku-drop-indicator", e.style.cssText = `
|
|
48
|
+
position: fixed;
|
|
49
|
+
pointer-events: none;
|
|
50
|
+
z-index: 9999;
|
|
51
|
+
background: #${t};
|
|
52
|
+
border-radius: 2px;
|
|
53
|
+
transition: all 0.1s ease-out;
|
|
54
|
+
box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.3);
|
|
55
|
+
`, e;
|
|
56
|
+
}
|
|
57
|
+
export function positionDropIndicator(t, e, i = "block") {
|
|
58
|
+
i === "block" ? (t.style.left = `${e.left}px`, t.style.top = `${e.top}px`, t.style.width = `${e.width}px`, t.style.height = "2px") : (t.style.left = `${e.left}px`, t.style.top = `${e.top}px`, t.style.width = "2px", t.style.height = `${e.height}px`);
|
|
59
|
+
}
|
|
60
|
+
export function getParentContainer(t) {
|
|
61
|
+
let e = t.parentElement;
|
|
62
|
+
for (; e; ) {
|
|
63
|
+
if (e.hasAttribute("data-node-id") && canAcceptDrop(e))
|
|
64
|
+
return e;
|
|
65
|
+
e = e.parentElement;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
package/dist/editor.d.ts
CHANGED
|
@@ -2,10 +2,4 @@ import type { CoreIframeContext, CoreIframeEvents, EditorContext, EditorEvents }
|
|
|
2
2
|
/**
|
|
3
3
|
* This function should be called inside the editor
|
|
4
4
|
*/
|
|
5
|
-
export declare function createEditorClient<IframeContext extends CoreIframeContext, IframeEvents extends CoreIframeEvents>(iframe: string | HTMLIFrameElement):
|
|
6
|
-
$context: EditorContext;
|
|
7
|
-
on: <E extends keyof IframeEvents>(eventName: E, listener: (...args: IframeEvents[E] extends infer T ? T extends IframeEvents[E] ? T extends (...args: infer A) => any ? A : never : never : never) => void) => void;
|
|
8
|
-
off: <E extends keyof IframeEvents>(eventName: E, listener: (...args: IframeEvents[E] extends infer T ? T extends IframeEvents[E] ? T extends (...args: infer A) => any ? A : never : never : never) => void) => void;
|
|
9
|
-
emit: <E extends never>(eventName: E, ...args: EditorEvents[E] extends infer T ? T extends EditorEvents[E] ? T extends (...args: infer A) => any ? A : never : never : never) => void;
|
|
10
|
-
removeAllListeners: () => void;
|
|
11
|
-
};
|
|
5
|
+
export declare function createEditorClient<IframeContext extends CoreIframeContext, IframeEvents extends CoreIframeEvents>(iframe: string | HTMLIFrameElement): import("@nookuio/rpc").ClientReturn<IframeContext, EditorContext, IframeEvents, EditorEvents>;
|
package/dist/editor.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createEditorClient = createEditorClient;
|
|
7
7
|
var _constants = require("./constants");
|
|
8
|
-
var
|
|
8
|
+
var _rpc = require("@nookuio/rpc");
|
|
9
9
|
var _telejson = require("telejson");
|
|
10
10
|
function y(a) {
|
|
11
11
|
const n = (0, _telejson.parse)(a, {
|
|
@@ -33,7 +33,7 @@ function createEditorClient(a) {
|
|
|
33
33
|
function r() {
|
|
34
34
|
return (!n || !n.isConnected) && (n = typeof a == "string" ? document.querySelector(`#${a}`) : a), n;
|
|
35
35
|
}
|
|
36
|
-
return (0,
|
|
36
|
+
return (0, _rpc.createClient)({}, {
|
|
37
37
|
handle(e) {
|
|
38
38
|
window.addEventListener("message", async t => {
|
|
39
39
|
if (typeof t.data != "object" || t.data.source !== _constants.IFRAME_SOURCE_NAME || t.data.type === "event" || !t.data.request) return;
|
package/dist/editor.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EDITOR_SOURCE_NAME as f, IFRAME_SOURCE_NAME as u } from "./constants.mjs";
|
|
2
|
-
import { createClient as E } from "
|
|
2
|
+
import { createClient as E } from "@nookuio/rpc";
|
|
3
3
|
import { stringify as p, parse as l } from "telejson";
|
|
4
4
|
function y(a) {
|
|
5
5
|
const n = l(a, { maxDepth: 1 / 0 }), r = (e) => {
|
package/dist/iframe.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CoreIframeContext, EditorEvents, VueIframeContext, VueIframeEvents } from './types';
|
|
1
|
+
import type { CoreIframeContext, EditorContext, EditorEvents, VueIframeContext, VueIframeEvents } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* This function should be called inside the iframe
|
|
4
4
|
*/
|
|
@@ -9,10 +9,4 @@ export declare function createVueIframeClient(vueCtx: Omit<VueIframeContext, key
|
|
|
9
9
|
* @default false
|
|
10
10
|
*/
|
|
11
11
|
disableDefaultConsole?: boolean;
|
|
12
|
-
}):
|
|
13
|
-
$context: VueIframeContext;
|
|
14
|
-
on: <E extends never>(eventName: E, listener: (...args: EditorEvents[E] extends infer T ? T extends EditorEvents[E] ? T extends (...args: infer A) => any ? A : never : never : never) => void) => void;
|
|
15
|
-
off: <E extends never>(eventName: E, listener: (...args: EditorEvents[E] extends infer T ? T extends EditorEvents[E] ? T extends (...args: infer A) => any ? A : never : never : never) => void) => void;
|
|
16
|
-
emit: <E extends keyof VueIframeEvents>(eventName: E, ...args: VueIframeEvents[E] extends infer T ? T extends VueIframeEvents[E] ? T extends (...args: infer A) => any ? A : never : never : never) => void;
|
|
17
|
-
removeAllListeners: () => void;
|
|
18
|
-
};
|
|
12
|
+
}): import("@nookuio/rpc").ClientReturn<EditorContext, VueIframeContext, EditorEvents, VueIframeEvents>;
|
package/dist/iframe.js
CHANGED
|
@@ -5,45 +5,48 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createVueIframeClient = createVueIframeClient;
|
|
7
7
|
var _constants = require("./constants");
|
|
8
|
-
var
|
|
8
|
+
var _rpc = require("@nookuio/rpc");
|
|
9
9
|
var _telejson = require("telejson");
|
|
10
|
-
|
|
10
|
+
var _dragDrop = require("./drag-drop");
|
|
11
|
+
function p(u, d) {
|
|
11
12
|
return `[data-node-id="${d}"][data-node-path="${u}"]`;
|
|
12
13
|
}
|
|
13
14
|
function h(u, d) {
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
const
|
|
17
|
-
const
|
|
15
|
+
const m = document.querySelectorAll(u);
|
|
16
|
+
if (!m?.length) return;
|
|
17
|
+
const r = Array.from(m).map(f => {
|
|
18
|
+
const l = f.getBoundingClientRect(),
|
|
18
19
|
g = {
|
|
19
|
-
width:
|
|
20
|
-
height:
|
|
21
|
-
top:
|
|
22
|
-
left:
|
|
20
|
+
width: l.width,
|
|
21
|
+
height: l.height,
|
|
22
|
+
top: l.top,
|
|
23
|
+
left: l.left
|
|
23
24
|
};
|
|
24
25
|
if (!d) return g;
|
|
25
|
-
const
|
|
26
|
+
const c = window.getComputedStyle(f) ?? {};
|
|
26
27
|
return {
|
|
27
28
|
...g,
|
|
28
29
|
padding: {
|
|
29
|
-
top:
|
|
30
|
-
right:
|
|
31
|
-
bottom:
|
|
32
|
-
left:
|
|
30
|
+
top: c.paddingTop,
|
|
31
|
+
right: c.paddingRight,
|
|
32
|
+
bottom: c.paddingBottom,
|
|
33
|
+
left: c.paddingLeft
|
|
33
34
|
}
|
|
34
35
|
};
|
|
35
36
|
});
|
|
36
|
-
if (
|
|
37
|
+
if (r?.length) return r.length === 1 ? r[0] : r;
|
|
37
38
|
}
|
|
38
39
|
function createVueIframeClient(u, d) {
|
|
39
|
-
const
|
|
40
|
+
const m = (0, _dragDrop.createDragDropContext)(),
|
|
41
|
+
r = (0, _rpc.createClient)({
|
|
40
42
|
...u,
|
|
43
|
+
...m,
|
|
41
44
|
async editText({
|
|
42
45
|
path: e,
|
|
43
46
|
id: t
|
|
44
47
|
}) {
|
|
45
48
|
if (!e || t === void 0) return;
|
|
46
|
-
const i =
|
|
49
|
+
const i = p(e, t),
|
|
47
50
|
n = document.querySelector(i);
|
|
48
51
|
if (!n) return;
|
|
49
52
|
n.style.outline = "none", n.setAttribute("spellcheck", "false"), n.setAttribute("contenteditable", "true");
|
|
@@ -51,16 +54,16 @@ function createVueIframeClient(u, d) {
|
|
|
51
54
|
const E = a.target;
|
|
52
55
|
if (!E) return;
|
|
53
56
|
const y = E.innerText;
|
|
54
|
-
n.removeAttribute("contenteditable"),
|
|
57
|
+
n.removeAttribute("contenteditable"), r.emit("text-update", {
|
|
55
58
|
path: e,
|
|
56
59
|
id: t,
|
|
57
60
|
content: y
|
|
58
|
-
}), n.removeEventListener("blur", o), n.removeEventListener("keydown",
|
|
61
|
+
}), n.removeEventListener("blur", o), n.removeEventListener("keydown", s), n.blur();
|
|
59
62
|
},
|
|
60
|
-
|
|
63
|
+
s = a => {
|
|
61
64
|
a.key === "Enter" && (a.stopPropagation(), a.preventDefault(), o(a));
|
|
62
65
|
};
|
|
63
|
-
n.addEventListener("keydown",
|
|
66
|
+
n.addEventListener("keydown", s), n.addEventListener("blur", o), n.focus();
|
|
64
67
|
},
|
|
65
68
|
async getHoveredElement({
|
|
66
69
|
path: e,
|
|
@@ -71,14 +74,14 @@ function createVueIframeClient(u, d) {
|
|
|
71
74
|
if (e) if (i !== void 0 && n !== void 0) {
|
|
72
75
|
let o = document.elementFromPoint(i, n);
|
|
73
76
|
if (!o) return;
|
|
74
|
-
let
|
|
75
|
-
if (
|
|
77
|
+
let s = o.getAttribute("data-node-path");
|
|
78
|
+
if (s !== e) {
|
|
76
79
|
if (!o.parentElement) return;
|
|
77
|
-
for (; o.parentElement &&
|
|
80
|
+
for (; o.parentElement && s !== e;) o = o.parentElement, s = o.getAttribute("data-node-path");
|
|
78
81
|
}
|
|
79
82
|
const a = o.getAttribute("data-node-id");
|
|
80
83
|
if (!a) return;
|
|
81
|
-
const E =
|
|
84
|
+
const E = p(e, a),
|
|
82
85
|
y = h(E, !1);
|
|
83
86
|
return y ? {
|
|
84
87
|
id: a,
|
|
@@ -86,12 +89,12 @@ function createVueIframeClient(u, d) {
|
|
|
86
89
|
data: y
|
|
87
90
|
} : void 0;
|
|
88
91
|
} else {
|
|
89
|
-
const o =
|
|
90
|
-
|
|
91
|
-
return
|
|
92
|
+
const o = p(e, t),
|
|
93
|
+
s = h(o, !1);
|
|
94
|
+
return s ? {
|
|
92
95
|
id: t,
|
|
93
96
|
path: e,
|
|
94
|
-
data:
|
|
97
|
+
data: s
|
|
95
98
|
} : void 0;
|
|
96
99
|
}
|
|
97
100
|
},
|
|
@@ -102,7 +105,7 @@ function createVueIframeClient(u, d) {
|
|
|
102
105
|
path: e,
|
|
103
106
|
id: t
|
|
104
107
|
}) {
|
|
105
|
-
const i =
|
|
108
|
+
const i = p(e, t),
|
|
106
109
|
n = h(i, !0);
|
|
107
110
|
if (n) return {
|
|
108
111
|
path: e,
|
|
@@ -130,8 +133,8 @@ function createVueIframeClient(u, d) {
|
|
|
130
133
|
const n = setTimeout(() => {
|
|
131
134
|
window.removeEventListener("message", o), i(new Error("Request timed out"));
|
|
132
135
|
}, 5e3);
|
|
133
|
-
function o(
|
|
134
|
-
typeof
|
|
136
|
+
function o(s) {
|
|
137
|
+
typeof s.data == "object" && (s.data.source !== _constants.EDITOR_SOURCE_NAME || !s.data.response || s.data.response.id === e.id && (clearTimeout(n), window.removeEventListener("message", o), t(s.data.response)));
|
|
135
138
|
}
|
|
136
139
|
window.parent.postMessage({
|
|
137
140
|
source: _constants.IFRAME_SOURCE_NAME,
|
|
@@ -156,22 +159,22 @@ function createVueIframeClient(u, d) {
|
|
|
156
159
|
maxDepth: 1 / 0
|
|
157
160
|
})
|
|
158
161
|
}),
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
162
|
+
f = d?.disableDefaultConsole ? void 0 : console.log.bind(console),
|
|
163
|
+
l = d?.disableDefaultConsole ? void 0 : console.warn.bind(console),
|
|
164
|
+
g = d?.disableDefaultConsole ? void 0 : console.error.bind(console),
|
|
165
|
+
c = d?.disableDefaultConsole ? void 0 : console.info.bind(console);
|
|
163
166
|
return console.log = (...e) => {
|
|
164
|
-
|
|
167
|
+
r.emit("console", "log", e), f?.(...e);
|
|
165
168
|
}, console.warn = (...e) => {
|
|
166
|
-
|
|
169
|
+
l?.(...e);
|
|
167
170
|
}, console.error = (...e) => {
|
|
168
|
-
|
|
171
|
+
r.emit("console", "error", e), g?.(...e);
|
|
169
172
|
}, console.info = (...e) => {
|
|
170
|
-
|
|
171
|
-
}, window.addEventListener("resize", async () =>
|
|
173
|
+
r.emit("console", "info", e), c?.(...e);
|
|
174
|
+
}, window.addEventListener("resize", async () => r.emit("resize", await r.$context.getPageHeight())), new MutationObserver(async () => r.emit("resize", await r.$context.getPageHeight())).observe(document.body, {
|
|
172
175
|
childList: !0,
|
|
173
176
|
subtree: !0,
|
|
174
177
|
attributes: !0,
|
|
175
178
|
characterData: !0
|
|
176
|
-
}),
|
|
179
|
+
}), r.emit("ready"), r;
|
|
177
180
|
}
|