@measured/puck 0.19.0-canary.0308d24 → 0.19.0-canary.046cb9ed

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.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 './resolve-all-data-3XjIPfNh.mjs';
3
- export { a7 as resolveAllData, a6 as transformProps } from './resolve-all-data-3XjIPfNh.mjs';
2
+ import { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-CM-cu7GU.mjs';
3
+ export { af as resolveAllData, ae as transformProps, w as walkTree } from './walk-tree-CM-cu7GU.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 './resolve-all-data-3XjIPfNh.js';
3
- export { a7 as resolveAllData, a6 as transformProps } from './resolve-all-data-3XjIPfNh.js';
2
+ import { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-CM-cu7GU.js';
3
+ export { af as resolveAllData, ae as transformProps, w as walkTree } from './walk-tree-CM-cu7GU.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
@@ -69,7 +69,8 @@ var rsc_exports = {};
69
69
  __export(rsc_exports, {
70
70
  Render: () => Render,
71
71
  resolveAllData: () => resolveAllData,
72
- transformProps: () => transformProps
72
+ transformProps: () => transformProps,
73
+ walkTree: () => walkTree
73
74
  });
74
75
  module.exports = __toCommonJS(rsc_exports);
75
76
 
@@ -81,7 +82,7 @@ var rootAreaId = "root";
81
82
  var rootZone = "default-zone";
82
83
  var rootDroppableId = `${rootAreaId}:${rootZone}`;
83
84
 
84
- // lib/setup-zone.ts
85
+ // lib/data/setup-zone.ts
85
86
  var setupZone = (data, zoneKey) => {
86
87
  if (zoneKey === rootDroppableId) {
87
88
  return data;
@@ -93,8 +94,76 @@ var setupZone = (data, zoneKey) => {
93
94
  return newData;
94
95
  };
95
96
 
96
- // components/ServerRender/index.tsx
97
+ // lib/use-slots.tsx
98
+ var import_react2 = require("react");
99
+ function useSlots(config, props, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
100
+ const slotProps = (0, import_react2.useMemo)(() => {
101
+ if (!(config == null ? void 0 : config.fields)) return props;
102
+ const slotProps2 = {};
103
+ const fieldKeys = Object.keys(config.fields);
104
+ for (let i = 0; i < fieldKeys.length; i++) {
105
+ const fieldKey = fieldKeys[i];
106
+ const field = config.fields[fieldKey];
107
+ if ((field == null ? void 0 : field.type) === "slot") {
108
+ const content = props[fieldKey] || [];
109
+ const render = (readOnly == null ? void 0 : readOnly[fieldKey]) || forceReadOnly ? renderSlotRender : renderSlotEdit;
110
+ const Slot = (dzProps) => render(__spreadProps(__spreadValues({
111
+ allow: field.allow,
112
+ disallow: field.disallow
113
+ }, dzProps), {
114
+ zone: fieldKey,
115
+ content
116
+ }));
117
+ slotProps2[fieldKey] = Slot;
118
+ }
119
+ }
120
+ return slotProps2;
121
+ }, [config, readOnly, forceReadOnly]);
122
+ return __spreadValues(__spreadValues({}, props), slotProps);
123
+ }
124
+
125
+ // components/SlotRender/server.tsx
126
+ var import_react3 = require("react");
97
127
  var import_jsx_runtime = require("react/jsx-runtime");
128
+ var SlotRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotRender, __spreadValues({}, props));
129
+ var Item = ({
130
+ config,
131
+ item,
132
+ metadata
133
+ }) => {
134
+ const Component = config.components[item.type];
135
+ const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
136
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
137
+ Component.render,
138
+ __spreadProps(__spreadValues({}, props), {
139
+ puck: __spreadProps(__spreadValues({}, props.puck), {
140
+ renderDropZone: DropZoneRender,
141
+ metadata: metadata || {}
142
+ })
143
+ })
144
+ );
145
+ };
146
+ var SlotRender = (0, import_react3.forwardRef)(
147
+ function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
148
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, style, ref, children: content.map((item) => {
149
+ if (!config.components[item.type]) {
150
+ return null;
151
+ }
152
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
153
+ Item,
154
+ {
155
+ config,
156
+ item,
157
+ metadata
158
+ },
159
+ item.props.id
160
+ );
161
+ }) });
162
+ }
163
+ );
164
+
165
+ // components/ServerRender/index.tsx
166
+ var import_jsx_runtime2 = require("react/jsx-runtime");
98
167
  function DropZoneRender({
99
168
  zone,
100
169
  data,
@@ -111,28 +180,26 @@ function DropZoneRender({
111
180
  zoneCompound = `${areaId}:${zone}`;
112
181
  content = setupZone(data, zoneCompound).zones[zoneCompound];
113
182
  }
114
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: content.map((item) => {
183
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: content.map((item) => {
115
184
  const Component = config.components[item.type];
116
- if (Component) {
117
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
118
- Component.render,
119
- __spreadProps(__spreadValues({}, item.props), {
120
- puck: {
121
- renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
122
- DropZoneRender,
123
- {
124
- zone: zone2,
125
- data,
126
- areaId: item.props.id,
127
- config,
128
- metadata
129
- }
130
- ),
185
+ const props = __spreadProps(__spreadValues({}, item.props), {
186
+ puck: {
187
+ renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
188
+ DropZoneRender,
189
+ {
190
+ zone: zone2,
191
+ data,
192
+ areaId: item.props.id,
193
+ config,
131
194
  metadata
132
195
  }
133
- }),
134
- item.props.id
135
- );
196
+ ),
197
+ metadata
198
+ }
199
+ });
200
+ const propsWithSlots = useSlots(Component, props, (props2) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
201
+ if (Component) {
202
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component.render, __spreadValues({}, propsWithSlots), item.props.id);
136
203
  }
137
204
  return null;
138
205
  }) });
@@ -140,44 +207,43 @@ function DropZoneRender({
140
207
  function Render({
141
208
  config,
142
209
  data,
143
- metadata
210
+ metadata = {}
144
211
  }) {
145
212
  var _a;
213
+ const rootProps = data.root.props || data.root;
214
+ const title = rootProps.title || "";
215
+ const props = __spreadProps(__spreadValues({}, rootProps), {
216
+ puck: {
217
+ renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
218
+ DropZoneRender,
219
+ {
220
+ zone,
221
+ data,
222
+ config,
223
+ metadata
224
+ }
225
+ ),
226
+ isEditing: false,
227
+ dragRef: null,
228
+ metadata
229
+ },
230
+ title,
231
+ editMode: false,
232
+ id: "puck-root"
233
+ });
234
+ const propsWithSlots = useSlots(config.root, props, (props2) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
146
235
  if ((_a = config.root) == null ? void 0 : _a.render) {
147
- const rootProps = data.root.props || data.root;
148
- const title = rootProps.title || "";
149
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
150
- config.root.render,
151
- __spreadProps(__spreadValues({}, rootProps), {
152
- puck: {
153
- renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
154
- DropZoneRender,
155
- {
156
- zone,
157
- data,
158
- config,
159
- metadata
160
- }
161
- ),
162
- isEditing: false,
163
- dragRef: null
164
- },
165
- title,
166
- editMode: false,
167
- id: "puck-root",
168
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
169
- DropZoneRender,
170
- {
171
- config,
172
- data,
173
- zone: rootZone,
174
- metadata
175
- }
176
- )
177
- })
178
- );
236
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
237
+ DropZoneRender,
238
+ {
239
+ config,
240
+ data,
241
+ zone: rootZone,
242
+ metadata
243
+ }
244
+ ) }));
179
245
  }
