@netlisian/softconfig 0.1.8 → 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,7 +1,7 @@
1
+ import * as _measured_puck from '@measured/puck';
2
+ import { Field, Fields, Config, DefaultComponentProps, History, AppState, PuckApi, ComponentData, ComponentConfig, RootData, AsFieldProps, WithChildren, Metadata, ResolveDataTrigger, PuckAction, OnAction, Data, Overrides as Overrides$1 } from '@measured/puck';
1
3
  import * as zustand from 'zustand';
2
4
  import { StoreApi } from 'zustand';
3
- import * as _measured_puck from '@measured/puck';
4
- import { Field, Fields, Config, DefaultComponentProps, History, AppState, PuckApi, ComponentData, ComponentConfig, RootData, AsFieldProps, WithChildren, Metadata, ResolveDataTrigger, PuckAction, Data, Overrides as Overrides$1 } 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';
@@ -153,89 +153,177 @@ type VersionedSoftComponent = {
153
153
  type SoftComponents = Record<string, VersionedSoftComponent>;
154
154
 
155
155
  type CompletedComponentResult = {
156
+ /**
157
+ * The generated unique registry key/identifier of the completed soft component.
158
+ */
156
159
  id: string;
160
+ /**
161
+ * The resolved semantic version string of the completed soft component version.
162
+ */
157
163
  version: string;
164
+ /**
165
+ * The compiled underlying JSON definition representing the soft component structure.
166
+ */
158
167
  softComponent: VersionedSoftComponent["versions"][string];
159
168
  };
160
169
  type BuildersSlice = {
161
170
  /**
162
- * Build a new soft component based on the selected item in history.
171
+ * Initializes the "build" mode to package standard component tree elements into a
172
+ * brand-new, unified, and reusable soft component.
173
+ *
174
+ * @param history - The current Puck workspace history timeline stack. Used to store
175
+ * the undo/redo states so they can be restored if the session is canceled.
176
+ * @param selectedItem - The component instance selected in the workspace that will
177
+ * serve as the seed/root of the building sandbox.
178
+ * @param itemSelector - Placement and index metadata of the selected item in the editor.
179
+ * @param puckDispatch - The Puck API dispatch function to apply state modifications.
180
+ * @param name - Optional initial user-facing label/display name for the new soft component.
163
181
  *
164
- * Steps:
165
- * 1. Data Modifications:
166
- * - Store History
167
- * - Set currently selected item to the root
168
- * 2. Soft Config Modifications:
169
- * - Update root to include: name, fields, fieldSettings, for soft component
170
- * - Update each component config to map the soft fields to component fields
171
- * - Update each component for slot settings (Dropzone enable/disable)
182
+ * @throws {Error} If no item is selected or the item selector is null.
183
+ *
184
+ * Lifecycle & Side Effects:
185
+ * 1. Clones and caches the current core soft configuration and history to the store.
186
+ * 2. Scans the workspace sub-tree to collect all descendent element IDs.
187
+ * 3. Schedules edit visibility highlights to visual-lock edits within the builder boundaries.
188
+ * 4. Transitions the builder workflow state to "building".
172
189
  */
173
190
  build: (history: History<AppState>[], selectedItem: PuckApi["selectedItem"], itemSelector: {
174
191
  index: number;
175
192
  zone?: string;
176
193
  } | null, puckDispatch: PuckApi["dispatch"], name?: string) => void | null;
177
194
  /**
178
- * Remodel the selected soft component by decomposing it and resetting as root.
195
+ * Enters "remodel" mode for an existing soft component, decomposing its compiled structure back
196
+ * into constituent discrete components inside the builder workspace.
197
+ *
198
+ * @param history - The current Puck history list to cache for later restoration.
199
+ * @param selectedItem - The compiled soft component instance selected in the editor.
200
+ * @param itemSelector - Workspace index and droppable zone metadata of the selected component.
201
+ * @param puckDispatch - The Puck API dispatch function.
202
+ * @param refreshPermission - Callback function to refresh access permissions (currently unused).
179
203
  *
180
- * Steps:
181
- * 1. Data Modifications:
182
- * - Store History
183
- * - Decompose and set selected soft component to root
184
- * 2. Soft Config Modifications:
185
- * - Update root with name, fields, fieldSettings for soft component
186
- * - Update each component config to map soft fields to component fields
187
- * - Update each component for slot settings (Dropzone enable/disable)
188
- * - Remove selected component or dependencies to avoid circular dependencies
204
+ * @throws {Error} If the selection parameters are missing, or if the target soft component
205
+ * definition cannot be resolved from the cache.
206
+ *
207
+ * Lifecycle & Side Effects:
208
+ * 1. Fetches the soft component version schema from the Zustand store.
209
+ * 2. Evaluates the reverse dependency graph to identify components depending on this soft component.
210
+ * This locks editing on dependent elements to avoid creating circular dependencies.
211
+ * 3. Explodes the soft component into its constituent raw components in-place within the document data.
212
+ * 4. Updates visual iframe overlays to confine editing to the decomposed sub-tree.
213
+ * 5. Transitions the builder workspace state to "remodeling".
189
214
  */
190
215
  remodel: (history: History<AppState>[], selectedItem: PuckApi["selectedItem"], itemSelector: {
191
216
  index: number;
192
217
  zone?: string;
193
- } | null, puckDispatch: PuckApi["dispatch"], refreshPermission: () => void) => void;
218
+ } | null, puckDispatch: PuckApi["dispatch"], refreshPermissions: () => void) => void;
194
219
  /**
195
- * Switch to a different version of the soft component being remodeled.
220
+ * Switches the active soft component inside the remodeling session to a different
221
+ * registered semantic version.
222
+ *
223
+ * @param componentName - The unique registry key of the soft component.
224
+ * @param newVersion - The target version to activate.
225
+ * @param currentProps - The current top-level properties configured for this element instance.
226
+ * @param puckDispatch - The Puck API dispatch function.
227
+ *
228
+ * @throws {Error} If the store is not currently in the 'remodeling' state, or if the
229
+ * requested version is missing.
196
230
  *
197
- * Steps:
198
- * 1. Get the soft component for the selected version
199
- * 2. Convert it back to AppState format
200
- * 3. Update the puck data with the new version's content
231
+ * Lifecycle & Side Effects:
232
+ * 1. Resolves the target version's raw layout structure from the store.
233
+ * 2. Re-runs soft component-to-AppState conversions for the target version.
234
+ * 3. Replaces the active remodeling workspace content in-place with the selected version's elements.
201
235
  */
