@measured/puck 0.19.0-canary.b918900 → 0.19.0-canary.bc5bfff1

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