@sveltia/ui 0.27.8 → 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.
|
@@ -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
|
|