@getcortexlabs/mavis-web 0.1.0-rc.13 → 0.1.0-rc.14

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 (80) hide show
  1. package/README.md +4 -4
  2. package/dist/component-motion.d.ts.map +1 -1
  3. package/dist/component-motion.js +16 -0
  4. package/dist/component-motion.js.map +1 -1
  5. package/dist/components/ChartPlot.d.ts +8 -0
  6. package/dist/components/ChartPlot.d.ts.map +1 -1
  7. package/dist/components/ChartPlot.js +21 -1
  8. package/dist/components/ChartPlot.js.map +1 -1
  9. package/dist/components/DateCalendar.d.ts +1 -1
  10. package/dist/components/DateCalendar.d.ts.map +1 -1
  11. package/dist/components/DateCalendar.js +3 -1
  12. package/dist/components/DateCalendar.js.map +1 -1
  13. package/dist/components/MButton.d.ts +7 -7
  14. package/dist/components/MCard.d.ts.map +1 -1
  15. package/dist/components/MCard.js +59 -19
  16. package/dist/components/MCard.js.map +1 -1
  17. package/dist/components/MChip.d.ts +1 -1
  18. package/dist/components/MDatePicker.d.ts +96 -96
  19. package/dist/components/MDatePicker.d.ts.map +1 -1
  20. package/dist/components/MEmptyState.d.ts +1 -1
  21. package/dist/components/MInput.d.ts +5 -5
  22. package/dist/components/MLink.d.ts +1 -1
  23. package/dist/components/MPopover.d.ts +1 -1
  24. package/dist/components/MProgress.d.ts +1 -1
  25. package/dist/components/MRangeSlider.d.ts +2 -2
  26. package/dist/components/MResizablePanels.d.ts +2 -2
  27. package/dist/components/MReveal.d.ts +10 -10
  28. package/dist/components/MSheet.d.ts +5 -5
  29. package/dist/components/MSlider.d.ts +2 -2
  30. package/dist/components/MStack.d.ts +10 -10
  31. package/dist/components/MTimePicker.d.ts +40 -40
  32. package/dist/components/MTimePicker.d.ts.map +1 -1
  33. package/dist/components/MTooltip.d.ts +1 -1
  34. package/dist/components/MVirtualList.d.ts.map +1 -1
  35. package/dist/components/MVirtualList.js +111 -40
  36. package/dist/components/MVirtualList.js.map +1 -1
  37. package/dist/components/advanced.d.ts +34 -34
  38. package/dist/components/configurator.d.ts +33 -33
  39. package/dist/components/creative.d.ts +20 -20
  40. package/dist/components/dashboard.d.ts +12 -12
  41. package/dist/components/dashboard.d.ts.map +1 -1
  42. package/dist/components/dashboard.js +137 -74
  43. package/dist/components/dashboard.js.map +1 -1
  44. package/dist/components/discovery.d.ts +10 -10
  45. package/dist/components/interactive.d.ts +6 -6
  46. package/dist/components/layout.d.ts +30 -30
  47. package/dist/components/navigation.d.ts +4 -4
  48. package/dist/components/screen-components.d.ts +23 -23
  49. package/dist/components/wayfinding.d.ts +11 -11
  50. package/dist/components/workflows.d.ts +5 -5
  51. package/dist/motion-region.d.ts.map +1 -1
  52. package/dist/motion-region.js +1 -0
  53. package/dist/motion-region.js.map +1 -1
  54. package/dist/motion-surface.d.ts +6 -1
  55. package/dist/motion-surface.d.ts.map +1 -1
  56. package/dist/motion-surface.js +53 -7
  57. package/dist/motion-surface.js.map +1 -1
  58. package/dist/motion.d.ts.map +1 -1
  59. package/dist/motion.js +8 -3
  60. package/dist/motion.js.map +1 -1
  61. package/dist/scroll-motion.d.ts.map +1 -1
  62. package/dist/scroll-motion.js +19 -6
  63. package/dist/scroll-motion.js.map +1 -1
  64. package/dist/section-scroll.d.ts +2 -1
  65. package/dist/section-scroll.d.ts.map +1 -1
  66. package/dist/section-scroll.js +43 -12
  67. package/dist/section-scroll.js.map +1 -1
  68. package/package.json +3 -3
  69. package/src/base.css +43 -1
  70. package/src/component-motion.ts +15 -0
  71. package/src/components/ChartPlot.ts +21 -1
  72. package/src/components/DateCalendar.ts +3 -1
  73. package/src/components/MCard.ts +71 -17
  74. package/src/components/MVirtualList.ts +107 -29
  75. package/src/components/dashboard.ts +133 -75
  76. package/src/motion-region.ts +1 -0
  77. package/src/motion-surface.ts +64 -9
  78. package/src/motion.ts +16 -5
  79. package/src/scroll-motion.ts +17 -6
  80. package/src/section-scroll.ts +38 -12
