@measured/puck-plugin-heading-analyzer 0.19.0-canary.0ea6ce4 → 0.19.0-canary.1918ad70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -61,6 +61,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
61
61
  mod
62
62
  ));
63
63
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
64
+ var __async = (__this, __arguments, generator) => {
65
+ return new Promise((resolve, reject) => {
66
+ var fulfilled = (value) => {
67
+ try {
68
+ step(generator.next(value));
69
+ } catch (e) {
70
+ reject(e);
71
+ }
72
+ };
73
+ var rejected = (value) => {
74
+ try {
75
+ step(generator.throw(value));
76
+ } catch (e) {
77
+ reject(e);
78
+ }
79
+ };
80
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
81
+ step((generator = generator.apply(__this, __arguments)).next());
82
+ });
83
+ };
64
84
 
65
85
  // ../tsup-config/react-import.js
66
86
  var import_react;
@@ -133,6 +153,42 @@ var require_classnames = __commonJS({
133
153
  }
134
154
  });
135
155
 
156
+ // ../../node_modules/fast-deep-equal/index.js
157
+ var require_fast_deep_equal = __commonJS({
158
+ "../../node_modules/fast-deep-equal/index.js"(exports2, module2) {
159
+ "use strict";
160
+ init_react_import();
161
+ module2.exports = function equal(a, b) {
162
+ if (a === b) return true;
163
+ if (a && b && typeof a == "object" && typeof b == "object") {
164
+ if (a.constructor !== b.constructor) return false;
165
+ var length, i, keys;
166
+ if (Array.isArray(a)) {
167
+ length = a.length;
168
+ if (length != b.length) return false;
169
+ for (i = length; i-- !== 0; )
170
+ if (!equal(a[i], b[i])) return false;
171
+ return true;
172
+ }
173
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
174
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
175
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
176
+ keys = Object.keys(a);
177
+ length = keys.length;
178
+ if (length !== Object.keys(b).length) return false;
179
+ for (i = length; i-- !== 0; )
180
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
181
+ for (i = length; i-- !== 0; ) {
182
+ var key = keys[i];
183
+ if (!equal(a[key], b[key])) return false;
184
+ }
185
+ return true;
186
+ }
187
+ return a !== a && b !== b;
188
+ };
189
+ }
190
+ });
191
+
136
192
  // index.ts
137
193
  var plugin_heading_analyzer_exports = {};
