@witchcraft/ui 0.1.0 → 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.
Files changed (138) hide show
  1. package/dist/module.json +2 -2
  2. package/dist/module.mjs +1 -1
  3. package/dist/runtime/components/Aria/Aria.vue +5 -9
  4. package/dist/runtime/components/Aria/Aria.vue.d.ts +5 -0
  5. package/dist/runtime/components/Icon/Icon.vue +10 -31
  6. package/dist/runtime/components/Icon/Icon.vue.d.ts +21 -0
  7. package/dist/runtime/components/LibButton/LibButton.vue +58 -77
  8. package/dist/runtime/components/LibButton/LibButton.vue.d.ts +36 -0
  9. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +48 -75
  10. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +42 -0
  11. package/dist/runtime/components/LibColorInput/LibColorInput.vue +63 -108
  12. package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +63 -0
  13. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +271 -352
  14. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +61 -0
  15. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +32 -57
  16. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +22 -0
  17. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue +17 -38
  18. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +40 -0
  19. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +53 -82
  20. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +34 -0
  21. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +50 -67
  22. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +34 -0
  23. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +7 -8
  24. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +22 -0
  25. package/dist/runtime/components/LibDebug/LibDebug.vue +42 -70
  26. package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +32 -0
  27. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +18 -31
  28. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +22 -0
  29. package/dist/runtime/components/LibFileInput/LibFileInput.vue +113 -157
  30. package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +43 -0
  31. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +215 -242
  32. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue.d.ts +165 -0
  33. package/dist/runtime/components/LibLabel/LibLabel.vue +30 -46
  34. package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +27 -0
  35. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +44 -59
  36. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +29 -0
  37. package/dist/runtime/components/LibNotifications/LibNotification.vue +32 -49
  38. package/dist/runtime/components/LibNotifications/LibNotification.vue.d.ts +17 -0
  39. package/dist/runtime/components/LibNotifications/LibNotifications.vue +63 -84
  40. package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +13 -0
  41. package/dist/runtime/components/LibPagination/LibPagination.vue +67 -112
  42. package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +104 -0
  43. package/dist/runtime/components/LibPalette/LibPalette.vue +20 -23
  44. package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +14 -0
  45. package/dist/runtime/components/LibPopup/LibPopup.vue +314 -352
  46. package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +46 -0
  47. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +70 -92
  48. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +41 -0
  49. package/dist/runtime/components/LibRecorder/LibRecorder.vue +133 -178
  50. package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +77 -0
  51. package/dist/runtime/components/LibRoot/LibRoot.vue +73 -100
  52. package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +41 -0
  53. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +49 -78
  54. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +35 -0
  55. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +123 -157
  56. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +94 -0
  57. package/dist/runtime/components/LibTable/LibTable.vue +63 -100
  58. package/dist/runtime/components/LibTable/LibTable.vue.d.ts +45 -0
  59. package/dist/runtime/components/Template/NAME.vue +15 -36
  60. package/dist/runtime/components/Template/NAME.vue.d.ts +17 -0
  61. package/dist/runtime/components/TestControls/TestControls.vue +6 -9
  62. package/dist/runtime/components/TestControls/TestControls.vue.d.ts +5 -0
  63. package/dist/runtime/directives/vResizableCols.js +89 -83
  64. package/dist/types.d.mts +2 -6
  65. package/package.json +11 -11
  66. package/src/runtime/components/Focus.stories.ts +3 -2
  67. package/src/runtime/components/Icon/Icon.vue +0 -1
  68. package/src/runtime/components/LibButton/LibButton.vue +0 -1
  69. package/src/runtime/components/LibCheckbox/LibCheckbox.vue +0 -1
  70. package/src/runtime/components/LibColorInput/LibColorInput.vue +0 -1
  71. package/src/runtime/components/LibColorPicker/utils/safeConvertToHsva.ts +0 -1
  72. package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +0 -1
  73. package/src/runtime/components/LibFileInput/LibFileInput.vue +0 -1
  74. package/src/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +0 -1
  75. package/src/runtime/components/LibMultiValues/LibMultiValues.vue +0 -1
  76. package/src/runtime/components/LibNotifications/LibNotification.vue +0 -1
  77. package/src/runtime/components/LibNotifications/LibNotifications.vue +0 -1
  78. package/src/runtime/components/LibPagination/LibPagination.vue +0 -1
  79. package/src/runtime/components/LibPopup/LibPopup.vue +0 -1
  80. package/src/runtime/components/LibProgressBar/LibProgressBar.vue +0 -1
  81. package/src/runtime/components/LibRecorder/LibRecorder.vue +0 -1
  82. package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +0 -1
  83. package/src/runtime/components/LibSuggestions/LibSuggestions.vue +0 -1
  84. package/src/runtime/components/LibTable/LibTable.vue +0 -1
  85. package/src/runtime/directives/vResizableCols.ts +79 -73
  86. package/dist/module.cjs +0 -5
  87. package/dist/module.d.ts +0 -36
  88. package/dist/runtime/components/Focus.stories.d.ts +0 -11
  89. package/dist/runtime/components/Focus.stories.js +0 -53
  90. package/dist/runtime/components/LibButton/LibButton.stories.d.ts +0 -12
  91. package/dist/runtime/components/LibButton/LibButton.stories.js +0 -94
  92. package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.d.ts +0 -14
  93. package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.js +0 -29
  94. package/dist/runtime/components/LibColorInput/LibColorInput.stories.d.ts +0 -7
  95. package/dist/runtime/components/LibColorInput/LibColorInput.stories.js +0 -58
  96. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.d.ts +0 -9
  97. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +0 -68
  98. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.d.ts +0 -7
  99. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.js +0 -36
  100. package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.d.ts +0 -11
  101. package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.js +0 -98
  102. package/dist/runtime/components/LibDebug/LibDebug.stories.d.ts +0 -9
  103. package/dist/runtime/components/LibDebug/LibDebug.stories.js +0 -46
  104. package/dist/runtime/components/LibFileInput/LibFileInput.stories.d.ts +0 -10
  105. package/dist/runtime/components/LibFileInput/LibFileInput.stories.js +0 -63
  106. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.d.ts +0 -33
  107. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.js +0 -384
  108. package/dist/runtime/components/LibLabel/LibLabel.stories.d.ts +0 -6
  109. package/dist/runtime/components/LibLabel/LibLabel.stories.js +0 -25
  110. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.d.ts +0 -23
  111. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.js +0 -61
  112. package/dist/runtime/components/LibNotifications/LibNotification.stories.d.ts +0 -15
  113. package/dist/runtime/components/LibNotifications/LibNotification.stories.js +0 -126
  114. package/dist/runtime/components/LibNotifications/LibNotifications.stories.d.ts +0 -6
  115. package/dist/runtime/components/LibNotifications/LibNotifications.stories.js +0 -109
  116. package/dist/runtime/components/LibPagination/LibPagination.stories.d.ts +0 -6
  117. package/dist/runtime/components/LibPagination/LibPagination.stories.js +0 -40
  118. package/dist/runtime/components/LibPalette/LibPalette.stories.d.ts +0 -6
  119. package/dist/runtime/components/LibPalette/LibPalette.stories.js +0 -20
  120. package/dist/runtime/components/LibPopup/LibPopup.stories.d.ts +0 -14
  121. package/dist/runtime/components/LibPopup/LibPopup.stories.js +0 -147
  122. package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.d.ts +0 -10
  123. package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.js +0 -81
  124. package/dist/runtime/components/LibRecorder/LibRecorder.stories.d.ts +0 -19
  125. package/dist/runtime/components/LibRecorder/LibRecorder.stories.js +0 -63
  126. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.d.ts +0 -26
  127. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.js +0 -78
  128. package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.d.ts +0 -27
  129. package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.js +0 -112
  130. package/dist/runtime/components/LibTable/LibTable.stories.d.ts +0 -16
  131. package/dist/runtime/components/LibTable/LibTable.stories.js +0 -156
  132. package/dist/runtime/components/Reset.stories.d.ts +0 -5
  133. package/dist/runtime/components/Reset.stories.js +0 -19
  134. package/dist/runtime/components/Scrolling.stories.d.ts +0 -6
  135. package/dist/runtime/components/Scrolling.stories.js +0 -44
  136. package/dist/runtime/composables/useScrollNearContainerEdges.stories.d.ts +0 -7
  137. package/dist/runtime/composables/useScrollNearContainerEdges.stories.js +0 -85
  138. package/dist/types.d.ts +0 -7
