react-state-custom 1.0.25 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/state-utils/utils.ts","../src/state-utils/useArrayHash.ts","../src/state-utils/ctx.ts","../src/state-utils/createRootCtx.tsx","../src/state-utils/createAutoCtx.tsx","../src/state-utils/useQuickSubscribe.ts","../src/dev-tool/useHighlight.tsx","../src/dev-tool/DataViewComponent.tsx","../src/dev-tool/StateLabelRender.tsx","../src/dev-tool/DevToolState.tsx","../src/dev-tool/DevTool.tsx"],"sourcesContent":["// Debounce function\nexport function debounce<T extends (...args: any[]) => any>(\n func: T,\n wait: number\n): ((...args: Parameters<T>) => void) & { cancel: any } {\n let timeout: ReturnType<typeof setTimeout> | null = null;\n\n let fn: Function & { cancel: any } = function (...args: Parameters<T>): void {\n if (timeout) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(() => {\n func(...args);\n }, wait);\n } as any;\n\n fn.cancel = () => clearTimeout(timeout!);\n\n return fn as any;\n}\n\n// Memoize function\nexport function memoize<T extends (...args: any[]) => any>(\n func: T\n): ((...args: Parameters<T>) => ReturnType<T>) & { cache: Map<string, ReturnType<T>> } {\n \n const cache = new Map<string, ReturnType<T>>();\n\n const cachedFunc: any = function (...args: Parameters<T>): ReturnType<T> {\n const key = JSON.stringify(args);\n if (cache.has(key)) {\n return cache.get(key) as ReturnType<T>;\n }\n const result = func(...args);\n cache.set(key, result);\n return result;\n }\n\n cachedFunc.cache = cache;\n\n return cachedFunc\n}\n\n","import { useRef } from \"react\"\n\n\nconst randomHash = () => Math.random().toString().slice(2)\n\n/**\n * useArrayHash\n *\n * A custom hook that computes a stable hash for an array of values.\n * The hash changes only when the array's contents differ from the previous call.\n *\n * @param e - The input array to hash.\n * @returns A string hash that updates when the array changes.\n *\n * How it works:\n * - Tracks the previous array and its hash using a `useRef`.\n * - Compares the new array to the previous one by length and element equality.\n * - If any difference is detected, generates a new random hash.\n */\nexport const useArrayHash = (e: any[]): string => {\n\n const { current: { computedHash } } = useRef({\n /**\n * Getter for the computed hash function.\n *\n * - Initializes with an empty array and a random hash.\n * - Returns a function that compares the current array to the previous one.\n * - Updates the hash if any difference is detected.\n */\n get computedHash() {\n let currentValues: any[] = []\n let currentHash = randomHash()\n return (e: any[]) => {\n let isDiff = false\n\n // Check for differences in array existence, length, or elements.\n isDiff = isDiff || ((!e) != (!currentValues))\n isDiff = isDiff || (e?.length != currentValues?.length);\n isDiff = isDiff || (e.some((f, i) => f != currentValues[i]));\n\n // Update the hash if differences are found.\n currentValues = e;\n if (isDiff) {\n currentHash = randomHash()\n }\n\n return currentHash\n }\n }\n })\n\n return computedHash(e)\n}","import { debounce, memoize } from \"./utils\";\nimport { useEffect, useMemo, useState } from \"react\"\nimport { useArrayHash } from \"./useArrayHash\"\n\n\n\nconst CHANGE_EVENT = \"@--change-event\"\n\nclass DataEvent<D> extends Event {\n constructor(\n public event: keyof D,\n public value: D[typeof event] | undefined\n ) {\n super(String(event));\n }\n}\n\nclass ChangeEvent<D> extends Event {\n constructor(\n public value: DataEvent<D>\n ) {\n super(CHANGE_EVENT, value);\n }\n}\n\n/**\n * Generic context for managing shared state and event subscriptions.\n * @template D - The shape of the data managed by the context.\n */\nexport class Context<D> extends EventTarget {\n /**\n * Create a new Context instance.\n * @param name - The name of the context (for debugging).\n */\n constructor(public name: string) {\n console.log(\"[CONTEXT] %s\", name)\n // this.event.setMaxListeners(100)\n super();\n }\n\n /**\n * The current data held by the context.\n */\n public data: Partial<D> = {}\n /**\n * Registry for tracking active keys (for duplicate detection).\n */\n public registry = new Set<string>()\n\n public useCounter = 0\n\n /**\n * Publish a value to the context and notify subscribers if it changed.\n * @param key - The key to update.\n * @param value - The new value.\n */\n public publish(key: keyof D, value: D[typeof key] | undefined) {\n\n if (value != this.data[key]) {\n this.data[key] = value\n let event = new DataEvent(key, value);\n this.dispatchEvent(event);\n this.dispatchEvent(new ChangeEvent(event))\n }\n }\n\n /**\n * Subscribe to changes for a specific key in the context.\n * @param key - The key to subscribe to.\n * @param _listener - Callback invoked with the new value.\n * @returns Unsubscribe function.\n */\n public subscribe(key: keyof D, _listener: (e: D[typeof key] | undefined) => void) {\n\n const listener = ({ event, value }: any) => {\n _listener(value)\n }\n\n this.addEventListener(String(key), listener)\n // console.log(\"listenerCount:\", String(key), this.event.listenerCount(String(key)))\n\n if (key in this.data) _listener(this.data[key])\n\n return () => this.removeEventListener(String(key), listener)\n }\n\n public subscribeAll(_listener: (changeKey: keyof D, newData: Partial<D>) => void) {\n\n const listener = (event: any) => {\n if (event instanceof ChangeEvent) {\n const { value: data } = event\n _listener(data.event as any as keyof D, this.data)\n }\n }\n\n this.addEventListener(String(CHANGE_EVENT), listener)\n\n return () => this.removeEventListener(String(CHANGE_EVENT), listener)\n\n }\n\n}\n\n/**\n * Get or create a memoized Context instance by name.\n * @param name - The context name.\n * @returns The Context instance.\n */\nexport const getContext = memoize((name: string) => new Context<any>(name))\n\n/**\n * Type alias for a function that returns a Context instance.\n */\nexport type getContext<D> = (e: string) => Context<D>\n\n/**\n * React hook to get a typed Context instance by name.\n * @param name - The context name.\n * @returns The Context instance.\n */\nexport const useDataContext = <D>(name: string = \"noname\") => {\n const ctx = useMemo(() => getContext(name), [name])\n useEffect(() => {\n ctx.useCounter += 1;\n return () => {\n ctx.useCounter -= 1;\n if (ctx.useCounter <= 0) {\n setTimeout(() => {\n if (ctx.useCounter <= 0) {\n getContext.cache.delete(JSON.stringify([name]))\n }\n }, 100)\n }\n }\n }, [ctx])\n\n return ctx as any as Context<D>\n}\n\n/**\n * Internal hook to check for duplicate registry entries in a context.\n * Warns if any of the provided names are already registered.\n * @param ctx - The context instance.\n * @param names - Names to check and register.\n */\nconst useRegistryChecker = (ctx: Context<any> | undefined, ...names: string[]) => {\n // return;\n const stack = new Error(\"[ctx] useRegistryChecker failed \" + JSON.stringify({ names, ctx: ctx?.name ?? 'undefined' }))\n\n useEffect(\n () => {\n if (ctx) {\n if (names.some(name => ctx.registry.has(name))) {\n console.error(stack)\n }\n names.forEach(e => ctx.registry.add(e))\n\n // console.debug(\"[ctx] %s%s add datasource\", componentId, ctx.name, names)\n return () => {\n // console.debug(\"[ctx] %s %s remove datasource\", componentId, ctx.name, names)\n\n names.forEach(e => ctx.registry.delete(e))\n }\n }\n },\n [ctx, names.length]\n )\n\n}\n\n/**\n * React hook to publish a value to the context when it changes.\n * @param ctx - The context instance.\n * @param key - The key to update.\n * @param value - The new value.\n */\nexport const useDataSource = <D, K extends keyof D>(ctx: Context<D> | undefined, key: K, value: D[K] | undefined) => {\n //@ts-check\n useEffect(() => {\n if (ctx && ctx.data[key] != value) {\n\n ctx.publish(key, value)\n }\n }, [key, value, ctx])\n\n useRegistryChecker(ctx, key as any)\n}\n\n/**\n * React hook to subscribe to a context value, with optional debounce.\n * @param ctx - The context instance.\n * @param key - The key to subscribe to.\n * @param debounceTime - Debounce time in ms (default 0).\n * @returns The current value for the key.\n */\nexport const useDataSubscribe = <D, K extends keyof D>(ctx: Context<D> | undefined, key: K, debounceTime = 0): D[K] | undefined => {\n //@ts-check\n const [{ value }, setState] = useState(() => ({ value: ctx?.data?.[key] }))\n\n useEffect(() => {\n if (ctx) {\n let callback = debounceTime == 0\n ? (value: any) => setState({ value } as any)\n : debounce((value: any) => setState({ value } as any), debounceTime)\n let unsub = ctx.subscribe(key, callback)\n value != ctx.data[key] && setState({ value: ctx.data[key] })\n return () => {\n unsub()\n }\n }\n }, [key, ctx])\n\n return ctx?.data[key]\n}\n\n/**\n * React hook to subscribe to a context value and transform it before returning.\n * @param ctx - The context instance.\n * @param key - The key to subscribe to.\n * @param transform - Function to transform the value.\n * @returns The transformed value.\n */\nexport const useDataSubscribeWithTransform = <D, K extends keyof D, E>(ctx: Context<D> | undefined, key: K, transform: (e: D[K] | undefined) => E): E => {\n const [, setState] = useState(0)\n const result = useMemo(\n () => transform(ctx?.data[key]),\n [transform, ctx?.data[key]]\n )\n\n useEffect(() => {\n if (ctx) {\n let preValue = result\n let callback = () => {\n let newValue = transform(ctx.data[key])\n if (newValue != preValue) {\n preValue = newValue;\n setState(e => e + 1)\n };\n }\n let unsub = ctx.subscribe(key, callback)\n callback();\n return () => unsub()\n }\n }, [key, ctx])\n\n return result\n}\n\n/**\n * React hook to publish multiple values to the context.\n * @param ctx - The context instance.\n * @param entries - Array of [key, value] pairs to update.\n */\nexport const useDataSourceMultiple = <D, T extends readonly (keyof D)[]>(\n ctx: Context<D> | undefined,\n ...entries: { -readonly [P in keyof T]: [T[P], D[T[P]]] }\n) => {\n //@ts-check\n useEffect(() => {\n if (ctx) {\n for (let [key, value] of entries) {\n ctx.data[key] != value && ctx.publish(key, value)\n }\n }\n }, [ctx, useArrayHash(entries.flat())])\n\n useRegistryChecker(ctx, ...entries.map(e => e[0]) as any)\n\n}\n\n/**\n * React hook to subscribe to multiple context values.\n * @param ctx - The context instance.\n * @param keys - Keys to subscribe to.\n * @returns An object with the current values for the keys.\n */\nexport const useDataSubscribeMultiple = <D, K extends (keyof D)[]>(\n ctx: Context<D> | undefined,\n ...keys: K\n): { [i in keyof K]: D[K[i]] | undefined } => {\n const [, setCounter] = useState(0)\n\n const returnValues = keys.map(key => ctx?.data?.[key])\n\n useEffect(() => {\n if (ctx) {\n let prevValues = returnValues\n const callback = debounce(() => {\n let currentValues = keys.map(key => ctx?.data?.[key])\n if (keys.some((key, i) => prevValues[i] != currentValues[i])) {\n // console.log(\"DIFF\", keys.filter((e, i) => prevValues[i] != currentValues[i]))\n prevValues = currentValues\n setCounter(c => c + 1)\n }\n }, 1)\n\n let handles = keys.map(key => ctx.subscribe(key, callback))\n\n let firstCall = setTimeout(callback, 1);\n\n return () => {\n clearTimeout(firstCall)\n callback.cancel();\n handles.forEach(unsub => unsub())\n }\n\n }\n }, [ctx, ...keys])\n\n\n return Object\n .fromEntries(keys.map((key, index) => [key, returnValues[index]])) as any\n}\n\n/**\n * React hook to subscribe to multiple context values with throttling.\n * @param ctx - The context instance.\n * @param debounceTime - Debounce time in ms (default 50).\n * @param keys - Keys to subscribe to.\n * @returns Array of current values for the keys.\n */\nexport const useDataSubscribeMultipleWithDebounce = <D, K extends (keyof D)[]>(\n ctx: Context<D> | undefined,\n debounceTime = 50,\n ...keys: K\n): { [i in keyof K]: D[K[i]] | undefined } => {\n //@ts-check\n const [, setCounter] = useState(0)\n\n const returnValues = keys.map(key => ctx?.data?.[key])\n\n useEffect(() => {\n if (ctx) {\n let prevValues = returnValues\n const callback = debounce(() => {\n let currentValues = keys.map(key => ctx?.data?.[key])\n if (keys.some((key, i) => prevValues[i] != currentValues[i])) {\n prevValues = currentValues\n setCounter(c => c + 1)\n }\n }, debounceTime)\n\n let handles = keys.map(key => ctx.subscribe(key, callback))\n\n let firstCall = setTimeout(callback, 1);\n\n return () => {\n clearTimeout(firstCall)\n callback.cancel();\n handles.forEach(unsub => unsub())\n }\n\n }\n }, [ctx, ...keys])\n\n return returnValues as any\n}\n\n\n\n","import { useEffect, useMemo } from \"react\"\nimport { useDataContext, useDataSourceMultiple, type Context } from \"./ctx\"\n\n\n/**\n * createRootCtx\n *\n * Factory that creates a headless \"Root\" component and companion hooks for a context namespace.\n * It derives a unique context name from a base `name` and a props object `U`, then publishes\n * a computed state `V` (from `useFn`) to that context.\n *\n * Usage (manual mounting):\n * ```\n * const { Root, useCtxState } = createRootCtx('user-state', useUserState)\n * ...\n * // Mount exactly one Root per unique props combination\n * <Root userId={id} />\n * ...\n * // Read anywhere ,using the same props shape\n * const user = useCtxState({ userId: id })\n *```\n * Strict vs lenient consumers:\n * - useCtxStateStrict(props) throws if a matching Root is not mounted.\n * - useCtxState(props) logs an error (after 1s) instead of throwing.\n *\n * Multiple instances safety:\n * - Mounting more than one Root with the same resolved context name throws (guards accidental duplicates).\n *\n * Name resolution notes:\n * - The context name is built from `name` + sorted key/value pairs of `props` (U), joined by \"-\".\n * - Prefer stable, primitive props to avoid collisions; if you need automation, pair with `createAutoCtx` and\n * mount a single <AutoRootCtx Wrapper={ErrorBoundary} /> at the app root so you don't manually mount `Root`.\n */\nexport const createRootCtx = <U extends object, V extends object>(name: string, useFn: (e: U) => V) => {\n\n const resolveCtxName = (e: U) => [\n name,\n ...Object\n .entries(e ?? {})\n .sort((e, f) => e[0].localeCompare(f[0]))\n .flat()\n ].join(\"-\")\n\n const ctxMountedCheck = new Set<string>()\n\n const DebugState = ({ }) => <></>\n\n\n const RootState: React.FC<U> = (e: U) => {\n const state = useFn(e)\n const ctxName = resolveCtxName(e)\n const ctx = useDataContext<V>(ctxName)\n const stack = useMemo(() => new Error().stack, [])\n\n useDataSourceMultiple(\n ctx,\n ...Object.entries(state) as any\n )\n\n useEffect(() => {\n if (ctxMountedCheck.has(ctxName)) {\n const err = new Error(\"RootContext \" + ctxName + \" are mounted more than once\")\n err.stack = stack;\n throw err\n }\n ctxMountedCheck.add(ctxName)\n return () => { ctxMountedCheck.delete(ctxName) };\n })\n\n return <DebugState {...e} {...state} />\n }\n\n RootState.displayName = `StateContainer[${name}]`\n DebugState.displayName = `Debug[${name}]`\n\n return {\n name,\n resolveCtxName,\n Root: RootState,\n /**\n * Strict consumer: throws if the corresponding Root for these props isn't mounted.\n * Use in development/tests to fail fast when wiring is incorrect.\n */\n useCtxStateStrict: (e: U): Context<V> => {\n const ctxName = resolveCtxName(e)\n\n const stack = useMemo(() => new Error().stack, [])\n\n useEffect(() => {\n if (!ctxMountedCheck.has(ctxName)) {\n const err = new Error(\"RootContext [\" + ctxName + \"] is not mounted\")\n err.stack = stack;\n throw err\n }\n }, [ctxName])\n\n return useDataContext<V>(ctxName)\n },\n /**\n * Lenient consumer: schedules a console.error if the Root isn't mounted instead of throwing.\n * Useful in production to avoid hard crashes while still surfacing misconfiguration.\n */\n useCtxState: (e: U): Context<V> => {\n const ctxName = resolveCtxName(e)\n\n const stack = useMemo(() => new Error().stack, [])\n\n useEffect(() => {\n if (!ctxMountedCheck.has(ctxName)) {\n const err = new Error(\"RootContext [\" + ctxName + \"] is not mounted\")\n err.stack = stack;\n let timeout = setTimeout(() => console.error(err), 1000)\n return () => clearTimeout(timeout)\n }\n }, [ctxMountedCheck.has(ctxName)])\n\n return useDataContext<V>(ctxName)\n }\n }\n}","import { useEffect, useState, Fragment, useCallback, useMemo } from \"react\"\nimport { useDataContext, useDataSourceMultiple, useDataSubscribe, type Context } from \"./ctx\"\nimport { createRootCtx } from \"./createRootCtx\"\n\n\n\n\n\n\nconst weakmapName = (function () {\n const weakmap = new WeakMap()\n\n return (e: any): string => {\n let result = weakmap.get(e);\n if (!result) {\n weakmap.set(e, result = (e?.name ?? \"\") + \":\" + Math.random().toString())\n }\n return result\n }\n})()\n\n\nconst resolveName = (e: any) => [\n ...Object\n .entries(e ?? {})\n .sort((e, f) => e[0].localeCompare(f[0]))\n .flat()\n].join(\"-\")\n\n/**\n * Inline docs: createAutoCtx + AutoRootCtx\n *\n * Quick start\n * 1) Mount <AutoRootCtx /> ONCE near your app root. Provide a Wrapper that acts like an ErrorBoundary to isolate and log errors.\n * Example: <AutoRootCtx Wrapper={MyErrorBoundary} />\n *\n * 2) Create auto contexts from your root context factories:\n * ```\n * const { useCtxState: useTestCtxState } = createAutoCtx(createRootCtx('test-state', stateFn))\n * const { useCtxState: useOtherCtxState } = createAutoCtx(createRootCtx('other-state', otherFn))\n * ```\n * 3) Use them in components:\n * ```\n * const ctx = useTestCtxState({ userId })\n * const { property1, property2 } = useDataSubscribeMultiple(ctx,'property1','property2')\n * // No need to mount the Root returned by createRootCtx directly — AutoRootCtx manages it for you.\n * ```\n * Notes\n * - AutoRootCtx must be mounted before any useCtxState hooks created by createAutoCtx run.\n * - Wrapper should be an ErrorBoundary-like component that simply renders {children}; no extra providers or layout required.\n * - For each unique params object (by stable stringified key), AutoRootCtx ensures a corresponding Root instance is rendered.\n */\n\nexport const AutoRootCtx = ({ Wrapper = Fragment }) => {\n\n const ctx = useDataContext<any>(\"auto-ctx\")\n\n\n // const [state, setState] = useState<Record<string, { Component: React.FC, subState: Record<string, { params: any, counter: number }> }>>({})\n const [state, setState] = useState<Record<string, {\n Component: React.FC,\n params: any,\n paramKey: string,\n counter: number,\n keepUntil?: number\n }>>({})\n\n\n const subscribeRoot = useCallback(\n (contextName: string, Component: React.FC<any>, params: any, timeToCleanState = 0) => {\n\n const recordKey = [contextName, weakmapName(Component), resolveName(params)].join(\":\");\n\n setState(state => ({\n ...state,\n [recordKey]: {\n ...state[recordKey] ?? { Component, params, paramKey: resolveName(params) },\n counter: (state[recordKey]?.counter ?? 0) + 1,\n keepUntil: undefined,\n }\n }))\n\n return () => setState(({ [recordKey]: current, ...rest }) => ({\n ...rest,\n ...(current?.counter > 1 || timeToCleanState > 0) ? {\n [recordKey]: {\n ...current,\n counter: current.counter - 1,\n keepUntil: current.counter > 1 ? undefined : (Date.now() + timeToCleanState),\n }\n } : {}\n }))\n\n },\n []\n )\n\n const nextDelete = useMemo(() => Object.entries(state)\n .filter(([, { counter, keepUntil }]) => counter <= 0 && keepUntil)\n .toSorted(([, { keepUntil: k1 = 0 }], [, { keepUntil: k2 = 0 }]) => k1 - k2)\n ?.at(0),\n [state]\n )\n\n console.log({ state, nextDelete })\n\n useEffect(() => {\n if (nextDelete) {\n const [key, { keepUntil }] = nextDelete\n if (typeof keepUntil == 'undefined')\n throw new Error(\"Invalid state mfr\")\n\n let t = setTimeout(() => {\n // console.log(\"Delay Cleaned\")\n setState(({ [key]: _, ...rest }) => rest)\n }, Math.max(0, keepUntil - Date.now()))\n return () => {\n // console.log(\"Cancel clean\")\n clearTimeout(t)\n };\n }\n }, [nextDelete])\n\n useDataSourceMultiple(ctx,\n [\"subscribe\", subscribeRoot],\n [\"state\", state],\n )\n\n return <>\n {Object\n .entries(state)\n .filter(([, { counter, keepUntil = 0 }]) => counter > 0 || keepUntil >= Date.now())\n .map(([key, { Component, params, counter, paramKey, keepUntil }]) => <Wrapper key={key}>\n <Component key={paramKey} {...params} />\n </Wrapper>)}\n </>\n\n}\n\n/**\n * createAutoCtx\n *\n * Bridges a Root context (from createRootCtx) to the global AutoRootCtx renderer.\n * You do NOT mount the Root component yourself — just mount <AutoRootCtx /> once at the app root.\n *\n * Usage: \n * ```\n * const { useCtxState: useTestCtxState } = createAutoCtx(createRootCtx(\n * 'test-state', \n * stateFn\n * ))\n * const { useCtxState: useOtherCtxState } = createAutoCtx(createRootCtx(\n * 'other-state', \n * otherFn\n * ))\n * ```\n * \n * Then inside components:\n * ```\n * const ctxState = useTestCtxState({ any: 'params' })\n * ```\n * AutoRootCtx will subscribe/unsubscribe instances per unique params and render the appropriate Root under the hood.\n */\nexport const createAutoCtx = <U extends object, V extends object,>(\n { Root, resolveCtxName, name }: ReturnType<typeof createRootCtx<U, V>>,\n timeToClean = 0\n) => {\n\n return {\n\n useCtxState: (e: U): Context<V> => {\n\n const ctxName = resolveCtxName(e)\n\n const subscribe = useDataSubscribe(useDataContext<any>(\"auto-ctx\"), \"subscribe\")\n\n useEffect(\n () => subscribe?.(name, Root, e, timeToClean),\n [Root, subscribe, name, ctxName, timeToClean]\n )\n\n return useDataContext<V>(ctxName)\n }\n }\n}","\nimport { debounce } from \"./utils\";\nimport { useState, useMemo, useEffect } from \"react\";\nimport type { Context } from \"./ctx\";\n\n/**\n * useQuickSubscribe is a custom React hook for efficiently subscribing to specific properties of a context's data object.\n * \n * @template D - The shape of the context data.\n * @param {Context<D> | undefined} ctx - The context object containing data and a subscribe method.\n * @returns {Partial<D>} A proxy object that mirrors the context data, automatically subscribing to properties as they are accessed.\n *\n * This hook tracks which properties of the context data are accessed by the component and subscribes to updates for only those properties.\n * When any of the subscribed properties change, the hook triggers a re-render. Subscriptions are managed and cleaned up automatically\n * when the component unmounts or the context changes. This approach minimizes unnecessary re-renders and resource usage by only\n * subscribing to the data that the component actually uses.\n *\n * Example usage:\n * const {name} = useQuickSubscribe(userContext);\n * // Accessing name will subscribe to changes in 'name' only\n * return <div>{name}</div>;\n */\n\nexport const useQuickSubscribe = <D>(\n ctx: Context<D> | undefined\n): {\n [P in keyof D]?: D[P] | undefined;\n } => {\n\n const [, setCounter] = useState(0);\n\n const { proxy, finalGetter, openGetter, clean } = useMemo(\n () => {\n\n const allKeys = new Set<keyof D>()\n const allCompareValue: { [P in keyof D]?: D[P] | undefined; } = {}\n const allUnsub = new Map()\n\n const proxy = new Proxy(\n ctx?.data as any,\n {\n get(target, p) {\n if (isOpenGetter) {\n allKeys.add(p as keyof D)\n return allCompareValue[p as keyof D] = target[p];\n } else {\n throw new Error(\"now allow here\")\n }\n }\n }\n ) as any\n\n let isOpenGetter = true;\n\n\n let onChange = debounce(() => {\n if ([...allKeys.values()]\n .some(k => allCompareValue[k] != ctx?.data?.[k])) {\n setCounter(c => c + 1)\n }\n }, 0)\n\n let openGetter = () => {\n isOpenGetter = true\n allKeys.clear()\n }\n\n let finalGetter = () => {\n isOpenGetter = false;\n\n [...allKeys.values()]\n .filter(k => !allUnsub.has(k))\n .forEach(k => {\n allUnsub.set(k, ctx?.subscribe(k, onChange))\n });\n\n [...allUnsub.keys()]\n .filter(k => !allKeys.has(k))\n .forEach(k => {\n let unsub = allUnsub.get(k)\n unsub?.();\n allUnsub.delete(k);\n });\n\n }\n\n let clean = () => {\n openGetter();\n finalGetter();\n setCounter(c => c + 1)\n }\n\n return { proxy, finalGetter, openGetter, clean }\n },\n [ctx]\n )\n\n openGetter();\n\n setTimeout(finalGetter, 0)\n\n useEffect(\n () => () => clean(),\n [clean]\n )\n\n return proxy;\n\n\n};\n","import React, { useContext, useMemo } from \"react\";\n\nexport function useHighlight(filterString: string) {\n const highlight = useMemo(\n () => buildRegex(filterString\n .toLowerCase()\n .split(\" \"), 'gi'),\n [filterString]\n );\n return { highlight };\n}\n\nfunction escapeRegex(str: string) {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction buildRegex(words: string[], flags = 'gi') {\n const pattern = words.map(escapeRegex).join('|');\n return new RegExp(`(${pattern})`, flags);\n}\n\nfunction markByToken(text: string, regex: RegExp) {\n const result = [];\n let last = 0;\n for (const match of text.matchAll(regex)) {\n const [m] = match;\n const start = match.index;\n if (start > last) result.push(text.slice(last, start));\n result.push(<mark key={start}>{m}</mark>);\n last = start + m.length;\n }\n if (last < text.length) result.push(text.slice(last));\n return result;\n}\n\nconst highlightCtx = React.createContext<{ highlight?: RegExp }>({\n highlight: undefined\n})\n\nexport const HightlightWrapper: React.FC<{ highlight: string, children: any }> = ({ children, highlight }) => {\n return <highlightCtx.Provider value={useHighlight(highlight)}>\n {children}\n </highlightCtx.Provider>\n}\n\nexport const HighlightString: React.FC<{ text: string; }> = ({ text }) => {\n const { highlight } = useContext(highlightCtx)\n\n const render = useMemo(\n () => highlight ? markByToken(text, highlight) : text,\n [text, highlight]\n );\n\n return <>{render}</>;\n\n};\n","import React, { useMemo } from \"react\";\n\n\nexport type DataViewComponent = React.FC<{ value: any; name: string; }>;\n\nexport const DataViewDefault: DataViewComponent = ({ name, value }) => {\n\n const renderString = useMemo(() => {\n try {\n return JSON.stringify({ [name]: value }, null, 2);\n } catch (error) {\n return String(error);\n }\n }, [name, value]);\n\n return <pre>{renderString}</pre>;\n};\n","import React, { useRef, useEffect } from \"react\";\nimport { getContext } from \"../state-utils/ctx\";\nimport { debounce } from \"../state-utils/utils\";\nimport { HighlightString } from \"./useHighlight\";\n\nexport const StateLabelRender: React.FC<any> = ({ selectedKey, setKey, currentKey, highlight, ...props }) => {\n const ctx = getContext(currentKey);\n const divRef = useRef<HTMLDivElement>(undefined);\n\n useEffect(() => {\n if (divRef.current) {\n let flashKeyDebounce = debounce(() => {\n if (divRef.current) {\n divRef.current?.classList.add(\"state-key-updated\");\n requestAnimationFrame(() => divRef.current?.classList.remove(\"state-key-updated\"));\n }\n }, 5);\n return ctx.subscribeAll(flashKeyDebounce);\n }\n\n }, [ctx, divRef]);\n\n return <div\n ref={divRef}\n className=\"state-key\"\n title={currentKey}\n data-active={currentKey == selectedKey}\n onClick={() => setKey(currentKey)}\n {...props}\n >\n <div className=\"state-key-name\">\n <HighlightString text={String(currentKey)} />\n </div>\n <div className=\"state-key-meta\">\n {Object.keys(ctx.data).length} items\n </div>\n </div>;\n};\n","import React, { useEffect, useMemo, useState } from \"react\"\nimport { getContext } from \"../state-utils/ctx\"\nimport { debounce } from \"../state-utils/utils\"\nimport { HightlightWrapper } from \"./useHighlight\"\nimport { DataViewComponent, DataViewDefault } from \"./DataViewComponent\"\nimport { StateLabelRender } from \"./StateLabelRender\"\nimport \"./devTool.css\"\n\nconst cache = getContext.cache\n\nexport const DevToolState: React.FC<{ Component: DataViewComponent }> = ({ Component }) => {\n const [allKeys, setKeys] = useState(() => [...cache.keys()])\n const [filterString, setFilterString] = useState(\"\")\n const [selectedKey, setKey] = useState(\"\")\n\n useEffect(() => {\n let t = setInterval(() => {\n setKeys(k => k.length != cache.size\n ? [...cache.keys()]\n : k\n )\n }, 50)\n return () => clearInterval(t)\n }, [cache])\n\n const filterFn = useMemo(\n () => {\n const preFilter = filterString\n .toLowerCase()\n .split(\" \")\n return (e: string) => {\n const sLow = e.toLowerCase()\n return preFilter.every(token => sLow.includes(token))\n }\n },\n [filterString]\n )\n\n\n return <div className=\"main-panel\">\n <div className=\"state-list\">\n <input\n placeholder=\"Type to Filter ...\"\n className=\"state-filter\"\n value={filterString}\n onChange={(ev) => setFilterString(ev.target.value)}\n />\n <HightlightWrapper highlight={filterString}>\n {allKeys\n .map(e => JSON.parse(e)?.[0])\n .filter(e => e != \"auto-ctx\" && e)\n .filter(filterFn)\n .map(e => <StateLabelRender {...{ selectedKey, setKey, currentKey: e, }} />)}\n </HightlightWrapper>\n\n </div>\n <div className=\"state-view\" >\n <StateView dataKey={selectedKey} key={selectedKey} Component={Component} />\n </div>\n </div>\n}\n\nexport const StateView: React.FC<{ dataKey: string, Component: DataViewComponent }> = ({ dataKey, Component = DataViewDefault }) => {\n const ctx = getContext(dataKey)\n const [currentData, setCurrentData] = useState({ ...ctx?.data })\n\n useEffect(() => {\n let updateDataDebounce = debounce(setCurrentData, 5)\n return ctx\n .subscribeAll((changeKey, newData) => updateDataDebounce({ ...newData }))\n\n }, [ctx])\n\n return <Component\n value={currentData}\n name={dataKey}\n />\n}\n","import \"./devTool.css\"\nimport { useState } from \"react\"\nimport { DevToolState } from \"./DevToolState\";\nimport { DataViewDefault } from \"./DataViewComponent\";\n\n\nexport const DevToolContainer = ({ toggleButton = \"[x]\", Component = DataViewDefault, ...props }) => {\n const [active, setActive] = useState(false);\n return <>\n <button className=\"react-state-dev-btn\" data-active={active} onClick={() => setActive(true)} {...props}>\n {props?.children ?? \"Toggle Dev Tool\"}\n </button>\n <div className=\"react-state-dev-container\" data-active={active}>\n <button className=\"close-btn\" onClick={() => setActive(false)}>\n [x]\n </button>\n {active && <DevToolState Component={Component} />}\n </div>\n </>\n}"],"names":["debounce","func","wait","timeout","fn","args","memoize","cache","cachedFunc","key","result","randomHash","useArrayHash","computedHash","useRef","currentValues","currentHash","e","isDiff","f","CHANGE_EVENT","DataEvent","event","value","ChangeEvent","Context","name","_listener","listener","data","getContext","useDataContext","ctx","useMemo","useEffect","useRegistryChecker","names","stack","useDataSource","useDataSubscribe","debounceTime","setState","useState","callback","unsub","useDataSubscribeWithTransform","transform","preValue","newValue","useDataSourceMultiple","entries","useDataSubscribeMultiple","keys","setCounter","returnValues","prevValues","i","c","handles","firstCall","index","useDataSubscribeMultipleWithDebounce","createRootCtx","useFn","resolveCtxName","ctxMountedCheck","DebugState","jsx","Fragment","RootState","state","ctxName","err","weakmapName","weakmap","resolveName","AutoRootCtx","Wrapper","subscribeRoot","useCallback","contextName","Component","params","timeToCleanState","recordKey","current","rest","nextDelete","counter","keepUntil","k1","k2","t","_","paramKey","createAutoCtx","Root","timeToClean","subscribe","useQuickSubscribe","proxy","finalGetter","openGetter","clean","allKeys","allCompareValue","allUnsub","target","p","isOpenGetter","onChange","k","useHighlight","filterString","buildRegex","escapeRegex","str","words","flags","pattern","markByToken","text","regex","last","match","m","start","highlightCtx","React","HightlightWrapper","children","highlight","HighlightString","useContext","render","DataViewDefault","renderString","error","StateLabelRender","selectedKey","setKey","currentKey","props","divRef","flashKeyDebounce","jsxs","DevToolState","setKeys","setFilterString","filterFn","preFilter","sLow","token","ev","StateView","dataKey","currentData","setCurrentData","updateDataDebounce","changeKey","newData","DevToolContainer","toggleButton","active","setActive"],"mappings":";;AACO,SAASA,EACdC,GACAC,GACsD;AACtD,MAAIC,IAAgD,MAEhDC,IAAiC,YAAaC,GAA2B;AAC3E,IAAIF,KACF,aAAaA,CAAO,GAEtBA,IAAU,WAAW,MAAM;AACzB,MAAAF,EAAK,GAAGI,CAAI;AAAA,IACd,GAAGH,CAAI;AAAA,EACT;AAEA,SAAAE,EAAG,SAAS,MAAM,aAAaD,CAAQ,GAEhCC;AACT;AAGO,SAASE,EACdL,GACqF;AAErF,QAAMM,wBAAY,IAAA,GAEZC,IAAkB,YAAaH,GAAoC;AACvE,UAAMI,IAAM,KAAK,UAAUJ,CAAI;AAC/B,QAAIE,EAAM,IAAIE,CAAG;AACf,aAAOF,EAAM,IAAIE,CAAG;AAEtB,UAAMC,IAAST,EAAK,GAAGI,CAAI;AAC3B,WAAAE,EAAM,IAAIE,GAAKC,CAAM,GACdA;AAAA,EACT;AAEA,SAAAF,EAAW,QAAQD,GAEZC;AACT;ACtCA,MAAMG,IAAa,MAAM,KAAK,OAAA,EAAS,SAAA,EAAW,MAAM,CAAC,GAgB5CC,IAAe,CAAC,MAAqB;AAEhD,QAAM,EAAE,SAAS,EAAE,cAAAC,EAAA,EAAa,IAAMC,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQ3C,IAAI,eAAe;AACjB,UAAIC,IAAuB,CAAA,GACvBC,IAAcL,EAAA;AAClB,aAAO,CAACM,MAAa;AACnB,YAAIC,IAAS;AAGb,eAAAA,IAASA,KAAY,CAACD,KAAO,CAACF,GAC9BG,IAASA,KAAWD,GAAG,UAAUF,GAAe,QAChDG,IAASA,KAAWD,EAAE,KAAK,CAACE,GAAG,MAA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V,GAAK,MAAM;AAE/D,SAAAE,EAAU,MAAM;AACZ,QAAI4H,IAAqB9J,EAAS6J,GAAgB,CAAC;AACnD,WAAO7H,EACF,aAAa,CAAC+H,GAAWC,MAAYF,EAAmB,EAAE,GAAGE,EAAA,CAAS,CAAC;AAAA,EAEhF,GAAG,CAAChI,CAAG,CAAC,GAED,gBAAAmC;AAAA,IAACc;AAAA,IAAA;AAAA,MACJ,OAAO2E;AAAA,MACP,MAAMD;AAAA,IAAA;AAAA,EAAA;AAEd,GCvEaM,KAAmB,CAAC,EAAE,cAAAC,IAAe,OAAO,WAAAjF,IAAYsD,GAAiB,GAAGO,QAAY;AACjG,QAAM,CAACqB,GAAQC,CAAS,IAAI1H,EAAS,EAAK;AAC1C,SAAO,gBAAAuG,EAAA7E,GAAA,EACH,UAAA;AAAA,IAAA,gBAAAD,EAAC,UAAA,EAAO,WAAU,uBAAsB,eAAagG,GAAQ,SAAS,MAAMC,EAAU,EAAI,GAAI,GAAGtB,GAC5F,UAAAA,GAAO,YAAY,mBACxB;AAAA,IACA,gBAAAG,EAAC,OAAA,EAAI,WAAU,6BAA4B,eAAakB,GACpD,UAAA;AAAA,MAAA,gBAAAhG,EAAC,UAAA,EAAO,WAAU,aAAY,SAAS,MAAMiG,EAAU,EAAK,GAAG,UAAA,MAAA,CAE/D;AAAA,MACCD,KAAU,gBAAAhG,EAAC+E,GAAA,EAAa,WAAAjE,EAAA,CAAsB;AAAA,IAAA,EAAA,CACnD;AAAA,EAAA,GACJ;AACJ;"}
1
+ {"version":3,"file":"index.es.js","sources":["../node_modules/react/cjs/react-compiler-runtime.production.js","../node_modules/react/cjs/react-compiler-runtime.development.js","../node_modules/react/compiler-runtime.js","../src/state-utils/utils.ts","../src/state-utils/useArrayHash.ts","../src/state-utils/ctx.ts","../src/state-utils/createRootCtx.tsx","../src/state-utils/paramsToId.tsx","../src/state-utils/createAutoCtx.tsx","../src/state-utils/useQuickSubscribe.ts","../src/dev-tool/useHighlight.tsx","../src/dev-tool/DataViewComponent.tsx","../src/dev-tool/StateLabelRender.tsx","../src/dev-tool/DevToolState.tsx","../src/dev-tool/DevTool.tsx"],"sourcesContent":["/**\n * @license React\n * react-compiler-runtime.production.js\n *\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n\"use strict\";\nvar ReactSharedInternals =\n require(\"react\").__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;\nexports.c = function (size) {\n return ReactSharedInternals.H.useMemoCache(size);\n};\n","/**\n * @license React\n * react-compiler-runtime.development.js\n *\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n\"use strict\";\n\"production\" !== process.env.NODE_ENV &&\n (function () {\n var ReactSharedInternals =\n require(\"react\").__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;\n exports.c = function (size) {\n var dispatcher = ReactSharedInternals.H;\n null === dispatcher &&\n console.error(\n \"Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\\n1. You might have mismatching versions of React and the renderer (such as React DOM)\\n2. You might be breaking the Rules of Hooks\\n3. You might have more than one copy of React in the same app\\nSee https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.\"\n );\n return dispatcher.useMemoCache(size);\n };\n })();\n","/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/react-compiler-runtime.production.js');\n} else {\n module.exports = require('./cjs/react-compiler-runtime.development.js');\n}\n","// Debounce function\nexport function debounce<T extends (...args: any[]) => any>(\n func: T,\n wait: number\n): ((...args: Parameters<T>) => void) & { cancel: any } {\n let timeout: ReturnType<typeof setTimeout> | null = null;\n\n let fn: Function & { cancel: any } = function (...args: Parameters<T>): void {\n if (timeout) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(() => {\n func(...args);\n }, wait);\n } as any;\n\n fn.cancel = () => clearTimeout(timeout!);\n\n return fn as any;\n}\n\n// Memoize function\nexport function memoize<T extends (...args: any[]) => any>(\n func: T\n): ((...args: Parameters<T>) => ReturnType<T>) & { cache: Map<string, ReturnType<T>> } {\n \n const cache = new Map<string, ReturnType<T>>();\n\n const cachedFunc: any = function (...args: Parameters<T>): ReturnType<T> {\n const key = JSON.stringify(args);\n if (cache.has(key)) {\n return cache.get(key) as ReturnType<T>;\n }\n const result = func(...args);\n cache.set(key, result);\n return result;\n }\n\n cachedFunc.cache = cache;\n\n return cachedFunc\n}\n\n","import { useRef } from \"react\"\n\n\nconst randomHash = () => Math.random().toString().slice(2)\n\n/**\n * useArrayHash\n *\n * A custom hook that computes a stable hash for an array of values.\n * The hash changes only when the array's contents differ from the previous call.\n *\n * @param e - The input array to hash.\n * @returns A string hash that updates when the array changes.\n *\n * How it works:\n * - Tracks the previous array and its hash using a `useRef`.\n * - Compares the new array to the previous one by length and element equality.\n * - If any difference is detected, generates a new random hash.\n */\nexport const useArrayHash = (e: any[]): string => {\n\n const { current: { computedHash } } = useRef({\n /**\n * Getter for the computed hash function.\n *\n * - Initializes with an empty array and a random hash.\n * - Returns a function that compares the current array to the previous one.\n * - Updates the hash if any difference is detected.\n */\n get computedHash() {\n let currentValues: any[] = []\n let currentHash = randomHash()\n return (e: any[]) => {\n let isDiff = false\n\n // Check for differences in array existence, length, or elements.\n isDiff = isDiff || ((!e) != (!currentValues))\n isDiff = isDiff || (e?.length != currentValues?.length);\n isDiff = isDiff || (e.some((f, i) => f != currentValues[i]));\n\n // Update the hash if differences are found.\n currentValues = e;\n if (isDiff) {\n currentHash = randomHash()\n }\n\n return currentHash\n }\n }\n })\n\n return computedHash(e)\n}","import { debounce, memoize } from \"./utils\";\nimport { useEffect, useMemo, useState } from \"react\"\nimport { useArrayHash } from \"./useArrayHash\"\n\n\n\nconst CHANGE_EVENT = \"@--change-event\"\n\nclass DataEvent<D> extends Event {\n constructor(\n public event: keyof D,\n public value: D[typeof event] | undefined\n ) {\n super(String(event));\n }\n}\n\nclass ChangeEvent<D> extends Event {\n constructor(\n public value: DataEvent<D>\n ) {\n super(CHANGE_EVENT, value);\n }\n}\n\n/**\n * Generic context for managing shared state and event subscriptions.\n * @template D - The shape of the data managed by the context.\n */\nexport class Context<D> extends EventTarget {\n /**\n * Create a new Context instance.\n * @param name - The name of the context (for debugging).\n */\n constructor(public name: string) {\n console.log(\"[CONTEXT] %s\", name)\n // this.event.setMaxListeners(100)\n super();\n }\n\n /**\n * The current data held by the context.\n */\n public data: Partial<D> = {}\n /**\n * Registry for tracking active keys (for duplicate detection).\n */\n public registry = new Set<string>()\n\n public useCounter = 0\n\n /**\n * Publish a value to the context and notify subscribers if it changed.\n * @param key - The key to update.\n * @param value - The new value.\n */\n public publish(key: keyof D, value: D[typeof key] | undefined) {\n\n if (value != this.data[key]) {\n this.data[key] = value\n let event = new DataEvent(key, value);\n this.dispatchEvent(event);\n this.dispatchEvent(new ChangeEvent(event))\n }\n }\n\n /**\n * Subscribe to changes for a specific key in the context.\n * @param key - The key to subscribe to.\n * @param _listener - Callback invoked with the new value.\n * @returns Unsubscribe function.\n */\n public subscribe(key: keyof D, _listener: (e: D[typeof key] | undefined) => void) {\n\n const listener = ({ event, value }: any) => {\n _listener(value)\n }\n\n this.addEventListener(String(key), listener)\n // console.log(\"listenerCount:\", String(key), this.event.listenerCount(String(key)))\n\n if (key in this.data) _listener(this.data[key])\n\n return () => this.removeEventListener(String(key), listener)\n }\n\n public subscribeAll(_listener: (changeKey: keyof D, newData: Partial<D>) => void) {\n\n const listener = (event: any) => {\n if (event instanceof ChangeEvent) {\n const { value: data } = event\n _listener(data.event as any as keyof D, this.data)\n }\n }\n\n this.addEventListener(String(CHANGE_EVENT), listener)\n\n return () => this.removeEventListener(String(CHANGE_EVENT), listener)\n\n }\n\n}\n\n/**\n * Get or create a memoized Context instance by name.\n * @param name - The context name.\n * @returns The Context instance.\n */\nexport const getContext = memoize((name: string) => new Context<any>(name))\n\n/**\n * Type alias for a function that returns a Context instance.\n */\nexport type getContext<D> = (e: string) => Context<D>\n\n/**\n * React hook to get a typed Context instance by name.\n * @param name - The context name.\n * @returns The Context instance.\n */\nexport const useDataContext = <D>(name: string = \"noname\") => {\n const ctx = useMemo(() => getContext(name), [name])\n useEffect(() => {\n ctx.useCounter += 1;\n return () => {\n ctx.useCounter -= 1;\n if (ctx.useCounter <= 0) {\n setTimeout(() => {\n if (ctx.useCounter <= 0) {\n getContext.cache.delete(JSON.stringify([name]))\n }\n }, 100)\n }\n }\n }, [ctx])\n\n return ctx as any as Context<D>\n}\n\n/**\n * Internal hook to check for duplicate registry entries in a context.\n * Warns if any of the provided names are already registered.\n * @param ctx - The context instance.\n * @param names - Names to check and register.\n */\nconst useRegistryChecker = (ctx: Context<any> | undefined, ...names: string[]) => {\n // return;\n const stack = new Error(\"[ctx] useRegistryChecker failed \" + JSON.stringify({ names, ctx: ctx?.name ?? 'undefined' }))\n\n useEffect(\n () => {\n if (ctx) {\n if (names.some(name => ctx.registry.has(name))) {\n console.error(stack)\n }\n names.forEach(e => ctx.registry.add(e))\n\n // console.debug(\"[ctx] %s%s add datasource\", componentId, ctx.name, names)\n return () => {\n // console.debug(\"[ctx] %s %s remove datasource\", componentId, ctx.name, names)\n\n names.forEach(e => ctx.registry.delete(e))\n }\n }\n },\n [ctx, names.length]\n )\n\n}\n\n/**\n * React hook to publish a value to the context when it changes.\n * @param ctx - The context instance.\n * @param key - The key to update.\n * @param value - The new value.\n */\nexport const useDataSource = <D, K extends keyof D>(ctx: Context<D> | undefined, key: K, value: D[K] | undefined) => {\n //@ts-check\n useEffect(() => {\n if (ctx && ctx.data[key] != value) {\n\n ctx.publish(key, value)\n }\n }, [key, value, ctx])\n\n useRegistryChecker(ctx, key as any)\n}\n\n/**\n * React hook to subscribe to a context value, with optional debounce.\n * @param ctx - The context instance.\n * @param key - The key to subscribe to.\n * @param debounceTime - Debounce time in ms (default 0).\n * @returns The current value for the key.\n */\nexport const useDataSubscribe = <D, K extends keyof D>(ctx: Context<D> | undefined, key: K, debounceTime = 0): D[K] | undefined => {\n //@ts-check\n const [{ value }, setState] = useState(() => ({ value: ctx?.data?.[key] }))\n\n useEffect(() => {\n if (ctx) {\n let callback = debounceTime == 0\n ? (value: any) => setState({ value } as any)\n : debounce((value: any) => setState({ value } as any), debounceTime)\n let unsub = ctx.subscribe(key, callback)\n value != ctx.data[key] && setState({ value: ctx.data[key] })\n return () => {\n unsub()\n }\n }\n }, [key, ctx])\n\n return ctx?.data[key]\n}\n\n/**\n * React hook to subscribe to a context value and transform it before returning.\n * @param ctx - The context instance.\n * @param key - The key to subscribe to.\n * @param transform - Function to transform the value.\n * @returns The transformed value.\n */\nexport const useDataSubscribeWithTransform = <D, K extends keyof D, E>(ctx: Context<D> | undefined, key: K, transform: (e: D[K] | undefined) => E): E => {\n const [, setState] = useState(0)\n const result = useMemo(\n () => transform(ctx?.data[key]),\n [transform, ctx?.data[key]]\n )\n\n useEffect(() => {\n if (ctx) {\n let preValue = result\n let callback = () => {\n let newValue = transform(ctx.data[key])\n if (newValue != preValue) {\n preValue = newValue;\n setState(e => e + 1)\n };\n }\n let unsub = ctx.subscribe(key, callback)\n callback();\n return () => unsub()\n }\n }, [key, ctx])\n\n return result\n}\n\n/**\n * React hook to publish multiple values to the context.\n * @param ctx - The context instance.\n * @param entries - Array of [key, value] pairs to update.\n */\nexport const useDataSourceMultiple = <D, T extends readonly (keyof D)[]>(\n ctx: Context<D> | undefined,\n ...entries: { -readonly [P in keyof T]: [T[P], D[T[P]]] }\n) => {\n //@ts-check\n useEffect(() => {\n if (ctx) {\n for (let [key, value] of entries) {\n ctx.data[key] != value && ctx.publish(key, value)\n }\n }\n }, [ctx, useArrayHash(entries.flat())])\n\n useRegistryChecker(ctx, ...entries.map(e => e[0]) as any)\n\n}\n\n/**\n * React hook to subscribe to multiple context values.\n * @param ctx - The context instance.\n * @param keys - Keys to subscribe to.\n * @returns An object with the current values for the keys.\n */\nexport const useDataSubscribeMultiple = <D, K extends (keyof D)[]>(\n ctx: Context<D> | undefined,\n ...keys: K\n): { [i in keyof K]: D[K[i]] | undefined } => {\n const [, setCounter] = useState(0)\n\n const returnValues = keys.map(key => ctx?.data?.[key])\n\n useEffect(() => {\n if (ctx) {\n let prevValues = returnValues\n const callback = debounce(() => {\n let currentValues = keys.map(key => ctx?.data?.[key])\n if (keys.some((key, i) => prevValues[i] != currentValues[i])) {\n // console.log(\"DIFF\", keys.filter((e, i) => prevValues[i] != currentValues[i]))\n prevValues = currentValues\n setCounter(c => c + 1)\n }\n }, 1)\n\n let handles = keys.map(key => ctx.subscribe(key, callback))\n\n let firstCall = setTimeout(callback, 1);\n\n return () => {\n clearTimeout(firstCall)\n callback.cancel();\n handles.forEach(unsub => unsub())\n }\n\n }\n }, [ctx, ...keys])\n\n\n return Object\n .fromEntries(keys.map((key, index) => [key, returnValues[index]])) as any\n}\n\n/**\n * React hook to subscribe to multiple context values with throttling.\n * @param ctx - The context instance.\n * @param debounceTime - Debounce time in ms (default 50).\n * @param keys - Keys to subscribe to.\n * @returns Array of current values for the keys.\n */\nexport const useDataSubscribeMultipleWithDebounce = <D, K extends (keyof D)[]>(\n ctx: Context<D> | undefined,\n debounceTime = 50,\n ...keys: K\n): { [i in keyof K]: D[K[i]] | undefined } => {\n //@ts-check\n const [, setCounter] = useState(0)\n\n const returnValues = keys.map(key => ctx?.data?.[key])\n\n useEffect(() => {\n if (ctx) {\n let prevValues = returnValues\n const callback = debounce(() => {\n let currentValues = keys.map(key => ctx?.data?.[key])\n if (keys.some((key, i) => prevValues[i] != currentValues[i])) {\n prevValues = currentValues\n setCounter(c => c + 1)\n }\n }, debounceTime)\n\n let handles = keys.map(key => ctx.subscribe(key, callback))\n\n let firstCall = setTimeout(callback, 1);\n\n return () => {\n clearTimeout(firstCall)\n callback.cancel();\n handles.forEach(unsub => unsub())\n }\n\n }\n }, [ctx, ...keys])\n\n return returnValues as any\n}\n\n\n\n","import { useEffect, useMemo } from \"react\"\nimport { useDataContext, useDataSourceMultiple, type Context } from \"./ctx\"\n// import { debugObjTime } from \"./debugObjTime\"\n\n\n/**\n * createRootCtx\n *\n * Factory that creates a headless \"Root\" component and companion hooks for a context namespace.\n * It derives a unique context name from a base `name` and a props object `U`, then publishes\n * a computed state `V` (from `useFn`) to that context.\n *\n * Usage (manual mounting):\n * ```\n * const { Root, useCtxState } = createRootCtx('user-state', useUserState)\n * ...\n * // Mount exactly one Root per unique props combination\n * <Root userId={id} />\n * ...\n * // Read anywhere ,using the same props shape\n * const user = useCtxState({ userId: id })\n *```\n * Strict vs lenient consumers:\n * - useCtxStateStrict(props) throws if a matching Root is not mounted.\n * - useCtxState(props) logs an error (after 1s) instead of throwing.\n *\n * Multiple instances safety:\n * - Mounting more than one Root with the same resolved context name throws (guards accidental duplicates).\n *\n * Name resolution notes:\n * - The context name is built from `name` + sorted key/value pairs of `props` (U), joined by \"-\".\n * - Prefer stable, primitive props to avoid collisions; if you need automation, pair with `createAutoCtx` and\n * mount a single <AutoRootCtx Wrapper={ErrorBoundary} /> at the app root so you don't manually mount `Root`.\n */\nexport const createRootCtx = <U extends object, V extends object>(name: string, useFn: (e: U) => V) => {\n\n const getCtxName = (e: U) => [\n name,\n ...Object\n .entries(e ?? {})\n .sort((e, f) => e[0].localeCompare(f[0]))\n .flat()\n ].join(\"-\")\n\n const ctxMountedCheck = new Set<string>()\n\n const useRootState = (e: U) => {\n const state = useFn(e)\n const ctxName = getCtxName(e)\n const ctx = useDataContext<V>(ctxName)\n const stack = useMemo(() => new Error().stack, [])\n\n useDataSourceMultiple(\n ctx,\n ...Object.entries(state) as any\n )\n\n useEffect(() => {\n if (ctxMountedCheck.has(ctxName)) {\n const err = new Error(\"RootContext \" + ctxName + \" are mounted more than once\")\n err.stack = stack;\n throw err\n }\n ctxMountedCheck.add(ctxName)\n return () => { ctxMountedCheck.delete(ctxName) };\n })\n\n return state;\n }\n\n const Debug = ({ }) => <></>\n\n const RootState: React.FC<U> = (e: U) => {\n const state = useRootState(e);\n return <Debug {...e} {...state} />\n }\n\n useRootState.displayName = `useState[${name}]`\n RootState.displayName = `StateContainer[${name}]`\n Debug.displayName = `Debug[${name}]`\n\n return {\n name,\n getCtxName,\n useRootState,\n Root: RootState,\n /**\n * Strict consumer: throws if the corresponding Root for these props isn't mounted.\n * Use in development/tests to fail fast when wiring is incorrect.\n */\n useCtxStateStrict: (e: U): Context<V> => {\n const ctxName = getCtxName(e)\n\n const stack = useMemo(() => new Error().stack, [])\n\n useEffect(() => {\n if (!ctxMountedCheck.has(ctxName)) {\n const err = new Error(\"RootContext [\" + ctxName + \"] is not mounted\")\n err.stack = stack;\n throw err\n }\n }, [ctxName])\n\n return useDataContext<V>(ctxName)\n },\n /**\n * Lenient consumer: schedules a console.error if the Root isn't mounted instead of throwing.\n * Useful in production to avoid hard crashes while still surfacing misconfiguration.\n */\n useCtxState: (e: U): Context<V> => {\n const ctxName = getCtxName(e)\n\n const stack = useMemo(() => new Error().stack, [])\n\n useEffect(() => {\n if (!ctxMountedCheck.has(ctxName)) {\n const err = new Error(\"RootContext [\" + ctxName + \"] is not mounted\")\n err.stack = stack;\n let timeout = setTimeout(() => console.error(err), 1000)\n return () => clearTimeout(timeout)\n }\n }, [ctxMountedCheck.has(ctxName)])\n\n return useDataContext<V>(ctxName)\n }\n }\n}","\nexport const paramsToId = (params: any) => Object\n .keys(params ?? {})\n .toSorted()\n .map(key => key + '=' + params?.[key])\n .join(\"&\");\n","import { useEffect, useState, Fragment, useCallback, useMemo, Activity } from \"react\"\nimport { useDataContext, useDataSourceMultiple, useDataSubscribe, type Context } from \"./ctx\"\nimport { createRootCtx } from \"./createRootCtx\"\nimport { paramsToId } from \"./paramsToId\"\n\n\n\nconst DebugState = ({ }) => <></>\n\nconst StateRunner: React.FC<{ useStateFn: Function, params: any, debugging: boolean }> = ({ useStateFn, params, debugging }) => {\n const state = useStateFn(params)\n return debugging ? <DebugState {...state} /> : <></>\n}\n\n\n/**\n * Inline docs: createAutoCtx + AutoRootCtx\n *\n * Quick start\n * 1) Mount <AutoRootCtx /> ONCE near your app root. Provide a Wrapper that acts like an ErrorBoundary to isolate and log errors.\n * Example: <AutoRootCtx Wrapper={MyErrorBoundary} />\n *\n * 2) Create auto contexts from your root context factories:\n * ```\n * const { useCtxState: useTestCtxState } = createAutoCtx(createRootCtx('test-state', stateFn))\n * const { useCtxState: useOtherCtxState } = createAutoCtx(createRootCtx('other-state', otherFn))\n * ```\n * 3) Use them in components:\n * ```\n * const ctx = useTestCtxState({ userId })\n * const { property1, property2 } = useDataSubscribeMultiple(ctx,'property1','property2')\n * // No need to mount the Root returned by createRootCtx directly — AutoRootCtx manages it for you.\n * ```\n * Notes\n * - AutoRootCtx must be mounted before any useCtxState hooks created by createAutoCtx run.\n * - Wrapper should be an ErrorBoundary-like component that simply renders {children}; no extra providers or layout required.\n * - For each unique params object (by stable stringified key), AutoRootCtx ensures a corresponding Root instance is rendered.\n */\n\nexport const AutoRootCtx: React.FC<{ Wrapper?: React.FC<any>, debugging?: boolean }> = ({ Wrapper = Fragment, debugging = false }) => {\n\n const ctx = useDataContext<any>(\"auto-ctx\")\n\n const [state, setState] = useState<Record<string, {\n useStateFn: Function,\n params: any,\n // paramKey: string,\n counter: number,\n keepUntil?: number\n }>>({})\n\n\n const subscribeRoot = useCallback(\n (contextName: string, useStateFn: Function, params: any, timeToCleanState = 0) => {\n\n const recordKey = contextName + '?' + paramsToId(params)\n\n\n setState(state => ({\n ...state,\n [recordKey]: {\n ...state[recordKey] ?? { useStateFn, params },\n counter: (state[recordKey]?.counter ?? 0) + 1,\n keepUntil: undefined,\n useStateFn,\n }\n }))\n\n return () => setState(({ [recordKey]: current, ...rest }) => ({\n ...rest,\n ...(current?.counter > 1 || timeToCleanState > 0) ? {\n [recordKey]: {\n ...current,\n counter: current.counter - 1,\n keepUntil: current.counter > 1 ? undefined : (Date.now() + timeToCleanState),\n }\n } : {}\n }))\n\n },\n []\n )\n\n const nextDelete = useMemo(() => Object.entries(state)\n .filter(([, { counter, keepUntil }]) => counter <= 0 && keepUntil)\n .toSorted(([, { keepUntil: k1 = 0 }], [, { keepUntil: k2 = 0 }]) => k1 - k2)\n ?.at(0),\n [state]\n )\n\n useEffect(() => {\n if (nextDelete) {\n const [key, { keepUntil }] = nextDelete\n if (typeof keepUntil == 'undefined')\n throw new Error(\"Invalid state mgr\")\n\n let t = setTimeout(() => {\n // console.log(\"Delay Cleaned\")\n setState(({ [key]: _, ...rest }) => rest)\n }, Math.max(0, keepUntil - Date.now()))\n return () => {\n // console.log(\"Cancel clean\")\n clearTimeout(t)\n };\n }\n }, [nextDelete])\n\n useDataSourceMultiple(ctx,\n [\"subscribe\", subscribeRoot],\n [\"state\", state],\n )\n\n return <>\n {Object\n .entries(state)\n .filter(([, { counter, keepUntil = 0 }]) => counter > 0 || keepUntil >= Date.now())\n .map(([key, { useStateFn, params }]) => <Wrapper key={key}>\n <StateRunner key={key} params={params} useStateFn={useStateFn} debugging={debugging} />\n </Wrapper>)}\n </>\n\n}\n\n/**\n * createAutoCtx\n *\n * Bridges a Root context (from createRootCtx) to the global AutoRootCtx renderer.\n * You do NOT mount the Root component yourself — just mount <AutoRootCtx /> once at the app root.\n *\n * Usage: \n * ```\n * const { useCtxState: useTestCtxState } = createAutoCtx(createRootCtx(\n * 'test-state', \n * stateFn\n * ))\n * const { useCtxState: useOtherCtxState } = createAutoCtx(createRootCtx(\n * 'other-state', \n * otherFn\n * ))\n * ```\n * \n * Then inside components:\n * ```\n * const ctxState = useTestCtxState({ any: 'params' })\n * ```\n * AutoRootCtx will subscribe/unsubscribe instances per unique params and render the appropriate Root under the hood.\n */\nexport const createAutoCtx = <U extends object, V extends object,>(\n { useRootState, getCtxName, name }: ReturnType<typeof createRootCtx<U, V>>,\n timeToClean = 0\n) => {\n\n return {\n\n useCtxState: (e: U): Context<V> => {\n\n const ctxName = getCtxName(e)\n\n const subscribe = useDataSubscribe(useDataContext<any>(\"auto-ctx\"), \"subscribe\")\n\n useEffect(\n () => subscribe?.(name, useRootState, e, timeToClean),\n [useRootState, subscribe, name, ctxName, timeToClean]\n )\n\n return useDataContext<V>(ctxName)\n }\n }\n}","\nimport { debounce } from \"./utils\";\nimport { useState, useMemo, useEffect } from \"react\";\nimport type { Context } from \"./ctx\";\n\n/**\n * useQuickSubscribe is a custom React hook for efficiently subscribing to specific properties of a context's data object.\n * \n * @template D - The shape of the context data.\n * @param {Context<D> | undefined} ctx - The context object containing data and a subscribe method.\n * @returns {Partial<D>} A proxy object that mirrors the context data, automatically subscribing to properties as they are accessed.\n *\n * This hook tracks which properties of the context data are accessed by the component and subscribes to updates for only those properties.\n * When any of the subscribed properties change, the hook triggers a re-render. Subscriptions are managed and cleaned up automatically\n * when the component unmounts or the context changes. This approach minimizes unnecessary re-renders and resource usage by only\n * subscribing to the data that the component actually uses.\n *\n * Example usage:\n * const {name} = useQuickSubscribe(userContext);\n * // Accessing name will subscribe to changes in 'name' only\n * return <div>{name}</div>;\n */\n\nexport const useQuickSubscribe = <D>(\n ctx: Context<D> | undefined\n): {\n [P in keyof D]?: D[P] | undefined;\n } => {\n\n const [, setCounter] = useState(0);\n\n const { proxy, finalGetter, openGetter, clean } = useMemo(\n () => {\n\n const allKeys = new Set<keyof D>()\n const allCompareValue: { [P in keyof D]?: D[P] | undefined; } = {}\n const allUnsub = new Map()\n\n const proxy = new Proxy(\n ctx?.data as any,\n {\n get(target, p) {\n if (isOpenGetter) {\n allKeys.add(p as keyof D)\n return allCompareValue[p as keyof D] = target[p];\n } else {\n throw new Error(\"now allow here\")\n }\n }\n }\n ) as any\n\n let isOpenGetter = true;\n\n\n let onChange = debounce(() => {\n if ([...allKeys.values()]\n .some(k => allCompareValue[k] != ctx?.data?.[k])) {\n setCounter(c => c + 1)\n }\n }, 0)\n\n let openGetter = () => {\n isOpenGetter = true\n allKeys.clear()\n }\n\n let finalGetter = () => {\n isOpenGetter = false;\n\n [...allKeys.values()]\n .filter(k => !allUnsub.has(k))\n .forEach(k => {\n allUnsub.set(k, ctx?.subscribe(k, onChange))\n });\n\n [...allUnsub.keys()]\n .filter(k => !allKeys.has(k))\n .forEach(k => {\n let unsub = allUnsub.get(k)\n unsub?.();\n allUnsub.delete(k);\n });\n\n }\n\n let clean = () => {\n openGetter();\n finalGetter();\n setCounter(c => c + 1)\n }\n\n return { proxy, finalGetter, openGetter, clean }\n },\n [ctx]\n )\n\n openGetter();\n\n setTimeout(finalGetter, 0)\n\n useEffect(\n () => () => clean(),\n [clean]\n )\n\n return proxy;\n\n\n};\n","import React, { useContext, useMemo } from \"react\";\n\nexport function useHighlight(filterString: string) {\n const highlight = useMemo(\n () => buildRegex(filterString\n .toLowerCase()\n .split(\" \"), 'gi'),\n [filterString]\n );\n return { highlight };\n}\n\nfunction escapeRegex(str: string) {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction buildRegex(words: string[], flags = 'gi') {\n const pattern = words.map(escapeRegex).join('|');\n return new RegExp(`(${pattern})`, flags);\n}\n\nfunction markByToken(text: string, regex: RegExp) {\n const result = [];\n let last = 0;\n for (const match of text.matchAll(regex)) {\n const [m] = match;\n const start = match.index;\n if (start > last) result.push(text.slice(last, start));\n result.push(<mark key={start}>{m}</mark>);\n last = start + m.length;\n }\n if (last < text.length) result.push(text.slice(last));\n return result;\n}\n\nconst highlightCtx = React.createContext<{ highlight?: RegExp }>({\n highlight: undefined\n})\n\nexport const HightlightWrapper: React.FC<{ highlight: string, children: any }> = ({ children, highlight }) => {\n return <highlightCtx.Provider value={useHighlight(highlight)}>\n {children}\n </highlightCtx.Provider>\n}\n\nexport const HighlightString: React.FC<{ text: string; }> = ({ text }) => {\n const { highlight } = useContext(highlightCtx)\n\n const render = useMemo(\n () => highlight ? markByToken(text, highlight) : text,\n [text, highlight]\n );\n\n return <>{render}</>;\n\n};\n","import React, { useMemo } from \"react\";\n\n\nexport type DataViewComponent = React.FC<{ value: any; name: string; }>;\n\nexport const DataViewDefault: DataViewComponent = ({ name, value }) => {\n\n const renderString = useMemo(() => {\n try {\n return JSON.stringify({ [name]: value }, null, 2);\n } catch (error) {\n return String(error);\n }\n }, [name, value]);\n\n return <pre>{renderString}</pre>;\n};\n","import React, { useRef, useEffect } from \"react\";\nimport { getContext } from \"../state-utils/ctx\";\nimport { debounce } from \"../state-utils/utils\";\nimport { HighlightString } from \"./useHighlight\";\n\nexport const StateLabelRender: React.FC<any> = ({ selectedKey, setKey, currentKey, highlight, ...props }) => {\n const ctx = getContext(currentKey);\n const divRef = useRef<HTMLDivElement>(undefined);\n\n useEffect(() => {\n if (divRef.current) {\n let flashKeyDebounce = debounce(() => {\n if (divRef.current) {\n divRef.current?.classList.add(\"state-key-updated\");\n requestAnimationFrame(() => divRef.current?.classList.remove(\"state-key-updated\"));\n }\n }, 5);\n return ctx.subscribeAll(flashKeyDebounce);\n }\n\n }, [ctx, divRef]);\n\n return <div\n ref={divRef}\n className=\"state-key\"\n title={currentKey}\n data-active={currentKey == selectedKey}\n onClick={() => setKey(currentKey)}\n {...props}\n >\n <div className=\"state-key-name\">\n <HighlightString text={String(currentKey)} />\n </div>\n <div className=\"state-key-meta\">\n {Object.keys(ctx.data).length} items\n </div>\n </div>;\n};\n","import React, { useEffect, useMemo, useState } from \"react\"\nimport { getContext } from \"../state-utils/ctx\"\nimport { debounce } from \"../state-utils/utils\"\nimport { HightlightWrapper } from \"./useHighlight\"\nimport { DataViewComponent, DataViewDefault } from \"./DataViewComponent\"\nimport { StateLabelRender } from \"./StateLabelRender\"\nimport \"./devTool.css\"\n\nconst cache = getContext.cache\n\nexport const DevToolState: React.FC<{ Component: DataViewComponent }> = ({ Component }) => {\n const [allKeys, setKeys] = useState(() => [...cache.keys()])\n const [filterString, setFilterString] = useState(\"\")\n const [selectedKey, setKey] = useState(\"\")\n\n useEffect(() => {\n let t = setInterval(() => {\n setKeys(k => k.length != cache.size\n ? [...cache.keys()]\n : k\n )\n }, 50)\n return () => clearInterval(t)\n }, [cache])\n\n const filterFn = useMemo(\n () => {\n const preFilter = filterString\n .toLowerCase()\n .split(\" \")\n return (e: string) => {\n const sLow = e.toLowerCase()\n return preFilter.every(token => sLow.includes(token))\n }\n },\n [filterString]\n )\n\n\n return <div className=\"main-panel\">\n <div className=\"state-list\">\n <input\n placeholder=\"Type to Filter ...\"\n className=\"state-filter\"\n value={filterString}\n onChange={(ev) => setFilterString(ev.target.value)}\n />\n <HightlightWrapper highlight={filterString}>\n {allKeys\n .map(e => JSON.parse(e)?.[0])\n .filter(e => e != \"auto-ctx\" && e)\n .filter(filterFn)\n .map(currentKey => <StateLabelRender key={currentKey} {...{ selectedKey, setKey, currentKey }} />)}\n </HightlightWrapper>\n\n </div>\n <div className=\"state-view\" >\n <StateView dataKey={selectedKey} key={selectedKey} Component={Component} />\n </div>\n </div>\n}\n\nexport const StateView: React.FC<{ dataKey: string, Component: DataViewComponent }> = ({ dataKey, Component = DataViewDefault }) => {\n const ctx = getContext(dataKey)\n const [currentData, setCurrentData] = useState({ ...ctx?.data })\n\n useEffect(() => {\n let updateDataDebounce = debounce(setCurrentData, 5)\n return ctx\n .subscribeAll((changeKey, newData) => updateDataDebounce({ ...newData }))\n\n }, [ctx])\n\n return <Component\n value={currentData}\n name={dataKey}\n />\n}\n","import \"./devTool.css\"\nimport { useState } from \"react\"\nimport { DevToolState } from \"./DevToolState\";\nimport { DataViewDefault } from \"./DataViewComponent\";\n\n\nexport const DevToolContainer = ({ toggleButton = \"[x]\", Component = DataViewDefault, ...props }) => {\n const [active, setActive] = useState(false);\n return <>\n <button className=\"react-state-dev-btn\" data-active={active} onClick={() => setActive(true)} {...props}>\n {props?.children ?? \"Toggle Dev Tool\"}\n </button>\n <div className=\"react-state-dev-container\" data-active={active}>\n <button className=\"close-btn\" onClick={() => setActive(false)}>\n [x]\n </button>\n {active && <DevToolState Component={Component} />}\n </div>\n </>\n}"],"names":["ReactSharedInternals","require$$0","reactCompilerRuntime_production","size","reactCompilerRuntime_development","dispatcher","compilerRuntimeModule","require$$1","debounce","func","wait","timeout","fn","args","clearTimeout","setTimeout","cancel","memoize","cache","Map","cachedFunc","key","JSON","stringify","has","get","result","set","randomHash","Math","random","toString","slice","useArrayHash","e","current","computedHash","useRef","currentValues","currentHash","isDiff","length","some","f","i","CHANGE_EVENT","DataEvent","Event","constructor","event","value","String","ChangeEvent","Context","EventTarget","name","console","log","data","registry","Set","useCounter","publish","dispatchEvent","subscribe","_listener","listener","addEventListener","removeEventListener","subscribeAll","getContext","useDataContext","ctx","useMemo","useEffect","delete","useRegistryChecker","t0","$","_c","names","t1","t2","t3","Error","stack","t4","error","forEach","add","e_0","t5","useDataSource","useDataSubscribe","debounceTime","undefined","setState","useState","callback","value_0","value_1","unsub","useDataSubscribeWithTransform","transform","preValue","newValue","useDataSourceMultiple","entries","flat","map","useDataSubscribeMultiple","keys","setCounter","returnValues","prevValues","key_0","key_1","_temp","handles","key_2","firstCall","_temp2","key_3","index","Object","fromEntries","useDataSubscribeMultipleWithDebounce","_temp3","_temp4","c","createRootCtx","useFn","getCtxName","sort","localeCompare","join","ctxMountedCheck","useRootState","state","ctxName","Symbol","for","err","Debug","jsx","Fragment","RootState","displayName","Root","useCtxStateStrict","useCtxState","paramsToId","params","toSorted","DebugState","StateRunner","useStateFn","debugging","AutoRootCtx","Wrapper","subscribeRoot","useCallback","contextName","timeToCleanState","recordKey","counter","keepUntil","rest","Date","now","nextDelete","filter","k1","k2","at","t","_","max","createAutoCtx","timeToClean","useQuickSubscribe","proxy","finalGetter","openGetter","clean","allKeys","allCompareValue","allUnsub","Proxy","target","p","isOpenGetter","onChange","values","k","clear","useHighlight","filterString","buildRegex","toLowerCase","split","highlight","escapeRegex","str","replace","words","flags","pattern","RegExp","markByToken","text","regex","last","match","matchAll","m","start","push","highlightCtx","React","createContext","HightlightWrapper","children","HighlightString","useContext","render","DataViewDefault","renderString","StateLabelRender","currentKey","props","selectedKey","setKey","divRef","flashKeyDebounce","classList","requestAnimationFrame","remove","t6","t7","t8","t9","jsxs","t10","DevToolState","Component","setKeys","setFilterString","setInterval","clearInterval","preFilter","sLow","every","token","includes","filterFn","ev","StateView","t11","dataKey","currentData","setCurrentData","updateDataDebounce","changeKey","newData","parse","e_1","DevToolContainer","toggleButton","active","setActive"],"mappings":";;;;;;;;;;;;;;;;AAWA,MAAIA,IACFC,EAAiB;AACnB,SAAAC,EAAA,IAAY,SAAUC,GAAM;AAC1B,WAAOH,EAAqB,EAAE,aAAaG,CAAI;AAAA,EACjD;;;;;;;;;;;;;;sBCJiB,QAAQ,IAAI,aAA7B,gBACG,WAAY;AACX,QAAIH,IACFC,EAAiB;AACnB,IAAAG,EAAA,IAAY,SAAUD,GAAM;AAC1B,UAAIE,IAAaL,EAAqB;AACtC,aAASK,MAAT,QACE,QAAQ;AAAA,QACN;AAAA;AAAA;AAAA;AAAA;AAAA,SAEGA,EAAW,aAAaF,CAAI;AAAA,IACzC;AAAA,EACA,EAAG;;;;sBCdC,QAAQ,IAAI,aAAa,eAC3BG,EAAA,UAAiBL,GAAA,IAEjBK,EAAA,UAAiBC,GAAA;;;ACXZ,SAASC,EACdC,GACAC,GACsD;AACtD,MAAIC,IAAgD,MAEhDC,IAAiC,YAAaC,GAA2B;AAC3E,IAAIF,KACFG,aAAaH,CAAO,GAEtBA,IAAUI,WAAW,MAAM;AACzBN,MAAAA,EAAK,GAAGI,CAAI;AAAA,IACd,GAAGH,CAAI;AAAA,EACT;AAEAE,SAAAA,EAAGI,SAAS,MAAMF,aAAaH,CAAQ,GAEhCC;AACT;AAGO,SAASK,GACdR,GACqF;AAErF,QAAMS,wBAAYC,IAAAA,GAEZC,IAAkB,YAAaP,GAAoC;AACvE,UAAMQ,IAAMC,KAAKC,UAAUV,CAAI;AAC/B,QAAIK,EAAMM,IAAIH,CAAG;AACf,aAAOH,EAAMO,IAAIJ,CAA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GACL,GAAMjK,QAAA+L,GAAA/L,QAAAiK,GAAAjK,QAAAkK,KAAAA,IAAAlK,EAAA,EAAA;AAAA,MAAAmK;AAAA,SAAAnK,EAAA,EAAA,MAAAa,KAAAb,UAAAkK,KATHC,2BACHtJ,UAAAA;AAAAA,IAAAA;AAAAA,IAGAqJ;AAAAA,EAAAA,GAKM,GACPlK,QAAAa,GAAAb,QAAAkK,GAAAlK,QAAAmK,KAAAA,IAAAnK,EAAA,EAAA,GAVImK;AAUJ;","x_google_ignoreList":[0,1,2]}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,22 @@
1
- (function(d,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime"],c):(d=typeof globalThis<"u"?globalThis:d||self,c(d.RState={},d.React,d.jsxRuntime))})(this,function(d,c,f){"use strict";function p(e,t){let s=null,r=function(...o){s&&clearTimeout(s),s=setTimeout(()=>{e(...o)},t)};return r.cancel=()=>clearTimeout(s),r}function L(e){const t=new Map,s=function(...r){const o=JSON.stringify(r);if(t.has(o))return t.get(o);const a=e(...r);return t.set(o,a),a};return s.cache=t,s}const N=()=>Math.random().toString().slice(2),T=e=>{const{current:{computedHash:t}}=c.useRef({get computedHash(){let s=[],r=N();return o=>{let a=!1;return a=a||!o!=!s,a=a||o?.length!=s?.length,a=a||o.some((n,i)=>n!=s[i]),s=o,a&&(r=N()),r}}});return t(e)},w="@--change-event";class H extends Event{constructor(t,s){super(String(t)),this.event=t,this.value=s}}class M extends Event{constructor(t){super(w,t),this.value=t}}class y extends EventTarget{constructor(t){console.log("[CONTEXT] %s",t),super(),this.name=t}data={};registry=new Set;useCounter=0;publish(t,s){if(s!=this.data[t]){this.data[t]=s;let r=new H(t,s);this.dispatchEvent(r),this.dispatchEvent(new M(r))}}subscribe(t,s){const r=({event:o,value:a})=>{s(a)};return this.addEventListener(String(t),r),t in this.data&&s(this.data[t]),()=>this.removeEventListener(String(t),r)}subscribeAll(t){const s=r=>{if(r instanceof M){const{value:o}=r;t(o.event,this.data)}};return this.addEventListener(String(w),s),()=>this.removeEventListener(String(w),s)}}const S=L(e=>new y(e)),m=(e="noname")=>{const t=c.useMemo(()=>S(e),[e]);return c.useEffect(()=>(t.useCounter+=1,()=>{t.useCounter-=1,t.useCounter<=0&&setTimeout(()=>{t.useCounter<=0&&S.cache.delete(JSON.stringify([e]))},100)}),[t]),t},k=(e,...t)=>{const s=new Error("[ctx] useRegistryChecker failed "+JSON.stringify({names:t,ctx:e?.name??"undefined"}));c.useEffect(()=>{if(e)return t.some(r=>e.registry.has(r))&&console.error(s),t.forEach(r=>e.registry.add(r)),()=>{t.forEach(r=>e.registry.delete(r))}},[e,t.length])},G=(e,t,s)=>{c.useEffect(()=>{e&&e.data[t]!=s&&e.publish(t,s)},[t,s,e]),k(e,t)},O=(e,t,s=0)=>{const[{value:r},o]=c.useState(()=>({value:e?.data?.[t]}));return c.useEffect(()=>{if(e){let a=s==0?i=>o({value:i}):p(i=>o({value:i}),s),n=e.subscribe(t,a);return r!=e.data[t]&&o({value:e.data[t]}),()=>{n()}}},[t,e]),e?.data[t]},U=(e,t,s)=>{const[,r]=c.useState(0),o=c.useMemo(()=>s(e?.data[t]),[s,e?.data[t]]);return c.useEffect(()=>{if(e){let a=o,n=()=>{let u=s(e.data[t]);u!=a&&(a=u,r(l=>l+1))},i=e.subscribe(t,n);return n(),()=>i()}},[t,e]),o},D=(e,...t)=>{c.useEffect(()=>{if(e)for(let[s,r]of t)e.data[s]!=r&&e.publish(s,r)},[e,T(t.flat())]),k(e,...t.map(s=>s[0]))},K=(e,...t)=>{const[,s]=c.useState(0),r=t.map(o=>e?.data?.[o]);return c.useEffect(()=>{if(e){let o=r;const a=p(()=>{let u=t.map(l=>e?.data?.[l]);t.some((l,h)=>o[h]!=u[h])&&(o=u,s(l=>l+1))},1);let n=t.map(u=>e.subscribe(u,a)),i=setTimeout(a,1);return()=>{clearTimeout(i),a.cancel(),n.forEach(u=>u())}}},[e,...t]),Object.fromEntries(t.map((o,a)=>[o,r[a]]))},W=(e,t=50,...s)=>{const[,r]=c.useState(0),o=s.map(a=>e?.data?.[a]);return c.useEffect(()=>{if(e){let a=o;const n=p(()=>{let l=s.map(h=>e?.data?.[h]);s.some((h,g)=>a[g]!=l[g])&&(a=l,r(h=>h+1))},t);let i=s.map(l=>e.subscribe(l,n)),u=setTimeout(n,1);return()=>{clearTimeout(u),n.cancel(),i.forEach(l=>l())}}},[e,...s]),o},J=(e,t)=>{const s=n=>[e,...Object.entries(n??{}).sort((i,u)=>i[0].localeCompare(u[0])).flat()].join("-"),r=new Set,o=({})=>f.jsx(f.Fragment,{}),a=n=>{const i=t(n),u=s(n),l=m(u),h=c.useMemo(()=>new Error().stack,[]);return D(l,...Object.entries(i)),c.useEffect(()=>{if(r.has(u)){const g=new Error("RootContext "+u+" are mounted more than once");throw g.stack=h,g}return r.add(u),()=>{r.delete(u)}}),f.jsx(o,{...n,...i})};return a.displayName=`StateContainer[${e}]`,o.displayName=`Debug[${e}]`,{name:e,resolveCtxName:s,Root:a,useCtxStateStrict:n=>{const i=s(n),u=c.useMemo(()=>new Error().stack,[]);return c.useEffect(()=>{if(!r.has(i)){const l=new Error("RootContext ["+i+"] is not mounted");throw l.stack=u,l}},[i]),m(i)},useCtxState:n=>{const i=s(n),u=c.useMemo(()=>new Error().stack,[]);return c.useEffect(()=>{if(!r.has(i)){const l=new Error("RootContext ["+i+"] is not mounted");l.stack=u;let h=setTimeout(()=>console.error(l),1e3);return()=>clearTimeout(h)}},[r.has(i)]),m(i)}}},$=function(){const e=new WeakMap;return t=>{let s=e.get(t);return s||e.set(t,s=(t?.name??"")+":"+Math.random().toString()),s}}(),j=e=>[...Object.entries(e??{}).sort((t,s)=>t[0].localeCompare(s[0])).flat()].join("-"),q=({Wrapper:e=c.Fragment})=>{const t=m("auto-ctx"),[s,r]=c.useState({}),o=c.useCallback((n,i,u,l=0)=>{const h=[n,$(i),j(u)].join(":");return r(g=>({...g,[h]:{...g[h]??{Component:i,params:u,paramKey:j(u)},counter:(g[h]?.counter??0)+1,keepUntil:void 0}})),()=>r(({[h]:g,...C})=>({...C,...g?.counter>1||l>0?{[h]:{...g,counter:g.counter-1,keepUntil:g.counter>1?void 0:Date.now()+l}}:{}}))},[]),a=c.useMemo(()=>Object.entries(s).filter(([,{counter:n,keepUntil:i}])=>n<=0&&i).toSorted(([,{keepUntil:n=0}],[,{keepUntil:i=0}])=>n-i)?.at(0),[s]);return console.log({state:s,nextDelete:a}),c.useEffect(()=>{if(a){const[n,{keepUntil:i}]=a;if(typeof i>"u")throw new Error("Invalid state mfr");let u=setTimeout(()=>{r(({[n]:l,...h})=>h)},Math.max(0,i-Date.now()));return()=>{clearTimeout(u)}}},[a]),D(t,["subscribe",o],["state",s]),f.jsx(f.Fragment,{children:Object.entries(s).filter(([,{counter:n,keepUntil:i=0}])=>n>0||i>=Date.now()).map(([n,{Component:i,params:u,counter:l,paramKey:h,keepUntil:g}])=>f.jsx(e,{children:f.jsx(i,{...u},h)},n))})},I=({Root:e,resolveCtxName:t,name:s},r=0)=>({useCtxState:o=>{const a=t(o),n=O(m("auto-ctx"),"subscribe");return c.useEffect(()=>n?.(s,e,o,r),[e,n,s,a,r]),m(a)}}),P=e=>{const[,t]=c.useState(0),{proxy:s,finalGetter:r,openGetter:o,clean:a}=c.useMemo(()=>{const n=new Set,i={},u=new Map,l=new Proxy(e?.data,{get(b,E){if(h)return n.add(E),i[E]=b[E];throw new Error("now allow here")}});let h=!0,g=p(()=>{[...n.values()].some(b=>i[b]!=e?.data?.[b])&&t(b=>b+1)},0),C=()=>{h=!0,n.clear()},F=()=>{h=!1,[...n.values()].filter(b=>!u.has(b)).forEach(b=>{u.set(b,e?.subscribe(b,g))}),[...u.keys()].filter(b=>!n.has(b)).forEach(b=>{u.get(b)?.(),u.delete(b)})};return{proxy:l,finalGetter:F,openGetter:C,clean:()=>{C(),F(),t(b=>b+1)}}},[e]);return o(),setTimeout(r,0),c.useEffect(()=>()=>a(),[a]),s};function z(e){return{highlight:c.useMemo(()=>Q(e.toLowerCase().split(" "),"gi"),[e])}}function B(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Q(e,t="gi"){const s=e.map(B).join("|");return new RegExp(`(${s})`,t)}function x(e,t){const s=[];let r=0;for(const o of e.matchAll(t)){const[a]=o,n=o.index;n>r&&s.push(e.slice(r,n)),s.push(f.jsx("mark",{children:a},n)),r=n+a.length}return r<e.length&&s.push(e.slice(r)),s}const A=c.createContext({highlight:void 0}),X=({children:e,highlight:t})=>f.jsx(A.Provider,{value:z(t),children:e}),_=({text:e})=>{const{highlight:t}=c.useContext(A),s=c.useMemo(()=>t?x(e,t):e,[e,t]);return f.jsx(f.Fragment,{children:s})},V=({name:e,value:t})=>{const s=c.useMemo(()=>{try{return JSON.stringify({[e]:t},null,2)}catch(r){return String(r)}},[e,t]);return f.jsx("pre",{children:s})},Y=({selectedKey:e,setKey:t,currentKey:s,highlight:r,...o})=>{const a=S(s),n=c.useRef(void 0);return c.useEffect(()=>{if(n.current){let i=p(()=>{n.current&&(n.current?.classList.add("state-key-updated"),requestAnimationFrame(()=>n.current?.classList.remove("state-key-updated")))},5);return a.subscribeAll(i)}},[a,n]),f.jsxs("div",{ref:n,className:"state-key",title:s,"data-active":s==e,onClick:()=>t(s),...o,children:[f.jsx("div",{className:"state-key-name",children:f.jsx(_,{text:String(s)})}),f.jsxs("div",{className:"state-key-meta",children:[Object.keys(a.data).length," items"]})]})},v=S.cache,Z=({Component:e})=>{const[t,s]=c.useState(()=>[...v.keys()]),[r,o]=c.useState(""),[a,n]=c.useState("");c.useEffect(()=>{let u=setInterval(()=>{s(l=>l.length!=v.size?[...v.keys()]:l)},50);return()=>clearInterval(u)},[v]);const i=c.useMemo(()=>{const u=r.toLowerCase().split(" ");return l=>{const h=l.toLowerCase();return u.every(g=>h.includes(g))}},[r]);return f.jsxs("div",{className:"main-panel",children:[f.jsxs("div",{className:"state-list",children:[f.jsx("input",{placeholder:"Type to Filter ...",className:"state-filter",value:r,onChange:u=>o(u.target.value)}),f.jsx(X,{highlight:r,children:t.map(u=>JSON.parse(u)?.[0]).filter(u=>u!="auto-ctx"&&u).filter(i).map(u=>f.jsx(Y,{selectedKey:a,setKey:n,currentKey:u}))})]}),f.jsx("div",{className:"state-view",children:f.jsx(R,{dataKey:a,Component:e},a)})]})},R=({dataKey:e,Component:t=V})=>{const s=S(e),[r,o]=c.useState({...s?.data});return c.useEffect(()=>{let a=p(o,5);return s.subscribeAll((n,i)=>a({...i}))},[s]),f.jsx(t,{value:r,name:e})},ee=({toggleButton:e="[x]",Component:t=V,...s})=>{const[r,o]=c.useState(!1);return f.jsxs(f.Fragment,{children:[f.jsx("button",{className:"react-state-dev-btn","data-active":r,onClick:()=>o(!0),...s,children:s?.children??"Toggle Dev Tool"}),f.jsxs("div",{className:"react-state-dev-container","data-active":r,children:[f.jsx("button",{className:"close-btn",onClick:()=>o(!1),children:"[x]"}),r&&f.jsx(Z,{Component:t})]})]})};d.AutoRootCtx=q,d.Context=y,d.DevToolContainer=ee,d.createAutoCtx=I,d.createRootCtx=J,d.getContext=S,d.useArrayHash=T,d.useDataContext=m,d.useDataSource=G,d.useDataSourceMultiple=D,d.useDataSubscribe=O,d.useDataSubscribeMultiple=K,d.useDataSubscribeMultipleWithDebounce=W,d.useDataSubscribeWithTransform=U,d.useQuickSubscribe=P,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
1
+ (function(S,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime"],h):(S=typeof globalThis<"u"?globalThis:S||self,h(S.RState={},S.React,S.jsxRuntime))})(this,function(S,h,p){"use strict";var R={exports:{}},H={};/**
2
+ * @license React
3
+ * react-compiler-runtime.production.js
4
+ *
5
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */var F;function Q(){if(F)return H;F=1;var n=h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;return H.c=function(e){return n.H.useMemoCache(e)},H}var K={};/**
10
+ * @license React
11
+ * react-compiler-runtime.development.js
12
+ *
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ */var U;function X(){return U||(U=1,process.env.NODE_ENV!=="production"&&function(){var n=h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;K.c=function(e){var t=n.H;return t===null&&console.error(`Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
18
+ 1. You might have mismatching versions of React and the renderer (such as React DOM)
19
+ 2. You might be breaking the Rules of Hooks
20
+ 3. You might have more than one copy of React in the same app
21
+ See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.`),t.useMemoCache(e)}}()),K}var I;function Z(){return I||(I=1,process.env.NODE_ENV==="production"?R.exports=Q():R.exports=X()),R.exports}var C=Z();function w(n,e){let t=null,s=function(...r){t&&clearTimeout(t),t=setTimeout(()=>{n(...r)},e)};return s.cancel=()=>clearTimeout(t),s}function x(n){const e=new Map,t=function(...s){const r=JSON.stringify(s);if(e.has(r))return e.get(r);const o=n(...s);return e.set(r,o),o};return t.cache=e,t}const j=()=>Math.random().toString().slice(2),G=n=>{const{current:{computedHash:e}}=h.useRef({get computedHash(){let t=[],s=j();return r=>{let o=!1;return o=o||!r!=!t,o=o||r?.length!=t?.length,o=o||r.some((l,c)=>l!=t[c]),t=r,o&&(s=j()),s}}});return e(n)},L="@--change-event";class q extends Event{constructor(e,t){super(String(e)),this.event=e,this.value=t}}class W extends Event{constructor(e){super(L,e),this.value=e}}class J extends EventTarget{constructor(e){console.log("[CONTEXT] %s",e),super(),this.name=e}data={};registry=new Set;useCounter=0;publish(e,t){if(t!=this.data[e]){this.data[e]=t;let s=new q(e,t);this.dispatchEvent(s),this.dispatchEvent(new W(s))}}subscribe(e,t){const s=({event:r,value:o})=>{t(o)};return this.addEventListener(String(e),s),e in this.data&&t(this.data[e]),()=>this.removeEventListener(String(e),s)}subscribeAll(e){const t=s=>{if(s instanceof W){const{value:r}=s;e(r.event,this.data)}};return this.addEventListener(String(L),t),()=>this.removeEventListener(String(L),t)}}const O=x(n=>new J(n)),T=(n="noname")=>{const e=h.useMemo(()=>O(n),[n]);return h.useEffect(()=>(e.useCounter+=1,()=>{e.useCounter-=1,e.useCounter<=0&&setTimeout(()=>{e.useCounter<=0&&O.cache.delete(JSON.stringify([n]))},100)}),[e]),e},P=(n,...e)=>{const t=C.c(12),s=e;let r;t[0]!==n?.name||t[1]!==s?(r=JSON.stringify({names:s,ctx:n?.name??"undefined"}),t[0]=n?.name,t[1]=s,t[2]=r):r=t[2];const o="[ctx] useRegistryChecker failed "+r;let l;t[3]!==o?(l=new Error(o),t[3]=o,t[4]=l):l=t[4];const c=l;let a;t[5]!==n||t[6]!==s||t[7]!==c?(a=()=>{if(n)return s.some(i=>n.registry.has(i))&&console.error(c),s.forEach(i=>n.registry.add(i)),()=>{s.forEach(i=>n.registry.delete(i))}},t[5]=n,t[6]=s,t[7]=c,t[8]=a):a=t[8];let u;t[9]!==n||t[10]!==s.length?(u=[n,s.length],t[9]=n,t[10]=s.length,t[11]=u):u=t[11],h.useEffect(a,u)},$=(n,e,t)=>{const s=C.c(5);let r,o;s[0]!==n||s[1]!==e||s[2]!==t?(r=()=>{n&&n.data[e]!=t&&n.publish(e,t)},o=[e,t,n],s[0]=n,s[1]=e,s[2]=t,s[3]=r,s[4]=o):(r=s[3],o=s[4]),h.useEffect(r,o),P(n,e)},Y=(n,e,t)=>{const s=C.c(11),r=t===void 0?0:t;let o;s[0]!==n?.data||s[1]!==e?(o=()=>({value:n?.data?.[e]}),s[0]=n?.data,s[1]=e,s[2]=o):o=s[2];const[l,c]=h.useState(o),{value:a}=l;let u;s[3]!==n||s[4]!==r||s[5]!==e||s[6]!==a?(u=()=>{if(n){const d=r==0?b=>c({value:b}):w(b=>c({value:b}),r),f=n.subscribe(e,d);return a!=n.data[e]&&c({value:n.data[e]}),()=>{f()}}},s[3]=n,s[4]=r,s[5]=e,s[6]=a,s[7]=u):u=s[7];let i;return s[8]!==n||s[9]!==e?(i=[e,n],s[8]=n,s[9]=e,s[10]=i):i=s[10],h.useEffect(u,i),n?.data[e]},ee=(n,e,t)=>{const[,s]=h.useState(0),r=h.useMemo(()=>t(n?.data[e]),[t,n?.data[e]]);return h.useEffect(()=>{if(n){let o=r,l=()=>{let a=t(n.data[e]);a!=o&&(o=a,s(u=>u+1))},c=n.subscribe(e,l);return l(),()=>c()}},[e,n]),r},V=(n,...e)=>{h.useEffect(()=>{if(n)for(let[t,s]of e)n.data[t]!=s&&n.publish(t,s)},[n,G(e.flat())]),P(n,...e.map(t=>t[0]))},te=(n,...e)=>{const t=C.c(18),s=e,[,r]=h.useState(0);let o;if(t[0]!==n?.data||t[1]!==s){let i;t[3]!==n?.data?(i=d=>n?.data?.[d],t[3]=n?.data,t[4]=i):i=t[4],o=s.map(i),t[0]=n?.data,t[1]=s,t[2]=o}else o=t[2];const l=o;let c;t[5]!==n||t[6]!==s||t[7]!==l||t[8]!==r?(c=()=>{if(n){let i=l;const d=w(()=>{const g=s.map(m=>n?.data?.[m]);s.some((m,v)=>i[v]!=g[v])&&(i=g,r(ne))},1),f=s.map(g=>n.subscribe(g,d)),b=setTimeout(d,1);return()=>{clearTimeout(b),d.cancel(),f.forEach(oe)}}},t[5]=n,t[6]=s,t[7]=l,t[8]=r,t[9]=c):c=t[9];let a;t[10]!==n||t[11]!==s?(a=[n,...s],t[10]=n,t[11]=s,t[12]=a):a=t[12],h.useEffect(c,a);let u;if(t[13]!==s||t[14]!==l){let i;t[16]!==l?(i=(d,f)=>[d,l[f]],t[16]=l,t[17]=i):i=t[17],u=Object.fromEntries(s.map(i)),t[13]=s,t[14]=l,t[15]=u}else u=t[15];return u},se=(n,e,...t)=>{const s=C.c(14),r=e===void 0?50:e,o=t,[,l]=h.useState(0);let c;if(s[0]!==n?.data||s[1]!==o){let d;s[3]!==n?.data?(d=f=>n?.data?.[f],s[3]=n?.data,s[4]=d):d=s[4],c=o.map(d),s[0]=n?.data,s[1]=o,s[2]=c}else c=s[2];const a=c;let u;s[5]!==n||s[6]!==r||s[7]!==o||s[8]!==a||s[9]!==l?(u=()=>{if(n){let d=a;const f=w(()=>{const m=o.map(v=>n?.data?.[v]);o.some((v,E)=>d[E]!=m[E])&&(d=m,l(ae))},r),b=o.map(m=>n.subscribe(m,f)),g=setTimeout(f,1);return()=>{clearTimeout(g),f.cancel(),b.forEach(re)}}},s[5]=n,s[6]=r,s[7]=o,s[8]=a,s[9]=l,s[10]=u):u=s[10];let i;return s[11]!==n||s[12]!==o?(i=[n,...o],s[11]=n,s[12]=o,s[13]=i):i=s[13],h.useEffect(u,i),a};function ne(n){return n+1}function oe(n){return n()}function ae(n){return n+1}function re(n){return n()}const ce=(n,e)=>{const t=c=>[n,...Object.entries(c??{}).sort((a,u)=>a[0].localeCompare(u[0])).flat()].join("-"),s=new Set,r=c=>{const a=C.c(5),u=e(c),i=t(c),d=T(i);let f;a[0]===Symbol.for("react.memo_cache_sentinel")?(f=new Error,a[0]=f):f=a[0];const b=f.stack;let g;a[1]!==u?(g=Object.entries(u),a[1]=u,a[2]=g):g=a[2],V(d,...g);let m;return a[3]!==i?(m=()=>{if(s.has(i)){const v=new Error("RootContext "+i+" are mounted more than once");throw v.stack=b,v}return s.add(i),()=>{s.delete(i)}},a[3]=i,a[4]=m):m=a[4],h.useEffect(m),u},o=c=>{const a=C.c(1);let u;return a[0]===Symbol.for("react.memo_cache_sentinel")?(u=p.jsx(p.Fragment,{}),a[0]=u):u=a[0],u},l=c=>{const a=C.c(3),u=r(c);let i;return a[0]!==c||a[1]!==u?(i=p.jsx(o,{...c,...u}),a[0]=c,a[1]=u,a[2]=i):i=a[2],i};return r.displayName=`useState[${n}]`,l.displayName=`StateContainer[${n}]`,o.displayName=`Debug[${n}]`,{name:n,getCtxName:t,useRootState:r,Root:l,useCtxStateStrict:c=>{const a=t(c),u=h.useMemo(()=>new Error().stack,[]);return h.useEffect(()=>{if(!s.has(a)){const i=new Error("RootContext ["+a+"] is not mounted");throw i.stack=u,i}},[a]),T(a)},useCtxState:c=>{const a=t(c),u=h.useMemo(()=>new Error().stack,[]);return h.useEffect(()=>{if(!s.has(a)){const i=new Error("RootContext ["+a+"] is not mounted");i.stack=u;let d=setTimeout(()=>console.error(i),1e3);return()=>clearTimeout(d)}},[s.has(a)]),T(a)}}},le=n=>Object.keys(n??{}).toSorted().map(e=>e+"="+n?.[e]).join("&"),ie=n=>{const e=C.c(1);let t;return e[0]===Symbol.for("react.memo_cache_sentinel")?(t=p.jsx(p.Fragment,{}),e[0]=t):t=e[0],t},ue=({useStateFn:n,params:e,debugging:t})=>{const s=n(e);return t?p.jsx(ie,{...s}):p.jsx(p.Fragment,{})},fe=({Wrapper:n=h.Fragment,debugging:e=!1})=>{const t=T("auto-ctx"),[s,r]=h.useState({}),o=h.useCallback((c,a,u,i=0)=>{const d=c+"?"+le(u);return r(f=>({...f,[d]:{...f[d]??{useStateFn:a,params:u},counter:(f[d]?.counter??0)+1,keepUntil:void 0,useStateFn:a}})),()=>r(({[d]:f,...b})=>({...b,...f?.counter>1||i>0?{[d]:{...f,counter:f.counter-1,keepUntil:f.counter>1?void 0:Date.now()+i}}:{}}))},[]),l=h.useMemo(()=>Object.entries(s).filter(([,{counter:c,keepUntil:a}])=>c<=0&&a).toSorted(([,{keepUntil:c=0}],[,{keepUntil:a=0}])=>c-a)?.at(0),[s]);return h.useEffect(()=>{if(l){const[c,{keepUntil:a}]=l;if(typeof a>"u")throw new Error("Invalid state mgr");let u=setTimeout(()=>{r(({[c]:i,...d})=>d)},Math.max(0,a-Date.now()));return()=>{clearTimeout(u)}}},[l]),V(t,["subscribe",o],["state",s]),p.jsx(p.Fragment,{children:Object.entries(s).filter(([,{counter:c,keepUntil:a=0}])=>c>0||a>=Date.now()).map(([c,{useStateFn:a,params:u}])=>p.jsx(n,{children:p.jsx(ue,{params:u,useStateFn:a,debugging:e},c)},c))})},de=({useRootState:n,getCtxName:e,name:t},s=0)=>({useCtxState:r=>{const o=e(r),l=Y(T("auto-ctx"),"subscribe");return h.useEffect(()=>l?.(t,n,r,s),[n,l,t,o,s]),T(o)}}),he=n=>{const[,e]=h.useState(0),{proxy:t,finalGetter:s,openGetter:r,clean:o}=h.useMemo(()=>{const l=new Set,c={},a=new Map,u=new Proxy(n?.data,{get(m,v){if(i)return l.add(v),c[v]=m[v];throw new Error("now allow here")}});let i=!0,d=w(()=>{[...l.values()].some(m=>c[m]!=n?.data?.[m])&&e(m=>m+1)},0),f=()=>{i=!0,l.clear()},b=()=>{i=!1,[...l.values()].filter(m=>!a.has(m)).forEach(m=>{a.set(m,n?.subscribe(m,d))}),[...a.keys()].filter(m=>!l.has(m)).forEach(m=>{a.get(m)?.(),a.delete(m)})};return{proxy:u,finalGetter:b,openGetter:f,clean:()=>{f(),b(),e(m=>m+1)}}},[n]);return r(),setTimeout(s,0),h.useEffect(()=>()=>o(),[o]),t};function me(n){const e=C.c(4);let t;e[0]!==n?(t=be(n.toLowerCase().split(" "),"gi"),e[0]=n,e[1]=t):t=e[1];const s=t;let r;return e[2]!==s?(r={highlight:s},e[2]=s,e[3]=r):r=e[3],r}function pe(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function be(n,e="gi"){const t=n.map(pe).join("|");return new RegExp(`(${t})`,e)}function ge(n,e){const t=[];let s=0;for(const r of n.matchAll(e)){const[o]=r,l=r.index;l>s&&t.push(n.slice(s,l)),t.push(p.jsx("mark",{children:o},l)),s=l+o.length}return s<n.length&&t.push(n.slice(s)),t}const z=h.createContext({highlight:void 0}),ve=n=>{const e=C.c(3),{children:t,highlight:s}=n,r=me(s);let o;return e[0]!==t||e[1]!==r?(o=p.jsx(z.Provider,{value:r,children:t}),e[0]=t,e[1]=r,e[2]=o):o=e[2],o},Se=n=>{const e=C.c(5),{text:t}=n,{highlight:s}=h.useContext(z);let r;e[0]!==s||e[1]!==t?(r=s?ge(t,s):t,e[0]=s,e[1]=t,e[2]=r):r=e[2];const o=r;let l;return e[3]!==o?(l=p.jsx(p.Fragment,{children:o}),e[3]=o,e[4]=l):l=e[4],l},B=n=>{const e=C.c(5),{name:t,value:s}=n;let r;try{let c;e[0]!==t||e[1]!==s?(c=JSON.stringify({[t]:s},null,2),e[0]=t,e[1]=s,e[2]=c):c=e[2],r=c}catch(c){r=String(c)}const o=r;let l;return e[3]!==o?(l=p.jsx("pre",{children:o}),e[3]=o,e[4]=l):l=e[4],l},Ce=n=>{const e=C.c(26);let t,s,r,o;if(e[0]!==n){const{selectedKey:N,setKey:y,currentKey:D,highlight:k,..._}=n;r=N,o=y,t=D,s=_,e[0]=n,e[1]=t,e[2]=s,e[3]=r,e[4]=o}else t=e[1],s=e[2],r=e[3],o=e[4];let l;e[5]!==t?(l=O(t),e[5]=t,e[6]=l):l=e[6];const c=l,a=h.useRef(void 0);let u,i;e[7]!==c?(u=()=>{if(a.current){const N=w(()=>{a.current&&(a.current?.classList.add("state-key-updated"),requestAnimationFrame(()=>a.current?.classList.remove("state-key-updated")))},5);return c.subscribeAll(N)}},i=[c,a],e[7]=c,e[8]=u,e[9]=i):(u=e[8],i=e[9]),h.useEffect(u,i);const d=t==r;let f;e[10]!==t||e[11]!==o?(f=()=>o(t),e[10]=t,e[11]=o,e[12]=f):f=e[12];const b=String(t);let g;e[13]!==b?(g=p.jsx("div",{className:"state-key-name",children:p.jsx(Se,{text:b})}),e[13]=b,e[14]=g):g=e[14];let m;e[15]!==c.data?(m=Object.keys(c.data),e[15]=c.data,e[16]=m):m=e[16];let v;e[17]!==m.length?(v=p.jsxs("div",{className:"state-key-meta",children:[m.length," items"]}),e[17]=m.length,e[18]=v):v=e[18];let E;return e[19]!==t||e[20]!==s||e[21]!==d||e[22]!==f||e[23]!==g||e[24]!==v?(E=p.jsxs("div",{ref:a,className:"state-key",title:t,"data-active":d,onClick:f,...s,children:[g,v]}),e[19]=t,e[20]=s,e[21]=d,e[22]=f,e[23]=g,e[24]=v,e[25]=E):E=e[25],E},A=O.cache,Ee=n=>{const e=C.c(27),{Component:t}=n,[s,r]=h.useState(Ne),[o,l]=h.useState(""),[c,a]=h.useState("");let u,i;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{const _=setInterval(()=>{r(ye)},50);return()=>clearInterval(_)},i=[A],e[0]=u,e[1]=i):(u=e[0],i=e[1]),h.useEffect(u,i);let d;e[2]!==o?(d=o.toLowerCase().split(" "),e[2]=o,e[3]=d):d=e[3];const f=d;let b;e[4]!==f?(b=_=>{const M=_.toLowerCase();return f.every(Oe=>M.includes(Oe))},e[4]=f,e[5]=b):b=e[5];const g=b;let m;e[6]===Symbol.for("react.memo_cache_sentinel")?(m=_=>l(_.target.value),e[6]=m):m=e[6];let v;e[7]!==o?(v=p.jsx("input",{placeholder:"Type to Filter ...",className:"state-filter",value:o,onChange:m}),e[7]=o,e[8]=v):v=e[8];let E;if(e[9]!==s||e[10]!==g||e[11]!==c){let _;e[13]!==c?(_=M=>p.jsx(Ce,{selectedKey:c,setKey:a,currentKey:M},M),e[13]=c,e[14]=_):_=e[14],E=s.map(De).filter(Te).filter(g).map(_),e[9]=s,e[10]=g,e[11]=c,e[12]=E}else E=e[12];let N;e[15]!==o||e[16]!==E?(N=p.jsx(ve,{highlight:o,children:E}),e[15]=o,e[16]=E,e[17]=N):N=e[17];let y;e[18]!==v||e[19]!==N?(y=p.jsxs("div",{className:"state-list",children:[v,N]}),e[18]=v,e[19]=N,e[20]=y):y=e[20];let D;e[21]!==t||e[22]!==c?(D=p.jsx("div",{className:"state-view",children:p.jsx(_e,{dataKey:c,Component:t},c)}),e[21]=t,e[22]=c,e[23]=D):D=e[23];let k;return e[24]!==D||e[25]!==y?(k=p.jsxs("div",{className:"main-panel",children:[y,D]}),e[24]=D,e[25]=y,e[26]=k):k=e[26],k},_e=n=>{const e=C.c(11),{dataKey:t,Component:s}=n,r=s===void 0?B:s;let o;e[0]!==t?(o=O(t),e[0]=t,e[1]=o):o=e[1];const l=o,c=l?.data;let a;e[2]!==c?(a={...c},e[2]=c,e[3]=a):a=e[3];const[u,i]=h.useState(a);let d,f;e[4]!==l?(d=()=>{const g=w(i,5);return l.subscribeAll((m,v)=>g({...v}))},f=[l],e[4]=l,e[5]=d,e[6]=f):(d=e[5],f=e[6]),h.useEffect(d,f);let b;return e[7]!==r||e[8]!==u||e[9]!==t?(b=p.jsx(r,{value:u,name:t}),e[7]=r,e[8]=u,e[9]=t,e[10]=b):b=e[10],b};function Ne(){return[...A.keys()]}function ye(n){return n.length!=A.size?[...A.keys()]:n}function De(n){return JSON.parse(n)?.[0]}function Te(n){return n!="auto-ctx"&&n}const we=n=>{const e=C.c(19);let t,s,r;e[0]!==n?({toggleButton:s,Component:r,...t}=n,e[0]=n,e[1]=t,e[2]=s,e[3]=r):(t=e[1],s=e[2],r=e[3]);const o=r===void 0?B:r,[l,c]=h.useState(!1);let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=()=>c(!0),e[4]=a):a=e[4];const u=t?.children??"Toggle Dev Tool";let i;e[5]!==l||e[6]!==t||e[7]!==u?(i=p.jsx("button",{className:"react-state-dev-btn","data-active":l,onClick:a,...t,children:u}),e[5]=l,e[6]=t,e[7]=u,e[8]=i):i=e[8];let d;e[9]===Symbol.for("react.memo_cache_sentinel")?(d=p.jsx("button",{className:"close-btn",onClick:()=>c(!1),children:"[x]"}),e[9]=d):d=e[9];let f;e[10]!==o||e[11]!==l?(f=l&&p.jsx(Ee,{Component:o}),e[10]=o,e[11]=l,e[12]=f):f=e[12];let b;e[13]!==l||e[14]!==f?(b=p.jsxs("div",{className:"react-state-dev-container","data-active":l,children:[d,f]}),e[13]=l,e[14]=f,e[15]=b):b=e[15];let g;return e[16]!==i||e[17]!==b?(g=p.jsxs(p.Fragment,{children:[i,b]}),e[16]=i,e[17]=b,e[18]=g):g=e[18],g};S.AutoRootCtx=fe,S.Context=J,S.DevToolContainer=we,S.createAutoCtx=de,S.createRootCtx=ce,S.getContext=O,S.useArrayHash=G,S.useDataContext=T,S.useDataSource=$,S.useDataSourceMultiple=V,S.useDataSubscribe=Y,S.useDataSubscribeMultiple=te,S.useDataSubscribeMultipleWithDebounce=se,S.useDataSubscribeWithTransform=ee,S.useQuickSubscribe=he,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
2
22
  //# sourceMappingURL=index.umd.js.map