@measured/puck 0.21.0-canary.79a26849 → 0.21.0-canary.7c2f9283

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.
Files changed (52) hide show
  1. package/dist/Editor-32UYWE6W.mjs +204 -0
  2. package/dist/Editor-IQP25PUX.css +404 -0
  3. package/dist/Render-3OV4N4MT.css +102 -0
  4. package/dist/Render-FXZX6NFH.mjs +55 -0
  5. package/dist/{walk-tree-CgWnYC1X.d.mts → actions-BkBoKAc5.d.mts} +226 -37
  6. package/dist/{walk-tree-CgWnYC1X.d.ts → actions-BkBoKAc5.d.ts} +226 -37
  7. package/dist/chunk-3VQHXASI.mjs +33 -0
  8. package/dist/chunk-6KNQXLQR.mjs +708 -0
  9. package/dist/chunk-AOEDIUVK.mjs +11 -0
  10. package/dist/{chunk-UABEUL66.mjs → chunk-FCCNEDWR.mjs} +6964 -7964
  11. package/dist/chunk-GVKHZNTR.mjs +53 -0
  12. package/dist/chunk-K562SEXI.mjs +1813 -0
  13. package/dist/chunk-KN3XDS7U.mjs +528 -0
  14. package/dist/chunk-M6W7YEVX.mjs +95 -0
  15. package/dist/chunk-MEL7FUSF.mjs +63 -0
  16. package/dist/chunk-NYGQH27S.mjs +445 -0
  17. package/dist/chunk-Q3TJ2VYO.mjs +436 -0
  18. package/dist/chunk-REWRIUGR.mjs +156 -0
  19. package/dist/chunk-V2IQTPPK.mjs +111 -0
  20. package/dist/chunk-V5I7CVLT.mjs +103 -0
  21. package/dist/chunk-Y2EFNT5P.mjs +108 -0
  22. package/dist/full-2GJTAAZE.css +301 -0
  23. package/dist/full-4OS3O57Y.mjs +93 -0
  24. package/dist/index-bqD1SEOb.d.mts +118 -0
  25. package/dist/index-lt1zf5WR.d.ts +118 -0
  26. package/dist/index.css +1032 -385
  27. package/dist/index.d.mts +115 -115
  28. package/dist/index.d.ts +115 -115
  29. package/dist/index.js +9636 -5416
  30. package/dist/index.mjs +34 -12
  31. package/dist/internal.d.mts +27 -0
  32. package/dist/internal.d.ts +27 -0
  33. package/dist/internal.js +927 -0
  34. package/dist/internal.mjs +13 -0
  35. package/dist/loaded-DCQVLO7I.mjs +57 -0
  36. package/dist/loaded-JGRO7BH7.mjs +57 -0
  37. package/dist/loaded-KKVJE5KH.mjs +60 -0
  38. package/dist/loaded-RVWBFK7L.css +87 -0
  39. package/dist/no-external.css +1121 -470
  40. package/dist/no-external.d.mts +19 -2
  41. package/dist/no-external.d.ts +19 -2
  42. package/dist/no-external.js +9639 -5416
  43. package/dist/no-external.mjs +36 -9
  44. package/dist/rsc.css +102 -0
  45. package/dist/rsc.d.mts +17 -2
  46. package/dist/rsc.d.ts +17 -2
  47. package/dist/rsc.js +547 -98
  48. package/dist/rsc.mjs +18 -9
  49. package/dist/walk-tree-CRRDqx6_.d.mts +29 -0
  50. package/dist/walk-tree-CS7sEpfG.d.ts +29 -0
  51. package/package.json +31 -4
  52. package/dist/chunk-JA7SEUEH.mjs +0 -966
