@measured/puck-plugin-heading-analyzer 0.19.0-canary.af4f756 → 0.19.0-canary.b22833ee

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,285 +153,116 @@ var require_classnames = __commonJS({
153
153
  }
154
154
  });
155
155
 
156
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js
157
- var require_use_sync_external_store_shim_production = __commonJS({
158
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js"(exports2) {
156
+ // ../../node_modules/flat/index.js
157
+ var require_flat = __commonJS({
158
+ "../../node_modules/flat/index.js"(exports2, module2) {
159
159
  "use strict";
160
160
  init_react_import();
161
- var React2 = require("react");
162
- function is(x, y) {
163
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
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);
164
166
  }
165
- var objectIs = "function" === typeof Object.is ? Object.is : is;
166
- var useState2 = React2.useState;
167
- var useEffect7 = React2.useEffect;
168
- var useLayoutEffect = React2.useLayoutEffect;
169
- var useDebugValue2 = React2.useDebugValue;
170
- function useSyncExternalStore$2(subscribe, getSnapshot) {
171
- var value = getSnapshot(), _useState = useState2({ inst: { value, getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1];
172
- useLayoutEffect(
173
- function() {
174
- inst.value = value;
175
- inst.getSnapshot = getSnapshot;
176
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
177
- },
178
- [subscribe, value, getSnapshot]
179
- );
180
- useEffect7(
181
- function() {
182
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
183
- return subscribe(function() {
184
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
185
- });
186
- },
187
- [subscribe]
188
- );
189
- useDebugValue2(value);
190
- return value;
167
+ function keyIdentity(key) {
168
+ return key;
191
169
  }
192
- function checkIfSnapshotChanged(inst) {
193
- var latestGetSnapshot = inst.getSnapshot;
194
- inst = inst.value;
195
- try {
196
- var nextValue = latestGetSnapshot();
197
- return !objectIs(inst, nextValue);
198
- } catch (error) {
199
- return true;
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
+ });
200
190
  }
191
+ step(target);
192
+ return output;
201
193
  }
202
- function useSyncExternalStore$1(subscribe, getSnapshot) {
203
- return getSnapshot();
204
- }
205
- var shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
206
- exports2.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim;
207
- }
208
- });
209
-
210
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
211
- var require_use_sync_external_store_shim_development = __commonJS({
212
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports2) {
213
- "use strict";
214
- init_react_import();
215
- "production" !== process.env.NODE_ENV && function() {
216
- function is(x, y) {
217
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
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;
218
203
  }
219
- function useSyncExternalStore$2(subscribe, getSnapshot) {
220
- didWarnOld18Alpha || void 0 === React2.startTransition || (didWarnOld18Alpha = true, console.error(
221
- "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
222
- ));
223
- var value = getSnapshot();
224
- if (!didWarnUncachedGetSnapshot) {
225
- var cachedValue = getSnapshot();
226
- objectIs(value, cachedValue) || (console.error(
227
- "The result of getSnapshot should be cached to avoid an infinite loop"
228
- ), didWarnUncachedGetSnapshot = true);
229
- }
230
- cachedValue = useState2({
231
- inst: { value, getSnapshot }
232
- });
233
- var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
234
- useLayoutEffect(
235
- function() {
236
- inst.value = value;
237
- inst.getSnapshot = getSnapshot;
238
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
239
- },
240
- [subscribe, value, getSnapshot]
241
- );
242
- useEffect7(
243
- function() {
244
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
245
- return subscribe(function() {
246
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
247
- });
248
- },
249
- [subscribe]
250
- );
251
- useDebugValue2(value);
252
- return value;
204
+ function getkey(key) {
205
+ const parsedKey = Number(key);
206
+ return isNaN(parsedKey) || key.indexOf(".") !== -1 || opts.object ? key : parsedKey;
253
207
  }
254
- function checkIfSnapshotChanged(inst) {
255
- var latestGetSnapshot = inst.getSnapshot;
256
- inst = inst.value;
257
- try {
258
- var nextValue = latestGetSnapshot();
259
- return !objectIs(inst, nextValue);
260
- } catch (error) {
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) {
261
219
  return true;
220
+ } else if (isArray) {
221
+ return !val.length;
222
+ } else if (isObject) {
223
+ return !Object.keys(val).length;
262
224
  }
263
225
  }
264
- function useSyncExternalStore$1(subscribe, getSnapshot) {
265
- return getSnapshot();
266
- }
267
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
268
- var React2 = require("react"), objectIs = "function" === typeof Object.is ? Object.is : is, useState2 = React2.useState, useEffect7 = React2.useEffect, useLayoutEffect = React2.useLayoutEffect, useDebugValue2 = React2.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
269
- exports2.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim;
270
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
271
- }();
272
- }
273
- });
274
-
275
- // ../../node_modules/use-sync-external-store/shim/index.js
276
- var require_shim = __commonJS({
277
- "../../node_modules/use-sync-external-store/shim/index.js"(exports2, module2) {
278
- "use strict";
279
- init_react_import();
280
- if (process.env.NODE_ENV === "production") {
281
- module2.exports = require_use_sync_external_store_shim_production();
282
- } else {
283
- module2.exports = require_use_sync_external_store_shim_development();
284
- }
285
- }
286
- });
287
-
288
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js
289
- var require_with_selector_production = __commonJS({
290
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js"(exports2) {
291
- "use strict";
292
- init_react_import();
293
- var React2 = require("react");
294
- var shim = require_shim();
295
- function is(x, y) {
296
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
297
- }
298
- var objectIs = "function" === typeof Object.is ? Object.is : is;
299
- var useSyncExternalStore = shim.useSyncExternalStore;
300
- var useRef = React2.useRef;
301
- var useEffect7 = React2.useEffect;
302
- var useMemo2 = React2.useMemo;
303
- var useDebugValue2 = React2.useDebugValue;
304
- exports2.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
305
- var instRef = useRef(null);
306
- if (null === instRef.current) {
307
- var inst = { hasValue: false, value: null };
308
- instRef.current = inst;
309
- } else inst = instRef.current;
310
- instRef = useMemo2(
311
- function() {
312
- function memoizedSelector(nextSnapshot) {
313
- if (!hasMemo) {
314
- hasMemo = true;
315
- memoizedSnapshot = nextSnapshot;
316
- nextSnapshot = selector(nextSnapshot);
317
- if (void 0 !== isEqual && inst.hasValue) {
318
- var currentSelection = inst.value;
319
- if (isEqual(currentSelection, nextSnapshot))
320
- return memoizedSelection = currentSelection;
321
- }
322
- return memoizedSelection = nextSnapshot;
323
- }
324
- currentSelection = memoizedSelection;
325
- if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
326
- var nextSelection = selector(nextSnapshot);
327
- if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
328
- return memoizedSnapshot = nextSnapshot, currentSelection;
329
- memoizedSnapshot = nextSnapshot;
330
- return memoizedSelection = nextSelection;
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;
331
248
  }
332
- var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
333
- return [
334
- function() {
335
- return memoizedSelector(getSnapshot());
336
- },
337
- null === maybeGetServerSnapshot ? void 0 : function() {
338
- return memoizedSelector(maybeGetServerSnapshot());
339
- }
340
- ];
341
- },
342
- [getSnapshot, getServerSnapshot, selector, isEqual]
343
- );
344
- var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
345
- useEffect7(
346
- function() {
347
- inst.hasValue = true;
348
- inst.value = value;
349
- },
350
- [value]
351
- );
352
- useDebugValue2(value);
353
- return value;
354
- };
355
- }
356
- });
357
-
358
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js
359
- var require_with_selector_development = __commonJS({
360
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js"(exports2) {
361
- "use strict";
362
- init_react_import();
363
- "production" !== process.env.NODE_ENV && function() {
364
- function is(x, y) {
365
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
366
- }
367
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
368
- var React2 = require("react"), shim = require_shim(), objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim.useSyncExternalStore, useRef = React2.useRef, useEffect7 = React2.useEffect, useMemo2 = React2.useMemo, useDebugValue2 = React2.useDebugValue;
369
- exports2.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
370
- var instRef = useRef(null);
371
- if (null === instRef.current) {
372
- var inst = { hasValue: false, value: null };
373
- instRef.current = inst;
374
- } else inst = instRef.current;
375
- instRef = useMemo2(
376
- function() {
377
- function memoizedSelector(nextSnapshot) {
378
- if (!hasMemo) {
379
- hasMemo = true;
380
- memoizedSnapshot = nextSnapshot;
381
- nextSnapshot = selector(nextSnapshot);
382
- if (void 0 !== isEqual && inst.hasValue) {
383
- var currentSelection = inst.value;
384
- if (isEqual(currentSelection, nextSnapshot))
385
- return memoizedSelection = currentSelection;
386
- }
387
- return memoizedSelection = nextSnapshot;
388
- }
389
- currentSelection = memoizedSelection;
390
- if (objectIs(memoizedSnapshot, nextSnapshot))
391
- return currentSelection;
392
- var nextSelection = selector(nextSnapshot);
393
- if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
394
- return memoizedSnapshot = nextSnapshot, currentSelection;
395
- memoizedSnapshot = nextSnapshot;
396
- return memoizedSelection = nextSelection;
397
- }
398
- var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
399
- return [
400
- function() {
401
- return memoizedSelector(getSnapshot());
402
- },
403
- null === maybeGetServerSnapshot ? void 0 : function() {
404
- return memoizedSelector(maybeGetServerSnapshot());
405
- }
406
- ];
407
- },
408
- [getSnapshot, getServerSnapshot, selector, isEqual]
409
- );
410
- var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
411
- useEffect7(
412
- function() {
413
- inst.hasValue = true;
414
- inst.value = value;
415
- },
416
- [value]
417
- );
418
- useDebugValue2(value);
419
- return value;
420
- };
421
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
422
- }();
423
- }
424
- });
425
-
426
- // ../../node_modules/use-sync-external-store/shim/with-selector.js
427
- var require_with_selector = __commonJS({
428
- "../../node_modules/use-sync-external-store/shim/with-selector.js"(exports2, module2) {
429
- "use strict";
430
- init_react_import();
431
- if (process.env.NODE_ENV === "production") {
432
- module2.exports = require_with_selector_production();
433
- } else {
434
- module2.exports = require_with_selector_development();
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;
435
266
  }
436
267
  }
437
268
  });
