dou-ui 0.1.0-alpha.5 → 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,121 @@
1
+ // src/components/dock/layout.ts
2
+ function groups(node) {
3
+ return node.type === "group" ? [node] : [...groups(node.start), ...groups(node.end)];
4
+ }
5
+ /** The group a tab is in. */
6
+ function findDockGroup(layout, value) {
7
+ return groups(layout).find((group) => group.tabs.includes(value));
8
+ }
9
+ /** The groups of a layout, from the top left. */
10
+ function dockGroups(layout) {
11
+ return groups(layout);
12
+ }
13
+ /** An id that no group of the layout has yet, `group-1`, `group-2`… */
14
+ function nextDockGroupId(layout) {
15
+ const ids = new Set(groups(layout).map((group) => group.id));
16
+ let n = 1;
17
+ while (ids.has(`group-${n}`)) n++;
18
+ return `group-${n}`;
19
+ }
20
+ /** Replace the nodes `map` returns something new for, keeping the rest. */
21
+ function mapNode(node, map) {
22
+ const own = map(node);
23
+ if (own !== node) return own;
24
+ if (node.type === "group") return node;
25
+ const start = mapNode(node.start, map);
26
+ const end = mapNode(node.end, map);
27
+ if (start === node.start && end === node.end) return node;
28
+ if (!start) return end;
29
+ if (!end) return start;
30
+ return {
31
+ ...node,
32
+ start,
33
+ end
34
+ };
35
+ }
36
+ /** Take a tab out of its group, dropping the group once it is empty. */
37
+ function takeOut(layout, value, keep) {
38
+ return mapNode(layout, (node) => {
39
+ if (node.type !== "group" || !node.tabs.includes(value)) return node;
40
+ const index = node.tabs.indexOf(value);
41
+ const tabs = node.tabs.filter((tab) => tab !== value);
42
+ if (!tabs.length && node.id !== keep) return null;
43
+ const active = node.active === value ? tabs[Math.min(index, tabs.length - 1)] ?? void 0 : node.active;
44
+ return {
45
+ ...node,
46
+ tabs,
47
+ active
48
+ };
49
+ });
50
+ }
51
+ /** A layout with nothing left in it keeps one empty group. */
52
+ var orEmpty = (layout, id) => layout ?? {
53
+ type: "group",
54
+ id,
55
+ tabs: []
56
+ };
57
+ /**
58
+ * Move a tab to a group, at `index` (counted without the tab itself) or
59
+ * at the end, and select it there. The group it leaves is dropped once
60
+ * it is empty. Returns a new layout; the one passed in is not changed.
61
+ */
62
+ function moveDockTab(layout, value, groupId, index) {
63
+ if (!groups(layout).find((group) => group.id === groupId)) return layout;
64
+ return mapNode(orEmpty(takeOut(layout, value, groupId), groupId), (node) => {
65
+ if (node.type !== "group" || node.id !== groupId) return node;
66
+ const tabs = [...node.tabs];
67
+ tabs.splice(Math.min(Math.max(index ?? tabs.length, 0), tabs.length), 0, value);
68
+ return {
69
+ ...node,
70
+ tabs,
71
+ active: value
72
+ };
73
+ });
74
+ }
75
+ /**
76
+ * Split a tab off to one side of a group, into a new group of its own
77
+ * that takes half of the group's place. Returns a new layout.
78
+ */
79
+ function splitDockTab(layout, value, groupId, side, newId = nextDockGroupId(layout)) {
80
+ const target = groups(layout).find((group) => group.id === groupId);
81
+ if (!target || target.tabs.length === 1 && target.tabs[0] === value) return layout;
82
+ const taken = takeOut(layout, value, groupId);
83
+ const added = {
84
+ type: "group",
85
+ id: newId,
86
+ tabs: [value],
87
+ active: value
88
+ };
89
+ return mapNode(orEmpty(taken, groupId), (node) => {
90
+ if (node.type !== "group" || node.id !== groupId) return node;
91
+ const direction = side === "left" || side === "right" ? "horizontal" : "vertical";
92
+ const first = side === "left" || side === "top";
93
+ return {
94
+ type: "split",
95
+ direction,
96
+ size: 50,
97
+ start: first ? added : node,
98
+ end: first ? node : added
99
+ };
100
+ });
101
+ }
102
+ /** Remove a tab, dropping its group once it is empty. Returns a new layout. */
103
+ function removeDockTab(layout, value) {
104
+ const group = findDockGroup(layout, value);
105
+ if (!group) return layout;
106
+ return orEmpty(takeOut(layout, value), group.id);
107
+ }
108
+ /** Select a tab in its group. Returns a new layout. */
109
+ function selectDockTab(layout, value) {
110
+ return mapNode(layout, (node) => node.type === "group" && node.tabs.includes(value) && node.active !== value ? {
111
+ ...node,
112
+ active: value
113
+ } : node);
114
+ }
115
+ /** Replace one node of the layout, found by identity. */
116
+ function replaceDockNode(layout, node, next) {
117
+ return mapNode(layout, (current) => current === node ? next : current);
118
+ }
119
+ export { dockGroups, findDockGroup, moveDockTab, nextDockGroupId, removeDockTab, replaceDockNode, selectDockTab, splitDockTab };
120
+
121
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.js","names":[],"sources":["../../../src/components/dock/layout.ts"],"sourcesContent":["import type { TabsValue } from '../tabs/tabs'\n\n/** Two parts side by side or stacked, as a `DouSplitter` shows them. */\nexport interface DockSplit {\n type: 'split'\n /** `horizontal` puts `start` and `end` side by side; `vertical` stacks them. */\n direction: 'horizontal' | 'vertical'\n /** The size of `start` in percent. Defaults to 50. */\n size?: number\n start: DockNode\n end: DockNode\n}\n\n/** A group of tabs, shown as one `DouTabs`. */\nexport interface DockGroup {\n type: 'group'\n id: string\n /** The values of its tabs, in order. */\n tabs: TabsValue[]\n /** The selected tab. Defaults to the first. */\n active?: TabsValue\n}\n\nexport type DockNode = DockSplit | DockGroup\n\n/** The side of a group a tab is split off to. */\nexport type DockSide = 'top' | 'right' | 'bottom' | 'left'\n\nfunction groups(node: DockNode): DockGroup[] {\n return node.type === 'group' ? [node] : [...groups(node.start), ...groups(node.end)]\n}\n\n/** The group a tab is in. */\nexport function findDockGroup(layout: DockNode, value: TabsValue) {\n return groups(layout).find((group) => group.tabs.includes(value))\n}\n\n/** The groups of a layout, from the top left. */\nexport function dockGroups(layout: DockNode) {\n return groups(layout)\n}\n\n/** An id that no group of the layout has yet, `group-1`, `group-2`… */\nexport function nextDockGroupId(layout: DockNode) {\n const ids = new Set(groups(layout).map((group) => group.id))\n let n = 1\n while (ids.has(`group-${n}`)) n++\n return `group-${n}`\n}\n\n/** Replace the nodes `map` returns something new for, keeping the rest. */\nfunction mapNode(node: DockNode, map: (node: DockNode) => DockNode | null): DockNode | null {\n const own = map(node)\n if (own !== node) return own\n if (node.type === 'group') return node\n const start = mapNode(node.start, map)\n const end = mapNode(node.end, map)\n if (start === node.start && end === node.end) return node\n // a split with one side gone is the other side\n if (!start) return end\n if (!end) return start\n return { ...node, start, end }\n}\n\n/** Take a tab out of its group, dropping the group once it is empty. */\nfunction takeOut(layout: DockNode, value: TabsValue, keep?: string): DockNode | null {\n return mapNode(layout, (node) => {\n if (node.type !== 'group' || !node.tabs.includes(value)) return node\n const index = node.tabs.indexOf(value)\n const tabs = node.tabs.filter((tab) => tab !== value)\n if (!tabs.length && node.id !== keep) return null\n const active =\n node.active === value ? (tabs[Math.min(index, tabs.length - 1)] ?? undefined) : node.active\n return { ...node, tabs, active }\n })\n}\n\n/** A layout with nothing left in it keeps one empty group. */\nconst orEmpty = (layout: DockNode | null, id: string): DockNode =>\n layout ?? { type: 'group', id, tabs: [] }\n\n/**\n * Move a tab to a group, at `index` (counted without the tab itself) or\n * at the end, and select it there. The group it leaves is dropped once\n * it is empty. Returns a new layout; the one passed in is not changed.\n */\nexport function moveDockTab(\n layout: DockNode,\n value: TabsValue,\n groupId: string,\n index?: number,\n): DockNode {\n const target = groups(layout).find((group) => group.id === groupId)\n if (!target) return layout\n const taken = takeOut(layout, value, groupId)\n const next = mapNode(orEmpty(taken, groupId), (node) => {\n if (node.type !== 'group' || node.id !== groupId) return node\n const tabs = [...node.tabs]\n tabs.splice(Math.min(Math.max(index ?? tabs.length, 0), tabs.length), 0, value)\n return { ...node, tabs, active: value }\n })\n return next!\n}\n\n/**\n * Split a tab off to one side of a group, into a new group of its own\n * that takes half of the group's place. Returns a new layout.\n */\nexport function splitDockTab(\n layout: DockNode,\n value: TabsValue,\n groupId: string,\n side: DockSide,\n newId: string = nextDockGroupId(layout),\n): DockNode {\n const target = groups(layout).find((group) => group.id === groupId)\n // splitting a group's only tab off itself would leave it where it was\n if (!target || (target.tabs.length === 1 && target.tabs[0] === value)) return layout\n const taken = takeOut(layout, value, groupId)\n const added: DockGroup = { type: 'group', id: newId, tabs: [value], active: value }\n const next = mapNode(orEmpty(taken, groupId), (node) => {\n if (node.type !== 'group' || node.id !== groupId) return node\n const direction = side === 'left' || side === 'right' ? 'horizontal' : 'vertical'\n const first = side === 'left' || side === 'top'\n return {\n type: 'split',\n direction,\n size: 50,\n start: first ? added : node,\n end: first ? node : added,\n }\n })\n return next!\n}\n\n/** Remove a tab, dropping its group once it is empty. Returns a new layout. */\nexport function removeDockTab(layout: DockNode, value: TabsValue): DockNode {\n const group = findDockGroup(layout, value)\n if (!group) return layout\n return orEmpty(takeOut(layout, value), group.id)\n}\n\n/** Select a tab in its group. Returns a new layout. */\nexport function selectDockTab(layout: DockNode, value: TabsValue): DockNode {\n return mapNode(layout, (node) =>\n node.type === 'group' && node.tabs.includes(value) && node.active !== value\n ? { ...node, active: value }\n : node,\n )!\n}\n\n/** Replace one node of the layout, found by identity. */\nexport function replaceDockNode(layout: DockNode, node: DockNode, next: DockNode): DockNode {\n return mapNode(layout, (current) => (current === node ? next : current))!\n}\n"],"mappings":";AA4BA,SAAS,OAAO,MAA6B;CAC3C,OAAO,KAAK,SAAS,UAAU,CAAC,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,KAAK,GAAG,GAAG,OAAO,KAAK,GAAG,CAAC;AACrF;;AAGA,SAAgB,cAAc,QAAkB,OAAkB;CAChE,OAAO,OAAO,MAAM,CAAC,CAAC,MAAM,UAAU,MAAM,KAAK,SAAS,KAAK,CAAC;AAClE;;AAGA,SAAgB,WAAW,QAAkB;CAC3C,OAAO,OAAO,MAAM;AACtB;;AAGA,SAAgB,gBAAgB,QAAkB;CAChD,MAAM,MAAM,IAAI,IAAI,OAAO,MAAM,CAAC,CAAC,KAAK,UAAU,MAAM,EAAE,CAAC;CAC3D,IAAI,IAAI;CACR,OAAO,IAAI,IAAI,SAAS,GAAG,GAAG;CAC9B,OAAO,SAAS;AAClB;;AAGA,SAAS,QA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AAa,YAAY,OAAO,OAAO,OAAQ;AACzE"}
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,7 @@
1
+ import '@dou-ui/theme/core.css'
2
+ import '@dou-ui/theme/components/overlay.css'
3
+ import '@dou-ui/theme/components/dock.css'
4
+ import '@dou-ui/theme/components/kbd.css'
5
+ import '@dou-ui/theme/components/splitter.css'
6
+ import '@dou-ui/theme/components/tabs.css'
7
+ import '@dou-ui/theme/components/tooltip.css'
@@ -0,0 +1,5 @@
1
+ // src/components/splitter/context.ts
2
+ var splitterContextKey = Symbol("DouSplitter");
3
+ export { splitterContextKey };
4
+
5
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":[],"sources":["../../../src/components/splitter/context.ts"],"sourcesContent":["import type { InjectionKey } from 'vue'\n\n/** The least room a splitter needs, in px, for its own px limits and those of splitters inside it. */\nexport interface SplitterMinSize {\n width: number\n height: number\n}\n\n/** How a splitter tells the one around it what it needs, so px limits hold however deep it sits. */\nexport interface SplitterContext {\n register: (el: HTMLElement, need: () => SplitterMinSize) => () => void\n}\n\nexport const splitterContextKey: InjectionKey<SplitterContext> = Symbol('DouSplitter')\n"],"mappings":";AAaA,IAAa,qBAAoD,OAAO,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"splitter.js","names":["_sfc_main"],"sources":["../../../src/components/splitter/splitter.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, ref, useId, useTemplateRef } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport type { SplitterLimit, SplitterProps, SplitterSlots } from './splitter'\n\ndefineOptions({ name: 'DouSplitter' })\n\nconst props = withDefaults(defineProps<SplitterProps>(), {\n direction: 'horizontal',\n min: 0,\n max: 100,\n collapsible: false,\n step: 1,\n disabled: false,\n})\nconst size = defineModel<number>({ default: 50 })\nconst collapsed = defineModel<boolean>('collapsed', { default: false })\nconst emit = defineEmits<{ change: [value: number] }>()\ndefineSlots<SplitterSlots>()\n\nconst ns = useNamespace('splitter')\nconst { t } = useLocale()\nconst startId = `dou-splitter-${useId()}-start`\nconst root = useTemplateRef<HTMLElement>('root')\n\nconst horizontal = computed(() => props.direction === 'horizontal')\nconst length = () => {\n const rect = root.value?.getBoundingClientRect()\n return (horizontal.value ? rect?.width : rect?.height) || 0\n}\nfunction toPercent(limit: SplitterLimit) {\n if (typeof limit === 'number') return limit\n const total = length()\n return total ? (Number.parseFloat(limit) / total) * 100 : 0\n}\nconst bounds = () => {\n const min = Math.max(0, toPercent(props.min))\n return { min, max: Math.max(min, Math.min(100, toPercent(props.max))) }\n}\nconst round = (value: number) => Math.round(value * 100) / 100\nfunction clamp(value: number) {\n const { min, max } = bounds()\n return round(Math.min(max, Math.max(min, value)))\n}\n\nfunction set(value: number) {\n const next = clamp(value)\n if (collapsed.value) collapsed.value = false\n if (next !== size.value) size.value = next\n}\n\nfunction toggle() {\n if (!props.collapsible || props.disabled) return\n collapsed.value = !collapsed.value\n emit('change', size.value)\n}\n\n/* dragging */\n\nconst dragging = ref(false)\nfunction onPointerdown(event: PointerEvent) {\n if (props.disabled || event.button !== 0) return\n event.preventDefault()\n ;(event.currentTarget as HTMLElement).setPointerCapture?.(event.pointerId)\n ;(event.currentTarget as HTMLElement).focus()\n dragging.value = true\n}\nfunction onPointermove(event: PointerEvent) {\n if (!dragging.value || !root.value) return\n const rect = root.value.getBoundingClientRect()\n const total = horizontal.value ? rect.width : rect.height\n if (!total) return\n const at = horizontal.value ? event.clientX - rect.left : event.clientY - rect.top\n set((at / total) * 100)\n}\nfunction onPointerup() {\n if (!dragging.value) return\n dragging.value = false\n emit('change', size.value)\n}\n\n/* keys */\n\nfunction onKeydown(event: KeyboardEvent) {\n if (props.disabled) return\n const step = props.step * (event.shiftKey ? 10 : 1)\n const back = horizontal.value ? 'ArrowLeft' : 'ArrowUp'\n const forth = horizontal.value ? 'ArrowRight' : 'ArrowDown'\n const current = collapsed.value ? 0 : size.value\n let next: number | undefined\n if (event.key === back) next = current - step\n else if (event.key === forth) next = current + step\n else if (event.key === 'Home') next = bounds().min\n else if (event.key === 'End') next = bounds().max\n else if (event.key === 'Enter' && props.collapsible) {\n event.preventDefault()\n return toggle()\n } else return\n event.preventDefault()\n set(next)\n emit('change', size.value)\n}\n\nconst shown = computed(() => (collapsed.value ? 0 : size.value))\nconst template = computed(\n () => `minmax(0, ${shown.value}fr) auto minmax(0, ${round(100 - shown.value)}fr)`,\n)\nconst style = computed(() =>\n horizontal.value ? { gridTemplateColumns: template.value } : { gridTemplateRows: template.value },\n)\nconst limits = computed(() => {\n // Read the px limits only once mounted; before that they count as 0.\n void size.value\n const { min, max } = root.value ? bounds() : { min: 0, max: 100 }\n return { min: Math.round(min), max: Math.round(max) }\n})\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[\n ns.b(),\n ns.m(direction),\n ns.is('dragging', dragging),\n ns.is('collapsed', collapsed),\n ns.is('disabled', disabled),\n ]\"\n :style=\"style\"\n >\n <div :id=\"startId\" :class=\"[ns.e('pane'), ns.is('start', true)]\">\n <slot name=\"start\" />\n </div>\n <div\n role=\"separator\"\n :class=\"ns.e('bar')\"\n :tabindex=\"disabled ? undefined : 0\"\n :aria-orientation=\"horizontal ? 'vertical' : 'horizontal'\"\n :aria-valuenow=\"Math.round(shown)\"\n :aria-valuemin=\"limits.min\"\n :aria-valuemax=\"limits.max\"\n :aria-controls=\"startId\"\n :aria-label=\"ariaLabel ?? t('splitter.label')\"\n :aria-disabled=\"disabled || undefined\"\n @pointerdown=\"onPointerdown\"\n @pointermove=\"onPointermove\"\n @pointerup=\"onPointerup\"\n @pointercancel=\"onPointerup\"\n @keydown=\"onKeydown\"\n @dblclick=\"toggle\"\n >\n <span :class=\"ns.e('handle')\" aria-hidden=\"true\" />\n </div>\n <div :class=\"[ns.e('pane'), ns.is('end', true)]\">\n <slot name=\"end\" />\n </div>\n </div>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"splitter.js","names":["_sfc_main"],"sources":["../../../src/components/splitter/splitter.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n inject,\n onBeforeUnmount,\n onMounted,\n provide,\n ref,\n shallowReactive,\n useId,\n useTemplateRef,\n watchEffect,\n} from 'vue'\nimport { useElementSize } from '../../composables/use-element-size'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport { splitterContextKey } from './context'\nimport type { SplitterMinSize } from './context'\nimport type { SplitterLimit, SplitterProps, SplitterSlots } from './splitter'\n\ndefineOptions({ name: 'DouSplitter' })\n\nconst props = withDefaults(defineProps<SplitterProps>(), {\n direction: 'horizontal',\n min: 0,\n max: 100,\n minEnd: 0,\n collapsible: false,\n step: 1,\n disabled: false,\n})\nconst size = defineModel<number>({ default: 50 })\nconst collapsed = defineModel<boolean>('collapsed', { default: false })\nconst emit = defineEmits<{ change: [value: number] }>()\ndefineSlots<SplitterSlots>()\n\nconst ns = useNamespace('splitter')\nconst { t } = useLocale()\nconst startId = `dou-splitter-${useId()}-start`\nconst root = useTemplateRef<HTMLElement>('root')\n\nconst horizontal = computed(() => props.direction === 'horizontal')\n// Kept up to date, so px limits still hold when the container resizes\nconst box = useElementSize(root, { box: 'border-box' })\n// the divider is a 1px line; the panes share the rest, so limits are a share of that\nconst BAR = 1\nconst length = () => Math.max(0, (horizontal.value ? box.width.value : box.height.value) - BAR)\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n for (const [name, limit] of [\n ['min', props.min],\n ['max', props.max],\n ['minEnd', props.minEnd],\n ] as const)\n if (typeof limit === 'string' && !/^\\s*\\d+(?:\\.\\d+)?px\\s*$/.test(limit))\n devWarn(\n `[dou-ui] DouSplitter: \\`${name}\\` is \"${limit}\"; use a number for percent or a length in px such as '240px'.`,\n )\n })\n\nconst px = (limit: SplitterLimit) => (typeof limit === 'string' ? Number.parseFloat(limit) || 0 : 0)\n// px as a percentage of the splitter, 0 until it is measured\nfunction share(value: number) {\n const total = length()\n return total ? (value / total) * 100 : 0\n}\nconst percent = (limit: SplitterLimit) => (typeof limit === 'number' ? limit : 0)\n\n/* splitters inside the panes: their px limits add up to a minimum for the pane */\n\nconst startPane = useTemplateRef<HTMLElement>('startPane')\nconst endPane = useTemplateRef<HTMLElement>('endPane')\nconst nested = shallowReactive(new Map<HTMLElement, () => SplitterMinSize>())\nprovide(splitterContextKey, {\n register(el, measureNeed) {\n nested.set(el, measureNeed)\n return () => nested.delete(el)\n },\n})\nfunction inside(pane: HTMLElement | null): SplitterMinSize {\n const need = { width: 0, height: 0 }\n for (const [el, measureNeed] of nested) {\n if (!pane?.contains(el)) continue\n const { width, height } = measureNeed()\n need.width = Math.max(need.width, width)\n need.height = Math.max(need.height, height)\n }\n return need\n}\nconst needs = computed(() => {\n const main = horizontal.value ? 'width' : 'height'\n const cross = horizontal.value ? 'height' : 'width'\n const start = inside(startPane.value)\n const end = inside(endPane.value)\n return {\n start: Math.max(px(props.min), start[main]),\n end: Math.max(px(props.minEnd), end[main]),\n cross: Math.max(collapsed.value ? 0 : start[cross], end[cross]),\n }\n})\nconst parent = inject(splitterContextKey, null)\nlet unregister: (() => void) | undefined\nonMounted(() => {\n unregister = root.value\n ? parent?.register(root.value, () => {\n const { start, end, cross } = needs.value\n const along = (collapsed.value ? 0 : start) + BAR + end\n return horizontal.value ? { width: along, height: cross } : { width: cross, height: along }\n })\n : undefined\n})\nonBeforeUnmount(() => unregister?.())\n\nconst bounds = () => {\n const min = Math.max(0, percent(props.min), share(needs.value.start))\n const end = Math.max(0, percent(props.minEnd), share(needs.value.end))\n // Too small for both minimums: they share the room in proportion\n if (min + end > 100) {\n const at = (min / (min + end)) * 100\n return { min: at, max: at }\n }\n const max = typeof props.max === 'number' ? props.max : share(px(props.max))\n return { min, max: Math.max(min, Math.min(100 - end, max)) }\n}\nconst round = (value: number) => Math.round(value * 100) / 100\nfunction clamp(value: number) {\n const { min, max } = bounds()\n const next = round(Math.min(max, Math.max(min, value)))\n // rounding must not push a pane below its minimum: round inwards at the limits\n if (next > max) return Math.floor(max * 100) / 100\n if (next < min) return Math.ceil(min * 100) / 100\n return next\n}\n\nfunction set(value: number) {\n const next = clamp(value)\n if (collapsed.value) collapsed.value = false\n if (next !== size.value) size.value = next\n}\n\nfunction toggle() {\n if (!props.collapsible || props.disabled) return\n collapsed.value = !collapsed.value\n emit('change', size.value)\n}\n\n/* dragging */\n\nconst dragging = ref(false)\nfunction onPointerdown(event: PointerEvent) {\n if (props.disabled || event.button !== 0) return\n event.preventDefault()\n ;(event.currentTarget as HTMLElement).setPointerCapture?.(event.pointerId)\n ;(event.currentTarget as HTMLElement).focus()\n dragging.value = true\n}\nfunction onPointermove(event: PointerEvent) {\n if (!dragging.value || !root.value) return\n const rect = root.value.getBoundingClientRect()\n const total = (horizontal.value ? rect.width : rect.height) - BAR\n if (total <= 0) return\n const at = (horizontal.value ? event.clientX - rect.left : event.clientY - rect.top) - BAR / 2\n set((at / total) * 100)\n}\nfunction onPointerup() {\n if (!dragging.value) return\n dragging.value = false\n emit('change', size.value)\n}\n\n/* keys */\n\nfunction onKeydown(event: KeyboardEvent) {\n if (props.disabled) return\n const step = props.step * (event.shiftKey ? 10 : 1)\n const back = horizontal.value ? 'ArrowLeft' : 'ArrowUp'\n const forth = horizontal.value ? 'ArrowRight' : 'ArrowDown'\n const current = shown.value\n let next: number | undefined\n if (event.key === back) next = current - step\n else if (event.key === forth) next = current + step\n else if (event.key === 'Home') next = bounds().min\n else if (event.key === 'End') next = bounds().max\n else if (event.key === 'Enter' && props.collapsible) {\n event.preventDefault()\n return toggle()\n } else return\n event.preventDefault()\n set(next)\n emit('change', size.value)\n}\n\n// What is on screen: the model value kept within the limits, which can\n// tighten as the container resizes. The model itself only changes when\n// someone moves the divider.\nconst shown = computed(() => {\n if (collapsed.value) return 0\n return clamp(size.value)\n})\nconst template = computed(\n () => `minmax(0, ${shown.value}fr) auto minmax(0, ${round(100 - shown.value)}fr)`,\n)\nconst style = computed(() =>\n horizontal.value ? { gridTemplateColumns: template.value } : { gridTemplateRows: template.value },\n)\nconst limits = computed(() => {\n // px limits count as 0 until the container is measured\n const { min, max } = bounds()\n return { min: Math.round(min), max: Math.round(max) }\n})\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[\n ns.b(),\n ns.m(direction),\n ns.is('dragging', dragging),\n ns.is('collapsed', collapsed),\n ns.is('disabled', disabled),\n ]\"\n :style=\"style\"\n >\n <div ref=\"startPane\" :id=\"startId\" :class=\"[ns.e('pane'), ns.is('start', true)]\">\n <slot name=\"start\" />\n </div>\n <div\n role=\"separator\"\n :class=\"ns.e('bar')\"\n :tabindex=\"disabled ? undefined : 0\"\n :aria-orientation=\"horizontal ? 'vertical' : 'horizontal'\"\n :aria-valuenow=\"Math.round(shown)\"\n :aria-valuemin=\"limits.min\"\n :aria-valuemax=\"limits.max\"\n :aria-controls=\"startId\"\n :aria-label=\"ariaLabel ?? t('splitter.label')\"\n :aria-disabled=\"disabled || undefined\"\n @pointerdown=\"onPointerdown\"\n @pointermove=\"onPointermove\"\n @pointerup=\"onPointerup\"\n @pointercancel=\"onPointerup\"\n @keydown=\"onKeydown\"\n @dblclick=\"toggle\"\n >\n <span :class=\"ns.e('handle')\" aria-hidden=\"true\" />\n </div>\n <div ref=\"endPane\" :class=\"[ns.e('pane'), ns.is('end', true)]\">\n <slot name=\"end\" />\n </div>\n </div>\n</template>\n"],"mappings":""}
@@ -1,6 +1,9 @@
1
1
  import { useNamespace } from "../../utils/namespace.js";
2
2
  import { useLocale } from "../config-provider/use-config.js";
3
- import { computed, createElementBlock, createElementVNode, defineComponent, mergeModels, normalizeClass, normalizeStyle, openBlock, ref, renderSlot, unref, useId, useModel, useTemplateRef } from "vue";
3
+ import { devWarn } from "../../utils/status-check.js";
4
+ import { useElementSize } from "../../composables/use-element-size.js";
5
+ import { splitterContextKey } from "./context.js";
6
+ import { computed, createElementBlock, createElementVNode, defineComponent, inject, mergeModels, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, provide, ref, renderSlot, shallowReactive, unref, useId, useModel, useTemplateRef, watchEffect } from "vue";
4
7
  // src/components/splitter/splitter.vue?vue&type=script&setup=true&lang.ts
5
8
  var _hoisted_1 = [
6
9
  "tabindex",
@@ -11,6 +14,7 @@ var _hoisted_1 = [
11
14
  "aria-label",
12
15
  "aria-disabled"
13
16
  ];
17
+ var BAR = 1;
14
18
  var splitter_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
15
19
  name: "DouSplitter",
16
20
  __name: "splitter",
@@ -19,6 +23,7 @@ var splitter_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
19
23
  direction: { default: "horizontal" },
20
24
  min: { default: 0 },
21
25
  max: { default: 100 },
26
+ minEnd: { default: 0 },
22
27
  collapsible: {
23
28
  type: Boolean,
24
29
  default: false
@@ -50,26 +55,91 @@ var splitter_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
50
55
  const startId = `dou-splitter-${useId()}-start`;
51
56
  const root = useTemplateRef("root");
52
57
  const horizontal = computed(() => props.direction === "horizontal");
53
- const length = () => {
54
- const rect = root.value?.getBoundingClientRect();
55
- return (horizontal.value ? rect?.width : rect?.height) || 0;
56
- };
57
- function toPercent(limit) {
58
- if (typeof limit === "number") return limit;
58
+ const box = useElementSize(root, { box: "border-box" });
59
+ const length = () => Math.max(0, (horizontal.value ? box.width.value : box.height.value) - BAR);
60
+ if (process.env.NODE_ENV !== "production") watchEffect(() => {
61
+ for (const [name, limit] of [
62
+ ["min", props.min],
63
+ ["max", props.max],
64
+ ["minEnd", props.minEnd]
65
+ ]) if (typeof limit === "string" && !/^\s*\d+(?:\.\d+)?px\s*$/.test(limit)) devWarn(`[dou-ui] DouSplitter: \`${name}\` is "${limit}"; use a number for percent or a length in px such as '240px'.`);
66
+ });
67
+ const px = (limit) => typeof limit === "string" ? Number.parseFloat(limit) || 0 : 0;
68
+ function share(value) {
59
69
  const total = length();
60
- return total ? Number.parseFloat(limit) / total * 100 : 0;
70
+ return total ? value / total * 100 : 0;
71
+ }
72
+ const percent = (limit) => typeof limit === "number" ? limit : 0;
73
+ const startPane = useTemplateRef("startPane");
74
+ const endPane = useTemplateRef("endPane");
75
+ const nested = shallowReactive(/* @__PURE__ */ new Map());
76
+ provide(splitterContextKey, { register(el, measureNeed) {
77
+ nested.set(el, measureNeed);
78
+ return () => nested.delete(el);
79
+ } });
80
+ function inside(pane) {
81
+ const need = {
82
+ width: 0,
83
+ height: 0
84
+ };
85
+ for (const [el, measureNeed] of nested) {
86
+ if (!pane?.contains(el)) continue;
87
+ const { width, height } = measureNeed();
88
+ need.width = Math.max(need.width, width);
89
+ need.height = Math.max(need.height, height);
90
+ }
91
+ return need;
61
92
  }
93
+ const needs = computed(() => {
94
+ const main = horizontal.value ? "width" : "height";
95
+ const cross = horizontal.value ? "height" : "width";
96
+ const start = inside(startPane.value);
97
+ const end = inside(endPane.value);
98
+ return {
99
+ start: Math.max(px(props.min), start[main]),
100
+ end: Math.max(px(props.minEnd), end[main]),
101
+ cross: Math.max(collapsed.value ? 0 : start[cross], end[cross])
102
+ };
103
+ });
104
+ const parent = inject(splitterContextKey, null);
105
+ let unregister;
106
+ onMounted(() => {
107
+ unregister = root.value ? parent?.register(root.value, () => {
108
+ const { start, end, cross } = needs.value;
109
+ const along = (collapsed.value ? 0 : start) + BAR + end;
110
+ return horizontal.value ? {
111
+ width: along,
112
+ height: cross
113
+ } : {
114
+ width: cross,
115
+ height: along
116
+ };
117
+ }) : void 0;
118
+ });
119
+ onBeforeUnmount(() => unregister?.());
62
120
  const bounds = () => {
63
- const min = Math.max(0, toPercent(props.min));
121
+ const min = Math.max(0, percent(props.min), share(needs.value.start));
122
+ const end = Math.max(0, percent(props.minEnd), share(needs.value.end));
123
+ if (min + end > 100) {
124
+ const at = min / (min + end) * 100;
125
+ return {
126
+ min: at,
127
+ max: at
128
+ };
129
+ }
130
+ const max = typeof props.max === "number" ? props.max : share(px(props.max));
64
131
  return {
65
132
  min,
66
- max: Math.max(min, Math.min(100, toPercent(props.max)))
133
+ max: Math.max(min, Math.min(100 - end, max))
67
134
  };
68
135
  };
69
136
  const round = (value) => Math.round(value * 100) / 100;
70
137
  function clamp(value) {
71
138
  const { min, max } = bounds();
72
- return round(Math.min(max, Math.max(min, value)));
139
+ const next = round(Math.min(max, Math.max(min, value)));
140
+ if (next > max) return Math.floor(max * 100) / 100;
141
+ if (next < min) return Math.ceil(min * 100) / 100;
142
+ return next;
73
143
  }
74
144
  function set(value) {
75
145
  const next = clamp(value);
@@ -92,9 +162,9 @@ var splitter_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
92
162
  function onPointermove(event) {
93
163
  if (!dragging.value || !root.value) return;
94
164
  const rect = root.value.getBoundingClientRect();
95
- const total = horizontal.value ? rect.width : rect.height;
96
- if (!total) return;
97
- set((horizontal.value ? event.clientX - rect.left : event.clientY - rect.top) / total * 100);
165
+ const total = (horizontal.value ? rect.width : rect.height) - BAR;
166
+ if (total <= 0) return;
167
+ set(((horizontal.value ? event.clientX - rect.left : event.clientY - rect.top) - BAR / 2) / total * 100);
98
168
  }
99
169
  function onPointerup() {
100
170
  if (!dragging.value) return;
@@ -106,7 +176,7 @@ var splitter_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
106
176
  const step = props.step * (event.shiftKey ? 10 : 1);
107
177
  const back = horizontal.value ? "ArrowLeft" : "ArrowUp";
108
178
  const forth = horizontal.value ? "ArrowRight" : "ArrowDown";
109
- const current = collapsed.value ? 0 : size.value;
179
+ const current = shown.value;
110
180
  let next;
111
181
  if (event.key === back) next = current - step;
112
182
  else if (event.key === forth) next = current + step;
@@ -120,15 +190,14 @@ var splitter_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
120
190
  set(next);
121
191
  emit("change", size.value);
122
192
  }
123
- const shown = computed(() => collapsed.value ? 0 : size.value);
193
+ const shown = computed(() => {
194
+ if (collapsed.value) return 0;
195
+ return clamp(size.value);
196
+ });
124
197
  const template = computed(() => `minmax(0, ${shown.value}fr) auto minmax(0, ${round(100 - shown.value)}fr)`);
125
198
  const style = computed(() => horizontal.value ? { gridTemplateColumns: template.value } : { gridTemplateRows: template.value });
126
199
  const limits = computed(() => {
127
- size.value;
128
- const { min, max } = root.value ? bounds() : {
129
- min: 0,
130
- max: 100
131
- };
200
+ const { min, max } = bounds();
132
201
  return {
133
202
  min: Math.round(min),
134
203
  max: Math.round(max)
@@ -148,6 +217,8 @@ var splitter_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
148
217
  style: normalizeStyle(style.value)
149
218
  }, [
150
219
  createElementVNode("div", {
220
+ ref_key: "startPane",
221
+ ref: startPane,
151
222
  id: startId,
152
223
  class: normalizeClass([unref(ns).e("pane"), unref(ns).is("start", true)])
153
224
  }, [renderSlot(_ctx.$slots, "start")], 2),
@@ -172,7 +243,11 @@ var splitter_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineC
172
243
  class: normalizeClass(unref(ns).e("handle")),
173
244
  "aria-hidden": "true"
174
245
  }, null, 2)], 42, _hoisted_1),
175
- createElementVNode("div", { class: normalizeClass([unref(ns).e("pane"), unref(ns).is("end", true)]) }, [renderSlot(_ctx.$slots, "end")], 2)
246
+ createElementVNode("div", {
247
+ ref_key: "endPane",
248
+ ref: endPane,
249
+ class: normalizeClass([unref(ns).e("pane"), unref(ns).is("end", true)])
250
+ }, [renderSlot(_ctx.$slots, "end")], 2)
176
251
  ], 6);
177
252
  };
178
253
  }
