@opencode/ui 0.0.0-dev-583 → 0.0.0-dev-605
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/components/list.d.ts +0 -6
- package/dist/components/menu-scroll.d.ts +9 -3
- package/dist/hooks/list-machine.d.ts +118 -0
- package/dist/hooks/use-filtered-list.d.ts +21 -35
- package/package.json +2 -2
- package/src/components/list.tsx +40 -137
- package/src/components/menu-scroll.css +19 -8
- package/src/components/menu-scroll.tsx +49 -15
- package/src/forms/search-list/search-list.css +5 -1
- package/src/forms/search-list/search-list.tsx +4 -4
- package/src/forms/select/select.css +8 -3
- package/src/forms/select/select.tsx +6 -1
- package/src/hooks/list-machine.ts +301 -0
- package/src/hooks/use-filtered-list.tsx +95 -119
|
@@ -12,10 +12,6 @@ export interface ListAddProps {
|
|
|
12
12
|
class?: string;
|
|
13
13
|
render: () => JSX.Element;
|
|
14
14
|
}
|
|
15
|
-
export interface ListAddProps {
|
|
16
|
-
class?: string;
|
|
17
|
-
render: () => JSX.Element;
|
|
18
|
-
}
|
|
19
15
|
export interface ListProps<T> extends FilteredListProps<T> {
|
|
20
16
|
class?: string;
|
|
21
17
|
children: (item: T) => JSX.Element;
|
|
@@ -23,9 +19,7 @@ export interface ListProps<T> extends FilteredListProps<T> {
|
|
|
23
19
|
loadingMessage?: string;
|
|
24
20
|
onKeyEvent?: (event: KeyboardEvent, item: T | undefined) => void;
|
|
25
21
|
onMove?: (item: T | undefined) => void;
|
|
26
|
-
onFilter?: (value: string) => void;
|
|
27
22
|
activeIcon?: IconProps["name"];
|
|
28
|
-
filter?: string;
|
|
29
23
|
search?: ListSearchProps | boolean;
|
|
30
24
|
itemWrapper?: (item: T, node: JSX.Element) => JSX.Element;
|
|
31
25
|
divider?: boolean;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import { type ComponentProps } from "solid-js";
|
|
1
|
+
import { type ComponentProps, type JSX } from "solid-js";
|
|
2
2
|
import "./menu-scroll.css";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A scroll container for menus, popovers and dialog lists. It hides the native scrollbar and draws the shared thumb
|
|
5
|
+
* over the content, so rows keep equal start and end padding whether or not the list overflows. Touch devices and
|
|
6
|
+
* high-contrast modes keep the native scrollbar.
|
|
7
|
+
*/
|
|
8
|
+
export declare function MenuScroll(props: Omit<ComponentProps<"div">, "ref" | "onScroll" | "onFocusIn"> & {
|
|
4
9
|
viewportClass?: string;
|
|
5
10
|
viewportRef?: (element: HTMLDivElement) => void;
|
|
6
|
-
|
|
11
|
+
onScroll?: JSX.EventHandler<HTMLDivElement, Event>;
|
|
12
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export type ListGroup<T> = {
|
|
2
|
+
category: string;
|
|
3
|
+
items: T[];
|
|
4
|
+
};
|
|
5
|
+
export type ListConfig<T> = {
|
|
6
|
+
readonly key: (item: T) => string;
|
|
7
|
+
readonly filterKeys?: string[];
|
|
8
|
+
readonly skipFilter?: (item: T) => boolean;
|
|
9
|
+
readonly groupBy?: (item: T) => string;
|
|
10
|
+
readonly sortBy?: (a: T, b: T) => number;
|
|
11
|
+
readonly sortGroupsBy?: (a: ListGroup<T>, b: ListGroup<T>) => number;
|
|
12
|
+
};
|
|
13
|
+
/** The one copy of the query. A `controlled` list shows the parent's `filter` prop and only reports edits. */
|
|
14
|
+
export type ListFilter = {
|
|
15
|
+
readonly type: "uncontrolled" | "controlled";
|
|
16
|
+
readonly query: string;
|
|
17
|
+
};
|
|
18
|
+
/** `mouse` while the pointer drives the highlight, so the list does not scroll under it. */
|
|
19
|
+
export type ListHighlight = {
|
|
20
|
+
readonly mode: "keyboard" | "mouse";
|
|
21
|
+
readonly activeKey: string | null;
|
|
22
|
+
};
|
|
23
|
+
type ListData<T> = {
|
|
24
|
+
readonly filter: ListFilter;
|
|
25
|
+
readonly groups: ListGroup<T>[];
|
|
26
|
+
readonly rows: T[];
|
|
27
|
+
readonly keys: string[];
|
|
28
|
+
readonly highlight: ListHighlight;
|
|
29
|
+
};
|
|
30
|
+
/** `loading` keeps the last rows on screen; `epoch` is the last attempt that settled. */
|
|
31
|
+
export type ListState<T> = (ListData<T> & {
|
|
32
|
+
readonly status: "ready";
|
|
33
|
+
readonly epoch: number;
|
|
34
|
+
}) | (ListData<T> & {
|
|
35
|
+
readonly status: "loading";
|
|
36
|
+
readonly attempt: number;
|
|
37
|
+
});
|
|
38
|
+
export type ListKeyDown = {
|
|
39
|
+
readonly type: "key.down";
|
|
40
|
+
readonly key: string;
|
|
41
|
+
readonly ctrl: boolean;
|
|
42
|
+
readonly alt: boolean;
|
|
43
|
+
readonly meta: boolean;
|
|
44
|
+
readonly shift: boolean;
|
|
45
|
+
readonly composing: boolean;
|
|
46
|
+
/** A search input keeps Home, End and Tab for the text field. */
|
|
47
|
+
readonly search: boolean;
|
|
48
|
+
/** Escape, or a key the caller's `onKeyEvent` already handled. */
|
|
49
|
+
readonly claimed: boolean;
|
|
50
|
+
};
|
|
51
|
+
export type ListEvent<T> = {
|
|
52
|
+
readonly type: "query.change";
|
|
53
|
+
readonly value: string;
|
|
54
|
+
readonly force?: boolean;
|
|
55
|
+
} | {
|
|
56
|
+
readonly type: "filter.controlled";
|
|
57
|
+
readonly value: string;
|
|
58
|
+
} | {
|
|
59
|
+
readonly type: "filter.uncontrolled";
|
|
60
|
+
} | {
|
|
61
|
+
readonly type: "items.reload";
|
|
62
|
+
} | {
|
|
63
|
+
readonly type: "load.resolved";
|
|
64
|
+
readonly attempt: number;
|
|
65
|
+
readonly items: T[];
|
|
66
|
+
} | {
|
|
67
|
+
readonly type: "load.failed";
|
|
68
|
+
readonly attempt: number;
|
|
69
|
+
} | {
|
|
70
|
+
readonly type: "pointer.move";
|
|
71
|
+
readonly key: string;
|
|
72
|
+
readonly moved: boolean;
|
|
73
|
+
} | {
|
|
74
|
+
readonly type: "pointer.leave";
|
|
75
|
+
} | {
|
|
76
|
+
readonly type: "active.set";
|
|
77
|
+
readonly key: string | null;
|
|
78
|
+
} | {
|
|
79
|
+
readonly type: "active.reset";
|
|
80
|
+
} | ListKeyDown;
|
|
81
|
+
export type ListEffect<T> = {
|
|
82
|
+
readonly type: "load";
|
|
83
|
+
readonly attempt: number;
|
|
84
|
+
readonly query: string;
|
|
85
|
+
} | {
|
|
86
|
+
readonly type: "notify.filter";
|
|
87
|
+
readonly value: string;
|
|
88
|
+
} | {
|
|
89
|
+
readonly type: "select";
|
|
90
|
+
readonly item: T;
|
|
91
|
+
readonly index: number;
|
|
92
|
+
};
|
|
93
|
+
export type ListTransition<T> = {
|
|
94
|
+
readonly state: ListState<T>;
|
|
95
|
+
readonly effects: ListEffect<T>[];
|
|
96
|
+
readonly handled: boolean;
|
|
97
|
+
};
|
|
98
|
+
export declare function createListState<T>(filter?: string): ListState<T>;
|
|
99
|
+
export declare function transitionList<T>(state: ListState<T>, event: ListEvent<T>, config: ListConfig<T>): ListTransition<T>;
|
|
100
|
+
/** The highlighted row and its index among all rows. */
|
|
101
|
+
export declare function listActive<T>(state: Pick<ListState<T>, "rows" | "keys" | "highlight">): {
|
|
102
|
+
item: T;
|
|
103
|
+
index: number;
|
|
104
|
+
} | undefined;
|
|
105
|
+
/** Where the list scrolls to keep the keyboard highlight in view; the pointer never scrolls it. */
|
|
106
|
+
export declare function listScrollTarget<T>(state: Pick<ListState<T>, "keys" | "highlight">): {
|
|
107
|
+
type: "none";
|
|
108
|
+
} | {
|
|
109
|
+
type: "top";
|
|
110
|
+
} | {
|
|
111
|
+
type: "item";
|
|
112
|
+
key: string;
|
|
113
|
+
};
|
|
114
|
+
export declare function groupItems<T>(items: T[], config: Pick<ListConfig<T>, "groupBy" | "sortBy" | "sortGroupsBy">): {
|
|
115
|
+
category: string;
|
|
116
|
+
items: T[];
|
|
117
|
+
}[];
|
|
118
|
+
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type ListEvent, type ListGroup } from "./list-machine";
|
|
2
|
+
export { groupItems } from "./list-machine";
|
|
1
3
|
export interface FilteredListProps<T> {
|
|
2
4
|
items: T[] | ((filter: string) => T[] | Promise<T[]>);
|
|
3
5
|
key: (item: T) => string;
|
|
@@ -5,47 +7,31 @@ export interface FilteredListProps<T> {
|
|
|
5
7
|
current?: T;
|
|
6
8
|
groupBy?: (x: T) => string;
|
|
7
9
|
sortBy?: (a: T, b: T) => number;
|
|
8
|
-
sortGroupsBy?: (a:
|
|
9
|
-
category: string;
|
|
10
|
-
items: T[];
|
|
11
|
-
}, b: {
|
|
12
|
-
category: string;
|
|
13
|
-
items: T[];
|
|
14
|
-
}) => number;
|
|
10
|
+
sortGroupsBy?: (a: ListGroup<T>, b: ListGroup<T>) => number;
|
|
15
11
|
skipFilter?: (item: T) => boolean;
|
|
16
12
|
onSelect?: (value: T | undefined, index: number) => void;
|
|
13
|
+
/** Makes the query parent-owned: the list shows this value and reports edits through `onFilter`. */
|
|
14
|
+
filter?: string;
|
|
15
|
+
onFilter?: (value: string) => void;
|
|
17
16
|
}
|
|
18
|
-
export declare function groupItems<T>(items: T[], props: Pick<FilteredListProps<T>, "groupBy" | "sortBy" | "sortGroupsBy">): {
|
|
19
|
-
category: string;
|
|
20
|
-
items: T[];
|
|
21
|
-
}[];
|
|
22
17
|
export declare function useFilteredList<T>(props: FilteredListProps<T>): {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
filter: ()
|
|
18
|
+
state: import("solid-js").Accessor<import("./list-machine").ListState<T>>;
|
|
19
|
+
dispatch: (event: ListEvent<T>, keyboard?: KeyboardEvent) => void;
|
|
20
|
+
grouped: {
|
|
21
|
+
readonly latest: ListGroup<T>[];
|
|
22
|
+
readonly loading: boolean;
|
|
23
|
+
readonly state: "ready" | "refreshing";
|
|
24
|
+
};
|
|
25
|
+
filter: import("solid-js").Accessor<string>;
|
|
31
26
|
flat: import("solid-js").Accessor<T[]>;
|
|
27
|
+
active: import("solid-js").Accessor<string | null>;
|
|
32
28
|
reset: () => void;
|
|
33
|
-
refetch: (
|
|
34
|
-
category: string;
|
|
35
|
-
items: [T, ...T[]];
|
|
36
|
-
}[] | {
|
|
37
|
-
category: string;
|
|
38
|
-
items: T[];
|
|
39
|
-
}[] | Promise<{
|
|
40
|
-
category: string;
|
|
41
|
-
items: [T, ...T[]];
|
|
42
|
-
}[] | {
|
|
43
|
-
category: string;
|
|
44
|
-
items: T[];
|
|
45
|
-
}[]> | null | undefined;
|
|
29
|
+
refetch: () => void;
|
|
46
30
|
clear: () => void;
|
|
47
|
-
onKeyDown: (event: KeyboardEvent) => void;
|
|
48
31
|
onInput: (value: string) => void;
|
|
49
|
-
|
|
50
|
-
|
|
32
|
+
setActive: (key: string | null) => void;
|
|
33
|
+
onKeyDown: (event: KeyboardEvent, options?: {
|
|
34
|
+
search?: boolean;
|
|
35
|
+
claimed?: boolean;
|
|
36
|
+
}) => void;
|
|
51
37
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencode/ui",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-605",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -288,7 +288,7 @@
|
|
|
288
288
|
"dependencies": {
|
|
289
289
|
"@kitlangton/solid-motion": "0.2.2",
|
|
290
290
|
"@kobalte/core": "0.13.13",
|
|
291
|
-
"@opencode/util": "0.0.0-dev-
|
|
291
|
+
"@opencode/util": "0.0.0-dev-605",
|
|
292
292
|
"@pierre/diffs": "1.6.1",
|
|
293
293
|
"@pierre/highlights": "0.2.0",
|
|
294
294
|
"@solid-primitives/event-listener": "2.4.6",
|
package/src/components/list.tsx
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type FilteredListProps, useFilteredList } from "@opencode/ui/hooks"
|
|
2
|
-
import { createEffect, For, type JSX, on, Show } from "solid-js"
|
|
2
|
+
import { createEffect, createMemo, createSignal, For, type JSX, on, Show } from "solid-js"
|
|
3
3
|
import { createStore } from "solid-js/store"
|
|
4
4
|
import { makeEventListener } from "@solid-primitives/event-listener"
|
|
5
5
|
import { useI18n } from "../context/i18n"
|
|
6
|
+
import { listActive, listScrollTarget } from "../hooks/list-machine"
|
|
6
7
|
import { Icon, type IconProps } from "@opencode/ui/icon"
|
|
7
8
|
import { IconButton } from "@opencode/ui/icon-button"
|
|
8
9
|
import { TextField } from "./text-field"
|
|
@@ -28,11 +29,6 @@ export interface ListAddProps {
|
|
|
28
29
|
render: () => JSX.Element
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
export interface ListAddProps {
|
|
32
|
-
class?: string
|
|
33
|
-
render: () => JSX.Element
|
|
34
|
-
}
|
|
35
|
-
|
|
36
32
|
export interface ListProps<T> extends FilteredListProps<T> {
|
|
37
33
|
class?: string
|
|
38
34
|
children: (item: T) => JSX.Element
|
|
@@ -40,9 +36,7 @@ export interface ListProps<T> extends FilteredListProps<T> {
|
|
|
40
36
|
loadingMessage?: string
|
|
41
37
|
onKeyEvent?: (event: KeyboardEvent, item: T | undefined) => void
|
|
42
38
|
onMove?: (item: T | undefined) => void
|
|
43
|
-
onFilter?: (value: string) => void
|
|
44
39
|
activeIcon?: IconProps["name"]
|
|
45
|
-
filter?: string
|
|
46
40
|
search?: ListSearchProps | boolean
|
|
47
41
|
itemWrapper?: (item: T, node: JSX.Element) => JSX.Element
|
|
48
42
|
divider?: boolean
|
|
@@ -60,16 +54,7 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
|
|
|
60
54
|
const i18n = useI18n()
|
|
61
55
|
let inputRef: HTMLInputElement | HTMLTextAreaElement | undefined
|
|
62
56
|
|
|
63
|
-
const [
|
|
64
|
-
mouseActive: false,
|
|
65
|
-
scrollRef: undefined as HTMLDivElement | undefined,
|
|
66
|
-
internalFilter: "",
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
const scrollRef = () => store.scrollRef
|
|
70
|
-
const setScrollRef = (el: HTMLDivElement | undefined) => setStore("scrollRef", el)
|
|
71
|
-
const internalFilter = () => store.internalFilter
|
|
72
|
-
const setInternalFilter = (value: string) => setStore("internalFilter", value)
|
|
57
|
+
const [scrollRef, setScrollRef] = createSignal<HTMLDivElement>()
|
|
73
58
|
|
|
74
59
|
const scrollIntoView = (container: HTMLDivElement, node: HTMLElement, block: "center" | "nearest") => {
|
|
75
60
|
const containerRect = container.getBoundingClientRect()
|
|
@@ -92,121 +77,43 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
|
|
|
92
77
|
container.scrollTop = Math.max(0, Math.min(target, max))
|
|
93
78
|
}
|
|
94
79
|
|
|
95
|
-
const
|
|
80
|
+
const list = useFilteredList<T>(props)
|
|
81
|
+
const keys = createMemo(() => list.state().keys)
|
|
82
|
+
const highlight = createMemo(() => list.state().highlight)
|
|
96
83
|
|
|
97
|
-
const searchProps = () => (
|
|
84
|
+
const searchProps = () => (props.search && props.search !== true ? props.search : {})
|
|
98
85
|
const searchAction = () => searchProps().action
|
|
99
86
|
const addProps = () => props.add
|
|
100
87
|
const showAdd = () => !!addProps()
|
|
101
88
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const applyFilter = (value: string, options?: { ref?: boolean }) => {
|
|
105
|
-
const prev = filter()
|
|
106
|
-
setInternalFilter(value)
|
|
107
|
-
onInput(value)
|
|
108
|
-
props.onFilter?.(value)
|
|
109
|
-
|
|
110
|
-
if (!options?.ref) return
|
|
111
|
-
|
|
112
|
-
// Force a refetch even if the value is unchanged.
|
|
113
|
-
// This is important for programmatic changes like Tab completion.
|
|
114
|
-
if (prev === value) {
|
|
115
|
-
void refetch()
|
|
116
|
-
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
queueMicrotask(() => refetch())
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
createEffect(() => {
|
|
124
|
-
if (props.filter === undefined) return
|
|
125
|
-
|
|
126
|
-
if (props.filter === internalFilter()) return
|
|
127
|
-
setInternalFilter(props.filter)
|
|
128
|
-
onInput(props.filter)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
createEffect(
|
|
132
|
-
on(
|
|
133
|
-
filter,
|
|
134
|
-
() => {
|
|
135
|
-
scrollRef()?.scrollTo(0, 0)
|
|
136
|
-
},
|
|
137
|
-
{ defer: true },
|
|
138
|
-
),
|
|
139
|
-
)
|
|
89
|
+
createEffect(on(list.filter, () => scrollRef()?.scrollTo(0, 0), { defer: true }))
|
|
140
90
|
|
|
141
91
|
createEffect(() => {
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
if (store.mouseActive || all.length === 0) return
|
|
92
|
+
const target = listScrollTarget({ keys: keys(), highlight: highlight() })
|
|
145
93
|
const scroll = scrollRef()
|
|
146
94
|
|
|
147
|
-
if (!scroll) return
|
|
148
|
-
|
|
149
|
-
if (active() === props.key(all[0])) {
|
|
150
|
-
scroll.scrollTo(0, 0)
|
|
151
|
-
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const key = active()
|
|
95
|
+
if (!scroll || target.type === "none") return
|
|
156
96
|
|
|
157
|
-
if (
|
|
158
|
-
const element = findByKey(scroll, key)
|
|
97
|
+
if (target.type === "top") return scroll.scrollTo(0, 0)
|
|
98
|
+
const element = findByKey(scroll, target.key)
|
|
159
99
|
|
|
160
|
-
if (
|
|
161
|
-
scrollIntoView(scroll, element, "center")
|
|
100
|
+
if (element) scrollIntoView(scroll, element, "center")
|
|
162
101
|
})
|
|
163
102
|
|
|
164
|
-
|
|
165
|
-
const all = flat()
|
|
166
|
-
const current = active()
|
|
167
|
-
const item = all.find((x) => props.key(x) === current)
|
|
168
|
-
props.onMove?.(item)
|
|
169
|
-
})
|
|
103
|
+
const activeItem = createMemo(() => listActive(list.state())?.item)
|
|
170
104
|
|
|
171
|
-
|
|
172
|
-
props.onSelect?.(item, index)
|
|
173
|
-
}
|
|
105
|
+
createEffect(() => props.onMove?.(activeItem()))
|
|
174
106
|
|
|
175
107
|
const handleKey = (e: KeyboardEvent) => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (e.key === "Escape") return
|
|
179
|
-
|
|
180
|
-
const all = flat()
|
|
181
|
-
const selected = all.find((x) => props.key(x) === active())
|
|
182
|
-
const index = selected ? all.indexOf(selected) : -1
|
|
183
|
-
props.onKeyEvent?.(e, selected)
|
|
184
|
-
|
|
185
|
-
if (e.defaultPrevented) return
|
|
186
|
-
|
|
187
|
-
if (e.key === "Enter" && !e.isComposing) {
|
|
188
|
-
e.preventDefault()
|
|
189
|
-
|
|
190
|
-
if (selected) handleSelect(selected, index)
|
|
191
|
-
} else if (props.search) {
|
|
192
|
-
if (e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey && (e.key === "n" || e.key === "p")) {
|
|
193
|
-
onKeyDown(e)
|
|
194
|
-
|
|
195
|
-
return
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
199
|
-
onKeyDown(e)
|
|
200
|
-
}
|
|
201
|
-
} else {
|
|
202
|
-
onKeyDown(e)
|
|
203
|
-
}
|
|
108
|
+
if (e.key !== "Escape") props.onKeyEvent?.(e, activeItem())
|
|
109
|
+
list.onKeyDown(e, { search: !!props.search, claimed: e.key === "Escape" || e.defaultPrevented })
|
|
204
110
|
}
|
|
205
111
|
|
|
206
112
|
props.ref?.({
|
|
207
113
|
onKeyDown: handleKey,
|
|
208
114
|
setScrollRef,
|
|
209
|
-
|
|
115
|
+
// Forces a reload even when the value is unchanged, for programmatic changes like Tab completion.
|
|
116
|
+
setFilter: (value) => list.dispatch({ type: "query.change", value, force: true }),
|
|
210
117
|
})
|
|
211
118
|
|
|
212
119
|
const renderAdd = () => {
|
|
@@ -222,10 +129,7 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
|
|
|
222
129
|
}
|
|
223
130
|
|
|
224
131
|
function GroupHeader(groupProps: { group: { category: string; items: T[] } }): JSX.Element {
|
|
225
|
-
const [state, setState] = createStore({
|
|
226
|
-
stuck: false,
|
|
227
|
-
header: undefined as HTMLDivElement | undefined,
|
|
228
|
-
})
|
|
132
|
+
const [state, setState] = createStore<{ stuck: boolean; header?: HTMLDivElement }>({ stuck: false })
|
|
229
133
|
|
|
230
134
|
createEffect(() => {
|
|
231
135
|
const scroll = scrollRef()
|
|
@@ -251,11 +155,11 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
|
|
|
251
155
|
}
|
|
252
156
|
|
|
253
157
|
const emptyMessage = () => {
|
|
254
|
-
if (grouped.loading) return props.loadingMessage ?? i18n.t("ui.list.loading")
|
|
158
|
+
if (list.grouped.loading) return props.loadingMessage ?? i18n.t("ui.list.loading")
|
|
255
159
|
|
|
256
160
|
if (props.emptyMessage) return props.emptyMessage
|
|
257
161
|
|
|
258
|
-
const query = filter()
|
|
162
|
+
const query = list.filter()
|
|
259
163
|
|
|
260
164
|
if (!query) return i18n.t("ui.list.empty")
|
|
261
165
|
|
|
@@ -304,8 +208,8 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
|
|
|
304
208
|
ref={(el: HTMLInputElement | HTMLTextAreaElement) => {
|
|
305
209
|
inputRef = el
|
|
306
210
|
}}
|
|
307
|
-
value={
|
|
308
|
-
onChange={(value) =>
|
|
211
|
+
value={list.filter()}
|
|
212
|
+
onChange={(value) => list.onInput(value)}
|
|
309
213
|
onKeyDown={handleKey}
|
|
310
214
|
placeholder={searchProps().placeholder}
|
|
311
215
|
spellcheck={false}
|
|
@@ -314,12 +218,12 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
|
|
|
314
218
|
autocapitalize="off"
|
|
315
219
|
/>
|
|
316
220
|
</div>
|
|
317
|
-
<Show when={
|
|
221
|
+
<Show when={list.filter()}>
|
|
318
222
|
<IconButton
|
|
319
223
|
icon={<Icon name="circle-x" />}
|
|
320
224
|
variant="ghost"
|
|
321
225
|
onClick={() => {
|
|
322
|
-
|
|
226
|
+
list.clear()
|
|
323
227
|
queueMicrotask(() => inputRef?.focus())
|
|
324
228
|
}}
|
|
325
229
|
aria-label={i18n.t("ui.list.clearFilter")}
|
|
@@ -331,16 +235,16 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
|
|
|
331
235
|
</Show>
|
|
332
236
|
<div ref={setScrollRef} data-slot="list-scroll">
|
|
333
237
|
<Show
|
|
334
|
-
when={flat().length > 0 || showAdd()}
|
|
238
|
+
when={list.flat().length > 0 || showAdd()}
|
|
335
239
|
fallback={
|
|
336
240
|
<div data-slot="list-empty-state">
|
|
337
241
|
<div data-slot="list-message">{emptyMessage()}</div>
|
|
338
242
|
</div>
|
|
339
243
|
}
|
|
340
244
|
>
|
|
341
|
-
<For each={grouped.latest}>
|
|
245
|
+
<For each={list.grouped.latest}>
|
|
342
246
|
{(group, groupIndex) => {
|
|
343
|
-
const isLastGroup = () => groupIndex() === grouped.latest.length - 1
|
|
247
|
+
const isLastGroup = () => groupIndex() === list.grouped.latest.length - 1
|
|
344
248
|
|
|
345
249
|
return (
|
|
346
250
|
<div data-slot="list-group">
|
|
@@ -354,20 +258,19 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
|
|
|
354
258
|
<button
|
|
355
259
|
data-slot="list-item"
|
|
356
260
|
data-key={props.key(item)}
|
|
357
|
-
data-active={props.key(item) === active()}
|
|
261
|
+
data-active={props.key(item) === list.active()}
|
|
358
262
|
data-selected={item === props.current}
|
|
359
|
-
onClick={() =>
|
|
263
|
+
onClick={() => props.onSelect?.(item, i())}
|
|
360
264
|
onKeyDown={handleKey}
|
|
361
265
|
type="button"
|
|
362
|
-
onMouseMove={(event) =>
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}}
|
|
266
|
+
onMouseMove={(event) =>
|
|
267
|
+
list.dispatch({
|
|
268
|
+
type: "pointer.move",
|
|
269
|
+
key: props.key(item),
|
|
270
|
+
moved: event.movementX !== 0 || event.movementY !== 0,
|
|
271
|
+
})
|
|
272
|
+
}
|
|
273
|
+
onMouseLeave={() => list.dispatch({ type: "pointer.leave" })}
|
|
371
274
|
>
|
|
372
275
|
{props.children(item)}
|
|
373
276
|
<Show when={item === props.current}>
|
|
@@ -401,7 +304,7 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
|
|
|
401
304
|
)
|
|
402
305
|
}}
|
|
403
306
|
</For>
|
|
404
|
-
<Show when={grouped.latest.length === 0 && showAdd()}>
|
|
307
|
+
<Show when={list.grouped.latest.length === 0 && showAdd()}>
|
|
405
308
|
<div data-slot="list-group">
|
|
406
309
|
<div data-slot="list-items">{renderAdd()}</div>
|
|
407
310
|
</div>
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
isolation: isolate;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
[data-
|
|
10
|
+
[data-component="menu-scroll"] > [data-scrollable] {
|
|
11
11
|
min-height: 0;
|
|
12
12
|
overflow-y: auto;
|
|
13
13
|
}
|
|
@@ -16,12 +16,13 @@
|
|
|
16
16
|
display: none;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
/* High-contrast modes keep the native scrollbar, which follows the system colours. */
|
|
20
|
+
@media (hover: hover) and (pointer: fine) and (forced-colors: none) {
|
|
21
|
+
[data-component="menu-scroll"] > [data-scrollable] {
|
|
21
22
|
scrollbar-width: none;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
[data-
|
|
25
|
+
[data-component="menu-scroll"] > [data-scrollable]::-webkit-scrollbar {
|
|
25
26
|
display: none;
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
pointer-events: none;
|
|
37
38
|
touch-action: none;
|
|
38
39
|
user-select: none;
|
|
40
|
+
transition: opacity 200ms ease;
|
|
39
41
|
|
|
40
42
|
&::after {
|
|
41
43
|
position: absolute;
|
|
@@ -45,15 +47,24 @@
|
|
|
45
47
|
content: "";
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
&:hover::after
|
|
49
|
-
&[data-dragging]::after {
|
|
50
|
+
&:hover::after {
|
|
50
51
|
background: var(--v2-border-border-strong);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
[data-component="menu-scroll"]:
|
|
55
|
-
[data-slot="menu-scroll-thumb"]
|
|
55
|
+
[data-component="menu-scroll"]:is([data-scrolling], [data-dragging]) > [data-slot="menu-scroll-thumb"],
|
|
56
|
+
[data-slot="menu-scroll-thumb"]:hover {
|
|
56
57
|
opacity: 1;
|
|
57
58
|
pointer-events: auto;
|
|
58
59
|
}
|
|
60
|
+
|
|
61
|
+
[data-component="menu-scroll"][data-dragging] > [data-slot="menu-scroll-thumb"]::after {
|
|
62
|
+
background: var(--v2-border-border-strong);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@media (prefers-reduced-motion: reduce) {
|
|
67
|
+
[data-slot="menu-scroll-thumb"] {
|
|
68
|
+
transition: none;
|
|
69
|
+
}
|
|
59
70
|
}
|