@netlisian/softconfig 0.1.8 → 0.1.10
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/puck/index.d.mts +183 -84
- package/dist/puck/index.d.ts +183 -84
- package/dist/puck/index.js +1009 -1470
- package/dist/puck/index.mjs +967 -1430
- package/package.json +6 -3
package/dist/puck/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
"use client";
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __defProps = Object.defineProperties;
|
|
4
5
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -43,24 +44,42 @@ var __async = (__this, __arguments, generator) => {
|
|
|
43
44
|
import { create } from "zustand";
|
|
44
45
|
import { subscribeWithSelector } from "zustand/middleware";
|
|
45
46
|
|
|
46
|
-
// src/puck/
|
|
47
|
-
import
|
|
48
|
-
walkTree as walkTree3
|
|
49
|
-
} from "@measured/puck";
|
|
50
|
-
|
|
51
|
-
// src/puck/lib/get-root-props.ts
|
|
52
|
-
var getRootProps = (appState) => appState.data.root.props;
|
|
47
|
+
// src/puck/lib/root-action-handler.ts
|
|
48
|
+
import isEqual from "react-fast-compare";
|
|
53
49
|
|
|
54
|
-
// src/puck/lib/
|
|
55
|
-
import
|
|
56
|
-
import equal2 from "react-fast-compare";
|
|
57
|
-
import {
|
|
58
|
-
createUsePuck,
|
|
59
|
-
walkTree
|
|
60
|
-
} from "@measured/puck";
|
|
50
|
+
// src/puck/lib/apply-mapping.ts
|
|
51
|
+
import equal from "react-fast-compare";
|
|
61
52
|
|
|
62
|
-
// src/puck/lib/
|
|
63
|
-
|
|
53
|
+
// src/puck/lib/set-prop-by-path.ts
|
|
54
|
+
function setPropertyByPath(props, path, value) {
|
|
55
|
+
const parts = path.replace(/\[(\w+)\]/g, ".$1").split(".");
|
|
56
|
+
const last = parts.pop();
|
|
57
|
+
let cur = props;
|
|
58
|
+
for (const p of parts) {
|
|
59
|
+
if (typeof cur[p] !== "object" || cur[p] === null) cur[p] = {};
|
|
60
|
+
cur = cur[p];
|
|
61
|
+
}
|
|
62
|
+
cur[last] = value;
|
|
63
|
+
}
|
|
64
|
+
function setImmutablePropertyByPath(obj, path, value) {
|
|
65
|
+
if (!path) return value;
|
|
66
|
+
const parts = path.replace(/\[(\w+)\]/g, ".$1").split(".");
|
|
67
|
+
const root = Array.isArray(obj) ? [...obj] : __spreadValues({}, obj);
|
|
68
|
+
let current = root;
|
|
69
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
70
|
+
const part = parts[i];
|
|
71
|
+
const nextPart = parts[i + 1];
|
|
72
|
+
const isArrayNext = !isNaN(Number(nextPart));
|
|
73
|
+
if (current[part] === void 0 || current[part] === null) {
|
|
74
|
+
current[part] = isArrayNext ? [] : {};
|
|
75
|
+
} else {
|
|
76
|
+
current[part] = Array.isArray(current[part]) ? [...current[part]] : __spreadValues({}, current[part]);
|
|
77
|
+
}
|
|
78
|
+
current = current[part];
|
|
79
|
+
}
|
|
80
|
+
current[parts[parts.length - 1]] = value;
|
|
81
|
+
return root;
|
|
82
|
+
}
|
|
64
83
|
|
|
65
84
|
// src/puck/lib/get-settings-by-path.ts
|
|
66
85
|
function getFieldSettingsByPath(fieldSettings, path) {
|
|
@@ -68,14 +87,6 @@ function getFieldSettingsByPath(fieldSettings, path) {
|
|
|
68
87
|
}
|
|
69
88
|
|
|
70
89
|
// src/puck/lib/array-field-utils.ts
|
|
71
|
-
var primitiveFieldTypes = /* @__PURE__ */ new Set([
|
|
72
|
-
"text",
|
|
73
|
-
"textarea",
|
|
74
|
-
"number",
|
|
75
|
-
"select",
|
|
76
|
-
"radio",
|
|
77
|
-
"reference"
|
|
78
|
-
]);
|
|
79
90
|
var isPrimitiveValue = (value) => ["string", "number", "boolean"].includes(typeof value);
|
|
80
91
|
var getFallbackValueForField = (type) => {
|
|
81
92
|
switch (type) {
|
|
@@ -107,7 +118,6 @@ var resolveExpressionSummary = (item, index, expression) => {
|
|
|
107
118
|
});
|
|
108
119
|
return isValid ? result : "";
|
|
109
120
|
};
|
|
110
|
-
var isPrimitiveFieldType = (type) => primitiveFieldTypes.has(type);
|
|
111
121
|
var buildArrayDefaultItemProps = (subFields = [], subFieldSettings = {}) => {
|
|
112
122
|
if (!subFields.length) return void 0;
|
|
113
123
|
const item = {};
|
|
@@ -160,486 +170,19 @@ var getArrayItemSubPath = (arrayPath) => {
|
|
|
160
170
|
return match ? match[1] : null;
|
|
161
171
|
};
|
|
162
172
|
|
|
163
|
-
// src/puck/lib/custom-fields.ts
|
|
164
|
-
var builtInSoftFieldTypes = /* @__PURE__ */ new Set([
|
|
165
|
-
"text",
|
|
166
|
-
"textarea",
|
|
167
|
-
"number",
|
|
168
|
-
"select",
|
|
169
|
-
"radio",
|
|
170
|
-
"array",
|
|
171
|
-
"object",
|
|
172
|
-
"reference"
|
|
173
|
-
]);
|
|
174
|
-
var warnedMessages = /* @__PURE__ */ new Set();
|
|
175
|
-
var warnOnce = (message) => {
|
|
176
|
-
if (warnedMessages.has(message)) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
warnedMessages.add(message);
|
|
180
|
-
console.warn(message);
|
|
181
|
-
};
|
|
182
|
-
var isBuiltInSoftFieldType = (fieldType) => {
|
|
183
|
-
return builtInSoftFieldTypes.has(fieldType);
|
|
184
|
-
};
|
|
185
|
-
var resolveCustomFieldDefinition = (fieldType, customFields) => {
|
|
186
|
-
if (isBuiltInSoftFieldType(fieldType)) {
|
|
187
|
-
return void 0;
|
|
188
|
-
}
|
|
189
|
-
return customFields == null ? void 0 : customFields[fieldType];
|
|
190
|
-
};
|
|
191
|
-
var resolveCustomFieldReturnType = (fieldType, customFields) => {
|
|
192
|
-
const customField = resolveCustomFieldDefinition(fieldType, customFields);
|
|
193
|
-
if (!customField) {
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
if (!customField.returnType) {
|
|
197
|
-
warnOnce(
|
|
198
|
-
`[soft-config] Custom field "${fieldType}" is missing a required returnType and will be skipped from mapping options.`
|
|
199
|
-
);
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
return customField.returnType;
|
|
203
|
-
};
|
|
204
|
-
var resolveCustomFieldSchema = (fieldType, customFields) => {
|
|
205
|
-
const customField = resolveCustomFieldDefinition(fieldType, customFields);
|
|
206
|
-
if (!customField) {
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
const returnType = resolveCustomFieldReturnType(fieldType, customFields);
|
|
210
|
-
if (!returnType) {
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
if (returnType !== "array" && returnType !== "object") {
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
216
|
-
const subFields = customField.subFields || [];
|
|
217
|
-
if (!subFields.length) {
|
|
218
|
-
warnOnce(
|
|
219
|
-
`[soft-config] Custom field "${fieldType}" returns ${returnType} but does not define subFields. It will be skipped from mapping options.`
|
|
220
|
-
);
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
subFields,
|
|
225
|
-
subFieldSettings: customField.subFieldSettings || {}
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
|
-
var getCustomFieldTypeOptions = (customFields) => {
|
|
229
|
-
if (!customFields) {
|
|
230
|
-
return [];
|
|
231
|
-
}
|
|
232
|
-
return Object.entries(customFields).filter(([fieldType]) => !isBuiltInSoftFieldType(fieldType)).map(([fieldType, definition]) => ({
|
|
233
|
-
label: typeof definition.field.label === "string" && definition.field.label ? definition.field.label : fieldType,
|
|
234
|
-
value: fieldType
|
|
235
|
-
}));
|
|
236
|
-
};
|
|
237
|
-
var mapCustomReturnTypeToMappingType = (returnType) => {
|
|
238
|
-
switch (returnType) {
|
|
239
|
-
case "string":
|
|
240
|
-
return "textarea";
|
|
241
|
-
case "number":
|
|
242
|
-
return "number";
|
|
243
|
-
case "boolean":
|
|
244
|
-
return "select";
|
|
245
|
-
case "array":
|
|
246
|
-
return "array";
|
|
247
|
-
case "object":
|
|
248
|
-
return "object";
|
|
249
|
-
default:
|
|
250
|
-
return "textarea";
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
// src/puck/lib/get-field-settings.tsx
|
|
255
|
-
import { jsx } from "react/jsx-runtime";
|
|
256
|
-
var buildPuckField = (field, fieldSettings, customFields) => {
|
|
257
|
-
const customFieldDefinition = resolveCustomFieldDefinition(
|
|
258
|
-
field.type,
|
|
259
|
-
customFields
|
|
260
|
-
);
|
|
261
|
-
const customReturnType = resolveCustomFieldReturnType(field.type, customFields);
|
|
262
|
-
if (customFieldDefinition && customReturnType) {
|
|
263
|
-
return __spreadProps(__spreadValues({}, customFieldDefinition.field), {
|
|
264
|
-
type: "custom",
|
|
265
|
-
label: customFieldDefinition.field.label || field.name
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
const resolvedType = field.type;
|
|
269
|
-
switch (resolvedType) {
|
|
270
|
-
case "text":
|
|
271
|
-
case "textarea":
|
|
272
|
-
return { type: resolvedType, label: field.name };
|
|
273
|
-
case "number":
|
|
274
|
-
return {
|
|
275
|
-
type: resolvedType,
|
|
276
|
-
label: field.name,
|
|
277
|
-
min: fieldSettings == null ? void 0 : fieldSettings.min,
|
|
278
|
-
max: fieldSettings == null ? void 0 : fieldSettings.max,
|
|
279
|
-
step: fieldSettings == null ? void 0 : fieldSettings.step
|
|
280
|
-
};
|
|
281
|
-
case "select":
|
|
282
|
-
case "radio":
|
|
283
|
-
return {
|
|
284
|
-
type: resolvedType,
|
|
285
|
-
label: field.name,
|
|
286
|
-
options: (fieldSettings == null ? void 0 : fieldSettings.options) || []
|
|
287
|
-
};
|
|
288
|
-
case "array": {
|
|
289
|
-
const subFields = (fieldSettings == null ? void 0 : fieldSettings.subFields) || [];
|
|
290
|
-
const subFieldSettings = (fieldSettings == null ? void 0 : fieldSettings.subFieldSettings) || {};
|
|
291
|
-
return {
|
|
292
|
-
type: "array",
|
|
293
|
-
label: field.name,
|
|
294
|
-
min: fieldSettings == null ? void 0 : fieldSettings.min,
|
|
295
|
-
max: fieldSettings == null ? void 0 : fieldSettings.max,
|
|
296
|
-
arrayFields: buildDefaultEditorFields(
|
|
297
|
-
subFields,
|
|
298
|
-
subFieldSettings,
|
|
299
|
-
customFields
|
|
300
|
-
),
|
|
301
|
-
defaultItemProps: buildArrayDefaultItemProps(subFields, subFieldSettings),
|
|
302
|
-
getItemSummary(item, index) {
|
|
303
|
-
return getArrayItemSummary(item, index, fieldSettings);
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
case "object":
|
|
308
|
-
return {
|
|
309
|
-
type: "object",
|
|
310
|
-
label: field.name,
|
|
311
|
-
objectFields: buildDefaultEditorFields(
|
|
312
|
-
(fieldSettings == null ? void 0 : fieldSettings.subFields) || [],
|
|
313
|
-
(fieldSettings == null ? void 0 : fieldSettings.subFieldSettings) || {},
|
|
314
|
-
customFields
|
|
315
|
-
)
|
|
316
|
-
};
|
|
317
|
-
default:
|
|
318
|
-
return { type: "text", label: field.name };
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
var buildDefaultEditorFields = (fields = [], fieldSettings = {}, customFields) => {
|
|
322
|
-
return fields.reduce((acc, field) => {
|
|
323
|
-
acc[field.name] = buildPuckField(
|
|
324
|
-
field,
|
|
325
|
-
fieldSettings[field.name],
|
|
326
|
-
customFields
|
|
327
|
-
);
|
|
328
|
-
return acc;
|
|
329
|
-
}, {});
|
|
330
|
-
};
|
|
331
|
-
var getFieldSettings = (_fields, _fieldSettings, customFields, deep) => {
|
|
332
|
-
const customTypeOptions = getCustomFieldTypeOptions(customFields);
|
|
333
|
-
return (_fields || []).reduce((fields, field) => {
|
|
334
|
-
const fieldSettings = {
|
|
335
|
-
// placeholder: { type: "text", label: "Placeholder" },
|
|
336
|
-
};
|
|
337
|
-
const currentFieldSettings = _fieldSettings == null ? void 0 : _fieldSettings[field.name];
|
|
338
|
-
const customFieldDefinition = resolveCustomFieldDefinition(
|
|
339
|
-
field.type,
|
|
340
|
-
customFields
|
|
341
|
-
);
|
|
342
|
-
const customReturnType = resolveCustomFieldReturnType(
|
|
343
|
-
field.type,
|
|
344
|
-
customFields
|
|
345
|
-
);
|
|
346
|
-
const resolvedType = field.type;
|
|
347
|
-
const customSchema = resolveCustomFieldSchema(field.type, customFields);
|
|
348
|
-
const resolvedSubFields = (customSchema == null ? void 0 : customSchema.subFields) || (currentFieldSettings == null ? void 0 : currentFieldSettings.subFields) || [];
|
|
349
|
-
const resolvedSubFieldSettings = (customSchema == null ? void 0 : customSchema.subFieldSettings) || (currentFieldSettings == null ? void 0 : currentFieldSettings.subFieldSettings) || {};
|
|
350
|
-
const customDefaultValueField = customFieldDefinition && customReturnType ? __spreadProps(__spreadValues({}, customFieldDefinition.field), {
|
|
351
|
-
type: "custom",
|
|
352
|
-
label: customFieldDefinition.field.label || "Default Value"
|
|
353
|
-
}) : null;
|
|
354
|
-
if (customDefaultValueField) {
|
|
355
|
-
fieldSettings.defaultValue = customDefaultValueField;
|
|
356
|
-
}
|
|
357
|
-
switch (resolvedType) {
|
|
358
|
-
case "text":
|
|
359
|
-
case "textarea":
|
|
360
|
-
if (!customDefaultValueField) {
|
|
361
|
-
fieldSettings.defaultValue = {
|
|
362
|
-
type: resolvedType,
|
|
363
|
-
label: "Default Value"
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
break;
|
|
367
|
-
case "number":
|
|
368
|
-
if (!customDefaultValueField) {
|
|
369
|
-
fieldSettings.defaultValue = {
|
|
370
|
-
type: resolvedType,
|
|
371
|
-
label: "Default Value"
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
fieldSettings.min = {
|
|
375
|
-
type: resolvedType,
|
|
376
|
-
label: "Minimum Value"
|
|
377
|
-
};
|
|
378
|
-
fieldSettings.max = {
|
|
379
|
-
type: resolvedType,
|
|
380
|
-
label: "Maximum Value"
|
|
381
|
-
};
|
|
382
|
-
fieldSettings.step = {
|
|
383
|
-
type: resolvedType,
|
|
384
|
-
label: "Step Size"
|
|
385
|
-
};
|
|
386
|
-
break;
|
|
387
|
-
case "radio":
|
|
388
|
-
case "select": {
|
|
389
|
-
const selectOptions = (currentFieldSettings == null ? void 0 : currentFieldSettings.options) || [];
|
|
390
|
-
if (!customDefaultValueField) {
|
|
391
|
-
fieldSettings.defaultValue = {
|
|
392
|
-
type: "custom",
|
|
393
|
-
label: "Default Value",
|
|
394
|
-
render: ({ value, onChange, id }) => /* @__PURE__ */ jsx(
|
|
395
|
-
AutoField,
|
|
396
|
-
{
|
|
397
|
-
field: {
|
|
398
|
-
type: resolvedType,
|
|
399
|
-
label: "Default Value",
|
|
400
|
-
options: selectOptions
|
|
401
|
-
},
|
|
402
|
-
value,
|
|
403
|
-
onChange,
|
|
404
|
-
readOnly: false,
|
|
405
|
-
id
|
|
406
|
-
}
|
|
407
|
-
)
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
fieldSettings.options = {
|
|
411
|
-
type: "array",
|
|
412
|
-
label: "Options",
|
|
413
|
-
defaultItemProps: {
|
|
414
|
-
label: "New Option",
|
|
415
|
-
value: "new"
|
|
416
|
-
},
|
|
417
|
-
arrayFields: {
|
|
418
|
-
label: { type: "text", label: "Label" },
|
|
419
|
-
value: {
|
|
420
|
-
type: "text",
|
|
421
|
-
label: "Value"
|
|
422
|
-
}
|
|
423
|
-
},
|
|
424
|
-
getItemSummary(item, index) {
|
|
425
|
-
return item.label || `Option ${(index || 0) + 1}`;
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
case "array":
|
|
431
|
-
case "object":
|
|
432
|
-
fieldSettings.subFields = {
|
|
433
|
-
type: "array",
|
|
434
|
-
label: "Sub Fields",
|
|
435
|
-
defaultItemProps: {
|
|
436
|
-
name: "New Sub Field",
|
|
437
|
-
type: "text"
|
|
438
|
-
},
|
|
439
|
-
arrayFields: {
|
|
440
|
-
name: { type: "text", label: "Name" },
|
|
441
|
-
type: {
|
|
442
|
-
type: "select",
|
|
443
|
-
options: deep ? [
|
|
444
|
-
{
|
|
445
|
-
label: "Text",
|
|
446
|
-
value: "text"
|
|
447
|
-
},
|
|
448
|
-
{
|
|
449
|
-
label: "Number",
|
|
450
|
-
value: "number"
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
label: "Select",
|
|
454
|
-
value: "select"
|
|
455
|
-
},
|
|
456
|
-
{
|
|
457
|
-
label: "Radio",
|
|
458
|
-
value: "radio"
|
|
459
|
-
},
|
|
460
|
-
...customTypeOptions
|
|
461
|
-
] : [
|
|
462
|
-
{
|
|
463
|
-
label: "Text",
|
|
464
|
-
value: "text"
|
|
465
|
-
},
|
|
466
|
-
{
|
|
467
|
-
label: "Number",
|
|
468
|
-
value: "number"
|
|
469
|
-
},
|
|
470
|
-
{
|
|
471
|
-
label: "Select",
|
|
472
|
-
value: "select"
|
|
473
|
-
},
|
|
474
|
-
{
|
|
475
|
-
label: "Radio",
|
|
476
|
-
value: "radio"
|
|
477
|
-
},
|
|
478
|
-
{
|
|
479
|
-
label: "Array",
|
|
480
|
-
value: "array"
|
|
481
|
-
},
|
|
482
|
-
{
|
|
483
|
-
label: "Object",
|
|
484
|
-
value: "object"
|
|
485
|
-
},
|
|
486
|
-
{
|
|
487
|
-
label: "Reference",
|
|
488
|
-
value: "reference"
|
|
489
|
-
},
|
|
490
|
-
...customTypeOptions
|
|
491
|
-
]
|
|
492
|
-
}
|
|
493
|
-
},
|
|
494
|
-
getItemSummary(item, index) {
|
|
495
|
-
return item.name || `Field ${(index || 0) + 1}`;
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
if (!deep)
|
|
499
|
-
fieldSettings.subFieldSettings = {
|
|
500
|
-
type: "object",
|
|
501
|
-
label: "Sub Field Settings",
|
|
502
|
-
objectFields: resolvedSubFields ? getFieldSettings(
|
|
503
|
-
resolvedSubFields,
|
|
504
|
-
resolvedSubFieldSettings,
|
|
505
|
-
customFields,
|
|
506
|
-
true
|
|
507
|
-
) : {}
|
|
508
|
-
};
|
|
509
|
-
if (resolvedType === "array") {
|
|
510
|
-
if (!customDefaultValueField) {
|
|
511
|
-
fieldSettings.defaultValue = {
|
|
512
|
-
type: "array",
|
|
513
|
-
label: "Default Items",
|
|
514
|
-
arrayFields: buildDefaultEditorFields(
|
|
515
|
-
resolvedSubFields,
|
|
516
|
-
resolvedSubFieldSettings,
|
|
517
|
-
customFields
|
|
518
|
-
),
|
|
519
|
-
defaultItemProps: buildArrayDefaultItemProps(
|
|
520
|
-
resolvedSubFields,
|
|
521
|
-
resolvedSubFieldSettings
|
|
522
|
-
),
|
|
523
|
-
getItemSummary(item, index) {
|
|
524
|
-
return getArrayItemSummary(item, index, currentFieldSettings);
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
fieldSettings.min = {
|
|
529
|
-
type: "number",
|
|
530
|
-
label: "Minimum Items"
|
|
531
|
-
};
|
|
532
|
-
fieldSettings.max = {
|
|
533
|
-
type: "number",
|
|
534
|
-
label: "Maximum Items"
|
|
535
|
-
};
|
|
536
|
-
fieldSettings.summary = {
|
|
537
|
-
type: "select",
|
|
538
|
-
label: "Summary",
|
|
539
|
-
options: [
|
|
540
|
-
{
|
|
541
|
-
label: "Default Numbering / Count",
|
|
542
|
-
value: "count"
|
|
543
|
-
},
|
|
544
|
-
{
|
|
545
|
-
label: "Field",
|
|
546
|
-
value: "field"
|
|
547
|
-
},
|
|
548
|
-
{
|
|
549
|
-
label: "Expression",
|
|
550
|
-
value: "expression"
|
|
551
|
-
}
|
|
552
|
-
]
|
|
553
|
-
};
|
|
554
|
-
if ((currentFieldSettings == null ? void 0 : currentFieldSettings.summary) === "field") {
|
|
555
|
-
fieldSettings.summaryField = {
|
|
556
|
-
type: "select",
|
|
557
|
-
label: "Summary Field",
|
|
558
|
-
options: [
|
|
559
|
-
{
|
|
560
|
-
label: "Select a field",
|
|
561
|
-
value: ""
|
|
562
|
-
},
|
|
563
|
-
...resolvedSubFields.filter((subField) => isPrimitiveFieldType(subField.type)).map((subField) => ({
|
|
564
|
-
label: subField.name,
|
|
565
|
-
value: subField.name
|
|
566
|
-
}))
|
|
567
|
-
]
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
if ((currentFieldSettings == null ? void 0 : currentFieldSettings.summary) === "expression") {
|
|
571
|
-
fieldSettings.summaryExpression = {
|
|
572
|
-
type: "text",
|
|
573
|
-
label: "Summary Expression"
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
break;
|
|
578
|
-
}
|
|
579
|
-
const overriddenFieldSettings = (customFieldDefinition == null ? void 0 : customFieldDefinition.fieldSettingsOverride) ? customFieldDefinition.fieldSettingsOverride({
|
|
580
|
-
fieldName: field.name,
|
|
581
|
-
fieldType: field.type,
|
|
582
|
-
fieldSettings: currentFieldSettings,
|
|
583
|
-
originalFieldSettings: fieldSettings
|
|
584
|
-
}) : fieldSettings;
|
|
585
|
-
fields[field.name] = {
|
|
586
|
-
type: "object",
|
|
587
|
-
label: field.name,
|
|
588
|
-
objectFields: overriddenFieldSettings
|
|
589
|
-
};
|
|
590
|
-
return fields;
|
|
591
|
-
}, {});
|
|
592
|
-
};
|
|
593
|
-
var get_field_settings_default = getFieldSettings;
|
|
594
|
-
|
|
595
|
-
// src/puck/context/useStore.ts
|
|
596
|
-
import { createContext, useContext } from "react";
|
|
597
|
-
import { useStore } from "zustand";
|
|
598
|
-
var appStoreContext = createContext(null);
|
|
599
|
-
var createUseSoftConfig = () => {
|
|
600
|
-
return function useSoftConfig2(selector, equalityFn) {
|
|
601
|
-
const context = useContext(appStoreContext);
|
|
602
|
-
if (!context) {
|
|
603
|
-
throw new Error(
|
|
604
|
-
"useSoftConfig must be used inside a SoftConfigProvider. Wrap your tree with <SoftConfigProvider value={store}>"
|
|
605
|
-
);
|
|
606
|
-
}
|
|
607
|
-
if (equalityFn) {
|
|
608
|
-
return useStore(context, selector, equalityFn);
|
|
609
|
-
}
|
|
610
|
-
return useStore(context, selector);
|
|
611
|
-
};
|
|
612
|
-
};
|
|
613
|
-
var useSoftConfig = createUseSoftConfig();
|
|
614
|
-
var useSoftConfigStore = () => {
|
|
615
|
-
const context = useContext(appStoreContext);
|
|
616
|
-
if (!context) {
|
|
617
|
-
throw new Error(
|
|
618
|
-
"useSoftConfigStore must be used inside a SoftConfigProvider."
|
|
619
|
-
);
|
|
620
|
-
}
|
|
621
|
-
return context;
|
|
622
|
-
};
|
|
623
|
-
|
|
624
173
|
// src/puck/lib/apply-mapping.ts
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
let cur = props;
|
|
632
|
-
for (const p of parts) {
|
|
633
|
-
if (typeof cur[p] !== "object" || cur[p] === null) cur[p] = {};
|
|
634
|
-
cur = cur[p];
|
|
174
|
+
var pathSegmentsCache = /* @__PURE__ */ new Map();
|
|
175
|
+
var getPathSegments = (path) => {
|
|
176
|
+
let segments = pathSegmentsCache.get(path);
|
|
177
|
+
if (!segments) {
|
|
178
|
+
segments = path.split(".");
|
|
179
|
+
pathSegmentsCache.set(path, segments);
|
|
635
180
|
}
|
|
636
|
-
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
// src/puck/lib/apply-mapping.ts
|
|
181
|
+
return segments;
|
|
182
|
+
};
|
|
640
183
|
var resolveValueByPath = (source, path) => {
|
|
641
184
|
if (!path) return source;
|
|
642
|
-
const segments = path
|
|
185
|
+
const segments = getPathSegments(path);
|
|
643
186
|
const resolveSegments = (current, index) => {
|
|
644
187
|
if (current === null || current === void 0) return void 0;
|
|
645
188
|
if (index >= segments.length) return current;
|
|
@@ -658,7 +201,7 @@ var resolveValueByPath = (source, path) => {
|
|
|
658
201
|
};
|
|
659
202
|
var resolveFieldSettingEntryByPath = (settings, path) => {
|
|
660
203
|
if (!path) return void 0;
|
|
661
|
-
const segments = path
|
|
204
|
+
const segments = getPathSegments(path);
|
|
662
205
|
let currentSettings = settings;
|
|
663
206
|
let currentEntry;
|
|
664
207
|
for (const segmentWithArraySuffix of segments) {
|
|
@@ -676,11 +219,11 @@ var resolveFieldSettingEntryByPath = (settings, path) => {
|
|
|
676
219
|
};
|
|
677
220
|
function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings", options) {
|
|
678
221
|
var _a, _b, _c;
|
|
679
|
-
|
|
222
|
+
let newProps = props;
|
|
680
223
|
const sourceProps = (_a = options == null ? void 0 : options.sourceProps) != null ? _a : props;
|
|
681
224
|
const mappedArrayPaths = /* @__PURE__ */ new Set();
|
|
682
225
|
let changed = false;
|
|
683
|
-
const
|
|
226
|
+
const arrayRulesMap = /* @__PURE__ */ new Map();
|
|
684
227
|
for (const entry of map) {
|
|
685
228
|
const { from, to, transform } = entry;
|
|
686
229
|
if (!from || !to) continue;
|
|
@@ -719,43 +262,21 @@ function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings",
|
|
|
719
262
|
if (isSingleArrayTarget) {
|
|
720
263
|
const toPath = toPaths[0];
|
|
721
264
|
const arrayBase = getArrayBasePath(toPath);
|
|
722
|
-
const subProp = getArrayItemSubPath(toPath) || "";
|
|
723
265
|
if (!arrayBase) continue;
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
const sourceArray = isFromArrayPath ? Array.isArray(result) ? result : result !== void 0 ? [result] : [] : Array.isArray(result) ? result : defaultArray.map(() => result);
|
|
729
|
-
let defaults = entry.unmappedArrayItemDefaultValues || entry.defaultOverrides || {};
|
|
730
|
-
if (typeof defaults === "string") {
|
|
731
|
-
try {
|
|
732
|
-
defaults = JSON.parse(defaults);
|
|
733
|
-
} catch (e) {
|
|
734
|
-
defaults = {};
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
const targetLength = sourceArray.length;
|
|
738
|
-
const constructed = Array.from({ length: targetLength }).map((_, idx) => {
|
|
739
|
-
const mappedValue = sourceArray[idx];
|
|
740
|
-
const defaultItem = defaultArray[idx] && typeof defaultArray[idx] === "object" ? defaultArray[idx] : {};
|
|
741
|
-
const currentItem = currentArray[idx] && typeof currentArray[idx] === "object" ? currentArray[idx] : {};
|
|
742
|
-
const item = __spreadValues(__spreadValues(__spreadValues({}, defaultItem), defaults), currentItem);
|
|
743
|
-
if (subProp && mappedValue !== void 0) {
|
|
744
|
-
setPropertyByPath(item, subProp, mappedValue);
|
|
745
|
-
}
|
|
746
|
-
return item;
|
|
747
|
-
});
|
|
748
|
-
const originalArray = resolveValueByPath(newProps, arrayBase);
|
|
749
|
-
if (!equal(originalArray, constructed)) {
|
|
750
|
-
setPropertyByPath(newProps, arrayBase, constructed);
|
|
751
|
-
changedArrayBases.add(arrayBase);
|
|
266
|
+
let rules = arrayRulesMap.get(arrayBase);
|
|
267
|
+
if (!rules) {
|
|
268
|
+
rules = [];
|
|
269
|
+
arrayRulesMap.set(arrayBase, rules);
|
|
752
270
|
}
|
|
271
|
+
rules.push({ entry, toPath, fromPaths, result });
|
|
753
272
|
mappedArrayPaths.add(arrayBase);
|
|
754
|
-
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (toPaths.length === 1 && Array.isArray(result) && toPaths[0].includes("array")) {
|
|
755
276
|
const toPath = toPaths[0];
|
|
756
277
|
const original = resolveValueByPath(newProps, toPath);
|
|
757
278
|
if (!equal(original, result)) {
|
|
758
|
-
|
|
279
|
+
newProps = setImmutablePropertyByPath(newProps, toPath, result);
|
|
759
280
|
changed = true;
|
|
760
281
|
}
|
|
761
282
|
} else if (Array.isArray(result) && toPaths.length > 1) {
|
|
@@ -763,7 +284,7 @@ function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings",
|
|
|
763
284
|
if (toPaths[idx]) {
|
|
764
285
|
const orig = resolveValueByPath(newProps, toPaths[idx]);
|
|
765
286
|
if (!equal(orig, val)) {
|
|
766
|
-
|
|
287
|
+
newProps = setImmutablePropertyByPath(newProps, toPaths[idx], val);
|
|
767
288
|
changed = true;
|
|
768
289
|
}
|
|
769
290
|
}
|
|
@@ -772,565 +293,233 @@ function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings",
|
|
|
772
293
|
const finalValue = result;
|
|
773
294
|
const originalValue = resolveValueByPath(newProps, toPaths[0]);
|
|
774
295
|
if (!equal(originalValue, finalValue)) {
|
|
775
|
-
|
|
296
|
+
newProps = setImmutablePropertyByPath(newProps, toPaths[0], finalValue);
|
|
776
297
|
changed = true;
|
|
777
298
|
}
|
|
778
299
|
}
|
|
779
300
|
}
|
|
780
|
-
const
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
};
|
|
802
|
-
var builderRootConfig = (config, overrides, editingComponent, showVersionFields = true, customFields) => {
|
|
803
|
-
const customTypeOptions = getCustomFieldTypeOptions(customFields);
|
|
804
|
-
return {
|
|
805
|
-
fields: __spreadValues({
|
|
806
|
-
_name: overrides.name || {
|
|
807
|
-
type: "text",
|
|
808
|
-
label: "Soft Component Name"
|
|
809
|
-
},
|
|
810
|
-
_category: overrides.categories || {
|
|
811
|
-
type: "select",
|
|
812
|
-
label: "Category",
|
|
813
|
-
options: [
|
|
814
|
-
...Object.keys(config.categories || {}).map((cat) => {
|
|
815
|
-
var _a;
|
|
816
|
-
return {
|
|
817
|
-
label: ((_a = config.categories) == null ? void 0 : _a[cat].title) || cat,
|
|
818
|
-
value: cat
|
|
819
|
-
};
|
|
820
|
-
}) || [],
|
|
821
|
-
{
|
|
822
|
-
label: Object.keys(config.categories || {}).length ? "Other" : "Uncategorized",
|
|
823
|
-
value: void 0
|
|
301
|
+
for (const [arrayBase, rules] of arrayRulesMap.entries()) {
|
|
302
|
+
const defaultArray = Array.isArray((_b = options == null ? void 0 : options.arrayDefaults) == null ? void 0 : _b[arrayBase]) ? (_c = options == null ? void 0 : options.arrayDefaults) == null ? void 0 : _c[arrayBase] : [];
|
|
303
|
+
const currentArrayAtPath = resolveValueByPath(newProps, arrayBase);
|
|
304
|
+
const currentArray = Array.isArray(currentArrayAtPath) ? currentArrayAtPath : [];
|
|
305
|
+
let targetLength = 0;
|
|
306
|
+
const ruleSourceArrays = rules.map(({ entry, fromPaths, result }) => {
|
|
307
|
+
const isFromArrayPath = typeof fromPaths[0] === "string" && isArrayMappingPath(fromPaths[0]);
|
|
308
|
+
const sourceArray = isFromArrayPath ? Array.isArray(result) ? result : result !== void 0 ? [result] : [] : Array.isArray(result) ? result : defaultArray.map(() => result);
|
|
309
|
+
targetLength = Math.max(targetLength, sourceArray.length);
|
|
310
|
+
return sourceArray;
|
|
311
|
+
});
|
|
312
|
+
const constructed = Array.from({ length: targetLength }).map((_, idx) => {
|
|
313
|
+
const defaultItem = defaultArray[idx] && typeof defaultArray[idx] === "object" ? defaultArray[idx] : {};
|
|
314
|
+
const currentItem = currentArray[idx] && typeof currentArray[idx] === "object" ? currentArray[idx] : {};
|
|
315
|
+
let mergedDefaults = {};
|
|
316
|
+
for (const rule of rules) {
|
|
317
|
+
let ruleDefaults = rule.entry.unmappedArrayItemDefaultValues || rule.entry.defaultOverrides || {};
|
|
318
|
+
if (typeof ruleDefaults === "string") {
|
|
319
|
+
try {
|
|
320
|
+
ruleDefaults = JSON.parse(ruleDefaults);
|
|
321
|
+
} catch (e) {
|
|
824
322
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
return item.name || `Field ${(index || 0) + 1}`;
|
|
836
|
-
},
|
|
837
|
-
arrayFields: {
|
|
838
|
-
name: { type: "text", label: "Name" },
|
|
839
|
-
type: {
|
|
840
|
-
type: "select",
|
|
841
|
-
label: "Type",
|
|
842
|
-
options: [
|
|
843
|
-
{ label: "Text", value: "text" },
|
|
844
|
-
{ label: "Textarea", value: "textarea" },
|
|
845
|
-
{ label: "Number", value: "number" },
|
|
846
|
-
{ label: "Select", value: "select" },
|
|
847
|
-
{ label: "Radio", value: "radio" },
|
|
848
|
-
{ label: "Array", value: "array" },
|
|
849
|
-
{ label: "Object", value: "object" },
|
|
850
|
-
// { label: "Reference", value: "reference" },
|
|
851
|
-
...customTypeOptions
|
|
852
|
-
]
|
|
323
|
+
}
|
|
324
|
+
mergedDefaults = __spreadValues(__spreadValues({}, mergedDefaults), ruleDefaults);
|
|
325
|
+
}
|
|
326
|
+
const baseItem = __spreadValues(__spreadValues({}, defaultItem), mergedDefaults);
|
|
327
|
+
let newItem = void 0;
|
|
328
|
+
for (const key of Object.keys(baseItem)) {
|
|
329
|
+
if (!(key in currentItem) && baseItem[key] !== void 0) {
|
|
330
|
+
if (!newItem) newItem = __spreadValues({}, currentItem);
|
|
331
|
+
if (newItem) {
|
|
332
|
+
newItem[key] = baseItem[key];
|
|
853
333
|
}
|
|
854
334
|
}
|
|
855
335
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
newFields._fieldSettings = {
|
|
866
|
-
type: "object",
|
|
867
|
-
label: "Field Settings",
|
|
868
|
-
objectFields: get_field_settings_default(
|
|
869
|
-
rootFields,
|
|
870
|
-
rootFieldSettings,
|
|
871
|
-
customFields
|
|
872
|
-
)
|
|
873
|
-
};
|
|
874
|
-
} else {
|
|
875
|
-
delete newFields._fieldSettings;
|
|
336
|
+
for (let i = 0; i < rules.length; i++) {
|
|
337
|
+
const { toPath } = rules[i];
|
|
338
|
+
const subProp = getArrayItemSubPath(toPath) || "";
|
|
339
|
+
const mappedValue = ruleSourceArrays[i][idx];
|
|
340
|
+
if (subProp && mappedValue !== void 0) {
|
|
341
|
+
const existingValue = resolveValueByPath(newItem || currentItem, subProp);
|
|
342
|
+
if (!equal(existingValue, mappedValue)) {
|
|
343
|
+
newItem = setImmutablePropertyByPath(newItem || currentItem, subProp, mappedValue);
|
|
344
|
+
}
|
|
876
345
|
}
|
|
877
346
|
}
|
|
878
|
-
return
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
// readOnly: Readonly<Record<string, boolean>> | undefined;
|
|
887
|
-
// } = {
|
|
888
|
-
// props,
|
|
889
|
-
// readOnly: undefined,
|
|
890
|
-
// };
|
|
891
|
-
// return result;
|
|
892
|
-
// },
|
|
893
|
-
render: (props) => {
|
|
894
|
-
const fieldSettings = props == null ? void 0 : props._fieldSettings;
|
|
895
|
-
const data = useCustomPuck((s) => s.appState.data);
|
|
896
|
-
const dispatch = useCustomPuck((s) => s.dispatch);
|
|
897
|
-
const getSelectorForId = useCustomPuck((s) => s.getSelectorForId);
|
|
898
|
-
const setVersion = useSoftConfig((s) => s.builder.setVersion);
|
|
899
|
-
const state = useSoftConfig((s) => s.state);
|
|
900
|
-
useEffect(() => {
|
|
901
|
-
if (!fieldSettings || Object.keys(fieldSettings).length === 0) return;
|
|
902
|
-
const replacements = [];
|
|
903
|
-
walkTree(
|
|
904
|
-
{
|
|
905
|
-
content: (data == null ? void 0 : data.content) || [],
|
|
906
|
-
root: (data == null ? void 0 : data.root) || {}
|
|
907
|
-
},
|
|
908
|
-
{
|
|
909
|
-
components: config.components
|
|
910
|
-
},
|
|
911
|
-
(content) => content.map((child) => {
|
|
912
|
-
var _a;
|
|
913
|
-
const map = ((_a = child.props) == null ? void 0 : _a._map) || [];
|
|
914
|
-
if (!map.length) return child;
|
|
915
|
-
const cleanProps = getSerializableProps(child.props);
|
|
916
|
-
const { newProps, changed } = applyMapping(
|
|
917
|
-
cleanProps,
|
|
918
|
-
fieldSettings,
|
|
919
|
-
map,
|
|
920
|
-
"fieldSettings"
|
|
921
|
-
);
|
|
922
|
-
if (!changed || equal2(cleanProps, newProps)) return child;
|
|
923
|
-
replacements.push({
|
|
924
|
-
id: child.props.id,
|
|
925
|
-
data: __spreadProps(__spreadValues({}, child), { props: newProps })
|
|
926
|
-
});
|
|
927
|
-
return child;
|
|
928
|
-
})
|
|
929
|
-
);
|
|
930
|
-
if (!replacements.length) return;
|
|
931
|
-
replacements.forEach((replacement) => {
|
|
932
|
-
const itemSelector = getSelectorForId(replacement.id);
|
|
933
|
-
if (!itemSelector) return;
|
|
934
|
-
dispatch({
|
|
935
|
-
type: "replace",
|
|
936
|
-
data: replacement.data,
|
|
937
|
-
destinationIndex: itemSelector.index,
|
|
938
|
-
destinationZone: itemSelector.zone
|
|
939
|
-
});
|
|
940
|
-
});
|
|
941
|
-
}, [fieldSettings, data, dispatch, getSelectorForId]);
|
|
942
|
-
useEffect(() => {
|
|
943
|
-
var _a;
|
|
944
|
-
if (state !== "remodeling" || !(props == null ? void 0 : props._version) || !(props == null ? void 0 : props._name)) return;
|
|
945
|
-
const currentVersion = props._version;
|
|
946
|
-
if (((_a = props._versions) == null ? void 0 : _a.includes(currentVersion)) && props._versions.length > 1) {
|
|
947
|
-
setVersion(props._name, currentVersion, props, dispatch);
|
|
347
|
+
return newItem !== void 0 ? newItem : currentItem;
|
|
348
|
+
});
|
|
349
|
+
let arrayChanged = currentArray.length !== constructed.length;
|
|
350
|
+
if (!arrayChanged) {
|
|
351
|
+
for (let i = 0; i < currentArray.length; i++) {
|
|
352
|
+
if (currentArray[i] !== constructed[i]) {
|
|
353
|
+
arrayChanged = true;
|
|
354
|
+
break;
|
|
948
355
|
}
|
|
949
|
-
}
|
|
950
|
-
return /* @__PURE__ */ jsx2(Fragment, { children: props.children });
|
|
951
|
-
}
|
|
952
|
-
};
|
|
953
|
-
};
|
|
954
|
-
|
|
955
|
-
// src/puck/lib/builder/generate-field-options.ts
|
|
956
|
-
var hasArrayMappingPath = (value) => value.includes("[]");
|
|
957
|
-
var isBareArrayPath = (value) => !hasArrayMappingPath(value) && !value.includes(".");
|
|
958
|
-
function filterToOptionsForFrom(fromPath, toOptions) {
|
|
959
|
-
if (!fromPath) return toOptions;
|
|
960
|
-
const fromHasArrayMapping = hasArrayMappingPath(fromPath);
|
|
961
|
-
const fromIsBareArray = isBareArrayPath(fromPath);
|
|
962
|
-
return toOptions.filter((option) => {
|
|
963
|
-
const optionHasArrayMapping = hasArrayMappingPath(option.value);
|
|
964
|
-
if (fromHasArrayMapping) {
|
|
965
|
-
return optionHasArrayMapping;
|
|
356
|
+
}
|
|
966
357
|
}
|
|
967
|
-
if (
|
|
968
|
-
|
|
358
|
+
if (arrayChanged) {
|
|
359
|
+
newProps = setImmutablePropertyByPath(newProps, arrayBase, constructed);
|
|
360
|
+
changed = true;
|
|
969
361
|
}
|
|
970
|
-
return !optionHasArrayMapping;
|
|
971
|
-
});
|
|
972
|
-
}
|
|
973
|
-
function generateFieldOptions(fields, prefix = "") {
|
|
974
|
-
const opts = [];
|
|
975
|
-
function recurse(current, prefix2) {
|
|
976
|
-
Object.entries(current).forEach(([key, fld]) => {
|
|
977
|
-
if (fld.type === "slot") return;
|
|
978
|
-
if (key === "_map") return;
|
|
979
|
-
if (key === "_slotEnabled") return;
|
|
980
|
-
const path = prefix2 ? `${prefix2}.${key}` : key;
|
|
981
|
-
if (fld.type === "object" && fld.objectFields) {
|
|
982
|
-
recurse(fld.objectFields, path);
|
|
983
|
-
} else if (fld.type === "array" && fld.arrayFields) {
|
|
984
|
-
recurse(
|
|
985
|
-
fld.arrayFields,
|
|
986
|
-
path + "[]"
|
|
987
|
-
);
|
|
988
|
-
} else {
|
|
989
|
-
opts.push({ label: path, value: path, type: fld.type });
|
|
990
|
-
}
|
|
991
|
-
});
|
|
992
362
|
}
|
|
993
|
-
|
|
994
|
-
return opts;
|
|
363
|
+
return { newProps, mappedArrayPaths, changed };
|
|
995
364
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
)
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
customSchema.subFields,
|
|
1016
|
-
customSchema.subFieldSettings,
|
|
1017
|
-
path + (customReturnType === "array" ? "[]" : "")
|
|
1018
|
-
);
|
|
1019
|
-
return;
|
|
1020
|
-
}
|
|
1021
|
-
opts.push({
|
|
1022
|
-
label: path,
|
|
1023
|
-
value: path,
|
|
1024
|
-
type: mapCustomReturnTypeToMappingType(customReturnType)
|
|
1025
|
-
});
|
|
1026
|
-
return;
|
|
1027
|
-
}
|
|
1028
|
-
if (!isBuiltInSoftFieldType(field.type)) {
|
|
1029
|
-
return;
|
|
1030
|
-
}
|
|
1031
|
-
if ((_a = settings == null ? void 0 : settings.subFields) == null ? void 0 : _a.length) {
|
|
1032
|
-
recurse(
|
|
1033
|
-
settings.subFields,
|
|
1034
|
-
settings.subFieldSettings || {},
|
|
1035
|
-
path + (field.type === "array" ? "[]" : "")
|
|
1036
|
-
);
|
|
1037
|
-
} else if (field.type !== "array" && field.type !== "object") {
|
|
1038
|
-
opts.push({ label: path, value: path, type: field.type });
|
|
365
|
+
|
|
366
|
+
// src/puck/lib/root-action-handler.ts
|
|
367
|
+
var currentGeneration = 0;
|
|
368
|
+
function hasDefaultValueChanged(prev, curr) {
|
|
369
|
+
var _a, _b;
|
|
370
|
+
if (!prev && !curr) return false;
|
|
371
|
+
if (!prev || !curr) return true;
|
|
372
|
+
if (!isEqual(prev == null ? void 0 : prev.defaultValue, curr == null ? void 0 : curr.defaultValue)) return true;
|
|
373
|
+
if ((prev == null ? void 0 : prev.subFieldSettings) || (curr == null ? void 0 : curr.subFieldSettings)) {
|
|
374
|
+
const subKeys = /* @__PURE__ */ new Set([
|
|
375
|
+
...Object.keys((prev == null ? void 0 : prev.subFieldSettings) || {}),
|
|
376
|
+
...Object.keys((curr == null ? void 0 : curr.subFieldSettings) || {})
|
|
377
|
+
]);
|
|
378
|
+
for (const subKey of subKeys) {
|
|
379
|
+
if (hasDefaultValueChanged(
|
|
380
|
+
(_a = prev == null ? void 0 : prev.subFieldSettings) == null ? void 0 : _a[subKey],
|
|
381
|
+
(_b = curr == null ? void 0 : curr.subFieldSettings) == null ? void 0 : _b[subKey]
|
|
382
|
+
)) {
|
|
383
|
+
return true;
|
|
1039
384
|
}
|
|
1040
|
-
}
|
|
385
|
+
}
|
|
1041
386
|
}
|
|
1042
|
-
|
|
1043
|
-
return opts;
|
|
387
|
+
return false;
|
|
1044
388
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
if (
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
389
|
+
var processReplacements = (appState, get, fieldSettings, changedKeys, zones, nodes) => __async(null, null, function* () {
|
|
390
|
+
var _a, _b;
|
|
391
|
+
const generation = ++currentGeneration;
|
|
392
|
+
yield new Promise((resolve) => setTimeout(resolve, 150));
|
|
393
|
+
if (generation !== currentGeneration) return;
|
|
394
|
+
const { puckDispatch, editableComponentIds } = get();
|
|
395
|
+
if (!puckDispatch) return;
|
|
396
|
+
if (changedKeys.size === 0) return;
|
|
397
|
+
const replacements = [];
|
|
398
|
+
const editableSet = new Set(editableComponentIds || []);
|
|
399
|
+
const hasEditableFilter = editableSet.size > 0;
|
|
400
|
+
const nodeEntries = Object.entries(nodes);
|
|
401
|
+
for (let i = 0; i < nodeEntries.length; i++) {
|
|
402
|
+
if (generation !== currentGeneration) return;
|
|
403
|
+
if (i > 0 && i % 50 === 0) {
|
|
404
|
+
yield new Promise((resolve) => setTimeout(resolve, 0));
|
|
405
|
+
if (generation !== currentGeneration) return;
|
|
1057
406
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
const prefixedModifiers = {};
|
|
1062
|
-
for (let modifier in modifiers) {
|
|
1063
|
-
prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
|
|
407
|
+
const [id, node] = nodeEntries[i];
|
|
408
|
+
if (hasEditableFilter && !editableSet.has(id)) {
|
|
409
|
+
continue;
|
|
1064
410
|
}
|
|
1065
|
-
const
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
})
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
error: null
|
|
1093
|
-
};
|
|
411
|
+
const map = ((_a = node.data.props) == null ? void 0 : _a._map) || [];
|
|
412
|
+
if (!map.length) continue;
|
|
413
|
+
let isAffected = false;
|
|
414
|
+
const flatProps = ((_b = node.flatData) == null ? void 0 : _b.props) || {};
|
|
415
|
+
for (const [flatKey, flatValue] of Object.entries(flatProps)) {
|
|
416
|
+
if (flatKey.includes("_map") && flatKey.includes("from") && typeof flatValue === "string") {
|
|
417
|
+
if (changedKeys.has(flatValue) || Array.from(changedKeys).some(
|
|
418
|
+
(ck) => flatValue.startsWith(ck + ".") || flatValue.startsWith(ck + "[")
|
|
419
|
+
)) {
|
|
420
|
+
isAffected = true;
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (!isAffected) continue;
|
|
426
|
+
const { newProps } = applyMapping(
|
|
427
|
+
__spreadValues({}, node.data.props),
|
|
428
|
+
fieldSettings,
|
|
429
|
+
map,
|
|
430
|
+
"fieldSettings"
|
|
431
|
+
);
|
|
432
|
+
replacements.push({
|
|
433
|
+
id,
|
|
434
|
+
data: __spreadProps(__spreadValues({}, node.data), {
|
|
435
|
+
props: __spreadValues(__spreadValues({}, node.data.props), newProps)
|
|
436
|
+
})
|
|
437
|
+
});
|
|
1094
438
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
439
|
+
if (!replacements.length) return;
|
|
440
|
+
requestAnimationFrame(() => {
|
|
441
|
+
replacements.forEach((replacement) => {
|
|
442
|
+
var _a2;
|
|
443
|
+
const node = nodes[replacement.id];
|
|
444
|
+
if (!node) return;
|
|
445
|
+
const zoneName = `${node.parentId}:${node.zone}`;
|
|
446
|
+
const index = (_a2 = zones[zoneName]) == null ? void 0 : _a2.contentIds.indexOf(replacement.id);
|
|
447
|
+
if (index !== void 0 && index !== -1) {
|
|
448
|
+
puckDispatch({
|
|
449
|
+
type: "replace",
|
|
450
|
+
destinationIndex: index,
|
|
451
|
+
destinationZone: zoneName,
|
|
452
|
+
data: replacement.data,
|
|
453
|
+
ui: void 0
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
var processVersionChange = (rootProps, get, zones, nodes) => {
|
|
460
|
+
const currentVersion = rootProps._version;
|
|
461
|
+
const versions = rootProps._versions || [];
|
|
462
|
+
if (versions.includes(currentVersion) && versions.length > 1) {
|
|
463
|
+
const puckDispatch = get().puckDispatch;
|
|
464
|
+
if (puckDispatch) {
|
|
465
|
+
get().builder.setVersion(
|
|
466
|
+
rootProps._name,
|
|
467
|
+
currentVersion,
|
|
468
|
+
rootProps,
|
|
469
|
+
puckDispatch,
|
|
470
|
+
// Mock getItemBySelector using indexes
|
|
471
|
+
(selector) => {
|
|
472
|
+
var _a;
|
|
473
|
+
if (!selector.zone) return void 0;
|
|
474
|
+
const id = (_a = zones[selector.zone]) == null ? void 0 : _a.contentIds[selector.index];
|
|
475
|
+
return id ? nodes[id].data : void 0;
|
|
476
|
+
},
|
|
477
|
+
// Mock getSelectorForId using indexes
|
|
478
|
+
(id) => {
|
|
479
|
+
var _a;
|
|
480
|
+
const node = nodes[id];
|
|
481
|
+
if (!node) return void 0;
|
|
482
|
+
const index = (_a = zones[node.zone]) == null ? void 0 : _a.contentIds.indexOf(id);
|
|
483
|
+
return { zone: node.zone, index };
|
|
484
|
+
}
|
|
485
|
+
);
|
|
486
|
+
}
|
|
1100
487
|
}
|
|
1101
|
-
|
|
1102
|
-
|
|
488
|
+
};
|
|
489
|
+
var rootActionHandler = (set, get) => (action, appState, previousState) => {
|
|
490
|
+
const storeState = get().state;
|
|
491
|
+
if (storeState !== "building" && storeState !== "remodeling" || action.type !== "replaceRoot") {
|
|
492
|
+
return;
|
|
1103
493
|
}
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
494
|
+
const { zones, nodes } = appState.indexes;
|
|
495
|
+
const rootProps = appState.data.root.props;
|
|
496
|
+
const previousRootProps = (previousState == null ? void 0 : previousState.data.root).props;
|
|
497
|
+
const fieldSettings = rootProps == null ? void 0 : rootProps._fieldSettings;
|
|
498
|
+
const previousFieldSettings = previousRootProps == null ? void 0 : previousRootProps._fieldSettings;
|
|
499
|
+
if (fieldSettings) {
|
|
500
|
+
const changedKeys = /* @__PURE__ */ new Set();
|
|
501
|
+
const allKeys = /* @__PURE__ */ new Set([
|
|
502
|
+
...Object.keys(previousFieldSettings || {}),
|
|
503
|
+
...Object.keys(fieldSettings || {})
|
|
504
|
+
]);
|
|
505
|
+
for (const key of allKeys) {
|
|
506
|
+
if (hasDefaultValueChanged(previousFieldSettings == null ? void 0 : previousFieldSettings[key], fieldSettings == null ? void 0 : fieldSettings[key])) {
|
|
507
|
+
changedKeys.add(key);
|
|
1111
508
|
}
|
|
1112
|
-
return /* @__PURE__ */ jsxs("div", { className: getClassName(), children: [
|
|
1113
|
-
/* @__PURE__ */ jsx3("h3", { className: getClassName("title"), children: "Component Error" }),
|
|
1114
|
-
/* @__PURE__ */ jsxs("details", { className: getClassName("details"), children: [
|
|
1115
|
-
/* @__PURE__ */ jsx3("summary", { children: "Show error details" }),
|
|
1116
|
-
this.state.error && this.state.error.toString()
|
|
1117
|
-
] }),
|
|
1118
|
-
/* @__PURE__ */ jsx3(
|
|
1119
|
-
"button",
|
|
1120
|
-
{
|
|
1121
|
-
onClick: this.resetError,
|
|
1122
|
-
className: getClassName("button"),
|
|
1123
|
-
children: "Try Again"
|
|
1124
|
-
}
|
|
1125
|
-
)
|
|
1126
|
-
] });
|
|
1127
509
|
}
|
|
1128
|
-
|
|
510
|
+
if (changedKeys.size > 0) {
|
|
511
|
+
processReplacements(appState, get, fieldSettings, changedKeys, zones, nodes);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (storeState === "remodeling" && (rootProps == null ? void 0 : rootProps._version) && (rootProps == null ? void 0 : rootProps._name) && (rootProps == null ? void 0 : rootProps._version) !== (previousRootProps == null ? void 0 : previousRootProps._version)) {
|
|
515
|
+
processVersionChange(rootProps, get, zones, nodes);
|
|
1129
516
|
}
|
|
1130
517
|
};
|
|
1131
518
|
|
|
1132
|
-
// src/puck/
|
|
1133
|
-
import {
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
config,
|
|
1137
|
-
overrides,
|
|
1138
|
-
editingComponent,
|
|
1139
|
-
showVersionFields,
|
|
1140
|
-
customFields
|
|
1141
|
-
),
|
|
1142
|
-
components: Object.entries(__spreadValues({}, config.components)).reduce(
|
|
1143
|
-
(acc, [name, component]) => {
|
|
1144
|
-
const tempComponent = __spreadProps(__spreadValues({}, component), {
|
|
1145
|
-
permissions: {
|
|
1146
|
-
insert: editingComponent !== name && !(dependents == null ? void 0 : dependents.has(name))
|
|
1147
|
-
},
|
|
1148
|
-
resolveFields(data, params) {
|
|
1149
|
-
return __async(this, null, function* () {
|
|
1150
|
-
var _a2;
|
|
1151
|
-
let fields = {};
|
|
1152
|
-
if (!fields._slot) {
|
|
1153
|
-
const slotFields = Object.entries(params.fields).filter(
|
|
1154
|
-
([_, field]) => field.type === "slot"
|
|
1155
|
-
);
|
|
1156
|
-
if (slotFields.length)
|
|
1157
|
-
fields._slot = {
|
|
1158
|
-
type: "array",
|
|
1159
|
-
label: "Enable Dropdown Slots",
|
|
1160
|
-
getItemSummary(item, index) {
|
|
1161
|
-
return item.slot || `Slot ${(index || 0) + 1}`;
|
|
1162
|
-
},
|
|
1163
|
-
arrayFields: {
|
|
1164
|
-
slot: {
|
|
1165
|
-
type: "select",
|
|
1166
|
-
label: "Slot",
|
|
1167
|
-
options: [
|
|
1168
|
-
{ label: "Select a slot", value: "" },
|
|
1169
|
-
...slotFields.filter(
|
|
1170
|
-
([fieldName, field]) => {
|
|
1171
|
-
var _a3;
|
|
1172
|
-
return field.type === "slot" && !(((_a3 = data.props) == null ? void 0 : _a3._slot) || []).some(
|
|
1173
|
-
(s) => s.slot === fieldName
|
|
1174
|
-
);
|
|
1175
|
-
}
|
|
1176
|
-
).map(([fieldName, field]) => ({
|
|
1177
|
-
label: field.label || fieldName,
|
|
1178
|
-
value: fieldName
|
|
1179
|
-
}))
|
|
1180
|
-
]
|
|
1181
|
-
},
|
|
1182
|
-
name: {
|
|
1183
|
-
type: "text",
|
|
1184
|
-
label: "Name",
|
|
1185
|
-
placeholder: "Optional Slot Name"
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
};
|
|
1189
|
-
}
|
|
1190
|
-
const defaultFields = component.resolveFields ? yield component.resolveFields(data, params) : component.fields || {};
|
|
1191
|
-
if (!fields._map || params.changed._map) {
|
|
1192
|
-
const rootProps = getRootProps(params.appState);
|
|
1193
|
-
const fromOptions = generateDynamicFieldOptions(
|
|
1194
|
-
(rootProps == null ? void 0 : rootProps._fields) || [],
|
|
1195
|
-
(rootProps == null ? void 0 : rootProps._fieldSettings) || {},
|
|
1196
|
-
customFields
|
|
1197
|
-
);
|
|
1198
|
-
const toOptionsFields = component.resolveFields && ((_a2 = data.props) == null ? void 0 : _a2._map) ? yield component.resolveFields(
|
|
1199
|
-
__spreadProps(__spreadValues({}, data), { props: __spreadProps(__spreadValues({}, data.props), { _map: void 0 }) }),
|
|
1200
|
-
params
|
|
1201
|
-
) : defaultFields;
|
|
1202
|
-
const toOptions = generateFieldOptions(toOptionsFields);
|
|
1203
|
-
fields._map = overrides.map ? {
|
|
1204
|
-
type: "custom",
|
|
1205
|
-
render: ({ value, onChange, id }) => {
|
|
1206
|
-
const rootProps2 = getRootProps(params.appState);
|
|
1207
|
-
return overrides.map({
|
|
1208
|
-
rootProps: rootProps2,
|
|
1209
|
-
value,
|
|
1210
|
-
onChange,
|
|
1211
|
-
id,
|
|
1212
|
-
props: data.props || {},
|
|
1213
|
-
fromOptions,
|
|
1214
|
-
toOptions
|
|
1215
|
-
});
|
|
1216
|
-
}
|
|
1217
|
-
} : (() => {
|
|
1218
|
-
var _a3;
|
|
1219
|
-
const mapEntries = ((_a3 = data.props) == null ? void 0 : _a3._map) || [];
|
|
1220
|
-
const toPaths = mapEntries.flatMap(
|
|
1221
|
-
(entry) => Array.isArray(entry.to) ? entry.to : entry.to ? [entry.to] : []
|
|
1222
|
-
);
|
|
1223
|
-
const toPath = toPaths.find(
|
|
1224
|
-
(path) => typeof path === "string" && isArrayMappingPath(path)
|
|
1225
|
-
);
|
|
1226
|
-
const arrayBaseName = toPath ? getArrayBasePath(toPath) : null;
|
|
1227
|
-
const targetArrayField = arrayBaseName ? defaultFields[arrayBaseName] : null;
|
|
1228
|
-
const mappedSubProps = /* @__PURE__ */ new Set();
|
|
1229
|
-
if (arrayBaseName) {
|
|
1230
|
-
toPaths.forEach((path) => {
|
|
1231
|
-
if (typeof path !== "string") return;
|
|
1232
|
-
if (getArrayBasePath(path) !== arrayBaseName) return;
|
|
1233
|
-
const subProp = getArrayItemSubPath(path);
|
|
1234
|
-
if (subProp) mappedSubProps.add(subProp);
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
const defaultValueFields = {};
|
|
1238
|
-
if (targetArrayField && targetArrayField.type === "array" && targetArrayField.arrayFields) {
|
|
1239
|
-
const arrayFields = targetArrayField.arrayFields;
|
|
1240
|
-
Object.entries(arrayFields).forEach(([key, fld]) => {
|
|
1241
|
-
if (mappedSubProps.has(key)) return;
|
|
1242
|
-
if (fld.type === "array" || fld.type === "object" || fld.type === "slot") return;
|
|
1243
|
-
defaultValueFields[key] = __spreadProps(__spreadValues({}, fld), { label: fld.label || key });
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
const baseArrayFields = {
|
|
1247
|
-
from: {
|
|
1248
|
-
type: "select",
|
|
1249
|
-
label: "From",
|
|
1250
|
-
options: [
|
|
1251
|
-
{ label: "Select a field", value: "" },
|
|
1252
|
-
...fromOptions.map(({ label, value }) => ({
|
|
1253
|
-
label,
|
|
1254
|
-
value
|
|
1255
|
-
}))
|
|
1256
|
-
]
|
|
1257
|
-
},
|
|
1258
|
-
to: {
|
|
1259
|
-
type: "select",
|
|
1260
|
-
label: "To",
|
|
1261
|
-
options: [
|
|
1262
|
-
{ label: "Select a field", value: "" },
|
|
1263
|
-
...toOptions.map(({ label, value }) => ({
|
|
1264
|
-
label,
|
|
1265
|
-
value
|
|
1266
|
-
}))
|
|
1267
|
-
]
|
|
1268
|
-
}
|
|
1269
|
-
};
|
|
1270
|
-
if (arrayBaseName && Object.keys(defaultValueFields).length > 0) {
|
|
1271
|
-
baseArrayFields.unmappedArrayItemDefaultValues = {
|
|
1272
|
-
type: "object",
|
|
1273
|
-
label: "Default Item Values",
|
|
1274
|
-
objectFields: defaultValueFields
|
|
1275
|
-
};
|
|
1276
|
-
}
|
|
1277
|
-
return {
|
|
1278
|
-
type: "array",
|
|
1279
|
-
label: "Dynamic Field Map",
|
|
1280
|
-
arrayFields: baseArrayFields
|
|
1281
|
-
};
|
|
1282
|
-
})();
|
|
1283
|
-
}
|
|
1284
|
-
fields = __spreadValues(__spreadValues({}, fields), defaultFields);
|
|
1285
|
-
return fields;
|
|
1286
|
-
});
|
|
1287
|
-
},
|
|
1288
|
-
resolveData: ({ props }, { lastData }) => {
|
|
1289
|
-
const _map = (props._map || []).map((item) => {
|
|
1290
|
-
const newItem = __spreadValues({}, item);
|
|
1291
|
-
if (typeof newItem.unmappedArrayItemDefaultValues === "string") {
|
|
1292
|
-
try {
|
|
1293
|
-
newItem.unmappedArrayItemDefaultValues = JSON.parse(
|
|
1294
|
-
newItem.unmappedArrayItemDefaultValues
|
|
1295
|
-
);
|
|
1296
|
-
} catch (e) {
|
|
1297
|
-
newItem.unmappedArrayItemDefaultValues = {};
|
|
1298
|
-
}
|
|
1299
|
-
} else if (!newItem.unmappedArrayItemDefaultValues) {
|
|
1300
|
-
newItem.unmappedArrayItemDefaultValues = {};
|
|
1301
|
-
}
|
|
1302
|
-
return newItem;
|
|
1303
|
-
});
|
|
1304
|
-
const readOnlyFields = _map.flatMap((item) => item.to);
|
|
1305
|
-
const readOnlyArrayBases = readOnlyFields.filter((field) => typeof field === "string").map(getArrayBasePath).filter((base) => base !== null);
|
|
1306
|
-
if (_map.length) {
|
|
1307
|
-
return {
|
|
1308
|
-
props: __spreadProps(__spreadValues({}, props), { _map }),
|
|
1309
|
-
readOnly: [
|
|
1310
|
-
...readOnlyFields.map((f) => String(f)),
|
|
1311
|
-
...readOnlyArrayBases
|
|
1312
|
-
].reduce(
|
|
1313
|
-
(acc2, field) => __spreadProps(__spreadValues({}, acc2), { [field]: true }),
|
|
1314
|
-
{}
|
|
1315
|
-
)
|
|
1316
|
-
};
|
|
1317
|
-
}
|
|
1318
|
-
return {
|
|
1319
|
-
props: __spreadProps(__spreadValues({}, props), { _map }),
|
|
1320
|
-
readOnly: {}
|
|
1321
|
-
};
|
|
1322
|
-
},
|
|
1323
|
-
render: (props) => {
|
|
1324
|
-
return /* @__PURE__ */ jsx4(ErrorBoundary, { children: component.render(props) });
|
|
1325
|
-
}
|
|
1326
|
-
});
|
|
1327
|
-
acc[name] = tempComponent;
|
|
1328
|
-
return acc;
|
|
1329
|
-
},
|
|
1330
|
-
{}
|
|
1331
|
-
),
|
|
1332
|
-
categories: config.categories || {}
|
|
1333
|
-
});
|
|
519
|
+
// src/puck/store/slices/builder.tsx
|
|
520
|
+
import {
|
|
521
|
+
walkTree as walkTree2
|
|
522
|
+
} from "@measured/puck";
|
|
1334
523
|
|
|
1335
524
|
// src/puck/lib/soft-component-constants.ts
|
|
1336
525
|
var TECHNICAL_KEYS = /* @__PURE__ */ new Set(["_map", "_slot", "id", "_version"]);
|
|
@@ -1354,6 +543,72 @@ var sanitizeComponent = (component, allowedTypes) => {
|
|
|
1354
543
|
});
|
|
1355
544
|
};
|
|
1356
545
|
|
|
546
|
+
// src/puck/lib/custom-fields.ts
|
|
547
|
+
var builtInSoftFieldTypes = /* @__PURE__ */ new Set([
|
|
548
|
+
"text",
|
|
549
|
+
"textarea",
|
|
550
|
+
"number",
|
|
551
|
+
"select",
|
|
552
|
+
"radio",
|
|
553
|
+
"array",
|
|
554
|
+
"object",
|
|
555
|
+
"reference"
|
|
556
|
+
]);
|
|
557
|
+
var warnedMessages = /* @__PURE__ */ new Set();
|
|
558
|
+
var warnOnce = (message) => {
|
|
559
|
+
if (warnedMessages.has(message)) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
warnedMessages.add(message);
|
|
563
|
+
console.warn(message);
|
|
564
|
+
};
|
|
565
|
+
var isBuiltInSoftFieldType = (fieldType) => {
|
|
566
|
+
return builtInSoftFieldTypes.has(fieldType);
|
|
567
|
+
};
|
|
568
|
+
var resolveCustomFieldDefinition = (fieldType, customFields) => {
|
|
569
|
+
if (isBuiltInSoftFieldType(fieldType)) {
|
|
570
|
+
return void 0;
|
|
571
|
+
}
|
|
572
|
+
return customFields == null ? void 0 : customFields[fieldType];
|
|
573
|
+
};
|
|
574
|
+
var resolveCustomFieldReturnType = (fieldType, customFields) => {
|
|
575
|
+
const customField = resolveCustomFieldDefinition(fieldType, customFields);
|
|
576
|
+
if (!customField) {
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
if (!customField.returnType) {
|
|
580
|
+
warnOnce(
|
|
581
|
+
`[soft-config] Custom field "${fieldType}" is missing a required returnType and will be skipped from mapping options.`
|
|
582
|
+
);
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
return customField.returnType;
|
|
586
|
+
};
|
|
587
|
+
var resolveCustomFieldSchema = (fieldType, customFields) => {
|
|
588
|
+
const customField = resolveCustomFieldDefinition(fieldType, customFields);
|
|
589
|
+
if (!customField) {
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
const returnType = resolveCustomFieldReturnType(fieldType, customFields);
|
|
593
|
+
if (!returnType) {
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
if (returnType !== "array" && returnType !== "object") {
|
|
597
|
+
return null;
|
|
598
|
+
}
|
|
599
|
+
const subFields = customField.subFields || [];
|
|
600
|
+
if (!subFields.length) {
|
|
601
|
+
warnOnce(
|
|
602
|
+
`[soft-config] Custom field "${fieldType}" returns ${returnType} but does not define subFields. It will be skipped from mapping options.`
|
|
603
|
+
);
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
return {
|
|
607
|
+
subFields,
|
|
608
|
+
subFieldSettings: customField.subFieldSettings || {}
|
|
609
|
+
};
|
|
610
|
+
};
|
|
611
|
+
|
|
1357
612
|
// src/puck/lib/soft-component-from-appstate.ts
|
|
1358
613
|
var getSubComponents = (content, componentConfigs, fieldSettings, slots) => {
|
|
1359
614
|
if (!content || !Array.isArray(content)) return [];
|
|
@@ -1509,8 +764,8 @@ var softComponentFromAppState = (appState, configComponents, editedItem, metadat
|
|
|
1509
764
|
var _a;
|
|
1510
765
|
const rootProps = ((_a = appState.data.root) == null ? void 0 : _a.props) || {};
|
|
1511
766
|
const fields = rootProps._fields || [];
|
|
1512
|
-
const
|
|
1513
|
-
const normalizedFieldSettings = __spreadValues({},
|
|
767
|
+
const fieldSettings = rootProps._fieldSettings || {};
|
|
768
|
+
const normalizedFieldSettings = __spreadValues({}, fieldSettings);
|
|
1514
769
|
(fields || []).forEach((field) => {
|
|
1515
770
|
const customFieldDefinition = resolveCustomFieldDefinition(
|
|
1516
771
|
field.type,
|
|
@@ -1836,12 +1091,100 @@ var rootZone = "default-zone";
|
|
|
1836
1091
|
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
1837
1092
|
|
|
1838
1093
|
// src/puck/components/soft-render/index.tsx
|
|
1839
|
-
import
|
|
1840
|
-
import
|
|
1841
|
-
|
|
1094
|
+
import React2, { useMemo, memo } from "react";
|
|
1095
|
+
import equal2 from "react-fast-compare";
|
|
1096
|
+
|
|
1097
|
+
// src/puck/components/error-boundary/index.tsx
|
|
1098
|
+
import { Component } from "react";
|
|
1099
|
+
|
|
1100
|
+
// src/puck/lib/get-class-name-factory.ts
|
|
1101
|
+
import classnames from "classnames";
|
|
1102
|
+
var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
|
|
1103
|
+
if (typeof options === "string") {
|
|
1104
|
+
const descendant = options;
|
|
1105
|
+
const style = styles[`${rootClass}-${descendant}`];
|
|
1106
|
+
if (style) {
|
|
1107
|
+
return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
|
|
1108
|
+
}
|
|
1109
|
+
return "";
|
|
1110
|
+
} else if (typeof options === "object") {
|
|
1111
|
+
const modifiers = options;
|
|
1112
|
+
const prefixedModifiers = {};
|
|
1113
|
+
for (let modifier in modifiers) {
|
|
1114
|
+
prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
|
|
1115
|
+
}
|
|
1116
|
+
const c = styles[rootClass];
|
|
1117
|
+
return config.baseClass + classnames(__spreadValues({
|
|
1118
|
+
[c]: !!c
|
|
1119
|
+
}, prefixedModifiers));
|
|
1120
|
+
} else {
|
|
1121
|
+
return config.baseClass + styles[rootClass] || "";
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
var get_class_name_factory_default = getClassNameFactory;
|
|
1125
|
+
|
|
1126
|
+
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
|
|
1127
|
+
var styles_module_default = { "ErrorBoundary": "_ErrorBoundary_1xl05_5", "ErrorBoundary-title": "_ErrorBoundary-title_1xl05_21", "ErrorBoundary-details": "_ErrorBoundary-details_1xl05_31", "ErrorBoundary-button": "_ErrorBoundary-button_1xl05_39" };
|
|
1128
|
+
|
|
1129
|
+
// src/puck/components/error-boundary/index.tsx
|
|
1130
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1131
|
+
var getClassName = get_class_name_factory_default("ErrorBoundary", styles_module_default);
|
|
1132
|
+
var ErrorBoundary = class extends Component {
|
|
1133
|
+
constructor(props) {
|
|
1134
|
+
super(props);
|
|
1135
|
+
this.resetError = () => {
|
|
1136
|
+
this.setState({
|
|
1137
|
+
hasError: false,
|
|
1138
|
+
error: null
|
|
1139
|
+
});
|
|
1140
|
+
};
|
|
1141
|
+
this.state = {
|
|
1142
|
+
hasError: false,
|
|
1143
|
+
error: null
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
static getDerivedStateFromError(error) {
|
|
1147
|
+
return {
|
|
1148
|
+
hasError: true,
|
|
1149
|
+
error
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
componentDidCatch(error, errorInfo) {
|
|
1153
|
+
console.error("Error caught by ErrorBoundary:", error, errorInfo);
|
|
1154
|
+
}
|
|
1155
|
+
render() {
|
|
1156
|
+
if (this.state.hasError) {
|
|
1157
|
+
if (typeof this.props.fallback === "function") {
|
|
1158
|
+
return this.props.fallback(this.state.error, this.resetError);
|
|
1159
|
+
}
|
|
1160
|
+
if (this.props.fallback) {
|
|
1161
|
+
return this.props.fallback;
|
|
1162
|
+
}
|
|
1163
|
+
return /* @__PURE__ */ jsxs("div", { className: getClassName(), children: [
|
|
1164
|
+
/* @__PURE__ */ jsx("h3", { className: getClassName("title"), children: "Component Error" }),
|
|
1165
|
+
/* @__PURE__ */ jsxs("details", { className: getClassName("details"), children: [
|
|
1166
|
+
/* @__PURE__ */ jsx("summary", { children: "Show error details" }),
|
|
1167
|
+
this.state.error && this.state.error.toString()
|
|
1168
|
+
] }),
|
|
1169
|
+
/* @__PURE__ */ jsx(
|
|
1170
|
+
"button",
|
|
1171
|
+
{
|
|
1172
|
+
onClick: this.resetError,
|
|
1173
|
+
className: getClassName("button"),
|
|
1174
|
+
children: "Try Again"
|
|
1175
|
+
}
|
|
1176
|
+
)
|
|
1177
|
+
] });
|
|
1178
|
+
}
|
|
1179
|
+
return this.props.children;
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
// src/puck/components/soft-render/index.tsx
|
|
1184
|
+
import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
|
|
1842
1185
|
function isPlainObject(val) {
|
|
1843
1186
|
if (typeof val !== "object" || val === null) return false;
|
|
1844
|
-
if (
|
|
1187
|
+
if (React2.isValidElement(val)) return false;
|
|
1845
1188
|
if ("$$typeof" in val) return false;
|
|
1846
1189
|
const proto = Object.getPrototypeOf(val);
|
|
1847
1190
|
return proto === Object.prototype || proto === null;
|
|
@@ -1849,12 +1192,27 @@ function isPlainObject(val) {
|
|
|
1849
1192
|
function cloneData(value) {
|
|
1850
1193
|
if (value === null || value === void 0) return value;
|
|
1851
1194
|
if (typeof value === "function") return value;
|
|
1852
|
-
if (Array.isArray(value))
|
|
1195
|
+
if (Array.isArray(value))
|
|
1196
|
+
return value.map(cloneData);
|
|
1853
1197
|
if (!isPlainObject(value)) return value;
|
|
1854
1198
|
return Object.fromEntries(
|
|
1855
1199
|
Object.entries(value).map(([k, v]) => [k, cloneData(v)])
|
|
1856
1200
|
);
|
|
1857
1201
|
}
|
|
1202
|
+
function shallowEqual(objA, objB) {
|
|
1203
|
+
if (Object.is(objA, objB)) return true;
|
|
1204
|
+
if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null)
|
|
1205
|
+
return false;
|
|
1206
|
+
const keysA = Object.keys(objA);
|
|
1207
|
+
const keysB = Object.keys(objB);
|
|
1208
|
+
if (keysA.length !== keysB.length) return false;
|
|
1209
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
1210
|
+
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
|
|
1211
|
+
return false;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
return true;
|
|
1215
|
+
}
|
|
1858
1216
|
var SubComponentRenderer = memo(
|
|
1859
1217
|
({
|
|
1860
1218
|
subComponent,
|
|
@@ -1906,7 +1264,7 @@ var SubComponentRenderer = memo(
|
|
|
1906
1264
|
style
|
|
1907
1265
|
}) => {
|
|
1908
1266
|
var _a3, _b2;
|
|
1909
|
-
return /* @__PURE__ */
|
|
1267
|
+
return /* @__PURE__ */ jsx2("div", { className, style, children: /* @__PURE__ */ jsx2(
|
|
1910
1268
|
SoftRender,
|
|
1911
1269
|
{
|
|
1912
1270
|
softComponentFields,
|
|
@@ -1933,7 +1291,7 @@ var SubComponentRenderer = memo(
|
|
|
1933
1291
|
]);
|
|
1934
1292
|
if (!componentConfig) return null;
|
|
1935
1293
|
const ComponentRender = componentConfig.render;
|
|
1936
|
-
return /* @__PURE__ */
|
|
1294
|
+
return /* @__PURE__ */ jsx2(ErrorBoundary, { children: /* @__PURE__ */ jsx2(
|
|
1937
1295
|
ComponentRender,
|
|
1938
1296
|
__spreadValues({
|
|
1939
1297
|
id: stableId,
|
|
@@ -1942,14 +1300,11 @@ var SubComponentRenderer = memo(
|
|
|
1942
1300
|
}, finalProps)
|
|
1943
1301
|
) });
|
|
1944
1302
|
},
|
|
1945
|
-
//
|
|
1946
|
-
//
|
|
1947
|
-
|
|
1948
|
-
//
|
|
1949
|
-
|
|
1950
|
-
// configComponents and softComponentFields are treated as stable config
|
|
1951
|
-
// references — reference equality is intentional and fast here.
|
|
1952
|
-
(prev, next) => prev.depth === next.depth && prev.index === next.index && prev.configComponents === next.configComponents && prev.softComponentFields === next.softComponentFields && equal3(prev.props, next.props) && equal3(prev.subComponent, next.subComponent) && equal3(prev.softComponentFieldSettings, next.softComponentFieldSettings)
|
|
1303
|
+
(prev, next) => prev.depth === next.depth && prev.index === next.index && prev.configComponents === next.configComponents && prev.softComponentFields === next.softComponentFields && // Shallow compare: props may contain functions/React nodes; deep equality
|
|
1304
|
+
// would risk retaining stale closures and is unnecessarily expensive here.
|
|
1305
|
+
shallowEqual(prev.props, next.props) && // Deep compare: subComponent and fieldSettings are plain JSON configuration
|
|
1306
|
+
// objects with no functions, so structural equality is safe and correct.
|
|
1307
|
+
equal2(prev.subComponent, next.subComponent) && equal2(prev.softComponentFieldSettings, next.softComponentFieldSettings)
|
|
1953
1308
|
);
|
|
1954
1309
|
SubComponentRenderer.displayName = "SubComponentRenderer";
|
|
1955
1310
|
var SoftRender = memo(
|
|
@@ -1962,9 +1317,9 @@ var SoftRender = memo(
|
|
|
1962
1317
|
depth = 0
|
|
1963
1318
|
}) => {
|
|
1964
1319
|
if (!(softSubComponent == null ? void 0 : softSubComponent.length)) return null;
|
|
1965
|
-
return /* @__PURE__ */
|
|
1320
|
+
return /* @__PURE__ */ jsx2(Fragment, { children: softSubComponent.map((subComponent, index) => {
|
|
1966
1321
|
var _a;
|
|
1967
|
-
return /* @__PURE__ */
|
|
1322
|
+
return /* @__PURE__ */ jsx2(
|
|
1968
1323
|
SubComponentRenderer,
|
|
1969
1324
|
{
|
|
1970
1325
|
subComponent,
|
|
@@ -1979,16 +1334,14 @@ var SoftRender = memo(
|
|
|
1979
1334
|
);
|
|
1980
1335
|
}) });
|
|
1981
1336
|
},
|
|
1982
|
-
|
|
1983
|
-
//
|
|
1984
|
-
|
|
1985
|
-
// props / softSubComponent: deep equality (primary render drivers).
|
|
1986
|
-
(prev, next) => prev.configComponents === next.configComponents && prev.softComponentFields === next.softComponentFields && equal3(prev.props, next.props) && equal3(prev.softSubComponent, next.softSubComponent) && equal3(prev.softComponentFieldSettings, next.softComponentFieldSettings)
|
|
1337
|
+
(prev, next) => prev.configComponents === next.configComponents && prev.softComponentFields === next.softComponentFields && // Shallow compare: props may contain functions/React nodes; see shallowEqual.
|
|
1338
|
+
shallowEqual(prev.props, next.props) && // Deep compare: softSubComponent and fieldSettings are plain JSON schemas.
|
|
1339
|
+
equal2(prev.softSubComponent, next.softSubComponent) && equal2(prev.softComponentFieldSettings, next.softComponentFieldSettings)
|
|
1987
1340
|
);
|
|
1988
1341
|
SoftRender.displayName = "SoftRender";
|
|
1989
1342
|
|
|
1990
1343
|
// src/puck/lib/create-versioned-component-config.tsx
|
|
1991
|
-
import { jsx as
|
|
1344
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1992
1345
|
var hydrateCustomField = (fieldName, field, fieldSettings, customFields) => {
|
|
1993
1346
|
var _a;
|
|
1994
1347
|
if (field.type !== "custom") {
|
|
@@ -2046,7 +1399,7 @@ var createVersionedComponentConfig = (componentName, displayName, version, allVe
|
|
|
2046
1399
|
var _a2;
|
|
2047
1400
|
const selectedVersion = props.version || version;
|
|
2048
1401
|
const versionedComponent = (_a2 = softComponents[componentName]) == null ? void 0 : _a2.versions[selectedVersion];
|
|
2049
|
-
return /* @__PURE__ */
|
|
1402
|
+
return /* @__PURE__ */ jsx3(
|
|
2050
1403
|
SoftRender,
|
|
2051
1404
|
{
|
|
2052
1405
|
softComponentFields: versionedComponent.fields,
|
|
@@ -2061,7 +1414,7 @@ var createVersionedComponentConfig = (componentName, displayName, version, allVe
|
|
|
2061
1414
|
};
|
|
2062
1415
|
|
|
2063
1416
|
// src/puck/lib/builder/sub-component-decomposer.tsx
|
|
2064
|
-
var subComponentDecomposer = (componentRootData, softSubComponent) => {
|
|
1417
|
+
var subComponentDecomposer = (componentRootData, softSubComponent, keepMapField) => {
|
|
2065
1418
|
var _a;
|
|
2066
1419
|
const resolvedProps = __spreadValues({}, softSubComponent.fixedProps);
|
|
2067
1420
|
(_a = softSubComponent.map) == null ? void 0 : _a.forEach((mapItem) => {
|
|
@@ -2084,21 +1437,21 @@ var subComponentDecomposer = (componentRootData, softSubComponent) => {
|
|
|
2084
1437
|
Object.entries(softSubComponent.components).forEach(
|
|
2085
1438
|
([slotKey, subComponents]) => {
|
|
2086
1439
|
resolvedProps[slotKey] = subComponents.map(
|
|
2087
|
-
(subComponent) => subComponentDecomposer(componentRootData, subComponent)
|
|
1440
|
+
(subComponent) => subComponentDecomposer(componentRootData, subComponent, keepMapField)
|
|
2088
1441
|
);
|
|
2089
1442
|
}
|
|
2090
1443
|
);
|
|
2091
1444
|
const accItem = {
|
|
2092
1445
|
type: softSubComponent.type,
|
|
2093
|
-
props: __spreadProps(__spreadValues({}, resolvedProps), {
|
|
1446
|
+
props: __spreadValues(__spreadProps(__spreadValues({}, resolvedProps), {
|
|
2094
1447
|
id: generateId(softSubComponent.type)
|
|
2095
|
-
})
|
|
1448
|
+
}), keepMapField ? { _map: softSubComponent.map } : {})
|
|
2096
1449
|
};
|
|
2097
1450
|
return accItem;
|
|
2098
1451
|
};
|
|
2099
1452
|
|
|
2100
1453
|
// src/puck/lib/builder/resolve-soft-component-data.ts
|
|
2101
|
-
var resolveSoftComponentData = (props, _fieldSettings = {}) => {
|
|
1454
|
+
var resolveSoftComponentData = (props, _fieldSettings = {}, keepMapField) => {
|
|
2102
1455
|
const map = props._map;
|
|
2103
1456
|
if (!(map == null ? void 0 : map.length)) return __spreadValues({}, props);
|
|
2104
1457
|
const { newProps } = applyMapping(
|
|
@@ -2107,11 +1460,16 @@ var resolveSoftComponentData = (props, _fieldSettings = {}) => {
|
|
|
2107
1460
|
map,
|
|
2108
1461
|
"propsFirst"
|
|
2109
1462
|
);
|
|
1463
|
+
if (keepMapField) {
|
|
1464
|
+
return __spreadProps(__spreadValues({}, newProps), {
|
|
1465
|
+
_map: map
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
2110
1468
|
return newProps;
|
|
2111
1469
|
};
|
|
2112
1470
|
|
|
2113
1471
|
// src/puck/lib/decompose-soft-component.ts
|
|
2114
|
-
function decomposeSoftComponent(componentData, softComponents, fieldSettings) {
|
|
1472
|
+
function decomposeSoftComponent(componentData, softComponents, fieldSettings, keepMapField) {
|
|
2115
1473
|
var _a, _b, _c, _d;
|
|
2116
1474
|
if (!(componentData == null ? void 0 : componentData.type) || !(componentData == null ? void 0 : componentData.props.id)) {
|
|
2117
1475
|
throw new Error("Component data must have type and id to decompose.");
|
|
@@ -2135,7 +1493,11 @@ function decomposeSoftComponent(componentData, softComponents, fieldSettings) {
|
|
|
2135
1493
|
}
|
|
2136
1494
|
const decomposedComponentData = softComponent.components.map(
|
|
2137
1495
|
(softSubComponent) => {
|
|
2138
|
-
return subComponentDecomposer(
|
|
1496
|
+
return subComponentDecomposer(
|
|
1497
|
+
resolvedComponentData,
|
|
1498
|
+
softSubComponent,
|
|
1499
|
+
keepMapField
|
|
1500
|
+
);
|
|
2139
1501
|
}
|
|
2140
1502
|
);
|
|
2141
1503
|
return decomposedComponentData;
|
|
@@ -2145,9 +1507,9 @@ function isSoftComponent(componentType, softComponents) {
|
|
|
2145
1507
|
}
|
|
2146
1508
|
|
|
2147
1509
|
// src/puck/lib/demolish-soft-component.ts
|
|
2148
|
-
import { walkTree
|
|
1510
|
+
import { walkTree } from "@measured/puck";
|
|
2149
1511
|
function demolishSoftComponent(componentName, data, config, softComponents) {
|
|
2150
|
-
const resolvedData =
|
|
1512
|
+
const resolvedData = walkTree(data, config, (components) => {
|
|
2151
1513
|
components.forEach((componentData, index) => {
|
|
2152
1514
|
if (componentData.type === componentName) {
|
|
2153
1515
|
const decomposed = decomposeSoftComponent(componentData, softComponents);
|
|
@@ -2227,50 +1589,22 @@ var clearEditVisibility = (doc) => {
|
|
|
2227
1589
|
doc.querySelectorAll("[data-puck-component]").forEach((el) => {
|
|
2228
1590
|
el.removeAttribute("data-edit-visibility");
|
|
2229
1591
|
el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
|
|
2230
|
-
});
|
|
2231
|
-
} catch (error) {
|
|
2232
|
-
console.warn(`Failed to clear edit visibility:`, error);
|
|
2233
|
-
}
|
|
2234
|
-
};
|
|
2235
|
-
|
|
2236
|
-
// src/puck/store/slices/builder.tsx
|
|
2237
|
-
var createBuildersSlice = (set, get
|
|
2238
|
-
build: (history, selectedItem, itemSelector, puckDispatch, name) => {
|
|
2239
|
-
if (!selectedItem || !itemSelector) {
|
|
2240
|
-
throw new Error("No item selected to build from.");
|
|
2241
|
-
}
|
|
2242
|
-
|
|
2243
|
-
type: "set",
|
|
2244
|
-
state: (previous) => {
|
|
2245
|
-
var _a;
|
|
2246
|
-
return {
|
|
2247
|
-
ui: __spreadProps(__spreadValues({}, previous.ui), {
|
|
2248
|
-
itemSelector: null
|
|
2249
|
-
}),
|
|
2250
|
-
data: __spreadProps(__spreadValues({}, previous.data), {
|
|
2251
|
-
root: __spreadProps(__spreadValues({}, previous.data.root), {
|
|
2252
|
-
props: __spreadProps(__spreadValues({}, (_a = previous.data.root) == null ? void 0 : _a.props), {
|
|
2253
|
-
_name: name || "New Soft Component"
|
|
2254
|
-
})
|
|
2255
|
-
})
|
|
2256
|
-
// content: [{ ...selectedItem }],
|
|
2257
|
-
})
|
|
2258
|
-
};
|
|
2259
|
-
}
|
|
2260
|
-
});
|
|
2261
|
-
const config = __spreadValues({}, get().softConfig);
|
|
2262
|
-
const overrides = get().overrides;
|
|
2263
|
-
const buildConfig = builderConfig(
|
|
2264
|
-
config,
|
|
2265
|
-
overrides,
|
|
2266
|
-
void 0,
|
|
2267
|
-
get().showVersionFields,
|
|
2268
|
-
void 0,
|
|
2269
|
-
get().customFields
|
|
2270
|
-
);
|
|
1592
|
+
});
|
|
1593
|
+
} catch (error) {
|
|
1594
|
+
console.warn(`Failed to clear edit visibility:`, error);
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
|
|
1598
|
+
// src/puck/store/slices/builder.tsx
|
|
1599
|
+
var createBuildersSlice = (set, get) => ({
|
|
1600
|
+
build: (history, selectedItem, itemSelector, puckDispatch, name) => {
|
|
1601
|
+
if (!selectedItem || !itemSelector) {
|
|
1602
|
+
throw new Error("No item selected to build from.");
|
|
1603
|
+
}
|
|
1604
|
+
const config = get().softConfig;
|
|
2271
1605
|
const editableIds = /* @__PURE__ */ new Set([selectedItem.props.id]);
|
|
2272
1606
|
const initialContent = [__spreadValues({}, selectedItem)];
|
|
2273
|
-
|
|
1607
|
+
walkTree2(
|
|
2274
1608
|
{
|
|
2275
1609
|
root: {},
|
|
2276
1610
|
content: initialContent
|
|
@@ -2290,8 +1624,6 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2290
1624
|
})
|
|
2291
1625
|
);
|
|
2292
1626
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2293
|
-
softConfig: buildConfig,
|
|
2294
|
-
storedConfig: config,
|
|
2295
1627
|
originalHistory: history,
|
|
2296
1628
|
itemSelector: {
|
|
2297
1629
|
index: itemSelector.index,
|
|
@@ -2301,17 +1633,24 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2301
1633
|
editableComponentIds: editableIds,
|
|
2302
1634
|
state: "building"
|
|
2303
1635
|
}));
|
|
2304
|
-
requestAnimationFrame(
|
|
2305
|
-
|
|
1636
|
+
requestAnimationFrame(() => {
|
|
1637
|
+
puckDispatch({
|
|
1638
|
+
type: "setUi",
|
|
1639
|
+
ui: { itemSelector: null },
|
|
1640
|
+
recordHistory: false
|
|
1641
|
+
});
|
|
1642
|
+
puckDispatch({
|
|
2306
1643
|
type: "replaceRoot",
|
|
2307
1644
|
root: {
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
1645
|
+
props: {
|
|
1646
|
+
_name: name || "New Soft Component"
|
|
1647
|
+
}
|
|
1648
|
+
},
|
|
1649
|
+
recordHistory: false
|
|
1650
|
+
});
|
|
1651
|
+
});
|
|
2313
1652
|
},
|
|
2314
|
-
remodel: (history, selectedItem, itemSelector, puckDispatch) => {
|
|
1653
|
+
remodel: (history, selectedItem, itemSelector, puckDispatch, refreshPermission) => {
|
|
2315
1654
|
var _a, _b;
|
|
2316
1655
|
if (!selectedItem || !itemSelector) {
|
|
2317
1656
|
throw new Error("No item selected to build from.");
|
|
@@ -2331,13 +1670,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2331
1670
|
`Soft component "${softComponentName}" with version "${softComponentVersion}" not found.`
|
|
2332
1671
|
);
|
|
2333
1672
|
}
|
|
2334
|
-
|
|
2335
|
-
type: "setUi",
|
|
2336
|
-
ui: (previous) => __spreadProps(__spreadValues({}, previous), {
|
|
2337
|
-
itemSelector: void 0
|
|
2338
|
-
})
|
|
2339
|
-
});
|
|
2340
|
-
const { root, content } = softComponentToAppState(
|
|
1673
|
+
const { root } = softComponentToAppState(
|
|
2341
1674
|
softComponent,
|
|
2342
1675
|
softComponentName,
|
|
2343
1676
|
softComponentVersion,
|
|
@@ -2349,82 +1682,104 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2349
1682
|
softComponentMeta == null ? void 0 : softComponentMeta.category,
|
|
2350
1683
|
get().customFields
|
|
2351
1684
|
);
|
|
2352
|
-
const config =
|
|
2353
|
-
const overrides = get().overrides;
|
|
1685
|
+
const config = get().softConfig;
|
|
2354
1686
|
const dependents = get().dependencyGraph.get(softComponentName) || /* @__PURE__ */ new Set();
|
|
2355
|
-
const
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
get().showVersionFields,
|
|
2360
|
-
dependents,
|
|
2361
|
-
get().customFields
|
|
2362
|
-
);
|
|
2363
|
-
const editableIds = /* @__PURE__ */ new Set([]);
|
|
2364
|
-
const decomposedComponents = get().builder.decompose(selectedItem);
|
|
2365
|
-
walkTree3(
|
|
2366
|
-
{ root: {}, content: decomposedComponents || [] },
|
|
1687
|
+
const decomposedComponents = get().builder.decompose(selectedItem, true);
|
|
1688
|
+
const editableIds = /* @__PURE__ */ new Set([decomposedComponents[0].props.id]);
|
|
1689
|
+
const { content: decomposedComponentsWithId } = walkTree2(
|
|
1690
|
+
{ root: {}, content: decomposedComponents },
|
|
2367
1691
|
{ components: config.components },
|
|
2368
1692
|
(components) => {
|
|
2369
|
-
components.forEach((
|
|
2370
|
-
|
|
1693
|
+
components.forEach((comp2) => {
|
|
1694
|
+
const id2 = generateId(comp2.type);
|
|
1695
|
+
comp2.props.id = id2;
|
|
1696
|
+
editableIds.add(id2);
|
|
2371
1697
|
});
|
|
2372
1698
|
return components;
|
|
2373
1699
|
}
|
|
2374
1700
|
);
|
|
2375
|
-
puckDispatch({
|
|
2376
|
-
type: "setData",
|
|
2377
|
-
data: (prevData) => ({
|
|
2378
|
-
root: __spreadProps(__spreadValues({}, root), { _versions: versions }),
|
|
2379
|
-
content: walkTree3(__spreadValues({}, prevData), __spreadValues({}, config), (components) => {
|
|
2380
|
-
const next = components.map((component) => __spreadProps(__spreadValues({}, component), {
|
|
2381
|
-
props: __spreadValues({}, component.props)
|
|
2382
|
-
}));
|
|
2383
|
-
const index = next.findIndex(
|
|
2384
|
-
(component) => component.props.id === selectedItem.props.id
|
|
2385
|
-
);
|
|
2386
|
-
if (index !== -1) {
|
|
2387
|
-
next.splice(
|
|
2388
|
-
index,
|
|
2389
|
-
1,
|
|
2390
|
-
...decomposedComponents.map((component) => __spreadProps(__spreadValues({}, component), {
|
|
2391
|
-
props: __spreadValues({}, component.props)
|
|
2392
|
-
}))
|
|
2393
|
-
);
|
|
2394
|
-
}
|
|
2395
|
-
return next;
|
|
2396
|
-
}).content
|
|
2397
|
-
})
|
|
2398
|
-
});
|
|
2399
|
-
requestAnimationFrame(
|
|
2400
|
-
() => setEditVisibility(get().iframeDoc, {
|
|
2401
|
-
mode: "remodel",
|
|
2402
|
-
editableIds
|
|
2403
|
-
})
|
|
2404
|
-
);
|
|
2405
1701
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2406
|
-
storedConfig: config,
|
|
2407
|
-
softConfig: buildConfig,
|
|
2408
1702
|
originalHistory: history,
|
|
2409
1703
|
itemSelector: {
|
|
2410
1704
|
index: itemSelector.index,
|
|
2411
1705
|
zone: itemSelector.zone || rootDroppableId
|
|
2412
1706
|
},
|
|
2413
|
-
editingComponentId: selectedItem.props.id,
|
|
2414
1707
|
editingComponent: softComponentName,
|
|
1708
|
+
editingDependents: dependents,
|
|
2415
1709
|
editableComponentIds: editableIds,
|
|
2416
|
-
state: "
|
|
1710
|
+
state: "assessing"
|
|
2417
1711
|
}));
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
1712
|
+
puckDispatch({
|
|
1713
|
+
type: "remove",
|
|
1714
|
+
index: itemSelector.index,
|
|
1715
|
+
zone: itemSelector.zone || rootDroppableId,
|
|
1716
|
+
recordHistory: false
|
|
1717
|
+
});
|
|
1718
|
+
const comp = decomposedComponentsWithId[0];
|
|
1719
|
+
if (!comp) {
|
|
1720
|
+
throw new Error("No decomposed components found.");
|
|
1721
|
+
}
|
|
1722
|
+
const id = comp.props.id;
|
|
1723
|
+
puckDispatch({
|
|
1724
|
+
type: "insert",
|
|
1725
|
+
destinationIndex: itemSelector.index,
|
|
1726
|
+
destinationZone: itemSelector.zone || rootDroppableId,
|
|
1727
|
+
componentType: comp.type,
|
|
1728
|
+
recordHistory: false,
|
|
1729
|
+
id
|
|
1730
|
+
});
|
|
1731
|
+
requestAnimationFrame(() => {
|
|
1732
|
+
var _a2;
|
|
1733
|
+
const _map = ((_a2 = comp.props) == null ? void 0 : _a2._map) || [];
|
|
1734
|
+
const readOnlyFields = _map.flatMap((item) => item.to);
|
|
1735
|
+
const readOnlyArrayBases = readOnlyFields.filter((field) => typeof field === "string").map(getArrayBasePath).filter((base) => base !== null);
|
|
1736
|
+
const readOnly = [
|
|
1737
|
+
...readOnlyFields.map((f) => String(f)),
|
|
1738
|
+
...readOnlyArrayBases
|
|
1739
|
+
].reduce((acc, field) => __spreadProps(__spreadValues({}, acc), { [field]: true }), {});
|
|
1740
|
+
puckDispatch({
|
|
1741
|
+
type: "replace",
|
|
1742
|
+
destinationIndex: itemSelector.index,
|
|
1743
|
+
destinationZone: itemSelector.zone || rootDroppableId,
|
|
1744
|
+
data: __spreadProps(__spreadValues({}, comp), {
|
|
1745
|
+
props: __spreadProps(__spreadValues({}, comp.props), {
|
|
1746
|
+
id
|
|
1747
|
+
}),
|
|
1748
|
+
readOnly
|
|
1749
|
+
}),
|
|
1750
|
+
recordHistory: false
|
|
1751
|
+
});
|
|
1752
|
+
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
1753
|
+
state: "remodeling"
|
|
1754
|
+
}));
|
|
1755
|
+
setEditVisibility(get().iframeDoc, {
|
|
1756
|
+
mode: "remodel",
|
|
1757
|
+
editableIds: new Set(editableIds)
|
|
1758
|
+
});
|
|
1759
|
+
});
|
|
1760
|
+
puckDispatch({
|
|
1761
|
+
type: "replaceRoot",
|
|
1762
|
+
root: {
|
|
1763
|
+
props: __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, root.props), root.props.title !== void 0 && {
|
|
1764
|
+
title: root.props.title
|
|
1765
|
+
}), root.props._name !== void 0 && {
|
|
1766
|
+
_name: root.props._name
|
|
1767
|
+
}), root.props._category !== void 0 && {
|
|
2424
1768
|
_category: root.props._category
|
|
2425
|
-
}
|
|
2426
|
-
|
|
2427
|
-
|
|
1769
|
+
}), {
|
|
1770
|
+
_versions: versions
|
|
1771
|
+
})
|
|
1772
|
+
},
|
|
1773
|
+
recordHistory: false
|
|
1774
|
+
});
|
|
1775
|
+
requestAnimationFrame(() => {
|
|
1776
|
+
puckDispatch({
|
|
1777
|
+
type: "setUi",
|
|
1778
|
+
ui: { itemSelector: null },
|
|
1779
|
+
recordHistory: false
|
|
1780
|
+
});
|
|
1781
|
+
refreshPermission();
|
|
1782
|
+
});
|
|
2428
1783
|
},
|
|
2429
1784
|
complete: (appState, setHistories, getItemBySelector) => {
|
|
2430
1785
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -2464,7 +1819,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2464
1819
|
}
|
|
2465
1820
|
const storedHistories = get().originalHistory;
|
|
2466
1821
|
setHistories([...storedHistories]);
|
|
2467
|
-
const config = __spreadValues({}, get().softConfig
|
|
1822
|
+
const config = __spreadValues({}, get().softConfig);
|
|
2468
1823
|
const mapComponentConfig = get().overrides.mapComponentConfig;
|
|
2469
1824
|
const newSoftComponentConfig = mapComponentConfig ? mapComponentConfig(componentName, defaultSoftComponentConfig, rootProps) : defaultSoftComponentConfig;
|
|
2470
1825
|
set((s) => {
|
|
@@ -2502,12 +1857,11 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2502
1857
|
}) : categories;
|
|
2503
1858
|
return __spreadProps(__spreadValues({}, s), {
|
|
2504
1859
|
softConfig: __spreadProps(__spreadValues({}, config), {
|
|
2505
|
-
root: __spreadValues({}, initialConfig.root),
|
|
2506
1860
|
components: nextComponents,
|
|
2507
1861
|
categories: nextCategories
|
|
2508
1862
|
}),
|
|
2509
|
-
storedConfig: void 0,
|
|
2510
1863
|
state: "inspecting",
|
|
1864
|
+
// Temporarily shift state to inspect() before finalizing back to ready
|
|
2511
1865
|
originalHistory: []
|
|
2512
1866
|
});
|
|
2513
1867
|
});
|
|
@@ -2527,7 +1881,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2527
1881
|
softComponent: completedSoftComponent
|
|
2528
1882
|
};
|
|
2529
1883
|
},
|
|
2530
|
-
inspect: (componentName, puckDispatch) => {
|
|
1884
|
+
inspect: (componentName, puckDispatch, selectedItemSelector) => {
|
|
2531
1885
|
if (get().state !== "inspecting") {
|
|
2532
1886
|
throw new Error("Not in inspecting state.");
|
|
2533
1887
|
}
|
|
@@ -2536,54 +1890,74 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2536
1890
|
throw new Error("No selector found for last item.");
|
|
2537
1891
|
}
|
|
2538
1892
|
const editableComponentId = get().editingComponentId;
|
|
1893
|
+
const itemSelector = get().itemSelector;
|
|
2539
1894
|
requestAnimationFrame(() => {
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
1895
|
+
var _a;
|
|
1896
|
+
if (editableComponentId && !Object.keys(get().softComponents).includes(
|
|
1897
|
+
(_a = editableComponentId == null ? void 0 : editableComponentId.split(":")) == null ? void 0 : _a[0].split("-")[0]
|
|
1898
|
+
)) {
|
|
1899
|
+
requestAnimationFrame(() => {
|
|
1900
|
+
puckDispatch({
|
|
1901
|
+
type: "remove",
|
|
1902
|
+
index: itemSelector.index,
|
|
1903
|
+
zone: itemSelector.zone,
|
|
1904
|
+
recordHistory: true
|
|
1905
|
+
});
|
|
1906
|
+
puckDispatch({
|
|
1907
|
+
type: "insert",
|
|
1908
|
+
destinationIndex: itemSelector.index,
|
|
1909
|
+
destinationZone: itemSelector.zone,
|
|
1910
|
+
componentType: componentName,
|
|
1911
|
+
recordHistory: true
|
|
1912
|
+
});
|
|
2553
1913
|
});
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
1914
|
+
}
|
|
1915
|
+
clearEditVisibility(get().iframeDoc);
|
|
1916
|
+
if (!selectedItemSelector && selector.index !== void 0) {
|
|
1917
|
+
puckDispatch({
|
|
1918
|
+
type: "setUi",
|
|
1919
|
+
ui: { itemSelector: selector },
|
|
1920
|
+
recordHistory: false
|
|
1921
|
+
});
|
|
1922
|
+
}
|
|
1923
|
+
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
1924
|
+
state: "ready",
|
|
1925
|
+
setItemSelector: void 0,
|
|
1926
|
+
setOriginalItem: void 0,
|
|
1927
|
+
itemSelector: null,
|
|
1928
|
+
editingComponent: null,
|
|
1929
|
+
editingComponentId: null,
|
|
1930
|
+
editableComponentIds: /* @__PURE__ */ new Set()
|
|
1931
|
+
}));
|
|
2561
1932
|
});
|
|
2562
|
-
requestAnimationFrame(() => clearEditVisibility(get().iframeDoc));
|
|
2563
|
-
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2564
|
-
state: "ready",
|
|
2565
|
-
setItemSelector: void 0,
|
|
2566
|
-
setOriginalItem: void 0,
|
|
2567
|
-
editingComponent: null,
|
|
2568
|
-
editingComponentId: null,
|
|
2569
|
-
editableComponentIds: /* @__PURE__ */ new Set()
|
|
2570
|
-
}));
|
|
2571
1933
|
},
|
|
2572
|
-
cancel: (setHistories) => {
|
|
1934
|
+
cancel: (setHistories, puckDispatch, selectedItemSelector) => {
|
|
2573
1935
|
const storedHistories = get().originalHistory;
|
|
2574
|
-
|
|
2575
|
-
requestAnimationFrame(() => clearEditVisibility(get().iframeDoc));
|
|
1936
|
+
const itemSelector = get().itemSelector;
|
|
2576
1937
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2577
|
-
|
|
2578
|
-
storedConfig: void 0,
|
|
2579
|
-
originalHistory: [],
|
|
2580
|
-
itemSelector: null,
|
|
2581
|
-
originalItem: null,
|
|
2582
|
-
state: "ready",
|
|
2583
|
-
editingComponent: null,
|
|
2584
|
-
editingComponentId: null,
|
|
2585
|
-
editableComponentIds: /* @__PURE__ */ new Set()
|
|
1938
|
+
state: "cancelling"
|
|
2586
1939
|
}));
|
|
1940
|
+
setHistories([...storedHistories]);
|
|
1941
|
+
requestAnimationFrame(() => {
|
|
1942
|
+
clearEditVisibility(get().iframeDoc);
|
|
1943
|
+
if (!selectedItemSelector && itemSelector) {
|
|
1944
|
+
puckDispatch({
|
|
1945
|
+
type: "setUi",
|
|
1946
|
+
ui: { itemSelector },
|
|
1947
|
+
recordHistory: false
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
1951
|
+
originalHistory: [],
|
|
1952
|
+
itemSelector: null,
|
|
1953
|
+
originalItem: null,
|
|
1954
|
+
state: "ready",
|
|
1955
|
+
editingComponent: null,
|
|
1956
|
+
editingComponentId: null,
|
|
1957
|
+
editableComponentIds: /* @__PURE__ */ new Set(),
|
|
1958
|
+
editingDependents: /* @__PURE__ */ new Set()
|
|
1959
|
+
}));
|
|
1960
|
+
});
|
|
2587
1961
|
},
|
|
2588
1962
|
compose: (appState, componentName, editedItem, displayName, category) => {
|
|
2589
1963
|
if (!componentName) {
|
|
@@ -2628,11 +2002,16 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2628
2002
|
get().setSoftComponent(componentName, version, softComponent);
|
|
2629
2003
|
return [newSoftComponentConfig, version];
|
|
2630
2004
|
},
|
|
2631
|
-
decompose: (componentData) => {
|
|
2005
|
+
decompose: (componentData, keepMapField) => {
|
|
2632
2006
|
if (!(componentData == null ? void 0 : componentData.type) || !(componentData == null ? void 0 : componentData.props.id)) {
|
|
2633
2007
|
throw new Error("Component data must have type and id to decompose.");
|
|
2634
2008
|
}
|
|
2635
|
-
return decomposeSoftComponent(
|
|
2009
|
+
return decomposeSoftComponent(
|
|
2010
|
+
componentData,
|
|
2011
|
+
get().softComponents,
|
|
2012
|
+
void 0,
|
|
2013
|
+
keepMapField
|
|
2014
|
+
);
|
|
2636
2015
|
},
|
|
2637
2016
|
demolish: (componentName, data, puckDispatch) => {
|
|
2638
2017
|
if (get().state !== "ready") {
|
|
@@ -2653,7 +2032,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2653
2032
|
softConfig: result.config
|
|
2654
2033
|
}));
|
|
2655
2034
|
},
|
|
2656
|
-
setVersion: (componentName, newVersion, currentProps, puckDispatch) => {
|
|
2035
|
+
setVersion: (componentName, newVersion, currentProps, puckDispatch, getItemBySelector, getSelectorForId) => {
|
|
2657
2036
|
var _a;
|
|
2658
2037
|
if (get().state !== "remodeling") {
|
|
2659
2038
|
throw new Error("Can only switch versions during remodeling.");
|
|
@@ -2680,12 +2059,91 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2680
2059
|
softComponentMeta == null ? void 0 : softComponentMeta.category,
|
|
2681
2060
|
get().customFields
|
|
2682
2061
|
);
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2062
|
+
const editableIds = get().editableComponentIds;
|
|
2063
|
+
if (!editableIds || editableIds.size === 0) return;
|
|
2064
|
+
const firstId = Array.from(editableIds)[0];
|
|
2065
|
+
const itemSelector = getSelectorForId(firstId);
|
|
2066
|
+
if (!itemSelector) return;
|
|
2067
|
+
requestAnimationFrame(() => {
|
|
2068
|
+
const countToRemove = Array.from(editableIds).filter(
|
|
2069
|
+
(id) => {
|
|
2070
|
+
var _a2;
|
|
2071
|
+
return ((_a2 = getSelectorForId(id)) == null ? void 0 : _a2.zone) === itemSelector.zone;
|
|
2072
|
+
}
|
|
2073
|
+
).length;
|
|
2074
|
+
for (let i = 0; i < countToRemove; i++) {
|
|
2075
|
+
puckDispatch({
|
|
2076
|
+
type: "remove",
|
|
2077
|
+
index: itemSelector.index,
|
|
2078
|
+
zone: itemSelector.zone,
|
|
2079
|
+
recordHistory: false
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
const newContent = content || [];
|
|
2083
|
+
const comp = newContent[0];
|
|
2084
|
+
if (comp) {
|
|
2085
|
+
puckDispatch({
|
|
2086
|
+
type: "insert",
|
|
2087
|
+
destinationIndex: itemSelector.index,
|
|
2088
|
+
destinationZone: itemSelector.zone,
|
|
2089
|
+
componentType: comp.type,
|
|
2090
|
+
recordHistory: false
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
requestAnimationFrame(() => {
|
|
2094
|
+
if (comp) {
|
|
2095
|
+
const insertedItem = getItemBySelector({
|
|
2096
|
+
index: itemSelector.index,
|
|
2097
|
+
zone: itemSelector.zone
|
|
2098
|
+
});
|
|
2099
|
+
if (insertedItem) {
|
|
2100
|
+
puckDispatch({
|
|
2101
|
+
type: "replace",
|
|
2102
|
+
destinationIndex: itemSelector.index,
|
|
2103
|
+
destinationZone: itemSelector.zone,
|
|
2104
|
+
data: __spreadProps(__spreadValues({}, comp), {
|
|
2105
|
+
props: __spreadProps(__spreadValues({}, comp.props), {
|
|
2106
|
+
id: insertedItem.props.id
|
|
2107
|
+
})
|
|
2108
|
+
}),
|
|
2109
|
+
recordHistory: false
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
puckDispatch({
|
|
2114
|
+
type: "replaceRoot",
|
|
2115
|
+
root: {
|
|
2116
|
+
props: __spreadProps(__spreadValues({}, root.props), {
|
|
2117
|
+
_versions: versions
|
|
2118
|
+
})
|
|
2119
|
+
},
|
|
2120
|
+
recordHistory: false
|
|
2121
|
+
});
|
|
2122
|
+
requestAnimationFrame(() => {
|
|
2123
|
+
const newEditableIds = /* @__PURE__ */ new Set();
|
|
2124
|
+
if (comp) {
|
|
2125
|
+
const finalItem = getItemBySelector({
|
|
2126
|
+
index: itemSelector.index,
|
|
2127
|
+
zone: itemSelector.zone
|
|
2128
|
+
});
|
|
2129
|
+
if (finalItem) {
|
|
2130
|
+
walkTree2(
|
|
2131
|
+
{ root: {}, content: [finalItem] },
|
|
2132
|
+
{ components: get().softConfig.components },
|
|
2133
|
+
(components) => {
|
|
2134
|
+
components.forEach((c) => newEditableIds.add(c.props.id));
|
|
2135
|
+
return components;
|
|
2136
|
+
}
|
|
2137
|
+
);
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
set((s) => __spreadProps(__spreadValues({}, s), { editableComponentIds: newEditableIds }));
|
|
2141
|
+
setEditVisibility(get().iframeDoc, {
|
|
2142
|
+
mode: "remodel",
|
|
2143
|
+
editableIds: newEditableIds
|
|
2144
|
+
});
|
|
2145
|
+
});
|
|
2146
|
+
});
|
|
2689
2147
|
});
|
|
2690
2148
|
}
|
|
2691
2149
|
});
|
|
@@ -2902,7 +2360,7 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides, showV
|
|
|
2902
2360
|
}
|
|
2903
2361
|
|
|
2904
2362
|
// src/puck/store/index.tsx
|
|
2905
|
-
var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
|
|
2363
|
+
var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}, contentAreaNames) => {
|
|
2906
2364
|
const normalizedSoftComponents = Object.fromEntries(
|
|
2907
2365
|
Object.entries(softComponents || {}).filter(([key]) => !hardConfig.components || !hardConfig.components[key]).map(([key, value]) => [key, __spreadProps(__spreadValues({}, value), { name: value.name || key })])
|
|
2908
2366
|
);
|
|
@@ -2932,6 +2390,11 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
|
|
|
2932
2390
|
softComponents: hydratedSoftComponents,
|
|
2933
2391
|
dependencyGraph: initialDependencyGraph,
|
|
2934
2392
|
showVersionFields,
|
|
2393
|
+
contentAreaNames,
|
|
2394
|
+
setContentAreaNames: (names) => set({ contentAreaNames: names }),
|
|
2395
|
+
puckDispatch: null,
|
|
2396
|
+
setPuckDispatch: (dispatch) => set({ puckDispatch: dispatch }),
|
|
2397
|
+
rootActionHandler: rootActionHandler(set, get),
|
|
2935
2398
|
// ─── Initial softConfig ─────────────────────────────────────────────────
|
|
2936
2399
|
softConfig: __spreadProps(__spreadValues({}, hardConfig), {
|
|
2937
2400
|
components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
|
|
@@ -3203,7 +2666,7 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
|
|
|
3203
2666
|
})
|
|
3204
2667
|
})),
|
|
3205
2668
|
// ─── Builder Slice ────────────────────────────────────────────────────────
|
|
3206
|
-
builder: createBuildersSlice(set, get
|
|
2669
|
+
builder: createBuildersSlice(set, get),
|
|
3207
2670
|
// ─── Dependency Graph ─────────────────────────────────────────────────────
|
|
3208
2671
|
rebuildDependents: (componentName) => {
|
|
3209
2672
|
const state = get();
|
|
@@ -3236,8 +2699,39 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
|
|
|
3236
2699
|
};
|
|
3237
2700
|
|
|
3238
2701
|
// src/puck/context/storeProvider.tsx
|
|
3239
|
-
import { useEffect
|
|
3240
|
-
|
|
2702
|
+
import { useEffect, useMemo as useMemo2, useState } from "react";
|
|
2703
|
+
|
|
2704
|
+
// src/puck/context/useStore.ts
|
|
2705
|
+
import { createContext, useContext } from "react";
|
|
2706
|
+
import { useStore } from "zustand";
|
|
2707
|
+
var appStoreContext = createContext(null);
|
|
2708
|
+
var createUseSoftConfig = () => {
|
|
2709
|
+
return function useSoftConfig2(selector, equalityFn) {
|
|
2710
|
+
const context = useContext(appStoreContext);
|
|
2711
|
+
if (!context) {
|
|
2712
|
+
throw new Error(
|
|
2713
|
+
"useSoftConfig must be used inside a SoftConfigProvider. Wrap your tree with <SoftConfigProvider value={store}>"
|
|
2714
|
+
);
|
|
2715
|
+
}
|
|
2716
|
+
if (equalityFn) {
|
|
2717
|
+
return useStore(context, selector, equalityFn);
|
|
2718
|
+
}
|
|
2719
|
+
return useStore(context, selector);
|
|
2720
|
+
};
|
|
2721
|
+
};
|
|
2722
|
+
var useSoftConfig = createUseSoftConfig();
|
|
2723
|
+
var useSoftConfigStore = () => {
|
|
2724
|
+
const context = useContext(appStoreContext);
|
|
2725
|
+
if (!context) {
|
|
2726
|
+
throw new Error(
|
|
2727
|
+
"useSoftConfigStore must be used inside a SoftConfigProvider."
|
|
2728
|
+
);
|
|
2729
|
+
}
|
|
2730
|
+
return context;
|
|
2731
|
+
};
|
|
2732
|
+
|
|
2733
|
+
// src/puck/context/storeProvider.tsx
|
|
2734
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
3241
2735
|
var SoftConfigProvider = ({
|
|
3242
2736
|
children,
|
|
3243
2737
|
hardConfig,
|
|
@@ -3246,7 +2740,8 @@ var SoftConfigProvider = ({
|
|
|
3246
2740
|
overrides,
|
|
3247
2741
|
value,
|
|
3248
2742
|
onActions,
|
|
3249
|
-
useVersioning = false
|
|
2743
|
+
useVersioning = false,
|
|
2744
|
+
contentAreaNames
|
|
3250
2745
|
}) => {
|
|
3251
2746
|
const store = useMemo2(
|
|
3252
2747
|
() => value != null ? value : createSoftConfigStore(
|
|
@@ -3255,18 +2750,15 @@ var SoftConfigProvider = ({
|
|
|
3255
2750
|
overrides,
|
|
3256
2751
|
onActions,
|
|
3257
2752
|
useVersioning,
|
|
3258
|
-
customFields
|
|
2753
|
+
customFields,
|
|
2754
|
+
contentAreaNames
|
|
3259
2755
|
),
|
|
3260
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3261
2756
|
[value]
|
|
3262
|
-
// Intentionally omitting the rest: createSoftConfigStore params are
|
|
3263
|
-
// treated as initialisation-time values. If callers need to react to
|
|
3264
|
-
// prop changes they should pass a new `value` store instead.
|
|
3265
2757
|
);
|
|
3266
2758
|
const [softConfig, setSoftConfig] = useState(
|
|
3267
2759
|
() => store.getState().softConfig
|
|
3268
2760
|
);
|
|
3269
|
-
|
|
2761
|
+
useEffect(() => {
|
|
3270
2762
|
let prev = store.getState().softConfig;
|
|
3271
2763
|
const unsubscribe = store.subscribe((state) => {
|
|
3272
2764
|
if (state.softConfig !== prev) {
|
|
@@ -3276,17 +2768,17 @@ var SoftConfigProvider = ({
|
|
|
3276
2768
|
});
|
|
3277
2769
|
return unsubscribe;
|
|
3278
2770
|
}, [store]);
|
|
3279
|
-
return /* @__PURE__ */
|
|
2771
|
+
return /* @__PURE__ */ jsx4(appStoreContext.Provider, { value: store, children: children(softConfig) });
|
|
3280
2772
|
};
|
|
3281
2773
|
|
|
3282
2774
|
// src/puck/actions/useBuild.tsx
|
|
3283
|
-
import { createUsePuck
|
|
2775
|
+
import { createUsePuck } from "@measured/puck";
|
|
3284
2776
|
|
|
3285
2777
|
// src/puck/lib/notify.ts
|
|
3286
2778
|
var customHandler = null;
|
|
3287
2779
|
var defaultHandler = (message, type) => {
|
|
3288
2780
|
if (type === "error") {
|
|
3289
|
-
|
|
2781
|
+
alert(`[Error] ${message}`);
|
|
3290
2782
|
} else {
|
|
3291
2783
|
console.log(`[Success] ${message}`);
|
|
3292
2784
|
}
|
|
@@ -3325,13 +2817,13 @@ var useActionEvent = () => {
|
|
|
3325
2817
|
};
|
|
3326
2818
|
|
|
3327
2819
|
// src/puck/actions/useBuild.tsx
|
|
3328
|
-
var
|
|
2820
|
+
var useCustomPuck = createUsePuck();
|
|
3329
2821
|
var useBuild = (name) => {
|
|
3330
2822
|
const build = useSoftConfig((s) => s.builder.build);
|
|
3331
|
-
const history =
|
|
3332
|
-
const selectedItem =
|
|
3333
|
-
const itemSelector =
|
|
3334
|
-
const dispatch =
|
|
2823
|
+
const history = useCustomPuck((s) => s.history.histories);
|
|
2824
|
+
const selectedItem = useCustomPuck((s) => s.selectedItem);
|
|
2825
|
+
const itemSelector = useCustomPuck((s) => s.appState.ui.itemSelector);
|
|
2826
|
+
const dispatch = useCustomPuck((s) => s.dispatch);
|
|
3335
2827
|
const status = useSoftConfig((s) => s.state);
|
|
3336
2828
|
const { triggerAction } = useActionEvent();
|
|
3337
2829
|
const handleBuild = () => {
|
|
@@ -3350,7 +2842,7 @@ var useBuild = (name) => {
|
|
|
3350
2842
|
});
|
|
3351
2843
|
}
|
|
3352
2844
|
} catch (error) {
|
|
3353
|
-
|
|
2845
|
+
alert("Failed to build: " + error);
|
|
3354
2846
|
notify.error(
|
|
3355
2847
|
"Failed to build: " + (error instanceof Error ? error.message : String(error))
|
|
3356
2848
|
);
|
|
@@ -3360,17 +2852,17 @@ var useBuild = (name) => {
|
|
|
3360
2852
|
};
|
|
3361
2853
|
|
|
3362
2854
|
// src/puck/actions/useRemodel.tsx
|
|
3363
|
-
import { createUsePuck as
|
|
3364
|
-
var
|
|
2855
|
+
import { createUsePuck as createUsePuck2 } from "@measured/puck";
|
|
2856
|
+
var useCustomPuck2 = createUsePuck2();
|
|
3365
2857
|
var useRemodel = () => {
|
|
3366
2858
|
const remodel = useSoftConfig((s) => s.builder.remodel);
|
|
3367
|
-
const history =
|
|
3368
|
-
const selectedItem =
|
|
3369
|
-
const itemSelector =
|
|
3370
|
-
const dispatch =
|
|
2859
|
+
const history = useCustomPuck2((s) => s.history.histories);
|
|
2860
|
+
const selectedItem = useCustomPuck2((s) => s.selectedItem);
|
|
2861
|
+
const itemSelector = useCustomPuck2((s) => s.appState.ui.itemSelector);
|
|
2862
|
+
const dispatch = useCustomPuck2((s) => s.dispatch);
|
|
3371
2863
|
const status = useSoftConfig((s) => s.state);
|
|
3372
2864
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
3373
|
-
const refreshPermissions =
|
|
2865
|
+
const refreshPermissions = useCustomPuck2((s) => s.refreshPermissions);
|
|
3374
2866
|
const { triggerAction } = useActionEvent();
|
|
3375
2867
|
const handleRemodel = (componentName) => {
|
|
3376
2868
|
var _a, _b, _c;
|
|
@@ -3386,7 +2878,13 @@ var useRemodel = () => {
|
|
|
3386
2878
|
const selectedVersion = ((_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.version) || ((_b = softComponents[name]) == null ? void 0 : _b.defaultVersion);
|
|
3387
2879
|
const selectedSoftComponent = selectedVersion ? (_c = softComponents[name]) == null ? void 0 : _c.versions[selectedVersion] : void 0;
|
|
3388
2880
|
try {
|
|
3389
|
-
remodel(
|
|
2881
|
+
remodel(
|
|
2882
|
+
history,
|
|
2883
|
+
selectedItem,
|
|
2884
|
+
itemSelector,
|
|
2885
|
+
dispatch,
|
|
2886
|
+
refreshPermissions
|
|
2887
|
+
);
|
|
3390
2888
|
void triggerAction({
|
|
3391
2889
|
type: "remodel",
|
|
3392
2890
|
payload: {
|
|
@@ -3404,9 +2902,9 @@ var useRemodel = () => {
|
|
|
3404
2902
|
}
|
|
3405
2903
|
return { id: name, version: selectedVersion };
|
|
3406
2904
|
} catch (error) {
|
|
3407
|
-
|
|
2905
|
+
alert("Failed to remodel: " + error);
|
|
3408
2906
|
notify.error(
|
|
3409
|
-
"Failed to remodel: " + (error instanceof Error ? error.message : String(error))
|
|
2907
|
+
"Failed to remodel: " + (error instanceof Error ? error.message : String(error)) + " " + String()
|
|
3410
2908
|
);
|
|
3411
2909
|
return null;
|
|
3412
2910
|
}
|
|
@@ -3419,14 +2917,14 @@ var useRemodel = () => {
|
|
|
3419
2917
|
};
|
|
3420
2918
|
|
|
3421
2919
|
// src/puck/actions/useComplete.tsx
|
|
3422
|
-
import { createUsePuck as
|
|
2920
|
+
import { createUsePuck as createUsePuck3 } from "@measured/puck";
|
|
3423
2921
|
import { useState as useState2, useCallback as useCallback2 } from "react";
|
|
3424
|
-
var
|
|
2922
|
+
var useCustomPuck3 = createUsePuck3();
|
|
3425
2923
|
var useComplete = () => {
|
|
3426
2924
|
const complete = useSoftConfig((s) => s.builder.complete);
|
|
3427
|
-
const appState =
|
|
3428
|
-
const setHistories =
|
|
3429
|
-
const getItemBySelector =
|
|
2925
|
+
const appState = useCustomPuck3((s) => s.appState);
|
|
2926
|
+
const setHistories = useCustomPuck3((s) => s.history.setHistories);
|
|
2927
|
+
const getItemBySelector = useCustomPuck3((s) => s.getItemBySelector);
|
|
3430
2928
|
const status = useSoftConfig((s) => s.state);
|
|
3431
2929
|
const [newComponent, setNewComponent] = useState2(null);
|
|
3432
2930
|
const { triggerAction } = useActionEvent();
|
|
@@ -3464,11 +2962,13 @@ var useComplete = () => {
|
|
|
3464
2962
|
};
|
|
3465
2963
|
|
|
3466
2964
|
// src/puck/actions/useCancel.tsx
|
|
3467
|
-
import { createUsePuck as
|
|
3468
|
-
var
|
|
2965
|
+
import { createUsePuck as createUsePuck4 } from "@measured/puck";
|
|
2966
|
+
var useCustomPuck4 = createUsePuck4();
|
|
3469
2967
|
var useCancel = () => {
|
|
3470
2968
|
const cancel = useSoftConfig((s) => s.builder.cancel);
|
|
3471
|
-
const setHistories =
|
|
2969
|
+
const setHistories = useCustomPuck4((s) => s.history.setHistories);
|
|
2970
|
+
const puckDispatch = useCustomPuck4((s) => s.dispatch);
|
|
2971
|
+
const selectedItemSelector = useCustomPuck4((s) => s.appState.ui.itemSelector);
|
|
3472
2972
|
const status = useSoftConfig((s) => s.state);
|
|
3473
2973
|
const { triggerAction } = useActionEvent();
|
|
3474
2974
|
const handleCancel = () => {
|
|
@@ -3477,13 +2977,13 @@ var useCancel = () => {
|
|
|
3477
2977
|
return;
|
|
3478
2978
|
}
|
|
3479
2979
|
try {
|
|
3480
|
-
cancel(setHistories);
|
|
2980
|
+
cancel(setHistories, puckDispatch, selectedItemSelector);
|
|
3481
2981
|
void triggerAction({
|
|
3482
2982
|
type: "cancel",
|
|
3483
2983
|
payload: {}
|
|
3484
2984
|
});
|
|
3485
2985
|
} catch (error) {
|
|
3486
|
-
|
|
2986
|
+
alert("Failed to cancel: " + error);
|
|
3487
2987
|
notify.error(
|
|
3488
2988
|
"Failed to cancel: " + (error instanceof Error ? error.message : String(error))
|
|
3489
2989
|
);
|
|
@@ -3494,22 +2994,22 @@ var useCancel = () => {
|
|
|
3494
2994
|
};
|
|
3495
2995
|
|
|
3496
2996
|
// src/puck/actions/useInspect.tsx
|
|
3497
|
-
import { createUsePuck as
|
|
3498
|
-
import { useEffect as
|
|
3499
|
-
var
|
|
2997
|
+
import { createUsePuck as createUsePuck5 } from "@measured/puck";
|
|
2998
|
+
import { useEffect as useEffect2 } from "react";
|
|
2999
|
+
var useCustomPuck5 = createUsePuck5();
|
|
3500
3000
|
var useInspect = (component) => {
|
|
3501
3001
|
const inspect = useSoftConfig((s) => s.builder.inspect);
|
|
3502
|
-
const dispatch =
|
|
3002
|
+
const dispatch = useCustomPuck5((s) => s.dispatch);
|
|
3503
3003
|
const status = useSoftConfig((s) => s.state);
|
|
3504
3004
|
const { triggerAction } = useActionEvent();
|
|
3505
|
-
|
|
3005
|
+
useEffect2(() => {
|
|
3506
3006
|
if (status !== "inspecting") return;
|
|
3507
3007
|
if (!component) {
|
|
3508
3008
|
notify.error("No component to inspect.");
|
|
3509
3009
|
return;
|
|
3510
3010
|
}
|
|
3511
3011
|
try {
|
|
3512
|
-
inspect(component.id, dispatch);
|
|
3012
|
+
inspect(component.id, dispatch, null);
|
|
3513
3013
|
void triggerAction({
|
|
3514
3014
|
type: "inspect",
|
|
3515
3015
|
payload: {
|
|
@@ -3528,16 +3028,24 @@ var useInspect = (component) => {
|
|
|
3528
3028
|
};
|
|
3529
3029
|
|
|
3530
3030
|
// src/puck/actions/useDecompose.tsx
|
|
3531
|
-
import { createUsePuck as
|
|
3532
|
-
|
|
3031
|
+
import { createUsePuck as createUsePuck6, walkTree as walkTree3 } from "@measured/puck";
|
|
3032
|
+
|
|
3033
|
+
// src/puck/lib/get-prop-by-path.ts
|
|
3034
|
+
function getPropertyByPath(props, path) {
|
|
3035
|
+
return path.replace(/\[(\w+)\]/g, ".$1").split(".").reduce((o, key) => o ? o[key] : void 0, props);
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
// src/puck/actions/useDecompose.tsx
|
|
3039
|
+
var useCustomPuck6 = createUsePuck6();
|
|
3533
3040
|
var useDecompose = () => {
|
|
3534
3041
|
const decompose = useSoftConfig((s) => s.builder.decompose);
|
|
3535
|
-
const appState =
|
|
3536
|
-
const dispatch =
|
|
3537
|
-
const selectedItem =
|
|
3042
|
+
const appState = useCustomPuck6((s) => s.appState);
|
|
3043
|
+
const dispatch = useCustomPuck6((s) => s.dispatch);
|
|
3044
|
+
const selectedItem = useCustomPuck6((s) => s.selectedItem);
|
|
3538
3045
|
const status = useSoftConfig((s) => s.state);
|
|
3539
3046
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
3540
3047
|
const config = useSoftConfig((s) => s.softConfig);
|
|
3048
|
+
const contentAreaNames = useSoftConfig((s) => s.contentAreaNames);
|
|
3541
3049
|
const { triggerAction } = useActionEvent();
|
|
3542
3050
|
const handleDecompose = (componentData) => {
|
|
3543
3051
|
if (status !== "ready") {
|
|
@@ -3560,12 +3068,22 @@ var useDecompose = () => {
|
|
|
3560
3068
|
notify.error("Nothing to decompose.");
|
|
3561
3069
|
return;
|
|
3562
3070
|
}
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3071
|
+
let newData = __spreadValues({}, appState.data);
|
|
3072
|
+
const targetAreas = contentAreaNames && contentAreaNames.length > 0 ? contentAreaNames : ["content"];
|
|
3073
|
+
targetAreas.forEach((path) => {
|
|
3074
|
+
const contentArray = getPropertyByPath(newData, path) || [];
|
|
3075
|
+
const walkedData = walkTree3(
|
|
3076
|
+
{ content: contentArray, root: newData.root || {} },
|
|
3077
|
+
config,
|
|
3078
|
+
(components) => {
|
|
3079
|
+
const index = components.findIndex((c) => c.props.id === target.props.id);
|
|
3080
|
+
if (index !== -1) {
|
|
3081
|
+
components.splice(index, 1, ...decomposedComponents);
|
|
3082
|
+
}
|
|
3083
|
+
return components;
|
|
3084
|
+
}
|
|
3085
|
+
);
|
|
3086
|
+
setPropertyByPath(newData, path, walkedData.content);
|
|
3569
3087
|
});
|
|
3570
3088
|
dispatch({
|
|
3571
3089
|
type: "setData",
|
|
@@ -3578,7 +3096,7 @@ var useDecompose = () => {
|
|
|
3578
3096
|
}
|
|
3579
3097
|
});
|
|
3580
3098
|
} catch (error) {
|
|
3581
|
-
|
|
3099
|
+
alert("Failed to decompose: " + error);
|
|
3582
3100
|
notify.error(
|
|
3583
3101
|
"Failed to decompose: " + (error instanceof Error ? error.message : String(error))
|
|
3584
3102
|
);
|
|
@@ -3592,12 +3110,12 @@ var useDecompose = () => {
|
|
|
3592
3110
|
};
|
|
3593
3111
|
|
|
3594
3112
|
// src/puck/actions/useDemolish.tsx
|
|
3595
|
-
import { createUsePuck as
|
|
3596
|
-
var
|
|
3113
|
+
import { createUsePuck as createUsePuck7 } from "@measured/puck";
|
|
3114
|
+
var useCustomPuck7 = createUsePuck7();
|
|
3597
3115
|
var useDemolish = () => {
|
|
3598
3116
|
const demolish = useSoftConfig((s) => s.builder.demolish);
|
|
3599
|
-
const dispatch =
|
|
3600
|
-
const data =
|
|
3117
|
+
const dispatch = useCustomPuck7((s) => s.dispatch);
|
|
3118
|
+
const data = useCustomPuck7((s) => s.appState.data);
|
|
3601
3119
|
const status = useSoftConfig((s) => s.state);
|
|
3602
3120
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
3603
3121
|
const { triggerAction } = useActionEvent();
|
|
@@ -3619,7 +3137,7 @@ var useDemolish = () => {
|
|
|
3619
3137
|
}
|
|
3620
3138
|
});
|
|
3621
3139
|
} catch (error) {
|
|
3622
|
-
|
|
3140
|
+
alert("Failed to demolish: " + error);
|
|
3623
3141
|
notify.error(
|
|
3624
3142
|
"Failed to demolish: " + (error instanceof Error ? error.message : String(error))
|
|
3625
3143
|
);
|
|
@@ -3680,17 +3198,17 @@ var useSetDefaultVersion = () => {
|
|
|
3680
3198
|
};
|
|
3681
3199
|
|
|
3682
3200
|
// src/puck/overrides/Header.tsx
|
|
3683
|
-
import { Button
|
|
3201
|
+
import { Button } from "@measured/puck";
|
|
3684
3202
|
|
|
3685
3203
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Header.module.css#css-module
|
|
3686
3204
|
var Header_module_default = { "Header": "_Header_19oj9_1" };
|
|
3687
3205
|
|
|
3688
3206
|
// src/puck/actions/usePublish.tsx
|
|
3689
|
-
import { createUsePuck as
|
|
3690
|
-
var
|
|
3207
|
+
import { createUsePuck as createUsePuck8 } from "@measured/puck";
|
|
3208
|
+
var useCustomPuck8 = createUsePuck8();
|
|
3691
3209
|
var usePublish = () => {
|
|
3692
3210
|
const components = useSoftConfig((s) => s.softComponents);
|
|
3693
|
-
const data =
|
|
3211
|
+
const data = useCustomPuck8((s) => s.appState.data);
|
|
3694
3212
|
const status = useSoftConfig((s) => s.state);
|
|
3695
3213
|
const { triggerAction } = useActionEvent();
|
|
3696
3214
|
const handlePublish = (publish) => {
|
|
@@ -3721,9 +3239,8 @@ var usePublish = () => {
|
|
|
3721
3239
|
};
|
|
3722
3240
|
|
|
3723
3241
|
// src/puck/overrides/Header.tsx
|
|
3724
|
-
import { Fragment as
|
|
3242
|
+
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
3725
3243
|
var getClassName2 = get_class_name_factory_default("Header", Header_module_default);
|
|
3726
|
-
var usePuck = createUsePuck10();
|
|
3727
3244
|
var Header = ({
|
|
3728
3245
|
onPublish,
|
|
3729
3246
|
children
|
|
@@ -3732,9 +3249,9 @@ var Header = ({
|
|
|
3732
3249
|
const { handleCancel, canCancel } = useCancel();
|
|
3733
3250
|
const { handlePublish } = usePublish();
|
|
3734
3251
|
useInspect(newComponent);
|
|
3735
|
-
return /* @__PURE__ */
|
|
3736
|
-
/* @__PURE__ */
|
|
3737
|
-
/* @__PURE__ */
|
|
3252
|
+
return /* @__PURE__ */ jsx5("div", { className: getClassName2(), children: canCancel ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
3253
|
+
/* @__PURE__ */ jsx5(Button, { onClick: handleCancel, children: "Cancel" }),
|
|
3254
|
+
/* @__PURE__ */ jsx5(
|
|
3738
3255
|
Button,
|
|
3739
3256
|
{
|
|
3740
3257
|
variant: "primary",
|
|
@@ -3747,7 +3264,7 @@ var Header = ({
|
|
|
3747
3264
|
children: "Complete"
|
|
3748
3265
|
}
|
|
3749
3266
|
)
|
|
3750
|
-
] }) : children ? children : /* @__PURE__ */
|
|
3267
|
+
] }) : children ? children : /* @__PURE__ */ jsx5(
|
|
3751
3268
|
Button,
|
|
3752
3269
|
{
|
|
3753
3270
|
variant: "primary",
|
|
@@ -3763,7 +3280,7 @@ var Header = ({
|
|
|
3763
3280
|
|
|
3764
3281
|
// src/puck/overrides/ActionBar.tsx
|
|
3765
3282
|
import { useMemo as useMemo3 } from "react";
|
|
3766
|
-
import { ActionBar, createUsePuck as
|
|
3283
|
+
import { ActionBar, createUsePuck as createUsePuck10 } from "@measured/puck";
|
|
3767
3284
|
import { Combine, ComponentIcon, EditIcon } from "lucide-react";
|
|
3768
3285
|
|
|
3769
3286
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
|
|
@@ -3771,9 +3288,9 @@ var ActionBar_module_default = { "ActionBar": "_ActionBar_pvuie_5", "ActionBar-l
|
|
|
3771
3288
|
|
|
3772
3289
|
// src/puck/overrides/ActionBar.tsx
|
|
3773
3290
|
import { shallow } from "zustand/shallow";
|
|
3774
|
-
import { Fragment as
|
|
3291
|
+
import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
3292
|
+
var useCustomPuck9 = createUsePuck10();
|
|
3775
3293
|
var getClassName3 = get_class_name_factory_default("ActionBar", ActionBar_module_default);
|
|
3776
|
-
var usePuck2 = createUsePuck11();
|
|
3777
3294
|
var ActionBarOverride = (props) => {
|
|
3778
3295
|
var _a, _b;
|
|
3779
3296
|
const { handleBuild } = useBuild(props.label ? props.label + " Soft Component" : "New Soft Component");
|
|
@@ -3782,10 +3299,11 @@ var ActionBarOverride = (props) => {
|
|
|
3782
3299
|
const overrides = useSoftConfig((s) => s.overrides);
|
|
3783
3300
|
const softComponents = useSoftConfig((s) => s.softComponents, shallow);
|
|
3784
3301
|
const editableIds = useSoftConfig((s) => s.editableComponentIds);
|
|
3785
|
-
const selectedItem =
|
|
3786
|
-
const
|
|
3302
|
+
const selectedItem = useCustomPuck9((s) => s.selectedItem);
|
|
3303
|
+
const appState = useCustomPuck9((s) => s.appState);
|
|
3304
|
+
const rootProps = appState.data.root.props;
|
|
3787
3305
|
const status = useSoftConfig((s) => s.state);
|
|
3788
|
-
const itemSelector =
|
|
3306
|
+
const itemSelector = appState.ui.itemSelector;
|
|
3789
3307
|
const softKeys = Object.keys(softComponents);
|
|
3790
3308
|
const key = useMemo3(() => {
|
|
3791
3309
|
const selectedType = selectedItem == null ? void 0 : selectedItem.type;
|
|
@@ -3815,35 +3333,35 @@ var ActionBarOverride = (props) => {
|
|
|
3815
3333
|
}
|
|
3816
3334
|
return props.label || "";
|
|
3817
3335
|
}, [isSoftComponent2, key, props.label, overrides, softComponents]);
|
|
3818
|
-
return /* @__PURE__ */
|
|
3336
|
+
return /* @__PURE__ */ jsx6("div", { className: getClassName3(), children: /* @__PURE__ */ jsxs3(ActionBar, { children: [
|
|
3819
3337
|
/* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
|
|
3820
3338
|
props.parentAction,
|
|
3821
|
-
/* @__PURE__ */
|
|
3339
|
+
/* @__PURE__ */ jsx6(ActionBar.Label, { label })
|
|
3822
3340
|
] }),
|
|
3823
3341
|
/* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
|
|
3824
|
-
status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ jsxs3(
|
|
3825
|
-
/* @__PURE__ */
|
|
3342
|
+
status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
3343
|
+
/* @__PURE__ */ jsx6(
|
|
3826
3344
|
ActionBar.Action,
|
|
3827
3345
|
{
|
|
3828
3346
|
onClick: () => handleRemodel(key),
|
|
3829
3347
|
label: "Remodel Soft Component",
|
|
3830
|
-
children: /* @__PURE__ */
|
|
3348
|
+
children: /* @__PURE__ */ jsx6(EditIcon, { size: 16 })
|
|
3831
3349
|
}
|
|
3832
3350
|
),
|
|
3833
|
-
/* @__PURE__ */
|
|
3351
|
+
/* @__PURE__ */ jsx6(
|
|
3834
3352
|
ActionBar.Action,
|
|
3835
3353
|
{
|
|
3836
3354
|
onClick: () => handleDecompose(),
|
|
3837
3355
|
label: "Decompose Soft Component",
|
|
3838
|
-
children: /* @__PURE__ */
|
|
3356
|
+
children: /* @__PURE__ */ jsx6(Combine, { size: 16 })
|
|
3839
3357
|
}
|
|
3840
3358
|
)
|
|
3841
|
-
] }) : /* @__PURE__ */
|
|
3359
|
+
] }) : /* @__PURE__ */ jsx6(
|
|
3842
3360
|
ActionBar.Action,
|
|
3843
3361
|
{
|
|
3844
3362
|
onClick: handleBuild,
|
|
3845
3363
|
label: "Build Soft Component",
|
|
3846
|
-
children: /* @__PURE__ */
|
|
3364
|
+
children: /* @__PURE__ */ jsx6(ComponentIcon, { size: 16 })
|
|
3847
3365
|
}
|
|
3848
3366
|
) : null,
|
|
3849
3367
|
status !== "ready" && !isEditable ? null : props.children
|
|
@@ -3853,7 +3371,7 @@ var ActionBarOverride = (props) => {
|
|
|
3853
3371
|
|
|
3854
3372
|
// src/puck/overrides/DrawerItem.tsx
|
|
3855
3373
|
import { useState as useState4 } from "react";
|
|
3856
|
-
import { Button as Button2, IconButton, createUsePuck as
|
|
3374
|
+
import { Button as Button2, IconButton, createUsePuck as createUsePuck11 } from "@measured/puck";
|
|
3857
3375
|
import { GripVertical, Check, X, Trash2, Cog } from "lucide-react";
|
|
3858
3376
|
|
|
3859
3377
|
// src/puck/lib/confirm.ts
|
|
@@ -3868,7 +3386,7 @@ var confirm = (message) => __async(null, null, function* () {
|
|
|
3868
3386
|
const result = confirmHandler(message);
|
|
3869
3387
|
return result instanceof Promise ? yield result : result;
|
|
3870
3388
|
} catch (error) {
|
|
3871
|
-
|
|
3389
|
+
alert("Confirm handler error: " + error);
|
|
3872
3390
|
return false;
|
|
3873
3391
|
}
|
|
3874
3392
|
});
|
|
@@ -3877,14 +3395,14 @@ var confirm = (message) => __async(null, null, function* () {
|
|
|
3877
3395
|
var DrawerItem_module_default = { "DrawerItem": "_DrawerItem_182aj_1", "DrawerItem--insertDisabled": "_DrawerItem--insertDisabled_182aj_14", "DrawerItem-content": "_DrawerItem-content_182aj_21", "DrawerItem-name": "_DrawerItem-name_182aj_31", "DrawerItem-version": "_DrawerItem-version_182aj_35", "DrawerItem-actions": "_DrawerItem-actions_182aj_40", "DrawerItem-settingsButton": "_DrawerItem-settingsButton_182aj_46", "DrawerItem-grip": "_DrawerItem-grip_182aj_56", "DrawerItem-modal": "_DrawerItem-modal_182aj_63", "DrawerItem-modalHeader": "_DrawerItem-modalHeader_182aj_71", "DrawerItem-modalTitle": "_DrawerItem-modalTitle_182aj_77", "DrawerItem-modalSubtitle": "_DrawerItem-modalSubtitle_182aj_84", "DrawerItem-modalBody": "_DrawerItem-modalBody_182aj_90", "DrawerItem-section": "_DrawerItem-section_182aj_100", "DrawerItem-sectionTitle": "_DrawerItem-sectionTitle_182aj_106", "DrawerItem-sectionDescription": "_DrawerItem-sectionDescription_182aj_113", "DrawerItem-versionList": "_DrawerItem-versionList_182aj_119", "DrawerItem-versionRow": "_DrawerItem-versionRow_182aj_125", "DrawerItem-versionRow--isDefault": "_DrawerItem-versionRow--isDefault_182aj_136", "DrawerItem-versionRow--isMarkedForDeletion": "_DrawerItem-versionRow--isMarkedForDeletion_182aj_141", "DrawerItem-versionInfo": "_DrawerItem-versionInfo_182aj_146", "DrawerItem-versionNumber": "_DrawerItem-versionNumber_182aj_153", "DrawerItem-defaultBadge": "_DrawerItem-defaultBadge_182aj_159", "DrawerItem-deleteBadge": "_DrawerItem-deleteBadge_182aj_170", "DrawerItem-versionActions": "_DrawerItem-versionActions_182aj_181", "DrawerItem-migrationOptions": "_DrawerItem-migrationOptions_182aj_187", "DrawerItem-migrationList": "_DrawerItem-migrationList_182aj_191", "DrawerItem-migrationOption": "_DrawerItem-migrationOption_182aj_187", "DrawerItem-migrationOption--isSelected": "_DrawerItem-migrationOption--isSelected_182aj_229", "DrawerItem-migrationOptionLabel": "_DrawerItem-migrationOptionLabel_182aj_234", "DrawerItem-modalFooter": "_DrawerItem-modalFooter_182aj_240", "DrawerItem-footerLeft": "_DrawerItem-footerLeft_182aj_250", "DrawerItem-footerRight": "_DrawerItem-footerRight_182aj_255" };
|
|
3878
3396
|
|
|
3879
3397
|
// src/puck/components/modal/index.tsx
|
|
3880
|
-
import { useEffect as
|
|
3398
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
3881
3399
|
import { createPortal } from "react-dom";
|
|
3882
3400
|
|
|
3883
3401
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
|
|
3884
3402
|
var styles_module_default2 = { "Modal": "_Modal_1t9ot_1", "Modal--isOpen": "_Modal--isOpen_1t9ot_29", "Modal-inner": "_Modal-inner_1t9ot_37" };
|
|
3885
3403
|
|
|
3886
3404
|
// src/puck/components/modal/index.tsx
|
|
3887
|
-
import { jsx as
|
|
3405
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
3888
3406
|
var getClassName4 = get_class_name_factory_default("Modal", styles_module_default2);
|
|
3889
3407
|
var Modal = ({
|
|
3890
3408
|
children,
|
|
@@ -3892,10 +3410,10 @@ var Modal = ({
|
|
|
3892
3410
|
isOpen
|
|
3893
3411
|
}) => {
|
|
3894
3412
|
const [rootEl, setRootEl] = useState3(null);
|
|
3895
|
-
|
|
3413
|
+
useEffect3(() => {
|
|
3896
3414
|
setRootEl(document.getElementById("puck-portal-root"));
|
|
3897
3415
|
}, []);
|
|
3898
|
-
|
|
3416
|
+
useEffect3(() => {
|
|
3899
3417
|
if (!isOpen) {
|
|
3900
3418
|
return;
|
|
3901
3419
|
}
|
|
@@ -3908,10 +3426,10 @@ var Modal = ({
|
|
|
3908
3426
|
return () => document.removeEventListener("keydown", handleEscape);
|
|
3909
3427
|
}, [isOpen, onClose]);
|
|
3910
3428
|
if (!rootEl) {
|
|
3911
|
-
return /* @__PURE__ */
|
|
3429
|
+
return /* @__PURE__ */ jsx7("div", {});
|
|
3912
3430
|
}
|
|
3913
3431
|
return createPortal(
|
|
3914
|
-
/* @__PURE__ */
|
|
3432
|
+
/* @__PURE__ */ jsx7(
|
|
3915
3433
|
"div",
|
|
3916
3434
|
{
|
|
3917
3435
|
className: getClassName4({ isOpen }),
|
|
@@ -3920,7 +3438,7 @@ var Modal = ({
|
|
|
3920
3438
|
onClose();
|
|
3921
3439
|
}
|
|
3922
3440
|
},
|
|
3923
|
-
children: /* @__PURE__ */
|
|
3441
|
+
children: /* @__PURE__ */ jsx7(
|
|
3924
3442
|
"div",
|
|
3925
3443
|
{
|
|
3926
3444
|
className: getClassName4("inner"),
|
|
@@ -3938,16 +3456,16 @@ var Modal = ({
|
|
|
3938
3456
|
|
|
3939
3457
|
// src/puck/overrides/DrawerItem.tsx
|
|
3940
3458
|
import { shallow as shallow2 } from "zustand/shallow";
|
|
3941
|
-
import { Fragment as
|
|
3459
|
+
import { Fragment as Fragment4, jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
3460
|
+
var useCustomPuck10 = createUsePuck11();
|
|
3942
3461
|
var getClassName5 = get_class_name_factory_default("DrawerItem", DrawerItem_module_default);
|
|
3943
|
-
var usePuck3 = createUsePuck12();
|
|
3944
3462
|
var DrawerItem = (props) => {
|
|
3945
3463
|
const componentMeta = useSoftConfig((s) => s.softComponents[props.name]);
|
|
3946
3464
|
const displayName = props.label || (componentMeta == null ? void 0 : componentMeta.name) || props.name;
|
|
3947
3465
|
const softComponents = new Set(
|
|
3948
3466
|
Object.keys(useSoftConfig((s) => s.softComponents, shallow2))
|
|
3949
3467
|
);
|
|
3950
|
-
const getPermissions =
|
|
3468
|
+
const getPermissions = useCustomPuck10((s) => s.getPermissions);
|
|
3951
3469
|
const insertAllowed = getPermissions({ type: props.name }).insert;
|
|
3952
3470
|
const removeSoftComponentVersion = useSoftConfig(
|
|
3953
3471
|
(s) => s.removeSoftComponentVersion
|
|
@@ -4031,7 +3549,7 @@ var DrawerItem = (props) => {
|
|
|
4031
3549
|
label: `Migrate to Version ${version}`
|
|
4032
3550
|
}))
|
|
4033
3551
|
];
|
|
4034
|
-
return /* @__PURE__ */ jsxs4(
|
|
3552
|
+
return /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
4035
3553
|
/* @__PURE__ */ jsxs4(
|
|
4036
3554
|
"div",
|
|
4037
3555
|
{
|
|
@@ -4041,40 +3559,39 @@ var DrawerItem = (props) => {
|
|
|
4041
3559
|
children: [
|
|
4042
3560
|
props.label,
|
|
4043
3561
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("content"), children: [
|
|
4044
|
-
/* @__PURE__ */
|
|
3562
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("name"), children: displayName }),
|
|
4045
3563
|
useVersioning && /* @__PURE__ */ jsxs4("div", { className: getClassName5("version"), children: [
|
|
4046
3564
|
"v",
|
|
4047
3565
|
defaultVersion
|
|
4048
3566
|
] })
|
|
4049
3567
|
] }),
|
|
4050
3568
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("actions"), children: [
|
|
4051
|
-
isHovering && /* @__PURE__ */
|
|
3569
|
+
isHovering && /* @__PURE__ */ jsx8("div", { className: getClassName5("settingsButton"), children: /* @__PURE__ */ jsx8(
|
|
4052
3570
|
IconButton,
|
|
4053
3571
|
{
|
|
4054
3572
|
title: "Settings",
|
|
4055
|
-
variant: "secondary",
|
|
4056
3573
|
onClick: (e) => {
|
|
4057
3574
|
e.stopPropagation();
|
|
4058
3575
|
setIsEditing(true);
|
|
4059
3576
|
setSelectedVersion(defaultVersion || "");
|
|
4060
3577
|
},
|
|
4061
|
-
children: /* @__PURE__ */
|
|
3578
|
+
children: /* @__PURE__ */ jsx8(Cog, { size: 12 })
|
|
4062
3579
|
}
|
|
4063
3580
|
) }),
|
|
4064
|
-
/* @__PURE__ */
|
|
3581
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("grip"), children: /* @__PURE__ */ jsx8(GripVertical, { size: 16 }) })
|
|
4065
3582
|
] })
|
|
4066
3583
|
]
|
|
4067
3584
|
}
|
|
4068
3585
|
),
|
|
4069
|
-
/* @__PURE__ */
|
|
3586
|
+
/* @__PURE__ */ jsx8(Modal, { isOpen: isEditing, onClose: handleCancel, children: /* @__PURE__ */ jsxs4("div", { className: getClassName5("modal"), children: [
|
|
4070
3587
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("modalHeader"), children: [
|
|
4071
|
-
/* @__PURE__ */
|
|
4072
|
-
/* @__PURE__ */
|
|
3588
|
+
/* @__PURE__ */ jsx8("h2", { className: getClassName5("modalTitle"), children: displayName }),
|
|
3589
|
+
/* @__PURE__ */ jsx8("p", { className: getClassName5("modalSubtitle"), children: "Component Settings" })
|
|
4073
3590
|
] }),
|
|
4074
|
-
/* @__PURE__ */
|
|
3591
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("modalBody"), children: useVersioning ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
4075
3592
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("section"), children: [
|
|
4076
|
-
/* @__PURE__ */
|
|
4077
|
-
/* @__PURE__ */
|
|
3593
|
+
/* @__PURE__ */ jsx8("h3", { className: getClassName5("sectionTitle"), children: "Versions" }),
|
|
3594
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("versionList"), children: versions.map((version) => {
|
|
4078
3595
|
const isDefault = version === (selectedVersion || defaultVersion);
|
|
4079
3596
|
const isMarkedForDeletion = versionsToDelete.has(version);
|
|
4080
3597
|
let rowClass = getClassName5("versionRow");
|
|
@@ -4086,16 +3603,16 @@ var DrawerItem = (props) => {
|
|
|
4086
3603
|
"Version ",
|
|
4087
3604
|
version
|
|
4088
3605
|
] }),
|
|
4089
|
-
isDefault && /* @__PURE__ */
|
|
4090
|
-
isMarkedForDeletion && /* @__PURE__ */
|
|
3606
|
+
isDefault && /* @__PURE__ */ jsx8("span", { className: getClassName5("defaultBadge"), children: "Default" }),
|
|
3607
|
+
isMarkedForDeletion && /* @__PURE__ */ jsx8("span", { className: getClassName5("deleteBadge"), children: "Marked for deletion" })
|
|
4091
3608
|
] }),
|
|
4092
3609
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("versionActions"), children: [
|
|
4093
|
-
!isDefault && !isMarkedForDeletion && /* @__PURE__ */
|
|
4094
|
-
/* @__PURE__ */
|
|
4095
|
-
/* @__PURE__ */
|
|
3610
|
+
!isDefault && !isMarkedForDeletion && /* @__PURE__ */ jsx8(Button2, { variant: "secondary", onClick: () => setSelectedVersion(version), children: "Set as Default" }),
|
|
3611
|
+
/* @__PURE__ */ jsx8(Button2, { variant: "secondary", onClick: () => toggleVersionForDeletion(version), children: isMarkedForDeletion ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
3612
|
+
/* @__PURE__ */ jsx8(X, { size: 14 }),
|
|
4096
3613
|
" Undo"
|
|
4097
|
-
] }) : /* @__PURE__ */ jsxs4(
|
|
4098
|
-
/* @__PURE__ */
|
|
3614
|
+
] }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
3615
|
+
/* @__PURE__ */ jsx8(Trash2, { size: 14 }),
|
|
4099
3616
|
" Delete"
|
|
4100
3617
|
] }) })
|
|
4101
3618
|
] })
|
|
@@ -4103,8 +3620,8 @@ var DrawerItem = (props) => {
|
|
|
4103
3620
|
}) })
|
|
4104
3621
|
] }),
|
|
4105
3622
|
versionsToDelete.size > 0 && /* @__PURE__ */ jsxs4("div", { className: getClassName5("section"), children: [
|
|
4106
|
-
/* @__PURE__ */
|
|
4107
|
-
/* @__PURE__ */
|
|
3623
|
+
/* @__PURE__ */ jsx8("h3", { className: getClassName5("sectionTitle"), children: "Migration Settings" }),
|
|
3624
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("migrationOptions"), children: /* @__PURE__ */ jsx8(
|
|
4108
3625
|
"div",
|
|
4109
3626
|
{
|
|
4110
3627
|
className: getClassName5("migrationList"),
|
|
@@ -4122,8 +3639,8 @@ var DrawerItem = (props) => {
|
|
|
4122
3639
|
className: `${getClassName5("migrationOption")} ${isSelected ? getClassName5("migrationOption--isSelected") : ""}`,
|
|
4123
3640
|
onClick: () => setMigrationTarget(target.value),
|
|
4124
3641
|
children: [
|
|
4125
|
-
/* @__PURE__ */
|
|
4126
|
-
isSelected && /* @__PURE__ */
|
|
3642
|
+
/* @__PURE__ */ jsx8("span", { className: getClassName5("migrationOptionLabel"), children: target.label }),
|
|
3643
|
+
isSelected && /* @__PURE__ */ jsx8(Check, { size: 14 })
|
|
4127
3644
|
]
|
|
4128
3645
|
},
|
|
4129
3646
|
target.value
|
|
@@ -4131,49 +3648,48 @@ var DrawerItem = (props) => {
|
|
|
4131
3648
|
})
|
|
4132
3649
|
}
|
|
4133
3650
|
) }),
|
|
4134
|
-
/* @__PURE__ */
|
|
3651
|
+
/* @__PURE__ */ jsx8("p", { className: getClassName5("helpText"), children: "Choose where to move existing instances of the deleted versions." })
|
|
4135
3652
|
] })
|
|
4136
|
-
] }) : /* @__PURE__ */
|
|
3653
|
+
] }) : /* @__PURE__ */ jsx8("div", { className: getClassName5("section"), children: /* @__PURE__ */ jsxs4("p", { children: [
|
|
4137
3654
|
"Manage high-level settings for the ",
|
|
4138
|
-
/* @__PURE__ */
|
|
3655
|
+
/* @__PURE__ */ jsx8("strong", { children: displayName }),
|
|
4139
3656
|
" component."
|
|
4140
3657
|
] }) }) }),
|
|
4141
3658
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("modalFooter"), children: [
|
|
4142
3659
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("footerLeft"), children: [
|
|
4143
3660
|
useVersioning ? /* @__PURE__ */ jsxs4(Button2, { size: "medium", onClick: handleApply, children: [
|
|
4144
|
-
/* @__PURE__ */
|
|
3661
|
+
/* @__PURE__ */ jsx8(Check, { size: 16 }),
|
|
4145
3662
|
" Apply Changes"
|
|
4146
|
-
] }) : /* @__PURE__ */
|
|
3663
|
+
] }) : /* @__PURE__ */ jsx8(Button2, { size: "medium", onClick: handleCancel, children: "Close" }),
|
|
4147
3664
|
useVersioning && /* @__PURE__ */ jsxs4(Button2, { size: "medium", variant: "secondary", onClick: handleCancel, children: [
|
|
4148
|
-
/* @__PURE__ */
|
|
3665
|
+
/* @__PURE__ */ jsx8(X, { size: 16 }),
|
|
4149
3666
|
" Cancel"
|
|
4150
3667
|
] })
|
|
4151
3668
|
] }),
|
|
4152
|
-
/* @__PURE__ */
|
|
4153
|
-
/* @__PURE__ */
|
|
3669
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("footerRight"), children: /* @__PURE__ */ jsxs4(Button2, { size: "medium", variant: "secondary", onClick: handleDemolishClick, children: [
|
|
3670
|
+
/* @__PURE__ */ jsx8(Trash2, { size: 16 }),
|
|
4154
3671
|
" Demolish Component"
|
|
4155
3672
|
] }) })
|
|
4156
3673
|
] })
|
|
4157
3674
|
] }) })
|
|
4158
3675
|
] });
|
|
4159
3676
|
}
|
|
4160
|
-
return /* @__PURE__ */
|
|
3677
|
+
return /* @__PURE__ */ jsx8(Fragment4, { children: props.children });
|
|
4161
3678
|
};
|
|
4162
|
-
var ComponentItem = DrawerItem;
|
|
4163
3679
|
|
|
4164
3680
|
// src/puck/overrides/Drawer.tsx
|
|
4165
3681
|
import { useState as useState5 } from "react";
|
|
4166
|
-
import { createUsePuck as
|
|
3682
|
+
import { createUsePuck as createUsePuck12, Drawer as PuckDrawer } from "@measured/puck";
|
|
4167
3683
|
import { ChevronDown, ChevronUp } from "lucide-react";
|
|
4168
3684
|
|
|
4169
3685
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Drawer.module.css#css-module
|
|
4170
3686
|
var Drawer_module_default = { "Drawer": "_Drawer_12zq5_1", "Drawer-category": "_Drawer-category_12zq5_7", "Drawer-category--isExpanded": "_Drawer-category--isExpanded_12zq5_15", "Drawer-categoryContent": "_Drawer-categoryContent_12zq5_19", "Drawer-categoryTitle": "_Drawer-categoryTitle_12zq5_27", "Drawer-categoryTitleIcon": "_Drawer-categoryTitleIcon_12zq5_63" };
|
|
4171
3687
|
|
|
4172
3688
|
// src/puck/overrides/Drawer.tsx
|
|
4173
|
-
import { jsx as
|
|
3689
|
+
import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
3690
|
+
var useCustomPuck11 = createUsePuck12();
|
|
4174
3691
|
var getClassName6 = get_class_name_factory_default("Drawer", Drawer_module_default);
|
|
4175
3692
|
var getCategoryClassName = get_class_name_factory_default("Drawer-category", Drawer_module_default);
|
|
4176
|
-
var usePuck4 = createUsePuck13();
|
|
4177
3693
|
var CategorySection = ({
|
|
4178
3694
|
id,
|
|
4179
3695
|
title,
|
|
@@ -4190,12 +3706,12 @@ var CategorySection = ({
|
|
|
4190
3706
|
onClick: () => onToggle(id),
|
|
4191
3707
|
title: expanded ? `Collapse ${title}` : `Expand ${title}`,
|
|
4192
3708
|
children: [
|
|
4193
|
-
/* @__PURE__ */
|
|
4194
|
-
/* @__PURE__ */
|
|
3709
|
+
/* @__PURE__ */ jsx9("span", { children: title }),
|
|
3710
|
+
/* @__PURE__ */ jsx9("span", { className: getClassName6("categoryTitleIcon"), children: expanded ? /* @__PURE__ */ jsx9(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx9(ChevronDown, { size: 12 }) })
|
|
4195
3711
|
]
|
|
4196
3712
|
}
|
|
4197
3713
|
),
|
|
4198
|
-
/* @__PURE__ */
|
|
3714
|
+
/* @__PURE__ */ jsx9("div", { className: getClassName6("categoryContent"), children: /* @__PURE__ */ jsx9(PuckDrawer, { children: componentKeys.map((key) => /* @__PURE__ */ jsx9(
|
|
4199
3715
|
PuckDrawer.Item,
|
|
4200
3716
|
{
|
|
4201
3717
|
name: key,
|
|
@@ -4207,8 +3723,8 @@ var CategorySection = ({
|
|
|
4207
3723
|
] });
|
|
4208
3724
|
var Drawer = (_props) => {
|
|
4209
3725
|
var _a, _b;
|
|
4210
|
-
const config =
|
|
4211
|
-
const getPermissions =
|
|
3726
|
+
const config = useCustomPuck11((s) => s.config);
|
|
3727
|
+
const getPermissions = useCustomPuck11((s) => s.getPermissions);
|
|
4212
3728
|
const categories = (_a = config.categories) != null ? _a : {};
|
|
4213
3729
|
const categorised = new Set(
|
|
4214
3730
|
Object.values(categories).flatMap((cat) => {
|
|
@@ -4235,7 +3751,7 @@ var Drawer = (_props) => {
|
|
|
4235
3751
|
});
|
|
4236
3752
|
const toggle = (id) => setExpanded((prev) => __spreadProps(__spreadValues({}, prev), { [id]: !prev[id] }));
|
|
4237
3753
|
if (categoryEntries.length === 0) {
|
|
4238
|
-
return /* @__PURE__ */
|
|
3754
|
+
return /* @__PURE__ */ jsx9(PuckDrawer, { children: allKeys.map((key) => /* @__PURE__ */ jsx9(
|
|
4239
3755
|
PuckDrawer.Item,
|
|
4240
3756
|
{
|
|
4241
3757
|
name: key,
|
|
@@ -4249,7 +3765,7 @@ var Drawer = (_props) => {
|
|
|
4249
3765
|
return /* @__PURE__ */ jsxs5("div", { className: getClassName6(), children: [
|
|
4250
3766
|
categoryEntries.map(([id, cat]) => {
|
|
4251
3767
|
var _a2, _b2, _c;
|
|
4252
|
-
return /* @__PURE__ */
|
|
3768
|
+
return /* @__PURE__ */ jsx9(
|
|
4253
3769
|
CategorySection,
|
|
4254
3770
|
{
|
|
4255
3771
|
id,
|
|
@@ -4264,7 +3780,7 @@ var Drawer = (_props) => {
|
|
|
4264
3780
|
id
|
|
4265
3781
|
);
|
|
4266
3782
|
}),
|
|
4267
|
-
otherKeys.length > 0 && /* @__PURE__ */
|
|
3783
|
+
otherKeys.length > 0 && /* @__PURE__ */ jsx9(
|
|
4268
3784
|
CategorySection,
|
|
4269
3785
|
{
|
|
4270
3786
|
id: "__other__",
|
|
@@ -4279,17 +3795,19 @@ var Drawer = (_props) => {
|
|
|
4279
3795
|
};
|
|
4280
3796
|
|
|
4281
3797
|
// src/puck/overrides/HeaderActions.tsx
|
|
4282
|
-
import { Button as Button3, createUsePuck as
|
|
4283
|
-
import { Fragment as
|
|
4284
|
-
var
|
|
3798
|
+
import { Button as Button3, createUsePuck as createUsePuck13 } from "@measured/puck";
|
|
3799
|
+
import { Fragment as Fragment5, jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
3800
|
+
var useCustomPuck12 = createUsePuck13();
|
|
4285
3801
|
var HeaderActions = ({ children }) => {
|
|
4286
3802
|
const { handleComplete } = useComplete();
|
|
4287
3803
|
const { handleCancel, canCancel } = useCancel();
|
|
4288
|
-
const dispatch =
|
|
3804
|
+
const dispatch = useCustomPuck12((s) => s.dispatch);
|
|
3805
|
+
const appState = useCustomPuck12((s) => s.appState);
|
|
3806
|
+
const selectedItemSelector = appState.ui.itemSelector;
|
|
4289
3807
|
const inspect = useSoftConfig((s) => s.builder.inspect);
|
|
4290
|
-
return /* @__PURE__ */
|
|
4291
|
-
/* @__PURE__ */
|
|
4292
|
-
/* @__PURE__ */
|
|
3808
|
+
return /* @__PURE__ */ jsx10(Fragment5, { children: canCancel ? /* @__PURE__ */ jsxs6(Fragment5, { children: [
|
|
3809
|
+
/* @__PURE__ */ jsx10(Button3, { onClick: handleCancel, children: "Cancel" }),
|
|
3810
|
+
/* @__PURE__ */ jsx10(
|
|
4293
3811
|
Button3,
|
|
4294
3812
|
{
|
|
4295
3813
|
variant: "primary",
|
|
@@ -4297,7 +3815,7 @@ var HeaderActions = ({ children }) => {
|
|
|
4297
3815
|
const completedComponent = handleComplete();
|
|
4298
3816
|
if (completedComponent) {
|
|
4299
3817
|
try {
|
|
4300
|
-
inspect(completedComponent.id, dispatch);
|
|
3818
|
+
inspect(completedComponent.id, dispatch, selectedItemSelector);
|
|
4301
3819
|
} catch (error) {
|
|
4302
3820
|
notify.error(
|
|
4303
3821
|
"Failed to inspect after completion: " + (error instanceof Error ? error.message : String(error))
|
|
@@ -4520,17 +4038,36 @@ var resolveSoftConfig = (data, softComponents, config) => {
|
|
|
4520
4038
|
if (process.env.NODE_ENV === "development") {
|
|
4521
4039
|
const validation = validateOnlyHardComponents(dissolved, softComponents);
|
|
4522
4040
|
if (!validation.isValid) {
|
|
4523
|
-
|
|
4524
|
-
"Warning: Soft components still present after dissolution:"
|
|
4525
|
-
|
|
4041
|
+
alert(
|
|
4042
|
+
"Warning: Soft components still present after dissolution: " + String(
|
|
4043
|
+
validation.softComponentsFound
|
|
4044
|
+
)
|
|
4526
4045
|
);
|
|
4527
4046
|
}
|
|
4528
4047
|
}
|
|
4529
4048
|
return dissolved;
|
|
4530
4049
|
};
|
|
4050
|
+
|
|
4051
|
+
// src/puck/lib/builder/generate-field-options.ts
|
|
4052
|
+
var hasArrayMappingPath = (value) => value.includes("[]");
|
|
4053
|
+
var isBareArrayPath = (value) => !hasArrayMappingPath(value) && !value.includes(".");
|
|
4054
|
+
function filterToOptionsForFrom(fromPath, toOptions) {
|
|
4055
|
+
if (!fromPath) return toOptions;
|
|
4056
|
+
const fromHasArrayMapping = hasArrayMappingPath(fromPath);
|
|
4057
|
+
const fromIsBareArray = isBareArrayPath(fromPath);
|
|
4058
|
+
return toOptions.filter((option) => {
|
|
4059
|
+
const optionHasArrayMapping = hasArrayMappingPath(option.value);
|
|
4060
|
+
if (fromHasArrayMapping) {
|
|
4061
|
+
return optionHasArrayMapping;
|
|
4062
|
+
}
|
|
4063
|
+
if (fromIsBareArray) {
|
|
4064
|
+
return isBareArrayPath(option.value);
|
|
4065
|
+
}
|
|
4066
|
+
return !optionHasArrayMapping;
|
|
4067
|
+
});
|
|
4068
|
+
}
|
|
4531
4069
|
export {
|
|
4532
4070
|
ActionBarOverride as ActionBar,
|
|
4533
|
-
ComponentItem,
|
|
4534
4071
|
Drawer as ComponentList,
|
|
4535
4072
|
Drawer,
|
|
4536
4073
|
DrawerItem,
|