@getcortexlabs/mavis 0.1.0-rc.11.1 → 0.1.0-rc.12.1

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 (98) hide show
  1. package/README.md +5 -5
  2. package/dist/native/date-format.android.d.ts +4 -0
  3. package/dist/native/date-format.android.d.ts.map +1 -1
  4. package/dist/native/date-format.android.js +20 -0
  5. package/dist/native/date-format.android.js.map +1 -1
  6. package/dist/native/date-format.d.ts +3 -0
  7. package/dist/native/date-format.d.ts.map +1 -1
  8. package/dist/native/date-format.ios.d.ts +4 -0
  9. package/dist/native/date-format.ios.d.ts.map +1 -1
  10. package/dist/native/date-format.ios.js +18 -0
  11. package/dist/native/date-format.ios.js.map +1 -1
  12. package/dist/native/date-format.js +3 -0
  13. package/dist/native/date-format.js.map +1 -1
  14. package/dist/native/image-crop-common.d.ts +5 -0
  15. package/dist/native/image-crop-common.d.ts.map +1 -0
  16. package/dist/native/image-crop-common.js +36 -0
  17. package/dist/native/image-crop-common.js.map +1 -0
  18. package/dist/native/image-crop.android.d.ts +3 -0
  19. package/dist/native/image-crop.android.d.ts.map +1 -0
  20. package/dist/native/image-crop.android.js +92 -0
  21. package/dist/native/image-crop.android.js.map +1 -0
  22. package/dist/native/image-crop.d.ts +3 -0
  23. package/dist/native/image-crop.d.ts.map +1 -0
  24. package/dist/native/image-crop.ios.d.ts +3 -0
  25. package/dist/native/image-crop.ios.d.ts.map +1 -0
  26. package/dist/native/image-crop.ios.js +68 -0
  27. package/dist/native/image-crop.ios.js.map +1 -0
  28. package/dist/native/image-crop.js +4 -0
  29. package/dist/native/image-crop.js.map +1 -0
  30. package/dist/vue/components/DateCalendar.d.ts +1 -1
  31. package/dist/vue/components/MAccordion.d.ts +1 -1
  32. package/dist/vue/components/MButton.d.ts +5 -5
  33. package/dist/vue/components/MCard.d.ts +1 -1
  34. package/dist/vue/components/MChip.d.ts +2 -2
  35. package/dist/vue/components/MCombobox.d.ts +3 -3
  36. package/dist/vue/components/MDatePicker.d.ts +16 -16
  37. package/dist/vue/components/MDialog.d.ts +3 -3
  38. package/dist/vue/components/MEmptyState.d.ts +1 -1
  39. package/dist/vue/components/MFilePicker.d.ts +3 -3
  40. package/dist/vue/components/MImageCompare.d.ts +1 -1
  41. package/dist/vue/components/MImageViewer.d.ts +5 -5
  42. package/dist/vue/components/MInput.d.ts +3 -3
  43. package/dist/vue/components/MListItem.d.ts +1 -1
  44. package/dist/vue/components/MPinInput.d.ts +57 -0
  45. package/dist/vue/components/MPinInput.d.ts.map +1 -0
  46. package/dist/vue/components/MPinInput.js +128 -0
  47. package/dist/vue/components/MPinInput.js.map +1 -0
  48. package/dist/vue/components/MPopover.d.ts +1 -1
  49. package/dist/vue/components/MPopover.d.ts.map +1 -1
  50. package/dist/vue/components/MPopover.js +23 -11
  51. package/dist/vue/components/MPopover.js.map +1 -1
  52. package/dist/vue/components/MProgress.d.ts +1 -1
  53. package/dist/vue/components/MRangeSlider.d.ts +1 -1
  54. package/dist/vue/components/MResizablePanels.d.ts +3 -3
  55. package/dist/vue/components/MSelect.d.ts +1 -1
  56. package/dist/vue/components/MTimePicker.d.ts +12 -12
  57. package/dist/vue/components/MTooltip.d.ts +1 -1
  58. package/dist/vue/components/advanced.d.ts +850 -0
  59. package/dist/vue/components/advanced.d.ts.map +1 -0
  60. package/dist/vue/components/advanced.js +214 -0
  61. package/dist/vue/components/advanced.js.map +1 -0
  62. package/dist/vue/components/configurator.d.ts +7 -7
  63. package/dist/vue/components/creative.d.ts +614 -0
  64. package/dist/vue/components/creative.d.ts.map +1 -0
  65. package/dist/vue/components/creative.js +185 -0
  66. package/dist/vue/components/creative.js.map +1 -0
  67. package/dist/vue/components/dashboard.d.ts +474 -0
  68. package/dist/vue/components/dashboard.d.ts.map +1 -0
  69. package/dist/vue/components/dashboard.js +193 -0
  70. package/dist/vue/components/dashboard.js.map +1 -0
  71. package/dist/vue/components/discovery.d.ts +3 -3
  72. package/dist/vue/components/interactive.d.ts +1 -1
  73. package/dist/vue/components/navigation.d.ts +3 -3
  74. package/dist/vue/components/screen-components.d.ts +502 -0
  75. package/dist/vue/components/screen-components.d.ts.map +1 -0
  76. package/dist/vue/components/screen-components.js +46 -0
  77. package/dist/vue/components/screen-components.js.map +1 -0
  78. package/dist/vue/components/wayfinding.d.ts +6 -6
  79. package/dist/vue/components/workflows.d.ts +3 -3
  80. package/dist/vue/index.d.ts +5 -1
  81. package/dist/vue/index.d.ts.map +1 -1
  82. package/dist/vue/index.js +30 -1
  83. package/dist/vue/index.js.map +1 -1
  84. package/package.json +3 -3
  85. package/src/native/date-format.android.ts +22 -0
  86. package/src/native/date-format.ios.ts +22 -0
  87. package/src/native/date-format.ts +7 -0
  88. package/src/native/image-crop-common.ts +46 -0
  89. package/src/native/image-crop.android.ts +140 -0
  90. package/src/native/image-crop.ios.ts +94 -0
  91. package/src/native/image-crop.ts +4 -0
  92. package/src/vue/components/MPinInput.ts +145 -0
  93. package/src/vue/components/MPopover.ts +20 -11
  94. package/src/vue/components/advanced.ts +263 -0
  95. package/src/vue/components/creative.ts +246 -0
  96. package/src/vue/components/dashboard.ts +249 -0
  97. package/src/vue/components/screen-components.ts +61 -0
  98. package/src/vue/index.ts +84 -0