@@ -0,0 +1,46 @@
1
+ import { type HTMLAttributes } from "vue";
2
+ import { type LinkableByIdProps, type TailwindClassProp, type PopupProps } from "../shared/props.js.js";
3
+ import type { IPopupReference, PopupPositioner } from "../../types/index.js.js";
4
+ type RealProps = LinkableByIdProps & PopupProps;
5
+ interface Props extends
6
+ /** @vue-ignore */
7
+ Partial<Omit<HTMLAttributes, "class"> & TailwindClassProp>, RealProps {
8
+ }
9
+ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props & {
10
+ modelValue?: boolean;
11
+ }, {
12
+ recompute: (force?: boolean) => void;
13
+ setReference: (el: IPopupReference | null) => void;
14
+ setBackground: (el: IPopupReference | null) => void;
15
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
16
+ "update:modelValue": (value: boolean) => any;
17
+ } & {
18
+ close: () => any;
19
+ }, string, import("vue").PublicProps, Readonly<Props & {
20
+ modelValue?: boolean;
21
+ }> & Readonly<{
22
+ "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
23
+ onClose?: (() => any) | undefined;
24
+ }>, {
25
+ canClose: boolean;
26
+ useDialogForBackdrop: false;
27
+ useBackdrop: boolean;
28
+ preferredHorizontal: ("center" | "right" | "left" | "either" | "center-screen" | "right-most" | "left-most" | "center-most")[] | PopupPositioner;
29
+ preferredVertical: ("top" | "bottom" | "center" | "either" | "center-screen" | "top-most" | "bottom-most" | "center-most")[] | PopupPositioner;
30
+ avoidRepositioning: boolean;
31
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
32
+ button?: (props: {
33
+ extractEl: (_: any) => any;
34
+ }) => any;
35
+ } & {
36
+ popup?: (props: {
37
+ position: any;
38
+ extractEl: (_: any) => any;
39
+ }) => any;
40
+ }>;
41
+ export default _default;
42
+ type __VLS_WithSlots<T, S> = T & {
43
+ new (): {
44
+ $slots: S;
45
+ };
46
+ };
@@ -35,17 +35,17 @@
35
35
  before:transition-all
