@measured/puck-plugin-heading-analyzer 0.19.0-canary.1918ad70 → 0.19.0-canary.1e8a3ae2

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
@@ -153,6 +153,120 @@ var require_classnames = __commonJS({
153
153
  }
154
154
  });
155
155
 
156
+ // ../../node_modules/flat/index.js
157
+ var require_flat = __commonJS({
158
+ "../../node_modules/flat/index.js"(exports2, module2) {
159
+ "use strict";
160
+ init_react_import();
161
+ module2.exports = flatten3;
162
+ flatten3.flatten = flatten3;
163
+ flatten3.unflatten = unflatten2;
164
+ function isBuffer(obj) {
165
+ return obj && obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
166
+ }
167
+ function keyIdentity(key) {
168
+ return key;
169
+ }
170
+ function flatten3(target, opts) {
171
+ opts = opts || {};
172
+ const delimiter = opts.delimiter || ".";
173
+ const maxDepth = opts.maxDepth;
174
+ const transformKey = opts.transformKey || keyIdentity;
175
+ const output = {};
176
+ function step(object, prev, currentDepth) {
177
+ currentDepth = currentDepth || 1;
178
+ Object.keys(object).forEach(function(key) {
179
+ const value = object[key];
180
+ const isarray = opts.safe && Array.isArray(value);
181
+ const type = Object.prototype.toString.call(value);
182
+ const isbuffer = isBuffer(value);
183
+ const isobject = type === "[object Object]" || type === "[object Array]";
184
+ const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
185
+ if (!isarray && !isbuffer && isobject && Object.keys(value).length && (!opts.maxDepth || currentDepth < maxDepth)) {
186
+ return step(value, newKey, currentDepth + 1);
187
+ }
188
+ output[newKey] = value;
189
+ });
190
+ }
191
+ step(target);
192
+ return output;
193
+ }
194
+ function unflatten2(target, opts) {
195
+ opts = opts || {};
196
+ const delimiter = opts.delimiter || ".";
197
+ const overwrite = opts.overwrite || false;
198
+ const transformKey = opts.transformKey || keyIdentity;
199
+ const result = {};
200
+ const isbuffer = isBuffer(target);
201
+ if (isbuffer || Object.prototype.toString.call(target) !== "[object Object]") {
202
+ return target;
203
+ }
204
+ function getkey(key) {
205
+ const parsedKey = Number(key);
206
+ return isNaN(parsedKey) || key.indexOf(".") !== -1 || opts.object ? key : parsedKey;
207
+ }
208
+ function addKeys(keyPrefix, recipient, target2) {
209
+ return Object.keys(target2).reduce(function(result2, key) {
210
+ result2[keyPrefix + delimiter + key] = target2[key];
211
+ return result2;
212
+ }, recipient);
213
+ }
214
+ function isEmpty(val) {
215
+ const type = Object.prototype.toString.call(val);
216
+ const isArray = type === "[object Array]";
217
+ const isObject = type === "[object Object]";
218
+ if (!val) {
219
+ return true;
220
+ } else if (isArray) {
221
+ return !val.length;
222
+ } else if (isObject) {
223
+ return !Object.keys(val).length;
224
+ }
225
+ }
226
+ target = Object.keys(target).reduce(function(result2, key) {
227
+ const type = Object.prototype.toString.call(target[key]);
228
+ const isObject = type === "[object Object]" || type === "[object Array]";
229
+ if (!isObject || isEmpty(target[key])) {
230
+ result2[key] = target[key];
231
+ return result2;
232
+ } else {
233
+ return addKeys(
234
+ key,
235
+ result2,
236
+ flatten3(target[key], opts)
237
+ );
238
+ }
239
+ }, {});
240
+ Object.keys(target).forEach(function(key) {
241
+ const split = key.split(delimiter).map(transformKey);
242
+ let key1 = getkey(split.shift());
243
+ let key2 = getkey(split[0]);
244
+ let recipient = result;
245
+ while (key2 !== void 0) {
246
+ if (key1 === "__proto__") {
247
+ return;
248
+ }
249
+ const type = Object.prototype.toString.call(recipient[key1]);
250
+ const isobject = type === "[object Object]" || type === "[object Array]";
251
+ if (!overwrite && !isobject && typeof recipient[key1] !== "undefined") {
252
+ return;
253
+ }
254
+ if (overwrite && !isobject || !overwrite && recipient[key1] == null) {
255
+ recipient[key1] = typeof key2 === "number" && !opts.object ? [] : {};
256
+ }
257
+ recipient = recipient[key1];
258
+ if (split.length > 0) {
259
+ key1 = getkey(split.shift());
260
+ key2 = getkey(split[0]);
261
+ }
262
+ }
263
+ recipient[key1] = unflatten2(target[key], opts);
264
+ });
265
+ return result;
266
+ }
267
+ }
268
+ });
269
+
156
270
  // ../../node_modules/fast-deep-equal/index.js
157
271
  var require_fast_deep_equal = __commonJS({
158
272
  "../../node_modules/fast-deep-equal/index.js"(exports2, module2) {
@@ -368,26 +482,16 @@ init_react_import();
368
482
  // ../core/reducer/index.ts
369
483
  init_react_import();
370
484
 
371
- // ../core/reducer/reduce.ts
485
+ // ../core/reducer/actions/set.ts
372
486
  init_react_import();
373
487
 
374
- // ../core/lib/insert.ts
488
+ // ../core/lib/data/walk-app-state.ts
375
489
  init_react_import();
376
- var insert = (list, index, item) => {
377
- const result = Array.from(list || []);
378
- result.splice(index, 0, item);
379
- return result;
380
- };
381
490
 
382
- // ../core/lib/remove.ts
491
+ // ../core/lib/data/for-related-zones.ts
383
492
  init_react_import();
384
- var remove = (list, index) => {
385
- const result = Array.from(list);
386
- result.splice(index, 1);
387
- return result;
388
- };
389
493
 
390
- // ../core/lib/setup-zone.ts
494
+ // ../core/lib/get-zone-id.ts
391
495
  init_react_import();
392
496
 
393
497
  // ../core/lib/root-droppable-id.ts
@@ -396,127 +500,7 @@ var rootAreaId = "root";
396
500
  var rootZone = "default-zone";
397
501
  var rootDroppableId = `${rootAreaId}:${rootZone}`;
398
502
 
399
- // ../core/lib/setup-zone.ts
400
- var setupZone = (data, zoneKey) => {
401
- if (zoneKey === rootDroppableId) {
402
- return data;
403
- }
404
- const newData = __spreadProps(__spreadValues({}, data), {
405
- zones: data.zones ? __spreadValues({}, data.zones) : {}
406
- });
407
- newData.zones[zoneKey] = newData.zones[zoneKey] || [];
408
- return newData;
409
- };
410
-
411
- // ../core/lib/get-item.ts
412
- init_react_import();
413
- function getItem(selector, state) {
414
- var _a, _b;
415
- const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
416
- return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
417
- }
418
-
419
- // ../core/lib/generate-id.ts
420
- init_react_import();
421
-
422
- // ../../node_modules/uuid/dist/esm-node/index.js
423
- init_react_import();
424
-
425
- // ../../node_modules/uuid/dist/esm-node/rng.js
426
- init_react_import();
427
- var import_crypto = __toESM(require("crypto"));
428
- var rnds8Pool = new Uint8Array(256);
429
- var poolPtr = rnds8Pool.length;
430
- function rng() {
431
- if (poolPtr > rnds8Pool.length - 16) {
432
- import_crypto.default.randomFillSync(rnds8Pool);
433
- poolPtr = 0;
434
- }
435
- return rnds8Pool.slice(poolPtr, poolPtr += 16);
436
- }
437
-
438
- // ../../node_modules/uuid/dist/esm-node/stringify.js
439
- init_react_import();
440
- var byteToHex = [];
441
- for (let i = 0; i < 256; ++i) {
442
- byteToHex.push((i + 256).toString(16).slice(1));
443
- }
444
- function unsafeStringify(arr, offset = 0) {
445
- 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]];
446
- }
447
-
448
- // ../../node_modules/uuid/dist/esm-node/v4.js
449
- init_react_import();
450
-
451
- // ../../node_modules/uuid/dist/esm-node/native.js
452
- init_react_import();
453
- var import_crypto2 = __toESM(require("crypto"));
454
- var native_default = {
455
- randomUUID: import_crypto2.default.randomUUID
456
- };
457
-
458
- // ../../node_modules/uuid/dist/esm-node/v4.js
459
- function v4(options, buf, offset) {
460
- if (native_default.randomUUID && !buf && !options) {
461
- return native_default.randomUUID();
462
- }
463
- options = options || {};
464
- const rnds = options.random || (options.rng || rng)();
465
- rnds[6] = rnds[6] & 15 | 64;
466
- rnds[8] = rnds[8] & 63 | 128;
467
- if (buf) {
468
- offset = offset || 0;
469
- for (let i = 0; i < 16; ++i) {
470
- buf[offset + i] = rnds[i];
471
- }
472
- return buf;
473
- }
474
- return unsafeStringify(rnds);
475
- }
476
- var v4_default = v4;
477
-
478
- // ../core/lib/generate-id.ts
479
- var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
480
-
481
- // ../core/lib/walk-tree.ts
482
- init_react_import();
483
-
484
- // ../core/lib/for-each-slot.ts
485
- init_react_import();
486
-
487
- // ../core/lib/is-slot.ts
488
- init_react_import();
489
- var isSlot = (prop) => {
490
- var _a, _b;
491
- return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
492
- };
493
-
494
- // ../core/lib/for-each-slot.ts
495
- var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, cb, recursive = false, isSlot2 = isSlot) {
496
- const props = item.props || {};
497
- const propKeys = Object.keys(props);
498
- for (let i = 0; i < propKeys.length; i++) {
499
- const propKey = propKeys[i];
500
- const itemType = "type" in item ? item.type : "root";
501
- if (isSlot2(itemType, propKey, props[propKey])) {
502
- const content = props[propKey];
503
- yield cb(props.id, propKey, content);
504
- if (recursive) {
505
- content.forEach(
506
- (childItem) => __async(void 0, null, function* () {
507
- return yield forEachSlot(childItem, cb, true, isSlot2);
508
- })
509
- );
510
- }
511
- }
512
- }
513
- });
514
-
515
- // ../core/lib/for-related-zones.ts
516
- init_react_import();
517
-
518
503
  // ../core/lib/get-zone-id.ts
