cogsbox-state 0.5.471 → 0.5.473

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.
Files changed (46) hide show
  1. package/README.md +2 -5
  2. package/dist/CogsState.d.ts +105 -79
  3. package/dist/CogsState.d.ts.map +1 -1
  4. package/dist/CogsState.jsx +1082 -987
  5. package/dist/CogsState.jsx.map +1 -1
  6. package/dist/Components.d.ts.map +1 -1
  7. package/dist/Components.jsx +293 -243
  8. package/dist/Components.jsx.map +1 -1
  9. package/dist/PluginRunner.d.ts +10 -0
  10. package/dist/PluginRunner.d.ts.map +1 -0
  11. package/dist/PluginRunner.jsx +128 -0
  12. package/dist/PluginRunner.jsx.map +1 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +33 -26
  16. package/dist/index.js.map +1 -1
  17. package/dist/pluginStore.d.ts +43 -0
  18. package/dist/pluginStore.d.ts.map +1 -0
  19. package/dist/pluginStore.js +52 -0
  20. package/dist/pluginStore.js.map +1 -0
  21. package/dist/plugins.d.ts +1326 -0
  22. package/dist/plugins.d.ts.map +1 -0
  23. package/dist/plugins.js +76 -0
  24. package/dist/plugins.js.map +1 -0
  25. package/dist/store.d.ts +69 -26
  26. package/dist/store.d.ts.map +1 -1
  27. package/dist/store.js +436 -152
  28. package/dist/store.js.map +1 -1
  29. package/dist/utility.d.ts +1 -1
  30. package/dist/utility.d.ts.map +1 -1
  31. package/dist/utility.js +12 -12
  32. package/dist/utility.js.map +1 -1
  33. package/dist/validation.d.ts +7 -0
  34. package/dist/validation.d.ts.map +1 -0
  35. package/dist/validation.js +39 -0
  36. package/dist/validation.js.map +1 -0
  37. package/package.json +18 -13
  38. package/src/CogsState.tsx +719 -458
  39. package/src/Components.tsx +304 -180
  40. package/src/PluginRunner.tsx +208 -0
  41. package/src/index.ts +2 -0
  42. package/src/pluginStore.ts +159 -0
  43. package/src/plugins.ts +548 -0
  44. package/src/store.ts +881 -189
  45. package/src/utility.ts +31 -31
  46. package/src/validation.ts +84 -0
