@opencode/ui 0.0.0-dev-794 → 0.0.0-dev-821

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.
@@ -0,0 +1,40 @@
1
+ import type { IconName } from "./file-icons/types";
2
+ export declare const FILE_ICON_LOAD_TIMEOUT_MS = 10000;
3
+ /** Bundled with the component, so they are always in the sprite and stand in for an icon that failed to load. */
4
+ export type FallbackIconName = "Document" | "Folder" | "FolderOpen";
5
+ /**
6
+ * Lifecycle of one lazy `<symbol>` in the in-document sprite, shared by every mounted icon with that name. It only
7
+ * moves forward: Chromium keeps a failed dynamic import failed for the page's lifetime, so a retry cannot succeed.
8
+ */
9
+ export type FileIconSymbolState = {
10
+ readonly status: "unrequested" | "loading" | "failed" | "ready";
11
+ };
12
+ export type FileIconSymbolEvent = {
13
+ readonly type: "requested";
14
+ } | {
15
+ readonly type: "load.succeeded";
16
+ readonly svg: string;
17
+ } | {
18
+ readonly type: "load.failed";
19
+ } | {
20
+ readonly type: "load.timed-out";
21
+ };
22
+ export type FileIconSymbolEffect = {
23
+ readonly type: "load";
24
+ } | {
25
+ readonly type: "insert-symbol";
26
+ readonly svg: string;
27
+ } | {
28
+ readonly type: "cancel-timeout";
29
+ };
30
+ export type FileIconSymbolTransition = {
31
+ readonly state: FileIconSymbolState;
32
+ readonly effects: readonly FileIconSymbolEffect[];
33
+ };
34
+ export declare const INITIAL_FILE_ICON_SYMBOL_STATE: FileIconSymbolState;
35
+ export declare const READY_FILE_ICON_SYMBOL_STATE: FileIconSymbolState;
36
+ export declare const FILE_ICON_REQUESTED: FileIconSymbolEvent;
37
+ export declare function transitionFileIconSymbol(state: FileIconSymbolState, event: FileIconSymbolEvent): FileIconSymbolTransition;
38
+ export declare function chooseFallbackIconName(type: "directory" | "file", expanded: boolean): FallbackIconName;
39
+ /** The symbol a mounted icon shows: its own unless it failed to load. */
40
+ export declare function selectFileIconSymbol(state: FileIconSymbolState, name: IconName, fallback: FallbackIconName): IconName;
@@ -17,6 +17,8 @@ export interface ListProps<T> extends FilteredListProps<T> {
17
17
  children: (item: T) => JSX.Element;
18
18
  emptyMessage?: string;
19
19
  loadingMessage?: string;
20
+ /** Shown when an async `items` loader rejects or times out. */
21
+ errorMessage?: string;
20
22
  onKeyEvent?: (event: KeyboardEvent, item: T | undefined) => void;
21
23
  onMove?: (item: T | undefined) => void;
22
24
  activeIcon?: IconProps["name"];
@@ -61,6 +61,8 @@ export declare function overflowChanged(vertical: boolean, horizontal: boolean):
61
61
  export declare function transitionScrollThumb(state: ScrollThumbState, event: ScrollThumbEvent): ScrollThumbTransition;
62
62
  export declare function selectShowVerticalThumb(state: ScrollThumbState): boolean;
63
63
  export declare function selectShowHorizontalThumb(state: ScrollThumbState): boolean;
64
+ /** Scroll-only reveal: a drag shows the thumb through `selectDraggingAxis` instead. */
65
+ export declare function selectThumbScrolling(state: ScrollThumbState): boolean;
64
66
  export declare function selectDraggingAxis(state: ScrollThumbState): ScrollAxis | undefined;
65
67
  /** `hoverReveals` is the `hover` visibility mode; in `scroll` mode only scrolling and dragging show the thumb. */
66
68
  export declare function selectThumbVisible(state: ScrollThumbState, hoverReveals: boolean): boolean;
@@ -0,0 +1,62 @@
1
+ export declare const TYPEWRITER_INITIAL_DELAY_MS = 200;
2
+ export declare const TYPEWRITER_LINGER_MS = 2000;
3
+ export type TypewriterCursor = "none" | "solid" | "blinking";
4
+ /**
5
+ * `typing` shows the first `index` characters behind a solid cursor; `index` 0 is the pause before the first one.
6
+ * `lingering` shows the whole text behind a blinking cursor, then `done` hides the cursor.
7
+ */
8
+ export type TypewriterState = {
9
+ readonly status: "empty";
10
+ readonly attempts: number;
11
+ } | {
12
+ readonly status: "typing";
13
+ readonly attempt: number;
14
+ readonly text: string;
15
+ /** Code points, so a step never shows half of a surrogate pair. */
16
+ readonly chars: readonly string[];
17
+ readonly index: number;
18
+ } | {
19
+ readonly status: "lingering";
20
+ readonly attempt: number;
21
+ readonly text: string;
22
+ } | {
23
+ readonly status: "done";
24
+ readonly attempts: number;
25
+ readonly text: string;
26
+ } | {
27
+ readonly status: "disposed";
28
+ };
29
+ export type TypewriterEvent = {
30
+ readonly type: "sync";
31
+ readonly text: string | undefined;
32
+ readonly reducedMotion: boolean;
33
+ } | {
34
+ readonly type: "typing.step";
35
+ readonly attempt: number;
36
+ } | {
37
+ readonly type: "linger.ended";
38
+ readonly attempt: number;
39
+ } | {
40
+ readonly type: "disposed";
41
+ };
42
+ export type TypewriterEffect = {
43
+ readonly type: "none";
44
+ } | {
45
+ readonly type: "clear";
46
+ } | {
47
+ readonly type: "schedule";
48
+ readonly kind: "initial" | "step" | "linger";
49
+ readonly attempt: number;
50
+ };
51
+ export type TypewriterTransition = {
52
+ readonly state: TypewriterState;
53
+ readonly effect: TypewriterEffect;
54
+ };
55
+ export declare const INITIAL_EMPTY_TYPEWRITER_STATE: TypewriterState;
56
+ export declare const DISPOSED_TYPEWRITER_STATE: TypewriterState;
57
+ export declare const DISPOSED_TYPEWRITER_EVENT: TypewriterEvent;
58
+ /** Mostly quick keystrokes, with an occasional hesitation. `roll` and `jitter` are uniform in [0, 1). */
59
+ export declare function typingStepDelayMs(roll: number, jitter: number): number;
60
+ export declare function transitionTypewriter(state: TypewriterState, event: TypewriterEvent): TypewriterTransition;
61
+ export declare function selectTypewriterDisplayed(state: TypewriterState): string;
62
+ export declare function selectTypewriterCursor(state: TypewriterState): TypewriterCursor;
@@ -1,3 +1,5 @@
1
+ /** How long an async `items(query)` may run before the list reports it failed rather than loading forever. */
2
+ export declare const LIST_LOAD_TIMEOUT_MS = 15000;
1
3
  export type ListGroup<T> = {
2
4
  category: string;
3
5
  items: T[];
@@ -27,13 +29,19 @@ type ListData<T> = {
27
29
  readonly keys: string[];
28
30
  readonly highlight: ListHighlight;
29
31
  };
30
- /** `loading` keeps the last rows on screen; `epoch` is the last attempt that settled. */
32
+ /**
33
+ * `loading` keeps the last rows on screen; `epoch` is the last attempt that settled. `failed` means the current
34
+ * query's async load rejected or timed out, which the list reports instead of "No results". `disposed` keeps the last
35
+ * data for readers that run during cleanup and ignores every event.
36
+ */
31
37
  export type ListState<T> = (ListData<T> & {
32
- readonly status: "ready";
38
+ readonly status: "ready" | "failed";
33
39
  readonly epoch: number;
34
40
  }) | (ListData<T> & {
35
41
  readonly status: "loading";
36
42
  readonly attempt: number;
43
+ }) | (ListData<T> & {
44
+ readonly status: "disposed";
37
45
  });
38
46
  export type ListKeyDown = {
39
47
  readonly type: "key.down";
@@ -66,6 +74,9 @@ export type ListEvent<T> = {
66
74
  } | {
67
75
  readonly type: "load.failed";
68
76
  readonly attempt: number;
77
+ } | {
78
+ readonly type: "load.timed-out";
79
+ readonly attempt: number;
69
80
  } | {
70
81
  readonly type: "pointer.move";
71
82
  readonly key: string;
@@ -77,11 +88,17 @@ export type ListEvent<T> = {
77
88
  readonly key: string | null;
78
89
  } | {
79
90
  readonly type: "active.reset";
91
+ } | {
92
+ readonly type: "disposed";
80
93
  } | ListKeyDown;
81
94
  export type ListEffect<T> = {
82
95
  readonly type: "load";
83
96
  readonly attempt: number;
84
97
  readonly query: string;
98
+ }
99
+ /** Stops the settled or abandoned attempt's timeout. */
100
+ | {
101
+ readonly type: "cancel.load";
85
102
  } | {
86
103
  readonly type: "notify.filter";
87
104
  readonly value: string;
@@ -90,6 +107,14 @@ export type ListEffect<T> = {
90
107
  readonly item: T;
91
108
  readonly index: number;
92
109
  };
110
+ export type ListEmptyState = {
111
+ readonly type: "loading";
112
+ } | {
113
+ readonly type: "failed";
114
+ } | {
115
+ readonly type: "empty";
116
+ readonly query: string;
117
+ };
93
118
  export type ListTransition<T> = {
94
119
  readonly state: ListState<T>;
95
120
  readonly effects: ListEffect<T>[];
@@ -97,6 +122,13 @@ export type ListTransition<T> = {
97
122
  };
98
123
  export declare function createListState<T>(filter?: string): ListState<T>;
99
124
  export declare function transitionList<T>(state: ListState<T>, event: ListEvent<T>, config: ListConfig<T>): ListTransition<T>;
125
+ export declare function selectListLoading<T>(state: ListState<T>): state is ListData<T> & {
126
+ readonly status: "loading";
127
+ readonly attempt: number;
128
+ };
129
+ export declare function selectListFailed<T>(state: ListState<T>): boolean;
130
+ /** What the list says when it has no rows to show. */
131
+ export declare function selectListEmptyState<T>(state: ListState<T>): ListEmptyState;
100
132
  /** The highlighted row and its index among all rows. */
101
133
  export declare function listActive<T>(state: Pick<ListState<T>, "rows" | "keys" | "highlight">): {
102
134
  item: T;
@@ -20,7 +20,7 @@ export declare function useFilteredList<T>(props: FilteredListProps<T>): {
20
20
  grouped: {
21
21
  readonly latest: ListGroup<T>[];
22
22
  readonly loading: boolean;
23
- readonly state: "ready" | "refreshing";
23
+ readonly state: "ready" | "refreshing" | "errored";
24
24
  };
25
25
  filter: import("solid-js").Accessor<string>;
26
26
  flat: import("solid-js").Accessor<T[]>;
package/dist/i18n/en.d.ts CHANGED
@@ -138,6 +138,7 @@ declare const source: {
138
138
  "ui.messagePart.tools.used.other": string;
139
139
  "ui.list.loading": string;
140
140
  "ui.list.empty": string;
141
+ "ui.list.failed": string;
141
142
  "ui.list.clearFilter": string;
142
143
  "ui.list.emptyWithFilter.prefix": string;
143
144
  "ui.list.emptyWithFilter.suffix": string;
@@ -0,0 +1,184 @@
1
+ /** Delay between OAuth status polls while the attempt is pending or the server is unreachable. */
2
+ export declare const MCP_SIGN_IN_POLL_MS = 1000;
3
+ /** How long the MCP server and resource sync after a sign-in may run before it shows a retryable error. */
4
+ export declare const MCP_SIGN_IN_SYNC_TIMEOUT_MS = 30000;
5
+ /** The server's answer to a status poll of the sign-in attempt. */
6
+ export type McpSignInAttemptStatus = {
7
+ readonly status: "pending" | "complete" | "expired";
8
+ } | {
9
+ readonly status: "failed";
10
+ readonly message: string;
11
+ };
12
+ export type McpSignInPollOutcome = {
13
+ readonly status: "pending";
14
+ } | {
15
+ readonly status: "complete";
16
+ } | {
17
+ readonly status: "failed";
18
+ readonly message: string;
19
+ } | {
20
+ readonly status: "expired";
21
+ }
22
+ /** The status request threw; the attempt may still be open on the server until its lifetime ends. */
23
+ | {
24
+ readonly status: "unreachable";
25
+ readonly message: string;
26
+ };
27
+ export type McpSignInEntryError = {
28
+ readonly type: "required";
29
+ } | {
30
+ readonly type: "rejected";
31
+ readonly message: string;
32
+ };
33
+ export type McpSignInFailure = {
34
+ readonly type: "auth-expired";
35
+ } | {
36
+ readonly type: "auth-failed";
37
+ readonly message: string;
38
+ }
39
+ /** The sign-in succeeded, but reloading the MCP lists failed; a retry reloads them again. */
40
+ | {
41
+ readonly type: "sync-failed";
42
+ readonly message: string;
43
+ } | {
44
+ readonly type: "sync-timed-out";
45
+ };
46
+ /**
47
+ * An MCP sign-in that also accepts the redirect URL pasted from the browser. Requests take attempt numbers from
48
+ * `issued`, so a result whose attempt the state no longer holds is stale.
49
+ */
50
+ export type McpSignInState = {
51
+ readonly status: "waiting";
52
+ readonly url: string;
53
+ readonly issued: number;
54
+ readonly pollAttempt: number;
55
+ readonly value: string;
56
+ /** The server accepted a pasted redirect URL and finishes the sign-in; the status poll reports the outcome. */
57
+ readonly pasteAccepted: boolean;
58
+ readonly entryError: McpSignInEntryError | undefined;
59
+ /** The last status request failed; shown if the attempt's lifetime ends before the server answers again. */
60
+ readonly unreachableError: string | undefined;
61
+ } | {
62
+ readonly status: "submitting";
63
+ readonly url: string;
64
+ readonly issued: number;
65
+ readonly pollAttempt: number;
66
+ readonly submitAttempt: number;
67
+ readonly value: string;
68
+ readonly unreachableError: string | undefined;
69
+ }
70
+ /** The sign-in succeeded; the MCP server and resource lists reload before the dialog closes. */
71
+ | {
72
+ readonly status: "completing";
73
+ readonly url: string;
74
+ readonly issued: number;
75
+ readonly syncAttempt: number;
76
+ } | {
77
+ readonly status: "failed";
78
+ readonly url: string;
79
+ readonly issued: number;
80
+ readonly failure: McpSignInFailure;
81
+ } | {
82
+ readonly status: "done";
83
+ } | {
84
+ readonly status: "disposed";
85
+ };
86
+ export type McpSignInEvent = {
87
+ readonly type: "browser.open";
88
+ } | {
89
+ readonly type: "paste.changed";
90
+ readonly value: string;
91
+ } | {
92
+ readonly type: "paste.submitted";
93
+ } | {
94
+ readonly type: "polled";
95
+ readonly pollAttempt: number;
96
+ readonly outcome: McpSignInPollOutcome;
97
+ } | {
98
+ readonly type: "submit.succeeded";
99
+ readonly submitAttempt: number;
100
+ } | {
101
+ readonly type: "submit.failed";
102
+ readonly submitAttempt: number;
103
+ readonly message: string;
104
+ }
105
+ /** The attempt's lifetime ended before the server reported an outcome. */
106
+ | {
107
+ readonly type: "waiting.timed-out";
108
+ } | {
109
+ readonly type: "sync.succeeded";
110
+ readonly syncAttempt: number;
111
+ } | {
112
+ readonly type: "sync.failed";
113
+ readonly syncAttempt: number;
114
+ readonly message: string;
115
+ } | {
116
+ readonly type: "sync.timed-out";
117
+ readonly syncAttempt: number;
118
+ } | {
119
+ readonly type: "retry.requested";
120
+ } | {
121
+ readonly type: "disposed";
122
+ };
123
+ export type McpSignInEffect = {
124
+ readonly type: "deadline.start";
125
+ readonly delayMs: number;
126
+ } | {
127
+ readonly type: "deadline.clear";
128
+ }
129
+ /** Aborts the poll in flight or scheduled, then polls the attempt's status after `delayMs`. */
130
+ | {
131
+ readonly type: "poll";
132
+ readonly pollAttempt: number;
133
+ readonly delayMs: number;
134
+ } | {
135
+ readonly type: "poll.abort";
136
+ } | {
137
+ readonly type: "submit";
138
+ readonly submitAttempt: number;
139
+ readonly code: string;
140
+ } | {
141
+ readonly type: "submit.abort";
142
+ }
143
+ /** Reloads the MCP server and resource lists, reporting back within `timeoutMs`. */
144
+ | {
145
+ readonly type: "sync";
146
+ readonly syncAttempt: number;
147
+ readonly timeoutMs: number;
148
+ } | {
149
+ readonly type: "sync.clear";
150
+ }
151
+ /** Reloads the MCP lists without reporting back, for a sign-in the server finishes after the dialog closed. */
152
+ | {
153
+ readonly type: "refresh";
154
+ } | {
155
+ readonly type: "open-external";
156
+ readonly url: string;
157
+ }
158
+ /** Ends the attempt on the server, so a late browser callback cannot connect the server. */
159
+ | {
160
+ readonly type: "cancel";
161
+ } | {
162
+ readonly type: "close";
163
+ };
164
+ export type McpSignInTransition = {
165
+ readonly state: McpSignInState;
166
+ readonly effects: readonly McpSignInEffect[];
167
+ };
168
+ export declare function startMcpSignIn(input: {
169
+ url: string;
170
+ lifetimeMs: number;
171
+ }): McpSignInTransition;
172
+ export declare function transitionMcpSignIn(state: McpSignInState, event: McpSignInEvent): McpSignInTransition;
173
+ export declare function selectMcpSignInView(state: McpSignInState): {
174
+ status: "completing" | "disposed" | "done" | "failed" | "submitting" | "waiting";
175
+ failure: McpSignInFailure | undefined;
176
+ canRetry: boolean;
177
+ showOpenBrowser: boolean;
178
+ showForm: boolean;
179
+ value: string;
180
+ entryError: McpSignInEntryError | undefined;
181
+ locked: boolean;
182
+ submitting: boolean;
183
+ };
184
+ export type McpSignInView = ReturnType<typeof selectMcpSignInView>;
@@ -0,0 +1,40 @@
1
+ import { type McpSignInAttemptStatus, type McpSignInEvent } from "./machine";
2
+ export type { McpSignInAttemptStatus, McpSignInFailure, McpSignInView } from "./machine";
3
+ /** The server and host calls of one MCP sign-in; the app and the details plugin bind them to their own SDK. */
4
+ export type McpSignInHost = {
5
+ /** The authorization URL the browser opens. */
6
+ url: string;
7
+ /** The attempt's lifetime in milliseconds, from the server's `time`; the two clocks may disagree. */
8
+ lifetime: number;
9
+ /** Polls the attempt's status. */
10
+ status: (signal: AbortSignal) => Promise<McpSignInAttemptStatus>;
11
+ /** Sends a redirect URL pasted from the browser. */
12
+ complete: (code: string, signal: AbortSignal) => Promise<void>;
13
+ /** Ends the attempt on the server. */
14
+ cancel: () => Promise<void>;
15
+ /** Reloads the MCP server and resource lists after the sign-in succeeded. */
16
+ sync: () => Promise<void>;
17
+ openExternal: (url: string) => void;
18
+ /** Closes the dialog once the lists reloaded. */
19
+ close: () => void;
20
+ /** The text shown for a failed request. The SDK and the data layer reject with an `Error`. */
21
+ message: (error: Error) => string;
22
+ };
23
+ /**
24
+ * Drives an MCP sign-in dialog's machine for the owner's lifetime: polls the attempt, sends a pasted redirect URL,
25
+ * reloads the MCP lists once it succeeded, and cancels an attempt still open when the owner is disposed.
26
+ */
27
+ export declare function createMcpSignIn(host: McpSignInHost): {
28
+ view: import("solid-js").Accessor<{
29
+ status: "completing" | "disposed" | "done" | "failed" | "submitting" | "waiting";
30
+ failure: import("./machine").McpSignInFailure | undefined;
31
+ canRetry: boolean;
32
+ showOpenBrowser: boolean;
33
+ showForm: boolean;
34
+ value: string;
35
+ entryError: import("./machine").McpSignInEntryError | undefined;
36
+ locked: boolean;
37
+ submitting: boolean;
38
+ }>;
39
+ dispatch: (event: McpSignInEvent) => void;
40
+ };
@@ -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": "0.0.0-dev-794",
3
+ "version": "0.0.0-dev-821",
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"
@@ -288,7 +300,7 @@
288
300
  "dependencies": {
289
301
  "@kitlangton/solid-motion": "0.2.2",
290
302
  "@kobalte/core": "0.13.13",
291
- "@opencode/util": "0.0.0-dev-794",
303
+ "@opencode/util": "0.0.0-dev-821",
292
304
  "@pierre/diffs": "1.6.1",
293
305
  "@pierre/highlights": "0.2.0",
294
306
  "@solid-primitives/event-listener": "2.4.6",
@@ -0,0 +1,78 @@
1
+ import type { IconName } from "./file-icons/types"
2
+
3
+ export const FILE_ICON_LOAD_TIMEOUT_MS = 10_000
4
+
5
+ /** Bundled with the component, so they are always in the sprite and stand in for an icon that failed to load. */
6
+ export type FallbackIconName = "Document" | "Folder" | "FolderOpen"
7
+
8
+ /**
9
+ * Lifecycle of one lazy `<symbol>` in the in-document sprite, shared by every mounted icon with that name. It only
10
+ * moves forward: Chromium keeps a failed dynamic import failed for the page's lifetime, so a retry cannot succeed.
11
+ */
12
+ export type FileIconSymbolState = { readonly status: "unrequested" | "loading" | "failed" | "ready" }
13
+
14
+ export type FileIconSymbolEvent =
15
+ | { readonly type: "requested" }
16
+ | { readonly type: "load.succeeded"; readonly svg: string }
17
+ | { readonly type: "load.failed" }
18
+ | { readonly type: "load.timed-out" }
19
+
20
+ export type FileIconSymbolEffect =
21
+ | { readonly type: "load" }
22
+ | { readonly type: "insert-symbol"; readonly svg: string }
23
+ | { readonly type: "cancel-timeout" }
24
+
25
+ export type FileIconSymbolTransition = {
26
+ readonly state: FileIconSymbolState
27
+ readonly effects: readonly FileIconSymbolEffect[]
28
+ }
29
+
30
+ const UNREQUESTED: FileIconSymbolState = Object.freeze({ status: "unrequested" })
31
+
32
+ const LOADING: FileIconSymbolState = Object.freeze({ status: "loading" })
33
+
34
+ const FAILED: FileIconSymbolState = Object.freeze({ status: "failed" })
35
+
36
+ const READY: FileIconSymbolState = Object.freeze({ status: "ready" })
37
+
38
+ export const INITIAL_FILE_ICON_SYMBOL_STATE = UNREQUESTED
39
+
40
+ export const READY_FILE_ICON_SYMBOL_STATE = READY
41
+
42
+ export const FILE_ICON_REQUESTED: FileIconSymbolEvent = Object.freeze({ type: "requested" })
43
+
44
+ const NONE: readonly FileIconSymbolEffect[] = Object.freeze([])
45
+
46
+ const LOAD: readonly FileIconSymbolEffect[] = Object.freeze([{ type: "load" }])
47
+
48
+ const CANCEL: readonly FileIconSymbolEffect[] = Object.freeze([{ type: "cancel-timeout" }])
49
+
50
+ export function transitionFileIconSymbol(
51
+ state: FileIconSymbolState,
52
+ event: FileIconSymbolEvent,
53
+ ): FileIconSymbolTransition {
54
+ if (state.status === "unrequested" && event.type === "requested") return { state: LOADING, effects: LOAD }
55
+
56
+ // A symbol that arrives after its timeout still upgrades the icons showing the fallback.
57
+ if ((state.status === "loading" || state.status === "failed") && event.type === "load.succeeded")
58
+ return {
59
+ state: READY,
60
+ effects: [...(state.status === "loading" ? CANCEL : NONE), { type: "insert-symbol", svg: event.svg }],
61
+ }
62
+
63
+ if (state.status === "loading" && (event.type === "load.failed" || event.type === "load.timed-out"))
64
+ return { state: FAILED, effects: CANCEL }
65
+
66
+ return { state, effects: NONE }
67
+ }
68
+
69
+ export function chooseFallbackIconName(type: "directory" | "file", expanded: boolean): FallbackIconName {
70
+ if (type === "file") return "Document"
71
+
72
+ return expanded ? "FolderOpen" : "Folder"
73
+ }
74
+
75
+ /** The symbol a mounted icon shows: its own unless it failed to load. */
76
+ export function selectFileIconSymbol(state: FileIconSymbolState, name: IconName, fallback: FallbackIconName): IconName {
77
+ return state.status === "failed" ? fallback : name
78
+ }