@getcortexlabs/mavis 0.1.0-rc.12.2 → 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 (95) 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 +55 -14
  11. package/dist/native/motion-surface.js.map +1 -1
  12. package/dist/native/moved-shadow.d.ts +5 -0
  13. package/dist/native/moved-shadow.d.ts.map +1 -0
  14. package/dist/native/moved-shadow.js +23 -0
  15. package/dist/native/moved-shadow.js.map +1 -0
  16. package/dist/native/scroll-motion.d.ts +1 -1
  17. package/dist/native/scroll-motion.d.ts.map +1 -1
  18. package/dist/native/scroll-motion.js +55 -16
  19. package/dist/native/scroll-motion.js.map +1 -1
  20. package/dist/native/section-scroll.d.ts +1 -1
  21. package/dist/native/section-scroll.d.ts.map +1 -1
  22. package/dist/native/section-scroll.js +19 -6
  23. package/dist/native/section-scroll.js.map +1 -1
  24. package/dist/native/visual-effects.d.ts.map +1 -1
  25. package/dist/native/visual-effects.js +5 -0
  26. package/dist/native/visual-effects.js.map +1 -1
  27. package/dist/vue/card-input.d.ts +4 -0
  28. package/dist/vue/card-input.d.ts.map +1 -0
  29. package/dist/vue/card-input.js +37 -0
  30. package/dist/vue/card-input.js.map +1 -0
  31. package/dist/vue/components/ChoiceControl.d.ts +1 -1
  32. package/dist/vue/components/DateCalendar.d.ts +1 -1
  33. package/dist/vue/components/MButton.d.ts +6 -6
  34. package/dist/vue/components/MCard.d.ts.map +1 -1
  35. package/dist/vue/components/MCard.js +29 -8
  36. package/dist/vue/components/MCard.js.map +1 -1
  37. package/dist/vue/components/MChip.d.ts +1 -1
  38. package/dist/vue/components/MDatePicker.d.ts +96 -96
  39. package/dist/vue/components/MDatePicker.d.ts.map +1 -1
  40. package/dist/vue/components/MEmptyState.d.ts +1 -1
  41. package/dist/vue/components/MInput.d.ts +4 -4
  42. package/dist/vue/components/MPopover.d.ts +1 -1
  43. package/dist/vue/components/MProgress.d.ts +1 -1
  44. package/dist/vue/components/MRangeSlider.d.ts +2 -2
  45. package/dist/vue/components/MResizablePanels.d.ts +1 -1
  46. package/dist/vue/components/MReveal.d.ts +8 -8
  47. package/dist/vue/components/MSheet.d.ts +4 -4
  48. package/dist/vue/components/MSlider.d.ts +1 -1
  49. package/dist/vue/components/MStack.d.ts +8 -8
  50. package/dist/vue/components/MTimePicker.d.ts +40 -40
  51. package/dist/vue/components/MTimePicker.d.ts.map +1 -1
  52. package/dist/vue/components/MTooltip.d.ts +1 -1
  53. package/dist/vue/components/MVirtualList.d.ts.map +1 -1
  54. package/dist/vue/components/MVirtualList.js +88 -67
  55. package/dist/vue/components/MVirtualList.js.map +1 -1
  56. package/dist/vue/components/advanced.d.ts +34 -34
  57. package/dist/vue/components/configurator.d.ts +33 -33
  58. package/dist/vue/components/creative.d.ts +20 -20
  59. package/dist/vue/components/dashboard.d.ts +12 -12
  60. package/dist/vue/components/dashboard.d.ts.map +1 -1
  61. package/dist/vue/components/dashboard.js +167 -66
  62. package/dist/vue/components/dashboard.js.map +1 -1
  63. package/dist/vue/components/discovery.d.ts +10 -10
  64. package/dist/vue/components/interactive.d.ts +6 -6
  65. package/dist/vue/components/layout.d.ts +27 -16
  66. package/dist/vue/components/layout.d.ts.map +1 -1
  67. package/dist/vue/components/layout.js +3 -0
  68. package/dist/vue/components/layout.js.map +1 -1
  69. package/dist/vue/components/navigation.d.ts +4 -4
  70. package/dist/vue/components/screen-components.d.ts +23 -23
  71. package/dist/vue/components/wayfinding.d.ts +11 -11
  72. package/dist/vue/components/workflows.d.ts +5 -5
  73. package/dist/vue/perspective.d.ts +4 -0
  74. package/dist/vue/perspective.d.ts.map +1 -0
  75. package/dist/vue/perspective.js +3 -0
  76. package/dist/vue/perspective.js.map +1 -0
  77. package/dist/vue/use-motion-surface.d.ts +1 -1
  78. package/dist/vue/use-motion-surface.d.ts.map +1 -1
  79. package/dist/vue/use-motion-surface.js +40 -8
  80. package/dist/vue/use-motion-surface.js.map +1 -1
  81. package/package.json +3 -3
  82. package/src/native/flex-layout.ios.ts +4 -0
  83. package/src/native/motion-region.ts +1 -0
  84. package/src/native/motion-surface.ts +58 -13
  85. package/src/native/moved-shadow.ts +22 -0
  86. package/src/native/scroll-motion.ts +60 -19
  87. package/src/native/section-scroll.ts +16 -6
  88. package/src/native/visual-effects.ts +5 -0
  89. package/src/vue/card-input.ts +44 -0
  90. package/src/vue/components/MCard.ts +35 -9
  91. package/src/vue/components/MVirtualList.ts +104 -78
  92. package/src/vue/components/dashboard.ts +173 -68
  93. package/src/vue/components/layout.ts +3 -0
  94. package/src/vue/perspective.ts +4 -0
  95. package/src/vue/use-motion-surface.ts +39 -8