180
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
246
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
181
247
  DropZoneRender,
182
248
  {
183
249
  config,
@@ -188,6 +254,57 @@ function Render({
188
254
  );
189
255
  }
190
256
 
257
+ // lib/data/is-slot.ts
258
+ var isSlot = (prop) => {
259
+ var _a, _b;
260
+ return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
261
+ };
262
+ var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
263
+ var _a, _b;
264
+ const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
265
+ if (!configForComponent) return isSlot(propValue);
266
+ return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
267
+ };
268
+
269
+ // lib/data/map-slots.ts
270
+ function mapSlotsAsync(_0, _1) {
271
+ return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
272
+ const props = __spreadValues({}, item.props);
273
+ const propKeys = Object.keys(props);
274
+ for (let i = 0; i < propKeys.length; i++) {
275
+ const propKey = propKeys[i];
276
+ const itemType = "type" in item ? item.type : "root";
277
+ if (isSlot2(itemType, propKey, props[propKey])) {
278
+ const content = props[propKey];
279
+ const mappedContent = recursive ? yield Promise.all(
280
+ content.map((item2) => __async(this, null, function* () {
281
+ return yield mapSlotsAsync(item2, map, recursive, isSlot2);
282
+ }))
283
+ ) : content;
284
+ props[propKey] = yield map(mappedContent, propKey);
285
+ }
286
+ }
287
+ return __spreadProps(__spreadValues({}, item), { props });
288
+ });
289
+ }
290
+ function mapSlotsSync(item, map, isSlot2 = isSlot) {
291
+ var _a, _b;
292
+ const props = __spreadValues({}, item.props);
293
+ const propKeys = Object.keys(props);
294
+ for (let i = 0; i < propKeys.length; i++) {
295
+ const propKey = propKeys[i];
296
+ const itemType = "type" in item ? item.type : "root";
297
+ if (isSlot2(itemType, propKey, props[propKey])) {
298
+ const content = props[propKey];
299
+ const mappedContent = content.map((item2) => {
300
+ return mapSlotsSync(item2, map, isSlot2);
301
+ });
302
+ props[propKey] = (_b = map(mappedContent, (_a = props.id) != null ? _a : "root", propKey)) != null ? _b : mappedContent;
303
+ }
304
+ }
305
+ return __spreadProps(__spreadValues({}, item), { props });
306
+ }
307
+
191
308
  // lib/get-changed.ts