@@ -1 +1 @@
1
- {"version":3,"file":"Components.jsx","sources":["../src/Components.tsx"],"sourcesContent":["import { FormElementParams, type FormOptsType } from './CogsState';\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} from 'react';\r\nimport {\r\n formRefStore,\r\n getGlobalStore,\r\n ValidationError,\r\n ValidationSeverity,\r\n} from './store';\r\nimport { useInView } from 'react-intersection-observer';\r\nimport { v4 as uuidv4 } from 'uuid';\r\nimport { isDeepEqual } from './utility';\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\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 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 })\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] = useState(() => uuidv4());\r\n const [, forceUpdate] = useState({});\r\n\r\n const stateKeyPathKey = [stateKey, ...path].join('.');\r\n useRegisterComponent(stateKey, componentId, forceUpdate);\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 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 return () => {\r\n unsubscribe();\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n isCurrentlyDebouncing.current = false;\r\n }\r\n };\r\n }, []);\r\n\r\n const debouncedUpdate = useCallback(\r\n (newValue: any) => {\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 setLocalValue(newValue);\r\n isCurrentlyDebouncing.current = true;\r\n\r\n if (debounceTimeoutRef.current) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n }\r\n\r\n const debounceTime = formOpts?.debounceTime ?? 200;\r\n\r\n debounceTimeoutRef.current = setTimeout(() => {\r\n isCurrentlyDebouncing.current = false;\r\n setState(newValue, path, { updateType: 'update' });\r\n\r\n // NEW: Check if validation is enabled via features\r\n const rootMeta = getGlobalStore\r\n .getState()\r\n .getShadowMetadata(stateKey, []);\r\n if (!rootMeta?.features?.validationEnabled) return;\r\n\r\n const validationOptions = getInitialOptions(stateKey)?.validation;\r\n const zodSchema =\r\n validationOptions?.zodSchemaV4 || validationOptions?.zodSchemaV3;\r\n\r\n if (zodSchema) {\r\n const fullState = getShadowValue(stateKey, []);\r\n const result = zodSchema.safeParse(fullState);\r\n const currentMeta = getShadowMetadata(stateKey, path) || {};\r\n\r\n if (!result.success) {\r\n const errors =\r\n 'issues' in result.error\r\n ? result.error.issues\r\n : (result.error as any).errors;\r\n\r\n const pathErrors = errors.filter(\r\n (error: any) =>\r\n JSON.stringify(error.path) === JSON.stringify(path)\r\n );\r\n\r\n if (pathErrors.length > 0) {\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'INVALID',\r\n errors: [\r\n {\r\n source: 'client',\r\n message: pathErrors[0]?.message,\r\n severity: 'warning', // Gentle error during typing\r\n },\r\n ],\r\n lastValidated: Date.now(),\r\n validatedValue: newValue,\r\n },\r\n });\r\n } else {\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALID',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: newValue,\r\n },\r\n });\r\n }\r\n } else {\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALID',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: newValue,\r\n },\r\n });\r\n }\r\n }\r\n }, debounceTime);\r\n forceUpdate({});\r\n },\r\n [setState, path, formOpts?.debounceTime, stateKey]\r\n );\r\n\r\n const handleBlur = useCallback(async () => {\r\n console.log('handleBlur triggered');\r\n\r\n // Commit any pending changes\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, { updateType: 'update' });\r\n }\r\n const rootMeta = getShadowMetadata(stateKey, []);\r\n if (!rootMeta?.features?.validationEnabled) return;\r\n const { getInitialOptions } = getGlobalStore.getState();\r\n const validationOptions = getInitialOptions(stateKey)?.validation;\r\n const zodSchema =\r\n validationOptions?.zodSchemaV4 || validationOptions?.zodSchemaV3;\r\n\r\n if (!zodSchema) return;\r\n\r\n // Get the full path including stateKey\r\n\r\n // Update validation state to \"validating\"\r\n const currentMeta = getShadowMetadata(stateKey, path);\r\n\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALIDATING',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: localValue,\r\n },\r\n });\r\n\r\n // Validate full state\r\n const fullState = getShadowValue(stateKey, []);\r\n const result = zodSchema.safeParse(fullState);\r\n\r\n if (!result.success) {\r\n const errors =\r\n 'issues' in result.error\r\n ? result.error.issues\r\n : (result.error as any).errors;\r\n\r\n // Find errors for this specific path\r\n const pathErrors = errors.filter((error: any) => {\r\n // For array paths, we need to translate indices to ULIDs\r\n if (path.some((p) => p.startsWith('id:'))) {\r\n // This is an array item path like [\"id:xyz\", \"name\"]\r\n const parentPath = path[0]!.startsWith('id:')\r\n ? []\r\n : path.slice(0, -1);\r\n\r\n const arrayMeta = getGlobalStore\r\n .getState()\r\n .getShadowMetadata(stateKey, parentPath);\r\n\r\n if (arrayMeta?.arrayKeys) {\r\n const itemKey = [stateKey, ...path.slice(0, -1)].join('.');\r\n const itemIndex = arrayMeta.arrayKeys.indexOf(itemKey);\r\n\r\n // Compare with Zod path\r\n const zodPath = [...parentPath, itemIndex, ...path.slice(-1)];\r\n const match =\r\n JSON.stringify(error.path) === JSON.stringify(zodPath);\r\n\r\n return match;\r\n }\r\n }\r\n\r\n const directMatch = JSON.stringify(error.path) === JSON.stringify(path);\r\n\r\n return directMatch;\r\n });\r\n\r\n // Update shadow metadata with validation result\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'INVALID',\r\n errors: pathErrors.map((err: any) => ({\r\n source: 'client' as const,\r\n message: err.message,\r\n severity: 'error' as const, // Hard error on blur\r\n })),\r\n lastValidated: Date.now(),\r\n validatedValue: localValue,\r\n },\r\n });\r\n } else {\r\n // Validation passed\r\n setShadowMetadata(stateKey, path, {\r\n ...currentMeta,\r\n validation: {\r\n status: 'VALID',\r\n errors: [],\r\n lastValidated: Date.now(),\r\n validatedValue: localValue,\r\n },\r\n });\r\n }\r\n forceUpdate({});\r\n }, [stateKey, path, localValue, setState]);\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 // 5. Wire the new onBlur handler to the input props.\r\n onBlur: handleBlur,\r\n ref: formRefStore\r\n .getState()\r\n .getFormRef(stateKey + '.' + path.join('.')),\r\n };\r\n }\r\n\r\n return target[prop];\r\n },\r\n });\r\n\r\n return (\r\n <ValidationWrapper formOpts={formOpts} path={path} stateKey={stateKey}>\r\n {renderFn(stateWithInputProps)}\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 // Call the safe, centralized function to register\r\n registerComponent(stateKey, fullComponentId, {\r\n forceUpdate: () => forceUpdate({}),\r\n paths: new Set(),\r\n reactiveType: ['component'],\r\n });\r\n\r\n // The cleanup now calls the safe, centralized unregister function\r\n return () => {\r\n unregisterComponent(stateKey, fullComponentId);\r\n };\r\n }, [stateKey, fullComponentId]); // Dependencies are stable and correct\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"],"names":["getInitialOptions","getShadowMetadata","setShadowMetadata","getShadowValue","registerComponent","unregisterComponent","notifyPathSubscribers","subscribeToPath","getGlobalStore","ValidationWrapper","formOpts","path","stateKey","children","thisStateOpts","validationState","status","errors","err","errorMessages","warningMessages","message","primarySeverity","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","stateKeyPathKey","globalStateValue","localValue","setLocalValue","isCurrentlyDebouncing","debounceTimeoutRef","isDeepEqual","newValue","debouncedUpdate","debounceTime","validationOptions","zodSchema","fullState","result","currentMeta","pathErrors","error","handleBlur","p","parentPath","arrayMeta","itemKey","itemIndex","zodPath","baseState","stateWithInputProps","target","prop","formRefStore","fullComponentId","useLayoutEffect","ref","loaded","setLoaded","images","loadedCount","handleImageLoad","image","IsolatedComponentWrapper"],"mappings":";;;;;;AAmBA,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;AAQZ,SAASC,GAAkB;AAAA,EAChC,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AACF,GAA2B;AACzB,QAAM,EAAE,mBAAAb,GAAmB,mBAAAC,GAAmB,gBAAAE,EAAAA,IAC5CK,EAAe,SAAA,GACXM,IAAgBd,EAAkBY,CAAS,GAG3CG,IADad,EAAkBW,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,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GAAE;AAChC;"}
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 { createMetadataContext, toDeconstructedMethods } 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 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 })\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 // 2. Memoize the list of active form wrappers to avoid re-calculating on every render.\r\n const activeFormWrappers = useMemo(() => {\r\n return (\r\n pluginStore\r\n .getState()\r\n .getPluginConfigsForState(stateKey)\r\n // We only care about plugins that have defined a formWrapper\r\n .filter((config) => typeof config.plugin.formWrapper === 'function')\r\n );\r\n }, [stateKey]);\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\r\n // Notify plugins\r\n notifyFormUpdate({\r\n stateKey,\r\n type: 'input',\r\n path,\r\n value: newValue,\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 type: 'focus',\r\n path,\r\n value: localValue,\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\r\n // Notify plugins\r\n notifyFormUpdate({\r\n stateKey,\r\n type: 'blur',\r\n path,\r\n value: localValue,\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 const wrappedElement = activeFormWrappers.reduceRight(\r\n (currentElement, config, index) => (\r\n <PluginWrapper\r\n stateKey={stateKey}\r\n path={path}\r\n pluginName={config.plugin.name}\r\n wrapperDepth={activeFormWrappers.length - 1 - index}\r\n >\r\n {currentElement}\r\n </PluginWrapper>\r\n ),\r\n initialElement\r\n );\r\n\r\n return (\r\n <ValidationWrapper formOpts={formOpts} path={path} stateKey={stateKey}>\r\n {wrappedElement}\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 // Call the safe, centralized function to register\r\n registerComponent(stateKey, fullComponentId, {\r\n forceUpdate: () => forceUpdate({}),\r\n paths: new Set(),\r\n reactiveType: ['component'],\r\n });\r\n\r\n // The cleanup now calls the safe, centralized unregister function\r\n return () => {\r\n unregisterComponent(stateKey, fullComponentId);\r\n };\r\n }, [stateKey, fullComponentId]); // Dependencies are stable and correct\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 metadataContext = createMetadataContext(stateKey, plugin.name);\r\n const deconstructed = toDeconstructedMethods(stateHandler);\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 ...metadataContext,\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","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","activeFormWrappers","useMemo","config","isDeepEqual","currentMeta","detectElementType","el","tagName","type","newValue","meta","debouncedUpdate","runValidation","debounceTime","handleFocus","handleBlur","baseState","stateWithInputProps","target","prop","initialElement","wrappedElement","currentElement","index","PluginWrapper","fullComponentId","useLayoutEffect","ref","loaded","setLoaded","images","loadedCount","handleImageLoad","image","IsolatedComponentWrapper","pluginName","wrapperDepth","fullPathKey","plugin","p","stateHandler","options","hookData","metadataContext","createMetadataContext","deconstructed","toDeconstructedMethods"],"mappings":";;;;;;;;;AAwBA,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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BsD,IAAW7D,EAAe,SAAA,EAAW,cAAcO,GAAUD,CAAI,GACnE,OAAO,UAELsG,IAAUzG,EACb,WACA,cAAc,IAAII,CAAQ,GACzB,IAAI+F,CAAU,GAEZO,IAAW1G,EAAY,SAAA,EAAW,cAAcI,GAAU+F,CAAU;AAE1E,MAAI,CAACG,GAAQ,eAAe,CAACE;AAC3B,kCAAU,UAAAnG,GAAS;AAGrB,QAAMsG,IAAkBC,EAAsBxG,GAAUkG,EAAO,IAAI,GAC7DO,IAAgBC,EAAuBN,CAAY;AAEzD,SAAOF,EAAO,YAAY;AAAA,IACxB,SAASjG;AAAA,IACT,MAAAF;AAAA,IACA,UAAAC;AAAA,IACA,YAAYkG,EAAO;AAAA,IACnB,GAAGO;AAAA,IACH,GAAGF;AAAA,IACH,SAAAF;AAAA,IACA,UAAAC;AAAA,IACA,WAAWhD,GAAU;AAAA,IACrB,cAAA0C;AAAA,EAAA,CACD;AACH,CAAC;"}
@@ -0,0 +1,10 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * The main orchestrator component. It reads from the central pluginStore
5
+ * and renders a `PluginInstance` controller for each active plugin.
6
+ */
7
+ export declare function PluginRunner({ children }: {
8
+ children: React.ReactNode;
9
+ }): import("react/jsx-runtime").JSX.Element;
10
+ //# sourceMappingURL=PluginRunner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginRunner.d.ts","sourceRoot":"","sources":["../src/PluginRunner.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AA0JhF;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,2CAiDvE"}
@@ -0,0 +1,128 @@
1
+ import { jsxs as F, Fragment as M, jsx as P } from "react/jsx-runtime";
2
+ import T, { useState as S, useMemo as U, useEffect as m, useRef as H, useReducer as C } from "react";
3
+ import { pluginStore as f } from "./pluginStore.js";
4
+ import { isDeepEqual as N } from "./utility.js";
5
+ import { createMetadataContext as j, toDeconstructedMethods as v } from "./plugins.js";
6
+ const { setHookResult: A, removeHookResult: I } = f.getState(), E = T.memo(
7
+ ({
8
+ stateKey: r,
9
+ plugin: e,
10
+ options: t,
11
+ stateHandler: d
12
+ }) => {
13
+ const [i, s] = S(!0), n = U(
14
+ () => j(r, e.name),
15
+ [r, e.name]
16
+ ), o = U(
17
+ () => v(d),
18
+ [d]
19
+ ), b = U(
20
+ () => ({
21
+ stateKey: r,
22
+ pluginName: e.name,
23
+ isInitialMount: i,
24
+ options: t,
25
+ ...o,
26
+ ...n
27
+ }),
28
+ [
29
+ r,
30
+ e.name,
31
+ i,
32
+ t,
33
+ o,
34
+ n
35
+ ]
36
+ ), a = e.useHook ? e.useHook(b) : void 0;
37
+ m(() => {
38
+ s(!1);
39
+ }, []), m(() => (e.useHook ? A(r, e.name, a) : I(r, e.name), () => I(r, e.name)), [r, e.name, !!e.useHook, a]);
40
+ const u = H(), [h, x] = S(!0);
41
+ m(() => {
42
+ e.transformState && (N(t, u.current) || (e.transformState({
43
+ stateKey: r,
44
+ pluginName: e.name,
45
+ options: t,
46
+ hookData: a,
47
+ isInitialTransform: h,
48
+ ...o,
49
+ ...n
50
+ }), u.current = t, x(!1)));
51
+ }, [
52
+ r,
53
+ e,
54
+ t,
55
+ a,
56
+ h,
57
+ o,
58
+ n
59
+ ]);
60
+ const k = H(a);
61
+ return k.current = a, m(() => {
62
+ if (!e.onUpdate) return;
63
+ const l = (c) => {
64
+ c.stateKey === r && e.onUpdate({
65
+ stateKey: r,
66
+ pluginName: e.name,
67
+ update: c,
68
+ path: c.path,
69
+ options: t,
70
+ hookData: k.current,
71
+ ...o,
72
+ ...n
73
+ });
74
+ };
75
+ return f.getState().subscribeToUpdates(l);
76
+ }, [r, e, t, o, n]), m(() => {
77
+ if (!e.onFormUpdate) return;
78
+ const l = (c) => {
79
+ if (c.stateKey === r) {
80
+ const R = c.path;
81
+ e.onFormUpdate({
82
+ stateKey: r,
83
+ pluginName: e.name,
84
+ path: R,
85
+ event: {
86
+ type: c.type,
87
+ value: c.value,
88
+ path: R
89
+ },
90
+ options: t,
91
+ hookData: k.current,
92
+ ...o,
93
+ ...n
94
+ });
95
+ }
96
+ };
97
+ return f.getState().subscribeToFormUpdates(l);
98
+ }, [r, e, t, o, n]), null;
99
+ }
100
+ );
101
+ function B({ children: r }) {
102
+ const [, e] = C((s) => s + 1, 0);
103
+ m(() => f.subscribe(e), []);
104
+ const { pluginOptions: t, stateHandlers: d, registeredPlugins: i } = f.getState();
105
+ return /* @__PURE__ */ F(M, { children: [
106
+ Array.from(t.entries()).map(([s, n]) => {
107
+ const o = d.get(s);
108
+ return o ? Array.from(n.entries()).map(([b, a]) => {
109
+ const u = i.find((h) => h.name === b);
110
+ return u ? /* @__PURE__ */ P(
111
+ E,
112
+ {
113
+ stateKey: s,
114
+ plugin: u,
115
+ options: a,
116
+ stateHandler: o
117
+ },
118
+ `${s}:${b}`
119
+ ) : null;
120
+ }) : null;
121
+ }),
122
+ r
123
+ ] });
124
+ }
125
+ export {
126
+ B as PluginRunner
127
+ };
128
+ //# sourceMappingURL=PluginRunner.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginRunner.jsx","sources":["../src/PluginRunner.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useState, useRef, useReducer } from 'react';\r\nimport { pluginStore } from './pluginStore';\r\nimport { isDeepEqual } from './utility';\r\nimport { createMetadataContext, toDeconstructedMethods } from './plugins';\r\nimport type { CogsPlugin } from './plugins';\r\nimport type { StateObject, UpdateTypeDetail } from './CogsState';\r\nimport { FormEventType } from './store';\r\n\r\nconst { setHookResult, removeHookResult } = pluginStore.getState();\r\n\r\nconst PluginInstance = React.memo(\r\n ({\r\n stateKey,\r\n plugin,\r\n options,\r\n stateHandler,\r\n }: {\r\n stateKey: string;\r\n plugin: CogsPlugin<any, any, any, any, any>;\r\n options: any;\r\n stateHandler: StateObject<any>;\r\n }) => {\r\n const [isInitialMount, setIsInitialMount] = useState(true);\r\n const metadataContext = useMemo(\r\n () => createMetadataContext(stateKey, plugin.name),\r\n [stateKey, plugin.name]\r\n );\r\n\r\n const deconstructed = useMemo(\r\n () => toDeconstructedMethods(stateHandler),\r\n [stateHandler]\r\n );\r\n\r\n const hookContext = useMemo(\r\n () => ({\r\n stateKey,\r\n pluginName: plugin.name,\r\n isInitialMount,\r\n options,\r\n ...deconstructed,\r\n ...metadataContext,\r\n }),\r\n [\r\n stateKey,\r\n plugin.name,\r\n isInitialMount,\r\n options,\r\n deconstructed,\r\n metadataContext,\r\n ]\r\n );\r\n\r\n const hookData = plugin.useHook ? plugin.useHook(hookContext) : undefined;\r\n\r\n useEffect(() => {\r\n setIsInitialMount(false);\r\n }, []);\r\n\r\n useEffect(() => {\r\n if (plugin.useHook) setHookResult(stateKey, plugin.name, hookData);\r\n else removeHookResult(stateKey, plugin.name);\r\n return () => removeHookResult(stateKey, plugin.name);\r\n }, [stateKey, plugin.name, !!plugin.useHook, hookData]);\r\n\r\n const lastProcessedOptionsRef = useRef<any>();\r\n const [isInitialTransform, setIsInitialTransform] = useState(true);\r\n\r\n useEffect(() => {\r\n if (plugin.transformState) {\r\n if (!isDeepEqual(options, lastProcessedOptionsRef.current)) {\r\n plugin.transformState({\r\n stateKey,\r\n pluginName: plugin.name,\r\n options,\r\n hookData,\r\n isInitialTransform,\r\n ...deconstructed,\r\n ...metadataContext,\r\n });\r\n lastProcessedOptionsRef.current = options;\r\n setIsInitialTransform(false);\r\n }\r\n }\r\n }, [\r\n stateKey,\r\n plugin,\r\n options,\r\n hookData,\r\n isInitialTransform,\r\n deconstructed,\r\n metadataContext,\r\n ]);\r\n\r\n const hookDataRef = useRef(hookData);\r\n hookDataRef.current = hookData;\r\n\r\n useEffect(() => {\r\n if (!plugin.onUpdate) return;\r\n\r\n const handleUpdate = (update: UpdateTypeDetail) => {\r\n if (update.stateKey === stateKey) {\r\n plugin.onUpdate!({\r\n stateKey,\r\n pluginName: plugin.name,\r\n update,\r\n path: update.path,\r\n options,\r\n hookData: hookDataRef.current,\r\n ...deconstructed,\r\n ...metadataContext,\r\n });\r\n }\r\n };\r\n\r\n const unsubscribe = pluginStore\r\n .getState()\r\n .subscribeToUpdates(handleUpdate);\r\n return unsubscribe;\r\n }, [stateKey, plugin, options, deconstructed, metadataContext]);\r\n\r\n useEffect(() => {\r\n if (!plugin.onFormUpdate) return;\r\n\r\n const handleFormUpdate = (\r\n event: FormEventType & { stateKey: string }\r\n ) => {\r\n if (event.stateKey === stateKey) {\r\n const path = event.path;\r\n plugin.onFormUpdate!({\r\n stateKey,\r\n pluginName: plugin.name,\r\n path,\r\n event: {\r\n type: event.type,\r\n value: event.value,\r\n path,\r\n },\r\n options,\r\n hookData: hookDataRef.current,\r\n ...deconstructed,\r\n ...metadataContext,\r\n });\r\n }\r\n };\r\n\r\n const unsubscribe = pluginStore\r\n .getState()\r\n .subscribeToFormUpdates(handleFormUpdate);\r\n return unsubscribe;\r\n }, [stateKey, plugin, options, deconstructed, metadataContext]);\r\n\r\n return null;\r\n }\r\n);\r\n/**\r\n * The main orchestrator component. It reads from the central pluginStore\r\n * and renders a `PluginInstance` controller for each active plugin.\r\n */\r\nexport function PluginRunner({ children }: { children: React.ReactNode }) {\r\n // A simple way to force a re-render when the store changes.\r\n const [, forceUpdate] = useReducer((c) => c + 1, 0);\r\n\r\n // Subscribe to the store. When plugins or their options are added/removed,\r\n // this component will re-render to update the list of PluginInstances.\r\n useEffect(() => {\r\n const unsubscribe = pluginStore.subscribe(forceUpdate);\r\n return unsubscribe;\r\n }, []);\r\n\r\n const { pluginOptions, stateHandlers, registeredPlugins } =\r\n pluginStore.getState();\r\n\r\n return (\r\n <>\r\n {/*\r\n This declarative mapping is the core of the solution.\r\n React will now manage adding and removing `PluginInstance` components\r\n as the application state changes, ensuring hooks are handled safely.\r\n */}\r\n {Array.from(pluginOptions.entries()).map(([stateKey, pluginMap]) => {\r\n const stateHandler = stateHandlers.get(stateKey);\r\n if (!stateHandler) {\r\n return null; // Don't render a runner if the state handler isn't ready.\r\n }\r\n\r\n return Array.from(pluginMap.entries()).map(([pluginName, options]) => {\r\n const plugin = registeredPlugins.find((p) => p.name === pluginName);\r\n if (!plugin) {\r\n return null; // Don't render if the plugin is not in the registered list.\r\n }\r\n\r\n // Render a dedicated, memoized controller for this specific plugin configuration.\r\n return (\r\n <PluginInstance\r\n key={`${stateKey}:${pluginName}`}\r\n stateKey={stateKey}\r\n plugin={plugin}\r\n options={options}\r\n stateHandler={stateHandler}\r\n />\r\n );\r\n });\r\n })}\r\n\r\n {children}\r\n </>\r\n );\r\n}\r\n"],"names":["setHookResult","removeHookResult","pluginStore","PluginInstance","React","stateKey","plugin","options","stateHandler","isInitialMount","setIsInitialMount","useState","metadataContext","useMemo","createMetadataContext","deconstructed","toDeconstructedMethods","hookContext","hookData","useEffect","lastProcessedOptionsRef","useRef","isInitialTransform","setIsInitialTransform","isDeepEqual","hookDataRef","handleUpdate","update","handleFormUpdate","event","path","PluginRunner","children","forceUpdate","useReducer","c","pluginOptions","stateHandlers","registeredPlugins","jsxs","Fragment","pluginMap","pluginName","p","jsx"],"mappings":";;;;;AAQA,MAAM,EAAE,eAAAA,GAAe,kBAAAC,MAAqBC,EAAY,SAAA,GAElDC,IAAiBC,EAAM;AAAA,EAC3B,CAAC;AAAA,IACC,UAAAC;AAAA,IACA,QAAAC;AAAA,IACA,SAAAC;AAAA,IACA,cAAAC;AAAA,EAAA,MAMI;AACJ,UAAM,CAACC,GAAgBC,CAAiB,IAAIC,EAAS,EAAI,GACnDC,IAAkBC;AAAA,MACtB,MAAMC,EAAsBT,GAAUC,EAAO,IAAI;AAAA,MACjD,CAACD,GAAUC,EAAO,IAAI;AAAA,IAAA,GAGlBS,IAAgBF;AAAA,MACpB,MAAMG,EAAuBR,CAAY;AAAA,MACzC,CAACA,CAAY;AAAA,IAAA,GAGTS,IAAcJ;AAAA,MAClB,OAAO;AAAA,Q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EAAAC,GAAA,EAMG,UAAA;AAAA,IAAA,MAAM,KAAKJ,EAAc,QAAA,CAAS,EAAE,IAAI,CAAC,CAAC/B,GAAUoC,CAAS,MAAM;AAClE,YAAMjC,IAAe6B,EAAc,IAAIhC,CAAQ;AAC/C,aAAKG,IAIE,MAAM,KAAKiC,EAAU,QAAA,CAAS,EAAE,IAAI,CAAC,CAACC,GAAYnC,CAAO,MAAM;AACpE,cAAMD,IAASgC,EAAkB,KAAK,CAACK,MAAMA,EAAE,SAASD,CAAU;AAClE,eAAKpC,IAMH,gBAAAsC;AAAA,UAACzC;AAAA,UAAA;AAAA,YAEC,UAAAE;AAAA,YACA,QAAAC;AAAA,YACA,SAAAC;AAAA,YACA,cAAAC;AAAA,UAAA;AAAA,UAJK,GAAGH,CAAQ,IAAIqC,CAAU;AAAA,QAAA,IANzB;AAAA,MAaX,CAAC,IAnBQ;AAAA,IAoBX,CAAC;AAAA,IAEAV;AAAA,EAAA,GACH;AAEJ;"}
package/dist/index.d.ts CHANGED
@@ -3,4 +3,6 @@ export * from './CogsStateClient.js';
3
3
  export * from './utility.js';
