@getcortexlabs/mavis-web 0.1.0-rc.13 → 0.1.0-rc.15
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/README.md +4 -4
- package/dist/component-motion.d.ts.map +1 -1
- package/dist/component-motion.js +16 -0
- package/dist/component-motion.js.map +1 -1
- package/dist/components/ChartPlot.d.ts +8 -0
- package/dist/components/ChartPlot.d.ts.map +1 -1
- package/dist/components/ChartPlot.js +21 -1
- package/dist/components/ChartPlot.js.map +1 -1
- package/dist/components/DateCalendar.d.ts +1 -1
- package/dist/components/DateCalendar.d.ts.map +1 -1
- package/dist/components/DateCalendar.js +3 -1
- package/dist/components/DateCalendar.js.map +1 -1
- package/dist/components/MButton.d.ts +7 -7
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +59 -19
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MChip.d.ts +1 -1
- package/dist/components/MDatePicker.d.ts +96 -96
- package/dist/components/MDatePicker.d.ts.map +1 -1
- package/dist/components/MEmptyState.d.ts +1 -1
- package/dist/components/MInput.d.ts +9 -9
- package/dist/components/MLink.d.ts +1 -1
- package/dist/components/MPopover.d.ts +1 -1
- package/dist/components/MProgress.d.ts +1 -1
- package/dist/components/MRangeSlider.d.ts +2 -2
- package/dist/components/MResizablePanels.d.ts +2 -2
- package/dist/components/MReveal.d.ts +10 -10
- package/dist/components/MSheet.d.ts +5 -5
- package/dist/components/MSlider.d.ts +2 -2
- package/dist/components/MStack.d.ts +10 -10
- package/dist/components/MTimePicker.d.ts +40 -40
- package/dist/components/MTimePicker.d.ts.map +1 -1
- package/dist/components/MTooltip.d.ts +1 -1
- package/dist/components/MVirtualList.d.ts.map +1 -1
- package/dist/components/MVirtualList.js +111 -40
- package/dist/components/MVirtualList.js.map +1 -1
- package/dist/components/advanced.d.ts +34 -34
- package/dist/components/configurator.d.ts +33 -33
- package/dist/components/creative.d.ts +20 -20
- package/dist/components/dashboard.d.ts +12 -12
- package/dist/components/dashboard.d.ts.map +1 -1
- package/dist/components/dashboard.js +153 -76
- package/dist/components/dashboard.js.map +1 -1
- package/dist/components/discovery.d.ts +10 -10
- package/dist/components/interactive.d.ts +6 -6
- package/dist/components/layout.d.ts +30 -30
- package/dist/components/navigation.d.ts +4 -4
- package/dist/components/screen-components.d.ts +23 -23
- package/dist/components/screen-components.d.ts.map +1 -1
- package/dist/components/wayfinding.d.ts +11 -11
- package/dist/components/workflows.d.ts +5 -5
- package/dist/motion-region.d.ts.map +1 -1
- package/dist/motion-region.js +1 -0
- package/dist/motion-region.js.map +1 -1
- package/dist/motion-surface.d.ts +6 -1
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +77 -14
- package/dist/motion-surface.js.map +1 -1
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +8 -3
- package/dist/motion.js.map +1 -1
- package/dist/pointer-availability.d.ts +6 -0
- package/dist/pointer-availability.d.ts.map +1 -0
- package/dist/pointer-availability.js +49 -0
- package/dist/pointer-availability.js.map +1 -0
- package/dist/scroll-motion.d.ts.map +1 -1
- package/dist/scroll-motion.js +19 -6
- package/dist/scroll-motion.js.map +1 -1
- package/dist/section-scroll.d.ts +2 -1
- package/dist/section-scroll.d.ts.map +1 -1
- package/dist/section-scroll.js +43 -12
- package/dist/section-scroll.js.map +1 -1
- package/package.json +3 -3
- package/src/base.css +43 -1
- package/src/component-motion.ts +15 -0
- package/src/components/ChartPlot.ts +21 -1
- package/src/components/DateCalendar.ts +3 -1
- package/src/components/MCard.ts +71 -17
- package/src/components/MVirtualList.ts +107 -29
- package/src/components/dashboard.ts +149 -75
- package/src/motion-region.ts +1 -0
- package/src/motion-surface.ts +87 -16
- package/src/motion.ts +16 -5
- package/src/pointer-availability.ts +54 -0
- package/src/scroll-motion.ts +17 -6
- package/src/section-scroll.ts +38 -12
package/src/components/MCard.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { resolveSpace, resolveRadius, shadowStyle } from '@getcortexlabs/mavis-core'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
defineComponent,
|
|
4
|
+
getCurrentInstance,
|
|
5
|
+
h,
|
|
6
|
+
mergeProps,
|
|
7
|
+
shallowRef,
|
|
8
|
+
useId,
|
|
9
|
+
type VNode,
|
|
10
|
+
} from 'vue'
|
|
3
11
|
import { preserveBoundPaint } from '../motion-surface.js'
|
|
4
12
|
import {
|
|
5
13
|
useButtonAction,
|
|
@@ -14,6 +22,26 @@ import { usePressFeedback } from '../motion.js'
|
|
|
14
22
|
|
|
15
23
|
const LinkColumn = createLayout('MCardLink', 'column', 'a')
|
|
16
24
|
|
|
25
|
+
/** A control owns clicks from its descendants; the surrounding card owns the remaining surface. */
|
|
26
|
+
function ownsClick(event?: MouseEvent) {
|
|
27
|
+
if (!event) return true
|
|
28
|
+
if (event.defaultPrevented) return false
|
|
29
|
+
const element = event.currentTarget as HTMLElement | null
|
|
30
|
+
const Element = element?.ownerDocument.defaultView?.Element
|
|
31
|
+
if (!element || !Element) return event.target === event.currentTarget
|
|
32
|
+
for (const node of event.composedPath()) {
|
|
33
|
+
if (node === element) return true
|
|
34
|
+
if (
|
|
35
|
+
node instanceof Element &&
|
|
36
|
+
node.matches(
|
|
37
|
+
'button, a[href], input, select, textarea, label, [contenteditable]:not([contenteditable="false"]), [tabindex], [role="button"], [role="checkbox"], [role="radio"], [role="switch"], [role="slider"], [role="tab"], [role="combobox"]',
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
|
|
17
45
|
export const MCard = defineComponent({
|
|
18
46
|
name: 'MCard',
|
|
19
47
|
inheritAttrs: false,
|
|
@@ -24,6 +52,7 @@ export const MCard = defineComponent({
|
|
|
24
52
|
const { theme } = useMavisTheme()
|
|
25
53
|
const navigation = useNavigationOptions(props)
|
|
26
54
|
const instance = getCurrentInstance()
|
|
55
|
+
const contentId = `m-card-content-${useId()}`
|
|
27
56
|
const element = shallowRef<HTMLElement>()
|
|
28
57
|
const lifecycle = usePressFeedback(
|
|
29
58
|
() => (props.interactive || props.href !== undefined) && !props.disabled,
|
|
@@ -46,6 +75,10 @@ export const MCard = defineComponent({
|
|
|
46
75
|
rel,
|
|
47
76
|
...layout
|
|
48
77
|
} = props
|
|
78
|
+
const separateAction = interactive && href === undefined
|
|
79
|
+
const { 'aria-label': explicitLabel, ...cardAttrs } = attrs
|
|
80
|
+
const label = props.accessibilityLabel ?? (explicitLabel as string | undefined)
|
|
81
|
+
if (separateAction) layout.accessibilityLabel = undefined
|
|
49
82
|
const tokens = theme.value.components.card
|
|
50
83
|
const shadow = `var(--m-card-shadow, ${shadowStyle(theme.value.elevation[elevation ?? tokens.elevation])})`
|
|
51
84
|
layout.padding ??= tokens.padding
|
|
@@ -57,7 +90,10 @@ export const MCard = defineComponent({
|
|
|
57
90
|
layout,
|
|
58
91
|
{
|
|
59
92
|
class: 'm-card',
|
|
93
|
+
'data-m-card-interactive': separateAction || undefined,
|
|
60
94
|
style: {
|
|
95
|
+
position: 'relative',
|
|
96
|
+
isolation: 'isolate',
|
|
61
97
|
paddingLeft:
|
|
62
98
|
props.paddingX !== undefined || props.padding !== undefined
|
|
63
99
|
? `${resolveSpace(theme.value, props.paddingX ?? props.padding!)}px`
|
|
@@ -88,7 +124,7 @@ export const MCard = defineComponent({
|
|
|
88
124
|
color: 'inherit',
|
|
89
125
|
},
|
|
90
126
|
},
|
|
91
|
-
attrs,
|
|
127
|
+
separateAction ? cardAttrs : attrs,
|
|
92
128
|
{
|
|
93
129
|
onVnodeMounted: (node: VNode) => {
|
|
94
130
|
element.value = node.el as HTMLElement
|
|
@@ -99,20 +135,8 @@ export const MCard = defineComponent({
|
|
|
99
135
|
? navigationAttrs(navigation(), disabled, activate, (error) => emit('error', error))
|
|
100
136
|
: interactive
|
|
101
137
|
? {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
'aria-disabled': disabled || undefined,
|
|
105
|
-
onClick: activate,
|
|
106
|
-
onKeydown: (event: KeyboardEvent) => {
|
|
107
|
-
if (event.target !== event.currentTarget) return
|
|
108
|
-
if (event.key === 'Enter' || event.key === ' ') event.preventDefault()
|
|
109
|
-
if (event.key === 'Enter' && !event.repeat) activate()
|
|
110
|
-
},
|
|
111
|
-
onKeyup: (event: KeyboardEvent) => {
|
|
112
|
-
if (event.target === event.currentTarget && event.key === ' ') {
|
|
113
|
-
event.preventDefault()
|
|
114
|
-
activate()
|
|
115
|
-
}
|
|
138
|
+
onClick: (event: MouseEvent) => {
|
|
139
|
+
if (ownsClick(event)) activate()
|
|
116
140
|
},
|
|
117
141
|
}
|
|
118
142
|
: // A labelled card with no action wired is read as one element, as on native.
|
|
@@ -122,7 +146,37 @@ export const MCard = defineComponent({
|
|
|
122
146
|
? { role: 'img' }
|
|
123
147
|
: {},
|
|
124
148
|
),
|
|
125
|
-
|
|
149
|
+
href !== undefined
|
|
150
|
+
? slots
|
|
151
|
+
: {
|
|
152
|
+
...slots,
|
|
153
|
+
default: () => [
|
|
154
|
+
separateAction
|
|
155
|
+
? h('button', {
|
|
156
|
+
key: 'action',
|
|
157
|
+
class: 'm-card-action',
|
|
158
|
+
type: 'button',
|
|
159
|
+
role: 'button',
|
|
160
|
+
tabindex: disabled ? -1 : 0,
|
|
161
|
+
disabled,
|
|
162
|
+
'aria-disabled': disabled || undefined,
|
|
163
|
+
'aria-label': label,
|
|
164
|
+
'aria-labelledby': label ? undefined : contentId,
|
|
165
|
+
onClick: activate,
|
|
166
|
+
})
|
|
167
|
+
: null,
|
|
168
|
+
h(
|
|
169
|
+
'div',
|
|
170
|
+
{
|
|
171
|
+
key: 'content',
|
|
172
|
+
id: contentId,
|
|
173
|
+
class: 'm-card-content',
|
|
174
|
+
style: { display: 'contents' },
|
|
175
|
+
},
|
|
176
|
+
slots.default?.(),
|
|
177
|
+
),
|
|
178
|
+
],
|
|
179
|
+
},
|
|
126
180
|
)
|
|
127
181
|
}
|
|
128
182
|
},
|
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
2
|
+
import { useMotionContext } from '../motion-context.js'
|
|
3
|
+
import { useConnectedMotion } from '../connected-motion.js'
|
|
4
|
+
import type { ListChanges } from '@rafaelaugusto/jolt/web'
|
|
3
5
|
import type { VirtualListComponent } from '@getcortexlabs/mavis-core/vue'
|
|
4
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
computed,
|
|
8
|
+
defineComponent,
|
|
9
|
+
getCurrentInstance,
|
|
10
|
+
h,
|
|
11
|
+
mergeProps,
|
|
12
|
+
nextTick,
|
|
13
|
+
onMounted,
|
|
14
|
+
ref,
|
|
15
|
+
shallowRef,
|
|
16
|
+
watch,
|
|
17
|
+
} from 'vue'
|
|
5
18
|
import { virtualListProps } from '@getcortexlabs/mavis-core/vue'
|
|
6
19
|
import {
|
|
7
20
|
choiceKey,
|
|
21
|
+
componentMotion,
|
|
22
|
+
virtualAnchor,
|
|
8
23
|
virtualKeys,
|
|
9
24
|
virtualWindow,
|
|
10
25
|
type VirtualListHandle,
|
|
@@ -16,16 +31,19 @@ const VirtualList = defineComponent({
|
|
|
16
31
|
inheritAttrs: false,
|
|
17
32
|
props: virtualListProps,
|
|
18
33
|
setup(props, { attrs, slots, expose }) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
34
|
+
const instance = getCurrentInstance()!
|
|
35
|
+
const { theme } = useMavisTheme()
|
|
36
|
+
const rendered = shallowRef<readonly unknown[]>([...props.items])
|
|
37
|
+
const keys = computed(() => virtualKeys(rendered.value, props.itemKey))
|
|
23
38
|
const root = ref<HTMLElement>()
|
|
39
|
+
let controller: ListChanges<unknown> | undefined
|
|
40
|
+
let notifyRecycling: ((target: HTMLElement) => void) | undefined
|
|
41
|
+
const rowElements = new Map<string, HTMLElement>()
|
|
24
42
|
const offset = ref(props.initialIndex * props.rowHeight)
|
|
25
43
|
const focusedKey = ref<string>()
|
|
26
44
|
const window = computed(() =>
|
|
27
45
|
virtualWindow(
|
|
28
|
-
|
|
46
|
+
rendered.value.length,
|
|
29
47
|
props.rowHeight,
|
|
30
48
|
props.height,
|
|
31
49
|
offset.value,
|
|
@@ -36,32 +54,82 @@ const VirtualList = defineComponent({
|
|
|
36
54
|
offset.value = window.value.scrollTop
|
|
37
55
|
if (root.value) root.value.scrollTop = offset.value
|
|
38
56
|
}
|
|
57
|
+
function commit(items: readonly unknown[]) {
|
|
58
|
+
const next = virtualKeys(items, props.itemKey)
|
|
59
|
+
const anchored = virtualAnchor(keys.value, next, props.rowHeight, props.height, offset.value)
|
|
60
|
+
// Reconcile the window and its anchor together. A shorter spacer can make
|
|
61
|
+
// the browser clamp scrollTop and dispatch scroll before Jolt's deferred
|
|
62
|
+
// layout pass; that event would cancel the pending anchor restoration.
|
|
63
|
+
rendered.value = [...items]
|
|
64
|
+
offset.value = anchored
|
|
65
|
+
instance.update()
|
|
66
|
+
syncOffset()
|
|
67
|
+
}
|
|
68
|
+
useConnectedMotion(root, useMotionContext(), (runtime, target) => {
|
|
69
|
+
const owned = runtime.listChanges(target, {
|
|
70
|
+
key: (item) => choiceKey(virtualKeys([item], props.itemKey)[0]!),
|
|
71
|
+
move: componentMotion(theme.value, 'layout'),
|
|
72
|
+
enter: true,
|
|
73
|
+
exit: 'fadeOut',
|
|
74
|
+
adapter: {
|
|
75
|
+
virtualized: true,
|
|
76
|
+
items: () => rendered.value,
|
|
77
|
+
render: commit,
|
|
78
|
+
rows: () => [...rowElements].map(([key, target]) => ({ key, target })),
|
|
79
|
+
anchor: (previous) => {
|
|
80
|
+
const before = offset.value
|
|
81
|
+
return (next) => {
|
|
82
|
+
offset.value = virtualAnchor(previous, next, props.rowHeight, props.height, before)
|
|
83
|
+
instance.update()
|
|
84
|
+
syncOffset()
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
observeRecycling: (notify) => {
|
|
88
|
+
notifyRecycling = notify
|
|
89
|
+
return () => {
|
|
90
|
+
notifyRecycling = undefined
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
controller = owned
|
|
96
|
+
if (!props.animated) owned.pause()
|
|
97
|
+
return () => {
|
|
98
|
+
owned.dispose()
|
|
99
|
+
if (controller === owned) controller = undefined
|
|
100
|
+
}
|
|
101
|
+
})
|
|
39
102
|
watch(
|
|
40
|
-
|
|
41
|
-
(
|
|
42
|
-
const
|
|
43
|
-
const anchor = previous[index]
|
|
44
|
-
const newIndex = anchor === undefined ? -1 : next.indexOf(anchor)
|
|
45
|
-
if (newIndex >= 0)
|
|
46
|
-
offset.value = newIndex * props.rowHeight + (offset.value % props.rowHeight)
|
|
103
|
+
() => props.items.map((item) => ({ item, key: virtualKeys([item], props.itemKey)[0]! })),
|
|
104
|
+
() => {
|
|
105
|
+
const next = virtualKeys(props.items, props.itemKey)
|
|
47
106
|
if (focusedKey.value && !next.some((key) => choiceKey(key) === focusedKey.value)) {
|
|
48
107
|
if (root.value?.contains(document.activeElement))
|
|
49
108
|
root.value.focus({ preventScroll: true })
|
|
50
109
|
focusedKey.value = undefined
|
|
51
110
|
}
|
|
52
|
-
|
|
111
|
+
if (controller && !controller.disposed) controller.update([...props.items])
|
|
112
|
+
else commit(props.items)
|
|
53
113
|
},
|
|
54
114
|
{ flush: 'pre' },
|
|
55
115
|
)
|
|
116
|
+
watch(
|
|
117
|
+
() => props.animated,
|
|
118
|
+
(enabled) => (enabled ? controller?.play() : controller?.pause()),
|
|
119
|
+
)
|
|
56
120
|
watch(
|
|
57
121
|
() => [props.rowHeight, props.height],
|
|
58
|
-
() =>
|
|
122
|
+
() => {
|
|
123
|
+
controller?.stop()
|
|
124
|
+
void nextTick(syncOffset)
|
|
125
|
+
},
|
|
59
126
|
)
|
|
60
127
|
onMounted(syncOffset)
|
|
61
128
|
expose({
|
|
62
129
|
scrollToIndex(index: number) {
|
|
63
130
|
if (!Number.isInteger(index) || index < 0 || index >= props.items.length)
|
|
64
131
|
throw new RangeError('List index is out of range.')
|
|
132
|
+
controller?.stop()
|
|
65
133
|
offset.value = index * props.rowHeight
|
|
66
134
|
syncOffset()
|
|
67
135
|
},
|
|
@@ -95,7 +163,9 @@ const VirtualList = defineComponent({
|
|
|
95
163
|
flexShrink: 0,
|
|
96
164
|
},
|
|
97
165
|
onScroll: () => {
|
|
98
|
-
|
|
166
|
+
const next = root.value?.scrollTop ?? 0
|
|
167
|
+
if (next !== offset.value) controller?.stop()
|
|
168
|
+
offset.value = next
|
|
99
169
|
},
|
|
100
170
|
onFocusin: (event: FocusEvent) => {
|
|
101
171
|
focusedKey.value = (event.target as HTMLElement).closest<HTMLElement>(
|
|
@@ -107,26 +177,34 @@ const VirtualList = defineComponent({
|
|
|
107
177
|
if (!root.value?.contains(document.activeElement)) focusedKey.value = undefined
|
|
108
178
|
}),
|
|
109
179
|
}),
|
|
110
|
-
|
|
180
|
+
rendered.value.length
|
|
111
181
|
? [
|
|
112
182
|
h(
|
|
113
183
|
'div',
|
|
114
184
|
{
|
|
115
|
-
...motion,
|
|
116
185
|
role: 'list',
|
|
117
186
|
style: { height: `${state.totalHeight}px`, position: 'relative' },
|
|
118
187
|
},
|
|
119
188
|
[...indices]
|
|
120
189
|
.sort((a, b) => a - b)
|
|
121
|
-
.map((index) =>
|
|
122
|
-
|
|
190
|
+
.map((index) => {
|
|
191
|
+
const itemKey = keys.value[index]!
|
|
192
|
+
const key = choiceKey(itemKey)
|
|
193
|
+
return h(
|
|
123
194
|
'div',
|
|
124
195
|
{
|
|
125
|
-
key
|
|
196
|
+
key,
|
|
197
|
+
ref: (element: unknown) => {
|
|
198
|
+
if (element instanceof HTMLElement) rowElements.set(key, element)
|
|
199
|
+
else rowElements.delete(key)
|
|
200
|
+
},
|
|
201
|
+
onVnodeBeforeUnmount: (node: { el?: unknown }) => {
|
|
202
|
+
if (node.el instanceof HTMLElement) notifyRecycling?.(node.el)
|
|
203
|
+
},
|
|
126
204
|
role: 'listitem',
|
|
127
|
-
'data-m-list-key':
|
|
205
|
+
'data-m-list-key': key,
|
|
128
206
|
'aria-posinset': index + 1,
|
|
129
|
-
'aria-setsize':
|
|
207
|
+
'aria-setsize': rendered.value.length,
|
|
130
208
|
style: {
|
|
131
209
|
position: 'absolute',
|
|
132
210
|
top: `${index * props.rowHeight}px`,
|
|
@@ -138,12 +216,12 @@ const VirtualList = defineComponent({
|
|
|
138
216
|
},
|
|
139
217
|
},
|
|
140
218
|
slots.default?.({
|
|
141
|
-
item:
|
|
219
|
+
item: rendered.value[index],
|
|
142
220
|
index,
|
|
143
|
-
itemKey
|
|
221
|
+
itemKey,
|
|
144
222
|
}),
|
|
145
|
-
)
|
|
146
|
-
),
|
|
223
|
+
)
|
|
224
|
+
}),
|
|
147
225
|
),
|
|
148
226
|
]
|
|
149
227
|
: (slots.empty?.() ?? [h(MText, { text: props.emptyLabel, tone: 'muted' })]),
|
|
@@ -24,10 +24,13 @@ import {
|
|
|
24
24
|
kanbanRegistryKey,
|
|
25
25
|
kanbanZoneProps,
|
|
26
26
|
kanbanDragProps,
|
|
27
|
+
type KanbanRegistry,
|
|
27
28
|
} from '@getcortexlabs/mavis-core/vue'
|
|
29
|
+
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
28
30
|
import { createMotionSurface } from '@getcortexlabs/mavis-core/experimental'
|
|
29
31
|
import { MBox, MColumn, MRow } from './layout.js'
|
|
30
32
|
import { useMotionContext } from '../motion-context.js'
|
|
33
|
+
import { useConnectedMotion } from '../connected-motion.js'
|
|
31
34
|
import { followReducedMotion } from '../reduced-motion.js'
|
|
32
35
|
import { MStack } from './MStack.js'
|
|
33
36
|
import { MText } from './MText.js'
|
|
@@ -126,14 +129,24 @@ const Zone = defineComponent({
|
|
|
126
129
|
inheritAttrs: false,
|
|
127
130
|
props: kanbanZoneProps,
|
|
128
131
|
setup(props, { attrs, slots }) {
|
|
129
|
-
const registry = inject(kanbanRegistryKey)
|
|
132
|
+
const registry = inject(kanbanRegistryKey)! as KanbanRegistry<HTMLElement>,
|
|
130
133
|
root = ref<HTMLElement>()
|
|
131
|
-
onMounted(() =>
|
|
132
|
-
|
|
134
|
+
onMounted(() => {
|
|
135
|
+
registry.zones.set(props.column, root.value!)
|
|
136
|
+
registry.revision.value++
|
|
137
|
+
})
|
|
138
|
+
onBeforeUnmount(() => {
|
|
139
|
+
registry.zones.delete(props.column)
|
|
140
|
+
registry.revision.value++
|
|
141
|
+
})
|
|
133
142
|
return () =>
|
|
134
143
|
h(
|
|
135
144
|
'div',
|
|
136
|
-
mergeProps(attrs, {
|
|
145
|
+
mergeProps(attrs, {
|
|
146
|
+
ref: root,
|
|
147
|
+
'data-kanban-column': props.column,
|
|
148
|
+
style: { position: 'relative', zIndex: props.raised ? 20 : undefined },
|
|
149
|
+
}),
|
|
137
150
|
slots.default?.(),
|
|
138
151
|
)
|
|
139
152
|
},
|
|
@@ -142,38 +155,123 @@ const Drag = defineComponent({
|
|
|
142
155
|
inheritAttrs: false,
|
|
143
156
|
props: kanbanDragProps,
|
|
144
157
|
setup(props, { attrs, slots }) {
|
|
145
|
-
const registry = inject(kanbanRegistryKey)
|
|
158
|
+
const registry = inject(kanbanRegistryKey)! as KanbanRegistry<HTMLElement>,
|
|
146
159
|
root = ref<HTMLElement>(),
|
|
147
160
|
surface = markRaw(createMotionSurface()),
|
|
148
161
|
dragging = ref(false)
|
|
149
|
-
let
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
startY = 0,
|
|
153
|
-
handle: HTMLElement | undefined
|
|
154
|
-
function end(commit = false) {
|
|
155
|
-
const was = dragging.value
|
|
156
|
-
dragging.value = false
|
|
157
|
-
const id = pointer
|
|
158
|
-
pointer = undefined
|
|
159
|
-
if (id !== undefined && handle?.hasPointerCapture(id)) handle.releasePointerCapture(id)
|
|
160
|
-
window.removeEventListener('keydown', escape)
|
|
161
|
-
window.removeEventListener('scroll', cancel, true)
|
|
162
|
-
window.removeEventListener('resize', cancel)
|
|
163
|
-
if (surface.available) {
|
|
164
|
-
if (props.animated && !commit)
|
|
165
|
-
surface.animate({ x: 0, y: 0, scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
|
|
166
|
-
else surface.set({ x: 0, y: 0, scale: 1 })
|
|
167
|
-
}
|
|
168
|
-
if (was) registry.finish(commit)
|
|
169
|
-
}
|
|
170
|
-
const cancel = () => end(false)
|
|
162
|
+
let runtime: WebRuntime | undefined,
|
|
163
|
+
zones: ReturnType<WebRuntime['dropZones']> | undefined,
|
|
164
|
+
live = false
|
|
171
165
|
const escape = (e: KeyboardEvent) => {
|
|
172
166
|
if (e.key === 'Escape') {
|
|
173
167
|
e.preventDefault()
|
|
174
168
|
cancel()
|
|
175
169
|
}
|
|
176
170
|
}
|
|
171
|
+
// Jolt cancels on these and leaves the card where it was; the board brings it back.
|
|
172
|
+
const interrupted = () => {
|
|
173
|
+
if (live) cancel()
|
|
174
|
+
}
|
|
175
|
+
function watchInput(on: boolean) {
|
|
176
|
+
const listen = on ? 'addEventListener' : 'removeEventListener'
|
|
177
|
+
window[listen]('keydown', escape as EventListener)
|
|
178
|
+
window[listen]('blur', interrupted)
|
|
179
|
+
window[listen]('resize', interrupted)
|
|
180
|
+
window[listen]('scroll', interrupted, true)
|
|
181
|
+
document[listen]('visibilitychange', interrupted)
|
|
182
|
+
}
|
|
183
|
+
function settle() {
|
|
184
|
+
if (live) watchInput(false)
|
|
185
|
+
live = false
|
|
186
|
+
dragging.value = false
|
|
187
|
+
}
|
|
188
|
+
function rest(animated: boolean) {
|
|
189
|
+
if (!surface.available) return
|
|
190
|
+
if (animated && props.animated)
|
|
191
|
+
surface.animate({ x: 0, y: 0, scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
|
|
192
|
+
else surface.set({ x: 0, y: 0, scale: 1 })
|
|
193
|
+
}
|
|
194
|
+
function cancel() {
|
|
195
|
+
end(true)
|
|
196
|
+
}
|
|
197
|
+
function cancelImmediately() {
|
|
198
|
+
end(false)
|
|
199
|
+
}
|
|
200
|
+
function end(animated: boolean) {
|
|
201
|
+
const was = live
|
|
202
|
+
settle()
|
|
203
|
+
zones?.cancel()
|
|
204
|
+
if (!was) return
|
|
205
|
+
rest(animated)
|
|
206
|
+
registry.finish(props.cardId)
|
|
207
|
+
}
|
|
208
|
+
function release() {
|
|
209
|
+
zones?.dispose()
|
|
210
|
+
zones = undefined
|
|
211
|
+
}
|
|
212
|
+
// Jolt refuses a drag under a transformed ancestor, so each contact gets fresh drop zones,
|
|
213
|
+
// after ending the layout motion that may still be moving the card's column.
|
|
214
|
+
function attach(handle: HTMLElement) {
|
|
215
|
+
if (live) return
|
|
216
|
+
release()
|
|
217
|
+
const source = root.value?.firstElementChild
|
|
218
|
+
if (!runtime || !(source instanceof HTMLElement)) return
|
|
219
|
+
for (let node = source.parentElement; node?.parentElement; node = node.parentElement) {
|
|
220
|
+
if (!new DOMMatrixReadOnly(getComputedStyle(node).transform).isIdentity)
|
|
221
|
+
runtime.animateLayout(node.parentElement).stop()
|
|
222
|
+
if (node.classList.contains('m-kanban')) break
|
|
223
|
+
}
|
|
224
|
+
const targets = registry.targets(props.cardId)
|
|
225
|
+
if (!targets.length) return
|
|
226
|
+
try {
|
|
227
|
+
zones = runtime.dropZones(source, {
|
|
228
|
+
targets,
|
|
229
|
+
drag: { handle, snap: [0] },
|
|
230
|
+
onMove({ id, bounds }) {
|
|
231
|
+
if (!live) {
|
|
232
|
+
if (!registry.begin(props.cardId, cancel)) {
|
|
233
|
+
zones?.cancel()
|
|
234
|
+
return
|
|
235
|
+
}
|
|
236
|
+
live = true
|
|
237
|
+
dragging.value = true
|
|
238
|
+
watchInput(true)
|
|
239
|
+
if (surface.available) surface.set({ scale: 1.02 })
|
|
240
|
+
}
|
|
241
|
+
registry.move(id, bounds)
|
|
242
|
+
},
|
|
243
|
+
onLeave: () => registry.leave(),
|
|
244
|
+
onDrop() {
|
|
245
|
+
settle()
|
|
246
|
+
rest(false)
|
|
247
|
+
registry.drop()
|
|
248
|
+
},
|
|
249
|
+
onReject() {
|
|
250
|
+
settle()
|
|
251
|
+
registry.finish(props.cardId)
|
|
252
|
+
if (!surface.available) return
|
|
253
|
+
if (props.animated)
|
|
254
|
+
surface.animate({ scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
|
|
255
|
+
// Jolt starts its return after this callback; without motion the card goes back at once.
|
|
256
|
+
else
|
|
257
|
+
queueMicrotask(() => {
|
|
258
|
+
zones?.cancel()
|
|
259
|
+
rest(false)
|
|
260
|
+
})
|
|
261
|
+
},
|
|
262
|
+
})
|
|
263
|
+
} catch {
|
|
264
|
+
zones = undefined
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
useConnectedMotion(root, useMotionContext(), (owner) => {
|
|
268
|
+
runtime = owner
|
|
269
|
+
return () => {
|
|
270
|
+
cancelImmediately()
|
|
271
|
+
release()
|
|
272
|
+
runtime = undefined
|
|
273
|
+
}
|
|
274
|
+
})
|
|
177
275
|
onMounted(() => {
|
|
178
276
|
registry.cards.set(props.cardId, () => root.value?.getBoundingClientRect())
|
|
179
277
|
registry.focus.set(props.cardId, () =>
|
|
@@ -183,20 +281,23 @@ const Drag = defineComponent({
|
|
|
183
281
|
)
|
|
184
282
|
})
|
|
185
283
|
onBeforeUnmount(() => {
|
|
186
|
-
|
|
284
|
+
cancelImmediately()
|
|
187
285
|
registry.cards.delete(props.cardId)
|
|
188
286
|
registry.focus.delete(props.cardId)
|
|
189
287
|
})
|
|
190
|
-
onDeactivated(
|
|
288
|
+
onDeactivated(cancelImmediately)
|
|
191
289
|
onScopeDispose(
|
|
192
|
-
surface.use(() =>
|
|
193
|
-
|
|
290
|
+
surface.use(() => {
|
|
291
|
+
rest(false)
|
|
292
|
+
return cancelImmediately
|
|
194
293
|
}),
|
|
195
294
|
)
|
|
196
295
|
watch(
|
|
197
296
|
() => props.disabled,
|
|
198
297
|
(value) => {
|
|
199
|
-
if (value)
|
|
298
|
+
if (!value) return
|
|
299
|
+
cancel()
|
|
300
|
+
release()
|
|
200
301
|
},
|
|
201
302
|
)
|
|
202
303
|
return () =>
|
|
@@ -206,6 +307,19 @@ const Drag = defineComponent({
|
|
|
206
307
|
ref: root,
|
|
207
308
|
'data-kanban-card': props.cardId,
|
|
208
309
|
style: { position: 'relative', zIndex: dragging.value ? 20 : undefined },
|
|
310
|
+
onPointerdownCapture: (e: PointerEvent) => {
|
|
311
|
+
const handle =
|
|
312
|
+
e.target instanceof Element ? e.target.closest('[data-kanban-handle]') : null
|
|
313
|
+
if (
|
|
314
|
+
!(handle instanceof HTMLElement) ||
|
|
315
|
+
props.disabled ||
|
|
316
|
+
e.button !== 0 ||
|
|
317
|
+
!e.isPrimary
|
|
318
|
+
)
|
|
319
|
+
return
|
|
320
|
+
handle.focus({ preventScroll: true })
|
|
321
|
+
attach(handle)
|
|
322
|
+
},
|
|
209
323
|
}),
|
|
210
324
|
[
|
|
211
325
|
h(MBox, { motionSurface: surface }, () =>
|
|
@@ -228,49 +342,9 @@ const Drag = defineComponent({
|
|
|
228
342
|
border: '0',
|
|
229
343
|
opacity: props.disabled ? 0.4 : 0.65,
|
|
230
344
|
},
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
e.preventDefault()
|
|
235
|
-
handle = e.currentTarget as HTMLElement
|
|
236
|
-
handle.focus({ preventScroll: true })
|
|
237
|
-
pointer = e.pointerId
|
|
238
|
-
startX = e.clientX
|
|
239
|
-
startY = e.clientY
|
|
240
|
-
handle.setPointerCapture(pointer)
|
|
241
|
-
window.addEventListener('keydown', escape)
|
|
242
|
-
window.addEventListener('scroll', cancel, true)
|
|
243
|
-
window.addEventListener('resize', cancel)
|
|
244
|
-
},
|
|
245
|
-
onPointermove: (e: PointerEvent) => {
|
|
246
|
-
if (e.pointerId !== pointer) return
|
|
247
|
-
const x = e.clientX - startX,
|
|
248
|
-
y = e.clientY - startY
|
|
249
|
-
if (!dragging.value && Math.hypot(x, y) >= 6) {
|
|
250
|
-
if (!registry.begin(props.cardId, cancel)) {
|
|
251
|
-
cancel()
|
|
252
|
-
return
|
|
253
|
-
}
|
|
254
|
-
anchor = root.value?.getBoundingClientRect()
|
|
255
|
-
dragging.value = true
|
|
256
|
-
}
|
|
257
|
-
if (dragging.value && surface.available) {
|
|
258
|
-
const current = root.value?.getBoundingClientRect()
|
|
259
|
-
surface.set({
|
|
260
|
-
x: x + (anchor && current ? anchor.x - current.x : 0),
|
|
261
|
-
y: y + (anchor && current ? anchor.y - current.y : 0),
|
|
262
|
-
scale: 1.02,
|
|
263
|
-
})
|
|
264
|
-
registry.move(x, y)
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
onPointerup: (e: PointerEvent) => {
|
|
268
|
-
if (e.pointerId === pointer) end(true)
|
|
269
|
-
},
|
|
270
|
-
onPointercancel: cancel,
|
|
271
|
-
onLostpointercapture: () => {
|
|
272
|
-
if (pointer !== undefined) cancel()
|
|
273
|
-
},
|
|
345
|
+
onLostpointercapture: interrupted,
|
|
346
|
+
// Safari moves focus to the page on mouse down; the grip keeps it for the arrow keys.
|
|
347
|
+
onMousedown: (e: MouseEvent) => e.preventDefault(),
|
|
274
348
|
onKeydown: (e: KeyboardEvent) => {
|
|
275
349
|
const direction = (
|
|
276
350
|
{
|
package/src/motion-region.ts
CHANGED
|
@@ -42,6 +42,7 @@ function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAd
|
|
|
42
42
|
: ([resolve(step[0]), step[1], step[2]] as const),
|
|
43
43
|
)
|
|
44
44
|
const adapter: MotionRegionAdapter = {
|
|
45
|
+
// Jolt owns the Vue flush boundary and bounded leaving copies, including interruption.
|
|
45
46
|
animateLayout: (change, { transition, ...options }) =>
|
|
46
47
|
runtime.animateLayout(target, change, { ...transition, ...options }),
|
|
47
48
|
...webPlatformMotion(runtime, target, resolve),
|