@measured/puck-plugin-heading-analyzer 0.18.3-canary.b44056f → 0.19.0-canary.0308d24

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/index.js CHANGED
@@ -61,6 +61,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
61
61
  mod
62
62
  ));
63
63
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
64
+ var __async = (__this, __arguments, generator) => {
65
+ return new Promise((resolve, reject) => {
66
+ var fulfilled = (value) => {
67
+ try {
68
+ step(generator.next(value));
69
+ } catch (e) {
70
+ reject(e);
71
+ }
72
+ };
73
+ var rejected = (value) => {
74
+ try {
75
+ step(generator.throw(value));
76
+ } catch (e) {
77
+ reject(e);
78
+ }
79
+ };
80
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
81
+ step((generator = generator.apply(__this, __arguments)).next());
82
+ });
83
+ };
64
84
 
65
85
  // ../tsup-config/react-import.js
66
86
  var import_react;
@@ -133,6 +153,325 @@ var require_classnames = __commonJS({
133
153
  }
134
154
  });
135
155
 
156
+ // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js
157
+ var require_use_sync_external_store_shim_production = __commonJS({
158
+ "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js"(exports2) {
159
+ "use strict";
160
+ init_react_import();
161
+ var React2 = require("react");
162
+ function is(x, y) {
163
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
164
+ }
165
+ var objectIs = "function" === typeof Object.is ? Object.is : is;
166
+ var useState2 = React2.useState;
167
+ var useEffect7 = React2.useEffect;
168
+ var useLayoutEffect = React2.useLayoutEffect;
169
+ var useDebugValue2 = React2.useDebugValue;
170
+ function useSyncExternalStore$2(subscribe, getSnapshot) {
171
+ var value = getSnapshot(), _useState = useState2({ inst: { value, getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1];
172
+ useLayoutEffect(
173
+ function() {
174
+ inst.value = value;
175
+ inst.getSnapshot = getSnapshot;
176
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
177
+ },
178
+ [subscribe, value, getSnapshot]
179
+ );
180
+ useEffect7(
181
+ function() {
182
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
183
+ return subscribe(function() {
184
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
185
+ });
186
+ },
187
+ [subscribe]
188
+ );
189
+ useDebugValue2(value);
190
+ return value;
191
+ }
192
+ function checkIfSnapshotChanged(inst) {
193
+ var latestGetSnapshot = inst.getSnapshot;
194
+ inst = inst.value;
195
+ try {
196
+ var nextValue = latestGetSnapshot();
197
+ return !objectIs(inst, nextValue);
198
+ } catch (error) {
199
+ return true;
200
+ }
201
+ }
202
+ function useSyncExternalStore$1(subscribe, getSnapshot) {
203
+ return getSnapshot();
204
+ }
205
+ var shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
206
+ exports2.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim;
207
+ }
208
+ });
209
+
210
+ // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
211
+ var require_use_sync_external_store_shim_development = __commonJS({
212
+ "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports2) {
213
+ "use strict";
214
+ init_react_import();
215
+ "production" !== process.env.NODE_ENV && function() {
216
+ function is(x, y) {
217
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
218
+ }
219
+ function useSyncExternalStore$2(subscribe, getSnapshot) {
220
+ didWarnOld18Alpha || void 0 === React2.startTransition || (didWarnOld18Alpha = true, console.error(
221
+ "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
222
+ ));
223
+ var value = getSnapshot();
224
+ if (!didWarnUncachedGetSnapshot) {
225
+ var cachedValue = getSnapshot();
226
+ objectIs(value, cachedValue) || (console.error(
227
+ "The result of getSnapshot should be cached to avoid an infinite loop"
228
+ ), didWarnUncachedGetSnapshot = true);
229
+ }
230
+ cachedValue = useState2({
231
+ inst: { value, getSnapshot }
232
+ });
233
+ var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
234
+ useLayoutEffect(
235
+ function() {
236
+ inst.value = value;
237
+ inst.getSnapshot = getSnapshot;
238
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
239
+ },
240
+ [subscribe, value, getSnapshot]
241
+ );
242
+ useEffect7(
243
+ function() {
244
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
245
+ return subscribe(function() {
246
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
247
+ });
248
+ },
249
+ [subscribe]
250
+ );
251
+ useDebugValue2(value);
252
+ return value;
253
+ }
254
+ function checkIfSnapshotChanged(inst) {
255
+ var latestGetSnapshot = inst.getSnapshot;
256
+ inst = inst.value;
257
+ try {
258
+ var nextValue = latestGetSnapshot();
259
+ return !objectIs(inst, nextValue);
260
+ } catch (error) {
261
+ return true;
262
+ }
263
+ }
264
+ function useSyncExternalStore$1(subscribe, getSnapshot) {
265
+ return getSnapshot();
266
+ }
267
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
268
+ var React2 = require("react"), objectIs = "function" === typeof Object.is ? Object.is : is, useState2 = React2.useState, useEffect7 = React2.useEffect, useLayoutEffect = React2.useLayoutEffect, useDebugValue2 = React2.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
269
+ exports2.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim;
270
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
271
+ }();
272
+ }
273
+ });
274
+
275
+ // ../../node_modules/use-sync-external-store/shim/index.js
276
+ var require_shim = __commonJS({
277
+ "../../node_modules/use-sync-external-store/shim/index.js"(exports2, module2) {
278
+ "use strict";
279
+ init_react_import();
280
+ if (process.env.NODE_ENV === "production") {
281
+ module2.exports = require_use_sync_external_store_shim_production();
282
+ } else {
283
+ module2.exports = require_use_sync_external_store_shim_development();
284
+ }
285
+ }
286
+ });
287
+
288
+ // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js
289
+ var require_with_selector_production = __commonJS({
290
+ "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js"(exports2) {
291
+ "use strict";
292
+ init_react_import();
293
+ var React2 = require("react");
294
+ var shim = require_shim();
295
+ function is(x, y) {
296
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
297
+ }
298
+ var objectIs = "function" === typeof Object.is ? Object.is : is;
299
+ var useSyncExternalStore = shim.useSyncExternalStore;
300
+ var useRef = React2.useRef;
301
+ var useEffect7 = React2.useEffect;
302
+ var useMemo2 = React2.useMemo;
303
+ var useDebugValue2 = React2.useDebugValue;
304
+ exports2.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
305
+ var instRef = useRef(null);
306
+ if (null === instRef.current) {
307
+ var inst = { hasValue: false, value: null };
308
+ instRef.current = inst;
309
+ } else inst = instRef.current;
310
+ instRef = useMemo2(
311
+ function() {
312
+ function memoizedSelector(nextSnapshot) {
313
+ if (!hasMemo) {
314
+ hasMemo = true;
315
+ memoizedSnapshot = nextSnapshot;
316
+ nextSnapshot = selector(nextSnapshot);
317
+ if (void 0 !== isEqual && inst.hasValue) {
318
+ var currentSelection = inst.value;
319
+ if (isEqual(currentSelection, nextSnapshot))
320
+ return memoizedSelection = currentSelection;
321
+ }
322
+ return memoizedSelection = nextSnapshot;
323
+ }
324
+ currentSelection = memoizedSelection;
325
+ if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
326
+ var nextSelection = selector(nextSnapshot);
327
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
328
+ return memoizedSnapshot = nextSnapshot, currentSelection;
329
+ memoizedSnapshot = nextSnapshot;
330
+ return memoizedSelection = nextSelection;
331
+ }
332
+ var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
333
+ return [
334
+ function() {
335
+ return memoizedSelector(getSnapshot());
336
+ },
337
+ null === maybeGetServerSnapshot ? void 0 : function() {
338
+ return memoizedSelector(maybeGetServerSnapshot());
339
+ }
340
+ ];
341
+ },
342
+ [getSnapshot, getServerSnapshot, selector, isEqual]
343
+ );
344
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
345
+ useEffect7(
346
+ function() {
347
+ inst.hasValue = true;
348
+ inst.value = value;
349
+ },
350
+ [value]
351
+ );
352
+ useDebugValue2(value);
353
+ return value;
354
+ };
355
+ }
356
+ });
357
+
358
+ // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js
359
+ var require_with_selector_development = __commonJS({
360
+ "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js"(exports2) {
361
+ "use strict";
362
+ init_react_import();
363
+ "production" !== process.env.NODE_ENV && function() {
364
+ function is(x, y) {
365
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
366
+ }
367
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
368
+ var React2 = require("react"), shim = require_shim(), objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim.useSyncExternalStore, useRef = React2.useRef, useEffect7 = React2.useEffect, useMemo2 = React2.useMemo, useDebugValue2 = React2.useDebugValue;
369
+ exports2.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
370
+ var instRef = useRef(null);
371
+ if (null === instRef.current) {
372
+ var inst = { hasValue: false, value: null };
373
+ instRef.current = inst;
374
+ } else inst = instRef.current;
375
+ instRef = useMemo2(
376
+ function() {
377
+ function memoizedSelector(nextSnapshot) {
378
+ if (!hasMemo) {
379
+ hasMemo = true;
380
+ memoizedSnapshot = nextSnapshot;
381
+ nextSnapshot = selector(nextSnapshot);
382
+ if (void 0 !== isEqual && inst.hasValue) {
383
+ var currentSelection = inst.value;
384
+ if (isEqual(currentSelection, nextSnapshot))
385
+ return memoizedSelection = currentSelection;
386
+ }
387
+ return memoizedSelection = nextSnapshot;
388
+ }
389
+ currentSelection = memoizedSelection;
390
+ if (objectIs(memoizedSnapshot, nextSnapshot))
391
+ return currentSelection;
392
+ var nextSelection = selector(nextSnapshot);
393
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
394
+ return memoizedSnapshot = nextSnapshot, currentSelection;
395
+ memoizedSnapshot = nextSnapshot;
396
+ return memoizedSelection = nextSelection;
397
+ }
398
+ var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
399
+ return [
400
+ function() {
401
+ return memoizedSelector(getSnapshot());
402
+ },
403
+ null === maybeGetServerSnapshot ? void 0 : function() {
404
+ return memoizedSelector(maybeGetServerSnapshot());
405
+ }
406
+ ];
407
+ },
408
+ [getSnapshot, getServerSnapshot, selector, isEqual]
409
+ );
410
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
411
+ useEffect7(
412
+ function() {
413
+ inst.hasValue = true;
414
+ inst.value = value;
415
+ },
416
+ [value]
417
+ );
418
+ useDebugValue2(value);
419
+ return value;
420
+ };
421
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
422
+ }();
423
+ }
424
+ });
425
+
426
+ // ../../node_modules/use-sync-external-store/shim/with-selector.js
427
+ var require_with_selector = __commonJS({
428
+ "../../node_modules/use-sync-external-store/shim/with-selector.js"(exports2, module2) {
429
+ "use strict";
430
+ init_react_import();
431
+ if (process.env.NODE_ENV === "production") {
432
+ module2.exports = require_with_selector_production();
433
+ } else {
434
+ module2.exports = require_with_selector_development();
435
+ }
436
+ }
437
+ });
438
+
439
+ // ../../node_modules/fast-deep-equal/index.js
440
+ var require_fast_deep_equal = __commonJS({
441
+ "../../node_modules/fast-deep-equal/index.js"(exports2, module2) {
442
+ "use strict";
443
+ init_react_import();
444
+ module2.exports = function equal(a, b) {
445
+ if (a === b) return true;
446
+ if (a && b && typeof a == "object" && typeof b == "object") {
447
+ if (a.constructor !== b.constructor) return false;
448
+ var length, i, keys;
449
+ if (Array.isArray(a)) {
450
+ length = a.length;
451
+ if (length != b.length) return false;
452
+ for (i = length; i-- !== 0; )
453
+ if (!equal(a[i], b[i])) return false;
454
+ return true;
455
+ }
456
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
457
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
458
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
459
+ keys = Object.keys(a);
460
+ length = keys.length;
461
+ if (length !== Object.keys(b).length) return false;
462
+ for (i = length; i-- !== 0; )
463
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
464
+ for (i = length; i-- !== 0; ) {
465
+ var key = keys[i];
466
+ if (!equal(a[key], b[key])) return false;
467
+ }
468
+ return true;
469
+ }
470
+ return a !== a && b !== b;
471
+ };
472
+ }
473
+ });
474
+
136
475
  // index.ts
