@nookuio/iframe 0.9.9 → 1.0.0-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/drag-drop/dragDropManager.d.ts +101 -0
- package/dist/drag-drop/dragDropManager.js +175 -0
- package/dist/drag-drop/dragDropManager.mjs +163 -0
- package/dist/drag-drop/index.d.ts +3 -0
- package/dist/drag-drop/index.js +38 -0
- package/dist/drag-drop/index.mjs +3 -0
- package/dist/drag-drop/types.d.ts +80 -0
- package/dist/drag-drop/types.js +1 -0
- package/dist/drag-drop/types.mjs +0 -0
- package/dist/drag-drop/utils.d.ts +36 -0
- package/dist/drag-drop/utils.js +79 -0
- package/dist/drag-drop/utils.mjs +56 -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 +90 -64
- package/dist/iframe.mjs +93 -66
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -0
- package/dist/index.mjs +1 -0
- package/dist/types.d.ts +67 -3
- package/package.json +4 -3
- package/dist/createClient.d.ts +0 -51
- package/dist/createClient.js +0 -118
- package/dist/createClient.mjs +0 -114
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export function getElement(e, t) {
|
|
2
|
+
return document.querySelector(`[data-node-id="${e}"][data-node-path="${t}"]`);
|
|
3
|
+
}
|
|
4
|
+
export function getDropZones() {
|
|
5
|
+
return Array.from(document.querySelectorAll('[data-node-id]:not([data-node-id=""])'));
|
|
6
|
+
}
|
|
7
|
+
export function canAcceptDrop(e) {
|
|
8
|
+
return e.getAttribute("data-node-type") !== "text";
|
|
9
|
+
}
|
|
10
|
+
export function getElementAtPosition(e, t, l) {
|
|
11
|
+
let n = document.elementFromPoint(e, t);
|
|
12
|
+
if (!n) return null;
|
|
13
|
+
let u = n.getAttribute("data-node-path");
|
|
14
|
+
for (; n && u !== l; ) {
|
|
15
|
+
if (n = n.parentElement, !n) return null;
|
|
16
|
+
u = n.getAttribute("data-node-path");
|
|
17
|
+
}
|
|
18
|
+
return n;
|
|
19
|
+
}
|
|
20
|
+
export function calculateInsertIndex(e, t, l) {
|
|
21
|
+
const n = Array.from(e.children).filter((o) => o.hasAttribute("data-node-id"));
|
|
22
|
+
if (n.length === 0)
|
|
23
|
+
return { index: 0, before: !0 };
|
|
24
|
+
const u = e.getBoundingClientRect(), c = n.every((o, d) => {
|
|
25
|
+
if (d === 0) return !0;
|
|
26
|
+
const r = n[d - 1].getBoundingClientRect(), i = o.getBoundingClientRect();
|
|
27
|
+
return r.bottom <= i.top;
|
|
28
|
+
});
|
|
29
|
+
for (let o = 0; o < n.length; o++) {
|
|
30
|
+
const r = n[o].getBoundingClientRect();
|
|
31
|
+
if (c) {
|
|
32
|
+
const i = r.top + r.height / 2;
|
|
33
|
+
if (l < i)
|
|
34
|
+
return { index: o, before: !0 };
|
|
35
|
+
} else {
|
|
36
|
+
const i = r.left + r.width / 2;
|
|
37
|
+
if (t < i)
|
|
38
|
+
return { index: o, before: !0 };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { index: n.length, before: !1 };
|
|
42
|
+
}
|
|
43
|
+
export function createDropIndicator(e = "2563EB") {
|
|
44
|
+
const t = document.createElement("div");
|
|
45
|
+
return t.className = "__nooku-drop-indicator", t.style.cssText = `
|
|
46
|
+
position: fixed;
|
|
47
|
+
pointer-events: none;
|
|
48
|
+
z-index: 9999;
|
|
49
|
+
background: #${e};
|
|
50
|
+
opacity: 0.5;
|
|
51
|
+
transition: all 0.15s ease;
|
|
52
|
+
`, t;
|
|
53
|
+
}
|
|
54
|
+
export function positionDropIndicator(e, t, l = "block") {
|
|
55
|
+
l === "block" ? (e.style.left = `${t.left}px`, e.style.top = `${t.top}px`, e.style.width = `${t.width}px`, e.style.height = "3px") : (e.style.left = `${t.left}px`, e.style.top = `${t.top}px`, e.style.width = "3px", e.style.height = `${t.height}px`);
|
|
56
|
+
}
|
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,93 +5,103 @@ 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
|
-
|
|
11
|
-
|
|
10
|
+
var _dragDropManager = require("./drag-drop/dragDropManager");
|
|
11
|
+
function p(m, l) {
|
|
12
|
+
return `[data-node-id="${l}"][data-node-path="${m}"]`;
|
|
12
13
|
}
|
|
13
|
-
function h(
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
const
|
|
17
|
-
const
|
|
14
|
+
function h(m, l) {
|
|
15
|
+
const d = document.querySelectorAll(m);
|
|
16
|
+
if (!d?.length) return;
|
|
17
|
+
const r = Array.from(d).map(f => {
|
|
18
|
+
const c = f.getBoundingClientRect(),
|
|
18
19
|
g = {
|
|
19
|
-
width:
|
|
20
|
-
height:
|
|
21
|
-
top:
|
|
22
|
-
left:
|
|
20
|
+
width: c.width,
|
|
21
|
+
height: c.height,
|
|
22
|
+
top: c.top,
|
|
23
|
+
left: c.left
|
|
23
24
|
};
|
|
24
25
|
if (!l) return g;
|
|
25
|
-
const
|
|
26
|
+
const u = window.getComputedStyle(f) ?? {};
|
|
26
27
|
return {
|
|
27
28
|
...g,
|
|
28
29
|
padding: {
|
|
29
|
-
top:
|
|
30
|
-
right:
|
|
31
|
-
bottom:
|
|
32
|
-
left:
|
|
30
|
+
top: u.paddingTop,
|
|
31
|
+
right: u.paddingRight,
|
|
32
|
+
bottom: u.paddingBottom,
|
|
33
|
+
left: u.paddingLeft
|
|
33
34
|
}
|
|
34
35
|
};
|
|
35
36
|
});
|
|
36
|
-
if (
|
|
37
|
+
if (r?.length) return r.length === 1 ? r[0] : r;
|
|
37
38
|
}
|
|
38
|
-
function createVueIframeClient(
|
|
39
|
-
const
|
|
40
|
-
|
|
39
|
+
function createVueIframeClient(m, l) {
|
|
40
|
+
const d = new _dragDropManager.DragDropManager();
|
|
41
|
+
d.setCallbacks({
|
|
42
|
+
onDragStart: e => {
|
|
43
|
+
r.emit("drag-start", e);
|
|
44
|
+
},
|
|
45
|
+
onDragEnd: e => {
|
|
46
|
+
r.emit("drag-end", e);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const r = (0, _rpc.createClient)({
|
|
50
|
+
...m,
|
|
41
51
|
async editText({
|
|
42
52
|
path: e,
|
|
43
53
|
id: t
|
|
44
54
|
}) {
|
|
45
55
|
if (!e || t === void 0) return;
|
|
46
|
-
const
|
|
47
|
-
n = document.querySelector(
|
|
56
|
+
const a = p(e, t),
|
|
57
|
+
n = document.querySelector(a);
|
|
48
58
|
if (!n) return;
|
|
49
59
|
n.style.outline = "none", n.setAttribute("spellcheck", "false"), n.setAttribute("contenteditable", "true");
|
|
50
|
-
const o =
|
|
51
|
-
const E =
|
|
60
|
+
const o = i => {
|
|
61
|
+
const E = i.target;
|
|
52
62
|
if (!E) return;
|
|
53
63
|
const y = E.innerText;
|
|
54
|
-
n.removeAttribute("contenteditable"),
|
|
64
|
+
n.removeAttribute("contenteditable"), r.emit("text-update", {
|
|
55
65
|
path: e,
|
|
56
66
|
id: t,
|
|
57
67
|
content: y
|
|
58
|
-
}), n.removeEventListener("blur", o), n.removeEventListener("keydown",
|
|
68
|
+
}), n.removeEventListener("blur", o), n.removeEventListener("keydown", s), n.blur();
|
|
59
69
|
},
|
|
60
|
-
|
|
61
|
-
|
|
70
|
+
s = i => {
|
|
71
|
+
i.key === "Enter" && (i.stopPropagation(), i.preventDefault(), o(i));
|
|
62
72
|
};
|
|
63
|
-
n.addEventListener("keydown",
|
|
73
|
+
n.addEventListener("keydown", s), n.addEventListener("blur", o), n.focus();
|
|
64
74
|
},
|
|
65
75
|
async getHoveredElement({
|
|
66
76
|
path: e,
|
|
67
77
|
id: t,
|
|
68
|
-
x:
|
|
78
|
+
x: a,
|
|
69
79
|
y: n
|
|
70
80
|
}) {
|
|
71
|
-
if (e) if (
|
|
72
|
-
let o = document.elementFromPoint(
|
|
81
|
+
if (e) if (a !== void 0 && n !== void 0) {
|
|
82
|
+
let o = document.elementFromPoint(a, n);
|
|
73
83
|
if (!o) return;
|
|
74
|
-
let
|
|
75
|
-
if (
|
|
84
|
+
let s = o.getAttribute("data-node-path");
|
|
85
|
+
if (s !== e) {
|
|
76
86
|
if (!o.parentElement) return;
|
|
77
|
-
for (; o.parentElement &&
|
|
87
|
+
for (; o.parentElement && s !== e;) o = o.parentElement, s = o.getAttribute("data-node-path");
|
|
78
88
|
}
|
|
79
|
-
const
|
|
80
|
-
if (!
|
|
81
|
-
const E =
|
|
89
|
+
const i = o.getAttribute("data-node-id");
|
|
90
|
+
if (!i) return;
|
|
91
|
+
const E = p(e, i),
|
|
82
92
|
y = h(E, !1);
|
|
83
93
|
return y ? {
|
|
84
|
-
id:
|
|
94
|
+
id: i,
|
|
85
95
|
path: e,
|
|
86
96
|
data: y
|
|
87
97
|
} : void 0;
|
|
88
98
|
} else {
|
|
89
|
-
const o =
|
|
90
|
-
|
|
91
|
-
return
|
|
99
|
+
const o = p(e, t),
|
|
100
|
+
s = h(o, !1);
|
|
101
|
+
return s ? {
|
|
92
102
|
id: t,
|
|
93
103
|
path: e,
|
|
94
|
-
data:
|
|
104
|
+
data: s
|
|
95
105
|
} : void 0;
|
|
96
106
|
}
|
|
97
107
|
},
|
|
@@ -102,35 +112,51 @@ function createVueIframeClient(c, l) {
|
|
|
102
112
|
path: e,
|
|
103
113
|
id: t
|
|
104
114
|
}) {
|
|
105
|
-
const
|
|
106
|
-
n = h(
|
|
115
|
+
const a = p(e, t),
|
|
116
|
+
n = h(a, !0);
|
|
107
117
|
if (n) return {
|
|
108
118
|
path: e,
|
|
109
119
|
id: t,
|
|
110
120
|
data: n
|
|
111
121
|
};
|
|
112
122
|
},
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
setTheme(e) {
|
|
124
|
+
const t = document.querySelector("body");
|
|
125
|
+
e === "dark" ? (document.documentElement.classList.remove("light"), document.documentElement.classList.add("dark"), t && (t.classList.remove("light"), t.classList.add("dark"))) : (document.documentElement.classList.remove("dark"), document.documentElement.classList.add("light"), t && (t.classList.remove("dark"), t.classList.add("light")));
|
|
126
|
+
},
|
|
127
|
+
async startDrag(e) {
|
|
128
|
+
return d.startDrag(e);
|
|
129
|
+
},
|
|
130
|
+
async updateDragPosition(e) {
|
|
131
|
+
return d.updateDragPosition(e);
|
|
132
|
+
},
|
|
133
|
+
async endDrag(e) {
|
|
134
|
+
return d.endDrag(e);
|
|
135
|
+
},
|
|
136
|
+
async getDropZones(e) {
|
|
137
|
+
return d.getDropZones(e);
|
|
138
|
+
},
|
|
139
|
+
async highlightDropZone(e) {
|
|
140
|
+
return d.highlightDropZone(e);
|
|
115
141
|
}
|
|
116
142
|
}, {
|
|
117
143
|
handle(e) {
|
|
118
144
|
window.addEventListener("message", async t => {
|
|
119
145
|
if (typeof t.data != "object" || t.data.source !== _constants.EDITOR_SOURCE_NAME || t.data.type === "event" || !t.data.request) return;
|
|
120
|
-
const
|
|
146
|
+
const a = await e(t.data.request);
|
|
121
147
|
window.parent.postMessage({
|
|
122
148
|
source: _constants.IFRAME_SOURCE_NAME,
|
|
123
|
-
response:
|
|
149
|
+
response: a
|
|
124
150
|
}, "*");
|
|
125
151
|
});
|
|
126
152
|
},
|
|
127
153
|
invoke(e) {
|
|
128
|
-
return new Promise((t,
|
|
154
|
+
return new Promise((t, a) => {
|
|
129
155
|
const n = setTimeout(() => {
|
|
130
|
-
window.removeEventListener("message", o),
|
|
156
|
+
window.removeEventListener("message", o), a(new Error("Request timed out"));
|
|
131
157
|
}, 5e3);
|
|
132
|
-
function o(
|
|
133
|
-
typeof
|
|
158
|
+
function o(s) {
|
|
159
|
+
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)));
|
|
134
160
|
}
|
|
135
161
|
window.parent.postMessage({
|
|
136
162
|
source: _constants.IFRAME_SOURCE_NAME,
|
|
@@ -155,22 +181,22 @@ function createVueIframeClient(c, l) {
|
|
|
155
181
|
maxDepth: 1 / 0
|
|
156
182
|
})
|
|
157
183
|
}),
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
184
|
+
f = l?.disableDefaultConsole ? void 0 : console.log.bind(console),
|
|
185
|
+
c = l?.disableDefaultConsole ? void 0 : console.warn.bind(console),
|
|
186
|
+
g = l?.disableDefaultConsole ? void 0 : console.error.bind(console),
|
|
187
|
+
u = l?.disableDefaultConsole ? void 0 : console.info.bind(console);
|
|
162
188
|
return console.log = (...e) => {
|
|
163
|
-
|
|
189
|
+
r.emit("console", "log", e), f?.(...e);
|
|
164
190
|
}, console.warn = (...e) => {
|
|
165
|
-
|
|
191
|
+
c?.(...e);
|
|
166
192
|
}, console.error = (...e) => {
|
|
167
|
-
|
|
193
|
+
r.emit("console", "error", e), g?.(...e);
|
|
168
194
|
}, console.info = (...e) => {
|
|
169
|
-
|
|
170
|
-
}, window.addEventListener("resize", async () =>
|
|
195
|
+
r.emit("console", "info", e), u?.(...e);
|
|
196
|
+
}, window.addEventListener("resize", async () => r.emit("resize", await r.$context.getPageHeight())), new MutationObserver(async () => r.emit("resize", await r.$context.getPageHeight())).observe(document.body, {
|
|
171
197
|
childList: !0,
|
|
172
198
|
subtree: !0,
|
|
173
199
|
attributes: !0,
|
|
174
200
|
characterData: !0
|
|
175
|
-
}),
|
|
201
|
+
}), r.emit("ready"), r;
|
|
176
202
|
}
|
package/dist/iframe.mjs
CHANGED
|
@@ -1,78 +1,88 @@
|
|
|
1
|
-
import { EDITOR_SOURCE_NAME as
|
|
2
|
-
import { createClient as C } from "
|
|
3
|
-
import { stringify as
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { EDITOR_SOURCE_NAME as b, IFRAME_SOURCE_NAME as w } from "./constants.mjs";
|
|
2
|
+
import { createClient as C } from "@nookuio/rpc";
|
|
3
|
+
import { stringify as D, parse as v } from "telejson";
|
|
4
|
+
import { DragDropManager as L } from "./drag-drop/dragDropManager.mjs";
|
|
5
|
+
function p(m, l) {
|
|
6
|
+
return `[data-node-id="${l}"][data-node-path="${m}"]`;
|
|
6
7
|
}
|
|
7
|
-
function h(
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
width:
|
|
13
|
-
height:
|
|
14
|
-
top:
|
|
15
|
-
left:
|
|
8
|
+
function h(m, l) {
|
|
9
|
+
const d = document.querySelectorAll(m);
|
|
10
|
+
if (!d?.length) return;
|
|
11
|
+
const r = Array.from(d).map((f) => {
|
|
12
|
+
const c = f.getBoundingClientRect(), g = {
|
|
13
|
+
width: c.width,
|
|
14
|
+
height: c.height,
|
|
15
|
+
top: c.top,
|
|
16
|
+
left: c.left
|
|
16
17
|
};
|
|
17
18
|
if (!l) return g;
|
|
18
|
-
const
|
|
19
|
+
const u = window.getComputedStyle(f) ?? {};
|
|
19
20
|
return {
|
|
20
21
|
...g,
|
|
21
22
|
padding: {
|
|
22
|
-
top:
|
|
23
|
-
right:
|
|
24
|
-
bottom:
|
|
25
|
-
left:
|
|
23
|
+
top: u.paddingTop,
|
|
24
|
+
right: u.paddingRight,
|
|
25
|
+
bottom: u.paddingBottom,
|
|
26
|
+
left: u.paddingLeft
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
});
|
|
29
|
-
if (
|
|
30
|
-
return
|
|
30
|
+
if (r?.length)
|
|
31
|
+
return r.length === 1 ? r[0] : r;
|
|
31
32
|
}
|
|
32
|
-
export function createVueIframeClient(
|
|
33
|
-
const
|
|
33
|
+
export function createVueIframeClient(m, l) {
|
|
34
|
+
const d = new L();
|
|
35
|
+
d.setCallbacks({
|
|
36
|
+
onDragStart: (e) => {
|
|
37
|
+
r.emit("drag-start", e);
|
|
38
|
+
},
|
|
39
|
+
onDragEnd: (e) => {
|
|
40
|
+
r.emit("drag-end", e);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const r = C(
|
|
34
44
|
{
|
|
35
|
-
...
|
|
45
|
+
...m,
|
|
36
46
|
async editText({ path: e, id: t }) {
|
|
37
47
|
if (!e || t === void 0) return;
|
|
38
|
-
const
|
|
48
|
+
const a = p(e, t), n = document.querySelector(a);
|
|
39
49
|
if (!n) return;
|
|
40
50
|
n.style.outline = "none", n.setAttribute("spellcheck", "false"), n.setAttribute("contenteditable", "true");
|
|
41
|
-
const o = (
|
|
42
|
-
const E =
|
|
51
|
+
const o = (i) => {
|
|
52
|
+
const E = i.target;
|
|
43
53
|
if (!E) return;
|
|
44
54
|
const y = E.innerText;
|
|
45
|
-
n.removeAttribute("contenteditable"),
|
|
46
|
-
},
|
|
47
|
-
|
|
55
|
+
n.removeAttribute("contenteditable"), r.emit("text-update", { path: e, id: t, content: y }), n.removeEventListener("blur", o), n.removeEventListener("keydown", s), n.blur();
|
|
56
|
+
}, s = (i) => {
|
|
57
|
+
i.key === "Enter" && (i.stopPropagation(), i.preventDefault(), o(i));
|
|
48
58
|
};
|
|
49
|
-
n.addEventListener("keydown",
|
|
59
|
+
n.addEventListener("keydown", s), n.addEventListener("blur", o), n.focus();
|
|
50
60
|
},
|
|
51
|
-
async getHoveredElement({ path: e, id: t, x:
|
|
61
|
+
async getHoveredElement({ path: e, id: t, x: a, y: n }) {
|
|
52
62
|
if (e)
|
|
53
|
-
if (
|
|
54
|
-
let o = document.elementFromPoint(
|
|
63
|
+
if (a !== void 0 && n !== void 0) {
|
|
64
|
+
let o = document.elementFromPoint(a, n);
|
|
55
65
|
if (!o) return;
|
|
56
|
-
let
|
|
57
|
-
if (
|
|
66
|
+
let s = o.getAttribute("data-node-path");
|
|
67
|
+
if (s !== e) {
|
|
58
68
|
if (!o.parentElement) return;
|
|
59
|
-
for (; o.parentElement &&
|
|
60
|
-
o = o.parentElement,
|
|
69
|
+
for (; o.parentElement && s !== e; )
|
|
70
|
+
o = o.parentElement, s = o.getAttribute("data-node-path");
|
|
61
71
|
}
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
const E =
|
|
72
|
+
const i = o.getAttribute("data-node-id");
|
|
73
|
+
if (!i) return;
|
|
74
|
+
const E = p(e, i), y = h(E, !1);
|
|
65
75
|
return y ? {
|
|
66
|
-
id:
|
|
76
|
+
id: i,
|
|
67
77
|
path: e,
|
|
68
78
|
data: y
|
|
69
79
|
} : void 0;
|
|
70
80
|
} else {
|
|
71
|
-
const o =
|
|
72
|
-
return
|
|
81
|
+
const o = p(e, t), s = h(o, !1);
|
|
82
|
+
return s ? {
|
|
73
83
|
id: t,
|
|
74
84
|
path: e,
|
|
75
|
-
data:
|
|
85
|
+
data: s
|
|
76
86
|
} : void 0;
|
|
77
87
|
}
|
|
78
88
|
},
|
|
@@ -80,7 +90,7 @@ export function createVueIframeClient(c, l) {
|
|
|
80
90
|
return document.body.scrollHeight > 0 ? document.body.scrollHeight : document.documentElement.scrollHeight;
|
|
81
91
|
},
|
|
82
92
|
async getSelectedElement({ path: e, id: t }) {
|
|
83
|
-
const
|
|
93
|
+
const a = p(e, t), n = h(a, !0);
|
|
84
94
|
if (n)
|
|
85
95
|
return {
|
|
86
96
|
path: e,
|
|
@@ -88,8 +98,25 @@ export function createVueIframeClient(c, l) {
|
|
|
88
98
|
data: n
|
|
89
99
|
};
|
|
90
100
|
},
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
setTheme(e) {
|
|
102
|
+
const t = document.querySelector("body");
|
|
103
|
+
e === "dark" ? (document.documentElement.classList.remove("light"), document.documentElement.classList.add("dark"), t && (t.classList.remove("light"), t.classList.add("dark"))) : (document.documentElement.classList.remove("dark"), document.documentElement.classList.add("light"), t && (t.classList.remove("dark"), t.classList.add("light")));
|
|
104
|
+
},
|
|
105
|
+
// Drag and drop methods
|
|
106
|
+
async startDrag(e) {
|
|
107
|
+
return d.startDrag(e);
|
|
108
|
+
},
|
|
109
|
+
async updateDragPosition(e) {
|
|
110
|
+
return d.updateDragPosition(e);
|
|
111
|
+
},
|
|
112
|
+
async endDrag(e) {
|
|
113
|
+
return d.endDrag(e);
|
|
114
|
+
},
|
|
115
|
+
async getDropZones(e) {
|
|
116
|
+
return d.getDropZones(e);
|
|
117
|
+
},
|
|
118
|
+
async highlightDropZone(e) {
|
|
119
|
+
return d.highlightDropZone(e);
|
|
93
120
|
}
|
|
94
121
|
// updateElementClass({ className, id, path }) {
|
|
95
122
|
// const selector = getSelector(path, id);
|
|
@@ -117,18 +144,18 @@ export function createVueIframeClient(c, l) {
|
|
|
117
144
|
{
|
|
118
145
|
handle(e) {
|
|
119
146
|
window.addEventListener("message", async (t) => {
|
|
120
|
-
if (typeof t.data != "object" || t.data.source !==
|
|
121
|
-
const
|
|
122
|
-
window.parent.postMessage({ source: w, response:
|
|
147
|
+
if (typeof t.data != "object" || t.data.source !== b || t.data.type === "event" || !t.data.request) return;
|
|
148
|
+
const a = await e(t.data.request);
|
|
149
|
+
window.parent.postMessage({ source: w, response: a }, "*");
|
|
123
150
|
});
|
|
124
151
|
},
|
|
125
152
|
invoke(e) {
|
|
126
|
-
return new Promise((t,
|
|
153
|
+
return new Promise((t, a) => {
|
|
127
154
|
const n = setTimeout(() => {
|
|
128
|
-
window.removeEventListener("message", o),
|
|
155
|
+
window.removeEventListener("message", o), a(new Error("Request timed out"));
|
|
129
156
|
}, 5e3);
|
|
130
|
-
function o(
|
|
131
|
-
typeof
|
|
157
|
+
function o(s) {
|
|
158
|
+
typeof s.data == "object" && (s.data.source !== b || !s.data.response || s.data.response.id === e.id && (clearTimeout(n), window.removeEventListener("message", o), t(s.data.response)));
|
|
132
159
|
}
|
|
133
160
|
window.parent.postMessage({ source: w, request: e }, "*"), window.addEventListener("message", o);
|
|
134
161
|
});
|
|
@@ -138,23 +165,23 @@ export function createVueIframeClient(c, l) {
|
|
|
138
165
|
},
|
|
139
166
|
handleEvent(e) {
|
|
140
167
|
window.addEventListener("message", (t) => {
|
|
141
|
-
typeof t.data == "object" && (t.data.source !==
|
|
168
|
+
typeof t.data == "object" && (t.data.source !== b || t.data.type !== "event" || !t.data.request || e(t.data.request));
|
|
142
169
|
});
|
|
143
170
|
},
|
|
144
|
-
deserialize: (e) =>
|
|
145
|
-
serialize: (e) =>
|
|
171
|
+
deserialize: (e) => v(e),
|
|
172
|
+
serialize: (e) => D(e, { maxDepth: 1 / 0 })
|
|
146
173
|
}
|
|
147
|
-
),
|
|
174
|
+
), f = l?.disableDefaultConsole ? void 0 : console.log.bind(console), c = l?.disableDefaultConsole ? void 0 : console.warn.bind(console), g = l?.disableDefaultConsole ? void 0 : console.error.bind(console), u = l?.disableDefaultConsole ? void 0 : console.info.bind(console);
|
|
148
175
|
return console.log = (...e) => {
|
|
149
|
-
|
|
176
|
+
r.emit("console", "log", e), f?.(...e);
|
|
150
177
|
}, console.warn = (...e) => {
|
|
151
|
-
|
|
178
|
+
c?.(...e);
|
|
152
179
|
}, console.error = (...e) => {
|
|
153
|
-
|
|
180
|
+
r.emit("console", "error", e), g?.(...e);
|
|
154
181
|
}, console.info = (...e) => {
|
|
155
|
-
|
|
156
|
-
}, window.addEventListener("resize", async () =>
|
|
157
|
-
async () =>
|
|
182
|
+
r.emit("console", "info", e), u?.(...e);
|
|
183
|
+
}, window.addEventListener("resize", async () => r.emit("resize", await r.$context.getPageHeight())), new MutationObserver(
|
|
184
|
+
async () => r.emit("resize", await r.$context.getPageHeight())
|
|
158
185
|
).observe(document.body, {
|
|
159
186
|
childList: !0,
|
|
160
187
|
// observe direct children additions/removals
|
|
@@ -164,5 +191,5 @@ export function createVueIframeClient(c, l) {
|
|
|
164
191
|
// observe attribute changes (like style, class)
|
|
165
192
|
characterData: !0
|
|
166
193
|
// observe text changes
|
|
167
|
-
}),
|
|
194
|
+
}), r.emit("ready"), r;
|
|
168
195
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -46,4 +46,15 @@ Object.keys(_editor).forEach(function (key) {
|
|
|
46
46
|
return _editor[key];
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
+
});
|
|
50
|
+
var _dragDrop = require("./drag-drop");
|
|
51
|
+
Object.keys(_dragDrop).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _dragDrop[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _dragDrop[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
49
60
|
});
|
package/dist/index.mjs
CHANGED