@cloudparker/moldex.js 0.0.124 → 4.1.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.
- package/dist/types.d.ts +6 -0
- package/dist/types.js +7 -0
- package/dist/views/core/button/components/button/button.svelte +135 -83
- package/dist/views/core/button/components/button-back/button-back.svelte +28 -15
- package/dist/views/core/button/components/button-close/button-close.svelte +4 -2
- package/dist/views/core/button/components/button-close-icon/button-close-icon.svelte +29 -15
- package/dist/views/core/button/components/button-dropdown/button-dropdown.svelte +96 -72
- package/dist/views/core/button/components/button-dropdown/button-dropdown.svelte.d.ts +1 -1
- package/dist/views/core/button/components/button-list-item/button-list-item.svelte +98 -52
- package/dist/views/core/button/components/button-menu/button-menu.svelte +79 -43
- package/dist/views/core/button/components/button-ok/button-ok.svelte +4 -2
- package/dist/views/core/button/components/button-search/button-search.svelte +45 -21
- package/dist/views/core/button/components/switch/switch.svelte +50 -37
- package/dist/views/core/common/components/content-area/content-area.svelte +40 -27
- package/dist/views/core/common/components/loading/loading.svelte +9 -2
- package/dist/views/core/common/components/virtual-scrolling/virtual-scrolling-list.svelte +37 -20
- package/dist/views/core/dialog/components/cropper-dialog/cropper-dialog.svelte +52 -36
- package/dist/views/core/dialog/components/dialog/dialog.svelte +298 -177
- package/dist/views/core/dialog/components/loading-dialog/loading-dialog.svelte +30 -18
- package/dist/views/core/dialog/components/msg-dialog/msg-dialog.svelte +17 -7
- package/dist/views/core/dialog/components/number-field-dialog/number-field-dialog.svelte +41 -26
- package/dist/views/core/dialog/components/picker-dialog/picker-dialog.svelte +150 -105
- package/dist/views/core/dialog/components/text-field-dialog/text-field-dialog.svelte +40 -25
- package/dist/views/core/dialog/components/textarea-field-dialog/textarea-field-dialog.svelte +40 -25
- package/dist/views/core/drawer/components/drawer/drawer.svelte +58 -36
- package/dist/views/core/icon/components/icon/icon.svelte +24 -12
- package/dist/views/core/icon/components/icon-circle/icon-circle.svelte +10 -2
- package/dist/views/core/input/components/checkbox-field/checkbox-field.svelte +44 -25
- package/dist/views/core/input/components/color-field/color-field.svelte +81 -69
- package/dist/views/core/input/components/combobox-field/combobox-field.svelte +359 -269
- package/dist/views/core/input/components/date-field/date-field.svelte +39 -30
- package/dist/views/core/input/components/datetime-field/datetime-field.svelte +18 -12
- package/dist/views/core/input/components/email-field/email-field.svelte +17 -12
- package/dist/views/core/input/components/file-field/file-field.svelte +78 -64
- package/dist/views/core/input/components/input-field/input-field.svelte +267 -164
- package/dist/views/core/input/components/label/label.svelte +24 -10
- package/dist/views/core/input/components/number-field/number-field.svelte +18 -12
- package/dist/views/core/input/components/password-field/password-field.svelte +70 -57
- package/dist/views/core/input/components/phone-field/phone-field.svelte +155 -104
- package/dist/views/core/input/components/radio-field/radio-field.svelte +83 -52
- package/dist/views/core/input/components/range-field/range-field.svelte +67 -44
- package/dist/views/core/input/components/search-field/search-field.svelte +62 -45
- package/dist/views/core/input/components/text-field/text-field.svelte +21 -16
- package/dist/views/core/input/components/textarea-field/textarea-field.svelte +17 -12
- package/dist/views/core/input/components/time-field/time-field.svelte +17 -12
- package/dist/views/core/navbar/components/navbar/navbar.svelte +76 -38
- package/dist/views/core/no-data/components/no-data/no-data.svelte +36 -19
- package/dist/views/core/pagination/components/pagination/pagination.svelte +90 -66
- package/dist/views/core/progressbar/components/progressbar/progressbar.svelte +36 -22
- package/dist/views/core/ruler/components/vertical-ruler/verticcal-ruler.svelte +5 -1
- package/dist/views/core/screen-detector/components/screen-detector.svelte +13 -9
- package/dist/views/core/sidebar/components/sidebar.svelte +36 -23
- package/dist/views/core/spinner/components/spinner/spinner.svelte +6 -1
- package/dist/views/core/text/components/text-await/text-await.svelte +9 -1
- package/dist/views/core/text/components/text-copy/text-copy.svelte +27 -16
- package/dist/views/core/text/components/text-currency/text-currency.svelte +13 -2
- package/dist/views/core/text/components/text-date/text-date.svelte +32 -20
- package/dist/views/core/text/components/text-email/text-email.svelte +12 -3
- package/dist/views/core/text/components/text-html/text-html.svelte +2 -1
- package/dist/views/core/text/components/text-phone/text-phone.svelte +12 -3
- package/dist/views/core/toast/components/toast/toast.svelte +43 -20
- package/dist/views/extra/fields/country-combobox-field.svelte +23 -15
- package/dist/views/extra/loaders/country-loader.svelte +33 -15
- package/dist/views/extra/texts/text-country-state.svelte +36 -28
- package/dist/views/extra/texts/text-country.svelte +16 -8
- package/package.json +3 -12
- package/readme.md +57 -2
- package/dist/tailwind.css +0 -1
- package/dist/theme.css +0 -27
|
@@ -1,272 +1,362 @@
|
|
|
1
|
-
<script module lang="ts"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
let
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
let
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export type ComboboxFieldProps = {
|
|
3
|
+
chipClassName?: string;
|
|
4
|
+
comboboxIconClassName?: string;
|
|
5
|
+
comboboxIconPath?: string;
|
|
6
|
+
createButtonClassName?: string;
|
|
7
|
+
createButtonLabel?: string;
|
|
8
|
+
displayClassName?: string;
|
|
9
|
+
displayFieldName?: string;
|
|
10
|
+
displayItemsCount?: number;
|
|
11
|
+
dropdownBodyClassName?: string;
|
|
12
|
+
dropdownBodySnippet?: Snippet;
|
|
13
|
+
dropdownClassName?: string;
|
|
14
|
+
dropdownFooterClassName?: string;
|
|
15
|
+
dropdownFooterSnippet?: Snippet;
|
|
16
|
+
dropdownHeaderClassName?: string;
|
|
17
|
+
dropdownHeaderSnippet?: Snippet;
|
|
18
|
+
emptyMessage?: string;
|
|
19
|
+
emptyMessageSnippet?: Snippet;
|
|
20
|
+
hasComboboxIcon?: boolean;
|
|
21
|
+
hasDropdownFooter?: boolean;
|
|
22
|
+
hasDropdownFooterCreateButton?: boolean;
|
|
23
|
+
hasDropdownHeader?: boolean;
|
|
24
|
+
hasDropdownHeaderSearch?: boolean;
|
|
25
|
+
hasCheckbox?: boolean;
|
|
26
|
+
iconClassName?: string;
|
|
27
|
+
iconPathFieldName?: string;
|
|
28
|
+
identityFieldName?: string;
|
|
29
|
+
itemClassName?: string;
|
|
30
|
+
items?: any[];
|
|
31
|
+
multiple?: boolean;
|
|
32
|
+
onCreateButtonClick?: (ev: MouseEvent) => void;
|
|
33
|
+
onSearch?: (value: string) => void;
|
|
34
|
+
searchClassName?: string;
|
|
35
|
+
searchFieldName?: string;
|
|
36
|
+
searchPlaceholder?: string;
|
|
37
|
+
showChip?: boolean;
|
|
38
|
+
subtitleClassName?: string;
|
|
39
|
+
subtitleFieldName?: string;
|
|
40
|
+
titleClassName?: string;
|
|
41
|
+
titleFieldName?: string;
|
|
42
|
+
checkboxIconPath?: string;
|
|
43
|
+
uncheckboxIconPath?: string;
|
|
44
|
+
checkboxIconClassName?: string;
|
|
45
|
+
uncheckboxIconClassName?: string;
|
|
46
|
+
checkboxClassName?: string;
|
|
47
|
+
dropPosition?: 'top' | 'bottom' | 'middle';
|
|
48
|
+
itemTileSnippet?: Snippet<[item: any, index: any]>;
|
|
49
|
+
};
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<script lang="ts">
|
|
53
|
+
import ButtonListItem from '../../../button/components/button-list-item/button-list-item.svelte';
|
|
54
|
+
import Button from '../../../button/components/button/button.svelte';
|
|
55
|
+
import {
|
|
56
|
+
mdiCheckCircle,
|
|
57
|
+
mdiCheckCircleOutline,
|
|
58
|
+
mdiUnfoldMoreHorizontal
|
|
59
|
+
} from '../../../icon';
|
|
60
|
+
import Icon from '../../../icon/components/icon/icon.svelte';
|
|
61
|
+
import NoData from '../../../no-data/components/no-data/no-data.svelte';
|
|
62
|
+
import type { Snippet } from 'svelte';
|
|
63
|
+
import InputField, { type InputFieldProps } from '../input-field/input-field.svelte';
|
|
64
|
+
import SearchField from '../search-field/search-field.svelte';
|
|
65
|
+
import { SvelteSet } from 'svelte/reactivity';
|
|
66
|
+
import VirtualScrollingList from '../../../common/components/virtual-scrolling/virtual-scrolling-list.svelte';
|
|
67
|
+
|
|
68
|
+
let {
|
|
69
|
+
appearance,
|
|
70
|
+
chipClassName,
|
|
71
|
+
className,
|
|
72
|
+
comboboxIconClassName,
|
|
73
|
+
comboboxIconPath = mdiUnfoldMoreHorizontal,
|
|
74
|
+
contentSnippet,
|
|
75
|
+
createButtonClassName,
|
|
76
|
+
createButtonLabel = 'Add',
|
|
77
|
+
displayClassName,
|
|
78
|
+
displayFieldName = 'name',
|
|
79
|
+
displayItemsCount,
|
|
80
|
+
dropdownBodyClassName,
|
|
81
|
+
dropdownBodySnippet,
|
|
82
|
+
dropdownClassName,
|
|
83
|
+
dropdownFooterClassName,
|
|
84
|
+
dropdownFooterSnippet,
|
|
85
|
+
dropdownHeaderClassName,
|
|
86
|
+
dropdownHeaderSnippet,
|
|
87
|
+
emptyMessage = 'No items exists!',
|
|
88
|
+
emptyMessageSnippet,
|
|
89
|
+
hasComboboxIcon = true,
|
|
90
|
+
hasDropdownFooter,
|
|
91
|
+
hasDropdownFooterCreateButton,
|
|
92
|
+
hasDropdownHeader,
|
|
93
|
+
hasDropdownHeaderSearch,
|
|
94
|
+
hasCheckbox,
|
|
95
|
+
iconClassName,
|
|
96
|
+
iconPathFieldName,
|
|
97
|
+
id,
|
|
98
|
+
identityFieldName = '_id',
|
|
99
|
+
itemClassName,
|
|
100
|
+
items,
|
|
101
|
+
multiple,
|
|
102
|
+
name,
|
|
103
|
+
onCreateButtonClick,
|
|
104
|
+
onSearch,
|
|
105
|
+
searchClassName,
|
|
106
|
+
searchFieldName = 'name',
|
|
107
|
+
searchPlaceholder = 'Search...',
|
|
108
|
+
showChip,
|
|
109
|
+
size,
|
|
110
|
+
subtitleClassName,
|
|
111
|
+
subtitleFieldName,
|
|
112
|
+
titleClassName,
|
|
113
|
+
titleFieldName = 'name',
|
|
114
|
+
value = $bindable(null),
|
|
115
|
+
checkboxIconPath = mdiCheckCircle,
|
|
116
|
+
uncheckboxIconPath = mdiCheckCircleOutline,
|
|
117
|
+
checkboxIconClassName = '',
|
|
118
|
+
uncheckboxIconClassName = '',
|
|
119
|
+
checkboxClassName = '',
|
|
120
|
+
dropPosition = 'bottom',
|
|
121
|
+
itemTileSnippet,
|
|
122
|
+
onChange,
|
|
123
|
+
...props
|
|
124
|
+
}: InputFieldProps & ComboboxFieldProps = $props();
|
|
125
|
+
|
|
126
|
+
let searchFieldRef: any | null = $state(null);
|
|
127
|
+
|
|
128
|
+
let isPlaced = $state(false);
|
|
129
|
+
let searchText: string = $state('');
|
|
130
|
+
let dropdownHeight = $state(0);
|
|
131
|
+
let windowScrollY = $state(0);
|
|
132
|
+
let bodyHeight: number = $state(0);
|
|
133
|
+
|
|
134
|
+
let placementClassName = $derived.by(() => {
|
|
135
|
+
if (!isPlaced) return 'mt-1';
|
|
136
|
+
|
|
137
|
+
const rect = inputFieldRef.getBoundingClientRect();
|
|
138
|
+
const spaceBelow = window.innerHeight - rect.bottom;
|
|
139
|
+
const spaceAbove = rect.top;
|
|
140
|
+
|
|
141
|
+
let placement;
|
|
142
|
+
|
|
143
|
+
switch (dropPosition) {
|
|
144
|
+
case 'top':
|
|
145
|
+
placement = 'bottom-full mb-1';
|
|
146
|
+
break;
|
|
147
|
+
case 'middle':
|
|
148
|
+
placement = '-translate-y-1/2 top-1/2';
|
|
149
|
+
break;
|
|
150
|
+
default:
|
|
151
|
+
placement = 'mt-1';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (dropPosition === 'bottom' && spaceBelow < dropdownHeight && spaceAbove > dropdownHeight) {
|
|
155
|
+
placement = 'bottom-full mb-1';
|
|
156
|
+
} else if (dropPosition === 'top' && spaceAbove < dropdownHeight && spaceBelow > dropdownHeight) {
|
|
157
|
+
placement = 'mt-1';
|
|
158
|
+
} else if (dropPosition === 'middle') {
|
|
159
|
+
const spaceNeeded = dropdownHeight / 2;
|
|
160
|
+
if (spaceAbove < spaceNeeded || spaceBelow < spaceNeeded) {
|
|
161
|
+
placement = spaceAbove > spaceBelow ? 'bottom-full mb-1' : 'mt-1';
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return placement;
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
let selectedItemsSet: SvelteSet<any> = $derived(
|
|
169
|
+
value ? new SvelteSet<any>(Array.isArray(value) ? value : [value]) : new SvelteSet<any>()
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
let comboboxIconSizeClassName = $derived.by(() => {
|
|
173
|
+
if (size) {
|
|
174
|
+
switch (size) {
|
|
175
|
+
case 'lg':
|
|
176
|
+
return '!h-7 !w-7';
|
|
177
|
+
case 'md':
|
|
178
|
+
return '!h-6 !w-6';
|
|
179
|
+
case 'sm':
|
|
180
|
+
return '!h-5 !w-5';
|
|
181
|
+
case 'xs':
|
|
182
|
+
return '!h-4 !w-4';
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
let hasPrimitiveItemsData = $derived.by(() => {
|
|
188
|
+
if (items) {
|
|
189
|
+
let firstItem = items[0];
|
|
190
|
+
return (
|
|
191
|
+
typeof firstItem == 'string' || typeof firstItem == 'number' || firstItem instanceof Date
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
return false;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
let _value = $derived.by(() => {
|
|
198
|
+
return selectedItemsSet?.size ? ' ' : '';
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
let displayItems: string[] = $derived.by(() => {
|
|
202
|
+
let array = Array.from(selectedItemsSet);
|
|
203
|
+
let results = array.map((id) => {
|
|
204
|
+
if (hasPrimitiveItemsData) {
|
|
205
|
+
return id;
|
|
206
|
+
} else {
|
|
207
|
+
let item = itemsIdentityMap[id];
|
|
208
|
+
if (item) {
|
|
209
|
+
if (displayFieldName && item.hasOwnProperty(displayFieldName)) {
|
|
210
|
+
return item[displayFieldName];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return results;
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
let displayItemsTitle = $derived(displayItems.join(', '));
|
|
219
|
+
|
|
220
|
+
let displayText: string = $derived.by(() => {
|
|
221
|
+
let results: string[] = displayItems;
|
|
222
|
+
if (!showChip) {
|
|
223
|
+
if (results?.length) {
|
|
224
|
+
if (multiple) {
|
|
225
|
+
let res: string = results.join(', ');
|
|
226
|
+
if (displayItemsCount != null && displayItemsCount > 1) {
|
|
227
|
+
res = results.slice(0, displayItemsCount).join(', ');
|
|
228
|
+
if (results.length > displayItemsCount) {
|
|
229
|
+
res += `<span class="text-gray-400 px-2">+ ${results.length - displayItemsCount} </span>`;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return res;
|
|
233
|
+
} else {
|
|
234
|
+
return results[0] || '';
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return '';
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
let preparedItems = $derived.by(() => {
|
|
243
|
+
return (items || []).map((item, index) => {
|
|
244
|
+
let res: any = {};
|
|
245
|
+
if (hasPrimitiveItemsData) {
|
|
246
|
+
res[identityFieldName] = item;
|
|
247
|
+
res[titleFieldName] = item;
|
|
248
|
+
res[searchFieldName] = item;
|
|
249
|
+
} else {
|
|
250
|
+
res = item;
|
|
251
|
+
}
|
|
252
|
+
return res;
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
let itemsIdentityMap: any = $derived.by(() => {
|
|
257
|
+
return preparedItems.reduce((acc, val) => {
|
|
258
|
+
acc[val[identityFieldName]] = val;
|
|
259
|
+
return acc;
|
|
260
|
+
}, {});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
let filteredItems = $derived.by(() => {
|
|
264
|
+
if (searchText) {
|
|
265
|
+
return preparedItems.filter((item: any) => {
|
|
266
|
+
return (item[searchFieldName] || '').toLowerCase().indexOf(searchText) >= 0;
|
|
267
|
+
});
|
|
268
|
+
} else {
|
|
269
|
+
return [...preparedItems];
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
let inputFieldRef: any | null = $state(null);
|
|
274
|
+
|
|
275
|
+
export function focus() {
|
|
276
|
+
inputFieldRef?.focus();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function toggleDropdown() {
|
|
280
|
+
if (isPlaced) {
|
|
281
|
+
closeDropdown();
|
|
282
|
+
} else {
|
|
283
|
+
openDropdown();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function closeDropdown() {
|
|
288
|
+
searchText = '';
|
|
289
|
+
isPlaced = false;
|
|
290
|
+
focus();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function openDropdown() {
|
|
294
|
+
isPlaced = true;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function handleInputClick() {
|
|
298
|
+
toggleDropdown();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function handleBackdropClick() {
|
|
302
|
+
toggleDropdown();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function handleKeyDown(event: KeyboardEvent) {
|
|
306
|
+
if (event.key === 'Escape') {
|
|
307
|
+
closeDropdown();
|
|
308
|
+
} else if (event.key === 'Enter' || event.key === ' ') {
|
|
309
|
+
event.preventDefault(); // Prevent default action for spacebar to avoid scrolling
|
|
310
|
+
toggleDropdown();
|
|
311
|
+
} else if (/^[a-zA-Z0-9]$/.test(event.key)) {
|
|
312
|
+
searchFieldRef && searchFieldRef.focus();
|
|
313
|
+
} else if (event.key === 'Backspace' || event.key === 'Delete') {
|
|
314
|
+
event.preventDefault(); // Prevent default action for these keys if necessary
|
|
315
|
+
selectedItemsSet.clear();
|
|
316
|
+
value = null;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function handleDropdownKeyDown(event: KeyboardEvent) {
|
|
321
|
+
if (event.key === 'Escape') {
|
|
322
|
+
closeDropdown();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function handleSearch(value: string) {
|
|
327
|
+
searchText = value;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function handleItemClick(ev: MouseEvent, item: any, index: number) {
|
|
331
|
+
let id = item[identityFieldName];
|
|
332
|
+
if (multiple) {
|
|
333
|
+
if (selectedItemsSet.has(id)) {
|
|
334
|
+
selectedItemsSet.delete(id);
|
|
335
|
+
} else {
|
|
336
|
+
selectedItemsSet.add(id);
|
|
337
|
+
}
|
|
338
|
+
} else {
|
|
339
|
+
selectedItemsSet.clear();
|
|
340
|
+
selectedItemsSet.add(id);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
items = [...(items || [])];
|
|
344
|
+
|
|
345
|
+
let array = Array.from(selectedItemsSet);
|
|
346
|
+
if (array.length) {
|
|
347
|
+
value = multiple ? array : array[0];
|
|
348
|
+
} else {
|
|
349
|
+
value = null;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (!multiple) {
|
|
353
|
+
closeDropdown();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
onChange && onChange(value);
|
|
357
|
+
|
|
358
|
+
// console.log('handleItemClick', selectedItemsSet, value);
|
|
359
|
+
}
|
|
270
360
|
</script>
|
|
271
361
|
|
|
272
362
|
{#snippet rightIcon()}
|