@@ -482,7 +313,7 @@ init_react_import();
482
313
 
483
314
  // src/HeadingAnalyzer.tsx
484
315
  init_react_import();
485
- var import_react12 = require("react");
316
+ var import_react11 = require("react");
486
317
 
487
318
  // css-module:/home/runner/work/puck/puck/packages/plugin-heading-analyzer/src/HeadingAnalyzer.module.css#css-module
488
319
  init_react_import();
@@ -643,7 +474,7 @@ var ChevronRight = createLucideIcon("ChevronRight", [
643
474
 
644
475
  // ../core/lib/use-breadcrumbs.ts
645
476
  init_react_import();
646
- var import_react11 = require("react");
477
+ var import_react10 = require("react");
647
478
 
648
479
  // ../core/store/index.ts
649
480
  init_react_import();
@@ -651,17 +482,17 @@ init_react_import();
651
482
  // ../core/reducer/index.ts
652
483
  init_react_import();
653
484
 
654
- // ../core/reducer/data.ts
485
+ // ../core/reducer/actions/set.ts
655
486
  init_react_import();
656
487
 
657
- // ../core/lib/reorder.ts
488
+ // ../core/lib/data/walk-app-state.ts
489
+ init_react_import();
490
+
491
+ // ../core/lib/data/for-related-zones.ts
492
+ init_react_import();
493
+
494
+ // ../core/lib/get-zone-id.ts
658
495
  init_react_import();
659
- var reorder = (list, startIndex, endIndex) => {
660
- const result = Array.from(list);
661
- const [removed] = result.splice(startIndex, 1);
662
- result.splice(endIndex, 0, removed);
663
- return result;
664
- };
665
496
 
666
497
  // ../core/lib/root-droppable-id.ts
667
498
  init_react_import();
@@ -669,57 +500,336 @@ var rootAreaId = "root";
669
500
  var rootZone = "default-zone";
670
501
  var rootDroppableId = `${rootAreaId}:${rootZone}`;
671
502
 
672
- // ../core/lib/insert.ts
673
- init_react_import();
674
- var insert = (list, index, item) => {
675
- const result = Array.from(list);
676
- result.splice(index, 0, item);
677
- return result;
503
+ // ../core/lib/get-zone-id.ts
504
+ var getZoneId = (zoneCompound) => {
505
+ if (!zoneCompound) {
506
+ return [];
507
+ }
508
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
509
+ return zoneCompound.split(":");
510
+ }
511
+ return [rootDroppableId, zoneCompound];
678
512
  };
679
513
 
680
- // ../core/lib/remove.ts
514
+ // ../core/lib/data/for-related-zones.ts
515
+ function forRelatedZones(item, data, cb, path = []) {
516
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
517
+ const [parentId] = getZoneId(zoneCompound);
518
+ if (parentId === item.props.id) {
519
+ cb(path, zoneCompound, content);
520
+ }
521
+ });
522
+ }
523
+
524
+ // ../core/lib/data/map-slots.ts
681
525
  init_react_import();
682
- var remove = (list, index) => {
683
- const result = Array.from(list);
684
- result.splice(index, 1);
685
- return result;
686
- };
687
526
 
688
- // ../core/lib/setup-zone.ts
527
+ // ../core/lib/data/default-slots.ts
689
528
  init_react_import();
690
- var setupZone = (data, zoneKey) => {
691
- if (zoneKey === rootDroppableId) {
692
- return data;
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);
693
571
  }
694
- const newData = __spreadProps(__spreadValues({}, data), {
695
- zones: data.zones ? __spreadValues({}, data.zones) : {}
696
- });
697
- newData.zones[zoneKey] = newData.zones[zoneKey] || [];
698
- return newData;
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;
699
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
+ }
700
666
 
701
- // ../core/lib/replace.ts
667
+ // ../core/lib/data/flatten-node.ts
702
668
  init_react_import();
703
- var replace = (list, index, newItem) => {
704
- const result = Array.from(list);
705
- result.splice(index, 1);
706
- result.splice(index, 0, newItem);
707
- return result;
708
- };
669
+ var import_flat = __toESM(require_flat());
709
670
 
710
- // ../core/lib/get-item.ts
671
+ // ../core/lib/data/strip-slots.ts
711
672
  init_react_import();
