@getcortexlabs/mavis-web 0.1.0-alpha.1 → 0.1.0-alpha.11
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 +8 -4
- package/dist/appearance.d.ts +4 -0
- package/dist/appearance.d.ts.map +1 -0
- package/dist/appearance.js +23 -0
- package/dist/appearance.js.map +1 -0
- package/dist/collection-motion.d.ts +4 -0
- package/dist/collection-motion.d.ts.map +1 -0
- package/dist/collection-motion.js +97 -0
- package/dist/collection-motion.js.map +1 -0
- package/dist/components/ChartPlot.d.ts +65 -0
- package/dist/components/ChartPlot.d.ts.map +1 -0
- package/dist/components/ChartPlot.js +135 -0
- package/dist/components/ChartPlot.js.map +1 -0
- package/dist/components/ChoicePaint.d.ts +17 -0
- package/dist/components/ChoicePaint.d.ts.map +1 -0
- package/dist/components/ChoicePaint.js +81 -0
- package/dist/components/ChoicePaint.js.map +1 -0
- package/dist/components/DateCalendar.d.ts +110 -0
- package/dist/components/DateCalendar.d.ts.map +1 -0
- package/dist/components/DateCalendar.js +166 -0
- package/dist/components/DateCalendar.js.map +1 -0
- package/dist/components/LoadingDecoration.d.ts +116 -0
- package/dist/components/LoadingDecoration.d.ts.map +1 -0
- package/dist/components/LoadingDecoration.js +35 -0
- package/dist/components/LoadingDecoration.js.map +1 -0
- package/dist/components/MAccordion.d.ts +119 -0
- package/dist/components/MAccordion.d.ts.map +1 -0
- package/dist/components/MAccordion.js +180 -0
- package/dist/components/MAccordion.js.map +1 -0
- package/dist/components/MAlert.d.ts +109 -0
- package/dist/components/MAlert.d.ts.map +1 -0
- package/dist/components/MAlert.js +88 -0
- package/dist/components/MAlert.js.map +1 -0
- package/dist/components/MAvatar.d.ts +80 -0
- package/dist/components/MAvatar.d.ts.map +1 -0
- package/dist/components/MAvatar.js +88 -0
- package/dist/components/MAvatar.js.map +1 -0
- package/dist/components/MBadge.d.ts +70 -0
- package/dist/components/MBadge.d.ts.map +1 -0
- package/dist/components/MBadge.js +35 -0
- package/dist/components/MBadge.js.map +1 -0
- package/dist/components/MButton.d.ts +215 -35
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MButton.js +104 -19
- package/dist/components/MButton.js.map +1 -1
- package/dist/components/MCard.d.ts +118 -25
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +69 -33
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MCheckbox.d.ts +103 -0
- package/dist/components/MCheckbox.d.ts.map +1 -0
- package/dist/components/MCheckbox.js +132 -0
- package/dist/components/MCheckbox.js.map +1 -0
- package/dist/components/MChip.d.ts +117 -0
- package/dist/components/MChip.d.ts.map +1 -0
- package/dist/components/MChip.js +103 -0
- package/dist/components/MChip.js.map +1 -0
- package/dist/components/MCombobox.d.ts +282 -0
- package/dist/components/MCombobox.d.ts.map +1 -0
- package/dist/components/MCombobox.js +450 -0
- package/dist/components/MCombobox.js.map +1 -0
- package/dist/components/MDatePicker.d.ts +1350 -0
- package/dist/components/MDatePicker.d.ts.map +1 -0
- package/dist/components/MDatePicker.js +23 -0
- package/dist/components/MDatePicker.js.map +1 -0
- package/dist/components/MDialog.d.ts +99 -0
- package/dist/components/MDialog.d.ts.map +1 -0
- package/dist/components/MDialog.js +279 -0
- package/dist/components/MDialog.js.map +1 -0
- package/dist/components/MEmptyState.d.ts +117 -0
- package/dist/components/MEmptyState.d.ts.map +1 -0
- package/dist/components/MEmptyState.js +79 -0
- package/dist/components/MEmptyState.js.map +1 -0
- 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/MGrid.d.ts +163 -0
- package/dist/components/MGrid.d.ts.map +1 -0
- package/dist/components/MGrid.js +32 -0
- package/dist/components/MGrid.js.map +1 -0
- package/dist/components/MIcon.d.ts +75 -0
- package/dist/components/MIcon.d.ts.map +1 -0
- package/dist/components/MIcon.js +38 -0
- package/dist/components/MIcon.js.map +1 -0
- package/dist/components/MImage.d.ts +248 -0
- package/dist/components/MImage.d.ts.map +1 -0
- package/dist/components/MImage.js +163 -0
- package/dist/components/MImage.js.map +1 -0
- package/dist/components/MInput.d.ts +202 -54
- package/dist/components/MInput.d.ts.map +1 -1
- package/dist/components/MInput.js +192 -71
- 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 +47 -0
- package/dist/components/MLink.js.map +1 -0
- package/dist/components/MListItem.d.ts +106 -0
- package/dist/components/MListItem.d.ts.map +1 -0
- package/dist/components/MListItem.js +53 -0
- package/dist/components/MListItem.js.map +1 -0
- package/dist/components/MPopover.d.ts +105 -0
- package/dist/components/MPopover.d.ts.map +1 -0
- package/dist/components/MPopover.js +238 -0
- package/dist/components/MPopover.js.map +1 -0
- package/dist/components/MProgress.d.ts +122 -0
- package/dist/components/MProgress.d.ts.map +1 -0
- package/dist/components/MProgress.js +69 -0
- package/dist/components/MProgress.js.map +1 -0
- package/dist/components/MRadioGroup.d.ts +104 -0
- package/dist/components/MRadioGroup.d.ts.map +1 -0
- package/dist/components/MRadioGroup.js +191 -0
- package/dist/components/MRadioGroup.js.map +1 -0
- package/dist/components/MRangeSlider.d.ts +104 -0
- package/dist/components/MRangeSlider.d.ts.map +1 -0
- package/dist/components/MRangeSlider.js +95 -0
- package/dist/components/MRangeSlider.js.map +1 -0
- package/dist/components/MReveal.d.ts +76 -40
- package/dist/components/MReveal.d.ts.map +1 -1
- package/dist/components/MReveal.js +43 -29
- package/dist/components/MReveal.js.map +1 -1
- package/dist/components/MScreen.d.ts +40 -7
- package/dist/components/MScreen.d.ts.map +1 -1
- package/dist/components/MScreen.js +59 -17
- package/dist/components/MScreen.js.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +95 -0
- package/dist/components/MSegmentedControl.d.ts.map +1 -0
- package/dist/components/MSegmentedControl.js +128 -0
- package/dist/components/MSegmentedControl.js.map +1 -0
- package/dist/components/MSelect.d.ts +140 -0
- package/dist/components/MSelect.d.ts.map +1 -0
- package/dist/components/MSelect.js +314 -0
- package/dist/components/MSelect.js.map +1 -0
- package/dist/components/MSeparator.d.ts +56 -0
- package/dist/components/MSeparator.d.ts.map +1 -0
- package/dist/components/MSeparator.js +36 -0
- package/dist/components/MSeparator.js.map +1 -0
- package/dist/components/MSheet.d.ts +117 -0
- package/dist/components/MSheet.d.ts.map +1 -0
- package/dist/components/MSheet.js +303 -0
- package/dist/components/MSheet.js.map +1 -0
- package/dist/components/MSkeleton.d.ts +89 -0
- package/dist/components/MSkeleton.d.ts.map +1 -0
- package/dist/components/MSkeleton.js +49 -0
- package/dist/components/MSkeleton.js.map +1 -0
- package/dist/components/MSlider.d.ts +9 -5
- package/dist/components/MSlider.d.ts.map +1 -1
- package/dist/components/MSlider.js +14 -2
- 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 +52 -0
- package/dist/components/MStack.js.map +1 -0
- package/dist/components/MSwitch.d.ts +89 -0
- package/dist/components/MSwitch.d.ts.map +1 -0
- package/dist/components/MSwitch.js +94 -0
- package/dist/components/MSwitch.js.map +1 -0
- package/dist/components/MTabs.d.ts +101 -0
- package/dist/components/MTabs.d.ts.map +1 -0
- package/dist/components/MTabs.js +228 -0
- package/dist/components/MTabs.js.map +1 -0
- package/dist/components/MText.d.ts +62 -26
- package/dist/components/MText.d.ts.map +1 -1
- package/dist/components/MText.js +37 -13
- package/dist/components/MText.js.map +1 -1
- package/dist/components/MTimePicker.d.ts +655 -0
- package/dist/components/MTimePicker.d.ts.map +1 -0
- package/dist/components/MTimePicker.js +81 -0
- package/dist/components/MTimePicker.js.map +1 -0
- package/dist/components/MToast.d.ts +24 -0
- package/dist/components/MToast.d.ts.map +1 -0
- package/dist/components/MToast.js +196 -0
- package/dist/components/MToast.js.map +1 -0
- package/dist/components/MTooltip.d.ts +65 -0
- package/dist/components/MTooltip.d.ts.map +1 -0
- package/dist/components/MTooltip.js +259 -0
- package/dist/components/MTooltip.js.map +1 -0
- package/dist/components/MVirtualList.d.ts +3 -0
- package/dist/components/MVirtualList.d.ts.map +1 -0
- package/dist/components/MVirtualList.js +109 -0
- package/dist/components/MVirtualList.js.map +1 -0
- package/dist/components/configurator.d.ts +541 -0
- package/dist/components/configurator.d.ts.map +1 -0
- package/dist/components/configurator.js +20 -0
- package/dist/components/configurator.js.map +1 -0
- package/dist/components/discovery.d.ts +282 -0
- package/dist/components/discovery.d.ts.map +1 -0
- package/dist/components/discovery.js +113 -0
- package/dist/components/discovery.js.map +1 -0
- package/dist/components/layout.d.ts +425 -95
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +18 -13
- package/dist/components/layout.js.map +1 -1
- package/dist/components/navigation.d.ts +225 -0
- package/dist/components/navigation.d.ts.map +1 -0
- package/dist/components/navigation.js +41 -0
- package/dist/components/navigation.js.map +1 -0
- package/dist/components/wayfinding.d.ts +441 -0
- package/dist/components/wayfinding.d.ts.map +1 -0
- package/dist/components/wayfinding.js +56 -0
- package/dist/components/wayfinding.js.map +1 -0
- 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/content-width.d.ts +4 -0
- package/dist/content-width.d.ts.map +1 -0
- package/dist/content-width.js +62 -0
- package/dist/content-width.js.map +1 -0
- package/dist/date-format.d.ts +6 -0
- package/dist/date-format.d.ts.map +1 -0
- package/dist/date-format.js +23 -0
- package/dist/date-format.js.map +1 -0
- package/dist/experimental.d.ts +11 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +31 -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/icons.d.ts +14 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/icons.js +23 -0
- package/dist/icons.js.map +1 -0
- package/dist/image-effects.d.ts +11 -0
- package/dist/image-effects.d.ts.map +1 -0
- package/dist/image-effects.js +67 -0
- package/dist/image-effects.js.map +1 -0
- package/dist/index.d.ts +55 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -6
- package/dist/index.js.map +1 -1
- package/dist/input-attrs.d.ts +15 -0
- package/dist/input-attrs.d.ts.map +1 -0
- package/dist/input-attrs.js +18 -0
- package/dist/input-attrs.js.map +1 -0
- 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 +174 -0
- package/dist/motion-region.js.map +1 -0
- package/dist/motion-surface.d.ts +16 -0
- package/dist/motion-surface.d.ts.map +1 -0
- package/dist/motion-surface.js +244 -0
- package/dist/motion-surface.js.map +1 -0
- package/dist/motion.d.ts +20 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +244 -0
- package/dist/motion.js.map +1 -0
- 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/nuxt-navigation.d.ts +18 -0
- package/dist/nuxt-navigation.d.ts.map +1 -0
- package/dist/nuxt-navigation.js +23 -0
- package/dist/nuxt-navigation.js.map +1 -0
- package/dist/platform-motion.d.ts +4 -0
- package/dist/platform-motion.d.ts.map +1 -0
- package/dist/platform-motion.js +23 -0
- package/dist/platform-motion.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/router-navigation.d.ts +31 -0
- package/dist/router-navigation.d.ts.map +1 -0
- package/dist/router-navigation.js +215 -0
- package/dist/router-navigation.js.map +1 -0
- package/dist/screen-viewport.d.ts.map +1 -1
- package/dist/screen-viewport.js +8 -0
- package/dist/screen-viewport.js.map +1 -1
- package/dist/scroll-motion.d.ts +5 -0
- package/dist/scroll-motion.d.ts.map +1 -0
- package/dist/scroll-motion.js +84 -0
- package/dist/scroll-motion.js.map +1 -0
- package/dist/section-scroll.d.ts +8 -0
- package/dist/section-scroll.d.ts.map +1 -0
- package/dist/section-scroll.js +79 -0
- package/dist/section-scroll.js.map +1 -0
- package/dist/services.d.ts +16 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +22 -0
- package/dist/services.js.map +1 -0
- package/dist/sheet-motion.d.ts +12 -0
- package/dist/sheet-motion.d.ts.map +1 -0
- package/dist/sheet-motion.js +83 -0
- package/dist/sheet-motion.js.map +1 -0
- package/dist/style.d.ts.map +1 -1
- package/dist/style.js +24 -9
- package/dist/style.js.map +1 -1
- package/dist/surface-effects.d.ts +4 -0
- package/dist/surface-effects.d.ts.map +1 -0
- package/dist/surface-effects.js +28 -0
- package/dist/surface-effects.js.map +1 -0
- 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/dist/use-motion-surface.d.ts +8 -0
- package/dist/use-motion-surface.d.ts.map +1 -0
- package/dist/use-motion-surface.js +33 -0
- package/dist/use-motion-surface.js.map +1 -0
- package/dist/visual-effects.d.ts +4 -0
- package/dist/visual-effects.d.ts.map +1 -0
- package/dist/visual-effects.js +120 -0
- package/dist/visual-effects.js.map +1 -0
- package/package.json +27 -4
- package/src/appearance.ts +23 -0
- package/src/base.css +1115 -0
- package/src/collection-motion.ts +107 -0
- package/src/components/ChartPlot.ts +139 -0
- package/src/components/ChoicePaint.ts +96 -0
- package/src/components/DateCalendar.ts +225 -0
- package/src/components/LoadingDecoration.ts +39 -0
- package/src/components/MAccordion.ts +231 -0
- package/src/components/MAlert.ts +109 -0
- package/src/components/MAvatar.ts +97 -0
- package/src/components/MBadge.ts +40 -0
- package/src/components/MButton.ts +138 -20
- package/src/components/MCard.ts +96 -30
- package/src/components/MCheckbox.ts +160 -0
- package/src/components/MChip.ts +109 -0
- package/src/components/MCombobox.ts +520 -0
- package/src/components/MDatePicker.ts +23 -0
- package/src/components/MDialog.ts +319 -0
- package/src/components/MEmptyState.ts +96 -0
- package/src/components/MFilePicker.ts +233 -0
- package/src/components/MGrid.ts +45 -0
- package/src/components/MIcon.ts +47 -0
- package/src/components/MImage.ts +183 -0
- package/src/components/MInput.ts +216 -71
- package/src/components/MLink.ts +63 -0
- package/src/components/MListItem.ts +66 -0
- package/src/components/MPopover.ts +280 -0
- package/src/components/MProgress.ts +82 -0
- package/src/components/MRadioGroup.ts +216 -0
- package/src/components/MRangeSlider.ts +115 -0
- package/src/components/MReveal.ts +62 -32
- package/src/components/MScreen.ts +57 -3
- package/src/components/MSegmentedControl.ts +151 -0
- package/src/components/MSelect.ts +367 -0
- package/src/components/MSeparator.ts +40 -0
- package/src/components/MSheet.ts +361 -0
- package/src/components/MSkeleton.ts +61 -0
- package/src/components/MSlider.ts +25 -2
- package/src/components/MStack.ts +73 -0
- package/src/components/MSwitch.ts +119 -0
- package/src/components/MTabs.ts +275 -0
- package/src/components/MText.ts +46 -14
- package/src/components/MTimePicker.ts +124 -0
- package/src/components/MToast.ts +241 -0
- package/src/components/MTooltip.ts +293 -0
- package/src/components/MVirtualList.ts +146 -0
- package/src/components/configurator.ts +24 -0
- package/src/components/discovery.ts +163 -0
- package/src/components/layout.ts +20 -12
- package/src/components/navigation.ts +44 -0
- package/src/components/wayfinding.ts +68 -0
- package/src/components/workflows.ts +27 -0
- package/src/connected-motion.ts +23 -0
- package/src/content-width.ts +70 -0
- package/src/date-format.ts +36 -0
- package/src/experimental.ts +37 -0
- package/src/files.ts +77 -0
- package/src/fonts/LICENSE +45 -0
- package/src/fonts/lucide.woff2 +0 -0
- package/src/hydration.ts +21 -0
- package/src/icons.css +7 -0
- package/src/icons.ts +28 -0
- package/src/image-effects.ts +80 -0
- package/src/index.ts +217 -20
- package/src/input-attrs.ts +41 -0
- package/src/motion-context.ts +35 -0
- package/src/motion-region.ts +209 -0
- package/src/motion-surface.ts +274 -0
- package/src/motion.ts +281 -0
- package/src/navigation.ts +44 -0
- package/src/nuxt-navigation.ts +29 -0
- package/src/platform-motion.ts +36 -0
- package/src/reveal-motion.ts +59 -0
- package/src/router-navigation.ts +249 -0
- package/src/screen-viewport.ts +6 -0
- package/src/scroll-motion.ts +88 -0
- package/src/section-scroll.ts +101 -0
- package/src/services.ts +39 -0
- package/src/sheet-motion.ts +80 -0
- package/src/style.css +2 -139
- package/src/style.ts +20 -9
- package/src/surface-effects.ts +33 -0
- package/src/tokens.ts +29 -0
- package/src/use-motion-surface.ts +43 -0
- package/src/visual-effects.ts +139 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useIconContent } from '../icons.js'
|
|
2
|
+
import { defineComponent, h, mergeProps } from 'vue'
|
|
3
|
+
import { iconProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
4
|
+
import { resolveIconSize } from '@getcortexlabs/mavis-core'
|
|
5
|
+
import { webAttrs } from '../style.js'
|
|
6
|
+
import { useMotionSurface } from '../use-motion-surface.js'
|
|
7
|
+
|
|
8
|
+
export const MIcon = defineComponent({
|
|
9
|
+
name: 'MIcon',
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
props: iconProps,
|
|
12
|
+
setup(props, { attrs }) {
|
|
13
|
+
const { theme } = useMavisTheme()
|
|
14
|
+
const renderIcon = useIconContent()
|
|
15
|
+
const motion = useMotionSurface(() => props.motionSurface)
|
|
16
|
+
return () => {
|
|
17
|
+
const icon = renderIcon(props.name, resolveIconSize(props.size))
|
|
18
|
+
const size = `${resolveIconSize(props.size)}px`
|
|
19
|
+
return h(
|
|
20
|
+
'span',
|
|
21
|
+
mergeProps(
|
|
22
|
+
motion,
|
|
23
|
+
{
|
|
24
|
+
class: 'm-icon',
|
|
25
|
+
style: {
|
|
26
|
+
fontFamily: icon.fontFamily,
|
|
27
|
+
fontSize: size,
|
|
28
|
+
width: size,
|
|
29
|
+
height: size,
|
|
30
|
+
lineHeight: 1,
|
|
31
|
+
color: theme.value.colors[props.tone],
|
|
32
|
+
display: 'inline-flex',
|
|
33
|
+
alignItems: 'center',
|
|
34
|
+
justifyContent: 'center',
|
|
35
|
+
flexShrink: 0,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
webAttrs({ ...attrs, id: props.id }),
|
|
39
|
+
props.label ? { role: 'img', 'aria-label': props.label } : { 'aria-hidden': 'true' },
|
|
40
|
+
),
|
|
41
|
+
props.motionSurface
|
|
42
|
+
? h('span', { 'data-jolt-symbol-layer': '', 'aria-hidden': 'true' }, icon.content)
|
|
43
|
+
: icon.content,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
})
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps, nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
|
2
|
+
import { imageProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { resolveRadius, resolveDimension } from '@getcortexlabs/mavis-core'
|
|
4
|
+
import { boxStyle, webAttrs, length } from '../style.js'
|
|
5
|
+
import { useMotionSurface } from '../use-motion-surface.js'
|
|
6
|
+
import { registerMotionImage } from '../image-effects.js'
|
|
7
|
+
|
|
8
|
+
export const MImage = defineComponent({
|
|
9
|
+
name: 'MImage',
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
props: imageProps,
|
|
12
|
+
emits: {
|
|
13
|
+
load: (_src: string) => true,
|
|
14
|
+
error: (_src: string) => true,
|
|
15
|
+
'update:src': (_src: string) => true,
|
|
16
|
+
},
|
|
17
|
+
setup(props, { attrs, emit }) {
|
|
18
|
+
const { theme } = useMavisTheme()
|
|
19
|
+
const status = ref<'loading' | 'ready' | 'error'>('loading')
|
|
20
|
+
let generation = 0,
|
|
21
|
+
alive = true
|
|
22
|
+
let currentImage: HTMLImageElement | undefined,
|
|
23
|
+
releaseImage: (() => void) | undefined,
|
|
24
|
+
committing: string | undefined
|
|
25
|
+
const motion = useMotionSurface(() =>
|
|
26
|
+
status.value === 'ready' ? props.motionSurface : undefined,
|
|
27
|
+
)
|
|
28
|
+
watch(
|
|
29
|
+
() => [props.src, props.srcset, props.sizes] as const,
|
|
30
|
+
(selection, previous) => {
|
|
31
|
+
if (
|
|
32
|
+
props.src === committing &&
|
|
33
|
+
selection[1] === previous?.[1] &&
|
|
34
|
+
selection[2] === previous?.[2]
|
|
35
|
+
) {
|
|
36
|
+
committing = undefined
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
generation++
|
|
40
|
+
status.value = props.src.trim() ? 'loading' : 'error'
|
|
41
|
+
},
|
|
42
|
+
{ flush: 'sync', immediate: true },
|
|
43
|
+
)
|
|
44
|
+
onBeforeUnmount(() => {
|
|
45
|
+
alive = false
|
|
46
|
+
generation++
|
|
47
|
+
releaseImage?.()
|
|
48
|
+
})
|
|
49
|
+
return () => {
|
|
50
|
+
if (!Number.isFinite(props.aspectRatio) || props.aspectRatio <= 0)
|
|
51
|
+
throw new RangeError('aspectRatio must be finite and positive.')
|
|
52
|
+
const current = generation,
|
|
53
|
+
src = props.src
|
|
54
|
+
const settle = (success: boolean, candidate?: string) => {
|
|
55
|
+
if (!alive || current !== generation) return
|
|
56
|
+
// The browser can select another srcset candidate without changing any Vue prop.
|
|
57
|
+
if (candidate !== undefined && currentImage?.currentSrc !== candidate) return
|
|
58
|
+
const next = success ? 'ready' : 'error'
|
|
59
|
+
if (status.value === next) return
|
|
60
|
+
status.value = next
|
|
61
|
+
if (success) emit('load', src)
|
|
62
|
+
else emit('error', src)
|
|
63
|
+
}
|
|
64
|
+
const radius = resolveRadius(theme.value, props.radius)
|
|
65
|
+
return h(
|
|
66
|
+
'div',
|
|
67
|
+
mergeProps(webAttrs(attrs), {
|
|
68
|
+
id: props.id,
|
|
69
|
+
class: 'm-image',
|
|
70
|
+
'data-state': status.value,
|
|
71
|
+
'aria-hidden': props.accessibilityHidden || !props.alt || undefined,
|
|
72
|
+
role: status.value === 'ready' ? undefined : 'img',
|
|
73
|
+
'aria-label':
|
|
74
|
+
status.value === 'ready'
|
|
75
|
+
? undefined
|
|
76
|
+
: `${props.alt}: ${status.value === 'error' ? props.errorLabel : props.loadingLabel}`,
|
|
77
|
+
style: {
|
|
78
|
+
...boxStyle(theme.value, props),
|
|
79
|
+
position: 'relative',
|
|
80
|
+
overflow: 'hidden',
|
|
81
|
+
width: length(resolveDimension(props.width)) ?? '100%',
|
|
82
|
+
aspectRatio: String(props.aspectRatio),
|
|
83
|
+
borderRadius: `${radius}px`,
|
|
84
|
+
backgroundColor: props.backgroundColor || theme.value.colors.elevated,
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
[
|
|
88
|
+
src.trim()
|
|
89
|
+
? h('img', {
|
|
90
|
+
key: current,
|
|
91
|
+
src,
|
|
92
|
+
srcset: props.srcset,
|
|
93
|
+
sizes: props.sizes,
|
|
94
|
+
loading: props.loading,
|
|
95
|
+
decoding: props.decoding,
|
|
96
|
+
fetchpriority: props.fetchpriority,
|
|
97
|
+
alt: props.alt,
|
|
98
|
+
onLoad: (event: Event) => {
|
|
99
|
+
const target = event.target as HTMLImageElement
|
|
100
|
+
const candidate = target?.currentSrc
|
|
101
|
+
if (target?.decode)
|
|
102
|
+
void target.decode().then(
|
|
103
|
+
() => settle(true, candidate),
|
|
104
|
+
() => settle(false, candidate),
|
|
105
|
+
)
|
|
106
|
+
else settle(true, candidate)
|
|
107
|
+
},
|
|
108
|
+
onError: () => settle(false),
|
|
109
|
+
onVnodeMounted: (node) => {
|
|
110
|
+
const image = node.el as HTMLImageElement
|
|
111
|
+
currentImage = image
|
|
112
|
+
releaseImage?.()
|
|
113
|
+
releaseImage = registerMotionImage(image, {
|
|
114
|
+
current: () => alive && current === generation && currentImage === image,
|
|
115
|
+
async commit(destination) {
|
|
116
|
+
if (!alive || current !== generation || currentImage !== image) return false
|
|
117
|
+
const previous = props.src
|
|
118
|
+
committing = destination
|
|
119
|
+
emit('update:src', destination)
|
|
120
|
+
await nextTick()
|
|
121
|
+
const accepted =
|
|
122
|
+
alive &&
|
|
123
|
+
current === generation &&
|
|
124
|
+
currentImage === image &&
|
|
125
|
+
props.src === destination
|
|
126
|
+
committing = undefined
|
|
127
|
+
if (!accepted && current === generation && currentImage === image)
|
|
128
|
+
image.src = previous
|
|
129
|
+
return accepted
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
motion.onVnodeMounted(node)
|
|
133
|
+
if (image.complete) {
|
|
134
|
+
const candidate = image.currentSrc
|
|
135
|
+
if (image.naturalWidth && image.decode)
|
|
136
|
+
void image.decode().then(
|
|
137
|
+
() => settle(true, candidate),
|
|
138
|
+
() => settle(false, candidate),
|
|
139
|
+
)
|
|
140
|
+
else settle(image.naturalWidth > 0)
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
onVnodeBeforeUnmount: () => {
|
|
144
|
+
motion.onVnodeBeforeUnmount()
|
|
145
|
+
releaseImage?.()
|
|
146
|
+
releaseImage = undefined
|
|
147
|
+
currentImage = undefined
|
|
148
|
+
},
|
|
149
|
+
style: {
|
|
150
|
+
position: 'absolute',
|
|
151
|
+
inset: 0,
|
|
152
|
+
width: '100%',
|
|
153
|
+
height: '100%',
|
|
154
|
+
objectFit: props.fit,
|
|
155
|
+
opacity: status.value === 'ready' ? 1 : 0,
|
|
156
|
+
},
|
|
157
|
+
})
|
|
158
|
+
: null,
|
|
159
|
+
status.value !== 'ready'
|
|
160
|
+
? h(
|
|
161
|
+
'span',
|
|
162
|
+
{
|
|
163
|
+
'aria-hidden': 'true',
|
|
164
|
+
style: {
|
|
165
|
+
position: 'absolute',
|
|
166
|
+
inset: 0,
|
|
167
|
+
display: 'flex',
|
|
168
|
+
alignItems: 'center',
|
|
169
|
+
justifyContent: 'center',
|
|
170
|
+
padding: '16px',
|
|
171
|
+
color: theme.value.colors.muted,
|
|
172
|
+
fontSize: `${theme.value.typography.caption.fontSize}px`,
|
|
173
|
+
textAlign: 'center',
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
status.value === 'error' ? props.errorLabel : props.loadingLabel,
|
|
177
|
+
)
|
|
178
|
+
: null,
|
|
179
|
+
],
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
})
|
package/src/components/MInput.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defineComponent,
|
|
3
|
+
getCurrentInstance,
|
|
4
|
+
nextTick,
|
|
3
5
|
h,
|
|
4
6
|
mergeProps,
|
|
5
7
|
onBeforeUnmount,
|
|
@@ -10,30 +12,80 @@ import {
|
|
|
10
12
|
watch,
|
|
11
13
|
} from 'vue'
|
|
12
14
|
import {
|
|
15
|
+
useButtonAction,
|
|
13
16
|
inputProps,
|
|
14
17
|
inputEmits,
|
|
15
18
|
useMavisTheme,
|
|
16
|
-
|
|
19
|
+
useLayoutShrink,
|
|
17
20
|
} from '@getcortexlabs/mavis-core/vue'
|
|
18
21
|
import {
|
|
22
|
+
fontFamily,
|
|
23
|
+
resolveRadius,
|
|
19
24
|
nonNegative,
|
|
20
25
|
resolveDimension,
|
|
21
26
|
validateInput,
|
|
22
|
-
|
|
27
|
+
iconSizes,
|
|
28
|
+
inputActionSize,
|
|
29
|
+
type InputActionHandle,
|
|
23
30
|
} from '@getcortexlabs/mavis-core'
|
|
24
31
|
import { length, webAttrs } from '../style.js'
|
|
32
|
+
import { MIcon } from './MIcon.js'
|
|
33
|
+
import { MButton } from './MButton.js'
|
|
34
|
+
import { inputAttrs, describedBy, type InputEditorAttributes } from '../input-attrs.js'
|
|
35
|
+
import { useHydrationEdit } from '../hydration.js'
|
|
25
36
|
|
|
26
|
-
|
|
37
|
+
const Input = defineComponent({
|
|
27
38
|
name: 'MInput',
|
|
28
39
|
inheritAttrs: false,
|
|
29
40
|
props: inputProps,
|
|
30
41
|
emits: inputEmits,
|
|
31
42
|
setup(props, { attrs, emit, expose }) {
|
|
43
|
+
useButtonAction()
|
|
44
|
+
const instance = getCurrentInstance()!
|
|
32
45
|
const { theme } = useMavisTheme()
|
|
33
|
-
const shrink =
|
|
46
|
+
const shrink = useLayoutShrink()
|
|
34
47
|
const generatedId = `m-input-${useId()}`
|
|
35
48
|
const editor = ref<HTMLInputElement | HTMLTextAreaElement>()
|
|
49
|
+
const actionButton = ref<{ $el?: HTMLElement }>()
|
|
36
50
|
const focused = ref(false)
|
|
51
|
+
const hydrationEdit = useHydrationEdit(
|
|
52
|
+
(root) => {
|
|
53
|
+
const field = root.querySelector<HTMLInputElement | HTMLTextAreaElement>('.m-input-editor')
|
|
54
|
+
if (
|
|
55
|
+
field &&
|
|
56
|
+
!props.disabled &&
|
|
57
|
+
!props.readonly &&
|
|
58
|
+
field.defaultValue === props.modelValue &&
|
|
59
|
+
field.value !== field.defaultValue
|
|
60
|
+
) {
|
|
61
|
+
// Adopt the user's edit as the hydration snapshot, including its HTML
|
|
62
|
+
// value. The same node/caret survive; controlled reset still belongs to the app.
|
|
63
|
+
field.defaultValue = field.value
|
|
64
|
+
return field.value
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
(value) => emit('update:modelValue', value),
|
|
68
|
+
)
|
|
69
|
+
watch(
|
|
70
|
+
() => props.type,
|
|
71
|
+
() => {
|
|
72
|
+
const field = editor.value
|
|
73
|
+
if (!field || document.activeElement !== field || field.selectionStart === null) return
|
|
74
|
+
const start = field.selectionStart,
|
|
75
|
+
end = field.selectionEnd!,
|
|
76
|
+
direction = field.selectionDirection
|
|
77
|
+
void nextTick(() => {
|
|
78
|
+
if (
|
|
79
|
+
editor.value !== field ||
|
|
80
|
+
document.activeElement !== field ||
|
|
81
|
+
field.selectionStart === null
|
|
82
|
+
)
|
|
83
|
+
return
|
|
84
|
+
field.setSelectionRange(start, end, direction ?? undefined)
|
|
85
|
+
})
|
|
86
|
+
},
|
|
87
|
+
{ flush: 'pre' },
|
|
88
|
+
)
|
|
37
89
|
let observer: ResizeObserver | undefined
|
|
38
90
|
let observed: HTMLElement | undefined
|
|
39
91
|
let width = 0
|
|
@@ -47,6 +99,7 @@ export const MInput = defineComponent({
|
|
|
47
99
|
field.clientWidth,
|
|
48
100
|
props.rows,
|
|
49
101
|
theme.value.typography.body.fontSize,
|
|
102
|
+
theme.value.components.input,
|
|
50
103
|
])
|
|
51
104
|
// Resetting height can move Safari's scroll position while a pointer is
|
|
52
105
|
// down. Focus/blur renders do not need to measure unchanged content.
|
|
@@ -56,6 +109,9 @@ export const MInput = defineComponent({
|
|
|
56
109
|
field.style.height = `${field.scrollHeight + 2}px`
|
|
57
110
|
}
|
|
58
111
|
function observe() {
|
|
112
|
+
// HTML reset must not replace a controlled value behind the application's back.
|
|
113
|
+
// Applications reset their models in @reset.prevent; ordinary reset keeps them intact.
|
|
114
|
+
if (editor.value) editor.value.defaultValue = props.modelValue
|
|
59
115
|
if (editor.value !== observed) {
|
|
60
116
|
observer?.disconnect()
|
|
61
117
|
observed = editor.value
|
|
@@ -66,6 +122,7 @@ export const MInput = defineComponent({
|
|
|
66
122
|
resize()
|
|
67
123
|
}
|
|
68
124
|
onMounted(() => {
|
|
125
|
+
if (typeof document !== 'undefined') focused.value = editor.value === document.activeElement
|
|
69
126
|
if (typeof ResizeObserver !== 'undefined') {
|
|
70
127
|
observer = new ResizeObserver(([entry]) => {
|
|
71
128
|
if (entry && entry.contentRect.width !== width) {
|
|
@@ -85,19 +142,43 @@ export const MInput = defineComponent({
|
|
|
85
142
|
},
|
|
86
143
|
)
|
|
87
144
|
expose({
|
|
145
|
+
focusAction: () => {
|
|
146
|
+
if (props.disabled || props.readonly || props.trailingAction?.disabled) return
|
|
147
|
+
actionButton.value?.$el?.focus?.({ preventScroll: true })
|
|
148
|
+
},
|
|
88
149
|
focus: () => {
|
|
89
150
|
if (!props.disabled) editor.value?.focus()
|
|
90
151
|
},
|
|
91
152
|
blur: () => editor.value?.blur(),
|
|
92
|
-
} satisfies
|
|
153
|
+
} satisfies InputActionHandle)
|
|
93
154
|
|
|
94
155
|
return () => {
|
|
95
156
|
validateInput(props)
|
|
96
157
|
const { colors, radius, typography, control, space } = theme.value
|
|
97
158
|
const id = props.id ?? generatedId
|
|
98
159
|
const message = props.error || props.helperText
|
|
160
|
+
const forwarded = inputAttrs(attrs)
|
|
99
161
|
const text = props.type === 'text' || props.type === 'search'
|
|
100
162
|
const border = props.error ? colors.danger : focused.value ? colors.primary : colors.border
|
|
163
|
+
const tokens = theme.value.components.input
|
|
164
|
+
const fontSize = tokens.fontSize ?? typography.body.fontSize
|
|
165
|
+
const family = fontFamily(tokens.fontFamily ?? typography.body.fontFamily, 'web')
|
|
166
|
+
const action = props.trailingAction
|
|
167
|
+
const icon = (name: typeof props.icon, trailing: boolean) =>
|
|
168
|
+
name
|
|
169
|
+
? h(MIcon, {
|
|
170
|
+
name,
|
|
171
|
+
size: 'md',
|
|
172
|
+
tone: props.error ? 'danger' : 'muted',
|
|
173
|
+
style: {
|
|
174
|
+
position: 'absolute',
|
|
175
|
+
[trailing ? 'right' : 'left']: `var(--m-input-padding-x, ${tokens.paddingX}px)`,
|
|
176
|
+
top: props.multiline ? `var(--m-input-padding-y, ${tokens.paddingY}px)` : '50%',
|
|
177
|
+
transform: props.multiline ? undefined : 'translateY(-50%)',
|
|
178
|
+
pointerEvents: 'none',
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
: null
|
|
101
182
|
return h(
|
|
102
183
|
'div',
|
|
103
184
|
mergeProps(
|
|
@@ -108,14 +189,15 @@ export const MInput = defineComponent({
|
|
|
108
189
|
flexDirection: 'column',
|
|
109
190
|
gap: `${space.sm}px`,
|
|
110
191
|
minWidth: 0,
|
|
192
|
+
fontFamily: fontFamily(typography.body.fontFamily, 'web'),
|
|
111
193
|
flexGrow: nonNegative(props.grow, 'grow'),
|
|
112
|
-
flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
|
|
194
|
+
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
113
195
|
width: length(resolveDimension(props.width)),
|
|
114
196
|
opacity: props.disabled ? 0.5 : 1,
|
|
115
197
|
'--m-input-placeholder': colors.muted,
|
|
116
198
|
},
|
|
117
199
|
},
|
|
118
|
-
webAttrs({ ...
|
|
200
|
+
webAttrs({ ...forwarded.wrapper, accessibilityHidden: props.accessibilityHidden }),
|
|
119
201
|
),
|
|
120
202
|
[
|
|
121
203
|
h(
|
|
@@ -131,70 +213,128 @@ export const MInput = defineComponent({
|
|
|
131
213
|
},
|
|
132
214
|
props.label,
|
|
133
215
|
),
|
|
134
|
-
h(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
216
|
+
h('div', { class: 'm-input-field', style: { position: 'relative', display: 'flex' } }, [
|
|
217
|
+
h(
|
|
218
|
+
props.multiline ? 'textarea' : 'input',
|
|
219
|
+
mergeProps(forwarded.editor, {
|
|
220
|
+
ref: editor,
|
|
221
|
+
id,
|
|
222
|
+
class: 'm-input-editor',
|
|
223
|
+
type: props.multiline ? undefined : props.type,
|
|
224
|
+
rows: props.multiline ? props.rows : undefined,
|
|
225
|
+
value: hydrationEdit() ?? props.modelValue,
|
|
226
|
+
name: props.name,
|
|
227
|
+
autocomplete: props.autocomplete,
|
|
228
|
+
required: props.required,
|
|
229
|
+
inputmode: props.inputmode,
|
|
230
|
+
form: props.form,
|
|
231
|
+
placeholder: props.placeholder,
|
|
232
|
+
disabled: props.disabled,
|
|
233
|
+
readonly: props.readonly,
|
|
234
|
+
maxlength: props.maxLength,
|
|
235
|
+
autocapitalize: props.autocapitalize ?? (text ? 'sentences' : 'none'),
|
|
236
|
+
autocorrect: (props.autocorrect ?? text) ? 'on' : 'off',
|
|
237
|
+
spellcheck: props.autocorrect ?? text,
|
|
238
|
+
enterkeyhint: props.multiline ? 'enter' : props.returnKey,
|
|
239
|
+
'aria-invalid': props.error ? 'true' : forwarded.editor['aria-invalid'],
|
|
240
|
+
'aria-describedby': describedBy(
|
|
241
|
+
forwarded.editor['aria-describedby'],
|
|
242
|
+
message ? `${id}-message` : undefined,
|
|
243
|
+
),
|
|
244
|
+
style: {
|
|
245
|
+
boxSizing: 'border-box',
|
|
246
|
+
width: '100%',
|
|
247
|
+
minWidth: 0,
|
|
248
|
+
minHeight: `${props.multiline ? props.rows * fontSize * tokens.lineHeight + tokens.paddingY * 2 + 2 : Math.max(control.md.height, action ? inputActionSize + 8 : 0)}px`,
|
|
249
|
+
margin: 0,
|
|
250
|
+
paddingTop: `var(--m-input-padding-y, ${tokens.paddingY}px)`,
|
|
251
|
+
paddingBottom: `var(--m-input-padding-y, ${tokens.paddingY}px)`,
|
|
252
|
+
paddingLeft: props.icon
|
|
253
|
+
? `calc(var(--m-input-padding-x, ${tokens.paddingX}px) + ${iconSizes.md + 10}px)`
|
|
254
|
+
: `var(--m-input-padding-x, ${tokens.paddingX}px)`,
|
|
255
|
+
paddingRight: action
|
|
256
|
+
? `max(var(--m-input-padding-x, ${tokens.paddingX}px), ${inputActionSize + 12}px)`
|
|
257
|
+
: props.trailingIcon
|
|
258
|
+
? `calc(var(--m-input-padding-x, ${tokens.paddingX}px) + ${iconSizes.md + 10}px)`
|
|
259
|
+
: `var(--m-input-padding-x, ${tokens.paddingX}px)`,
|
|
260
|
+
border: `1px solid ${border}`,
|
|
261
|
+
borderRadius: `var(--m-input-radius, ${resolveRadius(theme.value, tokens.radius)}px)`,
|
|
262
|
+
outline: 'none',
|
|
263
|
+
boxShadow: focused.value ? `0 0 0 2px ${border}` : 'none',
|
|
264
|
+
fontFamily: `var(--m-input-font-family, ${family})`,
|
|
265
|
+
fontSize: `var(--m-input-font-size, ${fontSize}px)`,
|
|
266
|
+
fontWeight: `var(--m-input-font-weight, ${tokens.fontWeight})`,
|
|
267
|
+
lineHeight: `var(--m-input-line-height, ${tokens.lineHeight})`,
|
|
268
|
+
backgroundColor: props.readonly ? colors.elevated : colors.surface,
|
|
269
|
+
color: colors.text,
|
|
270
|
+
caretColor: colors.primary,
|
|
271
|
+
resize: 'none',
|
|
272
|
+
overflow: props.multiline ? 'hidden' : undefined,
|
|
273
|
+
},
|
|
274
|
+
onInput: (event: Event) => {
|
|
275
|
+
if (props.disabled || props.readonly) return
|
|
276
|
+
const value = (event.target as HTMLInputElement).value
|
|
277
|
+
if (value !== props.modelValue) emit('update:modelValue', value)
|
|
278
|
+
resize()
|
|
279
|
+
},
|
|
280
|
+
onFocus: () => {
|
|
281
|
+
focused.value = true
|
|
282
|
+
emit('focus')
|
|
283
|
+
},
|
|
284
|
+
onBlur: () => {
|
|
285
|
+
focused.value = false
|
|
286
|
+
emit('blur')
|
|
287
|
+
},
|
|
288
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
289
|
+
if (
|
|
290
|
+
event.key !== 'Enter' ||
|
|
291
|
+
event.defaultPrevented ||
|
|
292
|
+
event.isComposing ||
|
|
293
|
+
event.keyCode === 229 ||
|
|
294
|
+
props.multiline
|
|
295
|
+
)
|
|
296
|
+
return
|
|
297
|
+
// An existing component handler owns this action (for example, focus next).
|
|
298
|
+
// Without one, leave implicit submission and validation to the HTML form.
|
|
299
|
+
const listeners = instance.vnode.props
|
|
300
|
+
if (!listeners?.onSubmit && !listeners?.onSubmitOnce && editor.value?.form) return
|
|
301
|
+
event.preventDefault()
|
|
302
|
+
if (!props.disabled && !props.readonly)
|
|
303
|
+
emit('submit', (event.target as HTMLInputElement).value)
|
|
304
|
+
},
|
|
305
|
+
}),
|
|
306
|
+
),
|
|
307
|
+
icon(props.icon, false),
|
|
308
|
+
icon(props.trailingIcon, true),
|
|
309
|
+
action
|
|
310
|
+
? h(MButton, {
|
|
311
|
+
ref: actionButton,
|
|
312
|
+
class: 'm-input-action',
|
|
313
|
+
type: 'button',
|
|
314
|
+
icon: action.icon,
|
|
315
|
+
accessibilityLabel: action.label,
|
|
316
|
+
variant: 'ghost',
|
|
317
|
+
disabled: props.disabled || props.readonly || action.disabled,
|
|
318
|
+
style: {
|
|
319
|
+
position: 'absolute',
|
|
320
|
+
right: '4px',
|
|
321
|
+
// Positioning must not overwrite the Button's Jolt-owned transform on updates.
|
|
322
|
+
top: props.multiline ? '4px' : `calc(50% - ${inputActionSize / 2}px)`,
|
|
323
|
+
height: `${inputActionSize}px`,
|
|
324
|
+
width: `${inputActionSize}px`,
|
|
325
|
+
minHeight: `${inputActionSize}px`,
|
|
326
|
+
padding: 0,
|
|
327
|
+
},
|
|
328
|
+
onPointerdown: (event: PointerEvent) => {
|
|
329
|
+
if (event.button === 0 && document.activeElement === editor.value)
|
|
330
|
+
event.preventDefault()
|
|
331
|
+
},
|
|
332
|
+
onClick: () => {
|
|
333
|
+
if (!props.disabled && !props.readonly && !action.disabled) emit('action')
|
|
334
|
+
},
|
|
335
|
+
})
|
|
336
|
+
: null,
|
|
337
|
+
]),
|
|
198
338
|
message
|
|
199
339
|
? h(
|
|
200
340
|
'p',
|
|
@@ -215,3 +355,8 @@ export const MInput = defineComponent({
|
|
|
215
355
|
}
|
|
216
356
|
},
|
|
217
357
|
})
|
|
358
|
+
|
|
359
|
+
// Vue's options overload does not infer setupContext.expose() in its constructor type.
|
|
360
|
+
export const MInput = Input as typeof Input & {
|
|
361
|
+
new (): InstanceType<typeof Input> & InputActionHandle & { $props: InputEditorAttributes }
|
|
362
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps } from 'vue'
|
|
2
|
+
import { fontFamily, nonNegative } from '@getcortexlabs/mavis-core'
|
|
3
|
+
import {
|
|
4
|
+
linkProps,
|
|
5
|
+
linkEmits,
|
|
6
|
+
textContent,
|
|
7
|
+
useLayoutShrink,
|
|
8
|
+
useMavisTheme,
|
|
9
|
+
useNavigationOptions,
|
|
10
|
+
viewAttrs,
|
|
11
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
12
|
+
import { webAttrs } from '../style.js'
|
|
13
|
+
import { navigationAttrs } from '../navigation.js'
|
|
14
|
+
|
|
15
|
+
export const MLink = defineComponent({
|
|
16
|
+
name: 'MLink',
|
|
17
|
+
inheritAttrs: false,
|
|
18
|
+
props: linkProps,
|
|
19
|
+
emits: linkEmits,
|
|
20
|
+
setup(props, { attrs, slots, emit }) {
|
|
21
|
+
const { theme } = useMavisTheme()
|
|
22
|
+
const shrink = useLayoutShrink()
|
|
23
|
+
const navigation = useNavigationOptions(props)
|
|
24
|
+
return () => {
|
|
25
|
+
const text = props.text ?? textContent(slots.default?.())
|
|
26
|
+
if (!(props.accessibilityLabel ?? text).trim()) throw new TypeError('MLink requires a name.')
|
|
27
|
+
const type = theme.value.typography.body
|
|
28
|
+
return h(
|
|
29
|
+
'a',
|
|
30
|
+
mergeProps(webAttrs({ ...attrs, ...viewAttrs(props) }), {
|
|
31
|
+
class: 'm-link',
|
|
32
|
+
style: {
|
|
33
|
+
'--m-focus': theme.value.colors.primary,
|
|
34
|
+
display: props.inline ? 'inline' : 'inline-flex',
|
|
35
|
+
alignItems: 'center',
|
|
36
|
+
justifyContent: 'center',
|
|
37
|
+
minHeight: props.inline ? undefined : '44px',
|
|
38
|
+
fontFamily: fontFamily(type.fontFamily, 'web'),
|
|
39
|
+
fontSize: `${type.fontSize}px`,
|
|
40
|
+
fontWeight: type.fontWeight,
|
|
41
|
+
lineHeight: type.lineHeight,
|
|
42
|
+
color: theme.value.colors.primary,
|
|
43
|
+
textDecoration: 'underline',
|
|
44
|
+
textUnderlineOffset: '0.18em',
|
|
45
|
+
cursor: props.disabled ? 'default' : 'pointer',
|
|
46
|
+
opacity: props.disabled ? 0.45 : 1,
|
|
47
|
+
overflowWrap: 'anywhere',
|
|
48
|
+
flexGrow: nonNegative(props.grow, 'grow'),
|
|
49
|
+
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
50
|
+
minWidth: 0,
|
|
51
|
+
},
|
|
52
|
+
...navigationAttrs(
|
|
53
|
+
navigation(),
|
|
54
|
+
props.disabled,
|
|
55
|
+
() => emit('click'),
|
|
56
|
+
(error) => emit('error', error),
|
|
57
|
+
),
|
|
58
|
+
}),
|
|
59
|
+
text,
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
})
|