@measured/puck-plugin-heading-analyzer 0.19.0-canary.020071e → 0.19.0-canary.036267f6

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.mjs CHANGED
@@ -21,12 +21,6 @@ var __spreadValues = (a, b) => {
21
21
  return a;
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
25
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
26
- }) : x)(function(x) {
27
- if (typeof require !== "undefined") return require.apply(this, arguments);
28
- throw Error('Dynamic require of "' + x + '" is not supported');
29
- });
30
24
  var __objRest = (source, exclude) => {
31
25
  var target = {};
32
26
  for (var prop in source)
@@ -42,7 +36,7 @@ var __objRest = (source, exclude) => {
42
36
  var __esm = (fn, res) => function __init() {
43
37
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
44
38
  };
45
- var __commonJS = (cb, mod) => function __require2() {
39
+ var __commonJS = (cb, mod) => function __require() {
46
40
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
47
41
  };
48
42
  var __copyProps = (to, from, except, desc) => {
@@ -152,289 +146,6 @@ var require_classnames = __commonJS({
152
146
  }
153
147
  });
154
148
 
155
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js
156
- var require_use_sync_external_store_shim_production = __commonJS({
157
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js"(exports) {
158
- "use strict";
159
- init_react_import();
160
- var React2 = __require("react");
161
- function is(x, y) {
162
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
163
- }
164
- var objectIs = "function" === typeof Object.is ? Object.is : is;
165
- var useState2 = React2.useState;
166
- var useEffect7 = React2.useEffect;
167
- var useLayoutEffect = React2.useLayoutEffect;
168
- var useDebugValue2 = React2.useDebugValue;
169
- function useSyncExternalStore$2(subscribe, getSnapshot) {
170
- var value = getSnapshot(), _useState = useState2({ inst: { value, getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1];
171
- useLayoutEffect(
172
- function() {
173
- inst.value = value;
174
- inst.getSnapshot = getSnapshot;
175
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
176
- },
177
- [subscribe, value, getSnapshot]
178
- );
179
- useEffect7(
180
- function() {
181
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
182
- return subscribe(function() {
183
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
184
- });
185
- },
186
- [subscribe]
187
- );
188
- useDebugValue2(value);
189
- return value;
190
- }
191
- function checkIfSnapshotChanged(inst) {
192
- var latestGetSnapshot = inst.getSnapshot;
193
- inst = inst.value;
194
- try {
195
- var nextValue = latestGetSnapshot();
196
- return !objectIs(inst, nextValue);
197
- } catch (error) {
198
- return true;
199
- }
200
- }
201
- function useSyncExternalStore$1(subscribe, getSnapshot) {
202
- return getSnapshot();
203
- }
204
- var shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
205
- exports.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim;
206
- }
207
- });
208
-
209
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
210
- var require_use_sync_external_store_shim_development = __commonJS({
211
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) {
212
- "use strict";
213
- init_react_import();
214
- "production" !== process.env.NODE_ENV && function() {
215
- function is(x, y) {
216
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
217
- }
218
- function useSyncExternalStore$2(subscribe, getSnapshot) {
219
- didWarnOld18Alpha || void 0 === React2.startTransition || (didWarnOld18Alpha = true, console.error(
220
- "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."
221
- ));
222
- var value = getSnapshot();
223
- if (!didWarnUncachedGetSnapshot) {
224
- var cachedValue = getSnapshot();
225
- objectIs(value, cachedValue) || (console.error(
226
- "The result of getSnapshot should be cached to avoid an infinite loop"
227
- ), didWarnUncachedGetSnapshot = true);
228
- }
229
- cachedValue = useState2({
230
- inst: { value, getSnapshot }
231
- });
232
- var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
233
- useLayoutEffect(
234
- function() {
235
- inst.value = value;
236
- inst.getSnapshot = getSnapshot;
237
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
238
- },
239
- [subscribe, value, getSnapshot]
240
- );
241
- useEffect7(
242
- function() {
243
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
244
- return subscribe(function() {
245
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
246
- });
247
- },
248
- [subscribe]
249
- );
250
- useDebugValue2(value);
251
- return value;
252
- }
253
- function checkIfSnapshotChanged(inst) {
254
- var latestGetSnapshot = inst.getSnapshot;
255
- inst = inst.value;
256
- try {
257
- var nextValue = latestGetSnapshot();
258
- return !objectIs(inst, nextValue);
259
- } catch (error) {
260
- return true;
261
- }
262
- }
263
- function useSyncExternalStore$1(subscribe, getSnapshot) {
264
- return getSnapshot();
265
- }
266
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
267
- 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;
268
- exports.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim;
269
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
270
- }();
271
- }
272
- });
273
-
274
- // ../../node_modules/use-sync-external-store/shim/index.js
275
- var require_shim = __commonJS({
276
- "../../node_modules/use-sync-external-store/shim/index.js"(exports, module) {
277
- "use strict";
278
- init_react_import();
279
- if (process.env.NODE_ENV === "production") {
280
- module.exports = require_use_sync_external_store_shim_production();
281
- } else {
282
- module.exports = require_use_sync_external_store_shim_development();
283
- }
284
- }
285
- });
286
-
287
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js
288
- var require_with_selector_production = __commonJS({
289
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js"(exports) {
290
- "use strict";
291
- init_react_import();
292
- var React2 = __require("react");
293
- var shim = require_shim();
294
- function is(x, y) {
295
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
296
- }
297
- var objectIs = "function" === typeof Object.is ? Object.is : is;
298
- var useSyncExternalStore = shim.useSyncExternalStore;
299
- var useRef = React2.useRef;
300
- var useEffect7 = React2.useEffect;
301
- var useMemo2 = React2.useMemo;
302
- var useDebugValue2 = React2.useDebugValue;
303
- exports.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
304
- var instRef = useRef(null);
305
- if (null === instRef.current) {
306
- var inst = { hasValue: false, value: null };
307
- instRef.current = inst;
308
- } else inst = instRef.current;
309
- instRef = useMemo2(
310
- function() {
311
- function memoizedSelector(nextSnapshot) {
312
- if (!hasMemo) {
313
- hasMemo = true;
314
- memoizedSnapshot = nextSnapshot;
315
- nextSnapshot = selector(nextSnapshot);
316
- if (void 0 !== isEqual && inst.hasValue) {
317
- var currentSelection = inst.value;
318
- if (isEqual(currentSelection, nextSnapshot))
319
- return memoizedSelection = currentSelection;
320
- }
321
- return memoizedSelection = nextSnapshot;
322
- }
323
- currentSelection = memoizedSelection;
324
- if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
325
- var nextSelection = selector(nextSnapshot);
326
- if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
327
- return memoizedSnapshot = nextSnapshot, currentSelection;
328
- memoizedSnapshot = nextSnapshot;
329
- return memoizedSelection = nextSelection;
330
- }
331
- var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
332
- return [
333
- function() {
334
- return memoizedSelector(getSnapshot());
335
- },
336
- null === maybeGetServerSnapshot ? void 0 : function() {
337
- return memoizedSelector(maybeGetServerSnapshot());
338
- }
339
- ];
340
- },
341
- [getSnapshot, getServerSnapshot, selector, isEqual]
342
- );
343
- var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
344
- useEffect7(
345
- function() {
346
- inst.hasValue = true;
347
- inst.value = value;
348
- },
349
- [value]
350
- );
351
- useDebugValue2(value);
352
- return value;
353
- };
354
- }
355
- });
356
-
357
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js
358
- var require_with_selector_development = __commonJS({
359
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js"(exports) {
360
- "use strict";
361
- init_react_import();
362
- "production" !== process.env.NODE_ENV && function() {
363
- function is(x, y) {
364
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
365
- }
366
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
367
- 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;
368
- exports.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
369
- var instRef = useRef(null);
370
- if (null === instRef.current) {
371
- var inst = { hasValue: false, value: null };
372
- instRef.current = inst;
373
- } else inst = instRef.current;
374
- instRef = useMemo2(
375
- function() {
376
- function memoizedSelector(nextSnapshot) {
377
- if (!hasMemo) {
378
- hasMemo = true;
379
- memoizedSnapshot = nextSnapshot;
380
- nextSnapshot = selector(nextSnapshot);
381
- if (void 0 !== isEqual && inst.hasValue) {
382
- var currentSelection = inst.value;
383
- if (isEqual(currentSelection, nextSnapshot))
384
- return memoizedSelection = currentSelection;
385
- }
386
- return memoizedSelection = nextSnapshot;
387
- }
388
- currentSelection = memoizedSelection;
389
- if (objectIs(memoizedSnapshot, nextSnapshot))
390
- return currentSelection;
391
- var nextSelection = selector(nextSnapshot);
392
- if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
393
- return memoizedSnapshot = nextSnapshot, currentSelection;
394
- memoizedSnapshot = nextSnapshot;
395
- return memoizedSelection = nextSelection;
396
- }
397
- var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
398
- return [
399
- function() {
400
- return memoizedSelector(getSnapshot());
401
- },
402
- null === maybeGetServerSnapshot ? void 0 : function() {
403
- return memoizedSelector(maybeGetServerSnapshot());
404
- }
405
- ];
406
- },
407
- [getSnapshot, getServerSnapshot, selector, isEqual]
408
- );
409
- var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
410
- useEffect7(
411
- function() {
412
- inst.hasValue = true;
413
- inst.value = value;
414
- },
415
- [value]
416
- );
417
- useDebugValue2(value);
418
- return value;
419
- };
420
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
421
- }();
422
- }
423
- });
424
-
425
- // ../../node_modules/use-sync-external-store/shim/with-selector.js
426
- var require_with_selector = __commonJS({
427
- "../../node_modules/use-sync-external-store/shim/with-selector.js"(exports, module) {
428
- "use strict";
429
- init_react_import();
430
- if (process.env.NODE_ENV === "production") {
431
- module.exports = require_with_selector_production();
432
- } else {
433
- module.exports = require_with_selector_development();
434
- }
435
- }
436
- });
437
-
438
149
  // ../../node_modules/fast-deep-equal/index.js
