cogsbox-state 0.5.475-canary.4 → 0.5.475-canary.8
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/CogsState.d.ts +4 -1
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +198 -198
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Components.d.ts +5 -6
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.jsx +165 -158
- package/dist/Components.jsx.map +1 -1
- package/package.json +2 -2
- package/src/CogsState.tsx +34 -22
- package/src/Components.tsx +26 -14
package/dist/Components.jsx.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Components.jsx","sources":["../src/Components.tsx"],"sourcesContent":["import {\r\n FormElementParams,\r\n StateObject,\r\n UpdateTypeDetail,\r\n type FormOptsType,\r\n} from './CogsState';\r\nimport { pluginStore } from './pluginStore';\r\nimport {\r\n createMetadataContext,\r\n createScopedMetadataContext,\r\n toDeconstructedMethods,\r\n} from './plugins';\r\nimport React, {\r\n memo,\r\n RefObject,\r\n useCallback,\r\n useEffect,\r\n useLayoutEffect,\r\n useRef,\r\n useState,\r\n useMemo,\r\n} from 'react';\r\nimport { getGlobalStore, ValidationError, ValidationSeverity } from './store';\r\nimport { useInView } from 'react-intersection-observer';\r\nimport { v4 as uuidv4 } from 'uuid';\r\nimport { isDeepEqual } from './utility';\r\nimport { runValidation } from './validation';\r\n\r\nconst {\r\n getInitialOptions,\r\n\r\n getShadowMetadata,\r\n setShadowMetadata,\r\n getShadowValue,\r\n\r\n registerComponent,\r\n unregisterComponent,\r\n\r\n notifyPathSubscribers,\r\n subscribeToPath,\r\n} = getGlobalStore.getState();\r\nconst { stateHandlers, notifyFormUpdate } = pluginStore.getState();\r\n\r\nexport type ValidationWrapperProps = {\r\n formOpts?: FormOptsType;\r\n path: string[];\r\n stateKey: string;\r\n children: React.ReactNode;\r\n};\r\n\r\nexport function ValidationWrapper({\r\n formOpts,\r\n path,\r\n stateKey,\r\n children,\r\n}: ValidationWrapperProps) {\r\n const { getInitialOptions, getShadowMetadata, getShadowValue } =\r\n getGlobalStore.getState();\r\n const thisStateOpts = getInitialOptions(stateKey!);\r\n\r\n const shadowMeta = getShadowMetadata(stateKey!, path);\r\n const validationState = shadowMeta?.validation;\r\n\r\n const status = validationState?.status || 'NOT_VALIDATED';\r\n\r\n const errors = (validationState?.errors || []).map((err) => ({\r\n ...err,\r\n path: path,\r\n })) as ValidationError[];\r\n const errorMessages = errors\r\n .filter((err) => err.severity === 'error')\r\n .map((err) => err.message);\r\n const warningMessages = errors\r\n .filter((err) => err.severity === 'warning')\r\n .map((err) => err.message);\r\n\r\n // Use first error, or first warning if no errors\r\n const message = errorMessages[0] || warningMessages[0];\r\n const primarySeverity: ValidationSeverity =\r\n errorMessages.length > 0\r\n ? 'error'\r\n : warningMessages.length > 0\r\n ? 'warning'\r\n : undefined;\r\n const { registeredPlugins } = pluginStore.getState();\r\n const pluginsApi: any = {};\r\n\r\n // We iterate over ALL registered plugins in the app.\r\n registeredPlugins.forEach((plugin) => {\r\n // A plugin is considered \"active\" for this state key if its name\r\n // exists as a key in the options (e.g., options.syncPlugin exists).\r\n if (thisStateOpts && thisStateOpts.hasOwnProperty(plugin.name)) {\r\n const pluginName = plugin.name;\r\n\r\n // Now we can safely build the API for this active plugin.\r\n const hookData = pluginStore\r\n .getState()\r\n .getHookResult(stateKey, pluginName);\r\n\r\n const scopedMetadata = createScopedMetadataContext(\r\n stateKey,\r\n pluginName,\r\n path\r\n );\r\n\r\n pluginsApi[pluginName] = {\r\n hookData,\r\n getFieldMetaData: scopedMetadata.getFieldMetaData,\r\n setFieldMetaData: scopedMetadata.setFieldMetaData,\r\n };\r\n }\r\n });\r\n return (\r\n <>\r\n {thisStateOpts?.formElements?.validation &&\r\n !formOpts?.validation?.disable ? (\r\n thisStateOpts.formElements!.validation!({\r\n children: (\r\n <React.Fragment key={path.toString()}>{children}</React.Fragment>\r\n ),\r\n status, // Now passes the new ValidationStatus type\r\n message: formOpts?.validation?.hideMessage\r\n ? ''\r\n : formOpts?.validation?.message || message || '',\r\n severity: primarySeverity,\r\n hasErrors: errorMessages.length > 0,\r\n hasWarnings: warningMessages.length > 0,\r\n allErrors: errors,\r\n path: path,\r\n getData: () => getShadowValue(stateKey!, path),\r\n plugins: pluginsApi,\r\n })\r\n ) : (\r\n <React.Fragment key={path.toString()}>{children}</React.Fragment>\r\n )}\r\n </>\r\n );\r\n}\r\nexport const MemoizedCogsItemWrapper = memo(\r\n ListItemWrapper,\r\n (prevProps, nextProps) => {\r\n // Re-render if any of these change:\r\n return (\r\n prevProps.itemPath.join('.') === nextProps.itemPath.join('.') &&\r\n prevProps.stateKey === nextProps.stateKey &&\r\n prevProps.itemComponentId === nextProps.itemComponentId &&\r\n prevProps.localIndex === nextProps.localIndex\r\n );\r\n }\r\n);\r\nexport function ListItemWrapper({\r\n stateKey,\r\n itemComponentId,\r\n itemPath,\r\n localIndex,\r\n arraySetter,\r\n rebuildStateShape,\r\n renderFn,\r\n}: {\r\n stateKey: string;\r\n itemComponentId: string;\r\n itemPath: string[];\r\n localIndex: number;\r\n arraySetter: any;\r\n\r\n rebuildStateShape: (options: {\r\n currentState: any;\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n }) => any;\r\n renderFn: (\r\n setter: any,\r\n index: number,\r\n\r\n arraySetter: any\r\n ) => React.ReactNode;\r\n}) {\r\n const [, forceUpdate] = useState({});\r\n const { ref: inViewRef, inView } = useInView();\r\n const elementRef = useRef<HTMLDivElement | null>(null);\r\n\r\n const imagesLoaded = useImageLoaded(elementRef);\r\n const hasReportedInitialHeight = useRef(false);\r\n const fullKey = [stateKey, ...itemPath].join('.');\r\n useRegisterComponent(stateKey, itemComponentId, forceUpdate);\r\n\r\n const setRefs = useCallback(\r\n (element: HTMLDivElement | null) => {\r\n elementRef.current = element;\r\n inViewRef(element); // This is the ref from useInView\r\n },\r\n [inViewRef]\r\n );\r\n\r\n useEffect(() => {\r\n const unsubscribe = subscribeToPath(fullKey, (e) => {\r\n forceUpdate({});\r\n });\r\n return () => unsubscribe();\r\n }, [fullKey]);\r\n useEffect(() => {\r\n if (!inView || !imagesLoaded || hasReportedInitialHeight.current) {\r\n return;\r\n }\r\n\r\n const element = elementRef.current;\r\n if (element && element.offsetHeight > 0) {\r\n hasReportedInitialHeight.current = true;\r\n const newHeight = element.offsetHeight;\r\n\r\n setShadowMetadata(stateKey, itemPath, {\r\n virtualizer: {\r\n itemHeight: newHeight,\r\n domRef: element,\r\n },\r\n });\r\n\r\n const arrayPath = itemPath.slice(0, -1);\r\n const arrayPathKey = [stateKey, ...arrayPath].join('.');\r\n notifyPathSubscribers(arrayPathKey, {\r\n type: 'ITEMHEIGHT',\r\n itemKey: itemPath.join('.'),\r\n\r\n ref: elementRef.current,\r\n });\r\n }\r\n }, [inView, imagesLoaded, stateKey, itemPath]);\r\n\r\n const itemValue = getShadowValue(stateKey, itemPath);\r\n\r\n if (itemValue === undefined) {\r\n return null;\r\n }\r\n\r\n const itemSetter = rebuildStateShape({\r\n currentState: itemValue,\r\n path: itemPath,\r\n componentId: itemComponentId,\r\n });\r\n const children = renderFn(itemSetter, localIndex, arraySetter);\r\n\r\n return <div ref={setRefs}>{children}</div>;\r\n}\r\n\r\nexport function FormElementWrapper({\r\n stateKey,\r\n path,\r\n rebuildStateShape,\r\n renderFn,\r\n formOpts,\r\n setState,\r\n}: {\r\n stateKey: string;\r\n path: string[];\r\n rebuildStateShape: (options: {\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n }) => any;\r\n renderFn: (params: FormElementParams<any>) => React.ReactNode;\r\n formOpts?: FormOptsType;\r\n setState: any;\r\n}) {\r\n const componentId = useRef(uuidv4()).current;\r\n\r\n const [, forceUpdate] = useState({});\r\n const formElementRef = useRef<any>(null);\r\n const stateKeyPathKey = [stateKey, ...path].join('.');\r\n useRegisterComponent(stateKey, componentId, forceUpdate);\r\n // Get the shadow node to access typeInfo and schema\r\n const shadowNode = getGlobalStore.getState().getShadowNode(stateKey, path);\r\n const typeInfo = shadowNode?._meta?.typeInfo;\r\n\r\n const globalStateValue = getShadowValue(stateKey, path);\r\n const [localValue, setLocalValue] = useState<any>(globalStateValue);\r\n const isCurrentlyDebouncing = useRef(false);\r\n const debounceTimeoutRef = useRef<NodeJS.Timeout | null>(null);\r\n\r\n useEffect(() => {\r\n if (\r\n !isCurrentlyDebouncing.current &&\r\n !isDeepEqual(globalStateValue, localValue)\r\n ) {\r\n setLocalValue(globalStateValue);\r\n }\r\n }, [globalStateValue]);\r\n\r\n useEffect(() => {\r\n const { getShadowMetadata, setShadowMetadata } = getGlobalStore.getState();\r\n\r\n // Initialize clientActivityState if needed\r\n const currentMeta = getShadowMetadata(stateKey, path) || {};\r\n if (!currentMeta.clientActivityState) {\r\n currentMeta.clientActivityState = { elements: new Map() };\r\n }\r\n\r\n // Detect element type from the ref\r\n const detectElementType = () => {\r\n const el = formElementRef.current;\r\n if (!el) return 'input';\r\n const tagName = el.tagName.toLowerCase();\r\n if (tagName === 'textarea') return 'textarea';\r\n if (tagName === 'select') return 'select';\r\n if (tagName === 'input') {\r\n const type = (el as HTMLInputElement).type;\r\n if (type === 'checkbox') return 'checkbox';\r\n if (type === 'radio') return 'radio';\r\n if (type === 'range') return 'range';\r\n if (type === 'file') return 'file';\r\n }\r\n return 'input';\r\n };\r\n\r\n // Add this element to the Map\r\n currentMeta.clientActivityState.elements.set(componentId, {\r\n domRef: formElementRef,\r\n elementType: detectElementType(),\r\n inputType: formElementRef.current?.type,\r\n mountedAt: Date.now(),\r\n });\r\n\r\n setShadowMetadata(stateKey, path, currentMeta);\r\n\r\n // Subscribe to path updates\r\n const unsubscribe = getGlobalStore\r\n .getState()\r\n .subscribeToPath(stateKeyPathKey, (newValue) => {\r\n if (!isCurrentlyDebouncing.current && localValue !== newValue) {\r\n forceUpdate({});\r\n }\r\n });\r\n\r\n // Cleanup\r\n return () => {\r\n unsubscribe();\r\n\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n isCurrentlyDebouncing.current = false;\r\n }\r\n\r\n // Remove element from Map\r\n const meta = getGlobalStore.getState().getShadowMetadata(stateKey, path);\r\n if (meta?.clientActivityState?.elements) {\r\n meta.clientActivityState.elements.delete(componentId);\r\n setShadowMetadata(stateKey, path, meta);\r\n }\r\n };\r\n }, []);\r\n\r\n const debouncedUpdate = useCallback(\r\n (newValue: any) => {\r\n // Type conversion logic (keep existing)\r\n if (typeInfo) {\r\n if (typeInfo.type === 'number' && typeof newValue === 'string') {\r\n newValue =\r\n newValue === ''\r\n ? typeInfo.nullable\r\n ? null\r\n : (typeInfo.default ?? 0)\r\n : Number(newValue);\r\n } else if (\r\n typeInfo.type === 'boolean' &&\r\n typeof newValue === 'string'\r\n ) {\r\n newValue = newValue === 'true' || newValue === '1';\r\n } else if (typeInfo.type === 'date' && typeof newValue === 'string') {\r\n newValue = new Date(newValue);\r\n }\r\n } else {\r\n const currentType = typeof globalStateValue;\r\n if (currentType === 'number' && typeof newValue === 'string') {\r\n newValue = newValue === '' ? 0 : Number(newValue);\r\n }\r\n }\r\n\r\n setLocalValue(newValue);\r\n\r\n // Update input activity details\r\n const { getShadowMetadata, setShadowMetadata } =\r\n getGlobalStore.getState();\r\n const meta = getShadowMetadata(stateKey, path);\r\n if (meta?.clientActivityState?.elements?.has(componentId)) {\r\n const element = meta.clientActivityState.elements.get(componentId);\r\n if (element && element.currentActivity?.type === 'focus') {\r\n element!.currentActivity.details = {\r\n ...element!.currentActivity.details,\r\n value: newValue,\r\n previousValue:\r\n element!.currentActivity.details?.value || globalStateValue,\r\n inputLength:\r\n typeof newValue === 'string' ? newValue.length : undefined,\r\n keystrokeCount:\r\n (element!.currentActivity.details?.keystrokeCount || 0) + 1,\r\n };\r\n setShadowMetadata(stateKey, path, meta);\r\n }\r\n }\r\n const element = meta?.clientActivityState?.elements?.get(componentId);\r\n\r\n // Notify plugins\r\n notifyFormUpdate({\r\n stateKey,\r\n activityType: 'input', // Changed from 'type'\r\n path,\r\n timestamp: Date.now(),\r\n details: {\r\n value: newValue,\r\n inputLength:\r\n typeof newValue === 'string' ? newValue.length : undefined,\r\n isComposing: false, // You'd need to track this from the actual input event\r\n isPasting: false, // You'd need to track this from paste events\r\n keystrokeCount:\r\n (element?.currentActivity?.details?.keystrokeCount || 0) + 1,\r\n },\r\n });\r\n // Validation (keep existing)\r\n const virtualOperation: UpdateTypeDetail = {\r\n stateKey,\r\n path,\r\n newValue: newValue,\r\n updateType: 'update',\r\n timeStamp: Date.now(),\r\n status: 'new',\r\n oldValue: globalStateValue,\r\n };\r\n runValidation(virtualOperation, 'onChange');\r\n\r\n // Debounce state update (keep existing)\r\n isCurrentlyDebouncing.current = true;\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n }\r\n\r\n const debounceTime = formOpts?.debounceTime ?? 200;\r\n debounceTimeoutRef.current = setTimeout(() => {\r\n isCurrentlyDebouncing.current = false;\r\n setState(newValue, path, {\r\n updateType: 'update',\r\n validationTrigger: 'onChange',\r\n });\r\n }, debounceTime);\r\n },\r\n [\r\n setState,\r\n path,\r\n formOpts?.debounceTime,\r\n typeInfo,\r\n globalStateValue,\r\n stateKey,\r\n componentId,\r\n ]\r\n );\r\n\r\n const handleFocus = useCallback(() => {\r\n const { getShadowMetadata, setShadowMetadata } = getGlobalStore.getState();\r\n\r\n // Update element's current activity\r\n const meta = getShadowMetadata(stateKey, path);\r\n if (meta?.clientActivityState?.elements?.has(componentId)) {\r\n const element = meta.clientActivityState.elements.get(componentId)!;\r\n element.currentActivity = {\r\n type: 'focus',\r\n startTime: Date.now(),\r\n details: {\r\n value: localValue,\r\n inputLength:\r\n typeof localValue === 'string' ? localValue.length : undefined,\r\n },\r\n };\r\n setShadowMetadata(stateKey, path, meta);\r\n }\r\n\r\n // Notify plugins\r\n notifyFormUpdate({\r\n stateKey,\r\n activityType: 'focus', // Changed from 'type'\r\n path,\r\n timestamp: Date.now(),\r\n details: {\r\n cursorPosition: formElementRef.current?.selectionStart,\r\n },\r\n });\r\n }, [stateKey, path, componentId, localValue]);\r\n const handleBlur = useCallback(() => {\r\n const { getShadowMetadata, setShadowMetadata } = getGlobalStore.getState();\r\n\r\n // Clear debounce if active\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n debounceTimeoutRef.current = null;\r\n isCurrentlyDebouncing.current = false;\r\n setState(localValue, path, {\r\n updateType: 'update',\r\n validationTrigger: 'onBlur',\r\n });\r\n }\r\n\r\n // Clear element's current activity\r\n const meta = getShadowMetadata(stateKey, path);\r\n if (meta?.clientActivityState?.elements?.has(componentId)) {\r\n const element = meta.clientActivityState.elements.get(componentId)!;\r\n element.currentActivity = undefined;\r\n setShadowMetadata(stateKey, path, meta);\r\n }\r\n const focusStartTime =\r\n meta?.clientActivityState?.elements?.get(componentId)?.currentActivity\r\n ?.startTime;\r\n\r\n // Notify plugins\r\n notifyFormUpdate({\r\n stateKey,\r\n activityType: 'blur', // Changed from 'type'\r\n path,\r\n timestamp: Date.now(),\r\n duration: focusStartTime ? Date.now() - focusStartTime : undefined,\r\n details: {\r\n duration: focusStartTime ? Date.now() - focusStartTime : 0,\r\n },\r\n });\r\n\r\n // Run validation if configured\r\n const validationOptions = getInitialOptions(stateKey)?.validation;\r\n if (validationOptions?.onBlur) {\r\n const virtualOperation: UpdateTypeDetail = {\r\n stateKey,\r\n path,\r\n newValue: localValue,\r\n updateType: 'update',\r\n timeStamp: Date.now(),\r\n status: 'new',\r\n oldValue: globalStateValue,\r\n };\r\n runValidation(virtualOperation, 'onBlur');\r\n }\r\n }, [localValue, setState, path, stateKey, componentId, globalStateValue]);\r\n\r\n const baseState = rebuildStateShape({\r\n path: path,\r\n componentId: componentId,\r\n meta: undefined,\r\n });\r\n\r\n const stateWithInputProps = new Proxy(baseState, {\r\n get(target, prop) {\r\n if (prop === '$inputProps') {\r\n return {\r\n value: localValue ?? '',\r\n onChange: (e: any) => {\r\n debouncedUpdate(e.target.value);\r\n },\r\n onFocus: handleFocus,\r\n onBlur: handleBlur,\r\n ref: formElementRef,\r\n };\r\n }\r\n\r\n return target[prop];\r\n },\r\n });\r\n\r\n const initialElement = renderFn(stateWithInputProps);\r\n\r\n return (\r\n <ValidationWrapper formOpts={formOpts} path={path} stateKey={stateKey}>\r\n {initialElement}\r\n </ValidationWrapper>\r\n );\r\n}\r\nexport function useRegisterComponent(\r\n stateKey: string,\r\n componentId: string,\r\n forceUpdate: (o: object) => void\r\n) {\r\n const fullComponentId = `${stateKey}////${componentId}`;\r\n\r\n useLayoutEffect(() => {\r\n registerComponent(stateKey, fullComponentId, {\r\n forceUpdate: () => forceUpdate({}),\r\n paths: new Set(),\r\n reactiveType: ['component'],\r\n });\r\n return () => {\r\n unregisterComponent(stateKey, fullComponentId);\r\n };\r\n }, [stateKey, fullComponentId]);\r\n}\r\n\r\nconst useImageLoaded = (ref: RefObject<HTMLElement>): boolean => {\r\n const [loaded, setLoaded] = useState(false);\r\n\r\n useLayoutEffect(() => {\r\n if (!ref.current) {\r\n setLoaded(true);\r\n return;\r\n }\r\n\r\n const images = Array.from(ref.current.querySelectorAll('img'));\r\n\r\n // If there are no images, we are \"loaded\" immediately.\r\n if (images.length === 0) {\r\n setLoaded(true);\r\n return;\r\n }\r\n\r\n let loadedCount = 0;\r\n const handleImageLoad = () => {\r\n loadedCount++;\r\n if (loadedCount === images.length) {\r\n setLoaded(true);\r\n }\r\n };\r\n\r\n images.forEach((image) => {\r\n if (image.complete) {\r\n handleImageLoad();\r\n } else {\r\n image.addEventListener('load', handleImageLoad);\r\n image.addEventListener('error', handleImageLoad);\r\n }\r\n });\r\n\r\n return () => {\r\n images.forEach((image) => {\r\n image.removeEventListener('load', handleImageLoad);\r\n image.removeEventListener('error', handleImageLoad);\r\n });\r\n };\r\n }, [ref.current]);\r\n\r\n return loaded;\r\n};\r\n// Components.tsx\r\n\r\n// Generic isolated component wrapper\r\nexport function IsolatedComponentWrapper({\r\n stateKey,\r\n path,\r\n rebuildStateShape,\r\n renderFn,\r\n}: {\r\n stateKey: string;\r\n path: string[];\r\n rebuildStateShape: (options: {\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n }) => any;\r\n renderFn: (state: any) => React.ReactNode;\r\n}) {\r\n const [componentId] = useState(() => uuidv4());\r\n const [, forceUpdate] = useState({});\r\n\r\n const stateKeyPathKey = [stateKey, ...path].join('.');\r\n useRegisterComponent(stateKey, componentId, forceUpdate);\r\n\r\n useEffect(() => {\r\n const unsubscribe = getGlobalStore\r\n .getState()\r\n .subscribeToPath(stateKeyPathKey, () => {\r\n forceUpdate({});\r\n });\r\n return () => unsubscribe();\r\n }, [stateKeyPathKey]);\r\n\r\n const baseState = rebuildStateShape({\r\n path: path,\r\n componentId: componentId,\r\n meta: undefined,\r\n });\r\n\r\n return <>{renderFn(baseState)}</>;\r\n}\r\n\r\n// 1. Define the MINIMAL props needed.\r\ntype PluginWrapperProps = {\r\n children: React.ReactNode;\r\n stateKey: string;\r\n path: string[];\r\n pluginName: string;\r\n wrapperDepth: number;\r\n};\r\n\r\nconst PluginWrapper = memo(function PluginWrapper({\r\n children,\r\n stateKey,\r\n path,\r\n pluginName,\r\n wrapperDepth,\r\n}: PluginWrapperProps) {\r\n const [, forceUpdate] = useState({});\r\n\r\n useEffect(() => {\r\n const fullPathKey = [stateKey, ...path].join('.');\r\n const unsubscribe = getGlobalStore\r\n .getState()\r\n .subscribeToPath(fullPathKey, () => {\r\n forceUpdate({});\r\n });\r\n return unsubscribe;\r\n }, [stateKey, path]);\r\n\r\n const plugin = pluginStore\r\n .getState()\r\n .registeredPlugins.find((p) => p.name === pluginName);\r\n\r\n const stateHandler: StateObject<any> | undefined = pluginStore\r\n .getState()\r\n .stateHandlers.get(stateKey);\r\n\r\n const typeInfo = getGlobalStore.getState().getShadowNode(stateKey, path)\r\n ?._meta?.typeInfo;\r\n\r\n const options = pluginStore\r\n .getState()\r\n .pluginOptions.get(stateKey)\r\n ?.get(pluginName);\r\n\r\n const hookData = pluginStore.getState().getHookResult(stateKey, pluginName);\r\n\r\n if (!plugin?.formWrapper || !stateHandler) {\r\n return <>{children}</>;\r\n }\r\n\r\n const deconstructed = toDeconstructedMethods(stateHandler);\r\n const scopedMetadataContext = createScopedMetadataContext(\r\n stateKey,\r\n plugin.name,\r\n path\r\n );\r\n return plugin.formWrapper({\r\n element: children,\r\n path,\r\n stateKey,\r\n pluginName: plugin.name,\r\n ...deconstructed,\r\n\r\n ...scopedMetadataContext,\r\n options,\r\n hookData,\r\n fieldType: typeInfo?.type,\r\n wrapperDepth,\r\n });\r\n});\r\n"],"names":["getInitialOptions","getShadowMetadata","setShadowMetadata","getShadowValue","registerComponent","unregisterComponent","notifyPathSubscribers","subscribeToPath","getGlobalStore","stateHandlers","notifyFormUpdate","pluginStore","ValidationWrapper","formOpts","path","stateKey","children","thisStateOpts","validationState","status","errors","err","errorMessages","warningMessages","message","primarySeverity","registeredPlugins","pluginsApi","plugin","pluginName","hookData","scopedMetadata","createScopedMetadataContext","jsx","Fragment","React","MemoizedCogsItemWrapper","memo","ListItemWrapper","prevProps","nextProps","itemComponentId","itemPath","localIndex","arraySetter","rebuildStateShape","renderFn","forceUpdate","useState","inViewRef","inView","useInView","elementRef","useRef","imagesLoaded","useImageLoaded","hasReportedInitialHeight","fullKey","useRegisterComponent","setRefs","useCallback","element","useEffect","unsubscribe","e","newHeight","arrayPath","arrayPathKey","itemValue","itemSetter","FormElementWrapper","setState","componentId","uuidv4","formElementRef","stateKeyPathKey","typeInfo","globalStateValue","localValue","setLocalValue","isCurrentlyDebouncing","debounceTimeoutRef","isDeepEqual","currentMeta","detectElementType","el","tagName","type","newValue","meta","debouncedUpdate","runValidation","debounceTime","handleFocus","handleBlur","focusStartTime","baseState","stateWithInputProps","target","prop","initialElement","fullComponentId","useLayoutEffect","ref","loaded","setLoaded","images","loadedCount","handleImageLoad","image","IsolatedComponentWrapper","wrapperDepth","fullPathKey","p","stateHandler","options","deconstructed","toDeconstructedMethods","scopedMetadataContext"],"mappings":";;;;;;;;;AA4BA,MAAM;AAAA,EACJ,mBAAAA;AAAA,EAEA,mBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,gBAAAC;AAAA,EAEA,mBAAAC;AAAA,EACA,qBAAAC;AAAA,EAEA,uBAAAC;AAAA,EACA,iBAAAC;AACF,IAAIC,EAAe,SAAA,GACb,EAAE,eAAAC,IAAe,kBAAAC,MAAqBC,EAAY,SAAA;AASjD,SAASC,GAAkB;AAAA,EAChC,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AACF,GAA2B;AACzB,QAAM,EAAE,mBAAAhB,GAAmB,mBAAAC,GAAmB,gBAAAE,EAAAA,IAC5CK,EAAe,SAAA,GACXS,IAAgBjB,EAAkBe,CAAS,GAG3CG,IADajB,EAAkBc,GAAWD,CAAI,GAChB,YAE9BK,IAASD,GAAiB,UAAU,iBAEpCE,KAAUF,GAAiB,UAAU,CAAA,GAAI,IAAI,CAACG,OAAS;AAAA,IAC3D,GAAGA;AAAA,IACH,MAAAP;AAAA,EAAA,EACA,GACIQ,IAAgBF,EACnB,OAAO,CAACC,MAAQA,EAAI,aAAa,OAAO,EACxC,IAAI,CAACA,MAAQA,EAAI,OAAO,GACrBE,IAAkBH,EACrB,OAAO,CAACC,MAAQA,EAAI,aAAa,SAAS,EAC1C,IAAI,CAACA,MAAQA,EAAI,OAAO,GAGrBG,IAAUF,EAAc,CAAC,KAAKC,EAAgB,CAAC,GAC/CE,IACJH,EAAc,SAAS,IACnB,UACAC,EAAgB,SAAS,IACvB,YACA,QACF,EAAE,mBAAAG,EAAA,IAAsBf,EAAY,SAAA,GACpCgB,IAAkB,CAAA;AAGxB,SAAAD,EAAkB,QAAQ,CAACE,MAAW;AAGpC,QAAIX,KAAiBA,EAAc,eAAeW,EAAO,IAAI,GAAG;AAC9D,YAAMC,IAAaD,EAAO,MAGpBE,IAAW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AAU,MAAM;AACd,UAAMkD,IAAc,CAACjG,GAAU,GAAGD,CAAI,EAAE,KAAK,GAAG;AAMhD,WALoBN,EACjB,SAAA,EACA,gBAAgBwG,GAAa,MAAM;AAClC,MAAAjE,EAAY,CAAA,CAAE;AAAA,IAChB,CAAC;AAAA,EAEL,GAAG,CAAChC,GAAUD,CAAI,CAAC;AAEnB,QAAMc,IAASjB,EACZ,SAAA,EACA,kBAAkB,KAAK,CAACsG,MAAMA,EAAE,SAASpF,CAAU,GAEhDqF,IAA6CvG,EAChD,SAAA,EACA,cAAc,IAAII,CAAQ,GAEvB6D,IAAWpE,EAAe,SAAA,EAAW,cAAcO,GAAUD,CAAI,GACnE,OAAO,UAELqG,IAAUxG,EACb,WACA,cAAc,IAAII,CAAQ,GACzB,IAAIc,CAAU,GAEZC,IAAWnB,EAAY,SAAA,EAAW,cAAcI,GAAUc,CAAU;AAE1E,MAAI,CAACD,GAAQ,eAAe,CAACsF;AAC3B,kCAAU,UAAAlG,GAAS;AAGrB,QAAMoG,IAAgBC,EAAuBH,CAAY,GACnDI,IAAwBtF;AAAA,IAC5BjB;AAAA,IACAa,EAAO;AAAA,IACPd;AAAA,EAAA;AAEF,SAAOc,EAAO,YAAY;AAAA,IACxB,SAASZ;AAAA,IACT,MAAAF;AAAA,IACA,UAAAC;AAAA,IACA,YAAYa,EAAO;AAAA,IACnB,GAAGwF;AAAA,IAEH,GAAGE;AAAA,IACH,SAAAH;AAAA,IACA,UAAArF;AAAA,IACA,WAAW8C,GAAU;AAAA,IACrB,cAAAmC;AAAA,EAAA,CACD;AACH,CAAC;"}
|
|
1
|
+
{"version":3,"file":"Components.jsx","sources":["../src/Components.tsx"],"sourcesContent":["import {\r\n FormElementParams,\r\n StateObject,\r\n UpdateTypeDetail,\r\n type FormOptsType,\r\n} from './CogsState';\r\nimport { pluginStore } from './pluginStore';\r\nimport {\r\n createMetadataContext,\r\n createScopedMetadataContext,\r\n toDeconstructedMethods,\r\n} from './plugins';\r\nimport React, {\r\n memo,\r\n RefObject,\r\n useCallback,\r\n useEffect,\r\n useLayoutEffect,\r\n useRef,\r\n useState,\r\n useMemo,\r\n} from 'react';\r\nimport { getGlobalStore, ValidationError, ValidationSeverity } from './store';\r\nimport { useInView } from 'react-intersection-observer';\r\nimport { v4 as uuidv4 } from 'uuid';\r\nimport { isDeepEqual } from './utility';\r\nimport { runValidation } from './validation';\r\n\r\nconst {\r\n getInitialOptions,\r\n\r\n getShadowMetadata,\r\n setShadowMetadata,\r\n getShadowValue,\r\n\r\n registerComponent,\r\n unregisterComponent,\r\n\r\n notifyPathSubscribers,\r\n subscribeToPath,\r\n} = getGlobalStore.getState();\r\nconst { stateHandlers, notifyFormUpdate } = pluginStore.getState();\r\n\r\nexport type ValidationWrapperProps = {\r\n formOpts?: FormOptsType;\r\n path: string[];\r\n stateKey: string;\r\n children: React.ReactNode;\r\n};\r\n\r\nexport function ValidationWrapper({\r\n formOpts,\r\n path,\r\n stateKey,\r\n children,\r\n}: ValidationWrapperProps) {\r\n const { getInitialOptions, getShadowMetadata, getShadowValue } =\r\n getGlobalStore.getState();\r\n const thisStateOpts = getInitialOptions(stateKey!);\r\n\r\n const shadowMeta = getShadowMetadata(stateKey!, path);\r\n const validationState = shadowMeta?.validation;\r\n\r\n const status = validationState?.status || 'NOT_VALIDATED';\r\n\r\n const errors = (validationState?.errors || []).map((err) => ({\r\n ...err,\r\n path: path,\r\n })) as ValidationError[];\r\n const errorMessages = errors\r\n .filter((err) => err.severity === 'error')\r\n .map((err) => err.message);\r\n const warningMessages = errors\r\n .filter((err) => err.severity === 'warning')\r\n .map((err) => err.message);\r\n\r\n // Use first error, or first warning if no errors\r\n const message = errorMessages[0] || warningMessages[0];\r\n const primarySeverity: ValidationSeverity =\r\n errorMessages.length > 0\r\n ? 'error'\r\n : warningMessages.length > 0\r\n ? 'warning'\r\n : undefined;\r\n const { registeredPlugins } = pluginStore.getState();\r\n const pluginsApi: any = {};\r\n\r\n // We iterate over ALL registered plugins in the app.\r\n registeredPlugins.forEach((plugin) => {\r\n // A plugin is considered \"active\" for this state key if its name\r\n // exists as a key in the options (e.g., options.syncPlugin exists).\r\n if (thisStateOpts && thisStateOpts.hasOwnProperty(plugin.name)) {\r\n const pluginName = plugin.name;\r\n\r\n // Now we can safely build the API for this active plugin.\r\n const hookData = pluginStore\r\n .getState()\r\n .getHookResult(stateKey, pluginName);\r\n\r\n const scopedMetadata = createScopedMetadataContext(\r\n stateKey,\r\n pluginName,\r\n path\r\n );\r\n\r\n pluginsApi[pluginName] = {\r\n hookData,\r\n getFieldMetaData: scopedMetadata.getFieldMetaData,\r\n setFieldMetaData: scopedMetadata.setFieldMetaData,\r\n };\r\n }\r\n });\r\n return (\r\n <>\r\n {thisStateOpts?.formElements?.validation &&\r\n !formOpts?.validation?.disable ? (\r\n thisStateOpts.formElements!.validation!({\r\n children: (\r\n <React.Fragment key={path.toString()}>{children}</React.Fragment>\r\n ),\r\n status, // Now passes the new ValidationStatus type\r\n message: formOpts?.validation?.hideMessage\r\n ? ''\r\n : formOpts?.validation?.message || message || '',\r\n severity: primarySeverity,\r\n hasErrors: errorMessages.length > 0,\r\n hasWarnings: warningMessages.length > 0,\r\n allErrors: errors,\r\n path: path,\r\n getData: () => getShadowValue(stateKey!, path),\r\n plugins: pluginsApi,\r\n })\r\n ) : (\r\n <React.Fragment key={path.toString()}>{children}</React.Fragment>\r\n )}\r\n </>\r\n );\r\n}\r\nexport const MemoizedCogsItemWrapper = memo(\r\n ListItemWrapper,\r\n (prevProps, nextProps) => {\r\n // Re-render if any of these change:\r\n return (\r\n prevProps.itemPath.join('.') === nextProps.itemPath.join('.') &&\r\n prevProps.stateKey === nextProps.stateKey &&\r\n prevProps.itemComponentId === nextProps.itemComponentId &&\r\n prevProps.localIndex === nextProps.localIndex\r\n );\r\n }\r\n);\r\nexport function ListItemWrapper({\r\n stateKey,\r\n itemComponentId,\r\n itemPath,\r\n localIndex,\r\n arraySetter,\r\n rebuildStateShape,\r\n renderFn,\r\n}: {\r\n stateKey: string;\r\n itemComponentId: string;\r\n itemPath: string[];\r\n localIndex: number;\r\n arraySetter: any;\r\n\r\n rebuildStateShape: (options: {\r\n currentState: any;\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n }) => any;\r\n renderFn: (\r\n setter: any,\r\n index: number,\r\n\r\n arraySetter: any\r\n ) => React.ReactNode;\r\n}) {\r\n const [, forceUpdate] = useState({});\r\n const { ref: inViewRef, inView } = useInView();\r\n const elementRef = useRef<HTMLDivElement | null>(null);\r\n\r\n const imagesLoaded = useImageLoaded(elementRef);\r\n const hasReportedInitialHeight = useRef(false);\r\n const fullKey = [stateKey, ...itemPath].join('.');\r\n useRegisterComponent(stateKey, itemComponentId, forceUpdate);\r\n\r\n const setRefs = useCallback(\r\n (element: HTMLDivElement | null) => {\r\n elementRef.current = element;\r\n inViewRef(element); // This is the ref from useInView\r\n },\r\n [inViewRef]\r\n );\r\n\r\n useEffect(() => {\r\n const unsubscribe = subscribeToPath(fullKey, (e) => {\r\n forceUpdate({});\r\n });\r\n return () => unsubscribe();\r\n }, [fullKey]);\r\n useEffect(() => {\r\n if (!inView || !imagesLoaded || hasReportedInitialHeight.current) {\r\n return;\r\n }\r\n\r\n const element = elementRef.current;\r\n if (element && element.offsetHeight > 0) {\r\n hasReportedInitialHeight.current = true;\r\n const newHeight = element.offsetHeight;\r\n\r\n setShadowMetadata(stateKey, itemPath, {\r\n virtualizer: {\r\n itemHeight: newHeight,\r\n domRef: element,\r\n },\r\n });\r\n\r\n const arrayPath = itemPath.slice(0, -1);\r\n const arrayPathKey = [stateKey, ...arrayPath].join('.');\r\n notifyPathSubscribers(arrayPathKey, {\r\n type: 'ITEMHEIGHT',\r\n itemKey: itemPath.join('.'),\r\n\r\n ref: elementRef.current,\r\n });\r\n }\r\n }, [inView, imagesLoaded, stateKey, itemPath]);\r\n\r\n const itemValue = getShadowValue(stateKey, itemPath);\r\n\r\n if (itemValue === undefined) {\r\n return null;\r\n }\r\n\r\n const itemSetter = rebuildStateShape({\r\n currentState: itemValue,\r\n path: itemPath,\r\n componentId: itemComponentId,\r\n });\r\n const children = renderFn(itemSetter, localIndex, arraySetter);\r\n\r\n return <div ref={setRefs}>{children}</div>;\r\n}\r\n\r\nexport function FormElementWrapper({\r\n stateKey,\r\n path,\r\n rebuildStateShape,\r\n renderFn,\r\n formOpts,\r\n setState,\r\n}: {\r\n stateKey: string;\r\n path: string[];\r\n rebuildStateShape: (options: {\r\n path: string[];\r\n componentId: string;\r\n meta?: any;\r\n }) => any;\r\n renderFn: (params: FormElementParams<any>) => React.ReactNode;\r\n formOpts?: FormOptsType;\r\n setState: any;\r\n}) {\r\n const componentId = useRef(uuidv4()).current;\r\n\r\n const [, forceUpdate] = useState({});\r\n const formElementRef = useRef<any>(null);\r\n const stateKeyPathKey = [stateKey, ...path].join('.');\r\n useRegisterComponent(stateKey, componentId, forceUpdate);\r\n // Get the shadow node to access typeInfo and schema\r\n const shadowNode = getGlobalStore.getState().getShadowNode(stateKey, path);\r\n const typeInfo = shadowNode?._meta?.typeInfo;\r\n\r\n const globalStateValue = getShadowValue(stateKey, path);\r\n const [localValue, setLocalValue] = useState<any>(globalStateValue);\r\n const isCurrentlyDebouncing = useRef(false);\r\n const debounceTimeoutRef = useRef<NodeJS.Timeout | null>(null);\r\n\r\n useEffect(() => {\r\n if (\r\n !isCurrentlyDebouncing.current &&\r\n !isDeepEqual(globalStateValue, localValue)\r\n ) {\r\n setLocalValue(globalStateValue);\r\n }\r\n }, [globalStateValue]);\r\n\r\n useEffect(() => {\r\n const { getShadowMetadata, setShadowMetadata } = getGlobalStore.getState();\r\n\r\n // Initialize clientActivityState if needed\r\n const currentMeta = getShadowMetadata(stateKey, path) || {};\r\n if (!currentMeta.clientActivityState) {\r\n currentMeta.clientActivityState = { elements: new Map() };\r\n }\r\n\r\n // Detect element type from the ref\r\n const detectElementType = () => {\r\n const el = formElementRef.current;\r\n if (!el) return 'input';\r\n const tagName = el.tagName.toLowerCase();\r\n if (tagName === 'textarea') return 'textarea';\r\n if (tagName === 'select') return 'select';\r\n if (tagName === 'input') {\r\n const type = (el as HTMLInputElement).type;\r\n if (type === 'checkbox') return 'checkbox';\r\n if (type === 'radio') return 'radio';\r\n if (type === 'range') return 'range';\r\n if (type === 'file') return 'file';\r\n }\r\n return 'input';\r\n };\r\n\r\n // Add this element to the Map\r\n currentMeta.clientActivityState.elements.set(componentId, {\r\n domRef: formElementRef,\r\n elementType: detectElementType(),\r\n inputType: formElementRef.current?.type,\r\n mountedAt: Date.now(),\r\n });\r\n\r\n setShadowMetadata(stateKey, path, currentMeta);\r\n\r\n // Subscribe to path updates\r\n const unsubscribe = getGlobalStore\r\n .getState()\r\n .subscribeToPath(stateKeyPathKey, (newValue) => {\r\n if (!isCurrentlyDebouncing.current && localValue !== newValue) {\r\n forceUpdate({});\r\n }\r\n });\r\n\r\n // Cleanup\r\n return () => {\r\n unsubscribe();\r\n\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n isCurrentlyDebouncing.current = false;\r\n }\r\n\r\n // Remove element from Map\r\n const meta = getGlobalStore.getState().getShadowMetadata(stateKey, path);\r\n if (meta?.clientActivityState?.elements) {\r\n meta.clientActivityState.elements.delete(componentId);\r\n setShadowMetadata(stateKey, path, meta);\r\n }\r\n };\r\n }, []);\r\n\r\n const debouncedUpdate = useCallback(\r\n (newValue: any) => {\r\n // Type conversion logic (keep existing)\r\n if (typeInfo) {\r\n if (typeInfo.type === 'number' && typeof newValue === 'string') {\r\n newValue =\r\n newValue === ''\r\n ? typeInfo.nullable\r\n ? null\r\n : (typeInfo.default ?? 0)\r\n : Number(newValue);\r\n } else if (\r\n typeInfo.type === 'boolean' &&\r\n typeof newValue === 'string'\r\n ) {\r\n newValue = newValue === 'true' || newValue === '1';\r\n } else if (typeInfo.type === 'date' && typeof newValue === 'string') {\r\n newValue = new Date(newValue);\r\n }\r\n } else {\r\n const currentType = typeof globalStateValue;\r\n if (currentType === 'number' && typeof newValue === 'string') {\r\n newValue = newValue === '' ? 0 : Number(newValue);\r\n }\r\n }\r\n\r\n setLocalValue(newValue);\r\n\r\n // Update input activity details\r\n const { getShadowMetadata, setShadowMetadata } =\r\n getGlobalStore.getState();\r\n const meta = getShadowMetadata(stateKey, path);\r\n if (meta?.clientActivityState?.elements?.has(componentId)) {\r\n const element = meta.clientActivityState.elements.get(componentId);\r\n if (element && element.currentActivity?.type === 'focus') {\r\n element!.currentActivity.details = {\r\n ...element!.currentActivity.details,\r\n value: newValue,\r\n previousValue:\r\n element!.currentActivity.details?.value || globalStateValue,\r\n inputLength:\r\n typeof newValue === 'string' ? newValue.length : undefined,\r\n keystrokeCount:\r\n (element!.currentActivity.details?.keystrokeCount || 0) + 1,\r\n };\r\n setShadowMetadata(stateKey, path, meta);\r\n }\r\n }\r\n const element = meta?.clientActivityState?.elements?.get(componentId);\r\n\r\n // Notify plugins\r\n notifyFormUpdate({\r\n stateKey,\r\n activityType: 'input', // Changed from 'type'\r\n path,\r\n timestamp: Date.now(),\r\n details: {\r\n value: newValue,\r\n inputLength:\r\n typeof newValue === 'string' ? newValue.length : undefined,\r\n isComposing: false, // You'd need to track this from the actual input event\r\n isPasting: false, // You'd need to track this from paste events\r\n keystrokeCount:\r\n (element?.currentActivity?.details?.keystrokeCount || 0) + 1,\r\n },\r\n });\r\n // Validation (keep existing)\r\n const virtualOperation: UpdateTypeDetail = {\r\n stateKey,\r\n path,\r\n newValue: newValue,\r\n updateType: 'update',\r\n timeStamp: Date.now(),\r\n status: 'new',\r\n oldValue: globalStateValue,\r\n };\r\n runValidation(virtualOperation, 'onChange');\r\n\r\n // Debounce state update (keep existing)\r\n isCurrentlyDebouncing.current = true;\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n }\r\n\r\n const debounceTime = formOpts?.debounceTime ?? 200;\r\n debounceTimeoutRef.current = setTimeout(() => {\r\n isCurrentlyDebouncing.current = false;\r\n setState(newValue, path, {\r\n updateType: 'update',\r\n validationTrigger: 'onChange',\r\n });\r\n }, debounceTime);\r\n },\r\n [\r\n setState,\r\n path,\r\n formOpts?.debounceTime,\r\n typeInfo,\r\n globalStateValue,\r\n stateKey,\r\n componentId,\r\n ]\r\n );\r\n\r\n const handleFocus = useCallback(() => {\r\n const { getShadowMetadata, setShadowMetadata } = getGlobalStore.getState();\r\n\r\n // Update element's current activity\r\n const meta = getShadowMetadata(stateKey, path);\r\n if (meta?.clientActivityState?.elements?.has(componentId)) {\r\n const element = meta.clientActivityState.elements.get(componentId)!;\r\n element.currentActivity = {\r\n type: 'focus',\r\n startTime: Date.now(),\r\n details: {\r\n value: localValue,\r\n inputLength:\r\n typeof localValue === 'string' ? localValue.length : undefined,\r\n },\r\n };\r\n setShadowMetadata(stateKey, path, meta);\r\n }\r\n\r\n // Notify plugins\r\n notifyFormUpdate({\r\n stateKey,\r\n activityType: 'focus', // Changed from 'type'\r\n path,\r\n timestamp: Date.now(),\r\n details: {\r\n cursorPosition: formElementRef.current?.selectionStart,\r\n },\r\n });\r\n }, [stateKey, path, componentId, localValue]);\r\n const handleBlur = useCallback(() => {\r\n const { getShadowMetadata, setShadowMetadata } = getGlobalStore.getState();\r\n\r\n // Clear debounce if active\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n debounceTimeoutRef.current = null;\r\n isCurrentlyDebouncing.current = false;\r\n setState(localValue, path, {\r\n updateType: 'update',\r\n validationTrigger: 'onBlur',\r\n });\r\n }\r\n\r\n // Clear element's current activity\r\n const meta = getShadowMetadata(stateKey, path);\r\n if (meta?.clientActivityState?.elements?.has(componentId)) {\r\n const element = meta.clientActivityState.elements.get(componentId)!;\r\n element.currentActivity = undefined;\r\n setShadowMetadata(stateKey, path, meta);\r\n }\r\n const focusStartTime =\r\n meta?.clientActivityState?.elements?.get(componentId)?.currentActivity\r\n ?.startTime;\r\n\r\n // Notify plugins\r\n notifyFormUpdate({\r\n stateKey,\r\n activityType: 'blur', // Changed from 'type'\r\n path,\r\n timestamp: Date.now(),\r\n duration: focusStartTime ? Date.now() - focusStartTime : undefined,\r\n details: {\r\n duration: focusStartTime ? Date.now() - focusStartTime : 0,\r\n },\r\n });\r\n\r\n // Run validation if configured\r\n const validationOptions = getInitialOptions(stateKey)?.validation;\r\n if (validationOptions?.onBlur) {\r\n const virtualOperation: UpdateTypeDetail = {\r\n stateKey,\r\n path,\r\n newValue: localValue,\r\n updateType: 'update',\r\n timeStamp: Date.now(),\r\n status: 'new',\r\n oldValue: globalStateValue,\r\n };\r\n runValidation(virtualOperation, 'onBlur');\r\n }\r\n }, [localValue, setState, path, stateKey, componentId, globalStateValue]);\r\n\r\n const baseState = rebuildStateShape({\r\n path: path,\r\n componentId: componentId,\r\n meta: undefined,\r\n });\r\n\r\n const stateWithInputProps = new Proxy(baseState, {\r\n get(target, prop) {\r\n if (prop === '$inputProps') {\r\n return {\r\n value: localValue ?? '',\r\n onChange: (e: any) => {\r\n debouncedUpdate(e.target.value);\r\n },\r\n onFocus: handleFocus,\r\n onBlur: handleBlur,\r\n ref: formElementRef,\r\n };\r\n }\r\n\r\n return target[prop];\r\n },\r\n });\r\n\r\n const initialElement = renderFn(stateWithInputProps);\r\n\r\n return (\r\n <ValidationWrapper formOpts={formOpts} path={path} stateKey={stateKey}>\r\n {initialElement}\r\n </ValidationWrapper>\r\n );\r\n}\r\nexport function useRegisterComponent(\r\n stateKey: string,\r\n componentId: string,\r\n forceUpdate: (o: object) => void\r\n) {\r\n const fullComponentId = `${stateKey}////${componentId}`;\r\n\r\n useLayoutEffect(() => {\r\n registerComponent(stateKey, fullComponentId, {\r\n forceUpdate: () => forceUpdate({}),\r\n paths: new Set(),\r\n reactiveType: ['component'],\r\n });\r\n return () => {\r\n unregisterComponent(stateKey, fullComponentId);\r\n };\r\n }, [stateKey, fullComponentId]);\r\n}\r\n\r\nconst useImageLoaded = (ref: RefObject<HTMLElement>): boolean => {\r\n const [loaded, setLoaded] = useState(false);\r\n\r\n useLayoutEffect(() => {\r\n if (!ref.current) {\r\n setLoaded(true);\r\n return;\r\n }\r\n\r\n const images = Array.from(ref.current.querySelectorAll('img'));\r\n\r\n // If there are no images, we are \"loaded\" immediately.\r\n if (images.length === 0) {\r\n setLoaded(true);\r\n return;\r\n }\r\n\r\n let loadedCount = 0;\r\n const handleImageLoad = () => {\r\n loadedCount++;\r\n if (loadedCount === images.length) {\r\n setLoaded(true);\r\n }\r\n };\r\n\r\n images.forEach((image) => {\r\n if (image.complete) {\r\n handleImageLoad();\r\n } else {\r\n image.addEventListener('load', handleImageLoad);\r\n image.addEventListener('error', handleImageLoad);\r\n }\r\n });\r\n\r\n return () => {\r\n images.forEach((image) => {\r\n image.removeEventListener('load', handleImageLoad);\r\n image.removeEventListener('error', handleImageLoad);\r\n });\r\n };\r\n }, [ref.current]);\r\n\r\n return loaded;\r\n};\r\n// Components.tsx\r\n\r\nexport function IsolatedComponentWrapper({\r\n stateKey,\r\n path, // The path of the parent node (e.g. ['form'])\r\n dependencies, // NEW: Optional array of Proxy objects or path arrays\r\n rebuildStateShape,\r\n renderFn,\r\n}: {\r\n stateKey: string;\r\n path: string[];\r\n dependencies?: any[]; // The explicit list of dependencies\r\n rebuildStateShape: (options: any) => any;\r\n renderFn: (state: any) => React.ReactNode;\r\n}) {\r\n const [componentId] = useState(() => uuidv4());\r\n const [, forceUpdate] = useState({});\r\n\r\n useRegisterComponent(stateKey, componentId, forceUpdate);\r\n\r\n const pathsToSubscribe = useMemo(() => {\r\n if (dependencies && dependencies.length > 0) {\r\n return dependencies.map((dep) => {\r\n return [stateKey, ...dep.$_path].join('.');\r\n });\r\n }\r\n\r\n return [[stateKey, ...path].join('.')];\r\n }, [stateKey, path, dependencies]);\r\n\r\n // 2. Subscribe to ALL calculated paths\r\n useEffect(() => {\r\n const store = getGlobalStore.getState();\r\n\r\n // Create an array of unsubscribe functions\r\n const unsubs = pathsToSubscribe.map((fullPathKey) => {\r\n return store.subscribeToPath(fullPathKey, () => {\r\n forceUpdate({});\r\n });\r\n });\r\n\r\n return () => {\r\n unsubs.forEach((unsub) => unsub());\r\n };\r\n }, [pathsToSubscribe]);\r\n\r\n const baseState = rebuildStateShape({\r\n path: path,\r\n componentId: componentId,\r\n meta: undefined,\r\n });\r\n\r\n return <>{renderFn(baseState)}</>;\r\n}\r\n// 1. Define the MINIMAL props needed.\r\ntype PluginWrapperProps = {\r\n children: React.ReactNode;\r\n stateKey: string;\r\n path: string[];\r\n pluginName: string;\r\n wrapperDepth: number;\r\n};\r\n\r\nconst PluginWrapper = memo(function PluginWrapper({\r\n children,\r\n stateKey,\r\n path,\r\n pluginName,\r\n wrapperDepth,\r\n}: PluginWrapperProps) {\r\n const [, forceUpdate] = useState({});\r\n\r\n useEffect(() => {\r\n const fullPathKey = [stateKey, ...path].join('.');\r\n const unsubscribe = getGlobalStore\r\n .getState()\r\n .subscribeToPath(fullPathKey, () => {\r\n forceUpdate({});\r\n });\r\n return unsubscribe;\r\n }, [stateKey, path]);\r\n\r\n const plugin = pluginStore\r\n .getState()\r\n .registeredPlugins.find((p) => p.name === pluginName);\r\n\r\n const stateHandler: StateObject<any> | undefined = pluginStore\r\n .getState()\r\n .stateHandlers.get(stateKey);\r\n\r\n const typeInfo = getGlobalStore.getState().getShadowNode(stateKey, path)\r\n ?._meta?.typeInfo;\r\n\r\n const options = pluginStore\r\n .getState()\r\n .pluginOptions.get(stateKey)\r\n ?.get(pluginName);\r\n\r\n const hookData = pluginStore.getState().getHookResult(stateKey, pluginName);\r\n\r\n if (!plugin?.formWrapper || !stateHandler) {\r\n return <>{children}</>;\r\n }\r\n\r\n const deconstructed = toDeconstructedMethods(stateHandler);\r\n const scopedMetadataContext = createScopedMetadataContext(\r\n stateKey,\r\n plugin.name,\r\n path\r\n );\r\n return plugin.formWrapper({\r\n element: children,\r\n path,\r\n stateKey,\r\n pluginName: plugin.name,\r\n ...deconstructed,\r\n\r\n ...scopedMetadataContext,\r\n options,\r\n hookData,\r\n fieldType: typeInfo?.type,\r\n wrapperDepth,\r\n });\r\n});\r\n"],"names":["getInitialOptions","getShadowMetadata","setShadowMetadata","getShadowValue","registerComponent","unregisterComponent","notifyPathSubscribers","subscribeToPath","getGlobalStore","stateHandlers","notifyFormUpdate","pluginStore","ValidationWrapper","formOpts","path","stateKey","children","thisStateOpts","validationState","status","errors","err","errorMessages","warningMessages","message","primarySeverity","registeredPlugins","pluginsApi","plugin","pluginName","hookData","scopedMetadata","createScopedMetadataContext","jsx","Fragment","React","MemoizedCogsItemWrapper","memo","ListItemWrapper","prevProps","nextProps","itemComponentId","itemPath","localIndex","arraySetter","rebuildStateShape","renderFn","forceUpdate","useState","inViewRef","inView","useInView","elementRef","useRef","imagesLoaded","useImageLoaded","hasReportedInitialHeight","fullKey","useRegisterComponent","setRefs","useCallback","element","useEffect","unsubscribe","e","newHeight","arrayPath","arrayPathKey","itemValue","itemSetter","FormElementWrapper","setState","componentId","uuidv4","formElementRef","stateKeyPathKey","typeInfo","globalStateValue","localValue","setLocalValue","isCurrentlyDebouncing","debounceTimeoutRef","isDeepEqual","currentMeta","detectElementType","el","tagName","type","newValue","meta","debouncedUpdate","runValidation","debounceTime","handleFocus","handleBlur","focusStartTime","baseState","stateWithInputProps","target","prop","initialElement","fullComponentId","useLayoutEffect","ref","loaded","setLoaded","images","loadedCount","handleImageLoad","image","IsolatedComponentWrapper","dependencies","pathsToSubscribe","useMemo","dep","store","unsubs","fullPathKey","unsub","wrapperDepth","p","stateHandler","options","deconstructed","toDeconstructedMethods","scopedMetadataContext"],"mappings":";;;;;;;;;AA4BA,MAAM;AAAA,EACJ,mBAAAA;AAAA,EAEA,mBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,gBAAAC;AAAA,EAEA,mBAAAC;AAAA,EACA,qBAAAC;AAAA,EAEA,uBAAAC;AAAA,EACA,iBAAAC;AACF,IAAIC,EAAe,SAAA,GACb,EAAE,eAAAC,IAAe,kBAAAC,MAAqBC,EAAY,SAAA;AASjD,SAASC,GAAkB;AAAA,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AAM;AACd,UAAMuD,IAAc,CAACtG,GAAU,GAAGD,CAAI,EAAE,KAAK,GAAG;AAMhD,WALoBN,EACjB,SAAA,EACA,gBAAgB6G,GAAa,MAAM;AAClC,MAAAtE,EAAY,CAAA,CAAE;AAAA,IAChB,CAAC;AAAA,EAEL,GAAG,CAAChC,GAAUD,CAAI,CAAC;AAEnB,QAAMc,IAASjB,EACZ,SAAA,EACA,kBAAkB,KAAK,CAAC6G,MAAMA,EAAE,SAAS3F,CAAU,GAEhD4F,IAA6C9G,EAChD,SAAA,EACA,cAAc,IAAII,CAAQ,GAEvB6D,IAAWpE,EAAe,SAAA,EAAW,cAAcO,GAAUD,CAAI,GACnE,OAAO,UAEL4G,IAAU/G,EACb,WACA,cAAc,IAAII,CAAQ,GACzB,IAAIc,CAAU,GAEZC,IAAWnB,EAAY,SAAA,EAAW,cAAcI,GAAUc,CAAU;AAE1E,MAAI,CAACD,GAAQ,eAAe,CAAC6F;AAC3B,kCAAU,UAAAzG,GAAS;AAGrB,QAAM2G,IAAgBC,EAAuBH,CAAY,GACnDI,IAAwB7F;AAAA,IAC5BjB;AAAA,IACAa,EAAO;AAAA,IACPd;AAAA,EAAA;AAEF,SAAOc,EAAO,YAAY;AAAA,IACxB,SAASZ;AAAA,IACT,MAAAF;AAAA,IACA,UAAAC;AAAA,IACA,YAAYa,EAAO;AAAA,IACnB,GAAG+F;AAAA,IAEH,GAAGE;AAAA,IACH,SAAAH;AAAA,IACA,UAAA5F;AAAA,IACA,WAAW8C,GAAU;AAAA,IACrB,cAAA2C;AAAA,EAAA,CACD;AACH,CAAC;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-state",
|
|
3
|
-
"version": "0.5.475-canary.
|
|
3
|
+
"version": "0.5.475-canary.8",
|
|
4
4
|
"description": "React state management library with form controls and server sync",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@trpc/next": "^10.0.0 || ^11.0.0",
|
|
51
|
-
"@types/react": "^18.0.0",
|
|
51
|
+
"@types/react": "^18.0.0 || ^19.0.0",
|
|
52
52
|
"zod": "^3.25.0 || ^4.0.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
package/src/CogsState.tsx
CHANGED
|
@@ -230,9 +230,18 @@ export type EndType<
|
|
|
230
230
|
$update: UpdateType<T>;
|
|
231
231
|
$_path: string[];
|
|
232
232
|
$_stateKey: string;
|
|
233
|
-
$isolate:
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
$isolate: {
|
|
234
|
+
// Overload 1: Just the render function (Default behavior)
|
|
235
|
+
(
|
|
236
|
+
renderFn: (state: StateObject<T, TPlugins>) => React.ReactNode
|
|
237
|
+
): JSX.Element;
|
|
238
|
+
|
|
239
|
+
// Overload 2: Dependencies array + render function (Optimized behavior)
|
|
240
|
+
(
|
|
241
|
+
dependencies: any[],
|
|
242
|
+
renderFn: (state: StateObject<T, TPlugins>) => React.ReactNode
|
|
243
|
+
): JSX.Element;
|
|
244
|
+
};
|
|
236
245
|
$formElement: (
|
|
237
246
|
control: FormControl<T>,
|
|
238
247
|
opts?: PerPathFormOptsType<T, TPlugins>
|
|
@@ -314,6 +323,7 @@ export type StateObject<
|
|
|
314
323
|
};
|
|
315
324
|
|
|
316
325
|
export type CogsUpdate<T extends unknown> = UpdateType<T>;
|
|
326
|
+
|
|
317
327
|
type EffectiveSetStateArg<
|
|
318
328
|
T,
|
|
319
329
|
UpdateType extends 'update' | 'insert' | 'cut',
|
|
@@ -349,7 +359,6 @@ export type UpdateTypeDetail = {
|
|
|
349
359
|
oldValue: any;
|
|
350
360
|
newValue: any;
|
|
351
361
|
userId?: number;
|
|
352
|
-
|
|
353
362
|
itemId?: string;
|
|
354
363
|
insertAfterId?: string;
|
|
355
364
|
metaData?: Record<string, any>;
|
|
@@ -511,14 +520,12 @@ const {
|
|
|
511
520
|
addPathComponent,
|
|
512
521
|
clearSelectedIndexesForState,
|
|
513
522
|
addStateLog,
|
|
514
|
-
setSyncInfo,
|
|
515
523
|
clearSelectedIndex,
|
|
516
524
|
getSyncInfo,
|
|
517
525
|
notifyPathSubscribers,
|
|
518
526
|
getPluginMetaDataMap,
|
|
519
527
|
setPluginMetaData,
|
|
520
528
|
removePluginMetaData,
|
|
521
|
-
// Note: The old functions are no longer imported under their original names
|
|
522
529
|
} = getGlobalStore.getState();
|
|
523
530
|
|
|
524
531
|
const { notifyUpdate } = pluginStore.getState();
|
|
@@ -1069,9 +1076,7 @@ let isFlushScheduled = false;
|
|
|
1069
1076
|
function scheduleFlush() {
|
|
1070
1077
|
if (!isFlushScheduled) {
|
|
1071
1078
|
isFlushScheduled = true;
|
|
1072
|
-
console.log('Scheduling flush');
|
|
1073
1079
|
queueMicrotask(() => {
|
|
1074
|
-
console.log('Actually flushing');
|
|
1075
1080
|
flushQueue();
|
|
1076
1081
|
});
|
|
1077
1082
|
}
|
|
@@ -2764,7 +2769,7 @@ function createProxyHandler<
|
|
|
2764
2769
|
if (prop === '$cut') {
|
|
2765
2770
|
return (index?: number, options?: { waitForSync?: boolean }) => {
|
|
2766
2771
|
const shadowMeta = getShadowMetadata(stateKey, path);
|
|
2767
|
-
|
|
2772
|
+
|
|
2768
2773
|
if (!shadowMeta?.arrayKeys || shadowMeta.arrayKeys.length === 0)
|
|
2769
2774
|
return;
|
|
2770
2775
|
|
|
@@ -2775,12 +2780,8 @@ function createProxyHandler<
|
|
|
2775
2780
|
? index
|
|
2776
2781
|
: shadowMeta.arrayKeys.length - 1;
|
|
2777
2782
|
|
|
2778
|
-
console.log('indexToCut ->>>>>>>>>>>>>>>>', indexToCut);
|
|
2779
|
-
|
|
2780
2783
|
const idToCut = shadowMeta.arrayKeys[indexToCut];
|
|
2781
2784
|
if (!idToCut) return;
|
|
2782
|
-
console.log('idToCut ->>>>>>>>>>>>>>>>', idToCut);
|
|
2783
|
-
|
|
2784
2785
|
effectiveSetState(null, [...path, idToCut], {
|
|
2785
2786
|
updateType: 'cut',
|
|
2786
2787
|
});
|
|
@@ -3011,7 +3012,6 @@ function createProxyHandler<
|
|
|
3011
3012
|
getPluginMetaDataMap(stateKey, path)?.get(pluginName);
|
|
3012
3013
|
}
|
|
3013
3014
|
if (prop === '$addPluginMetaData') {
|
|
3014
|
-
console.log('$addPluginMetaDat');
|
|
3015
3015
|
return (pluginName: string, data: Record<string, any>) =>
|
|
3016
3016
|
setPluginMetaData(stateKey, path, pluginName, data);
|
|
3017
3017
|
}
|
|
@@ -3078,12 +3078,6 @@ function createProxyHandler<
|
|
|
3078
3078
|
},
|
|
3079
3079
|
metaData?: Record<string, any>
|
|
3080
3080
|
) => {
|
|
3081
|
-
console.log(
|
|
3082
|
-
'getGlobalStore',
|
|
3083
|
-
getGlobalStore
|
|
3084
|
-
.getState()
|
|
3085
|
-
.getShadowMetadata(stateKey, operation.path)
|
|
3086
|
-
);
|
|
3087
3081
|
let index: number | undefined;
|
|
3088
3082
|
if (
|
|
3089
3083
|
operation.insertAfterId &&
|
|
@@ -3269,11 +3263,29 @@ function createProxyHandler<
|
|
|
3269
3263
|
};
|
|
3270
3264
|
}
|
|
3271
3265
|
if (prop === '$isolate') {
|
|
3272
|
-
|
|
3266
|
+
// We accept (renderFn) OR (deps, renderFn)
|
|
3267
|
+
return (
|
|
3268
|
+
arg1: any[] | ((state: any) => React.ReactNode),
|
|
3269
|
+
arg2?: (state: any) => React.ReactNode
|
|
3270
|
+
) => {
|
|
3271
|
+
// Check if the first argument is the dependency array
|
|
3272
|
+
const hasDependencies = Array.isArray(arg1);
|
|
3273
|
+
|
|
3274
|
+
// Normalize arguments
|
|
3275
|
+
const dependencies = hasDependencies ? arg1 : undefined;
|
|
3276
|
+
const renderFn = hasDependencies ? arg2 : arg1;
|
|
3277
|
+
|
|
3278
|
+
if (!renderFn || typeof renderFn !== 'function') {
|
|
3279
|
+
throw new Error(
|
|
3280
|
+
'CogsState: $isolate requires a render function.'
|
|
3281
|
+
);
|
|
3282
|
+
}
|
|
3283
|
+
|
|
3273
3284
|
return (
|
|
3274
3285
|
<IsolatedComponentWrapper
|
|
3275
3286
|
stateKey={stateKey}
|
|
3276
|
-
path={path}
|
|
3287
|
+
path={path} // The path of the node calling $isolate (e.g. "form")
|
|
3288
|
+
dependencies={dependencies} // Pass the specific parts to watch
|
|
3277
3289
|
rebuildStateShape={rebuildStateShape}
|
|
3278
3290
|
renderFn={renderFn}
|
|
3279
3291
|
/>
|
package/src/Components.tsx
CHANGED
|
@@ -633,36 +633,49 @@ const useImageLoaded = (ref: RefObject<HTMLElement>): boolean => {
|
|
|
633
633
|
};
|
|
634
634
|
// Components.tsx
|
|
635
635
|
|
|
636
|
-
// Generic isolated component wrapper
|
|
637
636
|
export function IsolatedComponentWrapper({
|
|
638
637
|
stateKey,
|
|
639
|
-
path,
|
|
638
|
+
path, // The path of the parent node (e.g. ['form'])
|
|
639
|
+
dependencies, // NEW: Optional array of Proxy objects or path arrays
|
|
640
640
|
rebuildStateShape,
|
|
641
641
|
renderFn,
|
|
642
642
|
}: {
|
|
643
643
|
stateKey: string;
|
|
644
644
|
path: string[];
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
componentId: string;
|
|
648
|
-
meta?: any;
|
|
649
|
-
}) => any;
|
|
645
|
+
dependencies?: any[]; // The explicit list of dependencies
|
|
646
|
+
rebuildStateShape: (options: any) => any;
|
|
650
647
|
renderFn: (state: any) => React.ReactNode;
|
|
651
648
|
}) {
|
|
652
649
|
const [componentId] = useState(() => uuidv4());
|
|
653
650
|
const [, forceUpdate] = useState({});
|
|
654
651
|
|
|
655
|
-
const stateKeyPathKey = [stateKey, ...path].join('.');
|
|
656
652
|
useRegisterComponent(stateKey, componentId, forceUpdate);
|
|
657
653
|
|
|
654
|
+
const pathsToSubscribe = useMemo(() => {
|
|
655
|
+
if (dependencies && dependencies.length > 0) {
|
|
656
|
+
return dependencies.map((dep) => {
|
|
657
|
+
return [stateKey, ...dep.$_path].join('.');
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return [[stateKey, ...path].join('.')];
|
|
662
|
+
}, [stateKey, path, dependencies]);
|
|
663
|
+
|
|
664
|
+
// 2. Subscribe to ALL calculated paths
|
|
658
665
|
useEffect(() => {
|
|
659
|
-
const
|
|
660
|
-
|
|
661
|
-
|
|
666
|
+
const store = getGlobalStore.getState();
|
|
667
|
+
|
|
668
|
+
// Create an array of unsubscribe functions
|
|
669
|
+
const unsubs = pathsToSubscribe.map((fullPathKey) => {
|
|
670
|
+
return store.subscribeToPath(fullPathKey, () => {
|
|
662
671
|
forceUpdate({});
|
|
663
672
|
});
|
|
664
|
-
|
|
665
|
-
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
return () => {
|
|
676
|
+
unsubs.forEach((unsub) => unsub());
|
|
677
|
+
};
|
|
678
|
+
}, [pathsToSubscribe]);
|
|
666
679
|
|
|
667
680
|
const baseState = rebuildStateShape({
|
|
668
681
|
path: path,
|
|
@@ -672,7 +685,6 @@ export function IsolatedComponentWrapper({
|
|
|
672
685
|
|
|
673
686
|
return <>{renderFn(baseState)}</>;
|
|
674
687
|
}
|
|
675
|
-
|
|
676
688
|
// 1. Define the MINIMAL props needed.
|
|
677
689
|
type PluginWrapperProps = {
|
|
678
690
|
children: React.ReactNode;
|