36
36
  before:z-1
37
37
  before:duration-500
38
- `,psuedoHide && `
38
+ `, psuedoHide && `
39
39
  after:opacity-0
40
40
  before:opacity-0
41
- `, ($attrs as any).class)"
41
+ `, $attrs.class)"
42
42
  :data-value="progress"
43
43
  :title="label"
44
44
  role="progressbar"
45
45
  :aria-valuenow="clampVal(progress, clamp[0] ?? 0, clamp[1] ?? 100)"
46
46
  :aria-valuemin="clamp[0] ?? 0"
47
47
  :aria-valuemax="clamp[1] ?? 100"
48
- v-bind="{...$attrs, class:undefined}"
48
+ v-bind="{ ...$attrs, class: void 0 }"
49
49
  :style="`--progress: ${clampVal(progress, clamp[0] ?? 0, clamp[1] ?? 100)}%;`"
50
50
  >
51
51
  <div class="procgress-bar--label-wrapper relative flex-1">
@@ -93,102 +93,80 @@
93
93
  </div>
94
94
  </Transition>
95
95
  </template>
96
- <script setup lang="ts">
97
- import { type HTMLAttributes,type PropType, ref, watch } from "vue"
98
-
99
- import { twMerge } from "../../utils/twMerge.js"
100
- import { type BaseInteractiveProps, baseInteractivePropsDefaults,getFallbackId,type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js"
101
-
102
- // TODO move to utils
103
- const clampVal = (n: number, min: number, max: number) => Math.min(Math.max(n, min), max)
104
96
 
97
+ <script setup>
98
+ import { ref, watch } from "vue";
99
+ import { twMerge } from "../../utils/twMerge.js";
100
+ import { baseInteractivePropsDefaults, getFallbackId } from "../shared/props.js";
101
+ const clampVal = (n, min, max) => Math.min(Math.max(n, min), max);
105
102
  defineOptions({
106
- name: "lib-progress-bar",
107
- inheritAttrs: false,
108
- })
109
- const fallbackId = getFallbackId()
110
- // eslint-disable-next-line no-use-before-define
111
- const props = withDefaults(defineProps<Props>(), {
112
- autohideOnComplete: -1,
113
- keepSpaceWhenHidden: false,
114
- clamp: () => [0, 100],
115
- ...baseInteractivePropsDefaults
116
- })
117
- const hide = ref<boolean>(false)
118
- const psuedoHide = ref<boolean>(false)
119
- let timeout: number
120
- let type: number
103
+ name: "lib-progress-bar",
104
+ inheritAttrs: false
105
+ });
106
+ const fallbackId = getFallbackId();
107
+ const props = defineProps(/* @__PURE__ */ _mergeDefaults({
108
+ id: { type: String, required: false },
109
+ disabled: { type: Boolean, required: false },
110
+ readonly: { type: Boolean, required: false },
111
+ border: { type: Boolean, required: false },
112
+ unstyle: { type: Boolean, required: false },
113
+ label: { type: String, required: false },
114
+ progress: { type: Number, required: true },
115
+ autohideOnComplete: { type: Number, required: false },
116
+ keepSpaceWhenHidden: { type: Boolean, required: false },
117
+ clamp: { type: Array, required: false }
118
+ }, {
119
+ autohideOnComplete: -1,
120
+ keepSpaceWhenHidden: false,
121
+ clamp: () => [0, 100],
122
+ ...baseInteractivePropsDefaults
123
+ }));
124
+ const hide = ref(false);
125
+ const psuedoHide = ref(false);
126
+ let timeout;
127
+ let type;
121
128
  if (props.autohideOnComplete > -1 && (props.progress >= 100 || props.progress < 0)) {
122
- if (props.keepSpaceWhenHidden) {
123
- hide.value = false
124
- psuedoHide.value = true
125
- } else {
126
- hide.value = true
127
- psuedoHide.value = false
128
- }
129
+ if (props.keepSpaceWhenHidden) {
130
+ hide.value = false;
131
+ psuedoHide.value = true;
132
+ } else {
133
+ hide.value = true;
134
+ psuedoHide.value = false;
135
+ }
129
136
  }