192
309
  var getChanged = (newItem, oldItem) => {
193
310
  return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
@@ -200,26 +317,15 @@ var getChanged = (newItem, oldItem) => {
200
317
  };
201
318
 
202
319
  // lib/resolve-component-data.ts
320
+ var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
203
321
  var cache = { lastChange: {} };
204
- var resolveAllComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (content, config, metadata = {}, onResolveStart, onResolveEnd) {
205
- return yield Promise.all(
206
- content.map((item) => __async(void 0, null, function* () {
207
- return yield resolveComponentData(
208
- item,
209
- config,
210
- metadata,
211
- onResolveStart,
212
- onResolveEnd
213
- );
214
- }))
215
- );
216
- });
217
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd) {
218
- const configForItem = config.components[item.type];
219
- if (configForItem.resolveData) {
220
- const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
221
- if (item && item === oldItem) {
222
- return resolved;
322
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
323
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
324
+ if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
325
+ const id = "id" in item.props ? item.props.id : "root";
326
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
327
+ if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
328
+ return { node: resolved, didChange: false };
223
329
  }
224
330
  const changed = getChanged(item, oldItem);
225
331
  if (onResolveStart) {
@@ -228,93 +334,113 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
228
334
  const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
229
335
  changed,
230
336
  lastData: oldItem,
231
- metadata
337
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
338
+ trigger
232
339
  });
233
- const resolvedItem = __spreadProps(__spreadValues({}, item), {
340
+ let resolvedItem = __spreadProps(__spreadValues({}, item), {
234
341
  props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
235
342
  });
343
+ if (recursive) {
344
+ resolvedItem = yield mapSlotsAsync(
345
+ resolvedItem,
346
+ (content) => __async(void 0, null, function* () {
347
+ return Promise.all(
348
+ content.map(
349
+ (childItem) => __async(void 0, null, function* () {
350
+ return (yield resolveComponentData(
351
+ childItem,
352
+ config,
353
+ metadata,
354
+ onResolveStart,
355
+ onResolveEnd,
356
+ trigger,
357
+ false
358
+ )).node;
359
+ })
360
+ )
361
+ );
362
+ }),
363
+ false,
364
+ createIsSlotConfig(config)
365
+ );
366
+ }
236
367
  if (Object.keys(readOnly).length) {
237
368
  resolvedItem.readOnly = readOnly;
238
369
  }
239
- cache.lastChange[item.props.id] = {
370
+ cache.lastChange[id] = {
240
371
  item,
241
372
  resolved: resolvedItem
242
373
  };
243
374
  if (onResolveEnd) {
244
375
  onResolveEnd(resolvedItem);
245
376
  }
246
- return resolvedItem;
377
+ return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
247
378
  }
248
- return item;
379
+ return { node: item, didChange: false };
249
380
  });
250
381
 
251
- // lib/resolve-root-data.ts
252
- var cache2 = {};
253
- function resolveRootData(data, config, metadata) {
254
- return __async(this, null, function* () {
255
- var _a, _b, _c, _d, _e;
256
- if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
257
- if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
258
- return cache2.lastChange.resolved;
259
- }
260
- const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
261
- const rootWithProps = data.root;
262
- const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
263
- changed,
264
- lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {},
265
- metadata: metadata || {}
266
- });
267
- cache2.lastChange = {
268
- original: data.root,
269
- resolved: resolvedRoot
270
- };
271
- return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
272
- props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
273
- });
274
- }
275
- return data.root;
276
- });
277
- }
278
-
279
- // lib/default-data.ts
382
+ // lib/data/default-data.ts
280
383
  var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
