@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,334 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Records a voice note with the microphone: a record button, a live waveform and timer while recording (pause,
|
|
4
|
+
* resume, stop, discard), then the recording to play back (play / pause over its own waveform) and use or discard.
|
|
5
|
+
* The recording comes out as a `Blob` with its duration and waveform peaks (`record`, `v-model`), in the format the
|
|
6
|
+
* browser records (WebM/Opus in Chrome and Firefox, MP4/AAC in Safari). `maxDuration` stops it by itself. The
|
|
7
|
+
* microphone is only on while recording. A denied permission or a missing microphone says so. Needs a secure page
|
|
8
|
+
* (https or localhost).
|
|
9
|
+
*
|
|
10
|
+
* @event update:modelValue The recording used, or null after Discard
|
|
11
|
+
* @event record The recording used: `{ blob, url, duration, mimeType, peaks }`
|
|
12
|
+
* @event error The microphone failed: `'denied' | 'unavailable' | 'unsupported' | 'failed'`
|
|
13
|
+
*/
|
|
14
|
+
import { computed, onBeforeUnmount, ref, shallowRef } from 'vue'
|
|
15
|
+
import MIcon from './MIcon.vue'
|
|
16
|
+
import MIconButton from './MIconButton.vue'
|
|
17
|
+
import { useLocale } from '../composables/useLocale'
|
|
18
|
+
|
|
19
|
+
/** A voice note made by `MAudioRecorder`. */
|
|
20
|
+
export interface AudioRecording {
|
|
21
|
+
blob: Blob
|
|
22
|
+
/** An object URL for the blob, to play it (revoked when the recorder is discarded or unmounted) */
|
|
23
|
+
url: string
|
|
24
|
+
/** In seconds */
|
|
25
|
+
duration: number
|
|
26
|
+
mimeType: string
|
|
27
|
+
/** Its waveform, levels 0–1 (`bars` of them), to draw it elsewhere */
|
|
28
|
+
peaks: number[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type MicError = 'denied' | 'unavailable' | 'unsupported' | 'failed'
|
|
32
|
+
|
|
33
|
+
const props = withDefaults(
|
|
34
|
+
defineProps<{
|
|
35
|
+
/** The recording used (v-model), or null */
|
|
36
|
+
modelValue?: AudioRecording | null
|
|
37
|
+
/** Stop by itself after this many seconds (0: no limit) */
|
|
38
|
+
maxDuration?: number
|
|
39
|
+
/** How many bars the waveform has */
|
|
40
|
+
bars?: number
|
|
41
|
+
/** The format to ask for, when the browser can record it */
|
|
42
|
+
mimeType?: string
|
|
43
|
+
/** Skip the review step: a stopped recording is used right away */
|
|
44
|
+
instant?: boolean
|
|
45
|
+
}>(),
|
|
46
|
+
{ modelValue: null, maxDuration: 0, bars: 40, instant: false },
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const emit = defineEmits<{
|
|
50
|
+
'update:modelValue': [recording: AudioRecording | null]
|
|
51
|
+
record: [recording: AudioRecording]
|
|
52
|
+
error: [error: MicError]
|
|
53
|
+
}>()
|
|
54
|
+
|
|
55
|
+
const t = useLocale()
|
|
56
|
+
|
|
57
|
+
const status = ref<'idle' | 'starting' | 'recording' | 'paused' | 'review' | 'error'>('idle')
|
|
58
|
+
const error = ref<MicError | null>(null)
|
|
59
|
+
const elapsed = ref(0)
|
|
60
|
+
const levels = ref<number[]>([])
|
|
61
|
+
const result = shallowRef<AudioRecording | null>(null)
|
|
62
|
+
const playing = ref(false)
|
|
63
|
+
const played = ref(0)
|
|
64
|
+
|
|
65
|
+
let stream: MediaStream | null = null
|
|
66
|
+
let recorder: MediaRecorder | null = null
|
|
67
|
+
let chunks: Blob[] = []
|
|
68
|
+
let audioCtx: AudioContext | null = null
|
|
69
|
+
let analyser: AnalyserNode | null = null
|
|
70
|
+
let sampler: ReturnType<typeof setInterval> | undefined
|
|
71
|
+
let startedAt = 0
|
|
72
|
+
let pausedFor = 0
|
|
73
|
+
let pausedAt = 0
|
|
74
|
+
let all: number[] = []
|
|
75
|
+
let audio: HTMLAudioElement | null = null
|
|
76
|
+
|
|
77
|
+
const fmt = (s: number) => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, '0')}`
|
|
78
|
+
|
|
79
|
+
function pickType(): string | undefined {
|
|
80
|
+
const Rec = typeof MediaRecorder !== 'undefined' ? MediaRecorder : undefined
|
|
81
|
+
const wanted = [props.mimeType, 'audio/webm;codecs=opus', 'audio/mp4', 'audio/ogg;codecs=opus', 'audio/webm'].filter(Boolean) as string[]
|
|
82
|
+
return wanted.find((m) => Rec?.isTypeSupported?.(m))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** `n` peaks out of any number of levels */
|
|
86
|
+
function downsample(values: number[], n: number): number[] {
|
|
87
|
+
if (!values.length) return Array(n).fill(0)
|
|
88
|
+
return Array.from({ length: n }, (_, i) => {
|
|
89
|
+
const a = Math.floor((i * values.length) / n)
|
|
90
|
+
const b = Math.max(a + 1, Math.floor(((i + 1) * values.length) / n))
|
|
91
|
+
return Math.max(...values.slice(a, b))
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function sample() {
|
|
96
|
+
if (status.value !== 'recording') return
|
|
97
|
+
elapsed.value = (performance.now() - startedAt - pausedFor) / 1000
|
|
98
|
+
let level = 0
|
|
99
|
+
if (analyser) {
|
|
100
|
+
const data = new Uint8Array(analyser.fftSize)
|
|
101
|
+
analyser.getByteTimeDomainData(data)
|
|
102
|
+
let sum = 0
|
|
103
|
+
for (const v of data) sum += ((v - 128) / 128) ** 2
|
|
104
|
+
// RMS, boosted so speech fills the bar
|
|
105
|
+
level = Math.min(1, Math.sqrt(sum / data.length) * 3)
|
|
106
|
+
}
|
|
107
|
+
all.push(level)
|
|
108
|
+
levels.value = [...levels.value, level].slice(-props.bars)
|
|
109
|
+
if (props.maxDuration > 0 && elapsed.value >= props.maxDuration) stop()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function start() {
|
|
113
|
+
const media = typeof navigator !== 'undefined' ? navigator.mediaDevices : undefined
|
|
114
|
+
if (!media?.getUserMedia || typeof MediaRecorder === 'undefined') return fail('unsupported')
|
|
115
|
+
discard()
|
|
116
|
+
status.value = 'starting'
|
|
117
|
+
try {
|
|
118
|
+
stream = await media.getUserMedia({ audio: true })
|
|
119
|
+
} catch (e) {
|
|
120
|
+
const name = (e as { name?: string })?.name
|
|
121
|
+
return fail(name === 'NotAllowedError' || name === 'SecurityError' ? 'denied' : name === 'NotFoundError' ? 'unavailable' : 'failed')
|
|
122
|
+
}
|
|
123
|
+
const type = pickType()
|
|
124
|
+
try {
|
|
125
|
+
recorder = new MediaRecorder(stream, type ? { mimeType: type } : undefined)
|
|
126
|
+
} catch {
|
|
127
|
+
return fail('failed')
|
|
128
|
+
}
|
|
129
|
+
chunks = []
|
|
130
|
+
all = []
|
|
131
|
+
levels.value = []
|
|
132
|
+
recorder.ondataavailable = (e) => { if (e.data.size) chunks.push(e.data) }
|
|
133
|
+
recorder.onstop = finish
|
|
134
|
+
try {
|
|
135
|
+
const Ctx = window.AudioContext ?? (window as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext
|
|
136
|
+
if (Ctx) {
|
|
137
|
+
audioCtx = new Ctx()
|
|
138
|
+
analyser = audioCtx.createAnalyser()
|
|
139
|
+
analyser.fftSize = 512
|
|
140
|
+
audioCtx.createMediaStreamSource(stream).connect(analyser)
|
|
141
|
+
}
|
|
142
|
+
} catch {
|
|
143
|
+
analyser = null
|
|
144
|
+
}
|
|
145
|
+
recorder.start(250)
|
|
146
|
+
startedAt = performance.now()
|
|
147
|
+
pausedFor = 0
|
|
148
|
+
elapsed.value = 0
|
|
149
|
+
status.value = 'recording'
|
|
150
|
+
sampler = setInterval(sample, 60)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function fail(kind: MicError) {
|
|
154
|
+
release()
|
|
155
|
+
status.value = 'error'
|
|
156
|
+
error.value = kind
|
|
157
|
+
emit('error', kind)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function pause() {
|
|
161
|
+
if (status.value !== 'recording' || !recorder) return
|
|
162
|
+
recorder.pause()
|
|
163
|
+
pausedAt = performance.now()
|
|
164
|
+
status.value = 'paused'
|
|
165
|
+
}
|
|
166
|
+
function resume() {
|
|
167
|
+
if (status.value !== 'paused' || !recorder) return
|
|
168
|
+
recorder.resume()
|
|
169
|
+
pausedFor += performance.now() - pausedAt
|
|
170
|
+
status.value = 'recording'
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function stop() {
|
|
174
|
+
if (!recorder || (status.value !== 'recording' && status.value !== 'paused')) return
|
|
175
|
+
if (status.value === 'paused') pausedFor += performance.now() - pausedAt
|
|
176
|
+
elapsed.value = (performance.now() - startedAt - pausedFor) / 1000
|
|
177
|
+
clearInterval(sampler)
|
|
178
|
+
recorder.stop()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The recorder stopped: build the recording, let the microphone go */
|
|
182
|
+
function finish() {
|
|
183
|
+
const mimeType = recorder?.mimeType || pickType() || 'audio/webm'
|
|
184
|
+
const blob = new Blob(chunks, { type: mimeType })
|
|
185
|
+
release()
|
|
186
|
+
const rec: AudioRecording = { blob, url: URL.createObjectURL(blob), duration: Math.round(elapsed.value * 10) / 10, mimeType, peaks: downsample(all, props.bars) }
|
|
187
|
+
result.value = rec
|
|
188
|
+
played.value = 0
|
|
189
|
+
if (props.instant) use()
|
|
190
|
+
else status.value = 'review'
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Microphone and analyser off */
|
|
194
|
+
function release() {
|
|
195
|
+
clearInterval(sampler)
|
|
196
|
+
stream?.getTracks().forEach((tr) => tr.stop())
|
|
197
|
+
stream = null
|
|
198
|
+
void audioCtx?.close().catch(() => {})
|
|
199
|
+
audioCtx = null
|
|
200
|
+
analyser = null
|
|
201
|
+
recorder = null
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function use() {
|
|
205
|
+
const rec = result.value
|
|
206
|
+
if (!rec) return
|
|
207
|
+
stopPlayback()
|
|
208
|
+
emit('update:modelValue', rec)
|
|
209
|
+
emit('record', rec)
|
|
210
|
+
status.value = 'idle'
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function discard() {
|
|
214
|
+
stopPlayback()
|
|
215
|
+
if (recorder && (status.value === 'recording' || status.value === 'paused')) {
|
|
216
|
+
recorder.onstop = null
|
|
217
|
+
recorder.stop()
|
|
218
|
+
}
|
|
219
|
+
release()
|
|
220
|
+
if (result.value && result.value.url !== props.modelValue?.url) URL.revokeObjectURL(result.value.url)
|
|
221
|
+
result.value = null
|
|
222
|
+
levels.value = []
|
|
223
|
+
elapsed.value = 0
|
|
224
|
+
if (status.value !== 'starting') status.value = 'idle'
|
|
225
|
+
if (props.modelValue) emit('update:modelValue', null)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ── Playback of the recording under review (or the one in the v-model) ────────────────────────
|
|
229
|
+
|
|
230
|
+
const reviewing = computed(() => (status.value === 'review' ? result.value : status.value === 'idle' ? props.modelValue : null))
|
|
231
|
+
|
|
232
|
+
function togglePlay() {
|
|
233
|
+
const rec = reviewing.value
|
|
234
|
+
if (!rec) return
|
|
235
|
+
if (playing.value) return stopPlayback(false)
|
|
236
|
+
audio ??= new Audio()
|
|
237
|
+
if (audio.src !== rec.url) audio.src = rec.url
|
|
238
|
+
audio.ontimeupdate = () => { played.value = rec.duration ? Math.min(1, audio!.currentTime / rec.duration) : 0 }
|
|
239
|
+
audio.onended = () => { playing.value = false; played.value = 0 }
|
|
240
|
+
void audio.play().then(() => (playing.value = true), () => (playing.value = false))
|
|
241
|
+
}
|
|
242
|
+
function stopPlayback(rewind = true) {
|
|
243
|
+
audio?.pause()
|
|
244
|
+
if (audio && rewind) audio.currentTime = 0
|
|
245
|
+
playing.value = false
|
|
246
|
+
if (rewind) played.value = 0
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
onBeforeUnmount(() => {
|
|
250
|
+
discardOnUnmount()
|
|
251
|
+
})
|
|
252
|
+
function discardOnUnmount() {
|
|
253
|
+
stopPlayback()
|
|
254
|
+
if (recorder && (status.value === 'recording' || status.value === 'paused')) {
|
|
255
|
+
recorder.onstop = null
|
|
256
|
+
recorder.stop()
|
|
257
|
+
}
|
|
258
|
+
release()
|
|
259
|
+
if (result.value && result.value.url !== props.modelValue?.url) URL.revokeObjectURL(result.value.url)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const liveBars = computed(() => {
|
|
263
|
+
const pad = Array(Math.max(0, props.bars - levels.value.length)).fill(0)
|
|
264
|
+
return [...pad, ...levels.value]
|
|
265
|
+
})
|
|
266
|
+
const errorText = computed(() => ({ denied: t.micDenied, unavailable: t.micUnavailable, unsupported: t.micUnsupported, failed: t.micUnavailable })[error.value ?? 'failed'])
|
|
267
|
+
|
|
268
|
+
defineExpose({ start, stop, pause, resume, discard })
|
|
269
|
+
</script>
|
|
270
|
+
|
|
271
|
+
<template>
|
|
272
|
+
<div class="m3-audio-recorder flex min-h-14 items-center gap-2 rounded-full bg-surface-container-high py-2 pl-2 pr-3">
|
|
273
|
+
<!-- Idle: record (and the used recording to play, when there's one) -->
|
|
274
|
+
<template v-if="status === 'idle' || status === 'error' || status === 'starting'">
|
|
275
|
+
<MIconButton
|
|
276
|
+
icon="mic"
|
|
277
|
+
:label="t.recorderStart"
|
|
278
|
+
variant="filled"
|
|
279
|
+
:disabled="status === 'starting'"
|
|
280
|
+
@click="start"
|
|
281
|
+
/>
|
|
282
|
+
<template v-if="status === 'error'">
|
|
283
|
+
<MIcon name="mic_off" :size="20" class="shrink-0 text-error" />
|
|
284
|
+
<span class="min-w-0 flex-1 text-body-small text-error" role="alert">{{ errorText }}</span>
|
|
285
|
+
</template>
|
|
286
|
+
<template v-else-if="modelValue">
|
|
287
|
+
<MIconButton :icon="playing ? 'pause' : 'play_arrow'" :label="playing ? t.recorderPausePlayback : t.recorderPlay" @click="togglePlay" />
|
|
288
|
+
<span class="mr-1 flex h-8 min-w-0 flex-1 items-center justify-between gap-px overflow-hidden" aria-hidden="true">
|
|
289
|
+
<span
|
|
290
|
+
v-for="(p, i) in modelValue.peaks"
|
|
291
|
+
:key="i"
|
|
292
|
+
class="min-w-px max-w-[3px] flex-1 rounded-full"
|
|
293
|
+
:class="i / modelValue.peaks.length < played ? 'bg-primary' : 'bg-on-surface-variant/50'"
|
|
294
|
+
:style="{ height: `${Math.max(12, p * 100)}%` }"
|
|
295
|
+
/>
|
|
296
|
+
</span>
|
|
297
|
+
<span class="shrink-0 pl-1 font-mono text-label-medium tabular-nums text-on-surface-variant">{{ fmt(modelValue.duration) }}</span>
|
|
298
|
+
<MIconButton icon="delete" :label="t.recorderDiscard" @click="discard" />
|
|
299
|
+
</template>
|
|
300
|
+
<span v-else class="flex-1 text-body-medium text-on-surface-variant">{{ t.recorderStart }}</span>
|
|
301
|
+
</template>
|
|
302
|
+
|
|
303
|
+
<!-- Recording: discard, live waveform, time, pause / resume, stop -->
|
|
304
|
+
<template v-else-if="status === 'recording' || status === 'paused'">
|
|
305
|
+
<MIconButton icon="delete" :label="t.recorderDiscard" @click="discard" />
|
|
306
|
+
<span class="size-2.5 shrink-0 rounded-full bg-error" :class="status === 'recording' ? 'animate-pulse' : 'opacity-40'" />
|
|
307
|
+
<span class="sr-only" role="status">{{ t.recorderRecording }}</span>
|
|
308
|
+
<span class="mr-1 flex h-8 min-w-0 flex-1 items-center justify-between gap-px overflow-hidden" aria-hidden="true">
|
|
309
|
+
<span v-for="(l, i) in liveBars" :key="i" class="min-w-px max-w-[3px] flex-1 rounded-full bg-primary transition-[height] duration-75" :style="{ height: `${Math.max(8, l * 100)}%` }" />
|
|
310
|
+
</span>
|
|
311
|
+
<span class="shrink-0 pl-1 font-mono text-label-medium tabular-nums text-on-surface" aria-live="off">{{ fmt(elapsed) }}<template v-if="maxDuration"> / {{ fmt(maxDuration) }}</template></span>
|
|
312
|
+
<MIconButton v-if="status === 'recording'" icon="pause" :label="t.recorderPause" @click="pause" />
|
|
313
|
+
<MIconButton v-else icon="mic" :label="t.recorderResume" @click="resume" />
|
|
314
|
+
<MIconButton icon="stop" :label="t.recorderStop" variant="filled" @click="stop" />
|
|
315
|
+
</template>
|
|
316
|
+
|
|
317
|
+
<!-- Review: play it over its waveform, discard or use -->
|
|
318
|
+
<template v-else-if="status === 'review' && result">
|
|
319
|
+
<MIconButton icon="delete" :label="t.recorderDiscard" @click="discard" />
|
|
320
|
+
<MIconButton :icon="playing ? 'pause' : 'play_arrow'" :label="playing ? t.recorderPausePlayback : t.recorderPlay" @click="togglePlay" />
|
|
321
|
+
<span class="mr-1 flex h-8 min-w-0 flex-1 items-center justify-between gap-px overflow-hidden" aria-hidden="true">
|
|
322
|
+
<span
|
|
323
|
+
v-for="(p, i) in result.peaks"
|
|
324
|
+
:key="i"
|
|
325
|
+
class="min-w-px max-w-[3px] flex-1 rounded-full"
|
|
326
|
+
:class="i / result.peaks.length < played ? 'bg-primary' : 'bg-on-surface-variant/50'"
|
|
327
|
+
:style="{ height: `${Math.max(12, p * 100)}%` }"
|
|
328
|
+
/>
|
|
329
|
+
</span>
|
|
330
|
+
<span class="shrink-0 pl-1 font-mono text-label-medium tabular-nums text-on-surface-variant">{{ fmt(result.duration) }}</span>
|
|
331
|
+
<MIconButton icon="send" :label="t.recorderUse" variant="filled" @click="use" />
|
|
332
|
+
</template>
|
|
333
|
+
</div>
|
|
334
|
+
</template>
|
|
@@ -10,6 +10,7 @@ import MIcon from './MIcon.vue'
|
|
|
10
10
|
import MIconButton from './MIconButton.vue'
|
|
11
11
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
12
12
|
import { useLocale } from '../composables/useLocale'
|
|
13
|
+
import { useFollowAnchor } from '../composables/_useFollowAnchor'
|
|
13
14
|
import { useDebounce } from '../composables/useDebounce'
|
|
14
15
|
import type { SelectOption } from './MSelect.vue'
|
|
15
16
|
import { useScrollLock } from '../composables/_useScrollLock'
|
|
@@ -203,11 +204,8 @@ function onOutsideClick(e: MouseEvent) {
|
|
|
203
204
|
if (!fieldEl.value?.contains(t) && !dropdownEl.value?.contains(t)) closeDropdown()
|
|
204
205
|
}
|
|
205
206
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (dropdownEl.value?.contains(e.target as Node)) return
|
|
209
|
-
closeDropdown()
|
|
210
|
-
}
|
|
207
|
+
// Stays on its field while the page or a container scrolls, the window/zoom changes or the field resizes
|
|
208
|
+
useFollowAnchor({ open: () => open.value, anchor: fieldEl, popup: dropdownEl, place: computeDropPos, close: closeDropdown })
|
|
211
209
|
|
|
212
210
|
function onKeydown(e: KeyboardEvent) {
|
|
213
211
|
if (e.key === 'Escape') {
|
|
@@ -263,11 +261,9 @@ function getEnabledIndex(opt: SelectOption): number {
|
|
|
263
261
|
|
|
264
262
|
onMounted(() => {
|
|
265
263
|
document.addEventListener('mousedown', onOutsideClick)
|
|
266
|
-
window.addEventListener('scroll', onScroll, true)
|
|
267
264
|
})
|
|
268
265
|
onUnmounted(() => {
|
|
269
266
|
document.removeEventListener('mousedown', onOutsideClick)
|
|
270
|
-
window.removeEventListener('scroll', onScroll, true)
|
|
271
267
|
})
|
|
272
268
|
|
|
273
269
|
// Recompute dropdown position when filtered options change while open
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Takes a photo with the device's camera: a live preview, a shutter button, switching between the front and back
|
|
4
|
+
* cameras, and Retake / Use photo once taken. The photo comes out as a `Blob` and a data URL (`capture`), and as the
|
|
5
|
+
* v-model (the data URL). The camera starts on a button press (or `autostart`), and stops once the photo is used and
|
|
6
|
+
* when unmounted. A denied permission or a missing camera says so, with a button to try again. Needs a secure page
|
|
7
|
+
* (https or localhost).
|
|
8
|
+
*
|
|
9
|
+
* @event update:modelValue The photo used (a data URL), or null after Retake
|
|
10
|
+
* @event capture The photo used: `{ blob, dataUrl, width, height }`
|
|
11
|
+
* @event error The camera failed: `'denied' | 'unavailable' | 'unsupported' | 'failed'`
|
|
12
|
+
*/
|
|
13
|
+
import { computed, onMounted, ref, watch } from 'vue'
|
|
14
|
+
import MButton from './MButton.vue'
|
|
15
|
+
import MIcon from './MIcon.vue'
|
|
16
|
+
import MIconButton from './MIconButton.vue'
|
|
17
|
+
import MSpinner from './MSpinner.vue'
|
|
18
|
+
import { useLocale } from '../composables/useLocale'
|
|
19
|
+
import { useCamera, type CameraError, type CameraFacing } from '../composables/_useCamera'
|
|
20
|
+
|
|
21
|
+
/** A photo taken by `MCameraCapture`. */
|
|
22
|
+
export interface CameraPhoto {
|
|
23
|
+
blob: Blob
|
|
24
|
+
dataUrl: string
|
|
25
|
+
width: number
|
|
26
|
+
height: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const props = withDefaults(
|
|
30
|
+
defineProps<{
|
|
31
|
+
/** The photo used (v-model): a data URL, or null */
|
|
32
|
+
modelValue?: string | null
|
|
33
|
+
/** Which camera to start with: the back one (`environment`) or the selfie one (`user`) */
|
|
34
|
+
facing?: CameraFacing
|
|
35
|
+
/** The preview's aspect ratio (CSS `aspect-ratio`) */
|
|
36
|
+
aspect?: string
|
|
37
|
+
/** The photo's format */
|
|
38
|
+
type?: 'image/jpeg' | 'image/png' | 'image/webp'
|
|
39
|
+
/** JPEG / WebP quality, 0–1 */
|
|
40
|
+
quality?: number
|
|
41
|
+
/** The resolution asked for (the longer side, ideal) */
|
|
42
|
+
resolution?: number
|
|
43
|
+
/** Start the camera on mount instead of on a button press */
|
|
44
|
+
autostart?: boolean
|
|
45
|
+
}>(),
|
|
46
|
+
{ modelValue: null, facing: 'environment', aspect: '4 / 3', type: 'image/jpeg', quality: 0.9, resolution: 1920, autostart: false },
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const emit = defineEmits<{
|
|
50
|
+
'update:modelValue': [dataUrl: string | null]
|
|
51
|
+
capture: [photo: CameraPhoto]
|
|
52
|
+
error: [error: CameraError]
|
|
53
|
+
}>()
|
|
54
|
+
|
|
55
|
+
const t = useLocale()
|
|
56
|
+
const video = ref<HTMLVideoElement>()
|
|
57
|
+
const cam = useCamera(video, { facing: () => props.facing, resolution: () => props.resolution })
|
|
58
|
+
const shot = ref<CameraPhoto | null>(null)
|
|
59
|
+
|
|
60
|
+
watch(cam.error, (e) => { if (e) emit('error', e) })
|
|
61
|
+
|
|
62
|
+
const errorText = computed(() => ({
|
|
63
|
+
denied: t.cameraDenied, unavailable: t.cameraUnavailable, unsupported: t.cameraUnsupported, failed: t.cameraFailed,
|
|
64
|
+
})[cam.error.value ?? 'failed'])
|
|
65
|
+
// The selfie camera previews mirrored, as phones do; the photo isn't
|
|
66
|
+
const mirrored = computed(() => cam.facing.value === 'user')
|
|
67
|
+
|
|
68
|
+
async function capture() {
|
|
69
|
+
const v = video.value
|
|
70
|
+
if (!v || !v.videoWidth) return
|
|
71
|
+
const canvas = document.createElement('canvas')
|
|
72
|
+
canvas.width = v.videoWidth
|
|
73
|
+
canvas.height = v.videoHeight
|
|
74
|
+
canvas.getContext('2d')!.drawImage(v, 0, 0)
|
|
75
|
+
const dataUrl = canvas.toDataURL(props.type, props.quality)
|
|
76
|
+
const blob = await new Promise<Blob | null>((r) => canvas.toBlob(r, props.type, props.quality))
|
|
77
|
+
if (!blob) return
|
|
78
|
+
shot.value = { blob, dataUrl, width: canvas.width, height: canvas.height }
|
|
79
|
+
v.pause()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function retake() {
|
|
83
|
+
shot.value = null
|
|
84
|
+
if (props.modelValue) emit('update:modelValue', null)
|
|
85
|
+
if (cam.status.value === 'live') void video.value?.play().catch(() => {})
|
|
86
|
+
else void cam.start()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function use() {
|
|
90
|
+
if (!shot.value) return
|
|
91
|
+
emit('update:modelValue', shot.value.dataUrl)
|
|
92
|
+
emit('capture', shot.value)
|
|
93
|
+
cam.stop()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
onMounted(() => { if (props.autostart) void cam.start() })
|
|
97
|
+
|
|
98
|
+
defineExpose({
|
|
99
|
+
/** Starts the camera */
|
|
100
|
+
start: () => cam.start(),
|
|
101
|
+
/** Stops the camera */
|
|
102
|
+
stop: cam.stop,
|
|
103
|
+
/** Takes the photo now (as the shutter button) */
|
|
104
|
+
capture,
|
|
105
|
+
})
|
|
106
|
+
</script>
|
|
107
|
+
|
|
108
|
+
<template>
|
|
109
|
+
<div class="m3-camera relative overflow-hidden rounded-xl bg-[#000] text-[#fff]" :style="{ aspectRatio: aspect }">
|
|
110
|
+
<!-- The used photo, once there is one and the camera is off -->
|
|
111
|
+
<img v-if="modelValue && !shot && cam.status.value !== 'live'" :src="modelValue" alt="" class="absolute inset-0 size-full object-cover">
|
|
112
|
+
|
|
113
|
+
<video
|
|
114
|
+
ref="video"
|
|
115
|
+
class="absolute inset-0 size-full object-cover"
|
|
116
|
+
:class="[{ invisible: cam.status.value !== 'live' || shot }, mirrored ? '-scale-x-100' : '']"
|
|
117
|
+
playsinline
|
|
118
|
+
muted
|
|
119
|
+
/>
|
|
120
|
+
<img v-if="shot" :src="shot.dataUrl" alt="" class="absolute inset-0 size-full object-cover">
|
|
121
|
+
|
|
122
|
+
<!-- Off: a button to start (or to start again over the used photo) -->
|
|
123
|
+
<div v-if="cam.status.value === 'idle' && !shot" class="absolute inset-0 grid place-items-center" :class="modelValue ? 'items-end p-4' : ''">
|
|
124
|
+
<MButton variant="tonal" icon="photo_camera" @click="cam.start()">{{ modelValue ? t.cameraRetake : t.cameraStart }}</MButton>
|
|
125
|
+
</div>
|
|
126
|
+
<div v-else-if="cam.status.value === 'starting'" class="absolute inset-0 flex flex-col items-center justify-center gap-3 text-body-medium" role="status">
|
|
127
|
+
<MSpinner :size="32" />{{ t.cameraStarting }}
|
|
128
|
+
</div>
|
|
129
|
+
<div v-else-if="cam.status.value === 'error'" class="absolute inset-0 flex flex-col items-center justify-center gap-3 p-6 text-center" role="alert">
|
|
130
|
+
<MIcon :name="cam.error.value === 'denied' ? 'no_photography' : 'videocam_off'" :size="36" />
|
|
131
|
+
<p class="max-w-72 text-body-medium">{{ errorText }}</p>
|
|
132
|
+
<MButton v-if="cam.error.value !== 'unsupported'" variant="tonal" icon="refresh" @click="cam.start()">{{ t.cameraStart }}</MButton>
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
<!-- Live: switch, shutter -->
|
|
136
|
+
<div v-if="cam.status.value === 'live' && !shot" class="absolute inset-x-0 bottom-0 flex items-center justify-center gap-8 bg-gradient-to-t from-[#000]/60 to-transparent px-4 pb-4 pt-10">
|
|
137
|
+
<MIconButton v-if="cam.canSwitch.value" icon="cameraswitch" :label="t.cameraSwitch" class="text-[#fff]" @click="cam.switchCamera()" />
|
|
138
|
+
<span v-else class="size-10" />
|
|
139
|
+
<button
|
|
140
|
+
type="button"
|
|
141
|
+
class="grid size-16 cursor-pointer place-items-center rounded-full border-4 border-[#fff] transition-transform active:scale-90 focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-[#fff]"
|
|
142
|
+
:aria-label="t.cameraCapture"
|
|
143
|
+
@click="capture"
|
|
144
|
+
>
|
|
145
|
+
<span class="size-12 rounded-full bg-[#fff]" />
|
|
146
|
+
</button>
|
|
147
|
+
<span class="size-10" />
|
|
148
|
+
</div>
|
|
149
|
+
|
|
150
|
+
<!-- Taken: retake or use -->
|
|
151
|
+
<div v-if="shot" class="absolute inset-x-0 bottom-0 flex items-center justify-end gap-2 bg-gradient-to-t from-[#000]/60 to-transparent px-4 pb-4 pt-10">
|
|
152
|
+
<MButton variant="text" class="text-[#fff]" @click="retake">{{ t.cameraRetake }}</MButton>
|
|
153
|
+
<MButton icon="check" @click="use">{{ t.cameraUsePhoto }}</MButton>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
</template>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Shows and hides its content with a height animation to the content's exact size (grid rows 0fr → 1fr, so nothing
|
|
4
|
+
* overshoots or needs measuring). While closed the content is `inert`: no Tab stop, hidden from screen readers.
|
|
5
|
+
* `unmountOnClose` drops it once closed (and mounts it again on open). With reduced motion it switches at once. The
|
|
6
|
+
* building block `MExpansionPanel` uses; reach for it for any "show more" of your own.
|
|
7
|
+
*
|
|
8
|
+
* @slot default The content
|
|
9
|
+
* @event after-open The open animation finished
|
|
10
|
+
* @event after-close The close animation finished (the content is unmounted after it with `unmountOnClose`)
|
|
11
|
+
*/
|
|
12
|
+
import { onBeforeUnmount, ref, watch } from 'vue'
|
|
13
|
+
|
|
14
|
+
const props = withDefaults(
|
|
15
|
+
defineProps<{
|
|
16
|
+
/** Shown or not */
|
|
17
|
+
open: boolean
|
|
18
|
+
/** Unmount the content once closed (it keeps its state otherwise) */
|
|
19
|
+
unmountOnClose?: boolean
|
|
20
|
+
/** The animation's length, in ms */
|
|
21
|
+
duration?: number
|
|
22
|
+
}>(),
|
|
23
|
+
{ unmountOnClose: false, duration: 300 },
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
const emit = defineEmits<{ 'after-open': []; 'after-close': [] }>()
|
|
27
|
+
|
|
28
|
+
const rendered = ref(props.open || !props.unmountOnClose)
|
|
29
|
+
let fallback: ReturnType<typeof setTimeout> | undefined
|
|
30
|
+
|
|
31
|
+
const reduced = () => typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
|
|
32
|
+
|
|
33
|
+
function settle() {
|
|
34
|
+
clearTimeout(fallback)
|
|
35
|
+
fallback = undefined
|
|
36
|
+
if (props.open) emit('after-open')
|
|
37
|
+
else {
|
|
38
|
+
if (props.unmountOnClose) rendered.value = false
|
|
39
|
+
emit('after-close')
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
watch(() => props.open, (open) => {
|
|
44
|
+
if (open) rendered.value = true
|
|
45
|
+
clearTimeout(fallback)
|
|
46
|
+
// No transitionend comes without motion; a timer covers a transition that never runs (hidden, display: none)
|
|
47
|
+
if (reduced() || props.duration <= 0) settle()
|
|
48
|
+
else fallback = setTimeout(settle, props.duration + 50)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
function onEnd(e: TransitionEvent) {
|
|
52
|
+
if (e.target === e.currentTarget && e.propertyName === 'grid-template-rows' && fallback !== undefined) settle()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onBeforeUnmount(() => clearTimeout(fallback))
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<template>
|
|
59
|
+
<div
|
|
60
|
+
class="m3-collapse"
|
|
61
|
+
:class="{ 'm3-collapse--open': open }"
|
|
62
|
+
:style="{ transitionDuration: `${duration}ms` }"
|
|
63
|
+
@transitionend="onEnd"
|
|
64
|
+
>
|
|
65
|
+
<div class="m3-collapse__body" :inert="!open || undefined">
|
|
66
|
+
<slot v-if="rendered" />
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
</template>
|
|
70
|
+
|
|
71
|
+
<style>
|
|
72
|
+
/* Grid rows 0fr → 1fr animate to the content's exact height */
|
|
73
|
+
.m3-collapse {
|
|
74
|
+
display: grid;
|
|
75
|
+
grid-template-rows: 0fr;
|
|
76
|
+
transition-property: grid-template-rows;
|
|
77
|
+
transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
|
|
78
|
+
}
|
|
79
|
+
.m3-collapse--open {
|
|
80
|
+
grid-template-rows: 1fr;
|
|
81
|
+
}
|
|
82
|
+
.m3-collapse__body {
|
|
83
|
+
min-height: 0;
|
|
84
|
+
overflow: hidden;
|
|
85
|
+
}
|
|
86
|
+
@media (prefers-reduced-motion: reduce) {
|
|
87
|
+
.m3-collapse {
|
|
88
|
+
transition: none;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
</style>
|
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @event update:modelValue Emitted with the picked color, live while dragging or typing.
|
|
8
8
|
*/
|
|
9
|
-
import { nextTick,
|
|
9
|
+
import { nextTick, onUnmounted, ref, watch } from 'vue'
|
|
10
10
|
import MIcon from './MIcon.vue'
|
|
11
11
|
import MColorPanel from './_MColorPanel.vue'
|
|
12
12
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
13
13
|
import { useLocale } from '../composables/useLocale'
|
|
14
|
+
import { useFollowAnchor } from '../composables/_useFollowAnchor'
|
|
14
15
|
import { defaultColorPresets, normalizeHex, pushRecentColor } from '../composables/_colorUtils'
|
|
15
16
|
import { OUTLINED_FLOATED_LABEL, vOverflowTitle } from '../composables/_fieldLayout'
|
|
16
17
|
|
|
@@ -90,11 +91,8 @@ function onOut(e: MouseEvent) {
|
|
|
90
91
|
close()
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (panelEl.value?.contains(e.target as Node)) return
|
|
96
|
-
close()
|
|
97
|
-
}
|
|
94
|
+
// Stays on its field while the page or a container scrolls, the window/zoom changes or the field resizes
|
|
95
|
+
useFollowAnchor({ open: () => open.value, anchor: triggerEl, popup: panelEl, place: computeDropPos, close: () => close() })
|
|
98
96
|
|
|
99
97
|
function onPanelKeydown(e: KeyboardEvent) {
|
|
100
98
|
if (e.key === 'Escape') {
|
|
@@ -125,9 +123,7 @@ watch(open, async (v) => {
|
|
|
125
123
|
}
|
|
126
124
|
})
|
|
127
125
|
|
|
128
|
-
onMounted(() => window.addEventListener('scroll', onScroll, true))
|
|
129
126
|
onUnmounted(() => {
|
|
130
|
-
window.removeEventListener('scroll', onScroll, true)
|
|
131
127
|
document.removeEventListener('mousedown', onOut)
|
|
132
128
|
})
|
|
133
129
|
</script>
|