@getcortexlabs/mavis 0.1.0-alpha.4 → 0.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/files.d.ts +4 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +3 -0
- package/dist/files.js.map +1 -0
- package/dist/native/combobox-editor.android.d.ts +3 -0
- package/dist/native/combobox-editor.android.d.ts.map +1 -0
- package/dist/native/combobox-editor.android.js +5 -0
- package/dist/native/combobox-editor.android.js.map +1 -0
- package/dist/native/combobox-editor.d.ts +4 -0
- package/dist/native/combobox-editor.d.ts.map +1 -0
- package/dist/native/combobox-editor.js +5 -0
- package/dist/native/combobox-editor.js.map +1 -0
- package/dist/native/file-access.d.ts +23 -0
- package/dist/native/file-access.d.ts.map +1 -0
- package/dist/native/file-access.js +55 -0
- package/dist/native/file-access.js.map +1 -0
- package/dist/native/file-picker.android.d.ts +3 -0
- package/dist/native/file-picker.android.d.ts.map +1 -0
- package/dist/native/file-picker.android.js +147 -0
- package/dist/native/file-picker.android.js.map +1 -0
- package/dist/native/file-picker.d.ts +4 -0
- package/dist/native/file-picker.d.ts.map +1 -0
- package/dist/native/file-picker.ios.d.ts +3 -0
- package/dist/native/file-picker.ios.d.ts.map +1 -0
- package/dist/native/file-picker.ios.js +152 -0
- package/dist/native/file-picker.ios.js.map +1 -0
- package/dist/native/file-picker.js +7 -0
- package/dist/native/file-picker.js.map +1 -0
- package/dist/native/motion-owner.d.ts +5 -0
- package/dist/native/motion-owner.d.ts.map +1 -0
- package/dist/native/motion-owner.js +53 -0
- package/dist/native/motion-owner.js.map +1 -0
- package/dist/native/motion-region.d.ts +6 -0
- package/dist/native/motion-region.d.ts.map +1 -0
- package/dist/native/motion-region.js +199 -0
- package/dist/native/motion-region.js.map +1 -0
- package/dist/native/motion-surface.d.ts +1 -1
- package/dist/native/motion-surface.d.ts.map +1 -1
- package/dist/native/motion-surface.js +18 -0
- package/dist/native/motion-surface.js.map +1 -1
- package/dist/native/scroll-motion.d.ts +1 -0
- package/dist/native/scroll-motion.d.ts.map +1 -1
- package/dist/native/scroll-motion.js +6 -0
- package/dist/native/scroll-motion.js.map +1 -1
- package/dist/vue/components/ChoiceControl.d.ts +21 -11
- package/dist/vue/components/ChoiceControl.d.ts.map +1 -1
- package/dist/vue/components/DateCalendar.d.ts +94 -0
- package/dist/vue/components/DateCalendar.d.ts.map +1 -0
- package/dist/vue/components/DateCalendar.js +96 -0
- package/dist/vue/components/DateCalendar.js.map +1 -0
- package/dist/vue/components/MAccordion.d.ts +19 -9
- package/dist/vue/components/MAccordion.d.ts.map +1 -1
- package/dist/vue/components/MAlert.d.ts +21 -11
- package/dist/vue/components/MAlert.d.ts.map +1 -1
- package/dist/vue/components/MAvatar.d.ts +12 -6
- package/dist/vue/components/MAvatar.d.ts.map +1 -1
- package/dist/vue/components/MBadge.d.ts +13 -7
- package/dist/vue/components/MBadge.d.ts.map +1 -1
- package/dist/vue/components/MButton.d.ts +81 -39
- package/dist/vue/components/MButton.d.ts.map +1 -1
- package/dist/vue/components/MCard.d.ts +46 -18
- package/dist/vue/components/MCard.d.ts.map +1 -1
- package/dist/vue/components/MCheckbox.d.ts +20 -10
- package/dist/vue/components/MCheckbox.d.ts.map +1 -1
- package/dist/vue/components/MChip.d.ts +23 -13
- package/dist/vue/components/MChip.d.ts.map +1 -1
- package/dist/vue/components/MCombobox.d.ts +279 -0
- package/dist/vue/components/MCombobox.d.ts.map +1 -0
- package/dist/vue/components/MCombobox.js +234 -0
- package/dist/vue/components/MCombobox.js.map +1 -0
- package/dist/vue/components/MDatePicker.d.ts +1254 -0
- package/dist/vue/components/MDatePicker.d.ts.map +1 -0
- package/dist/vue/components/MDatePicker.js +35 -0
- package/dist/vue/components/MDatePicker.js.map +1 -0
- package/dist/vue/components/MDialog.d.ts +7 -5
- package/dist/vue/components/MDialog.d.ts.map +1 -1
- package/dist/vue/components/MEmptyState.d.ts +20 -10
- package/dist/vue/components/MEmptyState.d.ts.map +1 -1
- package/dist/vue/components/MFilePicker.d.ts +112 -0
- package/dist/vue/components/MFilePicker.d.ts.map +1 -0
- package/dist/vue/components/MFilePicker.js +196 -0
- package/dist/vue/components/MFilePicker.js.map +1 -0
- package/dist/vue/components/MIcon.d.ts +5 -3
- package/dist/vue/components/MIcon.d.ts.map +1 -1
- package/dist/vue/components/MInput.d.ts +131 -59
- package/dist/vue/components/MInput.d.ts.map +1 -1
- package/dist/vue/components/MListItem.d.ts +24 -12
- package/dist/vue/components/MListItem.d.ts.map +1 -1
- package/dist/vue/components/MProgress.d.ts +19 -9
- package/dist/vue/components/MProgress.d.ts.map +1 -1
- package/dist/vue/components/MRadioGroup.d.ts +19 -9
- package/dist/vue/components/MRadioGroup.d.ts.map +1 -1
- package/dist/vue/components/MReveal.d.ts +73 -37
- package/dist/vue/components/MReveal.d.ts.map +1 -1
- package/dist/vue/components/MScreen.d.ts +12 -6
- package/dist/vue/components/MScreen.d.ts.map +1 -1
- package/dist/vue/components/MSegmentedControl.d.ts +19 -9
- package/dist/vue/components/MSegmentedControl.d.ts.map +1 -1
- package/dist/vue/components/MSelect.d.ts +21 -11
- package/dist/vue/components/MSelect.d.ts.map +1 -1
- package/dist/vue/components/MSeparator.d.ts +4 -2
- package/dist/vue/components/MSeparator.d.ts.map +1 -1
- package/dist/vue/components/MSheet.d.ts +19 -13
- package/dist/vue/components/MSheet.d.ts.map +1 -1
- package/dist/vue/components/MSkeleton.d.ts +17 -9
- package/dist/vue/components/MSkeleton.d.ts.map +1 -1
- package/dist/vue/components/MSlider.d.ts +9 -5
- package/dist/vue/components/MSlider.d.ts.map +1 -1
- package/dist/vue/components/MSwitch.d.ts +19 -9
- package/dist/vue/components/MSwitch.d.ts.map +1 -1
- package/dist/vue/components/MTabs.d.ts +19 -9
- package/dist/vue/components/MTabs.d.ts.map +1 -1
- package/dist/vue/components/MText.d.ts +46 -30
- package/dist/vue/components/MText.d.ts.map +1 -1
- package/dist/vue/components/layout.d.ts +200 -91
- package/dist/vue/components/layout.d.ts.map +1 -1
- package/dist/vue/components/layout.js +6 -4
- package/dist/vue/components/layout.js.map +1 -1
- package/dist/vue/components/workflows.d.ts +251 -0
- package/dist/vue/components/workflows.d.ts.map +1 -0
- package/dist/vue/components/workflows.js +35 -0
- package/dist/vue/components/workflows.js.map +1 -0
- package/dist/vue/index.d.ts +7 -2
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +15 -2
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/use-motion-region.d.ts +7 -0
- package/dist/vue/use-motion-region.d.ts.map +1 -0
- package/dist/vue/use-motion-region.js +28 -0
- package/dist/vue/use-motion-region.js.map +1 -0
- package/dist/vue/use-motion-surface.d.ts.map +1 -1
- package/dist/vue/use-motion-surface.js +3 -2
- package/dist/vue/use-motion-surface.js.map +1 -1
- package/package.json +3 -3
- package/src/files.ts +3 -0
- package/src/native/combobox-editor.android.ts +11 -0
- package/src/native/combobox-editor.ts +6 -0
- package/src/native/file-access.ts +71 -0
- package/src/native/file-picker.android.ts +191 -0
- package/src/native/file-picker.ios.ts +230 -0
- package/src/native/file-picker.ts +8 -0
- package/src/native/motion-owner.ts +59 -0
- package/src/native/motion-region.ts +213 -0
- package/src/native/motion-surface.ts +26 -1
- package/src/native/scroll-motion.ts +5 -0
- package/src/vue/components/DateCalendar.ts +117 -0
- package/src/vue/components/MCombobox.ts +257 -0
- package/src/vue/components/MDatePicker.ts +33 -0
- package/src/vue/components/MFilePicker.ts +226 -0
- package/src/vue/components/layout.ts +6 -3
- package/src/vue/components/workflows.ts +38 -0
- package/src/vue/index.ts +29 -1
- package/src/vue/use-motion-region.ts +29 -0
- package/src/vue/use-motion-surface.ts +21 -14
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { nativeScrollMotion } from './scroll-motion.js'
|
|
2
|
+
import { assertNativeRegion } from './motion-region.js'
|
|
2
3
|
import type { View, EventData, TouchGestureEventData } from '@nativescript/core'
|
|
3
4
|
import {
|
|
4
5
|
bind,
|
|
@@ -24,8 +25,32 @@ export function nativeContinuousSurface(target: View, enabled: () => boolean) {
|
|
|
24
25
|
let suppressUntil = 0
|
|
25
26
|
const adapter: Pick<
|
|
26
27
|
MotionSurfaceAdapter,
|
|
27
|
-
|
|
28
|
+
| 'motionValue'
|
|
29
|
+
| 'springValue'
|
|
30
|
+
| 'bind'
|
|
31
|
+
| 'drag'
|
|
32
|
+
| 'map'
|
|
33
|
+
| 'refresh'
|
|
34
|
+
| 'scrollLinked'
|
|
35
|
+
| 'pointerFollow'
|
|
28
36
|
> = {
|
|
37
|
+
pointerFollow(region, options) {
|
|
38
|
+
assertNativeRegion(region, target)
|
|
39
|
+
const x = adapter.motionValue!(options.rest?.x ?? 0)
|
|
40
|
+
const y = adapter.motionValue!(options.rest?.y ?? 0)
|
|
41
|
+
return {
|
|
42
|
+
x,
|
|
43
|
+
y,
|
|
44
|
+
execution: 'static',
|
|
45
|
+
active: false,
|
|
46
|
+
update() {},
|
|
47
|
+
refresh() {},
|
|
48
|
+
dispose() {
|
|
49
|
+
x.dispose()
|
|
50
|
+
y.dispose()
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
},
|
|
29
54
|
scrollLinked(source, frames, options) {
|
|
30
55
|
interrupt(Object.keys(frames))
|
|
31
56
|
const scroll = nativeScrollMotion(source, target, frames, options)
|
|
@@ -9,6 +9,11 @@ import {
|
|
|
9
9
|
} from '@getcortexlabs/mavis-core/experimental'
|
|
10
10
|
|
|
11
11
|
const sources = new WeakMap<MotionScrollAdapter, ScrollView>()
|
|
12
|
+
export function nativeScrollElement(adapter: MotionScrollAdapter) {
|
|
13
|
+
const source = sources.get(adapter)
|
|
14
|
+
if (!source) throw new TypeError('Use a scrolling native MScreen.')
|
|
15
|
+
return source
|
|
16
|
+
}
|
|
12
17
|
export function attachNativeScrollSource(reference: MotionScrollSource, source: ScrollView) {
|
|
13
18
|
const adapter: MotionScrollAdapter = { kind: 'native' }
|
|
14
19
|
sources.set(adapter, source)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { defineComponent, h } from 'nativescript-vue'
|
|
2
|
+
import { calendarDayLabel } from '@getcortexlabs/mavis-core'
|
|
3
|
+
import {
|
|
4
|
+
dateCalendarProps,
|
|
5
|
+
dateCalendarEmits,
|
|
6
|
+
useDateCalendar,
|
|
7
|
+
useMavisTheme,
|
|
8
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
9
|
+
import { MButton } from './MButton.js'
|
|
10
|
+
import { MText } from './MText.js'
|
|
11
|
+
import { MColumn, MRow } from './layout.js'
|
|
12
|
+
|
|
13
|
+
/** @internal Natural-size native buttons; horizontal scrolling preserves large text and targets. */
|
|
14
|
+
export const DateCalendar = defineComponent({
|
|
15
|
+
name: 'DateCalendar',
|
|
16
|
+
props: dateCalendarProps,
|
|
17
|
+
emits: dateCalendarEmits,
|
|
18
|
+
setup(props, { emit }) {
|
|
19
|
+
const { theme } = useMavisTheme()
|
|
20
|
+
const calendar = useDateCalendar(props, (value) => emit('update:activeDate', value))
|
|
21
|
+
return () => {
|
|
22
|
+
const { colors, radius } = theme.value
|
|
23
|
+
return h(
|
|
24
|
+
MColumn,
|
|
25
|
+
{ gap: 'sm' },
|
|
26
|
+
{
|
|
27
|
+
default: () => [
|
|
28
|
+
h(
|
|
29
|
+
MRow,
|
|
30
|
+
{ justify: 'between', gap: 'sm', wrap: true },
|
|
31
|
+
{
|
|
32
|
+
default: () => [
|
|
33
|
+
h(MButton, {
|
|
34
|
+
icon: 'chevron-left',
|
|
35
|
+
variant: 'ghost',
|
|
36
|
+
accessibilityLabel: calendar.words.value.previous,
|
|
37
|
+
disabled: !calendar.canPage(-1),
|
|
38
|
+
onClick: () => calendar.page(-1),
|
|
39
|
+
}),
|
|
40
|
+
h(MText, {
|
|
41
|
+
text: calendar.title.value,
|
|
42
|
+
weight: '600',
|
|
43
|
+
shrink: 1,
|
|
44
|
+
accessibilityLiveRegion: 'polite',
|
|
45
|
+
}),
|
|
46
|
+
h(MButton, {
|
|
47
|
+
icon: 'chevron-right',
|
|
48
|
+
variant: 'ghost',
|
|
49
|
+
accessibilityLabel: calendar.words.value.next,
|
|
50
|
+
disabled: !calendar.canPage(1),
|
|
51
|
+
onClick: () => calendar.page(1),
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
),
|
|
56
|
+
h('ScrollView', { orientation: 'horizontal' }, [
|
|
57
|
+
h(
|
|
58
|
+
'GridLayout',
|
|
59
|
+
{
|
|
60
|
+
columns: 'auto,auto,auto,auto,auto,auto,auto',
|
|
61
|
+
rows: Array.from(
|
|
62
|
+
{ length: calendar.cells.value.length / 7 + 1 },
|
|
63
|
+
() => 'auto',
|
|
64
|
+
).join(','),
|
|
65
|
+
},
|
|
66
|
+
[
|
|
67
|
+
...calendar.weekdays.value.map((weekday, column) =>
|
|
68
|
+
h(MText, {
|
|
69
|
+
key: `weekday-${weekday}`,
|
|
70
|
+
row: 0,
|
|
71
|
+
col: column,
|
|
72
|
+
text: calendar.words.value.shortWeekdays[weekday],
|
|
73
|
+
variant: 'caption',
|
|
74
|
+
tone: 'muted',
|
|
75
|
+
accessibilityLabel: calendar.words.value.weekdays[weekday],
|
|
76
|
+
style: { minWidth: 48, textAlignment: 'center', padding: 8 },
|
|
77
|
+
}),
|
|
78
|
+
),
|
|
79
|
+
...calendar.cells.value.map((date, index) => {
|
|
80
|
+
if (!date) return null
|
|
81
|
+
const selected = date === props.selected
|
|
82
|
+
return h(MButton, {
|
|
83
|
+
key: date,
|
|
84
|
+
row: Math.floor(index / 7) + 1,
|
|
85
|
+
col: index % 7,
|
|
86
|
+
text: String(Number(date.slice(8))),
|
|
87
|
+
variant: 'ghost',
|
|
88
|
+
accessibilityLabel: calendarDayLabel(date, props.locale),
|
|
89
|
+
accessibilityValue: selected ? calendar.words.value.selected : '',
|
|
90
|
+
disabled: !calendar.available(date),
|
|
91
|
+
style: {
|
|
92
|
+
minWidth: 48,
|
|
93
|
+
minHeight: 48,
|
|
94
|
+
margin: 1,
|
|
95
|
+
paddingLeft: 6,
|
|
96
|
+
paddingRight: 6,
|
|
97
|
+
borderWidth: 2,
|
|
98
|
+
borderColor: selected ? colors.primary : 'transparent',
|
|
99
|
+
borderRadius: radius.sm,
|
|
100
|
+
backgroundColor:
|
|
101
|
+
selected || calendar.inRange(date) ? colors.primarySoft : 'transparent',
|
|
102
|
+
color: colors.text,
|
|
103
|
+
},
|
|
104
|
+
onClick: () => {
|
|
105
|
+
if (calendar.available(date)) emit('select', date)
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
}),
|
|
109
|
+
],
|
|
110
|
+
),
|
|
111
|
+
]),
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
})
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
h,
|
|
4
|
+
mergeProps,
|
|
5
|
+
onBeforeUnmount,
|
|
6
|
+
nextTick,
|
|
7
|
+
ref,
|
|
8
|
+
watch,
|
|
9
|
+
} from 'nativescript-vue'
|
|
10
|
+
import { TextField, isAndroid, type EventData, type View } from '@nativescript/core'
|
|
11
|
+
import { choiceKey, type InputHandle } from '@getcortexlabs/mavis-core'
|
|
12
|
+
import {
|
|
13
|
+
comboboxProps,
|
|
14
|
+
comboboxEmits,
|
|
15
|
+
useCombobox,
|
|
16
|
+
useButtonAction,
|
|
17
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
18
|
+
import { comboboxComposing } from '../../native/combobox-editor'
|
|
19
|
+
import { MColumn, MRow } from './layout.js'
|
|
20
|
+
import { MInput } from './MInput.js'
|
|
21
|
+
import { MButton } from './MButton.js'
|
|
22
|
+
import { MText } from './MText.js'
|
|
23
|
+
import { ChoiceControl } from './ChoiceControl.js'
|
|
24
|
+
|
|
25
|
+
const Combobox = defineComponent({
|
|
26
|
+
name: 'MCombobox',
|
|
27
|
+
inheritAttrs: false,
|
|
28
|
+
props: comboboxProps,
|
|
29
|
+
emits: comboboxEmits,
|
|
30
|
+
setup(props, { attrs, emit, expose }) {
|
|
31
|
+
useButtonAction()
|
|
32
|
+
const combo = useCombobox(props, emit)
|
|
33
|
+
const input = ref<InputHandle>()
|
|
34
|
+
let nativeEditor: TextField | undefined
|
|
35
|
+
let compositionTimer: ReturnType<typeof setTimeout> | undefined
|
|
36
|
+
let editTimer: ReturnType<typeof setTimeout> | undefined
|
|
37
|
+
let blurTimer: ReturnType<typeof setTimeout> | undefined
|
|
38
|
+
function clearTimers() {
|
|
39
|
+
clearTimeout(compositionTimer)
|
|
40
|
+
clearTimeout(blurTimer)
|
|
41
|
+
clearTimeout(editTimer)
|
|
42
|
+
compositionTimer = blurTimer = editTimer = undefined
|
|
43
|
+
}
|
|
44
|
+
function close() {
|
|
45
|
+
clearTimers()
|
|
46
|
+
combo.close()
|
|
47
|
+
}
|
|
48
|
+
function unload() {
|
|
49
|
+
close()
|
|
50
|
+
nativeEditor = undefined
|
|
51
|
+
}
|
|
52
|
+
onBeforeUnmount(unload)
|
|
53
|
+
watch(combo.open, (open) => {
|
|
54
|
+
if (!open) clearTimers()
|
|
55
|
+
})
|
|
56
|
+
function finishComposition() {
|
|
57
|
+
clearTimeout(compositionTimer)
|
|
58
|
+
compositionTimer = undefined
|
|
59
|
+
if (!combo.open.value || !nativeEditor?.isLoaded) return
|
|
60
|
+
if (comboboxComposing(nativeEditor)) compositionTimer = setTimeout(finishComposition, 30)
|
|
61
|
+
else applyEdit(nativeEditor.text ?? '')
|
|
62
|
+
}
|
|
63
|
+
function applyEdit(value: string) {
|
|
64
|
+
if (comboboxComposing(nativeEditor)) {
|
|
65
|
+
combo.startComposition()
|
|
66
|
+
combo.edit(value)
|
|
67
|
+
clearTimeout(compositionTimer)
|
|
68
|
+
compositionTimer = setTimeout(finishComposition, 30)
|
|
69
|
+
} else if (combo.composing.value) combo.endComposition(value)
|
|
70
|
+
else combo.edit(value)
|
|
71
|
+
const field = nativeEditor
|
|
72
|
+
void nextTick(() => {
|
|
73
|
+
// Native text is mutable before Vue receives textChange. A rejected query
|
|
74
|
+
// can leave equal old/new props, so only rejection needs an explicit repair.
|
|
75
|
+
if (
|
|
76
|
+
field &&
|
|
77
|
+
nativeEditor === field &&
|
|
78
|
+
field.isLoaded &&
|
|
79
|
+
!combo.composing.value &&
|
|
80
|
+
props.query !== value &&
|
|
81
|
+
field.text === value
|
|
82
|
+
)
|
|
83
|
+
field.text = props.query
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
function edit(value: string) {
|
|
87
|
+
// Native text notifications can precede the IME attaching its composing span.
|
|
88
|
+
// Inspect on the next turn, before even a zero-debounce search is allowed to start.
|
|
89
|
+
clearTimeout(editTimer)
|
|
90
|
+
editTimer = setTimeout(() => {
|
|
91
|
+
editTimer = undefined
|
|
92
|
+
if (nativeEditor?.isLoaded) applyEdit(value)
|
|
93
|
+
}, 0)
|
|
94
|
+
}
|
|
95
|
+
function findEditor(view: View) {
|
|
96
|
+
if (view instanceof TextField) {
|
|
97
|
+
nativeEditor = view
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
view.eachChild?.((child) => {
|
|
101
|
+
findEditor(child as View)
|
|
102
|
+
return !nativeEditor
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
const focus = () => {
|
|
106
|
+
if (!props.disabled) input.value?.focus()
|
|
107
|
+
}
|
|
108
|
+
const blur = () => {
|
|
109
|
+
close()
|
|
110
|
+
input.value?.blur()
|
|
111
|
+
}
|
|
112
|
+
expose({ focus, blur } satisfies InputHandle)
|
|
113
|
+
return () => {
|
|
114
|
+
const state = combo.state.value
|
|
115
|
+
const selected = combo.selected.value
|
|
116
|
+
const status =
|
|
117
|
+
state.status === 'loading' || state.status === 'debouncing'
|
|
118
|
+
? props.loadingText
|
|
119
|
+
: state.status === 'error'
|
|
120
|
+
? props.searchErrorText
|
|
121
|
+
: state.status === 'empty'
|
|
122
|
+
? props.emptyText
|
|
123
|
+
: state.status === 'idle'
|
|
124
|
+
? props.idleText
|
|
125
|
+
: state.limited
|
|
126
|
+
? props.limitedText
|
|
127
|
+
: ''
|
|
128
|
+
void combo.revision.value
|
|
129
|
+
return h(
|
|
130
|
+
MColumn,
|
|
131
|
+
mergeProps(attrs, {
|
|
132
|
+
width: props.width,
|
|
133
|
+
grow: props.grow,
|
|
134
|
+
shrink: props.shrink,
|
|
135
|
+
gap: 'sm',
|
|
136
|
+
accessibilityHidden: props.accessibilityHidden,
|
|
137
|
+
onUnloaded: unload,
|
|
138
|
+
}),
|
|
139
|
+
{
|
|
140
|
+
default: () => [
|
|
141
|
+
h(MInput, {
|
|
142
|
+
ref: input,
|
|
143
|
+
id: props.id,
|
|
144
|
+
label: props.label,
|
|
145
|
+
modelValue: props.query,
|
|
146
|
+
placeholder: props.placeholder,
|
|
147
|
+
helperText: props.helperText,
|
|
148
|
+
error: props.error,
|
|
149
|
+
disabled: props.disabled,
|
|
150
|
+
type: 'search',
|
|
151
|
+
returnKey: 'search',
|
|
152
|
+
autocapitalize: 'none',
|
|
153
|
+
autocorrect: false,
|
|
154
|
+
trailingAction:
|
|
155
|
+
props.clearable && (props.query || props.modelValue !== null)
|
|
156
|
+
? { icon: 'x', label: props.clearLabel }
|
|
157
|
+
: undefined,
|
|
158
|
+
onAction: () => {
|
|
159
|
+
close()
|
|
160
|
+
combo.clear()
|
|
161
|
+
focus()
|
|
162
|
+
},
|
|
163
|
+
'onUpdate:modelValue': edit,
|
|
164
|
+
onLoaded: (event: EventData) => {
|
|
165
|
+
nativeEditor = undefined
|
|
166
|
+
findEditor(event.object as View)
|
|
167
|
+
},
|
|
168
|
+
onFocus: () => {
|
|
169
|
+
clearTimeout(blurTimer)
|
|
170
|
+
combo.show()
|
|
171
|
+
emit('focus')
|
|
172
|
+
},
|
|
173
|
+
onBlur: () => {
|
|
174
|
+
emit('blur')
|
|
175
|
+
// Let a result's tap commit before closing the results on an unrelated focus move.
|
|
176
|
+
blurTimer = setTimeout(close, 0)
|
|
177
|
+
},
|
|
178
|
+
onSubmit: () => {
|
|
179
|
+
if (!combo.composing.value) {
|
|
180
|
+
combo.show()
|
|
181
|
+
combo.retry()
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
}),
|
|
185
|
+
selected && props.query !== selected.label
|
|
186
|
+
? h(MText, { text: selected.label, variant: 'caption', tone: 'primary' })
|
|
187
|
+
: null,
|
|
188
|
+
combo.open.value
|
|
189
|
+
? h(
|
|
190
|
+
MColumn,
|
|
191
|
+
{ gap: 'xs' },
|
|
192
|
+
{
|
|
193
|
+
default: () => [
|
|
194
|
+
...state.options.map((option) =>
|
|
195
|
+
h(ChoiceControl, {
|
|
196
|
+
key: choiceKey(option.value),
|
|
197
|
+
radio: true,
|
|
198
|
+
pressFeedback: !isAndroid,
|
|
199
|
+
label: option.label,
|
|
200
|
+
helperText: option.helperText,
|
|
201
|
+
modelValue: option.value === props.modelValue,
|
|
202
|
+
disabled: props.disabled || option.disabled,
|
|
203
|
+
onActivate: () => {
|
|
204
|
+
clearTimers()
|
|
205
|
+
combo.choose(option)
|
|
206
|
+
if (!combo.open.value) input.value?.blur()
|
|
207
|
+
},
|
|
208
|
+
}),
|
|
209
|
+
),
|
|
210
|
+
status
|
|
211
|
+
? h(MText, {
|
|
212
|
+
text: status,
|
|
213
|
+
variant: 'caption',
|
|
214
|
+
tone: state.status === 'error' ? 'danger' : 'muted',
|
|
215
|
+
})
|
|
216
|
+
: null,
|
|
217
|
+
h(
|
|
218
|
+
MRow,
|
|
219
|
+
{ gap: 'sm', wrap: true },
|
|
220
|
+
{
|
|
221
|
+
default: () => [
|
|
222
|
+
state.status === 'error'
|
|
223
|
+
? h(MButton, {
|
|
224
|
+
text: props.retryLabel,
|
|
225
|
+
variant: 'ghost',
|
|
226
|
+
onClick: () => {
|
|
227
|
+
clearTimers()
|
|
228
|
+
combo.show()
|
|
229
|
+
combo.retry()
|
|
230
|
+
focus()
|
|
231
|
+
},
|
|
232
|
+
})
|
|
233
|
+
: null,
|
|
234
|
+
h(MButton, {
|
|
235
|
+
text: props.closeLabel,
|
|
236
|
+
variant: 'ghost',
|
|
237
|
+
onClick: () => {
|
|
238
|
+
combo.cancel()
|
|
239
|
+
blur()
|
|
240
|
+
},
|
|
241
|
+
}),
|
|
242
|
+
],
|
|
243
|
+
},
|
|
244
|
+
),
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
)
|
|
248
|
+
: null,
|
|
249
|
+
],
|
|
250
|
+
},
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
})
|
|
255
|
+
export const MCombobox = Combobox as typeof Combobox & {
|
|
256
|
+
new (): InstanceType<typeof Combobox> & InputHandle
|
|
257
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Utils, isAndroid, type View } from '@nativescript/core'
|
|
2
|
+
import { createDatePickers } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { MInput } from './MInput.js'
|
|
4
|
+
import { MButton } from './MButton.js'
|
|
5
|
+
import { MColumn, MRow } from './layout.js'
|
|
6
|
+
import { MSheet } from './MSheet.js'
|
|
7
|
+
import { DateCalendar } from './DateCalendar.js'
|
|
8
|
+
import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
|
|
9
|
+
|
|
10
|
+
function focusOpener(opener: unknown) {
|
|
11
|
+
const view = (opener as { $el?: { nativeView?: View } } | undefined)?.$el?.nativeView
|
|
12
|
+
view?.focus()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const { MDatePicker, MDateRangePicker } = createDatePickers({
|
|
16
|
+
Input: MInput,
|
|
17
|
+
Button: MButton,
|
|
18
|
+
Column: MColumn,
|
|
19
|
+
Row: MRow,
|
|
20
|
+
Sheet: MSheet,
|
|
21
|
+
Calendar: DateCalendar,
|
|
22
|
+
beforeOpen: (opener) => {
|
|
23
|
+
Utils.dismissKeyboard()
|
|
24
|
+
focusOpener(opener)
|
|
25
|
+
},
|
|
26
|
+
afterClose: (opener) => {
|
|
27
|
+
const view = (opener as { $el?: { nativeView?: View } } | undefined)?.$el?.nativeView
|
|
28
|
+
if (!view?.isLoaded) return
|
|
29
|
+
view.focus()
|
|
30
|
+
if (isAndroid) view.android.performAccessibilityAction(64, null)
|
|
31
|
+
else notifyAccessibilityLayout(view)
|
|
32
|
+
},
|
|
33
|
+
})
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
h,
|
|
4
|
+
mergeProps,
|
|
5
|
+
nextTick,
|
|
6
|
+
onBeforeUnmount,
|
|
7
|
+
onDeactivated,
|
|
8
|
+
shallowRef,
|
|
9
|
+
watch,
|
|
10
|
+
} from 'nativescript-vue'
|
|
11
|
+
import { filePickerProps, fileStatusText, useButtonAction } from '@getcortexlabs/mavis-core/vue'
|
|
12
|
+
import type { InputHandle } from '@getcortexlabs/mavis-core'
|
|
13
|
+
import { createNativeFilePicker } from '../../native/file-picker'
|
|
14
|
+
import { MColumn, MRow } from './layout.js'
|
|
15
|
+
import { MText } from './MText.js'
|
|
16
|
+
import { MButton } from './MButton.js'
|
|
17
|
+
import { MProgress } from './MProgress.js'
|
|
18
|
+
import { MCard } from './MCard.js'
|
|
19
|
+
import { Application, isAndroid, type EventData, type View } from '@nativescript/core'
|
|
20
|
+
|
|
21
|
+
const FilePicker = defineComponent({
|
|
22
|
+
name: 'MFilePicker',
|
|
23
|
+
inheritAttrs: false,
|
|
24
|
+
props: filePickerProps,
|
|
25
|
+
setup(props, { attrs, expose }) {
|
|
26
|
+
useButtonAction()
|
|
27
|
+
const state = shallowRef(props.selection.state)
|
|
28
|
+
const picker = createNativeFilePicker()
|
|
29
|
+
let chooseView: View | undefined
|
|
30
|
+
let loaded = false
|
|
31
|
+
let unsubscribe = () => {}
|
|
32
|
+
watch(
|
|
33
|
+
() => props.selection,
|
|
34
|
+
(selection, previous) => {
|
|
35
|
+
previous?.pause()
|
|
36
|
+
unsubscribe()
|
|
37
|
+
state.value = selection.state
|
|
38
|
+
unsubscribe = selection.subscribe((value) => {
|
|
39
|
+
state.value = value
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
{ immediate: true, flush: 'sync' },
|
|
43
|
+
)
|
|
44
|
+
watch(
|
|
45
|
+
() => props.disabled,
|
|
46
|
+
(disabled) => {
|
|
47
|
+
if (disabled) props.selection.pause()
|
|
48
|
+
},
|
|
49
|
+
)
|
|
50
|
+
function unload() {
|
|
51
|
+
loaded = false
|
|
52
|
+
// Android stops/unloads the owner Activity when its system document picker opens.
|
|
53
|
+
// Keep that intentional handoff alive; route unloads and component disposal still cancel.
|
|
54
|
+
if (isAndroid && Application.android.paused && props.selection.state.picking) {
|
|
55
|
+
for (const item of props.selection.state.items) props.selection.cancel(item.id)
|
|
56
|
+
} else props.selection.pause()
|
|
57
|
+
chooseView = undefined
|
|
58
|
+
}
|
|
59
|
+
onDeactivated(() => props.selection.pause())
|
|
60
|
+
onBeforeUnmount(() => {
|
|
61
|
+
unsubscribe()
|
|
62
|
+
props.selection.pause()
|
|
63
|
+
unload()
|
|
64
|
+
})
|
|
65
|
+
function focusChoose() {
|
|
66
|
+
if (loaded && !props.disabled && !state.value.picking) chooseView?.focus()
|
|
67
|
+
}
|
|
68
|
+
expose({
|
|
69
|
+
focus: focusChoose,
|
|
70
|
+
blur: () => {
|
|
71
|
+
chooseView?.android?.clearFocus()
|
|
72
|
+
chooseView?.ios?.resignFirstResponder()
|
|
73
|
+
},
|
|
74
|
+
} satisfies InputHandle)
|
|
75
|
+
function choose() {
|
|
76
|
+
if (!loaded || props.disabled || state.value.picking) return
|
|
77
|
+
const selection = props.selection
|
|
78
|
+
void selection.select(picker).finally(async () => {
|
|
79
|
+
await nextTick()
|
|
80
|
+
if (props.selection === selection) focusChoose()
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
return () => {
|
|
84
|
+
if (!props.label.trim()) throw new TypeError('FilePicker needs a non-empty label')
|
|
85
|
+
const selection = props.selection
|
|
86
|
+
return h(
|
|
87
|
+
MColumn,
|
|
88
|
+
mergeProps(attrs, {
|
|
89
|
+
gap: 'md',
|
|
90
|
+
onLoaded: () => {
|
|
91
|
+
loaded = true
|
|
92
|
+
},
|
|
93
|
+
onUnloaded: unload,
|
|
94
|
+
}),
|
|
95
|
+
{
|
|
96
|
+
default: () => [
|
|
97
|
+
h(MText, { text: props.label, weight: '600' }),
|
|
98
|
+
h(
|
|
99
|
+
MRow,
|
|
100
|
+
{ gap: 'sm', wrap: true },
|
|
101
|
+
{
|
|
102
|
+
default: () => [
|
|
103
|
+
h(MButton, {
|
|
104
|
+
text: props.chooseLabel,
|
|
105
|
+
variant: 'secondary',
|
|
106
|
+
disabled: props.disabled || state.value.picking,
|
|
107
|
+
accessibilityLabel: `${props.chooseLabel}: ${props.label}`,
|
|
108
|
+
onClick: choose,
|
|
109
|
+
onLoaded: (event: EventData) => {
|
|
110
|
+
chooseView = event.object as View
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
state.value.picking
|
|
114
|
+
? h(MButton, {
|
|
115
|
+
text: props.cancelLabel,
|
|
116
|
+
variant: 'ghost',
|
|
117
|
+
onClick: () => {
|
|
118
|
+
selection.cancelSelection()
|
|
119
|
+
focusChoose()
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
: null,
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
),
|
|
126
|
+
state.value.error
|
|
127
|
+
? h(MText, {
|
|
128
|
+
text: props.errorLabels[state.value.error.code] ?? state.value.error.message,
|
|
129
|
+
tone: 'danger',
|
|
130
|
+
})
|
|
131
|
+
: null,
|
|
132
|
+
!state.value.items.length ? h(MText, { text: props.emptyLabel, tone: 'muted' }) : null,
|
|
133
|
+
...state.value.items.map((item) => {
|
|
134
|
+
const preview = selection.preview(item.id)
|
|
135
|
+
const status = fileStatusText(item, props.statusLabels)
|
|
136
|
+
return h(
|
|
137
|
+
MCard,
|
|
138
|
+
{ key: item.id, gap: 'sm' },
|
|
139
|
+
{
|
|
140
|
+
default: () => [
|
|
141
|
+
preview
|
|
142
|
+
? h('Image', {
|
|
143
|
+
src: preview,
|
|
144
|
+
width: 80,
|
|
145
|
+
height: 80,
|
|
146
|
+
stretch: 'aspectFit',
|
|
147
|
+
horizontalAlignment: 'left',
|
|
148
|
+
accessible: false,
|
|
149
|
+
accessibilityHidden: true,
|
|
150
|
+
})
|
|
151
|
+
: null,
|
|
152
|
+
h(MText, { text: item.name, weight: '600' }),
|
|
153
|
+
h(MText, {
|
|
154
|
+
text: `${status}${item.size === undefined ? '' : ` · ${item.size} B`}`,
|
|
155
|
+
variant: 'caption',
|
|
156
|
+
tone:
|
|
157
|
+
item.status === 'failed'
|
|
158
|
+
? 'danger'
|
|
159
|
+
: item.status === 'uploaded'
|
|
160
|
+
? 'success'
|
|
161
|
+
: 'muted',
|
|
162
|
+
}),
|
|
163
|
+
item.status === 'uploading'
|
|
164
|
+
? h(MProgress, {
|
|
165
|
+
value: (item.progress ?? 0) * 100,
|
|
166
|
+
indeterminate: item.progress === undefined,
|
|
167
|
+
label: `${props.uploadLabel}: ${item.name}`,
|
|
168
|
+
indeterminateLabel: props.pendingLabel,
|
|
169
|
+
})
|
|
170
|
+
: null,
|
|
171
|
+
item.error
|
|
172
|
+
? h(MText, { text: item.error, tone: 'danger', variant: 'caption' })
|
|
173
|
+
: null,
|
|
174
|
+
h(
|
|
175
|
+
MRow,
|
|
176
|
+
{ gap: 'sm', wrap: true },
|
|
177
|
+
{
|
|
178
|
+
default: () => [
|
|
179
|
+
item.status === 'uploading'
|
|
180
|
+
? h(MButton, {
|
|
181
|
+
text: props.cancelLabel,
|
|
182
|
+
accessibilityLabel: `${props.cancelLabel}: ${item.name}`,
|
|
183
|
+
variant: 'secondary',
|
|
184
|
+
disabled: props.disabled,
|
|
185
|
+
onClick: () => selection.cancel(item.id),
|
|
186
|
+
})
|
|
187
|
+
: selection.canUpload && item.status !== 'uploaded'
|
|
188
|
+
? h(MButton, {
|
|
189
|
+
text:
|
|
190
|
+
item.status === 'failed' || item.status === 'cancelled'
|
|
191
|
+
? props.retryLabel
|
|
192
|
+
: props.uploadLabel,
|
|
193
|
+
accessibilityLabel: `${item.status === 'failed' || item.status === 'cancelled' ? props.retryLabel : props.uploadLabel}: ${item.name}`,
|
|
194
|
+
disabled: props.disabled || !selection.hasFile(item.id),
|
|
195
|
+
onClick: () => {
|
|
196
|
+
void selection.upload(item.id)
|
|
197
|
+
},
|
|
198
|
+
})
|
|
199
|
+
: null,
|
|
200
|
+
h(MButton, {
|
|
201
|
+
text: props.removeLabel,
|
|
202
|
+
accessibilityLabel: `${props.removeLabel}: ${item.name}`,
|
|
203
|
+
variant: 'ghost',
|
|
204
|
+
disabled: props.disabled,
|
|
205
|
+
onClick: () => {
|
|
206
|
+
focusChoose()
|
|
207
|
+
selection.remove(item.id)
|
|
208
|
+
},
|
|
209
|
+
}),
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
),
|
|
213
|
+
],
|
|
214
|
+
},
|
|
215
|
+
)
|
|
216
|
+
}),
|
|
217
|
+
],
|
|
218
|
+
},
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
export const MFilePicker = FilePicker as typeof FilePicker & {
|
|
225
|
+
new (): InstanceType<typeof FilePicker> & InputHandle
|
|
226
|
+
}
|