@measured/puck-plugin-heading-analyzer 0.19.0-canary.b9add22 → 0.19.0-canary.bc5bfff1

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,156 @@ var require_classnames = __commonJS({
133
153
  }
134
154
  });
135
155
 
156
+ // ../../node_modules/flat/index.js
157
+ var require_flat = __commonJS({
158
+ "../../node_modules/flat/index.js"(exports2, module2) {
159
+ "use strict";
160
+ init_react_import();
161
+ module2.exports = flatten2;
162
+ flatten2.flatten = flatten2;
163
+ flatten2.unflatten = unflatten2;
164
+ function isBuffer(obj) {
165
+ return obj && obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
166
+ }
167
+ function keyIdentity(key) {
168
+ return key;
169
+ }
170
+ function flatten2(target, opts) {
171
+ opts = opts || {};
172
+ const delimiter = opts.delimiter || ".";
173
+ const maxDepth = opts.maxDepth;
174
+ const transformKey = opts.transformKey || keyIdentity;
175
+ const output = {};
176
+ function step(object, prev, currentDepth) {
177
+ currentDepth = currentDepth || 1;
178
+ Object.keys(object).forEach(function(key) {
179
+ const value = object[key];
180
+ const isarray = opts.safe && Array.isArray(value);
181
+ const type = Object.prototype.toString.call(value);
182
+ const isbuffer = isBuffer(value);
183
+ const isobject = type === "[object Object]" || type === "[object Array]";
184
+ const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
185
+ if (!isarray && !isbuffer && isobject && Object.keys(value).length && (!opts.maxDepth || currentDepth < maxDepth)) {
186
+ return step(value, newKey, currentDepth + 1);
187
+ }
188
+ output[newKey] = value;
189
+ });
190
+ }
191
+ step(target);
192
+ return output;
193
+ }
194
+ function unflatten2(target, opts) {
195
+ opts = opts || {};
196
+ const delimiter = opts.delimiter || ".";
197
+ const overwrite = opts.overwrite || false;
198
+ const transformKey = opts.transformKey || keyIdentity;
199
+ const result = {};
200
+ const isbuffer = isBuffer(target);
201
+ if (isbuffer || Object.prototype.toString.call(target) !== "[object Object]") {
202
+ return target;
203
+ }
204
+ function getkey(key) {
205
+ const parsedKey = Number(key);
206
+ return isNaN(parsedKey) || key.indexOf(".") !== -1 || opts.object ? key : parsedKey;
207
+ }
208
+ function addKeys(keyPrefix, recipient, target2) {
209
+ return Object.keys(target2).reduce(function(result2, key) {
210
+ result2[keyPrefix + delimiter + key] = target2[key];
211
+ return result2;
212
+ }, recipient);
213
+ }
214
+ function isEmpty(val) {
215
+ const type = Object.prototype.toString.call(val);
216
+ const isArray = type === "[object Array]";
217
+ const isObject = type === "[object Object]";
218
+ if (!val) {
219
+ return true;
220
+ } else if (isArray) {
221
+ return !val.length;
222
+ } else if (isObject) {
223
+ return !Object.keys(val).length;
224
+ }
225
+ }
226
+ target = Object.keys(target).reduce(function(result2, key) {
227
+ const type = Object.prototype.toString.call(target[key]);
228
+ const isObject = type === "[object Object]" || type === "[object Array]";
229
+ if (!isObject || isEmpty(target[key])) {
230
+ result2[key] = target[key];
231
+ return result2;
232
+ } else {
233
+ return addKeys(
234
+ key,
235
+ result2,
236
+ flatten2(target[key], opts)
237
+ );
238
+ }
239
+ }, {});
240
+ Object.keys(target).forEach(function(key) {
241
+ const split = key.split(delimiter).map(transformKey);
242
+ let key1 = getkey(split.shift());
243
+ let key2 = getkey(split[0]);
244
+ let recipient = result;
245
+ while (key2 !== void 0) {
246
+ if (key1 === "__proto__") {
247
+ return;
248
+ }
249
+ const type = Object.prototype.toString.call(recipient[key1]);
250
+ const isobject = type === "[object Object]" || type === "[object Array]";
251
+ if (!overwrite && !isobject && typeof recipient[key1] !== "undefined") {
252
+ return;
253
+ }
254
+ if (overwrite && !isobject || !overwrite && recipient[key1] == null) {
255
+ recipient[key1] = typeof key2 === "number" && !opts.object ? [] : {};
256
+ }
257
+ recipient = recipient[key1];
258
+ if (split.length > 0) {
259
+ key1 = getkey(split.shift());
260
+ key2 = getkey(split[0]);
261
+ }
262
+ }
263
+ recipient[key1] = unflatten2(target[key], opts);
264
+ });
265
+ return result;
266
+ }
267
+ }
268
+ });
269
+
270
+ // ../../node_modules/fast-deep-equal/index.js
271
+ var require_fast_deep_equal = __commonJS({
272
+ "../../node_modules/fast-deep-equal/index.js"(exports2, module2) {
273
+ "use strict";
274
+ init_react_import();
275
+ module2.exports = function equal(a, b) {
276
+ if (a === b) return true;
277
+ if (a && b && typeof a == "object" && typeof b == "object") {
278
+ if (a.constructor !== b.constructor) return false;
279
+ var length, i, keys;
280
+ if (Array.isArray(a)) {
281
+ length = a.length;
282
+ if (length != b.length) return false;
283
+ for (i = length; i-- !== 0; )
284
+ if (!equal(a[i], b[i])) return false;
285
+ return true;
286
+ }
287
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
288
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
289
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
290
+ keys = Object.keys(a);
291
+ length = keys.length;
292
+ if (length !== Object.keys(b).length) return false;
293
+ for (i = length; i-- !== 0; )
294
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
295
+ for (i = length; i-- !== 0; ) {
296
+ var key = keys[i];
297
+ if (!equal(a[key], b[key])) return false;
298
+ }
299
+ return true;
300
+ }
301
+ return a !== a && b !== b;
302
+ };
303
+ }
304
+ });
305
+
136
306
  // index.ts
137
307
  var plugin_heading_analyzer_exports = {};
