@netlisian/softconfig 0.1.4 → 0.1.6

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,36 +1,104 @@
1
1
  import * as zustand from 'zustand';
2
2
  import { StoreApi } from 'zustand';
3
3
  import * as _measured_puck from '@measured/puck';
4
- import { DefaultComponentProps, Field, Config, Fields, History, AppState, PuckApi, ComponentData, ComponentConfig, RootData, AsFieldProps, WithChildren, Metadata, ResolveDataTrigger, PuckAction, Data } from '@measured/puck';
4
+ import { Field, Fields, Config, DefaultComponentProps, History, AppState, PuckApi, ComponentData, ComponentConfig, RootData, AsFieldProps, WithChildren, Metadata, ResolveDataTrigger, PuckAction, Data } from '@measured/puck';
5
5
  import * as React$1 from 'react';
6
6
  import React__default, { ReactNode, ReactElement } from 'react';
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
8
 
9
+ type BuiltInSoftFieldType = "text" | "textarea" | "number" | "select" | "radio" | "array" | "object" | "reference";
10
+ type SoftFieldType = BuiltInSoftFieldType | string;
11
+ type CustomFieldReturnType = "string" | "number" | "boolean" | "object" | "array";
12
+ type SoftFieldDefinition = {
13
+ name: string;
14
+ type: SoftFieldType;
15
+ };
16
+ type FieldOption = {
17
+ label: string;
18
+ value: string | number | boolean | object | null | undefined;
19
+ };
20
+ interface SharedFieldSettings<TSubFieldSettings> {
21
+ defaultValue?: unknown;
22
+ min?: number;
23
+ max?: number;
24
+ step?: number;
25
+ options?: FieldOption[];
26
+ summary?: string;
27
+ summaryField?: string;
28
+ summaryExpression?: string;
29
+ subFields?: SoftFieldDefinition[];
30
+ subFieldSettings?: TSubFieldSettings;
31
+ customFieldType?: string;
32
+ customFieldReturnType?: CustomFieldReturnType;
33
+ }
34
+ interface SoftFieldSettingsEntry extends SharedFieldSettings<SoftFieldSettings> {
35
+ }
36
+ type SoftFieldSettings = Record<string, SoftFieldSettingsEntry>;
37
+ interface FieldSettingsEntry extends SharedFieldSettings<FieldSettings> {
38
+ label: string;
39
+ }
40
+ type FieldSettings = Record<string, FieldSettingsEntry>;
41
+ type CustomFieldSettingsOverrideProps = {
42
+ fieldName: string;
43
+ fieldType: string;
44
+ fieldSettings?: SoftFieldSettingsEntry;
45
+ originalFieldSettings: Fields;
46
+ };
47
+ type CustomFieldDefinition = {
48
+ field: Field;
49
+ returnType: CustomFieldReturnType;
50
+ subFields?: SoftFieldDefinition[];
51
+ subFieldSettings?: SoftFieldSettings;
52
+ fieldSettingsOverride?: (props: CustomFieldSettingsOverrideProps) => Fields;
53
+ };
54
+ type CustomFields = Record<string, CustomFieldDefinition>;
55
+
56
+ type MapEntry = {
57
+ mode?: "simple" | "cva";
58
+ from?: string | string[];
59
+ to?: string | string[];
60
+ cva?: {
61
+ base?: string;
62
+ variants?: Array<{
63
+ fieldId?: string;
64
+ classes?: Record<string, string>;
65
+ }>;
66
+ };
67
+ transform?: (values: unknown[], props: Record<string, unknown>) => unknown;
68
+ unmappedArrayItemDefaultValues?: Record<string, unknown>;
69
+ /** @deprecated in favour of unmappedArrayItemDefaultValues – kept for back-compat */
70
+ defaultOverrides?: Record<string, unknown>;
71
+ };
72
+ type ApplyMappingResult = {
73
+ newProps: Record<string, unknown>;
74
+ mappedArrayPaths: Set<string>;
75
+ changed: boolean;
76
+ };
77
+ type ApplyMappingOptions = {
78
+ sourceProps?: Record<string, unknown>;
79
+ arrayDefaults?: Record<string, unknown[]>;
80
+ };
81
+ type MappingOption = {
82
+ label: string;
83
+ value: string;
84
+ type: Field["type"] | "reference";
85
+ };
86
+
9
87
  type BuilderRootConfig = {
10
88
  _name: string;
11
89
  _category?: string;
12
90
  _version?: string;
13
91
  _versions?: string[];
14
- _fields?: {
15
- name: string;
16
- type: Field["type"];
17
- }[];
18
- _fieldSettings?: {
19
- [key: string]: any;
20
- };
21
- [key: string]: any;
92
+ _fields?: SoftFieldDefinition[];
93
+ _fieldSettings?: SoftFieldSettings;
94
+ [key: string]: unknown;
22
95
  };