137
476
  var plugin_heading_analyzer_exports = {};
138
477
  __export(plugin_heading_analyzer_exports, {
@@ -143,7 +482,7 @@ init_react_import();
143
482
 
144
483
  // src/HeadingAnalyzer.tsx
145
484
  init_react_import();
146
- var import_react9 = require("react");
485
+ var import_react12 = require("react");
147
486
 
148
487
  // css-module:/home/runner/work/puck/puck/packages/plugin-heading-analyzer/src/HeadingAnalyzer.module.css#css-module
149
488
  init_react_import();
@@ -304,132 +643,523 @@ var ChevronRight = createLucideIcon("ChevronRight", [
304
643
 
305
644
  // ../core/lib/use-breadcrumbs.ts
306
645
  init_react_import();
307
- var import_react8 = require("react");
646
+ var import_react11 = require("react");
308
647
 
309
- // ../core/components/DropZone/context.tsx
648
+ // ../core/store/index.ts
310
649
  init_react_import();
311
- var import_react7 = require("react");
312
650
 
313
- // ../core/components/Puck/context.tsx
651
+ // ../core/reducer/index.ts
314
652
  init_react_import();
315
- var import_react6 = require("react");
316
653
 
317
- // ../core/lib/get-item.ts
654
+ // ../core/reducer/data.ts
318
655
  init_react_import();
319
656
 
657
+ // ../core/lib/reorder.ts
658
+ init_react_import();
659
+ var reorder = (list, startIndex, endIndex) => {
660
+ const result = Array.from(list);
661
+ const [removed] = result.splice(startIndex, 1);
662
+ result.splice(endIndex, 0, removed);
663
+ return result;
664
+ };
665
+
320
666
  // ../core/lib/root-droppable-id.ts
321
667
  init_react_import();
322
- var rootDroppableId = "default-zone";
668
+ var rootAreaId = "root";
669
+ var rootZone = "default-zone";
670
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
671
+
672
+ // ../core/lib/insert.ts
673
+ init_react_import();
674
+ var insert = (list, index, item) => {
675
+ const result = Array.from(list);
676
+ result.splice(index, 0, item);
677
+ return result;
678
+ };
679
+
680
+ // ../core/lib/remove.ts
681
+ init_react_import();
682
+ var remove = (list, index) => {
683
+ const result = Array.from(list);
684
+ result.splice(index, 1);
685
+ return result;
686
+ };
323
687
 
324
688
  // ../core/lib/setup-zone.ts
325
689
  init_react_import();
690
+ var setupZone = (data, zoneKey) => {
691
+ if (zoneKey === rootDroppableId) {
692
+ return data;
693
+ }
694
+ const newData = __spreadProps(__spreadValues({}, data), {
695
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
696
+ });
697
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
698
+ return newData;
699
+ };
326
700
 
327
- // ../core/components/ViewportControls/default-viewports.ts
701
+ // ../core/lib/replace.ts
328
702
  init_react_import();
329
- var defaultViewports = [
330
- { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
331
- { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
332
- { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
333
- ];
703
+ var replace = (list, index, newItem) => {
704
+ const result = Array.from(list);
705
+ result.splice(index, 1);
706
+ result.splice(index, 0, newItem);
707
+ return result;
708
+ };
334
709
 
335
- // ../core/lib/use-resolved-permissions.ts
710
+ // ../core/lib/get-item.ts
336
711
  init_react_import();
337
- var import_react4 = require("react");
712
+ function getItem(selector, data, dynamicProps = {}) {
713
+ if (!selector.zone || selector.zone === rootDroppableId) {
714
+ const item2 = data.content[selector.index];
715
+ return (item2 == null ? void 0 : item2.props) ? __spreadProps(__spreadValues({}, item2), { props: dynamicProps[item2.props.id] || item2.props }) : void 0;
716
+ }
717
+ const item = setupZone(data, selector.zone).zones[selector.zone][selector.index];
718
+ return (item == null ? void 0 : item.props) ? __spreadProps(__spreadValues({}, item), { props: dynamicProps[item.props.id] || item.props }) : void 0;
719
+ }
338
720
 
339
- // ../core/lib/flatten-data.ts
721
+ // ../core/lib/reduce-related-zones.ts
340
722
  init_react_import();
341
723
 
342
- // ../core/lib/get-changed.ts
724
+ // ../core/lib/generate-id.ts
343
725
  init_react_import();
344
726
 
345
- // ../core/lib/use-resolved-data.ts
727
+ // ../../node_modules/uuid/dist/esm-node/index.js
346
728
  init_react_import();
347
- var import_react5 = require("react");
348
729
 
349
- // ../core/lib/resolve-component-data.ts
730
+ // ../../node_modules/uuid/dist/esm-node/rng.js
350
731
  init_react_import();
732
+ var import_crypto = __toESM(require("crypto"));
733
+ var rnds8Pool = new Uint8Array(256);
734
+ var poolPtr = rnds8Pool.length;
735
+ function rng() {
736
+ if (poolPtr > rnds8Pool.length - 16) {
737
+ import_crypto.default.randomFillSync(rnds8Pool);
738
+ poolPtr = 0;
739
+ }
740
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
741
+ }
351
742
 
352
- // ../core/lib/apply-dynamic-props.ts
743
+ // ../../node_modules/uuid/dist/esm-node/stringify.js
353
744
  init_react_import();
745
+ var byteToHex = [];
746
+ for (let i = 0; i < 256; ++i) {
747
+ byteToHex.push((i + 256).toString(16).slice(1));
748
+ }
749
+ function unsafeStringify(arr, offset = 0) {
750
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
751
+ }
354
752
 
355
- // ../core/lib/resolve-root-data.ts
753
+ // ../../node_modules/uuid/dist/esm-node/v4.js
356
754
  init_react_import();
357
755
 
358
- // ../core/components/Puck/context.tsx
359
- var import_jsx_runtime2 = require("react/jsx-runtime");
360
- var defaultAppState = {
361
- data: { content: [], root: {} },
362
- ui: {
363
- leftSideBarVisible: true,
364
- rightSideBarVisible: true,
365
- arrayState: {},
366
- itemSelector: null,
367
- componentList: {},
368
- isDragging: false,
369
- previewMode: "edit",
370
- viewports: {
371
- current: {
372
- width: defaultViewports[0].width,
373
- height: defaultViewports[0].height || "auto"
756
+ // ../../node_modules/uuid/dist/esm-node/native.js
757
+ init_react_import();
758
+ var import_crypto2 = __toESM(require("crypto"));
759
+ var native_default = {
760
+ randomUUID: import_crypto2.default.randomUUID
761
+ };
762
+
763
+ // ../../node_modules/uuid/dist/esm-node/v4.js
764
+ function v4(options, buf, offset) {
765
+ if (native_default.randomUUID && !buf && !options) {
766
+ return native_default.randomUUID();
767
+ }
768
+ options = options || {};
769
+ const rnds = options.random || (options.rng || rng)();
770
+ rnds[6] = rnds[6] & 15 | 64;
771
+ rnds[8] = rnds[8] & 63 | 128;
772
+ if (buf) {
773
+ offset = offset || 0;
774
+ for (let i = 0; i < 16; ++i) {
775
+ buf[offset + i] = rnds[i];
776
+ }
777
+ return buf;
778
+ }
779
+ return unsafeStringify(rnds);
780
+ }
781
+ var v4_default = v4;
782
+
783
+ // ../core/lib/generate-id.ts
784
+ var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
785
+
786
+ // ../core/lib/get-zone-id.ts
787
+ init_react_import();
788
+ var getZoneId = (zoneCompound) => {
789
+ if (!zoneCompound) {
790
+ return [];
791
+ }
792
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
793
+ return zoneCompound.split(":");
794
+ }
795
+ return [rootDroppableId, zoneCompound];
796
+ };
797
+
798
+ // ../core/lib/reduce-related-zones.ts
799
+ function reduceRelatedZones(item, data, fn) {
800
+ return __spreadProps(__spreadValues({}, data), {
801
+ zones: Object.keys(data.zones || {}).reduce(
802
+ (acc, key) => {
803
+ const [parentId] = getZoneId(key);
804
+ if (parentId === item.props.id) {
805
+ const zones = data.zones;
806
+ return fn(acc, key, zones[key]);
807
+ }
808
+ return __spreadProps(__spreadValues({}, acc), { [key]: data.zones[key] });
374
809
  },
375
- options: [],
376
- controlsVisible: true
810
+ {}
811
+ )
812
+ });
813
+ }
814
+ var findRelatedByZoneId = (zoneId, data) => {
815
+ const [zoneParentId] = getZoneId(zoneId);
816
+ return (data.zones[zoneId] || []).reduce(
817
+ (acc, zoneItem) => {
818
+ const related = findRelatedByItem(zoneItem, data);
819
+ if (zoneItem.props.id === zoneParentId) {
820
+ return __spreadProps(__spreadValues(__spreadValues({}, acc), related), { [zoneId]: zoneItem });
821
+ }
822
+ return __spreadValues(__spreadValues({}, acc), related);
377
823
  },
378
- field: { focus: null }
824
+ {}
825
+ );
826
+ };
827
+ var findRelatedByItem = (item, data) => {
828
+ return Object.keys(data.zones || {}).reduce(
829
+ (acc, zoneId) => {
830
+ const [zoneParentId] = getZoneId(zoneId);
831
+ if (item.props.id === zoneParentId) {
832
+ const related = findRelatedByZoneId(zoneId, data);
833
+ return __spreadProps(__spreadValues(__spreadValues({}, acc), related), {
834
+ [zoneId]: data.zones[zoneId]
835
+ });
836
+ }
837
+ return acc;
838
+ },
839
+ {}
840
+ );
841
+ };
842
+ var removeRelatedZones = (item, data) => {
843
+ const newData = __spreadValues({}, data);
844
+ const related = findRelatedByItem(item, data);
845
+ Object.keys(related).forEach((key) => {
846
+ delete newData.zones[key];
847
+ });
848
+ return newData;
849
+ };
850
+ function duplicateRelatedZones(item, data, newId) {
851
+ return reduceRelatedZones(item, data, (acc, key, zone) => {
852
+ const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
853
+ props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
854
+ }));
855
+ const dupeOfDupes = dupedZone.reduce(
856
+ (dupeOfDupes2, item2, index) => __spreadValues(__spreadValues({}, dupeOfDupes2), duplicateRelatedZones(zone[index], data, item2.props.id).zones),
857
+ acc
858
+ );
859
+ const [_, zoneId] = getZoneId(key);
860
+ return __spreadProps(__spreadValues({}, dupeOfDupes), {
861
+ [key]: zone,
862
+ [`${newId}:${zoneId}`]: dupedZone
863
+ });
864
+ });
865
+ }
866
+
867
+ // ../core/reducer/data.ts
868
+ var zoneCache = {};
869
+ var replaceAction = (data, action) => {
870
+ if (action.destinationZone === rootDroppableId) {
871
+ return __spreadProps(__spreadValues({}, data), {
872
+ content: replace(data.content, action.destinationIndex, action.data)
873
+ });
379
874
  }
875
+ const newData = setupZone(data, action.destinationZone);
876
+ return __spreadProps(__spreadValues({}, newData), {
877
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
878
+ [action.destinationZone]: replace(
879
+ newData.zones[action.destinationZone],
880
+ action.destinationIndex,
881
+ action.data
882
+ )
883
+ })
884
+ });
380
885
  };
381
- var defaultContext = {
382
- state: defaultAppState,
383
- dispatch: () => null,
384
- config: { components: {} },
385
- componentState: {},
386
- setComponentState: () => {
387
- },
388
- resolveData: () => {
389
- },
390
- plugins: [],
391
- overrides: {},
392
- history: {},
393
- viewports: defaultViewports,
394
- zoomConfig: {
395
- autoZoom: 1,
396
- rootHeight: 0,
397
- zoom: 1
398
- },
399
- setZoomConfig: () => null,
400
- status: "LOADING",
401
- setStatus: () => null,
402
- iframe: {},
403
- globalPermissions: {},
404
- getPermissions: () => ({}),
405
- refreshPermissions: () => null
406
- };
407
- var appContext = (0, import_react6.createContext)(defaultContext);
408
- function useAppContext() {
409
- const mainContext = (0, import_react6.useContext)(appContext);
410
- return __spreadProps(__spreadValues({}, mainContext), {
411
- // Helpers
412
- setUi: (ui, recordHistory) => {
413
- return mainContext.dispatch({
414
- type: "setUi",
415
- ui,
416
- recordHistory
886
+ function insertAction(data, action, config) {
887
+ const emptyComponentData = {
888
+ type: action.componentType,
889
+ props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
890
+ id: action.id || generateId(action.componentType)
891
+ })
892
+ };
893
+ if (action.destinationZone === rootDroppableId) {
894
+ return __spreadProps(__spreadValues({}, data), {
895
+ content: insert(
896
+ data.content,
897
+ action.destinationIndex,
898
+ emptyComponentData
899
+ )
900
+ });
901
+ }
902
+ const newData = setupZone(data, action.destinationZone);
903
+ return __spreadProps(__spreadValues({}, data), {
904
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
905
+ [action.destinationZone]: insert(
906
+ newData.zones[action.destinationZone],
907
+ action.destinationIndex,
908
+ emptyComponentData
909
+ )
910
+ })
911
+ });
912
+ }
913
+ var reorderAction = (data, action) => {
914
+ if (action.destinationZone === rootDroppableId) {
915
+ return __spreadProps(__spreadValues({}, data), {
916
+ content: reorder(
917
+ data.content,
918
+ action.sourceIndex,
919
+ action.destinationIndex
920
+ )
921
+ });
922
+ }
923
+ const newData = setupZone(data, action.destinationZone);
924
+ return __spreadProps(__spreadValues({}, data), {
925
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
926
+ [action.destinationZone]: reorder(
927
+ newData.zones[action.destinationZone],
928
+ action.sourceIndex,
929
+ action.destinationIndex
930
+ )
931
+ })
932
+ });
933
+ };
934
+ function reduceData(data, action, config) {
935
+ if (action.type === "insert") {
936
+ return insertAction(data, action, config);
937
+ }
938
+ if (action.type === "duplicate") {
939
+ const item = getItem(
940
+ { index: action.sourceIndex, zone: action.sourceZone },
941
+ data
942
+ );
943
+ const newItem = __spreadProps(__spreadValues({}, item), {
944
+ props: __spreadProps(__spreadValues({}, item.props), {
945
+ id: generateId(item.type)
946
+ })
947
+ });
948
+ const dataWithRelatedDuplicated = duplicateRelatedZones(
949
+ item,
950
+ data,
951
+ newItem.props.id
952
+ );
953
+ if (action.sourceZone === rootDroppableId) {
954
+ return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
955
+ content: insert(data.content, action.sourceIndex + 1, newItem)
417
956
  });
418
957
  }
419
- });
958
+ return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
959
+ zones: __spreadProps(__spreadValues({}, dataWithRelatedDuplicated.zones), {
960
+ [action.sourceZone]: insert(
961
+ dataWithRelatedDuplicated.zones[action.sourceZone],
962
+ action.sourceIndex + 1,
963
+ newItem
964
+ )
965
+ })
966
+ });
967
+ }
968
+ if (action.type === "reorder") {
969
+ return reorderAction(data, action);
970
+ }
971
+ if (action.type === "move") {
972
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
973
+ return data;
974
+ }
975
+ const newData = setupZone(
976
+ setupZone(data, action.sourceZone),
977
+ action.destinationZone
978
+ );
979
+ const item = getItem(
980
+ { zone: action.sourceZone, index: action.sourceIndex },
981
+ newData
982
+ );
983
+ if (action.sourceZone === action.destinationZone) {
984
+ return reorderAction(data, __spreadProps(__spreadValues({}, action), { type: "reorder" }));
985
+ }
986
+ if (action.sourceZone === rootDroppableId) {
987
+ return __spreadProps(__spreadValues({}, newData), {
988
+ content: remove(newData.content, action.sourceIndex),
989
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
990
+ [action.destinationZone]: insert(
991
+ newData.zones[action.destinationZone],
992
+ action.destinationIndex,
993
+ item
994
+ )
995
+ })
996
+ });
997
+ }
998
+ if (action.destinationZone === rootDroppableId) {
999
+ return __spreadProps(__spreadValues({}, newData), {
1000
+ content: insert(newData.content, action.destinationIndex, item),
1001
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
1002
+ [action.sourceZone]: remove(
1003
+ newData.zones[action.sourceZone],
1004
+ action.sourceIndex
1005
+ )
1006
+ })
1007
+ });
1008
+ }
1009
+ return __spreadProps(__spreadValues({}, newData), {
1010
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
1011
+ [action.sourceZone]: remove(
1012
+ newData.zones[action.sourceZone],
1013
+ action.sourceIndex
1014
+ ),
1015
+ [action.destinationZone]: insert(
1016
+ newData.zones[action.destinationZone],
1017
+ action.destinationIndex,
1018
+ item
1019
+ )
1020
+ })
1021
+ });
1022
+ }
1023
+ if (action.type === "replace") {
1024
+ return replaceAction(data, action);
1025
+ }
1026
+ if (action.type === "remove") {
1027
+ const item = getItem({ index: action.index, zone: action.zone }, data);
1028
+ const dataWithRelatedRemoved = setupZone(
1029
+ removeRelatedZones(item, data),
1030
+ action.zone
1031
+ );
1032
+ if (action.zone === rootDroppableId) {
1033
+ return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
1034
+ content: remove(data.content, action.index)
1035
+ });
1036
+ }
1037
+ return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
1038
+ zones: __spreadProps(__spreadValues({}, dataWithRelatedRemoved.zones), {
1039
+ [action.zone]: remove(
1040
+ dataWithRelatedRemoved.zones[action.zone],
1041
+ action.index
1042
+ )
1043
+ })
1044
+ });
1045
+ }
1046
+ if (action.type === "registerZone") {
1047
+ if (zoneCache[action.zone]) {
1048
+ return __spreadProps(__spreadValues({}, data), {
1049
+ zones: __spreadProps(__spreadValues({}, data.zones), {
1050
+ [action.zone]: zoneCache[action.zone]
1051
+ })
1052
+ });
1053
+ }
1054
+ return setupZone(data, action.zone);
1055
+ }
1056
+ if (action.type === "unregisterZone") {
1057
+ const _zones = __spreadValues({}, data.zones || {});
1058
+ if (_zones[action.zone]) {
1059
+ zoneCache[action.zone] = _zones[action.zone];
1060
+ delete _zones[action.zone];
1061
+ }
1062
+ return __spreadProps(__spreadValues({}, data), { zones: _zones });
1063
+ }
1064
+ if (action.type === "setData") {
1065
+ if (typeof action.data === "object") {
1066
+ return __spreadValues(__spreadValues({}, data), action.data);
1067
+ }
1068
+ return __spreadValues(__spreadValues({}, data), action.data(data));
1069
+ }
1070
+ return data;
420
1071
  }
