@opencode/ui 2.2.4 → 2.2.6
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/actions/button/button.d.ts +2 -2
- package/dist/actions/icon-button/icon-button.d.ts +1 -1
- package/dist/components/animated-number-machine.d.ts +95 -0
- package/dist/components/file-icon-machine.d.ts +40 -0
- package/dist/components/file-icon.d.ts +0 -2
- package/dist/components/file-icons/choose-icon-name.d.ts +2 -0
- package/dist/components/image-flight-machine.d.ts +135 -0
- package/dist/components/image-zoom-machine.d.ts +95 -0
- package/dist/components/image-zoom.d.ts +6 -3
- package/dist/components/list.d.ts +2 -6
- package/dist/components/menu-scroll.d.ts +12 -0
- package/dist/components/popover-machine.d.ts +96 -0
- package/dist/components/popover.d.ts +2 -2
- package/dist/components/resize-handle-machine.d.ts +71 -0
- package/dist/components/resize-handle.d.ts +2 -0
- package/dist/components/scroll-view-machine.d.ts +68 -0
- package/dist/components/scroll-view.d.ts +2 -2
- package/dist/components/spinner.d.ts +11 -3
- package/dist/components/text-field-machine.d.ts +62 -0
- package/dist/components/text-reveal-machine.d.ts +90 -0
- package/dist/components/typewriter-machine.d.ts +62 -0
- package/dist/context/dialog-machine.d.ts +125 -0
- package/dist/context/dialog.d.ts +17 -16
- package/dist/data-display/line-comment/line-comment.d.ts +9 -0
- package/dist/data-display/line-comment/machine.d.ts +157 -0
- package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
- package/dist/data-display/project-avatar/animation.d.ts +1 -1
- package/dist/feedback/activity-ring/activity-ring.d.ts +2 -1
- package/dist/feedback/toast/machine.d.ts +57 -0
- package/dist/feedback/toast/toast.d.ts +1 -1
- package/dist/forms/checkbox/checkbox.d.ts +6 -1
- package/dist/forms/select/machine.d.ts +45 -0
- package/dist/forms/select/select.d.ts +4 -0
- package/dist/forms/text-input/text-input.d.ts +4 -2
- package/dist/forms/textarea/textarea.d.ts +1 -0
- package/dist/forms/typeahead/machine.d.ts +85 -0
- package/dist/hooks/auto-scroll-machine.d.ts +89 -0
- package/dist/hooks/create-auto-scroll.d.ts +1 -1
- package/dist/hooks/list-machine.d.ts +150 -0
- package/dist/hooks/use-filtered-list.d.ts +21 -35
- package/dist/i18n/en.d.ts +5 -0
- package/dist/icons/catalog.d.ts +8 -0
- package/dist/navigation/menu/machine.d.ts +49 -0
- package/dist/navigation/menu/menu.d.ts +5 -3
- package/dist/navigation/segmented-control/machine.d.ts +46 -0
- package/dist/overlays/mcp-sign-in/machine.d.ts +184 -0
- package/dist/overlays/mcp-sign-in/mcp-sign-in.d.ts +40 -0
- package/dist/overlays/tooltip/machine.d.ts +146 -0
- package/dist/theme/context.d.ts +38 -14
- package/dist/theme/machine.d.ts +174 -0
- package/dist/typography/text-shimmer/machine.d.ts +48 -0
- package/package.json +19 -3
- package/src/actions/button/button.tsx +11 -6
- package/src/actions/icon-button/icon-button.tsx +17 -4
- package/src/components/animated-number-machine.ts +214 -0
- package/src/components/animated-number.tsx +134 -83
- package/src/components/file-icon-machine.ts +78 -0
- package/src/components/file-icon.tsx +96 -579
- package/src/components/file-icons/choose-icon-name.ts +574 -0
- package/src/components/image-flight-machine.ts +247 -0
- package/src/components/image-preview.css +5 -2
- package/src/components/image-preview.tsx +390 -252
- package/src/components/image-zoom-machine.ts +191 -0
- package/src/components/image-zoom.ts +22 -14
- package/src/components/list.tsx +46 -137
- package/src/components/menu-scroll.css +70 -0
- package/src/components/menu-scroll.tsx +161 -0
- package/src/components/popover-machine.ts +198 -0
- package/src/components/popover.tsx +157 -89
- package/src/components/resize-handle-machine.ts +174 -0
- package/src/components/resize-handle.tsx +116 -67
- package/src/components/scroll-view-machine.ts +244 -0
- package/src/components/scroll-view.tsx +163 -116
- package/src/components/spinner.css +18 -5
- package/src/components/spinner.tsx +28 -14
- package/src/components/text-field-machine.ts +102 -0
- package/src/components/text-field.tsx +78 -24
- package/src/components/text-reveal-machine.ts +184 -0
- package/src/components/text-reveal.tsx +96 -93
- package/src/components/typewriter-machine.ts +134 -0
- package/src/components/typewriter.tsx +50 -39
- package/src/context/dialog-machine.ts +280 -0
- package/src/context/dialog.tsx +168 -177
- package/src/data-display/line-comment/line-comment.tsx +196 -132
- package/src/data-display/line-comment/machine.ts +391 -0
- package/src/data-display/project-avatar/animation-machine.ts +182 -0
- package/src/data-display/project-avatar/animation.ts +67 -38
- package/src/feedback/activity-ring/activity-ring.tsx +1 -1
- package/src/feedback/toast/machine.ts +115 -0
- package/src/feedback/toast/toast.tsx +55 -59
- package/src/forms/checkbox/checkbox-compact.css +169 -0
- package/src/forms/checkbox/checkbox.tsx +93 -31
- package/src/forms/search-list/search-list.css +5 -1
- package/src/forms/search-list/search-list.tsx +4 -4
- package/src/forms/select/machine.ts +81 -0
- package/src/forms/select/select.css +59 -17
- package/src/forms/select/select.tsx +67 -31
- package/src/forms/text-input/text-input.css +30 -16
- package/src/forms/text-input/text-input.tsx +6 -2
- package/src/forms/textarea/textarea.css +13 -8
- package/src/forms/textarea/textarea.tsx +3 -1
- package/src/forms/typeahead/machine.ts +253 -0
- package/src/forms/typeahead/typeahead.tsx +75 -66
- package/src/hooks/auto-scroll-machine.ts +261 -0
- package/src/hooks/create-auto-scroll.tsx +110 -205
- package/src/hooks/list-machine.ts +359 -0
- package/src/hooks/use-filtered-list.tsx +101 -112
- package/src/i18n/en.ts +6 -1
- package/src/icons/catalog.ts +8 -0
- package/src/navigation/menu/machine.ts +109 -0
- package/src/navigation/menu/menu.tsx +130 -22
- package/src/navigation/segmented-control/machine.ts +72 -0
- package/src/navigation/segmented-control/segmented-control.tsx +46 -46
- package/src/overlays/dialog/dialog.tsx +7 -1
- package/src/overlays/mcp-sign-in/machine.ts +343 -0
- package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -0
- package/src/overlays/tooltip/machine.ts +303 -0
- package/src/overlays/tooltip/tooltip.tsx +157 -92
- package/src/styles/theme.css +10 -2
- package/src/styles/tokens/theme.css +13 -0
- package/src/theme/context.tsx +192 -269
- package/src/theme/machine.ts +508 -0
- package/src/theme/themes/oc-2.json +2 -0
- package/src/theme/v2/mapping.ts +12 -8
- package/src/typography/text-shimmer/machine.ts +90 -0
- package/src/typography/text-shimmer/text-shimmer.css +71 -39
- package/src/typography/text-shimmer/text-shimmer.tsx +41 -24
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { DesktopTheme } from "./types";
|
|
2
|
+
export type ColorScheme = "light" | "dark" | "system";
|
|
3
|
+
export type ResolvedMode = "light" | "dark";
|
|
4
|
+
export declare const DEFAULT_THEME_ID = "oc-2";
|
|
5
|
+
/** A bundled theme import that has not settled by then shows the default theme until it arrives. */
|
|
6
|
+
export declare const THEME_LOAD_TIMEOUT_MS = 5000;
|
|
7
|
+
export type ThemeSelection = {
|
|
8
|
+
readonly themeId: string;
|
|
9
|
+
readonly scheme: ColorScheme;
|
|
10
|
+
};
|
|
11
|
+
/** Overrides one or both axes of the committed selection; a preview with neither is `committed`. */
|
|
12
|
+
export type ThemePreview = {
|
|
13
|
+
readonly themeId?: string;
|
|
14
|
+
readonly scheme?: ColorScheme;
|
|
15
|
+
};
|
|
16
|
+
/** What the window shows. `preload` is a registered theme that may still arrive: the cached colors stay on screen. */
|
|
17
|
+
export type AppliedTheme = {
|
|
18
|
+
readonly kind: "theme";
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly theme: DesktopTheme;
|
|
21
|
+
readonly mode: ResolvedMode;
|
|
22
|
+
readonly scheme: ColorScheme;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "preload";
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly mode: ResolvedMode;
|
|
27
|
+
readonly scheme: ColorScheme;
|
|
28
|
+
};
|
|
29
|
+
/** The colors in localStorage that the next start paints before the app loads. `unknown` keeps the last run's. */
|
|
30
|
+
export type CachedTheme = {
|
|
31
|
+
readonly status: "unknown";
|
|
32
|
+
} | {
|
|
33
|
+
readonly status: "cleared";
|
|
34
|
+
} | {
|
|
35
|
+
readonly status: "cached";
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly theme: DesktopTheme;
|
|
38
|
+
};
|
|
39
|
+
type ThemeData = {
|
|
40
|
+
readonly committed: ThemeSelection;
|
|
41
|
+
readonly systemMode: ResolvedMode;
|
|
42
|
+
/** `settled` once every theme source has registered what it will: a missing registered theme is not coming. */
|
|
43
|
+
readonly registration: "pending" | "settled";
|
|
44
|
+
/** Loaded bundled themes and registered themes, by id. */
|
|
45
|
+
readonly themes: Readonly<Record<string, DesktopTheme>>;
|
|
46
|
+
/** The attempt of each bundled theme import in flight, including one that timed out and may still arrive. */
|
|
47
|
+
readonly loads: Readonly<Record<string, number>>;
|
|
48
|
+
/**
|
|
49
|
+
* Bundled themes the window shows the default theme for: the import failed, or timed out and may still arrive.
|
|
50
|
+
* Selecting, previewing or preloading one tries again.
|
|
51
|
+
*/
|
|
52
|
+
readonly failed: Readonly<Record<string, true>>;
|
|
53
|
+
readonly issued: number;
|
|
54
|
+
readonly applied: AppliedTheme | undefined;
|
|
55
|
+
readonly cached: CachedTheme;
|
|
56
|
+
};
|
|
57
|
+
export type ThemeMachineState = ({
|
|
58
|
+
readonly status: "committed";
|
|
59
|
+
} & ThemeData) | ({
|
|
60
|
+
readonly status: "previewing";
|
|
61
|
+
readonly preview: ThemePreview;
|
|
62
|
+
} & ThemeData) | ({
|
|
63
|
+
readonly status: "disposed";
|
|
64
|
+
} & ThemeData);
|
|
65
|
+
export type ThemeEvent = {
|
|
66
|
+
readonly type: "theme.selected";
|
|
67
|
+
readonly id: string;
|
|
68
|
+
} | {
|
|
69
|
+
readonly type: "scheme.selected";
|
|
70
|
+
readonly scheme: ColorScheme;
|
|
71
|
+
} | {
|
|
72
|
+
readonly type: "preview.theme";
|
|
73
|
+
readonly id: string;
|
|
74
|
+
} | {
|
|
75
|
+
readonly type: "preview.scheme";
|
|
76
|
+
readonly scheme: ColorScheme;
|
|
77
|
+
} | {
|
|
78
|
+
readonly type: "preview.committed";
|
|
79
|
+
} | {
|
|
80
|
+
readonly type: "preview.cancelled";
|
|
81
|
+
} | {
|
|
82
|
+
readonly type: "theme.registered";
|
|
83
|
+
readonly theme: DesktopTheme;
|
|
84
|
+
} | {
|
|
85
|
+
readonly type: "theme.unregistered";
|
|
86
|
+
readonly theme: DesktopTheme;
|
|
87
|
+
} | {
|
|
88
|
+
readonly type: "settled";
|
|
89
|
+
} | {
|
|
90
|
+
readonly type: "themes.preload";
|
|
91
|
+
} | {
|
|
92
|
+
readonly type: "theme.loaded";
|
|
93
|
+
readonly id: string;
|
|
94
|
+
readonly attempt: number;
|
|
95
|
+
readonly theme: DesktopTheme;
|
|
96
|
+
} | {
|
|
97
|
+
readonly type: "theme.load.failed";
|
|
98
|
+
readonly id: string;
|
|
99
|
+
readonly attempt: number;
|
|
100
|
+
} | {
|
|
101
|
+
readonly type: "theme.load.timed-out";
|
|
102
|
+
readonly id: string;
|
|
103
|
+
readonly attempt: number;
|
|
104
|
+
} | {
|
|
105
|
+
readonly type: "system.mode.changed";
|
|
106
|
+
readonly mode: ResolvedMode;
|
|
107
|
+
} | {
|
|
108
|
+
readonly type: "storage.theme.changed";
|
|
109
|
+
readonly id: string;
|
|
110
|
+
} | {
|
|
111
|
+
readonly type: "storage.scheme.changed";
|
|
112
|
+
readonly scheme: ColorScheme;
|
|
113
|
+
} | {
|
|
114
|
+
readonly type: "disposed";
|
|
115
|
+
};
|
|
116
|
+
export type ThemeEffect = {
|
|
117
|
+
readonly type: "load-theme";
|
|
118
|
+
readonly id: string;
|
|
119
|
+
readonly attempt: number;
|
|
120
|
+
readonly timeoutMs: number;
|
|
121
|
+
} | {
|
|
122
|
+
readonly type: "cancel-load-timer";
|
|
123
|
+
readonly attempt: number;
|
|
124
|
+
} | {
|
|
125
|
+
readonly type: "cancel-all-loads";
|
|
126
|
+
} | {
|
|
127
|
+
readonly type: "persist-theme";
|
|
128
|
+
readonly id: string;
|
|
129
|
+
} | {
|
|
130
|
+
readonly type: "persist-scheme";
|
|
131
|
+
readonly scheme: ColorScheme;
|
|
132
|
+
} | {
|
|
133
|
+
readonly type: "cache-theme";
|
|
134
|
+
readonly id: string;
|
|
135
|
+
readonly theme: DesktopTheme;
|
|
136
|
+
} | {
|
|
137
|
+
readonly type: "clear-cache";
|
|
138
|
+
} | {
|
|
139
|
+
readonly type: "apply-theme";
|
|
140
|
+
readonly id: string;
|
|
141
|
+
readonly theme: DesktopTheme;
|
|
142
|
+
readonly mode: ResolvedMode;
|
|
143
|
+
readonly scheme: ColorScheme;
|
|
144
|
+
} | {
|
|
145
|
+
readonly type: "notify-applied";
|
|
146
|
+
readonly mode: ResolvedMode;
|
|
147
|
+
readonly scheme: ColorScheme;
|
|
148
|
+
} | {
|
|
149
|
+
readonly type: "warn-missing-theme";
|
|
150
|
+
readonly id: string;
|
|
151
|
+
};
|
|
152
|
+
export type ThemeTransition = {
|
|
153
|
+
readonly state: ThemeMachineState;
|
|
154
|
+
readonly effects: readonly ThemeEffect[];
|
|
155
|
+
};
|
|
156
|
+
export declare function parseColorScheme(value: string | null | undefined): ColorScheme;
|
|
157
|
+
export declare function createThemeState(input: {
|
|
158
|
+
readonly themeId: string;
|
|
159
|
+
readonly scheme: ColorScheme;
|
|
160
|
+
readonly systemMode: ResolvedMode;
|
|
161
|
+
readonly defaultTheme: DesktopTheme;
|
|
162
|
+
readonly bundled: ReadonlySet<string>;
|
|
163
|
+
}): ThemeTransition;
|
|
164
|
+
export declare function transitionTheme(state: ThemeMachineState, event: ThemeEvent, bundled: ReadonlySet<string>): ThemeTransition;
|
|
165
|
+
/** The theme the window should show when nothing is previewed. */
|
|
166
|
+
export declare function selectCommittedThemeId(state: ThemeMachineState, bundled: ReadonlySet<string>): string;
|
|
167
|
+
export declare function selectThemeId(state: ThemeMachineState, bundled: ReadonlySet<string>): string;
|
|
168
|
+
/** The scheme the user chose; a preview does not change it. */
|
|
169
|
+
export declare function selectColorScheme(state: ThemeMachineState): ColorScheme;
|
|
170
|
+
/** The light or dark mode the window shows, preview included. */
|
|
171
|
+
export declare function selectMode(state: ThemeMachineState): ResolvedMode;
|
|
172
|
+
/** An import is still within its timeout. */
|
|
173
|
+
export declare function selectThemesLoading(state: ThemeMachineState): boolean;
|
|
174
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Matches the opacity crossfade in `text-shimmer.css`; the sweep keeps running until the shimmer layer has faded. */
|
|
2
|
+
export declare const TEXT_SHIMMER_SWAP_MS = 220;
|
|
3
|
+
/**
|
|
4
|
+
* `active` shows the shimmer layer and runs its sweep. `fading` has already crossfaded back to the plain text and only
|
|
5
|
+
* keeps the sweep running until the fade ends, so the layer never freezes mid-fade. `inactive` runs nothing.
|
|
6
|
+
*/
|
|
7
|
+
export type TextShimmerState = {
|
|
8
|
+
readonly status: "inactive";
|
|
9
|
+
readonly attempts: number;
|
|
10
|
+
} | {
|
|
11
|
+
readonly status: "active";
|
|
12
|
+
readonly attempts: number;
|
|
13
|
+
} | {
|
|
14
|
+
readonly status: "fading";
|
|
15
|
+
readonly attempt: number;
|
|
16
|
+
} | {
|
|
17
|
+
readonly status: "disposed";
|
|
18
|
+
};
|
|
19
|
+
export type TextShimmerEvent = {
|
|
20
|
+
readonly type: "sync";
|
|
21
|
+
readonly active: boolean;
|
|
22
|
+
readonly reducedMotion: boolean;
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "settled";
|
|
25
|
+
readonly attempt: number;
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "disposed";
|
|
28
|
+
};
|
|
29
|
+
export declare const INITIAL_INACTIVE_TEXT_SHIMMER_STATE: TextShimmerState;
|
|
30
|
+
export declare const INITIAL_ACTIVE_TEXT_SHIMMER_STATE: TextShimmerState;
|
|
31
|
+
export declare const DISPOSED_TEXT_SHIMMER_STATE: TextShimmerState;
|
|
32
|
+
export declare const DISPOSED_TEXT_SHIMMER_EVENT: TextShimmerEvent;
|
|
33
|
+
export declare function syncTextShimmerEvent(active: boolean, reducedMotion: boolean): TextShimmerEvent;
|
|
34
|
+
export declare function createTextShimmerState(active: boolean): TextShimmerState;
|
|
35
|
+
export declare function transitionTextShimmer(state: TextShimmerState, event: TextShimmerEvent): TextShimmerState;
|
|
36
|
+
/** Whether the shimmer layer is shown; drives the opacity crossfade. */
|
|
37
|
+
export declare function selectTextShimmerActive(state: TextShimmerState): state is {
|
|
38
|
+
readonly status: "active";
|
|
39
|
+
readonly attempts: number;
|
|
40
|
+
};
|
|
41
|
+
/** Whether the sweep animation runs; it outlives `active` by the crossfade. */
|
|
42
|
+
export declare function selectTextShimmerRunning(state: TextShimmerState): state is {
|
|
43
|
+
readonly status: "active";
|
|
44
|
+
readonly attempts: number;
|
|
45
|
+
} | {
|
|
46
|
+
readonly status: "fading";
|
|
47
|
+
readonly attempt: number;
|
|
48
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencode/ui",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -102,10 +102,22 @@
|
|
|
102
102
|
"import": "./src/data-display/line-comment/line-comment.tsx",
|
|
103
103
|
"types": "./dist/data-display/line-comment/line-comment.d.ts"
|
|
104
104
|
},
|
|
105
|
+
"./line-comment/machine": {
|
|
106
|
+
"import": "./src/data-display/line-comment/machine.ts",
|
|
107
|
+
"types": "./dist/data-display/line-comment/machine.d.ts"
|
|
108
|
+
},
|
|
105
109
|
"./loader": {
|
|
106
110
|
"import": "./src/feedback/loader/loader.tsx",
|
|
107
111
|
"types": "./dist/feedback/loader/loader.d.ts"
|
|
108
112
|
},
|
|
113
|
+
"./mcp-sign-in": {
|
|
114
|
+
"import": "./src/overlays/mcp-sign-in/mcp-sign-in.ts",
|
|
115
|
+
"types": "./dist/overlays/mcp-sign-in/mcp-sign-in.d.ts"
|
|
116
|
+
},
|
|
117
|
+
"./mcp-sign-in/machine": {
|
|
118
|
+
"import": "./src/overlays/mcp-sign-in/machine.ts",
|
|
119
|
+
"types": "./dist/overlays/mcp-sign-in/machine.d.ts"
|
|
120
|
+
},
|
|
109
121
|
"./menu": {
|
|
110
122
|
"import": "./src/navigation/menu/menu.tsx",
|
|
111
123
|
"types": "./dist/navigation/menu/menu.d.ts"
|
|
@@ -255,6 +267,10 @@
|
|
|
255
267
|
"import": "./src/components/file-icons/types.ts",
|
|
256
268
|
"types": "./dist/components/file-icons/types.d.ts"
|
|
257
269
|
},
|
|
270
|
+
"./icons/file-type-name": {
|
|
271
|
+
"import": "./src/components/file-icons/choose-icon-name.ts",
|
|
272
|
+
"types": "./dist/components/file-icons/choose-icon-name.d.ts"
|
|
273
|
+
},
|
|
258
274
|
"./icons/app": {
|
|
259
275
|
"import": "./src/components/app-icons/types.ts",
|
|
260
276
|
"types": "./dist/components/app-icons/types.d.ts"
|
|
@@ -269,11 +285,11 @@
|
|
|
269
285
|
"typecheck:tsc": "tsc --noEmit",
|
|
270
286
|
"test": "bun test src --only-failures",
|
|
271
287
|
"dev": "vite",
|
|
272
|
-
"bench:motion": "bun script/motion-bench.ts",
|
|
273
288
|
"generate:tailwind": "bun run script/tailwind.ts",
|
|
274
289
|
"generate:v2-oc2": "bun run script/build-oc2-v2-overrides.ts"
|
|
275
290
|
},
|
|
276
291
|
"devDependencies": {
|
|
292
|
+
"@hona/strobe": "0.14.0",
|
|
277
293
|
"@solidjs/meta": "0.29.4",
|
|
278
294
|
"@tsconfig/node22": "22.0.2",
|
|
279
295
|
"@types/bun": "1.4.3",
|
|
@@ -288,7 +304,7 @@
|
|
|
288
304
|
"dependencies": {
|
|
289
305
|
"@kitlangton/solid-motion": "0.2.2",
|
|
290
306
|
"@kobalte/core": "0.13.13",
|
|
291
|
-
"@opencode/util": "2.2.
|
|
307
|
+
"@opencode/util": "2.2.6",
|
|
292
308
|
"@pierre/diffs": "1.6.1",
|
|
293
309
|
"@pierre/highlights": "0.2.0",
|
|
294
310
|
"@solid-primitives/event-listener": "2.4.6",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Root } from "@kobalte/core/button"
|
|
1
|
+
import type { Root } from "@kobalte/core/button"
|
|
2
2
|
import { type ComponentProps, Show, splitProps } from "solid-js"
|
|
3
3
|
import { Icon, type IconProps } from "@opencode/ui/icon"
|
|
4
4
|
import "./button.css"
|
|
5
5
|
|
|
6
6
|
export interface ButtonProps
|
|
7
|
-
extends ComponentProps<typeof Root>,
|
|
8
|
-
Pick<ComponentProps<"button">, "class" | "classList" | "children"> {
|
|
7
|
+
extends Omit<ComponentProps<typeof Root>, "type">,
|
|
8
|
+
Pick<ComponentProps<"button">, "class" | "classList" | "children" | "type"> {
|
|
9
9
|
size?: "small" | "normal" | "large"
|
|
10
10
|
variant?:
|
|
11
11
|
| "neutral"
|
|
@@ -22,11 +22,16 @@ export interface ButtonProps
|
|
|
22
22
|
icon?: IconProps["name"]
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// A native button with the attributes Kobalte's Button sets on one, without its per-instance computations.
|
|
25
26
|
export function Button(props: ButtonProps) {
|
|
26
|
-
const [split, rest] = splitProps(props, ["variant", "size", "icon", "class", "classList"])
|
|
27
|
+
const [split, rest] = splitProps(props, ["variant", "size", "icon", "class", "classList", "disabled"])
|
|
27
28
|
|
|
28
29
|
return (
|
|
29
|
-
<
|
|
30
|
+
<button
|
|
31
|
+
// A type the caller passes in `rest` replaces this default.
|
|
32
|
+
type="button"
|
|
33
|
+
disabled={split.disabled}
|
|
34
|
+
data-disabled={split.disabled ? "" : undefined}
|
|
30
35
|
{...rest}
|
|
31
36
|
data-component="button-v2"
|
|
32
37
|
data-size={split.size || "normal"}
|
|
@@ -39,6 +44,6 @@ export function Button(props: ButtonProps) {
|
|
|
39
44
|
>
|
|
40
45
|
<Show when={split.icon}>{(icon) => <Icon name={icon()} />}</Show>
|
|
41
46
|
{props.children}
|
|
42
|
-
</
|
|
47
|
+
</button>
|
|
43
48
|
)
|
|
44
49
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Root } from "@kobalte/core/button"
|
|
1
|
+
import type { Root } from "@kobalte/core/button"
|
|
2
2
|
import { type ComponentProps, splitProps } from "solid-js"
|
|
3
3
|
import { JSX } from "solid-js"
|
|
4
4
|
import "./icon-button.css"
|
|
@@ -12,11 +12,24 @@ export interface IconButtonProps
|
|
|
12
12
|
state?: "rest" | "hover" | "pressed"
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
// A native button with the attributes Kobalte's Button sets on one, without its per-instance computations.
|
|
15
16
|
export function IconButton(props: ComponentProps<"button"> & IconButtonProps) {
|
|
16
|
-
const [local, rest] = splitProps(props, [
|
|
17
|
+
const [local, rest] = splitProps(props, [
|
|
18
|
+
"variant",
|
|
19
|
+
"size",
|
|
20
|
+
"icon",
|
|
21
|
+
"class",
|
|
22
|
+
"classList",
|
|
23
|
+
"state",
|
|
24
|
+
"type",
|
|
25
|
+
"disabled",
|
|
26
|
+
])
|
|
17
27
|
|
|
18
28
|
return (
|
|
19
|
-
<
|
|
29
|
+
<button
|
|
30
|
+
type={local.type ?? "button"}
|
|
31
|
+
disabled={local.disabled}
|
|
32
|
+
data-disabled={local.disabled ? "" : undefined}
|
|
20
33
|
{...rest}
|
|
21
34
|
data-component="icon-button-v2"
|
|
22
35
|
data-size={local.size || "normal"}
|
|
@@ -28,6 +41,6 @@ export function IconButton(props: ComponentProps<"button"> & IconButtonProps) {
|
|
|
28
41
|
}}
|
|
29
42
|
>
|
|
30
43
|
{local.icon}
|
|
31
|
-
</
|
|
44
|
+
</button>
|
|
32
45
|
)
|
|
33
46
|
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
export const ANIMATED_NUMBER_TRACK_LENGTH = 30
|
|
2
|
+
|
|
3
|
+
/** Added to the measured transition time before a roll or resize that never reported its end settles anyway. */
|
|
4
|
+
export const ANIMATED_NUMBER_FALLBACK_PAD_MS = 100
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `resizing` eases the width to `targetDigits` while extra leading places stay mounted to roll in or out. `attempt`
|
|
8
|
+
* names each eased change, so a fallback timer from an earlier one cannot cut the current one short.
|
|
9
|
+
*/
|
|
10
|
+
export type AnimatedNumberState =
|
|
11
|
+
| {
|
|
12
|
+
readonly status: "static"
|
|
13
|
+
readonly attempt: number
|
|
14
|
+
readonly value: number
|
|
15
|
+
readonly direction: 1 | -1
|
|
16
|
+
readonly places: number
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
readonly status: "resizing"
|
|
20
|
+
readonly attempt: number
|
|
21
|
+
readonly value: number
|
|
22
|
+
readonly direction: 1 | -1
|
|
23
|
+
readonly places: number
|
|
24
|
+
readonly targetDigits: number
|
|
25
|
+
}
|
|
26
|
+
| { readonly status: "disposed" }
|
|
27
|
+
|
|
28
|
+
/** `canAnimate` is false while detached or under reduced motion, where no transition runs to report its end. */
|
|
29
|
+
export type AnimatedNumberEvent =
|
|
30
|
+
| { readonly type: "value.changed"; readonly value: number; readonly canAnimate: boolean }
|
|
31
|
+
| { readonly type: "resize.ended" }
|
|
32
|
+
| { readonly type: "resize.timed-out"; readonly attempt: number }
|
|
33
|
+
| { readonly type: "disposed" }
|
|
34
|
+
|
|
35
|
+
export type AnimatedDigitState =
|
|
36
|
+
| { readonly status: "static"; readonly attempt: number; readonly digit: number; readonly step: number }
|
|
37
|
+
| { readonly status: "rolling"; readonly attempt: number; readonly digit: number; readonly step: number }
|
|
38
|
+
| { readonly status: "disposed" }
|
|
39
|
+
|
|
40
|
+
export type AnimatedDigitEvent =
|
|
41
|
+
| { readonly type: "digit.changed"; readonly digit: number; readonly direction: 1 | -1; readonly canAnimate: boolean }
|
|
42
|
+
| { readonly type: "roll.ended" }
|
|
43
|
+
| { readonly type: "roll.timed-out"; readonly attempt: number }
|
|
44
|
+
| { readonly type: "disposed" }
|
|
45
|
+
|
|
46
|
+
/** `watch` arms the fallback for an eased change; `clear` drops it once the change has settled. */
|
|
47
|
+
export type AnimatedNumberEffect = { readonly type: "watch"; readonly attempt: number } | { readonly type: "clear" }
|
|
48
|
+
|
|
49
|
+
export type AnimatedNumberTransition<State> = {
|
|
50
|
+
readonly state: State
|
|
51
|
+
readonly effects: readonly AnimatedNumberEffect[]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const NONE: readonly AnimatedNumberEffect[] = Object.freeze([])
|
|
55
|
+
|
|
56
|
+
const CLEAR: readonly AnimatedNumberEffect[] = Object.freeze([Object.freeze({ type: "clear" })])
|
|
57
|
+
|
|
58
|
+
const DISPOSED = Object.freeze({ status: "disposed" as const })
|
|
59
|
+
|
|
60
|
+
export function createAnimatedNumberState(value: number): AnimatedNumberState {
|
|
61
|
+
return { status: "static", attempt: 0, value, direction: 1, places: digits(value) + 1 }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function transitionAnimatedNumber(
|
|
65
|
+
state: AnimatedNumberState,
|
|
66
|
+
event: AnimatedNumberEvent,
|
|
67
|
+
): AnimatedNumberTransition<AnimatedNumberState> {
|
|
68
|
+
if (state.status === "disposed") return { state, effects: NONE }
|
|
69
|
+
|
|
70
|
+
switch (event.type) {
|
|
71
|
+
case "disposed":
|
|
72
|
+
return { state: DISPOSED, effects: state.status === "resizing" ? CLEAR : NONE }
|
|
73
|
+
case "value.changed": {
|
|
74
|
+
if (event.value === state.value) return { state, effects: NONE }
|
|
75
|
+
const direction = event.value > state.value ? 1 : -1
|
|
76
|
+
const count = digits(event.value)
|
|
77
|
+
|
|
78
|
+
if (!event.canAnimate)
|
|
79
|
+
return {
|
|
80
|
+
state: { status: "static", attempt: state.attempt, value: event.value, direction, places: count + 1 },
|
|
81
|
+
effects: state.status === "resizing" ? CLEAR : NONE,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Only a change to the digit count eases the width, so a late font swap or zoom never animates it.
|
|
85
|
+
if (count === (state.status === "resizing" ? state.targetDigits : digits(state.value)))
|
|
86
|
+
return { state: { ...state, value: event.value, direction }, effects: NONE }
|
|
87
|
+
|
|
88
|
+
const attempt = state.attempt + 1
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
state: {
|
|
92
|
+
status: "resizing",
|
|
93
|
+
attempt,
|
|
94
|
+
value: event.value,
|
|
95
|
+
direction,
|
|
96
|
+
places: Math.max(state.places, count + 1),
|
|
97
|
+
targetDigits: count,
|
|
98
|
+
},
|
|
99
|
+
effects: [{ type: "watch", attempt }],
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
case "resize.ended":
|
|
104
|
+
return settleNumber(state)
|
|
105
|
+
case "resize.timed-out":
|
|
106
|
+
if (state.status !== "resizing" || event.attempt !== state.attempt) return { state, effects: NONE }
|
|
107
|
+
|
|
108
|
+
return settleNumber(state)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function createAnimatedDigitState(digit: number): AnimatedDigitState {
|
|
113
|
+
return { status: "static", attempt: 0, digit, step: digit + 10 }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function transitionAnimatedDigit(
|
|
117
|
+
state: AnimatedDigitState,
|
|
118
|
+
event: AnimatedDigitEvent,
|
|
119
|
+
): AnimatedNumberTransition<AnimatedDigitState> {
|
|
120
|
+
if (state.status === "disposed") return { state, effects: NONE }
|
|
121
|
+
|
|
122
|
+
switch (event.type) {
|
|
123
|
+
case "disposed":
|
|
124
|
+
return { state: DISPOSED, effects: state.status === "rolling" ? CLEAR : NONE }
|
|
125
|
+
case "digit.changed": {
|
|
126
|
+
const delta = spin(state.digit, event.digit, event.direction)
|
|
127
|
+
|
|
128
|
+
// An unchanged digit keeps any roll it is in the middle of.
|
|
129
|
+
if (!delta) return { state, effects: NONE }
|
|
130
|
+
const target = state.step + delta
|
|
131
|
+
|
|
132
|
+
// Rapid changes can run off the track, so they settle at once like a digit that cannot animate.
|
|
133
|
+
if (!event.canAnimate || target < 0 || target >= ANIMATED_NUMBER_TRACK_LENGTH)
|
|
134
|
+
return {
|
|
135
|
+
state: { status: "static", attempt: state.attempt, digit: event.digit, step: event.digit + 10 },
|
|
136
|
+
effects: state.status === "rolling" ? CLEAR : NONE,
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const attempt = state.attempt + 1
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
state: { status: "rolling", attempt, digit: event.digit, step: target },
|
|
143
|
+
effects: [{ type: "watch", attempt }],
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
case "roll.ended":
|
|
148
|
+
return settleDigit(state)
|
|
149
|
+
case "roll.timed-out":
|
|
150
|
+
if (state.status !== "rolling" || event.attempt !== state.attempt) return { state, effects: NONE }
|
|
151
|
+
|
|
152
|
+
return settleDigit(state)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function selectAnimatedNumberValue(state: AnimatedNumberState) {
|
|
157
|
+
return state.status === "disposed" ? 0 : state.value
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function selectAnimatedNumberDirection(state: AnimatedNumberState) {
|
|
161
|
+
return state.status === "disposed" ? 1 : state.direction
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function selectAnimatedNumberPlaces(state: AnimatedNumberState) {
|
|
165
|
+
return state.status === "disposed" ? 1 : state.places
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function selectAnimatedNumberResizing(state: AnimatedNumberState) {
|
|
169
|
+
return state.status === "resizing"
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function selectAnimatedDigitRolling(state: AnimatedDigitState) {
|
|
173
|
+
return state.status === "rolling"
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function selectAnimatedDigitStep(state: AnimatedDigitState) {
|
|
177
|
+
return state.status === "disposed" ? 10 : state.step
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function settleNumber(state: Exclude<AnimatedNumberState, { status: "disposed" }>) {
|
|
181
|
+
if (state.status !== "resizing") return { state, effects: NONE }
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
state: {
|
|
185
|
+
status: "static" as const,
|
|
186
|
+
attempt: state.attempt,
|
|
187
|
+
value: state.value,
|
|
188
|
+
direction: state.direction,
|
|
189
|
+
places: state.targetDigits + 1,
|
|
190
|
+
},
|
|
191
|
+
effects: CLEAR,
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function settleDigit(state: Exclude<AnimatedDigitState, { status: "disposed" }>) {
|
|
196
|
+
if (state.status !== "rolling") return { state, effects: NONE }
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
state: { status: "static" as const, attempt: state.attempt, digit: state.digit, step: state.digit + 10 },
|
|
200
|
+
effects: CLEAR,
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function digits(value: number) {
|
|
205
|
+
return String(value).length
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function spin(from: number, to: number, direction: 1 | -1) {
|
|
209
|
+
if (from === to) return 0
|
|
210
|
+
|
|
211
|
+
if (direction > 0) return (to - from + 10) % 10
|
|
212
|
+
|
|
213
|
+
return -((from - to + 10) % 10)
|
|
214
|
+
}
|