@measured/puck-plugin-heading-analyzer 0.19.0-canary.a281c342 → 0.19.0-canary.a60c81eb
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 +18 -9
- package/dist/index.d.ts +18 -9
- package/dist/index.js +974 -637
- package/dist/index.mjs +974 -637
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -153,6 +153,120 @@ var require_classnames = __commonJS({
|
|
153
153
|
}
|
154
154
|
});
|
155
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
|
+
|
156
270
|
// ../../node_modules/fast-deep-equal/index.js
|
157
271
|
var require_fast_deep_equal = __commonJS({
|
158
272
|
"../../node_modules/fast-deep-equal/index.js"(exports2, module2) {
|
@@ -368,26 +482,16 @@ init_react_import();
|
|
368
482
|
// ../core/reducer/index.ts
|
369
483
|
init_react_import();
|
370
484
|
|
371
|
-
// ../core/reducer/
|
485
|
+
// ../core/reducer/actions/set.ts
|
372
486
|
init_react_import();
|
373
487
|
|
374
|
-
// ../core/lib/
|
488
|
+
// ../core/lib/data/walk-app-state.ts
|
375
489
|
init_react_import();
|
376
|
-
var insert = (list, index, item) => {
|
377
|
-
const result = Array.from(list || []);
|
378
|
-
result.splice(index, 0, item);
|
379
|
-
return result;
|
380
|
-
};
|
381
490
|
|
382
|
-
// ../core/lib/
|
491
|
+
// ../core/lib/data/for-related-zones.ts
|
383
492
|
init_react_import();
|
384
|
-
var remove = (list, index) => {
|
385
|
-
const result = Array.from(list);
|
386
|
-
result.splice(index, 1);
|
387
|
-
return result;
|
388
|
-
};
|
389
493
|
|
390
|
-
// ../core/lib/
|
494
|
+
// ../core/lib/get-zone-id.ts
|
391
495
|
init_react_import();
|
392
496
|
|
393
497
|
// ../core/lib/root-droppable-id.ts
|
@@ -396,133 +500,7 @@ var rootAreaId = "root";
|
|
396
500
|
var rootZone = "default-zone";
|
397
501
|
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
398
502
|
|
399
|
-
// ../core/lib/setup-zone.ts
|
400
|
-
var setupZone = (data, zoneKey) => {
|
401
|
-
if (zoneKey === rootDroppableId) {
|
402
|
-
return data;
|
403
|
-
}
|
404
|
-
const newData = __spreadProps(__spreadValues({}, data), {
|
405
|
-
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
406
|
-
});
|
407
|
-
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
408
|
-
return newData;
|
409
|
-
};
|
410
|
-
|
411
|
-
// ../core/lib/get-item.ts
|
412
|
-
init_react_import();
|
413
|
-
function getItem(selector, state) {
|
414
|
-
var _a, _b;
|
415
|
-
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
416
|
-
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
417
|
-
}
|
418
|
-
|
419
|
-
// ../core/lib/generate-id.ts
|
420
|
-
init_react_import();
|
421
|
-
|
422
|
-
// ../../node_modules/uuid/dist/esm-node/index.js
|
423
|
-
init_react_import();
|
424
|
-
|
425
|
-
// ../../node_modules/uuid/dist/esm-node/rng.js
|
426
|
-
init_react_import();
|
427
|
-
var import_crypto = __toESM(require("crypto"));
|
428
|
-
var rnds8Pool = new Uint8Array(256);
|
429
|
-
var poolPtr = rnds8Pool.length;
|
430
|
-
function rng() {
|
431
|
-
if (poolPtr > rnds8Pool.length - 16) {
|
432
|
-
import_crypto.default.randomFillSync(rnds8Pool);
|
433
|
-
poolPtr = 0;
|
434
|
-
}
|
435
|
-
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
436
|
-
}
|
437
|
-
|
438
|
-
// ../../node_modules/uuid/dist/esm-node/stringify.js
|
439
|
-
init_react_import();
|
440
|
-
var byteToHex = [];
|
441
|
-
for (let i = 0; i < 256; ++i) {
|
442
|
-
byteToHex.push((i + 256).toString(16).slice(1));
|
443
|
-
}
|
444
|
-
function unsafeStringify(arr, offset = 0) {
|
445
|
-
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]];
|
446
|
-
}
|
447
|
-
|
448
|
-
// ../../node_modules/uuid/dist/esm-node/v4.js
|
449
|
-
init_react_import();
|
450
|
-
|
451
|
-
// ../../node_modules/uuid/dist/esm-node/native.js
|
452
|
-
init_react_import();
|
453
|
-
var import_crypto2 = __toESM(require("crypto"));
|
454
|
-
var native_default = {
|
455
|
-
randomUUID: import_crypto2.default.randomUUID
|
456
|
-
};
|
457
|
-
|
458
|
-
// ../../node_modules/uuid/dist/esm-node/v4.js
|
459
|
-
function v4(options, buf, offset) {
|
460
|
-
if (native_default.randomUUID && !buf && !options) {
|
461
|
-
return native_default.randomUUID();
|
462
|
-
}
|
463
|
-
options = options || {};
|
464
|
-
const rnds = options.random || (options.rng || rng)();
|
465
|
-
rnds[6] = rnds[6] & 15 | 64;
|
466
|
-
rnds[8] = rnds[8] & 63 | 128;
|
467
|
-
if (buf) {
|
468
|
-
offset = offset || 0;
|
469
|
-
for (let i = 0; i < 16; ++i) {
|
470
|
-
buf[offset + i] = rnds[i];
|
471
|
-
}
|
472
|
-
return buf;
|
473
|
-
}
|
474
|
-
return unsafeStringify(rnds);
|
475
|
-
}
|
476
|
-
var v4_default = v4;
|
477
|
-
|
478
|
-
// ../core/lib/generate-id.ts
|
479
|
-
var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
|
480
|
-
|
481
|
-
// ../core/lib/walk-tree.ts
|
482
|
-
init_react_import();
|
483
|
-
|
484
|
-
// ../core/lib/for-each-slot.ts
|
485
|
-
init_react_import();
|
486
|
-
|
487
|
-
// ../core/lib/is-slot.ts
|
488
|
-
init_react_import();
|
489
|
-
var isSlot = (prop) => {
|
490
|
-
var _a, _b;
|
491
|
-
return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
|
492
|
-
};
|
493
|
-
var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
|
494
|
-
var _a, _b;
|
495
|
-
const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
|
496
|
-
if (!configForComponent) return isSlot(propValue);
|
497
|
-
return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
|
498
|
-
};
|
499
|
-
|
500
|
-
// ../core/lib/for-each-slot.ts
|
501
|
-
var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, cb, recursive = false, isSlot2 = isSlot) {
|
502
|
-
const props = item.props || {};
|
503
|
-
const propKeys = Object.keys(props);
|
504
|
-
for (let i = 0; i < propKeys.length; i++) {
|
505
|
-
const propKey = propKeys[i];
|
506
|
-
const itemType = "type" in item ? item.type : "root";
|
507
|
-
if (isSlot2(itemType, propKey, props[propKey])) {
|
508
|
-
const content = props[propKey];
|
509
|
-
yield cb(props.id, propKey, content);
|
510
|
-
if (recursive) {
|
511
|
-
content.forEach(
|
512
|
-
(childItem) => __async(void 0, null, function* () {
|
513
|
-
return yield forEachSlot(childItem, cb, true, isSlot2);
|
514
|
-
})
|
515
|
-
);
|
516
|
-
}
|
517
|
-
}
|
518
|
-
}
|
519
|
-
});
|
520
|
-
|
521
|
-
// ../core/lib/for-related-zones.ts
|
522
|
-
init_react_import();
|
523
|
-
|
524
503
|
// ../core/lib/get-zone-id.ts
|
525
|
-
init_react_import();
|
526
504
|
var getZoneId = (zoneCompound) => {
|
527
505
|
if (!zoneCompound) {
|
528
506
|
return [];
|
@@ -533,36 +511,169 @@ var getZoneId = (zoneCompound) => {
|
|
533
511
|
return [rootDroppableId, zoneCompound];
|
534
512
|
};
|
535
513
|
|
536
|
-
// ../core/lib/for-related-zones.ts
|
514
|
+
// ../core/lib/data/for-related-zones.ts
|
537
515
|
function forRelatedZones(item, data, cb, path = []) {
|
538
516
|
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
539
517
|
const [parentId] = getZoneId(zoneCompound);
|
540
518
|
if (parentId === item.props.id) {
|
541
|
-
const newPath = [...path, zoneCompound];
|
542
|
-
content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
|
543
519
|
cb(path, zoneCompound, content);
|
544
520
|
}
|
545
521
|
});
|
546
522
|
}
|
547
523
|
|
548
|
-
// ../core/lib/
|
524
|
+
// ../core/lib/data/map-slots.ts
|
549
525
|
init_react_import();
|
550
|
-
var
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
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
|
561
655
|
});
|
656
|
+
}
|
657
|
+
|
658
|
+
// ../core/lib/data/flatten-node.ts
|
659
|
+
init_react_import();
|
660
|
+
var import_flat = __toESM(require_flat());
|
661
|
+
|
662
|
+
// ../core/lib/data/strip-slots.ts
|
663
|
+
init_react_import();
|
664
|
+
var stripSlots = (data, config) => {
|
665
|
+
return mapSlots(data, () => null, config);
|
562
666
|
};
|
563
667
|
|
564
|
-
// ../core/lib/
|
565
|
-
|
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) {
|
566
677
|
var _a;
|
567
678
|
let newZones = {};
|
568
679
|
const newZoneIndex = {};
|
@@ -603,11 +714,9 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
603
714
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
604
715
|
if (!mappedItem) return item;
|
605
716
|
const id = mappedItem.props.id;
|
606
|
-
|
607
|
-
const newProps = __spreadValues({}, mappedItem.props);
|
608
|
-
forEachSlot(
|
717
|
+
const newProps = __spreadProps(__spreadValues({}, mapSlots(
|
609
718
|
mappedItem,
|
610
|
-
(parentId2, slotId
|
719
|
+
(content, parentId2, slotId) => {
|
611
720
|
const zoneCompound = `${parentId2}:${slotId}`;
|
612
721
|
const [_2, newContent2] = processContent(
|
613
722
|
path,
|
@@ -616,17 +725,19 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
616
725
|
"slot",
|
617
726
|
parentId2
|
618
727
|
);
|
619
|
-
|
728
|
+
return newContent2;
|
620
729
|
},
|
621
|
-
|
622
|
-
|
623
|
-
|
730
|
+
config
|
731
|
+
).props), {
|
732
|
+
id
|
733
|
+
});
|
734
|
+
processRelatedZones(item, id, path);
|
624
735
|
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
625
736
|
const thisZoneCompound = path[path.length - 1];
|
626
737
|
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
627
738
|
newNodeIndex[id] = {
|
628
739
|
data: newItem,
|
629
|
-
flatData:
|
740
|
+
flatData: flattenNode(newItem, config),
|
630
741
|
path,
|
631
742
|
parentId,
|
632
743
|
zone
|
@@ -675,7 +786,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
675
786
|
return __spreadProps(__spreadValues({}, state), {
|
676
787
|
data: {
|
677
788
|
root,
|
678
|
-
// root: state.data.root, // TODO changing root causes it's entire subtree to re-render. Let's keep this disabled until the performance issues are resolved in #644.
|
679
789
|
content: processedContent,
|
680
790
|
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
681
791
|
},
|
@@ -686,26 +796,175 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
|
|
686
796
|
});
|
687
797
|
}
|
688
798
|
|
689
|
-
// ../core/reducer/
|
690
|
-
var
|
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
|
815
|
+
init_react_import();
|
816
|
+
|
817
|
+
// ../core/lib/data/insert.ts
|
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
|
+
};
|
824
|
+
|
825
|
+
// ../core/lib/generate-id.ts
|
826
|
+
init_react_import();
|
827
|
+
|
828
|
+
// ../../node_modules/uuid/dist/esm-node/index.js
|
829
|
+
init_react_import();
|
830
|
+
|
831
|
+
// ../../node_modules/uuid/dist/esm-node/rng.js
|
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
|
+
}
|
843
|
+
|
844
|
+
// ../../node_modules/uuid/dist/esm-node/stringify.js
|
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
|
+
}
|
853
|
+
|
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();
|
691
889
|
var getIdsForParent = (zoneCompound, state) => {
|
692
890
|
const [parentId] = zoneCompound.split(":");
|
693
891
|
const node = state.indexes.nodes[parentId];
|
694
892
|
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
695
893
|
};
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
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;
|
908
|
+
},
|
909
|
+
config,
|
910
|
+
true
|
911
|
+
);
|
703
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
|
+
})
|
960
|
+
},
|
961
|
+
appStore.config
|
962
|
+
);
|
704
963
|
const [parentId] = action.destinationZone.split(":");
|
705
964
|
const idsInPath = getIdsForParent(action.destinationZone, state);
|
706
|
-
return
|
965
|
+
return walkAppState(
|
707
966
|
state,
|
708
|
-
config,
|
967
|
+
appStore.config,
|
709
968
|
(content, zoneCompound) => {
|
710
969
|
if (zoneCompound === action.destinationZone) {
|
711
970
|
return insert(
|
@@ -728,6 +987,142 @@ function insertAction(state, action, config) {
|
|
728
987
|
}
|
729
988
|
);
|
730
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
|
+
);
|
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
|
+
);
|
1028
|
+
};
|
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
|
731
1126
|
var moveAction = (state, action, appStore) => {
|
732
1127
|
if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
|
733
1128
|
return state;
|
@@ -739,7 +1134,7 @@ var moveAction = (state, action, appStore) => {
|
|
739
1134
|
if (!item) return state;
|
740
1135
|
const idsInSourcePath = getIdsForParent(action.sourceZone, state);
|
741
1136
|
const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
|
742
|
-
return
|
1137
|
+
return walkAppState(
|
743
1138
|
state,
|
744
1139
|
appStore.config,
|
745
1140
|
(content, zoneCompound) => {
|
@@ -767,57 +1162,26 @@ var moveAction = (state, action, appStore) => {
|
|
767
1162
|
}
|
768
1163
|
);
|
769
1164
|
};
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
const idChanged = originalId !== action.data.props.id;
|
775
|
-
if (idChanged) {
|
776
|
-
throw new Error(
|
777
|
-
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
778
|
-
);
|
779
|
-
}
|
780
|
-
return walkTree(
|
1165
|
+
|
1166
|
+
// ../core/reducer/actions/reorder.ts
|
1167
|
+
var reorderAction = (state, action, appStore) => {
|
1168
|
+
return moveAction(
|
781
1169
|
state,
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
return newContent;
|
1170
|
+
{
|
1171
|
+
type: "move",
|
1172
|
+
sourceIndex: action.sourceIndex,
|
1173
|
+
sourceZone: action.destinationZone,
|
1174
|
+
destinationIndex: action.destinationIndex,
|
1175
|
+
destinationZone: action.destinationZone
|
789
1176
|
},
|
790
|
-
|
791
|
-
const pathIds = path.map((p) => p.split(":")[0]);
|
792
|
-
if (childItem.props.id === action.data.props.id) {
|
793
|
-
return action.data;
|
794
|
-
} else if (childItem.props.id === parentId) {
|
795
|
-
return childItem;
|
796
|
-
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
797
|
-
return childItem;
|
798
|
-
} else if (pathIds.indexOf(action.data.props.id) > -1) {
|
799
|
-
return childItem;
|
800
|
-
}
|
801
|
-
return null;
|
802
|
-
}
|
1177
|
+
appStore
|
803
1178
|
);
|
804
1179
|
};
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
if (action.state.indexes) {
|
809
|
-
console.warn(
|
810
|
-
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
811
|
-
);
|
812
|
-
return newState;
|
813
|
-
}
|
814
|
-
return walkTree(newState, appStore.config);
|
815
|
-
}
|
816
|
-
return __spreadValues(__spreadValues({}, state), action.state(state));
|
817
|
-
};
|
1180
|
+
|
1181
|
+
// ../core/reducer/actions/remove.ts
|
1182
|
+
init_react_import();
|
818
1183
|
var removeAction = (state, action, appStore) => {
|
819
1184
|
const item = getItem({ index: action.index, zone: action.zone }, state);
|
820
|
-
const [parentId] = action.zone.split(":");
|
821
1185
|
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
822
1186
|
(acc, [nodeId, nodeData]) => {
|
823
1187
|
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
@@ -828,7 +1192,7 @@ var removeAction = (state, action, appStore) => {
|
|
828
1192
|
},
|
829
1193
|
[item.props.id]
|
830
1194
|
);
|
831
|
-
const newState =
|
1195
|
+
const newState = walkAppState(
|
832
1196
|
state,
|
833
1197
|
appStore.config,
|
834
1198
|
(content, zoneCompound) => {
|
@@ -836,24 +1200,17 @@ var removeAction = (state, action, appStore) => {
|
|
836
1200
|
return remove(content, action.index);
|
837
1201
|
}
|
838
1202
|
return content;
|
839
|
-
},
|
840
|
-
(childItem, path) => {
|
841
|
-
const parentIds = path.map((p) => p.split(":")[0]);
|
842
|
-
if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
|
843
|
-
return childItem;
|
844
|
-
}
|
845
|
-
return null;
|
846
1203
|
}
|
847
1204
|
);
|
848
1205
|
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
849
|
-
const
|
850
|
-
if (nodesToDelete.includes(
|
1206
|
+
const parentId = zoneCompound.split(":")[0];
|
1207
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
851
1208
|
delete newState.data.zones[zoneCompound];
|
852
1209
|
}
|
853
1210
|
});
|
854
1211
|
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
855
|
-
const
|
856
|
-
if (nodesToDelete.includes(
|
1212
|
+
const parentId = zoneCompound.split(":")[0];
|
1213
|
+
if (nodesToDelete.includes(parentId)) {
|
857
1214
|
delete newState.indexes.zones[zoneCompound];
|
858
1215
|
}
|
859
1216
|
});
|
@@ -862,168 +1219,104 @@ var removeAction = (state, action, appStore) => {
|
|
862
1219
|
});
|
863
1220
|
return newState;
|
864
1221
|
};
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
if (
|
873
|
-
return
|
874
|
-
}
|
875
|
-
if (action.type === "replaceRoot") {
|
876
|
-
return walkTree(
|
877
|
-
state,
|
878
|
-
appStore.config,
|
879
|
-
(content) => content,
|
880
|
-
(childItem) => {
|
881
|
-
if (childItem.props.id === "root") {
|
882
|
-
return __spreadProps(__spreadValues({}, childItem), {
|
883
|
-
props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
|
884
|
-
readOnly: action.root.readOnly
|
885
|
-
});
|
886
|
-
}
|
887
|
-
return childItem;
|
888
|
-
}
|
889
|
-
);
|
890
|
-
}
|
891
|
-
if (action.type === "duplicate") {
|
892
|
-
const item = getItem(
|
893
|
-
{ index: action.sourceIndex, zone: action.sourceZone },
|
894
|
-
state
|
895
|
-
);
|
896
|
-
const idsInPath = getIdsForParent(action.sourceZone, state);
|
897
|
-
const newItem = __spreadProps(__spreadValues({}, item), {
|
898
|
-
props: __spreadProps(__spreadValues({}, item.props), {
|
899
|
-
id: generateId(item.type)
|
900
|
-
})
|
901
|
-
});
|
902
|
-
const modified = walkTree(
|
903
|
-
state,
|
904
|
-
appStore.config,
|
905
|
-
(content, zoneCompound) => {
|
906
|
-
if (zoneCompound === action.sourceZone) {
|
907
|
-
return insert(content, action.sourceIndex + 1, item);
|
908
|
-
}
|
909
|
-
return content;
|
910
|
-
},
|
911
|
-
(childItem, path, index) => {
|
912
|
-
const zoneCompound = path[path.length - 1];
|
913
|
-
const parents = path.map((p) => p.split(":")[0]);
|
914
|
-
if (parents.indexOf(newItem.props.id) > -1) {
|
915
|
-
return __spreadProps(__spreadValues({}, childItem), {
|
916
|
-
props: __spreadProps(__spreadValues({}, childItem.props), {
|
917
|
-
id: generateId(childItem.type)
|
918
|
-
})
|
919
|
-
});
|
920
|
-
}
|
921
|
-
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
922
|
-
return newItem;
|
923
|
-
}
|
924
|
-
const [sourceZoneParent] = action.sourceZone.split(":");
|
925
|
-
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
926
|
-
return childItem;
|
927
|
-
}
|
928
|
-
return null;
|
929
|
-
}
|
930
|
-
);
|
931
|
-
return __spreadProps(__spreadValues({}, modified), {
|
932
|
-
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
933
|
-
itemSelector: {
|
934
|
-
index: action.sourceIndex + 1,
|
935
|
-
zone: action.sourceZone
|
936
|
-
}
|
937
|
-
})
|
938
|
-
});
|
939
|
-
}
|
940
|
-
if (action.type === "reorder") {
|
941
|
-
return moveAction(
|
942
|
-
state,
|
943
|
-
{
|
944
|
-
type: "move",
|
945
|
-
sourceIndex: action.sourceIndex,
|
946
|
-
sourceZone: action.destinationZone,
|
947
|
-
destinationIndex: action.destinationIndex,
|
948
|
-
destinationZone: action.destinationZone
|
949
|
-
},
|
950
|
-
appStore
|
951
|
-
);
|
952
|
-
}
|
953
|
-
if (action.type === "move") {
|
954
|
-
return moveAction(state, action, appStore);
|
955
|
-
}
|
956
|
-
if (action.type === "remove") {
|
957
|
-
return removeAction(state, action, appStore);
|
958
|
-
}
|
959
|
-
if (action.type === "registerZone") {
|
960
|
-
if (zoneCache[action.zone]) {
|
961
|
-
return __spreadProps(__spreadValues({}, state), {
|
962
|
-
data: __spreadProps(__spreadValues({}, state.data), {
|
963
|
-
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
964
|
-
[action.zone]: zoneCache[action.zone]
|
965
|
-
})
|
966
|
-
}),
|
967
|
-
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
968
|
-
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
969
|
-
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
970
|
-
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
971
|
-
type: "dropzone"
|
972
|
-
})
|
973
|
-
})
|
974
|
-
})
|
975
|
-
});
|
976
|
-
}
|
977
|
-
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
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;
|
978
1231
|
}
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
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]) {
|
987
1243
|
return __spreadProps(__spreadValues({}, state), {
|
988
1244
|
data: __spreadProps(__spreadValues({}, state.data), {
|
989
|
-
zones:
|
1245
|
+
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
1246
|
+
[action.zone]: zoneCache[action.zone]
|
1247
|
+
})
|
990
1248
|
}),
|
991
1249
|
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
992
|
-
zones:
|
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
|
+
})
|
993
1256
|
})
|
994
1257
|
});
|
995
1258
|
}
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
}
|
1008
|
-
|
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(
|
1009
1287
|
__spreadProps(__spreadValues({}, state), {
|
1010
|
-
data: __spreadValues(__spreadValues({}, state.data), action.data
|
1288
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
1011
1289
|
}),
|
1012
1290
|
appStore.config
|
1013
1291
|
);
|
1014
1292
|
}
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
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") {
|
1021
1305
|
return __spreadProps(__spreadValues({}, state), {
|
1022
|
-
ui: __spreadValues(__spreadValues({}, state.ui), action.ui
|
1306
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
|
1023
1307
|
});
|
1024
1308
|
}
|
1025
|
-
return state
|
1026
|
-
}
|
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
|
+
};
|
1027
1320
|
|
1028
1321
|
// ../core/reducer/actions.tsx
|
1029
1322
|
init_react_import();
|
@@ -1042,7 +1335,7 @@ function storeInterceptor(reducer, record, onAction) {
|
|
1042
1335
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
1043
1336
|
if (record) record(newAppState);
|
1044
1337
|
}
|
1045
|
-
onAction == null ? void 0 : onAction(action, newAppState, state);
|
1338
|
+
onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
|
1046
1339
|
return newAppState;
|
1047
1340
|
};
|
1048
1341
|
}
|
@@ -1053,8 +1346,43 @@ function createReducer({
|
|
1053
1346
|
}) {
|
1054
1347
|
return storeInterceptor(
|
1055
1348
|
(state, action) => {
|
1056
|
-
|
1057
|
-
|
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;
|
1058
1386
|
},
|
1059
1387
|
record,
|
1060
1388
|
onAction
|
@@ -1249,7 +1577,7 @@ var createHistorySlice = (set, get) => {
|
|
1249
1577
|
const { dispatch, history } = get();
|
1250
1578
|
dispatch({
|
1251
1579
|
type: "set",
|
1252
|
-
state: ((_a = history.histories[
|
1580
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
1253
1581
|
});
|
1254
1582
|
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
1255
1583
|
},
|
@@ -1265,7 +1593,11 @@ var createNodesSlice = (set, get) => ({
|
|
1265
1593
|
const s = get().nodes;
|
1266
1594
|
const emptyNode = {
|
1267
1595
|
id,
|
1268
|
-
methods: {
|
1596
|
+
methods: {
|
1597
|
+
sync: () => null,
|
1598
|
+
hideOverlay: () => null,
|
1599
|
+
showOverlay: () => null
|
1600
|
+
},
|
1269
1601
|
element: null
|
1270
1602
|
};
|
1271
1603
|
const existingNode = s.nodes[id];
|
@@ -1298,11 +1630,11 @@ var createNodesSlice = (set, get) => ({
|
|
1298
1630
|
init_react_import();
|
1299
1631
|
var import_react7 = require("react");
|
1300
1632
|
|
1301
|
-
// ../core/lib/flatten-data.ts
|
1633
|
+
// ../core/lib/data/flatten-data.ts
|
1302
1634
|
init_react_import();
|
1303
1635
|
var flattenData = (state, config) => {
|
1304
1636
|
const data = [];
|
1305
|
-
|
1637
|
+
walkAppState(
|
1306
1638
|
state,
|
1307
1639
|
config,
|
1308
1640
|
(content) => content,
|
@@ -1316,12 +1648,13 @@ var flattenData = (state, config) => {
|
|
1316
1648
|
|
1317
1649
|
// ../core/lib/get-changed.ts
|
1318
1650
|
init_react_import();
|
1651
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1319
1652
|
var getChanged = (newItem, oldItem) => {
|
1320
1653
|
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
1321
1654
|
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
1322
1655
|
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
1323
1656
|
return __spreadProps(__spreadValues({}, acc), {
|
1324
|
-
[item]: oldItemProps[item]
|
1657
|
+
[item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
|
1325
1658
|
});
|
1326
1659
|
}, {}) : {};
|
1327
1660
|
};
|
@@ -1333,12 +1666,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1333
1666
|
const { cache: cache2, globalPermissions } = permissions;
|
1334
1667
|
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
1335
1668
|
var _a, _b, _c;
|
1336
|
-
const {
|
1337
|
-
config: config2,
|
1338
|
-
state: appState,
|
1339
|
-
setComponentLoading,
|
1340
|
-
unsetComponentLoading
|
1341
|
-
} = get();
|
1669
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
1342
1670
|
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
1343
1671
|
if (!componentConfig) {
|
1344
1672
|
return;
|
@@ -1347,14 +1675,14 @@ var createPermissionsSlice = (set, get) => {
|
|
1347
1675
|
if (componentConfig.resolvePermissions) {
|
1348
1676
|
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
1349
1677
|
if (Object.values(changed).some((el) => el === true) || force2) {
|
1350
|
-
setComponentLoading(item2.props.id);
|
1678
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
1351
1679
|
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
1352
1680
|
item2,
|
1353
1681
|
{
|
1354
1682
|
changed,
|
1355
1683
|
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
1356
1684
|
permissions: initialPermissions,
|
1357
|
-
appState,
|
1685
|
+
appState: makeStatePublic(appState),
|
1358
1686
|
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
1359
1687
|
}
|
1360
1688
|
);
|
@@ -1372,7 +1700,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1372
1700
|
})
|
1373
1701
|
})
|
1374
1702
|
});
|
1375
|
-
|
1703
|
+
clearTimeout2();
|
1376
1704
|
}
|
1377
1705
|
}
|
1378
1706
|
});
|
@@ -1382,7 +1710,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1382
1710
|
// Shim the root data in by conforming to component data shape
|
1383
1711
|
{
|
1384
1712
|
type: "root",
|
1385
|
-
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "
|
1713
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
1386
1714
|
},
|
1387
1715
|
force2
|
1388
1716
|
);
|
@@ -1397,7 +1725,6 @@ var createPermissionsSlice = (set, get) => {
|
|
1397
1725
|
} else if (root) {
|
1398
1726
|
resolveDataForRoot(force);
|
1399
1727
|
} else {
|
1400
|
-
resolveDataForRoot(force);
|
1401
1728
|
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
1402
1729
|
yield resolveDataForItem(item2, force);
|
1403
1730
|
}));
|
@@ -1428,7 +1755,7 @@ var createPermissionsSlice = (set, get) => {
|
|
1428
1755
|
} else if (root) {
|
1429
1756
|
const rootConfig = config.root;
|
1430
1757
|
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
1431
|
-
const resolvedForItem = resolvedPermissions["
|
1758
|
+
const resolvedForItem = resolvedPermissions["root"];
|
1432
1759
|
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
1433
1760
|
}
|
1434
1761
|
return globalPermissions;
|
@@ -1445,44 +1772,23 @@ var createFieldsSlice = (_set, _get) => {
|
|
1445
1772
|
return {
|
1446
1773
|
fields: {},
|
1447
1774
|
loading: false,
|
1448
|
-
lastResolvedData: {}
|
1775
|
+
lastResolvedData: {},
|
1776
|
+
id: void 0
|
1449
1777
|
};
|
1450
1778
|
};
|
1451
1779
|
|
1452
1780
|
// ../core/lib/resolve-component-data.ts
|
1453
1781
|
init_react_import();
|
1454
|
-
|
1455
|
-
// ../core/lib/map-slots.ts
|
1456
|
-
init_react_import();
|
1457
|
-
function mapSlots(item, map, recursive = true, isSlot2) {
|
1458
|
-
return __async(this, null, function* () {
|
1459
|
-
const props = __spreadValues({}, item.props);
|
1460
|
-
yield forEachSlot(
|
1461
|
-
item,
|
1462
|
-
(_parentId, propName, content) => __async(this, null, function* () {
|
1463
|
-
const mappedContent = recursive ? yield Promise.all(
|
1464
|
-
content.map((item2) => __async(this, null, function* () {
|
1465
|
-
return yield mapSlots(item2, map, recursive, isSlot2);
|
1466
|
-
}))
|
1467
|
-
) : content;
|
1468
|
-
props[propName] = yield map(mappedContent, propName);
|
1469
|
-
}),
|
1470
|
-
false,
|
1471
|
-
isSlot2
|
1472
|
-
);
|
1473
|
-
return __spreadProps(__spreadValues({}, item), { props });
|
1474
|
-
});
|
1475
|
-
}
|
1476
|
-
|
1477
|
-
// ../core/lib/resolve-component-data.ts
|
1478
|
-
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1782
|
+
var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
|
1479
1783
|
var cache = { lastChange: {} };
|
1480
|
-
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace"
|
1784
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
1481
1785
|
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
1482
|
-
|
1483
|
-
|
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) {
|
1484
1790
|
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
1485
|
-
if (item && (0,
|
1791
|
+
if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
|
1486
1792
|
return { node: resolved, didChange: false };
|
1487
1793
|
}
|
1488
1794
|
const changed = getChanged(item, oldItem);
|
@@ -1492,52 +1798,48 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1492
1798
|
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1493
1799
|
changed,
|
1494
1800
|
lastData: oldItem,
|
1495
|
-
metadata,
|
1801
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1496
1802
|
trigger
|
1497
1803
|
});
|
1498
|
-
|
1499
|
-
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1500
|
-
});
|
1501
|
-
if (recursive) {
|
1502
|
-
resolvedItem = yield mapSlots(
|
1503
|
-
resolvedItem,
|
1504
|
-
(content) => __async(void 0, null, function* () {
|
1505
|
-
return Promise.all(
|
1506
|
-
content.map(
|
1507
|
-
(childItem) => __async(void 0, null, function* () {
|
1508
|
-
return (yield resolveComponentData(
|
1509
|
-
childItem,
|
1510
|
-
config,
|
1511
|
-
metadata,
|
1512
|
-
onResolveStart,
|
1513
|
-
onResolveEnd,
|
1514
|
-
trigger,
|
1515
|
-
false
|
1516
|
-
)).node;
|
1517
|
-
})
|
1518
|
-
)
|
1519
|
-
);
|
1520
|
-
}),
|
1521
|
-
false,
|
1522
|
-
createIsSlotConfig(config)
|
1523
|
-
);
|
1524
|
-
}
|
1804
|
+
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
1525
1805
|
if (Object.keys(readOnly).length) {
|
1526
1806
|
resolvedItem.readOnly = readOnly;
|
1527
1807
|
}
|
1528
|
-
cache.lastChange[id] = {
|
1529
|
-
item,
|
1530
|
-
resolved: resolvedItem
|
1531
|
-
};
|
1532
|
-
if (onResolveEnd) {
|
1533
|
-
onResolveEnd(resolvedItem);
|
1534
|
-
}
|
1535
|
-
return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
|
1536
1808
|
}
|
1537
|
-
|
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
|
+
};
|
1538
1840
|
});
|
1539
1841
|
|
1540
|
-
// ../core/lib/to-root.ts
|
1842
|
+
// ../core/lib/data/to-root.ts
|
1541
1843
|
init_react_import();
|
1542
1844
|
var toRoot = (item) => {
|
1543
1845
|
if ("type" in item && item.type !== "root") {
|
@@ -1554,7 +1856,8 @@ var toRoot = (item) => {
|
|
1554
1856
|
return { props: {}, readOnly };
|
1555
1857
|
};
|
1556
1858
|
|
1557
|
-
// ../core/store/
|
1859
|
+
// ../core/store/default-app-state.ts
|
1860
|
+
init_react_import();
|
1558
1861
|
var defaultAppState = {
|
1559
1862
|
data: { content: [], root: {}, zones: {} },
|
1560
1863
|
ui: {
|
@@ -1580,170 +1883,182 @@ var defaultAppState = {
|
|
1580
1883
|
zones: {}
|
1581
1884
|
}
|
1582
1885
|
};
|
1886
|
+
|
1887
|
+
// ../core/store/index.ts
|
1583
1888
|
var defaultPageFields = {
|
1584
1889
|
title: { type: "text" }
|
1585
1890
|
};
|
1586
1891
|
var createAppStore = (initialAppStore) => create()(
|
1587
|
-
subscribeWithSelector((set, get) =>
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
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
|
1650
1979
|
})
|
1651
|
-
})
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
}
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
1691
|
-
}),
|
1692
|
-
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
1693
|
-
const { config, metadata, setComponentLoading } = get();
|
1694
|
-
return yield resolveComponentData(
|
1695
|
-
componentData,
|
1696
|
-
config,
|
1697
|
-
metadata,
|
1698
|
-
(item) => setComponentLoading(
|
1699
|
-
"id" in item.props ? item.props.id : "root",
|
1700
|
-
true,
|
1701
|
-
50
|
1702
|
-
),
|
1703
|
-
(item) => setComponentLoading(
|
1704
|
-
"id" in item.props ? item.props.id : "root",
|
1705
|
-
false,
|
1706
|
-
0
|
1707
|
-
),
|
1708
|
-
trigger
|
1709
|
-
);
|
1710
|
-
}),
|
1711
|
-
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1712
|
-
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1713
|
-
walkTree(
|
1714
|
-
state,
|
1715
|
-
config,
|
1716
|
-
(content) => content,
|
1717
|
-
(childItem) => {
|
1718
|
-
resolveComponentData2(childItem, "load").then((resolved) => {
|
1719
|
-
const { state: state2 } = get();
|
1720
|
-
const node = state2.indexes.nodes[resolved.node.props.id];
|
1721
|
-
if (node && resolved.didChange) {
|
1722
|
-
if (resolved.node.props.id === "root") {
|
1723
|
-
dispatch({
|
1724
|
-
type: "replaceRoot",
|
1725
|
-
root: toRoot(resolved.node)
|
1726
|
-
});
|
1727
|
-
} else {
|
1728
|
-
const zoneCompound = `${node.parentId}:${node.zone}`;
|
1729
|
-
const parentZone = state2.indexes.zones[zoneCompound];
|
1730
|
-
const index = parentZone.contentIds.indexOf(
|
1731
|
-
resolved.node.props.id
|
1732
|
-
);
|
1733
|
-
dispatch({
|
1734
|
-
type: "replace",
|
1735
|
-
data: resolved.node,
|
1736
|
-
destinationIndex: index,
|
1737
|
-
destinationZone: zoneCompound
|
1738
|
-
});
|
1739
|
-
}
|
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 });
|
1740
2019
|
}
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
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
|
+
})
|
1747
2062
|
);
|
1748
2063
|
var appStoreContext = (0, import_react9.createContext)(createAppStore());
|
1749
2064
|
function useAppStore(selector) {
|
@@ -1805,10 +2120,10 @@ init_react_import();
|
|
1805
2120
|
// ../core/lib/filter.ts
|
1806
2121
|
init_react_import();
|
1807
2122
|
|
1808
|
-
// ../core/lib/reorder.ts
|
2123
|
+
// ../core/lib/data/reorder.ts
|
1809
2124
|
init_react_import();
|
1810
2125
|
|
1811
|
-
// ../core/lib/replace.ts
|
2126
|
+
// ../core/lib/data/replace.ts
|
1812
2127
|
init_react_import();
|
1813
2128
|
|
1814
2129
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
|
@@ -1994,15 +2309,37 @@ var HeadingAnalyzer = () => {
|
|
1994
2309
|
const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
|
1995
2310
|
(0, import_react11.useEffect)(() => {
|
1996
2311
|
const frame = getFrame();
|
1997
|
-
|
1998
|
-
|
1999
|
-
setHierarchy(buildHierarchy(entry));
|
2000
|
-
const observer = new MutationObserver(() => {
|
2312
|
+
let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
|
2313
|
+
const createHierarchy = () => {
|
2001
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
|
+
}
|
2002
2325
|
});
|
2003
|
-
|
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
|
+
}
|
2004
2340
|
return () => {
|
2005
|
-
|
2341
|
+
entryObserver.disconnect();
|
2342
|
+
frameObserver.disconnect();
|
2006
2343
|
};
|
2007
2344
|
}, [data]);
|
2008
2345
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [
|