@m3ui-vue/m3ui-vue 0.8.5 → 0.8.7
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/README.md +5 -1
- package/dist/{MMenuItem-BXIxwIdM.js → MMenuItem-DmrsQrK7.js} +2 -2
- package/dist/{MMenuItem-BXIxwIdM.js.map → MMenuItem-DmrsQrK7.js.map} +1 -1
- package/dist/chart.js +5 -1
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MBottomSheet.vue.d.ts +3 -3
- package/dist/components/MChatBubble.vue.d.ts +4 -2
- package/dist/components/MCheckbox.vue.d.ts +2 -0
- package/dist/components/MDragDropList.vue.d.ts +19 -6
- package/dist/components/MFileUpload.vue.d.ts +16 -4
- package/dist/components/MKanban.vue.d.ts +15 -6
- package/dist/components/MListDetail.vue.d.ts +31 -0
- package/dist/components/MNavigationRail.vue.d.ts +6 -3
- package/dist/components/MNavigationSuite.vue.d.ts +46 -0
- package/dist/components/MShortNavigationBar.vue.d.ts +6 -1
- package/dist/components/MSideSheet.vue.d.ts +4 -4
- package/dist/components/MSupportingPane.vue.d.ts +34 -0
- package/dist/components/MTransferList.vue.d.ts +57 -30
- package/dist/components/MWindow.vue.d.ts +39 -1
- package/dist/components/_MTransferPane.vue.d.ts +46 -0
- package/dist/composables/_useItemLink.d.ts +30 -0
- package/dist/composables/_useSheetMotion.d.ts +7 -0
- package/dist/composables/useLocale.d.ts +27 -0
- package/dist/composables/useWindowSizeClass.d.ts +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/locales/index.js +196 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +4331 -2945
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/{useLocale-DbREg9Zn.js → useLocale-Bircp823.js} +29 -2
- package/dist/useLocale-Bircp823.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MChart.test.ts +28 -0
- package/src/__tests__/MChatBubble.test.ts +33 -0
- package/src/__tests__/MDragDropList.test.ts +194 -0
- package/src/__tests__/MFileUpload.test.ts +78 -0
- package/src/__tests__/MKanban.test.ts +150 -0
- package/src/__tests__/MPullToRefresh.test.ts +67 -0
- package/src/__tests__/MRating.test.ts +72 -0
- package/src/__tests__/MShortNavigationBar.test.ts +25 -0
- package/src/__tests__/MTransferList.test.ts +149 -0
- package/src/__tests__/MWindow.test.ts +258 -0
- package/src/__tests__/adaptiveLayouts.test.ts +191 -0
- package/src/__tests__/sheets.test.ts +76 -0
- package/src/components/MBottomSheet.vue +11 -57
- package/src/components/MChart.vue +2 -1
- package/src/components/MChatBubble.vue +107 -20
- package/src/components/MCheckbox.vue +3 -0
- package/src/components/MDragDropList.vue +485 -56
- package/src/components/MFileUpload.vue +56 -20
- package/src/components/MKanban.vue +720 -78
- package/src/components/MListDetail.vue +103 -0
- package/src/components/MNavigationRail.vue +48 -31
- package/src/components/MNavigationSuite.vue +89 -0
- package/src/components/MPullToRefresh.vue +101 -35
- package/src/components/MRating.vue +163 -67
- package/src/components/MResult.vue +19 -9
- package/src/components/MShortNavigationBar.vue +37 -17
- package/src/components/MSideSheet.vue +11 -56
- package/src/components/MSupportingPane.vue +70 -0
- package/src/components/MTransferList.vue +174 -137
- package/src/components/MWindow.vue +507 -108
- package/src/components/_MTransferPane.vue +260 -0
- package/src/composables/_useItemLink.ts +19 -0
- package/src/composables/_useSheetMotion.ts +181 -0
- package/src/composables/useLocale.ts +75 -0
- package/src/composables/useWindowSizeClass.ts +93 -0
- package/src/index.ts +6 -0
- package/src/locales/de.ts +37 -0
- package/src/locales/es.ts +37 -0
- package/src/locales/fr.ts +37 -0
- package/src/locales/ja.ts +37 -0
- package/src/locales/ko.ts +37 -0
- package/src/locales/pt.ts +37 -0
- package/src/locales/zh.ts +37 -0
- package/dist/useLocale-DbREg9Zn.js.map +0 -1
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Private helper for MTransferList: one pane (header with select-all, search, list).
|
|
3
|
+
// Both panes render through this so the source and target never drift apart.
|
|
4
|
+
import { computed, onBeforeUpdate, ref } from 'vue'
|
|
5
|
+
import MIcon from './MIcon.vue'
|
|
6
|
+
import MCheckbox from './MCheckbox.vue'
|
|
7
|
+
import type { TransferItem } from './MTransferList.vue'
|
|
8
|
+
|
|
9
|
+
type Value = string | number
|
|
10
|
+
|
|
11
|
+
const props = defineProps<{
|
|
12
|
+
title: string
|
|
13
|
+
items: TransferItem[]
|
|
14
|
+
checked: Set<Value>
|
|
15
|
+
filterable: boolean
|
|
16
|
+
search: string
|
|
17
|
+
searchPlaceholder: string
|
|
18
|
+
emptyText: string
|
|
19
|
+
listHeight: string
|
|
20
|
+
/** Side new items slide in from: the source pane receives from the end, the target from the start. */
|
|
21
|
+
enterFrom: 'start' | 'end'
|
|
22
|
+
selectAllLabel: string
|
|
23
|
+
clearSearchLabel: string
|
|
24
|
+
/** The `#item` slot draws the whole row: no checkbox, padding, min height or background. */
|
|
25
|
+
bare: boolean
|
|
26
|
+
}>()
|
|
27
|
+
|
|
28
|
+
defineSlots<{
|
|
29
|
+
item?: (props: { item: TransferItem; checked: boolean; toggle: () => void; move: () => void }) => unknown
|
|
30
|
+
empty?: () => unknown
|
|
31
|
+
}>()
|
|
32
|
+
|
|
33
|
+
const emit = defineEmits<{
|
|
34
|
+
toggle: [Value]
|
|
35
|
+
toggleAll: []
|
|
36
|
+
activate: [Value]
|
|
37
|
+
'update:search': [string]
|
|
38
|
+
}>()
|
|
39
|
+
|
|
40
|
+
const checkedVisible = computed(() => props.items.filter((i) => props.checked.has(i.value)).length)
|
|
41
|
+
const allChecked = computed(() => props.items.length > 0 && checkedVisible.value === props.items.length)
|
|
42
|
+
const someChecked = computed(() => checkedVisible.value > 0 && !allChecked.value)
|
|
43
|
+
|
|
44
|
+
// Leaving rows go `position: absolute` so the rest can slide up, but with no `top` each one
|
|
45
|
+
// falls back to its static position, which shifts as its siblings leave the flow too: on a
|
|
46
|
+
// "move all" every row collapsed onto the first slot while fading out. Snapshot every row's
|
|
47
|
+
// offset before the update (once the first leave starts, later measurements are already
|
|
48
|
+
// wrong) and pin each leaving row there.
|
|
49
|
+
const listEl = ref<HTMLElement>()
|
|
50
|
+
const rowBoxes = new WeakMap<Element, { top: number; left: number; width: number }>()
|
|
51
|
+
onBeforeUpdate(() => {
|
|
52
|
+
listEl.value?.querySelectorAll<HTMLElement>(':scope > ul > li').forEach((li) =>
|
|
53
|
+
rowBoxes.set(li, { top: li.offsetTop, left: li.offsetLeft, width: li.offsetWidth }),
|
|
54
|
+
)
|
|
55
|
+
})
|
|
56
|
+
function pinLeaving(el: Element) {
|
|
57
|
+
const box = rowBoxes.get(el)
|
|
58
|
+
if (!box) return
|
|
59
|
+
// Left and width too: a `bare` list is padded, so `left: 0; right: 0` would widen the row.
|
|
60
|
+
Object.assign((el as HTMLElement).style, { top: `${box.top}px`, left: `${box.left}px`, width: `${box.width}px`, right: 'auto' })
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Controls inside custom `#item` content (buttons, links, fields, or anything marked with
|
|
64
|
+
// `data-transfer-action`) keep their own clicks and keys instead of toggling or moving the row.
|
|
65
|
+
const CONTROL = 'button, a, select, textarea, [contenteditable], [data-transfer-action], input:not([type="checkbox"])'
|
|
66
|
+
const fromControl = (e: Event) => !!(e.target as Element).closest(CONTROL)
|
|
67
|
+
|
|
68
|
+
function onRowClick(e: MouseEvent, value: Value) {
|
|
69
|
+
// The checkbox handles its own clicks (its label + input); toggling here too is exactly
|
|
70
|
+
// the old double-toggle bug, where the box showed checked but the state wasn't.
|
|
71
|
+
if ((e.target as Element).closest('label') || fromControl(e)) return
|
|
72
|
+
emit('toggle', value)
|
|
73
|
+
}
|
|
74
|
+
function onRowActivate(e: Event, value: Value) {
|
|
75
|
+
if (fromControl(e)) return
|
|
76
|
+
e.preventDefault()
|
|
77
|
+
emit('activate', value)
|
|
78
|
+
}
|
|
79
|
+
// `bare` rows have no checkbox, so the row itself is the focusable checkbox: Space toggles.
|
|
80
|
+
function onRowSpace(e: KeyboardEvent, value: Value) {
|
|
81
|
+
if (!props.bare || e.target !== e.currentTarget) return
|
|
82
|
+
e.preventDefault()
|
|
83
|
+
emit('toggle', value)
|
|
84
|
+
}
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<template>
|
|
88
|
+
<section class="flex min-w-0 flex-1 flex-col overflow-hidden rounded-lg bg-surface-container-low">
|
|
89
|
+
<!-- Header: select-all + title + count -->
|
|
90
|
+
<header class="flex items-center gap-4 px-4 pt-3 pb-2">
|
|
91
|
+
<MCheckbox
|
|
92
|
+
:model-value="allChecked"
|
|
93
|
+
:indeterminate="someChecked"
|
|
94
|
+
:disabled="!items.length"
|
|
95
|
+
:aria-label="selectAllLabel"
|
|
96
|
+
@update:model-value="emit('toggleAll')"
|
|
97
|
+
/>
|
|
98
|
+
<h3 class="min-w-0 flex-1 truncate text-title-medium text-on-surface">{{ title }}</h3>
|
|
99
|
+
<span class="shrink-0 text-label-medium tabular-nums text-on-surface-variant">
|
|
100
|
+
{{ checkedVisible }}/{{ items.length }}
|
|
101
|
+
</span>
|
|
102
|
+
</header>
|
|
103
|
+
|
|
104
|
+
<!-- Search -->
|
|
105
|
+
<div v-if="filterable" class="px-3 pb-2">
|
|
106
|
+
<div
|
|
107
|
+
class="flex h-10 items-center gap-2 rounded-full bg-surface-container-high pr-1 pl-3 focus-within:ring-2 focus-within:ring-secondary"
|
|
108
|
+
>
|
|
109
|
+
<MIcon name="search" :size="20" class="shrink-0 text-on-surface-variant" />
|
|
110
|
+
<input
|
|
111
|
+
:value="search"
|
|
112
|
+
type="text"
|
|
113
|
+
:placeholder="searchPlaceholder"
|
|
114
|
+
class="min-w-0 flex-1 bg-transparent text-body-medium text-on-surface caret-primary outline-none placeholder:text-on-surface-variant"
|
|
115
|
+
@input="emit('update:search', ($event.target as HTMLInputElement).value)"
|
|
116
|
+
/>
|
|
117
|
+
<button
|
|
118
|
+
v-if="search"
|
|
119
|
+
type="button"
|
|
120
|
+
class="flex h-8 w-8 shrink-0 items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8"
|
|
121
|
+
:aria-label="clearSearchLabel"
|
|
122
|
+
@click="emit('update:search', '')"
|
|
123
|
+
>
|
|
124
|
+
<MIcon name="close" :size="18" />
|
|
125
|
+
</button>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<!-- List -->
|
|
130
|
+
<div ref="listEl" class="relative overflow-y-auto overscroll-contain" :style="{ height: listHeight }">
|
|
131
|
+
<TransitionGroup
|
|
132
|
+
tag="ul"
|
|
133
|
+
:name="`m3-tl-${enterFrom}`"
|
|
134
|
+
class="relative"
|
|
135
|
+
:class="bare ? 'flex flex-col gap-2 p-2' : 'py-1'"
|
|
136
|
+
@before-leave="pinLeaving"
|
|
137
|
+
>
|
|
138
|
+
<li
|
|
139
|
+
v-for="item in items"
|
|
140
|
+
:key="item.value"
|
|
141
|
+
class="group relative cursor-pointer select-none"
|
|
142
|
+
:class="bare
|
|
143
|
+
? 'rounded-md outline-none focus-visible:ring-2 focus-visible:ring-secondary'
|
|
144
|
+
: ['flex min-h-14 items-center gap-4 px-4 py-2 transition-colors duration-150', checked.has(item.value) ? 'bg-secondary-container' : '']"
|
|
145
|
+
:tabindex="bare ? 0 : undefined"
|
|
146
|
+
:role="bare ? 'checkbox' : undefined"
|
|
147
|
+
:aria-checked="bare ? checked.has(item.value) : undefined"
|
|
148
|
+
:aria-label="bare ? item.label : undefined"
|
|
149
|
+
@click="onRowClick($event, item.value)"
|
|
150
|
+
@dblclick="onRowActivate($event, item.value)"
|
|
151
|
+
@keydown.enter="onRowActivate($event, item.value)"
|
|
152
|
+
@keydown.space="onRowSpace($event, item.value)"
|
|
153
|
+
>
|
|
154
|
+
<!-- bare: the slot draws the whole row -->
|
|
155
|
+
<slot
|
|
156
|
+
v-if="bare"
|
|
157
|
+
name="item"
|
|
158
|
+
:item="item"
|
|
159
|
+
:checked="checked.has(item.value)"
|
|
160
|
+
:toggle="() => emit('toggle', item.value)"
|
|
161
|
+
:move="() => emit('activate', item.value)"
|
|
162
|
+
/>
|
|
163
|
+
<template v-else>
|
|
164
|
+
<span
|
|
165
|
+
aria-hidden="true"
|
|
166
|
+
class="pointer-events-none absolute inset-0 opacity-0 transition-opacity duration-150 group-hover:opacity-[0.08]"
|
|
167
|
+
:class="checked.has(item.value) ? 'bg-on-secondary-container' : 'bg-on-surface'"
|
|
168
|
+
/>
|
|
169
|
+
<MCheckbox
|
|
170
|
+
class="relative"
|
|
171
|
+
:model-value="checked.has(item.value)"
|
|
172
|
+
:aria-label="item.label"
|
|
173
|
+
@update:model-value="emit('toggle', item.value)"
|
|
174
|
+
/>
|
|
175
|
+
<!-- #item replaces the icon and text; the row (checkbox, highlight, hover) stays -->
|
|
176
|
+
<div v-if="$slots.item" class="relative min-w-0 flex-1">
|
|
177
|
+
<slot
|
|
178
|
+
name="item"
|
|
179
|
+
:item="item"
|
|
180
|
+
:checked="checked.has(item.value)"
|
|
181
|
+
:toggle="() => emit('toggle', item.value)"
|
|
182
|
+
:move="() => emit('activate', item.value)"
|
|
183
|
+
/>
|
|
184
|
+
</div>
|
|
185
|
+
<template v-else>
|
|
186
|
+
<span
|
|
187
|
+
v-if="item.icon"
|
|
188
|
+
class="relative flex h-10 w-10 shrink-0 items-center justify-center rounded-full transition-colors duration-150"
|
|
189
|
+
:class="checked.has(item.value) ? 'bg-secondary text-on-secondary' : 'bg-surface-container-highest text-on-surface-variant'"
|
|
190
|
+
>
|
|
191
|
+
<MIcon :name="item.icon" :size="20" />
|
|
192
|
+
</span>
|
|
193
|
+
<span class="relative min-w-0 flex-1">
|
|
194
|
+
<span
|
|
195
|
+
class="block truncate text-body-large"
|
|
196
|
+
:class="checked.has(item.value) ? 'text-on-secondary-container' : 'text-on-surface'"
|
|
197
|
+
>{{ item.label }}</span>
|
|
198
|
+
<span
|
|
199
|
+
v-if="item.description"
|
|
200
|
+
class="block truncate text-body-medium"
|
|
201
|
+
:class="checked.has(item.value) ? 'text-on-secondary-container/80' : 'text-on-surface-variant'"
|
|
202
|
+
>{{ item.description }}</span>
|
|
203
|
+
</span>
|
|
204
|
+
</template>
|
|
205
|
+
</template>
|
|
206
|
+
</li>
|
|
207
|
+
</TransitionGroup>
|
|
208
|
+
|
|
209
|
+
<div
|
|
210
|
+
v-if="!items.length"
|
|
211
|
+
class="absolute inset-0 flex flex-col items-center justify-center gap-2 p-6 text-center"
|
|
212
|
+
>
|
|
213
|
+
<slot name="empty">
|
|
214
|
+
<MIcon :name="search ? 'search_off' : 'inbox'" :size="32" class="text-on-surface-variant/60" />
|
|
215
|
+
<p class="text-body-medium text-on-surface-variant">{{ emptyText }}</p>
|
|
216
|
+
</slot>
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
</section>
|
|
220
|
+
</template>
|
|
221
|
+
|
|
222
|
+
<style scoped>
|
|
223
|
+
.m3-tl-start-move,
|
|
224
|
+
.m3-tl-end-move {
|
|
225
|
+
transition: transform 0.25s cubic-bezier(0.2, 0, 0, 1);
|
|
226
|
+
}
|
|
227
|
+
.m3-tl-start-enter-active,
|
|
228
|
+
.m3-tl-end-enter-active {
|
|
229
|
+
transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.2, 0, 0, 1);
|
|
230
|
+
}
|
|
231
|
+
.m3-tl-start-leave-active,
|
|
232
|
+
.m3-tl-end-leave-active {
|
|
233
|
+
transition: opacity 0.15s ease;
|
|
234
|
+
position: absolute;
|
|
235
|
+
left: 0;
|
|
236
|
+
right: 0;
|
|
237
|
+
}
|
|
238
|
+
.m3-tl-start-enter-from {
|
|
239
|
+
opacity: 0;
|
|
240
|
+
transform: translateX(-16px);
|
|
241
|
+
}
|
|
242
|
+
.m3-tl-end-enter-from {
|
|
243
|
+
opacity: 0;
|
|
244
|
+
transform: translateX(16px);
|
|
245
|
+
}
|
|
246
|
+
.m3-tl-start-leave-to,
|
|
247
|
+
.m3-tl-end-leave-to {
|
|
248
|
+
opacity: 0;
|
|
249
|
+
}
|
|
250
|
+
@media (prefers-reduced-motion: reduce) {
|
|
251
|
+
.m3-tl-start-move,
|
|
252
|
+
.m3-tl-end-move,
|
|
253
|
+
.m3-tl-start-enter-active,
|
|
254
|
+
.m3-tl-end-enter-active,
|
|
255
|
+
.m3-tl-start-leave-active,
|
|
256
|
+
.m3-tl-end-leave-active {
|
|
257
|
+
transition: none;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getCurrentInstance } from 'vue'
|
|
2
|
+
|
|
3
|
+
/** A navigation destination: a vue-router location, or a plain URL without vue-router. */
|
|
4
|
+
export type ItemLink = string | Record<string, unknown>
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Internal (not exported from index.ts): lets navigation items with a `to` render as real links
|
|
8
|
+
* (middle-click, open in new tab, `aria-current` from vue-router) instead of buttons. With
|
|
9
|
+
* vue-router installed it's a RouterLink; without it a string `to` becomes a plain `<a href>`
|
|
10
|
+
* rather than an unresolved `<RouterLink>` tag. Items without `to` (or disabled ones) stay buttons.
|
|
11
|
+
*/
|
|
12
|
+
export function useItemLink() {
|
|
13
|
+
const hasRouter = !!getCurrentInstance()?.appContext.components.RouterLink
|
|
14
|
+
return (item: { to?: ItemLink; disabled?: boolean }) => {
|
|
15
|
+
if (!item.to || item.disabled) return { tag: 'button', attrs: { type: 'button', disabled: item.disabled || undefined } }
|
|
16
|
+
if (hasRouter) return { tag: 'RouterLink', attrs: { to: item.to } }
|
|
17
|
+
return { tag: 'a', attrs: { href: typeof item.to === 'string' ? item.to : undefined } }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { onBeforeUnmount } from 'vue'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Internal (not exported from index.ts): enter/exit/drag motion for modal sheets
|
|
5
|
+
* (MBottomSheet on y, MSideSheet on x), after androidx BottomSheet.kt + SheetDefaults.kt:
|
|
6
|
+
* show = Standard DefaultSpatial spring (0.9 / 700) from fully off-screen (offset = the
|
|
7
|
+
* panel's own size), hide = FastEffects (1.0 / 3800), scrim alpha = DefaultEffects
|
|
8
|
+
* (1.0 / 1600). The panel slides only, no opacity fade. A drag release springs from where
|
|
9
|
+
* the finger left it, carrying its velocity, either back open or out.
|
|
10
|
+
*
|
|
11
|
+
* Library convention (see CLAUDE.md): springs stepped in one rAF loop, state in plain
|
|
12
|
+
* variables, the DOM written once per frame. The panel's transform must never also be bound
|
|
13
|
+
* reactively in the template, which is what silently killed the old CSS enter animation.
|
|
14
|
+
*
|
|
15
|
+
* Wire it to a `<Transition :css="false" @enter @leave>` around a root holding
|
|
16
|
+
* `[data-sheet-panel]` and `[data-sheet-scrim]`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
interface Spring { damping: number; stiffness: number }
|
|
20
|
+
const DEFAULT_SPATIAL: Spring = { damping: 0.9, stiffness: 700 }
|
|
21
|
+
const FAST_EFFECTS: Spring = { damping: 1, stiffness: 3800 }
|
|
22
|
+
const DEFAULT_EFFECTS: Spring = { damping: 1, stiffness: 1600 }
|
|
23
|
+
|
|
24
|
+
/** Past this many px, or this fast (px/s) toward closing, a released drag dismisses. */
|
|
25
|
+
const DISMISS_DISTANCE = 100
|
|
26
|
+
const DISMISS_VELOCITY = 1000
|
|
27
|
+
|
|
28
|
+
// Semi-implicit Euler in fixed 4ms substeps: FastEffects' stiffness (3800) is unstable at
|
|
29
|
+
// a dropped frame's 33ms step (it diverges instead of settling).
|
|
30
|
+
const SUBSTEP = 0.004
|
|
31
|
+
function step(s: { pos: number; vel: number }, target: number, spring: Spring, dt: number) {
|
|
32
|
+
for (let left = dt; left > 0; left -= SUBSTEP) {
|
|
33
|
+
const h = Math.min(SUBSTEP, left)
|
|
34
|
+
const accel = -spring.stiffness * (s.pos - target) - 2 * spring.damping * Math.sqrt(spring.stiffness) * s.vel
|
|
35
|
+
s.vel += accel * h
|
|
36
|
+
s.pos += s.vel * h
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function useSheetMotion(axis: 'x' | 'y', onDismiss: () => void) {
|
|
41
|
+
let panel: HTMLElement | null = null
|
|
42
|
+
let scrim: HTMLElement | null = null
|
|
43
|
+
const offset = { pos: 0, vel: 0 }
|
|
44
|
+
const alpha = { pos: 0, vel: 0 }
|
|
45
|
+
let offsetTarget = 0
|
|
46
|
+
let alphaTarget = 0
|
|
47
|
+
let offsetSpring = DEFAULT_SPATIAL
|
|
48
|
+
let settled: (() => void) | null = null
|
|
49
|
+
let raf = 0
|
|
50
|
+
let last = 0
|
|
51
|
+
|
|
52
|
+
let dragging = false
|
|
53
|
+
let dragStart = 0
|
|
54
|
+
let dragOrigin = 0
|
|
55
|
+
let lastMove = { at: 0, pos: 0 }
|
|
56
|
+
|
|
57
|
+
const size = () => (panel ? (axis === 'y' ? panel.offsetHeight : panel.offsetWidth) : 0)
|
|
58
|
+
const reducedMotion = () =>
|
|
59
|
+
typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
|
|
60
|
+
|
|
61
|
+
function write() {
|
|
62
|
+
if (panel) panel.style.transform = axis === 'y' ? `translateY(${offset.pos}px)` : `translateX(${offset.pos}px)`
|
|
63
|
+
if (scrim) scrim.style.opacity = String(Math.min(1, Math.max(0, alpha.pos)))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function finish() {
|
|
67
|
+
raf = 0
|
|
68
|
+
const cb = settled
|
|
69
|
+
settled = null
|
|
70
|
+
cb?.()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function frame(now: number) {
|
|
74
|
+
const dt = Math.min((now - last) / 1000, 1 / 30)
|
|
75
|
+
last = now
|
|
76
|
+
if (!dragging) step(offset, offsetTarget, offsetSpring, dt)
|
|
77
|
+
step(alpha, alphaTarget, DEFAULT_EFFECTS, dt)
|
|
78
|
+
const offsetDone = dragging || (Math.abs(offset.pos - offsetTarget) < 0.5 && Math.abs(offset.vel) < 5)
|
|
79
|
+
const alphaDone = Math.abs(alpha.pos - alphaTarget) < 0.002 && Math.abs(alpha.vel) < 0.05
|
|
80
|
+
if (offsetDone && alphaDone) {
|
|
81
|
+
if (!dragging) offset.pos = offsetTarget
|
|
82
|
+
alpha.pos = alphaTarget
|
|
83
|
+
offset.vel = alpha.vel = 0
|
|
84
|
+
write()
|
|
85
|
+
if (!dragging) return finish()
|
|
86
|
+
raf = 0
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
write()
|
|
90
|
+
raf = requestAnimationFrame(frame)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function run() {
|
|
94
|
+
if (reducedMotion()) {
|
|
95
|
+
offset.pos = offsetTarget
|
|
96
|
+
alpha.pos = alphaTarget
|
|
97
|
+
offset.vel = alpha.vel = 0
|
|
98
|
+
write()
|
|
99
|
+
return finish()
|
|
100
|
+
}
|
|
101
|
+
if (raf) return
|
|
102
|
+
last = performance.now()
|
|
103
|
+
raf = requestAnimationFrame(frame)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function bind(el: Element) {
|
|
107
|
+
panel = el.querySelector<HTMLElement>('[data-sheet-panel]')
|
|
108
|
+
scrim = el.querySelector<HTMLElement>('[data-sheet-scrim]')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function onEnter(el: Element, done: () => void) {
|
|
112
|
+
// Reopened mid-exit: let the old element go now instead of leaving it in the DOM.
|
|
113
|
+
settled?.()
|
|
114
|
+
settled = null
|
|
115
|
+
if (raf) cancelAnimationFrame(raf)
|
|
116
|
+
raf = 0
|
|
117
|
+
bind(el)
|
|
118
|
+
offset.pos = size()
|
|
119
|
+
offset.vel = 0
|
|
120
|
+
alpha.pos = 0
|
|
121
|
+
alpha.vel = 0
|
|
122
|
+
offsetTarget = 0
|
|
123
|
+
alphaTarget = 1
|
|
124
|
+
offsetSpring = DEFAULT_SPATIAL
|
|
125
|
+
settled = done
|
|
126
|
+
write()
|
|
127
|
+
run()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function onLeave(el: Element, done: () => void) {
|
|
131
|
+
bind(el)
|
|
132
|
+
dragging = false
|
|
133
|
+
offsetTarget = size()
|
|
134
|
+
alphaTarget = 0
|
|
135
|
+
offsetSpring = FAST_EFFECTS
|
|
136
|
+
settled = done
|
|
137
|
+
run()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function onDragStart(e: PointerEvent) {
|
|
141
|
+
// A sheet mounted already open never ran onEnter: find its elements from the handle.
|
|
142
|
+
const root = (e.currentTarget as HTMLElement).closest('[data-sheet-panel]')?.parentElement
|
|
143
|
+
if (root) bind(root)
|
|
144
|
+
dragging = true
|
|
145
|
+
dragStart = axis === 'y' ? e.clientY : e.clientX
|
|
146
|
+
dragOrigin = offset.pos
|
|
147
|
+
offset.vel = 0
|
|
148
|
+
lastMove = { at: performance.now(), pos: offset.pos }
|
|
149
|
+
;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function onDragMove(e: PointerEvent) {
|
|
153
|
+
if (!dragging) return
|
|
154
|
+
const now = performance.now()
|
|
155
|
+
offset.pos = Math.max(0, dragOrigin + (axis === 'y' ? e.clientY : e.clientX) - dragStart)
|
|
156
|
+
const dt = (now - lastMove.at) / 1000
|
|
157
|
+
if (dt > 0) offset.vel = (offset.pos - lastMove.pos) / dt
|
|
158
|
+
lastMove = { at: now, pos: offset.pos }
|
|
159
|
+
write()
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function onDragEnd() {
|
|
163
|
+
if (!dragging) return
|
|
164
|
+
dragging = false
|
|
165
|
+
// A pause before lifting the finger means no fling.
|
|
166
|
+
if (performance.now() - lastMove.at > 100) offset.vel = 0
|
|
167
|
+
if (offset.pos > DISMISS_DISTANCE || offset.vel > DISMISS_VELOCITY) {
|
|
168
|
+
onDismiss()
|
|
169
|
+
} else {
|
|
170
|
+
offsetTarget = 0
|
|
171
|
+
offsetSpring = DEFAULT_SPATIAL
|
|
172
|
+
run()
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
onBeforeUnmount(() => {
|
|
177
|
+
if (raf) cancelAnimationFrame(raf)
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
return { onEnter, onLeave, onDragStart, onDragMove, onDragEnd }
|
|
181
|
+
}
|
|
@@ -104,6 +104,44 @@ export interface M3Locale {
|
|
|
104
104
|
// JSON viewer
|
|
105
105
|
jsonElements: string
|
|
106
106
|
jsonFields: string
|
|
107
|
+
|
|
108
|
+
// Result
|
|
109
|
+
resultSuccessTitle: string
|
|
110
|
+
resultSuccessDesc: string
|
|
111
|
+
resultErrorTitle: string
|
|
112
|
+
resultErrorDesc: string
|
|
113
|
+
resultWarningTitle: string
|
|
114
|
+
resultWarningDesc: string
|
|
115
|
+
resultInfoTitle: string
|
|
116
|
+
resultInfoDesc: string
|
|
117
|
+
result404Title: string
|
|
118
|
+
result404Desc: string
|
|
119
|
+
result403Title: string
|
|
120
|
+
result403Desc: string
|
|
121
|
+
result500Title: string
|
|
122
|
+
result500Desc: string
|
|
123
|
+
|
|
124
|
+
// Chat bubble
|
|
125
|
+
chatTyping: string
|
|
126
|
+
chatRecordingAudio: string
|
|
127
|
+
|
|
128
|
+
// Drag & drop list ({pos}/{total} are replaced at runtime)
|
|
129
|
+
reorderHandle: string
|
|
130
|
+
reorderGrabbed: string
|
|
131
|
+
reorderMoved: string
|
|
132
|
+
reorderDropped: string
|
|
133
|
+
reorderCancelled: string
|
|
134
|
+
|
|
135
|
+
// Transfer list (panes)
|
|
136
|
+
selectAll: string
|
|
137
|
+
clearSearch: string
|
|
138
|
+
|
|
139
|
+
// Kanban ({column}/{pos}/{total} are replaced at runtime)
|
|
140
|
+
kanbanMoved: string
|
|
141
|
+
// MWindow title bar buttons
|
|
142
|
+
windowMinimize: string
|
|
143
|
+
windowMaximize: string
|
|
144
|
+
windowRestore: string
|
|
107
145
|
}
|
|
108
146
|
|
|
109
147
|
export const defaultLocale: M3Locale = {
|
|
@@ -196,6 +234,43 @@ export const defaultLocale: M3Locale = {
|
|
|
196
234
|
|
|
197
235
|
jsonElements: 'elements',
|
|
198
236
|
jsonFields: 'fields',
|
|
237
|
+
|
|
238
|
+
// Result
|
|
239
|
+
resultSuccessTitle: 'Success',
|
|
240
|
+
resultSuccessDesc: 'The action was completed successfully.',
|
|
241
|
+
resultErrorTitle: 'Something went wrong',
|
|
242
|
+
resultErrorDesc: 'An unexpected error occurred. Please try again.',
|
|
243
|
+
resultWarningTitle: 'Warning',
|
|
244
|
+
resultWarningDesc: 'Something needs your attention.',
|
|
245
|
+
resultInfoTitle: 'Information',
|
|
246
|
+
resultInfoDesc: 'Here is something you should know.',
|
|
247
|
+
result404Title: 'Page not found',
|
|
248
|
+
result404Desc: 'The page you are looking for does not exist or has been moved.',
|
|
249
|
+
result403Title: 'Access denied',
|
|
250
|
+
result403Desc: 'You don\'t have permission to view this resource.',
|
|
251
|
+
result500Title: 'Server error',
|
|
252
|
+
result500Desc: 'The server could not process the request.',
|
|
253
|
+
|
|
254
|
+
// Chat bubble
|
|
255
|
+
chatTyping: 'Typing…',
|
|
256
|
+
chatRecordingAudio: 'Recording audio…',
|
|
257
|
+
|
|
258
|
+
// Drag & drop list ({pos}/{total} are replaced at runtime)
|
|
259
|
+
reorderHandle: 'Reorder',
|
|
260
|
+
reorderGrabbed: 'Item grabbed, position {pos} of {total}. Use the arrow keys to move it, Space to drop it, Escape to cancel.',
|
|
261
|
+
reorderMoved: 'Moved to position {pos} of {total}.',
|
|
262
|
+
reorderDropped: 'Item dropped at position {pos} of {total}.',
|
|
263
|
+
reorderCancelled: 'Reorder cancelled.',
|
|
264
|
+
|
|
265
|
+
// Transfer list (panes)
|
|
266
|
+
selectAll: 'Select all',
|
|
267
|
+
clearSearch: 'Clear search',
|
|
268
|
+
|
|
269
|
+
// Kanban ({column}/{pos}/{total} are replaced at runtime)
|
|
270
|
+
kanbanMoved: 'Moved to {column}, position {pos} of {total}.',
|
|
271
|
+
windowMinimize: 'Minimize',
|
|
272
|
+
windowMaximize: 'Maximize',
|
|
273
|
+
windowRestore: 'Restore',
|
|
199
274
|
}
|
|
200
275
|
|
|
201
276
|
export const M3_LOCALE_KEY: InjectionKey<MaybeRef<Partial<M3Locale>>> = Symbol('m3-locale')
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { computed, onMounted, onUnmounted, ref, toValue, watch, type MaybeRefOrGetter, type Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* M3 window size classes, with the breakpoints from androidx `WindowSizeClass`
|
|
5
|
+
* (window-core: WIDTH_DP_MEDIUM_LOWER_BOUND 600, EXPANDED 840, LARGE 1200, EXTRA_LARGE 1600;
|
|
6
|
+
* HEIGHT_DP_MEDIUM_LOWER_BOUND 480, EXPANDED 900). CSS px stand in for dp.
|
|
7
|
+
*/
|
|
8
|
+
export type WidthSizeClass = 'compact' | 'medium' | 'expanded' | 'large' | 'extra-large'
|
|
9
|
+
export type HeightSizeClass = 'compact' | 'medium' | 'expanded'
|
|
10
|
+
|
|
11
|
+
export function widthSizeClass(width: number): WidthSizeClass {
|
|
12
|
+
if (width < 600) return 'compact'
|
|
13
|
+
if (width < 840) return 'medium'
|
|
14
|
+
if (width < 1200) return 'expanded'
|
|
15
|
+
if (width < 1600) return 'large'
|
|
16
|
+
return 'extra-large'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function heightSizeClass(height: number): HeightSizeClass {
|
|
20
|
+
if (height < 480) return 'compact'
|
|
21
|
+
if (height < 900) return 'medium'
|
|
22
|
+
return 'expanded'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface WindowSizeClassInfo {
|
|
26
|
+
width: Ref<number>
|
|
27
|
+
height: Ref<number>
|
|
28
|
+
widthClass: Ref<WidthSizeClass>
|
|
29
|
+
heightClass: Ref<HeightSizeClass>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Window mode shares one `resize` listener across every caller (same ref-counting as useDevice).
|
|
33
|
+
const winWidth = ref(typeof window === 'undefined' ? 0 : window.innerWidth)
|
|
34
|
+
const winHeight = ref(typeof window === 'undefined' ? 0 : window.innerHeight)
|
|
35
|
+
let winListeners = 0
|
|
36
|
+
function updateWindow() {
|
|
37
|
+
winWidth.value = window.innerWidth
|
|
38
|
+
winHeight.value = window.innerHeight
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The M3 width/height size classes, reactive.
|
|
43
|
+
*
|
|
44
|
+
* With no argument it tracks the browser window. Pass an element (ref or getter) to classify
|
|
45
|
+
* that element's own size instead, which is what the adaptive layout components do, so they
|
|
46
|
+
* adapt to the space they actually get (a column, a dialog, a resizable panel).
|
|
47
|
+
*/
|
|
48
|
+
export function useWindowSizeClass(target?: MaybeRefOrGetter<HTMLElement | null | undefined>): WindowSizeClassInfo {
|
|
49
|
+
let width: Ref<number>
|
|
50
|
+
let height: Ref<number>
|
|
51
|
+
|
|
52
|
+
if (target === undefined) {
|
|
53
|
+
width = winWidth
|
|
54
|
+
height = winHeight
|
|
55
|
+
onMounted(() => {
|
|
56
|
+
if (winListeners++ === 0) {
|
|
57
|
+
updateWindow()
|
|
58
|
+
window.addEventListener('resize', updateWindow)
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
onUnmounted(() => {
|
|
62
|
+
if (--winListeners === 0) window.removeEventListener('resize', updateWindow)
|
|
63
|
+
})
|
|
64
|
+
} else {
|
|
65
|
+
// Until the element is measured, guess from the window so the first paint is usually right.
|
|
66
|
+
width = ref(winWidth.value)
|
|
67
|
+
height = ref(winHeight.value)
|
|
68
|
+
let observer: ResizeObserver | undefined
|
|
69
|
+
const observe = (el: HTMLElement | null | undefined) => {
|
|
70
|
+
observer?.disconnect()
|
|
71
|
+
if (!el || typeof ResizeObserver === 'undefined') return
|
|
72
|
+
width.value = el.offsetWidth
|
|
73
|
+
height.value = el.offsetHeight
|
|
74
|
+
// offsetWidth/Height (border box), so padding on the element counts like it does for the window.
|
|
75
|
+
observer = new ResizeObserver(() => {
|
|
76
|
+
width.value = el.offsetWidth
|
|
77
|
+
height.value = el.offsetHeight
|
|
78
|
+
})
|
|
79
|
+
observer.observe(el)
|
|
80
|
+
}
|
|
81
|
+
onMounted(() => {
|
|
82
|
+
watch(() => toValue(target), observe, { immediate: true })
|
|
83
|
+
})
|
|
84
|
+
onUnmounted(() => observer?.disconnect())
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
width,
|
|
89
|
+
height,
|
|
90
|
+
widthClass: computed(() => widthSizeClass(width.value)),
|
|
91
|
+
heightClass: computed(() => heightSizeClass(height.value)),
|
|
92
|
+
}
|
|
93
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,8 @@ export { useFieldBg } from './composables/useFieldBg'
|
|
|
13
13
|
export { useLocale, defaultLocale } from './composables/useLocale'
|
|
14
14
|
export type { M3Locale } from './composables/useLocale'
|
|
15
15
|
export { useDevice } from './composables/useDevice'
|
|
16
|
+
export { useWindowSizeClass, widthSizeClass, heightSizeClass } from './composables/useWindowSizeClass'
|
|
17
|
+
export type { WidthSizeClass, HeightSizeClass, WindowSizeClassInfo } from './composables/useWindowSizeClass'
|
|
16
18
|
export { useNotification } from './composables/useNotification'
|
|
17
19
|
export type { Notification, NotificationVariant, NotificationPosition, NotificationOptions } from './composables/useNotification'
|
|
18
20
|
export { useDebounce } from './composables/useDebounce'
|
|
@@ -103,6 +105,10 @@ export { default as MNavigationBar } from './components/MNavigationBar.vue'
|
|
|
103
105
|
export { default as MNumberField } from './components/MNumberField.vue'
|
|
104
106
|
export { default as MNavigationDrawer } from './components/MNavigationDrawer.vue'
|
|
105
107
|
export { default as MNavigationRail } from './components/MNavigationRail.vue'
|
|
108
|
+
export { default as MNavigationSuite } from './components/MNavigationSuite.vue'
|
|
109
|
+
export type { NavigationSuiteItem, NavigationSuiteLayout } from './components/MNavigationSuite.vue'
|
|
110
|
+
export { default as MListDetail } from './components/MListDetail.vue'
|
|
111
|
+
export { default as MSupportingPane } from './components/MSupportingPane.vue'
|
|
106
112
|
export { default as MOverlay } from './components/MOverlay.vue'
|
|
107
113
|
export { default as MPageProgress } from './components/MPageProgress.vue'
|
|
108
114
|
export { default as MPagination } from './components/MPagination.vue'
|