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