138
194
  __export(plugin_heading_analyzer_exports, {
@@ -143,7 +199,7 @@ init_react_import();
143
199
 
144
200
  // src/HeadingAnalyzer.tsx
145
201
  init_react_import();
146
- var import_react9 = require("react");
202
+ var import_react11 = require("react");
147
203
 
148
204
  // css-module:/home/runner/work/puck/puck/packages/plugin-heading-analyzer/src/HeadingAnalyzer.module.css#css-module
149
205
  init_react_import();
@@ -304,122 +360,701 @@ var ChevronRight = createLucideIcon("ChevronRight", [
304
360
 
305
361
  // ../core/lib/use-breadcrumbs.ts
306
362
  init_react_import();
307
- var import_react8 = require("react");
363
+ var import_react10 = require("react");
308
364
 
309
- // ../core/components/DropZone/context.tsx
365
+ // ../core/store/index.ts
310
366
  init_react_import();
311
- var import_react7 = require("react");
312
367
 
313
- // ../core/components/Puck/context.tsx
368
+ // ../core/reducer/index.ts
314
369
  init_react_import();
315
- var import_react6 = require("react");
316
370
 
317
- // ../core/lib/get-item.ts
371
+ // ../core/reducer/reduce.ts
372
+ init_react_import();
373
+
374
+ // ../core/lib/insert.ts
375
+ init_react_import();
376
+ var insert = (list, index, item) => {
377
+ const result = Array.from(list || []);
378
+ result.splice(index, 0, item);
379
+ return result;
380
+ };
381
+
382
+ // ../core/lib/remove.ts
383
+ init_react_import();
384
+ var remove = (list, index) => {
385
+ const result = Array.from(list);
386
+ result.splice(index, 1);
387
+ return result;
388
+ };
389
+
390
+ // ../core/lib/setup-zone.ts
318
391
  init_react_import();
319
392
 
320
393
  // ../core/lib/root-droppable-id.ts
321
394
  init_react_import();
322
- var rootDroppableId = "default-zone";
395
+ var rootAreaId = "root";
396
+ var rootZone = "default-zone";
397
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
323
398
 
324
399
  // ../core/lib/setup-zone.ts
400
+ var setupZone = (data, zoneKey) => {
401
+ if (zoneKey === rootDroppableId) {
402
+ return data;
403
+ }
404
+ const newData = __spreadProps(__spreadValues({}, data), {
405
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
406
+ });
407
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
408
+ return newData;
409
+ };
410
+
411
+ // ../core/lib/get-item.ts
325
412
  init_react_import();
413
+ function getItem(selector, state) {
414
+ var _a, _b;
415
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
416
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
417
+ }
326
418
 
327
- // ../core/components/ViewportControls/default-viewports.ts
419
+ // ../core/lib/generate-id.ts
328
420
  init_react_import();
329
- var defaultViewports = [
330
- { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
331
- { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
332
- { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
333
- ];
334
421
 
335
- // ../core/lib/use-resolved-permissions.ts
422
+ // ../../node_modules/uuid/dist/esm-node/index.js
336
423
  init_react_import();
337
- var import_react4 = require("react");
338
424
 
339
- // ../core/lib/flatten-data.ts
425
+ // ../../node_modules/uuid/dist/esm-node/rng.js
340
426
  init_react_import();
427
+ var import_crypto = __toESM(require("crypto"));
428
+ var rnds8Pool = new Uint8Array(256);
429
+ var poolPtr = rnds8Pool.length;
430
+ function rng() {
431
+ if (poolPtr > rnds8Pool.length - 16) {
432
+ import_crypto.default.randomFillSync(rnds8Pool);
433
+ poolPtr = 0;
434
+ }
435
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
436
+ }
341
437
 
342
- // ../core/lib/get-changed.ts
438
+ // ../../node_modules/uuid/dist/esm-node/stringify.js
343
439
  init_react_import();
440
+ var byteToHex = [];
441
+ for (let i = 0; i < 256; ++i) {
442
+ byteToHex.push((i + 256).toString(16).slice(1));
443
+ }
444
+ function unsafeStringify(arr, offset = 0) {
445
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
446
+ }
344
447
 
345
- // ../core/lib/use-resolved-data.ts
448
+ // ../../node_modules/uuid/dist/esm-node/v4.js
346
449
  init_react_import();
347
- var import_react5 = require("react");
348
450
 
349
- // ../core/lib/resolve-component-data.ts
451
+ // ../../node_modules/uuid/dist/esm-node/native.js
452
+ init_react_import();
453
+ var import_crypto2 = __toESM(require("crypto"));
454
+ var native_default = {
455
+ randomUUID: import_crypto2.default.randomUUID
456
+ };
457
+
458
+ // ../../node_modules/uuid/dist/esm-node/v4.js
459
+ function v4(options, buf, offset) {
460
+ if (native_default.randomUUID && !buf && !options) {
461
+ return native_default.randomUUID();
462
+ }
463
+ options = options || {};
464
+ const rnds = options.random || (options.rng || rng)();
465
+ rnds[6] = rnds[6] & 15 | 64;
466
+ rnds[8] = rnds[8] & 63 | 128;
467
+ if (buf) {
468
+ offset = offset || 0;
469
+ for (let i = 0; i < 16; ++i) {
470
+ buf[offset + i] = rnds[i];
471
+ }
472
+ return buf;
473
+ }
474
+ return unsafeStringify(rnds);
475
+ }
476
+ var v4_default = v4;
477
+
478
+ // ../core/lib/generate-id.ts
479
+ var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
480
+
481
+ // ../core/lib/walk-tree.ts
350
482
  init_react_import();
351
483
 
352
- // ../core/lib/apply-dynamic-props.ts
484
+ // ../core/lib/for-each-slot.ts
353
485
  init_react_import();
354
486
 
355
- // ../core/lib/resolve-root-data.ts
487
+ // ../core/lib/is-slot.ts
356
488
  init_react_import();
489
+ var isSlot = (prop) => {
490
+ var _a, _b;
491
+ return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
492
+ };
357
493
 
358
- // ../core/components/Puck/context.tsx
359
- var import_jsx_runtime2 = require("react/jsx-runtime");
360
- var defaultAppState = {
361
- data: { content: [], root: {} },
362
- ui: {
363
- leftSideBarVisible: true,
364
- rightSideBarVisible: true,
365
- arrayState: {},
366
- itemSelector: null,
367
- componentList: {},
368
- isDragging: false,
369
- previewMode: "edit",
370
- viewports: {
371
- current: {
372
- width: defaultViewports[0].width,
373
- height: defaultViewports[0].height || "auto"
494
+ // ../core/lib/for-each-slot.ts
495
+ var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, cb, recursive = false, isSlot2 = isSlot) {
496
+ const props = item.props || {};
497
+ const propKeys = Object.keys(props);
498
+ for (let i = 0; i < propKeys.length; i++) {
499
+ const propKey = propKeys[i];
500
+ const itemType = "type" in item ? item.type : "root";
501
+ if (isSlot2(itemType, propKey, props[propKey])) {
502
+ const content = props[propKey];
503
+ yield cb(props.id, propKey, content);
504
+ if (recursive) {
505
+ content.forEach(
506
+ (childItem) => __async(void 0, null, function* () {
507
+ return yield forEachSlot(childItem, cb, true, isSlot2);
508
+ })
509
+ );
510
+ }
511
+ }
512
+ }
513
+ });
514
+
515
+ // ../core/lib/for-related-zones.ts
516
+ init_react_import();
517
+
518
+ // ../core/lib/get-zone-id.ts
519
+ init_react_import();
520
+ var getZoneId = (zoneCompound) => {
521
+ if (!zoneCompound) {
522
+ return [];
523
+ }
524
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
525
+ return zoneCompound.split(":");
526
+ }
527
+ return [rootDroppableId, zoneCompound];
528
+ };
529
+
530
+ // ../core/lib/for-related-zones.ts
531
+ function forRelatedZones(item, data, cb, path = []) {
532
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
533
+ const [parentId] = getZoneId(zoneCompound);
534
+ if (parentId === item.props.id) {
535
+ const newPath = [...path, zoneCompound];
536
+ content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
537
+ cb(path, zoneCompound, content);
538
+ }
539
+ });
540
+ }
541
+
542
+ // ../core/lib/strip-slots.ts
543
+ init_react_import();
544
+ var stripSlots = (data) => {
545
+ return __spreadProps(__spreadValues({}, data), {
546
+ props: Object.entries(data.props).reduce(
547
+ (acc, [propKey, propVal]) => {
548
+ if (isSlot(propVal)) {
549
+ return acc;
550
+ }
551
+ return __spreadProps(__spreadValues({}, acc), { [propKey]: propVal });
374
552
  },
375
- options: [],
376
- controlsVisible: true
553
+ { id: data.props.id }
554
+ )
555
+ });
556
+ };
557
+
558
+ // ../core/lib/walk-tree.ts
559
+ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
560
+ var _a;
561
+ let newZones = {};
562
+ const newZoneIndex = {};
563
+ const newNodeIndex = {};
564
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
565
+ var _a2;
566
+ const [parentId] = zoneCompound.split(":");
567
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
568
+ const [_2, zone] = zoneCompound.split(":");
569
+ const newZoneCompound = `${newId || parentId}:${zone}`;
570
+ const newContent2 = mappedContent.map(
571
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
572
+ );
573
+ newZoneIndex[newZoneCompound] = {
574
+ contentIds: newContent2.map((item) => item.props.id),
575
+ type: zoneType
576
+ };
577
+ return [newZoneCompound, newContent2];
578
+ };
579
+ const processRelatedZones = (item, newId, initialPath) => {
580
+ forRelatedZones(
581
+ item,
582
+ state.data,
583
+ (relatedPath, relatedZoneCompound, relatedContent) => {
584
+ const [zoneCompound, newContent2] = processContent(
585
+ relatedPath,
586
+ relatedZoneCompound,
587
+ relatedContent,
588
+ "dropzone",
589
+ newId
590
+ );
591
+ newZones[zoneCompound] = newContent2;
592
+ },
593
+ initialPath
594
+ );
595
+ };
596
+ const processItem = (item, path, index) => {
597
+ const mappedItem = mapNodeOrSkip(item, path, index);
598
+ if (!mappedItem) return item;
599
+ const id = mappedItem.props.id;
600
+ processRelatedZones(item, id, path);
601
+ const newProps = __spreadValues({}, mappedItem.props);
602
+ forEachSlot(
603
+ mappedItem,
604
+ (parentId2, slotId, content) => {
605
+ const zoneCompound = `${parentId2}:${slotId}`;
606
+ const [_2, newContent2] = processContent(
607
+ path,
608
+ zoneCompound,
609
+ content,
610
+ "slot",
611
+ parentId2
612
+ );
613
+ newProps[slotId] = newContent2;
614
+ },
615
+ false,
616
+ (itemType, propName, propValue) => {
617
+ var _a2, _b;
618
+ const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
619
+ if (!configForComponent) return isSlot(propValue);
620
+ return ((_b = (_a2 = configForComponent.fields) == null ? void 0 : _a2[propName]) == null ? void 0 : _b.type) === "slot";
621
+ }
622
+ );
623
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
624
+ const thisZoneCompound = path[path.length - 1];
625
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
626
+ newNodeIndex[id] = {
627
+ data: newItem,
628
+ flatData: stripSlots(newItem),
629
+ path,
630
+ parentId,
631
+ zone
632
+ };
633
+ const finalData = newItem;
634
+ if (newProps.id === "root") {
635
+ delete finalData["type"];
636
+ delete finalData.props["id"];
637
+ }
638
+ return finalData;
639
+ };
640
+ const zones = state.data.zones || {};
641
+ const [_, newContent] = processContent(
642
+ [],
643
+ rootDroppableId,
644
+ state.data.content,
645
+ "root"
646
+ );
647
+ const processedContent = newContent;
648
+ Object.keys(zones || {}).forEach((zoneCompound) => {
649
+ const [parentId] = zoneCompound.split(":");
650
+ const [_2, newContent2] = processContent(
651
+ [rootDroppableId],
652
+ zoneCompound,
653
+ zones[zoneCompound],
654
+ "dropzone",
655
+ parentId
656
+ );
657
+ newZones[zoneCompound] = newContent2;
658
+ }, newZones);
659
+ const processedRoot = processItem(
660
+ {
661
+ type: "root",
662
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
377
663
  },
378
- field: { focus: null }
664
+ [],
665
+ -1
666
+ );
667
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
668
+ props: processedRoot.props
669
+ });
670
+ return __spreadProps(__spreadValues({}, state), {
671
+ data: {
672
+ root,
673
+ // root: state.data.root, // TODO changing root causes it's entire subtree to re-render. Let's keep this disabled until the performance issues are resolved in #644.
674
+ content: processedContent,
675
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
676
+ },
677
+ indexes: {
678
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
679
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
680
+ }
681
+ });
682
+ }
683
+
684
+ // ../core/lib/deindex.ts
685
+ init_react_import();
686
+ var deindex = (state, componentData) => {
687
+ let zones = __spreadValues({}, state.indexes.zones);
688
+ let nodes = __spreadValues({}, state.indexes.nodes);
689
+ const dindexRelatedZones = (item) => {
690
+ forRelatedZones(item, state.data, (_path, zoneCompound, content) => {
691
+ content.forEach((subItem) => {
692
+ dindexChildren(subItem);
693
+ delete nodes[subItem.props.id];
694
+ });
695
+ delete zones[zoneCompound];
696
+ });
697
+ };
698
+ const dindexChildren = (item) => {
699
+ forEachSlot(
700
+ item,
701
+ (parentId, slotId, content) => {
702
+ const zoneCompound = `${parentId}:${slotId}`;
703
+ delete zones[zoneCompound];
704
+ content.forEach((item2) => {
705
+ dindexRelatedZones(item2);
706
+ delete nodes[item2.props.id];
707
+ });
708
+ },
709
+ true
710
+ );
711
+ };
712
+ dindexRelatedZones(componentData);
713
+ dindexChildren(componentData);
714
+ delete nodes[componentData.props.id];
715
+ return { nodes, zones };
716
+ };
717
+
718
+ // ../core/reducer/reduce.ts
719
+ var zoneCache = {};
720
+ var getIdsForParent = (zoneCompound, state) => {
721
+ const [parentId] = zoneCompound.split(":");
722
+ const node = state.indexes.nodes[parentId];
723
+ return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
724
+ };
725
+ function insertAction(state, action, config) {
726
+ const id = action.id || generateId(action.componentType);
727
+ const emptyComponentData = {
728
+ type: action.componentType,
729
+ props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
730
+ id
731
+ })
732
+ };
733
+ const [parentId] = action.destinationZone.split(":");
734
+ const idsInPath = getIdsForParent(action.destinationZone, state);
735
+ return walkTree(
736
+ state,
737
+ config,
738
+ (content, zoneCompound) => {
739
+ if (zoneCompound === action.destinationZone) {
740
+ return insert(
741
+ content || [],
742
+ action.destinationIndex,
743
+ emptyComponentData
744
+ );
745
+ }
746
+ return content;
747
+ },
748
+ (childItem) => {
749
+ if (childItem.props.id === id || childItem.props.id === parentId) {
750
+ return childItem;
751
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
752
+ return childItem;
753
+ }
754
+ return null;
755
+ }
756
+ );
757
+ }
758
+ var moveAction = (state, action, appStore) => {
759
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
760
+ return state;
379
761
  }
