dou-ui 0.1.0-alpha.6 → 0.1.0-alpha.7

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.
Files changed (71) hide show
  1. package/dist/components/chat-artifact/chat-artifact.js.map +1 -1
  2. package/dist/components/chat-artifact/chat-artifact.vue_vue_type_script_setup_true_lang.js +1 -1
  3. package/dist/components/chat-artifact/chat-artifact.vue_vue_type_script_setup_true_lang.js.map +1 -1
  4. package/dist/components/chat-message/chat-message.js.map +1 -1
  5. package/dist/components/dock/context.js +5 -0
  6. package/dist/components/dock/context.js.map +1 -0
  7. package/dist/components/dock/dock-group.js +6 -0
  8. package/dist/components/dock/dock-group.js.map +1 -0
  9. package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js +134 -0
  10. package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js.map +1 -0
  11. package/dist/components/dock/dock-node.js +6 -0
  12. package/dist/components/dock/dock-node.js.map +1 -0
  13. package/dist/components/dock/dock-node.vue_vue_type_script_setup_true_lang.js +47 -0
  14. package/dist/components/dock/dock-node.vue_vue_type_script_setup_true_lang.js.map +1 -0
  15. package/dist/components/dock/dock.js +6 -0
  16. package/dist/components/dock/dock.js.map +1 -0
  17. package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js +177 -0
  18. package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js.map +1 -0
  19. package/dist/components/dock/index.js +8 -0
  20. package/dist/components/dock/index.js.map +1 -0
  21. package/dist/components/dock/layout.js +121 -0
  22. package/dist/components/dock/layout.js.map +1 -0
  23. package/dist/components/dock/style.d.ts +1 -0
  24. package/dist/components/dock/style.js +7 -0
  25. package/dist/components/splitter/context.js +5 -0
  26. package/dist/components/splitter/context.js.map +1 -0
  27. package/dist/components/splitter/splitter.js.map +1 -1
  28. package/dist/components/splitter/splitter.vue_vue_type_script_setup_true_lang.js +97 -22
  29. package/dist/components/splitter/splitter.vue_vue_type_script_setup_true_lang.js.map +1 -1
  30. package/dist/components/tabs/tab-drag.js +172 -0
  31. package/dist/components/tabs/tab-drag.js.map +1 -0
  32. package/dist/components/tabs/tab-panel.js.map +1 -1
  33. package/dist/components/tabs/tab-panel.vue_vue_type_script_setup_true_lang.js +4 -0
  34. package/dist/components/tabs/tab-panel.vue_vue_type_script_setup_true_lang.js.map +1 -1
  35. package/dist/components/tabs/tabs.js.map +1 -1
  36. package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js +283 -72
  37. package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js.map +1 -1
  38. package/dist/components/tabs/tabs2.js.map +1 -1
  39. package/dist/index.js +6 -4
  40. package/dist/index.js.map +1 -1
  41. package/dist/locale/en.js +2 -1
  42. package/dist/locale/en.js.map +1 -1
  43. package/dist/locale/zh-cn.js +2 -1
  44. package/dist/locale/zh-cn.js.map +1 -1
  45. package/dist/locale/zh-tw.js +2 -1
  46. package/dist/locale/zh-tw.js.map +1 -1
  47. package/dist/plugin.js +4 -2
  48. package/dist/plugin.js.map +1 -1
  49. package/dist/style.css +1 -1
  50. package/dist/types/components/chat-artifact/chat-artifact.d.ts +5 -1
  51. package/dist/types/components/chat-message/chat-message.d.ts +1 -0
  52. package/dist/types/components/dock/context.d.ts +29 -0
  53. package/dist/types/components/dock/dock-group.vue.d.ts +7 -0
  54. package/dist/types/components/dock/dock-node.vue.d.ts +7 -0
  55. package/dist/types/components/dock/dock.d.ts +89 -0
  56. package/dist/types/components/dock/dock.vue.d.ts +31 -0
  57. package/dist/types/components/dock/index.d.ts +73 -0
  58. package/dist/types/components/dock/layout.d.ts +46 -0
  59. package/dist/types/components/index.d.ts +1 -0
  60. package/dist/types/components/menu/menu-item.vue.d.ts +1 -1
  61. package/dist/types/components/splitter/context.d.ts +11 -0
  62. package/dist/types/components/splitter/index.d.ts +3 -0
  63. package/dist/types/components/splitter/splitter.d.ts +5 -0
  64. package/dist/types/components/splitter/splitter.vue.d.ts +1 -0
  65. package/dist/types/components/tabs/index.d.ts +11 -0
  66. package/dist/types/components/tabs/tab-drag.d.ts +48 -0
  67. package/dist/types/components/tabs/tab-panel.vue.d.ts +1 -0
  68. package/dist/types/components/tabs/tabs.d.ts +28 -0
  69. package/dist/types/components/tabs/tabs.vue.d.ts +4 -1
  70. package/dist/types/locale/types.d.ts +2 -0
  71. package/package.json +3 -3
