@measured/puck 0.19.0-canary.61c8658 → 0.19.0-canary.6dc5101e

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