130
-
131
137
  watch([
132
- () => props.progress,
133
- () => props.keepSpaceWhenHidden,
134
- () => props.autohideOnComplete,
138
+ () => props.progress,
139
+ () => props.keepSpaceWhenHidden,
140
+ () => props.autohideOnComplete
135
141
  ], () => {
136
- if (props.autohideOnComplete > -1 && (props.progress >= 100 || props.progress < 0)) {
137
- if (props.keepSpaceWhenHidden) {
138
- if (type === 1) return
139
- clearTimeout(timeout)
140
- type = 1
141
- timeout = setTimeout(() => {
142
- type = 0
143
- hide.value = false
144
- psuedoHide.value = true
145
- }, props.autohideOnComplete) as any
146
- } else {
147
- if (type === 2) return
148
- clearTimeout(timeout)
149
- type = 2
150
- timeout = setTimeout(() => {
151
- type = 0
152
- hide.value = true
153
- psuedoHide.value = false
154
- }, props.autohideOnComplete) as any
155
- }
156
- } else {
157
- clearTimeout(timeout)
158
- hide.value = false
159
- psuedoHide.value = false
160
- }
161
- }, { immediate: false })
162
-
142
+ if (props.autohideOnComplete > -1 && (props.progress >= 100 || props.progress < 0)) {
143
+ if (props.keepSpaceWhenHidden) {
144
+ if (type === 1) return;
145
+ clearTimeout(timeout);
146
+ type = 1;
147
+ timeout = setTimeout(() => {
148
+ type = 0;
149
+ hide.value = false;
150
+ psuedoHide.value = true;
151
+ }, props.autohideOnComplete);
152
+ } else {
153
+ if (type === 2) return;
154
+ clearTimeout(timeout);
155
+ type = 2;
156
+ timeout = setTimeout(() => {
157
+ type = 0;
158
+ hide.value = true;
159
+ psuedoHide.value = false;
160
+ }, props.autohideOnComplete);
161
+ }
162
+ } else {
163
+ clearTimeout(timeout);
164
+ hide.value = false;
165
+ psuedoHide.value = false;
166
+ }
167
+ }, { immediate: false });
163
168
  </script>
164
- <script lang="ts">
165
-
166
- type RealProps =
167
- & LinkableByIdProps
168
- & BaseInteractiveProps
169
- & LabelProps
170
- & {
171
- progress: number
172
- /** Will auto hide after this given time if progress is 100% or more or less than 0% until progress is set to something else. Disabled (-1) by default. */
173
- autohideOnComplete?: number
174
- /**
175
- * Do not actually hide the element, just leave an unstyled div,
176
- * so the whole layout doesn't change on completion when autohideOnComplete is set.
177
- */
178
- keepSpaceWhenHidden?: boolean
179
- /**
180
- * By default the progress bar is visually clamped to 0-100, even if the value might be something else.
181
- * You can change what it's clamped to here, to for example,
182
- * show at least a small sliver of the progress bar when it's still 0.
183
- */
184
- clamp?: [start:number, end:number]
185
- }
186
169
 