202
- setVersion: (componentName: string, newVersion: string, currentProps: Record<string, any>, puckDispatch: PuckApi["dispatch"]) => void;
236
+ setVersion: (componentName: string, newVersion: string, currentProps: Record<string, any>, puckDispatch: PuckApi["dispatch"], getItemBySelector: PuckApi["getItemBySelector"], getSelectorForId: PuckApi["getSelectorForId"]) => void;
203
237
  /**
204
- * Mark the current build/remodel as complete.
238
+ * Finalizes the current build or remodel session, packaging all active workspace components
239
+ * into a compiled, versioned, reusable soft component configuration.
205
240
  *
206
- * Steps:
207
- * 1. Config Modifications:
208
- * - Compose the build settings into soft component
209
- * - Set the component to the config
210
- * - Restore permissions, resolve fields and resolve data of all components
211
- * 2. Data Modifications:
212
- * - Transform the last item of history to replace the source components into composed soft component
213
- * - Strip the build settings fields
214
- * - Apply modified history to puck data.
241
+ * @param appState - The current state of the builder editor workspace containing the composed elements.
242
+ * @param setHistories - Puck API callback to restore the original builder history timeline.
243
+ * @param getItemBySelector - Puck API utility to resolve a workspace item using its selector.
244
+ * @returns An object containing the generated component ID, version, and compiled soft component structure.
245
+ *
246
+ * @throws {Error} If the store is not in building/remodeling state, the root component is unnamed,
247
+ * or if the selected item cannot be resolved in the workspace.
248
+ *
249
+ * Lifecycle & Side Effects:
250
+ * 1. Converts display labels into safe, unique PascalCase configuration registration keys.
251
+ * 2. Packages workspace child items into a JSON-serializable versioned schema.
252
+ * 3. Re-registers the component with the core configuration components registry.
253
+ * 4. Categorizes the component within layout groups.
254
+ * 5. Restores original history timelines and transitions store state to "inspecting".
255
+ * 6. Rebuilds all other registered soft components that depend on this updated component.
215
256
  */
216
257
  complete: (appState: AppState<any>, setHistories: PuckApi["history"]["setHistories"], getItemBySelector: PuckApi["getItemBySelector"]) => CompletedComponentResult;
258
+ /**
259
+ * Permanently deletes a soft component registration and purges all of its active
260
+ * occurrences/instances from the active workspace document data.
261
+ *
262
+ * @param componentName - The unique registry name of the soft component to delete.
263
+ * @param data - The active workspace document data to scan and clean.
264
+ * @param puckDispatch - The Puck API dispatch function to apply document cleanups.
265
+ *
266
+ * @throws {Error} If the store is not currently in the stable 'ready' state.
267
+ */
217
268
  demolish: (componentName: string, data: AppState["data"], puckDispatch: PuckApi["dispatch"]) => void;
