@measured/puck 0.19.4-canary.fde74e8a → 0.20.0-canary.14d96817

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.
@@ -1,963 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __objRest = (source, exclude) => {
25
- var target = {};
26
- for (var prop in source)
27
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
28
- target[prop] = source[prop];
29
- if (source != null && __getOwnPropSymbols)
30
- for (var prop of __getOwnPropSymbols(source)) {
31
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
32
- target[prop] = source[prop];
33
- }
34
- return target;
35
- };
36
- var __esm = (fn, res) => function __init() {
37
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
38
- };
39
- var __commonJS = (cb, mod) => function __require() {
40
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
41
- };
42
- var __copyProps = (to, from, except, desc) => {
43
- if (from && typeof from === "object" || typeof from === "function") {
44
- for (let key of __getOwnPropNames(from))
45
- if (!__hasOwnProp.call(to, key) && key !== except)
46
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
47
- }
48
- return to;
49
- };
50
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
51
- // If the importer is in node compatibility mode or this is not an ESM
52
- // file that has been converted to a CommonJS file using a Babel-
53
- // compatible transform (i.e. "__esModule" has not been set), then set
54
- // "default" to the CommonJS "module.exports" for node compatibility.
55
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
56
- mod
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
- };
78
-
79
- // ../tsup-config/react-import.js
80
- import React from "react";
81
- var init_react_import = __esm({
82
- "../tsup-config/react-import.js"() {
83
- "use strict";
84
- }
85
- });
86
-
87
- // rsc.tsx
88
- init_react_import();
89
-
90
- // components/ServerRender/index.tsx
91
- init_react_import();
92
-
93
- // lib/root-droppable-id.ts
94
- init_react_import();
95
- var rootAreaId = "root";
96
- var rootZone = "default-zone";
97
- var rootDroppableId = `${rootAreaId}:${rootZone}`;
98
-
99
- // lib/data/setup-zone.ts
100
- init_react_import();
101
- var setupZone = (data, zoneKey) => {
102
- if (zoneKey === rootDroppableId) {
103
- return data;
104
- }
105
- const newData = __spreadProps(__spreadValues({}, data), {
106
- zones: data.zones ? __spreadValues({}, data.zones) : {}
107
- });
108
- newData.zones[zoneKey] = newData.zones[zoneKey] || [];
109
- return newData;
110
- };
111
-
112
- // lib/use-slots.tsx
113
- init_react_import();
114
- import { useMemo } from "react";
115
-
116
- // lib/data/map-slots.ts
117
- init_react_import();
118
-
119
- // lib/data/default-slots.ts
120
- init_react_import();
121
- var defaultSlots = (value, fields) => Object.keys(fields).reduce(
122
- (acc, fieldName) => fields[fieldName].type === "slot" ? __spreadValues({ [fieldName]: [] }, acc) : acc,
123
- value
124
- );
125
-
126
- // lib/data/map-slots.ts
127
- var isPromise = (v) => !!v && typeof v.then === "function";
128
- var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
129
- var containsPromise = (arr) => arr.some(isPromise);
130
- var walkField = ({
131
- value,
132
- fields,
133
- map,
134
- propKey = "",
135
- propPath = "",
136
- id = "",
137
- config,
138
- recurseSlots = false
139
- }) => {
140
- var _a, _b, _c;
141
- if (((_a = fields[propKey]) == null ? void 0 : _a.type) === "slot") {
142
- const content = value || [];
143
- const mappedContent = recurseSlots ? content.map((el) => {
144
- var _a2;
145
- const componentConfig = config.components[el.type];
146
- if (!componentConfig) {
147
- throw new Error(`Could not find component config for ${el.type}`);
148
- }
149
- const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
150
- return walkField({
151
- value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
152
- fields: fields2,
153
- map,
154
- id: el.props.id,
155
- config,
156
- recurseSlots
157
- });
158
- }) : content;
159
- if (containsPromise(mappedContent)) {
160
- return Promise.all(mappedContent);
161
- }
162
- return map(mappedContent, id, propPath, fields[propKey], propPath);
163
- }
164
- if (value && typeof value === "object") {
165
- if (Array.isArray(value)) {
166
- const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
167
- if (!arrayFields) return value;
168
- const newValue = value.map(
169
- (el, idx) => walkField({
170
- value: el,
171
- fields: arrayFields,
172
- map,
173
- propKey,
174
- propPath: `${propPath}[${idx}]`,
175
- id,
176
- config,
177
- recurseSlots
178
- })
179
- );
180
- if (containsPromise(newValue)) {
181
- return Promise.all(newValue);
182
- }
183
- return newValue;
184
- } else if ("$$typeof" in value) {
185
- return value;
186
- } else {
187
- const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
188
- return walkObject({
189
- value,
190
- fields: objectFields,
191
- map,
192
- id,
193
- getPropPath: (k) => `${propPath}.${k}`,
194
- config,
195
- recurseSlots
196
- });
197
- }
198
- }
199
- return value;
200
- };
201
- var walkObject = ({
202
- value,
203
- fields,
204
- map,
205
- id,
206
- getPropPath,
207
- config,
208
- recurseSlots
209
- }) => {
210
- const newProps = Object.entries(value).map(([k, v]) => {
211
- const opts = {
212
- value: v,
213
- fields,
214
- map,
215
- propKey: k,
216
- propPath: getPropPath(k),
217
- id,
218
- config,
219
- recurseSlots
220
- };
221
- const newValue = walkField(opts);
222
- if (isPromise(newValue)) {
223
- return newValue.then((resolvedValue) => ({
224
- [k]: resolvedValue
225
- }));
226
- }
227
- return {
228
- [k]: newValue
229
- };
230
- }, {});
231
- if (containsPromise(newProps)) {
232
- return Promise.all(newProps).then(flatten);
233
- }
234
- return flatten(newProps);
235
- };
236
- function mapSlots(item, map, config, recurseSlots = false) {
237
- var _a, _b, _c, _d, _e;
238
- const itemType = "type" in item ? item.type : "root";
239
- const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
240
- const newProps = walkObject({
241
- value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
242
- fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
243
- map,
244
- id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
245
- getPropPath: (k) => k,
246
- config,
247
- recurseSlots
248
- });
249
- if (isPromise(newProps)) {
250
- return newProps.then((resolvedProps) => __spreadProps(__spreadValues({}, item), {
251
- props: resolvedProps
252
- }));
253
- }
254
- return __spreadProps(__spreadValues({}, item), {
255
- props: newProps
256
- });
257
- }
258
-
259
- // lib/use-slots.tsx
260
- function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
261
- const slotProps = useMemo(() => {
262
- const mapped = mapSlots(
263
- item,
264
- (content, _parentId, propName, field, propPath) => {
265
- const wildcardPath = propPath.replace(/\[\d+\]/g, "[*]");
266
- const isReadOnly = (readOnly == null ? void 0 : readOnly[propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly;
267
- const render = isReadOnly ? renderSlotRender : renderSlotEdit;
268
- const Slot = (dzProps) => render(__spreadProps(__spreadValues({
269
- allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
270
- disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
271
- }, dzProps), {
272
- zone: propName,
273
- content
274
- }));
275
- return Slot;
276
- },
277
- config
278
- ).props;
279
- return mapped;
280
- }, [config, item, readOnly, forceReadOnly]);
281
- const mergedProps = useMemo(
282
- () => __spreadValues(__spreadValues({}, item.props), slotProps),
283
- [item.props, slotProps]
284
- );
285
- return mergedProps;
286
- }
287
-
288
- // components/SlotRender/server.tsx
289
- init_react_import();
290
- import { forwardRef } from "react";
291
- import { jsx } from "react/jsx-runtime";
292
- var SlotRenderPure = (props) => /* @__PURE__ */ jsx(SlotRender, __spreadValues({}, props));
293
- var Item = ({
294
- config,
295
- item,
296
- metadata
297
- }) => {
298
- const Component = config.components[item.type];
299
- const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
300
- return /* @__PURE__ */ jsx(
301
- Component.render,
302
- __spreadProps(__spreadValues({}, props), {
303
- puck: __spreadProps(__spreadValues({}, props.puck), {
304
- renderDropZone: DropZoneRender,
305
- metadata: metadata || {}
306
- })
307
- })
308
- );
309
- };
310
- var SlotRender = forwardRef(
311
- function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
312
- return /* @__PURE__ */ jsx("div", { className, style, ref, children: content.map((item) => {
313
- if (!config.components[item.type]) {
314
- return null;
315
- }
316
- return /* @__PURE__ */ jsx(
317
- Item,
318
- {
319
- config,
320
- item,
321
- metadata
322
- },
323
- item.props.id
324
- );
325
- }) });
326
- }
327
- );
328
-
329
- // components/ServerRender/index.tsx
330
- import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
331
- function DropZoneRender({
332
- zone,
333
- data,
334
- areaId = "root",
335
- config,
336
- metadata = {}
337
- }) {
338
- let zoneCompound = rootDroppableId;
339
- let content = (data == null ? void 0 : data.content) || [];
340
- if (!data || !config) {
341
- return null;
342
- }
343
- if (areaId !== rootAreaId && zone !== rootZone) {
344
- zoneCompound = `${areaId}:${zone}`;
345
- content = setupZone(data, zoneCompound).zones[zoneCompound];
346
- }
347
- return /* @__PURE__ */ jsx2(Fragment, { children: content.map((item) => {
348
- const Component = config.components[item.type];
349
- const props = __spreadProps(__spreadValues({}, item.props), {
350
- puck: {
351
- renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx2(
352
- DropZoneRender,
353
- {
354
- zone: zone2,
355
- data,
356
- areaId: item.props.id,
357
- config,
358
- metadata
359
- }
360
- ),
361
- metadata,
362
- dragRef: null,
363
- isEditing: false
364
- }
365
- });
366
- const renderItem = __spreadProps(__spreadValues({}, item), { props });
367
- const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
368
- if (Component) {
369
- return /* @__PURE__ */ jsx2(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
370
- }
371
- return null;
372
- }) });
373
- }
374
- function Render({
375
- config,
376
- data,
377
- metadata = {}
378
- }) {
379
- var _a;
380
- const rootProps = "props" in data.root ? data.root.props : data.root;
381
- const title = rootProps.title || "";
382
- const props = __spreadProps(__spreadValues({}, rootProps), {
383
- puck: {
384
- renderDropZone: ({ zone }) => /* @__PURE__ */ jsx2(
385
- DropZoneRender,
386
- {
387
- zone,
388
- data,
389
- config,
390
- metadata
391
- }
392
- ),
393
- isEditing: false,
394
- dragRef: null,
395
- metadata
396
- },
397
- title,
398
- editMode: false,
399
- id: "puck-root"
400
- });
401
- const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
402
- if ((_a = config.root) == null ? void 0 : _a.render) {
403
- return /* @__PURE__ */ jsx2(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx2(
404
- DropZoneRender,
405
- {
406
- config,
407
- data,
408
- zone: rootZone,
409
- metadata
410
- }
411
- ) }));
412
- }
413
- return /* @__PURE__ */ jsx2(
414
- DropZoneRender,
415
- {
416
- config,
417
- data,
418
- zone: rootZone,
419
- metadata
420
- }
421
- );
422
- }
423
-
424
- // lib/resolve-all-data.ts
425
- init_react_import();
426
-
427
- // lib/resolve-component-data.ts
428
- init_react_import();
429
-
430
- // lib/get-changed.ts
431
- init_react_import();
432
- import fdeq from "fast-deep-equal";
433
- var getChanged = (newItem, oldItem) => {
434
- return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
435
- const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
436
- const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
437
- return __spreadProps(__spreadValues({}, acc), {
438
- [item]: !fdeq(oldItemProps[item], newItemProps[item])
439
- });
440
- }, {}) : {};
441
- };
442
-
443
- // lib/resolve-component-data.ts
444
- import fdeq2 from "fast-deep-equal";
445
- var cache = { lastChange: {} };
446
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
447
- const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
448
- const resolvedItem = __spreadValues({}, item);
449
- const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
450
- const id = "id" in item.props ? item.props.id : "root";
451
- if (shouldRunResolver) {
452
- const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
453
- if (item && fdeq2(item, oldItem)) {
454
- return { node: resolved, didChange: false };
455
- }
456
- const changed = getChanged(item, oldItem);
457
- if (onResolveStart) {
458
- onResolveStart(item);
459
- }
460
- const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
461
- changed,
462
- lastData: oldItem,
463
- metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
464
- trigger
465
- });
466
- resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
467
- if (Object.keys(readOnly).length) {
468
- resolvedItem.readOnly = readOnly;
469
- }
470
- }
471
- let itemWithResolvedChildren = yield mapSlots(
472
- resolvedItem,
473
- (content) => __async(void 0, null, function* () {
474
- return yield Promise.all(
475
- content.map(
476
- (childItem) => __async(void 0, null, function* () {
477
- return (yield resolveComponentData(
478
- childItem,
479
- config,
480
- metadata,
481
- onResolveStart,
482
- onResolveEnd,
483
- trigger
484
- )).node;
485
- })
486
- )
487
- );
488
- }),
489
- config
490
- );
491
- if (shouldRunResolver && onResolveEnd) {
492
- onResolveEnd(resolvedItem);
493
- }
494
- cache.lastChange[id] = {
495
- item,
496
- resolved: itemWithResolvedChildren
497
- };
498
- return {
499
- node: itemWithResolvedChildren,
500
- didChange: !fdeq2(item, itemWithResolvedChildren)
501
- };
502
- });
503
-
504
- // lib/data/default-data.ts
505
- init_react_import();
506
- var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
507
- root: data.root || {},
508
- content: data.content || []
509
- });
510
-
511
- // lib/data/to-component.ts
512
- init_react_import();
513
- var toComponent = (item) => {
514
- return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
515
- props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
516
- type: "root"
517
- });
518
- };
519
-
520
- // lib/resolve-all-data.ts
521
- function resolveAllData(_0, _1) {
522
- return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
523
- var _a;
524
- const defaultedData = defaultData(data);
525
- const resolveNode = (_node) => __async(this, null, function* () {
526
- const node = toComponent(_node);
527
- onResolveStart == null ? void 0 : onResolveStart(node);
528
- const resolved = (yield resolveComponentData(
529
- node,
530
- config,
531
- metadata,
532
- () => {
533
- },
534
- () => {
535
- },
536
- "force"
537
- )).node;
538
- const resolvedDeep = yield mapSlots(
539
- resolved,
540
- processContent,
541
- config
542
- );
543
- onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
544
- return resolvedDeep;
545
- });
546
- const processContent = (content) => __async(this, null, function* () {
547
- return Promise.all(content.map(resolveNode));
548
- });
549
- const processZones = () => __async(this, null, function* () {
550
- var _a2;
551
- const zones = (_a2 = data.zones) != null ? _a2 : {};
552
- Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
553
- zones[zoneKey] = yield Promise.all(content.map(resolveNode));
554
- }));
555
- return zones;
556
- });
557
- const dynamic = {
558
- root: yield resolveNode(defaultedData.root),
559
- content: yield processContent(defaultedData.content),
560
- zones: yield processZones()
561
- };
562
- Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
563
- const content = defaultedData.zones[zoneKey];
564
- dynamic.zones[zoneKey] = yield processContent(content);
565
- }), {});
566
- return dynamic;
567
- });
568
- }
569
-
570
- // lib/transform-props.ts
571
- init_react_import();
572
-
573
- // lib/data/walk-tree.ts
574
- init_react_import();
575
- function walkTree(data, config, callbackFn) {
576
- var _a, _b;
577
- const walkItem = (item) => {
578
- return mapSlots(
579
- item,
580
- (content, parentId, propName) => {
581
- var _a2;
582
- return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
583
- },
584
- config,
585
- true
586
- );
587
- };
588
- if ("props" in data) {
589
- return walkItem(data);
590
- }
591
- const _data = data;
592
- const zones = (_a = _data.zones) != null ? _a : {};
593
- const mappedContent = _data.content.map(walkItem);
594
- return {
595
- root: walkItem(_data.root),
596
- content: (_b = callbackFn(mappedContent, {
597
- parentId: "root",
598
- propName: "default-zone"
599
- })) != null ? _b : mappedContent,
600
- zones: Object.keys(zones).reduce(
601
- (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
602
- [zoneCompound]: zones[zoneCompound].map(walkItem)
603
- }),
604
- {}
605
- )
606
- };
607
- }
608
-
609
- // lib/transform-props.ts
610
- function transformProps(data, propTransforms, config = { components: {} }) {
611
- const mapItem = (item) => {
612
- if (propTransforms[item.type]) {
613
- return __spreadProps(__spreadValues({}, item), {
614
- props: __spreadValues({
615
- id: item.props.id
616
- }, propTransforms[item.type](item.props))
617
- });
618
- }
619
- return item;
620
- };
621
- const defaultedData = defaultData(data);
622
- const rootProps = defaultedData.root.props || defaultedData.root;
623
- let newRoot = __spreadValues({}, defaultedData.root);
624
- if (propTransforms["root"]) {
625
- newRoot.props = propTransforms["root"](rootProps);
626
- }
627
- const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
628
- const updatedData = walkTree(
629
- dataWithUpdatedRoot,
630
- config,
631
- (content) => content.map(mapItem)
632
- );
633
- if (!defaultedData.root.props) {
634
- updatedData.root = updatedData.root.props;
635
- }
636
- return updatedData;
637
- }
638
-
639
- // lib/migrate.ts
640
- init_react_import();
641
-
642
- // store/default-app-state.ts
643
- init_react_import();
644
-
645
- // components/ViewportControls/default-viewports.ts
646
- init_react_import();
647
- var defaultViewports = [
648
- { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
649
- { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
650
- { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
651
- ];
652
-
653
- // store/default-app-state.ts
654
- var defaultAppState = {
655
- data: { content: [], root: {}, zones: {} },
656
- ui: {
657
- leftSideBarVisible: true,
658
- rightSideBarVisible: true,
659
- arrayState: {},
660
- itemSelector: null,
661
- componentList: {},
662
- isDragging: false,
663
- previewMode: "edit",
664
- viewports: {
665
- current: {
666
- width: defaultViewports[0].width,
667
- height: defaultViewports[0].height || "auto"
668
- },
669
- options: [],
670
- controlsVisible: true
671
- },
672
- field: { focus: null }
673
- },
674
- indexes: {
675
- nodes: {},
676
- zones: {}
677
- }
678
- };
679
-
680
- // lib/data/walk-app-state.ts
681
- init_react_import();
682
-
683
- // lib/data/for-related-zones.ts
684
- init_react_import();
685
-
686
- // lib/get-zone-id.ts
687
- init_react_import();
688
- var getZoneId = (zoneCompound) => {
689
- if (!zoneCompound) {
690
- return [];
691
- }
692
- if (zoneCompound && zoneCompound.indexOf(":") > -1) {
693
- return zoneCompound.split(":");
694
- }
695
- return [rootDroppableId, zoneCompound];
696
- };
697
-
698
- // lib/data/for-related-zones.ts
699
- function forRelatedZones(item, data, cb, path = []) {
700
- Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
701
- const [parentId] = getZoneId(zoneCompound);
702
- if (parentId === item.props.id) {
703
- cb(path, zoneCompound, content);
704
- }
705
- });
706
- }
707
-
708
- // lib/data/flatten-node.ts
709
- init_react_import();
710
- import flat from "flat";
711
-
712
- // lib/data/strip-slots.ts
713
- init_react_import();
714
- var stripSlots = (data, config) => {
715
- return mapSlots(data, () => null, config);
716
- };
717
-
718
- // lib/data/flatten-node.ts
719
- var { flatten: flatten2, unflatten } = flat;
720
- var flattenNode = (node, config) => {
721
- return __spreadProps(__spreadValues({}, node), {
722
- props: flatten2(stripSlots(node, config).props)
723
- });
724
- };
725
- var expandNode = (node) => {
726
- const props = unflatten(node.props);
727
- return __spreadProps(__spreadValues({}, node), {
728
- props
729
- });
730
- };
731
-
732
- // lib/data/walk-app-state.ts
733
- function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
734
- var _a;
735
- let newZones = {};
736
- const newZoneIndex = {};
737
- const newNodeIndex = {};
738
- const processContent = (path, zoneCompound, content, zoneType, newId) => {
739
- var _a2;
740
- const [parentId] = zoneCompound.split(":");
741
- const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
742
- const [_2, zone] = zoneCompound.split(":");
743
- const newZoneCompound = `${newId || parentId}:${zone}`;
744
- const newContent2 = mappedContent.map(
745
- (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
746
- );
747
- newZoneIndex[newZoneCompound] = {
748
- contentIds: newContent2.map((item) => item.props.id),
749
- type: zoneType
750
- };
751
- return [newZoneCompound, newContent2];
752
- };
753
- const processRelatedZones = (item, newId, initialPath) => {
754
- forRelatedZones(
755
- item,
756
- state.data,
757
- (relatedPath, relatedZoneCompound, relatedContent) => {
758
- const [zoneCompound, newContent2] = processContent(
759
- relatedPath,
760
- relatedZoneCompound,
761
- relatedContent,
762
- "dropzone",
763
- newId
764
- );
765
- newZones[zoneCompound] = newContent2;
766
- },
767
- initialPath
768
- );
769
- };
770
- const processItem = (item, path, index) => {
771
- const mappedItem = mapNodeOrSkip(item, path, index);
772
- if (!mappedItem) return item;
773
- const id = mappedItem.props.id;
774
- const newProps = __spreadProps(__spreadValues({}, mapSlots(
775
- mappedItem,
776
- (content, parentId2, slotId) => {
777
- const zoneCompound = `${parentId2}:${slotId}`;
778
- const [_2, newContent2] = processContent(
779
- path,
780
- zoneCompound,
781
- content,
782
- "slot",
783
- parentId2
784
- );
785
- return newContent2;
786
- },
787
- config
788
- ).props), {
789
- id
790
- });
791
- processRelatedZones(item, id, path);
792
- const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
793
- const thisZoneCompound = path[path.length - 1];
794
- const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
795
- newNodeIndex[id] = {
796
- data: newItem,
797
- flatData: flattenNode(newItem, config),
798
- path,
799
- parentId,
800
- zone
801
- };
802
- const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
803
- if (newProps.id === "root") {
804
- delete finalData["type"];
805
- delete finalData.props["id"];
806
- }
807
- return finalData;
808
- };
809
- const zones = state.data.zones || {};
810
- const [_, newContent] = processContent(
811
- [],
812
- rootDroppableId,
813
- state.data.content,
814
- "root"
815
- );
816
- const processedContent = newContent;
817
- const zonesAlreadyProcessed = Object.keys(newZones);
818
- Object.keys(zones || {}).forEach((zoneCompound) => {
819
- const [parentId] = zoneCompound.split(":");
820
- if (zonesAlreadyProcessed.includes(zoneCompound)) {
821
- return;
822
- }
823
- const [_2, newContent2] = processContent(
824
- [rootDroppableId],
825
- zoneCompound,
826
- zones[zoneCompound],
827
- "dropzone",
828
- parentId
829
- );
830
- newZones[zoneCompound] = newContent2;
831
- }, newZones);
832
- const processedRoot = processItem(
833
- {
834
- type: "root",
835
- props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
836
- },
837
- [],
838
- -1
839
- );
840
- const root = __spreadProps(__spreadValues({}, state.data.root), {
841
- props: processedRoot.props
842
- });
843
- return __spreadProps(__spreadValues({}, state), {
844
- data: {
845
- root,
846
- content: processedContent,
847
- zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
848
- },
849
- indexes: {
850
- nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
851
- zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
852
- }
853
- });
854
- }
855
-
856
- // lib/migrate.ts
857
- var migrations = [
858
- // Migrate root to root.props
859
- (data) => {
860
- const rootProps = data.root.props || data.root;
861
- if (Object.keys(data.root).length > 0 && !data.root.props) {
862
- console.warn(
863
- "Migration applied: Root props moved from `root` to `root.props`."
864
- );
865
- return __spreadProps(__spreadValues({}, data), {
866
- root: {
867
- props: __spreadValues({}, rootProps)
868
- }
869
- });
870
- }
871
- return data;
872
- },
873
- // Migrate zones to slots
874
- (data, config) => {
875
- var _a;
876
- if (!config) return data;
877
- console.log("Migrating DropZones to slots...");
878
- const updatedItems = {};
879
- const appState = __spreadProps(__spreadValues({}, defaultAppState), { data });
880
- const { indexes } = walkAppState(appState, config);
881
- const deletedCompounds = [];
882
- walkAppState(appState, config, (content, zoneCompound, zoneType) => {
883
- var _a2, _b, _c;
884
- if (zoneType === "dropzone") {
885
- const [id, slotName] = zoneCompound.split(":");
886
- const nodeData = indexes.nodes[id].data;
887
- const componentType = nodeData.type;
888
- const configForComponent = id === "root" ? config.root : config.components[componentType];
889
- if (((_b = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b.type) === "slot") {
890
- updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
891
- props: __spreadProps(__spreadValues(__spreadValues({}, nodeData.props), (_c = updatedItems[id]) == null ? void 0 : _c.props), {
892
- [slotName]: content
893
- })
894
- });
895
- deletedCompounds.push(zoneCompound);
896
- }
897
- return content;
898
- }
899
- return content;
900
- });
901
- const updated = walkAppState(
902
- appState,
903
- config,
904
- (content) => content,
905
- (item) => {
906
- var _a2;
907
- return (_a2 = updatedItems[item.props.id]) != null ? _a2 : item;
908
- }
909
- );
910
- deletedCompounds.forEach((zoneCompound) => {
911
- var _a2;
912
- const [_, propName] = zoneCompound.split(":");
913
- console.log(
914
- `\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
915
- );
916
- (_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
917
- });
918
- Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
919
- const [_, propName] = zoneCompound.split(":");
920
- throw new Error(
921
- `Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
922
- );
923
- });
924
- delete updated.data.zones;
925
- return updated.data;
926
- }
927
- ];
928
- function migrate(data, config) {
929
- return migrations == null ? void 0 : migrations.reduce(
930
- (acc, migration) => migration(acc, config),
931
- data
932
- );
933
- }
934
-
935
- export {
936
- __spreadValues,
937
- __spreadProps,
938
- __objRest,
939
- __commonJS,
940
- __toESM,
941
- __async,
942
- init_react_import,
943
- rootAreaId,
944
- rootZone,
945
- rootDroppableId,
946
- defaultSlots,
947
- walkField,
948
- expandNode,
949
- walkAppState,
950
- walkTree,
951
- setupZone,
952
- useSlots,
953
- SlotRenderPure,
954
- SlotRender,
955
- Render,
956
- getChanged,
957
- resolveComponentData,
958
- resolveAllData,
959
- transformProps,
960
- defaultViewports,
961
- defaultAppState,
962
- migrate
963
- };