439
150
  var require_fast_deep_equal = __commonJS({
440
151
  "../../node_modules/fast-deep-equal/index.js"(exports, module) {
@@ -476,7 +187,7 @@ init_react_import();
476
187
 
477
188
  // src/HeadingAnalyzer.tsx
478
189
  init_react_import();
479
- import { useEffect as useEffect6, useState } from "react";
190
+ import { useEffect as useEffect5, useState } from "react";
480
191
 
481
192
  // css-module:/home/runner/work/puck/puck/packages/plugin-heading-analyzer/src/HeadingAnalyzer.module.css#css-module
482
193
  init_react_import();
@@ -645,28 +356,13 @@ init_react_import();
645
356
  // ../core/reducer/index.ts
646
357
  init_react_import();
647
358
 
648
- // ../core/reducer/data.ts
649
- init_react_import();
650
-
651
- // ../core/lib/reorder.ts
652
- init_react_import();
653
- var reorder = (list, startIndex, endIndex) => {
654
- const result = Array.from(list);
655
- const [removed] = result.splice(startIndex, 1);
656
- result.splice(endIndex, 0, removed);
657
- return result;
658
- };
659
-
660
- // ../core/lib/root-droppable-id.ts
359
+ // ../core/reducer/reduce.ts
661
360
  init_react_import();
662
- var rootAreaId = "root";
663
- var rootZone = "default-zone";
664
- var rootDroppableId = `${rootAreaId}:${rootZone}`;
665
361
 
666
362
  // ../core/lib/insert.ts
667
363
  init_react_import();
668
364
  var insert = (list, index, item) => {
669
- const result = Array.from(list);
365
+ const result = Array.from(list || []);
670
366
  result.splice(index, 0, item);
671
367
  return result;
672
368
  };
@@ -681,6 +377,14 @@ var remove = (list, index) => {
681
377
 
682
378
  // ../core/lib/setup-zone.ts
683
379
  init_react_import();
380
+
381
+ // ../core/lib/root-droppable-id.ts
382
+ init_react_import();
383
+ var rootAreaId = "root";
384
+ var rootZone = "default-zone";
385
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
386
+
387
+ // ../core/lib/setup-zone.ts
684
388
  var setupZone = (data, zoneKey) => {
685
389
  if (zoneKey === rootDroppableId) {
686
390
  return data;
@@ -692,29 +396,14 @@ var setupZone = (data, zoneKey) => {
692
396
  return newData;
693
397
  };
694
398
 
695
- // ../core/lib/replace.ts
696
- init_react_import();
697
- var replace = (list, index, newItem) => {
698
- const result = Array.from(list);
699
- result.splice(index, 1);
700
- result.splice(index, 0, newItem);
701
- return result;
702
- };
703
-
704
399
  // ../core/lib/get-item.ts
705
400
  init_react_import();
706
- function getItem(selector, data, dynamicProps = {}) {
707
- if (!selector.zone || selector.zone === rootDroppableId) {
708
- const item2 = data.content[selector.index];
709
- return (item2 == null ? void 0 : item2.props) ? __spreadProps(__spreadValues({}, item2), { props: dynamicProps[item2.props.id] || item2.props }) : void 0;
710
- }
711
- const item = setupZone(data, selector.zone).zones[selector.zone][selector.index];
712
- return (item == null ? void 0 : item.props) ? __spreadProps(__spreadValues({}, item), { props: dynamicProps[item.props.id] || item.props }) : void 0;
401
+ function getItem(selector, state) {
402
+ var _a, _b;
403
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
404
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
713
405
  }
714
406
 
715
- // ../core/lib/reduce-related-zones.ts
716
- init_react_import();
717
-
718
407
  // ../core/lib/generate-id.ts
719
408
  init_react_import();
720
409
 
@@ -777,6 +466,43 @@ var v4_default = v4;
777
466
  // ../core/lib/generate-id.ts
778
467
  var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
779
468
 
469
+ // ../core/lib/walk-tree.ts
470
+ init_react_import();
471
+
472
+ // ../core/lib/for-each-slot.ts
473
+ init_react_import();
474
+
475
+ // ../core/lib/is-slot.ts
476
+ init_react_import();
477
+ var isSlot = (prop) => {
478
+ var _a, _b;
479
+ return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
480
+ };
481
+
482
+ // ../core/lib/for-each-slot.ts
483
+ var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, cb, recursive = false, isSlot2 = isSlot) {
484
+ const props = item.props || {};
485
+ const propKeys = Object.keys(props);
486
+ for (let i = 0; i < propKeys.length; i++) {
487
+ const propKey = propKeys[i];
488
+ const itemType = "type" in item ? item.type : "root";
489
+ if (isSlot2(itemType, propKey, props[propKey])) {
490
+ const content = props[propKey];
491
+ yield cb(props.id, propKey, content);
492
+ if (recursive) {
493
+ content.forEach(
494
+ (childItem) => __async(void 0, null, function* () {
495
+ return yield forEachSlot(childItem, cb, true, isSlot2);
496
+ })
497
+ );
498
+ }
499
+ }
500
+ }
501
+ });
502
+
503
+ // ../core/lib/for-related-zones.ts
504
+ init_react_import();
505
+
780
506
  // ../core/lib/get-zone-id.ts
781
507
  init_react_import();
782
508
  var getZoneId = (zoneCompound) => {
@@ -789,302 +515,491 @@ var getZoneId = (zoneCompound) => {
789
515
  return [rootDroppableId, zoneCompound];
790
516
  };
791
517
 
792
- // ../core/lib/reduce-related-zones.ts
793
- function reduceRelatedZones(item, data, fn) {
518
+ // ../core/lib/for-related-zones.ts
519
+ function forRelatedZones(item, data, cb, path = []) {
520
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
521
+ const [parentId] = getZoneId(zoneCompound);
522
+ if (parentId === item.props.id) {
523
+ const newPath = [...path, zoneCompound];
524
+ content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
525
+ cb(path, zoneCompound, content);
526
+ }
527
+ });
528
+ }
529
+
530
+ // ../core/lib/strip-slots.ts
531
+ init_react_import();
532
+ var stripSlots = (data) => {
794
533
  return __spreadProps(__spreadValues({}, data), {
795
- zones: Object.keys(data.zones || {}).reduce(
796
- (acc, key) => {
797
- const [parentId] = getZoneId(key);
798
- if (parentId === item.props.id) {
799
- const zones = data.zones;
800
- return fn(acc, key, zones[key]);
534
+ props: Object.entries(data.props).reduce(
535
+ (acc, [propKey, propVal]) => {
536
+ if (isSlot(propVal)) {
537
+ return acc;
801
538
  }
802
- return __spreadProps(__spreadValues({}, acc), { [key]: data.zones[key] });
539
+ return __spreadProps(__spreadValues({}, acc), { [propKey]: propVal });
803
540
  },
804
- {}
541
+ { id: data.props.id }
805
542
  )
806
543
  });
807
- }
808
- var findRelatedByZoneId = (zoneId, data) => {
809
- const [zoneParentId] = getZoneId(zoneId);
810
- return (data.zones[zoneId] || []).reduce(
811
- (acc, zoneItem) => {
812
- const related = findRelatedByItem(zoneItem, data);
813
- if (zoneItem.props.id === zoneParentId) {
814
- return __spreadProps(__spreadValues(__spreadValues({}, acc), related), { [zoneId]: zoneItem });
815
- }
816
- return __spreadValues(__spreadValues({}, acc), related);
817
- },
818
- {}
819
- );
820
544
  };
821
- var findRelatedByItem = (item, data) => {
822
- return Object.keys(data.zones || {}).reduce(
823
- (acc, zoneId) => {
824
- const [zoneParentId] = getZoneId(zoneId);
825
- if (item.props.id === zoneParentId) {
826
- const related = findRelatedByZoneId(zoneId, data);
827
- return __spreadProps(__spreadValues(__spreadValues({}, acc), related), {
828
- [zoneId]: data.zones[zoneId]
829
- });
545
+
546
+ // ../core/lib/walk-tree.ts
547
+ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
548
+ var _a;
549
+ let newZones = {};
550
+ const newZoneIndex = {};
551
+ const newNodeIndex = {};
552
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
553
+ var _a2;
554
+ const [parentId] = zoneCompound.split(":");
555
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
556
+ const [_2, zone] = zoneCompound.split(":");
557
+ const newZoneCompound = `${newId || parentId}:${zone}`;
558
+ const newContent2 = mappedContent.map(
559
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
560
+ );
561
+ newZoneIndex[newZoneCompound] = {
562
+ contentIds: newContent2.map((item) => item.props.id),
563
+ type: zoneType
564
+ };
565
+ return [newZoneCompound, newContent2];
566
+ };
567
+ const processRelatedZones = (item, newId, initialPath) => {
568
+ forRelatedZones(
569
+ item,
570
+ state.data,
571
+ (relatedPath, relatedZoneCompound, relatedContent) => {
572
+ const [zoneCompound, newContent2] = processContent(
573
+ relatedPath,
574
+ relatedZoneCompound,
575
+ relatedContent,
576
+ "dropzone",
577
+ newId
578
+ );
579
+ newZones[zoneCompound] = newContent2;
580
+ },
581
+ initialPath
582
+ );
583
+ };
584
+ const processItem = (item, path, index) => {
585
+ const mappedItem = mapNodeOrSkip(item, path, index);
586
+ if (!mappedItem) return item;
587
+ const id = mappedItem.props.id;
588
+ processRelatedZones(item, id, path);
589
+ const newProps = __spreadValues({}, mappedItem.props);
590
+ forEachSlot(
591
+ mappedItem,
592
+ (parentId2, slotId, content) => {
593
+ const zoneCompound = `${parentId2}:${slotId}`;
594
+ const [_2, newContent2] = processContent(
595
+ path,
596
+ zoneCompound,
597
+ content,
598
+ "slot",
599
+ parentId2
600
+ );
601
+ newProps[slotId] = newContent2;
602
+ },
603
+ false,
604
+ (itemType, propName, propValue) => {
605
+ var _a2, _b;
606
+ const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
607
+ if (!configForComponent) return isSlot(propValue);
608
+ return ((_b = (_a2 = configForComponent.fields) == null ? void 0 : _a2[propName]) == null ? void 0 : _b.type) === "slot";
830
609
  }
831
- return acc;
610
+ );
611
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
612
+ const thisZoneCompound = path[path.length - 1];
613
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
614
+ newNodeIndex[id] = {
615
+ data: newItem,
616
+ flatData: stripSlots(newItem),
617
+ path,
618
+ parentId,
619
+ zone
620
+ };
621
+ const finalData = newItem;
622
+ if (newProps.id === "root") {
623
+ delete finalData["type"];
624
+ delete finalData.props["id"];
625
+ }
626
+ return finalData;
627
+ };
628
+ const zones = state.data.zones || {};
629
+ const [_, newContent] = processContent(
630
+ [],
631
+ rootDroppableId,
632
+ state.data.content,
633
+ "root"
634
+ );
635
+ const processedContent = newContent;
636
+ Object.keys(zones || {}).forEach((zoneCompound) => {
637
+ const [parentId] = zoneCompound.split(":");
638
+ const [_2, newContent2] = processContent(
639
+ [rootDroppableId],
640
+ zoneCompound,
641
+ zones[zoneCompound],
642
+ "dropzone",
643
+ parentId
644
+ );
645
+ newZones[zoneCompound] = newContent2;
646
+ }, newZones);
647
+ const processedRoot = processItem(
648
+ {
649
+ type: "root",
650
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
832
651
  },
833
- {}
652
+ [],
653
+ -1
834
654
  );
835
- };
836
- var removeRelatedZones = (item, data) => {
837
- const newData = __spreadValues({}, data);
838
- const related = findRelatedByItem(item, data);
839
- Object.keys(related).forEach((key) => {
840
- delete newData.zones[key];
655
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
656
+ props: processedRoot.props
841
657
  });
842
- return newData;
843
- };
844
- function duplicateRelatedZones(item, data, newId) {
845
- return reduceRelatedZones(item, data, (acc, key, zone) => {
846
- const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
847
- props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
848
- }));
849
- const dupeOfDupes = dupedZone.reduce(
850
- (dupeOfDupes2, item2, index) => __spreadValues(__spreadValues({}, dupeOfDupes2), duplicateRelatedZones(zone[index], data, item2.props.id).zones),
851
- acc
852
- );
853
- const [_, zoneId] = getZoneId(key);
854
- return __spreadProps(__spreadValues({}, dupeOfDupes), {
855
- [key]: zone,
856
- [`${newId}:${zoneId}`]: dupedZone
857
- });
658
+ return __spreadProps(__spreadValues({}, state), {
659
+ data: {
660
+ root,
661
+ // root: state.data.root, // TODO changing root causes it's entire subtree to re-render. Let's keep this disabled until the performance issues are resolved in #644.
662
+ content: processedContent,
663
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
664
+ },
665
+ indexes: {
666
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
667
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
668
+ }
858
669
  });
859
670
  }
860
671
 
861
- // ../core/reducer/data.ts
862
- var zoneCache = {};
863
- var replaceAction = (data, action) => {
864
- if (action.destinationZone === rootDroppableId) {
865
- return __spreadProps(__spreadValues({}, data), {
866
- content: replace(data.content, action.destinationIndex, action.data)
672
+ // ../core/lib/deindex.ts
673
+ init_react_import();
674
+ var deindex = (state, componentData) => {
675
+ let zones = __spreadValues({}, state.indexes.zones);
676
+ let nodes = __spreadValues({}, state.indexes.nodes);
677
+ const dindexRelatedZones = (item) => {
678
+ forRelatedZones(item, state.data, (_path, zoneCompound, content) => {
679
+ content.forEach((subItem) => {
680
+ dindexChildren(subItem);
681
+ delete nodes[subItem.props.id];
682
+ });
683
+ delete zones[zoneCompound];
867
684
  });
868
- }
869
- const newData = setupZone(data, action.destinationZone);
870
- return __spreadProps(__spreadValues({}, newData), {
871
- zones: __spreadProps(__spreadValues({}, newData.zones), {
872
- [action.destinationZone]: replace(
873
- newData.zones[action.destinationZone],
874
- action.destinationIndex,
875
- action.data
876
- )
877
- })
878
- });
685
+ };
686
+ const dindexChildren = (item) => {
687
+ forEachSlot(
688
+ item,
689
+ (parentId, slotId, content) => {
690
+ const zoneCompound = `${parentId}:${slotId}`;
691
+ delete zones[zoneCompound];
692
+ content.forEach((item2) => {
693
+ dindexRelatedZones(item2);
694
+ delete nodes[item2.props.id];
695
+ });
696
+ },
697
+ true
698
+ );
699
+ };
700
+ dindexRelatedZones(componentData);
701
+ dindexChildren(componentData);
702
+ delete nodes[componentData.props.id];
703
+ return { nodes, zones };
704
+ };
705
+
706
+ // ../core/reducer/reduce.ts
707
+ var zoneCache = {};
708
+ var getIdsForParent = (zoneCompound, state) => {
709
+ const [parentId] = zoneCompound.split(":");
710
+ const node = state.indexes.nodes[parentId];
711
+ return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
879
712
  };
880
- function insertAction(data, action, config) {
713
+ function insertAction(state, action, config) {
714
+ const id = action.id || generateId(action.componentType);
881
715
  const emptyComponentData = {
882
716
  type: action.componentType,
883
717
  props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
884
- id: action.id || generateId(action.componentType)
718
+ id
885
719
  })
886
720
  };
887
- if (action.destinationZone === rootDroppableId) {
888
- return __spreadProps(__spreadValues({}, data), {
889
- content: insert(
890
- data.content,
891
- action.destinationIndex,
892
- emptyComponentData
893
- )
894
- });
895
- }
896
- const newData = setupZone(data, action.destinationZone);
897
- return __spreadProps(__spreadValues({}, data), {
898
- zones: __spreadProps(__spreadValues({}, newData.zones), {
899
- [action.destinationZone]: insert(
900
- newData.zones[action.destinationZone],
901
- action.destinationIndex,
902
- emptyComponentData
903
- )
904
- })
905
- });
721
+ const [parentId] = action.destinationZone.split(":");
722
+ const idsInPath = getIdsForParent(action.destinationZone, state);
723
+ return walkTree(
724
+ state,
725
+ config,
726
+ (content, zoneCompound) => {
727
+ if (zoneCompound === action.destinationZone) {
728
+ return insert(
729
+ content || [],
730
+ action.destinationIndex,
731
+ emptyComponentData
732
+ );
733
+ }
734
+ return content;
735
+ },
736
+ (childItem, path) => {
737
+ if (childItem.props.id === id || childItem.props.id === parentId) {
738
+ return childItem;
739
+ } else if (idsInPath.includes(childItem.props.id)) {
740
+ return childItem;
741
+ } else if (path.includes(action.destinationZone)) {
742
+ return childItem;
743
+ }
744
+ return null;
745
+ }
746
+ );
906
747
  }
907
- var reorderAction = (data, action) => {
908
- if (action.destinationZone === rootDroppableId) {
909
- return __spreadProps(__spreadValues({}, data), {
910
- content: reorder(
911
- data.content,
912
- action.sourceIndex,
913
- action.destinationIndex
914
- )
915
- });
748
+ var moveAction = (state, action, appStore) => {
749
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
750
+ return state;
916
751
  }
917
- const newData = setupZone(data, action.destinationZone);
918
- return __spreadProps(__spreadValues({}, data), {
919
- zones: __spreadProps(__spreadValues({}, newData.zones), {
920
- [action.destinationZone]: reorder(
921
- newData.zones[action.destinationZone],
922
- action.sourceIndex,
923
- action.destinationIndex
924
- )
925
- })
926
- });
752
+ const item = getItem(
753
+ { zone: action.sourceZone, index: action.sourceIndex },
754
+ state
755
+ );
756
+ if (!item) return state;
757
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
758
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
759
+ return walkTree(
760
+ state,
761
+ appStore.config,
762
+ (content, zoneCompound) => {
763
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
764
+ return insert(
765
+ remove(content, action.sourceIndex),
766
+ action.destinationIndex,
767
+ item
768
+ );
769
+ } else if (zoneCompound === action.sourceZone) {
770
+ return remove(content, action.sourceIndex);
771
+ } else if (zoneCompound === action.destinationZone) {
772
+ return insert(content, action.destinationIndex, item);
773
+ }
774
+ return content;
775
+ },
776
+ (childItem, path) => {
777
+ const [sourceZoneParent] = action.sourceZone.split(":");
778
+ const [destinationZoneParent] = action.destinationZone.split(":");
779
+ const childId = childItem.props.id;
780
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
781
+ return childItem;
782
+ }
783
+ return null;
784
+ }
785
+ );
786
+ };
787
+ var replaceAction = (state, action, appStore) => {
788
+ const [parentId] = action.destinationZone.split(":");
789
+ const idsInPath = getIdsForParent(action.destinationZone, state);
790
+ return walkTree(
791
+ state,
792
+ appStore.config,
793
+ (content) => content,
794
+ (childItem, path) => {
795
+ const pathIds = path.map((p) => p.split(":")[0]);
796
+ if (childItem.props.id === action.data.props.id) {
797
+ return action.data;
798
+ } else if (childItem.props.id === parentId) {
799
+ return childItem;
800
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
801
+ return childItem;
802
+ } else if (pathIds.indexOf(action.data.props.id) > -1) {
803
+ return childItem;
804
+ }
805
+ return null;
806
+ }
807
+ );
808
+ };
809
+ var setAction = (state, action, appStore) => {
810
+ if (typeof action.state === "object") {
811
+ const newState = __spreadValues(__spreadValues({}, state), action.state);
812
+ if (action.state.indexes) {
813
+ console.warn(
814
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
815
+ );
816
+ return newState;
817
+ }
818
+ return walkTree(newState, appStore.config);
819
+ }
820
+ return __spreadValues(__spreadValues({}, state), action.state(state));
927
821
  };
928
- function reduceData(data, action, config) {
822
+ function reduce(state, action, appStore) {
823
+ if (action.type === "set") {
824
+ return setAction(state, action, appStore);
825
+ }
929
826
  if (action.type === "insert") {
930
- return insertAction(data, action, config);
827
+ return insertAction(state, action, appStore.config);
828
+ }
829
+ if (action.type === "replace") {
830
+ return replaceAction(state, action, appStore);
831
+ }
832
+ if (action.type === "replaceRoot") {
833
+ return walkTree(
834
+ state,
835
+ appStore.config,
836
+ (content) => content,
837
+ (childItem) => {
838
+ if (childItem.props.id === "root") {
839
+ return __spreadProps(__spreadValues({}, childItem), {
840
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
841
+ readOnly: action.root.readOnly
842
+ });
843
+ }
844
+ return childItem;
845
+ }
846
+ );
931
847
  }
932
848
  if (action.type === "duplicate") {
933
849
  const item = getItem(
934
850
  { index: action.sourceIndex, zone: action.sourceZone },
935
- data
851
+ state
936
852
  );
853
+ const idsInPath = getIdsForParent(action.sourceZone, state);
937
854
  const newItem = __spreadProps(__spreadValues({}, item), {
938
855
  props: __spreadProps(__spreadValues({}, item.props), {
939
856
  id: generateId(item.type)
940
857
  })
941
858
  });
942
- const dataWithRelatedDuplicated = duplicateRelatedZones(
943
- item,
944
- data,
945
- newItem.props.id
859
+ const modified = walkTree(
860
+ state,
861
+ appStore.config,
862
+ (content, zoneCompound) => {
863
+ if (zoneCompound === action.sourceZone) {
864
+ return insert(content, action.sourceIndex + 1, item);
865
+ }
866
+ return content;
867
+ },
868
+ (childItem, path, index) => {
869
+ const zoneCompound = path[path.length - 1];
870
+ const parents = path.map((p) => p.split(":")[0]);
871
+ if (parents.indexOf(newItem.props.id) > -1) {
872
+ return __spreadProps(__spreadValues({}, childItem), {
873
+ props: __spreadProps(__spreadValues({}, childItem.props), {
874
+ id: generateId(childItem.type)
875
+ })
876
+ });
877
+ }
878
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
879
+ return newItem;
880
+ }
881
+ const [sourceZoneParent] = action.sourceZone.split(":");
882
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
883
+ return childItem;
884
+ }
885
+ return null;
886
+ }
946
887
  );
947
- if (action.sourceZone === rootDroppableId) {
948
- return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
949
- content: insert(data.content, action.sourceIndex + 1, newItem)
950
- });
951
- }
952
- return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
953
- zones: __spreadProps(__spreadValues({}, dataWithRelatedDuplicated.zones), {
954
- [action.sourceZone]: insert(
955
- dataWithRelatedDuplicated.zones[action.sourceZone],
956
- action.sourceIndex + 1,
957
- newItem
958
- )
888
+ return __spreadProps(__spreadValues({}, modified), {
889
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
890
+ itemSelector: {
891
+ index: action.sourceIndex + 1,
892
+ zone: action.sourceZone
893
+ }
959
894
  })
960
895
  });
961
896
  }
962
897
  if (action.type === "reorder") {
963
- return reorderAction(data, action);
964
- }
965
- if (action.type === "move") {
966
- if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
967
- return data;
968
- }
969
- const newData = setupZone(
970
- setupZone(data, action.sourceZone),
971
- action.destinationZone
972
- );
973
- const item = getItem(
974
- { zone: action.sourceZone, index: action.sourceIndex },
975
- newData
898
+ return moveAction(
899
+ state,
900
+ {
901
+ type: "move",
902
+ sourceIndex: action.sourceIndex,
903
+ sourceZone: action.destinationZone,
904
+ destinationIndex: action.destinationIndex,
905
+ destinationZone: action.destinationZone
906
+ },
907
+ appStore
976
908
  );
977
- if (action.sourceZone === action.destinationZone) {
978
- return reorderAction(data, __spreadProps(__spreadValues({}, action), { type: "reorder" }));
979
- }
980
- if (action.sourceZone === rootDroppableId) {
981
- return __spreadProps(__spreadValues({}, newData), {
982
- content: remove(newData.content, action.sourceIndex),
983
- zones: __spreadProps(__spreadValues({}, newData.zones), {
984
- [action.destinationZone]: insert(
985
- newData.zones[action.destinationZone],
986
- action.destinationIndex,
987
- item
988
- )
989
- })
990
- });
991
- }
992
- if (action.destinationZone === rootDroppableId) {
993
- return __spreadProps(__spreadValues({}, newData), {
994
- content: insert(newData.content, action.destinationIndex, item),
995
- zones: __spreadProps(__spreadValues({}, newData.zones), {
996
- [action.sourceZone]: remove(
997
- newData.zones[action.sourceZone],
998
- action.sourceIndex
999
- )
1000
- })
1001
- });
1002
- }
1003
- return __spreadProps(__spreadValues({}, newData), {
1004
- zones: __spreadProps(__spreadValues({}, newData.zones), {
1005
- [action.sourceZone]: remove(
1006
- newData.zones[action.sourceZone],
1007
- action.sourceIndex
1008
- ),
1009
- [action.destinationZone]: insert(
1010
- newData.zones[action.destinationZone],
1011
- action.destinationIndex,
1012
- item
1013
- )
1014
- })
1015
- });
1016
909
  }
1017
- if (action.type === "replace") {
1018
- return replaceAction(data, action);
910
+ if (action.type === "move") {
911
+ return moveAction(state, action, appStore);
1019
912
  }
1020
913
  if (action.type === "remove") {
1021
- const item = getItem({ index: action.index, zone: action.zone }, data);
1022
- const dataWithRelatedRemoved = setupZone(
1023
- removeRelatedZones(item, data),
1024
- action.zone
914
+ const item = getItem({ index: action.index, zone: action.zone }, state);
915
+ let deindexed = deindex(state, item);
916
+ const [parentId] = action.zone.split(":");
917
+ return walkTree(
918
+ __spreadProps(__spreadValues({}, state), { indexes: deindexed }),
919
+ appStore.config,
920
+ (content, zoneCompound) => {
921
+ if (zoneCompound === action.zone) {
922
+ return remove(content, action.index);
923
+ }
924
+ return content;
925
+ },
926
+ (childItem, path) => {
927
+ const parentIds = path.map((p) => p.split(":")[0]);
928
+ if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
929
+ return childItem;
930
+ }
931
+ return null;
932
+ }
1025
933
  );
1026
- if (action.zone === rootDroppableId) {
1027
- return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
1028
- content: remove(data.content, action.index)
1029
- });
1030
- }
1031
- return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
1032
- zones: __spreadProps(__spreadValues({}, dataWithRelatedRemoved.zones), {
1033
- [action.zone]: remove(
1034
- dataWithRelatedRemoved.zones[action.zone],
1035
- action.index
1036
- )
1037
- })
1038
- });
1039
934
  }
1040
935
  if (action.type === "registerZone") {
1041
936
  if (zoneCache[action.zone]) {
1042
- return __spreadProps(__spreadValues({}, data), {
1043
- zones: __spreadProps(__spreadValues({}, data.zones), {
1044
- [action.zone]: zoneCache[action.zone]
937
+ return __spreadProps(__spreadValues({}, state), {
938
+ data: __spreadProps(__spreadValues({}, state.data), {
939
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
940
+ [action.zone]: zoneCache[action.zone]
941
+ })
942
+ }),
943
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
944
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
945
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
946
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
947
+ type: "dropzone"
948
+ })
949
+ })
1045
950
  })
1046
951
  });
1047
952
  }
1048
- return setupZone(data, action.zone);
953
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1049
954
  }
1050
955
  if (action.type === "unregisterZone") {
1051
- const _zones = __spreadValues({}, data.zones || {});
956
+ const _zones = __spreadValues({}, state.data.zones || {});
957
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
1052
958
  if (_zones[action.zone]) {
1053
959
  zoneCache[action.zone] = _zones[action.zone];
1054
960
  delete _zones[action.zone];
1055
961
  }
1056
- return __spreadProps(__spreadValues({}, data), { zones: _zones });
962
+ delete zoneIndex[action.zone];
963
+ return __spreadProps(__spreadValues({}, state), {
964
+ data: __spreadProps(__spreadValues({}, state.data), {
965
+ zones: _zones
966
+ }),
967
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
968
+ zones: zoneIndex
969
+ })
970
+ });
1057
971
  }
