@measured/puck 0.19.0-canary.a967ca42 → 0.19.0-canary.af1dc891
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/{chunk-GL73J54P.mjs → chunk-HGAPIQP5.mjs} +231 -161
- package/dist/index.css +115 -113
- package/dist/index.d.mts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +782 -591
- package/dist/index.mjs +555 -426
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +232 -167
- package/dist/rsc.mjs +1 -1
- package/dist/{walk-tree-DOB5QZVq.d.mts → walk-tree-DBd3aQ_5.d.mts} +26 -21
- package/dist/{walk-tree-DOB5QZVq.d.ts → walk-tree-DBd3aQ_5.d.ts} +26 -21
- package/package.json +12 -7
package/dist/rsc.d.mts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
|
-
import { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-
|
3
|
-
export { af as migrate, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-
|
2
|
+
import { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-DBd3aQ_5.mjs';
|
3
|
+
export { af as migrate, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-DBd3aQ_5.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 { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-
|
3
|
-
export { af as migrate, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-
|
2
|
+
import { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-DBd3aQ_5.js';
|
3
|
+
export { af as migrate, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-DBd3aQ_5.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
@@ -97,32 +97,165 @@ var setupZone = (data, zoneKey) => {
|
|
97
97
|
|
98
98
|
// lib/use-slots.tsx
|
99
99
|
var import_react2 = require("react");
|
100
|
-
|
100
|
+
|
101
|
+
// lib/data/map-slots.ts
|
102
|
+
var isPromise = (v) => !!v && typeof v.then === "function";
|
103
|
+
var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
|
104
|
+
var containsPromise = (arr) => arr.some(isPromise);
|
105
|
+
var walkField = ({
|
106
|
+
value,
|
107
|
+
fields,
|
108
|
+
map,
|
109
|
+
propKey = "",
|
110
|
+
propPath = "",
|
111
|
+
id = "",
|
112
|
+
config,
|
113
|
+
recurseSlots = false
|
114
|
+
}) => {
|
115
|
+
var _a, _b, _c;
|
116
|
+
if (((_a = fields[propKey]) == null ? void 0 : _a.type) === "slot") {
|
117
|
+
const content = value || [];
|
118
|
+
const mappedContent = recurseSlots ? content.map((el) => {
|
119
|
+
var _a2;
|
120
|
+
const componentConfig = config.components[el.type];
|
121
|
+
if (!componentConfig) {
|
122
|
+
throw new Error(`Could not find component config for ${el.type}`);
|
123
|
+
}
|
124
|
+
const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
|
125
|
+
return walkField({
|
126
|
+
value: el,
|
127
|
+
fields: fields2,
|
128
|
+
map,
|
129
|
+
id: el.props.id,
|
130
|
+
config,
|
131
|
+
recurseSlots
|
132
|
+
});
|
133
|
+
}) : content;
|
134
|
+
if (containsPromise(mappedContent)) {
|
135
|
+
return Promise.all(mappedContent);
|
136
|
+
}
|
137
|
+
return map(mappedContent, id, propPath, fields[propKey], propPath);
|
138
|
+
}
|
139
|
+
if (value && typeof value === "object") {
|
140
|
+
if (Array.isArray(value)) {
|
141
|
+
const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
|
142
|
+
if (!arrayFields) return value;
|
143
|
+
const newValue = value.map(
|
144
|
+
(el, idx) => walkField({
|
145
|
+
value: el,
|
146
|
+
fields: arrayFields,
|
147
|
+
map,
|
148
|
+
propKey,
|
149
|
+
propPath: `${propPath}[${idx}]`,
|
150
|
+
id,
|
151
|
+
config,
|
152
|
+
recurseSlots
|
153
|
+
})
|
154
|
+
);
|
155
|
+
if (containsPromise(newValue)) {
|
156
|
+
return Promise.all(newValue);
|
157
|
+
}
|
158
|
+
return newValue;
|
159
|
+
} else if ("$$typeof" in value) {
|
160
|
+
return value;
|
161
|
+
} else {
|
162
|
+
const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
|
163
|
+
return walkObject({
|
164
|
+
value,
|
165
|
+
fields: objectFields,
|
166
|
+
map,
|
167
|
+
id,
|
168
|
+
getPropPath: (k) => `${propPath}.${k}`,
|
169
|
+
config,
|
170
|
+
recurseSlots
|
171
|
+
});
|
172
|
+
}
|
173
|
+
}
|
174
|
+
return value;
|
175
|
+
};
|
176
|
+
var walkObject = ({
|
177
|
+
value,
|
178
|
+
fields,
|
179
|
+
map,
|
180
|
+
id,
|
181
|
+
getPropPath,
|
182
|
+
config,
|
183
|
+
recurseSlots
|
184
|
+
}) => {
|
185
|
+
const newProps = Object.entries(value).map(([k, v]) => {
|
186
|
+
const opts = {
|
187
|
+
value: v,
|
188
|
+
fields,
|
189
|
+
map,
|
190
|
+
propKey: k,
|
191
|
+
propPath: getPropPath(k),
|
192
|
+
id,
|
193
|
+
config,
|
194
|
+
recurseSlots
|
195
|
+
};
|
196
|
+
const newValue = walkField(opts);
|
197
|
+
if (isPromise(newValue)) {
|
198
|
+
return newValue.then((resolvedValue) => ({
|
199
|
+
[k]: resolvedValue
|
200
|
+
}));
|
201
|
+
}
|
202
|
+
return {
|
203
|
+
[k]: newValue
|
204
|
+
};
|
205
|
+
}, {});
|
206
|
+
if (containsPromise(newProps)) {
|
207
|
+
return Promise.all(newProps).then(flatten);
|
208
|
+
}
|
209
|
+
return flatten(newProps);
|
210
|
+
};
|
211
|
+
function mapSlots(item, map, config, recurseSlots = false) {
|
212
|
+
var _a, _b, _c, _d;
|
213
|
+
const itemType = "type" in item ? item.type : "root";
|
214
|
+
const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
|
215
|
+
const newProps = walkObject({
|
216
|
+
value: (_b = item.props) != null ? _b : {},
|
217
|
+
fields: (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {},
|
218
|
+
map,
|
219
|
+
id: item.props ? (_d = item.props.id) != null ? _d : "root" : "root",
|
220
|
+
getPropPath: (k) => k,
|
221
|
+
config,
|
222
|
+
recurseSlots
|
223
|
+
});
|
224
|
+
if (isPromise(newProps)) {
|
225
|
+
return newProps.then((resolvedProps) => __spreadProps(__spreadValues({}, item), {
|
226
|
+
props: resolvedProps
|
227
|
+
}));
|
228
|
+
}
|
229
|
+
return __spreadProps(__spreadValues({}, item), {
|
230
|
+
props: newProps
|
231
|
+
});
|
232
|
+
}
|
233
|
+
|
234
|
+
// lib/use-slots.tsx
|
235
|
+
function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
|
101
236
|
const slotProps = (0, import_react2.useMemo)(() => {
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
if ((field == null ? void 0 : field.type) === "slot") {
|
109
|
-
const content = props[fieldKey] || [];
|
110
|
-
const render = (readOnly == null ? void 0 : readOnly[fieldKey]) || forceReadOnly ? renderSlotRender : renderSlotEdit;
|
237
|
+
const mapped = mapSlots(
|
238
|
+
item,
|
239
|
+
(content, _parentId, propName, field, propPath) => {
|
240
|
+
const wildcardPath = propPath.replace(/\[\d+\]/g, "[*]");
|
241
|
+
const isReadOnly = (readOnly == null ? void 0 : readOnly[propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly;
|
242
|
+
const render = isReadOnly ? renderSlotRender : renderSlotEdit;
|
111
243
|
const Slot = (dzProps) => render(__spreadProps(__spreadValues({
|
112
|
-
allow: field.allow,
|
113
|
-
disallow: field.disallow
|
244
|
+
allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
|
245
|
+
disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
|
114
246
|
}, dzProps), {
|
115
|
-
zone:
|
247
|
+
zone: propName,
|
116
248
|
content
|
117
249
|
}));
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
|
122
|
-
|
250
|
+
return Slot;
|
251
|
+
},
|
252
|
+
config
|
253
|
+
).props;
|
254
|
+
return mapped;
|
255
|
+
}, [config, item, readOnly, forceReadOnly]);
|
123
256
|
const mergedProps = (0, import_react2.useMemo)(
|
124
|
-
() => __spreadValues(__spreadValues({}, props), slotProps),
|
125
|
-
[props, slotProps]
|
257
|
+
() => __spreadValues(__spreadValues({}, item.props), slotProps),
|
258
|
+
[item.props, slotProps]
|
126
259
|
);
|
127
260
|
return mergedProps;
|
128
261
|
}
|
@@ -137,7 +270,7 @@ var Item = ({
|
|
137
270
|
metadata
|
138
271
|
}) => {
|
139
272
|
const Component = config.components[item.type];
|
140
|
-
const props = useSlots(
|
273
|
+
const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
141
274
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
142
275
|
Component.render,
|
143
276
|
__spreadProps(__spreadValues({}, props), {
|
@@ -199,12 +332,15 @@ function DropZoneRender({
|
|
199
332
|
metadata
|
200
333
|
}
|
201
334
|
),
|
202
|
-
metadata
|
335
|
+
metadata,
|
336
|
+
dragRef: null,
|
337
|
+
isEditing: false
|
203
338
|
}
|
204
339
|
});
|
205
|
-
const
|
340
|
+
const renderItem = __spreadProps(__spreadValues({}, item), { props });
|
341
|
+
const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
206
342
|
if (Component) {
|
207
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component.render, __spreadValues({}, propsWithSlots),
|
343
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
|
208
344
|
}
|
209
345
|
return null;
|
210
346
|
}) });
|
@@ -215,7 +351,7 @@ function Render({
|
|
215
351
|
metadata = {}
|
216
352
|
}) {
|
217
353
|
var _a;
|
218
|
-
const rootProps = data.root.props
|
354
|
+
const rootProps = "props" in data.root ? data.root.props : data.root;
|
219
355
|
const title = rootProps.title || "";
|
220
356
|
const props = __spreadProps(__spreadValues({}, rootProps), {
|
221
357
|
puck: {
|
@@ -236,7 +372,7 @@ function Render({
|
|
236
372
|
editMode: false,
|
237
373
|
id: "puck-root"
|
238
374
|
});
|
239
|
-
const propsWithSlots = useSlots(config
|
375
|
+
const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
240
376
|
if ((_a = config.root) == null ? void 0 : _a.render) {
|
241
377
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
242
378
|
DropZoneRender,
|
@@ -259,77 +395,29 @@ function Render({
|
|
259
395
|
);
|
260
396
|
}
|
261
397
|
|
262
|
-
// lib/data/is-slot.ts
|
263
|
-
var isSlot = (prop) => {
|
264
|
-
var _a, _b;
|
265
|
-
return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
|
266
|
-
};
|
267
|
-
var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
|
268
|
-
var _a, _b;
|
269
|
-
const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
|
270
|
-
if (!configForComponent) return isSlot(propValue);
|
271
|
-
return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
|
272
|
-
};
|
273
|
-
|
274
|
-
// lib/data/map-slots.ts
|
275
|
-
function mapSlotsAsync(_0, _1) {
|
276
|
-
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
277
|
-
const props = __spreadValues({}, item.props);
|
278
|
-
const propKeys = Object.keys(props);
|
279
|
-
for (let i = 0; i < propKeys.length; i++) {
|
280
|
-
const propKey = propKeys[i];
|
281
|
-
const itemType = "type" in item ? item.type : "root";
|
282
|
-
if (isSlot2(itemType, propKey, props[propKey])) {
|
283
|
-
const content = props[propKey];
|
284
|
-
const mappedContent = recursive ? yield Promise.all(
|
285
|
-
content.map((item2) => __async(this, null, function* () {
|
286
|
-
return yield mapSlotsAsync(item2, map, recursive, isSlot2);
|
287
|
-
}))
|
288
|
-
) : content;
|
289
|
-
props[propKey] = yield map(mappedContent, propKey);
|
290
|
-
}
|
291
|
-
}
|
292
|
-
return __spreadProps(__spreadValues({}, item), { props });
|
293
|
-
});
|
294
|
-
}
|
295
|
-
function mapSlotsSync(item, map, isSlot2 = isSlot) {
|
296
|
-
var _a, _b;
|
297
|
-
const props = __spreadValues({}, item.props);
|
298
|
-
const propKeys = Object.keys(props);
|
299
|
-
for (let i = 0; i < propKeys.length; i++) {
|
300
|
-
const propKey = propKeys[i];
|
301
|
-
const itemType = "type" in item ? item.type : "root";
|
302
|
-
if (isSlot2(itemType, propKey, props[propKey])) {
|
303
|
-
const content = props[propKey];
|
304
|
-
const mappedContent = content.map((item2) => {
|
305
|
-
return mapSlotsSync(item2, map, isSlot2);
|
306
|
-
});
|
307
|
-
props[propKey] = (_b = map(mappedContent, (_a = props.id) != null ? _a : "root", propKey)) != null ? _b : mappedContent;
|
308
|
-
}
|
309
|
-
}
|
310
|
-
return __spreadProps(__spreadValues({}, item), { props });
|
311
|
-
}
|
312
|
-
|
313
398
|
// lib/get-changed.ts
|
399
|
+
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
|
314
400
|
var getChanged = (newItem, oldItem) => {
|
315
401
|
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
316
402
|
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
317
403
|
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
318
404
|
return __spreadProps(__spreadValues({}, acc), {
|
319
|
-
[item]: oldItemProps[item]
|
405
|
+
[item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
|
320
406
|
});
|
321
407
|
}, {}) : {};
|
322
408
|
};
|
323
409
|
|
324
410
|
// lib/resolve-component-data.ts
|
325
|
-
var
|
411
|
+
var import_fast_deep_equal2 = __toESM(require("fast-deep-equal"));
|
326
412
|
var cache = { lastChange: {} };
|
327
|
-
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace"
|
413
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
328
414
|
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
329
|
-
|
330
|
-
|
415
|
+
const resolvedItem = __spreadValues({}, item);
|
416
|
+
const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
|
417
|
+
const id = "id" in item.props ? item.props.id : "root";
|
418
|
+
if (shouldRunResolver) {
|
331
419
|
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
332
|
-
if (item && (0,
|
420
|
+
if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
|
333
421
|
return { node: resolved, didChange: false };
|
334
422
|
}
|
335
423
|
const changed = getChanged(item, oldItem);
|
@@ -342,46 +430,42 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
342
430
|
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
343
431
|
trigger
|
344
432
|
});
|
345
|
-
|
346
|
-
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
347
|
-
});
|
348
|
-
if (recursive) {
|
349
|
-
resolvedItem = yield mapSlotsAsync(
|
350
|
-
resolvedItem,
|
351
|
-
(content) => __async(void 0, null, function* () {
|
352
|
-
return Promise.all(
|
353
|
-
content.map(
|
354
|
-
(childItem) => __async(void 0, null, function* () {
|
355
|
-
return (yield resolveComponentData(
|
356
|
-
childItem,
|
357
|
-
config,
|
358
|
-
metadata,
|
359
|
-
onResolveStart,
|
360
|
-
onResolveEnd,
|
361
|
-
trigger,
|
362
|
-
false
|
363
|
-
)).node;
|
364
|
-
})
|
365
|
-
)
|
366
|
-
);
|
367
|
-
}),
|
368
|
-
false,
|
369
|
-
createIsSlotConfig(config)
|
370
|
-
);
|
371
|
-
}
|
433
|
+
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
372
434
|
if (Object.keys(readOnly).length) {
|
373
435
|
resolvedItem.readOnly = readOnly;
|
374
436
|
}
|
375
|
-
cache.lastChange[id] = {
|
376
|
-
item,
|
377
|
-
resolved: resolvedItem
|
378
|
-
};
|
379
|
-
if (onResolveEnd) {
|
380
|
-
onResolveEnd(resolvedItem);
|
381
|
-
}
|
382
|
-
return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
|
383
437
|
}
|
384
|
-
|
438
|
+
let itemWithResolvedChildren = yield mapSlots(
|
439
|
+
resolvedItem,
|
440
|
+
(content) => __async(void 0, null, function* () {
|
441
|
+
return yield Promise.all(
|
442
|
+
content.map(
|
443
|
+
(childItem) => __async(void 0, null, function* () {
|
444
|
+
return (yield resolveComponentData(
|
445
|
+
childItem,
|
446
|
+
config,
|
447
|
+
metadata,
|
448
|
+
onResolveStart,
|
449
|
+
onResolveEnd,
|
450
|
+
trigger
|
451
|
+
)).node;
|
452
|
+
})
|
453
|
+
)
|
454
|
+
);
|
455
|
+
}),
|
456
|
+
config
|
457
|
+
);
|
458
|
+
if (shouldRunResolver && onResolveEnd) {
|
459
|
+
onResolveEnd(resolvedItem);
|
460
|
+
}
|
461
|
+
cache.lastChange[id] = {
|
462
|
+
item,
|
463
|
+
resolved: itemWithResolvedChildren
|
464
|
+
};
|
465
|
+
return {
|
466
|
+
node: itemWithResolvedChildren,
|
467
|
+
didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
|
468
|
+
};
|
385
469
|
});
|
386
470
|
|
387
471
|
// lib/data/default-data.ts
|
@@ -414,13 +498,12 @@ function resolveAllData(_0, _1) {
|
|
414
498
|
},
|
415
499
|
() => {
|
416
500
|
},
|
417
|
-
"force"
|
418
|
-
false
|
501
|
+
"force"
|
419
502
|
)).node;
|
420
|
-
const resolvedDeep = yield
|
503
|
+
const resolvedDeep = yield mapSlots(
|
421
504
|
resolved,
|
422
505
|
processContent,
|
423
|
-
|
506
|
+
config
|
424
507
|
);
|
425
508
|
onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
|
426
509
|
return resolvedDeep;
|
@@ -452,12 +535,15 @@ function resolveAllData(_0, _1) {
|
|
452
535
|
// lib/data/walk-tree.ts
|
453
536
|
function walkTree(data, config, callbackFn) {
|
454
537
|
var _a, _b;
|
455
|
-
const isSlot2 = createIsSlotConfig(config);
|
456
538
|
const walkItem = (item) => {
|
457
|
-
return
|
539
|
+
return mapSlots(
|
458
540
|
item,
|
459
|
-
(content, parentId, propName) =>
|
460
|
-
|
541
|
+
(content, parentId, propName) => {
|
542
|
+
var _a2;
|
543
|
+
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
544
|
+
},
|
545
|
+
config,
|
546
|
+
true
|
461
547
|
);
|
462
548
|
};
|
463
549
|
if ("props" in data) {
|
@@ -545,27 +631,6 @@ var defaultAppState = {
|
|
545
631
|
}
|
546
632
|
};
|
547
633
|
|
548
|
-
// lib/data/for-each-slot.ts
|
549
|
-
var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
|
550
|
-
const props = item.props || {};
|
551
|
-
const propKeys = Object.keys(props);
|
552
|
-
for (let i = 0; i < propKeys.length; i++) {
|
553
|
-
const propKey = propKeys[i];
|
554
|
-
const itemType = "type" in item ? item.type : "root";
|
555
|
-
if (isSlot2(itemType, propKey, props[propKey])) {
|
556
|
-
const content = props[propKey];
|
557
|
-
cb(props.id, propKey, content);
|
558
|
-
if (recursive) {
|
559
|
-
content.forEach(
|
560
|
-
(childItem) => __async(void 0, null, function* () {
|
561
|
-
return forEachSlot(childItem, cb, true, isSlot2);
|
562
|
-
})
|
563
|
-
);
|
564
|
-
}
|
565
|
-
}
|
566
|
-
}
|
567
|
-
};
|
568
|
-
|
569
634
|
// lib/get-zone-id.ts
|
570
635
|
var getZoneId = (zoneCompound) => {
|
571
636
|
if (!zoneCompound) {
|
@@ -587,18 +652,18 @@ function forRelatedZones(item, data, cb, path = []) {
|
|
587
652
|
});
|
588
653
|
}
|
589
654
|
|
655
|
+
// lib/data/flatten-node.ts
|
656
|
+
var import_flat = require("flat");
|
657
|
+
|
590
658
|
// lib/data/strip-slots.ts
|
591
|
-
var stripSlots = (data) => {
|
592
|
-
return
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
},
|
600
|
-
{ id: data.props.id }
|
601
|
-
)
|
659
|
+
var stripSlots = (data, config) => {
|
660
|
+
return mapSlots(data, () => null, config);
|
661
|
+
};
|
662
|
+
|
663
|
+
// lib/data/flatten-node.ts
|
664
|
+
var flattenNode = (node, config) => {
|
665
|
+
return __spreadProps(__spreadValues({}, node), {
|
666
|
+
props: (0, import_flat.flatten)(stripSlots(node, config).props)
|
602
667
|
});
|
603
668
|
};
|
604
669
|
|
@@ -644,10 +709,9 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
|
|
644
709
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
645
710
|
if (!mappedItem) return item;
|
646
711
|
const id = mappedItem.props.id;
|
647
|
-
const newProps = __spreadValues({},
|
648
|
-
forEachSlot(
|
712
|
+
const newProps = __spreadProps(__spreadValues({}, mapSlots(
|
649
713
|
mappedItem,
|
650
|
-
(parentId2, slotId
|
714
|
+
(content, parentId2, slotId) => {
|
651
715
|
const zoneCompound = `${parentId2}:${slotId}`;
|
652
716
|
const [_2, newContent2] = processContent(
|
653
717
|
path,
|
@@ -656,18 +720,19 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
|
|
656
720
|
"slot",
|
657
721
|
parentId2
|
658
722
|
);
|
659
|
-
|
723
|
+
return newContent2;
|
660
724
|
},
|
661
|
-
|
662
|
-
|
663
|
-
|
725
|
+
config
|
726
|
+
).props), {
|
727
|
+
id
|
728
|
+
});
|
664
729
|
processRelatedZones(item, id, path);
|
665
730
|
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
666
731
|
const thisZoneCompound = path[path.length - 1];
|
667
732
|
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
668
733
|
newNodeIndex[id] = {
|
669
734
|
data: newItem,
|
670
|
-
flatData:
|
735
|
+
flatData: flattenNode(newItem, config),
|
671
736
|
path,
|
672
737
|
parentId,
|
673
738
|
zone
|
package/dist/rsc.mjs
CHANGED
@@ -24,6 +24,7 @@ type BaseField = {
|
|
24
24
|
label?: string;
|
25
25
|
labelIcon?: ReactElement;
|
26
26
|
metadata?: Metadata;
|
27
|
+
visible?: boolean;
|
27
28
|
};
|
28
29
|
type TextField = BaseField & {
|
29
30
|
type: "text";
|
@@ -147,10 +148,14 @@ type FieldProps<F = Field<any>, ValueType = any> = {
|
|
147
148
|
readOnly?: boolean;
|
148
149
|
};
|
149
150
|
|
151
|
+
type SlotComponent = (props?: Omit<DropZoneProps, "zone">) => ReactNode;
|
150
152
|
type PuckComponent<Props> = (props: WithId<WithPuckProps<{
|
151
|
-
[
|
153
|
+
[K in keyof Props]: WithDeepSlots<Props[K], SlotComponent>;
|
152
154
|
}>>) => JSX.Element;
|
153
155
|
type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
|
156
|
+
type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
|
157
|
+
props?: Partial<Props>;
|
158
|
+
};
|
154
159
|
type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderProps, DataShape = Omit<ComponentData<FieldProps>, "type">> = {
|
155
160
|
render: PuckComponent<RenderProps>;
|
156
161
|
label?: string;
|
@@ -175,13 +180,7 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
175
180
|
lastData: DataShape | null;
|
176
181
|
metadata: Metadata;
|
177
182
|
trigger: ResolveDataTrigger;
|
178
|
-
}) => Promise<
|
179
|
-
props?: Partial<FieldProps>;
|
180
|
-
readOnly?: Partial<Record<keyof FieldProps, boolean>>;
|
181
|
-
}> | {
|
182
|
-
props?: Partial<FieldProps>;
|
183
|
-
readOnly?: Partial<Record<keyof FieldProps, boolean>>;
|
184
|
-
};
|
183
|
+
}) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
|
185
184
|
resolvePermissions?: (data: DataShape, params: {
|
186
185
|
changed: Partial<Record<keyof FieldProps, boolean> & {
|
187
186
|
id: string;
|
@@ -239,6 +238,7 @@ type PuckContext = {
|
|
239
238
|
dragRef: ((element: Element | null) => void) | null;
|
240
239
|
};
|
241
240
|
type DefaultRootFieldProps = {
|
241
|
+
[key: string]: any;
|
242
242
|
title?: string;
|
243
243
|
};
|
244
244
|
type DefaultRootRenderProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = WithPuckProps<WithChildren<Props>>;
|
@@ -255,13 +255,13 @@ type BaseData<Props extends {
|
|
255
255
|
readOnly?: Partial<Record<keyof Props, boolean>>;
|
256
256
|
};
|
257
257
|
type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = BaseData<Props> & {
|
258
|
-
props:
|
258
|
+
props: Props;
|
259
259
|
};
|
260
260
|
type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
|
261
261
|
type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
|
262
|
-
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
262
|
+
type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string, AllProps extends Record<string, DefaultComponentProps> = Record<string, DefaultComponentProps>> = {
|
263
263
|
type: Name;
|
264
|
-
props: WithId<
|
264
|
+
props: WithDeepSlots<WithId<Props>, Content<AllProps>>;
|
265
265
|
} & BaseData<Props>;
|
266
266
|
type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
|
267
267
|
type: Name;
|
@@ -270,18 +270,18 @@ type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultCompon
|
|
270
270
|
};
|
271
271
|
} & BaseData<Props>;
|
272
272
|
type MappedItem = ComponentData;
|
273
|
-
type ComponentDataMap<
|
274
|
-
[K in keyof
|
275
|
-
}[keyof
|
273
|
+
type ComponentDataMap<AllProps extends DefaultAllProps = DefaultAllProps> = {
|
274
|
+
[K in keyof AllProps]: ComponentData<AllProps[K], K extends string ? K : never, AllProps>;
|
275
|
+
}[keyof AllProps];
|
276
276
|
type Content<PropsMap extends {
|
277
277
|
[key: string]: DefaultComponentProps;
|
278
278
|
} = {
|
279
279
|
[key: string]: DefaultComponentProps;
|
280
280
|
}> = ComponentDataMap<PropsMap>[];
|
281
|
-
type Data<
|
282
|
-
root: RootData<RootProps
|
283
|
-
content: Content<
|
284
|
-
zones?: Record<string, Content<
|
281
|
+
type Data<AllProps extends DefaultAllProps = DefaultAllProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
|
282
|
+
root: WithDeepSlots<RootData<RootProps>, Content<AllProps>>;
|
283
|
+
content: Content<AllProps>;
|
284
|
+
zones?: Record<string, Content<AllProps>>;
|
285
285
|
};
|
286
286
|
type Metadata = {
|
287
287
|
[key: string]: any;
|
@@ -345,6 +345,13 @@ type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
|
|
345
345
|
zones: ZoneIndex;
|
346
346
|
};
|
347
347
|
};
|
348
|
+
type DefaultAllProps = Record<string, DefaultComponentProps>;
|
349
|
+
/**
|
350
|
+
* Recursively walk T and replace Slots with SlotComponents
|
351
|
+
*/
|
352
|
+
type WithDeepSlots<T, SlotType = T> = T extends Slot ? SlotType : T extends (infer U)[] ? Array<WithDeepSlots<U, SlotType>> : T extends (infer U)[] ? WithDeepSlots<U, SlotType>[] : T extends object ? {
|
353
|
+
[K in keyof T]: WithDeepSlots<T[K], SlotType>;
|
354
|
+
} : T;
|
348
355
|
|
349
356
|
type RenderFunc<Props extends {
|
350
357
|
[key: string]: any;
|
@@ -459,9 +466,7 @@ type Slot<Props extends {
|
|
459
466
|
}> = {
|
460
467
|
[K in keyof Props]: ComponentDataOptionalId<Props[K], K extends string ? K : never>;
|
461
468
|
}[keyof Props][];
|
462
|
-
type WithSlotProps<
|
463
|
-
[PropName in keyof Props]: Props[PropName] extends Slot<SlotProps> ? Content<SlotProps> : Props[PropName];
|
464
|
-
};
|
469
|
+
type WithSlotProps<Target extends Record<string, any>, AllProps extends DefaultAllProps = DefaultAllProps, SlotType extends Content<AllProps> = Content<AllProps>> = WithDeepSlots<Target, SlotType>;
|
465
470
|
|
466
471
|
type InsertAction = {
|
467
472
|
type: "insert";
|