@@ -1,10 +1,25 @@
1
- import { useComponentLayout } from '@getcortexlabs/mavis-core/vue'
2
- import { useMotionRegion } from '../motion-region.js'
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 { computed, defineComponent, h, mergeProps, nextTick, onMounted, ref, watch } from 'vue'
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 keys = computed(() => virtualKeys(props.items, props.itemKey))
20
- // Only data mutations animate the realized window. Scrolling never starts motion.
21
- const layout = useComponentLayout(() => keys.value, false)
22
- const motion = useMotionRegion(() => layout)
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
- props.items.length,
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
- keys,
41
- (next, previous) => {
42
- const index = Math.floor(offset.value / props.rowHeight)
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
- void nextTick(syncOffset)
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
- () => void nextTick(syncOffset),
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
- offset.value = root.value?.scrollTop ?? 0
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
- props.items.length
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
- h(
190
+ .map((index) => {
191
+ const itemKey = keys.value[index]!
192
+ const key = choiceKey(itemKey)
193
+ return h(
123
194
  'div',
124
195
  {
125
- key: choiceKey(keys.value[index]!),
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': choiceKey(keys.value[index]!),
205
+ 'data-m-list-key': key,
128
206
  'aria-posinset': index + 1,
129
- 'aria-setsize': props.items.length,
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: props.items[index],
219
+ item: rendered.value[index],
142
220
  index,
143
- itemKey: keys.value[index]!,
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,10 +129,16 @@ 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(() => registry.zones.set(props.column, () => root.value?.getBoundingClientRect()))
132
- onBeforeUnmount(() => registry.zones.delete(props.column))
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',
@@ -142,38 +151,117 @@ const Drag = defineComponent({
142
151
  inheritAttrs: false,
143
152
  props: kanbanDragProps,
144
153
  setup(props, { attrs, slots }) {
145
- const registry = inject(kanbanRegistryKey)!,
154
+ const registry = inject(kanbanRegistryKey)! as KanbanRegistry<HTMLElement>,
146
155
  root = ref<HTMLElement>(),
147
156
  surface = markRaw(createMotionSurface()),
148
157
  dragging = ref(false)
149
- let pointer: number | undefined,
150
- anchor: DOMRect | undefined,
151
- startX = 0,
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)
158
+ let runtime: WebRuntime | undefined,
159
+ zones: ReturnType<WebRuntime['dropZones']> | undefined,
160
+ live = false
171
161
  const escape = (e: KeyboardEvent) => {
172
162
  if (e.key === 'Escape') {
173
163
  e.preventDefault()
174
164
  cancel()
175
165
  }
176
166
  }
167
+ // Jolt cancels on these and leaves the card where it was; the board brings it back.
168
+ const interrupted = () => {
169
+ if (live) cancel()
170
+ }
171
+ function watchInput(on: boolean) {
172
+ const listen = on ? 'addEventListener' : 'removeEventListener'
173
+ window[listen]('keydown', escape as EventListener)
174
+ window[listen]('blur', interrupted)
175
+ window[listen]('resize', interrupted)
176
+ window[listen]('scroll', interrupted, true)
177
+ document[listen]('visibilitychange', interrupted)
178
+ }
179
+ function settle() {
180
+ if (live) watchInput(false)
181
+ live = false
182
+ dragging.value = false
183
+ }
184
+ function rest(animated: boolean) {
185
+ if (!surface.available) return
186
+ if (animated && props.animated)
187
+ surface.animate({ x: 0, y: 0, scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
188
+ else surface.set({ x: 0, y: 0, scale: 1 })
189
+ }
190
+ function cancel() {
191
+ const was = live
192
+ settle()
193
+ zones?.cancel()
194
+ if (!was) return
195
+ rest(true)
196
+ registry.finish(props.cardId)
197
+ }
198
+ function release() {
199
+ zones?.dispose()
200
+ zones = undefined
201
+ }
202
+ // Jolt refuses a drag under a transformed ancestor, so each contact gets fresh drop zones,
203
+ // after ending the layout motion that may still be moving the card's column.
204
+ function attach(handle: HTMLElement) {
205
+ if (live) return
206
+ release()
207
+ const source = root.value?.firstElementChild
208
+ if (!runtime || !(source instanceof HTMLElement)) return
209
+ for (let node = source.parentElement; node?.parentElement; node = node.parentElement) {
210
+ if (!new DOMMatrixReadOnly(getComputedStyle(node).transform).isIdentity)
211
+ runtime.animateLayout(node.parentElement).stop()
212
+ if (node.classList.contains('m-kanban')) break
213
+ }
214
+ const targets = registry.targets(props.cardId)
215
+ if (!targets.length) return
216
+ try {
217
+ zones = runtime.dropZones(source, {
218
+ targets,
219
+ drag: { handle, snap: [0] },
220
+ onMove({ id, bounds }) {
221
+ if (!live) {
222
+ if (!registry.begin(props.cardId, cancel)) {
223
+ zones?.cancel()
224
+ return
225
+ }
226
+ live = true
227
+ dragging.value = true
228
+ watchInput(true)
229
+ if (surface.available) surface.set({ scale: 1.02 })
230
+ }
231
+ registry.move(id, bounds)
232
+ },
233
+ onLeave: () => registry.leave(),
234
+ onDrop() {
235
+ settle()
236
+ rest(false)
237
+ registry.drop()
238
+ },
239
+ onReject() {
240
+ settle()
241
+ registry.finish(props.cardId)
242
+ if (!surface.available) return
243
+ if (props.animated)
244
+ surface.animate({ scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
245
+ // Jolt starts its return after this callback; without motion the card goes back at once.
246
+ else
247
+ queueMicrotask(() => {
248
+ zones?.cancel()
249
+ rest(false)
250
+ })
251
+ },
252
+ })
253
+ } catch {
254
+ zones = undefined
255
+ }
256
+ }
257
+ useConnectedMotion(root, useMotionContext(), (owner) => {
258
+ runtime = owner
259
+ return () => {
260
+ cancel()
261
+ release()
262
+ runtime = undefined
263
+ }
264
+ })
177
265
  onMounted(() => {
178
266
  registry.cards.set(props.cardId, () => root.value?.getBoundingClientRect())
179
267
  registry.focus.set(props.cardId, () =>
@@ -188,15 +276,12 @@ const Drag = defineComponent({
188
276
  registry.focus.delete(props.cardId)
189
277
  })
190
278
  onDeactivated(cancel)
191
- onScopeDispose(
192
- surface.use(() => () => {
193
- if (dragging.value) cancel()
194
- }),
195
- )
196
279
  watch(
197
280
  () => props.disabled,
198
281
  (value) => {
199
- if (value) cancel()
282
+ if (!value) return
283
+ cancel()
284
+ release()
200
285
  },
201
286
  )
202
287
  return () =>
@@ -206,6 +291,19 @@ const Drag = defineComponent({
206
291
  ref: root,
207
292
  'data-kanban-card': props.cardId,
208
293
  style: { position: 'relative', zIndex: dragging.value ? 20 : undefined },
294
+ onPointerdownCapture: (e: PointerEvent) => {
295
+ const handle =
296
+ e.target instanceof Element ? e.target.closest('[data-kanban-handle]') : null
297
+ if (
298
+ !(handle instanceof HTMLElement) ||
299
+ props.disabled ||
300
+ e.button !== 0 ||
301
+ !e.isPrimary
302
+ )
303
+ return
304
+ handle.focus({ preventScroll: true })
305
+ attach(handle)
306
+ },
209
307
  }),
210
308
  [
211
309
  h(MBox, { motionSurface: surface }, () =>
@@ -228,49 +326,9 @@ const Drag = defineComponent({
228
326
  border: '0',
229
327
  opacity: props.disabled ? 0.4 : 0.65,
230
328
  },
231
- onPointerdown: (e: PointerEvent) => {
232
- if (props.disabled || e.button !== 0 || !e.isPrimary || pointer !== undefined)
233
- return
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
- },
329
+ onLostpointercapture: interrupted,
330
+ // Safari moves focus to the page on mouse down; the grip keeps it for the arrow keys.
331
+ onMousedown: (e: MouseEvent) => e.preventDefault(),
274
332
  onKeydown: (e: KeyboardEvent) => {
275
333
  const direction = (
276
334
  {
@@ -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),
@@ -62,7 +62,11 @@ export function webMotionSurface(
62
62
  sources = new WeakMap<object, WebReadableValue>(),
63
63
  refreshes = new Map<object, () => void>(),
64
64
  plainText: () => boolean = () => false,
65
+ sections = new Set<ReturnType<typeof webSectionScroll>>(),
65
66
  ) {
67
+ const interrupt = (properties: readonly string[]) => {
68
+ for (const section of sections) section.interrupt(properties)
69
+ }
66
70
  const adapter: MotionSurfaceAdapter = {
67
71
  ...webVisualEffects(owner, target, sources, plainText),
68
72
  sensor(kind, options) {
@@ -110,8 +114,16 @@ export function webMotionSurface(
110
114
  try {
111
115
  scope.use((child) =>
112
116
  setup(
113
- webMotionSurface(runtime, target, enabled, child, sources, refreshes, plainText)
114
- .adapter,
117
+ webMotionSurface(
118
+ runtime,
119
+ target,
120
+ enabled,
121
+ child,
122
+ sources,
123
+ refreshes,
124
+ plainText,
125
+ sections,
126
+ ).adapter,
115
127
  ),
116
128
  )
117
129
  } catch (error) {
@@ -159,17 +171,32 @@ export function webMotionSurface(
159
171
  }
160
172
  },
161
173
  refresh: () => runtime.refresh(target),
162
- scrollSection: (source, section, frames, options) =>
163
- webSectionScroll(
174
+ scrollSection(source, section, frames, options) {
175
+ interrupt(Object.keys(frames))
176
+ const link = webSectionScroll(
164
177
  owner,
165
178
  webScrollElement(source),
166
179
  webRegion(section).target,
167
180
  target,
168
181
  frames,
169
182
  options,
170
- ),
171
- scrollLinked: (source, frames, options) =>
172
- owner.scrollLinked(webScrollElement(source), target, frames, options),
183
+ )
184
+ sections.add(link)
185
+ return {
186
+ get execution() {
187
+ return link.execution
188
+ },
189
+ refresh: () => link.refresh(),
190
+ dispose() {
191
+ sections.delete(link)
192
+ link.dispose()
193
+ },
194
+ }
195
+ },
196
+ scrollLinked(source, frames, options) {
197
+ interrupt(Object.keys(frames))
198
+ return owner.scrollLinked(webScrollElement(source), target, frames, options)
199
+ },
173
200
  map(source, input, output, options) {
174
201
  const value = sources.get(source) ?? (source as WebReadableValue)
175
202
  return 'map' in owner
@@ -180,9 +207,26 @@ export function webMotionSurface(
180
207
  const value = sources.get(source) ?? (source as WebReadableValue)
181
208
  return 'map' in owner ? owner.map(value, input, output) : value.to(input, output)
182
209
  },
210
+ scalar(source, operation, operand, maximum) {
211
+ const value = sources.get(source) ?? (source as WebReadableValue)
212
+ if (operation === 'clamp') return value.clamp(operand as number, maximum!)
213
+ if (
214
+ operation === 'abs' ||
215
+ operation === 'sin' ||
216
+ operation === 'cos' ||
217
+ operation === 'velocity'
218
+ )
219
+ return value[operation]()
220
+ const right =
221
+ typeof operand === 'number'
222
+ ? operand
223
+ : (sources.get(operand!) ?? (operand as WebReadableValue))
224
+ return value[operation](right)
225
+ },
226
+ readVelocity: (source) => (sources.get(source) ?? (source as WebReadableValue)).getVelocity(),
183
227
  springValue(source, options) {
184
228
  // Keep the runtime's private value identity; it rejects values from other contexts.
185
- const spring = owner.springValue(source as ReturnType<WebRuntime['motionValue']>, options)
229
+ const spring = owner.springValue(sources.get(source) ?? (source as WebReadableValue), options)
186
230
  const wrapper = {
187
231
  get: () => spring.get(),
188
232
  getVelocity: () => spring.getVelocity(),
@@ -205,19 +249,25 @@ export function webMotionSurface(
205
249
  stopValue: (value, options) => runtime.stop(value as WebMotionValue, options),
206
250
  playbackProgress: (handle) =>
207
251
  owner.playbackProgress(handle as Parameters<WebRuntime['playbackProgress']>[0]),
208
- decay: (velocity, options) => owner.decay(target, velocity, options),
252
+ decay(velocity, options) {
253
+ interrupt(Object.keys(velocity))
254
+ return owner.decay(target, velocity, options)
255
+ },
209
256
  animate(values, options) {
257
+ interrupt(Object.keys(values))
210
258
  const playback = owner.animate(target, motionKeyframes(values), options)
211
259
  takeShadow(target, values)
212
260
  return playback
213
261
  },
214
262
  set(values) {
263
+ interrupt(Object.keys(values))
215
264
  const playback = owner.set(target, values)
216
265
  takeShadow(target, values)
217
266
  return playback
218
267
  },
219
268
  motionValue: (initial) => owner.motionValue(initial),
220
269
  bind(values) {
270
+ interrupt(Object.keys(values))
221
271
  // Spring wrappers retain their public handle, rather than registering a second clock.
222
272
  const binding = owner.bind(
223
273
  target,
@@ -248,8 +298,13 @@ export function webMotionSurface(
248
298
  }
249
299
  },
250
300
  drag(options) {
301
+ // An interactive Card owns input through its surface button. Jolt must treat that
302
+ // button as the handle, while translation still belongs to the surrounding card.
303
+ // Only a direct child qualifies: nested controls keep their own pointer input.
304
+ const handle = target.querySelector<HTMLElement>(':scope > .m-card-action') ?? undefined
251
305
  const drag = owner.drag(target, {
252
306
  ...options,
307
+ handle,
253
308
  disabled: !enabled(),
254
309
  onRelease: options.onRelease
255
310
  ? (event) =>
package/src/motion.ts CHANGED
@@ -42,6 +42,12 @@ export function attachWebPress(
42
42
  }
43
43
  if (applicationSurface()) observeGeometry()
44
44
  const blocked = () => !enabled() || Boolean(target.closest('[inert], [aria-disabled="true"]'))
45
+ // MCard's action is a sibling of its controls, but feedback still transforms the whole card.
46
+ const ownsAction = (node: EventTarget | null) =>
47
+ node === target ||
48
+ (node instanceof window.Element &&
49
+ node.parentElement === target &&
50
+ node.classList.contains('m-card-action'))
45
51
  const apply = () => {
46
52
  const recipe = pressMotion(scale())[pressed ? 'pressed' : 'released']
47
53
  observeGeometry()
@@ -85,7 +91,7 @@ export function attachWebPress(
85
91
  )
86
92
  return
87
93
  for (const node of event.composedPath()) {
88
- if (node === target) break
94
+ if (ownsAction(node)) break
89
95
  if (
90
96
  node instanceof window.Element &&
91
97
  node.matches('button, a[href], input, select, textarea, [contenteditable], [role="button"]')
@@ -119,7 +125,7 @@ export function attachWebPress(
119
125
  'keydown',
120
126
  (event: KeyboardEvent) => {
121
127
  if (
122
- event.target !== target ||
128
+ !ownsAction(event.target) ||
123
129
  event.defaultPrevented ||
124
130
  event.repeat ||
125
131
  event.isComposing ||
@@ -143,9 +149,14 @@ export function attachWebPress(
143
149
  },
144
150
  true,
145
151
  )
146
- listen(target, 'blur', () => {
147
- if (key) cancel()
148
- })
152
+ listen(
153
+ target,
154
+ 'blur',
155
+ () => {
156
+ if (key) cancel()
157
+ },
158
+ true,
159
+ )
149
160
  listen(window, 'blur', cancel)
150
161
  listen(document, 'visibilitychange', () => {
151
162
  if (document.hidden) cancel()