@phreshos/react-ui 0.1.31 → 0.1.32
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/appearance.d.ts +6 -1
- package/dist/main.d.ts +2 -2
- package/dist/preferences.d.ts +8 -0
- package/dist/ui-provider.d.ts +4 -4
- package/dist/ui-provider.js +47 -8
- package/package.json +2 -2
package/dist/appearance.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { appearanceLimits, type Appearance as SystemAppearance, type AppearanceColor, type AppearanceColors, type AppearanceMaterial, type AppearanceRange, type AppearanceShadow, type AppearanceTransaction, type Easing, type ThemedValue } from "@phreshos/core";
|
|
1
|
+
import { appearanceLimits, type Appearance as SystemAppearance, type AppearanceUpdate as SystemAppearanceUpdate, type AppearanceColor, type AppearanceColors, type AppearanceMaterial, type AppearanceRange, type AppearanceShadow, type AppearanceTransaction, type Easing, type ThemedValue } from "@phreshos/core";
|
|
2
2
|
/** Complete visual input consumed by React UI. */
|
|
3
3
|
export type Appearance = Pick<SystemAppearance, "colors" | "spacing" | "radius" | "shadow" | "material" | "transaction">;
|
|
4
|
+
type AppearanceUpdateFields = Pick<SystemAppearanceUpdate, "colors" | "spacing" | "radius" | "shadow" | "material" | "transaction">;
|
|
5
|
+
/** At least one partial visual field recursively merged with the nearest UIProvider. */
|
|
6
|
+
export type AppearanceUpdate = {
|
|
7
|
+
[Field in keyof AppearanceUpdateFields]-?: Readonly<Required<Pick<AppearanceUpdateFields, Field>> & Omit<AppearanceUpdateFields, Field>>;
|
|
8
|
+
}[keyof AppearanceUpdateFields];
|
|
4
9
|
export { appearanceLimits, type AppearanceColor, type AppearanceColors, type AppearanceMaterial, type AppearanceRange, type AppearanceShadow, type AppearanceTransaction, type Easing, type ThemedValue };
|
|
5
10
|
/** React UI's default visual input, derived from the System default. */
|
|
6
11
|
export declare const defaultAppearance: Appearance;
|
package/dist/main.d.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* Components enter this surface only after their implementation-independent
|
|
5
5
|
* behavior contract has been established by the package's tests.
|
|
6
6
|
*/
|
|
7
|
-
export { defaultAppearance, type Appearance, type AppearanceColor, type AppearanceColors, type AppearanceMaterial, type AppearanceShadow, type AppearanceTransaction, type Easing, type ThemedValue } from "./appearance.js";
|
|
7
|
+
export { defaultAppearance, type Appearance, type AppearanceUpdate, type AppearanceColor, type AppearanceColors, type AppearanceMaterial, type AppearanceShadow, type AppearanceTransaction, type Easing, type ThemedValue } from "./appearance.js";
|
|
8
8
|
export { UIProvider, useAppearance, useBrowserPreferences, useDirection, useDocumentDirection, usePreferences, useThemedValue, type UIProviderProps } from "./ui-provider.js";
|
|
9
|
-
export type { Preferences, Theme } from "./preferences.js";
|
|
9
|
+
export type { Preferences, PreferencesUpdate, Theme } from "./preferences.js";
|
|
10
10
|
export type { Direction } from "./direction.js";
|
|
11
11
|
export { Flex, type FlexProps } from "./flex.js";
|
|
12
12
|
export { Grid, type GridProps } from "./grid.js";
|
package/dist/preferences.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { DesktopPreferences } from "@phreshos/core";
|
|
2
2
|
/** Complete environment preferences consumed by React UI. */
|
|
3
3
|
export type Preferences = Pick<DesktopPreferences, "theme" | "animations">;
|
|
4
|
+
/** At least one preference merged with the nearest UIProvider. */
|
|
5
|
+
export type PreferencesUpdate = Readonly<{
|
|
6
|
+
theme: Preferences["theme"];
|
|
7
|
+
animations?: Preferences["animations"];
|
|
8
|
+
}> | Readonly<{
|
|
9
|
+
theme?: Preferences["theme"];
|
|
10
|
+
animations: Preferences["animations"];
|
|
11
|
+
}>;
|
|
4
12
|
export type Theme = Preferences["theme"];
|
package/dist/ui-provider.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AppearanceUpdate } from "./appearance.js";
|
|
3
3
|
import { type Direction } from "./direction.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { PreferencesUpdate } from "./preferences.js";
|
|
5
5
|
export { useAppearance, useBrowserPreferences, usePreferences, useThemedValue } from "./appearance-context.js";
|
|
6
6
|
export { useDirection, useDocumentDirection } from "./direction.js";
|
|
7
7
|
/** Establishes only the explicitly supplied UI values for a React subtree. */
|
|
8
8
|
export declare function UIProvider({ appearance, children, direction, preferences }: UIProviderProps): ReactNode;
|
|
9
9
|
export interface UIProviderProps {
|
|
10
|
-
readonly appearance?:
|
|
10
|
+
readonly appearance?: AppearanceUpdate;
|
|
11
11
|
readonly children: ReactNode;
|
|
12
12
|
/** Establishes the concrete direction inherited by the provider subtree. */
|
|
13
13
|
readonly direction?: Direction;
|
|
14
|
-
readonly preferences?:
|
|
14
|
+
readonly preferences?: PreferencesUpdate;
|
|
15
15
|
}
|
package/dist/ui-provider.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
|
-
import { AppearanceContext, fixedPreferencesSource, PreferencesContext } from "./appearance-context.js";
|
|
3
|
+
import { AppearanceContext, fixedPreferencesSource, PreferencesContext, useAppearance, usePreferences } from "./appearance-context.js";
|
|
4
4
|
import { DirectionContext, fixedDirectionSource } from "./direction.js";
|
|
5
5
|
export { useAppearance, useBrowserPreferences, usePreferences, useThemedValue } from "./appearance-context.js";
|
|
6
6
|
export { useDirection, useDocumentDirection } from "./direction.js";
|
|
@@ -8,16 +8,55 @@ const directionBoundaryStyle = { display: "contents" };
|
|
|
8
8
|
/** Establishes only the explicitly supplied UI values for a React subtree. */
|
|
9
9
|
export function UIProvider({ appearance, children, direction, preferences }) {
|
|
10
10
|
let subtree = children;
|
|
11
|
-
const preferencesSource = useMemo(() => preferences === undefined ? undefined : fixedPreferencesSource(preferences), [preferences]);
|
|
12
11
|
const directionSource = useMemo(() => direction === undefined ? undefined : fixedDirectionSource(direction), [direction]);
|
|
13
|
-
if (
|
|
14
|
-
subtree = _jsx(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
subtree = _jsx(AppearanceContext.Provider, { value: appearance, children: subtree });
|
|
18
|
-
}
|
|
12
|
+
if (preferences !== undefined)
|
|
13
|
+
subtree = _jsx(PreferencesBoundary, { update: preferences, children: subtree });
|
|
14
|
+
if (appearance !== undefined)
|
|
15
|
+
subtree = _jsx(AppearanceBoundary, { update: appearance, children: subtree });
|
|
19
16
|
if (directionSource !== undefined) {
|
|
20
17
|
subtree = _jsx(DirectionContext.Provider, { value: directionSource, children: _jsx("div", { dir: direction, style: directionBoundaryStyle, children: subtree }) });
|
|
21
18
|
}
|
|
22
19
|
return subtree;
|
|
23
20
|
}
|
|
21
|
+
function AppearanceBoundary({ children, update }) {
|
|
22
|
+
const inherited = useAppearance();
|
|
23
|
+
const appearance = useMemo(() => mergeAppearance(inherited, update), [inherited, update]);
|
|
24
|
+
return _jsx(AppearanceContext.Provider, { value: appearance, children: children });
|
|
25
|
+
}
|
|
26
|
+
function PreferencesBoundary({ children, update }) {
|
|
27
|
+
if (update.theme !== undefined && update.animations !== undefined) {
|
|
28
|
+
// A complete boundary must not subscribe to the browser merely to obtain
|
|
29
|
+
// inherited fields that it already supplies itself.
|
|
30
|
+
return _jsx(CompletePreferencesBoundary, { theme: update.theme, animations: update.animations, children: children });
|
|
31
|
+
}
|
|
32
|
+
return _jsx(InheritedPreferencesBoundary, { update: update, children: children });
|
|
33
|
+
}
|
|
34
|
+
function CompletePreferencesBoundary({ animations, children, theme }) {
|
|
35
|
+
const preferences = useMemo(() => Object.freeze({ theme, animations }), [theme, animations]);
|
|
36
|
+
const source = useMemo(() => fixedPreferencesSource(preferences), [preferences]);
|
|
37
|
+
return _jsx(PreferencesContext.Provider, { value: source, children: children });
|
|
38
|
+
}
|
|
39
|
+
function InheritedPreferencesBoundary({ children, update }) {
|
|
40
|
+
const inherited = usePreferences();
|
|
41
|
+
const preferences = useMemo(() => Object.freeze({ ...inherited, ...update }), [inherited, update]);
|
|
42
|
+
const source = useMemo(() => fixedPreferencesSource(preferences), [preferences]);
|
|
43
|
+
return _jsx(PreferencesContext.Provider, { value: source, children: children });
|
|
44
|
+
}
|
|
45
|
+
function mergeAppearance(appearance, update) {
|
|
46
|
+
return Object.freeze({
|
|
47
|
+
colors: mergeThemed(appearance.colors, update.colors),
|
|
48
|
+
spacing: update.spacing ?? appearance.spacing,
|
|
49
|
+
radius: update.radius ?? appearance.radius,
|
|
50
|
+
shadow: mergeThemed(appearance.shadow, update.shadow),
|
|
51
|
+
material: mergeThemed(appearance.material, update.material),
|
|
52
|
+
transaction: Object.freeze({ ...appearance.transaction, ...update.transaction }),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function mergeThemed(current, update) {
|
|
56
|
+
if (update === undefined)
|
|
57
|
+
return current;
|
|
58
|
+
return Object.freeze({
|
|
59
|
+
light: Object.freeze({ ...current.light, ...update.light }),
|
|
60
|
+
dark: Object.freeze({ ...current.dark, ...update.dark })
|
|
61
|
+
});
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phreshos/react-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.32",
|
|
4
4
|
"description": "React components for coherent PhreshOS Program interfaces.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@base-ui/react": "^1.7.0",
|
|
59
59
|
"@internationalized/date": "^3.12.3",
|
|
60
|
-
"@phreshos/core": "^0.1.
|
|
60
|
+
"@phreshos/core": "^0.1.56",
|
|
61
61
|
"colorjs.io": "^0.7.1",
|
|
62
62
|
"motion": "^13.2.0",
|
|
63
63
|
"react-aria": "^3.51.0",
|