712
- function getItem(selector, data, dynamicProps = {}) {
713
- if (!selector.zone || selector.zone === rootDroppableId) {
714
- const item2 = data.content[selector.index];
715
- return (item2 == null ? void 0 : item2.props) ? __spreadProps(__spreadValues({}, item2), { props: dynamicProps[item2.props.id] || item2.props }) : void 0;
716
- }
717
- const item = setupZone(data, selector.zone).zones[selector.zone][selector.index];
718
- return (item == null ? void 0 : item.props) ? __spreadProps(__spreadValues({}, item), { props: dynamicProps[item.props.id] || item.props }) : void 0;
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)
681
+ });
682
+ };
683
+
684
+ // ../core/lib/data/walk-app-state.ts
685
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
686
+ var _a;
687
+ let newZones = {};
688
+ const newZoneIndex = {};
689
+ const newNodeIndex = {};
690
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
691
+ var _a2;
692
+ const [parentId] = zoneCompound.split(":");
693
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
694
+ const [_2, zone] = zoneCompound.split(":");
695
+ const newZoneCompound = `${newId || parentId}:${zone}`;
696
+ const newContent2 = mappedContent.map(
697
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
698
+ );
699
+ newZoneIndex[newZoneCompound] = {
700
+ contentIds: newContent2.map((item) => item.props.id),
701
+ type: zoneType
702
+ };
703
+ return [newZoneCompound, newContent2];
704
+ };
705
+ const processRelatedZones = (item, newId, initialPath) => {
706
+ forRelatedZones(
707
+ item,
708
+ state.data,
709
+ (relatedPath, relatedZoneCompound, relatedContent) => {
710
+ const [zoneCompound, newContent2] = processContent(
711
+ relatedPath,
712
+ relatedZoneCompound,
713
+ relatedContent,
714
+ "dropzone",
715
+ newId
716
+ );
717
+ newZones[zoneCompound] = newContent2;
718
+ },
719
+ initialPath
720
+ );
721
+ };
722
+ const processItem = (item, path, index) => {
723
+ const mappedItem = mapNodeOrSkip(item, path, index);
724
+ if (!mappedItem) return item;
725
+ const id = mappedItem.props.id;
726
+ const newProps = __spreadProps(__spreadValues({}, mapSlots(
727
+ mappedItem,
728
+ (content, parentId2, slotId) => {
729
+ const zoneCompound = `${parentId2}:${slotId}`;
730
+ const [_2, newContent2] = processContent(
731
+ path,
732
+ zoneCompound,
733
+ content,
734
+ "slot",
735
+ parentId2
736
+ );
737
+ return newContent2;
738
+ },
739
+ config
740
+ ).props), {
741
+ id
742
+ });
743
+ processRelatedZones(item, id, path);
744
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
745
+ const thisZoneCompound = path[path.length - 1];
746
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
747
+ newNodeIndex[id] = {
748
+ data: newItem,
749
+ flatData: flattenNode(newItem, config),
750
+ path,
751
+ parentId,
752
+ zone
753
+ };
754
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
755
+ if (newProps.id === "root") {
756
+ delete finalData["type"];
757
+ delete finalData.props["id"];
758
+ }
759
+ return finalData;
760
+ };
761
+ const zones = state.data.zones || {};
762
+ const [_, newContent] = processContent(
763
+ [],
764
+ rootDroppableId,
765
+ state.data.content,
766
+ "root"
767
+ );
768
+ const processedContent = newContent;
769
+ const zonesAlreadyProcessed = Object.keys(newZones);
770
+ Object.keys(zones || {}).forEach((zoneCompound) => {
771
+ const [parentId] = zoneCompound.split(":");
772
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
773
+ return;
774
+ }
775
+ const [_2, newContent2] = processContent(
776
+ [rootDroppableId],
777
+ zoneCompound,
778
+ zones[zoneCompound],
779
+ "dropzone",
780
+ parentId
781
+ );
782
+ newZones[zoneCompound] = newContent2;
783
+ }, newZones);
784
+ const processedRoot = processItem(
785
+ {
786
+ type: "root",
787
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
788
+ },
789
+ [],
790
+ -1
791
+ );
792
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
793
+ props: processedRoot.props
794
+ });
795
+ return __spreadProps(__spreadValues({}, state), {
796
+ data: {
797
+ root,
798
+ content: processedContent,
799
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
800
+ },
801
+ indexes: {
802
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
803
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
804
+ }
805
+ });
719
806
  }
720
807
 
721
- // ../core/lib/reduce-related-zones.ts
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."
817
+ );
818
+ return walkAppState(newState, appStore.config);
819
+ }
820
+ return __spreadValues(__spreadValues({}, state), action.state(state));
821
+ };
822
+
823
+ // ../core/reducer/actions/insert.ts
824
+ init_react_import();
825
+
826
+ // ../core/lib/data/insert.ts
722
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
+ };
723
833
 
724
834
  // ../core/lib/generate-id.ts
725
835
  init_react_import();
@@ -783,313 +893,438 @@ var v4_default = v4;
783
893
  // ../core/lib/generate-id.ts
784
894
  var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
785
895
 
786
- // ../core/lib/get-zone-id.ts
896
+ // ../core/lib/data/get-ids-for-parent.ts
787
897
  init_react_import();
788
- var getZoneId = (zoneCompound) => {
789
- if (!zoneCompound) {
790
- return [];
791
- }
792
- if (zoneCompound && zoneCompound.indexOf(":") > -1) {
793
- return zoneCompound.split(":");
794
- }
795
- return [rootDroppableId, zoneCompound];
898
+ var getIdsForParent = (zoneCompound, state) => {
899
+ const [parentId] = zoneCompound.split(":");
900
+ const node = state.indexes.nodes[parentId];
901
+ return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
796
902
  };
797
903
 
798
- // ../core/lib/reduce-related-zones.ts
799
- function reduceRelatedZones(item, data, fn) {
800
- return __spreadProps(__spreadValues({}, data), {
801
- zones: Object.keys(data.zones || {}).reduce(
802
- (acc, key) => {
803
- const [parentId] = getZoneId(key);
804
- if (parentId === item.props.id) {
805
- const zones = data.zones;
806
- return fn(acc, key, zones[key]);
807
- }
808
- return __spreadProps(__spreadValues({}, acc), { [key]: data.zones[key] });
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;
809
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
+ }),
810
938
  {}
811
939
  )
812
- });
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
+ );
972
+ const [parentId] = action.destinationZone.split(":");
973
+ const idsInPath = getIdsForParent(action.destinationZone, state);
974
+ return walkAppState(
975
+ state,
976
+ appStore.config,
977
+ (content, zoneCompound) => {
978
+ if (zoneCompound === action.destinationZone) {
979
+ return insert(
980
+ content || [],
981
+ action.destinationIndex,
982
+ emptyComponentData
983
+ );
984
+ }
985
+ return content;
986
+ },
987
+ (childItem, path) => {
988
+ if (childItem.props.id === id || childItem.props.id === parentId) {
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
+ );
813
998
  }
814
- var findRelatedByZoneId = (zoneId, data) => {
815
- const [zoneParentId] = getZoneId(zoneId);
816
- return (data.zones[zoneId] || []).reduce(
817
- (acc, zoneItem) => {
818
- const related = findRelatedByItem(zoneItem, data);
819
- if (zoneItem.props.id === zoneParentId) {
820
- return __spreadProps(__spreadValues(__spreadValues({}, acc), related), { [zoneId]: zoneItem });
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;
821
1020
  }
822
- return __spreadValues(__spreadValues({}, acc), related);
1021
+ return newContent;
823
1022
  },
824
- {}
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;
1029
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
1030
+ return childItem;
1031
+ } else if (pathIds.indexOf(data.props.id) > -1) {
1032
+ return childItem;
1033
+ }
1034
+ return null;
1035
+ }
825
1036
  );
826
1037
  };
827
- var findRelatedByItem = (item, data) => {
828
- return Object.keys(data.zones || {}).reduce(
829
- (acc, zoneId) => {
830
- const [zoneParentId] = getZoneId(zoneId);
831
- if (item.props.id === zoneParentId) {
832
- const related = findRelatedByZoneId(zoneId, data);
833
- return __spreadProps(__spreadValues(__spreadValues({}, acc), related), {
834
- [zoneId]: data.zones[zoneId]
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
835
1051
  });
836
1052
  }
837
- return acc;
838
- },
839
- {}
1053
+ return childItem;
1054
+ }
840
1055
  );
841
1056
  };
842
- var removeRelatedZones = (item, data) => {
843
- const newData = __spreadValues({}, data);
844
- const related = findRelatedByItem(item, data);
845
- Object.keys(related).forEach((key) => {
846
- delete newData.zones[key];
847
- });
848
- return newData;
849
- };
850
- function duplicateRelatedZones(item, data, newId) {
851
- return reduceRelatedZones(item, data, (acc, key, zone) => {
852
- const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
853
- props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
854
- }));
855
- const dupeOfDupes = dupedZone.reduce(
856
- (dupeOfDupes2, item2, index) => __spreadValues(__spreadValues({}, dupeOfDupes2), duplicateRelatedZones(zone[index], data, item2.props.id).zones),
857
- acc
858
- );
859
- const [_, zoneId] = getZoneId(key);
860
- return __spreadProps(__spreadValues({}, dupeOfDupes), {
861
- [key]: zone,
862
- [`${newId}:${zoneId}`]: dupedZone
863
- });
864
- });
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;
865
1067
  }
