@measured/puck 0.19.0-canary.1fc19b5 → 0.19.0-canary.22f5e3a3

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