1058
972
  if (action.type === "setData") {
1059
973
  if (typeof action.data === "object") {
1060
- return __spreadValues(__spreadValues({}, data), action.data);
974
+ console.warn(
975
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
976
+ );
977
+ return walkTree(
978
+ __spreadProps(__spreadValues({}, state), {
979
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
980
+ }),
981
+ appStore.config
982
+ );
1061
983
  }
1062
- return __spreadValues(__spreadValues({}, data), action.data(data));
1063
- }
1064
- return data;
1065
- }
1066
-
1067
- // ../core/reducer/state.ts
1068
- init_react_import();
1069
- var reduceUi = (ui, action) => {
984
+ return walkTree(
985
+ __spreadProps(__spreadValues({}, state), {
986
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
987
+ }),
988
+ appStore.config
989
+ );
990
+ }
1070
991
  if (action.type === "setUi") {
1071
992
  if (typeof action.ui === "object") {
1072
- return __spreadValues(__spreadValues({}, ui), action.ui);
993
+ return __spreadProps(__spreadValues({}, state), {
994
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
995
+ });
1073
996
  }
1074
- return __spreadValues(__spreadValues({}, ui), action.ui(ui));
1075
- }
1076
- if (action.type === "duplicate") {
1077
- return __spreadProps(__spreadValues({}, ui), {
1078
- itemSelector: { index: action.sourceIndex + 1, zone: action.sourceZone }
1079
- });
1080
- }
1081
- if (action.type === "remove") {
1082
- return __spreadProps(__spreadValues({}, ui), {
1083
- itemSelector: null
997
+ return __spreadProps(__spreadValues({}, state), {
998
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1084
999
  });
1085
1000
  }
1086
- return ui;
1087
- };
1001
+ return state;
1002
+ }
1088
1003
 