866
1068
 
867
- // ../core/reducer/data.ts
868
- var zoneCache = {};
869
- var replaceAction = (data, action) => {
870
- if (action.destinationZone === rootDroppableId) {
871
- return __spreadProps(__spreadValues({}, data), {
872
- content: replace(data.content, action.destinationIndex, action.data)
873
- });
874
- }
875
- const newData = setupZone(data, action.destinationZone);
876
- return __spreadProps(__spreadValues({}, newData), {
877
- zones: __spreadProps(__spreadValues({}, newData.zones), {
878
- [action.destinationZone]: replace(
879
- newData.zones[action.destinationZone],
880
- action.destinationIndex,
881
- action.data
882
- )
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)
883
1079
  })
884
1080
  });
885
- };
886
- function insertAction(data, action, config) {
887
- const emptyComponentData = {
888
- type: action.componentType,
889
- props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
890
- id: action.id || generateId(action.componentType)
891
- })
892
- };
893
- if (action.destinationZone === rootDroppableId) {
894
- return __spreadProps(__spreadValues({}, data), {
895
- content: insert(
896
- data.content,
897
- action.destinationIndex,
898
- emptyComponentData
899
- )
900
- });
901
- }
902
- const newData = setupZone(data, action.destinationZone);
903
- return __spreadProps(__spreadValues({}, data), {
904
- zones: __spreadProps(__spreadValues({}, newData.zones), {
905
- [action.destinationZone]: insert(
906
- newData.zones[action.destinationZone],
907
- action.destinationIndex,
908
- emptyComponentData
909
- )
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;
1106
+ }
1107
+ return null;
1108
+ }
1109
+ );
1110
+ return __spreadProps(__spreadValues({}, modified), {
1111
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
1112
+ itemSelector: {
1113
+ index: action.sourceIndex + 1,
1114
+ zone: action.sourceZone
1115
+ }
910
1116
  })
911
1117
  });
912
1118
  }
913
- var reorderAction = (data, action) => {
914
- if (action.destinationZone === rootDroppableId) {
915
- return __spreadProps(__spreadValues({}, data), {
916
- content: reorder(
917
- data.content,
918
- action.sourceIndex,
919
- action.destinationIndex
920
- )
921
- });
922
- }
923
- const newData = setupZone(data, action.destinationZone);
924
- return __spreadProps(__spreadValues({}, data), {
925
- zones: __spreadProps(__spreadValues({}, newData.zones), {
926
- [action.destinationZone]: reorder(
927
- newData.zones[action.destinationZone],
928
- action.sourceIndex,
929
- action.destinationIndex
930
- )
931
- })
932
- });
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;
933
1132
  };
934
- function reduceData(data, action, config) {
935
- if (action.type === "insert") {
936
- return insertAction(data, action, config);
937
- }
938
- if (action.type === "duplicate") {
939
- const item = getItem(
940
- { index: action.sourceIndex, zone: action.sourceZone },
941
- data
942
- );
943
- const newItem = __spreadProps(__spreadValues({}, item), {
944
- props: __spreadProps(__spreadValues({}, item.props), {
945
- id: generateId(item.type)
946
- })
947
- });
948
- const dataWithRelatedDuplicated = duplicateRelatedZones(
949
- item,
950
- data,
951
- newItem.props.id
952
- );
953
- if (action.sourceZone === rootDroppableId) {
954
- return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
955
- content: insert(data.content, action.sourceIndex + 1, newItem)
956
- });
957
- }
958
- return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
959
- zones: __spreadProps(__spreadValues({}, dataWithRelatedDuplicated.zones), {
960
- [action.sourceZone]: insert(
961
- dataWithRelatedDuplicated.zones[action.sourceZone],
962
- action.sourceIndex + 1,
963
- newItem
964
- )
965
- })
966
- });
967
- }
968
- if (action.type === "reorder") {
969
- return reorderAction(data, action);
1133
+
1134
+ // ../core/reducer/actions/move.ts
1135
+ var moveAction = (state, action, appStore) => {
1136
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
1137
+ return state;
970
1138
  }
971
- if (action.type === "move") {
972
- if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
973
- return data;
974
- }
975
- const newData = setupZone(
976
- setupZone(data, action.sourceZone),
977
- action.destinationZone
978
- );
979
- const item = getItem(
980
- { zone: action.sourceZone, index: action.sourceIndex },
981
- newData
982
- );
983
- if (action.sourceZone === action.destinationZone) {
984
- return reorderAction(data, __spreadProps(__spreadValues({}, action), { type: "reorder" }));
1139
+ const item = getItem(
1140
+ { zone: action.sourceZone, index: action.sourceIndex },
1141
+ state
1142
+ );
1143
+ if (!item) return state;
1144
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
1145
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
1146
+ return walkAppState(
1147
+ state,
1148
+ appStore.config,
1149
+ (content, zoneCompound) => {
1150
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
1151
+ return insert(
1152
+ remove(content, action.sourceIndex),
1153
+ action.destinationIndex,
1154
+ item
1155
+ );
1156
+ } else if (zoneCompound === action.sourceZone) {
1157
+ return remove(content, action.sourceIndex);
1158
+ } else if (zoneCompound === action.destinationZone) {
1159
+ return insert(content, action.destinationIndex, item);
1160
+ }
1161
+ return content;
1162
+ },
1163
+ (childItem, path) => {
1164
+ const [sourceZoneParent] = action.sourceZone.split(":");
1165
+ const [destinationZoneParent] = action.destinationZone.split(":");
1166
+ const childId = childItem.props.id;
1167
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
1168
+ return childItem;
1169
+ }
1170
+ return null;
985
1171
  }
986
- if (action.sourceZone === rootDroppableId) {
987
- return __spreadProps(__spreadValues({}, newData), {
988
- content: remove(newData.content, action.sourceIndex),
989
- zones: __spreadProps(__spreadValues({}, newData.zones), {
990
- [action.destinationZone]: insert(
991
- newData.zones[action.destinationZone],
992
- action.destinationIndex,
993
- item
994
- )
995
- })
996
- });
1172
+ );
1173
+ };
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(
1205
+ state,
1206
+ appStore.config,
1207
+ (content, zoneCompound) => {
1208
+ if (zoneCompound === action.zone) {
1209
+ return remove(content, action.index);
1210
+ }
1211
+ return content;
997
1212
  }
998
- if (action.destinationZone === rootDroppableId) {
999
- return __spreadProps(__spreadValues({}, newData), {
1000
- content: insert(newData.content, action.destinationIndex, item),
1001
- zones: __spreadProps(__spreadValues({}, newData.zones), {
1002
- [action.sourceZone]: remove(
1003
- newData.zones[action.sourceZone],
1004
- action.sourceIndex
1005
- )
1006
- })
1007
- });
1213
+ );
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];
1008
1218
  }
1009
- return __spreadProps(__spreadValues({}, newData), {
1010
- zones: __spreadProps(__spreadValues({}, newData.zones), {
1011
- [action.sourceZone]: remove(
1012
- newData.zones[action.sourceZone],
1013
- action.sourceIndex
1014
- ),
1015
- [action.destinationZone]: insert(
1016
- newData.zones[action.destinationZone],
1017
- action.destinationIndex,
1018
- item
1019
- )
1020
- })
1021
- });
1022
- }
1023
- if (action.type === "replace") {
1024
- return replaceAction(data, action);
1025
- }
1026
- if (action.type === "remove") {
1027
- const item = getItem({ index: action.index, zone: action.zone }, data);
1028
- const dataWithRelatedRemoved = setupZone(
1029
- removeRelatedZones(item, data),
1030
- action.zone
1031
- );
1032
- if (action.zone === rootDroppableId) {
1033
- return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
1034
- content: remove(data.content, action.index)
1035
- });
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];
1036
1224
  }
