@kws3/ui 1.9.2 → 2.0.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/CHANGELOG.mdx +74 -48
- package/buttons/ConfirmButton.svelte +11 -3
- package/buttons/DeleteButton.svelte +2 -3
- package/buttons/ProcessButton.svelte +3 -4
- package/buttons/SubmitButton.svelte +11 -3
- package/charts/AreaChart.svelte +1 -1
- package/charts/BarChart.svelte +1 -1
- package/charts/Chart.svelte +1 -0
- package/charts/DonutChart.svelte +1 -1
- package/charts/LineChart.svelte +1 -1
- package/charts/MixedChart.svelte +1 -1
- package/charts/PieChart.svelte +1 -1
- package/charts/RadialChart.svelte +1 -1
- package/charts/utils.js +1 -0
- package/controls/Checkbox.svelte +10 -4
- package/controls/FileUpload.svelte +14 -8
- package/controls/NumberInput.svelte +19 -10
- package/controls/Radio.svelte +8 -2
- package/controls/RangeSlider.svelte +8 -2
- package/controls/Toggle.svelte +9 -2
- package/controls/ToggleButtons.svelte +10 -3
- package/datagrid/DataSearch/DataSearch.svelte +1 -1
- package/datagrid/GridView/GridCell.svelte +3 -0
- package/datagrid/GridView/GridRow.svelte +15 -0
- package/datagrid/GridView/GridView.svelte +21 -3
- package/datagrid/Pagination/Pagination.svelte +3 -3
- package/datagrid/TileView/TileView.svelte +46 -5
- package/datagrid/TileView/TileViewItem.svelte +4 -0
- package/form/index.js +160 -0
- package/forms/AutoComplete.svelte +78 -33
- package/forms/Datepicker.svelte +22 -5
- package/forms/PasswordValidator/PasswordValidator.svelte +8 -8
- package/forms/PasswordValidator/validatePassword.js +13 -2
- package/forms/SearchInput.svelte +180 -0
- package/forms/Timepicker.svelte +69 -4
- package/forms/actions.js +21 -15
- package/forms/colorpicker/Colorpicker.js +28 -3
- package/forms/colorpicker/Colorpicker.svelte +2 -2
- package/forms/select/MultiSelect.svelte +89 -30
- package/forms/select/SearchableSelect.svelte +6 -5
- package/helpers/CardModal.svelte +2 -1
- package/helpers/ClipboardCopier.svelte +4 -1
- package/helpers/Dialog/Dialog.svelte +13 -8
- package/helpers/Dialog/index.js +6 -0
- package/helpers/Divider.svelte +2 -2
- package/helpers/FloatingUI/Floatie.svelte +6 -6
- package/helpers/FloatingUI/index.js +2 -1
- package/helpers/Icon.svelte +25 -9
- package/helpers/Loader.svelte +10 -3
- package/helpers/Message.svelte +2 -2
- package/helpers/Modal.svelte +2 -1
- package/helpers/Notification.svelte +1 -1
- package/helpers/Popover.svelte +4 -4
- package/helpers/ScrollableList.svelte +12 -8
- package/helpers/Skeleton.svelte +4 -1
- package/helpers/Timeline/Timeline.svelte +1 -1
- package/helpers/Timeline/TimelineItem.svelte +5 -5
- package/helpers/Tooltip.js +1 -1
- package/index.js +10 -4
- package/{utils → internal}/fuzzy.js +64 -65
- package/internal/index.js +27 -0
- package/internal/scrollIntoActiveElement.js +22 -0
- package/keyboard/index.js +94 -0
- package/package.json +6 -3
- package/{utils/resizeObserver.js → resizeObserver/index.js} +0 -0
- package/search/index.js +52 -0
- package/settings.js +1 -1
- package/sliding-panes/SlidingPane.svelte +1 -4
- package/styles/AutoComplete.scss +2 -1
- package/styles/Datepicker.scss +1 -1
- package/styles/Grid.scss +14 -0
- package/styles/Pagination.scss +8 -5
- package/styles/Select.scss +2 -1
- package/transitions/components/Scale.svelte +1 -0
- package/transitions/components/getEasing.js +18 -5
- package/types/ambient.d.ts +16 -0
- package/types/index.d.ts +46 -0
- package/types/type-defs/index.ts +14 -0
- package/utils/index.js +110 -9
- package/utils/fuzzysearch.js +0 -42
- package/utils/keyboard-events.js +0 -32
package/forms/actions.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import flatpickr from "flatpickr";
|
|
2
2
|
|
|
3
|
-
function createFlatpickrAction(defaultOpts, hooks) {
|
|
3
|
+
function createFlatpickrAction(defaultOpts, hooks, type) {
|
|
4
4
|
return function (
|
|
5
5
|
node,
|
|
6
6
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -34,9 +34,9 @@ function createFlatpickrAction(defaultOpts, hooks) {
|
|
|
34
34
|
_opts["onChange"] = createFirer("dateChange");
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
let OPTS = Object.assign(defaultOpts, _opts, opts);
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
let picker = flatpickr(node, OPTS);
|
|
40
40
|
|
|
41
41
|
function createFirer(name) {
|
|
42
42
|
return (selectedDates, dateStr, instance) => {
|
|
@@ -72,6 +72,10 @@ function createFlatpickrAction(defaultOpts, hooks) {
|
|
|
72
72
|
|
|
73
73
|
return {
|
|
74
74
|
update({ opts, value, placeholder, klass, style, disabled, color }) {
|
|
75
|
+
if (!picker.isOpen) {
|
|
76
|
+
picker = flatpickr(node, Object.assign(OPTS, opts));
|
|
77
|
+
}
|
|
78
|
+
|
|
75
79
|
if (picker) {
|
|
76
80
|
picker.setDate(value);
|
|
77
81
|
if (opts) {
|
|
@@ -81,19 +85,19 @@ function createFlatpickrAction(defaultOpts, hooks) {
|
|
|
81
85
|
if (opts.mode) {
|
|
82
86
|
picker.set("mode", opts.mode);
|
|
83
87
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
picker.set("disable", opts.disable ? opts.disable : [() => false]);
|
|
88
|
-
picker.set("time_24hr", opts.time_24hr || false);
|
|
88
|
+
if (type === "time") {
|
|
89
|
+
picker.set("altFormat", opts.time_24hr ? "H:i" : "h:i K");
|
|
90
|
+
}
|
|
89
91
|
}
|
|
90
|
-
|
|
91
92
|
//respond reactively to props
|
|
93
|
+
/** @type {any} */
|
|
92
94
|
const visibleInput = picker.input.nextSibling;
|
|
93
|
-
visibleInput
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
if (visibleInput) {
|
|
96
|
+
visibleInput.className = `input is-${color} ${klass}`;
|
|
97
|
+
visibleInput.style = `${style}`;
|
|
98
|
+
visibleInput.disabled = disabled;
|
|
99
|
+
visibleInput.placeholder = placeholder;
|
|
100
|
+
}
|
|
97
101
|
}
|
|
98
102
|
},
|
|
99
103
|
destroy() {
|
|
@@ -109,7 +113,8 @@ export let datepicker = createFlatpickrAction(
|
|
|
109
113
|
altFormat: "d/m/Y",
|
|
110
114
|
dateFormat: "Y-m-d",
|
|
111
115
|
},
|
|
112
|
-
["onOpen", "onClose", "onMonthChange", "onYearChange", "onReady"]
|
|
116
|
+
["onOpen", "onClose", "onMonthChange", "onYearChange", "onReady"],
|
|
117
|
+
"date"
|
|
113
118
|
);
|
|
114
119
|
|
|
115
120
|
export let timepicker = createFlatpickrAction(
|
|
@@ -120,5 +125,6 @@ export let timepicker = createFlatpickrAction(
|
|
|
120
125
|
enableTime: true,
|
|
121
126
|
noCalendar: true,
|
|
122
127
|
},
|
|
123
|
-
["onOpen", "onClose", "onReady"]
|
|
128
|
+
["onOpen", "onClose", "onReady"],
|
|
129
|
+
"time"
|
|
124
130
|
);
|
|
@@ -77,7 +77,11 @@ export default (function (win, doc) {
|
|
|
77
77
|
(r = v), (g = p), (b = q);
|
|
78
78
|
break;
|
|
79
79
|
}
|
|
80
|
-
return [
|
|
80
|
+
return [
|
|
81
|
+
r !== undefined ? round(r * 255) : NaN,
|
|
82
|
+
g !== undefined ? round(g * 255) : NaN,
|
|
83
|
+
b !== undefined ? round(b * 255) : NaN,
|
|
84
|
+
];
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
function HSV2HEX(a) {
|
|
@@ -116,8 +120,8 @@ export default (function (win, doc) {
|
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
function RGB2HEX(a) {
|
|
119
|
-
var s = +a[2] | (+a[1] << 8) | (+a[0] << 16);
|
|
120
|
-
s = "000000" + s
|
|
123
|
+
var s = (+a[2] | (+a[1] << 8) | (+a[0] << 16)).toString(16);
|
|
124
|
+
s = "000000" + s;
|
|
121
125
|
return s.slice(-6);
|
|
122
126
|
}
|
|
123
127
|
|
|
@@ -166,12 +170,14 @@ export default (function (win, doc) {
|
|
|
166
170
|
|
|
167
171
|
return (function ($) {
|
|
168
172
|
// plugin version
|
|
173
|
+
//@ts-ignore
|
|
169
174
|
$.version = "1.3.2";
|
|
170
175
|
|
|
171
176
|
// collect all instance(s)
|
|
172
177
|
$[instance] = {};
|
|
173
178
|
|
|
174
179
|
// plug to all instance(s)
|
|
180
|
+
//@ts-ignore
|
|
175
181
|
$.each = function (fn, t) {
|
|
176
182
|
return (
|
|
177
183
|
delay(
|
|
@@ -189,27 +195,39 @@ export default (function (win, doc) {
|
|
|
189
195
|
};
|
|
190
196
|
|
|
191
197
|
// static method(s)
|
|
198
|
+
//@ts-ignore
|
|
192
199
|
$.parse = parse;
|
|
200
|
+
//@ts-ignore
|
|
193
201
|
$._HSV2RGB = HSV2RGB;
|
|
202
|
+
//@ts-ignore
|
|
194
203
|
$._HSV2HEX = HSV2HEX;
|
|
204
|
+
//@ts-ignore
|
|
195
205
|
$._RGB2HSV = RGB2HSV;
|
|
206
|
+
//@ts-ignore
|
|
196
207
|
$._HEX2HSV = HEX2HSV;
|
|
208
|
+
//@ts-ignore
|
|
197
209
|
$._HEX2RGB = function (a) {
|
|
198
210
|
return _2RGB_pri(HEX2RGB(a));
|
|
199
211
|
};
|
|
212
|
+
//@ts-ignore
|
|
200
213
|
$.HSV2RGB = function (a) {
|
|
201
214
|
return HSV2RGB(_2HSV_pri(a));
|
|
202
215
|
};
|
|
216
|
+
//@ts-ignore
|
|
203
217
|
$.HSV2HEX = function (a) {
|
|
204
218
|
return HSV2HEX(_2HSV_pri(a));
|
|
205
219
|
};
|
|
220
|
+
//@ts-ignore
|
|
206
221
|
$.RGB2HSV = function (a) {
|
|
207
222
|
return _2HSV_pub(RGB2HSV(a));
|
|
208
223
|
};
|
|
224
|
+
//@ts-ignore
|
|
209
225
|
$.RGB2HEX = RGB2HEX;
|
|
226
|
+
//@ts-ignore
|
|
210
227
|
$.HEX2HSV = function (s) {
|
|
211
228
|
return _2HSV_pub(HEX2HSV(s));
|
|
212
229
|
};
|
|
230
|
+
//@ts-ignore
|
|
213
231
|
$.HEX2RGB = HEX2RGB;
|
|
214
232
|
|
|
215
233
|
return $;
|
|
@@ -405,6 +423,7 @@ export default (function (win, doc) {
|
|
|
405
423
|
if (is_target) {
|
|
406
424
|
create();
|
|
407
425
|
} else {
|
|
426
|
+
//@ts-ignore
|
|
408
427
|
$.exit();
|
|
409
428
|
}
|
|
410
429
|
trigger(is_target ? "enter" : "exit", [$]);
|
|
@@ -416,13 +435,16 @@ export default (function (win, doc) {
|
|
|
416
435
|
if (events !== false) {
|
|
417
436
|
on(events, target, click);
|
|
418
437
|
}
|
|
438
|
+
//@ts-ignore
|
|
419
439
|
$.create = function () {
|
|
420
440
|
return create(1), trigger("create", [$]), $;
|
|
421
441
|
};
|
|
442
|
+
//@ts-ignore
|
|
422
443
|
$.destroy = function () {
|
|
423
444
|
if (events !== false) {
|
|
424
445
|
off(events, target, click);
|
|
425
446
|
}
|
|
447
|
+
//@ts-ignore
|
|
426
448
|
$.exit(), set_data(false);
|
|
427
449
|
return trigger("destroy", [$]), $;
|
|
428
450
|
};
|
|
@@ -435,8 +457,10 @@ export default (function (win, doc) {
|
|
|
435
457
|
SV_point.style.right = SV_W - SV_point_W / 2 - SV_W * +HSV[1] + "px";
|
|
436
458
|
SV_point.style.top = SV_H - SV_point_H / 2 - SV_H * +HSV[2] + "px";
|
|
437
459
|
};
|
|
460
|
+
//@ts-ignore
|
|
438
461
|
$.exit = function () {
|
|
439
462
|
if (visible()) {
|
|
463
|
+
//@ts-ignore
|
|
440
464
|
visible().removeChild(picker);
|
|
441
465
|
$.visible = false;
|
|
442
466
|
}
|
|
@@ -499,6 +523,7 @@ export default (function (win, doc) {
|
|
|
499
523
|
if (!is_target && !is_picker) {
|
|
500
524
|
// click outside the target or picker element to exit
|
|
501
525
|
if (visible() && events !== false)
|
|
526
|
+
//@ts-ignore
|
|
502
527
|
$.exit(), trigger("exit", [$]), trigger_(0, a);
|
|
503
528
|
} else {
|
|
504
529
|
if (is_picker) {
|
|
@@ -36,7 +36,7 @@ This property can be bound to, to fetch the current colour, Default: `"000000"`
|
|
|
36
36
|
on:focus={focused}
|
|
37
37
|
{disabled}
|
|
38
38
|
bind:value={color}
|
|
39
|
-
use:colorpicker
|
|
39
|
+
use:colorpicker />
|
|
40
40
|
{#if !mini}
|
|
41
41
|
<Icon icon="hashtag" class="is-left" inner_style="color:#{color}" />
|
|
42
42
|
{/if}
|
|
@@ -84,7 +84,7 @@ This property can be bound to, to fetch the current colour, Default: `"000000"`
|
|
|
84
84
|
disabled = false,
|
|
85
85
|
/**
|
|
86
86
|
* Size of the colour picker trigger
|
|
87
|
-
* @type {''
|
|
87
|
+
* @type {import('@kws3/ui/types').SizeOptions}
|
|
88
88
|
*/
|
|
89
89
|
size = "";
|
|
90
90
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
@component
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
@param {
|
|
5
|
+
@param {Array|?string} [value=undefined] - Value of the Input
|
|
6
6
|
|
|
7
|
-
This property can be bound to, to fetch the current value, Default: `
|
|
7
|
+
This property can be bound to, to fetch the current value, Default: `undefined`
|
|
8
8
|
@param {object} [max=null] - Maximum number of selectable items from dropdown list.
|
|
9
9
|
|
|
10
10
|
Accepts a `null` value for unlimited selected items.
|
|
@@ -20,11 +20,11 @@ this property of each object will be returned as the value, Default: `"id"`
|
|
|
20
20
|
|
|
21
21
|
Only send this prop if you want to fetch `options` asynchronously.
|
|
22
22
|
`options` prop will be ignored if this prop is set., Default: `null`
|
|
23
|
-
@param {'fuzzy'|'strict'} [search_strategy="fuzzy"] - Filtered options to be displayed strictly based on search text or perform a fuzzy match.
|
|
23
|
+
@param {string|'fuzzy'|'strict'} [search_strategy="fuzzy"] - Filtered options to be displayed strictly based on search text or perform a fuzzy match.
|
|
24
24
|
Fuzzy match will not work if `search` function is set, as the backend service is meant to do the matching., Default: `"fuzzy"`
|
|
25
25
|
@param {number} [scoreThreshold=3] - Score threshold for fuzzy search strategy, setting high score gives more fuzzy matches., Default: `3`
|
|
26
|
-
@param {''|'small'|'medium'|'large'} [size=""] - Size of the input, Default: `""`
|
|
27
|
-
@param {''|'primary'|'success'|'warning'|'info'|'danger'|'dark'|'light'} [color=""] - Color of the input, Default: `""`
|
|
26
|
+
@param {string|''|'small'|'medium'|'large'} [size=""] - Size of the input, Default: `""`
|
|
27
|
+
@param {string|''|'primary'|'success'|'warning'|'info'|'danger'|'dark'|'light'} [color=""] - Color of the input, Default: `""`
|
|
28
28
|
@param {string} [style=""] - Inline CSS for input container, Default: `""`
|
|
29
29
|
@param {boolean} [readonly=false] - Marks component as read-only, Default: `false`
|
|
30
30
|
@param {boolean} [disabled=false] - Disables the component, Default: `false`
|
|
@@ -132,8 +132,22 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
132
132
|
on:mousedown|preventDefault|stopPropagation={() =>
|
|
133
133
|
handleOptionMouseDown(option)}
|
|
134
134
|
on:mouseenter|preventDefault|stopPropagation={() => {
|
|
135
|
+
if (mouseTracker.preventSelect) return;
|
|
135
136
|
activeOption = option;
|
|
136
137
|
}}
|
|
138
|
+
on:mousemove|preventDefault|stopPropagation={(e) => {
|
|
139
|
+
let { preventSelect, lastX, lastY } = mouseTracker;
|
|
140
|
+
if (
|
|
141
|
+
preventSelect &&
|
|
142
|
+
(lastX !== e.clientX || lastY !== e.clientY)
|
|
143
|
+
) {
|
|
144
|
+
mouseTracker.preventSelect = false;
|
|
145
|
+
activeOption = option;
|
|
146
|
+
}
|
|
147
|
+
// mouse x,y is not in same position after the scrolling
|
|
148
|
+
mouseTracker.lastX = e.clientX;
|
|
149
|
+
mouseTracker.lastY = e.clientY;
|
|
150
|
+
}}
|
|
137
151
|
class="is-size-{list_text_size[size]}"
|
|
138
152
|
class:selected={isSelected(option)}
|
|
139
153
|
class:active={activeOption === option}>
|
|
@@ -164,7 +178,8 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
164
178
|
import { debounce } from "@kws3/ui/utils";
|
|
165
179
|
import { createEventDispatcher, onMount, tick } from "svelte";
|
|
166
180
|
import { createPopper } from "@popperjs/core";
|
|
167
|
-
import {
|
|
181
|
+
import { makeSearchEngine } from "@kws3/ui/search";
|
|
182
|
+
import { scrollIntoActiveElement } from "../../internal";
|
|
168
183
|
|
|
169
184
|
const sameWidthPopperModifier = {
|
|
170
185
|
name: "sameWidth",
|
|
@@ -184,10 +199,16 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
184
199
|
|
|
185
200
|
const rootContainerId = "kws-overlay-root";
|
|
186
201
|
|
|
202
|
+
/**
|
|
203
|
+
* @typedef {import('@kws3/ui/types').ColorOptions} ColorOptions
|
|
204
|
+
* @typedef {import('@kws3/ui/types').SizeOptions} SizeOptions
|
|
205
|
+
*/
|
|
206
|
+
|
|
187
207
|
/**
|
|
188
208
|
* Value of the Input
|
|
189
209
|
*
|
|
190
210
|
* This property can be bound to, to fetch the current value
|
|
211
|
+
* @type {Array|?string}
|
|
191
212
|
*/
|
|
192
213
|
export let value = [];
|
|
193
214
|
/**
|
|
@@ -195,6 +216,7 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
195
216
|
*
|
|
196
217
|
* Accepts a `null` value for unlimited selected items.
|
|
197
218
|
* Or a number value
|
|
219
|
+
* @type {?number}
|
|
198
220
|
*/
|
|
199
221
|
export let max = null;
|
|
200
222
|
/**
|
|
@@ -230,22 +252,23 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
230
252
|
/**
|
|
231
253
|
* Filtered options to be displayed strictly based on search text or perform a fuzzy match.
|
|
232
254
|
* Fuzzy match will not work if `search` function is set, as the backend service is meant to do the matching.
|
|
233
|
-
* @type {'fuzzy'|'strict'}
|
|
255
|
+
* @type {string|'fuzzy'|'strict'}
|
|
234
256
|
*/
|
|
235
257
|
export let search_strategy = "fuzzy";
|
|
236
258
|
|
|
237
259
|
/**
|
|
238
260
|
* Score threshold for fuzzy search strategy, setting high score gives more fuzzy matches.
|
|
261
|
+
* @type {number}
|
|
239
262
|
*/
|
|
240
263
|
export let scoreThreshold = 3;
|
|
241
264
|
/**
|
|
242
265
|
* Size of the input
|
|
243
|
-
* @type {''
|
|
266
|
+
* @type {import('@kws3/ui/types').SizeOptions}
|
|
244
267
|
*/
|
|
245
268
|
export let size = "";
|
|
246
269
|
/**
|
|
247
270
|
* Color of the input
|
|
248
|
-
*
|
|
271
|
+
* @type {import('@kws3/ui/types').ColorOptions}
|
|
249
272
|
*/
|
|
250
273
|
export let color = "";
|
|
251
274
|
/**
|
|
@@ -326,6 +349,12 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
326
349
|
searchText = "",
|
|
327
350
|
searching = false,
|
|
328
351
|
showOptions = false,
|
|
352
|
+
mouseTracker = {
|
|
353
|
+
lastX: 0,
|
|
354
|
+
lastY: 0, // to check actual mouse is moving or not, for WebKit compatibility,
|
|
355
|
+
preventSelect: false, //prevent select by mouse when up or down key is pressed
|
|
356
|
+
},
|
|
357
|
+
fuzzysearch = null,
|
|
329
358
|
filteredOptions = [], //list of options filtered by search query
|
|
330
359
|
normalisedOptions = [], //list of options normalised
|
|
331
360
|
selectedOptions = [], //list of options that are selected
|
|
@@ -368,11 +397,15 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
368
397
|
$: activeOption, searchText, filteredOptions, updateActiveOption();
|
|
369
398
|
|
|
370
399
|
//TODO: optimise isSelected function
|
|
400
|
+
/** @type {(option: array)=> boolean}*/
|
|
371
401
|
$: isSelected = (option) => {
|
|
372
402
|
if (single) return matchesValue(value, option);
|
|
373
403
|
if (!(value && value.length > 0) || value === "") return false;
|
|
374
404
|
// nothing is selected if `value` is the empty array or string
|
|
375
|
-
else
|
|
405
|
+
else
|
|
406
|
+
return Array.isArray(value)
|
|
407
|
+
? value.some((v) => matchesValue(v, option))
|
|
408
|
+
: false;
|
|
376
409
|
};
|
|
377
410
|
|
|
378
411
|
$: singleVisibleValue =
|
|
@@ -450,11 +483,15 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
450
483
|
|
|
451
484
|
selectedOptions = _normalisedOptions
|
|
452
485
|
.filter(
|
|
453
|
-
(v) =>
|
|
486
|
+
(v) =>
|
|
487
|
+
Array.isArray(value) &&
|
|
488
|
+
value.some((vl) => `${v[used_value_key]}` === `${vl}`)
|
|
454
489
|
)
|
|
455
490
|
.sort(
|
|
456
491
|
(a, b) =>
|
|
457
|
-
value
|
|
492
|
+
// tweak for 'value is nullable' type error
|
|
493
|
+
(value ? value.indexOf(a[used_value_key]) : 0) -
|
|
494
|
+
(value ? value.indexOf(b[used_value_key]) : 0)
|
|
458
495
|
);
|
|
459
496
|
}
|
|
460
497
|
|
|
@@ -469,11 +506,13 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
469
506
|
return;
|
|
470
507
|
}
|
|
471
508
|
options_loading = true;
|
|
472
|
-
search
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
509
|
+
if (search !== null) {
|
|
510
|
+
search(filter).then((_options) => {
|
|
511
|
+
options = _options;
|
|
512
|
+
searching = false;
|
|
513
|
+
options_loading = false;
|
|
514
|
+
});
|
|
515
|
+
}
|
|
477
516
|
}
|
|
478
517
|
|
|
479
518
|
const debouncedTriggerSearch = debounce(triggerSearch, 150, false);
|
|
@@ -482,14 +521,25 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
482
521
|
POPPER = createPopper(el, dropdown, {
|
|
483
522
|
strategy: "fixed",
|
|
484
523
|
placement: "bottom-start",
|
|
524
|
+
// @ts-ignore
|
|
485
525
|
modifiers: [sameWidthPopperModifier],
|
|
486
526
|
});
|
|
487
527
|
|
|
488
|
-
if (allow_fuzzy_match
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
528
|
+
if (allow_fuzzy_match) {
|
|
529
|
+
let fuzzyOpts = {
|
|
530
|
+
analyzeSubTerms: true,
|
|
531
|
+
analyzeSubTermDepth: 10,
|
|
532
|
+
highlighting: {
|
|
533
|
+
after: "",
|
|
534
|
+
before: "",
|
|
535
|
+
},
|
|
536
|
+
};
|
|
537
|
+
let searchOptions = {
|
|
538
|
+
search_key: used_search_key,
|
|
539
|
+
scoreThreshold,
|
|
540
|
+
fuzzyOpts,
|
|
541
|
+
};
|
|
542
|
+
fuzzysearch = makeSearchEngine(searchOptions);
|
|
493
543
|
}
|
|
494
544
|
|
|
495
545
|
//normalize value for single versus multiselect
|
|
@@ -537,16 +587,20 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
537
587
|
setOptionsVisible(false);
|
|
538
588
|
}
|
|
539
589
|
|
|
540
|
-
if (
|
|
590
|
+
if (
|
|
591
|
+
!isAlreadySelected &&
|
|
592
|
+
!single &&
|
|
593
|
+
(max === null || (value && value.length < max))
|
|
594
|
+
) {
|
|
541
595
|
if (asyncMode) {
|
|
542
596
|
//Do not filter invalid options, as they are async and might not be invalid
|
|
543
597
|
//but ensure they are unique
|
|
544
|
-
value = [...value, token[used_value_key]].filter(
|
|
598
|
+
value = [...(value ? value : []), token[used_value_key]].filter(
|
|
545
599
|
(v, i, a) => a.indexOf(v) === i
|
|
546
600
|
);
|
|
547
601
|
} else {
|
|
548
602
|
//attach to value array while filtering out invalid values
|
|
549
|
-
value = [...value, token[used_value_key]].filter((v) => {
|
|
603
|
+
value = [...(value ? value : []), token[used_value_key]].filter((v) => {
|
|
550
604
|
return normalisedOptions.filter((nv) => nv[used_value_key] === v)
|
|
551
605
|
.length;
|
|
552
606
|
});
|
|
@@ -574,7 +628,7 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
574
628
|
|
|
575
629
|
function remove(token) {
|
|
576
630
|
if (readonly || disabled || single) return;
|
|
577
|
-
value = value
|
|
631
|
+
value = Array.isArray(value)
|
|
578
632
|
? value.filter((item) => !matchesValue(item, token))
|
|
579
633
|
: value;
|
|
580
634
|
|
|
@@ -639,6 +693,14 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
639
693
|
activeOption = filteredOptions[0];
|
|
640
694
|
else activeOption = filteredOptions[newActiveIdx];
|
|
641
695
|
}
|
|
696
|
+
|
|
697
|
+
tick().then(() => {
|
|
698
|
+
if (dropdown) {
|
|
699
|
+
mouseTracker.preventSelect = true;
|
|
700
|
+
let activeElem = dropdown.querySelector(".active");
|
|
701
|
+
scrollIntoActiveElement(dropdown, activeElem);
|
|
702
|
+
}
|
|
703
|
+
});
|
|
642
704
|
} else if (event.key === `Backspace`) {
|
|
643
705
|
if (single && hasValue) {
|
|
644
706
|
//for a single select
|
|
@@ -730,10 +792,7 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
730
792
|
return;
|
|
731
793
|
}
|
|
732
794
|
if (options.length) {
|
|
733
|
-
let result = fuzzysearch(filter, options
|
|
734
|
-
search_key: used_search_key,
|
|
735
|
-
scoreThreshold,
|
|
736
|
-
});
|
|
795
|
+
let result = fuzzysearch(filter, options);
|
|
737
796
|
filteredOptions = result;
|
|
738
797
|
}
|
|
739
798
|
}
|
|
@@ -12,8 +12,8 @@ Used to populate the list of options in the dropdown, Default: `[]`
|
|
|
12
12
|
this property of each object will be searched, Default: `"name"`
|
|
13
13
|
@param {string} [value_key="id"] - If `options` is an array of objects,
|
|
14
14
|
this property of each object will be returned as the value, Default: `"id"`
|
|
15
|
-
@param {''|'small'|'medium'|'large'} [size=""] - Size of the input, Default: `""`
|
|
16
|
-
@param {''|'primary'|'success'|'warning'|'info'|'danger'|'dark'|'light'} [color=""] - Color of the input, Default: `""`
|
|
15
|
+
@param {string|''|'small'|'medium'|'large'} [size=""] - Size of the input, Default: `""`
|
|
16
|
+
@param {string|''|'primary'|'success'|'warning'|'info'|'danger'|'dark'|'light'} [color=""] - Color of the input, Default: `""`
|
|
17
17
|
@param {string} [style=""] - Inline CSS for input container, Default: `""`
|
|
18
18
|
@param {boolean} [readonly=false] - Marks component as read-only, Default: `false`
|
|
19
19
|
@param {function|null} [search=null] - Async function to fetch options
|
|
@@ -88,6 +88,7 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
88
88
|
* Value of the Input
|
|
89
89
|
*
|
|
90
90
|
* This property can be bound to, to fetch the current value
|
|
91
|
+
* @type {object}
|
|
91
92
|
*/
|
|
92
93
|
export let value = null;
|
|
93
94
|
/**
|
|
@@ -112,12 +113,12 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
112
113
|
export let value_key = "id";
|
|
113
114
|
/**
|
|
114
115
|
* Size of the input
|
|
115
|
-
* @type {''
|
|
116
|
+
* @type {import('@kws3/ui/types').SizeOptions}
|
|
116
117
|
*/
|
|
117
118
|
export let size = "";
|
|
118
119
|
/**
|
|
119
120
|
* Color of the input
|
|
120
|
-
* @type {''
|
|
121
|
+
* @type {import('@kws3/ui/types').ColorOptions}
|
|
121
122
|
*/
|
|
122
123
|
export let color = "";
|
|
123
124
|
/**
|
|
@@ -140,7 +141,7 @@ Default value: `<span>{option[search_key] || option}</span>`
|
|
|
140
141
|
/**
|
|
141
142
|
* Filtered options to be displayed strictly based on search text or perform a fuzzy match.
|
|
142
143
|
* Fuzzy match will not work if `search` function is set, as the backend service is meant to do the matching.
|
|
143
|
-
* @type {'fuzzy'|'strict'}
|
|
144
|
+
* @type {string|'fuzzy'|'strict'}
|
|
144
145
|
*/
|
|
145
146
|
export let search_strategy = "fuzzy";
|
|
146
147
|
/**
|
package/helpers/CardModal.svelte
CHANGED
|
@@ -37,6 +37,7 @@ Only visible when the
|
|
|
37
37
|
<div
|
|
38
38
|
transition:scale={{
|
|
39
39
|
duration: transitionDuration,
|
|
40
|
+
// @ts-ignore
|
|
40
41
|
from: 0.8,
|
|
41
42
|
to: 1,
|
|
42
43
|
delay: transitionDelay,
|
|
@@ -116,7 +117,7 @@ Only visible when the
|
|
|
116
117
|
export let title = "",
|
|
117
118
|
/**
|
|
118
119
|
* Size of the modal
|
|
119
|
-
* @type {'
|
|
120
|
+
* @type {import('@kws3/ui/types').SizeOptions}
|
|
120
121
|
*/
|
|
121
122
|
size = "small",
|
|
122
123
|
/**
|
|
@@ -41,6 +41,9 @@ If `''` is selected, Icon will not change colour after copying, Default: `"succe
|
|
|
41
41
|
import { tick } from "svelte";
|
|
42
42
|
import { Icon } from "@kws3/ui";
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {import('@kws3/ui/types').ColorOptions} ColorOptions
|
|
46
|
+
*/
|
|
44
47
|
/**
|
|
45
48
|
* Default tooltip text
|
|
46
49
|
*/
|
|
@@ -70,7 +73,7 @@ If `''` is selected, Icon will not change colour after copying, Default: `"succe
|
|
|
70
73
|
*
|
|
71
74
|
* If `''` is selected, Icon will not change colour after copying
|
|
72
75
|
*
|
|
73
|
-
* @type {''
|
|
76
|
+
* @type {import('@kws3/ui/types').ColorOptions}
|
|
74
77
|
*/
|
|
75
78
|
copied_icon_color = "success";
|
|
76
79
|
|
|
@@ -87,12 +87,17 @@ For internal use only - not part of config object, Default: `""`
|
|
|
87
87
|
|
|
88
88
|
<script>
|
|
89
89
|
import { tick, onMount, createEventDispatcher } from "svelte";
|
|
90
|
-
import { Icon } from "@kws3/ui";
|
|
91
|
-
import {
|
|
92
|
-
import { isEnterKey, isEscKey
|
|
90
|
+
import { Icon, CardModal } from "@kws3/ui";
|
|
91
|
+
import { capitaliseFirstLetter } from "@kws3/ui/utils";
|
|
92
|
+
import { isEnterKey, isEscKey } from "../../internal";
|
|
93
93
|
|
|
94
94
|
const fire = createEventDispatcher();
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* @typedef {import('@kws3/ui/types').ColorOptions} ColorOptions
|
|
98
|
+
* @typedef {import('@kws3/ui/types').SizeOptions} SizeOptions
|
|
99
|
+
*/
|
|
100
|
+
|
|
96
101
|
/**
|
|
97
102
|
* Title text of the Dialog box
|
|
98
103
|
* @type {string}
|
|
@@ -104,7 +109,7 @@ For internal use only - not part of config object, Default: `""`
|
|
|
104
109
|
help_text = "",
|
|
105
110
|
/**
|
|
106
111
|
* Size of the Dialog box
|
|
107
|
-
* @type {
|
|
112
|
+
* @type {SizeOptions}
|
|
108
113
|
*/
|
|
109
114
|
size = "small",
|
|
110
115
|
/**
|
|
@@ -118,12 +123,12 @@ For internal use only - not part of config object, Default: `""`
|
|
|
118
123
|
icon = "",
|
|
119
124
|
/**
|
|
120
125
|
* Color of the Icon in the Dialog box
|
|
121
|
-
* @type {
|
|
126
|
+
* @type {ColorOptions}
|
|
122
127
|
*/
|
|
123
128
|
icon_color = "primary",
|
|
124
129
|
/**
|
|
125
130
|
* Size of the Icon in the Dialog box
|
|
126
|
-
* @type {
|
|
131
|
+
* @type {SizeOptions}
|
|
127
132
|
*/
|
|
128
133
|
icon_size = "",
|
|
129
134
|
/**
|
|
@@ -132,7 +137,7 @@ For internal use only - not part of config object, Default: `""`
|
|
|
132
137
|
ok_button_text = "Ok",
|
|
133
138
|
/**
|
|
134
139
|
* Color of OK button
|
|
135
|
-
* @type {
|
|
140
|
+
* @type {ColorOptions} ok_button_color
|
|
136
141
|
*/
|
|
137
142
|
ok_button_color = "primary",
|
|
138
143
|
/**
|
|
@@ -146,7 +151,7 @@ For internal use only - not part of config object, Default: `""`
|
|
|
146
151
|
cancel_button_text = "Cancel",
|
|
147
152
|
/**
|
|
148
153
|
* Color of Cancel button
|
|
149
|
-
* @type {
|
|
154
|
+
* @type {ColorOptions}
|
|
150
155
|
*/
|
|
151
156
|
cancel_button_color = "",
|
|
152
157
|
/**
|
package/helpers/Dialog/index.js
CHANGED
|
@@ -4,16 +4,19 @@ function createDialog(msg, props) {
|
|
|
4
4
|
props = Object.assign(props, { _text: msg });
|
|
5
5
|
|
|
6
6
|
const promise = new Promise((fulfil) => {
|
|
7
|
+
//@ts-ignore
|
|
7
8
|
const dialog = new Dialog({
|
|
8
9
|
target: document.body,
|
|
9
10
|
props,
|
|
10
11
|
intro: true,
|
|
11
12
|
});
|
|
12
13
|
|
|
14
|
+
//@ts-ignore
|
|
13
15
|
dialog.$on("_done", ({ detail }) => {
|
|
14
16
|
fulfil(detail);
|
|
15
17
|
//Does not outro out because of
|
|
16
18
|
//https://github.com/sveltejs/svelte/issues/4056
|
|
19
|
+
//@ts-ignore
|
|
17
20
|
dialog.$destroy();
|
|
18
21
|
});
|
|
19
22
|
});
|
|
@@ -39,8 +42,11 @@ export function confirm(msg, props) {
|
|
|
39
42
|
return createDialog(msg, props);
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
//@ts-ignore
|
|
42
46
|
Dialog.alert = alert;
|
|
47
|
+
//@ts-ignore
|
|
43
48
|
Dialog.confirm = confirm;
|
|
49
|
+
//@ts-ignore
|
|
44
50
|
Dialog.prompt = prompt;
|
|
45
51
|
|
|
46
52
|
export default Dialog;
|
package/helpers/Divider.svelte
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
<script>
|
|
26
26
|
/**
|
|
27
27
|
* Color of the Divider lines
|
|
28
|
-
* @type {''
|
|
28
|
+
* @type {import('@kws3/ui/types').ColorOptions}
|
|
29
29
|
*/
|
|
30
30
|
export let color = "",
|
|
31
31
|
/**
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
vertical = false,
|
|
39
39
|
/**
|
|
40
40
|
* Alignment of the Divider text. `top`/`left` and `bottom`/`right` are analogous for vertical Dividers
|
|
41
|
-
* @type {'center' | 'left' | 'right' | 'top' | 'bottom'}
|
|
41
|
+
* @type {string|'center' | 'left' | 'right' | 'top' | 'bottom'}
|
|
42
42
|
*/
|
|
43
43
|
alignment = "center",
|
|
44
44
|
/**
|