@nookuio/iframe 1.0.1-beta.0 → 1.0.1

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.
Files changed (46) hide show
  1. package/dist/constants.d.ts +0 -9
  2. package/dist/constants.js +2 -11
  3. package/dist/constants.mjs +1 -9
  4. package/dist/editor.js +41 -35
  5. package/dist/editor.mjs +42 -36
  6. package/dist/iframe.d.ts +1 -1
  7. package/dist/iframe.js +141 -126
  8. package/dist/iframe.mjs +150 -134
  9. package/dist/types.d.ts +7 -17
  10. package/package.json +2 -2
  11. package/dist/drag-drop/dragEnd.d.ts +0 -2
  12. package/dist/drag-drop/dragEnd.js +0 -27
  13. package/dist/drag-drop/dragEnd.mjs +0 -23
  14. package/dist/drag-drop/dragMove.d.ts +0 -2
  15. package/dist/drag-drop/dragMove.js +0 -46
  16. package/dist/drag-drop/dragMove.mjs +0 -40
  17. package/dist/drag-drop/dragReorder.d.ts +0 -3
  18. package/dist/drag-drop/dragReorder.js +0 -60
  19. package/dist/drag-drop/dragReorder.mjs +0 -64
  20. package/dist/drag-drop/dragStart.d.ts +0 -9
  21. package/dist/drag-drop/dragStart.js +0 -60
  22. package/dist/drag-drop/dragStart.mjs +0 -55
  23. package/dist/drag-drop/helpers.d.ts +0 -42
  24. package/dist/drag-drop/helpers.js +0 -205
  25. package/dist/drag-drop/helpers.mjs +0 -188
  26. package/dist/drag-drop/highlight.d.ts +0 -16
  27. package/dist/drag-drop/highlight.js +0 -32
  28. package/dist/drag-drop/highlight.mjs +0 -22
  29. package/dist/drag-drop/index.d.ts +0 -24
  30. package/dist/drag-drop/index.js +0 -106
  31. package/dist/drag-drop/index.mjs +0 -83
  32. package/dist/drag-drop/types.d.ts +0 -123
  33. package/dist/drag-drop/types.js +0 -1
  34. package/dist/drag-drop/types.mjs +0 -0
  35. package/dist/drag-drop backup/dragDropManager.d.ts +0 -101
  36. package/dist/drag-drop backup/dragDropManager.js +0 -204
  37. package/dist/drag-drop backup/dragDropManager.mjs +0 -183
  38. package/dist/drag-drop backup/index.d.ts +0 -3
  39. package/dist/drag-drop backup/index.js +0 -38
  40. package/dist/drag-drop backup/index.mjs +0 -3
  41. package/dist/drag-drop backup/types.d.ts +0 -80
  42. package/dist/drag-drop backup/types.js +0 -1
  43. package/dist/drag-drop backup/types.mjs +0 -0
  44. package/dist/drag-drop backup/utils.d.ts +0 -41
  45. package/dist/drag-drop backup/utils.js +0 -93
  46. package/dist/drag-drop backup/utils.mjs +0 -68
