@m3ui-vue/m3ui-vue 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/API.md +305 -12
- package/dist/{MButton-LiZRRP4h.js → MButton-B9RCM06i.js} +4 -4
- package/dist/MButton-B9RCM06i.js.map +1 -0
- package/dist/{MColorPickerModal-IjciC8zh.js → MColorPickerModal-ChRtcZOo.js} +5 -5
- package/dist/{MColorPickerModal-IjciC8zh.js.map → MColorPickerModal-ChRtcZOo.js.map} +1 -1
- package/dist/{MDialog-BLpfgIA3.js → MDialog-dk07tify.js} +3 -3
- package/dist/{MDialog-BLpfgIA3.js.map → MDialog-dk07tify.js.map} +1 -1
- package/dist/{MIconButton-CNjN0xwW.js → MIconButton-CrBPZidd.js} +46 -39
- package/dist/MIconButton-CrBPZidd.js.map +1 -0
- package/dist/MListItem-h9H223vx.js +1239 -0
- package/dist/MListItem-h9H223vx.js.map +1 -0
- package/dist/{MLoadingIndicator-dejdXpu8.js → MLoadingIndicator-YTV1Ov5w.js} +2 -2
- package/dist/{MLoadingIndicator-dejdXpu8.js.map → MLoadingIndicator-YTV1Ov5w.js.map} +1 -1
- package/dist/MMenuItem-US0Zbglq.js +596 -0
- package/dist/MMenuItem-US0Zbglq.js.map +1 -0
- package/dist/{MPdfViewer-B5Q9Xs9d.js → MPdfViewer-DL9mRsd2.js} +8 -8
- package/dist/{MPdfViewer-B5Q9Xs9d.js.map → MPdfViewer-DL9mRsd2.js.map} +1 -1
- package/dist/MProgressBar-BzZMxq7M.js +254 -0
- package/dist/MProgressBar-BzZMxq7M.js.map +1 -0
- package/dist/{MSeekBar-NwkuAzx-.js → MSeekBar-JFZcoJ8y.js} +2 -2
- package/dist/{MSeekBar-NwkuAzx-.js.map → MSeekBar-JFZcoJ8y.js.map} +1 -1
- package/dist/MSegmentedButton-DMou-8sG.js +106 -0
- package/dist/MSegmentedButton-DMou-8sG.js.map +1 -0
- package/dist/{MSignaturePad-Bqr-1R9f.js → MSignaturePad-WuvE_Cyl.js} +2 -2
- package/dist/{MSignaturePad-Bqr-1R9f.js.map → MSignaturePad-WuvE_Cyl.js.map} +1 -1
- package/dist/{MSlider-B7dIcHVn.js → MSlider-7TzhFHKS.js} +3 -3
- package/dist/{MSlider-B7dIcHVn.js.map → MSlider-7TzhFHKS.js.map} +1 -1
- package/dist/{MSpinner-CXLY7lWw.js → MSpinner-CkIVBuGE.js} +2 -2
- package/dist/{MSpinner-CXLY7lWw.js.map → MSpinner-CkIVBuGE.js.map} +1 -1
- package/dist/{MTextField-CryHMs8-.js → MTextField-B6_iOczK.js} +3 -3
- package/dist/{MTextField-CryHMs8-.js.map → MTextField-B6_iOczK.js.map} +1 -1
- package/dist/{_useFieldValidation-CvZnZfl-.js → _useFieldValidation-COBJ1tWr.js} +2 -2
- package/dist/{_useFieldValidation-CvZnZfl-.js.map → _useFieldValidation-COBJ1tWr.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MAvatarGroup.vue.d.ts +48 -0
- package/dist/components/MCommentThread.vue.d.ts +42 -0
- package/dist/components/MContainer.vue.d.ts +1 -1
- package/dist/components/MContextMenu.vue.d.ts +7 -0
- package/dist/components/MDataTable.vue.d.ts +7 -0
- package/dist/components/MList.vue.d.ts +11 -0
- package/dist/components/MListDetail.vue.d.ts +22 -0
- package/dist/components/MListItem.vue.d.ts +9 -1
- package/dist/components/MMenu.vue.d.ts +10 -0
- package/dist/components/MReactions.vue.d.ts +35 -0
- package/dist/components/MScaffold.vue.d.ts +45 -0
- package/dist/components/MScrollField.vue.d.ts +4 -1
- package/dist/components/MScrollable.vue.d.ts +5 -4
- package/dist/components/MSpreadsheet.vue.d.ts +1 -1
- package/dist/components/MSupportingPane.vue.d.ts +22 -0
- package/dist/components/MTable.vue.d.ts +7 -0
- package/dist/components/MVirtualList.vue.d.ts +51 -0
- package/dist/components/_MComment.vue.d.ts +8 -0
- package/dist/components/_MCommentComposer.vue.d.ts +23 -0
- package/dist/components/_commentThread.d.ts +41 -0
- package/dist/composables/_menuGroups.d.ts +7 -0
- package/dist/composables/_usePaneResize.d.ts +45 -0
- package/dist/composables/useLocale.d.ts +22 -0
- package/dist/composables/useUndo.d.ts +45 -0
- package/dist/directives/vRipple.d.ts +4 -0
- package/dist/draw.js +4 -4
- package/dist/flow.js +2 -2
- package/dist/gantt.js +3 -3
- package/dist/index.d.ts +12 -0
- package/dist/locales/index.js +128 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +11027 -9741
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +7 -7
- package/dist/media.js +6 -6
- package/dist/pdf-sign.js +8 -8
- package/dist/pdf.js +1 -1
- package/dist/plugin.d.ts +6 -0
- package/dist/rich-text-editor.js +6 -6
- package/dist/styles/theme.css +43 -6
- package/dist/styles.css +1 -1
- package/dist/{useLocale-ybIju59R.js → useLocale-YRaOT12S.js} +17 -1
- package/dist/useLocale-YRaOT12S.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MListItemNestedControl.test.ts +1 -1
- package/src/__tests__/MListMultiSelect.test.ts +132 -0
- package/src/__tests__/MMenu.test.ts +152 -0
- package/src/__tests__/MProgressBar.test.ts +84 -1
- package/src/__tests__/MScrollField.test.ts +16 -0
- package/src/__tests__/MScrollable.test.ts +61 -5
- package/src/__tests__/MSwitch.test.ts +83 -0
- package/src/__tests__/adaptiveLayouts.test.ts +167 -0
- package/src/__tests__/backlogComponents.test.ts +249 -0
- package/src/__tests__/popupPosition.test.ts +4 -0
- package/src/__tests__/stateLayerOpacity.test.ts +65 -0
- package/src/__tests__/tableCheckboxReveal.test.ts +35 -0
- package/src/__tests__/vRipple.test.ts +62 -0
- package/src/components/MAvatarGroup.vue +150 -0
- package/src/components/MButton.vue +1 -1
- package/src/components/MButtonGroup.vue +1 -1
- package/src/components/MCard.vue +4 -2
- package/src/components/MCheckbox.vue +13 -2
- package/src/components/MChip.vue +7 -4
- package/src/components/MCircleProgressBar.vue +69 -21
- package/src/components/MCommentThread.vue +131 -0
- package/src/components/MContextMenu.vue +18 -31
- package/src/components/MDataTable.vue +16 -6
- package/src/components/MFab.vue +2 -2
- package/src/components/MIconButton.vue +2 -2
- package/src/components/MList.vue +163 -5
- package/src/components/MListDetail.vue +100 -14
- package/src/components/MListItem.vue +66 -6
- package/src/components/MMenu.vue +48 -41
- package/src/components/MMenuItem.vue +48 -14
- package/src/components/MProgressBar.vue +183 -50
- package/src/components/MRadio.vue +14 -2
- package/src/components/MReactions.vue +161 -0
- package/src/components/MScaffold.vue +213 -0
- package/src/components/MScrollField.vue +15 -12
- package/src/components/MScrollable.vue +187 -46
- package/src/components/MSegmentedButton.vue +3 -1
- package/src/components/MSupportingPane.vue +102 -12
- package/src/components/MSwitch.vue +92 -9
- package/src/components/MTable.vue +17 -4
- package/src/components/MTimeScroll.vue +1 -1
- package/src/components/MToggleButton.vue +2 -2
- package/src/components/MVirtualList.vue +222 -0
- package/src/components/_MComment.vue +142 -0
- package/src/components/_MCommentComposer.vue +68 -0
- package/src/components/_commentThread.ts +46 -0
- package/src/composables/_menuGroups.ts +31 -0
- package/src/composables/_usePaneResize.ts +271 -0
- package/src/composables/useLocale.ts +38 -0
- package/src/composables/useUndo.ts +170 -0
- package/src/directives/vRipple.ts +18 -5
- package/src/index.ts +12 -0
- package/src/locales/ar.ts +16 -0
- package/src/locales/de.ts +16 -0
- package/src/locales/es.ts +16 -0
- package/src/locales/fr.ts +16 -0
- package/src/locales/ja.ts +16 -0
- package/src/locales/ko.ts +16 -0
- package/src/locales/pt.ts +16 -0
- package/src/locales/zh.ts +16 -0
- package/src/plugin.ts +7 -0
- package/src/styles/theme.css +43 -6
- package/dist/MButton-LiZRRP4h.js.map +0 -1
- package/dist/MIconButton-CNjN0xwW.js.map +0 -1
- package/dist/MListItem-BBQ-6i3v.js +0 -991
- package/dist/MListItem-BBQ-6i3v.js.map +0 -1
- package/dist/MMenuItem-E31tMzOt.js +0 -577
- package/dist/MMenuItem-E31tMzOt.js.map +0 -1
- package/dist/MProgressBar-CPrZhQbA.js +0 -179
- package/dist/MProgressBar-CPrZhQbA.js.map +0 -1
- package/dist/MSegmentedButton-DZuZLBML.js +0 -105
- package/dist/MSegmentedButton-DZuZLBML.js.map +0 -1
- package/dist/useLocale-ybIju59R.js.map +0 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Internal (MCommentThread): one comment and, below it, its replies (recursively).
|
|
3
|
+
import { computed, inject, ref } from 'vue'
|
|
4
|
+
import MIconButton from './MIconButton.vue'
|
|
5
|
+
import MMenu from './MMenu.vue'
|
|
6
|
+
import MMenuItem from './MMenuItem.vue'
|
|
7
|
+
import MReactions from './MReactions.vue'
|
|
8
|
+
import CommentComposer from './_MCommentComposer.vue'
|
|
9
|
+
import { COMMENT_THREAD_KEY, type CommentItem } from './_commentThread'
|
|
10
|
+
import { vRipple } from '../directives/vRipple'
|
|
11
|
+
|
|
12
|
+
defineOptions({ name: 'MComment' })
|
|
13
|
+
|
|
14
|
+
const props = defineProps<{ comment: CommentItem; depth: number }>()
|
|
15
|
+
const ctx = inject(COMMENT_THREAD_KEY)!
|
|
16
|
+
const t = ctx.locale
|
|
17
|
+
|
|
18
|
+
const replies = computed(() => props.comment.replies ?? [])
|
|
19
|
+
// Replies show right away up to a couple; more wait behind "View N replies" (YouTube, Google Docs)
|
|
20
|
+
const expanded = ref(replies.value.length <= ctx.repliesShown.value)
|
|
21
|
+
const replying = computed(() => ctx.replyTo.value === props.comment.id)
|
|
22
|
+
const editing = computed(() => ctx.editing.value === props.comment.id)
|
|
23
|
+
const canEdit = computed(() => ctx.canEdit(props.comment))
|
|
24
|
+
const size = computed(() => (props.depth === 0 ? 40 : 32))
|
|
25
|
+
// Past maxDepth, replies stay at the deepest indentation instead of drifting right
|
|
26
|
+
const nests = computed(() => props.depth + 1 < ctx.maxDepth.value)
|
|
27
|
+
|
|
28
|
+
const COLORS = ['bg-primary-container text-on-primary-container', 'bg-secondary-container text-on-secondary-container', 'bg-tertiary-container text-on-tertiary-container']
|
|
29
|
+
const avatarColor = computed(() => {
|
|
30
|
+
let h = 0
|
|
31
|
+
for (const c of props.comment.author.name) h = (h * 31 + c.charCodeAt(0)) | 0
|
|
32
|
+
return COLORS[Math.abs(h) % COLORS.length]
|
|
33
|
+
})
|
|
34
|
+
const initials = computed(() => {
|
|
35
|
+
const parts = props.comment.author.name.trim().split(/\s+/)
|
|
36
|
+
return ((parts[0]?.[0] ?? '') + (parts.length > 1 ? parts[parts.length - 1]![0] : '')).toUpperCase()
|
|
37
|
+
})
|
|
38
|
+
// @mentions in the text stand out
|
|
39
|
+
const pieces = computed(() => props.comment.text.split(/(@[\p{L}\p{N}_.-]+)/u).map((text) => ({ text, mention: text.startsWith('@') })))
|
|
40
|
+
const showRepliesLabel = computed(() =>
|
|
41
|
+
replies.value.length === 1 ? t.commentShowReply : t.commentShowReplies.replace('{count}', String(replies.value.length)),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
function startReply() {
|
|
45
|
+
ctx.editing.value = null
|
|
46
|
+
ctx.replyTo.value = props.comment.id
|
|
47
|
+
expanded.value = true
|
|
48
|
+
}
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<template>
|
|
52
|
+
<div class="flex gap-3" :data-comment-id="comment.id">
|
|
53
|
+
<div class="flex shrink-0 flex-col items-center">
|
|
54
|
+
<img v-if="comment.author.avatar" :src="comment.author.avatar" :alt="comment.author.name" class="rounded-full object-cover" :style="{ width: `${size}px`, height: `${size}px` }">
|
|
55
|
+
<span
|
|
56
|
+
v-else
|
|
57
|
+
class="flex items-center justify-center rounded-full font-medium"
|
|
58
|
+
:class="avatarColor"
|
|
59
|
+
:style="{ width: `${size}px`, height: `${size}px`, fontSize: `${Math.round(size * 0.4)}px` }"
|
|
60
|
+
aria-hidden="true"
|
|
61
|
+
>{{ initials }}</span>
|
|
62
|
+
<!-- The thread line, down to the replies -->
|
|
63
|
+
<span v-if="replies.length && expanded" class="mt-1 w-0.5 flex-1 rounded-full bg-outline-variant" aria-hidden="true" />
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<div class="min-w-0 flex-1">
|
|
67
|
+
<div class="flex items-center gap-2">
|
|
68
|
+
<span class="truncate text-title-small text-on-surface">{{ comment.author.name }}</span>
|
|
69
|
+
<time class="shrink-0 text-body-small text-on-surface-variant" :datetime="new Date(comment.createdAt).toISOString()">{{ ctx.relative(comment.createdAt) }}</time>
|
|
70
|
+
<span v-if="comment.edited" class="shrink-0 text-body-small text-on-surface-variant">· {{ t.commentEdited }}</span>
|
|
71
|
+
<span class="flex-1" />
|
|
72
|
+
<MMenu v-if="canEdit && !editing" align="end">
|
|
73
|
+
<template #trigger>
|
|
74
|
+
<MIconButton icon="more_vert" :label="t.commentActions" size="xs" class="-my-2 shrink-0" />
|
|
75
|
+
</template>
|
|
76
|
+
<MMenuItem icon="edit" @click="ctx.replyTo.value = null; ctx.editing.value = comment.id">{{ t.commentEdit }}</MMenuItem>
|
|
77
|
+
<MMenuItem icon="delete" @click="ctx.remove(comment)">{{ t.commentDelete }}</MMenuItem>
|
|
78
|
+
</MMenu>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<CommentComposer
|
|
82
|
+
v-if="editing"
|
|
83
|
+
class="mt-2"
|
|
84
|
+
:label="t.commentEdit"
|
|
85
|
+
:initial="comment.text"
|
|
86
|
+
:submit-label="t.commentSave"
|
|
87
|
+
:mention-sources="ctx.mentionSources.value"
|
|
88
|
+
cancelable
|
|
89
|
+
autofocus
|
|
90
|
+
@submit="(text) => { ctx.edit(comment, text); ctx.editing.value = null }"
|
|
91
|
+
@cancel="ctx.editing.value = null"
|
|
92
|
+
/>
|
|
93
|
+
<p v-else class="mt-0.5 text-body-medium break-words whitespace-pre-line text-on-surface">
|
|
94
|
+
<template v-for="(p, i) in pieces" :key="i"><span v-if="p.mention" class="font-medium text-primary">{{ p.text }}</span><template v-else>{{ p.text }}</template></template>
|
|
95
|
+
</p>
|
|
96
|
+
|
|
97
|
+
<div v-if="!editing" class="mt-1 flex flex-wrap items-center gap-2">
|
|
98
|
+
<button
|
|
99
|
+
v-if="ctx.replies.value"
|
|
100
|
+
v-ripple
|
|
101
|
+
type="button"
|
|
102
|
+
class="relative -ms-2 rounded-full px-2 py-1 text-label-large text-on-surface-variant outline-none hover:bg-on-surface/8 focus-visible:ring-2 focus-visible:ring-secondary active:bg-on-surface/10"
|
|
103
|
+
@click="startReply"
|
|
104
|
+
>{{ t.commentReply }}</button>
|
|
105
|
+
<MReactions
|
|
106
|
+
v-if="ctx.reactions.value"
|
|
107
|
+
size="small"
|
|
108
|
+
:model-value="comment.reactions ?? []"
|
|
109
|
+
@update:model-value="(list) => ctx.react(comment, list)"
|
|
110
|
+
/>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
<CommentComposer
|
|
114
|
+
v-if="replying"
|
|
115
|
+
class="mt-2"
|
|
116
|
+
:label="t.commentReplyTo.replace('{name}', comment.author.name)"
|
|
117
|
+
:submit-label="t.commentSend"
|
|
118
|
+
:mention-sources="ctx.mentionSources.value"
|
|
119
|
+
cancelable
|
|
120
|
+
autofocus
|
|
121
|
+
@submit="(text) => { ctx.reply(comment, text); ctx.replyTo.value = null }"
|
|
122
|
+
@cancel="ctx.replyTo.value = null"
|
|
123
|
+
/>
|
|
124
|
+
|
|
125
|
+
<template v-if="replies.length">
|
|
126
|
+
<button
|
|
127
|
+
v-ripple
|
|
128
|
+
type="button"
|
|
129
|
+
class="relative -ms-2 mt-1 inline-flex items-center gap-1 rounded-full px-2 py-1 text-label-large text-primary outline-none hover:bg-primary/8 focus-visible:ring-2 focus-visible:ring-secondary active:bg-primary/10"
|
|
130
|
+
:aria-expanded="expanded"
|
|
131
|
+
@click="expanded = !expanded"
|
|
132
|
+
>
|
|
133
|
+
<span class="material-symbols-outlined text-[18px] transition-transform" :class="expanded && 'rotate-180'" aria-hidden="true">expand_more</span>
|
|
134
|
+
{{ expanded ? t.commentHideReplies : showRepliesLabel }}
|
|
135
|
+
</button>
|
|
136
|
+
<div v-if="expanded" class="mt-3 flex flex-col gap-4" :class="!nests && '-ms-11'">
|
|
137
|
+
<MComment v-for="r in replies" :key="r.id" :comment="r" :depth="nests ? depth + 1 : depth" />
|
|
138
|
+
</div>
|
|
139
|
+
</template>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
</template>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Internal (MCommentThread): the box to write a comment, a reply or an edit. Ctrl/Cmd+Enter sends.
|
|
3
|
+
import { nextTick, onMounted, ref } from 'vue'
|
|
4
|
+
import MTextField from './MTextField.vue'
|
|
5
|
+
import MMentionField from './MMentionField.vue'
|
|
6
|
+
import type { MentionSource } from './MMentionField.vue'
|
|
7
|
+
import MButton from './MButton.vue'
|
|
8
|
+
import { useLocale } from '../composables/useLocale'
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
|
+
label: string
|
|
12
|
+
initial?: string
|
|
13
|
+
submitLabel: string
|
|
14
|
+
/** Shows Cancel and keeps the buttons visible (a reply or an edit) */
|
|
15
|
+
cancelable?: boolean
|
|
16
|
+
autofocus?: boolean
|
|
17
|
+
mentionSources?: MentionSource[]
|
|
18
|
+
}>(), { initial: '', cancelable: false, autofocus: false })
|
|
19
|
+
|
|
20
|
+
const emit = defineEmits<{ submit: [text: string]; cancel: [] }>()
|
|
21
|
+
|
|
22
|
+
const t = useLocale()
|
|
23
|
+
const text = ref(props.initial)
|
|
24
|
+
const field = ref<{ focus: () => void } | null>(null)
|
|
25
|
+
|
|
26
|
+
function submit() {
|
|
27
|
+
const value = text.value.trim()
|
|
28
|
+
if (!value) return
|
|
29
|
+
emit('submit', value)
|
|
30
|
+
text.value = ''
|
|
31
|
+
}
|
|
32
|
+
function onKeydown(e: KeyboardEvent) {
|
|
33
|
+
if (e.defaultPrevented) return
|
|
34
|
+
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) { e.preventDefault(); submit() }
|
|
35
|
+
else if (e.key === 'Escape' && props.cancelable) { e.preventDefault(); emit('cancel') }
|
|
36
|
+
}
|
|
37
|
+
onMounted(() => { if (props.autofocus) nextTick(() => field.value?.focus()) })
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<template>
|
|
41
|
+
<div class="flex flex-col gap-2" @keydown="onKeydown">
|
|
42
|
+
<MMentionField
|
|
43
|
+
v-if="mentionSources?.length"
|
|
44
|
+
ref="field"
|
|
45
|
+
v-model="text"
|
|
46
|
+
:sources="mentionSources"
|
|
47
|
+
:label="label"
|
|
48
|
+
multiline
|
|
49
|
+
:rows="1"
|
|
50
|
+
auto-grow
|
|
51
|
+
:max-rows="8"
|
|
52
|
+
/>
|
|
53
|
+
<MTextField
|
|
54
|
+
v-else
|
|
55
|
+
ref="field"
|
|
56
|
+
v-model="text"
|
|
57
|
+
:label="label"
|
|
58
|
+
multiline
|
|
59
|
+
:rows="1"
|
|
60
|
+
auto-grow
|
|
61
|
+
:max-rows="8"
|
|
62
|
+
/>
|
|
63
|
+
<div v-if="cancelable || text.trim()" class="flex justify-end gap-2">
|
|
64
|
+
<MButton v-if="cancelable" variant="text" size="sm" @click="emit('cancel')">{{ t.cancel }}</MButton>
|
|
65
|
+
<MButton variant="filled" size="sm" :disabled="!text.trim()" @click="submit">{{ submitLabel }}</MButton>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</template>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Internal: what MCommentThread shares with its comments (_MComment), and the public comment types.
|
|
2
|
+
import type { InjectionKey, Ref } from 'vue'
|
|
3
|
+
import type { Reaction } from './MReactions.vue'
|
|
4
|
+
import type { MentionSource } from './MMentionField.vue'
|
|
5
|
+
import type { M3Locale } from '../composables/useLocale'
|
|
6
|
+
|
|
7
|
+
/** Who wrote a comment */
|
|
8
|
+
export interface CommentAuthor {
|
|
9
|
+
name: string
|
|
10
|
+
/** Photo URL; without it, initials */
|
|
11
|
+
avatar?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** One comment of an `MCommentThread`, with its replies */
|
|
15
|
+
export interface CommentItem {
|
|
16
|
+
id: string | number
|
|
17
|
+
author: CommentAuthor
|
|
18
|
+
text: string
|
|
19
|
+
/** When it was written: a Date, an ISO string or a timestamp */
|
|
20
|
+
createdAt: Date | string | number
|
|
21
|
+
/** Shows "edited" next to the time */
|
|
22
|
+
edited?: boolean
|
|
23
|
+
replies?: CommentItem[]
|
|
24
|
+
reactions?: Reaction[]
|
|
25
|
+
/** The current user wrote it: they can edit and delete it (see `canEdit`) */
|
|
26
|
+
mine?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface CommentThreadContext {
|
|
30
|
+
locale: M3Locale
|
|
31
|
+
maxDepth: Ref<number>
|
|
32
|
+
repliesShown: Ref<number>
|
|
33
|
+
replies: Ref<boolean>
|
|
34
|
+
reactions: Ref<boolean>
|
|
35
|
+
mentionSources: Ref<MentionSource[] | undefined>
|
|
36
|
+
replyTo: Ref<string | number | null>
|
|
37
|
+
editing: Ref<string | number | null>
|
|
38
|
+
canEdit: (c: CommentItem) => boolean
|
|
39
|
+
relative: (date: Date | string | number) => string
|
|
40
|
+
reply: (c: CommentItem, text: string) => void
|
|
41
|
+
edit: (c: CommentItem, text: string) => void
|
|
42
|
+
remove: (c: CommentItem) => void
|
|
43
|
+
react: (c: CommentItem, reactions: Reaction[]) => void
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const COMMENT_THREAD_KEY: InjectionKey<CommentThreadContext> = Symbol('m-comment-thread')
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Fragment, type VNode } from 'vue'
|
|
2
|
+
import MMenuDivider from '../components/MMenuDivider.vue'
|
|
3
|
+
|
|
4
|
+
function flattenVNodes(vnodes: VNode[]): VNode[] {
|
|
5
|
+
const out: VNode[] = []
|
|
6
|
+
for (const vnode of vnodes) {
|
|
7
|
+
if (vnode.type === Fragment && Array.isArray(vnode.children)) out.push(...flattenVNodes(vnode.children as VNode[]))
|
|
8
|
+
else out.push(vnode)
|
|
9
|
+
}
|
|
10
|
+
return out
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isGapDivider(vnode: VNode): boolean {
|
|
14
|
+
if (vnode.type !== MMenuDivider) return false
|
|
15
|
+
const gap = (vnode.props as { gap?: unknown } | null)?.gap
|
|
16
|
+
return gap === '' || gap === true || gap === 'true'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Splits a menu's slot content into groups at each `<MMenuDivider gap />`, for the expressive variant's
|
|
21
|
+
* independently-rounded group boxes (MMenu, MContextMenu, and MMenuItem's flyout submenus). A plain
|
|
22
|
+
* `<MMenuDivider />` stays an in-line divider inside its group. Returns empty groups filtered out.
|
|
23
|
+
*/
|
|
24
|
+
export function splitMenuGroups(vnodes: VNode[]): VNode[][] {
|
|
25
|
+
const result: VNode[][] = [[]]
|
|
26
|
+
for (const vnode of flattenVNodes(vnodes)) {
|
|
27
|
+
if (isGapDivider(vnode)) result.push([])
|
|
28
|
+
else result[result.length - 1]!.push(vnode)
|
|
29
|
+
}
|
|
30
|
+
return result.filter((g) => g.length > 0)
|
|
31
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { computed, onMounted, onUnmounted, ref, watch, type Ref } from 'vue'
|
|
2
|
+
import { isRtl, logicalKey } from './_rtl'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Pane resizing for the two-pane adaptive layouts (MListDetail, MSupportingPane), after androidx
|
|
6
|
+
* material3-adaptive's `PaneExpansionState`: the user drags the handle in the 24dp spacer; on release the pane
|
|
7
|
+
* settles to the closest anchor, or, flung past 200px/s, to the closest anchor in the fling's direction
|
|
8
|
+
* (`getPositionOfTheClosestAnchor`), with Compose's default anchoring spring (dampingRatio 0.8, stiffness 380).
|
|
9
|
+
* A tap or Enter on the handle goes to the next wider anchor (the first one after the widest).
|
|
10
|
+
*
|
|
11
|
+
* Departure: Compose's anchors place the end of the *first* pane; here they're the width of the side pane
|
|
12
|
+
* (the list, the supporting pane), so 360/412 mean the same in both layouts. 0 collapses that pane, '100%' the
|
|
13
|
+
* other one. Widths are written to the DOM imperatively (no per-frame re-render of the slots).
|
|
14
|
+
*/
|
|
15
|
+
export type PaneAnchor = number | `${number}%`
|
|
16
|
+
|
|
17
|
+
export const DEFAULT_PANE_ANCHORS: PaneAnchor[] = [0, 360, 412, '50%', '100%']
|
|
18
|
+
export const PANE_SPACER = 24
|
|
19
|
+
|
|
20
|
+
const STIFFNESS = 380
|
|
21
|
+
const DAMPING = 0.8
|
|
22
|
+
const VELOCITY_THRESHOLD = 200
|
|
23
|
+
const SUBSTEP = 0.004
|
|
24
|
+
const TAP_SLOP = 4
|
|
25
|
+
|
|
26
|
+
export function usePaneResize(o: {
|
|
27
|
+
/** The resized pane */
|
|
28
|
+
pane: Ref<HTMLElement | undefined>
|
|
29
|
+
/** The handle (separator) */
|
|
30
|
+
handle: Ref<HTMLElement | undefined>
|
|
31
|
+
/** resizable && two panes */
|
|
32
|
+
enabled: () => boolean
|
|
33
|
+
/** Which side of the layout the resized pane is on */
|
|
34
|
+
side: 'start' | 'end'
|
|
35
|
+
/** The layout's width */
|
|
36
|
+
width: Ref<number>
|
|
37
|
+
anchors: () => PaneAnchor[] | undefined
|
|
38
|
+
/** The pane's width before any resize (a CSS length) */
|
|
39
|
+
initial: () => string
|
|
40
|
+
storageKey: () => string | undefined
|
|
41
|
+
/** Emitted after a resize settles */
|
|
42
|
+
onChange?: (anchor: PaneAnchor) => void
|
|
43
|
+
}) {
|
|
44
|
+
const anchor = ref<PaneAnchor | null>(null)
|
|
45
|
+
const dragging = ref(false)
|
|
46
|
+
/** Which pane a settled resize has collapsed: the resized one ('pane') or the other one ('other') */
|
|
47
|
+
const collapsed = ref<'pane' | 'other' | null>(null)
|
|
48
|
+
/** The handle's position along the layout, 0–100, for aria-valuenow */
|
|
49
|
+
const position = ref(0)
|
|
50
|
+
|
|
51
|
+
const anchors = () => {
|
|
52
|
+
const list = o.anchors()
|
|
53
|
+
return list && list.length ? list : DEFAULT_PANE_ANCHORS
|
|
54
|
+
}
|
|
55
|
+
const avail = () => Math.max(0, o.width.value - PANE_SPACER)
|
|
56
|
+
const clamp = (px: number) => Math.min(avail(), Math.max(0, px))
|
|
57
|
+
const resolve = (a: PaneAnchor) =>
|
|
58
|
+
clamp(typeof a === 'number' ? a : (parseFloat(a) / 100) * avail())
|
|
59
|
+
const same = (a: PaneAnchor, b: PaneAnchor) => String(a) === String(b)
|
|
60
|
+
|
|
61
|
+
let px = 0
|
|
62
|
+
let owned = false // the width on the pane is ours
|
|
63
|
+
let busy = false // dragging or settling: the watcher below leaves the width alone
|
|
64
|
+
let raf = 0
|
|
65
|
+
|
|
66
|
+
function write(value: number) {
|
|
67
|
+
px = value
|
|
68
|
+
if (o.pane.value) o.pane.value.style.width = `${value}px`
|
|
69
|
+
}
|
|
70
|
+
function settled() {
|
|
71
|
+
const max = avail()
|
|
72
|
+
collapsed.value = px <= 0.5 ? 'pane' : px >= max - 0.5 && max > 0 ? 'other' : null
|
|
73
|
+
const handlePos = o.side === 'start' ? px : max - px
|
|
74
|
+
position.value = max ? Math.round((handlePos / max) * 100) : 0
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Lays the pane out from the settled anchor (or the initial width) whenever the layout changes
|
|
78
|
+
function apply() {
|
|
79
|
+
const el = o.pane.value
|
|
80
|
+
if (!el || busy) return
|
|
81
|
+
if (!o.enabled()) {
|
|
82
|
+
// Clears only its own width: without `resizable` the template binds it
|
|
83
|
+
if (owned) el.style.width = ''
|
|
84
|
+
owned = false
|
|
85
|
+
collapsed.value = null
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
owned = true
|
|
89
|
+
if (anchor.value !== null) {
|
|
90
|
+
write(resolve(anchor.value))
|
|
91
|
+
} else {
|
|
92
|
+
const css = o.initial().trim()
|
|
93
|
+
el.style.width = css
|
|
94
|
+
// px and % resolve without reading layout; anything else (rem, calc) is measured
|
|
95
|
+
if (/^[\d.]+px$/.test(css)) px = clamp(parseFloat(css))
|
|
96
|
+
else if (/^[\d.]+%$/.test(css)) px = resolve(css as PaneAnchor)
|
|
97
|
+
else px = el.offsetWidth
|
|
98
|
+
}
|
|
99
|
+
settled()
|
|
100
|
+
}
|
|
101
|
+
watch([() => o.enabled(), o.width, () => o.initial(), anchor, () => String(anchors())], apply, { flush: 'post' })
|
|
102
|
+
|
|
103
|
+
onMounted(() => {
|
|
104
|
+
const key = o.storageKey()
|
|
105
|
+
if (key) {
|
|
106
|
+
try {
|
|
107
|
+
const raw = localStorage.getItem(`m3-pane-${key}`)
|
|
108
|
+
if (raw !== null) {
|
|
109
|
+
const saved = JSON.parse(raw) as PaneAnchor
|
|
110
|
+
if (anchors().some((a) => same(a, saved))) anchor.value = saved
|
|
111
|
+
}
|
|
112
|
+
} catch { /* unavailable or malformed: keep the default */ }
|
|
113
|
+
}
|
|
114
|
+
apply()
|
|
115
|
+
})
|
|
116
|
+
onUnmounted(() => cancelAnimationFrame(raf))
|
|
117
|
+
|
|
118
|
+
function commit(a: PaneAnchor) {
|
|
119
|
+
anchor.value = a
|
|
120
|
+
const key = o.storageKey()
|
|
121
|
+
if (key) {
|
|
122
|
+
try { localStorage.setItem(`m3-pane-${key}`, JSON.stringify(a)) } catch { /* ignore */ }
|
|
123
|
+
}
|
|
124
|
+
o.onChange?.(a)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function animateTo(a: PaneAnchor, velocity = 0) {
|
|
128
|
+
cancelAnimationFrame(raf)
|
|
129
|
+
const target = resolve(a)
|
|
130
|
+
const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
131
|
+
if (reduced || !o.pane.value) {
|
|
132
|
+
busy = false
|
|
133
|
+
write(target)
|
|
134
|
+
commit(a)
|
|
135
|
+
settled()
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
busy = true
|
|
139
|
+
collapsed.value = null // shown while it opens; settled() hides it again if it ends collapsed
|
|
140
|
+
let pos = px
|
|
141
|
+
let vel = velocity
|
|
142
|
+
let last = performance.now()
|
|
143
|
+
const c = 2 * DAMPING * Math.sqrt(STIFFNESS)
|
|
144
|
+
const frame = (now: number) => {
|
|
145
|
+
let dt = Math.min((now - last) / 1000, 1 / 30)
|
|
146
|
+
last = now
|
|
147
|
+
while (dt > 0) {
|
|
148
|
+
const h = Math.min(dt, SUBSTEP)
|
|
149
|
+
dt -= h
|
|
150
|
+
vel += (-STIFFNESS * (pos - target) - c * vel) * h
|
|
151
|
+
pos += vel * h
|
|
152
|
+
}
|
|
153
|
+
if (Math.abs(pos - target) < 0.5 && Math.abs(vel) < 1) {
|
|
154
|
+
raf = 0
|
|
155
|
+
busy = false
|
|
156
|
+
write(target)
|
|
157
|
+
commit(a)
|
|
158
|
+
settled()
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
write(clamp(pos))
|
|
162
|
+
raf = requestAnimationFrame(frame)
|
|
163
|
+
}
|
|
164
|
+
raf = requestAnimationFrame(frame)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** The anchor a release at `px` with `velocity` (px/s, positive = wider) settles to */
|
|
168
|
+
function settleAnchor(velocity: number): PaneAnchor {
|
|
169
|
+
const list = anchors()
|
|
170
|
+
const max = avail()
|
|
171
|
+
const cost = (a: PaneAnchor) => {
|
|
172
|
+
const delta = resolve(a) - px
|
|
173
|
+
if (velocity >= VELOCITY_THRESHOLD) return delta < 0 ? max - delta : delta
|
|
174
|
+
if (velocity <= -VELOCITY_THRESHOLD) return delta > 0 ? max + delta : -delta
|
|
175
|
+
return Math.abs(delta)
|
|
176
|
+
}
|
|
177
|
+
return list.reduce((best, a) => (cost(a) < cost(best) ? a : best), list[0]!)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** The next wider anchor, or the narrowest after the widest (tap / Enter on the handle) */
|
|
181
|
+
function nextAnchor(): PaneAnchor {
|
|
182
|
+
const sorted = [...anchors()].sort((a, b) => resolve(a) - resolve(b))
|
|
183
|
+
return sorted.find((a) => resolve(a) > px + 0.5) ?? sorted[0]!
|
|
184
|
+
}
|
|
185
|
+
function stepAnchor(dir: 1 | -1): PaneAnchor {
|
|
186
|
+
const sorted = [...anchors()].sort((a, b) => resolve(a) - resolve(b))
|
|
187
|
+
if (dir > 0) return sorted.find((a) => resolve(a) > px + 0.5) ?? sorted[sorted.length - 1]!
|
|
188
|
+
return [...sorted].reverse().find((a) => resolve(a) < px - 0.5) ?? sorted[0]!
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Pointer drag
|
|
192
|
+
let startX = 0
|
|
193
|
+
let startPx = 0
|
|
194
|
+
let moved = false
|
|
195
|
+
let samples: { t: number; px: number }[] = []
|
|
196
|
+
let sign = 1
|
|
197
|
+
|
|
198
|
+
function onPointerDown(e: PointerEvent) {
|
|
199
|
+
if (e.button !== 0 || !o.enabled() || !o.pane.value) return
|
|
200
|
+
cancelAnimationFrame(raf)
|
|
201
|
+
raf = 0
|
|
202
|
+
busy = true
|
|
203
|
+
;(e.currentTarget as HTMLElement).setPointerCapture?.(e.pointerId)
|
|
204
|
+
startX = e.clientX
|
|
205
|
+
startPx = px
|
|
206
|
+
moved = false
|
|
207
|
+
samples = [{ t: e.timeStamp, px }]
|
|
208
|
+
// The pane grows toward the handle's movement on the start side, away from it on the end side
|
|
209
|
+
sign = (o.side === 'start' ? 1 : -1) * (isRtl(o.handle.value) ? -1 : 1)
|
|
210
|
+
dragging.value = true
|
|
211
|
+
collapsed.value = null
|
|
212
|
+
document.body.style.userSelect = 'none'
|
|
213
|
+
}
|
|
214
|
+
function onPointerMove(e: PointerEvent) {
|
|
215
|
+
if (!dragging.value) return
|
|
216
|
+
const dx = (e.clientX - startX) * sign
|
|
217
|
+
if (!moved && Math.abs(dx) < TAP_SLOP) return
|
|
218
|
+
moved = true
|
|
219
|
+
write(clamp(startPx + dx))
|
|
220
|
+
samples.push({ t: e.timeStamp, px })
|
|
221
|
+
if (samples.length > 8) samples.shift()
|
|
222
|
+
}
|
|
223
|
+
function onPointerUp(e: PointerEvent) {
|
|
224
|
+
if (!dragging.value) return
|
|
225
|
+
dragging.value = false
|
|
226
|
+
document.body.style.userSelect = ''
|
|
227
|
+
if (!moved) {
|
|
228
|
+
animateTo(nextAnchor())
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
// Velocity over the last ~100ms of movement
|
|
232
|
+
const recent = samples.filter((s) => e.timeStamp - s.t <= 100)
|
|
233
|
+
const first = recent[0] ?? samples[0]!
|
|
234
|
+
const last = samples[samples.length - 1]!
|
|
235
|
+
const dt = (last.t - first.t) / 1000
|
|
236
|
+
const velocity = dt > 0 ? (last.px - first.px) / dt : 0
|
|
237
|
+
animateTo(settleAnchor(velocity), velocity)
|
|
238
|
+
}
|
|
239
|
+
function onPointerCancel() {
|
|
240
|
+
if (!dragging.value) return
|
|
241
|
+
dragging.value = false
|
|
242
|
+
document.body.style.userSelect = ''
|
|
243
|
+
animateTo(settleAnchor(0))
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function onKeydown(e: KeyboardEvent) {
|
|
247
|
+
if (!o.enabled()) return
|
|
248
|
+
const key = logicalKey(e, o.handle.value)
|
|
249
|
+
// ArrowRight moves the handle toward the end: the start pane grows, the end pane shrinks
|
|
250
|
+
const grow = o.side === 'start' ? 1 : -1
|
|
251
|
+
let target: PaneAnchor | null = null
|
|
252
|
+
const sorted = () => [...anchors()].sort((a, b) => resolve(a) - resolve(b))
|
|
253
|
+
if (key === 'ArrowRight') target = stepAnchor(grow as 1 | -1)
|
|
254
|
+
else if (key === 'ArrowLeft') target = stepAnchor(-grow as 1 | -1)
|
|
255
|
+
else if (e.key === 'Home') target = o.side === 'start' ? sorted()[0]! : sorted()[sorted().length - 1]!
|
|
256
|
+
else if (e.key === 'End') target = o.side === 'start' ? sorted()[sorted().length - 1]! : sorted()[0]!
|
|
257
|
+
else if (e.key === 'Enter' || e.key === ' ') target = nextAnchor()
|
|
258
|
+
if (target === null) return
|
|
259
|
+
e.preventDefault()
|
|
260
|
+
animateTo(target)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const handlers = {
|
|
264
|
+
pointerdown: onPointerDown,
|
|
265
|
+
pointermove: onPointerMove,
|
|
266
|
+
pointerup: onPointerUp,
|
|
267
|
+
pointercancel: onPointerCancel,
|
|
268
|
+
keydown: onKeydown,
|
|
269
|
+
}
|
|
270
|
+
return { dragging, collapsed, position, anchor: computed(() => anchor.value), handlers }
|
|
271
|
+
}
|
|
@@ -349,6 +349,28 @@ export interface M3Locale {
|
|
|
349
349
|
codeCopy: string
|
|
350
350
|
/** MCodeEditor: shown once the code is copied */
|
|
351
351
|
codeCopied: string
|
|
352
|
+
/** Pane resize handle of MListDetail / MSupportingPane */
|
|
353
|
+
paneResize: string
|
|
354
|
+
/** Composer placeholder of MCommentThread */
|
|
355
|
+
commentPlaceholder: string
|
|
356
|
+
/** Reply composer label of MCommentThread ({name}) */
|
|
357
|
+
commentReplyTo: string
|
|
358
|
+
commentReply: string
|
|
359
|
+
commentEdit: string
|
|
360
|
+
commentDelete: string
|
|
361
|
+
commentSave: string
|
|
362
|
+
commentSend: string
|
|
363
|
+
commentEdited: string
|
|
364
|
+
commentActions: string
|
|
365
|
+
commentShowReply: string
|
|
366
|
+
/** MCommentThread collapsed replies ({count}) */
|
|
367
|
+
commentShowReplies: string
|
|
368
|
+
commentHideReplies: string
|
|
369
|
+
reactionAdd: string
|
|
370
|
+
/** Accessible label of an MReactions chip ({emoji}, {count}) */
|
|
371
|
+
reactionCount: string
|
|
372
|
+
/** MAvatarGroup overflow chip label ({count}) */
|
|
373
|
+
avatarGroupMore: string
|
|
352
374
|
/** MFormBuilder: what the preview submitted */
|
|
353
375
|
formBuilderSubmitted: string
|
|
354
376
|
/** MFormBuilder: the inspector with nothing selected */
|
|
@@ -1188,6 +1210,22 @@ export const defaultLocale: M3Locale = {
|
|
|
1188
1210
|
formBuilderCopied: 'Copied',
|
|
1189
1211
|
codeCopy: 'Copy code',
|
|
1190
1212
|
codeCopied: 'Copied',
|
|
1213
|
+
paneResize: 'Resize panes',
|
|
1214
|
+
commentPlaceholder: 'Add a comment…',
|
|
1215
|
+
commentReplyTo: 'Reply to {name}…',
|
|
1216
|
+
commentReply: 'Reply',
|
|
1217
|
+
commentEdit: 'Edit',
|
|
1218
|
+
commentDelete: 'Delete',
|
|
1219
|
+
commentSave: 'Save',
|
|
1220
|
+
commentSend: 'Send',
|
|
1221
|
+
commentEdited: 'edited',
|
|
1222
|
+
commentActions: 'Comment actions',
|
|
1223
|
+
commentShowReply: 'View 1 reply',
|
|
1224
|
+
commentShowReplies: 'View {count} replies',
|
|
1225
|
+
commentHideReplies: 'Hide replies',
|
|
1226
|
+
reactionAdd: 'Add reaction',
|
|
1227
|
+
reactionCount: '{emoji}: {count}',
|
|
1228
|
+
avatarGroupMore: '{count} more',
|
|
1191
1229
|
formBuilderSubmitted: 'Submitted values',
|
|
1192
1230
|
formBuilderSelectField: 'Select a field to edit it',
|
|
1193
1231
|
formFieldText: 'Text',
|