138
308
  __export(plugin_heading_analyzer_exports, {
@@ -143,7 +313,7 @@ init_react_import();
143
313
 
144
314
  // src/HeadingAnalyzer.tsx
145
315
  init_react_import();
146
- var import_react9 = require("react");
316
+ var import_react11 = require("react");
147
317
 
148
318
  // css-module:/home/runner/work/puck/puck/packages/plugin-heading-analyzer/src/HeadingAnalyzer.module.css#css-module
149
319
  init_react_import();
@@ -304,122 +474,905 @@ var ChevronRight = createLucideIcon("ChevronRight", [
304
474
 
305
475
  // ../core/lib/use-breadcrumbs.ts
306
476
  init_react_import();
307
- var import_react8 = require("react");
477
+ var import_react10 = require("react");
308
478
 
309
- // ../core/components/DropZone/context.tsx
479
+ // ../core/store/index.ts
310
480
  init_react_import();
311
- var import_react7 = require("react");
312
481
 
313
- // ../core/components/Puck/context.tsx
482
+ // ../core/reducer/index.ts
483
+ init_react_import();
484
+
485
+ // ../core/reducer/actions/set.ts
486
+ init_react_import();
487
+
488
+ // ../core/lib/data/walk-app-state.ts
314
489
  init_react_import();
315
- var import_react6 = require("react");
316
490
 
317
- // ../core/lib/get-item.ts
491
+ // ../core/lib/data/for-related-zones.ts
492
+ init_react_import();
493
+
494
+ // ../core/lib/get-zone-id.ts
318
495
  init_react_import();
319
496
 
320
497
  // ../core/lib/root-droppable-id.ts
321
498
  init_react_import();
322
- var rootDroppableId = "default-zone";
499
+ var rootAreaId = "root";
500
+ var rootZone = "default-zone";
501
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
502
+
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];
512
+ };
513
+
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
+ }
323
523
 
324
- // ../core/lib/setup-zone.ts
524
+ // ../core/lib/data/map-slots.ts
325
525
  init_react_import();
326
526
 
327
- // ../core/components/ViewportControls/default-viewports.ts
527
+ // ../core/lib/data/is-slot.ts
328
528
  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
- ];
529
+ var isSlot = (prop) => {
530
+ var _a, _b;
531
+ return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
532
+ };
533
+ var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
534
+ var _a, _b;
535
+ const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
536
+ if (!configForComponent) return isSlot(propValue);
537
+ return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
538
+ };
539
+
540
+ // ../core/lib/data/map-slots.ts
541
+ function mapSlotsAsync(_0, _1) {
542
+ return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
543
+ const props = __spreadValues({}, item.props);
544
+ const propKeys = Object.keys(props);
545
+ for (let i = 0; i < propKeys.length; i++) {
546
+ const propKey = propKeys[i];
547
+ const itemType = "type" in item ? item.type : "root";
548
+ if (isSlot2(itemType, propKey, props[propKey])) {
549
+ const content = props[propKey];
550
+ const mappedContent = recursive ? yield Promise.all(
551
+ content.map((item2) => __async(this, null, function* () {
552
+ return yield mapSlotsAsync(item2, map, recursive, isSlot2);
553
+ }))
554
+ ) : content;
555
+ props[propKey] = yield map(mappedContent, propKey);
556
+ }
557
+ }
558
+ return __spreadProps(__spreadValues({}, item), { props });
559
+ });
560
+ }
561
+ var walkField = ({
562
+ value,
563
+ fields,
564
+ map,
565
+ propKey = "",
566
+ propPath = "",
567
+ id = ""
568
+ }) => {
569
+ var _a, _b, _c;
570
+ if (((_a = fields[propKey]) == null ? void 0 : _a.type) === "slot") {
571
+ const content = value || [];
572
+ return map(content, id, propPath, fields[propKey], propPath);
573
+ }
574
+ if (value && typeof value === "object") {
575
+ if (Array.isArray(value)) {
576
+ const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
577
+ if (!arrayFields) return value;
578
+ return value.map(
579
+ (el, idx) => walkField({
580
+ value: el,
581
+ fields: arrayFields,
582
+ map,
583
+ propKey,
584
+ propPath: `${propPath}[${idx}]`,
585
+ id
586
+ })
587
+ );
588
+ } else if ("$$typeof" in value) {
589
+ return value;
590
+ } else {
591
+ const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
592
+ return Object.entries(value).reduce(
593
+ (acc, [k, v]) => {
594
+ const newValue = walkField({
595
+ value: v,
596
+ fields: objectFields,
597
+ map,
598
+ propKey: k,
599
+ propPath: `${propPath}.${k}`,
600
+ id
601
+ });
602
+ if (typeof newValue === "undefined" || newValue === v) return acc;
603
+ return __spreadProps(__spreadValues({}, acc), {
604
+ [k]: newValue
605
+ });
606
+ },
607
+ value
608
+ );
609
+ }
610
+ }
611
+ return value;
612
+ };
613
+ function mapSlotsSync(item, map, config) {
614
+ var _a, _b, _c;
615
+ const itemType = "type" in item ? item.type : "root";
616
+ const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
617
+ const newProps = __spreadValues({}, (_b = item.props) != null ? _b : {});
618
+ Object.entries((_c = item.props) != null ? _c : {}).forEach(([k, v]) => {
619
+ var _a2, _b2;
620
+ const newValue = walkField({
621
+ value: v,
622
+ fields: (_a2 = componentConfig == null ? void 0 : componentConfig.fields) != null ? _a2 : {},
623
+ map,
624
+ propKey: k,
625
+ propPath: k,
626
+ id: (_b2 = item.props.id) != null ? _b2 : "root"
627
+ });
628
+ newProps[k] = newValue;
629
+ }, item.props);
630
+ return __spreadProps(__spreadValues({}, item), {
631
+ props: newProps
632
+ });
633
+ }
334
634
 
335
- // ../core/lib/use-resolved-permissions.ts
635
+ // ../core/lib/data/flatten-node.ts
336
636
  init_react_import();
337
- var import_react4 = require("react");
637
+ var import_flat = __toESM(require_flat());
338
638
 
339
- // ../core/lib/flatten-data.ts
639
+ // ../core/lib/data/strip-slots.ts
340
640
  init_react_import();
641
+ var stripSlots = (data, config) => {
642
+ return mapSlotsSync(data, () => null, config);
643
+ };
341
644
 
342
- // ../core/lib/get-changed.ts
645
+ // ../core/lib/data/flatten-node.ts
646
+ var flattenNode = (node, config) => {
647
+ return __spreadProps(__spreadValues({}, node), {
648
+ props: (0, import_flat.flatten)(stripSlots(node, config).props)
649
+ });
650
+ };
651
+
652
+ // ../core/lib/data/walk-app-state.ts
653
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
654
+ var _a;
655
+ let newZones = {};
656
+ const newZoneIndex = {};
657
+ const newNodeIndex = {};
658
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
659
+ var _a2;
660
+ const [parentId] = zoneCompound.split(":");
661
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
662
+ const [_2, zone] = zoneCompound.split(":");
663
+ const newZoneCompound = `${newId || parentId}:${zone}`;
664
+ const newContent2 = mappedContent.map(
665
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
666
+ );
667
+ newZoneIndex[newZoneCompound] = {
668
+ contentIds: newContent2.map((item) => item.props.id),
669
+ type: zoneType
670
+ };
671
+ return [newZoneCompound, newContent2];
672
+ };
673
+ const processRelatedZones = (item, newId, initialPath) => {
674
+ forRelatedZones(
675
+ item,
676
+ state.data,
677
+ (relatedPath, relatedZoneCompound, relatedContent) => {
678
+ const [zoneCompound, newContent2] = processContent(
679
+ relatedPath,
680
+ relatedZoneCompound,
681
+ relatedContent,
682
+ "dropzone",
683
+ newId
684
+ );
685
+ newZones[zoneCompound] = newContent2;
686
+ },
687
+ initialPath
688
+ );
689
+ };
690
+ const processItem = (item, path, index) => {
691
+ const mappedItem = mapNodeOrSkip(item, path, index);
692
+ if (!mappedItem) return item;
693
+ const id = mappedItem.props.id;
694
+ const newProps = __spreadProps(__spreadValues({}, mapSlotsSync(
695
+ mappedItem,
696
+ (content, parentId2, slotId) => {
697
+ const zoneCompound = `${parentId2}:${slotId}`;
698
+ const [_2, newContent2] = processContent(
699
+ path,
700
+ zoneCompound,
701
+ content,
702
+ "slot",
703
+ parentId2
704
+ );
705
+ return newContent2;
706
+ },
707
+ config
708
+ ).props), {
709
+ id
710
+ });
711
+ processRelatedZones(item, id, path);
712
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
713
+ const thisZoneCompound = path[path.length - 1];
714
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
715
+ newNodeIndex[id] = {
716
+ data: newItem,
717
+ flatData: flattenNode(newItem, config),
718
+ path,
719
+ parentId,
720
+ zone
721
+ };
722
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
723
+ if (newProps.id === "root") {
724
+ delete finalData["type"];
725
+ delete finalData.props["id"];
726
+ }
727
+ return finalData;
728
+ };
729
+ const zones = state.data.zones || {};
730
+ const [_, newContent] = processContent(
731
+ [],
732
+ rootDroppableId,
733
+ state.data.content,
734
+ "root"
735
+ );
736
+ const processedContent = newContent;
737
+ const zonesAlreadyProcessed = Object.keys(newZones);
738
+ Object.keys(zones || {}).forEach((zoneCompound) => {
739
+ const [parentId] = zoneCompound.split(":");
740
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
741
+ return;
742
+ }
743
+ const [_2, newContent2] = processContent(
744
+ [rootDroppableId],
745
+ zoneCompound,
746
+ zones[zoneCompound],
747
+ "dropzone",
748
+ parentId
749
+ );
750
+ newZones[zoneCompound] = newContent2;
751
+ }, newZones);
752
+ const processedRoot = processItem(
753
+ {
754
+ type: "root",
755
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
756
+ },
757
+ [],
758
+ -1
759
+ );
760
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
761
+ props: processedRoot.props
762
+ });
763
+ return __spreadProps(__spreadValues({}, state), {
764
+ data: {
765
+ root,
766
+ content: processedContent,
767
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
768
+ },
769
+ indexes: {
770
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
771
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
772
+ }
773
+ });
774
+ }
775
+
776
+ // ../core/reducer/actions/set.ts
777
+ var setAction = (state, action, appStore) => {
778
+ if (typeof action.state === "object") {
779
+ const newState = __spreadValues(__spreadValues({}, state), action.state);
780
+ if (action.state.indexes) {
781
+ return newState;
782
+ }
783
+ console.warn(
784
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
785
+ );
786
+ return walkAppState(newState, appStore.config);
787
+ }
788
+ return __spreadValues(__spreadValues({}, state), action.state(state));
789
+ };
790
+
791
+ // ../core/reducer/actions/insert.ts
343
792
  init_react_import();
344
793
 
345
- // ../core/lib/use-resolved-data.ts
794
+ // ../core/lib/data/insert.ts
346
795
  init_react_import();
347
- var import_react5 = require("react");
796
+ var insert = (list, index, item) => {
797
+ const result = Array.from(list || []);
798
+ result.splice(index, 0, item);
799
+ return result;
800
+ };
348
801
 
349
- // ../core/lib/resolve-component-data.ts
802
+ // ../core/lib/generate-id.ts
350
803
  init_react_import();
351
804
 
352
- // ../core/lib/apply-dynamic-props.ts
805
+ // ../../node_modules/uuid/dist/esm-node/index.js
353
806
  init_react_import();
354
807
 
355
- // ../core/lib/resolve-root-data.ts
808
+ // ../../node_modules/uuid/dist/esm-node/rng.js
356
809
  init_react_import();