@@ -0,0 +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}\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 /** 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 * 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 (event.button !== 0 || 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 const clone = options.el.cloneNode(true) as HTMLElement\n clone.removeAttribute('id')\n clone.classList.remove('is-dragging')\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 width: `${rect.width}px`,\n height: `${rect.height}px`,\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.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 = 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":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"tab-panel.js","names":["_sfc_main"],"sources":["../../../src/components/tabs/tab-panel.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n getCurrentInstance,\n inject,\n onBeforeUnmount,\n onMounted,\n ref,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { tabsKey } from './tabs'\nimport type { TabPanelProps, TabPanelSlots } from './tabs'\n\ndefineOptions({ name: 'DouTabPanel' })\n\nconst props = withDefaults(defineProps<TabPanelProps>(), {\n disabled: false,\n closable: undefined,\n eager: false,\n})\nconst slots = defineSlots<TabPanelSlots>()\n\nconst ns = useNamespace('tabs')\nconst tabs = inject(tabsKey, undefined)\nconst uid = getCurrentInstance()!.uid\nconst el = useTemplateRef<HTMLElement>('el')\n\ntabs?.register({ uid, props, slots, el })\nonMounted(() => tabs?.reorder())\nonBeforeUnmount(() => tabs?.unregister(uid))\n\nconst selected = computed(() => tabs?.selected.value === props.value)\n\n// Render the content the first time the panel is shown, then keep it, so\n// switching back is instant and keeps its state.\nconst visited = ref(selected.value || props.eager)\nwatch(selected, (value) => {\n if (value) visited.value = true\n})\n</script>\n\n<template>\n <div\n :id=\"tabs?.panelId(value)\"\n ref=\"el\"\n :class=\"ns.e('panel')\"\n role=\"tabpanel\"\n :aria-labelledby=\"tabs?.tabId(value)\"\n :hidden=\"!selected\"\n tabindex=\"0\"\n >\n <slot v-if=\"visited\" />\n </div>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"tab-panel.js","names":["_sfc_main"],"sources":["../../../src/components/tabs/tab-panel.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n getCurrentInstance,\n inject,\n onBeforeUnmount,\n onMounted,\n ref,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { tabsKey } from './tabs'\nimport type { TabPanelProps, TabPanelSlots } from './tabs'\n\ndefineOptions({ name: 'DouTabPanel' })\n\nconst props = withDefaults(defineProps<TabPanelProps>(), {\n disabled: false,\n closable: undefined,\n draggable: undefined,\n eager: false,\n})\nconst slots = defineSlots<TabPanelSlots>()\n\nconst ns = useNamespace('tabs')\nconst tabs = inject(tabsKey, undefined)\nconst uid = getCurrentInstance()!.uid\nconst el = useTemplateRef<HTMLElement>('el')\n\ntabs?.register({ uid, props, slots, el })\nonMounted(() => tabs?.reorder())\nonBeforeUnmount(() => tabs?.unregister(uid))\n\nconst selected = computed(() => tabs?.selected.value === props.value)\n\n// Render the content the first time the panel is shown, then keep it, so\n// switching back is instant and keeps its state.\nconst visited = ref(selected.value || props.eager)\nwatch(selected, (value) => {\n if (value) visited.value = true\n})\n</script>\n\n<template>\n <div\n :id=\"tabs?.panelId(value)\"\n ref=\"el\"\n :class=\"ns.e('panel')\"\n role=\"tabpanel\"\n :aria-labelledby=\"tabs?.tabId(value)\"\n :hidden=\"!selected\"\n tabindex=\"0\"\n >\n <slot v-if=\"visited\" />\n </div>\n</template>\n"],"mappings":""}
@@ -22,6 +22,10 @@ var tab_panel_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
22
22
  type: Boolean,
23
23
  default: void 0
24
24
  },
25
+ draggable: {
26
+ type: Boolean,
27
+ default: void 0
28
+ },
25
29
  eager: {
26
30
  type: Boolean,
27
31
  default: false
@@ -1 +1 @@
1
- {"version":3,"file":"tab-panel.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_unref","_normalizeClass","_renderSlot","_createCommentVNode"],"sources":["../../../src/components/tabs/tab-panel.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n getCurrentInstance,\n inject,\n onBeforeUnmount,\n onMounted,\n ref,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { tabsKey } from './tabs'\nimport type { TabPanelProps, TabPanelSlots } from './tabs'\n\ndefineOptions({ name: 'DouTabPanel' })\n\nconst props = withDefaults(defineProps<TabPanelProps>(), {\n disabled: false,\n closable: undefined,\n eager: false,\n})\nconst slots = defineSlots<TabPanelSlots>()\n\nconst ns = useNamespace('tabs')\nconst tabs = inject(tabsKey, undefined)\nconst uid = getCurrentInstance()!.uid\nconst el = useTemplateRef<HTMLElement>('el')\n\ntabs?.register({ uid, props, slots, el })\nonMounted(() => tabs?.reorder())\nonBeforeUnmount(() => tabs?.unregister(uid))\n\nconst selected = computed(() => tabs?.selected.value === props.value)\n\n// Render the content the first time the panel is shown, then keep it, so\n// switching back is instant and keeps its state.\nconst visited = ref(selected.value || props.eager)\nwatch(selected, (value) => {\n if (value) visited.value = true\n})\n</script>\n\n<template>\n <div\n :id=\"tabs?.panelId(value)\"\n ref=\"el\"\n :class=\"ns.e('panel')\"\n role=\"tabpanel\"\n :aria-labelledby=\"tabs?.tabId(value)\"\n :hidden=\"!selected\"\n tabindex=\"0\"\n >\n <slot v-if=\"visited\" />\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBA,MAAM,QAAQ;EAKd,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,MAAM;EAC9B,MAAM,OAAO,OAAO,SAAS,KAAA,CAAS;EACtC,MAAM,MAAM,mBAAmB,CAAC,CAAE;EAClC,MAAM,KAAK,eAA4B,IAAI;EAE3C,MAAM,SAAS;GAAE;GAAK;GAAO;GAAO;EAAG,CAAC;EACxC,gBAAgB,MAAM,QAAQ,CAAC;EAC/B,sBAAsB,MAAM,WAAW,GAAG,CAAC;EAE3C,MAAM,WAAW,eAAe,MAAM,SAAS,UAAU,MAAM,KAAK;EAIpE,MAAM,UAAU,IAAI,SAAS,SAAS,MAAM,KAAK;EACjD,MAAM,WAAW,UAAU;GACzB,IAAI,OAAO,QAAQ,QAAQ;EAC7B,CAAC;;GAIC,OAAAC,UAAA,GAAAC,mBAUM,OAAA;IATH,IAAIC,MAAA,IAAA,CAAI,EAAE,QAAQ,QAAA,KAAK;IACpB,SAAA;IAAJ,KAAI;IACH,OAAKC,eAAED,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,CAAA;IACZ,MAAK;IACJ,mBAAiBA,MAAA,IAAA,CAAI,EAAE,MAAM,QAAA,KAAK;IAClC,QAAM,CAAG,SAAA;IACV,UAAS;G,IAEG,QAAA,QAAZE,WAAuB,KAAA,QAAA,WAAA,CAAA,GAAA,KAAA,GAAA,KAAA,GAAA,CAAA,I"}
1
+ {"version":3,"file":"tab-panel.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_unref","_normalizeClass","_renderSlot","_createCommentVNode"],"sources":["../../../src/components/tabs/tab-panel.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n getCurrentInstance,\n inject,\n onBeforeUnmount,\n onMounted,\n ref,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { tabsKey } from './tabs'\nimport type { TabPanelProps, TabPanelSlots } from './tabs'\n\ndefineOptions({ name: 'DouTabPanel' })\n\nconst props = withDefaults(defineProps<TabPanelProps>(), {\n disabled: false,\n closable: undefined,\n draggable: undefined,\n eager: false,\n})\nconst slots = defineSlots<TabPanelSlots>()\n\nconst ns = useNamespace('tabs')\nconst tabs = inject(tabsKey, undefined)\nconst uid = getCurrentInstance()!.uid\nconst el = useTemplateRef<HTMLElement>('el')\n\ntabs?.register({ uid, props, slots, el })\nonMounted(() => tabs?.reorder())\nonBeforeUnmount(() => tabs?.unregister(uid))\n\nconst selected = computed(() => tabs?.selected.value === props.value)\n\n// Render the content the first time the panel is shown, then keep it, so\n// switching back is instant and keeps its state.\nconst visited = ref(selected.value || props.eager)\nwatch(selected, (value) => {\n if (value) visited.value = true\n})\n</script>\n\n<template>\n <div\n :id=\"tabs?.panelId(value)\"\n ref=\"el\"\n :class=\"ns.e('panel')\"\n role=\"tabpanel\"\n :aria-labelledby=\"tabs?.tabId(value)\"\n :hidden=\"!selected\"\n tabindex=\"0\"\n >\n <slot v-if=\"visited\" />\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBA,MAAM,QAAQ;EAMd,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,MAAM;EAC9B,MAAM,OAAO,OAAO,SAAS,KAAA,CAAS;EACtC,MAAM,MAAM,mBAAmB,CAAC,CAAE;EAClC,MAAM,KAAK,eAA4B,IAAI;EAE3C,MAAM,SAAS;GAAE;GAAK;GAAO;GAAO;EAAG,CAAC;EACxC,gBAAgB,MAAM,QAAQ,CAAC;EAC/B,sBAAsB,MAAM,WAAW,GAAG,CAAC;EAE3C,MAAM,WAAW,eAAe,MAAM,SAAS,UAAU,MAAM,KAAK;EAIpE,MAAM,UAAU,IAAI,SAAS,SAAS,MAAM,KAAK;EACjD,MAAM,WAAW,UAAU;GACzB,IAAI,OAAO,QAAQ,QAAQ;EAC7B,CAAC;;GAIC,OAAAC,UAAA,GAAAC,mBAUM,OAAA;IATH,IAAIC,MAAA,IAAA,CAAI,EAAE,QAAQ,QAAA,KAAK;IACpB,SAAA;IAAJ,KAAI;IACH,OAAKC,eAAED,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,CAAA;IACZ,MAAK;IACJ,mBAAiBA,MAAA,IAAA,CAAI,EAAE,MAAM,QAAA,KAAK;IAClC,QAAM,CAAG,SAAA;IACV,UAAS;G,IAEG,QAAA,QAAZE,WAAuB,KAAA,QAAA,WAAA,CAAA,GAAA,KAAA,GAAA,KAAA,GAAA,CAAA,I"}
@@ -1 +1 @@
1
- {"version":3,"file":"tabs.js","names":[],"sources":["../../../src/components/tabs/tabs.ts"],"sourcesContent":["import type { Component, InjectionKey, Ref } from 'vue'\nimport type { Size } from '../../utils/types'\n\nexport type TabsValue = string | number\nexport type TabsSize = Size\nexport type TabsActivation = 'auto' | 'manual'\n/** Where the tab list sits: above the panels, or beside them on the start or end side. */\nexport type TabsPlacement = 'top' | 'start' | 'end'\n\nexport interface TabsProps {\n /** The value of the selected panel, bound with `v-model`. Defaults to the first enabled panel. */\n modelValue?: TabsValue\n size?: TabsSize\n /**\n * `auto` selects a tab as soon as arrow keys move focus to it; `manual`\n * waits for `Enter` or `Space`, for panels that are slow to render.\n */\n activation?: TabsActivation\n placement?: TabsPlacement\n /**\n * A fixed height, numbers in px; `'100%'` fills the parent. The panels\n * fill it and scroll on their own, and so does a column of tabs that\n * does not fit. Left unset, the tabs grow with their content.\n */\n height?: number | string\n /**\n * Show each tab as its panel's `icon` alone. The label becomes the tab's\n * accessible name and shows in a tooltip on hover and focus.\n */\n iconOnly?: boolean\n /** Give every tab a close button that emits `remove`. A panel's own `closable` wins. */\n closable?: boolean\n /** Put a button after the tabs that emits `add`. */\n addable?: boolean\n /**\n * Called before another tab is selected. Return `false`, or a promise of\n * `false`, to stay on the current one, e.g. while a form has unsaved changes.\n */\n beforeLeave?: (next: TabsValue, current: TabsValue | undefined) => boolean | Promise<boolean>\n}\n\nexport interface TabsEmits {\n 'update:modelValue': [value: TabsValue]\n /** The user picked another tab. */\n change: [value: TabsValue]\n /** The close button of a tab was pressed, or `Delete` on a closable tab. Remove its panel. */\n remove: [value: TabsValue]\n /** The add button was pressed. */\n add: []\n}\n\nexport interface TabsSlots {\n /** The panels, `DouTabPanel`s. */\n default?: () => unknown\n /** Placed at the end of the tab list, e.g. an action button. */\n extra?: () => unknown\n}\n\nexport interface TabPanelProps {\n value: TabsValue\n /** The text of the tab. With `iconOnly`, its accessible name and tooltip. */\n label?: string\n /** An icon component, shown before the label, and alone with the tabs' `iconOnly`. */\n icon?: Component\n disabled?: boolean\n /** Show a close button on this tab, overriding the tabs' `closable`. */\n closable?: boolean\n /**\n * Render the content before the panel is first shown, instead of on\n * first show. For content that must exist while hidden, e.g. form\n * fields that are checked on submit.\n */\n eager?: boolean\n}\n\nexport interface TabPanelSlots {\n default?: () => unknown\n /** Replaces the text of the tab, e.g. to add a count. Not shown with the tabs' `iconOnly`. */\n label?: (props: { selected: boolean }) => unknown\n}\n\nexport interface TabPanelEntry {\n uid: number\n props: TabPanelProps\n slots: TabPanelSlots\n el: Ref<HTMLElement | null>\n}\n\nexport interface TabsContext {\n selected: Readonly<Ref<TabsValue | undefined>>\n tabId: (value: TabsValue) => string\n panelId: (value: TabsValue) => string\n register: (entry: TabPanelEntry) => void\n unregister: (uid: number) => void\n reorder: () => void\n}\n\nexport const tabsKey: InjectionKey<TabsContext> = Symbol('DouTabs')\n"],"mappings":";AAiGA,IAAa,UAAqC,OAAO,SAAS"}
1
+ {"version":3,"file":"tabs.js","names":[],"sources":["../../../src/components/tabs/tabs.ts"],"sourcesContent":["import type { Component, InjectionKey, Ref } from 'vue'\nimport type { Size } from '../../utils/types'\n\nexport type TabsValue = string | number\nexport type TabsSize = Size\nexport type TabsActivation = 'auto' | 'manual'\n/** Where the tab list sits: above the panels, or beside them on the start or end side. */\nexport type TabsPlacement = 'top' | 'start' | 'end'\n\nexport interface TabsProps {\n /** The value of the selected panel, bound with `v-model`. Defaults to the first enabled panel. */\n modelValue?: TabsValue\n size?: TabsSize\n /**\n * `auto` selects a tab as soon as arrow keys move focus to it; `manual`\n * waits for `Enter` or `Space`, for panels that are slow to render.\n */\n activation?: TabsActivation\n placement?: TabsPlacement\n /**\n * A fixed height, numbers in px; `'100%'` fills the parent. The panels\n * fill it and scroll on their own, and so does a column of tabs that\n * does not fit. Left unset, the tabs grow with their content.\n */\n height?: number | string\n /**\n * Show each tab as its panel's `icon` alone. The label becomes the tab's\n * accessible name and shows in a tooltip on hover and focus.\n */\n iconOnly?: boolean\n /** Give every tab a close button that emits `remove`. A panel's own `closable` wins. */\n closable?: boolean\n /** Put a button after the tabs that emits `add`. */\n addable?: boolean\n /**\n * Called before another tab is selected. Return `false`, or a promise of\n * `false`, to stay on the current one, e.g. while a form has unsaved changes.\n */\n beforeLeave?: (next: TabsValue, current: TabsValue | undefined) => boolean | Promise<boolean>\n /**\n * Let the tabs be dragged to a new place, and take tabs dropped here.\n * `Alt` with the arrow keys moves the focused tab. The tabs only emit\n * `move`; put the panels in the new order yourself.\n */\n draggable?: boolean\n /** Tabs with the same group take each other's tabs. */\n group?: string\n /** Names these tabs in `move` events, to tell the tabs of a group apart. */\n name?: string\n}\n\n/** Where a tab is: the `name` of its tabs and its index there. */\nexport interface TabsLocation {\n name: string | undefined\n index: number\n}\n\nexport interface TabsMoveEvent {\n value: TabsValue\n from: TabsLocation\n /** Where the tab ends up, its index counted once the move is done. */\n to: TabsLocation\n}\n\nexport interface TabsEmits {\n 'update:modelValue': [value: TabsValue]\n /** The user picked another tab. */\n change: [value: TabsValue]\n /** The close button of a tab was pressed, or `Delete` on a closable tab. Remove its panel. */\n remove: [value: TabsValue]\n /** The add button was pressed. */\n add: []\n /**\n * A tab was dragged, or moved with `Alt` and an arrow key. Sent by the\n * tabs it lands in, also when it comes from other tabs of the group.\n */\n move: [event: TabsMoveEvent]\n}\n\nexport interface TabsSlots {\n /** The panels, `DouTabPanel`s. */\n default?: () => unknown\n /** Placed at the end of the tab list, e.g. an action button. */\n extra?: () => unknown\n}\n\nexport interface TabPanelProps {\n value: TabsValue\n /** The text of the tab. With `iconOnly`, its accessible name and tooltip. */\n label?: string\n /** An icon component, shown before the label, and alone with the tabs' `iconOnly`. */\n icon?: Component\n disabled?: boolean\n /** Show a close button on this tab, overriding the tabs' `closable`. */\n closable?: boolean\n /** Whether this tab can be dragged, overriding the tabs' `draggable`. */\n draggable?: boolean\n /**\n * Render the content before the panel is first shown, instead of on\n * first show. For content that must exist while hidden, e.g. form\n * fields that are checked on submit.\n */\n eager?: boolean\n}\n\nexport interface TabPanelSlots {\n default?: () => unknown\n /** Replaces the text of the tab, e.g. to add a count. Not shown with the tabs' `iconOnly`. */\n label?: (props: { selected: boolean }) => unknown\n}\n\nexport interface TabPanelEntry {\n uid: number\n props: TabPanelProps\n slots: TabPanelSlots\n el: Ref<HTMLElement | null>\n}\n\nexport interface TabsContext {\n selected: Readonly<Ref<TabsValue | undefined>>\n tabId: (value: TabsValue) => string\n panelId: (value: TabsValue) => string\n register: (entry: TabPanelEntry) => void\n unregister: (uid: number) => void\n reorder: () => void\n}\n\nexport const tabsKey: InjectionKey<TabsContext> = Symbol('DouTabs')\n"],"mappings":";AA+HA,IAAa,UAAqC,OAAO,SAAS"}
@@ -5,8 +5,10 @@ import { useReducedMotion } from "../../composables/use-motion.js";
5
5
  import { devWarn } from "../../utils/status-check.js";