4
4
  export * from './TRPCValidationLink.js';
5
5
  export * from './store.js';
6
+ export * from './plugins.js';
7
+ export * from './PluginRunner.js';
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,34 +1,41 @@
1
- import { $cogsSignal as r, addStateOptions as o, createCogsState as a, createCogsStateFromSync as s, useCogsStateFn as n } from "./CogsState.jsx";
2
- import { CogsStateClient as f, config as i, useCogsConfig as c } from "./CogsStateClient.jsx";
3
- import { debounce as p, deepMerge as S, deleteNestedProperty as u, getArrayLengthDifferences as l, getArrayLengthDifferencesArray as m, getDifferences as y, getDifferencesArray as C, isArray as x, isDeepEqual as A, isFunction as D, isObject as b, transformStateFunc as F, updateNestedProperty as h } from "./utility.js";
4
- import { useCogsTrpcValidationLink as N } from "./TRPCValidationLink.js";
5
- import { buildShadowNode as P, formRefStore as j, generateId as k, getGlobalStore as q } from "./store.js";
1
+ import { $cogsSignal as r, addStateOptions as o, createCogsState as a, useCogsStateFn as n } from "./CogsState.jsx";
2
+ import { CogsStateClient as d, config as g, useCogsConfig as i } from "./CogsStateClient.jsx";
3
+ import { debounce as c, deepMerge as p, deleteNestedProperty as u, getArrayLengthDifferences as S, getArrayLengthDifferencesArray as l, getDifferences as m, getDifferencesArray as x, isArray as y, isDeepEqual as C, isFunction as h, isObject as D, transformStateFunc as A, updateNestedProperty as b } from "./utility.js";
4
+ import { useCogsTrpcValidationLink as w } from "./TRPCValidationLink.js";
5
+ import { buildShadowNode as L, generateId as M, getGlobalStore as N, shadowStateStore as k, updateShadowTypeInfo as I } from "./store.js";
6
+ import { createMetadataContext as T, createPluginContext as j, keyedSchema as q, toDeconstructedMethods as E } from "./plugins.js";
7
+ import { PluginRunner as R } from "./PluginRunner.jsx";
6
8
  export {
7
9
  r as $cogsSignal,
8
- f as CogsStateClient,
10
+ d as CogsStateClient,
11
+ R as PluginRunner,
9
12
  o as addStateOptions,
10
- P as buildShadowNode,
11
- i as config,
13
+ L as buildShadowNode,
14
+ g as config,
12
15
  a as createCogsState,
13
- s as createCogsStateFromSync,
14
- p as debounce,
15
- S as deepMerge,
16
+ T as createMetadataContext,
17
+ j as createPluginContext,
18
+ c as debounce,
19
+ p as deepMerge,
16
20
  u as deleteNestedProperty,
17
- j as formRefStore,
18
- k as generateId,
19
- l as getArrayLengthDifferences,
20
- m as getArrayLengthDifferencesArray,
21
- y as getDifferences,
22
- C as getDifferencesArray,
23
- q as getGlobalStore,
24
- x as isArray,
25
- A as isDeepEqual,
26
- D as isFunction,
27
- b as isObject,
28
- F as transformStateFunc,
29
- h as updateNestedProperty,
30
- c as useCogsConfig,
21
+ M as generateId,
22
+ S as getArrayLengthDifferences,
23
+ l as getArrayLengthDifferencesArray,
24
+ m as getDifferences,
25
+ x as getDifferencesArray,
26
+ N as getGlobalStore,
27
+ y as isArray,
28
+ C as isDeepEqual,
29
+ h as isFunction,
30
+ D as isObject,
31
+ q as keyedSchema,
32
+ k as shadowStateStore,
33
+ E as toDeconstructedMethods,
34
+ A as transformStateFunc,
35
+ b as updateNestedProperty,
36
+ I as updateShadowTypeInfo,
37
+ i as useCogsConfig,
31
38
  n as useCogsStateFn,
32
- N as useCogsTrpcValidationLink
39
+ w as useCogsTrpcValidationLink
33
40
  };
