@m3ui-vue/m3ui-vue 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/API.md +215 -4
  2. package/dist/{MButton-CuNzpoxm.js → MButton-Bl_BSUep.js} +2 -2
  3. package/dist/{MButton-CuNzpoxm.js.map → MButton-Bl_BSUep.js.map} +1 -1
  4. package/dist/{MDialog-HxEL-m58.js → MDialog-D_Yik8ou.js} +2 -2
  5. package/dist/{MDialog-HxEL-m58.js.map → MDialog-D_Yik8ou.js.map} +1 -1
  6. package/dist/{MListItem-DnPtv-hY.js → MListItem-BxifHJdU.js} +2 -2
  7. package/dist/{MListItem-DnPtv-hY.js.map → MListItem-BxifHJdU.js.map} +1 -1
  8. package/dist/{MLoadingIndicator-BQMNX6Dx.js → MLoadingIndicator-BxbFhSX6.js} +2 -2
  9. package/dist/{MLoadingIndicator-BQMNX6Dx.js.map → MLoadingIndicator-BxbFhSX6.js.map} +1 -1
  10. package/dist/{MSeekBar-LURE1Ah7.js → MSeekBar-BeN9QcB3.js} +2 -2
  11. package/dist/{MSeekBar-LURE1Ah7.js.map → MSeekBar-BeN9QcB3.js.map} +1 -1
  12. package/dist/{MSlider-_J4IS2_z.js → MSlider-BVSbJlGS.js} +2 -2
  13. package/dist/{MSlider-_J4IS2_z.js.map → MSlider-BVSbJlGS.js.map} +1 -1
  14. package/dist/{MSpinner-BhkMYKOM.js → MSpinner-C2SUnWk4.js} +2 -2
  15. package/dist/{MSpinner-BhkMYKOM.js.map → MSpinner-C2SUnWk4.js.map} +1 -1
  16. package/dist/{MTextField-CkzwNBWS.js → MTextField-CEkWSZ2v.js} +2 -2
  17. package/dist/{MTextField-CkzwNBWS.js.map → MTextField-CEkWSZ2v.js.map} +1 -1
  18. package/dist/{MTooltip-B67ZDSGp.js → MTooltip-CodJGEO-.js} +4 -4
  19. package/dist/{MTooltip-B67ZDSGp.js.map → MTooltip-CodJGEO-.js.map} +1 -1
  20. package/dist/api.json +1 -1
  21. package/dist/code-editor.js +1 -1
  22. package/dist/components/MDrawCanvas.vue.d.ts +3 -1
  23. package/dist/components/MFloorPlan.vue.d.ts +100 -2
  24. package/dist/components/MFloorPlanInspector.vue.d.ts +56 -0
  25. package/dist/components/MFloorPlanToolbar.vue.d.ts +51 -0
  26. package/dist/components/MFlow.vue.d.ts +13 -0
  27. package/dist/composables/useFloorPlan.d.ts +58 -0
  28. package/dist/composables/useLocale.d.ts +41 -0
  29. package/dist/draw.js +11 -9
  30. package/dist/draw.js.map +1 -1
  31. package/dist/flow.js +6 -1
  32. package/dist/flow.js.map +1 -1
  33. package/dist/gantt.js +1 -1
  34. package/dist/index.d.ts +6 -1
  35. package/dist/locales/index.js +287 -0
  36. package/dist/locales/index.js.map +1 -1
  37. package/dist/m3ui-vue.css +1 -1
  38. package/dist/m3ui.js +2938 -1945
  39. package/dist/m3ui.js.map +1 -1
  40. package/dist/map.js +5 -5
  41. package/dist/media.js +31 -31
  42. package/dist/pdf.js +5 -5
  43. package/dist/pdf.js.map +1 -1
  44. package/dist/rich-text-editor.js +4 -4
  45. package/dist/styles.css +1 -1
  46. package/dist/{useLocale-BpGxplLV.js → useLocale-CaWwi-b6.js} +42 -1
  47. package/dist/useLocale-CaWwi-b6.js.map +1 -0
  48. package/package.json +1 -1
  49. package/src/__tests__/MDrawCanvas.test.ts +8 -0
  50. package/src/__tests__/MFloorPlan.test.ts +235 -3
  51. package/src/__tests__/MFlow.test.ts +15 -0
  52. package/src/components/MDrawCanvas.vue +9 -3
  53. package/src/components/MFloorPlan.vue +586 -74
  54. package/src/components/MFloorPlanInspector.vue +169 -0
  55. package/src/components/MFloorPlanToolbar.vue +128 -0
  56. package/src/components/MFlow.vue +11 -0
  57. package/src/components/MPdfViewer.vue +2 -1
  58. package/src/composables/useFloorPlan.ts +73 -0
  59. package/src/composables/useLocale.ts +82 -0
  60. package/src/index.ts +6 -1
  61. package/src/locales/de.ts +41 -0
  62. package/src/locales/es.ts +41 -0
  63. package/src/locales/fr.ts +41 -0
  64. package/src/locales/ja.ts +41 -0
  65. package/src/locales/ko.ts +41 -0
  66. package/src/locales/pt.ts +41 -0
  67. package/src/locales/zh.ts +41 -0
  68. package/dist/useLocale-BpGxplLV.js.map +0 -1
