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