421
1072
 
1073
+ // ../core/reducer/state.ts
1074
+ init_react_import();
1075
+ var reduceUi = (ui, action) => {
1076
+ if (action.type === "setUi") {
1077
+ if (typeof action.ui === "object") {
1078
+ return __spreadValues(__spreadValues({}, ui), action.ui);
1079
+ }
1080
+ return __spreadValues(__spreadValues({}, ui), action.ui(ui));
1081
+ }
1082
+ if (action.type === "duplicate") {
1083
+ return __spreadProps(__spreadValues({}, ui), {
1084
+ itemSelector: { index: action.sourceIndex + 1, zone: action.sourceZone }
1085
+ });
1086
+ }
1087
+ if (action.type === "remove") {
1088
+ return __spreadProps(__spreadValues({}, ui), {
1089
+ itemSelector: null
1090
+ });
1091
+ }
1092
+ return ui;
1093
+ };
1094
+
1095
+ // ../core/reducer/actions.tsx
1096
+ init_react_import();
1097
+
1098
+ // ../core/reducer/index.ts
1099
+ function storeInterceptor(reducer, record, onAction) {
1100
+ return (state, action) => {
1101
+ const newAppState = reducer(state, action);
1102
+ const isValidType = ![
1103
+ "registerZone",
1104
+ "unregisterZone",
1105
+ "setData",
1106
+ "setUi",
1107
+ "set"
1108
+ ].includes(action.type);
1109
+ if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1110
+ if (record) record(newAppState);
1111
+ }
1112
+ onAction == null ? void 0 : onAction(action, newAppState, state);
1113
+ return newAppState;
1114
+ };
1115
+ }
1116
+ var setAction = (state, action) => {
1117
+ if (typeof action.state === "object") {
1118
+ return __spreadValues(__spreadValues({}, state), action.state);
1119
+ }
1120
+ return __spreadValues(__spreadValues({}, state), action.state(state));
1121
+ };
1122
+ function createReducer({
1123
+ config,
1124
+ record,
1125
+ onAction
1126
+ }) {
1127
+ return storeInterceptor(
1128
+ (state, action) => {
1129
+ const data = reduceData(state.data, action, config);
1130
+ const ui = reduceUi(state.ui, action);
1131
+ if (action.type === "set") {
1132
+ return setAction(state, action);
1133
+ }
1134
+ return { data, ui };
1135
+ },
1136
+ record,
1137
+ onAction
1138
+ );
1139
+ }
1140
+
1141
+ // ../core/components/ViewportControls/default-viewports.ts
1142
+ init_react_import();
1143
+ var defaultViewports = [
1144
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1145
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1146
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1147
+ ];
1148
+
1149
+ // ../../node_modules/zustand/esm/index.mjs
1150
+ init_react_import();
1151
+
422
1152
  // ../../node_modules/zustand/esm/vanilla.mjs
