@witchcraft/ui 0.3.9 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/runtime/components/LibNotifications/LibNotification.d.vue.ts +7 -1
- package/dist/runtime/components/LibNotifications/LibNotification.vue +23 -2
- package/dist/runtime/components/LibNotifications/LibNotification.vue.d.ts +7 -1
- package/dist/runtime/components/LibNotifications/LibNotifications.vue +2 -2
- package/dist/runtime/utils/doInvertTextColor.d.ts +4 -0
- package/dist/runtime/utils/doInvertTextColor.js +8 -0
- package/package.json +1 -1
- package/src/module.ts +0 -1
- package/src/runtime/components/LibNotifications/LibNotification.vue +35 -2
- package/src/runtime/components/LibNotifications/LibNotifications.vue +2 -2
- package/src/runtime/utils/doInvertTextColor.ts +11 -0
package/dist/module.json
CHANGED
|
@@ -11,7 +11,13 @@ Partial<Omit<HTMLAttributes, "class"> & TailwindClassProp>, RealProps {
|
|
|
11
11
|
}
|
|
12
12
|
declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props, {
|
|
13
13
|
focus: () => void;
|
|
14
|
-
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}
|
|
14
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
15
|
+
pause: (notification: NotificationEntry) => any;
|
|
16
|
+
resume: (notification: NotificationEntry) => any;
|
|
17
|
+
}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
|
|
18
|
+
onPause?: ((notification: NotificationEntry) => any) | undefined;
|
|
19
|
+
onResume?: ((notification: NotificationEntry) => any) | undefined;
|
|
20
|
+
}>, {
|
|
15
21
|
handler: NotificationHandler;
|
|
16
22
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
17
23
|
top?: (props: {
|
|
@@ -20,13 +20,16 @@
|
|
|
20
20
|
p-1
|
|
21
21
|
text-sm
|
|
22
22
|
focus:border-accent-500
|
|
23
|
+
focus-within:border-accent-500
|
|
23
24
|
`,
|
|
24
25
|
$attrs.class
|
|
25
26
|
)"
|
|
26
27
|
v-bind="{ ...$attrs, class: void 0 }"
|
|
27
28
|
tabindex="0"
|
|
29
|
+
:data-id="notification.id"
|
|
28
30
|
ref="notificationEl"
|
|
29
31
|
@keydown.enter.self="NotificationHandler.resolveToDefault(notification)"
|
|
32
|
+
@pointerenter="notification.timeout && !notification.isPaused && emit('pause', notification)"
|
|
30
33
|
>
|
|
31
34
|
<slot
|
|
32
35
|
name="top"
|
|
@@ -148,7 +151,7 @@
|
|
|
148
151
|
</template>
|
|
149
152
|
|
|
150
153
|
<script setup>
|
|
151
|
-
import { computed, onMounted, ref, useAttrs } from "vue";
|
|
154
|
+
import { computed, onBeforeUnmount, onMounted, ref, useAttrs } from "vue";
|
|
152
155
|
import IFa6RegularCopy from "~icons/fa6-regular/copy";
|
|
153
156
|
import IFa6SolidXmark from "~icons/fa6-solid/xmark";
|
|
154
157
|
import { useSlotVars } from "../../composables/useSlotVars.js";
|
|
@@ -167,11 +170,29 @@ const props = defineProps({
|
|
|
167
170
|
notification: { type: null, required: true },
|
|
168
171
|
handler: { type: Object, required: false, default: void 0 }
|
|
169
172
|
});
|
|
170
|
-
const
|
|
173
|
+
const emit = defineEmits(["pause", "resume"]);
|
|
174
|
+
const getColor = (notification, option) => {
|
|
175
|
+
return notification.dangerous.includes(option) ? "danger" : notification.default === option ? "primary" : "secondary";
|
|
176
|
+
};
|
|
171
177
|
const buttonColors = computed(() => props.notification.options.map((option) => getColor(props.notification, option)));
|
|
172
178
|
const notificationEl = ref(null);
|
|
179
|
+
const mousedownAbortController = new AbortController();
|
|
173
180
|
onMounted(() => {
|
|
174
181
|
notificationEl.value?.focus();
|
|
182
|
+
if (props.notification.timeout) {
|
|
183
|
+
window.addEventListener("pointerdown", (e) => {
|
|
184
|
+
if (!e.target || !(e.target instanceof HTMLElement)) return;
|
|
185
|
+
if (e.target === notificationEl.value || notificationEl.value?.contains(e.target)) {
|
|
186
|
+
if (props.notification.isPaused) return;
|
|
187
|
+
emit("pause", props.notification);
|
|
188
|
+
} else {
|
|
189
|
+
emit("resume", props.notification);
|
|
190
|
+
}
|
|
191
|
+
}, { signal: mousedownAbortController.signal });
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
onBeforeUnmount(() => {
|
|
195
|
+
mousedownAbortController.abort();
|
|
175
196
|
});
|
|
176
197
|
defineExpose({
|
|
177
198
|
focus: () => {
|
|
@@ -11,7 +11,13 @@ Partial<Omit<HTMLAttributes, "class"> & TailwindClassProp>, RealProps {
|
|
|
11
11
|
}
|
|
12
12
|
declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props, {
|
|
13
13
|
focus: () => void;
|
|
14
|
-
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}
|
|
14
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
15
|
+
pause: (notification: NotificationEntry) => any;
|
|
16
|
+
resume: (notification: NotificationEntry) => any;
|
|
17
|
+
}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
|
|
18
|
+
onPause?: ((notification: NotificationEntry) => any) | undefined;
|
|
19
|
+
onResume?: ((notification: NotificationEntry) => any) | undefined;
|
|
20
|
+
}>, {
|
|
15
21
|
handler: NotificationHandler;
|
|
16
22
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
17
23
|
top?: (props: {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
class="overflow-hidden my-2"
|
|
33
33
|
v-for="notification of notifications"
|
|
34
34
|
:key="notification.id"
|
|
35
|
-
@
|
|
36
|
-
@
|
|
35
|
+
@pause="handler.pause(notification)"
|
|
36
|
+
@resume="handler.resume(notification)"
|
|
37
37
|
>
|
|
38
38
|
<template #top>
|
|
39
39
|
<LibProgressBar
|
package/package.json
CHANGED
package/src/module.ts
CHANGED
|
@@ -21,7 +21,6 @@ import { unpluginIconViteOptions } from "./runtime/build/unpluginIconViteOptions
|
|
|
21
21
|
import { themeConvertionOpts } from "./runtime/tailwind/themeConvertionOpts.js"
|
|
22
22
|
import { theme } from "./runtime/theme.js"
|
|
23
23
|
|
|
24
|
-
import pkg from "../package.json" assert { type: "json" }
|
|
25
24
|
|
|
26
25
|
const knownDirectives = ["vExtractRootEl", "vResizableCols", "vResizeObserver", "vResizableCols"] as const
|
|
27
26
|
|
|
@@ -19,12 +19,15 @@
|
|
|
19
19
|
p-1
|
|
20
20
|
text-sm
|
|
21
21
|
focus:border-accent-500
|
|
22
|
+
focus-within:border-accent-500
|
|
22
23
|
`,
|
|
23
24
|
($attrs as any).class)"
|
|
24
25
|
v-bind="{ ...$attrs, class: undefined }"
|
|
25
26
|
tabindex="0"
|
|
27
|
+
:data-id="notification.id"
|
|
26
28
|
ref="notificationEl"
|
|
27
29
|
@keydown.enter.self="NotificationHandler.resolveToDefault(notification)"
|
|
30
|
+
@pointerenter="notification.timeout && !notification.isPaused && emit('pause', notification)"
|
|
28
31
|
>
|
|
29
32
|
<slot
|
|
30
33
|
name="top"
|
|
@@ -145,7 +148,7 @@
|
|
|
145
148
|
</template>
|
|
146
149
|
|
|
147
150
|
<script setup lang="ts">
|
|
148
|
-
import { computed, type HTMLAttributes, onMounted, ref, useAttrs } from "vue"
|
|
151
|
+
import { computed, type HTMLAttributes, onBeforeUnmount, onMounted, ref, useAttrs } from "vue"
|
|
149
152
|
|
|
150
153
|
import IFa6RegularCopy from "~icons/fa6-regular/copy"
|
|
151
154
|
import IFa6SolidXmark from "~icons/fa6-solid/xmark"
|
|
@@ -171,16 +174,46 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
171
174
|
handler: undefined
|
|
172
175
|
})
|
|
173
176
|
|
|
174
|
-
const
|
|
177
|
+
const emit = defineEmits<{
|
|
178
|
+
(e: "pause", notification: NotificationEntry): void
|
|
179
|
+
(e: "resume", notification: NotificationEntry): void
|
|
180
|
+
}>()
|
|
181
|
+
|
|
182
|
+
const getColor = (notification: NotificationEntry, option: string): "ok" | "primary" | "danger" | "secondary" => {
|
|
183
|
+
return notification.dangerous.includes(option)
|
|
184
|
+
? "danger"
|
|
185
|
+
: notification.default === option
|
|
186
|
+
? "primary"
|
|
187
|
+
: "secondary"
|
|
188
|
+
}
|
|
175
189
|
|
|
176
190
|
/* Todo make this more flexible? */
|
|
177
191
|
|
|
178
192
|
const buttonColors = computed(() => props.notification.options.map((option: any /* what ??? */) => getColor(props.notification, option)))
|
|
179
193
|
|
|
180
194
|
const notificationEl = ref<null | HTMLElement>(null)
|
|
195
|
+
|
|
196
|
+
const mousedownAbortController = new AbortController()
|
|
197
|
+
|
|
181
198
|
onMounted(() => {
|
|
182
199
|
notificationEl.value?.focus()
|
|
200
|
+
if (props.notification.timeout) {
|
|
201
|
+
window.addEventListener("pointerdown", e => {
|
|
202
|
+
if (!e.target || !(e.target instanceof HTMLElement)) return
|
|
203
|
+
if (e.target === notificationEl.value || notificationEl.value?.contains(e.target)) {
|
|
204
|
+
if (props.notification.isPaused) return
|
|
205
|
+
emit("pause", props.notification)
|
|
206
|
+
} else {
|
|
207
|
+
emit("resume", props.notification)
|
|
208
|
+
}
|
|
209
|
+
}, { signal: mousedownAbortController.signal })
|
|
210
|
+
}
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
onBeforeUnmount(() => {
|
|
214
|
+
mousedownAbortController.abort()
|
|
183
215
|
})
|
|
216
|
+
|
|
184
217
|
defineExpose({
|
|
185
218
|
focus: () => {
|
|
186
219
|
notificationEl.value?.focus()
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
class="overflow-hidden my-2"
|
|
33
33
|
v-for="notification of notifications"
|
|
34
34
|
:key="notification.id"
|
|
35
|
-
@
|
|
36
|
-
@
|
|
35
|
+
@pause="handler.pause(notification)"
|
|
36
|
+
@resume="handler.resume(notification)"
|
|
37
37
|
>
|
|
38
38
|
<template #top>
|
|
39
39
|
<LibProgressBar
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Color from "colorjs.io"
|
|
2
|
+
/**
|
|
3
|
+
* Returns whether the text should be inverted (to white) based on the given color.
|
|
4
|
+
*/
|
|
5
|
+
export function doInvertTextColor(color: string) {
|
|
6
|
+
const c = new Color(color).to("hsv")
|
|
7
|
+
const v = c.hsv[2]
|
|
8
|
+
const a = c.alpha
|
|
9
|
+
const doInvert = !!(v! < 50 || (a === undefined || a < 0.5))
|
|
10
|
+
return doInvert
|
|
11
|
+
}
|