@opencode/ui 0.0.0-dev-21864 → 0.0.0-dev-21875
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type SpringOptions } from "@kitlangton/solid-motion";
|
|
2
2
|
type Opt = Partial<Pick<SpringOptions, "visualDuration" | "bounce" | "stiffness" | "damping" | "mass" | "velocity">>;
|
|
3
|
-
export declare function useSpring(target: () => number, options?: Opt | (() => Opt), snapKey?: () =>
|
|
3
|
+
export declare function useSpring<K>(target: () => number, options?: Opt | (() => Opt), snapKey?: () => K): import("solid-js").Accessor<number>;
|
|
4
4
|
export {};
|
package/dist/context/i18n.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export type UiI18n = UiI18nSource & {
|
|
|
25
25
|
export declare function pluralCategory(locale: string, count: number): UiPluralCategory;
|
|
26
26
|
export declare function pluralKey(key: UiI18nPluralKey, category: UiPluralCategory): UiI18nPluralLookupKey;
|
|
27
27
|
export declare function localizedListSeparator(locale: string, index: number, count: number): string;
|
|
28
|
+
export declare function resolveTemplate(text: string, params?: UiI18nParams): string;
|
|
28
29
|
export declare function createUiI18n(source: UiI18nSource): UiI18n;
|
|
29
30
|
declare function UiI18nProvider(props: ParentProps<{
|
|
30
31
|
value: UiI18nSource;
|
|
@@ -16,13 +16,17 @@ export interface FilteredListProps<T> {
|
|
|
16
16
|
onSelect?: (value: T | undefined, index: number) => void;
|
|
17
17
|
noInitialSelection?: boolean;
|
|
18
18
|
}
|
|
19
|
+
export declare function groupItems<T>(items: T[], props: Pick<FilteredListProps<T>, "groupBy" | "sortBy" | "sortGroupsBy">): {
|
|
20
|
+
category: string;
|
|
21
|
+
items: T[];
|
|
22
|
+
}[];
|
|
19
23
|
export declare function useFilteredList<T>(props: FilteredListProps<T>): {
|
|
20
24
|
grouped: import("solid-js").InitializedResource<{
|
|
21
25
|
category: string;
|
|
22
26
|
items: [T, ...T[]];
|
|
23
27
|
}[] | {
|
|
24
28
|
category: string;
|
|
25
|
-
items:
|
|
29
|
+
items: T[];
|
|
26
30
|
}[]>;
|
|
27
31
|
filter: () => string;
|
|
28
32
|
flat: import("solid-js").Accessor<T[]>;
|
|
@@ -32,13 +36,13 @@ export declare function useFilteredList<T>(props: FilteredListProps<T>): {
|
|
|
32
36
|
items: [T, ...T[]];
|
|
33
37
|
}[] | {
|
|
34
38
|
category: string;
|
|
35
|
-
items:
|
|
39
|
+
items: T[];
|
|
36
40
|
}[] | Promise<{
|
|
37
41
|
category: string;
|
|
38
42
|
items: [T, ...T[]];
|
|
39
43
|
}[] | {
|
|
40
44
|
category: string;
|
|
41
|
-
items:
|
|
45
|
+
items: T[];
|
|
42
46
|
}[]> | null | undefined;
|
|
43
47
|
clear: () => void;
|
|
44
48
|
onKeyDown: (event: KeyboardEvent) => void;
|
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-21875",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -255,8 +255,6 @@
|
|
|
255
255
|
"fuzzysort": "3.1.0",
|
|
256
256
|
"katex": "0.16.47",
|
|
257
257
|
"marked": "18.0.11",
|
|
258
|
-
"motion": "12.34.5",
|
|
259
|
-
"remeda": "2.26.0",
|
|
260
258
|
"solid-list": "0.3.0",
|
|
261
259
|
"solid-sonner": "0.3.1"
|
|
262
260
|
},
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { attachSpring, motionValue } from "motion"
|
|
2
|
-
import type { SpringOptions } from "motion"
|
|
1
|
+
import { attachSpring, motionValue, type SpringOptions } from "@kitlangton/solid-motion"
|
|
3
2
|
import { createComputed, createEffect, createSignal, onCleanup } from "solid-js"
|
|
4
3
|
|
|
5
4
|
type Opt = Partial<Pick<SpringOptions, "visualDuration" | "bounce" | "stiffness" | "damping" | "mass" | "velocity">>
|
|
@@ -12,8 +11,8 @@ const eq = (a: Opt | undefined, b: Opt | undefined) =>
|
|
|
12
11
|
a?.mass === b?.mass &&
|
|
13
12
|
a?.velocity === b?.velocity
|
|
14
13
|
|
|
15
|
-
export function useSpring(target: () => number, options?: Opt | (() => Opt), snapKey?: () =>
|
|
16
|
-
const read = () => (
|
|
14
|
+
export function useSpring<K>(target: () => number, options?: Opt | (() => Opt), snapKey?: () => K) {
|
|
15
|
+
const read = () => (options instanceof Function ? options() : options)
|
|
17
16
|
const [value, setValue] = createSignal(target())
|
|
18
17
|
const source = motionValue(value())
|
|
19
18
|
const spring = motionValue(value())
|
|
@@ -48,7 +47,10 @@ export function useSpring(target: () => number, options?: Opt | (() => Opt), sna
|
|
|
48
47
|
if (eq(config, next)) return
|
|
49
48
|
config = next
|
|
50
49
|
stop()
|
|
50
|
+
// attachSpring's cleanup only unsubscribes from the source; the running animation keeps ticking until stopped.
|
|
51
|
+
spring.stop()
|
|
51
52
|
stop = attachSpring(spring, source, next)
|
|
53
|
+
spring.set(source.get())
|
|
52
54
|
setValue(spring.get())
|
|
53
55
|
})
|
|
54
56
|
|
package/src/context/i18n.tsx
CHANGED
|
@@ -51,6 +51,7 @@ export function pluralCategory(locale: string, count: number): UiPluralCategory
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export function pluralKey(key: UiI18nPluralKey, category: UiPluralCategory) {
|
|
54
|
+
// SAFETY: `PluralKey` names a base whose `.one`/`.other` forms exist, so `${key}.${category}` is a lookup key.
|
|
54
55
|
return `${key}.${category}` as UiI18nPluralLookupKey
|
|
55
56
|
}
|
|
56
57
|
|
|
@@ -73,7 +74,7 @@ export function localizedListSeparator(locale: string, index: number, count: num
|
|
|
73
74
|
.join("")
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
function resolveTemplate(text: string, params?: UiI18nParams) {
|
|
77
|
+
export function resolveTemplate(text: string, params?: UiI18nParams) {
|
|
77
78
|
if (!params) return text
|
|
78
79
|
|
|
79
80
|
return text.replace(/{{\s*([^}]+?)\s*}}/g, (_, rawKey) => {
|
|
@@ -106,6 +107,7 @@ export function createUiI18n(source: UiI18nSource): UiI18n {
|
|
|
106
107
|
const fallbackSource: UiI18nSource = {
|
|
107
108
|
locale: () => "en",
|
|
108
109
|
t: (key, params) => {
|
|
110
|
+
// SAFETY: the fallback source only translates keys from the UI dictionary; any other key falls back to itself.
|
|
109
111
|
const value = en[key as UiI18nKey] ?? String(key)
|
|
110
112
|
|
|
111
113
|
return resolveTemplate(value, params)
|
|
@@ -113,6 +115,7 @@ const fallbackSource: UiI18nSource = {
|
|
|
113
115
|
plural: (key, count, params) =>
|
|
114
116
|
fallback.pluralForm!(key, pluralCategory(fallback.locale(), count), { ...params, count }),
|
|
115
117
|
pluralForm: (key, category, params) => {
|
|
118
|
+
// SAFETY: locale keys are a subset of the dictionary keys, and every value is a string.
|
|
116
119
|
const values = en as Partial<Record<UiI18nLocaleKey, string>>
|
|
117
120
|
const value = values[pluralKey(key, category)] ?? values[`${key}.other`] ?? `${key}.other`
|
|
118
121
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fuzzysort from "fuzzysort"
|
|
2
|
-
import { entries, flatMap, groupBy, map, pipe } from "remeda"
|
|
3
2
|
import { createEffect, createMemo, createResource, on } from "solid-js"
|
|
4
3
|
import { createStore } from "solid-js/store"
|
|
5
4
|
import { createList } from "solid-list"
|
|
@@ -17,6 +16,27 @@ export interface FilteredListProps<T> {
|
|
|
17
16
|
noInitialSelection?: boolean
|
|
18
17
|
}
|
|
19
18
|
|
|
19
|
+
export function groupItems<T>(
|
|
20
|
+
items: T[],
|
|
21
|
+
props: Pick<FilteredListProps<T>, "groupBy" | "sortBy" | "sortGroupsBy">,
|
|
22
|
+
) {
|
|
23
|
+
// A plain object keeps the group order of `Object.entries`, where numeric-looking categories sort first.
|
|
24
|
+
const byCategory: Record<string, T[]> = {}
|
|
25
|
+
|
|
26
|
+
for (const item of items) {
|
|
27
|
+
const category = props.groupBy ? props.groupBy(item) : ""
|
|
28
|
+
byCategory[category] ??= []
|
|
29
|
+
byCategory[category].push(item)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const groups = Object.entries(byCategory).map(([category, group]) => ({
|
|
33
|
+
category,
|
|
34
|
+
items: props.sortBy ? group.sort(props.sortBy) : group,
|
|
35
|
+
}))
|
|
36
|
+
|
|
37
|
+
return props.sortGroupsBy ? groups.sort(props.sortGroupsBy) : groups
|
|
38
|
+
}
|
|
39
|
+
|
|
20
40
|
export function useFilteredList<T>(props: FilteredListProps<T>) {
|
|
21
41
|
const [store, setStore] = createStore<{ filter: string }>({ filter: "" })
|
|
22
42
|
|
|
@@ -24,9 +44,26 @@ export function useFilteredList<T>(props: FilteredListProps<T>) {
|
|
|
24
44
|
|
|
25
45
|
const empty: Group[] = []
|
|
26
46
|
|
|
47
|
+
const search = (all: T[], needle: string) => {
|
|
48
|
+
const skipFilter = props.skipFilter
|
|
49
|
+
const filterable = skipFilter ? all.filter((item) => !skipFilter(item)) : all
|
|
50
|
+
const skipped = skipFilter ? all.filter(skipFilter) : []
|
|
51
|
+
|
|
52
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- plain string lists have no keys to search by
|
|
53
|
+
const strings = !props.filterKeys && filterable.every((e) => typeof e === "string")
|
|
54
|
+
|
|
55
|
+
// SAFETY: when `strings` holds, every element is a string, so the matched targets are the items.
|
|
56
|
+
const filtered = strings
|
|
57
|
+
? (fuzzysort.go(needle, filterable as string[]).map((x) => x.target) as T[])
|
|
58
|
+
: fuzzysort.go(needle, filterable, { keys: props.filterKeys! }).map((x) => x.obj)
|
|
59
|
+
|
|
60
|
+
return skipped.length ? [...filtered, ...skipped] : filtered
|
|
61
|
+
}
|
|
62
|
+
|
|
27
63
|
const [grouped, { refetch }] = createResource(
|
|
28
64
|
() => ({
|
|
29
65
|
filter: store.filter,
|
|
66
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- `items` is either a list or a loader for one
|
|
30
67
|
items: typeof props.items === "function" ? props.items(store.filter) : props.items,
|
|
31
68
|
}),
|
|
32
69
|
async ({ filter, items }) => {
|
|
@@ -34,38 +71,14 @@ export function useFilteredList<T>(props: FilteredListProps<T>) {
|
|
|
34
71
|
const needle = query.toLowerCase()
|
|
35
72
|
const all = (await Promise.resolve(items)) || []
|
|
36
73
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!needle) return x
|
|
41
|
-
const skipFilter = props.skipFilter
|
|
42
|
-
const filterable = skipFilter ? x.filter((item) => !skipFilter(item)) : x
|
|
43
|
-
const skipped = skipFilter ? x.filter(skipFilter) : []
|
|
44
|
-
|
|
45
|
-
const filtered =
|
|
46
|
-
!props.filterKeys && Array.isArray(filterable) && filterable.every((e) => typeof e === "string")
|
|
47
|
-
? (fuzzysort.go(needle, filterable).map((x) => x.target) as T[])
|
|
48
|
-
: fuzzysort.go(needle, filterable, { keys: props.filterKeys! }).map((x) => x.obj)
|
|
49
|
-
|
|
50
|
-
return skipped.length ? [...filtered, ...skipped] : filtered
|
|
51
|
-
},
|
|
52
|
-
groupBy((x) => (props.groupBy ? props.groupBy(x) : "")),
|
|
53
|
-
entries(),
|
|
54
|
-
map(([k, v]) => ({ category: k, items: props.sortBy ? v.sort(props.sortBy) : v })),
|
|
55
|
-
(groups) => (props.sortGroupsBy ? groups.sort(props.sortGroupsBy) : groups),
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
return result
|
|
74
|
+
const matched = needle ? search(all, needle) : all
|
|
75
|
+
|
|
76
|
+
return groupItems(matched, props)
|
|
59
77
|
},
|
|
60
78
|
{ initialValue: empty },
|
|
61
79
|
)
|
|
62
80
|
|
|
63
|
-
const flat = createMemo(() =>
|
|
64
|
-
return pipe(
|
|
65
|
-
grouped.latest || [],
|
|
66
|
-
flatMap((x) => x.items),
|
|
67
|
-
)
|
|
68
|
-
})
|
|
81
|
+
const flat = createMemo(() => (grouped.latest || []).flatMap((x) => x.items))
|
|
69
82
|
|
|
70
83
|
function initialActive() {
|
|
71
84
|
if (props.noInitialSelection) return ""
|