187
- interface Props
188
- extends
189
- /** @vue-ignore */
190
- Partial<Omit<HTMLAttributes,"class"> & TailwindClassProp>,
191
- RealProps
192
- { }
170
+ <script>
193
171
 
194
172
  </script>
@@ -0,0 +1,41 @@
1
+ import { type HTMLAttributes } from "vue";
2
+ import { type BaseInteractiveProps, type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js.js";
3
+ type RealProps = LinkableByIdProps & BaseInteractiveProps & LabelProps & {
4
+ progress: number;
5
+ /** Will auto hide after this given time if progress is 100% or more or less than 0% until progress is set to something else. Disabled (-1) by default. */
6
+ autohideOnComplete?: number;
7
+ /**
8
+ * Do not actually hide the element, just leave an unstyled div,
9
+ * so the whole layout doesn't change on completion when autohideOnComplete is set.
10
+ */
11
+ keepSpaceWhenHidden?: boolean;
12
+ /**
13
+ * By default the progress bar is visually clamped to 0-100, even if the value might be something else.
14
+ * You can change what it's clamped to here, to for example,
15
+ * show at least a small sliver of the progress bar when it's still 0.
16
+ */
17
+ clamp?: [start: number, end: number];
18
+ };
19
+ interface Props extends
20
+ /** @vue-ignore */
21
+ Partial<Omit<HTMLAttributes, "class"> & TailwindClassProp>, RealProps {
22
+ }
23
+ declare const _default: __VLS_WithSlots<import("vue").DefineComponent<Props, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
24
+ disabled: boolean;
25
+ readonly: boolean;
26
+ border: boolean;
27
+ unstyle: boolean;
28
+ autohideOnComplete: number;
29
+ keepSpaceWhenHidden: boolean;
30
+ clamp: [start: number, end: number];
31
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
32
+ default?: (props: {}) => any;
33
+ } & {
34
+ default?: (props: {}) => any;
35
+ }>;
36
+ export default _default;
37
+ type __VLS_WithSlots<T, S> = T & {
38
+ new (): {
39
+ $slots: S;
40
+ };
41
+ };
@@ -4,8 +4,9 @@
4
4
  contenteditable=false is because of storybook, it's shortcuts interfere when not using real input elements
5
5
  -->
6
6
  <div
7
- :id="id?? fallbackId"
8
- :class="twMerge(`recorder
7
+ :id="id ?? fallbackId"
8
+ :class="twMerge(
9
+ `recorder
9
10
  flex items-center
10
11
  gap-2
11
12
  px-2
@@ -13,37 +14,38 @@
13
14
  focus-outline-no-offset
14
15
  rounded-sm
15
16
  `,
16
- border &&`
17
+ border && `
17
18
  border
18
19
  border-neutral-500
19
20
  focus:border-accent-500
20
21
  `,
21
-
22
- (disabled || readonly) && `
22
+ (disabled || readonly) && `
23
23
  text-neutral-400
24
24
  dark:text-neutral-600
25
25
  `,
26
- (disabled || readonly) && border && `
26
+ (disabled || readonly) && border && `
27
27
  bg-neutral-50
28
28
  dark:bg-neutral-950
29
29
  border-neutral-400
30
30
  dark:border-neutral-600
31
- `
32
- , ($attrs as any).class)"
31
+ `,
32
+ $attrs.class
33
+ )"
33
34
  :aria-disabled="disabled"
34
35
  :aria-readonly="readonly"
35
36
  :tabindex="disabled ? -1 : 0"
36
37
  :title="recording ? recordingTitle : tempValue"
37
38
  contenteditable="false"
38
39
  ref="recorderEl"
39
- v-bind="{...ariaLabel, ...$attrs, class:undefined}"
40
+ v-bind="{ ...ariaLabel, ...$attrs, class: void 0 }"
40
41
  @blur="handleBlurRecorder($event)"
41
42
  @click="handleClickRecorder($event)"
42
43
  @keydown.space.prevent="handleClickRecorder($event, true)"
43
44
  >
