@netlisian/softconfig 0.1.9 → 0.1.10

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