@@ -1,138 +1,164 @@
1
- import { useComponentContent } from '@getcortexlabs/mavis-core/vue'
2
- import { useMotionSurface } from '../use-motion-surface.js'
3
1
  import type { VirtualListComponent } from '@getcortexlabs/mavis-core/vue'
4
2
  import {
5
- computed,
6
3
  defineComponent,
7
4
  h,
8
- ListView,
9
5
  mergeProps,
10
6
  nextTick,
7
+ onBeforeUnmount,
8
+ registerElement,
11
9
  shallowRef,
12
- ref,
10
+ useItemTemplates,
13
11
  watch,
14
12
  } from 'nativescript-vue'
15
- import { isAndroid, type EventData, type ListView as NativeList } from '@nativescript/core'
16
- import { virtualListProps } from '@getcortexlabs/mavis-core/vue'
13
+ import {
14
+ isAndroid,
15
+ ListView as NativeList,
16
+ type EventData,
17
+ type ItemEventData,
18
+ } from '@nativescript/core'
19
+ import { listChanges, type ListChanges } from '@rafaelaugusto/jolt'
20
+ import { useMavisTheme, virtualListProps } from '@getcortexlabs/mavis-core/vue'
17
21
  import {
18
22
  choiceKey,
23
+ componentMotion,
19
24
  virtualKeys,
20
25
  virtualWindow,
21
- type VirtualItemSlot,
22
26
  type VirtualListHandle,
23
27
  } from '@getcortexlabs/mavis-core'
24
28
  import { MText } from './MText.js'
25
29
 
26
- // A recycled cell never inherits the previous item's presentation. Only a data
27
- // revision on an already loaded logical item plays; ordinary scrolling stays still.
28
- const RealizedContent = defineComponent({
29
- props: { revision: Number, height: Number },
30
- setup(props, { slots }) {
31
- const feedback = useComponentContent(() => props.revision, false)
32
- const motion = useMotionSurface(() => feedback)
33
- return () => h('GridLayout', { ...motion, height: props.height }, slots.default?.())
34
- },
35
- })
30
+ // Core owns placement/recycling. Vue owns the contents, with no independent items watcher.
31
+ registerElement('MavisVirtualList', () => NativeList, { viewFlags: 8 })
36
32
 