23
96
  type BuilderComponentConfig = {
24
97
  _slot?: {
25
98
  slot: string;
26
99
  }[];
27
- _map?: {
28
- to: string | string[];
29
- from: string | string[];
30
- transform?: (inputs: any[], props: DefaultComponentProps) => any;
31
- [key: string]: any;
32
- }[];
33
- [key: string]: any;
100
+ _map?: MapEntry[];
101
+ [key: string]: unknown;
34
102
  };
35
103
  type BuilderConfig = Config<any, BuilderRootConfig>;
36
104
 
@@ -50,9 +118,9 @@ type SoftComponent = {
50
118
  name: string;
51
119
  category?: string;
52
120
  fields: Fields;
53
- fieldSettings?: Record<string, any>;
121
+ fieldSettings?: SoftFieldSettings;
54
122
  defaultProps: DefaultComponentProps;
55
- rootProps?: Record<string, any>;
123
+ rootProps?: Record<string, unknown>;
56
124
  components: SoftSubComponent;
57
125
  slots: {
58
126
  [slot: string]: DefaultComponentProps;
@@ -65,9 +133,9 @@ type VersionedSoftComponent = {
65
133
  versions: {
66
134
  [version: string]: {
67
135
  fields: Fields;
68
- fieldSettings?: Record<string, any>;
136
+ fieldSettings?: SoftFieldSettings;
69
137
  defaultProps: DefaultComponentProps;
70
- rootProps?: Record<string, any>;
138
+ rootProps?: Record<string, unknown>;
71
139
  components: SoftSubComponent;
72
140
  slots: {
73
141
  [slot: string]: DefaultComponentProps;
@@ -232,9 +300,7 @@ type ActionEventPayload = {
232
300
  };
233
301
  type OnActionsCallback = (event: ActionEventPayload) => void | Promise<void>;
234
302
 
235
- type RenderFunc<Props extends {
236
- [key: string]: any;
237
- } = {
303
+ type RenderFunc<Props extends Record<string, unknown> = {
238
304
  children: ReactNode;
239
305
  }> = (props: Props) => ReactElement;
240
306
  type Overrides = {
@@ -243,20 +309,12 @@ type Overrides = {
243
309
  state: "building" | "remodeling" | "ready" | "inspecting";
244
310
  }) => string;
245
311
  componentKeyToName?: (key: string) => string;
246
- onRemodel?: (key: string) => Record<string, any>;
312
+ onRemodel?: (key: string) => Record<string, unknown>;
247
313
  additionalRootFields?: Record<string, Field>;
248
314
  map?: RenderFunc<{
249
315
  rootProps: BuilderRootConfig;
250
- toOptions: {
251
- label: string;
252
- value: string;
253
- type: Field["type"] | "reference";
254
- }[];
255
- fromOptions: {
256
- label: string;
257
- value: string;
258
- type: Field["type"] | "reference";
259
- }[];
316
+ toOptions: MappingOption[];
317
+ fromOptions: MappingOption[];
260
318
  props: DefaultComponentProps;
261
319
  value: BuilderComponentConfig["_map"];
262
320
  onChange: (value: BuilderComponentConfig["_map"]) => void;
@@ -267,7 +325,7 @@ type Overrides = {
267
325
  version: string;
268
326
  subComponentPath: string[];
269
327
  softComponent: VersionedSoftComponent["versions"][string];
270
- }) => ((inputs: any[], props: DefaultComponentProps) => any) | undefined;
328
+ }) => ((inputs: unknown[], props: Record<string, unknown>) => unknown) | undefined;
271
329
  onActions?: OnActionsCallback;
272
330
  name?: Field<string>;
273
331
  categories?: Field<string | undefined>;
@@ -284,6 +342,7 @@ type Overrides = {
284
342
  props: RootData<AsFieldProps<WithChildren<BuilderRootConfig>>> | Promise<RootData<AsFieldProps<WithChildren<BuilderRootConfig>>>>;
285
343
  readOnly: Readonly<Record<string, boolean>> | undefined;
286
344
  };
345
+ mapComponentConfig?: (componentName: string, defaultConfig: ComponentConfig) => Partial<ComponentConfig>;
287
346
  };
288
347
 
289
348
  type Status = "building" | "remodeling" | "ready" | "inspecting";
@@ -295,6 +354,7 @@ type AppStore = {
295
354
  originalHistory: History[];
296
355
  storedConfig?: Config;
297
356
  overrides: Overrides;
357
+ customFields: CustomFields;
298
358
  onActions?: OnActionsCallback;
299
359
  itemSelector: {
300
360
  index: number;
@@ -368,7 +428,7 @@ type AppStore = {
368
428
  setShowVersionFields: (show: boolean) => void;
369
429
  };
370
430
  type AppStoreApi = StoreApi<AppStore>;
371
- declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: SoftComponents, overrides?: Overrides, onActions?: OnActionsCallback, showVersionFields?: boolean) => zustand.UseBoundStore<Omit<StoreApi<AppStore>, "subscribe"> & {
431
+ declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: SoftComponents, overrides?: Overrides, onActions?: OnActionsCallback, showVersionFields?: boolean, customFields?: CustomFields) => zustand.UseBoundStore<Omit<StoreApi<AppStore>, "subscribe"> & {
372
432
  subscribe: {
373
433
  (listener: (selectedState: AppStore, previousSelectedState: AppStore) => void): () => void;
374
434
  <U>(selector: (state: AppStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
@@ -378,10 +438,11 @@ declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: Soft
378
438
  };
379
439
  }>;
380
440
 
381
- declare const SoftConfigProvider: ({ children, hardConfig, softComponents, overrides, value, onActions, useVersioning, }: {
441
+ declare const SoftConfigProvider: ({ children, hardConfig, softComponents, customFields, overrides, value, onActions, useVersioning, }: {
382
442
  children: (softConfig: Config, softComponents: SoftComponents, iframeDoc: AppStore["setIframeDoc"], validateAction: (action: PuckAction) => boolean) => ReactNode;
383
443
  hardConfig: Config;
384
444
  softComponents: SoftComponents;
445
+ customFields?: CustomFields;
385
446
  overrides?: Overrides;
386
447
  value?: StoreApi<AppStore>;
387
448
  onActions?: OnActionsCallback;
@@ -402,9 +463,9 @@ declare const useRemodel: () => {
402
463
  version: string;
403
464
  softComponent: {
404
465
  fields: _measured_puck.Fields;
405
- fieldSettings?: Record<string, any>;
466
+ fieldSettings?: SoftFieldSettings;
406
467
  defaultProps: DefaultComponentProps;
407
- rootProps?: Record<string, any>;
468
+ rootProps?: Record<string, unknown>;
408
469
  components: SoftSubComponent;
409
470
  slots: {
410
471
  [slot: string]: DefaultComponentProps;
@@ -462,11 +523,13 @@ declare const ActionBarOverride: (props: {
462
523
 
463
524
  declare const DrawerItem: (props: {
464
525
  name: string;
526
+ label?: string;
465
527
  children: React.ReactNode;
466
528
  }) => React.ReactElement;
467
529
  /** @deprecated Use DrawerItem instead */
468
530
  declare const ComponentItem: (props: {
469
531
  name: string;
532
+ label?: string;
470
533
  children: React.ReactNode;
471
534
  }) => React.ReactElement;
472
535
 
@@ -541,4 +604,45 @@ declare const Modal: ({ children, onClose, isOpen, }: {
541
604
  isOpen: boolean;
542
605
  }) => react_jsx_runtime.JSX.Element;
543
606
 
544
- export { ActionBarOverride as ActionBar, type ActionEventPayload, type AppStore, type AppStoreApi, type BuilderComponentConfig, type BuilderConfig, type BuilderRootConfig, ComponentItem, Drawer as ComponentList, Drawer, DrawerItem, Header, Modal, type OnActionsCallback, type Overrides, type SoftComponent, type SoftComponents, SoftConfigProvider, type VersionedSoftComponent, confirm, createActionCallback, createSoftConfigStore, createUseSoftConfig, notify, resolveSoftConfig, setConfirmHandler, setNotificationHandler, useBuild, useCancel, useComplete, useDecompose, useDemolish, useInspect, useRemodel, useSetDefaultVersion, useSoftConfig };
607
+ /**
608
+ * Filters toOptions based on the selected fromPath.
609
+ * - If fromPath contains an array segment, only return array-path to-options.
610
+ * - If fromPath is a bare array, only return bare array to-options.
611
+ * - Otherwise, hide array-path to-options (prevent array-to-scalar mismatches).
612
+ */
613
+ declare function filterToOptionsForFrom(fromPath: string | undefined, toOptions: MappingOption[]): MappingOption[];
614
+
615
+ /**
616
+ * Shared helper: evaluates `_map` entries and applies mapped values to component props.
617
+ *
618
+ * Used by both the live builder effect (root-config.tsx) and the runtime
619
+ * resolver (resolve-soft-component-data.ts) so the logic stays in one place.
620
+ *
621
+ * Array construction order (for array targets like `items[].imageUrl`):
622
+ * 1. Start from `unmappedArrayItemDefaultValues` on the map entry (initially populated
623
+ * from the component's `defaultItemProps`). These are the single source of
624
+ * truth for the item "template".
625
+ * 2. Overlay the mapped value for each array index.
626
+ * The result is a freshly-constructed array whose length equals the mapped
627
+ * source array and whose unmapped props come from the defaults above.
628
+ */
629
+
630
+ declare const resolveValueByPath: (source: any, path: string) => any;
631
+ /**
632
+ * Evaluate every `_map` entry and apply the results to `props`.
633
+ *
634
+ * @param props The component props to mutate (caller should pass a shallow copy).
635
+ * @param fieldSettings Root-level `_fieldSettings` for resolving `from` paths.
636
+ * @param map The `_map` array from the component.
637
+ * @param resolveInput Strategy for resolving `from` values. Two modes:
638
+ * - `"fieldSettings"` (builder): read from `fieldSettings` only.
639
+ * - `"propsFirst"` (runtime): prefer live prop values, fall back
640
+ * to fieldSettings `defaultValue`.
641
+ */
642
+ declare function applyMapping(props: Record<string, any>, fieldSettings: Record<string, any>, map: MapEntry[], resolveInput?: "fieldSettings" | "propsFirst", options?: ApplyMappingOptions): ApplyMappingResult;
643
+
644
+ declare const isArrayMappingPath: (path: string) => boolean;
645
+ declare const getArrayBasePath: (arrayPath: string) => string | null;
646
+ declare const getArrayItemSubPath: (arrayPath: string) => string | null;
647
+
648
+ export { ActionBarOverride as ActionBar, type ActionEventPayload, type AppStore, type AppStoreApi, type ApplyMappingOptions, type ApplyMappingResult, type BuilderComponentConfig, type BuilderConfig, type BuilderRootConfig, ComponentItem, Drawer as ComponentList, type CustomFieldDefinition, type CustomFieldReturnType, type CustomFields, Drawer, DrawerItem, type FieldSettings, Header, type MapEntry, Modal, type OnActionsCallback, type Overrides, type SoftComponent, type SoftComponents, SoftConfigProvider, type SoftFieldDefinition, type SoftFieldSettings, type VersionedSoftComponent, applyMapping, confirm, createActionCallback, createSoftConfigStore, createUseSoftConfig, filterToOptionsForFrom, getArrayBasePath, getArrayItemSubPath, isArrayMappingPath, notify, resolveSoftConfig, resolveValueByPath, setConfirmHandler, setNotificationHandler, useBuild, useCancel, useComplete, useDecompose, useDemolish, useInspect, useRemodel, useSetDefaultVersion, useSoftConfig };