@measured/puck 0.20.0-canary.755737e8 → 0.20.0-canary.7ccbeece

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,56 @@
1
+ import {
2
+ Action,
3
+ ActionBar,
4
+ AutoField,
5
+ Button,
6
+ Drawer,
7
+ DropZone,
8
+ FieldLabel,
9
+ Group,
10
+ IconButton,
11
+ Label,
12
+ Puck,
13
+ Render,
14
+ createUsePuck,
15
+ overrideKeys,
16
+ registerOverlayPortal,
17
+ renderContext,
18
+ setDeep,
19
+ useGetPuck,
20
+ usePuck
21
+ } from "./chunk-AR5UHF65.mjs";
22
+ import {
23
+ init_react_import,
24
+ migrate,
25
+ resolveAllData,
26
+ transformProps,
27
+ walkTree
28
+ } from "./chunk-HUKJ36SA.mjs";
29
+
30
+ // bundle/no-external.ts
31
+ init_react_import();
32
+ export {
33
+ Action,
34
+ ActionBar,
35
+ AutoField,
36
+ Button,
37
+ Drawer,
38
+ DropZone,
39
+ FieldLabel,
40
+ Group,
41
+ IconButton,
42
+ Label,
43
+ Puck,
44
+ Render,
45
+ createUsePuck,
46
+ migrate,
47
+ overrideKeys,
48
+ registerOverlayPortal,
49
+ renderContext,
50
+ resolveAllData,
51
+ setDeep,
52
+ transformProps,
53
+ useGetPuck,
54
+ usePuck,
55
+ walkTree
56
+ };
package/dist/rsc.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-6PP75PCU.mjs';
3
- export { af as migrate, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-6PP75PCU.mjs';
2
+ import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-B57SgEEc.mjs';
3
+ export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-B57SgEEc.mjs';
4
4
  import 'react';
5
5
 
6
6
  declare function Render<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ config, data, metadata, }: {
package/dist/rsc.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-6PP75PCU.js';
3
- export { af as migrate, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-6PP75PCU.js';
2
+ import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-B57SgEEc.js';
3
+ export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-B57SgEEc.js';
4
4
  import 'react';
5
5
 
6
6
  declare function Render<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ config, data, metadata, }: {
package/dist/rsc.js CHANGED
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
22
22
  return a;
23
23
  };
24
24
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
25
37
  var __export = (target, all) => {
26
38
  for (var name in all)
27
39
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -64,7 +76,7 @@ var __async = (__this, __arguments, generator) => {
64
76
  });
65
77
  };
66
78
 
67
- // rsc.tsx
79
+ // bundle/rsc.tsx
68
80
  var rsc_exports = {};