37
33
  const VirtualList = defineComponent({
38
34
  name: 'MVirtualList',
39
35
  inheritAttrs: false,
40
36
  props: virtualListProps,
41
37
  setup(props, { attrs, slots, expose }) {
42
- const keys = computed(() => virtualKeys(props.items, props.itemKey))
38
+ const { theme } = useMavisTheme()
43
39
  const list = shallowRef<NativeList>()
44
- const revision = ref(0)
40
+ let rendered: readonly unknown[] = [...props.items]
41
+ let controller: ListChanges<unknown> | undefined
45
42
  let requested = props.initialIndex
43
+ const key = (item: unknown) => virtualKeys([item], props.itemKey)[0]!
44
+ const templates = useItemTemplates({
45
+ componentName: 'MVirtualList',
46
+ slots: {
47
+ default: ({ item, index }) => [
48
+ h('GridLayout', { height: props.rowHeight, bindingContext: item }, [
49
+ h(
50
+ 'GridLayout',
51
+ { key: choiceKey(key(item)), height: props.rowHeight },
52
+ slots.default?.({ item, index, itemKey: key(item) }),
53
+ ),
54
+ ]),
55
+ ],
56
+ },
57
+ })
58
+ function renderItem(data: EventData) {
59
+ const event = data as ItemEventData
60
+ const item = rendered[event.index]
61
+ if (item === undefined) return
62
+ event.view = templates.renderCell(
63
+ { item, index: event.index, even: event.index % 2 === 0, odd: event.index % 2 !== 0 },
64
+ event.view,
65
+ )
66
+ }
67
+ function clear() {
68
+ list.value?.off(NativeList.itemLoadingEvent, renderItem)
69
+ controller?.dispose()
70
+ controller = undefined
71
+ }
72
+ function attach() {
73
+ clear()
74
+ const view = list.value
75
+ if (!view?.isLoaded) return
76
+ controller = listChanges(view, {
77
+ key: (item) => choiceKey(key(item)),
78
+ rowHeight: props.rowHeight,
79
+ move: componentMotion(theme.value, 'layout'),
80
+ enter: true,
81
+ exit: 'fadeOut',
82
+ })
83
+ if (!props.animated) controller.pause()
84
+ // Jolt subscribed first: recycle notification clears the old key's motion
85
+ // before Vue patches the reused cell with another item.
86
+ view.on(NativeList.itemLoadingEvent, renderItem)
87
+ }
46
88
  function scrollToIndex(index: number) {
47
89
  if (!Number.isInteger(index) || index < 0 || index >= props.items.length)
48
90
  throw new RangeError('List index is out of range.')
49
91
  requested = index
92
+ controller?.stop()
50
93
  list.value?.scrollToIndex(index)
51
94
  }
52
95
  expose({ scrollToIndex } satisfies VirtualListHandle)
53
96
  watch(
54
- keys,
55
- (next, previous) => {
56
- revision.value++
57
- const view = list.value
58
- const first = view
59
- ? isAndroid
60
- ? view.android?.getFirstVisiblePosition()
61
- : view.ios?.indexPathsForVisibleRows?.firstObject?.row
62
- : requested
63
- const key = previous[Math.max(0, first ?? requested)]
64
- const index = key === undefined ? -1 : next.indexOf(key)
65
- requested = Math.max(0, Math.min(index < 0 ? requested : index, next.length - 1))
66
- void nextTick(() => {
67
- if (next.length && view?.isLoaded) view.scrollToIndex(requested)
68
- })
97
+ () => props.items.map((item) => ({ item, key: key(item) })),
98
+ () => {
99
+ virtualKeys(props.items, props.itemKey)
100
+ rendered = [...props.items]
101
+ if (controller && !controller.disposed) controller.update(rendered)
102
+ else if (list.value) list.value.items = [...rendered]
69
103
  },
70
104
  { flush: 'pre' },
71
105
  )
106
+ watch(
107
+ () => props.animated,
108
+ (enabled) => (enabled ? controller?.play() : controller?.pause()),
109
+ )
110
+ watch(
111
+ () => [props.rowHeight, props.height],
112
+ () => {
113
+ attach()
114
+ },
115
+ { flush: 'post' },
116
+ )
117
+ onBeforeUnmount(clear)
72
118
  return () => {
73
119
  virtualWindow(props.items.length, props.rowHeight, props.height, 0, props.overscan)
74
- void keys.value
120
+ virtualKeys(props.items, props.itemKey)
75
121
  if (!props.label.trim()) throw new TypeError('Virtual lists require a label.')
76
122
  if (!Number.isInteger(props.initialIndex) || props.initialIndex < 0)
77
123
  throw new RangeError('initialIndex must be a nonnegative integer.')
78
- if (!props.items.length)
79
- return h(
80
- 'GridLayout',
81
- mergeProps(attrs, {
82
- id: props.id,
83
- height: props.height,
84
- accessibilityLabel: props.label,
85
- }),
86
- slots.empty?.() ?? [h(MText, { text: props.emptyLabel, tone: 'muted' })],
87
- )
88
124
  const content = h(
89
- ListView,
125
+ 'MavisVirtualList',
90
126
  mergeProps(attrs, {
91
127
  id: props.id,
92
- items: props.items,
93
128
  rowHeight: props.rowHeight,
94
129
  height: props.height,
95
130
  separatorColor: 'transparent',
96
131
  accessibilityLabel: props.label,
132
+ itemTemplates: templates.itemTemplates,
133
+ itemTemplateSelector: () => 'default',
97
134
  onLoaded: (event: EventData) => {
98
- list.value = event.object as NativeList
99
- // Core iOS coerces a pre-mount rowHeight to auto. Reapply it once the
100
- // UITableView exists so its delegate and scroll geometry use fixed rows.
101
- if (!isAndroid) {
102
- list.value.rowHeight = 'auto'
103
- list.value.rowHeight = props.rowHeight
104
- }
135
+ const view = (list.value = event.object as NativeList)
136
+ if (!isAndroid) view.rowHeight = 'auto'
137
+ view.rowHeight = props.rowHeight
138
+ rendered = [...props.items]
139
+ view.on(NativeList.itemLoadingEvent, renderItem)
140
+ view.items = [...rendered]
141
+ attach()
105
142
  void nextTick(() => {
106
- if (list.value?.isLoaded)
107
- list.value.scrollToIndex(Math.min(requested, props.items.length - 1))
143
+ if (view.isLoaded && rendered.length)
144
+ view.scrollToIndex(Math.min(requested, rendered.length - 1))
108
145
  })
109
146
  },
110
147
  onUnloaded: () => {
148
+ clear()
111
149
  list.value = undefined
112
150
  },
113
151
  }),
114
- {
115
- default: ({ item, index }: VirtualItemSlot) =>
116
- h('GridLayout', { height: props.rowHeight }, [
117
- // NativeScript owns cell reuse. A keyed child remounts local state when its logical item changes.
118
- h(
119
- RealizedContent,
120
- {
121
- key: choiceKey(keys.value[index]!),
122
- height: props.rowHeight,
123
- revision: revision.value,
124
- },
125
- () => slots.default?.({ item, index, itemKey: keys.value[index]! }),
126
- ),
127
- ]),
128
- },
152
+ templates.cellVNodes(),
129
153
  )
130
- // A flex parent's intrinsic/exact passes alternate width measure modes.
131
- // Core iOS reloads UITableView when that spec changes, losing its scroll
132
- // offset during cell reuse. The bounded grid gives the list one exact width.
133
- return isAndroid
134
- ? content
135
- : h('GridLayout', { rows: '*', columns: '*', height: props.height }, [content])
154
+ // The stable exact-size parent avoids iOS width-mode reloads and keeps the
155
+ // native list alive when the data becomes empty.
156
+ return h('GridLayout', { rows: '*', columns: '*', height: props.height }, [
157
+ content,
158
+ ...(!props.items.length
159
+ ? (slots.empty?.() ?? [h(MText, { text: props.emptyLabel, tone: 'muted' })])
160
+ : []),
161
+ ])
136
162
  }
137
163
  },
138
164
  })
@@ -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
  })
@@ -8,12 +8,14 @@ import {
8
8
  } from '@getcortexlabs/mavis-core/vue'
9
9
  import { defineComponent, h, mergeProps, provide, registerElement } from 'nativescript-vue'
10
10
  import { resolveSpace } from '@getcortexlabs/mavis-core'
11
+ import { resolvePerspective } from '@getcortexlabs/mavis-core/experimental'
11
12
  import { boxStyle } from '../props.js'
12
13
  import { MavisFlexLayout } from '../../native/flex-layout'
13
14
  import { MavisBox } from '../../native/box'
14
15
  import { useNativeViewAttrs } from '../accessibility.js'
15
16
  import { useMotionRegion } from '../use-motion-region.js'
16
17
  import { useMotionSurface } from '../use-motion-surface.js'
18
+ import { perspectiveKey } from '../perspective.js'
17
19
 
18
20
  export type { Align, Justify } from '@getcortexlabs/mavis-core/vue'
19
21
 
@@ -83,6 +85,7 @@ export const MBox = defineComponent({
83
85
  setup(props, { attrs, slots }) {
84
86
  const region = useMotionRegion(() => props.motionRegion)
85
87
  const surface = useMotionSurface(() => props.motionSurface)
88
+ provide(perspectiveKey, () => resolvePerspective(props.perspective))
86
89
  const { theme } = useMavisTheme()
87
90
  const nativeAttrs = useNativeViewAttrs(props)
88
91
  const shrink = useLayoutShrink()
@@ -0,0 +1,4 @@
1
+ import type { InjectionKey } from 'nativescript-vue'
2
+
3
+ /** The nearest box's projection distance. A box without one clears it, as CSS does. */
4
+ export const perspectiveKey: InjectionKey<() => number | undefined> = Symbol('mavis.perspective')