44
45
  <!-- :aria-description="recording ? recordingTitle : ''" -->
45
46
  <div
46
- :class="twMerge(`recorder--indicator
47
+ :class="twMerge(
48
+ `recorder--indicator
47
49
  inline-block
48
50
  bg-red-700
49
51
  rounded-full
@@ -52,192 +54,145 @@
52
54
  shrink-0
53
55
  hover:bg-red-500
54
56
  `,
55
- recording && `
57
+ recording && `
56
58
  animate-[blink_1s_infinite]
57
59
  bg-red-500
58
60
  `,
59
- (disabled || readonly) && `
61
+ (disabled || readonly) && `
60
62
  bg-neutral-500
61
63
  `
62
- )"
64
+ )"
63
65
  ref="recorderIndicatorEl"
64
66
  />
65
67
  <div class="recorder--value before:content-vertical-holder truncate">
66
- {{ recording
67
- ? recordingValue ?? t("recorder.recording")
68
- : tempValue }}
68
+ {{ recording ? recordingValue ?? t("recorder.recording") : tempValue }}
69
69
  </div>
70
70
  </div>
71
71
  </template>
72
- <script setup lang="ts">
73
- import { keys } from "@alanscodelog/utils/keys.js"
74
- import { computed, type HTMLAttributes ,onBeforeUnmount, onMounted, type PropType, ref, watch, watchPostEffect } from "vue"
75
-
76
- import { useAriaLabel } from "../../composables/useAriaLabel.js"
77
- import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
78
- import { twMerge } from "../../utils/twMerge.js"
79
- import { type BaseInteractiveProps, baseInteractivePropsDefaults, getFallbackId, type LabelProps, type LinkableByIdProps,type TailwindClassProp } from "../shared/props.js"
80
72
 
