@m3ui-vue/m3ui-vue 1.6.0 → 1.6.2
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 +940 -33
- package/dist/{MButton-CPghlKb0.js → MButton-OQ4wIERQ.js} +2 -2
- package/dist/{MButton-CPghlKb0.js.map → MButton-OQ4wIERQ.js.map} +1 -1
- package/dist/MColorPickerModal-NtkihoK6.js +577 -0
- package/dist/MColorPickerModal-NtkihoK6.js.map +1 -0
- package/dist/{MDialog-X50At1Gk.js → MDialog-DYMnaBlt.js} +3 -3
- package/dist/{MDialog-X50At1Gk.js.map → MDialog-DYMnaBlt.js.map} +1 -1
- package/dist/{MListItem-DVi1j1QI.js → MListItem-D2cNUyzP.js} +211 -168
- package/dist/MListItem-D2cNUyzP.js.map +1 -0
- package/dist/{MLoadingIndicator-vooA3110.js → MLoadingIndicator-DWUj0BAB.js} +2 -2
- package/dist/{MLoadingIndicator-vooA3110.js.map → MLoadingIndicator-DWUj0BAB.js.map} +1 -1
- package/dist/{MMenuItem-CRNZkVVr.js → MMenuItem-BuxYoASE.js} +133 -151
- package/dist/MMenuItem-BuxYoASE.js.map +1 -0
- package/dist/{MSeekBar-BL2W5_rD.js → MSeekBar-C4cn9RIF.js} +2 -2
- package/dist/{MSeekBar-BL2W5_rD.js.map → MSeekBar-C4cn9RIF.js.map} +1 -1
- package/dist/{MSlider-B9NcKTmZ.js → MSlider-BIkA6DiE.js} +2 -2
- package/dist/{MSlider-B9NcKTmZ.js.map → MSlider-BIkA6DiE.js.map} +1 -1
- package/dist/{MSpinner-_XpTRkAg.js → MSpinner-DZkXZJpc.js} +2 -2
- package/dist/{MSpinner-_XpTRkAg.js.map → MSpinner-DZkXZJpc.js.map} +1 -1
- package/dist/{MTextField-DpcPmR5B.js → MTextField-CNH-byir.js} +2 -2
- package/dist/{MTextField-DpcPmR5B.js.map → MTextField-CNH-byir.js.map} +1 -1
- package/dist/MTooltip-CK39Zon4.js +183 -0
- package/dist/MTooltip-CK39Zon4.js.map +1 -0
- package/dist/{_useEscapeStack-C5-BYr8y.js → _popupPosition-nL8SVKPK.js} +20 -2
- package/dist/_popupPosition-nL8SVKPK.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAddressField.vue.d.ts +54 -0
- package/dist/components/MAudioPlayer.vue.d.ts +1 -1
- package/dist/components/MAudioRecorder.vue.d.ts +51 -0
- package/dist/components/MAvailabilityCalendar.vue.d.ts +1 -1
- package/dist/components/MCameraCapture.vue.d.ts +51 -0
- package/dist/components/MCollapse.vue.d.ts +32 -0
- package/dist/components/MCountrySelect.vue.d.ts +41 -0
- package/dist/components/MCronField.vue.d.ts +26 -0
- package/dist/components/MDashboardGrid.vue.d.ts +65 -0
- package/dist/components/MDiffViewer.vue.d.ts +56 -0
- package/dist/components/MExpansionPanel.vue.d.ts +26 -3
- package/dist/components/MFilterBuilder.vue.d.ts +22 -0
- package/dist/components/MFlex.vue.d.ts +1 -1
- package/dist/components/MMapCluster.vue.d.ts +80 -0
- package/dist/components/MMapDraw.vue.d.ts +79 -0
- package/dist/components/MMentionField.vue.d.ts +102 -0
- package/dist/components/MNotificationCenter.vue.d.ts +57 -0
- package/dist/components/MQRScanner.vue.d.ts +52 -0
- package/dist/components/MQuiz.vue.d.ts +1 -1
- package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +1 -1
- package/dist/components/MTimezoneSelect.vue.d.ts +39 -0
- package/dist/components/MToolbar.vue.d.ts +1 -1
- package/dist/components/MVideoPlayer.vue.d.ts +1 -1
- package/dist/components/_MFilterGroup.vue.d.ts +17 -0
- package/dist/composables/_caretPosition.d.ts +6 -0
- package/dist/composables/_useCamera.d.ts +16 -0
- package/dist/composables/_useFollowAnchor.d.ts +15 -0
- package/dist/composables/cron.d.ts +29 -0
- package/dist/composables/dashboardLayout.d.ts +28 -0
- package/dist/composables/filterBuilder.d.ts +55 -0
- package/dist/composables/mapAdapters.d.ts +6 -1
- package/dist/composables/mapSearch.d.ts +1 -0
- package/dist/composables/textDiff.d.ts +24 -0
- package/dist/composables/useLocale.d.ts +108 -0
- package/dist/draw.js +28 -27
- package/dist/draw.js.map +1 -1
- package/dist/flow.js +1 -1
- package/dist/gantt.js +1 -1
- package/dist/index.d.ts +25 -0
- package/dist/locales/index.js +749 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +10444 -7495
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +5 -0
- package/dist/map.js +1509 -617
- package/dist/map.js.map +1 -1
- package/dist/media.js +5 -5
- package/dist/pdf.js +5 -5
- package/dist/rich-text-editor.js +5 -5
- package/dist/styles.css +1 -1
- package/dist/{useLocale-COav9m8C.js → useLocale-DaVSTdm0.js} +108 -1
- package/dist/useLocale-DaVSTdm0.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MAddressField.test.ts +149 -0
- package/src/__tests__/MAudioRecorder.test.ts +125 -0
- package/src/__tests__/MCameraCapture.test.ts +154 -0
- package/src/__tests__/MCountrySelect.test.ts +67 -0
- package/src/__tests__/MCronField.test.ts +100 -0
- package/src/__tests__/MDashboardGrid.test.ts +122 -0
- package/src/__tests__/MDiffViewer.test.ts +68 -0
- package/src/__tests__/MExpansionPanel.test.ts +107 -0
- package/src/__tests__/MFilterBuilder.test.ts +130 -0
- package/src/__tests__/MMapCluster.test.ts +127 -0
- package/src/__tests__/MMapDraw.test.ts +188 -0
- package/src/__tests__/MMapLayers.test.ts +56 -0
- package/src/__tests__/MMentionField.test.ts +163 -0
- package/src/__tests__/MNotificationCenter.test.ts +94 -0
- package/src/__tests__/_fakeMaplibre.ts +14 -3
- package/src/__tests__/attrsFallthrough.test.ts +4 -0
- package/src/__tests__/cron.test.ts +68 -0
- package/src/__tests__/dashboardLayout.test.ts +45 -0
- package/src/__tests__/filterBuilder.test.ts +91 -0
- package/src/__tests__/followAnchor.test.ts +162 -0
- package/src/__tests__/ssr.test.ts +3 -0
- package/src/__tests__/textDiff.test.ts +37 -0
- package/src/components/MAddressField.vue +301 -0
- package/src/components/MAudioRecorder.vue +334 -0
- package/src/components/MAutocomplete.vue +3 -7
- package/src/components/MCameraCapture.vue +156 -0
- package/src/components/MCollapse.vue +91 -0
- package/src/components/MColorPicker.vue +4 -8
- package/src/components/MCountrySelect.vue +89 -0
- package/src/components/MCronField.vue +251 -0
- package/src/components/MDashboardGrid.vue +382 -0
- package/src/components/MDatePicker.vue +10 -7
- package/src/components/MDateRangePicker.vue +10 -7
- package/src/components/MDiffViewer.vue +234 -0
- package/src/components/MExpansionPanel.vue +56 -48
- package/src/components/MFilterBuilder.vue +47 -0
- package/src/components/MMapBaseLayers.vue +29 -28
- package/src/components/MMapCluster.vue +295 -0
- package/src/components/MMapDraw.vue +601 -0
- package/src/components/MMapMeasure.vue +1 -1
- package/src/components/MMapSearch.vue +1 -9
- package/src/components/MMentionField.vue +373 -0
- package/src/components/MMultiAutocomplete.vue +3 -7
- package/src/components/MMultiSelect.vue +3 -7
- package/src/components/MNotificationCenter.vue +252 -0
- package/src/components/MPhoneInput.vue +3 -10
- package/src/components/MQRScanner.vue +177 -0
- package/src/components/MSelect.vue +3 -7
- package/src/components/MTimePicker.vue +10 -7
- package/src/components/MTimezoneSelect.vue +116 -0
- package/src/components/_MFilterGroup.vue +210 -0
- package/src/composables/_caretPosition.ts +44 -0
- package/src/composables/_useCamera.ts +66 -0
- package/src/composables/_useFollowAnchor.ts +109 -0
- package/src/composables/cron.ts +179 -0
- package/src/composables/dashboardLayout.ts +94 -0
- package/src/composables/filterBuilder.ts +195 -0
- package/src/composables/mapAdapters.ts +29 -15
- package/src/composables/mapSearch.ts +10 -0
- package/src/composables/textDiff.ts +106 -0
- package/src/composables/useLocale.ts +215 -0
- package/src/index.ts +25 -0
- package/src/locales/de.ts +107 -0
- package/src/locales/es.ts +107 -0
- package/src/locales/fr.ts +107 -0
- package/src/locales/ja.ts +107 -0
- package/src/locales/ko.ts +107 -0
- package/src/locales/pt.ts +107 -0
- package/src/locales/zh.ts +107 -0
- package/src/map.ts +5 -0
- package/dist/MListItem-DVi1j1QI.js.map +0 -1
- package/dist/MMenuItem-CRNZkVVr.js.map +0 -1
- package/dist/MTooltip-BL3jPYPT.js +0 -754
- package/dist/MTooltip-BL3jPYPT.js.map +0 -1
- package/dist/_useEscapeStack-C5-BYr8y.js.map +0 -1
- package/dist/useLocale-COav9m8C.js.map +0 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A country picker: every country (ISO 3166-1), named in the app's language by the browser (`Intl.DisplayNames`),
|
|
4
|
+
* with its flag, searchable as you type. The v-model is the ISO alpha-2 code (`'AR'`). Built on `MAutocomplete`,
|
|
5
|
+
* so it shares its look, keyboard and `mode="modal"`. Same country list as `MPhoneInput`.
|
|
6
|
+
*
|
|
7
|
+
* @event update:modelValue A country was picked (its code), or cleared (null)
|
|
8
|
+
*/
|
|
9
|
+
import { computed } from 'vue'
|
|
10
|
+
import MAutocomplete from './MAutocomplete.vue'
|
|
11
|
+
import { useLocale } from '../composables/useLocale'
|
|
12
|
+
import { flagEmoji } from '../composables/phoneNumber'
|
|
13
|
+
import { PHONE_COUNTRIES } from '../data/phone-countries'
|
|
14
|
+
|
|
15
|
+
const props = withDefaults(
|
|
16
|
+
defineProps<{
|
|
17
|
+
/** The country's ISO alpha-2 code (v-model), or null */
|
|
18
|
+
modelValue?: string | null
|
|
19
|
+
/** Field label (the locale's "Country" by default) */
|
|
20
|
+
label?: string
|
|
21
|
+
/** Only these countries (codes), in this order */
|
|
22
|
+
only?: string[]
|
|
23
|
+
/** These first, above the rest (e.g. the ones your users pick most) */
|
|
24
|
+
preferred?: string[]
|
|
25
|
+
/** Show the flag emoji before each name (Windows shows the two letters instead) */
|
|
26
|
+
flags?: boolean
|
|
27
|
+
/** Field style */
|
|
28
|
+
variant?: 'filled' | 'outlined'
|
|
29
|
+
/** Dropdown, or a dialog on small screens */
|
|
30
|
+
mode?: 'docked' | 'modal'
|
|
31
|
+
/** Show a clear button */
|
|
32
|
+
clearable?: boolean
|
|
33
|
+
/** Helper text below the field */
|
|
34
|
+
hint?: string
|
|
35
|
+
/** Error state */
|
|
36
|
+
error?: boolean
|
|
37
|
+
/** Error message shown when `error` is true */
|
|
38
|
+
errorLabel?: string
|
|
39
|
+
/** Marks it as required */
|
|
40
|
+
required?: boolean
|
|
41
|
+
/** Disables the field */
|
|
42
|
+
disabled?: boolean
|
|
43
|
+
}>(),
|
|
44
|
+
{ modelValue: null, flags: true, variant: 'filled', mode: 'docked', clearable: false },
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
const emit = defineEmits<{ 'update:modelValue': [code: string | null] }>()
|
|
48
|
+
|
|
49
|
+
const t = useLocale()
|
|
50
|
+
|
|
51
|
+
const names = computed(() => {
|
|
52
|
+
try {
|
|
53
|
+
return new Intl.DisplayNames([t.lang || 'en', 'en'], { type: 'region' })
|
|
54
|
+
} catch {
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
const nameOf = (code: string) => names.value?.of(code) ?? code
|
|
59
|
+
|
|
60
|
+
/** Every country code once (the phone list repeats none, but keep it safe) */
|
|
61
|
+
const ALL = [...new Set(PHONE_COUNTRIES.map((c) => c[0]))]
|
|
62
|
+
|
|
63
|
+
const options = computed(() => {
|
|
64
|
+
const codes = props.only ?? ALL
|
|
65
|
+
const named = codes.map((code) => ({ value: code, name: nameOf(code) }))
|
|
66
|
+
if (!props.only) named.sort((a, b) => a.name.localeCompare(b.name, t.lang || undefined))
|
|
67
|
+
const preferred = (props.preferred ?? []).filter((c) => codes.includes(c))
|
|
68
|
+
const ordered = [...preferred.map((c) => named.find((n) => n.value === c)!), ...named.filter((n) => !preferred.includes(n.value))]
|
|
69
|
+
return ordered.map((n) => ({ value: n.value, label: props.flags ? `${flagEmoji(n.value)} ${n.name}` : n.name }))
|
|
70
|
+
})
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<template>
|
|
74
|
+
<MAutocomplete
|
|
75
|
+
:model-value="modelValue"
|
|
76
|
+
:options="options"
|
|
77
|
+
:label="label ?? t.country"
|
|
78
|
+
:variant="variant"
|
|
79
|
+
:mode="mode"
|
|
80
|
+
:clearable="clearable"
|
|
81
|
+
:hint="hint"
|
|
82
|
+
:error="error"
|
|
83
|
+
:error-label="errorLabel"
|
|
84
|
+
:required="required"
|
|
85
|
+
:disabled="disabled"
|
|
86
|
+
leading-icon="public"
|
|
87
|
+
@update:model-value="(v: unknown) => emit('update:modelValue', (v as string | null) ?? null)"
|
|
88
|
+
/>
|
|
89
|
+
</template>
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A cron expression editor: the five-field expression in a text field, a sentence saying what it means in the app's
|
|
4
|
+
* language ("At 09:00, Monday to Friday"), the next times it runs, and, with `builder`, controls for the common
|
|
5
|
+
* schedules (every few minutes, hourly, daily, weekly on some days, monthly on a day) so nobody has to remember cron.
|
|
6
|
+
* Anything else stays editable as text (Custom). Invalid text shows an error and isn't emitted until it's valid.
|
|
7
|
+
*
|
|
8
|
+
* @event update:modelValue The expression changed (only valid ones)
|
|
9
|
+
*/
|
|
10
|
+
import { computed, ref, watch } from 'vue'
|
|
11
|
+
import MChip from './MChip.vue'
|
|
12
|
+
import MIcon from './MIcon.vue'
|
|
13
|
+
import MNumberField from './MNumberField.vue'
|
|
14
|
+
import MTextField from './MTextField.vue'
|
|
15
|
+
import MTimePicker from './MTimePicker.vue'
|
|
16
|
+
import { useLocale } from '../composables/useLocale'
|
|
17
|
+
import { describeCron, nextCronRuns, parseCron } from '../composables/cron'
|
|
18
|
+
|
|
19
|
+
type Frequency = 'minutes' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'custom'
|
|
20
|
+
|
|
21
|
+
const props = withDefaults(
|
|
22
|
+
defineProps<{
|
|
23
|
+
/** The expression (v-model): `minute hour day-of-month month day-of-week`, or a macro (`@daily`) */
|
|
24
|
+
modelValue: string
|
|
25
|
+
/** Field label (the locale's "Cron expression" by default) */
|
|
26
|
+
label?: string
|
|
27
|
+
/** Show the schedule controls above the expression */
|
|
28
|
+
builder?: boolean
|
|
29
|
+
/** How many upcoming runs to list (0: none) */
|
|
30
|
+
nextRuns?: number
|
|
31
|
+
/** Field style */
|
|
32
|
+
variant?: 'filled' | 'outlined'
|
|
33
|
+
/** Disables it */
|
|
34
|
+
disabled?: boolean
|
|
35
|
+
}>(),
|
|
36
|
+
{ builder: true, nextRuns: 3, variant: 'filled', disabled: false },
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
const emit = defineEmits<{ 'update:modelValue': [expression: string] }>()
|
|
40
|
+
|
|
41
|
+
const t = useLocale()
|
|
42
|
+
const lang = computed(() => t.lang || undefined)
|
|
43
|
+
|
|
44
|
+
// The text field keeps what's typed, valid or not; the v-model only ever gets valid expressions
|
|
45
|
+
const text = ref(props.modelValue)
|
|
46
|
+
watch(() => props.modelValue, (v) => { if (v !== text.value && parseCron(v)) text.value = v })
|
|
47
|
+
const schedule = computed(() => parseCron(text.value))
|
|
48
|
+
const invalid = computed(() => text.value.trim() !== '' && !schedule.value)
|
|
49
|
+
|
|
50
|
+
function onText(v: string | number) {
|
|
51
|
+
text.value = String(v)
|
|
52
|
+
if (parseCron(text.value)) emit('update:modelValue', text.value.trim())
|
|
53
|
+
}
|
|
54
|
+
function set(expression: string) {
|
|
55
|
+
text.value = expression
|
|
56
|
+
emit('update:modelValue', expression)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const summary = computed(() => describeCron(text.value, t))
|
|
60
|
+
const runs = computed(() => (props.nextRuns > 0 && schedule.value ? nextCronRuns(text.value, props.nextRuns) : []))
|
|
61
|
+
const runFormat = computed(() => new Intl.DateTimeFormat(lang.value, { weekday: 'short', day: 'numeric', month: 'short', hour: 'numeric', minute: '2-digit' }))
|
|
62
|
+
|
|
63
|
+
// ── The builder ────────────────────────────────────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
const single = (field: string) => (/^\d+$/.test(field) ? Number(field) : null)
|
|
66
|
+
|
|
67
|
+
/** Which simple schedule the expression is, if any */
|
|
68
|
+
const frequency = computed<Frequency>(() => {
|
|
69
|
+
const s = schedule.value
|
|
70
|
+
if (!s) return 'custom'
|
|
71
|
+
const [m, h, dom, mon, dow] = s.fields as [string, string, string, string, string]
|
|
72
|
+
if (mon !== '*') return 'custom'
|
|
73
|
+
if (/^\*\/\d+$/.test(m) && h === '*' && dom === '*' && dow === '*') return 'minutes'
|
|
74
|
+
if (single(m) === null) return 'custom'
|
|
75
|
+
if (h === '*' && dom === '*' && dow === '*') return 'hourly'
|
|
76
|
+
if (single(h) === null) return 'custom'
|
|
77
|
+
if (dom === '*' && dow === '*') return 'daily'
|
|
78
|
+
if (dom === '*') return 'weekly'
|
|
79
|
+
if (single(dom) !== null && dow === '*') return 'monthly'
|
|
80
|
+
return 'custom'
|
|
81
|
+
})
|
|
82
|
+
// Picking Custom keeps the expression but shows it as such
|
|
83
|
+
const customPicked = ref(false)
|
|
84
|
+
const shown = computed<Frequency>(() => (customPicked.value ? 'custom' : frequency.value))
|
|
85
|
+
|
|
86
|
+
const fields = computed(() => schedule.value?.fields ?? ['0', '9', '*', '*', '*'])
|
|
87
|
+
const minute = computed(() => single(fields.value[0]!) ?? 0)
|
|
88
|
+
const hour = computed(() => single(fields.value[1]!) ?? 9)
|
|
89
|
+
const every = computed(() => Number(/^\*\/(\d+)$/.exec(fields.value[0]!)?.[1] ?? 15))
|
|
90
|
+
const time = computed(() => `${String(hour.value).padStart(2, '0')}:${String(minute.value).padStart(2, '0')}`)
|
|
91
|
+
const dayOfMonth = computed(() => single(fields.value[2]!) ?? 1)
|
|
92
|
+
const weekdays = computed(() => (schedule.value && !schedule.value.any.weekdays ? schedule.value.weekdays : []))
|
|
93
|
+
|
|
94
|
+
function pick(f: Frequency) {
|
|
95
|
+
customPicked.value = f === 'custom'
|
|
96
|
+
const m = minute.value
|
|
97
|
+
const h = hour.value
|
|
98
|
+
if (f === 'minutes') set(`*/${every.value} * * * *`)
|
|
99
|
+
else if (f === 'hourly') set(`${m} * * * *`)
|
|
100
|
+
else if (f === 'daily') set(`${m} ${h} * * *`)
|
|
101
|
+
else if (f === 'weekly') set(`${m} ${h} * * ${weekdays.value.length ? weekdays.value.join(',') : '1-5'}`)
|
|
102
|
+
else if (f === 'monthly') set(`${m} ${h} ${dayOfMonth.value} * *`)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function setTime(v: string | null) {
|
|
106
|
+
if (!v) return
|
|
107
|
+
const [h, m] = v.split(':').map(Number) as [number, number]
|
|
108
|
+
const [, , dom, mon, dow] = fields.value
|
|
109
|
+
set(`${m} ${h} ${dom} ${mon} ${dow}`)
|
|
110
|
+
}
|
|
111
|
+
function setEvery(n: number | null) {
|
|
112
|
+
if (n && n >= 1 && n <= 59) set(`*/${Math.round(n)} * * * *`)
|
|
113
|
+
}
|
|
114
|
+
function setMinute(n: number | null) {
|
|
115
|
+
if (n !== null && n >= 0 && n <= 59) set(`${Math.round(n)} * * * *`)
|
|
116
|
+
}
|
|
117
|
+
function setDay(n: number | null) {
|
|
118
|
+
if (n && n >= 1 && n <= 31) set(`${minute.value} ${hour.value} ${Math.round(n)} * *`)
|
|
119
|
+
}
|
|
120
|
+
function toggleWeekday(d: number) {
|
|
121
|
+
const next = weekdays.value.includes(d) ? weekdays.value.filter((x) => x !== d) : [...weekdays.value, d].sort((a, b) => a - b)
|
|
122
|
+
// At least one day: unticking the last one leaves it
|
|
123
|
+
if (!next.length) return
|
|
124
|
+
set(`${minute.value} ${hour.value} * * ${compactDays(next)}`)
|
|
125
|
+
}
|
|
126
|
+
/** 1,2,3,4,5 → 1-5 */
|
|
127
|
+
function compactDays(days: number[]) {
|
|
128
|
+
const out: string[] = []
|
|
129
|
+
for (let i = 0; i < days.length; i++) {
|
|
130
|
+
let j = i
|
|
131
|
+
while (j + 1 < days.length && days[j + 1] === days[j]! + 1) j++
|
|
132
|
+
out.push(j - i >= 2 ? `${days[i]}-${days[j]}` : days.slice(i, j + 1).join(','))
|
|
133
|
+
i = j
|
|
134
|
+
}
|
|
135
|
+
return out.join(',')
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const FREQS = computed<{ value: Frequency; label: string }[]>(() => [
|
|
139
|
+
{ value: 'minutes', label: t.cronFreqMinutes },
|
|
140
|
+
{ value: 'hourly', label: t.cronFreqHourly },
|
|
141
|
+
{ value: 'daily', label: t.cronFreqDaily },
|
|
142
|
+
{ value: 'weekly', label: t.cronFreqWeekly },
|
|
143
|
+
{ value: 'monthly', label: t.cronFreqMonthly },
|
|
144
|
+
{ value: 'custom', label: t.cronFreqCustom },
|
|
145
|
+
])
|
|
146
|
+
// Monday first, as most calendars outside the US
|
|
147
|
+
const WEEK = [1, 2, 3, 4, 5, 6, 0]
|
|
148
|
+
const dayName = (d: number) => new Intl.DateTimeFormat(lang.value, { weekday: 'short' }).format(new Date(2024, 0, 7 + d))
|
|
149
|
+
</script>
|
|
150
|
+
|
|
151
|
+
<template>
|
|
152
|
+
<div class="m3-cron-field flex flex-col gap-3">
|
|
153
|
+
<template v-if="builder">
|
|
154
|
+
<div class="flex flex-wrap gap-2" role="group" :aria-label="label ?? t.cronExpression">
|
|
155
|
+
<MChip
|
|
156
|
+
v-for="f in FREQS"
|
|
157
|
+
:key="f.value"
|
|
158
|
+
type="filter"
|
|
159
|
+
:selected="shown === f.value"
|
|
160
|
+
:disabled="disabled"
|
|
161
|
+
@click="pick(f.value)"
|
|
162
|
+
>
|
|
163
|
+
{{ f.label }}
|
|
164
|
+
</MChip>
|
|
165
|
+
</div>
|
|
166
|
+
|
|
167
|
+
<div v-if="shown !== 'custom'" class="flex flex-wrap items-start gap-3">
|
|
168
|
+
<MNumberField
|
|
169
|
+
v-if="shown === 'minutes'"
|
|
170
|
+
:model-value="every"
|
|
171
|
+
:label="t.cronEvery"
|
|
172
|
+
:min="1"
|
|
173
|
+
:max="59"
|
|
174
|
+
:variant="variant"
|
|
175
|
+
:disabled="disabled"
|
|
176
|
+
class="w-44"
|
|
177
|
+
@update:model-value="setEvery"
|
|
178
|
+
/>
|
|
179
|
+
<MNumberField
|
|
180
|
+
v-else-if="shown === 'hourly'"
|
|
181
|
+
:model-value="minute"
|
|
182
|
+
:label="t.cronMinute"
|
|
183
|
+
:min="0"
|
|
184
|
+
:max="59"
|
|
185
|
+
:variant="variant"
|
|
186
|
+
:disabled="disabled"
|
|
187
|
+
class="w-44"
|
|
188
|
+
@update:model-value="setMinute"
|
|
189
|
+
/>
|
|
190
|
+
<template v-else>
|
|
191
|
+
<MTimePicker :model-value="time" :label="t.cronTime" :minute-step="1" :disabled="disabled" class="w-44" @update:model-value="setTime" />
|
|
192
|
+
<MNumberField
|
|
193
|
+
v-if="shown === 'monthly'"
|
|
194
|
+
:model-value="dayOfMonth"
|
|
195
|
+
:label="t.cronDayOfMonth"
|
|
196
|
+
:min="1"
|
|
197
|
+
:max="31"
|
|
198
|
+
:variant="variant"
|
|
199
|
+
:disabled="disabled"
|
|
200
|
+
class="w-44"
|
|
201
|
+
@update:model-value="setDay"
|
|
202
|
+
/>
|
|
203
|
+
</template>
|
|
204
|
+
</div>
|
|
205
|
+
|
|
206
|
+
<div v-if="shown === 'weekly'" class="flex flex-wrap gap-2">
|
|
207
|
+
<MChip
|
|
208
|
+
v-for="d in WEEK"
|
|
209
|
+
:key="d"
|
|
210
|
+
type="filter"
|
|
211
|
+
:selected="weekdays.includes(d)"
|
|
212
|
+
:disabled="disabled"
|
|
213
|
+
@click="toggleWeekday(d)"
|
|
214
|
+
>
|
|
215
|
+
{{ dayName(d) }}
|
|
216
|
+
</MChip>
|
|
217
|
+
</div>
|
|
218
|
+
</template>
|
|
219
|
+
|
|
220
|
+
<MTextField
|
|
221
|
+
:model-value="text"
|
|
222
|
+
:label="label ?? t.cronExpression"
|
|
223
|
+
:variant="variant"
|
|
224
|
+
:disabled="disabled"
|
|
225
|
+
:error="invalid"
|
|
226
|
+
:error-label="t.cronInvalid"
|
|
227
|
+
autocomplete="off"
|
|
228
|
+
class="m3-cron-field__input"
|
|
229
|
+
@update:model-value="onText"
|
|
230
|
+
/>
|
|
231
|
+
|
|
232
|
+
<p v-if="summary" class="flex items-start gap-2 text-body-medium text-on-surface" aria-live="polite">
|
|
233
|
+
<MIcon name="schedule" :size="20" class="shrink-0 text-on-surface-variant" />
|
|
234
|
+
<span class="first-letter:uppercase">{{ summary }}</span>
|
|
235
|
+
</p>
|
|
236
|
+
|
|
237
|
+
<div v-if="runs.length" class="flex flex-col gap-1">
|
|
238
|
+
<span class="text-label-medium text-on-surface-variant">{{ t.cronNextRuns }}</span>
|
|
239
|
+
<ul class="flex flex-col gap-0.5 text-body-small text-on-surface-variant">
|
|
240
|
+
<li v-for="r in runs" :key="r.getTime()" class="first-letter:uppercase">{{ runFormat.format(r) }}</li>
|
|
241
|
+
</ul>
|
|
242
|
+
</div>
|
|
243
|
+
</div>
|
|
244
|
+
</template>
|
|
245
|
+
|
|
246
|
+
<style scoped>
|
|
247
|
+
/* The expression in the mono font, its label in the field's */
|
|
248
|
+
.m3-cron-field__input :deep(input) {
|
|
249
|
+
font-family: var(--font-mono);
|
|
250
|
+
}
|
|
251
|
+
</style>
|