@netlisian/softconfig 0.0.9 → 0.1.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/README.md +0 -0
- package/dist/index.css +0 -0
- package/dist/index.d.mts +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/index.mjs +0 -0
- package/dist/puck/index.css +44 -43
- package/dist/puck/index.d.mts +71 -27
- package/dist/puck/index.d.ts +71 -27
- package/dist/puck/index.js +749 -372
- package/dist/puck/index.mjs +726 -348
- package/package.json +4 -2
package/dist/puck/index.js
CHANGED
|
@@ -86,6 +86,7 @@ __export(puck_exports, {
|
|
|
86
86
|
Modal: () => Modal,
|
|
87
87
|
SoftConfigProvider: () => SoftConfigProvider,
|
|
88
88
|
confirm: () => confirm,
|
|
89
|
+
createActionCallback: () => createActionCallback,
|
|
89
90
|
createSoftConfigStore: () => createSoftConfigStore,
|
|
90
91
|
createUseSoftConfig: () => createUseSoftConfig,
|
|
91
92
|
notify: () => notify,
|
|
@@ -108,6 +109,9 @@ module.exports = __toCommonJS(puck_exports);
|
|
|
108
109
|
var import_zustand2 = require("zustand");
|
|
109
110
|
var import_middleware = require("zustand/middleware");
|
|
110
111
|
|
|
112
|
+
// src/puck/store/slices/builder.tsx
|
|
113
|
+
var import_puck4 = require("@measured/puck");
|
|
114
|
+
|
|
111
115
|
// src/puck/lib/get-root-props.ts
|
|
112
116
|
var getRootProps = (appState) => appState.data.root.props;
|
|
113
117
|
|
|
@@ -315,19 +319,23 @@ var import_react = require("react");
|
|
|
315
319
|
var import_zustand = require("zustand");
|
|
316
320
|
var appStoreContext = (0, import_react.createContext)(null);
|
|
317
321
|
var createUseSoftConfig = () => {
|
|
318
|
-
return function useSoftConfig2(selector) {
|
|
322
|
+
return function useSoftConfig2(selector, equalityFn) {
|
|
319
323
|
const context = (0, import_react.useContext)(appStoreContext);
|
|
320
324
|
if (!context) {
|
|
321
325
|
throw new Error(
|
|
322
326
|
"useSoftConfig must be used inside a SoftConfigProvider. Wrap your tree with <SoftConfigProvider value={store}>"
|
|
323
327
|
);
|
|
324
328
|
}
|
|
329
|
+
if (equalityFn) {
|
|
330
|
+
return (0, import_zustand.useStore)(context, selector, equalityFn);
|
|
331
|
+
}
|
|
325
332
|
return (0, import_zustand.useStore)(context, selector);
|
|
326
333
|
};
|
|
327
334
|
};
|
|
328
335
|
var useSoftConfig = createUseSoftConfig();
|
|
329
336
|
|
|
330
337
|
// src/puck/lib/builder/root-config.tsx
|
|
338
|
+
var import_use_debounce = require("use-debounce");
|
|
331
339
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
332
340
|
var useCustomPuck = (0, import_puck2.createUsePuck)();
|
|
333
341
|
var breakVersion = (version) => {
|
|
@@ -348,8 +356,11 @@ var updateVersion = (version, increment) => {
|
|
|
348
356
|
}
|
|
349
357
|
return `${major}.${minor}.${patch}`;
|
|
350
358
|
};
|
|
351
|
-
var builderRootConfig = (config, overrides, editingComponent) => ({
|
|
359
|
+
var builderRootConfig = (config, overrides, editingComponent, showVersionFields = true) => ({
|
|
352
360
|
fields: {
|
|
361
|
+
// _editor: {
|
|
362
|
+
// type: "slot",
|
|
363
|
+
// },
|
|
353
364
|
_name: {
|
|
354
365
|
type: "text",
|
|
355
366
|
label: "Soft Component Name"
|
|
@@ -396,7 +407,7 @@ var builderRootConfig = (config, overrides, editingComponent) => ({
|
|
|
396
407
|
)
|
|
397
408
|
};
|
|
398
409
|
else delete fields._fieldSettings;
|
|
399
|
-
if (((_b = data == null ? void 0 : data._versions) == null ? void 0 : _b.length) && (!(data == null ? void 0 : data._version) || changed._version || changed._fieldSettings)) {
|
|
410
|
+
if (showVersionFields && ((_b = data == null ? void 0 : data._versions) == null ? void 0 : _b.length) && (!(data == null ? void 0 : data._version) || changed._version || changed._fieldSettings)) {
|
|
400
411
|
const latestVersion = data._versions[data._versions.length - 1] || "1.0.0";
|
|
401
412
|
delete fields._version;
|
|
402
413
|
fields._version = {
|
|
@@ -418,6 +429,8 @@ var builderRootConfig = (config, overrides, editingComponent) => ({
|
|
|
418
429
|
}
|
|
419
430
|
]
|
|
420
431
|
};
|
|
432
|
+
} else {
|
|
433
|
+
delete fields._version;
|
|
421
434
|
}
|
|
422
435
|
return fields;
|
|
423
436
|
},
|
|
@@ -436,80 +449,78 @@ var builderRootConfig = (config, overrides, editingComponent) => ({
|
|
|
436
449
|
const getSelectorForId = useCustomPuck((s) => s.getSelectorForId);
|
|
437
450
|
const setVersion = useSoftConfig((s) => s.builder.setVersion);
|
|
438
451
|
const state = useSoftConfig((s) => s.state);
|
|
452
|
+
const [debouncedFieldSettings] = (0, import_use_debounce.useDebounce)(fieldSettings, 500);
|
|
439
453
|
(0, import_react2.useEffect)(() => {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
});
|
|
479
|
-
}
|
|
454
|
+
if (!debouncedFieldSettings || Object.keys(debouncedFieldSettings).length === 0) return;
|
|
455
|
+
(0, import_puck2.walkTree)(
|
|
456
|
+
data,
|
|
457
|
+
{
|
|
458
|
+
components: config.components
|
|
459
|
+
},
|
|
460
|
+
(content) => content.map((child) => {
|
|
461
|
+
var _a;
|
|
462
|
+
const map = ((_a = child.props) == null ? void 0 : _a._map) || [];
|
|
463
|
+
if (map.length) {
|
|
464
|
+
map.forEach(({ from, to, transform }) => {
|
|
465
|
+
if (!from || !to) return;
|
|
466
|
+
const fromPaths = Array.isArray(from) ? from : [from];
|
|
467
|
+
const toPaths = Array.isArray(to) ? to : [to];
|
|
468
|
+
const inputValues = fromPaths.map(
|
|
469
|
+
(f) => getFieldSettingsByPath(props._fieldSettings || {}, f)
|
|
470
|
+
);
|
|
471
|
+
let value = transform ? transform(
|
|
472
|
+
inputValues.map((v) => v == null ? void 0 : v.defaultValue),
|
|
473
|
+
child.props
|
|
474
|
+
) : inputValues[0];
|
|
475
|
+
if (Array.isArray(value)) {
|
|
476
|
+
value.forEach((val, i) => {
|
|
477
|
+
if (toPaths[i]) {
|
|
478
|
+
const originalValue = getFieldSettingsByPath(
|
|
479
|
+
child.props,
|
|
480
|
+
toPaths[i]
|
|
481
|
+
);
|
|
482
|
+
if (originalValue !== val) {
|
|
483
|
+
const itemSelector = getSelectorForId(child.props.id);
|
|
484
|
+
if (!itemSelector) return;
|
|
485
|
+
setPropertyByPath(child.props, toPaths[i], val);
|
|
486
|
+
dispatch({
|
|
487
|
+
type: "replace",
|
|
488
|
+
data: child,
|
|
489
|
+
destinationIndex: itemSelector == null ? void 0 : itemSelector.index,
|
|
490
|
+
destinationZone: itemSelector == null ? void 0 : itemSelector.zone
|
|
491
|
+
});
|
|
480
492
|
}
|
|
481
|
-
});
|
|
482
|
-
} else if (toPaths[0]) {
|
|
483
|
-
const setting = getFieldSettingsByPath(
|
|
484
|
-
fieldSettings,
|
|
485
|
-
fromPaths.length === 1 ? fromPaths[0] : fromPaths.join(".")
|
|
486
|
-
);
|
|
487
|
-
const defaultValue = setting == null ? void 0 : setting.defaultValue;
|
|
488
|
-
const originalValue = getFieldSettingsByPath(
|
|
489
|
-
child.props,
|
|
490
|
-
toPaths[0]
|
|
491
|
-
);
|
|
492
|
-
const finalValue = transform !== void 0 && value !== void 0 ? value : defaultValue !== void 0 ? defaultValue : value;
|
|
493
|
-
if (originalValue !== finalValue) {
|
|
494
|
-
const itemSelector = getSelectorForId(child.props.id);
|
|
495
|
-
if (!itemSelector) return;
|
|
496
|
-
setPropertyByPath(child.props, toPaths[0], finalValue);
|
|
497
|
-
dispatch({
|
|
498
|
-
type: "replace",
|
|
499
|
-
data: child,
|
|
500
|
-
destinationIndex: itemSelector == null ? void 0 : itemSelector.index,
|
|
501
|
-
destinationZone: itemSelector == null ? void 0 : itemSelector.zone
|
|
502
|
-
});
|
|
503
493
|
}
|
|
494
|
+
});
|
|
495
|
+
} else if (toPaths[0]) {
|
|
496
|
+
const setting = getFieldSettingsByPath(
|
|
497
|
+
debouncedFieldSettings,
|
|
498
|
+
fromPaths.length === 1 ? fromPaths[0] : fromPaths.join(".")
|
|
499
|
+
);
|
|
500
|
+
const defaultValue = setting == null ? void 0 : setting.defaultValue;
|
|
501
|
+
const originalValue = getFieldSettingsByPath(
|
|
502
|
+
child.props,
|
|
503
|
+
toPaths[0]
|
|
504
|
+
);
|
|
505
|
+
const finalValue = transform !== void 0 && value !== void 0 ? value : defaultValue !== void 0 ? defaultValue : value;
|
|
506
|
+
if (originalValue !== finalValue) {
|
|
507
|
+
const itemSelector = getSelectorForId(child.props.id);
|
|
508
|
+
if (!itemSelector) return;
|
|
509
|
+
setPropertyByPath(child.props, toPaths[0], finalValue);
|
|
510
|
+
dispatch({
|
|
511
|
+
type: "replace",
|
|
512
|
+
data: child,
|
|
513
|
+
destinationIndex: itemSelector == null ? void 0 : itemSelector.index,
|
|
514
|
+
destinationZone: itemSelector == null ? void 0 : itemSelector.zone
|
|
515
|
+
});
|
|
504
516
|
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
)
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}, [fieldSettings]);
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
return child;
|
|
521
|
+
})
|
|
522
|
+
);
|
|
523
|
+
}, [debouncedFieldSettings, data, dispatch, getSelectorForId, props._fieldSettings]);
|
|
513
524
|
(0, import_react2.useEffect)(() => {
|
|
514
525
|
var _a;
|
|
515
526
|
if (state !== "remodeling") return;
|
|
@@ -594,7 +605,7 @@ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (op
|
|
|
594
605
|
};
|
|
595
606
|
var get_class_name_factory_default = getClassNameFactory;
|
|
596
607
|
|
|
597
|
-
// css-module
|
|
608
|
+
// css-module:/media/osamu/3628738E28734BBD/osamuProjects/netlisian/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
|
|
598
609
|
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" };
|
|
599
610
|
|
|
600
611
|
// src/puck/components/error-boundary/index.tsx
|
|
@@ -653,153 +664,153 @@ var ErrorBoundary = class extends import_react3.Component {
|
|
|
653
664
|
|
|
654
665
|
// src/puck/lib/builder/builder-config.tsx
|
|
655
666
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
656
|
-
var builderConfig = (config, overrides, editingComponent) => ({
|
|
657
|
-
root: builderRootConfig(config, overrides, editingComponent),
|
|
667
|
+
var builderConfig = (config, overrides, editingComponent, showVersionFields = true, dependents) => ({
|
|
668
|
+
root: builderRootConfig(config, overrides, editingComponent, showVersionFields),
|
|
658
669
|
components: Object.entries(__spreadValues({}, config.components)).reduce(
|
|
659
670
|
(acc, [name, component]) => {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
)
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
label: "Enable Dropdown Slots",
|
|
674
|
-
getItemSummary(item, index) {
|
|
675
|
-
return item.slot || `Slot ${(index || 0) + 1}`;
|
|
676
|
-
},
|
|
677
|
-
arrayFields: {
|
|
678
|
-
slot: {
|
|
679
|
-
type: "select",
|
|
680
|
-
label: "Slot",
|
|
681
|
-
options: [
|
|
682
|
-
{ label: "Select a slot", value: "" },
|
|
683
|
-
...slotFields.filter(
|
|
684
|
-
([fieldName, field]) => {
|
|
685
|
-
var _a2;
|
|
686
|
-
return field.type === "slot" && !(((_a2 = data.props) == null ? void 0 : _a2._slot) || []).some(
|
|
687
|
-
(s) => s.slot === fieldName
|
|
688
|
-
);
|
|
689
|
-
}
|
|
690
|
-
).map(([fieldName, field]) => ({
|
|
691
|
-
label: field.label || fieldName,
|
|
692
|
-
value: fieldName
|
|
693
|
-
}))
|
|
694
|
-
]
|
|
695
|
-
},
|
|
696
|
-
name: {
|
|
697
|
-
type: "text",
|
|
698
|
-
label: "Name",
|
|
699
|
-
placeholder: "Optional Slot Name"
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
};
|
|
703
|
-
}
|
|
704
|
-
const defaultFields = component.resolveFields ? yield component.resolveFields(data, params) : component.fields || {};
|
|
705
|
-
if (!fields._map) {
|
|
706
|
-
const rootProps = getRootProps(params.appState);
|
|
707
|
-
const fromOptions = generateDynamicFieldOptions(
|
|
708
|
-
(rootProps == null ? void 0 : rootProps._fields) || [],
|
|
709
|
-
(rootProps == null ? void 0 : rootProps._fieldSettings) || {}
|
|
710
|
-
);
|
|
711
|
-
const toOptions = generateFieldOptions(defaultFields, []);
|
|
712
|
-
fields._map = overrides.map ? {
|
|
713
|
-
type: "custom",
|
|
714
|
-
render: ({ value, onChange, id }) => {
|
|
715
|
-
const toOptions2 = generateFieldOptions(defaultFields, []);
|
|
716
|
-
const rootProps2 = getRootProps(params.appState);
|
|
717
|
-
return overrides.map({
|
|
718
|
-
rootProps: rootProps2,
|
|
719
|
-
value,
|
|
720
|
-
onChange,
|
|
721
|
-
id,
|
|
722
|
-
props: data.props || {},
|
|
723
|
-
fromOptions,
|
|
724
|
-
toOptions: toOptions2
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
} : {
|
|
671
|
+
const tempComponent = __spreadProps(__spreadValues({}, component), {
|
|
672
|
+
permissions: {
|
|
673
|
+
insert: editingComponent !== name && !(dependents == null ? void 0 : dependents.has(name))
|
|
674
|
+
},
|
|
675
|
+
resolveFields(data, params) {
|
|
676
|
+
return __async(this, null, function* () {
|
|
677
|
+
let fields = {};
|
|
678
|
+
if (!fields._slot) {
|
|
679
|
+
const slotFields = Object.entries(params.fields).filter(
|
|
680
|
+
([_, field]) => field.type === "slot"
|
|
681
|
+
);
|
|
682
|
+
if (slotFields.length)
|
|
683
|
+
fields._slot = {
|
|
728
684
|
type: "array",
|
|
729
|
-
label: "
|
|
685
|
+
label: "Enable Dropdown Slots",
|
|
686
|
+
getItemSummary(item, index) {
|
|
687
|
+
return item.slot || `Slot ${(index || 0) + 1}`;
|
|
688
|
+
},
|
|
730
689
|
arrayFields: {
|
|
731
|
-
|
|
690
|
+
slot: {
|
|
732
691
|
type: "select",
|
|
733
|
-
label: "
|
|
692
|
+
label: "Slot",
|
|
734
693
|
options: [
|
|
735
|
-
{ label: "Select a
|
|
736
|
-
...
|
|
737
|
-
|
|
738
|
-
|
|
694
|
+
{ label: "Select a slot", value: "" },
|
|
695
|
+
...slotFields.filter(
|
|
696
|
+
([fieldName, field]) => {
|
|
697
|
+
var _a2;
|
|
698
|
+
return field.type === "slot" && !(((_a2 = data.props) == null ? void 0 : _a2._slot) || []).some(
|
|
699
|
+
(s) => s.slot === fieldName
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
).map(([fieldName, field]) => ({
|
|
703
|
+
label: field.label || fieldName,
|
|
704
|
+
value: fieldName
|
|
739
705
|
}))
|
|
740
706
|
]
|
|
741
707
|
},
|
|
742
|
-
|
|
743
|
-
type: "
|
|
744
|
-
label: "
|
|
745
|
-
|
|
746
|
-
{ label: "Select a field", value: "" },
|
|
747
|
-
...toOptions.map(({ label, value }) => ({
|
|
748
|
-
label,
|
|
749
|
-
value
|
|
750
|
-
}))
|
|
751
|
-
]
|
|
708
|
+
name: {
|
|
709
|
+
type: "text",
|
|
710
|
+
label: "Name",
|
|
711
|
+
placeholder: "Optional Slot Name"
|
|
752
712
|
}
|
|
753
713
|
}
|
|
754
714
|
};
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
715
|
+
}
|
|
716
|
+
const defaultFields = component.resolveFields ? yield component.resolveFields(data, params) : component.fields || {};
|
|
717
|
+
if (!fields._map) {
|
|
718
|
+
const rootProps = getRootProps(params.appState);
|
|
719
|
+
const fromOptions = generateDynamicFieldOptions(
|
|
720
|
+
(rootProps == null ? void 0 : rootProps._fields) || [],
|
|
721
|
+
(rootProps == null ? void 0 : rootProps._fieldSettings) || {}
|
|
722
|
+
);
|
|
723
|
+
const toOptions = generateFieldOptions(defaultFields, []);
|
|
724
|
+
fields._map = overrides.map ? {
|
|
725
|
+
type: "custom",
|
|
726
|
+
render: ({ value, onChange, id }) => {
|
|
727
|
+
const toOptions2 = generateFieldOptions(defaultFields, []);
|
|
728
|
+
const rootProps2 = getRootProps(params.appState);
|
|
729
|
+
return overrides.map({
|
|
730
|
+
rootProps: rootProps2,
|
|
731
|
+
value,
|
|
732
|
+
onChange,
|
|
733
|
+
id,
|
|
734
|
+
props: data.props || {},
|
|
735
|
+
fromOptions,
|
|
736
|
+
toOptions: toOptions2
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
} : {
|
|
740
|
+
type: "array",
|
|
741
|
+
label: "Dynamic Field Map",
|
|
742
|
+
arrayFields: {
|
|
743
|
+
from: {
|
|
744
|
+
type: "select",
|
|
745
|
+
label: "From",
|
|
746
|
+
options: [
|
|
747
|
+
{ label: "Select a field", value: "" },
|
|
748
|
+
...fromOptions.map(({ label, value }) => ({
|
|
749
|
+
label,
|
|
750
|
+
value
|
|
751
|
+
}))
|
|
752
|
+
]
|
|
753
|
+
},
|
|
754
|
+
to: {
|
|
755
|
+
type: "select",
|
|
756
|
+
label: "To",
|
|
757
|
+
options: [
|
|
758
|
+
{ label: "Select a field", value: "" },
|
|
759
|
+
...toOptions.map(({ label, value }) => ({
|
|
760
|
+
label,
|
|
761
|
+
value
|
|
762
|
+
}))
|
|
763
|
+
]
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
fields = __spreadValues(__spreadValues({}, fields), defaultFields);
|
|
769
|
+
return fields;
|
|
770
|
+
});
|
|
771
|
+
},
|
|
772
|
+
resolveData: ({ props }, { lastData }) => {
|
|
773
|
+
var _a2;
|
|
774
|
+
const _map = props._map || [];
|
|
775
|
+
const readOnlyFields = _map.flatMap((item) => item.to);
|
|
776
|
+
if (_map.length) {
|
|
777
|
+
return {
|
|
778
|
+
props,
|
|
779
|
+
readOnly: readOnlyFields.reduce(
|
|
780
|
+
(acc2, field) => __spreadProps(__spreadValues({}, acc2), { [field]: true }),
|
|
781
|
+
{}
|
|
782
|
+
)
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
const prevMap = (_a2 = lastData == null ? void 0 : lastData.props) == null ? void 0 : _a2._map;
|
|
786
|
+
if (prevMap && prevMap.length === 1) {
|
|
787
|
+
const lastField = prevMap[0].to;
|
|
788
|
+
if (typeof lastField === "string") {
|
|
765
789
|
return {
|
|
766
790
|
props,
|
|
767
|
-
readOnly:
|
|
768
|
-
|
|
791
|
+
readOnly: { [lastField]: false }
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
if (Array.isArray(lastField)) {
|
|
795
|
+
return {
|
|
796
|
+
props,
|
|
797
|
+
readOnly: lastField.reduce(
|
|
798
|
+
(acc2, field) => __spreadProps(__spreadValues({}, acc2), { [String(field)]: false }),
|
|
769
799
|
{}
|
|
770
800
|
)
|
|
771
801
|
};
|
|
772
802
|
}
|
|
773
|
-
const prevMap = (_a2 = lastData == null ? void 0 : lastData.props) == null ? void 0 : _a2._map;
|
|
774
|
-
if (prevMap && prevMap.length === 1) {
|
|
775
|
-
const lastField = prevMap[0].to;
|
|
776
|
-
if (typeof lastField === "string") {
|
|
777
|
-
return {
|
|
778
|
-
props,
|
|
779
|
-
readOnly: { [lastField]: false }
|
|
780
|
-
};
|
|
781
|
-
}
|
|
782
|
-
if (Array.isArray(lastField)) {
|
|
783
|
-
return {
|
|
784
|
-
props,
|
|
785
|
-
readOnly: lastField.reduce(
|
|
786
|
-
(acc2, field) => __spreadProps(__spreadValues({}, acc2), { [String(field)]: false }),
|
|
787
|
-
{}
|
|
788
|
-
)
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
return {
|
|
793
|
-
props,
|
|
794
|
-
readOnly: {}
|
|
795
|
-
};
|
|
796
|
-
},
|
|
797
|
-
render: (props) => {
|
|
798
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorBoundary, { children: component.render(props) });
|
|
799
803
|
}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
804
|
+
return {
|
|
805
|
+
props,
|
|
806
|
+
readOnly: {}
|
|
807
|
+
};
|
|
808
|
+
},
|
|
809
|
+
render: (props) => {
|
|
810
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorBoundary, { children: component.render(props) });
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
acc[name] = tempComponent;
|
|
803
814
|
return acc;
|
|
804
815
|
},
|
|
805
816
|
{}
|
|
@@ -929,14 +940,14 @@ var softFieldsToPuckFields = (fields, fieldSettings) => {
|
|
|
929
940
|
{}
|
|
930
941
|
)) || {};
|
|
931
942
|
};
|
|
932
|
-
var softComponentFromAppState = (appState, configComponents) => {
|
|
943
|
+
var softComponentFromAppState = (appState, configComponents, editedItem) => {
|
|
933
944
|
var _a;
|
|
934
945
|
const rootProps = ((_a = appState.data.root) == null ? void 0 : _a.props) || {};
|
|
935
946
|
const fields = rootProps._fields || [];
|
|
936
947
|
const field_settings = rootProps._fieldSettings || {};
|
|
937
948
|
const slots = {};
|
|
938
949
|
const components = getSubComponents(
|
|
939
|
-
|
|
950
|
+
[editedItem],
|
|
940
951
|
configComponents,
|
|
941
952
|
field_settings,
|
|
942
953
|
slots
|
|
@@ -1126,6 +1137,7 @@ var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
|
1126
1137
|
// src/puck/components/soft-render/index.tsx
|
|
1127
1138
|
var import_react4 = require("react");
|
|
1128
1139
|
var import_uuid2 = require("uuid");
|
|
1140
|
+
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
|
|
1129
1141
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1130
1142
|
function SoftRender({
|
|
1131
1143
|
softComponentFields,
|
|
@@ -1137,11 +1149,10 @@ function SoftRender({
|
|
|
1137
1149
|
}) {
|
|
1138
1150
|
const _a = props, { id, puck, editMode } = _a, rest = __objRest(_a, ["id", "puck", "editMode"]);
|
|
1139
1151
|
const mapCacheRef = (0, import_react4.useRef)(/* @__PURE__ */ new Map());
|
|
1140
|
-
const prevPropsRef = (0, import_react4.useRef)(
|
|
1141
|
-
|
|
1142
|
-
if (prevPropsRef.current !== propsSnapshot) {
|
|
1152
|
+
const prevPropsRef = (0, import_react4.useRef)(null);
|
|
1153
|
+
if (!(0, import_fast_deep_equal.default)(prevPropsRef.current, props)) {
|
|
1143
1154
|
mapCacheRef.current.clear();
|
|
1144
|
-
prevPropsRef.current =
|
|
1155
|
+
prevPropsRef.current = props;
|
|
1145
1156
|
}
|
|
1146
1157
|
const subComponentRootProps = (0, import_react4.useMemo)(
|
|
1147
1158
|
() => Object.entries(softComponentFields || {}).filter(([_, field]) => field.type !== "slot").reduce(
|
|
@@ -1153,10 +1164,6 @@ function SoftRender({
|
|
|
1153
1164
|
),
|
|
1154
1165
|
[softComponentFields, props]
|
|
1155
1166
|
);
|
|
1156
|
-
const valuesToUpdateKey = (0, import_react4.useMemo)(
|
|
1157
|
-
() => JSON.stringify(subComponentRootProps),
|
|
1158
|
-
[subComponentRootProps]
|
|
1159
|
-
);
|
|
1160
1167
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: (softSubComponent == null ? void 0 : softSubComponent.length) > 0 && softSubComponent.map((subComponent, index) => {
|
|
1161
1168
|
var _a2;
|
|
1162
1169
|
const componentConfig = configComponents[subComponent == null ? void 0 : subComponent.type];
|
|
@@ -1183,7 +1190,7 @@ function SoftRender({
|
|
|
1183
1190
|
}
|
|
1184
1191
|
return propValue;
|
|
1185
1192
|
});
|
|
1186
|
-
const cacheKey = JSON.stringify(
|
|
1193
|
+
const cacheKey = inputValues.map((v, i) => `${i}:${typeof v === "object" ? JSON.stringify(v) : v}`).join("|");
|
|
1187
1194
|
let result = mapCacheRef.current.get(cacheKey);
|
|
1188
1195
|
if (!result) {
|
|
1189
1196
|
const runner = transform;
|
|
@@ -1210,7 +1217,7 @@ function SoftRender({
|
|
|
1210
1217
|
const slotName = enabledSlot.name || `${(_b = subComponent.fixedProps) == null ? void 0 : _b.id}-${slotKey}`;
|
|
1211
1218
|
resolvedProps[slotKey] = (0, import_react4.useMemo)(
|
|
1212
1219
|
() => rest[slotName] || (() => null),
|
|
1213
|
-
[slotName]
|
|
1220
|
+
[slotName, rest[slotName]]
|
|
1214
1221
|
);
|
|
1215
1222
|
} else {
|
|
1216
1223
|
resolvedProps[slotKey] = (0, import_react4.useMemo)(() => {
|
|
@@ -1231,7 +1238,7 @@ function SoftRender({
|
|
|
1231
1238
|
slotKey
|
|
1232
1239
|
) });
|
|
1233
1240
|
};
|
|
1234
|
-
}, [
|
|
1241
|
+
}, [slotKey, subComponentRootProps]);
|
|
1235
1242
|
}
|
|
1236
1243
|
}
|
|
1237
1244
|
}
|
|
@@ -1250,7 +1257,7 @@ function SoftRender({
|
|
|
1250
1257
|
|
|
1251
1258
|
// src/puck/lib/create-versioned-component-config.tsx
|
|
1252
1259
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1253
|
-
var createVersionedComponentConfig = (componentName, version, allVersions, config, softComponents, defaultProps) => {
|
|
1260
|
+
var createVersionedComponentConfig = (componentName, version, allVersions, config, softComponents, defaultProps, showVersioning = true) => {
|
|
1254
1261
|
var _a, _b;
|
|
1255
1262
|
const softConfig = config;
|
|
1256
1263
|
return {
|
|
@@ -1268,16 +1275,18 @@ var createVersionedComponentConfig = (componentName, version, allVersions, confi
|
|
|
1268
1275
|
var _a2, _b2;
|
|
1269
1276
|
const selectedVersion = ((_a2 = data.props) == null ? void 0 : _a2.version) || version;
|
|
1270
1277
|
const versionedComponent = (_b2 = softComponents[componentName]) == null ? void 0 : _b2.versions[selectedVersion];
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
return __spreadValues({
|
|
1275
|
-
version: {
|
|
1278
|
+
let fields = {};
|
|
1279
|
+
if (showVersioning) {
|
|
1280
|
+
fields.version = {
|
|
1276
1281
|
label: "Version",
|
|
1277
1282
|
type: "select",
|
|
1278
1283
|
options: allVersions.map((v) => ({ label: v, value: v }))
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
Object.entries((versionedComponent == null ? void 0 : versionedComponent.fields) || {}).filter(([, field]) => field.type !== "slot").forEach(([key, field]) => {
|
|
1287
|
+
fields[key] = field;
|
|
1288
|
+
});
|
|
1289
|
+
return fields;
|
|
1281
1290
|
},
|
|
1282
1291
|
render: (props) => {
|
|
1283
1292
|
var _a2;
|
|
@@ -1414,14 +1423,29 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1414
1423
|
props: {
|
|
1415
1424
|
_name: "New Soft Component"
|
|
1416
1425
|
}
|
|
1417
|
-
}
|
|
1418
|
-
content: [
|
|
1426
|
+
}
|
|
1427
|
+
// content: [{ ...selectedItem }],
|
|
1419
1428
|
})
|
|
1420
1429
|
})
|
|
1421
1430
|
});
|
|
1422
1431
|
const config = __spreadValues({}, get().softConfig);
|
|
1423
1432
|
const overrides = get().overrides;
|
|
1424
|
-
const buildConfig = builderConfig(config, overrides);
|
|
1433
|
+
const buildConfig = builderConfig(config, overrides, selectedItem.type, get().showVersionFields);
|
|
1434
|
+
const editableIds = /* @__PURE__ */ new Set([selectedItem.props.id]);
|
|
1435
|
+
const initialContent = [__spreadValues({}, selectedItem)];
|
|
1436
|
+
(0, import_puck4.walkTree)(
|
|
1437
|
+
{
|
|
1438
|
+
root: {},
|
|
1439
|
+
content: initialContent
|
|
1440
|
+
},
|
|
1441
|
+
{ components: config.components },
|
|
1442
|
+
(components) => {
|
|
1443
|
+
components.forEach((comp) => {
|
|
1444
|
+
editableIds.add(comp.props.id);
|
|
1445
|
+
});
|
|
1446
|
+
return components;
|
|
1447
|
+
}
|
|
1448
|
+
);
|
|
1425
1449
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
1426
1450
|
softConfig: buildConfig,
|
|
1427
1451
|
storedConfig: config,
|
|
@@ -1430,6 +1454,8 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1430
1454
|
index: itemSelector.index,
|
|
1431
1455
|
zone: itemSelector.zone || rootDroppableId
|
|
1432
1456
|
},
|
|
1457
|
+
editingComponentId: selectedItem.props.id,
|
|
1458
|
+
editableComponentIds: editableIds,
|
|
1433
1459
|
state: "building"
|
|
1434
1460
|
}));
|
|
1435
1461
|
setTimeout(
|
|
@@ -1476,16 +1502,48 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1476
1502
|
selectedItem.props,
|
|
1477
1503
|
get().softConfig.components
|
|
1478
1504
|
);
|
|
1505
|
+
const config = __spreadValues({}, get().softConfig);
|
|
1506
|
+
const overrides = get().overrides;
|
|
1507
|
+
const getStore = () => get();
|
|
1508
|
+
const getEditableIds = () => getStore().editableComponentIds;
|
|
1509
|
+
const dependents = get().dependencyGraph.get(softComponentName) || /* @__PURE__ */ new Set();
|
|
1510
|
+
const buildConfig = builderConfig(config, overrides, softComponentName, get().showVersionFields, dependents);
|
|
1511
|
+
const editableIds = /* @__PURE__ */ new Set([]);
|
|
1512
|
+
const decomposedComponents = get().builder.decompose(selectedItem);
|
|
1513
|
+
(0, import_puck4.walkTree)(
|
|
1514
|
+
{ root: {}, content: decomposedComponents || [] },
|
|
1515
|
+
{ components: config.components },
|
|
1516
|
+
(components) => {
|
|
1517
|
+
components.forEach((comp) => {
|
|
1518
|
+
editableIds.add(comp.props.id);
|
|
1519
|
+
});
|
|
1520
|
+
return components;
|
|
1521
|
+
}
|
|
1522
|
+
);
|
|
1479
1523
|
puckDispatch({
|
|
1480
1524
|
type: "setData",
|
|
1481
|
-
data: (
|
|
1525
|
+
data: (prevData) => ({
|
|
1482
1526
|
root: __spreadProps(__spreadValues({}, root), { _versions: versions }),
|
|
1483
|
-
content:
|
|
1527
|
+
content: (0, import_puck4.walkTree)(__spreadValues({}, prevData), __spreadValues({}, config), (components) => {
|
|
1528
|
+
const next = components.map((component) => __spreadProps(__spreadValues({}, component), {
|
|
1529
|
+
props: __spreadValues({}, component.props)
|
|
1530
|
+
}));
|
|
1531
|
+
const index = next.findIndex(
|
|
1532
|
+
(component) => component.props.id === selectedItem.props.id
|
|
1533
|
+
);
|
|
1534
|
+
if (index !== -1) {
|
|
1535
|
+
next.splice(
|
|
1536
|
+
index,
|
|
1537
|
+
1,
|
|
1538
|
+
...decomposedComponents.map((component) => __spreadProps(__spreadValues({}, component), {
|
|
1539
|
+
props: __spreadValues({}, component.props)
|
|
1540
|
+
}))
|
|
1541
|
+
);
|
|
1542
|
+
}
|
|
1543
|
+
return next;
|
|
1544
|
+
}).content
|
|
1484
1545
|
})
|
|
1485
1546
|
});
|
|
1486
|
-
const config = __spreadValues({}, get().softConfig);
|
|
1487
|
-
const overrides = get().overrides;
|
|
1488
|
-
const buildConfig = builderConfig(config, overrides, softComponentName);
|
|
1489
1547
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
1490
1548
|
storedConfig: config,
|
|
1491
1549
|
softConfig: buildConfig,
|
|
@@ -1494,20 +1552,22 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1494
1552
|
index: itemSelector.index,
|
|
1495
1553
|
zone: itemSelector.zone || rootDroppableId
|
|
1496
1554
|
},
|
|
1555
|
+
editingComponentId: selectedItem.props.id,
|
|
1556
|
+
editableComponentIds: editableIds,
|
|
1497
1557
|
state: "remodeling"
|
|
1498
1558
|
}));
|
|
1499
1559
|
setTimeout(
|
|
1500
1560
|
() => puckDispatch({
|
|
1501
1561
|
type: "replaceRoot",
|
|
1502
1562
|
root: {
|
|
1503
|
-
title:
|
|
1504
|
-
_name:
|
|
1563
|
+
title: root.props.title,
|
|
1564
|
+
_name: root.props.name
|
|
1505
1565
|
}
|
|
1506
1566
|
}),
|
|
1507
1567
|
100
|
|
1508
1568
|
);
|
|
1509
1569
|
},
|
|
1510
|
-
complete: (appState, setHistories) => {
|
|
1570
|
+
complete: (appState, setHistories, getItemBySelector) => {
|
|
1511
1571
|
var _a, _b;
|
|
1512
1572
|
if (get().state === "ready") {
|
|
1513
1573
|
throw new Error("Not building or remodeling a component.");
|
|
@@ -1516,7 +1576,17 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1516
1576
|
if (!componentName) {
|
|
1517
1577
|
throw new Error("Root component must have a name to compose.");
|
|
1518
1578
|
}
|
|
1519
|
-
const
|
|
1579
|
+
const itemSelector = get().itemSelector;
|
|
1580
|
+
if (!itemSelector) {
|
|
1581
|
+
throw new Error("No item selector found for completed component.");
|
|
1582
|
+
}
|
|
1583
|
+
const selectedItem = getItemBySelector(
|
|
1584
|
+
itemSelector
|
|
1585
|
+
);
|
|
1586
|
+
if (!selectedItem) {
|
|
1587
|
+
throw new Error("Cannot find item being edited");
|
|
1588
|
+
}
|
|
1589
|
+
const [newSoftComponentConfig, version] = get().builder.compose(appState, componentName, selectedItem) || [];
|
|
1520
1590
|
if (!newSoftComponentConfig) {
|
|
1521
1591
|
throw new Error("Failed to compose new soft component config.");
|
|
1522
1592
|
}
|
|
@@ -1548,8 +1618,11 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1548
1618
|
}),
|
|
1549
1619
|
storedConfig: void 0,
|
|
1550
1620
|
state: "inspecting",
|
|
1551
|
-
originalHistory: []
|
|
1621
|
+
originalHistory: [],
|
|
1622
|
+
editingComponentId: null,
|
|
1623
|
+
editableComponentIds: /* @__PURE__ */ new Set()
|
|
1552
1624
|
}));
|
|
1625
|
+
get().rebuildDependents(componentName, version);
|
|
1553
1626
|
return componentName;
|
|
1554
1627
|
},
|
|
1555
1628
|
inspect: (componentName, puckDispatch) => {
|
|
@@ -1576,7 +1649,9 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1576
1649
|
set((s) => __spreadProps(__spreadValues({}, s), {
|
|
1577
1650
|
state: "ready",
|
|
1578
1651
|
setItemSelector: void 0,
|
|
1579
|
-
setOriginalItem: void 0
|
|
1652
|
+
setOriginalItem: void 0,
|
|
1653
|
+
editingComponentId: null,
|
|
1654
|
+
editableComponentIds: /* @__PURE__ */ new Set()
|
|
1580
1655
|
}));
|
|
1581
1656
|
},
|
|
1582
1657
|
cancel: (setHistories) => {
|
|
@@ -1588,10 +1663,12 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1588
1663
|
originalHistory: [],
|
|
1589
1664
|
itemSelector: null,
|
|
1590
1665
|
originalItem: null,
|
|
1591
|
-
state: "ready"
|
|
1666
|
+
state: "ready",
|
|
1667
|
+
editingComponentId: null,
|
|
1668
|
+
editableComponentIds: /* @__PURE__ */ new Set()
|
|
1592
1669
|
}));
|
|
1593
1670
|
},
|
|
1594
|
-
compose: (appState, componentName) => {
|
|
1671
|
+
compose: (appState, componentName, editedItem) => {
|
|
1595
1672
|
if (!componentName) {
|
|
1596
1673
|
throw new Error("Root component must have a name to compose.");
|
|
1597
1674
|
}
|
|
@@ -1601,7 +1678,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1601
1678
|
`Component name "${componentName}" already exists in the configuration.`
|
|
1602
1679
|
);
|
|
1603
1680
|
}
|
|
1604
|
-
const [softComponent, version] = softComponentFromAppState(appState, componentConfigs);
|
|
1681
|
+
const [softComponent, version] = softComponentFromAppState(appState, componentConfigs, editedItem);
|
|
1605
1682
|
const existingComponent = get().softComponents[componentName];
|
|
1606
1683
|
const allVersions = Object.keys((existingComponent == null ? void 0 : existingComponent.versions) || {});
|
|
1607
1684
|
const isNewVersion = !allVersions.includes(version);
|
|
@@ -1617,7 +1694,8 @@ var createBuildersSlice = (set, get, initialConfig) => ({
|
|
|
1617
1694
|
})
|
|
1618
1695
|
})
|
|
1619
1696
|
}),
|
|
1620
|
-
softComponent.defaultProps
|
|
1697
|
+
softComponent.defaultProps,
|
|
1698
|
+
get().showVersionFields
|
|
1621
1699
|
);
|
|
1622
1700
|
get().setSoftComponent(componentName, version, softComponent);
|
|
1623
1701
|
return [newSoftComponentConfig, version];
|
|
@@ -1749,6 +1827,27 @@ function extractDependencies(softComponents, componentName, version) {
|
|
|
1749
1827
|
processSubComponents(component.components);
|
|
1750
1828
|
return dependencies;
|
|
1751
1829
|
}
|
|
1830
|
+
function buildReverseDependencyGraph(softComponents) {
|
|
1831
|
+
const reverseDeps = /* @__PURE__ */ new Map();
|
|
1832
|
+
for (const [componentName, component] of Object.entries(softComponents)) {
|
|
1833
|
+
const defaultVersion = component.defaultVersion || Object.keys(component.versions || {}).pop();
|
|
1834
|
+
if (!defaultVersion) continue;
|
|
1835
|
+
Object.entries(component.versions || {}).forEach(([version, versionedComp]) => {
|
|
1836
|
+
const dependencies = extractDependencies(softComponents, componentName, version);
|
|
1837
|
+
if (!component.dependencies) {
|
|
1838
|
+
component.dependencies = {};
|
|
1839
|
+
}
|
|
1840
|
+
component.dependencies[version] = dependencies;
|
|
1841
|
+
for (const dep of dependencies) {
|
|
1842
|
+
if (!reverseDeps.has(dep)) {
|
|
1843
|
+
reverseDeps.set(dep, /* @__PURE__ */ new Set());
|
|
1844
|
+
}
|
|
1845
|
+
reverseDeps.get(dep).add(componentName);
|
|
1846
|
+
}
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
return reverseDeps;
|
|
1850
|
+
}
|
|
1752
1851
|
function topologicalSort(softComponents, hardComponentNames) {
|
|
1753
1852
|
const sorted = [];
|
|
1754
1853
|
const visiting = /* @__PURE__ */ new Set();
|
|
@@ -1792,7 +1891,7 @@ function topologicalSort(softComponents, hardComponentNames) {
|
|
|
1792
1891
|
}
|
|
1793
1892
|
return sorted;
|
|
1794
1893
|
}
|
|
1795
|
-
function buildInitialSoftComponents(hardConfig, softComponents, overrides) {
|
|
1894
|
+
function buildInitialSoftComponents(hardConfig, softComponents, overrides, showVersioning = false) {
|
|
1796
1895
|
var _a, _b;
|
|
1797
1896
|
if (!softComponents || Object.keys(softComponents).length === 0) {
|
|
1798
1897
|
return {};
|
|
@@ -1826,7 +1925,8 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides) {
|
|
|
1826
1925
|
buildingConfig,
|
|
1827
1926
|
// Pass the accumulating config
|
|
1828
1927
|
hydratedSoftComponents,
|
|
1829
|
-
versionedComponent.defaultProps
|
|
1928
|
+
versionedComponent.defaultProps,
|
|
1929
|
+
showVersioning
|
|
1830
1930
|
);
|
|
1831
1931
|
componentConfigs[name] = newSoftComponentConfig;
|
|
1832
1932
|
buildingConfig.components[name] = newSoftComponentConfig;
|
|
@@ -1852,7 +1952,8 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides) {
|
|
|
1852
1952
|
allVersions,
|
|
1853
1953
|
hardConfig,
|
|
1854
1954
|
hydratedSoftComponents,
|
|
1855
|
-
versionedComponent.defaultProps
|
|
1955
|
+
versionedComponent.defaultProps,
|
|
1956
|
+
showVersioning
|
|
1856
1957
|
);
|
|
1857
1958
|
componentConfigs[name] = newSoftComponentConfig;
|
|
1858
1959
|
}
|
|
@@ -1860,21 +1961,106 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides) {
|
|
|
1860
1961
|
}
|
|
1861
1962
|
}
|
|
1862
1963
|
|
|
1964
|
+
// src/puck/lib/edit-visibility-utils.ts
|
|
1965
|
+
var setEditVisibility = (doc, context) => {
|
|
1966
|
+
if (!doc) return;
|
|
1967
|
+
try {
|
|
1968
|
+
const root = doc.documentElement;
|
|
1969
|
+
if (context.mode === "none") {
|
|
1970
|
+
root.removeAttribute("data-edit-mode");
|
|
1971
|
+
root.classList.remove("edit-visibility-mode");
|
|
1972
|
+
doc.querySelectorAll("[data-puck-component]").forEach((el) => {
|
|
1973
|
+
el.removeAttribute("data-edit-visibility");
|
|
1974
|
+
el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
|
|
1975
|
+
});
|
|
1976
|
+
} else {
|
|
1977
|
+
root.setAttribute("data-edit-mode", context.mode);
|
|
1978
|
+
root.classList.add("edit-visibility-mode");
|
|
1979
|
+
doc.querySelectorAll("[data-puck-component]").forEach((el) => {
|
|
1980
|
+
var _a;
|
|
1981
|
+
const id = el.getAttribute("data-puck-component");
|
|
1982
|
+
if (!id) return;
|
|
1983
|
+
const isEditable = context.editableIds.has(id);
|
|
1984
|
+
const isDependency = (_a = context.highlightDependencyIds) == null ? void 0 : _a.has(id);
|
|
1985
|
+
if (isEditable) {
|
|
1986
|
+
el.setAttribute("data-edit-visibility", "editable");
|
|
1987
|
+
el.classList.remove("edit-visibility-greyed", "edit-visibility-dependency");
|
|
1988
|
+
el.classList.add("edit-visibility-editable");
|
|
1989
|
+
} else if (isDependency) {
|
|
1990
|
+
el.setAttribute("data-edit-visibility", "dependency");
|
|
1991
|
+
el.classList.remove("edit-visibility-greyed", "edit-visibility-editable");
|
|
1992
|
+
el.classList.add("edit-visibility-dependency");
|
|
1993
|
+
} else {
|
|
1994
|
+
el.setAttribute("data-edit-visibility", "greyed");
|
|
1995
|
+
el.classList.remove("edit-visibility-editable", "edit-visibility-dependency");
|
|
1996
|
+
el.classList.add("edit-visibility-greyed");
|
|
1997
|
+
}
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
} catch (error) {
|
|
2001
|
+
console.warn(`Failed to set edit visibility:`, error);
|
|
2002
|
+
}
|
|
2003
|
+
};
|
|
2004
|
+
var clearEditVisibility = (doc) => {
|
|
2005
|
+
if (!doc) return;
|
|
2006
|
+
try {
|
|
2007
|
+
const root = doc.documentElement;
|
|
2008
|
+
root.removeAttribute("data-edit-mode");
|
|
2009
|
+
root.classList.remove("edit-visibility-mode");
|
|
2010
|
+
doc.querySelectorAll("[data-puck-component]").forEach((el) => {
|
|
2011
|
+
el.removeAttribute("data-edit-visibility");
|
|
2012
|
+
el.classList.remove("edit-visibility-greyed", "edit-visibility-editable", "edit-visibility-dependency");
|
|
2013
|
+
});
|
|
2014
|
+
} catch (error) {
|
|
2015
|
+
console.warn(`Failed to clear edit visibility:`, error);
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
|
|
1863
2019
|
// src/puck/store/index.tsx
|
|
1864
2020
|
var createSoftConfigStore = (hardConfig = {
|
|
1865
2021
|
components: {}
|
|
1866
|
-
}, softComponents = {}, overrides = {}, onActions) => {
|
|
2022
|
+
}, softComponents = {}, overrides = {}, onActions, showVersionFields = true) => {
|
|
2023
|
+
const iframeDocRef = { current: null };
|
|
1867
2024
|
const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(
|
|
1868
2025
|
softComponents,
|
|
1869
2026
|
overrides.hydrateMapTransform
|
|
1870
2027
|
) : softComponents;
|
|
2028
|
+
const initialDependencyGraph = buildReverseDependencyGraph(
|
|
2029
|
+
hydratedSoftComponents
|
|
2030
|
+
);
|
|
1871
2031
|
return (0, import_zustand2.create)()(
|
|
1872
2032
|
(0, import_middleware.subscribeWithSelector)(
|
|
1873
|
-
(
|
|
2033
|
+
(set, get) => ({
|
|
1874
2034
|
state: "ready",
|
|
1875
2035
|
originalHistory: [],
|
|
1876
2036
|
overrides,
|
|
1877
2037
|
onActions,
|
|
2038
|
+
iframeDocRef,
|
|
2039
|
+
showVersionFields,
|
|
2040
|
+
setShowVersionFields: (show) => set({ showVersionFields: show }),
|
|
2041
|
+
getIframeDoc: () => iframeDocRef.current,
|
|
2042
|
+
setIframeDoc: (doc) => {
|
|
2043
|
+
iframeDocRef.current = doc;
|
|
2044
|
+
if (!doc) {
|
|
2045
|
+
return;
|
|
2046
|
+
}
|
|
2047
|
+
const { state, editableComponentIds } = get();
|
|
2048
|
+
if (state === "building") {
|
|
2049
|
+
setEditVisibility(doc, {
|
|
2050
|
+
mode: "build",
|
|
2051
|
+
editableIds: editableComponentIds
|
|
2052
|
+
});
|
|
2053
|
+
return;
|
|
2054
|
+
}
|
|
2055
|
+
if (state === "remodeling") {
|
|
2056
|
+
setEditVisibility(doc, {
|
|
2057
|
+
mode: "remodel",
|
|
2058
|
+
editableIds: editableComponentIds
|
|
2059
|
+
});
|
|
2060
|
+
return;
|
|
2061
|
+
}
|
|
2062
|
+
clearEditVisibility(doc);
|
|
2063
|
+
},
|
|
1878
2064
|
storeHistory: (history) => set({ originalHistory: history }),
|
|
1879
2065
|
removeHistory: () => set({ originalHistory: [] }),
|
|
1880
2066
|
itemSelector: null,
|
|
@@ -1883,6 +2069,7 @@ var createSoftConfigStore = (hardConfig = {
|
|
|
1883
2069
|
setOriginalItem: (item) => set({ originalItem: item }),
|
|
1884
2070
|
hydratedSoftComponents,
|
|
1885
2071
|
softComponents: hydratedSoftComponents,
|
|
2072
|
+
dependencyGraph: initialDependencyGraph,
|
|
1886
2073
|
softConfig: __spreadProps(__spreadValues({}, hardConfig), {
|
|
1887
2074
|
components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
|
|
1888
2075
|
hardConfig,
|
|
@@ -1905,6 +2092,67 @@ var createSoftConfigStore = (hardConfig = {
|
|
|
1905
2092
|
};
|
|
1906
2093
|
});
|
|
1907
2094
|
},
|
|
2095
|
+
setSoftComponents: (incomingComponents) => {
|
|
2096
|
+
const state = get();
|
|
2097
|
+
const nextSoftComponents = __spreadValues({}, state.softComponents);
|
|
2098
|
+
const nextConfigComponents = __spreadValues({}, state.softConfig.components);
|
|
2099
|
+
Object.entries(incomingComponents).forEach(([name, data]) => {
|
|
2100
|
+
const existing = nextSoftComponents[name];
|
|
2101
|
+
const finalComponentData = existing ? __spreadProps(__spreadValues(__spreadValues({}, existing), data), {
|
|
2102
|
+
versions: __spreadValues(__spreadValues({}, existing.versions), data.versions)
|
|
2103
|
+
}) : data;
|
|
2104
|
+
nextSoftComponents[name] = finalComponentData;
|
|
2105
|
+
const activeVersion = finalComponentData.defaultVersion;
|
|
2106
|
+
const activeVersionData = finalComponentData.versions[activeVersion];
|
|
2107
|
+
if (activeVersionData) {
|
|
2108
|
+
nextConfigComponents[name] = createVersionedComponentConfig(
|
|
2109
|
+
name,
|
|
2110
|
+
activeVersion,
|
|
2111
|
+
Object.keys(finalComponentData.versions),
|
|
2112
|
+
state.softConfig,
|
|
2113
|
+
nextSoftComponents,
|
|
2114
|
+
activeVersionData.defaultProps,
|
|
2115
|
+
state.showVersionFields
|
|
2116
|
+
);
|
|
2117
|
+
}
|
|
2118
|
+
});
|
|
2119
|
+
set({
|
|
2120
|
+
softComponents: nextSoftComponents,
|
|
2121
|
+
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
2122
|
+
components: nextConfigComponents
|
|
2123
|
+
})
|
|
2124
|
+
});
|
|
2125
|
+
},
|
|
2126
|
+
hydrateTransforms: () => {
|
|
2127
|
+
const { overrides: overrides2, softComponents: softComponents2, softConfig } = get();
|
|
2128
|
+
if (!(overrides2 == null ? void 0 : overrides2.hydrateMapTransform)) return;
|
|
2129
|
+
const hydratedComponents = hydrateSoftComponentsTransforms(
|
|
2130
|
+
softComponents2,
|
|
2131
|
+
overrides2.hydrateMapTransform
|
|
2132
|
+
);
|
|
2133
|
+
const nextConfigComponents = __spreadValues({}, softConfig.components);
|
|
2134
|
+
Object.entries(hydratedComponents).forEach(([name, componentData]) => {
|
|
2135
|
+
const activeVersion = componentData.defaultVersion;
|
|
2136
|
+
const activeVersionData = componentData.versions[activeVersion];
|
|
2137
|
+
if (activeVersionData) {
|
|
2138
|
+
nextConfigComponents[name] = createVersionedComponentConfig(
|
|
2139
|
+
name,
|
|
2140
|
+
activeVersion,
|
|
2141
|
+
Object.keys(componentData.versions),
|
|
2142
|
+
softConfig,
|
|
2143
|
+
hydratedComponents,
|
|
2144
|
+
activeVersionData.defaultProps,
|
|
2145
|
+
get().showVersionFields
|
|
2146
|
+
);
|
|
2147
|
+
}
|
|
2148
|
+
});
|
|
2149
|
+
set({
|
|
2150
|
+
softComponents: hydratedComponents,
|
|
2151
|
+
softConfig: __spreadProps(__spreadValues({}, softConfig), {
|
|
2152
|
+
components: nextConfigComponents
|
|
2153
|
+
})
|
|
2154
|
+
});
|
|
2155
|
+
},
|
|
1908
2156
|
setSoftComponentDefaultVersion: (name, version) => {
|
|
1909
2157
|
var _a, _b, _c;
|
|
1910
2158
|
const softComponent = (_b = (_a = get().softComponents[name]) == null ? void 0 : _a.versions) == null ? void 0 : _b[version];
|
|
@@ -1922,7 +2170,8 @@ var createSoftConfigStore = (hardConfig = {
|
|
|
1922
2170
|
allVersions,
|
|
1923
2171
|
get().softConfig,
|
|
1924
2172
|
get().softComponents,
|
|
1925
|
-
softComponent.defaultProps
|
|
2173
|
+
softComponent.defaultProps,
|
|
2174
|
+
get().showVersionFields
|
|
1926
2175
|
);
|
|
1927
2176
|
set((state) => ({
|
|
1928
2177
|
softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
|
|
@@ -2022,8 +2271,49 @@ var createSoftConfigStore = (hardConfig = {
|
|
|
2022
2271
|
})
|
|
2023
2272
|
}));
|
|
2024
2273
|
},
|
|
2025
|
-
builder: createBuildersSlice(set, get, hardConfig)
|
|
2026
|
-
|
|
2274
|
+
builder: createBuildersSlice(set, get, hardConfig),
|
|
2275
|
+
editingComponentId: null,
|
|
2276
|
+
editableComponentIds: /* @__PURE__ */ new Set(),
|
|
2277
|
+
setEditableComponentIds: (ids) => set({ editableComponentIds: ids }),
|
|
2278
|
+
addEditableComponentId: (id) => {
|
|
2279
|
+
set((state) => {
|
|
2280
|
+
const newIds = new Set(state.editableComponentIds);
|
|
2281
|
+
newIds.add(id);
|
|
2282
|
+
return { editableComponentIds: newIds };
|
|
2283
|
+
});
|
|
2284
|
+
},
|
|
2285
|
+
clearEditingState: () => set({
|
|
2286
|
+
editingComponentId: null,
|
|
2287
|
+
editableComponentIds: /* @__PURE__ */ new Set()
|
|
2288
|
+
}),
|
|
2289
|
+
rebuildDependents: (componentName, version) => {
|
|
2290
|
+
const state = get();
|
|
2291
|
+
const dependents = state.dependencyGraph.get(componentName) || /* @__PURE__ */ new Set();
|
|
2292
|
+
if (dependents.size === 0) return;
|
|
2293
|
+
const config = __spreadValues({}, state.softConfig);
|
|
2294
|
+
const softComponents2 = state.softComponents;
|
|
2295
|
+
const toBuild = Array.from(dependents);
|
|
2296
|
+
for (const dependentName of toBuild) {
|
|
2297
|
+
const dependent = softComponents2[dependentName];
|
|
2298
|
+
const defaultVersion = dependent.defaultVersion || Object.keys(dependent.versions || {}).pop();
|
|
2299
|
+
if (!defaultVersion) continue;
|
|
2300
|
+
const versionedComponent = dependent.versions[defaultVersion];
|
|
2301
|
+
const allVersions = Object.keys(dependent.versions || {});
|
|
2302
|
+
if (!versionedComponent) continue;
|
|
2303
|
+
const newConfig = createVersionedComponentConfig(
|
|
2304
|
+
dependentName,
|
|
2305
|
+
defaultVersion,
|
|
2306
|
+
allVersions,
|
|
2307
|
+
config,
|
|
2308
|
+
softComponents2,
|
|
2309
|
+
versionedComponent.defaultProps,
|
|
2310
|
+
state.showVersionFields
|
|
2311
|
+
);
|
|
2312
|
+
config.components[dependentName] = newConfig;
|
|
2313
|
+
}
|
|
2314
|
+
set((s) => __spreadProps(__spreadValues({}, s), { softConfig: config }));
|
|
2315
|
+
}
|
|
2316
|
+
})
|
|
2027
2317
|
)
|
|
2028
2318
|
);
|
|
2029
2319
|
};
|
|
@@ -2037,11 +2327,12 @@ var SoftConfigProvider = ({
|
|
|
2037
2327
|
softComponents,
|
|
2038
2328
|
overrides,
|
|
2039
2329
|
value,
|
|
2040
|
-
onActions
|
|
2330
|
+
onActions,
|
|
2331
|
+
useVersioning = false
|
|
2041
2332
|
}) => {
|
|
2042
2333
|
const store = value != null ? value : (0, import_react5.useMemo)(
|
|
2043
|
-
() => createSoftConfigStore(hardConfig, softComponents, overrides, onActions),
|
|
2044
|
-
[hardConfig, softComponents, overrides, onActions]
|
|
2334
|
+
() => createSoftConfigStore(hardConfig, softComponents, overrides, onActions, useVersioning),
|
|
2335
|
+
[hardConfig, softComponents, overrides, onActions, useVersioning]
|
|
2045
2336
|
);
|
|
2046
2337
|
const [softConfig, setSoftConfig] = (0, import_react5.useState)(
|
|
2047
2338
|
() => store.getState().softConfig
|
|
@@ -2049,6 +2340,53 @@ var SoftConfigProvider = ({
|
|
|
2049
2340
|
const [internalSoftComponents, setSoftComponents] = (0, import_react5.useState)(
|
|
2050
2341
|
() => store.getState().softComponents
|
|
2051
2342
|
);
|
|
2343
|
+
const storeSetIframeDoc = (0, import_react5.useMemo)(
|
|
2344
|
+
() => store.getState().setIframeDoc,
|
|
2345
|
+
[store]
|
|
2346
|
+
);
|
|
2347
|
+
const validateAction = (0, import_react5.useMemo)(
|
|
2348
|
+
() => (action) => {
|
|
2349
|
+
const currentState = store.getState();
|
|
2350
|
+
if (currentState.state === "ready") {
|
|
2351
|
+
return true;
|
|
2352
|
+
}
|
|
2353
|
+
const editableIds = currentState.editableComponentIds;
|
|
2354
|
+
if (action.type === "replace") {
|
|
2355
|
+
if (action.data.props.id && editableIds.has(action.data.props.id)) {
|
|
2356
|
+
return true;
|
|
2357
|
+
}
|
|
2358
|
+
return false;
|
|
2359
|
+
}
|
|
2360
|
+
if (action.type === "insert" || action.type === "duplicate") {
|
|
2361
|
+
const zone = action.type === "insert" ? action.destinationZone : action.sourceZone;
|
|
2362
|
+
const parentId = zone == null ? void 0 : zone.split(":")[0];
|
|
2363
|
+
if (parentId && !editableIds.has(parentId)) {
|
|
2364
|
+
return false;
|
|
2365
|
+
}
|
|
2366
|
+
if (action.type === "insert") {
|
|
2367
|
+
const childId = action.id;
|
|
2368
|
+
if (childId) {
|
|
2369
|
+
currentState.addEditableComponentId(childId);
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
return true;
|
|
2373
|
+
}
|
|
2374
|
+
if (action.type === "remove" || action.type === "move" || action.type === "reorder") {
|
|
2375
|
+
let parentId;
|
|
2376
|
+
if (action.type === "remove") {
|
|
2377
|
+
parentId = action.zone.split(":")[0];
|
|
2378
|
+
} else if (action.type === "move" || action.type === "reorder") {
|
|
2379
|
+
parentId = action.destinationZone.split(":")[0];
|
|
2380
|
+
}
|
|
2381
|
+
if (parentId && !editableIds.has(parentId)) {
|
|
2382
|
+
return false;
|
|
2383
|
+
}
|
|
2384
|
+
return true;
|
|
2385
|
+
}
|
|
2386
|
+
return true;
|
|
2387
|
+
},
|
|
2388
|
+
[store]
|
|
2389
|
+
);
|
|
2052
2390
|
(0, import_react5.useEffect)(() => {
|
|
2053
2391
|
const unsubscribe = store.subscribe(() => {
|
|
2054
2392
|
setSoftConfig(store.getState().softConfig);
|
|
@@ -2058,11 +2396,32 @@ var SoftConfigProvider = ({
|
|
|
2058
2396
|
unsubscribe();
|
|
2059
2397
|
};
|
|
2060
2398
|
}, [store]);
|
|
2061
|
-
|
|
2399
|
+
(0, import_react5.useEffect)(() => {
|
|
2400
|
+
const unsubscribe = store.subscribe((state, prevState) => {
|
|
2401
|
+
if (prevState && state.state === prevState.state && state.editableComponentIds === prevState.editableComponentIds) {
|
|
2402
|
+
return;
|
|
2403
|
+
}
|
|
2404
|
+
const doc = store.getState().getIframeDoc();
|
|
2405
|
+
if (!doc) return;
|
|
2406
|
+
if (state.state === "building") {
|
|
2407
|
+
setEditVisibility(doc, { mode: "build", editableIds: state.editableComponentIds });
|
|
2408
|
+
return;
|
|
2409
|
+
}
|
|
2410
|
+
if (state.state === "remodeling") {
|
|
2411
|
+
setEditVisibility(doc, { mode: "remodel", editableIds: state.editableComponentIds });
|
|
2412
|
+
return;
|
|
2413
|
+
}
|
|
2414
|
+
clearEditVisibility(doc);
|
|
2415
|
+
});
|
|
2416
|
+
return () => {
|
|
2417
|
+
unsubscribe();
|
|
2418
|
+
};
|
|
2419
|
+
}, [store]);
|
|
2420
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(appStoreContext.Provider, { value: store, children: children(softConfig, internalSoftComponents, storeSetIframeDoc, validateAction) });
|
|
2062
2421
|
};
|
|
2063
2422
|
|
|
2064
2423
|
// src/puck/actions/useBuild.tsx
|
|
2065
|
-
var
|
|
2424
|
+
var import_puck5 = require("@measured/puck");
|
|
2066
2425
|
|
|
2067
2426
|
// src/puck/lib/notify.ts
|
|
2068
2427
|
var customHandler = null;
|
|
@@ -2107,7 +2466,7 @@ var useActionEvent = () => {
|
|
|
2107
2466
|
};
|
|
2108
2467
|
|
|
2109
2468
|
// src/puck/actions/useBuild.tsx
|
|
2110
|
-
var useCustomPuck2 = (0,
|
|
2469
|
+
var useCustomPuck2 = (0, import_puck5.createUsePuck)();
|
|
2111
2470
|
var useBuild = () => {
|
|
2112
2471
|
const build = useSoftConfig((s) => s.builder.build);
|
|
2113
2472
|
const history = useCustomPuck2((s) => s.history.histories);
|
|
@@ -2124,7 +2483,7 @@ var useBuild = () => {
|
|
|
2124
2483
|
try {
|
|
2125
2484
|
build(history, selectedItem, itemSelector, dispatch);
|
|
2126
2485
|
if (selectedItem == null ? void 0 : selectedItem.type) {
|
|
2127
|
-
triggerAction({
|
|
2486
|
+
void triggerAction({
|
|
2128
2487
|
type: "build",
|
|
2129
2488
|
payload: {
|
|
2130
2489
|
id: selectedItem.type
|
|
@@ -2142,8 +2501,8 @@ var useBuild = () => {
|
|
|
2142
2501
|
};
|
|
2143
2502
|
|
|
2144
2503
|
// src/puck/actions/useRemodel.tsx
|
|
2145
|
-
var
|
|
2146
|
-
var useCustomPuck3 = (0,
|
|
2504
|
+
var import_puck6 = require("@measured/puck");
|
|
2505
|
+
var useCustomPuck3 = (0, import_puck6.createUsePuck)();
|
|
2147
2506
|
var useRemodel = () => {
|
|
2148
2507
|
const remodel = useSoftConfig((s) => s.builder.remodel);
|
|
2149
2508
|
const history = useCustomPuck3((s) => s.history.histories);
|
|
@@ -2152,6 +2511,7 @@ var useRemodel = () => {
|
|
|
2152
2511
|
const dispatch = useCustomPuck3((s) => s.dispatch);
|
|
2153
2512
|
const status = useSoftConfig((s) => s.state);
|
|
2154
2513
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2514
|
+
const refreshPermissions = useCustomPuck3((s) => s.refreshPermissions);
|
|
2155
2515
|
const { triggerAction } = useActionEvent();
|
|
2156
2516
|
const handleRemodel = (componentName) => {
|
|
2157
2517
|
if (status !== "ready") {
|
|
@@ -2164,8 +2524,8 @@ var useRemodel = () => {
|
|
|
2164
2524
|
return;
|
|
2165
2525
|
}
|
|
2166
2526
|
try {
|
|
2167
|
-
remodel(history, selectedItem, itemSelector, dispatch);
|
|
2168
|
-
triggerAction({
|
|
2527
|
+
remodel(history, selectedItem, itemSelector, dispatch, refreshPermissions);
|
|
2528
|
+
void triggerAction({
|
|
2169
2529
|
type: "remodel",
|
|
2170
2530
|
payload: {
|
|
2171
2531
|
id: name
|
|
@@ -2186,13 +2546,14 @@ var useRemodel = () => {
|
|
|
2186
2546
|
};
|
|
2187
2547
|
|
|
2188
2548
|
// src/puck/actions/useComplete.tsx
|
|
2189
|
-
var
|
|
2549
|
+
var import_puck7 = require("@measured/puck");
|
|
2190
2550
|
var import_react7 = require("react");
|
|
2191
|
-
var useCustomPuck4 = (0,
|
|
2551
|
+
var useCustomPuck4 = (0, import_puck7.createUsePuck)();
|
|
2192
2552
|
var useComplete = () => {
|
|
2193
2553
|
const complete = useSoftConfig((s) => s.builder.complete);
|
|
2194
2554
|
const appState = useCustomPuck4((s) => s.appState);
|
|
2195
2555
|
const setHistories = useCustomPuck4((s) => s.history.setHistories);
|
|
2556
|
+
const getItemBySelector = useCustomPuck4((s) => s.getItemBySelector);
|
|
2196
2557
|
const status = useSoftConfig((s) => s.state);
|
|
2197
2558
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2198
2559
|
const [newComponent, setNewComponent] = (0, import_react7.useState)(null);
|
|
@@ -2204,12 +2565,12 @@ var useComplete = () => {
|
|
|
2204
2565
|
return null;
|
|
2205
2566
|
}
|
|
2206
2567
|
try {
|
|
2207
|
-
const componentName = complete(appState, setHistories);
|
|
2568
|
+
const componentName = complete(appState, setHistories, getItemBySelector);
|
|
2208
2569
|
setNewComponent(componentName);
|
|
2209
2570
|
const componentData = appState.data.root;
|
|
2210
2571
|
const softComponent = (_b = softComponents[componentName]) == null ? void 0 : _b.versions[(_a = softComponents[componentName]) == null ? void 0 : _a.defaultVersion];
|
|
2211
2572
|
if (softComponent && componentData) {
|
|
2212
|
-
triggerAction({
|
|
2573
|
+
void triggerAction({
|
|
2213
2574
|
type: "complete",
|
|
2214
2575
|
payload: {
|
|
2215
2576
|
id: componentName,
|
|
@@ -2226,14 +2587,14 @@ var useComplete = () => {
|
|
|
2226
2587
|
);
|
|
2227
2588
|
return null;
|
|
2228
2589
|
}
|
|
2229
|
-
}, [complete, appState, setHistories, status, softComponents, triggerAction]);
|
|
2590
|
+
}, [complete, appState, setHistories, status, softComponents, triggerAction, getItemBySelector]);
|
|
2230
2591
|
const canComplete = status === "building" || status === "remodeling";
|
|
2231
2592
|
return { handleComplete, canComplete, newComponent, setNewComponent };
|
|
2232
2593
|
};
|
|
2233
2594
|
|
|
2234
2595
|
// src/puck/actions/useCancel.tsx
|
|
2235
|
-
var
|
|
2236
|
-
var useCustomPuck5 = (0,
|
|
2596
|
+
var import_puck8 = require("@measured/puck");
|
|
2597
|
+
var useCustomPuck5 = (0, import_puck8.createUsePuck)();
|
|
2237
2598
|
var useCancel = () => {
|
|
2238
2599
|
const cancel = useSoftConfig((s) => s.builder.cancel);
|
|
2239
2600
|
const setHistories = useCustomPuck5((s) => s.history.setHistories);
|
|
@@ -2246,7 +2607,7 @@ var useCancel = () => {
|
|
|
2246
2607
|
}
|
|
2247
2608
|
try {
|
|
2248
2609
|
cancel(setHistories);
|
|
2249
|
-
triggerAction({
|
|
2610
|
+
void triggerAction({
|
|
2250
2611
|
type: "cancel",
|
|
2251
2612
|
payload: {}
|
|
2252
2613
|
});
|
|
@@ -2262,9 +2623,9 @@ var useCancel = () => {
|
|
|
2262
2623
|
};
|
|
2263
2624
|
|
|
2264
2625
|
// src/puck/actions/useInspect.tsx
|
|
2265
|
-
var
|
|
2626
|
+
var import_puck9 = require("@measured/puck");
|
|
2266
2627
|
var import_react8 = require("react");
|
|
2267
|
-
var useCustomPuck6 = (0,
|
|
2628
|
+
var useCustomPuck6 = (0, import_puck9.createUsePuck)();
|
|
2268
2629
|
var useInspect = (componentName) => {
|
|
2269
2630
|
const inspect = useSoftConfig((s) => s.builder.inspect);
|
|
2270
2631
|
const dispatch = useCustomPuck6((s) => s.dispatch);
|
|
@@ -2278,7 +2639,7 @@ var useInspect = (componentName) => {
|
|
|
2278
2639
|
}
|
|
2279
2640
|
try {
|
|
2280
2641
|
inspect(componentName, dispatch);
|
|
2281
|
-
triggerAction({
|
|
2642
|
+
void triggerAction({
|
|
2282
2643
|
type: "inspect",
|
|
2283
2644
|
payload: {
|
|
2284
2645
|
id: componentName
|
|
@@ -2294,8 +2655,8 @@ var useInspect = (componentName) => {
|
|
|
2294
2655
|
};
|
|
2295
2656
|
|
|
2296
2657
|
// src/puck/actions/useDecompose.tsx
|
|
2297
|
-
var
|
|
2298
|
-
var useCustomPuck7 = (0,
|
|
2658
|
+
var import_puck10 = require("@measured/puck");
|
|
2659
|
+
var useCustomPuck7 = (0, import_puck10.createUsePuck)();
|
|
2299
2660
|
var useDecompose = () => {
|
|
2300
2661
|
const decompose = useSoftConfig((s) => s.builder.decompose);
|
|
2301
2662
|
const appState = useCustomPuck7((s) => s.appState);
|
|
@@ -2326,7 +2687,7 @@ var useDecompose = () => {
|
|
|
2326
2687
|
notify.error("Nothing to decompose.");
|
|
2327
2688
|
return;
|
|
2328
2689
|
}
|
|
2329
|
-
const newData = (0,
|
|
2690
|
+
const newData = (0, import_puck10.walkTree)(appState.data, config, (components) => {
|
|
2330
2691
|
const index = components.findIndex((c) => c.props.id === target.props.id);
|
|
2331
2692
|
if (index !== -1) {
|
|
2332
2693
|
components.splice(index, 1, ...decomposedComponents);
|
|
@@ -2337,7 +2698,7 @@ var useDecompose = () => {
|
|
|
2337
2698
|
type: "setData",
|
|
2338
2699
|
data: newData
|
|
2339
2700
|
});
|
|
2340
|
-
triggerAction({
|
|
2701
|
+
void triggerAction({
|
|
2341
2702
|
type: "decompose",
|
|
2342
2703
|
payload: {
|
|
2343
2704
|
id: componentName
|
|
@@ -2358,8 +2719,8 @@ var useDecompose = () => {
|
|
|
2358
2719
|
};
|
|
2359
2720
|
|
|
2360
2721
|
// src/puck/actions/useDemolish.tsx
|
|
2361
|
-
var
|
|
2362
|
-
var useCustomPuck8 = (0,
|
|
2722
|
+
var import_puck11 = require("@measured/puck");
|
|
2723
|
+
var useCustomPuck8 = (0, import_puck11.createUsePuck)();
|
|
2363
2724
|
var useDemolish = () => {
|
|
2364
2725
|
const demolish = useSoftConfig((s) => s.builder.demolish);
|
|
2365
2726
|
const dispatch = useCustomPuck8((s) => s.dispatch);
|
|
@@ -2378,7 +2739,7 @@ var useDemolish = () => {
|
|
|
2378
2739
|
}
|
|
2379
2740
|
try {
|
|
2380
2741
|
demolish(componentName, data, dispatch);
|
|
2381
|
-
triggerAction({
|
|
2742
|
+
void triggerAction({
|
|
2382
2743
|
type: "demolish",
|
|
2383
2744
|
payload: {
|
|
2384
2745
|
id: componentName
|
|
@@ -2417,7 +2778,7 @@ var useSetDefaultVersion = () => {
|
|
|
2417
2778
|
return;
|
|
2418
2779
|
}
|
|
2419
2780
|
setSoftComponentDefaultVersion(componentName, version);
|
|
2420
|
-
triggerAction({
|
|
2781
|
+
void triggerAction({
|
|
2421
2782
|
type: "setDefaultVersion",
|
|
2422
2783
|
payload: {
|
|
2423
2784
|
id: componentName,
|
|
@@ -2446,14 +2807,14 @@ var useSetDefaultVersion = () => {
|
|
|
2446
2807
|
};
|
|
2447
2808
|
|
|
2448
2809
|
// src/puck/overrides/Header.tsx
|
|
2449
|
-
var
|
|
2810
|
+
var import_puck13 = require("@measured/puck");
|
|
2450
2811
|
|
|
2451
|
-
// css-module
|
|
2812
|
+
// css-module:/media/osamu/3628738E28734BBD/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/Header.module.css#css-module
|
|
2452
2813
|
var Header_module_default = { "Header": "_Header_19oj9_1" };
|
|
2453
2814
|
|
|
2454
2815
|
// src/puck/actions/usePublish.tsx
|
|
2455
|
-
var
|
|
2456
|
-
var useCustomPuck9 = (0,
|
|
2816
|
+
var import_puck12 = require("@measured/puck");
|
|
2817
|
+
var useCustomPuck9 = (0, import_puck12.createUsePuck)();
|
|
2457
2818
|
var usePublish = () => {
|
|
2458
2819
|
const components = useSoftConfig((s) => s.softComponents);
|
|
2459
2820
|
const data = useCustomPuck9((s) => s.appState.data);
|
|
@@ -2473,7 +2834,7 @@ var usePublish = () => {
|
|
|
2473
2834
|
const rootComponentType = (_a = data.root) == null ? void 0 : _a.type;
|
|
2474
2835
|
const rootVersion = (_b = components[rootComponentType]) == null ? void 0 : _b.defaultVersion;
|
|
2475
2836
|
if (rootComponentType && rootVersion) {
|
|
2476
|
-
triggerAction({
|
|
2837
|
+
void triggerAction({
|
|
2477
2838
|
type: "publish",
|
|
2478
2839
|
payload: {
|
|
2479
2840
|
id: rootComponentType,
|
|
@@ -2489,6 +2850,7 @@ var usePublish = () => {
|
|
|
2489
2850
|
// src/puck/overrides/Header.tsx
|
|
2490
2851
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
2491
2852
|
var getClassName2 = get_class_name_factory_default("Header", Header_module_default);
|
|
2853
|
+
var usePuck = (0, import_puck13.createUsePuck)();
|
|
2492
2854
|
var Header = ({
|
|
2493
2855
|
onPublish,
|
|
2494
2856
|
children
|
|
@@ -2498,9 +2860,9 @@ var Header = ({
|
|
|
2498
2860
|
const { handlePublish } = usePublish();
|
|
2499
2861
|
useInspect(newComponent);
|
|
2500
2862
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName2(), children: canCancel ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
2501
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2863
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_puck13.Button, { onClick: handleCancel, children: "Cancel" }),
|
|
2502
2864
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2503
|
-
|
|
2865
|
+
import_puck13.Button,
|
|
2504
2866
|
{
|
|
2505
2867
|
variant: "primary",
|
|
2506
2868
|
onClick: () => {
|
|
@@ -2513,7 +2875,7 @@ var Header = ({
|
|
|
2513
2875
|
}
|
|
2514
2876
|
)
|
|
2515
2877
|
] }) : children ? children : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2516
|
-
|
|
2878
|
+
import_puck13.Button,
|
|
2517
2879
|
{
|
|
2518
2880
|
variant: "primary",
|
|
2519
2881
|
onClick: () => {
|
|
@@ -2527,31 +2889,38 @@ var Header = ({
|
|
|
2527
2889
|
};
|
|
2528
2890
|
|
|
2529
2891
|
// src/puck/overrides/ActionBar.tsx
|
|
2530
|
-
var
|
|
2892
|
+
var import_puck14 = require("@measured/puck");
|
|
2531
2893
|
var import_lucide_react = require("lucide-react");
|
|
2532
2894
|
|
|
2533
|
-
// css-module
|
|
2895
|
+
// css-module:/media/osamu/3628738E28734BBD/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
|
|
2534
2896
|
var ActionBar_module_default = { "ActionBar": "_ActionBar_pvuie_5", "ActionBar-label": "_ActionBar-label_pvuie_39", "ActionBar-action": "_ActionBar-action_pvuie_63", "ActionBar-group": "_ActionBar-group_pvuie_79" };
|
|
2535
2897
|
|
|
2536
2898
|
// src/puck/overrides/ActionBar.tsx
|
|
2899
|
+
var import_shallow = require("zustand/shallow");
|
|
2537
2900
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
2538
2901
|
var getClassName3 = get_class_name_factory_default("ActionBar", ActionBar_module_default);
|
|
2902
|
+
var usePuck2 = (0, import_puck14.createUsePuck)();
|
|
2539
2903
|
var ActionBarOverride = (props) => {
|
|
2540
|
-
|
|
2541
|
-
const {
|
|
2542
|
-
const {
|
|
2543
|
-
const
|
|
2904
|
+
var _a;
|
|
2905
|
+
const { handleBuild } = useBuild();
|
|
2906
|
+
const { handleRemodel } = useRemodel();
|
|
2907
|
+
const { handleDecompose } = useDecompose();
|
|
2908
|
+
const softComponents = useSoftConfig((s) => s.softComponents, import_shallow.shallow);
|
|
2909
|
+
const editableIds = useSoftConfig((s) => s.editableComponentIds);
|
|
2910
|
+
const selectedItem = usePuck2((s) => s.selectedItem);
|
|
2544
2911
|
const status = useSoftConfig((s) => s.state);
|
|
2545
2912
|
const isSoftComponent2 = Object.keys(softComponents || {}).includes(props.label);
|
|
2546
|
-
|
|
2547
|
-
|
|
2913
|
+
const selectedId = (_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.id;
|
|
2914
|
+
const isEditable = Boolean(selectedId && editableIds.has(selectedId));
|
|
2915
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: getClassName3(), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_puck14.ActionBar, { children: [
|
|
2916
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_puck14.ActionBar.Group, { children: [
|
|
2548
2917
|
props.parentAction,
|
|
2549
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2918
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_puck14.ActionBar.Label, { label: props.label })
|
|
2550
2919
|
] }),
|
|
2551
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
2920
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_puck14.ActionBar.Group, { children: [
|
|
2552
2921
|
status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
2553
2922
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2554
|
-
|
|
2923
|
+
import_puck14.ActionBar.Action,
|
|
2555
2924
|
{
|
|
2556
2925
|
onClick: () => handleRemodel(props.label),
|
|
2557
2926
|
label: "Remodel Soft Component",
|
|
@@ -2559,22 +2928,29 @@ var ActionBarOverride = (props) => {
|
|
|
2559
2928
|
}
|
|
2560
2929
|
),
|
|
2561
2930
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2562
|
-
|
|
2931
|
+
import_puck14.ActionBar.Action,
|
|
2563
2932
|
{
|
|
2564
2933
|
onClick: () => handleDecompose(),
|
|
2565
2934
|
label: "Decompose Soft Component",
|
|
2566
2935
|
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react.Combine, { size: 16 })
|
|
2567
2936
|
}
|
|
2568
2937
|
)
|
|
2569
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2570
|
-
|
|
2938
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2939
|
+
import_puck14.ActionBar.Action,
|
|
2940
|
+
{
|
|
2941
|
+
onClick: handleBuild,
|
|
2942
|
+
label: "Build Soft Component",
|
|
2943
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react.ComponentIcon, { size: 16 })
|
|
2944
|
+
}
|
|
2945
|
+
) : null,
|
|
2946
|
+
status !== "ready" && !isEditable ? null : props.children
|
|
2571
2947
|
] })
|
|
2572
2948
|
] }) });
|
|
2573
2949
|
};
|
|
2574
2950
|
|
|
2575
2951
|
// src/puck/overrides/ComponentItem.tsx
|
|
2576
2952
|
var import_react10 = require("react");
|
|
2577
|
-
var
|
|
2953
|
+
var import_puck15 = require("@measured/puck");
|
|
2578
2954
|
var import_lucide_react2 = require("lucide-react");
|
|
2579
2955
|
|
|
2580
2956
|
// src/puck/lib/confirm.ts
|
|
@@ -2594,14 +2970,14 @@ var confirm = (message) => __async(null, null, function* () {
|
|
|
2594
2970
|
}
|
|
2595
2971
|
});
|
|
2596
2972
|
|
|
2597
|
-
// css-module
|
|
2598
|
-
var ComponentItem_module_default = { "ComponentItem": "
|
|
2973
|
+
// css-module:/media/osamu/3628738E28734BBD/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/ComponentItem.module.css#css-module
|
|
2974
|
+
var ComponentItem_module_default = { "ComponentItem": "_ComponentItem_1kbi2_1", "ComponentItem--insertDisabled": "_ComponentItem--insertDisabled_1kbi2_14", "ComponentItem-content": "_ComponentItem-content_1kbi2_21", "ComponentItem-name": "_ComponentItem-name_1kbi2_31", "ComponentItem-version": "_ComponentItem-version_1kbi2_35", "ComponentItem-actions": "_ComponentItem-actions_1kbi2_40", "ComponentItem-settingsButton": "_ComponentItem-settingsButton_1kbi2_46", "ComponentItem-grip": "_ComponentItem-grip_1kbi2_56", "ComponentItem-modal": "_ComponentItem-modal_1kbi2_63", "ComponentItem-modalHeader": "_ComponentItem-modalHeader_1kbi2_70", "ComponentItem-modalTitle": "_ComponentItem-modalTitle_1kbi2_75", "ComponentItem-modalSubtitle": "_ComponentItem-modalSubtitle_1kbi2_82", "ComponentItem-modalBody": "_ComponentItem-modalBody_1kbi2_88", "ComponentItem-section": "_ComponentItem-section_1kbi2_97", "ComponentItem-sectionTitle": "_ComponentItem-sectionTitle_1kbi2_103", "ComponentItem-sectionDescription": "_ComponentItem-sectionDescription_1kbi2_110", "ComponentItem-versionList": "_ComponentItem-versionList_1kbi2_116", "ComponentItem-versionRow": "_ComponentItem-versionRow_1kbi2_122", "ComponentItem-versionRow--isDefault": "_ComponentItem-versionRow--isDefault_1kbi2_133", "ComponentItem-versionRow--isMarkedForDeletion": "_ComponentItem-versionRow--isMarkedForDeletion_1kbi2_138", "ComponentItem-versionInfo": "_ComponentItem-versionInfo_1kbi2_143", "ComponentItem-versionNumber": "_ComponentItem-versionNumber_1kbi2_150", "ComponentItem-defaultBadge": "_ComponentItem-defaultBadge_1kbi2_156", "ComponentItem-deleteBadge": "_ComponentItem-deleteBadge_1kbi2_167", "ComponentItem-versionActions": "_ComponentItem-versionActions_1kbi2_178", "ComponentItem-migrationOptions": "_ComponentItem-migrationOptions_1kbi2_184", "ComponentItem-select": "_ComponentItem-select_1kbi2_188", "ComponentItem-modalFooter": "_ComponentItem-modalFooter_1kbi2_209", "ComponentItem-footerLeft": "_ComponentItem-footerLeft_1kbi2_218", "ComponentItem-footerRight": "_ComponentItem-footerRight_1kbi2_223" };
|
|
2599
2975
|
|
|
2600
2976
|
// src/puck/components/modal/index.tsx
|
|
2601
2977
|
var import_react9 = require("react");
|
|
2602
2978
|
var import_react_dom = require("react-dom");
|
|
2603
2979
|
|
|
2604
|
-
// css-module
|
|
2980
|
+
// css-module:/media/osamu/3628738E28734BBD/osamuProjects/netlisian/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
|
|
2605
2981
|
var styles_module_default2 = { "Modal": "_Modal_pvj02_1", "Modal--isOpen": "_Modal--isOpen_pvj02_29", "Modal-inner": "_Modal-inner_pvj02_37" };
|
|
2606
2982
|
|
|
2607
2983
|
// src/puck/components/modal/index.tsx
|
|
@@ -2633,12 +3009,16 @@ var Modal = ({
|
|
|
2633
3009
|
};
|
|
2634
3010
|
|
|
2635
3011
|
// src/puck/overrides/ComponentItem.tsx
|
|
3012
|
+
var import_shallow2 = require("zustand/shallow");
|
|
2636
3013
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2637
3014
|
var getClassName5 = get_class_name_factory_default("ComponentItem", ComponentItem_module_default);
|
|
3015
|
+
var usePuck3 = (0, import_puck15.createUsePuck)();
|
|
2638
3016
|
var ComponentItem = (props) => {
|
|
2639
3017
|
const softComponents = new Set(
|
|
2640
|
-
Object.keys(useSoftConfig((s) => s.softComponents))
|
|
3018
|
+
Object.keys(useSoftConfig((s) => s.softComponents, import_shallow2.shallow))
|
|
2641
3019
|
);
|
|
3020
|
+
const getPermissions = usePuck3((s) => s.getPermissions);
|
|
3021
|
+
const insertAllowed = getPermissions({ type: props.name }).insert;
|
|
2642
3022
|
const removeSoftComponentVersion = useSoftConfig(
|
|
2643
3023
|
(s) => s.removeSoftComponentVersion
|
|
2644
3024
|
);
|
|
@@ -2651,6 +3031,7 @@ var ComponentItem = (props) => {
|
|
|
2651
3031
|
/* @__PURE__ */ new Set()
|
|
2652
3032
|
);
|
|
2653
3033
|
const [migrateVersionMap, setMigrateVersionMap] = (0, import_react10.useState)({});
|
|
3034
|
+
const useVersioning = useSoftConfig((s) => s.showVersionFields);
|
|
2654
3035
|
const versions = getVersions(props.name);
|
|
2655
3036
|
const defaultVersion = getDefaultVersion(props.name);
|
|
2656
3037
|
const handleApply = () => __async(null, null, function* () {
|
|
@@ -2708,20 +3089,20 @@ var ComponentItem = (props) => {
|
|
|
2708
3089
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
|
|
2709
3090
|
"div",
|
|
2710
3091
|
{
|
|
2711
|
-
className: getClassName5(),
|
|
3092
|
+
className: getClassName5({ insertDisabled: !insertAllowed }),
|
|
2712
3093
|
onMouseEnter: () => setIsHovering(true),
|
|
2713
3094
|
onMouseLeave: () => setIsHovering(false),
|
|
2714
3095
|
children: [
|
|
2715
3096
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("content"), children: [
|
|
2716
3097
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("name"), children: props.name }),
|
|
2717
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("version"), children: [
|
|
3098
|
+
useVersioning && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("version"), children: [
|
|
2718
3099
|
"v",
|
|
2719
3100
|
defaultVersion
|
|
2720
3101
|
] })
|
|
2721
3102
|
] }),
|
|
2722
3103
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("actions"), children: [
|
|
2723
3104
|
isHovering && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("settingsButton"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2724
|
-
|
|
3105
|
+
import_puck15.IconButton,
|
|
2725
3106
|
{
|
|
2726
3107
|
title: "Settings",
|
|
2727
3108
|
variant: "secondary",
|
|
@@ -2730,7 +3111,7 @@ var ComponentItem = (props) => {
|
|
|
2730
3111
|
setIsEditing(true);
|
|
2731
3112
|
setSelectedVersion(defaultVersion || "");
|
|
2732
3113
|
},
|
|
2733
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Cog, { size:
|
|
3114
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Cog, { size: 12 })
|
|
2734
3115
|
}
|
|
2735
3116
|
) }),
|
|
2736
3117
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("grip"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.GripVertical, { size: 16 }) })
|
|
@@ -2741,9 +3122,9 @@ var ComponentItem = (props) => {
|
|
|
2741
3122
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Modal, { isOpen: isEditing, onClose: handleCancel, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("modal"), children: [
|
|
2742
3123
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("modalHeader"), children: [
|
|
2743
3124
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h2", { className: getClassName5("modalTitle"), children: props.name }),
|
|
2744
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: getClassName5("modalSubtitle"), children: "
|
|
3125
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: getClassName5("modalSubtitle"), children: "Component Settings" })
|
|
2745
3126
|
] }),
|
|
2746
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.
|
|
3127
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("modalBody"), children: useVersioning ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
|
|
2747
3128
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("section"), children: [
|
|
2748
3129
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h3", { className: getClassName5("sectionTitle"), children: "Versions" }),
|
|
2749
3130
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("versionList"), children: versions.map((version) => {
|
|
@@ -2752,52 +3133,30 @@ var ComponentItem = (props) => {
|
|
|
2752
3133
|
let rowClass = getClassName5("versionRow");
|
|
2753
3134
|
if (isDefault) rowClass += " " + getClassName5("versionRow--isDefault");
|
|
2754
3135
|
if (isMarkedForDeletion) rowClass += " " + getClassName5("versionRow--isMarkedForDeletion");
|
|
2755
|
-
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
|
|
2756
|
-
"div",
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
}
|
|
2776
|
-
),
|
|
2777
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2778
|
-
import_puck14.Button,
|
|
2779
|
-
{
|
|
2780
|
-
variant: isMarkedForDeletion ? "secondary" : "secondary",
|
|
2781
|
-
onClick: () => toggleVersionForDeletion(version),
|
|
2782
|
-
children: isMarkedForDeletion ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
|
|
2783
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.X, { size: 14 }),
|
|
2784
|
-
"Undo"
|
|
2785
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
|
|
2786
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Trash2, { size: 14 }),
|
|
2787
|
-
"Delete"
|
|
2788
|
-
] })
|
|
2789
|
-
}
|
|
2790
|
-
)
|
|
2791
|
-
] })
|
|
2792
|
-
]
|
|
2793
|
-
},
|
|
2794
|
-
version
|
|
2795
|
-
);
|
|
3136
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: rowClass, children: [
|
|
3137
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("versionInfo"), children: [
|
|
3138
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { className: getClassName5("versionNumber"), children: [
|
|
3139
|
+
"Version ",
|
|
3140
|
+
version
|
|
3141
|
+
] }),
|
|
3142
|
+
isDefault && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: getClassName5("defaultBadge"), children: "Default" }),
|
|
3143
|
+
isMarkedForDeletion && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: getClassName5("deleteBadge"), children: "Marked for deletion" })
|
|
3144
|
+
] }),
|
|
3145
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("versionActions"), children: [
|
|
3146
|
+
!isDefault && !isMarkedForDeletion && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_puck15.Button, { variant: "secondary", onClick: () => setSelectedVersion(version), children: "Set as Default" }),
|
|
3147
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_puck15.Button, { variant: "secondary", onClick: () => toggleVersionForDeletion(version), children: isMarkedForDeletion ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
|
|
3148
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.X, { size: 14 }),
|
|
3149
|
+
" Undo"
|
|
3150
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
|
|
3151
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Trash2, { size: 14 }),
|
|
3152
|
+
" Delete"
|
|
3153
|
+
] }) })
|
|
3154
|
+
] })
|
|
3155
|
+
] }, version);
|
|
2796
3156
|
}) })
|
|
2797
3157
|
] }),
|
|
2798
3158
|
versionsToDelete.size > 0 && availableVersions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("section"), children: [
|
|
2799
3159
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h3", { className: getClassName5("sectionTitle"), children: "Migration Settings" }),
|
|
2800
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: getClassName5("sectionDescription"), children: "Choose what to do with components using deleted versions" }),
|
|
2801
3160
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("migrationOptions"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
|
|
2802
3161
|
"select",
|
|
2803
3162
|
{
|
|
@@ -2820,30 +3179,26 @@ var ComponentItem = (props) => {
|
|
|
2820
3179
|
}
|
|
2821
3180
|
) })
|
|
2822
3181
|
] })
|
|
2823
|
-
] }),
|
|
3182
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("section"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("p", { children: [
|
|
3183
|
+
"Manage high-level settings for the ",
|
|
3184
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("strong", { children: props.name }),
|
|
3185
|
+
" component."
|
|
3186
|
+
] }) }) }),
|
|
2824
3187
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("modalFooter"), children: [
|
|
2825
3188
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("footerLeft"), children: [
|
|
2826
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
|
|
3189
|
+
useVersioning ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_puck15.Button, { size: "medium", onClick: handleApply, children: [
|
|
2827
3190
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Check, { size: 16 }),
|
|
2828
|
-
"Apply Changes"
|
|
2829
|
-
] }),
|
|
2830
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
|
|
3191
|
+
" Apply Changes"
|
|
3192
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_puck15.Button, { size: "medium", onClick: handleCancel, children: "Close" }),
|
|
3193
|
+
useVersioning && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_puck15.Button, { size: "medium", variant: "secondary", onClick: handleCancel, children: [
|
|
2831
3194
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.X, { size: 16 }),
|
|
2832
|
-
"Cancel"
|
|
3195
|
+
" Cancel"
|
|
2833
3196
|
] })
|
|
2834
3197
|
] }),
|
|
2835
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("footerRight"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
variant: "secondary",
|
|
2840
|
-
onClick: handleDemolishClick,
|
|
2841
|
-
children: [
|
|
2842
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Trash2, { size: 16 }),
|
|
2843
|
-
"Demolish Component"
|
|
2844
|
-
]
|
|
2845
|
-
}
|
|
2846
|
-
) })
|
|
3198
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("footerRight"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_puck15.Button, { size: "medium", variant: "secondary", onClick: handleDemolishClick, children: [
|
|
3199
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Trash2, { size: 16 }),
|
|
3200
|
+
" Demolish Component"
|
|
3201
|
+
] }) })
|
|
2847
3202
|
] })
|
|
2848
3203
|
] }) })
|
|
2849
3204
|
] });
|
|
@@ -2851,6 +3206,27 @@ var ComponentItem = (props) => {
|
|
|
2851
3206
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children: props.children });
|
|
2852
3207
|
};
|
|
2853
3208
|
|
|
3209
|
+
// src/puck/lib/action-callback.ts
|
|
3210
|
+
var createActionCallback = (validateAction, undo) => {
|
|
3211
|
+
return (action) => {
|
|
3212
|
+
const isValid = validateAction(action);
|
|
3213
|
+
if (!isValid) {
|
|
3214
|
+
notify.error(
|
|
3215
|
+
"Editing outside the soft component is not allowed when you are editing component definition."
|
|
3216
|
+
);
|
|
3217
|
+
if (typeof requestAnimationFrame === "function") {
|
|
3218
|
+
requestAnimationFrame(() => {
|
|
3219
|
+
requestAnimationFrame(() => {
|
|
3220
|
+
undo();
|
|
3221
|
+
});
|
|
3222
|
+
});
|
|
3223
|
+
} else {
|
|
3224
|
+
setTimeout(() => undo(), 0);
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
};
|
|
3228
|
+
};
|
|
3229
|
+
|
|
2854
3230
|
// src/puck/lib/dissolve-all-soft-components.ts
|
|
2855
3231
|
function extractDependencies2(softComponents, componentName, version) {
|
|
2856
3232
|
var _a, _b;
|
|
@@ -3060,6 +3436,7 @@ var resolveSoftConfig = (data, softComponents, config) => {
|
|
|
3060
3436
|
Modal,
|
|
3061
3437
|
SoftConfigProvider,
|
|
3062
3438
|
confirm,
|
|
3439
|
+
createActionCallback,
|
|
3063
3440
|
createSoftConfigStore,
|
|
3064
3441
|
createUseSoftConfig,
|
|
3065
3442
|
notify,
|