218
- inspect: (componentName: string, puckDispatch: PuckApi["dispatch"]) => void;
219
269
  /**
220
- * Mark the current build/remodel as complete.
270
+ * Concludes the inspection workflow, replacing the temporary seed item within the
271
+ * editor workspace document with the newly compiled soft component instance.
272
+ *
273
+ * @param componentName - The final compiled component registry name.
274
+ * @param puckDispatch - The Puck API dispatch function.
275
+ *
276
+ * @throws {Error} If the store is not currently in the 'inspecting' state.
277
+ *
278
+ * Lifecycle & Side Effects:
279
+ * 1. Walk the workspace tree to locate the temporary component being built/remodeled.
280
+ * 2. Replace it with the compiled component type and default versioned props.
281
+ * 3. Flushes layout restriction overlays on the iframe.
282
+ * 4. Resets active builder metadata and transitions state back to "ready".
283
+ */
284
+ inspect: (componentName: string, puckDispatch: PuckApi["dispatch"], selectedItemSelector: {
285
+ index: number;
286
+ zone?: string;
287
+ } | null) => void;
288
+ /**
289
+ * Discards all modifications made during the current build or remodel session,
290
+ * reverting the editor config, workspace elements, and histories back to their original state.
291
+ *
292
+ * @param setHistories - Puck API callback to restore the original history list.
221
293
  *
222
- * Steps:
223
- * 1. Config Modifications:
224
- * - Restore permissions, resolve fields and resolve data of all components
225
- * 2. Data Modifications:
226
- * - Restore history to puck data.
294
+ * Lifecycle & Side Effects:
295
+ * 1. Transitions store state to "cancelling" to suppress conflicting updates.
296
+ * 2. Re-applies the original workspace config and timeline histories.
297
+ * 3. Clears visual iframe constraints and resets active builder metadata back to normal.
227
298
  */
228
- cancel: (setHistories: PuckApi["history"]["setHistories"]) => void;
229
- /** Compose multiple components into a soft component.
230
- * 1. SoftComponent: Get soft fields + default values from the appState.root + sub-component maps + fixedProps
299
+ cancel: (setHistories: PuckApi["history"]["setHistories"], puckDispatch: PuckApi["dispatch"], selectedItemSelector: {
300
+ index: number;
301
+ zone?: string;
302
+ } | null) => void;
303
+ /**
304
+ * Internal compiler hook that converts builder editor workspace states (root props, children)
305
+ * into a unified `SoftComponent` schema and creates a versioned config.
306
+ *
307
+ * @param appState - The current builder editor state.
308
+ * @param componentName - The unique registry key for the soft component.
309
+ * @param editedItem - The original seed component that initiated the build session.
310
+ * @param displayName - The user-facing display name of the soft component.
311
+ * @param category - Optional layout category placement inside the component toolbox.
312
+ * @returns A tuple containing the `ComponentConfig` and its resolved version string, or undefined if failed.
313
+ *
314
+ * @throws {Error} If the component name is empty or collides with existing configs during a new build.
231
315
  */
232
316
  compose: (appState: AppState, componentName: string, editedItem: ComponentData, displayName: string, category?: string) => [ComponentConfig, string] | undefined;
233
- /** Break down a composed component into its parts.
234
- * 1. Get softComponentProps
235
- * 2. Create a virtual component with all the props from soft-component.
236
- * 3. Replace the softComponent with hardComponent
317
+ /**
318
+ * Utility to break down a composed soft component's props and children back into
319
+ * their discrete, uncompiled constituent elements.
320
+ *
321
+ * @param componentData - The compiled component data instance.
322
+ * @returns An array of unpacked standard child component data objects.
323
+ *
324
+ * @throws {Error} If the input component data lacks type or ID.
237
325
  */
238
- decompose: (componentData: ComponentData) => ComponentData[];
326
+ decompose: (componentData: ComponentData, keepMapField?: boolean) => ComponentData[];
239
327
  };
240
328
 