@@ -0,0 +1,145 @@
1
+ import { defineComponent, h, mergeProps, ref, registerElement, watch } from 'nativescript-vue'
2
+ import {
3
+ isIOS,
4
+ isAndroid,
5
+ type TextField,
6
+ type EventData,
7
+ type PropertyChangeData,
8
+ } from '@nativescript/core'
9
+ import {
10
+ pinInputProps,
11
+ usePinInput,
12
+ useMavisTheme,
13
+ createPinCell,
14
+ } from '@getcortexlabs/mavis-core/vue'
15
+ import { resolveRadius } from '@getcortexlabs/mavis-core'
16
+ import { MavisTextField } from '../../native/text-field'
17
+ import { MText } from './MText.js'
18
+
19
+ registerElement('MavisPinField', () => MavisTextField)
20
+ const PinCell = createPinCell(MText)
21
+ export const MPinInput = defineComponent({
22
+ name: 'MPinInput',
23
+ inheritAttrs: false,
24
+ props: pinInputProps,
25
+ emits: ['update:modelValue', 'complete', 'focus', 'blur'],
26
+ setup(props, { attrs, emit, expose }) {
27
+ const { theme } = useMavisTheme(),
28
+ state = usePinInput(props, emit)
29
+ const editor = ref<{ nativeView: TextField }>()
30
+ function blur() {
31
+ editor.value?.nativeView.dismissSoftInput()
32
+ editor.value?.nativeView.android?.clearFocus()
33
+ }
34
+ watch(
35
+ () => props.disabled,
36
+ (disabled) => {
37
+ if (disabled) blur()
38
+ },
39
+ )
40
+ expose({
41
+ focus: () => {
42
+ if (!props.disabled) editor.value?.nativeView.focus()
43
+ },
44
+ blur,
45
+ })
46
+ return () => {
47
+ const { colors, space } = theme.value,
48
+ message = props.error || props.helperText
49
+ return h('StackLayout', mergeProps(attrs, { minWidth: 0 }), [
50
+ h(MText, {
51
+ text: props.label,
52
+ variant: 'caption',
53
+ accessibilityHidden: true,
54
+ marginBottom: space.sm,
55
+ }),
56
+ h('GridLayout', { height: 56 }, [
57
+ h(
58
+ 'GridLayout',
59
+ {
60
+ columns: Array(props.length).fill('*').join(','),
61
+ accessibilityHidden: true,
62
+ isUserInteractionEnabled: false,
63
+ },
64
+ Array.from({ length: props.length }, (_, i) =>
65
+ h(PinCell, {
66
+ col: i,
67
+ digit: state.value.value[i] ?? '',
68
+ active: state.focused.value && state.position.value === i,
69
+ textAlignment: 'center',
70
+ verticalAlignment: 'middle',
71
+ height: 52,
72
+ fontSize: 24,
73
+ fontWeight: '600',
74
+ paddingTop: 10,
75
+ marginRight: i < props.length - 1 ? space.xs : 0,
76
+ borderRadius: resolveRadius(theme.value, 'md'),
77
+ borderWidth: 2,
78
+ borderColor: props.error
79
+ ? colors.danger
80
+ : state.focused.value && state.position.value === i
81
+ ? colors.primary
82
+ : colors.border,
83
+ backgroundColor: colors.surface,
84
+ color: colors.text,
85
+ opacity: props.disabled ? 0.5 : 1,
86
+ }),
87
+ ),
88
+ ),
89
+ h('MavisPinField', {
90
+ ref: editor,
91
+ id: props.id,
92
+ text: state.value.value,
93
+ keyboardType: 'number',
94
+ autocorrect: false,
95
+ autocapitalizationType: 'none',
96
+ closeOnReturn: false,
97
+ editable: !props.disabled && !props.readonly,
98
+ isEnabled: !props.disabled,
99
+ updateTextTrigger: 'textChanged',
100
+ accessibilityLabel: props.label,
101
+ accessibilityHint: message,
102
+ // The native editor retains selection, autofill and accessibility; cells are decorative.
103
+ color: 'transparent',
104
+ backgroundColor: 'transparent',
105
+ borderWidth: 0,
106
+ padding: 0,
107
+ fontSize: 24,
108
+ onLoaded: (event: EventData) => {
109
+ const view = event.object as TextField
110
+ if (isIOS) view.ios.textContentType = 'one-time-code'
111
+ if (isAndroid) {
112
+ view.android?.setLetterSpacing(0.6)
113
+ view.android?.setSelectAllOnFocus(false)
114
+ }
115
+ },
116
+ onTextChange: (event: PropertyChangeData) => {
117
+ const field = event.object as TextField
118
+ if (field.ios?.markedTextRange) return
119
+ const normalized = state.change(String(event.value ?? ''))
120
+ if (field.text !== normalized) field.text = normalized
121
+ },
122
+ onFocus: () => {
123
+ state.focused.value = true
124
+ state.position.value = Math.min(state.value.value.length, props.length - 1)
125
+ emit('focus')
126
+ },
127
+ onBlur: () => {
128
+ state.focused.value = false
129
+ emit('blur')
130
+ },
131
+ }),
132
+ ]),
133
+ message
134
+ ? h(MText, {
135
+ text: message,
136
+ variant: 'caption',
137
+ tone: props.error ? 'danger' : 'muted',
138
+ motionSurface: state.feedback,
139
+ marginTop: space.sm,
140
+ })
141
+ : null,
142
+ ])
143
+ }
144
+ },
145
+ })
@@ -85,7 +85,11 @@ export const MPopover = defineComponent({
85
85
  emit('update:open', false)
86
86
  emit('close', reason)
87
87
  }
88
- const scrolled = () => close('program')
88
+ let reposition: (() => void) | undefined
89
+ const scrolled = () => {
90
+ if (slots.anchor) reposition?.()
91
+ else close('program')
92
+ }
89
93
  function cleanup() {
90
94
  releaseBack()
91
95
  releaseClaim()
@@ -183,6 +187,10 @@ export const MPopover = defineComponent({
183
187
  }
184
188
  if (JSON.stringify(next) !== JSON.stringify(position.value)) position.value = next
185
189
  }
190
+ reposition = place
191
+ onBeforeUnmount(() => {
192
+ if (reposition === place) reposition = undefined
193
+ })
186
194
  watch(
187
195
  () => [props.width, props.placement],
188
196
  () => void nextTick(place),
@@ -285,19 +293,20 @@ export const MPopover = defineComponent({
285
293
  columns: 'auto',
286
294
  ...attrs,
287
295
  ref: anchor,
288
- horizontalAlignment: 'left',
296
+ horizontalAlignment: slots.anchor ? 'stretch' : 'left',
289
297
  verticalAlignment: 'top',
290
298
  },
291
299
  [
292
- h(MButton, {
293
- ref: trigger,
294
- text: props.triggerLabel,
295
- icon: props.icon,
296
- variant: props.variant,
297
- disabled: props.disabled,
298
- accessibilityState: props.open ? 'expanded' : '',
299
- onClick: () => (props.open ? close('trigger') : emit('update:open', true)),
300
- }),
300
+ slots.anchor?.() ??
301
+ h(MButton, {
302
+ ref: trigger,
303
+ text: props.triggerLabel,
304
+ icon: props.icon,
305
+ variant: props.variant,
306
+ disabled: props.disabled,
307
+ accessibilityState: props.open ? 'expanded' : '',
308
+ onClick: () => (props.open ? close('trigger') : emit('update:open', true)),
309
+ }),
301
310
  ],
302
311
  )
303
312
  }
@@ -0,0 +1,263 @@
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ mergeProps,
5
+ onBeforeUnmount,
6
+ onDeactivated,
7
+ onActivated,
8
+ watch,
9
+ type PropType,
10
+ } from 'nativescript-vue'
11
+ import {
12
+ type View,
13
+ type EventData,
14
+ type PanGestureEventData,
15
+ type PinchGestureEventData,
16
+ Application,
17
+ } from '@nativescript/core'
18
+ import {
19
+ createTreeSelect,
20
+ createMasonry,
21
+ createHeatmap,
22
+ createNotificationCenter,
23
+ createImageCropper,
24
+ createScheduler,
25
+ advancedCanvasProps,
26
+ advancedCellProps,
27
+ advancedGestureProps,
28
+ type AdvancedGesture,
29
+ } from '@getcortexlabs/mavis-core/vue'
30
+ import type { CropSource } from '@getcortexlabs/mavis-core'
31
+ import type { MotionSurface } from '@getcortexlabs/mavis-core/experimental'
32
+ import { loadCropImage } from '../../native/image-crop'
33
+ import { schedulerParts } from '../../native/date-format'
34
+ import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
35
+ import { MBox, MColumn, MRow } from './layout.js'
36
+ import { MStack } from './MStack.js'
37
+ import { MCard } from './MCard.js'
38
+ import { MText } from './MText.js'
39
+ import { MButton } from './MButton.js'
40
+ import { MInput } from './MInput.js'
41
+ import { MImage } from './MImage.js'
42
+ import { MCheckbox } from './MCheckbox.js'
43
+ import { MSlider } from './MSlider.js'
44
+ import { MPopover } from './MPopover.js'
45
+
46
+ const Host = defineComponent({
47
+ inheritAttrs: false,
48
+ props: { label: String },
49
+ setup(props, { attrs, slots, expose }) {
50
+ let view: View | undefined
51
+ expose({
52
+ focus(id?: string) {
53
+ const target = (id ? view?.getViewById(id) : view) as View | undefined
54
+ if (target) {
55
+ target.focus()
56
+ notifyAccessibilityLayout(target)
57
+ }
58
+ },
59
+ })
60
+ return () =>
61
+ h(
62
+ 'GridLayout',
63
+ mergeProps(attrs, {
64
+ width: '100%',
65
+ accessibilityLabel: props.label,
66
+ onLoaded: (e: EventData) => (view = e.object as View),
67
+ onUnloaded: () => (view = undefined),
68
+ }),
69
+ slots.default?.(),
70
+ )
71
+ },
72
+ })
73
+ const Measure = defineComponent({
74
+ emits: ['width'],
75
+ setup(_, { slots, emit }) {
76
+ let last = -1
77
+ const measure = (e: EventData) => {
78
+ const width = (e.object as View).getActualSize().width
79
+ if (Number.isFinite(width) && width > 0 && Math.abs(width - last) > 0.5) {
80
+ last = width
81
+ emit('width', width)
82
+ }
83
+ }
84
+ return () => h('GridLayout', { width: '100%', onLayoutChanged: measure }, slots.default?.())
85
+ },
86
+ })
87
+ const Canvas = defineComponent({
88
+ props: advancedCanvasProps,
89
+ setup(props, { slots }) {
90
+ return () =>
91
+ h('AbsoluteLayout', { width: props.width ?? '100%', height: props.height }, slots.default?.())
92
+ },
93
+ })
94
+ const Cell = defineComponent({
95
+ inheritAttrs: false,
96
+ props: advancedCellProps,
97
+ emits: ['height'],
98
+ setup(props, { attrs, slots, emit }) {
99
+ let last = -1
100
+ const measure = (e: EventData) => {
101
+ if (!props.measure) return
102
+ const height = (e.object as View).getActualSize().height
103
+ if (Number.isFinite(height) && height >= 0 && Math.abs(height - last) > 0.5) {
104
+ last = height
105
+ emit('height', height)
106
+ }
107
+ }
108
+ return () =>
109
+ h(
110
+ 'GridLayout',
111
+ mergeProps(attrs, {
112
+ left: props.x,
113
+ top: props.y,
114
+ width: props.width,
115
+ height: props.height,
116
+ verticalAlignment: 'top',
117
+ }),
118
+ [h(MBox, { width: '100%', height: props.height, onLayoutChanged: measure }, slots)],
119
+ )
120
+ },
121
+ })
122
+ const Scroll = defineComponent({
123
+ setup(_, { slots }) {
124
+ return () =>
125
+ h(
126
+ 'ScrollView',
127
+ { orientation: 'horizontal', width: '100%', scrollBarIndicatorVisible: true },
128
+ [h('StackLayout', { orientation: 'horizontal' }, slots.default?.())],
129
+ )
130
+ },
131
+ })
132
+ const Gesture = defineComponent({
133
+ inheritAttrs: false,
134
+ props: advancedGestureProps,
135
+ emits: ['gesture', 'step'],
136
+ setup(props, { attrs, slots, emit }) {
137
+ const active = new Set<string>()
138
+ let last = { x: 0, y: 0, scale: 1 }
139
+ function send(phase: AdvancedGesture['phase']) {
140
+ emit('gesture', { phase, ...last })
141
+ }
142
+ function cancel() {
143
+ if (active.size) send('cancel')
144
+ active.clear()
145
+ last = { x: 0, y: 0, scale: 1 }
146
+ }
147
+ function update(name: string, state: number, value: Partial<typeof last>) {
148
+ if (props.disabled) return
149
+ if (state === 1) {
150
+ if (!active.size) {
151
+ last = { x: 0, y: 0, scale: 1 }
152
+ send('start')
153
+ }
154
+ active.add(name)
155
+ }
156
+ if (state === 2 && active.has(name)) {
157
+ last = { ...last, ...value }
158
+ send('move')
159
+ }
160
+ if (state === 3 && active.has(name)) {
161
+ active.delete(name)
162
+ if (!active.size) {
163
+ send('end')
164
+ last = { x: 0, y: 0, scale: 1 }
165
+ }
166
+ }
167
+ if (state === 4) cancel()
168
+ }
169
+ let listening = false
170
+ function loaded() {
171
+ if (listening) return
172
+ listening = true
173
+ Application.on(Application.suspendEvent, cancel)
174
+ }
175
+ function unloaded() {
176
+ listening = false
177
+ cancel()
178
+ Application.off(Application.suspendEvent, cancel)
179
+ }
180
+ onBeforeUnmount(unloaded)
181
+ onDeactivated(unloaded)
182
+ onActivated(loaded)
183
+ watch(() => props.disabled, cancel)
184
+ return () =>
185
+ h(
186
+ 'GridLayout',
187
+ mergeProps(attrs, {
188
+ accessibilityLabel: props.label,
189
+ accessible: true,
190
+ isEnabled: !props.disabled,
191
+ onLoaded: loaded,
192
+ onUnloaded: unloaded,
193
+ onPan: (e: PanGestureEventData) => update('pan', e.state, { x: e.deltaX, y: e.deltaY }),
194
+ onPinch: (e: PinchGestureEventData) => update('pinch', e.state, { scale: e.scale }),
195
+ onTouch: (e: { action: string }) => {
196
+ if (e.action === 'cancel') cancel()
197
+ },
198
+ }),
199
+ slots.default?.(),
200
+ )
201
+ },
202
+ })
203
+ const CropPreview = defineComponent({
204
+ props: {
205
+ source: { type: Object as PropType<CropSource>, required: true },
206
+ width: Number,
207
+ height: Number,
208
+ motionSurface: Object as PropType<MotionSurface>,
209
+ },
210
+ setup(props) {
211
+ return () =>
212
+ h('AbsoluteLayout', { width: '100%', height: '100%', isUserInteractionEnabled: false }, [
213
+ h(
214
+ MBox,
215
+ {
216
+ left: 0,
217
+ top: 0,
218
+ width: props.width,
219
+ height: props.height,
220
+ motionSurface: props.motionSurface,
221
+ },
222
+ () =>
223
+ h('Image', {
224
+ src: props.source!.preview,
225
+ width: props.width,
226
+ height: props.height,
227
+ stretch: 'fill',
228
+ accessible: false,
229
+ }),
230
+ ),
231
+ ])
232
+ },
233
+ })
234
+ const ui = {
235
+ Box: MBox,
236
+ Column: MColumn,
237
+ Row: MRow,
238
+ Stack: MStack,
239
+ Card: MCard,
240
+ Text: MText,
241
+ Button: MButton,
242
+ Input: MInput,
243
+ Image: MImage,
244
+ Checkbox: MCheckbox,
245
+ Slider: MSlider,
246
+ Popover: MPopover,
247
+ Segmented: MBox,
248
+ Host,
249
+ Measure,
250
+ Cell,
251
+ Canvas,
252
+ Scroll,
253
+ Gesture,
254
+ CropPreview,
255
+ }
256
+ export const MTreeSelect = createTreeSelect(ui, 'native')
257
+ export const MMasonry = createMasonry(ui, 'native')
258
+ export const MHeatmap = createHeatmap(ui, 'native')
259
+ export const MNotificationCenter = createNotificationCenter(ui, 'native')
260
+ export const MImageCropper = createImageCropper(ui, 'native', loadCropImage)
261
+ export const MScheduler = createScheduler(ui, 'native', {
262
+ parts: (instant, timeZone) => schedulerParts(instant, { timeZone }),
263
+ })
@@ -0,0 +1,246 @@
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ mergeProps,
5
+ nextTick,
6
+ onBeforeUnmount,
7
+ onDeactivated,
8
+ watch,
9
+ type PropType,
10
+ } from 'nativescript-vue'
11
+ import {
12
+ Application,
13
+ ScrollView,
14
+ isAndroid,
15
+ isIOS,
16
+ type View,
17
+ type EventData,
18
+ } from '@nativescript/core'
19
+ import { reducedMotion, onReducedMotion } from '@rafaelaugusto/jolt'
20
+ import {
21
+ createColorPicker,
22
+ createGauge,
23
+ createSwipeDeck,
24
+ createTransferList,
25
+ createTour,
26
+ createMarquee,
27
+ tourHostProps,
28
+ marqueeHostProps,
29
+ } from '@getcortexlabs/mavis-core/vue'
30
+ import type { gaugeGeometry } from '@getcortexlabs/mavis-core'
31
+ import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
32
+ import { MBox, MColumn, MRow } from './layout.js'
33
+ import { MStack } from './MStack.js'
34
+ import { MCard } from './MCard.js'
35
+ import { MText } from './MText.js'
36
+ import { MInput } from './MInput.js'
37
+ import { MImage } from './MImage.js'
38
+ import { MButton } from './MButton.js'
39
+ import { MSlider } from './MSlider.js'
40
+ import { MCheckbox } from './MCheckbox.js'
41
+ import { MNumberFlow } from './interactive.js'
42
+ import { MPopover } from './MPopover.js'
43
+
44
+ const GaugeFallback = defineComponent({
45
+ props: {
46
+ geometry: Object as PropType<ReturnType<typeof gaugeGeometry>>,
47
+ size: Number,
48
+ strokeWidth: Number,
49
+ color: String,
50
+ track: String,
51
+ hidden: Boolean,
52
+ },
53
+ setup() {
54
+ return () => h('GridLayout', { accessible: false, isUserInteractionEnabled: false })
55
+ },
56
+ })
57
+ interface FocusView {
58
+ readonly isFirstResponder: boolean
59
+ readonly subviews: { count: number; objectAtIndex(index: number): FocusView }
60
+ readonly window?: FocusView
61
+ becomeFirstResponder(): boolean
62
+ }
63
+ const TourHost = defineComponent({
64
+ inheritAttrs: false,
65
+ props: tourHostProps,
66
+ setup(props, { attrs, slots }) {
67
+ let root: View | undefined,
68
+ restore = () => {}
69
+ function capture() {
70
+ if (!root?.isLoaded) return
71
+ if (isAndroid) {
72
+ const focused = root.page?.android?.findFocus?.()
73
+ restore = () => focused?.requestFocus?.()
74
+ } else if (isIOS) {
75
+ const find = (view: FocusView): FocusView | undefined => {
76
+ if (view.isFirstResponder) return view
77
+ for (let i = 0; i < view.subviews.count; i++) {
78
+ const result = find(view.subviews.objectAtIndex(i))
79
+ if (result) return result
80
+ }
81
+ }
82
+ const window = (root.ios as FocusView)?.window
83
+ const focused = window ? find(window) : undefined
84
+ restore = () => {
85
+ if (focused?.window) focused.becomeFirstResponder()
86
+ }
87
+ }
88
+ }
89
+ watch(
90
+ () => props.active,
91
+ (active) => {
92
+ if (active) capture()
93
+ else
94
+ void nextTick(() => {
95
+ if (root?.isLoaded && !props.active && props.restoreFocus) restore()
96
+ restore = () => {}
97
+ })
98
+ },
99
+ )
100
+ return () =>
101
+ h(
102
+ 'StackLayout',
103
+ mergeProps(attrs, {
104
+ onLoaded: (event: EventData) => {
105
+ root = event.object as View
106
+ if (props.active) capture()
107
+ },
108
+ onUnloaded: () => {
109
+ root = undefined
110
+ restore = () => {}
111
+ },
112
+ }),
113
+ slots.default?.(),
114
+ )
115
+ },
116
+ })
117
+ const TargetHost = defineComponent({
118
+ inheritAttrs: false,
119
+ props: tourHostProps,
120
+ setup(props, { attrs, slots }) {
121
+ let root: View | undefined
122
+ function reveal() {
123
+ if (!props.active || !root?.isLoaded) return
124
+ for (
125
+ let parent = root.parent as View | undefined;
126
+ parent;
127
+ parent = parent.parent as View | undefined
128
+ ) {
129
+ if (parent instanceof ScrollView) {
130
+ const location = root.getLocationRelativeTo(parent)
131
+ if (location) {
132
+ const size = root.getActualSize(),
133
+ viewport = parent.getActualSize()
134
+ if (location.y < 0)
135
+ parent.scrollToVerticalOffset(Math.max(0, parent.verticalOffset + location.y), false)
136
+ else if (location.y + size.height > viewport.height)
137
+ parent.scrollToVerticalOffset(
138
+ Math.max(0, parent.verticalOffset + location.y + size.height - viewport.height),
139
+ false,
140
+ )
141
+ }
142
+ break
143
+ }
144
+ }
145
+ notifyAccessibilityLayout(root)
146
+ }
147
+ watch(
148
+ () => props.active,
149
+ () => void nextTick(reveal),
150
+ { flush: 'post' },
151
+ )
152
+ return () =>
153
+ h(
154
+ 'GridLayout',
155
+ mergeProps(attrs, {
156
+ onLoaded: (event: EventData) => {
157
+ root = event.object as View
158
+ void nextTick(reveal)
159
+ },
160
+ onUnloaded: () => {
161
+ root = undefined
162
+ },
163
+ }),
164
+ slots.default?.(),
165
+ )
166
+ },
167
+ })
168
+ const MarqueeHost = defineComponent({
169
+ inheritAttrs: false,
170
+ props: marqueeHostProps,
171
+ emits: ['environment'],
172
+ setup(_props, { attrs, slots, emit }) {
173
+ let root: View | undefined,
174
+ suspended = false,
175
+ attached = false,
176
+ release = () => {}
177
+ const update = () =>
178
+ emit('environment', {
179
+ reduced: reducedMotion(),
180
+ paused: !attached || suspended,
181
+ width: root?.getActualSize().width ?? 0,
182
+ })
183
+ const suspend = () => {
184
+ suspended = true
185
+ update()
186
+ },
187
+ resume = () => {
188
+ suspended = false
189
+ update()
190
+ }
191
+ function detach() {
192
+ attached = false
193
+ release()
194
+ Application.off(Application.suspendEvent, suspend)
195
+ Application.off(Application.resumeEvent, resume)
196
+ update()
197
+ }
198
+ onBeforeUnmount(detach)
199
+ onDeactivated(detach)
200
+ return () =>
201
+ h(
202
+ 'GridLayout',
203
+ mergeProps(attrs, {
204
+ clipToBounds: true,
205
+ width: '100%',
206
+ onLoaded: (event: EventData) => {
207
+ root = event.object as View
208
+ if (attached) return
209
+ attached = true
210
+ release = onReducedMotion(update)
211
+ Application.on(Application.suspendEvent, suspend)
212
+ Application.on(Application.resumeEvent, resume)
213
+ update()
214
+ },
215
+ onUnloaded: detach,
216
+ onLayoutChanged: update,
217
+ }),
218
+ slots.default?.(),
219
+ )
220
+ },
221
+ })
222
+ const ui = {
223
+ Box: MBox,
224
+ Column: MColumn,
225
+ Row: MRow,
226
+ Stack: MStack,
227
+ Card: MCard,
228
+ Text: MText,
229
+ Input: MInput,
230
+ Image: MImage,
231
+ Button: MButton,
232
+ Slider: MSlider,
233
+ Checkbox: MCheckbox,
234
+ NumberFlow: MNumberFlow,
235
+ GaugeFallback,
236
+ MarqueeHost,
237
+ }
238
+ export const MColorPicker = createColorPicker(ui, 'native')
239
+ export const MGauge = createGauge(ui, 'native')
240
+ export const MSwipeDeck = createSwipeDeck(ui, 'native')
241
+ export const MTransferList = createTransferList(ui, 'native')
242
+ export const MMarquee = createMarquee(ui, 'native')
243
+ export const { MTour, MTourTarget } = createTour(
244
+ { ...ui, Popover: MPopover, Host: TourHost, TargetHost },
245
+ 'native',
246
+ )