762
+ const item = getItem(
763
+ { zone: action.sourceZone, index: action.sourceIndex },
764
+ state
765
+ );
766
+ if (!item) return state;
767
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
768
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
769
+ return walkTree(
770
+ state,
771
+ appStore.config,
772
+ (content, zoneCompound) => {
773
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
774
+ return insert(
775
+ remove(content, action.sourceIndex),
776
+ action.destinationIndex,
777
+ item
778
+ );
779
+ } else if (zoneCompound === action.sourceZone) {
780
+ return remove(content, action.sourceIndex);
781
+ } else if (zoneCompound === action.destinationZone) {
782
+ return insert(content, action.destinationIndex, item);
783
+ }
784
+ return content;
785
+ },
786
+ (childItem) => {
787
+ const [sourceZoneParent] = action.sourceZone.split(":");
788
+ const [destinationZoneParent] = action.destinationZone.split(":");
789
+ const childId = childItem.props.id;
790
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1) {
791
+ return childItem;
792
+ }
793
+ return null;
794
+ }
795
+ );
380
796
  };
381
- var defaultContext = {
382
- state: defaultAppState,
383
- dispatch: () => null,
384
- config: { components: {} },
385
- componentState: {},
386
- setComponentState: () => {
387
- },
388
- resolveData: () => {
389
- },
390
- plugins: [],
391
- overrides: {},
392
- history: {},
393
- viewports: defaultViewports,
394
- zoomConfig: {
395
- autoZoom: 1,
396
- rootHeight: 0,
397
- zoom: 1
398
- },
399
- setZoomConfig: () => null,
400
- status: "LOADING",
401
- setStatus: () => null,
402
- iframe: {},
403
- globalPermissions: {},
404
- getPermissions: () => ({}),
405
- refreshPermissions: () => null,
406
- metadata: {}
407
- };
408
- var appContext = (0, import_react6.createContext)(defaultContext);
409
- function useAppContext() {
410
- const mainContext = (0, import_react6.useContext)(appContext);
411
- return __spreadProps(__spreadValues({}, mainContext), {
412
- // Helpers
413
- setUi: (ui, recordHistory) => {
414
- return mainContext.dispatch({
415
- type: "setUi",
416
- ui,
417
- recordHistory
797
+ var replaceAction = (state, action, appStore) => {
798
+ const [parentId] = action.destinationZone.split(":");
799
+ const idsInPath = getIdsForParent(action.destinationZone, state);
800
+ return walkTree(
801
+ state,
802
+ appStore.config,
803
+ (content) => content,
804
+ (childItem, path) => {
805
+ const pathIds = path.map((p) => p.split(":")[0]);
806
+ if (childItem.props.id === action.data.props.id) {
807
+ return action.data;
808
+ } else if (childItem.props.id === parentId) {
809
+ return childItem;
810
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
811
+ return childItem;
812
+ } else if (pathIds.indexOf(action.data.props.id) > -1) {
813
+ return childItem;
814
+ }
815
+ return null;
816
+ }
817
+ );
818
+ };
819
+ var setAction = (state, action, appStore) => {
820
+ if (typeof action.state === "object") {
821
+ const newState = __spreadValues(__spreadValues({}, state), action.state);
822
+ if (action.state.indexes) {
823
+ console.warn(
824
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
825
+ );
826
+ return newState;
827
+ }
828
+ return walkTree(newState, appStore.config);
829
+ }
830
+ return __spreadValues(__spreadValues({}, state), action.state(state));
831
+ };
832
+ function reduce(state, action, appStore) {
833
+ if (action.type === "set") {
834
+ return setAction(state, action, appStore);
835
+ }
836
+ if (action.type === "insert") {
837
+ return insertAction(state, action, appStore.config);
838
+ }
839
+ if (action.type === "replace") {
840
+ return replaceAction(state, action, appStore);
841
+ }
842
+ if (action.type === "replaceRoot") {
843
+ return walkTree(
844
+ state,
845
+ appStore.config,
846
+ (content) => content,
847
+ (childItem) => {
848
+ if (childItem.props.id === "root") {
849
+ return __spreadProps(__spreadValues({}, childItem), {
850
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
851
+ readOnly: action.root.readOnly
852
+ });
853
+ }
854
+ return childItem;
855
+ }
856
+ );
857
+ }
858
+ if (action.type === "duplicate") {
859
+ const item = getItem(
860
+ { index: action.sourceIndex, zone: action.sourceZone },
861
+ state
862
+ );
863
+ const idsInPath = getIdsForParent(action.sourceZone, state);
864
+ const newItem = __spreadProps(__spreadValues({}, item), {
865
+ props: __spreadProps(__spreadValues({}, item.props), {
866
+ id: generateId(item.type)
867
+ })
868
+ });
869
+ const modified = walkTree(
870
+ state,
871
+ appStore.config,
872
+ (content, zoneCompound) => {
873
+ if (zoneCompound === action.sourceZone) {
874
+ return insert(content, action.sourceIndex + 1, item);
875
+ }
876
+ return content;
877
+ },
878
+ (childItem, path, index) => {
879
+ const zoneCompound = path[path.length - 1];
880
+ const parents = path.map((p) => p.split(":")[0]);
881
+ if (parents.indexOf(newItem.props.id) > -1) {
882
+ return __spreadProps(__spreadValues({}, childItem), {
883
+ props: __spreadProps(__spreadValues({}, childItem.props), {
884
+ id: generateId(childItem.type)
885
+ })
886
+ });
887
+ }
888
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
889
+ return newItem;
890
+ }
891
+ const [sourceZoneParent] = action.sourceZone.split(":");
892
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
893
+ return childItem;
894
+ }
895
+ return null;
896
+ }
897
+ );
898
+ return __spreadProps(__spreadValues({}, modified), {
899
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
900
+ itemSelector: {
901
+ index: action.sourceIndex + 1,
902
+ zone: action.sourceZone
903
+ }
904
+ })
905
+ });
906
+ }
907
+ if (action.type === "reorder") {
908
+ return moveAction(
909
+ state,
910
+ {
911
+ type: "move",
912
+ sourceIndex: action.sourceIndex,
913
+ sourceZone: action.destinationZone,
914
+ destinationIndex: action.destinationIndex,
915
+ destinationZone: action.destinationZone
916
+ },
917
+ appStore
918
+ );
919
+ }
920
+ if (action.type === "move") {
921
+ return moveAction(state, action, appStore);
922
+ }
923
+ if (action.type === "remove") {
924
+ const item = getItem({ index: action.index, zone: action.zone }, state);
925
+ let deindexed = deindex(state, item);
926
+ const [parentId] = action.zone.split(":");
927
+ return walkTree(
928
+ __spreadProps(__spreadValues({}, state), { indexes: deindexed }),
929
+ appStore.config,
930
+ (content, zoneCompound) => {
931
+ if (zoneCompound === action.zone) {
932
+ return remove(content, action.index);
933
+ }
934
+ return content;
935
+ },
936
+ (childItem, path) => {
937
+ const parentIds = path.map((p) => p.split(":")[0]);
938
+ if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
939
+ return childItem;
940
+ }
941
+ return null;
942
+ }
943
+ );
944
+ }
945
+ if (action.type === "registerZone") {
946
+ if (zoneCache[action.zone]) {
947
+ return __spreadProps(__spreadValues({}, state), {
948
+ data: __spreadProps(__spreadValues({}, state.data), {
949
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
950
+ [action.zone]: zoneCache[action.zone]
951
+ })
952
+ }),
953
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
954
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
955
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
956
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
957
+ type: "dropzone"
958
+ })
959
+ })
960
+ })
418
961
  });
