@m3ui-vue/m3ui-vue 1.2.2 → 1.3.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/dist/API.md +2776 -351
- package/dist/MButton-CuNzpoxm.js +172 -0
- package/dist/MButton-CuNzpoxm.js.map +1 -0
- package/dist/MDialog-HxEL-m58.js +173 -0
- package/dist/MDialog-HxEL-m58.js.map +1 -0
- package/dist/MIconButton-DoNotQ9v.js +282 -0
- package/dist/MIconButton-DoNotQ9v.js.map +1 -0
- package/dist/MListItem-DnPtv-hY.js +824 -0
- package/dist/MListItem-DnPtv-hY.js.map +1 -0
- package/dist/MLoadingIndicator-BQMNX6Dx.js +115 -0
- package/dist/MLoadingIndicator-BQMNX6Dx.js.map +1 -0
- package/dist/MMenuItem-Bih0h4-n.js +604 -0
- package/dist/MMenuItem-Bih0h4-n.js.map +1 -0
- package/dist/MProgressBar-BCoruxA-.js +184 -0
- package/dist/MProgressBar-BCoruxA-.js.map +1 -0
- package/dist/MSeekBar-LURE1Ah7.js +435 -0
- package/dist/MSeekBar-LURE1Ah7.js.map +1 -0
- package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
- package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
- package/dist/MSlider-_J4IS2_z.js +691 -0
- package/dist/MSlider-_J4IS2_z.js.map +1 -0
- package/dist/MSpinner-BhkMYKOM.js +65 -0
- package/dist/MSpinner-BhkMYKOM.js.map +1 -0
- package/dist/MTextField-CkzwNBWS.js +296 -0
- package/dist/MTextField-CkzwNBWS.js.map +1 -0
- package/dist/MTooltip-B67ZDSGp.js +756 -0
- package/dist/MTooltip-B67ZDSGp.js.map +1 -0
- package/dist/_storageKeys-CYXsUBwK.js +18 -0
- package/dist/_storageKeys-CYXsUBwK.js.map +1 -0
- package/dist/_useEscapeStack-CjndQhqg.js +19 -0
- package/dist/_useEscapeStack-CjndQhqg.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAudioPlayer.vue.d.ts +115 -0
- package/dist/components/MBadge.vue.d.ts +1 -1
- package/dist/components/MBottomSheetScaffold.vue.d.ts +1 -1
- package/dist/components/MBox.vue.d.ts +1 -1
- package/dist/components/MButton.vue.d.ts +1 -1
- package/dist/components/MConfirmDialog.vue.d.ts +1 -1
- package/dist/components/MCopyButton.vue.d.ts +2 -2
- package/dist/components/MDataTable.vue.d.ts +2 -2
- package/dist/components/MDialog.vue.d.ts +2 -2
- package/dist/components/MDivider.vue.d.ts +1 -1
- package/dist/components/MDragHandle.vue.d.ts +1 -1
- package/dist/components/MDrawCanvas.vue.d.ts +148 -0
- package/dist/components/MDrawLayers.vue.d.ts +3 -0
- package/dist/components/MDrawToolbar.vue.d.ts +34 -0
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +2 -2
- package/dist/components/MFixed.vue.d.ts +1 -1
- package/dist/components/MFlex.vue.d.ts +2 -2
- package/dist/components/MFloorPlan.vue.d.ts +160 -0
- package/dist/components/MFlow.vue.d.ts +305 -0
- package/dist/components/MFlowControls.vue.d.ts +33 -0
- package/dist/components/MFlowHandle.vue.d.ts +16 -0
- package/dist/components/MFlowMinimap.vue.d.ts +22 -0
- package/dist/components/MFlowNode.vue.d.ts +35 -0
- package/dist/components/MGantt.vue.d.ts +141 -0
- package/dist/components/MGanttControls.vue.d.ts +32 -0
- package/dist/components/MIconButton.vue.d.ts +3 -1
- package/dist/components/MImageCropper.vue.d.ts +110 -0
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MLightbox.vue.d.ts +2 -2
- package/dist/components/MList.vue.d.ts +1 -1
- package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
- package/dist/components/MMapControl.vue.d.ts +1 -1
- package/dist/components/MMapSearch.vue.d.ts +1 -1
- package/dist/components/MMaskField.vue.d.ts +12 -1
- package/dist/components/MMenu.vue.d.ts +1 -1
- package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
- package/dist/components/MNumberField.vue.d.ts +11 -2
- package/dist/components/MPdfViewer.vue.d.ts +174 -0
- package/dist/components/MPullToRefresh.vue.d.ts +1 -1
- package/dist/components/MResourceTimeline.vue.d.ts +149 -0
- package/dist/components/MScheduler.vue.d.ts +3 -3
- package/dist/components/MScheme.vue.d.ts +1 -1
- package/dist/components/MSearchField.vue.d.ts +1 -1
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
- package/dist/components/MSkeleton.vue.d.ts +1 -1
- package/dist/components/MSlider.vue.d.ts +2 -2
- package/dist/components/MSparkline.vue.d.ts +1 -1
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTagInput.vue.d.ts +12 -1
- package/dist/components/MTextField.vue.d.ts +13 -2
- package/dist/components/MToolbar.vue.d.ts +1 -1
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/MVideoPlayer.vue.d.ts +253 -0
- package/dist/components/MVirtualTable.vue.d.ts +1 -1
- package/dist/components/MWindow.vue.d.ts +3 -3
- package/dist/components/_MFlowEdge.vue.d.ts +9 -0
- package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
- package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
- package/dist/components/_MPdfPage.vue.d.ts +76 -0
- package/dist/components/_MTimeBackground.vue.d.ts +14 -0
- package/dist/components/_MTimeHeader.vue.d.ts +20 -0
- package/dist/composables/_flowPanel.d.ts +2 -0
- package/dist/composables/_flowSlot.d.ts +5 -0
- package/dist/composables/_ganttTime.d.ts +41 -0
- package/dist/composables/_useTimeAxis.d.ts +90 -0
- package/dist/composables/drawGeometry.d.ts +119 -0
- package/dist/composables/flowFormats.d.ts +79 -0
- package/dist/composables/flowLayout.d.ts +45 -0
- package/dist/composables/flowPaths.d.ts +53 -0
- package/dist/composables/ganttFormats.d.ts +52 -0
- package/dist/composables/ganttSchedule.d.ts +99 -0
- package/dist/composables/useDrawing.d.ts +44 -0
- package/dist/composables/useFlow.d.ts +266 -0
- package/dist/composables/useGantt.d.ts +87 -0
- package/dist/composables/useLocale.d.ts +163 -0
- package/dist/composables/useMediaPlayer.d.ts +101 -0
- package/dist/composables/usePdf.d.ts +119 -0
- package/dist/composables/useResourceTimeline.d.ts +70 -0
- package/dist/draw.d.ts +7 -0
- package/dist/draw.js +1700 -0
- package/dist/draw.js.map +1 -0
- package/dist/flow.d.ts +14 -0
- package/dist/flow.js +3542 -0
- package/dist/flow.js.map +1 -0
- package/dist/flowPaths-CUc6X373.js +161 -0
- package/dist/flowPaths-CUc6X373.js.map +1 -0
- package/dist/gantt.d.ts +12 -0
- package/dist/gantt.js +3575 -0
- package/dist/gantt.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/locales/index.js +1148 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7286 -7654
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +113 -108
- package/dist/map.js.map +1 -1
- package/dist/media.d.ts +5 -0
- package/dist/media.js +1311 -0
- package/dist/media.js.map +1 -0
- package/dist/pdf.d.ts +4 -0
- package/dist/pdf.js +1871 -0
- package/dist/pdf.js.map +1 -0
- package/dist/rich-text-editor.js +28 -26
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-JYxDDeXC.js → useLocale-BpGxplLV.js} +165 -2
- package/dist/useLocale-BpGxplLV.js.map +1 -0
- package/dist/{useThemeTokens-y0HZpyhL.js → useThemeTokens-DQQcaWbE.js} +40 -54
- package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
- package/package.json +29 -5
- package/src/__tests__/MAudioPlayer.test.ts +75 -0
- package/src/__tests__/MDrawCanvas.test.ts +110 -0
- package/src/__tests__/MFloorPlan.test.ts +97 -0
- package/src/__tests__/MFlow.test.ts +575 -0
- package/src/__tests__/MGantt.test.ts +130 -0
- package/src/__tests__/MImageCropper.test.ts +89 -0
- package/src/__tests__/MPdfViewer.test.ts +235 -0
- package/src/__tests__/MResourceTimeline.test.ts +102 -0
- package/src/__tests__/MVideoPlayer.test.ts +201 -0
- package/src/__tests__/drawGeometry.test.ts +58 -0
- package/src/__tests__/fieldExpose.test.ts +30 -0
- package/src/__tests__/flowFormats.test.ts +185 -0
- package/src/__tests__/flowLayout.test.ts +113 -0
- package/src/__tests__/ganttFormats.test.ts +76 -0
- package/src/__tests__/ganttSchedule.test.ts +136 -0
- package/src/__tests__/pdfMock.ts +83 -0
- package/src/__tests__/useMediaPlayer.test.ts +182 -0
- package/src/__tests__/usePdf.test.ts +102 -0
- package/src/components/MAudioPlayer.vue +319 -0
- package/src/components/MDrawCanvas.vue +813 -0
- package/src/components/MDrawLayers.vue +114 -0
- package/src/components/MDrawToolbar.vue +171 -0
- package/src/components/MFloorPlan.vue +581 -0
- package/src/components/MFlow.vue +2049 -0
- package/src/components/MFlowControls.vue +110 -0
- package/src/components/MFlowHandle.vue +60 -0
- package/src/components/MFlowMinimap.vue +134 -0
- package/src/components/MFlowNode.vue +98 -0
- package/src/components/MGantt.vue +1609 -0
- package/src/components/MGanttControls.vue +77 -0
- package/src/components/MIconButton.vue +3 -1
- package/src/components/MImageCropper.vue +507 -0
- package/src/components/MMaskField.vue +13 -0
- package/src/components/MNumberField.vue +13 -0
- package/src/components/MPdfViewer.vue +1269 -0
- package/src/components/MResourceTimeline.vue +1020 -0
- package/src/components/MTagInput.vue +13 -0
- package/src/components/MTextField.vue +16 -0
- package/src/components/MVideoPlayer.vue +839 -0
- package/src/components/_MFlowEdge.vue +100 -0
- package/src/components/_MFlowEdgeLabel.vue +56 -0
- package/src/components/_MFlowNodeShell.vue +111 -0
- package/src/components/_MPdfPage.vue +456 -0
- package/src/components/_MTimeBackground.vue +16 -0
- package/src/components/_MTimeHeader.vue +31 -0
- package/src/composables/_flowPanel.ts +13 -0
- package/src/composables/_flowSlot.ts +6 -0
- package/src/composables/_ganttTime.ts +200 -0
- package/src/composables/_useTimeAxis.ts +224 -0
- package/src/composables/drawGeometry.ts +405 -0
- package/src/composables/flowFormats.ts +916 -0
- package/src/composables/flowLayout.ts +297 -0
- package/src/composables/flowPaths.ts +239 -0
- package/src/composables/ganttFormats.ts +366 -0
- package/src/composables/ganttSchedule.ts +403 -0
- package/src/composables/useDrawing.ts +53 -0
- package/src/composables/useFlow.ts +250 -0
- package/src/composables/useGantt.ts +92 -0
- package/src/composables/useLocale.ts +328 -0
- package/src/composables/useMediaPlayer.ts +406 -0
- package/src/composables/usePdf.ts +456 -0
- package/src/composables/useResourceTimeline.ts +76 -0
- package/src/draw.ts +25 -0
- package/src/flow.ts +26 -0
- package/src/gantt.ts +12 -0
- package/src/index.ts +4 -0
- package/src/locales/de.ts +163 -0
- package/src/locales/es.ts +163 -0
- package/src/locales/fr.ts +163 -0
- package/src/locales/ja.ts +163 -0
- package/src/locales/ko.ts +163 -0
- package/src/locales/pt.ts +163 -0
- package/src/locales/zh.ts +163 -0
- package/src/media.ts +5 -0
- package/src/pdf.ts +15 -0
- package/dist/MMenuItem-D4Gx_l3F.js +0 -929
- package/dist/MMenuItem-D4Gx_l3F.js.map +0 -1
- package/dist/MSlider-Dx_S3vJ9.js +0 -1506
- package/dist/MSlider-Dx_S3vJ9.js.map +0 -1
- package/dist/MTextField-Bz8JIsnl.js +0 -633
- package/dist/MTextField-Bz8JIsnl.js.map +0 -1
- package/dist/useLocale-JYxDDeXC.js.map +0 -1
- package/dist/useThemeTokens-y0HZpyhL.js.map +0 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The layers of an MDrawCanvas (put it in its default slot, or anywhere inside it): pick the one you draw on, show or
|
|
4
|
+
* hide, lock, rename (double-click), reorder, add and delete. Top layer first, as drawing apps list them. Deleting a
|
|
5
|
+
* layer deletes what's on it. Not an M3 spec component.
|
|
6
|
+
*/
|
|
7
|
+
import { computed, inject, nextTick, ref } from 'vue'
|
|
8
|
+
import { DRAW_KEY } from '../composables/useDrawing'
|
|
9
|
+
import { drawId, type DrawLayer } from '../composables/drawGeometry'
|
|
10
|
+
import { useLocale } from '../composables/useLocale'
|
|
11
|
+
import MIconButton from './MIconButton.vue'
|
|
12
|
+
import MTooltip from './MTooltip.vue'
|
|
13
|
+
|
|
14
|
+
const draw = inject(DRAW_KEY, null)
|
|
15
|
+
if (!draw) throw new Error('MDrawLayers must be inside <MDrawCanvas>')
|
|
16
|
+
const d = draw
|
|
17
|
+
const locale = useLocale()
|
|
18
|
+
|
|
19
|
+
// Without layers the canvas has one implicit layer: the first edit here makes it real
|
|
20
|
+
const list = computed<DrawLayer[]>(() => (d.layers.value.length ? d.layers.value : [{ id: 'layer-1', name: locale.drawLayer.replace('{n}', '1') }]))
|
|
21
|
+
const shown = computed(() => list.value.slice().reverse())
|
|
22
|
+
const set = (next: DrawLayer[]) => d.setLayers(next)
|
|
23
|
+
const patch = (id: string, p: Partial<DrawLayer>) => set(list.value.map((l) => (l.id === id ? { ...l, ...p } : l)))
|
|
24
|
+
function add() {
|
|
25
|
+
const l = { id: drawId(), name: locale.drawLayer.replace('{n}', String(list.value.length + 1)) }
|
|
26
|
+
// Items drawn before there were layers stay on the first one
|
|
27
|
+
set([...list.value, l])
|
|
28
|
+
d.layer.value = l.id
|
|
29
|
+
}
|
|
30
|
+
function remove(id: string) {
|
|
31
|
+
if (list.value.length < 2) return
|
|
32
|
+
const first = list.value[0]!.id
|
|
33
|
+
const gone = d.items.value.filter((i) => (i.layer ?? first) === id).map((i) => i.id)
|
|
34
|
+
if (gone.length) {
|
|
35
|
+
d.selection.value = gone
|
|
36
|
+
d.deleteSelection()
|
|
37
|
+
}
|
|
38
|
+
const rest = list.value.filter((l) => l.id !== id)
|
|
39
|
+
// Items with no layer belong to the first one: keep them there if the first goes
|
|
40
|
+
set(rest)
|
|
41
|
+
if (d.layer.value === id) d.layer.value = rest[rest.length - 1]!.id
|
|
42
|
+
}
|
|
43
|
+
function move(id: string, by: 1 | -1) {
|
|
44
|
+
const i = list.value.findIndex((l) => l.id === id)
|
|
45
|
+
const j = i + by
|
|
46
|
+
if (j < 0 || j >= list.value.length) return
|
|
47
|
+
const next = list.value.slice()
|
|
48
|
+
;[next[i], next[j]] = [next[j]!, next[i]!]
|
|
49
|
+
set(next)
|
|
50
|
+
}
|
|
51
|
+
const renaming = ref('')
|
|
52
|
+
const input = ref<HTMLInputElement[]>()
|
|
53
|
+
function startRename(id: string) {
|
|
54
|
+
renaming.value = id
|
|
55
|
+
nextTick(() => input.value?.[0]?.select())
|
|
56
|
+
}
|
|
57
|
+
function rename(id: string, name: string) {
|
|
58
|
+
if (renaming.value !== id) return
|
|
59
|
+
renaming.value = ''
|
|
60
|
+
if (name.trim()) patch(id, { name: name.trim() })
|
|
61
|
+
}
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<template>
|
|
65
|
+
<div class="m3-draw-layers flex w-64 flex-col rounded-xl bg-surface-container p-2 text-on-surface shadow-elevation-2" role="group" :aria-label="locale.drawLayers">
|
|
66
|
+
<div class="flex items-center pb-1 pl-2">
|
|
67
|
+
<span class="flex-1 text-title-small">{{ locale.drawLayers }}</span>
|
|
68
|
+
<MTooltip :text="locale.drawAddLayer" placement="left"><MIconButton icon="add" size="xs" :label="locale.drawAddLayer" @click="add" /></MTooltip>
|
|
69
|
+
</div>
|
|
70
|
+
<div
|
|
71
|
+
v-for="l in shown"
|
|
72
|
+
:key="l.id"
|
|
73
|
+
class="group flex h-10 items-center gap-1 rounded-full pr-1 pl-3 text-body-medium"
|
|
74
|
+
:class="d.layer.value === l.id ? 'bg-secondary-container text-on-secondary-container' : 'hover:bg-on-surface/8'"
|
|
75
|
+
>
|
|
76
|
+
<input
|
|
77
|
+
v-if="renaming === l.id"
|
|
78
|
+
ref="input"
|
|
79
|
+
:value="l.name"
|
|
80
|
+
:aria-label="locale.drawLayerName"
|
|
81
|
+
class="h-7 min-w-0 flex-1 rounded-xs bg-surface px-1 ring-1 ring-primary outline-none"
|
|
82
|
+
@keydown.enter="rename(l.id, ($event.target as HTMLInputElement).value)"
|
|
83
|
+
@keydown.esc="renaming = ''"
|
|
84
|
+
@blur="rename(l.id, ($event.target as HTMLInputElement).value)"
|
|
85
|
+
/>
|
|
86
|
+
<button
|
|
87
|
+
v-else
|
|
88
|
+
type="button"
|
|
89
|
+
class="min-w-0 flex-1 truncate text-left outline-none"
|
|
90
|
+
:class="l.visible === false && 'opacity-50'"
|
|
91
|
+
:aria-pressed="d.layer.value === l.id"
|
|
92
|
+
@click="d.layer.value = l.id"
|
|
93
|
+
@dblclick="startRename(l.id)"
|
|
94
|
+
>{{ l.name }}</button>
|
|
95
|
+
<MTooltip :text="l.visible === false ? locale.drawShowLayer : locale.drawHideLayer" placement="left"><MIconButton :icon="l.visible === false ? 'visibility_off' : 'visibility'" size="xs" :label="l.visible === false ? locale.drawShowLayer : locale.drawHideLayer" @click="patch(l.id, { visible: l.visible === false })" /></MTooltip>
|
|
96
|
+
<MTooltip :text="l.locked ? locale.drawUnlockLayer : locale.drawLockLayer" placement="left"><MIconButton :icon="l.locked ? 'lock' : 'lock_open'" size="xs" :label="l.locked ? locale.drawUnlockLayer : locale.drawLockLayer" @click="patch(l.id, { locked: !l.locked })" /></MTooltip>
|
|
97
|
+
<div class="hidden flex-col group-hover:flex group-focus-within:flex">
|
|
98
|
+
<button type="button" class="h-4 leading-none text-on-surface-variant" :aria-label="locale.drawLayerUp" @click="move(l.id, 1)"><span class="material-symbols-outlined text-[16px]" aria-hidden="true">arrow_drop_up</span></button>
|
|
99
|
+
<button type="button" class="h-4 leading-none text-on-surface-variant" :aria-label="locale.drawLayerDown" @click="move(l.id, -1)"><span class="material-symbols-outlined text-[16px]" aria-hidden="true">arrow_drop_down</span></button>
|
|
100
|
+
</div>
|
|
101
|
+
<MIconButton v-if="list.length > 1" icon="delete" size="xs" :label="locale.drawDeleteLayer" @click="remove(l.id)" />
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
</template>
|
|
105
|
+
|
|
106
|
+
<style>
|
|
107
|
+
@layer base {
|
|
108
|
+
.m3-draw-layers {
|
|
109
|
+
position: absolute;
|
|
110
|
+
top: 16px;
|
|
111
|
+
right: 16px;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
</style>
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A floating toolbar for an MDrawCanvas (put it in its default slot): select and pan, the pens, the erasers, shapes
|
|
4
|
+
* (with fill), text, colors, sizes, undo and redo. Pens, erasers and shapes are each one button that remembers the
|
|
5
|
+
* last one picked, with a menu for the others. Sits at the bottom center by default (style its root to move it).
|
|
6
|
+
* Not an M3 spec component.
|
|
7
|
+
*
|
|
8
|
+
* @slot default More controls at the start
|
|
9
|
+
* @slot end More controls at the end
|
|
10
|
+
*/
|
|
11
|
+
import { computed, inject, ref, watch } from 'vue'
|
|
12
|
+
import { DRAW_KEY, type DrawTool } from '../composables/useDrawing'
|
|
13
|
+
import { useLocale, type M3Locale } from '../composables/useLocale'
|
|
14
|
+
import MIconButton from './MIconButton.vue'
|
|
15
|
+
import MMenu from './MMenu.vue'
|
|
16
|
+
import MMenuItem from './MMenuItem.vue'
|
|
17
|
+
import MTooltip from './MTooltip.vue'
|
|
18
|
+
import MColorPickerModal from './MColorPickerModal.vue'
|
|
19
|
+
|
|
20
|
+
const props = withDefaults(defineProps<{
|
|
21
|
+
/** The tools offered (in groups: pens, erasers and shapes share a button each) */
|
|
22
|
+
tools?: DrawTool[]
|
|
23
|
+
/** Color swatches */
|
|
24
|
+
colors?: string[]
|
|
25
|
+
/** Sizes offered (pen width; a shape's line is the same, text is 4× it) */
|
|
26
|
+
sizes?: number[]
|
|
27
|
+
/** Undo and redo */
|
|
28
|
+
history?: boolean
|
|
29
|
+
/** A button that opens a color picker for any color */
|
|
30
|
+
customColor?: boolean
|
|
31
|
+
}>(), {
|
|
32
|
+
tools: () => ['select', 'pan', 'pen', 'brush', 'marker', 'highlighter', 'eraser', 'stroke-eraser', 'line', 'arrow', 'rect', 'ellipse', 'text'],
|
|
33
|
+
colors: () => ['#1d1b20', '#e53935', '#fb8c00', '#fdd835', '#43a047', '#1e88e5', '#8e24aa', '#ffffff'],
|
|
34
|
+
sizes: () => [2, 4, 8, 16],
|
|
35
|
+
history: true,
|
|
36
|
+
customColor: true,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const draw = inject(DRAW_KEY, null)
|
|
40
|
+
if (!draw) throw new Error('MDrawToolbar must be inside <MDrawCanvas>')
|
|
41
|
+
const d = draw
|
|
42
|
+
const locale = useLocale()
|
|
43
|
+
|
|
44
|
+
const INFO: Record<DrawTool, { icon: string; key: keyof M3Locale }> = {
|
|
45
|
+
select: { icon: 'arrow_selector_tool', key: 'drawSelect' },
|
|
46
|
+
pan: { icon: 'pan_tool', key: 'drawPan' },
|
|
47
|
+
pen: { icon: 'ink_pen', key: 'drawPen' },
|
|
48
|
+
brush: { icon: 'brush', key: 'drawBrush' },
|
|
49
|
+
marker: { icon: 'stylus_note', key: 'drawMarker' },
|
|
50
|
+
highlighter: { icon: 'ink_highlighter', key: 'drawHighlighter' },
|
|
51
|
+
eraser: { icon: 'ink_eraser', key: 'drawEraser' },
|
|
52
|
+
'stroke-eraser': { icon: 'backspace', key: 'drawStrokeEraser' },
|
|
53
|
+
line: { icon: 'pen_size_2', key: 'drawLine' },
|
|
54
|
+
arrow: { icon: 'arrow_right_alt', key: 'drawArrow' },
|
|
55
|
+
rect: { icon: 'rectangle', key: 'drawRect' },
|
|
56
|
+
ellipse: { icon: 'circle', key: 'drawEllipse' },
|
|
57
|
+
text: { icon: 'text_fields', key: 'drawText' },
|
|
58
|
+
}
|
|
59
|
+
const GROUPS: DrawTool[][] = [['select'], ['pan'], ['pen', 'brush', 'marker', 'highlighter'], ['eraser', 'stroke-eraser'], ['line', 'arrow', 'rect', 'ellipse'], ['text']]
|
|
60
|
+
const groups = computed(() => GROUPS.map((g) => g.filter((t) => props.tools.includes(t))).filter((g) => g.length))
|
|
61
|
+
// Each group's button shows the last tool picked from it
|
|
62
|
+
const last = ref<Record<number, DrawTool>>({})
|
|
63
|
+
const shownTool = (g: DrawTool[], i: number) => (g.includes(d.tool.value) ? d.tool.value : last.value[i] ?? g[0]!)
|
|
64
|
+
watch(d.tool, (t) => {
|
|
65
|
+
const i = groups.value.findIndex((g) => g.includes(t))
|
|
66
|
+
if (i >= 0) last.value = { ...last.value, [i]: t }
|
|
67
|
+
}, { immediate: true })
|
|
68
|
+
const isShape = computed(() => ['rect', 'ellipse'].includes(d.tool.value))
|
|
69
|
+
const label = (t: DrawTool) => locale[INFO[t].key] as string
|
|
70
|
+
const picking = ref(false)
|
|
71
|
+
// A color that isn't one of the swatches shows on the custom button
|
|
72
|
+
const isCustom = computed(() => !props.colors.some((c) => c.toLowerCase() === d.color.value.toLowerCase()))
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<template>
|
|
76
|
+
<div class="m3-draw-toolbar flex max-w-[calc(100%-16px)] items-center gap-0.5 overflow-x-auto rounded-full bg-surface-container px-2 py-1 text-on-surface shadow-elevation-3 [scrollbar-width:none]" role="toolbar" :aria-label="locale.drawTools">
|
|
77
|
+
<slot />
|
|
78
|
+
<template v-for="(g, i) in groups" :key="i">
|
|
79
|
+
<MTooltip v-if="g.length === 1" :text="label(g[0]!)" placement="top"><MIconButton
|
|
80
|
+
|
|
81
|
+
:icon="INFO[g[0]!].icon"
|
|
82
|
+
:label="label(g[0]!)"
|
|
83
|
+
:variant="d.tool.value === g[0] ? 'filled' : 'standard'"
|
|
84
|
+
:aria-pressed="d.tool.value === g[0]"
|
|
85
|
+
@click="d.tool.value = g[0]!"
|
|
86
|
+
/></MTooltip>
|
|
87
|
+
<div v-else class="flex items-center">
|
|
88
|
+
<MTooltip :text="label(shownTool(g, i))" placement="top"><MIconButton
|
|
89
|
+
:icon="INFO[shownTool(g, i)].icon"
|
|
90
|
+
:label="label(shownTool(g, i))"
|
|
91
|
+
:variant="g.includes(d.tool.value) ? 'filled' : 'standard'"
|
|
92
|
+
:aria-pressed="g.includes(d.tool.value)"
|
|
93
|
+
@click="d.tool.value = shownTool(g, i)"
|
|
94
|
+
/></MTooltip>
|
|
95
|
+
<MMenu>
|
|
96
|
+
<template #trigger>
|
|
97
|
+
<button type="button" class="flex h-10 w-4 items-center justify-center rounded-full text-on-surface-variant hover:bg-on-surface/8" :aria-label="locale.drawMore">
|
|
98
|
+
<span class="material-symbols-outlined text-[18px]" aria-hidden="true">arrow_drop_down</span>
|
|
99
|
+
</button>
|
|
100
|
+
</template>
|
|
101
|
+
<MMenuItem v-for="t in g" :key="t" :icon="INFO[t].icon" :selected="d.tool.value === t" @click="d.tool.value = t">{{ label(t) }}</MMenuItem>
|
|
102
|
+
</MMenu>
|
|
103
|
+
</div>
|
|
104
|
+
</template>
|
|
105
|
+
<MTooltip v-if="isShape" :text="locale.drawFill" placement="top"><MIconButton
|
|
106
|
+
|
|
107
|
+
icon="format_color_fill"
|
|
108
|
+
:label="locale.drawFill"
|
|
109
|
+
:variant="d.fill.value ? 'tonal' : 'standard'"
|
|
110
|
+
:aria-pressed="d.fill.value"
|
|
111
|
+
@click="d.fill.value = !d.fill.value"
|
|
112
|
+
/></MTooltip>
|
|
113
|
+
<span class="mx-1 h-6 w-px shrink-0 bg-outline-variant" />
|
|
114
|
+
<button
|
|
115
|
+
v-for="c in colors"
|
|
116
|
+
:key="c"
|
|
117
|
+
type="button"
|
|
118
|
+
class="m-0.5 size-7 shrink-0 rounded-full border border-outline-variant outline-offset-2 transition-[outline-color] duration-150"
|
|
119
|
+
:class="d.color.value.toLowerCase() === c.toLowerCase() ? 'outline-2 outline-primary' : 'outline-2 outline-transparent'"
|
|
120
|
+
:style="{ background: c }"
|
|
121
|
+
:aria-label="`${locale.drawColor} ${c}`"
|
|
122
|
+
:aria-pressed="d.color.value.toLowerCase() === c.toLowerCase()"
|
|
123
|
+
@click="d.color.value = c"
|
|
124
|
+
/>
|
|
125
|
+
<MTooltip v-if="customColor" :text="locale.drawCustomColor" placement="top">
|
|
126
|
+
<button
|
|
127
|
+
type="button"
|
|
128
|
+
class="m-0.5 flex size-7 shrink-0 items-center justify-center rounded-full outline-offset-2 transition-[outline-color] duration-150"
|
|
129
|
+
:class="isCustom ? 'outline-2 outline-primary' : 'outline-2 outline-transparent'"
|
|
130
|
+
:style="{ background: isCustom ? d.color.value : 'conic-gradient(#f44336, #ffeb3b, #4caf50, #00bcd4, #3f51b5, #e91e63, #f44336)' }"
|
|
131
|
+
:aria-label="locale.drawCustomColor"
|
|
132
|
+
:aria-pressed="isCustom"
|
|
133
|
+
@click="picking = true"
|
|
134
|
+
>
|
|
135
|
+
<span v-if="!isCustom" class="material-symbols-outlined text-[16px] text-white drop-shadow" aria-hidden="true">add</span>
|
|
136
|
+
</button>
|
|
137
|
+
</MTooltip>
|
|
138
|
+
<MColorPickerModal v-if="customColor" v-model="d.color.value" v-model:show="picking" />
|
|
139
|
+
<span class="mx-1 h-6 w-px shrink-0 bg-outline-variant" />
|
|
140
|
+
<button
|
|
141
|
+
v-for="s in sizes"
|
|
142
|
+
:key="s"
|
|
143
|
+
type="button"
|
|
144
|
+
class="flex size-9 shrink-0 items-center justify-center rounded-full transition-colors"
|
|
145
|
+
:class="d.size.value === s ? 'bg-secondary-container' : 'hover:bg-on-surface/8'"
|
|
146
|
+
:aria-label="`${locale.drawSize} ${s}`"
|
|
147
|
+
:aria-pressed="d.size.value === s"
|
|
148
|
+
@click="d.size.value = s"
|
|
149
|
+
>
|
|
150
|
+
<span class="rounded-full bg-on-surface" :style="{ width: `${Math.min(20, Math.max(3, s * 1.2))}px`, height: `${Math.min(20, Math.max(3, s * 1.2))}px` }" />
|
|
151
|
+
</button>
|
|
152
|
+
<template v-if="history">
|
|
153
|
+
<span class="mx-1 h-6 w-px shrink-0 bg-outline-variant" />
|
|
154
|
+
<MTooltip :text="locale.drawUndo" placement="top"><MIconButton icon="undo" :label="locale.drawUndo" :disabled="!d.canUndo.value" @click="d.undo()" /></MTooltip>
|
|
155
|
+
<MTooltip :text="locale.drawRedo" placement="top"><MIconButton icon="redo" :label="locale.drawRedo" :disabled="!d.canRedo.value" @click="d.redo()" /></MTooltip>
|
|
156
|
+
</template>
|
|
157
|
+
<MTooltip v-if="d.selection.value.length" :text="locale.drawDelete" placement="top"><MIconButton icon="delete" :label="locale.drawDelete" @click="d.deleteSelection()" /></MTooltip>
|
|
158
|
+
<slot name="end" />
|
|
159
|
+
</div>
|
|
160
|
+
</template>
|
|
161
|
+
|
|
162
|
+
<style>
|
|
163
|
+
@layer base {
|
|
164
|
+
.m3-draw-toolbar {
|
|
165
|
+
position: absolute;
|
|
166
|
+
bottom: 16px;
|
|
167
|
+
left: 50%;
|
|
168
|
+
transform: translateX(-50%);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
</style>
|