73
+ <script setup>
74
+ import { keys } from "@alanscodelog/utils/keys.js";
75
+ import { computed, onBeforeUnmount, onMounted, ref, watch, watchPostEffect } from "vue";
76
+ import { useAriaLabel } from "../../composables/useAriaLabel.js";
77
+ import { useInjectedI18n } from "../../composables/useInjectedI18n.js";
78
+ import { twMerge } from "../../utils/twMerge.js";
79
+ import { baseInteractivePropsDefaults, getFallbackId } from "../shared/props.js";
81
80
  defineOptions({
82
- name: "lib-recorder",
83
- inheritAttrs: false,
84
- })
85
- const t = useInjectedI18n()
86
-
87
- const emits = defineEmits<{
88
- /** Recorder is blurred */
89
- (e: "recorder:blur", $event: FocusEvent): void
90
- /** Recorder is clicked. The component's indicator and recorder elements are passed to help filter out those clicks. */
91
- (e: "recorder:click", { event, indicator, input }: { event: MouseEvent | KeyboardEvent, indicator: HTMLElement, input: HTMLInputElement }): void
92
- /* User presses enter. Not emitted when multiple values are used. */
93
- (e: "focus:parent"): void
94
- }>()
95
- const fallbackId = getFallbackId()
96
- // eslint-disable-next-line no-use-before-define
97
- const props = withDefaults(defineProps<Props>(), {
98
- recordingTitle: "",
99
- id: undefined,
100
- binders: undefined,
101
- recorder: undefined,
102
- ...baseInteractivePropsDefaults
103
- })
104
- /**
105
- * Puts the element into recording mode if true. See {@link props.recorder}.
106
- */
107
- const recording = defineModel<boolean>("recording", { required: false, default: false })
108
-
109
- /** The final value of the recorder. For intermediate values while recording, pass a recorder and set an appropriate recording value. */
110
- const modelValue = defineModel<string>({ required: true })
111
-
112
-
113
- const recorderEl = ref<HTMLInputElement | null>(null)
114
- const recorderIndicatorEl = ref<HTMLElement | null>(null)
115
- const canEdit = computed(() => !props.disabled && !props.readonly)
116
- const tempValue = ref(modelValue.value)
117
-
81
+ name: "lib-recorder",
82
+ inheritAttrs: false
83
+ });
84
+ const t = useInjectedI18n();
85
+ const emits = defineEmits(["recorder:blur", "recorder:click", "focus:parent"]);
86
+ const fallbackId = getFallbackId();
87
+ const props = defineProps(/* @__PURE__ */ _mergeDefaults({
88
+ id: { type: String, required: false },
89
+ disabled: { type: Boolean, required: false },
90
+ readonly: { type: Boolean, required: false },
91
+ border: { type: Boolean, required: false },
92
+ unstyle: { type: Boolean, required: false },
93
+ label: { type: String, required: false },
94
+ recordingValue: { type: String, required: false },
95
+ recordingTitle: { type: String, required: false },
96
+ recorder: { type: null, required: false },
97
+ binders: { type: null, required: false }
98
+ }, {
99
+ recordingTitle: "",
100
+ id: void 0,
101
+ binders: void 0,
102
+ recorder: void 0,
103
+ ...baseInteractivePropsDefaults
104
+ }));
105
+ const recording = defineModel("recording", { type: Boolean, ...{ required: false, default: false } });
106
+ const modelValue = defineModel({ type: String, ...{ required: true } });
107
+ const recorderEl = ref(null);
108
+ const recorderIndicatorEl = ref(null);
109
+ const canEdit = computed(() => !props.disabled && !props.readonly);
110
+ const tempValue = ref(modelValue.value);
118
111
  watch([() => props.binders, () => props.binders], () => {
119
- if (recording.value) {
120
- throw new Error("Component was not designed to allow swapping out of binders/recorders while recording")
121
- }
122
- })
123
-
112
+ if (recording.value) {
113
+ throw new Error("Component was not designed to allow swapping out of binders/recorders while recording");
114
+ }
115
+ });
124
116
  watch(modelValue, () => {
125
- tempValue.value = modelValue.value
126
- })
127
- const ariaLabel = useAriaLabel(props)
128
-
129
- const boundListeners: Record<string, any> = {}
130
- let isBound = false
131
-
132
- const unbindListeners = (): void => {
133
- if (!isBound) return
134
- isBound = false
135
- if (props.recorder) {
136
- for (const key of keys(boundListeners)) {
137
- recorderEl.value?.removeEventListener(key, boundListeners[key])
138
- delete boundListeners[key]
139
- }
140
- }
141
- if (props.binders && recorderEl.value) {
142
- props.binders.unbind(recorderEl.value as HTMLInputElement)
143
- }
144
- }
145
- const bindListeners = (): void => {
146
- if (!props.recorder && !props.binders) {
147
- throw new Error("Record is true but no recorder or binders props was passed")
148
- }
149
- if (props.recorder && props.binders) {
150
- throw new Error("Recording is true and was passed both a recorder and a binders prop. Both cannot be used at the same time.")
151
- }
152
- isBound = true
153
- if (props.recorder) {
154
- for (const key of keys(props.recorder)) {
155
- recorderEl.value?.addEventListener(key, props.recorder[key], { passive: false })
156
- boundListeners[key] = props.recorder[key]
157
- }
158
- }
159
- if (props.binders && recorderEl.value) {
160
- props.binders.bind(recorderEl.value as HTMLInputElement)
161
- }
162
- }
163
-
117
+ tempValue.value = modelValue.value;
118
+ });
119
+ const ariaLabel = useAriaLabel(props);
120
+ const boundListeners = {};
121
+ let isBound = false;
122
+ const unbindListeners = () => {
123
+ if (!isBound) return;
124
+ isBound = false;
125
+ if (props.recorder) {
126
+ for (const key of keys(boundListeners)) {
127
+ recorderEl.value?.removeEventListener(key, boundListeners[key]);
128
+ delete boundListeners[key];
129
+ }
130
+ }
131
+ if (props.binders && recorderEl.value) {
132
+ props.binders.unbind(recorderEl.value);
133
+ }
134
+ };
135
+ const bindListeners = () => {
136
+ if (!props.recorder && !props.binders) {
137
+ throw new Error("Record is true but no recorder or binders props was passed");
138
+ }
139
+ if (props.recorder && props.binders) {
140
+ throw new Error("Recording is true and was passed both a recorder and a binders prop. Both cannot be used at the same time.");
141
+ }
142
+ isBound = true;
143
+ if (props.recorder) {
144
+ for (const key of keys(props.recorder)) {
145
+ recorderEl.value?.addEventListener(key, props.recorder[key], { passive: false });
146
+ boundListeners[key] = props.recorder[key];
147
+ }
148
+ }
149
+ if (props.binders && recorderEl.value) {
150
+ props.binders.bind(recorderEl.value);
151
+ }
152
+ };
164
153
  watchPostEffect(() => {
165
- if (!canEdit.value) {
166
- unbindListeners()
167
- recording.value = false
168
- return
169
- }
170
- if (recording.value) {
171
- bindListeners()
172
- } else {
173
- if ((props.recorder || props.binders) && isBound) {
174
- unbindListeners()
175
- // if we just blur the input then we can't shift+tab backwards
176
- // this way we can go forwards or backwards without actually focusing since parentEl is not focusable
177
- // parentEl.value?.focus()
178
- emits("focus:parent")
179
- }
180
- }
181
- })
182
-
154
+ if (!canEdit.value) {
155
+ unbindListeners();
156
+ recording.value = false;
157
+ return;
158
+ }
159
+ if (recording.value) {
160
+ bindListeners();
161
+ } else {
162
+ if ((props.recorder || props.binders) && isBound) {
163
+ unbindListeners();
164
+ emits("focus:parent");
165
+ }
166
+ }
167
+ });
183
168
  onBeforeUnmount(() => {
184
- unbindListeners()
185
- })
169
+ unbindListeners();
170
+ });
186
171
  onMounted(() => {
187
- if (recording.value) {
188
- bindListeners()
189
- }
190
- })
191
-
192
- const handleBlurRecorder = (e: FocusEvent): void => {
193
- if (!canEdit.value) return
194
- if (props.recorder || props.binders) {
195
- emits("recorder:blur", e)
196
- }
197
- }
198
-
199
- const handleClickRecorder = (e: MouseEvent | KeyboardEvent, isSpaceKey: boolean = false): void => {
200
- if (!canEdit.value) return
201
- if (!recording.value) {
202
- recorderEl.value?.focus()
203
- }
204
- // toggle if clicking on the recording indicator, otherwise only allow starting recording, so if needed, clicks can be recorded
205
- if (props.recorder || props.binders) {
206
- if (isSpaceKey) { return }
207
- emits("recorder:click", { event: e as MouseEvent, indicator: recorderIndicatorEl.value! as HTMLElement, input: recorderEl.value! as HTMLInputElement })
208
- }
209
- }
210
-
172
+ if (recording.value) {
173
+ bindListeners();
174
+ }
175
+ });
176
+ const handleBlurRecorder = (e) => {
177
+ if (!canEdit.value) return;
178
+ if (props.recorder || props.binders) {
179
+ emits("recorder:blur", e);
180
+ }
181
+ };
182
+ const handleClickRecorder = (e, isSpaceKey = false) => {
183
+ if (!canEdit.value) return;
184
+ if (!recording.value) {
185
+ recorderEl.value?.focus();
186
+ }
187
+ if (props.recorder || props.binders) {
188
+ if (isSpaceKey) {
189
+ return;
190
+ }
191
+ emits("recorder:click", { event: e, indicator: recorderIndicatorEl.value, input: recorderEl.value });
192
+ }
193
+ };
211
194
  </script>