419
962
  }
420
- });
963
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
964
+ }
965
+ if (action.type === "unregisterZone") {
966
+ const _zones = __spreadValues({}, state.data.zones || {});
967
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
968
+ if (_zones[action.zone]) {
969
+ zoneCache[action.zone] = _zones[action.zone];
970
+ delete _zones[action.zone];
971
+ }
972
+ delete zoneIndex[action.zone];
973
+ return __spreadProps(__spreadValues({}, state), {
974
+ data: __spreadProps(__spreadValues({}, state.data), {
975
+ zones: _zones
976
+ }),
977
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
978
+ zones: zoneIndex
979
+ })
980
+ });
981
+ }
982
+ if (action.type === "setData") {
983
+ if (typeof action.data === "object") {
984
+ console.warn(
985
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
986
+ );
987
+ return walkTree(
988
+ __spreadProps(__spreadValues({}, state), {
989
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
990
+ }),
991
+ appStore.config
992
+ );
993
+ }
994
+ return walkTree(
995
+ __spreadProps(__spreadValues({}, state), {
996
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
997
+ }),
998
+ appStore.config
999
+ );
1000
+ }
1001
+ if (action.type === "setUi") {
1002
+ if (typeof action.ui === "object") {
1003
+ return __spreadProps(__spreadValues({}, state), {
1004
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1005
+ });
1006
+ }
1007
+ return __spreadProps(__spreadValues({}, state), {
1008
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1009
+ });
1010
+ }
1011
+ return state;
1012
+ }
1013
+
1014
+ // ../core/reducer/actions.tsx
1015
+ init_react_import();
1016
+
1017
+ // ../core/reducer/index.ts
1018
+ function storeInterceptor(reducer, record, onAction) {
1019
+ return (state, action) => {
1020
+ const newAppState = reducer(state, action);
1021
+ const isValidType = ![
1022
+ "registerZone",
1023
+ "unregisterZone",
1024
+ "setData",
1025
+ "setUi",
1026
+ "set"
1027
+ ].includes(action.type);
1028
+ if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1029
+ if (record) record(newAppState);
1030
+ }
1031
+ onAction == null ? void 0 : onAction(action, newAppState, state);
1032
+ return newAppState;
1033
+ };
1034
+ }
1035
+ function createReducer({
1036
+ record,
1037
+ onAction,
1038
+ appStore
1039
+ }) {
1040
+ return storeInterceptor(
1041
+ (state, action) => {
1042
+ const result = reduce(state, action, appStore);
1043
+ return result;
1044
+ },
1045
+ record,
1046
+ onAction
1047
+ );
421
1048
  }
422
1049
 
1050
+ // ../core/components/ViewportControls/default-viewports.ts
1051
+ init_react_import();
1052
+ var defaultViewports = [
1053
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1054
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1055
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1056
+ ];
1057
+
423
1058
  // ../../node_modules/zustand/esm/vanilla.mjs
424
1059
  init_react_import();
