dou-ui 0.1.0-alpha.25 → 0.1.0-alpha.26
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/dist/components/dock/context.js.map +1 -1
- package/dist/components/dock/dock-group.js.map +1 -1
- package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js +15 -4
- package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dock/dock.js.map +1 -1
- package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js +72 -21
- package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dock/index.js +2 -2
- package/dist/components/dock/index.js.map +1 -1
- package/dist/components/dock/layout.js +12 -1
- package/dist/components/dock/layout.js.map +1 -1
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js +29 -5
- package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/tab-button.js.map +1 -1
- package/dist/components/tabs/tab-button.vue_vue_type_script_setup_true_lang.js +27 -5
- package/dist/components/tabs/tab-button.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/tab-drag.js +12 -4
- package/dist/components/tabs/tab-drag.js.map +1 -1
- package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js +70 -10
- package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/tabs2.js.map +1 -1
- package/dist/components/tabs/truncated-title.js +28 -0
- package/dist/components/tabs/truncated-title.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/style.css +1 -1
- package/dist/types/components/dock/context.d.ts +2 -0
- package/dist/types/components/dock/dock.d.ts +40 -0
- package/dist/types/components/dock/index.d.ts +1 -1
- package/dist/types/components/dock/layout.d.ts +6 -0
- package/dist/types/components/popover/popover.d.ts +1 -1
- package/dist/types/components/tabs/tab-button.vue.d.ts +1 -0
- package/dist/types/components/tabs/tab-drag.d.ts +10 -0
- package/dist/types/components/tabs/truncated-title.d.ts +7 -0
- package/package.json +3 -3
|
@@ -103,11 +103,35 @@ var popover_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
103
103
|
"dou-floating",
|
|
104
104
|
ns.is("titled", hasTitle.value)
|
|
105
105
|
]);
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
const CSS_LENGTH_PERCENTAGE = /^\+?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?(?:%|px|cm|mm|q|in|pc|pt|r?(?:em|ex|cap|ch|ic|lh)|[sld]?v(?:w|h|i|b|min|max)|cq(?:w|h|i|b|min|max))$/i;
|
|
107
|
+
const CSS_MIN_FUNCTION = /^(?:calc|min|max|clamp|round|abs|mod|rem|var|env)\(/i;
|
|
108
|
+
function isMinCompatibleSize(value) {
|
|
109
|
+
if (CSS_LENGTH_PERCENTAGE.test(value)) return true;
|
|
110
|
+
if (!CSS_MIN_FUNCTION.test(value) || !value.endsWith(")")) return false;
|
|
111
|
+
const openIndex = value.indexOf("(");
|
|
112
|
+
if (!value.slice(openIndex + 1, -1).trim()) return false;
|
|
113
|
+
let depth = 0;
|
|
114
|
+
for (let i = openIndex; i < value.length; i++) if (value[i] === "(") depth++;
|
|
115
|
+
else if (value[i] === ")") {
|
|
116
|
+
depth--;
|
|
117
|
+
if (depth === 0) return i === value.length - 1;
|
|
118
|
+
if (depth < 0) return false;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const cssSize = (value) => {
|
|
123
|
+
if (typeof value === "number") return Number.isFinite(value) && value >= 0 ? `${value}px` : void 0;
|
|
124
|
+
return value?.trim() || void 0;
|
|
125
|
+
};
|
|
126
|
+
const panelSizeStyle = computed(() => {
|
|
127
|
+
const width = cssSize(props.width);
|
|
128
|
+
const maxHeight = cssSize(props.maxHeight);
|
|
129
|
+
return {
|
|
130
|
+
width,
|
|
131
|
+
...width !== void 0 && isMinCompatibleSize(width) && { "--dou-popover-max-width": width },
|
|
132
|
+
...maxHeight !== void 0 && isMinCompatibleSize(maxHeight) && { "--dou-popover-max-height": maxHeight }
|
|
133
|
+
};
|
|
134
|
+
});
|
|
111
135
|
__expose({
|
|
112
136
|
open: () => popup.show(),
|
|
113
137
|
close: () => popup.dismiss()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.vue_vue_type_script_setup_true_lang.js","names":["$attrs","_useModel","_openBlock","_createElementBlock","_Fragment","_createVNode","_unref","_mergeProps","_withCtx","_renderSlot","_createBlock","_Teleport","_Transition","_withDirectives","_createElementVNode","_normalizeClass","_createTextVNode","_toDisplayString","_createCommentVNode","_vShow"],"sources":["../../../src/components/popover/popover.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, mergeProps, useId, useSlots } from 'vue'\nimport type { CSSProperties } from 'vue'\nimport { getTabbable } from '../../composables/use-focus-trap'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport type { PopoverExpose, PopoverProps, PopoverSlots } from './popover'\nimport { useTeleport } from '../../utils/teleport'\n\ndefineOptions({ name: 'DouPopover', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<PopoverProps>(), {\n placement: 'bottom',\n trigger: 'click',\n disabled: false,\n showDelay: 100,\n hideDelay: 150,\n offset: 8,\n openOnTap: true,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\ndefineSlots<PopoverSlots>()\nconst slots = useSlots()\n\nconst ns = useNamespace('popover')\nconst id = `dou-popover-${useId()}`\nconst titleId = `${id}-title`\nconst hasTitle = computed(() => !!props.title || !!slots.title)\n\nconst popup = usePopup({\n open,\n trigger: () => props.trigger,\n disabled: () => props.disabled,\n placement: () => props.placement,\n offset: () => props.offset,\n showDelay: () => props.showDelay,\n hideDelay: () => props.hideDelay,\n tap: () => props.openOnTap,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle, panelListeners } = popup\n\n// The panel lives at the end of <body>, away from the trigger in tab\n// order. `Tab` from the trigger steps into the panel, and stepping out of\n// either end of the panel lands back on the trigger, from where the\n// browser carries on as usual. Leaving the trigger any other way (`Tab`\n// with nothing to focus in the panel, or `Shift+Tab`) closes the panel, so\n// it doesn't stay open away from the focus.\nfunction onTriggerKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !open.value || !panelRef.value) return\n const first = event.shiftKey ? undefined : getTabbable(panelRef.value)[0]\n if (!first) return popup.hide()\n event.preventDefault()\n first.focus()\n}\n\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !panelRef.value) return\n const tabbable = getTabbable(panelRef.value)\n const trigger = popup.reference() as HTMLElement | null\n if (event.shiftKey && document.activeElement === tabbable[0]) {\n event.preventDefault()\n trigger?.focus()\n } else if (!event.shiftKey && document.activeElement === tabbable.at(-1)) {\n trigger?.focus()\n popup.hide()\n }\n}\n\n// Hover has no keyboard of its own: Enter or Space on the trigger (a click\n// with `detail` 0) opens and closes a hover card too, so a screen reader\n// can reach it. A link trigger keeps Enter for following the link.\nfunction onTriggerClick(event: MouseEvent) {\n if (props.trigger !== 'hover' || event.detail !== 0 || props.disabled) return\n if ((event.currentTarget as Element | null)?.matches('a[href]')) return\n if (open.value) return popup.hide()\n popup.tapped.value = true\n popup.show()\n}\n\nconst triggerProps = computed(() =>\n mergeProps(popup.triggerListeners.value, {\n onKeydown: onTriggerKeydown,\n onClick: onTriggerClick,\n 'aria-haspopup': 'dialog' as const,\n // a hover card a tap or the keyboard opened stays, like a dialog\n 'aria-expanded': props.trigger === 'hover' && !popup.tapped.value ? undefined : open.value,\n 'aria-controls': rendered.value ? id : undefined,\n }),\n)\n\nconst panelClasses = computed(() => [ns.b(), 'dou-floating', ns.is('titled', hasTitle.value)])\nconst cssSize = (value: string | number | undefined) =>\n typeof value === 'number' ? `${value}px` : (value ?? undefined)\nconst panelSizeStyle = computed<CSSProperties>(() => ({\n width: cssSize(props.width),\n ...(props.maxHeight !== undefined && {\n '--dou-popover-max-height': cssSize(props.maxHeight),\n }),\n}))\n\ndefineExpose<PopoverExpose>({ open: () => popup.show(), close: () => popup.dismiss() })\n</script>\n\n<template>\n <OnlyChild ref=\"triggerRef\" v-bind=\"triggerProps\"><slot /></OnlyChild>\n <Teleport v-if=\"rendered\" :to=\"teleportTarget.to\" :disabled=\"teleportTarget.disabled\">\n <Transition appear name=\"dou-floating\">\n <div\n v-show=\"open\"\n :id=\"id\"\n ref=\"panelRef\"\n role=\"dialog\"\n :aria-labelledby=\"hasTitle ? titleId : undefined\"\n :class=\"panelClasses\"\n :style=\"[panelStyle, panelSizeStyle]\"\n :data-placement=\"placement\"\n :data-dou-theme=\"theme\"\n v-bind=\"{ ...$attrs, ...panelListeners }\"\n @keydown=\"onPanelKeydown\"\n >\n <div v-if=\"hasTitle\" :id=\"titleId\" :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </div>\n <div :class=\"ns.e('content')\">\n <slot name=\"content\" :close=\"popup.dismiss\">{{ content }}</slot>\n </div>\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYA,MAAM,QAAQ;EAUd,MAAM,iBAAiB,kBAAkB,MAAM,QAAQ;EACvD,MAAM,OAAOC,SAAoB,SAAC,MAA0B;EAE5D,MAAM,QAAQ,SAAS;EAEvB,MAAM,KAAK,aAAa,SAAS;EACjC,MAAM,KAAK,eAAe,MAAM;EAChC,MAAM,UAAU,GAAG,GAAG;EACtB,MAAM,WAAW,eAAe,CAAC,CAAC,MAAM,SAAS,CAAC,CAAC,MAAM,KAAK;EAE9D,MAAM,QAAQ,SAAS;GACrB;GACA,eAAe,MAAM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AAC,EAAC,OAAA,CAAA;I,IAC7CG,WAAqC,KAAA,QAAA,SAAA,CAAA,SAAA,CAAfO,gBAAAC,gBAAA,QAAA,KAAK,GAAA,CAAA,C,yCAE7BH,mBAEM,OAAA,EAFA,OAAKC,eAAET,MAAA,EAAA,CAAE,CAAC,EAAC,SAAA,CAAA,E,IACfG,WAAgE,KAAA,QAAA,WAAA,EAA1C,OAAOH,MAAA,KAAA,CAAK,CAAC,QAAnC,SAAgE,CAAjBU,gBAAAC,gBAAA,QAAA,OAAO,GAAA,CAAA,C,4BAhBhD,CAAAE,OAAA,KAAA,KAAI,C"}
|
|
1
|
+
{"version":3,"file":"popover.vue_vue_type_script_setup_true_lang.js","names":["$attrs","_useModel","_openBlock","_createElementBlock","_Fragment","_createVNode","_unref","_mergeProps","_withCtx","_renderSlot","_createBlock","_Teleport","_Transition","_withDirectives","_createElementVNode","_normalizeClass","_createTextVNode","_toDisplayString","_createCommentVNode","_vShow"],"sources":["../../../src/components/popover/popover.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, mergeProps, useId, useSlots } from 'vue'\nimport type { CSSProperties } from 'vue'\nimport { getTabbable } from '../../composables/use-focus-trap'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport type { PopoverExpose, PopoverProps, PopoverSlots } from './popover'\nimport { useTeleport } from '../../utils/teleport'\n\ndefineOptions({ name: 'DouPopover', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<PopoverProps>(), {\n placement: 'bottom',\n trigger: 'click',\n disabled: false,\n showDelay: 100,\n hideDelay: 150,\n offset: 8,\n openOnTap: true,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\ndefineSlots<PopoverSlots>()\nconst slots = useSlots()\n\nconst ns = useNamespace('popover')\nconst id = `dou-popover-${useId()}`\nconst titleId = `${id}-title`\nconst hasTitle = computed(() => !!props.title || !!slots.title)\n\nconst popup = usePopup({\n open,\n trigger: () => props.trigger,\n disabled: () => props.disabled,\n placement: () => props.placement,\n offset: () => props.offset,\n showDelay: () => props.showDelay,\n hideDelay: () => props.hideDelay,\n tap: () => props.openOnTap,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle, panelListeners } = popup\n\n// The panel lives at the end of <body>, away from the trigger in tab\n// order. `Tab` from the trigger steps into the panel, and stepping out of\n// either end of the panel lands back on the trigger, from where the\n// browser carries on as usual. Leaving the trigger any other way (`Tab`\n// with nothing to focus in the panel, or `Shift+Tab`) closes the panel, so\n// it doesn't stay open away from the focus.\nfunction onTriggerKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !open.value || !panelRef.value) return\n const first = event.shiftKey ? undefined : getTabbable(panelRef.value)[0]\n if (!first) return popup.hide()\n event.preventDefault()\n first.focus()\n}\n\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !panelRef.value) return\n const tabbable = getTabbable(panelRef.value)\n const trigger = popup.reference() as HTMLElement | null\n if (event.shiftKey && document.activeElement === tabbable[0]) {\n event.preventDefault()\n trigger?.focus()\n } else if (!event.shiftKey && document.activeElement === tabbable.at(-1)) {\n trigger?.focus()\n popup.hide()\n }\n}\n\n// Hover has no keyboard of its own: Enter or Space on the trigger (a click\n// with `detail` 0) opens and closes a hover card too, so a screen reader\n// can reach it. A link trigger keeps Enter for following the link.\nfunction onTriggerClick(event: MouseEvent) {\n if (props.trigger !== 'hover' || event.detail !== 0 || props.disabled) return\n if ((event.currentTarget as Element | null)?.matches('a[href]')) return\n if (open.value) return popup.hide()\n popup.tapped.value = true\n popup.show()\n}\n\nconst triggerProps = computed(() =>\n mergeProps(popup.triggerListeners.value, {\n onKeydown: onTriggerKeydown,\n onClick: onTriggerClick,\n 'aria-haspopup': 'dialog' as const,\n // a hover card a tap or the keyboard opened stays, like a dialog\n 'aria-expanded': props.trigger === 'hover' && !popup.tapped.value ? undefined : open.value,\n 'aria-controls': rendered.value ? id : undefined,\n }),\n)\n\nconst panelClasses = computed(() => [ns.b(), 'dou-floating', ns.is('titled', hasTitle.value)])\n// CSS `min()` only accepts <length-percentage>, length math functions and\n// var()/env(). Writing unitless strings, intrinsic keywords or malformed values\n// into `--dou-popover-max-*` would make `max-width` / `max-height` invalid at\n// computed-value time (IACVT) and drop the viewport clamp.\nconst CSS_LENGTH_PERCENTAGE =\n /^\\+?(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:e[+-]?\\d+)?(?:%|px|cm|mm|q|in|pc|pt|r?(?:em|ex|cap|ch|ic|lh)|[sld]?v(?:w|h|i|b|min|max)|cq(?:w|h|i|b|min|max))$/i\nconst CSS_MIN_FUNCTION = /^(?:calc|min|max|clamp|round|abs|mod|rem|var|env)\\(/i\nfunction isMinCompatibleSize(value: string): boolean {\n if (CSS_LENGTH_PERCENTAGE.test(value)) return true\n if (!CSS_MIN_FUNCTION.test(value) || !value.endsWith(')')) return false\n const openIndex = value.indexOf('(')\n if (!value.slice(openIndex + 1, -1).trim()) return false\n let depth = 0\n for (let i = openIndex; i < value.length; i++) {\n if (value[i] === '(') depth++\n else if (value[i] === ')') {\n depth--\n if (depth === 0) return i === value.length - 1\n if (depth < 0) return false\n }\n }\n return false\n}\nconst cssSize = (value: string | number | undefined) => {\n if (typeof value === 'number')\n return Number.isFinite(value) && value >= 0 ? `${value}px` : undefined\n const trimmed = value?.trim()\n return trimmed || undefined\n}\nconst panelSizeStyle = computed<CSSProperties>(() => {\n const width = cssSize(props.width)\n const maxHeight = cssSize(props.maxHeight)\n return {\n width,\n ...(width !== undefined &&\n isMinCompatibleSize(width) && {\n '--dou-popover-max-width': width,\n }),\n ...(maxHeight !== undefined &&\n isMinCompatibleSize(maxHeight) && {\n '--dou-popover-max-height': maxHeight,\n }),\n }\n})\n\ndefineExpose<PopoverExpose>({ open: () => popup.show(), close: () => popup.dismiss() })\n</script>\n\n<template>\n <OnlyChild ref=\"triggerRef\" v-bind=\"triggerProps\"><slot /></OnlyChild>\n <Teleport v-if=\"rendered\" :to=\"teleportTarget.to\" :disabled=\"teleportTarget.disabled\">\n <Transition appear name=\"dou-floating\">\n <div\n v-show=\"open\"\n :id=\"id\"\n ref=\"panelRef\"\n role=\"dialog\"\n :aria-labelledby=\"hasTitle ? titleId : undefined\"\n :class=\"panelClasses\"\n :style=\"[panelStyle, panelSizeStyle]\"\n :data-placement=\"placement\"\n :data-dou-theme=\"theme\"\n v-bind=\"{ ...$attrs, ...panelListeners }\"\n @keydown=\"onPanelKeydown\"\n >\n <div v-if=\"hasTitle\" :id=\"titleId\" :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </div>\n <div :class=\"ns.e('content')\">\n <slot name=\"content\" :close=\"popup.dismiss\">{{ content }}</slot>\n </div>\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYA,MAAM,QAAQ;EAUd,MAAM,iBAAiB,kBAAkB,MAAM,QAAQ;EACvD,MAAM,OAAOC,SAAoB,SAAC,MAA0B;EAE5D,MAAM,QAAQ,SAAS;EAEvB,MAAM,KAAK,aAAa,SAAS;EACjC,MAAM,KAAK,eAAe,MAAM;EAChC,MAAM,UAAU,GAAG,GAAG;EACtB,MAAM,WAAW,eAAe,CAAC,CAAC,MAAM,SAAS,CAAC,CAAC,MAAM,KAAK;EAE9D,MAAM,QAAQ,SAAS;GACrB;GACA,eAAe,MAAM;GACrB,gBAAgB,MAAM;GACtB,iBAAiB,MAAM;GACvB,cAAc,MAAM;GACpB,iBAAiB,MAAM;GACvB,iBAAiB,MAAM;GACvB,WAAW,MAAM;EACnB,CAAC;EACD,MAAM,EAAE,YAAY,UAAU,UAAU,OAAO,WAAW,YAAY,mBAAmB;EAQzF,SAAS,iBAAiB,OAAsB;GAC9C,IAAI,MAAM,QAAQ,SAAS,CAAC,KAAK,SAAS,CAAC,SAAS,OAAO;GAC3D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AA;;IACE,SAAAJ,cAmBM,CAnBNK,eAAAC,mBAmBM,OAnBNP,WAmBM;KAjBC;KACD,SAAA;KAAJ,KAAI;KACJ,MAAK;KACJ,mBAAiB,SAAA,QAAW,UAAU,KAAA;KACtC,OAAO,aAAA;KACP,OAAK,CAAGD,MAAA,UAAA,GAAY,eAAA,KAAc;KAClC,kBAAgBA,MAAA,SAAA;KAChB,kBAAgBA,MAAA,KAAA;IACJN,GAAAA;KAAAA,GAAAA,KAAAA;KAAM,GAAKM,MAAA,cAAA;IAAc,GAAA,EACrC,WAAS,eAAc,CAAA,GAAA,CAEb,SAAA,SAAXJ,UAAA,GAAAC,mBAEM,OAAA;;KAFgB,IAAI;KAAU,OAAKY,eAAET,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,CAAA;I,IAC7CG,WAAqC,KAAA,QAAA,SAAA,CAAA,SAAA,CAAfO,gBAAAC,gBAAA,QAAA,KAAK,GAAA,CAAA,C,yCAE7BH,mBAEM,OAAA,EAFA,OAAKC,eAAET,MAAA,EAAA,CAAE,CAAC,EAAC,SAAA,CAAA,E,IACfG,WAAgE,KAAA,QAAA,WAAA,EAA1C,OAAOH,MAAA,KAAA,CAAK,CAAC,QAAnC,SAAgE,CAAjBU,gBAAAC,gBAAA,QAAA,OAAO,GAAA,CAAA,C,4BAhBhD,CAAAE,OAAA,KAAA,KAAI,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tab-button.js","names":["_sfc_main"],"sources":["../../../src/components/tabs/tab-button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { h } from 'vue'\nimport { CloseIcon } from '@dou-ui/icons'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouTooltip } from '../tooltip'\nimport type { FunctionalComponent, VNode } from 'vue'\nimport type { TabPanelEntry } from './tabs'\n\ndefineOptions({ name: 'DouTabButton' })\n\nconst props = defineProps<{\n entry: TabPanelEntry\n tabId: string\n panelId: string\n labelText: string\n selected: boolean\n closable: boolean\n iconAlone: boolean\n draggable: boolean\n dragging: boolean\n tipPlacement: 'top' | 'right' | 'left'\n keyShortcuts?: string\n setEl: (el: unknown) => void\n}>()\n\nconst emit = defineEmits<{\n click: []\n pointerdown: [event: PointerEvent]\n keydown: [event: KeyboardEvent]\n remove: []\n}>()\n\nconst ns = useNamespace('tabs')\nconst { t } = useLocale()\nconst onButtonRef = (el: unknown) => props.setEl(el)\n\n/** The label slot of a panel, rendered inside its tab. */\nconst TabLabel: FunctionalComponent = () =>\n (props.entry.slots.label?.({ selected: props.selected }) as VNode[] | undefined) ??\n props.labelText\n\nconst TabTip: FunctionalComponent = (_, { slots: tip }) =>\n props.iconAlone\n ? h(DouTooltip, { content: props.labelText, placement: props.tipPlacement }, tip)\n : tip.default?.()\n</script>\n\n<template>\n <TabTip>\n <button\n :id=\"tabId\"\n :ref=\"onButtonRef\"\n type=\"button\"\n role=\"tab\"\n :class=\"[\n ns.e('tab'),\n ns.is('selected', selected),\n ns.is('disabled', !!entry.props.disabled),\n ns.is('closable', closable),\n ns.is('icon-alone', iconAlone),\n ns.is('pinned', !!entry.props.pinned),\n ns.is('draggable', draggable),\n ns.is('dragging', dragging),\n ]\"\n :aria-selected=\"selected\"\n :aria-controls=\"panelId\"\n :aria-label=\"iconAlone ? labelText : undefined\"\n :aria-disabled=\"entry.props.disabled || undefined\"\n :tabindex=\"selected ? 0 : -1\"\n :aria-keyshortcuts=\"keyShortcuts\"\n @click=\"emit('click')\"\n @pointerdown=\"emit('pointerdown', $event)\"\n @keydown=\"emit('keydown', $event)\"\n >\n <component\n :is=\"entry.props.icon\"\n v-if=\"entry.props.icon\"\n :class=\"ns.e('icon')\"\n aria-hidden=\"true\"\n />\n <span v-if=\"!iconAlone\" :class=\"ns.e('label')\">\n <TabLabel />\n </span>\n <!-- not a button of its own: a tab cannot hold one; `Delete` closes it from the keyboard.\n An icon alone already has the label's tooltip, so the close button goes without. -->\n <DouTooltip\n v-if=\"closable\"\n :content=\"t('tabs.close')\"\n shortcut=\"delete\"\n :disabled=\"iconAlone\"\n >\n <span
|
|
1
|
+
{"version":3,"file":"tab-button.js","names":["_sfc_main"],"sources":["../../../src/components/tabs/tab-button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { h, ref, useTemplateRef, watch } from 'vue'\nimport { CloseIcon } from '@dou-ui/icons'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouTooltip } from '../tooltip'\nimport { resolveTruncatedTitle } from './truncated-title'\nimport type { FunctionalComponent, VNode } from 'vue'\nimport type { TabPanelEntry } from './tabs'\n\ndefineOptions({ name: 'DouTabButton' })\n\nconst props = defineProps<{\n entry: TabPanelEntry\n tabId: string\n panelId: string\n labelText: string\n selected: boolean\n closable: boolean\n iconAlone: boolean\n draggable: boolean\n dragging: boolean\n mergeTarget?: boolean\n tipPlacement: 'top' | 'right' | 'left'\n keyShortcuts?: string\n setEl: (el: unknown) => void\n}>()\n\nconst emit = defineEmits<{\n click: []\n pointerdown: [event: PointerEvent]\n keydown: [event: KeyboardEvent]\n remove: []\n}>()\n\nconst ns = useNamespace('tabs')\nconst { t } = useLocale()\nconst onButtonRef = (el: unknown) => props.setEl(el)\n\n// A label cut short by an ellipsis shows the full text as a native title on\n// hover. Measured lazily on pointerenter so idle tabs pay nothing, and skipped\n// for icon-alone tabs which already have a DouTooltip.\nconst labelRef = useTemplateRef<HTMLElement>('label')\nconst tabTitle = ref<string>()\nfunction updateTitle() {\n if (props.iconAlone) {\n tabTitle.value = undefined\n return\n }\n tabTitle.value = resolveTruncatedTitle(labelRef.value, props.entry.props.label)\n}\nwatch([() => props.labelText, () => props.iconAlone], () => {\n tabTitle.value = undefined\n})\n\n/** The label slot of a panel, rendered inside its tab. */\nconst TabLabel: FunctionalComponent = () =>\n (props.entry.slots.label?.({ selected: props.selected }) as VNode[] | undefined) ??\n props.labelText\n\nconst TabTip: FunctionalComponent = (_, { slots: tip }) =>\n props.iconAlone\n ? h(DouTooltip, { content: props.labelText, placement: props.tipPlacement }, tip)\n : tip.default?.()\n</script>\n\n<template>\n <TabTip>\n <button\n :id=\"tabId\"\n :ref=\"onButtonRef\"\n type=\"button\"\n role=\"tab\"\n :class=\"[\n ns.e('tab'),\n ns.is('selected', selected),\n ns.is('disabled', !!entry.props.disabled),\n ns.is('closable', closable),\n ns.is('icon-alone', iconAlone),\n ns.is('pinned', !!entry.props.pinned),\n ns.is('draggable', draggable),\n ns.is('dragging', dragging),\n ns.is('merge-target', !!mergeTarget),\n ]\"\n :title=\"tabTitle\"\n :aria-selected=\"selected\"\n :aria-controls=\"panelId\"\n :aria-label=\"iconAlone ? labelText : undefined\"\n :aria-disabled=\"entry.props.disabled || undefined\"\n :tabindex=\"selected ? 0 : -1\"\n :aria-keyshortcuts=\"keyShortcuts\"\n @click=\"emit('click')\"\n @pointerenter=\"updateTitle\"\n @pointerdown=\"emit('pointerdown', $event)\"\n @keydown=\"emit('keydown', $event)\"\n >\n <component\n :is=\"entry.props.icon\"\n v-if=\"entry.props.icon\"\n :class=\"ns.e('icon')\"\n aria-hidden=\"true\"\n />\n <span v-if=\"!iconAlone\" ref=\"label\" :class=\"ns.e('label')\" @pointerenter=\"updateTitle\">\n <TabLabel />\n </span>\n <!-- not a button of its own: a tab cannot hold one; `Delete` closes it from the keyboard.\n An icon alone already has the label's tooltip, so the close button goes without. -->\n <DouTooltip\n v-if=\"closable\"\n :content=\"t('tabs.close')\"\n shortcut=\"delete\"\n :disabled=\"iconAlone\"\n >\n <span\n :class=\"ns.e('close')\"\n :title=\"tabTitle ? '' : undefined\"\n aria-hidden=\"true\"\n @click.stop=\"emit('remove')\"\n >\n <CloseIcon />\n </span>\n </DouTooltip>\n </button>\n </TabTip>\n</template>\n"],"mappings":""}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { useNamespace } from "../../utils/namespace.js";
|
|
2
2
|
import { useLocale } from "../config-provider/use-config.js";
|
|
3
3
|
import { DouTooltip } from "../tooltip/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { resolveTruncatedTitle } from "./truncated-title.js";
|
|
5
|
+
import { createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, h, normalizeClass, openBlock, ref, resolveDynamicComponent, unref, useTemplateRef, watch, withCtx, withModifiers } from "vue";
|
|
5
6
|
import { CloseIcon } from "@dou-ui/icons";
|
|
6
7
|
// src/components/tabs/tab-button.vue?vue&type=script&setup=true&lang.ts
|
|
7
8
|
var _hoisted_1 = [
|
|
8
9
|
"id",
|
|
10
|
+
"title",
|
|
9
11
|
"aria-selected",
|
|
10
12
|
"aria-controls",
|
|
11
13
|
"aria-label",
|
|
@@ -13,6 +15,7 @@ var _hoisted_1 = [
|
|
|
13
15
|
"tabindex",
|
|
14
16
|
"aria-keyshortcuts"
|
|
15
17
|
];
|
|
18
|
+
var _hoisted_2 = ["title"];
|
|
16
19
|
var tab_button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
17
20
|
name: "DouTabButton",
|
|
18
21
|
__name: "tab-button",
|
|
@@ -26,6 +29,7 @@ var tab_button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
26
29
|
iconAlone: { type: Boolean },
|
|
27
30
|
draggable: { type: Boolean },
|
|
28
31
|
dragging: { type: Boolean },
|
|
32
|
+
mergeTarget: { type: Boolean },
|
|
29
33
|
tipPlacement: {},
|
|
30
34
|
keyShortcuts: {},
|
|
31
35
|
setEl: { type: Function }
|
|
@@ -42,6 +46,18 @@ var tab_button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
42
46
|
const ns = useNamespace("tabs");
|
|
43
47
|
const { t } = useLocale();
|
|
44
48
|
const onButtonRef = (el) => props.setEl(el);
|
|
49
|
+
const labelRef = useTemplateRef("label");
|
|
50
|
+
const tabTitle = ref();
|
|
51
|
+
function updateTitle() {
|
|
52
|
+
if (props.iconAlone) {
|
|
53
|
+
tabTitle.value = void 0;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
tabTitle.value = resolveTruncatedTitle(labelRef.value, props.entry.props.label);
|
|
57
|
+
}
|
|
58
|
+
watch([() => props.labelText, () => props.iconAlone], () => {
|
|
59
|
+
tabTitle.value = void 0;
|
|
60
|
+
});
|
|
45
61
|
/** The label slot of a panel, rendered inside its tab. */
|
|
46
62
|
const TabLabel = () => props.entry.slots.label?.({ selected: props.selected }) ?? props.labelText;
|
|
47
63
|
const TabTip = (_, { slots: tip }) => props.iconAlone ? h(DouTooltip, {
|
|
@@ -63,8 +79,10 @@ var tab_button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
63
79
|
unref(ns).is("icon-alone", __props.iconAlone),
|
|
64
80
|
unref(ns).is("pinned", !!__props.entry.props.pinned),
|
|
65
81
|
unref(ns).is("draggable", __props.draggable),
|
|
66
|
-
unref(ns).is("dragging", __props.dragging)
|
|
82
|
+
unref(ns).is("dragging", __props.dragging),
|
|
83
|
+
unref(ns).is("merge-target", !!__props.mergeTarget)
|
|
67
84
|
]),
|
|
85
|
+
title: tabTitle.value,
|
|
68
86
|
"aria-selected": __props.selected,
|
|
69
87
|
"aria-controls": __props.panelId,
|
|
70
88
|
"aria-label": __props.iconAlone ? __props.labelText : void 0,
|
|
@@ -72,6 +90,7 @@ var tab_button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
72
90
|
tabindex: __props.selected ? 0 : -1,
|
|
73
91
|
"aria-keyshortcuts": __props.keyShortcuts,
|
|
74
92
|
onClick: _cache[1] || (_cache[1] = ($event) => emit("click")),
|
|
93
|
+
onPointerenter: updateTitle,
|
|
75
94
|
onPointerdown: _cache[2] || (_cache[2] = ($event) => emit("pointerdown", $event)),
|
|
76
95
|
onKeydown: _cache[3] || (_cache[3] = ($event) => emit("keydown", $event))
|
|
77
96
|
}, [
|
|
@@ -82,8 +101,10 @@ var tab_button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
82
101
|
}, null, 8, ["class"])) : createCommentVNode("", true),
|
|
83
102
|
!__props.iconAlone ? (openBlock(), createElementBlock("span", {
|
|
84
103
|
key: 1,
|
|
85
|
-
|
|
86
|
-
|
|
104
|
+
ref: "label",
|
|
105
|
+
class: normalizeClass(unref(ns).e("label")),
|
|
106
|
+
onPointerenter: updateTitle
|
|
107
|
+
}, [createVNode(TabLabel)], 34)) : createCommentVNode("", true),
|
|
87
108
|
__props.closable ? (openBlock(), createBlock(unref(DouTooltip), {
|
|
88
109
|
key: 2,
|
|
89
110
|
content: unref(t)("tabs.close"),
|
|
@@ -92,9 +113,10 @@ var tab_button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
92
113
|
}, {
|
|
93
114
|
default: withCtx(() => [createElementVNode("span", {
|
|
94
115
|
class: normalizeClass(unref(ns).e("close")),
|
|
116
|
+
title: tabTitle.value ? "" : void 0,
|
|
95
117
|
"aria-hidden": "true",
|
|
96
118
|
onClick: _cache[0] || (_cache[0] = withModifiers(($event) => emit("remove"), ["stop"]))
|
|
97
|
-
}, [createVNode(unref(CloseIcon))],
|
|
119
|
+
}, [createVNode(unref(CloseIcon))], 10, _hoisted_2)]),
|
|
98
120
|
_: 1
|
|
99
121
|
}, 8, ["content", "disabled"])) : createCommentVNode("", true)
|
|
100
122
|
], 42, _hoisted_1)]),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tab-button.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_withCtx","_createElementVNode","_normalizeClass","_unref","_resolveDynamicComponent","_createCommentVNode","_createElementBlock","_createVNode","_withModifiers"],"sources":["../../../src/components/tabs/tab-button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { h } from 'vue'\nimport { CloseIcon } from '@dou-ui/icons'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouTooltip } from '../tooltip'\nimport type { FunctionalComponent, VNode } from 'vue'\nimport type { TabPanelEntry } from './tabs'\n\ndefineOptions({ name: 'DouTabButton' })\n\nconst props = defineProps<{\n entry: TabPanelEntry\n tabId: string\n panelId: string\n labelText: string\n selected: boolean\n closable: boolean\n iconAlone: boolean\n draggable: boolean\n dragging: boolean\n tipPlacement: 'top' | 'right' | 'left'\n keyShortcuts?: string\n setEl: (el: unknown) => void\n}>()\n\nconst emit = defineEmits<{\n click: []\n pointerdown: [event: PointerEvent]\n keydown: [event: KeyboardEvent]\n remove: []\n}>()\n\nconst ns = useNamespace('tabs')\nconst { t } = useLocale()\nconst onButtonRef = (el: unknown) => props.setEl(el)\n\n/** The label slot of a panel, rendered inside its tab. */\nconst TabLabel: FunctionalComponent = () =>\n (props.entry.slots.label?.({ selected: props.selected }) as VNode[] | undefined) ??\n props.labelText\n\nconst TabTip: FunctionalComponent = (_, { slots: tip }) =>\n props.iconAlone\n ? h(DouTooltip, { content: props.labelText, placement: props.tipPlacement }, tip)\n : tip.default?.()\n</script>\n\n<template>\n <TabTip>\n <button\n :id=\"tabId\"\n :ref=\"onButtonRef\"\n type=\"button\"\n role=\"tab\"\n :class=\"[\n ns.e('tab'),\n ns.is('selected', selected),\n ns.is('disabled', !!entry.props.disabled),\n ns.is('closable', closable),\n ns.is('icon-alone', iconAlone),\n ns.is('pinned', !!entry.props.pinned),\n ns.is('draggable', draggable),\n ns.is('dragging', dragging),\n ]\"\n :aria-selected=\"selected\"\n :aria-controls=\"panelId\"\n :aria-label=\"iconAlone ? labelText : undefined\"\n :aria-disabled=\"entry.props.disabled || undefined\"\n :tabindex=\"selected ? 0 : -1\"\n :aria-keyshortcuts=\"keyShortcuts\"\n @click=\"emit('click')\"\n @pointerdown=\"emit('pointerdown', $event)\"\n @keydown=\"emit('keydown', $event)\"\n >\n <component\n :is=\"entry.props.icon\"\n v-if=\"entry.props.icon\"\n :class=\"ns.e('icon')\"\n aria-hidden=\"true\"\n />\n <span v-if=\"!iconAlone\" :class=\"ns.e('label')\">\n <TabLabel />\n </span>\n <!-- not a button of its own: a tab cannot hold one; `Delete` closes it from the keyboard.\n An icon alone already has the label's tooltip, so the close button goes without. -->\n <DouTooltip\n v-if=\"closable\"\n :content=\"t('tabs.close')\"\n shortcut=\"delete\"\n :disabled=\"iconAlone\"\n >\n <span
|
|
1
|
+
{"version":3,"file":"tab-button.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_withCtx","_createElementVNode","_normalizeClass","_unref","_resolveDynamicComponent","_createCommentVNode","_createElementBlock","_createVNode","_withModifiers"],"sources":["../../../src/components/tabs/tab-button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { h, ref, useTemplateRef, watch } from 'vue'\nimport { CloseIcon } from '@dou-ui/icons'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouTooltip } from '../tooltip'\nimport { resolveTruncatedTitle } from './truncated-title'\nimport type { FunctionalComponent, VNode } from 'vue'\nimport type { TabPanelEntry } from './tabs'\n\ndefineOptions({ name: 'DouTabButton' })\n\nconst props = defineProps<{\n entry: TabPanelEntry\n tabId: string\n panelId: string\n labelText: string\n selected: boolean\n closable: boolean\n iconAlone: boolean\n draggable: boolean\n dragging: boolean\n mergeTarget?: boolean\n tipPlacement: 'top' | 'right' | 'left'\n keyShortcuts?: string\n setEl: (el: unknown) => void\n}>()\n\nconst emit = defineEmits<{\n click: []\n pointerdown: [event: PointerEvent]\n keydown: [event: KeyboardEvent]\n remove: []\n}>()\n\nconst ns = useNamespace('tabs')\nconst { t } = useLocale()\nconst onButtonRef = (el: unknown) => props.setEl(el)\n\n// A label cut short by an ellipsis shows the full text as a native title on\n// hover. Measured lazily on pointerenter so idle tabs pay nothing, and skipped\n// for icon-alone tabs which already have a DouTooltip.\nconst labelRef = useTemplateRef<HTMLElement>('label')\nconst tabTitle = ref<string>()\nfunction updateTitle() {\n if (props.iconAlone) {\n tabTitle.value = undefined\n return\n }\n tabTitle.value = resolveTruncatedTitle(labelRef.value, props.entry.props.label)\n}\nwatch([() => props.labelText, () => props.iconAlone], () => {\n tabTitle.value = undefined\n})\n\n/** The label slot of a panel, rendered inside its tab. */\nconst TabLabel: FunctionalComponent = () =>\n (props.entry.slots.label?.({ selected: props.selected }) as VNode[] | undefined) ??\n props.labelText\n\nconst TabTip: FunctionalComponent = (_, { slots: tip }) =>\n props.iconAlone\n ? h(DouTooltip, { content: props.labelText, placement: props.tipPlacement }, tip)\n : tip.default?.()\n</script>\n\n<template>\n <TabTip>\n <button\n :id=\"tabId\"\n :ref=\"onButtonRef\"\n type=\"button\"\n role=\"tab\"\n :class=\"[\n ns.e('tab'),\n ns.is('selected', selected),\n ns.is('disabled', !!entry.props.disabled),\n ns.is('closable', closable),\n ns.is('icon-alone', iconAlone),\n ns.is('pinned', !!entry.props.pinned),\n ns.is('draggable', draggable),\n ns.is('dragging', dragging),\n ns.is('merge-target', !!mergeTarget),\n ]\"\n :title=\"tabTitle\"\n :aria-selected=\"selected\"\n :aria-controls=\"panelId\"\n :aria-label=\"iconAlone ? labelText : undefined\"\n :aria-disabled=\"entry.props.disabled || undefined\"\n :tabindex=\"selected ? 0 : -1\"\n :aria-keyshortcuts=\"keyShortcuts\"\n @click=\"emit('click')\"\n @pointerenter=\"updateTitle\"\n @pointerdown=\"emit('pointerdown', $event)\"\n @keydown=\"emit('keydown', $event)\"\n >\n <component\n :is=\"entry.props.icon\"\n v-if=\"entry.props.icon\"\n :class=\"ns.e('icon')\"\n aria-hidden=\"true\"\n />\n <span v-if=\"!iconAlone\" ref=\"label\" :class=\"ns.e('label')\" @pointerenter=\"updateTitle\">\n <TabLabel />\n </span>\n <!-- not a button of its own: a tab cannot hold one; `Delete` closes it from the keyboard.\n An icon alone already has the label's tooltip, so the close button goes without. -->\n <DouTooltip\n v-if=\"closable\"\n :content=\"t('tabs.close')\"\n shortcut=\"delete\"\n :disabled=\"iconAlone\"\n >\n <span\n :class=\"ns.e('close')\"\n :title=\"tabTitle ? '' : undefined\"\n a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AAC,OAAA,CAAA;OACX,OAAO,SAAA,QAAQ,KAAQ,KAAA;OACxB,eAAY;OACX,SAAK,OAAA,OAAA,OAAA,KAAAK,eAAA,WAAO,KAAI,QAAA,GAAA,CAAA,MAAA,CAAA;M,IAEjBD,YAAaJ,MAAA,SAAA,CAAA,C"}
|
|
@@ -4,6 +4,7 @@ import { shallowRef } from "vue";
|
|
|
4
4
|
var zones = /* @__PURE__ */ new Map();
|
|
5
5
|
/** The drag in progress, if any. */
|
|
6
6
|
var activeTabDrag = shallowRef(null);
|
|
7
|
+
var tabMergeTargetKey = Symbol("DouTabMergeTarget");
|
|
7
8
|
function registerTabDropZone(zone) {
|
|
8
9
|
let el;
|
|
9
10
|
return {
|
|
@@ -75,7 +76,10 @@ function pressTab(event, options) {
|
|
|
75
76
|
if (options.ghost) {
|
|
76
77
|
clone = document.createElement("div");
|
|
77
78
|
clone.className = "dou-tabs__tab";
|
|
78
|
-
|
|
79
|
+
const text = document.createElement("span");
|
|
80
|
+
text.className = "dou-tabs__label";
|
|
81
|
+
text.textContent = options.ghost.label;
|
|
82
|
+
clone.append(text);
|
|
79
83
|
} else {
|
|
80
84
|
clone = options.el.cloneNode(true);
|
|
81
85
|
clone.removeAttribute("id");
|
|
@@ -102,8 +106,12 @@ function pressTab(event, options) {
|
|
|
102
106
|
for (const name of [
|
|
103
107
|
"--dou-tabs-height",
|
|
104
108
|
"--dou-tabs-padding-x",
|
|
105
|
-
"--dou-tabs-icon-size"
|
|
106
|
-
|
|
109
|
+
"--dou-tabs-icon-size",
|
|
110
|
+
"--dou-tabs-tab-max-width"
|
|
111
|
+
]) {
|
|
112
|
+
const value = style.getPropertyValue(name);
|
|
113
|
+
if (value) clone.style.setProperty(name, value);
|
|
114
|
+
}
|
|
107
115
|
clone.style.fontSize = style.fontSize;
|
|
108
116
|
}
|
|
109
117
|
const theme = (tabs ?? options.el).closest("[data-dou-theme]")?.dataset.douTheme;
|
|
@@ -184,6 +192,6 @@ function pressTab(event, options) {
|
|
|
184
192
|
window.addEventListener("pointercancel", onCancel);
|
|
185
193
|
window.addEventListener("keydown", onKey, true);
|
|
186
194
|
}
|
|
187
|
-
export { activeTabDrag, isIgnoredDragPress, pressTab, registerTabDropZone };
|
|
195
|
+
export { activeTabDrag, isIgnoredDragPress, pressTab, registerTabDropZone, tabMergeTargetKey };
|
|
188
196
|
|
|
189
197
|
//# sourceMappingURL=tab-drag.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tab-drag.js","names":[],"sources":["../../../src/components/tabs/tab-drag.ts"],"sourcesContent":["import { shallowRef } from 'vue'\nimport { holdPointer } from '../../utils/pointer'\nimport type { TabsValue } from './tabs'\n\n/** A tab being dragged. One at a time on the whole page. */\nexport interface TabDrag {\n value: TabsValue\n /** The tab's text, for the ghost and for what screen readers hear. */\n label: string\n /** The `group` of the tabs it comes from. */\n group: string | undefined\n /** The `name` of the tabs it comes from. */\n name: string | undefined\n /** Its index in the tabs it comes from. */\n index: number\n /** The tabs it comes from, to tell a move within them from one between tabs. */\n source: object\n /** Whether the dragged tab is pinned. */\n pinned?: boolean\n}\n\n/** A place a tab can be dropped on: a row of tabs, or a group of a dock. */\nexport interface TabDropZone {\n el: () => Element | null | undefined\n accepts: (drag: TabDrag) => boolean\n /** The pointer is over the zone; show where the tab would go. */\n over: (drag: TabDrag, x: number, y: number) => void\n /** The pointer left the zone, or the drag ended. */\n leave: () => void\n drop: (drag: TabDrag) => void\n}\n\nconst zones = new Map<Element, TabDropZone>()\n\n/** The drag in progress, if any. */\nexport const activeTabDrag = shallowRef<TabDrag | null>(null)\n\nexport function registerTabDropZone(zone: TabDropZone) {\n let el: Element | null | undefined\n return {\n /** Call after the zone's element changes. */\n update() {\n const next = zone.el()\n if (next === el) return\n if (el) zones.delete(el)\n el = next\n if (el) zones.set(el, zone)\n },\n remove() {\n if (el) zones.delete(el)\n el = undefined\n },\n }\n}\n\n/** The innermost zone under the point that takes this tab. */\nfunction zoneAt(drag: TabDrag, x: number, y: number) {\n let el = document.elementFromPoint(x, y)\n while (el) {\n const zone = zones.get(el)\n if (zone?.accepts(drag)) return zone\n el = el.parentElement\n }\n return undefined\n}\n\nexport interface StartTabDragOptions {\n /** The tab element: it is copied for the ghost and dimmed while it moves. */\n el: HTMLElement\n /**\n * For a drag that starts on something other than a tab: the ghost is a\n * tab with this text, sized like the tabs of `tabs`, in place of a copy of `el`.\n */\n ghost?: { label: string; tabs: HTMLElement | null | undefined }\n /** An element that stays in the page for the whole drag, to capture the pointer. */\n root: HTMLElement | null\n drag: () => TabDrag\n onStart?: () => void\n /** The drag is over, dropped or not. */\n onEnd?: (dropped: boolean) => void\n}\n\n/**\n * Whether a pointerdown should not start a tab drag: non-primary buttons and\n * modifier-key clicks keep their native behavior (context menu, open in new\n * tab, range select, etc.).\n */\nexport function isIgnoredDragPress(event: PointerEvent) {\n return event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey\n}\n\n/**\n * Watch a press on a tab and turn it into a drag once the pointer moves\n * far enough. On touch the press has to be held first, so a swipe still\n * scrolls the row of tabs.\n */\nexport function pressTab(event: PointerEvent, options: StartTabDragOptions) {\n if (isIgnoredDragPress(event) || activeTabDrag.value) return\n const start = { x: event.clientX, y: event.clientY }\n const press = event.pointerType === 'touch'\n let ready = !press\n let drag: TabDrag | null = null\n let ghost: HTMLElement | undefined\n let offset = { x: 0, y: 0 }\n let pointer = { x: 0, y: 0 }\n let current: TabDropZone | undefined\n let frame = 0\n const timer = press ? setTimeout(() => (ready = true), 250) : undefined\n const hold = holdPointer(event, options.root)\n\n function makeGhost(e: PointerEvent) {\n const rect = options.el.getBoundingClientRect()\n // below the pointer, off the row it moves along, so the mark where it drops stays in sight\n offset = { x: Math.min(e.clientX - rect.left, 16), y: -16 }\n let clone: HTMLElement\n if (options.ghost) {\n clone = document.createElement('div')\n clone.className = 'dou-tabs__tab'\n clone.textContent = options.ghost.label\n } else {\n clone = options.el.cloneNode(true) as HTMLElement\n clone.removeAttribute('id')\n clone.classList.remove('is-dragging')\n Object.assign(clone.style, { width: `${rect.width}px`, height: `${rect.height}px` })\n }\n clone.classList.add('dou-tabs-ghost')\n clone.setAttribute('aria-hidden', 'true')\n Object.assign(clone.style, {\n position: 'fixed',\n left: '0',\n top: '0',\n margin: '0',\n boxSizing: 'border-box',\n pointerEvents: 'none',\n zIndex: '9999',\n })\n // the copy sits on `body`: keep the size and theme of the tabs it came from\n const tabs = options.ghost ? options.ghost.tabs : options.el.closest<HTMLElement>('.dou-tabs')\n if (tabs) {\n const style = getComputedStyle(tabs)\n for (const name of ['--dou-tabs-height', '--dou-tabs-padding-x', '--dou-tabs-icon-size'])\n clone.style.setProperty(name, style.getPropertyValue(name))\n clone.style.fontSize = style.fontSize\n }\n const theme = (tabs ?? options.el).closest<HTMLElement>('[data-dou-theme]')?.dataset.douTheme\n if (theme) clone.dataset.douTheme = theme\n document.body.append(clone)\n ghost = clone\n moveGhost()\n }\n function moveGhost() {\n if (ghost) ghost.style.translate = `${pointer.x - offset.x}px ${pointer.y - offset.y}px`\n }\n\n // checked every frame, so a row that scrolls under a still pointer stays right\n function tick() {\n if (!drag) return\n const zone = zoneAt(drag, pointer.x, pointer.y)\n if (zone !== current) current?.leave()\n current = zone\n zone?.over(drag, pointer.x, pointer.y)\n frame = requestAnimationFrame(tick)\n }\n\n function begin(e: PointerEvent) {\n drag = options.drag()\n activeTabDrag.value = drag\n hold.grab()\n document.documentElement.classList.add('dou-tabs-dragging')\n makeGhost(e)\n options.onStart?.()\n frame = requestAnimationFrame(tick)\n }\n\n function end(commit: boolean) {\n stop()\n cancelAnimationFrame(frame)\n ghost?.remove()\n document.documentElement.classList.remove('dou-tabs-dragging')\n const finished = drag\n drag = null\n activeTabDrag.value = null\n if (!finished) return\n // where the pointer is now, also when no frame ran since the last move\n const zone = commit ? zoneAt(finished, pointer.x, pointer.y) : undefined\n if (zone !== current) current?.leave()\n current = undefined\n if (zone) {\n // brought up to date with the pointer, then dropped on; it clears what it showed\n zone.over(finished, pointer.x, pointer.y)\n zone.drop(finished)\n }\n options.onEnd?.(!!zone)\n }\n\n const onMove = (e: PointerEvent) => {\n pointer = { x: e.clientX, y: e.clientY }\n if (!drag) {\n if (Math.hypot(e.clientX - start.x, e.clientY - start.y) <= 4) return\n if (!ready) return stop()\n begin(e)\n }\n e.preventDefault()\n moveGhost()\n }\n const onUp = () => (drag ? end(true) : stop())\n const onCancel = () => (drag ? end(false) : stop())\n const onKey = (e: KeyboardEvent) => {\n if (e.key !== 'Escape' || !drag) return\n e.preventDefault()\n e.stopPropagation()\n end(false)\n }\n function stop() {\n clearTimeout(timer)\n hold.release()\n window.removeEventListener('pointermove', onMove)\n window.removeEventListener('pointerup', onUp)\n window.removeEventListener('pointercancel', onCancel)\n window.removeEventListener('keydown', onKey, true)\n }\n window.addEventListener('pointermove', onMove)\n window.addEventListener('pointerup', onUp)\n window.addEventListener('pointercancel', onCancel)\n window.addEventListener('keydown', onKey, true)\n}\n"],"mappings":";;;AAgCA,IAAM,wBAAQ,IAAI,IAA0B;;AAG5C,IAAa,gBAAgB,WAA2B,IAAI;AAE5D,SAAgB,oBAAoB,MAAmB;CACrD,IAAI;CACJ,OAAO;;EAEL,SAAS;GACP,MAAM,OAAO,KAAK,GAAG;GACrB,IAAI,SAAS,IAAI;GACjB,IAAI,IAAI,MAAM,OAAO,EAAE;GACvB,KAAK;GACL,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI;EAC5B;EACA,SAAS;GACP,IAAI,IAAI,MAAM,OAAO,EAAE;GACvB,KAAK,KAAA;EACP;CACF;AACF;;AAGA,SAAS,OAAO,MAAe,GAAW,GAAW;CACnD,IAAI,KAAK,SAAS,iBAAiB,GAAG,CAAC;CACvC,OAAO,IAAI;EACT,MAAM,OAAO,MAAM,IAAI,EAAE;EACzB,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO;EAChC,KAAK,GAAG;CACV;AAEF;;;;;;AAuBA,SAAgB,mBAAmB,OAAqB;CACtD,OAA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,CAAC,IAAI,KAAA;EAC/D,IAAI,SAAS,SAAS,SAAS,MAAM;EACrC,UAAU,KAAA;EACV,IAAI,MAAM;GAER,KAAK,KAAK,UAAU,QAAQ,GAAG,QAAQ,CAAC;GACxC,KAAK,KAAK,QAAQ;EACpB;EACA,QAAQ,QAAQ,CAAC,CAAC,IAAI;CACxB;CAEA,MAAM,UAAU,MAAoB;EAClC,UAAU;GAAE,GAAG,EAAE;GAAS,GAAG,EAAE;EAAQ;EACvC,IAAI,CAAC,MAAM;GACT,IAAI,KAAK,MAAM,EAAE,UAAU,MAAM,GAAG,EAAE,UAAU,MAAM,CAAC,KAAK,GAAG;GAC/D,IAAI,CAAC,OAAO,OAAO,KAAK;GACxB,MAAM,CAAC;EACT;EACA,EAAE,eAAe;EACjB,UAAU;CACZ;CACA,MAAM,aAAc,OAAO,IAAI,IAAI,IAAI,KAAK;CAC5C,MAAM,iBAAkB,OAAO,IAAI,KAAK,IAAI,KAAK;CACjD,MAAM,SAAS,MAAqB;EAClC,IAAI,EAAE,QAAQ,YAAY,CAAC,MAAM;EACjC,EAAE,eAAe;EACjB,EAAE,gBAAgB;EAClB,IAAI,KAAK;CACX;CACA,SAAS,OAAO;EACd,aAAa,KAAK;EAClB,KAAK,QAAQ;EACb,OAAO,oBAAoB,eAAe,MAAM;EAChD,OAAO,oBAAoB,aAAa,IAAI;EAC5C,OAAO,oBAAoB,iBAAiB,QAAQ;EACpD,OAAO,oBAAoB,WAAW,OAAO,IAAI;CACnD;CACA,OAAO,iBAAiB,eAAe,MAAM;CAC7C,OAAO,iBAAiB,aAAa,IAAI;CACzC,OAAO,iBAAiB,iBAAiB,QAAQ;CACjD,OAAO,iBAAiB,WAAW,OAAO,IAAI;AAChD"}
|
|
1
|
+
{"version":3,"file":"tab-drag.js","names":[],"sources":["../../../src/components/tabs/tab-drag.ts"],"sourcesContent":["import { shallowRef } from 'vue'\nimport { holdPointer } from '../../utils/pointer'\nimport type { InjectionKey, Ref } from 'vue'\nimport type { TabsValue } from './tabs'\n\n/** A tab being dragged. One at a time on the whole page. */\nexport interface TabDrag {\n value: TabsValue\n /** The tab's text, for the ghost and for what screen readers hear. */\n label: string\n /** The `group` of the tabs it comes from. */\n group: string | undefined\n /** The `name` of the tabs it comes from. */\n name: string | undefined\n /** Its index in the tabs it comes from. */\n index: number\n /** The tabs it comes from, to tell a move within them from one between tabs. */\n source: object\n /** Whether the dragged tab is pinned. */\n pinned?: boolean\n}\n\n/** A place a tab can be dropped on: a row of tabs, or a group of a dock. */\nexport interface TabDropZone {\n el: () => Element | null | undefined\n accepts: (drag: TabDrag) => boolean\n /** The pointer is over the zone; show where the tab would go. */\n over: (drag: TabDrag, x: number, y: number) => void\n /** The pointer left the zone, or the drag ended. */\n leave: () => void\n drop: (drag: TabDrag) => void\n}\n\nconst zones = new Map<Element, TabDropZone>()\n\n/** The drag in progress, if any. */\nexport const activeTabDrag = shallowRef<TabDrag | null>(null)\n\n/**\n * Internal bridge for `DouDock` to report whether dropping `drag` onto a\n * group's tab bar or center body will merge into an existing tab instead of inserting.\n */\nexport interface TabMergeBridge {\n resolve: (drag: TabDrag) => TabsValue | undefined\n active: Ref<TabsValue | null>\n}\nexport const tabMergeTargetKey: InjectionKey<TabMergeBridge> = Symbol('DouTabMergeTarget')\n\nexport function registerTabDropZone(zone: TabDropZone) {\n let el: Element | null | undefined\n return {\n /** Call after the zone's element changes. */\n update() {\n const next = zone.el()\n if (next === el) return\n if (el) zones.delete(el)\n el = next\n if (el) zones.set(el, zone)\n },\n remove() {\n if (el) zones.delete(el)\n el = undefined\n },\n }\n}\n\n/** The innermost zone under the point that takes this tab. */\nfunction zoneAt(drag: TabDrag, x: number, y: number) {\n let el = document.elementFromPoint(x, y)\n while (el) {\n const zone = zones.get(el)\n if (zone?.accepts(drag)) return zone\n el = el.parentElement\n }\n return undefined\n}\n\nexport interface StartTabDragOptions {\n /** The tab element: it is copied for the ghost and dimmed while it moves. */\n el: HTMLElement\n /**\n * For a drag that starts on something other than a tab: the ghost is a\n * tab with this text, sized like the tabs of `tabs`, in place of a copy of `el`.\n */\n ghost?: { label: string; tabs: HTMLElement | null | undefined }\n /** An element that stays in the page for the whole drag, to capture the pointer. */\n root: HTMLElement | null\n drag: () => TabDrag\n onStart?: () => void\n /** The drag is over, dropped or not. */\n onEnd?: (dropped: boolean) => void\n}\n\n/**\n * Whether a pointerdown should not start a tab drag: non-primary buttons and\n * modifier-key clicks keep their native behavior (context menu, open in new\n * tab, range select, etc.).\n */\nexport function isIgnoredDragPress(event: PointerEvent) {\n return event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey\n}\n\n/**\n * Watch a press on a tab and turn it into a drag once the pointer moves\n * far enough. On touch the press has to be held first, so a swipe still\n * scrolls the row of tabs.\n */\nexport function pressTab(event: PointerEvent, options: StartTabDragOptions) {\n if (isIgnoredDragPress(event) || activeTabDrag.value) return\n const start = { x: event.clientX, y: event.clientY }\n const press = event.pointerType === 'touch'\n let ready = !press\n let drag: TabDrag | null = null\n let ghost: HTMLElement | undefined\n let offset = { x: 0, y: 0 }\n let pointer = { x: 0, y: 0 }\n let current: TabDropZone | undefined\n let frame = 0\n const timer = press ? setTimeout(() => (ready = true), 250) : undefined\n const hold = holdPointer(event, options.root)\n\n function makeGhost(e: PointerEvent) {\n const rect = options.el.getBoundingClientRect()\n // below the pointer, off the row it moves along, so the mark where it drops stays in sight\n offset = { x: Math.min(e.clientX - rect.left, 16), y: -16 }\n let clone: HTMLElement\n if (options.ghost) {\n clone = document.createElement('div')\n clone.className = 'dou-tabs__tab'\n const text = document.createElement('span')\n text.className = 'dou-tabs__label'\n text.textContent = options.ghost.label\n clone.append(text)\n } else {\n clone = options.el.cloneNode(true) as HTMLElement\n clone.removeAttribute('id')\n clone.classList.remove('is-dragging')\n Object.assign(clone.style, { width: `${rect.width}px`, height: `${rect.height}px` })\n }\n clone.classList.add('dou-tabs-ghost')\n clone.setAttribute('aria-hidden', 'true')\n Object.assign(clone.style, {\n position: 'fixed',\n left: '0',\n top: '0',\n margin: '0',\n boxSizing: 'border-box',\n pointerEvents: 'none',\n zIndex: '9999',\n })\n // the copy sits on `body`: keep the size and theme of the tabs it came from\n const tabs = options.ghost ? options.ghost.tabs : options.el.closest<HTMLElement>('.dou-tabs')\n if (tabs) {\n const style = getComputedStyle(tabs)\n for (const name of [\n '--dou-tabs-height',\n '--dou-tabs-padding-x',\n '--dou-tabs-icon-size',\n '--dou-tabs-tab-max-width',\n ]) {\n const value = style.getPropertyValue(name)\n if (value) clone.style.setProperty(name, value)\n }\n clone.style.fontSize = style.fontSize\n }\n const theme = (tabs ?? options.el).closest<HTMLElement>('[data-dou-theme]')?.dataset.douTheme\n if (theme) clone.dataset.douTheme = theme\n document.body.append(clone)\n ghost = clone\n moveGhost()\n }\n function moveGhost() {\n if (ghost) ghost.style.translate = `${pointer.x - offset.x}px ${pointer.y - offset.y}px`\n }\n\n // checked every frame, so a row that scrolls under a still pointer stays right\n function tick() {\n if (!drag) return\n const zone = zoneAt(drag, pointer.x, pointer.y)\n if (zone !== current) current?.leave()\n current = zone\n zone?.over(drag, pointer.x, pointer.y)\n frame = requestAnimationFrame(tick)\n }\n\n function begin(e: PointerEvent) {\n drag = options.drag()\n activeTabDrag.value = drag\n hold.grab()\n document.documentElement.classList.add('dou-tabs-dragging')\n makeGhost(e)\n options.onStart?.()\n frame = requestAnimationFrame(tick)\n }\n\n function end(commit: boolean) {\n stop()\n cancelAnimationFrame(frame)\n ghost?.remove()\n document.documentElement.classList.remove('dou-tabs-dragging')\n const finished = drag\n drag = null\n activeTabDrag.value = null\n if (!finished) return\n // where the pointer is now, also when no frame ran since the last move\n const zone = commit ? zoneAt(finished, pointer.x, pointer.y) : undefined\n if (zone !== current) current?.leave()\n current = undefined\n if (zone) {\n // brought up to date with the pointer, then dropped on; it clears what it showed\n zone.over(finished, pointer.x, pointer.y)\n zone.drop(finished)\n }\n options.onEnd?.(!!zone)\n }\n\n const onMove = (e: PointerEvent) => {\n pointer = { x: e.clientX, y: e.clientY }\n if (!drag) {\n if (Math.hypot(e.clientX - start.x, e.clientY - start.y) <= 4) return\n if (!ready) return stop()\n begin(e)\n }\n e.preventDefault()\n moveGhost()\n }\n const onUp = () => (drag ? end(true) : stop())\n const onCancel = () => (drag ? end(false) : stop())\n const onKey = (e: KeyboardEvent) => {\n if (e.key !== 'Escape' || !drag) return\n e.preventDefault()\n e.stopPropagation()\n end(false)\n }\n function stop() {\n clearTimeout(timer)\n hold.release()\n window.removeEventListener('pointermove', onMove)\n window.removeEventListener('pointerup', onUp)\n window.removeEventListener('pointercancel', onCancel)\n window.removeEventListener('keydown', onKey, true)\n }\n window.addEventListener('pointermove', onMove)\n window.addEventListener('pointerup', onUp)\n window.addEventListener('pointercancel', onCancel)\n window.addEventListener('keydown', onKey, true)\n}\n"],"mappings":";;;AAiCA,IAAM,wBAAQ,IAAI,IAA0B;;AAG5C,IAAa,gBAAgB,WAA2B,IAAI;AAU5D,IAAa,oBAAkD,OAAO,mBAAmB;AAEzF,SAAgB,oBAAoB,MAAmB;CACrD,IAAI;CACJ,OAAO;;EAEL,SAAS;GACP,MAAM,OAAO,KAAK,GAAG;GACrB,IAAI,SAAS,IAAI;GACjB,IAAI,IAAI,MAAM,OAAO,EAAE;GACvB,KAAK;GACL,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI;EAC5B;EACA,SAAS;GACP,IAAI,IAAI,MAAM,OAAO,EAAE;GACvB,KAAK,KAAA;EACP;CACF;AACF;;AAGA,SAAS,OAAO,MAAe,GAAW,GAAW;CACnD,IAAI,KAAK,SAAS,iBAAiB,GAAG,CAAC;CACvC,OAAO,IAAI;EACT,MAAM,OAAO,MAAM,IAAI,EAAE;EACzB,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO;EAChC,KAAK,GAAG;CACV;AAEF;;;;;;AAuBA,SAAgB,mBAAmB,OAAqB;CACtD,OAAO,MAAM,WAAW,KAAK,MAAM,WAAW,MAAM,WAAW,MAAM,YAAY,MAAM;AACz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Popover } from "../popover/index.js";
|
|
8
8
|
import { announce } from "../../utils/announce.js";
|
|
9
|
+
import { resolveTruncatedTitle } from "./truncated-title.js";
|
|
9
10
|
import tab_button_default from "./tab-button.js";
|
|
10
|
-
import { pressTab, registerTabDropZone } from "./tab-drag.js";
|
|
11
|
+
import { pressTab, registerTabDropZone, tabMergeTargetKey } from "./tab-drag.js";
|
|
11
12
|
import { tabsKey } from "./tabs.js";
|
|
12
|
-
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, mergeModels, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, onUpdated, openBlock, provide, ref, renderList, renderSlot, resolveDynamicComponent, shallowRef, toRef, triggerRef, unref, useId, useModel, useSlots, useTemplateRef, watch, withCtx, withModifiers } from "vue";
|
|
13
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, inject, mergeModels, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, onUpdated, openBlock, provide, ref, renderList, renderSlot, resolveDynamicComponent, shallowRef, toRef, triggerRef, unref, useId, useModel, useSlots, useTemplateRef, watch, withCtx, withModifiers } from "vue";
|
|
13
14
|
import { CheckIcon, ChevronDownIcon, CloseIcon, PinIcon, PlusIcon } from "@dou-ui/icons";
|
|
14
15
|
// src/components/tabs/tabs.vue?vue&type=script&setup=true&lang.ts
|
|
15
16
|
var _hoisted_1 = ["aria-orientation"];
|
|
@@ -19,6 +20,7 @@ var _hoisted_4 = [
|
|
|
19
20
|
"disabled",
|
|
20
21
|
"aria-current",
|
|
21
22
|
"aria-keyshortcuts",
|
|
23
|
+
"onPointerenter",
|
|
22
24
|
"onClick",
|
|
23
25
|
"onKeydown"
|
|
24
26
|
];
|
|
@@ -118,11 +120,11 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
118
120
|
});
|
|
119
121
|
async function select(entry) {
|
|
120
122
|
if (entry.props.disabled) return;
|
|
121
|
-
await selectValue(entry.props.value);
|
|
123
|
+
await selectValue(entry.props.value, selected.value);
|
|
122
124
|
}
|
|
123
|
-
async function selectValue(next) {
|
|
124
|
-
if (next ===
|
|
125
|
-
if (props.beforeLeave && !await props.beforeLeave(next,
|
|
125
|
+
async function selectValue(next, current) {
|
|
126
|
+
if (next === current) return true;
|
|
127
|
+
if (props.beforeLeave && !await props.beforeLeave(next, current)) return false;
|
|
126
128
|
model.value = next;
|
|
127
129
|
emit("change", next);
|
|
128
130
|
return true;
|
|
@@ -233,6 +235,11 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
233
235
|
});
|
|
234
236
|
}
|
|
235
237
|
const marker = ref(null);
|
|
238
|
+
/** Existing tab that a dragged tab will merge into on drop, when inside a `DouDock`. */
|
|
239
|
+
const mergeTarget = ref(null);
|
|
240
|
+
let mergeFallbackIndex = 0;
|
|
241
|
+
const mergeBridge = inject(tabMergeTargetKey, void 0);
|
|
242
|
+
const activeMergeTarget = computed(() => mergeTarget.value ?? mergeBridge?.active.value ?? null);
|
|
236
243
|
function zoneEntries(zone) {
|
|
237
244
|
return zone === "pinned" ? pinnedPanels.value : regularPanels.value;
|
|
238
245
|
}
|
|
@@ -304,6 +311,14 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
304
311
|
accepts: (drag) => drag.source === self || props.draggable && !!props.group && drag.group === props.group,
|
|
305
312
|
over(drag, x, y) {
|
|
306
313
|
const zone = drag.pinned ? "pinned" : "regular";
|
|
314
|
+
const merge = mergeBridge?.resolve(drag);
|
|
315
|
+
if (merge !== void 0) {
|
|
316
|
+
marker.value = null;
|
|
317
|
+
mergeTarget.value = merge;
|
|
318
|
+
mergeFallbackIndex = rawInsertIndex(zone, insertionAt(zone, x, y));
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
mergeTarget.value = null;
|
|
307
322
|
if (zone === "regular") scrollNearEdge(x, y);
|
|
308
323
|
const slot = insertionAt(zone, x, y);
|
|
309
324
|
if (stays(drag, zone, slot)) {
|
|
@@ -324,13 +339,35 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
324
339
|
at
|
|
325
340
|
};
|
|
326
341
|
},
|
|
327
|
-
leave
|
|
342
|
+
leave() {
|
|
343
|
+
marker.value = null;
|
|
344
|
+
mergeTarget.value = null;
|
|
345
|
+
},
|
|
328
346
|
drop(drag) {
|
|
347
|
+
const merge = mergeTarget.value;
|
|
329
348
|
const current = marker.value;
|
|
330
349
|
marker.value = null;
|
|
350
|
+
mergeTarget.value = null;
|
|
351
|
+
if (merge !== null) {
|
|
352
|
+
emit("move", {
|
|
353
|
+
value: drag.value,
|
|
354
|
+
from: {
|
|
355
|
+
name: drag.name,
|
|
356
|
+
index: drag.index
|
|
357
|
+
},
|
|
358
|
+
to: {
|
|
359
|
+
name: props.name,
|
|
360
|
+
index: mergeFallbackIndex
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
331
365
|
if (!current) return;
|
|
332
366
|
const within = fromHere(drag);
|
|
333
367
|
const raw = rawInsertIndex(current.zone, current.slot);
|
|
368
|
+
const prevModel = model.value;
|
|
369
|
+
const prevSelected = selected.value;
|
|
370
|
+
const prevIndex = panels.value.findIndex((panel) => panel.props.value === drag.value);
|
|
334
371
|
emit("move", {
|
|
335
372
|
value: drag.value,
|
|
336
373
|
from: {
|
|
@@ -342,7 +379,17 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
342
379
|
index: within && raw > drag.index ? raw - 1 : raw
|
|
343
380
|
}
|
|
344
381
|
});
|
|
345
|
-
|
|
382
|
+
nextTick(() => {
|
|
383
|
+
if (model.value !== prevModel) return;
|
|
384
|
+
const nextIndex = panels.value.findIndex((panel) => panel.props.value === drag.value);
|
|
385
|
+
if (nextIndex < 0) return;
|
|
386
|
+
if (within && nextIndex === prevIndex) return;
|
|
387
|
+
if (drag.value === prevSelected) {
|
|
388
|
+
if (selected.value !== drag.value) model.value = drag.value;
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
selectValue(drag.value, prevSelected);
|
|
392
|
+
});
|
|
346
393
|
}
|
|
347
394
|
});
|
|
348
395
|
onMounted(() => {
|
|
@@ -560,9 +607,17 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
560
607
|
el?.scrollIntoView?.({ block: "nearest" });
|
|
561
608
|
el?.focus({ preventScroll: true });
|
|
562
609
|
}
|
|
610
|
+
function onOverflowItemEnter(event, entry) {
|
|
611
|
+
const button = event.currentTarget;
|
|
612
|
+
const labelEl = button?.querySelector(`.${ns.e("overflow-label")}`);
|
|
613
|
+
const title = resolveTruncatedTitle(labelEl, entry.props.label);
|
|
614
|
+
if (!button) return;
|
|
615
|
+
if (title) button.title = title;
|
|
616
|
+
else button.removeAttribute("title");
|
|
617
|
+
}
|
|
563
618
|
async function selectFromOverflow(entry, event) {
|
|
564
619
|
if (entry.props.disabled) return;
|
|
565
|
-
if (!await selectValue(entry.props.value)) return;
|
|
620
|
+
if (!await selectValue(entry.props.value, selected.value)) return;
|
|
566
621
|
overflowOpen.value = false;
|
|
567
622
|
await nextTick();
|
|
568
623
|
reveal(settled.value);
|
|
@@ -663,7 +718,7 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
663
718
|
vertical.value && unref(ns).is(`placement-${__props.placement}`, true),
|
|
664
719
|
unref(ns).is("fixed", __props.height !== void 0),
|
|
665
720
|
unref(ns).is("icon-only", __props.iconOnly),
|
|
666
|
-
unref(ns).is("drop-target", !!marker.value)
|
|
721
|
+
unref(ns).is("drop-target", !!marker.value || mergeTarget.value !== null)
|
|
667
722
|
]),
|
|
668
723
|
style: normalizeStyle(rootStyle.value)
|
|
669
724
|
}, [createElementVNode("div", {
|
|
@@ -691,6 +746,7 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
691
746
|
"icon-alone": iconAlone(entry),
|
|
692
747
|
draggable: isDraggable(entry),
|
|
693
748
|
dragging: draggingUid.value === entry.uid,
|
|
749
|
+
"merge-target": entry.props.value === activeMergeTarget.value,
|
|
694
750
|
"tip-placement": tipPlacement.value,
|
|
695
751
|
"key-shortcuts": keyShortcuts(entry),
|
|
696
752
|
"set-el": (el) => setTabElement("pinned", entry.uid, el),
|
|
@@ -708,6 +764,7 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
708
764
|
"icon-alone",
|
|
709
765
|
"draggable",
|
|
710
766
|
"dragging",
|
|
767
|
+
"merge-target",
|
|
711
768
|
"tip-placement",
|
|
712
769
|
"key-shortcuts",
|
|
713
770
|
"set-el",
|
|
@@ -750,6 +807,7 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
750
807
|
"icon-alone": iconAlone(entry),
|
|
751
808
|
draggable: isDraggable(entry),
|
|
752
809
|
dragging: draggingUid.value === entry.uid,
|
|
810
|
+
"merge-target": entry.props.value === activeMergeTarget.value,
|
|
753
811
|
"tip-placement": tipPlacement.value,
|
|
754
812
|
"key-shortcuts": keyShortcuts(entry),
|
|
755
813
|
"set-el": (el) => setTabElement("regular", entry.uid, el),
|
|
@@ -767,6 +825,7 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
767
825
|
"icon-alone",
|
|
768
826
|
"draggable",
|
|
769
827
|
"dragging",
|
|
828
|
+
"merge-target",
|
|
770
829
|
"tip-placement",
|
|
771
830
|
"key-shortcuts",
|
|
772
831
|
"set-el",
|
|
@@ -823,6 +882,7 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
823
882
|
disabled: entry.props.disabled,
|
|
824
883
|
"aria-current": entry.props.value === selected.value ? "true" : void 0,
|
|
825
884
|
"aria-keyshortcuts": isClosable(entry) ? "Delete" : void 0,
|
|
885
|
+
onPointerenter: ($event) => onOverflowItemEnter($event, entry),
|
|
826
886
|
onClick: ($event) => selectFromOverflow(entry, $event),
|
|
827
887
|
onKeydown: ($event) => onOverflowItemKeydown($event, entry)
|
|
828
888
|
}, [
|