1037
- return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
1038
- zones: __spreadProps(__spreadValues({}, dataWithRelatedRemoved.zones), {
1039
- [action.zone]: remove(
1040
- dataWithRelatedRemoved.zones[action.zone],
1041
- action.index
1042
- )
1043
- })
1044
- });
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;
1045
1240
  }
1046
- if (action.type === "registerZone") {
1047
- if (zoneCache[action.zone]) {
1048
- return __spreadProps(__spreadValues({}, data), {
1049
- zones: __spreadProps(__spreadValues({}, data.zones), {
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]) {
1252
+ return __spreadProps(__spreadValues({}, state), {
1253
+ data: __spreadProps(__spreadValues({}, state.data), {
1254
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
1050
1255
  [action.zone]: zoneCache[action.zone]
1051
1256
  })
1052
- });
1053
- }
1054
- return setupZone(data, action.zone);
1055
- }
1056
- if (action.type === "unregisterZone") {
1057
- const _zones = __spreadValues({}, data.zones || {});
1058
- if (_zones[action.zone]) {
1059
- zoneCache[action.zone] = _zones[action.zone];
1060
- delete _zones[action.zone];
1061
- }
1062
- return __spreadProps(__spreadValues({}, data), { zones: _zones });
1257
+ }),
1258
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
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
+ })
1265
+ })
1266
+ });
1063
1267
  }
1064
- if (action.type === "setData") {
1065
- if (typeof action.data === "object") {
1066
- return __spreadValues(__spreadValues({}, data), action.data);
1067
- }
1068
- return __spreadValues(__spreadValues({}, data), action.data(data));
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];
1069
1276
  }
1070
- return data;
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
+ });
1071
1286
  }
1072
1287
 
1073
- // ../core/reducer/state.ts
1288
+ // ../core/reducer/actions/set-data.ts
1074
1289
  init_react_import();
1075
- var reduceUi = (ui, action) => {
1076
- if (action.type === "setUi") {
1077
- if (typeof action.ui === "object") {
1078
- return __spreadValues(__spreadValues({}, ui), action.ui);
1079
- }
1080
- return __spreadValues(__spreadValues({}, ui), action.ui(ui));
1081
- }
1082
- if (action.type === "duplicate") {
1083
- return __spreadProps(__spreadValues({}, ui), {
1084
- itemSelector: { index: action.sourceIndex + 1, zone: action.sourceZone }
1085
- });
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(
1296
+ __spreadProps(__spreadValues({}, state), {
1297
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
1298
+ }),
1299
+ appStore.config
1300
+ );
1086
1301
  }
1087
- if (action.type === "remove") {
1088
- return __spreadProps(__spreadValues({}, ui), {
1089
- itemSelector: null
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") {
1314
+ return __spreadProps(__spreadValues({}, state), {
1315
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1090
1316
  });
1091
1317
  }
1092
- return ui;
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 };
1093
1328
  };
1094
1329
 
1095
1330
  // ../core/reducer/actions.tsx
@@ -1109,29 +1344,54 @@ function storeInterceptor(reducer, record, onAction) {
1109
1344
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1110
1345
  if (record) record(newAppState);
1111
1346
  }
1112
- onAction == null ? void 0 : onAction(action, newAppState, state);
1347
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1113
1348
  return newAppState;
1114
1349
  };
1115
1350
  }