423
1153
  init_react_import();
424
1154
  var import_meta = {};
425
1155
  var createStoreImpl = (createState) => {
426
1156
  let state;
427
1157
  const listeners = /* @__PURE__ */ new Set();
428
- const setState = (partial, replace) => {
1158
+ const setState = (partial, replace2) => {
429
1159
  const nextState = typeof partial === "function" ? partial(state) : partial;
430
1160
  if (!Object.is(nextState, state)) {
431
1161
  const previousState = state;
432
- state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
1162
+ state = (replace2 != null ? replace2 : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
433
1163
  listeners.forEach((listener) => listener(state, previousState));
434
1164
  }
435
1165
  };
@@ -453,94 +1183,718 @@ var createStoreImpl = (createState) => {
453
1183
  };
454
1184
  var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
455
1185
 
456
- // ../core/components/DropZone/context.tsx
457
- var import_jsx_runtime3 = require("react/jsx-runtime");
458
- var dropZoneContext = (0, import_react7.createContext)(null);
459
- var ZoneStoreContext = (0, import_react7.createContext)(
460
- createStore(() => ({
461
- zoneDepthIndex: {},
462
- nextZoneDepthIndex: {},
463
- areaDepthIndex: {},
464
- nextAreaDepthIndex: {},
465
- draggedItem: null,
466
- previewIndex: {}
467
- }))
468
- );
469
-
470
- // ../core/lib/get-zone-id.ts
471
- init_react_import();
472
- var getZoneId = (zoneCompound) => {
473
- if (!zoneCompound) {
474
- return [];
1186
+ // ../../node_modules/zustand/esm/index.mjs
1187
+ var import_react4 = __toESM(require("react"), 1);
1188
+ var import_with_selector = __toESM(require_with_selector(), 1);
1189
+ var import_meta2 = {};
1190
+ var { useDebugValue } = import_react4.default;
1191
+ var { useSyncExternalStoreWithSelector } = import_with_selector.default;
1192
+ var didWarnAboutEqualityFn = false;
1193
+ var identity = (arg) => arg;
1194
+ function useStore(api, selector = identity, equalityFn) {
1195
+ if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && equalityFn && !didWarnAboutEqualityFn) {
1196
+ console.warn(
1197
+ "[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"
1198
+ );
1199
+ didWarnAboutEqualityFn = true;
475
1200
  }
476
- if (zoneCompound && zoneCompound.indexOf(":") > -1) {
477
- return zoneCompound.split(":");
1201
+ const slice = useSyncExternalStoreWithSelector(
1202
+ api.subscribe,
1203
+ api.getState,
1204
+ api.getServerState || api.getInitialState,
1205
+ selector,
1206
+ equalityFn
1207
+ );
1208
+ useDebugValue(slice);
1209
+ return slice;
1210
+ }
1211
+ var createImpl = (createState) => {
1212
+ if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && typeof createState !== "function") {
1213
+ console.warn(
1214
+ "[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`."
1215
+ );
478
1216
  }
479
- return [rootDroppableId, zoneCompound];
1217
+ const api = typeof createState === "function" ? createStore(createState) : createState;
1218
+ const useBoundStore = (selector, equalityFn) => useStore(api, selector, equalityFn);
1219
+ Object.assign(useBoundStore, api);
1220
+ return useBoundStore;
480
1221
  };
1222
+ var create = (createState) => createState ? createImpl(createState) : createImpl;
481
1223
 
482
- // ../core/lib/use-breadcrumbs.ts
483
- var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
484
- const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
485
- const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
486
- if (!id) {
487
- return [];
488
- }
489
- return currentPathData == null ? void 0 : currentPathData.path.reduce((acc, zoneCompound) => {
490
- const [area] = getZoneId(zoneCompound);
491
- if (area === rootDroppableId) {
492
- return [
493
- {
494
- label: "Page",
495
- selector: null
1224
+ // ../../node_modules/zustand/esm/middleware.mjs
1225
+ init_react_import();
1226
+ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1227
+ const origSubscribe = api.subscribe;
1228
+ api.subscribe = (selector, optListener, options) => {
1229
+ let listener = selector;
1230
+ if (optListener) {
1231
+ const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
1232
+ let currentSlice = selector(api.getState());
1233
+ listener = (state) => {
1234
+ const nextSlice = selector(state);
1235
+ if (!equalityFn(currentSlice, nextSlice)) {
1236
+ const previousSlice = currentSlice;
1237
+ optListener(currentSlice = nextSlice, previousSlice);
496
1238
  }
497
- ];
1239
+ };
1240
+ if (options == null ? void 0 : options.fireImmediately) {
1241
+ optListener(currentSlice, currentSlice);
1242
+ }
1243
+ }
1244
+ return origSubscribe(listener);
1245
+ };
1246
+ const initialState = fn(set, get, api);
1247
+ return initialState;
1248
+ };
1249
+ var subscribeWithSelector = subscribeWithSelectorImpl;
1250
+
1251
+ // ../core/lib/resolve-data.ts
1252
+ init_react_import();
1253
+
1254
+ // ../core/lib/resolve-component-data.ts
1255
+ init_react_import();
1256
+
1257
+ // ../core/lib/get-changed.ts
1258
+ init_react_import();
1259
+ var getChanged = (newItem, oldItem) => {
1260
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1261
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1262
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1263
+ return __spreadProps(__spreadValues({}, acc), {
1264
+ [item]: oldItemProps[item] !== newItemProps[item]
1265
+ });
1266
+ }, {}) : {};
1267
+ };
1268
+
1269
+ // ../core/lib/resolve-component-data.ts
1270
+ var cache = { lastChange: {} };
1271
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd) {
1272
+ const configForItem = config.components[item.type];
1273
+ if (configForItem.resolveData) {
1274
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
1275
+ if (item && item === oldItem) {
1276
+ return resolved;
498
1277
  }
499
- const parentZoneCompound = acc.length > 0 ? acc[acc.length - 1].zoneCompound : rootDroppableId;
500
- let parentZone = data.content;
501
- if (parentZoneCompound && parentZoneCompound !== rootDroppableId) {
502
- parentZone = data.zones[parentZoneCompound];
1278
+ const changed = getChanged(item, oldItem);
1279
+ if (onResolveStart) {
1280
+ onResolveStart(item);
503
1281
  }
504
- if (!parentZone) {
505
- return acc;
1282
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1283
+ changed,
1284
+ lastData: oldItem,
1285
+ metadata
1286
+ });
1287
+ const resolvedItem = __spreadProps(__spreadValues({}, item), {
1288
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1289
+ });
1290
+ if (Object.keys(readOnly).length) {
1291
+ resolvedItem.readOnly = readOnly;
1292
+ }
1293
+ cache.lastChange[item.props.id] = {
1294
+ item,
1295
+ resolved: resolvedItem
1296
+ };
1297
+ if (onResolveEnd) {
1298
+ onResolveEnd(resolvedItem);
1299
+ }
1300
+ return resolvedItem;
1301
+ }
1302
+ return item;
1303
+ });
1304
+
1305
+ // ../core/lib/apply-dynamic-props.ts
1306
+ init_react_import();
1307
+ var applyDynamicProps = (data, dynamicProps, rootData) => {
1308
+ return __spreadProps(__spreadValues({}, data), {
1309
+ root: rootData ? __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}) : data.root,
1310
+ content: data.content.map((item) => {
1311
+ return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1312
+ }),
1313
+ zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
1314
+ return __spreadProps(__spreadValues({}, acc), {
1315
+ [zoneKey]: data.zones[zoneKey].map((item) => {
1316
+ return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1317
+ })
1318
+ });
1319
+ }, {})
1320
+ });
1321
+ };
1322
+
1323
+ // ../core/lib/resolve-root-data.ts
1324
+ init_react_import();
1325
+ var cache2 = {};
1326
+ function resolveRootData(data, config, metadata) {
1327
+ return __async(this, null, function* () {
1328
+ var _a, _b, _c, _d, _e;
1329
+ if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
1330
+ if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
1331
+ return cache2.lastChange.resolved;
1332
+ }
1333
+ const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
1334
+ const rootWithProps = data.root;
1335
+ const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
1336
+ changed,
1337
+ lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {},
1338
+ metadata: metadata || {}
1339
+ });
1340
+ cache2.lastChange = {
1341
+ original: data.root,
1342
+ resolved: resolvedRoot
1343
+ };
1344
+ return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
1345
+ props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
1346
+ });
1347
+ }
1348
+ return data.root;
1349
+ });
1350
+ }
1351
+
1352
+ // ../core/lib/flatten-data.ts
1353
+ init_react_import();
1354
+ var flattenData = (data) => {
1355
+ return Object.keys(data.zones || {}).reduce(
1356
+ (acc, zone) => [...acc, ...data.zones[zone]],
1357
+ data.content
1358
+ );
1359
+ };
1360
+
1361
+ // ../core/lib/resolve-data.ts
1362
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1363
+ var resolveData = (newAppState, appStoreData) => {
1364
+ const {
1365
+ state: appState,
1366
+ config,
1367
+ dispatch,
1368
+ resolveDataRuns,
1369
+ setComponentLoading,
1370
+ unsetComponentLoading,
1371
+ metadata,
1372
+ permissions
1373
+ } = appStoreData;
1374
+ const deferredSetStates = {};
1375
+ const _setComponentLoading = (id, loading, defer = 0) => {
1376
+ if (deferredSetStates[id]) {
1377
+ clearTimeout(deferredSetStates[id]);
1378
+ delete deferredSetStates[id];
506
1379
  }
507
- const itemIndex = parentZone.findIndex(
508
- (queryItem) => queryItem.props.id === area
1380
+ deferredSetStates[id] = setTimeout(() => {
1381
+ if (loading) {
1382
+ setComponentLoading(id);
1383
+ } else {
1384
+ unsetComponentLoading(id);
1385
+ }
1386
+ delete deferredSetStates[id];
1387
+ }, defer);
1388
+ };
1389
+ const runResolvers = () => __async(void 0, null, function* () {
1390
+ const newData = newAppState.data;
1391
+ const flatContent = flattenData(newData).filter(
1392
+ (item) => {
1393
+ var _a;
1394
+ return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
1395
+ }
509
1396
  );
510
- const item = parentZone[itemIndex];
511
- if (!item) {
512
- return acc;
1397
+ const applyIfChange = (dynamicDataMap, dynamicRoot) => {
1398
+ const processed = applyDynamicProps(
1399
+ __spreadValues({}, appState.data),
1400
+ dynamicDataMap,
1401
+ dynamicRoot
1402
+ );
1403
+ const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
1404
+ const containsChanges = !(0, import_fast_deep_equal.default)(appState, processedAppState);
1405
+ if (containsChanges) {
1406
+ dispatch({
1407
+ type: "set",
1408
+ state: (prev) => __spreadProps(__spreadValues({}, prev), {
1409
+ data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
1410
+ ui: resolveDataRuns > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
1411
+ }),
1412
+ recordHistory: resolveDataRuns > 0
1413
+ });
1414
+ }
1415
+ };
1416
+ const promises = [];
1417
+ promises.push(
1418
+ (() => __async(void 0, null, function* () {
1419
+ _setComponentLoading("puck-root", true, 50);
1420
+ const dynamicRoot = yield resolveRootData(newData, config, metadata);
1421
+ applyIfChange({}, dynamicRoot);
1422
+ _setComponentLoading("puck-root", false);
1423
+ }))()
1424
+ );
1425
+ flatContent.forEach((item) => {
1426
+ promises.push(
1427
+ (() => __async(void 0, null, function* () {
1428
+ permissions.resolvePermissions({ item }, true);
1429
+ const dynamicData = yield resolveComponentData(
1430
+ item,
1431
+ config,
1432
+ metadata,
1433
+ (item2) => {
1434
+ _setComponentLoading(item2.props.id, true, 50);
1435
+ },
1436
+ (item2) => {
1437
+ deferredSetStates[item2.props.id];
1438
+ _setComponentLoading(item2.props.id, false);
1439
+ }
1440
+ );
1441
+ const dynamicDataMap = { [item.props.id]: dynamicData };
1442
+ applyIfChange(dynamicDataMap);
1443
+ }))()
1444
+ );
1445
+ });
1446
+ yield Promise.all(promises);
1447
+ });
1448
+ return runResolvers();
1449
+ };
1450
+
1451
+ // ../core/store/index.ts
1452
+ var import_react10 = require("react");
1453
+
1454
+ // ../core/store/slices/history.ts
1455
+ init_react_import();
1456
+ var import_react6 = require("react");
1457
+
1458
+ // ../core/lib/use-hotkey.ts
1459
+ init_react_import();
1460
+ var import_react5 = require("react");
1461
+ var useHotkeyStore = create()(
1462
+ subscribeWithSelector((set) => ({
1463
+ held: {},
1464
+ hold: (key) => set((s) => s.held[key] ? s : { held: __spreadProps(__spreadValues({}, s.held), { [key]: true }) }),
1465
+ release: (key) => set((s) => s.held[key] ? { held: __spreadProps(__spreadValues({}, s.held), { [key]: false }) } : s),
1466
+ reset: (held = {}) => set(() => ({ held })),
1467
+ triggers: {}
1468
+ }))
1469
+ );
1470
+
1471
+ // ../core/store/slices/history.ts
1472
+ var EMPTY_HISTORY_INDEX = 0;
1473
+ function debounce(func, timeout = 300) {
1474
+ let timer;
1475
+ return (...args) => {
1476
+ clearTimeout(timer);
1477
+ timer = setTimeout(() => {
1478
+ func(...args);
1479
+ }, timeout);
1480
+ };
1481
+ }
1482
+ var tidyState = (state) => {
1483
+ return __spreadProps(__spreadValues({}, state), {
1484
+ ui: __spreadProps(__spreadValues({}, state.ui), {
1485
+ field: {
1486
+ focus: null
1487
+ }
1488
+ })
1489
+ });
1490
+ };
1491
+ var createHistorySlice = (set, get) => {
1492
+ const record = debounce((state) => {
1493
+ const { histories, index } = get().history;
1494
+ const history = {
1495
+ state,
1496
+ id: generateId("history")
1497
+ };
1498
+ const newHistories = [...histories.slice(0, index + 1), history];
1499
+ set({
1500
+ history: __spreadProps(__spreadValues({}, get().history), {
1501
+ histories: newHistories,
1502
+ index: newHistories.length - 1
1503
+ })
1504
+ });
1505
+ }, 250);
1506
+ return {
1507
+ initialAppState: {},
1508
+ index: EMPTY_HISTORY_INDEX,
1509
+ histories: [],
1510
+ hasPast: () => get().history.index > EMPTY_HISTORY_INDEX,
1511
+ hasFuture: () => get().history.index < get().history.histories.length - 1,
1512
+ prevHistory: () => {
1513
+ const { history } = get();
1514
+ return history.hasPast() ? history.histories[history.index - 1] : null;
1515
+ },
1516
+ nextHistory: () => {
1517
+ const s = get().history;
1518
+ return s.hasFuture() ? s.histories[s.index + 1] : null;
1519
+ },
1520
+ currentHistory: () => get().history.histories[get().history.index],
1521
+ back: () => {
1522
+ var _a;
1523
+ const { history, dispatch } = get();
1524
+ if (history.hasPast()) {
1525
+ const state = tidyState(
1526
+ ((_a = history.prevHistory()) == null ? void 0 : _a.state) || history.initialAppState
1527
+ );
1528
+ dispatch({
1529
+ type: "set",
1530
+ state
1531
+ });
1532
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index - 1 }) });
1533
+ }
1534
+ },
1535
+ forward: () => {
1536
+ var _a;
1537
+ const { history, dispatch } = get();
1538
+ if (history.hasFuture()) {
1539
+ const state = (_a = history.nextHistory()) == null ? void 0 : _a.state;
1540
+ dispatch({ type: "set", state: state ? tidyState(state) : {} });
1541
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index + 1 }) });
1542
+ }
1543
+ },
1544
+ setHistories: (histories) => {
1545
+ var _a;
1546
+ const { dispatch, history } = get();
1547
+ dispatch({
1548
+ type: "set",
1549
+ state: ((_a = history.histories[history.histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
1550
+ });
1551
+ set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
1552
+ },
1553
+ setHistoryIndex: (index) => {
1554
+ var _a;
1555
+ const { dispatch, history } = get();
1556
+ dispatch({
1557
+ type: "set",
1558
+ state: ((_a = history.histories[history.index]) == null ? void 0 : _a.state) || history.initialAppState
1559
+ });
1560
+ set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1561
+ },
1562
+ record
1563
+ };
1564
+ };
1565
+
1566
+ // ../core/store/slices/nodes.ts
1567
+ init_react_import();
1568
+ var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
1569
+ var import_react7 = require("react");
1570
+ var partialDeepEqual = (newItem, existingItem) => {
1571
+ const filteredExistingItem = Object.keys(newItem).reduce(
1572
+ (acc, key) => __spreadProps(__spreadValues({}, acc), { [key]: existingItem[key] }),
1573
+ {}
1574
+ );
1575
+ return (0, import_fast_deep_equal2.default)(newItem, filteredExistingItem);
1576
+ };
1577
+ var createNodesSlice = (set, get) => ({
1578
+ nodes: {},
1579
+ registerNode: (id, node) => {
1580
+ const s = get().nodes;
1581
+ if (s.nodes[id] && partialDeepEqual(node, s.nodes[id])) {
1582
+ return;
513
1583
  }
514
- return [
515
- ...acc,
516
- {
517
- label: item.type.toString(),
518
- selector: {
519
- index: itemIndex,
520
- zone: parentZoneCompound
1584
+ const emptyNode = {
1585
+ id,
1586
+ methods: { sync: () => null },
1587
+ data: { props: { id }, type: "unknown" },
1588
+ parentId: "",
1589
+ zone: "",
1590
+ path: [],
1591
+ element: null,
1592
+ index: -1
1593
+ };
1594
+ const existingNode = s.nodes[id];
1595
+ set({
1596
+ nodes: __spreadProps(__spreadValues({}, s), {
1597
+ nodes: __spreadProps(__spreadValues({}, s.nodes), {
1598
+ [id]: __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, emptyNode), existingNode), node), {
1599
+ id
1600
+ })
1601
+ })
1602
+ })
1603
+ });
1604
+ },
1605
+ unregisterNode: (id) => {
1606
+ const s = get().nodes;
1607
+ const existingNode = s.nodes[id];
1608
+ if (existingNode) {
1609
+ const newNodes = __spreadValues({}, s.nodes);
1610
+ delete newNodes[id];
1611
+ set({
1612
+ nodes: __spreadProps(__spreadValues({}, s), {
1613
+ nodes: newNodes
1614
+ })
1615
+ });
1616
+ }
1617
+ }
1618
+ });
1619
+
1620
+ // ../core/store/slices/permissions.ts
1621
+ init_react_import();
1622
+ var import_react8 = require("react");
1623
+ var createPermissionsSlice = (set, get) => {
1624
+ const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1625
+ const { state, permissions } = get();
1626
+ const { cache: cache3, globalPermissions } = permissions;
1627
+ const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1628
+ var _a, _b, _c;
1629
+ const {
1630
+ config,
1631
+ state: appState,
1632
+ setComponentLoading,
1633
+ unsetComponentLoading
1634
+ } = get();
1635
+ const componentConfig = item2.type === "root" ? config.root : config.components[item2.type];
1636
+ if (!componentConfig) {
1637
+ return;
1638
+ }
1639
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1640
+ if (componentConfig.resolvePermissions) {
1641
+ const changed = getChanged(item2, (_a = cache3[item2.props.id]) == null ? void 0 : _a.lastData);
1642
+ if (Object.values(changed).some((el) => el === true) || force2) {
1643
+ setComponentLoading(item2.props.id);
1644
+ const resolvedPermissions = yield componentConfig.resolvePermissions(
1645
+ item2,
1646
+ {
1647
+ changed,
1648
+ lastPermissions: ((_b = cache3[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1649
+ permissions: initialPermissions,
1650
+ appState,
1651
+ lastData: ((_c = cache3[item2.props.id]) == null ? void 0 : _c.lastData) || null
1652
+ }
1653
+ );
1654
+ const latest = get().permissions;
1655
+ set({
1656
+ permissions: __spreadProps(__spreadValues({}, latest), {
1657
+ cache: __spreadProps(__spreadValues({}, latest.cache), {
1658
+ [item2.props.id]: {
1659
+ lastData: item2,
1660
+ lastPermissions: resolvedPermissions
1661
+ }
1662
+ }),
1663
+ resolvedPermissions: __spreadProps(__spreadValues({}, latest.resolvedPermissions), {
1664
+ [item2.props.id]: resolvedPermissions
1665
+ })
1666
+ })
1667
+ });
1668
+ unsetComponentLoading(item2.props.id);
1669
+ }
1670
+ }
1671
+ });
1672
+ const resolveDataForRoot = (force2 = false) => {
1673
+ const { state: appState } = get();
1674
+ resolveDataForItem(
1675
+ // Shim the root data in by conforming to component data shape
1676
+ {
1677
+ type: "root",
1678
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
521
1679
  },
522
- zoneCompound
1680
+ force2
1681
+ );
1682
+ };
1683
+ const { item, type, root } = params;
1684
+ if (item) {
1685
+ yield resolveDataForItem(item, force);
1686
+ } else if (type) {
1687
+ flattenData(state.data).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1688
+ yield resolveDataForItem(item2, force);
1689
+ }));
1690
+ } else if (root) {
1691
+ resolveDataForRoot(force);
1692
+ } else {
1693
+ resolveDataForRoot(force);
1694
+ flattenData(state.data).map((item2) => __async(void 0, null, function* () {
1695
+ yield resolveDataForItem(item2, force);
1696
+ }));
1697
+ }
1698
+ });
1699
+ const refreshPermissions = (params) => resolvePermissions(params, true);
1700
+ return {
1701
+ cache: {},
1702
+ globalPermissions: {
1703
+ drag: true,
1704
+ edit: true,
1705
+ delete: true,
1706
+ duplicate: true,
1707
+ insert: true
1708
+ },
1709
+ resolvedPermissions: {},
1710
+ getPermissions: ({ item, type, root } = {}) => {
1711
+ const { config, permissions } = get();
1712
+ const { globalPermissions, resolvedPermissions } = permissions;
1713
+ if (item) {
1714
+ const componentConfig = config.components[item.type];
1715
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1716
+ const resolvedForItem = resolvedPermissions[item.props.id];
1717
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1718
+ } else if (type) {
1719
+ const componentConfig = config.components[type];
1720
+ return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1721
+ } else if (root) {
1722
+ const rootConfig = config.root;
1723
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1724
+ const resolvedForItem = resolvedPermissions["puck-root"];
1725
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
523
1726
  }
524
- ];
525
- }, []);
1727
+ return globalPermissions;
1728
+ },
1729
+ resolvePermissions,
1730
+ refreshPermissions
1731
+ };
1732
+ };
1733
+
1734
+ // ../core/store/slices/fields.ts
1735
+ init_react_import();
1736
+ var import_react9 = require("react");
1737
+ var createFieldsStore = (_set, _get) => {
1738
+ return {
1739
+ fields: {},
1740
+ loading: false,
1741
+ lastResolvedData: {}
1742
+ };
1743
+ };
1744
+
1745
+ // ../core/store/index.ts
1746
+ var defaultAppState = {
1747
+ data: { content: [], root: {}, zones: {} },
1748
+ ui: {
1749
+ leftSideBarVisible: true,
1750
+ rightSideBarVisible: true,
1751
+ arrayState: {},
1752
+ itemSelector: null,
1753
+ componentList: {},
1754
+ isDragging: false,
1755
+ previewMode: "edit",
1756
+ viewports: {
1757
+ current: {
1758
+ width: defaultViewports[0].width,
1759
+ height: defaultViewports[0].height || "auto"
1760
+ },
1761
+ options: [],
1762
+ controlsVisible: true
1763
+ },
1764
+ field: { focus: null }
1765
+ }
526
1766
  };