1089
1004
  // ../core/reducer/actions.tsx
1090
1005
  init_react_import();
@@ -1107,25 +1022,15 @@ function storeInterceptor(reducer, record, onAction) {
1107
1022
  return newAppState;
1108
1023
  };
1109
1024
  }
1110
- var setAction = (state, action) => {
1111
- if (typeof action.state === "object") {
1112
- return __spreadValues(__spreadValues({}, state), action.state);
1113
- }
1114
- return __spreadValues(__spreadValues({}, state), action.state(state));
1115
- };
1116
1025
  function createReducer({
1117
- config,
1118
1026
  record,
1119
- onAction
1027
+ onAction,
1028
+ appStore
1120
1029
  }) {
1121
1030
  return storeInterceptor(
1122
1031
  (state, action) => {
1123
- const data = reduceData(state.data, action, config);
1124
- const ui = reduceUi(state.ui, action);
1125
- if (action.type === "set") {
1126
- return setAction(state, action);
1127
- }
1128
- return { data, ui };
1032
+ const result = reduce(state, action, appStore);
1033
+ return result;
1129
1034
  },
1130
1035
  record,
1131
1036
  onAction
@@ -1140,20 +1045,16 @@ var defaultViewports = [
1140
1045
  { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1141
1046
  ];
1142
1047
 
1143
- // ../../node_modules/zustand/esm/index.mjs
1144
- init_react_import();
1145
-
1146
1048
  // ../../node_modules/zustand/esm/vanilla.mjs
1147
1049
  init_react_import();
1148
- var import_meta = {};
1149
1050
  var createStoreImpl = (createState) => {
1150
1051
  let state;
1151
1052
  const listeners = /* @__PURE__ */ new Set();
1152
- const setState = (partial, replace2) => {
1053
+ const setState = (partial, replace) => {
1153
1054
  const nextState = typeof partial === "function" ? partial(state) : partial;
1154
1055
  if (!Object.is(nextState, state)) {
1155
1056
  const previousState = state;
1156
- state = (replace2 != null ? replace2 : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
1057
+ state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
1157
1058
  listeners.forEach((listener) => listener(state, previousState));
1158
1059
  }
1159
1060
  };
@@ -1163,53 +1064,28 @@ var createStoreImpl = (createState) => {
1163
1064
  listeners.add(listener);
1164
1065
  return () => listeners.delete(listener);
1165
1066
  };
1166
- const destroy = () => {
1167
- if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
1168
- console.warn(
1169
- "[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."
1170
- );
1171
- }
1172
- listeners.clear();
1173
- };
1174
- const api = { setState, getState, getInitialState, subscribe, destroy };
1067
+ const api = { setState, getState, getInitialState, subscribe };
1175
1068
  const initialState = state = createState(setState, getState, api);
1176
1069
  return api;
1177
1070
  };
1178
1071
  var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
1179
1072
 
1180
- // ../../node_modules/zustand/esm/index.mjs
1181
- var import_with_selector = __toESM(require_with_selector(), 1);
1182
- import ReactExports from "react";
1183
- var import_meta2 = {};
1184
- var { useDebugValue } = ReactExports;
1185
- var { useSyncExternalStoreWithSelector } = import_with_selector.default;
1186
- var didWarnAboutEqualityFn = false;
1073
+ // ../../node_modules/zustand/esm/react.mjs
1074
+ init_react_import();
1075
+ import React2 from "react";
1187
1076
  var identity = (arg) => arg;
1188
- function useStore(api, selector = identity, equalityFn) {
1189
- if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && equalityFn && !didWarnAboutEqualityFn) {
1190
- console.warn(
1191
- "[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"
1192
- );
1193
- didWarnAboutEqualityFn = true;
1194
- }
1195
- const slice = useSyncExternalStoreWithSelector(
1077
+ function useStore(api, selector = identity) {
1078
+ const slice = React2.useSyncExternalStore(
1196
1079
  api.subscribe,
1197
- api.getState,
1198
- api.getServerState || api.getInitialState,
1199
- selector,
1200
- equalityFn
1080
+ () => selector(api.getState()),
1081
+ () => selector(api.getInitialState())
1201
1082
  );
1202
- useDebugValue(slice);
1083
+ React2.useDebugValue(slice);
1203
1084
  return slice;
1204
1085
  }
1205
1086
  var createImpl = (createState) => {
1206
- if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && typeof createState !== "function") {
1207
- console.warn(
1208
- "[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`."
1209
- );
1210
- }
1211
- const api = typeof createState === "function" ? createStore(createState) : createState;
1212
- const useBoundStore = (selector, equalityFn) => useStore(api, selector, equalityFn);
1087
+ const api = createStore(createState);
1088
+ const useBoundStore = (selector) => useStore(api, selector);
1213
1089
  Object.assign(useBoundStore, api);
1214
1090
  return useBoundStore;
1215
1091
  };
@@ -1242,206 +1118,6 @@ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1242
1118
  };
1243
1119
  var subscribeWithSelector = subscribeWithSelectorImpl;
1244
1120
 
1245
- // ../core/lib/resolve-data.ts
1246
- init_react_import();
1247
-
1248
- // ../core/lib/resolve-component-data.ts
1249
- init_react_import();
1250
-
1251
- // ../core/lib/get-changed.ts
1252
- init_react_import();
1253
- var getChanged = (newItem, oldItem) => {
1254
- return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1255
- const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1256
- const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1257
- return __spreadProps(__spreadValues({}, acc), {
1258
- [item]: oldItemProps[item] !== newItemProps[item]
1259
- });
1260
- }, {}) : {};
1261
- };
1262
-
1263
- // ../core/lib/resolve-component-data.ts
1264
- var cache = { lastChange: {} };
1265
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd) {
1266
- const configForItem = config.components[item.type];
1267
- if (configForItem.resolveData) {
1268
- const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
1269
- if (item && item === oldItem) {
1270
- return resolved;
1271
- }
1272
- const changed = getChanged(item, oldItem);
1273
- if (onResolveStart) {
1274
- onResolveStart(item);
1275
- }
1276
- const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1277
- changed,
1278
- lastData: oldItem,
1279
- metadata
1280
- });
1281
- const resolvedItem = __spreadProps(__spreadValues({}, item), {
1282
- props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1283
- });
1284
- if (Object.keys(readOnly).length) {
1285
- resolvedItem.readOnly = readOnly;
1286
- }
1287
- cache.lastChange[item.props.id] = {
1288
- item,
1289
- resolved: resolvedItem
1290
- };
1291
- if (onResolveEnd) {
1292
- onResolveEnd(resolvedItem);
1293
- }
1294
- return resolvedItem;
1295
- }
1296
- return item;
1297
- });
1298
-
1299
- // ../core/lib/apply-dynamic-props.ts
1300
- init_react_import();
1301
- var applyDynamicProps = (data, dynamicProps, rootData) => {
1302
- return __spreadProps(__spreadValues({}, data), {
1303
- root: rootData ? __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}) : data.root,
1304
- content: data.content.map((item) => {
1305
- return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1306
- }),
1307
- zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
1308
- return __spreadProps(__spreadValues({}, acc), {
1309
- [zoneKey]: data.zones[zoneKey].map((item) => {
1310
- return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1311
- })
1312
- });
1313
- }, {})
1314
- });
1315
- };
1316
-
1317
- // ../core/lib/resolve-root-data.ts
1318
- init_react_import();
1319
- var cache2 = {};
1320
- function resolveRootData(data, config, metadata) {
1321
- return __async(this, null, function* () {
1322
- var _a, _b, _c, _d, _e;
1323
- if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
1324
- if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
1325
- return cache2.lastChange.resolved;
1326
- }
1327
- const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
1328
- const rootWithProps = data.root;
1329
- const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
1330
- changed,
1331
- lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {},
1332
- metadata: metadata || {}
1333
- });
1334
- cache2.lastChange = {
1335
- original: data.root,
1336
- resolved: resolvedRoot
1337
- };
1338
- return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
1339
- props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
1340
- });
1341
- }
1342
- return data.root;
1343
- });
1344
- }
1345
-
1346
- // ../core/lib/flatten-data.ts
1347
- init_react_import();
1348
- var flattenData = (data) => {
1349
- return Object.keys(data.zones || {}).reduce(
1350
- (acc, zone) => [...acc, ...data.zones[zone]],
1351
- data.content
1352
- );
1353
- };
1354
-
1355
- // ../core/lib/resolve-data.ts
1356
- var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1357
- var resolveData = (newAppState, appStoreData) => {
1358
- const {
1359
- state: appState,
1360
- config,
1361
- dispatch,
1362
- resolveDataRuns,
1363
- setComponentLoading,
1364
- unsetComponentLoading,
1365
- metadata,
1366
- permissions
1367
- } = appStoreData;
1368
- const deferredSetStates = {};
1369
- const _setComponentLoading = (id, loading, defer = 0) => {
1370
- if (deferredSetStates[id]) {
1371
- clearTimeout(deferredSetStates[id]);
1372
- delete deferredSetStates[id];
1373
- }
1374
- deferredSetStates[id] = setTimeout(() => {
1375
- if (loading) {
1376
- setComponentLoading(id);
1377
- } else {
1378
- unsetComponentLoading(id);
1379
- }
1380
- delete deferredSetStates[id];
1381
- }, defer);
1382
- };
1383
- const runResolvers = () => __async(void 0, null, function* () {
1384
- const newData = newAppState.data;
1385
- const flatContent = flattenData(newData).filter(
1386
- (item) => {
1387
- var _a;
1388
- return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
1389
- }
1390
- );
1391
- const applyIfChange = (dynamicDataMap, dynamicRoot) => {
1392
- const processed = applyDynamicProps(
1393
- __spreadValues({}, appState.data),
1394
- dynamicDataMap,
1395
- dynamicRoot
1396
- );
1397
- const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
1398
- const containsChanges = !(0, import_fast_deep_equal.default)(appState, processedAppState);
1399
- if (containsChanges) {
1400
- dispatch({
1401
- type: "set",
1402
- state: (prev) => __spreadProps(__spreadValues({}, prev), {
1403
- data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
1404
- ui: resolveDataRuns > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
1405
- }),
1406
- recordHistory: resolveDataRuns > 0
1407
- });
1408
- }
1409
- };
1410
- const promises = [];
1411
- promises.push(
1412
- (() => __async(void 0, null, function* () {
1413
- _setComponentLoading("puck-root", true, 50);
1414
- const dynamicRoot = yield resolveRootData(newData, config, metadata);
1415
- applyIfChange({}, dynamicRoot);
1416
- _setComponentLoading("puck-root", false);
1417
- }))()
1418
- );
1419
- flatContent.forEach((item) => {
1420
- promises.push(
1421
- (() => __async(void 0, null, function* () {
1422
- permissions.resolvePermissions({ item }, true);
1423
- const dynamicData = yield resolveComponentData(
1424
- item,
1425
- config,
1426
- metadata,
1427
- (item2) => {
1428
- _setComponentLoading(item2.props.id, true, 50);
1429
- },
1430
- (item2) => {
1431
- deferredSetStates[item2.props.id];
1432
- _setComponentLoading(item2.props.id, false);
1433
- }
1434
- );
1435
- const dynamicDataMap = { [item.props.id]: dynamicData };
1436
- applyIfChange(dynamicDataMap);
1437
- }))()
1438
- );
1439
- });
1440
- yield Promise.all(promises);
1441
- });
1442
- return runResolvers();
1443
- };
1444
-
1445
1121
  // ../core/store/index.ts
