@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.
@@ -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): { [K in keyof IframeContext]: IframeContext[K] extends (...args: any[]) => any ? (...args: Parameters<IframeContext[K]>) => Promise<Awaited<ReturnType<IframeContext[K]>>> : IframeContext[K] extends any[] ? Promise<IframeContext[K]> : IframeContext[K] extends object ? IframeContext[K] extends infer T ? { [K_2 in keyof T]: T[K_2] extends (...args: any[]) => any ? (...args: Parameters<T[K_2]>) => Promise<Awaited<ReturnType<T[K_2]>>> : T[K_2] extends any[] ? Promise<T[K_2]> : T[K_2] extends object ? T[K_2] extends infer T_1 ? { [K_3 in keyof T_1]: T_1[K_3] extends (...args: any[]) => any ? (...args: Parameters<T_1[K_3]>) => Promise<Awaited<ReturnType<T_1[K_3]>>> : T_1[K_3] extends any[] ? Promise<T_1[K_3]> : T_1[K_3] extends object ? T_1[K_3] extends infer T_2 ? { [K_4 in keyof T_2]: T_2[K_4] extends (...args: any[]) => any ? (...args: Parameters<T_2[K_4]>) => Promise<Awaited<ReturnType<T_2[K_4]>>> : T_2[K_4] extends any[] ? Promise<T_2[K_4]> : T_2[K_4] extends object ? T_2[K_4] extends infer T_3 ? { [K_5 in keyof T_3]: T_3[K_5] extends (...args: any[]) => any ? (...args: Parameters<T_3[K_5]>) => Promise<Awaited<ReturnType<T_3[K_5]>>> : T_3[K_5] extends any[] ? Promise<T_3[K_5]> : T_3[K_5] extends object ? T_3[K_5] extends infer T_4 ? { [K_6 in keyof T_4]: T_4[K_6] extends (...args: any[]) => any ? (...args: Parameters<T_4[K_6]>) => Promise<Awaited<ReturnType<T_4[K_6]>>> : T_4[K_6] extends any[] ? Promise<T_4[K_6]> : T_4[K_6] extends object ? T_4[K_6] extends infer T_5 ? { [K_7 in keyof T_5]: T_5[K_7] extends (...args: any[]) => any ? (...args: Parameters<T_5[K_7]>) => Promise<Awaited<ReturnType<T_5[K_7]>>> : T_5[K_7] extends any[] ? Promise<T_5[K_7]> : T_5[K_7] extends object ? T_5[K_7] extends infer T_6 ? { [K_8 in keyof T_6]: T_6[K_8] extends (...args: any[]) => any ? (...args: Parameters<T_6[K_8]>) => Promise<Awaited<ReturnType<T_6[K_8]>>> : T_6[K_8] extends any[] ? Promise<T_6[K_8]> : T_6[K_8] extends object ? T_6[K_8] extends infer T_7 ? { [K_9 in keyof T_7]: T_7[K_9] extends (...args: any[]) => any ? (...args: Parameters<T_7[K_9]>) => Promise<Awaited<ReturnType<T_7[K_9]>>> : T_7[K_9] extends any[] ? Promise<T_7[K_9]> : T_7[K_9] extends object ? T_7[K_9] extends infer T_8 ? { [K_10 in keyof T_8]: T_8[K_10] extends (...args: any[]) => any ? (...args: Parameters<T_8[K_10]>) => Promise<Awaited<ReturnType<T_8[K_10]>>> : T_8[K_10] extends any[] ? Promise<T_8[K_10]> : T_8[K_10] extends object ? T_8[K_10] extends infer T_9 ? { [K_11 in keyof T_9]: T_9[K_11] extends (...args: any[]) => any ? (...args: Parameters<T_9[K_11]>) => Promise<Awaited<ReturnType<T_9[K_11]>>> : T_9[K_11] extends any[] ? Promise<T_9[K_11]> : T_9[K_11] extends object ? /*elided*/ any : Promise<T_9[K_11]>; } : never : Promise<T_8[K_10]>; } : never : Promise<T_7[K_9]>; } : never : Promise<T_6[K_8]>; } : never : Promise<T_5[K_7]>; } : never : Promise<T_4[K_6]>; } : never : Promise<T_3[K_5]>; } : never : Promise<T_2[K_4]>; } : never : Promise<T_1[K_3]>; } : never : Promise<T[K_2]>; } : never : Promise<IframeContext[K]>; } & {
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 _createClient = require("./createClient");
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, _createClient.createClient)({}, {
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 "./createClient.mjs";
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 _createClient = require("./createClient");
8
+ var _rpc = require("@nookuio/rpc");
9
9
  var _telejson = require("telejson");
10
- function b(c, l) {
11
- return `[data-node-id="${l}"][data-node-path="${c}"]`;
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(c, l) {
14
- const s = document.querySelectorAll(c);
15
- if (!s?.length) return;
16
- const d = Array.from(s).map(f => {
17
- const u = f.getBoundingClientRect(),
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: u.width,
20
- height: u.height,
21
- top: u.top,
22
- left: u.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 m = window.getComputedStyle(f) ?? {};
26
+ const u = window.getComputedStyle(f) ?? {};
26
27
  return {
27
28
  ...g,
28
29
  padding: {
29
- top: m.paddingTop,
30
- right: m.paddingRight,
31
- bottom: m.paddingBottom,
32
- left: m.paddingLeft
30
+ top: u.paddingTop,
31
+ right: u.paddingRight,
32
+ bottom: u.paddingBottom,
33
+ left: u.paddingLeft
33
34
  }
34
35
  };
35
36
  });
36
- if (d?.length) return d.length === 1 ? d[0] : d;
37
+ if (r?.length) return r.length === 1 ? r[0] : r;
37
38
  }
38
- function createVueIframeClient(c, l) {
39
- const s = (0, _createClient.createClient)({
40
- ...c,
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 i = b(e, t),
47
- n = document.querySelector(i);
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 = a => {
51
- const E = a.target;
60
+ const o = i => {
61
+ const E = i.target;
52
62
  if (!E) return;
53
63
  const y = E.innerText;
54
- n.removeAttribute("contenteditable"), s.emit("text-update", {
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", r), n.blur();
68
+ }), n.removeEventListener("blur", o), n.removeEventListener("keydown", s), n.blur();
59
69
  },
60
- r = a => {
61
- a.key === "Enter" && (a.stopPropagation(), a.preventDefault(), o(a));
70
+ s = i => {
71
+ i.key === "Enter" && (i.stopPropagation(), i.preventDefault(), o(i));
62
72
  };
63
- n.addEventListener("keydown", r), n.addEventListener("blur", o), n.focus();
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: i,
78
+ x: a,
69
79
  y: n
70
80
  }) {
71
- if (e) if (i !== void 0 && n !== void 0) {
72
- let o = document.elementFromPoint(i, n);
81
+ if (e) if (a !== void 0 && n !== void 0) {
82
+ let o = document.elementFromPoint(a, n);
73
83
  if (!o) return;
74
- let r = o.getAttribute("data-node-path");
75
- if (r !== e) {
84
+ let s = o.getAttribute("data-node-path");
85
+ if (s !== e) {
76
86
  if (!o.parentElement) return;
77
- for (; o.parentElement && r !== e;) o = o.parentElement, r = o.getAttribute("data-node-path");
87
+ for (; o.parentElement && s !== e;) o = o.parentElement, s = o.getAttribute("data-node-path");
78
88
  }
79
- const a = o.getAttribute("data-node-id");
80
- if (!a) return;
81
- const E = b(e, a),
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: a,
94
+ id: i,
85
95
  path: e,
86
96
  data: y
87
97
  } : void 0;
88
98
  } else {
89
- const o = b(e, t),
90
- r = h(o, !1);
91
- return r ? {
99
+ const o = p(e, t),
100
+ s = h(o, !1);
101
+ return s ? {
92
102
  id: t,
93
103
  path: e,
94
- data: r
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 i = b(e, t),
106
- n = h(i, !0);
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
- toggleTheme(e) {
114
- e === "dark" ? (document.documentElement.classList.remove("light"), document.documentElement.classList.add("dark")) : (document.documentElement.classList.remove("dark"), document.documentElement.classList.add("light"));
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 i = await e(t.data.request);
146
+ const a = await e(t.data.request);
121
147
  window.parent.postMessage({
122
148
  source: _constants.IFRAME_SOURCE_NAME,
123
- response: i
149
+ response: a
124
150
  }, "*");
125
151
  });
126
152
  },
127
153
  invoke(e) {
128
- return new Promise((t, i) => {
154
+ return new Promise((t, a) => {
129
155
  const n = setTimeout(() => {
130
- window.removeEventListener("message", o), i(new Error("Request timed out"));
156
+ window.removeEventListener("message", o), a(new Error("Request timed out"));
131
157
  }, 5e3);
132
- function o(r) {
133
- typeof r.data == "object" && (r.data.source !== _constants.EDITOR_SOURCE_NAME || !r.data.response || r.data.response.id === e.id && (clearTimeout(n), window.removeEventListener("message", o), t(r.data.response)));
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
- d = l?.disableDefaultConsole ? void 0 : console.log.bind(console),
159
- f = l?.disableDefaultConsole ? void 0 : console.warn.bind(console),
160
- u = l?.disableDefaultConsole ? void 0 : console.error.bind(console),
161
- g = l?.disableDefaultConsole ? void 0 : console.info.bind(console);
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
- s.emit("console", "log", e), d?.(...e);
189
+ r.emit("console", "log", e), f?.(...e);
164
190
  }, console.warn = (...e) => {
165
- f?.(...e);
191
+ c?.(...e);
166
192
  }, console.error = (...e) => {
167
- s.emit("console", "error", e), u?.(...e);
193
+ r.emit("console", "error", e), g?.(...e);
168
194
  }, console.info = (...e) => {
169
- s.emit("console", "info", e), g?.(...e);
170
- }, window.addEventListener("resize", async () => s.emit("resize", await s.$context.getPageHeight())), new MutationObserver(async () => s.emit("resize", await s.$context.getPageHeight())).observe(document.body, {
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
- }), s.emit("ready"), s;
201
+ }), r.emit("ready"), r;
176
202
  }
package/dist/iframe.mjs CHANGED
@@ -1,78 +1,88 @@
1
- import { EDITOR_SOURCE_NAME as p, IFRAME_SOURCE_NAME as w } from "./constants.mjs";
2
- import { createClient as C } from "./createClient.mjs";
3
- import { stringify as v, parse as L } from "telejson";
4
- function b(c, l) {
5
- return `[data-node-id="${l}"][data-node-path="${c}"]`;
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(c, l) {
8
- const s = document.querySelectorAll(c);
9
- if (!s?.length) return;
10
- const d = Array.from(s).map((f) => {
11
- const u = f.getBoundingClientRect(), g = {
12
- width: u.width,
13
- height: u.height,
14
- top: u.top,
15
- left: u.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 m = window.getComputedStyle(f) ?? {};
19
+ const u = window.getComputedStyle(f) ?? {};
19
20
  return {
20
21
  ...g,
21
22
  padding: {
22
- top: m.paddingTop,
23
- right: m.paddingRight,
24
- bottom: m.paddingBottom,
25
- left: m.paddingLeft
23
+ top: u.paddingTop,
24
+ right: u.paddingRight,
25
+ bottom: u.paddingBottom,
26
+ left: u.paddingLeft
26
27
  }
27
28
  };
28
29
  });
29
- if (d?.length)
30
- return d.length === 1 ? d[0] : d;
30
+ if (r?.length)
31
+ return r.length === 1 ? r[0] : r;
31
32
  }
32
- export function createVueIframeClient(c, l) {
33
- const s = C(
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
- ...c,
45
+ ...m,
36
46
  async editText({ path: e, id: t }) {
37
47
  if (!e || t === void 0) return;
38
- const i = b(e, t), n = document.querySelector(i);
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 = (a) => {
42
- const E = a.target;
51
+ const o = (i) => {
52
+ const E = i.target;
43
53
  if (!E) return;
44
54
  const y = E.innerText;
45
- n.removeAttribute("contenteditable"), s.emit("text-update", { path: e, id: t, content: y }), n.removeEventListener("blur", o), n.removeEventListener("keydown", r), n.blur();
46
- }, r = (a) => {
47
- a.key === "Enter" && (a.stopPropagation(), a.preventDefault(), o(a));
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", r), n.addEventListener("blur", o), n.focus();
59
+ n.addEventListener("keydown", s), n.addEventListener("blur", o), n.focus();
50
60
  },
51
- async getHoveredElement({ path: e, id: t, x: i, y: n }) {
61
+ async getHoveredElement({ path: e, id: t, x: a, y: n }) {
52
62
  if (e)
53
- if (i !== void 0 && n !== void 0) {
54
- let o = document.elementFromPoint(i, n);
63
+ if (a !== void 0 && n !== void 0) {
64
+ let o = document.elementFromPoint(a, n);
55
65
  if (!o) return;
56
- let r = o.getAttribute("data-node-path");
57
- if (r !== e) {
66
+ let s = o.getAttribute("data-node-path");
67
+ if (s !== e) {
58
68
  if (!o.parentElement) return;
59
- for (; o.parentElement && r !== e; )
60
- o = o.parentElement, r = o.getAttribute("data-node-path");
69
+ for (; o.parentElement && s !== e; )
70
+ o = o.parentElement, s = o.getAttribute("data-node-path");
61
71
  }
62
- const a = o.getAttribute("data-node-id");
63
- if (!a) return;
64
- const E = b(e, a), y = h(E, !1);
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: a,
76
+ id: i,
67
77
  path: e,
68
78
  data: y
69
79
  } : void 0;
70
80
  } else {
71
- const o = b(e, t), r = h(o, !1);
72
- return r ? {
81
+ const o = p(e, t), s = h(o, !1);
82
+ return s ? {
73
83
  id: t,
74
84
  path: e,
75
- data: r
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 i = b(e, t), n = h(i, !0);
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
- toggleTheme(e) {
92
- e === "dark" ? (document.documentElement.classList.remove("light"), document.documentElement.classList.add("dark")) : (document.documentElement.classList.remove("dark"), document.documentElement.classList.add("light"));
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 !== p || t.data.type === "event" || !t.data.request) return;
121
- const i = await e(t.data.request);
122
- window.parent.postMessage({ source: w, response: i }, "*");
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, i) => {
153
+ return new Promise((t, a) => {
127
154
  const n = setTimeout(() => {
128
- window.removeEventListener("message", o), i(new Error("Request timed out"));
155
+ window.removeEventListener("message", o), a(new Error("Request timed out"));
129
156
  }, 5e3);
130
- function o(r) {
131
- typeof r.data == "object" && (r.data.source !== p || !r.data.response || r.data.response.id === e.id && (clearTimeout(n), window.removeEventListener("message", o), t(r.data.response)));
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 !== p || t.data.type !== "event" || !t.data.request || e(t.data.request));
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) => L(e),
145
- serialize: (e) => v(e, { maxDepth: 1 / 0 })
171
+ deserialize: (e) => v(e),
172
+ serialize: (e) => D(e, { maxDepth: 1 / 0 })
146
173
  }
147
- ), d = l?.disableDefaultConsole ? void 0 : console.log.bind(console), f = l?.disableDefaultConsole ? void 0 : console.warn.bind(console), u = l?.disableDefaultConsole ? void 0 : console.error.bind(console), g = l?.disableDefaultConsole ? void 0 : console.info.bind(console);
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
- s.emit("console", "log", e), d?.(...e);
176
+ r.emit("console", "log", e), f?.(...e);
150
177
  }, console.warn = (...e) => {
151
- f?.(...e);
178
+ c?.(...e);
152
179
  }, console.error = (...e) => {
153
- s.emit("console", "error", e), u?.(...e);
180
+ r.emit("console", "error", e), g?.(...e);
154
181
  }, console.info = (...e) => {
155
- s.emit("console", "info", e), g?.(...e);
156
- }, window.addEventListener("resize", async () => s.emit("resize", await s.$context.getPageHeight())), new MutationObserver(
157
- async () => s.emit("resize", await s.$context.getPageHeight())
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
- }), s.emit("ready"), s;
194
+ }), r.emit("ready"), r;
168
195
  }
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './constants';
2
2
  export * from './types';
3
3
  export * from './iframe';
4
4
  export * from './editor';
5
+ export * from './drag-drop';
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
@@ -2,3 +2,4 @@ export * from "./constants.mjs";
2
2
  export * from "./types.mjs";
3
3
  export * from "./iframe.mjs";
4
4
  export * from "./editor.mjs";
5
+ export * from "./drag-drop/index.mjs";