@puckeditor/plugin-heading-analyzer 0.21.0-canary.d1c0d6a2

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 ADDED
@@ -0,0 +1,2791 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __objRest = (source, exclude) => {
25
+ var target = {};
26
+ for (var prop in source)
27
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
28
+ target[prop] = source[prop];
29
+ if (source != null && __getOwnPropSymbols)
30
+ for (var prop of __getOwnPropSymbols(source)) {
31
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
32
+ target[prop] = source[prop];
33
+ }
34
+ return target;
35
+ };
36
+ var __esm = (fn, res) => function __init() {
37
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
38
+ };
39
+ var __commonJS = (cb, mod) => function __require() {
40
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
41
+ };
42
+ var __copyProps = (to, from, except, desc) => {
43
+ if (from && typeof from === "object" || typeof from === "function") {
44
+ for (let key of __getOwnPropNames(from))
45
+ if (!__hasOwnProp.call(to, key) && key !== except)
46
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
47
+ }
48
+ return to;
49
+ };
50
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
51
+ // If the importer is in node compatibility mode or this is not an ESM
52
+ // file that has been converted to a CommonJS file using a Babel-
53
+ // compatible transform (i.e. "__esModule" has not been set), then set
54
+ // "default" to the CommonJS "module.exports" for node compatibility.
55
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
56
+ mod
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
+ };
78
+
79
+ // ../tsup-config/react-import.js
80
+ import React from "react";
81
+ var init_react_import = __esm({
82
+ "../tsup-config/react-import.js"() {
83
+ "use strict";
84
+ }
85
+ });
86
+
87
+ // ../../node_modules/classnames/index.js
88
+ var require_classnames = __commonJS({
89
+ "../../node_modules/classnames/index.js"(exports, module) {
90
+ "use strict";
91
+ init_react_import();
92
+ (function() {
93
+ "use strict";
94
+ var hasOwn2 = {}.hasOwnProperty;
95
+ function classNames() {
96
+ var classes = "";
97
+ for (var i = 0; i < arguments.length; i++) {
98
+ var arg = arguments[i];
99
+ if (arg) {
100
+ classes = appendClass(classes, parseValue(arg));
101
+ }
102
+ }
103
+ return classes;
104
+ }
105
+ function parseValue(arg) {
106
+ if (typeof arg === "string" || typeof arg === "number") {
107
+ return arg;
108
+ }
109
+ if (typeof arg !== "object") {
110
+ return "";
111
+ }
112
+ if (Array.isArray(arg)) {
113
+ return classNames.apply(null, arg);
114
+ }
115
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
116
+ return arg.toString();
117
+ }
118
+ var classes = "";
119
+ for (var key in arg) {
120
+ if (hasOwn2.call(arg, key) && arg[key]) {
121
+ classes = appendClass(classes, key);
122
+ }
123
+ }
124
+ return classes;
125
+ }
126
+ function appendClass(value, newClass) {
127
+ if (!newClass) {
128
+ return value;
129
+ }
130
+ if (value) {
131
+ return value + " " + newClass;
132
+ }
133
+ return value + newClass;
134
+ }
135
+ if (typeof module !== "undefined" && module.exports) {
136
+ classNames.default = classNames;
137
+ module.exports = classNames;
138
+ } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
139
+ define("classnames", [], function() {
140
+ return classNames;
141
+ });
142
+ } else {
143
+ window.classNames = classNames;
144
+ }
145
+ })();
146
+ }
147
+ });
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 isArray2 = type === "[object Array]";
210
+ const isObject = type === "[object Object]";
211
+ if (!val) {
212
+ return true;
213
+ } else if (isArray2) {
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
+ // index.ts
264
+ init_react_import();
265
+
266
+ // src/HeadingAnalyzer.tsx
267
+ init_react_import();
268
+ import { useEffect as useEffect5, useState } from "react";
269
+
270
+ // css-module:/home/runner/work/puck/puck/packages/plugin-heading-analyzer/src/HeadingAnalyzer.module.css#css-module
271
+ init_react_import();
272
+ var HeadingAnalyzer_module_default = { "HeadingAnalyzer": "_HeadingAnalyzer_yg0s7_1", "HeadingAnalyzer-cssWarning": "_HeadingAnalyzer-cssWarning_yg0s7_6", "HeadingAnalyzerItem": "_HeadingAnalyzerItem_yg0s7_10", "HeadingAnalyzerItem--missing": "_HeadingAnalyzerItem--missing_yg0s7_14" };
273
+
274
+ // src/HeadingAnalyzer.tsx
275
+ import { createUsePuck } from "@puckeditor/core";
276
+
277
+ // ../core/components/OutlineList/index.tsx
278
+ init_react_import();
279
+
280
+ // css-module:/home/runner/work/puck/puck/packages/core/components/OutlineList/styles.module.css#css-module
281
+ init_react_import();
282
+ var styles_module_default = { "OutlineList": "_OutlineList_w4lzv_1", "OutlineListItem": "_OutlineListItem_w4lzv_25", "OutlineListItem--clickable": "_OutlineListItem--clickable_w4lzv_45" };
283
+
284
+ // ../core/lib/get-class-name-factory.ts
285
+ init_react_import();
286
+ var import_classnames = __toESM(require_classnames());
287
+ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
288
+ if (typeof options === "string") {
289
+ const descendant = options;
290
+ const style = styles[`${rootClass}-${descendant}`];
291
+ if (style) {
292
+ return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
293
+ }
294
+ return "";
295
+ } else if (typeof options === "object") {
296
+ const modifiers = options;
297
+ const prefixedModifiers = {};
298
+ for (let modifier in modifiers) {
299
+ prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
300
+ }
301
+ const c = styles[rootClass];
302
+ return config.baseClass + (0, import_classnames.default)(__spreadValues({
303
+ [c]: !!c
304
+ }, prefixedModifiers));
305
+ } else {
306
+ return config.baseClass + styles[rootClass] || "";
307
+ }
308
+ };
309
+ var get_class_name_factory_default = getClassNameFactory;
310
+
311
+ // ../core/components/OutlineList/index.tsx
312
+ import { jsx } from "react/jsx-runtime";
313
+ var getClassName = get_class_name_factory_default("OutlineList", styles_module_default);
314
+ var getClassNameItem = get_class_name_factory_default("OutlineListItem", styles_module_default);
315
+ var OutlineList = ({ children }) => {
316
+ return /* @__PURE__ */ jsx("ul", { className: getClassName(), children });
317
+ };
318
+ OutlineList.Clickable = ({ children }) => /* @__PURE__ */ jsx("div", { className: getClassNameItem({ clickable: true }), children });
319
+ OutlineList.Item = ({
320
+ children,
321
+ onClick
322
+ }) => {
323
+ return /* @__PURE__ */ jsx(
324
+ "li",
325
+ {
326
+ className: getClassNameItem({ clickable: !!onClick }),
327
+ onClick,
328
+ children
329
+ }
330
+ );
331
+ };
332
+
333
+ // ../core/lib/scroll-into-view.ts
334
+ init_react_import();
335
+ var scrollIntoView = (el) => {
336
+ const oldStyle = __spreadValues({}, el.style);
337
+ el.style.scrollMargin = "256px";
338
+ if (el) {
339
+ el == null ? void 0 : el.scrollIntoView({ behavior: "smooth" });
340
+ el.style.scrollMargin = oldStyle.scrollMargin || "";
341
+ }
342
+ };
343
+
344
+ // ../core/lib/get-frame.ts
345
+ init_react_import();
346
+ var getFrame = () => {
347
+ if (typeof window === "undefined") return;
348
+ let frameEl = document.querySelector("#preview-frame");
349
+ if ((frameEl == null ? void 0 : frameEl.tagName) === "IFRAME") {
350
+ return frameEl.contentDocument || document;
351
+ }
352
+ return (frameEl == null ? void 0 : frameEl.ownerDocument) || document;
353
+ };
354
+
355
+ // ../../node_modules/lucide-react/dist/esm/lucide-react.js
356
+ init_react_import();
357
+
358
+ // ../../node_modules/lucide-react/dist/esm/createLucideIcon.js
359
+ init_react_import();
360
+ import { forwardRef as forwardRef2, createElement as createElement2 } from "react";
361
+
362
+ // ../../node_modules/lucide-react/dist/esm/shared/src/utils.js
363
+ init_react_import();
364
+ var toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
365
+ var mergeClasses = (...classes) => classes.filter((className, index, array) => {
366
+ return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
367
+ }).join(" ").trim();
368
+
369
+ // ../../node_modules/lucide-react/dist/esm/Icon.js
370
+ init_react_import();
371
+ import { forwardRef, createElement } from "react";
372
+
373
+ // ../../node_modules/lucide-react/dist/esm/defaultAttributes.js
374
+ init_react_import();
375
+ var defaultAttributes = {
376
+ xmlns: "http://www.w3.org/2000/svg",
377
+ width: 24,
378
+ height: 24,
379
+ viewBox: "0 0 24 24",
380
+ fill: "none",
381
+ stroke: "currentColor",
382
+ strokeWidth: 2,
383
+ strokeLinecap: "round",
384
+ strokeLinejoin: "round"
385
+ };
386
+
387
+ // ../../node_modules/lucide-react/dist/esm/Icon.js
388
+ var Icon = forwardRef(
389
+ (_a, ref) => {
390
+ var _b = _a, {
391
+ color = "currentColor",
392
+ size = 24,
393
+ strokeWidth = 2,
394
+ absoluteStrokeWidth,
395
+ className = "",
396
+ children,
397
+ iconNode
398
+ } = _b, rest = __objRest(_b, [
399
+ "color",
400
+ "size",
401
+ "strokeWidth",
402
+ "absoluteStrokeWidth",
403
+ "className",
404
+ "children",
405
+ "iconNode"
406
+ ]);
407
+ return createElement(
408
+ "svg",
409
+ __spreadValues(__spreadProps(__spreadValues({
410
+ ref
411
+ }, defaultAttributes), {
412
+ width: size,
413
+ height: size,
414
+ stroke: color,
415
+ strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
416
+ className: mergeClasses("lucide", className)
417
+ }), rest),
418
+ [
419
+ ...iconNode.map(([tag, attrs]) => createElement(tag, attrs)),
420
+ ...Array.isArray(children) ? children : [children]
421
+ ]
422
+ );
423
+ }
424
+ );
425
+
426
+ // ../../node_modules/lucide-react/dist/esm/createLucideIcon.js
427
+ var createLucideIcon = (iconName, iconNode) => {
428
+ const Component = forwardRef2(
429
+ (_a, ref) => {
430
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
431
+ return createElement2(Icon, __spreadValues({
432
+ ref,
433
+ iconNode,
434
+ className: mergeClasses(`lucide-${toKebabCase(iconName)}`, className)
435
+ }, props));
436
+ }
437
+ );
438
+ Component.displayName = `${iconName}`;
439
+ return Component;
440
+ };
441
+
442
+ // ../../node_modules/lucide-react/dist/esm/icons/heading-1.js
443
+ init_react_import();
444
+ var Heading1 = createLucideIcon("Heading1", [
445
+ ["path", { d: "M4 12h8", key: "17cfdx" }],
446
+ ["path", { d: "M4 18V6", key: "1rz3zl" }],
447
+ ["path", { d: "M12 18V6", key: "zqpxq5" }],
448
+ ["path", { d: "m17 12 3-2v8", key: "1hhhft" }]
449
+ ]);
450
+
451
+ // ../core/lib/index.ts
452
+ init_react_import();
453
+
454
+ // ../core/lib/filter.ts
455
+ init_react_import();
456
+
457
+ // ../core/lib/data/reorder.ts
458
+ init_react_import();
459
+
460
+ // ../core/lib/data/replace.ts
461
+ init_react_import();
462
+
463
+ // ../core/lib/use-reset-auto-zoom.ts
464
+ init_react_import();
465
+
466
+ // ../core/store/index.ts
467
+ init_react_import();
468
+
469
+ // ../core/reducer/index.ts
470
+ init_react_import();
471
+
472
+ // ../core/reducer/actions/set.ts
473
+ init_react_import();
474
+
475
+ // ../core/lib/data/walk-app-state.ts
476
+ init_react_import();
477
+
478
+ // ../core/lib/data/for-related-zones.ts
479
+ init_react_import();
480
+
481
+ // ../core/lib/get-zone-id.ts
482
+ init_react_import();
483
+
484
+ // ../core/lib/root-droppable-id.ts
485
+ init_react_import();
486
+ var rootAreaId = "root";
487
+ var rootZone = "default-zone";
488
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
489
+
490
+ // ../core/lib/get-zone-id.ts
491
+ var getZoneId = (zoneCompound) => {
492
+ if (!zoneCompound) {
493
+ return [];
494
+ }
495
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
496
+ return zoneCompound.split(":");
497
+ }
498
+ return [rootDroppableId, zoneCompound];
499
+ };
500
+
501
+ // ../core/lib/data/for-related-zones.ts
502
+ function forRelatedZones(item, data, cb, path = []) {
503
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
504
+ const [parentId] = getZoneId(zoneCompound);
505
+ if (parentId === item.props.id) {
506
+ cb(path, zoneCompound, content);
507
+ }
508
+ });
509
+ }
510
+
511
+ // ../core/lib/data/map-fields.ts
512
+ init_react_import();
513
+
514
+ // ../core/lib/data/default-slots.ts
515
+ init_react_import();
516
+ var defaultSlots = (value, fields) => Object.keys(fields).reduce(
517
+ (acc, fieldName) => fields[fieldName].type === "slot" ? __spreadValues({ [fieldName]: [] }, acc) : acc,
518
+ value
519
+ );
520
+
521
+ // ../core/lib/data/map-fields.ts
522
+ var isPromise = (v) => !!v && typeof v.then === "function";
523
+ var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
524
+ var containsPromise = (arr) => arr.some(isPromise);
525
+ var walkField = ({
526
+ value,
527
+ fields,
528
+ mappers,
529
+ propKey = "",
530
+ propPath = "",
531
+ id = "",
532
+ config,
533
+ recurseSlots = false
534
+ }) => {
535
+ var _a, _b, _c;
536
+ const fieldType = (_a = fields[propKey]) == null ? void 0 : _a.type;
537
+ const map = mappers[fieldType];
538
+ if (map && fieldType === "slot") {
539
+ const content = value || [];
540
+ const mappedContent = recurseSlots ? content.map((el) => {
541
+ var _a2;
542
+ const componentConfig = config.components[el.type];
543
+ if (!componentConfig) {
544
+ throw new Error(`Could not find component config for ${el.type}`);
545
+ }
546
+ const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
547
+ return walkField({
548
+ value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
549
+ fields: fields2,
550
+ mappers,
551
+ id: el.props.id,
552
+ config,
553
+ recurseSlots
554
+ });
555
+ }) : content;
556
+ if (containsPromise(mappedContent)) {
557
+ return Promise.all(mappedContent);
558
+ }
559
+ return map({
560
+ value: mappedContent,
561
+ parentId: id,
562
+ propName: propPath,
563
+ field: fields[propKey],
564
+ propPath
565
+ });
566
+ } else if (map && fields[propKey]) {
567
+ return map({
568
+ value,
569
+ parentId: id,
570
+ propName: propKey,
571
+ field: fields[propKey],
572
+ propPath
573
+ });
574
+ }
575
+ if (value && typeof value === "object") {
576
+ if (Array.isArray(value)) {
577
+ const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
578
+ if (!arrayFields) return value;
579
+ const newValue = value.map(
580
+ (el, idx) => walkField({
581
+ value: el,
582
+ fields: arrayFields,
583
+ mappers,
584
+ propKey,
585
+ propPath: `${propPath}[${idx}]`,
586
+ id,
587
+ config,
588
+ recurseSlots
589
+ })
590
+ );
591
+ if (containsPromise(newValue)) {
592
+ return Promise.all(newValue);
593
+ }
594
+ return newValue;
595
+ } else if ("$$typeof" in value) {
596
+ return value;
597
+ } else {
598
+ const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
599
+ return walkObject({
600
+ value,
601
+ fields: objectFields,
602
+ mappers,
603
+ id,
604
+ getPropPath: (k) => `${propPath}.${k}`,
605
+ config,
606
+ recurseSlots
607
+ });
608
+ }
609
+ }
610
+ return value;
611
+ };
612
+ var walkObject = ({
613
+ value,
614
+ fields,
615
+ mappers,
616
+ id,
617
+ getPropPath,
618
+ config,
619
+ recurseSlots
620
+ }) => {
621
+ const newProps = Object.entries(value).map(([k, v]) => {
622
+ const opts = {
623
+ value: v,
624
+ fields,
625
+ mappers,
626
+ propKey: k,
627
+ propPath: getPropPath(k),
628
+ id,
629
+ config,
630
+ recurseSlots
631
+ };
632
+ const newValue = walkField(opts);
633
+ if (isPromise(newValue)) {
634
+ return newValue.then((resolvedValue) => ({
635
+ [k]: resolvedValue
636
+ }));
637
+ }
638
+ return {
639
+ [k]: newValue
640
+ };
641
+ }, {});
642
+ if (containsPromise(newProps)) {
643
+ return Promise.all(newProps).then(flatten);
644
+ }
645
+ return flatten(newProps);
646
+ };
647
+ function mapFields(item, mappers, config, recurseSlots = false, shouldDefaultSlots = true) {
648
+ var _a, _b, _c, _d, _e;
649
+ const itemType = "type" in item ? item.type : "root";
650
+ const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
651
+ const newProps = walkObject({
652
+ value: shouldDefaultSlots ? defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}) : item.props,
653
+ fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
654
+ mappers,
655
+ id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
656
+ getPropPath: (k) => k,
657
+ config,
658
+ recurseSlots
659
+ });
660
+ if (isPromise(newProps)) {
661
+ return newProps.then((resolvedProps) => __spreadProps(__spreadValues({}, item), {
662
+ props: resolvedProps
663
+ }));
664
+ }
665
+ return __spreadProps(__spreadValues({}, item), {
666
+ props: newProps
667
+ });
668
+ }
669
+
670
+ // ../core/lib/data/flatten-node.ts
671
+ init_react_import();
672
+ var import_flat = __toESM(require_flat());
673
+
674
+ // ../core/lib/data/strip-slots.ts
675
+ init_react_import();
676
+ var stripSlots = (data, config) => {
677
+ return mapFields(data, { slot: () => null }, config);
678
+ };
679
+
680
+ // ../core/lib/data/flatten-node.ts
681
+ var { flatten: flatten2, unflatten } = import_flat.default;
682
+ function isEmptyArrayOrObject(val) {
683
+ if (Array.isArray(val)) {
684
+ return val.length === 0;
685
+ }
686
+ if (val != null && Object.prototype.toString.call(val) === "[object Object]") {
687
+ return Object.keys(val).length === 0;
688
+ }
689
+ return false;
690
+ }
691
+ function stripEmptyObjects(props) {
692
+ const result = {};
693
+ for (const key in props) {
694
+ if (!Object.prototype.hasOwnProperty.call(props, key)) continue;
695
+ const val = props[key];
696
+ if (isEmptyArrayOrObject(val)) continue;
697
+ result[key] = val;
698
+ }
699
+ return result;
700
+ }
701
+ var flattenNode = (node, config) => {
702
+ return __spreadProps(__spreadValues({}, node), {
703
+ props: stripEmptyObjects(flatten2(stripSlots(node, config).props))
704
+ });
705
+ };
706
+
707
+ // ../core/lib/data/walk-app-state.ts
708
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
709
+ var _a;
710
+ let newZones = {};
711
+ const newZoneIndex = {};
712
+ const newNodeIndex = {};
713
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
714
+ var _a2;
715
+ const [parentId] = zoneCompound.split(":");
716
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
717
+ const [_2, zone] = zoneCompound.split(":");
718
+ const newZoneCompound = `${newId || parentId}:${zone}`;
719
+ const newContent2 = mappedContent.map(
720
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
721
+ );
722
+ newZoneIndex[newZoneCompound] = {
723
+ contentIds: newContent2.map((item) => item.props.id),
724
+ type: zoneType
725
+ };
726
+ return [newZoneCompound, newContent2];
727
+ };
728
+ const processRelatedZones = (item, newId, initialPath) => {
729
+ forRelatedZones(
730
+ item,
731
+ state.data,
732
+ (relatedPath, relatedZoneCompound, relatedContent) => {
733
+ const [zoneCompound, newContent2] = processContent(
734
+ relatedPath,
735
+ relatedZoneCompound,
736
+ relatedContent,
737
+ "dropzone",
738
+ newId
739
+ );
740
+ newZones[zoneCompound] = newContent2;
741
+ },
742
+ initialPath
743
+ );
744
+ };
745
+ const processItem = (item, path, index) => {
746
+ const mappedItem = mapNodeOrSkip(item, path, index);
747
+ if (!mappedItem) return item;
748
+ const id = mappedItem.props.id;
749
+ const newProps = __spreadProps(__spreadValues({}, mapFields(
750
+ mappedItem,
751
+ {
752
+ slot: ({ value, parentId: parentId2, propPath }) => {
753
+ const content = value;
754
+ const zoneCompound = `${parentId2}:${propPath}`;
755
+ const [_2, newContent2] = processContent(
756
+ path,
757
+ zoneCompound,
758
+ content,
759
+ "slot",
760
+ parentId2
761
+ );
762
+ return newContent2;
763
+ }
764
+ },
765
+ config
766
+ ).props), {
767
+ id
768
+ });
769
+ processRelatedZones(item, id, path);
770
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
771
+ const thisZoneCompound = path[path.length - 1];
772
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
773
+ newNodeIndex[id] = {
774
+ data: newItem,
775
+ flatData: flattenNode(newItem, config),
776
+ path,
777
+ parentId,
778
+ zone
779
+ };
780
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
781
+ if (newProps.id === "root") {
782
+ delete finalData["type"];
783
+ delete finalData.props["id"];
784
+ }
785
+ return finalData;
786
+ };
787
+ const zones = state.data.zones || {};
788
+ const [_, newContent] = processContent(
789
+ [],
790
+ rootDroppableId,
791
+ state.data.content,
792
+ "root"
793
+ );
794
+ const processedContent = newContent;
795
+ const zonesAlreadyProcessed = Object.keys(newZones);
796
+ Object.keys(zones || {}).forEach((zoneCompound) => {
797
+ const [parentId] = zoneCompound.split(":");
798
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
799
+ return;
800
+ }
801
+ const [_2, newContent2] = processContent(
802
+ [rootDroppableId],
803
+ zoneCompound,
804
+ zones[zoneCompound],
805
+ "dropzone",
806
+ parentId
807
+ );
808
+ newZones[zoneCompound] = newContent2;
809
+ }, newZones);
810
+ const processedRoot = processItem(
811
+ {
812
+ type: "root",
813
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
814
+ },
815
+ [],
816
+ -1
817
+ );
818
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
819
+ props: processedRoot.props
820
+ });
821
+ return __spreadProps(__spreadValues({}, state), {
822
+ data: {
823
+ root,
824
+ content: processedContent,
825
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
826
+ },
827
+ indexes: {
828
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
829
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
830
+ }
831
+ });
832
+ }
833
+
834
+ // ../core/reducer/actions/set.ts
835
+ var setAction = (state, action, appStore) => {
836
+ if (typeof action.state === "object") {
837
+ const newState = __spreadValues(__spreadValues({}, state), action.state);
838
+ if (action.state.indexes) {
839
+ return newState;
840
+ }
841
+ console.warn(
842
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
843
+ );
844
+ return walkAppState(newState, appStore.config);
845
+ }
846
+ return __spreadValues(__spreadValues({}, state), action.state(state));
847
+ };
848
+
849
+ // ../core/reducer/actions/insert.ts
850
+ init_react_import();
851
+
852
+ // ../core/lib/data/insert.ts
853
+ init_react_import();
854
+ var insert = (list, index, item) => {
855
+ const result = Array.from(list || []);
856
+ result.splice(index, 0, item);
857
+ return result;
858
+ };
859
+
860
+ // ../core/lib/generate-id.ts
861
+ init_react_import();
862
+
863
+ // ../core/node_modules/uuid/dist/esm-node/index.js
864
+ init_react_import();
865
+
866
+ // ../core/node_modules/uuid/dist/esm-node/rng.js
867
+ init_react_import();
868
+ import crypto from "crypto";
869
+ var rnds8Pool = new Uint8Array(256);
870
+ var poolPtr = rnds8Pool.length;
871
+ function rng() {
872
+ if (poolPtr > rnds8Pool.length - 16) {
873
+ crypto.randomFillSync(rnds8Pool);
874
+ poolPtr = 0;
875
+ }
876
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
877
+ }
878
+
879
+ // ../core/node_modules/uuid/dist/esm-node/stringify.js
880
+ init_react_import();
881
+ var byteToHex = [];
882
+ for (let i = 0; i < 256; ++i) {
883
+ byteToHex.push((i + 256).toString(16).slice(1));
884
+ }
885
+ function unsafeStringify(arr, offset = 0) {
886
+ 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]];
887
+ }
888
+
889
+ // ../core/node_modules/uuid/dist/esm-node/v4.js
890
+ init_react_import();
891
+
892
+ // ../core/node_modules/uuid/dist/esm-node/native.js
893
+ init_react_import();
894
+ import crypto2 from "crypto";
895
+ var native_default = {
896
+ randomUUID: crypto2.randomUUID
897
+ };
898
+
899
+ // ../core/node_modules/uuid/dist/esm-node/v4.js
900
+ function v4(options, buf, offset) {
901
+ if (native_default.randomUUID && !buf && !options) {
902
+ return native_default.randomUUID();
903
+ }
904
+ options = options || {};
905
+ const rnds = options.random || (options.rng || rng)();
906
+ rnds[6] = rnds[6] & 15 | 64;
907
+ rnds[8] = rnds[8] & 63 | 128;
908
+ if (buf) {
909
+ offset = offset || 0;
910
+ for (let i = 0; i < 16; ++i) {
911
+ buf[offset + i] = rnds[i];
912
+ }
913
+ return buf;
914
+ }
915
+ return unsafeStringify(rnds);
916
+ }
917
+ var v4_default = v4;
918
+
919
+ // ../core/lib/generate-id.ts
920
+ var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
921
+
922
+ // ../core/lib/data/get-ids-for-parent.ts
923
+ init_react_import();
924
+ var getIdsForParent = (zoneCompound, state) => {
925
+ const [parentId] = zoneCompound.split(":");
926
+ const node = state.indexes.nodes[parentId];
927
+ return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
928
+ };
929
+
930
+ // ../core/lib/data/populate-ids.ts
931
+ init_react_import();
932
+
933
+ // ../core/lib/data/walk-tree.ts
934
+ init_react_import();
935
+ function walkTree(data, config, callbackFn) {
936
+ var _a, _b;
937
+ const walkItem = (item) => {
938
+ return mapFields(
939
+ item,
940
+ {
941
+ slot: ({ value, parentId, propName }) => {
942
+ var _a2;
943
+ const content = value;
944
+ return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
945
+ }
946
+ },
947
+ config,
948
+ true
949
+ );
950
+ };
951
+ if ("props" in data) {
952
+ return walkItem(data);
953
+ }
954
+ const _data = data;
955
+ const zones = (_a = _data.zones) != null ? _a : {};
956
+ const mappedContent = _data.content.map(walkItem);
957
+ return {
958
+ root: walkItem(_data.root),
959
+ content: (_b = callbackFn(mappedContent, {
960
+ parentId: "root",
961
+ propName: "default-zone"
962
+ })) != null ? _b : mappedContent,
963
+ zones: Object.keys(zones).reduce(
964
+ (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
965
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
966
+ }),
967
+ {}
968
+ )
969
+ };
970
+ }
971
+
972
+ // ../core/lib/data/populate-ids.ts
973
+ var populateIds = (data, config, override = false) => {
974
+ const id = generateId(data.type);
975
+ return walkTree(
976
+ __spreadProps(__spreadValues({}, data), {
977
+ props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({}, data.props)
978
+ }),
979
+ config,
980
+ (contents) => contents.map((item) => {
981
+ const id2 = generateId(item.type);
982
+ return __spreadProps(__spreadValues({}, item), {
983
+ props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
984
+ });
985
+ })
986
+ );
987
+ };
988
+
989
+ // ../core/reducer/actions/insert.ts
990
+ function insertAction(state, action, appStore) {
991
+ const id = action.id || generateId(action.componentType);
992
+ const emptyComponentData = populateIds(
993
+ {
994
+ type: action.componentType,
995
+ props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
996
+ id
997
+ })
998
+ },
999
+ appStore.config
1000
+ );
1001
+ const [parentId] = action.destinationZone.split(":");
1002
+ const idsInPath = getIdsForParent(action.destinationZone, state);
1003
+ return walkAppState(
1004
+ state,
1005
+ appStore.config,
1006
+ (content, zoneCompound) => {
1007
+ if (zoneCompound === action.destinationZone) {
1008
+ return insert(
1009
+ content || [],
1010
+ action.destinationIndex,
1011
+ emptyComponentData
1012
+ );
1013
+ }
1014
+ return content;
1015
+ },
1016
+ (childItem, path) => {
1017
+ if (childItem.props.id === id || childItem.props.id === parentId) {
1018
+ return childItem;
1019
+ } else if (idsInPath.includes(childItem.props.id)) {
1020
+ return childItem;
1021
+ } else if (path.includes(action.destinationZone)) {
1022
+ return childItem;
1023
+ }
1024
+ return null;
1025
+ }
1026
+ );
1027
+ }
1028
+
1029
+ // ../core/reducer/actions/replace.ts
1030
+ init_react_import();
1031
+ var replaceAction = (state, action, appStore) => {
1032
+ const [parentId] = action.destinationZone.split(":");
1033
+ const idsInPath = getIdsForParent(action.destinationZone, state);
1034
+ const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
1035
+ const idChanged = originalId !== action.data.props.id;
1036
+ if (idChanged) {
1037
+ throw new Error(
1038
+ `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
1039
+ );
1040
+ }
1041
+ const newSlotIds = [];
1042
+ const data = walkTree(action.data, appStore.config, (contents, opts) => {
1043
+ newSlotIds.push(`${opts.parentId}:${opts.propName}`);
1044
+ return contents.map((item) => {
1045
+ const id = generateId(item.type);
1046
+ return __spreadProps(__spreadValues({}, item), {
1047
+ props: __spreadValues({ id }, item.props)
1048
+ });
1049
+ });
1050
+ });
1051
+ const stateWithDeepSlotsRemoved = __spreadProps(__spreadValues({}, state), {
1052
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1053
+ });
1054
+ Object.keys(state.indexes.zones).forEach((zoneCompound) => {
1055
+ const id = zoneCompound.split(":")[0];
1056
+ if (id === originalId) {
1057
+ if (!newSlotIds.includes(zoneCompound)) {
1058
+ delete stateWithDeepSlotsRemoved.indexes.zones[zoneCompound];
1059
+ }
1060
+ }
1061
+ });
1062
+ return walkAppState(
1063
+ stateWithDeepSlotsRemoved,
1064
+ appStore.config,
1065
+ (content, zoneCompound) => {
1066
+ const newContent = [...content];
1067
+ if (zoneCompound === action.destinationZone) {
1068
+ newContent[action.destinationIndex] = data;
1069
+ }
1070
+ return newContent;
1071
+ },
1072
+ (childItem, path) => {
1073
+ const pathIds = path.map((p) => p.split(":")[0]);
1074
+ if (childItem.props.id === data.props.id) {
1075
+ return data;
1076
+ } else if (childItem.props.id === parentId) {
1077
+ return childItem;
1078
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
1079
+ return childItem;
1080
+ } else if (pathIds.indexOf(data.props.id) > -1) {
1081
+ return childItem;
1082
+ }
1083
+ return null;
1084
+ }
1085
+ );
1086
+ };
1087
+
1088
+ // ../core/reducer/actions/replace-root.ts
1089
+ init_react_import();
1090
+ var replaceRootAction = (state, action, appStore) => {
1091
+ return walkAppState(
1092
+ state,
1093
+ appStore.config,
1094
+ (content) => content,
1095
+ (childItem) => {
1096
+ if (childItem.props.id === "root") {
1097
+ return __spreadProps(__spreadValues({}, childItem), {
1098
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
1099
+ readOnly: action.root.readOnly
1100
+ });
1101
+ }
1102
+ return childItem;
1103
+ }
1104
+ );
1105
+ };
1106
+
1107
+ // ../core/reducer/actions/duplicate.ts
1108
+ init_react_import();
1109
+
1110
+ // ../core/lib/data/get-item.ts
1111
+ init_react_import();
1112
+ function getItem(selector, state) {
1113
+ var _a, _b;
1114
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
1115
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
1116
+ }
1117
+
1118
+ // ../core/reducer/actions/duplicate.ts
1119
+ function duplicateAction(state, action, appStore) {
1120
+ const item = getItem(
1121
+ { index: action.sourceIndex, zone: action.sourceZone },
1122
+ state
1123
+ );
1124
+ const idsInPath = getIdsForParent(action.sourceZone, state);
1125
+ const newItem = __spreadProps(__spreadValues({}, item), {
1126
+ props: __spreadProps(__spreadValues({}, item.props), {
1127
+ id: generateId(item.type)
1128
+ })
1129
+ });
1130
+ const modified = walkAppState(
1131
+ state,
1132
+ appStore.config,
1133
+ (content, zoneCompound) => {
1134
+ if (zoneCompound === action.sourceZone) {
1135
+ return insert(content, action.sourceIndex + 1, item);
1136
+ }
1137
+ return content;
1138
+ },
1139
+ (childItem, path, index) => {
1140
+ const zoneCompound = path[path.length - 1];
1141
+ const parents = path.map((p) => p.split(":")[0]);
1142
+ if (parents.indexOf(newItem.props.id) > -1) {
1143
+ return __spreadProps(__spreadValues({}, childItem), {
1144
+ props: __spreadProps(__spreadValues({}, childItem.props), {
1145
+ id: generateId(childItem.type)
1146
+ })
1147
+ });
1148
+ }
1149
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
1150
+ return newItem;
1151
+ }
1152
+ const [sourceZoneParent] = action.sourceZone.split(":");
1153
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
1154
+ return childItem;
1155
+ }
1156
+ return null;
1157
+ }
1158
+ );
1159
+ return __spreadProps(__spreadValues({}, modified), {
1160
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
1161
+ itemSelector: {
1162
+ index: action.sourceIndex + 1,
1163
+ zone: action.sourceZone
1164
+ }
1165
+ })
1166
+ });
1167
+ }
1168
+
1169
+ // ../core/reducer/actions/reorder.ts
1170
+ init_react_import();
1171
+
1172
+ // ../core/reducer/actions/move.ts
1173
+ init_react_import();
1174
+
1175
+ // ../core/lib/data/remove.ts
1176
+ init_react_import();
1177
+ var remove = (list, index) => {
1178
+ const result = Array.from(list);
1179
+ result.splice(index, 1);
1180
+ return result;
1181
+ };
1182
+
1183
+ // ../core/reducer/actions/move.ts
1184
+ var moveAction = (state, action, appStore) => {
1185
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
1186
+ return state;
1187
+ }
1188
+ const item = getItem(
1189
+ { zone: action.sourceZone, index: action.sourceIndex },
1190
+ state
1191
+ );
1192
+ if (!item) return state;
1193
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
1194
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
1195
+ return walkAppState(
1196
+ state,
1197
+ appStore.config,
1198
+ (content, zoneCompound) => {
1199
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
1200
+ return insert(
1201
+ remove(content, action.sourceIndex),
1202
+ action.destinationIndex,
1203
+ item
1204
+ );
1205
+ } else if (zoneCompound === action.sourceZone) {
1206
+ return remove(content, action.sourceIndex);
1207
+ } else if (zoneCompound === action.destinationZone) {
1208
+ return insert(content, action.destinationIndex, item);
1209
+ }
1210
+ return content;
1211
+ },
1212
+ (childItem, path) => {
1213
+ const [sourceZoneParent] = action.sourceZone.split(":");
1214
+ const [destinationZoneParent] = action.destinationZone.split(":");
1215
+ const childId = childItem.props.id;
1216
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
1217
+ return childItem;
1218
+ }
1219
+ return null;
1220
+ }
1221
+ );
1222
+ };
1223
+
1224
+ // ../core/reducer/actions/reorder.ts
1225
+ var reorderAction = (state, action, appStore) => {
1226
+ return moveAction(
1227
+ state,
1228
+ {
1229
+ type: "move",
1230
+ sourceIndex: action.sourceIndex,
1231
+ sourceZone: action.destinationZone,
1232
+ destinationIndex: action.destinationIndex,
1233
+ destinationZone: action.destinationZone
1234
+ },
1235
+ appStore
1236
+ );
1237
+ };
1238
+
1239
+ // ../core/reducer/actions/remove.ts
1240
+ init_react_import();
1241
+ var removeAction = (state, action, appStore) => {
1242
+ const item = getItem({ index: action.index, zone: action.zone }, state);
1243
+ const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
1244
+ (acc, [nodeId, nodeData]) => {
1245
+ const pathIds = nodeData.path.map((p) => p.split(":")[0]);
1246
+ if (pathIds.includes(item.props.id)) {
1247
+ return [...acc, nodeId];
1248
+ }
1249
+ return acc;
1250
+ },
1251
+ [item.props.id]
1252
+ );
1253
+ const newState = walkAppState(
1254
+ state,
1255
+ appStore.config,
1256
+ (content, zoneCompound) => {
1257
+ if (zoneCompound === action.zone) {
1258
+ return remove(content, action.index);
1259
+ }
1260
+ return content;
1261
+ }
1262
+ );
1263
+ Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
1264
+ const parentId = zoneCompound.split(":")[0];
1265
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
1266
+ delete newState.data.zones[zoneCompound];
1267
+ }
1268
+ });
1269
+ Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
1270
+ const parentId = zoneCompound.split(":")[0];
1271
+ if (nodesToDelete.includes(parentId)) {
1272
+ delete newState.indexes.zones[zoneCompound];
1273
+ }
1274
+ });
1275
+ nodesToDelete.forEach((id) => {
1276
+ delete newState.indexes.nodes[id];
1277
+ });
1278
+ return newState;
1279
+ };
1280
+
1281
+ // ../core/reducer/actions/register-zone.ts
1282
+ init_react_import();
1283
+
1284
+ // ../core/lib/data/setup-zone.ts
1285
+ init_react_import();
1286
+ var setupZone = (data, zoneKey) => {
1287
+ if (zoneKey === rootDroppableId) {
1288
+ return data;
1289
+ }
1290
+ const newData = __spreadProps(__spreadValues({}, data), {
1291
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
1292
+ });
1293
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
1294
+ return newData;
1295
+ };
1296
+
1297
+ // ../core/reducer/actions/register-zone.ts
1298
+ var zoneCache = {};
1299
+ function registerZoneAction(state, action) {
1300
+ if (zoneCache[action.zone]) {
1301
+ return __spreadProps(__spreadValues({}, state), {
1302
+ data: __spreadProps(__spreadValues({}, state.data), {
1303
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
1304
+ [action.zone]: zoneCache[action.zone]
1305
+ })
1306
+ }),
1307
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1308
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
1309
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
1310
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
1311
+ type: "dropzone"
1312
+ })
1313
+ })
1314
+ })
1315
+ });
1316
+ }
1317
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1318
+ }
1319
+ function unregisterZoneAction(state, action) {
1320
+ const _zones = __spreadValues({}, state.data.zones || {});
1321
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
1322
+ if (_zones[action.zone]) {
1323
+ zoneCache[action.zone] = _zones[action.zone];
1324
+ delete _zones[action.zone];
1325
+ }
1326
+ delete zoneIndex[action.zone];
1327
+ return __spreadProps(__spreadValues({}, state), {
1328
+ data: __spreadProps(__spreadValues({}, state.data), {
1329
+ zones: _zones
1330
+ }),
1331
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1332
+ zones: zoneIndex
1333
+ })
1334
+ });
1335
+ }
1336
+
1337
+ // ../core/reducer/actions/set-data.ts
1338
+ init_react_import();
1339
+ var setDataAction = (state, action, appStore) => {
1340
+ if (typeof action.data === "object") {
1341
+ console.warn(
1342
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1343
+ );
1344
+ return walkAppState(
1345
+ __spreadProps(__spreadValues({}, state), {
1346
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
1347
+ }),
1348
+ appStore.config
1349
+ );
1350
+ }
1351
+ return walkAppState(
1352
+ __spreadProps(__spreadValues({}, state), {
1353
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1354
+ }),
1355
+ appStore.config
1356
+ );
1357
+ };
1358
+
1359
+ // ../core/reducer/actions/set-ui.ts
1360
+ init_react_import();
1361
+ var setUiAction = (state, action) => {
1362
+ if (typeof action.ui === "object") {
1363
+ return __spreadProps(__spreadValues({}, state), {
1364
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1365
+ });
1366
+ }
1367
+ return __spreadProps(__spreadValues({}, state), {
1368
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1369
+ });
1370
+ };
1371
+
1372
+ // ../core/lib/data/make-state-public.ts
1373
+ init_react_import();
1374
+ var makeStatePublic = (state) => {
1375
+ const { data, ui } = state;
1376
+ return { data, ui };
1377
+ };
1378
+
1379
+ // ../core/reducer/actions.tsx
1380
+ init_react_import();
1381
+
1382
+ // ../core/reducer/index.ts
1383
+ function storeInterceptor(reducer, record, onAction) {
1384
+ return (state, action) => {
1385
+ const newAppState = reducer(state, action);
1386
+ const isValidType = ![
1387
+ "registerZone",
1388
+ "unregisterZone",
1389
+ "setData",
1390
+ "setUi",
1391
+ "set"
1392
+ ].includes(action.type);
1393
+ if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1394
+ if (record) record(newAppState);
1395
+ }
1396
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1397
+ return newAppState;
1398
+ };
1399
+ }
1400
+ function createReducer({
1401
+ record,
1402
+ onAction,
1403
+ appStore
1404
+ }) {
1405
+ return storeInterceptor(
1406
+ (state, action) => {
1407
+ if (action.type === "set") {
1408
+ return setAction(state, action, appStore);
1409
+ }
1410
+ if (action.type === "insert") {
1411
+ return insertAction(state, action, appStore);
1412
+ }
1413
+ if (action.type === "replace") {
1414
+ return replaceAction(state, action, appStore);
1415
+ }
1416
+ if (action.type === "replaceRoot") {
1417
+ return replaceRootAction(state, action, appStore);
1418
+ }
1419
+ if (action.type === "duplicate") {
1420
+ return duplicateAction(state, action, appStore);
1421
+ }
1422
+ if (action.type === "reorder") {
1423
+ return reorderAction(state, action, appStore);
1424
+ }
1425
+ if (action.type === "move") {
1426
+ return moveAction(state, action, appStore);
1427
+ }
1428
+ if (action.type === "remove") {
1429
+ return removeAction(state, action, appStore);
1430
+ }
1431
+ if (action.type === "registerZone") {
1432
+ return registerZoneAction(state, action);
1433
+ }
1434
+ if (action.type === "unregisterZone") {
1435
+ return unregisterZoneAction(state, action);
1436
+ }
1437
+ if (action.type === "setData") {
1438
+ return setDataAction(state, action, appStore);
1439
+ }
1440
+ if (action.type === "setUi") {
1441
+ return setUiAction(state, action);
1442
+ }
1443
+ return state;
1444
+ },
1445
+ record,
1446
+ onAction
1447
+ );
1448
+ }
1449
+
1450
+ // ../core/components/ViewportControls/default-viewports.ts
1451
+ init_react_import();
1452
+ var defaultViewports = [
1453
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1454
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1455
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" },
1456
+ { width: "100%", height: "auto", icon: "FullWidth", label: "Full-width" }
1457
+ ];
1458
+
1459
+ // ../../node_modules/zustand/esm/vanilla.mjs
1460
+ init_react_import();
1461
+ var createStoreImpl = (createState) => {
1462
+ let state;
1463
+ const listeners = /* @__PURE__ */ new Set();
1464
+ const setState = (partial, replace) => {
1465
+ const nextState = typeof partial === "function" ? partial(state) : partial;
1466
+ if (!Object.is(nextState, state)) {
1467
+ const previousState = state;
1468
+ state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
1469
+ listeners.forEach((listener) => listener(state, previousState));
1470
+ }
1471
+ };
1472
+ const getState = () => state;
1473
+ const getInitialState = () => initialState;
1474
+ const subscribe = (listener) => {
1475
+ listeners.add(listener);
1476
+ return () => listeners.delete(listener);
1477
+ };
1478
+ const api = { setState, getState, getInitialState, subscribe };
1479
+ const initialState = state = createState(setState, getState, api);
1480
+ return api;
1481
+ };
1482
+ var createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
1483
+
1484
+ // ../../node_modules/zustand/esm/react.mjs
1485
+ init_react_import();
1486
+ import React2 from "react";
1487
+ var identity = (arg) => arg;
1488
+ function useStore(api, selector = identity) {
1489
+ const slice = React2.useSyncExternalStore(
1490
+ api.subscribe,
1491
+ React2.useCallback(() => selector(api.getState()), [api, selector]),
1492
+ React2.useCallback(() => selector(api.getInitialState()), [api, selector])
1493
+ );
1494
+ React2.useDebugValue(slice);
1495
+ return slice;
1496
+ }
1497
+ var createImpl = (createState) => {
1498
+ const api = createStore(createState);
1499
+ const useBoundStore = (selector) => useStore(api, selector);
1500
+ Object.assign(useBoundStore, api);
1501
+ return useBoundStore;
1502
+ };
1503
+ var create = ((createState) => createState ? createImpl(createState) : createImpl);
1504
+
1505
+ // ../../node_modules/zustand/esm/middleware.mjs
1506
+ init_react_import();
1507
+ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1508
+ const origSubscribe = api.subscribe;
1509
+ api.subscribe = ((selector, optListener, options) => {
1510
+ let listener = selector;
1511
+ if (optListener) {
1512
+ const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
1513
+ let currentSlice = selector(api.getState());
1514
+ listener = (state) => {
1515
+ const nextSlice = selector(state);
1516
+ if (!equalityFn(currentSlice, nextSlice)) {
1517
+ const previousSlice = currentSlice;
1518
+ optListener(currentSlice = nextSlice, previousSlice);
1519
+ }
1520
+ };
1521
+ if (options == null ? void 0 : options.fireImmediately) {
1522
+ optListener(currentSlice, currentSlice);
1523
+ }
1524
+ }
1525
+ return origSubscribe(listener);
1526
+ });
1527
+ const initialState = fn(set, get, api);
1528
+ return initialState;
1529
+ };
1530
+ var subscribeWithSelector = subscribeWithSelectorImpl;
1531
+
1532
+ // ../core/store/index.ts
1533
+ import { createContext, useContext } from "react";
1534
+
1535
+ // ../core/store/slices/history.ts
1536
+ init_react_import();
1537
+ import { useEffect as useEffect2 } from "react";
1538
+
1539
+ // ../core/lib/use-hotkey.ts
1540
+ init_react_import();
1541
+ import { useEffect } from "react";
1542
+ var useHotkeyStore = create()(
1543
+ subscribeWithSelector((set) => ({
1544
+ held: {},
1545
+ hold: (key) => set((s) => s.held[key] ? s : { held: __spreadProps(__spreadValues({}, s.held), { [key]: true }) }),
1546
+ release: (key) => set((s) => s.held[key] ? { held: __spreadProps(__spreadValues({}, s.held), { [key]: false }) } : s),
1547
+ reset: (held = {}) => set(() => ({ held })),
1548
+ triggers: {}
1549
+ }))
1550
+ );
1551
+
1552
+ // ../core/store/slices/history.ts
1553
+ var EMPTY_HISTORY_INDEX = 0;
1554
+ function debounce(func, timeout = 300) {
1555
+ let timer;
1556
+ return (...args) => {
1557
+ clearTimeout(timer);
1558
+ timer = setTimeout(() => {
1559
+ func(...args);
1560
+ }, timeout);
1561
+ };
1562
+ }
1563
+ var tidyState = (state) => {
1564
+ return __spreadProps(__spreadValues({}, state), {
1565
+ ui: __spreadProps(__spreadValues({}, state.ui), {
1566
+ field: __spreadProps(__spreadValues({}, state.ui.field), {
1567
+ focus: null
1568
+ })
1569
+ })
1570
+ });
1571
+ };
1572
+ var createHistorySlice = (set, get) => {
1573
+ const record = debounce((state) => {
1574
+ const { histories, index } = get().history;
1575
+ const history = {
1576
+ state,
1577
+ id: generateId("history")
1578
+ };
1579
+ const newHistories = [...histories.slice(0, index + 1), history];
1580
+ set({
1581
+ history: __spreadProps(__spreadValues({}, get().history), {
1582
+ histories: newHistories,
1583
+ index: newHistories.length - 1
1584
+ })
1585
+ });
1586
+ }, 250);
1587
+ return {
1588
+ initialAppState: {},
1589
+ index: EMPTY_HISTORY_INDEX,
1590
+ histories: [],
1591
+ hasPast: () => get().history.index > EMPTY_HISTORY_INDEX,
1592
+ hasFuture: () => get().history.index < get().history.histories.length - 1,
1593
+ prevHistory: () => {
1594
+ const { history } = get();
1595
+ return history.hasPast() ? history.histories[history.index - 1] : null;
1596
+ },
1597
+ nextHistory: () => {
1598
+ const s = get().history;
1599
+ return s.hasFuture() ? s.histories[s.index + 1] : null;
1600
+ },
1601
+ currentHistory: () => get().history.histories[get().history.index],
1602
+ back: () => {
1603
+ var _a;
1604
+ const { history, dispatch } = get();
1605
+ if (history.hasPast()) {
1606
+ const state = tidyState(
1607
+ ((_a = history.prevHistory()) == null ? void 0 : _a.state) || history.initialAppState
1608
+ );
1609
+ dispatch({
1610
+ type: "set",
1611
+ state
1612
+ });
1613
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index - 1 }) });
1614
+ }
1615
+ },
1616
+ forward: () => {
1617
+ var _a;
1618
+ const { history, dispatch } = get();
1619
+ if (history.hasFuture()) {
1620
+ const state = (_a = history.nextHistory()) == null ? void 0 : _a.state;
1621
+ dispatch({ type: "set", state: state ? tidyState(state) : {} });
1622
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index + 1 }) });
1623
+ }
1624
+ },
1625
+ setHistories: (histories) => {
1626
+ var _a;
1627
+ const { dispatch, history } = get();
1628
+ dispatch({
1629
+ type: "set",
1630
+ state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
1631
+ });
1632
+ set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
1633
+ },
1634
+ setHistoryIndex: (index) => {
1635
+ var _a;
1636
+ const { dispatch, history } = get();
1637
+ dispatch({
1638
+ type: "set",
1639
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1640
+ });
1641
+ set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1642
+ },
1643
+ record
1644
+ };
1645
+ };
1646
+
1647
+ // ../core/store/slices/nodes.ts
1648
+ init_react_import();
1649
+ var createNodesSlice = (set, get) => ({
1650
+ nodes: {},
1651
+ registerNode: (id, node) => {
1652
+ const s = get().nodes;
1653
+ const emptyNode = {
1654
+ id,
1655
+ methods: {
1656
+ sync: () => null,
1657
+ hideOverlay: () => null,
1658
+ showOverlay: () => null
1659
+ },
1660
+ element: null
1661
+ };
1662
+ const existingNode = s.nodes[id];
1663
+ set({
1664
+ nodes: __spreadProps(__spreadValues({}, s), {
1665
+ nodes: __spreadProps(__spreadValues({}, s.nodes), {
1666
+ [id]: __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, emptyNode), existingNode), node), {
1667
+ id
1668
+ })
1669
+ })
1670
+ })
1671
+ });
1672
+ },
1673
+ unregisterNode: (id) => {
1674
+ const s = get().nodes;
1675
+ const existingNode = s.nodes[id];
1676
+ if (existingNode) {
1677
+ const newNodes = __spreadValues({}, s.nodes);
1678
+ delete newNodes[id];
1679
+ set({
1680
+ nodes: __spreadProps(__spreadValues({}, s), {
1681
+ nodes: newNodes
1682
+ })
1683
+ });
1684
+ }
1685
+ }
1686
+ });
1687
+
1688
+ // ../core/store/slices/permissions.ts
1689
+ init_react_import();
1690
+ import { useEffect as useEffect3 } from "react";
1691
+
1692
+ // ../core/lib/data/flatten-data.ts
1693
+ init_react_import();
1694
+ var flattenData = (state, config) => {
1695
+ const data = [];
1696
+ walkAppState(
1697
+ state,
1698
+ config,
1699
+ (content) => content,
1700
+ (item) => {
1701
+ data.push(item);
1702
+ return item;
1703
+ }
1704
+ );
1705
+ return data;
1706
+ };
1707
+
1708
+ // ../core/lib/get-changed.ts
1709
+ init_react_import();
1710
+
1711
+ // ../../node_modules/fast-equals/dist/esm/index.mjs
1712
+ init_react_import();
1713
+ var getOwnPropertyNames = Object.getOwnPropertyNames;
1714
+ var getOwnPropertySymbols = Object.getOwnPropertySymbols;
1715
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
1716
+ function combineComparators(comparatorA, comparatorB) {
1717
+ return function isEqual(a, b, state) {
1718
+ return comparatorA(a, b, state) && comparatorB(a, b, state);
1719
+ };
1720
+ }
1721
+ function createIsCircular(areItemsEqual) {
1722
+ return function isCircular(a, b, state) {
1723
+ if (!a || !b || typeof a !== "object" || typeof b !== "object") {
1724
+ return areItemsEqual(a, b, state);
1725
+ }
1726
+ var cache2 = state.cache;
1727
+ var cachedA = cache2.get(a);
1728
+ var cachedB = cache2.get(b);
1729
+ if (cachedA && cachedB) {
1730
+ return cachedA === b && cachedB === a;
1731
+ }
1732
+ cache2.set(a, b);
1733
+ cache2.set(b, a);
1734
+ var result = areItemsEqual(a, b, state);
1735
+ cache2.delete(a);
1736
+ cache2.delete(b);
1737
+ return result;
1738
+ };
1739
+ }
1740
+ function getStrictProperties(object) {
1741
+ return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object));
1742
+ }
1743
+ var hasOwn = Object.hasOwn || (function(object, property) {
1744
+ return hasOwnProperty.call(object, property);
1745
+ });
1746
+ function sameValueZeroEqual(a, b) {
1747
+ return a === b || !a && !b && a !== a && b !== b;
1748
+ }
1749
+ var PREACT_VNODE = "__v";
1750
+ var PREACT_OWNER = "__o";
1751
+ var REACT_OWNER = "_owner";
1752
+ var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
1753
+ var keys = Object.keys;
1754
+ function areArraysEqual(a, b, state) {
1755
+ var index = a.length;
1756
+ if (b.length !== index) {
1757
+ return false;
1758
+ }
1759
+ while (index-- > 0) {
1760
+ if (!state.equals(a[index], b[index], index, index, a, b, state)) {
1761
+ return false;
1762
+ }
1763
+ }
1764
+ return true;
1765
+ }
1766
+ function areDatesEqual(a, b) {
1767
+ return sameValueZeroEqual(a.getTime(), b.getTime());
1768
+ }
1769
+ function areErrorsEqual(a, b) {
1770
+ return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
1771
+ }
1772
+ function areFunctionsEqual(a, b) {
1773
+ return a === b;
1774
+ }
1775
+ function areMapsEqual(a, b, state) {
1776
+ var size = a.size;
1777
+ if (size !== b.size) {
1778
+ return false;
1779
+ }
1780
+ if (!size) {
1781
+ return true;
1782
+ }
1783
+ var matchedIndices = new Array(size);
1784
+ var aIterable = a.entries();
1785
+ var aResult;
1786
+ var bResult;
1787
+ var index = 0;
1788
+ while (aResult = aIterable.next()) {
1789
+ if (aResult.done) {
1790
+ break;
1791
+ }
1792
+ var bIterable = b.entries();
1793
+ var hasMatch = false;
1794
+ var matchIndex = 0;
1795
+ while (bResult = bIterable.next()) {
1796
+ if (bResult.done) {
1797
+ break;
1798
+ }
1799
+ if (matchedIndices[matchIndex]) {
1800
+ matchIndex++;
1801
+ continue;
1802
+ }
1803
+ var aEntry = aResult.value;
1804
+ var bEntry = bResult.value;
1805
+ if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state) && state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
1806
+ hasMatch = matchedIndices[matchIndex] = true;
1807
+ break;
1808
+ }
1809
+ matchIndex++;
1810
+ }
1811
+ if (!hasMatch) {
1812
+ return false;
1813
+ }
1814
+ index++;
1815
+ }
1816
+ return true;
1817
+ }
1818
+ var areNumbersEqual = sameValueZeroEqual;
1819
+ function areObjectsEqual(a, b, state) {
1820
+ var properties = keys(a);
1821
+ var index = properties.length;
1822
+ if (keys(b).length !== index) {
1823
+ return false;
1824
+ }
1825
+ while (index-- > 0) {
1826
+ if (!isPropertyEqual(a, b, state, properties[index])) {
1827
+ return false;
1828
+ }
1829
+ }
1830
+ return true;
1831
+ }
1832
+ function areObjectsEqualStrict(a, b, state) {
1833
+ var properties = getStrictProperties(a);
1834
+ var index = properties.length;
1835
+ if (getStrictProperties(b).length !== index) {
1836
+ return false;
1837
+ }
1838
+ var property;
1839
+ var descriptorA;
1840
+ var descriptorB;
1841
+ while (index-- > 0) {
1842
+ property = properties[index];
1843
+ if (!isPropertyEqual(a, b, state, property)) {
1844
+ return false;
1845
+ }
1846
+ descriptorA = getOwnPropertyDescriptor(a, property);
1847
+ descriptorB = getOwnPropertyDescriptor(b, property);
1848
+ if ((descriptorA || descriptorB) && (!descriptorA || !descriptorB || descriptorA.configurable !== descriptorB.configurable || descriptorA.enumerable !== descriptorB.enumerable || descriptorA.writable !== descriptorB.writable)) {
1849
+ return false;
1850
+ }
1851
+ }
1852
+ return true;
1853
+ }
1854
+ function arePrimitiveWrappersEqual(a, b) {
1855
+ return sameValueZeroEqual(a.valueOf(), b.valueOf());
1856
+ }
1857
+ function areRegExpsEqual(a, b) {
1858
+ return a.source === b.source && a.flags === b.flags;
1859
+ }
1860
+ function areSetsEqual(a, b, state) {
1861
+ var size = a.size;
1862
+ if (size !== b.size) {
1863
+ return false;
1864
+ }
1865
+ if (!size) {
1866
+ return true;
1867
+ }
1868
+ var matchedIndices = new Array(size);
1869
+ var aIterable = a.values();
1870
+ var aResult;
1871
+ var bResult;
1872
+ while (aResult = aIterable.next()) {
1873
+ if (aResult.done) {
1874
+ break;
1875
+ }
1876
+ var bIterable = b.values();
1877
+ var hasMatch = false;
1878
+ var matchIndex = 0;
1879
+ while (bResult = bIterable.next()) {
1880
+ if (bResult.done) {
1881
+ break;
1882
+ }
1883
+ if (!matchedIndices[matchIndex] && state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
1884
+ hasMatch = matchedIndices[matchIndex] = true;
1885
+ break;
1886
+ }
1887
+ matchIndex++;
1888
+ }
1889
+ if (!hasMatch) {
1890
+ return false;
1891
+ }
1892
+ }
1893
+ return true;
1894
+ }
1895
+ function areTypedArraysEqual(a, b) {
1896
+ var index = a.length;
1897
+ if (b.length !== index) {
1898
+ return false;
1899
+ }
1900
+ while (index-- > 0) {
1901
+ if (a[index] !== b[index]) {
1902
+ return false;
1903
+ }
1904
+ }
1905
+ return true;
1906
+ }
1907
+ function areUrlsEqual(a, b) {
1908
+ return a.hostname === b.hostname && a.pathname === b.pathname && a.protocol === b.protocol && a.port === b.port && a.hash === b.hash && a.username === b.username && a.password === b.password;
1909
+ }
1910
+ function isPropertyEqual(a, b, state, property) {
1911
+ if ((property === REACT_OWNER || property === PREACT_OWNER || property === PREACT_VNODE) && (a.$$typeof || b.$$typeof)) {
1912
+ return true;
1913
+ }
1914
+ return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
1915
+ }
1916
+ var ARGUMENTS_TAG = "[object Arguments]";
1917
+ var BOOLEAN_TAG = "[object Boolean]";
1918
+ var DATE_TAG = "[object Date]";
1919
+ var ERROR_TAG = "[object Error]";
1920
+ var MAP_TAG = "[object Map]";
1921
+ var NUMBER_TAG = "[object Number]";
1922
+ var OBJECT_TAG = "[object Object]";
1923
+ var REG_EXP_TAG = "[object RegExp]";
1924
+ var SET_TAG = "[object Set]";
1925
+ var STRING_TAG = "[object String]";
1926
+ var URL_TAG = "[object URL]";
1927
+ var isArray = Array.isArray;
1928
+ var isTypedArray = typeof ArrayBuffer === "function" && ArrayBuffer.isView ? ArrayBuffer.isView : null;
1929
+ var assign = Object.assign;
1930
+ var getTag = Object.prototype.toString.call.bind(Object.prototype.toString);
1931
+ function createEqualityComparator(_a) {
1932
+ var areArraysEqual2 = _a.areArraysEqual, areDatesEqual2 = _a.areDatesEqual, areErrorsEqual2 = _a.areErrorsEqual, areFunctionsEqual2 = _a.areFunctionsEqual, areMapsEqual2 = _a.areMapsEqual, areNumbersEqual2 = _a.areNumbersEqual, areObjectsEqual2 = _a.areObjectsEqual, arePrimitiveWrappersEqual2 = _a.arePrimitiveWrappersEqual, areRegExpsEqual2 = _a.areRegExpsEqual, areSetsEqual2 = _a.areSetsEqual, areTypedArraysEqual2 = _a.areTypedArraysEqual, areUrlsEqual2 = _a.areUrlsEqual;
1933
+ return function comparator(a, b, state) {
1934
+ if (a === b) {
1935
+ return true;
1936
+ }
1937
+ if (a == null || b == null) {
1938
+ return false;
1939
+ }
1940
+ var type = typeof a;
1941
+ if (type !== typeof b) {
1942
+ return false;
1943
+ }
1944
+ if (type !== "object") {
1945
+ if (type === "number") {
1946
+ return areNumbersEqual2(a, b, state);
1947
+ }
1948
+ if (type === "function") {
1949
+ return areFunctionsEqual2(a, b, state);
1950
+ }
1951
+ return false;
1952
+ }
1953
+ var constructor = a.constructor;
1954
+ if (constructor !== b.constructor) {
1955
+ return false;
1956
+ }
1957
+ if (constructor === Object) {
1958
+ return areObjectsEqual2(a, b, state);
1959
+ }
1960
+ if (isArray(a)) {
1961
+ return areArraysEqual2(a, b, state);
1962
+ }
1963
+ if (isTypedArray != null && isTypedArray(a)) {
1964
+ return areTypedArraysEqual2(a, b, state);
1965
+ }
1966
+ if (constructor === Date) {
1967
+ return areDatesEqual2(a, b, state);
1968
+ }
1969
+ if (constructor === RegExp) {
1970
+ return areRegExpsEqual2(a, b, state);
1971
+ }
1972
+ if (constructor === Map) {
1973
+ return areMapsEqual2(a, b, state);
1974
+ }
1975
+ if (constructor === Set) {
1976
+ return areSetsEqual2(a, b, state);
1977
+ }
1978
+ var tag = getTag(a);
1979
+ if (tag === DATE_TAG) {
1980
+ return areDatesEqual2(a, b, state);
1981
+ }
1982
+ if (tag === REG_EXP_TAG) {
1983
+ return areRegExpsEqual2(a, b, state);
1984
+ }
1985
+ if (tag === MAP_TAG) {
1986
+ return areMapsEqual2(a, b, state);
1987
+ }
1988
+ if (tag === SET_TAG) {
1989
+ return areSetsEqual2(a, b, state);
1990
+ }
1991
+ if (tag === OBJECT_TAG) {
1992
+ return typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual2(a, b, state);
1993
+ }
1994
+ if (tag === URL_TAG) {
1995
+ return areUrlsEqual2(a, b, state);
1996
+ }
1997
+ if (tag === ERROR_TAG) {
1998
+ return areErrorsEqual2(a, b, state);
1999
+ }
2000
+ if (tag === ARGUMENTS_TAG) {
2001
+ return areObjectsEqual2(a, b, state);
2002
+ }
2003
+ if (tag === BOOLEAN_TAG || tag === NUMBER_TAG || tag === STRING_TAG) {
2004
+ return arePrimitiveWrappersEqual2(a, b, state);
2005
+ }
2006
+ return false;
2007
+ };
2008
+ }
2009
+ function createEqualityComparatorConfig(_a) {
2010
+ var circular = _a.circular, createCustomConfig = _a.createCustomConfig, strict = _a.strict;
2011
+ var config = {
2012
+ areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
2013
+ areDatesEqual,
2014
+ areErrorsEqual,
2015
+ areFunctionsEqual,
2016
+ areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
2017
+ areNumbersEqual,
2018
+ areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
2019
+ arePrimitiveWrappersEqual,
2020
+ areRegExpsEqual,
2021
+ areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
2022
+ areTypedArraysEqual: strict ? areObjectsEqualStrict : areTypedArraysEqual,
2023
+ areUrlsEqual
2024
+ };
2025
+ if (createCustomConfig) {
2026
+ config = assign({}, config, createCustomConfig(config));
2027
+ }
2028
+ if (circular) {
2029
+ var areArraysEqual$1 = createIsCircular(config.areArraysEqual);
2030
+ var areMapsEqual$1 = createIsCircular(config.areMapsEqual);
2031
+ var areObjectsEqual$1 = createIsCircular(config.areObjectsEqual);
2032
+ var areSetsEqual$1 = createIsCircular(config.areSetsEqual);
2033
+ config = assign({}, config, {
2034
+ areArraysEqual: areArraysEqual$1,
2035
+ areMapsEqual: areMapsEqual$1,
2036
+ areObjectsEqual: areObjectsEqual$1,
2037
+ areSetsEqual: areSetsEqual$1
2038
+ });
2039
+ }
2040
+ return config;
2041
+ }
2042
+ function createInternalEqualityComparator(compare) {
2043
+ return function(a, b, _indexOrKeyA, _indexOrKeyB, _parentA, _parentB, state) {
2044
+ return compare(a, b, state);
2045
+ };
2046
+ }
2047
+ function createIsEqual(_a) {
2048
+ var circular = _a.circular, comparator = _a.comparator, createState = _a.createState, equals = _a.equals, strict = _a.strict;
2049
+ if (createState) {
2050
+ return function isEqual(a, b) {
2051
+ var _a2 = createState(), _b = _a2.cache, cache2 = _b === void 0 ? circular ? /* @__PURE__ */ new WeakMap() : void 0 : _b, meta = _a2.meta;
2052
+ return comparator(a, b, {
2053
+ cache: cache2,
2054
+ equals,
2055
+ meta,
2056
+ strict
2057
+ });
2058
+ };
2059
+ }
2060
+ if (circular) {
2061
+ return function isEqual(a, b) {
2062
+ return comparator(a, b, {
2063
+ cache: /* @__PURE__ */ new WeakMap(),
2064
+ equals,
2065
+ meta: void 0,
2066
+ strict
2067
+ });
2068
+ };
2069
+ }
2070
+ var state = {
2071
+ cache: void 0,
2072
+ equals,
2073
+ meta: void 0,
2074
+ strict
2075
+ };
2076
+ return function isEqual(a, b) {
2077
+ return comparator(a, b, state);
2078
+ };
2079
+ }
2080
+ var deepEqual = createCustomEqual();
2081
+ var strictDeepEqual = createCustomEqual({ strict: true });
2082
+ var circularDeepEqual = createCustomEqual({ circular: true });
2083
+ var strictCircularDeepEqual = createCustomEqual({
2084
+ circular: true,
2085
+ strict: true
2086
+ });
2087
+ var shallowEqual = createCustomEqual({
2088
+ createInternalComparator: function() {
2089
+ return sameValueZeroEqual;
2090
+ }
2091
+ });
2092
+ var strictShallowEqual = createCustomEqual({
2093
+ strict: true,
2094
+ createInternalComparator: function() {
2095
+ return sameValueZeroEqual;
2096
+ }
2097
+ });
2098
+ var circularShallowEqual = createCustomEqual({
2099
+ circular: true,
2100
+ createInternalComparator: function() {
2101
+ return sameValueZeroEqual;
2102
+ }
2103
+ });
2104
+ var strictCircularShallowEqual = createCustomEqual({
2105
+ circular: true,
2106
+ createInternalComparator: function() {
2107
+ return sameValueZeroEqual;
2108
+ },
2109
+ strict: true
2110
+ });
2111
+ function createCustomEqual(options) {
2112
+ if (options === void 0) {
2113
+ options = {};
2114
+ }
2115
+ var _a = options.circular, circular = _a === void 0 ? false : _a, createCustomInternalComparator = options.createInternalComparator, createState = options.createState, _b = options.strict, strict = _b === void 0 ? false : _b;
2116
+ var config = createEqualityComparatorConfig(options);
2117
+ var comparator = createEqualityComparator(config);
2118
+ var equals = createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator);
2119
+ return createIsEqual({ circular, comparator, createState, equals, strict });
2120
+ }
2121
+
2122
+ // ../core/lib/get-changed.ts
2123
+ var getChanged = (newItem, oldItem) => {
2124
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
2125
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
2126
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
2127
+ return __spreadProps(__spreadValues({}, acc), {
2128
+ [item]: !deepEqual(oldItemProps[item], newItemProps[item])
2129
+ });
2130
+ }, {}) : {};
2131
+ };
2132
+
2133
+ // ../core/store/slices/permissions.ts
2134
+ var createPermissionsSlice = (set, get) => {
2135
+ const resolvePermissions = (..._0) => __async(null, [..._0], function* (params = {}, force) {
2136
+ const { state, permissions, config } = get();
2137
+ const { cache: cache2, globalPermissions } = permissions;
2138
+ const resolvePermissionsForItem = (item2, force2 = false) => __async(null, null, function* () {
2139
+ var _a, _b;
2140
+ const { config: config2, state: appState, setComponentLoading } = get();
2141
+ const itemCache = cache2[item2.props.id];
2142
+ const nodes = appState.indexes.nodes;
2143
+ const parentId = (_a = nodes[item2.props.id]) == null ? void 0 : _a.parentId;
2144
+ const parentNode = parentId ? nodes[parentId] : null;
2145
+ const parentData = (_b = parentNode == null ? void 0 : parentNode.data) != null ? _b : null;
2146
+ const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
2147
+ if (!componentConfig) {
2148
+ return;
2149
+ }
2150
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
2151
+ if (componentConfig.resolvePermissions) {
2152
+ const changed = getChanged(item2, itemCache == null ? void 0 : itemCache.lastData);
2153
+ const propsChanged = Object.values(changed).some((el) => el === true);
2154
+ const parentChanged = (itemCache == null ? void 0 : itemCache.lastParentId) !== parentId;
2155
+ if (propsChanged || parentChanged || force2) {
2156
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
2157
+ const resolvedPermissions = yield componentConfig.resolvePermissions(
2158
+ item2,
2159
+ {
2160
+ changed,
2161
+ lastPermissions: (itemCache == null ? void 0 : itemCache.lastPermissions) || null,
2162
+ permissions: initialPermissions,
2163
+ appState: makeStatePublic(appState),
2164
+ lastData: (itemCache == null ? void 0 : itemCache.lastData) || null,
2165
+ parent: parentData
2166
+ }
2167
+ );
2168
+ const latest = get().permissions;
2169
+ set({
2170
+ permissions: __spreadProps(__spreadValues({}, latest), {
2171
+ cache: __spreadProps(__spreadValues({}, latest.cache), {
2172
+ [item2.props.id]: {
2173
+ lastParentId: parentId,
2174
+ lastData: item2,
2175
+ lastPermissions: resolvedPermissions
2176
+ }
2177
+ }),
2178
+ resolvedPermissions: __spreadProps(__spreadValues({}, latest.resolvedPermissions), {
2179
+ [item2.props.id]: resolvedPermissions
2180
+ })
2181
+ })
2182
+ });
2183
+ clearTimeout2();
2184
+ }
2185
+ }
2186
+ });
2187
+ const resolvePermissionsForRoot = (force2 = false) => {
2188
+ const { state: appState } = get();
2189
+ resolvePermissionsForItem(
2190
+ // Shim the root data in by conforming to component data shape
2191
+ {
2192
+ type: "root",
2193
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
2194
+ },
2195
+ force2
2196
+ );
2197
+ };
2198
+ const { item, type, root } = params;
2199
+ if (item) {
2200
+ yield resolvePermissionsForItem(item, force);
2201
+ } else if (type) {
2202
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(null, null, function* () {
2203
+ yield resolvePermissionsForItem(item2, force);
2204
+ }));
2205
+ } else if (root) {
2206
+ resolvePermissionsForRoot(force);
2207
+ } else {
2208
+ flattenData(state, config).map((item2) => __async(null, null, function* () {
2209
+ yield resolvePermissionsForItem(item2, force);
2210
+ }));
2211
+ }
2212
+ });
2213
+ const refreshPermissions = (params) => resolvePermissions(params, true);
2214
+ return {
2215
+ cache: {},
2216
+ globalPermissions: {
2217
+ drag: true,
2218
+ edit: true,
2219
+ delete: true,
2220
+ duplicate: true,
2221
+ insert: true
2222
+ },
2223
+ resolvedPermissions: {},
2224
+ getPermissions: ({ item, type, root } = {}) => {
2225
+ const { config, permissions } = get();
2226
+ const { globalPermissions, resolvedPermissions } = permissions;
2227
+ if (item) {
2228
+ const componentConfig = config.components[item.type];
2229
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
2230
+ const resolvedForItem = resolvedPermissions[item.props.id];
2231
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
2232
+ } else if (type) {
2233
+ const componentConfig = config.components[type];
2234
+ return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
2235
+ } else if (root) {
2236
+ const rootConfig = config.root;
2237
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
2238
+ const resolvedForItem = resolvedPermissions["root"];
2239
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
2240
+ }
2241
+ return globalPermissions;
2242
+ },
2243
+ resolvePermissions,
2244
+ refreshPermissions
2245
+ };
2246
+ };
2247
+
2248
+ // ../core/store/slices/fields.ts
2249
+ init_react_import();
2250
+ import { useCallback, useEffect as useEffect4 } from "react";
2251
+ var createFieldsSlice = (_set, _get) => {
2252
+ return {
2253
+ fields: {},
2254
+ loading: false,
2255
+ lastResolvedData: {},
2256
+ id: void 0
2257
+ };
2258
+ };
2259
+
2260
+ // ../core/lib/resolve-component-data.ts
2261
+ init_react_import();
2262
+
2263
+ // ../core/lib/data/to-component.ts
2264
+ init_react_import();
2265
+ var toComponent = (item) => {
2266
+ return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
2267
+ props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
2268
+ type: "root"
2269
+ });
2270
+ };
2271
+
2272
+ // ../core/lib/resolve-component-data.ts
2273
+ var cache = { lastChange: {} };
2274
+ var resolveComponentData = (_0, _1, ..._2) => __async(null, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", parent = null) {
2275
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
2276
+ const resolvedItem = __spreadValues({}, item);
2277
+ const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
2278
+ const id = "id" in item.props ? item.props.id : "root";
2279
+ if (shouldRunResolver) {
2280
+ const {
2281
+ item: oldItem = null,
2282
+ resolved = {},
2283
+ parentId: oldParentId = null
2284
+ } = cache.lastChange[id] || {};
2285
+ const isRootOrInserted = oldParentId === null;
2286
+ const parentChanged = !isRootOrInserted && (parent == null ? void 0 : parent.props.id) !== oldParentId;
2287
+ const dataChanged = item && !deepEqual(item, oldItem);
2288
+ const shouldSkip = trigger === "move" && !parentChanged || trigger !== "move" && trigger !== "force" && !dataChanged;
2289
+ if (shouldSkip) {
2290
+ return { node: resolved, didChange: false };
2291
+ }
2292
+ const changed = getChanged(item, oldItem);
2293
+ if (onResolveStart) {
2294
+ onResolveStart(item);
2295
+ }
2296
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
2297
+ changed,
2298
+ lastData: oldItem,
2299
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
2300
+ trigger,
2301
+ parent
2302
+ });
2303
+ resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
2304
+ if (Object.keys(readOnly).length) {
2305
+ resolvedItem.readOnly = readOnly;
2306
+ }
2307
+ }
2308
+ const itemAsComponentData = toComponent(resolvedItem);
2309
+ let itemWithResolvedChildren = yield mapFields(
2310
+ resolvedItem,
2311
+ {
2312
+ slot: (_02) => __async(null, [_02], function* ({ value }) {
2313
+ const content = value;
2314
+ return yield Promise.all(
2315
+ content.map(
2316
+ (childItem) => __async(null, null, function* () {
2317
+ return (yield resolveComponentData(
2318
+ childItem,
2319
+ config,
2320
+ metadata,
2321
+ onResolveStart,
2322
+ onResolveEnd,
2323
+ trigger,
2324
+ itemAsComponentData
2325
+ )).node;
2326
+ })
2327
+ )
2328
+ );
2329
+ })
2330
+ },
2331
+ config
2332
+ );
2333
+ if (shouldRunResolver && onResolveEnd) {
2334
+ onResolveEnd(resolvedItem);
2335
+ }
2336
+ cache.lastChange[id] = {
2337
+ item,
2338
+ resolved: itemWithResolvedChildren,
2339
+ parentId: parent == null ? void 0 : parent.props.id
2340
+ };
2341
+ return {
2342
+ node: itemWithResolvedChildren,
2343
+ didChange: !deepEqual(item, itemWithResolvedChildren)
2344
+ };
2345
+ });
2346
+
2347
+ // ../core/lib/data/to-root.ts
2348
+ init_react_import();
2349
+ var toRoot = (item) => {
2350
+ if ("type" in item && item.type !== "root") {
2351
+ throw new Error("Converting non-root item to root.");
2352
+ }
2353
+ const { readOnly } = item;
2354
+ if (item.props) {
2355
+ if ("id" in item.props) {
2356
+ const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
2357
+ return { props, readOnly };
2358
+ }
2359
+ return { props: item.props, readOnly };
2360
+ }
2361
+ return { props: {}, readOnly };
2362
+ };
2363
+
2364
+ // ../core/store/default-app-state.ts
2365
+ init_react_import();
2366
+ var defaultAppState = {
2367
+ data: { content: [], root: {}, zones: {} },
2368
+ ui: {
2369
+ leftSideBarVisible: true,
2370
+ rightSideBarVisible: true,
2371
+ arrayState: {},
2372
+ itemSelector: null,
2373
+ componentList: {},
2374
+ isDragging: false,
2375
+ previewMode: "edit",
2376
+ viewports: {
2377
+ current: {
2378
+ width: defaultViewports[0].width,
2379
+ height: defaultViewports[0].height || "auto"
2380
+ },
2381
+ options: [],
2382
+ controlsVisible: true
2383
+ },
2384
+ field: { focus: null },
2385
+ plugin: { current: null }
2386
+ },
2387
+ indexes: {
2388
+ nodes: {},
2389
+ zones: {}
2390
+ }
2391
+ };
2392
+
2393
+ // ../core/store/index.ts
2394
+ var defaultPageFields = {
2395
+ title: { type: "text" }
2396
+ };
2397
+ var createAppStore = (initialAppStore) => create()(
2398
+ subscribeWithSelector((set, get) => {
2399
+ var _a, _b;
2400
+ return __spreadProps(__spreadValues({
2401
+ instanceId: generateId(),
2402
+ state: defaultAppState,
2403
+ config: { components: {} },
2404
+ componentState: {},
2405
+ plugins: [],
2406
+ overrides: {},
2407
+ viewports: defaultViewports,
2408
+ zoomConfig: {
2409
+ autoZoom: 1,
2410
+ rootHeight: 0,
2411
+ zoom: 1
2412
+ },
2413
+ status: "LOADING",
2414
+ iframe: {},
2415
+ metadata: {},
2416
+ fieldTransforms: {}
2417
+ }, initialAppStore), {
2418
+ fields: createFieldsSlice(set, get),
2419
+ history: createHistorySlice(set, get),
2420
+ nodes: createNodesSlice(set, get),
2421
+ permissions: createPermissionsSlice(set, get),
2422
+ getCurrentData: () => {
2423
+ var _a2;
2424
+ const s = get();
2425
+ return (_a2 = s.selectedItem) != null ? _a2 : s.state.data.root;
2426
+ },
2427
+ getComponentConfig: (type) => {
2428
+ var _a2;
2429
+ const { config, selectedItem } = get();
2430
+ const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
2431
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
2432
+ },
2433
+ selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
2434
+ (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
2435
+ initialAppStore.state
2436
+ ) : null,
2437
+ dispatch: (action) => set((s) => {
2438
+ var _a2, _b2;
2439
+ const { record } = get().history;
2440
+ const dispatch = createReducer({
2441
+ record,
2442
+ appStore: s
2443
+ });
2444
+ const state = dispatch(s.state, action);
2445
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
2446
+ (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
2447
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
2448
+ }),
2449
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
2450
+ setStatus: (status) => set({ status }),
2451
+ setComponentState: (componentState) => set({ componentState }),
2452
+ pendingLoadTimeouts: {},
2453
+ setComponentLoading: (id, loading = true, defer = 0) => {
2454
+ const { setComponentState, pendingLoadTimeouts } = get();
2455
+ const loadId = generateId();
2456
+ const setLoading = () => {
2457
+ var _a2;
2458
+ const { componentState } = get();
2459
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
2460
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
2461
+ loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
2462
+ })
2463
+ }));
2464
+ };
2465
+ const unsetLoading = () => {
2466
+ var _a2;
2467
+ const { componentState } = get();
2468
+ clearTimeout(timeout);
2469
+ delete pendingLoadTimeouts[loadId];
2470
+ set({ pendingLoadTimeouts });
2471
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
2472
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
2473
+ loadingCount: Math.max(
2474
+ (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
2475
+ 0
2476
+ )
2477
+ })
2478
+ }));
2479
+ };
2480
+ const timeout = setTimeout(() => {
2481
+ if (loading) {
2482
+ setLoading();
2483
+ } else {
2484
+ unsetLoading();
2485
+ }
2486
+ delete pendingLoadTimeouts[loadId];
2487
+ set({ pendingLoadTimeouts });
2488
+ }, defer);
2489
+ set({
2490
+ pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
2491
+ [id]: timeout
2492
+ })
2493
+ });
2494
+ return unsetLoading;
2495
+ },
2496
+ unsetComponentLoading: (id) => {
2497
+ const { setComponentLoading } = get();
2498
+ setComponentLoading(id, false);
2499
+ },
2500
+ // Helper
2501
+ setUi: (ui, recordHistory) => set((s) => {
2502
+ const dispatch = createReducer({
2503
+ record: () => {
2504
+ },
2505
+ appStore: s
2506
+ });
2507
+ const state = dispatch(s.state, {
2508
+ type: "setUi",
2509
+ ui,
2510
+ recordHistory
2511
+ });
2512
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
2513
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
2514
+ }),
2515
+ resolveComponentData: (componentData, trigger) => __async(null, null, function* () {
2516
+ var _a2, _b2;
2517
+ const { config, metadata, setComponentLoading, permissions, state } = get();
2518
+ const componentId = "id" in componentData.props ? componentData.props.id : "root";
2519
+ const parentId = (_a2 = state.indexes.nodes[componentId]) == null ? void 0 : _a2.parentId;
2520
+ const parentNode = parentId ? state.indexes.nodes[parentId] : null;
2521
+ const parentData = (_b2 = parentNode == null ? void 0 : parentNode.data) != null ? _b2 : null;
2522
+ const timeouts = {};
2523
+ return yield resolveComponentData(
2524
+ componentData,
2525
+ config,
2526
+ metadata,
2527
+ (item) => {
2528
+ const id = "id" in item.props ? item.props.id : "root";
2529
+ timeouts[id] = setComponentLoading(id, true, 50);
2530
+ },
2531
+ (item) => __async(null, null, function* () {
2532
+ const id = "id" in item.props ? item.props.id : "root";
2533
+ if ("type" in item) {
2534
+ yield permissions.refreshPermissions({ item });
2535
+ } else {
2536
+ yield permissions.refreshPermissions({ root: true });
2537
+ }
2538
+ timeouts[id]();
2539
+ }),
2540
+ trigger,
2541
+ parentData
2542
+ );
2543
+ }),
2544
+ resolveAndCommitData: () => __async(null, null, function* () {
2545
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
2546
+ walkAppState(
2547
+ state,
2548
+ config,
2549
+ (content) => content,
2550
+ (childItem) => {
2551
+ resolveComponentData2(childItem, "load").then((resolved) => {
2552
+ const { state: state2 } = get();
2553
+ const node = state2.indexes.nodes[resolved.node.props.id];
2554
+ if (node && resolved.didChange) {
2555
+ if (resolved.node.props.id === "root") {
2556
+ dispatch({
2557
+ type: "replaceRoot",
2558
+ root: toRoot(resolved.node)
2559
+ });
2560
+ } else {
2561
+ const zoneCompound = `${node.parentId}:${node.zone}`;
2562
+ const parentZone = state2.indexes.zones[zoneCompound];
2563
+ const index = parentZone.contentIds.indexOf(
2564
+ resolved.node.props.id
2565
+ );
2566
+ dispatch({
2567
+ type: "replace",
2568
+ data: resolved.node,
2569
+ destinationIndex: index,
2570
+ destinationZone: zoneCompound
2571
+ });
2572
+ }
2573
+ }
2574
+ });
2575
+ return childItem;
2576
+ }
2577
+ );
2578
+ })
2579
+ });
2580
+ })
2581
+ );
2582
+ var appStoreContext = createContext(createAppStore());
2583
+
2584
+ // ../core/lib/get-zoom-config.ts
2585
+ init_react_import();
2586
+
2587
+ // src/HeadingAnalyzer.tsx
2588
+ import ReactFromJSONModule from "react-from-json";
2589
+ import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
2590
+ var getClassName2 = get_class_name_factory_default("HeadingAnalyzer", HeadingAnalyzer_module_default);
2591
+ var getClassNameItem2 = get_class_name_factory_default("HeadingAnalyzerItem", HeadingAnalyzer_module_default);
2592
+ var ReactFromJSON = ReactFromJSONModule.default || ReactFromJSONModule;
2593
+ var getOutline = ({ frame } = {}) => {
2594
+ const headings = (frame == null ? void 0 : frame.querySelectorAll("h1,h2,h3,h4,h5,h6")) || [];
2595
+ const _outline = [];
2596
+ headings.forEach((item, i) => {
2597
+ if (item.closest("[data-dnd-dragging]")) {
2598
+ return;
2599
+ }
2600
+ _outline.push({
2601
+ rank: parseInt(item.tagName.split("H")[1]),
2602
+ text: item.textContent,
2603
+ element: item
2604
+ });
2605
+ });
2606
+ return _outline;
2607
+ };
2608
+ function buildHierarchy(frame) {
2609
+ var _a, _b;
2610
+ const headings = getOutline({ frame });
2611
+ const root = { rank: 0, children: [], text: "" };
2612
+ let path = [root];
2613
+ for (let heading of headings) {
2614
+ const node = {
2615
+ rank: heading.rank,
2616
+ text: heading.text,
2617
+ children: [],
2618
+ element: heading.element
2619
+ };
2620
+ if (node.rank === 1) {
2621
+ path = [root];
2622
+ } else {
2623
+ while (path[path.length - 1].rank >= node.rank) {
2624
+ path.pop();
2625
+ }
2626
+ while (path.length < node.rank) {
2627
+ const missingNode = {
2628
+ rank: path.length,
2629
+ missing: true,
2630
+ children: [],
2631
+ text: ""
2632
+ };
2633
+ (_a = path[path.length - 1].children) == null ? void 0 : _a.push(missingNode);
2634
+ path.push(missingNode);
2635
+ }
2636
+ }
2637
+ (_b = path[path.length - 1].children) == null ? void 0 : _b.push(node);
2638
+ path.push(node);
2639
+ }
2640
+ return root.children;
2641
+ }
2642
+ var usePuck = createUsePuck();
2643
+ var HeadingAnalyzer = () => {
2644
+ const data = usePuck((s) => s.appState.data);
2645
+ const [hierarchy, setHierarchy] = useState([]);
2646
+ useEffect5(() => {
2647
+ const frame = getFrame();
2648
+ let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2649
+ const createHierarchy = () => {
2650
+ setHierarchy(buildHierarchy(entry));
2651
+ };
2652
+ const entryObserver = new MutationObserver(() => {
2653
+ createHierarchy();
2654
+ });
2655
+ const frameObserver = new MutationObserver(() => {
2656
+ entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2657
+ if (entry) {
2658
+ registerEntryObserver();
2659
+ frameObserver.disconnect();
2660
+ }
2661
+ });
2662
+ const registerEntryObserver = () => {
2663
+ if (!entry) return;
2664
+ entryObserver.observe(entry, { subtree: true, childList: true });
2665
+ };
2666
+ const registerFrameObserver = () => {
2667
+ if (!frame) return;
2668
+ frameObserver.observe(frame, { subtree: true, childList: true });
2669
+ };
2670
+ if (entry) {
2671
+ createHierarchy();
2672
+ registerEntryObserver();
2673
+ } else {
2674
+ registerFrameObserver();
2675
+ }
2676
+ return () => {
2677
+ entryObserver.disconnect();
2678
+ frameObserver.disconnect();
2679
+ };
2680
+ }, [data]);
2681
+ return /* @__PURE__ */ jsxs("div", { className: getClassName2(), children: [
2682
+ /* @__PURE__ */ jsxs(
2683
+ "small",
2684
+ {
2685
+ className: getClassName2("cssWarning"),
2686
+ style: {
2687
+ color: "var(--puck-color-red-04)",
2688
+ display: "block",
2689
+ marginBottom: 16
2690
+ },
2691
+ children: [
2692
+ "Heading analyzer styles not loaded. Please review the",
2693
+ " ",
2694
+ /* @__PURE__ */ jsx2("a", { href: "https://github.com/puckeditor/puck/blob/main/packages/plugin-heading-analyzer/README.md", children: "README" }),
2695
+ "."
2696
+ ]
2697
+ }
2698
+ ),
2699
+ hierarchy.length === 0 && /* @__PURE__ */ jsx2("div", { children: "No headings." }),
2700
+ /* @__PURE__ */ jsx2(OutlineList, { children: /* @__PURE__ */ jsx2(
2701
+ ReactFromJSON,
2702
+ {
2703
+ mapping: {
2704
+ Root: (props) => /* @__PURE__ */ jsx2(Fragment, { children: props.children }),
2705
+ OutlineListItem: (props) => /* @__PURE__ */ jsxs(OutlineList.Item, { children: [
2706
+ /* @__PURE__ */ jsx2(OutlineList.Clickable, { children: /* @__PURE__ */ jsx2(
2707
+ "small",
2708
+ {
2709
+ className: getClassNameItem2({ missing: props.missing }),
2710
+ onClick: typeof props.element == "undefined" ? void 0 : (e) => {
2711
+ e.stopPropagation();
2712
+ const el = props.element;
2713
+ const oldStyle = __spreadValues({}, el.style);
2714
+ if (el) {
2715
+ scrollIntoView(el);
2716
+ el.style.outline = "4px solid var(--puck-color-rose-06)";
2717
+ el.style.outlineOffset = "4px";
2718
+ setTimeout(() => {
2719
+ el.style.outline = oldStyle.outline || "";
2720
+ el.style.outlineOffset = oldStyle.outlineOffset || "";
2721
+ }, 2e3);
2722
+ }
2723
+ },
2724
+ children: props.missing ? /* @__PURE__ */ jsxs(Fragment, { children: [
2725
+ /* @__PURE__ */ jsxs("b", { children: [
2726
+ "H",
2727
+ props.rank
2728
+ ] }),
2729
+ ": Missing"
2730
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2731
+ /* @__PURE__ */ jsxs("b", { children: [
2732
+ "H",
2733
+ props.rank
2734
+ ] }),
2735
+ ": ",
2736
+ props.text
2737
+ ] })
2738
+ }
2739
+ ) }),
2740
+ /* @__PURE__ */ jsx2(OutlineList, { children: props.children })
2741
+ ] })
2742
+ },
2743
+ entry: {
2744
+ props: { children: hierarchy },
2745
+ type: "Root"
2746
+ },
2747
+ mapProp: (prop) => {
2748
+ if (prop && prop.rank) {
2749
+ return {
2750
+ type: "OutlineListItem",
2751
+ props: prop
2752
+ };
2753
+ }
2754
+ return prop;
2755
+ }
2756
+ }
2757
+ ) })
2758
+ ] });
2759
+ };
2760
+ var headingAnalyzer = {
2761
+ name: "heading-analyzer",
2762
+ label: "Audit",
2763
+ render: HeadingAnalyzer,
2764
+ icon: /* @__PURE__ */ jsx2(Heading1, {})
2765
+ };
2766
+ var HeadingAnalyzer_default = headingAnalyzer;
2767
+ export {
2768
+ HeadingAnalyzer_default as default
2769
+ };
2770
+ /*! Bundled license information:
2771
+
2772
+ classnames/index.js:
2773
+ (*!
2774
+ Copyright (c) 2018 Jed Watson.
2775
+ Licensed under the MIT License (MIT), see
2776
+ http://jedwatson.github.io/classnames
2777
+ *)
2778
+
2779
+ lucide-react/dist/esm/shared/src/utils.js:
2780
+ lucide-react/dist/esm/defaultAttributes.js:
2781
+ lucide-react/dist/esm/Icon.js:
2782
+ lucide-react/dist/esm/createLucideIcon.js:
2783
+ lucide-react/dist/esm/icons/heading-1.js:
2784
+ lucide-react/dist/esm/lucide-react.js:
2785
+ (**
2786
+ * @license lucide-react v0.468.0 - ISC
2787
+ *
2788
+ * This source code is licensed under the ISC license.
2789
+ * See the LICENSE file in the root directory of this source tree.
2790
+ *)
2791
+ */