@neovici/cosmoz-autocomplete 6.1.0 → 6.3.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.
@@ -1,7 +1,7 @@
1
1
  type Source<I> = (opts: {
2
2
  query: string;
3
3
  active?: boolean;
4
- }) => PromiseLike<I>;
4
+ }) => PromiseLike<I[]>;
5
5
  interface Base<I> {
6
6
  value: I | I[];
7
7
  limit?: number;
@@ -19,15 +19,16 @@ export interface Props<I> extends Base<I> {
19
19
  text: string;
20
20
  source: I[] | Source<I>;
21
21
  textProperty?: string;
22
+ textual?: (i: I) => string;
22
23
  valueProperty?: string;
23
24
  external?: boolean;
24
25
  hideEmpty?: boolean;
25
26
  disabled?: boolean;
26
27
  onFocus?: (focused?: boolean) => void;
27
28
  }
28
- export declare const useAutocomplete: <I>({ value: _value, text, onChange: _onChange, onText: _onText, onSelect, limit, source, textProperty, valueProperty, external, hideEmpty, keepQuery, keepOpened, ...thru }: Props<I>) => {
29
+ export declare const useAutocomplete: <I>({ value: _value, text, onChange: _onChange, onText: _onText, onSelect, limit, source, textProperty, textual: _textual, valueProperty, external, hideEmpty, keepQuery, keepOpened, ...thru }: Props<I>) => {
29
30
  query: string;
30
- textual: <O>(o: O) => string;
31
+ textual: (i: I) => string;
31
32
  value: I[];
32
33
  values$: Promise<I[]>;
33
34
  items$: Promise<I[]>;
@@ -6,8 +6,8 @@ import { useMeta } from '@neovici/cosmoz-utils/hooks/use-meta';
6
6
  import { useFocus } from '@neovici/cosmoz-dropdown/use-focus';
7
7
  import { useKeys } from './use-keys';
8
8
  import { search, notify, useNotify, EMPTY$ } from './util';
9
- export const useAutocomplete = ({ value: _value, text, onChange: _onChange, onText: _onText, onSelect, limit, source, textProperty, valueProperty, external, hideEmpty, keepQuery, keepOpened, ...thru }) => {
10
- const textual = useMemo(() => strProp(textProperty), [textProperty]), { active, onFocus, setClosed } = useFocus(thru), empty = !text, query = useMemo(() => text?.trim().toLowerCase(), [text]), host = useHost(), onText = useNotify(host, _onText, 'text'), onChange = useCallback((val) => {
9
+ export const useAutocomplete = ({ value: _value, text, onChange: _onChange, onText: _onText, onSelect, limit, source, textProperty, textual: _textual, valueProperty, external, hideEmpty, keepQuery, keepOpened, ...thru }) => {
10
+ const textual = useMemo(() => _textual || strProp(textProperty), [_textual, textProperty]), { active, onFocus, setClosed } = useFocus(thru), empty = !text, query = useMemo(() => text?.trim().toLowerCase(), [text]), host = useHost(), onText = useNotify(host, _onText, 'text'), onChange = useCallback((val) => {
11
11
  _onChange?.(val, () => setClosed(true));
12
12
  notify(host, 'value', val);
13
13
  }, [_onChange]), source$ = useMemo(() => Promise.resolve(typeof source === 'function' ? source({ query, active }) : source), [source, active, query]), value = useMemo(() => array(_value), [_value]), values$ = useMemo(() => source$.then((source) => [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-autocomplete",
3
- "version": "6.1.0",
3
+ "version": "6.3.0",
4
4
  "description": "A autocomplete input web component",
5
5
  "keywords": [
6
6
  "lit-html",