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