519
- init_react_import();
520
504
  var getZoneId = (zoneCompound) => {
521
505
  if (!zoneCompound) {
522
506
  return [];
@@ -527,36 +511,178 @@ var getZoneId = (zoneCompound) => {
527
511
  return [rootDroppableId, zoneCompound];
528
512
  };
529
513
 
530
- // ../core/lib/for-related-zones.ts
514
+ // ../core/lib/data/for-related-zones.ts
531
515
  function forRelatedZones(item, data, cb, path = []) {
532
516
  Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
533
517
  const [parentId] = getZoneId(zoneCompound);
534
518
  if (parentId === item.props.id) {
535
- const newPath = [...path, zoneCompound];
536
- content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
537
519
  cb(path, zoneCompound, content);
538
520
  }
539
521
  });
540
522
  }
541
523
 
542
- // ../core/lib/strip-slots.ts
524
+ // ../core/lib/data/map-slots.ts
543
525
  init_react_import();
544
- var stripSlots = (data) => {
545
- return __spreadProps(__spreadValues({}, data), {
546
- props: Object.entries(data.props).reduce(
547
- (acc, [propKey, propVal]) => {
548
- if (isSlot(propVal)) {
549
- return acc;
550
- }
551
- return __spreadProps(__spreadValues({}, acc), { [propKey]: propVal });
552
- },
553
- { id: data.props.id }
554
- )
526
+
527
+ // ../core/lib/data/default-slots.ts
528
+ init_react_import();
529
+ var defaultSlots = (value, fields) => Object.keys(fields).reduce(
530
+ (acc, fieldName) => fields[fieldName].type === "slot" ? __spreadValues({ [fieldName]: [] }, acc) : acc,
531
+ value
532
+ );
533
+
534
+ // ../core/lib/data/map-slots.ts
535
+ var isPromise = (v) => !!v && typeof v.then === "function";
536
+ var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
537
+ var containsPromise = (arr) => arr.some(isPromise);
538
+ var walkField = ({
539
+ value,
540
+ fields,
541
+ map,
542
+ propKey = "",
543
+ propPath = "",
544
+ id = "",
545
+ config,
546
+ recurseSlots = false
547
+ }) => {
548
+ var _a, _b, _c;
549
+ if (((_a = fields[propKey]) == null ? void 0 : _a.type) === "slot") {
550
+ const content = value || [];
551
+ const mappedContent = recurseSlots ? content.map((el) => {
552
+ var _a2;
553
+ const componentConfig = config.components[el.type];
554
+ if (!componentConfig) {
555
+ throw new Error(`Could not find component config for ${el.type}`);
556
+ }
557
+ const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
558
+ return walkField({
559
+ value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
560
+ fields: fields2,
561
+ map,
562
+ id: el.props.id,
563
+ config,
564
+ recurseSlots
565
+ });
566
+ }) : content;
567
+ if (containsPromise(mappedContent)) {
568
+ return Promise.all(mappedContent);
569
+ }
570
+ return map(mappedContent, id, propPath, fields[propKey], propPath);
571
+ }
572
+ if (value && typeof value === "object") {
573
+ if (Array.isArray(value)) {
574
+ const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
575
+ if (!arrayFields) return value;
576
+ const newValue = value.map(
577
+ (el, idx) => walkField({
578
+ value: el,
579
+ fields: arrayFields,
580
+ map,
581
+ propKey,
582
+ propPath: `${propPath}[${idx}]`,
583
+ id,
584
+ config,
585
+ recurseSlots
586
+ })
587
+ );
588
+ if (containsPromise(newValue)) {
589
+ return Promise.all(newValue);
590
+ }
591
+ return newValue;
592
+ } else if ("$$typeof" in value) {
593
+ return value;
594
+ } else {
595
+ const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
596
+ return walkObject({
597
+ value,
598
+ fields: objectFields,
599
+ map,
600
+ id,
601
+ getPropPath: (k) => `${propPath}.${k}`,
602
+ config,
603
+ recurseSlots
604
+ });
605
+ }
606
+ }
607
+ return value;
608
+ };
609
+ var walkObject = ({
610
+ value,
611
+ fields,
612
+ map,
613
+ id,
614
+ getPropPath,
615
+ config,
616
+ recurseSlots
617
+ }) => {
618
+ const newProps = Object.entries(value).map(([k, v]) => {
619
+ const opts = {
620
+ value: v,
621
+ fields,
622
+ map,
623
+ propKey: k,
624
+ propPath: getPropPath(k),
625
+ id,
626
+ config,
627
+ recurseSlots
628
+ };
629
+ const newValue = walkField(opts);
630
+ if (isPromise(newValue)) {
631
+ return newValue.then((resolvedValue) => ({
632
+ [k]: resolvedValue
633
+ }));
634
+ }
635
+ return {
636
+ [k]: newValue
637
+ };
638
+ }, {});
639
+ if (containsPromise(newProps)) {
640
+ return Promise.all(newProps).then(flatten);
641
+ }
642
+ return flatten(newProps);
643
+ };
644
+ function mapSlots(item, map, config, recurseSlots = false) {
645
+ var _a, _b, _c, _d, _e;
646
+ const itemType = "type" in item ? item.type : "root";
647
+ const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
648
+ const newProps = walkObject({
649
+ value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
650
+ fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
651
+ map,
652
+ id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
653
+ getPropPath: (k) => k,
654
+ config,
655
+ recurseSlots
656
+ });
657
+ if (isPromise(newProps)) {
658
+ return newProps.then((resolvedProps) => __spreadProps(__spreadValues({}, item), {
659
+ props: resolvedProps
660
+ }));
661
+ }
662
+ return __spreadProps(__spreadValues({}, item), {
663
+ props: newProps
664
+ });
665
+ }
666
+
667
+ // ../core/lib/data/flatten-node.ts
668
+ init_react_import();
669
+ var import_flat = __toESM(require_flat());
670
+
671
+ // ../core/lib/data/strip-slots.ts
672
+ init_react_import();
673
+ var stripSlots = (data, config) => {
674
+ return mapSlots(data, () => null, config);
675
+ };
676
+
677
+ // ../core/lib/data/flatten-node.ts
678
+ var flattenNode = (node, config) => {
679
+ return __spreadProps(__spreadValues({}, node), {
680
+ props: (0, import_flat.flatten)(stripSlots(node, config).props)
555
681
  });
556
682
  };
557
683
 
558
- // ../core/lib/walk-tree.ts
559
- function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
684
+ // ../core/lib/data/walk-app-state.ts
685
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
560
686
  var _a;
561
687
  let newZones = {};
562
688
  const newZoneIndex = {};
@@ -597,11 +723,9 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
597
723
  const mappedItem = mapNodeOrSkip(item, path, index);
598
724
  if (!mappedItem) return item;
599
725
  const id = mappedItem.props.id;
600
- processRelatedZones(item, id, path);
601
- const newProps = __spreadValues({}, mappedItem.props);
602
- forEachSlot(
726
+ const newProps = __spreadProps(__spreadValues({}, mapSlots(
603
727
  mappedItem,
604
- (parentId2, slotId, content) => {
728
+ (content, parentId2, slotId) => {
605
729
  const zoneCompound = `${parentId2}:${slotId}`;
606
730
  const [_2, newContent2] = processContent(
607
731
  path,
@@ -610,27 +734,24 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
610
734
  "slot",
611
735
  parentId2
612
736
  );
613
- newProps[slotId] = newContent2;
737
+ return newContent2;
614
738
  },
615
- false,
616
- (itemType, propName, propValue) => {
617
- var _a2, _b;
618
- const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
619
- if (!configForComponent) return isSlot(propValue);
620
- return ((_b = (_a2 = configForComponent.fields) == null ? void 0 : _a2[propName]) == null ? void 0 : _b.type) === "slot";
621
- }
622
- );
739
+ config
740
+ ).props), {
741
+ id
742
+ });
743
+ processRelatedZones(item, id, path);
623
744
  const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
624
745
  const thisZoneCompound = path[path.length - 1];
625
746
  const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
626
747
  newNodeIndex[id] = {
627
748
  data: newItem,
628
- flatData: stripSlots(newItem),
749
+ flatData: flattenNode(newItem, config),
629
750
  path,
630
751
  parentId,
631
752
  zone
632
753
  };
633
- const finalData = newItem;
754
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
634
755
  if (newProps.id === "root") {
635
756
  delete finalData["type"];
636
757
  delete finalData.props["id"];
@@ -645,8 +766,12 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
645
766
  "root"
646
767
  );
647
768
  const processedContent = newContent;
769
+ const zonesAlreadyProcessed = Object.keys(newZones);
648
770
  Object.keys(zones || {}).forEach((zoneCompound) => {
649
771
  const [parentId] = zoneCompound.split(":");
772
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
773
+ return;
774
+ }
650
775
  const [_2, newContent2] = processContent(
651
776
  [rootDroppableId],
652
777
  zoneCompound,
@@ -670,7 +795,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
670
795
  return __spreadProps(__spreadValues({}, state), {
671
796
  data: {
672
797
  root,
673
- // 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.
674
798
  content: processedContent,
675
799
  zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
676
800
  },
@@ -681,60 +805,175 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
681
805
  });
682
806
  }
683
807
 
684
- // ../core/lib/deindex.ts
685
- init_react_import();
686
- var deindex = (state, componentData) => {
687
- let zones = __spreadValues({}, state.indexes.zones);
688
- let nodes = __spreadValues({}, state.indexes.nodes);
689
- const dindexRelatedZones = (item) => {
690
- forRelatedZones(item, state.data, (_path, zoneCompound, content) => {
691
- content.forEach((subItem) => {
692
- dindexChildren(subItem);
693
- delete nodes[subItem.props.id];
694
- });
695
- delete zones[zoneCompound];
696
- });
697
- };
698
- const dindexChildren = (item) => {
699
- forEachSlot(
700
- item,
701
- (parentId, slotId, content) => {
702
- const zoneCompound = `${parentId}:${slotId}`;
703
- delete zones[zoneCompound];
704
- content.forEach((item2) => {
705
- dindexRelatedZones(item2);
706
- delete nodes[item2.props.id];
707
- });
708
- },
709
- true
808
+ // ../core/reducer/actions/set.ts
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
+ return newState;
814
+ }
815
+ console.warn(
816
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
710
817
  );
711
- };
712
- dindexRelatedZones(componentData);
713
- dindexChildren(componentData);
714
- delete nodes[componentData.props.id];
715
- return { nodes, zones };
818
+ return walkAppState(newState, appStore.config);
819
+ }
820
+ return __spreadValues(__spreadValues({}, state), action.state(state));
716
821
  };
717
822
 
718
- // ../core/reducer/reduce.ts
719
- var zoneCache = {};
823
+ // ../core/reducer/actions/insert.ts
824
+ init_react_import();
825
+
826
+ // ../core/lib/data/insert.ts
827
+ init_react_import();
828
+ var insert = (list, index, item) => {
829
+ const result = Array.from(list || []);
830
+ result.splice(index, 0, item);
831
+ return result;
832
+ };
833
+
834
+ // ../core/lib/generate-id.ts
835
+ init_react_import();
836
+
837
+ // ../../node_modules/uuid/dist/esm-node/index.js
838
+ init_react_import();
839
+
840
+ // ../../node_modules/uuid/dist/esm-node/rng.js
841
+ init_react_import();
842
+ var import_crypto = __toESM(require("crypto"));
843
+ var rnds8Pool = new Uint8Array(256);
844
+ var poolPtr = rnds8Pool.length;
845
+ function rng() {
846
+ if (poolPtr > rnds8Pool.length - 16) {
847
+ import_crypto.default.randomFillSync(rnds8Pool);
848
+ poolPtr = 0;
849
+ }
850
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
851
+ }
852
+
853
+ // ../../node_modules/uuid/dist/esm-node/stringify.js
854
+ init_react_import();
855
+ var byteToHex = [];
856
+ for (let i = 0; i < 256; ++i) {
857
+ byteToHex.push((i + 256).toString(16).slice(1));
858
+ }
859
+ function unsafeStringify(arr, offset = 0) {
860
+ 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]];
861
+ }
862
+
863
+ // ../../node_modules/uuid/dist/esm-node/v4.js
864
+ init_react_import();
865
+
866
+ // ../../node_modules/uuid/dist/esm-node/native.js
867
+ init_react_import();
868
+ var import_crypto2 = __toESM(require("crypto"));
869
+ var native_default = {
870
+ randomUUID: import_crypto2.default.randomUUID
871
+ };
872
+
873
+ // ../../node_modules/uuid/dist/esm-node/v4.js
874
+ function v4(options, buf, offset) {
875
+ if (native_default.randomUUID && !buf && !options) {
876
+ return native_default.randomUUID();
877
+ }
878
+ options = options || {};
879
+ const rnds = options.random || (options.rng || rng)();
880
+ rnds[6] = rnds[6] & 15 | 64;
881
+ rnds[8] = rnds[8] & 63 | 128;
882
+ if (buf) {
883
+ offset = offset || 0;
884
+ for (let i = 0; i < 16; ++i) {
885
+ buf[offset + i] = rnds[i];
886
+ }
887
+ return buf;
888
+ }
889
+ return unsafeStringify(rnds);
890
+ }
891
+ var v4_default = v4;
892
+
893
+ // ../core/lib/generate-id.ts
894
+ var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
895
+
896
+ // ../core/lib/data/get-ids-for-parent.ts
897
+ init_react_import();
720
898
  var getIdsForParent = (zoneCompound, state) => {
721
899
  const [parentId] = zoneCompound.split(":");
722
900
  const node = state.indexes.nodes[parentId];
723
901
  return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
724
902
  };
725
- function insertAction(state, action, config) {
726
- const id = action.id || generateId(action.componentType);
727
- const emptyComponentData = {
728
- type: action.componentType,
729
- props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
730
- id
731
- })
903
+
904
+ // ../core/lib/data/populate-ids.ts
905
+ init_react_import();
906
+
907
+ // ../core/lib/data/walk-tree.ts
908
+ init_react_import();
909
+ function walkTree(data, config, callbackFn) {
910
+ var _a, _b;
911
+ const walkItem = (item) => {
912
+ return mapSlots(
913
+ item,
914
+ (content, parentId, propName) => {
915
+ var _a2;
916
+ return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
917
+ },
918
+ config,
919
+ true
920
+ );
921
+ };
922
+ if ("props" in data) {
923
+ return walkItem(data);
924
+ }
925
+ const _data = data;
926
+ const zones = (_a = _data.zones) != null ? _a : {};
927
+ const mappedContent = _data.content.map(walkItem);
928
+ return {
929
+ root: walkItem(_data.root),
930
+ content: (_b = callbackFn(mappedContent, {
931
+ parentId: "root",
932
+ propName: "default-zone"
933
+ })) != null ? _b : mappedContent,
934
+ zones: Object.keys(zones).reduce(
935
+ (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
936
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
937
+ }),
938
+ {}
939
+ )
732
940
  };
941
+ }
942
+
943
+ // ../core/lib/data/populate-ids.ts
944
+ var populateIds = (data, config, override = false) => {
945
+ const id = generateId(data.type);
946
+ return walkTree(
947
+ __spreadProps(__spreadValues({}, data), {
948
+ props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({}, data.props)
949
+ }),
950
+ config,
951
+ (contents) => contents.map((item) => {
952
+ const id2 = generateId(item.type);
953
+ return __spreadProps(__spreadValues({}, item), {
954
+ props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
955
+ });
956
+ })
957
+ );
958
+ };
959
+
960
+ // ../core/reducer/actions/insert.ts
961
+ function insertAction(state, action, appStore) {
962
+ const id = action.id || generateId(action.componentType);
963
+ const emptyComponentData = populateIds(
964
+ {
965
+ type: action.componentType,
966
+ props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
967
+ id
968
+ })
969
+ },
970
+ appStore.config
971
+ );
733
972
  const [parentId] = action.destinationZone.split(":");
