frappe-ui 1.0.2 → 1.2.0
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/experimental/Calendar/CalendarEventRow.vue +0 -4
- package/experimental/Calendar/calendarUtils.ts +33 -21
- package/experimental/CommandPalette/CommandPaletteItem.vue +9 -1
- package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
- package/experimental/MultiEmailInput/types.ts +12 -3
- package/experimental/SpriteIcons/IconPicker.vue +2 -1
- package/experimental/Stepper/StepIndicator.vue +129 -0
- package/experimental/Stepper/Stepper.api.md +117 -0
- package/experimental/Stepper/Stepper.md +95 -0
- package/experimental/Stepper/Stepper.vue +82 -0
- package/experimental/Stepper/StepperHorizontal.vue +93 -0
- package/experimental/Stepper/StepperVertical.vue +291 -0
- package/experimental/Stepper/index.ts +11 -0
- package/experimental/Stepper/resolve.ts +87 -0
- package/experimental/Stepper/types.ts +89 -0
- package/experimental.ts +2 -21
- package/package.json +1 -3
- package/src/charts/CalendarHeatmapChart.vue +353 -0
- package/src/charts/DonutChart.vue +34 -58
- package/src/charts/HeatmapChart.vue +26 -64
- package/src/charts/NumberCard.vue +62 -7
- package/src/charts/PercentageBarChart.vue +243 -0
- package/src/charts/SankeyChart.vue +14 -11
- package/src/charts/ScatterChart.vue +24 -20
- package/src/charts/axisChartCommon.ts +182 -18
- package/src/charts/axisFormat.ts +8 -3
- package/src/charts/calendarHeatmapOptions.ts +604 -0
- package/src/charts/colorMath.ts +26 -0
- package/src/charts/components/ChartContainer.vue +63 -53
- package/src/charts/components/ChartLegend.vue +216 -24
- package/src/charts/components/ChartScale.vue +85 -0
- package/src/charts/core/dataLabelFit.ts +45 -6
- package/src/charts/core/useAxisChart.ts +36 -19
- package/src/charts/core/useChart.ts +6 -1
- package/src/charts/core/usePlotKeyboard.ts +13 -2
- package/src/charts/docs/BarChart.md +11 -3
- package/src/charts/docs/CalendarHeatmapChart.api.md +165 -0
- package/src/charts/docs/CalendarHeatmapChart.md +33 -0
- package/src/charts/docs/ChartContainer.api.md +6 -0
- package/src/charts/docs/ChartLegend.api.md +1 -1
- package/src/charts/docs/ChartLegend.md +25 -3
- package/src/charts/docs/DonutChart.api.md +12 -0
- package/src/charts/docs/DonutChart.md +17 -0
- package/src/charts/docs/HeatmapChart.api.md +1 -1
- package/src/charts/docs/LineChart.md +5 -3
- package/src/charts/docs/NumberCard.api.md +6 -0
- package/src/charts/docs/NumberCard.md +6 -0
- package/src/charts/docs/Overview.md +13 -6
- package/src/charts/docs/PercentageBarChart.api.md +148 -0
- package/src/charts/docs/PercentageBarChart.md +42 -0
- package/src/charts/docs/ScatterChart.md +2 -3
- package/src/charts/donutChartOptions.ts +22 -130
- package/src/charts/format.ts +4 -1
- package/src/charts/heatmapOptions.ts +17 -12
- package/src/charts/hiddenSeries.ts +8 -3
- package/src/charts/index.ts +12 -0
- package/src/charts/legendOverflow.ts +40 -0
- package/src/charts/numberCardFormat.ts +19 -13
- package/src/charts/referenceLines.ts +2 -1
- package/src/charts/scatterOptions.ts +16 -3
- package/src/charts/seriesData.ts +8 -3
- package/src/charts/slices.ts +228 -0
- package/src/charts/tokens.ts +99 -0
- package/src/charts/types.ts +318 -9
- package/src/components/Avatar/Avatar.md +27 -2
- package/src/components/Avatar/Avatar.vue +29 -12
- package/src/components/Breadcrumbs/Breadcrumbs.vue +2 -1
- package/src/components/Combobox/Combobox.vue +9 -2
- package/src/components/Combobox/ComboboxResults.vue +6 -1
- package/src/components/Combobox/utils.ts +2 -1
- package/src/components/DatePicker/DatePicker.md +7 -0
- package/src/components/DatePicker/DatePicker.vue +6 -0
- package/src/components/DatePicker/DateTimePicker.vue +6 -0
- package/src/components/DatePicker/composables.ts +18 -1
- package/src/components/DatePicker/utils.ts +53 -0
- package/src/components/Dialog/Dialog.md +3 -1
- package/src/components/Duration/Duration.api.md +16 -3
- package/src/components/Duration/Duration.md +21 -0
- package/src/components/Duration/Duration.vue +29 -8
- package/src/components/Duration/duration.ts +105 -44
- package/src/components/Duration/index.ts +1 -0
- package/src/components/Duration/types.ts +30 -1
- package/src/components/HoverCard/HoverCard.vue +21 -5
- package/src/components/Menu/utils.ts +3 -2
- package/src/components/MobileNav/MobileNavItem.vue +3 -22
- package/src/components/MultiSelect/MultiSelect.api.md +5 -0
- package/src/components/MultiSelect/MultiSelect.vue +34 -0
- package/src/components/MultiSelect/MultiSelectResults.vue +3 -4
- package/src/components/MultiSelect/types.ts +6 -0
- package/src/components/Select/Select.vue +4 -4
- package/src/components/Select/utils.ts +1 -0
- package/src/components/SettingsDialog/SettingsDialog.api.md +7 -2
- package/src/components/SettingsDialog/SettingsDialog.md +2 -1
- package/src/components/SettingsDialog/SettingsRow.vue +12 -2
- package/src/components/Sidebar/SidebarItem.vue +3 -33
- package/src/components/SidebarRail/SidebarRailItem.vue +4 -17
- package/src/components/Switch/Switch.vue +3 -3
- package/src/components/Tooltip/Tooltip.vue +8 -0
- package/src/components/shared/deferredTrigger.ts +174 -0
- package/src/components/shared/navLink.ts +45 -0
- package/src/components/shared/selection/utils.ts +8 -1
- package/src/data-fetching/useCall/useCall.ts +25 -26
- package/src/data-fetching/useFrappeFetch.ts +48 -2
- package/src/data-fetching/useList/useList.ts +11 -3
- package/src/data-fetching/utils.ts +15 -1
- package/src/molecules/editor/components/MediaNodeView.vue +10 -1
- package/src/molecules/editor/components/MediaResizeGuide.vue +71 -0
- package/src/molecules/editor/components/media-node-view-utils.ts +7 -0
- package/src/molecules/editor/composables/useNodeViewResize.ts +142 -10
- package/src/molecules/editor/extensions/attachment/attachment-engine.ts +1 -1
- package/src/molecules/editor/extensions/content-paste/paste-html-utils.ts +16 -6
- package/src/molecules/editor/extensions/iframe/IframeNodeView.vue +29 -10
- package/src/molecules/editor/extensions/iframe/iframe-allowlist.ts +35 -16
- package/src/molecules/editor/extensions/iframe/iframe-embed-utils.ts +1 -1
- package/src/molecules/editor/extensions/iframe/iframe-extension.ts +30 -30
- package/src/molecules/editor/extensions/link/LinkEditorPopup.vue +1 -1
- package/src/molecules/editor/extensions/link/link-paste-plugin.ts +1 -1
- package/src/molecules/editor/extensions/shared/media-upload-engine.ts +1 -1
- package/src/molecules/editor/useEditor.ts +12 -6
- package/src/molecules/list/ListRow.vue +8 -1
- package/src/utils/dialog.ts +57 -16
- package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
- package/tailwind/content.js +1 -1
- package/tailwind/plugin.js +22 -0
- package/vite/README.md +5 -3
- package/vite/codeLanguages.js +41 -17
- package/vite/doctypeInterfaceGenerator.js +52 -39
- package/vitepress/index.node.ts +0 -2
- package/experimental/TextEditor/TextEditor.api.md +0 -161
- package/experimental/TextEditor/TextEditor.vue +0 -298
- package/experimental/TextEditor/classIcon.ts +0 -21
- package/experimental/TextEditor/commands.js +0 -344
- package/experimental/TextEditor/components/CodeBlockComponent.vue +0 -103
- package/experimental/TextEditor/components/FontColor.vue +0 -153
- package/experimental/TextEditor/components/ImageViewerModal.vue +0 -463
- package/experimental/TextEditor/components/InsertImage.vue +0 -54
- package/experimental/TextEditor/components/InsertLink.vue +0 -13
- package/experimental/TextEditor/components/InsertVideo.vue +0 -14
- package/experimental/TextEditor/components/LinkPopup.vue +0 -99
- package/experimental/TextEditor/components/MediaNodeView.vue +0 -398
- package/experimental/TextEditor/components/MentionList.vue +0 -95
- package/experimental/TextEditor/components/TextEditorBubbleMenu.vue +0 -78
- package/experimental/TextEditor/components/TextEditorFixedMenu.vue +0 -78
- package/experimental/TextEditor/components/TextEditorFloatingMenu.vue +0 -61
- package/experimental/TextEditor/components/TextEditorMenu.vue +0 -218
- package/experimental/TextEditor/components/index.js +0 -0
- package/experimental/TextEditor/extensions/code-block.ts +0 -119
- package/experimental/TextEditor/extensions/color/color-extension.ts +0 -140
- package/experimental/TextEditor/extensions/color/color-styles.css +0 -25
- package/experimental/TextEditor/extensions/color/index.ts +0 -2
- package/experimental/TextEditor/extensions/content-paste-extension.ts +0 -160
- package/experimental/TextEditor/extensions/copy-styles.ts +0 -160
- package/experimental/TextEditor/extensions/emoji/EmojiList.vue +0 -55
- package/experimental/TextEditor/extensions/emoji/emoji-extension.ts +0 -55
- package/experimental/TextEditor/extensions/emoji/emojis.json +0 -7422
- package/experimental/TextEditor/extensions/heading/heading.ts +0 -20
- package/experimental/TextEditor/extensions/highlight/highlight-extension.ts +0 -241
- package/experimental/TextEditor/extensions/highlight/highlight-styles.css +0 -31
- package/experimental/TextEditor/extensions/highlight/index.ts +0 -2
- package/experimental/TextEditor/extensions/iframe/IframeNodeView.vue +0 -308
- package/experimental/TextEditor/extensions/iframe/InsertIframe.vue +0 -209
- package/experimental/TextEditor/extensions/iframe/iframe-extension.ts +0 -404
- package/experimental/TextEditor/extensions/iframe/index.ts +0 -11
- package/experimental/TextEditor/extensions/iframe/utils.ts +0 -283
- package/experimental/TextEditor/extensions/image/image-extension.ts +0 -661
- package/experimental/TextEditor/extensions/image/index.ts +0 -5
- package/experimental/TextEditor/extensions/image-group/ImageGroupNodeView.vue +0 -182
- package/experimental/TextEditor/extensions/image-group/ImageGroupUploadDialog.vue +0 -740
- package/experimental/TextEditor/extensions/image-group/image-group-extension.ts +0 -187
- package/experimental/TextEditor/extensions/image-viewer-extension.ts +0 -162
- package/experimental/TextEditor/extensions/link/index.ts +0 -1
- package/experimental/TextEditor/extensions/link/link-extension.ts +0 -323
- package/experimental/TextEditor/extensions/link/linkPasteHandler.ts +0 -51
- package/experimental/TextEditor/extensions/mention/index.ts +0 -1
- package/experimental/TextEditor/extensions/mention/mention-extension.ts +0 -204
- package/experimental/TextEditor/extensions/mention/style.css +0 -11
- package/experimental/TextEditor/extensions/shared/color-utils.ts +0 -236
- package/experimental/TextEditor/extensions/slash-commands/SlashCommandsList.vue +0 -59
- package/experimental/TextEditor/extensions/slash-commands/slash-commands-extension.ts +0 -184
- package/experimental/TextEditor/extensions/suggestion/SuggestionList.vue +0 -130
- package/experimental/TextEditor/extensions/suggestion/createSuggestionExtension.ts +0 -151
- package/experimental/TextEditor/extensions/suggestion/index.ts +0 -5
- package/experimental/TextEditor/extensions/tag/index.ts +0 -1
- package/experimental/TextEditor/extensions/tag/tag-extension.ts +0 -170
- package/experimental/TextEditor/extensions/toc-node/TocNodeView.vue +0 -439
- package/experimental/TextEditor/extensions/toc-node/index.ts +0 -3
- package/experimental/TextEditor/extensions/toc-node/toc-node-extension.ts +0 -167
- package/experimental/TextEditor/extensions/video-extension.ts +0 -653
- package/experimental/TextEditor/hljs-github.css +0 -197
- package/experimental/TextEditor/index.ts +0 -21
- package/experimental/TextEditor/style.css +0 -190
- package/experimental/TextEditor/types.ts +0 -72
- package/experimental/TextEditor/utils.js +0 -11
- package/src/utils/url-validation.ts +0 -39
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
HoverCardPortal,
|
|
6
6
|
HoverCardRoot,
|
|
7
7
|
HoverCardTrigger,
|
|
8
|
+
Slot,
|
|
8
9
|
injectHoverCardRootContext,
|
|
9
10
|
} from 'reka-ui'
|
|
10
11
|
import { computed, defineComponent, ref, watch } from 'vue'
|
|
11
12
|
import PopoverPanel from '../shared/popover/PopoverPanel.vue'
|
|
12
13
|
import { usePortalTarget } from '../../composables/usePortalTarget'
|
|
14
|
+
import { useDeferredTrigger } from '../shared/deferredTrigger'
|
|
13
15
|
import type {
|
|
14
16
|
HoverCardExposed,
|
|
15
17
|
HoverCardProps,
|
|
@@ -40,6 +42,9 @@ const closeDelay = computed(() => props.leaveDelay)
|
|
|
40
42
|
const triggerRef = ref<{ $el: Element } | null>(null)
|
|
41
43
|
const controllerRef = ref<{ setOpen: (value: boolean) => void } | null>(null)
|
|
42
44
|
|
|
45
|
+
// The trigger renders alone until it is first hovered or focused.
|
|
46
|
+
const { mounted, mount, shellProps } = useDeferredTrigger('hoverCard')
|
|
47
|
+
|
|
43
48
|
const HoverCardController = defineComponent({
|
|
44
49
|
setup(_, { expose }) {
|
|
45
50
|
const context = injectHoverCardRootContext()
|
|
@@ -69,11 +74,18 @@ function close() {
|
|
|
69
74
|
setOpen(false)
|
|
70
75
|
}
|
|
71
76
|
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
// Opening from the model, a template ref or a slot control mounts the card
|
|
78
|
+
// without a hover first. A controlled parent can also close without calling
|
|
79
|
+
// the slot control, so clear any imperative-open timer then, or Reka could
|
|
80
|
+
// reopen after the model turns false.
|
|
81
|
+
watch(
|
|
82
|
+
open,
|
|
83
|
+
(isOpen) => {
|
|
84
|
+
if (isOpen) mount()
|
|
85
|
+
else controllerRef.value?.setOpen(false)
|
|
86
|
+
},
|
|
87
|
+
{ immediate: true },
|
|
88
|
+
)
|
|
77
89
|
|
|
78
90
|
const slotProps = computed<HoverCardSlotProps>(() => ({
|
|
79
91
|
open: open.value,
|
|
@@ -102,7 +114,11 @@ function onPointerDownOutside(event: Event) {
|
|
|
102
114
|
</script>
|
|
103
115
|
|
|
104
116
|
<template>
|
|
117
|
+
<Slot v-if="!mounted" v-bind="shellProps">
|
|
118
|
+
<slot name="trigger" v-bind="slotProps" />
|
|
119
|
+
</Slot>
|
|
105
120
|
<HoverCardRoot
|
|
121
|
+
v-else
|
|
106
122
|
v-model:open="open"
|
|
107
123
|
:open-delay="openDelay"
|
|
108
124
|
:close-delay="closeDelay"
|
|
@@ -16,8 +16,9 @@ export type NormalizedMenuGroup = MenuGroupOption & {
|
|
|
16
16
|
|
|
17
17
|
export const menuClasses = {
|
|
18
18
|
content:
|
|
19
|
-
'menu-content z-[100] min-w-40 divide-y divide-outline-elevation-2 rounded-6 bg-surface-elevation-2 shadow-2xl ring-1 ring-black ring-opacity-5 focus:outline-none',
|
|
20
|
-
|
|
19
|
+
'menu-content z-[100] min-w-40 max-h-[--reka-popper-available-height] overflow-y-auto divide-y divide-outline-elevation-2 rounded-6 bg-surface-elevation-2 shadow-2xl ring-1 ring-black ring-opacity-5 focus:outline-none',
|
|
20
|
+
// The 1px gap keeps a highlighted row and a selected row next to it visibly separate.
|
|
21
|
+
group: 'flex flex-col gap-px p-1.5',
|
|
21
22
|
groupLabel:
|
|
22
23
|
'flex h-7 items-center px-2 text-sm font-medium leading-tighter text-ink-gray-4',
|
|
23
24
|
itemIcon: 'size-4 shrink-0',
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
</template>
|
|
61
61
|
|
|
62
62
|
<script setup lang="ts">
|
|
63
|
-
import { computed
|
|
64
|
-
import { RouterLink } from 'vue-router'
|
|
63
|
+
import { computed } from 'vue'
|
|
65
64
|
import Icon from '../Icon/Icon.vue'
|
|
65
|
+
import { useNavLink } from '../shared/navLink'
|
|
66
66
|
import { scrollShellToTop } from '../../composables/useShellScrolled'
|
|
67
67
|
import type { MobileNavItemProps } from './types'
|
|
68
68
|
|
|
@@ -73,26 +73,7 @@ defineSlots<{
|
|
|
73
73
|
default?: (props: { active: boolean }) => any
|
|
74
74
|
}>()
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
// works without warnings when mounted outside a vue-router app — docs, tests,
|
|
78
|
-
// embedded use. Same approach as SidebarItem.
|
|
79
|
-
const globals = getCurrentInstance()?.appContext.config.globalProperties
|
|
80
|
-
const hasRouter = computed(() => Boolean(globals?.$router))
|
|
81
|
-
|
|
82
|
-
const linkComponent = computed(() =>
|
|
83
|
-
props.route && hasRouter.value ? RouterLink : 'a',
|
|
84
|
-
)
|
|
85
|
-
const linkAttrs = computed(() =>
|
|
86
|
-
props.route
|
|
87
|
-
? hasRouter.value
|
|
88
|
-
? { to: props.route }
|
|
89
|
-
: { href: typeof props.route === 'string' ? props.route : undefined }
|
|
90
|
-
: { href: props.href },
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
const resolvedRoute = computed(() =>
|
|
94
|
-
props.route && globals?.$router ? globals.$router.resolve(props.route) : null,
|
|
95
|
-
)
|
|
76
|
+
const { globals, linkComponent, linkAttrs, resolvedRoute } = useNavLink(props)
|
|
96
77
|
|
|
97
78
|
// Is this item's target the exact current route? Drives scroll-vs-navigate and
|
|
98
79
|
// aria-current — distinct from `active`, which may span a whole section.
|
|
@@ -247,6 +247,11 @@
|
|
|
247
247
|
name: 'update:selectedOptions',
|
|
248
248
|
description: 'Fired alongside `update:modelValue` with the original option objects\nresolved out of `options`, so custom fields on an option survive.',
|
|
249
249
|
type: '[value: MultiSelectOption[]]'
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: 'highlight',
|
|
253
|
+
description: 'Fired when the highlighted row changes, by arrow keys or the pointer, with\nthe original option object. `null` once the popover closes.',
|
|
254
|
+
type: '[option: MultiSelectOption | null]'
|
|
250
255
|
}
|
|
251
256
|
]
|
|
252
257
|
|
|
@@ -111,6 +111,22 @@ const {
|
|
|
111
111
|
hasDescriptionSlot: () => Boolean(slots.description),
|
|
112
112
|
})
|
|
113
113
|
|
|
114
|
+
const triggerAttrs = computed(() => {
|
|
115
|
+
const { class: _class, style: _style, ...rest } = attrs
|
|
116
|
+
return rest
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// The list is named like the field: by its label, else by the name given to
|
|
120
|
+
// the component itself.
|
|
121
|
+
const listAttrs = computed(() =>
|
|
122
|
+
props.label || slots.label
|
|
123
|
+
? { 'aria-labelledby': labelId.value }
|
|
124
|
+
: {
|
|
125
|
+
'aria-label': attrs['aria-label'],
|
|
126
|
+
'aria-labelledby': attrs['aria-labelledby'],
|
|
127
|
+
},
|
|
128
|
+
)
|
|
129
|
+
|
|
114
130
|
const hasLabeling = computed(() => {
|
|
115
131
|
return Boolean(
|
|
116
132
|
props.label ||
|
|
@@ -307,6 +323,21 @@ function handleRootOpenChange(value: boolean) {
|
|
|
307
323
|
open.value = value
|
|
308
324
|
}
|
|
309
325
|
|
|
326
|
+
const highlightedValue = ref<unknown>()
|
|
327
|
+
|
|
328
|
+
const highlightedOption = computed<MultiSelectOption | null>(() => {
|
|
329
|
+
if (highlightedValue.value === undefined) return null
|
|
330
|
+
const value = toExternalValue(highlightedValue.value)
|
|
331
|
+
return rawOptions.value.find((option) => option.value === value) ?? null
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
watch(highlightedOption, (option) => emit('highlight', option))
|
|
335
|
+
|
|
336
|
+
// reka reports each new highlight but never its end, which comes with closing.
|
|
337
|
+
watch(open, (isOpen) => {
|
|
338
|
+
if (!isOpen) highlightedValue.value = undefined
|
|
339
|
+
})
|
|
340
|
+
|
|
310
341
|
function handleInputChange(event: Event) {
|
|
311
342
|
setQuery((event.target as HTMLInputElement).value)
|
|
312
343
|
}
|
|
@@ -380,6 +411,7 @@ defineSlots<MultiSelectSlots>()
|
|
|
380
411
|
:ignore-filter="true"
|
|
381
412
|
@update:modelValue="handleRootModelValueChange"
|
|
382
413
|
@update:open="handleRootOpenChange"
|
|
414
|
+
@highlight="highlightedValue = $event?.value"
|
|
383
415
|
>
|
|
384
416
|
<ComboboxAnchor as-child @click="handleTriggerClick">
|
|
385
417
|
<slot v-if="$slots.trigger" name="trigger" v-bind="slotProps" />
|
|
@@ -394,6 +426,7 @@ defineSlots<MultiSelectSlots>()
|
|
|
394
426
|
<button
|
|
395
427
|
v-else
|
|
396
428
|
ref="trigger"
|
|
429
|
+
v-bind="triggerAttrs"
|
|
397
430
|
type="button"
|
|
398
431
|
:class="[
|
|
399
432
|
triggerClasses,
|
|
@@ -485,6 +518,7 @@ defineSlots<MultiSelectSlots>()
|
|
|
485
518
|
|
|
486
519
|
<ComboboxPortal :to="portalTarget">
|
|
487
520
|
<ComboboxContent
|
|
521
|
+
v-bind="listAttrs"
|
|
488
522
|
data-slot="content"
|
|
489
523
|
data-selection
|
|
490
524
|
:data-variant="variant"
|
|
@@ -246,10 +246,9 @@ function getItemTextValue(item: NormalizedOption) {
|
|
|
246
246
|
|
|
247
247
|
<style scoped>
|
|
248
248
|
/*
|
|
249
|
-
* The outer item row paints its own bg via data-[highlighted]
|
|
250
|
-
*
|
|
251
|
-
* state.
|
|
252
|
-
* through; text emphasis on selected stays.
|
|
249
|
+
* The outer item row paints its own bg via data-[highlighted]. Clear
|
|
250
|
+
* ItemListRow's own bg, so a checked row is not filled: the checkbox shows
|
|
251
|
+
* the state. Text emphasis on selected stays.
|
|
253
252
|
*/
|
|
254
253
|
[data-slot='item'] [data-slot='item-list-row'] {
|
|
255
254
|
background-color: transparent;
|
|
@@ -320,4 +320,10 @@ export interface MultiSelectEmits {
|
|
|
320
320
|
* resolved out of `options`, so custom fields on an option survive.
|
|
321
321
|
*/
|
|
322
322
|
'update:selectedOptions': [value: MultiSelectOption[]]
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Fired when the highlighted row changes, by arrow keys or the pointer, with
|
|
326
|
+
* the original option object. `null` once the popover closes.
|
|
327
|
+
*/
|
|
328
|
+
highlight: [option: MultiSelectOption | null]
|
|
323
329
|
}
|
|
@@ -36,6 +36,7 @@ import OptionIcon from '../shared/selection/OptionIcon.vue'
|
|
|
36
36
|
import PopoverPanel from '../shared/popover/PopoverPanel.vue'
|
|
37
37
|
import {
|
|
38
38
|
EMPTY_VALUE_PREFIX,
|
|
39
|
+
checkedItemClasses,
|
|
39
40
|
inputFontSizeClasses,
|
|
40
41
|
itemClasses,
|
|
41
42
|
itemRootSizeClasses,
|
|
@@ -215,9 +216,8 @@ const internalModel = computed<SelectOptionValue | undefined>({
|
|
|
215
216
|
|
|
216
217
|
const selectedOption = computed(() => {
|
|
217
218
|
return (
|
|
218
|
-
selectOptions.value.find(
|
|
219
|
-
|
|
220
|
-
) ?? null
|
|
219
|
+
selectOptions.value.find((option) => option.value === currentValue.value) ??
|
|
220
|
+
null
|
|
221
221
|
)
|
|
222
222
|
})
|
|
223
223
|
|
|
@@ -467,7 +467,7 @@ defineExpose(exposed)
|
|
|
467
467
|
:disabled="internalOption.option.disabled"
|
|
468
468
|
:value="internalOption.internalValue"
|
|
469
469
|
data-slot="item"
|
|
470
|
-
:class="[itemClasses, itemRootClasses]"
|
|
470
|
+
:class="[itemClasses, checkedItemClasses, itemRootClasses]"
|
|
471
471
|
>
|
|
472
472
|
<!--
|
|
473
473
|
Full-row takeover precedence:
|
|
@@ -223,8 +223,13 @@
|
|
|
223
223
|
const settingsRowSlots = [
|
|
224
224
|
{
|
|
225
225
|
name: 'default',
|
|
226
|
-
description: '',
|
|
227
|
-
type: '
|
|
226
|
+
description: 'The setting\'s control, on the right.',
|
|
227
|
+
type: 'any'
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
name: 'description',
|
|
231
|
+
description: 'Replaces the `description` text, for content such as a link.',
|
|
232
|
+
type: 'any'
|
|
228
233
|
}
|
|
229
234
|
]
|
|
230
235
|
</script>
|
|
@@ -92,7 +92,8 @@ headers never scroll away. `SettingsHeader` takes `title`, `description` and an
|
|
|
92
92
|
`SettingsRow` shows a setting's title and description on the left and its
|
|
93
93
|
control on the right. When the control is a frappe-ui control such as `Switch`,
|
|
94
94
|
the title becomes its `<label>`, with no `label-for` needed. Set `labelFor` to
|
|
95
|
-
point the label at another element's id.
|
|
95
|
+
point the label at another element's id. The `#description` slot replaces the
|
|
96
|
+
`description` text, for a description that holds markup such as a link.
|
|
96
97
|
|
|
97
98
|
## Accessibility
|
|
98
99
|
|
|
@@ -9,8 +9,11 @@
|
|
|
9
9
|
>
|
|
10
10
|
{{ title }}
|
|
11
11
|
</component>
|
|
12
|
-
<div
|
|
13
|
-
|
|
12
|
+
<div
|
|
13
|
+
v-if="description || $slots.description"
|
|
14
|
+
class="mt-1 text-base leading-5 text-ink-gray-6"
|
|
15
|
+
>
|
|
16
|
+
<slot name="description">{{ description }}</slot>
|
|
14
17
|
</div>
|
|
15
18
|
</div>
|
|
16
19
|
<div ref="control" class="flex shrink-0 items-start justify-end">
|
|
@@ -31,6 +34,13 @@ const props = defineProps<{
|
|
|
31
34
|
labelFor?: string
|
|
32
35
|
}>()
|
|
33
36
|
|
|
37
|
+
defineSlots<{
|
|
38
|
+
/** The setting's control, on the right. */
|
|
39
|
+
default?: () => any
|
|
40
|
+
/** Replaces the `description` text, for content such as a link. */
|
|
41
|
+
description?: () => any
|
|
42
|
+
}>()
|
|
43
|
+
|
|
34
44
|
// frappe-ui form controls (Switch, Checkbox, …) render their interactive
|
|
35
45
|
// element with `data-slot="control"` and an auto-generated id. Detect it so the
|
|
36
46
|
// title acts as a clickable <label> without the caller wiring up an id.
|
|
@@ -128,17 +128,9 @@
|
|
|
128
128
|
</template>
|
|
129
129
|
|
|
130
130
|
<script setup lang="ts">
|
|
131
|
-
import {
|
|
132
|
-
computed,
|
|
133
|
-
getCurrentInstance,
|
|
134
|
-
inject,
|
|
135
|
-
onMounted,
|
|
136
|
-
ref,
|
|
137
|
-
useAttrs,
|
|
138
|
-
useTemplateRef,
|
|
139
|
-
} from 'vue'
|
|
140
|
-
import { RouterLink } from 'vue-router'
|
|
131
|
+
import { computed, inject, onMounted, ref, useAttrs, useTemplateRef } from 'vue'
|
|
141
132
|
import Icon from '../Icon/Icon.vue'
|
|
133
|
+
import { useNavLink } from '../shared/navLink'
|
|
142
134
|
import Tooltip from '../Tooltip/Tooltip.vue'
|
|
143
135
|
import { SidebarItemProps, sidebarCollapsedKey } from './types'
|
|
144
136
|
|
|
@@ -210,29 +202,7 @@ const ariaLabel = computed(
|
|
|
210
202
|
() => (attrs['aria-label'] as string) || tooltipText.value || undefined,
|
|
211
203
|
)
|
|
212
204
|
|
|
213
|
-
|
|
214
|
-
// so this component works — without warnings or crashes — when mounted outside a
|
|
215
|
-
// vue-router app (docs, tests, embedded use). vue-router installs $router/$route
|
|
216
|
-
// here; the $route getter stays reactive when read inside a computed.
|
|
217
|
-
const globals = getCurrentInstance()?.appContext.config.globalProperties
|
|
218
|
-
const hasRouter = computed(() => Boolean(globals?.$router))
|
|
219
|
-
|
|
220
|
-
// With a router, render RouterLink; without one, degrade to a plain <a> (with an
|
|
221
|
-
// href only when `route` is a string — we can't resolve a route-location object).
|
|
222
|
-
const linkComponent = computed(() =>
|
|
223
|
-
props.route && hasRouter.value ? RouterLink : 'a',
|
|
224
|
-
)
|
|
225
|
-
const linkAttrs = computed(() =>
|
|
226
|
-
props.route
|
|
227
|
-
? hasRouter.value
|
|
228
|
-
? { to: props.route }
|
|
229
|
-
: { href: typeof props.route === 'string' ? props.route : undefined }
|
|
230
|
-
: { href: props.href },
|
|
231
|
-
)
|
|
232
|
-
|
|
233
|
-
const resolvedRoute = computed(() =>
|
|
234
|
-
props.route && globals?.$router ? globals.$router.resolve(props.route) : null,
|
|
235
|
-
)
|
|
205
|
+
const { globals, linkComponent, linkAttrs, resolvedRoute } = useNavLink(props)
|
|
236
206
|
|
|
237
207
|
// Explicit `active` wins; otherwise infer from the current route so
|
|
238
208
|
// router-driven items light up without extra wiring.
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
</template>
|
|
73
73
|
|
|
74
74
|
<script setup lang="ts">
|
|
75
|
-
import { computed
|
|
76
|
-
import { RouterLink } from 'vue-router'
|
|
75
|
+
import { computed } from 'vue'
|
|
77
76
|
import Icon from '../Icon/Icon.vue'
|
|
77
|
+
import { useNavLink } from '../shared/navLink'
|
|
78
78
|
import Tooltip from '../Tooltip/Tooltip.vue'
|
|
79
79
|
import SidebarRailItemBadge from './SidebarRailItemBadge.vue'
|
|
80
80
|
import type { SidebarRailItemProps } from './types'
|
|
@@ -98,21 +98,8 @@ defineSlots<{
|
|
|
98
98
|
default?: () => any
|
|
99
99
|
}>()
|
|
100
100
|
|
|
101
|
-
const globals =
|
|
102
|
-
|
|
103
|
-
const linkComponent = computed(() =>
|
|
104
|
-
props.route && hasRouter.value ? RouterLink : 'a',
|
|
105
|
-
)
|
|
106
|
-
const linkAttrs = computed(() =>
|
|
107
|
-
props.route
|
|
108
|
-
? hasRouter.value
|
|
109
|
-
? { to: props.route }
|
|
110
|
-
: { href: typeof props.route === 'string' ? props.route : undefined }
|
|
111
|
-
: { href: props.href },
|
|
112
|
-
)
|
|
113
|
-
const resolvedRoute = computed(() =>
|
|
114
|
-
props.route && globals?.$router ? globals.$router.resolve(props.route) : null,
|
|
115
|
-
)
|
|
101
|
+
const { globals, linkComponent, linkAttrs, resolvedRoute } = useNavLink(props)
|
|
102
|
+
|
|
116
103
|
const resolvedActive = computed(() => {
|
|
117
104
|
if (props.active !== undefined) return props.active
|
|
118
105
|
const target = resolvedRoute.value
|
|
@@ -139,10 +139,10 @@ const switchClasses = computed(() => {
|
|
|
139
139
|
// The focus ring is applied globally via :focus-visible. In the padded
|
|
140
140
|
// padded rows it is shown on the row instead, so suppress it on the control.
|
|
141
141
|
props.padded ? 'focus:outline-none focus:ring-0' : '',
|
|
142
|
-
'disabled:cursor-not-allowed
|
|
142
|
+
'disabled:cursor-not-allowed',
|
|
143
143
|
model.value
|
|
144
|
-
? 'bg-surface-gray-10 enabled:hover:bg-surface-gray-9 active:bg-surface-gray-8 group-hover:enabled:bg-surface-gray-9'
|
|
145
|
-
: 'bg-surface-gray-4 enabled:hover:bg-surface-gray-5 active:bg-surface-gray-6 group-hover:enabled:bg-surface-gray-5',
|
|
144
|
+
? 'bg-surface-gray-10 enabled:hover:bg-surface-gray-9 active:bg-surface-gray-8 group-hover:enabled:bg-surface-gray-9 disabled:bg-surface-gray-7'
|
|
145
|
+
: 'bg-surface-gray-4 enabled:hover:bg-surface-gray-5 active:bg-surface-gray-6 group-hover:enabled:bg-surface-gray-5 disabled:bg-surface-gray-3',
|
|
146
146
|
props.size === 'md'
|
|
147
147
|
? 'h-5 w-8 border-[3px]'
|
|
148
148
|
: props.size === 'sm'
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import {
|
|
3
|
+
Slot,
|
|
3
4
|
TooltipProvider,
|
|
4
5
|
TooltipRoot,
|
|
5
6
|
TooltipTrigger,
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
} from 'reka-ui'
|
|
8
9
|
import TooltipBubble from './TooltipBubble.vue'
|
|
9
10
|
import { computed, type Component } from 'vue'
|
|
11
|
+
import { useDeferredTrigger } from '../shared/deferredTrigger'
|
|
10
12
|
import type { TooltipProps } from './types'
|
|
11
13
|
|
|
12
14
|
defineOptions({
|
|
@@ -36,6 +38,9 @@ const providerProps = computed(() =>
|
|
|
36
38
|
parentProvider ? {} : { delayDuration: delayDuration.value },
|
|
37
39
|
)
|
|
38
40
|
|
|
41
|
+
// The trigger renders alone until it is first hovered or focused.
|
|
42
|
+
const { mounted, shellProps } = useDeferredTrigger('tooltip')
|
|
43
|
+
|
|
39
44
|
defineSlots<{
|
|
40
45
|
/**
|
|
41
46
|
* The trigger. Tooltip is the one overlay whose `#default` is the trigger
|
|
@@ -51,6 +56,9 @@ defineSlots<{
|
|
|
51
56
|
|
|
52
57
|
<template>
|
|
53
58
|
<slot v-if="disabled" />
|
|
59
|
+
<Slot v-else-if="!mounted" v-bind="shellProps">
|
|
60
|
+
<slot />
|
|
61
|
+
</Slot>
|
|
54
62
|
<component :is="Provider" v-else v-bind="providerProps">
|
|
55
63
|
<TooltipRoot>
|
|
56
64
|
<TooltipTrigger as-child data-slot="trigger">
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { getCurrentInstance, ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Defers an overlay's popup machinery (reka root, trigger, portal) until its
|
|
5
|
+
* trigger is first hovered or focused.
|
|
6
|
+
*
|
|
7
|
+
* Until then the overlay renders its trigger alone through reka's `Slot`,
|
|
8
|
+
* with the data attributes reka's closed trigger carries, so the DOM is the
|
|
9
|
+
* same and nothing shifts. On the first hover or focus the overlay mounts in
|
|
10
|
+
* full and the event is sent again to the new trigger, so reka opens the
|
|
11
|
+
* popup with its usual delay, as if it had been mounted all along.
|
|
12
|
+
*
|
|
13
|
+
* The shell listens for what the reka trigger of that `kind` opens on, so it
|
|
14
|
+
* mounts in the same cases. Touch screens do not hover: there a tooltip never
|
|
15
|
+
* mounts, and a hover card mounts only when a tap focuses its trigger.
|
|
16
|
+
*
|
|
17
|
+
* Mounting replaces the trigger element, because its ancestors change from
|
|
18
|
+
* `Slot` to reka's root and trigger. Focus and text selection inside the
|
|
19
|
+
* trigger move to the new element.
|
|
20
|
+
*
|
|
21
|
+
* Call it from the overlay's `setup`, and render the full overlay as its root
|
|
22
|
+
* once `mounted` is true.
|
|
23
|
+
*/
|
|
24
|
+
export function useDeferredTrigger(kind: 'tooltip' | 'hoverCard') {
|
|
25
|
+
const instance = getCurrentInstance()!
|
|
26
|
+
const mounted = ref(false)
|
|
27
|
+
// Reka's tooltip ignores focus that comes from a press (a click or a tap),
|
|
28
|
+
// so a pressed tooltip trigger does not mount either. Its hover card opens
|
|
29
|
+
// on any focus.
|
|
30
|
+
let pressed = false
|
|
31
|
+
|
|
32
|
+
function mount(event?: Event) {
|
|
33
|
+
if (mounted.value) return
|
|
34
|
+
mounted.value = true
|
|
35
|
+
|
|
36
|
+
const shell = event?.currentTarget
|
|
37
|
+
if (!event || !(shell instanceof Element)) return
|
|
38
|
+
const focus = captureFocus(shell)
|
|
39
|
+
|
|
40
|
+
// Render now rather than on the next tick, so reka starts its hover-delay
|
|
41
|
+
// timer in the same task as the real event, as it did when it was mounted
|
|
42
|
+
// from the start. Tests that hover and then advance a fake clock rely on it.
|
|
43
|
+
instance.update()
|
|
44
|
+
const trigger = firstElement(instance.subTree.el)
|
|
45
|
+
if (!trigger) return
|
|
46
|
+
const gotFocus = receivesEvent(trigger, 'focus', () =>
|
|
47
|
+
focus?.restore(trigger),
|
|
48
|
+
)
|
|
49
|
+
replay(event, trigger, gotFocus)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function onPointer(event: Event) {
|
|
53
|
+
if ((event as Partial<PointerEvent>).pointerType !== 'touch') mount(event)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function onFocus(event: Event) {
|
|
57
|
+
if (!pressed) mount(event)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function onPointerdown() {
|
|
61
|
+
if (kind !== 'tooltip') return
|
|
62
|
+
pressed = true
|
|
63
|
+
document.addEventListener(
|
|
64
|
+
'pointerup',
|
|
65
|
+
() => setTimeout(() => (pressed = false), 1),
|
|
66
|
+
{ once: true },
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Props for the `Slot` that renders the trigger before mounting. */
|
|
71
|
+
const shellProps = {
|
|
72
|
+
'data-slot': 'trigger',
|
|
73
|
+
'data-state': 'closed',
|
|
74
|
+
'data-grace-area-trigger': '',
|
|
75
|
+
// Reka's tooltip opens on pointermove, its hover card on pointerenter.
|
|
76
|
+
[kind === 'tooltip' ? 'onPointermove' : 'onPointerenter']: onPointer,
|
|
77
|
+
// `focus` covers the trigger itself, `focusin` its descendants.
|
|
78
|
+
onFocus,
|
|
79
|
+
onFocusin: onFocus,
|
|
80
|
+
onPointerdown,
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return { mounted, mount, shellProps }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Sends the event that mounted the overlay to the new trigger, so reka runs
|
|
87
|
+
// its own open logic: hover delay, skip delay, touch filtering.
|
|
88
|
+
function replay(event: Event, trigger: Element, gotFocus: boolean) {
|
|
89
|
+
if (event.type.startsWith('pointer')) {
|
|
90
|
+
// A script can dispatch a plain `Event` named "pointermove", and reka
|
|
91
|
+
// still treats it as a pointer, so read its fields as optional.
|
|
92
|
+
const pointer: Partial<PointerEvent> = event
|
|
93
|
+
trigger.dispatchEvent(
|
|
94
|
+
new PointerEvent(event.type, {
|
|
95
|
+
pointerId: pointer.pointerId,
|
|
96
|
+
pointerType: pointer.pointerType ?? 'mouse',
|
|
97
|
+
isPrimary: pointer.isPrimary,
|
|
98
|
+
clientX: pointer.clientX,
|
|
99
|
+
clientY: pointer.clientY,
|
|
100
|
+
}),
|
|
101
|
+
)
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
// Reka opens on a `focus` event that reaches the trigger. A descendant's
|
|
105
|
+
// focus only arrives as `focusin`, so it is not sent again. Restoring focus
|
|
106
|
+
// already sends `focus`, unless the window does not have focus. Reka must
|
|
107
|
+
// see it exactly once: a hover card starts an open timer for each one.
|
|
108
|
+
if (event.type === 'focus' && !gotFocus) {
|
|
109
|
+
trigger.dispatchEvent(new FocusEvent('focus'))
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The first element a rendered tree starts with. Reka's root renders a
|
|
114
|
+
// fragment, whose node is an empty text anchor placed before the trigger.
|
|
115
|
+
// Vue types a rendered node loosely, as any renderer's node.
|
|
116
|
+
function firstElement(node: unknown): Element | null {
|
|
117
|
+
if (node instanceof Element) return node
|
|
118
|
+
if (node instanceof CharacterData) return node.nextElementSibling
|
|
119
|
+
return null
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Runs `action` and reports whether it dispatched `type` on `target`.
|
|
123
|
+
// Focus events dispatch synchronously inside `focus()`.
|
|
124
|
+
function receivesEvent(target: Element, type: string, action: () => void) {
|
|
125
|
+
let received = false
|
|
126
|
+
const listener = () => (received = true)
|
|
127
|
+
target.addEventListener(type, listener)
|
|
128
|
+
action()
|
|
129
|
+
target.removeEventListener(type, listener)
|
|
130
|
+
return received
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Remembers where focus is inside the trigger by child position, so it can be
|
|
134
|
+
// put back in the same place once the trigger element is replaced.
|
|
135
|
+
function captureFocus(shell: Element) {
|
|
136
|
+
const active = document.activeElement
|
|
137
|
+
if (!active || !shell.contains(active)) return
|
|
138
|
+
|
|
139
|
+
const path: number[] = []
|
|
140
|
+
for (let node = active; node !== shell; node = node.parentElement!) {
|
|
141
|
+
path.unshift(Array.from(node.parentElement!.children).indexOf(node))
|
|
142
|
+
}
|
|
143
|
+
const selection = isTextField(active)
|
|
144
|
+
? ([
|
|
145
|
+
active.selectionStart,
|
|
146
|
+
active.selectionEnd,
|
|
147
|
+
active.selectionDirection ?? undefined,
|
|
148
|
+
] as const)
|
|
149
|
+
: null
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
restore(trigger: Element) {
|
|
153
|
+
let target: Element | undefined = trigger
|
|
154
|
+
for (const index of path) target = target?.children[index]
|
|
155
|
+
if (!(target instanceof HTMLElement)) return
|
|
156
|
+
target.focus({ preventScroll: true })
|
|
157
|
+
if (!selection || !isTextField(target)) return
|
|
158
|
+
try {
|
|
159
|
+
target.setSelectionRange(...selection)
|
|
160
|
+
} catch {
|
|
161
|
+
// Inputs like type="email" do not support selection ranges.
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isTextField(
|
|
168
|
+
element: Element,
|
|
169
|
+
): element is HTMLInputElement | HTMLTextAreaElement {
|
|
170
|
+
return (
|
|
171
|
+
element instanceof HTMLInputElement ||
|
|
172
|
+
element instanceof HTMLTextAreaElement
|
|
173
|
+
)
|
|
174
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { computed, getCurrentInstance } from 'vue'
|
|
2
|
+
import { RouterLink } from 'vue-router'
|
|
3
|
+
import { safeHref } from '../../utils/url-safety'
|
|
4
|
+
import type { RouteDestination } from './route'
|
|
5
|
+
|
|
6
|
+
interface NavLinkProps {
|
|
7
|
+
route?: RouteDestination
|
|
8
|
+
href?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The link half of a nav item: which element to render, the attributes it
|
|
13
|
+
* takes, and the route it points at. Every href passes through `safeHref`
|
|
14
|
+
* here, so a nav item cannot render an unchecked one.
|
|
15
|
+
*/
|
|
16
|
+
export function useNavLink(props: NavLinkProps) {
|
|
17
|
+
// Read the router/route off global properties instead of useRouter()/useRoute()
|
|
18
|
+
// so the item works — without warnings or crashes — when mounted outside a
|
|
19
|
+
// vue-router app (docs, tests, embedded use). vue-router installs $router/$route
|
|
20
|
+
// here; the $route getter stays reactive when read inside a computed.
|
|
21
|
+
const globals = getCurrentInstance()?.appContext.config.globalProperties
|
|
22
|
+
const hasRouter = computed(() => Boolean(globals?.$router))
|
|
23
|
+
|
|
24
|
+
// With a router, render RouterLink; without one, degrade to a plain <a>. It
|
|
25
|
+
// gets an href only when `route` is a string: a route object has no URL
|
|
26
|
+
// without a router to resolve it.
|
|
27
|
+
const linkComponent = computed(() =>
|
|
28
|
+
props.route && hasRouter.value ? RouterLink : 'a',
|
|
29
|
+
)
|
|
30
|
+
const linkAttrs = computed(() =>
|
|
31
|
+
props.route
|
|
32
|
+
? hasRouter.value
|
|
33
|
+
? { to: props.route }
|
|
34
|
+
: { href: safeHref(props.route) }
|
|
35
|
+
: { href: safeHref(props.href) },
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
const resolvedRoute = computed(() =>
|
|
39
|
+
props.route && globals?.$router
|
|
40
|
+
? globals.$router.resolve(props.route)
|
|
41
|
+
: null,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
return { globals, linkComponent, linkAttrs, resolvedRoute }
|
|
45
|
+
}
|