@neovici/cosmoz-autocomplete 14.0.2 → 14.1.1
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-keybindings.d.ts +1 -9
- package/dist/autocomplete/autocomplete-keybindings.js +0 -11
- package/dist/autocomplete/autocomplete.d.ts +2 -1
- package/dist/autocomplete/autocomplete.js +3 -2
- package/dist/autocomplete/use-autocomplete.js +6 -16
- package/dist/listbox/style.css.js +2 -6
- package/package.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Activity
|
|
1
|
+
import { Activity } from '@neovici/cosmoz-utils/keybindings';
|
|
2
2
|
export declare const AUTOCOMPLETE_DESELECT_LAST: Activity;
|
|
3
|
-
export declare const AUTOCOMPLETE_SEARCH_WHEN_SELECTED: Activity;
|
|
4
3
|
export declare const autocompleteKeybindings: readonly [readonly [{
|
|
5
4
|
readonly key: "ArrowUp";
|
|
6
5
|
}, [symbol], {
|
|
@@ -29,11 +28,4 @@ export declare const autocompleteKeybindings: readonly [readonly [{
|
|
|
29
28
|
readonly description: "Remove the last selected item";
|
|
30
29
|
}, {
|
|
31
30
|
readonly allowInEditable: true;
|
|
32
|
-
}], readonly [{
|
|
33
|
-
readonly key: typeof ANY_KEY;
|
|
34
|
-
}, [symbol], {
|
|
35
|
-
readonly title: "Start searching";
|
|
36
|
-
readonly description: "Start searching when you start typing when an item is selected";
|
|
37
|
-
}, {
|
|
38
|
-
readonly allowInEditable: true;
|
|
39
31
|
}]];
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { ANY_KEY, } from '@neovici/cosmoz-utils/keybindings';
|
|
2
1
|
import { listboxKeybindings } from '../listbox/listbox-keybindings';
|
|
3
2
|
export const AUTOCOMPLETE_DESELECT_LAST = Symbol('autocomplete.deselect.last');
|
|
4
|
-
export const AUTOCOMPLETE_SEARCH_WHEN_SELECTED = Symbol('autocomplete.search.when.selected');
|
|
5
3
|
export const autocompleteKeybindings = [
|
|
6
4
|
...listboxKeybindings,
|
|
7
5
|
[
|
|
@@ -13,13 +11,4 @@ export const autocompleteKeybindings = [
|
|
|
13
11
|
},
|
|
14
12
|
{ allowInEditable: true },
|
|
15
13
|
],
|
|
16
|
-
[
|
|
17
|
-
{ key: ANY_KEY },
|
|
18
|
-
[AUTOCOMPLETE_SEARCH_WHEN_SELECTED],
|
|
19
|
-
{
|
|
20
|
-
title: 'Start searching',
|
|
21
|
-
description: 'Start searching when you start typing when an item is selected',
|
|
22
|
-
},
|
|
23
|
-
{ allowInEditable: true },
|
|
24
|
-
],
|
|
25
14
|
];
|
|
@@ -13,6 +13,7 @@ export interface Props<I> extends Base<I> {
|
|
|
13
13
|
hint?: string;
|
|
14
14
|
label?: string;
|
|
15
15
|
placeholder?: string;
|
|
16
|
+
compact?: boolean;
|
|
16
17
|
required?: boolean;
|
|
17
18
|
showSingle?: boolean;
|
|
18
19
|
itemHeight?: number | 'auto';
|
|
@@ -26,5 +27,5 @@ export interface Props<I> extends Base<I> {
|
|
|
26
27
|
type AProps<I> = Omit<Props<I>, keyof RProps<I>> & RProps<I> & {
|
|
27
28
|
onInputRef?: (el?: Element) => void;
|
|
28
29
|
};
|
|
29
|
-
declare const autocomplete: <I>(props: AProps<I>) => import("lit-html").TemplateResult<1>, Autocomplete: <I>(props: Props<I>) => import("lit-html").TemplateResult<1>, observedAttributes: readonly ["variant", "disabled", "invalid", "required", "hint", "text-property", "value-property", "limit", "min", "show-single", "preserve-order", "keep-opened", "keep-query", "default-index", "external-search", "item-height", "item-limit", "wrap", "lazy-open", "mode"];
|
|
30
|
+
declare const autocomplete: <I>(props: AProps<I>) => import("lit-html").TemplateResult<1>, Autocomplete: <I>(props: Props<I>) => import("lit-html").TemplateResult<1>, observedAttributes: readonly ["variant", "disabled", "invalid", "required", "compact", "hint", "text-property", "value-property", "limit", "min", "show-single", "preserve-order", "keep-opened", "keep-query", "default-index", "external-search", "item-height", "item-limit", "wrap", "lazy-open", "mode"];
|
|
30
31
|
export { Autocomplete, autocomplete, observedAttributes, style };
|
|
@@ -25,7 +25,7 @@ const shouldShowDropdown = ({ opened, isSingle, showSingle, hasResultsOrQuery, }
|
|
|
25
25
|
return hasResultsOrQuery;
|
|
26
26
|
};
|
|
27
27
|
const autocomplete = (props) => {
|
|
28
|
-
const { variant, opened, invalid, errorMessage, hint, label, placeholder, required, disabled, textual, text, onText, onToggle, onDeselect, value, limit, min, showSingle, items, source$, loading, chipRenderer, mode, } = props, isOne = limit === 1, isSingle = isOne && value?.[0] != null;
|
|
28
|
+
const { variant, opened, invalid, errorMessage, hint, label, placeholder, compact, required, disabled, textual, text, onText, onToggle, onDeselect, value, limit, min, showSingle, items, source$, loading, chipRenderer, mode, } = props, isOne = limit === 1, isSingle = isOne && value?.[0] != null;
|
|
29
29
|
const hasResultsOrQuery = loading || items.length > 0 || (text != null && text.length > 0);
|
|
30
30
|
return html `<cosmoz-dropdown-next
|
|
31
31
|
open-on-focus
|
|
@@ -42,7 +42,7 @@ const autocomplete = (props) => {
|
|
|
42
42
|
.placeholder=${isSingle ? undefined : placeholder}
|
|
43
43
|
hint=${ifDefined(hint)}
|
|
44
44
|
variant=${ifDefined(variant)}
|
|
45
|
-
?
|
|
45
|
+
?compact=${compact}
|
|
46
46
|
?disabled=${disabled}
|
|
47
47
|
?required=${required}
|
|
48
48
|
?invalid=${guard([source$, invalid], () => until(source$.then(() => invalid, () => true), invalid))}
|
|
@@ -98,6 +98,7 @@ const autocomplete = (props) => {
|
|
|
98
98
|
'disabled',
|
|
99
99
|
'invalid',
|
|
100
100
|
'required',
|
|
101
|
+
'compact',
|
|
101
102
|
'hint',
|
|
102
103
|
'text-property',
|
|
103
104
|
'value-property',
|
|
@@ -5,7 +5,7 @@ import { usePromise } from '@neovici/cosmoz-utils/hooks/use-promise';
|
|
|
5
5
|
import { useActivity } from '@neovici/cosmoz-utils/keybindings';
|
|
6
6
|
import { prop, strProp } from '@neovici/cosmoz-utils/object';
|
|
7
7
|
import { useCallback, useEffect, useMemo, useProperty, useState, } from '@pionjs/pion';
|
|
8
|
-
import { AUTOCOMPLETE_DESELECT_LAST
|
|
8
|
+
import { AUTOCOMPLETE_DESELECT_LAST } from './autocomplete-keybindings';
|
|
9
9
|
import { EMPTY, normalize, notify, search } from './util';
|
|
10
10
|
const useNotify = (host, fn, name) => useCallback((val) => {
|
|
11
11
|
fn?.(val);
|
|
@@ -34,19 +34,6 @@ export const useAutocomplete = ({ value: _value, text, mode, onChange: _onChange
|
|
|
34
34
|
check: () => !disabled && empty && host.matches(':focus-within'),
|
|
35
35
|
element: () => host,
|
|
36
36
|
}, []);
|
|
37
|
-
useActivity({
|
|
38
|
-
activity: AUTOCOMPLETE_SEARCH_WHEN_SELECTED,
|
|
39
|
-
callback: (ev) => {
|
|
40
|
-
const values = array(value);
|
|
41
|
-
const isOne = limit === 1;
|
|
42
|
-
if (values.length > 0 && isOne && ev.key.length === 1) {
|
|
43
|
-
onChange(values.slice(0, -1));
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
allowDefault: true,
|
|
47
|
-
check: () => !disabled && empty && host.matches(':focus-within'),
|
|
48
|
-
element: () => host,
|
|
49
|
-
}, [limit]);
|
|
50
37
|
// Clear query when popover closes
|
|
51
38
|
useEffect(() => {
|
|
52
39
|
if (!opened && !keepQuery)
|
|
@@ -106,9 +93,12 @@ export const useAutocomplete = ({ value: _value, text, mode, onChange: _onChange
|
|
|
106
93
|
onText: useCallback((e) => {
|
|
107
94
|
if (disabled)
|
|
108
95
|
return;
|
|
109
|
-
|
|
96
|
+
const text = e.target.value;
|
|
97
|
+
if (text && limit === 1 && value.length > 0)
|
|
98
|
+
onChange([]);
|
|
99
|
+
onText(text);
|
|
110
100
|
setOpened(true);
|
|
111
|
-
}, [disabled, onText,
|
|
101
|
+
}, [disabled, onText, setOpened, limit, value, onChange]),
|
|
112
102
|
onSelect: useCallback((newVal) => {
|
|
113
103
|
if (disabled)
|
|
114
104
|
return;
|
|
@@ -66,9 +66,7 @@ const style = css `
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
:host(:not([multi])) .item[aria-selected] {
|
|
69
|
-
background: rgb(
|
|
70
|
-
from var(--cz-color-bg-brand-solid) r g b / calc(alpha * 0.25)
|
|
71
|
-
);
|
|
69
|
+
background: rgb(from var(--cz-color-alpha-black) r g b / 0.22);
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
:host([multi]) .item::before {
|
|
@@ -101,9 +99,7 @@ export const styles = ({ index, itemHeight, auto, }) => css `
|
|
|
101
99
|
}
|
|
102
100
|
`)}
|
|
103
101
|
.item[data-index='${index || '0'}'] {
|
|
104
|
-
background: rgb(
|
|
105
|
-
from var(--cz-color-bg-brand-solid) r g b / calc(alpha * 0.15)
|
|
106
|
-
);
|
|
102
|
+
background: rgb(from var(--cz-color-alpha-black) r g b / 0.14);
|
|
107
103
|
}
|
|
108
104
|
.item[data-index='${index || '0'}'][part~='error'] {
|
|
109
105
|
background: var(--cz-color-bg-error);
|