@netlisian/softconfig 0.0.11 → 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.
@@ -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
- const propagateChanges = setTimeout(() => {
441
- if (!fieldSettings || Object.keys(fieldSettings).length === 0) return;
442
- (0, import_puck2.walkTree)(
443
- data,
444
- {
445
- components: config.components
446
- },
447
- (content) => content.map((child) => {
448
- var _a;
449
- const map = ((_a = child.props) == null ? void 0 : _a._map) || [];
450
- if (map.length) {
451
- map.forEach(({ from, to, transform }) => {
452
- if (!from || !to) return;
453
- const fromPaths = Array.isArray(from) ? from : [from];
454
- const toPaths = Array.isArray(to) ? to : [to];
455
- const inputValues = fromPaths.map(
456
- (f) => getFieldSettingsByPath(props._fieldSettings || {}, f)
457
- );
458
- let value = transform ? transform(
459
- inputValues.map((v) => v == null ? void 0 : v.defaultValue),
460
- child.props
461
- ) : inputValues[0];
462
- if (Array.isArray(value)) {
463
- value.forEach((val, i) => {
464
- if (toPaths[i]) {
465
- const originalValue = getFieldSettingsByPath(
466
- child.props,
467
- toPaths[i]
468
- );
469
- if (originalValue !== val) {
470
- const itemSelector = getSelectorForId(child.props.id);
471
- if (!itemSelector) return;
472
- setPropertyByPath(child.props, toPaths[i], val);
473
- dispatch({
474
- type: "replace",
475
- data: child,
476
- destinationIndex: itemSelector == null ? void 0 : itemSelector.index,
477
- destinationZone: itemSelector == null ? void 0 : itemSelector.zone
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
- return child;
508
- })
509
- );
510
- }, 300);
511
- return () => clearTimeout(propagateChanges);
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:D:\osamuProjects\netlisian\packages\soft-config\src\puck\components\error-boundary\styles.module.css#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
- if (!editingComponent || name !== editingComponent) {
661
- let _a;
662
- const tempComponent = __spreadProps(__spreadValues({}, component), {
663
- resolveFields(data, params) {
664
- return __async(this, null, function* () {
665
- let fields = {};
666
- if (!fields._slot) {
667
- const slotFields = Object.entries(params.fields).filter(
668
- ([_, field]) => field.type === "slot"
669
- );
670
- if (slotFields.length)
671
- fields._slot = {
672
- type: "array",
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: "Dynamic Field Map",
685
+ label: "Enable Dropdown Slots",
686
+ getItemSummary(item, index) {
687
+ return item.slot || `Slot ${(index || 0) + 1}`;
688
+ },
730
689
  arrayFields: {
731
- from: {
690
+ slot: {
732
691
  type: "select",
733
- label: "From",
692
+ label: "Slot",
734
693
  options: [
735
- { label: "Select a field", value: "" },
736
- ...fromOptions.map(({ label, value }) => ({
737
- label,
738
- value
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
- to: {
743
- type: "select",
744
- label: "To",
745
- options: [
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
- fields = __spreadValues(__spreadValues({}, fields), defaultFields);
757
- return fields;
758
- });
759
- },
760
- resolveData: ({ props }, { lastData }) => {
761
- var _a2;
762
- const _map = props._map || [];
763
- const readOnlyFields = _map.flatMap((item) => item.to);
764
- if (_map.length) {
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") {
789
+ return {
790
+ props,
791
+ readOnly: { [lastField]: false }
792
+ };
793
+ }
794
+ if (Array.isArray(lastField)) {
765
795
  return {
766
796
  props,
767
- readOnly: readOnlyFields.reduce(
768
- (acc2, field) => __spreadProps(__spreadValues({}, acc2), { [field]: true }),
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
- acc[name] = tempComponent;
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
- appState.data.content || [],
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
- const propsSnapshot = JSON.stringify(props);
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 = propsSnapshot;
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(inputValues);
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
- }, [valuesToUpdateKey]);
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
- const fieldsWithoutSlots = Object.fromEntries(
1272
- Object.entries((versionedComponent == null ? void 0 : versionedComponent.fields) || {}).filter(([, field]) => field.type !== "slot").map(([key, field]) => [key, __spreadValues({}, field)])
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
- }, fieldsWithoutSlots);
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: [__spreadValues({}, selectedItem)]
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: (previous) => __spreadProps(__spreadValues({}, previous), {
1525
+ data: (prevData) => ({
1482
1526
  root: __spreadProps(__spreadValues({}, root), { _versions: versions }),
1483
- content: 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: "Soft Component Builder",
1504
- _name: "New Soft Component"
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 [newSoftComponentConfig, version] = get().builder.compose(appState, componentName) || [];
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
- (0, import_middleware.devtools)((set, get) => ({
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,
@@ -1924,7 +2111,8 @@ var createSoftConfigStore = (hardConfig = {
1924
2111
  Object.keys(finalComponentData.versions),
1925
2112
  state.softConfig,
1926
2113
  nextSoftComponents,
1927
- activeVersionData.defaultProps
2114
+ activeVersionData.defaultProps,
2115
+ state.showVersionFields
1928
2116
  );
1929
2117
  }
1930
2118
  });
@@ -1953,7 +2141,8 @@ var createSoftConfigStore = (hardConfig = {
1953
2141
  Object.keys(componentData.versions),
1954
2142
  softConfig,
1955
2143
  hydratedComponents,
1956
- activeVersionData.defaultProps
2144
+ activeVersionData.defaultProps,
2145
+ get().showVersionFields
1957
2146
  );
1958
2147
  }
1959
2148
  });
@@ -1981,7 +2170,8 @@ var createSoftConfigStore = (hardConfig = {
1981
2170
  allVersions,
1982
2171
  get().softConfig,
1983
2172
  get().softComponents,
1984
- softComponent.defaultProps
2173
+ softComponent.defaultProps,
2174
+ get().showVersionFields
1985
2175
  );
1986
2176
  set((state) => ({
1987
2177
  softConfig: __spreadProps(__spreadValues({}, state.softConfig), {
@@ -2081,8 +2271,49 @@ var createSoftConfigStore = (hardConfig = {
2081
2271
  })
2082
2272
  }));
2083
2273
  },
2084
- builder: createBuildersSlice(set, get, hardConfig)
2085
- }))
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
+ })
2086
2317
  )
2087
2318
  );
2088
2319
  };
@@ -2096,11 +2327,12 @@ var SoftConfigProvider = ({
2096
2327
  softComponents,
2097
2328
  overrides,
2098
2329
  value,
2099
- onActions
2330
+ onActions,
2331
+ useVersioning = false
2100
2332
  }) => {
2101
2333
  const store = value != null ? value : (0, import_react5.useMemo)(
2102
- () => createSoftConfigStore(hardConfig, softComponents, overrides, onActions),
2103
- [hardConfig, softComponents, overrides, onActions]
2334
+ () => createSoftConfigStore(hardConfig, softComponents, overrides, onActions, useVersioning),
2335
+ [hardConfig, softComponents, overrides, onActions, useVersioning]
2104
2336
  );
2105
2337
  const [softConfig, setSoftConfig] = (0, import_react5.useState)(
2106
2338
  () => store.getState().softConfig
@@ -2108,6 +2340,53 @@ var SoftConfigProvider = ({
2108
2340
  const [internalSoftComponents, setSoftComponents] = (0, import_react5.useState)(
2109
2341
  () => store.getState().softComponents
2110
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
+ );
2111
2390
  (0, import_react5.useEffect)(() => {
2112
2391
  const unsubscribe = store.subscribe(() => {
2113
2392
  setSoftConfig(store.getState().softConfig);
@@ -2117,11 +2396,32 @@ var SoftConfigProvider = ({
2117
2396
  unsubscribe();
2118
2397
  };
2119
2398
  }, [store]);
2120
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(appStoreContext.Provider, { value: store, children: children(softConfig, internalSoftComponents) });
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) });
2121
2421
  };
2122
2422
 
2123
2423
  // src/puck/actions/useBuild.tsx
2124
- var import_puck4 = require("@measured/puck");
2424
+ var import_puck5 = require("@measured/puck");
2125
2425
 
2126
2426
  // src/puck/lib/notify.ts
2127
2427
  var customHandler = null;
@@ -2166,7 +2466,7 @@ var useActionEvent = () => {
2166
2466
  };
2167
2467
 
2168
2468
  // src/puck/actions/useBuild.tsx
2169
- var useCustomPuck2 = (0, import_puck4.createUsePuck)();
2469
+ var useCustomPuck2 = (0, import_puck5.createUsePuck)();
2170
2470
  var useBuild = () => {
2171
2471
  const build = useSoftConfig((s) => s.builder.build);
2172
2472
  const history = useCustomPuck2((s) => s.history.histories);
@@ -2201,8 +2501,8 @@ var useBuild = () => {
2201
2501
  };
2202
2502
 
2203
2503
  // src/puck/actions/useRemodel.tsx
2204
- var import_puck5 = require("@measured/puck");
2205
- var useCustomPuck3 = (0, import_puck5.createUsePuck)();
2504
+ var import_puck6 = require("@measured/puck");
2505
+ var useCustomPuck3 = (0, import_puck6.createUsePuck)();
2206
2506
  var useRemodel = () => {
2207
2507
  const remodel = useSoftConfig((s) => s.builder.remodel);
2208
2508
  const history = useCustomPuck3((s) => s.history.histories);
@@ -2211,6 +2511,7 @@ var useRemodel = () => {
2211
2511
  const dispatch = useCustomPuck3((s) => s.dispatch);
2212
2512
  const status = useSoftConfig((s) => s.state);
2213
2513
  const softComponents = useSoftConfig((s) => s.softComponents);
2514
+ const refreshPermissions = useCustomPuck3((s) => s.refreshPermissions);
2214
2515
  const { triggerAction } = useActionEvent();
2215
2516
  const handleRemodel = (componentName) => {
2216
2517
  if (status !== "ready") {
@@ -2223,7 +2524,7 @@ var useRemodel = () => {
2223
2524
  return;
2224
2525
  }
2225
2526
  try {
2226
- remodel(history, selectedItem, itemSelector, dispatch);
2527
+ remodel(history, selectedItem, itemSelector, dispatch, refreshPermissions);
2227
2528
  void triggerAction({
2228
2529
  type: "remodel",
2229
2530
  payload: {
@@ -2245,13 +2546,14 @@ var useRemodel = () => {
2245
2546
  };
2246
2547
 
2247
2548
  // src/puck/actions/useComplete.tsx
2248
- var import_puck6 = require("@measured/puck");
2549
+ var import_puck7 = require("@measured/puck");
2249
2550
  var import_react7 = require("react");
2250
- var useCustomPuck4 = (0, import_puck6.createUsePuck)();
2551
+ var useCustomPuck4 = (0, import_puck7.createUsePuck)();
2251
2552
  var useComplete = () => {
2252
2553
  const complete = useSoftConfig((s) => s.builder.complete);
2253
2554
  const appState = useCustomPuck4((s) => s.appState);
2254
2555
  const setHistories = useCustomPuck4((s) => s.history.setHistories);
2556
+ const getItemBySelector = useCustomPuck4((s) => s.getItemBySelector);
2255
2557
  const status = useSoftConfig((s) => s.state);
2256
2558
  const softComponents = useSoftConfig((s) => s.softComponents);
2257
2559
  const [newComponent, setNewComponent] = (0, import_react7.useState)(null);
@@ -2263,7 +2565,7 @@ var useComplete = () => {
2263
2565
  return null;
2264
2566
  }
2265
2567
  try {
2266
- const componentName = complete(appState, setHistories);
2568
+ const componentName = complete(appState, setHistories, getItemBySelector);
2267
2569
  setNewComponent(componentName);
2268
2570
  const componentData = appState.data.root;
2269
2571
  const softComponent = (_b = softComponents[componentName]) == null ? void 0 : _b.versions[(_a = softComponents[componentName]) == null ? void 0 : _a.defaultVersion];
@@ -2285,14 +2587,14 @@ var useComplete = () => {
2285
2587
  );
2286
2588
  return null;
2287
2589
  }
2288
- }, [complete, appState, setHistories, status, softComponents, triggerAction]);
2590
+ }, [complete, appState, setHistories, status, softComponents, triggerAction, getItemBySelector]);
2289
2591
  const canComplete = status === "building" || status === "remodeling";
2290
2592
  return { handleComplete, canComplete, newComponent, setNewComponent };
2291
2593
  };
2292
2594
 
2293
2595
  // src/puck/actions/useCancel.tsx
2294
- var import_puck7 = require("@measured/puck");
2295
- var useCustomPuck5 = (0, import_puck7.createUsePuck)();
2596
+ var import_puck8 = require("@measured/puck");
2597
+ var useCustomPuck5 = (0, import_puck8.createUsePuck)();
2296
2598
  var useCancel = () => {
2297
2599
  const cancel = useSoftConfig((s) => s.builder.cancel);
2298
2600
  const setHistories = useCustomPuck5((s) => s.history.setHistories);
@@ -2321,9 +2623,9 @@ var useCancel = () => {
2321
2623
  };
2322
2624
 
2323
2625
  // src/puck/actions/useInspect.tsx
2324
- var import_puck8 = require("@measured/puck");
2626
+ var import_puck9 = require("@measured/puck");
2325
2627
  var import_react8 = require("react");
2326
- var useCustomPuck6 = (0, import_puck8.createUsePuck)();
2628
+ var useCustomPuck6 = (0, import_puck9.createUsePuck)();
2327
2629
  var useInspect = (componentName) => {
2328
2630
  const inspect = useSoftConfig((s) => s.builder.inspect);
2329
2631
  const dispatch = useCustomPuck6((s) => s.dispatch);
@@ -2353,8 +2655,8 @@ var useInspect = (componentName) => {
2353
2655
  };
2354
2656
 
2355
2657
  // src/puck/actions/useDecompose.tsx
2356
- var import_puck9 = require("@measured/puck");
2357
- var useCustomPuck7 = (0, import_puck9.createUsePuck)();
2658
+ var import_puck10 = require("@measured/puck");
2659
+ var useCustomPuck7 = (0, import_puck10.createUsePuck)();
2358
2660
  var useDecompose = () => {
2359
2661
  const decompose = useSoftConfig((s) => s.builder.decompose);
2360
2662
  const appState = useCustomPuck7((s) => s.appState);
@@ -2385,7 +2687,7 @@ var useDecompose = () => {
2385
2687
  notify.error("Nothing to decompose.");
2386
2688
  return;
2387
2689
  }
2388
- const newData = (0, import_puck9.walkTree)(appState.data, config, (components) => {
2690
+ const newData = (0, import_puck10.walkTree)(appState.data, config, (components) => {
2389
2691
  const index = components.findIndex((c) => c.props.id === target.props.id);
2390
2692
  if (index !== -1) {
2391
2693
  components.splice(index, 1, ...decomposedComponents);
@@ -2417,8 +2719,8 @@ var useDecompose = () => {
2417
2719
  };
2418
2720
 
2419
2721
  // src/puck/actions/useDemolish.tsx
2420
- var import_puck10 = require("@measured/puck");
2421
- var useCustomPuck8 = (0, import_puck10.createUsePuck)();
2722
+ var import_puck11 = require("@measured/puck");
2723
+ var useCustomPuck8 = (0, import_puck11.createUsePuck)();
2422
2724
  var useDemolish = () => {
2423
2725
  const demolish = useSoftConfig((s) => s.builder.demolish);
2424
2726
  const dispatch = useCustomPuck8((s) => s.dispatch);
@@ -2505,14 +2807,14 @@ var useSetDefaultVersion = () => {
2505
2807
  };
2506
2808
 
2507
2809
  // src/puck/overrides/Header.tsx
2508
- var import_puck12 = require("@measured/puck");
2810
+ var import_puck13 = require("@measured/puck");
2509
2811
 
2510
- // css-module:D:\osamuProjects\netlisian\packages\soft-config\src\puck\overrides\Header.module.css#css-module
2812
+ // css-module:/media/osamu/3628738E28734BBD/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/Header.module.css#css-module
2511
2813
  var Header_module_default = { "Header": "_Header_19oj9_1" };
2512
2814
 
2513
2815
  // src/puck/actions/usePublish.tsx
2514
- var import_puck11 = require("@measured/puck");
2515
- var useCustomPuck9 = (0, import_puck11.createUsePuck)();
2816
+ var import_puck12 = require("@measured/puck");
2817
+ var useCustomPuck9 = (0, import_puck12.createUsePuck)();
2516
2818
  var usePublish = () => {
2517
2819
  const components = useSoftConfig((s) => s.softComponents);
2518
2820
  const data = useCustomPuck9((s) => s.appState.data);
@@ -2548,6 +2850,7 @@ var usePublish = () => {
2548
2850
  // src/puck/overrides/Header.tsx
2549
2851
  var import_jsx_runtime8 = require("react/jsx-runtime");
2550
2852
  var getClassName2 = get_class_name_factory_default("Header", Header_module_default);
2853
+ var usePuck = (0, import_puck13.createUsePuck)();
2551
2854
  var Header = ({
2552
2855
  onPublish,
2553
2856
  children
@@ -2557,9 +2860,9 @@ var Header = ({
2557
2860
  const { handlePublish } = usePublish();
2558
2861
  useInspect(newComponent);
2559
2862
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName2(), children: canCancel ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
2560
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_puck12.Button, { onClick: handleCancel, children: "Cancel" }),
2863
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_puck13.Button, { onClick: handleCancel, children: "Cancel" }),
2561
2864
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2562
- import_puck12.Button,
2865
+ import_puck13.Button,
2563
2866
  {
2564
2867
  variant: "primary",
2565
2868
  onClick: () => {
@@ -2572,7 +2875,7 @@ var Header = ({
2572
2875
  }
2573
2876
  )
2574
2877
  ] }) : children ? children : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2575
- import_puck12.Button,
2878
+ import_puck13.Button,
2576
2879
  {
2577
2880
  variant: "primary",
2578
2881
  onClick: () => {
@@ -2586,31 +2889,38 @@ var Header = ({
2586
2889
  };
2587
2890
 
2588
2891
  // src/puck/overrides/ActionBar.tsx
2589
- var import_puck13 = require("@measured/puck");
2892
+ var import_puck14 = require("@measured/puck");
2590
2893
  var import_lucide_react = require("lucide-react");
2591
2894
 
2592
- // css-module:D:\osamuProjects\netlisian\packages\soft-config\src\puck\overrides\ActionBar.module.css#css-module
2895
+ // css-module:/media/osamu/3628738E28734BBD/osamuProjects/netlisian/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
2593
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" };
2594
2897
 
2595
2898
  // src/puck/overrides/ActionBar.tsx
2899
+ var import_shallow = require("zustand/shallow");
2596
2900
  var import_jsx_runtime9 = require("react/jsx-runtime");
2597
2901
  var getClassName3 = get_class_name_factory_default("ActionBar", ActionBar_module_default);
2902
+ var usePuck2 = (0, import_puck14.createUsePuck)();
2598
2903
  var ActionBarOverride = (props) => {
2599
- const { handleBuild, canBuild } = useBuild();
2600
- const { handleRemodel, canRemodel } = useRemodel();
2601
- const { handleDecompose, canDecompose } = useDecompose();
2602
- const softComponents = useSoftConfig((s) => s.softComponents);
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);
2603
2911
  const status = useSoftConfig((s) => s.state);
2604
2912
  const isSoftComponent2 = Object.keys(softComponents || {}).includes(props.label);
2605
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: getClassName3(), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_puck13.ActionBar, { children: [
2606
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_puck13.ActionBar.Group, { children: [
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: [
2607
2917
  props.parentAction,
2608
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_puck13.ActionBar.Label, { label: props.label })
2918
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_puck14.ActionBar.Label, { label: props.label })
2609
2919
  ] }),
2610
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_puck13.ActionBar.Group, { children: [
2920
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_puck14.ActionBar.Group, { children: [
2611
2921
  status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
2612
2922
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
2613
- import_puck13.ActionBar.Action,
2923
+ import_puck14.ActionBar.Action,
2614
2924
  {
2615
2925
  onClick: () => handleRemodel(props.label),
2616
2926
  label: "Remodel Soft Component",
@@ -2618,22 +2928,29 @@ var ActionBarOverride = (props) => {
2618
2928
  }
2619
2929
  ),
2620
2930
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
2621
- import_puck13.ActionBar.Action,
2931
+ import_puck14.ActionBar.Action,
2622
2932
  {
2623
2933
  onClick: () => handleDecompose(),
2624
2934
  label: "Decompose Soft Component",
2625
2935
  children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react.Combine, { size: 16 })
2626
2936
  }
2627
2937
  )
2628
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_puck13.ActionBar.Action, { onClick: handleBuild, label: "Build Soft Component", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react.ComponentIcon, { size: 16 }) }) : null,
2629
- props.children
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
2630
2947
  ] })
2631
2948
  ] }) });
2632
2949
  };
2633
2950
 
2634
2951
  // src/puck/overrides/ComponentItem.tsx
2635
2952
  var import_react10 = require("react");
2636
- var import_puck14 = require("@measured/puck");
2953
+ var import_puck15 = require("@measured/puck");
2637
2954
  var import_lucide_react2 = require("lucide-react");
2638
2955
 
2639
2956
  // src/puck/lib/confirm.ts
@@ -2653,14 +2970,14 @@ var confirm = (message) => __async(null, null, function* () {
2653
2970
  }
2654
2971
  });
2655
2972
 
2656
- // css-module:D:\osamuProjects\netlisian\packages\soft-config\src\puck\overrides\ComponentItem.module.css#css-module
2657
- var ComponentItem_module_default = { "ComponentItem": "_ComponentItem_lp9eh_1", "ComponentItem-content": "_ComponentItem-content_lp9eh_14", "ComponentItem-name": "_ComponentItem-name_lp9eh_24", "ComponentItem-version": "_ComponentItem-version_lp9eh_28", "ComponentItem-actions": "_ComponentItem-actions_lp9eh_33", "ComponentItem-settingsButton": "_ComponentItem-settingsButton_lp9eh_39", "ComponentItem-grip": "_ComponentItem-grip_lp9eh_49", "ComponentItem-modal": "_ComponentItem-modal_lp9eh_56", "ComponentItem-modalHeader": "_ComponentItem-modalHeader_lp9eh_63", "ComponentItem-modalTitle": "_ComponentItem-modalTitle_lp9eh_68", "ComponentItem-modalSubtitle": "_ComponentItem-modalSubtitle_lp9eh_75", "ComponentItem-modalBody": "_ComponentItem-modalBody_lp9eh_81", "ComponentItem-section": "_ComponentItem-section_lp9eh_90", "ComponentItem-sectionTitle": "_ComponentItem-sectionTitle_lp9eh_96", "ComponentItem-sectionDescription": "_ComponentItem-sectionDescription_lp9eh_103", "ComponentItem-versionList": "_ComponentItem-versionList_lp9eh_109", "ComponentItem-versionRow": "_ComponentItem-versionRow_lp9eh_115", "ComponentItem-versionRow--isDefault": "_ComponentItem-versionRow--isDefault_lp9eh_126", "ComponentItem-versionRow--isMarkedForDeletion": "_ComponentItem-versionRow--isMarkedForDeletion_lp9eh_131", "ComponentItem-versionInfo": "_ComponentItem-versionInfo_lp9eh_136", "ComponentItem-versionNumber": "_ComponentItem-versionNumber_lp9eh_143", "ComponentItem-defaultBadge": "_ComponentItem-defaultBadge_lp9eh_149", "ComponentItem-deleteBadge": "_ComponentItem-deleteBadge_lp9eh_160", "ComponentItem-versionActions": "_ComponentItem-versionActions_lp9eh_171", "ComponentItem-migrationOptions": "_ComponentItem-migrationOptions_lp9eh_177", "ComponentItem-select": "_ComponentItem-select_lp9eh_181", "ComponentItem-modalFooter": "_ComponentItem-modalFooter_lp9eh_202", "ComponentItem-footerLeft": "_ComponentItem-footerLeft_lp9eh_211", "ComponentItem-footerRight": "_ComponentItem-footerRight_lp9eh_216" };
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" };
2658
2975
 
2659
2976
  // src/puck/components/modal/index.tsx
2660
2977
  var import_react9 = require("react");
2661
2978
  var import_react_dom = require("react-dom");
2662
2979
 
2663
- // css-module:D:\osamuProjects\netlisian\packages\soft-config\src\puck\components\modal\styles.module.css#css-module
2980
+ // css-module:/media/osamu/3628738E28734BBD/osamuProjects/netlisian/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
2664
2981
  var styles_module_default2 = { "Modal": "_Modal_pvj02_1", "Modal--isOpen": "_Modal--isOpen_pvj02_29", "Modal-inner": "_Modal-inner_pvj02_37" };
2665
2982
 
2666
2983
  // src/puck/components/modal/index.tsx
@@ -2692,12 +3009,16 @@ var Modal = ({
2692
3009
  };
2693
3010
 
2694
3011
  // src/puck/overrides/ComponentItem.tsx
3012
+ var import_shallow2 = require("zustand/shallow");
2695
3013
  var import_jsx_runtime11 = require("react/jsx-runtime");
2696
3014
  var getClassName5 = get_class_name_factory_default("ComponentItem", ComponentItem_module_default);
3015
+ var usePuck3 = (0, import_puck15.createUsePuck)();
2697
3016
  var ComponentItem = (props) => {
2698
3017
  const softComponents = new Set(
2699
- Object.keys(useSoftConfig((s) => s.softComponents))
3018
+ Object.keys(useSoftConfig((s) => s.softComponents, import_shallow2.shallow))
2700
3019
  );
3020
+ const getPermissions = usePuck3((s) => s.getPermissions);
3021
+ const insertAllowed = getPermissions({ type: props.name }).insert;
2701
3022
  const removeSoftComponentVersion = useSoftConfig(
2702
3023
  (s) => s.removeSoftComponentVersion
2703
3024
  );
@@ -2710,6 +3031,7 @@ var ComponentItem = (props) => {
2710
3031
  /* @__PURE__ */ new Set()
2711
3032
  );
2712
3033
  const [migrateVersionMap, setMigrateVersionMap] = (0, import_react10.useState)({});
3034
+ const useVersioning = useSoftConfig((s) => s.showVersionFields);
2713
3035
  const versions = getVersions(props.name);
2714
3036
  const defaultVersion = getDefaultVersion(props.name);
2715
3037
  const handleApply = () => __async(null, null, function* () {
@@ -2767,20 +3089,20 @@ var ComponentItem = (props) => {
2767
3089
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
2768
3090
  "div",
2769
3091
  {
2770
- className: getClassName5(),
3092
+ className: getClassName5({ insertDisabled: !insertAllowed }),
2771
3093
  onMouseEnter: () => setIsHovering(true),
2772
3094
  onMouseLeave: () => setIsHovering(false),
2773
3095
  children: [
2774
3096
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("content"), children: [
2775
3097
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("name"), children: props.name }),
2776
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("version"), children: [
3098
+ useVersioning && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("version"), children: [
2777
3099
  "v",
2778
3100
  defaultVersion
2779
3101
  ] })
2780
3102
  ] }),
2781
3103
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("actions"), children: [
2782
3104
  isHovering && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("settingsButton"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2783
- import_puck14.IconButton,
3105
+ import_puck15.IconButton,
2784
3106
  {
2785
3107
  title: "Settings",
2786
3108
  variant: "secondary",
@@ -2789,7 +3111,7 @@ var ComponentItem = (props) => {
2789
3111
  setIsEditing(true);
2790
3112
  setSelectedVersion(defaultVersion || "");
2791
3113
  },
2792
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Cog, { size: 14 })
3114
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Cog, { size: 12 })
2793
3115
  }
2794
3116
  ) }),
2795
3117
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("grip"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.GripVertical, { size: 16 }) })
@@ -2800,9 +3122,9 @@ var ComponentItem = (props) => {
2800
3122
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Modal, { isOpen: isEditing, onClose: handleCancel, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("modal"), children: [
2801
3123
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("modalHeader"), children: [
2802
3124
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h2", { className: getClassName5("modalTitle"), children: props.name }),
2803
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: getClassName5("modalSubtitle"), children: "Manage versions and settings" })
3125
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: getClassName5("modalSubtitle"), children: "Component Settings" })
2804
3126
  ] }),
2805
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("modalBody"), children: [
3127
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("modalBody"), children: useVersioning ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
2806
3128
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("section"), children: [
2807
3129
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h3", { className: getClassName5("sectionTitle"), children: "Versions" }),
2808
3130
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("versionList"), children: versions.map((version) => {
@@ -2811,52 +3133,30 @@ var ComponentItem = (props) => {
2811
3133
  let rowClass = getClassName5("versionRow");
2812
3134
  if (isDefault) rowClass += " " + getClassName5("versionRow--isDefault");
2813
3135
  if (isMarkedForDeletion) rowClass += " " + getClassName5("versionRow--isMarkedForDeletion");
2814
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
2815
- "div",
2816
- {
2817
- className: rowClass,
2818
- children: [
2819
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("versionInfo"), children: [
2820
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { className: getClassName5("versionNumber"), children: [
2821
- "Version ",
2822
- version
2823
- ] }),
2824
- isDefault && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: getClassName5("defaultBadge"), children: "Default" }),
2825
- isMarkedForDeletion && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: getClassName5("deleteBadge"), children: "Marked for deletion" })
2826
- ] }),
2827
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("versionActions"), children: [
2828
- !isDefault && !isMarkedForDeletion && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2829
- import_puck14.Button,
2830
- {
2831
- variant: "secondary",
2832
- onClick: () => setSelectedVersion(version),
2833
- children: "Set as Default"
2834
- }
2835
- ),
2836
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2837
- import_puck14.Button,
2838
- {
2839
- variant: isMarkedForDeletion ? "secondary" : "secondary",
2840
- onClick: () => toggleVersionForDeletion(version),
2841
- children: isMarkedForDeletion ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
2842
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.X, { size: 14 }),
2843
- "Undo"
2844
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
2845
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Trash2, { size: 14 }),
2846
- "Delete"
2847
- ] })
2848
- }
2849
- )
2850
- ] })
2851
- ]
2852
- },
2853
- version
2854
- );
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);
2855
3156
  }) })
2856
3157
  ] }),
2857
3158
  versionsToDelete.size > 0 && availableVersions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("section"), children: [
2858
3159
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h3", { className: getClassName5("sectionTitle"), children: "Migration Settings" }),
2859
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: getClassName5("sectionDescription"), children: "Choose what to do with components using deleted versions" }),
2860
3160
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("migrationOptions"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
2861
3161
  "select",
2862
3162
  {
@@ -2879,30 +3179,26 @@ var ComponentItem = (props) => {
2879
3179
  }
2880
3180
  ) })
2881
3181
  ] })
2882
- ] }),
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
+ ] }) }) }),
2883
3187
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("modalFooter"), children: [
2884
3188
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName5("footerLeft"), children: [
2885
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_puck14.Button, { size: "medium", onClick: handleApply, children: [
3189
+ useVersioning ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_puck15.Button, { size: "medium", onClick: handleApply, children: [
2886
3190
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Check, { size: 16 }),
2887
- "Apply Changes"
2888
- ] }),
2889
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_puck14.Button, { size: "medium", variant: "secondary", onClick: handleCancel, children: [
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: [
2890
3194
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.X, { size: 16 }),
2891
- "Cancel"
3195
+ " Cancel"
2892
3196
  ] })
2893
3197
  ] }),
2894
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName5("footerRight"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
2895
- import_puck14.Button,
2896
- {
2897
- size: "medium",
2898
- variant: "secondary",
2899
- onClick: handleDemolishClick,
2900
- children: [
2901
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react2.Trash2, { size: 16 }),
2902
- "Demolish Component"
2903
- ]
2904
- }
2905
- ) })
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
+ ] }) })
2906
3202
  ] })
2907
3203
  ] }) })
2908
3204
  ] });
@@ -2910,6 +3206,27 @@ var ComponentItem = (props) => {
2910
3206
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children: props.children });
2911
3207
  };
2912
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
+
2913
3230
  // src/puck/lib/dissolve-all-soft-components.ts
2914
3231
  function extractDependencies2(softComponents, componentName, version) {
2915
3232
  var _a, _b;
@@ -3119,6 +3436,7 @@ var resolveSoftConfig = (data, softComponents, config) => {
3119
3436
  Modal,
3120
3437
  SoftConfigProvider,
3121
3438
  confirm,
3439
+ createActionCallback,
3122
3440
  createSoftConfigStore,
3123
3441
  createUseSoftConfig,
3124
3442
  notify,