6
6
  import { useFormSize } from "../form/use-form-item.js";
7
7
  import { DouTooltip } from "../tooltip/index.js";
8
+ import { announce } from "../../utils/announce.js";
9
+ import { pressTab, registerTabDropZone } from "./tab-drag.js";
8
10
  import { tabsKey } from "./tabs.js";
9
- import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, h, mergeModels, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, provide, ref, renderList, renderSlot, resolveDynamicComponent, shallowRef, toRef, triggerRef, unref, useId, useModel, useSlots, useTemplateRef, watch, withCtx, withModifiers } from "vue";
11
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, h, 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";
10
12
  import { ChevronLeftIcon, ChevronRightIcon, CloseIcon, PlusIcon } from "@dou-ui/icons";
11
13
  // src/components/tabs/tabs.vue?vue&type=script&setup=true&lang.ts
12
14
  var _hoisted_1 = ["disabled", "aria-label"];
@@ -20,11 +22,13 @@ var _hoisted_3 = [
20
22
  "tabindex",
21
23
  "aria-keyshortcuts",
22
24
  "onClick",
25
+ "onPointerdown",
23
26
  "onKeydown"
24
27
  ];
25
28
  var _hoisted_4 = ["onClick"];
26
29
  var _hoisted_5 = ["disabled", "aria-label"];
