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