1767
+ var defaultPageFields = {
1768
+ title: { type: "text" }
1769
+ };
1770
+ var createAppStore = (initialAppStore) => create()(
1771
+ subscribeWithSelector((set, get) => __spreadProps(__spreadValues({
1772
+ state: defaultAppState,
1773
+ config: { components: {} },
1774
+ componentState: {},
1775
+ plugins: [],
1776
+ overrides: {},
1777
+ viewports: defaultViewports,
1778
+ zoomConfig: {
1779
+ autoZoom: 1,
1780
+ rootHeight: 0,
1781
+ zoom: 1
1782
+ },
1783
+ status: "LOADING",
1784
+ iframe: {},
1785
+ metadata: {}
1786
+ }, initialAppStore), {
1787
+ fields: createFieldsStore(set, get),
1788
+ history: createHistorySlice(set, get),
1789
+ nodes: createNodesSlice(set, get),
1790
+ permissions: createPermissionsSlice(set, get),
1791
+ getComponentConfig: (type) => {
1792
+ var _a;
1793
+ const { config, selectedItem } = get();
1794
+ const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1795
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1796
+ },
1797
+ dispatch: (action) => set((s) => {
1798
+ var _a, _b;
1799
+ const { record } = get().history;
1800
+ const dispatch = createReducer({ config: s.config, record });
1801
+ const state = dispatch(s.state, action);
1802
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1803
+ (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1804
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1805
+ }),
1806
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1807
+ setStatus: (status) => set({ status }),
1808
+ setComponentState: (componentState) => set({ componentState }),
1809
+ setComponentLoading: (id) => {
1810
+ var _a;
1811
+ const { setComponentState, componentState } = get();
1812
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1813
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1814
+ loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1815
+ })
1816
+ }));
1817
+ },
1818
+ unsetComponentLoading: (id) => {
1819
+ var _a;
1820
+ const { setComponentState, componentState } = get();
1821
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1822
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1823
+ loadingCount: Math.max(
1824
+ (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1825
+ 0
1826
+ )
1827
+ })
1828
+ }));
1829
+ },
1830
+ // Helper
1831
+ setUi: (ui, recordHistory) => set((s) => {
1832
+ const dispatch = createReducer({
1833
+ config: s.config,
1834
+ record: () => {
1835
+ }
1836
+ });
1837
+ const state = dispatch(s.state, {
1838
+ type: "setUi",
1839
+ ui,
1840
+ recordHistory
1841
+ });
1842
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1843
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1844
+ }),
1845
+ resolveDataRuns: 0,
1846
+ resolveData: (newAppState) => set((s) => {
1847
+ resolveData(newAppState, get());
1848
+ return __spreadProps(__spreadValues({}, s), { resolveDataRuns: s.resolveDataRuns + 1 });
1849
+ })
1850
+ }))
1851
+ );
1852
+ var appStoreContext = (0, import_react10.createContext)(createAppStore());
1853
+ function useAppStore(selector) {
1854
+ const context = (0, import_react10.useContext)(appStoreContext);
1855
+ return useStore(context, selector);
1856
+ }
1857
+ function useAppStoreApi() {
1858
+ return (0, import_react10.useContext)(appStoreContext);
1859
+ }
1860
+
1861
+ // ../core/lib/use-breadcrumbs.ts
527
1862
  var useBreadcrumbs = (renderCount) => {
528
- const {
529
- state: { data },
530
- selectedItem
531
- } = useAppContext();
532
- const dzContext = (0, import_react8.useContext)(dropZoneContext);
533
- return (0, import_react8.useMemo)(() => {
534
- const breadcrumbs = convertPathDataToBreadcrumbs(
535
- selectedItem,
536
- dzContext == null ? void 0 : dzContext.pathData,
537
- data
538
- );
1863
+ const selectedId = useAppStore((s) => {
1864
+ var _a;
1865
+ return (_a = s.selectedItem) == null ? void 0 : _a.props.id;
1866
+ });
1867
+ const config = useAppStore((s) => s.config);
1868
+ const path = useAppStore((s) => {
1869
+ var _a;
1870
+ return (_a = s.nodes.nodes[selectedId]) == null ? void 0 : _a.path;
1871
+ });
1872
+ const appStore = useAppStoreApi();
1873
+ return (0, import_react11.useMemo)(() => {
1874
+ const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
1875
+ var _a, _b;
1876
+ const [componentId] = zoneCompound.split(":");
1877
+ if (componentId === "root") {
1878
+ return {
1879
+ label: "Page",
1880
+ selector: null
1881
+ };
1882
+ }
1883
+ const node = appStore.getState().nodes.nodes[componentId];
1884
+ const label = node ? (_b = (_a = config.components[node.data.type]) == null ? void 0 : _a.label) != null ? _b : node.data.type : "Component";
1885
+ return {
1886
+ label,
1887
+ selector: node ? {
1888
+ index: node.index,
1889
+ zone: node.path[node.path.length - 1]
1890
+ } : null
1891
+ };
1892
+ })) || [];
539
1893
  if (renderCount) {
540
1894
  return breadcrumbs.slice(breadcrumbs.length - renderCount);
541
1895
  }
542
1896
  return breadcrumbs;
543
- }, [selectedItem, dzContext == null ? void 0 : dzContext.pathData, renderCount]);
1897
+ }, [path, renderCount]);
544
1898
  };