27
30
  var _hoisted_6 = ["aria-label"];
31
+ var ARROWS_MIN_WIDTH = 160;
28
32
  var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
29
33
  name: "DouTabs",
30
34
  __name: "tabs",
@@ -46,7 +50,13 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
46
50
  type: Boolean,
47
51
  default: false
48
52
  },
49
- beforeLeave: {}
53
+ beforeLeave: {},
54
+ draggable: {
55
+ type: Boolean,
56
+ default: false
57
+ },
58
+ group: {},
59
+ name: {}
50
60
  }, {
51
61
  "modelValue": {},
52
62
  "modelModifiers": {}
@@ -54,7 +64,8 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
54
64
  emits: /*@__PURE__*/ mergeModels([
55
65
  "change",
56
66
  "remove",
57
- "add"
67
+ "add",
68
+ "move"
58
69
  ], ["update:modelValue"]),
59
70
  setup(__props, { emit: __emit }) {
60
71
  const props = __props;
@@ -73,14 +84,20 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
73
84
  function unregister(uid) {
74
85
  panels.value = panels.value.filter((entry) => entry.uid !== uid);
75
86
  }
76
- function reorder() {
87
+ /** Put the panels in their order on the page; whether that changed anything. */
88
+ function sync() {
77
89
  const sorted = [...panels.value].sort((a, b) => {
78
90
  if (!a.el.value || !b.el.value) return 0;
79
91
  return a.el.value.compareDocumentPosition(b.el.value) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
80
92
  });
81
- if (sorted.some((entry, index) => entry !== panels.value[index])) panels.value = sorted;
82
- else triggerRef(panels);
93
+ if (!sorted.some((entry, index) => entry !== panels.value[index])) return false;
94
+ panels.value = sorted;
95
+ return true;
83
96
  }
97
+ function reorder() {
98
+ if (!sync()) triggerRef(panels);
99
+ }
100
+ onUpdated(sync);
84
101
  const firstEnabled = computed(() => panels.value.find((entry) => !entry.props.disabled));
85
102
  const selected = computed(() => model.value ?? firstEnabled.value?.props.value);
86
103
  const key = (value) => String(value).replace(/\s+/g, "-");
@@ -95,8 +112,11 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
95
112
  reorder
96
113
  });
97
114
  async function select(entry) {
98
- if (entry.props.disabled || entry.props.value === selected.value) return;
99
- const next = entry.props.value;
115
+ if (entry.props.disabled) return;
116
+ await selectValue(entry.props.value);
117
+ }
118
+ async function selectValue(next) {
119
+ if (next === selected.value) return;
100
120
  if (props.beforeLeave && !await props.beforeLeave(next, selected.value)) return;
101
121
  model.value = next;
102
122
  emit("change", next);
@@ -106,6 +126,7 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
106
126
  if (isClosable(entry)) emit("remove", entry.props.value);
107
127
  }
108
128
  const listRef = useTemplateRef("list");
129
+ const headerRef = useTemplateRef("header");
109
130
  const tabElements = /* @__PURE__ */ new Map();
110
131
  function setTabElement(uid, el) {
111
132
  if (el instanceof HTMLElement) tabElements.set(uid, el);
@@ -133,6 +154,7 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
133
154
  placement: tipPlacement.value
134
155
  }, tip) : tip.default?.();