425
1060
  var createStoreImpl = (createState) => {
@@ -445,94 +1080,707 @@ var createStoreImpl = (createState) => {
445
1080
  };
446
1081
  var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
447
1082
 
448
- // ../core/components/DropZone/context.tsx
449
- var import_jsx_runtime3 = require("react/jsx-runtime");
450
- var dropZoneContext = (0, import_react7.createContext)(null);
451
- var ZoneStoreContext = (0, import_react7.createContext)(
452
- createStore(() => ({
453
- zoneDepthIndex: {},
454
- nextZoneDepthIndex: {},
455
- areaDepthIndex: {},
456
- nextAreaDepthIndex: {},
457
- draggedItem: null,
458
- previewIndex: {}
1083
+ // ../../node_modules/zustand/esm/react.mjs
1084
+ init_react_import();
1085
+ var import_react4 = __toESM(require("react"), 1);
1086
+ var identity = (arg) => arg;
1087
+ function useStore(api, selector = identity) {
1088
+ const slice = import_react4.default.useSyncExternalStore(
1089
+ api.subscribe,
1090
+ () => selector(api.getState()),
1091
+ () => selector(api.getInitialState())
1092
+ );
1093
+ import_react4.default.useDebugValue(slice);
1094
+ return slice;
1095
+ }
1096
+ var createImpl = (createState) => {
1097
+ const api = createStore(createState);
1098
+ const useBoundStore = (selector) => useStore(api, selector);
1099
+ Object.assign(useBoundStore, api);
1100
+ return useBoundStore;
1101
+ };
1102
+ var create = (createState) => createState ? createImpl(createState) : createImpl;
1103
+
1104
+ // ../../node_modules/zustand/esm/middleware.mjs
1105
+ init_react_import();
1106
+ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1107
+ const origSubscribe = api.subscribe;
1108
+ api.subscribe = (selector, optListener, options) => {
1109
+ let listener = selector;
1110
+ if (optListener) {
1111
+ const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
1112
+ let currentSlice = selector(api.getState());
1113
+ listener = (state) => {
1114
+ const nextSlice = selector(state);
1115
+ if (!equalityFn(currentSlice, nextSlice)) {
1116
+ const previousSlice = currentSlice;
1117
+ optListener(currentSlice = nextSlice, previousSlice);
1118
+ }
1119
+ };
1120
+ if (options == null ? void 0 : options.fireImmediately) {
1121
+ optListener(currentSlice, currentSlice);
1122
+ }
1123
+ }
1124
+ return origSubscribe(listener);
1125
+ };
1126
+ const initialState = fn(set, get, api);
1127
+ return initialState;
1128
+ };
1129
+ var subscribeWithSelector = subscribeWithSelectorImpl;
1130
+
1131
+ // ../core/store/index.ts
1132
+ var import_react9 = require("react");
1133
+
1134
+ // ../core/store/slices/history.ts
1135
+ init_react_import();
1136
+ var import_react6 = require("react");
1137
+
1138
+ // ../core/lib/use-hotkey.ts
1139
+ init_react_import();
1140
+ var import_react5 = require("react");
1141
+ var useHotkeyStore = create()(
1142
+ subscribeWithSelector((set) => ({
1143
+ held: {},
1144
+ hold: (key) => set((s) => s.held[key] ? s : { held: __spreadProps(__spreadValues({}, s.held), { [key]: true }) }),
1145
+ release: (key) => set((s) => s.held[key] ? { held: __spreadProps(__spreadValues({}, s.held), { [key]: false }) } : s),
1146
+ reset: (held = {}) => set(() => ({ held })),
1147
+ triggers: {}
459
1148
  }))
460
1149
  );
461
1150
 
462
- // ../core/lib/get-zone-id.ts
1151
+ // ../core/store/slices/history.ts
1152
+ var EMPTY_HISTORY_INDEX = 0;
1153
+ function debounce(func, timeout = 300) {
1154
+ let timer;
1155
+ return (...args) => {
1156
+ clearTimeout(timer);
1157
+ timer = setTimeout(() => {
1158
+ func(...args);
1159
+ }, timeout);
1160
+ };
1161
+ }
1162
+ var tidyState = (state) => {
1163
+ return __spreadProps(__spreadValues({}, state), {
1164
+ ui: __spreadProps(__spreadValues({}, state.ui), {
1165
+ field: {
1166
+ focus: null
1167
+ }
1168
+ })
1169
+ });
1170
+ };
1171
+ var createHistorySlice = (set, get) => {
1172
+ const record = debounce((state) => {
1173
+ const { histories, index } = get().history;
1174
+ const history = {
1175
+ state,
1176
+ id: generateId("history")
1177
+ };
1178
+ const newHistories = [...histories.slice(0, index + 1), history];
1179
+ set({
1180
+ history: __spreadProps(__spreadValues({}, get().history), {
1181
+ histories: newHistories,
1182
+ index: newHistories.length - 1
1183
+ })
1184
+ });
1185
+ }, 250);
1186
+ return {
1187
+ initialAppState: {},
1188
+ index: EMPTY_HISTORY_INDEX,
1189
+ histories: [],
1190
+ hasPast: () => get().history.index > EMPTY_HISTORY_INDEX,
1191
+ hasFuture: () => get().history.index < get().history.histories.length - 1,
1192
+ prevHistory: () => {
1193
+ const { history } = get();
1194
+ return history.hasPast() ? history.histories[history.index - 1] : null;
1195
+ },
1196
+ nextHistory: () => {
1197
+ const s = get().history;
1198
+ return s.hasFuture() ? s.histories[s.index + 1] : null;
1199
+ },
1200
+ currentHistory: () => get().history.histories[get().history.index],
1201
+ back: () => {
1202
+ var _a;
1203
+ const { history, dispatch } = get();
1204
+ if (history.hasPast()) {
1205
+ const state = tidyState(
1206
+ ((_a = history.prevHistory()) == null ? void 0 : _a.state) || history.initialAppState
1207
+ );
1208
+ dispatch({
1209
+ type: "set",
1210
+ state
1211
+ });
1212
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index - 1 }) });
1213
+ }
1214
+ },
1215
+ forward: () => {
1216
+ var _a;
1217
+ const { history, dispatch } = get();
1218
+ if (history.hasFuture()) {
1219
+ const state = (_a = history.nextHistory()) == null ? void 0 : _a.state;
1220
+ dispatch({ type: "set", state: state ? tidyState(state) : {} });
1221
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index + 1 }) });
1222
+ }
1223
+ },
1224
+ setHistories: (histories) => {
1225
+ var _a;
1226
+ const { dispatch, history } = get();
1227
+ dispatch({
1228
+ type: "set",
1229
+ state: ((_a = history.histories[history.histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
1230
+ });
1231
+ set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
1232
+ },
1233
+ setHistoryIndex: (index) => {
1234
+ var _a;
1235
+ const { dispatch, history } = get();
1236
+ dispatch({
1237
+ type: "set",
1238
+ state: ((_a = history.histories[history.index]) == null ? void 0 : _a.state) || history.initialAppState
1239
+ });
1240
+ set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1241
+ },
1242
+ record
1243
+ };
1244
+ };
1245
+
1246
+ // ../core/store/slices/nodes.ts
463
1247
  init_react_import();
464
- var getZoneId = (zoneCompound) => {
465
- if (!zoneCompound) {
466
- return [];
467
- }
468
- if (zoneCompound && zoneCompound.indexOf(":") > -1) {
469
- return zoneCompound.split(":");
1248
+ var createNodesSlice = (set, get) => ({
1249
+ nodes: {},
1250
+ registerNode: (id, node) => {
1251
+ const s = get().nodes;
1252
+ const emptyNode = {
1253
+ id,
1254
+ methods: { sync: () => null },
1255
+ element: null
1256
+ };
1257
+ const existingNode = s.nodes[id];
1258
+ set({
1259
+ nodes: __spreadProps(__spreadValues({}, s), {
1260
+ nodes: __spreadProps(__spreadValues({}, s.nodes), {
1261
+ [id]: __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, emptyNode), existingNode), node), {
1262
+ id
1263
+ })
1264
+ })
1265
+ })
1266
+ });
1267
+ },
1268
+ unregisterNode: (id) => {
1269
+ const s = get().nodes;
1270
+ const existingNode = s.nodes[id];
1271
+ if (existingNode) {
1272
+ const newNodes = __spreadValues({}, s.nodes);
1273
+ delete newNodes[id];
1274
+ set({
1275
+ nodes: __spreadProps(__spreadValues({}, s), {
1276
+ nodes: newNodes
1277
+ })
1278
+ });
1279
+ }
470
1280
  }
471
- return [rootDroppableId, zoneCompound];
1281
+ });
1282
+
1283
+ // ../core/store/slices/permissions.ts
1284
+ init_react_import();
1285
+ var import_react7 = require("react");
1286
+
1287
+ // ../core/lib/flatten-data.ts
1288
+ init_react_import();
1289
+ var flattenData = (state, config) => {
1290
+ const data = [];
1291
+ walkTree(
1292
+ state,
1293
+ config,
1294
+ (content) => content,
1295
+ (item) => {
1296
+ data.push(item);
1297
+ return null;
1298
+ }
1299
+ );
1300
+ return data;
472
1301
  };
473
1302
 
474
- // ../core/lib/use-breadcrumbs.ts
475
- var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
476
- const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
477
- const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
478
- if (!id) {
479
- return [];
480
- }
481
- return currentPathData == null ? void 0 : currentPathData.path.reduce((acc, zoneCompound) => {
482
- const [area] = getZoneId(zoneCompound);
483
- if (area === rootDroppableId) {
484
- return [
485
- {
486
- label: "Page",
487
- selector: null
1303
+ // ../core/lib/get-changed.ts
1304
+ init_react_import();
1305
+ var getChanged = (newItem, oldItem) => {
1306
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1307
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1308
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1309
+ return __spreadProps(__spreadValues({}, acc), {
1310
+ [item]: oldItemProps[item] !== newItemProps[item]
1311
+ });
1312
+ }, {}) : {};
1313
+ };
1314
+
1315
+ // ../core/store/slices/permissions.ts
1316
+ var createPermissionsSlice = (set, get) => {
1317
+ const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1318
+ const { state, permissions, config } = get();
1319
+ const { cache: cache2, globalPermissions } = permissions;
1320
+ const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1321
+ var _a, _b, _c;
1322
+ const {
1323
+ config: config2,
1324
+ state: appState,
1325
+ setComponentLoading,
1326
+ unsetComponentLoading
1327
+ } = get();
1328
+ const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1329
+ if (!componentConfig) {
1330
+ return;
1331
+ }
1332
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1333
+ if (componentConfig.resolvePermissions) {
1334
+ const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1335
+ if (Object.values(changed).some((el) => el === true) || force2) {
1336
+ setComponentLoading(item2.props.id);
1337
+ const resolvedPermissions = yield componentConfig.resolvePermissions(
1338
+ item2,
1339
+ {
1340
+ changed,
1341
+ lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1342
+ permissions: initialPermissions,
1343
+ appState,
1344
+ lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1345
+ }
1346
+ );
1347
+ const latest = get().permissions;
1348
+ set({
1349
+ permissions: __spreadProps(__spreadValues({}, latest), {
1350
+ cache: __spreadProps(__spreadValues({}, latest.cache), {
1351
+ [item2.props.id]: {
1352
+ lastData: item2,
1353
+ lastPermissions: resolvedPermissions
1354
+ }
1355
+ }),
1356
+ resolvedPermissions: __spreadProps(__spreadValues({}, latest.resolvedPermissions), {
1357
+ [item2.props.id]: resolvedPermissions
1358
+ })
1359
+ })
1360
+ });
1361
+ unsetComponentLoading(item2.props.id);
488
1362
  }
489
- ];
1363
+ }
1364
+ });
1365
+ const resolveDataForRoot = (force2 = false) => {
1366
+ const { state: appState } = get();
1367
+ resolveDataForItem(
1368
+ // Shim the root data in by conforming to component data shape
1369
+ {
1370
+ type: "root",
1371
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
1372
+ },
1373
+ force2
1374
+ );
1375
+ };
1376
+ const { item, type, root } = params;
1377
+ if (item) {
1378
+ yield resolveDataForItem(item, force);
1379
+ } else if (type) {
1380
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1381
+ yield resolveDataForItem(item2, force);
1382
+ }));
1383
+ } else if (root) {
1384
+ resolveDataForRoot(force);
1385
+ } else {
1386
+ resolveDataForRoot(force);
1387
+ flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1388
+ yield resolveDataForItem(item2, force);
1389
+ }));
490
1390
  }
