@m3ui-vue/m3ui-vue 1.6.2 → 1.8.0
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/API.md +1224 -28
- package/dist/{MColorPickerModal-NtkihoK6.js → MColorPickerModal-H8nuX0Wu.js} +3 -4
- package/dist/{MColorPickerModal-NtkihoK6.js.map → MColorPickerModal-H8nuX0Wu.js.map} +1 -1
- package/dist/MDialog-B42Mhn8W.js +331 -0
- package/dist/MDialog-B42Mhn8W.js.map +1 -0
- package/dist/{MListItem-D2cNUyzP.js → MListItem-DiOAxaN7.js} +431 -325
- package/dist/MListItem-DiOAxaN7.js.map +1 -0
- package/dist/{MLoadingIndicator-DWUj0BAB.js → MLoadingIndicator-CuTZYFFj.js} +2 -2
- package/dist/{MLoadingIndicator-DWUj0BAB.js.map → MLoadingIndicator-CuTZYFFj.js.map} +1 -1
- package/dist/{MSeekBar-C4cn9RIF.js → MSeekBar-BCDQTx2t.js} +2 -2
- package/dist/{MSeekBar-C4cn9RIF.js.map → MSeekBar-BCDQTx2t.js.map} +1 -1
- package/dist/MSegmentedButton-BXzRsg1S.js +105 -0
- package/dist/MSegmentedButton-BXzRsg1S.js.map +1 -0
- package/dist/MSignaturePad-BTqGaPXA.js +313 -0
- package/dist/MSignaturePad-BTqGaPXA.js.map +1 -0
- package/dist/MSlider-D_O8J9YH.js +739 -0
- package/dist/MSlider-D_O8J9YH.js.map +1 -0
- package/dist/{MSpinner-DZkXZJpc.js → MSpinner-UCdtSOHP.js} +2 -2
- package/dist/{MSpinner-DZkXZJpc.js.map → MSpinner-UCdtSOHP.js.map} +1 -1
- package/dist/{MTextField-CNH-byir.js → MTextField-CYk9yFvi.js} +162 -115
- package/dist/MTextField-CYk9yFvi.js.map +1 -0
- package/dist/_useFieldValidation-B0B44M_t.js +191 -0
- package/dist/_useFieldValidation-B0B44M_t.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +184 -103
- package/dist/code-editor.js.map +1 -1
- package/dist/components/MAddressField.vue.d.ts +18 -3
- package/dist/components/MAppBarWithSearch.vue.d.ts +1 -1
- package/dist/components/MAudioRecorder.vue.d.ts +2 -2
- package/dist/components/MAutocomplete.vue.d.ts +22 -3
- package/dist/components/MCheckbox.vue.d.ts +23 -1
- package/dist/components/MCodeEditor.vue.d.ts +23 -1
- package/dist/components/MColorPicker.vue.d.ts +24 -3
- package/dist/components/MConfirmDialog.vue.d.ts +2 -2
- package/dist/components/MCountrySelect.vue.d.ts +13 -2
- package/dist/components/MCreditCardInput.vue.d.ts +33 -0
- package/dist/components/MCronField.vue.d.ts +23 -1
- package/dist/components/MDataTable.vue.d.ts +1 -1
- package/dist/components/MDatePicker.vue.d.ts +24 -3
- package/dist/components/MDateRangePicker.vue.d.ts +24 -3
- package/dist/components/MFileUpload.vue.d.ts +23 -2
- package/dist/components/MForm.vue.d.ts +61 -0
- package/dist/components/MFormBuilder.vue.d.ts +22 -0
- package/dist/components/MFormRenderer.vue.d.ts +151 -0
- package/dist/components/MJsonEditor.vue.d.ts +23 -1
- package/dist/components/MMapRoute.vue.d.ts +176 -0
- package/dist/components/MMaskField.vue.d.ts +20 -2
- package/dist/components/MMentionField.vue.d.ts +13 -2
- package/dist/components/MMultiAutocomplete.vue.d.ts +22 -3
- package/dist/components/MMultiSelect.vue.d.ts +22 -3
- package/dist/components/MNavigationRail.vue.d.ts +1 -1
- package/dist/components/MNotificationCenter.vue.d.ts +2 -2
- package/dist/components/MNumberField.vue.d.ts +20 -2
- package/dist/components/MPdfSigner.vue.d.ts +499 -0
- package/dist/components/MPdfViewer.vue.d.ts +12 -0
- package/dist/components/MPhoneInput.vue.d.ts +19 -4
- package/dist/components/MPinInput.vue.d.ts +24 -3
- package/dist/components/MPosKeypad.vue.d.ts +3 -3
- package/dist/components/MRadioGroup.vue.d.ts +23 -1
- package/dist/components/MRating.vue.d.ts +23 -1
- package/dist/components/MRichTextEditor.vue.d.ts +23 -1
- package/dist/components/MSearchBar.vue.d.ts +1 -1
- package/dist/components/MSegmentedButton.vue.d.ts +23 -2
- package/dist/components/MSelect.vue.d.ts +22 -3
- package/dist/components/MSignaturePad.vue.d.ts +19 -0
- package/dist/components/MSlider.vue.d.ts +23 -1
- package/dist/components/MSpreadsheet.vue.d.ts +137 -0
- package/dist/components/MStack.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +23 -1
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTagInput.vue.d.ts +20 -2
- package/dist/components/MText.vue.d.ts +1 -1
- package/dist/components/MTextField.vue.d.ts +26 -3
- package/dist/components/MTimePicker.vue.d.ts +24 -3
- package/dist/components/MTimezoneSelect.vue.d.ts +13 -2
- package/dist/components/MTour.vue.d.ts +2 -2
- package/dist/components/MTrackingTimeline.vue.d.ts +75 -0
- package/dist/components/MWindow.vue.d.ts +2 -2
- package/dist/composables/_routeGeometry.d.ts +26 -0
- package/dist/composables/_useFieldValidation.d.ts +91 -0
- package/dist/composables/mapRouting.d.ts +35 -0
- package/dist/composables/pdfSign.d.ts +52 -0
- package/dist/composables/spreadsheetFormula.d.ts +55 -0
- package/dist/composables/useLocale.d.ts +177 -0
- package/dist/composables/validation.d.ts +82 -0
- package/dist/draw.js +2 -2
- package/dist/flow.js +1 -1
- package/dist/gantt.js +2 -2
- package/dist/index.d.ts +12 -0
- package/dist/locales/index.js +693 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +15507 -12417
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +4 -0
- package/dist/map.js +1207 -745
- package/dist/map.js.map +1 -1
- package/dist/media.js +4 -4
- package/dist/pdf.d.ts +3 -0
- package/dist/pdf.js +1228 -687
- package/dist/pdf.js.map +1 -1
- package/dist/rich-text-editor.js +188 -146
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-DaVSTdm0.js → useLocale-DL96OFgr.js} +99 -1
- package/dist/useLocale-DL96OFgr.js.map +1 -0
- package/package.json +5 -1
- package/src/__tests__/MForm.test.ts +325 -0
- package/src/__tests__/MFormRenderer.test.ts +157 -0
- package/src/__tests__/MMapRoute.test.ts +418 -0
- package/src/__tests__/MPdfSigner.test.ts +175 -0
- package/src/__tests__/MPhoneInput.test.ts +5 -2
- package/src/__tests__/MRichTextEditor.test.ts +2 -1
- package/src/__tests__/MSpreadsheet.test.ts +223 -0
- package/src/__tests__/MTrackingTimeline.test.ts +66 -0
- package/src/__tests__/_fakeMaplibre.ts +4 -1
- package/src/__tests__/_osrmRoutes.ts +10 -0
- package/src/__tests__/attrsFallthrough.test.ts +11 -0
- package/src/__tests__/fieldsValidation.test.ts +229 -0
- package/src/__tests__/spreadsheetFormula.test.ts +77 -0
- package/src/__tests__/ssr.test.ts +4 -0
- package/src/__tests__/validation.test.ts +77 -0
- package/src/components/MAddressField.vue +45 -8
- package/src/components/MAutocomplete.vue +69 -23
- package/src/components/MCheckbox.vue +80 -17
- package/src/components/MCodeEditor.vue +59 -2
- package/src/components/MColorPicker.vue +65 -16
- package/src/components/MCountrySelect.vue +17 -3
- package/src/components/MCreditCardInput.vue +76 -7
- package/src/components/MCronField.vue +60 -10
- package/src/components/MDatePicker.vue +65 -16
- package/src/components/MDateRangePicker.vue +66 -16
- package/src/components/MFileUpload.vue +71 -8
- package/src/components/MForm.vue +208 -0
- package/src/components/MFormBuilder.vue +417 -0
- package/src/components/MFormRenderer.vue +324 -0
- package/src/components/MJsonEditor.vue +57 -3
- package/src/components/MMapRoute.vue +523 -0
- package/src/components/MMaskField.vue +55 -13
- package/src/components/MMentionField.vue +17 -2
- package/src/components/MMultiAutocomplete.vue +70 -23
- package/src/components/MMultiSelect.vue +70 -23
- package/src/components/MNumberField.vue +58 -16
- package/src/components/MPdfSigner.vue +433 -0
- package/src/components/MPdfViewer.vue +12 -0
- package/src/components/MPhoneInput.vue +60 -18
- package/src/components/MPinInput.vue +58 -10
- package/src/components/MRadioGroup.vue +65 -4
- package/src/components/MRating.vue +62 -6
- package/src/components/MRichTextEditor.vue +64 -4
- package/src/components/MSegmentedButton.vue +59 -2
- package/src/components/MSelect.vue +72 -26
- package/src/components/MSignaturePad.vue +71 -6
- package/src/components/MSlider.vue +61 -10
- package/src/components/MSpreadsheet.vue +992 -0
- package/src/components/MSwitch.vue +63 -8
- package/src/components/MTagInput.vue +67 -25
- package/src/components/MTextField.vue +68 -14
- package/src/components/MTimePicker.vue +65 -16
- package/src/components/MTimezoneSelect.vue +17 -3
- package/src/components/MTrackingTimeline.vue +257 -0
- package/src/composables/_routeGeometry.ts +140 -0
- package/src/composables/_useFieldValidation.ts +287 -0
- package/src/composables/mapRouting.ts +55 -0
- package/src/composables/pdfSign.ts +141 -0
- package/src/composables/spreadsheetFormula.ts +459 -0
- package/src/composables/useLocale.ts +277 -0
- package/src/composables/validation.ts +178 -0
- package/src/index.ts +12 -0
- package/src/locales/de.ts +98 -0
- package/src/locales/es.ts +105 -7
- package/src/locales/fr.ts +98 -0
- package/src/locales/ja.ts +98 -0
- package/src/locales/ko.ts +98 -0
- package/src/locales/pt.ts +98 -0
- package/src/locales/zh.ts +98 -0
- package/src/map.ts +4 -0
- package/src/pdf.ts +3 -0
- package/dist/MButton-OQ4wIERQ.js +0 -171
- package/dist/MButton-OQ4wIERQ.js.map +0 -1
- package/dist/MDialog-DYMnaBlt.js +0 -167
- package/dist/MDialog-DYMnaBlt.js.map +0 -1
- package/dist/MListItem-D2cNUyzP.js.map +0 -1
- package/dist/MProgressBar-BWly1UKN.js +0 -179
- package/dist/MProgressBar-BWly1UKN.js.map +0 -1
- package/dist/MSegmentedButton-BEB4gXLA.js +0 -64
- package/dist/MSegmentedButton-BEB4gXLA.js.map +0 -1
- package/dist/MSlider-BIkA6DiE.js +0 -690
- package/dist/MSlider-BIkA6DiE.js.map +0 -1
- package/dist/MTextField-CNH-byir.js.map +0 -1
- package/dist/useLocale-DaVSTdm0.js.map +0 -1
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* auto-submit
|
|
9
9
|
*/
|
|
10
10
|
import { computed, nextTick, ref, watch } from 'vue'
|
|
11
|
+
import { useFieldValidation, useFocusLeave } from '../composables/_useFieldValidation'
|
|
12
|
+
import type { ValidateOn, ValidationRule } from '../composables/validation'
|
|
11
13
|
|
|
12
14
|
const props = withDefaults(
|
|
13
15
|
defineProps<{
|
|
@@ -25,10 +27,23 @@ const props = withDefaults(
|
|
|
25
27
|
masked?: boolean
|
|
26
28
|
/** Visual style */
|
|
27
29
|
variant?: 'filled' | 'outlined'
|
|
28
|
-
/** Error state */
|
|
29
|
-
error?: boolean
|
|
30
|
+
/** Error state. A string is also the message (`:error="errors.x"`) */
|
|
31
|
+
error?: boolean | string
|
|
30
32
|
/** Error message shown when error is true */
|
|
31
33
|
errorLabel?: string
|
|
34
|
+
/** Marks as required — adds a red asterisk after the label; inside an `MForm` or with `rules`, also validates it */
|
|
35
|
+
required?: boolean
|
|
36
|
+
/**
|
|
37
|
+
* Validation rules: functions `(value, ctx) => true | 'message'` (may be async; see the built-in `required`,
|
|
38
|
+
* `email`, `minLength`…) or a Standard Schema (zod, valibot…). Checked in order; the first failure is shown
|
|
39
|
+
*/
|
|
40
|
+
rules?: ValidationRule | ValidationRule[]
|
|
41
|
+
/** When the rules are checked and shown: on leaving the field (default; live after that), while typing, or only on submit (`MForm`) */
|
|
42
|
+
validateOn?: ValidateOn
|
|
43
|
+
/** Wait this long (ms) after the value stops changing before re-checking (one request for an async rule, not one per key). Defaults to its `MForm`'s */
|
|
44
|
+
validateDebounce?: number
|
|
45
|
+
/** The key of this field in its `MForm`'s values, errors and schema */
|
|
46
|
+
name?: string
|
|
32
47
|
/** Hint text below the boxes */
|
|
33
48
|
hint?: string
|
|
34
49
|
/** Disables every box */
|
|
@@ -65,7 +80,31 @@ const groupBoundaries = computed(() => {
|
|
|
65
80
|
return boundaries
|
|
66
81
|
})
|
|
67
82
|
|
|
68
|
-
const emit = defineEmits<{ 'update:modelValue': [string]; complete: [string] }>()
|
|
83
|
+
const emit = defineEmits<{ blur: []; 'update:modelValue': [string]; complete: [string] }>()
|
|
84
|
+
|
|
85
|
+
const rootEl = ref<HTMLElement | null>(null)
|
|
86
|
+
const validation = useFieldValidation({
|
|
87
|
+
value: () => props.modelValue,
|
|
88
|
+
rules: () => props.rules,
|
|
89
|
+
required: () => props.required,
|
|
90
|
+
error: () => props.error,
|
|
91
|
+
errorLabel: () => props.errorLabel,
|
|
92
|
+
name: () => props.name,
|
|
93
|
+
validateOn: () => props.validateOn,
|
|
94
|
+
validateDebounce: () => props.validateDebounce,
|
|
95
|
+
disabled: () => props.disabled,
|
|
96
|
+
focus: () => { inputEls.value[0]?.focus() },
|
|
97
|
+
el: () => inputEls.value[0],
|
|
98
|
+
setValue: (v) => emit('update:modelValue', v as string),
|
|
99
|
+
isEmpty: (v) => String(v ?? '').length < props.length,
|
|
100
|
+
})
|
|
101
|
+
/** Its own `disabled` or its MForm's */
|
|
102
|
+
const isDisabled = validation.disabled
|
|
103
|
+
const { hasError, message: errorMessage, messageId } = validation
|
|
104
|
+
const onFocusOut = useFocusLeave(() => rootEl.value, () => {
|
|
105
|
+
validation.onBlur()
|
|
106
|
+
emit('blur')
|
|
107
|
+
})
|
|
69
108
|
|
|
70
109
|
const inputEls = ref<(HTMLInputElement | null)[]>([])
|
|
71
110
|
|
|
@@ -171,12 +210,12 @@ const boxClasses = computed(() => {
|
|
|
171
210
|
'h-14 w-12 min-w-0 shrink text-center text-title-large outline-none',
|
|
172
211
|
'transition-[border-color,border-width] duration-150',
|
|
173
212
|
'disabled:cursor-not-allowed disabled:text-on-surface/38',
|
|
174
|
-
|
|
213
|
+
hasError.value ? 'caret-error' : 'caret-primary',
|
|
175
214
|
]
|
|
176
215
|
if (props.variant === 'outlined') {
|
|
177
216
|
return [...base,
|
|
178
217
|
'rounded-xs border bg-transparent text-on-surface',
|
|
179
|
-
|
|
218
|
+
hasError.value
|
|
180
219
|
? 'border-error focus:border-2 focus:border-error'
|
|
181
220
|
: 'border-outline hover:border-on-surface focus:border-2 focus:border-primary',
|
|
182
221
|
'disabled:border-on-surface/12',
|
|
@@ -184,16 +223,23 @@ const boxClasses = computed(() => {
|
|
|
184
223
|
}
|
|
185
224
|
return [...base,
|
|
186
225
|
'rounded-t-xs bg-surface-container-highest border-b text-on-surface',
|
|
187
|
-
|
|
226
|
+
hasError.value
|
|
188
227
|
? 'border-error focus:border-b-2 focus:border-error'
|
|
189
228
|
: 'border-on-surface-variant hover:border-on-surface focus:border-b-2 focus:border-primary',
|
|
190
229
|
'disabled:border-on-surface/38 disabled:bg-[color-mix(in_srgb,var(--color-on-surface)_4%,var(--color-surface-container-highest))]',
|
|
191
230
|
].join(' ')
|
|
192
231
|
})
|
|
232
|
+
|
|
233
|
+
defineExpose({
|
|
234
|
+
/** Checks its rules and shows the result; resolves to whether they pass */
|
|
235
|
+
validate: validation.validate,
|
|
236
|
+
/** Hides its validation error (until the next check) */
|
|
237
|
+
resetValidation: validation.resetValidation,
|
|
238
|
+
})
|
|
193
239
|
</script>
|
|
194
240
|
|
|
195
241
|
<template>
|
|
196
|
-
<div class="flex flex-col gap-1">
|
|
242
|
+
<div ref="rootEl" class="flex flex-col gap-1" @focusout="onFocusOut">
|
|
197
243
|
<div role="group" :aria-label="label" class="flex min-w-0 items-center gap-2">
|
|
198
244
|
<template v-for="(digit, i) in digits" :key="i">
|
|
199
245
|
<input
|
|
@@ -203,8 +249,10 @@ const boxClasses = computed(() => {
|
|
|
203
249
|
:inputmode="type === 'numeric' ? 'numeric' : 'text'"
|
|
204
250
|
autocomplete="one-time-code"
|
|
205
251
|
maxlength="1"
|
|
206
|
-
:disabled="
|
|
252
|
+
:disabled="isDisabled"
|
|
207
253
|
:aria-label="`Digit ${i + 1} of ${totalLength}`"
|
|
254
|
+
:aria-invalid="hasError || undefined"
|
|
255
|
+
:aria-describedby="errorMessage || hint ? messageId : undefined"
|
|
208
256
|
:class="boxClasses"
|
|
209
257
|
@input="onInput(i, $event)"
|
|
210
258
|
@keydown="onKeydown(i, $event)"
|
|
@@ -219,7 +267,7 @@ const boxClasses = computed(() => {
|
|
|
219
267
|
</template>
|
|
220
268
|
</div>
|
|
221
269
|
|
|
222
|
-
<p v-if="
|
|
223
|
-
<p v-else-if="hint" class="px-1 text-body-small text-on-surface-variant">{{ hint }}</p>
|
|
270
|
+
<p v-if="errorMessage" :id="messageId" role="alert" class="px-1 text-body-small text-error">{{ errorMessage }}</p>
|
|
271
|
+
<p v-else-if="hint" :id="messageId" class="px-1 text-body-small text-on-surface-variant">{{ hint }}</p>
|
|
224
272
|
</div>
|
|
225
273
|
</template>
|
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
* A group of radio buttons sharing a single selection, column or row layout.
|
|
4
4
|
*
|
|
5
5
|
* @event update:modelValue Emitted with the selected option's value.
|
|
6
|
+
* @event blur Emitted when focus leaves the group
|
|
6
7
|
*/
|
|
8
|
+
import { ref } from 'vue'
|
|
7
9
|
import MRadio from './MRadio.vue'
|
|
10
|
+
import { useFieldValidation, useFocusLeave } from '../composables/_useFieldValidation'
|
|
11
|
+
import type { ValidateOn, ValidationRule } from '../composables/validation'
|
|
8
12
|
|
|
9
13
|
interface Option {
|
|
10
14
|
label: string
|
|
@@ -25,14 +29,69 @@ const props = withDefaults(defineProps<{
|
|
|
25
29
|
disabled?: boolean
|
|
26
30
|
/** Radio color */
|
|
27
31
|
color?: 'primary' | 'secondary' | 'tertiary' | 'error'
|
|
32
|
+
/** Error state. A string is also the message */
|
|
33
|
+
error?: boolean | string
|
|
34
|
+
/** Error message shown when `error` is true */
|
|
35
|
+
errorLabel?: string
|
|
36
|
+
/** Marks it as required (asterisk); inside an `MForm` or with `rules`, an option must be picked */
|
|
37
|
+
required?: boolean
|
|
38
|
+
/** Validation rules (functions or a Standard Schema); see `MForm` */
|
|
39
|
+
rules?: ValidationRule | ValidationRule[]
|
|
40
|
+
/** When the rules are checked and shown: on leaving it (default), on change, or only on submit */
|
|
41
|
+
validateOn?: ValidateOn
|
|
42
|
+
/** Wait this long (ms) after the value stops changing before re-checking (one request for an async rule, not one per key). Defaults to its `MForm`'s */
|
|
43
|
+
validateDebounce?: number
|
|
44
|
+
/** The key of this field in its `MForm` */
|
|
45
|
+
name?: string
|
|
28
46
|
}>(), { direction: 'column', disabled: false, color: 'primary' })
|
|
29
47
|
|
|
30
|
-
const emit = defineEmits<{ 'update:modelValue': [unknown] }>()
|
|
48
|
+
const emit = defineEmits<{ 'update:modelValue': [unknown]; blur: [] }>()
|
|
49
|
+
|
|
50
|
+
const rootEl = ref<HTMLElement | null>(null)
|
|
51
|
+
|
|
52
|
+
const validation = useFieldValidation({
|
|
53
|
+
value: () => props.modelValue,
|
|
54
|
+
rules: () => props.rules,
|
|
55
|
+
required: () => props.required,
|
|
56
|
+
error: () => props.error,
|
|
57
|
+
errorLabel: () => props.errorLabel,
|
|
58
|
+
name: () => props.name,
|
|
59
|
+
validateOn: () => props.validateOn,
|
|
60
|
+
validateDebounce: () => props.validateDebounce,
|
|
61
|
+
disabled: () => props.disabled,
|
|
62
|
+
focus: () => { (rootEl.value?.querySelector<HTMLInputElement>('input:checked:not(:disabled)') ?? rootEl.value?.querySelector<HTMLInputElement>('input:not(:disabled)'))?.focus() },
|
|
63
|
+
el: () => rootEl.value,
|
|
64
|
+
setValue: (v) => emit('update:modelValue', v as unknown),
|
|
65
|
+
})
|
|
66
|
+
/** Its own `disabled` or its MForm's */
|
|
67
|
+
const isDisabled = validation.disabled
|
|
68
|
+
const { hasError, message: errorMessage, messageId } = validation
|
|
69
|
+
// Moving between its radios isn't leaving it
|
|
70
|
+
const onFocusOut = useFocusLeave(() => rootEl.value, () => {
|
|
71
|
+
validation.onBlur()
|
|
72
|
+
emit('blur')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
defineExpose({
|
|
76
|
+
/** Checks its rules and shows the result; resolves to whether they pass */
|
|
77
|
+
validate: validation.validate,
|
|
78
|
+
/** Hides its validation error (until the next check) */
|
|
79
|
+
resetValidation: validation.resetValidation,
|
|
80
|
+
})
|
|
31
81
|
</script>
|
|
32
82
|
|
|
33
83
|
<template>
|
|
34
|
-
<div
|
|
35
|
-
|
|
84
|
+
<div
|
|
85
|
+
ref="rootEl"
|
|
86
|
+
class="flex flex-col gap-2"
|
|
87
|
+
role="radiogroup"
|
|
88
|
+
:aria-label="label"
|
|
89
|
+
:aria-required="required || undefined"
|
|
90
|
+
:aria-invalid="hasError || undefined"
|
|
91
|
+
:aria-describedby="errorMessage ? messageId : undefined"
|
|
92
|
+
@focusout="onFocusOut"
|
|
93
|
+
>
|
|
94
|
+
<span v-if="label" class="text-label-large" :class="hasError ? 'text-error' : 'text-on-surface-variant'">{{ label }}<span v-if="required" class="text-error"> *</span></span>
|
|
36
95
|
<div
|
|
37
96
|
class="flex gap-4"
|
|
38
97
|
:class="direction === 'row' ? 'flex-row flex-wrap' : 'flex-col'"
|
|
@@ -44,9 +103,11 @@ const emit = defineEmits<{ 'update:modelValue': [unknown] }>()
|
|
|
44
103
|
:value="opt.value"
|
|
45
104
|
:label="opt.label"
|
|
46
105
|
:color="color"
|
|
47
|
-
:disabled="
|
|
106
|
+
:disabled="isDisabled || !!opt.disabled"
|
|
48
107
|
@update:model-value="emit('update:modelValue', $event)"
|
|
49
108
|
/>
|
|
50
109
|
</div>
|
|
110
|
+
<!-- M3's radio has no error state: the message (and the group label) say so -->
|
|
111
|
+
<p v-if="errorMessage" :id="messageId" role="alert" class="text-body-small text-error">{{ errorMessage }}</p>
|
|
51
112
|
</div>
|
|
52
113
|
</template>
|
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @event update:modelValue Emitted when the user rates by click, drag or keyboard (v-model). Dragging past the
|
|
8
8
|
* first icon emits 0
|
|
9
|
+
* @event blur Emitted when the rating loses focus
|
|
9
10
|
*/
|
|
10
11
|
import { computed, ref } from 'vue'
|
|
12
|
+
import { useFieldValidation, useFocusLeave } from '../composables/_useFieldValidation'
|
|
13
|
+
import type { ValidateOn, ValidationRule } from '../composables/validation'
|
|
11
14
|
import MIcon from './MIcon.vue'
|
|
12
15
|
|
|
13
16
|
// Not part of the official M3 spec — built from M3 primitives instead: filled/outlined
|
|
@@ -33,9 +36,26 @@ const props = withDefaults(defineProps<{
|
|
|
33
36
|
* without this prop
|
|
34
37
|
*/
|
|
35
38
|
halfIncrements?: boolean
|
|
39
|
+
/** Error state. A string is also the message */
|
|
40
|
+
error?: boolean | string
|
|
41
|
+
/** Error message shown when `error` is true */
|
|
42
|
+
errorLabel?: string
|
|
43
|
+
/** Inside an `MForm` or with `rules`, 0 (not rated) fails */
|
|
44
|
+
required?: boolean
|
|
45
|
+
/** Validation rules (functions or a Standard Schema); see `MForm` */
|
|
46
|
+
rules?: ValidationRule | ValidationRule[]
|
|
47
|
+
/** When the rules are checked and shown: on leaving it (default), on change, or only on submit */
|
|
48
|
+
validateOn?: ValidateOn
|
|
49
|
+
/** Wait this long (ms) after the value stops changing before re-checking (one request for an async rule, not one per key). Defaults to its `MForm`'s */
|
|
50
|
+
validateDebounce?: number
|
|
51
|
+
/** The key of this field in its `MForm` */
|
|
52
|
+
name?: string
|
|
36
53
|
}>(), { max: 5, size: 28, color: 'primary', icon: 'star', halfIncrements: false })
|
|
37
54
|
|
|
38
|
-
|
|
55
|
+
// Rating + its message: attributes go on the rating
|
|
56
|
+
defineOptions({ inheritAttrs: false })
|
|
57
|
+
|
|
58
|
+
const emit = defineEmits<{ 'update:modelValue': [number]; blur: [] }>()
|
|
39
59
|
|
|
40
60
|
const ROLE_COLORS: Record<string, string> = {
|
|
41
61
|
primary: 'text-primary',
|
|
@@ -47,10 +67,33 @@ const ROLE_COLORS: Record<string, string> = {
|
|
|
47
67
|
const colorClass = computed(() => ROLE_COLORS[props.color] ?? '')
|
|
48
68
|
const customStyle = computed(() => (props.color in ROLE_COLORS ? undefined : { color: props.color }))
|
|
49
69
|
|
|
50
|
-
const interactive = computed(() => !props.readonly && !
|
|
70
|
+
const interactive = computed(() => !props.readonly && !isDisabled.value)
|
|
51
71
|
const step = computed(() => (props.halfIncrements ? 0.5 : 1))
|
|
52
72
|
|
|
53
73
|
const rootEl = ref<HTMLElement | null>(null)
|
|
74
|
+
|
|
75
|
+
const validation = useFieldValidation({
|
|
76
|
+
value: () => props.modelValue,
|
|
77
|
+
rules: () => props.rules,
|
|
78
|
+
required: () => props.required,
|
|
79
|
+
error: () => props.error,
|
|
80
|
+
errorLabel: () => props.errorLabel,
|
|
81
|
+
name: () => props.name,
|
|
82
|
+
validateOn: () => props.validateOn,
|
|
83
|
+
validateDebounce: () => props.validateDebounce,
|
|
84
|
+
disabled: () => props.disabled || props.readonly,
|
|
85
|
+
focus: () => { rootEl.value?.focus() },
|
|
86
|
+
el: () => rootEl.value,
|
|
87
|
+
setValue: (v) => emit('update:modelValue', v as number),
|
|
88
|
+
isEmpty: (v) => !v
|
|
89
|
+
})
|
|
90
|
+
/** Its own `disabled` or its MForm's */
|
|
91
|
+
const isDisabled = validation.disabled
|
|
92
|
+
const { hasError, message: errorMessage, messageId } = validation
|
|
93
|
+
const onFocusOut = useFocusLeave(() => rootEl.value, () => {
|
|
94
|
+
validation.onBlur()
|
|
95
|
+
emit('blur')
|
|
96
|
+
})
|
|
54
97
|
const itemEls: HTMLElement[] = []
|
|
55
98
|
|
|
56
99
|
// Pointer preview: `value` is what the rating would become, `index` is the item under the
|
|
@@ -160,11 +203,19 @@ function stateLayerClass(i: number) {
|
|
|
160
203
|
}
|
|
161
204
|
|
|
162
205
|
const valueText = computed(() => `${clamp(props.modelValue || 0)} / ${props.max}`)
|
|
206
|
+
|
|
207
|
+
defineExpose({
|
|
208
|
+
/** Checks its rules and shows the result; resolves to whether they pass */
|
|
209
|
+
validate: validation.validate,
|
|
210
|
+
/** Hides its validation error (until the next check) */
|
|
211
|
+
resetValidation: validation.resetValidation,
|
|
212
|
+
})
|
|
163
213
|
</script>
|
|
164
214
|
|
|
165
215
|
<template>
|
|
166
216
|
<div
|
|
167
217
|
ref="rootEl"
|
|
218
|
+
v-bind="$attrs"
|
|
168
219
|
class="inline-flex select-none items-center gap-0.5 rounded-full outline-none ring-secondary focus-visible:ring-2"
|
|
169
220
|
:class="interactive ? 'cursor-pointer touch-pan-y' : 'cursor-default'"
|
|
170
221
|
:role="readonly ? 'img' : 'slider'"
|
|
@@ -174,7 +225,10 @@ const valueText = computed(() => `${clamp(props.modelValue || 0)} / ${props.max}
|
|
|
174
225
|
:aria-valuemax="readonly ? undefined : max"
|
|
175
226
|
:aria-valuenow="readonly ? undefined : clamp(modelValue || 0)"
|
|
176
227
|
:aria-valuetext="readonly ? undefined : valueText"
|
|
177
|
-
:aria-disabled="
|
|
228
|
+
:aria-disabled="isDisabled || undefined"
|
|
229
|
+
:aria-invalid="hasError || undefined"
|
|
230
|
+
:aria-describedby="errorMessage ? messageId : undefined"
|
|
231
|
+
@focusout="onFocusOut"
|
|
178
232
|
@pointerdown="onPointerDown"
|
|
179
233
|
@pointermove="onPointerMove"
|
|
180
234
|
@pointerup="onPointerUp"
|
|
@@ -203,7 +257,7 @@ const valueText = computed(() => `${clamp(props.modelValue || 0)} / ${props.max}
|
|
|
203
257
|
:name="icon"
|
|
204
258
|
:size="size"
|
|
205
259
|
class="absolute end-0 top-0"
|
|
206
|
-
:class="
|
|
260
|
+
:class="isDisabled ? 'text-on-surface/38' : 'text-on-surface-variant'"
|
|
207
261
|
/>
|
|
208
262
|
</span>
|
|
209
263
|
<!-- Filled part (FILL 1 glyph), clipped from the start side — this is what renders
|
|
@@ -213,11 +267,13 @@ const valueText = computed(() => `${clamp(props.modelValue || 0)} / ${props.max}
|
|
|
213
267
|
:name="icon"
|
|
214
268
|
:size="size"
|
|
215
269
|
class="absolute start-0 top-0"
|
|
216
|
-
:class="
|
|
217
|
-
:style="[
|
|
270
|
+
:class="isDisabled ? 'text-on-surface/38' : colorClass"
|
|
271
|
+
:style="[isDisabled ? undefined : customStyle, { fontVariationSettings: `'FILL' 1` }]"
|
|
218
272
|
/>
|
|
219
273
|
</span>
|
|
220
274
|
</span>
|
|
221
275
|
</span>
|
|
222
276
|
</div>
|
|
277
|
+
<!-- Not an M3 component, and M3 has no rating error: the message says so -->
|
|
278
|
+
<p v-if="errorMessage" :id="messageId" role="alert" class="mt-1 text-body-small text-error">{{ errorMessage }}</p>
|
|
223
279
|
</template>
|
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
* and images.
|
|
5
5
|
*
|
|
6
6
|
* @event update:modelValue Emitted with the editor HTML on every content change — powers v-model
|
|
7
|
+
* @event blur Emitted when focus leaves the editor (toolbar and dialogs included)
|
|
7
8
|
*/
|
|
8
9
|
import { ref, watch, onMounted, onBeforeUnmount, shallowRef, computed } from 'vue'
|
|
10
|
+
import { useFieldValidation, useFocusLeave } from '../composables/_useFieldValidation'
|
|
11
|
+
import type { ValidateOn, ValidationRule } from '../composables/validation'
|
|
9
12
|
import MIcon from './MIcon.vue'
|
|
10
13
|
import MMenu from './MMenu.vue'
|
|
11
14
|
import MMenuItem from './MMenuItem.vue'
|
|
@@ -52,6 +55,20 @@ const props = withDefaults(
|
|
|
52
55
|
placeholder?: string
|
|
53
56
|
/** Disables editing */
|
|
54
57
|
disabled?: boolean
|
|
58
|
+
/** Error state. A string is also the message */
|
|
59
|
+
error?: boolean | string
|
|
60
|
+
/** Error message shown when `error` is true */
|
|
61
|
+
errorLabel?: string
|
|
62
|
+
/** Inside an `MForm` or with `rules`, the document must have some text (or an image) */
|
|
63
|
+
required?: boolean
|
|
64
|
+
/** Validation rules (functions or a Standard Schema); see `MForm` */
|
|
65
|
+
rules?: ValidationRule | ValidationRule[]
|
|
66
|
+
/** When the rules are checked and shown: on leaving it (default), on change, or only on submit */
|
|
67
|
+
validateOn?: ValidateOn
|
|
68
|
+
/** Wait this long (ms) after the value stops changing before re-checking (one request for an async rule, not one per key). Defaults to its `MForm`'s */
|
|
69
|
+
validateDebounce?: number
|
|
70
|
+
/** The key of this field in its `MForm` */
|
|
71
|
+
name?: string
|
|
55
72
|
/** Minimum height of the text area (not used with `fill`) */
|
|
56
73
|
minHeight?: string
|
|
57
74
|
/**
|
|
@@ -97,12 +114,42 @@ const l = computed<Required<RichTextEditorLabels>>(() => ({
|
|
|
97
114
|
...props.labels,
|
|
98
115
|
}))
|
|
99
116
|
|
|
100
|
-
|
|
117
|
+
// Editor + its message: attributes go on the editor
|
|
118
|
+
defineOptions({ inheritAttrs: false })
|
|
119
|
+
|
|
120
|
+
const emit = defineEmits<{ 'update:modelValue': [string]; blur: [] }>()
|
|
121
|
+
|
|
122
|
+
/** An empty document is still HTML (`<p></p>`): empty means no text and no image */
|
|
123
|
+
const isBlankHtml = (v: unknown) => !/<(img|hr|iframe|video)\b/i.test(String(v ?? '')) && !String(v ?? '').replace(/<[^>]*>/g, '').replace(/ /g, ' ').trim()
|
|
124
|
+
const rootEl = ref<HTMLElement | null>(null)
|
|
101
125
|
|
|
102
126
|
const ready = ref(false)
|
|
103
127
|
const editorRef = shallowRef<any>(null)
|
|
104
128
|
const editorContainer = ref<HTMLElement | null>(null)
|
|
105
129
|
|
|
130
|
+
const validation = useFieldValidation({
|
|
131
|
+
value: () => props.modelValue,
|
|
132
|
+
rules: () => props.rules,
|
|
133
|
+
required: () => props.required,
|
|
134
|
+
error: () => props.error,
|
|
135
|
+
errorLabel: () => props.errorLabel,
|
|
136
|
+
name: () => props.name,
|
|
137
|
+
validateOn: () => props.validateOn,
|
|
138
|
+
validateDebounce: () => props.validateDebounce,
|
|
139
|
+
disabled: () => props.disabled,
|
|
140
|
+
focus: () => { editorRef.value?.commands.focus() },
|
|
141
|
+
el: () => rootEl.value,
|
|
142
|
+
setValue: (v) => emit('update:modelValue', v as string),
|
|
143
|
+
isEmpty: isBlankHtml
|
|
144
|
+
})
|
|
145
|
+
/** Its own `disabled` or its MForm's */
|
|
146
|
+
const isDisabled = validation.disabled
|
|
147
|
+
const { hasError, message: errorMessage, messageId } = validation
|
|
148
|
+
const onFocusOut = useFocusLeave(() => rootEl.value, () => {
|
|
149
|
+
validation.onBlur()
|
|
150
|
+
emit('blur')
|
|
151
|
+
})
|
|
152
|
+
|
|
106
153
|
interface ToolBtn {
|
|
107
154
|
icon: string
|
|
108
155
|
label: string
|
|
@@ -140,7 +187,7 @@ onMounted(async () => {
|
|
|
140
187
|
const editor = new Editor({
|
|
141
188
|
element: editorContainer.value!,
|
|
142
189
|
content: props.modelValue,
|
|
143
|
-
editable: !
|
|
190
|
+
editable: !isDisabled.value,
|
|
144
191
|
extensions: [
|
|
145
192
|
StarterKit,
|
|
146
193
|
Underline,
|
|
@@ -188,7 +235,7 @@ onMounted(async () => {
|
|
|
188
235
|
if (editor.getHTML() !== val) editor.commands.setContent(val)
|
|
189
236
|
})
|
|
190
237
|
|
|
191
|
-
watch(() =>
|
|
238
|
+
watch(() => isDisabled.value, (v) => editor.setEditable(!v))
|
|
192
239
|
|
|
193
240
|
ready.value = true
|
|
194
241
|
})
|
|
@@ -231,13 +278,25 @@ function confirmImage() {
|
|
|
231
278
|
if (imageUrl.value) editorRef.value?.chain().focus().setImage({ src: imageUrl.value }).run()
|
|
232
279
|
imageDialogOpen.value = false
|
|
233
280
|
}
|
|
281
|
+
|
|
282
|
+
defineExpose({
|
|
283
|
+
/** Checks its rules and shows the result; resolves to whether they pass */
|
|
284
|
+
validate: validation.validate,
|
|
285
|
+
/** Hides its validation error (until the next check) */
|
|
286
|
+
resetValidation: validation.resetValidation,
|
|
287
|
+
})
|
|
234
288
|
</script>
|
|
235
289
|
|
|
236
290
|
<template>
|
|
237
291
|
<div
|
|
292
|
+
ref="rootEl"
|
|
293
|
+
v-bind="$attrs"
|
|
238
294
|
class="overflow-hidden rounded-lg border transition-colors duration-150"
|
|
295
|
+
:aria-invalid="hasError || undefined"
|
|
296
|
+
:aria-describedby="errorMessage ? messageId : undefined"
|
|
297
|
+
@focusout="onFocusOut"
|
|
239
298
|
:class="[
|
|
240
|
-
|
|
299
|
+
isDisabled ? 'border-outline-variant/50 opacity-60' : hasError ? 'border-error' : 'border-outline-variant focus-within:border-primary',
|
|
241
300
|
{ 'flex flex-col': fill },
|
|
242
301
|
]"
|
|
243
302
|
>
|
|
@@ -323,6 +382,7 @@ function confirmImage() {
|
|
|
323
382
|
</template>
|
|
324
383
|
</MDialog>
|
|
325
384
|
</div>
|
|
385
|
+
<p v-if="errorMessage" :id="messageId" role="alert" class="mt-1 px-4 text-body-small text-error">{{ errorMessage }}</p>
|
|
326
386
|
</template>
|
|
327
387
|
|
|
328
388
|
<style scoped>
|
|
@@ -12,10 +12,14 @@ export interface SegmentedOption<V extends string | number = string | number> {
|
|
|
12
12
|
* A row of joined segments for choosing between a small set of related options — single or multi select.
|
|
13
13
|
*
|
|
14
14
|
* @event update:modelValue Emitted on selection change — powers v-model
|
|
15
|
+
* @event blur Emitted when focus leaves the segments
|
|
15
16
|
*/
|
|
17
|
+
import { ref } from 'vue'
|
|
16
18
|
import MIcon from './MIcon.vue'
|
|
19
|
+
import { useFieldValidation, useFocusLeave } from '../composables/_useFieldValidation'
|
|
20
|
+
import type { ValidateOn, ValidationRule } from '../composables/validation'
|
|
17
21
|
|
|
18
|
-
withDefaults(defineProps<{
|
|
22
|
+
const props = withDefaults(defineProps<{
|
|
19
23
|
/** Selected value, or values with `multiSelect` (v-model); typed after the options' values */
|
|
20
24
|
modelValue: M
|
|
21
25
|
/** The options to choose from; see `SegmentedOption`. */
|
|
@@ -26,9 +30,55 @@ withDefaults(defineProps<{
|
|
|
26
30
|
density?: 'default' | 'comfortable' | 'compact'
|
|
27
31
|
/** Selected segment color */
|
|
28
32
|
color?: 'primary' | 'secondary' | 'tertiary'
|
|
33
|
+
/** Error state. A string is also the message */
|
|
34
|
+
error?: boolean | string
|
|
35
|
+
/** Error message shown when `error` is true */
|
|
36
|
+
errorLabel?: string
|
|
37
|
+
/** Inside an `MForm` or with `rules`, a segment must be selected */
|
|
38
|
+
required?: boolean
|
|
39
|
+
/** Validation rules (functions or a Standard Schema); see `MForm` */
|
|
40
|
+
rules?: ValidationRule | ValidationRule[]
|
|
41
|
+
/** When the rules are checked and shown: on leaving it (default), on change, or only on submit */
|
|
42
|
+
validateOn?: ValidateOn
|
|
43
|
+
/** Wait this long (ms) after the value stops changing before re-checking (one request for an async rule, not one per key). Defaults to its `MForm`'s */
|
|
44
|
+
validateDebounce?: number
|
|
45
|
+
/** The key of this field in its `MForm` */
|
|
46
|
+
name?: string
|
|
29
47
|
}>(), { multiSelect: false, density: 'default', color: 'primary' })
|
|
30
48
|
|
|
31
|
-
|
|
49
|
+
// Segments + their message: attributes go on the segments
|
|
50
|
+
defineOptions({ inheritAttrs: false })
|
|
51
|
+
|
|
52
|
+
const emit = defineEmits<{ 'update:modelValue': [M]; blur: [] }>()
|
|
53
|
+
|
|
54
|
+
const rootEl = ref<HTMLElement | null>(null)
|
|
55
|
+
|
|
56
|
+
const validation = useFieldValidation({
|
|
57
|
+
value: () => props.modelValue,
|
|
58
|
+
rules: () => props.rules,
|
|
59
|
+
required: () => props.required,
|
|
60
|
+
error: () => props.error,
|
|
61
|
+
errorLabel: () => props.errorLabel,
|
|
62
|
+
name: () => props.name,
|
|
63
|
+
validateOn: () => props.validateOn,
|
|
64
|
+
validateDebounce: () => props.validateDebounce,
|
|
65
|
+
disabled: () => false,
|
|
66
|
+
focus: () => { rootEl.value?.querySelector<HTMLButtonElement>('button:not(:disabled)')?.focus() },
|
|
67
|
+
el: () => rootEl.value,
|
|
68
|
+
setValue: (v) => emit('update:modelValue', v as M),
|
|
69
|
+
})
|
|
70
|
+
const { hasError, message: errorMessage, messageId } = validation
|
|
71
|
+
const onFocusOut = useFocusLeave(() => rootEl.value, () => {
|
|
72
|
+
validation.onBlur()
|
|
73
|
+
emit('blur')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
defineExpose({
|
|
77
|
+
/** Checks its rules and shows the result; resolves to whether they pass */
|
|
78
|
+
validate: validation.validate,
|
|
79
|
+
/** Hides its validation error (until the next check) */
|
|
80
|
+
resetValidation: validation.resetValidation,
|
|
81
|
+
})
|
|
32
82
|
|
|
33
83
|
function isSelected(value: V, modelValue: M) {
|
|
34
84
|
return Array.isArray(modelValue) ? modelValue.includes(value) : modelValue === value
|
|
@@ -50,8 +100,13 @@ function toggle(opt: SegmentedOption<V>, modelValue: M, multi: boolean) {
|
|
|
50
100
|
|
|
51
101
|
<template>
|
|
52
102
|
<div
|
|
103
|
+
ref="rootEl"
|
|
104
|
+
v-bind="$attrs"
|
|
53
105
|
class="inline-flex overflow-hidden rounded-full border border-outline"
|
|
54
106
|
role="group"
|
|
107
|
+
:aria-invalid="hasError || undefined"
|
|
108
|
+
:aria-describedby="errorMessage ? messageId : undefined"
|
|
109
|
+
@focusout="onFocusOut"
|
|
55
110
|
>
|
|
56
111
|
<button
|
|
57
112
|
v-for="(opt, i) in options"
|
|
@@ -89,4 +144,6 @@ function toggle(opt: SegmentedOption<V>, modelValue: M, multi: boolean) {
|
|
|
89
144
|
<span>{{ opt.label }}</span>
|
|
90
145
|
</button>
|
|
91
146
|
</div>
|
|
147
|
+
<!-- M3's segmented button has no error state: the message says so -->
|
|
148
|
+
<p v-if="errorMessage" :id="messageId" role="alert" class="mt-1 text-body-small text-error">{{ errorMessage }}</p>
|
|
92
149
|
</template>
|