1446
1122
  import { createContext, useContext } from "react";
1447
1123
 
@@ -1559,31 +1235,14 @@ var createHistorySlice = (set, get) => {
1559
1235
 
1560
1236
  // ../core/store/slices/nodes.ts
1561
1237
  init_react_import();
1562
- var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
1563
- import { useEffect as useEffect3 } from "react";
1564
- var partialDeepEqual = (newItem, existingItem) => {
1565
- const filteredExistingItem = Object.keys(newItem).reduce(
1566
- (acc, key) => __spreadProps(__spreadValues({}, acc), { [key]: existingItem[key] }),
1567
- {}
1568
- );
1569
- return (0, import_fast_deep_equal2.default)(newItem, filteredExistingItem);
1570
- };
1571
1238
  var createNodesSlice = (set, get) => ({
1572
1239
  nodes: {},
1573
1240
  registerNode: (id, node) => {
1574
1241
  const s = get().nodes;
1575
- if (s.nodes[id] && partialDeepEqual(node, s.nodes[id])) {
1576
- return;
1577
- }
1578
1242
  const emptyNode = {
1579
1243
  id,
1580
1244
  methods: { sync: () => null },
1581
- data: { props: { id }, type: "unknown" },
1582
- parentId: "",
1583
- zone: "",
1584
- path: [],
1585
- element: null,
1586
- index: -1
1245
+ element: null
1587
1246
  };
1588
1247
  const existingNode = s.nodes[id];
1589
1248
  set({
@@ -1613,36 +1272,66 @@ var createNodesSlice = (set, get) => ({
1613
1272
 
1614
1273
  // ../core/store/slices/permissions.ts
1615
1274
  init_react_import();
1616
- import { useEffect as useEffect4 } from "react";
1275
+ import { useEffect as useEffect3 } from "react";
1276
+
1277
+ // ../core/lib/flatten-data.ts
1278
+ init_react_import();
1279
+ var flattenData = (state, config) => {
1280
+ const data = [];
1281
+ walkTree(
1282
+ state,
1283
+ config,
1284
+ (content) => content,
1285
+ (item) => {
1286
+ data.push(item);
1287
+ return null;
1288
+ }
1289
+ );
1290
+ return data;
1291
+ };
1292
+
1293
+ // ../core/lib/get-changed.ts
1294
+ init_react_import();
1295
+ var getChanged = (newItem, oldItem) => {
1296
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1297
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1298
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1299
+ return __spreadProps(__spreadValues({}, acc), {
1300
+ [item]: oldItemProps[item] !== newItemProps[item]
1301
+ });
1302
+ }, {}) : {};
1303
+ };
1304
+
1305
+ // ../core/store/slices/permissions.ts
1617
1306
  var createPermissionsSlice = (set, get) => {
1618
1307
  const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1619
- const { state, permissions } = get();
1620
- const { cache: cache3, globalPermissions } = permissions;
1308
+ const { state, permissions, config } = get();
1309
+ const { cache: cache2, globalPermissions } = permissions;
1621
1310
  const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1622
1311
  var _a, _b, _c;
1623
1312
  const {
1624
- config,
1313
+ config: config2,
1625
1314
  state: appState,
1626
1315
  setComponentLoading,
1627
1316
  unsetComponentLoading
1628
1317
  } = get();
1629
- const componentConfig = item2.type === "root" ? config.root : config.components[item2.type];
1318
+ const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1630
1319
  if (!componentConfig) {
1631
1320
  return;
1632
1321
  }
1633
1322
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1634
1323
  if (componentConfig.resolvePermissions) {
1635
- const changed = getChanged(item2, (_a = cache3[item2.props.id]) == null ? void 0 : _a.lastData);
1324
+ const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1636
1325
  if (Object.values(changed).some((el) => el === true) || force2) {
1637
1326
  setComponentLoading(item2.props.id);
1638
1327
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1639
1328
  item2,
1640
1329
  {
1641
1330
  changed,
1642
- lastPermissions: ((_b = cache3[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1331
+ lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1643
1332
  permissions: initialPermissions,
1644
1333
  appState,
1645
- lastData: ((_c = cache3[item2.props.id]) == null ? void 0 : _c.lastData) || null
1334
+ lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1646
1335
  }
1647
1336
  );
1648
1337
  const latest = get().permissions;
@@ -1678,14 +1367,14 @@ var createPermissionsSlice = (set, get) => {
1678
1367
  if (item) {
1679
1368
  yield resolveDataForItem(item, force);
1680
1369
  } else if (type) {
1681
- flattenData(state.data).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1370
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1682
1371
  yield resolveDataForItem(item2, force);
1683
1372
  }));
1684
1373
  } else if (root) {
1685
1374
  resolveDataForRoot(force);
1686
1375
  } else {
1687
1376
  resolveDataForRoot(force);
1688
- flattenData(state.data).map((item2) => __async(void 0, null, function* () {
1377
+ flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1689
1378
  yield resolveDataForItem(item2, force);
1690
1379
  }));
1691
1380
  }
@@ -1727,8 +1416,8 @@ var createPermissionsSlice = (set, get) => {
1727
1416
 
1728
1417
  // ../core/store/slices/fields.ts
1729
1418
  init_react_import();
1730
- import { useCallback, useEffect as useEffect5 } from "react";
1731
- var createFieldsStore = (_set, _get) => {
1419
+ import { useCallback, useEffect as useEffect4 } from "react";
1420
+ var createFieldsSlice = (_set, _get) => {
1732
1421
  return {
1733
1422
  fields: {},
1734
1423
  loading: false,
@@ -1736,6 +1425,106 @@ var createFieldsStore = (_set, _get) => {
1736
1425
  };
1737
1426
  };
1738
1427
 
1428
+ // ../core/lib/resolve-component-data.ts
1429
+ init_react_import();
1430
+
1431
+ // ../core/lib/map-slots.ts
1432
+ init_react_import();
1433
+ function mapSlots(item, map, recursive = true, isSlot2) {
1434
+ return __async(this, null, function* () {
1435
+ const props = __spreadValues({}, item.props);
1436
+ yield forEachSlot(
1437
+ item,
1438
+ (_parentId, propName, content) => __async(this, null, function* () {
1439
+ const mappedContent = recursive ? yield Promise.all(
1440
+ content.map((item2) => __async(this, null, function* () {
1441
+ return yield mapSlots(item2, map, recursive, isSlot2);
1442
+ }))
1443
+ ) : content;
1444
+ props[propName] = yield map(mappedContent, propName);
1445
+ }),
1446
+ false,
1447
+ isSlot2
1448
+ );
1449
+ return __spreadProps(__spreadValues({}, item), { props });
1450
+ });
1451
+ }
1452
+
1453
+ // ../core/lib/resolve-component-data.ts
1454
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1455
+ var cache = { lastChange: {} };
1456
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
1457
+ const configForItem = "type" in item ? config.components[item.type] : config.root;
1458
+ if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
1459
+ const id = "id" in item.props ? item.props.id : "root";
1460
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1461
+ if (item && item === oldItem) {
1462
+ return resolved;
1463
+ }
1464
+ const changed = getChanged(item, oldItem);
1465
+ if (onResolveStart) {
1466
+ onResolveStart(item);
1467
+ }
1468
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1469
+ changed,
1470
+ lastData: oldItem,
1471
+ metadata,
1472
+ trigger
1473
+ });
1474
+ let resolvedItem = __spreadProps(__spreadValues({}, item), {
1475
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1476
+ });
1477
+ if (recursive) {
1478
+ resolvedItem = yield mapSlots(resolvedItem, (content) => __async(void 0, null, function* () {
1479
+ return Promise.all(
1480
+ content.map(
1481
+ (childItem) => __async(void 0, null, function* () {
1482
+ return (yield resolveComponentData(
1483
+ childItem,
1484
+ config,
1485
+ metadata,
1486
+ onResolveStart,
1487
+ onResolveEnd,
1488
+ trigger,
1489
+ false
1490
+ )).node;
1491
+ })
1492
+ )
1493
+ );
1494
+ }));
1495
+ }
1496
+ if (Object.keys(readOnly).length) {
1497
+ resolvedItem.readOnly = readOnly;
1498
+ }
1499
+ cache.lastChange[id] = {
1500
+ item,
1501
+ resolved: resolvedItem
1502
+ };
1503
+ if (onResolveEnd) {
1504
+ onResolveEnd(resolvedItem);
1505
+ }
1506
+ return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
1507
+ }
1508
+ return { node: item, didChange: false };
1509
+ });
1510
+
1511
+ // ../core/lib/to-root.ts
1512
+ init_react_import();
1513
+ var toRoot = (item) => {
1514
+ if ("type" in item && item.type !== "root") {
1515
+ throw new Error("Converting non-root item to root.");
1516
+ }
1517
+ const { readOnly } = item;
1518
+ if (item.props) {
1519
+ if ("id" in item.props) {
1520
+ const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
1521
+ return { props, readOnly };
1522
+ }
1523
+ return { props: item.props, readOnly };
1524
+ }
1525
+ return { props: {}, readOnly };
1526
+ };
1527
+
1739
1528
  // ../core/store/index.ts
1740
1529
  var defaultAppState = {
1741
1530
  data: { content: [], root: {}, zones: {} },
@@ -1756,6 +1545,10 @@ var defaultAppState = {
1756
1545
  controlsVisible: true
1757
1546
  },
1758
1547
  field: { focus: null }
1548
+ },
1549
+ indexes: {
1550
+ nodes: {},
1551
+ zones: {}
1759
1552
  }
1760
1553
  };
1761
1554
  var defaultPageFields = {
@@ -1778,7 +1571,7 @@ var createAppStore = (initialAppStore) => create()(
1778
1571
  iframe: {},
1779
1572
  metadata: {}
1780
1573
  }, initialAppStore), {
1781
- fields: createFieldsStore(set, get),
1574
+ fields: createFieldsSlice(set, get),
1782
1575
  history: createHistorySlice(set, get),
1783
1576
  nodes: createNodesSlice(set, get),
1784
1577
  permissions: createPermissionsSlice(set, get),
@@ -1791,55 +1584,141 @@ var createAppStore = (initialAppStore) => create()(
1791
1584
  dispatch: (action) => set((s) => {
1792
1585
  var _a, _b;
1793
1586
  const { record } = get().history;
1794
- const dispatch = createReducer({ config: s.config, record });
1587
+ const dispatch = createReducer({
1588
+ record,
1589
+ appStore: s
1590
+ });
1795
1591
  const state = dispatch(s.state, action);
1796
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1592
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1797
1593
  (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1798
1594
  return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1799
1595
  }),
1800
1596
  setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1801
1597
  setStatus: (status) => set({ status }),
1802
1598
  setComponentState: (componentState) => set({ componentState }),
1803
- setComponentLoading: (id) => {
1804
- var _a;
1805
- const { setComponentState, componentState } = get();
1806
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1807
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1808
- loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1599
+ pendingComponentLoads: {},
1600
+ setComponentLoading: (id, loading = true, defer = 0) => {
1601
+ const { setComponentState, pendingComponentLoads } = get();
1602
+ const thisPendingComponentLoads = __spreadValues({}, pendingComponentLoads);
1603
+ const setLoading = () => {
1604
+ var _a;
1605
+ const { componentState } = get();
1606
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1607
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1608
+ loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1609
+ })
1610
+ }));
1611
+ };
1612
+ const unsetLoading = () => {
1613
+ var _a;
1614
+ const { componentState } = get();
1615
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1616
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1617
+ loadingCount: Math.max(
1618
+ (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1619
+ 0
1620
+ )
1621
+ })
1622
+ }));
1623
+ };
1624
+ if (thisPendingComponentLoads[id]) {
1625
+ clearTimeout(thisPendingComponentLoads[id]);
1626
+ delete thisPendingComponentLoads[id];
1627
+ set({ pendingComponentLoads: thisPendingComponentLoads });
1628
+ }
1629
+ const timeout = setTimeout(() => {
1630
+ if (loading) {
1631
+ setLoading();
1632
+ } else {
1633
+ unsetLoading();
1634
+ }
1635
+ delete thisPendingComponentLoads[id];
1636
+ set({ pendingComponentLoads: thisPendingComponentLoads });
1637
+ }, defer);
1638
+ set({
1639
+ pendingComponentLoads: __spreadProps(__spreadValues({}, thisPendingComponentLoads), {
1640
+ [id]: timeout
1809
1641
  })
1810
- }));
1642
+ });
1811
1643
  },