@@ -0,0 +1,445 @@
1
+ import {
2
+ styles_module_default
3
+ } from "./chunk-AOEDIUVK.mjs";
4
+ import {
5
+ defaultAppState,
6
+ resolveComponentData,
7
+ toComponent
8
+ } from "./chunk-REWRIUGR.mjs";
9
+ import {
10
+ get_class_name_factory_default
11
+ } from "./chunk-Y2EFNT5P.mjs";
12
+ import {
13
+ getZoneId,
14
+ mapFields,
15
+ walkAppState,
16
+ walkTree
17
+ } from "./chunk-Q3TJ2VYO.mjs";
18
+ import {
19
+ __async,
20
+ __objRest,
21
+ __spreadProps,
22
+ __spreadValues,
23
+ init_react_import
24
+ } from "./chunk-M6W7YEVX.mjs";
25
+
26
+ // lib/migrate.ts
27
+ init_react_import();
28
+ var migrations = [
29
+ // Migrate root to root.props
30
+ (data) => {
31
+ const rootProps = data.root.props || data.root;
32
+ if (Object.keys(data.root).length > 0 && !data.root.props) {
33
+ console.warn(
34
+ "Migration applied: Root props moved from `root` to `root.props`."
35
+ );
36
+ return __spreadProps(__spreadValues({}, data), {
37
+ root: {
38
+ props: __spreadValues({}, rootProps)
39
+ }
40
+ });
41
+ }
42
+ return data;
43
+ },
44
+ // Migrate zones to slots
45
+ (data, config, migrationOptions) => {
46
+ var _a, _b;
47
+ if (!config) return data;
48
+ console.log("Migrating DropZones to slots...");
49
+ const updatedItems = {};
50
+ const appState = __spreadProps(__spreadValues({}, defaultAppState), { data });
51
+ const { indexes } = walkAppState(appState, config);
52
+ const deletedCompounds = [];
53
+ walkAppState(appState, config, (content, zoneCompound, zoneType) => {
54
+ var _a2, _b2, _c;
55
+ if (zoneType === "dropzone") {
56
+ const [id, slotName] = zoneCompound.split(":");
57
+ const nodeData = indexes.nodes[id].data;
58
+ const componentType = nodeData.type;
59
+ const configForComponent = id === "root" ? config.root : config.components[componentType];
60
+ if (((_b2 = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b2.type) === "slot") {
61
+ updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
62
+ props: __spreadProps(__spreadValues(__spreadValues({}, nodeData.props), (_c = updatedItems[id]) == null ? void 0 : _c.props), {
63
+ [slotName]: content
64
+ })
65
+ });
66
+ deletedCompounds.push(zoneCompound);
67
+ }
68
+ return content;
69
+ }
70
+ return content;
71
+ });
72
+ const updated = walkAppState(
73
+ appState,
74
+ config,
75
+ (content) => content,
76
+ (item) => {
77
+ var _a2;
78
+ return (_a2 = updatedItems[item.props.id]) != null ? _a2 : item;
79
+ }
80
+ );
81
+ deletedCompounds.forEach((zoneCompound) => {
82
+ var _a2;
83
+ const [_, propName] = zoneCompound.split(":");
84
+ console.log(
85
+ `\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
86
+ );
87
+ (_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
88
+ });
89
+ if (migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) {
90
+ const unmigratedZonesGrouped = {};
91
+ Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
92
+ var _a2;
93
+ const [componentId, propName] = zoneCompound.split(":");
94
+ const content = (_a2 = updated.data.zones) == null ? void 0 : _a2[zoneCompound];
95
+ if (!content) {
96
+ return;
97
+ }
98
+ if (!unmigratedZonesGrouped[componentId]) {
99
+ unmigratedZonesGrouped[componentId] = {};
100
+ }
101
+ if (!unmigratedZonesGrouped[componentId][propName]) {
102
+ unmigratedZonesGrouped[componentId][propName] = content;
103
+ }
104
+ });
105
+ Object.keys(unmigratedZonesGrouped).forEach((componentId) => {
106
+ updated.data = walkTree(updated.data, config, (content) => {
107
+ return content.map((child) => {
108
+ var _a2;
109
+ if (child.props.id !== componentId) {
110
+ return child;
111
+ }
112
+ const migrateFn = (_a2 = migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) == null ? void 0 : _a2[child.type];
113
+ if (!migrateFn) {
114
+ return child;
115
+ }
116
+ const zones = unmigratedZonesGrouped[componentId];
117
+ const migratedProps = migrateFn(child.props, zones);
118
+ Object.keys(zones).forEach((propName) => {
119
+ var _a3;
120
+ const zoneCompound = `${componentId}:${propName}`;
121
+ console.log(`\u2713 Success: Migrated "${zoneCompound}" DropZone`);
122
+ (_a3 = updated.data.zones) == null ? true : delete _a3[zoneCompound];
123
+ });
124
+ return __spreadProps(__spreadValues({}, child), {
125
+ props: migratedProps
126
+ });
127
+ });
128
+ });
129
+ });
130
+ }
131
+ Object.keys((_b = updated.data.zones) != null ? _b : {}).forEach((zoneCompound) => {
132
+ const [_, propName] = zoneCompound.split(":");
133
+ throw new Error(
134
+ `Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
135
+ );
136
+ });
137
+ delete updated.data.zones;
138
+ return updated.data;
139
+ }
140
+ ];
141
+ function migrate(data, config, migrationOptions) {
142
+ return migrations == null ? void 0 : migrations.reduce(
143
+ (acc, migration) => migration(acc, config, migrationOptions),
144
+ data
145
+ );
146
+ }
147
+
148
+ // lib/transform-props.ts
149
+ init_react_import();
150
+
151
+ // lib/data/default-data.ts
152
+ init_react_import();
153
+ var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
154
+ root: data.root || {},
155
+ content: data.content || []
156
+ });
157
+
158
+ // lib/transform-props.ts
159
+ function transformProps(data, propTransforms, config = { components: {} }) {
160
+ const mapItem = (item) => {
161
+ if (propTransforms[item.type]) {
162
+ return __spreadProps(__spreadValues({}, item), {
163
+ props: __spreadValues({
164
+ id: item.props.id
165
+ }, propTransforms[item.type](item.props))
166
+ });
167
+ }
168
+ return item;
169
+ };
170
+ const defaultedData = defaultData(data);
171
+ const rootProps = defaultedData.root.props || defaultedData.root;
172
+ let newRoot = __spreadValues({}, defaultedData.root);
173
+ if (propTransforms["root"]) {
174
+ newRoot.props = propTransforms["root"](rootProps);
175
+ }
176
+ const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
177
+ const updatedData = walkTree(
178
+ dataWithUpdatedRoot,
179
+ config,
180
+ (content) => content.map(mapItem)
181
+ );
182
+ if (!defaultedData.root.props) {
183
+ updatedData.root = updatedData.root.props;
184
+ }
185
+ return updatedData;
186
+ }
187
+
188
+ // lib/resolve-all-data.ts
189
+ init_react_import();
190
+
191
+ // lib/group-zones-by-component.ts
192
+ init_react_import();
193
+ var groupZonesByComponent = (data) => {
194
+ var _a;
195
+ const zoneEntries = Object.entries((_a = data.zones) != null ? _a : {});
196
+ return zoneEntries.reduce((acc, [zoneCompound, zoneContent]) => {
197
+ const [componentId, zoneName] = getZoneId(zoneCompound);
198
+ if (!componentId.length || !zoneName.length) return acc;
199
+ if (!acc[componentId]) {
200
+ acc[componentId] = [];
201
+ }
202
+ acc[componentId].push({ zoneCompound, content: zoneContent });
203
+ return acc;
204
+ }, {});
205
+ };
206
+
207
+ // lib/resolve-all-data.ts
208
+ function resolveAllData(_0, _1) {
209
+ return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
210
+ const defaultedData = defaultData(data);
211
+ const zonesByComponent = groupZonesByComponent(defaultedData);
212
+ let resolvedZones = {};
213
+ const resolveNode = (_node, parent) => __async(null, null, function* () {
214
+ const node = toComponent(_node);
215
+ onResolveStart == null ? void 0 : onResolveStart(node);
216
+ const resolved = (yield resolveComponentData(
217
+ node,
218
+ config,
219
+ metadata,
220
+ () => {
221
+ },
222
+ () => {
223
+ },
224
+ "force",
225
+ parent
226
+ )).node;
227
+ const resolvedAsComponent = toComponent(resolved);
228
+ const resolvedDeepPromise = mapFields(
229
+ resolved,
230
+ {
231
+ slot: ({ value }) => processContent(value, resolvedAsComponent)
232
+ },
233
+ config
234
+ );
235
+ let resolveZonePromises = [];
236
+ if (zonesByComponent[resolvedAsComponent.props.id]) {
237
+ resolveZonePromises = zonesByComponent[resolvedAsComponent.props.id].map(
238
+ (_02) => __async(null, [_02], function* ({ zoneCompound, content }) {
239
+ resolvedZones[zoneCompound] = yield processContent(
240
+ content,
241
+ resolvedAsComponent
242
+ );
243
+ })
244
+ );
245
+ }
246
+ const resolvedDeep = yield resolvedDeepPromise;
247
+ yield Promise.all(resolveZonePromises);
248
+ onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
249
+ return resolvedDeep;
250
+ });
251
+ const processContent = (content, parent) => __async(null, null, function* () {
252
+ return Promise.all(content.map((item) => resolveNode(item, parent)));
253
+ });
254
+ const result = defaultData({});
255
+ result.root = yield resolveNode(defaultedData.root, null);
256
+ result.content = yield processContent(
257
+ defaultedData.content,
258
+ toComponent(result.root)
259
+ );
260
+ result.zones = resolvedZones;
261
+ return result;
262
+ });
263
+ }
264
+
265
+ // lib/field-transforms/default-transforms/slot-transform.tsx
266
+ init_react_import();
267
+ var getSlotTransform = (renderSlotEdit, renderSlotRender = renderSlotEdit) => ({
268
+ slot: ({ value: content, propName, field, isReadOnly }) => {
269
+ const render = isReadOnly ? renderSlotRender : renderSlotEdit;
270
+ const Slot = (dzProps) => render(__spreadProps(__spreadValues({
271
+ allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
272
+ disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
273
+ }, dzProps), {
274
+ zone: propName,
275
+ content
276
+ }));
277
+ return Slot;
278
+ }
279
+ });
280
+
281
+ // lib/use-slots.tsx
282
+ init_react_import();
283
+
284
+ // lib/field-transforms/use-field-transforms.tsx
285
+ init_react_import();
286
+ import { useMemo } from "react";
287
+
288
+ // lib/field-transforms/build-mappers.ts
289
+ init_react_import();
290
+ function buildMappers(transforms, readOnly, forceReadOnly) {
291
+ return Object.keys(transforms).reduce((acc, _fieldType) => {
292
+ const fieldType = _fieldType;
293
+ return __spreadProps(__spreadValues({}, acc), {
294
+ [fieldType]: (_a) => {
295
+ var _b = _a, {
296
+ parentId
297
+ } = _b, params = __objRest(_b, [
298
+ "parentId"
299
+ ]);
300
+ const wildcardPath = params.propPath.replace(/\[\d+\]/g, "[*]");
301
+ const isReadOnly = (readOnly == null ? void 0 : readOnly[params.propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly || false;
302
+ const fn = transforms[fieldType];
303
+ return fn == null ? void 0 : fn(__spreadProps(__spreadValues({}, params), {
304
+ isReadOnly,
305
+ componentId: parentId
306
+ }));
307
+ }
308
+ });
309
+ }, {});
310
+ }
311
+
312
+ // lib/field-transforms/use-field-transforms.tsx
313
+ function useFieldTransforms(config, item, transforms, readOnly, forceReadOnly) {
314
+ const mappers = useMemo(
315
+ () => buildMappers(transforms, readOnly, forceReadOnly),
316
+ [transforms, readOnly, forceReadOnly]
317
+ );
318
+ const transformedProps = useMemo(() => {
319
+ return mapFields(item, mappers, config).props;
320
+ }, [config, item, mappers]);
321
+ const mergedProps = useMemo(
322
+ () => __spreadValues(__spreadValues({}, item.props), transformedProps),
323
+ [item.props, transformedProps]
324
+ );
325
+ return mergedProps;
326
+ }
327
+
328
+ // lib/use-slots.tsx
329
+ function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
330
+ return useFieldTransforms(
331
+ config,
332
+ item,
333
+ getSlotTransform(renderSlotEdit, renderSlotRender),
334
+ readOnly,
335
+ forceReadOnly
336
+ );
337
+ }
338
+
339
+ // components/RichTextEditor/lib/use-richtext-props.tsx
340
+ init_react_import();
341
+ import { lazy, Suspense, useMemo as useMemo2 } from "react";
342
+
343
+ // components/RichTextEditor/components/RenderFallback.tsx
344
+ init_react_import();
345
+ import { jsx } from "react/jsx-runtime";
346
+ var getClassName = get_class_name_factory_default("RichTextEditor", styles_module_default);
347
+ function RichTextRenderFallback({ content }) {
348
+ return /* @__PURE__ */ jsx("div", { className: getClassName(), children: /* @__PURE__ */ jsx(
349
+ "div",
350
+ {
351
+ className: "rich-text",
352
+ dangerouslySetInnerHTML: { __html: content }
353
+ }
354
+ ) });
355
+ }
356
+
357
+ // components/RichTextEditor/lib/use-richtext-props.tsx
358
+ import { jsx as jsx2 } from "react/jsx-runtime";
359
+ function useRichtextProps(fields, props) {
360
+ const findAllRichtextKeys = (fields2) => {
361
+ if (!fields2) return [];
362
+ const result = [];
363
+ for (const [key, field] of Object.entries(fields2)) {
364
+ if (field.type === "richtext") {
365
+ result.push(key);
366
+ }
367
+ }
368
+ return result;
369
+ };
370
+ const richtextKeys = useMemo2(() => findAllRichtextKeys(fields), [fields]);
371
+ const richtextProps = useMemo2(() => {
372
+ if (!(richtextKeys == null ? void 0 : richtextKeys.length)) return {};
373
+ const RichTextRender = lazy(
374
+ () => import("./Render-FXZX6NFH.mjs").then((m) => ({
375
+ default: m.RichTextRender
376
+ }))
377
+ );
378
+ return richtextKeys.reduce((acc, key) => {
379
+ acc[key] = /* @__PURE__ */ jsx2(Suspense, { fallback: /* @__PURE__ */ jsx2(RichTextRenderFallback, { content: props[key] }), children: /* @__PURE__ */ jsx2(
380
+ RichTextRender,
381
+ {
382
+ content: props[key],
383
+ field: fields[key]
384
+ }
385
+ ) });
386
+ return acc;
387
+ }, {});
388
+ }, [richtextKeys, props, fields]);
389
+ return richtextProps;
390
+ }
391
+
392
+ // components/SlotRender/server.tsx
393
+ init_react_import();
394
+ import { forwardRef } from "react";
395
+ import { jsx as jsx3 } from "react/jsx-runtime";
396
+ var SlotRenderPure = (props) => /* @__PURE__ */ jsx3(SlotRender, __spreadValues({}, props));
397
+ var Item = ({
398
+ config,
399
+ item,
400
+ metadata
401
+ }) => {
402
+ const Component = config.components[item.type];
403
+ const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ jsx3(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
404
+ const richtextProps = useRichtextProps(Component.fields, props);
405
+ return /* @__PURE__ */ jsx3(
406
+ Component.render,
407
+ __spreadProps(__spreadValues(__spreadValues({}, props), richtextProps), {
408
+ puck: __spreadProps(__spreadValues({}, props.puck), {
409
+ metadata: metadata || {}
410
+ })
411
+ })
412
+ );
413
+ };
414
+ var SlotRender = forwardRef(
415
+ function SlotRenderInternal({ className, style, content, config, metadata, as }, ref) {
416
+ const El = as != null ? as : "div";
417
+ return /* @__PURE__ */ jsx3(El, { className, style, ref, children: content.map((item) => {
418
+ if (!config.components[item.type]) {
419
+ return null;
420
+ }
421
+ return /* @__PURE__ */ jsx3(
422
+ Item,
423
+ {
424
+ config,
425
+ item,
426
+ metadata
427
+ },
428
+ item.props.id
429
+ );
430
+ }) });
431
+ }
432
+ );
433
+
434
+ export {
435
+ buildMappers,
436
+ getSlotTransform,
437
+ useSlots,
438
+ RichTextRenderFallback,
439
+ useRichtextProps,
440
+ SlotRenderPure,
441
+ SlotRender,
442
+ migrate,
443
+ transformProps,
444
+ resolveAllData
445
+ };