1116
- var setAction = (state, action) => {
1117
- if (typeof action.state === "object") {
1118
- return __spreadValues(__spreadValues({}, state), action.state);
1119
- }
1120
- return __spreadValues(__spreadValues({}, state), action.state(state));
1121
- };
1122
1351
  function createReducer({
1123
- config,
1124
1352
  record,
1125
- onAction
1353
+ onAction,
1354
+ appStore
1126
1355
  }) {
1127
1356
  return storeInterceptor(
1128
1357
  (state, action) => {
1129
- const data = reduceData(state.data, action, config);
1130
- const ui = reduceUi(state.ui, action);
1131
1358
  if (action.type === "set") {
1132
- return setAction(state, action);
1359
+ return setAction(state, action, appStore);
1360
+ }
1361
+ if (action.type === "insert") {
1362
+ return insertAction(state, action, appStore);
1133
1363
  }
1134
- return { data, ui };
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;
1135
1395
  },
1136
1396
  record,
1137
1397
  onAction
@@ -1146,20 +1406,16 @@ var defaultViewports = [
1146
1406
  { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1147
1407
  ];
1148
1408
 
1149
- // ../../node_modules/zustand/esm/index.mjs
1150
- init_react_import();
1151
-
1152
1409
  // ../../node_modules/zustand/esm/vanilla.mjs
1153
1410
  init_react_import();
1154
- var import_meta = {};
1155
1411
  var createStoreImpl = (createState) => {
1156
1412
  let state;
1157
1413
  const listeners = /* @__PURE__ */ new Set();
1158
- const setState = (partial, replace2) => {
1414
+ const setState = (partial, replace) => {
1159
1415
  const nextState = typeof partial === "function" ? partial(state) : partial;
1160
1416
  if (!Object.is(nextState, state)) {
1161
1417
  const previousState = state;
1162
- state = (replace2 != null ? replace2 : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
1418
+ state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
1163
1419
  listeners.forEach((listener) => listener(state, previousState));
1164
1420
  }
1165
1421
  };
@@ -1169,53 +1425,28 @@ var createStoreImpl = (createState) => {
1169
1425
  listeners.add(listener);
1170
1426
  return () => listeners.delete(listener);
1171
1427
  };
1172
- const destroy = () => {
1173
- if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
1174
- console.warn(
1175
- "[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."
1176
- );
1177
- }
1178
- listeners.clear();
1179
- };
1180
- const api = { setState, getState, getInitialState, subscribe, destroy };
1428
+ const api = { setState, getState, getInitialState, subscribe };
1181
1429
  const initialState = state = createState(setState, getState, api);
1182
1430
  return api;
1183
1431
  };
1184
1432
  var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
1185
1433
 
1186
- // ../../node_modules/zustand/esm/index.mjs
1434
+ // ../../node_modules/zustand/esm/react.mjs
1435
+ init_react_import();
1187
1436
  var import_react4 = __toESM(require("react"), 1);
1188
- var import_with_selector = __toESM(require_with_selector(), 1);
1189
- var import_meta2 = {};
1190
- var { useDebugValue } = import_react4.default;
1191
- var { useSyncExternalStoreWithSelector } = import_with_selector.default;
1192
- var didWarnAboutEqualityFn = false;
1193
1437
  var identity = (arg) => arg;
1194
- function useStore(api, selector = identity, equalityFn) {
1195
- if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && equalityFn && !didWarnAboutEqualityFn) {
1196
- console.warn(
1197
- "[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"
1198
- );
1199
- didWarnAboutEqualityFn = true;
1200
- }
1201
- const slice = useSyncExternalStoreWithSelector(
1438
+ function useStore(api, selector = identity) {
1439
+ const slice = import_react4.default.useSyncExternalStore(
1202
1440
  api.subscribe,
1203
- api.getState,
1204
- api.getServerState || api.getInitialState,
1205
- selector,
1206
- equalityFn
1441
+ () => selector(api.getState()),
1442
+ () => selector(api.getInitialState())
1207
1443
  );
1208
- useDebugValue(slice);
1444
+ import_react4.default.useDebugValue(slice);
1209
1445
  return slice;
1210
1446
  }
1211
1447
  var createImpl = (createState) => {
1212
- if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && typeof createState !== "function") {
1213
- console.warn(
1214
- "[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`."
1215
- );
1216
- }
1217
- const api = typeof createState === "function" ? createStore(createState) : createState;
1218
- const useBoundStore = (selector, equalityFn) => useStore(api, selector, equalityFn);
1448
+ const api = createStore(createState);
1449
+ const useBoundStore = (selector) => useStore(api, selector);
1219
1450
  Object.assign(useBoundStore, api);
1220
1451
  return useBoundStore;
1221
1452
  };
@@ -1248,208 +1479,8 @@ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1248
1479
  };
1249
1480
  var subscribeWithSelector = subscribeWithSelectorImpl;
1250
1481
 
1251
- // ../core/lib/resolve-data.ts
1252
- init_react_import();
1253
-
1254
- // ../core/lib/resolve-component-data.ts
1255
- init_react_import();
1256
-
1257
- // ../core/lib/get-changed.ts
1258
- init_react_import();
1259
- var getChanged = (newItem, oldItem) => {
1260
- return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1261
- const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1262
- const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1263
- return __spreadProps(__spreadValues({}, acc), {
1264
- [item]: oldItemProps[item] !== newItemProps[item]
1265
- });
1266
- }, {}) : {};
1267
- };
1268
-
1269
- // ../core/lib/resolve-component-data.ts
1270
- var cache = { lastChange: {} };
1271
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd) {
1272
- const configForItem = config.components[item.type];
1273
- if (configForItem.resolveData) {
1274
- const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
1275
- if (item && item === oldItem) {
1276
- return resolved;
1277
- }
1278
- const changed = getChanged(item, oldItem);
1279
- if (onResolveStart) {
1280
- onResolveStart(item);
1281
- }
1282
- const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1283
- changed,
1284
- lastData: oldItem,
1285
- metadata
1286
- });
1287
- const resolvedItem = __spreadProps(__spreadValues({}, item), {
1288
- props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1289
- });
1290
- if (Object.keys(readOnly).length) {
1291
- resolvedItem.readOnly = readOnly;
1292
- }
1293
- cache.lastChange[item.props.id] = {
1294
- item,
1295
- resolved: resolvedItem
1296
- };
1297
- if (onResolveEnd) {
1298
- onResolveEnd(resolvedItem);
1299
- }
1300
- return resolvedItem;
1301
- }
1302
- return item;
1303
- });
1304
-
1305
- // ../core/lib/apply-dynamic-props.ts
1306
- init_react_import();
1307
- var applyDynamicProps = (data, dynamicProps, rootData) => {
1308
- return __spreadProps(__spreadValues({}, data), {
1309
- root: rootData ? __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}) : data.root,
1310
- content: data.content.map((item) => {
1311
- return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1312
- }),
1313
- zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
1314
- return __spreadProps(__spreadValues({}, acc), {
1315
- [zoneKey]: data.zones[zoneKey].map((item) => {
1316
- return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1317
- })
1318
- });
1319
- }, {})
1320
- });
1321
- };
1322
-
1323
- // ../core/lib/resolve-root-data.ts
1324
- init_react_import();
1325
- var cache2 = {};
1326
- function resolveRootData(data, config, metadata) {
1327
- return __async(this, null, function* () {
1328
- var _a, _b, _c, _d, _e;
1329
- if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
1330
- if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
1331
- return cache2.lastChange.resolved;
1332
- }
1333
- const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
1334
- const rootWithProps = data.root;
1335
- const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
1336
- changed,
1337
- lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {},
1338
- metadata: metadata || {}
1339
- });
1340
- cache2.lastChange = {
1341
- original: data.root,
1342
- resolved: resolvedRoot
1343
- };
1344
- return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
1345
- props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
1346
- });
1347
- }
1348
- return data.root;
1349
- });
1350
- }
1351
-
1352
- // ../core/lib/flatten-data.ts
1353
- init_react_import();
1354
- var flattenData = (data) => {
1355
- return Object.keys(data.zones || {}).reduce(
1356
- (acc, zone) => [...acc, ...data.zones[zone]],
1357
- data.content
1358
- );
1359
- };
1360
-
1361
- // ../core/lib/resolve-data.ts
1362
- var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1363
- var resolveData = (newAppState, appStoreData) => {
1364
- const {
1365
- state: appState,
1366
- config,
1367
- dispatch,
1368
- resolveDataRuns,
1369
- setComponentLoading,
1370
- unsetComponentLoading,
1371
- metadata,
1372
- permissions
1373
- } = appStoreData;
1374
- const deferredSetStates = {};
1375
- const _setComponentLoading = (id, loading, defer = 0) => {
1376
- if (deferredSetStates[id]) {
1377
- clearTimeout(deferredSetStates[id]);
1378
- delete deferredSetStates[id];
1379
- }
1380
- deferredSetStates[id] = setTimeout(() => {
1381
- if (loading) {
1382
- setComponentLoading(id);
1383
- } else {
1384
- unsetComponentLoading(id);
1385
- }
1386
- delete deferredSetStates[id];
1387
- }, defer);
1388
- };
1389
- const runResolvers = () => __async(void 0, null, function* () {
1390
- const newData = newAppState.data;
1391
- const flatContent = flattenData(newData).filter(
1392
- (item) => {
1393
- var _a;
1394
- return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
1395
- }
1396
- );
1397
- const applyIfChange = (dynamicDataMap, dynamicRoot) => {
1398
- const processed = applyDynamicProps(
1399
- __spreadValues({}, appState.data),
1400
- dynamicDataMap,
1401
- dynamicRoot
1402
- );
1403
- const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
1404
- const containsChanges = !(0, import_fast_deep_equal.default)(appState, processedAppState);
1405
- if (containsChanges) {
1406
- dispatch({
1407
- type: "set",
1408
- state: (prev) => __spreadProps(__spreadValues({}, prev), {
1409
- data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
1410
- ui: resolveDataRuns > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
1411
- }),
1412
- recordHistory: resolveDataRuns > 0
1413
- });
1414
- }
1415
- };
1416
- const promises = [];
1417
- promises.push(
1418
- (() => __async(void 0, null, function* () {
1419
- _setComponentLoading("puck-root", true, 50);
1420
- const dynamicRoot = yield resolveRootData(newData, config, metadata);
1421
- applyIfChange({}, dynamicRoot);
1422
- _setComponentLoading("puck-root", false);
1423
- }))()
1424
- );
1425
- flatContent.forEach((item) => {
1426
- promises.push(
1427
- (() => __async(void 0, null, function* () {
1428
- permissions.resolvePermissions({ item }, true);
1429
- const dynamicData = yield resolveComponentData(
1430
- item,
1431
- config,
1432
- metadata,
1433
- (item2) => {
1434
- _setComponentLoading(item2.props.id, true, 50);
1435
- },
1436
- (item2) => {
1437
- deferredSetStates[item2.props.id];
1438
- _setComponentLoading(item2.props.id, false);
1439
- }
1440
- );
1441
- const dynamicDataMap = { [item.props.id]: dynamicData };
1442
- applyIfChange(dynamicDataMap);
1443
- }))()
1444
- );
1445
- });
1446
- yield Promise.all(promises);
1447
- });
1448
- return runResolvers();
1449
- };
1450
-
1451
1482
  // ../core/store/index.ts
1452
- var import_react10 = require("react");
1483
+ var import_react9 = require("react");
1453
1484
 
1454
1485
  // ../core/store/slices/history.ts
1455
1486
  init_react_import();
@@ -1555,7 +1586,7 @@ var createHistorySlice = (set, get) => {
1555
1586
  const { dispatch, history } = get();
1556
1587
  dispatch({
1557
1588
  type: "set",
1558
- 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
1559
1590
  });
1560
1591
  set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1561
1592
  },
