@measured/puck-plugin-heading-analyzer 0.19.0-canary.0ea6ce4 → 0.19.0-canary.15d05558

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