@@ -1 +1 @@
1
- {"version":3,"file":"splitter.vue_vue_type_script_setup_true_lang.js","names":["_useModel","_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_createElementVNode","_renderSlot"],"sources":["../../../src/components/splitter/splitter.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, ref, useId, useTemplateRef } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport type { SplitterLimit, SplitterProps, SplitterSlots } from './splitter'\n\ndefineOptions({ name: 'DouSplitter' })\n\nconst props = withDefaults(defineProps<SplitterProps>(), {\n direction: 'horizontal',\n min: 0,\n max: 100,\n collapsible: false,\n step: 1,\n disabled: false,\n})\nconst size = defineModel<number>({ default: 50 })\nconst collapsed = defineModel<boolean>('collapsed', { default: false })\nconst emit = defineEmits<{ change: [value: number] }>()\ndefineSlots<SplitterSlots>()\n\nconst ns = useNamespace('splitter')\nconst { t } = useLocale()\nconst startId = `dou-splitter-${useId()}-start`\nconst root = useTemplateRef<HTMLElement>('root')\n\nconst horizontal = computed(() => props.direction === 'horizontal')\nconst length = () => {\n const rect = root.value?.getBoundingClientRect()\n return (horizontal.value ? rect?.width : rect?.height) || 0\n}\nfunction toPercent(limit: SplitterLimit) {\n if (typeof limit === 'number') return limit\n const total = length()\n return total ? (Number.parseFloat(limit) / total) * 100 : 0\n}\nconst bounds = () => {\n const min = Math.max(0, toPercent(props.min))\n return { min, max: Math.max(min, Math.min(100, toPercent(props.max))) }\n}\nconst round = (value: number) => Math.round(value * 100) / 100\nfunction clamp(value: number) {\n const { min, max } = bounds()\n return round(Math.min(max, Math.max(min, value)))\n}\n\nfunction set(value: number) {\n const next = clamp(value)\n if (collapsed.value) collapsed.value = false\n if (next !== size.value) size.value = next\n}\n\nfunction toggle() {\n if (!props.collapsible || props.disabled) return\n collapsed.value = !collapsed.value\n emit('change', size.value)\n}\n\n/* dragging */\n\nconst dragging = ref(false)\nfunction onPointerdown(event: PointerEvent) {\n if (props.disabled || event.button !== 0) return\n event.preventDefault()\n ;(event.currentTarget as HTMLElement).setPointerCapture?.(event.pointerId)\n ;(event.currentTarget as HTMLElement).focus()\n dragging.value = true\n}\nfunction onPointermove(event: PointerEvent) {\n if (!dragging.value || !root.value) return\n const rect = root.value.getBoundingClientRect()\n const total = horizontal.value ? rect.width : rect.height\n if (!total) return\n const at = horizontal.value ? event.clientX - rect.left : event.clientY - rect.top\n set((at / total) * 100)\n}\nfunction onPointerup() {\n if (!dragging.value) return\n dragging.value = false\n emit('change', size.value)\n}\n\n/* keys */\n\nfunction onKeydown(event: KeyboardEvent) {\n if (props.disabled) return\n const step = props.step * (event.shiftKey ? 10 : 1)\n const back = horizontal.value ? 'ArrowLeft' : 'ArrowUp'\n const forth = horizontal.value ? 'ArrowRight' : 'ArrowDown'\n const current = collapsed.value ? 0 : size.value\n let next: number | undefined\n if (event.key === back) next = current - step\n else if (event.key === forth) next = current + step\n else if (event.key === 'Home') next = bounds().min\n else if (event.key === 'End') next = bounds().max\n else if (event.key === 'Enter' && props.collapsible) {\n event.preventDefault()\n return toggle()\n } else return\n event.preventDefault()\n set(next)\n emit('change', size.value)\n}\n\nconst shown = computed(() => (collapsed.value ? 0 : size.value))\nconst template = computed(\n () => `minmax(0, ${shown.value}fr) auto minmax(0, ${round(100 - shown.value)}fr)`,\n)\nconst style = computed(() =>\n horizontal.value ? { gridTemplateColumns: template.value } : { gridTemplateRows: template.value },\n)\nconst limits = computed(() => {\n // Read the px limits only once mounted; before that they count as 0.\n void size.value\n const { min, max } = root.value ? bounds() : { min: 0, max: 100 }\n return { min: Math.round(min), max: Math.round(max) }\n})\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[\n ns.b(),\n ns.m(direction),\n ns.is('dragging', dragging),\n ns.is('collapsed', collapsed),\n ns.is('disabled', disabled),\n ]\"\n :style=\"style\"\n >\n <div :id=\"startId\" :class=\"[ns.e('pane'), ns.is('start', true)]\">\n <slot name=\"start\" />\n </div>\n <div\n role=\"separator\"\n :class=\"ns.e('bar')\"\n :tabindex=\"disabled ? undefined : 0\"\n :aria-orientation=\"horizontal ? 'vertical' : 'horizontal'\"\n :aria-valuenow=\"Math.round(shown)\"\n :aria-valuemin=\"limits.min\"\n :aria-valuemax=\"limits.max\"\n :aria-controls=\"startId\"\n :aria-label=\"ariaLabel ?? t('splitter.label')\"\n :aria-disabled=\"disabled || undefined\"\n @pointerdown=\"onPointerdown\"\n @pointermove=\"onPointermove\"\n @pointerup=\"onPointerup\"\n @pointercancel=\"onPointerup\"\n @keydown=\"onKeydown\"\n @dblclick=\"toggle\"\n >\n <span :class=\"ns.e('handle')\" aria-hidden=\"true\" />\n </div>\n <div :class=\"[ns.e('pane'), ns.is('end', true)]\">\n <slot name=\"end\" />\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQA,MAAM,QAAQ;EAQd,MAAM,OAAOA,SAAmB,SAAA,YAAgB;EAChD,MAAM,YAAYA,SAAoB,SAAC,WAA+B;EACtE,MAAM,OAAO;EAGb,MAAM,KAAK,aAAa,UAAU;EAClC,MAAM,EAAE,MAAM,UAAU;EACxB,MAAM,UAAU,gBAAgB,MAAM,EAAE;EACxC,MAAM,OAAO,eAA4B,MAAM;EAE/C,MAAM,aAAa,eAAe,MAAM,cAAc,YAAY;EAClE,MAAM,eAAe;GACnB,MAAM,OAAO,KAAK,OAAO,sBAAsB;GAC/C,QAAQ,WAAW,QAAQ,MAAM,QAAQ,MAAM,WAAW;EAC5D;EACA,SAAS,UAAU,OAAsB;GACvC,IAAI,OAAO,UAAU,UAAU,OAAO;GACtC,MAAM,QAAQ,OAAO;GACrB,OAAO,QAAS,OAAO,WAAW,KAAK,IAAI,QAAS,MAAM;EAC5D;EACA,MAAM,eAAe;GACnB,MAAM,MAAM,KAAK,IAAI,GAAG,UAAU,MAAM,GAAG,CAAC;GAC5C,OAAO;IAAE;IAAK,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,UAAU,MAAM,GAAG,CAAC,CAAC;GAAE;EACxE;EACA,MAAM,SAAS,UAAkB,KAAK,MAAM,QAAQ,GAAG,IAAI;EAC3D,SAAS,MAAM,OAAe;GAC5B,MAAM,EAAE,KAAK,QAAQ,OAAO;GAC5B,OAAO,MAAM,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC;EAClD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WAAqB,KAAA,QAAA,OAAA,C;IAEvBD,mBAmBM,OAAA;KAlBJ,MAAK;KACJ,OAAKH,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,KAAA,CAAA;KACX,UAAU,QAAA,WAAW,KAAA,IAAS;KAC9B,oBAAkB,WAAA,QAAU,aAAA;KAC5B,iBAAe,KAAK,MAAM,MAAA,KAAK;KAC/B,iBAAe,OAAA,MAAO;KACtB,iBAAe,OAAA,MAAO;KACtB,iBAAe;KACf,cAAY,QAAA,aAAaA,MAAA,CAAA,CAAC,CAAA,gBAAA;KAC1B,iBAAe,QAAA,YAAY,KAAA;KACd;KACA;KACF;KACX,iBAAe;KACN;KACT,YAAU;I,IAEXE,mBAAmD,QAAA;KAA5C,OAAKH,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;KAAY,eAAY;;IAE5CE,mBAEM,OAAA,EAFA,OAAKH,eAAA,CAAGC,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA,GAAUA,MAAA,EAAA,CAAE,CAAC,GAAE,OAAA,IAAA,CAAA,CAAA,E,IAC/BG,WAAmB,KAAA,QAAA,KAAA,C"}
1
+ {"version":3,"file":"splitter.vue_vue_type_script_setup_true_lang.js","names":["_useModel","_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_createElementVNode","_renderSlot"],"sources":["../../../src/components/splitter/splitter.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n inject,\n onBeforeUnmount,\n onMounted,\n provide,\n ref,\n shallowReactive,\n useId,\n useTemplateRef,\n watchEffect,\n} from 'vue'\nimport { useElementSize } from '../../composables/use-element-size'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport { splitterContextKey } from './context'\nimport type { SplitterMinSize } from './context'\nimport type { SplitterLimit, SplitterProps, SplitterSlots } from './splitter'\n\ndefineOptions({ name: 'DouSplitter' })\n\nconst props = withDefaults(defineProps<SplitterProps>(), {\n direction: 'horizontal',\n min: 0,\n max: 100,\n minEnd: 0,\n collapsible: false,\n step: 1,\n disabled: false,\n})\nconst size = defineModel<number>({ default: 50 })\nconst collapsed = defineModel<boolean>('collapsed', { default: false })\nconst emit = defineEmits<{ change: [value: number] }>()\ndefineSlots<SplitterSlots>()\n\nconst ns = useNamespace('splitter')\nconst { t } = useLocale()\nconst startId = `dou-splitter-${useId()}-start`\nconst root = useTemplateRef<HTMLElement>('root')\n\nconst horizontal = computed(() => props.direction === 'horizontal')\n// Kept up to date, so px limits still hold when the container resizes\nconst box = useElementSize(root, { box: 'border-box' })\n// the divider is a 1px line; the panes share the rest, so limits are a share of that\nconst BAR = 1\nconst length = () => Math.max(0, (horizontal.value ? box.width.value : box.height.value) - BAR)\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n for (const [name, limit] of [\n ['min', props.min],\n ['max', props.max],\n ['minEnd', props.minEnd],\n ] as const)\n if (typeof limit === 'string' && !/^\\s*\\d+(?:\\.\\d+)?px\\s*$/.test(limit))\n devWarn(\n `[dou-ui] DouSplitter: \\`${name}\\` is \"${limit}\"; use a number for percent or a length in px such as '240px'.`,\n )\n })\n\nconst px = (limit: SplitterLimit) => (typeof limit === 'string' ? Number.parseFloat(limit) || 0 : 0)\n// px as a percentage of the splitter, 0 until it is measured\nfunction share(value: number) {\n const total = length()\n return total ? (value / total) * 100 : 0\n}\nconst percent = (limit: SplitterLimit) => (typeof limit === 'number' ? limit : 0)\n\n/* splitters inside the panes: their px limits add up to a minimum for the pane */\n\nconst startPane = useTemplateRef<HTMLElement>('startPane')\nconst endPane = useTemplateRef<HTMLElement>('endPane')\nconst nested = shallowReactive(new Map<HTMLElement, () => SplitterMinSize>())\nprovide(splitterContextKey, {\n register(el, measureNeed) {\n nested.set(el, measureNeed)\n return () => nested.delete(el)\n },\n})\nfunction inside(pane: HTMLElement | null): SplitterMinSize {\n const need = { width: 0, height: 0 }\n for (const [el, measureNeed] of nested) {\n if (!pane?.contains(el)) continue\n const { width, height } = measureNeed()\n need.width = Math.max(need.width, width)\n need.height = Math.max(need.height, height)\n }\n return need\n}\nconst needs = computed(() => {\n const main = horizontal.value ? 'width' : 'height'\n const cross = horizontal.value ? 'height' : 'width'\n const start = inside(startPane.value)\n const end = inside(endPane.value)\n return {\n start: Math.max(px(props.min), start[main]),\n end: Math.max(px(props.minEnd), end[main]),\n cross: Math.max(collapsed.value ? 0 : start[cross], end[cross]),\n }\n})\nconst parent = inject(splitterContextKey, null)\nlet unregister: (() => void) | undefined\nonMounted(() => {\n unregister = root.value\n ? parent?.register(root.value, () => {\n const { start, end, cross } = needs.value\n const along = (collapsed.value ? 0 : start) + BAR + end\n return horizontal.value ? { width: along, height: cross } : { width: cross, height: along }\n })\n : undefined\n})\nonBeforeUnmount(() => unregister?.())\n\nconst bounds = () => {\n const min = Math.max(0, percent(props.min), share(needs.value.start))\n const end = Math.max(0, percent(props.minEnd), share(needs.value.end))\n // Too small for both minimums: they share the room in proportion\n if (min + end > 100) {\n const at = (min / (min + end)) * 100\n return { min: at, max: at }\n }\n const max = typeof props.max === 'number' ? props.max : share(px(props.max))\n return { min, max: Math.max(min, Math.min(100 - end, max)) }\n}\nconst round = (value: number) => Math.round(value * 100) / 100\nfunction clamp(value: number) {\n const { min, max } = bounds()\n const next = round(Math.min(max, Math.max(min, value)))\n // rounding must not push a pane below its minimum: round inwards at the limits\n if (next > max) return Math.floor(max * 100) / 100\n if (next < min) return Math.ceil(min * 100) / 100\n return next\n}\n\nfunction set(value: number) {\n const next = clamp(value)\n if (collapsed.value) collapsed.value = false\n if (next !== size.value) size.value = next\n}\n\nfunction toggle() {\n if (!props.collapsible || props.disabled) return\n collapsed.value = !collapsed.value\n emit('change', size.value)\n}\n\n/* dragging */\n\nconst dragging = ref(false)\nfunction onPointerdown(event: PointerEvent) {\n if (props.disabled || event.button !== 0) return\n event.preventDefault()\n ;(event.currentTarget as HTMLElement).setPointerCapture?.(event.pointerId)\n ;(event.currentTarget as HTMLElement).focus()\n dragging.value = true\n}\nfunction onPointermove(event: PointerEvent) {\n if (!dragging.value || !root.value) return\n const rect = root.value.getBoundingClientRect()\n const total = (horizontal.value ? rect.width : rect.height) - BAR\n if (total <= 0) return\n const at = (horizontal.value ? event.clientX - rect.left : event.clientY - rect.top) - BAR / 2\n set((at / total) * 100)\n}\nfunction onPointerup() {\n if (!dragging.value) return\n dragging.value = false\n emit('change', size.value)\n}\n\n/* keys */\n\nfunction onKeydown(event: KeyboardEvent) {\n if (props.disabled) return\n const step = props.step * (event.shiftKey ? 10 : 1)\n const back = horizontal.value ? 'ArrowLeft' : 'ArrowUp'\n const forth = horizontal.value ? 'ArrowRight' : 'ArrowDown'\n const current = shown.value\n let next: number | undefined\n if (event.key === back) next = current - step\n else if (event.key === forth) next = current + step\n else if (event.key === 'Home') next = bounds().min\n else if (event.key === 'End') next = bounds().max\n else if (event.key === 'Enter' && props.collapsible) {\n event.preventDefault()\n return toggle()\n } else return\n event.preventDefault()\n set(next)\n emit('change', size.value)\n}\n\n// What is on screen: the model value kept within the limits, which can\n// tighten as the container resizes. The model itself only changes when\n// someone moves the divider.\nconst shown = computed(() => {\n if (collapsed.value) return 0\n return clamp(size.value)\n})\nconst template = computed(\n () => `minmax(0, ${shown.value}fr) auto minmax(0, ${round(100 - shown.value)}fr)`,\n)\nconst style = computed(() =>\n horizontal.value ? { gridTemplateColumns: template.value } : { gridTemplateRows: template.value },\n)\nconst limits = computed(() => {\n // px limits count as 0 until the container is measured\n const { min, max } = bounds()\n return { min: Math.round(min), max: Math.round(max) }\n})\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[\n ns.b(),\n ns.m(direction),\n ns.is('dragging', dragging),\n ns.is('collapsed', collapsed),\n ns.is('disabled', disabled),\n ]\"\n :style=\"style\"\n >\n <div ref=\"startPane\" :id=\"startId\" :class=\"[ns.e('pane'), ns.is('start', true)]\">\n <slot name=\"start\" />\n </div>\n <div\n role=\"separator\"\n :class=\"ns.e('bar')\"\n :tabindex=\"disabled ? undefined : 0\"\n :aria-orientation=\"horizontal ? 'vertical' : 'horizontal'\"\n :aria-valuenow=\"Math.round(shown)\"\n :aria-valuemin=\"limits.min\"\n :aria-valuemax=\"limits.max\"\n :aria-controls=\"startId\"\n :aria-label=\"ariaLabel ?? t('splitter.label')\"\n :aria-disabled=\"disabled || undefined\"\n @pointerdown=\"onPointerdown\"\n @pointermove=\"onPointermove\"\n @pointerup=\"onPointerup\"\n @pointercancel=\"onPointerup\"\n @keydown=\"onKeydown\"\n @dblclick=\"toggle\"\n >\n <span :class=\"ns.e('handle')\" aria-hidden=\"true\" />\n </div>\n <div ref=\"endPane\" :class=\"[ns.e('pane'), ns.is('end', true)]\">\n <slot name=\"end\" />\n </div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;AA8CA,IAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAvBZ,MAAM,QAAQ;EASd,MAAM,OAAOA,SAAmB,SAAA,YAAgB;EAChD,MAAM,YAAYA,SAAoB,SAAC,WAA+B;EACtE,MAAM,OAAO;EAGb,MAAM,KAAK,aAAa,UAAU;EAClC,MAAM,EAAE,MAAM,UAAU;EACxB,MAAM,UAAU,gBAAgB,MAAM,EAAE;EACxC,MAAM,OAAO,eAA4B,MAAM;EAE/C,MAAM,aAAa,eAAe,MAAM,cAAc,YAAY;EAElE,MAAM,MAAM,eAAe,MAAM,EAAE,KAAK,aAAa,CAAC;EAGtD,MAAM,eAAe,KAAK,IAAI,IAAI,WAAW,QAAQ,IAAI,MAAM,QAAQ,IAAI,OAAO,SAAS,GAAG;EAE9F,IAAA,QAAA,IAAA,aAA6B,cAC3B,kBAAkB;GAChB,KAAK,MAAM,CAAC,MAAM,UAAU;IAC1B,CAAC,OAAO,MAAM,GAAG;IACjB,CAAC,OAAO,MAAM,GAAG;IACjB,CAAC,UAAU,MAAM,MAAM;GACzB,GACE,IAAI,OAAO,UAAU,YAAY,CAAC,0BAA0B,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IAEvBD,mBAmBM,OAAA;KAlBJ,MAAK;KACJ,OAAKH,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,KAAA,CAAA;KACX,UAAU,QAAA,WAAW,KAAA,IAAS;KAC9B,oBAAkB,WAAA,QAAU,aAAA;KAC5B,iBAAe,KAAK,MAAM,MAAA,KAAK;KAC/B,iBAAe,OAAA,MAAO;KACtB,iBAAe,OAAA,MAAO;KACtB,iBAAe;KACf,cAAY,QAAA,aAAaA,MAAA,CAAA,CAAC,CAAA,gBAAA;KAC1B,iBAAe,QAAA,YAAY,KAAA;KACd;KACA;KACF;KACX,iBAAe;KACN;KACT,YAAU;I,IAEXE,mBAAmD,QAAA;KAA5C,OAAKH,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;KAAY,eAAY;;IAE5CE,mBAEM,OAAA;KAFG,SAAA;KAAJ,KAAI;KAAW,OAAKH,eAAA,CAAGC,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA,GAAUA,MAAA,EAAA,CAAE,CAAC,GAAE,OAAA,IAAA,CAAA,CAAA;I,IAC7CG,WAAmB,KAAA,QAAA,KAAA,C"}
@@ -0,0 +1,172 @@
1
+ import { holdPointer } from "../../utils/pointer.js";
2
+ import { shallowRef } from "vue";
3
+ // src/components/tabs/tab-drag.ts
4
+ var zones = /* @__PURE__ */ new Map();
5
+ /** The drag in progress, if any. */
6
+ var activeTabDrag = shallowRef(null);
7
+ function registerTabDropZone(zone) {
8
+ let el;
9
+ return {
10
+ /** Call after the zone's element changes. */
11
+ update() {
12
+ const next = zone.el();
13
+ if (next === el) return;
14
+ if (el) zones.delete(el);
15
+ el = next;
16
+ if (el) zones.set(el, zone);
17
+ },
18
+ remove() {
19
+ if (el) zones.delete(el);
20
+ el = void 0;
21
+ }
22
+ };
23
+ }
24
+ /** The innermost zone under the point that takes this tab. */
25
+ function zoneAt(drag, x, y) {
26
+ let el = document.elementFromPoint(x, y);
27
+ while (el) {
28
+ const zone = zones.get(el);
29
+ if (zone?.accepts(drag)) return zone;
30
+ el = el.parentElement;
31
+ }
32
+ }
33
+ /**
34
+ * Watch a press on a tab and turn it into a drag once the pointer moves
35
+ * far enough. On touch the press has to be held first, so a swipe still
36
+ * scrolls the row of tabs.
37
+ */
38
+ function pressTab(event, options) {
39
+ if (event.button !== 0 || activeTabDrag.value) return;
40
+ const start = {
41
+ x: event.clientX,
42
+ y: event.clientY
43
+ };
44
+ const press = event.pointerType === "touch";
45
+ let ready = !press;
46
+ let drag = null;
47
+ let ghost;
48
+ let offset = {
49
+ x: 0,
50
+ y: 0
51
+ };
52
+ let pointer = {
53
+ x: 0,
54
+ y: 0
55
+ };
56
+ let current;
57
+ let frame = 0;
58
+ const timer = press ? setTimeout(() => ready = true, 250) : void 0;
59
+ const hold = holdPointer(event, options.root);
60
+ function makeGhost(e) {
61
+ const rect = options.el.getBoundingClientRect();
62
+ offset = {
63
+ x: Math.min(e.clientX - rect.left, 16),
64
+ y: -16
65
+ };
66
+ const clone = options.el.cloneNode(true);
67
+ clone.removeAttribute("id");
68
+ clone.classList.remove("is-dragging");
69
+ clone.classList.add("dou-tabs-ghost");
70
+ clone.setAttribute("aria-hidden", "true");
71
+ Object.assign(clone.style, {
72
+ position: "fixed",
73
+ left: "0",
74
+ top: "0",
75
+ width: `${rect.width}px`,
76
+ height: `${rect.height}px`,
77
+ margin: "0",
78
+ boxSizing: "border-box",
79
+ pointerEvents: "none",
80
+ zIndex: "9999"
81
+ });
82
+ const tabs = options.el.closest(".dou-tabs");
83
+ if (tabs) {
84
+ const style = getComputedStyle(tabs);
85
+ for (const name of [
86
+ "--dou-tabs-height",
87
+ "--dou-tabs-padding-x",
88
+ "--dou-tabs-icon-size"
89
+ ]) clone.style.setProperty(name, style.getPropertyValue(name));
90
+ clone.style.fontSize = style.fontSize;
91
+ }
92
+ const theme = options.el.closest("[data-dou-theme]")?.dataset.douTheme;
93
+ if (theme) clone.dataset.douTheme = theme;
94
+ document.body.append(clone);
95
+ ghost = clone;
96
+ moveGhost();
97
+ }
98
+ function moveGhost() {
99
+ if (ghost) ghost.style.translate = `${pointer.x - offset.x}px ${pointer.y - offset.y}px`;
100
+ }
101
+ function tick() {
102
+ if (!drag) return;
103
+ const zone = zoneAt(drag, pointer.x, pointer.y);
104
+ if (zone !== current) current?.leave();
105
+ current = zone;
106
+ zone?.over(drag, pointer.x, pointer.y);
107
+ frame = requestAnimationFrame(tick);
108
+ }
109
+ function begin(e) {
110
+ drag = options.drag();
111
+ activeTabDrag.value = drag;
112
+ hold.grab();
113
+ document.documentElement.classList.add("dou-tabs-dragging");
114
+ makeGhost(e);
115
+ options.onStart?.();
116
+ frame = requestAnimationFrame(tick);
117
+ }
118
+ function end(commit) {
119
+ stop();
120
+ cancelAnimationFrame(frame);
121
+ ghost?.remove();
122
+ document.documentElement.classList.remove("dou-tabs-dragging");
123
+ const finished = drag;
124
+ drag = null;
125
+ activeTabDrag.value = null;
126
+ if (!finished) return;
127
+ const zone = commit ? zoneAt(finished, pointer.x, pointer.y) : void 0;
128
+ if (zone !== current) current?.leave();
129
+ current = void 0;
130
+ if (zone) {
131
+ zone.over(finished, pointer.x, pointer.y);
132
+ zone.drop(finished);
133
+ }
134
+ options.onEnd?.(!!zone);
135
+ }
136
+ const onMove = (e) => {
137
+ pointer = {
138
+ x: e.clientX,
139
+ y: e.clientY
140
+ };
141
+ if (!drag) {
142
+ if (Math.hypot(e.clientX - start.x, e.clientY - start.y) <= 4) return;
143
+ if (!ready) return stop();
144
+ begin(e);
145
+ }
146
+ e.preventDefault();
147
+ moveGhost();
148
+ };
149
+ const onUp = () => drag ? end(true) : stop();
150
+ const onCancel = () => drag ? end(false) : stop();
151
+ const onKey = (e) => {
152
+ if (e.key !== "Escape" || !drag) return;
153
+ e.preventDefault();
154
+ e.stopPropagation();
155
+ end(false);
156
+ };
157
+ function stop() {
158
+ clearTimeout(timer);
159
+ hold.release();
160
+ window.removeEventListener("pointermove", onMove);
161
+ window.removeEventListener("pointerup", onUp);
162
+ window.removeEventListener("pointercancel", onCancel);
163
+ window.removeEventListener("keydown", onKey, true);
164
+ }
165
+ window.addEventListener("pointermove", onMove);
166
+ window.addEventListener("pointerup", onUp);
167
+ window.addEventListener("pointercancel", onCancel);
168
+ window.addEventListener("keydown", onKey, true);
169
+ }
170
+ export { activeTabDrag, pressTab, registerTabDropZone };
171
+
172
+ //# sourceMappingURL=tab-drag.js.map