@@ -1565,31 +1596,18 @@ var createHistorySlice = (set, get) => {
1565
1596
 
1566
1597
  // ../core/store/slices/nodes.ts
1567
1598
  init_react_import();
1568
- var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
1569
- var import_react7 = require("react");
1570
- var partialDeepEqual = (newItem, existingItem) => {
1571
- const filteredExistingItem = Object.keys(newItem).reduce(
1572
- (acc, key) => __spreadProps(__spreadValues({}, acc), { [key]: existingItem[key] }),
1573
- {}
1574
- );
1575
- return (0, import_fast_deep_equal2.default)(newItem, filteredExistingItem);
1576
- };
1577
1599
  var createNodesSlice = (set, get) => ({
1578
1600
  nodes: {},
1579
1601
  registerNode: (id, node) => {
1580
1602
  const s = get().nodes;
1581
- if (s.nodes[id] && partialDeepEqual(node, s.nodes[id])) {
1582
- return;
1583
- }
1584
1603
  const emptyNode = {
1585
1604
  id,
1586
- methods: { sync: () => null },
1587
- data: { props: { id }, type: "unknown" },
1588
- parentId: "",
1589
- zone: "",
1590
- path: [],
1591
- element: null,
1592
- index: -1
1605
+ methods: {
1606
+ sync: () => null,
1607
+ hideOverlay: () => null,
1608
+ showOverlay: () => null
1609
+ },
1610
+ element: null
1593
1611
  };
1594
1612
  const existingNode = s.nodes[id];
1595
1613
  set({
@@ -1619,36 +1637,62 @@ var createNodesSlice = (set, get) => ({
1619
1637
 
1620
1638
  // ../core/store/slices/permissions.ts
1621
1639
  init_react_import();
1622
- var import_react8 = require("react");
1640
+ var import_react7 = require("react");
1641
+
1642
+ // ../core/lib/data/flatten-data.ts
1643
+ init_react_import();
1644
+ var flattenData = (state, config) => {
1645
+ const data = [];
1646
+ walkAppState(
1647
+ state,
1648
+ config,
1649
+ (content) => content,
1650
+ (item) => {
1651
+ data.push(item);
1652
+ return null;
1653
+ }
1654
+ );
1655
+ return data;
1656
+ };
1657
+
1658
+ // ../core/lib/get-changed.ts
1659
+ init_react_import();
1660
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1661
+ var getChanged = (newItem, oldItem) => {
1662
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1663
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1664
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1665
+ return __spreadProps(__spreadValues({}, acc), {
1666
+ [item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
1667
+ });
1668
+ }, {}) : {};
1669
+ };
1670
+
1671
+ // ../core/store/slices/permissions.ts
1623
1672
  var createPermissionsSlice = (set, get) => {
1624
1673
  const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1625
- const { state, permissions } = get();
1626
- const { cache: cache3, globalPermissions } = permissions;
1674
+ const { state, permissions, config } = get();
1675
+ const { cache: cache2, globalPermissions } = permissions;
1627
1676
  const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1628
1677
  var _a, _b, _c;
1629
- const {
1630
- config,
1631
- state: appState,
1632
- setComponentLoading,
1633
- unsetComponentLoading
1634
- } = get();
1635
- const componentConfig = item2.type === "root" ? config.root : config.components[item2.type];
1678
+ const { config: config2, state: appState, setComponentLoading } = get();
1679
+ const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1636
1680
  if (!componentConfig) {
1637
1681
  return;
1638
1682
  }
1639
1683
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1640
1684
  if (componentConfig.resolvePermissions) {
1641
- const changed = getChanged(item2, (_a = cache3[item2.props.id]) == null ? void 0 : _a.lastData);
1685
+ const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1642
1686
  if (Object.values(changed).some((el) => el === true) || force2) {
1643
- setComponentLoading(item2.props.id);
1687
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1644
1688
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1645
1689
  item2,
1646
1690
  {
1647
1691
  changed,
1648
- lastPermissions: ((_b = cache3[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1692
+ lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1649
1693
  permissions: initialPermissions,
1650
- appState,
1651
- lastData: ((_c = cache3[item2.props.id]) == null ? void 0 : _c.lastData) || null
1694
+ appState: makeStatePublic(appState),
1695
+ lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1652
1696
  }
1653
1697
  );
1654
1698
  const latest = get().permissions;
@@ -1665,7 +1709,7 @@ var createPermissionsSlice = (set, get) => {
1665
1709
  })
1666
1710
  })
1667
1711
  });
1668
- unsetComponentLoading(item2.props.id);
1712
+ clearTimeout2();
1669
1713
  }
1670
1714
  }
1671
1715
  });
@@ -1675,7 +1719,7 @@ var createPermissionsSlice = (set, get) => {
1675
1719
  // Shim the root data in by conforming to component data shape
1676
1720
  {
1677
1721
  type: "root",
1678
- props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
1722
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1679
1723
  },
1680
1724
  force2
1681
1725
  );
@@ -1684,14 +1728,13 @@ var createPermissionsSlice = (set, get) => {
1684
1728
  if (item) {
1685
1729
  yield resolveDataForItem(item, force);
1686
1730
  } else if (type) {
1687
- flattenData(state.data).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1731
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1688
1732
  yield resolveDataForItem(item2, force);
1689
1733
  }));
1690
1734
  } else if (root) {
1691
1735
  resolveDataForRoot(force);
1692
1736
  } else {
1693
- resolveDataForRoot(force);
1694
- flattenData(state.data).map((item2) => __async(void 0, null, function* () {
1737
+ flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1695
1738
  yield resolveDataForItem(item2, force);
1696
1739
  }));
1697
1740
  }
@@ -1721,7 +1764,7 @@ var createPermissionsSlice = (set, get) => {
1721
1764
  } else if (root) {
1722
1765
  const rootConfig = config.root;
1723
1766
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1724
- const resolvedForItem = resolvedPermissions["puck-root"];
1767
+ const resolvedForItem = resolvedPermissions["root"];
1725
1768
  return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1726
1769
  }
1727
1770
  return globalPermissions;
@@ -1733,16 +1776,97 @@ var createPermissionsSlice = (set, get) => {
1733
1776
 
1734
1777
  // ../core/store/slices/fields.ts
1735
1778
  init_react_import();
1736
- var import_react9 = require("react");
1737
- var createFieldsStore = (_set, _get) => {
1779
+ var import_react8 = require("react");
1780
+ var createFieldsSlice = (_set, _get) => {
1738
1781
  return {
1739
1782
  fields: {},
1740
1783
  loading: false,
1741
- lastResolvedData: {}
1784
+ lastResolvedData: {},
1785
+ id: void 0
1742
1786
  };
1743
1787
  };
1744
1788
 
1745
- // ../core/store/index.ts
1789
+ // ../core/lib/resolve-component-data.ts
1790
+ init_react_import();
1791
+ var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
1792
+ var cache = { lastChange: {} };
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) {
1799
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1800
+ if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
1801
+ return { node: resolved, didChange: false };
1802
+ }
1803
+ const changed = getChanged(item, oldItem);
1804
+ if (onResolveStart) {
1805
+ onResolveStart(item);
1806
+ }
1807
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1808
+ changed,
1809
+ lastData: oldItem,
1810
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1811
+ trigger
1812
+ });
1813
+ resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
1814
+ if (Object.keys(readOnly).length) {
1815
+ resolvedItem.readOnly = readOnly;
1816
+ }
1817
+ }
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
+ };
1849
+ });
1850
+
1851
+ // ../core/lib/data/to-root.ts
1852
+ init_react_import();
1853
+ var toRoot = (item) => {
1854
+ if ("type" in item && item.type !== "root") {
1855
+ throw new Error("Converting non-root item to root.");
1856
+ }
1857
+ const { readOnly } = item;
1858
+ if (item.props) {
1859
+ if ("id" in item.props) {
1860
+ const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
1861
+ return { props, readOnly };
1862
+ }
1863
+ return { props: item.props, readOnly };
1864
+ }
1865
+ return { props: {}, readOnly };
1866
+ };
1867
+
1868
+ // ../core/store/default-app-state.ts
1869
+ init_react_import();
1746
1870
  var defaultAppState = {
1747
1871
  data: { content: [], root: {}, zones: {} },
1748
1872
  ui: {
@@ -1762,100 +1886,196 @@ var defaultAppState = {
1762
1886
  controlsVisible: true
1763
1887
  },
1764
1888
  field: { focus: null }
1889
+ },
1890
+ indexes: {
1891
+ nodes: {},
1892
+ zones: {}
1765
1893
  }
1766
1894
  };
1895
+
1896
+ // ../core/store/index.ts
1767
1897
  var defaultPageFields = {
1768
1898
  title: { type: "text" }
1769
1899
  };