545
1899
 
546
1900
  // ../core/components/Loader/index.tsx
@@ -552,18 +1906,12 @@ init_react_import();
552
1906
  // ../core/lib/filter.ts
553
1907
  init_react_import();
554
1908
 
555
- // ../core/lib/reorder.ts
556
- init_react_import();
557
-
558
- // ../core/lib/replace.ts
559
- init_react_import();
560
-
561
1909
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
562
1910
  init_react_import();
563
1911
  var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
564
1912
 
565
1913
  // ../core/components/Loader/index.tsx
566
- var import_jsx_runtime4 = require("react/jsx-runtime");
1914
+ var import_jsx_runtime2 = require("react/jsx-runtime");
567
1915
  var getClassName2 = get_class_name_factory_default("Loader", styles_module_default3);
568
1916
  var Loader = (_a) => {
569
1917
  var _b = _a, {
@@ -573,7 +1921,7 @@ var Loader = (_a) => {
573
1921
  "color",
574
1922
  "size"
575
1923
  ]);
576
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1924
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
577
1925
  "span",
578
1926
  __spreadValues({
579
1927
  className: getClassName2(),
@@ -588,7 +1936,7 @@ var Loader = (_a) => {
588
1936
  };
589
1937
 
590
1938
  // ../core/components/SidebarSection/index.tsx
591
- var import_jsx_runtime5 = require("react/jsx-runtime");
1939
+ var import_jsx_runtime3 = require("react/jsx-runtime");
592
1940
  var getClassName3 = get_class_name_factory_default("SidebarSection", styles_module_default);
593
1941
  var SidebarSection = ({
594
1942
  children,
@@ -599,17 +1947,17 @@ var SidebarSection = ({
599
1947
  noPadding,
600
1948
  isLoading
601
1949
  }) => {
602
- const { setUi } = useAppContext();
1950
+ const setUi = useAppStore((s) => s.setUi);
603
1951
  const breadcrumbs = useBreadcrumbs(1);
604
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1952
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
605
1953
  "div",
606
1954
  {
607
1955
  className: getClassName3({ noBorderTop, noPadding }),
608
1956
  style: { background },
609
1957
  children: [
610
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName3("title"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName3("breadcrumbs"), children: [
611
- showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName3("breadcrumb"), children: [
612
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1958
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName3("title"), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: getClassName3("breadcrumbs"), children: [
1959
+ showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: getClassName3("breadcrumb"), children: [
1960
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
613
1961
  "button",
614
1962
  {
615
1963
  type: "button",
@@ -618,12 +1966,12 @@ var SidebarSection = ({
618
1966
  children: breadcrumb.label
619
1967
  }
620
1968
  ),
621
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChevronRight, { size: 16 })
1969
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChevronRight, { size: 16 })
622
1970
  ] }, i)) : null,
623
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName3("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Heading, { rank: "2", size: "xs", children: title }) })
1971
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName3("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Heading, { rank: "2", size: "xs", children: title }) })
624
1972
  ] }) }),
625
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName3("content"), children }),
626
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName3("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Loader, { size: 32 }) })
1973
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName3("content"), children }),
1974
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName3("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Loader, { size: 32 }) })
627
1975
  ]
628
1976
  }
629
1977
  );
