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