cogsbox-state 0.5.464 → 0.5.465

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.
package/dist/store.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import { create } from 'zustand';\r\nimport { ulid } from 'ulid';\r\nimport type {\r\n OptionsType,\r\n ReactivityType,\r\n StateKeys,\r\n SyncInfo,\r\n UpdateTypeDetail,\r\n} from './CogsState.js';\r\n\r\nimport { startTransition, type ReactNode } from 'react';\r\n\r\ntype StateUpdater<StateValue> =\r\n | StateValue\r\n | ((prevValue: StateValue) => StateValue);\r\n\r\nexport type FreshValuesObject = {\r\n pathsToValues?: string[];\r\n prevValue?: any;\r\n newValue?: any;\r\n timeStamp: number;\r\n};\r\n\r\ntype SyncLogType = {\r\n timeStamp: number;\r\n};\r\ntype StateValue = any;\r\n\r\nexport type TrieNode = {\r\n subscribers: Set<string>;\r\n children: Map<string, TrieNode>;\r\n};\r\n\r\nexport type FormRefStoreState = {\r\n formRefs: Map<string, React.RefObject<any>>;\r\n registerFormRef: (id: string, ref: React.RefObject<any>) => void;\r\n getFormRef: (id: string) => React.RefObject<any> | undefined;\r\n removeFormRef: (id: string) => void;\r\n // New method to get all refs for a stateKey\r\n getFormRefsByStateKey: (\r\n stateKey: string\r\n ) => Map<string, React.RefObject<any>>;\r\n};\r\n\r\nexport const formRefStore = create<FormRefStoreState>((set, get) => ({\r\n formRefs: new Map(),\r\n\r\n registerFormRef: (id, ref) =>\r\n set((state) => {\r\n const newRefs = new Map(state.formRefs);\r\n newRefs.set(id, ref);\r\n return { formRefs: newRefs };\r\n }),\r\n\r\n getFormRef: (id) => get().formRefs.get(id),\r\n\r\n removeFormRef: (id) =>\r\n set((state) => {\r\n const newRefs = new Map(state.formRefs);\r\n newRefs.delete(id);\r\n return { formRefs: newRefs };\r\n }),\r\n\r\n // Get all refs that start with the stateKey prefix\r\n getFormRefsByStateKey: (stateKey) => {\r\n const allRefs = get().formRefs;\r\n const stateKeyPrefix = stateKey + '.';\r\n const filteredRefs = new Map();\r\n\r\n allRefs.forEach((ref, id) => {\r\n if (id.startsWith(stateKeyPrefix) || id === stateKey) {\r\n filteredRefs.set(id, ref);\r\n }\r\n });\r\n\r\n return filteredRefs;\r\n },\r\n}));\r\nexport type ComponentsType = {\r\n components?: Map<\r\n string,\r\n {\r\n forceUpdate: () => void;\r\n paths: Set<string>;\r\n deps?: any[];\r\n prevDeps?: any[];\r\n depsFunction?: (state: any) => any[] | true;\r\n reactiveType: ReactivityType[] | ReactivityType;\r\n }\r\n >;\r\n};\r\nexport type ShadowMetadata = {\r\n id?: string;\r\n\r\n stateSource?: 'default' | 'server' | 'localStorage';\r\n lastServerSync?: number;\r\n isDirty?: boolean;\r\n baseServerState?: any;\r\n\r\n arrayKeys?: string[];\r\n\r\n fields?: Record<string, any>;\r\n virtualizer?: {\r\n itemHeight?: number;\r\n domRef?: HTMLElement | null;\r\n };\r\n syncInfo?: { status: string };\r\n validation?: ValidationState;\r\n lastUpdated?: number;\r\n value?: any;\r\n classSignals?: Array<{\r\n id: string;\r\n effect: string;\r\n lastClasses: string;\r\n deps: any[];\r\n }>;\r\n signals?: Array<{\r\n instanceId: string;\r\n parentId: string;\r\n position: number;\r\n effect?: string;\r\n }>;\r\n mapWrappers?: Array<{\r\n instanceId: string;\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n mapFn: (\r\n setter: any,\r\n index: number,\r\n\r\n arraySetter: any\r\n ) => ReactNode;\r\n containerRef: HTMLDivElement | null;\r\n rebuildStateShape: any;\r\n }>;\r\n transformCaches?: Map<\r\n string,\r\n {\r\n validIds: string[];\r\n computedAt: number;\r\n transforms: Array<{ type: 'filter' | 'sort'; fn: Function }>;\r\n }\r\n >;\r\n pathComponents?: Set<string>;\r\n streams?: Map<\r\n string,\r\n {\r\n buffer: any[];\r\n flushTimer: NodeJS.Timeout | null;\r\n }\r\n >;\r\n} & ComponentsType;\r\n\r\nexport type ValidationStatus =\r\n | 'PRISTINE' // Untouched, matches initial state.\r\n | 'DIRTY' // Changed, but no validation run yet.\r\n | 'VALID_LIVE' // Valid while typing.\r\n | 'INVALID_LIVE' // Gentle error during typing.\r\n | 'VALIDATION_FAILED' // Hard error on blur/submit.\r\n | 'VALID_PENDING_SYNC' // Passed validation, ready for sync.\r\n | 'SYNCING' // Actively being sent to the server.\r\n | 'SYNCED' // Server confirmed success.\r\n | 'SYNC_FAILED'; // Server rejected the data.\r\n\r\nexport type ValidationState = {\r\n status: ValidationStatus;\r\n message?: string;\r\n lastValidated?: number;\r\n validatedValue?: any;\r\n};\r\nexport type CogsEvent =\r\n | { type: 'INSERT'; path: string; itemKey: string; index: number }\r\n | { type: 'REMOVE'; path: string; itemKey: string }\r\n | { type: 'UPDATE'; path: string; newValue: any }\r\n | { type: 'ITEMHEIGHT'; itemKey: string; height: number }\r\n | { type: 'RELOAD'; path: string };\r\nexport type CogsGlobalState = {\r\n updateQueue: Set<() => void>;\r\n isFlushScheduled: boolean;\r\n\r\n flushUpdates: () => void;\r\n\r\n // --- Shadow State and Subscription System ---\r\n registerComponent: (\r\n stateKey: string,\r\n componentId: string,\r\n registration: any\r\n ) => void;\r\n unregisterComponent: (stateKey: string, componentId: string) => void;\r\n addPathComponent: (\r\n stateKey: string,\r\n dependencyPath: string[],\r\n fullComponentId: string\r\n ) => void;\r\n shadowStateStore: Map<string, ShadowMetadata>;\r\n\r\n markAsDirty: (\r\n key: string,\r\n path: string[],\r\n options: { bubble: boolean }\r\n ) => void;\r\n // These method signatures stay the same\r\n initializeShadowState: (key: string, initialState: any) => void;\r\n updateShadowAtPath: (key: string, path: string[], newValue: any) => void;\r\n insertShadowArrayElement: (\r\n key: string,\r\n arrayPath: string[],\r\n newItem: any\r\n ) => void;\r\n removeShadowArrayElement: (key: string, arrayPath: string[]) => void;\r\n getShadowValue: (\r\n key: string,\r\n\r\n validArrayIds?: string[]\r\n ) => any;\r\n\r\n getShadowMetadata: (\r\n key: string,\r\n path: string[]\r\n ) => ShadowMetadata | undefined;\r\n setShadowMetadata: (\r\n key: string,\r\n path: string[],\r\n metadata: Omit<ShadowMetadata, 'id'>\r\n ) => void;\r\n setTransformCache: (\r\n key: string,\r\n path: string[],\r\n cacheKey: string,\r\n cacheData: any\r\n ) => void;\r\n\r\n pathSubscribers: Map<string, Set<(newValue: any) => void>>;\r\n subscribeToPath: (\r\n path: string,\r\n callback: (newValue: any) => void\r\n ) => () => void;\r\n notifyPathSubscribers: (updatedPath: string, newValue: any) => void;\r\n\r\n selectedIndicesMap: Map<string, string>; // stateKey -> (parentPath -> selectedIndex)\r\n getSelectedIndex: (stateKey: string, validArrayIds?: string[]) => number;\r\n setSelectedIndex: (key: string, itemKey: string) => void;\r\n clearSelectedIndex: ({ arrayKey }: { arrayKey: string }) => void;\r\n clearSelectedIndexesForState: (stateKey: string) => void;\r\n\r\n // --- Core State and Updaters ---\r\n\r\n initialStateOptions: { [key: string]: OptionsType };\r\n\r\n initialStateGlobal: { [key: string]: StateValue };\r\n\r\n updateInitialStateGlobal: (key: string, newState: StateValue) => void;\r\n\r\n getInitialOptions: (key: string) => OptionsType | undefined;\r\n setInitialStateOptions: (key: string, value: OptionsType) => void;\r\n\r\n serverStateUpdates: Map<\r\n string,\r\n {\r\n data: any;\r\n status: 'loading' | 'success' | 'error';\r\n timestamp: number;\r\n }\r\n >;\r\n\r\n setServerStateUpdate: (key: string, serverState: any) => void;\r\n\r\n stateLog: Map<string, Map<string, UpdateTypeDetail>>;\r\n syncInfoStore: Map<string, SyncInfo>;\r\n addStateLog: (key: string, update: UpdateTypeDetail) => void;\r\n\r\n setSyncInfo: (key: string, syncInfo: SyncInfo) => void;\r\n getSyncInfo: (key: string) => SyncInfo | null;\r\n};\r\nconst isSimpleObject = (value: any): boolean => {\r\n // Most common cases first\r\n if (value === null || typeof value !== 'object') return false;\r\n\r\n // Arrays are simple objects\r\n if (Array.isArray(value)) return true;\r\n\r\n // Plain objects second most common\r\n if (value.constructor === Object) return true;\r\n\r\n // Everything else is not simple\r\n return false;\r\n};\r\nexport const getGlobalStore = create<CogsGlobalState>((set, get) => ({\r\n updateQueue: new Set<() => void>(),\r\n // A flag to ensure we only schedule the flush once per event-loop tick.\r\n isFlushScheduled: false,\r\n\r\n // This function is called by queueMicrotask to execute all queued updates.\r\n flushUpdates: () => {\r\n const { updateQueue } = get();\r\n\r\n if (updateQueue.size > 0) {\r\n startTransition(() => {\r\n updateQueue.forEach((updateFn) => updateFn());\r\n });\r\n }\r\n\r\n // Clear the queue and reset the flag for the next event loop tick.\r\n set({ updateQueue: new Set(), isFlushScheduled: false });\r\n },\r\n addPathComponent: (stateKey, dependencyPath, fullComponentId) => {\r\n set((state) => {\r\n const newShadowStore = new Map(state.shadowStateStore);\r\n const dependencyKey = [stateKey, ...dependencyPath].join('.');\r\n\r\n // --- Part 1: Update the path's own metadata ---\r\n const pathMeta = newShadowStore.get(dependencyKey) || {};\r\n // Create a *new* Set to ensure immutability\r\n const pathComponents = new Set(pathMeta.pathComponents);\r\n pathComponents.add(fullComponentId);\r\n // Update the metadata for the specific path\r\n newShadowStore.set(dependencyKey, { ...pathMeta, pathComponents });\r\n\r\n // --- Part 2: Update the component's own list of paths ---\r\n const rootMeta = newShadowStore.get(stateKey) || {};\r\n const component = rootMeta.components?.get(fullComponentId);\r\n\r\n // If the component exists, update its `paths` set immutably\r\n if (component) {\r\n const newPaths = new Set(component.paths);\r\n newPaths.add(dependencyKey);\r\n\r\n const newComponentRegistration = { ...component, paths: newPaths };\r\n const newComponentsMap = new Map(rootMeta.components);\r\n newComponentsMap.set(fullComponentId, newComponentRegistration);\r\n\r\n // Update the root metadata with the new components map\r\n newShadowStore.set(stateKey, {\r\n ...rootMeta,\r\n components: newComponentsMap,\r\n });\r\n }\r\n\r\n // Return the final, updated state\r\n return { shadowStateStore: newShadowStore };\r\n });\r\n },\r\n registerComponent: (stateKey, fullComponentId, registration) => {\r\n set((state) => {\r\n const newShadowStore = new Map(state.shadowStateStore);\r\n const rootMeta = newShadowStore.get(stateKey) || {};\r\n const components = new Map(rootMeta.components);\r\n components.set(fullComponentId, registration);\r\n newShadowStore.set(stateKey, { ...rootMeta, components });\r\n return { shadowStateStore: newShadowStore };\r\n });\r\n },\r\n\r\n unregisterComponent: (stateKey, fullComponentId) => {\r\n set((state) => {\r\n const newShadowStore = new Map(state.shadowStateStore);\r\n const rootMeta = newShadowStore.get(stateKey);\r\n if (!rootMeta?.components) {\r\n return state; // Return original state, no change needed\r\n }\r\n\r\n const components = new Map(rootMeta.components);\r\n const wasDeleted = components.delete(fullComponentId);\r\n\r\n // Only update state if something was actually deleted\r\n if (wasDeleted) {\r\n newShadowStore.set(stateKey, { ...rootMeta, components });\r\n return { shadowStateStore: newShadowStore };\r\n }\r\n\r\n return state; // Nothing changed\r\n });\r\n },\r\n markAsDirty: (key: string, path: string[], options = { bubble: true }) => {\r\n const { shadowStateStore } = get();\r\n const updates = new Map<string, ShadowMetadata>();\r\n\r\n const setDirty = (currentPath: string[]) => {\r\n const fullKey = [key, ...currentPath].join('.');\r\n const meta = shadowStateStore.get(fullKey) || {};\r\n\r\n // If already dirty, no need to update\r\n if (meta.isDirty === true) {\r\n return true; // Return true to indicate parent is dirty\r\n }\r\n\r\n updates.set(fullKey, { ...meta, isDirty: true });\r\n return false; // Not previously dirty\r\n };\r\n\r\n // Mark the target path\r\n setDirty(path);\r\n\r\n // Bubble up if requested\r\n if (options.bubble) {\r\n let parentPath = [...path];\r\n while (parentPath.length > 0) {\r\n parentPath.pop();\r\n const wasDirty = setDirty(parentPath);\r\n if (wasDirty) {\r\n break; // Stop bubbling if parent was already dirty\r\n }\r\n }\r\n }\r\n\r\n // Apply all updates at once\r\n if (updates.size > 0) {\r\n set((state) => {\r\n updates.forEach((meta, key) => {\r\n state.shadowStateStore.set(key, meta);\r\n });\r\n return state;\r\n });\r\n }\r\n },\r\n serverStateUpdates: new Map(),\r\n setServerStateUpdate: (key, serverState) => {\r\n set((state) => {\r\n const newMap = new Map(state.serverStateUpdates);\r\n newMap.set(key, serverState);\r\n return { serverStateUpdates: newMap };\r\n });\r\n\r\n // Notify all subscribers for this key\r\n get().notifyPathSubscribers(key, {\r\n type: 'SERVER_STATE_UPDATE',\r\n serverState,\r\n });\r\n },\r\n shadowStateStore: new Map(),\r\n getShadowNode: (key: string) => get().shadowStateStore.get(key),\r\n pathSubscribers: new Map<string, Set<(newValue: any) => void>>(),\r\n\r\n subscribeToPath: (path, callback) => {\r\n const subscribers = get().pathSubscribers;\r\n const subsForPath = subscribers.get(path) || new Set();\r\n subsForPath.add(callback);\r\n subscribers.set(path, subsForPath);\r\n\r\n return () => {\r\n const currentSubs = get().pathSubscribers.get(path);\r\n if (currentSubs) {\r\n currentSubs.delete(callback);\r\n if (currentSubs.size === 0) {\r\n get().pathSubscribers.delete(path);\r\n }\r\n }\r\n };\r\n },\r\n\r\n notifyPathSubscribers: (updatedPath, newValue) => {\r\n const subscribers = get().pathSubscribers;\r\n const subs = subscribers.get(updatedPath);\r\n\r\n if (subs) {\r\n subs.forEach((callback) => callback(newValue));\r\n }\r\n },\r\n\r\n initializeShadowState: (key: string, initialState: any) => {\r\n set((state) => {\r\n // 1. Make a copy of the current store to modify it\r\n const newShadowStore = new Map(state.shadowStateStore);\r\n console.log('initializeShadowState');\r\n // 2. PRESERVE the existing components map before doing anything else\r\n const existingRootMeta = newShadowStore.get(key);\r\n const preservedComponents = existingRootMeta?.components;\r\n\r\n // 3. Wipe all old shadow entries for this state key\r\n const prefixToDelete = key + '.';\r\n for (const k of Array.from(newShadowStore.keys())) {\r\n if (k === key || k.startsWith(prefixToDelete)) {\r\n newShadowStore.delete(k);\r\n }\r\n }\r\n\r\n // 4. Run your original logic to rebuild the state tree from scratch\r\n const processValue = (value: any, path: string[]) => {\r\n const nodeKey = [key, ...path].join('.');\r\n\r\n if (Array.isArray(value)) {\r\n const childIds: string[] = [];\r\n value.forEach(() => {\r\n const itemId = `id:${ulid()}`;\r\n childIds.push(nodeKey + '.' + itemId);\r\n });\r\n newShadowStore.set(nodeKey, { arrayKeys: childIds });\r\n value.forEach((item, index) => {\r\n const itemId = childIds[index]!.split('.').pop();\r\n processValue(item, [...path!, itemId!]);\r\n });\r\n } else if (isSimpleObject(value)) {\r\n const fields = Object.fromEntries(\r\n Object.keys(value).map((k) => [k, nodeKey + '.' + k])\r\n );\r\n newShadowStore.set(nodeKey, { fields });\r\n Object.keys(value).forEach((k) => {\r\n processValue(value[k], [...path, k]);\r\n });\r\n } else {\r\n newShadowStore.set(nodeKey, { value });\r\n }\r\n };\r\n processValue(initialState, []);\r\n\r\n // 5. RESTORE the preserved components map onto the new root metadata\r\n if (preservedComponents) {\r\n const newRootMeta = newShadowStore.get(key) || {};\r\n newShadowStore.set(key, {\r\n ...newRootMeta,\r\n components: preservedComponents,\r\n });\r\n }\r\n\r\n // 6. Return the completely updated state\r\n return { shadowStateStore: newShadowStore };\r\n });\r\n },\r\n\r\n getShadowValue: (fullKey: string, validArrayIds?: string[]) => {\r\n const memo = new Map<string, any>();\r\n const reconstruct = (keyToBuild: string, ids?: string[]): any => {\r\n if (memo.has(keyToBuild)) {\r\n return memo.get(keyToBuild);\r\n }\r\n\r\n const shadowMeta = get().shadowStateStore.get(keyToBuild);\r\n if (!shadowMeta) {\r\n return undefined;\r\n }\r\n\r\n if (shadowMeta.value !== undefined) {\r\n return shadowMeta.value;\r\n }\r\n\r\n let result: any; // The value we are about to build.\r\n\r\n if (shadowMeta.arrayKeys) {\r\n const keys = ids ?? shadowMeta.arrayKeys;\r\n result = [];\r\n memo.set(keyToBuild, result);\r\n keys.forEach((itemKey) => {\r\n result.push(reconstruct(itemKey));\r\n });\r\n } else if (shadowMeta.fields) {\r\n result = {};\r\n memo.set(keyToBuild, result);\r\n Object.entries(shadowMeta.fields).forEach(([key, fieldPath]) => {\r\n result[key] = reconstruct(fieldPath as string);\r\n });\r\n } else {\r\n result = undefined;\r\n }\r\n\r\n // Return the final, fully populated result.\r\n return result;\r\n };\r\n\r\n // Start the process by calling the inner function on the root key.\r\n return reconstruct(fullKey, validArrayIds);\r\n },\r\n getShadowMetadata: (key: string, path: string[]) => {\r\n const fullKey = [key, ...path].join('.');\r\n\r\n return get().shadowStateStore.get(fullKey);\r\n },\r\n\r\n setShadowMetadata: (key, path, metadata) => {\r\n const fullKey = [key, ...path].join('.');\r\n const existingMeta = get().shadowStateStore.get(fullKey);\r\n\r\n // --- THIS IS THE TRAP ---\r\n // If the existing metadata HAS a components map, but the NEW metadata DOES NOT,\r\n // it means we are about to wipe it out. This is the bug.\r\n if (existingMeta?.components && !metadata.components) {\r\n console.group(\r\n '%c🚨 RACE CONDITION DETECTED! 🚨',\r\n 'color: red; font-size: 18px; font-weight: bold;'\r\n );\r\n console.error(\r\n `An overwrite is about to happen on stateKey: \"${key}\" at path: [${path.join(', ')}]`\r\n );\r\n console.log(\r\n 'The EXISTING metadata had a components map:',\r\n existingMeta.components\r\n );\r\n console.log(\r\n 'The NEW metadata is trying to save WITHOUT a components map:',\r\n metadata\r\n );\r\n console.log(\r\n '%cStack trace to the function that caused this overwrite:',\r\n 'font-weight: bold;'\r\n );\r\n console.trace(); // This prints the call stack, leading you to the bad code.\r\n console.groupEnd();\r\n }\r\n // --- END OF TRAP ---\r\n\r\n const newShadowStore = new Map(get().shadowStateStore);\r\n const finalMeta = { ...(existingMeta || {}), ...metadata };\r\n newShadowStore.set(fullKey, finalMeta);\r\n set({ shadowStateStore: newShadowStore });\r\n },\r\n setTransformCache: (\r\n key: string,\r\n path: string[],\r\n cacheKey: string,\r\n cacheData: any\r\n ) => {\r\n const fullKey = [key, ...path].join('.');\r\n const newShadowStore = new Map(get().shadowStateStore);\r\n const existing = newShadowStore.get(fullKey) || {};\r\n\r\n // Initialize transformCaches if it doesn't exist\r\n if (!existing.transformCaches) {\r\n existing.transformCaches = new Map();\r\n }\r\n\r\n // Update just the specific cache entry\r\n existing.transformCaches.set(cacheKey, cacheData);\r\n\r\n // Update shadow store WITHOUT notifying path subscribers\r\n newShadowStore.set(fullKey, existing);\r\n set({ shadowStateStore: newShadowStore });\r\n\r\n // Don't call notifyPathSubscribers here - cache updates shouldn't trigger renders\r\n },\r\n insertShadowArrayElement: (\r\n key: string,\r\n arrayPath: string[],\r\n newItem: any\r\n ) => {\r\n const newShadowStore = new Map(get().shadowStateStore);\r\n const arrayKey = [key, ...arrayPath].join('.');\r\n const parentMeta = newShadowStore.get(arrayKey);\r\n\r\n if (!parentMeta || !parentMeta.arrayKeys) return;\r\n\r\n const newItemId = `id:${ulid()}`;\r\n const fullItemKey = arrayKey + '.' + newItemId;\r\n\r\n // Just add to the end (or at a specific index if provided)\r\n const newArrayKeys = [...parentMeta.arrayKeys];\r\n newArrayKeys.push(fullItemKey); // Or use splice if you have an index\r\n newShadowStore.set(arrayKey, { ...parentMeta, arrayKeys: newArrayKeys });\r\n\r\n // Process the new item - but use the correct logic\r\n const processNewItem = (value: any, path: string[]) => {\r\n const nodeKey = [key, ...path].join('.');\r\n\r\n if (Array.isArray(value)) {\r\n // Handle arrays...\r\n } else if (typeof value === 'object' && value !== null) {\r\n // Create fields mapping\r\n const fields = Object.fromEntries(\r\n Object.keys(value).map((k) => [k, nodeKey + '.' + k])\r\n );\r\n newShadowStore.set(nodeKey, { fields });\r\n\r\n // Process each field\r\n Object.entries(value).forEach(([k, v]) => {\r\n processNewItem(v, [...path, k]);\r\n });\r\n } else {\r\n // Primitive value\r\n newShadowStore.set(nodeKey, { value });\r\n }\r\n };\r\n\r\n processNewItem(newItem, [...arrayPath, newItemId]);\r\n set({ shadowStateStore: newShadowStore });\r\n\r\n get().notifyPathSubscribers(arrayKey, {\r\n type: 'INSERT',\r\n path: arrayKey,\r\n itemKey: fullItemKey,\r\n });\r\n },\r\n removeShadowArrayElement: (key: string, itemPath: string[]) => {\r\n const newShadowStore = new Map(get().shadowStateStore);\r\n\r\n // Get the full item key (e.g., \"stateKey.products.id:xxx\")\r\n const itemKey = [key, ...itemPath].join('.');\r\n\r\n // Extract parent path and item ID\r\n const parentPath = itemPath.slice(0, -1);\r\n const parentKey = [key, ...parentPath].join('.');\r\n\r\n // Get parent metadata\r\n const parentMeta = newShadowStore.get(parentKey);\r\n\r\n if (parentMeta && parentMeta.arrayKeys) {\r\n // Find the index of the item to remove\r\n const indexToRemove = parentMeta.arrayKeys.findIndex(\r\n (arrayItemKey) => arrayItemKey === itemKey\r\n );\r\n\r\n if (indexToRemove !== -1) {\r\n // Create new array keys with the item removed\r\n const newArrayKeys = parentMeta.arrayKeys.filter(\r\n (arrayItemKey) => arrayItemKey !== itemKey\r\n );\r\n\r\n // Update parent with new array keys\r\n newShadowStore.set(parentKey, {\r\n ...parentMeta,\r\n arrayKeys: newArrayKeys,\r\n });\r\n\r\n // Delete all data associated with the removed item\r\n const prefixToDelete = itemKey + '.';\r\n for (const k of Array.from(newShadowStore.keys())) {\r\n if (k === itemKey || k.startsWith(prefixToDelete)) {\r\n newShadowStore.delete(k);\r\n }\r\n }\r\n }\r\n }\r\n\r\n set({ shadowStateStore: newShadowStore });\r\n\r\n get().notifyPathSubscribers(parentKey, {\r\n type: 'REMOVE',\r\n path: parentKey,\r\n itemKey: itemKey, // The exact ID of the removed item\r\n });\r\n },\r\n\r\n updateShadowAtPath: (key, path, newValue) => {\r\n const fullKey = [key, ...path].join('.');\r\n\r\n // Optimization: Only update if value actually changed\r\n const existingMeta = get().shadowStateStore.get(fullKey);\r\n if (existingMeta?.value === newValue && !isSimpleObject(newValue)) {\r\n return; // Skip update for unchanged primitives\r\n }\r\n\r\n // CHANGE: Don't clone the entire Map, just update in place\r\n set((state) => {\r\n const store = state.shadowStateStore;\r\n\r\n if (!isSimpleObject(newValue)) {\r\n const meta = store.get(fullKey) || {};\r\n store.set(fullKey, { ...meta, value: newValue });\r\n } else {\r\n // Handle objects by iterating\r\n const processObject = (currentPath: string[], objectToSet: any) => {\r\n const currentFullKey = [key, ...currentPath].join('.');\r\n const meta = store.get(currentFullKey);\r\n\r\n if (meta && meta.fields) {\r\n for (const fieldKey in objectToSet) {\r\n if (Object.prototype.hasOwnProperty.call(objectToSet, fieldKey)) {\r\n const childValue = objectToSet[fieldKey];\r\n const childFullPath = meta.fields[fieldKey];\r\n\r\n if (childFullPath) {\r\n if (isSimpleObject(childValue)) {\r\n processObject(\r\n childFullPath.split('.').slice(1),\r\n childValue\r\n );\r\n } else {\r\n const existingChildMeta = store.get(childFullPath) || {};\r\n store.set(childFullPath, {\r\n ...existingChildMeta,\r\n value: childValue,\r\n });\r\n }\r\n }\r\n }\r\n }\r\n }\r\n };\r\n\r\n processObject(path, newValue);\r\n }\r\n\r\n // Only notify after all changes are made\r\n get().notifyPathSubscribers(fullKey, { type: 'UPDATE', newValue });\r\n\r\n // Return same reference if using Zustand's immer middleware\r\n return state;\r\n });\r\n },\r\n selectedIndicesMap: new Map<string, string>(),\r\n getSelectedIndex: (arrayKey: string, validIds?: string[]): number => {\r\n const itemKey = get().selectedIndicesMap.get(arrayKey);\r\n\r\n if (!itemKey) return -1;\r\n\r\n // Use validIds if provided (for filtered views), otherwise use all arrayKeys\r\n const arrayKeys =\r\n validIds ||\r\n getGlobalStore.getState().getShadowMetadata(arrayKey, [])?.arrayKeys;\r\n\r\n if (!arrayKeys) return -1;\r\n\r\n return arrayKeys.indexOf(itemKey);\r\n },\r\n\r\n setSelectedIndex: (arrayKey: string, itemKey: string | undefined) => {\r\n set((state) => {\r\n const newMap = state.selectedIndicesMap;\r\n\r\n if (itemKey === undefined) {\r\n newMap.delete(arrayKey);\r\n } else {\r\n if (newMap.has(arrayKey)) {\r\n get().notifyPathSubscribers(newMap.get(arrayKey)!, {\r\n type: 'THIS_UNSELECTED',\r\n });\r\n }\r\n newMap.set(arrayKey, itemKey);\r\n\r\n get().notifyPathSubscribers(itemKey, {\r\n type: 'THIS_SELECTED',\r\n });\r\n }\r\n get().notifyPathSubscribers(arrayKey, {\r\n type: 'GET_SELECTED',\r\n });\r\n return {\r\n ...state,\r\n selectedIndicesMap: newMap,\r\n };\r\n });\r\n },\r\n clearSelectedIndex: ({ arrayKey }: { arrayKey: string }): void => {\r\n set((state) => {\r\n const newMap = state.selectedIndicesMap;\r\n const acutalKey = newMap.get(arrayKey);\r\n if (acutalKey) {\r\n get().notifyPathSubscribers(acutalKey, {\r\n type: 'CLEAR_SELECTION',\r\n });\r\n }\r\n\r\n newMap.delete(arrayKey);\r\n get().notifyPathSubscribers(arrayKey, {\r\n type: 'CLEAR_SELECTION',\r\n });\r\n return {\r\n ...state,\r\n selectedIndicesMap: newMap,\r\n };\r\n });\r\n },\r\n clearSelectedIndexesForState: (stateKey: string) => {\r\n set((state) => {\r\n const newOuterMap = new Map(state.selectedIndicesMap);\r\n const changed = newOuterMap.delete(stateKey);\r\n if (changed) {\r\n return { selectedIndicesMap: newOuterMap };\r\n } else {\r\n return {};\r\n }\r\n });\r\n },\r\n\r\n initialStateOptions: {},\r\n\r\n stateTimeline: {},\r\n cogsStateStore: {},\r\n stateLog: new Map(),\r\n\r\n initialStateGlobal: {},\r\n\r\n validationErrors: new Map(),\r\n addStateLog: (key, update) => {\r\n set((state) => {\r\n const newLog = new Map(state.stateLog);\r\n const stateLogForKey = new Map(newLog.get(key));\r\n const uniquePathKey = JSON.stringify(update.path);\r\n\r\n const existing = stateLogForKey.get(uniquePathKey);\r\n if (existing) {\r\n // If an update for this path already exists, just modify it. (Fast)\r\n existing.newValue = update.newValue;\r\n existing.timeStamp = update.timeStamp;\r\n } else {\r\n // Otherwise, add the new update. (Fast)\r\n stateLogForKey.set(uniquePathKey, { ...update });\r\n }\r\n\r\n newLog.set(key, stateLogForKey);\r\n return { stateLog: newLog };\r\n });\r\n },\r\n\r\n getInitialOptions: (key) => {\r\n return get().initialStateOptions[key];\r\n },\r\n\r\n setInitialStateOptions: (key, value) => {\r\n set((prev) => ({\r\n initialStateOptions: {\r\n ...prev.initialStateOptions,\r\n [key]: value,\r\n },\r\n }));\r\n },\r\n updateInitialStateGlobal: (key, newState) => {\r\n set((prev) => ({\r\n initialStateGlobal: {\r\n ...prev.initialStateGlobal,\r\n [key]: newState,\r\n },\r\n }));\r\n },\r\n\r\n syncInfoStore: new Map<string, SyncInfo>(),\r\n setSyncInfo: (key: string, syncInfo: SyncInfo) =>\r\n set((state) => {\r\n const newMap = new Map(state.syncInfoStore);\r\n newMap.set(key, syncInfo);\r\n return { ...state, syncInfoStore: newMap };\r\n }),\r\n getSyncInfo: (key: string) => get().syncInfoStore.get(key) || null,\r\n}));\r\n"],"names":["formRefStore","create","set","get","id","ref","state","newRefs","stateKey","allRefs","stateKeyPrefix","filteredRefs","isSimpleObject","value","getGlobalStore","updateQueue","startTransition","updateFn","dependencyPath","fullComponentId","newShadowStore","dependencyKey","pathMeta","pathComponents","rootMeta","component","newPaths","newComponentRegistration","newComponentsMap","registration","components","key","path","options","shadowStateStore","updates","setDirty","currentPath","fullKey","meta","parentPath","serverState","newMap","callback","subscribers","subsForPath","currentSubs","updatedPath","newValue","subs","initialState","preservedComponents","prefixToDelete","k","processValue","nodeKey","childIds","itemId","ulid","item","index","fields","newRootMeta","validArrayIds","memo","reconstruct","keyToBuild","ids","shadowMeta","result","keys","itemKey","fieldPath","metadata","existingMeta","finalMeta","cacheKey","cacheData","existing","arrayPath","newItem","arrayKey","parentMeta","newItemId","fullItemKey","newArrayKeys","processNewItem","v","itemPath","parentKey","arrayItemKey","store","processObject","objectToSet","currentFullKey","fieldKey","childValue","childFullPath","existingChildMeta","validIds","arrayKeys","acutalKey","newOuterMap","update","newLog","stateLogForKey","uniquePathKey","prev","newState","syncInfo"],"mappings":";;;AA4CO,MAAMA,IAAeC,EAA0B,CAACC,GAAKC,OAAS;AAAA,EACnE,8BAAc,IAAA;AAAA,EAEd,iBAAiB,CAACC,GAAIC,MACpBH,EAAI,CAACI,MAAU;AACb,UAAMC,IAAU,IAAI,IAAID,EAAM,QAAQ;AACtC,WAAAC,EAAQ,IAAIH,GAAIC,CAAG,GACZ,EAAE,UAAUE,EAAA;AAAA,EACrB,CAAC;AAAA,EA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A,EAAS,WAAWyB,EAAO,UAC3BzB,EAAS,YAAYyB,EAAO,aAG5BE,EAAe,IAAIC,GAAe,EAAE,GAAGH,GAAQ,GAGjDC,EAAO,IAAIzE,GAAK0E,CAAc,GACvB,EAAE,UAAUD,EAAA;AAAA,IACrB,CAAC;AAAA,EACH;AAAA,EAEA,mBAAmB,CAACzE,MACX5B,EAAA,EAAM,oBAAoB4B,CAAG;AAAA,EAGtC,wBAAwB,CAACA,GAAKlB,MAAU;AACtC,IAAAX,EAAI,CAACyG,OAAU;AAAA,MACb,qBAAqB;AAAA,QACnB,GAAGA,EAAK;AAAA,QACR,CAAC5E,CAAG,GAAGlB;AAAA,MAAA;AAAA,IACT,EACA;AAAA,EACJ;AAAA,EACA,0BAA0B,CAACkB,GAAK6E,MAAa;AAC3C,IAAA1G,EAAI,CAACyG,OAAU;AAAA,MACb,oBAAoB;AAAA,QAClB,GAAGA,EAAK;AAAA,QACR,CAAC5E,CAAG,GAAG6E;AAAA,MAAA;AAAA,IACT,EACA;AAAA,EACJ;AAAA,EAEA,mCAAmB,IAAA;AAAA,EACnB,aAAa,CAAC7E,GAAa8E,MACzB3G,EAAI,CAACI,MAAU;AACb,UAAMoC,IAAS,IAAI,IAAIpC,EAAM,aAAa;AAC1C,WAAAoC,EAAO,IAAIX,GAAK8E,CAAQ,GACjB,EAAE,GAAGvG,GAAO,eAAeoC,EAAA;AAAA,EACpC,CAAC;AAAA,EACH,aAAa,CAACX,MAAgB5B,EAAA,EAAM,cAAc,IAAI4B,CAAG,KAAK;AAChE,EAAE;"}
1
+ {"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import { create } from 'zustand';\r\nimport { ulid } from 'ulid';\r\nimport type {\r\n OptionsType,\r\n ReactivityType,\r\n SyncInfo,\r\n UpdateTypeDetail,\r\n} from './CogsState.js';\r\n\r\nimport { startTransition, type ReactNode } from 'react';\r\n\r\nexport type FreshValuesObject = {\r\n pathsToValues?: string[];\r\n prevValue?: any;\r\n newValue?: any;\r\n timeStamp: number;\r\n};\r\n\r\ntype StateValue = any;\r\n\r\nexport type TrieNode = {\r\n subscribers: Set<string>;\r\n children: Map<string, TrieNode>;\r\n};\r\n\r\nexport type FormRefStoreState = {\r\n formRefs: Map<string, React.RefObject<any>>;\r\n registerFormRef: (id: string, ref: React.RefObject<any>) => void;\r\n getFormRef: (id: string) => React.RefObject<any> | undefined;\r\n removeFormRef: (id: string) => void;\r\n // New method to get all refs for a stateKey\r\n getFormRefsByStateKey: (\r\n stateKey: string\r\n ) => Map<string, React.RefObject<any>>;\r\n};\r\n\r\nexport const formRefStore = create<FormRefStoreState>((set, get) => ({\r\n formRefs: new Map(),\r\n\r\n registerFormRef: (id, ref) =>\r\n set((state) => {\r\n const newRefs = new Map(state.formRefs);\r\n newRefs.set(id, ref);\r\n return { formRefs: newRefs };\r\n }),\r\n\r\n getFormRef: (id) => get().formRefs.get(id),\r\n\r\n removeFormRef: (id) =>\r\n set((state) => {\r\n const newRefs = new Map(state.formRefs);\r\n newRefs.delete(id);\r\n return { formRefs: newRefs };\r\n }),\r\n\r\n // Get all refs that start with the stateKey prefix\r\n getFormRefsByStateKey: (stateKey) => {\r\n const allRefs = get().formRefs;\r\n const stateKeyPrefix = stateKey + '.';\r\n const filteredRefs = new Map();\r\n\r\n allRefs.forEach((ref, id) => {\r\n if (id.startsWith(stateKeyPrefix) || id === stateKey) {\r\n filteredRefs.set(id, ref);\r\n }\r\n });\r\n\r\n return filteredRefs;\r\n },\r\n}));\r\nexport type ComponentsType = {\r\n components?: Map<\r\n string,\r\n {\r\n forceUpdate: () => void;\r\n paths: Set<string>;\r\n deps?: any[];\r\n prevDeps?: any[];\r\n depsFunction?: (state: any) => any[] | true;\r\n reactiveType: ReactivityType[] | ReactivityType;\r\n }\r\n >;\r\n};\r\n\r\nexport type ValidationStatus =\r\n | 'NOT_VALIDATED' // Never run\r\n | 'VALIDATING' // Currently running\r\n | 'VALID' // Passed\r\n | 'INVALID'; // Failed\r\n\r\nexport type ValidationError = {\r\n source: 'client' | 'sync_engine' | 'api';\r\n message: string;\r\n severity: 'warning' | 'error'; // warning = gentle, error = blocking\r\n code?: string; // Optional error code\r\n};\r\n\r\nexport type ValidationState = {\r\n status: ValidationStatus;\r\n errors: ValidationError[];\r\n lastValidated?: number;\r\n validatedValue?: any; // Value when last validated\r\n};\r\n\r\n// This is the new definition for the metadata object\r\nexport type ShadowMetadata = {\r\n id?: string;\r\n stateSource?: 'default' | 'server' | 'localStorage';\r\n lastServerSync?: number;\r\n isDirty?: boolean;\r\n baseServerState?: any;\r\n arrayKeys?: string[];\r\n fields?: Record<string, any>;\r\n virtualizer?: {\r\n itemHeight?: number;\r\n domRef?: HTMLElement | null;\r\n };\r\n syncInfo?: { status: string };\r\n validation?: ValidationState;\r\n features?: {\r\n syncEnabled: boolean;\r\n validationEnabled: boolean;\r\n localStorageEnabled: boolean;\r\n };\r\n lastUpdated?: number;\r\n signals?: Array<{\r\n instanceId: string;\r\n parentId: string;\r\n position: number;\r\n effect?: string;\r\n }>;\r\n mapWrappers?: Array<{\r\n instanceId: string;\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n mapFn: (setter: any, index: number, arraySetter: any) => ReactNode;\r\n containerRef: HTMLDivElement | null;\r\n rebuildStateShape: any;\r\n }>;\r\n transformCaches?: Map<\r\n string,\r\n {\r\n validIds: string[];\r\n computedAt: number;\r\n transforms: Array<{ type: 'filter' | 'sort'; fn: Function }>;\r\n }\r\n >;\r\n pathComponents?: Set<string>;\r\n streams?: Map<\r\n string,\r\n {\r\n buffer: any[];\r\n flushTimer: NodeJS.Timeout | null;\r\n }\r\n >;\r\n} & ComponentsType;\r\n\r\n// The shadow node itself can have a value and the metadata object.\r\ntype ShadowNode = {\r\n value?: any;\r\n _meta?: ShadowMetadata;\r\n [key: string]: any; // For nested data properties\r\n};\r\n\r\nexport type CogsGlobalState = {\r\n // NEW shadow store\r\n shadowStateStore: Map<string, ShadowNode>; // Changed ShadowMetadata to ShadowNode\r\n setTransformCache: (\r\n key: string,\r\n path: string[],\r\n cacheKey: string,\r\n cacheData: any\r\n ) => void;\r\n // NEW functions\r\n initializeShadowState: (key: string, initialState: any) => void;\r\n\r\n // REFACTORED: getShadowNode gets the whole object (data + _meta)\r\n getShadowNode: (key: string, path: string[]) => ShadowNode | undefined;\r\n // REFACTORED: getShadowMetadata now returns just the _meta field\r\n getShadowMetadata: (\r\n key: string,\r\n path: string[]\r\n ) => ShadowMetadata | undefined;\r\n\r\n setShadowMetadata: (key: string, path: string[], metadata: any) => void;\r\n getShadowValue: (\r\n key: string,\r\n path: string[],\r\n validArrayIds?: string[],\r\n log?: boolean\r\n ) => any;\r\n updateShadowAtPath: (key: string, path: string[], newValue: any) => void;\r\n insertShadowArrayElement: (\r\n key: string,\r\n arrayPath: string[],\r\n newItem: any,\r\n index?: number\r\n ) => void;\r\n removeShadowArrayElement: (key: string, itemPath: string[]) => void;\r\n registerComponent: (\r\n stateKey: string,\r\n componentId: string,\r\n registration: any\r\n ) => void;\r\n unregisterComponent: (stateKey: string, componentId: string) => void;\r\n addPathComponent: (\r\n stateKey: string,\r\n dependencyPath: string[],\r\n fullComponentId: string\r\n ) => void;\r\n\r\n markAsDirty: (\r\n key: string,\r\n path: string[],\r\n options: { bubble: boolean }\r\n ) => void;\r\n // These method signatures stay the same\r\n\r\n pathSubscribers: Map<string, Set<(newValue: any) => void>>;\r\n subscribeToPath: (\r\n path: string,\r\n callback: (newValue: any) => void\r\n ) => () => void;\r\n notifyPathSubscribers: (updatedPath: string, newValue: any) => void;\r\n\r\n selectedIndicesMap: Map<string, string>; // stateKey -> (parentPath -> selectedIndex)\r\n getSelectedIndex: (stateKey: string, validArrayIds?: string[]) => number;\r\n setSelectedIndex: (key: string, itemKey: string) => void;\r\n clearSelectedIndex: ({ arrayKey }: { arrayKey: string }) => void;\r\n clearSelectedIndexesForState: (stateKey: string) => void;\r\n\r\n // --- Core State and Updaters ---\r\n\r\n initialStateOptions: { [key: string]: OptionsType };\r\n\r\n initialStateGlobal: { [key: string]: StateValue };\r\n\r\n updateInitialStateGlobal: (key: string, newState: StateValue) => void;\r\n\r\n getInitialOptions: (key: string) => OptionsType | undefined;\r\n setInitialStateOptions: (key: string, value: OptionsType) => void;\r\n\r\n serverStateUpdates: Map<\r\n string,\r\n {\r\n data: any;\r\n status: 'loading' | 'success' | 'error';\r\n timestamp: number;\r\n }\r\n >;\r\n\r\n setServerStateUpdate: (key: string, serverState: any) => void;\r\n\r\n stateLog: Map<string, Map<string, UpdateTypeDetail>>;\r\n syncInfoStore: Map<string, SyncInfo>;\r\n addStateLog: (updates: UpdateTypeDetail[]) => void;\r\n\r\n setSyncInfo: (key: string, syncInfo: SyncInfo) => void;\r\n getSyncInfo: (key: string) => SyncInfo | null;\r\n};\r\n\r\n// ✅ CHANGE 1: `METADATA_KEYS` now only contains `_meta` and `value`.\r\n// The other keys are now properties of the `ShadowMetadata` type.\r\nexport const METADATA_KEYS = new Set(['_meta', 'value']);\r\n\r\n/**\r\n * The single source of truth for converting a regular JS value/object\r\n * into the shadow state tree format with the new `_meta` structure.\r\n */\r\n// ✅ CHANGE 2: `buildShadowNode` now creates the `_meta` field.\r\nexport function buildShadowNode(value: any): ShadowNode {\r\n // Primitives and null are wrapped.\r\n if (value === null || typeof value !== 'object') {\r\n return { value };\r\n }\r\n\r\n // Arrays are converted to an object with id-keyed children and metadata in `_meta`.\r\n if (Array.isArray(value)) {\r\n const arrayNode: ShadowNode = { _meta: { arrayKeys: [] } }; // Initialize with _meta and arrayKeys\r\n const idKeys: string[] = [];\r\n value.forEach((item) => {\r\n const itemId = `id:${ulid()}`;\r\n arrayNode[itemId] = buildShadowNode(item); // Recurse for each item\r\n idKeys.push(itemId);\r\n });\r\n arrayNode._meta!.arrayKeys = idKeys; // Set the final ordered keys\r\n return arrayNode;\r\n }\r\n\r\n // Plain objects are recursively processed.\r\n if (value.constructor === Object) {\r\n const objectNode: ShadowNode = { _meta: {} }; // Initialize with an empty meta object\r\n for (const key in value) {\r\n if (Object.prototype.hasOwnProperty.call(value, key)) {\r\n objectNode[key] = buildShadowNode(value[key]); // Recurse for each property\r\n }\r\n }\r\n return objectNode;\r\n }\r\n\r\n // Fallback for other object types (Date, etc.) - treat them as primitives.\r\n return { value };\r\n}\r\n\r\nexport const getGlobalStore = create<CogsGlobalState>((set, get) => ({\r\n shadowStateStore: new Map<string, ShadowNode>(),\r\n\r\n setTransformCache: (\r\n key: string,\r\n path: string[],\r\n cacheKey: string,\r\n cacheData: any\r\n ) => {\r\n // This function now uses setShadowMetadata which correctly places the data.\r\n const metadata = get().getShadowMetadata(key, path) || {};\r\n if (!metadata.transformCaches) {\r\n metadata.transformCaches = new Map();\r\n }\r\n metadata.transformCaches.set(cacheKey, cacheData);\r\n get().setShadowMetadata(key, path, {\r\n transformCaches: metadata.transformCaches,\r\n });\r\n },\r\n\r\n initializeShadowState: (key: string, initialState: any) => {\r\n set((state) => {\r\n const newShadowStore = new Map(state.shadowStateStore);\r\n const existingRoot =\r\n newShadowStore.get(key) || newShadowStore.get(`[${key}`);\r\n let preservedMetadata: Partial<ShadowMetadata> = {};\r\n\r\n if (existingRoot?._meta) {\r\n const {\r\n components,\r\n features,\r\n lastServerSync,\r\n stateSource,\r\n baseServerState,\r\n } = existingRoot._meta;\r\n if (components) preservedMetadata.components = components;\r\n if (features) preservedMetadata.features = features;\r\n if (lastServerSync) preservedMetadata.lastServerSync = lastServerSync;\r\n if (stateSource) preservedMetadata.stateSource = stateSource;\r\n if (baseServerState)\r\n preservedMetadata.baseServerState = baseServerState;\r\n }\r\n\r\n newShadowStore.delete(key);\r\n newShadowStore.delete(`[${key}`);\r\n\r\n const newRoot = buildShadowNode(initialState);\r\n // Ensure _meta exists before assigning to it\r\n if (!newRoot._meta) newRoot._meta = {};\r\n Object.assign(newRoot._meta, preservedMetadata);\r\n\r\n const storageKey = Array.isArray(initialState) ? `[${key}` : key;\r\n newShadowStore.set(storageKey, newRoot);\r\n\r\n return { shadowStateStore: newShadowStore };\r\n });\r\n },\r\n\r\n // ✅ NEW HELPER: Gets the entire node (data and metadata).\r\n getShadowNode: (key: string, path: string[]): ShadowNode | undefined => {\r\n const store = get().shadowStateStore;\r\n let current: any = store.get(key) || store.get(`[${key}`);\r\n\r\n if (!current) return undefined;\r\n if (path.length === 0) return current;\r\n\r\n for (const segment of path) {\r\n if (typeof current !== 'object' || current === null) return undefined;\r\n current = current[segment];\r\n if (current === undefined) return undefined;\r\n }\r\n return current;\r\n },\r\n\r\n // ✅ REFACTORED: Returns only the `_meta` part of a node.\r\n getShadowMetadata: (\r\n key: string,\r\n path: string[]\r\n ): ShadowMetadata | undefined => {\r\n const node = get().getShadowNode(key, path);\r\n return node?._meta;\r\n },\r\n\r\n // ✅ REFACTORED: Sets data within the `_meta` object.\r\n setShadowMetadata: (\r\n key: string,\r\n path: string[],\r\n newMetadata: Partial<ShadowMetadata>\r\n ) => {\r\n set((state) => {\r\n const newStore = new Map(state.shadowStateStore);\r\n const rootKey = newStore.has(`[${key}`) ? `[${key}` : key;\r\n let root = newStore.get(rootKey);\r\n\r\n if (!root) {\r\n root = {};\r\n newStore.set(rootKey, root);\r\n }\r\n\r\n const clonedRoot: any = { ...root };\r\n newStore.set(rootKey, clonedRoot);\r\n\r\n let current = clonedRoot;\r\n for (const segment of path) {\r\n const nextNode = current[segment] || {};\r\n current[segment] = { ...nextNode }; // Clone for immutability\r\n current = current[segment];\r\n }\r\n\r\n // Ensure _meta object exists and merge the new metadata into it\r\n current._meta = { ...(current._meta || {}), ...newMetadata };\r\n\r\n return { shadowStateStore: newStore };\r\n });\r\n },\r\n getShadowValue: (\r\n key: string,\r\n path: string[],\r\n validArrayIds?: string[],\r\n log?: boolean\r\n ) => {\r\n const node = get().getShadowNode(key, path);\r\n\r\n if (node === null || node === undefined) return undefined;\r\n\r\n const nodeKeys = Object.keys(node);\r\n\r\n // ✅ FIX: A node is a primitive wrapper ONLY if its keys are 'value' and/or '_meta'.\r\n // This prevents objects in your data that happen to have a \"value\" property from being\r\n // incorrectly treated as wrappers.\r\n const isPrimitiveWrapper =\r\n Object.prototype.hasOwnProperty.call(node, 'value') &&\r\n nodeKeys.every((k) => k === 'value' || k === '_meta');\r\n\r\n if (isPrimitiveWrapper) {\r\n return node.value;\r\n }\r\n\r\n // Array Check (This part is correct)\r\n const isArrayNode =\r\n node._meta &&\r\n Object.prototype.hasOwnProperty.call(node._meta, 'arrayKeys');\r\n if (isArrayNode) {\r\n const keysToIterate =\r\n validArrayIds !== undefined && validArrayIds.length > 0\r\n ? validArrayIds\r\n : node._meta!.arrayKeys!;\r\n\r\n return keysToIterate.map((itemKey: string) =>\r\n get().getShadowValue(key, [...path, itemKey])\r\n );\r\n }\r\n\r\n // Object Reconstruction (This part is also correct)\r\n const result: any = {};\r\n for (const propKey of nodeKeys) {\r\n // We correctly ignore metadata and array item keys here.\r\n if (propKey !== '_meta' && !propKey.startsWith('id:')) {\r\n result[propKey] = get().getShadowValue(key, [...path, propKey]);\r\n }\r\n }\r\n return result;\r\n },\r\n\r\n // ✅ REFACTORED: Correctly preserves `_meta` on updates.\r\n updateShadowAtPath: (key, path, newValue) => {\r\n set((state) => {\r\n const newStore = new Map(state.shadowStateStore);\r\n const rootKey = newStore.has(`[${key}`) ? `[${key}` : key;\r\n let root = newStore.get(rootKey);\r\n\r\n if (!root) return state;\r\n\r\n const clonedRoot: any = { ...root };\r\n newStore.set(rootKey, clonedRoot);\r\n\r\n if (path.length === 0) {\r\n const newRootStructure = buildShadowNode(newValue);\r\n // Preserve the top-level metadata\r\n if (clonedRoot._meta) {\r\n newRootStructure._meta = {\r\n ...(newRootStructure._meta || {}),\r\n ...clonedRoot._meta,\r\n };\r\n }\r\n newStore.set(rootKey, newRootStructure);\r\n } else {\r\n let current = clonedRoot;\r\n const parentPath = path.slice(0, -1);\r\n for (const segment of parentPath) {\r\n current[segment] = { ...current[segment] };\r\n current = current[segment];\r\n }\r\n\r\n const lastSegment = path[path.length - 1]!;\r\n const existingNode = current[lastSegment] || {};\r\n const newNodeStructure = buildShadowNode(newValue);\r\n\r\n // This merge is critical: it preserves existing metadata during an update.\r\n if (existingNode._meta) {\r\n newNodeStructure._meta = {\r\n ...(newNodeStructure._meta || {}),\r\n ...existingNode._meta,\r\n };\r\n }\r\n current[lastSegment] = newNodeStructure;\r\n }\r\n\r\n get().notifyPathSubscribers([key, ...path].join('.'), {\r\n type: 'UPDATE',\r\n newValue,\r\n });\r\n return { shadowStateStore: newStore };\r\n });\r\n },\r\n\r\n // ✅ REFACTORED: Works with `_meta.arrayKeys`.\r\n insertShadowArrayElement: (key, arrayPath, newItem, index) => {\r\n const arrayNode = get().getShadowNode(key, arrayPath);\r\n if (!arrayNode?._meta?.arrayKeys) {\r\n console.error(\r\n `Array not found at path: ${[key, ...arrayPath].join('.')}`\r\n );\r\n return;\r\n }\r\n\r\n const newItemId = `id:${ulid()}`;\r\n const newItemNode = buildShadowNode(newItem);\r\n\r\n // Update the `arrayKeys` in the metadata\r\n const currentKeys = arrayNode._meta.arrayKeys;\r\n const newKeys = [...currentKeys];\r\n if (index !== undefined && index >= 0 && index <= newKeys.length) {\r\n newKeys.splice(index, 0, newItemId);\r\n } else {\r\n newKeys.push(newItemId);\r\n }\r\n\r\n // Update transform caches if they exist\r\n if (arrayNode._meta.transformCaches) {\r\n arrayNode._meta.transformCaches.forEach((cache) => {\r\n if (cache.validIds && Array.isArray(cache.validIds)) {\r\n const matchesFilters = cache.transforms.every((transform) =>\r\n transform.type === 'filter' ? transform.fn(newItem) : true\r\n );\r\n if (matchesFilters) {\r\n cache.validIds = [...cache.validIds];\r\n if (index !== undefined) {\r\n cache.validIds.splice(index, 0, newItemId);\r\n } else {\r\n cache.validIds.push(newItemId);\r\n }\r\n }\r\n }\r\n });\r\n }\r\n\r\n // Directly set the new item and updated metadata on the node before setting state\r\n arrayNode[newItemId] = newItemNode;\r\n arrayNode._meta.arrayKeys = newKeys;\r\n\r\n get().setShadowMetadata(key, arrayPath, { arrayKeys: newKeys });\r\n\r\n // Trigger notifications\r\n const arrayKey = [key, ...arrayPath].join('.');\r\n get().notifyPathSubscribers(arrayKey, {\r\n type: 'INSERT',\r\n path: arrayKey,\r\n itemKey: `${arrayKey}.${newItemId}`,\r\n index: index ?? newKeys.length - 1,\r\n });\r\n },\r\n\r\n // ✅ REFACTORED: Works with `_meta.arrayKeys`.\r\n removeShadowArrayElement: (key, itemPath) => {\r\n if (itemPath.length === 0) return;\r\n\r\n const arrayPath = itemPath.slice(0, -1);\r\n const itemId = itemPath[itemPath.length - 1];\r\n if (!itemId?.startsWith('id:')) return;\r\n\r\n const arrayNode = get().getShadowNode(key, arrayPath);\r\n if (!arrayNode?._meta?.arrayKeys) return;\r\n\r\n // Filter the item's ID from the `arrayKeys` metadata\r\n const newKeys = arrayNode._meta.arrayKeys.filter((k) => k !== itemId);\r\n\r\n // Delete the item's data from the node\r\n delete arrayNode[itemId];\r\n\r\n // Persist the modified array node back to the store\r\n get().setShadowMetadata(key, arrayPath, { arrayKeys: newKeys });\r\n\r\n const arrayKey = [key, ...arrayPath].join('.');\r\n get().notifyPathSubscribers(arrayKey, {\r\n type: 'REMOVE',\r\n path: arrayKey,\r\n itemKey: `${arrayKey}.${itemId}`,\r\n });\r\n },\r\n\r\n // The rest of the functions are updated to use the new helpers (`getShadowMetadata`, `setShadowMetadata`)\r\n // which abstracts away the `_meta` implementation detail.\r\n\r\n addPathComponent: (stateKey, dependencyPath, fullComponentId) => {\r\n const metadata = get().getShadowMetadata(stateKey, dependencyPath) || {};\r\n const newPathComponents = new Set(metadata.pathComponents);\r\n newPathComponents.add(fullComponentId);\r\n get().setShadowMetadata(stateKey, dependencyPath, {\r\n pathComponents: newPathComponents,\r\n });\r\n\r\n const rootMeta = get().getShadowMetadata(stateKey, []);\r\n if (rootMeta?.components) {\r\n const component = rootMeta.components.get(fullComponentId);\r\n if (component) {\r\n const fullPathKey = [stateKey, ...dependencyPath].join('.');\r\n const newPaths = new Set(component.paths);\r\n newPaths.add(fullPathKey);\r\n const newComponentRegistration = { ...component, paths: newPaths };\r\n const newComponentsMap = new Map(rootMeta.components);\r\n newComponentsMap.set(fullComponentId, newComponentRegistration);\r\n get().setShadowMetadata(stateKey, [], { components: newComponentsMap });\r\n }\r\n }\r\n },\r\n\r\n registerComponent: (stateKey, fullComponentId, registration) => {\r\n const rootMeta = get().getShadowMetadata(stateKey, []) || {};\r\n const components = new Map(rootMeta.components);\r\n components.set(fullComponentId, registration);\r\n get().setShadowMetadata(stateKey, [], { components });\r\n },\r\n\r\n unregisterComponent: (stateKey, fullComponentId) => {\r\n const rootMeta = get().getShadowMetadata(stateKey, []);\r\n if (!rootMeta?.components) return;\r\n const components = new Map(rootMeta.components);\r\n if (components.delete(fullComponentId)) {\r\n get().setShadowMetadata(stateKey, [], { components });\r\n }\r\n },\r\n\r\n // ✅ REFACTORED: `markAsDirty` now correctly writes to `_meta.isDirty`.\r\n markAsDirty: (key, path, options = { bubble: true }) => {\r\n const setDirtyOnPath = (pathToMark: string[]) => {\r\n const node = get().getShadowNode(key, pathToMark);\r\n if (node?._meta?.isDirty) {\r\n return true; // Already dirty, stop bubbling\r\n }\r\n get().setShadowMetadata(key, pathToMark, { isDirty: true });\r\n return false; // Was not dirty before\r\n };\r\n\r\n setDirtyOnPath(path);\r\n\r\n if (options.bubble) {\r\n let parentPath = [...path];\r\n while (parentPath.length > 0) {\r\n parentPath.pop();\r\n if (setDirtyOnPath(parentPath)) {\r\n break; // Stop if parent was already dirty\r\n }\r\n }\r\n }\r\n },\r\n\r\n serverStateUpdates: new Map(),\r\n setServerStateUpdate: (key, serverState) => {\r\n set((state) => ({\r\n serverStateUpdates: new Map(state.serverStateUpdates).set(\r\n key,\r\n serverState\r\n ),\r\n }));\r\n get().notifyPathSubscribers(key, {\r\n type: 'SERVER_STATE_UPDATE',\r\n serverState,\r\n });\r\n },\r\n\r\n pathSubscribers: new Map<string, Set<(newValue: any) => void>>(),\r\n subscribeToPath: (path, callback) => {\r\n const subscribers = get().pathSubscribers;\r\n const subsForPath = subscribers.get(path) || new Set();\r\n subsForPath.add(callback);\r\n subscribers.set(path, subsForPath);\r\n\r\n return () => {\r\n const currentSubs = get().pathSubscribers.get(path);\r\n if (currentSubs) {\r\n currentSubs.delete(callback);\r\n if (currentSubs.size === 0) {\r\n get().pathSubscribers.delete(path);\r\n }\r\n }\r\n };\r\n },\r\n notifyPathSubscribers: (updatedPath, newValue) => {\r\n const subscribers = get().pathSubscribers;\r\n const subs = subscribers.get(updatedPath);\r\n if (subs) {\r\n subs.forEach((callback) => callback(newValue));\r\n }\r\n },\r\n\r\n selectedIndicesMap: new Map<string, string>(),\r\n getSelectedIndex: (arrayKey, validIds) => {\r\n const itemKey = get().selectedIndicesMap.get(arrayKey);\r\n if (!itemKey) return -1;\r\n\r\n const arrayMeta = get().getShadowMetadata(\r\n arrayKey.split('.')[0]!,\r\n arrayKey.split('.').slice(1)\r\n );\r\n const arrayKeys = validIds || arrayMeta?.arrayKeys;\r\n\r\n return arrayKeys ? arrayKeys.indexOf(itemKey) : -1;\r\n },\r\n\r\n setSelectedIndex: (arrayKey, itemKey) => {\r\n set((state) => {\r\n const newMap = new Map(state.selectedIndicesMap);\r\n const oldSelection = newMap.get(arrayKey);\r\n if (oldSelection) {\r\n get().notifyPathSubscribers(oldSelection, { type: 'THIS_UNSELECTED' });\r\n }\r\n\r\n if (itemKey === undefined) {\r\n newMap.delete(arrayKey);\r\n } else {\r\n newMap.set(arrayKey, itemKey);\r\n get().notifyPathSubscribers(itemKey, { type: 'THIS_SELECTED' });\r\n }\r\n\r\n get().notifyPathSubscribers(arrayKey, { type: 'GET_SELECTED' });\r\n return { selectedIndicesMap: newMap };\r\n });\r\n },\r\n\r\n clearSelectedIndex: ({ arrayKey }) => {\r\n set((state) => {\r\n const newMap = new Map(state.selectedIndicesMap);\r\n const actualKey = newMap.get(arrayKey);\r\n if (actualKey) {\r\n get().notifyPathSubscribers(actualKey, { type: 'CLEAR_SELECTION' });\r\n }\r\n newMap.delete(arrayKey);\r\n get().notifyPathSubscribers(arrayKey, { type: 'CLEAR_SELECTION' });\r\n return { selectedIndicesMap: newMap };\r\n });\r\n },\r\n\r\n clearSelectedIndexesForState: (stateKey) => {\r\n set((state) => {\r\n const newMap = new Map(state.selectedIndicesMap);\r\n let changed = false;\r\n for (const key of newMap.keys()) {\r\n if (key === stateKey || key.startsWith(stateKey + '.')) {\r\n newMap.delete(key);\r\n changed = true;\r\n }\r\n }\r\n return changed ? { selectedIndicesMap: newMap } : {};\r\n });\r\n },\r\n\r\n initialStateOptions: {},\r\n stateLog: new Map(),\r\n initialStateGlobal: {},\r\n\r\n addStateLog: (updates) => {\r\n if (!updates || updates.length === 0) return;\r\n set((state) => {\r\n const newLog = new Map(state.stateLog);\r\n const logsGroupedByKey = new Map<string, UpdateTypeDetail[]>();\r\n for (const update of updates) {\r\n const group = logsGroupedByKey.get(update.stateKey) || [];\r\n group.push(update);\r\n logsGroupedByKey.set(update.stateKey, group);\r\n }\r\n for (const [key, batchOfUpdates] of logsGroupedByKey.entries()) {\r\n const newStateLogForKey = new Map(newLog.get(key));\r\n for (const update of batchOfUpdates) {\r\n newStateLogForKey.set(JSON.stringify(update.path), { ...update });\r\n }\r\n newLog.set(key, newStateLogForKey);\r\n }\r\n return { stateLog: newLog };\r\n });\r\n },\r\n\r\n getInitialOptions: (key) => get().initialStateOptions[key],\r\n setInitialStateOptions: (key, value) => {\r\n set((prev) => ({\r\n initialStateOptions: { ...prev.initialStateOptions, [key]: value },\r\n }));\r\n },\r\n updateInitialStateGlobal: (key, newState) => {\r\n set((prev) => ({\r\n initialStateGlobal: { ...prev.initialStateGlobal, [key]: newState },\r\n }));\r\n },\r\n\r\n syncInfoStore: new Map<string, SyncInfo>(),\r\n setSyncInfo: (key, syncInfo) =>\r\n set((state) => {\r\n const newMap = new Map(state.syncInfoStore);\r\n newMap.set(key, syncInfo);\r\n return { syncInfoStore: newMap };\r\n }),\r\n getSyncInfo: (key) => get().syncInfoStore.get(key) || null,\r\n}));\r\n"],"names":["formRefStore","create","set","get","id","ref","state","newRefs","stateKey","allRefs","stateKeyPrefix","filteredRefs","METADATA_KEYS","buildShadowNode","value","arrayNode","idKeys","item","itemId","ulid","objectNode","key","getGlobalStore","path","cacheKey","cacheData","metadata","initialState","newShadowStore","existingRoot","preservedMetadata","components","features","lastServerSync","stateSource","baseServerState","newRoot","storageKey","store","current","segment","newMetadata","newStore","rootKey","root","clonedRoot","nextNode","validArrayIds","log","node","nodeKeys","k","itemKey","result","propKey","newValue","newRootStructure","parentPath","lastSegment","existingNode","newNodeStructure","arrayPath","newItem","index","newItemId","newItemNode","newKeys","cache","transform","arrayKey","itemPath","dependencyPath","fullComponentId","newPathComponents","rootMeta","component","fullPathKey","newPaths","newComponentRegistration","newComponentsMap","registration","options","setDirtyOnPath","pathToMark","serverState","callback","subscribers","subsForPath","currentSubs","updatedPath","subs","validIds","arrayMeta","arrayKeys","newMap","oldSelection","actualKey","changed","updates","newLog","logsGroupedByKey","update","group","batchOfUpdates","newStateLogForKey","prev","newState","syncInfo"],"mappings":";;AAoCO,MAAMA,IAAeC,EAA0B,CAACC,GAAKC,OAAS;AAAA,EACnE,8BAAc,IAAA;AAAA,EAEd,iBAAiB,CAACC,GAAIC,MACpBH,EAAI,CAACI,MAAU;AACb,UAAMC,IAAU,IAAI,IAAID,EAAM,QAAQ;AACtC,WAAAC,EAAQ,IAAIH,GAAIC,CAAG,GACZ,EAAE,UAAUE,EAAA;AAAA,EACrB,CAAC;AAAA,EAEH,YAAY,CAACH,MAAOD,IAAM,SAAS,IAAIC,CAAE;AAAA,EAEzC,eAAe,CAACA,MACdF,EAAI,CAACI,MAAU;AACb,UAAMC,IAAU,IAAI,IAAID,EAAM,QAAQ;AACtC,WAAAC,EAAQ,OAAOH,CAAE,GACV,EAAE,UAAUG,EAAA;AAAA,EACrB,CAAC;AAAA;AAAA,EAGH,uBAAuB,CAACC,MAAa;AACnC,UAAMC,IAAUN,IAAM,UAChBO,IAAiBF,IAAW,KAC5BG,wBA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9E,GAAKmF,CAAiB;AAAA,MACnC;AACA,aAAO,EAAE,UAAUL,EAAA;AAAA,IACrB,CAAC;AAAA,EACH;AAAA,EAEA,mBAAmB,CAAC9E,MAAQlB,EAAA,EAAM,oBAAoBkB,CAAG;AAAA,EACzD,wBAAwB,CAACA,GAAKP,MAAU;AACtC,IAAAZ,EAAI,CAACuG,OAAU;AAAA,MACb,qBAAqB,EAAE,GAAGA,EAAK,qBAAqB,CAACpF,CAAG,GAAGP,EAAA;AAAA,IAAM,EACjE;AAAA,EACJ;AAAA,EACA,0BAA0B,CAACO,GAAKqF,MAAa;AAC3C,IAAAxG,EAAI,CAACuG,OAAU;AAAA,MACb,oBAAoB,EAAE,GAAGA,EAAK,oBAAoB,CAACpF,CAAG,GAAGqF,EAAA;AAAA,IAAS,EAClE;AAAA,EACJ;AAAA,EAEA,mCAAmB,IAAA;AAAA,EACnB,aAAa,CAACrF,GAAKsF,MACjBzG,EAAI,CAACI,MAAU;AACb,UAAMwF,IAAS,IAAI,IAAIxF,EAAM,aAAa;AAC1C,WAAAwF,EAAO,IAAIzE,GAAKsF,CAAQ,GACjB,EAAE,eAAeb,EAAA;AAAA,EAC1B,CAAC;AAAA,EACH,aAAa,CAACzE,MAAQlB,EAAA,EAAM,cAAc,IAAIkB,CAAG,KAAK;AACxD,EAAE;"}
package/dist/utility.d.ts CHANGED
@@ -9,7 +9,6 @@ export declare const isDeepEqual: (object1?: Record<string, any>, object2?: Reco
9
9
  }, currentPath?: string[]) => boolean;
