@getcortexlabs/mavis-web 0.1.0-alpha.4 → 0.1.0-alpha.6
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 +5 -3
- package/dist/components/DateCalendar.d.ts +95 -0
- package/dist/components/DateCalendar.d.ts.map +1 -0
- package/dist/components/DateCalendar.js +157 -0
- package/dist/components/DateCalendar.js.map +1 -0
- package/dist/components/MAccordion.d.ts +19 -9
- package/dist/components/MAccordion.d.ts.map +1 -1
- package/dist/components/MAlert.d.ts +20 -10
- package/dist/components/MAlert.d.ts.map +1 -1
- package/dist/components/MAvatar.d.ts +13 -7
- package/dist/components/MAvatar.d.ts.map +1 -1
- package/dist/components/MBadge.d.ts +12 -6
- package/dist/components/MBadge.d.ts.map +1 -1
- package/dist/components/MButton.d.ts +129 -41
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MButton.js +13 -8
- package/dist/components/MButton.js.map +1 -1
- package/dist/components/MCard.d.ts +89 -15
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +36 -30
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MCheckbox.d.ts +20 -10
- package/dist/components/MCheckbox.d.ts.map +1 -1
- package/dist/components/MCheckbox.js +22 -3
- package/dist/components/MCheckbox.js.map +1 -1
- package/dist/components/MChip.d.ts +22 -12
- package/dist/components/MChip.d.ts.map +1 -1
- package/dist/components/MCombobox.d.ts +282 -0
- package/dist/components/MCombobox.d.ts.map +1 -0
- package/dist/components/MCombobox.js +440 -0
- package/dist/components/MCombobox.js.map +1 -0
- package/dist/components/MDatePicker.d.ts +1302 -0
- package/dist/components/MDatePicker.d.ts.map +1 -0
- package/dist/components/MDatePicker.js +31 -0
- package/dist/components/MDatePicker.js.map +1 -0
- package/dist/components/MDialog.d.ts +7 -5
- package/dist/components/MDialog.d.ts.map +1 -1
- package/dist/components/MEmptyState.d.ts +19 -9
- package/dist/components/MEmptyState.d.ts.map +1 -1
- package/dist/components/MFilePicker.d.ts +112 -0
- package/dist/components/MFilePicker.d.ts.map +1 -0
- package/dist/components/MFilePicker.js +193 -0
- package/dist/components/MFilePicker.js.map +1 -0
- package/dist/components/MIcon.d.ts +4 -2
- package/dist/components/MIcon.d.ts.map +1 -1
- package/dist/components/MInput.d.ts +135 -63
- package/dist/components/MInput.d.ts.map +1 -1
- package/dist/components/MInput.js +20 -4
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MLink.d.ts +120 -0
- package/dist/components/MLink.d.ts.map +1 -0
- package/dist/components/MLink.js +75 -0
- package/dist/components/MLink.js.map +1 -0
- package/dist/components/MListItem.d.ts +26 -12
- package/dist/components/MListItem.d.ts.map +1 -1
- package/dist/components/MProgress.d.ts +18 -8
- package/dist/components/MProgress.d.ts.map +1 -1
- package/dist/components/MRadioGroup.d.ts +19 -9
- package/dist/components/MRadioGroup.d.ts.map +1 -1
- package/dist/components/MRadioGroup.js +22 -0
- package/dist/components/MRadioGroup.js.map +1 -1
- package/dist/components/MReveal.d.ts +71 -35
- package/dist/components/MReveal.d.ts.map +1 -1
- package/dist/components/MReveal.js +39 -50
- package/dist/components/MReveal.js.map +1 -1
- package/dist/components/MScreen.d.ts +12 -6
- package/dist/components/MScreen.d.ts.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +19 -9
- package/dist/components/MSegmentedControl.d.ts.map +1 -1
- package/dist/components/MSelect.d.ts +21 -11
- package/dist/components/MSelect.d.ts.map +1 -1
- package/dist/components/MSeparator.d.ts +4 -2
- package/dist/components/MSeparator.d.ts.map +1 -1
- package/dist/components/MSheet.d.ts +18 -12
- package/dist/components/MSheet.d.ts.map +1 -1
- package/dist/components/MSheet.js +1 -1
- package/dist/components/MSheet.js.map +1 -1
- package/dist/components/MSkeleton.d.ts +16 -8
- package/dist/components/MSkeleton.d.ts.map +1 -1
- package/dist/components/MSlider.d.ts +10 -6
- package/dist/components/MSlider.d.ts.map +1 -1
- package/dist/components/MSlider.js +12 -1
- package/dist/components/MSlider.js.map +1 -1
- package/dist/components/MStack.d.ts +198 -0
- package/dist/components/MStack.d.ts.map +1 -0
- package/dist/components/MStack.js +62 -0
- package/dist/components/MStack.js.map +1 -0
- package/dist/components/MSwitch.d.ts +19 -9
- package/dist/components/MSwitch.d.ts.map +1 -1
- package/dist/components/MSwitch.js +3 -3
- package/dist/components/MSwitch.js.map +1 -1
- package/dist/components/MTabs.d.ts +19 -9
- package/dist/components/MTabs.d.ts.map +1 -1
- package/dist/components/MText.d.ts +44 -28
- package/dist/components/MText.d.ts.map +1 -1
- package/dist/components/MText.js +6 -6
- package/dist/components/MText.js.map +1 -1
- package/dist/components/layout.d.ts +367 -81
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +14 -12
- package/dist/components/layout.js.map +1 -1
- package/dist/components/workflows.d.ts +251 -0
- package/dist/components/workflows.d.ts.map +1 -0
- package/dist/components/workflows.js +23 -0
- package/dist/components/workflows.js.map +1 -0
- package/dist/connected-motion.d.ts +6 -0
- package/dist/connected-motion.d.ts.map +1 -0
- package/dist/connected-motion.js +18 -0
- package/dist/connected-motion.js.map +1 -0
- package/dist/experimental.d.ts +9 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +27 -0
- package/dist/experimental.js.map +1 -0
- package/dist/files.d.ts +6 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +82 -0
- package/dist/files.js.map +1 -0
- package/dist/hydration.d.ts +3 -0
- package/dist/hydration.d.ts.map +1 -0
- package/dist/hydration.js +20 -0
- package/dist/hydration.js.map +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -2
- package/dist/index.js.map +1 -1
- package/dist/motion-context.d.ts +13 -0
- package/dist/motion-context.d.ts.map +1 -0
- package/dist/motion-context.js +33 -0
- package/dist/motion-context.js.map +1 -0
- package/dist/motion-region.d.ts +16 -0
- package/dist/motion-region.d.ts.map +1 -0
- package/dist/motion-region.js +164 -0
- package/dist/motion-region.js.map +1 -0
- package/dist/motion-surface.d.ts +6 -2
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +71 -11
- package/dist/motion-surface.js.map +1 -1
- package/dist/motion.d.ts +3 -3
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +47 -30
- package/dist/motion.js.map +1 -1
- package/dist/navigation.d.ts +12 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +38 -0
- package/dist/navigation.js.map +1 -0
- package/dist/reveal-motion.d.ts +5 -0
- package/dist/reveal-motion.d.ts.map +1 -0
- package/dist/reveal-motion.js +53 -0
- package/dist/reveal-motion.js.map +1 -0
- package/dist/screen-viewport.d.ts.map +1 -1
- package/dist/screen-viewport.js +5 -0
- package/dist/screen-viewport.js.map +1 -1
- package/dist/scroll-motion.d.ts.map +1 -1
- package/dist/scroll-motion.js +16 -14
- package/dist/scroll-motion.js.map +1 -1
- package/dist/sheet-motion.d.ts.map +1 -1
- package/dist/sheet-motion.js +96 -62
- package/dist/sheet-motion.js.map +1 -1
- package/dist/tokens.d.ts +7 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +29 -0
- package/dist/tokens.js.map +1 -0
- package/package.json +7 -3
- package/src/components/DateCalendar.ts +213 -0
- package/src/components/MButton.ts +17 -7
- package/src/components/MCard.ts +45 -27
- package/src/components/MCheckbox.ts +25 -3
- package/src/components/MCombobox.ts +510 -0
- package/src/components/MDatePicker.ts +31 -0
- package/src/components/MFilePicker.ts +233 -0
- package/src/components/MInput.ts +24 -4
- package/src/components/MLink.ts +85 -0
- package/src/components/MRadioGroup.ts +26 -0
- package/src/components/MReveal.ts +57 -64
- package/src/components/MSheet.ts +1 -1
- package/src/components/MSlider.ts +18 -1
- package/src/components/MStack.ts +90 -0
- package/src/components/MSwitch.ts +3 -3
- package/src/components/MText.ts +6 -6
- package/src/components/layout.ts +15 -12
- package/src/components/workflows.ts +27 -0
- package/src/connected-motion.ts +23 -0
- package/src/experimental.ts +29 -0
- package/src/files.ts +77 -0
- package/src/hydration.ts +21 -0
- package/src/index.ts +36 -1
- package/src/motion-context.ts +35 -0
- package/src/motion-region.ts +198 -0
- package/src/motion-surface.ts +87 -12
- package/src/motion.ts +53 -47
- package/src/navigation.ts +44 -0
- package/src/reveal-motion.ts +59 -0
- package/src/screen-viewport.ts +4 -0
- package/src/scroll-motion.ts +16 -15
- package/src/sheet-motion.ts +86 -57
- package/src/style.css +6 -0
- package/src/tokens.ts +29 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
h,
|
|
4
|
+
mergeProps,
|
|
5
|
+
nextTick,
|
|
6
|
+
onBeforeUnmount,
|
|
7
|
+
onDeactivated,
|
|
8
|
+
onMounted,
|
|
9
|
+
ref,
|
|
10
|
+
shallowRef,
|
|
11
|
+
watch,
|
|
12
|
+
} from 'vue'
|
|
13
|
+
import { filePickerProps, fileStatusText, useButtonAction } from '@getcortexlabs/mavis-core/vue'
|
|
14
|
+
import type { InputHandle } from '@getcortexlabs/mavis-core'
|
|
15
|
+
import { createWebFilePicker } from '../files.js'
|
|
16
|
+
import { MColumn, MRow } from './layout.js'
|
|
17
|
+
import { MText } from './MText.js'
|
|
18
|
+
import { MButton } from './MButton.js'
|
|
19
|
+
import { MProgress } from './MProgress.js'
|
|
20
|
+
import { MCard } from './MCard.js'
|
|
21
|
+
|
|
22
|
+
const FilePicker = defineComponent({
|
|
23
|
+
name: 'MFilePicker',
|
|
24
|
+
inheritAttrs: false,
|
|
25
|
+
props: filePickerProps,
|
|
26
|
+
setup(props, { attrs, expose }) {
|
|
27
|
+
useButtonAction()
|
|
28
|
+
const root = ref<HTMLElement>()
|
|
29
|
+
const state = shallowRef(props.selection.state)
|
|
30
|
+
const picker = createWebFilePicker()
|
|
31
|
+
let mounted = false
|
|
32
|
+
let unsubscribe = () => {}
|
|
33
|
+
watch(
|
|
34
|
+
() => props.selection,
|
|
35
|
+
(selection, previous) => {
|
|
36
|
+
previous?.pause()
|
|
37
|
+
unsubscribe()
|
|
38
|
+
state.value = selection.state
|
|
39
|
+
unsubscribe = selection.subscribe((value) => {
|
|
40
|
+
state.value = value
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
{ immediate: true, flush: 'sync' },
|
|
44
|
+
)
|
|
45
|
+
watch(
|
|
46
|
+
() => props.disabled,
|
|
47
|
+
(disabled) => {
|
|
48
|
+
if (disabled) props.selection.pause()
|
|
49
|
+
},
|
|
50
|
+
)
|
|
51
|
+
onMounted(() => {
|
|
52
|
+
mounted = true
|
|
53
|
+
})
|
|
54
|
+
onDeactivated(() => props.selection.pause())
|
|
55
|
+
onBeforeUnmount(() => {
|
|
56
|
+
mounted = false
|
|
57
|
+
unsubscribe()
|
|
58
|
+
props.selection.pause()
|
|
59
|
+
})
|
|
60
|
+
function focusChoose() {
|
|
61
|
+
if (!mounted || props.disabled || state.value.picking) return
|
|
62
|
+
root.value
|
|
63
|
+
?.querySelector<HTMLButtonElement>('[data-file-choose]')
|
|
64
|
+
?.focus({ preventScroll: true })
|
|
65
|
+
}
|
|
66
|
+
expose({
|
|
67
|
+
focus: focusChoose,
|
|
68
|
+
blur: () => root.value?.querySelector<HTMLButtonElement>('[data-file-choose]')?.blur(),
|
|
69
|
+
} satisfies InputHandle)
|
|
70
|
+
function choose() {
|
|
71
|
+
if (!mounted || props.disabled || state.value.picking) return
|
|
72
|
+
focusChoose()
|
|
73
|
+
const selection = props.selection
|
|
74
|
+
void selection.select(picker).finally(async () => {
|
|
75
|
+
await nextTick()
|
|
76
|
+
if (mounted && props.selection === selection && !props.disabled) focusChoose()
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
return () => {
|
|
80
|
+
if (!props.label.trim()) throw new TypeError('FilePicker needs a non-empty label')
|
|
81
|
+
const selection = props.selection
|
|
82
|
+
return h(
|
|
83
|
+
'div',
|
|
84
|
+
mergeProps(attrs, {
|
|
85
|
+
ref: root,
|
|
86
|
+
role: 'group',
|
|
87
|
+
'aria-label': props.label,
|
|
88
|
+
style: { minWidth: 0 },
|
|
89
|
+
}),
|
|
90
|
+
[
|
|
91
|
+
h(
|
|
92
|
+
MColumn,
|
|
93
|
+
{ gap: 'md' },
|
|
94
|
+
{
|
|
95
|
+
default: () => [
|
|
96
|
+
h(MText, { text: props.label, weight: '600' }),
|
|
97
|
+
h(
|
|
98
|
+
MRow,
|
|
99
|
+
{ gap: 'sm', wrap: true },
|
|
100
|
+
{
|
|
101
|
+
default: () => [
|
|
102
|
+
h(MButton, {
|
|
103
|
+
text: props.chooseLabel,
|
|
104
|
+
variant: 'secondary',
|
|
105
|
+
disabled: props.disabled || state.value.picking,
|
|
106
|
+
'data-file-choose': '',
|
|
107
|
+
onClick: choose,
|
|
108
|
+
}),
|
|
109
|
+
state.value.picking
|
|
110
|
+
? h(MButton, {
|
|
111
|
+
text: props.cancelLabel,
|
|
112
|
+
variant: 'ghost',
|
|
113
|
+
onClick: () => {
|
|
114
|
+
selection.cancelSelection()
|
|
115
|
+
focusChoose()
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
: null,
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
),
|
|
122
|
+
state.value.error
|
|
123
|
+
? h('div', { role: 'alert' }, [
|
|
124
|
+
h(MText, {
|
|
125
|
+
text:
|
|
126
|
+
props.errorLabels[state.value.error.code] ?? state.value.error.message,
|
|
127
|
+
tone: 'danger',
|
|
128
|
+
}),
|
|
129
|
+
])
|
|
130
|
+
: null,
|
|
131
|
+
!state.value.items.length
|
|
132
|
+
? h(MText, { text: props.emptyLabel, tone: 'muted' })
|
|
133
|
+
: null,
|
|
134
|
+
...state.value.items.map((item) => {
|
|
135
|
+
const preview = selection.preview(item.id)
|
|
136
|
+
const status = fileStatusText(item, props.statusLabels)
|
|
137
|
+
return h(
|
|
138
|
+
MCard,
|
|
139
|
+
{ key: item.id, gap: 'sm' },
|
|
140
|
+
{
|
|
141
|
+
default: () => [
|
|
142
|
+
typeof preview === 'string'
|
|
143
|
+
? h('img', {
|
|
144
|
+
src: preview,
|
|
145
|
+
alt: '',
|
|
146
|
+
width: 80,
|
|
147
|
+
height: 80,
|
|
148
|
+
style: { objectFit: 'contain', borderRadius: '8px' },
|
|
149
|
+
onError: () => selection.discardPreview(item.id),
|
|
150
|
+
})
|
|
151
|
+
: null,
|
|
152
|
+
h(MText, {
|
|
153
|
+
text: item.name,
|
|
154
|
+
weight: '600',
|
|
155
|
+
style: { overflowWrap: 'anywhere' },
|
|
156
|
+
}),
|
|
157
|
+
h(MText, {
|
|
158
|
+
text: `${status}${item.size === undefined ? '' : ` · ${item.size} B`}`,
|
|
159
|
+
variant: 'caption',
|
|
160
|
+
tone:
|
|
161
|
+
item.status === 'failed'
|
|
162
|
+
? 'danger'
|
|
163
|
+
: item.status === 'uploaded'
|
|
164
|
+
? 'success'
|
|
165
|
+
: 'muted',
|
|
166
|
+
'aria-live': 'polite',
|
|
167
|
+
}),
|
|
168
|
+
item.status === 'uploading'
|
|
169
|
+
? h(MProgress, {
|
|
170
|
+
value: (item.progress ?? 0) * 100,
|
|
171
|
+
indeterminate: item.progress === undefined,
|
|
172
|
+
label: `${props.uploadLabel}: ${item.name}`,
|
|
173
|
+
indeterminateLabel: props.pendingLabel,
|
|
174
|
+
})
|
|
175
|
+
: null,
|
|
176
|
+
item.error
|
|
177
|
+
? h(MText, { text: item.error, tone: 'danger', variant: 'caption' })
|
|
178
|
+
: null,
|
|
179
|
+
h(
|
|
180
|
+
MRow,
|
|
181
|
+
{ gap: 'sm', wrap: true },
|
|
182
|
+
{
|
|
183
|
+
default: () => [
|
|
184
|
+
item.status === 'uploading'
|
|
185
|
+
? h(MButton, {
|
|
186
|
+
text: props.cancelLabel,
|
|
187
|
+
accessibilityLabel: `${props.cancelLabel}: ${item.name}`,
|
|
188
|
+
variant: 'secondary',
|
|
189
|
+
disabled: props.disabled,
|
|
190
|
+
onClick: () => selection.cancel(item.id),
|
|
191
|
+
})
|
|
192
|
+
: selection.canUpload && item.status !== 'uploaded'
|
|
193
|
+
? h(MButton, {
|
|
194
|
+
text:
|
|
195
|
+
item.status === 'failed' || item.status === 'cancelled'
|
|
196
|
+
? props.retryLabel
|
|
197
|
+
: props.uploadLabel,
|
|
198
|
+
accessibilityLabel: `${item.status === 'failed' || item.status === 'cancelled' ? props.retryLabel : props.uploadLabel}: ${item.name}`,
|
|
199
|
+
disabled: props.disabled || !selection.hasFile(item.id),
|
|
200
|
+
onClick: () => {
|
|
201
|
+
void selection.upload(item.id)
|
|
202
|
+
},
|
|
203
|
+
})
|
|
204
|
+
: null,
|
|
205
|
+
h(MButton, {
|
|
206
|
+
text: props.removeLabel,
|
|
207
|
+
accessibilityLabel: `${props.removeLabel}: ${item.name}`,
|
|
208
|
+
variant: 'ghost',
|
|
209
|
+
disabled: props.disabled,
|
|
210
|
+
onClick: () => {
|
|
211
|
+
focusChoose()
|
|
212
|
+
selection.remove(item.id)
|
|
213
|
+
},
|
|
214
|
+
}),
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
),
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
)
|
|
221
|
+
}),
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
),
|
|
225
|
+
],
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
export const MFilePicker = FilePicker as typeof FilePicker & {
|
|
232
|
+
new (): InstanceType<typeof FilePicker> & InputHandle
|
|
233
|
+
}
|
package/src/components/MInput.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
inputProps,
|
|
17
17
|
inputEmits,
|
|
18
18
|
useMavisTheme,
|
|
19
|
-
|
|
19
|
+
useLayoutShrink,
|
|
20
20
|
} from '@getcortexlabs/mavis-core/vue'
|
|
21
21
|
import {
|
|
22
22
|
fontFamily,
|
|
@@ -32,6 +32,7 @@ import { length, webAttrs } from '../style.js'
|
|
|
32
32
|
import { MIcon } from './MIcon.js'
|
|
33
33
|
import { MButton } from './MButton.js'
|
|
34
34
|
import { inputAttrs, describedBy, type InputEditorAttributes } from '../input-attrs.js'
|
|
35
|
+
import { useHydrationEdit } from '../hydration.js'
|
|
35
36
|
|
|
36
37
|
const Input = defineComponent({
|
|
37
38
|
name: 'MInput',
|
|
@@ -42,10 +43,28 @@ const Input = defineComponent({
|
|
|
42
43
|
useButtonAction()
|
|
43
44
|
const instance = getCurrentInstance()!
|
|
44
45
|
const { theme } = useMavisTheme()
|
|
45
|
-
const shrink =
|
|
46
|
+
const shrink = useLayoutShrink()
|
|
46
47
|
const generatedId = `m-input-${useId()}`
|
|
47
48
|
const editor = ref<HTMLInputElement | HTMLTextAreaElement>()
|
|
48
49
|
const focused = ref(false)
|
|
50
|
+
const hydrationEdit = useHydrationEdit(
|
|
51
|
+
(root) => {
|
|
52
|
+
const field = root.querySelector<HTMLInputElement | HTMLTextAreaElement>('.m-input-editor')
|
|
53
|
+
if (
|
|
54
|
+
field &&
|
|
55
|
+
!props.disabled &&
|
|
56
|
+
!props.readonly &&
|
|
57
|
+
field.defaultValue === props.modelValue &&
|
|
58
|
+
field.value !== field.defaultValue
|
|
59
|
+
) {
|
|
60
|
+
// Adopt the user's edit as the hydration snapshot, including its HTML
|
|
61
|
+
// value. The same node/caret survive; controlled reset still belongs to the app.
|
|
62
|
+
field.defaultValue = field.value
|
|
63
|
+
return field.value
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
(value) => emit('update:modelValue', value),
|
|
67
|
+
)
|
|
49
68
|
watch(
|
|
50
69
|
() => props.type,
|
|
51
70
|
() => {
|
|
@@ -102,6 +121,7 @@ const Input = defineComponent({
|
|
|
102
121
|
resize()
|
|
103
122
|
}
|
|
104
123
|
onMounted(() => {
|
|
124
|
+
if (typeof document !== 'undefined') focused.value = editor.value === document.activeElement
|
|
105
125
|
if (typeof ResizeObserver !== 'undefined') {
|
|
106
126
|
observer = new ResizeObserver(([entry]) => {
|
|
107
127
|
if (entry && entry.contentRect.width !== width) {
|
|
@@ -166,7 +186,7 @@ const Input = defineComponent({
|
|
|
166
186
|
minWidth: 0,
|
|
167
187
|
fontFamily: fontFamily(typography.body.fontFamily, 'web'),
|
|
168
188
|
flexGrow: nonNegative(props.grow, 'grow'),
|
|
169
|
-
flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
|
|
189
|
+
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
170
190
|
width: length(resolveDimension(props.width)),
|
|
171
191
|
opacity: props.disabled ? 0.5 : 1,
|
|
172
192
|
'--m-input-placeholder': colors.muted,
|
|
@@ -197,7 +217,7 @@ const Input = defineComponent({
|
|
|
197
217
|
class: 'm-input-editor',
|
|
198
218
|
type: props.multiline ? undefined : props.type,
|
|
199
219
|
rows: props.multiline ? props.rows : undefined,
|
|
200
|
-
value: props.modelValue,
|
|
220
|
+
value: hydrationEdit() ?? props.modelValue,
|
|
201
221
|
name: props.name,
|
|
202
222
|
autocomplete: props.autocomplete,
|
|
203
223
|
required: props.required,
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps } from 'vue'
|
|
2
|
+
import { fontFamily, linkDestination, linkRel, nonNegative } from '@getcortexlabs/mavis-core'
|
|
3
|
+
import {
|
|
4
|
+
linkProps,
|
|
5
|
+
linkEmits,
|
|
6
|
+
textContent,
|
|
7
|
+
useLayoutShrink,
|
|
8
|
+
useMavisTheme,
|
|
9
|
+
viewAttrs,
|
|
10
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
11
|
+
import { webAttrs } from '../style.js'
|
|
12
|
+
|
|
13
|
+
export const MLink = defineComponent({
|
|
14
|
+
name: 'MLink',
|
|
15
|
+
inheritAttrs: false,
|
|
16
|
+
props: linkProps,
|
|
17
|
+
emits: linkEmits,
|
|
18
|
+
setup(props, { attrs, slots, emit }) {
|
|
19
|
+
const { theme } = useMavisTheme()
|
|
20
|
+
const shrink = useLayoutShrink()
|
|
21
|
+
return () => {
|
|
22
|
+
const href = linkDestination(props.href)
|
|
23
|
+
const text = props.text ?? textContent(slots.default?.())
|
|
24
|
+
if (!(props.accessibilityLabel ?? text).trim()) throw new TypeError('MLink requires a name.')
|
|
25
|
+
const type = theme.value.typography.body
|
|
26
|
+
return h(
|
|
27
|
+
'a',
|
|
28
|
+
mergeProps(webAttrs({ ...attrs, ...viewAttrs(props) }), {
|
|
29
|
+
class: 'm-link',
|
|
30
|
+
href: props.disabled ? undefined : href,
|
|
31
|
+
target: props.target,
|
|
32
|
+
rel: linkRel(props.target, props.rel),
|
|
33
|
+
role: 'link',
|
|
34
|
+
tabindex: props.disabled ? -1 : undefined,
|
|
35
|
+
'aria-disabled': props.disabled || undefined,
|
|
36
|
+
style: {
|
|
37
|
+
'--m-focus': theme.value.colors.primary,
|
|
38
|
+
display: props.inline ? 'inline' : 'inline-flex',
|
|
39
|
+
alignItems: 'center',
|
|
40
|
+
justifyContent: 'center',
|
|
41
|
+
minHeight: props.inline ? undefined : '44px',
|
|
42
|
+
fontFamily: fontFamily(type.fontFamily, 'web'),
|
|
43
|
+
fontSize: `${type.fontSize}px`,
|
|
44
|
+
fontWeight: type.fontWeight,
|
|
45
|
+
lineHeight: type.lineHeight,
|
|
46
|
+
color: theme.value.colors.primary,
|
|
47
|
+
textDecoration: 'underline',
|
|
48
|
+
textUnderlineOffset: '0.18em',
|
|
49
|
+
cursor: props.disabled ? 'default' : 'pointer',
|
|
50
|
+
opacity: props.disabled ? 0.45 : 1,
|
|
51
|
+
overflowWrap: 'anywhere',
|
|
52
|
+
flexGrow: nonNegative(props.grow, 'grow'),
|
|
53
|
+
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
54
|
+
minWidth: 0,
|
|
55
|
+
},
|
|
56
|
+
onClick(event: MouseEvent) {
|
|
57
|
+
if (props.disabled) {
|
|
58
|
+
event.preventDefault()
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
if (event.defaultPrevented) return
|
|
62
|
+
emit('click')
|
|
63
|
+
if (
|
|
64
|
+
!props.navigate ||
|
|
65
|
+
props.target !== '_self' ||
|
|
66
|
+
event.button !== 0 ||
|
|
67
|
+
event.metaKey ||
|
|
68
|
+
event.ctrlKey ||
|
|
69
|
+
event.shiftKey ||
|
|
70
|
+
event.altKey
|
|
71
|
+
)
|
|
72
|
+
return
|
|
73
|
+
event.preventDefault()
|
|
74
|
+
try {
|
|
75
|
+
Promise.resolve(props.navigate(href)).catch((error) => emit('error', error))
|
|
76
|
+
} catch (error) {
|
|
77
|
+
emit('error', error)
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
text,
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
})
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from '@getcortexlabs/mavis-core/vue'
|
|
10
10
|
import { MColumn } from './layout.js'
|
|
11
11
|
import { MText } from './MText.js'
|
|
12
|
+
import { useHydrationEdit } from '../hydration.js'
|
|
12
13
|
|
|
13
14
|
export const MRadioGroup = defineComponent({
|
|
14
15
|
name: 'MRadioGroup',
|
|
@@ -19,6 +20,31 @@ export const MRadioGroup = defineComponent({
|
|
|
19
20
|
useButtonAction()
|
|
20
21
|
const { theme } = useMavisTheme()
|
|
21
22
|
const generatedId = `m-radio-${useId()}`
|
|
23
|
+
useHydrationEdit(
|
|
24
|
+
(root) => {
|
|
25
|
+
const inputs = [...root.querySelectorAll<HTMLInputElement>('.m-radio-input')]
|
|
26
|
+
const initial = inputs.findIndex((input) => input.defaultChecked)
|
|
27
|
+
const selected = inputs.findIndex((input) => input.checked)
|
|
28
|
+
const option = props.options[selected]
|
|
29
|
+
if (
|
|
30
|
+
!props.disabled &&
|
|
31
|
+
option &&
|
|
32
|
+
!option.disabled &&
|
|
33
|
+
selected !== initial &&
|
|
34
|
+
(props.options[initial]?.value ?? null) === props.modelValue
|
|
35
|
+
)
|
|
36
|
+
return { inputs, value: option.value }
|
|
37
|
+
},
|
|
38
|
+
({ inputs, value }) => {
|
|
39
|
+
emit('update:modelValue', value)
|
|
40
|
+
void nextTick(() => {
|
|
41
|
+
if (!alive) return
|
|
42
|
+
inputs.forEach((input, index) => {
|
|
43
|
+
input.checked = props.options[index]?.value === props.modelValue
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
},
|
|
47
|
+
)
|
|
22
48
|
const controls = new Map<string, HTMLInputElement>()
|
|
23
49
|
let alive = true
|
|
24
50
|
onBeforeUnmount(() => {
|
|
@@ -1,80 +1,73 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps, onActivated, onDeactivated } from 'vue'
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
shallowRef,
|
|
9
|
-
} from 'vue'
|
|
10
|
-
import { revealProps } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
revealProps,
|
|
4
|
+
useMavisTheme,
|
|
5
|
+
useRevealState,
|
|
6
|
+
viewAttrs,
|
|
7
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
8
|
+
import { revealHost } from '../reveal-motion.js'
|
|
11
9
|
import { MColumn } from './layout.js'
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
10
|
+
import { useMotionContext } from '../motion-context.js'
|
|
11
|
+
import { webAttrs, boxStyle } from '../style.js'
|
|
14
12
|
|
|
15
13
|
export const MReveal = defineComponent({
|
|
16
14
|
name: 'MReveal',
|
|
17
15
|
inheritAttrs: false,
|
|
18
16
|
props: revealProps,
|
|
19
17
|
setup(props, { attrs, slots }) {
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const { theme } = useMavisTheme()
|
|
19
|
+
const state = useRevealState(() => props.show)
|
|
20
|
+
const context = useMotionContext()
|
|
21
|
+
let mounted: HTMLElement | undefined
|
|
22
|
+
let retained: HTMLElement | undefined
|
|
23
|
+
function attach(element: HTMLElement) {
|
|
24
|
+
if (mounted === element) return
|
|
25
|
+
mounted = retained = element
|
|
26
|
+
return state.attach(
|
|
27
|
+
revealHost(
|
|
28
|
+
element,
|
|
29
|
+
context,
|
|
30
|
+
() => theme.value,
|
|
31
|
+
() => Boolean(props.accessibilityHidden),
|
|
32
|
+
),
|
|
33
|
+
)
|
|
34
|
+
}
|
|
27
35
|
onDeactivated(() => {
|
|
28
|
-
|
|
36
|
+
state.detach()
|
|
37
|
+
mounted = undefined
|
|
29
38
|
})
|
|
30
39
|
onActivated(() => {
|
|
31
|
-
|
|
40
|
+
if (retained) return attach(retained)
|
|
32
41
|
})
|
|
33
|
-
let trigger: HTMLElement | undefined
|
|
34
42
|
return () => {
|
|
35
|
-
const { show, ...
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
MColumn,
|
|
64
|
-
mergeProps(layout, attrs, {
|
|
65
|
-
key: 'content',
|
|
66
|
-
onVnodeMounted: (node) => {
|
|
67
|
-
target.value = mounted = node.el as HTMLElement
|
|
68
|
-
},
|
|
69
|
-
onVnodeUnmounted: () => {
|
|
70
|
-
target.value = mounted = null
|
|
71
|
-
},
|
|
72
|
-
}),
|
|
73
|
-
slots,
|
|
74
|
-
)
|
|
75
|
-
: null,
|
|
76
|
-
},
|
|
77
|
-
)
|
|
43
|
+
const { show, id, accessibilityLabel, accessibilityHidden, grow, shrink, width, ...content } =
|
|
44
|
+
props
|
|
45
|
+
return state.present.value
|
|
46
|
+
? h(
|
|
47
|
+
'div',
|
|
48
|
+
mergeProps(
|
|
49
|
+
{
|
|
50
|
+
class: 'm-reveal',
|
|
51
|
+
style: {
|
|
52
|
+
...boxStyle(theme.value, { grow, shrink: shrink ?? 0, width }),
|
|
53
|
+
overflow: state.phase.value === 'open' ? undefined : 'clip',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
webAttrs({ ...attrs, ...viewAttrs({ id, accessibilityLabel, accessibilityHidden }) }),
|
|
57
|
+
{
|
|
58
|
+
'data-state': state.phase.value,
|
|
59
|
+
inert: !show || accessibilityHidden || undefined,
|
|
60
|
+
'aria-hidden': !show || accessibilityHidden || undefined,
|
|
61
|
+
onVnodeMounted: (node) => attach(node.el as HTMLElement),
|
|
62
|
+
onVnodeBeforeUnmount: () => {
|
|
63
|
+
state.detach()
|
|
64
|
+
mounted = retained = undefined
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
),
|
|
68
|
+
[h(MColumn, content, slots)],
|
|
69
|
+
)
|
|
70
|
+
: null
|
|
78
71
|
}
|
|
79
72
|
},
|
|
80
73
|
})
|
package/src/components/MSheet.ts
CHANGED
|
@@ -74,7 +74,7 @@ const Sheet = defineComponent({
|
|
|
74
74
|
...element.querySelectorAll<HTMLElement>(
|
|
75
75
|
'button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])',
|
|
76
76
|
),
|
|
77
|
-
].filter((control) => !control.closest('[inert]'))
|
|
77
|
+
].filter((control) => control.tabIndex >= 0 && !control.closest('[inert]'))
|
|
78
78
|
// Engines differ on which control a modal dialog focuses first; start at the first control,
|
|
79
79
|
// or the panel itself, unless the content asked for focus with `autofocus`.
|
|
80
80
|
function focusInitial(element: HTMLDialogElement) {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from '@getcortexlabs/mavis-core/vue'
|
|
8
8
|
import { sliderScale } from '@getcortexlabs/mavis-core'
|
|
9
9
|
import { webAttrs } from '../style.js'
|
|
10
|
+
import { useHydrationEdit } from '../hydration.js'
|
|
10
11
|
|
|
11
12
|
export const MSlider = defineComponent({
|
|
12
13
|
name: 'MSlider',
|
|
@@ -16,6 +17,22 @@ export const MSlider = defineComponent({
|
|
|
16
17
|
setup(props, { attrs, emit }) {
|
|
17
18
|
useButtonAction()
|
|
18
19
|
const { theme } = useMavisTheme()
|
|
20
|
+
const hydrationEdit = useHydrationEdit(
|
|
21
|
+
(root) => {
|
|
22
|
+
const input = root as HTMLInputElement
|
|
23
|
+
const scale = sliderScale(props.min, props.max, props.step)
|
|
24
|
+
if (
|
|
25
|
+
!props.disabled &&
|
|
26
|
+
Number(input.defaultValue) === scale.toNative(props.modelValue) &&
|
|
27
|
+
input.value !== input.defaultValue
|
|
28
|
+
) {
|
|
29
|
+
input.defaultValue = input.value
|
|
30
|
+
return input.valueAsNumber
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
(index) =>
|
|
34
|
+
emit('update:modelValue', sliderScale(props.min, props.max, props.step).fromNative(index)),
|
|
35
|
+
)
|
|
19
36
|
return () => {
|
|
20
37
|
const scale = sliderScale(props.min, props.max, props.step)
|
|
21
38
|
const index = scale.toNative(props.modelValue)
|
|
@@ -44,7 +61,7 @@ export const MSlider = defineComponent({
|
|
|
44
61
|
min: 0,
|
|
45
62
|
max: scale.steps,
|
|
46
63
|
step: 1,
|
|
47
|
-
value: index,
|
|
64
|
+
value: hydrationEdit() ?? index,
|
|
48
65
|
disabled: props.disabled,
|
|
49
66
|
'aria-label': props.label,
|
|
50
67
|
'aria-valuemin': props.min,
|