@@ -637,18 +1985,18 @@ init_react_import();
637
1985
  var styles_module_default4 = { "OutlineList": "_OutlineList_w4lzv_1", "OutlineListItem": "_OutlineListItem_w4lzv_25", "OutlineListItem--clickable": "_OutlineListItem--clickable_w4lzv_45" };
638
1986
 
639
1987
  // ../core/components/OutlineList/index.tsx
640
- var import_jsx_runtime6 = require("react/jsx-runtime");
1988
+ var import_jsx_runtime4 = require("react/jsx-runtime");
641
1989
  var getClassName4 = get_class_name_factory_default("OutlineList", styles_module_default4);
642
1990
  var getClassNameItem = get_class_name_factory_default("OutlineListItem", styles_module_default4);
643
1991
  var OutlineList = ({ children }) => {
644
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: getClassName4(), children });
1992
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: getClassName4(), children });
645
1993
  };
646
- OutlineList.Clickable = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: getClassNameItem({ clickable: true }), children });
1994
+ OutlineList.Clickable = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassNameItem({ clickable: true }), children });
647
1995
  OutlineList.Item = ({
648
1996
  children,
649
1997
  onClick
650
1998
  }) => {
651
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1999
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
652
2000
  "li",
653
2001
  {
654
2002
  className: getClassNameItem({ clickable: !!onClick }),
@@ -682,7 +2030,7 @@ var getFrame = () => {
682
2030
 
683
2031
  // src/HeadingAnalyzer.tsx
684
2032
  var import_react_from_json = __toESM(require("react-from-json"));
685
- var import_jsx_runtime7 = require("react/jsx-runtime");
2033
+ var import_jsx_runtime5 = require("react/jsx-runtime");
686
2034
  var getClassName5 = get_class_name_factory_default("HeadingAnalyzer", HeadingAnalyzer_module_default);
687
2035
  var getClassNameItem2 = get_class_name_factory_default("HeadingAnalyzerItem", HeadingAnalyzer_module_default);
688
2036
  var ReactFromJSON = import_react_from_json.default.default || import_react_from_json.default;
@@ -735,10 +2083,11 @@ function buildHierarchy(frame) {
735
2083
  }
736
2084
  return root.children;
737
2085
  }
2086
+ var usePuck = (0, import_puck.createUsePuck)();
738
2087
  var HeadingAnalyzer = () => {
739
- const { appState } = (0, import_puck.usePuck)();
740
- const [hierarchy, setHierarchy] = (0, import_react9.useState)([]);
741
- (0, import_react9.useEffect)(() => {
2088
+ const data = usePuck((s) => s.appState.data);
2089
+ const [hierarchy, setHierarchy] = (0, import_react12.useState)([]);
2090
+ (0, import_react12.useEffect)(() => {
742
2091
  const frame = getFrame();
743
2092
  const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
744
2093
  if (!entry) return;
@@ -750,9 +2099,9 @@ var HeadingAnalyzer = () => {
750
2099
  return () => {
751
2100
  observer.disconnect();
752
2101
  };
753
- }, [appState.data]);
754
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: getClassName5(), children: [
755
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2102
+ }, [data]);
2103
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [
2104
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
756
2105
  "small",
757
2106
  {
758
2107
  className: getClassName5("cssWarning"),
@@ -764,19 +2113,19 @@ var HeadingAnalyzer = () => {
764
2113
  children: [
765
2114
  "Heading analyzer styles not loaded. Please review the",
766
2115
  " ",
767
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { href: "https://github.com/measuredco/puck/blob/main/packages/plugin-heading-analyzer/README.md", children: "README" }),
2116
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { href: "https://github.com/measuredco/puck/blob/main/packages/plugin-heading-analyzer/README.md", children: "README" }),
768
2117
  "."
769
2118
  ]
770
2119
  }
771
2120
  ),
772
- hierarchy.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children: "No headings." }),
773
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OutlineList, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2121
+ hierarchy.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: "No headings." }),
2122
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OutlineList, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
774
2123
  ReactFromJSON,
