@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,118 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MDrawCanvas from '../components/MDrawCanvas.vue'
|
|
5
|
+
import MDrawToolbar from '../components/MDrawToolbar.vue'
|
|
6
|
+
import type { DrawItem, DrawStroke } from '../composables/drawGeometry'
|
|
7
|
+
|
|
8
|
+
function setup(props: Record<string, unknown> = {}) {
|
|
9
|
+
const w = mount(MDrawCanvas, {
|
|
10
|
+
props: { modelValue: [] as DrawItem[], 'onUpdate:modelValue': (v: DrawItem[]) => w.setProps({ modelValue: v }), ...props },
|
|
11
|
+
attachTo: document.body,
|
|
12
|
+
})
|
|
13
|
+
const el = w.element as HTMLElement
|
|
14
|
+
const svg = el.querySelector('svg')!
|
|
15
|
+
const ev = (type: string, x: number, y: number, o: Record<string, unknown> = {}) =>
|
|
16
|
+
(type === 'pointerdown' ? svg : el).dispatchEvent(new PointerEvent(type, { bubbles: true, clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', button: 0, buttons: 1, ...o }))
|
|
17
|
+
const drag = async (pts: [number, number][], o: Record<string, unknown> = {}) => {
|
|
18
|
+
ev('pointerdown', ...pts[0]!, o)
|
|
19
|
+
for (const p of pts.slice(1)) ev('pointermove', ...p, o)
|
|
20
|
+
ev('pointerup', ...pts[pts.length - 1]!, o)
|
|
21
|
+
await nextTick()
|
|
22
|
+
}
|
|
23
|
+
const items = () => w.props('modelValue') as DrawItem[]
|
|
24
|
+
return { w, el, ev, drag, items }
|
|
25
|
+
}
|
|
26
|
+
const across = (y = 50): [number, number][] => Array.from({ length: 11 }, (_, i) => [i * 10, y])
|
|
27
|
+
|
|
28
|
+
describe('MDrawCanvas', () => {
|
|
29
|
+
it('draws a stroke with the pen, and undo / redo take it back and forth', async () => {
|
|
30
|
+
const { w, drag, items } = setup()
|
|
31
|
+
await drag(across())
|
|
32
|
+
expect(items()).toHaveLength(1)
|
|
33
|
+
expect(items()[0]!.type).toBe('stroke')
|
|
34
|
+
expect((items()[0] as DrawStroke).points.length).toBeGreaterThan(2)
|
|
35
|
+
;(w.vm as any).undo()
|
|
36
|
+
await nextTick()
|
|
37
|
+
expect(items()).toHaveLength(0)
|
|
38
|
+
;(w.vm as any).redo()
|
|
39
|
+
await nextTick()
|
|
40
|
+
expect(items()).toHaveLength(1)
|
|
41
|
+
})
|
|
42
|
+
it('the eraser cuts a stroke in two, in one undo step', async () => {
|
|
43
|
+
const { w, drag, items } = setup()
|
|
44
|
+
await drag(across())
|
|
45
|
+
await w.setProps({ tool: 'eraser' })
|
|
46
|
+
await drag([[50, 30], [50, 70]])
|
|
47
|
+
expect(items()).toHaveLength(2)
|
|
48
|
+
;(w.vm as any).undo()
|
|
49
|
+
await nextTick()
|
|
50
|
+
expect(items()).toHaveLength(1)
|
|
51
|
+
})
|
|
52
|
+
it('the pen\'s eraser end erases whatever tool is picked', async () => {
|
|
53
|
+
const { drag, items } = setup()
|
|
54
|
+
await drag(across())
|
|
55
|
+
await drag([[50, 30], [50, 70]], { pointerType: 'pen', button: 5, buttons: 32, pressure: 0.5 })
|
|
56
|
+
expect(items()).toHaveLength(2)
|
|
57
|
+
})
|
|
58
|
+
it('draws shapes, and selects, moves and deletes them', async () => {
|
|
59
|
+
const { w, drag, items, el } = setup({ tool: 'rect' })
|
|
60
|
+
await drag([[10, 10], [60, 40]])
|
|
61
|
+
expect(items()[0]).toMatchObject({ type: 'shape', shape: 'rect', from: [10, 10], to: [60, 40] })
|
|
62
|
+
await w.setProps({ tool: 'select' })
|
|
63
|
+
await drag([[0, 0], [100, 0], [100, 100], [0, 100]])
|
|
64
|
+
expect(w.emitted('update:selection')!.at(-1)![0]).toEqual([items()[0]!.id])
|
|
65
|
+
await w.setProps({ selection: [items()[0]!.id] })
|
|
66
|
+
await drag([[10, 25], [30, 45]])
|
|
67
|
+
expect(items()[0]).toMatchObject({ from: [30, 30], to: [80, 60] })
|
|
68
|
+
el.dispatchEvent(new KeyboardEvent('keydown', { key: 'Delete', bubbles: true }))
|
|
69
|
+
await nextTick()
|
|
70
|
+
expect(items()).toHaveLength(0)
|
|
71
|
+
})
|
|
72
|
+
it('with penOnly, a finger pans instead of drawing', async () => {
|
|
73
|
+
const { w, drag, items } = setup({ penOnly: true })
|
|
74
|
+
await drag(across(), { pointerType: 'touch' })
|
|
75
|
+
expect(items()).toHaveLength(0)
|
|
76
|
+
expect((w.emitted('update:viewport')!.at(-1)![0] as { x: number }).x).toBe(100)
|
|
77
|
+
})
|
|
78
|
+
it('in pages mode, items belong to the page under them, in its coordinates', async () => {
|
|
79
|
+
const { drag, items } = setup({ mode: 'pages', pages: 2, pageSize: { width: 200, height: 100 } })
|
|
80
|
+
await drag([[10, 150], [50, 150]])
|
|
81
|
+
expect(items()[0]!.page).toBe(1)
|
|
82
|
+
expect((items()[0] as DrawStroke).points[0]![1]).toBeCloseTo(26)
|
|
83
|
+
})
|
|
84
|
+
it('hidden and locked layers are left alone', async () => {
|
|
85
|
+
const stroke = (id: string, layer: string): DrawItem => ({ id, type: 'stroke', pen: 'marker', color: '#000', size: 4, layer, points: across().map(([x, y]) => [x, y, 1]) })
|
|
86
|
+
const { w, drag, items } = setup({
|
|
87
|
+
modelValue: [stroke('a', 'l1'), stroke('b', 'l2')],
|
|
88
|
+
layers: [{ id: 'l1', name: '1', locked: true }, { id: 'l2', name: '2' }],
|
|
89
|
+
tool: 'stroke-eraser',
|
|
90
|
+
})
|
|
91
|
+
await drag([[50, 30], [50, 70]])
|
|
92
|
+
expect(items().map((i) => i.id)).toEqual(['a'])
|
|
93
|
+
expect(w.findAll('path').length).toBeGreaterThan(0)
|
|
94
|
+
})
|
|
95
|
+
it('the toolbar picks tools and colors', async () => {
|
|
96
|
+
const w = mount({
|
|
97
|
+
components: { MDrawCanvas, MDrawToolbar },
|
|
98
|
+
data: () => ({ tool: 'pen', color: '#1d1b20' }),
|
|
99
|
+
template: '<MDrawCanvas v-model:tool="tool" v-model:color="color"><MDrawToolbar /></MDrawCanvas>',
|
|
100
|
+
})
|
|
101
|
+
await w.find('[aria-label="Text"]').trigger('click')
|
|
102
|
+
expect((w.vm as any).tool).toBe('text')
|
|
103
|
+
await w.find('[aria-label="Color #e53935"]').trigger('click')
|
|
104
|
+
expect((w.vm as any).color).toBe('#e53935')
|
|
105
|
+
// A color that isn't a swatch lights up the custom-color button
|
|
106
|
+
;(w.vm as any).color = '#123456'
|
|
107
|
+
await nextTick()
|
|
108
|
+
expect(w.find('[aria-label="Custom color"]').attributes('aria-pressed')).toBe('true')
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
describe('MDrawCanvas background image', () => {
|
|
113
|
+
it('places it by backgroundImageBox on an infinite canvas', () => {
|
|
114
|
+
const w = mount(MDrawCanvas, { props: { backgroundImage: 'photo.jpg', backgroundImageBox: { x: 10, y: 20, width: 300, height: 200 } } })
|
|
115
|
+
const img = w.find('image')
|
|
116
|
+
expect([img.attributes('x'), img.attributes('y'), img.attributes('width'), img.attributes('height')]).toEqual(['10', '20', '300', '200'])
|
|
117
|
+
})
|
|
118
|
+
})
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MFloorPlan, { type FloorTable } from '../components/MFloorPlan.vue'
|
|
5
|
+
|
|
6
|
+
const base = (): FloorTable[] => [
|
|
7
|
+
{ id: 1, label: 'T1', x: 100, y: 100, seats: 4, status: 'occupied', badge: 12 },
|
|
8
|
+
{ id: 2, label: 'T2', x: 300, y: 100, shape: 'round', seats: 6 },
|
|
9
|
+
]
|
|
10
|
+
function setup(props: Record<string, unknown> = {}) {
|
|
11
|
+
const w = mount(MFloorPlan, {
|
|
12
|
+
props: { tables: base(), 'onUpdate:tables': (v: FloorTable[]) => w.setProps({ tables: v }), ...props },
|
|
13
|
+
attachTo: document.body,
|
|
14
|
+
})
|
|
15
|
+
return w
|
|
16
|
+
}
|
|
17
|
+
const table = (w: ReturnType<typeof setup>, label: string) => w.findAll('[role="button"]').find((b) => b.attributes('aria-label')!.startsWith(label))!
|
|
18
|
+
|
|
19
|
+
describe('MFloorPlan', () => {
|
|
20
|
+
it('draws tables with their status, seats and badge', () => {
|
|
21
|
+
const w = setup()
|
|
22
|
+
expect(table(w, 'T1').attributes('aria-label')).toBe('T1, Occupied, 4 seats, 12')
|
|
23
|
+
expect(table(w, 'T1').attributes('style')).toContain('--color-primary-container')
|
|
24
|
+
// chairs: 4 + 6
|
|
25
|
+
expect(w.findAll('.m3-floor-chair').length).toBe(10)
|
|
26
|
+
})
|
|
27
|
+
it('a click opens a table in service mode, without moving it', async () => {
|
|
28
|
+
const w = setup()
|
|
29
|
+
await table(w, 'T2').trigger('click')
|
|
30
|
+
expect(w.emitted('table-click')![0]![0]).toMatchObject({ id: 2 })
|
|
31
|
+
table(w, 'T2').element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 0, clientY: 0, pointerId: 1 }))
|
|
32
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 50, clientY: 0, pointerId: 1 }))
|
|
33
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 50, clientY: 0, pointerId: 1 }))
|
|
34
|
+
expect(w.emitted('move')).toBeUndefined()
|
|
35
|
+
})
|
|
36
|
+
it('editable: a drag moves the selected tables, snapped to the grid, and emits move', async () => {
|
|
37
|
+
const w = setup({ editable: true, grid: 20, selection: [1, 2], 'onUpdate:selection': (v: unknown) => w.setProps({ selection: v as number[] }) })
|
|
38
|
+
table(w, 'T1').element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 0, clientY: 0, pointerId: 1 }))
|
|
39
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 33, clientY: 47, pointerId: 1 }))
|
|
40
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 33, clientY: 47, pointerId: 1 }))
|
|
41
|
+
await nextTick()
|
|
42
|
+
expect(w.emitted('move')![0]![0]).toEqual([{ id: 1, x: 140, y: 140 }, { id: 2, x: 340, y: 140 }])
|
|
43
|
+
expect((w.props('tables') as FloorTable[])[0]).toMatchObject({ x: 140, y: 140 })
|
|
44
|
+
})
|
|
45
|
+
it('editable: arrows nudge by the grid, and tables stay inside the plan', async () => {
|
|
46
|
+
const w = setup({ editable: true, grid: 10 })
|
|
47
|
+
await table(w, 'T1').trigger('keydown', { key: 'ArrowLeft' })
|
|
48
|
+
expect((w.props('tables') as FloorTable[])[0]).toMatchObject({ x: 90 })
|
|
49
|
+
for (let i = 0; i < 20; i++) await table(w, 'T1').trigger('keydown', { key: 'ArrowUp', shiftKey: true })
|
|
50
|
+
expect((w.props('tables') as FloorTable[])[0]!.y).toBe(36)
|
|
51
|
+
})
|
|
52
|
+
it('draws merged tables as one group', () => {
|
|
53
|
+
const w = setup({ merges: [{ id: 'm', tables: [1, 2], label: 'T1 + T2' }] })
|
|
54
|
+
expect(w.text()).toContain('T1 + T2')
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
describe('MFloorPlan zones, walls and decor', () => {
|
|
59
|
+
const down = (el: Element, x: number, y: number) => el.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: x, clientY: y, pointerId: 3 }))
|
|
60
|
+
const moveUp = (x: number, y: number) => {
|
|
61
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: x, clientY: y, pointerId: 3 }))
|
|
62
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: x, clientY: y, pointerId: 3 }))
|
|
63
|
+
}
|
|
64
|
+
function plan(props: Record<string, unknown>) {
|
|
65
|
+
const w = mount(MFloorPlan, { props: { editable: true, grid: 10, ...props }, attachTo: document.body })
|
|
66
|
+
for (const k of ['areas', 'walls', 'decor']) (w.vm as any)[`onUpdate:${k}`] = null
|
|
67
|
+
return w
|
|
68
|
+
}
|
|
69
|
+
it('draws a wall corner by corner, Enter ends it', async () => {
|
|
70
|
+
const w = plan({ tool: 'wall' })
|
|
71
|
+
const root = w.element as HTMLElement
|
|
72
|
+
down(root, 10, 10)
|
|
73
|
+
down(root, 200, 12)
|
|
74
|
+
down(root, 200, 300)
|
|
75
|
+
root.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))
|
|
76
|
+
await nextTick()
|
|
77
|
+
expect((w.emitted('update:walls')!.at(-1)![0] as any[])[0].points).toEqual([[10, 10], [200, 10], [200, 300]])
|
|
78
|
+
})
|
|
79
|
+
it('drags out a zone, snapped', async () => {
|
|
80
|
+
const w = plan({ tool: 'area' })
|
|
81
|
+
down(w.element, 20, 20)
|
|
82
|
+
moveUp(203, 118)
|
|
83
|
+
await nextTick()
|
|
84
|
+
expect((w.emitted('update:areas')!.at(-1)![0] as any[])[0]).toMatchObject({ x: 20, y: 20, width: 180, height: 100 })
|
|
85
|
+
})
|
|
86
|
+
it('moves decor and deletes what is picked', async () => {
|
|
87
|
+
const w = plan({ decor: [{ id: 'p', kind: 'plant', x: 100, y: 100 }], 'onUpdate:decor': (v: unknown) => w.setProps({ decor: v as any }) })
|
|
88
|
+
const plant = w.find('[aria-label="Plant"]').element
|
|
89
|
+
down(plant, 0, 0)
|
|
90
|
+
moveUp(41, 19)
|
|
91
|
+
await nextTick()
|
|
92
|
+
expect((w.props('decor') as any[])[0]).toMatchObject({ x: 140, y: 120 })
|
|
93
|
+
w.element.dispatchEvent(new KeyboardEvent('keydown', { key: 'Delete', bubbles: true }))
|
|
94
|
+
await nextTick()
|
|
95
|
+
expect(w.props('decor')).toEqual([])
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe('MFloorPlan editing comforts', () => {
|
|
100
|
+
const down = (el: Element, x: number, y: number, o: Record<string, unknown> = {}) => el.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: x, clientY: y, pointerId: 5, ...o }))
|
|
101
|
+
const moveUp = (x: number, y: number) => {
|
|
102
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: x, clientY: y, pointerId: 5 }))
|
|
103
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: x, clientY: y, pointerId: 5 }))
|
|
104
|
+
}
|
|
105
|
+
const key = (w: { element: Element }, k: string, o: Record<string, unknown> = {}) => w.element.dispatchEvent(new KeyboardEvent('keydown', { key: k, bubbles: true, ...o }))
|
|
106
|
+
function plan(props: Record<string, unknown> = {}) {
|
|
107
|
+
const w: any = mount(MFloorPlan, {
|
|
108
|
+
props: {
|
|
109
|
+
editable: true,
|
|
110
|
+
grid: 10,
|
|
111
|
+
tables: base(),
|
|
112
|
+
merges: [{ id: 'm', tables: [1, 2] }],
|
|
113
|
+
...props,
|
|
114
|
+
...Object.fromEntries(['tables', 'areas', 'walls', 'decor', 'merges', 'selection', 'picked'].map((k) => [`onUpdate:${k}`, (v: unknown) => w.setProps({ [k]: v })])),
|
|
115
|
+
},
|
|
116
|
+
attachTo: document.body,
|
|
117
|
+
})
|
|
118
|
+
return w
|
|
119
|
+
}
|
|
120
|
+
it('undoes and redoes a drag', async () => {
|
|
121
|
+
const w = plan()
|
|
122
|
+
down(table(w, 'T1').element, 0, 0)
|
|
123
|
+
moveUp(40, 0)
|
|
124
|
+
await nextTick()
|
|
125
|
+
expect(w.props('tables')[0].x).toBe(140)
|
|
126
|
+
key(w, 'z', { ctrlKey: true })
|
|
127
|
+
await nextTick()
|
|
128
|
+
expect(w.props('tables')[0].x).toBe(100)
|
|
129
|
+
key(w, 'z', { ctrlKey: true, shiftKey: true })
|
|
130
|
+
await nextTick()
|
|
131
|
+
expect(w.props('tables')[0].x).toBe(140)
|
|
132
|
+
})
|
|
133
|
+
it('Delete removes the selected tables and their merge; Ctrl+D duplicates', async () => {
|
|
134
|
+
const w = plan({ selection: [2] })
|
|
135
|
+
key(w, 'd', { ctrlKey: true })
|
|
136
|
+
await nextTick()
|
|
137
|
+
expect(w.props('tables')).toHaveLength(3)
|
|
138
|
+
expect(w.props('tables')[2]).toMatchObject({ label: 'T2', x: 320, y: 120 })
|
|
139
|
+
await w.setProps({ selection: [2] })
|
|
140
|
+
key(w, 'Delete')
|
|
141
|
+
await nextTick()
|
|
142
|
+
expect(w.props('tables').map((t: FloorTable) => t.id)).not.toContain(2)
|
|
143
|
+
expect(w.props('merges')).toEqual([])
|
|
144
|
+
})
|
|
145
|
+
it('resizes a zone by its top-left corner, keeping the opposite one', async () => {
|
|
146
|
+
const w = plan({ areas: [{ id: 'z', x: 100, y: 100, width: 200, height: 100 }], picked: { kind: 'area', id: 'z' } })
|
|
147
|
+
down(w.find('[data-corner="nw"]').element, 0, 0)
|
|
148
|
+
moveUp(-40, -20)
|
|
149
|
+
await nextTick()
|
|
150
|
+
expect(w.props('areas')[0]).toMatchObject({ x: 60, y: 80, width: 240, height: 120 })
|
|
151
|
+
})
|
|
152
|
+
it('a double-click adds a corner to a wall; Delete removes a picked corner', async () => {
|
|
153
|
+
const w = plan({ walls: [{ id: 'w', points: [[0, 0], [200, 0]] }] })
|
|
154
|
+
const path = w.find('svg path').element
|
|
155
|
+
path.dispatchEvent(new MouseEvent('dblclick', { bubbles: true, clientX: 100, clientY: 0 }))
|
|
156
|
+
await nextTick()
|
|
157
|
+
expect(w.props('walls')[0].points).toEqual([[0, 0], [100, 0], [200, 0]])
|
|
158
|
+
expect(w.props('picked')).toEqual({ kind: 'wall', id: 'w', vertex: 1 })
|
|
159
|
+
key(w, 'Delete')
|
|
160
|
+
await nextTick()
|
|
161
|
+
expect(w.props('walls')[0].points).toEqual([[0, 0], [200, 0]])
|
|
162
|
+
})
|
|
163
|
+
it('rotates the picked table by its handle in 15° steps', async () => {
|
|
164
|
+
const w = plan({ selection: [1] })
|
|
165
|
+
const h = w.find('[data-rotate]').element
|
|
166
|
+
// The table's center is (100, 100) at scale 1; pointing right of it is 90°
|
|
167
|
+
h.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 100, clientY: 40, pointerId: 6 }))
|
|
168
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 160, clientY: 98, pointerId: 6 }))
|
|
169
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 160, clientY: 98, pointerId: 6 }))
|
|
170
|
+
await nextTick()
|
|
171
|
+
expect(w.props('tables')[0].rotation).toBe(90)
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
import MFloorPlanToolbar from '../components/MFloorPlanToolbar.vue'
|
|
176
|
+
import MFloorPlanInspector from '../components/MFloorPlanInspector.vue'
|
|
177
|
+
import { defineComponent, h, ref as vref } from 'vue'
|
|
178
|
+
|
|
179
|
+
describe('MFloorPlan family', () => {
|
|
180
|
+
it('draws decor kinds of yours, and the #decor slot replaces their inside', () => {
|
|
181
|
+
const w = mount(MFloorPlan, {
|
|
182
|
+
props: { decor: [{ id: 'tv', kind: 'tv', x: 100, y: 100 }], decorKinds: { tv: { label: 'TV', icon: 'tv', width: 80, height: 20, shape: 'bar', color: '#000' } } },
|
|
183
|
+
slots: { decor: '<template #decor="{ item, kind }"><b class="mine">{{ kind.label }}:{{ item.id }}</b></template>' },
|
|
184
|
+
})
|
|
185
|
+
const el = w.find('[aria-label="TV"]')
|
|
186
|
+
expect(el.attributes('style')).toContain('width: 80px')
|
|
187
|
+
expect(w.find('.mine').text()).toBe('TV:tv')
|
|
188
|
+
})
|
|
189
|
+
it('in service, selectable multiple + merge() joins tables; canMerge can refuse', async () => {
|
|
190
|
+
const w: any = mount(MFloorPlan, {
|
|
191
|
+
props: {
|
|
192
|
+
tables: base(),
|
|
193
|
+
selectable: 'multiple',
|
|
194
|
+
canMerge: (ids: (string | number)[]) => (ids.includes(3) ? 'Table 3 has an open bill' : true),
|
|
195
|
+
'onUpdate:selection': (v: unknown) => w.setProps({ selection: v }),
|
|
196
|
+
'onUpdate:merges': (v: unknown) => w.setProps({ merges: v }),
|
|
197
|
+
},
|
|
198
|
+
})
|
|
199
|
+
await table(w, 'T1').trigger('click')
|
|
200
|
+
await table(w, 'T2').trigger('click')
|
|
201
|
+
expect(w.props('selection')).toEqual([1, 2])
|
|
202
|
+
const m = w.vm.merge()
|
|
203
|
+
expect(m).toMatchObject({ tables: [1, 2], label: 'T1 + T2' })
|
|
204
|
+
expect(w.emitted('merge')).toHaveLength(1)
|
|
205
|
+
expect(w.vm.merge([1, 3])).toBeNull()
|
|
206
|
+
expect(w.emitted('merge-refused')![0]).toEqual([[1, 2, 3], 'Table 3 has an open bill'])
|
|
207
|
+
w.vm.split(1)
|
|
208
|
+
expect(w.emitted('split')).toHaveLength(1)
|
|
209
|
+
})
|
|
210
|
+
it('the toolbar adds tables and undoes, and the inspector edits from outside the plan', async () => {
|
|
211
|
+
const App = defineComponent({
|
|
212
|
+
setup() {
|
|
213
|
+
const plan = vref()
|
|
214
|
+
const tables = vref<FloorTable[]>(base())
|
|
215
|
+
return () => [
|
|
216
|
+
h(MFloorPlan, { ref: plan, editable: true, tables: tables.value, 'onUpdate:tables': (v: FloorTable[]) => (tables.value = v) }),
|
|
217
|
+
h(MFloorPlanToolbar, { plan: plan.value }),
|
|
218
|
+
h(MFloorPlanInspector, { plan: plan.value }),
|
|
219
|
+
]
|
|
220
|
+
},
|
|
221
|
+
})
|
|
222
|
+
const w = mount(App, { attachTo: document.body })
|
|
223
|
+
await nextTick()
|
|
224
|
+
await w.find('[aria-label="Add a table"]').trigger('click')
|
|
225
|
+
await nextTick()
|
|
226
|
+
const item = [...document.querySelectorAll('button')].find((b) => b.textContent?.includes('Round · 2'))!
|
|
227
|
+
item.click()
|
|
228
|
+
await nextTick()
|
|
229
|
+
expect(w.findAll('.m3-floor-plan [role="button"]')).toHaveLength(3)
|
|
230
|
+
// The new table is selected: the inspector shows it, and renaming it goes into the tables
|
|
231
|
+
const field = w.find('.m3-floor-plan-inspector input')
|
|
232
|
+
await field.setValue('Window seat')
|
|
233
|
+
expect(w.find('.m3-floor-plan').text()).toContain('Window seat')
|
|
234
|
+
await w.find('[aria-label="Undo"]').trigger('click')
|
|
235
|
+
await w.find('[aria-label="Undo"]').trigger('click')
|
|
236
|
+
expect(w.findAll('.m3-floor-plan [role="button"]')).toHaveLength(2)
|
|
237
|
+
w.unmount()
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
describe('MFloorPlan by touch', () => {
|
|
242
|
+
const touch = (type: string, el: EventTarget, x: number, y: number) =>
|
|
243
|
+
el.dispatchEvent(new PointerEvent(type, { bubbles: true, button: 0, clientX: x, clientY: y, pointerId: 9, pointerType: 'touch' }))
|
|
244
|
+
function plan(props: Record<string, unknown> = {}) {
|
|
245
|
+
const w: any = mount(MFloorPlan, {
|
|
246
|
+
props: { editable: true, grid: 10, tables: base(), ...props, ...Object.fromEntries(['tables', 'selection', 'walls'].map((k) => [`onUpdate:${k}`, (v: unknown) => w.setProps({ [k]: v })])) },
|
|
247
|
+
attachTo: document.body,
|
|
248
|
+
})
|
|
249
|
+
return w
|
|
250
|
+
}
|
|
251
|
+
it('holding a table down adds it to the selection; a tap still picks only it', async () => {
|
|
252
|
+
vi.useFakeTimers()
|
|
253
|
+
const w = plan({ selection: [1] })
|
|
254
|
+
touch('pointerdown', table(w, 'T2').element, 0, 0)
|
|
255
|
+
vi.advanceTimersByTime(500)
|
|
256
|
+
touch('pointerup', window, 0, 0)
|
|
257
|
+
await nextTick()
|
|
258
|
+
expect(w.props('selection')).toEqual([1, 2])
|
|
259
|
+
await table(w, 'T2').trigger('click')
|
|
260
|
+
expect(w.props('selection')).toEqual([1, 2])
|
|
261
|
+
vi.useRealTimers()
|
|
262
|
+
})
|
|
263
|
+
it('dragging an unpicked table with a finger picks it and moves it', async () => {
|
|
264
|
+
const w = plan({ selection: [1] })
|
|
265
|
+
touch('pointerdown', table(w, 'T2').element, 0, 0)
|
|
266
|
+
touch('pointermove', window, 40, 0)
|
|
267
|
+
touch('pointerup', window, 40, 0)
|
|
268
|
+
await nextTick()
|
|
269
|
+
expect(w.props('selection')).toEqual([2])
|
|
270
|
+
expect(w.props('tables')[1].x).toBe(340)
|
|
271
|
+
})
|
|
272
|
+
it('a wall being drawn can be finished from the context (the toolbar\'s Done)', async () => {
|
|
273
|
+
const w = plan({ tool: 'wall' })
|
|
274
|
+
const down = (x: number, y: number) => w.element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: x, clientY: y, pointerId: 3 }))
|
|
275
|
+
down(0, 0)
|
|
276
|
+
down(100, 0)
|
|
277
|
+
await nextTick()
|
|
278
|
+
expect(w.vm.context.drawingWall.value).toBe(true)
|
|
279
|
+
w.vm.context.finishWall()
|
|
280
|
+
await nextTick()
|
|
281
|
+
expect(w.props('walls')[0].points).toEqual([[0, 0], [100, 0]])
|
|
282
|
+
})
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
describe('MFloorPlan merges across the room', () => {
|
|
286
|
+
it('draws touching tables in one outline and tables apart in their own, joined by a line', () => {
|
|
287
|
+
const tables: FloorTable[] = [
|
|
288
|
+
{ id: 1, label: '1', x: 100, y: 100, seats: 4 },
|
|
289
|
+
{ id: 2, label: '2', x: 172, y: 100, seats: 4 },
|
|
290
|
+
{ id: 3, label: '3', x: 700, y: 400, seats: 4 },
|
|
291
|
+
{ id: 4, label: '4', x: 400, y: 250, seats: 4 },
|
|
292
|
+
]
|
|
293
|
+
const w = mount(MFloorPlan, { props: { tables, merges: [{ id: 'm', tables: [1, 2, 3], label: '1 + 2 + 3' }] } })
|
|
294
|
+
// 1 and 2 touch: one outline; 3 is apart: its own; 4 (between them) isn't covered
|
|
295
|
+
expect(w.findAll('.m3-floor-merge')).toHaveLength(2)
|
|
296
|
+
expect(w.findAll('.m3-floor-merge-link')).toHaveLength(1)
|
|
297
|
+
expect(w.findAll('.m3-floor-merge-label')).toHaveLength(1)
|
|
298
|
+
})
|
|
299
|
+
})
|