@measured/puck 0.21.0-canary.bd7b613d → 0.21.0-canary.c0db75c1

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