@sveltia/ui 0.27.7 → 0.27.9
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.
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
* @typedef {object} Props
|
|
12
12
|
* @property {any[]} items Item list.
|
|
13
13
|
* @property {string} itemKey Item key used for the `each` loop.
|
|
14
|
-
* @property {number} [itemChunkSize] Number of items to be loaded at once.
|
|
15
|
-
* @property {Snippet<[any]>} renderItem Snippet to render each item.
|
|
14
|
+
* @property {number} [itemChunkSize] Number of items to be loaded at once. Defaults to 25.
|
|
15
|
+
* @property {Snippet<[any, number]>} renderItem Snippet to render each item. The snippet receives
|
|
16
|
+
* the item and its index as parameters.
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
/** @type {Props} */
|
|
@@ -50,8 +51,8 @@
|
|
|
50
51
|
});
|
|
51
52
|
</script>
|
|
52
53
|
|
|
53
|
-
{#each items.slice(0, loadedItemSize) as item (item[itemKey])}
|
|
54
|
-
{@render renderItem(item)}
|
|
54
|
+
{#each items.slice(0, loadedItemSize) as item, index (item[itemKey] ?? index)}
|
|
55
|
+
{@render renderItem(item, index)}
|
|
55
56
|
{/each}
|
|
56
57
|
|
|
57
58
|
{#if loading}
|
|
@@ -17,13 +17,14 @@ declare const InfiniteScroll: import("svelte").Component<{
|
|
|
17
17
|
*/
|
|
18
18
|
itemKey: string;
|
|
19
19
|
/**
|
|
20
|
-
* Number of items to be loaded at once.
|
|
20
|
+
* Number of items to be loaded at once. Defaults to 25.
|
|
21
21
|
*/
|
|
22
22
|
itemChunkSize?: number | undefined;
|
|
23
23
|
/**
|
|
24
|
-
* Snippet to render each item.
|
|
24
|
+
* Snippet to render each item. The snippet receives
|
|
25
|
+
* the item and its index as parameters.
|
|
25
26
|
*/
|
|
26
|
-
renderItem: Snippet<[any]>;
|
|
27
|
+
renderItem: Snippet<[any, number]>;
|
|
27
28
|
}, {}, "">;
|
|
28
29
|
type Props = {
|
|
29
30
|
/**
|
|
@@ -35,12 +36,13 @@ type Props = {
|
|
|
35
36
|
*/
|
|
36
37
|
itemKey: string;
|
|
37
38
|
/**
|
|
38
|
-
* Number of items to be loaded at once.
|
|
39
|
+
* Number of items to be loaded at once. Defaults to 25.
|
|
39
40
|
*/
|
|
40
41
|
itemChunkSize?: number | undefined;
|
|
41
42
|
/**
|
|
42
|
-
* Snippet to render each item.
|
|
43
|
+
* Snippet to render each item. The snippet receives
|
|
44
|
+
* the item and its index as parameters.
|
|
43
45
|
*/
|
|
44
|
-
renderItem: Snippet<[any]>;
|
|
46
|
+
renderItem: Snippet<[any, number]>;
|
|
45
47
|
};
|
|
46
48
|
import type { Snippet } from 'svelte';
|
|
@@ -93,13 +93,24 @@
|
|
|
93
93
|
ondragover={(event) => event.preventDefault()}
|
|
94
94
|
ondrop={(event) => event.preventDefault()}
|
|
95
95
|
oncontextmenu={(event) => {
|
|
96
|
-
//
|
|
96
|
+
// Allow context menu in developer mode
|
|
97
|
+
if (document.documentElement.matches('[data-env="dev"]')) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// eslint-disable-next-line prefer-destructuring
|
|
102
|
+
const target = /** @type {HTMLElement} */ (event.target);
|
|
103
|
+
|
|
104
|
+
// Allow context menu on text inputs and contentEditable elements
|
|
97
105
|
if (
|
|
98
|
-
|
|
99
|
-
|
|
106
|
+
document.documentElement.matches('[data-env="dev"]') ||
|
|
107
|
+
(target?.matches('input, textarea') && 'maxLength' in target) ||
|
|
108
|
+
/** @type {HTMLElement} */ (target?.closest('[role="textbox"]'))?.contentEditable === 'true'
|
|
100
109
|
) {
|
|
101
|
-
|
|
110
|
+
return;
|
|
102
111
|
}
|
|
112
|
+
|
|
113
|
+
event.preventDefault();
|
|
103
114
|
}}
|
|
104
115
|
>
|
|
105
116
|
{@render children?.()}
|
|
@@ -6,6 +6,26 @@ import { generateElementId } from '@sveltia/utils/element';
|
|
|
6
6
|
import { sleep } from '@sveltia/utils/misc';
|
|
7
7
|
import { getSelectedItemDetail } from './select.svelte';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Normalize the given string for search value comparison. Since `transliterate` is slow, we only
|
|
11
|
+
* apply basic normalization.
|
|
12
|
+
* @param {string} value Original value.
|
|
13
|
+
* @returns {string} Normalized value.
|
|
14
|
+
* @todo Move this to @sveltia/utils.
|
|
15
|
+
*/
|
|
16
|
+
const normalize = (value) => {
|
|
17
|
+
value = value.trim();
|
|
18
|
+
|
|
19
|
+
if (!value) {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return value
|
|
24
|
+
.normalize('NFD')
|
|
25
|
+
.replace(/\p{Diacritic}/gu, '')
|
|
26
|
+
.toLocaleLowerCase();
|
|
27
|
+
};
|
|
28
|
+
|
|
9
29
|
/**
|
|
10
30
|
* @type {{ [role: string]: {
|
|
11
31
|
* orientation: 'vertical' | 'horizontal',
|
|
@@ -464,18 +484,18 @@ class Group {
|
|
|
464
484
|
* @param {{ searchTerms: string }} params Updated params.
|
|
465
485
|
*/
|
|
466
486
|
onUpdate({ searchTerms }) {
|
|
467
|
-
const terms = searchTerms
|
|
487
|
+
const terms = normalize(searchTerms);
|
|
468
488
|
const _terms = terms ? terms.split(/\s+/) : [];
|
|
469
489
|
|
|
470
490
|
const matched = this.allMembers
|
|
471
491
|
.map((member) => {
|
|
472
|
-
const searchValue =
|
|
473
|
-
|
|
474
|
-
member.dataset.searchValue ??
|
|
492
|
+
const searchValue = normalize(
|
|
493
|
+
member.dataset.searchValue ??
|
|
475
494
|
member.dataset.label ??
|
|
476
495
|
member.querySelector('.label')?.textContent ??
|
|
477
|
-
member.textContent
|
|
478
|
-
|
|
496
|
+
member.textContent ??
|
|
497
|
+
'',
|
|
498
|
+
);
|
|
479
499
|
|
|
480
500
|
const hidden = !_terms.every((term) => searchValue.includes(term));
|
|
481
501
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltia/ui",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@sveltejs/adapter-auto": "^6.0.1",
|
|
51
|
-
"@sveltejs/kit": "^2.
|
|
51
|
+
"@sveltejs/kit": "^2.27.0",
|
|
52
52
|
"@sveltejs/package": "^2.4.0",
|
|
53
53
|
"@sveltejs/vite-plugin-svelte": "6.1.0",
|
|
54
54
|
"cspell": "^9.2.0",
|
|
@@ -56,18 +56,18 @@
|
|
|
56
56
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
57
57
|
"eslint-config-prettier": "^10.1.8",
|
|
58
58
|
"eslint-plugin-import": "^2.32.0",
|
|
59
|
-
"eslint-plugin-jsdoc": "^
|
|
59
|
+
"eslint-plugin-jsdoc": "^52.0.2",
|
|
60
60
|
"eslint-plugin-svelte": "^2.46.1",
|
|
61
61
|
"postcss": "^8.5.6",
|
|
62
62
|
"postcss-html": "^1.8.0",
|
|
63
63
|
"prettier": "^3.6.2",
|
|
64
64
|
"prettier-plugin-svelte": "^3.4.0",
|
|
65
65
|
"sass": "^1.89.2",
|
|
66
|
-
"stylelint": "^16.
|
|
66
|
+
"stylelint": "^16.23.0",
|
|
67
67
|
"stylelint-config-recommended-scss": "^15.0.1",
|
|
68
68
|
"stylelint-scss": "^6.12.1",
|
|
69
|
-
"svelte": "5.37.
|
|
70
|
-
"svelte-check": "^4.3.
|
|
69
|
+
"svelte": "5.37.3",
|
|
70
|
+
"svelte-check": "^4.3.1",
|
|
71
71
|
"svelte-i18n": "^4.0.1",
|
|
72
72
|
"svelte-preprocess": "^6.0.3",
|
|
73
73
|
"tslib": "^2.8.1",
|