775
2124
  {
776
2125
  mapping: {
777
- Root: (props) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: props.children }),
778
- OutlineListItem: (props) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(OutlineList.Item, { children: [
779
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OutlineList.Clickable, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2126
+ Root: (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: props.children }),
2127
+ OutlineListItem: (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(OutlineList.Item, { children: [
2128
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OutlineList.Clickable, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
780
2129
  "small",
781
2130
  {
782
2131
  className: getClassNameItem2({ missing: props.missing }),
@@ -794,14 +2143,14 @@ var HeadingAnalyzer = () => {
794
2143
  }, 2e3);
795
2144
  }
796
2145
  },
797
- children: props.missing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
798
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("b", { children: [
2146
+ children: props.missing ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
2147
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("b", { children: [
799
2148
  "H",
800
2149
  props.rank
801
2150
  ] }),
802
2151
  ": Missing"
803
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
804
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("b", { children: [
2152
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
2153
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("b", { children: [
805
2154
  "H",
806
2155
  props.rank
807
2156
  ] }),
@@ -810,7 +2159,7 @@ var HeadingAnalyzer = () => {
810
2159
  ] })
811
2160
  }
812
2161
  ) }),
813
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OutlineList, { children: props.children })
2162
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OutlineList, { children: props.children })
814
2163
  ] })
815
2164
  },
816
2165
  entry: {
@@ -832,9 +2181,9 @@ var HeadingAnalyzer = () => {
832
2181
  };
833
2182
  var headingAnalyzer = {
834
2183
  overrides: {
835
- fields: ({ children, itemSelector }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2184
+ fields: ({ children, itemSelector }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
836
2185
  children,
837
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: { display: itemSelector ? "none" : "block" }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SidebarSection, { title: "Heading Outline", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HeadingAnalyzer, {}) }) })
2186
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { display: itemSelector ? "none" : "block" }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SidebarSection, { title: "Heading Outline", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(HeadingAnalyzer, {}) }) })
838
2187
  ] })
839
2188
  }
840
2189
  };
@@ -848,6 +2197,50 @@ classnames/index.js:
848
2197
  http://jedwatson.github.io/classnames
849
2198
  *)
850
2199
 
2200
+ use-sync-external-store/cjs/use-sync-external-store-shim.production.js:
2201
+ (**
2202
+ * @license React
2203
+ * use-sync-external-store-shim.production.js
2204
+ *
2205
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2206
+ *
2207
+ * This source code is licensed under the MIT license found in the
2208
+ * LICENSE file in the root directory of this source tree.
2209
+ *)
2210
+
2211
+ use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
2212
+ (**
2213
+ * @license React
2214
+ * use-sync-external-store-shim.development.js
2215
+ *
2216
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2217
+ *
2218
+ * This source code is licensed under the MIT license found in the
2219
+ * LICENSE file in the root directory of this source tree.
2220
+ *)
2221
+
2222
+ use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js:
2223
+ (**
2224
+ * @license React
2225
+ * use-sync-external-store-shim/with-selector.production.js
2226
+ *
2227
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2228
+ *
2229
+ * This source code is licensed under the MIT license found in the
2230
+ * LICENSE file in the root directory of this source tree.
2231
+ *)
2232
+
2233
+ use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js:
2234
+ (**
2235
+ * @license React
2236
+ * use-sync-external-store-shim/with-selector.development.js
2237
+ *
2238
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2239
+ *
2240
+ * This source code is licensed under the MIT license found in the
2241
+ * LICENSE file in the root directory of this source tree.
2242
+ *)
2243
+
851
2244
  lucide-react/dist/esm/shared/src/utils.js:
852
2245
  (**
853
2246
  * @license lucide-react v0.468.0 - ISC