281
384
  root: data.root || {},
282
385
  content: data.content || []
283
386
  });
284
387
 
388
+ // lib/data/to-component.ts
389
+ var toComponent = (item) => {
390
+ return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
391
+ props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
392
+ type: "root"
393
+ });
394
+ };
395
+
285
396
  // lib/resolve-all-data.ts
286
397
  function resolveAllData(_0, _1) {
287
398
  return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
399
+ var _a;
288
400
  const defaultedData = defaultData(data);
289
- const dynamicRoot = yield resolveRootData(
290
- defaultedData,
291
- config,
292
- metadata
293
- );
294
- const { zones = {} } = data;
295
- const zoneKeys = Object.keys(zones);
296
- const resolvedZones = {};
297
- for (let i = 0; i < zoneKeys.length; i++) {
298
- const zoneKey = zoneKeys[i];
299
- resolvedZones[zoneKey] = yield resolveAllComponentData(
300
- zones[zoneKey],
401
+ const resolveNode = (_node) => __async(this, null, function* () {
402
+ const node = toComponent(_node);
403
+ onResolveStart == null ? void 0 : onResolveStart(node);
404
+ const resolved = (yield resolveComponentData(
405
+ node,
301
406
  config,
302
407
  metadata,
303
- onResolveStart,
304
- onResolveEnd
408
+ () => {
409
+ },
410
+ () => {
411
+ },
412
+ "force",
413
+ false
414
+ )).node;
415
+ const resolvedDeep = yield mapSlotsAsync(
416
+ resolved,
417
+ processContent,
418
+ false
305
419
  );
306
- }
307
- return __spreadProps(__spreadValues({}, defaultedData), {
308
- root: dynamicRoot,
309
- content: yield resolveAllComponentData(
310
- defaultedData.content,
311
- config,
312
- metadata,
313
- onResolveStart,
314
- onResolveEnd
315
- ),
316
- zones: resolvedZones
420
+ onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
421
+ return resolvedDeep;
422
+ });
423
+ const processContent = (content) => __async(this, null, function* () {
424
+ return Promise.all(content.map(resolveNode));
317
425
  });
426
+ const processZones = () => __async(this, null, function* () {
427
+ var _a2;
428
+ const zones = (_a2 = data.zones) != null ? _a2 : {};
429
+ Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
430
+ zones[zoneKey] = yield Promise.all(content.map(resolveNode));
431
+ }));
432
+ return zones;
433
+ });
434
+ const dynamic = {
435
+ root: yield resolveNode(defaultedData.root),
436
+ content: yield processContent(defaultedData.content),
437
+ zones: yield processZones()
438
+ };
439
+ Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
440
+ const content = defaultedData.zones[zoneKey];
441
+ dynamic.zones[zoneKey] = yield processContent(content);
442
+ }), {});
443
+ return dynamic;
318
444
  });
319
445
  }
320
446
 
@@ -350,9 +476,42 @@ function transformProps(data, propTransforms) {
350
476
  });
351
477
  return afterPropTransforms;
352
478
  }
