@m3ui-vue/m3ui-vue 1.3.0 → 1.3.1
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 +213 -4
- package/dist/{MButton-CuNzpoxm.js → MButton-Bl_BSUep.js} +2 -2
- package/dist/{MButton-CuNzpoxm.js.map → MButton-Bl_BSUep.js.map} +1 -1
- package/dist/{MDialog-HxEL-m58.js → MDialog-D_Yik8ou.js} +2 -2
- package/dist/{MDialog-HxEL-m58.js.map → MDialog-D_Yik8ou.js.map} +1 -1
- package/dist/{MListItem-DnPtv-hY.js → MListItem-BxifHJdU.js} +2 -2
- package/dist/{MListItem-DnPtv-hY.js.map → MListItem-BxifHJdU.js.map} +1 -1
- package/dist/{MLoadingIndicator-BQMNX6Dx.js → MLoadingIndicator-BxbFhSX6.js} +2 -2
- package/dist/{MLoadingIndicator-BQMNX6Dx.js.map → MLoadingIndicator-BxbFhSX6.js.map} +1 -1
- package/dist/{MSeekBar-LURE1Ah7.js → MSeekBar-BeN9QcB3.js} +2 -2
- package/dist/{MSeekBar-LURE1Ah7.js.map → MSeekBar-BeN9QcB3.js.map} +1 -1
- package/dist/{MSlider-_J4IS2_z.js → MSlider-BVSbJlGS.js} +2 -2
- package/dist/{MSlider-_J4IS2_z.js.map → MSlider-BVSbJlGS.js.map} +1 -1
- package/dist/{MSpinner-BhkMYKOM.js → MSpinner-C2SUnWk4.js} +2 -2
- package/dist/{MSpinner-BhkMYKOM.js.map → MSpinner-C2SUnWk4.js.map} +1 -1
- package/dist/{MTextField-CkzwNBWS.js → MTextField-CEkWSZ2v.js} +2 -2
- package/dist/{MTextField-CkzwNBWS.js.map → MTextField-CEkWSZ2v.js.map} +1 -1
- package/dist/{MTooltip-B67ZDSGp.js → MTooltip-CodJGEO-.js} +4 -4
- package/dist/{MTooltip-B67ZDSGp.js.map → MTooltip-CodJGEO-.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MDrawCanvas.vue.d.ts +3 -1
- package/dist/components/MFloorPlan.vue.d.ts +90 -2
- package/dist/components/MFloorPlanInspector.vue.d.ts +56 -0
- package/dist/components/MFloorPlanToolbar.vue.d.ts +51 -0
- package/dist/components/MFlow.vue.d.ts +13 -0
- package/dist/composables/useFloorPlan.d.ts +58 -0
- package/dist/composables/useLocale.d.ts +41 -0
- package/dist/draw.js +11 -9
- package/dist/draw.js.map +1 -1
- package/dist/flow.js +6 -1
- package/dist/flow.js.map +1 -1
- package/dist/gantt.js +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/locales/index.js +287 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +2934 -1955
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +5 -5
- package/dist/media.js +31 -31
- package/dist/pdf.js +5 -5
- package/dist/pdf.js.map +1 -1
- package/dist/rich-text-editor.js +4 -4
- package/dist/styles.css +1 -1
- package/dist/{useLocale-BpGxplLV.js → useLocale-CaWwi-b6.js} +42 -1
- package/dist/useLocale-CaWwi-b6.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MDrawCanvas.test.ts +8 -0
- package/src/__tests__/MFloorPlan.test.ts +205 -3
- package/src/__tests__/MFlow.test.ts +15 -0
- package/src/components/MDrawCanvas.vue +9 -3
- package/src/components/MFloorPlan.vue +571 -72
- package/src/components/MFloorPlanInspector.vue +169 -0
- package/src/components/MFloorPlanToolbar.vue +128 -0
- package/src/components/MFlow.vue +11 -0
- package/src/components/MPdfViewer.vue +2 -1
- package/src/composables/useFloorPlan.ts +73 -0
- package/src/composables/useLocale.ts +82 -0
- package/src/index.ts +6 -1
- package/src/locales/de.ts +41 -0
- package/src/locales/es.ts +41 -0
- package/src/locales/fr.ts +41 -0
- package/src/locales/ja.ts +41 -0
- package/src/locales/ko.ts +41 -0
- package/src/locales/pt.ts +41 -0
- package/src/locales/zh.ts +41 -0
- package/dist/useLocale-BpGxplLV.js.map +0 -1
|
@@ -44,7 +44,8 @@ export interface FloorWall {
|
|
|
44
44
|
/** Something on the plan that isn't a table: a door, a window, a plant, a column, the register, a text label… */
|
|
45
45
|
export interface FloorDecor {
|
|
46
46
|
id: string | number
|
|
47
|
-
|
|
47
|
+
/** A built-in kind, or one of yours from `decorKinds` */
|
|
48
|
+
kind: FloorDecorBuiltin | (string & {})
|
|
48
49
|
x: number
|
|
49
50
|
y: number
|
|
50
51
|
width?: number
|
|
@@ -53,6 +54,21 @@ export interface FloorDecor {
|
|
|
53
54
|
/** The text of a label (or a caption under the others) */
|
|
54
55
|
label?: string
|
|
55
56
|
}
|
|
57
|
+
export type FloorDecorBuiltin = 'door' | 'window' | 'plant' | 'column' | 'restroom' | 'kitchen' | 'register' | 'stairs' | 'label'
|
|
58
|
+
/** How a decor kind looks: its default size, an icon, a shape and fill; yours or a built-in one restyled */
|
|
59
|
+
export interface FloorDecorKind {
|
|
60
|
+
/** Name, for the accessible label */
|
|
61
|
+
label?: string
|
|
62
|
+
icon?: string
|
|
63
|
+
width: number
|
|
64
|
+
height: number
|
|
65
|
+
/** `box` a rounded rectangle, `round` a circle, `bar` a thin slab (doors, windows), `text` the item's label only */
|
|
66
|
+
shape?: 'box' | 'round' | 'bar' | 'text'
|
|
67
|
+
/** Fill: an M3 color role (`surface`, `primary`…) or any CSS color */
|
|
68
|
+
color?: string
|
|
69
|
+
}
|
|
70
|
+
/** What's picked on the plan besides tables: a zone, a wall (and one of its corners) or a decor item */
|
|
71
|
+
export type FloorPick = { kind: 'area' | 'wall' | 'decor'; id: string | number; vertex?: number } | null
|
|
56
72
|
/** How a status looks: an M3 color role ('primary', 'tertiary', 'error'…) or any CSS color, an icon, a name */
|
|
57
73
|
export interface FloorStatus {
|
|
58
74
|
label: string
|
|
@@ -68,12 +84,19 @@ export interface FloorStatus {
|
|
|
68
84
|
* group. Positions are plan units scaled to the component's width, so the same plan fits a phone and a wall screen.
|
|
69
85
|
* Not an M3 spec component.
|
|
70
86
|
*
|
|
87
|
+
* Editing: drag tables (Shift-click picks several), zones (resize by any corner), walls (drag a corner once picked;
|
|
88
|
+
* double-click a wall for a new corner) and decor (resize by its corner); rotate the picked table or decor by the handle
|
|
89
|
+
* above it (15° steps, Shift for free). Arrows nudge, Delete removes what's picked (a wall's picked corner, or the
|
|
90
|
+
* selected tables), Ctrl+D duplicates, Ctrl+Z / Ctrl+Shift+Z undo and redo. `v-model:picked` says which zone, wall or
|
|
91
|
+
* decor is picked, for an inspector of your own.
|
|
92
|
+
*
|
|
71
93
|
* @slot table The inside of a table: `{ table, status, selected }`
|
|
72
94
|
* @event table-click A table was clicked or opened with Enter (not after a drag)
|
|
73
95
|
* @event move Tables moved by a drag or the arrows, with their new positions (`{ id, x, y }[]`), to save them
|
|
74
96
|
*/
|
|
75
|
-
import { computed, onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'
|
|
97
|
+
import { computed, onBeforeUnmount, onMounted, provide, ref, shallowRef } from 'vue'
|
|
76
98
|
import { useLocale } from '../composables/useLocale'
|
|
99
|
+
import { FLOOR_PLAN_KEY, type FloorItemKind, type FloorPlanContext } from '../composables/useFloorPlan'
|
|
77
100
|
import MIcon from './MIcon.vue'
|
|
78
101
|
|
|
79
102
|
const props = withDefaults(defineProps<{
|
|
@@ -90,6 +113,12 @@ const props = withDefaults(defineProps<{
|
|
|
90
113
|
showGrid?: boolean
|
|
91
114
|
/** Draw chairs from `seats` */
|
|
92
115
|
chairs?: boolean
|
|
116
|
+
/** Decor kinds of yours, or the built-in ones restyled (merged over them by name) */
|
|
117
|
+
decorKinds?: Record<string, FloorDecorKind>
|
|
118
|
+
/** Outside editing, what a click on a table selects: nothing, one, or several (toggling; to merge them) */
|
|
119
|
+
selectable?: 'none' | 'single' | 'multiple'
|
|
120
|
+
/** Whether these tables may be merged: `true`, or `false` / a reason to refuse (shown by `merge-refused`) */
|
|
121
|
+
canMerge?: (ids: (string | number)[]) => boolean | string
|
|
93
122
|
/** Accessible name */
|
|
94
123
|
label?: string
|
|
95
124
|
}>(), {
|
|
@@ -105,6 +134,7 @@ const props = withDefaults(defineProps<{
|
|
|
105
134
|
grid: 10,
|
|
106
135
|
showGrid: true,
|
|
107
136
|
chairs: true,
|
|
137
|
+
selectable: 'none',
|
|
108
138
|
})
|
|
109
139
|
const tables = defineModel<FloorTable[]>('tables', { default: () => [] })
|
|
110
140
|
const merges = defineModel<FloorMerge[]>('merges', { default: () => [] })
|
|
@@ -114,10 +144,52 @@ const walls = defineModel<FloorWall[]>('walls', { default: () => [] })
|
|
|
114
144
|
const decor = defineModel<FloorDecor[]>('decor', { default: () => [] })
|
|
115
145
|
/** While editing: `select` moves things, `wall` draws a wall (click each corner, double-click or Enter to end), `area` drags out a zone */
|
|
116
146
|
const tool = defineModel<'select' | 'wall' | 'area'>('tool', { default: 'select' })
|
|
117
|
-
|
|
147
|
+
/** While editing: the zone, wall (and corner) or decor item picked, for an inspector of your own */
|
|
148
|
+
const picked = defineModel<FloorPick>('picked', { default: null })
|
|
149
|
+
// ── History: every edit the plan makes is a step Ctrl+Z takes back ──
|
|
150
|
+
type Snap = { tables: FloorTable[]; areas: FloorArea[]; walls: FloorWall[]; decor: FloorDecor[]; merges: FloorMerge[] }
|
|
151
|
+
const past = shallowRef<Snap[]>([])
|
|
152
|
+
const future = shallowRef<Snap[]>([])
|
|
153
|
+
const snap0 = (): Snap => ({ tables: tables.value, areas: areas.value, walls: walls.value, decor: decor.value, merges: merges.value })
|
|
154
|
+
/** Called before an edit: what it changes can be undone */
|
|
155
|
+
function record() {
|
|
156
|
+
past.value = [...past.value, snap0()].slice(-100)
|
|
157
|
+
future.value = []
|
|
158
|
+
}
|
|
159
|
+
function restore(sn: Snap) {
|
|
160
|
+
const now = snap0()
|
|
161
|
+
if (sn.tables !== now.tables) tables.value = sn.tables
|
|
162
|
+
if (sn.areas !== now.areas) areas.value = sn.areas
|
|
163
|
+
if (sn.walls !== now.walls) walls.value = sn.walls
|
|
164
|
+
if (sn.decor !== now.decor) decor.value = sn.decor
|
|
165
|
+
if (sn.merges !== now.merges) merges.value = sn.merges
|
|
166
|
+
}
|
|
167
|
+
function undo() {
|
|
168
|
+
const sn = past.value[past.value.length - 1]
|
|
169
|
+
if (!sn) return
|
|
170
|
+
future.value = [snap0(), ...future.value]
|
|
171
|
+
past.value = past.value.slice(0, -1)
|
|
172
|
+
restore(sn)
|
|
173
|
+
}
|
|
174
|
+
function redo() {
|
|
175
|
+
const sn = future.value[0]
|
|
176
|
+
if (!sn) return
|
|
177
|
+
past.value = [...past.value, snap0()]
|
|
178
|
+
future.value = future.value.slice(1)
|
|
179
|
+
restore(sn)
|
|
180
|
+
}
|
|
181
|
+
const emit = defineEmits<{
|
|
182
|
+
merge: [merge: FloorMerge]
|
|
183
|
+
split: [merge: FloorMerge]
|
|
184
|
+
'merge-refused': [ids: (string | number)[], reason: string]
|
|
185
|
+
'table-click': [table: FloorTable, event: MouseEvent | KeyboardEvent]
|
|
186
|
+
move: [moved: { id: string | number; x: number; y: number }[]]
|
|
187
|
+
}>()
|
|
118
188
|
const locale = useLocale()
|
|
119
189
|
|
|
120
190
|
const root = ref<HTMLElement>()
|
|
191
|
+
/** A finger: bigger handles */
|
|
192
|
+
const coarse = ref(typeof matchMedia !== 'undefined' && matchMedia('(pointer: coarse)').matches)
|
|
121
193
|
const scale = ref(1)
|
|
122
194
|
let ro: ResizeObserver | null = null
|
|
123
195
|
onMounted(() => {
|
|
@@ -184,34 +256,75 @@ function look(st?: FloorStatus) {
|
|
|
184
256
|
if (ROLES.has(st.color)) return { background: `var(--color-${st.color}-container)`, color: `var(--color-on-${st.color}-container)` }
|
|
185
257
|
return { background: st.color, color: '#fff' }
|
|
186
258
|
}
|
|
187
|
-
|
|
259
|
+
/**
|
|
260
|
+
* How a merge is drawn: tables that sit together share one outline (a cluster); clusters apart from each other get
|
|
261
|
+
* an outline each, joined by a dashed line, so a merge across the room doesn't swallow the tables in between
|
|
262
|
+
*/
|
|
263
|
+
const mergeShapes = computed(() =>
|
|
188
264
|
merges.value.map((m) => {
|
|
189
265
|
const ms = placed.value.filter((p) => m.tables.includes(p.t.id))
|
|
190
266
|
if (!ms.length) return null
|
|
191
267
|
const pad = CHAIR + 10
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
|
|
268
|
+
const boxes = ms.map((p) => ({ x1: p.x - p.size.w / 2 - pad, y1: p.y - p.size.h / 2 - pad, x2: p.x + p.size.w / 2 + pad, y2: p.y + p.size.h / 2 + pad }))
|
|
269
|
+
// Union-find over touching boxes
|
|
270
|
+
const parent = boxes.map((_, i) => i)
|
|
271
|
+
const find = (i: number): number => (parent[i] === i ? i : (parent[i] = find(parent[i]!)))
|
|
272
|
+
for (let i = 0; i < boxes.length; i++)
|
|
273
|
+
for (let j = i + 1; j < boxes.length; j++) {
|
|
274
|
+
const a = boxes[i]!
|
|
275
|
+
const b = boxes[j]!
|
|
276
|
+
if (a.x1 <= b.x2 && b.x1 <= a.x2 && a.y1 <= b.y2 && b.y1 <= a.y2) parent[find(i)] = find(j)
|
|
277
|
+
}
|
|
278
|
+
const groups = new Map<number, typeof boxes>()
|
|
279
|
+
boxes.forEach((b, i) => groups.set(find(i), [...(groups.get(find(i)) ?? []), b]))
|
|
280
|
+
const clusters = [...groups.values()].map((bs) => {
|
|
281
|
+
const x1 = Math.min(...bs.map((b) => b.x1))
|
|
282
|
+
const y1 = Math.min(...bs.map((b) => b.y1))
|
|
283
|
+
const x2 = Math.max(...bs.map((b) => b.x2))
|
|
284
|
+
const y2 = Math.max(...bs.map((b) => b.y2))
|
|
285
|
+
return { x: x1, y: y1, w: x2 - x1, h: y2 - y1, cx: (x1 + x2) / 2, cy: (y1 + y2) / 2 }
|
|
286
|
+
})
|
|
287
|
+
// Each cluster linked to the nearest one already linked (a small spanning tree)
|
|
288
|
+
const links: [number, number, number, number][] = []
|
|
289
|
+
for (let i = 1; i < clusters.length; i++) {
|
|
290
|
+
let best = 0
|
|
291
|
+
for (let j = 1; j < i; j++) if (Math.hypot(clusters[j]!.cx - clusters[i]!.cx, clusters[j]!.cy - clusters[i]!.cy) < Math.hypot(clusters[best]!.cx - clusters[i]!.cx, clusters[best]!.cy - clusters[i]!.cy)) best = j
|
|
292
|
+
links.push([clusters[best]!.cx, clusters[best]!.cy, clusters[i]!.cx, clusters[i]!.cy])
|
|
293
|
+
}
|
|
294
|
+
return { m, clusters, links }
|
|
197
295
|
}).filter((b) => !!b),
|
|
198
296
|
)
|
|
199
297
|
|
|
200
298
|
// ── Dragging ────────────────────────────────────────────────────────────────────────────────────────────
|
|
201
|
-
let drag: { id: number; sx: number; sy: number; start: Map<string | number, { x: number; y: number }>; moved: boolean } | null = null
|
|
299
|
+
let drag: { id: number; sx: number; sy: number; start: Map<string | number, { x: number; y: number }>; moved: boolean; pick?: string | number } | null = null
|
|
202
300
|
let suppressClick = false
|
|
203
301
|
const snap = (v: number) => (props.grid ? Math.round(v / props.grid) * props.grid : v)
|
|
204
302
|
function clamp(t: FloorTable, x: number, y: number) {
|
|
205
303
|
const s = sizeOf(t)
|
|
206
304
|
return { x: Math.min(props.width - s.w / 2, Math.max(s.w / 2, x)), y: Math.min(props.height - s.h / 2, Math.max(s.h / 2, y)) }
|
|
207
305
|
}
|
|
306
|
+
// A finger has no Shift: holding a table down adds it to the selection (or takes it out)
|
|
307
|
+
const LONG_PRESS = 450
|
|
308
|
+
let longPress = 0
|
|
309
|
+
let longPressed = false
|
|
208
310
|
function onDown(e: PointerEvent, t: FloorTable) {
|
|
209
311
|
if (!props.editable || e.button !== 0 || tool.value !== 'select') return
|
|
210
312
|
e.stopPropagation()
|
|
211
313
|
picked.value = null
|
|
212
|
-
|
|
314
|
+
const touch = e.pointerType === 'touch'
|
|
315
|
+
longPressed = false
|
|
316
|
+
clearTimeout(longPress)
|
|
317
|
+
if (touch) {
|
|
318
|
+
longPress = window.setTimeout(() => {
|
|
319
|
+
if (!drag || drag.moved) return
|
|
320
|
+
longPressed = true
|
|
321
|
+
selection.value = selection.value.includes(t.id) ? selection.value.filter((x) => x !== t.id) : [...selection.value, t.id]
|
|
322
|
+
navigator.vibrate?.(10)
|
|
323
|
+
}, LONG_PRESS)
|
|
324
|
+
} else if (!selection.value.includes(t.id)) selection.value = e.shiftKey || e.ctrlKey || e.metaKey ? [...selection.value, t.id] : [t.id]
|
|
325
|
+
// A touch picks the table once it moves (or on release), so a long press can add to what's picked
|
|
213
326
|
const ids = selection.value.includes(t.id) ? selection.value : [t.id]
|
|
214
|
-
drag = { id: e.pointerId, sx: e.clientX, sy: e.clientY, start: new Map(tables.value.filter((x) => ids.includes(x.id)).map((x) => [x.id, { x: x.x, y: x.y }])), moved: false }
|
|
327
|
+
drag = { id: e.pointerId, sx: e.clientX, sy: e.clientY, start: new Map(tables.value.filter((x) => ids.includes(x.id)).map((x) => [x.id, { x: x.x, y: x.y }])), moved: false, pick: touch && !selection.value.includes(t.id) ? t.id : undefined }
|
|
215
328
|
window.addEventListener('pointermove', onMove)
|
|
216
329
|
window.addEventListener('pointerup', onUp)
|
|
217
330
|
window.addEventListener('pointercancel', onUp)
|
|
@@ -220,7 +333,11 @@ function onMove(e: PointerEvent) {
|
|
|
220
333
|
if (!drag || e.pointerId !== drag.id) return
|
|
221
334
|
const dx = (e.clientX - drag.sx) / scale.value
|
|
222
335
|
const dy = (e.clientY - drag.sy) / scale.value
|
|
223
|
-
if (!drag.moved && Math.hypot(e.clientX - drag.sx, e.clientY - drag.sy) < 4) return
|
|
336
|
+
if (!drag.moved && Math.hypot(e.clientX - drag.sx, e.clientY - drag.sy) < (e.pointerType === 'touch' ? 8 : 4)) return
|
|
337
|
+
if (!drag.moved) {
|
|
338
|
+
clearTimeout(longPress)
|
|
339
|
+
if (drag.pick !== undefined) selection.value = [drag.pick]
|
|
340
|
+
}
|
|
224
341
|
drag.moved = true
|
|
225
342
|
const next = new Map<string | number, { x: number; y: number }>()
|
|
226
343
|
for (const [id, p] of drag.start) next.set(id, clamp(tables.value.find((x) => x.id === id)!, p.x + dx, p.y + dy))
|
|
@@ -228,6 +345,11 @@ function onMove(e: PointerEvent) {
|
|
|
228
345
|
}
|
|
229
346
|
function onUp(e: PointerEvent) {
|
|
230
347
|
if (!drag || e.pointerId !== drag.id) return
|
|
348
|
+
clearTimeout(longPress)
|
|
349
|
+
if (longPressed) {
|
|
350
|
+
suppressClick = true
|
|
351
|
+
setTimeout(() => (suppressClick = false))
|
|
352
|
+
}
|
|
231
353
|
window.removeEventListener('pointermove', onMove)
|
|
232
354
|
window.removeEventListener('pointerup', onUp)
|
|
233
355
|
window.removeEventListener('pointercancel', onUp)
|
|
@@ -241,12 +363,16 @@ function onUp(e: PointerEvent) {
|
|
|
241
363
|
commitMoves(new Map([...d!].map(([id, p]) => [id, clamp(tables.value.find((x) => x.id === id)!, snap(p.x), snap(p.y))])))
|
|
242
364
|
}
|
|
243
365
|
function commitMoves(next: Map<string | number, { x: number; y: number }>) {
|
|
366
|
+
record()
|
|
244
367
|
tables.value = tables.value.map((t) => (next.has(t.id) ? { ...t, ...next.get(t.id)! } : t))
|
|
245
368
|
emit('move', [...next].map(([id, p]) => ({ id, ...p })))
|
|
246
369
|
}
|
|
247
370
|
function onClick(e: MouseEvent, t: FloorTable) {
|
|
248
371
|
if (suppressClick) return
|
|
249
372
|
if (props.editable && !(e.shiftKey || e.ctrlKey || e.metaKey)) selection.value = [t.id]
|
|
373
|
+
else if (!props.editable && props.selectable === 'single') selection.value = selection.value.length === 1 && selection.value[0] === t.id ? [] : [t.id]
|
|
374
|
+
else if (!props.editable && props.selectable === 'multiple')
|
|
375
|
+
selection.value = selection.value.includes(t.id) ? selection.value.filter((x) => x !== t.id) : [...selection.value, t.id]
|
|
250
376
|
emit('table-click', t, e)
|
|
251
377
|
}
|
|
252
378
|
function onKey(e: KeyboardEvent, t: FloorTable) {
|
|
@@ -268,24 +394,38 @@ onBeforeUnmount(() => {
|
|
|
268
394
|
window.removeEventListener('pointercancel', onUp)
|
|
269
395
|
})
|
|
270
396
|
// ── Zones, walls and decor ───────────────────────────────────────────────────────────────────────────────
|
|
271
|
-
const
|
|
272
|
-
door: { icon: 'door_front',
|
|
273
|
-
window: { icon: 'window',
|
|
274
|
-
plant: { icon: 'potted_plant',
|
|
275
|
-
column: {
|
|
276
|
-
restroom: { icon: 'wc',
|
|
277
|
-
kitchen: { icon: 'skillet',
|
|
278
|
-
register: { icon: 'point_of_sale',
|
|
279
|
-
stairs: { icon: 'stairs',
|
|
280
|
-
label: {
|
|
281
|
-
}
|
|
282
|
-
const
|
|
397
|
+
const BUILTIN_DECOR: Record<FloorDecorBuiltin, FloorDecorKind> = {
|
|
398
|
+
door: { label: 'Door', icon: 'door_front', width: 60, height: 14, shape: 'bar' },
|
|
399
|
+
window: { label: 'Window', icon: 'window', width: 80, height: 10, shape: 'bar' },
|
|
400
|
+
plant: { label: 'Plant', icon: 'potted_plant', width: 40, height: 40 },
|
|
401
|
+
column: { label: 'Column', width: 30, height: 30, shape: 'round', color: 'var(--color-outline)' },
|
|
402
|
+
restroom: { label: 'Restroom', icon: 'wc', width: 48, height: 48 },
|
|
403
|
+
kitchen: { label: 'Kitchen', icon: 'skillet', width: 48, height: 48 },
|
|
404
|
+
register: { label: 'Register', icon: 'point_of_sale', width: 48, height: 48 },
|
|
405
|
+
stairs: { label: 'Stairs', icon: 'stairs', width: 60, height: 60 },
|
|
406
|
+
label: { label: 'Label', width: 120, height: 30, shape: 'text' },
|
|
407
|
+
}
|
|
408
|
+
const kinds = computed<Record<string, FloorDecorKind>>(() => {
|
|
409
|
+
const out: Record<string, FloorDecorKind> = { ...BUILTIN_DECOR }
|
|
410
|
+
for (const [k, v] of Object.entries(props.decorKinds ?? {})) out[k] = { ...out[k], ...v }
|
|
411
|
+
return out
|
|
412
|
+
})
|
|
413
|
+
const kindOf = (d: FloorDecor): FloorDecorKind => kinds.value[d.kind] ?? { width: 40, height: 40 }
|
|
414
|
+
const decorSize = (d: FloorDecor) => ({ w: d.width ?? kindOf(d).width, h: d.height ?? kindOf(d).height })
|
|
415
|
+
function decorLook(k: FloorDecorKind) {
|
|
416
|
+
const shape = k.shape ?? 'box'
|
|
417
|
+
if (shape === 'text') return {}
|
|
418
|
+
const c = k.color ?? (shape === 'bar' ? 'surface-container-highest' : 'surface-container-high')
|
|
419
|
+
const bg = c.startsWith('surface') || c.startsWith('var(') || c.startsWith('#') || c.startsWith('rgb') || c.startsWith('hsl')
|
|
420
|
+
? (c.startsWith('surface') ? `var(--color-${c})` : c)
|
|
421
|
+
: `var(--color-${c}-container)`
|
|
422
|
+
return { background: bg, borderRadius: shape === 'round' ? '9999px' : shape === 'bar' ? '2px' : '8px' }
|
|
423
|
+
}
|
|
283
424
|
function areaLook(color?: string) {
|
|
284
425
|
const c = color ?? 'secondary'
|
|
285
426
|
return ROLES.has(c) ? { background: `color-mix(in srgb, var(--color-${c}-container) 45%, transparent)`, borderColor: `var(--color-${c})` } : { background: `color-mix(in srgb, ${c} 18%, transparent)`, borderColor: c }
|
|
286
427
|
}
|
|
287
|
-
|
|
288
|
-
const picked = ref<{ kind: 'area' | 'wall' | 'decor'; id: string | number } | null>(null)
|
|
428
|
+
// `picked` (a v-model) is declared with the other models
|
|
289
429
|
const isPicked = (kind: 'area' | 'wall' | 'decor', id: string | number) => picked.value?.kind === kind && picked.value.id === id
|
|
290
430
|
const toPlan = (e: { clientX: number; clientY: number }) => {
|
|
291
431
|
const r = root.value!.getBoundingClientRect()
|
|
@@ -317,32 +457,45 @@ function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: ()
|
|
|
317
457
|
}
|
|
318
458
|
const areaDraft = shallowRef<FloorArea | null>(null)
|
|
319
459
|
const shownAreas = computed(() => areas.value.map((a) => (areaDraft.value?.id === a.id ? areaDraft.value : a)).concat(areaDraft.value && !areas.value.some((a) => a.id === areaDraft.value!.id) ? [areaDraft.value] : []))
|
|
320
|
-
|
|
460
|
+
type Corner = 'nw' | 'ne' | 'sw' | 'se'
|
|
461
|
+
function onAreaDown(e: PointerEvent, a: FloorArea, corner: Corner | null) {
|
|
321
462
|
if (!props.editable || tool.value !== 'select' || e.button !== 0) return
|
|
322
463
|
e.stopPropagation()
|
|
323
464
|
picked.value = { kind: 'area', id: a.id }
|
|
324
465
|
selection.value = []
|
|
325
466
|
follow(e, (dx, dy) => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
467
|
+
if (!corner) {
|
|
468
|
+
areaDraft.value = { ...a, x: a.x + dx, y: a.y + dy }
|
|
469
|
+
return
|
|
470
|
+
}
|
|
471
|
+
// The opposite corner stays put
|
|
472
|
+
const min = props.grid || 20
|
|
473
|
+
const left = corner.includes('w')
|
|
474
|
+
const top = corner[0] === 'n'
|
|
475
|
+
const w = Math.max(min, a.width + (left ? -dx : dx))
|
|
476
|
+
const h = Math.max(min, a.height + (top ? -dy : dy))
|
|
477
|
+
areaDraft.value = { ...a, x: left ? a.x + a.width - w : a.x, y: top ? a.y + a.height - h : a.y, width: w, height: h }
|
|
329
478
|
}, () => {
|
|
330
479
|
const d = areaDraft.value!
|
|
331
480
|
areaDraft.value = null
|
|
481
|
+
record()
|
|
332
482
|
areas.value = areas.value.map((x) => (x.id === a.id ? { ...d, x: snap(d.x), y: snap(d.y), width: snap(d.width) || d.width, height: snap(d.height) || d.height } : x))
|
|
333
483
|
})
|
|
334
484
|
}
|
|
335
485
|
const decorDraft = shallowRef<FloorDecor | null>(null)
|
|
336
486
|
const shownDecor = computed(() => decor.value.map((d) => (decorDraft.value?.id === d.id ? decorDraft.value : d)))
|
|
337
|
-
function onDecorDown(e: PointerEvent, d: FloorDecor) {
|
|
487
|
+
function onDecorDown(e: PointerEvent, d: FloorDecor, resize = false) {
|
|
338
488
|
if (!props.editable || tool.value !== 'select' || e.button !== 0) return
|
|
339
489
|
e.stopPropagation()
|
|
340
490
|
picked.value = { kind: 'decor', id: d.id }
|
|
341
491
|
selection.value = []
|
|
342
|
-
|
|
492
|
+
const s0 = decorSize(d)
|
|
493
|
+
// Resizing from the bottom-right corner keeps it centered where it is, growing both ways
|
|
494
|
+
follow(e, (dx, dy) => (decorDraft.value = resize ? { ...d, width: Math.max(10, s0.w + dx * 2), height: Math.max(6, s0.h + dy * 2) } : { ...d, x: d.x + dx, y: d.y + dy }), () => {
|
|
343
495
|
const n = decorDraft.value!
|
|
344
496
|
decorDraft.value = null
|
|
345
|
-
|
|
497
|
+
record()
|
|
498
|
+
decor.value = decor.value.map((x) => (x.id === d.id ? (resize ? { ...n, width: Math.round(n.width!), height: Math.round(n.height!) } : { ...n, x: snap(n.x), y: snap(n.y) }) : x))
|
|
346
499
|
})
|
|
347
500
|
}
|
|
348
501
|
const wallDraft = shallowRef<FloorWall | null>(null)
|
|
@@ -351,13 +504,14 @@ const wallPath = (w: FloorWall) => w.points.map(([x, y], i) => `${i ? 'L' : 'M'}
|
|
|
351
504
|
function onWallDown(e: PointerEvent, w: FloorWall, vertex = -1) {
|
|
352
505
|
if (!props.editable || tool.value !== 'select' || e.button !== 0) return
|
|
353
506
|
e.stopPropagation()
|
|
354
|
-
picked.value = { kind: 'wall', id: w.id }
|
|
507
|
+
picked.value = { kind: 'wall', id: w.id, ...(vertex >= 0 && { vertex }) }
|
|
355
508
|
selection.value = []
|
|
356
509
|
follow(e, (dx, dy) => {
|
|
357
510
|
wallDraft.value = { ...w, points: w.points.map(([x, y], i) => (vertex < 0 || i === vertex ? [x + dx, y + dy] : [x, y])) }
|
|
358
511
|
}, () => {
|
|
359
512
|
const n = wallDraft.value!
|
|
360
513
|
wallDraft.value = null
|
|
514
|
+
record()
|
|
361
515
|
walls.value = walls.value.map((x) => (x.id === w.id ? { ...n, points: n.points.map(([x, y]) => [snap(x), snap(y)] as [number, number]) } : x))
|
|
362
516
|
})
|
|
363
517
|
}
|
|
@@ -387,6 +541,7 @@ function onPlanPointer(e: PointerEvent) {
|
|
|
387
541
|
const d = areaDraft.value!
|
|
388
542
|
areaDraft.value = null
|
|
389
543
|
if (d.width > 10 && d.height > 10) {
|
|
544
|
+
record()
|
|
390
545
|
areas.value = [...areas.value, { ...d, x: snap(d.x), y: snap(d.y), width: snap(d.width) || d.width, height: snap(d.height) || d.height }]
|
|
391
546
|
picked.value = { kind: 'area', id }
|
|
392
547
|
}
|
|
@@ -402,6 +557,7 @@ function finishWall() {
|
|
|
402
557
|
const pts = drawing.value?.filter((p, i, a) => !i || p[0] !== a[i - 1]![0] || p[1] !== a[i - 1]![1])
|
|
403
558
|
drawing.value = null
|
|
404
559
|
hover.value = null
|
|
560
|
+
if (pts && pts.length > 1) record()
|
|
405
561
|
if (pts && pts.length > 1) walls.value = [...walls.value, { id: newId('wall'), points: pts }]
|
|
406
562
|
}
|
|
407
563
|
function onPlanKey(e: KeyboardEvent) {
|
|
@@ -411,15 +567,254 @@ function onPlanKey(e: KeyboardEvent) {
|
|
|
411
567
|
else drawing.value = null
|
|
412
568
|
return
|
|
413
569
|
}
|
|
414
|
-
if (!props.editable
|
|
415
|
-
const
|
|
570
|
+
if (!props.editable) return
|
|
571
|
+
const mod = e.ctrlKey || e.metaKey
|
|
572
|
+
const key = e.key.toLowerCase()
|
|
573
|
+
if (mod && key === 'z') {
|
|
574
|
+
e.preventDefault()
|
|
575
|
+
if (e.shiftKey) redo()
|
|
576
|
+
else undo()
|
|
577
|
+
return
|
|
578
|
+
}
|
|
579
|
+
if (mod && key === 'y') {
|
|
580
|
+
e.preventDefault()
|
|
581
|
+
redo()
|
|
582
|
+
return
|
|
583
|
+
}
|
|
584
|
+
if (mod && key === 'd') {
|
|
585
|
+
e.preventDefault()
|
|
586
|
+
duplicate()
|
|
587
|
+
return
|
|
588
|
+
}
|
|
589
|
+
if (e.key !== 'Delete' && e.key !== 'Backspace') return
|
|
590
|
+
if (!picked.value && !selection.value.length) return
|
|
416
591
|
e.preventDefault()
|
|
592
|
+
removeSelected()
|
|
593
|
+
}
|
|
594
|
+
function removeSelected() {
|
|
595
|
+
if (!picked.value) {
|
|
596
|
+
if (selection.value.length) removeTables(selection.value)
|
|
597
|
+
return
|
|
598
|
+
}
|
|
599
|
+
const { kind, id, vertex } = picked.value
|
|
600
|
+
record()
|
|
417
601
|
if (kind === 'area') areas.value = areas.value.filter((a) => a.id !== id)
|
|
418
|
-
if (kind === 'wall')
|
|
602
|
+
if (kind === 'wall') {
|
|
603
|
+
const w = walls.value.find((x) => x.id === id)
|
|
604
|
+
// A picked corner goes (a wall keeps at least two); otherwise the whole wall
|
|
605
|
+
if (w && vertex !== undefined && w.points.length > 2) {
|
|
606
|
+
walls.value = walls.value.map((x) => (x.id === id ? { ...x, points: x.points.filter((_, i) => i !== vertex) } : x))
|
|
607
|
+
picked.value = { kind: 'wall', id }
|
|
608
|
+
return
|
|
609
|
+
}
|
|
610
|
+
walls.value = walls.value.filter((x) => x.id !== id)
|
|
611
|
+
}
|
|
419
612
|
if (kind === 'decor') decor.value = decor.value.filter((d) => d.id !== id)
|
|
420
613
|
picked.value = null
|
|
421
614
|
}
|
|
422
615
|
const svgEl = ref<SVGSVGElement>()
|
|
616
|
+
/** Removes tables (and takes them out of their merges; a merge left with one table goes) */
|
|
617
|
+
function removeTables(ids: (string | number)[]) {
|
|
618
|
+
record()
|
|
619
|
+
tables.value = tables.value.filter((t) => !ids.includes(t.id))
|
|
620
|
+
merges.value = merges.value.map((m) => ({ ...m, tables: m.tables.filter((x) => !ids.includes(x)) })).filter((m) => m.tables.length > 1)
|
|
621
|
+
selection.value = []
|
|
622
|
+
}
|
|
623
|
+
/** A copy of the selected tables, or of the picked zone or decor, a grid step or two away */
|
|
624
|
+
function duplicate() {
|
|
625
|
+
const off = Math.max(20, (props.grid || 10) * 2)
|
|
626
|
+
if (selection.value.length) {
|
|
627
|
+
const copies = tables.value.filter((t) => selection.value.includes(t.id)).map((t) => ({ ...t, id: newId('table'), x: t.x + off, y: t.y + off, status: undefined, badge: undefined }))
|
|
628
|
+
record()
|
|
629
|
+
tables.value = [...tables.value, ...copies]
|
|
630
|
+
selection.value = copies.map((t) => t.id)
|
|
631
|
+
return
|
|
632
|
+
}
|
|
633
|
+
const pk = picked.value
|
|
634
|
+
if (pk?.kind === 'area') {
|
|
635
|
+
const a = areas.value.find((x) => x.id === pk.id)
|
|
636
|
+
if (!a) return
|
|
637
|
+
const c = { ...a, id: newId('area'), x: a.x + off, y: a.y + off }
|
|
638
|
+
record()
|
|
639
|
+
areas.value = [...areas.value, c]
|
|
640
|
+
picked.value = { kind: 'area', id: c.id }
|
|
641
|
+
} else if (pk?.kind === 'decor') {
|
|
642
|
+
const d = decor.value.find((x) => x.id === pk.id)
|
|
643
|
+
if (!d) return
|
|
644
|
+
const c = { ...d, id: newId('decor'), x: d.x + off, y: d.y + off }
|
|
645
|
+
record()
|
|
646
|
+
decor.value = [...decor.value, c]
|
|
647
|
+
picked.value = { kind: 'decor', id: c.id }
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
// ── Rotating a table or a decor item by its handle (15° steps; Shift: free) ──
|
|
651
|
+
const rotateDraft = shallowRef<{ id: string | number; kind: 'table' | 'decor'; deg: number } | null>(null)
|
|
652
|
+
function onRotateDown(e: PointerEvent, kind: 'table' | 'decor', id: string | number, cx: number, cy: number) {
|
|
653
|
+
if (!props.editable || e.button !== 0) return
|
|
654
|
+
e.stopPropagation()
|
|
655
|
+
e.preventDefault()
|
|
656
|
+
const r = root.value!.getBoundingClientRect()
|
|
657
|
+
const angle = (ev: PointerEvent) => (Math.atan2(ev.clientY - (r.top + cy * scale.value), ev.clientX - (r.left + cx * scale.value)) * 180) / Math.PI + 90
|
|
658
|
+
const mv = (ev: PointerEvent) => {
|
|
659
|
+
if (ev.pointerId !== e.pointerId) return
|
|
660
|
+
let deg = ((angle(ev) % 360) + 360) % 360
|
|
661
|
+
if (!ev.shiftKey) deg = Math.round(deg / 15) * 15 % 360
|
|
662
|
+
rotateDraft.value = { id, kind, deg }
|
|
663
|
+
}
|
|
664
|
+
const up = (ev: PointerEvent) => {
|
|
665
|
+
if (ev.pointerId !== e.pointerId) return
|
|
666
|
+
window.removeEventListener('pointermove', mv)
|
|
667
|
+
window.removeEventListener('pointerup', up)
|
|
668
|
+
window.removeEventListener('pointercancel', up)
|
|
669
|
+
const d = rotateDraft.value
|
|
670
|
+
rotateDraft.value = null
|
|
671
|
+
if (!d) return
|
|
672
|
+
record()
|
|
673
|
+
if (kind === 'table') tables.value = tables.value.map((t) => (t.id === id ? { ...t, rotation: d.deg } : t))
|
|
674
|
+
else decor.value = decor.value.map((x) => (x.id === id ? { ...x, rotation: d.deg } : x))
|
|
675
|
+
}
|
|
676
|
+
window.addEventListener('pointermove', mv)
|
|
677
|
+
window.addEventListener('pointerup', up)
|
|
678
|
+
window.addEventListener('pointercancel', up)
|
|
679
|
+
}
|
|
680
|
+
const rotationOf = (kind: 'table' | 'decor', id: string | number, base?: number) => (rotateDraft.value?.kind === kind && rotateDraft.value.id === id ? rotateDraft.value.deg : base ?? 0)
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Merges tables (the selection by default, with what they're already merged with) into one group. `canMerge` can
|
|
684
|
+
* refuse (the `merge-refused` event says why). Returns the merge, or null.
|
|
685
|
+
*/
|
|
686
|
+
function merge(ids: (string | number)[] = selection.value, label?: string): FloorMerge | null {
|
|
687
|
+
const all = [...new Set(ids.flatMap((id) => merges.value.find((m) => m.tables.includes(id))?.tables ?? [id]))]
|
|
688
|
+
if (all.length < 2) return null
|
|
689
|
+
const ok = props.canMerge?.(all) ?? true
|
|
690
|
+
if (ok !== true) {
|
|
691
|
+
emit('merge-refused', all, typeof ok === 'string' ? ok : '')
|
|
692
|
+
return null
|
|
693
|
+
}
|
|
694
|
+
const name = label ?? all.map((id) => tables.value.find((t) => t.id === id)?.label ?? id).join(' + ')
|
|
695
|
+
const m: FloorMerge = { id: newId('merge'), tables: all, label: name }
|
|
696
|
+
record()
|
|
697
|
+
merges.value = [...merges.value.filter((x) => !x.tables.some((id) => all.includes(id))), m]
|
|
698
|
+
selection.value = []
|
|
699
|
+
emit('merge', m)
|
|
700
|
+
return m
|
|
701
|
+
}
|
|
702
|
+
/** Splits a merge (by its id, or the one a table is in) back into its tables */
|
|
703
|
+
function split(idOrTable: string | number) {
|
|
704
|
+
const m = merges.value.find((x) => x.id === idOrTable) ?? merges.value.find((x) => x.tables.includes(idOrTable))
|
|
705
|
+
if (!m) return
|
|
706
|
+
record()
|
|
707
|
+
merges.value = merges.value.filter((x) => x !== m)
|
|
708
|
+
emit('split', m)
|
|
709
|
+
}
|
|
710
|
+
// ── The context the toolbar, the inspector and your own controls work through ──
|
|
711
|
+
let lastEdit = { key: '', at: 0 }
|
|
712
|
+
function update(kind: FloorItemKind, id: string | number, patch: Record<string, unknown>) {
|
|
713
|
+
// Typing a label or dragging a slider is one undo step, not one per keystroke
|
|
714
|
+
const key = `${kind}:${id}:${Object.keys(patch).sort().join()}`
|
|
715
|
+
const now = performance.now()
|
|
716
|
+
if (key !== lastEdit.key || now - lastEdit.at > 1000) record()
|
|
717
|
+
lastEdit = { key, at: now }
|
|
718
|
+
const apply = <T extends { id: string | number }>(list: T[]) => list.map((x) => (x.id === id ? { ...x, ...patch } : x))
|
|
719
|
+
if (kind === 'table') tables.value = apply(tables.value)
|
|
720
|
+
else if (kind === 'area') areas.value = apply(areas.value)
|
|
721
|
+
else if (kind === 'wall') walls.value = apply(walls.value)
|
|
722
|
+
else decor.value = apply(decor.value)
|
|
723
|
+
}
|
|
724
|
+
function addTable(t: Partial<FloorTable> = {}): FloorTable {
|
|
725
|
+
const n = Math.max(0, ...tables.value.map((x) => Number(x.label)).filter((x) => Number.isFinite(x))) + 1
|
|
726
|
+
const table: FloorTable = { id: newId('table'), label: String(n), x: snap(props.width / 2), y: snap(props.height / 2), shape: 'square', seats: 4, ...t }
|
|
727
|
+
record()
|
|
728
|
+
tables.value = [...tables.value, table]
|
|
729
|
+
selection.value = [table.id]
|
|
730
|
+
picked.value = null
|
|
731
|
+
return table
|
|
732
|
+
}
|
|
733
|
+
function addDecor(kind: string, d: Partial<FloorDecor> = {}): FloorDecor {
|
|
734
|
+
const item: FloorDecor = { id: newId('decor'), kind, x: snap(props.width / 2), y: snap(props.height / 2), ...(kinds.value[kind]?.shape === 'text' && { label: kinds.value[kind]?.label ?? kind }), ...d }
|
|
735
|
+
record()
|
|
736
|
+
decor.value = [...decor.value, item]
|
|
737
|
+
picked.value = { kind: 'decor', id: item.id }
|
|
738
|
+
selection.value = []
|
|
739
|
+
return item
|
|
740
|
+
}
|
|
741
|
+
const context: FloorPlanContext = {
|
|
742
|
+
tables,
|
|
743
|
+
areas,
|
|
744
|
+
walls,
|
|
745
|
+
decor,
|
|
746
|
+
merges,
|
|
747
|
+
selection,
|
|
748
|
+
picked,
|
|
749
|
+
tool,
|
|
750
|
+
editable: computed(() => props.editable),
|
|
751
|
+
drawingWall: computed(() => !!drawing.value),
|
|
752
|
+
finishWall,
|
|
753
|
+
cancelWall: () => {
|
|
754
|
+
drawing.value = null
|
|
755
|
+
hover.value = null
|
|
756
|
+
},
|
|
757
|
+
kinds,
|
|
758
|
+
statuses: computed(() => props.statuses),
|
|
759
|
+
size: computed(() => ({ width: props.width, height: props.height })),
|
|
760
|
+
canUndo: computed(() => past.value.length > 0),
|
|
761
|
+
canRedo: computed(() => future.value.length > 0),
|
|
762
|
+
undo,
|
|
763
|
+
redo,
|
|
764
|
+
addTable,
|
|
765
|
+
addDecor,
|
|
766
|
+
update: update as FloorPlanContext['update'],
|
|
767
|
+
removeSelected,
|
|
768
|
+
removeTables,
|
|
769
|
+
duplicate,
|
|
770
|
+
merge,
|
|
771
|
+
split,
|
|
772
|
+
}
|
|
773
|
+
provide(FLOOR_PLAN_KEY, context)
|
|
774
|
+
|
|
775
|
+
defineExpose({
|
|
776
|
+
/** Everything above and more, for MFloorPlanToolbar / MFloorPlanInspector outside the plan (`:plan="plan"`) */
|
|
777
|
+
context,
|
|
778
|
+
addTable,
|
|
779
|
+
addDecor,
|
|
780
|
+
update,
|
|
781
|
+
removeSelected,
|
|
782
|
+
/** Merge tables (default: the selection) / split a merge (by its id or a table's) */
|
|
783
|
+
merge,
|
|
784
|
+
split,
|
|
785
|
+
/** Undo / redo the plan's own edits (also Ctrl+Z, Ctrl+Shift+Z or Ctrl+Y) */
|
|
786
|
+
undo,
|
|
787
|
+
redo,
|
|
788
|
+
canUndo: computed(() => past.value.length > 0),
|
|
789
|
+
canRedo: computed(() => future.value.length > 0),
|
|
790
|
+
/** Copy the selected tables, or the picked zone or decor (also Ctrl+D) */
|
|
791
|
+
duplicate,
|
|
792
|
+
/** Remove tables, taking them out of their merges (Delete does it for the selection) */
|
|
793
|
+
removeTables,
|
|
794
|
+
})
|
|
795
|
+
/** Double-click on a wall: a new corner there, on the nearest segment */
|
|
796
|
+
function onWallDblclick(e: MouseEvent, w: FloorWall) {
|
|
797
|
+
if (!props.editable || tool.value !== 'select') return
|
|
798
|
+
e.stopPropagation()
|
|
799
|
+
const p = toPlan(e)
|
|
800
|
+
let best = 0
|
|
801
|
+
let bestD = Infinity
|
|
802
|
+
for (let i = 1; i < w.points.length; i++) {
|
|
803
|
+
const [ax, ay] = w.points[i - 1]!
|
|
804
|
+
const [bx, by] = w.points[i]!
|
|
805
|
+
const len = (bx - ax) ** 2 + (by - ay) ** 2
|
|
806
|
+
const t = len ? Math.max(0, Math.min(1, ((p.x - ax) * (bx - ax) + (p.y - ay) * (by - ay)) / len)) : 0
|
|
807
|
+
const d = Math.hypot(ax + t * (bx - ax) - p.x, ay + t * (by - ay) - p.y)
|
|
808
|
+
if (d < bestD) {
|
|
809
|
+
bestD = d
|
|
810
|
+
best = i
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
const pt: [number, number] = [snap(p.x), snap(p.y)]
|
|
814
|
+
record()
|
|
815
|
+
walls.value = walls.value.map((x) => (x.id === w.id ? { ...x, points: [...x.points.slice(0, best), pt, ...x.points.slice(best)] } : x))
|
|
816
|
+
picked.value = { kind: 'wall', id: w.id, vertex: best }
|
|
817
|
+
}
|
|
423
818
|
|
|
424
819
|
const ariaOf = (p: (typeof placed.value)[number]) =>
|
|
425
820
|
[p.t.label, p.status?.label, p.t.seats ? locale.floorSeats.replace('{n}', String(p.t.seats)) : '', p.t.badge !== undefined ? String(p.t.badge) : ''].filter(Boolean).join(', ')
|
|
@@ -434,7 +829,7 @@ const gridStyle = computed(() => {
|
|
|
434
829
|
<template>
|
|
435
830
|
<div
|
|
436
831
|
ref="root"
|
|
437
|
-
class="m3-floor-plan
|
|
832
|
+
class="m3-floor-plan select-none"
|
|
438
833
|
:style="{ aspectRatio: `${width} / ${height}`, ...gridStyle }"
|
|
439
834
|
role="group"
|
|
440
835
|
tabindex="-1"
|
|
@@ -450,16 +845,23 @@ const gridStyle = computed(() => {
|
|
|
450
845
|
v-for="a in shownAreas"
|
|
451
846
|
:key="`a${a.id}`"
|
|
452
847
|
class="absolute rounded-lg border"
|
|
453
|
-
:class="[editable && tool === 'select' ? 'cursor-move' : 'pointer-events-none', isPicked('area', a.id) && 'ring-2 ring-primary']"
|
|
848
|
+
:class="[editable && tool === 'select' ? 'cursor-move touch-none' : 'pointer-events-none', isPicked('area', a.id) && 'ring-2 ring-primary']"
|
|
454
849
|
:style="{ left: `${a.x * scale}px`, top: `${a.y * scale}px`, width: `${a.width * scale}px`, height: `${a.height * scale}px`, ...areaLook(a.color) }"
|
|
455
|
-
@pointerdown="onAreaDown($event, a,
|
|
850
|
+
@pointerdown="onAreaDown($event, a, null)"
|
|
456
851
|
>
|
|
457
|
-
<
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
852
|
+
<slot name="area" :area="a" :picked="isPicked('area', a.id)" :scale="scale">
|
|
853
|
+
<span v-if="a.label" class="absolute top-1 left-2 text-label-medium text-on-surface-variant">{{ a.label }}</span>
|
|
854
|
+
</slot>
|
|
855
|
+
<template v-if="editable && isPicked('area', a.id)">
|
|
856
|
+
<span
|
|
857
|
+
v-for="c in (['nw', 'ne', 'sw', 'se'] as const)"
|
|
858
|
+
:key="c"
|
|
859
|
+
class="m3-floor-handle absolute size-3 rounded-xs border-2 border-primary bg-surface"
|
|
860
|
+
:class="[c[0] === 'n' ? '-top-1.5' : '-bottom-1.5', c[1] === 'w' ? '-left-1.5' : '-right-1.5', c === 'nw' || c === 'se' ? 'cursor-nwse-resize' : 'cursor-nesw-resize']"
|
|
861
|
+
:data-corner="c"
|
|
862
|
+
@pointerdown="onAreaDown($event, a, c)"
|
|
863
|
+
/>
|
|
864
|
+
</template>
|
|
463
865
|
</div>
|
|
464
866
|
|
|
465
867
|
<!-- Walls -->
|
|
@@ -470,10 +872,11 @@ const gridStyle = computed(() => {
|
|
|
470
872
|
fill="none"
|
|
471
873
|
stroke-linecap="round"
|
|
472
874
|
stroke-linejoin="round"
|
|
473
|
-
class="
|
|
474
|
-
:class="[editable && tool === 'select' && 'pointer-events-auto cursor-move', isPicked('wall', w.id) && '
|
|
875
|
+
class="m3-floor-wall"
|
|
876
|
+
:class="[editable && tool === 'select' && 'pointer-events-auto cursor-move touch-none', isPicked('wall', w.id) && 'm3-floor-wall-picked']"
|
|
475
877
|
:stroke-width="(w.thickness ?? 8) * scale"
|
|
476
878
|
@pointerdown="onWallDown($event, w)"
|
|
879
|
+
@dblclick="onWallDblclick($event, w)"
|
|
477
880
|
/>
|
|
478
881
|
<template v-if="editable && isPicked('wall', w.id)">
|
|
479
882
|
<circle
|
|
@@ -481,8 +884,9 @@ const gridStyle = computed(() => {
|
|
|
481
884
|
:key="i"
|
|
482
885
|
:cx="pt[0] * scale"
|
|
483
886
|
:cy="pt[1] * scale"
|
|
484
|
-
r="6"
|
|
485
|
-
class="pointer-events-auto cursor-move
|
|
887
|
+
:r="(picked?.vertex === i ? 8 : 6) * (coarse ? 1.6 : 1)"
|
|
888
|
+
class="pointer-events-auto cursor-move touch-none stroke-primary"
|
|
889
|
+
:class="picked?.vertex === i ? 'fill-primary' : 'fill-surface'"
|
|
486
890
|
stroke-width="2"
|
|
487
891
|
@pointerdown="onWallDown($event, w, i)"
|
|
488
892
|
/>
|
|
@@ -505,40 +909,83 @@ const gridStyle = computed(() => {
|
|
|
505
909
|
:key="`d${d.id}`"
|
|
506
910
|
class="absolute flex -translate-x-1/2 -translate-y-1/2 items-center justify-center text-on-surface-variant"
|
|
507
911
|
:class="[
|
|
508
|
-
|
|
509
|
-
editable && tool === 'select' ? 'cursor-move' : 'pointer-events-none',
|
|
912
|
+
editable && tool === 'select' ? 'cursor-move touch-none' : 'pointer-events-none',
|
|
510
913
|
isPicked('decor', d.id) && 'ring-2 ring-primary',
|
|
511
914
|
]"
|
|
512
|
-
:style="{ left: `${d.x * scale}px`, top: `${d.y * scale}px`, width: `${decorSize(d).w * scale}px`, height: `${decorSize(d).h * scale}px`, rotate: `${d.rotation
|
|
513
|
-
:aria-label="d.label ?? d.kind"
|
|
915
|
+
:style="{ left: `${d.x * scale}px`, top: `${d.y * scale}px`, width: `${decorSize(d).w * scale}px`, height: `${decorSize(d).h * scale}px`, rotate: `${rotationOf('decor', d.id, d.rotation)}deg`, ...decorLook(kindOf(d)) }"
|
|
916
|
+
:aria-label="d.label ?? kindOf(d).label ?? d.kind"
|
|
514
917
|
role="img"
|
|
515
918
|
@pointerdown="onDecorDown($event, d)"
|
|
516
919
|
>
|
|
517
|
-
<
|
|
518
|
-
|
|
920
|
+
<slot name="decor" :item="d" :kind="kindOf(d)" :picked="isPicked('decor', d.id)" :scale="scale">
|
|
921
|
+
<MIcon v-if="kindOf(d).icon && kindOf(d).shape !== 'bar'" :name="kindOf(d).icon!" :size="Math.max(12, Math.min(decorSize(d).w, decorSize(d).h) * 0.6 * scale)" />
|
|
922
|
+
<span v-if="kindOf(d).shape === 'text'" class="truncate text-title-small text-on-surface-variant" :style="{ fontSize: `${Math.max(10, 16 * scale)}px` }">{{ d.label }}</span>
|
|
923
|
+
</slot>
|
|
924
|
+
<span
|
|
925
|
+
v-if="editable && isPicked('decor', d.id)"
|
|
926
|
+
class="m3-floor-handle absolute -right-1.5 -bottom-1.5 size-3 cursor-nwse-resize rounded-xs border-2 border-primary bg-surface"
|
|
927
|
+
data-resize
|
|
928
|
+
@pointerdown="onDecorDown($event, d, true)"
|
|
929
|
+
/>
|
|
930
|
+
<span
|
|
931
|
+
v-if="editable && isPicked('decor', d.id)"
|
|
932
|
+
class="m3-floor-handle absolute -top-6 left-1/2 size-3.5 -translate-x-1/2 cursor-grab rounded-full border-2 border-primary bg-surface"
|
|
933
|
+
:aria-label="locale.floorRotate"
|
|
934
|
+
data-rotate
|
|
935
|
+
@pointerdown="onRotateDown($event, 'decor', d.id, d.x, d.y)"
|
|
936
|
+
/>
|
|
519
937
|
</div>
|
|
520
938
|
|
|
521
939
|
<!-- Merged tables: one outline around the group -->
|
|
522
|
-
<
|
|
523
|
-
v-for="
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
940
|
+
<svg v-if="mergeShapes.some((ms) => ms!.links.length)" class="pointer-events-none absolute inset-0 size-full overflow-visible">
|
|
941
|
+
<template v-for="ms in mergeShapes" :key="`ml${ms!.m.id}`">
|
|
942
|
+
<line
|
|
943
|
+
v-for="(l, i) in ms!.links"
|
|
944
|
+
:key="i"
|
|
945
|
+
class="m3-floor-merge-link"
|
|
946
|
+
:x1="l[0] * scale"
|
|
947
|
+
:y1="l[1] * scale"
|
|
948
|
+
:x2="l[2] * scale"
|
|
949
|
+
:y2="l[3] * scale"
|
|
950
|
+
stroke-width="2"
|
|
951
|
+
stroke-dasharray="6 5"
|
|
952
|
+
stroke-linecap="round"
|
|
953
|
+
/>
|
|
954
|
+
</template>
|
|
955
|
+
</svg>
|
|
956
|
+
<template v-for="ms in mergeShapes" :key="`m${ms!.m.id}`">
|
|
957
|
+
<div
|
|
958
|
+
v-for="(b, i) in ms!.clusters"
|
|
959
|
+
:key="i"
|
|
960
|
+
class="m3-floor-merge pointer-events-none absolute rounded-2xl border-2 border-dashed"
|
|
961
|
+
:style="{ left: `${b.x * scale}px`, top: `${b.y * scale}px`, width: `${b.w * scale}px`, height: `${b.h * scale}px` }"
|
|
962
|
+
>
|
|
963
|
+
<slot v-if="i === 0" name="merge" :merge="ms!.m" :tables="ms!.m.tables">
|
|
964
|
+
<span v-if="ms!.m.label" class="m3-floor-merge-label absolute -top-2.5 left-3 rounded-full px-2 text-label-small whitespace-nowrap">{{ ms!.m.label }}</span>
|
|
965
|
+
</slot>
|
|
966
|
+
</div>
|
|
967
|
+
</template>
|
|
530
968
|
|
|
531
969
|
<div
|
|
532
970
|
v-for="p in placed"
|
|
533
971
|
:key="p.t.id"
|
|
534
972
|
class="absolute"
|
|
535
973
|
:class="!draft?.has(p.t.id) && 'transition-[left,top] duration-200 ease-out'"
|
|
536
|
-
:style="{ left: `${p.x * scale}px`, top: `${p.y * scale}px`, transform: `rotate(${p.t.rotation
|
|
974
|
+
:style="{ left: `${p.x * scale}px`, top: `${p.y * scale}px`, transform: `rotate(${rotationOf('table', p.t.id, p.t.rotation)}deg)` }"
|
|
537
975
|
>
|
|
976
|
+
<!-- Rotation handle of the one table picked while editing -->
|
|
977
|
+
<span
|
|
978
|
+
v-if="editable && selection.length === 1 && selection[0] === p.t.id && tool === 'select'"
|
|
979
|
+
class="m3-floor-handle absolute z-10 size-3.5 -translate-x-1/2 -translate-y-1/2 cursor-grab rounded-full border-2 border-primary bg-surface"
|
|
980
|
+
:style="{ left: '0px', top: `${-(p.size.h / 2 + CHAIR + 18) * scale}px` }"
|
|
981
|
+
:aria-label="locale.floorRotate"
|
|
982
|
+
data-rotate
|
|
983
|
+
@pointerdown="onRotateDown($event, 'table', p.t.id, p.x, p.y)"
|
|
984
|
+
/>
|
|
538
985
|
<span
|
|
539
986
|
v-for="(ch, i) in p.chairs"
|
|
540
987
|
:key="i"
|
|
541
|
-
class="pointer-events-none absolute rounded-md
|
|
988
|
+
class="m3-floor-chair pointer-events-none absolute rounded-md"
|
|
542
989
|
:style="{ width: `${CHAIR * scale}px`, height: `${CHAIR * 0.75 * scale}px`, left: `${ch.x * scale}px`, top: `${ch.y * scale}px`, transform: `translate(-50%, -50%) rotate(${ch.r}deg)` }"
|
|
543
990
|
/>
|
|
544
991
|
<div
|
|
@@ -558,24 +1005,76 @@ const gridStyle = computed(() => {
|
|
|
558
1005
|
@click="onClick($event, p.t)"
|
|
559
1006
|
@keydown="onKey($event, p.t)"
|
|
560
1007
|
>
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
<
|
|
564
|
-
|
|
1008
|
+
<!-- The inside stays upright however the table turns -->
|
|
1009
|
+
<span class="flex flex-col items-center justify-center gap-0.5" :style="{ transform: `rotate(${-rotationOf('table', p.t.id, p.t.rotation)}deg)` }">
|
|
1010
|
+
<slot name="table" :table="p.t" :status="p.status" :selected="selection.includes(p.t.id)">
|
|
1011
|
+
<MIcon v-if="p.status?.icon && scale > 0.5" :name="p.status.icon" :size="Math.max(12, 18 * scale)" class="opacity-80" />
|
|
1012
|
+
<span class="max-w-full truncate px-1 leading-tight font-medium">{{ p.t.label }}</span>
|
|
1013
|
+
</slot>
|
|
1014
|
+
</span>
|
|
565
1015
|
<span
|
|
566
1016
|
v-if="p.t.badge !== undefined"
|
|
567
1017
|
class="absolute -top-2 -right-2 min-w-5 rounded-full bg-error px-1.5 text-center text-label-small leading-5 text-on-error"
|
|
568
|
-
:style="{ transform: `rotate(${-(p.t.rotation
|
|
1018
|
+
:style="{ transform: `rotate(${-rotationOf('table', p.t.id, p.t.rotation)}deg)` }"
|
|
569
1019
|
>{{ p.t.badge }}</span>
|
|
570
1020
|
</div>
|
|
571
1021
|
</div>
|
|
1022
|
+
<!-- Anything of yours over the plan, placed in plan units with toPx -->
|
|
1023
|
+
<slot name="overlay" :scale="scale" :to-px="(v: number) => v * scale" />
|
|
572
1024
|
</div>
|
|
573
1025
|
</template>
|
|
574
1026
|
|
|
575
1027
|
<style>
|
|
1028
|
+
/* Defaults a consumer's own utilities override: none on the root itself. The colors are custom properties to restyle:
|
|
1029
|
+
--m3-floor-wall, --m3-floor-wall-picked, --m3-floor-chair, --m3-floor-merge, --m3-floor-merge-label */
|
|
576
1030
|
@layer base {
|
|
577
1031
|
.m3-floor-plan {
|
|
1032
|
+
--m3-floor-wall: var(--color-on-surface-variant);
|
|
1033
|
+
--m3-floor-wall-picked: var(--color-primary);
|
|
1034
|
+
--m3-floor-chair: var(--color-outline-variant);
|
|
1035
|
+
--m3-floor-merge: var(--color-primary);
|
|
1036
|
+
--m3-floor-merge-label: var(--color-on-primary);
|
|
1037
|
+
position: relative;
|
|
1038
|
+
overflow: hidden;
|
|
578
1039
|
width: 100%;
|
|
1040
|
+
border-radius: var(--radius-xl, 12px);
|
|
1041
|
+
background-color: var(--color-surface-container-low);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
@layer base {
|
|
1045
|
+
/* Handles: never a scroll, and a finger-sized target around the small mark */
|
|
1046
|
+
.m3-floor-handle {
|
|
1047
|
+
touch-action: none;
|
|
1048
|
+
}
|
|
1049
|
+
.m3-floor-handle::after {
|
|
1050
|
+
content: '';
|
|
1051
|
+
position: absolute;
|
|
1052
|
+
inset: -6px;
|
|
1053
|
+
}
|
|
1054
|
+
@media (pointer: coarse) {
|
|
1055
|
+
.m3-floor-handle::after {
|
|
1056
|
+
inset: -16px;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
.m3-floor-wall {
|
|
1060
|
+
stroke: var(--m3-floor-wall);
|
|
1061
|
+
}
|
|
1062
|
+
.m3-floor-wall-picked {
|
|
1063
|
+
stroke: var(--m3-floor-wall-picked);
|
|
1064
|
+
}
|
|
1065
|
+
.m3-floor-chair {
|
|
1066
|
+
background: var(--m3-floor-chair);
|
|
1067
|
+
}
|
|
1068
|
+
.m3-floor-merge {
|
|
1069
|
+
border-color: color-mix(in srgb, var(--m3-floor-merge) 60%, transparent);
|
|
1070
|
+
background: color-mix(in srgb, var(--m3-floor-merge) 5%, transparent);
|
|
1071
|
+
}
|
|
1072
|
+
.m3-floor-merge-link {
|
|
1073
|
+
stroke: color-mix(in srgb, var(--m3-floor-merge) 60%, transparent);
|
|
1074
|
+
}
|
|
1075
|
+
.m3-floor-merge-label {
|
|
1076
|
+
background: var(--m3-floor-merge);
|
|
1077
|
+
color: var(--m3-floor-merge-label);
|
|
579
1078
|
}
|
|
580
1079
|
}
|
|
581
1080
|
</style>
|