@neovici/cosmoz-autocomplete 10.12.0 → 11.0.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.
|
@@ -6,7 +6,11 @@ import { usePromise } from '@neovici/cosmoz-utils/hooks/use-promise';
|
|
|
6
6
|
import { prop, strProp } from '@neovici/cosmoz-utils/object';
|
|
7
7
|
import { useCallback, useEffect, useMemo, useState } from '@pionjs/pion';
|
|
8
8
|
import { useKeys } from './use-keys';
|
|
9
|
-
import { EMPTY, normalize, notify, search
|
|
9
|
+
import { EMPTY, normalize, notify, search } from './util';
|
|
10
|
+
const useNotify = (host, fn, name) => useCallback((val) => {
|
|
11
|
+
fn?.(val);
|
|
12
|
+
host.dispatchEvent(new CustomEvent(name, { detail: val }));
|
|
13
|
+
}, [fn]);
|
|
10
14
|
export const useAutocomplete = ({ value: _value, text, onChange: _onChange, onText: _onText, onSelect, limit, min, source, textProperty, textual: _textual, valueProperty, keepOpened, keepQuery, preserveOrder, defaultIndex, externalSearch, ...thru }) => {
|
|
11
15
|
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) => {
|
|
12
16
|
_onChange?.(val, () => setClosed(true));
|
|
@@ -1,9 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove accents/diacritics from a string.
|
|
3
|
+
* @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
4
|
+
* @see https://medium.com/nerd-for-tech/basics-of-javascript-string-normalize-method-f3241174c2d0
|
|
5
|
+
* @see https://www.codu.co/articles/remove-accents-from-a-javascript-string-skgp1inb
|
|
6
|
+
*
|
|
7
|
+
* @param str string from which to remove accents
|
|
8
|
+
* @returns string w/o accents
|
|
9
|
+
*/
|
|
10
|
+
export declare const removeAccents: (str: string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Search items by query string, returning matches sorted by position.
|
|
13
|
+
* Accent-insensitive search.
|
|
14
|
+
*/
|
|
1
15
|
export declare const search: <I>(source: I[], query: string | undefined, textual: (i: I) => string) => I[];
|
|
16
|
+
/**
|
|
17
|
+
* Normalize source to an array.
|
|
18
|
+
*/
|
|
2
19
|
export declare const normalize: <I>(source: I[] | false | null | undefined) => I[];
|
|
20
|
+
/**
|
|
21
|
+
* Dispatch a custom event with detail.
|
|
22
|
+
*/
|
|
3
23
|
export declare const notify: <T>(host: EventTarget, name: string, detail: T) => boolean;
|
|
4
|
-
export declare const useNotify: <V>(host: EventTarget, fn: undefined | ((v: V) => void), name: string) => (val: V) => void;
|
|
5
24
|
export declare const EMPTY: never[];
|
|
6
25
|
type Arr = unknown[];
|
|
7
26
|
type ArrFn<T extends Arr> = (...args: T) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Request animation frame wrapper with cleanup.
|
|
29
|
+
*/
|
|
8
30
|
export declare const raf: <A extends Arr, F extends ArrFn<A> = ArrFn<A>>(fn: F) => (...args: A) => () => void;
|
|
9
31
|
export {};
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { useCallback } from '@pionjs/pion';
|
|
2
1
|
/**
|
|
2
|
+
* Remove accents/diacritics from a string.
|
|
3
3
|
* @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
4
4
|
* @see https://medium.com/nerd-for-tech/basics-of-javascript-string-normalize-method-f3241174c2d0
|
|
5
5
|
* @see https://www.codu.co/articles/remove-accents-from-a-javascript-string-skgp1inb
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
8
|
-
* @returns
|
|
7
|
+
* @param str string from which to remove accents
|
|
8
|
+
* @returns string w/o accents
|
|
9
9
|
*/
|
|
10
|
-
const removeAccents = (str) => {
|
|
10
|
+
export const removeAccents = (str) => {
|
|
11
11
|
return str.normalize('NFD').replace(/[\u0300-\u036f]/gu, '');
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Search items by query string, returning matches sorted by position.
|
|
15
|
+
* Accent-insensitive search.
|
|
16
|
+
*/
|
|
13
17
|
export const search = (source, query, textual) => {
|
|
14
18
|
if (!query)
|
|
15
19
|
return source;
|
|
@@ -28,17 +32,22 @@ export const search = (source, query, textual) => {
|
|
|
28
32
|
}
|
|
29
33
|
return matches.sort((a, b) => a.index - b.index).map(({ item }) => item);
|
|
30
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Normalize source to an array.
|
|
37
|
+
*/
|
|
31
38
|
export const normalize = (source) => {
|
|
32
39
|
if (source === false || source == null)
|
|
33
40
|
return [];
|
|
34
41
|
return source;
|
|
35
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Dispatch a custom event with detail.
|
|
45
|
+
*/
|
|
36
46
|
export const notify = (host, name, detail) => host.dispatchEvent(new CustomEvent(name, { detail }));
|
|
37
|
-
export const useNotify = (host, fn, name) => useCallback((val) => {
|
|
38
|
-
fn?.(val);
|
|
39
|
-
notify(host, name, val);
|
|
40
|
-
}, [fn]);
|
|
41
47
|
export const EMPTY = [];
|
|
48
|
+
/**
|
|
49
|
+
* Request animation frame wrapper with cleanup.
|
|
50
|
+
*/
|
|
42
51
|
export const raf = (fn) => (...args) => {
|
|
43
52
|
let id;
|
|
44
53
|
const cleanup = () => {
|
package/dist/listbox/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { virtualize, virtualizerRef, } from '@lit-labs/virtualizer/virtualize.js';
|
|
2
|
-
import { connectable } from '@neovici/cosmoz-
|
|
2
|
+
import { connectable } from '@neovici/cosmoz-utils/connectable';
|
|
3
3
|
import { sheet } from '@neovici/cosmoz-utils';
|
|
4
4
|
import { spreadProps } from '@neovici/cosmoz-utils/directives/spread-props';
|
|
5
5
|
import { noop } from '@neovici/cosmoz-utils/function';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-autocomplete",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A autocomplete input web component",
|
|
6
6
|
"keywords": [
|
|
@@ -26,8 +26,10 @@
|
|
|
26
26
|
"build": "tsc -p tsconfig.build.json",
|
|
27
27
|
"check:duplicates": "check-duplicate-components",
|
|
28
28
|
"start": "npm run storybook:start",
|
|
29
|
-
"test": "
|
|
30
|
-
"test:
|
|
29
|
+
"test": "vitest --run && npm run e2e",
|
|
30
|
+
"test:unit": "vitest --project=unit --run",
|
|
31
|
+
"test:storybook": "vitest --project=storybook --run",
|
|
32
|
+
"test:watch": "vitest",
|
|
31
33
|
"e2e": "playwright test",
|
|
32
34
|
"prepare": "husky",
|
|
33
35
|
"prettier": "prettier --write \"**/*.{js,ts,json,css,md}\"",
|
|
@@ -77,7 +79,7 @@
|
|
|
77
79
|
"@lit-labs/virtualizer": "^2.0.0",
|
|
78
80
|
"@neovici/cosmoz-dropdown": "^6.0.0 || ^7.0.0",
|
|
79
81
|
"@neovici/cosmoz-input": "^5.0.2",
|
|
80
|
-
"@neovici/cosmoz-utils": "^6.
|
|
82
|
+
"@neovici/cosmoz-utils": "^6.19.0",
|
|
81
83
|
"@pionjs/pion": "^2.7.1",
|
|
82
84
|
"i18next": "^23.16.8",
|
|
83
85
|
"lit-html": "^2.0.0 || ^3.0.0"
|
|
@@ -86,23 +88,28 @@
|
|
|
86
88
|
"@commitlint/cli": "^20.0.0",
|
|
87
89
|
"@commitlint/config-conventional": "^20.0.0",
|
|
88
90
|
"@neovici/cfg": "^2.8.0",
|
|
89
|
-
"@open-wc/testing": "^4.0.0",
|
|
90
91
|
"@playwright/test": "^1.43.1",
|
|
91
92
|
"@semantic-release/changelog": "^6.0.0",
|
|
92
93
|
"@semantic-release/git": "^10.0.0",
|
|
94
|
+
"@storybook/addon-docs": "^10.0.0",
|
|
95
|
+
"@storybook/addon-vitest": "^10.0.0",
|
|
93
96
|
"@storybook/web-components-vite": "^10.0.0",
|
|
94
|
-
"@types/mocha": "^10.0.0",
|
|
95
97
|
"@types/node": "24.0.0",
|
|
98
|
+
"@vitest/browser": "^4.0.0",
|
|
99
|
+
"@vitest/browser-playwright": "^4.0.0",
|
|
96
100
|
"esbuild": "^0.24.0",
|
|
97
101
|
"eslint": "^9.0.0",
|
|
98
102
|
"http-server": "^14.1.1",
|
|
99
103
|
"husky": "^9.0.0",
|
|
104
|
+
"jsdom": "^26.1.0",
|
|
100
105
|
"lint-staged": "^16.2.7",
|
|
101
106
|
"rollup-plugin-esbuild": "^6.1.1",
|
|
102
107
|
"rollup-plugin-terser": "^7.0.2",
|
|
103
108
|
"semantic-release": "^25.0.0",
|
|
109
|
+
"shadow-dom-testing-library": "^1.13.1",
|
|
104
110
|
"sinon": "^19.0.0",
|
|
105
|
-
"storybook": "^10.0.0"
|
|
111
|
+
"storybook": "^10.0.0",
|
|
112
|
+
"vitest": "^4.0.0"
|
|
106
113
|
},
|
|
107
114
|
"overrides": {
|
|
108
115
|
"conventional-changelog-conventionalcommits": ">= 8.0.0"
|