@measured/puck 0.19.0-canary.85ee736 → 0.19.0-canary.8d459e4e

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/README.md CHANGED
@@ -3,9 +3,6 @@
3
3
  The visual editor for React.
4
4
 
5
5
  <p align="left">
6
- <a aria-label="Measured logo" href="https://measured.co">
7
- <img src="https://img.shields.io/badge/MADE%20BY%20Measured-000000.svg?style=for-the-badge&labelColor=000">
8
- </a>
9
6
  <a aria-label="NPM version" href="https://www.npmjs.com/package/@measured/puck">
10
7
  <img alt="" src="https://img.shields.io/npm/v/@measured/puck.svg?style=for-the-badge&labelColor=000000">
11
8
  </a>
@@ -95,6 +92,7 @@ Available recipes include:
95
92
 
96
93
  - [**next**](https://github.com/measuredco/puck/tree/main/recipes/next): Next.js example, using App Router and static page generation
97
94
  - [**remix**](https://github.com/measuredco/puck/tree/main/recipes/remix): Remix Run v2 example, using dynamic routes at root-level
95
+ - [**react-router**](https://github.com/measuredco/puck/tree/main/recipes/react-router): React Router v7 app example, using dynamic routes to create pages at any level
98
96
 
99
97
  ## Community
100
98
 
@@ -109,4 +107,4 @@ Or [book a discovery call](https://app.cal.com/chrisvxd/puck-enquiry/) for hands
109
107
 
110
108
  ## License
111
109
 
112
- MIT © [Measured Corporation Ltd](https://measured.co)
110
+ MIT © [The Puck Contributors](https://github.com/measuredco/puck/graphs/contributors)
@@ -0,0 +1,543 @@
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 __typeError = (msg) => {
12
+ throw TypeError(msg);
13
+ };
14
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
+ var __spreadValues = (a, b) => {
16
+ for (var prop in b || (b = {}))
17
+ if (__hasOwnProp.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ if (__getOwnPropSymbols)
20
+ for (var prop of __getOwnPropSymbols(b)) {
21
+ if (__propIsEnum.call(b, prop))
22
+ __defNormalProp(a, prop, b[prop]);
23
+ }
24
+ return a;
25
+ };
26
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
+ var __objRest = (source, exclude) => {
28
+ var target = {};
29
+ for (var prop in source)
30
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
31
+ target[prop] = source[prop];
32
+ if (source != null && __getOwnPropSymbols)
33
+ for (var prop of __getOwnPropSymbols(source)) {
34
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
35
+ target[prop] = source[prop];
36
+ }
37
+ return target;
38
+ };
39
+ var __esm = (fn, res) => function __init() {
40
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
41
+ };
42
+ var __commonJS = (cb, mod) => function __require() {
43
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
44
+ };
45
+ var __copyProps = (to, from, except, desc) => {
46
+ if (from && typeof from === "object" || typeof from === "function") {
47
+ for (let key of __getOwnPropNames(from))
48
+ if (!__hasOwnProp.call(to, key) && key !== except)
49
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
50
+ }
51
+ return to;
52
+ };
53
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
54
+ // If the importer is in node compatibility mode or this is not an ESM
55
+ // file that has been converted to a CommonJS file using a Babel-
56
+ // compatible transform (i.e. "__esModule" has not been set), then set
57
+ // "default" to the CommonJS "module.exports" for node compatibility.
58
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
59
+ mod
60
+ ));
61
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
62
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
63
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
64
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
65
+ var __async = (__this, __arguments, generator) => {
66
+ return new Promise((resolve, reject) => {
67
+ var fulfilled = (value) => {
68
+ try {
69
+ step(generator.next(value));
70
+ } catch (e) {
71
+ reject(e);
72
+ }
73
+ };
74
+ var rejected = (value) => {
75
+ try {
76
+ step(generator.throw(value));
77
+ } catch (e) {
78
+ reject(e);
79
+ }
80
+ };
81
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
82
+ step((generator = generator.apply(__this, __arguments)).next());
83
+ });
84
+ };
85
+
86
+ // ../tsup-config/react-import.js
87
+ import React from "react";
88
+ var init_react_import = __esm({
89
+ "../tsup-config/react-import.js"() {
90
+ "use strict";
91
+ }
92
+ });
93
+
94
+ // components/ServerRender/index.tsx
95
+ init_react_import();
96
+
97
+ // lib/root-droppable-id.ts
98
+ init_react_import();
99
+ var rootAreaId = "root";
100
+ var rootZone = "default-zone";
101
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
102
+
103
+ // lib/data/setup-zone.ts
104
+ init_react_import();
105
+ var setupZone = (data, zoneKey) => {
106
+ if (zoneKey === rootDroppableId) {
107
+ return data;
108
+ }
109
+ const newData = __spreadProps(__spreadValues({}, data), {
110
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
111
+ });
112
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
113
+ return newData;
114
+ };
115
+
116
+ // lib/use-slots.tsx
117
+ init_react_import();
118
+ import { useMemo } from "react";
119
+ function useSlots(config, props, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
120
+ const slotProps = useMemo(() => {
121
+ if (!(config == null ? void 0 : config.fields)) return props;
122
+ const slotProps2 = {};
123
+ const fieldKeys = Object.keys(config.fields);
124
+ for (let i = 0; i < fieldKeys.length; i++) {
125
+ const fieldKey = fieldKeys[i];
126
+ const field = config.fields[fieldKey];
127
+ if ((field == null ? void 0 : field.type) === "slot") {
128
+ const content = props[fieldKey] || [];
129
+ const render = (readOnly == null ? void 0 : readOnly[fieldKey]) || forceReadOnly ? renderSlotRender : renderSlotEdit;
130
+ const Slot = (dzProps) => render(__spreadProps(__spreadValues({
131
+ allow: field.allow,
132
+ disallow: field.disallow
133
+ }, dzProps), {
134
+ zone: fieldKey,
135
+ content
136
+ }));
137
+ slotProps2[fieldKey] = Slot;
138
+ }
139
+ }
140
+ return slotProps2;
141
+ }, [config, readOnly, forceReadOnly]);
142
+ return __spreadValues(__spreadValues({}, props), slotProps);
143
+ }
144
+
145
+ // components/SlotRender/server.tsx
146
+ init_react_import();
147
+ import { forwardRef } from "react";
148
+ import { jsx } from "react/jsx-runtime";
149
+ var SlotRenderPure = (props) => /* @__PURE__ */ jsx(SlotRender, __spreadValues({}, props));
150
+ var Item = ({
151
+ config,
152
+ item,
153
+ metadata
154
+ }) => {
155
+ const Component = config.components[item.type];
156
+ const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
157
+ return /* @__PURE__ */ jsx(
158
+ Component.render,
159
+ __spreadProps(__spreadValues({}, props), {
160
+ puck: __spreadProps(__spreadValues({}, props.puck), {
161
+ renderDropZone: DropZoneRender,
162
+ metadata: metadata || {}
163
+ })
164
+ })
165
+ );
166
+ };
167
+ var SlotRender = forwardRef(
168
+ function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
169
+ return /* @__PURE__ */ jsx("div", { className, style, ref, children: content.map((item) => {
170
+ if (!config.components[item.type]) {
171
+ return null;
172
+ }
173
+ return /* @__PURE__ */ jsx(
174
+ Item,
175
+ {
176
+ config,
177
+ item,
178
+ metadata
179
+ },
180
+ item.props.id
181
+ );
182
+ }) });
183
+ }
184
+ );
185
+
186
+ // components/ServerRender/index.tsx
187
+ import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
188
+ function DropZoneRender({
189
+ zone,
190
+ data,
191
+ areaId = "root",
192
+ config,
193
+ metadata = {}
194
+ }) {
195
+ let zoneCompound = rootDroppableId;
196
+ let content = (data == null ? void 0 : data.content) || [];
197
+ if (!data || !config) {
198
+ return null;
199
+ }
200
+ if (areaId !== rootAreaId && zone !== rootZone) {
201
+ zoneCompound = `${areaId}:${zone}`;
202
+ content = setupZone(data, zoneCompound).zones[zoneCompound];
203
+ }
204
+ return /* @__PURE__ */ jsx2(Fragment, { children: content.map((item) => {
205
+ const Component = config.components[item.type];
206
+ const props = __spreadProps(__spreadValues({}, item.props), {
207
+ puck: {
208
+ renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx2(
209
+ DropZoneRender,
210
+ {
211
+ zone: zone2,
212
+ data,
213
+ areaId: item.props.id,
214
+ config,
215
+ metadata
216
+ }
217
+ ),
218
+ metadata
219
+ }
220
+ });
221
+ const propsWithSlots = useSlots(Component, props, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
222
+ if (Component) {
223
+ return /* @__PURE__ */ jsx2(Component.render, __spreadValues({}, propsWithSlots), item.props.id);
224
+ }
225
+ return null;
226
+ }) });
227
+ }
228
+ function Render({
229
+ config,
230
+ data,
231
+ metadata = {}
232
+ }) {
233
+ var _a;
234
+ const rootProps = data.root.props || data.root;
235
+ const title = rootProps.title || "";
236
+ const props = __spreadProps(__spreadValues({}, rootProps), {
237
+ puck: {
238
+ renderDropZone: ({ zone }) => /* @__PURE__ */ jsx2(
239
+ DropZoneRender,
240
+ {
241
+ zone,
242
+ data,
243
+ config,
244
+ metadata
245
+ }
246
+ ),
247
+ isEditing: false,
248
+ dragRef: null,
249
+ metadata
250
+ },
251
+ title,
252
+ editMode: false,
253
+ id: "puck-root"
254
+ });
255
+ const propsWithSlots = useSlots(config.root, props, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
256
+ if ((_a = config.root) == null ? void 0 : _a.render) {
257
+ return /* @__PURE__ */ jsx2(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx2(
258
+ DropZoneRender,
259
+ {
260
+ config,
261
+ data,
262
+ zone: rootZone,
263
+ metadata
264
+ }
265
+ ) }));
266
+ }
267
+ return /* @__PURE__ */ jsx2(
268
+ DropZoneRender,
269
+ {
270
+ config,
271
+ data,
272
+ zone: rootZone,
273
+ metadata
274
+ }
275
+ );
276
+ }
277
+
278
+ // lib/transform-props.ts
279
+ init_react_import();
280
+
281
+ // lib/data/default-data.ts
282
+ init_react_import();
283
+ var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
284
+ root: data.root || {},
285
+ content: data.content || []
286
+ });
287
+
288
+ // lib/transform-props.ts
289
+ function transformProps(data, propTransforms) {
290
+ const mapItem = (item) => {
291
+ if (propTransforms[item.type]) {
292
+ return __spreadProps(__spreadValues({}, item), {
293
+ props: propTransforms[item.type](item.props)
294
+ });
295
+ }
296
+ return item;
297
+ };
298
+ const defaultedData = defaultData(data);
299
+ const rootProps = defaultedData.root.props || defaultedData.root;
300
+ let newRoot = __spreadValues({}, defaultedData.root);
301
+ if (propTransforms["root"]) {
302
+ if (defaultedData.root.props) {
303
+ newRoot.props = propTransforms["root"](rootProps);
304
+ } else {
305
+ newRoot = propTransforms["root"](rootProps);
306
+ }
307
+ }
308
+ const afterPropTransforms = __spreadProps(__spreadValues({}, defaultedData), {
309
+ root: newRoot,
310
+ content: defaultedData.content.map(mapItem),
311
+ zones: Object.keys(data.zones || {}).reduce(
312
+ (acc, zoneKey) => __spreadProps(__spreadValues({}, acc), {
313
+ [zoneKey]: data.zones[zoneKey].map(mapItem)
314
+ }),
315
+ {}
316
+ )
317
+ });
318
+ return afterPropTransforms;
319
+ }
320
+
321
+ // lib/resolve-all-data.ts
322
+ init_react_import();
323
+
324
+ // lib/resolve-component-data.ts
325
+ init_react_import();
326
+
327
+ // lib/data/map-slots.ts
328
+ init_react_import();
329
+
330
+ // lib/data/is-slot.ts
331
+ init_react_import();
332
+ var isSlot = (prop) => {
333
+ var _a, _b;
334
+ return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
335
+ };
336
+ var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
337
+ var _a, _b;
338
+ const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
339
+ if (!configForComponent) return isSlot(propValue);
340
+ return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
341
+ };
342
+
343
+ // lib/data/map-slots.ts
344
+ function mapSlotsAsync(_0, _1) {
345
+ return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
346
+ const props = __spreadValues({}, item.props);
347
+ const propKeys = Object.keys(props);
348
+ for (let i = 0; i < propKeys.length; i++) {
349
+ const propKey = propKeys[i];
350
+ const itemType = "type" in item ? item.type : "root";
351
+ if (isSlot2(itemType, propKey, props[propKey])) {
352
+ const content = props[propKey];
353
+ const mappedContent = recursive ? yield Promise.all(
354
+ content.map((item2) => __async(this, null, function* () {
355
+ return yield mapSlotsAsync(item2, map, recursive, isSlot2);
356
+ }))
357
+ ) : content;
358
+ props[propKey] = yield map(mappedContent, propKey);
359
+ }
360
+ }
361
+ return __spreadProps(__spreadValues({}, item), { props });
362
+ });
363
+ }
364
+ function mapSlotsSync(item, map, isSlot2 = isSlot) {
365
+ var _a, _b;
366
+ const props = __spreadValues({}, item.props);
367
+ const propKeys = Object.keys(props);
368
+ for (let i = 0; i < propKeys.length; i++) {
369
+ const propKey = propKeys[i];
370
+ const itemType = "type" in item ? item.type : "root";
371
+ if (isSlot2(itemType, propKey, props[propKey])) {
372
+ const content = props[propKey];
373
+ const mappedContent = content.map((item2) => {
374
+ return mapSlotsSync(item2, map, isSlot2);
375
+ });
376
+ props[propKey] = (_b = map(mappedContent, (_a = props.id) != null ? _a : "root", propKey)) != null ? _b : mappedContent;
377
+ }
378
+ }
379
+ return __spreadProps(__spreadValues({}, item), { props });
380
+ }
381
+
382
+ // lib/get-changed.ts
383
+ init_react_import();
384
+ var getChanged = (newItem, oldItem) => {
385
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
386
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
387
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
388
+ return __spreadProps(__spreadValues({}, acc), {
389
+ [item]: oldItemProps[item] !== newItemProps[item]
390
+ });
391
+ }, {}) : {};
392
+ };
393
+
394
+ // lib/resolve-component-data.ts
395
+ import fdeq from "fast-deep-equal";
396
+ var cache = { lastChange: {} };
397
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
398
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
399
+ if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
400
+ const id = "id" in item.props ? item.props.id : "root";
401
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
402
+ if (item && fdeq(item, oldItem)) {
403
+ return { node: resolved, didChange: false };
404
+ }
405
+ const changed = getChanged(item, oldItem);
406
+ if (onResolveStart) {
407
+ onResolveStart(item);
408
+ }
409
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
410
+ changed,
411
+ lastData: oldItem,
412
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
413
+ trigger
414
+ });
415
+ let resolvedItem = __spreadProps(__spreadValues({}, item), {
416
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
417
+ });
418
+ if (recursive) {
419
+ resolvedItem = yield mapSlotsAsync(
420
+ resolvedItem,
421
+ (content) => __async(void 0, null, function* () {
422
+ return Promise.all(
423
+ content.map(
424
+ (childItem) => __async(void 0, null, function* () {
425
+ return (yield resolveComponentData(
426
+ childItem,
427
+ config,
428
+ metadata,
429
+ onResolveStart,
430
+ onResolveEnd,
431
+ trigger,
432
+ false
433
+ )).node;
434
+ })
435
+ )
436
+ );
437
+ }),
438
+ false,
439
+ createIsSlotConfig(config)
440
+ );
441
+ }
442
+ if (Object.keys(readOnly).length) {
443
+ resolvedItem.readOnly = readOnly;
444
+ }
445
+ cache.lastChange[id] = {
446
+ item,
447
+ resolved: resolvedItem
448
+ };
449
+ if (onResolveEnd) {
450
+ onResolveEnd(resolvedItem);
451
+ }
452
+ return { node: resolvedItem, didChange: !fdeq(item, resolvedItem) };
453
+ }
454
+ return { node: item, didChange: false };
455
+ });
456
+
457
+ // lib/data/to-component.ts
458
+ init_react_import();
459
+ var toComponent = (item) => {
460
+ return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
461
+ props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
462
+ type: "root"
463
+ });
464
+ };
465
+
466
+ // lib/resolve-all-data.ts
467
+ function resolveAllData(_0, _1) {
468
+ return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
469
+ var _a;
470
+ const defaultedData = defaultData(data);
471
+ const resolveNode = (_node) => __async(this, null, function* () {
472
+ const node = toComponent(_node);
473
+ onResolveStart == null ? void 0 : onResolveStart(node);
474
+ const resolved = (yield resolveComponentData(
475
+ node,
476
+ config,
477
+ metadata,
478
+ () => {
479
+ },
480
+ () => {
481
+ },
482
+ "force",
483
+ false
484
+ )).node;
485
+ const resolvedDeep = yield mapSlotsAsync(
486
+ resolved,
487
+ processContent,
488
+ false
489
+ );
490
+ onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
491
+ return resolvedDeep;
492
+ });
493
+ const processContent = (content) => __async(this, null, function* () {
494
+ return Promise.all(content.map(resolveNode));
495
+ });
496
+ const processZones = () => __async(this, null, function* () {
497
+ var _a2;
498
+ const zones = (_a2 = data.zones) != null ? _a2 : {};
499
+ Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
500
+ zones[zoneKey] = yield Promise.all(content.map(resolveNode));
501
+ }));
502
+ return zones;
503
+ });
504
+ const dynamic = {
505
+ root: yield resolveNode(defaultedData.root),
506
+ content: yield processContent(defaultedData.content),
507
+ zones: yield processZones()
508
+ };
509
+ Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
510
+ const content = defaultedData.zones[zoneKey];
511
+ dynamic.zones[zoneKey] = yield processContent(content);
512
+ }), {});
513
+ return dynamic;
514
+ });
515
+ }
516
+
517
+ export {
518
+ __spreadValues,
519
+ __spreadProps,
520
+ __objRest,
521
+ __commonJS,
522
+ __toESM,
523
+ __privateGet,
524
+ __privateAdd,
525
+ __privateSet,
526
+ __async,
527
+ init_react_import,
528
+ isSlot,
529
+ createIsSlotConfig,
530
+ rootAreaId,
531
+ rootZone,
532
+ rootDroppableId,
533
+ setupZone,
534
+ getChanged,
535
+ mapSlotsSync,
536
+ resolveComponentData,
537
+ useSlots,
538
+ Render,
539
+ SlotRenderPure,
540
+ SlotRender,
541
+ transformProps,
542
+ resolveAllData
543
+ };