1812
1644
  unsetComponentLoading: (id) => {
1813
- var _a;
1814
- const { setComponentState, componentState } = get();
1815
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1816
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1817
- loadingCount: Math.max(
1818
- (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1819
- 0
1820
- )
1821
- })
1822
- }));
1645
+ const { setComponentLoading } = get();
1646
+ setComponentLoading(id, false);
1823
1647
  },
1824
1648
  // Helper
1825
1649
  setUi: (ui, recordHistory) => set((s) => {
1826
1650
  const dispatch = createReducer({
1827
- config: s.config,
1828
1651
  record: () => {
1829
- }
1652
+ },
1653
+ appStore: s
1830
1654
  });
1831
1655
  const state = dispatch(s.state, {
1832
1656
  type: "setUi",
1833
1657
  ui,
1834
1658
  recordHistory
1835
1659
  });
1836
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1660
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1837
1661
  return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1838
1662
  }),
1839
- resolveDataRuns: 0,
1840
- resolveData: (newAppState) => set((s) => {
1841
- resolveData(newAppState, get());
1842
- return __spreadProps(__spreadValues({}, s), { resolveDataRuns: s.resolveDataRuns + 1 });
1663
+ // resolveDataRuns: 0,
1664
+ // resolveData: (newAppState) =>
1665
+ // set((s) => {
1666
+ // resolveData(newAppState, get);
1667
+ // return { ...s, resolveDataRuns: s.resolveDataRuns + 1 };
1668
+ // }),
1669
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1670
+ const { config, metadata, setComponentLoading } = get();
1671
+ return yield resolveComponentData(
1672
+ componentData,
1673
+ config,
1674
+ metadata,
1675
+ (item) => setComponentLoading(
1676
+ "id" in item.props ? item.props.id : "root",
1677
+ true,
1678
+ 50
1679
+ ),
1680
+ (item) => setComponentLoading(
1681
+ "id" in item.props ? item.props.id : "root",
1682
+ false,
1683
+ 0
1684
+ ),
1685
+ trigger
1686
+ );
1687
+ }),
1688
+ resolveAndCommitData: () => __async(void 0, null, function* () {
1689
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1690
+ walkTree(
1691
+ state,
1692
+ config,
1693
+ (content) => content,
1694
+ (childItem) => {
1695
+ resolveComponentData2(childItem, "load").then((resolved) => {
1696
+ const { state: state2 } = get();
1697
+ const node = state2.indexes.nodes[resolved.node.props.id];
1698
+ if (node && resolved.didChange) {
1699
+ if (resolved.node.props.id === "root") {
1700
+ dispatch({
1701
+ type: "replaceRoot",
1702
+ root: toRoot(resolved.node)
1703
+ });
1704
+ } else {
1705
+ const zoneCompound = `${node.parentId}:${node.zone}`;
1706
+ const parentZone = state2.indexes.zones[zoneCompound];
1707
+ const index = parentZone.contentIds.indexOf(
1708
+ resolved.node.props.id
1709
+ );
1710
+ dispatch({
1711
+ type: "replace",
1712
+ data: resolved.node,
1713
+ destinationIndex: index,
1714
+ destinationZone: zoneCompound
1715
+ });
1716
+ }
1717
+ }
1718
+ });
1719
+ return childItem;
1720
+ }
1721
+ );
1843
1722
  })
