@witchcraft/ui 0.1.1 → 0.1.3
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.cjs +5 -0
- package/dist/module.d.ts +36 -0
- package/dist/module.json +2 -2
- package/dist/module.mjs +2 -1
- package/dist/runtime/assets/utils.css +1 -1
- package/dist/runtime/components/Aria/Aria.vue +9 -5
- package/dist/runtime/components/Focus.stories.d.ts +11 -0
- package/dist/runtime/components/Focus.stories.js +53 -0
- package/dist/runtime/components/Icon/Icon.vue +30 -10
- package/dist/runtime/components/LibButton/LibButton.stories.d.ts +12 -0
- package/dist/runtime/components/LibButton/LibButton.stories.js +94 -0
- package/dist/runtime/components/LibButton/LibButton.vue +72 -58
- package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.d.ts +14 -0
- package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.js +29 -0
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +74 -48
- package/dist/runtime/components/LibColorInput/LibColorInput.stories.d.ts +7 -0
- package/dist/runtime/components/LibColorInput/LibColorInput.stories.js +58 -0
- package/dist/runtime/components/LibColorInput/LibColorInput.vue +107 -63
- package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.d.ts +9 -0
- package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +68 -0
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +352 -271
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.d.ts +7 -0
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.js +36 -0
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +56 -32
- package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.d.ts +11 -0
- package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.js +98 -0
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue +38 -17
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +82 -53
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +67 -50
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +8 -7
- package/dist/runtime/components/LibDebug/LibDebug.stories.d.ts +9 -0
- package/dist/runtime/components/LibDebug/LibDebug.stories.js +46 -0
- package/dist/runtime/components/LibDebug/LibDebug.vue +70 -42
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +31 -18
- package/dist/runtime/components/LibFileInput/LibFileInput.stories.d.ts +10 -0
- package/dist/runtime/components/LibFileInput/LibFileInput.stories.js +63 -0
- package/dist/runtime/components/LibFileInput/LibFileInput.vue +156 -113
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.d.ts +33 -0
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.js +384 -0
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +241 -215
- package/dist/runtime/components/LibLabel/LibLabel.stories.d.ts +6 -0
- package/dist/runtime/components/LibLabel/LibLabel.stories.js +25 -0
- package/dist/runtime/components/LibLabel/LibLabel.vue +46 -30
- package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.d.ts +23 -0
- package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.js +61 -0
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +58 -44
- package/dist/runtime/components/LibNotifications/LibNotification.stories.d.ts +15 -0
- package/dist/runtime/components/LibNotifications/LibNotification.stories.js +126 -0
- package/dist/runtime/components/LibNotifications/LibNotification.vue +48 -32
- package/dist/runtime/components/LibNotifications/LibNotifications.stories.d.ts +6 -0
- package/dist/runtime/components/LibNotifications/LibNotifications.stories.js +109 -0
- package/dist/runtime/components/LibNotifications/LibNotifications.vue +83 -63
- package/dist/runtime/components/LibPagination/LibPagination.stories.d.ts +6 -0
- package/dist/runtime/components/LibPagination/LibPagination.stories.js +40 -0
- package/dist/runtime/components/LibPagination/LibPagination.vue +111 -67
- package/dist/runtime/components/LibPalette/LibPalette.stories.d.ts +6 -0
- package/dist/runtime/components/LibPalette/LibPalette.stories.js +20 -0
- package/dist/runtime/components/LibPalette/LibPalette.vue +23 -20
- package/dist/runtime/components/LibPopup/LibPopup.stories.d.ts +14 -0
- package/dist/runtime/components/LibPopup/LibPopup.stories.js +147 -0
- package/dist/runtime/components/LibPopup/LibPopup.vue +351 -314
- package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.d.ts +10 -0
- package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.js +81 -0
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +91 -70
- package/dist/runtime/components/LibRecorder/LibRecorder.stories.d.ts +19 -0
- package/dist/runtime/components/LibRecorder/LibRecorder.stories.js +63 -0
- package/dist/runtime/components/LibRecorder/LibRecorder.vue +177 -133
- package/dist/runtime/components/LibRoot/LibRoot.vue +100 -73
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.d.ts +26 -0
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.js +78 -0
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +77 -49
- package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.d.ts +27 -0
- package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.js +112 -0
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +156 -123
- package/dist/runtime/components/LibTable/LibTable.stories.d.ts +16 -0
- package/dist/runtime/components/LibTable/LibTable.stories.js +156 -0
- package/dist/runtime/components/LibTable/LibTable.vue +99 -63
- package/dist/runtime/components/Reset.stories.d.ts +5 -0
- package/dist/runtime/components/Reset.stories.js +19 -0
- package/dist/runtime/components/Scrolling.stories.d.ts +6 -0
- package/dist/runtime/components/Scrolling.stories.js +44 -0
- package/dist/runtime/components/Template/NAME.vue +36 -15
- package/dist/runtime/components/TestControls/TestControls.vue +9 -6
- package/dist/runtime/composables/useScrollNearContainerEdges.stories.d.ts +7 -0
- package/dist/runtime/composables/useScrollNearContainerEdges.stories.js +85 -0
- package/dist/types.d.mts +6 -2
- package/dist/types.d.ts +7 -0
- package/package.json +11 -5
- package/src/module.ts +2 -1
- package/src/runtime/assets/utils.css +5 -5
- package/src/runtime/components/LibButton/LibButton.vue +2 -6
- package/src/runtime/nuxt/plugins/vue-plugin.ts +1 -1
- package/dist/runtime/components/Aria/Aria.vue.d.ts +0 -5
- package/dist/runtime/components/Icon/Icon.vue.d.ts +0 -21
- package/dist/runtime/components/LibButton/LibButton.vue.d.ts +0 -36
- package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +0 -42
- package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +0 -63
- package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +0 -61
- package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +0 -22
- package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +0 -40
- package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +0 -34
- package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +0 -34
- package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +0 -22
- package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +0 -32
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +0 -22
- package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +0 -43
- package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue.d.ts +0 -165
- package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +0 -27
- package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +0 -29
- package/dist/runtime/components/LibNotifications/LibNotification.vue.d.ts +0 -17
- package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +0 -13
- package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +0 -104
- package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +0 -14
- package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +0 -46
- package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +0 -41
- package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +0 -77
- package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +0 -41
- package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +0 -35
- package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +0 -94
- package/dist/runtime/components/LibTable/LibTable.vue.d.ts +0 -45
- package/dist/runtime/components/Template/NAME.vue.d.ts +0 -17
- package/dist/runtime/components/TestControls/TestControls.vue.d.ts +0 -5
|
@@ -1,49 +1,69 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { getLocalTimeZone } from "@internationalized/date"
|
|
3
|
-
import { DatePickerArrow, DatePickerCalendar, DatePickerCell, DatePickerCellTrigger, DatePickerContent, DatePickerField, DatePickerGrid, DatePickerGridBody, DatePickerGridHead, DatePickerGridRow, DatePickerHeadCell, DatePickerHeader, DatePickerHeading, DatePickerInput, DatePickerNext, DatePickerPrev, DatePickerRoot, DatePickerTrigger } from "reka-ui"
|
|
4
|
-
import { onBeforeUnmount, ref, toRaw, useAttrs, watch } from "vue"
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { type DateValue, getLocalTimeZone } from "@internationalized/date"
|
|
3
|
+
import { DatePickerArrow, DatePickerCalendar, DatePickerCell, DatePickerCellTrigger, DatePickerContent, DatePickerField, DatePickerGrid, DatePickerGridBody, DatePickerGridHead, DatePickerGridRow, DatePickerHeadCell, DatePickerHeader, DatePickerHeading, DatePickerInput, DatePickerNext, DatePickerPrev, DatePickerRoot, DatePickerTrigger } from "reka-ui"
|
|
4
|
+
import { onBeforeUnmount, ref, toRaw, useAttrs, watch } from "vue"
|
|
5
|
+
|
|
6
|
+
import { convertDateWithFallback, getNow,toEmittableDate } from "./helpers.js"
|
|
7
|
+
|
|
8
|
+
import { useInjectedLocale } from "../../composables/useInjectedLocale.js"
|
|
9
|
+
import type { SingleDate } from "../../types/index.js"
|
|
10
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
11
|
+
import Icon from "../Icon/Icon.vue"
|
|
12
|
+
|
|
13
|
+
const attrs = useAttrs()
|
|
14
|
+
|
|
15
|
+
const props = withDefaults(defineProps<{
|
|
16
|
+
useTime?: boolean
|
|
17
|
+
id: string
|
|
18
|
+
fallbackDate?: Date
|
|
19
|
+
timeZone?: string
|
|
20
|
+
updateInterval?: number
|
|
21
|
+
}>(), {
|
|
22
|
+
timeZone: getLocalTimeZone(),
|
|
23
|
+
useTime: false,
|
|
24
|
+
fallbackDate: _ => getNow({ withTime: _.useTime ?? false }).toDate(_.timeZone ?? getLocalTimeZone()),
|
|
25
|
+
updateInterval: 10000
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const locale = useInjectedLocale().timeLocale
|
|
29
|
+
|
|
30
|
+
const date = defineModel<SingleDate>({ required: true })
|
|
31
|
+
|
|
32
|
+
let justSet = false
|
|
33
|
+
const tempDate = ref()
|
|
21
34
|
function updateTempDate() {
|
|
22
|
-
|
|
35
|
+
tempDate.value = convertDateWithFallback(date.value, props)
|
|
23
36
|
}
|
|
24
|
-
|
|
37
|
+
|
|
38
|
+
updateTempDate()
|
|
39
|
+
|
|
25
40
|
watch(date, () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
})
|
|
41
|
+
if (!justSet) {
|
|
42
|
+
updateTempDate()
|
|
43
|
+
} else {
|
|
44
|
+
justSet = false
|
|
45
|
+
}
|
|
46
|
+
})
|
|
32
47
|
watch(tempDate, () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
48
|
+
justSet = true
|
|
49
|
+
date.value = toEmittableDate(toRaw(tempDate.value as any))
|
|
50
|
+
})
|
|
51
|
+
|
|
36
52
|
watch(() => props.timeZone, () => {
|
|
37
|
-
|
|
38
|
-
})
|
|
53
|
+
updateTempDate()
|
|
54
|
+
})
|
|
55
|
+
|
|
39
56
|
const interval = setInterval(() => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
57
|
+
if (!date.value) {
|
|
58
|
+
// update suggested date if none is set
|
|
59
|
+
updateTempDate()
|
|
60
|
+
}
|
|
61
|
+
}, props.updateInterval)
|
|
62
|
+
|
|
44
63
|
onBeforeUnmount(() => {
|
|
45
|
-
|
|
46
|
-
})
|
|
64
|
+
clearInterval(interval)
|
|
65
|
+
})
|
|
66
|
+
|
|
47
67
|
</script>
|
|
48
68
|
|
|
49
69
|
<template>
|
|
@@ -51,13 +71,11 @@ onBeforeUnmount(() => {
|
|
|
51
71
|
:id="id"
|
|
52
72
|
:locale="locale"
|
|
53
73
|
class="date-picker--root"
|
|
54
|
-
v-model="tempDate"
|
|
74
|
+
v-model="tempDate as DateValue"
|
|
55
75
|
>
|
|
56
76
|
<DatePickerField
|
|
57
77
|
v-slot="{ segments }"
|
|
58
|
-
:class="
|
|
59
|
-
twMerge(
|
|
60
|
-
`
|
|
78
|
+
:class="twMerge(`
|
|
61
79
|
date-picker--field
|
|
62
80
|
flex items-center justify-between
|
|
63
81
|
select-none
|
|
@@ -65,9 +83,8 @@ onBeforeUnmount(() => {
|
|
|
65
83
|
metadata-input-border
|
|
66
84
|
rounded-sm
|
|
67
85
|
`,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
86
|
+
(attrs as any).class)
|
|
87
|
+
"
|
|
71
88
|
>
|
|
72
89
|
<div :class="twMerge(`
|
|
73
90
|
date-picker--segment
|
|
@@ -76,7 +93,7 @@ onBeforeUnmount(() => {
|
|
|
76
93
|
overflow-scroll
|
|
77
94
|
scrollbar-hidden
|
|
78
95
|
whitespace-nowrap
|
|
79
|
-
`, date ===
|
|
96
|
+
`, date === undefined && 'text-neutral-400')"
|
|
80
97
|
>
|
|
81
98
|
<template
|
|
82
99
|
v-for="item in segments"
|
|
@@ -192,7 +209,7 @@ onBeforeUnmount(() => {
|
|
|
192
209
|
outlined
|
|
193
210
|
px-1
|
|
194
211
|
"
|
|
195
|
-
:prev-page="(
|
|
212
|
+
:prev-page="(date: DateValue) => date.subtract({ years: 1 })"
|
|
196
213
|
>
|
|
197
214
|
<Icon class="scale-150">
|
|
198
215
|
<i-radix-icons-double-arrow-left/>
|
|
@@ -246,7 +263,7 @@ onBeforeUnmount(() => {
|
|
|
246
263
|
outlined
|
|
247
264
|
px-1
|
|
248
265
|
"
|
|
249
|
-
:next-page="(
|
|
266
|
+
:next-page="(date: DateValue) => date.add({ years: 1 })"
|
|
250
267
|
>
|
|
251
268
|
<Icon class="scale-150">
|
|
252
269
|
<i-radix-icons-double-arrow-right/>
|
|
@@ -358,7 +375,7 @@ onBeforeUnmount(() => {
|
|
|
358
375
|
</DatePickerGridBody>
|
|
359
376
|
</DatePickerGrid>
|
|
360
377
|
</div>
|
|
361
|
-
<slot v-bind="{
|
|
378
|
+
<slot v-bind="{tempValue: tempDate}"/>
|
|
362
379
|
</DatePickerCalendar>
|
|
363
380
|
</DatePickerContent>
|
|
364
381
|
</DatePickerRoot>
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { getLocalTimeZone } from "@internationalized/date"
|
|
3
|
-
import { getTimeZoneList } from "../../helpers/getTimeZoneList.js";
|
|
4
|
-
import LibInputDeprecated from "../LibInputDeprecated/LibInputDeprecated.vue";
|
|
5
|
-
const timeZone = defineModel({ type: String, ...{ default: getLocalTimeZone() } });
|
|
6
|
-
const label = defineModel("label", { type: String, ...{ default: "Time Zone" } });
|
|
7
|
-
</script>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { getLocalTimeZone } from "@internationalized/date"
|
|
8
3
|
|
|
4
|
+
import { getTimeZoneList } from "../../helpers/getTimeZoneList.js"
|
|
5
|
+
import LibInputDeprecated from "../LibInputDeprecated/LibInputDeprecated.vue"
|
|
6
|
+
const timeZone = defineModel<string>({ default: getLocalTimeZone() })
|
|
7
|
+
const label = defineModel<string>("label", { default: "Time Zone" })
|
|
8
|
+
</script>
|
|
9
9
|
<template>
|
|
10
10
|
<LibInputDeprecated
|
|
11
11
|
:restrict-to-suggestions="true"
|
|
@@ -24,3 +24,4 @@ const label = defineModel("label", { type: String, ...{ default: "Time Zone" } }
|
|
|
24
24
|
</template>
|
|
25
25
|
</LibInputDeprecated>
|
|
26
26
|
</template>
|
|
27
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3";
|
|
2
|
+
import LibDebug from "./LibDebug.vue.js";
|
|
3
|
+
declare const meta: Meta<typeof LibDebug>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof LibDebug>;
|
|
6
|
+
export declare const Primary: Story;
|
|
7
|
+
export declare const WithCustomTab: Story;
|
|
8
|
+
export declare const NoValue: Story;
|
|
9
|
+
export declare const StringWithWhitespace: Story;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { crop } from "@alanscodelog/utils/crop.js";
|
|
2
|
+
import LibDebug from "./LibDebug.vue";
|
|
3
|
+
import * as components from "../index.js";
|
|
4
|
+
const meta = {
|
|
5
|
+
component: LibDebug,
|
|
6
|
+
title: "Components/Debug",
|
|
7
|
+
args: {
|
|
8
|
+
value: { any: ["any", { value: "any" }] }
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
export const Primary = {
|
|
13
|
+
render: (args) => ({
|
|
14
|
+
components,
|
|
15
|
+
setup: () => ({ args }),
|
|
16
|
+
template: `
|
|
17
|
+
<lib-debug v-bind="args" />
|
|
18
|
+
`
|
|
19
|
+
})
|
|
20
|
+
};
|
|
21
|
+
export const WithCustomTab = {
|
|
22
|
+
...Primary,
|
|
23
|
+
args: {
|
|
24
|
+
...Primary.args,
|
|
25
|
+
value: { any: ["any", { value: "any" }] },
|
|
26
|
+
tab: 2
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export const NoValue = {
|
|
30
|
+
...Primary,
|
|
31
|
+
args: {
|
|
32
|
+
...Primary.args,
|
|
33
|
+
value: void 0
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export const StringWithWhitespace = {
|
|
37
|
+
...Primary,
|
|
38
|
+
args: {
|
|
39
|
+
...Primary.args,
|
|
40
|
+
value: crop`
|
|
41
|
+
Manually
|
|
42
|
+
Indented
|
|
43
|
+
String
|
|
44
|
+
`
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -18,56 +18,84 @@
|
|
|
18
18
|
</LibButton>
|
|
19
19
|
</div>
|
|
20
20
|
<pre v-if="value"
|
|
21
|
-
:class="
|
|
22
|
-
`
|
|
21
|
+
:class="`
|
|
23
22
|
debug--value
|
|
24
23
|
[tab-size:${tab}]
|
|
25
24
|
`
|
|
26
|
-
"
|
|
25
|
+
"
|
|
27
26
|
>{{ getStringValue(value) }}</pre>
|
|
28
|
-
<pre v-if="value ===
|
|
27
|
+
<pre v-if="value === undefined"><slot/></pre>
|
|
29
28
|
</div>
|
|
30
29
|
</template>
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
import
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
31
|
+
|
|
32
|
+
<script setup lang="ts">
|
|
33
|
+
import { type PropType, useSlots } from "vue"
|
|
34
|
+
|
|
35
|
+
import Icon from "../Icon/Icon.vue"
|
|
36
|
+
import LibButton from "../LibButton/LibButton.vue"
|
|
37
|
+
|
|
38
|
+
const $slots = useSlots()
|
|
39
|
+
|
|
40
|
+
const props = withDefaults(defineProps<{
|
|
41
|
+
/** The value to debug, can be anything. */
|
|
42
|
+
// eslint-disable-next-line vue/no-restricted-props
|
|
43
|
+
value?: any
|
|
44
|
+
/** Sets the tab size in css. Defaults to 3. */
|
|
45
|
+
tab?: number
|
|
46
|
+
title?: string
|
|
47
|
+
}>(), {
|
|
48
|
+
tab: 3,
|
|
49
|
+
title: "Debug",
|
|
50
|
+
value: undefined,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const getStringValue = (value: any): string => value === undefined
|
|
54
|
+
? "undefined"
|
|
55
|
+
: typeof value === "string"
|
|
56
|
+
? value
|
|
57
|
+
: JSON.stringify(value, null, "\t")
|
|
58
|
+
|
|
59
|
+
const findText = (children: any[]): string => {
|
|
60
|
+
let res = ""
|
|
61
|
+
for (const child of children) {
|
|
62
|
+
if (child.children) {
|
|
63
|
+
if (typeof child.children === "string") res += child.children as string
|
|
64
|
+
else res += findText(child.children)
|
|
65
|
+
} else {
|
|
66
|
+
res += "\n"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return res
|
|
70
|
+
}
|
|
71
|
+
const copy = (): void => {
|
|
72
|
+
if (navigator.clipboard) {
|
|
73
|
+
const text = props.value
|
|
74
|
+
? getStringValue(props.value)
|
|
75
|
+
: $slots.default?.()?.[0]?.children
|
|
76
|
+
? findText([...$slots.default()[0]!.children as any[]])
|
|
77
|
+
: undefined
|
|
78
|
+
if (text === undefined) {
|
|
79
|
+
// eslint-disable-next-line no-console
|
|
80
|
+
console.warn("Cannot copy text, can't generate string value from `getStringValue` or `the default slot`.")
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
navigator.clipboard.writeText(text).catch(() => { })
|
|
84
|
+
}
|
|
85
|
+
}
|
|
66
86
|
</script>
|
|
67
87
|
|
|
68
|
-
<script>
|
|
88
|
+
<script lang="ts">
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Simple debug component for displaying objects and strings with whitespace.
|
|
92
|
+
*
|
|
93
|
+
* In the case of objects, it JSON.stringifies them with a tab character. The tab width can be controlled with the `tab` prop, which will set the `tab-size` css property on the element.
|
|
94
|
+
*
|
|
95
|
+
* The value can be undefined, it will just display undefined.
|
|
96
|
+
*/
|
|
69
97
|
export default {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
98
|
+
name: "lib-debug",
|
|
99
|
+
// https://v3.vuejs.org/guide/typescript-support.html#annotating-props
|
|
100
|
+
}
|
|
73
101
|
</script>
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<DevOnly>
|
|
3
|
-
<slot v-if="doShow && $attrs?.['as-child'] !==
|
|
3
|
+
<slot v-if="doShow && $attrs?.['as-child'] !== undefined"/>
|
|
4
4
|
<div v-else-if="doShow"
|
|
5
|
-
:class="twMerge(
|
|
6
|
-
`
|
|
5
|
+
:class="twMerge(`
|
|
7
6
|
dev-only
|
|
8
7
|
border
|
|
9
8
|
border-dashed
|
|
@@ -12,27 +11,41 @@
|
|
|
12
11
|
py-1
|
|
13
12
|
never-packaged
|
|
14
13
|
`,
|
|
15
|
-
|
|
16
|
-
)"
|
|
17
|
-
v-bind="{
|
|
14
|
+
($attrs.class as string)
|
|
15
|
+
)"
|
|
16
|
+
v-bind="{...$attrs, class: undefined}"
|
|
18
17
|
>
|
|
19
18
|
<slot/>
|
|
20
19
|
</div>
|
|
21
20
|
</DevOnly>
|
|
22
21
|
</template>
|
|
22
|
+
<script lang="ts" setup>
|
|
23
|
+
import { computed, inject, ref, useAttrs } from "vue"
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const doShow = computed(() => props.show || injectedShow.value);
|
|
34
|
-
</script>
|
|
25
|
+
import { showDevOnlyInjectionKey } from "../../composables/useShowDevOnlyKey.js"
|
|
26
|
+
import { twMerge } from "../../utils/twMerge.js"
|
|
27
|
+
const $attrs = useAttrs()
|
|
28
|
+
|
|
29
|
+
const props = withDefaults(defineProps<{
|
|
30
|
+
show?: boolean
|
|
31
|
+
}>(), {
|
|
32
|
+
show: false
|
|
33
|
+
})
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
const injectedShow = inject(showDevOnlyInjectionKey, ref(false))
|
|
36
|
+
const doShow = computed(() => props.show || injectedShow.value)
|
|
37
|
+
|
|
38
|
+
</script>
|
|
39
|
+
<script lang="ts">
|
|
40
|
+
interface Props {
|
|
41
|
+
show?: boolean
|
|
42
|
+
}
|
|
37
43
|
|
|
44
|
+
// Not sure why nuxt's types aren't correctly getting detected
|
|
45
|
+
// This should be enough to bypass the type lint error.
|
|
46
|
+
declare module "vue" {
|
|
47
|
+
export interface GlobalComponents {
|
|
48
|
+
DevOnly: any
|
|
49
|
+
}
|
|
50
|
+
}
|
|
38
51
|
</script>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3";
|
|
2
|
+
import LibFileInput from "./LibFileInput.vue.js";
|
|
3
|
+
declare const meta: Meta<typeof LibFileInput>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof LibFileInput>;
|
|
6
|
+
export declare const SingleFile: Story;
|
|
7
|
+
export declare const MultipleFile: Story;
|
|
8
|
+
export declare const AnyFormat: Story;
|
|
9
|
+
export declare const Compact: Story;
|
|
10
|
+
export declare const ErrorHandling: Story;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import LibFileInput from "./LibFileInput.vue";
|
|
3
|
+
import * as components from "../index.js";
|
|
4
|
+
const meta = {
|
|
5
|
+
component: LibFileInput,
|
|
6
|
+
title: "Components/FileInput",
|
|
7
|
+
args: {}
|
|
8
|
+
};
|
|
9
|
+
export default meta;
|
|
10
|
+
export const SingleFile = {
|
|
11
|
+
render: (args) => ({
|
|
12
|
+
components,
|
|
13
|
+
setup: () => {
|
|
14
|
+
function errorHandler(e) {
|
|
15
|
+
console.log(e);
|
|
16
|
+
}
|
|
17
|
+
return { args, errorHandler };
|
|
18
|
+
},
|
|
19
|
+
template: `
|
|
20
|
+
<lib-file-input v-bind="{...args}" @errors="errorHandler"></lib-file-input>
|
|
21
|
+
`
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
export const MultipleFile = {
|
|
25
|
+
...SingleFile,
|
|
26
|
+
args: {
|
|
27
|
+
...SingleFile.args,
|
|
28
|
+
multiple: true
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const AnyFormat = {
|
|
32
|
+
...SingleFile,
|
|
33
|
+
args: {
|
|
34
|
+
...SingleFile.args,
|
|
35
|
+
multiple: true,
|
|
36
|
+
formats: []
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const Compact = {
|
|
40
|
+
...SingleFile,
|
|
41
|
+
args: {
|
|
42
|
+
...SingleFile.args,
|
|
43
|
+
compact: true
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export const ErrorHandling = {
|
|
47
|
+
render: (args) => ({
|
|
48
|
+
components,
|
|
49
|
+
setup: () => {
|
|
50
|
+
const errors = ref([]);
|
|
51
|
+
const errorHandler = (e) => errors.value = e;
|
|
52
|
+
return {
|
|
53
|
+
args,
|
|
54
|
+
errors,
|
|
55
|
+
errorHandler
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
template: `
|
|
59
|
+
<lib-debug :title="'Errors'">{{errors}}</lib-debug>
|
|
60
|
+
<lib-file-input v-bind="{...args}" @errors="errorHandler"></lib-file-input>
|
|
61
|
+
`
|
|
62
|
+
})
|
|
63
|
+
};
|