@m3ui-vue/m3ui-vue 1.3.5 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/API.md +76 -16
  2. package/dist/{MButton-Bl_BSUep.js → MButton-D5eJiDza.js} +2 -2
  3. package/dist/{MButton-Bl_BSUep.js.map → MButton-D5eJiDza.js.map} +1 -1
  4. package/dist/{MDialog-D_Yik8ou.js → MDialog-WqB0jewp.js} +2 -2
  5. package/dist/{MDialog-D_Yik8ou.js.map → MDialog-WqB0jewp.js.map} +1 -1
  6. package/dist/{MListItem-BxifHJdU.js → MListItem-Cf-C2Ru-.js} +2 -2
  7. package/dist/{MListItem-BxifHJdU.js.map → MListItem-Cf-C2Ru-.js.map} +1 -1
  8. package/dist/{MLoadingIndicator-BxbFhSX6.js → MLoadingIndicator-D4GzEZoH.js} +2 -2
  9. package/dist/{MLoadingIndicator-BxbFhSX6.js.map → MLoadingIndicator-D4GzEZoH.js.map} +1 -1
  10. package/dist/{MSeekBar-BeN9QcB3.js → MSeekBar-B19xoWE3.js} +2 -2
  11. package/dist/{MSeekBar-BeN9QcB3.js.map → MSeekBar-B19xoWE3.js.map} +1 -1
  12. package/dist/{MSlider-BVSbJlGS.js → MSlider-9RoiuebS.js} +2 -2
  13. package/dist/{MSlider-BVSbJlGS.js.map → MSlider-9RoiuebS.js.map} +1 -1
  14. package/dist/{MSpinner-C2SUnWk4.js → MSpinner-BNF8MN-L.js} +2 -2
  15. package/dist/{MSpinner-C2SUnWk4.js.map → MSpinner-BNF8MN-L.js.map} +1 -1
  16. package/dist/{MTextField-CEkWSZ2v.js → MTextField-CuG0T3qh.js} +2 -2
  17. package/dist/{MTextField-CEkWSZ2v.js.map → MTextField-CuG0T3qh.js.map} +1 -1
  18. package/dist/{MTooltip-CodJGEO-.js → MTooltip-Bv7yxngk.js} +4 -4
  19. package/dist/{MTooltip-CodJGEO-.js.map → MTooltip-Bv7yxngk.js.map} +1 -1
  20. package/dist/api.json +1 -1
  21. package/dist/code-editor.js +1 -1
  22. package/dist/components/MFloorPlan.vue.d.ts +192 -14
  23. package/dist/components/MFloorPlanInspector.vue.d.ts +12 -12
  24. package/dist/components/MMap.vue.d.ts +2 -2
  25. package/dist/components/MPdfViewer.vue.d.ts +2 -2
  26. package/dist/composables/useFloorPlan.d.ts +10 -3
  27. package/dist/composables/useLocale.d.ts +9 -0
  28. package/dist/draw.js +2 -2
  29. package/dist/flow.js +1 -1
  30. package/dist/gantt.js +1 -1
  31. package/dist/index.d.ts +1 -1
  32. package/dist/locales/index.js +56 -0
  33. package/dist/locales/index.js.map +1 -1
  34. package/dist/m3ui-vue.css +1 -1
  35. package/dist/m3ui.js +3076 -1955
  36. package/dist/m3ui.js.map +1 -1
  37. package/dist/map.js +5 -5
  38. package/dist/media.js +4 -4
  39. package/dist/pdf.js +4 -4
  40. package/dist/rich-text-editor.js +4 -4
  41. package/dist/styles.css +1 -1
  42. package/dist/{useLocale-CaWwi-b6.js → useLocale-D2ucaY-l.js} +9 -1
  43. package/dist/useLocale-D2ucaY-l.js.map +1 -0
  44. package/package.json +1 -1
  45. package/src/__tests__/MFloorPlan.test.ts +423 -0
  46. package/src/components/MFloorPlan.vue +1337 -101
  47. package/src/components/MFloorPlanInspector.vue +21 -6
  48. package/src/components/MFloorPlanToolbar.vue +4 -3
  49. package/src/composables/useFloorPlan.ts +7 -3
  50. package/src/composables/useLocale.ts +17 -0
  51. package/src/index.ts +1 -1
  52. package/src/locales/de.ts +8 -0
  53. package/src/locales/es.ts +8 -0
  54. package/src/locales/fr.ts +8 -0
  55. package/src/locales/ja.ts +8 -0
  56. package/src/locales/ko.ts +8 -0
  57. package/src/locales/pt.ts +8 -0
  58. package/src/locales/zh.ts +8 -0
  59. package/dist/useLocale-CaWwi-b6.js.map +0 -1
