@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,4 +1,5 @@
1
1
  'use client'
2
+ "use client";
2
3
  var __defProp = Object.defineProperty;
3
4
  var __defProps = Object.defineProperties;
4
5
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -43,24 +44,42 @@ var __async = (__this, __arguments, generator) => {
43
44
  import { create } from "zustand";
44
45
  import { subscribeWithSelector } from "zustand/middleware";
45
46
 
46
- // src/puck/store/slices/builder.tsx
47
- import {
48
- walkTree as walkTree3
49
- } from "@measured/puck";
50
-
51
- // src/puck/lib/get-root-props.ts
52
- var getRootProps = (appState) => appState.data.root.props;
47
+ // src/puck/lib/root-action-handler.ts
48
+ import isEqual from "react-fast-compare";
53
49
 
54
- // src/puck/lib/builder/root-config.tsx
55
- import { useEffect } from "react";
56
- import equal2 from "react-fast-compare";
57
- import {
58
- createUsePuck,
59
- walkTree
60
- } from "@measured/puck";
50
+ // src/puck/lib/apply-mapping.ts
51
+ import equal from "react-fast-compare";
61
52
 
62
- // src/puck/lib/get-field-settings.tsx
63
- import { AutoField } from "@measured/puck";
53
+ // src/puck/lib/set-prop-by-path.ts
54
+ function setPropertyByPath(props, path, value) {
55
+ const parts = path.replace(/\[(\w+)\]/g, ".$1").split(".");
56
+ const last = parts.pop();
57
+ let cur = props;
58
+ for (const p of parts) {
59
+ if (typeof cur[p] !== "object" || cur[p] === null) cur[p] = {};
60
+ cur = cur[p];
61
+ }
62
+ cur[last] = value;
63
+ }
64
+ function setImmutablePropertyByPath(obj, path, value) {
65
+ if (!path) return value;
66
+ const parts = path.replace(/\[(\w+)\]/g, ".$1").split(".");
67
+ const root = Array.isArray(obj) ? [...obj] : __spreadValues({}, obj);
68
+ let current = root;
69
+ for (let i = 0; i < parts.length - 1; i++) {
70
+ const part = parts[i];
71
+ const nextPart = parts[i + 1];
72
+ const isArrayNext = !isNaN(Number(nextPart));
73
+ if (current[part] === void 0 || current[part] === null) {
74
+ current[part] = isArrayNext ? [] : {};
75
+ } else {
76
+ current[part] = Array.isArray(current[part]) ? [...current[part]] : __spreadValues({}, current[part]);
77
+ }
78
+ current = current[part];
79
+ }
80
+ current[parts[parts.length - 1]] = value;
81
+ return root;
82
+ }
64
83
 
65
84
  // src/puck/lib/get-settings-by-path.ts
66
85
  function getFieldSettingsByPath(fieldSettings, path) {
@@ -68,14 +87,6 @@ function getFieldSettingsByPath(fieldSettings, path) {
68
87
  }
69
88
 
70
89
  // src/puck/lib/array-field-utils.ts
71
- var primitiveFieldTypes = /* @__PURE__ */ new Set([
72
- "text",
73
- "textarea",
74
- "number",
75
- "select",
76
- "radio",
77
- "reference"
78
- ]);
79
90
  var isPrimitiveValue = (value) => ["string", "number", "boolean"].includes(typeof value);
80
91
  var getFallbackValueForField = (type) => {
81
92
  switch (type) {
@@ -107,7 +118,6 @@ var resolveExpressionSummary = (item, index, expression) => {
107
118
  });
108
119
  return isValid ? result : "";
109
120
  };
110
- var isPrimitiveFieldType = (type) => primitiveFieldTypes.has(type);
111
121
  var buildArrayDefaultItemProps = (subFields = [], subFieldSettings = {}) => {
112
122
  if (!subFields.length) return void 0;
113
123
  const item = {};
@@ -160,486 +170,19 @@ var getArrayItemSubPath = (arrayPath) => {
160
170
  return match ? match[1] : null;
161
171
  };
162
172
 
163
- // src/puck/lib/custom-fields.ts
164
- var builtInSoftFieldTypes = /* @__PURE__ */ new Set([
165
- "text",
166
- "textarea",
167
- "number",
168
- "select",
169
- "radio",
170
- "array",
171
- "object",
172
- "reference"
173
- ]);
174
- var warnedMessages = /* @__PURE__ */ new Set();
175
- var warnOnce = (message) => {
176
- if (warnedMessages.has(message)) {
177
- return;
178
- }
179
- warnedMessages.add(message);
180
- console.warn(message);
181
- };
182
- var isBuiltInSoftFieldType = (fieldType) => {
183
- return builtInSoftFieldTypes.has(fieldType);
184
- };
185
- var resolveCustomFieldDefinition = (fieldType, customFields) => {
186
- if (isBuiltInSoftFieldType(fieldType)) {
187
- return void 0;
188
- }
189
- return customFields == null ? void 0 : customFields[fieldType];
190
- };
191
- var resolveCustomFieldReturnType = (fieldType, customFields) => {
192
- const customField = resolveCustomFieldDefinition(fieldType, customFields);
193
- if (!customField) {
194
- return null;
195
- }
196
- if (!customField.returnType) {
197
- warnOnce(
198
- `[soft-config] Custom field "${fieldType}" is missing a required returnType and will be skipped from mapping options.`
199
- );
200
- return null;
201
- }
202
- return customField.returnType;
203
- };
204
- var resolveCustomFieldSchema = (fieldType, customFields) => {
205
- const customField = resolveCustomFieldDefinition(fieldType, customFields);
206
- if (!customField) {
207
- return null;
208
- }
209
- const returnType = resolveCustomFieldReturnType(fieldType, customFields);
210
- if (!returnType) {
211
- return null;
212
- }
213
- if (returnType !== "array" && returnType !== "object") {
214
- return null;
215
- }
216
- const subFields = customField.subFields || [];
217
- if (!subFields.length) {
218
- warnOnce(
219
- `[soft-config] Custom field "${fieldType}" returns ${returnType} but does not define subFields. It will be skipped from mapping options.`
220
- );
221
- return null;
222
- }
223
- return {
224
- subFields,
225
- subFieldSettings: customField.subFieldSettings || {}
226
- };
227
- };
228
- var getCustomFieldTypeOptions = (customFields) => {
229
- if (!customFields) {
230
- return [];
231
- }
232
- return Object.entries(customFields).filter(([fieldType]) => !isBuiltInSoftFieldType(fieldType)).map(([fieldType, definition]) => ({
233
- label: typeof definition.field.label === "string" && definition.field.label ? definition.field.label : fieldType,
234
- value: fieldType
235
- }));
236
- };
237
- var mapCustomReturnTypeToMappingType = (returnType) => {
238
- switch (returnType) {
239
- case "string":
240
- return "textarea";
241
- case "number":
242
- return "number";
243
- case "boolean":
244
- return "select";
245
- case "array":
246
- return "array";
247
- case "object":
248
- return "object";
249
- default:
250
- return "textarea";
251
- }
252
- };
253
-
254
- // src/puck/lib/get-field-settings.tsx
255
- import { jsx } from "react/jsx-runtime";
256
- var buildPuckField = (field, fieldSettings, customFields) => {
257
- const customFieldDefinition = resolveCustomFieldDefinition(
258
- field.type,
259
- customFields
260
- );
261
- const customReturnType = resolveCustomFieldReturnType(field.type, customFields);
262
- if (customFieldDefinition && customReturnType) {
263
- return __spreadProps(__spreadValues({}, customFieldDefinition.field), {
264
- type: "custom",
265
- label: customFieldDefinition.field.label || field.name
266
- });
267
- }
268
- const resolvedType = field.type;
269
- switch (resolvedType) {
270
- case "text":
271
- case "textarea":
272
- return { type: resolvedType, label: field.name };
273
- case "number":
274
- return {
275
- type: resolvedType,
276
- label: field.name,
277
- min: fieldSettings == null ? void 0 : fieldSettings.min,
278
- max: fieldSettings == null ? void 0 : fieldSettings.max,
279
- step: fieldSettings == null ? void 0 : fieldSettings.step
280
- };
281
- case "select":
282
- case "radio":
283
- return {
284
- type: resolvedType,
285
- label: field.name,
286
- options: (fieldSettings == null ? void 0 : fieldSettings.options) || []
287
- };
288
- case "array": {
289
- const subFields = (fieldSettings == null ? void 0 : fieldSettings.subFields) || [];
290
- const subFieldSettings = (fieldSettings == null ? void 0 : fieldSettings.subFieldSettings) || {};
291
- return {
292
- type: "array",
293
- label: field.name,
294
- min: fieldSettings == null ? void 0 : fieldSettings.min,
295
- max: fieldSettings == null ? void 0 : fieldSettings.max,
296
- arrayFields: buildDefaultEditorFields(
297
- subFields,
298
- subFieldSettings,
299
- customFields
300
- ),
301
- defaultItemProps: buildArrayDefaultItemProps(subFields, subFieldSettings),
302
- getItemSummary(item, index) {
303
- return getArrayItemSummary(item, index, fieldSettings);
304
- }
305
- };
306
- }
307
- case "object":
308
- return {
309
- type: "object",
310
- label: field.name,
311
- objectFields: buildDefaultEditorFields(
312
- (fieldSettings == null ? void 0 : fieldSettings.subFields) || [],
313
- (fieldSettings == null ? void 0 : fieldSettings.subFieldSettings) || {},
314
- customFields
315
- )
316
- };
317
- default:
318
- return { type: "text", label: field.name };
319
- }
320
- };
321
- var buildDefaultEditorFields = (fields = [], fieldSettings = {}, customFields) => {
322
- return fields.reduce((acc, field) => {
323
- acc[field.name] = buildPuckField(
324
- field,
325
- fieldSettings[field.name],
326
- customFields
327
- );
328
- return acc;
329
- }, {});
330
- };
331
- var getFieldSettings = (_fields, _fieldSettings, customFields, deep) => {
332
- const customTypeOptions = getCustomFieldTypeOptions(customFields);
333
- return (_fields || []).reduce((fields, field) => {
334
- const fieldSettings = {
335
- // placeholder: { type: "text", label: "Placeholder" },
336
- };
337
- const currentFieldSettings = _fieldSettings == null ? void 0 : _fieldSettings[field.name];
338
- const customFieldDefinition = resolveCustomFieldDefinition(
339
- field.type,
340
- customFields
341
- );
342
- const customReturnType = resolveCustomFieldReturnType(
343
- field.type,
344
- customFields
345
- );
346
- const resolvedType = field.type;
347
- const customSchema = resolveCustomFieldSchema(field.type, customFields);
348
- const resolvedSubFields = (customSchema == null ? void 0 : customSchema.subFields) || (currentFieldSettings == null ? void 0 : currentFieldSettings.subFields) || [];
349
- const resolvedSubFieldSettings = (customSchema == null ? void 0 : customSchema.subFieldSettings) || (currentFieldSettings == null ? void 0 : currentFieldSettings.subFieldSettings) || {};
350
- const customDefaultValueField = customFieldDefinition && customReturnType ? __spreadProps(__spreadValues({}, customFieldDefinition.field), {
351
- type: "custom",
352
- label: customFieldDefinition.field.label || "Default Value"
353
- }) : null;
354
- if (customDefaultValueField) {
355
- fieldSettings.defaultValue = customDefaultValueField;
356
- }
357
- switch (resolvedType) {
358
- case "text":
359
- case "textarea":
360
- if (!customDefaultValueField) {
361
- fieldSettings.defaultValue = {
362
- type: resolvedType,
363
- label: "Default Value"
364
- };
365
- }
366
- break;
367
- case "number":
368
- if (!customDefaultValueField) {
369
- fieldSettings.defaultValue = {
370
- type: resolvedType,
371
- label: "Default Value"
372
- };
373
- }
374
- fieldSettings.min = {
375
- type: resolvedType,
376
- label: "Minimum Value"
377
- };
378
- fieldSettings.max = {
379
- type: resolvedType,
380
- label: "Maximum Value"
381
- };
382
- fieldSettings.step = {
383
- type: resolvedType,
384
- label: "Step Size"
385
- };
386
- break;
387
- case "radio":
388
- case "select": {
389
- const selectOptions = (currentFieldSettings == null ? void 0 : currentFieldSettings.options) || [];
390
- if (!customDefaultValueField) {
391
- fieldSettings.defaultValue = {
392
- type: "custom",
393
- label: "Default Value",
394
- render: ({ value, onChange, id }) => /* @__PURE__ */ jsx(
395
- AutoField,
396
- {
397
- field: {
398
- type: resolvedType,
399
- label: "Default Value",
400
- options: selectOptions
401
- },
402
- value,
403
- onChange,
404
- readOnly: false,
405
- id
406
- }
407
- )
408
- };
409
- }
410
- fieldSettings.options = {
411
- type: "array",
412
- label: "Options",
413
- defaultItemProps: {
414
- label: "New Option",
415
- value: "new"
416
- },
417
- arrayFields: {
418
- label: { type: "text", label: "Label" },
419
- value: {
420
- type: "text",
421
- label: "Value"
422
- }
423
- },
424
- getItemSummary(item, index) {
425
- return item.label || `Option ${(index || 0) + 1}`;
426
- }
427
- };
428
- break;
429
- }
430
- case "array":
431
- case "object":
432
- fieldSettings.subFields = {
433
- type: "array",
434
- label: "Sub Fields",
435
- defaultItemProps: {
436
- name: "New Sub Field",
437
- type: "text"
438
- },
439
- arrayFields: {
440
- name: { type: "text", label: "Name" },
441
- type: {
442
- type: "select",
443
- options: deep ? [
444
- {
445
- label: "Text",
446
- value: "text"
447
- },
448
- {
449
- label: "Number",
450
- value: "number"
451
- },
452
- {
453
- label: "Select",
454
- value: "select"
455
- },
456
- {
457
- label: "Radio",
458
- value: "radio"
459
- },
460
- ...customTypeOptions
461
- ] : [
462
- {
463
- label: "Text",
464
- value: "text"
465
- },
466
- {
467
- label: "Number",
468
- value: "number"
469
- },
470
- {
471
- label: "Select",
472
- value: "select"
473
- },
474
- {
475
- label: "Radio",
476
- value: "radio"
477
- },
478
- {
479
- label: "Array",
480
- value: "array"
481
- },
482
- {
483
- label: "Object",
484
- value: "object"
485
- },
486
- {
487
- label: "Reference",
488
- value: "reference"
489
- },
490
- ...customTypeOptions
491
- ]
492
- }
493
- },
494
- getItemSummary(item, index) {
495
- return item.name || `Field ${(index || 0) + 1}`;
496
- }
497
- };
498
- if (!deep)
499
- fieldSettings.subFieldSettings = {
500
- type: "object",
501
- label: "Sub Field Settings",
502
- objectFields: resolvedSubFields ? getFieldSettings(
503
- resolvedSubFields,
504
- resolvedSubFieldSettings,
505
- customFields,
506
- true
507
- ) : {}
508
- };
509
- if (resolvedType === "array") {
510
- if (!customDefaultValueField) {
511
- fieldSettings.defaultValue = {
512
- type: "array",
513
- label: "Default Items",
514
- arrayFields: buildDefaultEditorFields(
515
- resolvedSubFields,
516
- resolvedSubFieldSettings,
517
- customFields
518
- ),
519
- defaultItemProps: buildArrayDefaultItemProps(
520
- resolvedSubFields,
521
- resolvedSubFieldSettings
522
- ),
523
- getItemSummary(item, index) {
524
- return getArrayItemSummary(item, index, currentFieldSettings);
525
- }
526
- };
527
- }
528
- fieldSettings.min = {
529
- type: "number",
530
- label: "Minimum Items"
531
- };
532
- fieldSettings.max = {
533
- type: "number",
534
- label: "Maximum Items"
535
- };
536
- fieldSettings.summary = {
537
- type: "select",
538
- label: "Summary",
539
- options: [
540
- {
541
- label: "Default Numbering / Count",
542
- value: "count"
543
- },
544
- {
545
- label: "Field",
546
- value: "field"
547
- },
548
- {
549
- label: "Expression",
550
- value: "expression"
551
- }
552
- ]
553
- };
554
- if ((currentFieldSettings == null ? void 0 : currentFieldSettings.summary) === "field") {
555
- fieldSettings.summaryField = {
556
- type: "select",
557
- label: "Summary Field",
558
- options: [
559
- {
560
- label: "Select a field",
561
- value: ""
562
- },
563
- ...resolvedSubFields.filter((subField) => isPrimitiveFieldType(subField.type)).map((subField) => ({
564
- label: subField.name,
565
- value: subField.name
566
- }))
567
- ]
568
- };
569
- }
570
- if ((currentFieldSettings == null ? void 0 : currentFieldSettings.summary) === "expression") {
571
- fieldSettings.summaryExpression = {
572
- type: "text",
573
- label: "Summary Expression"
574
- };
575
- }
576
- }
577
- break;
578
- }
579
- const overriddenFieldSettings = (customFieldDefinition == null ? void 0 : customFieldDefinition.fieldSettingsOverride) ? customFieldDefinition.fieldSettingsOverride({
580
- fieldName: field.name,
581
- fieldType: field.type,
582
- fieldSettings: currentFieldSettings,
583
- originalFieldSettings: fieldSettings
584
- }) : fieldSettings;
585
- fields[field.name] = {
586
- type: "object",
587
- label: field.name,
588
- objectFields: overriddenFieldSettings
589
- };
590
- return fields;
591
- }, {});
592
- };
593
- var get_field_settings_default = getFieldSettings;
594
-
595
- // src/puck/context/useStore.ts
596
- import { createContext, useContext } from "react";
597
- import { useStore } from "zustand";
598
- var appStoreContext = createContext(null);
599
- var createUseSoftConfig = () => {
600
- return function useSoftConfig2(selector, equalityFn) {
601
- const context = useContext(appStoreContext);
602
- if (!context) {
603
- throw new Error(
604
- "useSoftConfig must be used inside a SoftConfigProvider. Wrap your tree with <SoftConfigProvider value={store}>"
605
- );
606
- }
607
- if (equalityFn) {
608
- return useStore(context, selector, equalityFn);
609
- }
610
- return useStore(context, selector);
611
- };
612
- };
613
- var useSoftConfig = createUseSoftConfig();
614
- var useSoftConfigStore = () => {
615
- const context = useContext(appStoreContext);
616
- if (!context) {
617
- throw new Error(
618
- "useSoftConfigStore must be used inside a SoftConfigProvider."
619
- );
620
- }
621
- return context;
622
- };
623
-
624
173
  // src/puck/lib/apply-mapping.ts
625
- import equal from "react-fast-compare";
626
-
627
- // src/puck/lib/set-prop-by-path.ts
628
- function setPropertyByPath(props, path, value) {
629
- const parts = path.split(".");
630
- const last = parts.pop();
631
- let cur = props;
632
- for (const p of parts) {
633
- if (typeof cur[p] !== "object" || cur[p] === null) cur[p] = {};
634
- cur = cur[p];
174
+ var pathSegmentsCache = /* @__PURE__ */ new Map();
175
+ var getPathSegments = (path) => {
176
+ let segments = pathSegmentsCache.get(path);
177
+ if (!segments) {
178
+ segments = path.split(".");
179
+ pathSegmentsCache.set(path, segments);
635
180
  }
636
- cur[last] = value;
637
- }
638
-
639
- // src/puck/lib/apply-mapping.ts
181
+ return segments;
182
+ };
640
183
  var resolveValueByPath = (source, path) => {
641
184
  if (!path) return source;
642
- const segments = path.split(".");
185
+ const segments = getPathSegments(path);
643
186
  const resolveSegments = (current, index) => {
644
187
  if (current === null || current === void 0) return void 0;
645
188
  if (index >= segments.length) return current;
@@ -658,7 +201,7 @@ var resolveValueByPath = (source, path) => {
658
201
  };
659
202
  var resolveFieldSettingEntryByPath = (settings, path) => {
660
203
  if (!path) return void 0;
661
- const segments = path.split(".");
204
+ const segments = getPathSegments(path);
662
205
  let currentSettings = settings;
663
206
  let currentEntry;
664
207
  for (const segmentWithArraySuffix of segments) {
@@ -676,11 +219,11 @@ var resolveFieldSettingEntryByPath = (settings, path) => {
676
219
  };
677
220
  function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings", options) {
678
221
  var _a, _b, _c;
679
- const newProps = __spreadValues({}, props);
222
+ let newProps = props;
680
223
  const sourceProps = (_a = options == null ? void 0 : options.sourceProps) != null ? _a : props;
681
224
  const mappedArrayPaths = /* @__PURE__ */ new Set();
682
225
  let changed = false;
683
- const changedArrayBases = /* @__PURE__ */ new Set();
226
+ const arrayRulesMap = /* @__PURE__ */ new Map();
684
227
  for (const entry of map) {
685
228
  const { from, to, transform } = entry;
686
229
  if (!from || !to) continue;
@@ -719,43 +262,21 @@ function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings",
719
262
  if (isSingleArrayTarget) {
720
263
  const toPath = toPaths[0];
721
264
  const arrayBase = getArrayBasePath(toPath);
722
- const subProp = getArrayItemSubPath(toPath) || "";
723
265
  if (!arrayBase) continue;
724
- 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] : [];
725
- const currentArrayAtPath = resolveValueByPath(newProps, arrayBase);
726
- const currentArray = Array.isArray(currentArrayAtPath) ? currentArrayAtPath : [];
727
- const isFromArrayPath = typeof fromPaths[0] === "string" && isArrayMappingPath(fromPaths[0]);
728
- const sourceArray = isFromArrayPath ? Array.isArray(result) ? result : result !== void 0 ? [result] : [] : Array.isArray(result) ? result : defaultArray.map(() => result);
729
- let defaults = entry.unmappedArrayItemDefaultValues || entry.defaultOverrides || {};
730
- if (typeof defaults === "string") {
731
- try {
732
- defaults = JSON.parse(defaults);
733
- } catch (e) {
734
- defaults = {};
735
- }
736
- }
737
- const targetLength = sourceArray.length;
738
- const constructed = Array.from({ length: targetLength }).map((_, idx) => {
739
- const mappedValue = sourceArray[idx];
740
- const defaultItem = defaultArray[idx] && typeof defaultArray[idx] === "object" ? defaultArray[idx] : {};
741
- const currentItem = currentArray[idx] && typeof currentArray[idx] === "object" ? currentArray[idx] : {};
742
- const item = __spreadValues(__spreadValues(__spreadValues({}, defaultItem), defaults), currentItem);
743
- if (subProp && mappedValue !== void 0) {
744
- setPropertyByPath(item, subProp, mappedValue);
745
- }
746
- return item;
747
- });
748
- const originalArray = resolveValueByPath(newProps, arrayBase);
749
- if (!equal(originalArray, constructed)) {
750
- setPropertyByPath(newProps, arrayBase, constructed);
751
- changedArrayBases.add(arrayBase);
266
+ let rules = arrayRulesMap.get(arrayBase);
267
+ if (!rules) {
268
+ rules = [];
269
+ arrayRulesMap.set(arrayBase, rules);
752
270
  }
271
+ rules.push({ entry, toPath, fromPaths, result });
753
272
  mappedArrayPaths.add(arrayBase);
754
- } else if (toPaths.length === 1 && Array.isArray(result) && toPaths[0].includes("array")) {
273
+ continue;
274
+ }
275
+ if (toPaths.length === 1 && Array.isArray(result) && toPaths[0].includes("array")) {
755
276
  const toPath = toPaths[0];
756
277
  const original = resolveValueByPath(newProps, toPath);
757
278
  if (!equal(original, result)) {
758
- setPropertyByPath(newProps, toPath, result);
279
+ newProps = setImmutablePropertyByPath(newProps, toPath, result);
759
280
  changed = true;
760
281
  }
761
282
  } else if (Array.isArray(result) && toPaths.length > 1) {
@@ -763,7 +284,7 @@ function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings",
763
284
  if (toPaths[idx]) {
764
285
  const orig = resolveValueByPath(newProps, toPaths[idx]);
765
286
  if (!equal(orig, val)) {
766
- setPropertyByPath(newProps, toPaths[idx], val);
287
+ newProps = setImmutablePropertyByPath(newProps, toPaths[idx], val);
767
288
  changed = true;
768
289
  }
769
290
  }
@@ -772,565 +293,233 @@ function applyMapping(props, fieldSettings, map, resolveInput = "fieldSettings",
772
293
  const finalValue = result;
773
294
  const originalValue = resolveValueByPath(newProps, toPaths[0]);
774
295
  if (!equal(originalValue, finalValue)) {
775
- setPropertyByPath(newProps, toPaths[0], finalValue);
296
+ newProps = setImmutablePropertyByPath(newProps, toPaths[0], finalValue);
776
297
  changed = true;
777
298
  }
778
299
  }
779
300
  }
780
- const hasNetArrayChanges = Array.from(changedArrayBases).some(
781
- (arrayBase) => !equal(resolveValueByPath(props, arrayBase), resolveValueByPath(newProps, arrayBase))
782
- );
783
- return { newProps, mappedArrayPaths, changed: changed || hasNetArrayChanges };
784
- }
785
-
786
- // src/puck/lib/builder/root-config.tsx
787
- import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
788
- var useCustomPuck = createUsePuck();
789
- var getSerializableProps = (props) => {
790
- const cleanProps = {
791
- id: props.id
792
- };
793
- for (const key in props) {
794
- const value = props[key];
795
- if (["children", "puck", "editMode"].includes(key)) continue;
796
- if (value && typeof value === "object" && value.$$typeof) continue;
797
- if (typeof value === "function") continue;
798
- cleanProps[key] = value;
799
- }
800
- return cleanProps;
801
- };
802
- var builderRootConfig = (config, overrides, editingComponent, showVersionFields = true, customFields) => {
803
- const customTypeOptions = getCustomFieldTypeOptions(customFields);
804
- return {
805
- fields: __spreadValues({
806
- _name: overrides.name || {
807
- type: "text",
808
- label: "Soft Component Name"
809
- },
810
- _category: overrides.categories || {
811
- type: "select",
812
- label: "Category",
813
- options: [
814
- ...Object.keys(config.categories || {}).map((cat) => {
815
- var _a;
816
- return {
817
- label: ((_a = config.categories) == null ? void 0 : _a[cat].title) || cat,
818
- value: cat
819
- };
820
- }) || [],
821
- {
822
- label: Object.keys(config.categories || {}).length ? "Other" : "Uncategorized",
823
- value: void 0
824
- }
825
- ]
826
- },
827
- _fields: {
828
- type: "array",
829
- label: "Fields",
830
- defaultItemProps: {
831
- name: "New Field",
832
- type: "text"
833
- },
834
- getItemSummary(item, index) {
835
- return item.name || `Field ${(index || 0) + 1}`;
836
- },
837
- arrayFields: {
838
- name: { type: "text", label: "Name" },
839
- type: {
840
- type: "select",
841
- label: "Type",
842
- options: [
843
- { label: "Text", value: "text" },
844
- { label: "Textarea", value: "textarea" },
845
- { label: "Number", value: "number" },
846
- { label: "Select", value: "select" },
847
- { label: "Radio", value: "radio" },
848
- { label: "Array", value: "array" },
849
- { label: "Object", value: "object" },
850
- // { label: "Reference", value: "reference" },
851
- ...customTypeOptions
852
- ]
301
+ for (const [arrayBase, rules] of arrayRulesMap.entries()) {
302
+ const defaultArray = Array.isArray((_b = options == null ? void 0 : options.arrayDefaults) == null ? void 0 : _b[arrayBase]) ? (_c = options == null ? void 0 : options.arrayDefaults) == null ? void 0 : _c[arrayBase] : [];
303
+ const currentArrayAtPath = resolveValueByPath(newProps, arrayBase);
304
+ const currentArray = Array.isArray(currentArrayAtPath) ? currentArrayAtPath : [];
305
+ let targetLength = 0;
306
+ const ruleSourceArrays = rules.map(({ entry, fromPaths, result }) => {
307
+ const isFromArrayPath = typeof fromPaths[0] === "string" && isArrayMappingPath(fromPaths[0]);
308
+ const sourceArray = isFromArrayPath ? Array.isArray(result) ? result : result !== void 0 ? [result] : [] : Array.isArray(result) ? result : defaultArray.map(() => result);
309
+ targetLength = Math.max(targetLength, sourceArray.length);
310
+ return sourceArray;
311
+ });
312
+ const constructed = Array.from({ length: targetLength }).map((_, idx) => {
313
+ const defaultItem = defaultArray[idx] && typeof defaultArray[idx] === "object" ? defaultArray[idx] : {};
314
+ const currentItem = currentArray[idx] && typeof currentArray[idx] === "object" ? currentArray[idx] : {};
315
+ let mergedDefaults = {};
316
+ for (const rule of rules) {
317
+ let ruleDefaults = rule.entry.unmappedArrayItemDefaultValues || rule.entry.defaultOverrides || {};
318
+ if (typeof ruleDefaults === "string") {
319
+ try {
320
+ ruleDefaults = JSON.parse(ruleDefaults);
321
+ } catch (e) {
853
322
  }
854
323
  }
324
+ mergedDefaults = __spreadValues(__spreadValues({}, mergedDefaults), ruleDefaults);
855
325
  }
856
- }, overrides.additionalRootFields || {}),
857
- resolveFields({ props: data }, { fields, changed }) {
858
- const newFields = __spreadValues({}, fields);
859
- const rootFields = Array.isArray(
860
- data == null ? void 0 : data._fields
861
- ) ? (data == null ? void 0 : data._fields) || [] : [];
862
- const rootFieldSettings = (data == null ? void 0 : data._fieldSettings) || {};
863
- if (changed._fields || changed._fieldSettings) {
864
- if (rootFields.length) {
865
- newFields._fieldSettings = {
866
- type: "object",
867
- label: "Field Settings",
868
- objectFields: get_field_settings_default(
869
- rootFields,
870
- rootFieldSettings,
871
- customFields
872
- )
873
- };
874
- } else {
875
- delete newFields._fieldSettings;
876
- }
877
- }
878
- return newFields;
879
- },
880
- // resolveData: (props, params) => {
881
- // if (overrides.resolveRootData) {
882
- // return overrides.resolveRootData(props, params, { editingComponent });
883
- // }
884
- // const result: {
885
- // props: RootData<AsFieldProps<WithChildren<BuilderRootConfig>>>;
886
- // readOnly: Readonly<Record<string, boolean>> | undefined;
887
- // } = {
888
- // props,
889
- // readOnly: undefined,
890
- // };
891
- // return result;
892
- // },
893
- render: (props) => {
894
- const fieldSettings = props == null ? void 0 : props._fieldSettings;
895
- const data = useCustomPuck((s) => s.appState.data);
896
- const dispatch = useCustomPuck((s) => s.dispatch);
897
- const getSelectorForId = useCustomPuck((s) => s.getSelectorForId);
898
- const setVersion = useSoftConfig((s) => s.builder.setVersion);
899
- const state = useSoftConfig((s) => s.state);
900
- useEffect(() => {
901
- if (!fieldSettings || Object.keys(fieldSettings).length === 0) return;
902
- const replacements = [];
903
- walkTree(
904
- {
905
- content: (data == null ? void 0 : data.content) || [],
906
- root: (data == null ? void 0 : data.root) || {}
907
- },
908
- {
909
- components: config.components
910
- },
911
- (content) => content.map((child) => {
912
- var _a;
913
- const map = ((_a = child.props) == null ? void 0 : _a._map) || [];
914
- if (!map.length) return child;
915
- const cleanProps = getSerializableProps(child.props);
916
- const { newProps, changed } = applyMapping(
917
- cleanProps,
918
- fieldSettings,
919
- map,
920
- "fieldSettings"
921
- );
922
- if (!changed || equal2(cleanProps, newProps)) return child;
923
- replacements.push({
924
- id: child.props.id,
925
- data: __spreadProps(__spreadValues({}, child), { props: newProps })
926
- });
927
- return child;
928
- })
929
- );
930
- if (!replacements.length) return;
931
- replacements.forEach((replacement) => {
932
- const itemSelector = getSelectorForId(replacement.id);
933
- if (!itemSelector) return;
934
- dispatch({
935
- type: "replace",
936
- data: replacement.data,
937
- destinationIndex: itemSelector.index,
938
- destinationZone: itemSelector.zone
939
- });
940
- });
941
- }, [fieldSettings, data, dispatch, getSelectorForId]);
942
- useEffect(() => {
943
- var _a;
944
- if (state !== "remodeling" || !(props == null ? void 0 : props._version) || !(props == null ? void 0 : props._name)) return;
945
- const currentVersion = props._version;
946
- if (((_a = props._versions) == null ? void 0 : _a.includes(currentVersion)) && props._versions.length > 1) {
947
- setVersion(props._name, currentVersion, props, dispatch);
326
+ const baseItem = __spreadValues(__spreadValues({}, defaultItem), mergedDefaults);
327
+ let newItem = void 0;
328
+ for (const key of Object.keys(baseItem)) {
329
+ if (!(key in currentItem) && baseItem[key] !== void 0) {
330
+ if (!newItem) newItem = __spreadValues({}, currentItem);
331
+ if (newItem) {
332
+ newItem[key] = baseItem[key];
333
+ }
948
334
  }
949
- }, [props == null ? void 0 : props._version]);
950
- return /* @__PURE__ */ jsx2(Fragment, { children: props.children });
951
- }
952
- };
953
- };
954
-
955
- // src/puck/lib/builder/generate-field-options.ts
956
- var hasArrayMappingPath = (value) => value.includes("[]");
957
- var isBareArrayPath = (value) => !hasArrayMappingPath(value) && !value.includes(".");
958
- function filterToOptionsForFrom(fromPath, toOptions) {
959
- if (!fromPath) return toOptions;
960
- const fromHasArrayMapping = hasArrayMappingPath(fromPath);
961
- const fromIsBareArray = isBareArrayPath(fromPath);
962
- return toOptions.filter((option) => {
963
- const optionHasArrayMapping = hasArrayMappingPath(option.value);
964
- if (fromHasArrayMapping) {
965
- return optionHasArrayMapping;
966
- }
967
- if (fromIsBareArray) {
968
- return isBareArrayPath(option.value);
969
- }
970
- return !optionHasArrayMapping;
971
- });
972
- }
973
- function generateFieldOptions(fields, prefix = "") {
974
- const opts = [];
975
- function recurse(current, prefix2) {
976
- Object.entries(current).forEach(([key, fld]) => {
977
- if (fld.type === "slot") return;
978
- if (key === "_map") return;
979
- if (key === "_slotEnabled") return;
980
- const path = prefix2 ? `${prefix2}.${key}` : key;
981
- if (fld.type === "object" && fld.objectFields) {
982
- recurse(fld.objectFields, path);
983
- } else if (fld.type === "array" && fld.arrayFields) {
984
- recurse(
985
- fld.arrayFields,
986
- path + "[]"
987
- );
988
- } else {
989
- opts.push({ label: path, value: path, type: fld.type });
990
335
  }
991
- });
992
- }
993
- recurse(fields, prefix);
994
- return opts;
995
- }
996
- function generateDynamicFieldOptions(_fields, _fieldSettings, customFields, prefix = "") {
997
- const opts = [];
998
- if (!_fields) return opts;
999
- function recurse(fields, fieldSettings, currentPrefix) {
1000
- fields.forEach((field) => {
1001
- var _a;
1002
- const settings = fieldSettings[field.name];
1003
- const customReturnType = resolveCustomFieldReturnType(
1004
- field.type,
1005
- customFields
1006
- );
1007
- const path = currentPrefix ? `${currentPrefix}.${field.name}` : field.name;
1008
- if (customReturnType) {
1009
- if (customReturnType === "array" || customReturnType === "object") {
1010
- const customSchema = resolveCustomFieldSchema(field.type, customFields);
1011
- if (!customSchema) {
1012
- return;
336
+ for (let i = 0; i < rules.length; i++) {
337
+ const { toPath } = rules[i];
338
+ const subProp = getArrayItemSubPath(toPath) || "";
339
+ const mappedValue = ruleSourceArrays[i][idx];
340
+ if (subProp && mappedValue !== void 0) {
341
+ const existingValue = resolveValueByPath(newItem || currentItem, subProp);
342
+ if (!equal(existingValue, mappedValue)) {
343
+ newItem = setImmutablePropertyByPath(newItem || currentItem, subProp, mappedValue);
1013
344
  }
1014
- recurse(
1015
- customSchema.subFields,
1016
- customSchema.subFieldSettings,
1017
- path + (customReturnType === "array" ? "[]" : "")
1018
- );
1019
- return;
1020
345
  }
1021
- opts.push({
1022
- label: path,
1023
- value: path,
1024
- type: mapCustomReturnTypeToMappingType(customReturnType)
1025
- });
1026
- return;
1027
- }
1028
- if (!isBuiltInSoftFieldType(field.type)) {
1029
- return;
1030
- }
1031
- if ((_a = settings == null ? void 0 : settings.subFields) == null ? void 0 : _a.length) {
1032
- recurse(
1033
- settings.subFields,
1034
- settings.subFieldSettings || {},
1035
- path + (field.type === "array" ? "[]" : "")
1036
- );
1037
- } else if (field.type !== "array" && field.type !== "object") {
1038
- opts.push({ label: path, value: path, type: field.type });
1039
346
  }
347
+ return newItem !== void 0 ? newItem : currentItem;
1040
348
  });
349
+ let arrayChanged = currentArray.length !== constructed.length;
350
+ if (!arrayChanged) {
351
+ for (let i = 0; i < currentArray.length; i++) {
352
+ if (currentArray[i] !== constructed[i]) {
353
+ arrayChanged = true;
354
+ break;
355
+ }
356
+ }
357
+ }
358
+ if (arrayChanged) {
359
+ newProps = setImmutablePropertyByPath(newProps, arrayBase, constructed);
360
+ changed = true;
361
+ }
1041
362
  }
1042
- recurse(_fields, _fieldSettings || {}, prefix);
1043
- return opts;
1044
- }
1045
-
1046
- // src/puck/components/error-boundary/index.tsx
1047
- import { Component } from "react";
1048
-
1049
- // src/puck/lib/get-class-name-factory.ts
1050
- import classnames from "classnames";
1051
- var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
1052
- if (typeof options === "string") {
1053
- const descendant = options;
1054
- const style = styles[`${rootClass}-${descendant}`];
1055
- if (style) {
1056
- return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
1057
- }
1058
- return "";
1059
- } else if (typeof options === "object") {
1060
- const modifiers = options;
1061
- const prefixedModifiers = {};
1062
- for (let modifier in modifiers) {
1063
- prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
1064
- }
1065
- const c = styles[rootClass];
1066
- return config.baseClass + classnames(__spreadValues({
1067
- [c]: !!c
1068
- }, prefixedModifiers));
1069
- } else {
1070
- return config.baseClass + styles[rootClass] || "";
1071
- }
1072
- };
1073
- var get_class_name_factory_default = getClassNameFactory;
1074
-
1075
- // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
1076
- 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" };
1077
-
1078
- // src/puck/components/error-boundary/index.tsx
1079
- import { jsx as jsx3, jsxs } from "react/jsx-runtime";
1080
- var getClassName = get_class_name_factory_default("ErrorBoundary", styles_module_default);
1081
- var ErrorBoundary = class extends Component {
1082
- constructor(props) {
1083
- super(props);
1084
- this.resetError = () => {
1085
- this.setState({
1086
- hasError: false,
1087
- error: null
1088
- });
1089
- };
1090
- this.state = {
1091
- hasError: false,
1092
- error: null
1093
- };
1094
- }
1095
- static getDerivedStateFromError(error) {
1096
- return {
1097
- hasError: true,
1098
- error
1099
- };
363
+ return { newProps, mappedArrayPaths, changed };
364
+ }
365
+
366
+ // src/puck/lib/root-action-handler.ts
367
+ var currentGeneration = 0;
368
+ function hasDefaultValueChanged(prev, curr) {
369
+ var _a, _b;
370
+ if (!prev && !curr) return false;
371
+ if (!prev || !curr) return true;
372
+ if (!isEqual(prev == null ? void 0 : prev.defaultValue, curr == null ? void 0 : curr.defaultValue)) return true;
373
+ if ((prev == null ? void 0 : prev.subFieldSettings) || (curr == null ? void 0 : curr.subFieldSettings)) {
374
+ const subKeys = /* @__PURE__ */ new Set([
375
+ ...Object.keys((prev == null ? void 0 : prev.subFieldSettings) || {}),
376
+ ...Object.keys((curr == null ? void 0 : curr.subFieldSettings) || {})
377
+ ]);
378
+ for (const subKey of subKeys) {
379
+ if (hasDefaultValueChanged(
380
+ (_a = prev == null ? void 0 : prev.subFieldSettings) == null ? void 0 : _a[subKey],
381
+ (_b = curr == null ? void 0 : curr.subFieldSettings) == null ? void 0 : _b[subKey]
382
+ )) {
383
+ return true;
384
+ }
385
+ }
1100
386
  }
1101
- componentDidCatch(error, errorInfo) {
1102
- console.error("Error caught by ErrorBoundary:", error, errorInfo);
387
+ return false;
388
+ }
389
+ var processReplacements = (appState, get, fieldSettings, changedKeys, zones, nodes) => __async(null, null, function* () {
390
+ var _a, _b;
391
+ const generation = ++currentGeneration;
392
+ yield new Promise((resolve) => setTimeout(resolve, 150));
393
+ if (generation !== currentGeneration) return;
394
+ const { puckDispatch, editableComponentIds } = get();
395
+ if (!puckDispatch) return;
396
+ if (changedKeys.size === 0) return;
397
+ const replacements = [];
398
+ const editableSet = new Set(editableComponentIds || []);
399
+ const hasEditableFilter = editableSet.size > 0;
400
+ const nodeEntries = Object.entries(nodes);
401
+ for (let i = 0; i < nodeEntries.length; i++) {
402
+ if (generation !== currentGeneration) return;
403
+ if (i > 0 && i % 50 === 0) {
404
+ yield new Promise((resolve) => setTimeout(resolve, 0));
405
+ if (generation !== currentGeneration) return;
406
+ }
407
+ const [id, node] = nodeEntries[i];
408
+ if (hasEditableFilter && !editableSet.has(id)) {
409
+ continue;
410
+ }
411
+ const map = ((_a = node.data.props) == null ? void 0 : _a._map) || [];
412
+ if (!map.length) continue;
413
+ let isAffected = false;
414
+ const flatProps = ((_b = node.flatData) == null ? void 0 : _b.props) || {};
415
+ for (const [flatKey, flatValue] of Object.entries(flatProps)) {
416
+ if (flatKey.includes("_map") && flatKey.includes("from") && typeof flatValue === "string") {
417
+ if (changedKeys.has(flatValue) || Array.from(changedKeys).some(
418
+ (ck) => flatValue.startsWith(ck + ".") || flatValue.startsWith(ck + "[")
419
+ )) {
420
+ isAffected = true;
421
+ break;
422
+ }
423
+ }
424
+ }
425
+ if (!isAffected) continue;
426
+ const { newProps } = applyMapping(
427
+ __spreadValues({}, node.data.props),
428
+ fieldSettings,
429
+ map,
430
+ "fieldSettings"
431
+ );
432
+ replacements.push({
433
+ id,
434
+ data: __spreadProps(__spreadValues({}, node.data), {
435
+ props: __spreadValues(__spreadValues({}, node.data.props), newProps)
436
+ })
437
+ });
1103
438
  }
1104
- render() {
1105
- if (this.state.hasError) {
1106
- if (typeof this.props.fallback === "function") {
1107
- return this.props.fallback(this.state.error, this.resetError);
439
+ if (!replacements.length) return;
440
+ requestAnimationFrame(() => {
441
+ replacements.forEach((replacement) => {
442
+ var _a2;
443
+ const node = nodes[replacement.id];
444
+ if (!node) return;
445
+ const zoneName = `${node.parentId}:${node.zone}`;
446
+ const index = (_a2 = zones[zoneName]) == null ? void 0 : _a2.contentIds.indexOf(replacement.id);
447
+ if (index !== void 0 && index !== -1) {
448
+ puckDispatch({
449
+ type: "replace",
450
+ destinationIndex: index,
451
+ destinationZone: zoneName,
452
+ data: replacement.data,
453
+ ui: void 0
454
+ });
1108
455
  }
1109
- if (this.props.fallback) {
1110
- return this.props.fallback;
456
+ });
457
+ });
458
+ });
459
+ var processVersionChange = (rootProps, get, zones, nodes) => {
460
+ const currentVersion = rootProps._version;
461
+ const versions = rootProps._versions || [];
462
+ if (versions.includes(currentVersion) && versions.length > 1) {
463
+ const puckDispatch = get().puckDispatch;
464
+ if (puckDispatch) {
465
+ get().builder.setVersion(
466
+ rootProps._name,
467
+ currentVersion,
468
+ rootProps,
469
+ puckDispatch,
470
+ // Mock getItemBySelector using indexes
471
+ (selector) => {
472
+ var _a;
473
+ if (!selector.zone) return void 0;
474
+ const id = (_a = zones[selector.zone]) == null ? void 0 : _a.contentIds[selector.index];
475
+ return id ? nodes[id].data : void 0;
476
+ },
477
+ // Mock getSelectorForId using indexes
478
+ (id) => {
479
+ var _a;
480
+ const node = nodes[id];
481
+ if (!node) return void 0;
482
+ const index = (_a = zones[node.zone]) == null ? void 0 : _a.contentIds.indexOf(id);
483
+ return { zone: node.zone, index };
484
+ }
485
+ );
486
+ }
487
+ }
488
+ };
489
+ var rootActionHandler = (set, get) => (action, appState, previousState) => {
490
+ const storeState = get().state;
491
+ if (storeState !== "building" && storeState !== "remodeling" || action.type !== "replaceRoot") {
492
+ return;
493
+ }
494
+ const { zones, nodes } = appState.indexes;
495
+ const rootProps = appState.data.root.props;
496
+ const previousRootProps = (previousState == null ? void 0 : previousState.data.root).props;
497
+ const fieldSettings = rootProps == null ? void 0 : rootProps._fieldSettings;
498
+ const previousFieldSettings = previousRootProps == null ? void 0 : previousRootProps._fieldSettings;
499
+ if (fieldSettings) {
500
+ const changedKeys = /* @__PURE__ */ new Set();
501
+ const allKeys = /* @__PURE__ */ new Set([
502
+ ...Object.keys(previousFieldSettings || {}),
503
+ ...Object.keys(fieldSettings || {})
504
+ ]);
505
+ for (const key of allKeys) {
506
+ if (hasDefaultValueChanged(previousFieldSettings == null ? void 0 : previousFieldSettings[key], fieldSettings == null ? void 0 : fieldSettings[key])) {
507
+ changedKeys.add(key);
1111
508
  }
1112
- return /* @__PURE__ */ jsxs("div", { className: getClassName(), children: [
1113
- /* @__PURE__ */ jsx3("h3", { className: getClassName("title"), children: "Component Error" }),
1114
- /* @__PURE__ */ jsxs("details", { className: getClassName("details"), children: [
1115
- /* @__PURE__ */ jsx3("summary", { children: "Show error details" }),
1116
- this.state.error && this.state.error.toString()
1117
- ] }),
1118
- /* @__PURE__ */ jsx3(
1119
- "button",
1120
- {
1121
- onClick: this.resetError,
1122
- className: getClassName("button"),
1123
- children: "Try Again"
1124
- }
1125
- )
1126
- ] });
1127
509
  }
1128
- return this.props.children;
510
+ if (changedKeys.size > 0) {
511
+ processReplacements(appState, get, fieldSettings, changedKeys, zones, nodes);
512
+ }
513
+ }
514
+ if (storeState === "remodeling" && (rootProps == null ? void 0 : rootProps._version) && (rootProps == null ? void 0 : rootProps._name) && (rootProps == null ? void 0 : rootProps._version) !== (previousRootProps == null ? void 0 : previousRootProps._version)) {
515
+ processVersionChange(rootProps, get, zones, nodes);
1129
516
  }
1130
517
  };
1131
518
 
1132
- // src/puck/lib/builder/builder-config.tsx
1133
- import { jsx as jsx4 } from "react/jsx-runtime";
1134
- var builderConfig = (config, overrides, editingComponent, showVersionFields = true, dependents, customFields) => ({
1135
- root: builderRootConfig(
1136
- config,
1137
- overrides,
1138
- editingComponent,
1139
- showVersionFields,
1140
- customFields
1141
- ),
1142
- components: Object.entries(__spreadValues({}, config.components)).reduce(
1143
- (acc, [name, component]) => {
1144
- const tempComponent = __spreadProps(__spreadValues({}, component), {
1145
- permissions: {
1146
- insert: editingComponent !== name && !(dependents == null ? void 0 : dependents.has(name))
1147
- },
1148
- resolveFields(data, params) {
1149
- return __async(this, null, function* () {
1150
- var _a2;
1151
- let fields = {};
1152
- if (!fields._slot) {
1153
- const slotFields = Object.entries(params.fields).filter(
1154
- ([_, field]) => field.type === "slot"
1155
- );
1156
- if (slotFields.length)
1157
- fields._slot = {
1158
- type: "array",
1159
- label: "Enable Dropdown Slots",
1160
- getItemSummary(item, index) {
1161
- return item.slot || `Slot ${(index || 0) + 1}`;
1162
- },
1163
- arrayFields: {
1164
- slot: {
1165
- type: "select",
1166
- label: "Slot",
1167
- options: [
1168
- { label: "Select a slot", value: "" },
1169
- ...slotFields.filter(
1170
- ([fieldName, field]) => {
1171
- var _a3;
1172
- return field.type === "slot" && !(((_a3 = data.props) == null ? void 0 : _a3._slot) || []).some(
1173
- (s) => s.slot === fieldName
1174
- );
1175
- }
1176
- ).map(([fieldName, field]) => ({
1177
- label: field.label || fieldName,
1178
- value: fieldName
1179
- }))
1180
- ]
1181
- },
1182
- name: {
1183
- type: "text",
1184
- label: "Name",
1185
- placeholder: "Optional Slot Name"
1186
- }
1187
- }
1188
- };
1189
- }
1190
- const defaultFields = component.resolveFields ? yield component.resolveFields(data, params) : component.fields || {};
1191
- if (!fields._map || params.changed._map) {
1192
- const rootProps = getRootProps(params.appState);
1193
- const fromOptions = generateDynamicFieldOptions(
1194
- (rootProps == null ? void 0 : rootProps._fields) || [],
1195
- (rootProps == null ? void 0 : rootProps._fieldSettings) || {},
1196
- customFields
1197
- );
1198
- const toOptionsFields = component.resolveFields && ((_a2 = data.props) == null ? void 0 : _a2._map) ? yield component.resolveFields(
1199
- __spreadProps(__spreadValues({}, data), { props: __spreadProps(__spreadValues({}, data.props), { _map: void 0 }) }),
1200
- params
1201
- ) : defaultFields;
1202
- const toOptions = generateFieldOptions(toOptionsFields);
1203
- fields._map = overrides.map ? {
1204
- type: "custom",
1205
- render: ({ value, onChange, id }) => {
1206
- const rootProps2 = getRootProps(params.appState);
1207
- return overrides.map({
1208
- rootProps: rootProps2,
1209
- value,
1210
- onChange,
1211
- id,
1212
- props: data.props || {},
1213
- fromOptions,
1214
- toOptions
1215
- });
1216
- }
1217
- } : (() => {
1218
- var _a3;
1219
- const mapEntries = ((_a3 = data.props) == null ? void 0 : _a3._map) || [];
1220
- const toPaths = mapEntries.flatMap(
1221
- (entry) => Array.isArray(entry.to) ? entry.to : entry.to ? [entry.to] : []
1222
- );
1223
- const toPath = toPaths.find(
1224
- (path) => typeof path === "string" && isArrayMappingPath(path)
1225
- );
1226
- const arrayBaseName = toPath ? getArrayBasePath(toPath) : null;
1227
- const targetArrayField = arrayBaseName ? defaultFields[arrayBaseName] : null;
1228
- const mappedSubProps = /* @__PURE__ */ new Set();
1229
- if (arrayBaseName) {
1230
- toPaths.forEach((path) => {
1231
- if (typeof path !== "string") return;
1232
- if (getArrayBasePath(path) !== arrayBaseName) return;
1233
- const subProp = getArrayItemSubPath(path);
1234
- if (subProp) mappedSubProps.add(subProp);
1235
- });
1236
- }
1237
- const defaultValueFields = {};
1238
- if (targetArrayField && targetArrayField.type === "array" && targetArrayField.arrayFields) {
1239
- const arrayFields = targetArrayField.arrayFields;
1240
- Object.entries(arrayFields).forEach(([key, fld]) => {
1241
- if (mappedSubProps.has(key)) return;
1242
- if (fld.type === "array" || fld.type === "object" || fld.type === "slot") return;
1243
- defaultValueFields[key] = __spreadProps(__spreadValues({}, fld), { label: fld.label || key });
1244
- });
1245
- }
1246
- const baseArrayFields = {
1247
- from: {
1248
- type: "select",
1249
- label: "From",
1250
- options: [
1251
- { label: "Select a field", value: "" },
1252
- ...fromOptions.map(({ label, value }) => ({
1253
- label,
1254
- value
1255
- }))
1256
- ]
1257
- },
1258
- to: {
1259
- type: "select",
1260
- label: "To",
1261
- options: [
1262
- { label: "Select a field", value: "" },
1263
- ...toOptions.map(({ label, value }) => ({
1264
- label,
1265
- value
1266
- }))
1267
- ]
1268
- }
1269
- };
1270
- if (arrayBaseName && Object.keys(defaultValueFields).length > 0) {
1271
- baseArrayFields.unmappedArrayItemDefaultValues = {
1272
- type: "object",
1273
- label: "Default Item Values",
1274
- objectFields: defaultValueFields
1275
- };
1276
- }
1277
- return {
1278
- type: "array",
1279
- label: "Dynamic Field Map",
1280
- arrayFields: baseArrayFields
1281
- };
1282
- })();
1283
- }
1284
- fields = __spreadValues(__spreadValues({}, fields), defaultFields);
1285
- return fields;
1286
- });
1287
- },
1288
- resolveData: ({ props }, { lastData }) => {
1289
- const _map = (props._map || []).map((item) => {
1290
- const newItem = __spreadValues({}, item);
1291
- if (typeof newItem.unmappedArrayItemDefaultValues === "string") {
1292
- try {
1293
- newItem.unmappedArrayItemDefaultValues = JSON.parse(
1294
- newItem.unmappedArrayItemDefaultValues
1295
- );
1296
- } catch (e) {
1297
- newItem.unmappedArrayItemDefaultValues = {};
1298
- }
1299
- } else if (!newItem.unmappedArrayItemDefaultValues) {
1300
- newItem.unmappedArrayItemDefaultValues = {};
1301
- }
1302
- return newItem;
1303
- });
1304
- const readOnlyFields = _map.flatMap((item) => item.to);
1305
- const readOnlyArrayBases = readOnlyFields.filter((field) => typeof field === "string").map(getArrayBasePath).filter((base) => base !== null);
1306
- if (_map.length) {
1307
- return {
1308
- props: __spreadProps(__spreadValues({}, props), { _map }),
1309
- readOnly: [
1310
- ...readOnlyFields.map((f) => String(f)),
1311
- ...readOnlyArrayBases
1312
- ].reduce(
1313
- (acc2, field) => __spreadProps(__spreadValues({}, acc2), { [field]: true }),
1314
- {}
1315
- )
1316
- };
1317
- }
1318
- return {
1319
- props: __spreadProps(__spreadValues({}, props), { _map }),
1320
- readOnly: {}
1321
- };
1322
- },
1323
- render: (props) => {
1324
- return /* @__PURE__ */ jsx4(ErrorBoundary, { children: component.render(props) });
1325
- }
1326
- });
1327
- acc[name] = tempComponent;
1328
- return acc;
1329
- },
1330
- {}
1331
- ),
1332
- categories: config.categories || {}
1333
- });
519
+ // src/puck/store/slices/builder.tsx
520
+ import {
521
+ walkTree as walkTree2
522
+ } from "@measured/puck";
1334
523
 
1335
524
  // src/puck/lib/soft-component-constants.ts
1336
525
  var TECHNICAL_KEYS = /* @__PURE__ */ new Set(["_map", "_slot", "id", "_version"]);
@@ -1354,6 +543,72 @@ var sanitizeComponent = (component, allowedTypes) => {
1354
543
  });
1355
544
  };
1356
545
 
546
+ // src/puck/lib/custom-fields.ts
547
+ var builtInSoftFieldTypes = /* @__PURE__ */ new Set([
548
+ "text",
549
+ "textarea",
550
+ "number",
551
+ "select",
552
+ "radio",
553
+ "array",
554
+ "object",
555
+ "reference"
556
+ ]);
557
+ var warnedMessages = /* @__PURE__ */ new Set();
558
+ var warnOnce = (message) => {
559
+ if (warnedMessages.has(message)) {
560
+ return;
561
+ }
562
+ warnedMessages.add(message);
563
+ console.warn(message);
564
+ };
565
+ var isBuiltInSoftFieldType = (fieldType) => {
566
+ return builtInSoftFieldTypes.has(fieldType);
567
+ };
568
+ var resolveCustomFieldDefinition = (fieldType, customFields) => {
569
+ if (isBuiltInSoftFieldType(fieldType)) {
570
+ return void 0;
571
+ }
572
+ return customFields == null ? void 0 : customFields[fieldType];
573
+ };
574
+ var resolveCustomFieldReturnType = (fieldType, customFields) => {
575
+ const customField = resolveCustomFieldDefinition(fieldType, customFields);
576
+ if (!customField) {
577
+ return null;
578
+ }
579
+ if (!customField.returnType) {
580
+ warnOnce(
581
+ `[soft-config] Custom field "${fieldType}" is missing a required returnType and will be skipped from mapping options.`
582
+ );
583
+ return null;
584
+ }
585
+ return customField.returnType;
586
+ };
587
+ var resolveCustomFieldSchema = (fieldType, customFields) => {
588
+ const customField = resolveCustomFieldDefinition(fieldType, customFields);
589
+ if (!customField) {
590
+ return null;
591
+ }
592
+ const returnType = resolveCustomFieldReturnType(fieldType, customFields);
593
+ if (!returnType) {
594
+ return null;
595
+ }
596
+ if (returnType !== "array" && returnType !== "object") {
597
+ return null;
598
+ }
599
+ const subFields = customField.subFields || [];
600
+ if (!subFields.length) {
601
+ warnOnce(
602
+ `[soft-config] Custom field "${fieldType}" returns ${returnType} but does not define subFields. It will be skipped from mapping options.`
603
+ );
604
+ return null;
605
+ }
606
+ return {
607
+ subFields,
608
+ subFieldSettings: customField.subFieldSettings || {}
609
+ };
610
+ };
611
+
1357
612
  // src/puck/lib/soft-component-from-appstate.ts
1358
613
  var getSubComponents = (content, componentConfigs, fieldSettings, slots) => {
1359
614
  if (!content || !Array.isArray(content)) return [];
@@ -1509,8 +764,8 @@ var softComponentFromAppState = (appState, configComponents, editedItem, metadat
1509
764
  var _a;
1510
765
  const rootProps = ((_a = appState.data.root) == null ? void 0 : _a.props) || {};
1511
766
  const fields = rootProps._fields || [];
1512
- const field_settings = rootProps._fieldSettings || {};
1513
- const normalizedFieldSettings = __spreadValues({}, field_settings);
767
+ const fieldSettings = rootProps._fieldSettings || {};
768
+ const normalizedFieldSettings = __spreadValues({}, fieldSettings);
1514
769
  (fields || []).forEach((field) => {
1515
770
  const customFieldDefinition = resolveCustomFieldDefinition(
1516
771
  field.type,
@@ -1836,12 +1091,100 @@ var rootZone = "default-zone";
1836
1091
  var rootDroppableId = `${rootAreaId}:${rootZone}`;
1837
1092
 
1838
1093
  // src/puck/components/soft-render/index.tsx
1839
- import React3, { useMemo, memo } from "react";
1840
- import equal3 from "react-fast-compare";
1841
- import { Fragment as Fragment2, jsx as jsx5 } from "react/jsx-runtime";
1094
+ import React2, { useMemo, memo } from "react";
1095
+ import equal2 from "react-fast-compare";
1096
+
1097
+ // src/puck/components/error-boundary/index.tsx
1098
+ import { Component } from "react";
1099
+
1100
+ // src/puck/lib/get-class-name-factory.ts
1101
+ import classnames from "classnames";
1102
+ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
1103
+ if (typeof options === "string") {
1104
+ const descendant = options;
1105
+ const style = styles[`${rootClass}-${descendant}`];
1106
+ if (style) {
1107
+ return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
1108
+ }
1109
+ return "";
1110
+ } else if (typeof options === "object") {
1111
+ const modifiers = options;
1112
+ const prefixedModifiers = {};
1113
+ for (let modifier in modifiers) {
1114
+ prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
1115
+ }
1116
+ const c = styles[rootClass];
1117
+ return config.baseClass + classnames(__spreadValues({
1118
+ [c]: !!c
1119
+ }, prefixedModifiers));
1120
+ } else {
1121
+ return config.baseClass + styles[rootClass] || "";
1122
+ }
1123
+ };
1124
+ var get_class_name_factory_default = getClassNameFactory;
1125
+
1126
+ // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/error-boundary/styles.module.css#css-module
1127
+ var styles_module_default = { "ErrorBoundary": "_ErrorBoundary_1xl05_5", "ErrorBoundary-title": "_ErrorBoundary-title_1xl05_21", "ErrorBoundary-details": "_ErrorBoundary-details_1xl05_31", "ErrorBoundary-button": "_ErrorBoundary-button_1xl05_39" };
1128
+
1129
+ // src/puck/components/error-boundary/index.tsx
1130
+ import { jsx, jsxs } from "react/jsx-runtime";
1131
+ var getClassName = get_class_name_factory_default("ErrorBoundary", styles_module_default);
1132
+ var ErrorBoundary = class extends Component {
1133
+ constructor(props) {
1134
+ super(props);
1135
+ this.resetError = () => {
1136
+ this.setState({
1137
+ hasError: false,
1138
+ error: null
1139
+ });
1140
+ };
1141
+ this.state = {
1142
+ hasError: false,
1143
+ error: null
1144
+ };
1145
+ }
1146
+ static getDerivedStateFromError(error) {
1147
+ return {
1148
+ hasError: true,
1149
+ error
1150
+ };
1151
+ }
1152
+ componentDidCatch(error, errorInfo) {
1153
+ console.error("Error caught by ErrorBoundary:", error, errorInfo);
1154
+ }
1155
+ render() {
1156
+ if (this.state.hasError) {
1157
+ if (typeof this.props.fallback === "function") {
1158
+ return this.props.fallback(this.state.error, this.resetError);
1159
+ }
1160
+ if (this.props.fallback) {
1161
+ return this.props.fallback;
1162
+ }
1163
+ return /* @__PURE__ */ jsxs("div", { className: getClassName(), children: [
1164
+ /* @__PURE__ */ jsx("h3", { className: getClassName("title"), children: "Component Error" }),
1165
+ /* @__PURE__ */ jsxs("details", { className: getClassName("details"), children: [
1166
+ /* @__PURE__ */ jsx("summary", { children: "Show error details" }),
1167
+ this.state.error && this.state.error.toString()
1168
+ ] }),
1169
+ /* @__PURE__ */ jsx(
1170
+ "button",
1171
+ {
1172
+ onClick: this.resetError,
1173
+ className: getClassName("button"),
1174
+ children: "Try Again"
1175
+ }
1176
+ )
1177
+ ] });
1178
+ }
1179
+ return this.props.children;
1180
+ }
1181
+ };
1182
+
1183
+ // src/puck/components/soft-render/index.tsx
1184
+ import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
1842
1185
  function isPlainObject(val) {
1843
1186
  if (typeof val !== "object" || val === null) return false;
1844
- if (React3.isValidElement(val)) return false;
1187
+ if (React2.isValidElement(val)) return false;
1845
1188
  if ("$$typeof" in val) return false;
1846
1189
  const proto = Object.getPrototypeOf(val);
1847
1190
  return proto === Object.prototype || proto === null;
@@ -1849,12 +1192,27 @@ function isPlainObject(val) {
1849
1192
  function cloneData(value) {
1850
1193
  if (value === null || value === void 0) return value;
1851
1194
  if (typeof value === "function") return value;
1852
- if (Array.isArray(value)) return value.map(cloneData);
1195
+ if (Array.isArray(value))
1196
+ return value.map(cloneData);
1853
1197
  if (!isPlainObject(value)) return value;
1854
1198
  return Object.fromEntries(
1855
1199
  Object.entries(value).map(([k, v]) => [k, cloneData(v)])
1856
1200
  );
1857
1201
  }
1202
+ function shallowEqual(objA, objB) {
1203
+ if (Object.is(objA, objB)) return true;
1204
+ if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null)
1205
+ return false;
1206
+ const keysA = Object.keys(objA);
1207
+ const keysB = Object.keys(objB);
1208
+ if (keysA.length !== keysB.length) return false;
1209
+ for (let i = 0; i < keysA.length; i++) {
1210
+ if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
1211
+ return false;
1212
+ }
1213
+ }
1214
+ return true;
1215
+ }
1858
1216
  var SubComponentRenderer = memo(
1859
1217
  ({
1860
1218
  subComponent,
@@ -1906,7 +1264,7 @@ var SubComponentRenderer = memo(
1906
1264
  style
1907
1265
  }) => {
1908
1266
  var _a3, _b2;
1909
- return /* @__PURE__ */ jsx5("div", { className, style, children: /* @__PURE__ */ jsx5(
1267
+ return /* @__PURE__ */ jsx2("div", { className, style, children: /* @__PURE__ */ jsx2(
1910
1268
  SoftRender,
1911
1269
  {
1912
1270
  softComponentFields,
@@ -1933,7 +1291,7 @@ var SubComponentRenderer = memo(
1933
1291
  ]);
1934
1292
  if (!componentConfig) return null;
1935
1293
  const ComponentRender = componentConfig.render;
1936
- return /* @__PURE__ */ jsx5(ErrorBoundary, { children: /* @__PURE__ */ jsx5(
1294
+ return /* @__PURE__ */ jsx2(ErrorBoundary, { children: /* @__PURE__ */ jsx2(
1937
1295
  ComponentRender,
1938
1296
  __spreadValues({
1939
1297
  id: stableId,
@@ -1942,14 +1300,11 @@ var SubComponentRenderer = memo(
1942
1300
  }, finalProps)
1943
1301
  ) });
1944
1302
  },
1945
- // Custom comparator for SubComponentRenderer.
1946
- //
1947
- // Uses deep equality on subComponent (it may be a new reference even when
1948
- // semantically unchanged if the parent SoftRender array is reconstructed)
1949
- // and on props (the primary driver of field-mapping changes).
1950
- // configComponents and softComponentFields are treated as stable config
1951
- // references — reference equality is intentional and fast here.
1952
- (prev, next) => prev.depth === next.depth && prev.index === next.index && prev.configComponents === next.configComponents && prev.softComponentFields === next.softComponentFields && equal3(prev.props, next.props) && equal3(prev.subComponent, next.subComponent) && equal3(prev.softComponentFieldSettings, next.softComponentFieldSettings)
1303
+ (prev, next) => prev.depth === next.depth && prev.index === next.index && prev.configComponents === next.configComponents && prev.softComponentFields === next.softComponentFields && // Shallow compare: props may contain functions/React nodes; deep equality
1304
+ // would risk retaining stale closures and is unnecessarily expensive here.
1305
+ shallowEqual(prev.props, next.props) && // Deep compare: subComponent and fieldSettings are plain JSON configuration
1306
+ // objects with no functions, so structural equality is safe and correct.
1307
+ equal2(prev.subComponent, next.subComponent) && equal2(prev.softComponentFieldSettings, next.softComponentFieldSettings)
1953
1308
  );
1954
1309
  SubComponentRenderer.displayName = "SubComponentRenderer";
1955
1310
  var SoftRender = memo(
@@ -1962,9 +1317,9 @@ var SoftRender = memo(
1962
1317
  depth = 0
1963
1318
  }) => {
1964
1319
  if (!(softSubComponent == null ? void 0 : softSubComponent.length)) return null;
1965
- return /* @__PURE__ */ jsx5(Fragment2, { children: softSubComponent.map((subComponent, index) => {
1320
+ return /* @__PURE__ */ jsx2(Fragment, { children: softSubComponent.map((subComponent, index) => {
1966
1321
  var _a;
1967
- return /* @__PURE__ */ jsx5(
1322
+ return /* @__PURE__ */ jsx2(
1968
1323
  SubComponentRenderer,
1969
1324
  {
1970
1325
  subComponent,
@@ -1979,16 +1334,14 @@ var SoftRender = memo(
1979
1334
  );
1980
1335
  }) });
1981
1336
  },
1982
- // Covers all five props not just `props` and `softSubComponent`.
1983
- // configComponents / softComponentFields: reference equality (stable config).
1984
- // softComponentFieldSettings: deep equality (may carry dynamic defaults).
1985
- // props / softSubComponent: deep equality (primary render drivers).
1986
- (prev, next) => prev.configComponents === next.configComponents && prev.softComponentFields === next.softComponentFields && equal3(prev.props, next.props) && equal3(prev.softSubComponent, next.softSubComponent) && equal3(prev.softComponentFieldSettings, next.softComponentFieldSettings)
1337
+ (prev, next) => prev.configComponents === next.configComponents && prev.softComponentFields === next.softComponentFields && // Shallow compare: props may contain functions/React nodes; see shallowEqual.
1338
+ shallowEqual(prev.props, next.props) && // Deep compare: softSubComponent and fieldSettings are plain JSON schemas.
1339
+ equal2(prev.softSubComponent, next.softSubComponent) && equal2(prev.softComponentFieldSettings, next.softComponentFieldSettings)
1987
1340
  );
1988
1341
  SoftRender.displayName = "SoftRender";
1989
1342
 
1990
1343
  // src/puck/lib/create-versioned-component-config.tsx
1991
- import { jsx as jsx6 } from "react/jsx-runtime";
1344
+ import { jsx as jsx3 } from "react/jsx-runtime";
1992
1345
  var hydrateCustomField = (fieldName, field, fieldSettings, customFields) => {
1993
1346
  var _a;
1994
1347
  if (field.type !== "custom") {
@@ -2046,7 +1399,7 @@ var createVersionedComponentConfig = (componentName, displayName, version, allVe
2046
1399
  var _a2;
2047
1400
  const selectedVersion = props.version || version;
2048
1401
  const versionedComponent = (_a2 = softComponents[componentName]) == null ? void 0 : _a2.versions[selectedVersion];
2049
- return /* @__PURE__ */ jsx6(
1402
+ return /* @__PURE__ */ jsx3(
2050
1403
  SoftRender,
2051
1404
  {
2052
1405
  softComponentFields: versionedComponent.fields,
@@ -2061,7 +1414,7 @@ var createVersionedComponentConfig = (componentName, displayName, version, allVe
2061
1414
  };
2062
1415
 
2063
1416
  // src/puck/lib/builder/sub-component-decomposer.tsx
2064
- var subComponentDecomposer = (componentRootData, softSubComponent) => {
1417
+ var subComponentDecomposer = (componentRootData, softSubComponent, keepMapField) => {
2065
1418
  var _a;
2066
1419
  const resolvedProps = __spreadValues({}, softSubComponent.fixedProps);
2067
1420
  (_a = softSubComponent.map) == null ? void 0 : _a.forEach((mapItem) => {
@@ -2084,21 +1437,21 @@ var subComponentDecomposer = (componentRootData, softSubComponent) => {
2084
1437
  Object.entries(softSubComponent.components).forEach(
2085
1438
  ([slotKey, subComponents]) => {
2086
1439
  resolvedProps[slotKey] = subComponents.map(
2087
- (subComponent) => subComponentDecomposer(componentRootData, subComponent)
1440
+ (subComponent) => subComponentDecomposer(componentRootData, subComponent, keepMapField)
2088
1441
  );
2089
1442
  }
2090
1443
  );
2091
1444
  const accItem = {
2092
1445
  type: softSubComponent.type,
2093
- props: __spreadProps(__spreadValues({}, resolvedProps), {
1446
+ props: __spreadValues(__spreadProps(__spreadValues({}, resolvedProps), {
2094
1447
  id: generateId(softSubComponent.type)
2095
- })
1448
+ }), keepMapField ? { _map: softSubComponent.map } : {})
2096
1449
  };
2097
1450
  return accItem;
2098
1451
  };
2099
1452
 
2100
1453
  // src/puck/lib/builder/resolve-soft-component-data.ts
2101
- var resolveSoftComponentData = (props, _fieldSettings = {}) => {
1454
+ var resolveSoftComponentData = (props, _fieldSettings = {}, keepMapField) => {
2102
1455
  const map = props._map;
2103
1456
  if (!(map == null ? void 0 : map.length)) return __spreadValues({}, props);
2104
1457
  const { newProps } = applyMapping(
@@ -2107,11 +1460,16 @@ var resolveSoftComponentData = (props, _fieldSettings = {}) => {
2107
1460
  map,
2108
1461
  "propsFirst"
2109
1462
  );
1463
+ if (keepMapField) {
1464
+ return __spreadProps(__spreadValues({}, newProps), {
1465
+ _map: map
1466
+ });
1467
+ }
2110
1468
  return newProps;
2111
1469
  };
2112
1470
 
2113
1471
  // src/puck/lib/decompose-soft-component.ts
2114
- function decomposeSoftComponent(componentData, softComponents, fieldSettings) {
1472
+ function decomposeSoftComponent(componentData, softComponents, fieldSettings, keepMapField) {
2115
1473
  var _a, _b, _c, _d;
2116
1474
  if (!(componentData == null ? void 0 : componentData.type) || !(componentData == null ? void 0 : componentData.props.id)) {
2117
1475
  throw new Error("Component data must have type and id to decompose.");
@@ -2135,7 +1493,11 @@ function decomposeSoftComponent(componentData, softComponents, fieldSettings) {
2135
1493
  }
2136
1494
  const decomposedComponentData = softComponent.components.map(
2137
1495
  (softSubComponent) => {
2138
- return subComponentDecomposer(resolvedComponentData, softSubComponent);
1496
+ return subComponentDecomposer(
1497
+ resolvedComponentData,
1498
+ softSubComponent,
1499
+ keepMapField
1500
+ );
2139
1501
  }
2140
1502
  );
2141
1503
  return decomposedComponentData;
@@ -2145,9 +1507,9 @@ function isSoftComponent(componentType, softComponents) {
2145
1507
  }
2146
1508
 
2147
1509
  // src/puck/lib/demolish-soft-component.ts
2148
- import { walkTree as walkTree2 } from "@measured/puck";
1510
+ import { walkTree } from "@measured/puck";
2149
1511
  function demolishSoftComponent(componentName, data, config, softComponents) {
2150
- const resolvedData = walkTree2(data, config, (components) => {
1512
+ const resolvedData = walkTree(data, config, (components) => {
2151
1513
  components.forEach((componentData, index) => {
2152
1514
  if (componentData.type === componentName) {
2153
1515
  const decomposed = decomposeSoftComponent(componentData, softComponents);
@@ -2234,24 +1596,15 @@ var clearEditVisibility = (doc) => {
2234
1596
  };
2235
1597
 
2236
1598
  // src/puck/store/slices/builder.tsx
2237
- var createBuildersSlice = (set, get, initialConfig) => ({
1599
+ var createBuildersSlice = (set, get) => ({
2238
1600
  build: (history, selectedItem, itemSelector, puckDispatch, name) => {
2239
1601
  if (!selectedItem || !itemSelector) {
2240
1602
  throw new Error("No item selected to build from.");
2241
1603
  }
2242
- const config = __spreadValues({}, get().softConfig);
2243
- const overrides = get().overrides;
2244
- const buildConfig = builderConfig(
2245
- config,
2246
- overrides,
2247
- void 0,
2248
- get().showVersionFields,
2249
- void 0,
2250
- get().customFields
2251
- );
1604
+ const config = get().softConfig;
2252
1605
  const editableIds = /* @__PURE__ */ new Set([selectedItem.props.id]);
2253
1606
  const initialContent = [__spreadValues({}, selectedItem)];
2254
- walkTree3(
1607
+ walkTree2(
2255
1608
  {
2256
1609
  root: {},
2257
1610
  content: initialContent
@@ -2271,8 +1624,6 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2271
1624
  })
2272
1625
  );
2273
1626
  set((s) => __spreadProps(__spreadValues({}, s), {
2274
- softConfig: buildConfig,
2275
- storedConfig: config,
2276
1627
  originalHistory: history,
2277
1628
  itemSelector: {
2278
1629
  index: itemSelector.index,
@@ -2282,28 +1633,24 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2282
1633
  editableComponentIds: editableIds,
2283
1634
  state: "building"
2284
1635
  }));
2285
- requestAnimationFrame(
2286
- () => puckDispatch({
2287
- type: "set",
2288
- state: (previous) => {
2289
- var _a;
2290
- return {
2291
- ui: __spreadProps(__spreadValues({}, previous.ui), {
2292
- itemSelector: null
2293
- }),
2294
- data: __spreadProps(__spreadValues({}, previous.data), {
2295
- root: __spreadProps(__spreadValues({}, previous.data.root), {
2296
- props: __spreadProps(__spreadValues({}, (_a = previous.data.root) == null ? void 0 : _a.props), {
2297
- _name: name || "New Soft Component"
2298
- })
2299
- })
2300
- })
2301
- };
2302
- }
2303
- })
2304
- );
1636
+ requestAnimationFrame(() => {
1637
+ puckDispatch({
1638
+ type: "setUi",
1639
+ ui: { itemSelector: null },
1640
+ recordHistory: false
1641
+ });
1642
+ puckDispatch({
1643
+ type: "replaceRoot",
1644
+ root: {
1645
+ props: {
1646
+ _name: name || "New Soft Component"
1647
+ }
1648
+ },
1649
+ recordHistory: false
1650
+ });
1651
+ });
2305
1652
  },
2306
- remodel: (history, selectedItem, itemSelector, puckDispatch) => {
1653
+ remodel: (history, selectedItem, itemSelector, puckDispatch, refreshPermission) => {
2307
1654
  var _a, _b;
2308
1655
  if (!selectedItem || !itemSelector) {
2309
1656
  throw new Error("No item selected to build from.");
@@ -2323,7 +1670,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2323
1670
  `Soft component "${softComponentName}" with version "${softComponentVersion}" not found.`
2324
1671
  );
2325
1672
  }
2326
- const { root, content } = softComponentToAppState(
1673
+ const { root } = softComponentToAppState(
2327
1674
  softComponent,
2328
1675
  softComponentName,
2329
1676
  softComponentVersion,
@@ -2335,91 +1682,104 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2335
1682
  softComponentMeta == null ? void 0 : softComponentMeta.category,
2336
1683
  get().customFields
2337
1684
  );
2338
- const config = __spreadValues({}, get().softConfig);
2339
- const overrides = get().overrides;
1685
+ const config = get().softConfig;
2340
1686
  const dependents = get().dependencyGraph.get(softComponentName) || /* @__PURE__ */ new Set();
2341
- const buildConfig = builderConfig(
2342
- config,
2343
- overrides,
2344
- softComponentName,
2345
- get().showVersionFields,
2346
- dependents,
2347
- get().customFields
2348
- );
2349
- const editableIds = /* @__PURE__ */ new Set([]);
2350
- const decomposedComponents = get().builder.decompose(selectedItem);
2351
- walkTree3(
2352
- { root: {}, content: decomposedComponents || [] },
1687
+ const decomposedComponents = get().builder.decompose(selectedItem, true);
1688
+ const editableIds = /* @__PURE__ */ new Set([decomposedComponents[0].props.id]);
1689
+ const { content: decomposedComponentsWithId } = walkTree2(
1690
+ { root: {}, content: decomposedComponents },
2353
1691
  { components: config.components },
2354
1692
  (components) => {
2355
- components.forEach((comp) => {
2356
- editableIds.add(comp.props.id);
1693
+ components.forEach((comp2) => {
1694
+ const id2 = generateId(comp2.type);
1695
+ comp2.props.id = id2;
1696
+ editableIds.add(id2);
2357
1697
  });
2358
1698
  return components;
2359
1699
  }
2360
1700
  );
2361
- requestAnimationFrame(() => {
2362
- puckDispatch({
2363
- type: "set",
2364
- state: (previous) => ({
2365
- data: {
2366
- root: __spreadProps(__spreadValues({}, root), { _versions: versions }),
2367
- content: walkTree3(
2368
- __spreadValues({}, previous.data),
2369
- __spreadValues({}, config),
2370
- (components) => {
2371
- const next = components.map((component) => __spreadProps(__spreadValues({}, component), {
2372
- props: __spreadValues({}, component.props)
2373
- }));
2374
- const index = next.findIndex(
2375
- (component) => component.props.id === selectedItem.props.id
2376
- );
2377
- if (index !== -1) {
2378
- next.splice(
2379
- index,
2380
- 1,
2381
- ...decomposedComponents.map((component) => __spreadProps(__spreadValues({}, component), {
2382
- props: __spreadValues({}, component.props)
2383
- }))
2384
- );
2385
- }
2386
- return next;
2387
- }
2388
- ).content
2389
- },
2390
- ui: __spreadProps(__spreadValues({}, previous.ui), {
2391
- itemSelector: null
2392
- })
2393
- })
2394
- });
2395
- setEditVisibility(get().iframeDoc, {
2396
- mode: "remodel",
2397
- editableIds
2398
- });
2399
- });
2400
1701
  set((s) => __spreadProps(__spreadValues({}, s), {
2401
- storedConfig: config,
2402
- softConfig: buildConfig,
2403
1702
  originalHistory: history,
2404
1703
  itemSelector: {
2405
1704
  index: itemSelector.index,
2406
1705
  zone: itemSelector.zone || rootDroppableId
2407
1706
  },
2408
- editingComponentId: selectedItem.props.id,
2409
1707
  editingComponent: softComponentName,
1708
+ editingDependents: dependents,
2410
1709
  editableComponentIds: editableIds,
2411
- state: "remodeling"
1710
+ state: "assessing"
2412
1711
  }));
2413
- requestAnimationFrame(
2414
- () => puckDispatch({
2415
- type: "replaceRoot",
2416
- root: {
2417
- title: root.props.title,
2418
- _name: root.props._name,
1712
+ puckDispatch({
1713
+ type: "remove",
1714
+ index: itemSelector.index,
1715
+ zone: itemSelector.zone || rootDroppableId,
1716
+ recordHistory: false
1717
+ });
1718
+ const comp = decomposedComponentsWithId[0];
1719
+ if (!comp) {
1720
+ throw new Error("No decomposed components found.");
1721
+ }
1722
+ const id = comp.props.id;
1723
+ puckDispatch({
1724
+ type: "insert",
1725
+ destinationIndex: itemSelector.index,
1726
+ destinationZone: itemSelector.zone || rootDroppableId,
1727
+ componentType: comp.type,
1728
+ recordHistory: false,
1729
+ id
1730
+ });
1731
+ requestAnimationFrame(() => {
1732
+ var _a2;
1733
+ const _map = ((_a2 = comp.props) == null ? void 0 : _a2._map) || [];
1734
+ const readOnlyFields = _map.flatMap((item) => item.to);
1735
+ const readOnlyArrayBases = readOnlyFields.filter((field) => typeof field === "string").map(getArrayBasePath).filter((base) => base !== null);
1736
+ const readOnly = [
1737
+ ...readOnlyFields.map((f) => String(f)),
1738
+ ...readOnlyArrayBases
1739
+ ].reduce((acc, field) => __spreadProps(__spreadValues({}, acc), { [field]: true }), {});
1740
+ puckDispatch({
1741
+ type: "replace",
1742
+ destinationIndex: itemSelector.index,
1743
+ destinationZone: itemSelector.zone || rootDroppableId,
1744
+ data: __spreadProps(__spreadValues({}, comp), {
1745
+ props: __spreadProps(__spreadValues({}, comp.props), {
1746
+ id
1747
+ }),
1748
+ readOnly
1749
+ }),
1750
+ recordHistory: false
1751
+ });
1752
+ set((s) => __spreadProps(__spreadValues({}, s), {
1753
+ state: "remodeling"
1754
+ }));
1755
+ setEditVisibility(get().iframeDoc, {
1756
+ mode: "remodel",
1757
+ editableIds: new Set(editableIds)
1758
+ });
1759
+ });
1760
+ puckDispatch({
1761
+ type: "replaceRoot",
1762
+ root: {
1763
+ props: __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, root.props), root.props.title !== void 0 && {
1764
+ title: root.props.title
1765
+ }), root.props._name !== void 0 && {
1766
+ _name: root.props._name
1767
+ }), root.props._category !== void 0 && {
2419
1768
  _category: root.props._category
2420
- }
2421
- })
2422
- );
1769
+ }), {
1770
+ _versions: versions
1771
+ })
1772
+ },
1773
+ recordHistory: false
1774
+ });
1775
+ requestAnimationFrame(() => {
1776
+ puckDispatch({
1777
+ type: "setUi",
1778
+ ui: { itemSelector: null },
1779
+ recordHistory: false
1780
+ });
1781
+ refreshPermission();
1782
+ });
2423
1783
  },
2424
1784
  complete: (appState, setHistories, getItemBySelector) => {
2425
1785
  var _a, _b, _c, _d, _e, _f, _g;
@@ -2459,7 +1819,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2459
1819
  }
2460
1820
  const storedHistories = get().originalHistory;
2461
1821
  setHistories([...storedHistories]);
2462
- const config = __spreadValues({}, get().softConfig || initialConfig);
1822
+ const config = __spreadValues({}, get().softConfig);
2463
1823
  const mapComponentConfig = get().overrides.mapComponentConfig;
2464
1824
  const newSoftComponentConfig = mapComponentConfig ? mapComponentConfig(componentName, defaultSoftComponentConfig, rootProps) : defaultSoftComponentConfig;
2465
1825
  set((s) => {
@@ -2497,11 +1857,9 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2497
1857
  }) : categories;
2498
1858
  return __spreadProps(__spreadValues({}, s), {
2499
1859
  softConfig: __spreadProps(__spreadValues({}, config), {
2500
- root: __spreadValues({}, initialConfig.root),
2501
1860
  components: nextComponents,
2502
1861
  categories: nextCategories
2503
1862
  }),
2504
- storedConfig: void 0,
2505
1863
  state: "inspecting",
2506
1864
  // Temporarily shift state to inspect() before finalizing back to ready
2507
1865
  originalHistory: []
@@ -2523,7 +1881,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2523
1881
  softComponent: completedSoftComponent
2524
1882
  };
2525
1883
  },
2526
- inspect: (componentName, puckDispatch) => {
1884
+ inspect: (componentName, puckDispatch, selectedItemSelector) => {
2527
1885
  if (get().state !== "inspecting") {
2528
1886
  throw new Error("Not in inspecting state.");
2529
1887
  }
@@ -2532,59 +1890,72 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2532
1890
  throw new Error("No selector found for last item.");
2533
1891
  }
2534
1892
  const editableComponentId = get().editingComponentId;
1893
+ const itemSelector = get().itemSelector;
2535
1894
  requestAnimationFrame(() => {
2536
- const config = get().softConfig;
2537
- const newComponent = config.components[componentName];
2538
- const reconstructedTree = (data) => walkTree3(data, config, (components) => {
2539
- return components.map((comp) => {
2540
- if (comp.props.id === editableComponentId) {
2541
- return {
2542
- type: componentName,
2543
- props: __spreadProps(__spreadValues({}, newComponent.defaultProps), {
2544
- id: generateId(componentName)
2545
- })
2546
- };
2547
- }
2548
- return comp;
1895
+ var _a;
1896
+ if (editableComponentId && !Object.keys(get().softComponents).includes(
1897
+ (_a = editableComponentId == null ? void 0 : editableComponentId.split(":")) == null ? void 0 : _a[0].split("-")[0]
1898
+ )) {
1899
+ requestAnimationFrame(() => {
1900
+ puckDispatch({
1901
+ type: "remove",
1902
+ index: itemSelector.index,
1903
+ zone: itemSelector.zone,
1904
+ recordHistory: true
1905
+ });
1906
+ puckDispatch({
1907
+ type: "insert",
1908
+ destinationIndex: itemSelector.index,
1909
+ destinationZone: itemSelector.zone,
1910
+ componentType: componentName,
1911
+ recordHistory: true
1912
+ });
2549
1913
  });
2550
- });
2551
- puckDispatch({
2552
- type: "setData",
2553
- data: (data) => {
2554
- return reconstructedTree(data);
2555
- },
2556
- recordHistory: true
2557
- // Record this swap on the standard undo/redo stack
2558
- });
1914
+ }
2559
1915
  clearEditVisibility(get().iframeDoc);
1916
+ if (!selectedItemSelector && selector.index !== void 0) {
1917
+ puckDispatch({
1918
+ type: "setUi",
1919
+ ui: { itemSelector: selector },
1920
+ recordHistory: false
1921
+ });
1922
+ }
2560
1923
  set((s) => __spreadProps(__spreadValues({}, s), {
2561
1924
  state: "ready",
2562
1925
  setItemSelector: void 0,
2563
1926
  setOriginalItem: void 0,
1927
+ itemSelector: null,
2564
1928
  editingComponent: null,
2565
1929
  editingComponentId: null,
2566
1930
  editableComponentIds: /* @__PURE__ */ new Set()
2567
1931
  }));
2568
1932
  });
2569
1933
  },
2570
- cancel: (setHistories) => {
1934
+ cancel: (setHistories, puckDispatch, selectedItemSelector) => {
2571
1935
  const storedHistories = get().originalHistory;
1936
+ const itemSelector = get().itemSelector;
2572
1937
  set((s) => __spreadProps(__spreadValues({}, s), {
2573
1938
  state: "cancelling"
2574
1939
  }));
2575
1940
  setHistories([...storedHistories]);
2576
1941
  requestAnimationFrame(() => {
2577
1942
  clearEditVisibility(get().iframeDoc);
1943
+ if (!selectedItemSelector && itemSelector) {
1944
+ puckDispatch({
1945
+ type: "setUi",
1946
+ ui: { itemSelector },
1947
+ recordHistory: false
1948
+ });
1949
+ }
2578
1950
  set((s) => __spreadProps(__spreadValues({}, s), {
2579
- softConfig: get().storedConfig || initialConfig,
2580
- storedConfig: void 0,
2581
1951
  originalHistory: [],
2582
1952
  itemSelector: null,
2583
1953
  originalItem: null,
2584
1954
  state: "ready",
2585
1955
  editingComponent: null,
2586
1956
  editingComponentId: null,
2587
- editableComponentIds: /* @__PURE__ */ new Set()
1957
+ editableComponentIds: /* @__PURE__ */ new Set(),
1958
+ editingDependents: /* @__PURE__ */ new Set()
2588
1959
  }));
2589
1960
  });
2590
1961
  },
@@ -2631,11 +2002,16 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2631
2002
  get().setSoftComponent(componentName, version, softComponent);
2632
2003
  return [newSoftComponentConfig, version];
2633
2004
  },
2634
- decompose: (componentData) => {
2005
+ decompose: (componentData, keepMapField) => {
2635
2006
  if (!(componentData == null ? void 0 : componentData.type) || !(componentData == null ? void 0 : componentData.props.id)) {
2636
2007
  throw new Error("Component data must have type and id to decompose.");
2637
2008
  }
2638
- return decomposeSoftComponent(componentData, get().softComponents);
2009
+ return decomposeSoftComponent(
2010
+ componentData,
2011
+ get().softComponents,
2012
+ void 0,
2013
+ keepMapField
2014
+ );
2639
2015
  },
2640
2016
  demolish: (componentName, data, puckDispatch) => {
2641
2017
  if (get().state !== "ready") {
@@ -2656,7 +2032,7 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2656
2032
  softConfig: result.config
2657
2033
  }));
2658
2034
  },
2659
- setVersion: (componentName, newVersion, currentProps, puckDispatch) => {
2035
+ setVersion: (componentName, newVersion, currentProps, puckDispatch, getItemBySelector, getSelectorForId) => {
2660
2036
  var _a;
2661
2037
  if (get().state !== "remodeling") {
2662
2038
  throw new Error("Can only switch versions during remodeling.");
@@ -2683,12 +2059,91 @@ var createBuildersSlice = (set, get, initialConfig) => ({
2683
2059
  softComponentMeta == null ? void 0 : softComponentMeta.category,
2684
2060
  get().customFields
2685
2061
  );
2686
- puckDispatch({
2687
- type: "setData",
2688
- data: (previous) => __spreadProps(__spreadValues({}, previous), {
2689
- root: __spreadProps(__spreadValues({}, root), { props: __spreadProps(__spreadValues({}, root.props), { _versions: versions }) }),
2690
- content: content || []
2691
- })
2062
+ const editableIds = get().editableComponentIds;
2063
+ if (!editableIds || editableIds.size === 0) return;
2064
+ const firstId = Array.from(editableIds)[0];
2065
+ const itemSelector = getSelectorForId(firstId);
2066
+ if (!itemSelector) return;
2067
+ requestAnimationFrame(() => {
2068
+ const countToRemove = Array.from(editableIds).filter(
2069
+ (id) => {
2070
+ var _a2;
2071
+ return ((_a2 = getSelectorForId(id)) == null ? void 0 : _a2.zone) === itemSelector.zone;
2072
+ }
2073
+ ).length;
2074
+ for (let i = 0; i < countToRemove; i++) {
2075
+ puckDispatch({
2076
+ type: "remove",
2077
+ index: itemSelector.index,
2078
+ zone: itemSelector.zone,
2079
+ recordHistory: false
2080
+ });
2081
+ }
2082
+ const newContent = content || [];
2083
+ const comp = newContent[0];
2084
+ if (comp) {
2085
+ puckDispatch({
2086
+ type: "insert",
2087
+ destinationIndex: itemSelector.index,
2088
+ destinationZone: itemSelector.zone,
2089
+ componentType: comp.type,
2090
+ recordHistory: false
2091
+ });
2092
+ }
2093
+ requestAnimationFrame(() => {
2094
+ if (comp) {
2095
+ const insertedItem = getItemBySelector({
2096
+ index: itemSelector.index,
2097
+ zone: itemSelector.zone
2098
+ });
2099
+ if (insertedItem) {
2100
+ puckDispatch({
2101
+ type: "replace",
2102
+ destinationIndex: itemSelector.index,
2103
+ destinationZone: itemSelector.zone,
2104
+ data: __spreadProps(__spreadValues({}, comp), {
2105
+ props: __spreadProps(__spreadValues({}, comp.props), {
2106
+ id: insertedItem.props.id
2107
+ })
2108
+ }),
2109
+ recordHistory: false
2110
+ });
2111
+ }
2112
+ }
2113
+ puckDispatch({
2114
+ type: "replaceRoot",
2115
+ root: {
2116
+ props: __spreadProps(__spreadValues({}, root.props), {
2117
+ _versions: versions
2118
+ })
2119
+ },
2120
+ recordHistory: false
2121
+ });
2122
+ requestAnimationFrame(() => {
2123
+ const newEditableIds = /* @__PURE__ */ new Set();
2124
+ if (comp) {
2125
+ const finalItem = getItemBySelector({
2126
+ index: itemSelector.index,
2127
+ zone: itemSelector.zone
2128
+ });
2129
+ if (finalItem) {
2130
+ walkTree2(
2131
+ { root: {}, content: [finalItem] },
2132
+ { components: get().softConfig.components },
2133
+ (components) => {
2134
+ components.forEach((c) => newEditableIds.add(c.props.id));
2135
+ return components;
2136
+ }
2137
+ );
2138
+ }
2139
+ }
2140
+ set((s) => __spreadProps(__spreadValues({}, s), { editableComponentIds: newEditableIds }));
2141
+ setEditVisibility(get().iframeDoc, {
2142
+ mode: "remodel",
2143
+ editableIds: newEditableIds
2144
+ });
2145
+ });
2146
+ });
2692
2147
  });
2693
2148
  }
2694
2149
  });
@@ -2905,7 +2360,7 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides, showV
2905
2360
  }
2906
2361
 
2907
2362
  // src/puck/store/index.tsx
2908
- var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}) => {
2363
+ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {}, overrides = {}, onActions, showVersionFields = true, customFields = {}, contentAreaNames) => {
2909
2364
  const normalizedSoftComponents = Object.fromEntries(
2910
2365
  Object.entries(softComponents || {}).filter(([key]) => !hardConfig.components || !hardConfig.components[key]).map(([key, value]) => [key, __spreadProps(__spreadValues({}, value), { name: value.name || key })])
2911
2366
  );
@@ -2935,6 +2390,11 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
2935
2390
  softComponents: hydratedSoftComponents,
2936
2391
  dependencyGraph: initialDependencyGraph,
2937
2392
  showVersionFields,
2393
+ contentAreaNames,
2394
+ setContentAreaNames: (names) => set({ contentAreaNames: names }),
2395
+ puckDispatch: null,
2396
+ setPuckDispatch: (dispatch) => set({ puckDispatch: dispatch }),
2397
+ rootActionHandler: rootActionHandler(set, get),
2938
2398
  // ─── Initial softConfig ─────────────────────────────────────────────────
2939
2399
  softConfig: __spreadProps(__spreadValues({}, hardConfig), {
2940
2400
  components: __spreadValues(__spreadValues({}, hardConfig.components), buildInitialSoftComponents(
@@ -3206,7 +2666,7 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
3206
2666
  })
3207
2667
  })),
3208
2668
  // ─── Builder Slice ────────────────────────────────────────────────────────
3209
- builder: createBuildersSlice(set, get, hardConfig),
2669
+ builder: createBuildersSlice(set, get),
3210
2670
  // ─── Dependency Graph ─────────────────────────────────────────────────────
3211
2671
  rebuildDependents: (componentName) => {
3212
2672
  const state = get();
@@ -3239,8 +2699,39 @@ var createSoftConfigStore = (hardConfig = { components: {} }, softComponents = {
3239
2699
  };
3240
2700
 
3241
2701
  // src/puck/context/storeProvider.tsx
3242
- import { useEffect as useEffect2, useMemo as useMemo2, useState } from "react";
3243
- import { jsx as jsx7 } from "react/jsx-runtime";
2702
+ import { useEffect, useMemo as useMemo2, useState } from "react";
2703
+
2704
+ // src/puck/context/useStore.ts
2705
+ import { createContext, useContext } from "react";
2706
+ import { useStore } from "zustand";
2707
+ var appStoreContext = createContext(null);
2708
+ var createUseSoftConfig = () => {
2709
+ return function useSoftConfig2(selector, equalityFn) {
2710
+ const context = useContext(appStoreContext);
2711
+ if (!context) {
2712
+ throw new Error(
2713
+ "useSoftConfig must be used inside a SoftConfigProvider. Wrap your tree with <SoftConfigProvider value={store}>"
2714
+ );
2715
+ }
2716
+ if (equalityFn) {
2717
+ return useStore(context, selector, equalityFn);
2718
+ }
2719
+ return useStore(context, selector);
2720
+ };
2721
+ };
2722
+ var useSoftConfig = createUseSoftConfig();
2723
+ var useSoftConfigStore = () => {
2724
+ const context = useContext(appStoreContext);
2725
+ if (!context) {
2726
+ throw new Error(
2727
+ "useSoftConfigStore must be used inside a SoftConfigProvider."
2728
+ );
2729
+ }
2730
+ return context;
2731
+ };
2732
+
2733
+ // src/puck/context/storeProvider.tsx
2734
+ import { jsx as jsx4 } from "react/jsx-runtime";
3244
2735
  var SoftConfigProvider = ({
3245
2736
  children,
3246
2737
  hardConfig,
@@ -3249,7 +2740,8 @@ var SoftConfigProvider = ({
3249
2740
  overrides,
3250
2741
  value,
3251
2742
  onActions,
3252
- useVersioning = false
2743
+ useVersioning = false,
2744
+ contentAreaNames
3253
2745
  }) => {
3254
2746
  const store = useMemo2(
3255
2747
  () => value != null ? value : createSoftConfigStore(
@@ -3258,18 +2750,15 @@ var SoftConfigProvider = ({
3258
2750
  overrides,
3259
2751
  onActions,
3260
2752
  useVersioning,
3261
- customFields
2753
+ customFields,
2754
+ contentAreaNames
3262
2755
  ),
3263
- // eslint-disable-next-line react-hooks/exhaustive-deps
3264
2756
  [value]
3265
- // Intentionally omitting the rest: createSoftConfigStore params are
3266
- // treated as initialisation-time values. If callers need to react to
3267
- // prop changes they should pass a new `value` store instead.
3268
2757
  );
3269
2758
  const [softConfig, setSoftConfig] = useState(
3270
2759
  () => store.getState().softConfig
3271
2760
  );
3272
- useEffect2(() => {
2761
+ useEffect(() => {
3273
2762
  let prev = store.getState().softConfig;
3274
2763
  const unsubscribe = store.subscribe((state) => {
3275
2764
  if (state.softConfig !== prev) {
@@ -3279,17 +2768,17 @@ var SoftConfigProvider = ({
3279
2768
  });
3280
2769
  return unsubscribe;
3281
2770
  }, [store]);
3282
- return /* @__PURE__ */ jsx7(appStoreContext.Provider, { value: store, children: children(softConfig) });
2771
+ return /* @__PURE__ */ jsx4(appStoreContext.Provider, { value: store, children: children(softConfig) });
3283
2772
  };
3284
2773
 
3285
2774
  // src/puck/actions/useBuild.tsx
3286
- import { createUsePuck as createUsePuck2 } from "@measured/puck";
2775
+ import { createUsePuck } from "@measured/puck";
3287
2776
 
3288
2777
  // src/puck/lib/notify.ts
3289
2778
  var customHandler = null;
3290
2779
  var defaultHandler = (message, type) => {
3291
2780
  if (type === "error") {
3292
- console.error(`[Error] ${message}`);
2781
+ alert(`[Error] ${message}`);
3293
2782
  } else {
3294
2783
  console.log(`[Success] ${message}`);
3295
2784
  }
@@ -3328,13 +2817,13 @@ var useActionEvent = () => {
3328
2817
  };
3329
2818
 
3330
2819
  // src/puck/actions/useBuild.tsx
3331
- var useCustomPuck2 = createUsePuck2();
2820
+ var useCustomPuck = createUsePuck();
3332
2821
  var useBuild = (name) => {
3333
2822
  const build = useSoftConfig((s) => s.builder.build);
3334
- const history = useCustomPuck2((s) => s.history.histories);
3335
- const selectedItem = useCustomPuck2((s) => s.selectedItem);
3336
- const itemSelector = useCustomPuck2((s) => s.appState.ui.itemSelector);
3337
- const dispatch = useCustomPuck2((s) => s.dispatch);
2823
+ const history = useCustomPuck((s) => s.history.histories);
2824
+ const selectedItem = useCustomPuck((s) => s.selectedItem);
2825
+ const itemSelector = useCustomPuck((s) => s.appState.ui.itemSelector);
2826
+ const dispatch = useCustomPuck((s) => s.dispatch);
3338
2827
  const status = useSoftConfig((s) => s.state);
3339
2828
  const { triggerAction } = useActionEvent();
3340
2829
  const handleBuild = () => {
@@ -3353,7 +2842,7 @@ var useBuild = (name) => {
3353
2842
  });
3354
2843
  }
3355
2844
  } catch (error) {
3356
- console.error("Failed to build:", error);
2845
+ alert("Failed to build: " + error);
3357
2846
  notify.error(
3358
2847
  "Failed to build: " + (error instanceof Error ? error.message : String(error))
3359
2848
  );
@@ -3363,17 +2852,17 @@ var useBuild = (name) => {
3363
2852
  };
3364
2853
 
3365
2854
  // src/puck/actions/useRemodel.tsx
3366
- import { createUsePuck as createUsePuck3 } from "@measured/puck";
3367
- var useCustomPuck3 = createUsePuck3();
2855
+ import { createUsePuck as createUsePuck2 } from "@measured/puck";
2856
+ var useCustomPuck2 = createUsePuck2();
3368
2857
  var useRemodel = () => {
3369
2858
  const remodel = useSoftConfig((s) => s.builder.remodel);
3370
- const history = useCustomPuck3((s) => s.history.histories);
3371
- const selectedItem = useCustomPuck3((s) => s.selectedItem);
3372
- const itemSelector = useCustomPuck3((s) => s.appState.ui.itemSelector);
3373
- const dispatch = useCustomPuck3((s) => s.dispatch);
2859
+ const history = useCustomPuck2((s) => s.history.histories);
2860
+ const selectedItem = useCustomPuck2((s) => s.selectedItem);
2861
+ const itemSelector = useCustomPuck2((s) => s.appState.ui.itemSelector);
2862
+ const dispatch = useCustomPuck2((s) => s.dispatch);
3374
2863
  const status = useSoftConfig((s) => s.state);
3375
2864
  const softComponents = useSoftConfig((s) => s.softComponents);
3376
- const refreshPermissions = useCustomPuck3((s) => s.refreshPermissions);
2865
+ const refreshPermissions = useCustomPuck2((s) => s.refreshPermissions);
3377
2866
  const { triggerAction } = useActionEvent();
3378
2867
  const handleRemodel = (componentName) => {
3379
2868
  var _a, _b, _c;
@@ -3389,7 +2878,13 @@ var useRemodel = () => {
3389
2878
  const selectedVersion = ((_a = selectedItem == null ? void 0 : selectedItem.props) == null ? void 0 : _a.version) || ((_b = softComponents[name]) == null ? void 0 : _b.defaultVersion);
3390
2879
  const selectedSoftComponent = selectedVersion ? (_c = softComponents[name]) == null ? void 0 : _c.versions[selectedVersion] : void 0;
3391
2880
  try {
3392
- remodel(history, selectedItem, itemSelector, dispatch, refreshPermissions);
2881
+ remodel(
2882
+ history,
2883
+ selectedItem,
2884
+ itemSelector,
2885
+ dispatch,
2886
+ refreshPermissions
2887
+ );
3393
2888
  void triggerAction({
3394
2889
  type: "remodel",
3395
2890
  payload: {
@@ -3407,9 +2902,9 @@ var useRemodel = () => {
3407
2902
  }
3408
2903
  return { id: name, version: selectedVersion };
3409
2904
  } catch (error) {
3410
- console.error("Failed to remodel:", error);
2905
+ alert("Failed to remodel: " + error);
3411
2906
  notify.error(
3412
- "Failed to remodel: " + (error instanceof Error ? error.message : String(error))
2907
+ "Failed to remodel: " + (error instanceof Error ? error.message : String(error)) + " " + String()
3413
2908
  );
3414
2909
  return null;
3415
2910
  }
@@ -3422,14 +2917,14 @@ var useRemodel = () => {
3422
2917
  };
3423
2918
 
3424
2919
  // src/puck/actions/useComplete.tsx
3425
- import { createUsePuck as createUsePuck4 } from "@measured/puck";
2920
+ import { createUsePuck as createUsePuck3 } from "@measured/puck";
3426
2921
  import { useState as useState2, useCallback as useCallback2 } from "react";
3427
- var useCustomPuck4 = createUsePuck4();
2922
+ var useCustomPuck3 = createUsePuck3();
3428
2923
  var useComplete = () => {
3429
2924
  const complete = useSoftConfig((s) => s.builder.complete);
3430
- const appState = useCustomPuck4((s) => s.appState);
3431
- const setHistories = useCustomPuck4((s) => s.history.setHistories);
3432
- const getItemBySelector = useCustomPuck4((s) => s.getItemBySelector);
2925
+ const appState = useCustomPuck3((s) => s.appState);
2926
+ const setHistories = useCustomPuck3((s) => s.history.setHistories);
2927
+ const getItemBySelector = useCustomPuck3((s) => s.getItemBySelector);
3433
2928
  const status = useSoftConfig((s) => s.state);
3434
2929
  const [newComponent, setNewComponent] = useState2(null);
3435
2930
  const { triggerAction } = useActionEvent();
@@ -3467,11 +2962,13 @@ var useComplete = () => {
3467
2962
  };
3468
2963
 
3469
2964
  // src/puck/actions/useCancel.tsx
3470
- import { createUsePuck as createUsePuck5 } from "@measured/puck";
3471
- var useCustomPuck5 = createUsePuck5();
2965
+ import { createUsePuck as createUsePuck4 } from "@measured/puck";
2966
+ var useCustomPuck4 = createUsePuck4();
3472
2967
  var useCancel = () => {
3473
2968
  const cancel = useSoftConfig((s) => s.builder.cancel);
3474
- const setHistories = useCustomPuck5((s) => s.history.setHistories);
2969
+ const setHistories = useCustomPuck4((s) => s.history.setHistories);
2970
+ const puckDispatch = useCustomPuck4((s) => s.dispatch);
2971
+ const selectedItemSelector = useCustomPuck4((s) => s.appState.ui.itemSelector);
3475
2972
  const status = useSoftConfig((s) => s.state);
3476
2973
  const { triggerAction } = useActionEvent();
3477
2974
  const handleCancel = () => {
@@ -3480,13 +2977,13 @@ var useCancel = () => {
3480
2977
  return;
3481
2978
  }
3482
2979
  try {
3483
- cancel(setHistories);
2980
+ cancel(setHistories, puckDispatch, selectedItemSelector);
3484
2981
  void triggerAction({
3485
2982
  type: "cancel",
3486
2983
  payload: {}
3487
2984
  });
3488
2985
  } catch (error) {
3489
- console.error("Failed to cancel:", error);
2986
+ alert("Failed to cancel: " + error);
3490
2987
  notify.error(
3491
2988
  "Failed to cancel: " + (error instanceof Error ? error.message : String(error))
3492
2989
  );
@@ -3497,22 +2994,22 @@ var useCancel = () => {
3497
2994
  };
3498
2995
 
3499
2996
  // src/puck/actions/useInspect.tsx
3500
- import { createUsePuck as createUsePuck6 } from "@measured/puck";
3501
- import { useEffect as useEffect3 } from "react";
3502
- var useCustomPuck6 = createUsePuck6();
2997
+ import { createUsePuck as createUsePuck5 } from "@measured/puck";
2998
+ import { useEffect as useEffect2 } from "react";
2999
+ var useCustomPuck5 = createUsePuck5();
3503
3000
  var useInspect = (component) => {
3504
3001
  const inspect = useSoftConfig((s) => s.builder.inspect);
3505
- const dispatch = useCustomPuck6((s) => s.dispatch);
3002
+ const dispatch = useCustomPuck5((s) => s.dispatch);
3506
3003
  const status = useSoftConfig((s) => s.state);
3507
3004
  const { triggerAction } = useActionEvent();
3508
- useEffect3(() => {
3005
+ useEffect2(() => {
3509
3006
  if (status !== "inspecting") return;
3510
3007
  if (!component) {
3511
3008
  notify.error("No component to inspect.");
3512
3009
  return;
3513
3010
  }
3514
3011
  try {
3515
- inspect(component.id, dispatch);
3012
+ inspect(component.id, dispatch, null);
3516
3013
  void triggerAction({
3517
3014
  type: "inspect",
3518
3015
  payload: {
@@ -3531,16 +3028,24 @@ var useInspect = (component) => {
3531
3028
  };
3532
3029
 
3533
3030
  // src/puck/actions/useDecompose.tsx
3534
- import { createUsePuck as createUsePuck7, walkTree as walkTree4 } from "@measured/puck";
3535
- var useCustomPuck7 = createUsePuck7();
3031
+ import { createUsePuck as createUsePuck6, walkTree as walkTree3 } from "@measured/puck";
3032
+
3033
+ // src/puck/lib/get-prop-by-path.ts
3034
+ function getPropertyByPath(props, path) {
3035
+ return path.replace(/\[(\w+)\]/g, ".$1").split(".").reduce((o, key) => o ? o[key] : void 0, props);
3036
+ }
3037
+
3038
+ // src/puck/actions/useDecompose.tsx
3039
+ var useCustomPuck6 = createUsePuck6();
3536
3040
  var useDecompose = () => {
3537
3041
  const decompose = useSoftConfig((s) => s.builder.decompose);
3538
- const appState = useCustomPuck7((s) => s.appState);
3539
- const dispatch = useCustomPuck7((s) => s.dispatch);
3540
- const selectedItem = useCustomPuck7((s) => s.selectedItem);
3042
+ const appState = useCustomPuck6((s) => s.appState);
3043
+ const dispatch = useCustomPuck6((s) => s.dispatch);
3044
+ const selectedItem = useCustomPuck6((s) => s.selectedItem);
3541
3045
  const status = useSoftConfig((s) => s.state);
3542
3046
  const softComponents = useSoftConfig((s) => s.softComponents);
3543
3047
  const config = useSoftConfig((s) => s.softConfig);
3048
+ const contentAreaNames = useSoftConfig((s) => s.contentAreaNames);
3544
3049
  const { triggerAction } = useActionEvent();
3545
3050
  const handleDecompose = (componentData) => {
3546
3051
  if (status !== "ready") {
@@ -3563,12 +3068,22 @@ var useDecompose = () => {
3563
3068
  notify.error("Nothing to decompose.");
3564
3069
  return;
3565
3070
  }
3566
- const newData = walkTree4(appState.data, config, (components) => {
3567
- const index = components.findIndex((c) => c.props.id === target.props.id);
3568
- if (index !== -1) {
3569
- components.splice(index, 1, ...decomposedComponents);
3570
- }
3571
- return components;
3071
+ let newData = __spreadValues({}, appState.data);
3072
+ const targetAreas = contentAreaNames && contentAreaNames.length > 0 ? contentAreaNames : ["content"];
3073
+ targetAreas.forEach((path) => {
3074
+ const contentArray = getPropertyByPath(newData, path) || [];
3075
+ const walkedData = walkTree3(
3076
+ { content: contentArray, root: newData.root || {} },
3077
+ config,
3078
+ (components) => {
3079
+ const index = components.findIndex((c) => c.props.id === target.props.id);
3080
+ if (index !== -1) {
3081
+ components.splice(index, 1, ...decomposedComponents);
3082
+ }
3083
+ return components;
3084
+ }
3085
+ );
3086
+ setPropertyByPath(newData, path, walkedData.content);
3572
3087
  });
3573
3088
  dispatch({
3574
3089
  type: "setData",
@@ -3581,7 +3096,7 @@ var useDecompose = () => {
3581
3096
  }
3582
3097
  });
3583
3098
  } catch (error) {
3584
- console.error("Failed to decompose:", error);
3099
+ alert("Failed to decompose: " + error);
3585
3100
  notify.error(
3586
3101
  "Failed to decompose: " + (error instanceof Error ? error.message : String(error))
3587
3102
  );
@@ -3595,12 +3110,12 @@ var useDecompose = () => {
3595
3110
  };
3596
3111
 
3597
3112
  // src/puck/actions/useDemolish.tsx
3598
- import { createUsePuck as createUsePuck8 } from "@measured/puck";
3599
- var useCustomPuck8 = createUsePuck8();
3113
+ import { createUsePuck as createUsePuck7 } from "@measured/puck";
3114
+ var useCustomPuck7 = createUsePuck7();
3600
3115
  var useDemolish = () => {
3601
3116
  const demolish = useSoftConfig((s) => s.builder.demolish);
3602
- const dispatch = useCustomPuck8((s) => s.dispatch);
3603
- const data = useCustomPuck8((s) => s.appState.data);
3117
+ const dispatch = useCustomPuck7((s) => s.dispatch);
3118
+ const data = useCustomPuck7((s) => s.appState.data);
3604
3119
  const status = useSoftConfig((s) => s.state);
3605
3120
  const softComponents = useSoftConfig((s) => s.softComponents);
3606
3121
  const { triggerAction } = useActionEvent();
@@ -3622,7 +3137,7 @@ var useDemolish = () => {
3622
3137
  }
3623
3138
  });
3624
3139
  } catch (error) {
3625
- console.error("Failed to demolish:", error);
3140
+ alert("Failed to demolish: " + error);
3626
3141
  notify.error(
3627
3142
  "Failed to demolish: " + (error instanceof Error ? error.message : String(error))
3628
3143
  );
@@ -3689,11 +3204,11 @@ import { Button } from "@measured/puck";
3689
3204
  var Header_module_default = { "Header": "_Header_19oj9_1" };
3690
3205
 
3691
3206
  // src/puck/actions/usePublish.tsx
3692
- import { createUsePuck as createUsePuck9 } from "@measured/puck";
3693
- var useCustomPuck9 = createUsePuck9();
3207
+ import { createUsePuck as createUsePuck8 } from "@measured/puck";
3208
+ var useCustomPuck8 = createUsePuck8();
3694
3209
  var usePublish = () => {
3695
3210
  const components = useSoftConfig((s) => s.softComponents);
3696
- const data = useCustomPuck9((s) => s.appState.data);
3211
+ const data = useCustomPuck8((s) => s.appState.data);
3697
3212
  const status = useSoftConfig((s) => s.state);
3698
3213
  const { triggerAction } = useActionEvent();
3699
3214
  const handlePublish = (publish) => {
@@ -3724,7 +3239,7 @@ var usePublish = () => {
3724
3239
  };
3725
3240
 
3726
3241
  // src/puck/overrides/Header.tsx
3727
- import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs2 } from "react/jsx-runtime";
3242
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
3728
3243
  var getClassName2 = get_class_name_factory_default("Header", Header_module_default);
3729
3244
  var Header = ({
3730
3245
  onPublish,
@@ -3734,9 +3249,9 @@ var Header = ({
3734
3249
  const { handleCancel, canCancel } = useCancel();
3735
3250
  const { handlePublish } = usePublish();
3736
3251
  useInspect(newComponent);
3737
- return /* @__PURE__ */ jsx8("div", { className: getClassName2(), children: canCancel ? /* @__PURE__ */ jsxs2(Fragment3, { children: [
3738
- /* @__PURE__ */ jsx8(Button, { onClick: handleCancel, children: "Cancel" }),
3739
- /* @__PURE__ */ jsx8(
3252
+ return /* @__PURE__ */ jsx5("div", { className: getClassName2(), children: canCancel ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
3253
+ /* @__PURE__ */ jsx5(Button, { onClick: handleCancel, children: "Cancel" }),
3254
+ /* @__PURE__ */ jsx5(
3740
3255
  Button,
3741
3256
  {
3742
3257
  variant: "primary",
@@ -3749,7 +3264,7 @@ var Header = ({
3749
3264
  children: "Complete"
3750
3265
  }
3751
3266
  )
3752
- ] }) : children ? children : /* @__PURE__ */ jsx8(
3267
+ ] }) : children ? children : /* @__PURE__ */ jsx5(
3753
3268
  Button,
3754
3269
  {
3755
3270
  variant: "primary",
@@ -3765,7 +3280,7 @@ var Header = ({
3765
3280
 
3766
3281
  // src/puck/overrides/ActionBar.tsx
3767
3282
  import { useMemo as useMemo3 } from "react";
3768
- import { ActionBar, createUsePuck as createUsePuck11 } from "@measured/puck";
3283
+ import { ActionBar, createUsePuck as createUsePuck10 } from "@measured/puck";
3769
3284
  import { Combine, ComponentIcon, EditIcon } from "lucide-react";
3770
3285
 
3771
3286
  // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/ActionBar.module.css#css-module
@@ -3773,9 +3288,9 @@ var ActionBar_module_default = { "ActionBar": "_ActionBar_pvuie_5", "ActionBar-l
3773
3288
 
3774
3289
  // src/puck/overrides/ActionBar.tsx
3775
3290
  import { shallow } from "zustand/shallow";
3776
- import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs3 } from "react/jsx-runtime";
3291
+ import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
3292
+ var useCustomPuck9 = createUsePuck10();
3777
3293
  var getClassName3 = get_class_name_factory_default("ActionBar", ActionBar_module_default);
3778
- var usePuck = createUsePuck11();
3779
3294
  var ActionBarOverride = (props) => {
3780
3295
  var _a, _b;
3781
3296
  const { handleBuild } = useBuild(props.label ? props.label + " Soft Component" : "New Soft Component");
@@ -3784,10 +3299,11 @@ var ActionBarOverride = (props) => {
3784
3299
  const overrides = useSoftConfig((s) => s.overrides);
3785
3300
  const softComponents = useSoftConfig((s) => s.softComponents, shallow);
3786
3301
  const editableIds = useSoftConfig((s) => s.editableComponentIds);
3787
- const selectedItem = usePuck((s) => s.selectedItem);
3788
- const rootProps = usePuck((s) => s.appState.data.root.props);
3302
+ const selectedItem = useCustomPuck9((s) => s.selectedItem);
3303
+ const appState = useCustomPuck9((s) => s.appState);
3304
+ const rootProps = appState.data.root.props;
3789
3305
  const status = useSoftConfig((s) => s.state);
3790
- const itemSelector = usePuck((s) => s.appState.ui.itemSelector);
3306
+ const itemSelector = appState.ui.itemSelector;
3791
3307
  const softKeys = Object.keys(softComponents);
3792
3308
  const key = useMemo3(() => {
3793
3309
  const selectedType = selectedItem == null ? void 0 : selectedItem.type;
@@ -3817,35 +3333,35 @@ var ActionBarOverride = (props) => {
3817
3333
  }
3818
3334
  return props.label || "";
3819
3335
  }, [isSoftComponent2, key, props.label, overrides, softComponents]);
3820
- return /* @__PURE__ */ jsx9("div", { className: getClassName3(), children: /* @__PURE__ */ jsxs3(ActionBar, { children: [
3336
+ return /* @__PURE__ */ jsx6("div", { className: getClassName3(), children: /* @__PURE__ */ jsxs3(ActionBar, { children: [
3821
3337
  /* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
3822
3338
  props.parentAction,
3823
- /* @__PURE__ */ jsx9(ActionBar.Label, { label })
3339
+ /* @__PURE__ */ jsx6(ActionBar.Label, { label })
3824
3340
  ] }),
3825
3341
  /* @__PURE__ */ jsxs3(ActionBar.Group, { children: [
3826
- status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ jsxs3(Fragment4, { children: [
3827
- /* @__PURE__ */ jsx9(
3342
+ status === "ready" ? isSoftComponent2 ? /* @__PURE__ */ jsxs3(Fragment3, { children: [
3343
+ /* @__PURE__ */ jsx6(
3828
3344
  ActionBar.Action,
3829
3345
  {
3830
3346
  onClick: () => handleRemodel(key),
3831
3347
  label: "Remodel Soft Component",
3832
- children: /* @__PURE__ */ jsx9(EditIcon, { size: 16 })
3348
+ children: /* @__PURE__ */ jsx6(EditIcon, { size: 16 })
3833
3349
  }
3834
3350
  ),
3835
- /* @__PURE__ */ jsx9(
3351
+ /* @__PURE__ */ jsx6(
3836
3352
  ActionBar.Action,
3837
3353
  {
3838
3354
  onClick: () => handleDecompose(),
3839
3355
  label: "Decompose Soft Component",
3840
- children: /* @__PURE__ */ jsx9(Combine, { size: 16 })
3356
+ children: /* @__PURE__ */ jsx6(Combine, { size: 16 })
3841
3357
  }
3842
3358
  )
3843
- ] }) : /* @__PURE__ */ jsx9(
3359
+ ] }) : /* @__PURE__ */ jsx6(
3844
3360
  ActionBar.Action,
3845
3361
  {
3846
3362
  onClick: handleBuild,
3847
3363
  label: "Build Soft Component",
3848
- children: /* @__PURE__ */ jsx9(ComponentIcon, { size: 16 })
3364
+ children: /* @__PURE__ */ jsx6(ComponentIcon, { size: 16 })
3849
3365
  }
3850
3366
  ) : null,
3851
3367
  status !== "ready" && !isEditable ? null : props.children
@@ -3855,7 +3371,7 @@ var ActionBarOverride = (props) => {
3855
3371
 
3856
3372
  // src/puck/overrides/DrawerItem.tsx
3857
3373
  import { useState as useState4 } from "react";
3858
- import { Button as Button2, IconButton, createUsePuck as createUsePuck12 } from "@measured/puck";
3374
+ import { Button as Button2, IconButton, createUsePuck as createUsePuck11 } from "@measured/puck";
3859
3375
  import { GripVertical, Check, X, Trash2, Cog } from "lucide-react";
3860
3376
 
3861
3377
  // src/puck/lib/confirm.ts
@@ -3870,7 +3386,7 @@ var confirm = (message) => __async(null, null, function* () {
3870
3386
  const result = confirmHandler(message);
3871
3387
  return result instanceof Promise ? yield result : result;
3872
3388
  } catch (error) {
3873
- console.error("Confirm handler error:", error);
3389
+ alert("Confirm handler error: " + error);
3874
3390
  return false;
3875
3391
  }
3876
3392
  });
@@ -3879,14 +3395,14 @@ var confirm = (message) => __async(null, null, function* () {
3879
3395
  var DrawerItem_module_default = { "DrawerItem": "_DrawerItem_182aj_1", "DrawerItem--insertDisabled": "_DrawerItem--insertDisabled_182aj_14", "DrawerItem-content": "_DrawerItem-content_182aj_21", "DrawerItem-name": "_DrawerItem-name_182aj_31", "DrawerItem-version": "_DrawerItem-version_182aj_35", "DrawerItem-actions": "_DrawerItem-actions_182aj_40", "DrawerItem-settingsButton": "_DrawerItem-settingsButton_182aj_46", "DrawerItem-grip": "_DrawerItem-grip_182aj_56", "DrawerItem-modal": "_DrawerItem-modal_182aj_63", "DrawerItem-modalHeader": "_DrawerItem-modalHeader_182aj_71", "DrawerItem-modalTitle": "_DrawerItem-modalTitle_182aj_77", "DrawerItem-modalSubtitle": "_DrawerItem-modalSubtitle_182aj_84", "DrawerItem-modalBody": "_DrawerItem-modalBody_182aj_90", "DrawerItem-section": "_DrawerItem-section_182aj_100", "DrawerItem-sectionTitle": "_DrawerItem-sectionTitle_182aj_106", "DrawerItem-sectionDescription": "_DrawerItem-sectionDescription_182aj_113", "DrawerItem-versionList": "_DrawerItem-versionList_182aj_119", "DrawerItem-versionRow": "_DrawerItem-versionRow_182aj_125", "DrawerItem-versionRow--isDefault": "_DrawerItem-versionRow--isDefault_182aj_136", "DrawerItem-versionRow--isMarkedForDeletion": "_DrawerItem-versionRow--isMarkedForDeletion_182aj_141", "DrawerItem-versionInfo": "_DrawerItem-versionInfo_182aj_146", "DrawerItem-versionNumber": "_DrawerItem-versionNumber_182aj_153", "DrawerItem-defaultBadge": "_DrawerItem-defaultBadge_182aj_159", "DrawerItem-deleteBadge": "_DrawerItem-deleteBadge_182aj_170", "DrawerItem-versionActions": "_DrawerItem-versionActions_182aj_181", "DrawerItem-migrationOptions": "_DrawerItem-migrationOptions_182aj_187", "DrawerItem-migrationList": "_DrawerItem-migrationList_182aj_191", "DrawerItem-migrationOption": "_DrawerItem-migrationOption_182aj_187", "DrawerItem-migrationOption--isSelected": "_DrawerItem-migrationOption--isSelected_182aj_229", "DrawerItem-migrationOptionLabel": "_DrawerItem-migrationOptionLabel_182aj_234", "DrawerItem-modalFooter": "_DrawerItem-modalFooter_182aj_240", "DrawerItem-footerLeft": "_DrawerItem-footerLeft_182aj_250", "DrawerItem-footerRight": "_DrawerItem-footerRight_182aj_255" };
3880
3396
 
3881
3397
  // src/puck/components/modal/index.tsx
3882
- import { useEffect as useEffect4, useState as useState3 } from "react";
3398
+ import { useEffect as useEffect3, useState as useState3 } from "react";
3883
3399
  import { createPortal } from "react-dom";
3884
3400
 
3885
3401
  // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/components/modal/styles.module.css#css-module
3886
3402
  var styles_module_default2 = { "Modal": "_Modal_1t9ot_1", "Modal--isOpen": "_Modal--isOpen_1t9ot_29", "Modal-inner": "_Modal-inner_1t9ot_37" };
3887
3403
 
3888
3404
  // src/puck/components/modal/index.tsx
3889
- import { jsx as jsx10 } from "react/jsx-runtime";
3405
+ import { jsx as jsx7 } from "react/jsx-runtime";
3890
3406
  var getClassName4 = get_class_name_factory_default("Modal", styles_module_default2);
3891
3407
  var Modal = ({
3892
3408
  children,
@@ -3894,10 +3410,10 @@ var Modal = ({
3894
3410
  isOpen
3895
3411
  }) => {
3896
3412
  const [rootEl, setRootEl] = useState3(null);
3897
- useEffect4(() => {
3413
+ useEffect3(() => {
3898
3414
  setRootEl(document.getElementById("puck-portal-root"));
3899
3415
  }, []);
3900
- useEffect4(() => {
3416
+ useEffect3(() => {
3901
3417
  if (!isOpen) {
3902
3418
  return;
3903
3419
  }
@@ -3910,10 +3426,10 @@ var Modal = ({
3910
3426
  return () => document.removeEventListener("keydown", handleEscape);
3911
3427
  }, [isOpen, onClose]);
3912
3428
  if (!rootEl) {
3913
- return /* @__PURE__ */ jsx10("div", {});
3429
+ return /* @__PURE__ */ jsx7("div", {});
3914
3430
  }
3915
3431
  return createPortal(
3916
- /* @__PURE__ */ jsx10(
3432
+ /* @__PURE__ */ jsx7(
3917
3433
  "div",
3918
3434
  {
3919
3435
  className: getClassName4({ isOpen }),
@@ -3922,7 +3438,7 @@ var Modal = ({
3922
3438
  onClose();
3923
3439
  }
3924
3440
  },
3925
- children: /* @__PURE__ */ jsx10(
3441
+ children: /* @__PURE__ */ jsx7(
3926
3442
  "div",
3927
3443
  {
3928
3444
  className: getClassName4("inner"),
@@ -3940,16 +3456,16 @@ var Modal = ({
3940
3456
 
3941
3457
  // src/puck/overrides/DrawerItem.tsx
3942
3458
  import { shallow as shallow2 } from "zustand/shallow";
3943
- import { Fragment as Fragment5, jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
3459
+ import { Fragment as Fragment4, jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
3460
+ var useCustomPuck10 = createUsePuck11();
3944
3461
  var getClassName5 = get_class_name_factory_default("DrawerItem", DrawerItem_module_default);
3945
- var usePuck2 = createUsePuck12();
3946
3462
  var DrawerItem = (props) => {
3947
3463
  const componentMeta = useSoftConfig((s) => s.softComponents[props.name]);
3948
3464
  const displayName = props.label || (componentMeta == null ? void 0 : componentMeta.name) || props.name;
3949
3465
  const softComponents = new Set(
3950
3466
  Object.keys(useSoftConfig((s) => s.softComponents, shallow2))
3951
3467
  );
3952
- const getPermissions = usePuck2((s) => s.getPermissions);
3468
+ const getPermissions = useCustomPuck10((s) => s.getPermissions);
3953
3469
  const insertAllowed = getPermissions({ type: props.name }).insert;
3954
3470
  const removeSoftComponentVersion = useSoftConfig(
3955
3471
  (s) => s.removeSoftComponentVersion
@@ -4033,7 +3549,7 @@ var DrawerItem = (props) => {
4033
3549
  label: `Migrate to Version ${version}`
4034
3550
  }))
4035
3551
  ];
4036
- return /* @__PURE__ */ jsxs4(Fragment5, { children: [
3552
+ return /* @__PURE__ */ jsxs4(Fragment4, { children: [
4037
3553
  /* @__PURE__ */ jsxs4(
4038
3554
  "div",
4039
3555
  {
@@ -4043,40 +3559,39 @@ var DrawerItem = (props) => {
4043
3559
  children: [
4044
3560
  props.label,
4045
3561
  /* @__PURE__ */ jsxs4("div", { className: getClassName5("content"), children: [
4046
- /* @__PURE__ */ jsx11("div", { className: getClassName5("name"), children: displayName }),
3562
+ /* @__PURE__ */ jsx8("div", { className: getClassName5("name"), children: displayName }),
4047
3563
  useVersioning && /* @__PURE__ */ jsxs4("div", { className: getClassName5("version"), children: [
4048
3564
  "v",
4049
3565
  defaultVersion
4050
3566
  ] })
4051
3567
  ] }),
4052
3568
  /* @__PURE__ */ jsxs4("div", { className: getClassName5("actions"), children: [
4053
- isHovering && /* @__PURE__ */ jsx11("div", { className: getClassName5("settingsButton"), children: /* @__PURE__ */ jsx11(
3569
+ isHovering && /* @__PURE__ */ jsx8("div", { className: getClassName5("settingsButton"), children: /* @__PURE__ */ jsx8(
4054
3570
  IconButton,
4055
3571
  {
4056
3572
  title: "Settings",
4057
- variant: "secondary",
4058
3573
  onClick: (e) => {
4059
3574
  e.stopPropagation();
4060
3575
  setIsEditing(true);
4061
3576
  setSelectedVersion(defaultVersion || "");
4062
3577
  },
4063
- children: /* @__PURE__ */ jsx11(Cog, { size: 12 })
3578
+ children: /* @__PURE__ */ jsx8(Cog, { size: 12 })
4064
3579
  }
4065
3580
  ) }),
4066
- /* @__PURE__ */ jsx11("div", { className: getClassName5("grip"), children: /* @__PURE__ */ jsx11(GripVertical, { size: 16 }) })
3581
+ /* @__PURE__ */ jsx8("div", { className: getClassName5("grip"), children: /* @__PURE__ */ jsx8(GripVertical, { size: 16 }) })
4067
3582
  ] })
4068
3583
  ]
4069
3584
  }
4070
3585
  ),
4071
- /* @__PURE__ */ jsx11(Modal, { isOpen: isEditing, onClose: handleCancel, children: /* @__PURE__ */ jsxs4("div", { className: getClassName5("modal"), children: [
3586
+ /* @__PURE__ */ jsx8(Modal, { isOpen: isEditing, onClose: handleCancel, children: /* @__PURE__ */ jsxs4("div", { className: getClassName5("modal"), children: [
4072
3587
  /* @__PURE__ */ jsxs4("div", { className: getClassName5("modalHeader"), children: [
4073
- /* @__PURE__ */ jsx11("h2", { className: getClassName5("modalTitle"), children: displayName }),
4074
- /* @__PURE__ */ jsx11("p", { className: getClassName5("modalSubtitle"), children: "Component Settings" })
3588
+ /* @__PURE__ */ jsx8("h2", { className: getClassName5("modalTitle"), children: displayName }),
3589
+ /* @__PURE__ */ jsx8("p", { className: getClassName5("modalSubtitle"), children: "Component Settings" })
4075
3590
  ] }),
4076
- /* @__PURE__ */ jsx11("div", { className: getClassName5("modalBody"), children: useVersioning ? /* @__PURE__ */ jsxs4(Fragment5, { children: [
3591
+ /* @__PURE__ */ jsx8("div", { className: getClassName5("modalBody"), children: useVersioning ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
4077
3592
  /* @__PURE__ */ jsxs4("div", { className: getClassName5("section"), children: [
4078
- /* @__PURE__ */ jsx11("h3", { className: getClassName5("sectionTitle"), children: "Versions" }),
4079
- /* @__PURE__ */ jsx11("div", { className: getClassName5("versionList"), children: versions.map((version) => {
3593
+ /* @__PURE__ */ jsx8("h3", { className: getClassName5("sectionTitle"), children: "Versions" }),
3594
+ /* @__PURE__ */ jsx8("div", { className: getClassName5("versionList"), children: versions.map((version) => {
4080
3595
  const isDefault = version === (selectedVersion || defaultVersion);
4081
3596
  const isMarkedForDeletion = versionsToDelete.has(version);
4082
3597
  let rowClass = getClassName5("versionRow");
@@ -4088,16 +3603,16 @@ var DrawerItem = (props) => {
4088
3603
  "Version ",
4089
3604
  version
4090
3605
  ] }),
4091
- isDefault && /* @__PURE__ */ jsx11("span", { className: getClassName5("defaultBadge"), children: "Default" }),
4092
- isMarkedForDeletion && /* @__PURE__ */ jsx11("span", { className: getClassName5("deleteBadge"), children: "Marked for deletion" })
3606
+ isDefault && /* @__PURE__ */ jsx8("span", { className: getClassName5("defaultBadge"), children: "Default" }),
3607
+ isMarkedForDeletion && /* @__PURE__ */ jsx8("span", { className: getClassName5("deleteBadge"), children: "Marked for deletion" })
4093
3608
  ] }),
4094
3609
  /* @__PURE__ */ jsxs4("div", { className: getClassName5("versionActions"), children: [
4095
- !isDefault && !isMarkedForDeletion && /* @__PURE__ */ jsx11(Button2, { variant: "secondary", onClick: () => setSelectedVersion(version), children: "Set as Default" }),
4096
- /* @__PURE__ */ jsx11(Button2, { variant: "secondary", onClick: () => toggleVersionForDeletion(version), children: isMarkedForDeletion ? /* @__PURE__ */ jsxs4(Fragment5, { children: [
4097
- /* @__PURE__ */ jsx11(X, { size: 14 }),
3610
+ !isDefault && !isMarkedForDeletion && /* @__PURE__ */ jsx8(Button2, { variant: "secondary", onClick: () => setSelectedVersion(version), children: "Set as Default" }),
3611
+ /* @__PURE__ */ jsx8(Button2, { variant: "secondary", onClick: () => toggleVersionForDeletion(version), children: isMarkedForDeletion ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
3612
+ /* @__PURE__ */ jsx8(X, { size: 14 }),
4098
3613
  " Undo"
4099
- ] }) : /* @__PURE__ */ jsxs4(Fragment5, { children: [
4100
- /* @__PURE__ */ jsx11(Trash2, { size: 14 }),
3614
+ ] }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
3615
+ /* @__PURE__ */ jsx8(Trash2, { size: 14 }),
4101
3616
  " Delete"
4102
3617
  ] }) })
4103
3618
  ] })
@@ -4105,8 +3620,8 @@ var DrawerItem = (props) => {
4105
3620
  }) })
4106
3621
  ] }),
4107
3622
  versionsToDelete.size > 0 && /* @__PURE__ */ jsxs4("div", { className: getClassName5("section"), children: [
4108
- /* @__PURE__ */ jsx11("h3", { className: getClassName5("sectionTitle"), children: "Migration Settings" }),
4109
- /* @__PURE__ */ jsx11("div", { className: getClassName5("migrationOptions"), children: /* @__PURE__ */ jsx11(
3623
+ /* @__PURE__ */ jsx8("h3", { className: getClassName5("sectionTitle"), children: "Migration Settings" }),
3624
+ /* @__PURE__ */ jsx8("div", { className: getClassName5("migrationOptions"), children: /* @__PURE__ */ jsx8(
4110
3625
  "div",
4111
3626
  {
4112
3627
  className: getClassName5("migrationList"),
@@ -4124,8 +3639,8 @@ var DrawerItem = (props) => {
4124
3639
  className: `${getClassName5("migrationOption")} ${isSelected ? getClassName5("migrationOption--isSelected") : ""}`,
4125
3640
  onClick: () => setMigrationTarget(target.value),
4126
3641
  children: [
4127
- /* @__PURE__ */ jsx11("span", { className: getClassName5("migrationOptionLabel"), children: target.label }),
4128
- isSelected && /* @__PURE__ */ jsx11(Check, { size: 14 })
3642
+ /* @__PURE__ */ jsx8("span", { className: getClassName5("migrationOptionLabel"), children: target.label }),
3643
+ isSelected && /* @__PURE__ */ jsx8(Check, { size: 14 })
4129
3644
  ]
4130
3645
  },
4131
3646
  target.value
@@ -4133,49 +3648,48 @@ var DrawerItem = (props) => {
4133
3648
  })
4134
3649
  }
4135
3650
  ) }),
4136
- /* @__PURE__ */ jsx11("p", { className: getClassName5("helpText"), children: "Choose where to move existing instances of the deleted versions." })
3651
+ /* @__PURE__ */ jsx8("p", { className: getClassName5("helpText"), children: "Choose where to move existing instances of the deleted versions." })
4137
3652
  ] })
4138
- ] }) : /* @__PURE__ */ jsx11("div", { className: getClassName5("section"), children: /* @__PURE__ */ jsxs4("p", { children: [
3653
+ ] }) : /* @__PURE__ */ jsx8("div", { className: getClassName5("section"), children: /* @__PURE__ */ jsxs4("p", { children: [
4139
3654
  "Manage high-level settings for the ",
4140
- /* @__PURE__ */ jsx11("strong", { children: displayName }),
3655
+ /* @__PURE__ */ jsx8("strong", { children: displayName }),
4141
3656
  " component."
4142
3657
  ] }) }) }),
4143
3658
  /* @__PURE__ */ jsxs4("div", { className: getClassName5("modalFooter"), children: [
4144
3659
  /* @__PURE__ */ jsxs4("div", { className: getClassName5("footerLeft"), children: [
4145
3660
  useVersioning ? /* @__PURE__ */ jsxs4(Button2, { size: "medium", onClick: handleApply, children: [
4146
- /* @__PURE__ */ jsx11(Check, { size: 16 }),
3661
+ /* @__PURE__ */ jsx8(Check, { size: 16 }),
4147
3662
  " Apply Changes"
4148
- ] }) : /* @__PURE__ */ jsx11(Button2, { size: "medium", onClick: handleCancel, children: "Close" }),
3663
+ ] }) : /* @__PURE__ */ jsx8(Button2, { size: "medium", onClick: handleCancel, children: "Close" }),
4149
3664
  useVersioning && /* @__PURE__ */ jsxs4(Button2, { size: "medium", variant: "secondary", onClick: handleCancel, children: [
4150
- /* @__PURE__ */ jsx11(X, { size: 16 }),
3665
+ /* @__PURE__ */ jsx8(X, { size: 16 }),
4151
3666
  " Cancel"
4152
3667
  ] })
4153
3668
  ] }),
4154
- /* @__PURE__ */ jsx11("div", { className: getClassName5("footerRight"), children: /* @__PURE__ */ jsxs4(Button2, { size: "medium", variant: "secondary", onClick: handleDemolishClick, children: [
4155
- /* @__PURE__ */ jsx11(Trash2, { size: 16 }),
3669
+ /* @__PURE__ */ jsx8("div", { className: getClassName5("footerRight"), children: /* @__PURE__ */ jsxs4(Button2, { size: "medium", variant: "secondary", onClick: handleDemolishClick, children: [
3670
+ /* @__PURE__ */ jsx8(Trash2, { size: 16 }),
4156
3671
  " Demolish Component"
4157
3672
  ] }) })
4158
3673
  ] })
4159
3674
  ] }) })
4160
3675
  ] });
4161
3676
  }
4162
- return /* @__PURE__ */ jsx11(Fragment5, { children: props.children });
3677
+ return /* @__PURE__ */ jsx8(Fragment4, { children: props.children });
4163
3678
  };
4164
- var ComponentItem = DrawerItem;
4165
3679
 
4166
3680
  // src/puck/overrides/Drawer.tsx
4167
3681
  import { useState as useState5 } from "react";
4168
- import { createUsePuck as createUsePuck13, Drawer as PuckDrawer } from "@measured/puck";
3682
+ import { createUsePuck as createUsePuck12, Drawer as PuckDrawer } from "@measured/puck";
4169
3683
  import { ChevronDown, ChevronUp } from "lucide-react";
4170
3684
 
4171
3685
  // css-module:/home/osamu/Documents/netlisian-soft/packages/soft-config/src/puck/overrides/Drawer.module.css#css-module
4172
3686
  var Drawer_module_default = { "Drawer": "_Drawer_12zq5_1", "Drawer-category": "_Drawer-category_12zq5_7", "Drawer-category--isExpanded": "_Drawer-category--isExpanded_12zq5_15", "Drawer-categoryContent": "_Drawer-categoryContent_12zq5_19", "Drawer-categoryTitle": "_Drawer-categoryTitle_12zq5_27", "Drawer-categoryTitleIcon": "_Drawer-categoryTitleIcon_12zq5_63" };
4173
3687
 
4174
3688
  // src/puck/overrides/Drawer.tsx
4175
- import { jsx as jsx12, jsxs as jsxs5 } from "react/jsx-runtime";
3689
+ import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
3690
+ var useCustomPuck11 = createUsePuck12();
4176
3691
  var getClassName6 = get_class_name_factory_default("Drawer", Drawer_module_default);
4177
3692
  var getCategoryClassName = get_class_name_factory_default("Drawer-category", Drawer_module_default);
4178
- var usePuck3 = createUsePuck13();
4179
3693
  var CategorySection = ({
4180
3694
  id,
4181
3695
  title,
@@ -4192,12 +3706,12 @@ var CategorySection = ({
4192
3706
  onClick: () => onToggle(id),
4193
3707
  title: expanded ? `Collapse ${title}` : `Expand ${title}`,
4194
3708
  children: [
4195
- /* @__PURE__ */ jsx12("span", { children: title }),
4196
- /* @__PURE__ */ jsx12("span", { className: getClassName6("categoryTitleIcon"), children: expanded ? /* @__PURE__ */ jsx12(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx12(ChevronDown, { size: 12 }) })
3709
+ /* @__PURE__ */ jsx9("span", { children: title }),
3710
+ /* @__PURE__ */ jsx9("span", { className: getClassName6("categoryTitleIcon"), children: expanded ? /* @__PURE__ */ jsx9(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx9(ChevronDown, { size: 12 }) })
4197
3711
  ]
4198
3712
  }
4199
3713
  ),
4200
- /* @__PURE__ */ jsx12("div", { className: getClassName6("categoryContent"), children: /* @__PURE__ */ jsx12(PuckDrawer, { children: componentKeys.map((key) => /* @__PURE__ */ jsx12(
3714
+ /* @__PURE__ */ jsx9("div", { className: getClassName6("categoryContent"), children: /* @__PURE__ */ jsx9(PuckDrawer, { children: componentKeys.map((key) => /* @__PURE__ */ jsx9(
4201
3715
  PuckDrawer.Item,
4202
3716
  {
4203
3717
  name: key,
@@ -4209,8 +3723,8 @@ var CategorySection = ({
4209
3723
  ] });
4210
3724
  var Drawer = (_props) => {
4211
3725
  var _a, _b;
4212
- const config = usePuck3((s) => s.config);
4213
- const getPermissions = usePuck3((s) => s.getPermissions);
3726
+ const config = useCustomPuck11((s) => s.config);
3727
+ const getPermissions = useCustomPuck11((s) => s.getPermissions);
4214
3728
  const categories = (_a = config.categories) != null ? _a : {};
4215
3729
  const categorised = new Set(
4216
3730
  Object.values(categories).flatMap((cat) => {
@@ -4237,7 +3751,7 @@ var Drawer = (_props) => {
4237
3751
  });
4238
3752
  const toggle = (id) => setExpanded((prev) => __spreadProps(__spreadValues({}, prev), { [id]: !prev[id] }));
4239
3753
  if (categoryEntries.length === 0) {
4240
- return /* @__PURE__ */ jsx12(PuckDrawer, { children: allKeys.map((key) => /* @__PURE__ */ jsx12(
3754
+ return /* @__PURE__ */ jsx9(PuckDrawer, { children: allKeys.map((key) => /* @__PURE__ */ jsx9(
4241
3755
  PuckDrawer.Item,
4242
3756
  {
4243
3757
  name: key,
@@ -4251,7 +3765,7 @@ var Drawer = (_props) => {
4251
3765
  return /* @__PURE__ */ jsxs5("div", { className: getClassName6(), children: [
4252
3766
  categoryEntries.map(([id, cat]) => {
4253
3767
  var _a2, _b2, _c;
4254
- return /* @__PURE__ */ jsx12(
3768
+ return /* @__PURE__ */ jsx9(
4255
3769
  CategorySection,
4256
3770
  {
4257
3771
  id,
@@ -4266,7 +3780,7 @@ var Drawer = (_props) => {
4266
3780
  id
4267
3781
  );
4268
3782
  }),
4269
- otherKeys.length > 0 && /* @__PURE__ */ jsx12(
3783
+ otherKeys.length > 0 && /* @__PURE__ */ jsx9(
4270
3784
  CategorySection,
4271
3785
  {
4272
3786
  id: "__other__",
@@ -4281,17 +3795,19 @@ var Drawer = (_props) => {
4281
3795
  };
4282
3796
 
4283
3797
  // src/puck/overrides/HeaderActions.tsx
4284
- import { Button as Button3, createUsePuck as createUsePuck14 } from "@measured/puck";
4285
- import { Fragment as Fragment6, jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
4286
- var usePuck4 = createUsePuck14();
3798
+ import { Button as Button3, createUsePuck as createUsePuck13 } from "@measured/puck";
3799
+ import { Fragment as Fragment5, jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
3800
+ var useCustomPuck12 = createUsePuck13();
4287
3801
  var HeaderActions = ({ children }) => {
4288
3802
  const { handleComplete } = useComplete();
4289
3803
  const { handleCancel, canCancel } = useCancel();
4290
- const dispatch = usePuck4((s) => s.dispatch);
3804
+ const dispatch = useCustomPuck12((s) => s.dispatch);
3805
+ const appState = useCustomPuck12((s) => s.appState);
3806
+ const selectedItemSelector = appState.ui.itemSelector;
4291
3807
  const inspect = useSoftConfig((s) => s.builder.inspect);
4292
- return /* @__PURE__ */ jsx13(Fragment6, { children: canCancel ? /* @__PURE__ */ jsxs6(Fragment6, { children: [
4293
- /* @__PURE__ */ jsx13(Button3, { onClick: handleCancel, children: "Cancel" }),
4294
- /* @__PURE__ */ jsx13(
3808
+ return /* @__PURE__ */ jsx10(Fragment5, { children: canCancel ? /* @__PURE__ */ jsxs6(Fragment5, { children: [
3809
+ /* @__PURE__ */ jsx10(Button3, { onClick: handleCancel, children: "Cancel" }),
3810
+ /* @__PURE__ */ jsx10(
4295
3811
  Button3,
4296
3812
  {
4297
3813
  variant: "primary",
@@ -4299,7 +3815,7 @@ var HeaderActions = ({ children }) => {
4299
3815
  const completedComponent = handleComplete();
4300
3816
  if (completedComponent) {
4301
3817
  try {
4302
- inspect(completedComponent.id, dispatch);
3818
+ inspect(completedComponent.id, dispatch, selectedItemSelector);
4303
3819
  } catch (error) {
4304
3820
  notify.error(
4305
3821
  "Failed to inspect after completion: " + (error instanceof Error ? error.message : String(error))
@@ -4522,17 +4038,36 @@ var resolveSoftConfig = (data, softComponents, config) => {
4522
4038
  if (process.env.NODE_ENV === "development") {
4523
4039
  const validation = validateOnlyHardComponents(dissolved, softComponents);
4524
4040
  if (!validation.isValid) {
4525
- console.warn(
4526
- "Warning: Soft components still present after dissolution:",
4527
- validation.softComponentsFound
4041
+ alert(
4042
+ "Warning: Soft components still present after dissolution: " + String(
4043
+ validation.softComponentsFound
4044
+ )
4528
4045
  );
4529
4046
  }
4530
4047
  }
4531
4048
  return dissolved;
4532
4049
  };
4050
+
4051
+ // src/puck/lib/builder/generate-field-options.ts
4052
+ var hasArrayMappingPath = (value) => value.includes("[]");
4053
+ var isBareArrayPath = (value) => !hasArrayMappingPath(value) && !value.includes(".");
4054
+ function filterToOptionsForFrom(fromPath, toOptions) {
4055
+ if (!fromPath) return toOptions;
4056
+ const fromHasArrayMapping = hasArrayMappingPath(fromPath);
4057
+ const fromIsBareArray = isBareArrayPath(fromPath);
4058
+ return toOptions.filter((option) => {
4059
+ const optionHasArrayMapping = hasArrayMappingPath(option.value);
4060
+ if (fromHasArrayMapping) {
4061
+ return optionHasArrayMapping;
4062
+ }
4063
+ if (fromIsBareArray) {
4064
+ return isBareArrayPath(option.value);
4065
+ }
4066
+ return !optionHasArrayMapping;
4067
+ });
4068
+ }
4533
4069
  export {
4534
4070
  ActionBarOverride as ActionBar,
4535
- ComponentItem,
4536
4071
  Drawer as ComponentList,
4537
4072
  Drawer,
4538
4073
  DrawerItem,