@measured/puck-plugin-heading-analyzer 0.20.0-canary.755737e8 → 0.20.0-canary.8909f8cc

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,12 +146,162 @@ 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, useState } 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();
@@ -140,12 +310,12 @@ var HeadingAnalyzer_module_default = { "HeadingAnalyzer": "_HeadingAnalyzer_116v
140
310
  // src/HeadingAnalyzer.tsx
141
311
  import { createUsePuck } from "@measured/puck";
142
312
 
143
- // ../core/components/OutlineList/index.tsx
313
+ // ../core/components/SidebarSection/index.tsx
144
314
  init_react_import();
145
315
 
146
- // css-module:/home/runner/work/puck/puck/packages/core/components/OutlineList/styles.module.css#css-module
316
+ // css-module:/home/runner/work/puck/puck/packages/core/components/SidebarSection/styles.module.css#css-module
147
317
  init_react_import();
148
- var styles_module_default = { "OutlineList": "_OutlineList_w4lzv_1", "OutlineListItem": "_OutlineListItem_w4lzv_25", "OutlineListItem--clickable": "_OutlineListItem--clickable_w4lzv_45" };
318
+ var styles_module_default = { "SidebarSection": "_SidebarSection_8boj8_1", "SidebarSection-title": "_SidebarSection-title_8boj8_12", "SidebarSection--noBorderTop": "_SidebarSection--noBorderTop_8boj8_20", "SidebarSection-content": "_SidebarSection-content_8boj8_24", "SidebarSection--noPadding": "_SidebarSection--noPadding_8boj8_28", "SidebarSection-breadcrumbLabel": "_SidebarSection-breadcrumbLabel_8boj8_41", "SidebarSection-breadcrumbs": "_SidebarSection-breadcrumbs_8boj8_70", "SidebarSection-breadcrumb": "_SidebarSection-breadcrumb_8boj8_41", "SidebarSection-heading": "_SidebarSection-heading_8boj8_82", "SidebarSection-loadingOverlay": "_SidebarSection-loadingOverlay_8boj8_86" };
149
319
 
150
320
  // ../core/lib/get-class-name-factory.ts
151
321
  init_react_import();
@@ -174,50 +344,29 @@ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (op
174
344
  };
175
345
  var get_class_name_factory_default = getClassNameFactory;
176
346
 
177
- // ../core/components/OutlineList/index.tsx
347
+ // ../core/components/Heading/index.tsx
348
+ init_react_import();
349
+
350
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Heading/styles.module.css#css-module
351
+ init_react_import();
352
+ var styles_module_default2 = { "Heading": "_Heading_qxrry_1", "Heading--xxxxl": "_Heading--xxxxl_qxrry_12", "Heading--xxxl": "_Heading--xxxl_qxrry_18", "Heading--xxl": "_Heading--xxl_qxrry_22", "Heading--xl": "_Heading--xl_qxrry_26", "Heading--l": "_Heading--l_qxrry_30", "Heading--m": "_Heading--m_qxrry_34", "Heading--s": "_Heading--s_qxrry_38", "Heading--xs": "_Heading--xs_qxrry_42" };
353
+
354
+ // ../core/components/Heading/index.tsx
178
355
  import { jsx } from "react/jsx-runtime";
179
- var getClassName = get_class_name_factory_default("OutlineList", styles_module_default);
180
- var getClassNameItem = get_class_name_factory_default("OutlineListItem", styles_module_default);
181
- var OutlineList = ({ children }) => {
182
- return /* @__PURE__ */ jsx("ul", { className: getClassName(), children });
183
- };
184
- OutlineList.Clickable = ({ children }) => /* @__PURE__ */ jsx("div", { className: getClassNameItem({ clickable: true }), children });
185
- OutlineList.Item = ({
186
- children,
187
- onClick
188
- }) => {
356
+ var getClassName = get_class_name_factory_default("Heading", styles_module_default2);
357
+ var Heading = ({ children, rank, size = "m" }) => {
358
+ const Tag = rank ? `h${rank}` : "span";
189
359
  return /* @__PURE__ */ jsx(
190
- "li",
360
+ Tag,
191
361
  {
192
- className: getClassNameItem({ clickable: !!onClick }),
193
- onClick,
362
+ className: getClassName({
363
+ [size]: true
364
+ }),
194
365
  children
195
366
  }
196
367
  );
197
368
  };
198
369
 
199
- // ../core/lib/scroll-into-view.ts
200
- init_react_import();
201
- var scrollIntoView = (el) => {
202
- const oldStyle = __spreadValues({}, el.style);
203
- el.style.scrollMargin = "256px";
204
- if (el) {
205
- el == null ? void 0 : el.scrollIntoView({ behavior: "smooth" });
206
- el.style.scrollMargin = oldStyle.scrollMargin || "";
207
- }
208
- };
209
-
210
- // ../core/lib/get-frame.ts
211
- init_react_import();
212
- var getFrame = () => {
213
- if (typeof window === "undefined") return;
214
- let frameEl = document.querySelector("#preview-frame");
215
- if ((frameEl == null ? void 0 : frameEl.tagName) === "IFRAME") {
216
- return frameEl.contentDocument || document;
217
- }
218
- return (frameEl == null ? void 0 : frameEl.ownerDocument) || document;
219
- };
220
-
221
370
  // ../../node_modules/lucide-react/dist/esm/lucide-react.js
222
371
  init_react_import();
223
372
 
@@ -305,15 +454,1682 @@ var createLucideIcon = (iconName, iconNode) => {
305
454
  return Component;
306
455
  };
307
456
 
308
- // ../../node_modules/lucide-react/dist/esm/icons/heading-1.js
457
+ // ../../node_modules/lucide-react/dist/esm/icons/chevron-right.js
309
458
  init_react_import();
310
- var Heading1 = createLucideIcon("Heading1", [
311
- ["path", { d: "M4 12h8", key: "17cfdx" }],
312
- ["path", { d: "M4 18V6", key: "1rz3zl" }],
313
- ["path", { d: "M12 18V6", key: "zqpxq5" }],
314
- ["path", { d: "m17 12 3-2v8", key: "1hhhft" }]
459
+ var ChevronRight = createLucideIcon("ChevronRight", [
460
+ ["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]
315
461
  ]);
316
462
 
463
+ // ../core/lib/use-breadcrumbs.ts
464
+ init_react_import();
465
+ import { useMemo } from "react";
466
+
467
+ // ../core/store/index.ts
468
+ init_react_import();
469
+
470
+ // ../core/reducer/index.ts
471
+ init_react_import();
472
+
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
483
+ init_react_import();
484
+
485
+ // ../core/lib/root-droppable-id.ts
486
+ init_react_import();
487
+ var rootAreaId = "root";
488
+ var rootZone = "default-zone";
489
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
490
+
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
513
+ init_react_import();
514
+
515
+ // ../core/lib/data/default-slots.ts
516
+ init_react_import();
517
+ var defaultSlots = (value, fields) => Object.keys(fields).reduce(
518
+ (acc, fieldName) => fields[fieldName].type === "slot" ? __spreadValues({ [fieldName]: [] }, acc) : acc,
519
+ value
520
+ );
521
+
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
656
+ init_react_import();
657
+ var import_flat = __toESM(require_flat());
658
+
659
+ // ../core/lib/data/strip-slots.ts
660
+ init_react_import();
661
+ var stripSlots = (data, config) => {
662
+ return mapSlots(data, () => null, config);
663
+ };
664
+
665
+ // ../core/lib/data/flatten-node.ts
666
+ var { flatten: flatten2, unflatten } = import_flat.default;
667
+ var flattenNode = (node, config) => {
668
+ return __spreadProps(__spreadValues({}, node), {
669
+ props: flatten2(stripSlots(node, config).props)
670
+ });
671
+ };
672
+
673
+ // ../core/lib/data/walk-app-state.ts
674
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
675
+ var _a;
676
+ let newZones = {};
677
+ const newZoneIndex = {};
678
+ const newNodeIndex = {};
679
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
680
+ var _a2;
681
+ const [parentId] = zoneCompound.split(":");
682
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
683
+ const [_2, zone] = zoneCompound.split(":");
684
+ const newZoneCompound = `${newId || parentId}:${zone}`;
685
+ const newContent2 = mappedContent.map(
686
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
687
+ );
688
+ newZoneIndex[newZoneCompound] = {
689
+ contentIds: newContent2.map((item) => item.props.id),
690
+ type: zoneType
691
+ };
692
+ return [newZoneCompound, newContent2];
693
+ };
694
+ const processRelatedZones = (item, newId, initialPath) => {
695
+ forRelatedZones(
696
+ item,
697
+ state.data,
698
+ (relatedPath, relatedZoneCompound, relatedContent) => {
699
+ const [zoneCompound, newContent2] = processContent(
700
+ relatedPath,
701
+ relatedZoneCompound,
702
+ relatedContent,
703
+ "dropzone",
704
+ newId
705
+ );
706
+ newZones[zoneCompound] = newContent2;
707
+ },
708
+ initialPath
709
+ );
710
+ };
711
+ const processItem = (item, path, index) => {
712
+ const mappedItem = mapNodeOrSkip(item, path, index);
713
+ if (!mappedItem) return item;
714
+ const id = mappedItem.props.id;
715
+ const newProps = __spreadProps(__spreadValues({}, mapSlots(
716
+ mappedItem,
717
+ (content, parentId2, slotId) => {
718
+ const zoneCompound = `${parentId2}:${slotId}`;
719
+ const [_2, newContent2] = processContent(
720
+ path,
721
+ zoneCompound,
722
+ content,
723
+ "slot",
724
+ parentId2
725
+ );
726
+ return newContent2;
727
+ },
728
+ config
729
+ ).props), {
730
+ id
731
+ });
732
+ processRelatedZones(item, id, path);
733
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
734
+ const thisZoneCompound = path[path.length - 1];
735
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
736
+ newNodeIndex[id] = {
737
+ data: newItem,
738
+ flatData: flattenNode(newItem, config),
739
+ path,
740
+ parentId,
741
+ zone
742
+ };
743
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
744
+ if (newProps.id === "root") {
745
+ delete finalData["type"];
746
+ delete finalData.props["id"];
747
+ }
748
+ return finalData;
749
+ };
750
+ const zones = state.data.zones || {};
751
+ const [_, newContent] = processContent(
752
+ [],
753
+ rootDroppableId,
754
+ state.data.content,
755
+ "root"
756
+ );
757
+ const processedContent = newContent;
758
+ const zonesAlreadyProcessed = Object.keys(newZones);
759
+ Object.keys(zones || {}).forEach((zoneCompound) => {
760
+ const [parentId] = zoneCompound.split(":");
761
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
762
+ return;
763
+ }
764
+ const [_2, newContent2] = processContent(
765
+ [rootDroppableId],
766
+ zoneCompound,
767
+ zones[zoneCompound],
768
+ "dropzone",
769
+ parentId
770
+ );
771
+ newZones[zoneCompound] = newContent2;
772
+ }, newZones);
773
+ const processedRoot = processItem(
774
+ {
775
+ type: "root",
776
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
777
+ },
778
+ [],
779
+ -1
780
+ );
781
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
782
+ props: processedRoot.props
783
+ });
784
+ return __spreadProps(__spreadValues({}, state), {
785
+ data: {
786
+ root,
787
+ content: processedContent,
788
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
789
+ },
790
+ indexes: {
791
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
792
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
793
+ }
794
+ });
795
+ }
796
+
797
+ // ../core/reducer/actions/set.ts
798
+ var setAction = (state, action, appStore) => {
799
+ if (typeof action.state === "object") {
800
+ const newState = __spreadValues(__spreadValues({}, state), action.state);
801
+ if (action.state.indexes) {
802
+ return newState;
803
+ }
804
+ console.warn(
805
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
806
+ );
807
+ return walkAppState(newState, appStore.config);
808
+ }
809
+ return __spreadValues(__spreadValues({}, state), action.state(state));
810
+ };
811
+
812
+ // ../core/reducer/actions/insert.ts
813
+ init_react_import();
814
+
815
+ // ../core/lib/data/insert.ts
816
+ init_react_import();
817
+ var insert = (list, index, item) => {
818
+ const result = Array.from(list || []);
819
+ result.splice(index, 0, item);
820
+ return result;
821
+ };
822
+
823
+ // ../core/lib/generate-id.ts
824
+ init_react_import();
825
+
826
+ // ../../node_modules/uuid/dist/esm-node/index.js
827
+ init_react_import();
828
+
829
+ // ../../node_modules/uuid/dist/esm-node/rng.js
830
+ init_react_import();
831
+ import crypto from "crypto";
832
+ var rnds8Pool = new Uint8Array(256);
833
+ var poolPtr = rnds8Pool.length;
834
+ function rng() {
835
+ if (poolPtr > rnds8Pool.length - 16) {
836
+ crypto.randomFillSync(rnds8Pool);
837
+ poolPtr = 0;
838
+ }
839
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
840
+ }
841
+
842
+ // ../../node_modules/uuid/dist/esm-node/stringify.js
843
+ init_react_import();
844
+ var byteToHex = [];
845
+ for (let i = 0; i < 256; ++i) {
846
+ byteToHex.push((i + 256).toString(16).slice(1));
847
+ }
848
+ function unsafeStringify(arr, offset = 0) {
849
+ 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]];
850
+ }
851
+
852
+ // ../../node_modules/uuid/dist/esm-node/v4.js
853
+ init_react_import();
854
+
855
+ // ../../node_modules/uuid/dist/esm-node/native.js
856
+ init_react_import();
857
+ import crypto2 from "crypto";
858
+ var native_default = {
859
+ randomUUID: crypto2.randomUUID
860
+ };
861
+
862
+ // ../../node_modules/uuid/dist/esm-node/v4.js
863
+ function v4(options, buf, offset) {
864
+ if (native_default.randomUUID && !buf && !options) {
865
+ return native_default.randomUUID();
866
+ }
867
+ options = options || {};
868
+ const rnds = options.random || (options.rng || rng)();
869
+ rnds[6] = rnds[6] & 15 | 64;
870
+ rnds[8] = rnds[8] & 63 | 128;
871
+ if (buf) {
872
+ offset = offset || 0;
873
+ for (let i = 0; i < 16; ++i) {
874
+ buf[offset + i] = rnds[i];
875
+ }
876
+ return buf;
877
+ }
878
+ return unsafeStringify(rnds);
879
+ }
880
+ var v4_default = v4;
881
+
882
+ // ../core/lib/generate-id.ts
883
+ var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
884
+
885
+ // ../core/lib/data/get-ids-for-parent.ts
886
+ init_react_import();
887
+ var getIdsForParent = (zoneCompound, state) => {
888
+ const [parentId] = zoneCompound.split(":");
889
+ const node = state.indexes.nodes[parentId];
890
+ return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
891
+ };
892
+
893
+ // ../core/lib/data/populate-ids.ts
894
+ init_react_import();
895
+
896
+ // ../core/lib/data/walk-tree.ts
897
+ init_react_import();
898
+ function walkTree(data, config, callbackFn) {
899
+ var _a, _b;
900
+ const walkItem = (item) => {
901
+ return mapSlots(
902
+ item,
903
+ (content, parentId, propName) => {
904
+ var _a2;
905
+ return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
906
+ },
907
+ config,
908
+ true
909
+ );
910
+ };
911
+ if ("props" in data) {
912
+ return walkItem(data);
913
+ }
914
+ const _data = data;
915
+ const zones = (_a = _data.zones) != null ? _a : {};
916
+ const mappedContent = _data.content.map(walkItem);
917
+ return {
918
+ root: walkItem(_data.root),
919
+ content: (_b = callbackFn(mappedContent, {
920
+ parentId: "root",
921
+ propName: "default-zone"
922
+ })) != null ? _b : mappedContent,
923
+ zones: Object.keys(zones).reduce(
924
+ (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
925
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
926
+ }),
927
+ {}
928
+ )
929
+ };
930
+ }
931
+
932
+ // ../core/lib/data/populate-ids.ts
933
+ var populateIds = (data, config, override = false) => {
934
+ const id = generateId(data.type);
935
+ return walkTree(
936
+ __spreadProps(__spreadValues({}, data), {
937
+ props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({}, data.props)
938
+ }),
939
+ config,
940
+ (contents) => contents.map((item) => {
941
+ const id2 = generateId(item.type);
942
+ return __spreadProps(__spreadValues({}, item), {
943
+ props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
944
+ });
945
+ })
946
+ );
947
+ };
948
+
949
+ // ../core/reducer/actions/insert.ts
950
+ function insertAction(state, action, appStore) {
951
+ const id = action.id || generateId(action.componentType);
952
+ const emptyComponentData = populateIds(
953
+ {
954
+ type: action.componentType,
955
+ props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
956
+ id
957
+ })
958
+ },
959
+ appStore.config
960
+ );
961
+ const [parentId] = action.destinationZone.split(":");
962
+ const idsInPath = getIdsForParent(action.destinationZone, state);
963
+ return walkAppState(
964
+ state,
965
+ appStore.config,
966
+ (content, zoneCompound) => {
967
+ if (zoneCompound === action.destinationZone) {
968
+ return insert(
969
+ content || [],
970
+ action.destinationIndex,
971
+ emptyComponentData
972
+ );
973
+ }
974
+ return content;
975
+ },
976
+ (childItem, path) => {
977
+ if (childItem.props.id === id || childItem.props.id === parentId) {
978
+ return childItem;
979
+ } else if (idsInPath.includes(childItem.props.id)) {
980
+ return childItem;
981
+ } else if (path.includes(action.destinationZone)) {
982
+ return childItem;
983
+ }
984
+ return null;
985
+ }
986
+ );
987
+ }
988
+
989
+ // ../core/reducer/actions/replace.ts
990
+ init_react_import();
991
+ var replaceAction = (state, action, appStore) => {
992
+ const [parentId] = action.destinationZone.split(":");
993
+ const idsInPath = getIdsForParent(action.destinationZone, state);
994
+ const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
995
+ const idChanged = originalId !== action.data.props.id;
996
+ if (idChanged) {
997
+ throw new Error(
998
+ `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
999
+ );
1000
+ }
1001
+ const newSlotIds = [];
1002
+ const data = walkTree(action.data, appStore.config, (contents, opts) => {
1003
+ newSlotIds.push(`${opts.parentId}:${opts.propName}`);
1004
+ return contents.map((item) => {
1005
+ const id = generateId(item.type);
1006
+ return __spreadProps(__spreadValues({}, item), {
1007
+ props: __spreadValues({ id }, item.props)
1008
+ });
1009
+ });
1010
+ });
1011
+ const stateWithDeepSlotsRemoved = __spreadValues({}, state);
1012
+ Object.keys(state.indexes.zones).forEach((zoneCompound) => {
1013
+ const id = zoneCompound.split(":")[0];
1014
+ if (id === originalId) {
1015
+ if (!newSlotIds.includes(zoneCompound)) {
1016
+ delete stateWithDeepSlotsRemoved.indexes.zones[zoneCompound];
1017
+ }
1018
+ }
1019
+ });
1020
+ return walkAppState(
1021
+ stateWithDeepSlotsRemoved,
1022
+ appStore.config,
1023
+ (content, zoneCompound) => {
1024
+ const newContent = [...content];
1025
+ if (zoneCompound === action.destinationZone) {
1026
+ newContent[action.destinationIndex] = data;
1027
+ }
1028
+ return newContent;
1029
+ },
1030
+ (childItem, path) => {
1031
+ const pathIds = path.map((p) => p.split(":")[0]);
1032
+ if (childItem.props.id === data.props.id) {
1033
+ return data;
1034
+ } else if (childItem.props.id === parentId) {
1035
+ return childItem;
1036
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
1037
+ return childItem;
1038
+ } else if (pathIds.indexOf(data.props.id) > -1) {
1039
+ return childItem;
1040
+ }
1041
+ return null;
1042
+ }
1043
+ );
1044
+ };
1045
+
1046
+ // ../core/reducer/actions/replace-root.ts
1047
+ init_react_import();
1048
+ var replaceRootAction = (state, action, appStore) => {
1049
+ return walkAppState(
1050
+ state,
1051
+ appStore.config,
1052
+ (content) => content,
1053
+ (childItem) => {
1054
+ if (childItem.props.id === "root") {
1055
+ return __spreadProps(__spreadValues({}, childItem), {
1056
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
1057
+ readOnly: action.root.readOnly
1058
+ });
1059
+ }
1060
+ return childItem;
1061
+ }
1062
+ );
1063
+ };
1064
+
1065
+ // ../core/reducer/actions/duplicate.ts
1066
+ init_react_import();
1067
+
1068
+ // ../core/lib/data/get-item.ts
1069
+ init_react_import();
1070
+ function getItem(selector, state) {
1071
+ var _a, _b;
1072
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
1073
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
1074
+ }
1075
+
1076
+ // ../core/reducer/actions/duplicate.ts
1077
+ function duplicateAction(state, action, appStore) {
1078
+ const item = getItem(
1079
+ { index: action.sourceIndex, zone: action.sourceZone },
1080
+ state
1081
+ );
1082
+ const idsInPath = getIdsForParent(action.sourceZone, state);
1083
+ const newItem = __spreadProps(__spreadValues({}, item), {
1084
+ props: __spreadProps(__spreadValues({}, item.props), {
1085
+ id: generateId(item.type)
1086
+ })
1087
+ });
1088
+ const modified = walkAppState(
1089
+ state,
1090
+ appStore.config,
1091
+ (content, zoneCompound) => {
1092
+ if (zoneCompound === action.sourceZone) {
1093
+ return insert(content, action.sourceIndex + 1, item);
1094
+ }
1095
+ return content;
1096
+ },
1097
+ (childItem, path, index) => {
1098
+ const zoneCompound = path[path.length - 1];
1099
+ const parents = path.map((p) => p.split(":")[0]);
1100
+ if (parents.indexOf(newItem.props.id) > -1) {
1101
+ return __spreadProps(__spreadValues({}, childItem), {
1102
+ props: __spreadProps(__spreadValues({}, childItem.props), {
1103
+ id: generateId(childItem.type)
1104
+ })
1105
+ });
1106
+ }
1107
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
1108
+ return newItem;
1109
+ }
1110
+ const [sourceZoneParent] = action.sourceZone.split(":");
1111
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
1112
+ return childItem;
1113
+ }
1114
+ return null;
1115
+ }
1116
+ );
1117
+ return __spreadProps(__spreadValues({}, modified), {
1118
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
1119
+ itemSelector: {
1120
+ index: action.sourceIndex + 1,
1121
+ zone: action.sourceZone
1122
+ }
1123
+ })
1124
+ });
1125
+ }
1126
+
1127
+ // ../core/reducer/actions/reorder.ts
1128
+ init_react_import();
1129
+
1130
+ // ../core/reducer/actions/move.ts
1131
+ init_react_import();
1132
+
1133
+ // ../core/lib/data/remove.ts
1134
+ init_react_import();
1135
+ var remove = (list, index) => {
1136
+ const result = Array.from(list);
1137
+ result.splice(index, 1);
1138
+ return result;
1139
+ };
1140
+
1141
+ // ../core/reducer/actions/move.ts
1142
+ var moveAction = (state, action, appStore) => {
1143
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
1144
+ return state;
1145
+ }
1146
+ const item = getItem(
1147
+ { zone: action.sourceZone, index: action.sourceIndex },
1148
+ state
1149
+ );
1150
+ if (!item) return state;
1151
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
1152
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
1153
+ return walkAppState(
1154
+ state,
1155
+ appStore.config,
1156
+ (content, zoneCompound) => {
1157
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
1158
+ return insert(
1159
+ remove(content, action.sourceIndex),
1160
+ action.destinationIndex,
1161
+ item
1162
+ );
1163
+ } else if (zoneCompound === action.sourceZone) {
1164
+ return remove(content, action.sourceIndex);
1165
+ } else if (zoneCompound === action.destinationZone) {
1166
+ return insert(content, action.destinationIndex, item);
1167
+ }
1168
+ return content;
1169
+ },
1170
+ (childItem, path) => {
1171
+ const [sourceZoneParent] = action.sourceZone.split(":");
1172
+ const [destinationZoneParent] = action.destinationZone.split(":");
1173
+ const childId = childItem.props.id;
1174
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
1175
+ return childItem;
1176
+ }
1177
+ return null;
1178
+ }
1179
+ );
1180
+ };
1181
+
1182
+ // ../core/reducer/actions/reorder.ts
1183
+ var reorderAction = (state, action, appStore) => {
1184
+ return moveAction(
1185
+ state,
1186
+ {
1187
+ type: "move",
1188
+ sourceIndex: action.sourceIndex,
1189
+ sourceZone: action.destinationZone,
1190
+ destinationIndex: action.destinationIndex,
1191
+ destinationZone: action.destinationZone
1192
+ },
1193
+ appStore
1194
+ );
1195
+ };
1196
+
1197
+ // ../core/reducer/actions/remove.ts
1198
+ init_react_import();
1199
+ var removeAction = (state, action, appStore) => {
1200
+ const item = getItem({ index: action.index, zone: action.zone }, state);
1201
+ const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
1202
+ (acc, [nodeId, nodeData]) => {
1203
+ const pathIds = nodeData.path.map((p) => p.split(":")[0]);
1204
+ if (pathIds.includes(item.props.id)) {
1205
+ return [...acc, nodeId];
1206
+ }
1207
+ return acc;
1208
+ },
1209
+ [item.props.id]
1210
+ );
1211
+ const newState = walkAppState(
1212
+ state,
1213
+ appStore.config,
1214
+ (content, zoneCompound) => {
1215
+ if (zoneCompound === action.zone) {
1216
+ return remove(content, action.index);
1217
+ }
1218
+ return content;
1219
+ }
1220
+ );
1221
+ Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
1222
+ const parentId = zoneCompound.split(":")[0];
1223
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
1224
+ delete newState.data.zones[zoneCompound];
1225
+ }
1226
+ });
1227
+ Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
1228
+ const parentId = zoneCompound.split(":")[0];
1229
+ if (nodesToDelete.includes(parentId)) {
1230
+ delete newState.indexes.zones[zoneCompound];
1231
+ }
1232
+ });
1233
+ nodesToDelete.forEach((id) => {
1234
+ delete newState.indexes.nodes[id];
1235
+ });
1236
+ return newState;
1237
+ };
1238
+
1239
+ // ../core/reducer/actions/register-zone.ts
1240
+ init_react_import();
1241
+
1242
+ // ../core/lib/data/setup-zone.ts
1243
+ init_react_import();
1244
+ var setupZone = (data, zoneKey) => {
1245
+ if (zoneKey === rootDroppableId) {
1246
+ return data;
1247
+ }
1248
+ const newData = __spreadProps(__spreadValues({}, data), {
1249
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
1250
+ });
1251
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
1252
+ return newData;
1253
+ };
1254
+
1255
+ // ../core/reducer/actions/register-zone.ts
1256
+ var zoneCache = {};
1257
+ function registerZoneAction(state, action) {
1258
+ if (zoneCache[action.zone]) {
1259
+ return __spreadProps(__spreadValues({}, state), {
1260
+ data: __spreadProps(__spreadValues({}, state.data), {
1261
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
1262
+ [action.zone]: zoneCache[action.zone]
1263
+ })
1264
+ }),
1265
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1266
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
1267
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
1268
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
1269
+ type: "dropzone"
1270
+ })
1271
+ })
1272
+ })
1273
+ });
1274
+ }
1275
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1276
+ }
1277
+ function unregisterZoneAction(state, action) {
1278
+ const _zones = __spreadValues({}, state.data.zones || {});
1279
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
1280
+ if (_zones[action.zone]) {
1281
+ zoneCache[action.zone] = _zones[action.zone];
1282
+ delete _zones[action.zone];
1283
+ }
1284
+ delete zoneIndex[action.zone];
1285
+ return __spreadProps(__spreadValues({}, state), {
1286
+ data: __spreadProps(__spreadValues({}, state.data), {
1287
+ zones: _zones
1288
+ }),
1289
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1290
+ zones: zoneIndex
1291
+ })
1292
+ });
1293
+ }
1294
+
1295
+ // ../core/reducer/actions/set-data.ts
1296
+ init_react_import();
1297
+ var setDataAction = (state, action, appStore) => {
1298
+ if (typeof action.data === "object") {
1299
+ console.warn(
1300
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1301
+ );
1302
+ return walkAppState(
1303
+ __spreadProps(__spreadValues({}, state), {
1304
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
1305
+ }),
1306
+ appStore.config
1307
+ );
1308
+ }
1309
+ return walkAppState(
1310
+ __spreadProps(__spreadValues({}, state), {
1311
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1312
+ }),
1313
+ appStore.config
1314
+ );
1315
+ };
1316
+
1317
+ // ../core/reducer/actions/set-ui.ts
1318
+ init_react_import();
1319
+ var setUiAction = (state, action) => {
1320
+ if (typeof action.ui === "object") {
1321
+ return __spreadProps(__spreadValues({}, state), {
1322
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1323
+ });
1324
+ }
1325
+ return __spreadProps(__spreadValues({}, state), {
1326
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1327
+ });
1328
+ };
1329
+
1330
+ // ../core/lib/data/make-state-public.ts
1331
+ init_react_import();
1332
+ var makeStatePublic = (state) => {
1333
+ const { data, ui } = state;
1334
+ return { data, ui };
1335
+ };
1336
+
1337
+ // ../core/reducer/actions.tsx
1338
+ init_react_import();
1339
+
1340
+ // ../core/reducer/index.ts
1341
+ function storeInterceptor(reducer, record, onAction) {
1342
+ return (state, action) => {
1343
+ const newAppState = reducer(state, action);
1344
+ const isValidType = ![
1345
+ "registerZone",
1346
+ "unregisterZone",
1347
+ "setData",
1348
+ "setUi",
1349
+ "set"
1350
+ ].includes(action.type);
1351
+ if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1352
+ if (record) record(newAppState);
1353
+ }
1354
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1355
+ return newAppState;
1356
+ };
1357
+ }
1358
+ function createReducer({
1359
+ record,
1360
+ onAction,
1361
+ appStore
1362
+ }) {
1363
+ return storeInterceptor(
1364
+ (state, action) => {
1365
+ if (action.type === "set") {
1366
+ return setAction(state, action, appStore);
1367
+ }
1368
+ if (action.type === "insert") {
1369
+ return insertAction(state, action, appStore);
1370
+ }
1371
+ if (action.type === "replace") {
1372
+ return replaceAction(state, action, appStore);
1373
+ }
1374
+ if (action.type === "replaceRoot") {
1375
+ return replaceRootAction(state, action, appStore);
1376
+ }
1377
+ if (action.type === "duplicate") {
1378
+ return duplicateAction(state, action, appStore);
1379
+ }
1380
+ if (action.type === "reorder") {
1381
+ return reorderAction(state, action, appStore);
1382
+ }
1383
+ if (action.type === "move") {
1384
+ return moveAction(state, action, appStore);
1385
+ }
1386
+ if (action.type === "remove") {
1387
+ return removeAction(state, action, appStore);
1388
+ }
1389
+ if (action.type === "registerZone") {
1390
+ return registerZoneAction(state, action);
1391
+ }
1392
+ if (action.type === "unregisterZone") {
1393
+ return unregisterZoneAction(state, action);
1394
+ }
1395
+ if (action.type === "setData") {
1396
+ return setDataAction(state, action, appStore);
1397
+ }
1398
+ if (action.type === "setUi") {
1399
+ return setUiAction(state, action);
1400
+ }
1401
+ return state;
1402
+ },
1403
+ record,
1404
+ onAction
1405
+ );
1406
+ }
1407
+
1408
+ // ../core/components/ViewportControls/default-viewports.ts
1409
+ init_react_import();
1410
+ var defaultViewports = [
1411
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1412
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1413
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1414
+ ];
1415
+
1416
+ // ../../node_modules/zustand/esm/vanilla.mjs
1417
+ init_react_import();
1418
+ var createStoreImpl = (createState) => {
1419
+ let state;
1420
+ const listeners = /* @__PURE__ */ new Set();
1421
+ const setState = (partial, replace) => {
1422
+ const nextState = typeof partial === "function" ? partial(state) : partial;
1423
+ if (!Object.is(nextState, state)) {
1424
+ const previousState = state;
1425
+ state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
1426
+ listeners.forEach((listener) => listener(state, previousState));
1427
+ }
1428
+ };
1429
+ const getState = () => state;
1430
+ const getInitialState = () => initialState;
1431
+ const subscribe = (listener) => {
1432
+ listeners.add(listener);
1433
+ return () => listeners.delete(listener);
1434
+ };
1435
+ const api = { setState, getState, getInitialState, subscribe };
1436
+ const initialState = state = createState(setState, getState, api);
1437
+ return api;
1438
+ };
1439
+ var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
1440
+
1441
+ // ../../node_modules/zustand/esm/react.mjs
1442
+ init_react_import();
1443
+ import React2 from "react";
1444
+ var identity = (arg) => arg;
1445
+ function useStore(api, selector = identity) {
1446
+ const slice = React2.useSyncExternalStore(
1447
+ api.subscribe,
1448
+ () => selector(api.getState()),
1449
+ () => selector(api.getInitialState())
1450
+ );
1451
+ React2.useDebugValue(slice);
1452
+ return slice;
1453
+ }
1454
+ var createImpl = (createState) => {
1455
+ const api = createStore(createState);
1456
+ const useBoundStore = (selector) => useStore(api, selector);
1457
+ Object.assign(useBoundStore, api);
1458
+ return useBoundStore;
1459
+ };
1460
+ var create = (createState) => createState ? createImpl(createState) : createImpl;
1461
+
1462
+ // ../../node_modules/zustand/esm/middleware.mjs
1463
+ init_react_import();
1464
+ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1465
+ const origSubscribe = api.subscribe;
1466
+ api.subscribe = (selector, optListener, options) => {
1467
+ let listener = selector;
1468
+ if (optListener) {
1469
+ const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
1470
+ let currentSlice = selector(api.getState());
1471
+ listener = (state) => {
1472
+ const nextSlice = selector(state);
1473
+ if (!equalityFn(currentSlice, nextSlice)) {
1474
+ const previousSlice = currentSlice;
1475
+ optListener(currentSlice = nextSlice, previousSlice);
1476
+ }
1477
+ };
1478
+ if (options == null ? void 0 : options.fireImmediately) {
1479
+ optListener(currentSlice, currentSlice);
1480
+ }
1481
+ }
1482
+ return origSubscribe(listener);
1483
+ };
1484
+ const initialState = fn(set, get, api);
1485
+ return initialState;
1486
+ };
1487
+ var subscribeWithSelector = subscribeWithSelectorImpl;
1488
+
1489
+ // ../core/store/index.ts
1490
+ import { createContext, useContext } from "react";
1491
+
1492
+ // ../core/store/slices/history.ts
1493
+ init_react_import();
1494
+ import { useEffect as useEffect2 } from "react";
1495
+
1496
+ // ../core/lib/use-hotkey.ts
1497
+ init_react_import();
1498
+ import { useEffect } from "react";
1499
+ var useHotkeyStore = create()(
1500
+ subscribeWithSelector((set) => ({
1501
+ held: {},
1502
+ hold: (key) => set((s) => s.held[key] ? s : { held: __spreadProps(__spreadValues({}, s.held), { [key]: true }) }),
1503
+ release: (key) => set((s) => s.held[key] ? { held: __spreadProps(__spreadValues({}, s.held), { [key]: false }) } : s),
1504
+ reset: (held = {}) => set(() => ({ held })),
1505
+ triggers: {}
1506
+ }))
1507
+ );
1508
+
1509
+ // ../core/store/slices/history.ts
1510
+ var EMPTY_HISTORY_INDEX = 0;
1511
+ function debounce(func, timeout = 300) {
1512
+ let timer;
1513
+ return (...args) => {
1514
+ clearTimeout(timer);
1515
+ timer = setTimeout(() => {
1516
+ func(...args);
1517
+ }, timeout);
1518
+ };
1519
+ }
1520
+ var tidyState = (state) => {
1521
+ return __spreadProps(__spreadValues({}, state), {
1522
+ ui: __spreadProps(__spreadValues({}, state.ui), {
1523
+ field: {
1524
+ focus: null
1525
+ }
1526
+ })
1527
+ });
1528
+ };
1529
+ var createHistorySlice = (set, get) => {
1530
+ const record = debounce((state) => {
1531
+ const { histories, index } = get().history;
1532
+ const history = {
1533
+ state,
1534
+ id: generateId("history")
1535
+ };
1536
+ const newHistories = [...histories.slice(0, index + 1), history];
1537
+ set({
1538
+ history: __spreadProps(__spreadValues({}, get().history), {
1539
+ histories: newHistories,
1540
+ index: newHistories.length - 1
1541
+ })
1542
+ });
1543
+ }, 250);
1544
+ return {
1545
+ initialAppState: {},
1546
+ index: EMPTY_HISTORY_INDEX,
1547
+ histories: [],
1548
+ hasPast: () => get().history.index > EMPTY_HISTORY_INDEX,
1549
+ hasFuture: () => get().history.index < get().history.histories.length - 1,
1550
+ prevHistory: () => {
1551
+ const { history } = get();
1552
+ return history.hasPast() ? history.histories[history.index - 1] : null;
1553
+ },
1554
+ nextHistory: () => {
1555
+ const s = get().history;
1556
+ return s.hasFuture() ? s.histories[s.index + 1] : null;
1557
+ },
1558
+ currentHistory: () => get().history.histories[get().history.index],
1559
+ back: () => {
1560
+ var _a;
1561
+ const { history, dispatch } = get();
1562
+ if (history.hasPast()) {
1563
+ const state = tidyState(
1564
+ ((_a = history.prevHistory()) == null ? void 0 : _a.state) || history.initialAppState
1565
+ );
1566
+ dispatch({
1567
+ type: "set",
1568
+ state
1569
+ });
1570
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index - 1 }) });
1571
+ }
1572
+ },
1573
+ forward: () => {
1574
+ var _a;
1575
+ const { history, dispatch } = get();
1576
+ if (history.hasFuture()) {
1577
+ const state = (_a = history.nextHistory()) == null ? void 0 : _a.state;
1578
+ dispatch({ type: "set", state: state ? tidyState(state) : {} });
1579
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index + 1 }) });
1580
+ }
1581
+ },
1582
+ setHistories: (histories) => {
1583
+ var _a;
1584
+ const { dispatch, history } = get();
1585
+ dispatch({
1586
+ type: "set",
1587
+ state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
1588
+ });
1589
+ set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
1590
+ },
1591
+ setHistoryIndex: (index) => {
1592
+ var _a;
1593
+ const { dispatch, history } = get();
1594
+ dispatch({
1595
+ type: "set",
1596
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1597
+ });
1598
+ set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1599
+ },
1600
+ record
1601
+ };
1602
+ };
1603
+
1604
+ // ../core/store/slices/nodes.ts
1605
+ init_react_import();
1606
+ var createNodesSlice = (set, get) => ({
1607
+ nodes: {},
1608
+ registerNode: (id, node) => {
1609
+ const s = get().nodes;
1610
+ const emptyNode = {
1611
+ id,
1612
+ methods: {
1613
+ sync: () => null,
1614
+ hideOverlay: () => null,
1615
+ showOverlay: () => null
1616
+ },
1617
+ element: null
1618
+ };
1619
+ const existingNode = s.nodes[id];
1620
+ set({
1621
+ nodes: __spreadProps(__spreadValues({}, s), {
1622
+ nodes: __spreadProps(__spreadValues({}, s.nodes), {
1623
+ [id]: __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, emptyNode), existingNode), node), {
1624
+ id
1625
+ })
1626
+ })
1627
+ })
1628
+ });
1629
+ },
1630
+ unregisterNode: (id) => {
1631
+ const s = get().nodes;
1632
+ const existingNode = s.nodes[id];
1633
+ if (existingNode) {
1634
+ const newNodes = __spreadValues({}, s.nodes);
1635
+ delete newNodes[id];
1636
+ set({
1637
+ nodes: __spreadProps(__spreadValues({}, s), {
1638
+ nodes: newNodes
1639
+ })
1640
+ });
1641
+ }
1642
+ }
1643
+ });
1644
+
1645
+ // ../core/store/slices/permissions.ts
1646
+ init_react_import();
1647
+ import { useEffect as useEffect3 } from "react";
1648
+
1649
+ // ../core/lib/data/flatten-data.ts
1650
+ init_react_import();
1651
+ var flattenData = (state, config) => {
1652
+ const data = [];
1653
+ walkAppState(
1654
+ state,
1655
+ config,
1656
+ (content) => content,
1657
+ (item) => {
1658
+ data.push(item);
1659
+ return null;
1660
+ }
1661
+ );
1662
+ return data;
1663
+ };
1664
+
1665
+ // ../core/lib/get-changed.ts
1666
+ init_react_import();
1667
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1668
+ var getChanged = (newItem, oldItem) => {
1669
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1670
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1671
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1672
+ return __spreadProps(__spreadValues({}, acc), {
1673
+ [item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
1674
+ });
1675
+ }, {}) : {};
1676
+ };
1677
+
1678
+ // ../core/store/slices/permissions.ts
1679
+ var createPermissionsSlice = (set, get) => {
1680
+ const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1681
+ const { state, permissions, config } = get();
1682
+ const { cache: cache2, globalPermissions } = permissions;
1683
+ const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1684
+ var _a, _b, _c;
1685
+ const { config: config2, state: appState, setComponentLoading } = get();
1686
+ const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1687
+ if (!componentConfig) {
1688
+ return;
1689
+ }
1690
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1691
+ if (componentConfig.resolvePermissions) {
1692
+ const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1693
+ if (Object.values(changed).some((el) => el === true) || force2) {
1694
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1695
+ const resolvedPermissions = yield componentConfig.resolvePermissions(
1696
+ item2,
1697
+ {
1698
+ changed,
1699
+ lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1700
+ permissions: initialPermissions,
1701
+ appState: makeStatePublic(appState),
1702
+ lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1703
+ }
1704
+ );
1705
+ const latest = get().permissions;
1706
+ set({
1707
+ permissions: __spreadProps(__spreadValues({}, latest), {
1708
+ cache: __spreadProps(__spreadValues({}, latest.cache), {
1709
+ [item2.props.id]: {
1710
+ lastData: item2,
1711
+ lastPermissions: resolvedPermissions
1712
+ }
1713
+ }),
1714
+ resolvedPermissions: __spreadProps(__spreadValues({}, latest.resolvedPermissions), {
1715
+ [item2.props.id]: resolvedPermissions
1716
+ })
1717
+ })
1718
+ });
1719
+ clearTimeout2();
1720
+ }
1721
+ }
1722
+ });
1723
+ const resolveDataForRoot = (force2 = false) => {
1724
+ const { state: appState } = get();
1725
+ resolveDataForItem(
1726
+ // Shim the root data in by conforming to component data shape
1727
+ {
1728
+ type: "root",
1729
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1730
+ },
1731
+ force2
1732
+ );
1733
+ };
1734
+ const { item, type, root } = params;
1735
+ if (item) {
1736
+ yield resolveDataForItem(item, force);
1737
+ } else if (type) {
1738
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1739
+ yield resolveDataForItem(item2, force);
1740
+ }));
1741
+ } else if (root) {
1742
+ resolveDataForRoot(force);
1743
+ } else {
1744
+ flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1745
+ yield resolveDataForItem(item2, force);
1746
+ }));
1747
+ }
1748
+ });
1749
+ const refreshPermissions = (params) => resolvePermissions(params, true);
1750
+ return {
1751
+ cache: {},
1752
+ globalPermissions: {
1753
+ drag: true,
1754
+ edit: true,
1755
+ delete: true,
1756
+ duplicate: true,
1757
+ insert: true
1758
+ },
1759
+ resolvedPermissions: {},
1760
+ getPermissions: ({ item, type, root } = {}) => {
1761
+ const { config, permissions } = get();
1762
+ const { globalPermissions, resolvedPermissions } = permissions;
1763
+ if (item) {
1764
+ const componentConfig = config.components[item.type];
1765
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1766
+ const resolvedForItem = resolvedPermissions[item.props.id];
1767
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1768
+ } else if (type) {
1769
+ const componentConfig = config.components[type];
1770
+ return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1771
+ } else if (root) {
1772
+ const rootConfig = config.root;
1773
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1774
+ const resolvedForItem = resolvedPermissions["root"];
1775
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1776
+ }
1777
+ return globalPermissions;
1778
+ },
1779
+ resolvePermissions,
1780
+ refreshPermissions
1781
+ };
1782
+ };
1783
+
1784
+ // ../core/store/slices/fields.ts
1785
+ init_react_import();
1786
+ import { useCallback, useEffect as useEffect4 } from "react";
1787
+ var createFieldsSlice = (_set, _get) => {
1788
+ return {
1789
+ fields: {},
1790
+ loading: false,
1791
+ lastResolvedData: {},
1792
+ id: void 0
1793
+ };
1794
+ };
1795
+
1796
+ // ../core/lib/resolve-component-data.ts
1797
+ init_react_import();
1798
+ var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
1799
+ var cache = { lastChange: {} };
1800
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
1801
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
1802
+ const resolvedItem = __spreadValues({}, item);
1803
+ const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
1804
+ const id = "id" in item.props ? item.props.id : "root";
1805
+ if (shouldRunResolver) {
1806
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1807
+ if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
1808
+ return { node: resolved, didChange: false };
1809
+ }
1810
+ const changed = getChanged(item, oldItem);
1811
+ if (onResolveStart) {
1812
+ onResolveStart(item);
1813
+ }
1814
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1815
+ changed,
1816
+ lastData: oldItem,
1817
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1818
+ trigger
1819
+ });
1820
+ resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
1821
+ if (Object.keys(readOnly).length) {
1822
+ resolvedItem.readOnly = readOnly;
1823
+ }
1824
+ }
1825
+ let itemWithResolvedChildren = yield mapSlots(
1826
+ resolvedItem,
1827
+ (content) => __async(void 0, null, function* () {
1828
+ return yield Promise.all(
1829
+ content.map(
1830
+ (childItem) => __async(void 0, null, function* () {
1831
+ return (yield resolveComponentData(
1832
+ childItem,
1833
+ config,
1834
+ metadata,
1835
+ onResolveStart,
1836
+ onResolveEnd,
1837
+ trigger
1838
+ )).node;
1839
+ })
1840
+ )
1841
+ );
1842
+ }),
1843
+ config
1844
+ );
1845
+ if (shouldRunResolver && onResolveEnd) {
1846
+ onResolveEnd(resolvedItem);
1847
+ }
1848
+ cache.lastChange[id] = {
1849
+ item,
1850
+ resolved: itemWithResolvedChildren
1851
+ };
1852
+ return {
1853
+ node: itemWithResolvedChildren,
1854
+ didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
1855
+ };
1856
+ });
1857
+
1858
+ // ../core/lib/data/to-root.ts
1859
+ init_react_import();
1860
+ var toRoot = (item) => {
1861
+ if ("type" in item && item.type !== "root") {
1862
+ throw new Error("Converting non-root item to root.");
1863
+ }
1864
+ const { readOnly } = item;
1865
+ if (item.props) {
1866
+ if ("id" in item.props) {
1867
+ const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
1868
+ return { props, readOnly };
1869
+ }
1870
+ return { props: item.props, readOnly };
1871
+ }
1872
+ return { props: {}, readOnly };
1873
+ };
1874
+
1875
+ // ../core/store/default-app-state.ts
1876
+ init_react_import();
1877
+ var defaultAppState = {
1878
+ data: { content: [], root: {}, zones: {} },
1879
+ ui: {
1880
+ leftSideBarVisible: true,
1881
+ rightSideBarVisible: true,
1882
+ arrayState: {},
1883
+ itemSelector: null,
1884
+ componentList: {},
1885
+ isDragging: false,
1886
+ previewMode: "edit",
1887
+ viewports: {
1888
+ current: {
1889
+ width: defaultViewports[0].width,
1890
+ height: defaultViewports[0].height || "auto"
1891
+ },
1892
+ options: [],
1893
+ controlsVisible: true
1894
+ },
1895
+ field: { focus: null }
1896
+ },
1897
+ indexes: {
1898
+ nodes: {},
1899
+ zones: {}
1900
+ }
1901
+ };
1902
+
1903
+ // ../core/store/index.ts
1904
+ var defaultPageFields = {
1905
+ title: { type: "text" }
1906
+ };
1907
+ var createAppStore = (initialAppStore) => create()(
1908
+ subscribeWithSelector((set, get) => {
1909
+ var _a, _b;
1910
+ return __spreadProps(__spreadValues({
1911
+ state: defaultAppState,
1912
+ config: { components: {} },
1913
+ componentState: {},
1914
+ plugins: [],
1915
+ overrides: {},
1916
+ viewports: defaultViewports,
1917
+ zoomConfig: {
1918
+ autoZoom: 1,
1919
+ rootHeight: 0,
1920
+ zoom: 1
1921
+ },
1922
+ status: "LOADING",
1923
+ iframe: {},
1924
+ metadata: {}
1925
+ }, initialAppStore), {
1926
+ fields: createFieldsSlice(set, get),
1927
+ history: createHistorySlice(set, get),
1928
+ nodes: createNodesSlice(set, get),
1929
+ permissions: createPermissionsSlice(set, get),
1930
+ getComponentConfig: (type) => {
1931
+ var _a2;
1932
+ const { config, selectedItem } = get();
1933
+ const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
1934
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1935
+ },
1936
+ selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
1937
+ (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
1938
+ initialAppStore.state
1939
+ ) : null,
1940
+ dispatch: (action) => set((s) => {
1941
+ var _a2, _b2;
1942
+ const { record } = get().history;
1943
+ const dispatch = createReducer({
1944
+ record,
1945
+ appStore: s
1946
+ });
1947
+ const state = dispatch(s.state, action);
1948
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1949
+ (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
1950
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1951
+ }),
1952
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1953
+ setStatus: (status) => set({ status }),
1954
+ setComponentState: (componentState) => set({ componentState }),
1955
+ pendingLoadTimeouts: {},
1956
+ setComponentLoading: (id, loading = true, defer = 0) => {
1957
+ const { setComponentState, pendingLoadTimeouts } = get();
1958
+ const loadId = generateId();
1959
+ const setLoading = () => {
1960
+ var _a2;
1961
+ const { componentState } = get();
1962
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1963
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1964
+ loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
1965
+ })
1966
+ }));
1967
+ };
1968
+ const unsetLoading = () => {
1969
+ var _a2;
1970
+ const { componentState } = get();
1971
+ clearTimeout(timeout);
1972
+ delete pendingLoadTimeouts[loadId];
1973
+ set({ pendingLoadTimeouts });
1974
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1975
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1976
+ loadingCount: Math.max(
1977
+ (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
1978
+ 0
1979
+ )
1980
+ })
1981
+ }));
1982
+ };
1983
+ const timeout = setTimeout(() => {
1984
+ if (loading) {
1985
+ setLoading();
1986
+ } else {
1987
+ unsetLoading();
1988
+ }
1989
+ delete pendingLoadTimeouts[loadId];
1990
+ set({ pendingLoadTimeouts });
1991
+ }, defer);
1992
+ set({
1993
+ pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
1994
+ [id]: timeout
1995
+ })
1996
+ });
1997
+ return unsetLoading;
1998
+ },
1999
+ unsetComponentLoading: (id) => {
2000
+ const { setComponentLoading } = get();
2001
+ setComponentLoading(id, false);
2002
+ },
2003
+ // Helper
2004
+ setUi: (ui, recordHistory) => set((s) => {
2005
+ const dispatch = createReducer({
2006
+ record: () => {
2007
+ },
2008
+ appStore: s
2009
+ });
2010
+ const state = dispatch(s.state, {
2011
+ type: "setUi",
2012
+ ui,
2013
+ recordHistory
2014
+ });
2015
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
2016
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
2017
+ }),
2018
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
2019
+ const { config, metadata, setComponentLoading, permissions } = get();
2020
+ const timeouts = {};
2021
+ return yield resolveComponentData(
2022
+ componentData,
2023
+ config,
2024
+ metadata,
2025
+ (item) => {
2026
+ const id = "id" in item.props ? item.props.id : "root";
2027
+ timeouts[id] = setComponentLoading(id, true, 50);
2028
+ },
2029
+ (item) => __async(void 0, null, function* () {
2030
+ const id = "id" in item.props ? item.props.id : "root";
2031
+ if ("type" in item) {
2032
+ yield permissions.refreshPermissions({ item });
2033
+ } else {
2034
+ yield permissions.refreshPermissions({ root: true });
2035
+ }
2036
+ timeouts[id]();
2037
+ }),
2038
+ trigger
2039
+ );
2040
+ }),
2041
+ resolveAndCommitData: () => __async(void 0, null, function* () {
2042
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
2043
+ walkAppState(
2044
+ state,
2045
+ config,
2046
+ (content) => content,
2047
+ (childItem) => {
2048
+ resolveComponentData2(childItem, "load").then((resolved) => {
2049
+ const { state: state2 } = get();
2050
+ const node = state2.indexes.nodes[resolved.node.props.id];
2051
+ if (node && resolved.didChange) {
2052
+ if (resolved.node.props.id === "root") {
2053
+ dispatch({
2054
+ type: "replaceRoot",
2055
+ root: toRoot(resolved.node)
2056
+ });
2057
+ } else {
2058
+ const zoneCompound = `${node.parentId}:${node.zone}`;
2059
+ const parentZone = state2.indexes.zones[zoneCompound];
2060
+ const index = parentZone.contentIds.indexOf(
2061
+ resolved.node.props.id
2062
+ );
2063
+ dispatch({
2064
+ type: "replace",
2065
+ data: resolved.node,
2066
+ destinationIndex: index,
2067
+ destinationZone: zoneCompound
2068
+ });
2069
+ }
2070
+ }
2071
+ });
2072
+ return childItem;
2073
+ }
2074
+ );
2075
+ })
2076
+ });
2077
+ })
2078
+ );
2079
+ var appStoreContext = createContext(createAppStore());
2080
+ function useAppStore(selector) {
2081
+ const context = useContext(appStoreContext);
2082
+ return useStore(context, selector);
2083
+ }
2084
+ function useAppStoreApi() {
2085
+ return useContext(appStoreContext);
2086
+ }
2087
+
2088
+ // ../core/lib/use-breadcrumbs.ts
2089
+ var useBreadcrumbs = (renderCount) => {
2090
+ const selectedId = useAppStore((s) => {
2091
+ var _a;
2092
+ return (_a = s.selectedItem) == null ? void 0 : _a.props.id;
2093
+ });
2094
+ const config = useAppStore((s) => s.config);
2095
+ const path = useAppStore((s) => {
2096
+ var _a;
2097
+ return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
2098
+ });
2099
+ const appStore = useAppStoreApi();
2100
+ return useMemo(() => {
2101
+ const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
2102
+ var _a, _b, _c;
2103
+ const [componentId] = zoneCompound.split(":");
2104
+ if (componentId === "root") {
2105
+ return {
2106
+ label: "Page",
2107
+ selector: null
2108
+ };
2109
+ }
2110
+ const node = appStore.getState().state.indexes.nodes[componentId];
2111
+ const parentId = node.path[node.path.length - 1];
2112
+ const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
2113
+ const index = contentIds.indexOf(componentId);
2114
+ const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
2115
+ return {
2116
+ label,
2117
+ selector: node ? {
2118
+ index,
2119
+ zone: node.path[node.path.length - 1]
2120
+ } : null
2121
+ };
2122
+ })) || [];
2123
+ if (renderCount) {
2124
+ return breadcrumbs.slice(breadcrumbs.length - renderCount);
2125
+ }
2126
+ return breadcrumbs;
2127
+ }, [path, renderCount]);
2128
+ };
2129
+
2130
+ // ../core/components/Loader/index.tsx
2131
+ init_react_import();
2132
+
317
2133
  // ../core/lib/index.ts
318
2134
  init_react_import();
319
2135
 
@@ -326,10 +2142,139 @@ init_react_import();
326
2142
  // ../core/lib/data/replace.ts
327
2143
  init_react_import();
328
2144
 
2145
+ // ../core/lib/use-reset-auto-zoom.ts
2146
+ init_react_import();
2147
+ import { useCallback as useCallback2 } from "react";
2148
+
2149
+ // ../core/lib/get-zoom-config.ts
2150
+ init_react_import();
2151
+
2152
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
2153
+ init_react_import();
2154
+ var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
2155
+
2156
+ // ../core/components/Loader/index.tsx
2157
+ import { jsx as jsx2 } from "react/jsx-runtime";
2158
+ var getClassName2 = get_class_name_factory_default("Loader", styles_module_default3);
2159
+ var Loader = (_a) => {
2160
+ var _b = _a, {
2161
+ color,
2162
+ size = 16
2163
+ } = _b, props = __objRest(_b, [
2164
+ "color",
2165
+ "size"
2166
+ ]);
2167
+ return /* @__PURE__ */ jsx2(
2168
+ "span",
2169
+ __spreadValues({
2170
+ className: getClassName2(),
2171
+ style: {
2172
+ width: size,
2173
+ height: size,
2174
+ color
2175
+ },
2176
+ "aria-label": "loading"
2177
+ }, props)
2178
+ );
2179
+ };
2180
+
2181
+ // ../core/components/SidebarSection/index.tsx
2182
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
2183
+ var getClassName3 = get_class_name_factory_default("SidebarSection", styles_module_default);
2184
+ var SidebarSection = ({
2185
+ children,
2186
+ title,
2187
+ background,
2188
+ showBreadcrumbs,
2189
+ noBorderTop,
2190
+ noPadding,
2191
+ isLoading
2192
+ }) => {
2193
+ const setUi = useAppStore((s) => s.setUi);
2194
+ const breadcrumbs = useBreadcrumbs(1);
2195
+ return /* @__PURE__ */ jsxs(
2196
+ "div",
2197
+ {
2198
+ className: getClassName3({ noBorderTop, noPadding }),
2199
+ style: { background },
2200
+ children: [
2201
+ /* @__PURE__ */ jsx3("div", { className: getClassName3("title"), children: /* @__PURE__ */ jsxs("div", { className: getClassName3("breadcrumbs"), children: [
2202
+ showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ jsxs("div", { className: getClassName3("breadcrumb"), children: [
2203
+ /* @__PURE__ */ jsx3(
2204
+ "button",
2205
+ {
2206
+ type: "button",
2207
+ className: getClassName3("breadcrumbLabel"),
2208
+ onClick: () => setUi({ itemSelector: breadcrumb.selector }),
2209
+ children: breadcrumb.label
2210
+ }
2211
+ ),
2212
+ /* @__PURE__ */ jsx3(ChevronRight, { size: 16 })
2213
+ ] }, i)) : null,
2214
+ /* @__PURE__ */ jsx3("div", { className: getClassName3("heading"), children: /* @__PURE__ */ jsx3(Heading, { rank: "2", size: "xs", children: title }) })
2215
+ ] }) }),
2216
+ /* @__PURE__ */ jsx3("div", { className: getClassName3("content"), children }),
2217
+ isLoading && /* @__PURE__ */ jsx3("div", { className: getClassName3("loadingOverlay"), children: /* @__PURE__ */ jsx3(Loader, { size: 32 }) })
2218
+ ]
2219
+ }
2220
+ );
2221
+ };
2222
+
2223
+ // ../core/components/OutlineList/index.tsx
2224
+ init_react_import();
2225
+
2226
+ // css-module:/home/runner/work/puck/puck/packages/core/components/OutlineList/styles.module.css#css-module
2227
+ init_react_import();
2228
+ var styles_module_default4 = { "OutlineList": "_OutlineList_w4lzv_1", "OutlineListItem": "_OutlineListItem_w4lzv_25", "OutlineListItem--clickable": "_OutlineListItem--clickable_w4lzv_45" };
2229
+
2230
+ // ../core/components/OutlineList/index.tsx
2231
+ import { jsx as jsx4 } from "react/jsx-runtime";
2232
+ var getClassName4 = get_class_name_factory_default("OutlineList", styles_module_default4);
2233
+ var getClassNameItem = get_class_name_factory_default("OutlineListItem", styles_module_default4);
2234
+ var OutlineList = ({ children }) => {
2235
+ return /* @__PURE__ */ jsx4("ul", { className: getClassName4(), children });
2236
+ };
2237
+ OutlineList.Clickable = ({ children }) => /* @__PURE__ */ jsx4("div", { className: getClassNameItem({ clickable: true }), children });
2238
+ OutlineList.Item = ({
2239
+ children,
2240
+ onClick
2241
+ }) => {
2242
+ return /* @__PURE__ */ jsx4(
2243
+ "li",
2244
+ {
2245
+ className: getClassNameItem({ clickable: !!onClick }),
2246
+ onClick,
2247
+ children
2248
+ }
2249
+ );
2250
+ };
2251
+
2252
+ // ../core/lib/scroll-into-view.ts
2253
+ init_react_import();
2254
+ var scrollIntoView = (el) => {
2255
+ const oldStyle = __spreadValues({}, el.style);
2256
+ el.style.scrollMargin = "256px";
2257
+ if (el) {
2258
+ el == null ? void 0 : el.scrollIntoView({ behavior: "smooth" });
2259
+ el.style.scrollMargin = oldStyle.scrollMargin || "";
2260
+ }
2261
+ };
2262
+
2263
+ // ../core/lib/get-frame.ts
2264
+ init_react_import();
2265
+ var getFrame = () => {
2266
+ if (typeof window === "undefined") return;
2267
+ let frameEl = document.querySelector("#preview-frame");
2268
+ if ((frameEl == null ? void 0 : frameEl.tagName) === "IFRAME") {
2269
+ return frameEl.contentDocument || document;
2270
+ }
2271
+ return (frameEl == null ? void 0 : frameEl.ownerDocument) || document;
2272
+ };
2273
+
329
2274
  // src/HeadingAnalyzer.tsx
330
2275
  import ReactFromJSONModule from "react-from-json";
331
- import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
332
- var getClassName2 = get_class_name_factory_default("HeadingAnalyzer", HeadingAnalyzer_module_default);
2276
+ import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
2277
+ var getClassName5 = get_class_name_factory_default("HeadingAnalyzer", HeadingAnalyzer_module_default);
333
2278
  var getClassNameItem2 = get_class_name_factory_default("HeadingAnalyzerItem", HeadingAnalyzer_module_default);
334
2279
  var ReactFromJSON = ReactFromJSONModule.default || ReactFromJSONModule;
335
2280
  var getOutline = ({ frame } = {}) => {
@@ -385,7 +2330,7 @@ var usePuck = createUsePuck();
385
2330
  var HeadingAnalyzer = () => {
386
2331
  const data = usePuck((s) => s.appState.data);
387
2332
  const [hierarchy, setHierarchy] = useState([]);
388
- useEffect(() => {
2333
+ useEffect5(() => {
389
2334
  const frame = getFrame();
390
2335
  let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
391
2336
  const createHierarchy = () => {
@@ -420,11 +2365,11 @@ var HeadingAnalyzer = () => {
420
2365
  frameObserver.disconnect();
421
2366
  };
422
2367
  }, [data]);
423
- return /* @__PURE__ */ jsxs("div", { className: getClassName2(), children: [
424
- /* @__PURE__ */ jsxs(
2368
+ return /* @__PURE__ */ jsxs2("div", { className: getClassName5(), children: [
2369
+ /* @__PURE__ */ jsxs2(
425
2370
  "small",
426
2371
  {
427
- className: getClassName2("cssWarning"),
2372
+ className: getClassName5("cssWarning"),
428
2373
  style: {
429
2374
  color: "var(--puck-color-red-04)",
430
2375
  display: "block",
@@ -433,19 +2378,19 @@ var HeadingAnalyzer = () => {
433
2378
  children: [
434
2379
  "Heading analyzer styles not loaded. Please review the",
435
2380
  " ",
436
- /* @__PURE__ */ jsx2("a", { href: "https://github.com/measuredco/puck/blob/main/packages/plugin-heading-analyzer/README.md", children: "README" }),
2381
+ /* @__PURE__ */ jsx5("a", { href: "https://github.com/measuredco/puck/blob/main/packages/plugin-heading-analyzer/README.md", children: "README" }),
437
2382
  "."
438
2383
  ]
439
2384
  }
440
2385
  ),
441
- hierarchy.length === 0 && /* @__PURE__ */ jsx2("div", { children: "No headings." }),
442
- /* @__PURE__ */ jsx2(OutlineList, { children: /* @__PURE__ */ jsx2(
2386
+ hierarchy.length === 0 && /* @__PURE__ */ jsx5("div", { children: "No headings." }),
2387
+ /* @__PURE__ */ jsx5(OutlineList, { children: /* @__PURE__ */ jsx5(
443
2388
  ReactFromJSON,
444
2389
  {
445
2390
  mapping: {
446
- Root: (props) => /* @__PURE__ */ jsx2(Fragment, { children: props.children }),
447
- OutlineListItem: (props) => /* @__PURE__ */ jsxs(OutlineList.Item, { children: [
448
- /* @__PURE__ */ jsx2(OutlineList.Clickable, { children: /* @__PURE__ */ jsx2(
2391
+ Root: (props) => /* @__PURE__ */ jsx5(Fragment, { children: props.children }),
2392
+ OutlineListItem: (props) => /* @__PURE__ */ jsxs2(OutlineList.Item, { children: [
2393
+ /* @__PURE__ */ jsx5(OutlineList.Clickable, { children: /* @__PURE__ */ jsx5(
449
2394
  "small",
450
2395
  {
451
2396
  className: getClassNameItem2({ missing: props.missing }),
@@ -463,14 +2408,14 @@ var HeadingAnalyzer = () => {
463
2408
  }, 2e3);
464
2409
  }
465
2410
  },
466
- children: props.missing ? /* @__PURE__ */ jsxs(Fragment, { children: [
467
- /* @__PURE__ */ jsxs("b", { children: [
2411
+ children: props.missing ? /* @__PURE__ */ jsxs2(Fragment, { children: [
2412
+ /* @__PURE__ */ jsxs2("b", { children: [
468
2413
  "H",
469
2414
  props.rank
470
2415
  ] }),
471
2416
  ": Missing"
472
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
473
- /* @__PURE__ */ jsxs("b", { children: [
2417
+ ] }) : /* @__PURE__ */ jsxs2(Fragment, { children: [
2418
+ /* @__PURE__ */ jsxs2("b", { children: [
474
2419
  "H",
475
2420
  props.rank
476
2421
  ] }),
@@ -479,7 +2424,7 @@ var HeadingAnalyzer = () => {
479
2424
  ] })
480
2425
  }
481
2426
  ) }),
482
- /* @__PURE__ */ jsx2(OutlineList, { children: props.children })
2427
+ /* @__PURE__ */ jsx5(OutlineList, { children: props.children })
483
2428
  ] })
484
2429
  },
485
2430
  entry: {
@@ -500,10 +2445,12 @@ var HeadingAnalyzer = () => {
500
2445
  ] });
501
2446
  };
502
2447
  var headingAnalyzer = {
503
- name: "heading-analyzer",
504
- label: "Audit",
505
- render: HeadingAnalyzer,
506
- icon: /* @__PURE__ */ jsx2(Heading1, {})
2448
+ overrides: {
2449
+ fields: ({ children, itemSelector }) => /* @__PURE__ */ jsxs2(Fragment, { children: [
2450
+ children,
2451
+ /* @__PURE__ */ jsx5("div", { style: { display: itemSelector ? "none" : "block" }, children: /* @__PURE__ */ jsx5(SidebarSection, { title: "Heading Outline", children: /* @__PURE__ */ jsx5(HeadingAnalyzer, {}) }) })
2452
+ ] })
2453
+ }
507
2454
  };
508
2455
  var HeadingAnalyzer_default = headingAnalyzer;
509
2456
  export {
@@ -550,7 +2497,7 @@ lucide-react/dist/esm/createLucideIcon.js:
550
2497
  * See the LICENSE file in the root directory of this source tree.
551
2498
  *)
552
2499
 
553
- lucide-react/dist/esm/icons/heading-1.js:
2500
+ lucide-react/dist/esm/icons/chevron-right.js:
554
2501
  (**
555
2502
  * @license lucide-react v0.468.0 - ISC
556
2503
  *