@m3ui-vue/m3ui-vue 1.2.2 → 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 +3010 -376
- package/dist/MButton-Bl_BSUep.js +172 -0
- package/dist/MButton-Bl_BSUep.js.map +1 -0
- package/dist/MDialog-D_Yik8ou.js +173 -0
- package/dist/MDialog-D_Yik8ou.js.map +1 -0
- package/dist/MIconButton-DoNotQ9v.js +282 -0
- package/dist/MIconButton-DoNotQ9v.js.map +1 -0
- package/dist/MListItem-BxifHJdU.js +824 -0
- package/dist/MListItem-BxifHJdU.js.map +1 -0
- package/dist/MLoadingIndicator-BxbFhSX6.js +115 -0
- package/dist/MLoadingIndicator-BxbFhSX6.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-BeN9QcB3.js +435 -0
- package/dist/MSeekBar-BeN9QcB3.js.map +1 -0
- package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
- package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
- package/dist/MSlider-BVSbJlGS.js +691 -0
- package/dist/MSlider-BVSbJlGS.js.map +1 -0
- package/dist/MSpinner-C2SUnWk4.js +65 -0
- package/dist/MSpinner-C2SUnWk4.js.map +1 -0
- package/dist/MTextField-CEkWSZ2v.js +296 -0
- package/dist/MTextField-CEkWSZ2v.js.map +1 -0
- package/dist/MTooltip-CodJGEO-.js +756 -0
- package/dist/MTooltip-CodJGEO-.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 +150 -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 +248 -0
- 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 +318 -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/useFloorPlan.d.ts +58 -0
- package/dist/composables/useFlow.d.ts +266 -0
- package/dist/composables/useGantt.d.ts +87 -0
- package/dist/composables/useLocale.d.ts +204 -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 +1702 -0
- package/dist/draw.js.map +1 -0
- package/dist/flow.d.ts +14 -0
- package/dist/flow.js +3547 -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 +9 -0
- package/dist/locales/index.js +1435 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +8248 -7637
- 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-CaWwi-b6.js} +206 -2
- package/dist/useLocale-CaWwi-b6.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 +118 -0
- package/src/__tests__/MFloorPlan.test.ts +299 -0
- package/src/__tests__/MFlow.test.ts +590 -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 +819 -0
- package/src/components/MDrawLayers.vue +114 -0
- package/src/components/MDrawToolbar.vue +171 -0
- package/src/components/MFloorPlan.vue +1080 -0
- package/src/components/MFloorPlanInspector.vue +169 -0
- package/src/components/MFloorPlanToolbar.vue +128 -0
- package/src/components/MFlow.vue +2060 -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 +1270 -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/useFloorPlan.ts +73 -0
- package/src/composables/useFlow.ts +250 -0
- package/src/composables/useGantt.ts +92 -0
- package/src/composables/useLocale.ts +410 -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 +9 -0
- package/src/locales/de.ts +204 -0
- package/src/locales/es.ts +204 -0
- package/src/locales/fr.ts +204 -0
- package/src/locales/ja.ts +204 -0
- package/src/locales/ko.ts +204 -0
- package/src/locales/pt.ts +204 -0
- package/src/locales/zh.ts +204 -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,1080 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/** A table on the plan, in plan units (not pixels) */
|
|
3
|
+
export interface FloorTable {
|
|
4
|
+
id: string | number
|
|
5
|
+
label: string
|
|
6
|
+
x: number
|
|
7
|
+
y: number
|
|
8
|
+
shape?: 'round' | 'square' | 'rect'
|
|
9
|
+
seats?: number
|
|
10
|
+
/** Size in plan units (default: from the shape and the seats) */
|
|
11
|
+
width?: number
|
|
12
|
+
height?: number
|
|
13
|
+
/** Degrees */
|
|
14
|
+
rotation?: number
|
|
15
|
+
/** A key of `statuses` */
|
|
16
|
+
status?: string
|
|
17
|
+
/** A small badge: minutes seated, the total, a count… */
|
|
18
|
+
badge?: string | number
|
|
19
|
+
data?: Record<string, unknown>
|
|
20
|
+
}
|
|
21
|
+
/** Tables joined together (drawn as one group) */
|
|
22
|
+
export interface FloorMerge {
|
|
23
|
+
id: string | number
|
|
24
|
+
tables: (string | number)[]
|
|
25
|
+
label?: string
|
|
26
|
+
}
|
|
27
|
+
/** A zone of the room (terrace, main hall, VIP): a rectangle behind the tables */
|
|
28
|
+
export interface FloorArea {
|
|
29
|
+
id: string | number
|
|
30
|
+
label?: string
|
|
31
|
+
x: number
|
|
32
|
+
y: number
|
|
33
|
+
width: number
|
|
34
|
+
height: number
|
|
35
|
+
/** An M3 color role or any CSS color */
|
|
36
|
+
color?: string
|
|
37
|
+
}
|
|
38
|
+
/** A wall: a line through its points */
|
|
39
|
+
export interface FloorWall {
|
|
40
|
+
id: string | number
|
|
41
|
+
points: [number, number][]
|
|
42
|
+
thickness?: number
|
|
43
|
+
}
|
|
44
|
+
/** Something on the plan that isn't a table: a door, a window, a plant, a column, the register, a text label… */
|
|
45
|
+
export interface FloorDecor {
|
|
46
|
+
id: string | number
|
|
47
|
+
/** A built-in kind, or one of yours from `decorKinds` */
|
|
48
|
+
kind: FloorDecorBuiltin | (string & {})
|
|
49
|
+
x: number
|
|
50
|
+
y: number
|
|
51
|
+
width?: number
|
|
52
|
+
height?: number
|
|
53
|
+
rotation?: number
|
|
54
|
+
/** The text of a label (or a caption under the others) */
|
|
55
|
+
label?: string
|
|
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
|
|
72
|
+
/** How a status looks: an M3 color role ('primary', 'tertiary', 'error'…) or any CSS color, an icon, a name */
|
|
73
|
+
export interface FloorStatus {
|
|
74
|
+
label: string
|
|
75
|
+
color: string
|
|
76
|
+
icon?: string
|
|
77
|
+
}
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<script setup lang="ts">
|
|
81
|
+
/**
|
|
82
|
+
* A floor plan of tables: to arrange them (`editable`: drag one or several, snapped to a grid, arrows nudge) and to
|
|
83
|
+
* run service (each table colored by its status, with a badge, a click to open it). Merged tables are drawn as one
|
|
84
|
+
* group. Positions are plan units scaled to the component's width, so the same plan fits a phone and a wall screen.
|
|
85
|
+
* Not an M3 spec component.
|
|
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
|
+
*
|
|
93
|
+
* @slot table The inside of a table: `{ table, status, selected }`
|
|
94
|
+
* @event table-click A table was clicked or opened with Enter (not after a drag)
|
|
95
|
+
* @event move Tables moved by a drag or the arrows, with their new positions (`{ id, x, y }[]`), to save them
|
|
96
|
+
*/
|
|
97
|
+
import { computed, onBeforeUnmount, onMounted, provide, ref, shallowRef } from 'vue'
|
|
98
|
+
import { useLocale } from '../composables/useLocale'
|
|
99
|
+
import { FLOOR_PLAN_KEY, type FloorItemKind, type FloorPlanContext } from '../composables/useFloorPlan'
|
|
100
|
+
import MIcon from './MIcon.vue'
|
|
101
|
+
|
|
102
|
+
const props = withDefaults(defineProps<{
|
|
103
|
+
/** The plan's size in plan units */
|
|
104
|
+
width?: number
|
|
105
|
+
height?: number
|
|
106
|
+
/** Status keys to their look */
|
|
107
|
+
statuses?: Record<string, FloorStatus>
|
|
108
|
+
/** Drag tables around; otherwise a click opens one */
|
|
109
|
+
editable?: boolean
|
|
110
|
+
/** Grid step in plan units (0: no snapping) */
|
|
111
|
+
grid?: number
|
|
112
|
+
/** Draw the grid while editing */
|
|
113
|
+
showGrid?: boolean
|
|
114
|
+
/** Draw chairs from `seats` */
|
|
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
|
|
122
|
+
/** Accessible name */
|
|
123
|
+
label?: string
|
|
124
|
+
}>(), {
|
|
125
|
+
width: 1000,
|
|
126
|
+
height: 600,
|
|
127
|
+
statuses: () => ({
|
|
128
|
+
free: { label: 'Free', color: 'surface' },
|
|
129
|
+
occupied: { label: 'Occupied', color: 'primary', icon: 'restaurant' },
|
|
130
|
+
bill: { label: 'Bill requested', color: 'tertiary', icon: 'receipt_long' },
|
|
131
|
+
reserved: { label: 'Reserved', color: 'secondary', icon: 'event' },
|
|
132
|
+
}),
|
|
133
|
+
editable: false,
|
|
134
|
+
grid: 10,
|
|
135
|
+
showGrid: true,
|
|
136
|
+
chairs: true,
|
|
137
|
+
selectable: 'none',
|
|
138
|
+
})
|
|
139
|
+
const tables = defineModel<FloorTable[]>('tables', { default: () => [] })
|
|
140
|
+
const merges = defineModel<FloorMerge[]>('merges', { default: () => [] })
|
|
141
|
+
const selection = defineModel<(string | number)[]>('selection', { default: () => [] })
|
|
142
|
+
const areas = defineModel<FloorArea[]>('areas', { default: () => [] })
|
|
143
|
+
const walls = defineModel<FloorWall[]>('walls', { default: () => [] })
|
|
144
|
+
const decor = defineModel<FloorDecor[]>('decor', { default: () => [] })
|
|
145
|
+
/** While editing: `select` moves things, `wall` draws a wall (click each corner, double-click or Enter to end), `area` drags out a zone */
|
|
146
|
+
const tool = defineModel<'select' | 'wall' | 'area'>('tool', { default: 'select' })
|
|
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
|
+
}>()
|
|
188
|
+
const locale = useLocale()
|
|
189
|
+
|
|
190
|
+
const root = ref<HTMLElement>()
|
|
191
|
+
/** A finger: bigger handles */
|
|
192
|
+
const coarse = ref(typeof matchMedia !== 'undefined' && matchMedia('(pointer: coarse)').matches)
|
|
193
|
+
const scale = ref(1)
|
|
194
|
+
let ro: ResizeObserver | null = null
|
|
195
|
+
onMounted(() => {
|
|
196
|
+
ro = new ResizeObserver(() => (scale.value = (root.value?.clientWidth || props.width) / props.width))
|
|
197
|
+
ro.observe(root.value!)
|
|
198
|
+
scale.value = (root.value!.clientWidth || props.width) / props.width
|
|
199
|
+
})
|
|
200
|
+
onBeforeUnmount(() => ro?.disconnect())
|
|
201
|
+
|
|
202
|
+
// ── Geometry ────────────────────────────────────────────────────────────────────────────────────────────
|
|
203
|
+
const CHAIR = 16
|
|
204
|
+
type FloorBox = { w: number; h: number }
|
|
205
|
+
function sizeOf(t: FloorTable): FloorBox {
|
|
206
|
+
const n = t.seats ?? 4
|
|
207
|
+
const shape = t.shape ?? 'square'
|
|
208
|
+
if (t.width && (t.height || shape !== 'rect')) return { w: t.width, h: t.height ?? t.width }
|
|
209
|
+
if (shape === 'round') {
|
|
210
|
+
const d = Math.max(60, 40 + n * 8)
|
|
211
|
+
return { w: d, h: d }
|
|
212
|
+
}
|
|
213
|
+
if (shape === 'square') return { w: 72, h: 72 }
|
|
214
|
+
return { w: Math.max(100, Math.ceil(n / 2) * 40 + 20), h: 72 }
|
|
215
|
+
}
|
|
216
|
+
/** Chairs around a table, as centers relative to its center */
|
|
217
|
+
function chairsOf(t: FloorTable, s: FloorBox): { x: number; y: number; r: number }[] {
|
|
218
|
+
const n = t.seats ?? 0
|
|
219
|
+
if (!props.chairs || !n) return []
|
|
220
|
+
const gap = CHAIR / 2 + 4
|
|
221
|
+
if ((t.shape ?? 'square') === 'round') {
|
|
222
|
+
return Array.from({ length: n }, (_, i) => {
|
|
223
|
+
const a = (i / n) * Math.PI * 2 - Math.PI / 2
|
|
224
|
+
return { x: Math.cos(a) * (s.w / 2 + gap), y: Math.sin(a) * (s.h / 2 + gap), r: (a * 180) / Math.PI + 90 }
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
// Long sides first (top and bottom), then the ends
|
|
228
|
+
const sides: { len: number; at: (f: number) => { x: number; y: number; r: number } }[] = [
|
|
229
|
+
{ len: s.w, at: (f) => ({ x: -s.w / 2 + f * s.w, y: -s.h / 2 - gap, r: 0 }) },
|
|
230
|
+
{ len: s.w, at: (f) => ({ x: -s.w / 2 + f * s.w, y: s.h / 2 + gap, r: 180 }) },
|
|
231
|
+
{ len: s.h, at: (f) => ({ x: -s.w / 2 - gap, y: -s.h / 2 + f * s.h, r: 270 }) },
|
|
232
|
+
{ len: s.h, at: (f) => ({ x: s.w / 2 + gap, y: -s.h / 2 + f * s.h, r: 90 }) },
|
|
233
|
+
]
|
|
234
|
+
const square = (t.shape ?? 'square') === 'square'
|
|
235
|
+
const per = [0, 0, 0, 0]
|
|
236
|
+
for (let i = 0; i < n; i++) {
|
|
237
|
+
if (square) per[i % 4]!++
|
|
238
|
+
else if (n > 2 && i >= n - 2 && n % 2 === 0 && n >= 6) per[i === n - 2 ? 2 : 3]!++
|
|
239
|
+
else per[i % 2]!++
|
|
240
|
+
}
|
|
241
|
+
return sides.flatMap((side, k) => Array.from({ length: per[k]! }, (_, i) => side.at((i + 1) / (per[k]! + 1))))
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// While a drag moves tables, their positions live here until the drop
|
|
245
|
+
const draft = shallowRef<Map<string | number, { x: number; y: number }> | null>(null)
|
|
246
|
+
const placed = computed(() =>
|
|
247
|
+
tables.value.map((t) => {
|
|
248
|
+
const at = draft.value?.get(t.id) ?? { x: t.x, y: t.y }
|
|
249
|
+
const size = sizeOf(t)
|
|
250
|
+
return { t, x: at.x, y: at.y, size, chairs: chairsOf(t, size), status: t.status ? props.statuses[t.status] : undefined }
|
|
251
|
+
}),
|
|
252
|
+
)
|
|
253
|
+
const ROLES = new Set(['primary', 'secondary', 'tertiary', 'error', 'success', 'surface'])
|
|
254
|
+
function look(st?: FloorStatus) {
|
|
255
|
+
if (!st || st.color === 'surface') return { background: 'var(--color-surface-container-highest)', color: 'var(--color-on-surface)' }
|
|
256
|
+
if (ROLES.has(st.color)) return { background: `var(--color-${st.color}-container)`, color: `var(--color-on-${st.color}-container)` }
|
|
257
|
+
return { background: st.color, color: '#fff' }
|
|
258
|
+
}
|
|
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(() =>
|
|
264
|
+
merges.value.map((m) => {
|
|
265
|
+
const ms = placed.value.filter((p) => m.tables.includes(p.t.id))
|
|
266
|
+
if (!ms.length) return null
|
|
267
|
+
const pad = CHAIR + 10
|
|
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 }
|
|
295
|
+
}).filter((b) => !!b),
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
// ── Dragging ────────────────────────────────────────────────────────────────────────────────────────────
|
|
299
|
+
let drag: { id: number; sx: number; sy: number; start: Map<string | number, { x: number; y: number }>; moved: boolean; pick?: string | number } | null = null
|
|
300
|
+
let suppressClick = false
|
|
301
|
+
const snap = (v: number) => (props.grid ? Math.round(v / props.grid) * props.grid : v)
|
|
302
|
+
function clamp(t: FloorTable, x: number, y: number) {
|
|
303
|
+
const s = sizeOf(t)
|
|
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)) }
|
|
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
|
|
310
|
+
function onDown(e: PointerEvent, t: FloorTable) {
|
|
311
|
+
if (!props.editable || e.button !== 0 || tool.value !== 'select') return
|
|
312
|
+
e.stopPropagation()
|
|
313
|
+
picked.value = null
|
|
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
|
|
326
|
+
const ids = selection.value.includes(t.id) ? selection.value : [t.id]
|
|
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 }
|
|
328
|
+
window.addEventListener('pointermove', onMove)
|
|
329
|
+
window.addEventListener('pointerup', onUp)
|
|
330
|
+
window.addEventListener('pointercancel', onUp)
|
|
331
|
+
}
|
|
332
|
+
function onMove(e: PointerEvent) {
|
|
333
|
+
if (!drag || e.pointerId !== drag.id) return
|
|
334
|
+
const dx = (e.clientX - drag.sx) / scale.value
|
|
335
|
+
const dy = (e.clientY - drag.sy) / scale.value
|
|
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
|
+
}
|
|
341
|
+
drag.moved = true
|
|
342
|
+
const next = new Map<string | number, { x: number; y: number }>()
|
|
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))
|
|
344
|
+
draft.value = next
|
|
345
|
+
}
|
|
346
|
+
function onUp(e: PointerEvent) {
|
|
347
|
+
if (!drag || e.pointerId !== drag.id) return
|
|
348
|
+
clearTimeout(longPress)
|
|
349
|
+
if (longPressed) {
|
|
350
|
+
suppressClick = true
|
|
351
|
+
setTimeout(() => (suppressClick = false))
|
|
352
|
+
}
|
|
353
|
+
window.removeEventListener('pointermove', onMove)
|
|
354
|
+
window.removeEventListener('pointerup', onUp)
|
|
355
|
+
window.removeEventListener('pointercancel', onUp)
|
|
356
|
+
const d = draft.value
|
|
357
|
+
const moved = drag.moved && d && e.type !== 'pointercancel'
|
|
358
|
+
drag = null
|
|
359
|
+
draft.value = null
|
|
360
|
+
if (!moved) return
|
|
361
|
+
suppressClick = true
|
|
362
|
+
setTimeout(() => (suppressClick = false))
|
|
363
|
+
commitMoves(new Map([...d!].map(([id, p]) => [id, clamp(tables.value.find((x) => x.id === id)!, snap(p.x), snap(p.y))])))
|
|
364
|
+
}
|
|
365
|
+
function commitMoves(next: Map<string | number, { x: number; y: number }>) {
|
|
366
|
+
record()
|
|
367
|
+
tables.value = tables.value.map((t) => (next.has(t.id) ? { ...t, ...next.get(t.id)! } : t))
|
|
368
|
+
emit('move', [...next].map(([id, p]) => ({ id, ...p })))
|
|
369
|
+
}
|
|
370
|
+
function onClick(e: MouseEvent, t: FloorTable) {
|
|
371
|
+
if (suppressClick) return
|
|
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]
|
|
376
|
+
emit('table-click', t, e)
|
|
377
|
+
}
|
|
378
|
+
function onKey(e: KeyboardEvent, t: FloorTable) {
|
|
379
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
380
|
+
e.preventDefault()
|
|
381
|
+
emit('table-click', t, e)
|
|
382
|
+
return
|
|
383
|
+
}
|
|
384
|
+
const dir = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }[e.key]
|
|
385
|
+
if (!dir || !props.editable) return
|
|
386
|
+
e.preventDefault()
|
|
387
|
+
const step = (props.grid || 1) * (e.shiftKey ? 5 : 1)
|
|
388
|
+
const ids = selection.value.includes(t.id) ? selection.value : [t.id]
|
|
389
|
+
commitMoves(new Map(tables.value.filter((x) => ids.includes(x.id)).map((x) => [x.id, clamp(x, x.x + dir[0]! * step, x.y + dir[1]! * step)])))
|
|
390
|
+
}
|
|
391
|
+
onBeforeUnmount(() => {
|
|
392
|
+
window.removeEventListener('pointermove', onMove)
|
|
393
|
+
window.removeEventListener('pointerup', onUp)
|
|
394
|
+
window.removeEventListener('pointercancel', onUp)
|
|
395
|
+
})
|
|
396
|
+
// ── Zones, walls and decor ───────────────────────────────────────────────────────────────────────────────
|
|
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
|
+
}
|
|
424
|
+
function areaLook(color?: string) {
|
|
425
|
+
const c = color ?? 'secondary'
|
|
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 }
|
|
427
|
+
}
|
|
428
|
+
// `picked` (a v-model) is declared with the other models
|
|
429
|
+
const isPicked = (kind: 'area' | 'wall' | 'decor', id: string | number) => picked.value?.kind === kind && picked.value.id === id
|
|
430
|
+
const toPlan = (e: { clientX: number; clientY: number }) => {
|
|
431
|
+
const r = root.value!.getBoundingClientRect()
|
|
432
|
+
return { x: (e.clientX - r.left) / scale.value, y: (e.clientY - r.top) / scale.value }
|
|
433
|
+
}
|
|
434
|
+
/** A generic drag in plan units: `move` gets the offset from where it started, `end` runs once if it moved */
|
|
435
|
+
function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: () => void) {
|
|
436
|
+
// Keys (Delete, Enter) reach the plan while something on it is being edited
|
|
437
|
+
root.value?.focus({ preventScroll: true })
|
|
438
|
+
const sx = e.clientX
|
|
439
|
+
const sy = e.clientY
|
|
440
|
+
let moved = false
|
|
441
|
+
const mv = (ev: PointerEvent) => {
|
|
442
|
+
if (ev.pointerId !== e.pointerId) return
|
|
443
|
+
if (!moved && Math.hypot(ev.clientX - sx, ev.clientY - sy) < 4) return
|
|
444
|
+
moved = true
|
|
445
|
+
move((ev.clientX - sx) / scale.value, (ev.clientY - sy) / scale.value)
|
|
446
|
+
}
|
|
447
|
+
const up = (ev: PointerEvent) => {
|
|
448
|
+
if (ev.pointerId !== e.pointerId) return
|
|
449
|
+
window.removeEventListener('pointermove', mv)
|
|
450
|
+
window.removeEventListener('pointerup', up)
|
|
451
|
+
window.removeEventListener('pointercancel', up)
|
|
452
|
+
if (moved) end()
|
|
453
|
+
}
|
|
454
|
+
window.addEventListener('pointermove', mv)
|
|
455
|
+
window.addEventListener('pointerup', up)
|
|
456
|
+
window.addEventListener('pointercancel', up)
|
|
457
|
+
}
|
|
458
|
+
const areaDraft = shallowRef<FloorArea | null>(null)
|
|
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] : []))
|
|
460
|
+
type Corner = 'nw' | 'ne' | 'sw' | 'se'
|
|
461
|
+
function onAreaDown(e: PointerEvent, a: FloorArea, corner: Corner | null) {
|
|
462
|
+
if (!props.editable || tool.value !== 'select' || e.button !== 0) return
|
|
463
|
+
e.stopPropagation()
|
|
464
|
+
picked.value = { kind: 'area', id: a.id }
|
|
465
|
+
selection.value = []
|
|
466
|
+
follow(e, (dx, dy) => {
|
|
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 }
|
|
478
|
+
}, () => {
|
|
479
|
+
const d = areaDraft.value!
|
|
480
|
+
areaDraft.value = null
|
|
481
|
+
record()
|
|
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))
|
|
483
|
+
})
|
|
484
|
+
}
|
|
485
|
+
const decorDraft = shallowRef<FloorDecor | null>(null)
|
|
486
|
+
const shownDecor = computed(() => decor.value.map((d) => (decorDraft.value?.id === d.id ? decorDraft.value : d)))
|
|
487
|
+
function onDecorDown(e: PointerEvent, d: FloorDecor, resize = false) {
|
|
488
|
+
if (!props.editable || tool.value !== 'select' || e.button !== 0) return
|
|
489
|
+
e.stopPropagation()
|
|
490
|
+
picked.value = { kind: 'decor', id: d.id }
|
|
491
|
+
selection.value = []
|
|
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 }), () => {
|
|
495
|
+
const n = decorDraft.value!
|
|
496
|
+
decorDraft.value = null
|
|
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))
|
|
499
|
+
})
|
|
500
|
+
}
|
|
501
|
+
const wallDraft = shallowRef<FloorWall | null>(null)
|
|
502
|
+
const shownWalls = computed(() => walls.value.map((w) => (wallDraft.value?.id === w.id ? wallDraft.value : w)))
|
|
503
|
+
const wallPath = (w: FloorWall) => w.points.map(([x, y], i) => `${i ? 'L' : 'M'}${x * scale.value} ${y * scale.value}`).join('')
|
|
504
|
+
function onWallDown(e: PointerEvent, w: FloorWall, vertex = -1) {
|
|
505
|
+
if (!props.editable || tool.value !== 'select' || e.button !== 0) return
|
|
506
|
+
e.stopPropagation()
|
|
507
|
+
picked.value = { kind: 'wall', id: w.id, ...(vertex >= 0 && { vertex }) }
|
|
508
|
+
selection.value = []
|
|
509
|
+
follow(e, (dx, dy) => {
|
|
510
|
+
wallDraft.value = { ...w, points: w.points.map(([x, y], i) => (vertex < 0 || i === vertex ? [x + dx, y + dy] : [x, y])) }
|
|
511
|
+
}, () => {
|
|
512
|
+
const n = wallDraft.value!
|
|
513
|
+
wallDraft.value = null
|
|
514
|
+
record()
|
|
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))
|
|
516
|
+
})
|
|
517
|
+
}
|
|
518
|
+
// Drawing new walls and zones
|
|
519
|
+
const drawing = ref<[number, number][] | null>(null)
|
|
520
|
+
const hover = ref<[number, number] | null>(null)
|
|
521
|
+
let made = 0
|
|
522
|
+
const newId = (p: string) => `${p}${Date.now().toString(36)}${made++}`
|
|
523
|
+
function onPlanPointer(e: PointerEvent) {
|
|
524
|
+
if (!props.editable) return
|
|
525
|
+
if (tool.value === 'select') {
|
|
526
|
+
if (e.target === e.currentTarget || (e.target as Element).closest('svg') === svgEl.value) {
|
|
527
|
+
selection.value = []
|
|
528
|
+
picked.value = null
|
|
529
|
+
}
|
|
530
|
+
return
|
|
531
|
+
}
|
|
532
|
+
const p = toPlan(e)
|
|
533
|
+
const at: [number, number] = [snap(p.x), snap(p.y)]
|
|
534
|
+
if (tool.value === 'wall') {
|
|
535
|
+
drawing.value = [...(drawing.value ?? [at]), at]
|
|
536
|
+
return
|
|
537
|
+
}
|
|
538
|
+
const id = newId('area')
|
|
539
|
+
areaDraft.value = { id, x: at[0], y: at[1], width: 0, height: 0 }
|
|
540
|
+
follow(e, (dx, dy) => (areaDraft.value = { id, x: Math.min(at[0], at[0] + dx), y: Math.min(at[1], at[1] + dy), width: Math.abs(dx), height: Math.abs(dy) }), () => {
|
|
541
|
+
const d = areaDraft.value!
|
|
542
|
+
areaDraft.value = null
|
|
543
|
+
if (d.width > 10 && d.height > 10) {
|
|
544
|
+
record()
|
|
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 }]
|
|
546
|
+
picked.value = { kind: 'area', id }
|
|
547
|
+
}
|
|
548
|
+
})
|
|
549
|
+
}
|
|
550
|
+
function onPlanMove(e: PointerEvent) {
|
|
551
|
+
if (drawing.value) {
|
|
552
|
+
const p = toPlan(e)
|
|
553
|
+
hover.value = [snap(p.x), snap(p.y)]
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
function finishWall() {
|
|
557
|
+
const pts = drawing.value?.filter((p, i, a) => !i || p[0] !== a[i - 1]![0] || p[1] !== a[i - 1]![1])
|
|
558
|
+
drawing.value = null
|
|
559
|
+
hover.value = null
|
|
560
|
+
if (pts && pts.length > 1) record()
|
|
561
|
+
if (pts && pts.length > 1) walls.value = [...walls.value, { id: newId('wall'), points: pts }]
|
|
562
|
+
}
|
|
563
|
+
function onPlanKey(e: KeyboardEvent) {
|
|
564
|
+
if (drawing.value && (e.key === 'Enter' || e.key === 'Escape')) {
|
|
565
|
+
e.preventDefault()
|
|
566
|
+
if (e.key === 'Enter') finishWall()
|
|
567
|
+
else drawing.value = null
|
|
568
|
+
return
|
|
569
|
+
}
|
|
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
|
|
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()
|
|
601
|
+
if (kind === 'area') areas.value = areas.value.filter((a) => a.id !== id)
|
|
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
|
+
}
|
|
612
|
+
if (kind === 'decor') decor.value = decor.value.filter((d) => d.id !== id)
|
|
613
|
+
picked.value = null
|
|
614
|
+
}
|
|
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
|
+
}
|
|
818
|
+
|
|
819
|
+
const ariaOf = (p: (typeof placed.value)[number]) =>
|
|
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(', ')
|
|
821
|
+
const gridStyle = computed(() => {
|
|
822
|
+
const g = (props.grid >= 10 ? props.grid : props.grid * Math.ceil(10 / Math.max(1, props.grid))) * scale.value
|
|
823
|
+
return props.editable && props.showGrid && props.grid
|
|
824
|
+
? { backgroundImage: 'radial-gradient(circle, var(--color-outline-variant) 1px, transparent 1.2px)', backgroundSize: `${g}px ${g}px` }
|
|
825
|
+
: {}
|
|
826
|
+
})
|
|
827
|
+
</script>
|
|
828
|
+
|
|
829
|
+
<template>
|
|
830
|
+
<div
|
|
831
|
+
ref="root"
|
|
832
|
+
class="m3-floor-plan select-none"
|
|
833
|
+
:style="{ aspectRatio: `${width} / ${height}`, ...gridStyle }"
|
|
834
|
+
role="group"
|
|
835
|
+
tabindex="-1"
|
|
836
|
+
:aria-label="label ?? locale.floorPlan"
|
|
837
|
+
:class="editable && tool !== 'select' && 'cursor-crosshair'"
|
|
838
|
+
@pointerdown="onPlanPointer"
|
|
839
|
+
@pointermove="onPlanMove"
|
|
840
|
+
@dblclick="drawing && finishWall()"
|
|
841
|
+
@keydown="onPlanKey"
|
|
842
|
+
>
|
|
843
|
+
<!-- Zones -->
|
|
844
|
+
<div
|
|
845
|
+
v-for="a in shownAreas"
|
|
846
|
+
:key="`a${a.id}`"
|
|
847
|
+
class="absolute rounded-lg border"
|
|
848
|
+
:class="[editable && tool === 'select' ? 'cursor-move touch-none' : 'pointer-events-none', isPicked('area', a.id) && 'ring-2 ring-primary']"
|
|
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) }"
|
|
850
|
+
@pointerdown="onAreaDown($event, a, null)"
|
|
851
|
+
>
|
|
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>
|
|
865
|
+
</div>
|
|
866
|
+
|
|
867
|
+
<!-- Walls -->
|
|
868
|
+
<svg ref="svgEl" class="pointer-events-none absolute inset-0 size-full overflow-visible">
|
|
869
|
+
<g v-for="w in shownWalls" :key="`w${w.id}`">
|
|
870
|
+
<path
|
|
871
|
+
:d="wallPath(w)"
|
|
872
|
+
fill="none"
|
|
873
|
+
stroke-linecap="round"
|
|
874
|
+
stroke-linejoin="round"
|
|
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']"
|
|
877
|
+
:stroke-width="(w.thickness ?? 8) * scale"
|
|
878
|
+
@pointerdown="onWallDown($event, w)"
|
|
879
|
+
@dblclick="onWallDblclick($event, w)"
|
|
880
|
+
/>
|
|
881
|
+
<template v-if="editable && isPicked('wall', w.id)">
|
|
882
|
+
<circle
|
|
883
|
+
v-for="(pt, i) in w.points"
|
|
884
|
+
:key="i"
|
|
885
|
+
:cx="pt[0] * scale"
|
|
886
|
+
:cy="pt[1] * scale"
|
|
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'"
|
|
890
|
+
stroke-width="2"
|
|
891
|
+
@pointerdown="onWallDown($event, w, i)"
|
|
892
|
+
/>
|
|
893
|
+
</template>
|
|
894
|
+
</g>
|
|
895
|
+
<path
|
|
896
|
+
v-if="drawing"
|
|
897
|
+
:d="wallPath({ id: 'new', points: hover ? [...drawing, hover] : drawing })"
|
|
898
|
+
fill="none"
|
|
899
|
+
class="stroke-primary"
|
|
900
|
+
stroke-dasharray="6 4"
|
|
901
|
+
stroke-linecap="round"
|
|
902
|
+
:stroke-width="8 * scale"
|
|
903
|
+
/>
|
|
904
|
+
</svg>
|
|
905
|
+
|
|
906
|
+
<!-- Decor -->
|
|
907
|
+
<div
|
|
908
|
+
v-for="d in shownDecor"
|
|
909
|
+
:key="`d${d.id}`"
|
|
910
|
+
class="absolute flex -translate-x-1/2 -translate-y-1/2 items-center justify-center text-on-surface-variant"
|
|
911
|
+
:class="[
|
|
912
|
+
editable && tool === 'select' ? 'cursor-move touch-none' : 'pointer-events-none',
|
|
913
|
+
isPicked('decor', d.id) && 'ring-2 ring-primary',
|
|
914
|
+
]"
|
|
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"
|
|
917
|
+
role="img"
|
|
918
|
+
@pointerdown="onDecorDown($event, d)"
|
|
919
|
+
>
|
|
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
|
+
/>
|
|
937
|
+
</div>
|
|
938
|
+
|
|
939
|
+
<!-- Merged tables: one outline around the group -->
|
|
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>
|
|
968
|
+
|
|
969
|
+
<div
|
|
970
|
+
v-for="p in placed"
|
|
971
|
+
:key="p.t.id"
|
|
972
|
+
class="absolute"
|
|
973
|
+
:class="!draft?.has(p.t.id) && 'transition-[left,top] duration-200 ease-out'"
|
|
974
|
+
:style="{ left: `${p.x * scale}px`, top: `${p.y * scale}px`, transform: `rotate(${rotationOf('table', p.t.id, p.t.rotation)}deg)` }"
|
|
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
|
+
/>
|
|
985
|
+
<span
|
|
986
|
+
v-for="(ch, i) in p.chairs"
|
|
987
|
+
:key="i"
|
|
988
|
+
class="m3-floor-chair pointer-events-none absolute rounded-md"
|
|
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)` }"
|
|
990
|
+
/>
|
|
991
|
+
<div
|
|
992
|
+
role="button"
|
|
993
|
+
tabindex="0"
|
|
994
|
+
class="absolute flex -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center gap-0.5 text-center shadow-elevation-1 outline-none transition-[box-shadow] duration-150 focus-visible:ring-2 focus-visible:ring-secondary"
|
|
995
|
+
:class="[
|
|
996
|
+
(p.t.shape ?? 'square') === 'round' ? 'rounded-full' : 'rounded-lg',
|
|
997
|
+
editable ? 'cursor-grab touch-none active:cursor-grabbing' : 'cursor-pointer hover:shadow-elevation-2',
|
|
998
|
+
selection.includes(p.t.id) && 'ring-2 ring-primary',
|
|
999
|
+
draft?.has(p.t.id) && 'shadow-elevation-3',
|
|
1000
|
+
]"
|
|
1001
|
+
:style="{ width: `${p.size.w * scale}px`, height: `${p.size.h * scale}px`, ...look(p.status), fontSize: `${Math.max(9, 14 * scale)}px` }"
|
|
1002
|
+
:aria-label="ariaOf(p)"
|
|
1003
|
+
:aria-pressed="editable ? selection.includes(p.t.id) : undefined"
|
|
1004
|
+
@pointerdown="onDown($event, p.t)"
|
|
1005
|
+
@click="onClick($event, p.t)"
|
|
1006
|
+
@keydown="onKey($event, p.t)"
|
|
1007
|
+
>
|
|
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>
|
|
1015
|
+
<span
|
|
1016
|
+
v-if="p.t.badge !== undefined"
|
|
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"
|
|
1018
|
+
:style="{ transform: `rotate(${-rotationOf('table', p.t.id, p.t.rotation)}deg)` }"
|
|
1019
|
+
>{{ p.t.badge }}</span>
|
|
1020
|
+
</div>
|
|
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" />
|
|
1024
|
+
</div>
|
|
1025
|
+
</template>
|
|
1026
|
+
|
|
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 */
|
|
1030
|
+
@layer base {
|
|
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;
|
|
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);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
</style>
|