@measured/puck 0.20.0-canary.274fe3d9 → 0.20.0-canary.29cd4d52

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.
@@ -13,17 +13,19 @@ import {
13
13
  Render,
14
14
  createUsePuck,
15
15
  overrideKeys,
16
+ registerOverlayPortal,
16
17
  renderContext,
18
+ setDeep,
17
19
  useGetPuck,
18
20
  usePuck
19
- } from "./chunk-4KAREQPB.mjs";
21
+ } from "./chunk-DCZ7BU3G.mjs";
20
22
  import {
21
23
  init_react_import,
22
24
  migrate,
23
25
  resolveAllData,
24
26
  transformProps,
25
27
  walkTree
26
- } from "./chunk-32MJ3X3H.mjs";
28
+ } from "./chunk-NFK5JVZW.mjs";
27
29
 
28
30
  // bundle/no-external.ts
29
31
  init_react_import();
@@ -43,8 +45,10 @@ export {
43
45
  createUsePuck,
44
46
  migrate,
45
47
  overrideKeys,
48
+ registerOverlayPortal,
46
49
  renderContext,
47
50
  resolveAllData,
51
+ setDeep,
48
52
  transformProps,
49
53
  useGetPuck,
50
54
  usePuck,
package/dist/rsc.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-DrNRq2FV.mjs';
3
- export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-DrNRq2FV.mjs';
2
+ import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-CiAkCQEp.mjs';
3
+ export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-CiAkCQEp.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 { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-DrNRq2FV.js';
3
- export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-DrNRq2FV.js';
2
+ import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-CiAkCQEp.js';
3
+ export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-CiAkCQEp.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 });
@@ -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");
@@ -281,7 +340,6 @@ var Item = ({
281
340
  Component.render,
282
341
  __spreadProps(__spreadValues({}, props), {
283
342
  puck: __spreadProps(__spreadValues({}, props.puck), {
284
- renderDropZone: DropZoneRender,
285
343
  metadata: metadata || {}
286
344
  })
287
345
  })
@@ -441,24 +499,27 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
441
499
  resolvedItem.readOnly = readOnly;
442
500
  }
443
501
  }
444
- let itemWithResolvedChildren = yield mapSlots(
502
+ let itemWithResolvedChildren = yield mapFields(
445
503
  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
- }),
504
+ {
505
+ slot: (_02) => __async(void 0, [_02], function* ({ value }) {
506
+ const content = value;
507
+ return yield Promise.all(
508
+ content.map(
509
+ (childItem) => __async(void 0, null, function* () {
510
+ return (yield resolveComponentData(
511
+ childItem,
512
+ config,
513
+ metadata,
514
+ onResolveStart,
515
+ onResolveEnd,
516
+ trigger
517
+ )).node;
518
+ })
519
+ )
520
+ );
521
+ })
522
+ },
462
523
  config
463
524
  );
464
525
  if (shouldRunResolver && onResolveEnd) {
@@ -506,9 +567,9 @@ function resolveAllData(_0, _1) {
506
567
  },
507
568
  "force"
508
569
  )).node;