810
+ var import_crypto = __toESM(require("crypto"));
811
+ var rnds8Pool = new Uint8Array(256);
812
+ var poolPtr = rnds8Pool.length;
813
+ function rng() {
814
+ if (poolPtr > rnds8Pool.length - 16) {
815
+ import_crypto.default.randomFillSync(rnds8Pool);
816
+ poolPtr = 0;
817
+ }
818
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
819
+ }
357
820
 
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"
821
+ // ../../node_modules/uuid/dist/esm-node/stringify.js
822
+ init_react_import();
823
+ var byteToHex = [];
824
+ for (let i = 0; i < 256; ++i) {
825
+ byteToHex.push((i + 256).toString(16).slice(1));
826
+ }
827
+ function unsafeStringify(arr, offset = 0) {
828
+ 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]];
829
+ }
830
+
831
+ // ../../node_modules/uuid/dist/esm-node/v4.js
832
+ init_react_import();
833
+
834
+ // ../../node_modules/uuid/dist/esm-node/native.js
835
+ init_react_import();
836
+ var import_crypto2 = __toESM(require("crypto"));
837
+ var native_default = {
838
+ randomUUID: import_crypto2.default.randomUUID
839
+ };
840
+
841
+ // ../../node_modules/uuid/dist/esm-node/v4.js
842
+ function v4(options, buf, offset) {
843
+ if (native_default.randomUUID && !buf && !options) {
844
+ return native_default.randomUUID();
845
+ }
846
+ options = options || {};
847
+ const rnds = options.random || (options.rng || rng)();
848
+ rnds[6] = rnds[6] & 15 | 64;
849
+ rnds[8] = rnds[8] & 63 | 128;
850
+ if (buf) {
851
+ offset = offset || 0;
852
+ for (let i = 0; i < 16; ++i) {
853
+ buf[offset + i] = rnds[i];
854
+ }
855
+ return buf;
856
+ }
857
+ return unsafeStringify(rnds);
858
+ }
859
+ var v4_default = v4;
860
+
861
+ // ../core/lib/generate-id.ts
862
+ var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
863
+
864
+ // ../core/lib/data/get-ids-for-parent.ts
865
+ init_react_import();
866
+ var getIdsForParent = (zoneCompound, state) => {
867
+ const [parentId] = zoneCompound.split(":");
868
+ const node = state.indexes.nodes[parentId];
869
+ return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
870
+ };
871
+
872
+ // ../core/lib/data/populate-ids.ts
873
+ init_react_import();
874
+
875
+ // ../core/lib/data/walk-tree.ts
876
+ init_react_import();
877
+ function walkTree(data, config, callbackFn) {
878
+ var _a, _b;
879
+ const walkItem = (item) => {
880
+ return mapSlotsSync(
881
+ item,
882
+ (content, parentId, propName) => {
883
+ var _a2;
884
+ return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
374
885
  },
375
- options: [],
376
- controlsVisible: true
886
+ config
887
+ );
888
+ };
889
+ if ("props" in data) {
890
+ return walkItem(data);
891
+ }
892
+ const _data = data;
893
+ const zones = (_a = _data.zones) != null ? _a : {};
894
+ const mappedContent = _data.content.map(walkItem);
895
+ return {
896
+ root: walkItem(_data.root),
897
+ content: (_b = callbackFn(mappedContent, {
898
+ parentId: "root",
899
+ propName: "default-zone"
900
+ })) != null ? _b : mappedContent,
901
+ zones: Object.keys(zones).reduce(
902
+ (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
903
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
904
+ }),
905
+ {}
906
+ )
907
+ };
908
+ }
909
+
910
+ // ../core/lib/data/populate-ids.ts
911
+ var populateIds = (data, config, override = false) => {
912
+ const id = generateId(data.type);
913
+ return walkTree(
914
+ __spreadProps(__spreadValues({}, data), {
915
+ props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({ id }, data.props)
916
+ }),
917
+ config,
918
+ (contents) => contents.map((item) => {
919
+ const id2 = generateId(item.type);
920
+ return __spreadProps(__spreadValues({}, item), {
921
+ props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
922
+ });
923
+ })
924
+ );
925
+ };
926
+
927
+ // ../core/reducer/actions/insert.ts
928
+ function insertAction(state, action, appStore) {
929
+ const id = action.id || generateId(action.componentType);
930
+ const emptyComponentData = populateIds(
931
+ {
932
+ type: action.componentType,
933
+ props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
934
+ id
935
+ })
377
936
  },
