@witchcraft/ui 0.0.1 → 0.1.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/README.md +18 -28
- package/dist/module.d.mts +3 -1
- package/dist/module.json +3 -3
- package/dist/module.mjs +21 -12
- package/dist/runtime/assets/base.css +1 -1
- package/dist/runtime/assets/locales/en.json +2 -2
- package/dist/runtime/assets/tailwind.css +1 -1
- package/dist/runtime/assets/utils.css +1 -0
- package/dist/runtime/build/WitchcraftUiResolver.js +1 -1
- package/dist/runtime/components/Aria/Aria.vue +5 -9
- package/dist/runtime/components/Aria/Aria.vue.d.ts +5 -0
- package/dist/runtime/components/Icon/Icon.vue +12 -28
- package/dist/runtime/components/Icon/Icon.vue.d.ts +21 -0
- package/dist/runtime/components/LibButton/LibButton.vue +93 -117
- package/dist/runtime/components/LibButton/LibButton.vue.d.ts +36 -0
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +53 -76
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +42 -0
- package/dist/runtime/components/LibColorInput/LibColorInput.vue +131 -101
- package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +63 -0
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +326 -296
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +61 -0
- package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.d.ts +2 -0
- package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.js +18 -0
- package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.d.ts +2 -0
- package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.js +17 -0
- package/dist/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.d.ts +2 -0
- package/dist/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.js +8 -0
- package/dist/runtime/components/LibColorPicker/utils/truncate.d.ts +1 -0
- package/dist/runtime/components/LibColorPicker/utils/truncate.js +5 -0
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +42 -64
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +22 -0
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue +20 -54
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +40 -0
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +205 -173
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +34 -0
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +215 -164
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +34 -0
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +9 -10
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +22 -0
- package/dist/runtime/components/LibDebug/LibDebug.vue +47 -65
- package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +32 -0
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +19 -34
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +22 -0
- package/dist/runtime/components/LibFileInput/LibFileInput.vue +155 -173
- package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +43 -0
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +352 -0
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue.d.ts +165 -0
- package/dist/runtime/components/LibLabel/LibLabel.vue +30 -46
- package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +27 -0
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +50 -66
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +29 -0
- package/dist/runtime/components/LibNotifications/LibNotification.vue +48 -56
- package/dist/runtime/components/LibNotifications/LibNotification.vue.d.ts +17 -0
- package/dist/runtime/components/LibNotifications/LibNotifications.vue +71 -83
- package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +13 -0
- package/dist/runtime/components/LibPagination/LibPagination.vue +86 -131
- package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +104 -0
- package/dist/runtime/components/LibPalette/LibPalette.vue +23 -26
- package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +14 -0
- package/dist/runtime/components/LibPopup/LibPopup.vue +326 -400
- package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +46 -0
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +73 -93
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +41 -0
- package/dist/runtime/components/LibRecorder/LibRecorder.vue +134 -179
- package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +77 -0
- package/dist/runtime/components/LibRoot/LibRoot.vue +75 -89
- package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +41 -0
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +51 -82
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +35 -0
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +147 -164
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +94 -0
- package/dist/runtime/components/LibTable/LibTable.vue +69 -106
- package/dist/runtime/components/LibTable/LibTable.vue.d.ts +45 -0
- package/dist/runtime/components/Template/NAME.vue +15 -36
- package/dist/runtime/components/Template/NAME.vue.d.ts +17 -0
- package/dist/runtime/components/TestControls/TestControls.vue +7 -10
- package/dist/runtime/components/TestControls/TestControls.vue.d.ts +5 -0
- package/dist/runtime/components/index.d.ts +12 -11
- package/dist/runtime/components/index.js +12 -11
- package/dist/runtime/components/shared/props.d.ts +81 -16
- package/dist/runtime/components/shared/storyHelpers/playInput.js +5 -5
- package/dist/runtime/components/shared/storyHelpers/playSuggestions.js +15 -11
- package/dist/runtime/composables/index.d.ts +5 -0
- package/dist/runtime/composables/index.js +5 -0
- package/dist/runtime/composables/useDivideAttrs.js +1 -0
- package/dist/runtime/composables/useDragWithThreshold.d.ts +71 -0
- package/dist/runtime/composables/useDragWithThreshold.js +40 -0
- package/dist/runtime/composables/usePreHydrationValue.d.ts +12 -0
- package/dist/runtime/composables/usePreHydrationValue.js +15 -0
- package/dist/runtime/composables/useSetupI18n.d.ts +2 -0
- package/dist/runtime/composables/useSetupI18n.js +5 -1
- package/dist/runtime/composables/useSuggestions.d.ts +7 -5
- package/dist/runtime/composables/useSuggestions.js +94 -57
- package/dist/runtime/directives/vResizableCols.js +92 -84
- package/dist/runtime/helpers/NotificationHandler.d.ts +5 -0
- package/dist/runtime/helpers/index.d.ts +3 -1
- package/dist/runtime/helpers/index.js +3 -1
- package/dist/runtime/types/index.d.ts +6 -0
- package/dist/runtime/utils/notifyIfError.d.ts +14 -0
- package/dist/runtime/utils/notifyIfError.js +29 -0
- package/dist/types.d.mts +2 -6
- package/package.json +27 -29
- package/src/module.ts +31 -12
- package/src/runtime/assets/base.css +10 -1
- package/src/runtime/assets/locales/en.json +2 -2
- package/src/runtime/assets/tailwind.css +1 -1
- package/src/runtime/assets/{style.css → utils.css} +86 -4
- package/src/runtime/build/WitchcraftUiResolver.ts +1 -1
- package/src/runtime/components/Focus.stories.ts +3 -2
- package/src/runtime/components/Icon/Icon.vue +10 -6
- package/src/runtime/components/LibButton/LibButton.vue +41 -47
- package/src/runtime/components/LibCheckbox/LibCheckbox.vue +7 -4
- package/src/runtime/components/LibColorInput/LibColorInput.vue +111 -37
- package/src/runtime/components/LibColorPicker/LibColorPicker.stories.ts +25 -4
- package/src/runtime/components/LibColorPicker/LibColorPicker.vue +242 -131
- package/src/runtime/components/LibColorPicker/utils/safeConvertToHsva.ts +24 -0
- package/src/runtime/components/LibColorPicker/utils/safeConvertToRgba.ts +23 -0
- package/src/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.ts +13 -0
- package/src/runtime/components/LibColorPicker/utils/truncate.ts +6 -0
- package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.ts +1 -1
- package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +11 -9
- package/src/runtime/components/LibDatePicker/LibDatePicker.vue +4 -17
- package/src/runtime/components/LibDatePicker/LibRangeDatePicker.vue +192 -131
- package/src/runtime/components/LibDatePicker/LibSingleDatePicker.vue +183 -115
- package/src/runtime/components/LibDatePicker/LibTimeZonePicker.vue +3 -3
- package/src/runtime/components/LibDebug/LibDebug.vue +15 -5
- package/src/runtime/components/LibDevOnly/LibDevOnly.vue +1 -3
- package/src/runtime/components/LibFileInput/LibFileInput.vue +54 -29
- package/src/runtime/components/{LibInput/LibInput.stories.ts → LibInputDeprecated/LibInputDeprecated.stories.ts} +64 -19
- package/{dist/runtime/components/LibInput/LibInput.vue → src/runtime/components/LibInputDeprecated/LibInputDeprecated.vue} +40 -34
- package/src/runtime/components/LibLabel/LibLabel.vue +2 -2
- package/src/runtime/components/LibMultiValues/LibMultiValues.stories.ts +5 -4
- package/src/runtime/components/LibMultiValues/LibMultiValues.vue +11 -13
- package/src/runtime/components/LibNotifications/LibNotification.vue +19 -11
- package/src/runtime/components/LibNotifications/LibNotifications.stories.ts +2 -2
- package/src/runtime/components/LibNotifications/LibNotifications.vue +20 -12
- package/src/runtime/components/LibPagination/LibPagination.stories.ts +2 -2
- package/src/runtime/components/LibPagination/LibPagination.vue +19 -20
- package/src/runtime/components/LibPalette/LibPalette.vue +3 -3
- package/src/runtime/components/LibPopup/LibPopup.stories.ts +2 -2
- package/src/runtime/components/LibPopup/LibPopup.vue +30 -67
- package/src/runtime/components/LibProgressBar/LibProgressBar.vue +3 -2
- package/src/runtime/components/LibRecorder/LibRecorder.vue +2 -3
- package/src/runtime/components/LibRoot/LibRoot.vue +14 -1
- package/src/runtime/components/LibSimpleInput/LibSimpleInput.stories.ts +1 -1
- package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +5 -8
- package/src/runtime/components/LibSuggestions/LibSuggestions.vue +42 -26
- package/src/runtime/components/LibTable/LibTable.vue +8 -9
- package/src/runtime/components/Scrolling.stories.ts +58 -0
- package/src/runtime/components/Template/NAME.vue +1 -1
- package/src/runtime/components/TestControls/TestControls.vue +1 -1
- package/src/runtime/components/index.ts +12 -12
- package/src/runtime/components/shared/props.ts +82 -19
- package/src/runtime/components/shared/storyHelpers/playInput.ts +6 -5
- package/src/runtime/components/shared/storyHelpers/playSuggestions.ts +25 -11
- package/src/runtime/composables/index.ts +5 -0
- package/src/runtime/composables/useDarkMode.ts +2 -2
- package/src/runtime/composables/useDivideAttrs.ts +1 -0
- package/src/runtime/composables/useDragWithThreshold.ts +108 -0
- package/src/runtime/composables/usePreHydrationValue.ts +30 -0
- package/src/runtime/composables/useSetupI18n.ts +8 -2
- package/src/runtime/composables/useSuggestions.ts +92 -45
- package/src/runtime/directives/vResizableCols.ts +82 -74
- package/src/runtime/helpers/NotificationHandler.ts +5 -0
- package/src/runtime/helpers/index.ts +3 -1
- package/src/runtime/types/index.ts +5 -0
- package/src/runtime/utils/notifyIfError.ts +45 -0
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -34
- package/dist/runtime/assets/style.css +0 -1
- package/dist/runtime/components/Focus.stories.d.ts +0 -11
- package/dist/runtime/components/Focus.stories.js +0 -53
- package/dist/runtime/components/LibButton/LibButton.stories.d.ts +0 -12
- package/dist/runtime/components/LibButton/LibButton.stories.js +0 -94
- package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.d.ts +0 -14
- package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.js +0 -29
- package/dist/runtime/components/LibColorInput/LibColorInput.stories.d.ts +0 -7
- package/dist/runtime/components/LibColorInput/LibColorInput.stories.js +0 -58
- package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.d.ts +0 -7
- package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +0 -51
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.d.ts +0 -7
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.js +0 -36
- package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.d.ts +0 -11
- package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.js +0 -98
- package/dist/runtime/components/LibDebug/LibDebug.stories.d.ts +0 -9
- package/dist/runtime/components/LibDebug/LibDebug.stories.js +0 -46
- package/dist/runtime/components/LibFileInput/LibFileInput.stories.d.ts +0 -10
- package/dist/runtime/components/LibFileInput/LibFileInput.stories.js +0 -63
- package/dist/runtime/components/LibInput/LibInput.stories.d.ts +0 -33
- package/dist/runtime/components/LibInput/LibInput.stories.js +0 -339
- package/dist/runtime/components/LibLabel/LibLabel.stories.d.ts +0 -6
- package/dist/runtime/components/LibLabel/LibLabel.stories.js +0 -25
- package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.d.ts +0 -23
- package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.js +0 -60
- package/dist/runtime/components/LibNotifications/LibNotification.stories.d.ts +0 -15
- package/dist/runtime/components/LibNotifications/LibNotification.stories.js +0 -126
- package/dist/runtime/components/LibNotifications/LibNotifications.stories.d.ts +0 -6
- package/dist/runtime/components/LibNotifications/LibNotifications.stories.js +0 -109
- package/dist/runtime/components/LibPagination/LibPagination.stories.d.ts +0 -6
- package/dist/runtime/components/LibPagination/LibPagination.stories.js +0 -40
- package/dist/runtime/components/LibPalette/LibPalette.stories.d.ts +0 -6
- package/dist/runtime/components/LibPalette/LibPalette.stories.js +0 -20
- package/dist/runtime/components/LibPopup/LibPopup.stories.d.ts +0 -14
- package/dist/runtime/components/LibPopup/LibPopup.stories.js +0 -147
- package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.d.ts +0 -10
- package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.js +0 -81
- package/dist/runtime/components/LibRecorder/LibRecorder.stories.d.ts +0 -19
- package/dist/runtime/components/LibRecorder/LibRecorder.stories.js +0 -63
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.d.ts +0 -26
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.js +0 -78
- package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.d.ts +0 -27
- package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.js +0 -112
- package/dist/runtime/components/LibTable/LibTable.stories.d.ts +0 -16
- package/dist/runtime/components/LibTable/LibTable.stories.js +0 -156
- package/dist/runtime/components/reset.stories.d.ts +0 -5
- package/dist/runtime/components/reset.stories.js +0 -19
- package/dist/runtime/composables/useScrollNearContainerEdges.stories.d.ts +0 -7
- package/dist/runtime/composables/useScrollNearContainerEdges.stories.js +0 -85
- package/dist/runtime/helpers/addValue.d.ts +0 -1
- package/dist/runtime/helpers/addValue.js +0 -8
- package/dist/types.d.ts +0 -7
- package/src/runtime/components/LibInput/LibInput.vue +0 -372
- package/src/runtime/helpers/addValue.ts +0 -10
- /package/src/runtime/components/{reset.stories.ts → Reset.stories.ts} +0 -0
|
@@ -1,33 +1,42 @@
|
|
|
1
1
|
import { isBlank } from "@alanscodelog/utils/isBlank.js";
|
|
2
2
|
import { isObject } from "@alanscodelog/utils/isObject.js";
|
|
3
|
+
import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn.js";
|
|
4
|
+
import { removeIfIn } from "@alanscodelog/utils/removeIfIn.js";
|
|
3
5
|
import { computed, ref, toRaw, watch } from "vue";
|
|
4
|
-
export function useSuggestions($inputValue, $modelValue, emit, opts, debug = false) {
|
|
6
|
+
export function useSuggestions($inputValue, $modelValue, $open, emit, opts, debug = false) {
|
|
5
7
|
if (typeof opts.suggestions?.[0] === "object" && !opts.suggestionLabel && !opts.suggestionsFilter) {
|
|
6
8
|
throw new Error("`suggestionLabel` or `suggestionsFilter` must be passed if suggestions are objects.");
|
|
7
9
|
}
|
|
8
|
-
const isOpen = ref(false);
|
|
9
10
|
const activeSuggestion = ref(-1);
|
|
10
|
-
watch(isOpen, (val) => {
|
|
11
|
-
emit("update:isOpen", val);
|
|
12
|
-
});
|
|
13
11
|
watch(activeSuggestion, (val) => {
|
|
14
12
|
emit("update:activeSuggestion", val);
|
|
15
13
|
});
|
|
16
|
-
|
|
14
|
+
if (opts.suggestions) {
|
|
15
|
+
for (const suggestion of opts.suggestions) {
|
|
16
|
+
suggestionLabelGuard(suggestion, opts.suggestionLabel);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const getSuggestionLabel = (item) => {
|
|
20
|
+
suggestionLabelGuard(item, opts.suggestionLabel);
|
|
17
21
|
if (isObject(item)) {
|
|
18
|
-
|
|
19
|
-
return opts.suggestionLabel(item);
|
|
20
|
-
}
|
|
21
|
-
throw new Error("`suggestionLabel` must be passed if suggestions are objects.");
|
|
22
|
+
return opts.suggestionLabel(item);
|
|
22
23
|
}
|
|
23
24
|
return item;
|
|
24
25
|
};
|
|
25
|
-
const
|
|
26
|
-
|
|
26
|
+
const defaultSuggestionsFilter = (input, items) => input === "" ? [...items] : items.filter((item) => {
|
|
27
|
+
if (Array.isArray($modelValue.value)) {
|
|
28
|
+
if ($modelValue.value.includes(getSuggestionLabel(item))) return true;
|
|
29
|
+
}
|
|
30
|
+
return getSuggestionLabel(item).toLowerCase().includes(input.toLowerCase());
|
|
31
|
+
});
|
|
27
32
|
const suggestionsFilter = computed(() => opts.suggestionsFilter ?? defaultSuggestionsFilter);
|
|
28
33
|
const suggestionsList = computed(() => {
|
|
29
34
|
if (opts.suggestions) {
|
|
30
|
-
const
|
|
35
|
+
const suggestions = [...opts.suggestions];
|
|
36
|
+
if (Array.isArray($modelValue.value) && !opts.showSelectedValues) {
|
|
37
|
+
pushIfNotIn(suggestions, $modelValue.value);
|
|
38
|
+
}
|
|
39
|
+
const res = suggestionsFilter.value($inputValue.value, suggestions);
|
|
31
40
|
return res;
|
|
32
41
|
}
|
|
33
42
|
return void 0;
|
|
@@ -43,19 +52,30 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
|
|
|
43
52
|
if (opts.suggestions) {
|
|
44
53
|
const res = suggestionAvailable.value ? suggestionsList.value : opts.suggestions;
|
|
45
54
|
if (opts.restrictToSuggestions && !isValidSuggestion.value) return res;
|
|
46
|
-
if (opts.preventDuplicateValues && opts.values) {
|
|
47
|
-
return res.filter((suggestion) => !opts.values.includes(suggestionKey(suggestion)));
|
|
48
|
-
}
|
|
49
55
|
return res;
|
|
50
56
|
}
|
|
51
57
|
return void 0;
|
|
52
58
|
});
|
|
53
|
-
|
|
59
|
+
function setValue(val) {
|
|
60
|
+
if (Array.isArray($modelValue.value)) {
|
|
61
|
+
if ($modelValue.value.includes(val)) {
|
|
62
|
+
removeIfIn($modelValue.value, val);
|
|
63
|
+
return true;
|
|
64
|
+
} else {
|
|
65
|
+
pushIfNotIn($modelValue.value, [val]);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
$modelValue.value = val;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
function closeSuggestions() {
|
|
73
|
+
if (!opts.canClose) return;
|
|
54
74
|
if (debug) console.log("closeSuggestions");
|
|
55
|
-
|
|
75
|
+
$open.value = false;
|
|
56
76
|
activeSuggestion.value = -1;
|
|
57
|
-
}
|
|
58
|
-
|
|
77
|
+
}
|
|
78
|
+
function openSuggestions() {
|
|
59
79
|
if (debug) console.log("openSuggestions", { openable: openable.value });
|
|
60
80
|
if (!openable.value) return;
|
|
61
81
|
if (activeSuggestion.value === -1) {
|
|
@@ -65,20 +85,22 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
|
|
|
65
85
|
activeSuggestion.value = 0;
|
|
66
86
|
}
|
|
67
87
|
}
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
function enterSuggestion(num) {
|
|
88
|
+
$open.value = true;
|
|
89
|
+
}
|
|
90
|
+
function enterSuggestion(num, doClose = true) {
|
|
71
91
|
if (num < -1 || num > (filteredSuggestions.value?.length ?? 0)) return;
|
|
72
92
|
if (debug) console.log("enterSuggestion", num);
|
|
73
93
|
if (filteredSuggestions.value === void 0) return;
|
|
74
94
|
const suggestion = filteredSuggestions.value[num];
|
|
75
|
-
const val =
|
|
76
|
-
|
|
77
|
-
$inputValue.value = getSuggestionLabel(suggestion);
|
|
78
|
-
|
|
79
|
-
|
|
95
|
+
const val = getSuggestionLabel(suggestion);
|
|
96
|
+
const wasRemoved = setValue(val);
|
|
97
|
+
$inputValue.value = Array.isArray($modelValue.value) ? "" : getSuggestionLabel(suggestion);
|
|
98
|
+
if (doClose) {
|
|
99
|
+
closeSuggestions();
|
|
100
|
+
}
|
|
101
|
+
emit("submit", val, toRaw(suggestion), wasRemoved);
|
|
80
102
|
}
|
|
81
|
-
|
|
103
|
+
function enterSelected(doClose = true) {
|
|
82
104
|
if (activeSuggestion.value === -1) {
|
|
83
105
|
if (!opts.restrictToSuggestions) {
|
|
84
106
|
if (debug) console.log("enterSelected, unrestricted, emitting submit");
|
|
@@ -89,9 +111,9 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
|
|
|
89
111
|
return;
|
|
90
112
|
}
|
|
91
113
|
if (debug) console.log("enterSelected");
|
|
92
|
-
enterSuggestion(activeSuggestion.value);
|
|
93
|
-
}
|
|
94
|
-
|
|
114
|
+
enterSuggestion(activeSuggestion.value, doClose);
|
|
115
|
+
}
|
|
116
|
+
function selectSuggestion(num) {
|
|
95
117
|
if (debug) console.log("selectSuggestion", num);
|
|
96
118
|
if (num >= -1) {
|
|
97
119
|
activeSuggestion.value = num;
|
|
@@ -99,37 +121,41 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
|
|
|
99
121
|
if (num === Infinity && (filteredSuggestions.value?.length ?? 0) > 0) {
|
|
100
122
|
activeSuggestion.value = filteredSuggestions.value.length - 1;
|
|
101
123
|
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
124
|
+
}
|
|
125
|
+
function toggleSuggestions() {
|
|
126
|
+
$open.value ? closeSuggestions() : openSuggestions();
|
|
127
|
+
}
|
|
128
|
+
function prevSuggestion() {
|
|
107
129
|
if (!filteredSuggestions.value) return;
|
|
108
130
|
if (activeSuggestion.value > 0) {
|
|
109
131
|
activeSuggestion.value--;
|
|
110
132
|
} else if (filteredSuggestions.value) {
|
|
111
133
|
activeSuggestion.value = filteredSuggestions.value.length - 1;
|
|
112
134
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
135
|
+
}
|
|
136
|
+
function nextSuggestion() {
|
|
115
137
|
if (!filteredSuggestions.value) return;
|
|
116
138
|
if (activeSuggestion.value >= filteredSuggestions.value.length - 1) {
|
|
117
139
|
activeSuggestion.value = 0;
|
|
118
140
|
} else {
|
|
119
141
|
activeSuggestion.value++;
|
|
120
142
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
143
|
+
}
|
|
144
|
+
function firstSuggestion() {
|
|
123
145
|
selectSuggestion(0);
|
|
124
|
-
}
|
|
125
|
-
|
|
146
|
+
}
|
|
147
|
+
function lastSuggestion() {
|
|
126
148
|
selectSuggestion(Infinity);
|
|
127
|
-
}
|
|
128
|
-
|
|
149
|
+
}
|
|
150
|
+
function cancel() {
|
|
151
|
+
if (Array.isArray($modelValue.value)) {
|
|
152
|
+
$inputValue.value = "";
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
129
155
|
if (debug) console.log("cancel");
|
|
130
156
|
$inputValue.value = getSuggestionLabel($modelValue.value);
|
|
131
157
|
closeSuggestions();
|
|
132
|
-
}
|
|
158
|
+
}
|
|
133
159
|
watch(() => opts.canOpen, (val) => {
|
|
134
160
|
if (!val) {
|
|
135
161
|
if (debug) console.log("canOpen changed to false, closing suggestions");
|
|
@@ -149,10 +175,14 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
|
|
|
149
175
|
}
|
|
150
176
|
});
|
|
151
177
|
watch($modelValue, () => {
|
|
152
|
-
|
|
178
|
+
if (Array.isArray($modelValue.value)) {
|
|
179
|
+
$inputValue.value = "";
|
|
180
|
+
} else {
|
|
181
|
+
$inputValue.value = getSuggestionLabel($modelValue.value);
|
|
182
|
+
}
|
|
153
183
|
if (debug) console.log("modelValue changed");
|
|
154
184
|
});
|
|
155
|
-
|
|
185
|
+
function defaultSuggestionSelector(suggestions, input) {
|
|
156
186
|
if (input.length === 0) return 0;
|
|
157
187
|
let longestMatch;
|
|
158
188
|
let ii = -1;
|
|
@@ -168,17 +198,17 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
|
|
|
168
198
|
}
|
|
169
199
|
}
|
|
170
200
|
return ii;
|
|
171
|
-
}
|
|
201
|
+
}
|
|
172
202
|
watch($inputValue, () => {
|
|
173
203
|
if (debug) console.log("input changed:", $inputValue.value, "modelValue:", $modelValue.value);
|
|
174
|
-
if (getSuggestionLabel($modelValue.value) === $inputValue.value) return;
|
|
204
|
+
if (!Array.isArray($modelValue.value) && getSuggestionLabel($modelValue.value) === $inputValue.value) return;
|
|
175
205
|
if (suggestionAvailable.value) {
|
|
176
206
|
if (debug) console.log("input changed, suggestion available, opening suggestions");
|
|
177
207
|
openSuggestions();
|
|
178
208
|
}
|
|
179
|
-
if (!opts.restrictToSuggestions) {
|
|
209
|
+
if (!opts.restrictToSuggestions && !Array.isArray($modelValue.value)) {
|
|
180
210
|
if (debug) console.log("input changed, unrestricted, setting modelValue");
|
|
181
|
-
$
|
|
211
|
+
setValue($inputValue.value);
|
|
182
212
|
}
|
|
183
213
|
if (exactlyMatchingSuggestion.value && suggestionsList.value) {
|
|
184
214
|
if (debug) console.log("input changed, exactly matching, setting activeSuggestion");
|
|
@@ -200,11 +230,11 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
|
|
|
200
230
|
hasValidSuggestion: isValidSuggestion,
|
|
201
231
|
openable,
|
|
202
232
|
getLabel: getSuggestionLabel,
|
|
203
|
-
|
|
233
|
+
$open,
|
|
204
234
|
open: openSuggestions,
|
|
205
235
|
close: closeSuggestions,
|
|
206
236
|
enterSelected,
|
|
207
|
-
enterSuggestion,
|
|
237
|
+
enterIndex: enterSuggestion,
|
|
208
238
|
toggle: toggleSuggestions,
|
|
209
239
|
cancel,
|
|
210
240
|
select: selectSuggestion,
|
|
@@ -214,13 +244,20 @@ export function useSuggestions($inputValue, $modelValue, emit, opts, debug = fal
|
|
|
214
244
|
last: lastSuggestion
|
|
215
245
|
};
|
|
216
246
|
}
|
|
217
|
-
export function useSuggestionsInputAria(id,
|
|
247
|
+
export function useSuggestionsInputAria(id, $open, activeSuggestion, suggestions) {
|
|
218
248
|
const ariaInputProps = computed(() => ({
|
|
219
249
|
"aria-autocomplete": suggestions !== void 0 ? "both" : void 0,
|
|
220
250
|
"aria-controls": suggestions !== void 0 ? `suggestions-${id.value}` : void 0,
|
|
221
251
|
role: suggestions ? "combobox" : void 0,
|
|
222
|
-
"aria-expanded": suggestions !== void 0 ?
|
|
223
|
-
"aria-activedescendant":
|
|
252
|
+
"aria-expanded": suggestions !== void 0 ? $open.value : void 0,
|
|
253
|
+
"aria-activedescendant": $open.value ? `suggestion-${id.value}-${activeSuggestion.value}` : void 0
|
|
224
254
|
}));
|
|
225
255
|
return ariaInputProps;
|
|
226
256
|
}
|
|
257
|
+
export function suggestionLabelGuard(item, suggestionLabeler) {
|
|
258
|
+
if (isObject(item)) {
|
|
259
|
+
if (!suggestionLabeler) {
|
|
260
|
+
throw new Error("`suggestionLabel` must be passed if suggestions are objects.");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
@@ -48,7 +48,7 @@ export const vResizableCols = {
|
|
|
48
48
|
return {};
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
|
|
51
|
+
function setWidth(col, amountInPx, el) {
|
|
52
52
|
const $el = getElInfo(el);
|
|
53
53
|
const width = Math.max($el.margin, amountInPx);
|
|
54
54
|
const index = getColEls(el).findIndex((_) => col === _);
|
|
@@ -57,12 +57,12 @@ const setWidth = (col, amountInPx, el) => {
|
|
|
57
57
|
} else {
|
|
58
58
|
$el.widths.value[index] = `${width}px`;
|
|
59
59
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
60
|
+
}
|
|
61
|
+
function getBox(el) {
|
|
62
62
|
const rect = el.getBoundingClientRect();
|
|
63
63
|
return { x: Math.round(rect.x), width: Math.round(rect.width) };
|
|
64
|
-
}
|
|
65
|
-
|
|
64
|
+
}
|
|
65
|
+
function getCols(el) {
|
|
66
66
|
const $el = getElInfo(el);
|
|
67
67
|
if (!$el.target) unreachable();
|
|
68
68
|
let col = getColEls(el)[$el.grips.get($el.target)];
|
|
@@ -77,75 +77,81 @@ const getCols = (el) => {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
return { col, colNext };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
80
|
+
}
|
|
81
|
+
function createPointerDownHandler(el) {
|
|
82
|
+
return (e) => {
|
|
83
|
+
const $el = getElInfo(el);
|
|
84
|
+
if (!$el.isDragging) {
|
|
85
|
+
castType(e.target);
|
|
86
|
+
$el.target = e.target;
|
|
87
|
+
$el.isDragging = true;
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
document.addEventListener("pointerup", $el.pointerUpHandler);
|
|
90
|
+
const { col, colNext } = getCols(el);
|
|
91
|
+
if (col === null || colNext === null) {
|
|
92
|
+
el.classList.add("resizable-cols-error");
|
|
93
|
+
} else {
|
|
94
|
+
document.addEventListener("pointermove", $el.pointerMoveHandler);
|
|
95
|
+
const box = getBox(col);
|
|
96
|
+
if (box) {
|
|
97
|
+
$el.offset = e.pageX - (box.x + box.width);
|
|
98
|
+
}
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function createPointerMoveHandler(el) {
|
|
104
|
+
return (e) => {
|
|
105
|
+
const $el = getElInfo(el);
|
|
106
|
+
if ($el.isDragging) {
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
const { col, colNext } = getCols(el);
|
|
109
|
+
if (col !== null) {
|
|
110
|
+
const leftBox = getBox(col);
|
|
111
|
+
const oldWidth = leftBox.width;
|
|
112
|
+
const leftBound = leftBox.x;
|
|
113
|
+
const rightBox = colNext ? getBox(colNext) : getBox(el);
|
|
114
|
+
const rightBound = rightBox.x + rightBox.width;
|
|
115
|
+
const margin = $el.margin;
|
|
116
|
+
const pos = e.pageX - $el.offset;
|
|
117
|
+
if ($el.fitWidth) {
|
|
118
|
+
if (pos > leftBound + margin && pos < rightBound - margin) {
|
|
119
|
+
const newWidth = pos - leftBound;
|
|
120
|
+
const diff = oldWidth - newWidth;
|
|
121
|
+
if (rightBox.width + diff < margin) {
|
|
122
|
+
el.classList.add("resizable-cols-error");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
setWidth(col, newWidth, el);
|
|
126
|
+
setWidth(colNext, rightBox.width + diff, el);
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
if (pos > leftBound + margin) {
|
|
130
|
+
const newWidth = pos - leftBound;
|
|
131
|
+
setWidth(col, newWidth, el);
|
|
121
132
|
}
|
|
122
|
-
setWidth(col, newWidth, el);
|
|
123
|
-
setWidth(colNext, rightBox.width + diff, el);
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
if (pos > leftBound + margin) {
|
|
127
|
-
const newWidth = pos - leftBound;
|
|
128
|
-
setWidth(col, newWidth, el);
|
|
129
133
|
}
|
|
134
|
+
positionGrips(el);
|
|
130
135
|
}
|
|
131
|
-
positionGrips(el);
|
|
132
136
|
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function createPointerUpHandler(el) {
|
|
140
|
+
return (e) => {
|
|
141
|
+
const $el = getElInfo(el);
|
|
142
|
+
if ($el.isDragging) {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
$el.isDragging = false;
|
|
145
|
+
el.classList.remove("resizable-cols-error");
|
|
146
|
+
$el.offset = 0;
|
|
147
|
+
delete $el.target;
|
|
148
|
+
document.removeEventListener("pointermove", $el.pointerMoveHandler);
|
|
149
|
+
document.removeEventListener("pointerup", $el.pointerUpHandler);
|
|
150
|
+
document.removeEventListener("pointerleave", $el.pointerLeaveHandler);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function createGrip() {
|
|
149
155
|
const grip = document.createElement("div");
|
|
150
156
|
grip.style.position = "absolute";
|
|
151
157
|
grip.style.cursor = "col-resize";
|
|
@@ -153,31 +159,31 @@ const createGrip = () => {
|
|
|
153
159
|
grip.style.bottom = "0";
|
|
154
160
|
grip.classList.add("grip");
|
|
155
161
|
return grip;
|
|
156
|
-
}
|
|
162
|
+
}
|
|
157
163
|
const removeGrips = (el) => {
|
|
158
164
|
const grips = Array.from(el.querySelectorAll(".grip") ?? []);
|
|
159
165
|
for (const grip of grips) {
|
|
160
166
|
el.removeChild(grip);
|
|
161
167
|
}
|
|
162
168
|
};
|
|
163
|
-
|
|
169
|
+
function getTestGripSize(el) {
|
|
164
170
|
const testGrip = createGrip();
|
|
165
171
|
el.appendChild(testGrip);
|
|
166
172
|
const dynamicMinWidth = getBox(testGrip).width * 3;
|
|
167
173
|
el.removeChild(testGrip);
|
|
168
174
|
return dynamicMinWidth;
|
|
169
|
-
}
|
|
170
|
-
|
|
175
|
+
}
|
|
176
|
+
function getElInfo(el) {
|
|
171
177
|
const $el = elMap.get(el);
|
|
172
178
|
if (!$el) unreachable("El went missing.");
|
|
173
179
|
return $el;
|
|
174
|
-
}
|
|
175
|
-
|
|
180
|
+
}
|
|
181
|
+
function getColEls(el) {
|
|
176
182
|
const $el = elMap.get(el);
|
|
177
183
|
if (!$el) unreachable("El went missing.");
|
|
178
184
|
return [...el.querySelectorAll(`:scope ${$el.selector ? $el.selector : "tr > td"}`)];
|
|
179
|
-
}
|
|
180
|
-
|
|
185
|
+
}
|
|
186
|
+
function setupColumns(el, opts) {
|
|
181
187
|
const gripWidth = getTestGripSize(el);
|
|
182
188
|
const $el = {
|
|
183
189
|
grips: /* @__PURE__ */ new Map(),
|
|
@@ -207,19 +213,21 @@ const setupColumns = (el, opts) => {
|
|
|
207
213
|
}
|
|
208
214
|
positionGrips(el);
|
|
209
215
|
el.classList.add("resizable-cols-setup");
|
|
210
|
-
}
|
|
211
|
-
|
|
216
|
+
}
|
|
217
|
+
function positionGrips(el) {
|
|
212
218
|
let xPos = 0;
|
|
213
219
|
const $el = getElInfo(el);
|
|
214
220
|
for (const grip of $el.grips.keys()) {
|
|
215
221
|
const col = $el.grips.get(grip);
|
|
216
|
-
const
|
|
222
|
+
const colEls = getColEls(el)[col];
|
|
223
|
+
if (!colEls) unreachable();
|
|
224
|
+
const colBox = getBox(colEls);
|
|
217
225
|
const gripBox = getBox(grip);
|
|
218
226
|
grip.style.left = `${xPos + colBox.width - gripBox.width / 2}px`;
|
|
219
227
|
xPos += colBox.width;
|
|
220
228
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
229
|
+
}
|
|
230
|
+
function setColWidths(el, children) {
|
|
223
231
|
const $el = getElInfo(el);
|
|
224
232
|
const header = children ?? getColEls(el).slice(0, $el.colCount);
|
|
225
233
|
const len = $el.colCount;
|
|
@@ -237,8 +245,8 @@ const setColWidths = (el, children) => {
|
|
|
237
245
|
} else {
|
|
238
246
|
el.style.minWidth = "";
|
|
239
247
|
}
|
|
240
|
-
}
|
|
241
|
-
|
|
248
|
+
}
|
|
249
|
+
function teardownColumns(el) {
|
|
242
250
|
const $el = getElInfo(el);
|
|
243
251
|
el.removeEventListener("pointerdown", $el.pointerDownHandler);
|
|
244
252
|
document.removeEventListener("pointermove", $el.pointerMoveHandler);
|
|
@@ -249,4 +257,4 @@ const teardownColumns = (el) => {
|
|
|
249
257
|
elMap.delete(el);
|
|
250
258
|
el.classList.remove("resizable-cols-setup");
|
|
251
259
|
removeGrips(el);
|
|
252
|
-
}
|
|
260
|
+
}
|
|
@@ -28,11 +28,16 @@ export type RawNotificationEntry<TOptions extends string[] = ["Ok", "Cancel"], T
|
|
|
28
28
|
message: string;
|
|
29
29
|
title?: string;
|
|
30
30
|
code?: string;
|
|
31
|
+
/** @default ["Ok", "Cancel"] */
|
|
31
32
|
options?: TOptions;
|
|
33
|
+
/** @default false */
|
|
32
34
|
requiresAction?: boolean;
|
|
33
35
|
cancellable?: TCancellable;
|
|
36
|
+
/** @default "Ok" */
|
|
34
37
|
default?: TOptions[number];
|
|
38
|
+
/** @default [] */
|
|
35
39
|
dangerous?: TOptions[number][];
|
|
40
|
+
/** @default false if cancellable, otherwise the default timeout */
|
|
36
41
|
timeout?: number | boolean;
|
|
37
42
|
icon?: string;
|
|
38
43
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export { addValue } from "./addValue.js.js";
|
|
2
1
|
export { base64ToImg } from "./base64ToImg.js.js";
|
|
3
2
|
export { copy } from "./copy.js.js";
|
|
3
|
+
export { createNoonUtcDate } from "./createNoonUtcDate.js.js";
|
|
4
4
|
export { createRecorderHandler } from "./storybook.js.js";
|
|
5
|
+
export { defaultTranslationFunction } from "./defaultTranslationFunction.js.js";
|
|
6
|
+
export { getTimeZoneList } from "./getTimeZoneList.js.js";
|
|
5
7
|
export { hasModifiers } from "./hasModifiers.js.js";
|
|
6
8
|
export { NotificationHandler } from "./NotificationHandler.js.js";
|
|
7
9
|
export { readFile } from "./readFile.js.js";
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export { addValue } from "./addValue.js";
|
|
2
1
|
export { base64ToImg } from "./base64ToImg.js";
|
|
3
2
|
export { copy } from "./copy.js";
|
|
3
|
+
export { createNoonUtcDate } from "./createNoonUtcDate.js";
|
|
4
4
|
export { createRecorderHandler } from "./storybook.js";
|
|
5
|
+
export { defaultTranslationFunction } from "./defaultTranslationFunction.js";
|
|
6
|
+
export { getTimeZoneList } from "./getTimeZoneList.js";
|
|
5
7
|
export { hasModifiers } from "./hasModifiers.js";
|
|
6
8
|
export { NotificationHandler } from "./NotificationHandler.js";
|
|
7
9
|
export { readFile } from "./readFile.js";
|
|
@@ -53,18 +53,24 @@ export type FileInputError = ErrorW<{
|
|
|
53
53
|
isValidMimeType: boolean;
|
|
54
54
|
isValidExtension: boolean;
|
|
55
55
|
}>;
|
|
56
|
+
/** h 0-360+ (deg), s 0-100%, v 0-100%, a 0-1 */
|
|
56
57
|
export type HsvaColor = {
|
|
57
58
|
h: number;
|
|
58
59
|
s: number;
|
|
59
60
|
v: number;
|
|
60
61
|
a?: number;
|
|
61
62
|
};
|
|
63
|
+
/** rgb 0-255, 0-1 for alpha */
|
|
62
64
|
export type RgbaColor = {
|
|
63
65
|
r: number;
|
|
64
66
|
g: number;
|
|
65
67
|
b: number;
|
|
66
68
|
a?: number;
|
|
67
69
|
};
|
|
70
|
+
export type Point = {
|
|
71
|
+
x: number;
|
|
72
|
+
y: number;
|
|
73
|
+
};
|
|
68
74
|
export type ScrollNearContainerEdgesOptions = {
|
|
69
75
|
containerEl: Ref<HTMLElement | null>;
|
|
70
76
|
/** Margin inside contianer that allows scrolling. 10 by default. */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notifies the user if the given value is an error. Useful for making non-critical errors don't go unnoticed.
|
|
3
|
+
*
|
|
4
|
+
* Integrates with {@link TypedError} from `@alanscodelog/utils` to display the error code as well if it has one.
|
|
5
|
+
*
|
|
6
|
+
* If the value is not an error, it is returned.
|
|
7
|
+
*/
|
|
8
|
+
export declare function notifyIfError<T>(err: T, { logger, ns, force, }?: {
|
|
9
|
+
logger?: {
|
|
10
|
+
debug: (...args: any[]) => void;
|
|
11
|
+
};
|
|
12
|
+
ns?: string;
|
|
13
|
+
force?: boolean;
|
|
14
|
+
}): T;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TypedError } from "@alanscodelog/utils/TypedError.js";
|
|
2
|
+
import { useNotificationHandler } from "../composables/useNotificationHandler.js";
|
|
3
|
+
export function notifyIfError(err, {
|
|
4
|
+
logger,
|
|
5
|
+
ns,
|
|
6
|
+
force = false
|
|
7
|
+
} = {}) {
|
|
8
|
+
if (force || err instanceof Error) {
|
|
9
|
+
const errMessage = {
|
|
10
|
+
message: err instanceof Error ? err.message : `Unknown error ${err}`,
|
|
11
|
+
code: err instanceof TypedError ? err.code : void 0
|
|
12
|
+
};
|
|
13
|
+
if (logger) {
|
|
14
|
+
logger.debug({
|
|
15
|
+
ns,
|
|
16
|
+
...errMessage,
|
|
17
|
+
stack: err instanceof Error ? err.stack : void 0
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
void useNotificationHandler().notify({
|
|
21
|
+
title: "Error",
|
|
22
|
+
...errMessage,
|
|
23
|
+
options: ["Ok"],
|
|
24
|
+
cancellable: "Ok",
|
|
25
|
+
timeout: true
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return err;
|
|
29
|
+
}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
export { default } from './module.mjs'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
-
|
|
7
|
-
export { default } from './module.js'
|
|
3
|
+
export { type ModuleOptions } from './module.mjs'
|