@measured/puck 0.19.0-canary.f13b9536 → 0.19.0-canary.f6398bca
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 +1 -4
- package/dist/chunk-COT3ZFIM.mjs +576 -0
- package/dist/index.d.mts +4 -10
- package/dist/index.d.ts +4 -10
- package/dist/index.js +381 -279
- package/dist/index.mjs +6507 -1614
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +255 -3766
- package/dist/rsc.mjs +5 -103
- package/dist/{resolve-all-data-DgtDFF0E.d.mts → walk-tree-CM-cu7GU.d.mts} +42 -20
- package/dist/{resolve-all-data-DgtDFF0E.d.ts → walk-tree-CM-cu7GU.d.ts} +42 -20
- package/package.json +2 -2
- package/dist/chunk-ZOHJNF5K.mjs +0 -5427
- package/dist/rsc.css +0 -339
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>
|
@@ -110,4 +107,4 @@ Or [book a discovery call](https://app.cal.com/chrisvxd/puck-enquiry/) for hands
|
|
110
107
|
|
111
108
|
## License
|
112
109
|
|
113
|
-
MIT © [
|
110
|
+
MIT © [The Puck Contributors](https://github.com/measuredco/puck/graphs/contributors)
|
@@ -0,0 +1,576 @@
|
|
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
|
+
// lib/data/walk-tree.ts
|
95
|
+
init_react_import();
|
96
|
+
|
97
|
+
// lib/data/is-slot.ts
|
98
|
+
init_react_import();
|
99
|
+
var isSlot = (prop) => {
|
100
|
+
var _a, _b;
|
101
|
+
return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
|
102
|
+
};
|
103
|
+
var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
|
104
|
+
var _a, _b;
|
105
|
+
const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
|
106
|
+
if (!configForComponent) return isSlot(propValue);
|
107
|
+
return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
|
108
|
+
};
|
109
|
+
|
110
|
+
// lib/data/map-slots.ts
|
111
|
+
init_react_import();
|
112
|
+
function mapSlotsAsync(_0, _1) {
|
113
|
+
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
114
|
+
const props = __spreadValues({}, item.props);
|
115
|
+
const propKeys = Object.keys(props);
|
116
|
+
for (let i = 0; i < propKeys.length; i++) {
|
117
|
+
const propKey = propKeys[i];
|
118
|
+
const itemType = "type" in item ? item.type : "root";
|
119
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
120
|
+
const content = props[propKey];
|
121
|
+
const mappedContent = recursive ? yield Promise.all(
|
122
|
+
content.map((item2) => __async(this, null, function* () {
|
123
|
+
return yield mapSlotsAsync(item2, map, recursive, isSlot2);
|
124
|
+
}))
|
125
|
+
) : content;
|
126
|
+
props[propKey] = yield map(mappedContent, propKey);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
return __spreadProps(__spreadValues({}, item), { props });
|
130
|
+
});
|
131
|
+
}
|
132
|
+
function mapSlotsSync(item, map, isSlot2 = isSlot) {
|
133
|
+
var _a, _b;
|
134
|
+
const props = __spreadValues({}, item.props);
|
135
|
+
const propKeys = Object.keys(props);
|
136
|
+
for (let i = 0; i < propKeys.length; i++) {
|
137
|
+
const propKey = propKeys[i];
|
138
|
+
const itemType = "type" in item ? item.type : "root";
|
139
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
140
|
+
const content = props[propKey];
|
141
|
+
const mappedContent = content.map((item2) => {
|
142
|
+
return mapSlotsSync(item2, map, isSlot2);
|
143
|
+
});
|
144
|
+
props[propKey] = (_b = map(mappedContent, (_a = props.id) != null ? _a : "root", propKey)) != null ? _b : mappedContent;
|
145
|
+
}
|
146
|
+
}
|
147
|
+
return __spreadProps(__spreadValues({}, item), { props });
|
148
|
+
}
|
149
|
+
|
150
|
+
// lib/data/walk-tree.ts
|
151
|
+
function walkTree(data, config, callbackFn) {
|
152
|
+
var _a, _b;
|
153
|
+
const isSlot2 = createIsSlotConfig(config);
|
154
|
+
const walkItem = (item) => {
|
155
|
+
return mapSlotsSync(
|
156
|
+
item,
|
157
|
+
(content, parentId, propName) => callbackFn(content, { parentId, propName }),
|
158
|
+
isSlot2
|
159
|
+
);
|
160
|
+
};
|
161
|
+
if ("props" in data) {
|
162
|
+
return walkItem(data);
|
163
|
+
}
|
164
|
+
const _data = data;
|
165
|
+
const zones = (_a = _data.zones) != null ? _a : {};
|
166
|
+
const mappedContent = _data.content.map(walkItem);
|
167
|
+
return {
|
168
|
+
root: walkItem(_data.root),
|
169
|
+
content: (_b = callbackFn(mappedContent, {
|
170
|
+
parentId: "root",
|
171
|
+
propName: "default-zone"
|
172
|
+
})) != null ? _b : mappedContent,
|
173
|
+
zones: Object.keys(zones).reduce(
|
174
|
+
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
175
|
+
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
176
|
+
}),
|
177
|
+
{}
|
178
|
+
)
|
179
|
+
};
|
180
|
+
}
|
181
|
+
|
182
|
+
// components/ServerRender/index.tsx
|
183
|
+
init_react_import();
|
184
|
+
|
185
|
+
// lib/root-droppable-id.ts
|
186
|
+
init_react_import();
|
187
|
+
var rootAreaId = "root";
|
188
|
+
var rootZone = "default-zone";
|
189
|
+
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
190
|
+
|
191
|
+
// lib/data/setup-zone.ts
|
192
|
+
init_react_import();
|
193
|
+
var setupZone = (data, zoneKey) => {
|
194
|
+
if (zoneKey === rootDroppableId) {
|
195
|
+
return data;
|
196
|
+
}
|
197
|
+
const newData = __spreadProps(__spreadValues({}, data), {
|
198
|
+
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
199
|
+
});
|
200
|
+
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
201
|
+
return newData;
|
202
|
+
};
|
203
|
+
|
204
|
+
// lib/use-slots.tsx
|
205
|
+
init_react_import();
|
206
|
+
import { useMemo } from "react";
|
207
|
+
function useSlots(config, props, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
|
208
|
+
const slotProps = useMemo(() => {
|
209
|
+
if (!(config == null ? void 0 : config.fields)) return props;
|
210
|
+
const slotProps2 = {};
|
211
|
+
const fieldKeys = Object.keys(config.fields);
|
212
|
+
for (let i = 0; i < fieldKeys.length; i++) {
|
213
|
+
const fieldKey = fieldKeys[i];
|
214
|
+
const field = config.fields[fieldKey];
|
215
|
+
if ((field == null ? void 0 : field.type) === "slot") {
|
216
|
+
const content = props[fieldKey] || [];
|
217
|
+
const render = (readOnly == null ? void 0 : readOnly[fieldKey]) || forceReadOnly ? renderSlotRender : renderSlotEdit;
|
218
|
+
const Slot = (dzProps) => render(__spreadProps(__spreadValues({
|
219
|
+
allow: field.allow,
|
220
|
+
disallow: field.disallow
|
221
|
+
}, dzProps), {
|
222
|
+
zone: fieldKey,
|
223
|
+
content
|
224
|
+
}));
|
225
|
+
slotProps2[fieldKey] = Slot;
|
226
|
+
}
|
227
|
+
}
|
228
|
+
return slotProps2;
|
229
|
+
}, [config, readOnly, forceReadOnly]);
|
230
|
+
return __spreadValues(__spreadValues({}, props), slotProps);
|
231
|
+
}
|
232
|
+
|
233
|
+
// components/SlotRender/server.tsx
|
234
|
+
init_react_import();
|
235
|
+
import { forwardRef } from "react";
|
236
|
+
import { jsx } from "react/jsx-runtime";
|
237
|
+
var SlotRenderPure = (props) => /* @__PURE__ */ jsx(SlotRender, __spreadValues({}, props));
|
238
|
+
var Item = ({
|
239
|
+
config,
|
240
|
+
item,
|
241
|
+
metadata
|
242
|
+
}) => {
|
243
|
+
const Component = config.components[item.type];
|
244
|
+
const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
245
|
+
return /* @__PURE__ */ jsx(
|
246
|
+
Component.render,
|
247
|
+
__spreadProps(__spreadValues({}, props), {
|
248
|
+
puck: __spreadProps(__spreadValues({}, props.puck), {
|
249
|
+
renderDropZone: DropZoneRender,
|
250
|
+
metadata: metadata || {}
|
251
|
+
})
|
252
|
+
})
|
253
|
+
);
|
254
|
+
};
|
255
|
+
var SlotRender = forwardRef(
|
256
|
+
function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
|
257
|
+
return /* @__PURE__ */ jsx("div", { className, style, ref, children: content.map((item) => {
|
258
|
+
if (!config.components[item.type]) {
|
259
|
+
return null;
|
260
|
+
}
|
261
|
+
return /* @__PURE__ */ jsx(
|
262
|
+
Item,
|
263
|
+
{
|
264
|
+
config,
|
265
|
+
item,
|
266
|
+
metadata
|
267
|
+
},
|
268
|
+
item.props.id
|
269
|
+
);
|
270
|
+
}) });
|
271
|
+
}
|
272
|
+
);
|
273
|
+
|
274
|
+
// components/ServerRender/index.tsx
|
275
|
+
import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
|
276
|
+
function DropZoneRender({
|
277
|
+
zone,
|
278
|
+
data,
|
279
|
+
areaId = "root",
|
280
|
+
config,
|
281
|
+
metadata = {}
|
282
|
+
}) {
|
283
|
+
let zoneCompound = rootDroppableId;
|
284
|
+
let content = (data == null ? void 0 : data.content) || [];
|
285
|
+
if (!data || !config) {
|
286
|
+
return null;
|
287
|
+
}
|
288
|
+
if (areaId !== rootAreaId && zone !== rootZone) {
|
289
|
+
zoneCompound = `${areaId}:${zone}`;
|
290
|
+
content = setupZone(data, zoneCompound).zones[zoneCompound];
|
291
|
+
}
|
292
|
+
return /* @__PURE__ */ jsx2(Fragment, { children: content.map((item) => {
|
293
|
+
const Component = config.components[item.type];
|
294
|
+
const props = __spreadProps(__spreadValues({}, item.props), {
|
295
|
+
puck: {
|
296
|
+
renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx2(
|
297
|
+
DropZoneRender,
|
298
|
+
{
|
299
|
+
zone: zone2,
|
300
|
+
data,
|
301
|
+
areaId: item.props.id,
|
302
|
+
config,
|
303
|
+
metadata
|
304
|
+
}
|
305
|
+
),
|
306
|
+
metadata
|
307
|
+
}
|
308
|
+
});
|
309
|
+
const propsWithSlots = useSlots(Component, props, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
310
|
+
if (Component) {
|
311
|
+
return /* @__PURE__ */ jsx2(Component.render, __spreadValues({}, propsWithSlots), item.props.id);
|
312
|
+
}
|
313
|
+
return null;
|
314
|
+
}) });
|
315
|
+
}
|
316
|
+
function Render({
|
317
|
+
config,
|
318
|
+
data,
|
319
|
+
metadata = {}
|
320
|
+
}) {
|
321
|
+
var _a;
|
322
|
+
const rootProps = data.root.props || data.root;
|
323
|
+
const title = rootProps.title || "";
|
324
|
+
const props = __spreadProps(__spreadValues({}, rootProps), {
|
325
|
+
puck: {
|
326
|
+
renderDropZone: ({ zone }) => /* @__PURE__ */ jsx2(
|
327
|
+
DropZoneRender,
|
328
|
+
{
|
329
|
+
zone,
|
330
|
+
data,
|
331
|
+
config,
|
332
|
+
metadata
|
333
|
+
}
|
334
|
+
),
|
335
|
+
isEditing: false,
|
336
|
+
dragRef: null,
|
337
|
+
metadata
|
338
|
+
},
|
339
|
+
title,
|
340
|
+
editMode: false,
|
341
|
+
id: "puck-root"
|
342
|
+
});
|
343
|
+
const propsWithSlots = useSlots(config.root, props, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
344
|
+
if ((_a = config.root) == null ? void 0 : _a.render) {
|
345
|
+
return /* @__PURE__ */ jsx2(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx2(
|
346
|
+
DropZoneRender,
|
347
|
+
{
|
348
|
+
config,
|
349
|
+
data,
|
350
|
+
zone: rootZone,
|
351
|
+
metadata
|
352
|
+
}
|
353
|
+
) }));
|
354
|
+
}
|
355
|
+
return /* @__PURE__ */ jsx2(
|
356
|
+
DropZoneRender,
|
357
|
+
{
|
358
|
+
config,
|
359
|
+
data,
|
360
|
+
zone: rootZone,
|
361
|
+
metadata
|
362
|
+
}
|
363
|
+
);
|
364
|
+
}
|
365
|
+
|
366
|
+
// lib/transform-props.ts
|
367
|
+
init_react_import();
|
368
|
+
|
369
|
+
// lib/data/default-data.ts
|
370
|
+
init_react_import();
|
371
|
+
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
372
|
+
root: data.root || {},
|
373
|
+
content: data.content || []
|
374
|
+
});
|
375
|
+
|
376
|
+
// lib/transform-props.ts
|
377
|
+
function transformProps(data, propTransforms) {
|
378
|
+
const mapItem = (item) => {
|
379
|
+
if (propTransforms[item.type]) {
|
380
|
+
return __spreadProps(__spreadValues({}, item), {
|
381
|
+
props: propTransforms[item.type](item.props)
|
382
|
+
});
|
383
|
+
}
|
384
|
+
return item;
|
385
|
+
};
|
386
|
+
const defaultedData = defaultData(data);
|
387
|
+
const rootProps = defaultedData.root.props || defaultedData.root;
|
388
|
+
let newRoot = __spreadValues({}, defaultedData.root);
|
389
|
+
if (propTransforms["root"]) {
|
390
|
+
if (defaultedData.root.props) {
|
391
|
+
newRoot.props = propTransforms["root"](rootProps);
|
392
|
+
} else {
|
393
|
+
newRoot = propTransforms["root"](rootProps);
|
394
|
+
}
|
395
|
+
}
|
396
|
+
const afterPropTransforms = __spreadProps(__spreadValues({}, defaultedData), {
|
397
|
+
root: newRoot,
|
398
|
+
content: defaultedData.content.map(mapItem),
|
399
|
+
zones: Object.keys(data.zones || {}).reduce(
|
400
|
+
(acc, zoneKey) => __spreadProps(__spreadValues({}, acc), {
|
401
|
+
[zoneKey]: data.zones[zoneKey].map(mapItem)
|
402
|
+
}),
|
403
|
+
{}
|
404
|
+
)
|
405
|
+
});
|
406
|
+
return afterPropTransforms;
|
407
|
+
}
|
408
|
+
|
409
|
+
// lib/resolve-all-data.ts
|
410
|
+
init_react_import();
|
411
|
+
|
412
|
+
// lib/resolve-component-data.ts
|
413
|
+
init_react_import();
|
414
|
+
|
415
|
+
// lib/get-changed.ts
|
416
|
+
init_react_import();
|
417
|
+
var getChanged = (newItem, oldItem) => {
|
418
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
419
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
420
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
421
|
+
return __spreadProps(__spreadValues({}, acc), {
|
422
|
+
[item]: oldItemProps[item] !== newItemProps[item]
|
423
|
+
});
|
424
|
+
}, {}) : {};
|
425
|
+
};
|
426
|
+
|
427
|
+
// lib/resolve-component-data.ts
|
428
|
+
import fdeq from "fast-deep-equal";
|
429
|
+
var cache = { lastChange: {} };
|
430
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
|
431
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
432
|
+
if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
|
433
|
+
const id = "id" in item.props ? item.props.id : "root";
|
434
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
435
|
+
if (item && fdeq(item, oldItem)) {
|
436
|
+
return { node: resolved, didChange: false };
|
437
|
+
}
|
438
|
+
const changed = getChanged(item, oldItem);
|
439
|
+
if (onResolveStart) {
|
440
|
+
onResolveStart(item);
|
441
|
+
}
|
442
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
443
|
+
changed,
|
444
|
+
lastData: oldItem,
|
445
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
446
|
+
trigger
|
447
|
+
});
|
448
|
+
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
449
|
+
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
450
|
+
});
|
451
|
+
if (recursive) {
|
452
|
+
resolvedItem = yield mapSlotsAsync(
|
453
|
+
resolvedItem,
|
454
|
+
(content) => __async(void 0, null, function* () {
|
455
|
+
return Promise.all(
|
456
|
+
content.map(
|
457
|
+
(childItem) => __async(void 0, null, function* () {
|
458
|
+
return (yield resolveComponentData(
|
459
|
+
childItem,
|
460
|
+
config,
|
461
|
+
metadata,
|
462
|
+
onResolveStart,
|
463
|
+
onResolveEnd,
|
464
|
+
trigger,
|
465
|
+
false
|
466
|
+
)).node;
|
467
|
+
})
|
468
|
+
)
|
469
|
+
);
|
470
|
+
}),
|
471
|
+
false,
|
472
|
+
createIsSlotConfig(config)
|
473
|
+
);
|
474
|
+
}
|
475
|
+
if (Object.keys(readOnly).length) {
|
476
|
+
resolvedItem.readOnly = readOnly;
|
477
|
+
}
|
478
|
+
cache.lastChange[id] = {
|
479
|
+
item,
|
480
|
+
resolved: resolvedItem
|
481
|
+
};
|
482
|
+
if (onResolveEnd) {
|
483
|
+
onResolveEnd(resolvedItem);
|
484
|
+
}
|
485
|
+
return { node: resolvedItem, didChange: !fdeq(item, resolvedItem) };
|
486
|
+
}
|
487
|
+
return { node: item, didChange: false };
|
488
|
+
});
|
489
|
+
|
490
|
+
// lib/data/to-component.ts
|
491
|
+
init_react_import();
|
492
|
+
var toComponent = (item) => {
|
493
|
+
return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
|
494
|
+
props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
|
495
|
+
type: "root"
|
496
|
+
});
|
497
|
+
};
|
498
|
+
|
499
|
+
// lib/resolve-all-data.ts
|
500
|
+
function resolveAllData(_0, _1) {
|
501
|
+
return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
|
502
|
+
var _a;
|
503
|
+
const defaultedData = defaultData(data);
|
504
|
+
const resolveNode = (_node) => __async(this, null, function* () {
|
505
|
+
const node = toComponent(_node);
|
506
|
+
onResolveStart == null ? void 0 : onResolveStart(node);
|
507
|
+
const resolved = (yield resolveComponentData(
|
508
|
+
node,
|
509
|
+
config,
|
510
|
+
metadata,
|
511
|
+
() => {
|
512
|
+
},
|
513
|
+
() => {
|
514
|
+
},
|
515
|
+
"force",
|
516
|
+
false
|
517
|
+
)).node;
|
518
|
+
const resolvedDeep = yield mapSlotsAsync(
|
519
|
+
resolved,
|
520
|
+
processContent,
|
521
|
+
false
|
522
|
+
);
|
523
|
+
onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
|
524
|
+
return resolvedDeep;
|
525
|
+
});
|
526
|
+
const processContent = (content) => __async(this, null, function* () {
|
527
|
+
return Promise.all(content.map(resolveNode));
|
528
|
+
});
|
529
|
+
const processZones = () => __async(this, null, function* () {
|
530
|
+
var _a2;
|
531
|
+
const zones = (_a2 = data.zones) != null ? _a2 : {};
|
532
|
+
Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
|
533
|
+
zones[zoneKey] = yield Promise.all(content.map(resolveNode));
|
534
|
+
}));
|
535
|
+
return zones;
|
536
|
+
});
|
537
|
+
const dynamic = {
|
538
|
+
root: yield resolveNode(defaultedData.root),
|
539
|
+
content: yield processContent(defaultedData.content),
|
540
|
+
zones: yield processZones()
|
541
|
+
};
|
542
|
+
Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
|
543
|
+
const content = defaultedData.zones[zoneKey];
|
544
|
+
dynamic.zones[zoneKey] = yield processContent(content);
|
545
|
+
}), {});
|
546
|
+
return dynamic;
|
547
|
+
});
|
548
|
+
}
|
549
|
+
|
550
|
+
export {
|
551
|
+
__spreadValues,
|
552
|
+
__spreadProps,
|
553
|
+
__objRest,
|
554
|
+
__commonJS,
|
555
|
+
__toESM,
|
556
|
+
__privateGet,
|
557
|
+
__privateAdd,
|
558
|
+
__privateSet,
|
559
|
+
__async,
|
560
|
+
init_react_import,
|
561
|
+
isSlot,
|
562
|
+
createIsSlotConfig,
|
563
|
+
rootAreaId,
|
564
|
+
rootZone,
|
565
|
+
rootDroppableId,
|
566
|
+
walkTree,
|
567
|
+
setupZone,
|
568
|
+
getChanged,
|
569
|
+
resolveComponentData,
|
570
|
+
useSlots,
|
571
|
+
Render,
|
572
|
+
SlotRenderPure,
|
573
|
+
SlotRender,
|
574
|
+
transformProps,
|
575
|
+
resolveAllData
|
576
|
+
};
|
package/dist/index.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { H as History,
|
2
|
-
export {
|
1
|
+
import { H as History, P as Permissions, C as ComponentData, a as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as Field, h as FieldProps, D as DropZoneProps, i as Data, j as OnAction, k as InitialHistory, l as ItemSelector } from './walk-tree-CM-cu7GU.mjs';
|
2
|
+
export { Z as Adaptor, X as ArrayField, t as ArrayState, aa as AsFieldProps, B as BaseData, K as BaseField, G as ComponentDataMap, z as ComponentDataOptionalId, J as Content, a1 as CustomField, a0 as CustomFieldRender, a7 as DefaultComponentProps, a4 as DefaultRootFieldProps, a6 as DefaultRootProps, a5 as DefaultRootRenderProps, m as Direction, n as DragAxis, $ as ExternalField, _ as ExternalFieldWithAdaptor, ac as ExtractPropsFromConfig, ad as ExtractRootPropsFromConfig, r as FieldRenderFunctions, s as ItemWithId, E as MappedItem, N as NumberField, Y as ObjectField, q as OverrideKey, u as PuckComponent, a3 as PuckContext, W as RadioField, v as RootConfig, y as RootData, x as RootDataWithoutProps, Q as SelectField, S as Slot, a2 as SlotField, T as TextField, L as TextareaField, o as Viewport, ab as WithChildren, a8 as WithId, a9 as WithPuckProps, p as overrideKeys, af as resolveAllData, ae as transformProps, w as walkTree } from './walk-tree-CM-cu7GU.mjs';
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
4
4
|
import * as react from 'react';
|
5
5
|
import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';
|
@@ -248,18 +248,12 @@ declare function Render<UserConfig extends Config = Config, G extends UserGeneri
|
|
248
248
|
|
249
249
|
declare function migrate(data: Data, config?: Config): Data;
|
250
250
|
|
251
|
-
type MapSlotOptions = {
|
252
|
-
parentId: string;
|
253
|
-
propName: string;
|
254
|
-
};
|
255
|
-
declare function mapSlotsPublic<T extends ComponentData | RootData>(item: T, config: Config, map: (data: Content, options: MapSlotOptions) => Content): T;
|
256
|
-
|
257
251
|
type WithGet<T> = T & {
|
258
252
|
get: () => T;
|
259
253
|
};
|
260
254
|
type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
|
261
255
|
appState: AppState;
|
262
|
-
config:
|
256
|
+
config: UserConfig;
|
263
257
|
dispatch: AppStore["dispatch"];
|
264
258
|
getPermissions: GetPermissions<UserConfig>;
|
265
259
|
refreshPermissions: RefreshPermissions<UserConfig>;
|
@@ -292,4 +286,4 @@ type UsePuckStore<UserConfig extends Config = Config> = WithGet<PuckApi<UserConf
|
|
292
286
|
declare function createUsePuck<UserConfig extends Config = Config>(): <T = PuckApi<UserConfig>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
|
293
287
|
declare function usePuck<UserConfig extends Config = Config>(): UsePuckStore<UserConfig>;
|
294
288
|
|
295
|
-
export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config,
|
289
|
+
export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, Drawer, DropZone, Field, FieldLabel, FieldProps, Fields, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, type PuckApi, Render, ResolveDataTrigger, RootDataWithProps, UiState, type UsePuckData, UserGenerics, Viewports, createUsePuck, migrate, renderContext, usePuck };
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { H as History,
|
2
|
-
export {
|
1
|
+
import { H as History, P as Permissions, C as ComponentData, a as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as Field, h as FieldProps, D as DropZoneProps, i as Data, j as OnAction, k as InitialHistory, l as ItemSelector } from './walk-tree-CM-cu7GU.js';
|
2
|
+
export { Z as Adaptor, X as ArrayField, t as ArrayState, aa as AsFieldProps, B as BaseData, K as BaseField, G as ComponentDataMap, z as ComponentDataOptionalId, J as Content, a1 as CustomField, a0 as CustomFieldRender, a7 as DefaultComponentProps, a4 as DefaultRootFieldProps, a6 as DefaultRootProps, a5 as DefaultRootRenderProps, m as Direction, n as DragAxis, $ as ExternalField, _ as ExternalFieldWithAdaptor, ac as ExtractPropsFromConfig, ad as ExtractRootPropsFromConfig, r as FieldRenderFunctions, s as ItemWithId, E as MappedItem, N as NumberField, Y as ObjectField, q as OverrideKey, u as PuckComponent, a3 as PuckContext, W as RadioField, v as RootConfig, y as RootData, x as RootDataWithoutProps, Q as SelectField, S as Slot, a2 as SlotField, T as TextField, L as TextareaField, o as Viewport, ab as WithChildren, a8 as WithId, a9 as WithPuckProps, p as overrideKeys, af as resolveAllData, ae as transformProps, w as walkTree } from './walk-tree-CM-cu7GU.js';
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
4
4
|
import * as react from 'react';
|
5
5
|
import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';
|
@@ -248,18 +248,12 @@ declare function Render<UserConfig extends Config = Config, G extends UserGeneri
|
|
248
248
|
|
249
249
|
declare function migrate(data: Data, config?: Config): Data;
|
250
250
|
|
251
|
-
type MapSlotOptions = {
|
252
|
-
parentId: string;
|
253
|
-
propName: string;
|
254
|
-
};
|
255
|
-
declare function mapSlotsPublic<T extends ComponentData | RootData>(item: T, config: Config, map: (data: Content, options: MapSlotOptions) => Content): T;
|
256
|
-
|
257
251
|
type WithGet<T> = T & {
|
258
252
|
get: () => T;
|
259
253
|
};
|
260
254
|
type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>> = {
|
261
255
|
appState: AppState;
|
262
|
-
config:
|
256
|
+
config: UserConfig;
|
263
257
|
dispatch: AppStore["dispatch"];
|
264
258
|
getPermissions: GetPermissions<UserConfig>;
|
265
259
|
refreshPermissions: RefreshPermissions<UserConfig>;
|
@@ -292,4 +286,4 @@ type UsePuckStore<UserConfig extends Config = Config> = WithGet<PuckApi<UserConf
|
|
292
286
|
declare function createUsePuck<UserConfig extends Config = Config>(): <T = PuckApi<UserConfig>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
|
293
287
|
declare function usePuck<UserConfig extends Config = Config>(): UsePuckStore<UserConfig>;
|
294
288
|
|
295
|
-
export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config,
|
289
|
+
export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, Drawer, DropZone, Field, FieldLabel, FieldProps, Fields, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, type PuckApi, Render, ResolveDataTrigger, RootDataWithProps, UiState, type UsePuckData, UserGenerics, Viewports, createUsePuck, migrate, renderContext, usePuck };
|