378
- field: { focus: null }
937
+ appStore.config
938
+ );
939
+ const [parentId] = action.destinationZone.split(":");
940
+ const idsInPath = getIdsForParent(action.destinationZone, state);
941
+ return walkAppState(
942
+ state,
943
+ appStore.config,
944
+ (content, zoneCompound) => {
945
+ if (zoneCompound === action.destinationZone) {
946
+ return insert(
947
+ content || [],
948
+ action.destinationIndex,
949
+ emptyComponentData
950
+ );
951
+ }
952
+ return content;
953
+ },
954
+ (childItem, path) => {
955
+ if (childItem.props.id === id || childItem.props.id === parentId) {
956
+ return childItem;
957
+ } else if (idsInPath.includes(childItem.props.id)) {
958
+ return childItem;
959
+ } else if (path.includes(action.destinationZone)) {
960
+ return childItem;
961
+ }
962
+ return null;
963
+ }
964
+ );
965
+ }
966
+
967
+ // ../core/reducer/actions/replace.ts
968
+ init_react_import();
969
+ var replaceAction = (state, action, appStore) => {
970
+ const [parentId] = action.destinationZone.split(":");
971
+ const idsInPath = getIdsForParent(action.destinationZone, state);
972
+ const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
973
+ const idChanged = originalId !== action.data.props.id;
974
+ if (idChanged) {
975
+ throw new Error(
976
+ `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
977
+ );
379
978
  }
979
+ const data = populateIds(action.data, appStore.config);
980
+ return walkAppState(
981
+ state,
982
+ appStore.config,
983
+ (content, zoneCompound) => {
984
+ const newContent = [...content];
985
+ if (zoneCompound === action.destinationZone) {
986
+ newContent[action.destinationIndex] = data;
987
+ }
988
+ return newContent;
989
+ },
990
+ (childItem, path) => {
991
+ const pathIds = path.map((p) => p.split(":")[0]);
992
+ if (childItem.props.id === data.props.id) {
993
+ return data;
994
+ } else if (childItem.props.id === parentId) {
995
+ return childItem;
996
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
997
+ return childItem;
998
+ } else if (pathIds.indexOf(data.props.id) > -1) {
999
+ return childItem;
1000
+ }
1001
+ return null;
1002
+ }
1003
+ );
380
1004
  };
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
418
- });
1005
+
1006
+ // ../core/reducer/actions/replace-root.ts
1007
+ init_react_import();
1008
+ var replaceRootAction = (state, action, appStore) => {
1009
+ return walkAppState(
1010
+ state,
1011
+ appStore.config,
1012
+ (content) => content,
1013
+ (childItem) => {
1014
+ if (childItem.props.id === "root") {
1015
+ return __spreadProps(__spreadValues({}, childItem), {
1016
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
1017
+ readOnly: action.root.readOnly
1018
+ });
1019
+ }
1020
+ return childItem;
1021
+ }
1022
+ );
1023
+ };
1024
+
1025
+ // ../core/reducer/actions/duplicate.ts
1026
+ init_react_import();
1027
+
1028
+ // ../core/lib/data/get-item.ts
1029
+ init_react_import();
1030
+ function getItem(selector, state) {
1031
+ var _a, _b;
1032
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
1033
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
1034
+ }
1035
+
1036
+ // ../core/reducer/actions/duplicate.ts
1037
+ function duplicateAction(state, action, appStore) {
1038
+ const item = getItem(
1039
+ { index: action.sourceIndex, zone: action.sourceZone },
1040
+ state
1041
+ );
1042
+ const idsInPath = getIdsForParent(action.sourceZone, state);
1043
+ const newItem = __spreadProps(__spreadValues({}, item), {
1044
+ props: __spreadProps(__spreadValues({}, item.props), {
1045
+ id: generateId(item.type)
1046
+ })
1047
+ });
1048
+ const modified = walkAppState(
1049
+ state,
1050
+ appStore.config,
1051
+ (content, zoneCompound) => {
1052
+ if (zoneCompound === action.sourceZone) {
1053
+ return insert(content, action.sourceIndex + 1, item);
1054
+ }
1055
+ return content;
1056
+ },
1057
+ (childItem, path, index) => {
1058
+ const zoneCompound = path[path.length - 1];
1059
+ const parents = path.map((p) => p.split(":")[0]);
1060
+ if (parents.indexOf(newItem.props.id) > -1) {
1061
+ return __spreadProps(__spreadValues({}, childItem), {
1062
+ props: __spreadProps(__spreadValues({}, childItem.props), {
1063
+ id: generateId(childItem.type)
1064
+ })
1065
+ });
1066
+ }
1067
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
1068
+ return newItem;
1069
+ }
1070
+ const [sourceZoneParent] = action.sourceZone.split(":");
1071
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
1072
+ return childItem;
1073
+ }
1074
+ return null;
1075
+ }
1076
+ );
1077
+ return __spreadProps(__spreadValues({}, modified), {
1078
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
1079
+ itemSelector: {
1080
+ index: action.sourceIndex + 1,
1081
+ zone: action.sourceZone
1082
+ }
1083
+ })
1084
+ });
1085
+ }
1086
+
1087
+ // ../core/reducer/actions/reorder.ts
1088
+ init_react_import();
1089
+
1090
+ // ../core/reducer/actions/move.ts
1091
+ init_react_import();
1092
+
1093
+ // ../core/lib/data/remove.ts
1094
+ init_react_import();
1095
+ var remove = (list, index) => {
1096
+ const result = Array.from(list);
1097
+ result.splice(index, 1);
1098
+ return result;
1099
+ };
1100
+
1101
+ // ../core/reducer/actions/move.ts
1102
+ var moveAction = (state, action, appStore) => {
1103
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
1104
+ return state;
1105
+ }
1106
+ const item = getItem(
1107
+ { zone: action.sourceZone, index: action.sourceIndex },
1108
+ state
1109
+ );
1110
+ if (!item) return state;
1111
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
1112
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
1113
+ return walkAppState(
1114
+ state,
1115
+ appStore.config,
1116
+ (content, zoneCompound) => {
1117
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
1118
+ return insert(
1119
+ remove(content, action.sourceIndex),
1120
+ action.destinationIndex,
1121
+ item
1122
+ );
1123
+ } else if (zoneCompound === action.sourceZone) {
1124
+ return remove(content, action.sourceIndex);
1125
+ } else if (zoneCompound === action.destinationZone) {
1126
+ return insert(content, action.destinationIndex, item);
1127
+ }
1128
+ return content;
1129
+ },
1130
+ (childItem, path) => {
1131
+ const [sourceZoneParent] = action.sourceZone.split(":");
1132
+ const [destinationZoneParent] = action.destinationZone.split(":");
1133
+ const childId = childItem.props.id;
1134
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
1135
+ return childItem;
1136
+ }
1137
+ return null;
1138
+ }
1139
+ );
1140
+ };
1141
+
1142
+ // ../core/reducer/actions/reorder.ts
1143
+ var reorderAction = (state, action, appStore) => {
1144
+ return moveAction(
1145
+ state,
1146
+ {
1147
+ type: "move",
1148
+ sourceIndex: action.sourceIndex,
1149
+ sourceZone: action.destinationZone,
1150
+ destinationIndex: action.destinationIndex,
1151
+ destinationZone: action.destinationZone
1152
+ },
1153
+ appStore
1154
+ );
1155
+ };
1156
+
1157
+ // ../core/reducer/actions/remove.ts
1158
+ init_react_import();
1159
+ var removeAction = (state, action, appStore) => {
1160
+ const item = getItem({ index: action.index, zone: action.zone }, state);
1161
+ const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
1162
+ (acc, [nodeId, nodeData]) => {
1163
+ const pathIds = nodeData.path.map((p) => p.split(":")[0]);
1164
+ if (pathIds.includes(item.props.id)) {
1165
+ return [...acc, nodeId];
1166
+ }
1167
+ return acc;
1168
+ },
1169
+ [item.props.id]
1170
+ );
1171
+ const newState = walkAppState(
1172
+ state,
1173
+ appStore.config,
1174
+ (content, zoneCompound) => {
1175
+ if (zoneCompound === action.zone) {
1176
+ return remove(content, action.index);
1177
+ }
1178
+ return content;
1179
+ }
1180
+ );
1181
+ Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
1182
+ const parentId = zoneCompound.split(":")[0];
1183
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
1184
+ delete newState.data.zones[zoneCompound];
419
1185
  }
420
1186
  });
1187
+ Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
1188
+ const parentId = zoneCompound.split(":")[0];
1189
+ if (nodesToDelete.includes(parentId)) {
1190
+ delete newState.indexes.zones[zoneCompound];
1191
+ }
1192
+ });
1193
+ nodesToDelete.forEach((id) => {
1194
+ delete newState.indexes.nodes[id];
1195
+ });
1196
+ return newState;
1197
+ };
1198
+
1199
+ // ../core/reducer/actions/register-zone.ts
1200
+ init_react_import();
1201
+
1202
+ // ../core/lib/data/setup-zone.ts
1203
+ init_react_import();
1204
+ var setupZone = (data, zoneKey) => {
1205
+ if (zoneKey === rootDroppableId) {
1206
+ return data;
1207
+ }
1208
+ const newData = __spreadProps(__spreadValues({}, data), {
1209
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
1210
+ });
1211
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
1212
+ return newData;
1213
+ };
1214
+
1215
+ // ../core/reducer/actions/register-zone.ts
1216
+ var zoneCache = {};
1217
+ function registerZoneAction(state, action) {
1218
+ if (zoneCache[action.zone]) {
1219
+ return __spreadProps(__spreadValues({}, state), {
1220
+ data: __spreadProps(__spreadValues({}, state.data), {
1221
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
1222
+ [action.zone]: zoneCache[action.zone]
1223
+ })
1224
+ }),
1225
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1226
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
1227
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
1228
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
1229
+ type: "dropzone"
1230
+ })
1231
+ })
1232
+ })
1233
+ });
1234
+ }
1235
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1236
+ }
1237
+ function unregisterZoneAction(state, action) {
1238
+ const _zones = __spreadValues({}, state.data.zones || {});
1239
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
1240
+ if (_zones[action.zone]) {
1241
+ zoneCache[action.zone] = _zones[action.zone];
1242
+ delete _zones[action.zone];
1243
+ }
1244
+ delete zoneIndex[action.zone];
1245
+ return __spreadProps(__spreadValues({}, state), {
1246
+ data: __spreadProps(__spreadValues({}, state.data), {
1247
+ zones: _zones
1248
+ }),
1249
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1250
+ zones: zoneIndex
1251
+ })
1252
+ });
421
1253
  }
422
1254
 
1255
+ // ../core/reducer/actions/set-data.ts
1256
+ init_react_import();
1257
+ var setDataAction = (state, action, appStore) => {
1258
+ if (typeof action.data === "object") {
1259
+ console.warn(
1260
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1261
+ );
1262
+ return walkAppState(
1263
+ __spreadProps(__spreadValues({}, state), {
1264
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
1265
+ }),
1266
+ appStore.config
1267
+ );
1268
+ }
1269
+ return walkAppState(
1270
+ __spreadProps(__spreadValues({}, state), {
1271
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1272
+ }),
1273
+ appStore.config
1274
+ );
1275
+ };
1276
+
1277
+ // ../core/reducer/actions/set-ui.ts
1278
+ init_react_import();
1279
+ var setUiAction = (state, action) => {
1280
+ if (typeof action.ui === "object") {
1281
+ return __spreadProps(__spreadValues({}, state), {
1282
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1283
+ });
1284
+ }
1285
+ return __spreadProps(__spreadValues({}, state), {
1286
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1287
+ });
1288
+ };
1289
+
1290
+ // ../core/lib/data/make-state-public.ts
1291
+ init_react_import();
1292
+ var makeStatePublic = (state) => {
1293
+ const { data, ui } = state;
1294
+ return { data, ui };
1295
+ };
1296
+
1297
+ // ../core/reducer/actions.tsx
1298
+ init_react_import();
1299
+
1300
+ // ../core/reducer/index.ts
1301
+ function storeInterceptor(reducer, record, onAction) {
1302
+ return (state, action) => {
1303
+ const newAppState = reducer(state, action);
1304
+ const isValidType = ![
1305
+ "registerZone",
1306
+ "unregisterZone",
1307
+ "setData",
1308
+ "setUi",
1309
+ "set"
1310
+ ].includes(action.type);
1311
+ if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1312
+ if (record) record(newAppState);
1313
+ }
1314
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1315
+ return newAppState;
1316
+ };
1317
+ }
1318
+ function createReducer({
1319
+ record,
1320
+ onAction,
1321
+ appStore
1322
+ }) {
1323
+ return storeInterceptor(
1324
+ (state, action) => {
1325
+ if (action.type === "set") {
1326
+ return setAction(state, action, appStore);
1327
+ }
1328
+ if (action.type === "insert") {
1329
+ return insertAction(state, action, appStore);
1330
+ }
1331
+ if (action.type === "replace") {
1332
+ return replaceAction(state, action, appStore);
1333
+ }
1334
+ if (action.type === "replaceRoot") {
1335
+ return replaceRootAction(state, action, appStore);
1336
+ }
1337
+ if (action.type === "duplicate") {
1338
+ return duplicateAction(state, action, appStore);
1339
+ }
1340
+ if (action.type === "reorder") {
1341
+ return reorderAction(state, action, appStore);
1342
+ }
1343
+ if (action.type === "move") {
1344
+ return moveAction(state, action, appStore);
1345
+ }
1346
+ if (action.type === "remove") {
1347
+ return removeAction(state, action, appStore);
1348
+ }
1349
+ if (action.type === "registerZone") {
1350
+ return registerZoneAction(state, action);
1351
+ }
1352
+ if (action.type === "unregisterZone") {
1353
+ return unregisterZoneAction(state, action);
1354
+ }
1355
+ if (action.type === "setData") {
1356
+ return setDataAction(state, action, appStore);
1357
+ }
1358
+ if (action.type === "setUi") {
1359
+ return setUiAction(state, action);
1360
+ }
1361
+ return state;
1362
+ },
1363
+ record,
1364
+ onAction
1365
+ );
1366
+ }
1367
+
1368
+ // ../core/components/ViewportControls/default-viewports.ts
1369
+ init_react_import();
1370
+ var defaultViewports = [
1371
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1372
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1373
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1374
+ ];
1375
+
423
1376
  // ../../node_modules/zustand/esm/vanilla.mjs
424
1377
  init_react_import();
425
1378
  var createStoreImpl = (createState) => {
@@ -445,94 +1398,694 @@ var createStoreImpl = (createState) => {
445
1398
  };
446
1399
  var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
447
1400
 
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: {}
1401
+ // ../../node_modules/zustand/esm/react.mjs
1402
+ init_react_import();
1403
+ var import_react4 = __toESM(require("react"), 1);
1404
+ var identity = (arg) => arg;
1405
+ function useStore(api, selector = identity) {
1406
+ const slice = import_react4.default.useSyncExternalStore(
1407
+ api.subscribe,
1408
+ () => selector(api.getState()),
1409
+ () => selector(api.getInitialState())
1410
+ );
1411
+ import_react4.default.useDebugValue(slice);
1412
+ return slice;
1413
+ }
1414
+ var createImpl = (createState) => {
1415
+ const api = createStore(createState);
1416
+ const useBoundStore = (selector) => useStore(api, selector);
1417
+ Object.assign(useBoundStore, api);
1418
+ return useBoundStore;
1419
+ };
1420
+ var create = (createState) => createState ? createImpl(createState) : createImpl;
1421
+
1422
+ // ../../node_modules/zustand/esm/middleware.mjs
1423
+ init_react_import();
1424
+ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1425
+ const origSubscribe = api.subscribe;
1426
+ api.subscribe = (selector, optListener, options) => {
1427
+ let listener = selector;
1428
+ if (optListener) {
1429
+ const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
1430
+ let currentSlice = selector(api.getState());
1431
+ listener = (state) => {
1432
+ const nextSlice = selector(state);
1433
+ if (!equalityFn(currentSlice, nextSlice)) {
1434
+ const previousSlice = currentSlice;
1435
+ optListener(currentSlice = nextSlice, previousSlice);
1436
+ }
1437
+ };
1438
+ if (options == null ? void 0 : options.fireImmediately) {
1439
+ optListener(currentSlice, currentSlice);
1440
+ }
1441
+ }
1442
+ return origSubscribe(listener);
1443
+ };
1444
+ const initialState = fn(set, get, api);
1445
+ return initialState;
1446
+ };
1447
+ var subscribeWithSelector = subscribeWithSelectorImpl;
1448
+
1449
+ // ../core/store/index.ts
1450
+ var import_react9 = require("react");
1451
+
1452
+ // ../core/store/slices/history.ts
1453
+ init_react_import();
1454
+ var import_react6 = require("react");
1455
+
1456
+ // ../core/lib/use-hotkey.ts
1457
+ init_react_import();
1458
+ var import_react5 = require("react");
1459
+ var useHotkeyStore = create()(
1460
+ subscribeWithSelector((set) => ({
1461
+ held: {},
1462
+ hold: (key) => set((s) => s.held[key] ? s : { held: __spreadProps(__spreadValues({}, s.held), { [key]: true }) }),
1463
+ release: (key) => set((s) => s.held[key] ? { held: __spreadProps(__spreadValues({}, s.held), { [key]: false }) } : s),
1464
+ reset: (held = {}) => set(() => ({ held })),
1465
+ triggers: {}
459
1466
  }))
460
1467
  );
461
1468
 
462
- // ../core/lib/get-zone-id.ts
1469
+ // ../core/store/slices/history.ts
1470
+ var EMPTY_HISTORY_INDEX = 0;
1471
+ function debounce(func, timeout = 300) {
1472
+ let timer;
1473
+ return (...args) => {
1474
+ clearTimeout(timer);
1475
+ timer = setTimeout(() => {
1476
+ func(...args);
1477
+ }, timeout);
1478
+ };
1479
+ }
1480
+ var tidyState = (state) => {
1481
+ return __spreadProps(__spreadValues({}, state), {
1482
+ ui: __spreadProps(__spreadValues({}, state.ui), {
1483
+ field: {
1484
+ focus: null
1485
+ }
1486
+ })
1487
+ });
1488
+ };
1489
+ var createHistorySlice = (set, get) => {
1490
+ const record = debounce((state) => {
1491
+ const { histories, index } = get().history;
1492
+ const history = {
1493
+ state,
1494
+ id: generateId("history")
1495
+ };
1496
+ const newHistories = [...histories.slice(0, index + 1), history];
1497
+ set({
1498
+ history: __spreadProps(__spreadValues({}, get().history), {
1499
+ histories: newHistories,
1500
+ index: newHistories.length - 1
1501
+ })
1502
+ });
1503
+ }, 250);
1504
+ return {
1505
+ initialAppState: {},
1506
+ index: EMPTY_HISTORY_INDEX,
1507
+ histories: [],
1508
+ hasPast: () => get().history.index > EMPTY_HISTORY_INDEX,
1509
+ hasFuture: () => get().history.index < get().history.histories.length - 1,
1510
+ prevHistory: () => {
1511
+ const { history } = get();
1512
+ return history.hasPast() ? history.histories[history.index - 1] : null;
1513
+ },
1514
+ nextHistory: () => {
1515
+ const s = get().history;
1516
+ return s.hasFuture() ? s.histories[s.index + 1] : null;
1517
+ },
1518
+ currentHistory: () => get().history.histories[get().history.index],
1519
+ back: () => {
1520
+ var _a;
1521
+ const { history, dispatch } = get();
1522
+ if (history.hasPast()) {
1523
+ const state = tidyState(
1524
+ ((_a = history.prevHistory()) == null ? void 0 : _a.state) || history.initialAppState
1525
+ );
1526
+ dispatch({
1527
+ type: "set",
1528
+ state
1529
+ });
1530
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index - 1 }) });
1531
+ }
1532
+ },
1533
+ forward: () => {
1534
+ var _a;
1535
+ const { history, dispatch } = get();
1536
+ if (history.hasFuture()) {
1537
+ const state = (_a = history.nextHistory()) == null ? void 0 : _a.state;
1538
+ dispatch({ type: "set", state: state ? tidyState(state) : {} });
1539
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index + 1 }) });
1540
+ }
1541
+ },
1542
+ setHistories: (histories) => {
1543
+ var _a;
1544
+ const { dispatch, history } = get();
1545
+ dispatch({
1546
+ type: "set",
1547
+ state: ((_a = history.histories[history.histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
1548
+ });
1549
+ set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
1550
+ },
1551
+ setHistoryIndex: (index) => {
1552
+ var _a;
1553
+ const { dispatch, history } = get();
1554
+ dispatch({
1555
+ type: "set",
1556
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1557
+ });
1558
+ set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1559
+ },
1560
+ record
1561
+ };
1562
+ };
1563
+
1564
+ // ../core/store/slices/nodes.ts
463
1565
  init_react_import();
464
- var getZoneId = (zoneCompound) => {
465
- if (!zoneCompound) {
466
- return [];
467
- }
468
- if (zoneCompound && zoneCompound.indexOf(":") > -1) {
469
- return zoneCompound.split(":");
1566
+ var createNodesSlice = (set, get) => ({
1567
+ nodes: {},
1568
+ registerNode: (id, node) => {
1569
+ const s = get().nodes;
1570
+ const emptyNode = {
1571
+ id,
1572
+ methods: {
1573
+ sync: () => null,
1574
+ hideOverlay: () => null,
1575
+ showOverlay: () => null
1576
+ },
1577
+ element: null
1578
+ };
1579
+ const existingNode = s.nodes[id];
1580
+ set({
1581
+ nodes: __spreadProps(__spreadValues({}, s), {
1582
+ nodes: __spreadProps(__spreadValues({}, s.nodes), {
1583
+ [id]: __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, emptyNode), existingNode), node), {
1584
+ id
1585
+ })
1586
+ })
1587
+ })
1588
+ });
1589
+ },
1590
+ unregisterNode: (id) => {
1591
+ const s = get().nodes;
1592
+ const existingNode = s.nodes[id];
1593
+ if (existingNode) {
1594
+ const newNodes = __spreadValues({}, s.nodes);
1595
+ delete newNodes[id];
1596
+ set({
1597
+ nodes: __spreadProps(__spreadValues({}, s), {
1598
+ nodes: newNodes
1599
+ })
1600
+ });
1601
+ }
470
1602
  }
471
- return [rootDroppableId, zoneCompound];
1603
+ });
1604
+
1605
+ // ../core/store/slices/permissions.ts
1606
+ init_react_import();
1607
+ var import_react7 = require("react");
1608
+
1609
+ // ../core/lib/data/flatten-data.ts
1610
+ init_react_import();
1611
+ var flattenData = (state, config) => {
1612
+ const data = [];
1613
+ walkAppState(
1614
+ state,
1615
+ config,
1616
+ (content) => content,
1617
+ (item) => {
1618
+ data.push(item);
1619
+ return null;
1620
+ }
1621
+ );
1622
+ return data;
472
1623
  };
473
1624
 
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
1625
+ // ../core/lib/get-changed.ts
1626
+ init_react_import();
1627
+ var getChanged = (newItem, oldItem) => {
1628
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1629
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1630
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1631
+ return __spreadProps(__spreadValues({}, acc), {
1632
+ [item]: oldItemProps[item] !== newItemProps[item]
1633
+ });
1634
+ }, {}) : {};
1635
+ };
1636
+
1637
+ // ../core/store/slices/permissions.ts
1638
+ var createPermissionsSlice = (set, get) => {
1639
+ const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1640
+ const { state, permissions, config } = get();
1641
+ const { cache: cache2, globalPermissions } = permissions;
1642
+ const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1643
+ var _a, _b, _c;
1644
+ const { config: config2, state: appState, setComponentLoading } = get();
1645
+ const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1646
+ if (!componentConfig) {
1647
+ return;
1648
+ }
1649
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1650
+ if (componentConfig.resolvePermissions) {
1651
+ const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1652
+ if (Object.values(changed).some((el) => el === true) || force2) {
1653
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1654
+ const resolvedPermissions = yield componentConfig.resolvePermissions(
1655
+ item2,
1656
+ {
1657
+ changed,
1658
+ lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1659
+ permissions: initialPermissions,
1660
+ appState: makeStatePublic(appState),
1661
+ lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1662
+ }
1663
+ );
1664
+ const latest = get().permissions;
1665
+ set({
1666
+ permissions: __spreadProps(__spreadValues({}, latest), {
1667
+ cache: __spreadProps(__spreadValues({}, latest.cache), {
1668
+ [item2.props.id]: {
1669
+ lastData: item2,
1670
+ lastPermissions: resolvedPermissions
1671
+ }
1672
+ }),
1673
+ resolvedPermissions: __spreadProps(__spreadValues({}, latest.resolvedPermissions), {
1674
+ [item2.props.id]: resolvedPermissions
1675
+ })
1676
+ })
1677
+ });
1678
+ clearTimeout2();
488
1679
  }
489
- ];
1680
+ }
1681
+ });
1682
+ const resolveDataForRoot = (force2 = false) => {
1683
+ const { state: appState } = get();
1684
+ resolveDataForItem(
1685
+ // Shim the root data in by conforming to component data shape
1686
+ {
1687
+ type: "root",
1688
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1689
+ },
1690
+ force2
1691
+ );
1692
+ };
1693
+ const { item, type, root } = params;
1694
+ if (item) {
1695
+ yield resolveDataForItem(item, force);
1696
+ } else if (type) {
1697
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1698
+ yield resolveDataForItem(item2, force);
1699
+ }));
1700
+ } else if (root) {
1701
+ resolveDataForRoot(force);
1702
+ } else {
1703
+ flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1704
+ yield resolveDataForItem(item2, force);
1705
+ }));
490
1706
  }
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];
1707
+ });
1708
+ const refreshPermissions = (params) => resolvePermissions(params, true);
1709
+ return {
1710
+ cache: {},
1711
+ globalPermissions: {
1712
+ drag: true,
1713
+ edit: true,
1714
+ delete: true,
1715
+ duplicate: true,
1716
+ insert: true
1717
+ },
1718
+ resolvedPermissions: {},
1719
+ getPermissions: ({ item, type, root } = {}) => {
1720
+ const { config, permissions } = get();
1721
+ const { globalPermissions, resolvedPermissions } = permissions;
1722
+ if (item) {
1723
+ const componentConfig = config.components[item.type];
1724
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1725
+ const resolvedForItem = resolvedPermissions[item.props.id];
1726
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1727
+ } else if (type) {
1728
+ const componentConfig = config.components[type];
1729
+ return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1730
+ } else if (root) {
1731
+ const rootConfig = config.root;
1732
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1733
+ const resolvedForItem = resolvedPermissions["root"];
1734
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1735
+ }
1736
+ return globalPermissions;
1737
+ },
1738
+ resolvePermissions,
1739
+ refreshPermissions
1740
+ };
1741
+ };
1742
+
1743
+ // ../core/store/slices/fields.ts
1744
+ init_react_import();
1745
+ var import_react8 = require("react");
1746
+ var createFieldsSlice = (_set, _get) => {
1747
+ return {
1748
+ fields: {},
1749
+ loading: false,
1750
+ lastResolvedData: {},
1751
+ id: void 0
1752
+ };
1753
+ };
1754
+
1755
+ // ../core/lib/resolve-component-data.ts
1756
+ init_react_import();
1757
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1758
+ var cache = { lastChange: {} };
1759
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
1760
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
1761
+ if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
1762
+ const id = "id" in item.props ? item.props.id : "root";
1763
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1764
+ if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
1765
+ return { node: resolved, didChange: false };
495
1766
  }
496
- if (!parentZone) {
497
- return acc;
1767
+ const changed = getChanged(item, oldItem);
1768
+ if (onResolveStart) {
1769
+ onResolveStart(item);
498
1770
  }
499
- const itemIndex = parentZone.findIndex(
500
- (queryItem) => queryItem.props.id === area
501
- );
502
- const item = parentZone[itemIndex];
503
- if (!item) {
504
- return acc;
1771
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1772
+ changed,
1773
+ lastData: oldItem,
1774
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1775
+ trigger
1776
+ });
1777
+ let resolvedItem = __spreadProps(__spreadValues({}, item), {
1778
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1779
+ });
1780
+ if (recursive) {
1781
+ resolvedItem = yield mapSlotsAsync(
1782
+ resolvedItem,
1783
+ (content) => __async(void 0, null, function* () {
1784
+ return Promise.all(
1785
+ content.map(
1786
+ (childItem) => __async(void 0, null, function* () {
1787
+ return (yield resolveComponentData(
1788
+ childItem,
1789
+ config,
1790
+ metadata,
1791
+ onResolveStart,
1792
+ onResolveEnd,
1793
+ trigger,
1794
+ false
1795
+ )).node;
1796
+ })
1797
+ )
1798
+ );
1799
+ }),
1800
+ false,
1801
+ createIsSlotConfig(config)
1802
+ );
505
1803
  }
506
- return [
507
- ...acc,
508
- {
509
- label: item.type.toString(),
510
- selector: {
511
- index: itemIndex,
512
- zone: parentZoneCompound
513
- },
514
- zoneCompound
515
- }
516
- ];
517
- }, []);
1804
+ if (Object.keys(readOnly).length) {
1805
+ resolvedItem.readOnly = readOnly;
1806
+ }
1807
+ cache.lastChange[id] = {
1808
+ item,
1809
+ resolved: resolvedItem
1810
+ };
1811
+ if (onResolveEnd) {
1812
+ onResolveEnd(resolvedItem);
1813
+ }
1814
+ return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
1815
+ }
1816
+ return { node: item, didChange: false };
1817
+ });
1818
+
1819
+ // ../core/lib/data/to-root.ts
1820
+ init_react_import();
1821
+ var toRoot = (item) => {
1822
+ if ("type" in item && item.type !== "root") {
1823
+ throw new Error("Converting non-root item to root.");
1824
+ }
1825
+ const { readOnly } = item;
1826
+ if (item.props) {
1827
+ if ("id" in item.props) {
1828
+ const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
1829
+ return { props, readOnly };
1830
+ }
1831
+ return { props: item.props, readOnly };
1832
+ }
1833
+ return { props: {}, readOnly };
518
1834
  };
1835
+
1836
+ // ../core/store/default-app-state.ts
1837
+ init_react_import();
1838
+ var defaultAppState = {
1839
+ data: { content: [], root: {}, zones: {} },
1840
+ ui: {
1841
+ leftSideBarVisible: true,
1842
+ rightSideBarVisible: true,
1843
+ arrayState: {},
1844
+ itemSelector: null,
1845
+ componentList: {},
1846
+ isDragging: false,
1847
+ previewMode: "edit",
1848
+ viewports: {
1849
+ current: {
1850
+ width: defaultViewports[0].width,
1851
+ height: defaultViewports[0].height || "auto"
1852
+ },
1853
+ options: [],
1854
+ controlsVisible: true
1855
+ },
1856
+ field: { focus: null }
1857
+ },
1858
+ indexes: {
1859
+ nodes: {},
1860
+ zones: {}
1861
+ }
1862
+ };
1863
+
1864
+ // ../core/store/index.ts
1865
+ var defaultPageFields = {
1866
+ title: { type: "text" }
1867
+ };
1868
+ var createAppStore = (initialAppStore) => create()(
1869
+ subscribeWithSelector((set, get) => {
1870
+ var _a, _b;
1871
+ return __spreadProps(__spreadValues({
1872
+ state: defaultAppState,
1873
+ config: { components: {} },
1874
+ componentState: {},
1875
+ plugins: [],
1876
+ overrides: {},
1877
+ viewports: defaultViewports,
1878
+ zoomConfig: {
1879
+ autoZoom: 1,
1880
+ rootHeight: 0,
1881
+ zoom: 1
1882
+ },
1883
+ status: "LOADING",
1884
+ iframe: {},
1885
+ metadata: {}
1886
+ }, initialAppStore), {
1887
+ fields: createFieldsSlice(set, get),
1888
+ history: createHistorySlice(set, get),
1889
+ nodes: createNodesSlice(set, get),
1890
+ permissions: createPermissionsSlice(set, get),
1891
+ getComponentConfig: (type) => {
1892
+ var _a2;
1893
+ const { config, selectedItem } = get();
1894
+ const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
1895
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1896
+ },
1897
+ selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
1898
+ (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
1899
+ initialAppStore.state
1900
+ ) : null,
1901
+ dispatch: (action) => set((s) => {
1902
+ var _a2, _b2;
1903
+ const { record } = get().history;
1904
+ const dispatch = createReducer({
1905
+ record,
1906
+ appStore: s
1907
+ });
1908
+ const state = dispatch(s.state, action);
1909
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1910
+ (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
1911
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1912
+ }),
1913
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1914
+ setStatus: (status) => set({ status }),
1915
+ setComponentState: (componentState) => set({ componentState }),
1916
+ pendingLoadTimeouts: {},
1917
+ setComponentLoading: (id, loading = true, defer = 0) => {
1918
+ const { setComponentState, pendingLoadTimeouts } = get();
1919
+ const loadId = generateId();
1920
+ const setLoading = () => {
1921
+ var _a2;
1922
+ const { componentState } = get();
1923
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1924
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1925
+ loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
1926
+ })
1927
+ }));
1928
+ };
1929
+ const unsetLoading = () => {
1930
+ var _a2;
1931
+ const { componentState } = get();
1932
+ clearTimeout(timeout);
1933
+ delete pendingLoadTimeouts[loadId];
1934
+ set({ pendingLoadTimeouts });
1935
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1936
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1937
+ loadingCount: Math.max(
1938
+ (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
1939
+ 0
1940
+ )
1941
+ })
1942
+ }));
1943
+ };
1944
+ const timeout = setTimeout(() => {
1945
+ if (loading) {
1946
+ setLoading();
1947
+ } else {
1948
+ unsetLoading();
1949
+ }
1950
+ delete pendingLoadTimeouts[loadId];
1951
+ set({ pendingLoadTimeouts });
1952
+ }, defer);
1953
+ set({
1954
+ pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
1955
+ [id]: timeout
1956
+ })
1957
+ });
1958
+ return unsetLoading;
1959
+ },
1960
+ unsetComponentLoading: (id) => {
1961
+ const { setComponentLoading } = get();
1962
+ setComponentLoading(id, false);
1963
+ },
1964
+ // Helper
1965
+ setUi: (ui, recordHistory) => set((s) => {
1966
+ const dispatch = createReducer({
1967
+ record: () => {
1968
+ },
1969
+ appStore: s
1970
+ });
1971
+ const state = dispatch(s.state, {
1972
+ type: "setUi",
1973
+ ui,
1974
+ recordHistory
1975
+ });
1976
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1977
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1978
+ }),
1979
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1980
+ const { config, metadata, setComponentLoading, permissions } = get();
1981
+ const timeouts = {};
1982
+ return yield resolveComponentData(
1983
+ componentData,
1984
+ config,
1985
+ metadata,
1986
+ (item) => {
1987
+ const id = "id" in item.props ? item.props.id : "root";
1988
+ timeouts[id] = setComponentLoading(id, true, 50);
1989
+ },
1990
+ (item) => __async(void 0, null, function* () {
1991
+ const id = "id" in item.props ? item.props.id : "root";
1992
+ if ("type" in item) {
1993
+ yield permissions.refreshPermissions({ item });
1994
+ } else {
1995
+ yield permissions.refreshPermissions({ root: true });
1996
+ }
1997
+ timeouts[id]();
1998
+ }),
1999
+ trigger
2000
+ );
2001
+ }),
2002
+ resolveAndCommitData: () => __async(void 0, null, function* () {
2003
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
2004
+ walkAppState(
2005
+ state,
2006
+ config,
2007
+ (content) => content,
2008
+ (childItem) => {
2009
+ resolveComponentData2(childItem, "load").then((resolved) => {
2010
+ const { state: state2 } = get();
2011
+ const node = state2.indexes.nodes[resolved.node.props.id];
2012
+ if (node && resolved.didChange) {
2013
+ if (resolved.node.props.id === "root") {
2014
+ dispatch({
2015
+ type: "replaceRoot",
2016
+ root: toRoot(resolved.node)
2017
+ });
2018
+ } else {
2019
+ const zoneCompound = `${node.parentId}:${node.zone}`;
2020
+ const parentZone = state2.indexes.zones[zoneCompound];
2021
+ const index = parentZone.contentIds.indexOf(
2022
+ resolved.node.props.id
2023
+ );
2024
+ dispatch({
2025
+ type: "replace",
2026
+ data: resolved.node,
2027
+ destinationIndex: index,
2028
+ destinationZone: zoneCompound
2029
+ });
2030
+ }
2031
+ }
2032
+ });
2033
+ return childItem;
2034
+ }
2035
+ );
2036
+ })
2037
+ });
2038
+ })
2039
+ );
2040
+ var appStoreContext = (0, import_react9.createContext)(createAppStore());
2041
+ function useAppStore(selector) {
2042
+ const context = (0, import_react9.useContext)(appStoreContext);
2043
+ return useStore(context, selector);
2044
+ }
2045
+ function useAppStoreApi() {
2046
+ return (0, import_react9.useContext)(appStoreContext);
2047
+ }
2048
+
2049
+ // ../core/lib/use-breadcrumbs.ts
519
2050
  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
- );
2051
+ const selectedId = useAppStore((s) => {
2052
+ var _a;
2053
+ return (_a = s.selectedItem) == null ? void 0 : _a.props.id;
2054
+ });
2055
+ const config = useAppStore((s) => s.config);
2056
+ const path = useAppStore((s) => {
2057
+ var _a;
2058
+ return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
2059
+ });
2060
+ const appStore = useAppStoreApi();
2061
+ return (0, import_react10.useMemo)(() => {
2062
+ const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
2063
+ var _a, _b, _c;
2064
+ const [componentId] = zoneCompound.split(":");
2065
+ if (componentId === "root") {
2066
+ return {
2067
+ label: "Page",
2068
+ selector: null
2069
+ };
2070
+ }
2071
+ const node = appStore.getState().state.indexes.nodes[componentId];
2072
+ const parentId = node.path[node.path.length - 1];
2073
+ const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
2074
+ const index = contentIds.indexOf(componentId);
2075
+ const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
2076
+ return {
2077
+ label,
2078
+ selector: node ? {
2079
+ index,
2080
+ zone: node.path[node.path.length - 1]
2081
+ } : null
2082
+ };
2083
+ })) || [];
531
2084
  if (renderCount) {
532
2085
  return breadcrumbs.slice(breadcrumbs.length - renderCount);
533
2086
  }
534
2087
  return breadcrumbs;
535
- }, [selectedItem, dzContext == null ? void 0 : dzContext.pathData, renderCount]);
2088
+ }, [path, renderCount]);
536
2089
  };
537
2090
 
538
2091
  // ../core/components/Loader/index.tsx
@@ -544,10 +2097,10 @@ init_react_import();
544
2097
  // ../core/lib/filter.ts
545
2098
  init_react_import();
546
2099
 
547
- // ../core/lib/reorder.ts
2100
+ // ../core/lib/data/reorder.ts
548
2101
  init_react_import();
549
2102
 
550
- // ../core/lib/replace.ts
2103
+ // ../core/lib/data/replace.ts
551
2104
  init_react_import();
552
2105
 
553
2106
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
@@ -555,7 +2108,7 @@ init_react_import();
555
2108
  var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
556
2109
 
557
2110
  // ../core/components/Loader/index.tsx
558
- var import_jsx_runtime4 = require("react/jsx-runtime");
2111
+ var import_jsx_runtime2 = require("react/jsx-runtime");
559
2112
  var getClassName2 = get_class_name_factory_default("Loader", styles_module_default3);
560
2113
  var Loader = (_a) => {
561
2114
  var _b = _a, {
@@ -565,7 +2118,7 @@ var Loader = (_a) => {
565
2118
  "color",
566
2119
  "size"
567
2120
  ]);
568
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2121
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
569
2122
  "span",
570
2123
  __spreadValues({
571
2124
  className: getClassName2(),
@@ -580,7 +2133,7 @@ var Loader = (_a) => {
580
2133
  };
581
2134
 
582
2135
  // ../core/components/SidebarSection/index.tsx
583
- var import_jsx_runtime5 = require("react/jsx-runtime");
2136
+ var import_jsx_runtime3 = require("react/jsx-runtime");
584
2137
  var getClassName3 = get_class_name_factory_default("SidebarSection", styles_module_default);
585
2138
  var SidebarSection = ({
586
2139
  children,
@@ -591,17 +2144,17 @@ var SidebarSection = ({
591
2144
  noPadding,
592
2145
  isLoading
593
2146
  }) => {
594
- const { setUi } = useAppContext();
2147
+ const setUi = useAppStore((s) => s.setUi);
595
2148
  const breadcrumbs = useBreadcrumbs(1);
596
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2149
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
597
2150
  "div",
598
2151
  {
599
2152
  className: getClassName3({ noBorderTop, noPadding }),
600
2153
  style: { background },
601
2154
  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)(
2155
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName3("title"), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: getClassName3("breadcrumbs"), children: [
2156
+ showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: getClassName3("breadcrumb"), children: [
2157
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
605
2158
  "button",
606
2159
  {
607
2160
  type: "button",
@@ -610,12 +2163,12 @@ var SidebarSection = ({
610
2163
  children: breadcrumb.label
611
2164
  }
612
2165
  ),
613
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChevronRight, { size: 16 })
2166
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChevronRight, { size: 16 })
614
2167
  ] }, 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 }) })
2168
+ /* @__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
2169
  ] }) }),
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 }) })
2170
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName3("content"), children }),
2171
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName3("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Loader, { size: 32 }) })
619
2172
  ]
620
2173
  }
621
2174
  );
@@ -629,18 +2182,18 @@ init_react_import();
629
2182
  var styles_module_default4 = { "OutlineList": "_OutlineList_w4lzv_1", "OutlineListItem": "_OutlineListItem_w4lzv_25", "OutlineListItem--clickable": "_OutlineListItem--clickable_w4lzv_45" };
630
2183
 
631
2184
  // ../core/components/OutlineList/index.tsx
632
- var import_jsx_runtime6 = require("react/jsx-runtime");
2185
+ var import_jsx_runtime4 = require("react/jsx-runtime");
633
2186
  var getClassName4 = get_class_name_factory_default("OutlineList", styles_module_default4);
634
2187
  var getClassNameItem = get_class_name_factory_default("OutlineListItem", styles_module_default4);
635
2188
  var OutlineList = ({ children }) => {
636
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: getClassName4(), children });
2189
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: getClassName4(), children });
637
2190
  };
638
- OutlineList.Clickable = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: getClassNameItem({ clickable: true }), children });
2191
+ OutlineList.Clickable = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassNameItem({ clickable: true }), children });
639
2192
  OutlineList.Item = ({
640
2193
  children,
641
2194
  onClick
642
2195
  }) => {
643
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2196
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
644
2197
  "li",
645
2198
  {
646
2199
  className: getClassNameItem({ clickable: !!onClick }),
@@ -674,7 +2227,7 @@ var getFrame = () => {
674
2227
 
675
2228
  // src/HeadingAnalyzer.tsx
676
2229
  var import_react_from_json = __toESM(require("react-from-json"));
677
- var import_jsx_runtime7 = require("react/jsx-runtime");
2230
+ var import_jsx_runtime5 = require("react/jsx-runtime");
678
2231
  var getClassName5 = get_class_name_factory_default("HeadingAnalyzer", HeadingAnalyzer_module_default);
679
2232
  var getClassNameItem2 = get_class_name_factory_default("HeadingAnalyzerItem", HeadingAnalyzer_module_default);
680
2233
  var ReactFromJSON = import_react_from_json.default.default || import_react_from_json.default;
@@ -682,6 +2235,9 @@ var getOutline = ({ frame } = {}) => {
682
2235
  const headings = (frame == null ? void 0 : frame.querySelectorAll("h1,h2,h3,h4,h5,h6")) || [];
683
2236
  const _outline = [];
684
2237
  headings.forEach((item, i) => {
2238
+ if (item.closest("[data-dnd-dragging]")) {
2239
+ return;
2240
+ }
685
2241
  _outline.push({
686
2242
  rank: parseInt(item.tagName.split("H")[1]),
687
2243
  text: item.textContent,
@@ -724,24 +2280,47 @@ function buildHierarchy(frame) {
724
2280
  }
725
2281
  return root.children;
726
2282
  }
2283
+ var usePuck = (0, import_puck.createUsePuck)();
727
2284
  var HeadingAnalyzer = () => {
728
- const { appState } = (0, import_puck.usePuck)();
729
- const [hierarchy, setHierarchy] = (0, import_react9.useState)([]);
730
- (0, import_react9.useEffect)(() => {
2285
+ const data = usePuck((s) => s.appState.data);
2286
+ const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
2287
+ (0, import_react11.useEffect)(() => {
731
2288
  const frame = getFrame();
732
- const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
733
- if (!entry) return;
734
- setHierarchy(buildHierarchy(entry));
735
- const observer = new MutationObserver(() => {
2289
+ let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2290
+ const createHierarchy = () => {
736
2291
  setHierarchy(buildHierarchy(entry));
2292
+ };
2293
+ const entryObserver = new MutationObserver(() => {
2294
+ createHierarchy();
2295
+ });
2296
+ const frameObserver = new MutationObserver(() => {
2297
+ entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2298
+ if (entry) {
2299
+ registerEntryObserver();
2300
+ frameObserver.disconnect();
2301
+ }
737
2302
  });
738
- observer.observe(entry, { subtree: true, childList: true });
2303
+ const registerEntryObserver = () => {
2304
+ if (!entry) return;
2305
+ entryObserver.observe(entry, { subtree: true, childList: true });
2306
+ };
2307
+ const registerFrameObserver = () => {
2308
+ if (!frame) return;
2309
+ frameObserver.observe(frame, { subtree: true, childList: true });
2310
+ };
2311
+ if (entry) {
2312
+ createHierarchy();
2313
+ registerEntryObserver();
2314
+ } else {
2315
+ registerFrameObserver();
2316
+ }
739
2317
  return () => {
740
- observer.disconnect();
2318
+ entryObserver.disconnect();
2319
+ frameObserver.disconnect();
741
2320
  };
742
- }, [appState.data]);
743
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: getClassName5(), children: [
744
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2321
+ }, [data]);
2322
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [
2323
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
745
2324
  "small",
746
2325
  {
747
2326
  className: getClassName5("cssWarning"),
@@ -753,19 +2332,19 @@ var HeadingAnalyzer = () => {
753
2332
  children: [
754
2333
  "Heading analyzer styles not loaded. Please review the",
755
2334
  " ",
756
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { href: "https://github.com/measuredco/puck/blob/main/packages/plugin-heading-analyzer/README.md", children: "README" }),
2335
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { href: "https://github.com/measuredco/puck/blob/main/packages/plugin-heading-analyzer/README.md", children: "README" }),
757
2336
  "."
758
2337
  ]
759
2338
  }
760
2339
  ),
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)(
2340
+ hierarchy.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: "No headings." }),
2341
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OutlineList, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
763
2342
  ReactFromJSON,
764
2343
  {
765
2344
  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)(
2345
+ Root: (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: props.children }),
2346
+ OutlineListItem: (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(OutlineList.Item, { children: [
2347
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OutlineList.Clickable, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
769
2348
  "small",
770
2349
  {
771
2350
  className: getClassNameItem2({ missing: props.missing }),
@@ -783,14 +2362,14 @@ var HeadingAnalyzer = () => {
783
2362
  }, 2e3);
784
2363
  }
785
2364
  },
786
- children: props.missing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
787
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("b", { children: [
2365
+ children: props.missing ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
2366
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("b", { children: [
788
2367
  "H",
789
2368
  props.rank
790
2369
  ] }),
791
2370
  ": Missing"
792
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
793
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("b", { children: [
2371
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
2372
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("b", { children: [
794
2373
  "H",
795
2374
  props.rank
796
2375
  ] }),
@@ -799,7 +2378,7 @@ var HeadingAnalyzer = () => {
799
2378
  ] })
800
2379
  }
801
2380
  ) }),
802
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OutlineList, { children: props.children })
2381
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(OutlineList, { children: props.children })
803
2382
  ] })
804
2383
  },
805
2384
  entry: {
@@ -821,9 +2400,9 @@ var HeadingAnalyzer = () => {
821
2400
  };
822
2401
  var headingAnalyzer = {
823
2402
  overrides: {
824
- fields: ({ children, itemSelector }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2403
+ fields: ({ children, itemSelector }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
825
2404
  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, {}) }) })
2405
+ /* @__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
2406
  ] })
828
2407
  }
829
2408
  };