@@ -1,183 +0,0 @@
1
- import {
2
- getElement as p,
3
- getDropZones as f,
4
- canAcceptDrop as h,
5
- getElementAtPosition as b,
6
- calculateInsertIndex as u,
7
- createDropIndicator as m,
8
- positionDropIndicator as g,
9
- getParentContainer as D
10
- } from "./utils.mjs";
11
- export class DragDropManager {
12
- activeDrags = /* @__PURE__ */ new Map();
13
- dropIndicator = null;
14
- onDragStartCallback;
15
- onDragEndCallback;
16
- constructor() {
17
- this.dropIndicator = m();
18
- }
19
- /**
20
- * Set event callbacks
21
- */
22
- setCallbacks(r) {
23
- this.onDragStartCallback = r.onDragStart, this.onDragEndCallback = r.onDragEnd;
24
- }
25
- /**
26
- * Start dragging an element
27
- */
28
- async startDrag(r) {
29
- const { elementId: a, path: i, x: e, y: t } = r, o = p(a, i);
30
- if (!o)
31
- throw new Error(`Element not found: ${a} at ${i}`);
32
- const d = `drag-${Date.now()}-${Math.random()}`, n = o.getBoundingClientRect(), s = o.cloneNode(!0);
33
- s.classList.add("__nooku-drag-clone"), s.style.cssText = `
34
- position: fixed;
35
- left: ${n.left}px;
36
- top: ${n.top}px;
37
- width: ${n.width}px;
38
- height: ${n.height}px;
39
- pointer-events: none;
40
- z-index: 10000;
41
- opacity: 0.8;
42
- transition: none;
43
- `, document.body.appendChild(s), o.style.opacity = "0.3", o.classList.add("__nooku-dragging");
44
- const c = D(o), I = {
45
- dragId: d,
46
- elementId: a,
47
- path: i,
48
- startX: e,
49
- startY: t,
50
- currentX: e,
51
- currentY: t,
52
- element: o,
53
- clone: s,
54
- initialRect: n,
55
- currentDropZone: c || void 0,
56
- mode: "reorder"
57
- };
58
- return this.activeDrags.set(d, I), this.onDragStartCallback?.({ elementId: a, path: i }), { dragId: d };
59
- }
60
- /**
61
- * Update drag position
62
- */
63
- async updateDragPosition(r) {
64
- const { dragId: a, x: i, y: e } = r, t = this.activeDrags.get(a);
65
- if (!t)
66
- throw new Error(`Drag not found: ${a}`);
67
- const o = i - t.startX, d = e - t.startY;
68
- t.currentX = i, t.currentY = e, t.clone.style.left = `${t.initialRect.left + o}px`, t.clone.style.top = `${t.initialRect.top + d}px`;
69
- const n = this.findDropZoneAtPosition(i, e, t.path), s = D(t.element);
70
- n === s ? t.mode = "reorder" : n && (t.mode = "move"), n !== t.currentDropZone ? (t.currentDropZone && t.currentDropZone.classList.remove("__nooku-drop-zone-active"), t.currentDropZone = n, n ? (n.classList.add("__nooku-drop-zone-active"), this.showDropIndicator(n, i, e, t)) : this.hideDropIndicator()) : n && this.showDropIndicator(n, i, e, t);
71
- }
72
- /**
73
- * End drag operation
74
- */
75
- async endDrag(r) {
76
- const { dragId: a, canceled: i = !1 } = r, e = this.activeDrags.get(a);
77
- if (!e)
78
- throw new Error(`Drag not found: ${a}`);
79
- e.element.classList.remove("__nooku-dragging"), e.element.style.opacity = "", e.clone.remove(), e.currentDropZone && e.currentDropZone.classList.remove("__nooku-drop-zone-active"), this.hideDropIndicator();
80
- let t;
81
- if (i || !e.currentDropZone)
82
- t = { dropped: !1 };
83
- else {
84
- const o = e.currentDropZone.getAttribute("data-node-id") || void 0, d = e.currentDropZone.getAttribute("data-node-path") || void 0, { index: n } = u(e.currentDropZone, e.currentX, e.currentY, e.element);
85
- t = {
86
- dropped: !0,
87
- targetId: o,
88
- targetPath: d,
89
- insertIndex: n
90
- };
91
- }
92
- return this.activeDrags.delete(a), this.onDragEndCallback?.(t), t;
93
- }
94
- /**
95
- * Get drop zones at position
96
- */
97
- async getDropZones(r) {
98
- const { x: a, y: i } = r;
99
- return f().map((t) => {
100
- const o = t.getBoundingClientRect(), d = t.getAttribute("data-node-id") || "", n = t.getAttribute("data-node-path") || "", s = a >= o.left && a <= o.right && i >= o.top && i <= o.bottom;
101
- return {
102
- elementId: d,
103
- path: n,
104
- rect: {
105
- top: o.top,
106
- left: o.left,
107
- width: o.width,
108
- height: o.height
109
- },
110
- canDrop: s && h(t)
111
- };
112
- }).filter((t) => t.canDrop);
113
- }
114
- /**
115
- * Highlight drop zone
116
- */
117
- async highlightDropZone(r) {
118
- const { elementId: a, path: i, clear: e = !1 } = r;
119
- if (document.querySelectorAll(".__nooku-drop-zone-highlight").forEach((o) => {
120
- o.classList.remove("__nooku-drop-zone-highlight");
121
- }), e || !a || !i) {
122
- this.hideDropIndicator();
123
- return;
124
- }
125
- const t = p(a, i);
126
- t && t.classList.add("__nooku-drop-zone-highlight");
127
- }
128
- /**
129
- * Find drop zone at position
130
- */
131
- findDropZoneAtPosition(r, a, i) {
132
- const e = b(r, a, i);
133
- if (!e) return;
134
- let t = e;
135
- for (; t; ) {
136
- if (t.hasAttribute("data-node-id") && h(t))
137
- return t;
138
- t = t.parentElement;
139
- }
140
- }
141
- /**
142
- * Show drop indicator
143
- */
144
- showDropIndicator(r, a, i, e) {
145
- this.dropIndicator || (this.dropIndicator = m()), this.dropIndicator.parentElement || document.body.appendChild(this.dropIndicator);
146
- const { index: t, before: o, layout: d } = u(r, a, i, e.element), n = Array.from(r.children).filter(
147
- (s) => s.hasAttribute("data-node-id") && s !== e.element && !s.classList.contains("__nooku-drag-clone")
148
- );
149
- if (e.currentInsertIndex = t, n.length === 0) {
150
- const s = r.getBoundingClientRect();
151
- g(this.dropIndicator, s, d);
152
- } else if (t < n.length) {
153
- const c = n[t].getBoundingClientRect();
154
- d === "block" ? g(this.dropIndicator, { ...c, height: 2 }, d) : g(this.dropIndicator, { ...c, width: 2 }, d);
155
- } else {
156
- const c = n[n.length - 1].getBoundingClientRect();
157
- d === "block" ? g(this.dropIndicator, { ...c, top: c.bottom, height: 2 }, d) : g(this.dropIndicator, { ...c, left: c.right, width: 2 }, d);
158
- }
159
- this.dropIndicator.style.display = "block";
160
- }
161
- /**
162
- * Hide drop indicator
163
- */
164
- hideDropIndicator() {
165
- this.dropIndicator && (this.dropIndicator.style.display = "none");
166
- }
167
- /**
168
- * Clean up
169
- */
170
- destroy() {
171
- this.activeDrags.clear(), this.dropIndicator?.remove(), this.dropIndicator = null;
172
- }
173
- }
174
- export function createDragDropContext() {
175
- const l = new DragDropManager();
176
- return {
177
- startDrag: (r) => l.startDrag(r),
178
- updateDragPosition: (r) => l.updateDragPosition(r),
179
- endDrag: (r) => l.endDrag(r),
180
- getDropZones: (r) => l.getDropZones(r),
181
- highlightDropZone: (r) => l.highlightDropZone(r)
182
- };
183
- }
@@ -1,3 +0,0 @@
1
- export * from './types';
2
- export * from './utils';
3
- export * from './dragDropManager';
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _types = require("./types");
7
- Object.keys(_types).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _types[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _types[key];
14
- }
15
- });
16
- });
17
- var _utils = require("./utils");
18
- Object.keys(_utils).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _utils[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _utils[key];
25
- }
26
- });
27
- });
28
- var _dragDropManager = require("./dragDropManager");
29
- Object.keys(_dragDropManager).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _dragDropManager[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _dragDropManager[key];
36
- }
37
- });
38
- });
@@ -1,3 +0,0 @@
1
- export * from "./types.mjs";
2
- export * from "./utils.mjs";
3
- export * from "./dragDropManager.mjs";
@@ -1,80 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- "use strict";
File without changes
@@ -1,41 +0,0 @@
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;
@@ -1,93 +0,0 @@
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
- }
@@ -1,68 +0,0 @@
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
- }