491
- const parentZoneCompound = acc.length > 0 ? acc[acc.length - 1].zoneCompound : rootDroppableId;
492
- let parentZone = data.content;
493
- if (parentZoneCompound && parentZoneCompound !== rootDroppableId) {
494
- parentZone = data.zones[parentZoneCompound];
1391
+ });
1392
+ const refreshPermissions = (params) => resolvePermissions(params, true);
1393
+ return {
1394
+ cache: {},
1395
+ globalPermissions: {
1396
+ drag: true,
1397
+ edit: true,
1398
+ delete: true,
1399
+ duplicate: true,
1400
+ insert: true
1401
+ },
1402
+ resolvedPermissions: {},
1403
+ getPermissions: ({ item, type, root } = {}) => {
1404
+ const { config, permissions } = get();
1405
+ const { globalPermissions, resolvedPermissions } = permissions;
1406
+ if (item) {
1407
+ const componentConfig = config.components[item.type];
1408
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1409
+ const resolvedForItem = resolvedPermissions[item.props.id];
1410
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1411
+ } else if (type) {
1412
+ const componentConfig = config.components[type];
1413
+ return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1414
+ } else if (root) {
1415
+ const rootConfig = config.root;
1416
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1417
+ const resolvedForItem = resolvedPermissions["puck-root"];
1418
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1419
+ }
1420
+ return globalPermissions;
1421
+ },
1422
+ resolvePermissions,
1423
+ refreshPermissions
1424
+ };
1425
+ };
1426
+
1427
+ // ../core/store/slices/fields.ts
1428
+ init_react_import();
1429
+ var import_react8 = require("react");
1430
+ var createFieldsSlice = (_set, _get) => {
1431
+ return {
1432
+ fields: {},
1433
+ loading: false,
1434
+ lastResolvedData: {}
1435
+ };
1436
+ };
1437
+
1438
+ // ../core/lib/resolve-component-data.ts
1439
+ init_react_import();
1440
+
1441
+ // ../core/lib/map-slots.ts
1442
+ init_react_import();
1443
+ function mapSlots(item, map, recursive = true, isSlot2) {
1444
+ return __async(this, null, function* () {
1445
+ const props = __spreadValues({}, item.props);
1446
+ yield forEachSlot(
1447
+ item,
1448
+ (_parentId, propName, content) => __async(this, null, function* () {
1449
+ const mappedContent = recursive ? yield Promise.all(
1450
+ content.map((item2) => __async(this, null, function* () {
1451
+ return yield mapSlots(item2, map, recursive, isSlot2);
1452
+ }))
1453
+ ) : content;
1454
+ props[propName] = yield map(mappedContent, propName);
1455
+ }),
1456
+ false,
1457
+ isSlot2
1458
+ );
1459
+ return __spreadProps(__spreadValues({}, item), { props });
1460
+ });
1461
+ }
1462
+
1463
+ // ../core/lib/resolve-component-data.ts
1464
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1465
+ var cache = { lastChange: {} };
1466
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
1467
+ const configForItem = "type" in item ? config.components[item.type] : config.root;
1468
+ if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
1469
+ const id = "id" in item.props ? item.props.id : "root";
1470
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1471
+ if (item && item === oldItem) {
1472
+ return resolved;
495
1473
  }
496
- if (!parentZone) {
497
- return acc;
1474
+ const changed = getChanged(item, oldItem);
1475
+ if (onResolveStart) {
1476
+ onResolveStart(item);
498
1477
  }
499
- const itemIndex = parentZone.findIndex(
500
- (queryItem) => queryItem.props.id === area
501
- );
502
- const item = parentZone[itemIndex];
503
- if (!item) {
504
- return acc;
1478
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1479
+ changed,
1480
+ lastData: oldItem,
1481
+ metadata,
1482
+ trigger
1483
+ });
1484
+ let resolvedItem = __spreadProps(__spreadValues({}, item), {
1485
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1486
+ });
1487
+ if (recursive) {
1488
+ resolvedItem = yield mapSlots(resolvedItem, (content) => __async(void 0, null, function* () {
1489
+ return Promise.all(
1490
+ content.map(
1491
+ (childItem) => __async(void 0, null, function* () {
1492
+ return (yield resolveComponentData(
1493
+ childItem,
1494
+ config,
1495
+ metadata,
1496
+ onResolveStart,
1497
+ onResolveEnd,
1498
+ trigger,
1499
+ false
1500
+ )).node;
1501
+ })
1502
+ )
1503
+ );
1504
+ }));
505
1505
  }
506
- return [
507
- ...acc,
508
- {
509
- label: item.type.toString(),
510
- selector: {
511
- index: itemIndex,
512
- zone: parentZoneCompound
513
- },
514
- zoneCompound
515
- }
516
- ];
517
- }, []);
1506
+ if (Object.keys(readOnly).length) {
1507
+ resolvedItem.readOnly = readOnly;
1508
+ }
1509
+ cache.lastChange[id] = {
1510
+ item,
1511
+ resolved: resolvedItem
1512
+ };
1513
+ if (onResolveEnd) {
1514
+ onResolveEnd(resolvedItem);
1515
+ }
1516
+ return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
1517
+ }
1518
+ return { node: item, didChange: false };
1519
+ });
1520
+
1521
+ // ../core/lib/to-root.ts
1522
+ init_react_import();
1523
+ var toRoot = (item) => {
1524
+ if ("type" in item && item.type !== "root") {
1525
+ throw new Error("Converting non-root item to root.");
1526
+ }
1527
+ const { readOnly } = item;
1528
+ if (item.props) {
1529
+ if ("id" in item.props) {
1530
+ const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
1531
+ return { props, readOnly };
1532
+ }
1533
+ return { props: item.props, readOnly };
1534
+ }
1535
+ return { props: {}, readOnly };
518
1536
  };