@@ -0,0 +1,169 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Edits what's picked on an MFloorPlan: a table (name, seats, shape, angle; split it if merged), several tables (merge
4
+ * them), a zone (name, color), a wall (thickness, delete a corner) or decor (text, size, angle); duplicate and delete.
5
+ * A slot per kind adds fields of your own below the built-in ones, with an `update` to change the item (an undo step).
6
+ * Inside the plan's `#overlay` slot it finds the plan by itself; anywhere else, pass the plan's template ref as `plan`.
7
+ * Not an M3 spec component.
8
+ *
9
+ * @slot table Below a table's fields: `{ table, update }`
10
+ * @slot tables Below several picked tables: `{ ids }`
11
+ * @slot area Below a zone's fields: `{ area, update }`
12
+ * @slot wall Below a wall's fields: `{ wall, update }`
13
+ * @slot decor Below a decor item's fields: `{ item, kind, update }`
14
+ * @slot empty When nothing is picked
15
+ */
16
+ import { computed, inject } from 'vue'
17
+ import { FLOOR_PLAN_KEY, floorDecorName, type FloorPlanContext } from '../composables/useFloorPlan'
18
+ import { useLocale } from '../composables/useLocale'
19
+ import type { FloorArea, FloorDecor, FloorTable, FloorWall } from './MFloorPlan.vue'
20
+ import MButton from './MButton.vue'
21
+ import MIcon from './MIcon.vue'
22
+ import MNumberField from './MNumberField.vue'
23
+ import MSegmentedButton from './MSegmentedButton.vue'
24
+ import MSlider from './MSlider.vue'
25
+ import MTextField from './MTextField.vue'
26
+
27
+ const props = withDefaults(defineProps<{
28
+ /** The plan: its template ref (or its `context`). Not needed inside the plan's slots */
29
+ plan?: { context: FloorPlanContext } | FloorPlanContext | null
30
+ /** Colors offered for zones: M3 color roles or CSS colors */
31
+ zoneColors?: string[]
32
+ /** Merge and split buttons */
33
+ merging?: boolean
34
+ }>(), {
35
+ plan: null,
36
+ zoneColors: () => ['secondary', 'tertiary', 'primary', 'success', 'error'],
37
+ merging: true,
38
+ })
39
+
40
+ const injected = inject(FLOOR_PLAN_KEY, null)
41
+ const ctx = computed<FloorPlanContext | null>(() => {
42
+ const p = props.plan
43
+ if (p && 'context' in p) return p.context
44
+ return (p as FloorPlanContext | null) ?? injected
45
+ })
46
+ const locale = useLocale()
47
+
48
+ const table = computed(() => {
49
+ const c = ctx.value
50
+ if (!c || c.picked.value || c.selection.value.length !== 1) return undefined
51
+ return c.tables.value.find((t) => t.id === c.selection.value[0])
52
+ })
53
+ const many = computed(() => (ctx.value && !ctx.value.picked.value && ctx.value.selection.value.length > 1 ? ctx.value.selection.value : null))
54
+ const area = computed(() => (ctx.value?.picked.value?.kind === 'area' ? ctx.value.areas.value.find((a) => a.id === ctx.value!.picked.value!.id) : undefined))
55
+ const wall = computed(() => (ctx.value?.picked.value?.kind === 'wall' ? ctx.value.walls.value.find((w) => w.id === ctx.value!.picked.value!.id) : undefined))
56
+ const vertex = computed(() => ctx.value?.picked.value?.vertex)
57
+ const item = computed(() => (ctx.value?.picked.value?.kind === 'decor' ? ctx.value.decor.value.find((d) => d.id === ctx.value!.picked.value!.id) : undefined))
58
+ const kind = computed(() => (item.value ? ctx.value!.kinds.value[item.value.kind] : undefined))
59
+ const mergeOf = computed(() => (table.value ? ctx.value!.merges.value.find((m) => m.tables.includes(table.value!.id)) : undefined))
60
+
61
+ const upTable = (p: Partial<FloorTable>) => ctx.value!.update('table', table.value!.id, p)
62
+ const upArea = (p: Partial<FloorArea>) => ctx.value!.update('area', area.value!.id, p)
63
+ const upWall = (p: Partial<FloorWall>) => ctx.value!.update('wall', wall.value!.id, p)
64
+ const upDecor = (p: Partial<FloorDecor>) => ctx.value!.update('decor', item.value!.id, p)
65
+ const ROLES = new Set(['primary', 'secondary', 'tertiary', 'error', 'success', 'surface'])
66
+ const swatch = (c: string) => (ROLES.has(c) ? `var(--color-${c})` : c)
67
+ function deleteCorner() {
68
+ ctx.value!.removeSelected()
69
+ }
70
+ </script>
71
+
72
+ <template>
73
+ <div v-if="ctx" class="m3-floor-plan-inspector flex flex-col gap-3">
74
+ <!-- A table -->
75
+ <template v-if="table">
76
+ <div class="flex items-center gap-2 text-title-small"><MIcon name="table_restaurant" :size="18" />{{ locale.floorTableN.replace('{label}', table.label) }}</div>
77
+ <div class="grid grid-cols-2 gap-3">
78
+ <MTextField :model-value="table.label" :label="locale.floorLabel" variant="outlined" @update:model-value="upTable({ label: String($event) })" />
79
+ <MNumberField :model-value="table.seats ?? 0" :label="locale.floorSeatsField" variant="outlined" :min="0" :max="40" @update:model-value="upTable({ seats: $event ?? 0, width: undefined, height: undefined })" />
80
+ </div>
81
+ <MSegmentedButton
82
+ :model-value="table.shape ?? 'square'"
83
+ :options="[{ value: 'round', label: locale.floorRound }, { value: 'square', label: locale.floorSquare }, { value: 'rect', label: locale.floorLong }]"
84
+ density="compact"
85
+ @update:model-value="upTable({ shape: $event as FloorTable['shape'], width: undefined, height: undefined })"
86
+ />
87
+ <MSlider :model-value="table.rotation ?? 0" :min="0" :max="345" :step="15" :label="locale.floorAngle" @update:model-value="upTable({ rotation: $event as number })" show-value />
88
+ <slot name="table" :table="table" :update="upTable" />
89
+ <div class="flex flex-wrap gap-2">
90
+ <MButton v-if="merging && mergeOf" variant="tonal" icon="call_split" @click="ctx.split(mergeOf.id)">{{ locale.floorSplit }} · {{ mergeOf.label }}</MButton>
91
+ <MButton variant="text" icon="content_copy" @click="ctx.duplicate()">{{ locale.floorDuplicate }}</MButton>
92
+ <MButton variant="text" color="error" icon="delete" @click="ctx.removeSelected()">{{ locale.floorDelete }}</MButton>
93
+ </div>
94
+ </template>
95
+
96
+ <!-- Several tables -->
97
+ <template v-else-if="many">
98
+ <div class="flex items-center gap-2 text-title-small"><MIcon name="select_all" :size="18" />{{ locale.floorTablesPicked.replace('{n}', String(many.length)) }}</div>
99
+ <slot name="tables" :ids="many" />
100
+ <div class="flex flex-wrap gap-2">
101
+ <MButton v-if="merging" variant="tonal" icon="join" @click="ctx.merge(many)">{{ locale.floorMerge }}</MButton>
102
+ <MButton variant="text" icon="content_copy" @click="ctx.duplicate()">{{ locale.floorDuplicate }}</MButton>
103
+ <MButton variant="text" color="error" icon="delete" @click="ctx.removeSelected()">{{ locale.floorDelete }}</MButton>
104
+ </div>
105
+ </template>
106
+
107
+ <!-- A zone -->
108
+ <template v-else-if="area">
109
+ <div class="flex items-center gap-2 text-title-small"><MIcon name="crop_square" :size="18" />{{ locale.floorZone }}</div>
110
+ <MTextField :model-value="area.label ?? ''" :label="locale.floorLabel" variant="outlined" @update:model-value="upArea({ label: String($event) })" />
111
+ <div>
112
+ <div class="mb-1 text-label-medium text-on-surface-variant">{{ locale.floorColor }}</div>
113
+ <div class="flex flex-wrap gap-2">
114
+ <button
115
+ v-for="c in zoneColors"
116
+ :key="c"
117
+ type="button"
118
+ class="size-8 rounded-full border border-outline-variant outline-offset-2"
119
+ :class="(area.color ?? 'secondary') === c ? 'outline-2 outline-primary' : 'outline-2 outline-transparent'"
120
+ :style="{ background: swatch(c) }"
121
+ :aria-label="`${locale.floorColor} ${c}`"
122
+ :aria-pressed="(area.color ?? 'secondary') === c"
123
+ @click="upArea({ color: c })"
124
+ />
125
+ </div>
126
+ </div>
127
+ <div class="grid grid-cols-2 gap-3">
128
+ <MNumberField :model-value="Math.round(area.width)" :label="locale.floorWidth" variant="outlined" :min="10" @update:model-value="upArea({ width: $event ?? area.width })" />
129
+ <MNumberField :model-value="Math.round(area.height)" :label="locale.floorHeight" variant="outlined" :min="10" @update:model-value="upArea({ height: $event ?? area.height })" />
130
+ </div>
131
+ <slot name="area" :area="area" :update="upArea" />
132
+ <div class="flex flex-wrap gap-2">
133
+ <MButton variant="text" icon="content_copy" @click="ctx.duplicate()">{{ locale.floorDuplicate }}</MButton>
134
+ <MButton variant="text" color="error" icon="delete" @click="ctx.removeSelected()">{{ locale.floorDelete }}</MButton>
135
+ </div>
136
+ </template>
137
+
138
+ <!-- A wall -->
139
+ <template v-else-if="wall">
140
+ <div class="flex items-center gap-2 text-title-small"><MIcon name="timeline" :size="18" />{{ locale.floorWall }}</div>
141
+ <MSlider :model-value="wall.thickness ?? 8" :min="2" :max="30" :step="1" :label="locale.floorThickness" @update:model-value="upWall({ thickness: $event as number })" show-value />
142
+ <slot name="wall" :wall="wall" :update="upWall" />
143
+ <div class="flex flex-wrap gap-2">
144
+ <MButton v-if="vertex !== undefined && wall.points.length > 2" variant="tonal" icon="remove" @click="deleteCorner">{{ locale.floorDeleteCorner }}</MButton>
145
+ <MButton variant="text" color="error" icon="delete" @click="ctx.picked.value = { kind: 'wall', id: wall.id }; ctx.removeSelected()">{{ locale.floorDelete }}</MButton>
146
+ </div>
147
+ </template>
148
+
149
+ <!-- Decor -->
150
+ <template v-else-if="item">
151
+ <div class="flex items-center gap-2 text-title-small"><MIcon :name="kind?.icon ?? 'category'" :size="18" />{{ floorDecorName(item.kind, ctx.kinds.value, locale) }}</div>
152
+ <MTextField :model-value="item.label ?? ''" :label="locale.floorLabel" variant="outlined" @update:model-value="upDecor({ label: String($event) || undefined })" />
153
+ <div class="grid grid-cols-2 gap-3">
154
+ <MNumberField :model-value="Math.round(item.width ?? kind?.width ?? 40)" :label="locale.floorWidth" variant="outlined" :min="4" @update:model-value="upDecor({ width: $event ?? undefined })" />
155
+ <MNumberField :model-value="Math.round(item.height ?? kind?.height ?? 40)" :label="locale.floorHeight" variant="outlined" :min="4" @update:model-value="upDecor({ height: $event ?? undefined })" />
156
+ </div>
157
+ <MSlider :model-value="item.rotation ?? 0" :min="0" :max="345" :step="15" :label="locale.floorAngle" @update:model-value="upDecor({ rotation: $event as number })" show-value />
158
+ <slot name="decor" :item="item" :kind="kind" :update="upDecor" />
159
+ <div class="flex flex-wrap gap-2">
160
+ <MButton variant="text" icon="content_copy" @click="ctx.duplicate()">{{ locale.floorDuplicate }}</MButton>
161
+ <MButton variant="text" color="error" icon="delete" @click="ctx.removeSelected()">{{ locale.floorDelete }}</MButton>
162
+ </div>
163
+ </template>
164
+
165
+ <slot v-else name="empty">
166
+ <p class="text-body-small text-on-surface-variant">{{ locale.floorNothingPicked }}</p>
167
+ </slot>
168
+ </div>
169
+ </template>
@@ -0,0 +1,128 @@
1
+ <script lang="ts">
2
+ import type { FloorTable } from './MFloorPlan.vue'
3
+ /** A table offered by the toolbar's Add a table menu */
4
+ export type FloorTablePreset = Partial<FloorTable> & { name?: string }
5
+ </script>
6
+
7
+ <script setup lang="ts">
8
+ /**
9
+ * A toolbar for editing an MFloorPlan: move / draw a wall / drag out a zone, add a table (your presets) or decor (any
10
+ * kind, yours too), duplicate, delete, undo and redo. Inside the plan's `#overlay` slot it finds the plan by itself;
11
+ * anywhere else, pass the plan's template ref as `plan`. Not an M3 spec component.
12
+ *
13
+ * @slot default More controls at the start
14
+ * @slot end More controls at the end
15
+ */
16
+ import { computed, inject } from 'vue'
17
+ import { FLOOR_PLAN_KEY, floorDecorName, type FloorPlanContext } from '../composables/useFloorPlan'
18
+ import { useLocale } from '../composables/useLocale'
19
+ import MIcon from './MIcon.vue'
20
+ import MIconButton from './MIconButton.vue'
21
+ import MMenu from './MMenu.vue'
22
+ import MMenuItem from './MMenuItem.vue'
23
+ import MSegmentedButton from './MSegmentedButton.vue'
24
+ import MTooltip from './MTooltip.vue'
25
+
26
+ const props = withDefaults(defineProps<{
27
+ /** The plan: its template ref (or its `context`). Not needed inside the plan's slots */
28
+ plan?: { context: FloorPlanContext } | FloorPlanContext | null
29
+ /** Tables offered by Add a table (name, shape, seats, size…); `[]` hides it, when your app creates tables elsewhere */
30
+ tables?: FloorTablePreset[]
31
+ /** Decor kinds offered (default: every kind the plan knows, yours included) */
32
+ decor?: string[]
33
+ /** Move / wall / zone */
34
+ tools?: boolean
35
+ /** Undo and redo */
36
+ history?: boolean
37
+ }>(), {
38
+ plan: null,
39
+ tables: () => [
40
+ { shape: 'round', seats: 2 },
41
+ { shape: 'round', seats: 4 },
42
+ { shape: 'square', seats: 4 },
43
+ { shape: 'rect', seats: 6 },
44
+ ],
45
+ tools: true,
46
+ history: true,
47
+ })
48
+
49
+ const injected = inject(FLOOR_PLAN_KEY, null)
50
+ const ctx = computed<FloorPlanContext | null>(() => {
51
+ const p = props.plan
52
+ if (p && 'context' in p) return p.context
53
+ return (p as FloorPlanContext | null) ?? injected
54
+ })
55
+ const locale = useLocale()
56
+ const decorKinds = computed(() => {
57
+ const all = ctx.value?.kinds.value ?? {}
58
+ return (props.decor ?? Object.keys(all)).filter((k) => all[k]).map((k) => ({
59
+ kind: k,
60
+ icon: all[k]!.icon ?? (all[k]!.shape === 'round' ? 'circle' : all[k]!.shape === 'text' ? 'title' : 'crop_square'),
61
+ name: floorDecorName(k, all, locale),
62
+ }))
63
+ })
64
+ const shapeName = (s?: FloorTable['shape']) => (s === 'round' ? locale.floorRound : s === 'rect' ? locale.floorLong : locale.floorSquare)
65
+ const presetName = (p: FloorTablePreset) => p.name ?? `${shapeName(p.shape)} · ${p.seats ?? 4}`
66
+ const presetIcon = (p: FloorTablePreset) => (p.shape === 'round' ? 'circle' : p.shape === 'rect' ? 'rectangle' : 'square')
67
+ const canDelete = computed(() => !!ctx.value && (!!ctx.value.picked.value || ctx.value.selection.value.length > 0))
68
+ const canDuplicate = computed(() => !!ctx.value && (ctx.value.selection.value.length > 0 || (!!ctx.value.picked.value && ctx.value.picked.value.kind !== 'wall')))
69
+ function add(p: FloorTablePreset) {
70
+ const { name: _n, ...t } = p
71
+ ctx.value?.addTable(t)
72
+ }
73
+ </script>
74
+
75
+ <template>
76
+ <div v-if="ctx" class="m3-floor-plan-toolbar flex flex-wrap items-center gap-1 px-2 py-1" role="toolbar" :aria-label="locale.floorTools">
77
+ <slot />
78
+ <MSegmentedButton
79
+ v-if="tools"
80
+ :model-value="ctx.tool.value"
81
+ :options="[
82
+ { value: 'select', label: locale.floorMove, icon: 'open_with' },
83
+ { value: 'wall', label: locale.floorDrawWall, icon: 'timeline' },
84
+ { value: 'area', label: locale.floorDrawZone, icon: 'crop_square' },
85
+ ]"
86
+ density="compact"
87
+ @update:model-value="ctx.tool.value = $event as 'select' | 'wall' | 'area'"
88
+ />
89
+ <template v-if="ctx.drawingWall.value">
90
+ <MTooltip :text="locale.floorFinishWall" placement="top"><MIconButton icon="check" variant="filled" :label="locale.floorFinishWall" @click="ctx.finishWall()" /></MTooltip>
91
+ <MTooltip :text="locale.floorCancel" placement="top"><MIconButton icon="close" :label="locale.floorCancel" @click="ctx.cancelWall()" /></MTooltip>
92
+ </template>
93
+ <MMenu v-if="tables.length">
94
+ <template #trigger>
95
+ <MTooltip :text="locale.floorAddTable" placement="top"><MIconButton icon="table_restaurant" :label="locale.floorAddTable" /></MTooltip>
96
+ </template>
97
+ <MMenuItem v-for="(p, i) in tables" :key="i" :icon="presetIcon(p)" @click="add(p)">{{ presetName(p) }}</MMenuItem>
98
+ </MMenu>
99
+ <MMenu v-if="decorKinds.length">
100
+ <template #trigger>
101
+ <MTooltip :text="locale.floorAddDecor" placement="top"><MIconButton icon="chair" :label="locale.floorAddDecor" /></MTooltip>
102
+ </template>
103
+ <MMenuItem v-for="d in decorKinds" :key="d.kind" @click="ctx.addDecor(d.kind)">
104
+ <template #icon><MIcon :name="d.icon" /></template>
105
+ {{ d.name }}
106
+ </MMenuItem>
107
+ </MMenu>
108
+ <span class="mx-1 h-6 w-px shrink-0 bg-outline-variant" />
109
+ <MTooltip :text="locale.floorDuplicate" placement="top"><MIconButton icon="content_copy" :label="locale.floorDuplicate" :disabled="!canDuplicate" @click="ctx.duplicate()" /></MTooltip>
110
+ <MTooltip :text="locale.floorDelete" placement="top"><MIconButton icon="delete" :label="locale.floorDelete" :disabled="!canDelete" @click="ctx.removeSelected()" /></MTooltip>
111
+ <template v-if="history">
112
+ <span class="mx-1 h-6 w-px shrink-0 bg-outline-variant" />
113
+ <MTooltip :text="locale.floorUndo" placement="top"><MIconButton icon="undo" :label="locale.floorUndo" :disabled="!ctx.canUndo.value" @click="ctx.undo()" /></MTooltip>
114
+ <MTooltip :text="locale.floorRedo" placement="top"><MIconButton icon="redo" :label="locale.floorRedo" :disabled="!ctx.canRedo.value" @click="ctx.redo()" /></MTooltip>
115
+ </template>
116
+ <slot name="end" />
117
+ </div>
118
+ </template>
119
+
120
+ <style>
121
+ @layer base {
122
+ .m3-floor-plan-toolbar {
123
+ border-radius: 9999px;
124
+ background-color: var(--color-surface-container);
125
+ color: var(--color-on-surface);
126
+ }
127
+ }
128
+ </style>
@@ -153,6 +153,12 @@ const props = withDefaults(defineProps<{
153
153
  * branches, so a swipe across one still pans
154
154
  */
155
155
  edgeBranching?: boolean
156
+ /**
157
+ * Let the browser's own context menu open on the canvas (right click, or a long press on a phone). Off by default:
158
+ * the `*-contextmenu` events still fire, for a menu of your own (MContextMenu's `showAt`). Text fields inside
159
+ * nodes always keep it, for copy and paste
160
+ */
161
+ nativeContextMenu?: boolean
156
162
  /** The canvas's accessible name */
157
163
  label?: string
158
164
  }>(), {
@@ -186,6 +192,7 @@ const props = withDefaults(defineProps<{
186
192
  dropIntoGroups: false,
187
193
  insertOnEdge: true,
188
194
  edgeBranching: false,
195
+ nativeContextMenu: false,
189
196
  animate: true,
190
197
  })
191
198
 
@@ -1273,6 +1280,8 @@ function onDblClick(e: MouseEvent) {
1273
1280
  function onContextMenu(e: MouseEvent) {
1274
1281
  const t = e.target as HTMLElement
1275
1282
  if (onOverlay(t)) return
1283
+ // The browser's menu (and a phone's long-press menu) stays closed on the canvas, except in text fields
1284
+ if (!props.nativeContextMenu && !t.closest('input, textarea, select, [contenteditable]')) e.preventDefault()
1276
1285
  const nodeEl = t.closest<HTMLElement>('[data-flow-node]')
1277
1286
  const edgeEl = t.closest<HTMLElement>('[data-flow-edge]')
1278
1287
  const n = nodeEl ? nodeById.value.get(nodeEl.dataset.flowNode!) : undefined
@@ -2020,6 +2029,8 @@ defineExpose(context as FlowContext)
2020
2029
  position: relative;
2021
2030
  display: block;
2022
2031
  touch-action: none;
2032
+ /* No callout (save image, copy) on a long press: a long press there selects */
2033
+ -webkit-touch-callout: none;
2023
2034
  }
2024
2035
  }
2025
2036
  .m3-flow-circle {
@@ -1103,7 +1103,8 @@ const TOOLS = computed(() => [
1103
1103
  :aria-pressed="color === c"
1104
1104
  @click="color = c"
1105
1105
  >
1106
- <span class="size-6 rounded-full border border-outline-variant transition-transform" :class="color === c && 'scale-125 ring-2 ring-on-surface ring-offset-2 ring-offset-surface-container-high'" :style="{ backgroundColor: c }" />
1106
+ <!-- Grows by its real size, not a scale (Firefox draws a scaled ring jagged) -->
1107
+ <span class="rounded-full border border-outline-variant transition-[width,height] duration-150" :class="color === c ? 'size-[30px] ring-2 ring-on-surface ring-offset-2 ring-offset-surface-container-high' : 'size-6'" :style="{ backgroundColor: c }" />
1107
1108
  </button>
1108
1109
  <!-- The pen's widths, drawn as dots of their size -->
1109
1110
  <template v-if="tool === 'ink' && inkWidths.length > 1">
@@ -0,0 +1,73 @@
1
+ import { inject, type ComputedRef, type InjectionKey, type Ref } from 'vue'
2
+ import type { M3Locale } from './useLocale'
3
+ import type { FloorArea, FloorDecor, FloorDecorKind, FloorMerge, FloorPick, FloorStatus, FloorTable, FloorWall } from '../components/MFloorPlan.vue'
4
+
5
+ export type FloorTool = 'select' | 'wall' | 'area'
6
+ export type FloorItemKind = 'table' | 'area' | 'wall' | 'decor'
7
+
8
+ /**
9
+ * An MFloorPlan's state and actions. MFloorPlanToolbar and MFloorPlanInspector are built on it, and so can controls
10
+ * of your own: inside the plan's slots with `useFloorPlan()`, or anywhere from its template ref (`plan.context`).
11
+ * Every edit made through it is a step of the plan's undo history.
12
+ */
13
+ export interface FloorPlanContext {
14
+ tables: Ref<FloorTable[]>
15
+ areas: Ref<FloorArea[]>
16
+ walls: Ref<FloorWall[]>
17
+ decor: Ref<FloorDecor[]>
18
+ merges: Ref<FloorMerge[]>
19
+ selection: Ref<(string | number)[]>
20
+ picked: Ref<FloorPick>
21
+ tool: Ref<FloorTool>
22
+ editable: ComputedRef<boolean>
23
+ /** A wall is being drawn (tool `wall`): finish it (also double-click / Enter) or cancel it (Escape) */
24
+ drawingWall: ComputedRef<boolean>
25
+ finishWall(): void
26
+ cancelWall(): void
27
+ /** The decor kinds: built-in ones merged with `decorKinds` */
28
+ kinds: ComputedRef<Record<string, FloorDecorKind>>
29
+ statuses: ComputedRef<Record<string, FloorStatus>>
30
+ /** The plan's size in plan units */
31
+ size: ComputedRef<{ width: number; height: number }>
32
+ canUndo: ComputedRef<boolean>
33
+ canRedo: ComputedRef<boolean>
34
+ undo(): void
35
+ redo(): void
36
+ /** Adds a table (at the plan's middle unless placed; numbered after the highest numbered one) and selects it */
37
+ addTable(table?: Partial<FloorTable>): FloorTable
38
+ /** Adds a decor item of a kind and picks it */
39
+ addDecor(kind: string, item?: Partial<FloorDecor>): FloorDecor
40
+ /** Changes one item (consecutive changes to the same item within a moment are one undo step) */
41
+ update(kind: 'table', id: string | number, patch: Partial<FloorTable>): void
42
+ update(kind: 'area', id: string | number, patch: Partial<FloorArea>): void
43
+ update(kind: 'wall', id: string | number, patch: Partial<FloorWall>): void
44
+ update(kind: 'decor', id: string | number, patch: Partial<FloorDecor>): void
45
+ /** Removes what's picked (a wall's picked corner, or the whole item), or else the selected tables */
46
+ removeSelected(): void
47
+ removeTables(ids: (string | number)[]): void
48
+ /** Copies the selected tables, or the picked zone or decor */
49
+ duplicate(): void
50
+ merge(ids?: (string | number)[], label?: string): FloorMerge | null
51
+ split(idOrTable: string | number): void
52
+ }
53
+
54
+ export const FLOOR_PLAN_KEY: InjectionKey<FloorPlanContext> = Symbol('m3-floor-plan')
55
+
56
+ /** The enclosing MFloorPlan's state and actions (inside its slots) */
57
+ export function useFloorPlan(): FloorPlanContext {
58
+ const ctx = inject(FLOOR_PLAN_KEY, null)
59
+ if (!ctx) throw new Error('useFloorPlan() must be called inside <MFloorPlan> (or pass the plan to your component)')
60
+ return ctx
61
+ }
62
+
63
+ const BUILTIN_NAMES: Record<string, keyof M3Locale> = {
64
+ door: 'floorDecorDoor', window: 'floorDecorWindow', plant: 'floorDecorPlant', column: 'floorDecorColumn', restroom: 'floorDecorRestroom',
65
+ kitchen: 'floorDecorKitchen', register: 'floorDecorRegister', stairs: 'floorDecorStairs', label: 'floorDecorLabel',
66
+ }
67
+ const BUILTIN_LABELS = new Set(['Door', 'Window', 'Plant', 'Column', 'Restroom', 'Kitchen', 'Register', 'Stairs', 'Label'])
68
+ /** A decor kind's name: a built-in one in the app's language (unless renamed), else its label or key */
69
+ export function floorDecorName(kind: string, kinds: Record<string, FloorDecorKind>, locale: M3Locale): string {
70
+ const k = kinds[kind]
71
+ if (BUILTIN_NAMES[kind] && (!k?.label || BUILTIN_LABELS.has(k.label))) return locale[BUILTIN_NAMES[kind]!] as string
72
+ return k?.label ?? kind
73
+ }
@@ -387,6 +387,47 @@ export interface M3Locale {
387
387
  drawColor: string
388
388
  floorPlan: string
389
389
  floorSeats: string
390
+ floorRotate: string
391
+ floorTools: string
392
+ floorMove: string
393
+ floorDrawWall: string
394
+ floorDrawZone: string
395
+ floorAddTable: string
396
+ floorAddDecor: string
397
+ floorDuplicate: string
398
+ floorDelete: string
399
+ floorUndo: string
400
+ floorRedo: string
401
+ floorLabel: string
402
+ floorSeatsField: string
403
+ floorShape: string
404
+ floorRound: string
405
+ floorSquare: string
406
+ floorLong: string
407
+ floorAngle: string
408
+ floorColor: string
409
+ floorThickness: string
410
+ floorWidth: string
411
+ floorHeight: string
412
+ floorMerge: string
413
+ floorSplit: string
414
+ floorNothingPicked: string
415
+ floorTablesPicked: string
416
+ floorTableN: string
417
+ floorZone: string
418
+ floorWall: string
419
+ floorDeleteCorner: string
420
+ floorFinishWall: string
421
+ floorCancel: string
422
+ floorDecorDoor: string
423
+ floorDecorWindow: string
424
+ floorDecorPlant: string
425
+ floorDecorColumn: string
426
+ floorDecorRestroom: string
427
+ floorDecorKitchen: string
428
+ floorDecorRegister: string
429
+ floorDecorStairs: string
430
+ floorDecorLabel: string
390
431
  drawCustomColor: string
391
432
  drawSize: string
392
433
  drawUndo: string
@@ -768,6 +809,47 @@ export const defaultLocale: M3Locale = {
768
809
  drawColor: 'Color',
769
810
  floorPlan: 'Floor plan',
770
811
  floorSeats: '{n} seats',
812
+ floorRotate: 'Rotate',
813
+ floorTools: 'Floor plan tools',
814
+ floorMove: 'Move',
815
+ floorDrawWall: 'Wall',
816
+ floorDrawZone: 'Zone',
817
+ floorAddTable: 'Add a table',
818
+ floorAddDecor: 'Add decor',
819
+ floorDuplicate: 'Duplicate',
820
+ floorDelete: 'Delete',
821
+ floorUndo: 'Undo',
822
+ floorRedo: 'Redo',
823
+ floorLabel: 'Label',
824
+ floorSeatsField: 'Seats',
825
+ floorShape: 'Shape',
826
+ floorRound: 'Round',
827
+ floorSquare: 'Square',
828
+ floorLong: 'Long',
829
+ floorAngle: 'Angle',
830
+ floorColor: 'Color',
831
+ floorThickness: 'Thickness',
832
+ floorWidth: 'Width',
833
+ floorHeight: 'Height',
834
+ floorMerge: 'Merge tables',
835
+ floorSplit: 'Split',
836
+ floorNothingPicked: 'Pick a table, a zone, a wall or decor to change it',
837
+ floorTablesPicked: '{n} tables picked',
838
+ floorTableN: 'Table {label}',
839
+ floorZone: 'Zone',
840
+ floorWall: 'Wall',
841
+ floorDeleteCorner: 'Delete the corner',
842
+ floorFinishWall: 'Finish the wall',
843
+ floorCancel: 'Cancel',
844
+ floorDecorDoor: 'Door',
845
+ floorDecorWindow: 'Window',
846
+ floorDecorPlant: 'Plant',
847
+ floorDecorColumn: 'Column',
848
+ floorDecorRestroom: 'Restroom',
849
+ floorDecorKitchen: 'Kitchen',
850
+ floorDecorRegister: 'Register',
851
+ floorDecorStairs: 'Stairs',
852
+ floorDecorLabel: 'Text',
771
853
  drawCustomColor: 'Custom color',
772
854
  drawSize: 'Size',
773
855
  drawUndo: 'Undo',
package/src/index.ts CHANGED
@@ -127,7 +127,12 @@ export { default as MFab } from './components/MFab.vue'
127
127
  export { default as MFabMenu } from './components/MFabMenu.vue'
128
128
  export { default as MFileUpload } from './components/MFileUpload.vue'
129
129
  export { default as MFloorPlan } from './components/MFloorPlan.vue'
130
- export type { FloorTable, FloorMerge, FloorStatus } from './components/MFloorPlan.vue'
130
+ export { default as MFloorPlanToolbar } from './components/MFloorPlanToolbar.vue'
131
+ export type { FloorTablePreset } from './components/MFloorPlanToolbar.vue'
132
+ export { default as MFloorPlanInspector } from './components/MFloorPlanInspector.vue'
133
+ export { useFloorPlan, floorDecorName } from './composables/useFloorPlan'
134
+ export type { FloorPlanContext, FloorTool, FloorItemKind } from './composables/useFloorPlan'
135
+ export type { FloorTable, FloorMerge, FloorStatus, FloorArea, FloorWall, FloorDecor, FloorPick, FloorDecorKind, FloorDecorBuiltin } from './components/MFloorPlan.vue'
131
136
  export { default as MImageCropper } from './components/MImageCropper.vue'
132
137
  export { default as MFixed } from './components/MFixed.vue'
133
138
  export { default as MFooter } from './components/MFooter.vue'
package/src/locales/de.ts CHANGED
@@ -375,6 +375,47 @@ export const deLocale: M3Locale = {
375
375
  drawColor: 'Farbe',
376
376
  floorPlan: 'Raumplan',
377
377
  floorSeats: '{n} Plätze',
378
+ floorRotate: 'Drehen',
379
+ floorTools: 'Raumplan-Werkzeuge',
380
+ floorMove: 'Verschieben',
381
+ floorDrawWall: 'Wand',
382
+ floorDrawZone: 'Zone',
383
+ floorAddTable: 'Tisch hinzufügen',
384
+ floorAddDecor: 'Deko hinzufügen',
385
+ floorDuplicate: 'Duplizieren',
386
+ floorDelete: 'Löschen',
387
+ floorUndo: 'Rückgängig',
388
+ floorRedo: 'Wiederholen',
389
+ floorLabel: 'Name',
390
+ floorSeatsField: 'Plätze',
391
+ floorShape: 'Form',
392
+ floorRound: 'Rund',
393
+ floorSquare: 'Quadratisch',
394
+ floorLong: 'Lang',
395
+ floorAngle: 'Winkel',
396
+ floorColor: 'Farbe',
397
+ floorThickness: 'Stärke',
398
+ floorWidth: 'Breite',
399
+ floorHeight: 'Höhe',
400
+ floorMerge: 'Tische zusammenstellen',
401
+ floorSplit: 'Trennen',
402
+ floorNothingPicked: 'Wähle einen Tisch, eine Zone, eine Wand oder Deko zum Bearbeiten',
403
+ floorTablesPicked: '{n} Tische gewählt',
404
+ floorTableN: 'Tisch {label}',
405
+ floorZone: 'Zone',
406
+ floorWall: 'Wand',
407
+ floorDeleteCorner: 'Ecke löschen',
408
+ floorFinishWall: 'Wand fertigstellen',
409
+ floorCancel: 'Abbrechen',
410
+ floorDecorDoor: 'Tür',
411
+ floorDecorWindow: 'Fenster',
412
+ floorDecorPlant: 'Pflanze',
413
+ floorDecorColumn: 'Säule',
414
+ floorDecorRestroom: 'Toilette',
415
+ floorDecorKitchen: 'Küche',
416
+ floorDecorRegister: 'Kasse',
417
+ floorDecorStairs: 'Treppe',
418
+ floorDecorLabel: 'Text',
378
419
  drawCustomColor: 'Eigene Farbe',
379
420
  drawSize: 'Größe',
380
421
  drawUndo: 'Rückgängig',
package/src/locales/es.ts CHANGED
@@ -375,6 +375,47 @@ export const esLocale: M3Locale = {
375
375
  drawColor: 'Color',
376
376
  floorPlan: 'Plano del salón',
377
377
  floorSeats: '{n} lugares',
378
+ floorRotate: 'Girar',
379
+ floorTools: 'Herramientas del plano',
380
+ floorMove: 'Mover',
381
+ floorDrawWall: 'Pared',
382
+ floorDrawZone: 'Zona',
383
+ floorAddTable: 'Agregar mesa',
384
+ floorAddDecor: 'Agregar decoración',
385
+ floorDuplicate: 'Duplicar',
386
+ floorDelete: 'Eliminar',
387
+ floorUndo: 'Deshacer',
388
+ floorRedo: 'Rehacer',
389
+ floorLabel: 'Nombre',
390
+ floorSeatsField: 'Lugares',
391
+ floorShape: 'Forma',
392
+ floorRound: 'Redonda',
393
+ floorSquare: 'Cuadrada',
394
+ floorLong: 'Larga',
395
+ floorAngle: 'Ángulo',
396
+ floorColor: 'Color',
397
+ floorThickness: 'Grosor',
398
+ floorWidth: 'Ancho',
399
+ floorHeight: 'Alto',
400
+ floorMerge: 'Unir mesas',
401
+ floorSplit: 'Separar',
402
+ floorNothingPicked: 'Elegí una mesa, zona, pared o decoración para editarla',
403
+ floorTablesPicked: '{n} mesas elegidas',
404
+ floorTableN: 'Mesa {label}',
405
+ floorZone: 'Zona',
406
+ floorWall: 'Pared',
407
+ floorDeleteCorner: 'Eliminar la esquina',
408
+ floorFinishWall: 'Terminar la pared',
409
+ floorCancel: 'Cancelar',
410
+ floorDecorDoor: 'Puerta',
411
+ floorDecorWindow: 'Ventana',
412
+ floorDecorPlant: 'Planta',
413
+ floorDecorColumn: 'Columna',
414
+ floorDecorRestroom: 'Baño',
415
+ floorDecorKitchen: 'Cocina',
416
+ floorDecorRegister: 'Caja',
417
+ floorDecorStairs: 'Escalera',
418
+ floorDecorLabel: 'Texto',
378
419
  drawCustomColor: 'Color personalizado',
379
420
  drawSize: 'Tamaño',
380
421
  drawUndo: 'Deshacer',