@m3ui-vue/m3ui-vue 1.3.2 → 1.3.4
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 +77 -5
- package/dist/api.json +1 -1
- package/dist/components/MFlow.vue.d.ts +45 -6
- package/dist/components/MFlowHandle.vue.d.ts +3 -2
- package/dist/composables/flowPaths.d.ts +20 -1
- package/dist/composables/useFlow.d.ts +47 -1
- package/dist/flow.d.ts +2 -2
- package/dist/flow.js +1358 -1060
- package/dist/flow.js.map +1 -1
- package/dist/flowPaths-DzW-aiET.js +204 -0
- package/dist/flowPaths-DzW-aiET.js.map +1 -0
- package/dist/gantt.js +1 -1
- package/dist/m3ui.js +2 -2
- package/dist/m3ui.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/MFlow.test.ts +139 -2
- package/src/components/MFloorPlanInspector.vue +3 -3
- package/src/components/MFlow.vue +268 -33
- package/src/components/MFlowHandle.vue +5 -3
- package/src/components/_MFlowEdge.vue +73 -1
- package/src/composables/flowPaths.ts +77 -7
- package/src/composables/useFlow.ts +39 -1
- package/src/flow.ts +2 -1
- package/dist/flowPaths-CUc6X373.js +0 -161
- package/dist/flowPaths-CUc6X373.js.map +0 -1
package/package.json
CHANGED
|
@@ -2,7 +2,9 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
|
2
2
|
import { mount, flushPromises } from '@vue/test-utils'
|
|
3
3
|
import { nextTick } from 'vue'
|
|
4
4
|
import MFlow from '../components/MFlow.vue'
|
|
5
|
-
import
|
|
5
|
+
import MFlowHandle from '../components/MFlowHandle.vue'
|
|
6
|
+
import type { FlowEdge, FlowNode, FlowXY } from '../composables/useFlow'
|
|
7
|
+
import { routePoints, pointsToRoute } from '../composables/flowPaths'
|
|
6
8
|
|
|
7
9
|
// happy-dom has no layout: the canvas is 800×600 at the page's corner, every node 180×60
|
|
8
10
|
beforeEach(() => {
|
|
@@ -16,7 +18,7 @@ beforeEach(() => {
|
|
|
16
18
|
if (this.classList.contains('m3-flow')) return r(0, 0, 800, 600)
|
|
17
19
|
if (this.classList.contains('m3-flow-handle')) {
|
|
18
20
|
const c = this.className
|
|
19
|
-
const [x, y] = c.includes('right-0') ? [180, 30] : c.includes('bottom-0') ? [90, 60] : c.includes('top-1/2') ? [0, 30] : [90, 0]
|
|
21
|
+
const [x, y] = c.includes('left-1/2') && c.includes('top-1/2') ? [90, 30] : c.includes('right-0') ? [180, 30] : c.includes('bottom-0') ? [90, 60] : c.includes('top-1/2') ? [0, 30] : [90, 0]
|
|
20
22
|
return r(x - 5, y - 5, 10, 10)
|
|
21
23
|
}
|
|
22
24
|
return r(0, 0, 0, 0)
|
|
@@ -379,6 +381,112 @@ describe('MFlow', () => {
|
|
|
379
381
|
expect(w.emitted('update:viewport')!.at(-1)![0]).toEqual({ x: start.x + 60, y: start.y, zoom })
|
|
380
382
|
touch(window, 'pointerup', 3, 460, 400)
|
|
381
383
|
})
|
|
384
|
+
it('edgesReroutable: dragging a selected step edge\'s segment gives it a route, which moves with both its nodes', async () => {
|
|
385
|
+
const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'smoothstep' }]
|
|
386
|
+
const w = await flow({ edges, edgesReroutable: true, selection: { nodes: [], edges: ['e1'] } })
|
|
387
|
+
await nextTick()
|
|
388
|
+
const grip = w.find('[data-flow-segment="0"]')
|
|
389
|
+
expect(grip.exists()).toBe(true)
|
|
390
|
+
pointer(grip.element, 'pointerdown', 240, 30)
|
|
391
|
+
pointer(window, 'pointermove', 240, 60)
|
|
392
|
+
pointer(window, 'pointermove', 240, 90)
|
|
393
|
+
pointer(window, 'pointerup', 240, 90)
|
|
394
|
+
const out = w.emitted('update:edges')!.at(-1)![0] as FlowEdge[]
|
|
395
|
+
// A jog a grid step from each handle, running where the pointer let go
|
|
396
|
+
expect(out[0]!.route).toEqual([200, 90, 280])
|
|
397
|
+
expect(w.emitted('reroute')![0]![0]).toMatchObject({ id: 'e1', route: [200, 90, 280] })
|
|
398
|
+
await w.setProps({ edges: out })
|
|
399
|
+
expect(w.find('.m3-flow-edge-line').attributes('d')).toMatch(/^M180,30 L/)
|
|
400
|
+
})
|
|
401
|
+
it('a segment grip moves out from under the delete button', async () => {
|
|
402
|
+
const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'smoothstep' }]
|
|
403
|
+
const w = await flow({ edges, edgesReroutable: true, selection: { nodes: [], edges: ['e1'] } })
|
|
404
|
+
await nextTick()
|
|
405
|
+
// The × sits at (240, 30), 40px wide with its hit area: the grip of the one segment (180 → 300) slides clear of it
|
|
406
|
+
const grip = w.find('[data-flow-segment="0"]')
|
|
407
|
+
const cx = Number(grip.attributes('x')) + 9
|
|
408
|
+
expect(Math.abs(cx - 240)).toBeGreaterThanOrEqual(20 + 9)
|
|
409
|
+
expect(cx).toBeGreaterThan(180)
|
|
410
|
+
expect(cx).toBeLessThan(300)
|
|
411
|
+
})
|
|
412
|
+
it('snapToGrid puts a node\'s position plus its gridOffset on the grid', async () => {
|
|
413
|
+
const w = await flow({ nodes: [N('a', 10, 10, { gridOffset: { x: 10, y: 10 } }), N('b', 300, 0)], snapToGrid: true, gridSize: 20 })
|
|
414
|
+
pointer(node(w, 'a'), 'pointerdown', 100, 40)
|
|
415
|
+
pointer(window, 'pointermove', 140, 80)
|
|
416
|
+
pointer(window, 'pointermove', 203, 143)
|
|
417
|
+
pointer(window, 'pointerup', 203, 143)
|
|
418
|
+
const nodes = w.emitted('update:nodes')!.at(-1)![0] as FlowNode[]
|
|
419
|
+
// Its middle (position + 10) sits on the 20px grid
|
|
420
|
+
expect(nodes.find((n) => n.id === 'a')!.position).toEqual({ x: 110, y: 110 })
|
|
421
|
+
})
|
|
422
|
+
it('getEdgeAt finds the edge under a point, where on it, and which way it runs', async () => {
|
|
423
|
+
const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'smoothstep' }]
|
|
424
|
+
const w = await flow({ edges, snapToGrid: true, gridSize: 20 })
|
|
425
|
+
const ctx = w.vm as unknown as { getEdgeAt: (p: FlowXY, o?: object) => unknown }
|
|
426
|
+
expect(ctx.getEdgeAt({ x: 243, y: 34 })).toMatchObject({ edge: { id: 'e1' }, position: { x: 240, y: 30 }, direction: 'right' })
|
|
427
|
+
expect(ctx.getEdgeAt({ x: 243, y: 60 })).toBeNull()
|
|
428
|
+
expect(ctx.getEdgeAt({ x: 243, y: 34 }, { ignore: (e: FlowEdge) => e.id === 'e1' })).toBeNull()
|
|
429
|
+
})
|
|
430
|
+
it('a tap on a handle selects its node; a drag from it still connects', async () => {
|
|
431
|
+
const w = await flow({ nodes: [N('a', 0, 0), N('b', 300, 0), N('c', 300, 200)] })
|
|
432
|
+
const out = w.find('[data-flow-node="a"] [data-flow-handle="source"]').element
|
|
433
|
+
pointer(out, 'pointerdown', 180, 30)
|
|
434
|
+
pointer(window, 'pointerup', 181, 30)
|
|
435
|
+
expect(w.emitted('update:selection')!.at(-1)![0]).toEqual({ nodes: ['a'], edges: [] })
|
|
436
|
+
expect(w.emitted('connect')).toBeUndefined()
|
|
437
|
+
// b's input already has e1: tapped (not pulled), it selects b and leaves e1 alone
|
|
438
|
+
pointer(w.find('[data-flow-node="b"] [data-flow-handle="target"]').element, 'pointerdown', 300, 30)
|
|
439
|
+
pointer(window, 'pointerup', 300, 30)
|
|
440
|
+
expect(w.emitted('update:selection')!.at(-1)![0]).toEqual({ nodes: ['b'], edges: [] })
|
|
441
|
+
expect(w.emitted('update:edges')).toBeUndefined()
|
|
442
|
+
})
|
|
443
|
+
it("a handle at position 'auto' leaves on the side facing the edge's other end", async () => {
|
|
444
|
+
const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'step', markerEnd: 'none' }]
|
|
445
|
+
const w = mount(MFlow, {
|
|
446
|
+
props: { nodes: [N('a', 0, 0, { type: 'dot' }), N('b', 300, 200)], edges, animate: false },
|
|
447
|
+
slots: { 'node-dot': `<template #node-dot><div style="width:180px;height:60px"><MFlowHandle type="source" position="auto" /></div></template>` },
|
|
448
|
+
global: { components: { MFlowHandle } },
|
|
449
|
+
attachTo: document.body,
|
|
450
|
+
})
|
|
451
|
+
await flushPromises()
|
|
452
|
+
await nextTick()
|
|
453
|
+
// From the middle of a (90, 30) toward b's left side (300, 230): it goes right first
|
|
454
|
+
expect(w.find('.m3-flow-edge-line').attributes('d')).toMatch(/^M90,30 L\d+/)
|
|
455
|
+
const first = () => w.find('.m3-flow-edge-line').attributes('d').match(/^M90,30 L(-?[\d.]+),(-?[\d.]+)/)!
|
|
456
|
+
expect(Number(first()[1])).toBeGreaterThan(90)
|
|
457
|
+
// b far below and only a little to the right: it goes down first
|
|
458
|
+
await w.setProps({ nodes: [N('a', 0, 0, { type: 'dot' }), N('b', 120, 600)] })
|
|
459
|
+
await nextTick()
|
|
460
|
+
expect(Number(first()[1])).toBe(90)
|
|
461
|
+
expect(Number(first()[2])).toBeGreaterThan(30)
|
|
462
|
+
// An edge can ask for its side: up first, whatever the other end
|
|
463
|
+
await w.setProps({ edges: [{ ...edges[0]!, sourcePosition: 'top' as const }] })
|
|
464
|
+
await nextTick()
|
|
465
|
+
expect(Number(first()[1])).toBe(90)
|
|
466
|
+
expect(Number(first()[2])).toBeLessThan(30)
|
|
467
|
+
})
|
|
468
|
+
it('routePoints / pointsToRoute round-trip, and the ends stretch when a node moves', () => {
|
|
469
|
+
const ends = { sourceX: 0, sourceY: 0, sourcePosition: 'right' as const, targetX: 200, targetY: 100, targetPosition: 'left' as const }
|
|
470
|
+
const pts = routePoints({ ...ends, route: [60, 40, 140] })
|
|
471
|
+
expect(pts).toEqual([[0, 0], [60, 0], [60, 40], [140, 40], [140, 100], [200, 100]])
|
|
472
|
+
expect(pointsToRoute(pts, 'right', 'left')).toEqual([60, 40, 140])
|
|
473
|
+
expect(pointsToRoute(pts, 'right')).toEqual([60, 40, 140, 100])
|
|
474
|
+
// The target went up: the last leg still arrives level with it
|
|
475
|
+
expect(routePoints({ ...ends, targetY: -20, route: [60, 40, 140] }).at(-2)).toEqual([140, -20])
|
|
476
|
+
})
|
|
477
|
+
it('a pinch that starts on a node zooms without selecting it; a tap on a node still selects it', async () => {
|
|
478
|
+
const w = await flow()
|
|
479
|
+
const touch = (el: EventTarget, type: string, id: number, x: number, y: number) => pointer(el, type, x, y, { pointerType: 'touch', pointerId: id })
|
|
480
|
+
touch(node(w, 'a'), 'pointerdown', 1, 60, 30)
|
|
481
|
+
touch(w.element, 'pointerdown', 2, 260, 30)
|
|
482
|
+
touch(window, 'pointermove', 2, 460, 30)
|
|
483
|
+
touch(window, 'pointerup', 1, 60, 30)
|
|
484
|
+
touch(window, 'pointerup', 2, 460, 30)
|
|
485
|
+
expect(w.emitted('update:selection')).toBeUndefined()
|
|
486
|
+
touch(node(w, 'b'), 'pointerdown', 3, 360, 30)
|
|
487
|
+
touch(window, 'pointerup', 3, 360, 30)
|
|
488
|
+
expect(w.emitted('update:selection')!.at(-1)![0]).toEqual({ nodes: ['b'], edges: [] })
|
|
489
|
+
})
|
|
382
490
|
it('a node spliced in without room pushes the next one, and what comes after it, along', async () => {
|
|
383
491
|
// a (0..180) → c (260..440) → d (600..): b (180 wide) can't fit between a and c with 48px each side
|
|
384
492
|
const nodes = [N('a', 0, 0), N('c', 260, 0), N('d', 600, 0), N('b', 100, 300)]
|
|
@@ -523,6 +631,35 @@ describe('MFlow', () => {
|
|
|
523
631
|
// The view didn't pan meanwhile
|
|
524
632
|
expect(w.emitted('update:viewport')).toBeUndefined()
|
|
525
633
|
})
|
|
634
|
+
it("edgeBranching 'junction': adds nothing, and tells where on the edge the branch was grabbed", async () => {
|
|
635
|
+
const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'smoothstep' }]
|
|
636
|
+
const w = await flow({ nodes: [N('a', 0, 0), N('b', 300, 0), N('c', 300, 200)], edges, edgeBranching: 'junction', snapToGrid: true, gridSize: 20 })
|
|
637
|
+
pointer(w.find('[data-flow-edge="e1"] path').element, 'pointerdown', 243, 34)
|
|
638
|
+
pointer(window, 'pointermove', 340, 220)
|
|
639
|
+
pointer(window, 'pointerup', 340, 220)
|
|
640
|
+
// On the edge (y 30) and on the grid along it (x 240)
|
|
641
|
+
expect(w.emitted('branch')![0]![0]).toMatchObject({ edge: { id: 'e1' }, connection: { source: 'a', target: 'c' }, position: { x: 240, y: 30 }, direction: 'right', end: { x: 340, y: 220 } })
|
|
642
|
+
expect(w.emitted('connect')).toBeUndefined()
|
|
643
|
+
expect(w.emitted('update:edges')).toBeUndefined()
|
|
644
|
+
// Dropped on nothing: still a branch, with no connection
|
|
645
|
+
pointer(w.find('[data-flow-edge="e1"] path').element, 'pointerdown', 260, 30)
|
|
646
|
+
pointer(window, 'pointermove', 500, 500)
|
|
647
|
+
pointer(window, 'pointerup', 500, 500)
|
|
648
|
+
expect(w.emitted('branch')![1]![0]).toMatchObject({ connection: null, position: { x: 260, y: 30 } })
|
|
649
|
+
})
|
|
650
|
+
it("edgeBranching 'junction': on a vertical run, says it runs down, and splits an edge's own route in two", async () => {
|
|
651
|
+
// a's right (180, 30) → over at x 240 → down to b's left (300, 230)
|
|
652
|
+
const edges: FlowEdge[] = [{ id: 'e1', source: 'a', target: 'b', type: 'smoothstep', route: [240] }]
|
|
653
|
+
const w = await flow({ nodes: [N('a', 0, 0), N('b', 300, 200), N('c', 600, 400)], edges, edgeBranching: 'junction', snapToGrid: true, gridSize: 20 })
|
|
654
|
+
pointer(w.find('[data-flow-edge="e1"] path').element, 'pointerdown', 243, 128)
|
|
655
|
+
pointer(window, 'pointermove', 500, 500)
|
|
656
|
+
pointer(window, 'pointerup', 500, 500)
|
|
657
|
+
const ev = w.emitted('branch')![0]![0] as { position: FlowXY; direction: string; routes: { before: number[]; after: number[] } }
|
|
658
|
+
expect(ev.position).toEqual({ x: 240, y: 120 })
|
|
659
|
+
expect(ev.direction).toBe('bottom')
|
|
660
|
+
expect(routePoints({ sourceX: 180, sourceY: 30, sourcePosition: 'right', targetX: 240, targetY: 120, targetPosition: 'top', route: ev.routes.before })).toEqual([[180, 30], [240, 30], [240, 120]])
|
|
661
|
+
expect(routePoints({ sourceX: 240, sourceY: 120, sourcePosition: 'bottom', targetX: 300, targetY: 230, targetPosition: 'left', route: ev.routes.after })).toEqual([[240, 120], [240, 230], [300, 230]])
|
|
662
|
+
})
|
|
526
663
|
it('edgeBranching: a click still selects; off (the default), a drag from an edge pans; a finger only branches a selected edge', async () => {
|
|
527
664
|
let w = await flow({ nodes: [N('a', 0, 0), N('b', 300, 0), N('c', 300, 200)], edgeBranching: true })
|
|
528
665
|
let hit = w.find('[data-flow-edge="e1"] path').element
|
|
@@ -74,7 +74,7 @@ function deleteCorner() {
|
|
|
74
74
|
<!-- A table -->
|
|
75
75
|
<template v-if="table">
|
|
76
76
|
<div class="flex items-center gap-2 text-title-small"><MIcon name="table_restaurant" :size="18" />{{ locale.floorTableN.replace('{label}', table.label) }}</div>
|
|
77
|
-
<div class="grid grid-cols-
|
|
77
|
+
<div class="grid grid-cols-[repeat(auto-fit,minmax(9rem,1fr))] gap-3">
|
|
78
78
|
<MTextField :model-value="table.label" :label="locale.floorLabel" variant="outlined" @update:model-value="upTable({ label: String($event) })" />
|
|
79
79
|
<MNumberField :model-value="table.seats ?? 0" :label="locale.floorSeatsField" variant="outlined" :min="0" :max="40" @update:model-value="upTable({ seats: $event ?? 0, width: undefined, height: undefined })" />
|
|
80
80
|
</div>
|
|
@@ -124,7 +124,7 @@ function deleteCorner() {
|
|
|
124
124
|
/>
|
|
125
125
|
</div>
|
|
126
126
|
</div>
|
|
127
|
-
<div class="grid grid-cols-
|
|
127
|
+
<div class="grid grid-cols-[repeat(auto-fit,minmax(9rem,1fr))] gap-3">
|
|
128
128
|
<MNumberField :model-value="Math.round(area.width)" :label="locale.floorWidth" variant="outlined" :min="10" @update:model-value="upArea({ width: $event ?? area.width })" />
|
|
129
129
|
<MNumberField :model-value="Math.round(area.height)" :label="locale.floorHeight" variant="outlined" :min="10" @update:model-value="upArea({ height: $event ?? area.height })" />
|
|
130
130
|
</div>
|
|
@@ -150,7 +150,7 @@ function deleteCorner() {
|
|
|
150
150
|
<template v-else-if="item">
|
|
151
151
|
<div class="flex items-center gap-2 text-title-small"><MIcon :name="kind?.icon ?? 'category'" :size="18" />{{ floorDecorName(item.kind, ctx.kinds.value, locale) }}</div>
|
|
152
152
|
<MTextField :model-value="item.label ?? ''" :label="locale.floorLabel" variant="outlined" @update:model-value="upDecor({ label: String($event) || undefined })" />
|
|
153
|
-
<div class="grid grid-cols-
|
|
153
|
+
<div class="grid grid-cols-[repeat(auto-fit,minmax(9rem,1fr))] gap-3">
|
|
154
154
|
<MNumberField :model-value="Math.round(item.width ?? kind?.width ?? 40)" :label="locale.floorWidth" variant="outlined" :min="4" @update:model-value="upDecor({ width: $event ?? undefined })" />
|
|
155
155
|
<MNumberField :model-value="Math.round(item.height ?? kind?.height ?? 40)" :label="locale.floorHeight" variant="outlined" :min="4" @update:model-value="upDecor({ height: $event ?? undefined })" />
|
|
156
156
|
</div>
|