479
+
480
+ // lib/data/walk-tree.ts
481
+ function walkTree(data, config, callbackFn) {
482
+ var _a, _b;
483
+ const isSlot2 = createIsSlotConfig(config);
484
+ const walkItem = (item) => {
485
+ return mapSlotsSync(
486
+ item,
487
+ (content, parentId, propName) => callbackFn(content, { parentId, propName }),
488
+ isSlot2
489
+ );
490
+ };
491
+ if ("props" in data) {
492
+ return walkItem(data);
493
+ }
494
+ const _data = data;
495
+ const zones = (_a = _data.zones) != null ? _a : {};
496
+ const mappedContent = _data.content.map(walkItem);
497
+ return {
498
+ root: walkItem(_data.root),
499
+ content: (_b = callbackFn(mappedContent, {
500
+ parentId: "root",
501
+ propName: "default-zone"
502
+ })) != null ? _b : mappedContent,
503
+ zones: Object.keys(zones).reduce(
504
+ (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
505
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
506
+ }),
507
+ {}
508
+ )
509
+ };
510
+ }
353
511
  // Annotate the CommonJS export names for ESM import in node:
354
512
  0 && (module.exports = {
355
513
  Render,
356
514
  resolveAllData,
357
- transformProps
515
+ transformProps,
516
+ walkTree
358
517
  });
package/dist/rsc.mjs CHANGED
@@ -1,115 +1,16 @@
1
1
  import {
2
- __spreadProps,
3
- __spreadValues,
2
+ Render,
4
3
  init_react_import,
5
4
  resolveAllData,
6
- rootAreaId,
7
- rootDroppableId,
8
- rootZone,
9
- setupZone,
10
- transformProps
11
- } from "./chunk-7N5DRY4G.mjs";
5
+ transformProps,
6
+ walkTree
7
+ } from "./chunk-COT3ZFIM.mjs";
12
8
 
13
9
  // rsc.tsx
14
10
  init_react_import();
15
-
16
- // components/ServerRender/index.tsx
17
- init_react_import();
18
- import { Fragment, jsx } from "react/jsx-runtime";
19
- function DropZoneRender({
20
- zone,
21
- data,
22
- areaId = "root",
23
- config,
24
- metadata = {}
25
- }) {
26
- let zoneCompound = rootDroppableId;
27
- let content = (data == null ? void 0 : data.content) || [];
28
- if (!data || !config) {
29
- return null;
30
- }
31
- if (areaId !== rootAreaId && zone !== rootZone) {
32
- zoneCompound = `${areaId}:${zone}`;
33
- content = setupZone(data, zoneCompound).zones[zoneCompound];
34
- }
35
- return /* @__PURE__ */ jsx(Fragment, { children: content.map((item) => {
36
- const Component = config.components[item.type];
37
- if (Component) {
38
- return /* @__PURE__ */ jsx(
39
- Component.render,
40
- __spreadProps(__spreadValues({}, item.props), {
41
- puck: {
42
- renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx(
43
- DropZoneRender,
44
- {
45
- zone: zone2,
46
- data,
47
- areaId: item.props.id,
48
- config,
49
- metadata
50
- }
51
- ),
52
- metadata
53
- }
54
- }),
55
- item.props.id
56
- );
57
- }
58
- return null;
59
- }) });
60
- }
61
- function Render({
62
- config,
63
- data,
64
- metadata
65
- }) {
66
- var _a;
67
- if ((_a = config.root) == null ? void 0 : _a.render) {
68
- const rootProps = data.root.props || data.root;
69
- const title = rootProps.title || "";
70
- return /* @__PURE__ */ jsx(
71
- config.root.render,
72
- __spreadProps(__spreadValues({}, rootProps), {
73
- puck: {
74
- renderDropZone: ({ zone }) => /* @__PURE__ */ jsx(
75
- DropZoneRender,
76
- {
77
- zone,
78
- data,
79
- config,
80
- metadata
81
- }
82
- ),
83
- isEditing: false,
84
- dragRef: null
85
- },
86
- title,
87
- editMode: false,
88
- id: "puck-root",
89
- children: /* @__PURE__ */ jsx(
90
- DropZoneRender,
91
- {
92
- config,
93
- data,
94
- zone: rootZone,
95
- metadata
96
- }
97
- )
98
- })
99
- );
100
- }
101
- return /* @__PURE__ */ jsx(
102
- DropZoneRender,
103
- {
104
- config,
105
- data,
106
- zone: rootZone,
107
- metadata
108
- }
109
- );
110
- }
111
11
  export {
112
12
  Render,
113
13
  resolveAllData,
114
- transformProps
14
+ transformProps,
15
+ walkTree
115
16
  };