241
329
  type ActionEventPayload = {
@@ -306,7 +394,7 @@ type RenderFunc<Props extends Record<string, unknown> = {
306
394
  type Overrides = {
307
395
  componentLabelToName?: (label: string, context: Partial<BuilderRootConfig> & {
308
396
  existingKeys: string[];
309
- state: "building" | "remodeling" | "ready" | "inspecting";
397
+ state: Status;
310
398
  }) => string;
311
399
  componentNameToLabel?: (name: string) => string;
312
400
  onRemodel?: (name: string) => Record<string, unknown>;
@@ -339,14 +427,17 @@ type Overrides = {
339
427
  }, context: {
340
428
  editingComponent?: string;
341
429
  }) => {
342
- props: RootData<AsFieldProps<WithChildren<BuilderRootConfig>>> | Promise<RootData<AsFieldProps<WithChildren<BuilderRootConfig>>>>;
343
- readOnly: Readonly<Record<string, boolean>> | undefined;
344
- };
430
+ props?: Partial<AsFieldProps<WithChildren<BuilderRootConfig>>>;
431
+ readOnly?: Readonly<Record<string, boolean>>;
432
+ } | Promise<{
433
+ props?: Partial<AsFieldProps<WithChildren<BuilderRootConfig>>>;
434
+ readOnly?: Readonly<Record<string, boolean>>;
435
+ }>;
345
436
  mapComponentConfig?: (componentName: string, defaultConfig: ComponentConfig, rootProps: BuilderRootConfig & RootData) => ComponentConfig;
346
437
  };
347
438
 
348
439
  /** Represents the current editing mode of the Puck editor. */
