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