10
10
  export declare function updateNestedProperty(path: string[], state: any, update: any): any;
11
11
  export declare function deleteNestedProperty(path: string[], state: any): any;
12
- export declare function getNestedValue<TStateObject extends unknown>(obj: TStateObject, pathArray: string[], stateKey: string): any;
13
12
  type DifferencePaths = string[];
14
13
  export declare function getDifferences(obj1: any, obj2: any, currentPath?: string): DifferencePaths;
15
14
  export declare function deepMerge(target: any, source: any): any;
@@ -1 +1 @@
1
- {"version":3,"file":"utility.d.ts","sourceRoot":"","sources":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CACd,CACF;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAC7B,IAAI,EAAE,MAAM,GACX,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAmB5B;AACD,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG;IACrE,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC"}
package/dist/utility.js CHANGED
@@ -1,230 +1,193 @@
1
- import { getGlobalStore as w } from "./store.js";
2
- const c = (n) => n && typeof n == "object" && !Array.isArray(n) && n !== null, v = (n) => typeof n == "function", d = (n) => Array.isArray(n), g = (n, e, t = {}, r = []) => {
3
- if (c(n) && c(e)) {
4
- const i = Object.keys(n), s = Object.keys(e);
5
- if (i.length !== s.length)
1
+ const u = (e) => e && typeof e == "object" && !Array.isArray(e) && e !== null, $ = (e) => typeof e == "function", y = (e) => Array.isArray(e), d = (e, n, i = {}, r = []) => {
2
+ if (u(e) && u(n)) {
3
+ const t = Object.keys(e), l = Object.keys(n);
4
+ if (t.length !== l.length)
6
5
  return !1;
7
- for (let o of i) {
8
- const f = n[o], l = e[o];
9
- if (!(o in n) || !(o in e))
6
+ for (let s of t) {
7
+ const o = e[s], f = n[s];
8
+ if (!(s in e) || !(s in n))
10
9
  return !1;
11
- const a = [...r, o];
12
- if (!g(f, l, t, a))
10
+ const c = [...r, s];
11
+ if (!d(o, f, i, c))
13
12
  return !1;
14
13
  }
15
14
  return !0;
16
- } else if (d(n) && d(e)) {
17
- if (n.length !== e.length)
15
+ } else if (y(e) && y(n)) {
16
+ if (e.length !== n.length)
18
17
  return !1;
19
- for (let i = 0; i < n.length; i++)
20
- if (!g(n[i], e[i], t, [
18
+ for (let t = 0; t < e.length; t++)
19
+ if (!d(e[t], n[t], i, [
21
20
  ...r,
22
- i.toString()
21
+ t.toString()
23
22
  ]))
24
23
  return !1;
25
24
  return !0;
26
25
  } else
27
- return n === e || Number.isNaN(n) && Number.isNaN(e);
26
+ return e === n || Number.isNaN(e) && Number.isNaN(n);
28
27
  };
29
- function h(n, e, t) {
30
- if (!n || n.length === 0) return t;
31
- const r = n[0], i = n.slice(1);
32
- if (Array.isArray(e)) {
33
- const s = Number(r);
34
- if (!isNaN(s) && s >= 0 && s < e.length)
28
+ function g(e, n, i) {
29
+ if (!e || e.length === 0) return i;
30
+ const r = e[0], t = e.slice(1);
31
+ if (Array.isArray(n)) {
32
+ const l = Number(r);
33
+ if (!isNaN(l) && l >= 0 && l < n.length)
35
34
  return [
36
- ...e.slice(0, s),
37
- h(i, e[s], t),
38
- ...e.slice(s + 1)
35
+ ...n.slice(0, l),
36
+ g(t, n[l], i),
37
+ ...n.slice(l + 1)
39
38
  ];
40
- throw console.log("errorstate", e, n), new Error(
41
- `Invalid array index "${s}" in path "${n.join(".")}".`
39
+ throw console.log("errorstate", n, e), new Error(
40
+ `Invalid array index "${l}" in path "${e.join(".")}".`
42
41
  );
43
- } else if (typeof e == "object" && e !== null) {
44
- if (r && r in e)
42
+ } else if (typeof n == "object" && n !== null) {
43
+ if (r && r in n)
45
44
  return {
46
- ...e,
47
- [r]: h(i, e[r], t)
45
+ ...n,
46
+ [r]: g(t, n[r], i)
48
47
  };
49
- throw console.log("Invalid property", r, i, n), new Error(
50
- `Invalid property "${r}" in path "${n.join(".")}".`
48
+ throw console.log("Invalid property", r, t, e), new Error(
49
+ `Invalid property "${r}" in path "${e.join(".")}".`
51
50
  );
52
51
  } else
53
52
  throw new Error(
54
- `Cannot update nested property at path "${n.join(".")}". The path does not exist.`
53
+ `Cannot update nested property at path "${e.join(".")}". The path does not exist.`
55
54
  );
56
55
  }
57
- function p(n, e) {
58
- if (!n || n.length === 0) return e;
59
- const t = n[0], r = n.slice(1);
60
- if (Array.isArray(e)) {
61
- const i = Number(t);
62
- if (!isNaN(i) && i >= 0 && i < e.length)
63
- return r.length === 0 ? [...e.slice(0, i), ...e.slice(i + 1)] : [
64
- ...e.slice(0, i),
65
- p(r, e[i]),
66
- ...e.slice(i + 1)
56
+ function p(e, n) {
57
+ if (!e || e.length === 0) return n;
58
+ const i = e[0], r = e.slice(1);
59
+ if (Array.isArray(n)) {
60
+ const t = Number(i);
61
+ if (!isNaN(t) && t >= 0 && t < n.length)
62
+ return r.length === 0 ? [...n.slice(0, t), ...n.slice(t + 1)] : [
63
+ ...n.slice(0, t),
64
+ p(r, n[t]),
65
+ ...n.slice(t + 1)
67
66
  ];
68
67
  throw new Error(
69
- `Invalid array index "${i}" in path "${n.join(".")}".`
68
+ `Invalid array index "${t}" in path "${e.join(".")}".`
70
69
  );
71
- } else if (typeof e == "object" && e !== null)
70
+ } else if (typeof n == "object" && n !== null)
72
71
  if (r.length === 0) {
73
- const { [t]: i, ...s } = e;
74
- return s;
72
+ const { [i]: t, ...l } = n;
73
+ return l;
75
74
  } else {
76
- if (t in e)
75
+ if (i in n)
77
76
  return {
78
- ...e,
79
- [t]: p(r, e[t])
77
+ ...n,
78
+ [i]: p(r, n[i])
80
79
  };
81
80
  throw new Error(
82
- `Invalid property "${t}" in path "${n.join(".")}".`
81
+ `Invalid property "${i}" in path "${e.join(".")}".`
83
82
  );
84
83
  }
85
84
  else
86
85
  throw new Error(
87
- `Cannot delete nested property at path "${n.join(".")}". The path does not exist.`
86
+ `Cannot delete nested property at path "${e.join(".")}". The path does not exist.`
88
87
  );
89
88
  }
90
- function N(n, e, t) {
91
- let r = n;
92
- for (let i = 0; i < e.length; i++) {
93
- const s = e[i];
94
- if (r == null)
95
- return;
96
- if (typeof s == "string" && s.startsWith("id:")) {
97
- if (!Array.isArray(r)) {
98
- console.error("Path segment with 'id:' requires an array.", {
99
- path: e,
100
- currentValue: r
101
- });
102
- return;
103
- }
104
- const o = e.slice(0, i), f = [t, ...o, s].join("."), l = [t, ...o].join("."), a = w.getState().shadowStateStore.get(l);
105
- if (!a?.arrayKeys) {
106
- console.error(
107
- "No arrayKeys found in shadow state for parent path:",
108
- l
109
- );
110
- return;
111
- }
112
- const y = a.arrayKeys.indexOf(f);
113
- if (y === -1) {
114
- console.error(
115
- `Item key ${f} not found in parent's arrayKeys:`,
116
- a.arrayKeys
117
- );
118
- return;
119
- }
120
- r = r[y];
121
- } else Array.isArray(r) ? r = r[parseInt(s)] : r = r[s];
122
- }
123
- return r;
124
- }
125
- function u(n, e, t = "") {
89
+ function a(e, n, i = "") {
126
90
  let r = [];
127
- if (typeof n == "function" && typeof e == "function")
91
+ if (typeof e == "function" && typeof n == "function")
128
92
  return r;
129
- if (n == null || e === null || e === void 0)
130
- return n !== e ? [t] : r;
131
- if (typeof n != "object" || typeof e != "object")
132
- return n !== e ? [t] : r;
133
- if (Array.isArray(n) && Array.isArray(e)) {
134
- n.length !== e.length && r.push(`${t}`);
135
- const f = Math.min(n.length, e.length);
136
- for (let l = 0; l < f; l++)
137
- n[l] !== e[l] && (r = r.concat(
138
- u(
139
- n[l],
140
- e[l],
141
- t ? `${t}.${l}` : `${l}`
93
+ if (e == null || n === null || n === void 0)
94
+ return e !== n ? [i] : r;
95
+ if (typeof e != "object" || typeof n != "object")
96
+ return e !== n ? [i] : r;
97
+ if (Array.isArray(e) && Array.isArray(n)) {
98
+ e.length !== n.length && r.push(`${i}`);
99
+ const o = Math.min(e.length, n.length);
100
+ for (let f = 0; f < o; f++)
101
+ e[f] !== n[f] && (r = r.concat(
102
+ a(
103
+ e[f],
104
+ n[f],
105
+ i ? `${i}.${f}` : `${f}`
142
106
  )
143
107
  ));
144
- if (n.length !== e.length) {
145
- const l = n.length > e.length ? n : e;
146
- for (let a = f; a < l.length; a++)
147
- r.push(t ? `${t}.${a}` : `${a}`);
108
+ if (e.length !== n.length) {
109
+ const f = e.length > n.length ? e : n;
110
+ for (let c = o; c < f.length; c++)
111
+ r.push(i ? `${i}.${c}` : `${c}`);
148
112
  }
149
113
  return r;
150
114
  }
151
- const i = Object.keys(n), s = Object.keys(e);
152
- return Array.from(/* @__PURE__ */ new Set([...i, ...s])).forEach((f) => {
153
- const l = t ? `${t}.${f}` : f;
115
+ const t = Object.keys(e), l = Object.keys(n);
116
+ return Array.from(/* @__PURE__ */ new Set([...t, ...l])).forEach((o) => {
117
+ const f = i ? `${i}.${o}` : o;
154
118
  r = r.concat(
155
- u(n[f], e[f], l)
119
+ a(e[o], n[o], f)
156
120
  );
157
121
  }), r;
158
122
  }
159
- function $(n, e) {
160
- const t = { ...n };
161
- return c(n) && c(e) && Object.keys(e).forEach((r) => {
162
- c(e[r]) ? r in n ? t[r] = $(n[r], e[r]) : Object.assign(t, { [r]: e[r] }) : Object.assign(t, { [r]: e[r] });
163
- }), t;
123
+ function A(e, n) {
124
+ const i = { ...e };
125
+ return u(e) && u(n) && Object.keys(n).forEach((r) => {
126
+ u(n[r]) ? r in e ? i[r] = A(e[r], n[r]) : Object.assign(i, { [r]: n[r] }) : Object.assign(i, { [r]: n[r] });
127
+ }), i;
164
128
  }
165
- function S(n, e) {
166
- return u(n, e).map(
129
+ function w(e, n) {
130
+ return a(e, n).map(
167
131
  (r) => r.replace(/\[(\w+)\]/g, ".$1").split(".").filter(Boolean)
168
132
  );
169
133
  }
170
- function A(n, e, t = "") {
134
+ function h(e, n, i = "") {
171
135
  let r = [];
172
- if (n == null || e === null || e === void 0)
136
+ if (e == null || n === null || n === void 0)
173
137
  return r;
174
- if (Array.isArray(n) && Array.isArray(e))
175
- n.length !== e.length && r.push(t);
176
- else if (typeof n == "object" && typeof e == "object") {
177
- const i = /* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(e)]);
178
- for (const s of i) {
179
- const o = t ? `${t}.${s}` : s;
180
- (Array.isArray(n[s]) || Array.isArray(e[s])) && (r = r.concat(
181
- A(n[s], e[s], o)
138
+ if (Array.isArray(e) && Array.isArray(n))
139
+ e.length !== n.length && r.push(i);
140
+ else if (typeof e == "object" && typeof n == "object") {
141
+ const t = /* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(n)]);
142
+ for (const l of t) {
143
+ const s = i ? `${i}.${l}` : l;
144
+ (Array.isArray(e[l]) || Array.isArray(n[l])) && (r = r.concat(
145
+ h(e[l], n[l], s)
182
146
  ));
183
147
  }
184
148
  }
185
149
  return r;
186
150
  }
187
- function O(n, e) {
188
- return A(n, e).map(
151
+ function m(e, n) {
152
+ return h(e, n).map(
189
153
  (r) => r.replace(/\[(\w+)\]/g, ".$1").split(".").filter(Boolean)
190
154
  );
191
155
  }
192
- function I(n) {
193
- const e = (s) => Object.values(s).some(
194
- (o) => o?.hasOwnProperty("initialState")
156
+ function N(e) {
157
+ const n = (l) => Object.values(l).some(
158
+ (s) => s?.hasOwnProperty("initialState")
195
159
  );
196
- let t = {};
197
- const r = (s) => {
198
- const o = {};
199
- return Object.entries(s).forEach(([f, l]) => {
200
- l?.initialState ? (t = { ...t ?? {}, [f]: l }, o[f] = l.initialState) : o[f] = l;
201
- }), o;
160
+ let i = {};
161
+ const r = (l) => {
162
+ const s = {};
163
+ return Object.entries(l).forEach(([o, f]) => {
164
+ f?.initialState ? (i = { ...i ?? {}, [o]: f }, s[o] = f.initialState) : s[o] = f;
165
+ }), s;
202
166
  };
203
- return [e(n) ? r(n) : n, t];
167
+ return [n(e) ? r(e) : e, i];
204
168
  }
205
- function D(n, e) {
206
- let t = null;
207
- const r = (...i) => {
208
- t && clearTimeout(t), t = setTimeout(() => n(...i), e);
169
+ function O(e, n) {
170
+ let i = null;
171
+ const r = (...t) => {
172
+ i && clearTimeout(i), i = setTimeout(() => e(...t), n);
209
173
  };
210
174
  return r.cancel = () => {
211
- t && (clearTimeout(t), t = null);
175
+ i && (clearTimeout(i), i = null);
212
176
  }, r;
213
177
  }
214
178
  export {
215
- D as debounce,
216
- $ as deepMerge,
179
+ O as debounce,
180
+ A as deepMerge,
217
181
  p as deleteNestedProperty,
218
- A as getArrayLengthDifferences,
219
- O as getArrayLengthDifferencesArray,
220
- u as getDifferences,
221
- S as getDifferencesArray,
222
- N as getNestedValue,
223
- d as isArray,
224
- g as isDeepEqual,
225
- v as isFunction,
226
- c as isObject,
227
- I as transformStateFunc,
228
- h as updateNestedProperty
182
+ h as getArrayLengthDifferences,
183
+ m as getArrayLengthDifferencesArray,
184
+ a as getDifferences,
185
+ w as getDifferencesArray,
186
+ y as isArray,
187
+ d as isDeepEqual,
188
+ $ as isFunction,
189
+ u as isObject,
190
+ N as transformStateFunc,
191
+ g as updateNestedProperty
229
192
  };
230
193
  //# sourceMappingURL=utility.js.map