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