509
- const resolvedDeep = yield mapSlots(
570
+ const resolvedDeep = yield mapFields(
510
571
  resolved,
511
- processContent,
572
+ { slot: ({ value }) => processContent(value) },
512
573
  config
513
574
  );
514
575
  onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
@@ -542,11 +603,14 @@ function resolveAllData(_0, _1) {
542
603
  function walkTree(data, config, callbackFn) {
543
604
  var _a, _b;
544
605
  const walkItem = (item) => {
545
- return mapSlots(
606
+ return mapFields(
546
607
  item,
547
- (content, parentId, propName) => {
548
- var _a2;
549
- return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
608
+ {
609
+ slot: ({ value, parentId, propName }) => {
610
+ var _a2;
611
+ const content = value;
612
+ return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
613
+ }
550
614
  },
551
615
  config,
552
616
  true
@@ -663,7 +727,7 @@ var import_flat = __toESM(require("flat"));
663
727
 
664
728
  // lib/data/strip-slots.ts
665
729
  var stripSlots = (data, config) => {
666
- return mapSlots(data, () => null, config);
730
+ return mapFields(data, { slot: () => null }, config);
667
731
  };
668
732
 
669
733
  // lib/data/flatten-node.ts
@@ -716,18 +780,21 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
716
780
  const mappedItem = mapNodeOrSkip(item, path, index);
717
781
  if (!mappedItem) return item;
718
782
  const id = mappedItem.props.id;
719
- const newProps = __spreadProps(__spreadValues({}, mapSlots(
783
+ const newProps = __spreadProps(__spreadValues({}, mapFields(
720
784
  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;
785
+ {
786
+ slot: ({ value, parentId: parentId2, propPath }) => {
787
+ const content = value;
788
+ const zoneCompound = `${parentId2}:${propPath}`;
789
+ const [_2, newContent2] = processContent(
790
+ path,
791
+ zoneCompound,
792
+ content,
793
+ "slot",
794
+ parentId2
795
+ );
796
+ return newContent2;
797
+ }
731
798
  },
732
799
  config
733
800
  ).props), {
package/dist/rsc.mjs CHANGED
@@ -1,14 +1,117 @@
1
1
  import {
2
- Render,
2
+ SlotRenderPure,
3
+ __spreadProps,
4
+ __spreadValues,
3
5
  init_react_import,
4
6
  migrate,
5
7
  resolveAllData,
8
+ rootAreaId,
9
+ rootDroppableId,
10
+ rootZone,
11
+ setupZone,
6
12
  transformProps,
13
+ useSlots,
7
14
  walkTree
8
- } from "./chunk-32MJ3X3H.mjs";
15
+ } from "./chunk-NFK5JVZW.mjs";
9
16
 
10
17
  // bundle/rsc.tsx
11
18
  init_react_import();
19
+
20
+ // components/ServerRender/index.tsx
21
+ init_react_import();
22
+ import { Fragment, jsx } from "react/jsx-runtime";
23
+ function DropZoneRender({
24
+ zone,
25
+ data,
26
+ areaId = "root",
27
+ config,
28
+ metadata = {}
29
+ }) {
30
+ let zoneCompound = rootDroppableId;
31
+ let content = (data == null ? void 0 : data.content) || [];
32
+ if (!data || !config) {
33
+ return null;
34
+ }
35
+ if (areaId !== rootAreaId && zone !== rootZone) {
36
+ zoneCompound = `${areaId}:${zone}`;
37
+ content = setupZone(data, zoneCompound).zones[zoneCompound];
38
+ }
39
+ return /* @__PURE__ */ jsx(Fragment, { children: content.map((item) => {
40
+ const Component = config.components[item.type];
41
+ const props = __spreadProps(__spreadValues({}, item.props), {
42
+ puck: {
43
+ renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx(
44
+ DropZoneRender,
45
+ {
46
+ zone: zone2,
47
+ data,
48
+ areaId: item.props.id,
49
+ config,
50
+ metadata
51
+ }
52
+ ),
53
+ metadata,
54
+ dragRef: null,
55
+ isEditing: false
56
+ }
57
+ });
58
+ const renderItem = __spreadProps(__spreadValues({}, item), { props });
59
+ const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
60
+ if (Component) {
61
+ return /* @__PURE__ */ jsx(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
62
+ }
63
+ return null;
64
+ }) });
65
+ }
66
+ function Render({
67
+ config,
68
+ data,
69
+ metadata = {}
70
+ }) {
71
+ var _a;
72
+ const rootProps = "props" in data.root ? data.root.props : data.root;
73
+ const title = rootProps.title || "";
74
+ const props = __spreadProps(__spreadValues({}, rootProps), {
75
+ puck: {
76
+ renderDropZone: ({ zone }) => /* @__PURE__ */ jsx(
77
+ DropZoneRender,
78
+ {
79
+ zone,
80
+ data,
81
+ config,
82
+ metadata
83
+ }
84
+ ),
85
+ isEditing: false,
86
+ dragRef: null,
87
+ metadata
88
+ },
89
+ title,
90
+ editMode: false,
91
+ id: "puck-root"
92
+ });
93
+ const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
94
+ if ((_a = config.root) == null ? void 0 : _a.render) {
95
+ return /* @__PURE__ */ jsx(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx(
96
+ DropZoneRender,
97
+ {
98
+ config,
99
+ data,
100
+ zone: rootZone,
101
+ metadata
102
+ }
103
+ ) }));
104
+ }
105
+ return /* @__PURE__ */ jsx(
106
+ DropZoneRender,
107
+ {
108
+ config,
109
+ data,
110
+ zone: rootZone,
111
+ metadata
112
+ }
113
+ );
114
+ }
12
115
  export {
13
116
  Render,
14
117
  migrate,