734
973
  const idsInPath = getIdsForParent(action.destinationZone, state);
735
- return walkTree(
974
+ return walkAppState(
736
975
  state,
737
- config,
976
+ appStore.config,
738
977
  (content, zoneCompound) => {
739
978
  if (zoneCompound === action.destinationZone) {
740
979
  return insert(
@@ -745,16 +984,154 @@ function insertAction(state, action, config) {
745
984
  }
746
985
  return content;
747
986
  },
748
- (childItem) => {
987
+ (childItem, path) => {
749
988
  if (childItem.props.id === id || childItem.props.id === parentId) {
750
989
  return childItem;
990
+ } else if (idsInPath.includes(childItem.props.id)) {
991
+ return childItem;
992
+ } else if (path.includes(action.destinationZone)) {
993
+ return childItem;
994
+ }
995
+ return null;
996
+ }
997
+ );
998
+ }
999
+
1000
+ // ../core/reducer/actions/replace.ts
1001
+ init_react_import();
1002
+ var replaceAction = (state, action, appStore) => {
1003
+ const [parentId] = action.destinationZone.split(":");
1004
+ const idsInPath = getIdsForParent(action.destinationZone, state);
1005
+ const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
1006
+ const idChanged = originalId !== action.data.props.id;
1007
+ if (idChanged) {
1008
+ throw new Error(
1009
+ `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
1010
+ );
1011
+ }
1012
+ const data = populateIds(action.data, appStore.config);
1013
+ return walkAppState(
1014
+ state,
1015
+ appStore.config,
1016
+ (content, zoneCompound) => {
1017
+ const newContent = [...content];
1018
+ if (zoneCompound === action.destinationZone) {
1019
+ newContent[action.destinationIndex] = data;
1020
+ }
1021
+ return newContent;
1022
+ },
1023
+ (childItem, path) => {
1024
+ const pathIds = path.map((p) => p.split(":")[0]);
1025
+ if (childItem.props.id === data.props.id) {
1026
+ return data;
1027
+ } else if (childItem.props.id === parentId) {
1028
+ return childItem;
751
1029
  } else if (idsInPath.indexOf(childItem.props.id) > -1) {
752
1030
  return childItem;
1031
+ } else if (pathIds.indexOf(data.props.id) > -1) {
1032
+ return childItem;
1033
+ }
1034
+ return null;
1035
+ }
1036
+ );
1037
+ };
1038
+
1039
+ // ../core/reducer/actions/replace-root.ts
1040
+ init_react_import();
1041
+ var replaceRootAction = (state, action, appStore) => {
1042
+ return walkAppState(
1043
+ state,
1044
+ appStore.config,
1045
+ (content) => content,
1046
+ (childItem) => {
1047
+ if (childItem.props.id === "root") {
1048
+ return __spreadProps(__spreadValues({}, childItem), {
1049
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
1050
+ readOnly: action.root.readOnly
1051
+ });
1052
+ }
1053
+ return childItem;
1054
+ }
1055
+ );
1056
+ };
1057
+
1058
+ // ../core/reducer/actions/duplicate.ts
1059
+ init_react_import();
1060
+
1061
+ // ../core/lib/data/get-item.ts
1062
+ init_react_import();
1063
+ function getItem(selector, state) {
1064
+ var _a, _b;
1065
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
1066
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
1067
+ }
1068
+
1069
+ // ../core/reducer/actions/duplicate.ts
1070
+ function duplicateAction(state, action, appStore) {
1071
+ const item = getItem(
1072
+ { index: action.sourceIndex, zone: action.sourceZone },
1073
+ state
1074
+ );
1075
+ const idsInPath = getIdsForParent(action.sourceZone, state);
1076
+ const newItem = __spreadProps(__spreadValues({}, item), {
1077
+ props: __spreadProps(__spreadValues({}, item.props), {
1078
+ id: generateId(item.type)
1079
+ })
1080
+ });
1081
+ const modified = walkAppState(
1082
+ state,
1083
+ appStore.config,
1084
+ (content, zoneCompound) => {
1085
+ if (zoneCompound === action.sourceZone) {
1086
+ return insert(content, action.sourceIndex + 1, item);
1087
+ }
1088
+ return content;
1089
+ },
1090
+ (childItem, path, index) => {
1091
+ const zoneCompound = path[path.length - 1];
1092
+ const parents = path.map((p) => p.split(":")[0]);
1093
+ if (parents.indexOf(newItem.props.id) > -1) {
1094
+ return __spreadProps(__spreadValues({}, childItem), {
1095
+ props: __spreadProps(__spreadValues({}, childItem.props), {
1096
+ id: generateId(childItem.type)
1097
+ })
1098
+ });
1099
+ }
1100
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
1101
+ return newItem;
1102
+ }
1103
+ const [sourceZoneParent] = action.sourceZone.split(":");
1104
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
1105
+ return childItem;
753
1106
  }
754
1107
  return null;
755
1108
  }
756
1109
  );
1110
+ return __spreadProps(__spreadValues({}, modified), {
1111
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
1112
+ itemSelector: {
1113
+ index: action.sourceIndex + 1,
1114
+ zone: action.sourceZone
1115
+ }
1116
+ })
1117
+ });
757
1118
  }
1119
+
1120
+ // ../core/reducer/actions/reorder.ts
1121
+ init_react_import();
1122
+
1123
+ // ../core/reducer/actions/move.ts
1124
+ init_react_import();
1125
+
1126
+ // ../core/lib/data/remove.ts
1127
+ init_react_import();
1128
+ var remove = (list, index) => {
1129
+ const result = Array.from(list);
1130
+ result.splice(index, 1);
1131
+ return result;
1132
+ };
1133
+
1134
+ // ../core/reducer/actions/move.ts
758
1135
  var moveAction = (state, action, appStore) => {
759
1136
  if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
760
1137
  return state;
@@ -766,7 +1143,7 @@ var moveAction = (state, action, appStore) => {
766
1143
  if (!item) return state;
767
1144
  const idsInSourcePath = getIdsForParent(action.sourceZone, state);
768
1145
  const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
769
- return walkTree(
1146
+ return walkAppState(
770
1147
  state,
771
1148
  appStore.config,
772
1149
  (content, zoneCompound) => {
@@ -783,233 +1160,172 @@ var moveAction = (state, action, appStore) => {
783
1160
  }
784
1161
  return content;
785
1162
  },
786
- (childItem) => {
1163
+ (childItem, path) => {
787
1164
  const [sourceZoneParent] = action.sourceZone.split(":");
788
1165
  const [destinationZoneParent] = action.destinationZone.split(":");
789
1166
  const childId = childItem.props.id;
790
- if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1) {
1167
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
791
1168
  return childItem;
792
1169
  }
793
1170
  return null;
794
1171
  }
795
1172
  );
796
1173
  };
797
- var replaceAction = (state, action, appStore) => {
798
- const [parentId] = action.destinationZone.split(":");
799
- const idsInPath = getIdsForParent(action.destinationZone, state);
800
- return walkTree(
1174
+
1175
+ // ../core/reducer/actions/reorder.ts
1176
+ var reorderAction = (state, action, appStore) => {
1177
+ return moveAction(
1178
+ state,
1179
+ {
1180
+ type: "move",
1181
+ sourceIndex: action.sourceIndex,
1182
+ sourceZone: action.destinationZone,
1183
+ destinationIndex: action.destinationIndex,
1184
+ destinationZone: action.destinationZone
1185
+ },
1186
+ appStore
1187
+ );
1188
+ };
1189
+
1190
+ // ../core/reducer/actions/remove.ts
1191
+ init_react_import();
1192
+ var removeAction = (state, action, appStore) => {
1193
+ const item = getItem({ index: action.index, zone: action.zone }, state);
1194
+ const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
1195
+ (acc, [nodeId, nodeData]) => {
1196
+ const pathIds = nodeData.path.map((p) => p.split(":")[0]);
1197
+ if (pathIds.includes(item.props.id)) {
1198
+ return [...acc, nodeId];
1199
+ }
1200
+ return acc;
1201
+ },
1202
+ [item.props.id]
1203
+ );
1204
+ const newState = walkAppState(
801
1205
  state,
802
1206
  appStore.config,
803
- (content) => content,
804
- (childItem, path) => {
805
- const pathIds = path.map((p) => p.split(":")[0]);
806
- if (childItem.props.id === action.data.props.id) {
807
- return action.data;
808
- } else if (childItem.props.id === parentId) {
809
- return childItem;
810
- } else if (idsInPath.indexOf(childItem.props.id) > -1) {
811
- return childItem;
812
- } else if (pathIds.indexOf(action.data.props.id) > -1) {
813
- return childItem;
1207
+ (content, zoneCompound) => {
1208
+ if (zoneCompound === action.zone) {
1209
+ return remove(content, action.index);
814
1210
  }
815
- return null;
1211
+ return content;
816
1212
  }
817
1213
  );
818
- };
819
- var setAction = (state, action, appStore) => {
820
- if (typeof action.state === "object") {
821
- const newState = __spreadValues(__spreadValues({}, state), action.state);
822
- if (action.state.indexes) {
823
- console.warn(
824
- "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
825
- );
826
- return newState;
1214
+ Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
1215
+ const parentId = zoneCompound.split(":")[0];
1216
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
1217
+ delete newState.data.zones[zoneCompound];
827
1218
  }
828
- return walkTree(newState, appStore.config);
829
- }
830
- return __spreadValues(__spreadValues({}, state), action.state(state));
831
- };
832
- function reduce(state, action, appStore) {
833
- if (action.type === "set") {
834
- return setAction(state, action, appStore);
835
- }
836
- if (action.type === "insert") {
837
- return insertAction(state, action, appStore.config);
838
- }
839
- if (action.type === "replace") {
840
- return replaceAction(state, action, appStore);
841
- }
842
- if (action.type === "replaceRoot") {
843
- return walkTree(
844
- state,
845
- appStore.config,
846
- (content) => content,
847
- (childItem) => {
848
- if (childItem.props.id === "root") {
849
- return __spreadProps(__spreadValues({}, childItem), {
850
- props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
851
- readOnly: action.root.readOnly
852
- });
853
- }
854
- return childItem;
855
- }
856
- );
857
- }
858
- if (action.type === "duplicate") {
859
- const item = getItem(
860
- { index: action.sourceIndex, zone: action.sourceZone },
861
- state
862
- );
863
- const idsInPath = getIdsForParent(action.sourceZone, state);
864
- const newItem = __spreadProps(__spreadValues({}, item), {
865
- props: __spreadProps(__spreadValues({}, item.props), {
866
- id: generateId(item.type)
867
- })
868
- });
869
- const modified = walkTree(
870
- state,
871
- appStore.config,
872
- (content, zoneCompound) => {
873
- if (zoneCompound === action.sourceZone) {
874
- return insert(content, action.sourceIndex + 1, item);
875
- }
876
- return content;
877
- },
878
- (childItem, path, index) => {
879
- const zoneCompound = path[path.length - 1];
880
- const parents = path.map((p) => p.split(":")[0]);
881
- if (parents.indexOf(newItem.props.id) > -1) {
882
- return __spreadProps(__spreadValues({}, childItem), {
883
- props: __spreadProps(__spreadValues({}, childItem.props), {
884
- id: generateId(childItem.type)
885
- })
886
- });
887
- }
888
- if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
889
- return newItem;
890
- }
891
- const [sourceZoneParent] = action.sourceZone.split(":");
892
- if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
893
- return childItem;
894
- }
895
- return null;
896
- }
897
- );
898
- return __spreadProps(__spreadValues({}, modified), {
899
- ui: __spreadProps(__spreadValues({}, modified.ui), {
900
- itemSelector: {
901
- index: action.sourceIndex + 1,
902
- zone: action.sourceZone
903
- }
904
- })
905
- });
906
- }
907
- if (action.type === "reorder") {
908
- return moveAction(
909
- state,
910
- {
911
- type: "move",
912
- sourceIndex: action.sourceIndex,
913
- sourceZone: action.destinationZone,
914
- destinationIndex: action.destinationIndex,
915
- destinationZone: action.destinationZone
916
- },
917
- appStore
918
- );
919
- }
920
- if (action.type === "move") {
921
- return moveAction(state, action, appStore);
922
- }
923
- if (action.type === "remove") {
924
- const item = getItem({ index: action.index, zone: action.zone }, state);
925
- let deindexed = deindex(state, item);
926
- const [parentId] = action.zone.split(":");
927
- return walkTree(
928
- __spreadProps(__spreadValues({}, state), { indexes: deindexed }),
929
- appStore.config,
930
- (content, zoneCompound) => {
931
- if (zoneCompound === action.zone) {
932
- return remove(content, action.index);
933
- }
934
- return content;
935
- },
936
- (childItem, path) => {
937
- const parentIds = path.map((p) => p.split(":")[0]);
938
- if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
939
- return childItem;
940
- }
941
- return null;
942
- }
943
- );
944
- }
945
- if (action.type === "registerZone") {
946
- if (zoneCache[action.zone]) {
947
- return __spreadProps(__spreadValues({}, state), {
948
- data: __spreadProps(__spreadValues({}, state.data), {
949
- zones: __spreadProps(__spreadValues({}, state.data.zones), {
950
- [action.zone]: zoneCache[action.zone]
951
- })
952
- }),
953
- indexes: __spreadProps(__spreadValues({}, state.indexes), {
954
- zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
955
- [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
956
- contentIds: zoneCache[action.zone].map((item) => item.props.id),
957
- type: "dropzone"
958
- })
959
- })
960
- })
961
- });
1219
+ });
1220
+ Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
1221
+ const parentId = zoneCompound.split(":")[0];
1222
+ if (nodesToDelete.includes(parentId)) {
1223
+ delete newState.indexes.zones[zoneCompound];
962
1224
  }
963
- return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1225
+ });
1226
+ nodesToDelete.forEach((id) => {
1227
+ delete newState.indexes.nodes[id];
1228
+ });
1229
+ return newState;
1230
+ };
1231
+
1232
+ // ../core/reducer/actions/register-zone.ts
1233
+ init_react_import();
1234
+
1235
+ // ../core/lib/data/setup-zone.ts
1236
+ init_react_import();
1237
+ var setupZone = (data, zoneKey) => {
1238
+ if (zoneKey === rootDroppableId) {
1239
+ return data;
964
1240
  }
965
- if (action.type === "unregisterZone") {
966
- const _zones = __spreadValues({}, state.data.zones || {});
967
- const zoneIndex = __spreadValues({}, state.indexes.zones || {});
968
- if (_zones[action.zone]) {
969
- zoneCache[action.zone] = _zones[action.zone];
970
- delete _zones[action.zone];
971
- }
972
- delete zoneIndex[action.zone];
1241
+ const newData = __spreadProps(__spreadValues({}, data), {
1242
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
1243
+ });
1244
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
1245
+ return newData;
1246
+ };
1247
+
1248
+ // ../core/reducer/actions/register-zone.ts
1249
+ var zoneCache = {};
1250
+ function registerZoneAction(state, action) {
1251
+ if (zoneCache[action.zone]) {
973
1252
  return __spreadProps(__spreadValues({}, state), {
974
1253
  data: __spreadProps(__spreadValues({}, state.data), {
975
- zones: _zones
1254
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
1255
+ [action.zone]: zoneCache[action.zone]
1256
+ })
976
1257
  }),
977
1258
  indexes: __spreadProps(__spreadValues({}, state.indexes), {
978
- zones: zoneIndex
1259
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
1260
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
1261
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
1262
+ type: "dropzone"
1263
+ })
1264
+ })
979
1265
  })
980
1266
  });
981
1267
  }
982
- if (action.type === "setData") {
983
- if (typeof action.data === "object") {
984
- console.warn(
985
- "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
986
- );
987
- return walkTree(
988
- __spreadProps(__spreadValues({}, state), {
989
- data: __spreadValues(__spreadValues({}, state.data), action.data)
990
- }),
991
- appStore.config
992
- );
993
- }
994
- return walkTree(
1268
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1269
+ }
1270
+ function unregisterZoneAction(state, action) {
1271
+ const _zones = __spreadValues({}, state.data.zones || {});
1272
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
1273
+ if (_zones[action.zone]) {
1274
+ zoneCache[action.zone] = _zones[action.zone];
1275
+ delete _zones[action.zone];
1276
+ }
1277
+ delete zoneIndex[action.zone];
1278
+ return __spreadProps(__spreadValues({}, state), {
1279
+ data: __spreadProps(__spreadValues({}, state.data), {
1280
+ zones: _zones
1281
+ }),
1282
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1283
+ zones: zoneIndex
1284
+ })
1285
+ });
1286
+ }
1287
+
1288
+ // ../core/reducer/actions/set-data.ts
1289
+ init_react_import();
1290
+ var setDataAction = (state, action, appStore) => {
1291
+ if (typeof action.data === "object") {
1292
+ console.warn(
1293
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1294
+ );
1295
+ return walkAppState(
995
1296
  __spreadProps(__spreadValues({}, state), {
996
- data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1297
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
997
1298
  }),
998
1299
  appStore.config
999
1300
  );
1000
1301
  }
1001
- if (action.type === "setUi") {
1002
- if (typeof action.ui === "object") {
1003
- return __spreadProps(__spreadValues({}, state), {
1004
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1005
- });
1006
- }
1302
+ return walkAppState(
1303
+ __spreadProps(__spreadValues({}, state), {
1304
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1305
+ }),
1306
+ appStore.config
1307
+ );
1308
+ };
1309
+
1310
+ // ../core/reducer/actions/set-ui.ts
1311
+ init_react_import();
1312
+ var setUiAction = (state, action) => {
1313
+ if (typeof action.ui === "object") {
1007
1314
  return __spreadProps(__spreadValues({}, state), {
1008
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1315
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1009
1316
  });
1010
1317
  }
1011
- return state;
1012
- }
1318
+ return __spreadProps(__spreadValues({}, state), {
1319
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1320
+ });
1321
+ };
1322
+
1323
+ // ../core/lib/data/make-state-public.ts
1324
+ init_react_import();
1325
+ var makeStatePublic = (state) => {
1326
+ const { data, ui } = state;
1327
+ return { data, ui };
1328
+ };
1013
1329
 
1014
1330
  // ../core/reducer/actions.tsx
1015
1331
  init_react_import();
@@ -1028,7 +1344,7 @@ function storeInterceptor(reducer, record, onAction) {
1028
1344
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1029
1345
  if (record) record(newAppState);
1030
1346
  }
1031
- onAction == null ? void 0 : onAction(action, newAppState, state);
1347
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1032
1348
  return newAppState;
1033
1349
  };
1034
1350
  }
@@ -1039,8 +1355,43 @@ function createReducer({
1039
1355
  }) {
1040
1356
  return storeInterceptor(
1041
1357
  (state, action) => {
1042
- const result = reduce(state, action, appStore);
1043
- return result;
1358
+ if (action.type === "set") {
1359
+ return setAction(state, action, appStore);
1360
+ }
1361
+ if (action.type === "insert") {
1362
+ return insertAction(state, action, appStore);
1363
+ }
1364
+ if (action.type === "replace") {
1365
+ return replaceAction(state, action, appStore);
1366
+ }
1367
+ if (action.type === "replaceRoot") {
1368
+ return replaceRootAction(state, action, appStore);
1369
+ }
1370
+ if (action.type === "duplicate") {
1371
+ return duplicateAction(state, action, appStore);
1372
+ }
1373
+ if (action.type === "reorder") {
1374
+ return reorderAction(state, action, appStore);
1375
+ }
1376
+ if (action.type === "move") {
1377
+ return moveAction(state, action, appStore);
1378
+ }
1379
+ if (action.type === "remove") {
1380
+ return removeAction(state, action, appStore);
1381
+ }
1382
+ if (action.type === "registerZone") {
1383
+ return registerZoneAction(state, action);
1384
+ }
1385
+ if (action.type === "unregisterZone") {
1386
+ return unregisterZoneAction(state, action);
1387
+ }
1388
+ if (action.type === "setData") {
1389
+ return setDataAction(state, action, appStore);
1390
+ }
1391
+ if (action.type === "setUi") {
1392
+ return setUiAction(state, action);
1393
+ }
1394
+ return state;
1044
1395
  },
1045
1396
  record,
1046
1397
  onAction
@@ -1235,7 +1586,7 @@ var createHistorySlice = (set, get) => {
1235
1586
  const { dispatch, history } = get();
1236
1587
  dispatch({
1237
1588
  type: "set",
1238
- state: ((_a = history.histories[history.index]) == null ? void 0 : _a.state) || history.initialAppState
1589
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1239
1590
  });
1240
1591
  set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1241
1592
  },
@@ -1251,7 +1602,11 @@ var createNodesSlice = (set, get) => ({
1251
1602
  const s = get().nodes;
1252
1603
  const emptyNode = {
1253
1604
  id,
1254
- methods: { sync: () => null },
1605
+ methods: {
1606
+ sync: () => null,
1607
+ hideOverlay: () => null,
1608
+ showOverlay: () => null
1609
+ },
1255
1610
  element: null
1256
1611
  };
1257
1612
  const existingNode = s.nodes[id];
@@ -1284,11 +1639,11 @@ var createNodesSlice = (set, get) => ({
1284
1639
  init_react_import();
1285
1640
  var import_react7 = require("react");
1286
1641
 
1287
- // ../core/lib/flatten-data.ts
1642
+ // ../core/lib/data/flatten-data.ts
1288
1643
  init_react_import();
1289
1644
  var flattenData = (state, config) => {
1290
1645
  const data = [];
1291
- walkTree(
1646
+ walkAppState(
1292
1647
  state,
1293
1648
  config,
1294
1649
  (content) => content,
@@ -1302,12 +1657,13 @@ var flattenData = (state, config) => {
1302
1657
 
1303
1658
  // ../core/lib/get-changed.ts
1304
1659
  init_react_import();
1660
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1305
1661
  var getChanged = (newItem, oldItem) => {
1306
1662
  return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1307
1663
  const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1308
1664
  const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1309
1665
  return __spreadProps(__spreadValues({}, acc), {
1310
- [item]: oldItemProps[item] !== newItemProps[item]
1666
+ [item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
1311
1667
  });
1312
1668
  }, {}) : {};
1313
1669
  };
@@ -1319,12 +1675,7 @@ var createPermissionsSlice = (set, get) => {
1319
1675
  const { cache: cache2, globalPermissions } = permissions;
1320
1676
  const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1321
1677
  var _a, _b, _c;
1322
- const {
1323
- config: config2,
1324
- state: appState,
1325
- setComponentLoading,
1326
- unsetComponentLoading
1327
- } = get();
1678
+ const { config: config2, state: appState, setComponentLoading } = get();
1328
1679
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1329
1680
  if (!componentConfig) {
1330
1681
  return;
@@ -1333,14 +1684,14 @@ var createPermissionsSlice = (set, get) => {
1333
1684
  if (componentConfig.resolvePermissions) {
1334
1685
  const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1335
1686
  if (Object.values(changed).some((el) => el === true) || force2) {
1336
- setComponentLoading(item2.props.id);
1687
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1337
1688
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1338
1689
  item2,
1339
1690
  {
1340
1691
  changed,
1341
1692
  lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1342
1693
  permissions: initialPermissions,
1343
- appState,
1694
+ appState: makeStatePublic(appState),
1344
1695
  lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1345
1696
  }
1346
1697
  );
@@ -1358,7 +1709,7 @@ var createPermissionsSlice = (set, get) => {
1358
1709
  })
1359
1710
  })
1360
1711
  });
1361
- unsetComponentLoading(item2.props.id);
1712
+ clearTimeout2();
1362
1713
  }
1363
1714
  }
1364
1715
  });
@@ -1368,7 +1719,7 @@ var createPermissionsSlice = (set, get) => {
1368
1719
  // Shim the root data in by conforming to component data shape
1369
1720
  {
1370
1721
  type: "root",
1371
- props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
1722
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1372
1723
  },
1373
1724
  force2
1374
1725
  );
@@ -1383,7 +1734,6 @@ var createPermissionsSlice = (set, get) => {
1383
1734
  } else if (root) {
1384
1735
  resolveDataForRoot(force);
1385
1736
  } else {
1386
- resolveDataForRoot(force);
1387
1737
  flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1388
1738
  yield resolveDataForItem(item2, force);
1389
1739
  }));
@@ -1414,7 +1764,7 @@ var createPermissionsSlice = (set, get) => {
1414
1764
  } else if (root) {
1415
1765
  const rootConfig = config.root;
1416
1766
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1417
- const resolvedForItem = resolvedPermissions["puck-root"];
1767
+ const resolvedForItem = resolvedPermissions["root"];
1418
1768
  return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1419
1769
  }
1420
1770
  return globalPermissions;
@@ -1431,45 +1781,24 @@ var createFieldsSlice = (_set, _get) => {
1431
1781
  return {
1432
1782
  fields: {},
1433
1783
  loading: false,
1434
- lastResolvedData: {}
1784
+ lastResolvedData: {},
1785
+ id: void 0
1435
1786
  };
1436
1787
  };
1437
1788
 
1438
1789
  // ../core/lib/resolve-component-data.ts
1439
1790
  init_react_import();
1440
-
1441
- // ../core/lib/map-slots.ts
1442
- init_react_import();
1443
- function mapSlots(item, map, recursive = true, isSlot2) {
1444
- return __async(this, null, function* () {
1445
- const props = __spreadValues({}, item.props);
1446
- yield forEachSlot(
1447
- item,
1448
- (_parentId, propName, content) => __async(this, null, function* () {
1449
- const mappedContent = recursive ? yield Promise.all(
1450
- content.map((item2) => __async(this, null, function* () {
1451
- return yield mapSlots(item2, map, recursive, isSlot2);
1452
- }))
1453
- ) : content;
1454
- props[propName] = yield map(mappedContent, propName);
1455
- }),
1456
- false,
1457
- isSlot2
1458
- );
1459
- return __spreadProps(__spreadValues({}, item), { props });
1460
- });
1461
- }
1462
-
1463
- // ../core/lib/resolve-component-data.ts
1464
- var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1791
+ var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
1465
1792
  var cache = { lastChange: {} };
1466
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
1467
- const configForItem = "type" in item ? config.components[item.type] : config.root;
1468
- if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
1469
- const id = "id" in item.props ? item.props.id : "root";
1793
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
1794
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
1795
+ const resolvedItem = __spreadValues({}, item);
1796
+ const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
1797
+ const id = "id" in item.props ? item.props.id : "root";
1798
+ if (shouldRunResolver) {
1470
1799
  const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1471
- if (item && item === oldItem) {
1472
- return resolved;
1800
+ if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
1801
+ return { node: resolved, didChange: false };
1473
1802
  }
1474
1803
  const changed = getChanged(item, oldItem);
1475
1804
  if (onResolveStart) {
@@ -1478,47 +1807,48 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1478
1807
  const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1479
1808
  changed,
1480
1809
  lastData: oldItem,
1481
- metadata,
1810
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1482
1811
  trigger
1483
1812
  });
1484
- let resolvedItem = __spreadProps(__spreadValues({}, item), {
1485
- props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1486
- });
1487
- if (recursive) {
1488
- resolvedItem = yield mapSlots(resolvedItem, (content) => __async(void 0, null, function* () {
1489
- return Promise.all(
1490
- content.map(
1491
- (childItem) => __async(void 0, null, function* () {
1492
- return (yield resolveComponentData(
1493
- childItem,
1494
- config,
1495
- metadata,
1496
- onResolveStart,
1497
- onResolveEnd,
1498
- trigger,
1499
- false
1500
- )).node;
1501
- })
1502
- )
1503
- );
1504
- }));
1505
- }
1813
+ resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
1506
1814
  if (Object.keys(readOnly).length) {
1507
1815
  resolvedItem.readOnly = readOnly;
1508
1816
  }
1509
- cache.lastChange[id] = {
1510
- item,
1511
- resolved: resolvedItem
1512
- };
1513
- if (onResolveEnd) {
1514
- onResolveEnd(resolvedItem);
1515
- }
1516
- return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
1517
1817
  }
1518
- return { node: item, didChange: false };
1818
+ let itemWithResolvedChildren = yield mapSlots(
1819
+ resolvedItem,
1820
+ (content) => __async(void 0, null, function* () {
1821
+ return yield Promise.all(
1822
+ content.map(
1823
+ (childItem) => __async(void 0, null, function* () {
1824
+ return (yield resolveComponentData(
1825
+ childItem,
1826
+ config,
1827
+ metadata,
1828
+ onResolveStart,
1829
+ onResolveEnd,
1830
+ trigger
1831
+ )).node;
1832
+ })
1833
+ )
1834
+ );
1835
+ }),
1836
+ config
1837
+ );
1838
+ if (shouldRunResolver && onResolveEnd) {
1839
+ onResolveEnd(resolvedItem);
1840
+ }
1841
+ cache.lastChange[id] = {
1842
+ item,
1843
+ resolved: itemWithResolvedChildren
1844
+ };
1845
+ return {
1846
+ node: itemWithResolvedChildren,
1847
+ didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
1848
+ };
1519
1849
  });
1520
1850
 
1521
- // ../core/lib/to-root.ts
1851
+ // ../core/lib/data/to-root.ts
1522
1852
  init_react_import();
1523
1853
  var toRoot = (item) => {
1524
1854
  if ("type" in item && item.type !== "root") {
@@ -1535,7 +1865,8 @@ var toRoot = (item) => {
1535
1865
  return { props: {}, readOnly };
1536
1866
  };
1537
1867
 
1538
- // ../core/store/index.ts
1868
+ // ../core/store/default-app-state.ts
1869
+ init_react_import();
1539
1870
  var defaultAppState = {
1540
1871
  data: { content: [], root: {}, zones: {} },
1541
1872
  ui: {
@@ -1561,176 +1892,182 @@ var defaultAppState = {
1561
1892
  zones: {}
1562
1893
  }
1563
1894
  };
1895
+
1896
+ // ../core/store/index.ts
1564
1897
  var defaultPageFields = {
1565
1898
  title: { type: "text" }
1566
1899
  };
1567
1900
  var createAppStore = (initialAppStore) => create()(
1568
- subscribeWithSelector((set, get) => __spreadProps(__spreadValues({
1569
- state: defaultAppState,
1570
- config: { components: {} },
1571
- componentState: {},
1572
- plugins: [],
1573
- overrides: {},
1574
- viewports: defaultViewports,
1575
- zoomConfig: {
1576
- autoZoom: 1,
1577
- rootHeight: 0,
1578
- zoom: 1
1579
- },
1580
- status: "LOADING",
1581
- iframe: {},
1582
- metadata: {}
1583
- }, initialAppStore), {
1584
- fields: createFieldsSlice(set, get),
1585
- history: createHistorySlice(set, get),
1586
- nodes: createNodesSlice(set, get),
1587
- permissions: createPermissionsSlice(set, get),
1588
- getComponentConfig: (type) => {
1589
- var _a;
1590
- const { config, selectedItem } = get();
1591
- const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1592
- return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1593
- },
1594
- dispatch: (action) => set((s) => {
1595
- var _a, _b;
1596
- const { record } = get().history;
1597
- const dispatch = createReducer({
1598
- record,
1599
- appStore: s
1600
- });
1601
- const state = dispatch(s.state, action);
1602
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1603
- (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1604
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1605
- }),
1606
- setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1607
- setStatus: (status) => set({ status }),
1608
- setComponentState: (componentState) => set({ componentState }),
1609
- pendingComponentLoads: {},
1610
- setComponentLoading: (id, loading = true, defer = 0) => {
1611
- const { setComponentState, pendingComponentLoads } = get();
1612
- const thisPendingComponentLoads = __spreadValues({}, pendingComponentLoads);
1613
- const setLoading = () => {
1614
- var _a;
1615
- const { componentState } = get();
1616
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1617
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1618
- loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1619
- })
1620
- }));
1621
- };
1622
- const unsetLoading = () => {
1623
- var _a;
1624
- const { componentState } = get();
1625
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1626
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1627
- loadingCount: Math.max(
1628
- (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1629
- 0
1630
- )
1901
+ subscribeWithSelector((set, get) => {
1902
+ var _a, _b;
1903
+ return __spreadProps(__spreadValues({
1904
+ state: defaultAppState,
1905
+ config: { components: {} },
1906
+ componentState: {},
1907
+ plugins: [],
1908
+ overrides: {},
1909
+ viewports: defaultViewports,
1910
+ zoomConfig: {
1911
+ autoZoom: 1,
1912
+ rootHeight: 0,
1913
+ zoom: 1
1914
+ },
1915
+ status: "LOADING",
1916
+ iframe: {},
1917
+ metadata: {}
1918
+ }, initialAppStore), {
1919
+ fields: createFieldsSlice(set, get),
1920
+ history: createHistorySlice(set, get),
1921
+ nodes: createNodesSlice(set, get),
1922
+ permissions: createPermissionsSlice(set, get),
1923
+ getComponentConfig: (type) => {
1924
+ var _a2;
1925
+ const { config, selectedItem } = get();
1926
+ const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
1927
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1928
+ },
1929
+ selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
1930
+ (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
1931
+ initialAppStore.state
1932
+ ) : null,
1933
+ dispatch: (action) => set((s) => {
1934
+ var _a2, _b2;
1935
+ const { record } = get().history;
1936
+ const dispatch = createReducer({
1937
+ record,
1938
+ appStore: s
1939
+ });
1940
+ const state = dispatch(s.state, action);
1941
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1942
+ (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
1943
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1944
+ }),
1945
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1946
+ setStatus: (status) => set({ status }),
1947
+ setComponentState: (componentState) => set({ componentState }),
1948
+ pendingLoadTimeouts: {},
1949
+ setComponentLoading: (id, loading = true, defer = 0) => {
1950
+ const { setComponentState, pendingLoadTimeouts } = get();
1951
+ const loadId = generateId();
1952
+ const setLoading = () => {
1953
+ var _a2;
1954
+ const { componentState } = get();
1955
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1956
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1957
+ loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
1958
+ })
1959
+ }));
1960
+ };
1961
+ const unsetLoading = () => {
1962
+ var _a2;
1963
+ const { componentState } = get();
1964
+ clearTimeout(timeout);
1965
+ delete pendingLoadTimeouts[loadId];
1966
+ set({ pendingLoadTimeouts });
1967
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1968
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1969
+ loadingCount: Math.max(
1970
+ (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
1971
+ 0
1972
+ )
1973
+ })
1974
+ }));
1975
+ };
1976
+ const timeout = setTimeout(() => {
1977
+ if (loading) {
1978
+ setLoading();
1979
+ } else {
1980
+ unsetLoading();
1981
+ }
1982
+ delete pendingLoadTimeouts[loadId];
1983
+ set({ pendingLoadTimeouts });
1984
+ }, defer);
1985
+ set({
1986
+ pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
1987
+ [id]: timeout
1631
1988
  })
1632
- }));
1633
- };
1634
- if (thisPendingComponentLoads[id]) {
1635
- clearTimeout(thisPendingComponentLoads[id]);
1636
- delete thisPendingComponentLoads[id];
1637
- set({ pendingComponentLoads: thisPendingComponentLoads });
1638
- }
1639
- const timeout = setTimeout(() => {
1640
- if (loading) {
1641
- setLoading();
1642
- } else {
1643
- unsetLoading();
1644
- }
1645
- delete thisPendingComponentLoads[id];
1646
- set({ pendingComponentLoads: thisPendingComponentLoads });
1647
- }, defer);
1648
- set({
1649
- pendingComponentLoads: __spreadProps(__spreadValues({}, thisPendingComponentLoads), {
1650
- [id]: timeout
1651
- })
1652
- });
1653
- },
1654
- unsetComponentLoading: (id) => {
1655
- const { setComponentLoading } = get();
1656
- setComponentLoading(id, false);
1657
- },
1658
- // Helper
1659
- setUi: (ui, recordHistory) => set((s) => {
1660
- const dispatch = createReducer({
1661
- record: () => {
1662
- },
1663
- appStore: s
1664
- });
1665
- const state = dispatch(s.state, {
1666
- type: "setUi",
1667
- ui,
1668
- recordHistory
1669
- });
1670
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1671
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1672
- }),
1673
- // resolveDataRuns: 0,
1674
- // resolveData: (newAppState) =>
1675
- // set((s) => {
1676
- // resolveData(newAppState, get);
1677
- // return { ...s, resolveDataRuns: s.resolveDataRuns + 1 };
1678
- // }),
1679
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1680
- const { config, metadata, setComponentLoading } = get();
1681
- return yield resolveComponentData(
1682
- componentData,
1683
- config,
1684
- metadata,
1685
- (item) => setComponentLoading(
1686
- "id" in item.props ? item.props.id : "root",
1687
- true,
1688
- 50
1689
- ),
1690
- (item) => setComponentLoading(
1691
- "id" in item.props ? item.props.id : "root",
1692
- false,
1693
- 0
1694
- ),
1695
- trigger
1696
- );
1697
- }),
1698
- resolveAndCommitData: () => __async(void 0, null, function* () {
1699
- const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1700
- walkTree(
1701
- state,
1702
- config,
1703
- (content) => content,
1704
- (childItem) => {
1705
- resolveComponentData2(childItem, "load").then((resolved) => {
1706
- const { state: state2 } = get();
1707
- const node = state2.indexes.nodes[resolved.node.props.id];
1708
- if (node && resolved.didChange) {
1709
- if (resolved.node.props.id === "root") {
1710
- dispatch({
1711
- type: "replaceRoot",
1712
- root: toRoot(resolved.node)
1713
- });
1714
- } else {
1715
- const zoneCompound = `${node.parentId}:${node.zone}`;
1716
- const parentZone = state2.indexes.zones[zoneCompound];
1717
- const index = parentZone.contentIds.indexOf(
1718
- resolved.node.props.id
1719
- );
1720
- dispatch({
1721
- type: "replace",
1722
- data: resolved.node,
1723
- destinationIndex: index,
1724
- destinationZone: zoneCompound
1725
- });
1726
- }
1989
+ });
1990
+ return unsetLoading;
1991
+ },
1992
+ unsetComponentLoading: (id) => {
1993
+ const { setComponentLoading } = get();
1994
+ setComponentLoading(id, false);
1995
+ },
1996
+ // Helper
1997
+ setUi: (ui, recordHistory) => set((s) => {
1998
+ const dispatch = createReducer({
1999
+ record: () => {
2000
+ },
2001
+ appStore: s
2002
+ });
2003
+ const state = dispatch(s.state, {
2004
+ type: "setUi",
2005
+ ui,
2006
+ recordHistory
2007
+ });
2008
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
2009
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
2010
+ }),
2011
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
2012
+ const { config, metadata, setComponentLoading, permissions } = get();
2013
+ const timeouts = {};
2014
+ return yield resolveComponentData(
2015
+ componentData,
2016
+ config,
2017
+ metadata,
2018
+ (item) => {
2019
+ const id = "id" in item.props ? item.props.id : "root";
2020
+ timeouts[id] = setComponentLoading(id, true, 50);
2021
+ },
2022
+ (item) => __async(void 0, null, function* () {
2023
+ const id = "id" in item.props ? item.props.id : "root";
2024
+ if ("type" in item) {
2025
+ yield permissions.refreshPermissions({ item });
2026
+ } else {
2027
+ yield permissions.refreshPermissions({ root: true });
1727
2028
  }
1728
- });
1729
- return childItem;
1730
- }
1731
- );
1732
- })
1733
- }))
2029
+ timeouts[id]();
2030
+ }),
2031
+ trigger
2032
+ );
2033
+ }),
2034
+ resolveAndCommitData: () => __async(void 0, null, function* () {
2035
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
2036
+ walkAppState(
2037
+ state,
2038
+ config,
2039
+ (content) => content,
2040
+ (childItem) => {
2041
+ resolveComponentData2(childItem, "load").then((resolved) => {
2042
+ const { state: state2 } = get();
2043
+ const node = state2.indexes.nodes[resolved.node.props.id];
2044
+ if (node && resolved.didChange) {
2045
+ if (resolved.node.props.id === "root") {
2046
+ dispatch({
2047
+ type: "replaceRoot",
2048
+ root: toRoot(resolved.node)
2049
+ });
2050
+ } else {
2051
+ const zoneCompound = `${node.parentId}:${node.zone}`;
2052
+ const parentZone = state2.indexes.zones[zoneCompound];
2053
+ const index = parentZone.contentIds.indexOf(
2054
+ resolved.node.props.id
2055
+ );
2056
+ dispatch({
2057
+ type: "replace",
2058
+ data: resolved.node,
2059
+ destinationIndex: index,
2060
+ destinationZone: zoneCompound
2061
+ });
2062
+ }
2063
+ }
2064
+ });
2065
+ return childItem;
2066
+ }
2067
+ );
2068
+ })
2069
+ });
2070
+ })
1734
2071
  );
1735
2072
  var appStoreContext = (0, import_react9.createContext)(createAppStore());
1736
2073
  function useAppStore(selector) {
@@ -1792,10 +2129,10 @@ init_react_import();
1792
2129
  // ../core/lib/filter.ts
1793
2130
  init_react_import();
1794
2131
 
1795
- // ../core/lib/reorder.ts
2132
+ // ../core/lib/data/reorder.ts
1796
2133
  init_react_import();
1797
2134
 
1798
- // ../core/lib/replace.ts
2135
+ // ../core/lib/data/replace.ts
1799
2136
  init_react_import();
1800
2137
 
1801
2138
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
@@ -1981,15 +2318,37 @@ var HeadingAnalyzer = () => {
1981
2318
  const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
1982
2319
  (0, import_react11.useEffect)(() => {
1983
2320
  const frame = getFrame();
1984
- const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
1985
- if (!entry) return;
1986
- setHierarchy(buildHierarchy(entry));
1987
- const observer = new MutationObserver(() => {
2321
+ let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2322
+ const createHierarchy = () => {
1988
2323
  setHierarchy(buildHierarchy(entry));
2324
+ };
2325
+ const entryObserver = new MutationObserver(() => {
2326
+ createHierarchy();
2327
+ });
2328
+ const frameObserver = new MutationObserver(() => {
2329
+ entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2330
+ if (entry) {
2331
+ registerEntryObserver();
2332
+ frameObserver.disconnect();
2333
+ }
1989
2334
  });
1990
- observer.observe(entry, { subtree: true, childList: true });
2335
+ const registerEntryObserver = () => {
2336
+ if (!entry) return;
2337
+ entryObserver.observe(entry, { subtree: true, childList: true });
2338
+ };
2339
+ const registerFrameObserver = () => {
2340
+ if (!frame) return;
2341
+ frameObserver.observe(frame, { subtree: true, childList: true });
2342
+ };
2343
+ if (entry) {
2344
+ createHierarchy();
2345
+ registerEntryObserver();
2346
+ } else {
2347
+ registerFrameObserver();
2348
+ }
1991
2349
  return () => {
1992
- observer.disconnect();
2350
+ entryObserver.disconnect();
2351
+ frameObserver.disconnect();
1993
2352
  };
1994
2353
  }, [data]);
1995
2354
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [