@getcortexlabs/mavis 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 (76) hide show
  1. package/README.md +5 -5
  2. package/dist/native/flex-layout.ios.d.ts.map +1 -1
  3. package/dist/native/flex-layout.ios.js +4 -0
  4. package/dist/native/flex-layout.ios.js.map +1 -1
  5. package/dist/native/motion-region.d.ts.map +1 -1
  6. package/dist/native/motion-region.js +1 -0
  7. package/dist/native/motion-region.js.map +1 -1
  8. package/dist/native/motion-surface.d.ts +1 -1
  9. package/dist/native/motion-surface.d.ts.map +1 -1
  10. package/dist/native/motion-surface.js +20 -3
  11. package/dist/native/motion-surface.js.map +1 -1
  12. package/dist/native/scroll-motion.d.ts +1 -1
  13. package/dist/native/scroll-motion.d.ts.map +1 -1
  14. package/dist/native/scroll-motion.js +55 -16
  15. package/dist/native/scroll-motion.js.map +1 -1
  16. package/dist/native/section-scroll.d.ts +1 -1
  17. package/dist/native/section-scroll.d.ts.map +1 -1
  18. package/dist/native/section-scroll.js +19 -6
  19. package/dist/native/section-scroll.js.map +1 -1
  20. package/dist/vue/card-input.d.ts +4 -0
  21. package/dist/vue/card-input.d.ts.map +1 -0
  22. package/dist/vue/card-input.js +37 -0
  23. package/dist/vue/card-input.js.map +1 -0
  24. package/dist/vue/components/ChoiceControl.d.ts +1 -1
  25. package/dist/vue/components/DateCalendar.d.ts +1 -1
  26. package/dist/vue/components/MButton.d.ts +6 -6
  27. package/dist/vue/components/MCard.d.ts.map +1 -1
  28. package/dist/vue/components/MCard.js +3 -2
  29. package/dist/vue/components/MCard.js.map +1 -1
  30. package/dist/vue/components/MChip.d.ts +1 -1
  31. package/dist/vue/components/MDatePicker.d.ts +96 -96
  32. package/dist/vue/components/MDatePicker.d.ts.map +1 -1
  33. package/dist/vue/components/MEmptyState.d.ts +1 -1
  34. package/dist/vue/components/MInput.d.ts +4 -4
  35. package/dist/vue/components/MPopover.d.ts +1 -1
  36. package/dist/vue/components/MProgress.d.ts +1 -1
  37. package/dist/vue/components/MRangeSlider.d.ts +2 -2
  38. package/dist/vue/components/MResizablePanels.d.ts +1 -1
  39. package/dist/vue/components/MReveal.d.ts +8 -8
  40. package/dist/vue/components/MSheet.d.ts +4 -4
  41. package/dist/vue/components/MSlider.d.ts +1 -1
  42. package/dist/vue/components/MStack.d.ts +8 -8
  43. package/dist/vue/components/MTimePicker.d.ts +40 -40
  44. package/dist/vue/components/MTimePicker.d.ts.map +1 -1
  45. package/dist/vue/components/MTooltip.d.ts +1 -1
  46. package/dist/vue/components/MVirtualList.d.ts.map +1 -1
  47. package/dist/vue/components/MVirtualList.js +88 -67
  48. package/dist/vue/components/MVirtualList.js.map +1 -1
  49. package/dist/vue/components/advanced.d.ts +34 -34
  50. package/dist/vue/components/configurator.d.ts +33 -33
  51. package/dist/vue/components/creative.d.ts +20 -20
  52. package/dist/vue/components/dashboard.d.ts +12 -12
  53. package/dist/vue/components/dashboard.d.ts.map +1 -1
  54. package/dist/vue/components/dashboard.js +167 -66
  55. package/dist/vue/components/dashboard.js.map +1 -1
  56. package/dist/vue/components/discovery.d.ts +10 -10
  57. package/dist/vue/components/interactive.d.ts +6 -6
  58. package/dist/vue/components/layout.d.ts +16 -16
  59. package/dist/vue/components/navigation.d.ts +4 -4
  60. package/dist/vue/components/screen-components.d.ts +23 -23
  61. package/dist/vue/components/wayfinding.d.ts +11 -11
  62. package/dist/vue/components/workflows.d.ts +5 -5
  63. package/dist/vue/use-motion-surface.d.ts.map +1 -1
  64. package/dist/vue/use-motion-surface.js +0 -6
  65. package/dist/vue/use-motion-surface.js.map +1 -1
  66. package/package.json +3 -3
  67. package/src/native/flex-layout.ios.ts +4 -0
  68. package/src/native/motion-region.ts +1 -0
  69. package/src/native/motion-surface.ts +22 -3
  70. package/src/native/scroll-motion.ts +60 -19
  71. package/src/native/section-scroll.ts +16 -6
  72. package/src/vue/card-input.ts +44 -0
  73. package/src/vue/components/MCard.ts +4 -3
  74. package/src/vue/components/MVirtualList.ts +104 -78
  75. package/src/vue/components/dashboard.ts +173 -68
  76. package/src/vue/use-motion-surface.ts +0 -4
@@ -4,6 +4,7 @@ import {
4
4
  inject,
5
5
  markRaw,
6
6
  mergeProps,
7
+ nextTick,
7
8
  onBeforeUnmount,
8
9
  onDeactivated,
9
10
  onScopeDispose,
@@ -11,12 +12,14 @@ import {
11
12
  } from 'nativescript-vue'
12
13
  import {
13
14
  Application,
15
+ isAndroid,
14
16
  type View,
15
17
  type EventData,
16
- type PanGestureEventData,
18
+ type LayoutBase,
19
+ type TouchGestureEventData,
17
20
  } from '@nativescript/core'
18
21
  import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
19
- import { reducedMotion, onReducedMotion } from '@rafaelaugusto/jolt'
22
+ import { dropZones, reducedMotion, onReducedMotion, type DropZones } from '@rafaelaugusto/jolt'
20
23
  import {
21
24
  createDashboardShape,
22
25
  createDonutChart,
@@ -28,6 +31,7 @@ import {
28
31
  kanbanRegistryKey,
29
32
  kanbanZoneProps,
30
33
  kanbanDragProps,
34
+ type KanbanRegistry,
31
35
  } from '@getcortexlabs/mavis-core/vue'
32
36
  import { createMotionSurface } from '@getcortexlabs/mavis-core/experimental'
33
37
  import { MBox, MColumn, MRow } from './layout.js'
@@ -86,29 +90,49 @@ const Environment = defineComponent({
86
90
  })
87
91
  function rect(view?: View) {
88
92
  if (!view?.isLoaded) return
89
- const p = view.getLocationOnScreen(),
93
+ const p = view.getLocationInWindow(),
90
94
  size = view.getActualSize()
91
95
  return p ? { ...p, ...size } : undefined
92
96
  }
97
+ // A dragged card leaves its column: nothing between the card and the board may clip it.
98
+ // On Android a clipped source counts as hidden and Jolt cancels the drag.
99
+ function unclip(source: View, columns: readonly View[]) {
100
+ const show = (view: View) => {
101
+ if (isAndroid) {
102
+ const group = view.android as { setClipChildren?(clip: boolean): void } & {
103
+ setClipToPadding?(clip: boolean): void
104
+ }
105
+ group?.setClipChildren?.(false)
106
+ group?.setClipToPadding?.(false)
107
+ } else (view as LayoutBase).clipToBounds = false
108
+ }
109
+ for (let view = source.parent as View | undefined; view; view = view.parent as View | undefined) {
110
+ show(view)
111
+ if (columns.includes(view)) {
112
+ if (view.parent) show(view.parent as View)
113
+ break
114
+ }
115
+ }
116
+ }
93
117
  const Zone = defineComponent({
94
118
  inheritAttrs: false,
95
119
  props: kanbanZoneProps,
96
120
  setup(props, { attrs, slots }) {
97
- const registry = inject(kanbanRegistryKey)!
98
- let view: View | undefined
99
- onBeforeUnmount(() => registry.zones.delete(props.column))
121
+ const registry = inject(kanbanRegistryKey)! as KanbanRegistry<View>
122
+ const leave = () => {
123
+ if (registry.zones.delete(props.column)) registry.revision.value++
124
+ }
125
+ onBeforeUnmount(leave)
100
126
  return () =>
101
127
  h(
102
128
  'GridLayout',
103
129
  mergeProps(attrs, {
130
+ zIndex: props.raised ? 20 : 0,
104
131
  onLoaded: (e: EventData) => {
105
- view = e.object as View
106
- registry.zones.set(props.column, () => rect(view))
107
- },
108
- onUnloaded: () => {
109
- view = undefined
110
- registry.zones.delete(props.column)
132
+ registry.zones.set(props.column, e.object as View)
133
+ registry.revision.value++
111
134
  },
135
+ onUnloaded: leave,
112
136
  }),
113
137
  slots.default?.(),
114
138
  )
@@ -118,39 +142,118 @@ const Drag = defineComponent({
118
142
  inheritAttrs: false,
119
143
  props: kanbanDragProps,
120
144
  setup(props, { attrs, slots }) {
121
- const registry = inject(kanbanRegistryKey)!,
145
+ const registry = inject(kanbanRegistryKey)! as KanbanRegistry<View>,
122
146
  surface = markRaw(createMotionSurface())
123
147
  let view: View | undefined,
124
- anchor: ReturnType<typeof rect>,
125
- dragging = false
126
- function end(commit = false) {
127
- const was = dragging
128
- dragging = false
129
- if (surface.available) {
130
- if (props.animated && !commit)
131
- surface.animate({ x: 0, y: 0, scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
132
- else surface.set({ x: 0, y: 0, scale: 1 })
133
- }
148
+ source: View | undefined,
149
+ grip: View | undefined,
150
+ zones: DropZones | undefined,
151
+ live = false,
152
+ queued = false,
153
+ disposed = false
154
+ function settle() {
155
+ live = false
156
+ Application.off(Application.suspendEvent, cancel)
134
157
  if (view) view.style.zIndex = 0
135
- if (was) registry.finish(commit)
136
158
  }
137
- const cancel = () => end(false)
138
- onBeforeUnmount(() => {
159
+ // Jolt can end a drag on its own (a cancelled touch, a source that went out of sight) and
160
+ // leaves the card where it was; once the touch is over the board brings it back.
161
+ const touched = (e: TouchGestureEventData) => {
162
+ if (e.action !== 'up' && e.action !== 'cancel') return
163
+ setTimeout(() => {
164
+ if (live && !zones?.dragging) cancel()
165
+ })
166
+ }
167
+ function rest(animated: boolean) {
168
+ if (!surface.available) return
169
+ if (animated && props.animated)
170
+ surface.animate({ x: 0, y: 0, scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
171
+ else surface.set({ x: 0, y: 0, scale: 1 })
172
+ }
173
+ function cancel() {
174
+ const was = live
175
+ settle()
176
+ zones?.cancel()
177
+ if (!was) return
178
+ rest(true)
179
+ registry.finish(props.cardId)
180
+ }
181
+ function release() {
182
+ zones?.dispose()
183
+ zones = undefined
184
+ }
185
+ function attach() {
186
+ if (live) return
187
+ release()
188
+ if (props.disabled || !source?.isLoaded || !grip?.isLoaded) return
189
+ const targets = registry.targets(props.cardId).filter(({ target }) => target.isLoaded)
190
+ if (!targets.length) return
191
+ unclip(
192
+ source,
193
+ targets.map(({ target }) => target),
194
+ )
195
+ zones = dropZones(source, {
196
+ targets,
197
+ drag: { handle: grip, snap: [0] },
198
+ onMove({ id, bounds }) {
199
+ if (!live) {
200
+ if (!registry.begin(props.cardId, cancel)) {
201
+ zones?.cancel()
202
+ return
203
+ }
204
+ live = true
205
+ Application.on(Application.suspendEvent, cancel)
206
+ if (view) view.style.zIndex = 20
207
+ if (surface.available) surface.set({ scale: 1.02 })
208
+ }
209
+ registry.move(id, bounds)
210
+ },
211
+ onLeave: () => registry.leave(),
212
+ onDrop() {
213
+ settle()
214
+ rest(false)
215
+ registry.drop()
216
+ },
217
+ onReject() {
218
+ settle()
219
+ registry.finish(props.cardId)
220
+ if (!surface.available) return
221
+ if (props.animated)
222
+ surface.animate({ scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
223
+ else
224
+ void Promise.resolve().then(() => {
225
+ zones?.cancel()
226
+ rest(false)
227
+ })
228
+ },
229
+ })
230
+ }
231
+ // Views load parent first, so the columns and the card's own views arrive over one tick.
232
+ function schedule() {
233
+ if (queued || disposed) return
234
+ queued = true
235
+ void nextTick(() => {
236
+ queued = false
237
+ if (!disposed) attach()
238
+ })
239
+ }
240
+ function unload() {
139
241
  cancel()
242
+ release()
243
+ }
244
+ onBeforeUnmount(() => {
245
+ disposed = true
246
+ unload()
140
247
  registry.cards.delete(props.cardId)
141
248
  registry.focus.delete(props.cardId)
142
249
  })
143
250
  onDeactivated(cancel)
144
251
  onScopeDispose(surface.use(() => cancel))
145
- watch(
146
- () => props.disabled,
147
- (value) => {
148
- if (value) cancel()
149
- },
150
- )
252
+ watch(() => [registry.revision.value, props.disabled], schedule)
253
+ // A plain GridLayout would take the column's whole height on iOS; a box keeps the card's own.
151
254
  return () =>
152
255
  h(
153
- 'GridLayout',
256
+ MBox,
154
257
  mergeProps(attrs, {
155
258
  onLoaded: (e: EventData) => {
156
259
  view = e.object as View
@@ -160,48 +263,50 @@ const Drag = defineComponent({
160
263
  })
161
264
  },
162
265
  onUnloaded: () => {
163
- cancel()
266
+ unload()
164
267
  view = undefined
165
268
  registry.cards.delete(props.cardId)
166
269
  registry.focus.delete(props.cardId)
167
270
  },
168
271
  }),
169
- [
170
- h(MBox, { motionSurface: surface }, () =>
171
- h(MColumn, { gap: 'xs' }, () => [
172
- h(
173
- MBox,
174
- {
175
- height: 36,
176
- accessibilityHidden: true,
177
- accessibilityLabel: props.label,
178
- opacity: props.disabled ? 0.4 : 0.65,
179
- onPan: (e: PanGestureEventData) => {
180
- if (props.disabled) return
181
- if (e.state === 1) {
182
- anchor = rect(view)
183
- dragging = registry.begin(props.cardId, cancel)
184
- if (dragging && view) view.style.zIndex = 20
185
- }
186
- if (e.state === 2 && dragging && surface.available) {
187
- const current = rect(view)
188
- surface.set({
189
- x: e.deltaX + (anchor && current ? anchor.x - current.x : 0),
190
- y: e.deltaY + (anchor && current ? anchor.y - current.y : 0),
191
- scale: 1.02,
192
- })
193
- registry.move(e.deltaX, e.deltaY)
194
- }
195
- if (e.state === 3) end(true)
196
- if (e.state === 4) cancel()
272
+ () =>
273
+ h(
274
+ MBox,
275
+ {
276
+ motionSurface: surface,
277
+ onLoaded: (e: EventData) => {
278
+ source = e.object as View
279
+ schedule()
280
+ },
281
+ onUnloaded: () => {
282
+ unload()
283
+ source = undefined
284
+ },
285
+ },
286
+ () =>
287
+ h(MColumn, { gap: 'xs' }, () => [
288
+ h(
289
+ MBox,
290
+ {
291
+ height: 36,
292
+ accessibilityHidden: true,
293
+ accessibilityLabel: props.label,
294
+ opacity: props.disabled ? 0.4 : 0.65,
295
+ onTouch: touched,
296
+ onLoaded: (e: EventData) => {
297
+ grip = e.object as View
298
+ schedule()
299
+ },
300
+ onUnloaded: () => {
301
+ unload()
302
+ grip = undefined
303
+ },
197
304
  },
198
- },
199
- () => h(MText, { text: '⠿', textAlignment: 'center' }),
200
- ),
201
- ...(slots.default?.() ?? []),
202
- ]),
305
+ () => h(MText, { text: '⠿', textAlignment: 'center' }),
306
+ ),
307
+ ...(slots.default?.() ?? []),
308
+ ]),
203
309
  ),
204
- ],
205
310
  )
206
311
  },
207
312
  })
@@ -89,10 +89,6 @@ export function useMotionSurface(
89
89
  },
90
90
  set: (values) => {
91
91
  continuous?.interrupt(Object.keys(values))
92
- // Jolt on Android leaves the path's translationY on the view when a path still in
93
- // flight is replaced by a zero-duration set (rafaelaugustos/jolt#479).
94
- if (isAndroid && ('x' in values || 'y' in values || 'rotate' in values))
95
- for (const [handle, frames] of active) if (frames.path) handle.stop()
96
92
  const handle = animate(target, values, { duration: 0 })
97
93
  takeShadow(target, values)
98
94
  return handle