foldkit 0.22.0 → 0.24.0

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,4 @@
1
+ import { Option } from 'effect';
2
+ /** Finds the first enabled item whose search text starts with the query, searching forward from the active item and wrapping around. On a fresh search, starts after the active item; on a refinement, includes the active item. */
3
+ export declare const resolveTypeaheadMatch: <Item>(items: ReadonlyArray<Item>, query: string, maybeActiveItemIndex: Option.Option<number>, isDisabled: (index: number) => boolean, itemToSearchText: (item: Item, index: number) => string, isRefinement: boolean) => Option.Option<number>;
4
+ //# sourceMappingURL=typeahead.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeahead.d.ts","sourceRoot":"","sources":["../../src/ui/typeahead.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAuB,MAAM,QAAQ,CAAA;AAI3D,oOAAoO;AACpO,eAAO,MAAM,qBAAqB,GAAI,IAAI,EACxC,OAAO,aAAa,CAAC,IAAI,CAAC,EAC1B,OAAO,MAAM,EACb,sBAAsB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAC3C,YAAY,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,EACtC,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,EACvD,cAAc,OAAO,KACpB,MAAM,CAAC,MAAM,CAAC,MAAM,CA4BtB,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { Array, Option, String as Str, pipe } from 'effect';
2
+ import { wrapIndex } from './keyboard';
3
+ /** Finds the first enabled item whose search text starts with the query, searching forward from the active item and wrapping around. On a fresh search, starts after the active item; on a refinement, includes the active item. */
4
+ export const resolveTypeaheadMatch = (items, query, maybeActiveItemIndex, isDisabled, itemToSearchText, isRefinement) => {
5
+ const lowerQuery = Str.toLowerCase(query);
6
+ const offset = isRefinement ? 0 : 1;
7
+ const startIndex = Option.match(maybeActiveItemIndex, {
8
+ onNone: () => 0,
9
+ onSome: index => index + offset,
10
+ });
11
+ const isEnabledMatch = (index) => !isDisabled(index) &&
12
+ pipe(items, Array.get(index), Option.exists(item => pipe(itemToSearchText(item, index), Str.toLowerCase, Str.startsWith(lowerQuery))));
13
+ return pipe(items, Array.length, Array.makeBy(step => wrapIndex(startIndex + step, items.length)), Array.findFirst(isEnabledMatch));
14
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldkit",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Elm-inspired UI framework powered by Effect",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -63,6 +63,10 @@
63
63
  "types": "./dist/ui/disclosure/public.d.ts",
64
64
  "import": "./dist/ui/disclosure/public.js"
65
65
  },
66
+ "./ui/listbox": {
67
+ "types": "./dist/ui/listbox/public.d.ts",
68
+ "import": "./dist/ui/listbox/public.js"
69
+ },
66
70
  "./ui/menu": {
67
71
  "types": "./dist/ui/menu/public.d.ts",
68
72
  "import": "./dist/ui/menu/public.js"