@m3ui-vue/m3ui-vue 1.4.1 → 1.4.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 +251 -9
- package/dist/{MButton-DQMTIlaV.js → MButton-D7M324r9.js} +2 -2
- package/dist/{MButton-DQMTIlaV.js.map → MButton-D7M324r9.js.map} +1 -1
- package/dist/{MDialog-cdgapGfZ.js → MDialog-DuOnNF9s.js} +2 -2
- package/dist/{MDialog-cdgapGfZ.js.map → MDialog-DuOnNF9s.js.map} +1 -1
- package/dist/{MListItem-ZkSGIIrb.js → MListItem-Bb84X6ex.js} +144 -120
- package/dist/{MListItem-ZkSGIIrb.js.map → MListItem-Bb84X6ex.js.map} +1 -1
- package/dist/{MLoadingIndicator-U6_oGx8z.js → MLoadingIndicator-BUGRo2Tu.js} +2 -2
- package/dist/{MLoadingIndicator-U6_oGx8z.js.map → MLoadingIndicator-BUGRo2Tu.js.map} +1 -1
- package/dist/{MSeekBar-DTZVizZg.js → MSeekBar-BQUvUqb9.js} +2 -2
- package/dist/{MSeekBar-DTZVizZg.js.map → MSeekBar-BQUvUqb9.js.map} +1 -1
- package/dist/{MSlider-CqJkEYRZ.js → MSlider-SFdjE1Hy.js} +2 -2
- package/dist/{MSlider-CqJkEYRZ.js.map → MSlider-SFdjE1Hy.js.map} +1 -1
- package/dist/{MSpinner-Btgc-0nb.js → MSpinner-DKGNN64_.js} +2 -2
- package/dist/{MSpinner-Btgc-0nb.js.map → MSpinner-DKGNN64_.js.map} +1 -1
- package/dist/{MTextField-B6M0gJEO.js → MTextField-Utsef6Kk.js} +2 -2
- package/dist/{MTextField-B6M0gJEO.js.map → MTextField-Utsef6Kk.js.map} +1 -1
- package/dist/{MTooltip-Dspji4XG.js → MTooltip-BhTFQ9Z2.js} +4 -4
- package/dist/{MTooltip-Dspji4XG.js.map → MTooltip-BhTFQ9Z2.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAvailabilityCalendar.vue.d.ts +1 -1
- package/dist/components/MCalendarHeatmap.vue.d.ts +120 -0
- package/dist/components/MDatePicker.vue.d.ts +5 -0
- package/dist/components/MDatePickerModal.vue.d.ts +5 -0
- package/dist/components/MDateRangePicker.vue.d.ts +5 -0
- package/dist/components/MDateRangePickerModal.vue.d.ts +5 -0
- package/dist/components/MLightbox.vue.d.ts +1 -1
- package/dist/components/MListItem.vue.d.ts +10 -6
- package/dist/components/MMeterGroup.vue.d.ts +98 -0
- package/dist/components/MPhoneInput.vue.d.ts +72 -0
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MTreeTable.vue.d.ts +1 -1
- package/dist/components/MTypewriter.vue.d.ts +57 -0
- package/dist/components/MVideoPlayer.vue.d.ts +1 -1
- package/dist/components/_MMonthYearButton.vue.d.ts +16 -0
- package/dist/components/_MYearGrid.vue.d.ts +19 -0
- package/dist/composables/_useCalendarMonth.d.ts +7 -0
- package/dist/composables/phoneNumber.d.ts +39 -0
- package/dist/composables/useLocale.d.ts +18 -0
- package/dist/data/phone-countries.d.ts +2 -0
- package/dist/draw.js +2 -2
- package/dist/flow.js +1 -1
- package/dist/gantt.js +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/locales/index.js +63 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +3615 -1999
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +5 -5
- package/dist/media.js +4 -4
- package/dist/pdf.js +4 -4
- package/dist/rich-text-editor.js +4 -4
- package/dist/styles.css +1 -1
- package/dist/{useLocale-DLKJIRFi.js → useLocale-B8YKWg-H.js} +10 -1
- package/dist/useLocale-B8YKWg-H.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MCalendarHeatmap.test.ts +79 -0
- package/src/__tests__/MListItemNestedControl.test.ts +88 -0
- package/src/__tests__/MMeterGroup.test.ts +43 -0
- package/src/__tests__/MPhoneInput.test.ts +97 -0
- package/src/__tests__/MTypewriter.test.ts +50 -0
- package/src/__tests__/calendarMonth.test.ts +104 -0
- package/src/__tests__/ssr.test.ts +4 -0
- package/src/components/MCalendarHeatmap.vue +349 -0
- package/src/components/MDatePicker.vue +74 -34
- package/src/components/MDatePickerModal.vue +79 -36
- package/src/components/MDateRangePicker.vue +73 -33
- package/src/components/MDateRangePickerModal.vue +75 -35
- package/src/components/MListItem.vue +54 -8
- package/src/components/MMeterGroup.vue +196 -0
- package/src/components/MPhoneInput.vue +480 -0
- package/src/components/MTypewriter.vue +195 -0
- package/src/components/_MMonthYearButton.vue +36 -0
- package/src/components/_MYearGrid.vue +106 -0
- package/src/composables/_useCalendarMonth.ts +32 -2
- package/src/composables/phoneNumber.ts +137 -0
- package/src/composables/useLocale.ts +27 -0
- package/src/data/phone-countries.ts +62 -0
- package/src/index.ts +8 -0
- package/src/locales/de.ts +9 -0
- package/src/locales/es.ts +9 -0
- package/src/locales/fr.ts +9 -0
- package/src/locales/ja.ts +9 -0
- package/src/locales/ko.ts +9 -0
- package/src/locales/pt.ts +9 -0
- package/src/locales/zh.ts +9 -0
- package/dist/useLocale-DLKJIRFi.js.map +0 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* Internal (not exported from index.ts): the date pickers' month/year menu button, Compose's YearPickerMenuButton.
|
|
4
|
+
* A pill text button with the month's title and a drop-down arrow that turns over while the year grid is open.
|
|
5
|
+
*/
|
|
6
|
+
import { ref } from 'vue'
|
|
7
|
+
import MIcon from './MIcon.vue'
|
|
8
|
+
|
|
9
|
+
defineProps<{
|
|
10
|
+
/** The month's title ("May 1990") */
|
|
11
|
+
label: string
|
|
12
|
+
expanded: boolean
|
|
13
|
+
/** What the button does: switch to the years, or back to the days */
|
|
14
|
+
action: string
|
|
15
|
+
}>()
|
|
16
|
+
|
|
17
|
+
defineEmits<{ toggle: [] }>()
|
|
18
|
+
|
|
19
|
+
const el = ref<HTMLButtonElement>()
|
|
20
|
+
defineExpose({ focus: () => el.value?.focus() })
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<template>
|
|
24
|
+
<button
|
|
25
|
+
ref="el"
|
|
26
|
+
type="button"
|
|
27
|
+
class="flex h-10 cursor-pointer items-center gap-1 rounded-full pr-2 pl-3 text-title-small font-medium capitalize text-on-surface-variant outline-none transition-colors hover:bg-on-surface-variant/8 focus-visible:ring-2 focus-visible:ring-secondary active:bg-on-surface-variant/10"
|
|
28
|
+
:aria-label="`${label}, ${action}`"
|
|
29
|
+
:aria-expanded="expanded"
|
|
30
|
+
aria-live="polite"
|
|
31
|
+
@click="$emit('toggle')"
|
|
32
|
+
>
|
|
33
|
+
{{ label }}
|
|
34
|
+
<MIcon name="arrow_drop_down" :size="18" class="transition-transform duration-200" :class="expanded && 'rotate-180'" />
|
|
35
|
+
</button>
|
|
36
|
+
</template>
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* Internal (not exported from index.ts): the year grid of the four date pickers, Compose's YearPicker. Laid over
|
|
4
|
+
* the weekday row and the days (the parent wraps them in a `relative` box), as tall as them: 72x36dp pills, 3 per
|
|
5
|
+
* row, 16dp apart (DatePickerModalTokens SelectionYear*, YearsInRow, YearsVerticalPadding). The year on view is
|
|
6
|
+
* filled, the current one outlined, the ones min/max leave no day in disabled (OnSurfaceVariant at 38%).
|
|
7
|
+
*/
|
|
8
|
+
import { computed, nextTick, ref, watch } from 'vue'
|
|
9
|
+
|
|
10
|
+
const props = defineProps<{
|
|
11
|
+
open: boolean
|
|
12
|
+
years: { year: number; disabled: boolean }[]
|
|
13
|
+
/** The year on view: the selected pill */
|
|
14
|
+
viewYear: number
|
|
15
|
+
locale: string
|
|
16
|
+
/** The radiogroup's accessible name */
|
|
17
|
+
label: string
|
|
18
|
+
}>()
|
|
19
|
+
|
|
20
|
+
const emit = defineEmits<{ pick: [year: number] }>()
|
|
21
|
+
|
|
22
|
+
const el = ref<HTMLElement>()
|
|
23
|
+
const currentYear = new Date().getFullYear()
|
|
24
|
+
const yearFormat = computed(() => new Intl.NumberFormat(props.locale, { useGrouping: false }))
|
|
25
|
+
|
|
26
|
+
// The grid's Tab stop (and first focus): the year on view, else the first enabled one
|
|
27
|
+
const tabStop = computed(() => {
|
|
28
|
+
const on = props.years.find((y) => y.year === props.viewYear && !y.disabled)
|
|
29
|
+
return (on ?? props.years.find((y) => !y.disabled))?.year
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// Opens on the year on view, in the middle of the grid, with the focus on it (Compose requests it too)
|
|
33
|
+
watch(() => props.open, async (open) => {
|
|
34
|
+
if (!open) return
|
|
35
|
+
await nextTick()
|
|
36
|
+
const btn = el.value?.querySelector<HTMLElement>('[tabindex="0"]')
|
|
37
|
+
if (!el.value || !btn) return
|
|
38
|
+
el.value.scrollTop = btn.offsetTop - (el.value.clientHeight - btn.offsetHeight) / 2
|
|
39
|
+
btn.focus({ preventScroll: true })
|
|
40
|
+
}, { immediate: true })
|
|
41
|
+
|
|
42
|
+
// Arrows move the focus across the enabled years (a row is 3), Home/End to the ends; Enter/Space pick
|
|
43
|
+
function onKey(e: KeyboardEvent) {
|
|
44
|
+
const buttons = Array.from(el.value?.querySelectorAll<HTMLElement>('button:not(:disabled)') ?? [])
|
|
45
|
+
const i = buttons.indexOf(document.activeElement as HTMLElement)
|
|
46
|
+
if (i < 0) return
|
|
47
|
+
const step: Record<string, number> = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -3, ArrowDown: 3, Home: -i, End: buttons.length - 1 - i }
|
|
48
|
+
if (!(e.key in step)) return
|
|
49
|
+
e.preventDefault()
|
|
50
|
+
buttons[Math.min(buttons.length - 1, Math.max(0, i + step[e.key]!))]?.focus()
|
|
51
|
+
}
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<template>
|
|
55
|
+
<Transition name="m3-date-years">
|
|
56
|
+
<div
|
|
57
|
+
v-if="open"
|
|
58
|
+
ref="el"
|
|
59
|
+
class="absolute inset-0 grid auto-rows-min grid-cols-3 justify-items-center gap-y-4 overflow-y-auto bg-surface-container-high py-2"
|
|
60
|
+
role="radiogroup"
|
|
61
|
+
:aria-label="label"
|
|
62
|
+
@keydown="onKey"
|
|
63
|
+
>
|
|
64
|
+
<button
|
|
65
|
+
v-for="{ year: y, disabled } in years"
|
|
66
|
+
:key="y"
|
|
67
|
+
type="button"
|
|
68
|
+
role="radio"
|
|
69
|
+
:aria-checked="y === viewYear"
|
|
70
|
+
:disabled="disabled"
|
|
71
|
+
:tabindex="y === tabStop ? 0 : -1"
|
|
72
|
+
class="flex h-9 w-[72px] items-center justify-center rounded-full text-body-large outline-none transition-colors focus-visible:ring-2 focus-visible:ring-secondary"
|
|
73
|
+
:class="
|
|
74
|
+
y === viewYear
|
|
75
|
+
? disabled ? 'bg-primary/38 text-on-primary' : 'cursor-pointer bg-primary text-on-primary'
|
|
76
|
+
: disabled
|
|
77
|
+
? 'cursor-not-allowed text-on-surface-variant/38' + (y === currentYear ? ' border border-primary/38' : '')
|
|
78
|
+
: y === currentYear
|
|
79
|
+
? 'cursor-pointer border border-primary text-primary hover:bg-primary/8'
|
|
80
|
+
: 'cursor-pointer text-on-surface-variant hover:bg-on-surface-variant/8'
|
|
81
|
+
"
|
|
82
|
+
@click="emit('pick', y)"
|
|
83
|
+
>
|
|
84
|
+
{{ yearFormat.format(y) }}
|
|
85
|
+
</button>
|
|
86
|
+
</div>
|
|
87
|
+
</Transition>
|
|
88
|
+
</template>
|
|
89
|
+
|
|
90
|
+
<style>
|
|
91
|
+
/* Compose: expandVertically + fadeIn from 0.6 (DefaultEffects) in, shrinkVertically + fadeOut (FastEffects) out */
|
|
92
|
+
.m3-date-years-enter-active {
|
|
93
|
+
transition: clip-path 200ms cubic-bezier(0.2, 0, 0, 1), opacity 200ms cubic-bezier(0.2, 0, 0, 1);
|
|
94
|
+
}
|
|
95
|
+
.m3-date-years-leave-active {
|
|
96
|
+
transition: clip-path 150ms cubic-bezier(0.2, 0, 0, 1), opacity 150ms cubic-bezier(0.2, 0, 0, 1);
|
|
97
|
+
}
|
|
98
|
+
.m3-date-years-enter-from {
|
|
99
|
+
clip-path: inset(0 0 100% 0);
|
|
100
|
+
opacity: 0.6;
|
|
101
|
+
}
|
|
102
|
+
.m3-date-years-leave-to {
|
|
103
|
+
clip-path: inset(0 0 100% 0);
|
|
104
|
+
opacity: 0;
|
|
105
|
+
}
|
|
106
|
+
</style>
|
|
@@ -23,7 +23,13 @@ export function isoDate(y: number, m: number, d: number) {
|
|
|
23
23
|
|
|
24
24
|
export function useCalendarMonth(
|
|
25
25
|
viewDate: Ref<Date>,
|
|
26
|
-
opts: {
|
|
26
|
+
opts: {
|
|
27
|
+
locale: () => string
|
|
28
|
+
min: () => string | undefined
|
|
29
|
+
max: () => string | undefined
|
|
30
|
+
/** First and last year the year grid offers (DatePickerDefaults.YearRange: 1900–2100); min/max disable years in it */
|
|
31
|
+
yearRange?: () => [number, number] | undefined
|
|
32
|
+
},
|
|
27
33
|
) {
|
|
28
34
|
// Narrow weekday names, Monday first (1 Jan 2024 was a Monday)
|
|
29
35
|
const weekdays = computed(() => {
|
|
@@ -70,5 +76,29 @@ export function useCalendarMonth(
|
|
|
70
76
|
const prevMonth = () => shiftMonth(-1)
|
|
71
77
|
const nextMonth = () => shiftMonth(1)
|
|
72
78
|
|
|
73
|
-
|
|
79
|
+
// The year grid (Compose's YearPicker): every year of yearRange, the ones min/max leave no day in disabled
|
|
80
|
+
// (Compose's selectableDates.isSelectableYear)
|
|
81
|
+
const years = computed(() => {
|
|
82
|
+
const [from, to] = opts.yearRange?.() ?? [1900, 2100]
|
|
83
|
+
const min = opts.min()
|
|
84
|
+
const max = opts.max()
|
|
85
|
+
const minYear = min ? Number(min.slice(0, 4)) : -Infinity
|
|
86
|
+
const maxYear = max ? Number(max.slice(0, 4)) : Infinity
|
|
87
|
+
const out: { year: number; disabled: boolean }[] = []
|
|
88
|
+
for (let year = from; year <= to; year++) out.push({ year, disabled: year < minYear || year > maxYear })
|
|
89
|
+
return out
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
// Shows a year keeping the month on view, as Compose's year grid does; brought inside min/max when that month
|
|
93
|
+
// falls outside them (min 15 June 2020 and March on view: June 2020)
|
|
94
|
+
function showYear(year: number) {
|
|
95
|
+
let month = viewDate.value.getMonth()
|
|
96
|
+
const min = opts.min()
|
|
97
|
+
const max = opts.max()
|
|
98
|
+
if (min && isoDate(year, month + 1, 0) < min && Number(min.slice(0, 4)) === year) month = Number(min.slice(5, 7)) - 1
|
|
99
|
+
if (max && isoDate(year, month, 1) > max && Number(max.slice(0, 4)) === year) month = Number(max.slice(5, 7)) - 1
|
|
100
|
+
viewDate.value = new Date(year, month, 1)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return { weekdays, monthLabel, days, isOutOfRange, isToday, prevMonth, nextMonth, years, showYear }
|
|
74
104
|
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { PHONE_COUNTRIES } from '../data/phone-countries'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Phone numbers for MPhoneInput, also exported to show a stored number elsewhere. Not libphonenumber: masks for the
|
|
5
|
+
* countries most used and E.164 rules (a calling code, then at most 15 digits in all) for the rest. A number is
|
|
6
|
+
* "valid" when its length fits one of its country's masks, or any 4 to 14 national digits for a country without
|
|
7
|
+
* masks.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface PhoneCountry {
|
|
11
|
+
/** ISO 3166-1 alpha-2 */
|
|
12
|
+
iso2: string
|
|
13
|
+
/** Calling code, without the + */
|
|
14
|
+
dial: string
|
|
15
|
+
/** National number masks, `#` a digit */
|
|
16
|
+
masks: readonly string[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ParsedPhone {
|
|
20
|
+
country: PhoneCountry
|
|
21
|
+
/** National significant number: digits only, no trunk 0 */
|
|
22
|
+
national: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const BY_ISO = new Map<string, PhoneCountry>()
|
|
26
|
+
const BY_DIAL = new Map<string, PhoneCountry[]>()
|
|
27
|
+
for (const [iso2, dial, masks] of PHONE_COUNTRIES) {
|
|
28
|
+
const c: PhoneCountry = { iso2, dial, masks: masks ?? [] }
|
|
29
|
+
BY_ISO.set(iso2, c)
|
|
30
|
+
BY_DIAL.set(dial, [...(BY_DIAL.get(dial) ?? []), c])
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Every country, in the data's order */
|
|
34
|
+
export function phoneCountries(): PhoneCountry[] {
|
|
35
|
+
return [...BY_ISO.values()]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function phoneCountry(iso2: string): PhoneCountry | undefined {
|
|
39
|
+
return BY_ISO.get(iso2.toUpperCase())
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Italy (and the Vatican, San Marino) keep the leading 0 of landlines in international numbers
|
|
43
|
+
const KEEPS_ZERO = new Set(['IT', 'VA', 'SM'])
|
|
44
|
+
|
|
45
|
+
/** Digits of a national number as typed: no formatting, no trunk 0 */
|
|
46
|
+
export function nationalDigits(input: string, country: PhoneCountry): string {
|
|
47
|
+
let d = input.replace(/\D/g, '')
|
|
48
|
+
if (!KEEPS_ZERO.has(country.iso2)) d = d.replace(/^0+/, '')
|
|
49
|
+
return d.slice(0, 15 - country.dial.length)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Splits an international number (`+541123456789`, `00 54 11...`, `+54 9 11 2345-6789`) into its country and
|
|
54
|
+
* national digits. Where a calling code is shared (+1), `prefer` wins if it has it, else the first listed (US).
|
|
55
|
+
*/
|
|
56
|
+
export function parsePhone(value: string, prefer?: string): ParsedPhone | null {
|
|
57
|
+
let d = value.trim()
|
|
58
|
+
if (d.startsWith('00')) d = '+' + d.slice(2)
|
|
59
|
+
if (!d.startsWith('+')) return null
|
|
60
|
+
d = d.replace(/\D/g, '')
|
|
61
|
+
for (let len = 4; len >= 1; len--) {
|
|
62
|
+
const list = BY_DIAL.get(d.slice(0, len))
|
|
63
|
+
if (!list) continue
|
|
64
|
+
const country = list.find((c) => c.iso2 === prefer?.toUpperCase()) ?? list[0]!
|
|
65
|
+
return { country, national: nationalDigits(d.slice(len), country) }
|
|
66
|
+
}
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// A mask may start with literal digits the number must start with (Argentina's mobiles: "9 ## ####-####")
|
|
71
|
+
const leadOf = (mask: string) => mask.match(/^\d+/)?.[0] ?? ''
|
|
72
|
+
const slots = (mask: string) => mask.split('#').length - 1
|
|
73
|
+
const sizeOf = (mask: string) => leadOf(mask).length + slots(mask)
|
|
74
|
+
|
|
75
|
+
function applyMask(mask: string, digits: string) {
|
|
76
|
+
const lead = leadOf(mask)
|
|
77
|
+
let out = lead
|
|
78
|
+
let i = lead.length
|
|
79
|
+
for (const ch of mask.slice(lead.length)) {
|
|
80
|
+
if (i >= digits.length) break
|
|
81
|
+
out += ch === '#' ? digits[i++] : ch
|
|
82
|
+
}
|
|
83
|
+
return out.trimEnd()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* National digits formatted with the country's masks: the one whose leading digits match (Argentina's 9 for
|
|
88
|
+
* mobiles), else the shortest that holds them. Digits past every mask are appended; countries without masks get
|
|
89
|
+
* groups of three with the last four together.
|
|
90
|
+
*/
|
|
91
|
+
export function formatNational(national: string, country: PhoneCountry): string {
|
|
92
|
+
if (!national) return ''
|
|
93
|
+
const matches = (m: string) => {
|
|
94
|
+
const lead = leadOf(m)
|
|
95
|
+
return national.startsWith(lead) || lead.startsWith(national)
|
|
96
|
+
}
|
|
97
|
+
const masks = [...country.masks].filter(matches).sort((a, b) => leadOf(b).length - leadOf(a).length || sizeOf(a) - sizeOf(b))
|
|
98
|
+
const mask = masks.find((m) => sizeOf(m) >= national.length)
|
|
99
|
+
if (mask) return applyMask(mask, national)
|
|
100
|
+
const longest = masks.sort((a, b) => sizeOf(b) - sizeOf(a))[0]
|
|
101
|
+
if (longest) return applyMask(longest, national) + ' ' + national.slice(sizeOf(longest))
|
|
102
|
+
if (national.length <= 4) return national
|
|
103
|
+
// Groups of three, a lone digit left over joining the group before it (3012 → "3012", not "301 2")
|
|
104
|
+
const groups = national.slice(0, -4).match(/.{1,3}/g) ?? []
|
|
105
|
+
if (groups.length > 1 && groups[groups.length - 1]!.length === 1) groups[groups.length - 2] += groups.pop()!
|
|
106
|
+
return [...groups, national.slice(-4)].join(' ')
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Whether national digits are a plausible full number for the country */
|
|
110
|
+
export function isValidNational(national: string, country: PhoneCountry): boolean {
|
|
111
|
+
if (!national) return false
|
|
112
|
+
if (country.masks.length) return country.masks.some((m) => sizeOf(m) === national.length && national.startsWith(leadOf(m)))
|
|
113
|
+
return national.length >= 4 && national.length + country.dial.length <= 15
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** E.164 (`+541123456789`) from a country and national digits; null when there are none */
|
|
117
|
+
export function toE164(national: string, country: PhoneCountry): string | null {
|
|
118
|
+
return national ? `+${country.dial}${national}` : null
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** A stored E.164 number for display: `+54 11 2345-6789`; the input back when it isn't one */
|
|
122
|
+
export function formatPhone(e164: string, prefer?: string): string {
|
|
123
|
+
const p = parsePhone(e164, prefer)
|
|
124
|
+
if (!p) return e164
|
|
125
|
+
return `+${p.country.dial} ${formatNational(p.national, p.country)}`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Whether an E.164 number is a plausible full number for its country */
|
|
129
|
+
export function isValidPhone(e164: string, prefer?: string): boolean {
|
|
130
|
+
const p = parsePhone(e164, prefer)
|
|
131
|
+
return !!p && isValidNational(p.national, p.country)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The flag emoji of an ISO 3166-1 alpha-2 code (regional indicator letters) */
|
|
135
|
+
export function flagEmoji(iso2: string): string {
|
|
136
|
+
return String.fromCodePoint(...[...iso2.toUpperCase()].map((c) => 0x1f1e6 + c.charCodeAt(0) - 65))
|
|
137
|
+
}
|
|
@@ -45,6 +45,24 @@ export interface M3Locale {
|
|
|
45
45
|
ok: string
|
|
46
46
|
dateToggleInput: string
|
|
47
47
|
dateToggleCalendar: string
|
|
48
|
+
/** The date pickers' month/year button: opens the year grid */
|
|
49
|
+
dateSwitchToYear: string
|
|
50
|
+
/** The same button while the year grid is open: back to the days */
|
|
51
|
+
dateSwitchToDay: string
|
|
52
|
+
/** Calendar heatmap legend, low end */
|
|
53
|
+
heatmapLess: string
|
|
54
|
+
/** Calendar heatmap legend, high end */
|
|
55
|
+
heatmapMore: string
|
|
56
|
+
/** Meter group: what's left of max */
|
|
57
|
+
meterRemaining: string
|
|
58
|
+
/** Meter group header; {used} and {max} are replaced */
|
|
59
|
+
meterUsedOf: string
|
|
60
|
+
/** Phone input: the country selector */
|
|
61
|
+
phoneCountry: string
|
|
62
|
+
/** Phone input: the country search field */
|
|
63
|
+
phoneSearchCountry: string
|
|
64
|
+
/** Phone input: the number doesn't fit its country's length */
|
|
65
|
+
phoneInvalid: string
|
|
48
66
|
dateInputLabel: string
|
|
49
67
|
selectTime: string
|
|
50
68
|
timeHourSelection: string
|
|
@@ -637,6 +655,15 @@ export const defaultLocale: M3Locale = {
|
|
|
637
655
|
ok: 'OK',
|
|
638
656
|
dateToggleInput: 'Switch to text input',
|
|
639
657
|
dateToggleCalendar: 'Switch to calendar',
|
|
658
|
+
dateSwitchToYear: 'Switch to selecting a year',
|
|
659
|
+
dateSwitchToDay: 'Switch to selecting a day',
|
|
660
|
+
heatmapLess: 'Less',
|
|
661
|
+
heatmapMore: 'More',
|
|
662
|
+
meterRemaining: 'Remaining',
|
|
663
|
+
meterUsedOf: '{used} of {max}',
|
|
664
|
+
phoneCountry: 'Country',
|
|
665
|
+
phoneSearchCountry: 'Search country',
|
|
666
|
+
phoneInvalid: 'Incomplete phone number',
|
|
640
667
|
dateInputLabel: 'Date',
|
|
641
668
|
selectTime: 'Select time',
|
|
642
669
|
timeHourSelection: 'Select hour',
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Countries for MPhoneInput: ISO 3166-1 alpha-2 code, ITU calling code and, for the countries most used, national
|
|
3
|
+
* number masks (`#` a digit; several when lengths vary, e.g. Argentina's landlines and mobiles with the 9).
|
|
4
|
+
* Names aren't stored: they come from Intl.DisplayNames in the app's language. Where several countries share a
|
|
5
|
+
* calling code (+1, +7, +44, +61...), the first listed is the one a pasted number lands on.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type PhoneCountryData = readonly [iso2: string, dial: string, masks?: readonly string[]]
|
|
9
|
+
|
|
10
|
+
export const PHONE_COUNTRIES: readonly PhoneCountryData[] = [
|
|
11
|
+
['US', '1', ['(###) ###-####']],
|
|
12
|
+
['CA', '1', ['(###) ###-####']],
|
|
13
|
+
['AG', '1'], ['AI', '1'], ['AS', '1'], ['BB', '1'], ['BM', '1'], ['BS', '1'], ['DM', '1'],
|
|
14
|
+
['DO', '1', ['(###) ###-####']], ['GD', '1'], ['GU', '1'], ['JM', '1'], ['KN', '1'], ['KY', '1'], ['LC', '1'],
|
|
15
|
+
['MP', '1'], ['MS', '1'], ['PR', '1', ['(###) ###-####']], ['SX', '1'], ['TC', '1'], ['TT', '1'], ['VC', '1'],
|
|
16
|
+
['VG', '1'], ['VI', '1'],
|
|
17
|
+
['RU', '7', ['### ###-##-##']],
|
|
18
|
+
['KZ', '7', ['### ###-##-##']],
|
|
19
|
+
['EG', '20'], ['ZA', '27', ['## ### ####']], ['GR', '30', ['### ### ####']], ['NL', '31', ['# ########']],
|
|
20
|
+
['BE', '32', ['### ## ## ##']], ['FR', '33', ['# ## ## ## ##']], ['ES', '34', ['### ## ## ##']], ['HU', '36'],
|
|
21
|
+
['IT', '39'], ['VA', '39'], ['RO', '40', ['### ### ###']], ['CH', '41', ['## ### ## ##']], ['AT', '43'],
|
|
22
|
+
['GB', '44', ['#### ######']], ['GG', '44'], ['IM', '44'], ['JE', '44'],
|
|
23
|
+
['DK', '45', ['## ## ## ##']], ['SE', '46'], ['NO', '47', ['### ## ###']], ['SJ', '47'], ['PL', '48', ['### ### ###']],
|
|
24
|
+
['DE', '49'],
|
|
25
|
+
['PE', '51', ['### ### ###']], ['MX', '52', ['## #### ####']], ['CU', '53', ['# ### ####']],
|
|
26
|
+
['AR', '54', ['## ####-####', '9 ## ####-####']], ['BR', '55', ['(##) ####-####', '(##) #####-####']],
|
|
27
|
+
['CL', '56', ['# #### ####']], ['CO', '57', ['### ### ####']], ['VE', '58', ['### ### ####']],
|
|
28
|
+
['MY', '60'], ['AU', '61', ['### ### ###']], ['CC', '61'], ['CX', '61'], ['ID', '62'], ['PH', '63', ['### ### ####']],
|
|
29
|
+
['NZ', '64'], ['SG', '65', ['#### ####']], ['TH', '66'],
|
|
30
|
+
['JP', '81', ['#-####-####', '##-####-####']], ['KR', '82', ['##-####-####']], ['VN', '84'], ['CN', '86', ['### #### ####']],
|
|
31
|
+
['TR', '90', ['### ### ## ##']], ['IN', '91', ['##### #####']], ['PK', '92'], ['AF', '93'], ['LK', '94'],
|
|
32
|
+
['MM', '95'], ['IR', '98'],
|
|
33
|
+
['SS', '211'], ['MA', '212'], ['EH', '212'], ['DZ', '213'], ['TN', '216'], ['LY', '218'], ['GM', '220'],
|
|
34
|
+
['SN', '221'], ['MR', '222'], ['ML', '223'], ['GN', '224'], ['CI', '225'], ['BF', '226'], ['NE', '227'],
|
|
35
|
+
['TG', '228'], ['BJ', '229'], ['MU', '230'], ['LR', '231'], ['SL', '232'], ['GH', '233'], ['NG', '234'],
|
|
36
|
+
['TD', '235'], ['CF', '236'], ['CM', '237'], ['CV', '238'], ['ST', '239'], ['GQ', '240'], ['GA', '241'],
|
|
37
|
+
['CG', '242'], ['CD', '243'], ['AO', '244'], ['GW', '245'], ['IO', '246'], ['SC', '248'], ['SD', '249'],
|
|
38
|
+
['RW', '250'], ['ET', '251'], ['SO', '252'], ['DJ', '253'], ['KE', '254'], ['TZ', '255'], ['UG', '256'],
|
|
39
|
+
['BI', '257'], ['MZ', '258'], ['ZM', '260'], ['MG', '261'], ['RE', '262'], ['YT', '262'], ['ZW', '263'],
|
|
40
|
+
['NA', '264'], ['MW', '265'], ['LS', '266'], ['BW', '267'], ['SZ', '268'], ['KM', '269'], ['SH', '290'],
|
|
41
|
+
['ER', '291'], ['AW', '297'], ['FO', '298'], ['GL', '299'],
|
|
42
|
+
['GI', '350'], ['PT', '351', ['### ### ###']], ['LU', '352'], ['IE', '353', ['## ### ####']], ['IS', '354'],
|
|
43
|
+
['AL', '355'], ['MT', '356'], ['CY', '357'], ['FI', '358'], ['AX', '358'], ['BG', '359'], ['LT', '370'],
|
|
44
|
+
['LV', '371'], ['EE', '372'], ['MD', '373'], ['AM', '374'], ['BY', '375'], ['AD', '376'], ['MC', '377'],
|
|
45
|
+
['SM', '378'], ['UA', '380', ['## ### ## ##']], ['RS', '381'], ['ME', '382'], ['XK', '383'], ['HR', '385'],
|
|
46
|
+
['SI', '386'], ['BA', '387'], ['MK', '389'], ['CZ', '420', ['### ### ###']], ['SK', '421', ['### ### ###']],
|
|
47
|
+
['LI', '423'],
|
|
48
|
+
['FK', '500'], ['BZ', '501'], ['GT', '502', ['#### ####']], ['SV', '503', ['#### ####']], ['HN', '504', ['####-####']],
|
|
49
|
+
['NI', '505', ['#### ####']], ['CR', '506', ['#### ####']], ['PA', '507', ['####-####']], ['PM', '508'],
|
|
50
|
+
['HT', '509'], ['GP', '590'], ['BL', '590'], ['MF', '590'], ['BO', '591', ['# ### ####']], ['GY', '592'],
|
|
51
|
+
['EC', '593', ['## ### ####']], ['GF', '594'], ['PY', '595', ['### ### ###']], ['MQ', '596'], ['SR', '597'],
|
|
52
|
+
['UY', '598', ['## ### ###']], ['CW', '599'], ['BQ', '599'],
|
|
53
|
+
['TL', '670'], ['NF', '672'], ['BN', '673'], ['NR', '674'], ['PG', '675'], ['TO', '676'], ['SB', '677'],
|
|
54
|
+
['VU', '678'], ['FJ', '679'], ['PW', '680'], ['WF', '681'], ['CK', '682'], ['NU', '683'], ['WS', '685'],
|
|
55
|
+
['KI', '686'], ['NC', '687'], ['TV', '688'], ['PF', '689'], ['TK', '690'], ['FM', '691'], ['MH', '692'],
|
|
56
|
+
['KP', '850'], ['HK', '852', ['#### ####']], ['MO', '853'], ['KH', '855'], ['LA', '856'], ['BD', '880'],
|
|
57
|
+
['TW', '886'],
|
|
58
|
+
['MV', '960'], ['LB', '961'], ['JO', '962'], ['SY', '963'], ['IQ', '964'], ['KW', '965'], ['SA', '966', ['## ### ####']],
|
|
59
|
+
['YE', '967'], ['OM', '968'], ['PS', '970'], ['AE', '971', ['## ### ####']], ['IL', '972', ['##-###-####']],
|
|
60
|
+
['BH', '973'], ['QA', '974'], ['BT', '975'], ['MN', '976'], ['NP', '977'], ['TJ', '992'], ['TM', '993'],
|
|
61
|
+
['AZ', '994'], ['GE', '995'], ['KG', '996'], ['UZ', '998'],
|
|
62
|
+
]
|
package/src/index.ts
CHANGED
|
@@ -75,6 +75,11 @@ export { default as MAlert } from './components/MAlert.vue'
|
|
|
75
75
|
export { default as MAnimatedNumber } from './components/MAnimatedNumber.vue'
|
|
76
76
|
export { default as MCountdown } from './components/MCountdown.vue'
|
|
77
77
|
export type { CountdownUnit, CountdownParts } from './components/MCountdown.vue'
|
|
78
|
+
export { default as MCalendarHeatmap } from './components/MCalendarHeatmap.vue'
|
|
79
|
+
export type { HeatmapDay, HeatmapCell } from './components/MCalendarHeatmap.vue'
|
|
80
|
+
export { default as MMeterGroup } from './components/MMeterGroup.vue'
|
|
81
|
+
export type { MeterItem } from './components/MMeterGroup.vue'
|
|
82
|
+
export { default as MTypewriter } from './components/MTypewriter.vue'
|
|
78
83
|
export { default as MAutocomplete } from './components/MAutocomplete.vue'
|
|
79
84
|
export { default as MAppBar } from './components/MAppBar.vue'
|
|
80
85
|
export { default as MAppBarWithSearch } from './components/MAppBarWithSearch.vue'
|
|
@@ -191,6 +196,9 @@ export { default as MBeforeAfter } from './components/MBeforeAfter.vue'
|
|
|
191
196
|
export { default as MCreditCardInput } from './components/MCreditCardInput.vue'
|
|
192
197
|
export type { CreditCardValue, CreditCardField } from './components/MCreditCardInput.vue'
|
|
193
198
|
export { detectCardBrand, luhnCheck, formatCardNumber, isValidCardNumber, isValidExpiry } from './composables/cardBrand'
|
|
199
|
+
export { default as MPhoneInput } from './components/MPhoneInput.vue'
|
|
200
|
+
export { formatPhone, isValidPhone, parsePhone, phoneCountries, flagEmoji } from './composables/phoneNumber'
|
|
201
|
+
export type { PhoneCountry, ParsedPhone } from './composables/phoneNumber'
|
|
194
202
|
export type { CardBrand, CardBrandInfo } from './composables/cardBrand'
|
|
195
203
|
export { default as MPosKeypad } from './components/MPosKeypad.vue'
|
|
196
204
|
export { default as MOrderTicket } from './components/MOrderTicket.vue'
|
package/src/locales/de.ts
CHANGED
|
@@ -42,6 +42,15 @@ export const deLocale: M3Locale = {
|
|
|
42
42
|
ok: 'OK',
|
|
43
43
|
dateToggleInput: 'Zur Texteingabe wechseln',
|
|
44
44
|
dateToggleCalendar: 'Zum Kalender wechseln',
|
|
45
|
+
dateSwitchToYear: 'Zur Jahresauswahl wechseln',
|
|
46
|
+
dateSwitchToDay: 'Zur Tagesauswahl wechseln',
|
|
47
|
+
heatmapLess: 'Weniger',
|
|
48
|
+
heatmapMore: 'Mehr',
|
|
49
|
+
meterRemaining: 'Verfügbar',
|
|
50
|
+
meterUsedOf: '{used} von {max}',
|
|
51
|
+
phoneCountry: 'Land',
|
|
52
|
+
phoneSearchCountry: 'Land suchen',
|
|
53
|
+
phoneInvalid: 'Unvollständige Telefonnummer',
|
|
45
54
|
dateInputLabel: 'Datum',
|
|
46
55
|
selectTime: 'Uhrzeit auswählen',
|
|
47
56
|
timeHourSelection: 'Stunde auswählen',
|
package/src/locales/es.ts
CHANGED
|
@@ -42,6 +42,15 @@ export const esLocale: M3Locale = {
|
|
|
42
42
|
ok: 'Aceptar',
|
|
43
43
|
dateToggleInput: 'Cambiar a entrada de texto',
|
|
44
44
|
dateToggleCalendar: 'Cambiar a calendario',
|
|
45
|
+
dateSwitchToYear: 'Cambiar a selección de año',
|
|
46
|
+
dateSwitchToDay: 'Cambiar a selección de día',
|
|
47
|
+
heatmapLess: 'Menos',
|
|
48
|
+
heatmapMore: 'Más',
|
|
49
|
+
meterRemaining: 'Disponible',
|
|
50
|
+
meterUsedOf: '{used} de {max}',
|
|
51
|
+
phoneCountry: 'País',
|
|
52
|
+
phoneSearchCountry: 'Buscar país',
|
|
53
|
+
phoneInvalid: 'Número de teléfono incompleto',
|
|
45
54
|
dateInputLabel: 'Fecha',
|
|
46
55
|
selectTime: 'Seleccionar hora',
|
|
47
56
|
timeHourSelection: 'Seleccionar hora',
|
package/src/locales/fr.ts
CHANGED
|
@@ -42,6 +42,15 @@ export const frLocale: M3Locale = {
|
|
|
42
42
|
ok: 'OK',
|
|
43
43
|
dateToggleInput: 'Passer à la saisie de texte',
|
|
44
44
|
dateToggleCalendar: 'Passer au calendrier',
|
|
45
|
+
dateSwitchToYear: "Passer à la sélection de l'année",
|
|
46
|
+
dateSwitchToDay: 'Passer à la sélection du jour',
|
|
47
|
+
heatmapLess: 'Moins',
|
|
48
|
+
heatmapMore: 'Plus',
|
|
49
|
+
meterRemaining: 'Disponible',
|
|
50
|
+
meterUsedOf: '{used} sur {max}',
|
|
51
|
+
phoneCountry: 'Pays',
|
|
52
|
+
phoneSearchCountry: 'Rechercher un pays',
|
|
53
|
+
phoneInvalid: 'Numéro de téléphone incomplet',
|
|
45
54
|
dateInputLabel: 'Date',
|
|
46
55
|
selectTime: "Sélectionner l'heure",
|
|
47
56
|
timeHourSelection: "Sélectionner l'heure",
|
package/src/locales/ja.ts
CHANGED
|
@@ -42,6 +42,15 @@ export const jaLocale: M3Locale = {
|
|
|
42
42
|
ok: 'OK',
|
|
43
43
|
dateToggleInput: 'テキスト入力に切り替え',
|
|
44
44
|
dateToggleCalendar: 'カレンダーに切り替え',
|
|
45
|
+
dateSwitchToYear: '年の選択に切り替え',
|
|
46
|
+
dateSwitchToDay: '日の選択に切り替え',
|
|
47
|
+
heatmapLess: '少ない',
|
|
48
|
+
heatmapMore: '多い',
|
|
49
|
+
meterRemaining: '空き',
|
|
50
|
+
meterUsedOf: '{used} / {max}',
|
|
51
|
+
phoneCountry: '国・地域',
|
|
52
|
+
phoneSearchCountry: '国・地域を検索',
|
|
53
|
+
phoneInvalid: '電話番号が不完全です',
|
|
45
54
|
dateInputLabel: '日付',
|
|
46
55
|
selectTime: '時刻を選択',
|
|
47
56
|
timeHourSelection: '時間を選択',
|
package/src/locales/ko.ts
CHANGED
|
@@ -42,6 +42,15 @@ export const koLocale: M3Locale = {
|
|
|
42
42
|
ok: '확인',
|
|
43
43
|
dateToggleInput: '텍스트 입력으로 전환',
|
|
44
44
|
dateToggleCalendar: '달력으로 전환',
|
|
45
|
+
dateSwitchToYear: '연도 선택으로 전환',
|
|
46
|
+
dateSwitchToDay: '날짜 선택으로 전환',
|
|
47
|
+
heatmapLess: '적음',
|
|
48
|
+
heatmapMore: '많음',
|
|
49
|
+
meterRemaining: '남음',
|
|
50
|
+
meterUsedOf: '{used} / {max}',
|
|
51
|
+
phoneCountry: '국가',
|
|
52
|
+
phoneSearchCountry: '국가 검색',
|
|
53
|
+
phoneInvalid: '전화번호가 완전하지 않습니다',
|
|
45
54
|
dateInputLabel: '날짜',
|
|
46
55
|
selectTime: '시간 선택',
|
|
47
56
|
timeHourSelection: '시간 선택',
|
package/src/locales/pt.ts
CHANGED
|
@@ -42,6 +42,15 @@ export const ptLocale: M3Locale = {
|
|
|
42
42
|
ok: 'OK',
|
|
43
43
|
dateToggleInput: 'Mudar para entrada de texto',
|
|
44
44
|
dateToggleCalendar: 'Mudar para calendário',
|
|
45
|
+
dateSwitchToYear: 'Mudar para seleção de ano',
|
|
46
|
+
dateSwitchToDay: 'Mudar para seleção de dia',
|
|
47
|
+
heatmapLess: 'Menos',
|
|
48
|
+
heatmapMore: 'Mais',
|
|
49
|
+
meterRemaining: 'Disponível',
|
|
50
|
+
meterUsedOf: '{used} de {max}',
|
|
51
|
+
phoneCountry: 'País',
|
|
52
|
+
phoneSearchCountry: 'Pesquisar país',
|
|
53
|
+
phoneInvalid: 'Número de telefone incompleto',
|
|
45
54
|
dateInputLabel: 'Data',
|
|
46
55
|
selectTime: 'Selecionar hora',
|
|
47
56
|
timeHourSelection: 'Selecionar hora',
|
package/src/locales/zh.ts
CHANGED
|
@@ -42,6 +42,15 @@ export const zhLocale: M3Locale = {
|
|
|
42
42
|
ok: '确定',
|
|
43
43
|
dateToggleInput: '切换到文本输入',
|
|
44
44
|
dateToggleCalendar: '切换到日历',
|
|
45
|
+
dateSwitchToYear: '切换到年份选择',
|
|
46
|
+
dateSwitchToDay: '切换到日期选择',
|
|
47
|
+
heatmapLess: '少',
|
|
48
|
+
heatmapMore: '多',
|
|
49
|
+
meterRemaining: '可用',
|
|
50
|
+
meterUsedOf: '{used} / {max}',
|
|
51
|
+
phoneCountry: '国家/地区',
|
|
52
|
+
phoneSearchCountry: '搜索国家/地区',
|
|
53
|
+
phoneInvalid: '电话号码不完整',
|
|
45
54
|
dateInputLabel: '日期',
|
|
46
55
|
selectTime: '选择时间',
|
|
47
56
|
timeHourSelection: '选择小时',
|