@measured/puck-plugin-heading-analyzer 0.20.0-canary.755737e8 → 0.20.0-canary.7ccbeece

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