@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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { IS_MAC } from "../internal";
|
|
2
|
+
const ctrlKeys = {
|
|
3
|
+
ctrl: "ctrlKey",
|
|
4
|
+
meta: "metaKey",
|
|
5
|
+
shift: "shiftKey",
|
|
6
|
+
alt: "altKey",
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {string | number} definition - can be a string like 'Enter', 'Tab' or number as keyCode, also allow combination key like 'ctrl+d', 'ctrl+alt+x'
|
|
11
|
+
* @param {boolean} CommandKey - if true, in mac 'ctrl' key binding will be shift on 'command' key.
|
|
12
|
+
* @returns {function} .
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function makeKeyDefinition(definition, CommandKey = false) {
|
|
16
|
+
let def = definition;
|
|
17
|
+
let keys = [];
|
|
18
|
+
|
|
19
|
+
if (typeof def === "number") {
|
|
20
|
+
keys = [def];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof def === "string") {
|
|
24
|
+
if (CommandKey) {
|
|
25
|
+
if (IS_MAC) {
|
|
26
|
+
def = def.replace("ctrl", "meta");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
keys = def.split("+");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return function (node, fire) {
|
|
33
|
+
function keydownHandler(event) {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
let firedCount = 0;
|
|
36
|
+
let which = event.which || event.keyCode;
|
|
37
|
+
keys.forEach((key) => {
|
|
38
|
+
if (event[ctrlKeys[key]]) {
|
|
39
|
+
firedCount++;
|
|
40
|
+
}
|
|
41
|
+
if (
|
|
42
|
+
key === event.key ||
|
|
43
|
+
("key" + key).toLowerCase() === event.code.toLowerCase()
|
|
44
|
+
) {
|
|
45
|
+
firedCount++;
|
|
46
|
+
}
|
|
47
|
+
if (key === which) {
|
|
48
|
+
firedCount++;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
let valid = false;
|
|
53
|
+
if (keys.length === firedCount) {
|
|
54
|
+
valid = true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (valid) {
|
|
58
|
+
fire(event);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
node.addEventListener("keydown", keydownHandler, false);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
destroy() {
|
|
66
|
+
node.removeEventListener("keydown", keydownHandler, false);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export let enter = makeKeyDefinition("Enter");
|
|
73
|
+
export let tab = makeKeyDefinition("Tab");
|
|
74
|
+
export let escape = makeKeyDefinition("Escape");
|
|
75
|
+
export let space = makeKeyDefinition(" ");
|
|
76
|
+
export let leftarrow = makeKeyDefinition("ArrowLeft");
|
|
77
|
+
export let rightarrow = makeKeyDefinition("ArrowRight");
|
|
78
|
+
export let downarrow = makeKeyDefinition("ArrowDown");
|
|
79
|
+
export let uparrow = makeKeyDefinition("ArrowUp");
|
|
80
|
+
export let backspace = makeKeyDefinition("Backspace");
|
|
81
|
+
export let del = makeKeyDefinition("Delete");
|
|
82
|
+
|
|
83
|
+
export default {
|
|
84
|
+
enter,
|
|
85
|
+
tab,
|
|
86
|
+
escape,
|
|
87
|
+
space,
|
|
88
|
+
leftarrow,
|
|
89
|
+
rightarrow,
|
|
90
|
+
downarrow,
|
|
91
|
+
uparrow,
|
|
92
|
+
backspace,
|
|
93
|
+
del,
|
|
94
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kws3/ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "UI components for use with Svelte v3 applications.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"svelte": "index.js",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
9
|
},
|
|
@@ -17,11 +18,13 @@
|
|
|
17
18
|
"contributors": [
|
|
18
19
|
"Sharif Ahmed <me.sharifahmed@gmail.com>",
|
|
19
20
|
"Sabir <sabirveli@gmail.com>",
|
|
20
|
-
"Suneesh S K <suneeshsk3@gmail.com>"
|
|
21
|
+
"Suneesh S K <suneeshsk3@gmail.com>",
|
|
22
|
+
"Nikeeta <nikeetaa231@gmail.com>"
|
|
21
23
|
],
|
|
22
24
|
"publishConfig": {
|
|
23
25
|
"access": "public"
|
|
24
26
|
},
|
|
27
|
+
"types": "types/index.d.ts",
|
|
25
28
|
"dependencies": {
|
|
26
29
|
"apexcharts": "3.33.2",
|
|
27
30
|
"flatpickr": "^4.5.2",
|
|
@@ -29,5 +32,5 @@
|
|
|
29
32
|
"text-mask-core": "^5.1.2",
|
|
30
33
|
"tippy.js": "^6.3.1"
|
|
31
34
|
},
|
|
32
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "d724cb9ab00f7eba724b874aabfef4cf03ef8e35"
|
|
33
36
|
}
|
|
File without changes
|
package/search/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { fuzzy } from "../internal";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('@kws3/ui/types').SearchOptions} SearchOptions - contains search options and fuzzy lib options
|
|
5
|
+
* @typedef {import('@kws3/ui/types').SearchHelper} SearchHelper - returned search helper function which take unction take params `needle` and `haystack`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {SearchOptions} opts
|
|
10
|
+
*/
|
|
11
|
+
export function makeSearchEngine(opts) {
|
|
12
|
+
let search_key = opts.search_key ? opts.search_key : "value";
|
|
13
|
+
let scoreThreshold = opts.scoreThreshold ? opts.scoreThreshold : 5;
|
|
14
|
+
let fuzzyOpts = opts.fuzzyOpts ? opts.fuzzyOpts : {};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} needle
|
|
18
|
+
* @param {array} haystack
|
|
19
|
+
* @returns {array}
|
|
20
|
+
*/
|
|
21
|
+
return function (needle, haystack) {
|
|
22
|
+
let OPTS = haystack.map((option) => {
|
|
23
|
+
let item = { ...option };
|
|
24
|
+
item.original = { ...option };
|
|
25
|
+
if (typeof item === "object") {
|
|
26
|
+
if (!Array.isArray(search_key)) {
|
|
27
|
+
search_key = [search_key];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
search_key.forEach((s_key) => {
|
|
31
|
+
if (`${s_key}` in item) {
|
|
32
|
+
let output = fuzzy(option[s_key], needle, fuzzyOpts);
|
|
33
|
+
item.original[s_key] = output.highlightedTerm;
|
|
34
|
+
item.score =
|
|
35
|
+
!item.score || (item.score && item.score < output.score)
|
|
36
|
+
? output.score
|
|
37
|
+
: item.score || 0;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return item;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
let maxScore = Math.max(...OPTS.map((i) => i.score));
|
|
45
|
+
let calculatedLimit = maxScore - scoreThreshold;
|
|
46
|
+
|
|
47
|
+
OPTS = OPTS.filter(
|
|
48
|
+
(r) => r.score > (calculatedLimit > 0 ? calculatedLimit : 0)
|
|
49
|
+
);
|
|
50
|
+
return OPTS.map((i) => i.original);
|
|
51
|
+
};
|
|
52
|
+
}
|
package/settings.js
CHANGED
|
@@ -40,7 +40,7 @@ export {
|
|
|
40
40
|
* - `hasTransitions`: `true` - Transitions are applied
|
|
41
41
|
* - `defaultChartColors`: `["#284BED", "#ED6134", "#1DAFEC", "#EDB405", "#11EDB7", "#77ED11"]` - default colors for charts
|
|
42
42
|
*
|
|
43
|
-
* @param {*}
|
|
43
|
+
* @param {*} obj containing all settings
|
|
44
44
|
*/
|
|
45
45
|
export function applySettings(obj) {
|
|
46
46
|
Object.entries(obj).forEach(([k, v]) => {
|
|
@@ -54,10 +54,7 @@ This will work only when `track_height` is set to `true`
|
|
|
54
54
|
<script>
|
|
55
55
|
import { onMount, createEventDispatcher } from "svelte";
|
|
56
56
|
import { debounce } from "@kws3/ui/utils";
|
|
57
|
-
import {
|
|
58
|
-
resizeObserver,
|
|
59
|
-
hasResizeObserver,
|
|
60
|
-
} from "@kws3/ui/utils/resizeObserver";
|
|
57
|
+
import { resizeObserver, hasResizeObserver } from "@kws3/ui/resizeObserver";
|
|
61
58
|
|
|
62
59
|
const fire = createEventDispatcher();
|
|
63
60
|
|
package/styles/AutoComplete.scss
CHANGED
|
@@ -14,6 +14,7 @@ $kws-autocomplete-selecting-background: $primary !default;
|
|
|
14
14
|
$kws-autocomplete-text-matches-color: currentColor !default;
|
|
15
15
|
$kws-autocomplete-text-matches-background: transparent !default;
|
|
16
16
|
$kws-autocomplete-text-matches-font-weight: $weight-bold !default;
|
|
17
|
+
$kws-autocomplete-options-background: $scheme-main-ter !default;
|
|
17
18
|
|
|
18
19
|
$__modal-z: 41 !default;
|
|
19
20
|
@if $modal-z {
|
|
@@ -65,7 +66,7 @@ $kws-autocomplete-options-z-index: $__modal-z + 1 !default;
|
|
|
65
66
|
padding: 0;
|
|
66
67
|
cursor: pointer;
|
|
67
68
|
overflow: auto;
|
|
68
|
-
background:
|
|
69
|
+
background: $kws-autocomplete-options-background;
|
|
69
70
|
border: 1px solid $kws-autocomplete-border-color;
|
|
70
71
|
box-shadow: $kws-autocomplete-box-shadow;
|
|
71
72
|
position: relative;
|
package/styles/Datepicker.scss
CHANGED
package/styles/Grid.scss
CHANGED
|
@@ -13,6 +13,9 @@ $kws-gridview-checked-row-background: $primary-light !default;
|
|
|
13
13
|
color: $kws-gridview-th-color;
|
|
14
14
|
vertical-align: middle;
|
|
15
15
|
}
|
|
16
|
+
td {
|
|
17
|
+
vertical-align: middle;
|
|
18
|
+
}
|
|
16
19
|
&.is-bordered {
|
|
17
20
|
tr {
|
|
18
21
|
th:last-child,
|
|
@@ -54,4 +57,15 @@ $kws-gridview-checked-row-background: $primary-light !default;
|
|
|
54
57
|
color: findColorInvert($kws-gridview-checked-row-background) !important;
|
|
55
58
|
}
|
|
56
59
|
}
|
|
60
|
+
|
|
61
|
+
&.is-narrow {
|
|
62
|
+
th {
|
|
63
|
+
font-size: 0.9rem;
|
|
64
|
+
line-height: 1.2;
|
|
65
|
+
}
|
|
66
|
+
td,
|
|
67
|
+
th {
|
|
68
|
+
padding: 0.25rem 0.4rem;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
57
71
|
}
|
package/styles/Pagination.scss
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
$kws-pagination-item-color: $text !default;
|
|
2
|
-
$kws-pagination-item-background:
|
|
2
|
+
$kws-pagination-item-background: $scheme-main !default;
|
|
3
3
|
$kws-pagination-item-border: 1px solid $border !default;
|
|
4
4
|
$kws-pagination-item-hover-color: $kws-pagination-item-color !default;
|
|
5
5
|
$kws-pagination-item-hover-border: $kws-pagination-item-border !default;
|
|
6
|
-
$kws-pagination-item-disabled-background: $
|
|
6
|
+
$kws-pagination-item-disabled-background: $scheme-main-ter !default;
|
|
7
7
|
$kws-pagination-item-disabled-color: $grey !default;
|
|
8
|
-
$kws-pagination-item-ellipsis-background: $
|
|
9
|
-
$kws-pagination-item-ellipsis-border-color: $
|
|
8
|
+
$kws-pagination-item-ellipsis-background: $scheme-main-ter !default;
|
|
9
|
+
$kws-pagination-item-ellipsis-border-color: $scheme-main-ter !default;
|
|
10
10
|
$kws-pagination-item-active-background: $success !default;
|
|
11
11
|
$kws-pagination-item-active-color: findColorInvert(
|
|
12
12
|
$kws-pagination-item-active-background
|
|
@@ -14,7 +14,10 @@ $kws-pagination-item-active-color: findColorInvert(
|
|
|
14
14
|
|
|
15
15
|
$kws-pagination-frame-box-shadow: 0 0.125rem 0.1875rem rgba(0, 0, 0, 0.1),
|
|
16
16
|
0 0 0 0.0625rem rgba(0, 0, 0, 0.1) !default;
|
|
17
|
-
$kws-pagination-frame-background: linear-gradient(
|
|
17
|
+
$kws-pagination-frame-background: linear-gradient(
|
|
18
|
+
$scheme-main,
|
|
19
|
+
$scheme-main-ter
|
|
20
|
+
) !default;
|
|
18
21
|
|
|
19
22
|
.pagination {
|
|
20
23
|
&.is-small {
|
package/styles/Select.scss
CHANGED
|
@@ -10,6 +10,7 @@ $kws-select-selecting-color: $primary-invert !default;
|
|
|
10
10
|
$kws-select-selecting-background: $primary !default;
|
|
11
11
|
$kws-select-selected-color: $primary-dark !default;
|
|
12
12
|
$kws-select-selected-background: $primary-light !default;
|
|
13
|
+
$kws-select-options-background: $scheme-main-ter !default;
|
|
13
14
|
|
|
14
15
|
$__modal-z: 41 !default;
|
|
15
16
|
@if $modal-z {
|
|
@@ -96,7 +97,7 @@ $kws-select-options-z-index: $__modal-z + 1 !default;
|
|
|
96
97
|
cursor: pointer;
|
|
97
98
|
border-radius: 0 0 $kws-select-radius $kws-select-radius;
|
|
98
99
|
overflow: auto;
|
|
99
|
-
background:
|
|
100
|
+
background: $kws-select-options-background;
|
|
100
101
|
box-shadow: 0 3px 9px rgba(0, 0, 0, 0.4);
|
|
101
102
|
position: relative;
|
|
102
103
|
z-index: 4;
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
sineOut,
|
|
3
|
+
elasticOut,
|
|
4
|
+
expoOut,
|
|
5
|
+
cubicOut,
|
|
6
|
+
circOut,
|
|
7
|
+
bounceOut,
|
|
8
|
+
backOut,
|
|
9
|
+
} from "svelte/easing";
|
|
2
10
|
|
|
3
11
|
export default function getEasing(easing) {
|
|
4
12
|
let eases = {
|
|
5
|
-
sineOut,
|
|
6
|
-
|
|
13
|
+
sineOut,
|
|
14
|
+
elasticOut,
|
|
15
|
+
expoOut,
|
|
16
|
+
cubicOut,
|
|
17
|
+
circOut,
|
|
18
|
+
bounceOut,
|
|
19
|
+
backOut,
|
|
7
20
|
};
|
|
8
|
-
return easing ?
|
|
9
|
-
}
|
|
21
|
+
return easing ? eases[easing] || sineOut : sineOut;
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare namespace svelte.JSX {
|
|
2
|
+
interface HTMLAttributes<T> {
|
|
3
|
+
onshowing?: (event: any) => any;
|
|
4
|
+
onshown?: (event: any) => any;
|
|
5
|
+
onhiding?: (event: any) => any;
|
|
6
|
+
onhidden?: (event: any) => any;
|
|
7
|
+
ontriggered?: (event: any) => any;
|
|
8
|
+
onclose?: (event: any) => any;
|
|
9
|
+
ontimeChange?: (event: any) => any;
|
|
10
|
+
onready?: (event: any) => any;
|
|
11
|
+
onopen?: (event: any) => any;
|
|
12
|
+
ondateChange?: (event: any) => any;
|
|
13
|
+
onmonthChange?: (event: any) => any;
|
|
14
|
+
onyearChange?: (event: any) => any;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Colors, BGColors, SpinnerColors, Sizes } from "./type-defs.ts";
|
|
2
|
+
export type SearchOptions = {
|
|
3
|
+
search_key: Array<string> | string;
|
|
4
|
+
scoreThreshold: number;
|
|
5
|
+
fuzzyOpts: {
|
|
6
|
+
analyzeSubTerms: boolean;
|
|
7
|
+
analyzeSubTermDepth: number;
|
|
8
|
+
highlighting: {
|
|
9
|
+
after: string;
|
|
10
|
+
before: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type SearchHelper = (needle: string, haystack: array) => array;
|
|
16
|
+
|
|
17
|
+
export type ValidatePasswordOptions = {
|
|
18
|
+
name: string;
|
|
19
|
+
text: string;
|
|
20
|
+
identifier: string;
|
|
21
|
+
regex: RegExp;
|
|
22
|
+
passed: boolean;
|
|
23
|
+
active: boolean;
|
|
24
|
+
value?: string;
|
|
25
|
+
negate?: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
declare global {
|
|
29
|
+
interface Navigator {
|
|
30
|
+
readonly userAgentData: {
|
|
31
|
+
platform: string;
|
|
32
|
+
};
|
|
33
|
+
readonly platform: string;
|
|
34
|
+
}
|
|
35
|
+
interface Window {
|
|
36
|
+
ApexCharts: Object;
|
|
37
|
+
readonly navigator: Navigator;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type Options<T> = T;
|
|
42
|
+
|
|
43
|
+
export type ColorOptions = Options<Colors>;
|
|
44
|
+
export type SizeOptions = Options<Sizes>;
|
|
45
|
+
export type SpinnerColorOptions = Options<Colors | SpinnerColors>;
|
|
46
|
+
export type BGColorOptions = Options<Colors | BGColors>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Colors =
|
|
2
|
+
| ""
|
|
3
|
+
| "primary"
|
|
4
|
+
| "success"
|
|
5
|
+
| "warning"
|
|
6
|
+
| "info"
|
|
7
|
+
| "danger"
|
|
8
|
+
| "dark"
|
|
9
|
+
| "light";
|
|
10
|
+
|
|
11
|
+
export type BGColors = "" | "transparent" | "link";
|
|
12
|
+
export type SpinnerColors = "" | "grey";
|
|
13
|
+
|
|
14
|
+
export type Sizes = "" | "small" | "medium" | "large";
|
package/utils/index.js
CHANGED
|
@@ -1,32 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Truncate a string.
|
|
3
|
+
* @param {string} [str=""] - String to truncate, Default: `""`
|
|
4
|
+
* @param {number} [len=0] - The number of characters to extract, Default: `""`
|
|
5
|
+
*/
|
|
6
|
+
export function truncate(str = "", len = 0) {
|
|
2
7
|
return str && str.length >= len + 3 ? str.substr(0, len) + "..." : str;
|
|
3
8
|
}
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Insert line breaks where newlines (\n) occur in the string.
|
|
12
|
+
* @param {string} [input=""] - String to be checked, Default: `""`
|
|
13
|
+
*/
|
|
14
|
+
export function nl2br(input = "") {
|
|
6
15
|
if (!input) {
|
|
7
16
|
return "";
|
|
8
17
|
}
|
|
9
|
-
|
|
18
|
+
let html = (input + ``).replace(/\n/g, "<br/>");
|
|
19
|
+
return html;
|
|
10
20
|
}
|
|
11
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Clone an Object.
|
|
24
|
+
* @param {object} [obj={}] - Object to be cloned, Default: `{}`
|
|
25
|
+
*/
|
|
12
26
|
export function cloneObject(obj) {
|
|
13
27
|
return JSON.parse(JSON.stringify(obj));
|
|
14
28
|
}
|
|
15
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Request an animation before the next repaint.
|
|
32
|
+
* @param {function} [callback=function(){}] - callback function
|
|
33
|
+
*/
|
|
16
34
|
export var rAF =
|
|
17
35
|
window.requestAnimationFrame ||
|
|
36
|
+
//@ts-ignore
|
|
18
37
|
window.webkitRequestAnimationFrame ||
|
|
38
|
+
//@ts-ignore
|
|
19
39
|
window.mozRequestAnimationFrame ||
|
|
40
|
+
//@ts-ignore
|
|
20
41
|
window.oRequestAnimationFrame ||
|
|
42
|
+
//@ts-ignore
|
|
21
43
|
window.msRequestAnimationFrame ||
|
|
22
44
|
function (callback) {
|
|
23
45
|
window.setTimeout(callback, 1000 / 60);
|
|
24
46
|
};
|
|
25
47
|
|
|
26
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Returns a function, that, as long as it continues to be invoked, will not
|
|
50
|
+
* be triggered. The function will be called after it stops being called for
|
|
51
|
+
* `threshold` milliseconds.
|
|
52
|
+
* @param {function} [fn=function(){}] - The function that you want to execute after the debounce time
|
|
53
|
+
* @param {number} [threshold=100] - The amount of time to wait, Default: `100`
|
|
54
|
+
* @param {boolean} [isAsap=false] - flag to debounce early, Default: `false`
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
export function debounce(fn = function () {}, threshold, isAsap) {
|
|
27
58
|
var timeout, result;
|
|
28
59
|
function debounced() {
|
|
29
60
|
var args = arguments,
|
|
61
|
+
//@ts-ignore
|
|
30
62
|
context = this;
|
|
31
63
|
function delayed() {
|
|
32
64
|
if (!isAsap) {
|
|
@@ -48,14 +80,83 @@ export function debounce(fn, threshold, isAsap) {
|
|
|
48
80
|
return debounced;
|
|
49
81
|
}
|
|
50
82
|
|
|
51
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Capitalise First letter of string.
|
|
85
|
+
* @param {string} [string=""] - A string whose first letter is to be capitalised, Default: `""`
|
|
86
|
+
*/
|
|
87
|
+
export function capitaliseFirstLetter(string = "") {
|
|
52
88
|
return string.charAt(0).toUpperCase() + string.toLowerCase().slice(1);
|
|
53
89
|
}
|
|
54
90
|
|
|
55
|
-
|
|
56
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Returns Date Object.
|
|
93
|
+
* Makes mysql dates work in safari
|
|
94
|
+
* @param {string} [strDate=""] - Date String., Default: `""`
|
|
95
|
+
*/
|
|
96
|
+
export function createDate(strDate) {
|
|
97
|
+
// eslint-disable-next-line @kws3/svelte3/no-date-string-arg
|
|
98
|
+
return strDate ? new Date(strDate.replace(/-/g, "/")) : null;
|
|
57
99
|
}
|
|
58
100
|
|
|
59
|
-
|
|
60
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Returns currency format.
|
|
103
|
+
* @param {number} [n=''] - Number., Default: `""`
|
|
104
|
+
*/
|
|
105
|
+
export function currency(n) {
|
|
106
|
+
var nn = Number(n);
|
|
107
|
+
return (isNaN(nn) ? 0 : nn).toFixed(2);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Converts date to ordinal.
|
|
112
|
+
* @param {number} [n=''] - Number., Default: `""`
|
|
113
|
+
*/
|
|
114
|
+
export function dateToOrdinal(n) {
|
|
115
|
+
n = Number(n);
|
|
116
|
+
return (
|
|
117
|
+
n +
|
|
118
|
+
(n > 0
|
|
119
|
+
? ["th", "st", "nd", "rd"][(n > 3 && n < 21) || n % 10 > 3 ? 0 : n % 10]
|
|
120
|
+
: "")
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Returns a random integer between min (inclusive) and max (inclusive).
|
|
126
|
+
* The value is no lower than min (or the next integer greater than min
|
|
127
|
+
* if min isn't an integer) and no greater than max (or the next integer
|
|
128
|
+
* lower than max if max isn't an integer).
|
|
129
|
+
* @param {number} [min] - Minimum Number.
|
|
130
|
+
* @param {number} [max] - Maximum Number.
|
|
131
|
+
*/
|
|
132
|
+
export function randomIntegerFromInterval(min = 0, max = Infinity) {
|
|
133
|
+
min = Math.ceil(min);
|
|
134
|
+
max = Math.floor(max);
|
|
135
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns random percentage.
|
|
140
|
+
* @param {number} [min=1] - Minimum Number, Default: `1`
|
|
141
|
+
* @param {number} [max=100] - Maximum Number, Default: `100`
|
|
142
|
+
*/
|
|
143
|
+
export function randomPercent(min = 1, max = 100) {
|
|
144
|
+
return randomIntegerFromInterval(min, max) + "%";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Downloads file.
|
|
149
|
+
* @param {Object} [data={}] - File data.
|
|
150
|
+
* @param {string} [fileName=''] - File Name.
|
|
151
|
+
*/
|
|
152
|
+
export function fileDownloader(data, fileName = "file_name") {
|
|
153
|
+
let a = document.createElement("a");
|
|
154
|
+
document.body.appendChild(a);
|
|
155
|
+
a.setAttribute("style", "display: none");
|
|
156
|
+
let blob = new Blob([data], { type: "octet/stream" }),
|
|
157
|
+
url = window.URL.createObjectURL(blob);
|
|
158
|
+
a.href = url;
|
|
159
|
+
a.download = fileName;
|
|
160
|
+
a.click();
|
|
161
|
+
window.URL.revokeObjectURL(url);
|
|
61
162
|
}
|
package/utils/fuzzysearch.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import fuzzy from "./fuzzy.js";
|
|
2
|
-
|
|
3
|
-
export function fuzzysearch(needle, haystack, opts) {
|
|
4
|
-
let search_key = defaultValue(opts, "search_key", "value");
|
|
5
|
-
let scoreThreshold = defaultValue(opts, "scoreThreshold", 5);
|
|
6
|
-
|
|
7
|
-
let OPTS = haystack.map((option) => {
|
|
8
|
-
let item = { ...option };
|
|
9
|
-
item.original = { ...option };
|
|
10
|
-
if (typeof item === "object") {
|
|
11
|
-
if (!Array.isArray(search_key)) {
|
|
12
|
-
search_key = [search_key];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
search_key.forEach((s_key) => {
|
|
16
|
-
if (`${s_key}` in item) {
|
|
17
|
-
let output = fuzzy(option[s_key], needle);
|
|
18
|
-
item.original[s_key] = output.highlightedTerm;
|
|
19
|
-
item.score =
|
|
20
|
-
!item.score || (item.score && item.score < output.score)
|
|
21
|
-
? output.score
|
|
22
|
-
: item.score || 0;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return item;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
let maxScore = Math.max(...OPTS.map((i) => i.score));
|
|
30
|
-
let calculatedLimit = maxScore - scoreThreshold;
|
|
31
|
-
|
|
32
|
-
OPTS = OPTS.filter(
|
|
33
|
-
(r) => r.score > (calculatedLimit > 0 ? calculatedLimit : 0)
|
|
34
|
-
);
|
|
35
|
-
return OPTS.map((i) => i.original);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function defaultValue(opts, key, value) {
|
|
39
|
-
return opts && opts[key] ? opts[key] : value;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { fuzzy };
|
package/utils/keyboard-events.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
let events = [
|
|
2
|
-
{name: 'enter', code: 13},
|
|
3
|
-
{name: 'tab', code: 9},
|
|
4
|
-
{name: 'escape', code: 27},
|
|
5
|
-
{name: 'space', code: 32},
|
|
6
|
-
{name: 'leftarrow', code: 37},
|
|
7
|
-
{name: 'rightarrow', code: 39},
|
|
8
|
-
{name: 'downarrow', code: 40},
|
|
9
|
-
{name: 'uparrow', code: 38},
|
|
10
|
-
{name: 'backspace', code: 8},
|
|
11
|
-
{name: 'del', code: 46},
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
export function keyboardEvents(node) {
|
|
15
|
-
function keydownHandler(event) {
|
|
16
|
-
events.forEach(({name, code}) => {
|
|
17
|
-
let which = event.which || event.keyCode;
|
|
18
|
-
if (which === code) {
|
|
19
|
-
node.dispatchEvent(
|
|
20
|
-
new CustomEvent(name)
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
node.addEventListener('keydown', keydownHandler, false);
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
destroy() {
|
|
29
|
-
node.removeEventListener('keydown', keydownHandler, false);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|