@@ -187,6 +187,63 @@ describe('MFloorPlan editing comforts', () => {
187
187
  await nextTick()
188
188
  expect(w.props('areas')[0]).toMatchObject({ x: 60, y: 80, width: 240, height: 120 })
189
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
+ })
190
247
  it('a double-click adds a corner to a wall; Delete removes a picked corner', async () => {
191
248
  const w = plan({ walls: [{ id: 'w', points: [[0, 0], [200, 0]] }] })
192
249
  const path = w.find('svg path').element
@@ -356,6 +413,10 @@ describe('MFloorPlan rotatable', () => {
356
413
  const off = mount(MFloorPlan, { props: { editable: true, tables: base(), selection: [1], rotatable: false } })
357
414
  expect(on.findAll('[data-rotate]')).toHaveLength(1)
358
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)
359
420
  })
360
421
  })
361
422
 
@@ -365,3 +426,365 @@ describe('MFloorPlanToolbar without table presets', () => {
365
426
  expect(w.find('[aria-label="Add a table"]').exists()).toBe(false)
366
427
  })
367
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 finger draws a wall where it lifts, a second tap on the last corner ends it, and undo takes a corner back', async () => {
567
+ const w = plan({ tool: 'wall', tables: [] })
568
+ const t = { pointerType: 'touch' }
569
+ const fup = (x: number, y: number) => window.dispatchEvent(new PointerEvent('pointerup', { clientX: x, clientY: y, pointerId: 7, pointerType: 'touch' }))
570
+ const fmove = (x: number, y: number) => window.dispatchEvent(new PointerEvent('pointermove', { clientX: x, clientY: y, pointerId: 7, pointerType: 'touch' }))
571
+ // Lands at the first corner, drags to the second: shown while dragging, placed on release
572
+ down(w.element, 20, 20, t)
573
+ fmove(120, 22)
574
+ await nextTick()
575
+ expect(w.find('path.stroke-primary[stroke-dasharray]').exists()).toBe(true)
576
+ fup(120, 22)
577
+ // A tap places a corner; undo takes it back
578
+ down(w.element, 120, 200, t)
579
+ fup(120, 200)
580
+ w.vm.undo()
581
+ // Tapping the last corner again ends the wall
582
+ down(w.element, 121, 19, t)
583
+ fup(121, 19)
584
+ await nextTick()
585
+ expect(w.props('walls')[0].points).toEqual([[20, 20], [120, 20]])
586
+ expect(w.vm.context.drawingWall.value).toBe(false)
587
+ })
588
+ it('a pinch drops the corner a finger was placing; zoomed in, one finger still draws', async () => {
589
+ const w = plan({ tool: 'wall', tables: [], zoomable: true })
590
+ down(w.element, 20, 20, { pointerType: 'touch' })
591
+ down(w.element, 200, 200, { pointerType: 'touch', pointerId: 8 })
592
+ window.dispatchEvent(new PointerEvent('pointerup', { clientX: 20, clientY: 20, pointerId: 7, pointerType: 'touch' }))
593
+ window.dispatchEvent(new PointerEvent('pointerup', { clientX: 200, clientY: 200, pointerId: 8, pointerType: 'touch' }))
594
+ expect(w.vm.context.drawingWall.value).toBe(false)
595
+ await w.setProps({ zoom: 2 })
596
+ down(w.element, 20, 20, { pointerType: 'touch' })
597
+ window.dispatchEvent(new PointerEvent('pointerup', { clientX: 20, clientY: 20, pointerId: 7, pointerType: 'touch' }))
598
+ expect(w.vm.context.drawingWall.value).toBe(true)
599
+ })
600
+ it('a finger dragging a wall\'s corner keeps the page from scrolling (SVG shapes ignore touch-action)', async () => {
601
+ const w = plan({ tables: [], walls: [{ id: 'w', points: [[100, 100], [200, 100]] }], picked: { kind: 'wall', id: 'w' } })
602
+ const tm = () => {
603
+ const ev = new Event('touchmove', { bubbles: true, cancelable: true }) as TouchEvent
604
+ Object.defineProperty(ev, 'touches', { value: [{}] })
605
+ w.element.dispatchEvent(ev)
606
+ return ev.defaultPrevented
607
+ }
608
+ expect(tm()).toBe(false)
609
+ down(w.findAll('circle').at(-1)!.element, 200, 100, { pointerType: 'touch' })
610
+ expect(tm()).toBe(true)
611
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: 260, clientY: 100, pointerId: 7, pointerType: 'touch' }))
612
+ window.dispatchEvent(new PointerEvent('pointerup', { clientX: 260, clientY: 100, pointerId: 7, pointerType: 'touch' }))
613
+ await nextTick()
614
+ expect(w.props('walls')[0].points[1]).toEqual([260, 100])
615
+ expect(tm()).toBe(false)
616
+ })
617
+ it('corners land on the plan\'s edges and corners, and walls, zones and decor stop there', async () => {
618
+ const w = plan({ tool: 'wall', tables: [], width: 400, height: 300 })
619
+ down(w.element, 3, 296)
620
+ down(w.element, 398, 297)
621
+ key(w, 'Enter')
622
+ await nextTick()
623
+ expect(w.props('walls')[0].points).toEqual([[0, 300], [400, 300]])
624
+ // A corner dragged past the edge stays on it
625
+ await w.setProps({ tool: 'select', walls: [{ id: 'w', points: [[100, 100], [200, 100]] }], picked: { kind: 'wall', id: 'w' } })
626
+ const corner = w.findAll('circle').at(-1)!.element
627
+ down(corner, 200, 100)
628
+ moveUp(520, -40)
629
+ await nextTick()
630
+ expect(w.props('walls')[0].points[1]).toEqual([400, 0])
631
+ // The whole wall stops at the edge
632
+ down(w.find('path.m3-floor-wall').element, 150, 100)
633
+ moveUp(150, 600)
634
+ await nextTick()
635
+ expect(w.props('walls')[0].points.map((p: number[]) => p[1])).toEqual([300, 200])
636
+ // Decor too
637
+ await w.setProps({ decor: [{ id: 'p', kind: 'plant', x: 100, y: 100 }] })
638
+ down(w.find('[aria-label="Plant"]').element, 0, 0)
639
+ moveUp(-500, 0)
640
+ await nextTick()
641
+ expect(w.props('decor')[0].x).toBe(20)
642
+ })
643
+ it('zoomed in, a drag near the view\'s edge scrolls the plan and brings what it holds along', async () => {
644
+ const w = plan({ tables: [], zoomable: true, width: 400, height: 300, zoom: 2, decor: [{ id: 'p', kind: 'plant', x: 100, y: 100 }] })
645
+ ;(w.element as HTMLElement).getBoundingClientRect = () => ({ left: 0, top: 0, right: 400, bottom: 300, width: 400, height: 300, x: 0, y: 0, toJSON() {} }) as DOMRect
646
+ Object.defineProperty(w.element, 'clientWidth', { value: 400 })
647
+ window.dispatchEvent(new Event('resize'))
648
+ const plant = w.find('[aria-label="Plant"]').element
649
+ down(plant, 200, 200)
650
+ move(300, 200)
651
+ move(395, 200)
652
+ await new Promise((r) => setTimeout(r, 150))
653
+ window.dispatchEvent(new PointerEvent('pointerup', { clientX: 395, clientY: 200, pointerId: 7 }))
654
+ await nextTick()
655
+ // Without scrolling it would have moved (395 - 200) / 2 ≈ 97.5; the view scrolled, so it went farther
656
+ expect(w.props('decor')[0].x).toBeGreaterThan(220)
657
+ })
658
+ it('a wall being drawn joins another wall\'s corner nearby', async () => {
659
+ const w = plan({ tool: 'wall', tables: [], walls: [{ id: 'w', points: [[33, 47], [33, 200]] }] })
660
+ down(w.element, 35, 45)
661
+ down(w.element, 200, 50)
662
+ key(w, 'Enter')
663
+ await nextTick()
664
+ expect((w.props('walls') as any[])[1].points).toEqual([[33, 47], [200, 50]])
665
+ })
666
+ it('overlap: warn outlines tables on top of each other; prevent undoes the move', async () => {
667
+ 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 }] })
668
+ expect(table(w, 'A').classes()).toContain('m3-floor-overlap')
669
+ expect(table(w, 'C').classes()).not.toContain('m3-floor-overlap')
670
+ await w.setProps({ overlap: 'prevent' })
671
+ down(table(w, 'C').element, 0, 0)
672
+ moveUp(-260, 0)
673
+ await nextTick()
674
+ expect(w.props('tables')[2].x).toBe(400)
675
+ })
676
+ it('seatNumbers: chairs numbered, taken ones colored, a click in service emits seat-click', async () => {
677
+ const w = plan({ editable: false, seatNumbers: true, tables: [{ id: 1, label: 'A', x: 100, y: 100, seats: 4, activeSeats: [2] }] })
678
+ const chairs = w.findAll('[data-seat]')
679
+ expect(chairs.map((c) => c.text())).toEqual(['1', '2', '3', '4'])
680
+ expect(chairs[1]!.classes()).toContain('m3-floor-chair-taken')
681
+ await chairs[2]!.trigger('click')
682
+ expect(w.emitted('seat-click')![0]!.slice(0, 2)).toEqual([expect.objectContaining({ id: 1 }), 3])
683
+ })
684
+ it('measure: the picked wall\'s sides in your unit', () => {
685
+ const w = plan({ measure: { unit: 'm', per: 100 }, walls: [{ id: 'w', points: [[0, 0], [300, 0], [300, 150]] }], picked: { kind: 'wall', id: 'w' } })
686
+ expect(w.findAll('.m3-floor-measure').map((m: any) => m.text())).toEqual(['3.00 m', '1.50 m'])
687
+ })
688
+ it('toSVG draws zones, walls, decor and tables', () => {
689
+ 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 }] })
690
+ const svg = w.vm.toSVG() as string
691
+ expect(svg.startsWith('<svg')).toBe(true)
692
+ expect(svg).toContain('>Hall</text>')
693
+ expect(svg).toContain('<polyline')
694
+ expect(svg).toContain('>T1</text>')
695
+ expect(svg).toContain('A60 60')
696
+ })
697
+ it('duplicating near the edge keeps the copy inside the plan', async () => {
698
+ 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' } })
699
+ w.vm.duplicate()
700
+ await nextTick()
701
+ const copy = (w.props('decor') as any[])[1]
702
+ expect(copy.x).toBeLessThanOrEqual(380)
703
+ expect(copy.y).toBeLessThanOrEqual(280)
704
+ await w.setProps({ picked: { kind: 'area', id: 'z' } })
705
+ w.vm.duplicate()
706
+ await nextTick()
707
+ const z = (w.props('areas') as any[])[1]
708
+ expect(z.x + z.width).toBeLessThanOrEqual(400)
709
+ expect(z.y + z.height).toBeLessThanOrEqual(300)
710
+ })
711
+ })
712
+
713
+ describe('MFloorPlan zoom and tables', () => {
714
+ it('tables don\'t slide when the plan zooms, only when they move', async () => {
715
+ vi.useFakeTimers()
716
+ const w: any = mount(MFloorPlan, { props: { tables: base(), zoomable: true, zoom: 1, 'onUpdate:zoom': (v: number) => w.setProps({ zoom: v }) }, attachTo: document.body })
717
+ const wrap = () => table(w, 'T1').element.parentElement!
718
+ expect(wrap().className).toContain('transition-[left,top]')
719
+ await w.setProps({ zoom: 2 })
720
+ expect(wrap().style.left).toBe('200px')
721
+ expect(wrap().className).not.toContain('transition-[left,top]')
722
+ vi.advanceTimersByTime(200)
723
+ await nextTick()
724
+ expect(wrap().className).toContain('transition-[left,top]')
725
+ vi.useRealTimers()
726
+ })
727
+ })
728
+
729
+ describe('MFloorPlan cellSize and bigger tables', () => {
730
+ it('a table resized by cell keeps its cell and covers the next ones; dragged, it lands on whole cells', async () => {
731
+ const w: any = mount(MFloorPlan, {
732
+ 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 }) },
733
+ attachTo: document.body,
734
+ })
735
+ const wrap = () => table(w, 'A').element.parentElement!
736
+ // A one-cell table sits in the middle of its cell
737
+ expect(wrap().style.left).toBe('125px')
738
+ w.find('[data-table-resize]').element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 0, clientY: 0, pointerId: 8 }))
739
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: 60, clientY: 0, pointerId: 8 }))
740
+ window.dispatchEvent(new PointerEvent('pointerup', { clientX: 60, clientY: 0, pointerId: 8 }))
741
+ await nextTick()
742
+ // Two cells wide: still in cell (2, 1), covering cells 2 and 3
743
+ expect(w.props('tables')[0]).toMatchObject({ x: 2, y: 1, width: 100, height: 40 })
744
+ expect(wrap().style.left).toBe('150px')
745
+ table(w, 'A').element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 0, clientY: 0, pointerId: 8 }))
746
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: 70, clientY: 0, pointerId: 8 }))
747
+ window.dispatchEvent(new PointerEvent('pointerup', { clientX: 70, clientY: 0, pointerId: 8 }))
748
+ await nextTick()
749
+ expect(w.props('tables')[0]).toMatchObject({ x: 3, y: 1 })
750
+ expect(wrap().style.left).toBe('200px')
751
+ })
752
+ })
753
+
754
+ describe('MFloorPlan resizeSnap', () => {
755
+ const drag = (el: Element, dx: number, dy: number) => {
756
+ el.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, clientX: 0, clientY: 0, pointerId: 12 }))
757
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: dx, clientY: dy, pointerId: 12 }))
758
+ window.dispatchEvent(new PointerEvent('pointerup', { clientX: dx, clientY: dy, pointerId: 12 }))
759
+ }
760
+ function plan(props: Record<string, unknown>) {
761
+ const w: any = mount(MFloorPlan, {
762
+ props: { editable: true, ...props, ...Object.fromEntries(['tables', 'decor'].map((k) => [`onUpdate:${k}`, (v: unknown) => w.setProps({ [k]: v })])) },
763
+ attachTo: document.body,
764
+ })
765
+ return w
766
+ }
767
+ it('grid: a table by cell grows by whole cells, keeping its margin', async () => {
768
+ const w = plan({ grid: 50, cellSize: 50, resizeSnap: 'grid', selection: [1], tables: [{ id: 1, label: 'A', x: 1, y: 1, width: 40, height: 40 }] })
769
+ drag(w.find('[data-table-resize]').element, 62, 10)
770
+ await nextTick()
771
+ expect(w.props('tables')[0]).toMatchObject({ width: 90, height: 40 })
772
+ })
773
+ it('subgrid: a table about its middle grows a step on each side; free follows the pointer', async () => {
774
+ const w = plan({ grid: 20, subgrid: 2, resizeSnap: 'subgrid', selection: [1], tables: [{ id: 1, label: 'A', x: 100, y: 100, width: 60, height: 60 }] })
775
+ drag(w.find('[data-table-resize]').element, 13, 3)
776
+ await nextTick()
777
+ // Pulled 13 (26 in all, both sides): 20, one step of 10 per side
778
+ expect(w.props('tables')[0]).toMatchObject({ width: 80, height: 60 })
779
+ await w.setProps({ resizeSnap: 'free' })
780
+ drag(w.find('[data-table-resize]').element, 7, 0)
781
+ await nextTick()
782
+ expect(w.props('tables')[0]).toMatchObject({ width: 94 })
783
+ })
784
+ it('decor steps too, from its fixed corner', async () => {
785
+ 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' } })
786
+ drag(w.find('[data-resize]').element, 27, 2)
787
+ await nextTick()
788
+ expect((w.props('decor') as any[])[0]).toMatchObject({ width: 80, height: 14 })
789
+ })
790
+ })