@neovici/cosmoz-autocomplete 10.7.0 → 10.7.2
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/autocomplete/autocomplete.js +10 -8
- package/dist/autocomplete/use-autocomplete.d.ts +3 -3
- package/dist/autocomplete/use-autocomplete.js +1 -1
- package/dist/autocomplete/use-overflow.js +1 -0
- package/dist/autocomplete/util.d.ts +1 -1
- package/dist/listbox/item-renderer.d.ts +1 -1
- package/dist/listbox/use-listbox.d.ts +1 -1
- package/dist/listbox/util.d.ts +1 -1
- package/package.json +3 -9
|
@@ -27,12 +27,11 @@ const middleware = [
|
|
|
27
27
|
}),
|
|
28
28
|
...defaultMiddleware,
|
|
29
29
|
];
|
|
30
|
-
const shouldShowDropdown = ({ active,
|
|
30
|
+
const shouldShowDropdown = ({ active, isSingle, showSingle, }) => {
|
|
31
31
|
if (!active)
|
|
32
32
|
return false;
|
|
33
|
-
const hasResultsOrQuery = loading || items.length > 0 || text.length > 0;
|
|
34
33
|
const disallowedSingle = isSingle && !showSingle;
|
|
35
|
-
return
|
|
34
|
+
return !disallowedSingle;
|
|
36
35
|
};
|
|
37
36
|
const autocomplete = (props) => {
|
|
38
37
|
const { active, invalid, errorMessage, label, placeholder, disabled, noLabelFloat, alwaysFloatLabel, textual, text, onText, onFocus, onClick, onDeselect, value, limit, min, showSingle, items, source$, placement, loading, } = props, host = useHost(), isOne = limit == 1, // eslint-disable-line eqeqeq
|
|
@@ -52,6 +51,7 @@ const autocomplete = (props) => {
|
|
|
52
51
|
useImperativeApi({
|
|
53
52
|
focus: () => host.shadowRoot?.querySelector('#input')?.focus(),
|
|
54
53
|
}, []);
|
|
54
|
+
const hasResultsOrQuery = loading || items.length > 0 || (text != null && text.length > 0);
|
|
55
55
|
return html `<cosmoz-input
|
|
56
56
|
id="input"
|
|
57
57
|
part="input"
|
|
@@ -86,9 +86,6 @@ const autocomplete = (props) => {
|
|
|
86
86
|
|
|
87
87
|
${when(shouldShowDropdown({
|
|
88
88
|
active,
|
|
89
|
-
loading,
|
|
90
|
-
items,
|
|
91
|
-
text,
|
|
92
89
|
isSingle,
|
|
93
90
|
showSingle,
|
|
94
91
|
}), () => listbox({
|
|
@@ -96,8 +93,13 @@ const autocomplete = (props) => {
|
|
|
96
93
|
items,
|
|
97
94
|
multi: !isOne,
|
|
98
95
|
setFloating,
|
|
99
|
-
styles
|
|
100
|
-
|
|
96
|
+
styles: {
|
|
97
|
+
...styles,
|
|
98
|
+
// WORKAROUND: hide the listbox if there are no results, don't remove it from DOM
|
|
99
|
+
// TODO: revert https://github.com/Neovici/cosmoz-autocomplete/pull/206 after https://github.com/pionjs/pion/issues/64 is fixed
|
|
100
|
+
display: hasResultsOrQuery ? undefined : 'none',
|
|
101
|
+
},
|
|
102
|
+
}, when(loading, () => html `<cosmoz-autocomplete-skeleton-span></cosmoz-autocomplete-skeleton-span>`, () => when(text != null && text.length > 0 && items.length === 0, () => html `<slot name="no-result"></slot>`))))}`;
|
|
101
103
|
}, Autocomplete = (props) => {
|
|
102
104
|
const thru = {
|
|
103
105
|
...props,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type Source<I> = (opts: {
|
|
2
|
-
query
|
|
2
|
+
query?: string;
|
|
3
3
|
active?: boolean;
|
|
4
4
|
}) => PromiseLike<I[]>;
|
|
5
5
|
interface Base<I> {
|
|
@@ -17,7 +17,7 @@ interface Meta<I> extends Omit<Base<I>, 'value'> {
|
|
|
17
17
|
value: I[];
|
|
18
18
|
}
|
|
19
19
|
export interface Props<I> extends Base<I> {
|
|
20
|
-
text
|
|
20
|
+
text?: string;
|
|
21
21
|
source: I[] | Source<I>;
|
|
22
22
|
textProperty?: string;
|
|
23
23
|
textual?: (prop?: string) => (i: I) => string;
|
|
@@ -30,7 +30,7 @@ export interface Props<I> extends Base<I> {
|
|
|
30
30
|
}
|
|
31
31
|
export declare const useAutocomplete: <I>({ value: _value, text, onChange: _onChange, onText: _onText, onSelect, limit, min, source, textProperty, textual: _textual, valueProperty, keepOpened, keepQuery, preserveOrder, defaultIndex, externalSearch, ...thru }: Props<I>) => {
|
|
32
32
|
active: boolean | undefined;
|
|
33
|
-
query: string;
|
|
33
|
+
query: string | undefined;
|
|
34
34
|
textual: (i: I) => string;
|
|
35
35
|
value: I[];
|
|
36
36
|
source$: Promise<I[]>;
|
|
@@ -84,6 +84,6 @@ export const useAutocomplete = ({ value: _value, text, onChange: _onChange, onTe
|
|
|
84
84
|
}, [meta]),
|
|
85
85
|
onDeselect: useCallback((val) => meta.onChange(without(val)(meta.value)), [meta]),
|
|
86
86
|
// whenever there is a query, override defaultIndex to 0, so the first result gets selected
|
|
87
|
-
defaultIndex: query?.length > 0 ? 0 : defaultIndex,
|
|
87
|
+
defaultIndex: (query !== undefined && query?.length > 0) ? 0 : defaultIndex,
|
|
88
88
|
};
|
|
89
89
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useLayoutEffect, useState, useMemo } from '@pionjs/pion';
|
|
2
2
|
import { useHost } from '@neovici/cosmoz-utils/hooks/use-host';
|
|
3
3
|
import { raf } from './util';
|
|
4
|
+
// eslint-disable-next-line max-statements
|
|
4
5
|
const overflow = (host) => {
|
|
5
6
|
const chips = host.shadowRoot.querySelectorAll('.chip');
|
|
6
7
|
const badge = host.shadowRoot.querySelector('.badge');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const search: <I>(source: I[], query: string, textual: (i: I) => string) => I[];
|
|
1
|
+
export declare const search: <I>(source: I[], query: string | undefined, textual: (i: I) => string) => I[];
|
|
2
2
|
export declare const normalize: <I>(source: I[] | false | null) => I[];
|
|
3
3
|
export declare const notify: <T>(host: EventTarget, name: string, detail: T) => boolean;
|
|
4
4
|
export declare const useNotify: <V>(host: EventTarget, fn: undefined | ((v: V) => void), name: string) => (val: V) => void;
|
|
@@ -6,7 +6,7 @@ export interface ItemRendererOpts<I> {
|
|
|
6
6
|
highlight: (i: number) => void;
|
|
7
7
|
select: (item: I) => void;
|
|
8
8
|
isSelected: (item: I) => void;
|
|
9
|
-
query
|
|
9
|
+
query?: string;
|
|
10
10
|
textual: (i: I) => string;
|
|
11
11
|
}
|
|
12
12
|
export type Render<I> = (content: unknown, item: I, i: number) => unknown;
|
package/dist/listbox/util.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const byValue: <K extends PropertyKey | undefined, T>(value: T | T[], valueProperty: K) => ((item: T) => boolean) | ((item: T) => T | undefined);
|
|
2
|
-
export declare const mark: (text: string, query: string) => string | (string | import("lit-html").TemplateResult<1>)[];
|
|
2
|
+
export declare const mark: (text: string, query: string | undefined) => string | (string | import("lit-html").TemplateResult<1>)[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-autocomplete",
|
|
3
|
-
"version": "10.7.
|
|
3
|
+
"version": "10.7.2",
|
|
4
4
|
"description": "A autocomplete input web component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lit-html",
|
|
@@ -87,15 +87,9 @@
|
|
|
87
87
|
"@playwright/test": "^1.43.1",
|
|
88
88
|
"@semantic-release/changelog": "^6.0.0",
|
|
89
89
|
"@semantic-release/git": "^10.0.0",
|
|
90
|
-
"@storybook/
|
|
91
|
-
"@storybook/addon-links": "^7.0.0",
|
|
92
|
-
"@storybook/builder-vite": "7.6.17",
|
|
93
|
-
"@storybook/storybook-deployer": "^2.8.5",
|
|
94
|
-
"@storybook/web-components": "7.6.17",
|
|
90
|
+
"@storybook/web-components-vite": "^9.1.4",
|
|
95
91
|
"@types/mocha": "^10.0.6",
|
|
96
92
|
"@types/node": "^22.10.2",
|
|
97
|
-
"@web/storybook-builder": "^0.1.9",
|
|
98
|
-
"@web/storybook-framework-web-components": "^0.1.1",
|
|
99
93
|
"esbuild": "^0.24.0",
|
|
100
94
|
"http-server": "^14.1.1",
|
|
101
95
|
"husky": "^9.0.0",
|
|
@@ -104,7 +98,7 @@
|
|
|
104
98
|
"rollup-plugin-terser": "^7.0.2",
|
|
105
99
|
"semantic-release": "^24.0.0",
|
|
106
100
|
"sinon": "^19.0.0",
|
|
107
|
-
"storybook": "^
|
|
101
|
+
"storybook": "^9.1.4"
|
|
108
102
|
},
|
|
109
103
|
"overrides": {
|
|
110
104
|
"conventional-changelog-conventionalcommits": ">= 8.0.0"
|