34
41
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
@@ -0,0 +1,43 @@
1
+ import { StateObject, UpdateTypeDetail } from './CogsState';
2
+ import { CogsPlugin } from './plugins';
3
+
4
+ type PluginRegistryStore = {
5
+ stateHandlers: Map<string, StateObject<any>>;
6
+ registerStateHandler: (stateKey: string, handler: StateObject<any>) => void;
7
+ registeredPlugins: readonly CogsPlugin<any, any, any, any, any>[];
8
+ setRegisteredPlugins: (plugins: readonly CogsPlugin<any, any, any, any, any>[]) => void;
9
+ pluginOptions: Map<string, Map<string, any>>;
10
+ setPluginOptionsForState: (stateKey: string, pluginOptions: Record<string, any>) => void;
11
+ getPluginConfigsForState: (stateKey: string) => Array<{
12
+ plugin: CogsPlugin<any, any, any, any, any>;
13
+ options: any;
14
+ }>;
15
+ updateSubscribers: Set<(update: UpdateTypeDetail) => void>;
16
+ subscribeToUpdates: (callback: (update: UpdateTypeDetail) => void) => () => void;
17
+ notifyUpdate: (update: UpdateTypeDetail) => void;
18
+ formUpdateSubscribers: Set<(event: {
19
+ stateKey: string;
20
+ type: 'focus' | 'blur' | 'input';
21
+ path: string[];
22
+ value?: any;
23
+ }) => void>;
24
+ subscribeToFormUpdates: (callback: (event: {
25
+ stateKey: string;
26
+ type: 'focus' | 'blur' | 'input';
27
+ path: string[];
28
+ value?: any;
29
+ }) => void) => () => void;
30
+ notifyFormUpdate: (event: {
31
+ stateKey: string;
32
+ type: 'focus' | 'blur' | 'input';
33
+ path: string[];
34
+ value?: any;
35
+ }) => void;
36
+ hookResults: Map<string, Map<string, any>>;
37
+ setHookResult: (stateKey: string, pluginName: string, data: any) => void;
38
+ getHookResult: (stateKey: string, pluginName: string) => any | undefined;
39
+ removeHookResult: (stateKey: string, pluginName: string) => void;
40
+ };
41
+ export declare const pluginStore: import('zustand').UseBoundStore<import('zustand').StoreApi<PluginRegistryStore>>;
42
+ export {};
43
+ //# sourceMappingURL=pluginStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluginStore.d.ts","sourceRoot":"","sources":["../src/pluginStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,KAAK,mBAAmB,GAAG;IACzB,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,oBAAoB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAC5E,iBAAiB,EA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I,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;QACjC,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,KAAK,CAAC,EAAE,GAAG,CAAC;KACb,KAAK,IAAI,KACP,MAAM,IAAI,CAAC;IAChB,gBAAgB,EAAE,CAAC,KAAK,EAAE;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;QACjC,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,KAAK,CAAC,EAAE,GAAG,CAAC;KACb,KAAK,IAAI,CAAC;IACX,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3C,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IACzE,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,GAAG,GAAG,SAAS,CAAC;IACzE,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CAClE,CAAC;AAEF,eAAO,MAAM,WAAW,kFAqGrB,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { create as l } from "zustand";
2
+ const b = l((u, o) => ({
3
+ stateHandlers: /* @__PURE__ */ new Map(),
4
+ registerStateHandler: (e, s) => u((n) => {
5
+ const t = new Map(n.stateHandlers);
6
+ return t.set(e, s), console.log("addign handler", e, s), { stateHandlers: t };
7
+ }),
8
+ registeredPlugins: [],
9
+ pluginOptions: /* @__PURE__ */ new Map(),
10
+ setRegisteredPlugins: (e) => u({ registeredPlugins: e }),
11
+ setPluginOptionsForState: (e, s) => u((n) => {
12
+ const t = new Map(n.pluginOptions), r = /* @__PURE__ */ new Map();
13
+ return Object.entries(s).forEach(([i, p]) => {
14
+ n.registeredPlugins.some((a) => a.name === i) && r.set(i, p);
15
+ }), r.size > 0 && t.set(e, r), { pluginOptions: t };
16
+ }),
17
+ getPluginConfigsForState: (e) => {
18
+ const s = o(), n = s.pluginOptions.get(e);
19
+ return n ? s.registeredPlugins.map((t) => {
20
+ const r = n.get(t.name);
21
+ return r !== void 0 ? { plugin: t, options: r } : null;
22
+ }).filter(Boolean) : [];
23
+ },
24
+ updateSubscribers: /* @__PURE__ */ new Set(),
25
+ subscribeToUpdates: (e) => (o().updateSubscribers.add(e), () => {
26
+ o().updateSubscribers.delete(e);
27
+ }),
28
+ notifyUpdate: (e) => {
29
+ o().updateSubscribers.forEach((s) => s(e));
30
+ },
31
+ formUpdateSubscribers: /* @__PURE__ */ new Set(),
32
+ subscribeToFormUpdates: (e) => (o().formUpdateSubscribers.add(e), () => {
33
+ o().formUpdateSubscribers.delete(e);
34
+ }),
35
+ notifyFormUpdate: (e) => {
36
+ o().formUpdateSubscribers.forEach((s) => s(e));
37
+ },
38
+ hookResults: /* @__PURE__ */ new Map(),
39
+ setHookResult: (e, s, n) => u((t) => {
40
+ const r = new Map(t.hookResults), i = new Map(r.get(e) ?? /* @__PURE__ */ new Map());
41
+ return n === void 0 ? i.delete(s) : i.set(s, n), i.size > 0 ? r.set(e, i) : r.delete(e), { hookResults: r };
42
+ }),
43
+ getHookResult: (e, s) => o().hookResults.get(e)?.get(s),
44
+ removeHookResult: (e, s) => u((n) => {
45
+ const t = new Map(n.hookResults), r = new Map(t.get(e) ?? /* @__PURE__ */ new Map());
46
+ return r.delete(s), r.size > 0 ? t.set(e, r) : t.delete(e), { hookResults: t };
47
+ })
48
+ }));
49
+ export {
50
+ b as pluginStore
51
+ };
52
+ //# sourceMappingURL=pluginStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluginStore.js","sources":["../src/pluginStore.ts"],"sourcesContent":["import { create } from 'zustand';\r\nimport type { PluginData, StateObject, UpdateTypeDetail } from './CogsState';\r\nimport type { CogsPlugin } from './plugins';\r\n\r\ntype PluginRegistryStore = {\r\n stateHandlers: Map<string, StateObject<any>>; // stateKey -> handler\r\n registerStateHandler: (stateKey: string, handler: StateObject<any>) => void;\r\n registeredPlugins: readonly CogsPlugin<any, any, any, any, any>[];\r\n setRegisteredPlugins: (\r\n plugins: readonly CogsPlugin<any, any, any, any, any>[]\r\n ) => void;\r\n\r\n // Store options keyed by stateKey and pluginName\r\n pluginOptions: Map<string, Map<string, any>>; // stateKey -> pluginName -> options\r\n setPluginOptionsForState: (\r\n stateKey: string,\r\n pluginOptions: Record<string, any>\r\n ) => void;\r\n\r\n // Get all plugin configs for a specific stateKey\r\n getPluginConfigsForState: (stateKey: string) => Array<{\r\n plugin: CogsPlugin<any, any, any, any, any>;\r\n options: any;\r\n }>;\r\n updateSubscribers: Set<(update: UpdateTypeDetail) => void>;\r\n subscribeToUpdates: (\r\n callback: (update: UpdateTypeDetail) => void\r\n ) => () => void;\r\n notifyUpdate: (update: UpdateTypeDetail) => void;\r\n formUpdateSubscribers: Set<\r\n (event: {\r\n stateKey: string;\r\n type: 'focus' | 'blur' | 'input';\r\n path: string[];\r\n value?: any;\r\n }) => void\r\n >;\r\n subscribeToFormUpdates: (\r\n callback: (event: {\r\n stateKey: string;\r\n type: 'focus' | 'blur' | 'input';\r\n path: string[];\r\n value?: any;\r\n }) => void\r\n ) => () => void;\r\n notifyFormUpdate: (event: {\r\n stateKey: string;\r\n type: 'focus' | 'blur' | 'input';\r\n path: string[];\r\n value?: any;\r\n }) => void;\r\n hookResults: Map<string, Map<string, any>>; // stateKey -> pluginName -> hook\r\n setHookResult: (stateKey: string, pluginName: string, data: any) => void;\r\n getHookResult: (stateKey: string, pluginName: string) => any | undefined;\r\n removeHookResult: (stateKey: string, pluginName: string) => void;\r\n};\r\n\r\nexport const pluginStore = create<PluginRegistryStore>((set, get) => ({\r\n stateHandlers: new Map(),\r\n registerStateHandler: (stateKey, handler) =>\r\n set((state) => {\r\n const newMap = new Map(state.stateHandlers);\r\n newMap.set(stateKey, handler);\r\n console.log('addign handler', stateKey, handler);\r\n return { stateHandlers: newMap };\r\n }),\r\n registeredPlugins: [],\r\n pluginOptions: new Map(),\r\n\r\n setRegisteredPlugins: (plugins) => set({ registeredPlugins: plugins }),\r\n\r\n setPluginOptionsForState: (stateKey, pluginOptions) =>\r\n set((state) => {\r\n const newMap = new Map(state.pluginOptions);\r\n const statePluginMap = new Map();\r\n\r\n // Store each plugin's options\r\n Object.entries(pluginOptions).forEach(([pluginName, options]) => {\r\n // Only store if this is actually a registered plugin\r\n if (state.registeredPlugins.some((p) => p.name === pluginName)) {\r\n statePluginMap.set(pluginName, options);\r\n }\r\n });\r\n\r\n if (statePluginMap.size > 0) {\r\n newMap.set(stateKey, statePluginMap);\r\n }\r\n\r\n return { pluginOptions: newMap };\r\n }),\r\n\r\n getPluginConfigsForState: (stateKey) => {\r\n const state = get();\r\n const stateOptions = state.pluginOptions.get(stateKey);\r\n if (!stateOptions) return [];\r\n\r\n return state.registeredPlugins\r\n .map((plugin) => {\r\n const options = stateOptions.get(plugin.name);\r\n if (options !== undefined) {\r\n return { plugin, options };\r\n }\r\n return null;\r\n })\r\n .filter(Boolean) as Array<{\r\n plugin: CogsPlugin<any, any, any, any, any>;\r\n options: any;\r\n }>;\r\n },\r\n updateSubscribers: new Set(),\r\n subscribeToUpdates: (callback) => {\r\n const subscribers = get().updateSubscribers;\r\n subscribers.add(callback);\r\n // Return an unsubscribe function\r\n return () => {\r\n get().updateSubscribers.delete(callback);\r\n };\r\n },\r\n notifyUpdate: (update) => {\r\n // Call all registered subscribers with the update details\r\n get().updateSubscribers.forEach((callback) => callback(update));\r\n },\r\n formUpdateSubscribers: new Set(),\r\n subscribeToFormUpdates: (callback) => {\r\n const subscribers = get().formUpdateSubscribers;\r\n subscribers.add(callback);\r\n return () => {\r\n get().formUpdateSubscribers.delete(callback);\r\n };\r\n },\r\n notifyFormUpdate: (event) => {\r\n get().formUpdateSubscribers.forEach((callback) => callback(event));\r\n },\r\n hookResults: new Map(),\r\n\r\n setHookResult: (stateKey, pluginName, data) =>\r\n set((state) => {\r\n const next = new Map(state.hookResults);\r\n const byPlugin = new Map(next.get(stateKey) ?? new Map());\r\n if (data === undefined) byPlugin.delete(pluginName);\r\n else byPlugin.set(pluginName, data);\r\n if (byPlugin.size > 0) next.set(stateKey, byPlugin);\r\n else next.delete(stateKey);\r\n return { hookResults: next };\r\n }),\r\n\r\n getHookResult: (stateKey, pluginName) =>\r\n get().hookResults.get(stateKey)?.get(pluginName),\r\n\r\n removeHookResult: (stateKey, pluginName) =>\r\n set((state) => {\r\n const next = new Map(state.hookResults);\r\n const byPlugin = new Map(next.get(stateKey) ?? new Map());\r\n byPlugin.delete(pluginName);\r\n if (byPlugin.size > 0) next.set(stateKey, byPlugin);\r\n else next.delete(stateKey);\r\n return { hookResults: next };\r\n }),\r\n}));\r\n"],"names":["pluginStore","create","set","get","stateKey","handler","state","newMap","plugins","pluginOptions","statePluginMap","pluginName","options","p","stateOptions","plugin","callback","update","event","data","next","byPlugin"],"mappings":";AAyDO,MAAMA,IAAcC,EAA4B,CAACC,GAAKC,OAAS;AAAA,EACpE,mCAAmB,IAAA;AAAA,EACnB,sBAAsB,CAACC,GAAUC,MAC/BH,EAAI,CAACI,MAAU;AACb,UAAMC,IAAS,IAAI,IAAID,EAAM,aAAa;AAC1C,WAAAC,EAAO,IAAIH,GAAUC,CAAO,GAC5B,QAAQ,IAAI,kBAAkBD,GAAUC,CAAO,GACxC,EAAE,eAAeE,EAAA;AAAA,EAC1B,CAAC;AAAA,EACH,mBAAmB,CAAA;AAAA,EACnB,mCAAmB,IAAA;AAAA,EAEnB,sBAAsB,CAACC,MAAYN,EAAI,EAAE,mBAAmBM,GAAS;AAAA,EAErE,0BAA0B,CAACJ,GAAUK,MACnCP,EAAI,CAACI,MAAU;AACb,UAAMC,IAAS,IAAI,IAAID,EAAM,aAAa,GACpCI,wBAAqB,IAAA;AAG3B,kBAAO,QAAQD,CAAa,EAAE,QAAQ,CAAC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