1844
1723
  }))
1845
1724
  );
@@ -1861,12 +1740,12 @@ var useBreadcrumbs = (renderCount) => {
1861
1740
  const config = useAppStore((s) => s.config);
1862
1741
  const path = useAppStore((s) => {
1863
1742
  var _a;
1864
- return (_a = s.nodes.nodes[selectedId]) == null ? void 0 : _a.path;
1743
+ return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
1865
1744
  });
1866
1745
  const appStore = useAppStoreApi();
1867
1746
  return useMemo(() => {
1868
1747
  const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
1869
- var _a, _b;
1748
+ var _a, _b, _c;
1870
1749
  const [componentId] = zoneCompound.split(":");
1871
1750
  if (componentId === "root") {
1872
1751
  return {
@@ -1874,12 +1753,15 @@ var useBreadcrumbs = (renderCount) => {
1874
1753
  selector: null
1875
1754
  };
1876
1755
  }
1877
- const node = appStore.getState().nodes.nodes[componentId];
1878
- const label = node ? (_b = (_a = config.components[node.data.type]) == null ? void 0 : _a.label) != null ? _b : node.data.type : "Component";
1756
+ const node = appStore.getState().state.indexes.nodes[componentId];
1757
+ const parentId = node.path[node.path.length - 1];
1758
+ const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
1759
+ const index = contentIds.indexOf(componentId);
1760
+ const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
1879
1761
  return {
1880
1762
  label,
1881
1763
  selector: node ? {
1882
- index: node.index,
1764
+ index,
1883
1765
  zone: node.path[node.path.length - 1]
1884
1766
  } : null
1885
1767
  };
@@ -1900,6 +1782,12 @@ init_react_import();
1900
1782
  // ../core/lib/filter.ts
1901
1783
  init_react_import();
1902
1784
 
1785
+ // ../core/lib/reorder.ts
1786
+ init_react_import();
1787
+
1788
+ // ../core/lib/replace.ts
1789
+ init_react_import();
1790
+
1903
1791
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
1904
1792
  init_react_import();
1905
1793
  var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
@@ -2081,7 +1969,7 @@ var usePuck = createUsePuck();
2081
1969
  var HeadingAnalyzer = () => {
2082
1970
  const data = usePuck((s) => s.appState.data);
2083
1971
  const [hierarchy, setHierarchy] = useState([]);
2084
- useEffect6(() => {
1972
+ useEffect5(() => {
2085
1973
  const frame = getFrame();
2086
1974
  const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2087
1975
  if (!entry) return;
@@ -2194,50 +2082,6 @@ classnames/index.js:
2194
2082
  http://jedwatson.github.io/classnames
2195
2083
  *)
2196
2084
 
2197
- use-sync-external-store/cjs/use-sync-external-store-shim.production.js:
2198
- (**
2199
- * @license React
2200
- * use-sync-external-store-shim.production.js
2201
- *
2202
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2203
- *
2204
- * This source code is licensed under the MIT license found in the
2205
- * LICENSE file in the root directory of this source tree.
2206
- *)
2207
-
2208
- use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
2209
- (**
2210
- * @license React
2211
- * use-sync-external-store-shim.development.js
2212
- *
2213
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2214
- *
2215
- * This source code is licensed under the MIT license found in the
2216
- * LICENSE file in the root directory of this source tree.
2217
- *)
2218
-
2219
- use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js:
2220
- (**
2221
- * @license React
2222
- * use-sync-external-store-shim/with-selector.production.js
2223
- *
2224
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2225
- *
2226
- * This source code is licensed under the MIT license found in the
2227
- * LICENSE file in the root directory of this source tree.
2228
- *)
2229
-
2230
- use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js:
2231
- (**
2232
- * @license React
2233
- * use-sync-external-store-shim/with-selector.development.js
2234
- *
2235
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2236
- *
2237
- * This source code is licensed under the MIT license found in the
2238
- * LICENSE file in the root directory of this source tree.
2239
- *)
2240
-
2241
2085
  lucide-react/dist/esm/shared/src/utils.js:
2242
2086
  (**
2243
2087
  * @license lucide-react v0.468.0 - ISC