@mongez/react-atom
Version:
A simple state management tool for React Js.
1 lines • 26.5 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","names":[],"sources":["../../../../@mongez/react-atom/src/store.tsx","../../../../@mongez/react-atom/src/context.tsx","../../../../@mongez/react-atom/src/react-atom.tsx","../../../../@mongez/react-atom/src/helpers.ts","../../../../@mongez/react-atom/src/portal-atom.ts","../../../../@mongez/react-atom/src/ssr.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n AtomStore,\n type Atom,\n createAtomStore,\n} from \"@mongez/atom\";\nimport React, { createContext, useContext, useEffect, useState } from \"react\";\n\n/**\n * React context that holds the active atom store. Components that read or\n * write atoms via the React hooks resolve the store-scoped clone from this\n * context. When the context is null (no provider mounted), hooks fall back\n * to the module-level singleton atom, which is the right behavior for a\n * client-only SPA.\n */\nexport const AtomStoreContext = createContext<AtomStore | null>(null);\n\nexport type AtomStoreProviderProps = {\n /**\n * An existing store to use. If omitted, the provider creates its own\n * fresh store on first render. Pass an externally created store when you\n * need to mutate it outside React (e.g. during Next.js data loading).\n */\n store?: AtomStore;\n\n /**\n * Atom templates to pre-register in the store. Pre-registration is\n * required when you want the initial values from `initialValues` to apply\n * to atoms that have not yet been used in React.\n */\n initialAtoms?: Atom<any>[];\n\n /**\n * Initial values keyed by atom key. Applied silently (no update event)\n * so the first render of subscribers sees the hydrated value.\n *\n * If an atom in this map has not been pre-registered via `initialAtoms`\n * or used yet, its value is queued and applied the first time that atom\n * enters the store via a React hook.\n */\n initialValues?: Record<string, unknown>;\n\n children: React.ReactNode;\n};\n\n/**\n * Provider that scopes atom reads and writes to a request-local `AtomStore`.\n *\n * Wrap the root of your component tree (or any subtree) with this provider\n * to give that subtree its own isolated copy of every atom's state. This is\n * the supported pattern for SSR in Next.js, Remix, and TanStack Start —\n * each request creates its own store, so concurrent requests cannot see\n * each other's state.\n *\n * Without a provider, atoms fall back to the module-level singleton (the\n * historical client-only behavior).\n */\nexport function AtomStoreProvider({\n store,\n initialAtoms,\n initialValues,\n children,\n}: AtomStoreProviderProps) {\n const [activeStore] = useState<AtomStore>(() => {\n const next = store ?? createAtomStore();\n\n if (initialAtoms) {\n for (const atomTemplate of initialAtoms) {\n next.use(atomTemplate);\n }\n }\n\n if (initialValues) {\n next.hydrate(initialValues);\n }\n\n return next;\n });\n\n useEffect(() => {\n return () => {\n // Only auto-destroy stores that the provider itself created. Stores\n // passed in via props are owned by the caller.\n if (!store) {\n activeStore.destroy();\n }\n };\n }, [activeStore, store]);\n\n return (\n <AtomStoreContext.Provider value={activeStore}>\n {children}\n </AtomStoreContext.Provider>\n );\n}\n\n/**\n * Read the active atom store. Returns null when no `<AtomStoreProvider>` is\n * mounted in the tree above this component.\n */\nexport function useAtomStore(): AtomStore | null {\n return useContext(AtomStoreContext);\n}\n\n/**\n * Resolve an atom for the current render context.\n *\n * Two call shapes:\n *\n * - `useAtom(template)` — pass an atom you imported. Returns the\n * store-scoped clone if a `<AtomStoreProvider>` is mounted above; falls\n * back to the template itself otherwise. Use this when you need to call\n * action methods (`startLoading()`, `open()`, etc.) from event handlers\n * in an SSR-safe way.\n *\n * - `useAtom(key)` — pass a string key. Returns the scoped atom registered\n * under that key in the active store, or `undefined` when no provider is\n * mounted or the key has not entered the store. This is a legacy escape\n * hatch; prefer the template form.\n */\nexport function useAtom<V, A extends Record<string, any> = {}>(\n template: Atom<V, A>\n): Atom<V, A>;\nexport function useAtom<V = any>(key: string): Atom<V> | undefined;\nexport function useAtom(arg: Atom<any> | string): Atom<any> | undefined {\n const store = useContext(AtomStoreContext);\n if (typeof arg === \"string\") {\n return store?.get(arg);\n }\n return store ? store.use(arg) : arg;\n}\n","\"use client\";\n\nimport { type Atom } from \"@mongez/atom\";\nimport React from \"react\";\nimport { AtomStoreContext, AtomStoreProvider } from \"./store\";\n\n/**\n * @deprecated Re-export of `AtomStoreContext` from \"./store\". The context\n * value type changed from a key→atom record to an `AtomStore` instance; if\n * you only consumed this via `useAtom(key)` the migration is transparent.\n */\nexport const AtomContext = AtomStoreContext;\n\n/**\n * Backwards-compatible alias for `<AtomStoreProvider>`.\n *\n * Maps the legacy `register` (atoms to pre-clone) to `initialAtoms`, and\n * `defaultValue` (record of initial atom values) to `initialValues`.\n *\n * @deprecated Use `<AtomStoreProvider>` from \"./store\" directly.\n */\nexport function AtomProvider({\n register,\n defaultValue,\n children,\n}: {\n register?: Atom<any>[];\n defaultValue?: Record<string, unknown>;\n children: React.ReactNode;\n}) {\n return (\n <AtomStoreProvider initialAtoms={register} initialValues={defaultValue}>\n {children}\n </AtomStoreProvider>\n );\n}\n","\"use client\";\n/* eslint-disable react-hooks/rules-of-hooks */\nimport {\n type Atom,\n type AtomActions,\n type AtomCollectionActions,\n type AtomOptions,\n type AtomValue,\n atomCollection as baseAtomCollection,\n type CollectionOptions,\n createAtom,\n} from \"@mongez/atom\";\nimport {\n useCallback,\n useEffect,\n useSyncExternalStore,\n} from \"react\";\nimport { useAtom } from \"./store\";\nimport type { ReactActions, ReactAtom } from \"./types\";\n\n/**\n * Build the React-aware action bag injected into every atom created via\n * the `atom()` factory in this package.\n *\n * Every hook in here goes through `useAtom(this)` first so that\n * components rendered inside an `<AtomStoreProvider>` operate on the\n * store-scoped clone, not the module-level template.\n *\n * Subscriptions are wired through `useSyncExternalStore` to keep React 18+\n * concurrent rendering tear-free.\n */\nfunction reactActions<Value>(data: any): ReactActions<Value> {\n return {\n ...data.actions,\n\n Provider(props) {\n const atom = useAtom(this as unknown as Atom<Value>);\n useEffect(() => {\n atom.update(props.value as Value);\n }, [props.value, atom]);\n return props.children;\n },\n\n useWatch(key, callback) {\n const atom = useAtom(this as unknown as Atom<Value>);\n useEffect(() => {\n const sub = atom.watch(key, callback);\n return () => sub.unsubscribe();\n }, [atom, key, callback]);\n },\n\n useState() {\n const atom = useAtom(this as unknown as Atom<Value>);\n\n const subscribe = useCallback(\n (onChange: () => void) => {\n const sub = atom.onChange(onChange);\n return () => sub.unsubscribe();\n },\n [atom]\n );\n const getSnapshot = useCallback(() => atom.value, [atom]);\n\n const value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n const setValue = useCallback(\n (next: Value | ((oldValue: Value) => Value)) => {\n atom.update(next as any);\n },\n [atom]\n );\n\n return [value, setValue];\n },\n\n useValue() {\n const atom = useAtom(this as unknown as Atom<Value>);\n\n const subscribe = useCallback(\n (onChange: () => void) => {\n const sub = atom.onChange(onChange);\n return () => sub.unsubscribe();\n },\n [atom]\n );\n const getSnapshot = useCallback(() => atom.value, [atom]);\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n },\n\n use<K extends keyof Value>(key: K): Value[K] {\n const atom = useAtom(this as unknown as ReactAtom<Value>);\n\n const subscribe = useCallback(\n (onChange: () => void) => {\n const sub = atom.watch(key, onChange);\n return () => sub.unsubscribe();\n },\n [atom, key]\n );\n const getSnapshot = useCallback(\n () => atom.get(key),\n [atom, key]\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n },\n };\n}\n\n/**\n * Create a new React-aware atom.\n *\n * The returned atom carries hooks (`useState`, `useValue`, `use`, `useWatch`)\n * and a `<Provider>` component as instance methods. All hooks honor the\n * nearest `<AtomStoreProvider>` and use `useSyncExternalStore` underneath.\n */\nexport function atom<\n Value = any,\n Actions extends AtomActions<Value> = AtomActions<Value>,\n>(data: AtomOptions<AtomValue<Value>>): ReactAtom<Value, Actions> {\n return createAtom<Value, any>({\n ...data,\n actions: reactActions<Value>(data),\n });\n}\n\n/**\n * Create a React-aware collection atom for working with arrays.\n */\nexport function atomCollection<\n Value = any,\n Actions extends AtomCollectionActions<Value> = AtomCollectionActions<Value>,\n>(options: CollectionOptions<Value>) {\n return baseAtomCollection({\n ...options,\n actions: {\n ...options.actions,\n ...(reactActions(options) as any),\n } as AtomCollectionActions<Value[]> & Actions,\n });\n}\n","import { ReactNode } from \"react\";\nimport { atom } from \"./react-atom\";\nimport { ReactAtom } from \"./types\";\n\nexport type OpenAtomActions = {\n /**\n * Toggle open state\n */\n toggle: () => void;\n /**\n * Mark as opened\n */\n open: () => void;\n /**\n * Mark as closed\n */\n close: () => void;\n /**\n * Listen and get the opened state\n */\n useOpened: () => boolean;\n};\n\n/**\n * Open atom type\n */\nexport type OpenAtomType = {\n opened: boolean;\n} & OpenAtomActions;\n\n/**\n * Create a boolean atom\n */\nexport function openAtom(\n key: string,\n defaultOpened = false,\n): ReactAtom<boolean, OpenAtomActions> {\n return atom<boolean, OpenAtomActions>({\n key,\n default: defaultOpened,\n actions: {\n toggle() {\n this.update(!this.currentValue);\n },\n open() {\n this.update(true);\n },\n close() {\n this.update(false);\n },\n useOpened() {\n return (this as unknown as ReactAtom).useState()[0];\n },\n },\n });\n}\n\nexport type LoadingAtomActions = {\n /**\n * Start loading\n */\n startLoading: () => void;\n /**\n * Stop loading\n */\n stopLoading: () => void;\n /**\n * Toggle loading\n */\n toggleLoading: () => void;\n};\n\nexport type LoadingAtom = ReactAtom<boolean, LoadingAtomActions>;\n\n/**\n * Create a loading atom\n */\nexport function loadingAtom(key: string, defaultLoading = false) {\n const atomHandler = atom<boolean, LoadingAtomActions>({\n key,\n default: defaultLoading,\n actions: {\n startLoading() {\n this.update(true);\n },\n stopLoading() {\n this.update(false);\n },\n toggleLoading() {\n this.update(!this.currentValue);\n },\n },\n });\n\n return atomHandler;\n}\n\n/**\n * Fetching atom type\n */\nexport type FetchingAtomType<DataType, PaginationType> = {\n /**\n * Loading state\n */\n isLoading: boolean;\n /**\n * Fetched data\n */\n data: DataType | null;\n /**\n * Pagination data\n */\n pagination?: PaginationType;\n /**\n * Fetching error\n */\n error: any;\n};\n\nexport type FetchingAtomActions<DataType, PaginationType> = {\n /**\n * Start loading\n */\n startLoading: () => void;\n /**\n * Stop loading\n */\n stopLoading: () => void;\n /**\n * Mark data as fetched successfully, this will mark loading as false and set data\n */\n success: (data: DataType, pagination?: PaginationType) => void;\n /**\n * Mark data as fetched successfully, this will mark loading as false and set data\n */\n failed: (error: ReactNode) => void;\n /**\n * Used only with arrays, this will append data to the current data and mark loading as false\n */\n append: (data: DataType) => void;\n /**\n * Used only with arrays, this will prepend data to current data and mark loading as false\n */\n prepend: (data: DataType) => void;\n /**\n * Get and use loading state\n */\n useLoading: () => boolean;\n /**\n * Get and use data\n */\n useData: () => DataType | null;\n /**\n * Get and use error\n */\n useError: () => ReactNode;\n /**\n * Get and use pagination\n */\n usePagination: () => PaginationType | undefined;\n};\n\n/**\n * Create a fetching atom\n */\nexport function fetchingAtom<DataType = any, PaginationType = any>(\n key: string,\n defaultValue: DataType | null = null,\n defaultFetching = true,\n) {\n return atom<\n FetchingAtomType<DataType, PaginationType>,\n FetchingAtomActions<DataType, PaginationType>\n >({\n key,\n actions: {\n startLoading() {\n this.change(\"isLoading\", true);\n },\n stopLoading() {\n this.change(\"isLoading\", false);\n },\n useLoading() {\n return (this as unknown as ReactAtom).use(\"isLoading\");\n },\n useData() {\n return (this as unknown as ReactAtom).use(\"data\");\n },\n useError() {\n return (this as unknown as ReactAtom).use(\"error\");\n },\n usePagination() {\n return (this as unknown as ReactAtom).use(\"pagination\");\n },\n success(data, pagination?: PaginationType) {\n this.merge({\n isLoading: false,\n data,\n pagination,\n });\n },\n append(data: DataType) {\n const newData: any[] = [...(this.value.data as any), ...(data as any)];\n this.merge({\n isLoading: false,\n data: newData as DataType,\n });\n },\n prepend(data: DataType) {\n const newData: any[] = [...(data as any), ...(this.value.data as any)];\n this.merge({\n isLoading: false,\n data: newData as DataType,\n });\n },\n failed(error) {\n this.merge({\n isLoading: false,\n error,\n });\n },\n },\n default: {\n isLoading: defaultFetching,\n data: defaultValue,\n error: undefined,\n pagination: undefined,\n },\n });\n}\n","import { atom } from \"./react-atom\";\nimport { type ReactAtom } from \"./types\";\n\nexport type PortalActions<T = any> = {\n /**\n * Opens the portal with optional data.\n * @param data - Optional data to be passed when opening the portal.\n */\n open: (data?: T) => void;\n\n /**\n * Closes the portal.\n */\n close: () => void;\n\n /**\n * Toggles the portal's open state. If the portal is closed, it opens with optional data.\n * If the portal is open, it closes.\n * @param data - Optional data to be passed when opening the portal.\n */\n toggle: (data?: T) => void;\n\n /**\n * Hook to determine if the portal is currently open.\n * @returns A boolean indicating if the portal is open.\n */\n useOpened: () => boolean;\n\n /**\n * Hook to retrieve the current data associated with the portal.\n * @returns The data associated with the portal.\n */\n useData: () => T;\n};\n\ntype PortalData<T = any> = {\n opened: boolean;\n data: T;\n};\n\nexport type AtomPortal<T = any> = ReactAtom<PortalData<T>, PortalActions<T>>;\n\n/**\n * Create a portal atom\n * This atom is used to create a portal (a modal, a tooltip, a dropdown, etc.)\n */\nexport function portalAtom<T = any>(name: string, opened: boolean = false) {\n return atom<PortalData<T>, PortalActions<T>>({\n key: `${name}-portal`,\n default: {\n opened: opened,\n data: {} as T,\n },\n actions: {\n open(data?: T) {\n this.merge({\n opened: true,\n data,\n });\n },\n close() {\n this.change(\"opened\", false);\n },\n toggle(data?: T) {\n const opened = this.get(\"opened\");\n\n if (opened) {\n return this.change(\"opened\", false);\n }\n\n this.merge({\n opened: true,\n data,\n });\n },\n useOpened() {\n return (this as ReactAtom).use(\"opened\");\n },\n useData() {\n return (this as ReactAtom).use(\"data\");\n },\n },\n }) as AtomPortal<T>;\n}\n","/**\n * SSR helpers.\n *\n * These are framework-agnostic primitives for the standard SSR flow:\n *\n * server: store.snapshot() → serializeStore() → embed in HTML\n * client: readHydration() → <AtomStoreProvider initialValues={...}>\n *\n * They're intentionally small. Next.js App Router, Remix, and TanStack\n * Start each have their own preferred transport (`__NEXT_DATA__`, loader\n * payloads, streaming chunks); the helpers here only cover the \"vanilla\"\n * inline-script-tag transport. If your framework already has a typed\n * server-to-client payload (e.g. `useLoaderData()`), skip these helpers\n * and feed the snapshot straight into `<AtomStoreProvider initialValues>`.\n */\nimport type { AtomStore } from \"@mongez/atom\";\nimport React from \"react\";\n\n/**\n * The default DOM id used by {@link HydrateAtomsScript} and\n * {@link readHydration}. Override per-provider if you need to embed\n * multiple snapshots in one document.\n */\nexport const DEFAULT_HYDRATION_SCRIPT_ID = \"__mongez_atom_state\";\n\n/**\n * Build a JSON string suitable for embedding inside an HTML `<script>`\n * tag. Two safety steps beyond a plain `JSON.stringify`:\n *\n * 1. The closing tag sequence `</` is escaped to `<\\/` so an atom value\n * containing literal HTML cannot break out of the script element.\n * 2. The U+2028 / U+2029 line separators (which are valid JSON but not\n * valid JavaScript string literals) are escaped.\n */\nexport function serializeSnapshot(\n snapshot: Record<string, unknown>,\n options: {\n /**\n * Custom replacer passed through to `JSON.stringify`.\n */\n replacer?: (key: string, value: unknown) => unknown;\n /**\n * Pretty-printing indent. Defaults to 0 (compact).\n */\n space?: number;\n } = {},\n): string {\n const json = JSON.stringify(\n snapshot,\n options.replacer as any,\n options.space,\n );\n return json\n .replace(/<\\/(script)/gi, \"<\\\\/$1\")\n .replace(/\\u2028/g, \"\\\\u2028\")\n .replace(/\\u2029/g, \"\\\\u2029\");\n}\n\n/**\n * Convenience that snapshots a store and serializes the result in one call.\n *\n * const payload = serializeStore(serverStore);\n * // payload is a script-safe JSON string\n */\nexport function serializeStore(\n store: AtomStore,\n options?: Parameters<typeof serializeSnapshot>[1],\n): string {\n return serializeSnapshot(store.snapshot(), options);\n}\n\nexport type HydrateAtomsScriptProps = {\n /**\n * The serialized snapshot to embed. Pass either a pre-serialized string\n * (from {@link serializeStore}) or a raw snapshot object — the component\n * will serialize it for you.\n */\n snapshot: Record<string, unknown> | string;\n /**\n * DOM id for the `<script>` element. Defaults to\n * {@link DEFAULT_HYDRATION_SCRIPT_ID}. Set this when embedding multiple\n * stores in one document (e.g. a shell + a route-level boundary).\n */\n id?: string;\n /**\n * `nonce` for CSP-protected pages.\n */\n nonce?: string;\n};\n\n/**\n * Renders an inline `<script type=\"application/json\">` carrying a store\n * snapshot for the client to pick up.\n *\n * Place this once per `<AtomStoreProvider>` you want to hydrate. The\n * matching client-side call is {@link readHydration}.\n *\n * // server\n * <AtomStoreProvider store={serverStore}>\n * <App />\n * <HydrateAtomsScript snapshot={serverStore.snapshot()} />\n * </AtomStoreProvider>\n *\n * // client root\n * <AtomStoreProvider initialValues={readHydration() ?? undefined}>\n * <App />\n * </AtomStoreProvider>\n */\nexport function HydrateAtomsScript({\n snapshot,\n id = DEFAULT_HYDRATION_SCRIPT_ID,\n nonce,\n}: HydrateAtomsScriptProps) {\n const serialized =\n typeof snapshot === \"string\" ? snapshot : serializeSnapshot(snapshot);\n\n return (\n <script\n id={id}\n type=\"application/json\"\n nonce={nonce}\n // The serializer already neutralized `</script>` and the line\n // separators, so dangerouslySetInnerHTML is safe here.\n dangerouslySetInnerHTML={{ __html: serialized }}\n />\n );\n}\n\n/**\n * Read a hydration snapshot embedded via {@link HydrateAtomsScript} from\n * the current document.\n *\n * - On the server (no `document`), returns `null`.\n * - When the script tag is missing, returns `null`.\n * - When the script body is not valid JSON, returns `null` and logs the\n * error via `console.error` (so a malformed payload is visible during\n * development but does not crash hydration).\n */\nexport function readHydration(\n id: string = DEFAULT_HYDRATION_SCRIPT_ID,\n): Record<string, unknown> | null {\n if (typeof document === \"undefined\") return null;\n const el = document.getElementById(id);\n if (!el) return null;\n try {\n return JSON.parse(el.textContent ?? \"null\") as\n | Record<string, unknown>\n | null;\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\n `[@mongez/react-atom] Could not parse hydration script #${id}:`,\n err,\n );\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAa,4CAAmD,IAAI;;;;;;;;;;;;;AA0CpE,SAAgB,kBAAkB,EAChC,OACA,cACA,eACA,YACyB;CACzB,MAAM,CAAC,yCAAyC;EAC9C,MAAM,OAAO,2CAAyB;EAEtC,IAAI,cACF,KAAK,MAAM,gBAAgB,cACzB,KAAK,IAAI,YAAY;EAIzB,IAAI,eACF,KAAK,QAAQ,aAAa;EAG5B,OAAO;CACT,CAAC;CAED,2BAAgB;EACd,aAAa;GAGX,IAAI,CAAC,OACH,YAAY,QAAQ;EAExB;CACF,GAAG,CAAC,aAAa,KA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