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