@entifix/react-controls 0.23.22 → 0.23.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/preferences/index.d.ts +1 -0
- package/dist/preferences/index.d.ts.map +1 -1
- package/dist/preferences/index.js +1 -0
- package/dist/preferences/index.js.map +1 -1
- package/dist/preferences/preference-sink.d.ts +16 -0
- package/dist/preferences/preference-sink.d.ts.map +1 -0
- package/dist/preferences/preference-sink.js +6 -0
- package/dist/preferences/preference-sink.js.map +1 -0
- package/dist/preferences/ui-preferences-context.d.ts +2 -1
- package/dist/preferences/ui-preferences-context.d.ts.map +1 -1
- package/dist/preferences/ui-preferences-context.js +12 -2
- package/dist/preferences/ui-preferences-context.js.map +1 -1
- package/dist/theme/theme-context.d.ts.map +1 -1
- package/dist/theme/theme-context.js +8 -7
- package/dist/theme/theme-context.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './indexeddb-ui-preferences-state.js';
|
|
2
2
|
export * from './local-storage-ui-preferences-state.js';
|
|
3
|
+
export * from './preference-sink.js';
|
|
3
4
|
export * from './ui-preferences-context.js';
|
|
4
5
|
export * from './ui-preferences-state.js';
|
|
5
6
|
export * from './use-ui-preference.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/preferences/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,yCAAyC,CAAC;AACxD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/preferences/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,yCAAyC,CAAC;AACxD,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './indexeddb-ui-preferences-state.js';
|
|
2
2
|
export * from './local-storage-ui-preferences-state.js';
|
|
3
|
+
export * from './preference-sink.js';
|
|
3
4
|
export * from './ui-preferences-context.js';
|
|
4
5
|
export * from './ui-preferences-state.js';
|
|
5
6
|
export * from './use-ui-preference.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preferences/index.ts"],"sourcesContent":["export * from './indexeddb-ui-preferences-state.js';\nexport * from './local-storage-ui-preferences-state.js';\nexport * from './ui-preferences-context.js';\nexport * from './ui-preferences-state.js';\nexport * from './use-ui-preference.js';\nexport * from './use-viewport-mode.js';\n"],"names":[],"mappings":"AAAA,cAAc,sCAAsC;AACpD,cAAc,0CAA0C;AACxD,cAAc,8BAA8B;AAC5C,cAAc,4BAA4B;AAC1C,cAAc,yBAAyB;AACvC,cAAc,yBAAyB"}
|
|
1
|
+
{"version":3,"sources":["../../src/preferences/index.ts"],"sourcesContent":["export * from './indexeddb-ui-preferences-state.js';\nexport * from './local-storage-ui-preferences-state.js';\nexport * from './preference-sink.js';\nexport * from './ui-preferences-context.js';\nexport * from './ui-preferences-state.js';\nexport * from './use-ui-preference.js';\nexport * from './use-viewport-mode.js';\n"],"names":[],"mappings":"AAAA,cAAc,sCAAsC;AACpD,cAAc,0CAA0C;AACxD,cAAc,uBAAuB;AACrC,cAAc,8BAA8B;AAC5C,cAAc,4BAA4B;AAC1C,cAAc,yBAAyB;AACvC,cAAc,yBAAyB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a control copies a choice it already keeps elsewhere — the theme and
|
|
3
|
+
* the density live in a cookie — so a host that also keeps preferences, on a
|
|
4
|
+
* server or in IndexedDB, has them too.
|
|
5
|
+
*
|
|
6
|
+
* A plain callback and no `effect`, because a theme reaches every page of every
|
|
7
|
+
* host, including static sites that store no preferences at all: reading the
|
|
8
|
+
* Effect-returning store here would ship Effect to all of them. The store's
|
|
9
|
+
* provider, `UiPreferencesProvider`, supplies the sink; without one a choice
|
|
10
|
+
* is copied nowhere.
|
|
11
|
+
*/
|
|
12
|
+
export type PreferenceSink = (key: string, value: unknown) => void;
|
|
13
|
+
export declare const PreferenceSinkContext: import("react").Context<PreferenceSink | null>;
|
|
14
|
+
/** The sink the nearest `UiPreferencesProvider` supplies, or `null`. */
|
|
15
|
+
export declare const usePreferenceSink: () => PreferenceSink | null;
|
|
16
|
+
//# sourceMappingURL=preference-sink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preference-sink.d.ts","sourceRoot":"","sources":["../../src/preferences/preference-sink.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;AAEnE,eAAO,MAAM,qBAAqB,gDAA6C,CAAC;AAEhF,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,QAAO,cAAc,GAAG,IACnB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
export const PreferenceSinkContext = createContext(null);
|
|
4
|
+
/** The sink the nearest `UiPreferencesProvider` supplies, or `null`. */ export const usePreferenceSink = ()=>useContext(PreferenceSinkContext);
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=preference-sink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/preferences/preference-sink.ts"],"sourcesContent":["'use client';\n\nimport { createContext, useContext } from 'react';\n\n/**\n * Where a control copies a choice it already keeps elsewhere — the theme and\n * the density live in a cookie — so a host that also keeps preferences, on a\n * server or in IndexedDB, has them too.\n *\n * A plain callback and no `effect`, because a theme reaches every page of every\n * host, including static sites that store no preferences at all: reading the\n * Effect-returning store here would ship Effect to all of them. The store's\n * provider, `UiPreferencesProvider`, supplies the sink; without one a choice\n * is copied nowhere.\n */\nexport type PreferenceSink = (key: string, value: unknown) => void;\n\nexport const PreferenceSinkContext = createContext<PreferenceSink | null>(null);\n\n/** The sink the nearest `UiPreferencesProvider` supplies, or `null`. */\nexport const usePreferenceSink = (): PreferenceSink | null =>\n useContext(PreferenceSinkContext);\n"],"names":["createContext","useContext","PreferenceSinkContext","usePreferenceSink"],"mappings":"AAAA;AAEA,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AAelD,OAAO,MAAMC,wBAAwBF,cAAqC,MAAM;AAEhF,sEAAsE,GACtE,OAAO,MAAMG,oBAAoB,IAC/BF,WAAWC,uBAAuB"}
|
|
@@ -9,7 +9,8 @@ export interface UiPreferencesProviderProps extends PropsWithChildren {
|
|
|
9
9
|
/**
|
|
10
10
|
* Supplies the {@link UiPreferencesState} every personalizable control reads
|
|
11
11
|
* through. Mount it once per app, at the root: swapping the implementation here
|
|
12
|
-
* (say, for a server-backed store) migrates every control at once.
|
|
12
|
+
* (say, for a server-backed store) migrates every control at once. It also
|
|
13
|
+
* supplies the {@link PreferenceSinkContext} a theme copies its choices to.
|
|
13
14
|
*/
|
|
14
15
|
export declare function UiPreferencesProvider({ children, store, namespace, }: UiPreferencesProviderProps): import("react").JSX.Element;
|
|
15
16
|
export declare function useUiPreferencesState(): UiPreferencesState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-preferences-context.d.ts","sourceRoot":"","sources":["../../src/preferences/ui-preferences-context.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ui-preferences-context.d.ts","sourceRoot":"","sources":["../../src/preferences/ui-preferences-context.tsx"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,iBAAiB,EAGvB,MAAM,OAAO,CAAC;AAUf,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAIpE,MAAM,WAAW,0BAA2B,SAAQ,iBAAiB;IACnE,+EAA+E;IAC/E,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,QAAQ,EACR,KAAK,EACL,SAA4C,GAC7C,EAAE,0BAA0B,+BAmB5B;AAUD,wBAAgB,qBAAqB,IAAI,kBAAkB,CAE1D"}
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Effect } from 'effect';
|
|
3
4
|
import { createContext, useContext, useMemo } from 'react';
|
|
4
5
|
import { DEFAULT_UI_PREFERENCES_NAMESPACE, makeLocalStorageUiPreferencesState } from './local-storage-ui-preferences-state.js';
|
|
6
|
+
import { PreferenceSinkContext } from './preference-sink.js';
|
|
5
7
|
const UiPreferencesContext = /*#__PURE__*/ createContext(null);
|
|
6
8
|
/**
|
|
7
9
|
* Supplies the {@link UiPreferencesState} every personalizable control reads
|
|
8
10
|
* through. Mount it once per app, at the root: swapping the implementation here
|
|
9
|
-
* (say, for a server-backed store) migrates every control at once.
|
|
11
|
+
* (say, for a server-backed store) migrates every control at once. It also
|
|
12
|
+
* supplies the {@link PreferenceSinkContext} a theme copies its choices to.
|
|
10
13
|
*/ export function UiPreferencesProvider({ children, store, namespace = DEFAULT_UI_PREFERENCES_NAMESPACE }) {
|
|
11
14
|
const value = useMemo(()=>store != null ? store : makeLocalStorageUiPreferencesState(namespace), [
|
|
12
15
|
store,
|
|
13
16
|
namespace
|
|
14
17
|
]);
|
|
18
|
+
// A copy is best-effort: the control that asked kept the choice already.
|
|
19
|
+
const sink = useMemo(()=>(key, choice)=>void Effect.runPromise(value.write(key, choice)).catch(()=>undefined), [
|
|
20
|
+
value
|
|
21
|
+
]);
|
|
15
22
|
return /*#__PURE__*/ _jsx(UiPreferencesContext.Provider, {
|
|
16
23
|
value: value,
|
|
17
|
-
children:
|
|
24
|
+
children: /*#__PURE__*/ _jsx(PreferenceSinkContext.Provider, {
|
|
25
|
+
value: sink,
|
|
26
|
+
children: children
|
|
27
|
+
})
|
|
18
28
|
});
|
|
19
29
|
}
|
|
20
30
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preferences/ui-preferences-context.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n type PropsWithChildren,\n useContext,\n useMemo,\n} from 'react';\n\nimport {\n DEFAULT_UI_PREFERENCES_NAMESPACE,\n makeLocalStorageUiPreferencesState,\n} from './local-storage-ui-preferences-state.js';\nimport type { UiPreferencesState } from './ui-preferences-state.js';\n\nconst UiPreferencesContext = createContext<UiPreferencesState | null>(null);\n\nexport interface UiPreferencesProviderProps extends PropsWithChildren {\n /** Explicit store. Omit and a `localStorage` one is built from `namespace`. */\n store?: UiPreferencesState;\n /** Key prefix, so apps sharing an origin don't clobber each other. */\n namespace?: string;\n}\n\n/**\n * Supplies the {@link UiPreferencesState} every personalizable control reads\n * through. Mount it once per app, at the root: swapping the implementation here\n * (say, for a server-backed store) migrates every control at once.\n */\nexport function UiPreferencesProvider({\n children,\n store,\n namespace = DEFAULT_UI_PREFERENCES_NAMESPACE,\n}: UiPreferencesProviderProps) {\n const value = useMemo(\n () => store ?? makeLocalStorageUiPreferencesState(namespace),\n [store, namespace],\n );\n\n return (\n <UiPreferencesContext.Provider value={value}>\n {children}\n </UiPreferencesContext.Provider>\n );\n}\n\n/**\n * The active store. Falls back to a default `localStorage` store when no\n * provider is mounted, so a control stays usable in isolation (tests, an app\n * that has not opted in yet) — the fallback is module-level so its identity is\n * stable across renders.\n */\nconst fallbackStore = makeLocalStorageUiPreferencesState();\n\nexport function useUiPreferencesState(): UiPreferencesState {\n return useContext(UiPreferencesContext) ?? fallbackStore;\n}\n"],"names":["createContext","useContext","useMemo","DEFAULT_UI_PREFERENCES_NAMESPACE","makeLocalStorageUiPreferencesState","UiPreferencesContext","UiPreferencesProvider","children","store","namespace","value","Provider","fallbackStore","useUiPreferencesState"],"mappings":"AAAA;;AAEA,
|
|
1
|
+
{"version":3,"sources":["../../src/preferences/ui-preferences-context.tsx"],"sourcesContent":["'use client';\n\nimport { Effect } from 'effect';\nimport {\n createContext,\n type PropsWithChildren,\n useContext,\n useMemo,\n} from 'react';\n\nimport {\n DEFAULT_UI_PREFERENCES_NAMESPACE,\n makeLocalStorageUiPreferencesState,\n} from './local-storage-ui-preferences-state.js';\nimport {\n type PreferenceSink,\n PreferenceSinkContext,\n} from './preference-sink.js';\nimport type { UiPreferencesState } from './ui-preferences-state.js';\n\nconst UiPreferencesContext = createContext<UiPreferencesState | null>(null);\n\nexport interface UiPreferencesProviderProps extends PropsWithChildren {\n /** Explicit store. Omit and a `localStorage` one is built from `namespace`. */\n store?: UiPreferencesState;\n /** Key prefix, so apps sharing an origin don't clobber each other. */\n namespace?: string;\n}\n\n/**\n * Supplies the {@link UiPreferencesState} every personalizable control reads\n * through. Mount it once per app, at the root: swapping the implementation here\n * (say, for a server-backed store) migrates every control at once. It also\n * supplies the {@link PreferenceSinkContext} a theme copies its choices to.\n */\nexport function UiPreferencesProvider({\n children,\n store,\n namespace = DEFAULT_UI_PREFERENCES_NAMESPACE,\n}: UiPreferencesProviderProps) {\n const value = useMemo(\n () => store ?? makeLocalStorageUiPreferencesState(namespace),\n [store, namespace],\n );\n // A copy is best-effort: the control that asked kept the choice already.\n const sink = useMemo<PreferenceSink>(\n () => (key, choice) =>\n void Effect.runPromise(value.write(key, choice)).catch(() => undefined),\n [value],\n );\n\n return (\n <UiPreferencesContext.Provider value={value}>\n <PreferenceSinkContext.Provider value={sink}>\n {children}\n </PreferenceSinkContext.Provider>\n </UiPreferencesContext.Provider>\n );\n}\n\n/**\n * The active store. Falls back to a default `localStorage` store when no\n * provider is mounted, so a control stays usable in isolation (tests, an app\n * that has not opted in yet) — the fallback is module-level so its identity is\n * stable across renders.\n */\nconst fallbackStore = makeLocalStorageUiPreferencesState();\n\nexport function useUiPreferencesState(): UiPreferencesState {\n return useContext(UiPreferencesContext) ?? fallbackStore;\n}\n"],"names":["Effect","createContext","useContext","useMemo","DEFAULT_UI_PREFERENCES_NAMESPACE","makeLocalStorageUiPreferencesState","PreferenceSinkContext","UiPreferencesContext","UiPreferencesProvider","children","store","namespace","value","sink","key","choice","runPromise","write","catch","undefined","Provider","fallbackStore","useUiPreferencesState"],"mappings":"AAAA;;AAEA,SAASA,MAAM,QAAQ,SAAS;AAChC,SACEC,aAAa,EAEbC,UAAU,EACVC,OAAO,QACF,QAAQ;AAEf,SACEC,gCAAgC,EAChCC,kCAAkC,QAC7B,0CAA0C;AACjD,SAEEC,qBAAqB,QAChB,uBAAuB;AAG9B,MAAMC,qCAAuBN,cAAyC;AAStE;;;;;CAKC,GACD,OAAO,SAASO,sBAAsB,EACpCC,QAAQ,EACRC,KAAK,EACLC,YAAYP,gCAAgC,EACjB;IAC3B,MAAMQ,QAAQT,QACZ,IAAMO,gBAAAA,QAASL,mCAAmCM,YAClD;QAACD;QAAOC;KAAU;IAEpB,yEAAyE;IACzE,MAAME,OAAOV,QACX,IAAM,CAACW,KAAKC,SACV,KAAKf,OAAOgB,UAAU,CAACJ,MAAMK,KAAK,CAACH,KAAKC,SAASG,KAAK,CAAC,IAAMC,YAC/D;QAACP;KAAM;IAGT,qBACE,KAACL,qBAAqBa,QAAQ;QAACR,OAAOA;kBACpC,cAAA,KAACN,sBAAsBc,QAAQ;YAACR,OAAOC;sBACpCJ;;;AAIT;AAEA;;;;;CAKC,GACD,MAAMY,gBAAgBhB;AAEtB,OAAO,SAASiB;QACPpB;IAAP,QAAOA,cAAAA,WAAWK,iCAAXL,cAAoCmB;AAC7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-context.d.ts","sourceRoot":"","sources":["../../src/theme/theme-context.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"theme-context.d.ts","sourceRoot":"","sources":["../../src/theme/theme-context.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,iBAAiB,EAMvB,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EACjB,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D;uEACmE;IACnE,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACzC;AAiCD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,cAAc,EACd,UAAyB,EACzB,QAAQ,EACR,YAAY,EACZ,cAAc,GACf,EAAE,kBAAkB,+BA4HpB;AAED,oEAAoE;AACpE,eAAO,MAAM,gBAAgB,QAAO,iBAAiB,GAAG,IAC9B,CAAC;AAE3B,wBAAgB,QAAQ,IAAI,iBAAiB,CAI5C"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { Effect } from 'effect';
|
|
4
3
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
5
|
-
import {
|
|
4
|
+
import { usePreferenceSink } from '../preferences/preference-sink.js';
|
|
6
5
|
import { densityCookie, THEME_COOKIE } from './theme-cookie.js';
|
|
7
6
|
const ThemeContext = /*#__PURE__*/ createContext(null);
|
|
8
7
|
const DENSITIES = [
|
|
@@ -51,7 +50,7 @@ function writeCookie(name, value) {
|
|
|
51
50
|
// `undefined` until a density is stored, chosen or defaulted: the document's
|
|
52
51
|
// own `data-density` stands until then.
|
|
53
52
|
const [density, setDensityState] = useState(initialDensity != null ? initialDensity : defaultDensity);
|
|
54
|
-
const
|
|
53
|
+
const sink = usePreferenceSink();
|
|
55
54
|
const isKnown = useCallback((value)=>typeof value === 'string' && themes.some((t)=>t.id === value), [
|
|
56
55
|
themes
|
|
57
56
|
]);
|
|
@@ -126,13 +125,15 @@ function writeCookie(name, value) {
|
|
|
126
125
|
}, [
|
|
127
126
|
density
|
|
128
127
|
]);
|
|
129
|
-
// The cookie is what the next page is rendered in;
|
|
130
|
-
// gets a copy, so
|
|
128
|
+
// The cookie is what the next page is rendered in; a host that mounts a
|
|
129
|
+
// `UiPreferencesProvider` gets a copy, so preferences it keeps server-side
|
|
130
|
+
// have it too. Without one nothing else is written — and no Effect is
|
|
131
|
+
// shipped for it (see `preference-sink.ts`).
|
|
131
132
|
const remember = useCallback((cookie, key, value)=>{
|
|
132
133
|
writeCookie(cookie, value);
|
|
133
|
-
void
|
|
134
|
+
sink == null ? void 0 : sink(key, value);
|
|
134
135
|
}, [
|
|
135
|
-
|
|
136
|
+
sink
|
|
136
137
|
]);
|
|
137
138
|
const setTheme = useCallback((next)=>{
|
|
138
139
|
setThemeState(next);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/theme/theme-context.tsx"],"sourcesContent":["'use client';\n\nimport { Effect } from 'effect';\nimport {\n createContext,\n type PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'react';\n\nimport { useUiPreferencesState } from '../preferences/ui-preferences-context.js';\nimport { densityCookie, THEME_COOKIE } from './theme-cookie.js';\nimport type {\n Density,\n ThemeContextValue,\n ThemeOption,\n ThemePalette,\n} from './types.js';\n\nconst ThemeContext = createContext<ThemeContextValue | null>(null);\n\nexport interface ThemeProviderProps extends PropsWithChildren {\n /** The themes this app exposes. First entry is the default unless\n * `defaultTheme` is given. Drives `data-theme` + the switcher. */\n themes: ThemeOption[];\n /** Theme id used for the first paint / when nothing is stored. */\n defaultTheme?: string;\n /**\n * The density when nothing is stored. Omitted, the provider leaves\n * `data-density` as the document has it until a density is chosen.\n */\n defaultDensity?: Density;\n /**\n * The cookie the theme is kept in — namespace it per app so apps don't\n * clobber each other. The density is kept beside it, under\n * `${storageKey}-density`. A cookie rather than local storage, so a server\n * can read the choice and render `data-theme` and `data-density` with the\n * page: no paint in the wrong palette before a script corrects it.\n */\n storageKey?: string;\n /**\n * The theme and density the server read from those cookies and rendered\n * the page in (`readThemeCookies` in `@entifix/next-shell/server`). Given,\n * the provider starts there and nothing changes after the page loads.\n */\n initialTheme?: string;\n initialDensity?: Density;\n /**\n * Runtime palettes for brands not shipped as CSS presets (multi-tenant /\n * white-label). Keyed by theme id; injected as `[data-theme='id']{…}` vars\n * appended after the app stylesheet, so they override static presets.\n */\n palettes?: Record<string, ThemePalette>;\n}\n\nconst DENSITIES: readonly Density[] = ['comfortable', 'compact'];\n\nconst isDensity = (value: unknown): value is Density =>\n DENSITIES.includes(value as Density);\n\n/** Storage that may be absent or refuse (a private window, blocked site data). */\n/** A year: a preference outlives a session. */\nconst COOKIE_MAX_AGE = 60 * 60 * 24 * 365;\n\n/** A first-party cookie's value, or `null` when it is not set. */\nfunction readCookie(name: string): string | null {\n try {\n for (const pair of document.cookie.split('; ')) {\n const at = pair.indexOf('=');\n if (pair.slice(0, at) === name)\n return decodeURIComponent(pair.slice(at + 1));\n }\n } catch {\n // A sandboxed document refuses cookies; nothing was stored, then.\n }\n return null;\n}\n\nfunction writeCookie(name: string, value: string) {\n try {\n document.cookie = `${name}=${encodeURIComponent(value)}; path=/; max-age=${COOKIE_MAX_AGE}; samesite=lax`;\n } catch {\n // Nothing to remember it in; the choice still applies to this page.\n }\n}\n\n/**\n * Applies the active palette and density by writing `data-theme` and\n * `data-density` on <html>, and remembers what the user chooses. Static palette\n * VALUES live in CSS (@entifix/style presets or an app-local themes.css); this\n * flips the selector. Dynamic palettes passed via `palettes` are injected at\n * runtime under the same `data-theme` mechanism.\n *\n * ⚠️ **Only a choice is written to storage, never a default.** The provider\n * used to persist whatever theme it held from an effect, and under StrictMode\n * the effect ran before the stored value had been read back: the default\n * overwrote the stored theme, and a reload in development always came back on\n * the default. Writing in `setTheme` and `setDensity` alone means mounting,\n * however many times, can never lose what was chosen.\n */\nexport function ThemeProvider({\n children,\n themes,\n defaultTheme,\n defaultDensity,\n storageKey = THEME_COOKIE,\n palettes,\n initialTheme,\n initialDensity,\n}: ThemeProviderProps) {\n const initial = initialTheme ?? defaultTheme ?? themes[0]?.id ?? '';\n const [theme, setThemeState] = useState<string>(initial);\n const densityKey = densityCookie(storageKey);\n // `undefined` until a density is stored, chosen or defaulted: the document's\n // own `data-density` stands until then.\n const [density, setDensityState] = useState<Density | undefined>(\n initialDensity ?? defaultDensity,\n );\n const preferences = useUiPreferencesState();\n\n const isKnown = useCallback(\n (value: unknown): value is string =>\n typeof value === 'string' && themes.some(t => t.id === value),\n [themes],\n );\n\n // Read the stored choice on mount, for a host that could not: a static\n // export has no server to read the cookie, so it renders `initial` and the\n // client corrects after mount. Reading in render would mismatch hydration.\n // Where the server read it, `initial` already is the stored choice and this\n // changes nothing. It only reads, so running twice changes nothing.\n // ⚠️ Until the stored choice has been read, nothing is reflected onto the\n // document. A static export's `ThemeScript` has already painted the stored\n // palette before React loads; reflecting `initial` on the first commit would\n // repaint the default over it for one frame, and the stored one again on the\n // next — the flash the script exists to prevent.\n const [adopted, setAdopted] = useState(false);\n useEffect(() => {\n const stored = readCookie(storageKey);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- one-shot SSR-safe hydration, see comment above\n if (isKnown(stored)) setThemeState(stored);\n setAdopted(true);\n // A stored density wins; otherwise the default, otherwise whatever the\n // document was served with, so the context never reports a density the\n // page is not in.\n const storedDensity = readCookie(densityKey);\n const served = document.documentElement.dataset.density;\n if (isDensity(storedDensity)) setDensityState(storedDensity);\n else if (defaultDensity === undefined && isDensity(served)) {\n setDensityState(served);\n }\n }, [storageKey, densityKey, isKnown, defaultDensity]);\n\n // Inject runtime palettes as a single <style> appended to <head>. Being last\n // in the cascade, these win over any static preset defining the same tokens.\n useEffect(() => {\n if (!palettes || Object.keys(palettes).length === 0) return;\n const styleId = `${storageKey}-runtime-palettes`;\n const css = Object.entries(palettes)\n .map(([id, palette]) => {\n const decls = Object.entries(palette)\n .map(([token, value]) => `--color-${token}: ${value};`)\n .join(' ');\n return `[data-theme='${id}'] { ${decls} }`;\n })\n .join('\\n');\n\n let el = document.getElementById(styleId) as HTMLStyleElement | null;\n if (!el) {\n el = document.createElement('style');\n el.id = styleId;\n document.head.appendChild(el);\n }\n el.textContent = css;\n }, [palettes, storageKey]);\n\n // Reflect the active theme and density onto the document. Storage is not\n // touched here — see the ⚠️ above.\n //\n // Written only when it differs: a page the server rendered in the stored\n // theme is already right, and even a write of the same value is a change\n // something watching the document would see.\n useEffect(() => {\n if (!adopted) return;\n const root = document.documentElement;\n if (root.dataset.theme !== theme) root.dataset.theme = theme;\n }, [adopted, theme]);\n useEffect(() => {\n const root = document.documentElement;\n if (density !== undefined && root.dataset.density !== density)\n root.dataset.density = density;\n }, [density]);\n\n // The cookie is what the next page is rendered in; the UI-preferences port\n // gets a copy, so a host that keeps preferences server-side has them too.\n const remember = useCallback(\n (cookie: string, key: 'theme' | 'density', value: string) => {\n writeCookie(cookie, value);\n void Effect.runPromise(preferences.write(key, value)).catch(\n () => undefined,\n );\n },\n [preferences],\n );\n const setTheme = useCallback(\n (next: string) => {\n setThemeState(next);\n remember(storageKey, 'theme', next);\n },\n [storageKey, remember],\n );\n const setDensity = useCallback(\n (next: Density) => {\n setDensityState(next);\n remember(densityKey, 'density', next);\n },\n [densityKey, remember],\n );\n\n const value = useMemo<ThemeContextValue>(\n () => ({\n theme,\n setTheme,\n themes,\n density: density ?? 'comfortable',\n setDensity,\n }),\n [theme, setTheme, themes, density, setDensity],\n );\n\n return (\n <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>\n );\n}\n\n/** The theme context, or `null` outside a {@link ThemeProvider}. */\nexport const useOptionalTheme = (): ThemeContextValue | null =>\n useContext(ThemeContext);\n\nexport function useTheme(): ThemeContextValue {\n const ctx = useContext(ThemeContext);\n if (!ctx) throw new Error('useTheme must be used within a ThemeProvider');\n return ctx;\n}\n"],"names":["Effect","createContext","useCallback","useContext","useEffect","useMemo","useState","useUiPreferencesState","densityCookie","THEME_COOKIE","ThemeContext","DENSITIES","isDensity","value","includes","COOKIE_MAX_AGE","readCookie","name","pair","document","cookie","split","at","indexOf","slice","decodeURIComponent","writeCookie","encodeURIComponent","ThemeProvider","children","themes","defaultTheme","defaultDensity","storageKey","palettes","initialTheme","initialDensity","initial","id","theme","setThemeState","densityKey","density","setDensityState","preferences","isKnown","some","t","adopted","setAdopted","stored","storedDensity","served","documentElement","dataset","undefined","Object","keys","length","styleId","css","entries","map","palette","decls","token","join","el","getElementById","createElement","head","appendChild","textContent","root","remember","key","runPromise","write","catch","setTheme","next","setDensity","Provider","useOptionalTheme","useTheme","ctx","Error"],"mappings":"AAAA;;AAEA,SAASA,MAAM,QAAQ,SAAS;AAChC,SACEC,aAAa,EAEbC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,QAAQ,QACH,QAAQ;AAEf,SAASC,qBAAqB,QAAQ,2CAA2C;AACjF,SAASC,aAAa,EAAEC,YAAY,QAAQ,oBAAoB;AAQhE,MAAMC,6BAAeT,cAAwC;AAoC7D,MAAMU,YAAgC;IAAC;IAAe;CAAU;AAEhE,MAAMC,YAAY,CAACC,QACjBF,UAAUG,QAAQ,CAACD;AAErB,gFAAgF,GAChF,6CAA6C,GAC7C,MAAME,iBAAiB,KAAK,KAAK,KAAK;AAEtC,gEAAgE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MsD,mBAAmB,IAC9BhF,WAAWO,cAAc;AAE3B,OAAO,SAAS0E;IACd,MAAMC,MAAMlF,WAAWO;IACvB,IAAI,CAAC2E,KAAK,MAAM,IAAIC,MAAM;IAC1B,OAAOD;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/theme/theme-context.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n type PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'react';\n\nimport { usePreferenceSink } from '../preferences/preference-sink.js';\nimport { densityCookie, THEME_COOKIE } from './theme-cookie.js';\nimport type {\n Density,\n ThemeContextValue,\n ThemeOption,\n ThemePalette,\n} from './types.js';\n\nconst ThemeContext = createContext<ThemeContextValue | null>(null);\n\nexport interface ThemeProviderProps extends PropsWithChildren {\n /** The themes this app exposes. First entry is the default unless\n * `defaultTheme` is given. Drives `data-theme` + the switcher. */\n themes: ThemeOption[];\n /** Theme id used for the first paint / when nothing is stored. */\n defaultTheme?: string;\n /**\n * The density when nothing is stored. Omitted, the provider leaves\n * `data-density` as the document has it until a density is chosen.\n */\n defaultDensity?: Density;\n /**\n * The cookie the theme is kept in — namespace it per app so apps don't\n * clobber each other. The density is kept beside it, under\n * `${storageKey}-density`. A cookie rather than local storage, so a server\n * can read the choice and render `data-theme` and `data-density` with the\n * page: no paint in the wrong palette before a script corrects it.\n */\n storageKey?: string;\n /**\n * The theme and density the server read from those cookies and rendered\n * the page in (`readThemeCookies` in `@entifix/next-shell/server`). Given,\n * the provider starts there and nothing changes after the page loads.\n */\n initialTheme?: string;\n initialDensity?: Density;\n /**\n * Runtime palettes for brands not shipped as CSS presets (multi-tenant /\n * white-label). Keyed by theme id; injected as `[data-theme='id']{…}` vars\n * appended after the app stylesheet, so they override static presets.\n */\n palettes?: Record<string, ThemePalette>;\n}\n\nconst DENSITIES: readonly Density[] = ['comfortable', 'compact'];\n\nconst isDensity = (value: unknown): value is Density =>\n DENSITIES.includes(value as Density);\n\n/** Storage that may be absent or refuse (a private window, blocked site data). */\n/** A year: a preference outlives a session. */\nconst COOKIE_MAX_AGE = 60 * 60 * 24 * 365;\n\n/** A first-party cookie's value, or `null` when it is not set. */\nfunction readCookie(name: string): string | null {\n try {\n for (const pair of document.cookie.split('; ')) {\n const at = pair.indexOf('=');\n if (pair.slice(0, at) === name)\n return decodeURIComponent(pair.slice(at + 1));\n }\n } catch {\n // A sandboxed document refuses cookies; nothing was stored, then.\n }\n return null;\n}\n\nfunction writeCookie(name: string, value: string) {\n try {\n document.cookie = `${name}=${encodeURIComponent(value)}; path=/; max-age=${COOKIE_MAX_AGE}; samesite=lax`;\n } catch {\n // Nothing to remember it in; the choice still applies to this page.\n }\n}\n\n/**\n * Applies the active palette and density by writing `data-theme` and\n * `data-density` on <html>, and remembers what the user chooses. Static palette\n * VALUES live in CSS (@entifix/style presets or an app-local themes.css); this\n * flips the selector. Dynamic palettes passed via `palettes` are injected at\n * runtime under the same `data-theme` mechanism.\n *\n * ⚠️ **Only a choice is written to storage, never a default.** The provider\n * used to persist whatever theme it held from an effect, and under StrictMode\n * the effect ran before the stored value had been read back: the default\n * overwrote the stored theme, and a reload in development always came back on\n * the default. Writing in `setTheme` and `setDensity` alone means mounting,\n * however many times, can never lose what was chosen.\n */\nexport function ThemeProvider({\n children,\n themes,\n defaultTheme,\n defaultDensity,\n storageKey = THEME_COOKIE,\n palettes,\n initialTheme,\n initialDensity,\n}: ThemeProviderProps) {\n const initial = initialTheme ?? defaultTheme ?? themes[0]?.id ?? '';\n const [theme, setThemeState] = useState<string>(initial);\n const densityKey = densityCookie(storageKey);\n // `undefined` until a density is stored, chosen or defaulted: the document's\n // own `data-density` stands until then.\n const [density, setDensityState] = useState<Density | undefined>(\n initialDensity ?? defaultDensity,\n );\n const sink = usePreferenceSink();\n\n const isKnown = useCallback(\n (value: unknown): value is string =>\n typeof value === 'string' && themes.some(t => t.id === value),\n [themes],\n );\n\n // Read the stored choice on mount, for a host that could not: a static\n // export has no server to read the cookie, so it renders `initial` and the\n // client corrects after mount. Reading in render would mismatch hydration.\n // Where the server read it, `initial` already is the stored choice and this\n // changes nothing. It only reads, so running twice changes nothing.\n // ⚠️ Until the stored choice has been read, nothing is reflected onto the\n // document. A static export's `ThemeScript` has already painted the stored\n // palette before React loads; reflecting `initial` on the first commit would\n // repaint the default over it for one frame, and the stored one again on the\n // next — the flash the script exists to prevent.\n const [adopted, setAdopted] = useState(false);\n useEffect(() => {\n const stored = readCookie(storageKey);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- one-shot SSR-safe hydration, see comment above\n if (isKnown(stored)) setThemeState(stored);\n setAdopted(true);\n // A stored density wins; otherwise the default, otherwise whatever the\n // document was served with, so the context never reports a density the\n // page is not in.\n const storedDensity = readCookie(densityKey);\n const served = document.documentElement.dataset.density;\n if (isDensity(storedDensity)) setDensityState(storedDensity);\n else if (defaultDensity === undefined && isDensity(served)) {\n setDensityState(served);\n }\n }, [storageKey, densityKey, isKnown, defaultDensity]);\n\n // Inject runtime palettes as a single <style> appended to <head>. Being last\n // in the cascade, these win over any static preset defining the same tokens.\n useEffect(() => {\n if (!palettes || Object.keys(palettes).length === 0) return;\n const styleId = `${storageKey}-runtime-palettes`;\n const css = Object.entries(palettes)\n .map(([id, palette]) => {\n const decls = Object.entries(palette)\n .map(([token, value]) => `--color-${token}: ${value};`)\n .join(' ');\n return `[data-theme='${id}'] { ${decls} }`;\n })\n .join('\\n');\n\n let el = document.getElementById(styleId) as HTMLStyleElement | null;\n if (!el) {\n el = document.createElement('style');\n el.id = styleId;\n document.head.appendChild(el);\n }\n el.textContent = css;\n }, [palettes, storageKey]);\n\n // Reflect the active theme and density onto the document. Storage is not\n // touched here — see the ⚠️ above.\n //\n // Written only when it differs: a page the server rendered in the stored\n // theme is already right, and even a write of the same value is a change\n // something watching the document would see.\n useEffect(() => {\n if (!adopted) return;\n const root = document.documentElement;\n if (root.dataset.theme !== theme) root.dataset.theme = theme;\n }, [adopted, theme]);\n useEffect(() => {\n const root = document.documentElement;\n if (density !== undefined && root.dataset.density !== density)\n root.dataset.density = density;\n }, [density]);\n\n // The cookie is what the next page is rendered in; a host that mounts a\n // `UiPreferencesProvider` gets a copy, so preferences it keeps server-side\n // have it too. Without one nothing else is written — and no Effect is\n // shipped for it (see `preference-sink.ts`).\n const remember = useCallback(\n (cookie: string, key: 'theme' | 'density', value: string) => {\n writeCookie(cookie, value);\n sink?.(key, value);\n },\n [sink],\n );\n const setTheme = useCallback(\n (next: string) => {\n setThemeState(next);\n remember(storageKey, 'theme', next);\n },\n [storageKey, remember],\n );\n const setDensity = useCallback(\n (next: Density) => {\n setDensityState(next);\n remember(densityKey, 'density', next);\n },\n [densityKey, remember],\n );\n\n const value = useMemo<ThemeContextValue>(\n () => ({\n theme,\n setTheme,\n themes,\n density: density ?? 'comfortable',\n setDensity,\n }),\n [theme, setTheme, themes, density, setDensity],\n );\n\n return (\n <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>\n );\n}\n\n/** The theme context, or `null` outside a {@link ThemeProvider}. */\nexport const useOptionalTheme = (): ThemeContextValue | null =>\n useContext(ThemeContext);\n\nexport function useTheme(): ThemeContextValue {\n const ctx = useContext(ThemeContext);\n if (!ctx) throw new Error('useTheme must be used within a ThemeProvider');\n return ctx;\n}\n"],"names":["createContext","useCallback","useContext","useEffect","useMemo","useState","usePreferenceSink","densityCookie","THEME_COOKIE","ThemeContext","DENSITIES","isDensity","value","includes","COOKIE_MAX_AGE","readCookie","name","pair","document","cookie","split","at","indexOf","slice","decodeURIComponent","writeCookie","encodeURIComponent","ThemeProvider","children","themes","defaultTheme","defaultDensity","storageKey","palettes","initialTheme","initialDensity","initial","id","theme","setThemeState","densityKey","density","setDensityState","sink","isKnown","some","t","adopted","setAdopted","stored","storedDensity","served","documentElement","dataset","undefined","Object","keys","length","styleId","css","entries","map","palette","decls","token","join","el","getElementById","createElement","head","appendChild","textContent","root","remember","key","setTheme","next","setDensity","Provider","useOptionalTheme","useTheme","ctx","Error"],"mappings":"AA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YACjB,CAAC2E;QACClC,gBAAgBkC;QAChBH,SAASjC,YAAY,WAAWoC;IAClC,GACA;QAACpC;QAAYiC;KAAS;IAGxB,MAAM7D,QAAQR,QACZ,IAAO,CAAA;YACLkC;YACAqC;YACA9C;YACAY,OAAO,EAAEA,kBAAAA,UAAW;YACpBoC;QACF,CAAA,GACA;QAACvC;QAAOqC;QAAU9C;QAAQY;QAASoC;KAAW;IAGhD,qBACE,KAACpE,aAAaqE,QAAQ;QAAClE,OAAOA;kBAAQgB;;AAE1C;AAEA,kEAAkE,GAClE,OAAO,MAAMmD,mBAAmB,IAC9B7E,WAAWO,cAAc;AAE3B,OAAO,SAASuE;IACd,MAAMC,MAAM/E,WAAWO;IACvB,IAAI,CAACwE,KAAK,MAAM,IAAIC,MAAM;IAC1B,OAAOD;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/react-controls",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.24",
|
|
4
4
|
"description": "Entity-agnostic React UI — table, form, filters, wizard, command palette — rendered from entity metadata, plus layout primitives.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@headlessui/react": "^2.2.10",
|
|
20
20
|
"class-variance-authority": "^0.7.1",
|
|
21
21
|
"idb": "^8.0.4",
|
|
22
|
-
"@entifix/core": "0.23.
|
|
22
|
+
"@entifix/core": "0.23.24"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
"./package.json": "./package.json",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"react": "19.3.1",
|
|
56
56
|
"react-i18next": "18.0.1",
|
|
57
57
|
"storybook": "^10.6.8",
|
|
58
|
-
"@entifix/i18n": "0.23.
|
|
59
|
-
"@entifix/style": "0.23.
|
|
58
|
+
"@entifix/i18n": "0.23.24",
|
|
59
|
+
"@entifix/style": "0.23.24"
|
|
60
60
|
},
|
|
61
61
|
"nx": {
|
|
62
62
|
"tags": [
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"i18next": ">=26 <28",
|
|
112
112
|
"react": ">=19 <20",
|
|
113
113
|
"react-i18next": ">=17 <19",
|
|
114
|
-
"@entifix/i18n": "0.23.
|
|
114
|
+
"@entifix/i18n": "0.23.24"
|
|
115
115
|
},
|
|
116
116
|
"peerDependenciesMeta": {
|
|
117
117
|
"@entifix/i18n": {
|