69
81
  __export(rsc_exports, {
70
82
  Render: () => Render,
@@ -95,7 +107,7 @@ var setupZone = (data, zoneKey) => {
95
107
  return newData;
96
108
  };
97
109
 
98
- // lib/use-slots.tsx
110
+ // lib/field-transforms/use-field-transforms.tsx
99
111
  var import_react2 = require("react");
100
112
 
101
113
  // lib/data/default-slots.ts
@@ -104,14 +116,14 @@ var defaultSlots = (value, fields) => Object.keys(fields).reduce(
104
116
  value
105
117
  );
106
118
 
107
- // lib/data/map-slots.ts
119
+ // lib/data/map-fields.ts
108
120
  var isPromise = (v) => !!v && typeof v.then === "function";
109
121
  var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
110
122
  var containsPromise = (arr) => arr.some(isPromise);
111
123
  var walkField = ({
112
124
  value,
113
125
  fields,
114
- map,
126
+ mappers,
115
127
  propKey = "",
116
128
  propPath = "",
117
129
  id = "",
@@ -119,7 +131,9 @@ var walkField = ({
119
131
  recurseSlots = false
120
132
  }) => {
121
133
  var _a, _b, _c;
122
- if (((_a = fields[propKey]) == null ? void 0 : _a.type) === "slot") {
134
+ const fieldType = (_a = fields[propKey]) == null ? void 0 : _a.type;
135
+ const map = mappers[fieldType];
136
+ if (map && fieldType === "slot") {
123
137
  const content = value || [];
124
138
  const mappedContent = recurseSlots ? content.map((el) => {
125
139
  var _a2;
@@ -131,7 +145,7 @@ var walkField = ({
131
145
  return walkField({
132
146
  value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
133
147
  fields: fields2,
134
- map,
148
+ mappers,
135
149
  id: el.props.id,
136
150
  config,
137
151
  recurseSlots
@@ -140,7 +154,21 @@ var walkField = ({
140
154
  if (containsPromise(mappedContent)) {
141
155
  return Promise.all(mappedContent);
142
156
  }
143
- return map(mappedContent, id, propPath, fields[propKey], propPath);
157
+ return map({
158
+ value: mappedContent,
159
+ parentId: id,
160
+ propName: propKey,
161
+ field: fields[propKey],
162
+ propPath
163
+ });
164
+ } else if (map && fields[propKey]) {
165
+ return map({
166
+ value,
167
+ parentId: id,
168
+ propName: propKey,
169
+ field: fields[propKey],
170
+ propPath
171
+ });
144
172
  }
145
173
  if (value && typeof value === "object") {
146
174
  if (Array.isArray(value)) {
@@ -150,7 +178,7 @@ var walkField = ({
150
178
  (el, idx) => walkField({
151
179
  value: el,
152
180
  fields: arrayFields,
153
- map,
181
+ mappers,
154
182
  propKey,
155
183
  propPath: `${propPath}[${idx}]`,
156
184
  id,
@@ -169,7 +197,7 @@ var walkField = ({
169
197
  return walkObject({
170
198
  value,
171
199
  fields: objectFields,
172
- map,
200
+ mappers,
173
201
  id,
174
202
  getPropPath: (k) => `${propPath}.${k}`,
175
203
  config,
@@ -182,7 +210,7 @@ var walkField = ({
182
210
  var walkObject = ({
183
211
  value,
184
212
  fields,
185
- map,
213
+ mappers,
186
214
  id,
187
215
  getPropPath,
188
216
  config,
@@ -192,7 +220,7 @@ var walkObject = ({
192
220
  const opts = {
193
221
  value: v,
194
222
  fields,
195
- map,
223
+ mappers,
196
224
  propKey: k,
197
225
  propPath: getPropPath(k),
198
226
  id,
@@ -214,14 +242,14 @@ var walkObject = ({
214
242
  }
215
243
  return flatten(newProps);
216
244
  };
217
- function mapSlots(item, map, config, recurseSlots = false) {
245
+ function mapFields(item, mappers, config, recurseSlots = false) {
218
246
  var _a, _b, _c, _d, _e;
219
247
  const itemType = "type" in item ? item.type : "root";
220
248
  const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
221
249
  const newProps = walkObject({
222
250
  value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
223
251
  fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
224
- map,
252
+ mappers,
225
253
  id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
226
254
  getPropPath: (k) => k,
227
255
  config,
@@ -237,35 +265,66 @@ function mapSlots(item, map, config, recurseSlots = false) {
237
265
  });
238
266
  }
239
267
 
240
- // lib/use-slots.tsx
241
- function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
242
- const slotProps = (0, import_react2.useMemo)(() => {
243
- const mapped = mapSlots(
244
- item,
245
- (content, _parentId, propName, field, propPath) => {
246
- const wildcardPath = propPath.replace(/\[\d+\]/g, "[*]");
247
- const isReadOnly = (readOnly == null ? void 0 : readOnly[propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly;
248
- const render = isReadOnly ? renderSlotRender : renderSlotEdit;
249
- const Slot = (dzProps) => render(__spreadProps(__spreadValues({
250
- allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
251
- disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
252
- }, dzProps), {
253
- zone: propName,
254
- content
255
- }));
256
- return Slot;
257
- },
258
- config
259
- ).props;
268
+ // lib/field-transforms/use-field-transforms.tsx
269
+ function useFieldTransforms(config, item, transforms, readOnly, forceReadOnly) {
270
+ const mappers = (0, import_react2.useMemo)(() => {
271
+ return Object.keys(transforms).reduce((acc, _fieldType) => {
272
+ const fieldType = _fieldType;
273
+ return __spreadProps(__spreadValues({}, acc), {
274
+ [fieldType]: (_a) => {
275
+ var _b = _a, {
276
+ parentId
277
+ } = _b, params = __objRest(_b, [
278
+ "parentId"
279
+ ]);
280
+ const wildcardPath = params.propPath.replace(/\[\d+\]/g, "[*]");
281
+ const isReadOnly = (readOnly == null ? void 0 : readOnly[params.propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly || false;
282
+ const fn = transforms[fieldType];
283
+ return fn == null ? void 0 : fn(__spreadProps(__spreadValues({}, params), {
284
+ isReadOnly,
285
+ componentId: parentId
286
+ }));
287
+ }
288
+ });
289
+ }, {});
290
+ }, [transforms, readOnly, forceReadOnly]);
291
+ const transformedProps = (0, import_react2.useMemo)(() => {
292
+ const mapped = mapFields(item, mappers, config).props;
260
293
  return mapped;
261
- }, [config, item, readOnly, forceReadOnly]);
294
+ }, [config, item, mappers]);
262
295
  const mergedProps = (0, import_react2.useMemo)(
263
- () => __spreadValues(__spreadValues({}, item.props), slotProps),
264
- [item.props, slotProps]
296
+ () => __spreadValues(__spreadValues({}, item.props), transformedProps),
297
+ [item.props, transformedProps]
265
298
  );
266
299
  return mergedProps;
267
300
  }
268
301
 
302
+ // lib/field-transforms/default-transforms/slot-transform.tsx
303
+ var getSlotTransform = (renderSlotEdit, renderSlotRender = renderSlotEdit) => ({
304
+ slot: ({ value: content, propName, field, isReadOnly }) => {
305
+ const render = isReadOnly ? renderSlotRender : renderSlotEdit;
306
+ const Slot = (dzProps) => render(__spreadProps(__spreadValues({
307
+ allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
308
+ disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
309
+ }, dzProps), {
310
+ zone: propName,
311
+ content
312
+ }));
313
+ return Slot;
314
+ }
315
+ });
316
+
317
+ // lib/use-slots.tsx
318
+ function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
319
+ return useFieldTransforms(
320
+ config,
321
+ item,
322
+ getSlotTransform(renderSlotEdit, renderSlotRender),
323
+ readOnly,
324
+ forceReadOnly
325
+ );
326
+ }
327
+
269
328
  // components/SlotRender/server.tsx
270
329
  var import_react3 = require("react");
271
330
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -441,24 +500,27 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
441
500
  resolvedItem.readOnly = readOnly;
442
501
  }
443
502
  }
444
- let itemWithResolvedChildren = yield mapSlots(
503
+ let itemWithResolvedChildren = yield mapFields(
445
504
  resolvedItem,
446
- (content) => __async(void 0, null, function* () {
447
- return yield Promise.all(
448
- content.map(
449
- (childItem) => __async(void 0, null, function* () {
450
- return (yield resolveComponentData(
451
- childItem,
452
- config,
453
- metadata,
454
- onResolveStart,
455
- onResolveEnd,
456
- trigger
457
- )).node;
458
- })
459
- )
460
- );
461
- }),
505
+ {
506
+ slot: (_02) => __async(void 0, [_02], function* ({ value }) {
507
+ const content = value;
508
+ return yield Promise.all(
509
+ content.map(
510
+ (childItem) => __async(void 0, null, function* () {
511
+ return (yield resolveComponentData(
512
+ childItem,
513
+ config,
514
+ metadata,
515
+ onResolveStart,
516
+ onResolveEnd,
517
+ trigger
518
+ )).node;
519
+ })
520
+ )
521
+ );
522
+ })
523
+ },
462
524
  config
463
525
  );
464
526
  if (shouldRunResolver && onResolveEnd) {
@@ -506,9 +568,9 @@ function resolveAllData(_0, _1) {
506
568
  },
507
569
  "force"
508
570
  )).node;
509
- const resolvedDeep = yield mapSlots(
571
+ const resolvedDeep = yield mapFields(
510
572
  resolved,
511
- processContent,
573
+ { slot: ({ value }) => processContent(value) },
512
574
  config
513
575
  );
514
576
  onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
@@ -542,11 +604,14 @@ function resolveAllData(_0, _1) {
542
604
  function walkTree(data, config, callbackFn) {
543
605
  var _a, _b;
544
606
  const walkItem = (item) => {
545
- return mapSlots(
607
+ return mapFields(
546
608
  item,
547
- (content, parentId, propName) => {
548
- var _a2;
549
- return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
609
+ {
610
+ slot: ({ value, parentId, propName }) => {
611
+ var _a2;
612
+ const content = value;
613
+ return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
614
+ }
550
615
  },
551
616
  config,
552
617
  true
@@ -663,7 +728,7 @@ var import_flat = __toESM(require("flat"));
663
728
 
664
729
  // lib/data/strip-slots.ts
665
730
  var stripSlots = (data, config) => {
666
- return mapSlots(data, () => null, config);
731
+ return mapFields(data, { slot: () => null }, config);
667
732
  };
668
733
 
669
734
  // lib/data/flatten-node.ts
@@ -716,18 +781,21 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
716
781
  const mappedItem = mapNodeOrSkip(item, path, index);
717
782
  if (!mappedItem) return item;
718
783
  const id = mappedItem.props.id;
719
- const newProps = __spreadProps(__spreadValues({}, mapSlots(
784
+ const newProps = __spreadProps(__spreadValues({}, mapFields(
720
785
  mappedItem,
721
- (content, parentId2, slotId) => {
722
- const zoneCompound = `${parentId2}:${slotId}`;
723
- const [_2, newContent2] = processContent(
724
- path,
725
- zoneCompound,
726
- content,
727
- "slot",
728
- parentId2
729
- );
730
- return newContent2;
786
+ {
787
+ slot: ({ value, parentId: parentId2, propPath }) => {
788
+ const content = value;
789
+ const zoneCompound = `${parentId2}:${propPath}`;
790
+ const [_2, newContent2] = processContent(
791
+ path,
792
+ zoneCompound,
793
+ content,
794
+ "slot",
795
+ parentId2
796
+ );
797
+ return newContent2;
798
+ }
731
799
  },
732
800
  config
733
801
  ).props), {
@@ -816,8 +884,8 @@ var migrations = [
816
884
  return data;
817
885
  },
818
886
  // Migrate zones to slots
819
- (data, config) => {
820
- var _a;
887
+ (data, config, migrationOptions) => {
888
+ var _a, _b;
821
889
  if (!config) return data;
822
890
  console.log("Migrating DropZones to slots...");
823
891
  const updatedItems = {};
@@ -825,13 +893,13 @@ var migrations = [
825
893
  const { indexes } = walkAppState(appState, config);
826
894
  const deletedCompounds = [];
827
895
  walkAppState(appState, config, (content, zoneCompound, zoneType) => {
828
- var _a2, _b, _c;
896
+ var _a2, _b2, _c;
829
897
  if (zoneType === "dropzone") {
830
898
  const [id, slotName] = zoneCompound.split(":");
831
899
  const nodeData = indexes.nodes[id].data;
832
900
  const componentType = nodeData.type;
833
901
  const configForComponent = id === "root" ? config.root : config.components[componentType];
834
- if (((_b = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b.type) === "slot") {
902
+ if (((_b2 = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b2.type) === "slot") {
835
903
  updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
836
904
  props: __spreadProps(__spreadValues(__spreadValues({}, nodeData.props), (_c = updatedItems[id]) == null ? void 0 : _c.props), {
837
905
  [slotName]: content
@@ -860,7 +928,49 @@ var migrations = [
860
928
  );
861
929
  (_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
862
930
  });
863
- Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
931
+ if (migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) {
932
+ const unmigratedZonesGrouped = {};
933
+ Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
934
+ var _a2;
935
+ const [componentId, propName] = zoneCompound.split(":");
936
+ const content = (_a2 = updated.data.zones) == null ? void 0 : _a2[zoneCompound];
937
+ if (!content) {
938
+ return;
939
+ }
940
+ if (!unmigratedZonesGrouped[componentId]) {
941
+ unmigratedZonesGrouped[componentId] = {};
942
+ }
943
+ if (!unmigratedZonesGrouped[componentId][propName]) {
944
+ unmigratedZonesGrouped[componentId][propName] = content;
945
+ }
946
+ });
947
+ Object.keys(unmigratedZonesGrouped).forEach((componentId) => {
948
+ updated.data = walkTree(updated.data, config, (content) => {
949
+ return content.map((child) => {
950
+ var _a2;
951
+ if (child.props.id !== componentId) {
952
+ return child;
953
+ }
954
+ const migrateFn = (_a2 = migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) == null ? void 0 : _a2[child.type];
955
+ if (!migrateFn) {
956
+ return child;
957
+ }
958
+ const zones = unmigratedZonesGrouped[componentId];
959
+ const migratedProps = migrateFn(child.props, zones);
960
+ Object.keys(zones).forEach((propName) => {
961
+ var _a3;
962
+ const zoneCompound = `${componentId}:${propName}`;
963
+ console.log(`\u2713 Success: Migrated "${zoneCompound}" DropZone`);
964
+ (_a3 = updated.data.zones) == null ? true : delete _a3[zoneCompound];
965
+ });
966
+ return __spreadProps(__spreadValues({}, child), {
967
+ props: migratedProps
968
+ });
969
+ });
970
+ });
971
+ });
972
+ }
973
+ Object.keys((_b = updated.data.zones) != null ? _b : {}).forEach((zoneCompound) => {
864
974
  const [_, propName] = zoneCompound.split(":");
865
975
  throw new Error(
866
976
  `Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
@@ -870,9 +980,9 @@ var migrations = [
870
980
  return updated.data;
871
981
  }
872
982
  ];
873
- function migrate(data, config) {
983
+ function migrate(data, config, migrationOptions) {
874
984
  return migrations == null ? void 0 : migrations.reduce(
875
- (acc, migration) => migration(acc, config),
985
+ (acc, migration) => migration(acc, config, migrationOptions),
876
986
  data
877
987
  );
878
988
  }
package/dist/rsc.mjs CHANGED
@@ -1,10 +1,14 @@
1
1
  import {
2
2
  Render,
3
+ init_react_import,
3
4
  migrate,
4
5
  resolveAllData,
5
6
  transformProps,
6
7
  walkTree
7
- } from "./chunk-IM42S4YL.mjs";
8
+ } from "./chunk-HUKJ36SA.mjs";
9
+
10
+ // bundle/rsc.tsx
11
+ init_react_import();
8
12
  export {
9
13
  Render,
10
14
  migrate,