@m3ui-vue/m3ui-vue 1.3.7 → 1.3.8
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 +40 -9
- package/dist/api.json +1 -1
- package/dist/components/MBadge.vue.d.ts +1 -1
- package/dist/components/MFlow.vue.d.ts +13 -0
- package/dist/components/MSlider.vue.d.ts +2 -2
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MTour.vue.d.ts +52 -2
- package/dist/composables/flowPaths.d.ts +11 -3
- package/dist/composables/useFlow.d.ts +4 -0
- package/dist/flow.d.ts +1 -1
- package/dist/flow.js +525 -433
- package/dist/flow.js.map +1 -1
- package/dist/{flowPaths-DzW-aiET.js → flowPaths-CcWOKY4Z.js} +5 -5
- package/dist/flowPaths-CcWOKY4Z.js.map +1 -0
- package/dist/gantt.js +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +232 -163
- package/dist/m3ui.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/__tests__/MFlow.test.ts +69 -0
- package/src/__tests__/MTour.test.ts +102 -0
- package/src/components/MFlow.vue +117 -17
- package/src/components/MTour.vue +145 -27
- package/src/composables/flowPaths.ts +16 -7
- package/src/composables/useFlow.ts +4 -0
- package/src/flow.ts +1 -1
- package/dist/flowPaths-DzW-aiET.js.map +0 -1
package/src/components/MFlow.vue
CHANGED
|
@@ -17,7 +17,7 @@ const emptySelection = (): FlowSelection => ({ nodes: [], edges: [] })
|
|
|
17
17
|
* and the lock are too. Pan by dragging the background (or the wheel, or two fingers), zoom with Ctrl + wheel, a
|
|
18
18
|
* trackpad or touch pinch, or a double click. Shift + drag (or `selectionOnDrag`; on touch, a long press on the
|
|
19
19
|
* background) draws a selection box; Delete
|
|
20
|
-
* removes what's selected, Ctrl+Z/Ctrl+Shift+Z undo and redo, Ctrl+C/X/V/A copy, cut, paste and select all, and
|
|
20
|
+
* removes what's selected, Ctrl+Z/Ctrl+Shift+Z undo and redo, Ctrl+C/X/V/D/A copy, cut, paste, duplicate and select all, and
|
|
21
21
|
* the arrows move the selected nodes. A drag from a handle to another connects them; dropped on nothing it fires
|
|
22
22
|
* `connect-end` with the spot, to offer a new node there. To disconnect: the × on a selected edge, Delete, dragging
|
|
23
23
|
* an edge's end (or a connected input) away and dropping it on nothing. Alignment guides show while dragging one node.
|
|
@@ -80,7 +80,7 @@ import {
|
|
|
80
80
|
type FlowXY,
|
|
81
81
|
} from '../composables/useFlow'
|
|
82
82
|
import { layoutLayered, layoutTree, type FlowLayout, type FlowLayoutDirection, type FlowLayoutOptions } from '../composables/flowLayout'
|
|
83
|
-
import { distanceToPoints, edgePathPoints, getBezierPath, getRoutedPath, getSmoothStepPath, getStepPath, getStraightPath, pointsToRoute, routePoints, smoothStepPoints, type FlowEdgePath } from '../composables/flowPaths'
|
|
83
|
+
import { distanceToPoints, edgePathPoints, getBezierPath, getRoutedPath, getSmoothStepPath, getStepPath, getStraightPath, pointsToRoute, routePoints, smoothStepPoints, type FlowEdgePath, type FlowStepCenter } from '../composables/flowPaths'
|
|
84
84
|
import { DEFAULT_SPATIAL } from '../composables/_useSpring'
|
|
85
85
|
import { prefersReducedMotion } from '../composables/_springAnimation'
|
|
86
86
|
import { useLocale } from '../composables/useLocale'
|
|
@@ -126,6 +126,12 @@ const props = withDefaults(defineProps<{
|
|
|
126
126
|
* the route in `edge.route`), or drag a leg at either end to add a jog. Default off
|
|
127
127
|
*/
|
|
128
128
|
edgesReroutable?: boolean
|
|
129
|
+
/**
|
|
130
|
+
* `smoothstep`/`step` edges from different sources whose middle runs would lie on top of each other, running the
|
|
131
|
+
* same way, are moved apart by this many px, so two wires never read as one (edges from the same output may share
|
|
132
|
+
* a run). Edges with their own `route` stay put and the others keep off them. Default 0: off
|
|
133
|
+
*/
|
|
134
|
+
edgeSpacing?: number
|
|
129
135
|
/** Merged into edges made by connecting (`type`, `animated`, `markerEnd`…) */
|
|
130
136
|
defaultEdgeOptions?: Partial<FlowEdge>
|
|
131
137
|
/** Adds an edge to `edges` when a connection is made; off, only `connect` fires */
|
|
@@ -199,6 +205,7 @@ const props = withDefaults(defineProps<{
|
|
|
199
205
|
elementsSelectable: true,
|
|
200
206
|
edgesReconnectable: true,
|
|
201
207
|
edgesReroutable: false,
|
|
208
|
+
edgeSpacing: 0,
|
|
202
209
|
autoConnect: true,
|
|
203
210
|
connectionRadius: 24,
|
|
204
211
|
deleteKeys: () => ['Delete', 'Backspace'],
|
|
@@ -631,7 +638,7 @@ function rawHandlePoint(nodeId: string, type: 'source' | 'target', handleId?: st
|
|
|
631
638
|
// Arrowheads stop at a handle's rim instead of under it
|
|
632
639
|
const HANDLE_RADIUS = 5
|
|
633
640
|
|
|
634
|
-
function pathFor(type: string | undefined, p: Omit<EdgeGeometry, keyof FlowEdgePath | 'sourceInset' | 'targetInset'>): FlowEdgePath {
|
|
641
|
+
function pathFor(type: string | undefined, p: Omit<EdgeGeometry, keyof FlowEdgePath | 'sourceInset' | 'targetInset'> & FlowStepCenter): FlowEdgePath {
|
|
635
642
|
switch (type) {
|
|
636
643
|
case 'smoothstep': return getSmoothStepPath(p)
|
|
637
644
|
case 'step': return getStepPath(p)
|
|
@@ -712,7 +719,7 @@ function edgeGeometry(e: FlowEdge): EdgeGeometry | null {
|
|
|
712
719
|
if (!at) return null
|
|
713
720
|
const { s, t, ends } = at
|
|
714
721
|
const route = isOrthogonal(e) ? routeOf(e) : undefined
|
|
715
|
-
const path = route ? getRoutedPath({ ...ends, route, borderRadius: edgeRoute(e) === 'step' ? 0 : 8 }) : pathFor(edgeRoute(e), ends)
|
|
722
|
+
const path = route ? getRoutedPath({ ...ends, route, borderRadius: edgeRoute(e) === 'step' ? 0 : 8 }) : pathFor(edgeRoute(e), { ...ends, ...lanes.value.get(e.id) })
|
|
716
723
|
return { ...ends, ...path, sourceInset: s.inset, targetInset: t.inset }
|
|
717
724
|
}
|
|
718
725
|
function edgeCorners(e: FlowEdge): [number, number][] | null {
|
|
@@ -720,8 +727,73 @@ function edgeCorners(e: FlowEdge): [number, number][] | null {
|
|
|
720
727
|
const at = edgeEnds(e)
|
|
721
728
|
if (!at) return null
|
|
722
729
|
const route = routeOf(e)
|
|
723
|
-
return route ? routePoints({ ...at.ends, route }) : smoothStepPoints(at.ends)
|
|
724
|
-
}
|
|
730
|
+
return route ? routePoints({ ...at.ends, route }) : smoothStepPoints({ ...at.ends, ...lanes.value.get(e.id) })
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// ── Keeping parallel edges apart (edgeSpacing) ────────────────────────────────────────────────────────────
|
|
734
|
+
// Each step edge whose ends face each other has one free run halfway between them (vertical between left/right
|
|
735
|
+
// handles, horizontal between top/bottom ones). Those runs are laid out like lanes: one that would lie on another
|
|
736
|
+
// edge's run (same way, overlapping, from a different source) moves a spacing to either side, nearest first,
|
|
737
|
+
// staying between the legs. Everything else (legs, routed edges) is an obstacle that doesn't move.
|
|
738
|
+
const STEP_OFFSET = 20
|
|
739
|
+
interface Run { src: string; vertical: boolean; c: number; lo: number; hi: number }
|
|
740
|
+
function freeRun(ends: { sourceX: number; sourceY: number; sourcePosition: FlowPosition; targetX: number; targetY: number; targetPosition: FlowPosition }) {
|
|
741
|
+
const n = { left: -1, right: 1, top: -1, bottom: 1 } as const
|
|
742
|
+
const sH = ends.sourcePosition === 'left' || ends.sourcePosition === 'right'
|
|
743
|
+
const tH = ends.targetPosition === 'left' || ends.targetPosition === 'right'
|
|
744
|
+
if (sH !== tH) return null
|
|
745
|
+
const ns = n[ends.sourcePosition]
|
|
746
|
+
const nt = n[ends.targetPosition]
|
|
747
|
+
const [s, t] = sH ? [ends.sourceX, ends.targetX] : [ends.sourceY, ends.targetY]
|
|
748
|
+
if (ns !== -nt || (t - s) * ns < 2 * STEP_OFFSET) return null
|
|
749
|
+
const a = s + ns * STEP_OFFSET
|
|
750
|
+
const b = t + nt * STEP_OFFSET
|
|
751
|
+
return { vertical: sH, c: (s + t) / 2, min: Math.min(a, b), max: Math.max(a, b) }
|
|
752
|
+
}
|
|
753
|
+
const lanes = computed(() => {
|
|
754
|
+
const out = new Map<string, FlowStepCenter>()
|
|
755
|
+
const gap = props.edgeSpacing
|
|
756
|
+
if (!gap) return out
|
|
757
|
+
const placed: Run[] = []
|
|
758
|
+
const free: (Run & { id: string; min: number; max: number })[] = []
|
|
759
|
+
for (const e of visibleEdges.value) {
|
|
760
|
+
if (!isOrthogonal(e)) continue
|
|
761
|
+
const at = edgeEnds(e)
|
|
762
|
+
if (!at) continue
|
|
763
|
+
const src = `${e.source}\u0000${e.sourceHandle ?? ''}`
|
|
764
|
+
const route = routeOf(e)
|
|
765
|
+
const run = route ? null : freeRun(at.ends)
|
|
766
|
+
const pts = route ? routePoints({ ...at.ends, route }) : smoothStepPoints(at.ends)
|
|
767
|
+
for (let i = 1; i < pts.length; i++) {
|
|
768
|
+
const [ax, ay] = pts[i - 1]!
|
|
769
|
+
const [bx, by] = pts[i]!
|
|
770
|
+
const vertical = Math.abs(ax - bx) < 0.01
|
|
771
|
+
if (!vertical && Math.abs(ay - by) >= 0.01) continue
|
|
772
|
+
const r: Run = { src, vertical, c: vertical ? ax : ay, lo: vertical ? Math.min(ay, by) : Math.min(ax, bx), hi: vertical ? Math.max(ay, by) : Math.max(ax, bx) }
|
|
773
|
+
if (run && run.vertical === vertical && Math.abs(run.c - r.c) < 0.01) free.push({ ...r, id: e.id, min: run.min, max: run.max })
|
|
774
|
+
else placed.push(r)
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
const clash = (r: Run, c: number) =>
|
|
778
|
+
placed.some((o) => o.vertical === r.vertical && o.src !== r.src && Math.abs(o.c - c) < gap / 2 && Math.min(o.hi, r.hi) - Math.max(o.lo, r.lo) > 0.5)
|
|
779
|
+
// Longer runs first: they have the most to cross, and shorter ones fit around them
|
|
780
|
+
free.sort((a, b) => b.hi - b.lo - (a.hi - a.lo) || a.c - b.c)
|
|
781
|
+
for (const r of free) {
|
|
782
|
+
let c = r.c
|
|
783
|
+
for (let k = 0; k <= 16; k++) {
|
|
784
|
+
const step = k === 0 ? 0 : Math.ceil(k / 2) * gap * (k % 2 ? 1 : -1)
|
|
785
|
+
const at = r.c + step
|
|
786
|
+
if (at < r.min - 0.01 || at > r.max + 0.01) continue
|
|
787
|
+
if (!clash(r, at)) {
|
|
788
|
+
c = at
|
|
789
|
+
break
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
if (c !== r.c) out.set(r.id, r.vertical ? { centerX: c } : { centerY: c })
|
|
793
|
+
placed.push({ ...r, c })
|
|
794
|
+
}
|
|
795
|
+
return out
|
|
796
|
+
})
|
|
725
797
|
const isReroutable = (e: FlowEdge) => !locked.value && isOrthogonal(e) && (e.reroutable ?? props.edgesReroutable)
|
|
726
798
|
|
|
727
799
|
// What's drawn: groups under the edges, other nodes over them; children over their parents
|
|
@@ -911,11 +983,12 @@ function selectAll() {
|
|
|
911
983
|
})
|
|
912
984
|
}
|
|
913
985
|
|
|
914
|
-
|
|
986
|
+
/** The selected nodes (their children too) and the edges between them, as copy() keeps them */
|
|
987
|
+
function selectionClip(): { nodes: FlowNode[]; edges: FlowEdge[] } | null {
|
|
915
988
|
const ids = new Set(selLocal.value.nodes)
|
|
916
989
|
for (const id of [...ids]) descendants(id).forEach((d) => ids.add(d))
|
|
917
|
-
if (!ids.size) return
|
|
918
|
-
|
|
990
|
+
if (!ids.size) return null
|
|
991
|
+
return {
|
|
919
992
|
nodes: nodesLocal.value.filter((n) => ids.has(n.id)).map((n) => {
|
|
920
993
|
// A node copied without its group keeps its place on the canvas
|
|
921
994
|
if (n.parentId && !ids.has(n.parentId)) {
|
|
@@ -926,6 +999,11 @@ function copy() {
|
|
|
926
999
|
}),
|
|
927
1000
|
edges: edgesLocal.value.filter((e) => ids.has(e.source) && ids.has(e.target)),
|
|
928
1001
|
}
|
|
1002
|
+
}
|
|
1003
|
+
function copy() {
|
|
1004
|
+
const clip = selectionClip()
|
|
1005
|
+
if (!clip) return
|
|
1006
|
+
clipboard = clip
|
|
929
1007
|
pasteCount = 0
|
|
930
1008
|
}
|
|
931
1009
|
function cut() {
|
|
@@ -936,21 +1014,33 @@ function cut() {
|
|
|
936
1014
|
function paste(at?: FlowXY) {
|
|
937
1015
|
if (!clipboard?.nodes.length || locked.value) return
|
|
938
1016
|
pasteCount++
|
|
939
|
-
|
|
1017
|
+
place(clipboard, at, props.gridSize * 2 * pasteCount)
|
|
1018
|
+
}
|
|
1019
|
+
/** Copies of the selection a grid step or two away, leaving the clipboard alone */
|
|
1020
|
+
function duplicate() {
|
|
1021
|
+
const clip = selectionClip()
|
|
1022
|
+
if (!clip || locked.value) return
|
|
1023
|
+
place(clip, undefined, props.gridSize * 2)
|
|
1024
|
+
}
|
|
1025
|
+
/** Adds copies of `clip` (new ids), its top left at `at` or `step` from where it was, and selects them */
|
|
1026
|
+
function place(clip: { nodes: FlowNode[]; edges: FlowEdge[] }, at: FlowXY | undefined, step: number) {
|
|
1027
|
+
const tops = clip.nodes.filter((n) => !n.parentId || !clip.nodes.some((m) => m.id === n.parentId))
|
|
940
1028
|
const minX = Math.min(...tops.map((n) => n.position.x))
|
|
941
1029
|
const minY = Math.min(...tops.map((n) => n.position.y))
|
|
942
|
-
|
|
943
|
-
const
|
|
944
|
-
const
|
|
945
|
-
const
|
|
1030
|
+
// On the grid, the same step as moving them would be, so a node that sat on it still does
|
|
1031
|
+
const gs = props.gridSize
|
|
1032
|
+
const onGrid = (v: number) => (props.snapToGrid && gs ? Math.round(v / gs) * gs : v)
|
|
1033
|
+
const dx = onGrid(at ? at.x - minX : step)
|
|
1034
|
+
const dy = onGrid(at ? at.y - minY : step)
|
|
1035
|
+
const idMap = new Map(clip.nodes.map((n) => [n.id, makeId('node')]))
|
|
946
1036
|
const topIds = new Set(tops.map((n) => n.id))
|
|
947
|
-
const nodes =
|
|
1037
|
+
const nodes = clip.nodes.map((n) => ({
|
|
948
1038
|
...n,
|
|
949
1039
|
id: idMap.get(n.id)!,
|
|
950
1040
|
parentId: n.parentId ? idMap.get(n.parentId) ?? n.parentId : undefined,
|
|
951
1041
|
position: topIds.has(n.id) ? { x: n.position.x + dx, y: n.position.y + dy } : n.position,
|
|
952
1042
|
}))
|
|
953
|
-
const edges =
|
|
1043
|
+
const edges = clip.edges.map((e) => ({ ...e, id: makeId('edge'), source: idMap.get(e.source)!, target: idMap.get(e.target)! }))
|
|
954
1044
|
instantNext = true
|
|
955
1045
|
commit({ nodes: [...nodesLocal.value, ...nodes], edges: edges.length ? [...edgesLocal.value, ...edges] : undefined })
|
|
956
1046
|
setSelection({ nodes: nodes.map((n) => n.id), edges: edges.map((e) => e.id) })
|
|
@@ -1060,7 +1150,11 @@ function onPointerDown(e: PointerEvent) {
|
|
|
1060
1150
|
if (gesture) return
|
|
1061
1151
|
if (e.button === 2) return
|
|
1062
1152
|
downTarget = t
|
|
1063
|
-
|
|
1153
|
+
// The canvas takes the keys, except from content inside a node that handles its own (a field, a game pad, a piano
|
|
1154
|
+
// focusing itself on this same pointerdown would otherwise lose its focus at once). Its keys still bubble up here
|
|
1155
|
+
const own = t.closest(NO_DRAG)
|
|
1156
|
+
const ownerNode = own?.closest('[data-flow-node]')
|
|
1157
|
+
if (!own || !ownerNode || own === ownerNode) root.value?.focus({ preventScroll: true })
|
|
1064
1158
|
|
|
1065
1159
|
const handle = t.closest<HTMLElement>('[data-flow-handle]')
|
|
1066
1160
|
const reconnect = t.closest<HTMLElement>('[data-flow-reconnect]')
|
|
@@ -2025,6 +2119,7 @@ function onKeyDown(e: KeyboardEvent) {
|
|
|
2025
2119
|
if (mod && key === 'a') { e.preventDefault(); selectAll(); return }
|
|
2026
2120
|
if (mod && key === 'c') { copy(); return }
|
|
2027
2121
|
if (mod && key === 'x') { e.preventDefault(); cut(); return }
|
|
2122
|
+
if (mod && key === 'd') { e.preventDefault(); duplicate(); return }
|
|
2028
2123
|
if (mod && key === 'v') {
|
|
2029
2124
|
e.preventDefault()
|
|
2030
2125
|
paste(pointer.inside ? screenToFlow(pointer) : undefined)
|
|
@@ -2114,6 +2209,11 @@ const context: FlowInternals = {
|
|
|
2114
2209
|
copy,
|
|
2115
2210
|
cut,
|
|
2116
2211
|
paste,
|
|
2212
|
+
duplicate,
|
|
2213
|
+
getEdgePath: (id: string) => {
|
|
2214
|
+
const e = edgeById.value.get(id)
|
|
2215
|
+
return (e && edgeGeometry(e)?.path) ?? null
|
|
2216
|
+
},
|
|
2117
2217
|
startDrag,
|
|
2118
2218
|
registerHandle,
|
|
2119
2219
|
measureNode: queueMeasure,
|
package/src/components/MTour.vue
CHANGED
|
@@ -3,17 +3,33 @@
|
|
|
3
3
|
* A guided, step-by-step walkthrough that highlights a page element per step with an auto-positioned tooltip
|
|
4
4
|
* and a dimming scrim.
|
|
5
5
|
*
|
|
6
|
+
* With `interactive` the page stays usable: no scrim, the target gets a ring drawn over it (the element itself is
|
|
7
|
+
* left alone) and the ring and the tooltip follow it every frame, for targets that move (a canvas being panned, a
|
|
8
|
+
* panel opening). With `v-model:step` the page drives the steps itself (a tutorial that moves on when the user has
|
|
9
|
+
* done what a step asks, or skips the ones already done), and the `content`/`actions` slots replace the text and
|
|
10
|
+
* the buttons.
|
|
11
|
+
*
|
|
12
|
+
* @slot content Replaces a step's title and text. Scope: `{ step, index }`
|
|
13
|
+
* @slot indicator Replaces the "2 / 5" over the step. Scope: `{ index, count }`
|
|
14
|
+
* @slot progress Replaces the progress dots. Scope: `{ index, count }`
|
|
15
|
+
* @slot actions Replaces the Previous/Next buttons. Scope: `{ step, index, isFirst, isLast, next, prev, close }`
|
|
6
16
|
* @event update:modelValue Emitted when the tour opens or closes (Escape-less — closed via the X button,
|
|
7
17
|
* clicking the scrim, or finishing) — powers v-model
|
|
18
|
+
* @event update:step Emitted when the current step changes (v-model:step)
|
|
8
19
|
* @event finish Emitted when the user completes the last step (clicks the finish button)
|
|
9
20
|
*/
|
|
10
|
-
import { ref, computed, watch, nextTick, onBeforeUnmount } from 'vue'
|
|
21
|
+
import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount } from 'vue'
|
|
11
22
|
import MButton from './MButton.vue'
|
|
12
23
|
import MIcon from './MIcon.vue'
|
|
13
24
|
import { useLocale } from '../composables/useLocale'
|
|
14
25
|
|
|
15
26
|
export interface TourStep {
|
|
16
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The element to highlight and point at: a CSS selector, or a function returning the element (looked up again
|
|
29
|
+
* on every frame in `interactive` mode, so it can change). None, or none found: the tooltip sits in the viewport,
|
|
30
|
+
* on its `placement` side (centered without one)
|
|
31
|
+
*/
|
|
32
|
+
target?: string | (() => Element | null | undefined)
|
|
17
33
|
title: string
|
|
18
34
|
content: string
|
|
19
35
|
placement?: 'top' | 'bottom' | 'left' | 'right'
|
|
@@ -30,16 +46,34 @@ const props = defineProps<{
|
|
|
30
46
|
nextLabel?: string
|
|
31
47
|
/** Label for the final step's button (defaults to the locale string, 'Finish') */
|
|
32
48
|
finishLabel?: string
|
|
49
|
+
/** The current step's index (v-model:step); without it the tour keeps its own */
|
|
50
|
+
step?: number
|
|
51
|
+
/**
|
|
52
|
+
* Leaves the page usable while the tour is open: no scrim, a ring drawn over the target instead of lifting the
|
|
53
|
+
* target itself, tooltip and ring following the target as it moves, no scrolling to it
|
|
54
|
+
*/
|
|
55
|
+
interactive?: boolean
|
|
33
56
|
}>()
|
|
34
57
|
|
|
35
58
|
const locale = useLocale()
|
|
36
59
|
|
|
37
60
|
const emit = defineEmits<{
|
|
38
61
|
'update:modelValue': [boolean]
|
|
62
|
+
'update:step': [number]
|
|
39
63
|
finish: []
|
|
40
64
|
}>()
|
|
41
65
|
|
|
42
|
-
const
|
|
66
|
+
const ownStep = ref(0)
|
|
67
|
+
const currentStep = computed({
|
|
68
|
+
get: () => props.step ?? ownStep.value,
|
|
69
|
+
set: (v: number) => {
|
|
70
|
+
ownStep.value = v
|
|
71
|
+
emit('update:step', v)
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
const tooltipEl = ref<HTMLElement | null>(null)
|
|
75
|
+
/** The ring over the target in interactive mode (fixed, viewport coordinates) */
|
|
76
|
+
const ringStyle = ref<Record<string, string> | null>(null)
|
|
43
77
|
const tooltipStyle = ref<Record<string, string>>({})
|
|
44
78
|
const arrowStyle = ref<Record<string, string>>({})
|
|
45
79
|
const placement = ref<'top' | 'bottom' | 'left' | 'right'>('bottom')
|
|
@@ -49,7 +83,20 @@ const isFirst = computed(() => currentStep.value === 0)
|
|
|
49
83
|
const isLast = computed(() => currentStep.value === props.steps.length - 1)
|
|
50
84
|
|
|
51
85
|
let scrollRaf = 0
|
|
52
|
-
|
|
86
|
+
let followRaf = 0
|
|
87
|
+
|
|
88
|
+
function targetOf(st: TourStep | undefined): HTMLElement | null {
|
|
89
|
+
const t = st?.target
|
|
90
|
+
if (!t) return null
|
|
91
|
+
const el = typeof t === 'string' ? document.querySelector(t) : t()
|
|
92
|
+
// Not laid out (display: none, or a closed panel's leftover): as if there were none
|
|
93
|
+
return el && el.getClientRects().length ? (el as HTMLElement) : null
|
|
94
|
+
}
|
|
95
|
+
const same = (a: Record<string, string> | null, b: Record<string, string> | null) => JSON.stringify(a) === JSON.stringify(b)
|
|
96
|
+
function follow() {
|
|
97
|
+
positionTooltip()
|
|
98
|
+
followRaf = requestAnimationFrame(follow)
|
|
99
|
+
}
|
|
53
100
|
function onScrollOrResize() {
|
|
54
101
|
cancelAnimationFrame(scrollRaf)
|
|
55
102
|
scrollRaf = requestAnimationFrame(positionTooltip)
|
|
@@ -58,27 +105,60 @@ function onScrollOrResize() {
|
|
|
58
105
|
function startListeners() {
|
|
59
106
|
window.addEventListener('scroll', onScrollOrResize, true)
|
|
60
107
|
window.addEventListener('resize', onScrollOrResize)
|
|
108
|
+
if (props.interactive) {
|
|
109
|
+
cancelAnimationFrame(followRaf)
|
|
110
|
+
followRaf = requestAnimationFrame(follow)
|
|
111
|
+
}
|
|
61
112
|
}
|
|
62
113
|
|
|
63
114
|
function stopListeners() {
|
|
64
115
|
window.removeEventListener('scroll', onScrollOrResize, true)
|
|
65
116
|
window.removeEventListener('resize', onScrollOrResize)
|
|
66
117
|
cancelAnimationFrame(scrollRaf)
|
|
118
|
+
cancelAnimationFrame(followRaf)
|
|
119
|
+
ringStyle.value = null
|
|
67
120
|
}
|
|
68
121
|
|
|
69
122
|
function positionTooltip() {
|
|
70
123
|
if (!step.value) return
|
|
71
|
-
const el =
|
|
72
|
-
if (!el) return
|
|
73
|
-
|
|
74
|
-
const rect = el.getBoundingClientRect()
|
|
75
|
-
const pad = 12
|
|
76
|
-
const arrowSize = 8
|
|
124
|
+
const el = targetOf(step.value)
|
|
77
125
|
const vw = window.innerWidth
|
|
78
126
|
const vh = window.innerHeight
|
|
79
127
|
const edge = 8
|
|
80
128
|
const tooltipW = Math.min(320, vw - edge * 2)
|
|
81
|
-
|
|
129
|
+
// Its real height once it's there (a slot can make it any height)
|
|
130
|
+
const approxH = tooltipEl.value?.offsetHeight || 220
|
|
131
|
+
|
|
132
|
+
if (!el) {
|
|
133
|
+
// Nothing to point at: on its side of the viewport, or in the middle
|
|
134
|
+
const side = step.value.placement
|
|
135
|
+
const s: Record<string, string> = { width: `${tooltipW}px` }
|
|
136
|
+
if (side === 'left' || side === 'right') {
|
|
137
|
+
s[side] = `${edge * 2}px`
|
|
138
|
+
s.top = '50%'
|
|
139
|
+
s.transform = 'translateY(-50%)'
|
|
140
|
+
} else {
|
|
141
|
+
s.left = `${(vw - tooltipW) / 2}px`
|
|
142
|
+
if (side === 'top') s.top = `${edge * 2}px`
|
|
143
|
+
else if (side === 'bottom') s.bottom = `${edge * 2}px`
|
|
144
|
+
else {
|
|
145
|
+
s.top = '50%'
|
|
146
|
+
s.transform = 'translateY(-50%)'
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!same(tooltipStyle.value, s)) tooltipStyle.value = s
|
|
150
|
+
if (!same(arrowStyle.value, { display: 'none' })) arrowStyle.value = { display: 'none' }
|
|
151
|
+
if (ringStyle.value) ringStyle.value = null
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const rect = el.getBoundingClientRect()
|
|
156
|
+
const pad = 12
|
|
157
|
+
const arrowSize = 8
|
|
158
|
+
if (props.interactive) {
|
|
159
|
+
const r = { left: `${rect.left - 4}px`, top: `${rect.top - 4}px`, width: `${rect.width + 8}px`, height: `${rect.height + 8}px` }
|
|
160
|
+
if (!same(ringStyle.value, r)) ringStyle.value = r
|
|
161
|
+
}
|
|
82
162
|
|
|
83
163
|
let p = step.value.placement ?? 'bottom'
|
|
84
164
|
|
|
@@ -143,21 +223,20 @@ function positionTooltip() {
|
|
|
143
223
|
}
|
|
144
224
|
}
|
|
145
225
|
|
|
146
|
-
tooltipStyle.value = s
|
|
147
|
-
arrowStyle.value = a
|
|
226
|
+
if (!same(tooltipStyle.value, s)) tooltipStyle.value = s
|
|
227
|
+
if (!same(arrowStyle.value, a)) arrowStyle.value = a
|
|
148
228
|
}
|
|
149
229
|
|
|
150
230
|
function scrollToTarget() {
|
|
151
|
-
if (!step.value) return
|
|
152
|
-
|
|
153
|
-
el?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
|
231
|
+
if (!step.value || props.interactive) return
|
|
232
|
+
targetOf(step.value)?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
|
154
233
|
}
|
|
155
234
|
|
|
156
235
|
function highlightTarget() {
|
|
157
236
|
if (!step.value) return
|
|
158
237
|
document.querySelectorAll('.m3-tour-highlight').forEach((el) => el.classList.remove('m3-tour-highlight'))
|
|
159
|
-
|
|
160
|
-
|
|
238
|
+
if (props.interactive) return
|
|
239
|
+
targetOf(step.value)?.classList.add('m3-tour-highlight')
|
|
161
240
|
}
|
|
162
241
|
|
|
163
242
|
function clearHighlight() {
|
|
@@ -180,11 +259,11 @@ function goPrev() {
|
|
|
180
259
|
function close() {
|
|
181
260
|
stopListeners()
|
|
182
261
|
clearHighlight()
|
|
183
|
-
|
|
262
|
+
if (props.step === undefined) ownStep.value = 0
|
|
184
263
|
emit('update:modelValue', false)
|
|
185
264
|
}
|
|
186
265
|
|
|
187
|
-
|
|
266
|
+
function show() {
|
|
188
267
|
if (props.modelValue) {
|
|
189
268
|
nextTick(() => {
|
|
190
269
|
highlightTarget()
|
|
@@ -192,12 +271,26 @@ watch([() => props.modelValue, currentStep], () => {
|
|
|
192
271
|
positionTooltip()
|
|
193
272
|
})
|
|
194
273
|
}
|
|
195
|
-
}
|
|
274
|
+
}
|
|
275
|
+
watch([() => props.modelValue, currentStep], show)
|
|
196
276
|
|
|
197
277
|
watch(() => props.modelValue, (v) => {
|
|
198
278
|
if (v) startListeners()
|
|
199
279
|
else { stopListeners(); clearHighlight() }
|
|
200
280
|
})
|
|
281
|
+
// Mounted already open: no watcher has run yet
|
|
282
|
+
onMounted(() => {
|
|
283
|
+
if (!props.modelValue) return
|
|
284
|
+
startListeners()
|
|
285
|
+
show()
|
|
286
|
+
})
|
|
287
|
+
watch(() => props.interactive, () => {
|
|
288
|
+
if (props.modelValue) {
|
|
289
|
+
stopListeners()
|
|
290
|
+
startListeners()
|
|
291
|
+
highlightTarget()
|
|
292
|
+
}
|
|
293
|
+
})
|
|
201
294
|
|
|
202
295
|
onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
203
296
|
</script>
|
|
@@ -206,13 +299,19 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
206
299
|
<Teleport to="body">
|
|
207
300
|
<!-- Overlay -->
|
|
208
301
|
<Transition name="m3-tour" appear>
|
|
209
|
-
<div v-if="modelValue && step" class="fixed inset-0 z-200 bg-scrim/32" @click="close" />
|
|
302
|
+
<div v-if="modelValue && step && !interactive" class="fixed inset-0 z-200 bg-scrim/32" @click="close" />
|
|
210
303
|
</Transition>
|
|
211
304
|
|
|
305
|
+
<!-- The target's ring (interactive) -->
|
|
306
|
+
<div v-if="modelValue && step && interactive && ringStyle" class="m3-tour-ring pointer-events-none fixed z-201 rounded-xl" :style="ringStyle" aria-hidden="true" />
|
|
307
|
+
|
|
212
308
|
<!-- Tooltip -->
|
|
213
309
|
<Transition name="m3-tour" appear>
|
|
214
310
|
<div
|
|
215
311
|
v-if="modelValue && step"
|
|
312
|
+
ref="tooltipEl"
|
|
313
|
+
:role="interactive ? 'region' : 'dialog'"
|
|
314
|
+
:aria-label="step.title"
|
|
216
315
|
class="fixed z-202 w-80 max-w-[calc(100vw-1rem)] rounded-xl bg-surface-container-high p-5 shadow-elevation-3"
|
|
217
316
|
:style="tooltipStyle"
|
|
218
317
|
>
|
|
@@ -221,9 +320,11 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
221
320
|
|
|
222
321
|
<!-- Step indicator -->
|
|
223
322
|
<div class="mb-2 flex items-center justify-between">
|
|
224
|
-
<
|
|
225
|
-
|
|
226
|
-
|
|
323
|
+
<slot name="indicator" :index="currentStep" :count="steps.length">
|
|
324
|
+
<span class="text-label-small text-on-surface-variant">
|
|
325
|
+
{{ currentStep + 1 }} / {{ steps.length }}
|
|
326
|
+
</span>
|
|
327
|
+
</slot>
|
|
227
328
|
<button
|
|
228
329
|
:aria-label="locale.close"
|
|
229
330
|
type="button"
|
|
@@ -234,10 +335,13 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
234
335
|
</button>
|
|
235
336
|
</div>
|
|
236
337
|
|
|
237
|
-
<
|
|
238
|
-
|
|
338
|
+
<slot name="content" :step="step" :index="currentStep">
|
|
339
|
+
<h3 class="mb-1 text-title-medium font-medium text-on-surface">{{ step.title }}</h3>
|
|
340
|
+
<p class="mb-4 text-body-medium text-on-surface-variant">{{ step.content }}</p>
|
|
341
|
+
</slot>
|
|
239
342
|
|
|
240
343
|
<!-- Progress dots -->
|
|
344
|
+
<slot name="progress" :index="currentStep" :count="steps.length">
|
|
241
345
|
<div class="mb-4 flex justify-center gap-1.5">
|
|
242
346
|
<div
|
|
243
347
|
v-for="(_, i) in steps"
|
|
@@ -246,8 +350,10 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
246
350
|
:class="i === currentStep ? 'w-6 bg-primary' : 'w-1.5 bg-outline-variant'"
|
|
247
351
|
/>
|
|
248
352
|
</div>
|
|
353
|
+
</slot>
|
|
249
354
|
|
|
250
355
|
<!-- Actions -->
|
|
356
|
+
<slot name="actions" :step="step" :index="currentStep" :is-first="isFirst" :is-last="isLast" :next="goNext" :prev="goPrev" :close="close">
|
|
251
357
|
<div class="flex justify-between">
|
|
252
358
|
<MButton
|
|
253
359
|
v-if="!isFirst"
|
|
@@ -261,6 +367,7 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
261
367
|
{{ isLast ? (finishLabel ?? locale.finish) : (nextLabel ?? locale.next) }}
|
|
262
368
|
</MButton>
|
|
263
369
|
</div>
|
|
370
|
+
</slot>
|
|
264
371
|
</div>
|
|
265
372
|
</Transition>
|
|
266
373
|
</Teleport>
|
|
@@ -274,6 +381,17 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
274
381
|
border-radius: 8px;
|
|
275
382
|
}
|
|
276
383
|
|
|
384
|
+
.m3-tour-ring {
|
|
385
|
+
box-shadow: 0 0 0 3px var(--color-primary), 0 0 0 8px color-mix(in srgb, var(--color-primary) 24%, transparent);
|
|
386
|
+
animation: m3-tour-ring 1.6s ease-in-out infinite;
|
|
387
|
+
}
|
|
388
|
+
@keyframes m3-tour-ring {
|
|
389
|
+
50% { box-shadow: 0 0 0 3px var(--color-primary), 0 0 0 12px color-mix(in srgb, var(--color-primary) 0%, transparent); }
|
|
390
|
+
}
|
|
391
|
+
@media (prefers-reduced-motion: reduce) {
|
|
392
|
+
.m3-tour-ring { animation: none; }
|
|
393
|
+
}
|
|
394
|
+
|
|
277
395
|
.m3-tour-enter-active,
|
|
278
396
|
.m3-tour-leave-active {
|
|
279
397
|
transition: opacity 0.2s ease;
|
|
@@ -80,7 +80,16 @@ export function getBezierPath(p: FlowEdgePathParams & { curvature?: number }): F
|
|
|
80
80
|
type Pt = [number, number]
|
|
81
81
|
|
|
82
82
|
/** The corners of an orthogonal route between the ends, leaving and arriving square to the sides */
|
|
83
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Where a step edge from `sourcePosition` to `targetPosition` turns. `centerX` / `centerY` move its middle run (the
|
|
85
|
+
* one halfway between the ends) off the halfway point, e.g. to keep it off another edge's
|
|
86
|
+
*/
|
|
87
|
+
export interface FlowStepCenter {
|
|
88
|
+
centerX?: number
|
|
89
|
+
centerY?: number
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function smoothStepPoints(p: FlowEdgePathParams & FlowStepCenter & { offset?: number }): Pt[] {
|
|
84
93
|
const { sourceX: sx, sourceY: sy, targetX: tx, targetY: ty } = p
|
|
85
94
|
const sp = p.sourcePosition ?? 'bottom'
|
|
86
95
|
const tp = p.targetPosition ?? 'top'
|
|
@@ -95,7 +104,7 @@ export function smoothStepPoints(p: FlowEdgePathParams & { offset?: number }): P
|
|
|
95
104
|
if (sH && tH) {
|
|
96
105
|
if (nsx === -ntx && (tx - sx) * nsx >= 2 * off) {
|
|
97
106
|
// Facing each other with room: one vertical run halfway
|
|
98
|
-
const mx = (sx + tx) / 2
|
|
107
|
+
const mx = p.centerX ?? (sx + tx) / 2
|
|
99
108
|
mid = [[mx, sy], [mx, ty]]
|
|
100
109
|
} else if (nsx === ntx) {
|
|
101
110
|
// Both sides look the same way: go round past the farther one
|
|
@@ -103,18 +112,18 @@ export function smoothStepPoints(p: FlowEdgePathParams & { offset?: number }): P
|
|
|
103
112
|
mid = [[x, sy], [x, ty]]
|
|
104
113
|
} else {
|
|
105
114
|
// Behind: out, across halfway between the ends, and back in
|
|
106
|
-
const my = (sy + ty) / 2
|
|
115
|
+
const my = p.centerY ?? (sy + ty) / 2
|
|
107
116
|
mid = [s1, [s1[0], my], [t1[0], my], t1]
|
|
108
117
|
}
|
|
109
118
|
} else if (!sH && !tH) {
|
|
110
119
|
if (nsy === -nty && (ty - sy) * nsy >= 2 * off) {
|
|
111
|
-
const my = (sy + ty) / 2
|
|
120
|
+
const my = p.centerY ?? (sy + ty) / 2
|
|
112
121
|
mid = [[sx, my], [tx, my]]
|
|
113
122
|
} else if (nsy === nty) {
|
|
114
123
|
const y = nsy > 0 ? Math.max(s1[1], t1[1]) : Math.min(s1[1], t1[1])
|
|
115
124
|
mid = [[sx, y], [tx, y]]
|
|
116
125
|
} else {
|
|
117
|
-
const mx = (sx + tx) / 2
|
|
126
|
+
const mx = p.centerX ?? (sx + tx) / 2
|
|
118
127
|
mid = [s1, [mx, s1[1]], [mx, t1[1]], t1]
|
|
119
128
|
}
|
|
120
129
|
} else if (sH) {
|
|
@@ -223,7 +232,7 @@ export function getRoutedPath(p: FlowEdgePathParams & { route: number[]; borderR
|
|
|
223
232
|
}
|
|
224
233
|
|
|
225
234
|
/** Right-angled steps with rounded corners (`borderRadius`, default 8; 0 gives sharp steps). `offset` (default 20) is how far it leaves a node before turning */
|
|
226
|
-
export function getSmoothStepPath(p: FlowEdgePathParams & { borderRadius?: number; offset?: number }): FlowEdgePath {
|
|
235
|
+
export function getSmoothStepPath(p: FlowEdgePathParams & FlowStepCenter & { borderRadius?: number; offset?: number }): FlowEdgePath {
|
|
227
236
|
return roundedPath(smoothStepPoints(p), p.borderRadius ?? 8)
|
|
228
237
|
}
|
|
229
238
|
|
|
@@ -292,7 +301,7 @@ export function distanceToPoints(x: number, y: number, pts: [number, number][]):
|
|
|
292
301
|
}
|
|
293
302
|
|
|
294
303
|
/** `getSmoothStepPath` with sharp corners */
|
|
295
|
-
export function getStepPath(p: FlowEdgePathParams & { offset?: number; route?: number[] }): FlowEdgePath {
|
|
304
|
+
export function getStepPath(p: FlowEdgePathParams & FlowStepCenter & { offset?: number; route?: number[] }): FlowEdgePath {
|
|
296
305
|
return p.route ? getRoutedPath({ ...p, route: p.route, borderRadius: 0 }) : getSmoothStepPath({ ...p, borderRadius: 0 })
|
|
297
306
|
}
|
|
298
307
|
|
|
@@ -181,6 +181,8 @@ export interface FlowContext {
|
|
|
181
181
|
* there (as the `branch` event gives). For dropping something onto an edge, e.g. a junction
|
|
182
182
|
*/
|
|
183
183
|
getEdgeAt(p: FlowXY, opts?: { radius?: number; ignore?: (e: FlowEdge) => boolean }): FlowEdgeHit | null
|
|
184
|
+
/** The SVG path (`d`, flow coordinates) an edge is drawn along right now, its own route and edgeSpacing included: to draw it elsewhere, e.g. an exported image */
|
|
185
|
+
getEdgePath(id: string): string | null
|
|
184
186
|
/** Page (client) coordinates → flow coordinates */
|
|
185
187
|
screenToFlow(p: { x: number; y: number }): FlowXY
|
|
186
188
|
flowToScreen(p: FlowXY): { x: number; y: number }
|
|
@@ -210,6 +212,8 @@ export interface FlowContext {
|
|
|
210
212
|
cut(): void
|
|
211
213
|
/** Pastes what was copied, at a flow point (default a step from the originals) */
|
|
212
214
|
paste(at?: FlowXY): void
|
|
215
|
+
/** Copies of the selection (with the edges between them) a step away, selected; the clipboard stays as it was */
|
|
216
|
+
duplicate(): void
|
|
213
217
|
/**
|
|
214
218
|
* Drags a node with a pointer that's already down, e.g. one just added from a palette outside the canvas: it
|
|
215
219
|
* follows the pointer from there (guides, splicing into an edge) until it's let go. With a finger, the page
|
package/src/flow.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type {
|
|
|
19
19
|
FlowXY,
|
|
20
20
|
} from './composables/useFlow'
|
|
21
21
|
export { getBezierPath, getSmoothStepPath, getStepPath, getStraightPath, smoothStepPoints, routePoints, pointsToRoute, getRoutedPath, arrowPath } from './composables/flowPaths'
|
|
22
|
-
export type { FlowEdgePath, FlowEdgePathParams, FlowPosition } from './composables/flowPaths'
|
|
22
|
+
export type { FlowEdgePath, FlowEdgePathParams, FlowPosition, FlowStepCenter } from './composables/flowPaths'
|
|
23
23
|
export { layoutTree, layoutLayered } from './composables/flowLayout'
|
|
24
24
|
export type { FlowLayout, FlowLayoutDirection, FlowLayoutOptions, FlowLayoutResult } from './composables/flowLayout'
|
|
25
25
|
export type { FlowPanelPosition } from './composables/_flowPanel'
|