@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.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
"use strict";
|
|
3
|
+
"use client";
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __defProps = Object.defineProperties;
|
|
@@ -69,7 +70,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
69
70
|
var puck_exports = {};
|
|
70
71
|
__export(puck_exports, {
|
|
71
72
|
ActionBar: () => ActionBarOverride,
|
|
72
|
-
ComponentItem: () => ComponentItem,
|
|
73
73
|
ComponentList: () => Drawer,
|
|
74
74
|
Drawer: () => Drawer,
|
|
75
75
|
DrawerItem: () => DrawerItem,
|
|
@@ -105,22 +105,45 @@ __export(puck_exports, {
|
|
|
105
105
|
module.exports = __toCommonJS(puck_exports);
|
|
106
106
|
|
|
107
107
|
// src/puck/store/index.tsx
|
|
108
|
-
var
|
|
108
|
+
var import_zustand = require("zustand");
|
|
109
109
|
var import_middleware = require("zustand/middleware");
|
|
110
110
|
|
|
111
|
-
// src/puck/
|
|
112
|
-
var import_puck4 = require("@measured/puck");
|
|
113
|
-
|
|
114
|
-
// src/puck/lib/get-root-props.ts
|
|
115
|
-
var getRootProps = (appState) => appState.data.root.props;
|
|
116
|
-
|
|
117
|
-
// src/puck/lib/builder/root-config.tsx
|
|
118
|
-
var import_react2 = require("react");
|
|
111
|
+
// src/puck/lib/root-action-handler.ts
|
|
119
112
|
var import_react_fast_compare2 = __toESM(require("react-fast-compare"));
|
|
120
|
-
var import_puck2 = require("@measured/puck");
|
|
121
113
|
|
|
122
|
-
// src/puck/lib/
|
|
123
|
-
var
|
|
114
|
+
// src/puck/lib/apply-mapping.ts
|
|
115
|
+
var import_react_fast_compare = __toESM(require("react-fast-compare"));
|
|
116
|
+
|
|
117
|
+
// src/puck/lib/set-prop-by-path.ts
|
|
118
|
+
function setPropertyByPath(props, path, value) {
|
|
119
|
+
const parts = path.replace(/\[(\w+)\]/g, ".$1").split(".");
|
|
120
|
+
const last = parts.pop();
|
|
121
|
+
let cur = props;
|
|
122
|
+
for (const p of parts) {
|
|
123
|
+
if (typeof cur[p] !== "object" || cur[p] === null) cur[p] = {};
|
|
124
|
+
cur = cur[p];
|
|
125
|
+
}
|
|
126
|
+
cur[last] = value;
|
|
127
|
+
}
|
|
128
|
+
function setImmutablePropertyByPath(obj, path, value) {
|
|
129
|
+
if (!path) return value;
|
|
130
|
+
const parts = path.replace(/\[(\w+)\]/g, ".$1").split(".");
|
|
131
|
+
const root = Array.isArray(obj) ? [...obj] : __spreadValues({}, obj);
|
|
132
|
+
let current = root;
|
|
133
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
134
|
+
const part = parts[i];
|
|
135
|
+
const nextPart = parts[i + 1];
|
|
136
|
+
const isArrayNext = !isNaN(Number(nextPart));
|
|
137
|
+
if (current[part] === void 0 || current[part] === null) {
|
|
138
|
+
current[part] = isArrayNext ? [] : {};
|
|
139
|
+
} else {
|
|
140
|
+
current[part] = Array.isArray(current[part]) ? [...current[part]] : __spreadValues({}, current[part]);
|
|
141
|
+
}
|
|
142
|
+
current = current[part];
|
|
143
|
+
}
|
|
144
|
+
current[parts[parts.length - 1]] = value;
|
|
145
|
+
return root;
|
|
146
|
+
}
|
|
124
147
|
|
|
125
148
|
// src/puck/lib/get-settings-by-path.ts
|
|
126
149
|
function getFieldSettingsByPath(fieldSettings, path) {
|
|
@@ -128,14 +151,6 @@ function getFieldSettingsByPath(fieldSettings, path) {
|
|
|
128
151
|
}
|
|
129
152
|
|
|
130
153
|
// src/puck/lib/array-field-utils.ts
|
|
131
|
-
var primitiveFieldTypes = /* @__PURE__ */ new Set([
|
|
132
|
-
"text",
|
|
133
|
-
"textarea",
|
|
134
|
-
"number",
|
|
135
|
-
"select",
|
|
136
|
-
"radio",
|
|
137
|
-
"reference"
|
|
138
|
-
]);
|
|
139
154
|
var isPrimitiveValue = (value) => ["string", "number", "boolean"].includes(typeof value);
|
|
140
155
|
var getFallbackValueForField = (type) => {
|
|
141
156
|
switch (type) {
|
|
@@ -167,7 +182,6 @@ var resolveExpressionSummary = (item, index, expression) => {
|
|
|
167
182
|
});
|
|
168
183
|
return isValid ? result : "";
|
|
169
184
|
};
|
|
170
|
-
var isPrimitiveFieldType = (type) => primitiveFieldTypes.has(type);
|
|
171
185
|
var buildArrayDefaultItemProps = (subFields = [], subFieldSettings = {}) => {
|
|
172
186
|
if (!subFields.length) return void 0;
|
|
173
187
|
const item = {};
|
|
@@ -220,486 +234,19 @@ var getArrayItemSubPath = (arrayPath) => {
|
|
|
220
234
|
return match ? match[1] : null;
|
|
221
235
|
};
|
|
222
236
|
|
|
223
|
-
// src/puck/lib/custom-fields.ts
|
|
224
|
-
var builtInSoftFieldTypes = /* @__PURE__ */ new Set([
|
|
225
|
-
"text",
|
|
226
|
-
"textarea",
|
|
227
|
-
"number",
|
|
228
|
-
"select",
|
|
229
|
-
"radio",
|
|
230
|
-
"array",
|
|
231
|
-
"object",
|
|
232
|
-
"reference"
|
|
233
|
-
]);
|
|
234
|
-
var warnedMessages = /* @__PURE__ */ new Set();
|
|
235
|
-
var warnOnce = (message) => {
|
|
236
|
-
if (warnedMessages.has(message)) {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
warnedMessages.add(message);
|
|
240
|
-
console.warn(message);
|
|
241
|
-
};
|
|
242
|
-
var isBuiltInSoftFieldType = (fieldType) => {
|
|
243
|
-
return builtInSoftFieldTypes.has(fieldType);
|
|
244
|
-
};
|
|
245
|
-
var resolveCustomFieldDefinition = (fieldType, customFields) => {
|
|
246
|
-
if (isBuiltInSoftFieldType(fieldType)) {
|
|
247
|
-
return void 0;
|
|
248
|
-
}
|
|
249
|
-
return customFields == null ? void 0 : customFields[fieldType];
|
|
250
|
-
};
|
|
251
|
-
var resolveCustomFieldReturnType = (fieldType, customFields) => {
|
|
252
|
-
const customField = resolveCustomFieldDefinition(fieldType, customFields);
|
|
253
|
-
if (!customField) {
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
if (!customField.returnType) {
|
|
257
|
-
warnOnce(
|
|
258
|
-
`[soft-config] Custom field "${fieldType}" is missing a required returnType and will be skipped from mapping options.`
|
|
259
|
-
);
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
262
|
-
return customField.returnType;
|
|
263
|
-
};
|
|
264
|
-
var resolveCustomFieldSchema = (fieldType, customFields) => {
|
|
265
|
-
const customField = resolveCustomFieldDefinition(fieldType, customFields);
|
|
266
|
-
if (!customField) {
|
|
267
|
-
return null;
|
|
268
|
-
}
|
|
269
|
-
const returnType = resolveCustomFieldReturnType(fieldType, customFields);
|
|
270
|
-
if (!returnType) {
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
if (returnType !== "array" && returnType !== "object") {
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
const subFields = customField.subFields || [];
|
|
277
|
-
if (!subFields.length) {
|
|
278
|
-
warnOnce(
|
|
279
|
-
`[soft-config] Custom field "${fieldType}" returns ${returnType} but does not define subFields. It will be skipped from mapping options.`
|
|
280
|
-
);
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
return {
|
|
284
|
-
subFields,
|
|
285
|
-
subFieldSettings: customField.subFieldSettings || {}
|
|
286
|
-
};
|
|
287
|
-
};
|
|
288
|
-
var getCustomFieldTypeOptions = (customFields) => {
|
|
289
|
-
if (!customFields) {
|
|
290
|
-
return [];
|
|
291
|
-
}
|
|
292
|
-
return Object.entries(customFields).filter(([fieldType]) => !isBuiltInSoftFieldType(fieldType)).map(([fieldType, definition]) => ({
|
|
293
|
-
label: typeof definition.field.label === "string" && definition.field.label ? definition.field.label : fieldType,
|
|
294
|
-
value: fieldType
|
|
295
|
-
}));
|
|
296
|
-
};
|
|
297
|
-
var mapCustomReturnTypeToMappingType = (returnType) => {
|
|
298
|
-
switch (returnType) {
|
|
299
|
-
case "string":
|
|
300
|
-
return "textarea";
|
|
301
|
-
case "number":
|
|
302
|
-
return "number";
|
|
303
|
-
case "boolean":
|
|
304
|
-
return "select";
|
|
305
|
-
case "array":
|
|
306
|
-
return "array";
|
|
307
|
-
case "object":
|
|
308
|
-
return "object";
|
|
309
|
-
default:
|
|
310
|
-
return "textarea";
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
// src/puck/lib/get-field-settings.tsx
|
|
315
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
316
|
-
var buildPuckField = (field, fieldSettings, customFields) => {
|
|
317
|
-
const customFieldDefinition = resolveCustomFieldDefinition(
|
|
318
|
-
field.type,
|
|
319
|
-
customFields
|
|
320
|
-
);
|
|
321
|
-
const customReturnType = resolveCustomFieldReturnType(field.type, customFields);
|
|
322
|
-
if (customFieldDefinition && customReturnType) {
|
|
323
|
-
return __spreadProps(__spreadValues({}, customFieldDefinition.field), {
|
|
324
|
-
type: "custom",
|
|
325
|
-
label: customFieldDefinition.field.label || field.name
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
const resolvedType = field.type;
|
|
329
|
-
switch (resolvedType) {
|
|
330
|
-
case "text":
|
|
331
|
-
case "textarea":
|
|
332
|
-
return { type: resolvedType, label: field.name };
|
|
333
|
-
case "number":
|
|
334
|
-
return {
|
|
335
|
-
type: resolvedType,
|
|
336
|
-
label: field.name,
|
|
337
|
-
min: fieldSettings == null ? void 0 : fieldSettings.min,
|
|
338
|
-
max: fieldSettings == null ? void 0 : fieldSettings.max,
|
|
339
|
-
step: fieldSettings == null ? void 0 : fieldSettings.step
|
|
340
|
-
};
|
|
341
|
-
case "select":
|
|
342
|
-
case "radio":
|
|
343
|
-
return {
|
|
344
|
-
type: resolvedType,
|
|
345
|
-
label: field.name,
|
|
346
|
-
options: (fieldSettings == null ? void 0 : fieldSettings.options) || []
|
|
347
|
-
};
|
|
348
|
-
case "array": {
|
|
349
|
-
const subFields = (fieldSettings == null ? void 0 : fieldSettings.subFields) || [];
|
|
350
|
-
const subFieldSettings = (fieldSettings == null ? void 0 : fieldSettings.subFieldSettings) || {};
|
|
351
|
-
return {
|
|
352
|
-
type: "array",
|
|
353
|
-
label: field.name,
|
|
354
|
-
min: fieldSettings == null ? void 0 : fieldSettings.min,
|
|
355
|
-
max: fieldSettings == null ? void 0 : fieldSettings.max,
|
|
356
|
-
arrayFields: buildDefaultEditorFields(
|
|
357
|
-
subFields,
|
|
358
|
-
subFieldSettings,
|
|
359
|
-
customFields
|
|
360
|
-
),
|
|
361
|
-
defaultItemProps: buildArrayDefaultItemProps(subFields, subFieldSettings),
|
|
362
|
-
getItemSummary(item, index) {
|
|
363
|
-
return getArrayItemSummary(item, index, fieldSettings);
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
case "object":
|
|
368
|
-
return {
|
|
369
|
-
type: "object",
|
|
370
|
-
label: field.name,
|
|
371
|
-
objectFields: buildDefaultEditorFields(
|
|
372
|
-
(fieldSettings == null ? void 0 : fieldSettings.subFields) || [],
|
|
373
|
-
(fieldSettings == null ? void 0 : fieldSettings.subFieldSettings) || {},
|
|
374
|
-
customFields
|
|
375
|
-
)
|
|
376
|
-
};
|
|
377
|
-
default:
|
|
378
|
-
return { type: "text", label: field.name };
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
var buildDefaultEditorFields = (fields = [], fieldSettings = {}, customFields) => {
|
|
382
|
-
return fields.reduce((acc, field) => {
|
|
383
|
-
acc[field.name] = buildPuckField(
|
|
384
|
-
field,
|
|
385
|
-
fieldSettings[field.name],
|
|
386
|
-
customFields
|
|
387
|
-
);
|
|
388
|
-
return acc;
|
|
389
|
-
}, {});
|
|
390
|
-
};
|
|
391
|
-
var getFieldSettings = (_fields, _fieldSettings, customFields, deep) => {
|
|
392
|
-
const customTypeOptions = getCustomFieldTypeOptions(customFields);
|
|
393
|
-
return (_fields || []).reduce((fields, field) => {
|
|
394
|
-
const fieldSettings = {
|
|
395
|
-
// placeholder: { type: "text", label: "Placeholder" },
|
|
396
|
-
};
|
|
397
|
-
const currentFieldSettings = _fieldSettings == null ? void 0 : _fieldSettings[field.name];
|
|
398
|
-
const customFieldDefinition = resolveCustomFieldDefinition(
|
|
399
|
-
field.type,
|
|
400
|
-
customFields
|
|
401
|
-
);
|
|
402
|
-
const customReturnType = resolveCustomFieldReturnType(
|
|
403
|
-
field.type,
|
|
404
|
-
customFields
|
|
405
|
-
);
|
|
406
|
-
const resolvedType = field.type;
|
|
407
|
-
const customSchema = resolveCustomFieldSchema(field.type, customFields);
|
|
408
|
-
const resolvedSubFields = (customSchema == null ? void 0 : customSchema.subFields) || (currentFieldSettings == null ? void 0 : currentFieldSettings.subFields) || [];
|
|
409
|
-
const resolvedSubFieldSettings = (customSchema == null ? void 0 : customSchema.subFieldSettings) || (currentFieldSettings == null ? void 0 : currentFieldSettings.subFieldSettings) || {};
|
|
410
|
-
const customDefaultValueField = customFieldDefinition && customReturnType ? __spreadProps(__spreadValues({}, customFieldDefinition.field), {
|
|
411
|
-
type: "custom",
|
|
412
|
-
label: customFieldDefinition.field.label || "Default Value"
|
|
413
|
-
}) : null;
|
|
414
|
-
if (customDefaultValueField) {
|
|
415
|
-
fieldSettings.defaultValue = customDefaultValueField;
|
|
416
|
-
}
|
|
417
|
-
switch (resolvedType) {
|
|
418
|
-
case "text":
|
|
419
|
-
case "textarea":
|
|
420
|
-
if (!customDefaultValueField) {
|
|
421
|
-
fieldSettings.defaultValue = {
|
|
422
|
-
type: resolvedType,
|
|
423
|
-
label: "Default Value"
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
break;
|
|
427
|
-
case "number":
|
|
428
|
-
if (!customDefaultValueField) {
|
|
429
|
-
fieldSettings.defaultValue = {
|
|
430
|
-
type: resolvedType,
|
|
431
|
-
label: "Default Value"
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
fieldSettings.min = {
|
|
435
|
-
type: resolvedType,
|
|
436
|
-
label: "Minimum Value"
|
|
437
|
-
};
|
|
438
|
-
fieldSettings.max = {
|
|
439
|
-
type: resolvedType,
|
|
440
|
-
label: "Maximum Value"
|
|
441
|
-
};
|
|
442
|
-
fieldSettings.step = {
|
|
443
|
-
type: resolvedType,
|
|
444
|
-
label: "Step Size"
|
|
445
|
-
};
|
|
446
|
-
break;
|
|
447
|
-
case "radio":
|
|
448
|
-
case "select": {
|
|
449
|
-
const selectOptions = (currentFieldSettings == null ? void 0 : currentFieldSettings.options) || [];
|
|
450
|
-
if (!customDefaultValueField) {
|
|
451
|
-
fieldSettings.defaultValue = {
|
|
452
|
-
type: "custom",
|
|
453
|
-
label: "Default Value",
|
|
454
|
-
render: ({ value, onChange, id }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
455
|
-
import_puck.AutoField,
|
|
456
|
-
{
|
|
457
|
-
field: {
|
|
458
|
-
type: resolvedType,
|
|
459
|
-
label: "Default Value",
|
|
460
|
-
options: selectOptions
|
|
461
|
-
},
|
|
462
|
-
value,
|
|
463
|
-
onChange,
|
|
464
|
-
readOnly: false,
|
|
465
|
-
id
|
|
466
|
-
}
|
|
467
|
-
)
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
fieldSettings.options = {
|
|
471
|
-
type: "array",
|
|
472
|
-
label: "Options",
|
|
473
|
-
defaultItemProps: {
|
|
474
|
-
label: "New Option",
|
|
475
|
-
value: "new"
|
|
476
|
-
},
|
|
477
|
-
arrayFields: {
|
|
478
|
-
label: { type: "text", label: "Label" },
|
|
479
|
-
value: {
|
|
480
|
-
type: "text",
|
|
481
|
-
label: "Value"
|
|
482
|
-
}
|
|
483
|
-
},
|
|
484
|
-
getItemSummary(item, index) {
|
|
485
|
-
return item.label || `Option ${(index || 0) + 1}`;
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
case "array":
|
|
491
|
-
case "object":
|
|
492
|
-
fieldSettings.subFields = {
|
|
493
|
-
type: "array",
|
|
494
|
-
label: "Sub Fields",
|
|
495
|
-
defaultItemProps: {
|
|
496
|
-
name: "New Sub Field",
|
|
497
|
-
type: "text"
|
|
498
|
-
},
|
|
499
|
-
arrayFields: {
|
|
500
|
-
name: { type: "text", label: "Name" },
|
|
501
|
-
type: {
|
|
502
|
-
type: "select",
|
|
503
|
-
options: deep ? [
|
|
504
|
-
{
|
|
505
|
-
label: "Text",
|
|
506
|
-
value: "text"
|
|
507
|
-
},
|
|
508
|
-
{
|
|
509
|
-
label: "Number",
|
|
510
|
-
value: "number"
|
|
511
|
-
},
|
|
512
|
-
{
|
|
513
|
-
label: "Select",
|
|
514
|
-
value: "select"
|
|
515
|
-
},
|
|
516
|
-
{
|
|
517
|
-
label: "Radio",
|
|
518
|
-
value: "radio"
|
|
519
|
-
},
|
|
520
|
-
...customTypeOptions
|
|
521
|
-
] : [
|
|
522
|
-
{
|
|
523
|
-
label: "Text",
|
|
524
|
-
value: "text"
|
|
525
|
-
},
|
|
526
|
-
{
|
|
527
|
-
label: "Number",
|
|
528
|
-
value: "number"
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
label: "Select",
|
|
532
|
-
value: "select"
|
|
533
|
-
},
|
|
534
|
-
{
|
|
535
|
-
label: "Radio",
|
|
536
|
-
value: "radio"
|
|
537
|
-
},
|
|
538
|
-
{
|
|
539
|
-
label: "Array",
|
|
540
|
-
value: "array"
|
|
541
|
-
},
|
|
542
|
-
{
|
|
543
|
-
label: "Object",
|
|
544
|
-
value: "object"
|
|
545
|
-
},
|
|
546
|
-
{
|
|
547
|
-
label: "Reference",
|
|
548
|
-
value: "reference"
|
|
549
|
-
},
|
|
550
|
-
...customTypeOptions
|
|
551
|
-
]
|
|
552
|
-
}
|
|
553
|
-
},
|
|
554
|
-
getItemSummary(item, index) {
|
|
555
|
-
return item.name || `Field ${(index || 0) + 1}`;
|
|
556
|
-
}
|
|
557
|
-
};
|
|
558
|
-
if (!deep)
|
|
559
|
-
fieldSettings.subFieldSettings = {
|
|
560
|
-
type: "object",
|
|
561
|
-
label: "Sub Field Settings",
|
|
562
|
-
objectFields: resolvedSubFields ? getFieldSettings(
|
|
563
|
-
resolvedSubFields,
|
|
564
|
-
resolvedSubFieldSettings,
|
|
565
|
-
customFields,
|
|
566
|
-
true
|
|
567
|
-
) : {}
|
|
568
|
-
};
|
|
569
|
-
if (resolvedType === "array") {
|
|
570
|
-
if (!customDefaultValueField) {
|
|
571
|
-
fieldSettings.defaultValue = {
|
|
572
|
-
type: "array",
|
|
573
|
-
label: "Default Items",
|
|
574
|
-
arrayFields: buildDefaultEditorFields(
|
|
575
|
-
resolvedSubFields,
|
|
576
|
-
resolvedSubFieldSettings,
|
|
577
|
-
customFields
|
|
578
|
-
),
|
|
579
|
-
defaultItemProps: buildArrayDefaultItemProps(
|
|
580
|
-
resolvedSubFields,
|
|
581
|
-
resolvedSubFieldSettings
|
|
582
|
-
),
|
|
583
|
-
getItemSummary(item, index) {
|
|
584
|
-
return getArrayItemSummary(item, index, currentFieldSettings);
|
|
585
|
-
}
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
fieldSettings.min = {
|
|
589
|
-
type: "number",
|
|
590
|
-
label: "Minimum Items"
|
|
591
|
-
};
|
|
592
|
-
fieldSettings.max = {
|
|
593
|
-
type: "number",
|
|
594
|
-
label: "Maximum Items"
|
|
595
|
-
};
|
|
596
|
-
fieldSettings.summary = {
|
|
597
|
-
type: "select",
|
|
598
|
-
label: "Summary",
|
|
599
|
-
options: [
|
|
600
|
-
{
|
|
601
|
-
label: "Default Numbering / Count",
|
|
602
|
-
value: "count"
|
|
603
|
-
},
|
|
604
|
-
{
|
|
605
|
-
label: "Field",
|
|
606
|
-
value: "field"
|
|
607
|
-
},
|
|
608
|
-
{
|
|
609
|
-
label: "Expression",
|
|
610
|
-
value: "expression"
|
|
611
|
-
}
|
|
612
|
-
]
|
|
613
|
-
};
|
|
614
|
-
if ((currentFieldSettings == null ? void 0 : currentFieldSettings.summary) === "field") {
|
|
615
|
-
fieldSettings.summaryField = {
|
|
616
|
-
type: "select",
|
|
617
|
-
label: "Summary Field",
|
|
618
|
-
options: [
|
|
619
|
-
{
|
|
620
|
-
label: "Select a field",
|
|
621
|
-
value: ""
|
|
622
|
-
},
|
|
623
|
-
...resolvedSubFields.filter((subField) => isPrimitiveFieldType(subField.type)).map((subField) => ({
|
|
624
|
-
label: subField.name,
|
|
625
|
-
value: subField.name
|
|
626
|
-
}))
|
|
627
|
-
]
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
if ((currentFieldSettings == null ? void 0 : currentFieldSettings.summary) === "expression") {
|
|
631
|
-
fieldSettings.summaryExpression = {
|
|
632
|
-
type: "text",
|
|
633
|
-
label: "Summary Expression"
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
break;
|
|
638
|
-
}
|
|
639
|
-
const overriddenFieldSettings = (customFieldDefinition == null ? void 0 : customFieldDefinition.fieldSettingsOverride) ? customFieldDefinition.fieldSettingsOverride({
|
|
640
|
-
fieldName: field.name,
|
|
641
|
-
fieldType: field.type,
|
|
642
|
-
fieldSettings: currentFieldSettings,
|
|
643
|
-
originalFieldSettings: fieldSettings
|
|
644
|
-
}) : fieldSettings;
|
|
645
|
-
fields[field.name] = {
|
|
646
|
-
type: "object",
|
|
647
|
-
label: field.name,
|
|
648
|
-
objectFields: overriddenFieldSettings
|
|
649
|
-
};
|
|
650
|
-
return fields;
|
|
651
|
-
}, {});
|
|
652
|
-
};
|
|
653
|
-
var get_field_settings_default = getFieldSettings;
|
|
654
|
-
|
|
655
|
-
// src/puck/context/useStore.ts
|
|
656
|
-
var import_react = require("react");
|
|
657
|
-
var import_zustand = require("zustand");
|
|
658
|
-
var appStoreContext = (0, import_react.createContext)(null);
|
|
659
|
-
var createUseSoftConfig = () => {
|
|
660
|
-
return function useSoftConfig2(selector, equalityFn) {
|
|
661
|
-
const context = (0, import_react.useContext)(appStoreContext);
|
|
662
|
-
if (!context) {
|
|
663
|
-
throw new Error(
|
|
664
|
-
"useSoftConfig must be used inside a SoftConfigProvider. Wrap your tree with <SoftConfigProvider value={store}>"
|
|
665
|
-
);
|
|
666
|
-
}
|
|
667
|
-
if (equalityFn) {
|
|
668
|
-
return (0, import_zustand.useStore)(context, selector, equalityFn);
|
|
669
|
-
}
|
|
670
|
-
return (0, import_zustand.useStore)(context, selector);
|
|
671
|
-
};
|
|
672
|
-
};
|
|
673
|
-
var useSoftConfig = createUseSoftConfig();
|
|
674
|
-
var useSoftConfigStore = () => {
|
|
675
|
-
const context = (0, import_react.useContext)(appStoreContext);
|
|
676
|
-
if (!context) {
|
|
677
|
-
throw new Error(
|
|
678
|
-
"useSoftConfigStore must be used inside a SoftConfigProvider."
|
|
679
|
-
);
|
|
680
|
-
}
|
|
681
|
-
return context;
|
|
682
|
-
};
|
|
683
|
-
|
|
684
237
|
// src/puck/lib/apply-mapping.ts
|
|
685
|
-
var
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
let cur = props;
|
|
692
|
-
for (const p of parts) {
|
|
693
|
-
if (typeof cur[p] !== "object" || cur[p] === null) cur[p] = {};
|
|
694
|
-
cur = cur[p];
|
|
238
|
+
var pathSegmentsCache = /* @__PURE__ */ new Map();
|
|
239
|
+
var getPathSegments = (path) => {
|
|
240
|
+
let segments = pathSegmentsCache.get(path);
|
|
241
|
+
if (!segments) {
|
|
242
|
+
segments = path.split(".");
|
|
243
|
+
pathSegmentsCache.set(path, segments);
|
|
695
244
|
}
|
|
696
|
-
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
// src/puck/lib/apply-mapping.ts
|
|
245
|
+
return segments;
|
|
246
|
+
};
|
|
700
247
|
var resolveValueByPath = (source, path) => {
|
|
701
248
|
if (!path) return source;
|
|
702
|
-
const segments = path
|
|
249
|
+
const segments = getPathSegments(path);
|
|
703
250
|
const resolveSegments = (current, index) => {
|
|
704
251
|
if (current === null || current === void 0) return void 0;
|
|
705
252
|
if (index >= segments.length) return current;
|
|
@@ -718,7 +265,7 @@ var resolveValueByPath = (source, path) => {
|
|
|
718
265
|
};
|
|
719
266
|
var resolveFieldSettingEntryByPath = (settings, path) => {
|
|
720
267
|
if (!path) return void 0;
|
|
721
|
-
const segments = path
|
|
268
|
+
const segments = getPathSegments(path);
|
|
722
269
|
let currentSettings = settings;
|
|
723
270
|
let currentEntry;
|
|
724
271
|
for (const segmentWithArraySuffix of segments) {
|
|
@@ -736,11 +283,11 @@ var resolveFieldSettingEntryByPath = (settings, path) => {
|
|
|
736
283
|
};
|
|
737
284
|
function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings", options) {
|
|
738
285
|
var _a, _b, _c;
|
|
739
|
-
|
|
286
|
+
let newProps = props;
|
|
740
287
|
const sourceProps = (_a = options == null ? void 0 : options.sourceProps) != null ? _a : props;
|
|
741
288
|
const mappedArrayPaths = /* @__PURE__ */ new Set();
|
|
742
289
|
let changed = false;
|
|
743
|
-
const
|
|
290
|
+
const arrayRulesMap = /* @__PURE__ */ new Map();
|
|
744
291
|
for (const entry of map) {
|
|
745
292
|
const { from, to, transform } = entry;
|
|
746
293
|
if (!from || !to) continue;
|
|
@@ -779,43 +326,21 @@ function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings",
|
|
|
779
326
|
if (isSingleArrayTarget) {
|
|
780
327
|
const toPath = toPaths[0];
|
|
781
328
|
const arrayBase = getArrayBasePath(toPath);
|
|
782
|
-
const subProp = getArrayItemSubPath(toPath) || "";
|
|
783
329
|
if (!arrayBase) continue;
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
const sourceArray = isFromArrayPath ? Array.isArray(result) ? result : result !== void 0 ? [result] : [] : Array.isArray(result) ? result : defaultArray.map(() => result);
|
|
789
|
-
let defaults = entry.unmappedArrayItemDefaultValues || entry.defaultOverrides || {};
|
|
790
|
-
if (typeof defaults === "string") {
|
|
791
|
-
try {
|
|
792
|
-
defaults = JSON.parse(defaults);
|
|
793
|
-
} catch (e) {
|
|
794
|
-
defaults = {};
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
const targetLength = sourceArray.length;
|
|
798
|
-
const constructed = Array.from({ length: targetLength }).map((_, idx) => {
|
|
799
|
-
const mappedValue = sourceArray[idx];
|
|
800
|
-
const defaultItem = defaultArray[idx] && typeof defaultArray[idx] === "object" ? defaultArray[idx] : {};
|
|
801
|
-
const currentItem = currentArray[idx] && typeof currentArray[idx] === "object" ? currentArray[idx] : {};
|
|
802
|
-
const item = __spreadValues(__spreadValues(__spreadValues({}, defaultItem), defaults), currentItem);
|
|
803
|
-
if (subProp && mappedValue !== void 0) {
|
|
804
|
-
setPropertyByPath(item, subProp, mappedValue);
|
|
805
|
-
}
|
|
806
|
-
return item;
|
|
807
|
-
});
|
|
808
|
-
const originalArray = resolveValueByPath(newProps, arrayBase);
|
|
809
|
-
if (!(0, import_react_fast_compare.default)(originalArray, constructed)) {
|
|
810
|
-
setPropertyByPath(newProps, arrayBase, constructed);
|
|
811
|
-
changedArrayBases.add(arrayBase);
|
|
330
|
+
let rules = arrayRulesMap.get(arrayBase);
|
|
331
|
+
if (!rules) {
|
|
332
|
+
rules = [];
|
|
333
|
+
arrayRulesMap.set(arrayBase, rules);
|
|
812
334
|
}
|
|
335
|
+
rules.push({ entry, toPath, fromPaths, result });
|
|
813
336
|
mappedArrayPaths.add(arrayBase);
|
|
814
|
-
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (toPaths.length === 1 && Array.isArray(result) && toPaths[0].includes("array")) {
|
|
815
340
|
const toPath = toPaths[0];
|
|
816
341
|
const original = resolveValueByPath(newProps, toPath);
|
|
817
342
|
if (!(0, import_react_fast_compare.default)(original, result)) {
|
|
818
|
-
|
|
343
|
+
newProps = setImmutablePropertyByPath(newProps, toPath, result);
|
|
819
344
|
changed = true;
|
|
820
345
|
}
|
|
821
346
|
} else if (Array.isArray(result) && toPaths.length > 1) {
|
|
@@ -823,7 +348,7 @@ function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings",
|
|
|
823
348
|
if (toPaths[idx]) {
|
|
824
349
|
const orig = resolveValueByPath(newProps, toPaths[idx]);
|
|
825
350
|
if (!(0, import_react_fast_compare.default)(orig, val)) {
|
|
826
|
-
|
|
351
|
+
newProps = setImmutablePropertyByPath(newProps, toPaths[idx], val);
|
|
827
352
|
changed = true;
|
|
828
353
|
}
|
|
829
354
|
}
|
|
@@ -832,565 +357,231 @@ function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings",
|
|
|
832
357
|
const finalValue = result;
|
|
833
358
|
const originalValue = resolveValueByPath(newProps, toPaths[0]);
|
|
834
359
|
if (!(0, import_react_fast_compare.default)(originalValue, finalValue)) {
|
|
835
|
-
|
|
360
|
+
newProps = setImmutablePropertyByPath(newProps, toPaths[0], finalValue);
|
|
836
361
|
changed = true;
|
|
837
362
|
}
|
|
838
363
|
}
|
|
839
364
|
}
|
|
840
|
-
const
|
|
841
|
-
(arrayBase)
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
};
|
|
862
|
-
var builderRootConfig = (config, overrides, editingComponent, showVersionFields = true, customFields) => {
|
|
863
|
-
const customTypeOptions = getCustomFieldTypeOptions(customFields);
|
|
864
|
-
return {
|
|
865
|
-
fields: __spreadValues({
|
|
866
|
-
_name: overrides.name || {
|
|
867
|
-
type: "text",
|
|
868
|
-
label: "Soft Component Name"
|
|
869
|
-
},
|
|
870
|
-
_category: overrides.categories || {
|
|
871
|
-
type: "select",
|
|
872
|
-
label: "Category",
|
|
873
|
-
options: [
|
|
874
|
-
...Object.keys(config.categories || {}).map((cat) => {
|
|
875
|
-
var _a;
|
|
876
|
-
return {
|
|
877
|
-
label: ((_a = config.categories) == null ? void 0 : _a[cat].title) || cat,
|
|
878
|
-
value: cat
|
|
879
|
-
};
|
|
880
|
-
}) || [],
|
|
881
|
-
{
|
|
882
|
-
label: Object.keys(config.categories || {}).length ? "Other" : "Uncategorized",
|
|
883
|
-
value: void 0
|
|
884
|
-
}
|
|
885
|
-
]
|
|
886
|
-
},
|
|
887
|
-
_fields: {
|
|
888
|
-
type: "array",
|
|
889
|
-
label: "Fields",
|
|
890
|
-
defaultItemProps: {
|
|
891
|
-
name: "New Field",
|
|
892
|
-
type: "text"
|
|
893
|
-
},
|
|
894
|
-
getItemSummary(item, index) {
|
|
895
|
-
return item.name || `Field ${(index || 0) + 1}`;
|
|
896
|
-
},
|
|
897
|
-
arrayFields: {
|
|
898
|
-
name: { type: "text", label: "Name" },
|
|
899
|
-
type: {
|
|
900
|
-
type: "select",
|
|
901
|
-
label: "Type",
|
|
902
|
-
options: [
|
|
903
|
-
{ label: "Text", value: "text" },
|
|
904
|
-
{ label: "Textarea", value: "textarea" },
|
|
905
|
-
{ label: "Number", value: "number" },
|
|
906
|
-
{ label: "Select", value: "select" },
|
|
907
|
-
{ label: "Radio", value: "radio" },
|
|
908
|
-
{ label: "Array", value: "array" },
|
|
909
|
-
{ label: "Object", value: "object" },
|
|
910
|
-
// { label: "Reference", value: "reference" },
|
|
911
|
-
...customTypeOptions
|
|
912
|
-
]
|
|
365
|
+
for (const [arrayBase, rules] of arrayRulesMap.entries()) {
|
|
366
|
+
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] : [];
|
|
367
|
+
const currentArrayAtPath = resolveValueByPath(newProps, arrayBase);
|
|
368
|
+
const currentArray = Array.isArray(currentArrayAtPath) ? currentArrayAtPath : [];
|
|
369
|
+
let targetLength = 0;
|
|
370
|
+
const ruleSourceArrays = rules.map(({ entry, fromPaths, result }) => {
|
|
371
|
+
const isFromArrayPath = typeof fromPaths[0] === "string" && isArrayMappingPath(fromPaths[0]);
|
|
372
|
+
const sourceArray = isFromArrayPath ? Array.isArray(result) ? result : result !== void 0 ? [result] : [] : Array.isArray(result) ? result : defaultArray.map(() => result);
|
|
373
|
+
targetLength = Math.max(targetLength, sourceArray.length);
|
|
374
|
+
return sourceArray;
|
|
375
|
+
});
|
|
376
|
+
const constructed = Array.from({ length: targetLength }).map((_, idx) => {
|
|
377
|
+
const defaultItem = defaultArray[idx] && typeof defaultArray[idx] === "object" ? defaultArray[idx] : {};
|
|
378
|
+
const currentItem = currentArray[idx] && typeof currentArray[idx] === "object" ? currentArray[idx] : {};
|
|
379
|
+
let mergedDefaults = {};
|
|
380
|
+
for (const rule of rules) {
|
|
381
|
+
let ruleDefaults = rule.entry.unmappedArrayItemDefaultValues || rule.entry.defaultOverrides || {};
|
|
382
|
+
if (typeof ruleDefaults === "string") {
|
|
383
|
+
try {
|
|
384
|
+
ruleDefaults = JSON.parse(ruleDefaults);
|
|
385
|
+
} catch (e) {
|
|
913
386
|
}
|
|
914
387
|
}
|
|
388
|
+
mergedDefaults = __spreadValues(__spreadValues({}, mergedDefaults), ruleDefaults);
|
|
915
389
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
const
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
if (rootFields.length) {
|
|
925
|
-
newFields._fieldSettings = {
|
|
926
|
-
type: "object",
|
|
927
|
-
label: "Field Settings",
|
|
928
|
-
objectFields: get_field_settings_default(
|
|
929
|
-
rootFields,
|
|
930
|
-
rootFieldSettings,
|
|
931
|
-
customFields
|
|
932
|
-
)
|
|
933
|
-
};
|
|
934
|
-
} else {
|
|
935
|
-
delete newFields._fieldSettings;
|
|
390
|
+
const baseItem = __spreadValues(__spreadValues({}, defaultItem), mergedDefaults);
|
|
391
|
+
let newItem = void 0;
|
|
392
|
+
for (const key of Object.keys(baseItem)) {
|
|
393
|
+
if (!(key in currentItem) && baseItem[key] !== void 0) {
|
|
394
|
+
if (!newItem) newItem = __spreadValues({}, currentItem);
|
|
395
|
+
if (newItem) {
|
|
396
|
+
newItem[key] = baseItem[key];
|
|
397
|
+
}
|
|
936
398
|
}
|
|
937
399
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
// } = {
|
|
948
|
-
// props,
|
|
949
|
-
// readOnly: undefined,
|
|
950
|
-
// };
|
|
951
|
-
// return result;
|
|
952
|
-
// },
|
|
953
|
-
render: (props) => {
|
|
954
|
-
const fieldSettings = props == null ? void 0 : props._fieldSettings;
|
|
955
|
-
const data = useCustomPuck((s) => s.appState.data);
|
|
956
|
-
const dispatch = useCustomPuck((s) => s.dispatch);
|
|
957
|
-
const getSelectorForId = useCustomPuck((s) => s.getSelectorForId);
|
|
958
|
-
const setVersion = useSoftConfig((s) => s.builder.setVersion);
|
|
959
|
-
const state = useSoftConfig((s) => s.state);
|
|
960
|
-
(0, import_react2.useEffect)(() => {
|
|
961
|
-
if (!fieldSettings || Object.keys(fieldSettings).length === 0) return;
|
|
962
|
-
const replacements = [];
|
|
963
|
-
(0, import_puck2.walkTree)(
|
|
964
|
-
{
|
|
965
|
-
content: (data == null ? void 0 : data.content) || [],
|
|
966
|
-
root: (data == null ? void 0 : data.root) || {}
|
|
967
|
-
},
|
|
968
|
-
{
|
|
969
|
-
components: config.components
|
|
970
|
-
},
|
|
971
|
-
(content) => content.map((child) => {
|
|
972
|
-
var _a;
|
|
973
|
-
const map = ((_a = child.props) == null ? void 0 : _a._map) || [];
|
|
974
|
-
if (!map.length) return child;
|
|
975
|
-
const cleanProps = getSerializableProps(child.props);
|
|
976
|
-
const { newProps, changed } = applyMapping(
|
|
977
|
-
cleanProps,
|
|
978
|
-
fieldSettings,
|
|
979
|
-
map,
|
|
980
|
-
"fieldSettings"
|
|
981
|
-
);
|
|
982
|
-
if (!changed || (0, import_react_fast_compare2.default)(cleanProps, newProps)) return child;
|
|
983
|
-
replacements.push({
|
|
984
|
-
id: child.props.id,
|
|
985
|
-
data: __spreadProps(__spreadValues({}, child), { props: newProps })
|
|
986
|
-
});
|
|
987
|
-
return child;
|
|
988
|
-
})
|
|
989
|
-
);
|
|
990
|
-
if (!replacements.length) return;
|
|
991
|
-
replacements.forEach((replacement) => {
|
|
992
|
-
const itemSelector = getSelectorForId(replacement.id);
|
|
993
|
-
if (!itemSelector) return;
|
|
994
|
-
dispatch({
|
|
995
|
-
type: "replace",
|
|
996
|
-
data: replacement.data,
|
|
997
|
-
destinationIndex: itemSelector.index,
|
|
998
|
-
destinationZone: itemSelector.zone
|
|
999
|
-
});
|
|
1000
|
-
});
|
|
1001
|
-
}, [fieldSettings, data, dispatch, getSelectorForId]);
|
|
1002
|
-
(0, import_react2.useEffect)(() => {
|
|
1003
|
-
var _a;
|
|
1004
|
-
if (state !== "remodeling" || !(props == null ? void 0 : props._version) || !(props == null ? void 0 : props._name)) return;
|
|
1005
|
-
const currentVersion = props._version;
|
|
1006
|
-
if (((_a = props._versions) == null ? void 0 : _a.includes(currentVersion)) && props._versions.length > 1) {
|
|
1007
|
-
setVersion(props._name, currentVersion, props, dispatch);
|
|
400
|
+
for (let i = 0; i < rules.length; i++) {
|
|
401
|
+
const { toPath } = rules[i];
|
|
402
|
+
const subProp = getArrayItemSubPath(toPath) || "";
|
|
403
|
+
const mappedValue = ruleSourceArrays[i][idx];
|
|
404
|
+
if (subProp && mappedValue !== void 0) {
|
|
405
|
+
const existingValue = resolveValueByPath(newItem || currentItem, subProp);
|
|
406
|
+
if (!(0, import_react_fast_compare.default)(existingValue, mappedValue)) {
|
|
407
|
+
newItem = setImmutablePropertyByPath(newItem || currentItem, subProp, mappedValue);
|
|
408
|
+
}
|
|
1008
409
|
}
|
|
1009
|
-
}, [props == null ? void 0 : props._version]);
|
|
1010
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: props.children });
|
|
1011
|
-
}
|
|
1012
|
-
};
|
|
1013
|
-
};
|
|
1014
|
-
|
|
1015
|
-
// src/puck/lib/builder/generate-field-options.ts
|
|
1016
|
-
var hasArrayMappingPath = (value) => value.includes("[]");
|
|
1017
|
-
var isBareArrayPath = (value) => !hasArrayMappingPath(value) && !value.includes(".");
|
|
1018
|
-
function filterToOptionsForFrom(fromPath, toOptions) {
|
|
1019
|
-
if (!fromPath) return toOptions;
|
|
1020
|
-
const fromHasArrayMapping = hasArrayMappingPath(fromPath);
|
|
1021
|
-
const fromIsBareArray = isBareArrayPath(fromPath);
|
|
1022
|
-
return toOptions.filter((option) => {
|
|
1023
|
-
const optionHasArrayMapping = hasArrayMappingPath(option.value);
|
|
1024
|
-
if (fromHasArrayMapping) {
|
|
1025
|
-
return optionHasArrayMapping;
|
|
1026
|
-
}
|
|
1027
|
-
if (fromIsBareArray) {
|
|
1028
|
-
return isBareArrayPath(option.value);
|
|
1029
|
-
}
|
|
1030
|
-
return !optionHasArrayMapping;
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
|
-
function generateFieldOptions(fields, prefix = "") {
|
|
1034
|
-
const opts = [];
|
|
1035
|
-
function recurse(current, prefix2) {
|
|
1036
|
-
Object.entries(current).forEach(([key, fld]) => {
|
|
1037
|
-
if (fld.type === "slot") return;
|
|
1038
|
-
if (key === "_map") return;
|
|
1039
|
-
if (key === "_slotEnabled") return;
|
|
1040
|
-
const path = prefix2 ? `${prefix2}.${key}` : key;
|
|
1041
|
-
if (fld.type === "object" && fld.objectFields) {
|
|
1042
|
-
recurse(fld.objectFields, path);
|
|
1043
|
-
} else if (fld.type === "array" && fld.arrayFields) {
|
|
1044
|
-
recurse(
|
|
1045
|
-
fld.arrayFields,
|
|
1046
|
-
path + "[]"
|
|
1047
|
-
);
|
|
1048
|
-
} else {
|
|
1049
|
-
opts.push({ label: path, value: path, type: fld.type });
|
|
1050
410
|
}
|
|
411
|
+
return newItem !== void 0 ? newItem : currentItem;
|
|
1051
412
|
});
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
if (!_fields) return opts;
|
|
1059
|
-
function recurse(fields, fieldSettings, currentPrefix) {
|
|
1060
|
-
fields.forEach((field) => {
|
|
1061
|
-
var _a;
|
|
1062
|
-
const settings = fieldSettings[field.name];
|
|
1063
|
-
const customReturnType = resolveCustomFieldReturnType(
|
|
1064
|
-
field.type,
|
|
1065
|
-
customFields
|
|
1066
|
-
);
|
|
1067
|
-
const path = currentPrefix ? `${currentPrefix}.${field.name}` : field.name;
|
|
1068
|
-
if (customReturnType) {
|
|
1069
|
-
if (customReturnType === "array" || customReturnType === "object") {
|
|
1070
|
-
const customSchema = resolveCustomFieldSchema(field.type, customFields);
|
|
1071
|
-
if (!customSchema) {
|
|
1072
|
-
return;
|
|
1073
|
-
}
|
|
1074
|
-
recurse(
|
|
1075
|
-
customSchema.subFields,
|
|
1076
|
-
customSchema.subFieldSettings,
|
|
1077
|
-
path + (customReturnType === "array" ? "[]" : "")
|
|
1078
|
-
);
|
|
1079
|
-
return;
|
|
413
|
+
let arrayChanged = currentArray.length !== constructed.length;
|
|
414
|
+
if (!arrayChanged) {
|
|
415
|
+
for (let i = 0; i < currentArray.length; i++) {
|
|
416
|
+
if (currentArray[i] !== constructed[i]) {
|
|
417
|
+
arrayChanged = true;
|
|
418
|
+
break;
|
|
1080
419
|
}
|
|
1081
|
-
opts.push({
|
|
1082
|
-
label: path,
|
|
1083
|
-
value: path,
|
|
1084
|
-
type: mapCustomReturnTypeToMappingType(customReturnType)
|
|
1085
|
-
});
|
|
1086
|
-
return;
|
|
1087
|
-
}
|
|
1088
|
-
if (!isBuiltInSoftFieldType(field.type)) {
|
|
1089
|
-
return;
|
|
1090
|
-
}
|
|
1091
|
-
if ((_a = settings == null ? void 0 : settings.subFields) == null ? void 0 : _a.length) {
|
|
1092
|
-
recurse(
|
|
1093
|
-
settings.subFields,
|
|
1094
|
-
settings.subFieldSettings || {},
|
|
1095
|
-
path + (field.type === "array" ? "[]" : "")
|
|
1096
|
-
);
|
|
1097
|
-
} else if (field.type !== "array" && field.type !== "object") {
|
|
1098
|
-
opts.push({ label: path, value: path, type: field.type });
|
|
1099
420
|
}
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
recurse(_fields, _fieldSettings || {}, prefix);
|
|
1103
|
-
return opts;
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
// src/puck/components/error-boundary/index.tsx
|
|
1107
|
-
var import_react3 = require("react");
|
|
1108
|
-
|
|
1109
|
-
// src/puck/lib/get-class-name-factory.ts
|
|
1110
|
-
var import_classnames = __toESM(require("classnames"));
|
|
1111
|
-
var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
|
|
1112
|
-
if (typeof options === "string") {
|
|
1113
|
-
const descendant = options;
|
|
1114
|
-
const style = styles[`${rootClass}-${descendant}`];
|
|
1115
|
-
if (style) {
|
|
1116
|
-
return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
|
|
1117
421
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
const prefixedModifiers = {};
|
|
1122
|
-
for (let modifier in modifiers) {
|
|
1123
|
-
prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
|
|
422
|
+
if (arrayChanged) {
|
|
423
|
+
newProps = setImmutablePropertyByPath(newProps, arrayBase, constructed);
|
|
424
|
+
changed = true;
|
|
1124
425
|
}
|
|
1125
|
-
const c = styles[rootClass];
|
|
1126
|
-
return config.baseClass + (0, import_classnames.default)(__spreadValues({
|
|
1127
|
-
[c]: !!c
|
|
1128
|
-
}, prefixedModifiers));
|
|
1129
|
-
} else {
|
|
1130
|
-
return config.baseClass + styles[rootClass] || "";
|
|
1131
426
|
}
|
|
1132
|
-
};
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
|
|
1136
|
-
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" };
|
|
427
|
+
return { newProps, mappedArrayPaths, changed };
|
|
428
|
+
}
|
|
1137
429
|
|
|
1138
|
-
// src/puck/
|
|
1139
|
-
var
|
|
1140
|
-
|
|
1141
|
-
var
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
})
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
error
|
|
1159
|
-
};
|
|
430
|
+
// src/puck/lib/root-action-handler.ts
|
|
431
|
+
var currentGeneration = 0;
|
|
432
|
+
function hasDefaultValueChanged(prev, curr) {
|
|
433
|
+
var _a, _b;
|
|
434
|
+
if (!prev && !curr) return false;
|
|
435
|
+
if (!prev || !curr) return true;
|
|
436
|
+
if (!(0, import_react_fast_compare2.default)(prev == null ? void 0 : prev.defaultValue, curr == null ? void 0 : curr.defaultValue)) return true;
|
|
437
|
+
if ((prev == null ? void 0 : prev.subFieldSettings) || (curr == null ? void 0 : curr.subFieldSettings)) {
|
|
438
|
+
const subKeys = /* @__PURE__ */ new Set([
|
|
439
|
+
...Object.keys((prev == null ? void 0 : prev.subFieldSettings) || {}),
|
|
440
|
+
...Object.keys((curr == null ? void 0 : curr.subFieldSettings) || {})
|
|
441
|
+
]);
|
|
442
|
+
for (const subKey of subKeys) {
|
|
443
|
+
if (hasDefaultValueChanged(
|
|
444
|
+
(_a = prev == null ? void 0 : prev.subFieldSettings) == null ? void 0 : _a[subKey],
|
|
445
|
+
(_b = curr == null ? void 0 : curr.subFieldSettings) == null ? void 0 : _b[subKey]
|
|
446
|
+
)) {
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
1160
450
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
var processReplacements = (appState, get, fieldSettings, changedKeys, zones, nodes) => __async(null, null, function* () {
|
|
454
|
+
var _a, _b;
|
|
455
|
+
const generation = ++currentGeneration;
|
|
456
|
+
yield new Promise((resolve) => setTimeout(resolve, 150));
|
|
457
|
+
if (generation !== currentGeneration) return;
|
|
458
|
+
const { puckDispatch, editableComponentIds } = get();
|
|
459
|
+
if (!puckDispatch) return;
|
|
460
|
+
if (changedKeys.size === 0) return;
|
|
461
|
+
const replacements = [];
|
|
462
|
+
const editableSet = new Set(editableComponentIds || []);
|
|
463
|
+
const hasEditableFilter = editableSet.size > 0;
|
|
464
|
+
const nodeEntries = Object.entries(nodes);
|
|
465
|
+
for (let i = 0; i < nodeEntries.length; i++) {
|
|
466
|
+
if (generation !== currentGeneration) return;
|
|
467
|
+
if (i > 0 && i % 50 === 0) {
|
|
468
|
+
yield new Promise((resolve) => setTimeout(resolve, 0));
|
|
469
|
+
if (generation !== currentGeneration) return;
|
|
470
|
+
}
|
|
471
|
+
const [id, node] = nodeEntries[i];
|
|
472
|
+
if (hasEditableFilter && !editableSet.has(id)) {
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const map = ((_a = node.data.props) == null ? void 0 : _a._map) || [];
|
|
476
|
+
if (!map.length) continue;
|
|
477
|
+
let isAffected = false;
|
|
478
|
+
const flatProps = ((_b = node.flatData) == null ? void 0 : _b.props) || {};
|
|
479
|
+
for (const [flatKey, flatValue] of Object.entries(flatProps)) {
|
|
480
|
+
if (flatKey.includes("_map") && flatKey.includes("from") && typeof flatValue === "string") {
|
|
481
|
+
if (changedKeys.has(flatValue) || Array.from(changedKeys).some(
|
|
482
|
+
(ck) => flatValue.startsWith(ck + ".") || flatValue.startsWith(ck + "[")
|
|
483
|
+
)) {
|
|
484
|
+
isAffected = true;
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (!isAffected) continue;
|
|
490
|
+
const { newProps } = applyMapping(
|
|
491
|
+
__spreadValues({}, node.data.props),
|
|
492
|
+
fieldSettings,
|
|
493
|
+
map,
|
|
494
|
+
"fieldSettings"
|
|
495
|
+
);
|
|
496
|
+
replacements.push({
|
|
497
|
+
id,
|
|
498
|
+
data: __spreadProps(__spreadValues({}, node.data), {
|
|
499
|
+
props: __spreadValues(__spreadValues({}, node.data.props), newProps)
|
|
500
|
+
})
|
|
501
|
+
});
|
|
1163
502
|
}
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
503
|
+
if (!replacements.length) return;
|
|
504
|
+
requestAnimationFrame(() => {
|
|
505
|
+
replacements.forEach((replacement) => {
|
|
506
|
+
var _a2;
|
|
507
|
+
const node = nodes[replacement.id];
|
|
508
|
+
if (!node) return;
|
|
509
|
+
const zoneName = `${node.parentId}:${node.zone}`;
|
|
510
|
+
const index = (_a2 = zones[zoneName]) == null ? void 0 : _a2.contentIds.indexOf(replacement.id);
|
|
511
|
+
if (index !== void 0 && index !== -1) {
|
|
512
|
+
puckDispatch({
|
|
513
|
+
type: "replace",
|
|
514
|
+
destinationIndex: index,
|
|
515
|
+
destinationZone: zoneName,
|
|
516
|
+
data: replacement.data,
|
|
517
|
+
ui: void 0
|
|
518
|
+
});
|
|
1168
519
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
var processVersionChange = (rootProps, get, zones, nodes) => {
|
|
524
|
+
const currentVersion = rootProps._version;
|
|
525
|
+
const versions = rootProps._versions || [];
|
|
526
|
+
if (versions.includes(currentVersion) && versions.length > 1) {
|
|
527
|
+
const puckDispatch = get().puckDispatch;
|
|
528
|
+
if (puckDispatch) {
|
|
529
|
+
get().builder.setVersion(
|
|
530
|
+
rootProps._name,
|
|
531
|
+
currentVersion,
|
|
532
|
+
rootProps,
|
|
533
|
+
puckDispatch,
|
|
534
|
+
// Mock getItemBySelector using indexes
|
|
535
|
+
(selector) => {
|
|
536
|
+
var _a;
|
|
537
|
+
if (!selector.zone) return void 0;
|
|
538
|
+
const id = (_a = zones[selector.zone]) == null ? void 0 : _a.contentIds[selector.index];
|
|
539
|
+
return id ? nodes[id].data : void 0;
|
|
540
|
+
},
|
|
541
|
+
// Mock getSelectorForId using indexes
|
|
542
|
+
(id) => {
|
|
543
|
+
var _a;
|
|
544
|
+
const node = nodes[id];
|
|
545
|
+
if (!node) return void 0;
|
|
546
|
+
const index = (_a = zones[node.zone]) == null ? void 0 : _a.contentIds.indexOf(id);
|
|
547
|
+
return { zone: node.zone, index };
|
|
548
|
+
}
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
var rootActionHandler = (set, get) => (action, appState, previousState) => {
|
|
554
|
+
const storeState = get().state;
|
|
555
|
+
if (storeState !== "building" && storeState !== "remodeling" || action.type !== "replaceRoot") {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
const { zones, nodes } = appState.indexes;
|
|
559
|
+
const rootProps = appState.data.root.props;
|
|
560
|
+
const previousRootProps = (previousState == null ? void 0 : previousState.data.root).props;
|
|
561
|
+
const fieldSettings = rootProps == null ? void 0 : rootProps._fieldSettings;
|
|
562
|
+
const previousFieldSettings = previousRootProps == null ? void 0 : previousRootProps._fieldSettings;
|
|
563
|
+
if (fieldSettings) {
|
|
564
|
+
const changedKeys = /* @__PURE__ */ new Set();
|
|
565
|
+
const allKeys = /* @__PURE__ */ new Set([
|
|
566
|
+
...Object.keys(previousFieldSettings || {}),
|
|
567
|
+
...Object.keys(fieldSettings || {})
|
|
568
|
+
]);
|
|
569
|
+
for (const key of allKeys) {
|
|
570
|
+
if (hasDefaultValueChanged(previousFieldSettings == null ? void 0 : previousFieldSettings[key], fieldSettings == null ? void 0 : fieldSettings[key])) {
|
|
571
|
+
changedKeys.add(key);
|
|
1171
572
|
}
|
|
1172
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: getClassName(), children: [
|
|
1173
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: getClassName("title"), children: "Component Error" }),
|
|
1174
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("details", { className: getClassName("details"), children: [
|
|
1175
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("summary", { children: "Show error details" }),
|
|
1176
|
-
this.state.error && this.state.error.toString()
|
|
1177
|
-
] }),
|
|
1178
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1179
|
-
"button",
|
|
1180
|
-
{
|
|
1181
|
-
onClick: this.resetError,
|
|
1182
|
-
className: getClassName("button"),
|
|
1183
|
-
children: "Try Again"
|
|
1184
|
-
}
|
|
1185
|
-
)
|
|
1186
|
-
] });
|
|
1187
573
|
}
|
|
1188
|
-
|
|
574
|
+
if (changedKeys.size > 0) {
|
|
575
|
+
processReplacements(appState, get, fieldSettings, changedKeys, zones, nodes);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
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)) {
|
|
579
|
+
processVersionChange(rootProps, get, zones, nodes);
|
|
1189
580
|
}
|
|
1190
581
|
};
|
|
1191
582
|
|
|
1192
|
-
// src/puck/
|
|
1193
|
-
var
|
|
1194
|
-
var builderConfig = (config, overrides, editingComponent, showVersionFields = true, dependents, customFields) => ({
|
|
1195
|
-
root: builderRootConfig(
|
|
1196
|
-
config,
|
|
1197
|
-
overrides,
|
|
1198
|
-
editingComponent,
|
|
1199
|
-
showVersionFields,
|
|
1200
|
-
customFields
|
|
1201
|
-
),
|
|
1202
|
-
components: Object.entries(__spreadValues({}, config.components)).reduce(
|
|
1203
|
-
(acc, [name, component]) => {
|
|
1204
|
-
const tempComponent = __spreadProps(__spreadValues({}, component), {
|
|
1205
|
-
permissions: {
|
|
1206
|
-
insert: editingComponent !== name && !(dependents == null ? void 0 : dependents.has(name))
|
|
1207
|
-
},
|
|
1208
|
-
resolveFields(data, params) {
|
|
1209
|
-
return __async(this, null, function* () {
|
|
1210
|
-
var _a2;
|
|
1211
|
-
let fields = {};
|
|
1212
|
-
if (!fields._slot) {
|
|
1213
|
-
const slotFields = Object.entries(params.fields).filter(
|
|
1214
|
-
([_, field]) => field.type === "slot"
|
|
1215
|
-
);
|
|
1216
|
-
if (slotFields.length)
|
|
1217
|
-
fields._slot = {
|
|
1218
|
-
type: "array",
|
|
1219
|
-
label: "Enable Dropdown Slots",
|
|
1220
|
-
getItemSummary(item, index) {
|
|
1221
|
-
return item.slot || `Slot ${(index || 0) + 1}`;
|
|
1222
|
-
},
|
|
1223
|
-
arrayFields: {
|
|
1224
|
-
slot: {
|
|
1225
|
-
type: "select",
|
|
1226
|
-
label: "Slot",
|
|
1227
|
-
options: [
|
|
1228
|
-
{ label: "Select a slot", value: "" },
|
|
1229
|
-
...slotFields.filter(
|
|
1230
|
-
([fieldName, field]) => {
|
|
1231
|
-
var _a3;
|
|
1232
|
-
return field.type === "slot" && !(((_a3 = data.props) == null ? void 0 : _a3._slot) || []).some(
|
|
1233
|
-
(s) => s.slot === fieldName
|
|
1234
|
-
);
|
|
1235
|
-
}
|
|
1236
|
-
).map(([fieldName, field]) => ({
|
|
1237
|
-
label: field.label || fieldName,
|
|
1238
|
-
value: fieldName
|
|
1239
|
-
}))
|
|
1240
|
-
]
|
|
1241
|
-
},
|
|
1242
|
-
name: {
|
|
1243
|
-
type: "text",
|
|
1244
|
-
label: "Name",
|
|
1245
|
-
placeholder: "Optional Slot Name"
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
};
|
|
1249
|
-
}
|
|
1250
|
-
const defaultFields = component.resolveFields ? yield component.resolveFields(data, params) : component.fields || {};
|
|
1251
|
-
if (!fields._map || params.changed._map) {
|
|
1252
|
-
const rootProps = getRootProps(params.appState);
|
|
1253
|
-
const fromOptions = generateDynamicFieldOptions(
|
|
1254
|
-
(rootProps == null ? void 0 : rootProps._fields) || [],
|
|
1255
|
-
(rootProps == null ? void 0 : rootProps._fieldSettings) || {},
|
|
1256
|
-
customFields
|
|
1257
|
-
);
|
|
1258
|
-
const toOptionsFields = component.resolveFields && ((_a2 = data.props) == null ? void 0 : _a2._map) ? yield component.resolveFields(
|
|
1259
|
-
__spreadProps(__spreadValues({}, data), { props: __spreadProps(__spreadValues({}, data.props), { _map: void 0 }) }),
|
|
1260
|
-
params
|
|
1261
|
-
) : defaultFields;
|
|
1262
|
-
const toOptions = generateFieldOptions(toOptionsFields);
|
|
1263
|
-
fields._map = overrides.map ? {
|
|
1264
|
-
type: "custom",
|
|
1265
|
-
render: ({ value, onChange, id }) => {
|
|
1266
|
-
const rootProps2 = getRootProps(params.appState);
|
|
1267
|
-
return overrides.map({
|
|
1268
|
-
rootProps: rootProps2,
|
|
1269
|
-
value,
|
|
1270
|
-
onChange,
|
|
1271
|
-
id,
|
|
1272
|
-
props: data.props || {},
|
|
1273
|
-
fromOptions,
|
|
1274
|
-
toOptions
|
|
1275
|
-
});
|
|
1276
|
-
}
|
|
1277
|
-
} : (() => {
|
|
1278
|
-
var _a3;
|
|
1279
|
-
const mapEntries = ((_a3 = data.props) == null ? void 0 : _a3._map) || [];
|
|
1280
|
-
const toPaths = mapEntries.flatMap(
|
|
1281
|
-
(entry) => Array.isArray(entry.to) ? entry.to : entry.to ? [entry.to] : []
|
|
1282
|
-
);
|
|
1283
|
-
const toPath = toPaths.find(
|
|
1284
|
-
(path) => typeof path === "string" && isArrayMappingPath(path)
|
|
1285
|
-
);
|
|
1286
|
-
const arrayBaseName = toPath ? getArrayBasePath(toPath) : null;
|
|
1287
|
-
const targetArrayField = arrayBaseName ? defaultFields[arrayBaseName] : null;
|
|
1288
|
-
const mappedSubProps = /* @__PURE__ */ new Set();
|
|
1289
|
-
if (arrayBaseName) {
|
|
1290
|
-
toPaths.forEach((path) => {
|
|
1291
|
-
if (typeof path !== "string") return;
|
|
1292
|
-
if (getArrayBasePath(path) !== arrayBaseName) return;
|
|
1293
|
-
const subProp = getArrayItemSubPath(path);
|
|
1294
|
-
if (subProp) mappedSubProps.add(subProp);
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
const defaultValueFields = {};
|
|
1298
|
-
if (targetArrayField && targetArrayField.type === "array" && targetArrayField.arrayFields) {
|
|
1299
|
-
const arrayFields = targetArrayField.arrayFields;
|
|
1300
|
-
Object.entries(arrayFields).forEach(([key, fld]) => {
|
|
1301
|
-
if (mappedSubProps.has(key)) return;
|
|
1302
|
-
if (fld.type === "array" || fld.type === "object" || fld.type === "slot") return;
|
|
1303
|
-
defaultValueFields[key] = __spreadProps(__spreadValues({}, fld), { label: fld.label || key });
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1306
|
-
const baseArrayFields = {
|
|
1307
|
-
from: {
|
|
1308
|
-
type: "select",
|
|
1309
|
-
label: "From",
|
|
1310
|
-
options: [
|
|
1311
|
-
{ label: "Select a field", value: "" },
|
|
1312
|
-
...fromOptions.map(({ label, value }) => ({
|
|
1313
|
-
label,
|
|
1314
|
-
value
|
|
1315
|
-
}))
|
|
1316
|
-
]
|
|
1317
|
-
},
|
|
1318
|
-
to: {
|
|
1319
|
-
type: "select",
|
|
1320
|
-
label: "To",
|
|
1321
|
-
options: [
|
|
1322
|
-
{ label: "Select a field", value: "" },
|
|
1323
|
-
...toOptions.map(({ label, value }) => ({
|
|
1324
|
-
label,
|
|
1325
|
-
value
|
|
1326
|
-
}))
|
|
1327
|
-
]
|
|
1328
|
-
}
|
|
1329
|
-
};
|
|
1330
|
-
if (arrayBaseName && Object.keys(defaultValueFields).length > 0) {
|
|
1331
|
-
baseArrayFields.unmappedArrayItemDefaultValues = {
|
|
1332
|
-
type: "object",
|
|
1333
|
-
label: "Default Item Values",
|
|
1334
|
-
objectFields: defaultValueFields
|
|
1335
|
-
};
|
|
1336
|
-
}
|
|
1337
|
-
return {
|
|
1338
|
-
type: "array",
|
|
1339
|
-
label: "Dynamic Field Map",
|
|
1340
|
-
arrayFields: baseArrayFields
|
|
1341
|
-
};
|
|
1342
|
-
})();
|
|
1343
|
-
}
|
|
1344
|
-
fields = __spreadValues(__spreadValues({}, fields), defaultFields);
|
|
1345
|
-
return fields;
|
|
1346
|
-
});
|
|
1347
|
-
},
|
|
1348
|
-
resolveData: ({ props }, { lastData }) => {
|
|
1349
|
-
const _map = (props._map || []).map((item) => {
|
|
1350
|
-
const newItem = __spreadValues({}, item);
|
|
1351
|
-
if (typeof newItem.unmappedArrayItemDefaultValues === "string") {
|
|
1352
|
-
try {
|
|
1353
|
-
newItem.unmappedArrayItemDefaultValues = JSON.parse(
|
|
1354
|
-
newItem.unmappedArrayItemDefaultValues
|
|
1355
|
-
);
|
|
1356
|
-
} catch (e) {
|
|
1357
|
-
newItem.unmappedArrayItemDefaultValues = {};
|
|
1358
|
-
}
|
|
1359
|
-
} else if (!newItem.unmappedArrayItemDefaultValues) {
|
|
1360
|
-
newItem.unmappedArrayItemDefaultValues = {};
|
|
1361
|
-
}
|
|
1362
|
-
return newItem;
|
|
1363
|
-
});
|
|
1364
|
-
const readOnlyFields = _map.flatMap((item) => item.to);
|
|
1365
|
-
const readOnlyArrayBases = readOnlyFields.filter((field) => typeof field === "string").map(getArrayBasePath).filter((base) => base !== null);
|
|
1366
|
-
if (_map.length) {
|
|
1367
|
-
return {
|
|
1368
|
-
props: __spreadProps(__spreadValues({}, props), { _map }),
|
|
1369
|
-
readOnly: [
|
|
1370
|
-
...readOnlyFields.map((f) => String(f)),
|
|
1371
|
-
...readOnlyArrayBases
|
|
1372
|
-
].reduce(
|
|
1373
|
-
(acc2, field) => __spreadProps(__spreadValues({}, acc2), { [field]: true }),
|
|
1374
|
-
{}
|
|
1375
|
-
)
|
|
1376
|
-
};
|
|
1377
|
-
}
|
|
1378
|
-
return {
|
|
1379
|
-
props: __spreadProps(__spreadValues({}, props), { _map }),
|
|
1380
|
-
readOnly: {}
|
|
1381
|
-
};
|
|
1382
|
-
},
|
|
1383
|
-
render: (props) => {
|
|
1384
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorBoundary, { children: component.render(props) });
|
|
1385
|
-
}
|
|
1386
|
-
});
|
|
1387
|
-
acc[name] = tempComponent;
|
|
1388
|
-
return acc;
|
|
1389
|
-
},
|
|
1390
|
-
{}
|
|
1391
|
-
),
|
|
1392
|
-
categories: config.categories || {}
|
|
1393
|
-
});
|
|
583
|
+
// src/puck/store/slices/builder.tsx
|
|
584
|
+
var import_core2 = require("@puckeditor/core");
|
|
1394
585
|
|
|
1395
586
|
// src/puck/lib/soft-component-constants.ts
|
|
1396
587
|
var TECHNICAL_KEYS = /* @__PURE__ */ new Set(["_map", "_slot", "id", "_version"]);
|
|
@@ -1414,6 +605,72 @@ var sanitizeComponent = (component, allowedTypes) => {
|
|
|
1414
605
|
});
|
|
1415
606
|
};
|
|
1416
607
|
|
|
608
|
+
// src/puck/lib/custom-fields.ts
|
|
609
|
+
var builtInSoftFieldTypes = /* @__PURE__ */ new Set([
|
|
610
|
+
"text",
|
|
611
|
+
"textarea",
|
|
612
|
+
"number",
|
|
613
|
+
"select",
|
|
614
|
+
"radio",
|
|
615
|
+
"array",
|
|
616
|
+
"object",
|
|
617
|
+
"reference"
|
|
618
|
+
]);
|
|
619
|
+
var warnedMessages = /* @__PURE__ */ new Set();
|
|
620
|
+
var warnOnce = (message) => {
|
|
621
|
+
if (warnedMessages.has(message)) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
warnedMessages.add(message);
|
|
625
|
+
console.warn(message);
|
|
626
|
+
};
|
|
627
|
+
var isBuiltInSoftFieldType = (fieldType) => {
|
|
628
|
+
return builtInSoftFieldTypes.has(fieldType);
|
|
629
|
+
};
|
|
630
|
+
var resolveCustomFieldDefinition = (fieldType, customFields) => {
|
|
631
|
+
if (isBuiltInSoftFieldType(fieldType)) {
|
|
632
|
+
return void 0;
|
|
633
|
+
}
|
|
634
|
+
return customFields == null ? void 0 : customFields[fieldType];
|
|
635
|
+
};
|
|
636
|
+
var resolveCustomFieldReturnType = (fieldType, customFields) => {
|
|
637
|
+
const customField = resolveCustomFieldDefinition(fieldType, customFields);
|
|
638
|
+
if (!customField) {
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
if (!customField.returnType) {
|
|
642
|
+
warnOnce(
|
|
643
|
+
`[soft-config] Custom field "${fieldType}" is missing a required returnType and will be skipped from mapping options.`
|
|
644
|
+
);
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
return customField.returnType;
|
|
648
|
+
};
|
|
649
|
+
var resolveCustomFieldSchema = (fieldType, customFields) => {
|
|
650
|
+
const customField = resolveCustomFieldDefinition(fieldType, customFields);
|
|
651
|
+
if (!customField) {
|
|
652
|
+
return null;
|
|
653
|
+
}
|
|
654
|
+
const returnType = resolveCustomFieldReturnType(fieldType, customFields);
|
|
655
|
+
if (!returnType) {
|
|
656
|
+
return null;
|
|
657
|
+
}
|
|
658
|
+
if (returnType !== "array" && returnType !== "object") {
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
const subFields = customField.subFields || [];
|
|
662
|
+
if (!subFields.length) {
|
|
663
|
+
warnOnce(
|
|
664
|
+
`[soft-config] Custom field "${fieldType}" returns ${returnType} but does not define subFields. It will be skipped from mapping options.`
|
|
665
|
+
);
|
|
666
|
+
return null;
|
|
667
|
+
}
|
|
668
|
+
return {
|
|
669
|
+
subFields,
|
|
670
|
+
subFieldSettings: customField.subFieldSettings || {}
|
|
671
|
+
};
|
|
672
|
+
};
|
|
673
|
+
|
|
1417
674
|
// src/puck/lib/soft-component-from-appstate.ts
|
|
1418
675
|
var getSubComponents = (content, componentConfigs, fieldSettings, slots) => {
|
|
1419
676
|
if (!content || !Array.isArray(content)) return [];
|
|
@@ -1569,8 +826,8 @@ var softComponentFromAppState = (appState, configComponents, editedItem, metadat
|
|
|
1569
826
|
var _a;
|
|
1570
827
|
const rootProps = ((_a = appState.data.root) == null ? void 0 : _a.props) || {};
|
|
1571
828
|
const fields = rootProps._fields || [];
|
|
1572
|
-
const
|
|
1573
|
-
const normalizedFieldSettings = __spreadValues({},
|
|
829
|
+
const fieldSettings = rootProps._fieldSettings || {};
|
|
830
|
+
const normalizedFieldSettings = __spreadValues({}, fieldSettings);
|
|
1574
831
|
(fields || []).forEach((field) => {
|
|
1575
832
|
const customFieldDefinition = resolveCustomFieldDefinition(
|
|
1576
833
|
field.type,
|
|
@@ -1896,12 +1153,100 @@ var rootZone = "default-zone";
|
|
|
1896
1153
|
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
1897
1154
|
|
|
1898
1155
|
// src/puck/components/soft-render/index.tsx
|
|
1899
|
-
var
|
|
1156
|
+
var import_react2 = __toESM(require("react"));
|
|
1900
1157
|
var import_react_fast_compare3 = __toESM(require("react-fast-compare"));
|
|
1901
|
-
|
|
1158
|
+
|
|
1159
|
+
// src/puck/components/error-boundary/index.tsx
|
|
1160
|
+
var import_react = require("react");
|
|
1161
|
+
|
|
1162
|
+
// src/puck/lib/get-class-name-factory.ts
|
|
1163
|
+
var import_classnames = __toESM(require("classnames"));
|
|
1164
|
+
var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
|
|
1165
|
+
if (typeof options === "string") {
|
|
1166
|
+
const descendant = options;
|
|
1167
|
+
const style = styles[`${rootClass}-${descendant}`];
|
|
1168
|
+
if (style) {
|
|
1169
|
+
return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
|
|
1170
|
+
}
|
|
1171
|
+
return "";
|
|
1172
|
+
} else if (typeof options === "object") {
|
|
1173
|
+
const modifiers = options;
|
|
1174
|
+
const prefixedModifiers = {};
|
|
1175
|
+
for (let modifier in modifiers) {
|
|
1176
|
+
prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
|
|
1177
|
+
}
|
|
1178
|
+
const c = styles[rootClass];
|
|
1179
|
+
return config.baseClass + (0, import_classnames.default)(__spreadValues({
|
|
1180
|
+
[c]: !!c
|
|
1181
|
+
}, prefixedModifiers));
|
|
1182
|
+
} else {
|
|
1183
|
+
return config.baseClass + styles[rootClass] || "";
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
var get_class_name_factory_default = getClassNameFactory;
|
|
1187
|
+
|
|
1188
|
+
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
|
|
1189
|
+
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" };
|
|
1190
|
+
|
|
1191
|
+
// src/puck/components/error-boundary/index.tsx
|
|
1192
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1193
|
+
var getClassName = get_class_name_factory_default("ErrorBoundary", styles_module_default);
|
|
1194
|
+
var ErrorBoundary = class extends import_react.Component {
|
|
1195
|
+
constructor(props) {
|
|
1196
|
+
super(props);
|
|
1197
|
+
this.resetError = () => {
|
|
1198
|
+
this.setState({
|
|
1199
|
+
hasError: false,
|
|
1200
|
+
error: null
|
|
1201
|
+
});
|
|
1202
|
+
};
|
|
1203
|
+
this.state = {
|
|
1204
|
+
hasError: false,
|
|
1205
|
+
error: null
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
static getDerivedStateFromError(error) {
|
|
1209
|
+
return {
|
|
1210
|
+
hasError: true,
|
|
1211
|
+
error
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
componentDidCatch(error, errorInfo) {
|
|
1215
|
+
console.error("Error caught by ErrorBoundary:", error, errorInfo);
|
|
1216
|
+
}
|
|
1217
|
+
render() {
|
|
1218
|
+
if (this.state.hasError) {
|
|
1219
|
+
if (typeof this.props.fallback === "function") {
|
|
1220
|
+
return this.props.fallback(this.state.error, this.resetError);
|
|
1221
|
+
}
|
|
1222
|
+
if (this.props.fallback) {
|
|
1223
|
+
return this.props.fallback;
|
|
1224
|
+
}
|
|
1225
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: getClassName(), children: [
|
|
1226
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { className: getClassName("title"), children: "Component Error" }),
|
|
1227
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("details", { className: getClassName("details"), children: [
|
|
1228
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("summary", { children: "Show error details" }),
|
|
1229
|
+
this.state.error && this.state.error.toString()
|
|
1230
|
+
] }),
|
|
1231
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1232
|
+
"button",
|
|
1233
|
+
{
|
|
1234
|
+
onClick: this.resetError,
|
|
1235
|
+
className: getClassName("button"),
|
|
1236
|
+
children: "Try Again"
|
|
1237
|
+
}
|
|
1238
|
+
)
|
|
1239
|
+
] });
|
|
1240
|
+
}
|
|
1241
|
+
return this.props.children;
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1244
|
+
|
|
1245
|
+
// src/puck/components/soft-render/index.tsx
|
|
1246
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1902
1247
|
function isPlainObject(val) {
|
|
1903
1248
|
if (typeof val !== "object" || val === null) return false;
|
|
1904
|
-
if (
|
|
1249
|
+
if (import_react2.default.isValidElement(val)) return false;
|
|
1905
1250
|
if ("$$typeof" in val) return false;
|
|
1906
1251
|
const proto = Object.getPrototypeOf(val);
|
|
1907
1252
|
return proto === Object.prototype || proto === null;
|
|
@@ -1909,13 +1254,28 @@ function isPlainObject(val) {
|
|
|
1909
1254
|
function cloneData(value) {
|
|
1910
1255
|
if (value === null || value === void 0) return value;
|
|
1911
1256
|
if (typeof value === "function") return value;
|
|
1912
|
-
if (Array.isArray(value))
|
|
1257
|
+
if (Array.isArray(value))
|
|
1258
|
+
return value.map(cloneData);
|
|
1913
1259
|
if (!isPlainObject(value)) return value;
|
|
1914
1260
|
return Object.fromEntries(
|
|
1915
1261
|
Object.entries(value).map(([k, v]) => [k, cloneData(v)])
|
|
1916
1262
|
);
|
|
1917
1263
|
}
|
|
1918
|
-
|
|
1264
|
+
function shallowEqual(objA, objB) {
|
|
1265
|
+
if (Object.is(objA, objB)) return true;
|
|
1266
|
+
if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null)
|
|
1267
|
+
return false;
|
|
1268
|
+
const keysA = Object.keys(objA);
|
|
1269
|
+
const keysB = Object.keys(objB);
|
|
1270
|
+
if (keysA.length !== keysB.length) return false;
|
|
1271
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
1272
|
+
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
|
|
1273
|
+
return false;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
return true;
|
|
1277
|
+
}
|
|
1278
|
+
var SubComponentRenderer = (0, import_react2.memo)(
|
|
1919
1279
|
({
|
|
1920
1280
|
subComponent,
|
|
1921
1281
|
softComponentFields,
|
|
@@ -1927,11 +1287,11 @@ var SubComponentRenderer = (0, import_react4.memo)(
|
|
|
1927
1287
|
}) => {
|
|
1928
1288
|
const { id, puck, editMode } = props;
|
|
1929
1289
|
const componentConfig = configComponents[subComponent == null ? void 0 : subComponent.type];
|
|
1930
|
-
const stableId = (0,
|
|
1290
|
+
const stableId = (0, import_react2.useMemo)(
|
|
1931
1291
|
() => depth === 0 ? id : `${subComponent.type}-${id}-d${depth}-i${index}`,
|
|
1932
1292
|
[id, depth, subComponent.type, index]
|
|
1933
1293
|
);
|
|
1934
|
-
const finalProps = (0,
|
|
1294
|
+
const finalProps = (0, import_react2.useMemo)(() => {
|
|
1935
1295
|
var _a;
|
|
1936
1296
|
if (!componentConfig) return {};
|
|
1937
1297
|
const clonedProps = cloneData(subComponent.fixedProps || {});
|
|
@@ -1966,7 +1326,7 @@ var SubComponentRenderer = (0, import_react4.memo)(
|
|
|
1966
1326
|
style
|
|
1967
1327
|
}) => {
|
|
1968
1328
|
var _a3, _b2;
|
|
1969
|
-
return /* @__PURE__ */ (0,
|
|
1329
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className, style, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1970
1330
|
SoftRender,
|
|
1971
1331
|
{
|
|
1972
1332
|
softComponentFields,
|
|
@@ -1993,7 +1353,7 @@ var SubComponentRenderer = (0, import_react4.memo)(
|
|
|
1993
1353
|
]);
|
|
1994
1354
|
if (!componentConfig) return null;
|
|
1995
1355
|
const ComponentRender = componentConfig.render;
|
|
1996
|
-
return /* @__PURE__ */ (0,
|
|
1356
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorBoundary, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1997
1357
|
ComponentRender,
|
|
1998
1358
|
__spreadValues({
|
|
1999
1359
|
id: stableId,
|
|
@@ -2002,17 +1362,14 @@ var SubComponentRenderer = (0, import_react4.memo)(
|
|
|
2002
1362
|
}, finalProps)
|
|
2003
1363
|
) });
|
|
2004
1364
|
},
|
|
2005
|
-
//
|
|
2006
|
-
//
|
|
2007
|
-
|
|
2008
|
-
//
|
|
2009
|
-
|
|
2010
|
-
// configComponents and softComponentFields are treated as stable config
|
|
2011
|
-
// references — reference equality is intentional and fast here.
|
|
2012
|
-
(prev, next) => prev.depth === next.depth && prev.index === next.index && prev.configComponents === next.configComponents && prev.softComponentFields === next.softComponentFields && (0, import_react_fast_compare3.default)(prev.props, next.props) && (0, import_react_fast_compare3.default)(prev.subComponent, next.subComponent) && (0, import_react_fast_compare3.default)(prev.softComponentFieldSettings, next.softComponentFieldSettings)
|
|
1365
|
+
(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
|
|
1366
|
+
// would risk retaining stale closures and is unnecessarily expensive here.
|
|
1367
|
+
shallowEqual(prev.props, next.props) && // Deep compare: subComponent and fieldSettings are plain JSON configuration
|
|
1368
|
+
// objects with no functions, so structural equality is safe and correct.
|
|
1369
|
+
(0, import_react_fast_compare3.default)(prev.subComponent, next.subComponent) && (0, import_react_fast_compare3.default)(prev.softComponentFieldSettings, next.softComponentFieldSettings)
|
|
2013
1370
|
);
|
|
2014
1371
|
SubComponentRenderer.displayName = "SubComponentRenderer";
|
|
2015
|
-
var SoftRender = (0,
|
|
1372
|
+
var SoftRender = (0, import_react2.memo)(
|
|
2016
1373
|
({
|
|
2017
1374
|
softComponentFields,
|
|
2018
1375
|
softComponentFieldSettings,
|
|
@@ -2022,9 +1379,9 @@ var SoftRender = (0, import_react4.memo)(
|
|
|
2022
1379
|
depth = 0
|
|
2023
1380
|
}) => {
|
|
2024
1381
|
if (!(softSubComponent == null ? void 0 : softSubComponent.length)) return null;
|
|
2025
|
-
return /* @__PURE__ */ (0,
|
|
1382
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: softSubComponent.map((subComponent, index) => {
|
|
2026
1383
|
var _a;
|
|
2027
|
-
return /* @__PURE__ */ (0,
|
|
1384
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2028
1385
|
SubComponentRenderer,
|
|
2029
1386
|
{
|
|
2030
1387
|
subComponent,
|
|
@@ -2039,16 +1396,14 @@ var SoftRender = (0, import_react4.memo)(
|
|
|
2039
1396
|
);
|
|
2040
1397
|
}) });
|
|
2041
1398
|
},
|
|
2042
|
-
|
|
2043
|
-
//
|
|
2044
|
-
|
|
2045
|
-
// props / softSubComponent: deep equality (primary render drivers).
|
|
2046
|
-
(prev, next) => prev.configComponents === next.configComponents && prev.softComponentFields === next.softComponentFields && (0, import_react_fast_compare3.default)(prev.props, next.props) && (0, import_react_fast_compare3.default)(prev.softSubComponent, next.softSubComponent) && (0, import_react_fast_compare3.default)(prev.softComponentFieldSettings, next.softComponentFieldSettings)
|
|
1399
|
+
(prev, next) => prev.configComponents === next.configComponents && prev.softComponentFields === next.softComponentFields && // Shallow compare: props may contain functions/React nodes; see shallowEqual.
|
|
1400
|
+
shallowEqual(prev.props, next.props) && // Deep compare: softSubComponent and fieldSettings are plain JSON schemas.
|
|
1401
|
+
(0, import_react_fast_compare3.default)(prev.softSubComponent, next.softSubComponent) && (0, import_react_fast_compare3.default)(prev.softComponentFieldSettings, next.softComponentFieldSettings)
|
|
2047
1402
|
);
|
|
2048
1403
|
SoftRender.displayName = "SoftRender";
|
|
2049
1404
|
|
|
2050
1405
|
// src/puck/lib/create-versioned-component-config.tsx
|
|
2051
|
-
var
|
|
1406
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
2052
1407
|
var hydrateCustomField = (fieldName, field, fieldSettings, customFields) => {
|
|
2053
1408
|
var _a;
|
|
2054
1409
|
if (field.type !== "custom") {
|
|
@@ -2106,7 +1461,7 @@ var createVersionedComponentConfig = (componentName, displayName, version, allVe
|
|
|
2106
1461
|
var _a2;
|
|
2107
1462
|
const selectedVersion = props.version || version;
|
|
2108
1463
|
const versionedComponent = (_a2 = softComponents[componentName]) == null ? void 0 : _a2.versions[selectedVersion];
|
|
2109
|
-
return /* @__PURE__ */ (0,
|
|
1464
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2110
1465
|
SoftRender,
|
|
2111
1466
|
{
|
|
2112
1467
|
softComponentFields: versionedComponent.fields,
|
|
@@ -2121,7 +1476,7 @@ var createVersionedComponentConfig = (componentName, displayName, version, allVe
|
|
|
2121
1476
|
};
|
|
2122
1477
|
|
|
2123
1478
|
// src/puck/lib/builder/sub-component-decomposer.tsx
|
|
2124
|
-
var subComponentDecomposer = (componentRootData, softSubComponent) => {
|
|
1479
|
+
var subComponentDecomposer = (componentRootData, softSubComponent, keepMapField) => {
|
|
2125
1480
|
var _a;
|
|
2126
1481
|
const resolvedProps = __spreadValues({}, softSubComponent.fixedProps);
|
|
2127
1482
|
(_a = softSubComponent.map) == null ? void 0 : _a.forEach((mapItem) => {
|
|
@@ -2144,21 +1499,21 @@ var subComponentDecomposer = (componentRootData, softSubComponent) => {
|
|
|
2144
1499
|
Object.entries(softSubComponent.components).forEach(
|
|
2145
1500
|
([slotKey, subComponents]) => {
|
|
2146
1501
|
resolvedProps[slotKey] = subComponents.map(
|
|
2147
|
-
(subComponent) => subComponentDecomposer(componentRootData, subComponent)
|
|
1502
|
+
(subComponent) => subComponentDecomposer(componentRootData, subComponent, keepMapField)
|
|
2148
1503
|
);
|
|
2149
1504
|
}
|
|
2150
1505
|
);
|
|
2151
1506
|
const accItem = {
|
|
2152
1507
|
type: softSubComponent.type,
|
|
2153
|
-
props: __spreadProps(__spreadValues({}, resolvedProps), {
|
|
1508
|
+
props: __spreadValues(__spreadProps(__spreadValues({}, resolvedProps), {
|
|
2154
1509
|
id: generateId(softSubComponent.type)
|
|
2155
|
-
})
|
|
1510
|
+
}), keepMapField ? { _map: softSubComponent.map } : {})
|
|
2156
1511
|
};
|
|
2157
1512
|
return accItem;
|
|
2158
1513
|
};
|
|
2159
1514
|
|
|
2160
1515
|
// src/puck/lib/builder/resolve-soft-component-data.ts
|
|
2161
|
-
var resolveSoftComponentData = (props, _fieldSettings = {}) => {
|
|
1516
|
+
var resolveSoftComponentData = (props, _fieldSettings = {}, keepMapField) => {
|
|
2162
1517
|
const map = props._map;
|
|
2163
1518
|
if (!(map == null ? void 0 : map.length)) return __spreadValues({}, props);
|
|
2164
1519
|
const { newProps } = applyMapping(
|
|
@@ -2167,11 +1522,16 @@ var resolveSoftComponentData = (props, _fieldSettings = {}) => {
|
|
|
2167
1522
|
map,
|
|
2168
1523
|
"propsFirst"
|
|
2169
1524
|
);
|
|
1525
|
+
if (keepMapField) {
|
|
1526
|
+
return __spreadProps(__spreadValues({}, newProps), {
|
|
1527
|
+
_map: map
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
2170
1530
|
return newProps;
|
|
2171
1531
|
};
|
|
2172
1532
|
|
|
2173
1533
|
// src/puck/lib/decompose-soft-component.ts
|
|
2174
|
-
function decomposeSoftComponent(componentData, softComponents, fieldSettings) {
|
|
1534
|
+
function decomposeSoftComponent(componentData, softComponents, fieldSettings, keepMapField) {
|
|
2175
1535
|
var _a, _b, _c, _d;
|
|
2176
1536
|
if (!(componentData == null ? void 0 : componentData.type) || !(componentData == null ? void 0 : componentData.props.id)) {
|
|
2177
1537
|
throw new Error("Component data must have type and id to decompose.");
|
|
@@ -2195,7 +1555,11 @@ function decomposeSoftComponent(componentData, softComponents, fieldSettings) {
|
|
|
2195
1555
|
}
|
|
2196
1556
|
const decomposedComponentData = softComponent.components.map(
|
|
2197
1557
|
(softSubComponent) => {
|
|
2198
|
-
return subComponentDecomposer(
|
|
1558
|
+
return subComponentDecomposer(
|
|
1559
|
+
resolvedComponentData,
|
|
1560
|
+
softSubComponent,
|
|
1561
|
+
keepMapField
|
|
1562
|
+
);
|
|
2199
1563
|
}
|
|
2200
1564
|
);
|
|
2201
1565
|
return decomposedComponentData;
|
|
@@ -2205,9 +1569,9 @@ function isSoftComponent(componentType, softComponents) {
|
|
|
2205
1569
|
}
|
|
2206
1570
|
|
|
2207
1571
|
// src/puck/lib/demolish-soft-component.ts
|
|
2208
|
-
var
|
|
1572
|
+
var import_core = require("@puckeditor/core");
|
|
2209
1573
|
function demolishSoftComponent(componentName, data, config, softComponents) {
|
|
2210
|
-
const resolvedData = (0,
|
|
1574
|
+
const resolvedData = (0, import_core.walkTree)(data, config, (components) => {
|
|
2211
1575
|
components.forEach((componentData, index) => {
|
|
2212
1576
|
if (componentData.type === componentName) {
|
|
2213
1577
|
const decomposed = decomposeSoftComponent(componentData, softComponents);
|
|
@@ -2294,24 +1658,15 @@ var clearEditVisibility = (doc) => {
|
|
|
2294
1658
|
};
|
|
2295
1659
|
|
|
2296
1660
|
// src/puck/store/slices/builder.tsx
|
|
2297
|
-
var createBuildersSlice = (set, get
|
|
1661
|
+
var createBuildersSlice = (set, get) => ({
|
|
2298
1662
|
build: (history, selectedItem, itemSelector, puckDispatch, name) => {
|
|
2299
1663
|
if (!selectedItem || !itemSelector) {
|
|
2300
1664
|
throw new Error("No item selected to build from.");
|
|
2301
|
-
}
|
|
2302
|
-
const config =
|
|
2303
|
-
const overrides = get().overrides;
|
|
2304
|
-
const buildConfig = builderConfig(
|
|
2305
|
-
config,
|
|
2306
|
-
overrides,
|
|
2307
|
-
void 0,
|
|
2308
|
-
get().showVersionFields,
|
|
2309
|
-
void 0,
|
|
2310
|
-
get().customFields
|
|
2311
|
-
);
|
|
1665
|
+
}
|
|
1666
|
+
const config = get().softConfig;
|
|
2312
1667
|
const editableIds = /* @__PURE__ */ new Set([selectedItem.props.id]);
|
|
2313
1668
|
const initialContent = [__spreadValues({}, selectedItem)];
|
|
2314
|
-
(0,
|
|
1669
|
+
(0, import_core2.walkTree)(
|
|
2315
1670
|
{
|
|
2316
1671
|
root: {},
|
|
2317
1672
|
content: initialContent
|
|
@@ -2331,8 +1686,6 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2331
1686
|
})
|
|
2332
1687
|
);
|
|
2333
1688
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2334
|
-
softConfig: buildConfig,
|
|
2335
|
-
storedConfig: config,
|
|
2336
1689
|
originalHistory: history,
|
|
2337
1690
|
itemSelector: {
|
|
2338
1691
|
index: itemSelector.index,
|
|
@@ -2342,28 +1695,24 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2342
1695
|
editableComponentIds: editableIds,
|
|
2343
1696
|
state: "building"
|
|
2344
1697
|
}));
|
|
2345
|
-
requestAnimationFrame(
|
|
2346
|
-
|
|
2347
|
-
type: "
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
};
|
|
2362
|
-
}
|
|
2363
|
-
})
|
|
2364
|
-
);
|
|
1698
|
+
requestAnimationFrame(() => {
|
|
1699
|
+
puckDispatch({
|
|
1700
|
+
type: "setUi",
|
|
1701
|
+
ui: { itemSelector: null },
|
|
1702
|
+
recordHistory: false
|
|
1703
|
+
});
|
|
1704
|
+
puckDispatch({
|
|
1705
|
+
type: "replaceRoot",
|
|
1706
|
+
root: {
|
|
1707
|
+
props: {
|
|
1708
|
+
_name: name || "New Soft Component"
|
|
1709
|
+
}
|
|
1710
|
+
},
|
|
1711
|
+
recordHistory: false
|
|
1712
|
+
});
|
|
1713
|
+
});
|
|
2365
1714
|
},
|
|
2366
|
-
remodel: (history, selectedItem, itemSelector, puckDispatch) => {
|
|
1715
|
+
remodel: (history, selectedItem, itemSelector, puckDispatch, refreshPermission) => {
|
|
2367
1716
|
var _a, _b;
|
|
2368
1717
|
if (!selectedItem || !itemSelector) {
|
|
2369
1718
|
throw new Error("No item selected to build from.");
|
|
@@ -2383,7 +1732,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2383
1732
|
`Soft component "${softComponentName}" with version "${softComponentVersion}" not found.`
|
|
2384
1733
|
);
|
|
2385
1734
|
}
|
|
2386
|
-
const { root
|
|
1735
|
+
const { root } = softComponentToAppState(
|
|
2387
1736
|
softComponent,
|
|
2388
1737
|
softComponentName,
|
|
2389
1738
|
softComponentVersion,
|
|
@@ -2395,91 +1744,107 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2395
1744
|
softComponentMeta == null ? void 0 : softComponentMeta.category,
|
|
2396
1745
|
get().customFields
|
|
2397
1746
|
);
|
|
2398
|
-
const config =
|
|
2399
|
-
const overrides = get().overrides;
|
|
1747
|
+
const config = get().softConfig;
|
|
2400
1748
|
const dependents = get().dependencyGraph.get(softComponentName) || /* @__PURE__ */ new Set();
|
|
2401
|
-
const
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
get().showVersionFields,
|
|
2406
|
-
dependents,
|
|
2407
|
-
get().customFields
|
|
2408
|
-
);
|
|
2409
|
-
const editableIds = /* @__PURE__ */ new Set([]);
|
|
2410
|
-
const decomposedComponents = get().builder.decompose(selectedItem);
|
|
2411
|
-
(0, import_puck4.walkTree)(
|
|
2412
|
-
{ root: {}, content: decomposedComponents || [] },
|
|
1749
|
+
const decomposedComponents = get().builder.decompose(selectedItem, true);
|
|
1750
|
+
const editableIds = /* @__PURE__ */ new Set([decomposedComponents[0].props.id]);
|
|
1751
|
+
const { content: decomposedComponentsWithId } = (0, import_core2.walkTree)(
|
|
1752
|
+
{ root: {}, content: decomposedComponents },
|
|
2413
1753
|
{ components: config.components },
|
|
2414
1754
|
(components) => {
|
|
2415
|
-
components.forEach((
|
|
2416
|
-
|
|
1755
|
+
components.forEach((comp2) => {
|
|
1756
|
+
const id2 = generateId(comp2.type);
|
|
1757
|
+
comp2.props.id = id2;
|
|
1758
|
+
editableIds.add(id2);
|
|
2417
1759
|
});
|
|
2418
1760
|
return components;
|
|
2419
1761
|
}
|
|
2420
1762
|
);
|
|
2421
|
-
requestAnimationFrame(() => {
|
|
2422
|
-
puckDispatch({
|
|
2423
|
-
type: "set",
|
|
2424
|
-
state: (previous) => ({
|
|
2425
|
-
data: {
|
|
2426
|
-
root: __spreadProps(__spreadValues({}, root), { _versions: versions }),
|
|
2427
|
-
content: (0, import_puck4.walkTree)(
|
|
2428
|
-
__spreadValues({}, previous.data),
|
|
2429
|
-
__spreadValues({}, config),
|
|
2430
|
-
(components) => {
|
|
2431
|
-
const next = components.map((component) => __spreadProps(__spreadValues({}, component), {
|
|
2432
|
-
props: __spreadValues({}, component.props)
|
|
2433
|
-
}));
|
|
2434
|
-
const index = next.findIndex(
|
|
2435
|
-
(component) => component.props.id === selectedItem.props.id
|
|
2436
|
-
);
|
|
2437
|
-
if (index !== -1) {
|
|
2438
|
-
next.splice(
|
|
2439
|
-
index,
|
|
2440
|
-
1,
|
|
2441
|
-
...decomposedComponents.map((component) => __spreadProps(__spreadValues({}, component), {
|
|
2442
|
-
props: __spreadValues({}, component.props)
|
|
2443
|
-
}))
|
|
2444
|
-
);
|
|
2445
|
-
}
|
|
2446
|
-
return next;
|
|
2447
|
-
}
|
|
2448
|
-
).content
|
|
2449
|
-
},
|
|
2450
|
-
ui: __spreadProps(__spreadValues({}, previous.ui), {
|
|
2451
|
-
itemSelector: null
|
|
2452
|
-
})
|
|
2453
|
-
})
|
|
2454
|
-
});
|
|
2455
|
-
setEditVisibility(get().iframeDoc, {
|
|
2456
|
-
mode: "remodel",
|
|
2457
|
-
editableIds
|
|
2458
|
-
});
|
|
2459
|
-
});
|
|
2460
1763
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2461
|
-
storedConfig: config,
|
|
2462
|
-
softConfig: buildConfig,
|
|
2463
1764
|
originalHistory: history,
|
|
2464
1765
|
itemSelector: {
|
|
2465
1766
|
index: itemSelector.index,
|
|
2466
1767
|
zone: itemSelector.zone || rootDroppableId
|
|
2467
1768
|
},
|
|
2468
|
-
editingComponentId: selectedItem.props.id,
|
|
2469
1769
|
editingComponent: softComponentName,
|
|
1770
|
+
editingDependents: dependents,
|
|
2470
1771
|
editableComponentIds: editableIds,
|
|
2471
|
-
state: "
|
|
1772
|
+
state: "assessing"
|
|
2472
1773
|
}));
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
1774
|
+
puckDispatch({
|
|
1775
|
+
type: "remove",
|
|
1776
|
+
index: itemSelector.index,
|
|
1777
|
+
zone: itemSelector.zone || rootDroppableId,
|
|
1778
|
+
recordHistory: false
|
|
1779
|
+
});
|
|
1780
|
+
const comp = decomposedComponentsWithId[0];
|
|
1781
|
+
if (!comp) {
|
|
1782
|
+
throw new Error("No decomposed components found.");
|
|
1783
|
+
}
|
|
1784
|
+
const id = comp.props.id;
|
|
1785
|
+
puckDispatch({
|
|
1786
|
+
type: "insert",
|
|
1787
|
+
destinationIndex: itemSelector.index,
|
|
1788
|
+
destinationZone: itemSelector.zone || rootDroppableId,
|
|
1789
|
+
componentType: comp.type,
|
|
1790
|
+
recordHistory: false,
|
|
1791
|
+
id
|
|
1792
|
+
});
|
|
1793
|
+
requestAnimationFrame(() => {
|
|
1794
|
+
var _a2;
|
|
1795
|
+
const _map = ((_a2 = comp.props) == null ? void 0 : _a2._map) || [];
|
|
1796
|
+
const readOnlyFields = _map.flatMap((item) => item.to);
|
|
1797
|
+
const readOnlyArrayBases = readOnlyFields.filter((field) => typeof field === "string").map(getArrayBasePath).filter((base) => base !== null);
|
|
1798
|
+
const readOnly = [
|
|
1799
|
+
...readOnlyFields.map((f) => String(f)),
|
|
1800
|
+
...readOnlyArrayBases
|
|
1801
|
+
].reduce(
|
|
1802
|
+
(acc, field) => __spreadProps(__spreadValues({}, acc), { [field]: true }),
|
|
1803
|
+
{}
|
|
1804
|
+
);
|
|
1805
|
+
puckDispatch({
|
|
1806
|
+
type: "replace",
|
|
1807
|
+
destinationIndex: itemSelector.index,
|
|
1808
|
+
destinationZone: itemSelector.zone || rootDroppableId,
|
|
1809
|
+
data: __spreadProps(__spreadValues({}, comp), {
|
|
1810
|
+
props: __spreadProps(__spreadValues({}, comp.props), {
|
|
1811
|
+
id
|
|
1812
|
+
}),
|
|
1813
|
+
readOnly
|
|
1814
|
+
}),
|
|
1815
|
+
recordHistory: false
|
|
1816
|
+
});
|
|
1817
|
+
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
1818
|
+
state: "remodeling"
|
|
1819
|
+
}));
|
|
1820
|
+
setEditVisibility(get().iframeDoc, {
|
|
1821
|
+
mode: "remodel",
|
|
1822
|
+
editableIds: new Set(editableIds)
|
|
1823
|
+
});
|
|
1824
|
+
});
|
|
1825
|
+
puckDispatch({
|
|
1826
|
+
type: "replaceRoot",
|
|
1827
|
+
root: {
|
|
1828
|
+
props: __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, root.props), root.props.title !== void 0 && {
|
|
1829
|
+
title: root.props.title
|
|
1830
|
+
}), root.props._name !== void 0 && {
|
|
1831
|
+
_name: root.props._name
|
|
1832
|
+
}), root.props._category !== void 0 && {
|
|
2479
1833
|
_category: root.props._category
|
|
2480
|
-
}
|
|
2481
|
-
|
|
2482
|
-
|
|
1834
|
+
}), {
|
|
1835
|
+
_versions: versions
|
|
1836
|
+
})
|
|
1837
|
+
},
|
|
1838
|
+
recordHistory: false
|
|
1839
|
+
});
|
|
1840
|
+
requestAnimationFrame(() => {
|
|
1841
|
+
puckDispatch({
|
|
1842
|
+
type: "setUi",
|
|
1843
|
+
ui: { itemSelector: null },
|
|
1844
|
+
recordHistory: false
|
|
1845
|
+
});
|
|
1846
|
+
refreshPermission();
|
|
1847
|
+
});
|
|
2483
1848
|
},
|
|
2484
1849
|
complete: (appState, setHistories, getItemBySelector) => {
|
|
2485
1850
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -2519,7 +1884,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2519
1884
|
}
|
|
2520
1885
|
const storedHistories = get().originalHistory;
|
|
2521
1886
|
setHistories([...storedHistories]);
|
|
2522
|
-
const config = __spreadValues({}, get().softConfig
|
|
1887
|
+
const config = __spreadValues({}, get().softConfig);
|
|
2523
1888
|
const mapComponentConfig = get().overrides.mapComponentConfig;
|
|
2524
1889
|
const newSoftComponentConfig = mapComponentConfig ? mapComponentConfig(componentName, defaultSoftComponentConfig, rootProps) : defaultSoftComponentConfig;
|
|
2525
1890
|
set((s) => {
|
|
@@ -2557,11 +1922,9 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2557
1922
|
}) : categories;
|
|
2558
1923
|
return __spreadProps(__spreadValues({}, s), {
|
|
2559
1924
|
softConfig: __spreadProps(__spreadValues({}, config), {
|
|
2560
|
-
root: __spreadValues({}, initialConfig.root),
|
|
2561
1925
|
components: nextComponents,
|
|
2562
1926
|
categories: nextCategories
|
|
2563
1927
|
}),
|
|
2564
|
-
storedConfig: void 0,
|
|
2565
1928
|
state: "inspecting",
|
|
2566
1929
|
// Temporarily shift state to inspect() before finalizing back to ready
|
|
2567
1930
|
originalHistory: []
|
|
@@ -2583,7 +1946,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2583
1946
|
softComponent: completedSoftComponent
|
|
2584
1947
|
};
|
|
2585
1948
|
},
|
|
2586
|
-
inspect: (componentName, puckDispatch) => {
|
|
1949
|
+
inspect: (componentName, puckDispatch, selectedItemSelector) => {
|
|
2587
1950
|
if (get().state !== "inspecting") {
|
|
2588
1951
|
throw new Error("Not in inspecting state.");
|
|
2589
1952
|
}
|
|
@@ -2592,59 +1955,72 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2592
1955
|
throw new Error("No selector found for last item.");
|
|
2593
1956
|
}
|
|
2594
1957
|
const editableComponentId = get().editingComponentId;
|
|
1958
|
+
const itemSelector = get().itemSelector;
|
|
2595
1959
|
requestAnimationFrame(() => {
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
1960
|
+
var _a;
|
|
1961
|
+
if (editableComponentId && !Object.keys(get().softComponents).includes(
|
|
1962
|
+
(_a = editableComponentId == null ? void 0 : editableComponentId.split(":")) == null ? void 0 : _a[0].split("-")[0]
|
|
1963
|
+
)) {
|
|
1964
|
+
requestAnimationFrame(() => {
|
|
1965
|
+
puckDispatch({
|
|
1966
|
+
type: "remove",
|
|
1967
|
+
index: itemSelector.index,
|
|
1968
|
+
zone: itemSelector.zone,
|
|
1969
|
+
recordHistory: true
|
|
1970
|
+
});
|
|
1971
|
+
puckDispatch({
|
|
1972
|
+
type: "insert",
|
|
1973
|
+
destinationIndex: itemSelector.index,
|
|
1974
|
+
destinationZone: itemSelector.zone,
|
|
1975
|
+
componentType: componentName,
|
|
1976
|
+
recordHistory: true
|
|
1977
|
+
});
|
|
2609
1978
|
});
|
|
2610
|
-
}
|
|
2611
|
-
puckDispatch({
|
|
2612
|
-
type: "setData",
|
|
2613
|
-
data: (data) => {
|
|
2614
|
-
return reconstructedTree(data);
|
|
2615
|
-
},
|
|
2616
|
-
recordHistory: true
|
|
2617
|
-
// Record this swap on the standard undo/redo stack
|
|
2618
|
-
});
|
|
1979
|
+
}
|
|
2619
1980
|
clearEditVisibility(get().iframeDoc);
|
|
1981
|
+
if (!selectedItemSelector && selector.index !== void 0) {
|
|
1982
|
+
puckDispatch({
|
|
1983
|
+
type: "setUi",
|
|
1984
|
+
ui: { itemSelector: selector },
|
|
1985
|
+
recordHistory: false
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
2620
1988
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2621
1989
|
state: "ready",
|
|
2622
1990
|
setItemSelector: void 0,
|
|
2623
1991
|
setOriginalItem: void 0,
|
|
1992
|
+
itemSelector: null,
|
|
2624
1993
|
editingComponent: null,
|
|
2625
1994
|
editingComponentId: null,
|
|
2626
1995
|
editableComponentIds: /* @__PURE__ */ new Set()
|
|
2627
1996
|
}));
|
|
2628
1997
|
});
|
|
2629
1998
|
},
|
|
2630
|
-
cancel: (setHistories) => {
|
|
1999
|
+
cancel: (setHistories, puckDispatch, selectedItemSelector) => {
|
|
2631
2000
|
const storedHistories = get().originalHistory;
|
|
2001
|
+
const itemSelector = get().itemSelector;
|
|
2632
2002
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2633
2003
|
state: "cancelling"
|
|
2634
2004
|
}));
|
|
2635
2005
|
setHistories([...storedHistories]);
|
|
2636
2006
|
requestAnimationFrame(() => {
|
|
2637
2007
|
clearEditVisibility(get().iframeDoc);
|
|
2008
|
+
if (!selectedItemSelector && itemSelector) {
|
|
2009
|
+
puckDispatch({
|
|
2010
|
+
type: "setUi",
|
|
2011
|
+
ui: { itemSelector },
|
|
2012
|
+
recordHistory: false
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2638
2015
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
2639
|
-
softConfig: get().storedConfig || initialConfig,
|
|
2640
|
-
storedConfig: void 0,
|
|
2641
2016
|
originalHistory: [],
|
|
2642
2017
|
itemSelector: null,
|
|
2643
2018
|
originalItem: null,
|
|
2644
2019
|
state: "ready",
|
|
2645
2020
|
editingComponent: null,
|
|
2646
2021
|
editingComponentId: null,
|
|
2647
|
-
editableComponentIds: /* @__PURE__ */ new Set()
|
|
2022
|
+
editableComponentIds: /* @__PURE__ */ new Set(),
|
|
2023
|
+
editingDependents: /* @__PURE__ */ new Set()
|
|
2648
2024
|
}));
|
|
2649
2025
|
});
|
|
2650
2026
|
},
|
|
@@ -2691,11 +2067,16 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2691
2067
|
get().setSoftComponent(componentName, version, softComponent);
|
|
2692
2068
|
return [newSoftComponentConfig, version];
|
|
2693
2069
|
},
|
|
2694
|
-
decompose: (componentData) => {
|
|
2070
|
+
decompose: (componentData, keepMapField) => {
|
|
2695
2071
|
if (!(componentData == null ? void 0 : componentData.type) || !(componentData == null ? void 0 : componentData.props.id)) {
|
|
2696
2072
|
throw new Error("Component data must have type and id to decompose.");
|
|
2697
2073
|
}
|
|
2698
|
-
return decomposeSoftComponent(
|
|
2074
|
+
return decomposeSoftComponent(
|
|
2075
|
+
componentData,
|
|
2076
|
+
get().softComponents,
|
|
2077
|
+
void 0,
|
|
2078
|
+
keepMapField
|
|
2079
|
+
);
|
|
2699
2080
|
},
|
|
2700
2081
|
demolish: (componentName, data, puckDispatch) => {
|
|
2701
2082
|
if (get().state !== "ready") {
|
|
@@ -2716,7 +2097,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2716
2097
|
softConfig: result.config
|
|
2717
2098
|
}));
|
|
2718
2099
|
},
|
|
2719
|
-
setVersion: (componentName, newVersion, currentProps, puckDispatch) => {
|
|
2100
|
+
setVersion: (componentName, newVersion, currentProps, puckDispatch, getItemBySelector, getSelectorForId) => {
|
|
2720
2101
|
var _a;
|
|
2721
2102
|
if (get().state !== "remodeling") {
|
|
2722
2103
|
throw new Error("Can only switch versions during remodeling.");
|
|
@@ -2743,12 +2124,91 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
2743
2124
|
softComponentMeta == null ? void 0 : softComponentMeta.category,
|
|
2744
2125
|
get().customFields
|
|
2745
2126
|
);
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2127
|
+
const editableIds = get().editableComponentIds;
|
|
2128
|
+
if (!editableIds || editableIds.size === 0) return;
|
|
2129
|
+
const firstId = Array.from(editableIds)[0];
|
|
2130
|
+
const itemSelector = getSelectorForId(firstId);
|
|
2131
|
+
if (!itemSelector) return;
|
|
2132
|
+
requestAnimationFrame(() => {
|
|
2133
|
+
const countToRemove = Array.from(editableIds).filter(
|
|
2134
|
+
(id) => {
|
|
2135
|
+
var _a2;
|
|
2136
|
+
return ((_a2 = getSelectorForId(id)) == null ? void 0 : _a2.zone) === itemSelector.zone;
|
|
2137
|
+
}
|
|
2138
|
+
).length;
|
|
2139
|
+
for (let i = 0; i < countToRemove; i++) {
|
|
2140
|
+
puckDispatch({
|
|
2141
|
+
type: "remove",
|
|
2142
|
+
index: itemSelector.index,
|
|
2143
|
+
zone: itemSelector.zone,
|
|
2144
|
+
recordHistory: false
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
const newContent = content || [];
|
|
2148
|
+
const comp = newContent[0];
|
|
2149
|
+
if (comp) {
|
|
2150
|
+
puckDispatch({
|
|
2151
|
+
type: "insert",
|
|
2152
|
+
destinationIndex: itemSelector.index,
|
|
2153
|
+
destinationZone: itemSelector.zone,
|
|
2154
|
+
componentType: comp.type,
|
|
2155
|
+
recordHistory: false
|
|
2156
|
+
});
|
|
2157
|
+
}
|
|
2158
|
+
requestAnimationFrame(() => {
|
|
2159
|
+
if (comp) {
|
|
2160
|
+
const insertedItem = getItemBySelector({
|
|
2161
|
+
index: itemSelector.index,
|
|
2162
|
+
zone: itemSelector.zone
|
|
2163
|
+
});
|
|
2164
|
+
if (insertedItem) {
|
|
2165
|
+
puckDispatch({
|
|
2166
|
+
type: "replace",
|
|
2167
|
+
destinationIndex: itemSelector.index,
|
|
2168
|
+
destinationZone: itemSelector.zone,
|
|
2169
|
+
data: __spreadProps(__spreadValues({}, comp), {
|
|
2170
|
+
props: __spreadProps(__spreadValues({}, comp.props), {
|
|
2171
|
+
id: insertedItem.props.id
|
|
2172
|
+
})
|
|
2173
|
+
}),
|
|
2174
|
+
recordHistory: false
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
puckDispatch({
|
|
2179
|
+
type: "replaceRoot",
|
|
2180
|
+
root: {
|
|
2181
|
+
props: __spreadProps(__spreadValues({}, root.props), {
|
|
2182
|
+
_versions: versions
|
|
2183
|
+
})
|
|
2184
|
+
},
|
|
2185
|
+
recordHistory: false
|
|
2186
|
+
});
|
|
2187
|
+
requestAnimationFrame(() => {
|
|
2188
|
+
const newEditableIds = /* @__PURE__ */ new Set();
|
|
2189
|
+
if (comp) {
|
|
2190
|
+
const finalItem = getItemBySelector({
|
|
2191
|
+
index: itemSelector.index,
|
|
2192
|
+
zone: itemSelector.zone
|
|
2193
|
+
});
|
|
2194
|
+
if (finalItem) {
|
|
2195
|
+
(0, import_core2.walkTree)(
|
|
2196
|
+
{ root: {}, content: [finalItem] },
|
|
2197
|
+
{ components: get().softConfig.components },
|
|
2198
|
+
(components) => {
|
|
2199
|
+
components.forEach((c) => newEditableIds.add(c.props.id));
|
|
2200
|
+
return components;
|
|
2201
|
+
}
|
|
2202
|
+
);
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
set((s) => __spreadProps(__spreadValues({}, s), { editableComponentIds: newEditableIds }));
|
|
2206
|
+
setEditVisibility(get().iframeDoc, {
|
|
2207
|
+
mode: "remodel",
|
|
2208
|
+
editableIds: newEditableIds
|
|
2209
|
+
});
|
|
2210
|
+
});
|
|
2211
|
+
});
|
|
2752
2212
|
});
|
|
2753
2213
|
}
|
|
2754
2214
|
});
|
|
@@ -2965,7 +2425,7 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides, showV
|
|
|
2965
2425
|
}
|
|
2966
2426
|
|
|
2967
2427
|
// src/puck/store/index.tsx
|
|
2968
|
-
var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
|
|
2428
|
+
var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}, contentAreaNames) => {
|
|
2969
2429
|
const normalizedSoftComponents = Object.fromEntries(
|
|
2970
2430
|
Object.entries(softComponents || {}).filter(([key]) => !hardConfig.components || !hardConfig.components[key]).map(([key, value]) => [key, __spreadProps(__spreadValues({}, value), { name: value.name || key })])
|
|
2971
2431
|
);
|
|
@@ -2977,7 +2437,7 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
|
|
|
2977
2437
|
const initialDependencyGraph = buildReverseDependencyGraph(
|
|
2978
2438
|
hydratedSoftComponents
|
|
2979
2439
|
);
|
|
2980
|
-
return (0,
|
|
2440
|
+
return (0, import_zustand.create)()(
|
|
2981
2441
|
(0, import_middleware.subscribeWithSelector)((set, get) => ({
|
|
2982
2442
|
// ─── Initial State ──────────────────────────────────────────────────────
|
|
2983
2443
|
state: "ready",
|
|
@@ -2995,6 +2455,11 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
|
|
|
2995
2455
|
softComponents: hydratedSoftComponents,
|
|
2996
2456
|
dependencyGraph: initialDependencyGraph,
|
|
2997
2457
|
showVersionFields,
|
|
2458
|
+
contentAreaNames,
|
|
2459
|
+
setContentAreaNames: (names) => set({ contentAreaNames: names }),
|
|
2460
|
+
puckDispatch: null,
|
|
2461
|
+
setPuckDispatch: (dispatch) => set({ puckDispatch: dispatch }),
|
|
2462
|
+
rootActionHandler: rootActionHandler(set, get),
|
|
2998
2463
|
// ─── Initial softConfig ─────────────────────────────────────────────────
|
|
2999
2464
|
softConfig: __spreadProps(__spreadValues({}, hardConfig), {
|
|
3000
2465
|
components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
|
|
@@ -3266,7 +2731,7 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
|
|
|
3266
2731
|
})
|
|
3267
2732
|
})),
|
|
3268
2733
|
// ─── Builder Slice ────────────────────────────────────────────────────────
|
|
3269
|
-
builder: createBuildersSlice(set, get
|
|
2734
|
+
builder: createBuildersSlice(set, get),
|
|
3270
2735
|
// ─── Dependency Graph ─────────────────────────────────────────────────────
|
|
3271
2736
|
rebuildDependents: (componentName) => {
|
|
3272
2737
|
const state = get();
|
|
@@ -3299,8 +2764,39 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
|
|
|
3299
2764
|
};
|
|
3300
2765
|
|
|
3301
2766
|
// src/puck/context/storeProvider.tsx
|
|
3302
|
-
var
|
|
3303
|
-
|
|
2767
|
+
var import_react4 = require("react");
|
|
2768
|
+
|
|
2769
|
+
// src/puck/context/useStore.ts
|
|
2770
|
+
var import_react3 = require("react");
|
|
2771
|
+
var import_zustand2 = require("zustand");
|
|
2772
|
+
var appStoreContext = (0, import_react3.createContext)(null);
|
|
2773
|
+
var createUseSoftConfig = () => {
|
|
2774
|
+
return function useSoftConfig2(selector, equalityFn) {
|
|
2775
|
+
const context = (0, import_react3.useContext)(appStoreContext);
|
|
2776
|
+
if (!context) {
|
|
2777
|
+
throw new Error(
|
|
2778
|
+
"useSoftConfig must be used inside a SoftConfigProvider. Wrap your tree with <SoftConfigProvider value={store}>"
|
|
2779
|
+
);
|
|
2780
|
+
}
|
|
2781
|
+
if (equalityFn) {
|
|
2782
|
+
return (0, import_zustand2.useStore)(context, selector, equalityFn);
|
|
2783
|
+
}
|
|
2784
|
+
return (0, import_zustand2.useStore)(context, selector);
|
|
2785
|
+
};
|
|
2786
|
+
};
|
|
2787
|
+
var useSoftConfig = createUseSoftConfig();
|
|
2788
|
+
var useSoftConfigStore = () => {
|
|
2789
|
+
const context = (0, import_react3.useContext)(appStoreContext);
|
|
2790
|
+
if (!context) {
|
|
2791
|
+
throw new Error(
|
|
2792
|
+
"useSoftConfigStore must be used inside a SoftConfigProvider."
|
|
2793
|
+
);
|
|
2794
|
+
}
|
|
2795
|
+
return context;
|
|
2796
|
+
};
|
|
2797
|
+
|
|
2798
|
+
// src/puck/context/storeProvider.tsx
|
|
2799
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
3304
2800
|
var SoftConfigProvider = ({
|
|
3305
2801
|
children,
|
|
3306
2802
|
hardConfig,
|
|
@@ -3309,27 +2805,25 @@ var SoftConfigProvider = ({
|
|
|
3309
2805
|
overrides,
|
|
3310
2806
|
value,
|
|
3311
2807
|
onActions,
|
|
3312
|
-
useVersioning = false
|
|
2808
|
+
useVersioning = false,
|
|
2809
|
+
contentAreaNames
|
|
3313
2810
|
}) => {
|
|
3314
|
-
const store = (0,
|
|
2811
|
+
const store = (0, import_react4.useMemo)(
|
|
3315
2812
|
() => value != null ? value : createSoftConfigStore(
|
|
3316
2813
|
hardConfig,
|
|
3317
2814
|
softComponents,
|
|
3318
2815
|
overrides,
|
|
3319
2816
|
onActions,
|
|
3320
2817
|
useVersioning,
|
|
3321
|
-
customFields
|
|
2818
|
+
customFields,
|
|
2819
|
+
contentAreaNames
|
|
3322
2820
|
),
|
|
3323
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3324
2821
|
[value]
|
|
3325
|
-
// Intentionally omitting the rest: createSoftConfigStore params are
|
|
3326
|
-
// treated as initialisation-time values. If callers need to react to
|
|
3327
|
-
// prop changes they should pass a new `value` store instead.
|
|
3328
2822
|
);
|
|
3329
|
-
const [softConfig, setSoftConfig] = (0,
|
|
2823
|
+
const [softConfig, setSoftConfig] = (0, import_react4.useState)(
|
|
3330
2824
|
() => store.getState().softConfig
|
|
3331
2825
|
);
|
|
3332
|
-
(0,
|
|
2826
|
+
(0, import_react4.useEffect)(() => {
|
|
3333
2827
|
let prev = store.getState().softConfig;
|
|
3334
2828
|
const unsubscribe = store.subscribe((state) => {
|
|
3335
2829
|
if (state.softConfig !== prev) {
|
|
@@ -3339,17 +2833,17 @@ var SoftConfigProvider = ({
|
|
|
3339
2833
|
});
|
|
3340
2834
|
return unsubscribe;
|
|
3341
2835
|
}, [store]);
|
|
3342
|
-
return /* @__PURE__ */ (0,
|
|
2836
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(appStoreContext.Provider, { value: store, children: children(softConfig) });
|
|
3343
2837
|
};
|
|
3344
2838
|
|
|
3345
2839
|
// src/puck/actions/useBuild.tsx
|
|
3346
|
-
var
|
|
2840
|
+
var import_core3 = require("@puckeditor/core");
|
|
3347
2841
|
|
|
3348
2842
|
// src/puck/lib/notify.ts
|
|
3349
2843
|
var customHandler = null;
|
|
3350
2844
|
var defaultHandler = (message, type) => {
|
|
3351
2845
|
if (type === "error") {
|
|
3352
|
-
|
|
2846
|
+
alert(`[Error] ${message}`);
|
|
3353
2847
|
} else {
|
|
3354
2848
|
console.log(`[Success] ${message}`);
|
|
3355
2849
|
}
|
|
@@ -3369,10 +2863,10 @@ var notify = {
|
|
|
3369
2863
|
};
|
|
3370
2864
|
|
|
3371
2865
|
// src/puck/hooks/useActionEvent.ts
|
|
3372
|
-
var
|
|
2866
|
+
var import_react5 = require("react");
|
|
3373
2867
|
var useActionEvent = () => {
|
|
3374
2868
|
const onActions = useSoftConfig((s) => s.onActions);
|
|
3375
|
-
const triggerAction = (0,
|
|
2869
|
+
const triggerAction = (0, import_react5.useCallback)(
|
|
3376
2870
|
(event) => __async(null, null, function* () {
|
|
3377
2871
|
if (onActions) {
|
|
3378
2872
|
try {
|
|
@@ -3388,13 +2882,13 @@ var useActionEvent = () => {
|
|
|
3388
2882
|
};
|
|
3389
2883
|
|
|
3390
2884
|
// src/puck/actions/useBuild.tsx
|
|
3391
|
-
var
|
|
2885
|
+
var useCustomPuck = (0, import_core3.createUsePuck)();
|
|
3392
2886
|
var useBuild = (name) => {
|
|
3393
2887
|
const build = useSoftConfig((s) => s.builder.build);
|
|
3394
|
-
const history =
|
|
3395
|
-
const selectedItem =
|
|
3396
|
-
const itemSelector =
|
|
3397
|
-
const dispatch =
|
|
2888
|
+
const history = useCustomPuck((s) => s.history.histories);
|
|
2889
|
+
const selectedItem = useCustomPuck((s) => s.selectedItem);
|
|
2890
|
+
const itemSelector = useCustomPuck((s) => s.appState.ui.itemSelector);
|
|
2891
|
+
const dispatch = useCustomPuck((s) => s.dispatch);
|
|
3398
2892
|
const status = useSoftConfig((s) => s.state);
|
|
3399
2893
|
const { triggerAction } = useActionEvent();
|
|
3400
2894
|
const handleBuild = () => {
|
|
@@ -3413,7 +2907,7 @@ var useBuild = (name) => {
|
|
|
3413
2907
|
});
|
|
3414
2908
|
}
|
|
3415
2909
|
} catch (error) {
|
|
3416
|
-
|
|
2910
|
+
alert("Failed to build: " + error);
|
|
3417
2911
|
notify.error(
|
|
3418
2912
|
"Failed to build: " + (error instanceof Error ? error.message : String(error))
|
|
3419
2913
|
);
|
|
@@ -3423,17 +2917,17 @@ var useBuild = (name) => {
|
|
|
3423
2917
|
};
|
|
3424
2918
|
|
|
3425
2919
|
// src/puck/actions/useRemodel.tsx
|
|
3426
|
-
var
|
|
3427
|
-
var
|
|
2920
|
+
var import_core4 = require("@puckeditor/core");
|
|
2921
|
+
var useCustomPuck2 = (0, import_core4.createUsePuck)();
|
|
3428
2922
|
var useRemodel = () => {
|
|
3429
2923
|
const remodel = useSoftConfig((s) => s.builder.remodel);
|
|
3430
|
-
const history =
|
|
3431
|
-
const selectedItem =
|
|
3432
|
-
const itemSelector =
|
|
3433
|
-
const dispatch =
|
|
2924
|
+
const history = useCustomPuck2((s) => s.history.histories);
|
|
2925
|
+
const selectedItem = useCustomPuck2((s) => s.selectedItem);
|
|
2926
|
+
const itemSelector = useCustomPuck2((s) => s.appState.ui.itemSelector);
|
|
2927
|
+
const dispatch = useCustomPuck2((s) => s.dispatch);
|
|
3434
2928
|
const status = useSoftConfig((s) => s.state);
|
|
3435
2929
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
3436
|
-
const refreshPermissions =
|
|
2930
|
+
const refreshPermissions = useCustomPuck2((s) => s.refreshPermissions);
|
|
3437
2931
|
const { triggerAction } = useActionEvent();
|
|
3438
2932
|
const handleRemodel = (componentName) => {
|
|
3439
2933
|
var _a, _b, _c;
|
|
@@ -3449,7 +2943,13 @@ var useRemodel = () => {
|
|
|
3449
2943
|
const selectedVersion = ((_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.version) || ((_b = softComponents[name]) == null ? void 0 : _b.defaultVersion);
|
|
3450
2944
|
const selectedSoftComponent = selectedVersion ? (_c = softComponents[name]) == null ? void 0 : _c.versions[selectedVersion] : void 0;
|
|
3451
2945
|
try {
|
|
3452
|
-
remodel(
|
|
2946
|
+
remodel(
|
|
2947
|
+
history,
|
|
2948
|
+
selectedItem,
|
|
2949
|
+
itemSelector,
|
|
2950
|
+
dispatch,
|
|
2951
|
+
refreshPermissions
|
|
2952
|
+
);
|
|
3453
2953
|
void triggerAction({
|
|
3454
2954
|
type: "remodel",
|
|
3455
2955
|
payload: {
|
|
@@ -3467,9 +2967,9 @@ var useRemodel = () => {
|
|
|
3467
2967
|
}
|
|
3468
2968
|
return { id: name, version: selectedVersion };
|
|
3469
2969
|
} catch (error) {
|
|
3470
|
-
|
|
2970
|
+
alert("Failed to remodel: " + error);
|
|
3471
2971
|
notify.error(
|
|
3472
|
-
"Failed to remodel: " + (error instanceof Error ? error.message : String(error))
|
|
2972
|
+
"Failed to remodel: " + (error instanceof Error ? error.message : String(error)) + " " + String()
|
|
3473
2973
|
);
|
|
3474
2974
|
return null;
|
|
3475
2975
|
}
|
|
@@ -3482,24 +2982,28 @@ var useRemodel = () => {
|
|
|
3482
2982
|
};
|
|
3483
2983
|
|
|
3484
2984
|
// src/puck/actions/useComplete.tsx
|
|
3485
|
-
var
|
|
3486
|
-
var
|
|
3487
|
-
var
|
|
2985
|
+
var import_core5 = require("@puckeditor/core");
|
|
2986
|
+
var import_react6 = require("react");
|
|
2987
|
+
var useCustomPuck3 = (0, import_core5.createUsePuck)();
|
|
3488
2988
|
var useComplete = () => {
|
|
3489
2989
|
const complete = useSoftConfig((s) => s.builder.complete);
|
|
3490
|
-
const appState =
|
|
3491
|
-
const setHistories =
|
|
3492
|
-
const getItemBySelector =
|
|
2990
|
+
const appState = useCustomPuck3((s) => s.appState);
|
|
2991
|
+
const setHistories = useCustomPuck3((s) => s.history.setHistories);
|
|
2992
|
+
const getItemBySelector = useCustomPuck3((s) => s.getItemBySelector);
|
|
3493
2993
|
const status = useSoftConfig((s) => s.state);
|
|
3494
|
-
const [newComponent, setNewComponent] = (0,
|
|
2994
|
+
const [newComponent, setNewComponent] = (0, import_react6.useState)(null);
|
|
3495
2995
|
const { triggerAction } = useActionEvent();
|
|
3496
|
-
const handleComplete = (0,
|
|
2996
|
+
const handleComplete = (0, import_react6.useCallback)(() => {
|
|
3497
2997
|
if (status === "ready") {
|
|
3498
2998
|
notify.error("Not building or remodeling a component.");
|
|
3499
2999
|
return null;
|
|
3500
3000
|
}
|
|
3501
3001
|
try {
|
|
3502
|
-
const completedComponent = complete(
|
|
3002
|
+
const completedComponent = complete(
|
|
3003
|
+
appState,
|
|
3004
|
+
setHistories,
|
|
3005
|
+
getItemBySelector
|
|
3006
|
+
);
|
|
3503
3007
|
setNewComponent(completedComponent);
|
|
3504
3008
|
const componentData = appState.data.root;
|
|
3505
3009
|
if (componentData) {
|
|
@@ -3521,17 +3025,26 @@ var useComplete = () => {
|
|
|
3521
3025
|
);
|
|
3522
3026
|
return null;
|
|
3523
3027
|
}
|
|
3524
|
-
}, [
|
|
3028
|
+
}, [
|
|
3029
|
+
complete,
|
|
3030
|
+
appState,
|
|
3031
|
+
setHistories,
|
|
3032
|
+
status,
|
|
3033
|
+
triggerAction,
|
|
3034
|
+
getItemBySelector
|
|
3035
|
+
]);
|
|
3525
3036
|
const canComplete = status === "building" || status === "remodeling";
|
|
3526
3037
|
return { handleComplete, canComplete, newComponent, setNewComponent };
|
|
3527
3038
|
};
|
|
3528
3039
|
|
|
3529
3040
|
// src/puck/actions/useCancel.tsx
|
|
3530
|
-
var
|
|
3531
|
-
var
|
|
3041
|
+
var import_core6 = require("@puckeditor/core");
|
|
3042
|
+
var useCustomPuck4 = (0, import_core6.createUsePuck)();
|
|
3532
3043
|
var useCancel = () => {
|
|
3533
3044
|
const cancel = useSoftConfig((s) => s.builder.cancel);
|
|
3534
|
-
const setHistories =
|
|
3045
|
+
const setHistories = useCustomPuck4((s) => s.history.setHistories);
|
|
3046
|
+
const puckDispatch = useCustomPuck4((s) => s.dispatch);
|
|
3047
|
+
const selectedItemSelector = useCustomPuck4((s) => s.appState.ui.itemSelector);
|
|
3535
3048
|
const status = useSoftConfig((s) => s.state);
|
|
3536
3049
|
const { triggerAction } = useActionEvent();
|
|
3537
3050
|
const handleCancel = () => {
|
|
@@ -3540,13 +3053,13 @@ var useCancel = () => {
|
|
|
3540
3053
|
return;
|
|
3541
3054
|
}
|
|
3542
3055
|
try {
|
|
3543
|
-
cancel(setHistories);
|
|
3056
|
+
cancel(setHistories, puckDispatch, selectedItemSelector);
|
|
3544
3057
|
void triggerAction({
|
|
3545
3058
|
type: "cancel",
|
|
3546
3059
|
payload: {}
|
|
3547
3060
|
});
|
|
3548
3061
|
} catch (error) {
|
|
3549
|
-
|
|
3062
|
+
alert("Failed to cancel: " + error);
|
|
3550
3063
|
notify.error(
|
|
3551
3064
|
"Failed to cancel: " + (error instanceof Error ? error.message : String(error))
|
|
3552
3065
|
);
|
|
@@ -3557,22 +3070,22 @@ var useCancel = () => {
|
|
|
3557
3070
|
};
|
|
3558
3071
|
|
|
3559
3072
|
// src/puck/actions/useInspect.tsx
|
|
3560
|
-
var
|
|
3561
|
-
var
|
|
3562
|
-
var
|
|
3073
|
+
var import_core7 = require("@puckeditor/core");
|
|
3074
|
+
var import_react7 = require("react");
|
|
3075
|
+
var useCustomPuck5 = (0, import_core7.createUsePuck)();
|
|
3563
3076
|
var useInspect = (component) => {
|
|
3564
3077
|
const inspect = useSoftConfig((s) => s.builder.inspect);
|
|
3565
|
-
const dispatch =
|
|
3078
|
+
const dispatch = useCustomPuck5((s) => s.dispatch);
|
|
3566
3079
|
const status = useSoftConfig((s) => s.state);
|
|
3567
3080
|
const { triggerAction } = useActionEvent();
|
|
3568
|
-
(0,
|
|
3081
|
+
(0, import_react7.useEffect)(() => {
|
|
3569
3082
|
if (status !== "inspecting") return;
|
|
3570
3083
|
if (!component) {
|
|
3571
3084
|
notify.error("No component to inspect.");
|
|
3572
3085
|
return;
|
|
3573
3086
|
}
|
|
3574
3087
|
try {
|
|
3575
|
-
inspect(component.id, dispatch);
|
|
3088
|
+
inspect(component.id, dispatch, null);
|
|
3576
3089
|
void triggerAction({
|
|
3577
3090
|
type: "inspect",
|
|
3578
3091
|
payload: {
|
|
@@ -3591,16 +3104,24 @@ var useInspect = (component) => {
|
|
|
3591
3104
|
};
|
|
3592
3105
|
|
|
3593
3106
|
// src/puck/actions/useDecompose.tsx
|
|
3594
|
-
var
|
|
3595
|
-
|
|
3107
|
+
var import_core8 = require("@puckeditor/core");
|
|
3108
|
+
|
|
3109
|
+
// src/puck/lib/get-prop-by-path.ts
|
|
3110
|
+
function getPropertyByPath(props, path) {
|
|
3111
|
+
return path.replace(/\[(\w+)\]/g, ".$1").split(".").reduce((o, key) => o ? o[key] : void 0, props);
|
|
3112
|
+
}
|
|
3113
|
+
|
|
3114
|
+
// src/puck/actions/useDecompose.tsx
|
|
3115
|
+
var useCustomPuck6 = (0, import_core8.createUsePuck)();
|
|
3596
3116
|
var useDecompose = () => {
|
|
3597
3117
|
const decompose = useSoftConfig((s) => s.builder.decompose);
|
|
3598
|
-
const appState =
|
|
3599
|
-
const dispatch =
|
|
3600
|
-
const selectedItem =
|
|
3118
|
+
const appState = useCustomPuck6((s) => s.appState);
|
|
3119
|
+
const dispatch = useCustomPuck6((s) => s.dispatch);
|
|
3120
|
+
const selectedItem = useCustomPuck6((s) => s.selectedItem);
|
|
3601
3121
|
const status = useSoftConfig((s) => s.state);
|
|
3602
3122
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
3603
3123
|
const config = useSoftConfig((s) => s.softConfig);
|
|
3124
|
+
const contentAreaNames = useSoftConfig((s) => s.contentAreaNames);
|
|
3604
3125
|
const { triggerAction } = useActionEvent();
|
|
3605
3126
|
const handleDecompose = (componentData) => {
|
|
3606
3127
|
if (status !== "ready") {
|
|
@@ -3623,12 +3144,24 @@ var useDecompose = () => {
|
|
|
3623
3144
|
notify.error("Nothing to decompose.");
|
|
3624
3145
|
return;
|
|
3625
3146
|
}
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3147
|
+
let newData = __spreadValues({}, appState.data);
|
|
3148
|
+
const targetAreas = contentAreaNames && contentAreaNames.length > 0 ? contentAreaNames : ["content"];
|
|
3149
|
+
targetAreas.forEach((path) => {
|
|
3150
|
+
const contentArray = getPropertyByPath(newData, path) || [];
|
|
3151
|
+
const walkedData = (0, import_core8.walkTree)(
|
|
3152
|
+
{ content: contentArray, root: newData.root || {} },
|
|
3153
|
+
config,
|
|
3154
|
+
(components) => {
|
|
3155
|
+
const index = components.findIndex(
|
|
3156
|
+
(c) => c.props.id === target.props.id
|
|
3157
|
+
);
|
|
3158
|
+
if (index !== -1) {
|
|
3159
|
+
components.splice(index, 1, ...decomposedComponents);
|
|
3160
|
+
}
|
|
3161
|
+
return components;
|
|
3162
|
+
}
|
|
3163
|
+
);
|
|
3164
|
+
setPropertyByPath(newData, path, walkedData.content);
|
|
3632
3165
|
});
|
|
3633
3166
|
dispatch({
|
|
3634
3167
|
type: "setData",
|
|
@@ -3641,7 +3174,7 @@ var useDecompose = () => {
|
|
|
3641
3174
|
}
|
|
3642
3175
|
});
|
|
3643
3176
|
} catch (error) {
|
|
3644
|
-
|
|
3177
|
+
alert("Failed to decompose: " + error);
|
|
3645
3178
|
notify.error(
|
|
3646
3179
|
"Failed to decompose: " + (error instanceof Error ? error.message : String(error))
|
|
3647
3180
|
);
|
|
@@ -3655,12 +3188,12 @@ var useDecompose = () => {
|
|
|
3655
3188
|
};
|
|
3656
3189
|
|
|
3657
3190
|
// src/puck/actions/useDemolish.tsx
|
|
3658
|
-
var
|
|
3659
|
-
var
|
|
3191
|
+
var import_core9 = require("@puckeditor/core");
|
|
3192
|
+
var useCustomPuck7 = (0, import_core9.createUsePuck)();
|
|
3660
3193
|
var useDemolish = () => {
|
|
3661
3194
|
const demolish = useSoftConfig((s) => s.builder.demolish);
|
|
3662
|
-
const dispatch =
|
|
3663
|
-
const data =
|
|
3195
|
+
const dispatch = useCustomPuck7((s) => s.dispatch);
|
|
3196
|
+
const data = useCustomPuck7((s) => s.appState.data);
|
|
3664
3197
|
const status = useSoftConfig((s) => s.state);
|
|
3665
3198
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
3666
3199
|
const { triggerAction } = useActionEvent();
|
|
@@ -3682,7 +3215,7 @@ var useDemolish = () => {
|
|
|
3682
3215
|
}
|
|
3683
3216
|
});
|
|
3684
3217
|
} catch (error) {
|
|
3685
|
-
|
|
3218
|
+
alert("Failed to demolish: " + error);
|
|
3686
3219
|
notify.error(
|
|
3687
3220
|
"Failed to demolish: " + (error instanceof Error ? error.message : String(error))
|
|
3688
3221
|
);
|
|
@@ -3743,17 +3276,17 @@ var useSetDefaultVersion = () => {
|
|
|
3743
3276
|
};
|
|
3744
3277
|
|
|
3745
3278
|
// src/puck/overrides/Header.tsx
|
|
3746
|
-
var
|
|
3279
|
+
var import_core11 = require("@puckeditor/core");
|
|
3747
3280
|
|
|
3748
3281
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Header.module.css#css-module
|
|
3749
3282
|
var Header_module_default = { "Header": "_Header_19oj9_1" };
|
|
3750
3283
|
|
|
3751
3284
|
// src/puck/actions/usePublish.tsx
|
|
3752
|
-
var
|
|
3753
|
-
var
|
|
3285
|
+
var import_core10 = require("@puckeditor/core");
|
|
3286
|
+
var useCustomPuck8 = (0, import_core10.createUsePuck)();
|
|
3754
3287
|
var usePublish = () => {
|
|
3755
3288
|
const components = useSoftConfig((s) => s.softComponents);
|
|
3756
|
-
const data =
|
|
3289
|
+
const data = useCustomPuck8((s) => s.appState.data);
|
|
3757
3290
|
const status = useSoftConfig((s) => s.state);
|
|
3758
3291
|
const { triggerAction } = useActionEvent();
|
|
3759
3292
|
const handlePublish = (publish) => {
|
|
@@ -3784,7 +3317,7 @@ var usePublish = () => {
|
|
|
3784
3317
|
};
|
|
3785
3318
|
|
|
3786
3319
|
// src/puck/overrides/Header.tsx
|
|
3787
|
-
var
|
|
3320
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
3788
3321
|
var getClassName2 = get_class_name_factory_default("Header", Header_module_default);
|
|
3789
3322
|
var Header = ({
|
|
3790
3323
|
onPublish,
|
|
@@ -3794,10 +3327,10 @@ var Header = ({
|
|
|
3794
3327
|
const { handleCancel, canCancel } = useCancel();
|
|
3795
3328
|
const { handlePublish } = usePublish();
|
|
3796
3329
|
useInspect(newComponent);
|
|
3797
|
-
return /* @__PURE__ */ (0,
|
|
3798
|
-
/* @__PURE__ */ (0,
|
|
3799
|
-
/* @__PURE__ */ (0,
|
|
3800
|
-
|
|
3330
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName2(), children: canCancel ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
3331
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_core11.Button, { onClick: handleCancel, children: "Cancel" }),
|
|
3332
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3333
|
+
import_core11.Button,
|
|
3801
3334
|
{
|
|
3802
3335
|
variant: "primary",
|
|
3803
3336
|
onClick: () => {
|
|
@@ -3809,8 +3342,8 @@ var Header = ({
|
|
|
3809
3342
|
children: "Complete"
|
|
3810
3343
|
}
|
|
3811
3344
|
)
|
|
3812
|
-
] }) : children ? children : /* @__PURE__ */ (0,
|
|
3813
|
-
|
|
3345
|
+
] }) : children ? children : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3346
|
+
import_core11.Button,
|
|
3814
3347
|
{
|
|
3815
3348
|
variant: "primary",
|
|
3816
3349
|
onClick: () => {
|
|
@@ -3824,8 +3357,8 @@ var Header = ({
|
|
|
3824
3357
|
};
|
|
3825
3358
|
|
|
3826
3359
|
// src/puck/overrides/ActionBar.tsx
|
|
3827
|
-
var
|
|
3828
|
-
var
|
|
3360
|
+
var import_react8 = require("react");
|
|
3361
|
+
var import_core12 = require("@puckeditor/core");
|
|
3829
3362
|
var import_lucide_react = require("lucide-react");
|
|
3830
3363
|
|
|
3831
3364
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
|
|
@@ -3833,23 +3366,26 @@ var ActionBar_module_default = { "ActionBar": "_ActionBar_pvuie_5", "ActionBar-l
|
|
|
3833
3366
|
|
|
3834
3367
|
// src/puck/overrides/ActionBar.tsx
|
|
3835
3368
|
var import_shallow = require("zustand/shallow");
|
|
3836
|
-
var
|
|
3369
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
3370
|
+
var useCustomPuck9 = (0, import_core12.createUsePuck)();
|
|
3837
3371
|
var getClassName3 = get_class_name_factory_default("ActionBar", ActionBar_module_default);
|
|
3838
|
-
var usePuck = (0, import_puck14.createUsePuck)();
|
|
3839
3372
|
var ActionBarOverride = (props) => {
|
|
3840
3373
|
var _a, _b;
|
|
3841
|
-
const { handleBuild } = useBuild(
|
|
3374
|
+
const { handleBuild } = useBuild(
|
|
3375
|
+
props.label ? props.label + " Soft Component" : "New Soft Component"
|
|
3376
|
+
);
|
|
3842
3377
|
const { handleRemodel } = useRemodel();
|
|
3843
3378
|
const { handleDecompose } = useDecompose();
|
|
3844
3379
|
const overrides = useSoftConfig((s) => s.overrides);
|
|
3845
3380
|
const softComponents = useSoftConfig((s) => s.softComponents, import_shallow.shallow);
|
|
3846
3381
|
const editableIds = useSoftConfig((s) => s.editableComponentIds);
|
|
3847
|
-
const selectedItem =
|
|
3848
|
-
const
|
|
3382
|
+
const selectedItem = useCustomPuck9((s) => s.selectedItem);
|
|
3383
|
+
const appState = useCustomPuck9((s) => s.appState);
|
|
3384
|
+
const rootProps = appState.data.root.props;
|
|
3849
3385
|
const status = useSoftConfig((s) => s.state);
|
|
3850
|
-
const itemSelector =
|
|
3386
|
+
const itemSelector = appState.ui.itemSelector;
|
|
3851
3387
|
const softKeys = Object.keys(softComponents);
|
|
3852
|
-
const key = (0,
|
|
3388
|
+
const key = (0, import_react8.useMemo)(() => {
|
|
3853
3389
|
const selectedType = selectedItem == null ? void 0 : selectedItem.type;
|
|
3854
3390
|
if (selectedType && softKeys.includes(selectedType)) {
|
|
3855
3391
|
return selectedType;
|
|
@@ -3858,54 +3394,49 @@ var ActionBarOverride = (props) => {
|
|
|
3858
3394
|
existingKeys: softKeys,
|
|
3859
3395
|
state: status
|
|
3860
3396
|
}));
|
|
3861
|
-
}, [
|
|
3862
|
-
props.label,
|
|
3863
|
-
overrides,
|
|
3864
|
-
selectedItem == null ? void 0 : selectedItem.type,
|
|
3865
|
-
softKeys,
|
|
3866
|
-
status,
|
|
3867
|
-
rootProps
|
|
3868
|
-
]);
|
|
3397
|
+
}, [props.label, overrides, selectedItem == null ? void 0 : selectedItem.type, softKeys, status, rootProps]);
|
|
3869
3398
|
const isSoftComponent2 = softKeys.includes(key);
|
|
3870
3399
|
const selectedId = (_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.id;
|
|
3871
3400
|
const parentId = (_b = itemSelector == null ? void 0 : itemSelector.zone) == null ? void 0 : _b.split(":")[0];
|
|
3872
|
-
const isEditable = Boolean(
|
|
3873
|
-
|
|
3401
|
+
const isEditable = Boolean(
|
|
3402
|
+
selectedId && (editableIds.has(selectedId) || parentId && editableIds.has(parentId))
|
|
3403
|
+
);
|
|
3404
|
+
const label = (0, import_react8.useMemo)(() => {
|
|
3874
3405
|
var _a2;
|
|
3875
3406
|
if (isSoftComponent2) {
|
|
3876
3407
|
return ((_a2 = softComponents[key]) == null ? void 0 : _a2.name) || componentLabelFromName(key, overrides);
|
|
3877
3408
|
}
|
|
3878
3409
|
return props.label || "";
|
|
3879
3410
|
}, [isSoftComponent2, key, props.label, overrides, softComponents]);
|
|
3880
|
-
return /* @__PURE__ */ (0,
|
|
3881
|
-
/* @__PURE__ */ (0,
|
|
3411
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: getClassName3(), children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_core12.ActionBar, { children: [
|
|
3412
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_core12.ActionBar.Group, { children: [
|
|
3882
3413
|
props.parentAction,
|
|
3883
|
-
/* @__PURE__ */ (0,
|
|
3414
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_core12.ActionBar.Label, { label })
|
|
3884
3415
|
] }),
|
|
3885
|
-
/* @__PURE__ */ (0,
|
|
3886
|
-
status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ (0,
|
|
3887
|
-
/* @__PURE__ */ (0,
|
|
3888
|
-
|
|
3416
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_core12.ActionBar.Group, { children: [
|
|
3417
|
+
status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
3418
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
3419
|
+
import_core12.ActionBar.Action,
|
|
3889
3420
|
{
|
|
3890
3421
|
onClick: () => handleRemodel(key),
|
|
3891
3422
|
label: "Remodel Soft Component",
|
|
3892
|
-
children: /* @__PURE__ */ (0,
|
|
3423
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react.EditIcon, { size: 16 })
|
|
3893
3424
|
}
|
|
3894
3425
|
),
|
|
3895
|
-
/* @__PURE__ */ (0,
|
|
3896
|
-
|
|
3426
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
3427
|
+
import_core12.ActionBar.Action,
|
|
3897
3428
|
{
|
|
3898
3429
|
onClick: () => handleDecompose(),
|
|
3899
3430
|
label: "Decompose Soft Component",
|
|
3900
|
-
children: /* @__PURE__ */ (0,
|
|
3431
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react.Combine, { size: 16 })
|
|
3901
3432
|
}
|
|
3902
3433
|
)
|
|
3903
|
-
] }) : /* @__PURE__ */ (0,
|
|
3904
|
-
|
|
3434
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
3435
|
+
import_core12.ActionBar.Action,
|
|
3905
3436
|
{
|
|
3906
3437
|
onClick: handleBuild,
|
|
3907
3438
|
label: "Build Soft Component",
|
|
3908
|
-
children: /* @__PURE__ */ (0,
|
|
3439
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react.ComponentIcon, { size: 16 })
|
|
3909
3440
|
}
|
|
3910
3441
|
) : null,
|
|
3911
3442
|
status !== "ready" && !isEditable ? null : props.children
|
|
@@ -3914,8 +3445,8 @@ var ActionBarOverride = (props) => {
|
|
|
3914
3445
|
};
|
|
3915
3446
|
|
|
3916
3447
|
// src/puck/overrides/DrawerItem.tsx
|
|
3917
|
-
var
|
|
3918
|
-
var
|
|
3448
|
+
var import_react10 = require("react");
|
|
3449
|
+
var import_core13 = require("@puckeditor/core");
|
|
3919
3450
|
var import_lucide_react2 = require("lucide-react");
|
|
3920
3451
|
|
|
3921
3452
|
// src/puck/lib/confirm.ts
|
|
@@ -3930,7 +3461,7 @@ var confirm = (message) => __async(null, null, function* () {
|
|
|
3930
3461
|
const result = confirmHandler(message);
|
|
3931
3462
|
return result instanceof Promise ? yield result : result;
|
|
3932
3463
|
} catch (error) {
|
|
3933
|
-
|
|
3464
|
+
alert("Confirm handler error: " + error);
|
|
3934
3465
|
return false;
|
|
3935
3466
|
}
|
|
3936
3467
|
});
|
|
@@ -3939,25 +3470,25 @@ var confirm = (message) => __async(null, null, function* () {
|
|
|
3939
3470
|
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" };
|
|
3940
3471
|
|
|
3941
3472
|
// src/puck/components/modal/index.tsx
|
|
3942
|
-
var
|
|
3473
|
+
var import_react9 = require("react");
|
|
3943
3474
|
var import_react_dom = require("react-dom");
|
|
3944
3475
|
|
|
3945
3476
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
|
|
3946
3477
|
var styles_module_default2 = { "Modal": "_Modal_1t9ot_1", "Modal--isOpen": "_Modal--isOpen_1t9ot_29", "Modal-inner": "_Modal-inner_1t9ot_37" };
|
|
3947
3478
|
|
|
3948
3479
|
// src/puck/components/modal/index.tsx
|
|
3949
|
-
var
|
|
3480
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
3950
3481
|
var getClassName4 = get_class_name_factory_default("Modal", styles_module_default2);
|
|
3951
3482
|
var Modal = ({
|
|
3952
3483
|
children,
|
|
3953
3484
|
onClose,
|
|
3954
3485
|
isOpen
|
|
3955
3486
|
}) => {
|
|
3956
|
-
const [rootEl, setRootEl] = (0,
|
|
3957
|
-
(0,
|
|
3487
|
+
const [rootEl, setRootEl] = (0, import_react9.useState)(null);
|
|
3488
|
+
(0, import_react9.useEffect)(() => {
|
|
3958
3489
|
setRootEl(document.getElementById("puck-portal-root"));
|
|
3959
3490
|
}, []);
|
|
3960
|
-
(0,
|
|
3491
|
+
(0, import_react9.useEffect)(() => {
|
|
3961
3492
|
if (!isOpen) {
|
|
3962
3493
|
return;
|
|
3963
3494
|
}
|
|
@@ -3970,10 +3501,10 @@ var Modal = ({
|
|
|
3970
3501
|
return () => document.removeEventListener("keydown", handleEscape);
|
|
3971
3502
|
}, [isOpen, onClose]);
|
|
3972
3503
|
if (!rootEl) {
|
|
3973
|
-
return /* @__PURE__ */ (0,
|
|
3504
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", {});
|
|
3974
3505
|
}
|
|
3975
3506
|
return (0, import_react_dom.createPortal)(
|
|
3976
|
-
/* @__PURE__ */ (0,
|
|
3507
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
3977
3508
|
"div",
|
|
3978
3509
|
{
|
|
3979
3510
|
className: getClassName4({ isOpen }),
|
|
@@ -3982,7 +3513,7 @@ var Modal = ({
|
|
|
3982
3513
|
onClose();
|
|
3983
3514
|
}
|
|
3984
3515
|
},
|
|
3985
|
-
children: /* @__PURE__ */ (0,
|
|
3516
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
3986
3517
|
"div",
|
|
3987
3518
|
{
|
|
3988
3519
|
className: getClassName4("inner"),
|
|
@@ -4000,16 +3531,16 @@ var Modal = ({
|
|
|
4000
3531
|
|
|
4001
3532
|
// src/puck/overrides/DrawerItem.tsx
|
|
4002
3533
|
var import_shallow2 = require("zustand/shallow");
|
|
4003
|
-
var
|
|
3534
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
3535
|
+
var useCustomPuck10 = (0, import_core13.createUsePuck)();
|
|
4004
3536
|
var getClassName5 = get_class_name_factory_default("DrawerItem", DrawerItem_module_default);
|
|
4005
|
-
var usePuck2 = (0, import_puck15.createUsePuck)();
|
|
4006
3537
|
var DrawerItem = (props) => {
|
|
4007
3538
|
const componentMeta = useSoftConfig((s) => s.softComponents[props.name]);
|
|
4008
3539
|
const displayName = props.label || (componentMeta == null ? void 0 : componentMeta.name) || props.name;
|
|
4009
3540
|
const softComponents = new Set(
|
|
4010
3541
|
Object.keys(useSoftConfig((s) => s.softComponents, import_shallow2.shallow))
|
|
4011
3542
|
);
|
|
4012
|
-
const getPermissions =
|
|
3543
|
+
const getPermissions = useCustomPuck10((s) => s.getPermissions);
|
|
4013
3544
|
const insertAllowed = getPermissions({ type: props.name }).insert;
|
|
4014
3545
|
const removeSoftComponentVersion = useSoftConfig(
|
|
4015
3546
|
(s) => s.removeSoftComponentVersion
|
|
@@ -4017,13 +3548,13 @@ var DrawerItem = (props) => {
|
|
|
4017
3548
|
const { handleDemolish } = useDemolish();
|
|
4018
3549
|
const { handleSetDefaultVersion, getVersions, getDefaultVersion } = useSetDefaultVersion();
|
|
4019
3550
|
const { triggerAction } = useActionEvent();
|
|
4020
|
-
const [isEditing, setIsEditing] = (0,
|
|
4021
|
-
const [isHovering, setIsHovering] = (0,
|
|
4022
|
-
const [selectedVersion, setSelectedVersion] = (0,
|
|
4023
|
-
const [versionsToDelete, setVersionsToDelete] = (0,
|
|
3551
|
+
const [isEditing, setIsEditing] = (0, import_react10.useState)(false);
|
|
3552
|
+
const [isHovering, setIsHovering] = (0, import_react10.useState)(false);
|
|
3553
|
+
const [selectedVersion, setSelectedVersion] = (0, import_react10.useState)("");
|
|
3554
|
+
const [versionsToDelete, setVersionsToDelete] = (0, import_react10.useState)(
|
|
4024
3555
|
/* @__PURE__ */ new Set()
|
|
4025
3556
|
);
|
|
4026
|
-
const [migrationTarget, setMigrationTarget] = (0,
|
|
3557
|
+
const [migrationTarget, setMigrationTarget] = (0, import_react10.useState)("decompose");
|
|
4027
3558
|
const useVersioning = useSoftConfig((s) => s.showVersionFields);
|
|
4028
3559
|
const versions = getVersions(props.name);
|
|
4029
3560
|
const defaultVersion = getDefaultVersion(props.name);
|
|
@@ -4093,8 +3624,8 @@ var DrawerItem = (props) => {
|
|
|
4093
3624
|
label: `Migrate to Version ${version}`
|
|
4094
3625
|
}))
|
|
4095
3626
|
];
|
|
4096
|
-
return /* @__PURE__ */ (0,
|
|
4097
|
-
/* @__PURE__ */ (0,
|
|
3627
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
3628
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
4098
3629
|
"div",
|
|
4099
3630
|
{
|
|
4100
3631
|
className: getClassName5({ insertDisabled: !insertAllowed }),
|
|
@@ -4102,71 +3633,86 @@ var DrawerItem = (props) => {
|
|
|
4102
3633
|
onMouseLeave: () => setIsHovering(false),
|
|
4103
3634
|
children: [
|
|
4104
3635
|
props.label,
|
|
4105
|
-
/* @__PURE__ */ (0,
|
|
4106
|
-
/* @__PURE__ */ (0,
|
|
4107
|
-
useVersioning && /* @__PURE__ */ (0,
|
|
3636
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName5("content"), children: [
|
|
3637
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName5("name"), children: displayName }),
|
|
3638
|
+
useVersioning && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName5("version"), children: [
|
|
4108
3639
|
"v",
|
|
4109
3640
|
defaultVersion
|
|
4110
3641
|
] })
|
|
4111
3642
|
] }),
|
|
4112
|
-
/* @__PURE__ */ (0,
|
|
4113
|
-
isHovering && /* @__PURE__ */ (0,
|
|
4114
|
-
|
|
3643
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName5("actions"), children: [
|
|
3644
|
+
isHovering && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName5("settingsButton"), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
3645
|
+
import_core13.IconButton,
|
|
4115
3646
|
{
|
|
4116
3647
|
title: "Settings",
|
|
4117
|
-
variant: "secondary",
|
|
4118
3648
|
onClick: (e) => {
|
|
4119
3649
|
e.stopPropagation();
|
|
4120
3650
|
setIsEditing(true);
|
|
4121
3651
|
setSelectedVersion(defaultVersion || "");
|
|
4122
3652
|
},
|
|
4123
|
-
children: /* @__PURE__ */ (0,
|
|
3653
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.Cog, { size: 12 })
|
|
4124
3654
|
}
|
|
4125
3655
|
) }),
|
|
4126
|
-
/* @__PURE__ */ (0,
|
|
3656
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName5("grip"), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.GripVertical, { size: 16 }) })
|
|
4127
3657
|
] })
|
|
4128
3658
|
]
|
|
4129
3659
|
}
|
|
4130
3660
|
),
|
|
4131
|
-
/* @__PURE__ */ (0,
|
|
4132
|
-
/* @__PURE__ */ (0,
|
|
4133
|
-
/* @__PURE__ */ (0,
|
|
4134
|
-
/* @__PURE__ */ (0,
|
|
3661
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Modal, { isOpen: isEditing, onClose: handleCancel, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName5("modal"), children: [
|
|
3662
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName5("modalHeader"), children: [
|
|
3663
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h2", { className: getClassName5("modalTitle"), children: displayName }),
|
|
3664
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: getClassName5("modalSubtitle"), children: "Component Settings" })
|
|
4135
3665
|
] }),
|
|
4136
|
-
/* @__PURE__ */ (0,
|
|
4137
|
-
/* @__PURE__ */ (0,
|
|
4138
|
-
/* @__PURE__ */ (0,
|
|
4139
|
-
/* @__PURE__ */ (0,
|
|
3666
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName5("modalBody"), children: useVersioning ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
3667
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName5("section"), children: [
|
|
3668
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h3", { className: getClassName5("sectionTitle"), children: "Versions" }),
|
|
3669
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName5("versionList"), children: versions.map((version) => {
|
|
4140
3670
|
const isDefault = version === (selectedVersion || defaultVersion);
|
|
4141
3671
|
const isMarkedForDeletion = versionsToDelete.has(version);
|
|
4142
3672
|
let rowClass = getClassName5("versionRow");
|
|
4143
|
-
if (isDefault)
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
3673
|
+
if (isDefault)
|
|
3674
|
+
rowClass += " " + getClassName5("versionRow--isDefault");
|
|
3675
|
+
if (isMarkedForDeletion)
|
|
3676
|
+
rowClass += " " + getClassName5("versionRow--isMarkedForDeletion");
|
|
3677
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: rowClass, children: [
|
|
3678
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName5("versionInfo"), children: [
|
|
3679
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: getClassName5("versionNumber"), children: [
|
|
4148
3680
|
"Version ",
|
|
4149
3681
|
version
|
|
4150
3682
|
] }),
|
|
4151
|
-
isDefault && /* @__PURE__ */ (0,
|
|
4152
|
-
isMarkedForDeletion && /* @__PURE__ */ (0,
|
|
3683
|
+
isDefault && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: getClassName5("defaultBadge"), children: "Default" }),
|
|
3684
|
+
isMarkedForDeletion && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: getClassName5("deleteBadge"), children: "Marked for deletion" })
|
|
4153
3685
|
] }),
|
|
4154
|
-
/* @__PURE__ */ (0,
|
|
4155
|
-
!isDefault && !isMarkedForDeletion && /* @__PURE__ */ (0,
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
3686
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName5("versionActions"), children: [
|
|
3687
|
+
!isDefault && !isMarkedForDeletion && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
3688
|
+
import_core13.Button,
|
|
3689
|
+
{
|
|
3690
|
+
variant: "secondary",
|
|
3691
|
+
onClick: () => setSelectedVersion(version),
|
|
3692
|
+
children: "Set as Default"
|
|
3693
|
+
}
|
|
3694
|
+
),
|
|
3695
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
3696
|
+
import_core13.Button,
|
|
3697
|
+
{
|
|
3698
|
+
variant: "secondary",
|
|
3699
|
+
onClick: () => toggleVersionForDeletion(version),
|
|
3700
|
+
children: isMarkedForDeletion ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
3701
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.X, { size: 14 }),
|
|
3702
|
+
" Undo"
|
|
3703
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
3704
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.Trash2, { size: 14 }),
|
|
3705
|
+
" Delete"
|
|
3706
|
+
] })
|
|
3707
|
+
}
|
|
3708
|
+
)
|
|
4163
3709
|
] })
|
|
4164
3710
|
] }, version);
|
|
4165
3711
|
}) })
|
|
4166
3712
|
] }),
|
|
4167
|
-
versionsToDelete.size > 0 && /* @__PURE__ */ (0,
|
|
4168
|
-
/* @__PURE__ */ (0,
|
|
4169
|
-
/* @__PURE__ */ (0,
|
|
3713
|
+
versionsToDelete.size > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName5("section"), children: [
|
|
3714
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h3", { className: getClassName5("sectionTitle"), children: "Migration Settings" }),
|
|
3715
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName5("migrationOptions"), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
4170
3716
|
"div",
|
|
4171
3717
|
{
|
|
4172
3718
|
className: getClassName5("migrationList"),
|
|
@@ -4174,18 +3720,28 @@ var DrawerItem = (props) => {
|
|
|
4174
3720
|
"aria-label": "Migration target",
|
|
4175
3721
|
children: migrationTargets.map((target) => {
|
|
4176
3722
|
const isSelected = migrationTarget === target.value;
|
|
4177
|
-
return /* @__PURE__ */ (0,
|
|
3723
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
4178
3724
|
"button",
|
|
4179
3725
|
{
|
|
4180
3726
|
"aria-label": target.label,
|
|
4181
3727
|
type: "button",
|
|
4182
3728
|
role: "radio",
|
|
4183
3729
|
"aria-checked": isSelected,
|
|
4184
|
-
className: `${getClassName5("migrationOption")} ${isSelected ? getClassName5(
|
|
3730
|
+
className: `${getClassName5("migrationOption")} ${isSelected ? getClassName5(
|
|
3731
|
+
"migrationOption--isSelected"
|
|
3732
|
+
) : ""}`,
|
|
4185
3733
|
onClick: () => setMigrationTarget(target.value),
|
|
4186
3734
|
children: [
|
|
4187
|
-
/* @__PURE__ */ (0,
|
|
4188
|
-
|
|
3735
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
3736
|
+
"span",
|
|
3737
|
+
{
|
|
3738
|
+
className: getClassName5(
|
|
3739
|
+
"migrationOptionLabel"
|
|
3740
|
+
),
|
|
3741
|
+
children: target.label
|
|
3742
|
+
}
|
|
3743
|
+
),
|
|
3744
|
+
isSelected && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.Check, { size: 14 })
|
|
4189
3745
|
]
|
|
4190
3746
|
},
|
|
4191
3747
|
target.value
|
|
@@ -4193,49 +3749,65 @@ var DrawerItem = (props) => {
|
|
|
4193
3749
|
})
|
|
4194
3750
|
}
|
|
4195
3751
|
) }),
|
|
4196
|
-
/* @__PURE__ */ (0,
|
|
3752
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: getClassName5("helpText"), children: "Choose where to move existing instances of the deleted versions." })
|
|
4197
3753
|
] })
|
|
4198
|
-
] }) : /* @__PURE__ */ (0,
|
|
4199
|
-
"Manage high-level settings for the
|
|
4200
|
-
|
|
3754
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName5("section"), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("p", { children: [
|
|
3755
|
+
"Manage high-level settings for the",
|
|
3756
|
+
" ",
|
|
3757
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("strong", { children: displayName }),
|
|
4201
3758
|
" component."
|
|
4202
3759
|
] }) }) }),
|
|
4203
|
-
/* @__PURE__ */ (0,
|
|
4204
|
-
/* @__PURE__ */ (0,
|
|
4205
|
-
useVersioning ? /* @__PURE__ */ (0,
|
|
4206
|
-
/* @__PURE__ */ (0,
|
|
3760
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName5("modalFooter"), children: [
|
|
3761
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName5("footerLeft"), children: [
|
|
3762
|
+
useVersioning ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_core13.Button, { size: "medium", onClick: handleApply, children: [
|
|
3763
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.Check, { size: 16 }),
|
|
4207
3764
|
" Apply Changes"
|
|
4208
|
-
] }) : /* @__PURE__ */ (0,
|
|
4209
|
-
useVersioning && /* @__PURE__ */ (0,
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
3765
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core13.Button, { size: "medium", onClick: handleCancel, children: "Close" }),
|
|
3766
|
+
useVersioning && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
3767
|
+
import_core13.Button,
|
|
3768
|
+
{
|
|
3769
|
+
size: "medium",
|
|
3770
|
+
variant: "secondary",
|
|
3771
|
+
onClick: handleCancel,
|
|
3772
|
+
children: [
|
|
3773
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.X, { size: 16 }),
|
|
3774
|
+
" Cancel"
|
|
3775
|
+
]
|
|
3776
|
+
}
|
|
3777
|
+
)
|
|
4213
3778
|
] }),
|
|
4214
|
-
/* @__PURE__ */ (0,
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
3779
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName5("footerRight"), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
3780
|
+
import_core13.Button,
|
|
3781
|
+
{
|
|
3782
|
+
size: "medium",
|
|
3783
|
+
variant: "secondary",
|
|
3784
|
+
onClick: handleDemolishClick,
|
|
3785
|
+
children: [
|
|
3786
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.Trash2, { size: 16 }),
|
|
3787
|
+
" Demolish Component"
|
|
3788
|
+
]
|
|
3789
|
+
}
|
|
3790
|
+
) })
|
|
4218
3791
|
] })
|
|
4219
3792
|
] }) })
|
|
4220
3793
|
] });
|
|
4221
3794
|
}
|
|
4222
|
-
return /* @__PURE__ */ (0,
|
|
3795
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: props.children });
|
|
4223
3796
|
};
|
|
4224
|
-
var ComponentItem = DrawerItem;
|
|
4225
3797
|
|
|
4226
3798
|
// src/puck/overrides/Drawer.tsx
|
|
4227
|
-
var
|
|
4228
|
-
var
|
|
3799
|
+
var import_react11 = require("react");
|
|
3800
|
+
var import_core14 = require("@puckeditor/core");
|
|
4229
3801
|
var import_lucide_react3 = require("lucide-react");
|
|
4230
3802
|
|
|
4231
3803
|
// css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Drawer.module.css#css-module
|
|
4232
3804
|
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" };
|
|
4233
3805
|
|
|
4234
3806
|
// src/puck/overrides/Drawer.tsx
|
|
4235
|
-
var
|
|
3807
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
3808
|
+
var useCustomPuck11 = (0, import_core14.createUsePuck)();
|
|
4236
3809
|
var getClassName6 = get_class_name_factory_default("Drawer", Drawer_module_default);
|
|
4237
3810
|
var getCategoryClassName = get_class_name_factory_default("Drawer-category", Drawer_module_default);
|
|
4238
|
-
var usePuck3 = (0, import_puck16.createUsePuck)();
|
|
4239
3811
|
var CategorySection = ({
|
|
4240
3812
|
id,
|
|
4241
3813
|
title,
|
|
@@ -4243,8 +3815,8 @@ var CategorySection = ({
|
|
|
4243
3815
|
getPermissions,
|
|
4244
3816
|
expanded,
|
|
4245
3817
|
onToggle
|
|
4246
|
-
}) => /* @__PURE__ */ (0,
|
|
4247
|
-
title && /* @__PURE__ */ (0,
|
|
3818
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: getCategoryClassName({ isExpanded: expanded }), children: [
|
|
3819
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
4248
3820
|
"button",
|
|
4249
3821
|
{
|
|
4250
3822
|
type: "button",
|
|
@@ -4252,13 +3824,13 @@ var CategorySection = ({
|
|
|
4252
3824
|
onClick: () => onToggle(id),
|
|
4253
3825
|
title: expanded ? `Collapse ${title}` : `Expand ${title}`,
|
|
4254
3826
|
children: [
|
|
4255
|
-
/* @__PURE__ */ (0,
|
|
4256
|
-
/* @__PURE__ */ (0,
|
|
3827
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: title }),
|
|
3828
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: getClassName6("categoryTitleIcon"), children: expanded ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react3.ChevronUp, { size: 12 }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react3.ChevronDown, { size: 12 }) })
|
|
4257
3829
|
]
|
|
4258
3830
|
}
|
|
4259
3831
|
),
|
|
4260
|
-
/* @__PURE__ */ (0,
|
|
4261
|
-
|
|
3832
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: getClassName6("categoryContent"), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_core14.Drawer, { children: componentKeys.map((key) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3833
|
+
import_core14.Drawer.Item,
|
|
4262
3834
|
{
|
|
4263
3835
|
name: key,
|
|
4264
3836
|
isDragDisabled: !getPermissions({ type: key }).insert,
|
|
@@ -4269,8 +3841,8 @@ var CategorySection = ({
|
|
|
4269
3841
|
] });
|
|
4270
3842
|
var Drawer = (_props) => {
|
|
4271
3843
|
var _a, _b;
|
|
4272
|
-
const config =
|
|
4273
|
-
const getPermissions =
|
|
3844
|
+
const config = useCustomPuck11((s) => s.config);
|
|
3845
|
+
const getPermissions = useCustomPuck11((s) => s.getPermissions);
|
|
4274
3846
|
const categories = (_a = config.categories) != null ? _a : {};
|
|
4275
3847
|
const categorised = new Set(
|
|
4276
3848
|
Object.values(categories).flatMap((cat) => {
|
|
@@ -4279,15 +3851,18 @@ var Drawer = (_props) => {
|
|
|
4279
3851
|
})
|
|
4280
3852
|
);
|
|
4281
3853
|
const allKeys = Object.keys(config.components);
|
|
4282
|
-
const labels = Object.entries(config.components).reduce(
|
|
4283
|
-
acc[key
|
|
4284
|
-
|
|
4285
|
-
|
|
3854
|
+
const labels = Object.entries(config.components).reduce(
|
|
3855
|
+
(acc, [key, comp]) => {
|
|
3856
|
+
acc[key] = comp.label || key;
|
|
3857
|
+
return acc;
|
|
3858
|
+
},
|
|
3859
|
+
{}
|
|
3860
|
+
);
|
|
4286
3861
|
const otherKeys = allKeys.filter((k) => !categorised.has(k));
|
|
4287
3862
|
const categoryEntries = Object.entries(categories).filter(
|
|
4288
3863
|
([, cat]) => cat.visible !== false
|
|
4289
3864
|
);
|
|
4290
|
-
const [expanded, setExpanded] = (0,
|
|
3865
|
+
const [expanded, setExpanded] = (0, import_react11.useState)(() => {
|
|
4291
3866
|
const init = {};
|
|
4292
3867
|
categoryEntries.forEach(([id, cat]) => {
|
|
4293
3868
|
init[id] = cat.defaultExpanded !== false;
|
|
@@ -4297,8 +3872,8 @@ var Drawer = (_props) => {
|
|
|
4297
3872
|
});
|
|
4298
3873
|
const toggle = (id) => setExpanded((prev) => __spreadProps(__spreadValues({}, prev), { [id]: !prev[id] }));
|
|
4299
3874
|
if (categoryEntries.length === 0) {
|
|
4300
|
-
return /* @__PURE__ */ (0,
|
|
4301
|
-
|
|
3875
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_core14.Drawer, { children: allKeys.map((key) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3876
|
+
import_core14.Drawer.Item,
|
|
4302
3877
|
{
|
|
4303
3878
|
name: key,
|
|
4304
3879
|
label: labels[key],
|
|
@@ -4308,10 +3883,10 @@ var Drawer = (_props) => {
|
|
|
4308
3883
|
key
|
|
4309
3884
|
)) });
|
|
4310
3885
|
}
|
|
4311
|
-
return /* @__PURE__ */ (0,
|
|
3886
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: getClassName6(), children: [
|
|
4312
3887
|
categoryEntries.map(([id, cat]) => {
|
|
4313
3888
|
var _a2, _b2, _c;
|
|
4314
|
-
return /* @__PURE__ */ (0,
|
|
3889
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
4315
3890
|
CategorySection,
|
|
4316
3891
|
{
|
|
4317
3892
|
id,
|
|
@@ -4326,7 +3901,7 @@ var Drawer = (_props) => {
|
|
|
4326
3901
|
id
|
|
4327
3902
|
);
|
|
4328
3903
|
}),
|
|
4329
|
-
otherKeys.length > 0 && /* @__PURE__ */ (0,
|
|
3904
|
+
otherKeys.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
4330
3905
|
CategorySection,
|
|
4331
3906
|
{
|
|
4332
3907
|
id: "__other__",
|
|
@@ -4341,25 +3916,31 @@ var Drawer = (_props) => {
|
|
|
4341
3916
|
};
|
|
4342
3917
|
|
|
4343
3918
|
// src/puck/overrides/HeaderActions.tsx
|
|
4344
|
-
var
|
|
4345
|
-
var
|
|
4346
|
-
var
|
|
3919
|
+
var import_core15 = require("@puckeditor/core");
|
|
3920
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
3921
|
+
var useCustomPuck12 = (0, import_core15.createUsePuck)();
|
|
4347
3922
|
var HeaderActions = ({ children }) => {
|
|
4348
3923
|
const { handleComplete } = useComplete();
|
|
4349
3924
|
const { handleCancel, canCancel } = useCancel();
|
|
4350
|
-
const dispatch =
|
|
3925
|
+
const dispatch = useCustomPuck12((s) => s.dispatch);
|
|
3926
|
+
const appState = useCustomPuck12((s) => s.appState);
|
|
3927
|
+
const selectedItemSelector = appState.ui.itemSelector;
|
|
4351
3928
|
const inspect = useSoftConfig((s) => s.builder.inspect);
|
|
4352
|
-
return /* @__PURE__ */ (0,
|
|
4353
|
-
/* @__PURE__ */ (0,
|
|
4354
|
-
/* @__PURE__ */ (0,
|
|
4355
|
-
|
|
3929
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: canCancel ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
|
|
3930
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_core15.Button, { onClick: handleCancel, children: "Cancel" }),
|
|
3931
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
3932
|
+
import_core15.Button,
|
|
4356
3933
|
{
|
|
4357
3934
|
variant: "primary",
|
|
4358
3935
|
onClick: () => {
|
|
4359
3936
|
const completedComponent = handleComplete();
|
|
4360
3937
|
if (completedComponent) {
|
|
4361
3938
|
try {
|
|
4362
|
-
inspect(
|
|
3939
|
+
inspect(
|
|
3940
|
+
completedComponent.id,
|
|
3941
|
+
dispatch,
|
|
3942
|
+
selectedItemSelector
|
|
3943
|
+
);
|
|
4363
3944
|
} catch (error) {
|
|
4364
3945
|
notify.error(
|
|
4365
3946
|
"Failed to inspect after completion: " + (error instanceof Error ? error.message : String(error))
|
|
@@ -4582,18 +4163,37 @@ var resolveSoftConfig = (data, softComponents, config) => {
|
|
|
4582
4163
|
if (process.env.NODE_ENV === "development") {
|
|
4583
4164
|
const validation = validateOnlyHardComponents(dissolved, softComponents);
|
|
4584
4165
|
if (!validation.isValid) {
|
|
4585
|
-
|
|
4586
|
-
"Warning: Soft components still present after dissolution:"
|
|
4587
|
-
|
|
4166
|
+
alert(
|
|
4167
|
+
"Warning: Soft components still present after dissolution: " + String(
|
|
4168
|
+
validation.softComponentsFound
|
|
4169
|
+
)
|
|
4588
4170
|
);
|
|
4589
4171
|
}
|
|
4590
4172
|
}
|
|
4591
4173
|
return dissolved;
|
|
4592
4174
|
};
|
|
4175
|
+
|
|
4176
|
+
// src/puck/lib/builder/generate-field-options.ts
|
|
4177
|
+
var hasArrayMappingPath = (value) => value.includes("[]");
|
|
4178
|
+
var isBareArrayPath = (value) => !hasArrayMappingPath(value) && !value.includes(".");
|
|
4179
|
+
function filterToOptionsForFrom(fromPath, toOptions) {
|
|
4180
|
+
if (!fromPath) return toOptions;
|
|
4181
|
+
const fromHasArrayMapping = hasArrayMappingPath(fromPath);
|
|
4182
|
+
const fromIsBareArray = isBareArrayPath(fromPath);
|
|
4183
|
+
return toOptions.filter((option) => {
|
|
4184
|
+
const optionHasArrayMapping = hasArrayMappingPath(option.value);
|
|
4185
|
+
if (fromHasArrayMapping) {
|
|
4186
|
+
return optionHasArrayMapping;
|
|
4187
|
+
}
|
|
4188
|
+
if (fromIsBareArray) {
|
|
4189
|
+
return isBareArrayPath(option.value);
|
|
4190
|
+
}
|
|
4191
|
+
return !optionHasArrayMapping;
|
|
4192
|
+
});
|
|
4193
|
+
}
|
|
4593
4194
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4594
4195
|
0 && (module.exports = {
|
|
4595
4196
|
ActionBar,
|
|
4596
|
-
ComponentItem,
|
|
4597
4197
|
ComponentList,
|
|
4598
4198
|
Drawer,
|
|
4599
4199
|
DrawerItem,
|