@nookuio/iframe 1.0.2-beta.0 → 1.0.2
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 +0 -9
- package/dist/constants.js +2 -11
- package/dist/constants.mjs +1 -9
- package/dist/editor.js +41 -35
- package/dist/editor.mjs +42 -36
- package/dist/iframe.d.ts +1 -1
- package/dist/iframe.js +140 -124
- package/dist/iframe.mjs +150 -133
- package/dist/types.d.ts +7 -17
- package/package.json +2 -2
- package/dist/drag-drop/dragEnd.d.ts +0 -2
- package/dist/drag-drop/dragEnd.js +0 -27
- package/dist/drag-drop/dragEnd.mjs +0 -23
- package/dist/drag-drop/dragMove.d.ts +0 -2
- package/dist/drag-drop/dragMove.js +0 -46
- package/dist/drag-drop/dragMove.mjs +0 -40
- package/dist/drag-drop/dragReorder.d.ts +0 -3
- package/dist/drag-drop/dragReorder.js +0 -60
- package/dist/drag-drop/dragReorder.mjs +0 -64
- package/dist/drag-drop/dragStart.d.ts +0 -9
- package/dist/drag-drop/dragStart.js +0 -60
- package/dist/drag-drop/dragStart.mjs +0 -55
- package/dist/drag-drop/helpers.d.ts +0 -42
- package/dist/drag-drop/helpers.js +0 -205
- package/dist/drag-drop/helpers.mjs +0 -188
- package/dist/drag-drop/highlight.d.ts +0 -19
- package/dist/drag-drop/highlight.js +0 -34
- package/dist/drag-drop/highlight.mjs +0 -21
- package/dist/drag-drop/index.d.ts +0 -24
- package/dist/drag-drop/index.js +0 -106
- package/dist/drag-drop/index.mjs +0 -83
- package/dist/drag-drop/types.d.ts +0 -123
- package/dist/drag-drop/types.js +0 -1
- package/dist/drag-drop/types.mjs +0 -0
- package/dist/drag-drop backup/dragDropManager.d.ts +0 -101
- package/dist/drag-drop backup/dragDropManager.js +0 -204
- package/dist/drag-drop backup/dragDropManager.mjs +0 -183
- package/dist/drag-drop backup/index.d.ts +0 -3
- package/dist/drag-drop backup/index.js +0 -38
- package/dist/drag-drop backup/index.mjs +0 -3
- package/dist/drag-drop backup/types.d.ts +0 -80
- package/dist/drag-drop backup/types.js +0 -1
- package/dist/drag-drop backup/types.mjs +0 -0
- package/dist/drag-drop backup/utils.d.ts +0 -41
- package/dist/drag-drop backup/utils.js +0 -93
- package/dist/drag-drop backup/utils.mjs +0 -68
package/dist/constants.d.ts
CHANGED
|
@@ -6,12 +6,3 @@ export declare const COMPONENT_PREVIEW_PAGE_PATH = "/__nooku__/component-preview
|
|
|
6
6
|
export declare const VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = "/__nooku__/virtual-sfc-editor";
|
|
7
7
|
export declare const IFRAME_SOURCE_NAME = "nooku-frame";
|
|
8
8
|
export declare const EDITOR_SOURCE_NAME = "nooku-editor";
|
|
9
|
-
export declare const ATTRIBUTES: {
|
|
10
|
-
id: string;
|
|
11
|
-
path: string;
|
|
12
|
-
type: string;
|
|
13
|
-
index: string;
|
|
14
|
-
component: string;
|
|
15
|
-
forceRender: string;
|
|
16
|
-
selected: string;
|
|
17
|
-
};
|
package/dist/constants.js
CHANGED
|
@@ -3,18 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = exports.IFRAME_SOURCE_NAME = exports.EDITOR_SOURCE_NAME = exports.EDITOR_PAGE_PATH = exports.COMPONENT_PREVIEW_PAGE_PATH =
|
|
6
|
+
exports.VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = exports.IFRAME_SOURCE_NAME = exports.EDITOR_SOURCE_NAME = exports.EDITOR_PAGE_PATH = exports.COMPONENT_PREVIEW_PAGE_PATH = void 0;
|
|
7
7
|
const EDITOR_PAGE_PATH = exports.EDITOR_PAGE_PATH = "/__nooku__/editor",
|
|
8
8
|
COMPONENT_PREVIEW_PAGE_PATH = exports.COMPONENT_PREVIEW_PAGE_PATH = "/__nooku__/component-preview",
|
|
9
9
|
VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = exports.VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = "/__nooku__/virtual-sfc-editor",
|
|
10
10
|
IFRAME_SOURCE_NAME = exports.IFRAME_SOURCE_NAME = "nooku-frame",
|
|
11
|
-
EDITOR_SOURCE_NAME = exports.EDITOR_SOURCE_NAME = "nooku-editor"
|
|
12
|
-
ATTRIBUTES = exports.ATTRIBUTES = {
|
|
13
|
-
id: "data-node-id",
|
|
14
|
-
path: "data-node-path",
|
|
15
|
-
type: "data-node-type",
|
|
16
|
-
index: "data-node-index",
|
|
17
|
-
component: "data-node-component",
|
|
18
|
-
forceRender: "data-node-force-render",
|
|
19
|
-
selected: "data-node-selected"
|
|
20
|
-
};
|
|
11
|
+
EDITOR_SOURCE_NAME = exports.EDITOR_SOURCE_NAME = "nooku-editor";
|
package/dist/constants.mjs
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export const EDITOR_PAGE_PATH = "/__nooku__/editor", COMPONENT_PREVIEW_PAGE_PATH = "/__nooku__/component-preview", VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = "/__nooku__/virtual-sfc-editor", IFRAME_SOURCE_NAME = "nooku-frame", EDITOR_SOURCE_NAME = "nooku-editor"
|
|
2
|
-
id: "data-node-id",
|
|
3
|
-
path: "data-node-path",
|
|
4
|
-
type: "data-node-type",
|
|
5
|
-
index: "data-node-index",
|
|
6
|
-
component: "data-node-component",
|
|
7
|
-
forceRender: "data-node-force-render",
|
|
8
|
-
selected: "data-node-selected"
|
|
9
|
-
};
|
|
1
|
+
export const EDITOR_PAGE_PATH = "/__nooku__/editor", COMPONENT_PREVIEW_PAGE_PATH = "/__nooku__/component-preview", VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = "/__nooku__/virtual-sfc-editor", IFRAME_SOURCE_NAME = "nooku-frame", EDITOR_SOURCE_NAME = "nooku-editor";
|
package/dist/editor.js
CHANGED
|
@@ -7,58 +7,60 @@ exports.createEditorClient = createEditorClient;
|
|
|
7
7
|
var _constants = require("./constants");
|
|
8
8
|
var _rpc = require("@nookuio/rpc");
|
|
9
9
|
var _telejson = require("telejson");
|
|
10
|
-
function
|
|
11
|
-
const
|
|
10
|
+
function l(s) {
|
|
11
|
+
const a = (0, _telejson.parse)(s, {
|
|
12
12
|
maxDepth: 1 / 0
|
|
13
13
|
}),
|
|
14
|
-
|
|
15
|
-
if (Array.isArray(
|
|
16
|
-
|
|
17
|
-
});else if (
|
|
18
|
-
if (
|
|
19
|
-
...
|
|
14
|
+
n = r => {
|
|
15
|
+
if (Array.isArray(r)) r.forEach((e, t) => {
|
|
16
|
+
r[t] = n(e);
|
|
17
|
+
});else if (r && typeof r == "object") {
|
|
18
|
+
if (r.hasOwnProperty("__v_isRef")) return {
|
|
19
|
+
...r,
|
|
20
20
|
__v_isRef: "true",
|
|
21
|
-
value:
|
|
21
|
+
value: r.hasOwnProperty("value") && r.value !== void 0 ? r.value : r._value ?? r._rawValue
|
|
22
22
|
};
|
|
23
|
-
Object.keys(
|
|
24
|
-
e
|
|
23
|
+
Object.keys(r).forEach(e => {
|
|
24
|
+
r[e] = n(r[e]);
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
return
|
|
27
|
+
return r;
|
|
28
28
|
};
|
|
29
|
-
return
|
|
29
|
+
return n(a);
|
|
30
30
|
}
|
|
31
|
-
function createEditorClient(
|
|
32
|
-
let
|
|
33
|
-
function
|
|
34
|
-
return (!
|
|
31
|
+
function createEditorClient(s) {
|
|
32
|
+
let a;
|
|
33
|
+
function n() {
|
|
34
|
+
return (!a || !a.isConnected) && (a = typeof s == "string" ? document.querySelector(`#${s}`) : s), a;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
const i = new Map();
|
|
37
|
+
return window.addEventListener("message", async e => {
|
|
38
|
+
if (typeof e.data != "object" || e.data.source !== _constants.IFRAME_SOURCE_NAME || e.data.type === "event" || !e.data.response) return;
|
|
39
|
+
const t = i.get(e.data.response.id);
|
|
40
|
+
t && (i.delete(e.data.response.id), t(e.data.response));
|
|
41
|
+
}), (0, _rpc.createClient)({}, {
|
|
37
42
|
handle(e) {
|
|
38
43
|
window.addEventListener("message", async t => {
|
|
39
44
|
if (typeof t.data != "object" || t.data.source !== _constants.IFRAME_SOURCE_NAME || t.data.type === "event" || !t.data.request) return;
|
|
40
|
-
const
|
|
41
|
-
if (!
|
|
42
|
-
const
|
|
43
|
-
|
|
45
|
+
const o = n();
|
|
46
|
+
if (!o) return;
|
|
47
|
+
const d = await e(t.data.request);
|
|
48
|
+
o.contentWindow?.postMessage({
|
|
44
49
|
source: _constants.EDITOR_SOURCE_NAME,
|
|
45
|
-
response:
|
|
50
|
+
response: d
|
|
46
51
|
}, "*");
|
|
47
52
|
});
|
|
48
53
|
},
|
|
49
54
|
async invoke(e) {
|
|
50
|
-
const t =
|
|
51
|
-
return t ? new Promise((
|
|
52
|
-
const c = setTimeout(() =>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
typeof i.data == "object" && (i.data.source !== _constants.IFRAME_SOURCE_NAME || !i.data.response || i.data.response.id === e.id && (clearTimeout(c), window.removeEventListener("message", d), s(i.data.response)));
|
|
57
|
-
}
|
|
58
|
-
t.contentWindow?.postMessage({
|
|
55
|
+
const t = n();
|
|
56
|
+
return t ? new Promise((o, d) => {
|
|
57
|
+
const c = setTimeout(() => d(new Error("Request timed out")), 5e3);
|
|
58
|
+
i.set(e.id, m => {
|
|
59
|
+
clearTimeout(c), o(m);
|
|
60
|
+
}), t.contentWindow?.postMessage({
|
|
59
61
|
source: _constants.EDITOR_SOURCE_NAME,
|
|
60
62
|
request: e
|
|
61
|
-
}, "*")
|
|
63
|
+
}, "*");
|
|
62
64
|
}) : {
|
|
63
65
|
type: "response",
|
|
64
66
|
id: e.id,
|
|
@@ -67,7 +69,7 @@ function createEditorClient(a) {
|
|
|
67
69
|
};
|
|
68
70
|
},
|
|
69
71
|
emit(e) {
|
|
70
|
-
const t =
|
|
72
|
+
const t = n();
|
|
71
73
|
t && t.contentWindow?.postMessage({
|
|
72
74
|
source: _constants.EDITOR_SOURCE_NAME,
|
|
73
75
|
type: "event",
|
|
@@ -79,7 +81,11 @@ function createEditorClient(a) {
|
|
|
79
81
|
typeof t.data == "object" && (t.data.source !== _constants.IFRAME_SOURCE_NAME || t.data.type !== "event" || !t.data.request || e(t.data.request));
|
|
80
82
|
});
|
|
81
83
|
},
|
|
82
|
-
|
|
84
|
+
destroy() {
|
|
85
|
+
i.clear();
|
|
86
|
+
},
|
|
87
|
+
timeout: 5e3,
|
|
88
|
+
deserialize: l,
|
|
83
89
|
serialize: e => (0, _telejson.stringify)(e, {
|
|
84
90
|
maxDepth: 1 / 0
|
|
85
91
|
})
|
package/dist/editor.mjs
CHANGED
|
@@ -1,55 +1,57 @@
|
|
|
1
1
|
import { EDITOR_SOURCE_NAME as f, IFRAME_SOURCE_NAME as u } from "./constants.mjs";
|
|
2
|
-
import { createClient as
|
|
3
|
-
import { stringify as
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
if (Array.isArray(
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { createClient as p } from "@nookuio/rpc";
|
|
3
|
+
import { stringify as y, parse as E } from "telejson";
|
|
4
|
+
function l(s) {
|
|
5
|
+
const a = E(s, { maxDepth: 1 / 0 }), n = (r) => {
|
|
6
|
+
if (Array.isArray(r))
|
|
7
|
+
r.forEach((e, t) => {
|
|
8
|
+
r[t] = n(e);
|
|
9
9
|
});
|
|
10
|
-
else if (
|
|
11
|
-
if (
|
|
10
|
+
else if (r && typeof r == "object") {
|
|
11
|
+
if (r.hasOwnProperty("__v_isRef"))
|
|
12
12
|
return {
|
|
13
|
-
...
|
|
13
|
+
...r,
|
|
14
14
|
__v_isRef: "true",
|
|
15
15
|
// converted to string
|
|
16
|
-
value:
|
|
16
|
+
value: r.hasOwnProperty("value") && r.value !== void 0 ? r.value : r._value ?? r._rawValue
|
|
17
17
|
};
|
|
18
|
-
Object.keys(
|
|
19
|
-
e
|
|
18
|
+
Object.keys(r).forEach((e) => {
|
|
19
|
+
r[e] = n(r[e]);
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
return
|
|
22
|
+
return r;
|
|
23
23
|
};
|
|
24
|
-
return
|
|
24
|
+
return n(a);
|
|
25
25
|
}
|
|
26
|
-
export function createEditorClient(
|
|
27
|
-
let
|
|
28
|
-
function
|
|
29
|
-
return (!
|
|
26
|
+
export function createEditorClient(s) {
|
|
27
|
+
let a;
|
|
28
|
+
function n() {
|
|
29
|
+
return (!a || !a.isConnected) && (a = typeof s == "string" ? document.querySelector(`#${s}`) : s), a;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
const i = /* @__PURE__ */ new Map();
|
|
32
|
+
return window.addEventListener("message", async (e) => {
|
|
33
|
+
if (typeof e.data != "object" || e.data.source !== u || e.data.type === "event" || !e.data.response) return;
|
|
34
|
+
const t = i.get(e.data.response.id);
|
|
35
|
+
t && (i.delete(e.data.response.id), t(e.data.response));
|
|
36
|
+
}), p(
|
|
32
37
|
{},
|
|
33
38
|
{
|
|
34
39
|
handle(e) {
|
|
35
40
|
window.addEventListener("message", async (t) => {
|
|
36
41
|
if (typeof t.data != "object" || t.data.source !== u || t.data.type === "event" || !t.data.request) return;
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
const
|
|
40
|
-
|
|
42
|
+
const o = n();
|
|
43
|
+
if (!o) return;
|
|
44
|
+
const d = await e(t.data.request);
|
|
45
|
+
o.contentWindow?.postMessage({ source: f, response: d }, "*");
|
|
41
46
|
});
|
|
42
47
|
},
|
|
43
48
|
async invoke(e) {
|
|
44
|
-
const t =
|
|
45
|
-
return t ? new Promise((
|
|
46
|
-
const c = setTimeout(() =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
typeof i.data == "object" && (i.data.source !== u || !i.data.response || i.data.response.id === e.id && (clearTimeout(c), window.removeEventListener("message", d), s(i.data.response)));
|
|
51
|
-
}
|
|
52
|
-
t.contentWindow?.postMessage({ source: f, request: e }, "*"), window.addEventListener("message", d);
|
|
49
|
+
const t = n();
|
|
50
|
+
return t ? new Promise((o, d) => {
|
|
51
|
+
const c = setTimeout(() => d(new Error("Request timed out")), 5e3);
|
|
52
|
+
i.set(e.id, (m) => {
|
|
53
|
+
clearTimeout(c), o(m);
|
|
54
|
+
}), t.contentWindow?.postMessage({ source: f, request: e }, "*");
|
|
53
55
|
}) : {
|
|
54
56
|
type: "response",
|
|
55
57
|
id: e.id,
|
|
@@ -58,7 +60,7 @@ export function createEditorClient(a) {
|
|
|
58
60
|
};
|
|
59
61
|
},
|
|
60
62
|
emit(e) {
|
|
61
|
-
const t =
|
|
63
|
+
const t = n();
|
|
62
64
|
t && t.contentWindow?.postMessage({ source: f, type: "event", request: e }, "*");
|
|
63
65
|
},
|
|
64
66
|
handleEvent(e) {
|
|
@@ -66,8 +68,12 @@ export function createEditorClient(a) {
|
|
|
66
68
|
typeof t.data == "object" && (t.data.source !== u || t.data.type !== "event" || !t.data.request || e(t.data.request));
|
|
67
69
|
});
|
|
68
70
|
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
destroy() {
|
|
72
|
+
i.clear();
|
|
73
|
+
},
|
|
74
|
+
timeout: 5e3,
|
|
75
|
+
deserialize: l,
|
|
76
|
+
serialize: (e) => y(e, { maxDepth: 1 / 0 })
|
|
71
77
|
}
|
|
72
78
|
);
|
|
73
79
|
}
|
package/dist/iframe.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { CoreIframeContext, EditorContext, EditorEvents, VueIframeContext,
|
|
|
2
2
|
/**
|
|
3
3
|
* This function should be called inside the iframe
|
|
4
4
|
*/
|
|
5
|
-
export declare function createVueIframeClient(vueCtx: Omit<VueIframeContext, keyof CoreIframeContext
|
|
5
|
+
export declare function createVueIframeClient(vueCtx: Omit<VueIframeContext, Exclude<keyof CoreIframeContext, 'updateCode'>>, options?: {
|
|
6
6
|
/**
|
|
7
7
|
* If true, the default console methods will be disabled
|
|
8
8
|
*
|
package/dist/iframe.js
CHANGED
|
@@ -7,139 +7,151 @@ exports.createVueIframeClient = createVueIframeClient;
|
|
|
7
7
|
var _constants = require("./constants");
|
|
8
8
|
var _rpc = require("@nookuio/rpc");
|
|
9
9
|
var _telejson = require("telejson");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return `[data-node-id="${d}"][data-node-path="${u}"]`;
|
|
10
|
+
function u(c, a) {
|
|
11
|
+
return `[data-node-id="${a}"][data-node-path="${c}"]`;
|
|
13
12
|
}
|
|
14
|
-
function
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
width:
|
|
21
|
-
height:
|
|
22
|
-
top:
|
|
23
|
-
left:
|
|
13
|
+
function y(c, a) {
|
|
14
|
+
const n = document.querySelectorAll(c);
|
|
15
|
+
if (!n?.length) return;
|
|
16
|
+
const t = Array.from(n).map(d => {
|
|
17
|
+
const o = d.getBoundingClientRect(),
|
|
18
|
+
s = {
|
|
19
|
+
width: o.width,
|
|
20
|
+
height: o.height,
|
|
21
|
+
top: o.top,
|
|
22
|
+
left: o.left
|
|
24
23
|
};
|
|
25
|
-
if (!
|
|
26
|
-
const
|
|
24
|
+
if (!a) return s;
|
|
25
|
+
const i = window.getComputedStyle(d) ?? {};
|
|
27
26
|
return {
|
|
28
|
-
...
|
|
27
|
+
...s,
|
|
29
28
|
padding: {
|
|
30
|
-
top:
|
|
31
|
-
right:
|
|
32
|
-
bottom:
|
|
33
|
-
left:
|
|
29
|
+
top: i.paddingTop,
|
|
30
|
+
right: i.paddingRight,
|
|
31
|
+
bottom: i.paddingBottom,
|
|
32
|
+
left: i.paddingLeft
|
|
34
33
|
}
|
|
35
34
|
};
|
|
36
35
|
});
|
|
37
|
-
if (
|
|
36
|
+
if (t?.length) return t.length === 1 ? t[0] : t;
|
|
38
37
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
id: t,
|
|
60
|
-
content: y
|
|
61
|
-
}), n.removeEventListener("blur", o), n.removeEventListener("keydown", s), n.blur();
|
|
62
|
-
},
|
|
63
|
-
s = a => {
|
|
64
|
-
a.key === "Enter" && (a.stopPropagation(), a.preventDefault(), o(a));
|
|
65
|
-
};
|
|
66
|
-
n.addEventListener("keydown", s), n.addEventListener("blur", o), n.focus();
|
|
67
|
-
},
|
|
68
|
-
async getHoveredElement({
|
|
69
|
-
path: e,
|
|
70
|
-
id: t,
|
|
71
|
-
x: i,
|
|
72
|
-
y: n
|
|
73
|
-
}) {
|
|
74
|
-
if (e) if (i !== void 0 && n !== void 0) {
|
|
75
|
-
let o = document.elementFromPoint(i, n);
|
|
76
|
-
if (!o) return;
|
|
77
|
-
let s = o.getAttribute("data-node-path");
|
|
78
|
-
if (s !== e) {
|
|
79
|
-
if (!o.parentElement) return;
|
|
80
|
-
for (; o.parentElement && s !== e;) o = o.parentElement, s = o.getAttribute("data-node-path");
|
|
81
|
-
}
|
|
82
|
-
const a = o.getAttribute("data-node-id");
|
|
83
|
-
if (!a) return;
|
|
84
|
-
const E = p(e, a),
|
|
85
|
-
y = h(E, !1);
|
|
86
|
-
return y ? {
|
|
87
|
-
id: a,
|
|
88
|
-
path: e,
|
|
89
|
-
data: y
|
|
90
|
-
} : void 0;
|
|
91
|
-
} else {
|
|
92
|
-
const o = p(e, t),
|
|
93
|
-
s = h(o, !1);
|
|
94
|
-
return s ? {
|
|
38
|
+
function C(c) {
|
|
39
|
+
async function a() {
|
|
40
|
+
return document.body.scrollHeight > 0 ? document.body.scrollHeight : document.documentElement.scrollHeight;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
async editText({
|
|
44
|
+
path: n,
|
|
45
|
+
id: t
|
|
46
|
+
}) {
|
|
47
|
+
if (!n || t === void 0) return;
|
|
48
|
+
const d = u(n, t),
|
|
49
|
+
o = document.querySelector(d);
|
|
50
|
+
if (!o) return;
|
|
51
|
+
o.style.outline = "none", o.setAttribute("spellcheck", "false"), o.setAttribute("contenteditable", "true");
|
|
52
|
+
const s = l => {
|
|
53
|
+
const e = l.target;
|
|
54
|
+
if (!e) return;
|
|
55
|
+
const r = e.innerText;
|
|
56
|
+
o.removeAttribute("contenteditable"), c?.onTextUpdate?.({
|
|
57
|
+
path: n,
|
|
95
58
|
id: t,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
59
|
+
content: r
|
|
60
|
+
}), o.removeEventListener("blur", s), o.removeEventListener("keydown", i), o.blur();
|
|
61
|
+
},
|
|
62
|
+
i = l => {
|
|
63
|
+
l.key === "Enter" && (l.stopPropagation(), l.preventDefault(), s(l));
|
|
64
|
+
};
|
|
65
|
+
o.addEventListener("keydown", i), o.addEventListener("blur", s), o.focus();
|
|
66
|
+
},
|
|
67
|
+
async getHoveredElement({
|
|
68
|
+
path: n,
|
|
69
|
+
id: t,
|
|
70
|
+
x: d,
|
|
71
|
+
y: o
|
|
72
|
+
}) {
|
|
73
|
+
if (n) if (d !== void 0 && o !== void 0) {
|
|
74
|
+
let s = document.elementFromPoint(d, o);
|
|
75
|
+
if (!s) return;
|
|
76
|
+
let i = s.getAttribute("data-node-path");
|
|
77
|
+
if (i !== n) {
|
|
78
|
+
if (!s.parentElement) return;
|
|
79
|
+
for (; s.parentElement && i !== n;) s = s.parentElement, i = s.getAttribute("data-node-path");
|
|
99
80
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
81
|
+
const l = s.getAttribute("data-node-id");
|
|
82
|
+
if (!l) return;
|
|
83
|
+
const e = u(n, l),
|
|
84
|
+
r = y(e, !1);
|
|
85
|
+
return r ? {
|
|
86
|
+
id: l,
|
|
87
|
+
path: n,
|
|
88
|
+
data: r
|
|
89
|
+
} : void 0;
|
|
90
|
+
} else {
|
|
91
|
+
const s = u(n, t),
|
|
92
|
+
i = y(s, !1);
|
|
93
|
+
return i ? {
|
|
112
94
|
id: t,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
setTheme(e) {
|
|
117
|
-
const t = document.querySelector("body");
|
|
118
|
-
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")));
|
|
95
|
+
path: n,
|
|
96
|
+
data: i
|
|
97
|
+
} : void 0;
|
|
119
98
|
}
|
|
99
|
+
},
|
|
100
|
+
getPageHeight: a,
|
|
101
|
+
async getSelectedElement({
|
|
102
|
+
path: n,
|
|
103
|
+
id: t
|
|
104
|
+
}) {
|
|
105
|
+
const d = u(n, t),
|
|
106
|
+
o = y(d, !0);
|
|
107
|
+
if (o) return {
|
|
108
|
+
path: n,
|
|
109
|
+
id: t,
|
|
110
|
+
data: o
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
setTheme(n) {
|
|
114
|
+
const t = document.querySelector("body");
|
|
115
|
+
n === "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")));
|
|
116
|
+
},
|
|
117
|
+
async updateCode(n, t) {
|
|
118
|
+
typeof t > "u" ? document.body.innerHTML = "" : document.body.innerHTML = t, c?.onResize?.(await a());
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function createVueIframeClient(c, a) {
|
|
123
|
+
const n = new Map();
|
|
124
|
+
window.addEventListener("message", async e => {
|
|
125
|
+
if (typeof e.data != "object" || e.data.source !== _constants.EDITOR_SOURCE_NAME || e.data.type === "event" || !e.data.response) return;
|
|
126
|
+
const r = n.get(e.data.response.id);
|
|
127
|
+
r && (n.delete(e.data.response.id), r(e.data.response));
|
|
128
|
+
});
|
|
129
|
+
const t = (0, _rpc.createClient)({
|
|
130
|
+
...C({
|
|
131
|
+
onResize: (...e) => t?.emit("resize", ...e),
|
|
132
|
+
onTextUpdate: (...e) => t?.emit("text-update", ...e)
|
|
133
|
+
}),
|
|
134
|
+
...c
|
|
120
135
|
}, {
|
|
121
136
|
handle(e) {
|
|
122
|
-
window.addEventListener("message", async
|
|
123
|
-
if (typeof
|
|
124
|
-
const
|
|
137
|
+
window.addEventListener("message", async r => {
|
|
138
|
+
if (typeof r.data != "object" || r.data.source !== _constants.EDITOR_SOURCE_NAME || r.data.type === "event" || !r.data.request) return;
|
|
139
|
+
const m = await e(r.data.request);
|
|
125
140
|
window.parent.postMessage({
|
|
126
141
|
source: _constants.IFRAME_SOURCE_NAME,
|
|
127
|
-
response:
|
|
142
|
+
response: m
|
|
128
143
|
}, "*");
|
|
129
144
|
});
|
|
130
145
|
},
|
|
131
146
|
invoke(e) {
|
|
132
|
-
return new Promise((
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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)));
|
|
138
|
-
}
|
|
139
|
-
window.parent.postMessage({
|
|
147
|
+
return new Promise((r, m) => {
|
|
148
|
+
const E = setTimeout(() => m(new Error("Request timed out")), 5e3);
|
|
149
|
+
n.set(e.id, p => {
|
|
150
|
+
clearTimeout(E), r(p);
|
|
151
|
+
}), window.parent.postMessage({
|
|
140
152
|
source: _constants.IFRAME_SOURCE_NAME,
|
|
141
153
|
request: e
|
|
142
|
-
}, "*")
|
|
154
|
+
}, "*");
|
|
143
155
|
});
|
|
144
156
|
},
|
|
145
157
|
emit(e) {
|
|
@@ -150,31 +162,35 @@ function createVueIframeClient(u, d) {
|
|
|
150
162
|
}, "*");
|
|
151
163
|
},
|
|
152
164
|
handleEvent(e) {
|
|
153
|
-
window.addEventListener("message",
|
|
154
|
-
typeof
|
|
165
|
+
window.addEventListener("message", r => {
|
|
166
|
+
typeof r.data == "object" && (r.data.source !== _constants.EDITOR_SOURCE_NAME || r.data.type !== "event" || !r.data.request || e(r.data.request));
|
|
155
167
|
});
|
|
156
168
|
},
|
|
169
|
+
destroy() {
|
|
170
|
+
n.clear();
|
|
171
|
+
},
|
|
157
172
|
deserialize: e => (0, _telejson.parse)(e),
|
|
158
173
|
serialize: e => (0, _telejson.stringify)(e, {
|
|
159
174
|
maxDepth: 1 / 0
|
|
160
|
-
})
|
|
175
|
+
}),
|
|
176
|
+
timeout: 5e3
|
|
161
177
|
}),
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
178
|
+
d = a?.disableDefaultConsole ? void 0 : console.log.bind(console),
|
|
179
|
+
o = a?.disableDefaultConsole ? void 0 : console.warn.bind(console),
|
|
180
|
+
s = a?.disableDefaultConsole ? void 0 : console.error.bind(console),
|
|
181
|
+
i = a?.disableDefaultConsole ? void 0 : console.info.bind(console);
|
|
166
182
|
return console.log = (...e) => {
|
|
167
|
-
|
|
183
|
+
t.emit("console", "log", e), d?.(...e);
|
|
168
184
|
}, console.warn = (...e) => {
|
|
169
|
-
|
|
185
|
+
o?.(...e);
|
|
170
186
|
}, console.error = (...e) => {
|
|
171
|
-
|
|
187
|
+
t.emit("console", "error", e), s?.(...e);
|
|
172
188
|
}, console.info = (...e) => {
|
|
173
|
-
|
|
174
|
-
}, window.addEventListener("resize", async () =>
|
|
189
|
+
t.emit("console", "info", e), i?.(...e);
|
|
190
|
+
}, window.addEventListener("resize", async () => t.emit("resize", await t.$context.getPageHeight())), new MutationObserver(async () => t.emit("resize", await t.$context.getPageHeight())).observe(document.body, {
|
|
175
191
|
childList: !0,
|
|
176
192
|
subtree: !0,
|
|
177
193
|
attributes: !0,
|
|
178
194
|
characterData: !0
|
|
179
|
-
}),
|
|
195
|
+
}), t.emit("ready"), t;
|
|
180
196
|
}
|