1537
+
1538
+ // ../core/store/index.ts
1539
+ var defaultAppState = {
1540
+ data: { content: [], root: {}, zones: {} },
1541
+ ui: {
1542
+ leftSideBarVisible: true,
1543
+ rightSideBarVisible: true,
1544
+ arrayState: {},
1545
+ itemSelector: null,
1546
+ componentList: {},
1547
+ isDragging: false,
1548
+ previewMode: "edit",
1549
+ viewports: {
1550
+ current: {
1551
+ width: defaultViewports[0].width,
1552
+ height: defaultViewports[0].height || "auto"
1553
+ },
1554
+ options: [],
1555
+ controlsVisible: true
1556
+ },
1557
+ field: { focus: null }
1558
+ },
1559
+ indexes: {
1560
+ nodes: {},
1561
+ zones: {}
1562
+ }
1563
+ };
1564
+ var defaultPageFields = {
1565
+ title: { type: "text" }
1566
+ };
1567
+ var createAppStore = (initialAppStore) => create()(
1568
+ subscribeWithSelector((set, get) => __spreadProps(__spreadValues({
1569
+ state: defaultAppState,
1570
+ config: { components: {} },
1571
+ componentState: {},
1572
+ plugins: [],
1573
+ overrides: {},
1574
+ viewports: defaultViewports,
1575
+ zoomConfig: {
1576
+ autoZoom: 1,
1577
+ rootHeight: 0,
1578
+ zoom: 1
1579
+ },
1580
+ status: "LOADING",
1581
+ iframe: {},
1582
+ metadata: {}
1583
+ }, initialAppStore), {
1584
+ fields: createFieldsSlice(set, get),
1585
+ history: createHistorySlice(set, get),
1586
+ nodes: createNodesSlice(set, get),
1587
+ permissions: createPermissionsSlice(set, get),
1588
+ getComponentConfig: (type) => {
1589
+ var _a;
1590
+ const { config, selectedItem } = get();
1591
+ const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1592
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1593
+ },
1594
+ dispatch: (action) => set((s) => {
1595
+ var _a, _b;
1596
+ const { record } = get().history;
1597
+ const dispatch = createReducer({
1598
+ record,
1599
+ appStore: s
1600
+ });
1601
+ const state = dispatch(s.state, action);
1602
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1603
+ (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1604
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1605
+ }),
1606
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1607
+ setStatus: (status) => set({ status }),
1608
+ setComponentState: (componentState) => set({ componentState }),
1609
+ pendingComponentLoads: {},
1610
+ setComponentLoading: (id, loading = true, defer = 0) => {
1611
+ const { setComponentState, pendingComponentLoads } = get();
1612
+ const thisPendingComponentLoads = __spreadValues({}, pendingComponentLoads);
1613
+ const setLoading = () => {
1614
+ var _a;
1615
+ const { componentState } = get();
1616
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1617
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1618
+ loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1619
+ })
1620
+ }));
1621
+ };
1622
+ const unsetLoading = () => {
1623
+ var _a;
1624
+ const { componentState } = get();
1625
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1626
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1627
+ loadingCount: Math.max(
1628
+ (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1629
+ 0
1630
+ )
1631
+ })
1632
+ }));
1633
+ };
1634
+ if (thisPendingComponentLoads[id]) {
1635
+ clearTimeout(thisPendingComponentLoads[id]);
1636
+ delete thisPendingComponentLoads[id];
1637
+ set({ pendingComponentLoads: thisPendingComponentLoads });
1638
+ }
1639
+ const timeout = setTimeout(() => {
1640
+ if (loading) {
1641
+ setLoading();
1642
+ } else {
1643
+ unsetLoading();
1644
+ }
1645
+ delete thisPendingComponentLoads[id];
1646
+ set({ pendingComponentLoads: thisPendingComponentLoads });
1647
+ }, defer);
1648
+ set({
1649
+ pendingComponentLoads: __spreadProps(__spreadValues({}, thisPendingComponentLoads), {
1650
+ [id]: timeout
1651
+ })
1652
+ });
1653
+ },
1654
+ unsetComponentLoading: (id) => {
1655
+ const { setComponentLoading } = get();
1656
+ setComponentLoading(id, false);
1657
+ },
1658
+ // Helper
1659
+ setUi: (ui, recordHistory) => set((s) => {
1660
+ const dispatch = createReducer({
1661
+ record: () => {
1662
+ },
1663
+ appStore: s
1664
+ });
1665
+ const state = dispatch(s.state, {
1666
+ type: "setUi",
1667
+ ui,
1668
+ recordHistory
1669
+ });
1670
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1671
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1672
+ }),
1673
+ // resolveDataRuns: 0,
1674
+ // resolveData: (newAppState) =>
1675
+ // set((s) => {
1676
+ // resolveData(newAppState, get);
1677
+ // return { ...s, resolveDataRuns: s.resolveDataRuns + 1 };
1678
+ // }),
1679
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1680
+ const { config, metadata, setComponentLoading } = get();
1681
+ return yield resolveComponentData(
1682
+ componentData,
1683
+ config,
1684
+ metadata,
1685
+ (item) => setComponentLoading(
1686
+ "id" in item.props ? item.props.id : "root",
1687
+ true,
1688
+ 50
1689
+ ),
1690
+ (item) => setComponentLoading(
1691
+ "id" in item.props ? item.props.id : "root",
1692
+ false,
1693
+ 0
1694
+ ),
1695
+ trigger
1696
+ );
1697
+ }),
1698
+ resolveAndCommitData: () => __async(void 0, null, function* () {
1699
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1700
+ walkTree(
1701
+ state,
1702
+ config,
1703
+ (content) => content,
1704
+ (childItem) => {
1705
+ resolveComponentData2(childItem, "load").then((resolved) => {
1706
+ const { state: state2 } = get();
1707
+ const node = state2.indexes.nodes[resolved.node.props.id];
1708
+ if (node && resolved.didChange) {
1709
+ if (resolved.node.props.id === "root") {
1710
+ dispatch({
1711
+ type: "replaceRoot",
1712
+ root: toRoot(resolved.node)
1713
+ });
1714
+ } else {
1715
+ const zoneCompound = `${node.parentId}:${node.zone}`;
1716
+ const parentZone = state2.indexes.zones[zoneCompound];
1717
+ const index = parentZone.contentIds.indexOf(
1718
+ resolved.node.props.id
1719
+ );
1720
+ dispatch({
1721
+ type: "replace",
1722
+ data: resolved.node,
1723
+ destinationIndex: index,
1724
+ destinationZone: zoneCompound
1725
+ });
1726
+ }
1727
+ }
1728
+ });
1729
+ return childItem;
1730
+ }
1731
+ );
1732
+ })
1733
+ }))
1734
+ );
1735
+ var appStoreContext = (0, import_react9.createContext)(createAppStore());
1736
+ function useAppStore(selector) {
1737
+ const context = (0, import_react9.useContext)(appStoreContext);
1738
+ return useStore(context, selector);
1739
+ }
1740
+ function useAppStoreApi() {
1741
+ return (0, import_react9.useContext)(appStoreContext);
1742
+ }
1743
+
1744
+ // ../core/lib/use-breadcrumbs.ts
519
1745
  var useBreadcrumbs = (renderCount) => {
520
- const {
521
- state: { data },
522
- selectedItem
523
- } = useAppContext();
524
- const dzContext = (0, import_react8.useContext)(dropZoneContext);
525
- return (0, import_react8.useMemo)(() => {
526
- const breadcrumbs = convertPathDataToBreadcrumbs(
527
- selectedItem,
528
- dzContext == null ? void 0 : dzContext.pathData,
529
- data
530
- );
1746
+ const selectedId = useAppStore((s) => {
1747
+ var _a;
1748
+ return (_a = s.selectedItem) == null ? void 0 : _a.props.id;
1749
+ });
1750
+ const config = useAppStore((s) => s.config);
1751
+ const path = useAppStore((s) => {
1752
+ var _a;
1753
+ return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
1754
+ });
1755
+ const appStore = useAppStoreApi();
1756
+ return (0, import_react10.useMemo)(() => {
1757
+ const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
1758
+ var _a, _b, _c;
1759
+ const [componentId] = zoneCompound.split(":");
1760
+ if (componentId === "root") {
1761
+ return {
1762
+ label: "Page",
1763
+ selector: null
1764
+ };
1765
+ }
1766
+ const node = appStore.getState().state.indexes.nodes[componentId];
1767
+ const parentId = node.path[node.path.length - 1];
1768
+ const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
1769
+ const index = contentIds.indexOf(componentId);
1770
+ const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
1771
+ return {
1772
+ label,
1773
+ selector: node ? {
1774
+ index,
1775
+ zone: node.path[node.path.length - 1]
1776
+ } : null
1777
+ };
1778
+ })) || [];
531
1779
  if (renderCount) {
532
1780
  return breadcrumbs.slice(breadcrumbs.length - renderCount);
533
1781
  }
534
1782
  return breadcrumbs;
535
- }, [selectedItem, dzContext == null ? void 0 : dzContext.pathData, renderCount]);
1783
+ }, [path, renderCount]);
536
1784
  };
537
1785
 
538
1786
  // ../core/components/Loader/index.tsx
@@ -555,7 +1803,7 @@ init_react_import();
555
1803
  var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
556
1804
 
557
1805
  // ../core/components/Loader/index.tsx
558
- var import_jsx_runtime4 = require("react/jsx-runtime");
1806
+ var import_jsx_runtime2 = require("react/jsx-runtime");
559
1807
  var getClassName2 = get_class_name_factory_default("Loader", styles_module_default3);