349
- type Status = "building" | "remodeling" | "ready" | "inspecting";
440
+ type Status = "building" | "remodeling" | "ready" | "cancelling" | "assessing" | "inspecting";
350
441
  type AppStore = {
351
442
  /** The current merged Puck config (hard + soft components). Rebuilt on soft component changes. */
352
443
  softConfig: Config;
@@ -500,9 +591,21 @@ type AppStore = {
500
591
  * Always returns true when `state === "ready"` (no restrictions apply).
501
592
  */
502
593
  validateAction: (action: PuckAction, previousAction?: PuckAction) => boolean;
594
+ /** Names of the content areas where soft components can be built. */
595
+ contentAreaNames?: string[];
596
+ /** Setter for the content area names */
597
+ setContentAreaNames: (names?: string[]) => void;
598
+ /** Access to the puck dispatch function, stored during edits. */
599
+ puckDispatch?: ((action: PuckAction) => void) | null;
600
+ /** Setter for the puck dispatch function */
601
+ setPuckDispatch: (dispatch: ((action: PuckAction) => void) | null) => void;
602
+ /**
603
+ * Optional root action handler injected via the store creation.
604
+ */
605
+ rootActionHandler?: OnAction;
503
606
  };
504
607
  type AppStoreApi = StoreApi<AppStore>;
505
- declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: SoftComponents, overrides?: Overrides, onActions?: OnActionsCallback, showVersionFields?: boolean, customFields?: CustomFields) => zustand.UseBoundStore<Omit<StoreApi<AppStore>, "subscribe"> & {
608
+ declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: SoftComponents, overrides?: Overrides, onActions?: OnActionsCallback, showVersionFields?: boolean, customFields?: CustomFields, contentAreaNames?: string[]) => zustand.UseBoundStore<Omit<StoreApi<AppStore>, "subscribe"> & {
506
609
  subscribe: {
507
610
  (listener: (selectedState: AppStore, previousSelectedState: AppStore) => void): () => void;
508
611
  <U>(selector: (state: AppStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
@@ -528,8 +631,9 @@ declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: Soft
528
631
  * @param props.value - Optional external store API.
529
632
  * @param props.onActions - Callback triggered on Puck actions.
530
633
  * @param props.useVersioning - Flag to enable or disable versioning (defaults to false).
634
+ * @param props.contentAreaNames - Optional list of data paths mapping where soft components can be built or remodeled.
531
635
  */
532
- declare const SoftConfigProvider: ({ children, hardConfig, softComponents, customFields, overrides, value, onActions, useVersioning, }: {
636
+ declare const SoftConfigProvider: ({ children, hardConfig, softComponents, customFields, overrides, value, onActions, useVersioning, contentAreaNames, }: {
533
637
  children: (softConfig: Config) => ReactNode;
534
638
  hardConfig: Config;
535
639
  softComponents?: SoftComponents;
@@ -538,6 +642,7 @@ declare const SoftConfigProvider: ({ children, hardConfig, softComponents, custo
538
642
  value?: StoreApi<AppStore>;
539
643
  onActions?: OnActionsCallback;
540
644
  useVersioning?: boolean;
645
+ contentAreaNames?: string[];
541
646
  }) => react_jsx_runtime.JSX.Element;
542
647
 
543
648
  declare const createUseSoftConfig: () => <T>(selector: (state: AppStore) => T, equalityFn?: (a: T, b: T) => boolean) => T;
@@ -625,12 +730,6 @@ declare const DrawerItem: (props: {
625
730
  label?: string;
626
731
  children: React.ReactNode;
627
732
  }) => React.ReactElement;
628
- /** @deprecated Use DrawerItem instead */
629
- declare const ComponentItem: (props: {
630
- name: string;
631
- label?: string;
632
- children: React.ReactNode;
633
- }) => React.ReactElement;
634
733
 
635
734
  /**
636
735
  * Drawer — custom drawer override for the Puck editor.
@@ -713,22 +812,7 @@ declare const Modal: ({ children, onClose, isOpen, }: {
713
812
  */
714
813
  declare function filterToOptionsForFrom(fromPath: string | undefined, toOptions: MappingOption[]): MappingOption[];
715
814
 
716
- /**
717
- * Shared helper: evaluates `_map` entries and applies mapped values to component props.
718
- *
719
- * Used by both the live builder effect (root-config.tsx) and the runtime
720
- * resolver (resolve-soft-component-data.ts) so the logic stays in one place.
721
- *
722
- * Array construction order (for array targets like `items[].imageUrl`):
723
- * 1. Start from `unmappedArrayItemDefaultValues` on the map entry (initially populated
724
- * from the component's `defaultItemProps`). These are the single source of
725
- * truth for the item "template".
726
- * 2. Overlay the mapped value for each array index.
727
- * The result is a freshly-constructed array whose length equals the mapped
728
- * source array and whose unmapped props come from the defaults above.
729
- */
730
-
731
- declare const resolveValueByPath: (source: any, path: string) => any;
815
+ declare const resolveValueByPath: (source: unknown, path: string) => unknown;
732
816
  /**
733
817
  * Evaluate every `_map` entry and apply the results to `props`.
734
818
  *
@@ -740,10 +824,25 @@ declare const resolveValueByPath: (source: any, path: string) => any;
740
824
  * - `"propsFirst"` (runtime): prefer live prop values, fall back
741
825
  * to fieldSettings `defaultValue`.
742
826
  */
743
- declare function applyMapping(props: Record<string, any>, fieldSettings: Record<string, any>, map: MapEntry[], resolveInput?: "fieldSettings" | "propsFirst", options?: ApplyMappingOptions): ApplyMappingResult;
827
+ declare function applyMapping(props: DefaultComponentProps, fieldSettings: DefaultComponentProps, map: MapEntry[], resolveInput?: "fieldSettings" | "propsFirst", options?: ApplyMappingOptions): ApplyMappingResult;
744
828
 
745
829
  declare const isArrayMappingPath: (path: string) => boolean;
746
830
  declare const getArrayBasePath: (arrayPath: string) => string | null;
747
831
  declare const getArrayItemSubPath: (arrayPath: string) => string | null;
748
832
 
749
- 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, HeaderActions, 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, useSoftConfigStore };
833
+ type ZoneType = "root" | "dropzone" | "slot";
834
+ type PuckNodeData = {
835
+ data: ComponentData;
836
+ flatData: ComponentData;
837
+ parentId: string | null;
838
+ zone: string;
839
+ path: string[];
840
+ };
841
+ type PuckZoneData = {
842
+ contentIds: string[];
843
+ type: ZoneType;
844
+ };
845
+ type NodeIndex = Record<string, PuckNodeData>;
846
+ type ZoneIndex = Record<string, PuckZoneData>;
847
+
848
+ export { ActionBarOverride as ActionBar, type ActionEventPayload, type AppStore, type AppStoreApi, type ApplyMappingOptions, type ApplyMappingResult, type BuilderComponentConfig, type BuilderConfig, type BuilderRootConfig, Drawer as ComponentList, type CustomFieldDefinition, type CustomFieldReturnType, type CustomFields, Drawer, DrawerItem, type FieldSettings, Header, HeaderActions, type MapEntry, Modal, type NodeIndex, type OnActionsCallback, type Overrides, type PuckNodeData, type PuckZoneData, type SoftComponent, type SoftComponents, SoftConfigProvider, type SoftFieldDefinition, type SoftFieldSettings, type Status, type VersionedSoftComponent, type ZoneIndex, type ZoneType, applyMapping, confirm, createActionCallback, createSoftConfigStore, createUseSoftConfig, filterToOptionsForFrom, getArrayBasePath, getArrayItemSubPath, isArrayMappingPath, notify, resolveSoftConfig, resolveValueByPath, setConfirmHandler, setNotificationHandler, useBuild, useCancel, useComplete, useDecompose, useDemolish, useInspect, useRemodel, useSetDefaultVersion, useSoftConfig, useSoftConfigStore };