@m3ui-vue/m3ui-vue 1.3.4 → 1.3.6
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 +78 -17
- package/dist/{MButton-Bl_BSUep.js → MButton-D5eJiDza.js} +2 -2
- package/dist/{MButton-Bl_BSUep.js.map → MButton-D5eJiDza.js.map} +1 -1
- package/dist/{MDialog-D_Yik8ou.js → MDialog-WqB0jewp.js} +2 -2
- package/dist/{MDialog-D_Yik8ou.js.map → MDialog-WqB0jewp.js.map} +1 -1
- package/dist/{MListItem-BxifHJdU.js → MListItem-Cf-C2Ru-.js} +2 -2
- package/dist/{MListItem-BxifHJdU.js.map → MListItem-Cf-C2Ru-.js.map} +1 -1
- package/dist/{MLoadingIndicator-BxbFhSX6.js → MLoadingIndicator-D4GzEZoH.js} +2 -2
- package/dist/{MLoadingIndicator-BxbFhSX6.js.map → MLoadingIndicator-D4GzEZoH.js.map} +1 -1
- package/dist/{MSeekBar-BeN9QcB3.js → MSeekBar-B19xoWE3.js} +2 -2
- package/dist/{MSeekBar-BeN9QcB3.js.map → MSeekBar-B19xoWE3.js.map} +1 -1
- package/dist/{MSlider-BVSbJlGS.js → MSlider-9RoiuebS.js} +2 -2
- package/dist/{MSlider-BVSbJlGS.js.map → MSlider-9RoiuebS.js.map} +1 -1
- package/dist/{MSpinner-C2SUnWk4.js → MSpinner-BNF8MN-L.js} +2 -2
- package/dist/{MSpinner-C2SUnWk4.js.map → MSpinner-BNF8MN-L.js.map} +1 -1
- package/dist/{MTextField-CEkWSZ2v.js → MTextField-CuG0T3qh.js} +2 -2
- package/dist/{MTextField-CEkWSZ2v.js.map → MTextField-CuG0T3qh.js.map} +1 -1
- package/dist/{MTooltip-CodJGEO-.js → MTooltip-Bv7yxngk.js} +4 -4
- package/dist/{MTooltip-CodJGEO-.js.map → MTooltip-Bv7yxngk.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MFloorPlan.vue.d.ts +213 -16
- package/dist/components/MFloorPlanInspector.vue.d.ts +12 -12
- package/dist/components/MMap.vue.d.ts +2 -2
- package/dist/components/MPdfViewer.vue.d.ts +2 -2
- package/dist/composables/useFloorPlan.d.ts +10 -3
- package/dist/composables/useLocale.d.ts +9 -0
- package/dist/draw.js +2 -2
- package/dist/flow.js +1 -1
- package/dist/gantt.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/locales/index.js +56 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +2796 -1792
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +5 -5
- package/dist/media.js +4 -4
- package/dist/pdf.js +4 -4
- package/dist/rich-text-editor.js +4 -4
- package/dist/styles.css +1 -1
- package/dist/{useLocale-CaWwi-b6.js → useLocale-D2ucaY-l.js} +9 -1
- package/dist/useLocale-D2ucaY-l.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MFloorPlan.test.ts +369 -0
- package/src/components/MFloorPlan.vue +1166 -88
- package/src/components/MFloorPlanInspector.vue +21 -6
- package/src/components/MFloorPlanToolbar.vue +4 -3
- package/src/composables/useFloorPlan.ts +7 -3
- package/src/composables/useLocale.ts +17 -0
- package/src/index.ts +1 -1
- package/src/locales/de.ts +8 -0
- package/src/locales/es.ts +8 -0
- package/src/locales/fr.ts +8 -0
- package/src/locales/ja.ts +8 -0
- package/src/locales/ko.ts +8 -0
- package/src/locales/pt.ts +8 -0
- package/src/locales/zh.ts +8 -0
- package/dist/useLocale-CaWwi-b6.js.map +0 -1
|
@@ -42,6 +42,44 @@ describe('MFloorPlan', () => {
|
|
|
42
42
|
expect(w.emitted('move')![0]![0]).toEqual([{ id: 1, x: 140, y: 140 }, { id: 2, x: 340, y: 140 }])
|
|
43
43
|
expect((w.props('tables') as FloorTable[])[0]).toMatchObject({ x: 140, y: 140 })
|
|
44
44
|
})
|
|
45
|
+
it('editable + selectable multiple: a click toggles a table in the selection, a drag moves that table alone', async () => {
|
|
46
|
+
const w = setup({ editable: true, selectable: 'multiple', dragMerged: true, merges: [{ id: 'm', tables: [1, 2] }], grid: 20, selection: [], 'onUpdate:selection': (v: unknown) => w.setProps({ selection: v as number[] }) })
|
|
47
|
+
const press = (label: string, dx = 0) => {
|
|
48
|
+
table(w, label).element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 0, clientY: 0, pointerId: 1 }))
|
|
49
|
+
if (dx) window.dispatchEvent(new PointerEvent('pointermove', { clientX: dx, clientY: 0, pointerId: 1 }))
|
|
50
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: dx, clientY: 0, pointerId: 1 }))
|
|
51
|
+
}
|
|
52
|
+
// A press alone doesn't change the selection; the click toggles
|
|
53
|
+
press('T1')
|
|
54
|
+
expect(w.props('selection')).toEqual([])
|
|
55
|
+
await table(w, 'T1').trigger('click')
|
|
56
|
+
await table(w, 'T2').trigger('click')
|
|
57
|
+
expect(w.props('selection')).toEqual([1, 2])
|
|
58
|
+
await table(w, 'T1').trigger('click')
|
|
59
|
+
expect(w.props('selection')).toEqual([2])
|
|
60
|
+
// A drag moves only the table pressed: not the rest of the selection, nor its merge (dragMerged); the selection stays
|
|
61
|
+
await table(w, 'T1').trigger('click')
|
|
62
|
+
expect(w.props('selection')).toEqual([2, 1])
|
|
63
|
+
await new Promise((r) => setTimeout(r))
|
|
64
|
+
press('T2', 40)
|
|
65
|
+
await nextTick()
|
|
66
|
+
expect((w.props('tables') as FloorTable[]).map((t) => t.x)).toEqual([100, 340])
|
|
67
|
+
await new Promise((r) => setTimeout(r))
|
|
68
|
+
press('T1', 60)
|
|
69
|
+
await nextTick()
|
|
70
|
+
expect((w.props('tables') as FloorTable[]).map((t) => t.x)).toEqual([160, 340])
|
|
71
|
+
expect(w.props('selection')).toEqual([2, 1])
|
|
72
|
+
})
|
|
73
|
+
it('tableSnap cell: a dropped table sits in the middle of a grid square, and arrows keep it there', async () => {
|
|
74
|
+
const w = setup({ editable: true, grid: 20, tableSnap: 'cell', selection: [1], 'onUpdate:selection': (v: unknown) => w.setProps({ selection: v as number[] }) })
|
|
75
|
+
table(w, 'T1').element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 0, clientY: 0, pointerId: 1 }))
|
|
76
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 33, clientY: 47, pointerId: 1 }))
|
|
77
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 33, clientY: 47, pointerId: 1 }))
|
|
78
|
+
await nextTick()
|
|
79
|
+
expect((w.props('tables') as FloorTable[])[0]).toMatchObject({ x: 130, y: 150 })
|
|
80
|
+
await table(w, 'T1').trigger('keydown', { key: 'ArrowRight' })
|
|
81
|
+
expect((w.props('tables') as FloorTable[])[0]).toMatchObject({ x: 150, y: 150 })
|
|
82
|
+
})
|
|
45
83
|
it('editable: arrows nudge by the grid, and tables stay inside the plan', async () => {
|
|
46
84
|
const w = setup({ editable: true, grid: 10 })
|
|
47
85
|
await table(w, 'T1').trigger('keydown', { key: 'ArrowLeft' })
|
|
@@ -149,6 +187,63 @@ describe('MFloorPlan editing comforts', () => {
|
|
|
149
187
|
await nextTick()
|
|
150
188
|
expect(w.props('areas')[0]).toMatchObject({ x: 60, y: 80, width: 240, height: 120 })
|
|
151
189
|
})
|
|
190
|
+
it('resizes turned decor along its own axes, keeping the opposite corner', async () => {
|
|
191
|
+
// A window turned to stand upright: its length runs down the plan, so dragging the handle down lengthens it
|
|
192
|
+
const w = plan({ decor: [{ id: 'win', kind: 'window', x: 200, y: 200, width: 80, height: 10, rotation: 90 }], picked: { kind: 'decor', id: 'win' } })
|
|
193
|
+
down(w.find('[data-resize]').element, 0, 0)
|
|
194
|
+
moveUp(0, 40)
|
|
195
|
+
await nextTick()
|
|
196
|
+
const d = (w.props('decor') as any[])[0]
|
|
197
|
+
expect(d).toMatchObject({ width: 120, height: 10 })
|
|
198
|
+
// Its far end (the top, at y 160) stays put: the middle moved half the growth
|
|
199
|
+
expect(d.x).toBeCloseTo(200)
|
|
200
|
+
expect(d.y).toBeCloseTo(220)
|
|
201
|
+
})
|
|
202
|
+
it('resizes unturned decor from its corner, the opposite one staying put', async () => {
|
|
203
|
+
const w = plan({ decor: [{ id: 'd', kind: 'door', x: 100, y: 100, width: 60, height: 14 }], picked: { kind: 'decor', id: 'd' } })
|
|
204
|
+
down(w.find('[data-resize]').element, 0, 0)
|
|
205
|
+
moveUp(20, 0)
|
|
206
|
+
await nextTick()
|
|
207
|
+
expect((w.props('decor') as any[])[0]).toMatchObject({ x: 110, y: 100, width: 80, height: 14 })
|
|
208
|
+
})
|
|
209
|
+
it('subgrid: walls, zones and decor snap halfway between the points, tables to the grid', async () => {
|
|
210
|
+
const w = plan({ subgrid: 2, decor: [{ id: 'p', kind: 'plant', x: 100, y: 100 }] })
|
|
211
|
+
down(w.find('[aria-label="Plant"]').element, 0, 0)
|
|
212
|
+
moveUp(6, 0)
|
|
213
|
+
await nextTick()
|
|
214
|
+
expect((w.props('decor') as any[])[0]).toMatchObject({ x: 105, y: 100 })
|
|
215
|
+
down(table(w, 'T1').element, 0, 0)
|
|
216
|
+
moveUp(6, 0)
|
|
217
|
+
await nextTick()
|
|
218
|
+
expect(w.props('tables')[0]).toMatchObject({ x: 110 })
|
|
219
|
+
})
|
|
220
|
+
it('arrows move the picked zone, decor or a wall\'s picked corner', async () => {
|
|
221
|
+
const w = plan({
|
|
222
|
+
subgrid: 2,
|
|
223
|
+
areas: [{ id: 'z', x: 100, y: 100, width: 100, height: 100 }],
|
|
224
|
+
walls: [{ id: 'w', points: [[0, 0], [100, 0]] }],
|
|
225
|
+
picked: { kind: 'area', id: 'z' },
|
|
226
|
+
})
|
|
227
|
+
key(w, 'ArrowRight')
|
|
228
|
+
await nextTick()
|
|
229
|
+
key(w, 'ArrowDown', { shiftKey: true })
|
|
230
|
+
await nextTick()
|
|
231
|
+
expect(w.props('areas')[0]).toMatchObject({ x: 105, y: 125 })
|
|
232
|
+
await w.setProps({ picked: { kind: 'wall', id: 'w', vertex: 1 } })
|
|
233
|
+
key(w, 'ArrowLeft')
|
|
234
|
+
await nextTick()
|
|
235
|
+
expect(w.props('walls')[0].points).toEqual([[0, 0], [95, 0]])
|
|
236
|
+
})
|
|
237
|
+
it('a door and a window look different, and a door can be flipped', async () => {
|
|
238
|
+
const w = plan({ decor: [{ id: 'd', kind: 'door', x: 100, y: 100 }, { id: 'v', kind: 'window', x: 300, y: 100, flip: true }] })
|
|
239
|
+
const door = w.find('[aria-label="Door"]')
|
|
240
|
+
const win = w.find('[aria-label="Window"]')
|
|
241
|
+
expect(door.find('.m3-floor-door-swing').exists()).toBe(true)
|
|
242
|
+
expect(win.find('.m3-floor-window-pane').exists()).toBe(true)
|
|
243
|
+
expect(win.find('.m3-floor-door-swing').exists()).toBe(false)
|
|
244
|
+
await w.setProps({ decor: [{ id: 'd', kind: 'door', x: 100, y: 100, flip: true }] })
|
|
245
|
+
expect((w.find('[aria-label="Door"] svg').element as SVGElement).style.transform).toBe('scaleX(-1)')
|
|
246
|
+
})
|
|
152
247
|
it('a double-click adds a corner to a wall; Delete removes a picked corner', async () => {
|
|
153
248
|
const w = plan({ walls: [{ id: 'w', points: [[0, 0], [200, 0]] }] })
|
|
154
249
|
const path = w.find('svg path').element
|
|
@@ -318,6 +413,10 @@ describe('MFloorPlan rotatable', () => {
|
|
|
318
413
|
const off = mount(MFloorPlan, { props: { editable: true, tables: base(), selection: [1], rotatable: false } })
|
|
319
414
|
expect(on.findAll('[data-rotate]')).toHaveLength(1)
|
|
320
415
|
expect(off.findAll('[data-rotate]')).toHaveLength(0)
|
|
416
|
+
// decor only: the picked decor turns, a selected table doesn't
|
|
417
|
+
const decorOnly = mount(MFloorPlan, { props: { editable: true, tables: base(), selection: [1], rotatable: ['decor'], decor: [{ id: 'p', kind: 'plant', x: 50, y: 50 }], picked: { kind: 'decor', id: 'p' } } })
|
|
418
|
+
expect(decorOnly.findAll('[data-rotate]')).toHaveLength(1)
|
|
419
|
+
expect(decorOnly.find('[aria-label="Plant"] [data-rotate]').exists()).toBe(true)
|
|
321
420
|
})
|
|
322
421
|
})
|
|
323
422
|
|
|
@@ -327,3 +426,273 @@ describe('MFloorPlanToolbar without table presets', () => {
|
|
|
327
426
|
expect(w.find('[aria-label="Add a table"]').exists()).toBe(false)
|
|
328
427
|
})
|
|
329
428
|
})
|
|
429
|
+
|
|
430
|
+
describe('MFloorPlan 1.3.6', () => {
|
|
431
|
+
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: 7, ...o }))
|
|
432
|
+
const move = (x: number, y: number) => window.dispatchEvent(new PointerEvent('pointermove', { clientX: x, clientY: y, pointerId: 7 }))
|
|
433
|
+
const up = (x: number, y: number) => window.dispatchEvent(new PointerEvent('pointerup', { clientX: x, clientY: y, pointerId: 7 }))
|
|
434
|
+
const moveUp = (x: number, y: number) => {
|
|
435
|
+
move(x, y)
|
|
436
|
+
up(x, y)
|
|
437
|
+
}
|
|
438
|
+
const key = (w: { element: Element }, k: string, o: Record<string, unknown> = {}) => w.element.dispatchEvent(new KeyboardEvent('keydown', { key: k, bubbles: true, ...o }))
|
|
439
|
+
function plan(props: Record<string, unknown> = {}) {
|
|
440
|
+
const w: any = mount(MFloorPlan, {
|
|
441
|
+
props: {
|
|
442
|
+
editable: true,
|
|
443
|
+
grid: 10,
|
|
444
|
+
tables: base(),
|
|
445
|
+
...props,
|
|
446
|
+
...Object.fromEntries(['tables', 'areas', 'walls', 'decor', 'merges', 'selection', 'picked', 'zoom', 'tool'].map((k) => [`onUpdate:${k}`, (v: unknown) => w.setProps({ [k]: v })])),
|
|
447
|
+
},
|
|
448
|
+
attachTo: document.body,
|
|
449
|
+
})
|
|
450
|
+
return w
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
it('cellSize: tables by column and row, a drag steps a cell and gives cells back', async () => {
|
|
454
|
+
const w = plan({ cellSize: 50, width: 500, height: 300, tables: [{ id: 1, label: 'A', x: 2, y: 1, shape: 'square', width: 40, height: 40 }] })
|
|
455
|
+
// Drawn in the middle of cell (2, 1): 125, 75
|
|
456
|
+
expect(table(w, 'A').element.parentElement!.style.left).toBe('125px')
|
|
457
|
+
down(table(w, 'A').element, 0, 0)
|
|
458
|
+
moveUp(48, 0)
|
|
459
|
+
await nextTick()
|
|
460
|
+
expect(w.props('tables')[0]).toMatchObject({ x: 3, y: 1 })
|
|
461
|
+
expect(w.emitted('move')!.at(-1)![0]).toEqual([{ id: 1, x: 3, y: 1 }])
|
|
462
|
+
table(w, 'A').element.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }))
|
|
463
|
+
await nextTick()
|
|
464
|
+
expect(w.props('tables')[0]).toMatchObject({ x: 3, y: 2 })
|
|
465
|
+
// Kept inside the plan's cells
|
|
466
|
+
w.vm.addTable({ label: 'B', x: 9, y: 5 })
|
|
467
|
+
await nextTick()
|
|
468
|
+
expect(w.props('tables')[1]).toMatchObject({ x: 9, y: 5 })
|
|
469
|
+
})
|
|
470
|
+
it('tableOrigin corner: x / y are the top-left corner', async () => {
|
|
471
|
+
const w = plan({ tableOrigin: 'corner', tables: [{ id: 1, label: 'A', x: 100, y: 100, width: 60, height: 40, shape: 'rect' }] })
|
|
472
|
+
expect(table(w, 'A').element.parentElement!.style.left).toBe('130px')
|
|
473
|
+
down(table(w, 'A').element, 0, 0)
|
|
474
|
+
moveUp(20, 10)
|
|
475
|
+
await nextTick()
|
|
476
|
+
expect(w.props('tables')[0]).toMatchObject({ x: 120, y: 110 })
|
|
477
|
+
})
|
|
478
|
+
it('zoomable: Ctrl + wheel zooms about the pointer, and a drag then moves a table half as far', async () => {
|
|
479
|
+
const w = plan({ zoomable: true })
|
|
480
|
+
// happy-dom's WheelEvent drops ctrlKey from its init
|
|
481
|
+
const wheel = new WheelEvent('wheel', { bubbles: true, cancelable: true, deltaY: -347, clientX: 0, clientY: 0 })
|
|
482
|
+
Object.defineProperty(wheel, 'ctrlKey', { value: true })
|
|
483
|
+
w.element.dispatchEvent(wheel)
|
|
484
|
+
await nextTick()
|
|
485
|
+
expect(w.props('zoom')).toBeCloseTo(2, 1)
|
|
486
|
+
await w.setProps({ zoom: 2 })
|
|
487
|
+
down(table(w, 'T1').element, 0, 0)
|
|
488
|
+
moveUp(40, 0)
|
|
489
|
+
await nextTick()
|
|
490
|
+
expect(w.props('tables')[0].x).toBe(120)
|
|
491
|
+
// The buttons: back to the whole plan
|
|
492
|
+
await w.find('[aria-label="Whole plan"]').trigger('click')
|
|
493
|
+
expect(w.props('zoom')).toBe(1)
|
|
494
|
+
})
|
|
495
|
+
it('a background image sits under the plan, in plan units', () => {
|
|
496
|
+
const w = plan({ backgroundImage: 'plan.png', backgroundBox: { x: 10, y: 20, width: 300, height: 200 }, backgroundOpacity: 0.3 })
|
|
497
|
+
const img = w.find('img[data-floor-bg]').element as HTMLImageElement
|
|
498
|
+
expect(img.style.left).toBe('10px')
|
|
499
|
+
expect(img.style.width).toBe('300px')
|
|
500
|
+
expect(img.style.opacity).toBe('0.3')
|
|
501
|
+
})
|
|
502
|
+
it('a mouse drag on empty floor selects the tables it touches', async () => {
|
|
503
|
+
const w = plan()
|
|
504
|
+
down(w.find('.m3-floor-view').element, 50, 50)
|
|
505
|
+
move(250, 200)
|
|
506
|
+
await nextTick()
|
|
507
|
+
expect(w.find('.m3-floor-marquee').exists()).toBe(true)
|
|
508
|
+
up(250, 200)
|
|
509
|
+
await nextTick()
|
|
510
|
+
expect(w.props('selection')).toEqual([1])
|
|
511
|
+
expect(w.find('.m3-floor-marquee').exists()).toBe(false)
|
|
512
|
+
})
|
|
513
|
+
it('transferable: in service a table carried onto another emits transfer; canTransfer can refuse', async () => {
|
|
514
|
+
const w = plan({ editable: false, transferable: true })
|
|
515
|
+
down(table(w, 'T1').element, 100, 100)
|
|
516
|
+
move(200, 100)
|
|
517
|
+
await nextTick()
|
|
518
|
+
expect(w.find('.m3-floor-carry').exists()).toBe(true)
|
|
519
|
+
moveUp(300, 100)
|
|
520
|
+
await nextTick()
|
|
521
|
+
const [from, to] = w.emitted('transfer')![0] as FloorTable[]
|
|
522
|
+
expect([from!.id, to!.id]).toEqual([1, 2])
|
|
523
|
+
// The tables stay where they are
|
|
524
|
+
expect(w.props('tables')[0].x).toBe(100)
|
|
525
|
+
await w.setProps({ canTransfer: () => 'Busy' })
|
|
526
|
+
down(table(w, 'T1').element, 100, 100)
|
|
527
|
+
move(200, 100)
|
|
528
|
+
moveUp(300, 100)
|
|
529
|
+
await nextTick()
|
|
530
|
+
expect(w.emitted('transfer-refused')![0]![2]).toBe('Busy')
|
|
531
|
+
})
|
|
532
|
+
it('resizes the selected table by its handle, about its middle', async () => {
|
|
533
|
+
const w = plan({ selection: [1] })
|
|
534
|
+
down(w.find('[data-table-resize]').element, 0, 0)
|
|
535
|
+
moveUp(10, 5)
|
|
536
|
+
await nextTick()
|
|
537
|
+
expect(w.props('tables')[0]).toMatchObject({ x: 100, y: 100, width: 92, height: 82 })
|
|
538
|
+
})
|
|
539
|
+
it('draws a zone of any shape corner by corner, and closes it on its first corner', async () => {
|
|
540
|
+
const w = plan({ tool: 'polygon', tables: [] })
|
|
541
|
+
for (const [x, y] of [[0, 0], [200, 0], [200, 100], [100, 100], [100, 200], [0, 200], [0, 0]]) down(w.element, x!, y!)
|
|
542
|
+
await nextTick()
|
|
543
|
+
const a = (w.props('areas') as any[])[0]
|
|
544
|
+
expect(a.points).toHaveLength(6)
|
|
545
|
+
expect(a).toMatchObject({ x: 0, y: 0, width: 200, height: 200 })
|
|
546
|
+
})
|
|
547
|
+
it('a double-click on a zone gives it a corner; corners drag, snap to walls, and Delete removes them', async () => {
|
|
548
|
+
const w = plan({ tables: [], areas: [{ id: 'z', x: 100, y: 100, width: 200, height: 100 }], walls: [{ id: 'w', points: [[403, 97], [500, 97]] }], picked: { kind: 'area', id: 'z' } })
|
|
549
|
+
const zone = w.find('.m3-floor-view > div.absolute.rounded-lg')
|
|
550
|
+
zone.element.dispatchEvent(new MouseEvent('dblclick', { bubbles: true, clientX: 200, clientY: 100 }))
|
|
551
|
+
await nextTick()
|
|
552
|
+
let a = (w.props('areas') as any[])[0]
|
|
553
|
+
expect(a.points).toEqual([[100, 100], [200, 100], [300, 100], [300, 200], [100, 200]])
|
|
554
|
+
expect(w.props('picked')).toEqual({ kind: 'area', id: 'z', vertex: 1 })
|
|
555
|
+
// Dragged near the wall's off-grid corner, it lands on it
|
|
556
|
+
down(w.find('[data-zone-corner="2"]').element, 300, 100)
|
|
557
|
+
moveUp(401, 99)
|
|
558
|
+
await nextTick()
|
|
559
|
+
a = (w.props('areas') as any[])[0]
|
|
560
|
+
expect(a.points[2]).toEqual([403, 97])
|
|
561
|
+
expect(a.width).toBe(303)
|
|
562
|
+
key(w, 'Delete')
|
|
563
|
+
await nextTick()
|
|
564
|
+
expect((w.props('areas') as any[])[0].points).toHaveLength(4)
|
|
565
|
+
})
|
|
566
|
+
it('a wall being drawn joins another wall\'s corner nearby', async () => {
|
|
567
|
+
const w = plan({ tool: 'wall', tables: [], walls: [{ id: 'w', points: [[33, 47], [33, 200]] }] })
|
|
568
|
+
down(w.element, 35, 45)
|
|
569
|
+
down(w.element, 200, 50)
|
|
570
|
+
key(w, 'Enter')
|
|
571
|
+
await nextTick()
|
|
572
|
+
expect((w.props('walls') as any[])[1].points).toEqual([[33, 47], [200, 50]])
|
|
573
|
+
})
|
|
574
|
+
it('overlap: warn outlines tables on top of each other; prevent undoes the move', async () => {
|
|
575
|
+
const w = plan({ tables: [{ id: 1, label: 'A', x: 100, y: 100 }, { id: 2, label: 'B', x: 130, y: 100 }, { id: 3, label: 'C', x: 400, y: 100 }] })
|
|
576
|
+
expect(table(w, 'A').classes()).toContain('m3-floor-overlap')
|
|
577
|
+
expect(table(w, 'C').classes()).not.toContain('m3-floor-overlap')
|
|
578
|
+
await w.setProps({ overlap: 'prevent' })
|
|
579
|
+
down(table(w, 'C').element, 0, 0)
|
|
580
|
+
moveUp(-260, 0)
|
|
581
|
+
await nextTick()
|
|
582
|
+
expect(w.props('tables')[2].x).toBe(400)
|
|
583
|
+
})
|
|
584
|
+
it('seatNumbers: chairs numbered, taken ones colored, a click in service emits seat-click', async () => {
|
|
585
|
+
const w = plan({ editable: false, seatNumbers: true, tables: [{ id: 1, label: 'A', x: 100, y: 100, seats: 4, activeSeats: [2] }] })
|
|
586
|
+
const chairs = w.findAll('[data-seat]')
|
|
587
|
+
expect(chairs.map((c) => c.text())).toEqual(['1', '2', '3', '4'])
|
|
588
|
+
expect(chairs[1]!.classes()).toContain('m3-floor-chair-taken')
|
|
589
|
+
await chairs[2]!.trigger('click')
|
|
590
|
+
expect(w.emitted('seat-click')![0]!.slice(0, 2)).toEqual([expect.objectContaining({ id: 1 }), 3])
|
|
591
|
+
})
|
|
592
|
+
it('measure: the picked wall\'s sides in your unit', () => {
|
|
593
|
+
const w = plan({ measure: { unit: 'm', per: 100 }, walls: [{ id: 'w', points: [[0, 0], [300, 0], [300, 150]] }], picked: { kind: 'wall', id: 'w' } })
|
|
594
|
+
expect(w.findAll('.m3-floor-measure').map((m: any) => m.text())).toEqual(['3.00 m', '1.50 m'])
|
|
595
|
+
})
|
|
596
|
+
it('toSVG draws zones, walls, decor and tables', () => {
|
|
597
|
+
const w = plan({ areas: [{ id: 'z', x: 0, y: 0, width: 100, height: 100, label: 'Hall' }], walls: [{ id: 'w', points: [[0, 0], [100, 0]] }], decor: [{ id: 'd', kind: 'door', x: 50, y: 0 }] })
|
|
598
|
+
const svg = w.vm.toSVG() as string
|
|
599
|
+
expect(svg.startsWith('<svg')).toBe(true)
|
|
600
|
+
expect(svg).toContain('>Hall</text>')
|
|
601
|
+
expect(svg).toContain('<polyline')
|
|
602
|
+
expect(svg).toContain('>T1</text>')
|
|
603
|
+
expect(svg).toContain('A60 60')
|
|
604
|
+
})
|
|
605
|
+
it('duplicating near the edge keeps the copy inside the plan', async () => {
|
|
606
|
+
const w = plan({ width: 400, height: 300, tables: [], decor: [{ id: 'p', kind: 'plant', x: 390, y: 290 }], areas: [{ id: 'z', x: 300, y: 200, width: 100, height: 100 }], picked: { kind: 'decor', id: 'p' } })
|
|
607
|
+
w.vm.duplicate()
|
|
608
|
+
await nextTick()
|
|
609
|
+
const copy = (w.props('decor') as any[])[1]
|
|
610
|
+
expect(copy.x).toBeLessThanOrEqual(380)
|
|
611
|
+
expect(copy.y).toBeLessThanOrEqual(280)
|
|
612
|
+
await w.setProps({ picked: { kind: 'area', id: 'z' } })
|
|
613
|
+
w.vm.duplicate()
|
|
614
|
+
await nextTick()
|
|
615
|
+
const z = (w.props('areas') as any[])[1]
|
|
616
|
+
expect(z.x + z.width).toBeLessThanOrEqual(400)
|
|
617
|
+
expect(z.y + z.height).toBeLessThanOrEqual(300)
|
|
618
|
+
})
|
|
619
|
+
})
|
|
620
|
+
|
|
621
|
+
describe('MFloorPlan zoom and tables', () => {
|
|
622
|
+
it('tables don\'t slide when the plan zooms, only when they move', async () => {
|
|
623
|
+
vi.useFakeTimers()
|
|
624
|
+
const w: any = mount(MFloorPlan, { props: { tables: base(), zoomable: true, zoom: 1, 'onUpdate:zoom': (v: number) => w.setProps({ zoom: v }) }, attachTo: document.body })
|
|
625
|
+
const wrap = () => table(w, 'T1').element.parentElement!
|
|
626
|
+
expect(wrap().className).toContain('transition-[left,top]')
|
|
627
|
+
await w.setProps({ zoom: 2 })
|
|
628
|
+
expect(wrap().style.left).toBe('200px')
|
|
629
|
+
expect(wrap().className).not.toContain('transition-[left,top]')
|
|
630
|
+
vi.advanceTimersByTime(200)
|
|
631
|
+
await nextTick()
|
|
632
|
+
expect(wrap().className).toContain('transition-[left,top]')
|
|
633
|
+
vi.useRealTimers()
|
|
634
|
+
})
|
|
635
|
+
})
|
|
636
|
+
|
|
637
|
+
describe('MFloorPlan cellSize and bigger tables', () => {
|
|
638
|
+
it('a table resized by cell keeps its cell and covers the next ones; dragged, it lands on whole cells', async () => {
|
|
639
|
+
const w: any = mount(MFloorPlan, {
|
|
640
|
+
props: { editable: true, grid: 50, cellSize: 50, width: 500, height: 300, selection: [1], tables: [{ id: 1, label: 'A', x: 2, y: 1, shape: 'square', width: 40, height: 40 }], 'onUpdate:tables': (v: FloorTable[]) => w.setProps({ tables: v }) },
|
|
641
|
+
attachTo: document.body,
|
|
642
|
+
})
|
|
643
|
+
const wrap = () => table(w, 'A').element.parentElement!
|
|
644
|
+
// A one-cell table sits in the middle of its cell
|
|
645
|
+
expect(wrap().style.left).toBe('125px')
|
|
646
|
+
w.find('[data-table-resize]').element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 0, clientY: 0, pointerId: 8 }))
|
|
647
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 60, clientY: 0, pointerId: 8 }))
|
|
648
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 60, clientY: 0, pointerId: 8 }))
|
|
649
|
+
await nextTick()
|
|
650
|
+
// Two cells wide: still in cell (2, 1), covering cells 2 and 3
|
|
651
|
+
expect(w.props('tables')[0]).toMatchObject({ x: 2, y: 1, width: 100, height: 40 })
|
|
652
|
+
expect(wrap().style.left).toBe('150px')
|
|
653
|
+
table(w, 'A').element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 0, clientY: 0, pointerId: 8 }))
|
|
654
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 70, clientY: 0, pointerId: 8 }))
|
|
655
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 70, clientY: 0, pointerId: 8 }))
|
|
656
|
+
await nextTick()
|
|
657
|
+
expect(w.props('tables')[0]).toMatchObject({ x: 3, y: 1 })
|
|
658
|
+
expect(wrap().style.left).toBe('200px')
|
|
659
|
+
})
|
|
660
|
+
})
|
|
661
|
+
|
|
662
|
+
describe('MFloorPlan resizeSnap', () => {
|
|
663
|
+
const drag = (el: Element, dx: number, dy: number) => {
|
|
664
|
+
el.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 0, clientY: 0, pointerId: 12 }))
|
|
665
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: dx, clientY: dy, pointerId: 12 }))
|
|
666
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: dx, clientY: dy, pointerId: 12 }))
|
|
667
|
+
}
|
|
668
|
+
function plan(props: Record<string, unknown>) {
|
|
669
|
+
const w: any = mount(MFloorPlan, {
|
|
670
|
+
props: { editable: true, ...props, ...Object.fromEntries(['tables', 'decor'].map((k) => [`onUpdate:${k}`, (v: unknown) => w.setProps({ [k]: v })])) },
|
|
671
|
+
attachTo: document.body,
|
|
672
|
+
})
|
|
673
|
+
return w
|
|
674
|
+
}
|
|
675
|
+
it('grid: a table by cell grows by whole cells, keeping its margin', async () => {
|
|
676
|
+
const w = plan({ grid: 50, cellSize: 50, resizeSnap: 'grid', selection: [1], tables: [{ id: 1, label: 'A', x: 1, y: 1, width: 40, height: 40 }] })
|
|
677
|
+
drag(w.find('[data-table-resize]').element, 62, 10)
|
|
678
|
+
await nextTick()
|
|
679
|
+
expect(w.props('tables')[0]).toMatchObject({ width: 90, height: 40 })
|
|
680
|
+
})
|
|
681
|
+
it('subgrid: a table about its middle grows a step on each side; free follows the pointer', async () => {
|
|
682
|
+
const w = plan({ grid: 20, subgrid: 2, resizeSnap: 'subgrid', selection: [1], tables: [{ id: 1, label: 'A', x: 100, y: 100, width: 60, height: 60 }] })
|
|
683
|
+
drag(w.find('[data-table-resize]').element, 13, 3)
|
|
684
|
+
await nextTick()
|
|
685
|
+
// Pulled 13 (26 in all, both sides): 20, one step of 10 per side
|
|
686
|
+
expect(w.props('tables')[0]).toMatchObject({ width: 80, height: 60 })
|
|
687
|
+
await w.setProps({ resizeSnap: 'free' })
|
|
688
|
+
drag(w.find('[data-table-resize]').element, 7, 0)
|
|
689
|
+
await nextTick()
|
|
690
|
+
expect(w.props('tables')[0]).toMatchObject({ width: 94 })
|
|
691
|
+
})
|
|
692
|
+
it('decor steps too, from its fixed corner', async () => {
|
|
693
|
+
const w = plan({ grid: 20, resizeSnap: 'grid', decor: [{ id: 'd', kind: 'door', x: 100, y: 100, width: 60, height: 14 }], picked: { kind: 'decor', id: 'd' } })
|
|
694
|
+
drag(w.find('[data-resize]').element, 27, 2)
|
|
695
|
+
await nextTick()
|
|
696
|
+
expect((w.props('decor') as any[])[0]).toMatchObject({ width: 80, height: 14 })
|
|
697
|
+
})
|
|
698
|
+
})
|