135
156
  function onKeydown(event, entry) {
157
+ if (event.altKey && isDraggable(entry) && moveByKey(event, entry)) return;
136
158
  const enabled = panels.value.filter((panel) => !panel.props.disabled);
137
159
  const index = enabled.indexOf(entry);
138
160
  let target;
@@ -168,6 +190,176 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
168
190
  tabElement(target)?.focus();
169
191
  if (props.activation === "auto") select(target);
170
192
  }
193
+ const isDraggable = (entry) => !entry.props.disabled && (entry.props.draggable ?? props.draggable);
194
+ /** This instance, to tell a move within the tabs from one that comes from other tabs. */
195
+ const self = {};
196
+ const draggingUid = ref(null);
197
+ let clickBlocked = false;
198
+ function onClick(entry) {
199
+ if (clickBlocked) return;
200
+ select(entry);
201
+ }
202
+ function onPointerdown(event, entry) {
203
+ if (!isDraggable(entry) || event.target.closest(`.${ns.e("close")}`)) return;
204
+ const el = tabElement(entry);
205
+ if (!el) return;
206
+ pressTab(event, {
207
+ el,
208
+ root: listRef.value,
209
+ drag: () => ({
210
+ value: entry.props.value,
211
+ label: labelText(entry),
212
+ group: props.group,
213
+ name: props.name,
214
+ index: panels.value.indexOf(entry),
215
+ source: self
216
+ }),
217
+ onStart: () => draggingUid.value = entry.uid,
218
+ onEnd: () => {
219
+ draggingUid.value = null;
220
+ clickBlocked = true;
221
+ setTimeout(() => clickBlocked = false);
222
+ }
223
+ });
224
+ }
225
+ /** Where a tab dropped now would go: before the tab at `index`, or after the last. */
226
+ const marker = ref(null);
227
+ function insertionAt(x, y) {
228
+ const entries = panels.value;
229
+ const index = entries.findIndex((entry) => {
230
+ const rect = tabElement(entry)?.getBoundingClientRect();
231
+ if (!rect) return false;
232
+ return vertical.value ? y < rect.top + rect.height / 2 : x < rect.left + rect.width / 2;
233
+ });
234
+ return index < 0 ? entries.length : index;
235
+ }
236
+ /** Whether dropping there leaves the tab where it is. */
237
+ const stays = (drag, index) => drag.source === self && (index === drag.index || index === drag.index + 1);
238
+ function markerOffset(index) {
239
+ const entries = panels.value;
240
+ const style = getComputedStyle(listRef.value);
241
+ const gap = Number.parseFloat(vertical.value ? style.rowGap : style.columnGap) || 0;
242
+ const before = entries[index] && tabElement(entries[index]);
243
+ if (before) return (vertical.value ? before.offsetTop : before.offsetLeft) - gap / 2;
244
+ const last = entries.at(-1);
245
+ const after = last && tabElement(last);
246
+ if (!after) return 0;
247
+ return vertical.value ? after.offsetTop + after.offsetHeight + gap / 2 : after.offsetLeft + after.offsetWidth + gap / 2;
248
+ }
249
+ /** Scroll a row that does not fit while the pointer is near one of its ends. */
250
+ function scrollNearEdge(x, y) {
251
+ const list = listRef.value;
252
+ if (!list) return;
253
+ const rect = list.getBoundingClientRect();
254
+ const EDGE = 32;
255
+ const speed = (d) => Math.ceil((EDGE - Math.max(0, d)) / EDGE * 10);
256
+ const [pos, startEdge, endEdge] = vertical.value ? [
257
+ y,
258
+ rect.top,
259
+ rect.bottom
260
+ ] : [
261
+ x,
262
+ rect.left,
263
+ rect.right
264
+ ];
265
+ let delta = 0;
266
+ if (pos - startEdge < EDGE) delta = -speed(pos - startEdge);
267
+ else if (endEdge - pos < EDGE) delta = speed(endEdge - pos);
268
+ if (!delta) return;
269
+ if (vertical.value) list.scrollTop += delta;
270
+ else list.scrollLeft += delta;
271
+ }
272
+ const dropZone = registerTabDropZone({
273
+ el: () => headerRef.value,
274
+ accepts: (drag) => drag.source === self || props.draggable && !!props.group && drag.group === props.group,
275
+ over(drag, x, y) {
276
+ scrollNearEdge(x, y);
277
+ const index = insertionAt(x, y);
278
+ if (stays(drag, index)) {
279
+ marker.value = null;
280
+ return;
281
+ }
282
+ const list = listRef.value;
283
+ const end = (vertical.value ? list.scrollHeight : list.scrollWidth) - 2;
284
+ const at = Math.min(Math.max(markerOffset(index), 1), end);
285
+ if (marker.value?.index !== index || marker.value.at !== at) marker.value = {
286
+ index,
287
+ at
288
+ };
289
+ },
290
+ leave: () => marker.value = null,
291
+ drop(drag) {
292
+ const index = marker.value?.index;
293
+ marker.value = null;
294
+ if (index === void 0) return;
295
+ const within = drag.source === self;
296
+ emit("move", {
297
+ value: drag.value,
298
+ from: {
299
+ name: drag.name,
300
+ index: drag.index
301
+ },
302
+ to: {
303
+ name: props.name,
304
+ index: within && index > drag.index ? index - 1 : index
305
+ }
306
+ });
307
+ selectValue(drag.value);
308
+ }
309
+ });
310
+ onMounted(() => {
311
+ dropZone.update();
312
+ if (process.env.NODE_ENV !== "production" && props.group && props.name === void 0) devWarn(`[dou-ui] DouTabs: tabs in the group "${props.group}" need a \`name\`; \`move\` cannot tell which tabs a tab came from without it.`);
313
+ });
314
+ onUpdated(() => dropZone.update());
315
+ onBeforeUnmount(() => dropZone.remove());
316
+ const markerStyle = computed(() => {
317
+ const at = marker.value?.at;
318
+ if (at === void 0) return { display: "none" };
319
+ return { transform: vertical.value ? `translateY(${at}px)` : `translateX(${at}px)` };
320
+ });
321
+ /** A tab moved with the keyboard keeps the focus once it is in its new place. */
322
+ let focusAfterMove;
323
+ function moveByKey(event, entry) {
324
+ const [prev, next] = vertical.value ? ["ArrowUp", "ArrowDown"] : ["ArrowLeft", "ArrowRight"];
325
+ const entries = panels.value;
326
+ const index = entries.indexOf(entry);
327
+ const last = entries.length - 1;
328
+ const target = event.key === prev ? index - 1 : event.key === next ? index + 1 : event.key === "Home" ? 0 : event.key === "End" ? last : null;
329
+ if (target === null) return false;
330
+ event.preventDefault();
331
+ if (target < 0 || target > last || target === index) return true;
332
+ focusAfterMove = entry.props.value;
333
+ emit("move", {
334
+ value: entry.props.value,
335
+ from: {
336
+ name: props.name,
337
+ index
338
+ },
339
+ to: {
340
+ name: props.name,
341
+ index: target
342
+ }
343
+ });
344
+ announce(t("tabs.moved", {
345
+ label: labelText(entry),
346
+ position: target + 1,
347
+ total: entries.length
348
+ }));
349
+ return true;
350
+ }
351
+ watch(panels, () => {
352
+ if (focusAfterMove === void 0) return;
353
+ const entry = panels.value.find((panel) => panel.props.value === focusAfterMove);
354
+ focusAfterMove = void 0;
355
+ const el = entry && tabElement(entry);
356
+ if (el && document.activeElement !== el) el.focus();
357
+ }, { flush: "post" });
358
+ const moveKeys = computed(() => vertical.value ? "Alt+ArrowUp Alt+ArrowDown Alt+Home Alt+End" : "Alt+ArrowLeft Alt+ArrowRight Alt+Home Alt+End");
359
+ function keyShortcuts(entry) {
360
+ const keys = [isClosable(entry) && "Delete", isDraggable(entry) && moveKeys.value].filter(Boolean);
361
+ return keys.length ? keys.join(" ") : void 0;
362
+ }
171
363
  const indicator = ref(null);
