@neovici/cosmoz-autocomplete 7.7.0 → 7.9.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.
|
@@ -4,6 +4,7 @@ import { until } from 'lit-html/directives/until.js';
|
|
|
4
4
|
import { when } from 'lit-html/directives/when.js';
|
|
5
5
|
import { useCallback } from 'haunted';
|
|
6
6
|
import { useHost } from '@neovici/cosmoz-utils/hooks/use-host';
|
|
7
|
+
import { useImperativeApi } from '@neovici/cosmoz-utils/hooks/use-imperative-api';
|
|
7
8
|
import '@neovici/cosmoz-input';
|
|
8
9
|
import { useAutocomplete } from './use-autocomplete';
|
|
9
10
|
import { listbox } from '../listbox';
|
|
@@ -24,6 +25,9 @@ const autocomplete = (props) => {
|
|
|
24
25
|
items,
|
|
25
26
|
multi: !isOne,
|
|
26
27
|
}))));
|
|
28
|
+
useImperativeApi({
|
|
29
|
+
focus: () => host.shadowRoot?.querySelector('#input')?.focus(),
|
|
30
|
+
}, []);
|
|
27
31
|
return html ` <style>
|
|
28
32
|
${style}
|
|
29
33
|
</style>
|
|
@@ -5,15 +5,17 @@ import { useHost } from '@neovici/cosmoz-utils/hooks/use-host';
|
|
|
5
5
|
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
|
-
import { search, notify, useNotify, EMPTY$ } from './util';
|
|
8
|
+
import { search, normalize, notify, useNotify, EMPTY$ } from './util';
|
|
9
9
|
export const useAutocomplete = ({ value: _value, text, onChange: _onChange, onText: _onText, onSelect, limit, source, textProperty, textual: _textual, valueProperty, external, hideEmpty, keepOpened, keepQuery, ...thru }) => {
|
|
10
10
|
const textual = useMemo(() => (_textual ?? strProp)(textProperty), [_textual, textProperty]), { active, focused, onFocus, setClosed } = useFocus(thru), empty = !text, query = useMemo(() => text?.trim(), [text]), host = useHost(), onText = useNotify(host, _onText, 'text'), onChange = useCallback((val) => {
|
|
11
11
|
_onChange?.(val, () => setClosed(true));
|
|
12
12
|
notify(host, 'value', val);
|
|
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) =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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) => {
|
|
14
|
+
return [
|
|
15
|
+
...value,
|
|
16
|
+
...without(value, prop(valueProperty))(normalize(source)),
|
|
17
|
+
];
|
|
18
|
+
}), [source$, value, valueProperty]);
|
|
17
19
|
useKeys({
|
|
18
20
|
focused,
|
|
19
21
|
empty,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const search: <I>(source: I[], query: string, textual: (i: I) => string) => I[];
|
|
2
|
+
export declare const normalize: <I>(source: false | I[] | null) => I[];
|
|
2
3
|
export declare const notify: <T>(host: EventTarget, name: string, detail: T) => boolean;
|
|
3
4
|
export declare const useNotify: <V>(host: EventTarget, fn: ((v: V) => void) | undefined, name: string) => (val: V) => void;
|
|
4
5
|
export declare const EMPTY: never[], EMPTY$: Promise<never[]>;
|
|
@@ -18,6 +18,11 @@ export const search = (source, query, textual) => {
|
|
|
18
18
|
})
|
|
19
19
|
.map(({ item }) => item);
|
|
20
20
|
};
|
|
21
|
+
export const normalize = (source) => {
|
|
22
|
+
if (source === false || source == null)
|
|
23
|
+
return [];
|
|
24
|
+
return source;
|
|
25
|
+
};
|
|
21
26
|
export const notify = (host, name, detail) => host.dispatchEvent(new CustomEvent(name, { detail }));
|
|
22
27
|
export const useNotify = (host, fn, name) => useCallback((val) => {
|
|
23
28
|
fn?.(val);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-autocomplete",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.9.0",
|
|
4
4
|
"description": "A autocomplete input web component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lit-html",
|
|
@@ -82,12 +82,12 @@
|
|
|
82
82
|
"@semantic-release/changelog": "^6.0.0",
|
|
83
83
|
"@semantic-release/git": "^10.0.0",
|
|
84
84
|
"@storybook/storybook-deployer": "^2.8.5",
|
|
85
|
-
"@web/dev-server-storybook": "^0.
|
|
85
|
+
"@web/dev-server-storybook": "^1.0.0",
|
|
86
86
|
"eslint-import-resolver-exports": "^1.0.0-beta.5",
|
|
87
87
|
"husky": "^8.0.0",
|
|
88
88
|
"rollup-plugin-terser": "^7.0.2",
|
|
89
|
-
"semantic-release": "^
|
|
90
|
-
"sinon": "^
|
|
89
|
+
"semantic-release": "^22.0.0",
|
|
90
|
+
"sinon": "^16.0.0",
|
|
91
91
|
"typescript": "^5.0.0"
|
|
92
92
|
}
|
|
93
93
|
}
|