212
- <script lang="ts">
213
- type RealProps =
214
- & LinkableByIdProps
215
- & BaseInteractiveProps
216
- & LabelProps
217
- & {
218
- border?: boolean
219
- /** A value to display while recording, if none given the i18n `recorder.recording` key is used. */
220
- recordingValue?: string
221
- /** A title to display on the input div while recording. Is also used as the aria-description. */
222
- recordingTitle?: string
223
- /**
224
- * The recorder object is a series of event listeners to attach to the input div while recording is started. If you need to bind directly to the element, see the `binders` prop.
225
- *
226
- * The listeners are then unbound when recording is set to false again.
227
- *
228
- * Note that the component does not handle the setting of `recording` (unless the component is disabled), `modelValue`, or `recordingValue` at all and has no mechanism for cancelling a recording. It is left to the recorder listeners and any `recorder:*` handlers to determine what to do.
229
- */
230
- recorder?: undefined | Record<string, any>
231
- /** This provides a way to manually attach/remove event listeners to/from the element. It is an alternative to the `recorder` prop, see it for more details. Both cannot be specified at the same time.*/
232
- binders?: undefined | { bind: (el: HTMLElement) => void, unbind: (el: HTMLElement) => void }
233
- /** The id of the element. If not provided, the id will be generated automatically. */
234
- id?: string
235
- }
236
195
 
237
- interface Props
238
- extends
239
- /** @vue-ignore */
240
- Partial<Omit<HTMLAttributes,"class"> & TailwindClassProp>,
241
- RealProps
242
- { }
196
+ <script>
197
+
243
198
  </script>