1770
1900
  var createAppStore = (initialAppStore) => create()(
1771
- subscribeWithSelector((set, get) => __spreadProps(__spreadValues({
1772
- state: defaultAppState,
1773
- config: { components: {} },
1774
- componentState: {},
1775
- plugins: [],
1776
- overrides: {},
1777
- viewports: defaultViewports,
1778
- zoomConfig: {
1779
- autoZoom: 1,
1780
- rootHeight: 0,
1781
- zoom: 1
1782
- },
1783
- status: "LOADING",
1784
- iframe: {},
1785
- metadata: {}
1786
- }, initialAppStore), {
1787
- fields: createFieldsStore(set, get),
1788
- history: createHistorySlice(set, get),
1789
- nodes: createNodesSlice(set, get),
1790
- permissions: createPermissionsSlice(set, get),
1791
- getComponentConfig: (type) => {
1792
- var _a;
1793
- const { config, selectedItem } = get();
1794
- const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1795
- return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1796
- },
1797
- dispatch: (action) => set((s) => {
1798
- var _a, _b;
1799
- const { record } = get().history;
1800
- const dispatch = createReducer({ config: s.config, record });
1801
- const state = dispatch(s.state, action);
1802
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1803
- (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1804
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1805
- }),
1806
- setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1807
- setStatus: (status) => set({ status }),
1808
- setComponentState: (componentState) => set({ componentState }),
1809
- setComponentLoading: (id) => {
1810
- var _a;
1811
- const { setComponentState, componentState } = get();
1812
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1813
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1814
- loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1815
- })
1816
- }));
1817
- },
1818
- unsetComponentLoading: (id) => {
1819
- var _a;
1820
- const { setComponentState, componentState } = get();
1821
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1822
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1823
- loadingCount: Math.max(
1824
- (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1825
- 0
1826
- )
1827
- })
1828
- }));
1829
- },
1830
- // Helper
1831
- setUi: (ui, recordHistory) => set((s) => {
1832
- const dispatch = createReducer({
1833
- config: s.config,
1834
- record: () => {
1835
- }
1836
- });
1837
- const state = dispatch(s.state, {
1838
- type: "setUi",
1839
- ui,
1840
- recordHistory
1841
- });
1842
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1843
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1844
- }),
1845
- resolveDataRuns: 0,
1846
- resolveData: (newAppState) => set((s) => {
1847
- resolveData(newAppState, get());
1848
- return __spreadProps(__spreadValues({}, s), { resolveDataRuns: s.resolveDataRuns + 1 });
1849
- })
1850
- }))
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
1988
+ })
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 });
2028
+ }
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
+ })
1851
2071
  );
1852
- var appStoreContext = (0, import_react10.createContext)(createAppStore());
2072
+ var appStoreContext = (0, import_react9.createContext)(createAppStore());
1853
2073
  function useAppStore(selector) {
1854
- const context = (0, import_react10.useContext)(appStoreContext);
2074
+ const context = (0, import_react9.useContext)(appStoreContext);
1855
2075
  return useStore(context, selector);
1856
2076
  }
1857
2077
  function useAppStoreApi() {
1858
- return (0, import_react10.useContext)(appStoreContext);
2078
+ return (0, import_react9.useContext)(appStoreContext);
1859
2079
  }
1860
2080
 
1861
2081
  // ../core/lib/use-breadcrumbs.ts
@@ -1867,12 +2087,12 @@ var useBreadcrumbs = (renderCount) => {
1867
2087
  const config = useAppStore((s) => s.config);
1868
2088
  const path = useAppStore((s) => {
1869
2089
  var _a;
1870
- return (_a = s.nodes.nodes[selectedId]) == null ? void 0 : _a.path;
2090
+ return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
1871
2091
  });
1872
2092
  const appStore = useAppStoreApi();
1873
- return (0, import_react11.useMemo)(() => {
2093
+ return (0, import_react10.useMemo)(() => {
1874
2094
  const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
1875
- var _a, _b;
2095
+ var _a, _b, _c;
1876
2096
  const [componentId] = zoneCompound.split(":");
1877
2097
  if (componentId === "root") {
1878
2098
  return {
@@ -1880,12 +2100,15 @@ var useBreadcrumbs = (renderCount) => {
1880
2100
  selector: null
1881
2101
  };
1882
2102
  }
1883
- const node = appStore.getState().nodes.nodes[componentId];
1884
- const label = node ? (_b = (_a = config.components[node.data.type]) == null ? void 0 : _a.label) != null ? _b : node.data.type : "Component";
2103
+ const node = appStore.getState().state.indexes.nodes[componentId];
2104
+ const parentId = node.path[node.path.length - 1];
2105
+ const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
2106
+ const index = contentIds.indexOf(componentId);
2107
+ const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
1885
2108
  return {
1886
2109
  label,
1887
2110
  selector: node ? {
1888
- index: node.index,
2111
+ index,
1889
2112
  zone: node.path[node.path.length - 1]
1890
2113
  } : null
1891
2114
  };
@@ -1906,6 +2129,12 @@ init_react_import();
1906
2129
  // ../core/lib/filter.ts
1907
2130
  init_react_import();
1908
2131
 
2132
+ // ../core/lib/data/reorder.ts
2133
+ init_react_import();
2134
+
2135
+ // ../core/lib/data/replace.ts
2136
+ init_react_import();
2137
+
1909
2138
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
1910
2139
  init_react_import();
1911
2140
  var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
@@ -2086,18 +2315,40 @@ function buildHierarchy(frame) {
2086
2315
  var usePuck = (0, import_puck.createUsePuck)();
2087
2316
  var HeadingAnalyzer = () => {
2088
2317
  const data = usePuck((s) => s.appState.data);
2089
- const [hierarchy, setHierarchy] = (0, import_react12.useState)([]);
2090
- (0, import_react12.useEffect)(() => {
2318
+ const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
2319
+ (0, import_react11.useEffect)(() => {
2091
2320
  const frame = getFrame();
2092
- const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2093
- if (!entry) return;
2094
- setHierarchy(buildHierarchy(entry));
2095
- const observer = new MutationObserver(() => {
2321
+ let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2322
+ const createHierarchy = () => {
2096
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
+ }
2097
2334
  });
2098
- 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
+ }
2099
2349
  return () => {
2100
- observer.disconnect();
2350
+ entryObserver.disconnect();
2351
+ frameObserver.disconnect();
2101
2352
  };
2102
2353
  }, [data]);
2103
2354
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [
@@ -2197,50 +2448,6 @@ classnames/index.js:
2197
2448
  http://jedwatson.github.io/classnames
2198
2449
  *)
2199
2450
 
2200
- use-sync-external-store/cjs/use-sync-external-store-shim.production.js:
2201
- (**
2202
- * @license React
2203
- * use-sync-external-store-shim.production.js
2204
- *
2205
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2206
- *
2207
- * This source code is licensed under the MIT license found in the
2208
- * LICENSE file in the root directory of this source tree.
2209
- *)
2210
-
2211
- use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
2212
- (**
2213
- * @license React
2214
- * use-sync-external-store-shim.development.js
2215
- *
2216
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2217
- *
2218
- * This source code is licensed under the MIT license found in the
2219
- * LICENSE file in the root directory of this source tree.
2220
- *)
2221
-
2222
- use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js:
2223
- (**
2224
- * @license React
2225
- * use-sync-external-store-shim/with-selector.production.js
2226
- *
2227
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2228
- *
2229
- * This source code is licensed under the MIT license found in the
2230
- * LICENSE file in the root directory of this source tree.
2231
- *)
2232
-
2233
- use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js:
2234
- (**
2235
- * @license React
2236
- * use-sync-external-store-shim/with-selector.development.js
2237
- *
2238
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2239
- *
2240
- * This source code is licensed under the MIT license found in the
2241
- * LICENSE file in the root directory of this source tree.
2242
- *)
2243
-
2244
2451
  lucide-react/dist/esm/shared/src/utils.js:
2245
2452
  (**
2246
2453
  * @license lucide-react v0.468.0 - ISC