172
364
  const settled = ref(false);
173
365
  function measure() {
@@ -190,7 +382,10 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
190
382
  end: false
191
383
  });
192
384
  const reduced = useReducedMotion();
385
+ const arrows = ref(true);
193
386
  function updateOverflow() {
387
+ const width = headerRef.value?.clientWidth || Infinity;
388
+ arrows.value = width >= ARROWS_MIN_WIDTH;
194
389
  const list = listRef.value;
195
390
  if (!list) {
196
391
  overflow.value = {
@@ -297,11 +492,15 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
297
492
  unref(ns).is("vertical", vertical.value),
298
493
  vertical.value && unref(ns).is(`placement-${__props.placement}`, true),
299
494
  unref(ns).is("fixed", __props.height !== void 0),
300
- unref(ns).is("icon-only", __props.iconOnly)
495
+ unref(ns).is("icon-only", __props.iconOnly),
496
+ unref(ns).is("drop-target", !!marker.value)
301
497
  ]),
302
498
  style: normalizeStyle(rootStyle.value)
303
- }, [createElementVNode("div", { class: normalizeClass(unref(ns).e("header")) }, [
304
- !vertical.value && (overflow.value.start || overflow.value.end) ? (openBlock(), createElementBlock("button", {
499
+ }, [createElementVNode("div", {
500
+ ref: "header",
501
+ class: normalizeClass(unref(ns).e("header"))
502
+ }, [
503
+ !vertical.value && arrows.value && (overflow.value.start || overflow.value.end) ? (openBlock(), createElementBlock("button", {
305
504
  key: 0,
306
505
  type: "button",
307
506
  tabindex: "-1",
@@ -320,67 +519,79 @@ var tabs_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
320
519
  role: "tablist",
321
520
  "aria-orientation": vertical.value ? "vertical" : "horizontal",
322
521
  onScrollPassive: updateOverflow
323
- }, [(openBlock(true), createElementBlock(Fragment, null, renderList(panels.value, (entry) => {
324
- return openBlock(), createBlock(TabTip, {
325
- key: entry.uid,
326
- entry
327
- }, {
328
- default: withCtx(() => [createElementVNode("button", {
329
- id: tabId(entry.props.value),
330
- ref_for: true,
331
- ref: (el) => setTabElement(entry.uid, el),
332
- type: "button",
333
- role: "tab",
334
- class: normalizeClass([
335
- unref(ns).e("tab"),
336
- unref(ns).is("selected", entry.props.value === selected.value),
337
- unref(ns).is("disabled", !!entry.props.disabled),
338
- unref(ns).is("closable", isClosable(entry)),
339
- unref(ns).is("icon-alone", iconAlone(entry))
340
- ]),
341
- "aria-selected": entry.props.value === selected.value,
342
- "aria-controls": panelId(entry.props.value),
343
- "aria-label": iconAlone(entry) ? labelText(entry) : void 0,
344
- "aria-disabled": entry.props.disabled || void 0,
345
- tabindex: entry.props.value === selected.value ? 0 : -1,
346
- "aria-keyshortcuts": isClosable(entry) ? "Delete" : void 0,
347
- onClick: ($event) => select(entry),
348
- onKeydown: ($event) => onKeydown($event, entry)
349
- }, [
350
- entry.props.icon ? (openBlock(), createBlock(resolveDynamicComponent(entry.props.icon), {
351
- key: 0,
352
- class: normalizeClass(unref(ns).e("icon")),
353
- "aria-hidden": "true"
354
- }, null, 8, ["class"])) : createCommentVNode("", true),
355
- !iconAlone(entry) ? (openBlock(), createElementBlock("span", {
356
- key: 1,
357
- class: normalizeClass(unref(ns).e("label"))
358
- }, [createVNode(TabLabel, {
359
- entry,
360
- selected: entry.props.value === selected.value
361
- }, null, 8, ["entry", "selected"])], 2)) : createCommentVNode("", true),
362
- isClosable(entry) ? (openBlock(), createBlock(unref(DouTooltip), {
363
- key: 2,
364
- content: unref(t)("tabs.close"),
365
- shortcut: "delete",
366
- disabled: iconAlone(entry)
367
- }, {
368
- default: withCtx(() => [createElementVNode("span", {
369
- class: normalizeClass(unref(ns).e("close")),
370
- "aria-hidden": "true",
371
- onClick: withModifiers(($event) => remove(entry), ["stop"])
372
- }, [createVNode(unref(CloseIcon))], 10, _hoisted_4)]),
373
- _: 2
374
- }, 1032, ["content", "disabled"])) : createCommentVNode("", true)
375
- ], 42, _hoisted_3)]),
376
- _: 2
377
- }, 1032, ["entry"]);
378
- }), 128)), createElementVNode("span", {
379
- class: normalizeClass(unref(ns).e("indicator")),
380
- style: normalizeStyle(indicatorStyle.value),
381
- "aria-hidden": "true"
382
- }, null, 6)], 42, _hoisted_2),
383
- !vertical.value && (overflow.value.start || overflow.value.end) ? (openBlock(), createElementBlock("button", {
522
+ }, [
523
+ (openBlock(true), createElementBlock(Fragment, null, renderList(panels.value, (entry) => {
524
+ return openBlock(), createBlock(TabTip, {
525
+ key: entry.uid,
526
+ entry
527
+ }, {
528
+ default: withCtx(() => [createElementVNode("button", {
529
+ id: tabId(entry.props.value),
530
+ ref_for: true,
531
+ ref: (el) => setTabElement(entry.uid, el),
532
+ type: "button",
533
+ role: "tab",
534
+ class: normalizeClass([
535
+ unref(ns).e("tab"),
536
+ unref(ns).is("selected", entry.props.value === selected.value),
537
+ unref(ns).is("disabled", !!entry.props.disabled),
538
+ unref(ns).is("closable", isClosable(entry)),
539
+ unref(ns).is("icon-alone", iconAlone(entry)),
540
+ unref(ns).is("draggable", isDraggable(entry)),
541
+ unref(ns).is("dragging", draggingUid.value === entry.uid)
542
+ ]),
543
+ "aria-selected": entry.props.value === selected.value,
544
+ "aria-controls": panelId(entry.props.value),
545
+ "aria-label": iconAlone(entry) ? labelText(entry) : void 0,
546
+ "aria-disabled": entry.props.disabled || void 0,
547
+ tabindex: entry.props.value === selected.value ? 0 : -1,
548
+ "aria-keyshortcuts": keyShortcuts(entry),
549
+ onClick: ($event) => onClick(entry),
550
+ onPointerdown: ($event) => onPointerdown($event, entry),
551
+ onKeydown: ($event) => onKeydown($event, entry)
552
+ }, [
553
+ entry.props.icon ? (openBlock(), createBlock(resolveDynamicComponent(entry.props.icon), {
554
+ key: 0,
555
+ class: normalizeClass(unref(ns).e("icon")),
556
+ "aria-hidden": "true"
557
+ }, null, 8, ["class"])) : createCommentVNode("", true),
558
+ !iconAlone(entry) ? (openBlock(), createElementBlock("span", {
559
+ key: 1,
560
+ class: normalizeClass(unref(ns).e("label"))
561
+ }, [createVNode(TabLabel, {
562
+ entry,
563
+ selected: entry.props.value === selected.value
564
+ }, null, 8, ["entry", "selected"])], 2)) : createCommentVNode("", true),
565
+ isClosable(entry) ? (openBlock(), createBlock(unref(DouTooltip), {
566
+ key: 2,
567
+ content: unref(t)("tabs.close"),
568
+ shortcut: "delete",
569
+ disabled: iconAlone(entry)
570
+ }, {
571
+ default: withCtx(() => [createElementVNode("span", {
572
+ class: normalizeClass(unref(ns).e("close")),
573
+ "aria-hidden": "true",
574
+ onClick: withModifiers(($event) => remove(entry), ["stop"])
575
+ }, [createVNode(unref(CloseIcon))], 10, _hoisted_4)]),
576
+ _: 2
577
+ }, 1032, ["content", "disabled"])) : createCommentVNode("", true)
578
+ ], 42, _hoisted_3)]),
579
+ _: 2
580
+ }, 1032, ["entry"]);
581
+ }), 128)),
582
+ createElementVNode("span", {
583
+ class: normalizeClass(unref(ns).e("indicator")),
584
+ style: normalizeStyle(indicatorStyle.value),
585
+ "aria-hidden": "true"
586
+ }, null, 6),
587
+ __props.draggable ? (openBlock(), createElementBlock("span", {
588
+ key: 0,
589
+ class: normalizeClass(unref(ns).e("marker")),
590
+ style: normalizeStyle(markerStyle.value),
591
+ "aria-hidden": "true"
592
+ }, null, 6)) : createCommentVNode("", true)
593
+ ], 42, _hoisted_2),
594
+ !vertical.value && arrows.value && (overflow.value.start || overflow.value.end) ? (openBlock(), createElementBlock("button", {
384
595
  key: 1,
385
596
  type: "button",
386
597
  tabindex: "-1",