560
1808
  var Loader = (_a) => {
561
1809
  var _b = _a, {
@@ -565,7 +1813,7 @@ var Loader = (_a) => {
565
1813
  "color",
566
1814
  "size"
567
1815
  ]);
568
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1816
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
569
1817
  "span",
570
1818
  __spreadValues({
571
1819
  className: getClassName2(),
@@ -580,7 +1828,7 @@ var Loader = (_a) => {
580
1828
  };
581
1829
 
582
1830
  // ../core/components/SidebarSection/index.tsx
583
- var import_jsx_runtime5 = require("react/jsx-runtime");
1831
+ var import_jsx_runtime3 = require("react/jsx-runtime");
584
1832
  var getClassName3 = get_class_name_factory_default("SidebarSection", styles_module_default);
585
1833
  var SidebarSection = ({
586
1834
  children,
@@ -591,17 +1839,17 @@ var SidebarSection = ({
591
1839
  noPadding,
592
1840
  isLoading
593
1841
  }) => {
594
- const { setUi } = useAppContext();
1842
+ const setUi = useAppStore((s) => s.setUi);
595
1843
  const breadcrumbs = useBreadcrumbs(1);
596
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1844
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
597
1845
  "div",
598
1846
  {
599
1847
  className: getClassName3({ noBorderTop, noPadding }),
600
1848
  style: { background },
601
1849
  children: [
602
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName3("title"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName3("breadcrumbs"), children: [
603
- showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName3("breadcrumb"), children: [
604
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1850
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName3("title"), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: getClassName3("breadcrumbs"), children: [
1851
+ showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: getClassName3("breadcrumb"), children: [
1852
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
605
1853
  "button",
606
1854
  {
607
1855
  type: "button",
@@ -610,12 +1858,12 @@ var SidebarSection = ({
610
1858
  children: breadcrumb.label
611
1859
  }
612
1860
  ),
613
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChevronRight, { size: 16 })
1861
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChevronRight, { size: 16 })
614
1862
  ] }, i)) : null,
615
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName3("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Heading, { rank: "2", size: "xs", children: title }) })
1863
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName3("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Heading, { rank: "2", size: "xs", children: title }) })
616
1864
  ] }) }),
617
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName3("content"), children }),
618
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName3("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Loader, { size: 32 }) })
1865
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName3("content"), children }),
1866
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName3("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Loader, { size: 32 }) })
619
1867
  ]
620
1868
  }
621
1869
  );
@@ -629,18 +1877,18 @@ init_react_import();
629
1877
  var styles_module_default4 = { "OutlineList": "_OutlineList_w4lzv_1", "OutlineListItem": "_OutlineListItem_w4lzv_25", "OutlineListItem--clickable": "_OutlineListItem--clickable_w4lzv_45" };
630
1878
 
631
1879
  // ../core/components/OutlineList/index.tsx
632
- var import_jsx_runtime6 = require("react/jsx-runtime");
1880
+ var import_jsx_runtime4 = require("react/jsx-runtime");
633
1881
  var getClassName4 = get_class_name_factory_default("OutlineList", styles_module_default4);
634
1882
  var getClassNameItem = get_class_name_factory_default("OutlineListItem", styles_module_default4);
635
1883
  var OutlineList = ({ children }) => {
636
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: getClassName4(), children });
1884
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: getClassName4(), children });
637
1885
  };
638
- OutlineList.Clickable = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: getClassNameItem({ clickable: true }), children });
1886
+ OutlineList.Clickable = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassNameItem({ clickable: true }), children });
639
1887
  OutlineList.Item = ({
640
1888
  children,
641
1889
  onClick
642
1890
  }) => {
643
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1891
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
644
1892
  "li",
645
1893
  {
646
1894
  className: getClassNameItem({ clickable: !!onClick }),
@@ -674,7 +1922,7 @@ var getFrame = () => {
674
1922
 
675
1923
  // src/HeadingAnalyzer.tsx
676
1924
  var import_react_from_json = __toESM(require("react-from-json"));
677
- var import_jsx_runtime7 = require("react/jsx-runtime");
1925
+ var import_jsx_runtime5 = require("react/jsx-runtime");
678
1926
  var getClassName5 = get_class_name_factory_default("HeadingAnalyzer", HeadingAnalyzer_module_default);
679
1927
  var getClassNameItem2 = get_class_name_factory_default("HeadingAnalyzerItem", HeadingAnalyzer_module_default);
680
1928
  var ReactFromJSON = import_react_from_json.default.default || import_react_from_json.default;
@@ -682,6 +1930,9 @@ var getOutline = ({ frame } = {}) => {
682
1930
  const headings = (frame == null ? void 0 : frame.querySelectorAll("h1,h2,h3,h4,h5,h6")) || [];
683
1931
  const _outline = [];
684
1932
  headings.forEach((item, i) => {
1933
+ if (item.closest("[data-dnd-dragging]")) {
1934
+ return;
1935
+ }
685
1936
  _outline.push({
686
1937
  rank: parseInt(item.tagName.split("H")[1]),
687
1938
  text: item.textContent,
@@ -724,10 +1975,11 @@ function buildHierarchy(frame) {
724
1975
  }
725
1976
  return root.children;
726
1977
  }
1978
+ var usePuck = (0, import_puck.createUsePuck)();
727
1979
  var HeadingAnalyzer = () => {
728
- const { appState } = (0, import_puck.usePuck)();
729
- const [hierarchy, setHierarchy] = (0, import_react9.useState)([]);
730
- (0, import_react9.useEffect)(() => {
1980
+ const data = usePuck((s) => s.appState.data);
1981
+ const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
1982
+ (0, import_react11.useEffect)(() => {
731
1983
  const frame = getFrame();
732
1984
  const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
733
1985
  if (!entry) return;
@@ -739,9 +1991,9 @@ var HeadingAnalyzer = () => {
739
1991
  return () => {
740
1992
  observer.disconnect();
741
1993
  };
742
- }, [appState.data]);
743
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: getClassName5(), children: [
744
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1994
+ }, [data]);
1995
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [
1996
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
745
1997
  "small",
746
1998
  {
747
1999
  className: getClassName5("cssWarning"),
@@ -753,19 +2005,19 @@ var HeadingAnalyzer = () => {
753
2005
  children: [
754
2006
  "Heading analyzer styles not loaded. Please review the",
755
2007
  " ",
756
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { href: "https://github.com/measuredco/puck/blob/main/packages/plugin-heading-analyzer/README.md", children: "README" }),
2008
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { href: "https://github.com/measuredco/puck/blob/main/packages/plugin-heading-analyzer/README.md", children: "README" }),
757
2009
  "."
758
2010
  ]
759
2011
  }
760
2012
  ),
761
- hierarchy.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children: "No headings." }),
762
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OutlineList, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2013
+ hierarchy.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: "No headings." }),
2014
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OutlineList, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
763
2015
  ReactFromJSON,
764
2016
  {
765
2017
  mapping: {
766
- Root: (props) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: props.children }),
767
- OutlineListItem: (props) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(OutlineList.Item, { children: [
768
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OutlineList.Clickable, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2018
+ Root: (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: props.children }),
2019
+ OutlineListItem: (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(OutlineList.Item, { children: [
2020
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OutlineList.Clickable, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
769
2021
  "small",
770
2022
  {
771
2023
  className: getClassNameItem2({ missing: props.missing }),
@@ -783,14 +2035,14 @@ var HeadingAnalyzer = () => {
783
2035
  }, 2e3);
784
2036
  }
785
2037
  },
786
- children: props.missing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
787
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("b", { children: [
2038
+ children: props.missing ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
2039
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("b", { children: [
788
2040
  "H",
789
2041
  props.rank
790
2042
  ] }),
791
2043
  ": Missing"
792
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
793
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("b", { children: [
2044
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
2045
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("b", { children: [
794
2046
  "H",
795
2047
  props.rank
796
2048
  ] }),
@@ -799,7 +2051,7 @@ var HeadingAnalyzer = () => {
799
2051
  ] })
800
2052
  }
801
2053
  ) }),
802
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OutlineList, { children: props.children })
2054
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OutlineList, { children: props.children })
803
2055
  ] })
804
2056
  },
805
2057
  entry: {
@@ -821,9 +2073,9 @@ var HeadingAnalyzer = () => {
821
2073
  };
822
2074
  var headingAnalyzer = {
823
2075
  overrides: {
824
- fields: ({ children, itemSelector }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2076
+ fields: ({ children, itemSelector }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
825
2077
  children,
826
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: { display: itemSelector ? "none" : "block" }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SidebarSection, { title: "Heading Outline", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HeadingAnalyzer, {}) }) })
2078
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { display: itemSelector ? "none" : "block" }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SidebarSection, { title: "Heading Outline", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(HeadingAnalyzer, {}) }) })
827
2079
  ] })
828
2080
  }
829
2081
  };