@netlisian/softconfig 0.1.9 → 0.2.0
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 +55 -38
- package/dist/puck/index.d.ts +55 -38
- package/dist/puck/index.js +1080 -1480
- package/dist/puck/index.mjs +1034 -1436
- package/package.json +8 -5
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";
|
|
47
|
+
// src/puck/lib/root-action-handler.ts
|
|
48
|
+
import isEqual from "react-fast-compare";
|
|
50
49
|
|
|
51
|
-
// src/puck/lib/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// src/puck/lib/builder/root-config.tsx
|
|
55
|
-
import { useEffect } from "react";
|
|
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 "@puckeditor/core";
|
|
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 "@puckeditor/core";
|
|
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);
|
|
@@ -2234,24 +1596,15 @@ var clearEditVisibility = (doc) => {
|
|
|
2234
1596
|
};
|
|
2235
1597
|
|
|
2236
1598
|
// src/puck/store/slices/builder.tsx
|
|
2237
|
-
var createBuildersSlice = (set, get
|
|
1599
|
+
var createBuildersSlice = (set, get) => ({
|
|
2238
1600
|
build: (history, selectedItem, itemSelector, puckDispatch, name) => {
|
|
2239
1601
|
if (!selectedItem || !itemSelector) {
|
|
2240
1602
|
throw new Error("No item selected to build from.");
|
|
2241
1603
|
}
|
|
2242
|
-
const config =
|
|
2243
|
-
const overrides = get().overrides;
|
|
2244
|
-
const buildConfig = builderConfig(
|
|
2245
|
-
config,
|
|
2246
|
-
overrides,
|
|
2247
|
-
void 0,
|
|
2248
|
-
get().showVersionFields,
|
|
2249
|
-
void 0,
|
|
2250
|
-
get().customFields
|
|
2251
|
-
);
|
|
1604
|
+
const config = get().softConfig;
|
|
2252
1605
|
const editableIds = /* @__PURE__ */ new Set([selectedItem.props.id]);
|
|
2253
1606
|
const initialContent = [__spreadValues({}, selectedItem)];
|
|
2254
|
-
|
|
1607
|
+
walkTree2(
|
|
2255
1608
|
{
|
|
2256
1609
|
root: {},
|
|
2257
1610
|
content: initialContent
|
|
@@ -2271,39 +1624,33 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2271
1624
|
})
|
|
2272
1625
|
);
|
|
2273
1626
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2274
|
-
softConfig: buildConfig,
|
|
2275
|
-
storedConfig: config,
|
|
2276
1627
|
originalHistory: history,
|
|
2277
|
-
itemSelector: {
|
|
2278
|
-
index: itemSelector.index,
|
|
2279
|
-
zone: itemSelector.zone || rootDroppableId
|
|
2280
|
-
},
|
|
2281
|
-
editingComponentId: selectedItem.props.id,
|
|
2282
|
-
editableComponentIds: editableIds,
|
|
2283
|
-
state: "building"
|
|
2284
|
-
}));
|
|
2285
|
-
requestAnimationFrame(
|
|
2286
|
-
|
|
2287
|
-
type: "
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
};
|
|
2302
|
-
}
|
|
2303
|
-
})
|
|
2304
|
-
);
|
|
1628
|
+
itemSelector: {
|
|
1629
|
+
index: itemSelector.index,
|
|
1630
|
+
zone: itemSelector.zone || rootDroppableId
|
|
1631
|
+
},
|
|
1632
|
+
editingComponentId: selectedItem.props.id,
|
|
1633
|
+
editableComponentIds: editableIds,
|
|
1634
|
+
state: "building"
|
|
1635
|
+
}));
|
|
1636
|
+
requestAnimationFrame(() => {
|
|
1637
|
+
puckDispatch({
|
|
1638
|
+
type: "setUi",
|
|
1639
|
+
ui: { itemSelector: null },
|
|
1640
|
+
recordHistory: false
|
|
1641
|
+
});
|
|
1642
|
+
puckDispatch({
|
|
1643
|
+
type: "replaceRoot",
|
|
1644
|
+
root: {
|
|
1645
|
+
props: {
|
|
1646
|
+
_name: name || "New Soft Component"
|
|
1647
|
+
}
|
|
1648
|
+
},
|
|
1649
|
+
recordHistory: false
|
|
1650
|
+
});
|
|
1651
|
+
});
|
|
2305
1652
|
},
|
|
2306
|
-
remodel: (history, selectedItem, itemSelector, puckDispatch) => {
|
|
1653
|
+
remodel: (history, selectedItem, itemSelector, puckDispatch, refreshPermission) => {
|
|
2307
1654
|
var _a, _b;
|
|
2308
1655
|
if (!selectedItem || !itemSelector) {
|
|
2309
1656
|
throw new Error("No item selected to build from.");
|
|
@@ -2323,7 +1670,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2323
1670
|
`Soft component "${softComponentName}" with version "${softComponentVersion}" not found.`
|
|
2324
1671
|
);
|
|
2325
1672
|
}
|
|
2326
|
-
const { root
|
|
1673
|
+
const { root } = softComponentToAppState(
|
|
2327
1674
|
softComponent,
|
|
2328
1675
|
softComponentName,
|
|
2329
1676
|
softComponentVersion,
|
|
@@ -2335,91 +1682,107 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2335
1682
|
softComponentMeta == null ? void 0 : softComponentMeta.category,
|
|
2336
1683
|
get().customFields
|
|
2337
1684
|
);
|
|
2338
|
-
const config =
|
|
2339
|
-
const overrides = get().overrides;
|
|
1685
|
+
const config = get().softConfig;
|
|
2340
1686
|
const dependents = get().dependencyGraph.get(softComponentName) || /* @__PURE__ */ new Set();
|
|
2341
|
-
const
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
get().showVersionFields,
|
|
2346
|
-
dependents,
|
|
2347
|
-
get().customFields
|
|
2348
|
-
);
|
|
2349
|
-
const editableIds = /* @__PURE__ */ new Set([]);
|
|
2350
|
-
const decomposedComponents = get().builder.decompose(selectedItem);
|
|
2351
|
-
walkTree3(
|
|
2352
|
-
{ 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 },
|
|
2353
1691
|
{ components: config.components },
|
|
2354
1692
|
(components) => {
|
|
2355
|
-
components.forEach((
|
|
2356
|
-
|
|
1693
|
+
components.forEach((comp2) => {
|
|
1694
|
+
const id2 = generateId(comp2.type);
|
|
1695
|
+
comp2.props.id = id2;
|
|
1696
|
+
editableIds.add(id2);
|
|
2357
1697
|
});
|
|
2358
1698
|
return components;
|
|
2359
1699
|
}
|
|
2360
1700
|
);
|
|
2361
|
-
requestAnimationFrame(() => {
|
|
2362
|
-
puckDispatch({
|
|
2363
|
-
type: "set",
|
|
2364
|
-
state: (previous) => ({
|
|
2365
|
-
data: {
|
|
2366
|
-
root: __spreadProps(__spreadValues({}, root), { _versions: versions }),
|
|
2367
|
-
content: walkTree3(
|
|
2368
|
-
__spreadValues({}, previous.data),
|
|
2369
|
-
__spreadValues({}, config),
|
|
2370
|
-
(components) => {
|
|
2371
|
-
const next = components.map((component) => __spreadProps(__spreadValues({}, component), {
|
|
2372
|
-
props: __spreadValues({}, component.props)
|
|
2373
|
-
}));
|
|
2374
|
-
const index = next.findIndex(
|
|
2375
|
-
(component) => component.props.id === selectedItem.props.id
|
|
2376
|
-
);
|
|
2377
|
-
if (index !== -1) {
|
|
2378
|
-
next.splice(
|
|
2379
|
-
index,
|
|
2380
|
-
1,
|
|
2381
|
-
...decomposedComponents.map((component) => __spreadProps(__spreadValues({}, component), {
|
|
2382
|
-
props: __spreadValues({}, component.props)
|
|
2383
|
-
}))
|
|
2384
|
-
);
|
|
2385
|
-
}
|
|
2386
|
-
return next;
|
|
2387
|
-
}
|
|
2388
|
-
).content
|
|
2389
|
-
},
|
|
2390
|
-
ui: __spreadProps(__spreadValues({}, previous.ui), {
|
|
2391
|
-
itemSelector: null
|
|
2392
|
-
})
|
|
2393
|
-
})
|
|
2394
|
-
});
|
|
2395
|
-
setEditVisibility(get().iframeDoc, {
|
|
2396
|
-
mode: "remodel",
|
|
2397
|
-
editableIds
|
|
2398
|
-
});
|
|
2399
|
-
});
|
|
2400
1701
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2401
|
-
storedConfig: config,
|
|
2402
|
-
softConfig: buildConfig,
|
|
2403
1702
|
originalHistory: history,
|
|
2404
1703
|
itemSelector: {
|
|
2405
1704
|
index: itemSelector.index,
|
|
2406
1705
|
zone: itemSelector.zone || rootDroppableId
|
|
2407
1706
|
},
|
|
2408
|
-
editingComponentId: selectedItem.props.id,
|
|
2409
1707
|
editingComponent: softComponentName,
|
|
1708
|
+
editingDependents: dependents,
|
|
2410
1709
|
editableComponentIds: editableIds,
|
|
2411
|
-
state: "
|
|
1710
|
+
state: "assessing"
|
|
2412
1711
|
}));
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
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(
|
|
1740
|
+
(acc, field) => __spreadProps(__spreadValues({}, acc), { [field]: true }),
|
|
1741
|
+
{}
|
|
1742
|
+
);
|
|
1743
|
+
puckDispatch({
|
|
1744
|
+
type: "replace",
|
|
1745
|
+
destinationIndex: itemSelector.index,
|
|
1746
|
+
destinationZone: itemSelector.zone || rootDroppableId,
|
|
1747
|
+
data: __spreadProps(__spreadValues({}, comp), {
|
|
1748
|
+
props: __spreadProps(__spreadValues({}, comp.props), {
|
|
1749
|
+
id
|
|
1750
|
+
}),
|
|
1751
|
+
readOnly
|
|
1752
|
+
}),
|
|
1753
|
+
recordHistory: false
|
|
1754
|
+
});
|
|
1755
|
+
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
1756
|
+
state: "remodeling"
|
|
1757
|
+
}));
|
|
1758
|
+
setEditVisibility(get().iframeDoc, {
|
|
1759
|
+
mode: "remodel",
|
|
1760
|
+
editableIds: new Set(editableIds)
|
|
1761
|
+
});
|
|
1762
|
+
});
|
|
1763
|
+
puckDispatch({
|
|
1764
|
+
type: "replaceRoot",
|
|
1765
|
+
root: {
|
|
1766
|
+
props: __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, root.props), root.props.title !== void 0 && {
|
|
1767
|
+
title: root.props.title
|
|
1768
|
+
}), root.props._name !== void 0 && {
|
|
1769
|
+
_name: root.props._name
|
|
1770
|
+
}), root.props._category !== void 0 && {
|
|
2419
1771
|
_category: root.props._category
|
|
2420
|
-
}
|
|
2421
|
-
|
|
2422
|
-
|
|
1772
|
+
}), {
|
|
1773
|
+
_versions: versions
|
|
1774
|
+
})
|
|
1775
|
+
},
|
|
1776
|
+
recordHistory: false
|
|
1777
|
+
});
|
|
1778
|
+
requestAnimationFrame(() => {
|
|
1779
|
+
puckDispatch({
|
|
1780
|
+
type: "setUi",
|
|
1781
|
+
ui: { itemSelector: null },
|
|
1782
|
+
recordHistory: false
|
|
1783
|
+
});
|
|
1784
|
+
refreshPermission();
|
|
1785
|
+
});
|
|
2423
1786
|
},
|
|
2424
1787
|
complete: (appState, setHistories, getItemBySelector) => {
|
|
2425
1788
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -2459,7 +1822,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2459
1822
|
}
|
|
2460
1823
|
const storedHistories = get().originalHistory;
|
|
2461
1824
|
setHistories([...storedHistories]);
|
|
2462
|
-
const config = __spreadValues({}, get().softConfig
|
|
1825
|
+
const config = __spreadValues({}, get().softConfig);
|
|
2463
1826
|
const mapComponentConfig = get().overrides.mapComponentConfig;
|
|
2464
1827
|
const newSoftComponentConfig = mapComponentConfig ? mapComponentConfig(componentName, defaultSoftComponentConfig, rootProps) : defaultSoftComponentConfig;
|
|
2465
1828
|
set((s) => {
|
|
@@ -2497,11 +1860,9 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2497
1860
|
}) : categories;
|
|
2498
1861
|
return __spreadProps(__spreadValues({}, s), {
|
|
2499
1862
|
softConfig: __spreadProps(__spreadValues({}, config), {
|
|
2500
|
-
root: __spreadValues({}, initialConfig.root),
|
|
2501
1863
|
components: nextComponents,
|
|
2502
1864
|
categories: nextCategories
|
|
2503
1865
|
}),
|
|
2504
|
-
storedConfig: void 0,
|
|
2505
1866
|
state: "inspecting",
|
|
2506
1867
|
// Temporarily shift state to inspect() before finalizing back to ready
|
|
2507
1868
|
originalHistory: []
|
|
@@ -2523,7 +1884,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2523
1884
|
softComponent: completedSoftComponent
|
|
2524
1885
|
};
|
|
2525
1886
|
},
|
|
2526
|
-
inspect: (componentName, puckDispatch) => {
|
|
1887
|
+
inspect: (componentName, puckDispatch, selectedItemSelector) => {
|
|
2527
1888
|
if (get().state !== "inspecting") {
|
|
2528
1889
|
throw new Error("Not in inspecting state.");
|
|
2529
1890
|
}
|
|
@@ -2532,59 +1893,72 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2532
1893
|
throw new Error("No selector found for last item.");
|
|
2533
1894
|
}
|
|
2534
1895
|
const editableComponentId = get().editingComponentId;
|
|
1896
|
+
const itemSelector = get().itemSelector;
|
|
2535
1897
|
requestAnimationFrame(() => {
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
1898
|
+
var _a;
|
|
1899
|
+
if (editableComponentId && !Object.keys(get().softComponents).includes(
|
|
1900
|
+
(_a = editableComponentId == null ? void 0 : editableComponentId.split(":")) == null ? void 0 : _a[0].split("-")[0]
|
|
1901
|
+
)) {
|
|
1902
|
+
requestAnimationFrame(() => {
|
|
1903
|
+
puckDispatch({
|
|
1904
|
+
type: "remove",
|
|
1905
|
+
index: itemSelector.index,
|
|
1906
|
+
zone: itemSelector.zone,
|
|
1907
|
+
recordHistory: true
|
|
1908
|
+
});
|
|
1909
|
+
puckDispatch({
|
|
1910
|
+
type: "insert",
|
|
1911
|
+
destinationIndex: itemSelector.index,
|
|
1912
|
+
destinationZone: itemSelector.zone,
|
|
1913
|
+
componentType: componentName,
|
|
1914
|
+
recordHistory: true
|
|
1915
|
+
});
|
|
2549
1916
|
});
|
|
2550
|
-
}
|
|
2551
|
-
puckDispatch({
|
|
2552
|
-
type: "setData",
|
|
2553
|
-
data: (data) => {
|
|
2554
|
-
return reconstructedTree(data);
|
|
2555
|
-
},
|
|
2556
|
-
recordHistory: true
|
|
2557
|
-
// Record this swap on the standard undo/redo stack
|
|
2558
|
-
});
|
|
1917
|
+
}
|
|
2559
1918
|
clearEditVisibility(get().iframeDoc);
|
|
1919
|
+
if (!selectedItemSelector && selector.index !== void 0) {
|
|
1920
|
+
puckDispatch({
|
|
1921
|
+
type: "setUi",
|
|
1922
|
+
ui: { itemSelector: selector },
|
|
1923
|
+
recordHistory: false
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
2560
1926
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2561
1927
|
state: "ready",
|
|
2562
1928
|
setItemSelector: void 0,
|
|
2563
1929
|
setOriginalItem: void 0,
|
|
1930
|
+
itemSelector: null,
|
|
2564
1931
|
editingComponent: null,
|
|
2565
1932
|
editingComponentId: null,
|
|
2566
1933
|
editableComponentIds: /* @__PURE__ */ new Set()
|
|
2567
1934
|
}));
|
|
2568
1935
|
});
|
|
2569
1936
|
},
|
|
2570
|
-
cancel: (setHistories) => {
|
|
1937
|
+
cancel: (setHistories, puckDispatch, selectedItemSelector) => {
|
|
2571
1938
|
const storedHistories = get().originalHistory;
|
|
1939
|
+
const itemSelector = get().itemSelector;
|
|
2572
1940
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2573
1941
|
state: "cancelling"
|
|
2574
1942
|
}));
|
|
2575
1943
|
setHistories([...storedHistories]);
|
|
2576
1944
|
requestAnimationFrame(() => {
|
|
2577
1945
|
clearEditVisibility(get().iframeDoc);
|
|
1946
|
+
if (!selectedItemSelector && itemSelector) {
|
|
1947
|
+
puckDispatch({
|
|
1948
|
+
type: "setUi",
|
|
1949
|
+
ui: { itemSelector },
|
|
1950
|
+
recordHistory: false
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
2578
1953
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2579
|
-
softConfig: get().storedConfig || initialConfig,
|
|
2580
|
-
storedConfig: void 0,
|
|
2581
1954
|
originalHistory: [],
|
|
2582
1955
|
itemSelector: null,
|
|
2583
1956
|
originalItem: null,
|
|
2584
1957
|
state: "ready",
|
|
2585
1958
|
editingComponent: null,
|
|
2586
1959
|
editingComponentId: null,
|
|
2587
|
-
editableComponentIds: /* @__PURE__ */ new Set()
|
|
1960
|
+
editableComponentIds: /* @__PURE__ */ new Set(),
|
|
1961
|
+
editingDependents: /* @__PURE__ */ new Set()
|
|
2588
1962
|
}));
|
|
2589
1963
|
});
|
|
2590
1964
|
},
|
|
@@ -2631,11 +2005,16 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2631
2005
|
get().setSoftComponent(componentName, version, softComponent);
|
|
2632
2006
|
return [newSoftComponentConfig, version];
|
|
2633
2007
|
},
|
|
2634
|
-
decompose: (componentData) => {
|
|
2008
|
+
decompose: (componentData, keepMapField) => {
|
|
2635
2009
|
if (!(componentData == null ? void 0 : componentData.type) || !(componentData == null ? void 0 : componentData.props.id)) {
|
|
2636
2010
|
throw new Error("Component data must have type and id to decompose.");
|
|
2637
2011
|
}
|
|
2638
|
-
return decomposeSoftComponent(
|
|
2012
|
+
return decomposeSoftComponent(
|
|
2013
|
+
componentData,
|
|
2014
|
+
get().softComponents,
|
|
2015
|
+
void 0,
|
|
2016
|
+
keepMapField
|
|
2017
|
+
);
|
|
2639
2018
|
},
|
|
2640
2019
|
demolish: (componentName, data, puckDispatch) => {
|
|
2641
2020
|
if (get().state !== "ready") {
|
|
@@ -2656,7 +2035,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2656
2035
|
softConfig: result.config
|
|
2657
2036
|
}));
|
|
2658
2037
|
},
|
|
2659
|
-
setVersion: (componentName, newVersion, currentProps, puckDispatch) => {
|
|
2038
|
+
setVersion: (componentName, newVersion, currentProps, puckDispatch, getItemBySelector, getSelectorForId) => {
|
|
2660
2039
|
var _a;
|
|
2661
2040
|
if (get().state !== "remodeling") {
|
|
2662
2041
|
throw new Error("Can only switch versions during remodeling.");
|
|
@@ -2683,12 +2062,91 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2683
2062
|
softComponentMeta == null ? void 0 : softComponentMeta.category,
|
|
2684
2063
|
get().customFields
|
|
2685
2064
|
);
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2065
|
+
const editableIds = get().editableComponentIds;
|
|
2066
|
+
if (!editableIds || editableIds.size === 0) return;
|
|
2067
|
+
const firstId = Array.from(editableIds)[0];
|
|
2068
|
+
const itemSelector = getSelectorForId(firstId);
|
|
2069
|
+
if (!itemSelector) return;
|
|
2070
|
+
requestAnimationFrame(() => {
|
|
2071
|
+
const countToRemove = Array.from(editableIds).filter(
|
|
2072
|
+
(id) => {
|
|
2073
|
+
var _a2;
|
|
2074
|
+
return ((_a2 = getSelectorForId(id)) == null ? void 0 : _a2.zone) === itemSelector.zone;
|
|
2075
|
+
}
|
|
2076
|
+
).length;
|
|
2077
|
+
for (let i = 0; i < countToRemove; i++) {
|
|
2078
|
+
puckDispatch({
|
|
2079
|
+
type: "remove",
|
|
2080
|
+
index: itemSelector.index,
|
|
2081
|
+
zone: itemSelector.zone,
|
|
2082
|
+
recordHistory: false
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
const newContent = content || [];
|
|
2086
|
+
const comp = newContent[0];
|
|
2087
|
+
if (comp) {
|
|
2088
|
+
puckDispatch({
|
|
2089
|
+
type: "insert",
|
|
2090
|
+
destinationIndex: itemSelector.index,
|
|
2091
|
+
destinationZone: itemSelector.zone,
|
|
2092
|
+
componentType: comp.type,
|
|
2093
|
+
recordHistory: false
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
requestAnimationFrame(() => {
|
|
2097
|
+
if (comp) {
|
|
2098
|
+
const insertedItem = getItemBySelector({
|
|
2099
|
+
index: itemSelector.index,
|
|
2100
|
+
zone: itemSelector.zone
|
|
2101
|
+
});
|
|
2102
|
+
if (insertedItem) {
|
|
2103
|
+
puckDispatch({
|
|
2104
|
+
type: "replace",
|
|
2105
|
+
destinationIndex: itemSelector.index,
|
|
2106
|
+
destinationZone: itemSelector.zone,
|
|
2107
|
+
data: __spreadProps(__spreadValues({}, comp), {
|
|
2108
|
+
props: __spreadProps(__spreadValues({}, comp.props), {
|
|
2109
|
+
id: insertedItem.props.id
|
|
2110
|
+
})
|
|
2111
|
+
}),
|
|
2112
|
+
recordHistory: false
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
puckDispatch({
|
|
2117
|
+
type: "replaceRoot",
|
|
2118
|
+
root: {
|
|
2119
|
+
props: __spreadProps(__spreadValues({}, root.props), {
|
|
2120
|
+
_versions: versions
|
|
2121
|
+
})
|
|
2122
|
+
},
|
|
2123
|
+
recordHistory: false
|
|
2124
|
+
});
|
|
2125
|
+
requestAnimationFrame(() => {
|
|
2126
|
+
const newEditableIds = /* @__PURE__ */ new Set();
|
|
2127
|
+
if (comp) {
|
|
2128
|
+
const finalItem = getItemBySelector({
|
|
2129
|
+
index: itemSelector.index,
|
|
2130
|
+
zone: itemSelector.zone
|
|
2131
|
+
});
|
|
2132
|
+
if (finalItem) {
|
|
2133
|
+
walkTree2(
|
|
2134
|
+
{ root: {}, content: [finalItem] },
|
|
2135
|
+
{ components: get().softConfig.components },
|
|
2136
|
+
(components) => {
|
|
2137
|
+
components.forEach((c) => newEditableIds.add(c.props.id));
|
|
2138
|
+
return components;
|
|
2139
|
+
}
|
|
2140
|
+
);
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
set((s) => __spreadProps(__spreadValues({}, s), { editableComponentIds: newEditableIds }));
|
|
2144
|
+
setEditVisibility(get().iframeDoc, {
|
|
2145
|
+
mode: "remodel",
|
|
2146
|
+
editableIds: newEditableIds
|
|
2147
|
+
});
|
|
2148
|
+
});
|
|
2149
|
+
});
|
|
2692
2150
|
});
|
|
2693
2151
|
}
|
|
2694
2152
|
});
|
|
@@ -2905,7 +2363,7 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides, showV
|
|
|
2905
2363
|
}
|
|
2906
2364
|
|
|
2907
2365
|
// src/puck/store/index.tsx
|
|
2908
|
-
var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
|
|
2366
|
+
var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}, contentAreaNames) => {
|
|
2909
2367
|
const normalizedSoftComponents = Object.fromEntries(
|
|
2910
2368
|
Object.entries(softComponents || {}).filter(([key]) => !hardConfig.components || !hardConfig.components[key]).map(([key, value]) => [key, __spreadProps(__spreadValues({}, value), { name: value.name || key })])
|
|
2911
2369
|
);
|
|
@@ -2935,6 +2393,11 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
|
|
|
2935
2393
|
softComponents: hydratedSoftComponents,
|
|
2936
2394
|
dependencyGraph: initialDependencyGraph,
|
|
2937
2395
|
showVersionFields,
|
|
2396
|
+
contentAreaNames,
|
|
2397
|
+
setContentAreaNames: (names) => set({ contentAreaNames: names }),
|
|
2398
|
+
puckDispatch: null,
|
|
2399
|
+
setPuckDispatch: (dispatch) => set({ puckDispatch: dispatch }),
|
|
2400
|
+
rootActionHandler: rootActionHandler(set, get),
|
|
2938
2401
|
// ─── Initial softConfig ─────────────────────────────────────────────────
|
|
2939
2402
|
softConfig: __spreadProps(__spreadValues({}, hardConfig), {
|
|
2940
2403
|
components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
|
|
@@ -3206,7 +2669,7 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
|
|
|
3206
2669
|
})
|
|
3207
2670
|
})),
|
|
3208
2671
|
// ─── Builder Slice ────────────────────────────────────────────────────────
|
|
3209
|
-
builder: createBuildersSlice(set, get
|
|
2672
|
+
builder: createBuildersSlice(set, get),
|
|
3210
2673
|
// ─── Dependency Graph ─────────────────────────────────────────────────────
|
|
3211
2674
|
rebuildDependents: (componentName) => {
|
|
3212
2675
|
const state = get();
|
|
@@ -3239,8 +2702,39 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
|
|
|
3239
2702
|
};
|
|
3240
2703
|
|
|
3241
2704
|
// src/puck/context/storeProvider.tsx
|
|
3242
|
-
import { useEffect
|
|
3243
|
-
|
|
2705
|
+
import { useEffect, useMemo as useMemo2, useState } from "react";
|
|
2706
|
+
|
|
2707
|
+
// src/puck/context/useStore.ts
|
|
2708
|
+
import { createContext, useContext } from "react";
|
|
2709
|
+
import { useStore } from "zustand";
|
|
2710
|
+
var appStoreContext = createContext(null);
|
|
2711
|
+
var createUseSoftConfig = () => {
|
|
2712
|
+
return function useSoftConfig2(selector, equalityFn) {
|
|
2713
|
+
const context = useContext(appStoreContext);
|
|
2714
|
+
if (!context) {
|
|
2715
|
+
throw new Error(
|
|
2716
|
+
"useSoftConfig must be used inside a SoftConfigProvider. Wrap your tree with <SoftConfigProvider value={store}>"
|
|
2717
|
+
);
|
|
2718
|
+
}
|
|
2719
|
+
if (equalityFn) {
|
|
2720
|
+
return useStore(context, selector, equalityFn);
|
|
2721
|
+
}
|
|
2722
|
+
return useStore(context, selector);
|
|
2723
|
+
};
|
|
2724
|
+
};
|
|
2725
|
+
var useSoftConfig = createUseSoftConfig();
|
|
2726
|
+
var useSoftConfigStore = () => {
|
|
2727
|
+
const context = useContext(appStoreContext);
|
|
2728
|
+
if (!context) {
|
|
2729
|
+
throw new Error(
|
|
2730
|
+
"useSoftConfigStore must be used inside a SoftConfigProvider."
|
|
2731
|
+
);
|
|
2732
|
+
}
|
|
2733
|
+
return context;
|
|
2734
|
+
};
|
|
2735
|
+
|
|
2736
|
+
// src/puck/context/storeProvider.tsx
|
|
2737
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
3244
2738
|
var SoftConfigProvider = ({
|
|
3245
2739
|
children,
|
|
3246
2740
|
hardConfig,
|
|
@@ -3249,7 +2743,8 @@ var SoftConfigProvider = ({
|
|
|
3249
2743
|
overrides,
|
|
3250
2744
|
value,
|
|
3251
2745
|
onActions,
|
|
3252
|
-
useVersioning = false
|
|
2746
|
+
useVersioning = false,
|
|
2747
|
+
contentAreaNames
|
|
3253
2748
|
}) => {
|
|
3254
2749
|
const store = useMemo2(
|
|
3255
2750
|
() => value != null ? value : createSoftConfigStore(
|
|
@@ -3258,18 +2753,15 @@ var SoftConfigProvider = ({
|
|
|
3258
2753
|
overrides,
|
|
3259
2754
|
onActions,
|
|
3260
2755
|
useVersioning,
|
|
3261
|
-
customFields
|
|
2756
|
+
customFields,
|
|
2757
|
+
contentAreaNames
|
|
3262
2758
|
),
|
|
3263
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3264
2759
|
[value]
|
|
3265
|
-
// Intentionally omitting the rest: createSoftConfigStore params are
|
|
3266
|
-
// treated as initialisation-time values. If callers need to react to
|
|
3267
|
-
// prop changes they should pass a new `value` store instead.
|
|
3268
2760
|
);
|
|
3269
2761
|
const [softConfig, setSoftConfig] = useState(
|
|
3270
2762
|
() => store.getState().softConfig
|
|
3271
2763
|
);
|
|
3272
|
-
|
|
2764
|
+
useEffect(() => {
|
|
3273
2765
|
let prev = store.getState().softConfig;
|
|
3274
2766
|
const unsubscribe = store.subscribe((state) => {
|
|
3275
2767
|
if (state.softConfig !== prev) {
|
|
@@ -3279,17 +2771,17 @@ var SoftConfigProvider = ({
|
|
|
3279
2771
|
});
|
|
3280
2772
|
return unsubscribe;
|
|
3281
2773
|
}, [store]);
|
|
3282
|
-
return /* @__PURE__ */
|
|
2774
|
+
return /* @__PURE__ */ jsx4(appStoreContext.Provider, { value: store, children: children(softConfig) });
|
|
3283
2775
|
};
|
|
3284
2776
|
|
|
3285
2777
|
// src/puck/actions/useBuild.tsx
|
|
3286
|
-
import { createUsePuck
|
|
2778
|
+
import { createUsePuck } from "@puckeditor/core";
|
|
3287
2779
|
|
|
3288
2780
|
// src/puck/lib/notify.ts
|
|
3289
2781
|
var customHandler = null;
|
|
3290
2782
|
var defaultHandler = (message, type) => {
|
|
3291
2783
|
if (type === "error") {
|
|
3292
|
-
|
|
2784
|
+
alert(`[Error] ${message}`);
|
|
3293
2785
|
} else {
|
|
3294
2786
|
console.log(`[Success] ${message}`);
|
|
3295
2787
|
}
|
|
@@ -3328,13 +2820,13 @@ var useActionEvent = () => {
|
|
|
3328
2820
|
};
|
|
3329
2821
|
|
|
3330
2822
|
// src/puck/actions/useBuild.tsx
|
|
3331
|
-
var
|
|
2823
|
+
var useCustomPuck = createUsePuck();
|
|
3332
2824
|
var useBuild = (name) => {
|
|
3333
2825
|
const build = useSoftConfig((s) => s.builder.build);
|
|
3334
|
-
const history =
|
|
3335
|
-
const selectedItem =
|
|
3336
|
-
const itemSelector =
|
|
3337
|
-
const dispatch =
|
|
2826
|
+
const history = useCustomPuck((s) => s.history.histories);
|
|
2827
|
+
const selectedItem = useCustomPuck((s) => s.selectedItem);
|
|
2828
|
+
const itemSelector = useCustomPuck((s) => s.appState.ui.itemSelector);
|
|
2829
|
+
const dispatch = useCustomPuck((s) => s.dispatch);
|
|
3338
2830
|
const status = useSoftConfig((s) => s.state);
|
|
3339
2831
|
const { triggerAction } = useActionEvent();
|
|
3340
2832
|
const handleBuild = () => {
|
|
@@ -3353,7 +2845,7 @@ var useBuild = (name) => {
|
|
|
3353
2845
|
});
|
|
3354
2846
|
}
|
|
3355
2847
|
} catch (error) {
|
|
3356
|
-
|
|
2848
|
+
alert("Failed to build: " + error);
|
|
3357
2849
|
notify.error(
|
|
3358
2850
|
"Failed to build: " + (error instanceof Error ? error.message : String(error))
|
|
3359
2851
|
);
|
|
@@ -3363,17 +2855,17 @@ var useBuild = (name) => {
|
|
|
3363
2855
|
};
|
|
3364
2856
|
|
|
3365
2857
|
// src/puck/actions/useRemodel.tsx
|
|
3366
|
-
import { createUsePuck as
|
|
3367
|
-
var
|
|
2858
|
+
import { createUsePuck as createUsePuck2 } from "@puckeditor/core";
|
|
2859
|
+
var useCustomPuck2 = createUsePuck2();
|
|
3368
2860
|
var useRemodel = () => {
|
|
3369
2861
|
const remodel = useSoftConfig((s) => s.builder.remodel);
|
|
3370
|
-
const history =
|
|
3371
|
-
const selectedItem =
|
|
3372
|
-
const itemSelector =
|
|
3373
|
-
const dispatch =
|
|
2862
|
+
const history = useCustomPuck2((s) => s.history.histories);
|
|
2863
|
+
const selectedItem = useCustomPuck2((s) => s.selectedItem);
|
|
2864
|
+
const itemSelector = useCustomPuck2((s) => s.appState.ui.itemSelector);
|
|
2865
|
+
const dispatch = useCustomPuck2((s) => s.dispatch);
|
|
3374
2866
|
const status = useSoftConfig((s) => s.state);
|
|
3375
2867
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
3376
|
-
const refreshPermissions =
|
|
2868
|
+
const refreshPermissions = useCustomPuck2((s) => s.refreshPermissions);
|
|
3377
2869
|
const { triggerAction } = useActionEvent();
|
|
3378
2870
|
const handleRemodel = (componentName) => {
|
|
3379
2871
|
var _a, _b, _c;
|
|
@@ -3389,7 +2881,13 @@ var useRemodel = () => {
|
|
|
3389
2881
|
const selectedVersion = ((_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.version) || ((_b = softComponents[name]) == null ? void 0 : _b.defaultVersion);
|
|
3390
2882
|
const selectedSoftComponent = selectedVersion ? (_c = softComponents[name]) == null ? void 0 : _c.versions[selectedVersion] : void 0;
|
|
3391
2883
|
try {
|
|
3392
|
-
remodel(
|
|
2884
|
+
remodel(
|
|
2885
|
+
history,
|
|
2886
|
+
selectedItem,
|
|
2887
|
+
itemSelector,
|
|
2888
|
+
dispatch,
|
|
2889
|
+
refreshPermissions
|
|
2890
|
+
);
|
|
3393
2891
|
void triggerAction({
|
|
3394
2892
|
type: "remodel",
|
|
3395
2893
|
payload: {
|
|
@@ -3407,9 +2905,9 @@ var useRemodel = () => {
|
|
|
3407
2905
|
}
|
|
3408
2906
|
return { id: name, version: selectedVersion };
|
|
3409
2907
|
} catch (error) {
|
|
3410
|
-
|
|
2908
|
+
alert("Failed to remodel: " + error);
|
|
3411
2909
|
notify.error(
|
|
3412
|
-
"Failed to remodel: " + (error instanceof Error ? error.message : String(error))
|
|
2910
|
+
"Failed to remodel: " + (error instanceof Error ? error.message : String(error)) + " " + String()
|
|
3413
2911
|
);
|
|
3414
2912
|
return null;
|
|
3415
2913
|
}
|
|
@@ -3422,14 +2920,14 @@ var useRemodel = () => {
|
|
|
3422
2920
|
};
|
|
3423
2921
|
|
|
3424
2922
|
// src/puck/actions/useComplete.tsx
|
|
3425
|
-
import { createUsePuck as
|
|
2923
|
+
import { createUsePuck as createUsePuck3 } from "@puckeditor/core";
|
|
3426
2924
|
import { useState as useState2, useCallback as useCallback2 } from "react";
|
|
3427
|
-
var
|
|
2925
|
+
var useCustomPuck3 = createUsePuck3();
|
|
3428
2926
|
var useComplete = () => {
|
|
3429
2927
|
const complete = useSoftConfig((s) => s.builder.complete);
|
|
3430
|
-
const appState =
|
|
3431
|
-
const setHistories =
|
|
3432
|
-
const getItemBySelector =
|
|
2928
|
+
const appState = useCustomPuck3((s) => s.appState);
|
|
2929
|
+
const setHistories = useCustomPuck3((s) => s.history.setHistories);
|
|
2930
|
+
const getItemBySelector = useCustomPuck3((s) => s.getItemBySelector);
|
|
3433
2931
|
const status = useSoftConfig((s) => s.state);
|
|
3434
2932
|
const [newComponent, setNewComponent] = useState2(null);
|
|
3435
2933
|
const { triggerAction } = useActionEvent();
|
|
@@ -3439,7 +2937,11 @@ var useComplete = () => {
|
|
|
3439
2937
|
return null;
|
|
3440
2938
|
}
|
|
3441
2939
|
try {
|
|
3442
|
-
const completedComponent = complete(
|
|
2940
|
+
const completedComponent = complete(
|
|
2941
|
+
appState,
|
|
2942
|
+
setHistories,
|
|
2943
|
+
getItemBySelector
|
|
2944
|
+
);
|
|
3443
2945
|
setNewComponent(completedComponent);
|
|
3444
2946
|
const componentData = appState.data.root;
|
|
3445
2947
|
if (componentData) {
|
|
@@ -3461,17 +2963,26 @@ var useComplete = () => {
|
|
|
3461
2963
|
);
|
|
3462
2964
|
return null;
|
|
3463
2965
|
}
|
|
3464
|
-
}, [
|
|
2966
|
+
}, [
|
|
2967
|
+
complete,
|
|
2968
|
+
appState,
|
|
2969
|
+
setHistories,
|
|
2970
|
+
status,
|
|
2971
|
+
triggerAction,
|
|
2972
|
+
getItemBySelector
|
|
2973
|
+
]);
|
|
3465
2974
|
const canComplete = status === "building" || status === "remodeling";
|
|
3466
2975
|
return { handleComplete, canComplete, newComponent, setNewComponent };
|
|
3467
2976
|
};
|
|
3468
2977
|
|
|
3469
2978
|
// src/puck/actions/useCancel.tsx
|
|
3470
|
-
import { createUsePuck as
|
|
3471
|
-
var
|
|
2979
|
+
import { createUsePuck as createUsePuck4 } from "@puckeditor/core";
|
|
2980
|
+
var useCustomPuck4 = createUsePuck4();
|
|
3472
2981
|
var useCancel = () => {
|
|
3473
2982
|
const cancel = useSoftConfig((s) => s.builder.cancel);
|
|
3474
|
-
const setHistories =
|
|
2983
|
+
const setHistories = useCustomPuck4((s) => s.history.setHistories);
|
|
2984
|
+
const puckDispatch = useCustomPuck4((s) => s.dispatch);
|
|
2985
|
+
const selectedItemSelector = useCustomPuck4((s) => s.appState.ui.itemSelector);
|
|
3475
2986
|
const status = useSoftConfig((s) => s.state);
|
|
3476
2987
|
const { triggerAction } = useActionEvent();
|
|
3477
2988
|
const handleCancel = () => {
|
|
@@ -3480,13 +2991,13 @@ var useCancel = () => {
|
|
|
3480
2991
|
return;
|
|
3481
2992
|
}
|
|
3482
2993
|
try {
|
|
3483
|
-
cancel(setHistories);
|
|
2994
|
+
cancel(setHistories, puckDispatch, selectedItemSelector);
|
|
3484
2995
|
void triggerAction({
|
|
3485
2996
|
type: "cancel",
|
|
3486
2997
|
payload: {}
|
|
3487
2998
|
});
|
|
3488
2999
|
} catch (error) {
|
|
3489
|
-
|
|
3000
|
+
alert("Failed to cancel: " + error);
|
|
3490
3001
|
notify.error(
|
|
3491
3002
|
"Failed to cancel: " + (error instanceof Error ? error.message : String(error))
|
|
3492
3003
|
);
|
|
@@ -3497,22 +3008,22 @@ var useCancel = () => {
|
|
|
3497
3008
|
};
|
|
3498
3009
|
|
|
3499
3010
|
// src/puck/actions/useInspect.tsx
|
|
3500
|
-
import { createUsePuck as
|
|
3501
|
-
import { useEffect as
|
|
3502
|
-
var
|
|
3011
|
+
import { createUsePuck as createUsePuck5 } from "@puckeditor/core";
|
|
3012
|
+
import { useEffect as useEffect2 } from "react";
|
|
3013
|
+
var useCustomPuck5 = createUsePuck5();
|
|
3503
3014
|
var useInspect = (component) => {
|
|
3504
3015
|
const inspect = useSoftConfig((s) => s.builder.inspect);
|
|
3505
|
-
const dispatch =
|
|
3016
|
+
const dispatch = useCustomPuck5((s) => s.dispatch);
|
|
3506
3017
|
const status = useSoftConfig((s) => s.state);
|
|
3507
3018
|
const { triggerAction } = useActionEvent();
|
|
3508
|
-
|
|
3019
|
+
useEffect2(() => {
|
|
3509
3020
|
if (status !== "inspecting") return;
|
|
3510
3021
|
if (!component) {
|
|
3511
3022
|
notify.error("No component to inspect.");
|
|
3512
3023
|
return;
|
|
3513
3024
|
}
|
|
3514
3025
|
try {
|
|
3515
|
-
inspect(component.id, dispatch);
|
|
3026
|
+
inspect(component.id, dispatch, null);
|
|
3516
3027
|
void triggerAction({
|
|
3517
3028
|
type: "inspect",
|
|
3518
3029
|
payload: {
|
|
@@ -3531,16 +3042,24 @@ var useInspect = (component) => {
|
|
|
3531
3042
|
};
|
|
3532
3043
|
|
|
3533
3044
|
// src/puck/actions/useDecompose.tsx
|
|
3534
|
-
import { createUsePuck as
|
|
3535
|
-
|
|
3045
|
+
import { createUsePuck as createUsePuck6, walkTree as walkTree3 } from "@puckeditor/core";
|
|
3046
|
+
|
|
3047
|
+
// src/puck/lib/get-prop-by-path.ts
|
|
3048
|
+
function getPropertyByPath(props, path) {
|
|
3049
|
+
return path.replace(/\[(\w+)\]/g, ".$1").split(".").reduce((o, key) => o ? o[key] : void 0, props);
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
// src/puck/actions/useDecompose.tsx
|
|
3053
|
+
var useCustomPuck6 = createUsePuck6();
|
|
3536
3054
|
var useDecompose = () => {
|
|
3537
3055
|
const decompose = useSoftConfig((s) => s.builder.decompose);
|
|
3538
|
-
const appState =
|
|
3539
|
-
const dispatch =
|
|
3540
|
-
const selectedItem =
|
|
3056
|
+
const appState = useCustomPuck6((s) => s.appState);
|
|
3057
|
+
const dispatch = useCustomPuck6((s) => s.dispatch);
|
|
3058
|
+
const selectedItem = useCustomPuck6((s) => s.selectedItem);
|
|
3541
3059
|
const status = useSoftConfig((s) => s.state);
|
|
3542
3060
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
3543
3061
|
const config = useSoftConfig((s) => s.softConfig);
|
|
3062
|
+
const contentAreaNames = useSoftConfig((s) => s.contentAreaNames);
|
|
3544
3063
|
const { triggerAction } = useActionEvent();
|
|
3545
3064
|
const handleDecompose = (componentData) => {
|
|
3546
3065
|
if (status !== "ready") {
|
|
@@ -3563,12 +3082,24 @@ var useDecompose = () => {
|
|
|
3563
3082
|
notify.error("Nothing to decompose.");
|
|
3564
3083
|
return;
|
|
3565
3084
|
}
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3085
|
+
let newData = __spreadValues({}, appState.data);
|
|
3086
|
+
const targetAreas = contentAreaNames && contentAreaNames.length > 0 ? contentAreaNames : ["content"];
|
|
3087
|
+
targetAreas.forEach((path) => {
|
|
3088
|
+
const contentArray = getPropertyByPath(newData, path) || [];
|
|
3089
|
+
const walkedData = walkTree3(
|
|
3090
|
+
{ content: contentArray, root: newData.root || {} },
|
|
3091
|
+
config,
|
|
3092
|
+
(components) => {
|
|
3093
|
+
const index = components.findIndex(
|
|
3094
|
+
(c) => c.props.id === target.props.id
|
|
3095
|
+
);
|
|
3096
|
+
if (index !== -1) {
|
|
3097
|
+
components.splice(index, 1, ...decomposedComponents);
|
|
3098
|
+
}
|
|
3099
|
+
return components;
|
|
3100
|
+
}
|
|
3101
|
+
);
|
|
3102
|
+
setPropertyByPath(newData, path, walkedData.content);
|
|
3572
3103
|
});
|
|
3573
3104
|
dispatch({
|
|
3574
3105
|
type: "setData",
|
|
@@ -3581,7 +3112,7 @@ var useDecompose = () => {
|
|
|
3581
3112
|
}
|
|
3582
3113
|
});
|
|
3583
3114
|
} catch (error) {
|
|
3584
|
-
|
|
3115
|
+
alert("Failed to decompose: " + error);
|
|
3585
3116
|
notify.error(
|
|
3586
3117
|
"Failed to decompose: " + (error instanceof Error ? error.message : String(error))
|
|
3587
3118
|
);
|
|
@@ -3595,12 +3126,12 @@ var useDecompose = () => {
|
|
|
3595
3126
|
};
|
|
3596
3127
|
|
|
3597
3128
|
// src/puck/actions/useDemolish.tsx
|
|
3598
|
-
import { createUsePuck as
|
|
3599
|
-
var
|
|
3129
|
+
import { createUsePuck as createUsePuck7 } from "@puckeditor/core";
|
|
3130
|
+
var useCustomPuck7 = createUsePuck7();
|
|
3600
3131
|
var useDemolish = () => {
|
|
3601
3132
|
const demolish = useSoftConfig((s) => s.builder.demolish);
|
|
3602
|
-
const dispatch =
|
|
3603
|
-
const data =
|
|
3133
|
+
const dispatch = useCustomPuck7((s) => s.dispatch);
|
|
3134
|
+
const data = useCustomPuck7((s) => s.appState.data);
|
|
3604
3135
|
const status = useSoftConfig((s) => s.state);
|
|
3605
3136
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
3606
3137
|
const { triggerAction } = useActionEvent();
|
|
@@ -3622,7 +3153,7 @@ var useDemolish = () => {
|
|
|
3622
3153
|
}
|
|
3623
3154
|
});
|
|
3624
3155
|
} catch (error) {
|
|
3625
|
-
|
|
3156
|
+
alert("Failed to demolish: " + error);
|
|
3626
3157
|
notify.error(
|
|
3627
3158
|
"Failed to demolish: " + (error instanceof Error ? error.message : String(error))
|
|
3628
3159
|
);
|
|
@@ -3683,17 +3214,17 @@ var useSetDefaultVersion = () => {
|
|
|
3683
3214
|
};
|
|
3684
3215
|
|
|
3685
3216
|
// src/puck/overrides/Header.tsx
|
|
3686
|
-
import { Button } from "@
|
|
3217
|
+
import { Button } from "@puckeditor/core";
|
|
3687
3218
|
|
|
3688
3219
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Header.module.css#css-module
|
|
3689
3220
|
var Header_module_default = { "Header": "_Header_19oj9_1" };
|
|
3690
3221
|
|
|
3691
3222
|
// src/puck/actions/usePublish.tsx
|
|
3692
|
-
import { createUsePuck as
|
|
3693
|
-
var
|
|
3223
|
+
import { createUsePuck as createUsePuck8 } from "@puckeditor/core";
|
|
3224
|
+
var useCustomPuck8 = createUsePuck8();
|
|
3694
3225
|
var usePublish = () => {
|
|
3695
3226
|
const components = useSoftConfig((s) => s.softComponents);
|
|
3696
|
-
const data =
|
|
3227
|
+
const data = useCustomPuck8((s) => s.appState.data);
|
|
3697
3228
|
const status = useSoftConfig((s) => s.state);
|
|
3698
3229
|
const { triggerAction } = useActionEvent();
|
|
3699
3230
|
const handlePublish = (publish) => {
|
|
@@ -3724,7 +3255,7 @@ var usePublish = () => {
|
|
|
3724
3255
|
};
|
|
3725
3256
|
|
|
3726
3257
|
// src/puck/overrides/Header.tsx
|
|
3727
|
-
import { Fragment as
|
|
3258
|
+
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
3728
3259
|
var getClassName2 = get_class_name_factory_default("Header", Header_module_default);
|
|
3729
3260
|
var Header = ({
|
|
3730
3261
|
onPublish,
|
|
@@ -3734,9 +3265,9 @@ var Header = ({
|
|
|
3734
3265
|
const { handleCancel, canCancel } = useCancel();
|
|
3735
3266
|
const { handlePublish } = usePublish();
|
|
3736
3267
|
useInspect(newComponent);
|
|
3737
|
-
return /* @__PURE__ */
|
|
3738
|
-
/* @__PURE__ */
|
|
3739
|
-
/* @__PURE__ */
|
|
3268
|
+
return /* @__PURE__ */ jsx5("div", { className: getClassName2(), children: canCancel ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
3269
|
+
/* @__PURE__ */ jsx5(Button, { onClick: handleCancel, children: "Cancel" }),
|
|
3270
|
+
/* @__PURE__ */ jsx5(
|
|
3740
3271
|
Button,
|
|
3741
3272
|
{
|
|
3742
3273
|
variant: "primary",
|
|
@@ -3749,7 +3280,7 @@ var Header = ({
|
|
|
3749
3280
|
children: "Complete"
|
|
3750
3281
|
}
|
|
3751
3282
|
)
|
|
3752
|
-
] }) : children ? children : /* @__PURE__ */
|
|
3283
|
+
] }) : children ? children : /* @__PURE__ */ jsx5(
|
|
3753
3284
|
Button,
|
|
3754
3285
|
{
|
|
3755
3286
|
variant: "primary",
|
|
@@ -3765,7 +3296,7 @@ var Header = ({
|
|
|
3765
3296
|
|
|
3766
3297
|
// src/puck/overrides/ActionBar.tsx
|
|
3767
3298
|
import { useMemo as useMemo3 } from "react";
|
|
3768
|
-
import { ActionBar, createUsePuck as
|
|
3299
|
+
import { ActionBar, createUsePuck as createUsePuck10 } from "@puckeditor/core";
|
|
3769
3300
|
import { Combine, ComponentIcon, EditIcon } from "lucide-react";
|
|
3770
3301
|
|
|
3771
3302
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
|
|
@@ -3773,21 +3304,24 @@ var ActionBar_module_default = { "ActionBar": "_ActionBar_pvuie_5", "ActionBar-l
|
|
|
3773
3304
|
|
|
3774
3305
|
// src/puck/overrides/ActionBar.tsx
|
|
3775
3306
|
import { shallow } from "zustand/shallow";
|
|
3776
|
-
import { Fragment as
|
|
3307
|
+
import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
3308
|
+
var useCustomPuck9 = createUsePuck10();
|
|
3777
3309
|
var getClassName3 = get_class_name_factory_default("ActionBar", ActionBar_module_default);
|
|
3778
|
-
var usePuck = createUsePuck11();
|
|
3779
3310
|
var ActionBarOverride = (props) => {
|
|
3780
3311
|
var _a, _b;
|
|
3781
|
-
const { handleBuild } = useBuild(
|
|
3312
|
+
const { handleBuild } = useBuild(
|
|
3313
|
+
props.label ? props.label + " Soft Component" : "New Soft Component"
|
|
3314
|
+
);
|
|
3782
3315
|
const { handleRemodel } = useRemodel();
|
|
3783
3316
|
const { handleDecompose } = useDecompose();
|
|
3784
3317
|
const overrides = useSoftConfig((s) => s.overrides);
|
|
3785
3318
|
const softComponents = useSoftConfig((s) => s.softComponents, shallow);
|
|
3786
3319
|
const editableIds = useSoftConfig((s) => s.editableComponentIds);
|
|
3787
|
-
const selectedItem =
|
|
3788
|
-
const
|
|
3320
|
+
const selectedItem = useCustomPuck9((s) => s.selectedItem);
|
|
3321
|
+
const appState = useCustomPuck9((s) => s.appState);
|
|
3322
|
+
const rootProps = appState.data.root.props;
|
|
3789
3323
|
const status = useSoftConfig((s) => s.state);
|
|
3790
|
-
const itemSelector =
|
|
3324
|
+
const itemSelector = appState.ui.itemSelector;
|
|
3791
3325
|
const softKeys = Object.keys(softComponents);
|
|
3792
3326
|
const key = useMemo3(() => {
|
|
3793
3327
|
const selectedType = selectedItem == null ? void 0 : selectedItem.type;
|
|
@@ -3798,18 +3332,13 @@ var ActionBarOverride = (props) => {
|
|
|
3798
3332
|
existingKeys: softKeys,
|
|
3799
3333
|
state: status
|
|
3800
3334
|
}));
|
|
3801
|
-
}, [
|
|
3802
|
-
props.label,
|
|
3803
|
-
overrides,
|
|
3804
|
-
selectedItem == null ? void 0 : selectedItem.type,
|
|
3805
|
-
softKeys,
|
|
3806
|
-
status,
|
|
3807
|
-
rootProps
|
|
3808
|
-
]);
|
|
3335
|
+
}, [props.label, overrides, selectedItem == null ? void 0 : selectedItem.type, softKeys, status, rootProps]);
|
|
3809
3336
|
const isSoftComponent2 = softKeys.includes(key);
|
|
3810
3337
|
const selectedId = (_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.id;
|
|
3811
3338
|
const parentId = (_b = itemSelector == null ? void 0 : itemSelector.zone) == null ? void 0 : _b.split(":")[0];
|
|
3812
|
-
const isEditable = Boolean(
|
|
3339
|
+
const isEditable = Boolean(
|
|
3340
|
+
selectedId && (editableIds.has(selectedId) || parentId && editableIds.has(parentId))
|
|
3341
|
+
);
|
|
3813
3342
|
const label = useMemo3(() => {
|
|
3814
3343
|
var _a2;
|
|
3815
3344
|
if (isSoftComponent2) {
|
|
@@ -3817,35 +3346,35 @@ var ActionBarOverride = (props) => {
|
|
|
3817
3346
|
}
|
|
3818
3347
|
return props.label || "";
|
|
3819
3348
|
}, [isSoftComponent2, key, props.label, overrides, softComponents]);
|
|
3820
|
-
return /* @__PURE__ */
|
|
3349
|
+
return /* @__PURE__ */ jsx6("div", { className: getClassName3(), children: /* @__PURE__ */ jsxs3(ActionBar, { children: [
|
|
3821
3350
|
/* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
|
|
3822
3351
|
props.parentAction,
|
|
3823
|
-
/* @__PURE__ */
|
|
3352
|
+
/* @__PURE__ */ jsx6(ActionBar.Label, { label })
|
|
3824
3353
|
] }),
|
|
3825
3354
|
/* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
|
|
3826
|
-
status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ jsxs3(
|
|
3827
|
-
/* @__PURE__ */
|
|
3355
|
+
status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
3356
|
+
/* @__PURE__ */ jsx6(
|
|
3828
3357
|
ActionBar.Action,
|
|
3829
3358
|
{
|
|
3830
3359
|
onClick: () => handleRemodel(key),
|
|
3831
3360
|
label: "Remodel Soft Component",
|
|
3832
|
-
children: /* @__PURE__ */
|
|
3361
|
+
children: /* @__PURE__ */ jsx6(EditIcon, { size: 16 })
|
|
3833
3362
|
}
|
|
3834
3363
|
),
|
|
3835
|
-
/* @__PURE__ */
|
|
3364
|
+
/* @__PURE__ */ jsx6(
|
|
3836
3365
|
ActionBar.Action,
|
|
3837
3366
|
{
|
|
3838
3367
|
onClick: () => handleDecompose(),
|
|
3839
3368
|
label: "Decompose Soft Component",
|
|
3840
|
-
children: /* @__PURE__ */
|
|
3369
|
+
children: /* @__PURE__ */ jsx6(Combine, { size: 16 })
|
|
3841
3370
|
}
|
|
3842
3371
|
)
|
|
3843
|
-
] }) : /* @__PURE__ */
|
|
3372
|
+
] }) : /* @__PURE__ */ jsx6(
|
|
3844
3373
|
ActionBar.Action,
|
|
3845
3374
|
{
|
|
3846
3375
|
onClick: handleBuild,
|
|
3847
3376
|
label: "Build Soft Component",
|
|
3848
|
-
children: /* @__PURE__ */
|
|
3377
|
+
children: /* @__PURE__ */ jsx6(ComponentIcon, { size: 16 })
|
|
3849
3378
|
}
|
|
3850
3379
|
) : null,
|
|
3851
3380
|
status !== "ready" && !isEditable ? null : props.children
|
|
@@ -3855,7 +3384,7 @@ var ActionBarOverride = (props) => {
|
|
|
3855
3384
|
|
|
3856
3385
|
// src/puck/overrides/DrawerItem.tsx
|
|
3857
3386
|
import { useState as useState4 } from "react";
|
|
3858
|
-
import { Button as Button2, IconButton, createUsePuck as
|
|
3387
|
+
import { Button as Button2, IconButton, createUsePuck as createUsePuck11 } from "@puckeditor/core";
|
|
3859
3388
|
import { GripVertical, Check, X, Trash2, Cog } from "lucide-react";
|
|
3860
3389
|
|
|
3861
3390
|
// src/puck/lib/confirm.ts
|
|
@@ -3870,7 +3399,7 @@ var confirm = (message) => __async(null, null, function* () {
|
|
|
3870
3399
|
const result = confirmHandler(message);
|
|
3871
3400
|
return result instanceof Promise ? yield result : result;
|
|
3872
3401
|
} catch (error) {
|
|
3873
|
-
|
|
3402
|
+
alert("Confirm handler error: " + error);
|
|
3874
3403
|
return false;
|
|
3875
3404
|
}
|
|
3876
3405
|
});
|
|
@@ -3879,14 +3408,14 @@ var confirm = (message) => __async(null, null, function* () {
|
|
|
3879
3408
|
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" };
|
|
3880
3409
|
|
|
3881
3410
|
// src/puck/components/modal/index.tsx
|
|
3882
|
-
import { useEffect as
|
|
3411
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
3883
3412
|
import { createPortal } from "react-dom";
|
|
3884
3413
|
|
|
3885
3414
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
|
|
3886
3415
|
var styles_module_default2 = { "Modal": "_Modal_1t9ot_1", "Modal--isOpen": "_Modal--isOpen_1t9ot_29", "Modal-inner": "_Modal-inner_1t9ot_37" };
|
|
3887
3416
|
|
|
3888
3417
|
// src/puck/components/modal/index.tsx
|
|
3889
|
-
import { jsx as
|
|
3418
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
3890
3419
|
var getClassName4 = get_class_name_factory_default("Modal", styles_module_default2);
|
|
3891
3420
|
var Modal = ({
|
|
3892
3421
|
children,
|
|
@@ -3894,10 +3423,10 @@ var Modal = ({
|
|
|
3894
3423
|
isOpen
|
|
3895
3424
|
}) => {
|
|
3896
3425
|
const [rootEl, setRootEl] = useState3(null);
|
|
3897
|
-
|
|
3426
|
+
useEffect3(() => {
|
|
3898
3427
|
setRootEl(document.getElementById("puck-portal-root"));
|
|
3899
3428
|
}, []);
|
|
3900
|
-
|
|
3429
|
+
useEffect3(() => {
|
|
3901
3430
|
if (!isOpen) {
|
|
3902
3431
|
return;
|
|
3903
3432
|
}
|
|
@@ -3910,10 +3439,10 @@ var Modal = ({
|
|
|
3910
3439
|
return () => document.removeEventListener("keydown", handleEscape);
|
|
3911
3440
|
}, [isOpen, onClose]);
|
|
3912
3441
|
if (!rootEl) {
|
|
3913
|
-
return /* @__PURE__ */
|
|
3442
|
+
return /* @__PURE__ */ jsx7("div", {});
|
|
3914
3443
|
}
|
|
3915
3444
|
return createPortal(
|
|
3916
|
-
/* @__PURE__ */
|
|
3445
|
+
/* @__PURE__ */ jsx7(
|
|
3917
3446
|
"div",
|
|
3918
3447
|
{
|
|
3919
3448
|
className: getClassName4({ isOpen }),
|
|
@@ -3922,7 +3451,7 @@ var Modal = ({
|
|
|
3922
3451
|
onClose();
|
|
3923
3452
|
}
|
|
3924
3453
|
},
|
|
3925
|
-
children: /* @__PURE__ */
|
|
3454
|
+
children: /* @__PURE__ */ jsx7(
|
|
3926
3455
|
"div",
|
|
3927
3456
|
{
|
|
3928
3457
|
className: getClassName4("inner"),
|
|
@@ -3940,16 +3469,16 @@ var Modal = ({
|
|
|
3940
3469
|
|
|
3941
3470
|
// src/puck/overrides/DrawerItem.tsx
|
|
3942
3471
|
import { shallow as shallow2 } from "zustand/shallow";
|
|
3943
|
-
import { Fragment as
|
|
3472
|
+
import { Fragment as Fragment4, jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
3473
|
+
var useCustomPuck10 = createUsePuck11();
|
|
3944
3474
|
var getClassName5 = get_class_name_factory_default("DrawerItem", DrawerItem_module_default);
|
|
3945
|
-
var usePuck2 = createUsePuck12();
|
|
3946
3475
|
var DrawerItem = (props) => {
|
|
3947
3476
|
const componentMeta = useSoftConfig((s) => s.softComponents[props.name]);
|
|
3948
3477
|
const displayName = props.label || (componentMeta == null ? void 0 : componentMeta.name) || props.name;
|
|
3949
3478
|
const softComponents = new Set(
|
|
3950
3479
|
Object.keys(useSoftConfig((s) => s.softComponents, shallow2))
|
|
3951
3480
|
);
|
|
3952
|
-
const getPermissions =
|
|
3481
|
+
const getPermissions = useCustomPuck10((s) => s.getPermissions);
|
|
3953
3482
|
const insertAllowed = getPermissions({ type: props.name }).insert;
|
|
3954
3483
|
const removeSoftComponentVersion = useSoftConfig(
|
|
3955
3484
|
(s) => s.removeSoftComponentVersion
|
|
@@ -4033,7 +3562,7 @@ var DrawerItem = (props) => {
|
|
|
4033
3562
|
label: `Migrate to Version ${version}`
|
|
4034
3563
|
}))
|
|
4035
3564
|
];
|
|
4036
|
-
return /* @__PURE__ */ jsxs4(
|
|
3565
|
+
return /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
4037
3566
|
/* @__PURE__ */ jsxs4(
|
|
4038
3567
|
"div",
|
|
4039
3568
|
{
|
|
@@ -4043,70 +3572,85 @@ var DrawerItem = (props) => {
|
|
|
4043
3572
|
children: [
|
|
4044
3573
|
props.label,
|
|
4045
3574
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("content"), children: [
|
|
4046
|
-
/* @__PURE__ */
|
|
3575
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("name"), children: displayName }),
|
|
4047
3576
|
useVersioning && /* @__PURE__ */ jsxs4("div", { className: getClassName5("version"), children: [
|
|
4048
3577
|
"v",
|
|
4049
3578
|
defaultVersion
|
|
4050
3579
|
] })
|
|
4051
3580
|
] }),
|
|
4052
3581
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("actions"), children: [
|
|
4053
|
-
isHovering && /* @__PURE__ */
|
|
3582
|
+
isHovering && /* @__PURE__ */ jsx8("div", { className: getClassName5("settingsButton"), children: /* @__PURE__ */ jsx8(
|
|
4054
3583
|
IconButton,
|
|
4055
3584
|
{
|
|
4056
3585
|
title: "Settings",
|
|
4057
|
-
variant: "secondary",
|
|
4058
3586
|
onClick: (e) => {
|
|
4059
3587
|
e.stopPropagation();
|
|
4060
3588
|
setIsEditing(true);
|
|
4061
3589
|
setSelectedVersion(defaultVersion || "");
|
|
4062
3590
|
},
|
|
4063
|
-
children: /* @__PURE__ */
|
|
3591
|
+
children: /* @__PURE__ */ jsx8(Cog, { size: 12 })
|
|
4064
3592
|
}
|
|
4065
3593
|
) }),
|
|
4066
|
-
/* @__PURE__ */
|
|
3594
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("grip"), children: /* @__PURE__ */ jsx8(GripVertical, { size: 16 }) })
|
|
4067
3595
|
] })
|
|
4068
3596
|
]
|
|
4069
3597
|
}
|
|
4070
3598
|
),
|
|
4071
|
-
/* @__PURE__ */
|
|
3599
|
+
/* @__PURE__ */ jsx8(Modal, { isOpen: isEditing, onClose: handleCancel, children: /* @__PURE__ */ jsxs4("div", { className: getClassName5("modal"), children: [
|
|
4072
3600
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("modalHeader"), children: [
|
|
4073
|
-
/* @__PURE__ */
|
|
4074
|
-
/* @__PURE__ */
|
|
3601
|
+
/* @__PURE__ */ jsx8("h2", { className: getClassName5("modalTitle"), children: displayName }),
|
|
3602
|
+
/* @__PURE__ */ jsx8("p", { className: getClassName5("modalSubtitle"), children: "Component Settings" })
|
|
4075
3603
|
] }),
|
|
4076
|
-
/* @__PURE__ */
|
|
3604
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("modalBody"), children: useVersioning ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
4077
3605
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("section"), children: [
|
|
4078
|
-
/* @__PURE__ */
|
|
4079
|
-
/* @__PURE__ */
|
|
3606
|
+
/* @__PURE__ */ jsx8("h3", { className: getClassName5("sectionTitle"), children: "Versions" }),
|
|
3607
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("versionList"), children: versions.map((version) => {
|
|
4080
3608
|
const isDefault = version === (selectedVersion || defaultVersion);
|
|
4081
3609
|
const isMarkedForDeletion = versionsToDelete.has(version);
|
|
4082
3610
|
let rowClass = getClassName5("versionRow");
|
|
4083
|
-
if (isDefault)
|
|
4084
|
-
|
|
3611
|
+
if (isDefault)
|
|
3612
|
+
rowClass += " " + getClassName5("versionRow--isDefault");
|
|
3613
|
+
if (isMarkedForDeletion)
|
|
3614
|
+
rowClass += " " + getClassName5("versionRow--isMarkedForDeletion");
|
|
4085
3615
|
return /* @__PURE__ */ jsxs4("div", { className: rowClass, children: [
|
|
4086
3616
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("versionInfo"), children: [
|
|
4087
3617
|
/* @__PURE__ */ jsxs4("span", { className: getClassName5("versionNumber"), children: [
|
|
4088
3618
|
"Version ",
|
|
4089
3619
|
version
|
|
4090
3620
|
] }),
|
|
4091
|
-
isDefault && /* @__PURE__ */
|
|
4092
|
-
isMarkedForDeletion && /* @__PURE__ */
|
|
3621
|
+
isDefault && /* @__PURE__ */ jsx8("span", { className: getClassName5("defaultBadge"), children: "Default" }),
|
|
3622
|
+
isMarkedForDeletion && /* @__PURE__ */ jsx8("span", { className: getClassName5("deleteBadge"), children: "Marked for deletion" })
|
|
4093
3623
|
] }),
|
|
4094
3624
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("versionActions"), children: [
|
|
4095
|
-
!isDefault && !isMarkedForDeletion && /* @__PURE__ */
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
3625
|
+
!isDefault && !isMarkedForDeletion && /* @__PURE__ */ jsx8(
|
|
3626
|
+
Button2,
|
|
3627
|
+
{
|
|
3628
|
+
variant: "secondary",
|
|
3629
|
+
onClick: () => setSelectedVersion(version),
|
|
3630
|
+
children: "Set as Default"
|
|
3631
|
+
}
|
|
3632
|
+
),
|
|
3633
|
+
/* @__PURE__ */ jsx8(
|
|
3634
|
+
Button2,
|
|
3635
|
+
{
|
|
3636
|
+
variant: "secondary",
|
|
3637
|
+
onClick: () => toggleVersionForDeletion(version),
|
|
3638
|
+
children: isMarkedForDeletion ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
3639
|
+
/* @__PURE__ */ jsx8(X, { size: 14 }),
|
|
3640
|
+
" Undo"
|
|
3641
|
+
] }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
3642
|
+
/* @__PURE__ */ jsx8(Trash2, { size: 14 }),
|
|
3643
|
+
" Delete"
|
|
3644
|
+
] })
|
|
3645
|
+
}
|
|
3646
|
+
)
|
|
4103
3647
|
] })
|
|
4104
3648
|
] }, version);
|
|
4105
3649
|
}) })
|
|
4106
3650
|
] }),
|
|
4107
3651
|
versionsToDelete.size > 0 && /* @__PURE__ */ jsxs4("div", { className: getClassName5("section"), children: [
|
|
4108
|
-
/* @__PURE__ */
|
|
4109
|
-
/* @__PURE__ */
|
|
3652
|
+
/* @__PURE__ */ jsx8("h3", { className: getClassName5("sectionTitle"), children: "Migration Settings" }),
|
|
3653
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("migrationOptions"), children: /* @__PURE__ */ jsx8(
|
|
4110
3654
|
"div",
|
|
4111
3655
|
{
|
|
4112
3656
|
className: getClassName5("migrationList"),
|
|
@@ -4121,11 +3665,21 @@ var DrawerItem = (props) => {
|
|
|
4121
3665
|
type: "button",
|
|
4122
3666
|
role: "radio",
|
|
4123
3667
|
"aria-checked": isSelected,
|
|
4124
|
-
className: `${getClassName5("migrationOption")} ${isSelected ? getClassName5(
|
|
3668
|
+
className: `${getClassName5("migrationOption")} ${isSelected ? getClassName5(
|
|
3669
|
+
"migrationOption--isSelected"
|
|
3670
|
+
) : ""}`,
|
|
4125
3671
|
onClick: () => setMigrationTarget(target.value),
|
|
4126
3672
|
children: [
|
|
4127
|
-
/* @__PURE__ */
|
|
4128
|
-
|
|
3673
|
+
/* @__PURE__ */ jsx8(
|
|
3674
|
+
"span",
|
|
3675
|
+
{
|
|
3676
|
+
className: getClassName5(
|
|
3677
|
+
"migrationOptionLabel"
|
|
3678
|
+
),
|
|
3679
|
+
children: target.label
|
|
3680
|
+
}
|
|
3681
|
+
),
|
|
3682
|
+
isSelected && /* @__PURE__ */ jsx8(Check, { size: 14 })
|
|
4129
3683
|
]
|
|
4130
3684
|
},
|
|
4131
3685
|
target.value
|
|
@@ -4133,49 +3687,65 @@ var DrawerItem = (props) => {
|
|
|
4133
3687
|
})
|
|
4134
3688
|
}
|
|
4135
3689
|
) }),
|
|
4136
|
-
/* @__PURE__ */
|
|
3690
|
+
/* @__PURE__ */ jsx8("p", { className: getClassName5("helpText"), children: "Choose where to move existing instances of the deleted versions." })
|
|
4137
3691
|
] })
|
|
4138
|
-
] }) : /* @__PURE__ */
|
|
4139
|
-
"Manage high-level settings for the
|
|
4140
|
-
|
|
3692
|
+
] }) : /* @__PURE__ */ jsx8("div", { className: getClassName5("section"), children: /* @__PURE__ */ jsxs4("p", { children: [
|
|
3693
|
+
"Manage high-level settings for the",
|
|
3694
|
+
" ",
|
|
3695
|
+
/* @__PURE__ */ jsx8("strong", { children: displayName }),
|
|
4141
3696
|
" component."
|
|
4142
3697
|
] }) }) }),
|
|
4143
3698
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("modalFooter"), children: [
|
|
4144
3699
|
/* @__PURE__ */ jsxs4("div", { className: getClassName5("footerLeft"), children: [
|
|
4145
3700
|
useVersioning ? /* @__PURE__ */ jsxs4(Button2, { size: "medium", onClick: handleApply, children: [
|
|
4146
|
-
/* @__PURE__ */
|
|
3701
|
+
/* @__PURE__ */ jsx8(Check, { size: 16 }),
|
|
4147
3702
|
" Apply Changes"
|
|
4148
|
-
] }) : /* @__PURE__ */
|
|
4149
|
-
useVersioning && /* @__PURE__ */ jsxs4(
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
3703
|
+
] }) : /* @__PURE__ */ jsx8(Button2, { size: "medium", onClick: handleCancel, children: "Close" }),
|
|
3704
|
+
useVersioning && /* @__PURE__ */ jsxs4(
|
|
3705
|
+
Button2,
|
|
3706
|
+
{
|
|
3707
|
+
size: "medium",
|
|
3708
|
+
variant: "secondary",
|
|
3709
|
+
onClick: handleCancel,
|
|
3710
|
+
children: [
|
|
3711
|
+
/* @__PURE__ */ jsx8(X, { size: 16 }),
|
|
3712
|
+
" Cancel"
|
|
3713
|
+
]
|
|
3714
|
+
}
|
|
3715
|
+
)
|
|
4153
3716
|
] }),
|
|
4154
|
-
/* @__PURE__ */
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
3717
|
+
/* @__PURE__ */ jsx8("div", { className: getClassName5("footerRight"), children: /* @__PURE__ */ jsxs4(
|
|
3718
|
+
Button2,
|
|
3719
|
+
{
|
|
3720
|
+
size: "medium",
|
|
3721
|
+
variant: "secondary",
|
|
3722
|
+
onClick: handleDemolishClick,
|
|
3723
|
+
children: [
|
|
3724
|
+
/* @__PURE__ */ jsx8(Trash2, { size: 16 }),
|
|
3725
|
+
" Demolish Component"
|
|
3726
|
+
]
|
|
3727
|
+
}
|
|
3728
|
+
) })
|
|
4158
3729
|
] })
|
|
4159
3730
|
] }) })
|
|
4160
3731
|
] });
|
|
4161
3732
|
}
|
|
4162
|
-
return /* @__PURE__ */
|
|
3733
|
+
return /* @__PURE__ */ jsx8(Fragment4, { children: props.children });
|
|
4163
3734
|
};
|
|
4164
|
-
var ComponentItem = DrawerItem;
|
|
4165
3735
|
|
|
4166
3736
|
// src/puck/overrides/Drawer.tsx
|
|
4167
3737
|
import { useState as useState5 } from "react";
|
|
4168
|
-
import { createUsePuck as
|
|
3738
|
+
import { createUsePuck as createUsePuck12, Drawer as PuckDrawer } from "@puckeditor/core";
|
|
4169
3739
|
import { ChevronDown, ChevronUp } from "lucide-react";
|
|
4170
3740
|
|
|
4171
3741
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Drawer.module.css#css-module
|
|
4172
3742
|
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" };
|
|
4173
3743
|
|
|
4174
3744
|
// src/puck/overrides/Drawer.tsx
|
|
4175
|
-
import { jsx as
|
|
3745
|
+
import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
3746
|
+
var useCustomPuck11 = createUsePuck12();
|
|
4176
3747
|
var getClassName6 = get_class_name_factory_default("Drawer", Drawer_module_default);
|
|
4177
3748
|
var getCategoryClassName = get_class_name_factory_default("Drawer-category", Drawer_module_default);
|
|
4178
|
-
var usePuck3 = createUsePuck13();
|
|
4179
3749
|
var CategorySection = ({
|
|
4180
3750
|
id,
|
|
4181
3751
|
title,
|
|
@@ -4192,12 +3762,12 @@ var CategorySection = ({
|
|
|
4192
3762
|
onClick: () => onToggle(id),
|
|
4193
3763
|
title: expanded ? `Collapse ${title}` : `Expand ${title}`,
|
|
4194
3764
|
children: [
|
|
4195
|
-
/* @__PURE__ */
|
|
4196
|
-
/* @__PURE__ */
|
|
3765
|
+
/* @__PURE__ */ jsx9("span", { children: title }),
|
|
3766
|
+
/* @__PURE__ */ jsx9("span", { className: getClassName6("categoryTitleIcon"), children: expanded ? /* @__PURE__ */ jsx9(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx9(ChevronDown, { size: 12 }) })
|
|
4197
3767
|
]
|
|
4198
3768
|
}
|
|
4199
3769
|
),
|
|
4200
|
-
/* @__PURE__ */
|
|
3770
|
+
/* @__PURE__ */ jsx9("div", { className: getClassName6("categoryContent"), children: /* @__PURE__ */ jsx9(PuckDrawer, { children: componentKeys.map((key) => /* @__PURE__ */ jsx9(
|
|
4201
3771
|
PuckDrawer.Item,
|
|
4202
3772
|
{
|
|
4203
3773
|
name: key,
|
|
@@ -4209,8 +3779,8 @@ var CategorySection = ({
|
|
|
4209
3779
|
] });
|
|
4210
3780
|
var Drawer = (_props) => {
|
|
4211
3781
|
var _a, _b;
|
|
4212
|
-
const config =
|
|
4213
|
-
const getPermissions =
|
|
3782
|
+
const config = useCustomPuck11((s) => s.config);
|
|
3783
|
+
const getPermissions = useCustomPuck11((s) => s.getPermissions);
|
|
4214
3784
|
const categories = (_a = config.categories) != null ? _a : {};
|
|
4215
3785
|
const categorised = new Set(
|
|
4216
3786
|
Object.values(categories).flatMap((cat) => {
|
|
@@ -4219,10 +3789,13 @@ var Drawer = (_props) => {
|
|
|
4219
3789
|
})
|
|
4220
3790
|
);
|
|
4221
3791
|
const allKeys = Object.keys(config.components);
|
|
4222
|
-
const labels = Object.entries(config.components).reduce(
|
|
4223
|
-
acc[key
|
|
4224
|
-
|
|
4225
|
-
|
|
3792
|
+
const labels = Object.entries(config.components).reduce(
|
|
3793
|
+
(acc, [key, comp]) => {
|
|
3794
|
+
acc[key] = comp.label || key;
|
|
3795
|
+
return acc;
|
|
3796
|
+
},
|
|
3797
|
+
{}
|
|
3798
|
+
);
|
|
4226
3799
|
const otherKeys = allKeys.filter((k) => !categorised.has(k));
|
|
4227
3800
|
const categoryEntries = Object.entries(categories).filter(
|
|
4228
3801
|
([, cat]) => cat.visible !== false
|
|
@@ -4237,7 +3810,7 @@ var Drawer = (_props) => {
|
|
|
4237
3810
|
});
|
|
4238
3811
|
const toggle = (id) => setExpanded((prev) => __spreadProps(__spreadValues({}, prev), { [id]: !prev[id] }));
|
|
4239
3812
|
if (categoryEntries.length === 0) {
|
|
4240
|
-
return /* @__PURE__ */
|
|
3813
|
+
return /* @__PURE__ */ jsx9(PuckDrawer, { children: allKeys.map((key) => /* @__PURE__ */ jsx9(
|
|
4241
3814
|
PuckDrawer.Item,
|
|
4242
3815
|
{
|
|
4243
3816
|
name: key,
|
|
@@ -4251,7 +3824,7 @@ var Drawer = (_props) => {
|
|
|
4251
3824
|
return /* @__PURE__ */ jsxs5("div", { className: getClassName6(), children: [
|
|
4252
3825
|
categoryEntries.map(([id, cat]) => {
|
|
4253
3826
|
var _a2, _b2, _c;
|
|
4254
|
-
return /* @__PURE__ */
|
|
3827
|
+
return /* @__PURE__ */ jsx9(
|
|
4255
3828
|
CategorySection,
|
|
4256
3829
|
{
|
|
4257
3830
|
id,
|
|
@@ -4266,7 +3839,7 @@ var Drawer = (_props) => {
|
|
|
4266
3839
|
id
|
|
4267
3840
|
);
|
|
4268
3841
|
}),
|
|
4269
|
-
otherKeys.length > 0 && /* @__PURE__ */
|
|
3842
|
+
otherKeys.length > 0 && /* @__PURE__ */ jsx9(
|
|
4270
3843
|
CategorySection,
|
|
4271
3844
|
{
|
|
4272
3845
|
id: "__other__",
|
|
@@ -4281,17 +3854,19 @@ var Drawer = (_props) => {
|
|
|
4281
3854
|
};
|
|
4282
3855
|
|
|
4283
3856
|
// src/puck/overrides/HeaderActions.tsx
|
|
4284
|
-
import { Button as Button3, createUsePuck as
|
|
4285
|
-
import { Fragment as
|
|
4286
|
-
var
|
|
3857
|
+
import { Button as Button3, createUsePuck as createUsePuck13 } from "@puckeditor/core";
|
|
3858
|
+
import { Fragment as Fragment5, jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
3859
|
+
var useCustomPuck12 = createUsePuck13();
|
|
4287
3860
|
var HeaderActions = ({ children }) => {
|
|
4288
3861
|
const { handleComplete } = useComplete();
|
|
4289
3862
|
const { handleCancel, canCancel } = useCancel();
|
|
4290
|
-
const dispatch =
|
|
3863
|
+
const dispatch = useCustomPuck12((s) => s.dispatch);
|
|
3864
|
+
const appState = useCustomPuck12((s) => s.appState);
|
|
3865
|
+
const selectedItemSelector = appState.ui.itemSelector;
|
|
4291
3866
|
const inspect = useSoftConfig((s) => s.builder.inspect);
|
|
4292
|
-
return /* @__PURE__ */
|
|
4293
|
-
/* @__PURE__ */
|
|
4294
|
-
/* @__PURE__ */
|
|
3867
|
+
return /* @__PURE__ */ jsx10(Fragment5, { children: canCancel ? /* @__PURE__ */ jsxs6(Fragment5, { children: [
|
|
3868
|
+
/* @__PURE__ */ jsx10(Button3, { onClick: handleCancel, children: "Cancel" }),
|
|
3869
|
+
/* @__PURE__ */ jsx10(
|
|
4295
3870
|
Button3,
|
|
4296
3871
|
{
|
|
4297
3872
|
variant: "primary",
|
|
@@ -4299,7 +3874,11 @@ var HeaderActions = ({ children }) => {
|
|
|
4299
3874
|
const completedComponent = handleComplete();
|
|
4300
3875
|
if (completedComponent) {
|
|
4301
3876
|
try {
|
|
4302
|
-
inspect(
|
|
3877
|
+
inspect(
|
|
3878
|
+
completedComponent.id,
|
|
3879
|
+
dispatch,
|
|
3880
|
+
selectedItemSelector
|
|
3881
|
+
);
|
|
4303
3882
|
} catch (error) {
|
|
4304
3883
|
notify.error(
|
|
4305
3884
|
"Failed to inspect after completion: " + (error instanceof Error ? error.message : String(error))
|
|
@@ -4522,17 +4101,36 @@ var resolveSoftConfig = (data, softComponents, config) => {
|
|
|
4522
4101
|
if (process.env.NODE_ENV === "development") {
|
|
4523
4102
|
const validation = validateOnlyHardComponents(dissolved, softComponents);
|
|
4524
4103
|
if (!validation.isValid) {
|
|
4525
|
-
|
|
4526
|
-
"Warning: Soft components still present after dissolution:"
|
|
4527
|
-
|
|
4104
|
+
alert(
|
|
4105
|
+
"Warning: Soft components still present after dissolution: " + String(
|
|
4106
|
+
validation.softComponentsFound
|
|
4107
|
+
)
|
|
4528
4108
|
);
|
|
4529
4109
|
}
|
|
4530
4110
|
}
|
|
4531
4111
|
return dissolved;
|
|
4532
4112
|
};
|
|
4113
|
+
|
|
4114
|
+
// src/puck/lib/builder/generate-field-options.ts
|
|
4115
|
+
var hasArrayMappingPath = (value) => value.includes("[]");
|
|
4116
|
+
var isBareArrayPath = (value) => !hasArrayMappingPath(value) && !value.includes(".");
|
|
4117
|
+
function filterToOptionsForFrom(fromPath, toOptions) {
|
|
4118
|
+
if (!fromPath) return toOptions;
|
|
4119
|
+
const fromHasArrayMapping = hasArrayMappingPath(fromPath);
|
|
4120
|
+
const fromIsBareArray = isBareArrayPath(fromPath);
|
|
4121
|
+
return toOptions.filter((option) => {
|
|
4122
|
+
const optionHasArrayMapping = hasArrayMappingPath(option.value);
|
|
4123
|
+
if (fromHasArrayMapping) {
|
|
4124
|
+
return optionHasArrayMapping;
|
|
4125
|
+
}
|
|
4126
|
+
if (fromIsBareArray) {
|
|
4127
|
+
return isBareArrayPath(option.value);
|
|
4128
|
+
}
|
|
4129
|
+
return !optionHasArrayMapping;
|
|
4130
|
+
});
|
|
4131
|
+
}
|
|
4533
4132
|
export {
|
|
4534
4133
|
ActionBarOverride as ActionBar,
|
|
4535
|
-
ComponentItem,
|
|
4536
4134
|
Drawer as ComponentList,
|
|
4537
4135
|
Drawer,
|
|
4538
4136
|
DrawerItem,
|