@measured/puck 0.19.0-canary.a6dd529f → 0.19.0-canary.a967ca42

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.
@@ -0,0 +1,879 @@
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
+ // lib/data/walk-tree.ts
88
+ init_react_import();
89
+
90
+ // lib/data/is-slot.ts
91
+ init_react_import();
92
+ var isSlot = (prop) => {
93
+ var _a, _b;
94
+ return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
95
+ };
96
+ var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
97
+ var _a, _b;
98
+ const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
99
+ if (!configForComponent) return isSlot(propValue);
100
+ return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
101
+ };
102
+
103
+ // lib/data/map-slots.ts
104
+ init_react_import();
105
+ function mapSlotsAsync(_0, _1) {
106
+ return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
107
+ const props = __spreadValues({}, item.props);
108
+ const propKeys = Object.keys(props);
109
+ for (let i = 0; i < propKeys.length; i++) {
110
+ const propKey = propKeys[i];
111
+ const itemType = "type" in item ? item.type : "root";
112
+ if (isSlot2(itemType, propKey, props[propKey])) {
113
+ const content = props[propKey];
114
+ const mappedContent = recursive ? yield Promise.all(
115
+ content.map((item2) => __async(this, null, function* () {
116
+ return yield mapSlotsAsync(item2, map, recursive, isSlot2);
117
+ }))
118
+ ) : content;
119
+ props[propKey] = yield map(mappedContent, propKey);
120
+ }
121
+ }
122
+ return __spreadProps(__spreadValues({}, item), { props });
123
+ });
124
+ }
125
+ function mapSlotsSync(item, map, isSlot2 = isSlot) {
126
+ var _a, _b;
127
+ const props = __spreadValues({}, item.props);
128
+ const propKeys = Object.keys(props);
129
+ for (let i = 0; i < propKeys.length; i++) {
130
+ const propKey = propKeys[i];
131
+ const itemType = "type" in item ? item.type : "root";
132
+ if (isSlot2(itemType, propKey, props[propKey])) {
133
+ const content = props[propKey];
134
+ const mappedContent = content.map((item2) => {
135
+ return mapSlotsSync(item2, map, isSlot2);
136
+ });
137
+ props[propKey] = (_b = map(mappedContent, (_a = props.id) != null ? _a : "root", propKey)) != null ? _b : mappedContent;
138
+ }
139
+ }
140
+ return __spreadProps(__spreadValues({}, item), { props });
141
+ }
142
+
143
+ // lib/data/walk-tree.ts
144
+ function walkTree(data, config, callbackFn) {
145
+ var _a, _b;
146
+ const isSlot2 = createIsSlotConfig(config);
147
+ const walkItem = (item) => {
148
+ return mapSlotsSync(
149
+ item,
150
+ (content, parentId, propName) => callbackFn(content, { parentId, propName }),
151
+ isSlot2
152
+ );
153
+ };
154
+ if ("props" in data) {
155
+ return walkItem(data);
156
+ }
157
+ const _data = data;
158
+ const zones = (_a = _data.zones) != null ? _a : {};
159
+ const mappedContent = _data.content.map(walkItem);
160
+ return {
161
+ root: walkItem(_data.root),
162
+ content: (_b = callbackFn(mappedContent, {
163
+ parentId: "root",
164
+ propName: "default-zone"
165
+ })) != null ? _b : mappedContent,
166
+ zones: Object.keys(zones).reduce(
167
+ (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
168
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
169
+ }),
170
+ {}
171
+ )
172
+ };
173
+ }
174
+
175
+ // components/ServerRender/index.tsx
176
+ init_react_import();
177
+
178
+ // lib/root-droppable-id.ts
179
+ init_react_import();
180
+ var rootAreaId = "root";
181
+ var rootZone = "default-zone";
182
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
183
+
184
+ // lib/data/setup-zone.ts
185
+ init_react_import();
186
+ var setupZone = (data, zoneKey) => {
187
+ if (zoneKey === rootDroppableId) {
188
+ return data;
189
+ }
190
+ const newData = __spreadProps(__spreadValues({}, data), {
191
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
192
+ });
193
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
194
+ return newData;
195
+ };
196
+
197
+ // lib/use-slots.tsx
198
+ init_react_import();
199
+ import { useMemo } from "react";
200
+ function useSlots(config, props, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
201
+ const slotProps = useMemo(() => {
202
+ if (!(config == null ? void 0 : config.fields)) return props;
203
+ const slotProps2 = {};
204
+ const fieldKeys = Object.keys(config.fields);
205
+ for (let i = 0; i < fieldKeys.length; i++) {
206
+ const fieldKey = fieldKeys[i];
207
+ const field = config.fields[fieldKey];
208
+ if ((field == null ? void 0 : field.type) === "slot") {
209
+ const content = props[fieldKey] || [];
210
+ const render = (readOnly == null ? void 0 : readOnly[fieldKey]) || forceReadOnly ? renderSlotRender : renderSlotEdit;
211
+ const Slot = (dzProps) => render(__spreadProps(__spreadValues({
212
+ allow: field.allow,
213
+ disallow: field.disallow
214
+ }, dzProps), {
215
+ zone: fieldKey,
216
+ content
217
+ }));
218
+ slotProps2[fieldKey] = Slot;
219
+ }
220
+ }
221
+ return slotProps2;
222
+ }, [config, readOnly, forceReadOnly]);
223
+ const mergedProps = useMemo(
224
+ () => __spreadValues(__spreadValues({}, props), slotProps),
225
+ [props, slotProps]
226
+ );
227
+ return mergedProps;
228
+ }
229
+
230
+ // components/SlotRender/server.tsx
231
+ init_react_import();
232
+ import { forwardRef } from "react";
233
+ import { jsx } from "react/jsx-runtime";
234
+ var SlotRenderPure = (props) => /* @__PURE__ */ jsx(SlotRender, __spreadValues({}, props));
235
+ var Item = ({
236
+ config,
237
+ item,
238
+ metadata
239
+ }) => {
240
+ const Component = config.components[item.type];
241
+ const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
242
+ return /* @__PURE__ */ jsx(
243
+ Component.render,
244
+ __spreadProps(__spreadValues({}, props), {
245
+ puck: __spreadProps(__spreadValues({}, props.puck), {
246
+ renderDropZone: DropZoneRender,
247
+ metadata: metadata || {}
248
+ })
249
+ })
250
+ );
251
+ };
252
+ var SlotRender = forwardRef(
253
+ function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
254
+ return /* @__PURE__ */ jsx("div", { className, style, ref, children: content.map((item) => {
255
+ if (!config.components[item.type]) {
256
+ return null;
257
+ }
258
+ return /* @__PURE__ */ jsx(
259
+ Item,
260
+ {
261
+ config,
262
+ item,
263
+ metadata
264
+ },
265
+ item.props.id
266
+ );
267
+ }) });
268
+ }
269
+ );
270
+
271
+ // components/ServerRender/index.tsx
272
+ import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
273
+ function DropZoneRender({
274
+ zone,
275
+ data,
276
+ areaId = "root",
277
+ config,
278
+ metadata = {}
279
+ }) {
280
+ let zoneCompound = rootDroppableId;
281
+ let content = (data == null ? void 0 : data.content) || [];
282
+ if (!data || !config) {
283
+ return null;
284
+ }
285
+ if (areaId !== rootAreaId && zone !== rootZone) {
286
+ zoneCompound = `${areaId}:${zone}`;
287
+ content = setupZone(data, zoneCompound).zones[zoneCompound];
288
+ }
289
+ return /* @__PURE__ */ jsx2(Fragment, { children: content.map((item) => {
290
+ const Component = config.components[item.type];
291
+ const props = __spreadProps(__spreadValues({}, item.props), {
292
+ puck: {
293
+ renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx2(
294
+ DropZoneRender,
295
+ {
296
+ zone: zone2,
297
+ data,
298
+ areaId: item.props.id,
299
+ config,
300
+ metadata
301
+ }
302
+ ),
303
+ metadata
304
+ }
305
+ });
306
+ const propsWithSlots = useSlots(Component, props, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
307
+ if (Component) {
308
+ return /* @__PURE__ */ jsx2(Component.render, __spreadValues({}, propsWithSlots), item.props.id);
309
+ }
310
+ return null;
311
+ }) });
312
+ }
313
+ function Render({
314
+ config,
315
+ data,
316
+ metadata = {}
317
+ }) {
318
+ var _a;
319
+ const rootProps = data.root.props || data.root;
320
+ const title = rootProps.title || "";
321
+ const props = __spreadProps(__spreadValues({}, rootProps), {
322
+ puck: {
323
+ renderDropZone: ({ zone }) => /* @__PURE__ */ jsx2(
324
+ DropZoneRender,
325
+ {
326
+ zone,
327
+ data,
328
+ config,
329
+ metadata
330
+ }
331
+ ),
332
+ isEditing: false,
333
+ dragRef: null,
334
+ metadata
335
+ },
336
+ title,
337
+ editMode: false,
338
+ id: "puck-root"
339
+ });
340
+ const propsWithSlots = useSlots(config.root, props, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
341
+ if ((_a = config.root) == null ? void 0 : _a.render) {
342
+ return /* @__PURE__ */ jsx2(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx2(
343
+ DropZoneRender,
344
+ {
345
+ config,
346
+ data,
347
+ zone: rootZone,
348
+ metadata
349
+ }
350
+ ) }));
351
+ }
352
+ return /* @__PURE__ */ jsx2(
353
+ DropZoneRender,
354
+ {
355
+ config,
356
+ data,
357
+ zone: rootZone,
358
+ metadata
359
+ }
360
+ );
361
+ }
362
+
363
+ // lib/migrate.ts
364
+ init_react_import();
365
+
366
+ // store/default-app-state.ts
367
+ init_react_import();
368
+
369
+ // components/ViewportControls/default-viewports.ts
370
+ init_react_import();
371
+ var defaultViewports = [
372
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
373
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
374
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
375
+ ];
376
+
377
+ // store/default-app-state.ts
378
+ var defaultAppState = {
379
+ data: { content: [], root: {}, zones: {} },
380
+ ui: {
381
+ leftSideBarVisible: true,
382
+ rightSideBarVisible: true,
383
+ arrayState: {},
384
+ itemSelector: null,
385
+ componentList: {},
386
+ isDragging: false,
387
+ previewMode: "edit",
388
+ viewports: {
389
+ current: {
390
+ width: defaultViewports[0].width,
391
+ height: defaultViewports[0].height || "auto"
392
+ },
393
+ options: [],
394
+ controlsVisible: true
395
+ },
396
+ field: { focus: null }
397
+ },
398
+ indexes: {
399
+ nodes: {},
400
+ zones: {}
401
+ }
402
+ };
403
+
404
+ // lib/data/walk-app-state.ts
405
+ init_react_import();
406
+
407
+ // lib/data/for-each-slot.ts
408
+ init_react_import();
409
+ var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
410
+ const props = item.props || {};
411
+ const propKeys = Object.keys(props);
412
+ for (let i = 0; i < propKeys.length; i++) {
413
+ const propKey = propKeys[i];
414
+ const itemType = "type" in item ? item.type : "root";
415
+ if (isSlot2(itemType, propKey, props[propKey])) {
416
+ const content = props[propKey];
417
+ cb(props.id, propKey, content);
418
+ if (recursive) {
419
+ content.forEach(
420
+ (childItem) => __async(void 0, null, function* () {
421
+ return forEachSlot(childItem, cb, true, isSlot2);
422
+ })
423
+ );
424
+ }
425
+ }
426
+ }
427
+ };
428
+
429
+ // lib/data/for-related-zones.ts
430
+ init_react_import();
431
+
432
+ // lib/get-zone-id.ts
433
+ init_react_import();
434
+ var getZoneId = (zoneCompound) => {
435
+ if (!zoneCompound) {
436
+ return [];
437
+ }
438
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
439
+ return zoneCompound.split(":");
440
+ }
441
+ return [rootDroppableId, zoneCompound];
442
+ };
443
+
444
+ // lib/data/for-related-zones.ts
445
+ function forRelatedZones(item, data, cb, path = []) {
446
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
447
+ const [parentId] = getZoneId(zoneCompound);
448
+ if (parentId === item.props.id) {
449
+ cb(path, zoneCompound, content);
450
+ }
451
+ });
452
+ }
453
+
454
+ // lib/data/strip-slots.ts
455
+ init_react_import();
456
+ var stripSlots = (data) => {
457
+ return __spreadProps(__spreadValues({}, data), {
458
+ props: Object.entries(data.props).reduce(
459
+ (acc, [propKey, propVal]) => {
460
+ if (isSlot(propVal)) {
461
+ return acc;
462
+ }
463
+ return __spreadProps(__spreadValues({}, acc), { [propKey]: propVal });
464
+ },
465
+ { id: data.props.id }
466
+ )
467
+ });
468
+ };
469
+
470
+ // lib/data/walk-app-state.ts
471
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
472
+ var _a;
473
+ let newZones = {};
474
+ const newZoneIndex = {};
475
+ const newNodeIndex = {};
476
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
477
+ var _a2;
478
+ const [parentId] = zoneCompound.split(":");
479
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
480
+ const [_2, zone] = zoneCompound.split(":");
481
+ const newZoneCompound = `${newId || parentId}:${zone}`;
482
+ const newContent2 = mappedContent.map(
483
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
484
+ );
485
+ newZoneIndex[newZoneCompound] = {
486
+ contentIds: newContent2.map((item) => item.props.id),
487
+ type: zoneType
488
+ };
489
+ return [newZoneCompound, newContent2];
490
+ };
491
+ const processRelatedZones = (item, newId, initialPath) => {
492
+ forRelatedZones(
493
+ item,
494
+ state.data,
495
+ (relatedPath, relatedZoneCompound, relatedContent) => {
496
+ const [zoneCompound, newContent2] = processContent(
497
+ relatedPath,
498
+ relatedZoneCompound,
499
+ relatedContent,
500
+ "dropzone",
501
+ newId
502
+ );
503
+ newZones[zoneCompound] = newContent2;
504
+ },
505
+ initialPath
506
+ );
507
+ };
508
+ const processItem = (item, path, index) => {
509
+ const mappedItem = mapNodeOrSkip(item, path, index);
510
+ if (!mappedItem) return item;
511
+ const id = mappedItem.props.id;
512
+ const newProps = __spreadValues({}, mappedItem.props);
513
+ forEachSlot(
514
+ mappedItem,
515
+ (parentId2, slotId, content) => {
516
+ const zoneCompound = `${parentId2}:${slotId}`;
517
+ const [_2, newContent2] = processContent(
518
+ path,
519
+ zoneCompound,
520
+ content,
521
+ "slot",
522
+ parentId2
523
+ );
524
+ newProps[slotId] = newContent2;
525
+ },
526
+ false,
527
+ createIsSlotConfig(config)
528
+ );
529
+ processRelatedZones(item, id, path);
530
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
531
+ const thisZoneCompound = path[path.length - 1];
532
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
533
+ newNodeIndex[id] = {
534
+ data: newItem,
535
+ flatData: stripSlots(newItem),
536
+ path,
537
+ parentId,
538
+ zone
539
+ };
540
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
541
+ if (newProps.id === "root") {
542
+ delete finalData["type"];
543
+ delete finalData.props["id"];
544
+ }
545
+ return finalData;
546
+ };
547
+ const zones = state.data.zones || {};
548
+ const [_, newContent] = processContent(
549
+ [],
550
+ rootDroppableId,
551
+ state.data.content,
552
+ "root"
553
+ );
554
+ const processedContent = newContent;
555
+ const zonesAlreadyProcessed = Object.keys(newZones);
556
+ Object.keys(zones || {}).forEach((zoneCompound) => {
557
+ const [parentId] = zoneCompound.split(":");
558
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
559
+ return;
560
+ }
561
+ const [_2, newContent2] = processContent(
562
+ [rootDroppableId],
563
+ zoneCompound,
564
+ zones[zoneCompound],
565
+ "dropzone",
566
+ parentId
567
+ );
568
+ newZones[zoneCompound] = newContent2;
569
+ }, newZones);
570
+ const processedRoot = processItem(
571
+ {
572
+ type: "root",
573
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
574
+ },
575
+ [],
576
+ -1
577
+ );
578
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
579
+ props: processedRoot.props
580
+ });
581
+ return __spreadProps(__spreadValues({}, state), {
582
+ data: {
583
+ root,
584
+ content: processedContent,
585
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
586
+ },
587
+ indexes: {
588
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
589
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
590
+ }
591
+ });
592
+ }
593
+
594
+ // lib/migrate.ts
595
+ var migrations = [
596
+ // Migrate root to root.props
597
+ (data) => {
598
+ const rootProps = data.root.props || data.root;
599
+ if (Object.keys(data.root).length > 0 && !data.root.props) {
600
+ console.warn(
601
+ "Migration applied: Root props moved from `root` to `root.props`."
602
+ );
603
+ return __spreadProps(__spreadValues({}, data), {
604
+ root: {
605
+ props: __spreadValues({}, rootProps)
606
+ }
607
+ });
608
+ }
609
+ return data;
610
+ },
611
+ // Migrate zones to slots
612
+ (data, config) => {
613
+ var _a;
614
+ if (!config) return data;
615
+ console.log("Migrating DropZones to slots...");
616
+ const updatedItems = {};
617
+ const appState = __spreadProps(__spreadValues({}, defaultAppState), { data });
618
+ const { indexes } = walkAppState(appState, config);
619
+ const deletedCompounds = [];
620
+ walkAppState(appState, config, (content, zoneCompound, zoneType) => {
621
+ var _a2, _b;
622
+ if (zoneType === "dropzone") {
623
+ const [id, slotName] = zoneCompound.split(":");
624
+ const nodeData = indexes.nodes[id].data;
625
+ const componentType = nodeData.type;
626
+ const configForComponent = id === "root" ? config.root : config.components[componentType];
627
+ if (((_b = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b.type) === "slot") {
628
+ updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
629
+ props: __spreadProps(__spreadValues({}, nodeData.props), {
630
+ [slotName]: content
631
+ })
632
+ });
633
+ deletedCompounds.push(zoneCompound);
634
+ }
635
+ return content;
636
+ }
637
+ return content;
638
+ });
639
+ const updated = walkAppState(
640
+ appState,
641
+ config,
642
+ (content) => content,
643
+ (item) => {
644
+ var _a2;
645
+ return (_a2 = updatedItems[item.props.id]) != null ? _a2 : item;
646
+ }
647
+ );
648
+ deletedCompounds.forEach((zoneCompound) => {
649
+ var _a2;
650
+ const [_, propName] = zoneCompound.split(":");
651
+ console.log(
652
+ `\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
653
+ );
654
+ (_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
655
+ });
656
+ Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
657
+ const [_, propName] = zoneCompound.split(":");
658
+ throw new Error(
659
+ `Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
660
+ );
661
+ });
662
+ delete updated.data.zones;
663
+ return updated.data;
664
+ }
665
+ ];
666
+ function migrate(data, config) {
667
+ return migrations == null ? void 0 : migrations.reduce(
668
+ (acc, migration) => migration(acc, config),
669
+ data
670
+ );
671
+ }
672
+
673
+ // lib/transform-props.ts
674
+ init_react_import();
675
+
676
+ // lib/data/default-data.ts
677
+ init_react_import();
678
+ var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
679
+ root: data.root || {},
680
+ content: data.content || []
681
+ });
682
+
683
+ // lib/transform-props.ts
684
+ function transformProps(data, propTransforms, config = { components: {} }) {
685
+ const mapItem = (item) => {
686
+ if (propTransforms[item.type]) {
687
+ return __spreadProps(__spreadValues({}, item), {
688
+ props: __spreadValues({
689
+ id: item.props.id
690
+ }, propTransforms[item.type](item.props))
691
+ });
692
+ }
693
+ return item;
694
+ };
695
+ const defaultedData = defaultData(data);
696
+ const rootProps = defaultedData.root.props || defaultedData.root;
697
+ let newRoot = __spreadValues({}, defaultedData.root);
698
+ if (propTransforms["root"]) {
699
+ newRoot.props = propTransforms["root"](rootProps);
700
+ }
701
+ const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
702
+ const updatedData = walkTree(
703
+ dataWithUpdatedRoot,
704
+ config,
705
+ (content) => content.map(mapItem)
706
+ );
707
+ if (!defaultedData.root.props) {
708
+ updatedData.root = updatedData.root.props;
709
+ }
710
+ return updatedData;
711
+ }
712
+
713
+ // lib/resolve-all-data.ts
714
+ init_react_import();
715
+
716
+ // lib/resolve-component-data.ts
717
+ init_react_import();
718
+
719
+ // lib/get-changed.ts
720
+ init_react_import();
721
+ var getChanged = (newItem, oldItem) => {
722
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
723
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
724
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
725
+ return __spreadProps(__spreadValues({}, acc), {
726
+ [item]: oldItemProps[item] !== newItemProps[item]
727
+ });
728
+ }, {}) : {};
729
+ };
730
+
731
+ // lib/resolve-component-data.ts
732
+ import fdeq from "fast-deep-equal";
733
+ var cache = { lastChange: {} };
734
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
735
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
736
+ if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
737
+ const id = "id" in item.props ? item.props.id : "root";
738
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
739
+ if (item && fdeq(item, oldItem)) {
740
+ return { node: resolved, didChange: false };
741
+ }
742
+ const changed = getChanged(item, oldItem);
743
+ if (onResolveStart) {
744
+ onResolveStart(item);
745
+ }
746
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
747
+ changed,
748
+ lastData: oldItem,
749
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
750
+ trigger
751
+ });
752
+ let resolvedItem = __spreadProps(__spreadValues({}, item), {
753
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
754
+ });
755
+ if (recursive) {
756
+ resolvedItem = yield mapSlotsAsync(
757
+ resolvedItem,
758
+ (content) => __async(void 0, null, function* () {
759
+ return Promise.all(
760
+ content.map(
761
+ (childItem) => __async(void 0, null, function* () {
762
+ return (yield resolveComponentData(
763
+ childItem,
764
+ config,
765
+ metadata,
766
+ onResolveStart,
767
+ onResolveEnd,
768
+ trigger,
769
+ false
770
+ )).node;
771
+ })
772
+ )
773
+ );
774
+ }),
775
+ false,
776
+ createIsSlotConfig(config)
777
+ );
778
+ }
779
+ if (Object.keys(readOnly).length) {
780
+ resolvedItem.readOnly = readOnly;
781
+ }
782
+ cache.lastChange[id] = {
783
+ item,
784
+ resolved: resolvedItem
785
+ };
786
+ if (onResolveEnd) {
787
+ onResolveEnd(resolvedItem);
788
+ }
789
+ return { node: resolvedItem, didChange: !fdeq(item, resolvedItem) };
790
+ }
791
+ return { node: item, didChange: false };
792
+ });
793
+
794
+ // lib/data/to-component.ts
795
+ init_react_import();
796
+ var toComponent = (item) => {
797
+ return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
798
+ props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
799
+ type: "root"
800
+ });
801
+ };
802
+
803
+ // lib/resolve-all-data.ts
804
+ function resolveAllData(_0, _1) {
805
+ return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
806
+ var _a;
807
+ const defaultedData = defaultData(data);
808
+ const resolveNode = (_node) => __async(this, null, function* () {
809
+ const node = toComponent(_node);
810
+ onResolveStart == null ? void 0 : onResolveStart(node);
811
+ const resolved = (yield resolveComponentData(
812
+ node,
813
+ config,
814
+ metadata,
815
+ () => {
816
+ },
817
+ () => {
818
+ },
819
+ "force",
820
+ false
821
+ )).node;
822
+ const resolvedDeep = yield mapSlotsAsync(
823
+ resolved,
824
+ processContent,
825
+ false
826
+ );
827
+ onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
828
+ return resolvedDeep;
829
+ });
830
+ const processContent = (content) => __async(this, null, function* () {
831
+ return Promise.all(content.map(resolveNode));
832
+ });
833
+ const processZones = () => __async(this, null, function* () {
834
+ var _a2;
835
+ const zones = (_a2 = data.zones) != null ? _a2 : {};
836
+ Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
837
+ zones[zoneKey] = yield Promise.all(content.map(resolveNode));
838
+ }));
839
+ return zones;
840
+ });
841
+ const dynamic = {
842
+ root: yield resolveNode(defaultedData.root),
843
+ content: yield processContent(defaultedData.content),
844
+ zones: yield processZones()
845
+ };
846
+ Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
847
+ const content = defaultedData.zones[zoneKey];
848
+ dynamic.zones[zoneKey] = yield processContent(content);
849
+ }), {});
850
+ return dynamic;
851
+ });
852
+ }
853
+
854
+ export {
855
+ __spreadValues,
856
+ __spreadProps,
857
+ __objRest,
858
+ __commonJS,
859
+ __toESM,
860
+ __async,
861
+ init_react_import,
862
+ rootAreaId,
863
+ rootZone,
864
+ rootDroppableId,
865
+ walkAppState,
866
+ walkTree,
867
+ setupZone,
868
+ defaultViewports,
869
+ getChanged,
870
+ resolveComponentData,
871
+ defaultAppState,
872
+ useSlots,
873
+ Render,
874
+ SlotRenderPure,
875
+ SlotRender,
876
+ migrate,
877
+ transformProps,
878
+ resolveAllData
879
+ };