dou-ui 0.1.0-alpha.25 → 0.1.0-alpha.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/components/dock/context.js.map +1 -1
  2. package/dist/components/dock/dock-group.js.map +1 -1
  3. package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js +15 -4
  4. package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js.map +1 -1
  5. package/dist/components/dock/dock.js.map +1 -1
  6. package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js +72 -21
  7. package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js.map +1 -1
  8. package/dist/components/dock/index.js +2 -2
  9. package/dist/components/dock/index.js.map +1 -1
  10. package/dist/components/dock/layout.js +12 -1
  11. package/dist/components/dock/layout.js.map +1 -1
  12. package/dist/components/popover/popover.js.map +1 -1
  13. package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js +29 -5
  14. package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js.map +1 -1
  15. package/dist/components/tabs/tab-button.js.map +1 -1
  16. package/dist/components/tabs/tab-button.vue_vue_type_script_setup_true_lang.js +27 -5
  17. package/dist/components/tabs/tab-button.vue_vue_type_script_setup_true_lang.js.map +1 -1
  18. package/dist/components/tabs/tab-drag.js +12 -4
  19. package/dist/components/tabs/tab-drag.js.map +1 -1
  20. package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js +70 -10
  21. package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js.map +1 -1
  22. package/dist/components/tabs/tabs2.js.map +1 -1
  23. package/dist/components/tabs/truncated-title.js +28 -0
  24. package/dist/components/tabs/truncated-title.js.map +1 -0
  25. package/dist/index.js +2 -2
  26. package/dist/style.css +1 -1
  27. package/dist/types/components/dock/context.d.ts +2 -0
  28. package/dist/types/components/dock/dock.d.ts +40 -0
  29. package/dist/types/components/dock/index.d.ts +1 -1
  30. package/dist/types/components/dock/layout.d.ts +6 -0
  31. package/dist/types/components/popover/popover.d.ts +1 -1
  32. package/dist/types/components/tabs/tab-button.vue.d.ts +1 -0
  33. package/dist/types/components/tabs/tab-drag.d.ts +10 -0
  34. package/dist/types/components/tabs/truncated-title.d.ts +7 -0
  35. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":[],"sources":["../../../src/components/dock/context.ts"],"sourcesContent":["import type { InjectionKey } from 'vue'\nimport type { SplitterLimit } from '../splitter/splitter'\nimport type { TabDrag } from '../tabs/tab-drag'\nimport type { TabsMoveEvent, TabsSize, TabsValue } from '../tabs/tabs'\nimport type { DockPanel, DockSlots } from './dock'\nimport type { DockGroup, DockNode, DockSide, DockSplit } from './layout'\n\nexport interface DockContext {\n /** The group name the tabs of this dock share. */\n group: string\n size: () => TabsSize | undefined\n closable: () => boolean\n addable: () => boolean\n /** The smallest each side of a split in this direction may get. */\n min: (direction: DockSplit['direction']) => SplitterLimit\n draggable: () => boolean\n panel: (value: TabsValue) => DockPanel | undefined\n slots: DockSlots\n resize: (node: DockSplit, size: number) => void\n select: (group: DockGroup, value: TabsValue) => void\n move: (event: TabsMoveEvent) => void\n /** Whether a drop on the body of `group` could do something. */\n canDrop: (drag: TabDrag, group: DockGroup, side: DockSide | 'center') => boolean\n drop: (drag: TabDrag, group: DockGroup, side: DockSide | 'center') => void\n remove: (value: TabsValue, group: DockGroup) => void\n add: (group: DockGroup) => void\n /** A pointer pressed or the focus moved into a group, or a tab was dropped on it. */\n use: (group: string) => void\n /** The place in the layout a group is shown in. */\n setCell: (id: string, el: unknown) => void\n}\n\nexport const dockKey: InjectionKey<DockContext> = Symbol('DouDock')\n\nexport type { DockNode }\n"],"mappings":";AAgCA,IAAa,UAAqC,OAAO,SAAS"}
1
+ {"version":3,"file":"context.js","names":[],"sources":["../../../src/components/dock/context.ts"],"sourcesContent":["import type { InjectionKey } from 'vue'\nimport type { SplitterLimit } from '../splitter/splitter'\nimport type { TabDrag } from '../tabs/tab-drag'\nimport type { TabsMoveEvent, TabsSize, TabsValue } from '../tabs/tabs'\nimport type { DockPanel, DockSlots } from './dock'\nimport type { DockGroup, DockNode, DockSide, DockSplit } from './layout'\n\nexport interface DockContext {\n /** The group name the tabs of this dock share. */\n group: string\n size: () => TabsSize | undefined\n closable: () => boolean\n addable: () => boolean\n /** The smallest each side of a split in this direction may get. */\n min: (direction: DockSplit['direction']) => SplitterLimit\n draggable: () => boolean\n panel: (value: TabsValue) => DockPanel | undefined\n slots: DockSlots\n resize: (node: DockSplit, size: number) => void\n select: (group: DockGroup, value: TabsValue) => void\n move: (event: TabsMoveEvent) => void\n /** Existing tab in `group` that `drag` will merge into by `mergeId`, if any. */\n mergeTarget: (drag: TabDrag, group: DockGroup) => TabsValue | undefined\n /** Whether a drop on the body of `group` could do something. */\n canDrop: (drag: TabDrag, group: DockGroup, side: DockSide | 'center') => boolean\n drop: (drag: TabDrag, group: DockGroup, side: DockSide | 'center') => void\n remove: (value: TabsValue, group: DockGroup) => void\n add: (group: DockGroup) => void\n /** A pointer pressed or the focus moved into a group, or a tab was dropped on it. */\n use: (group: string) => void\n /** The place in the layout a group is shown in. */\n setCell: (id: string, el: unknown) => void\n}\n\nexport const dockKey: InjectionKey<DockContext> = Symbol('DouDock')\n\nexport type { DockNode }\n"],"mappings":";AAkCA,IAAa,UAAqC,OAAO,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"dock-group.js","names":["_sfc_main"],"sources":["../../../src/components/dock/dock-group.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { inject, onBeforeUnmount, onMounted, onUpdated, ref, useTemplateRef } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouTabPanel, DouTabs } from '../tabs'\nimport { registerTabDropZone } from '../tabs/tab-drag'\nimport { dockKey } from './context'\nimport { dockDropSide } from './drop-side'\nimport type { FunctionalComponent } from 'vue'\nimport type { DockGroup, DockSide } from './layout'\n\ndefineOptions({ name: 'DouDockGroup' })\n\nconst props = defineProps<{\n group: DockGroup\n /** Which slots the dock has; read in its render, so a slot that comes later shows up. */\n slotted: { label: boolean; extra: boolean; empty: boolean }\n}>()\nconst dock = inject(dockKey)!\nconst ns = useNamespace('dock')\n\n/* the edges of the body split a tab off, the middle takes it in */\n\nconst el = useTemplateRef<HTMLElement>('el')\nconst target = ref<DockSide | 'center' | null>(null)\n\nfunction sideAt(x: number, y: number) {\n return dockDropSide(el.value!.getBoundingClientRect(), x, y, {\n width: dock.min('horizontal'),\n height: dock.min('vertical'),\n })\n}\n\nconst zone = registerTabDropZone({\n el: () => el.value,\n accepts: (drag) => drag.group === dock.group,\n over(drag, x, y) {\n const side = sideAt(x, y)\n target.value = dock.canDrop(drag, props.group, side) ? side : null\n },\n leave: () => (target.value = null),\n drop(drag) {\n const side = target.value\n target.value = null\n if (side) dock.drop(drag, props.group, side)\n },\n})\nonMounted(() => zone.update())\nonUpdated(() => zone.update())\nonBeforeUnmount(() => zone.remove())\n\n/** Renders what a slot of the dock gives back, under one component type so it is not remounted. */\nconst Outlet: FunctionalComponent<{ render: () => unknown }> = (outlet) =>\n outlet.render() as ReturnType<FunctionalComponent>\n\nconst label = (value: string | number) => dock.panel(value)?.label ?? String(value)\n</script>\n\n<template>\n <div\n ref=\"el\"\n :class=\"[ns.e('group'), ns.is('empty', !group.tabs.length)]\"\n :data-dock-group=\"group.id\"\n @pointerdown.capture=\"dock.use(group.id)\"\n @focusin=\"dock.use(group.id)\"\n >\n <DouTabs\n :model-value=\"group.active ?? group.tabs[0]\"\n :name=\"group.id\"\n :group=\"dock.group\"\n :size=\"dock.size()\"\n :closable=\"dock.closable()\"\n :addable=\"dock.addable()\"\n height=\"100%\"\n :draggable=\"dock.draggable()\"\n @update:model-value=\"$event !== undefined && dock.select(group, $event)\"\n @move=\"dock.move\"\n @remove=\"dock.remove($event, group)\"\n @add=\"dock.add(group)\"\n >\n <DouTabPanel\n v-for=\"value in group.tabs\"\n :key=\"value\"\n :value=\"value\"\n :label=\"label(value)\"\n :icon=\"dock.panel(value)?.icon\"\n :closable=\"dock.panel(value)?.closable\"\n :disabled=\"dock.panel(value)?.disabled\"\n :draggable=\"dock.panel(value)?.draggable\"\n :pinned=\"dock.panel(value)?.pinned\"\n >\n <template v-if=\"slotted.label\" #label=\"{ selected }\">\n <Outlet :render=\"() => dock.slots.label?.({ value, selected })\" />\n </template>\n <Outlet :render=\"() => dock.slots.default?.({ value })\" />\n </DouTabPanel>\n <template v-if=\"slotted.extra\" #extra>\n <Outlet\n :render=\"() => dock.slots.extra?.({ group, active: group.active ?? group.tabs[0] })\"\n />\n </template>\n </DouTabs>\n <div v-if=\"!group.tabs.length && slotted.empty\" :class=\"ns.e('empty')\">\n <Outlet :render=\"() => dock.slots.empty?.()\" />\n </div>\n <div\n :class=\"[ns.e('drop'), target && ns.is(target, true), ns.is('shown', !!target)]\"\n aria-hidden=\"true\"\n />\n </div>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"dock-group.js","names":["_sfc_main"],"sources":["../../../src/components/dock/dock-group.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { inject, onBeforeUnmount, onMounted, onUpdated, provide, ref, useTemplateRef } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouTabPanel, DouTabs } from '../tabs'\nimport { registerTabDropZone, tabMergeTargetKey } from '../tabs/tab-drag'\nimport { dockKey } from './context'\nimport { dockDropSide } from './drop-side'\nimport type { FunctionalComponent } from 'vue'\nimport type { TabsValue } from '../tabs/tabs'\nimport type { DockGroup, DockSide } from './layout'\n\ndefineOptions({ name: 'DouDockGroup' })\n\nconst props = defineProps<{\n group: DockGroup\n /** Which slots the dock has; read in its render, so a slot that comes later shows up. */\n slotted: { label: boolean; extra: boolean; empty: boolean }\n}>()\nconst dock = inject(dockKey)!\nconst ns = useNamespace('dock')\nconst centerMergeTarget = ref<TabsValue | null>(null)\nprovide(tabMergeTargetKey, {\n resolve: (drag) => dock.mergeTarget(drag, props.group),\n active: centerMergeTarget,\n})\n\n/* the edges of the body split a tab off, the middle takes it in */\n\nconst el = useTemplateRef<HTMLElement>('el')\nconst target = ref<DockSide | 'center' | null>(null)\n\nfunction sideAt(x: number, y: number) {\n return dockDropSide(el.value!.getBoundingClientRect(), x, y, {\n width: dock.min('horizontal'),\n height: dock.min('vertical'),\n })\n}\n\nconst zone = registerTabDropZone({\n el: () => el.value,\n accepts: (drag) => drag.group === dock.group,\n over(drag, x, y) {\n const side = sideAt(x, y)\n const next = dock.canDrop(drag, props.group, side) ? side : null\n target.value = next\n centerMergeTarget.value =\n next === 'center' ? (dock.mergeTarget(drag, props.group) ?? null) : null\n },\n leave() {\n target.value = null\n centerMergeTarget.value = null\n },\n drop(drag) {\n const side = target.value\n target.value = null\n centerMergeTarget.value = null\n if (side) dock.drop(drag, props.group, side)\n },\n})\nonMounted(() => zone.update())\nonUpdated(() => zone.update())\nonBeforeUnmount(() => zone.remove())\n\n/** Renders what a slot of the dock gives back, under one component type so it is not remounted. */\nconst Outlet: FunctionalComponent<{ render: () => unknown }> = (outlet) =>\n outlet.render() as ReturnType<FunctionalComponent>\n\nconst label = (value: string | number) => dock.panel(value)?.label ?? String(value)\n</script>\n\n<template>\n <div\n ref=\"el\"\n :class=\"[ns.e('group'), ns.is('empty', !group.tabs.length)]\"\n :data-dock-group=\"group.id\"\n @pointerdown.capture=\"dock.use(group.id)\"\n @focusin=\"dock.use(group.id)\"\n >\n <DouTabs\n :model-value=\"group.active ?? group.tabs[0]\"\n :name=\"group.id\"\n :group=\"dock.group\"\n :size=\"dock.size()\"\n :closable=\"dock.closable()\"\n :addable=\"dock.addable()\"\n height=\"100%\"\n :draggable=\"dock.draggable()\"\n @update:model-value=\"$event !== undefined && dock.select(group, $event)\"\n @move=\"dock.move\"\n @remove=\"dock.remove($event, group)\"\n @add=\"dock.add(group)\"\n >\n <DouTabPanel\n v-for=\"value in group.tabs\"\n :key=\"value\"\n :value=\"value\"\n :label=\"label(value)\"\n :icon=\"dock.panel(value)?.icon\"\n :closable=\"dock.panel(value)?.closable\"\n :disabled=\"dock.panel(value)?.disabled\"\n :draggable=\"dock.panel(value)?.draggable\"\n :pinned=\"dock.panel(value)?.pinned\"\n >\n <template v-if=\"slotted.label\" #label=\"{ selected }\">\n <Outlet :render=\"() => dock.slots.label?.({ value, selected })\" />\n </template>\n <Outlet :render=\"() => dock.slots.default?.({ value })\" />\n </DouTabPanel>\n <template v-if=\"slotted.extra\" #extra>\n <Outlet\n :render=\"() => dock.slots.extra?.({ group, active: group.active ?? group.tabs[0] })\"\n />\n </template>\n </DouTabs>\n <div v-if=\"!group.tabs.length && slotted.empty\" :class=\"ns.e('empty')\">\n <Outlet :render=\"() => dock.slots.empty?.()\" />\n </div>\n <div\n :class=\"[ns.e('drop'), target && ns.is(target, true), ns.is('shown', !!target)]\"\n aria-hidden=\"true\"\n />\n </div>\n</template>\n"],"mappings":""}
@@ -1,9 +1,9 @@
1
1
  import { useNamespace } from "../../utils/namespace.js";
2
2
  import { dockKey } from "./context.js";
3
3
  import { dockDropSide } from "./drop-side.js";
4
- import { registerTabDropZone } from "../tabs/tab-drag.js";
4
+ import { registerTabDropZone, tabMergeTargetKey } from "../tabs/tab-drag.js";
5
5
  import { DouTabPanel, DouTabs } from "../tabs/index.js";
6
- import { Fragment, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createVNode, defineComponent, inject, normalizeClass, onBeforeUnmount, onMounted, onUpdated, openBlock, ref, renderList, unref, useTemplateRef, withCtx } from "vue";
6
+ import { Fragment, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createVNode, defineComponent, inject, normalizeClass, onBeforeUnmount, onMounted, onUpdated, openBlock, provide, ref, renderList, unref, useTemplateRef, withCtx } from "vue";
7
7
  // src/components/dock/dock-group.vue?vue&type=script&setup=true&lang.ts
8
8
  var _hoisted_1 = ["data-dock-group"];
9
9
  var dock_group_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
@@ -17,6 +17,11 @@ var dock_group_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
17
17
  const props = __props;
18
18
  const dock = inject(dockKey);
19
19
  const ns = useNamespace("dock");
20
+ const centerMergeTarget = ref(null);
21
+ provide(tabMergeTargetKey, {
22
+ resolve: (drag) => dock.mergeTarget(drag, props.group),
23
+ active: centerMergeTarget
24
+ });
20
25
  const el = useTemplateRef("el");
21
26
  const target = ref(null);
22
27
  function sideAt(x, y) {
@@ -30,12 +35,18 @@ var dock_group_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
30
35
  accepts: (drag) => drag.group === dock.group,
31
36
  over(drag, x, y) {
32
37
  const side = sideAt(x, y);
33
- target.value = dock.canDrop(drag, props.group, side) ? side : null;
38
+ const next = dock.canDrop(drag, props.group, side) ? side : null;
39
+ target.value = next;
40
+ centerMergeTarget.value = next === "center" ? dock.mergeTarget(drag, props.group) ?? null : null;
41
+ },
42
+ leave() {
43
+ target.value = null;
44
+ centerMergeTarget.value = null;
34
45
  },
35
- leave: () => target.value = null,
36
46
  drop(drag) {
37
47
  const side = target.value;
38
48
  target.value = null;
49
+ centerMergeTarget.value = null;
39
50
  if (side) dock.drop(drag, props.group, side);
40
51
  }
41
52
  });
@@ -1 +1 @@
1
- {"version":3,"file":"dock-group.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_createVNode","_createSlots","_withCtx","_Fragment","_renderList","_createBlock","_createCommentVNode","_createElementVNode"],"sources":["../../../src/components/dock/dock-group.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { inject, onBeforeUnmount, onMounted, onUpdated, ref, useTemplateRef } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouTabPanel, DouTabs } from '../tabs'\nimport { registerTabDropZone } from '../tabs/tab-drag'\nimport { dockKey } from './context'\nimport { dockDropSide } from './drop-side'\nimport type { FunctionalComponent } from 'vue'\nimport type { DockGroup, DockSide } from './layout'\n\ndefineOptions({ name: 'DouDockGroup' })\n\nconst props = defineProps<{\n group: DockGroup\n /** Which slots the dock has; read in its render, so a slot that comes later shows up. */\n slotted: { label: boolean; extra: boolean; empty: boolean }\n}>()\nconst dock = inject(dockKey)!\nconst ns = useNamespace('dock')\n\n/* the edges of the body split a tab off, the middle takes it in */\n\nconst el = useTemplateRef<HTMLElement>('el')\nconst target = ref<DockSide | 'center' | null>(null)\n\nfunction sideAt(x: number, y: number) {\n return dockDropSide(el.value!.getBoundingClientRect(), x, y, {\n width: dock.min('horizontal'),\n height: dock.min('vertical'),\n })\n}\n\nconst zone = registerTabDropZone({\n el: () => el.value,\n accepts: (drag) => drag.group === dock.group,\n over(drag, x, y) {\n const side = sideAt(x, y)\n target.value = dock.canDrop(drag, props.group, side) ? side : null\n },\n leave: () => (target.value = null),\n drop(drag) {\n const side = target.value\n target.value = null\n if (side) dock.drop(drag, props.group, side)\n },\n})\nonMounted(() => zone.update())\nonUpdated(() => zone.update())\nonBeforeUnmount(() => zone.remove())\n\n/** Renders what a slot of the dock gives back, under one component type so it is not remounted. */\nconst Outlet: FunctionalComponent<{ render: () => unknown }> = (outlet) =>\n outlet.render() as ReturnType<FunctionalComponent>\n\nconst label = (value: string | number) => dock.panel(value)?.label ?? String(value)\n</script>\n\n<template>\n <div\n ref=\"el\"\n :class=\"[ns.e('group'), ns.is('empty', !group.tabs.length)]\"\n :data-dock-group=\"group.id\"\n @pointerdown.capture=\"dock.use(group.id)\"\n @focusin=\"dock.use(group.id)\"\n >\n <DouTabs\n :model-value=\"group.active ?? group.tabs[0]\"\n :name=\"group.id\"\n :group=\"dock.group\"\n :size=\"dock.size()\"\n :closable=\"dock.closable()\"\n :addable=\"dock.addable()\"\n height=\"100%\"\n :draggable=\"dock.draggable()\"\n @update:model-value=\"$event !== undefined && dock.select(group, $event)\"\n @move=\"dock.move\"\n @remove=\"dock.remove($event, group)\"\n @add=\"dock.add(group)\"\n >\n <DouTabPanel\n v-for=\"value in group.tabs\"\n :key=\"value\"\n :value=\"value\"\n :label=\"label(value)\"\n :icon=\"dock.panel(value)?.icon\"\n :closable=\"dock.panel(value)?.closable\"\n :disabled=\"dock.panel(value)?.disabled\"\n :draggable=\"dock.panel(value)?.draggable\"\n :pinned=\"dock.panel(value)?.pinned\"\n >\n <template v-if=\"slotted.label\" #label=\"{ selected }\">\n <Outlet :render=\"() => dock.slots.label?.({ value, selected })\" />\n </template>\n <Outlet :render=\"() => dock.slots.default?.({ value })\" />\n </DouTabPanel>\n <template v-if=\"slotted.extra\" #extra>\n <Outlet\n :render=\"() => dock.slots.extra?.({ group, active: group.active ?? group.tabs[0] })\"\n />\n </template>\n </DouTabs>\n <div v-if=\"!group.tabs.length && slotted.empty\" :class=\"ns.e('empty')\">\n <Outlet :render=\"() => dock.slots.empty?.()\" />\n </div>\n <div\n :class=\"[ns.e('drop'), target && ns.is(target, true), ns.is('shown', !!target)]\"\n aria-hidden=\"true\"\n />\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;EAYA,MAAM,QAAQ;EAKd,MAAM,OAAO,OAAO,OAAO;EAC3B,MAAM,KAAK,aAAa,MAAM;EAI9B,MAAM,KAAK,eAA4B,IAAI;EAC3C,MAAM,SAAS,IAAgC,IAAI;EAEnD,SAAS,OAAO,GAAW,GAAW;GACpC,OAAO,aAAa,GAAG,MAAO,sBAAsB,GAAG,GAAG,GAAG;IAC3D,OAAO,KAAK,IAAI,YAAY;IAC5B,QAAQ,KAAK,IAAI,UAAU;GAC7B,CAAC;EACH;EAEA,MAAM,OAAO,oBAAoB;GAC/B,UAAU,GAAG;GACb,UAAU,SAAS,KAAK,UAAU,KAAK;GACvC,KAAK,MAAM,GAAG,GAAG;IACf,MAAM,OAAO,OAAO,GAAG,CAAC;IACxB,OAAO,QAAQ,KAAK,QAAQ,MAAM,MAAM,OAAO,IAAI,IAAI,OAAO;GAChE;GACA,aAAc,OAAO,QAAQ;GAC7B,KAAK,MAAM;IACT,MAAM,OAAO,OAAO;IACpB,OAAO,QAAQ;IACf,IAAI,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OAAA;;KAF2C,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,CAAA;I,IAC1DC,YAA+C,QAAA,EAAtC,cAAcD,MAAA,IAAA,CAAI,CAAC,MAAM,QAAK,E;IAEzCQ,mBAGE,OAAA;KAFC,OAAKT,eAAA;MAAGC,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA;MAAU,OAAA,SAAUA,MAAA,EAAA,CAAE,CAAC,GAAG,OAAA,OAAM,IAAA;MAASA,MAAA,EAAA,CAAE,CAAC,GAAE,SAAA,CAAA,CAAY,OAAA,KAAM;KAAA,CAAA;KAC7E,eAAY"}
1
+ {"version":3,"file":"dock-group.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_createVNode","_createSlots","_withCtx","_Fragment","_renderList","_createBlock","_createCommentVNode","_createElementVNode"],"sources":["../../../src/components/dock/dock-group.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { inject, onBeforeUnmount, onMounted, onUpdated, provide, ref, useTemplateRef } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { DouTabPanel, DouTabs } from '../tabs'\nimport { registerTabDropZone, tabMergeTargetKey } from '../tabs/tab-drag'\nimport { dockKey } from './context'\nimport { dockDropSide } from './drop-side'\nimport type { FunctionalComponent } from 'vue'\nimport type { TabsValue } from '../tabs/tabs'\nimport type { DockGroup, DockSide } from './layout'\n\ndefineOptions({ name: 'DouDockGroup' })\n\nconst props = defineProps<{\n group: DockGroup\n /** Which slots the dock has; read in its render, so a slot that comes later shows up. */\n slotted: { label: boolean; extra: boolean; empty: boolean }\n}>()\nconst dock = inject(dockKey)!\nconst ns = useNamespace('dock')\nconst centerMergeTarget = ref<TabsValue | null>(null)\nprovide(tabMergeTargetKey, {\n resolve: (drag) => dock.mergeTarget(drag, props.group),\n active: centerMergeTarget,\n})\n\n/* the edges of the body split a tab off, the middle takes it in */\n\nconst el = useTemplateRef<HTMLElement>('el')\nconst target = ref<DockSide | 'center' | null>(null)\n\nfunction sideAt(x: number, y: number) {\n return dockDropSide(el.value!.getBoundingClientRect(), x, y, {\n width: dock.min('horizontal'),\n height: dock.min('vertical'),\n })\n}\n\nconst zone = registerTabDropZone({\n el: () => el.value,\n accepts: (drag) => drag.group === dock.group,\n over(drag, x, y) {\n const side = sideAt(x, y)\n const next = dock.canDrop(drag, props.group, side) ? side : null\n target.value = next\n centerMergeTarget.value =\n next === 'center' ? (dock.mergeTarget(drag, props.group) ?? null) : null\n },\n leave() {\n target.value = null\n centerMergeTarget.value = null\n },\n drop(drag) {\n const side = target.value\n target.value = null\n centerMergeTarget.value = null\n if (side) dock.drop(drag, props.group, side)\n },\n})\nonMounted(() => zone.update())\nonUpdated(() => zone.update())\nonBeforeUnmount(() => zone.remove())\n\n/** Renders what a slot of the dock gives back, under one component type so it is not remounted. */\nconst Outlet: FunctionalComponent<{ render: () => unknown }> = (outlet) =>\n outlet.render() as ReturnType<FunctionalComponent>\n\nconst label = (value: string | number) => dock.panel(value)?.label ?? String(value)\n</script>\n\n<template>\n <div\n ref=\"el\"\n :class=\"[ns.e('group'), ns.is('empty', !group.tabs.length)]\"\n :data-dock-group=\"group.id\"\n @pointerdown.capture=\"dock.use(group.id)\"\n @focusin=\"dock.use(group.id)\"\n >\n <DouTabs\n :model-value=\"group.active ?? group.tabs[0]\"\n :name=\"group.id\"\n :group=\"dock.group\"\n :size=\"dock.size()\"\n :closable=\"dock.closable()\"\n :addable=\"dock.addable()\"\n height=\"100%\"\n :draggable=\"dock.draggable()\"\n @update:model-value=\"$event !== undefined && dock.select(group, $event)\"\n @move=\"dock.move\"\n @remove=\"dock.remove($event, group)\"\n @add=\"dock.add(group)\"\n >\n <DouTabPanel\n v-for=\"value in group.tabs\"\n :key=\"value\"\n :value=\"value\"\n :label=\"label(value)\"\n :icon=\"dock.panel(value)?.icon\"\n :closable=\"dock.panel(value)?.closable\"\n :disabled=\"dock.panel(value)?.disabled\"\n :draggable=\"dock.panel(value)?.draggable\"\n :pinned=\"dock.panel(value)?.pinned\"\n >\n <template v-if=\"slotted.label\" #label=\"{ selected }\">\n <Outlet :render=\"() => dock.slots.label?.({ value, selected })\" />\n </template>\n <Outlet :render=\"() => dock.slots.default?.({ value })\" />\n </DouTabPanel>\n <template v-if=\"slotted.extra\" #extra>\n <Outlet\n :render=\"() => dock.slots.extra?.({ group, active: group.active ?? group.tabs[0] })\"\n />\n </template>\n </DouTabs>\n <div v-if=\"!group.tabs.length && slotted.empty\" :class=\"ns.e('empty')\">\n <Outlet :render=\"() => dock.slots.empty?.()\" />\n </div>\n <div\n :class=\"[ns.e('drop'), target && ns.is(target, true), ns.is('shown', !!target)]\"\n aria-hidden=\"true\"\n />\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;EAaA,MAAM,QAAQ;EAKd,MAAM,OAAO,OAAO,OAAO;EAC3B,MAAM,KAAK,aAAa,MAAM;EAC9B,MAAM,oBAAoB,IAAsB,IAAI;EACpD,QAAQ,mBAAmB;GACzB,UAAU,SAAS,KAAK,YAAY,MAAM,MAAM,KAAK;GACrD,QAAQ;EACV,CAAC;EAID,MAAM,KAAK,eAA4B,IAAI;EAC3C,MAAM,SAAS,IAAgC,IAAI;EAEnD,SAAS,OAAO,GAAW,GAAW;GACpC,OAAO,aAAa,GAAG,MAAO,sBAAsB,GAAG,GAAG,GAAG;IAC3D,OAAO,KAAK,IAAI,YAAY;IAC5B,QAAQ,KAAK,IAAI,UAAU;GAC7B,CAAC;EACH;EAEA,MAAM,OAAO,oBAAoB;GAC/B,UAAU,GAAG;GACb,UAAU,SAAS,KAAK,UAAU,KAAK;GACvC,KAAK,MAAM,GAAG,GAAG;IACf,MAAM,OAAO,OAAO,GAAG,CAAC;IACxB,MAAM,OAAO,KAAK,QAAQ,MAAM,MAAM,OAAO,IAAI,IAAI,OAAO;IAC5D,OAAO,QAAQ;IACf,kBAAkB,QAChB,SAAS,WAAY,KAAK,YAAY,MAAM,MAAM,KAAK,KAAK,OAAQ;G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MAAK,QAAU,QAAA,MAAM,UAAU,QAAA,MAAM,KAAI;KAAA,CAAA,E;;;;;;;;;;;;IAIvE,CAAA,QAAA,MAAM,KAAK,UAAU,QAAA,QAAQ,SAAzCH,UAAA,GAAAC,mBAEM,OAAA;;KAF2C,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,CAAA;I,IAC1DC,YAA+C,QAAA,EAAtC,cAAcD,MAAA,IAAA,CAAI,CAAC,MAAM,QAAK,E;IAEzCQ,mBAGE,OAAA;KAFC,OAAKT,eAAA;MAAGC,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA;MAAU,OAAA,SAAUA,MAAA,EAAA,CAAE,CAAC,GAAG,OAAA,OAAM,IAAA;MAASA,MAAA,EAAA,CAAE,CAAC,GAAE,SAAA,CAAA,CAAY,OAAA,KAAM;KAAA,CAAA;KAC7E,eAAY"}
@@ -1 +1 @@
1
- {"version":3,"file":"dock.js","names":["_sfc_main"],"sources":["../../../src/components/dock/dock.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n nextTick,\n provide,\n shallowReactive,\n useId,\n useTemplateRef,\n watch,\n watchEffect,\n} from 'vue'\nimport { useResizeObserver } from '../../composables/use-element-size'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { dockKey } from './context'\nimport { roomForSplit } from './drop-side'\nimport DockGroupView from './dock-group.vue'\nimport DockNodeView from './dock-node.vue'\nimport {\n dockGroups,\n findDockGroup,\n moveDockTab,\n nextDockGroupId,\n replaceDockNode,\n selectDockTab,\n splitDockTab,\n} from './layout'\nimport { isIgnoredDragPress, pressTab } from '../tabs/tab-drag'\nimport type { SplitterLimit } from '../splitter/splitter'\nimport type { TabDrag } from '../tabs/tab-drag'\nimport type { TabsMoveEvent, TabsValue } from '../tabs/tabs'\nimport type { DockDropItem, DockEmits, DockExpose, DockPanel, DockProps, DockSlots } from './dock'\nimport type { DockGroup, DockNode, DockSide } from './layout'\n\ndefineOptions({ name: 'DouDock' })\n\nconst DEFAULT_MIN = '120px'\n\nconst props = withDefaults(defineProps<DockProps>(), {\n panels: () => [],\n closable: false,\n addable: false,\n draggable: true,\n min: DEFAULT_MIN,\n})\nconst emit = defineEmits<Omit<DockEmits, 'update:activeGroup'>>()\nconst activeGroup = defineModel<string>('activeGroup')\nconst slots = defineSlots<DockSlots>()\n\nconst ns = useNamespace('dock')\nconst group = `dou-dock-${useId()}`\n\n// Changes made in one go (a drop moves a tab and selects it) build on\n// each other before the new layout comes back through the prop.\nlet latest = props.modelValue\nwatch(\n () => props.modelValue,\n (value) => (latest = value),\n)\nfunction commit(next: DockNode) {\n if (next === latest) return\n latest = next\n emit('update:modelValue', next)\n // a parent that turned the change down keeps its layout: build on that from now on\n void nextTick(() => (latest = props.modelValue))\n}\n\nconst panels = computed(() => new Map(props.panels.map((entry) => [entry.value, entry])))\nfunction panel(value: TabsValue): DockPanel | undefined {\n const found = panels.value.get(value)\n if (!found && process.env.NODE_ENV !== 'production')\n devWarn(\n `[dou-ui] DouDock: the tab \"${value}\" has no entry in \\`panels\\`; it is named by its value.`,\n )\n return found\n}\n\n/** Where a tab is now. */\nfunction locate(value: TabsValue) {\n const found = findDockGroup(latest, value)\n return found && { group: found.id, index: found.tabs.indexOf(value) }\n}\n\nfunction move(event: TabsMoveEvent) {\n const from = locate(event.value) ?? null\n const to = event.to.name\n if (to === undefined) return\n const index = event.to.index\n commit(moveDockTab(latest, event.value, to, index))\n emit('move', { value: event.value, from, to: { group: to, index } })\n use(to)\n}\n\nfunction canDrop(drag: TabDrag, target: DockGroup, side: DockSide | 'center') {\n const from = findDockGroup(latest, drag.value)\n // not in the layout yet: it opens anywhere\n if (!from) return true\n // the middle of its own group, or an edge of a group it is alone in, leaves it where it is\n if (from.id === target.id) return side !== 'center' && target.tabs.length > 1\n return true\n}\n\nfunction pinnedInsertIndex(target: DockGroup) {\n let index = 0\n for (let i = 0; i < target.tabs.length; i++) {\n if (panels.value.get(target.tabs[i]!)?.pinned) index = i + 1\n }\n return index\n}\n\nfunction drop(drag: TabDrag, target: DockGroup, side: DockSide | 'center') {\n const from = locate(drag.value) ?? null\n if (!canDrop(drag, target, side)) return\n if (side === 'center') {\n const index = drag.pinned ? pinnedInsertIndex(target) : target.tabs.length\n commit(moveDockTab(latest, drag.value, target.id, index))\n emit('move', { value: drag.value, from, to: { group: target.id, index } })\n use(target.id)\n return\n }\n const id = props.createId?.(latest) ?? nextDockGroupId(latest)\n commit(splitDockTab(latest, drag.value, target.id, side, id))\n emit('split', { value: drag.value, from, target: target.id, side, group: id })\n use(id)\n}\n\n/* the group last used */\n\nfunction use(id: string | undefined) {\n // also unbound, it emits only a change\n if (id !== activeGroup.value) activeGroup.value = id\n}\n// a group dragged empty or closed, or one never in the layout, is not the one to open things in\nwatch(\n () =>\n activeGroup.value !== undefined && !findGroup(props.modelValue, activeGroup.value)\n ? activeGroup.value\n : undefined,\n (stale) => stale !== undefined && use(undefined),\n { immediate: true },\n)\n\n// Each group is rendered here, in one flat list, and teleported into its\n// place in the layout: splitting or merging the parts around a group moves\n// it, and its content (state, scroll position) stays as it is.\nconst groups = computed(() => dockGroups(props.modelValue))\nfunction findGroup(layout: DockNode, id: string) {\n return dockGroups(layout).some((item) => item.id === id)\n}\nconst cells = shallowReactive(new Map<string, HTMLElement>())\nfunction setCell(id: string, el: unknown) {\n if (el instanceof HTMLElement) {\n if (cells.get(id) !== el) cells.set(id, el)\n } else if (cells.has(id) && !cells.get(id)!.isConnected) {\n cells.delete(id)\n sizes.delete(id)\n }\n}\n\n// Moving a group in the page resets what scrolled inside it: note the\n// offsets before a change of shape moves groups, and put them back after.\nconst shape = (node: DockNode): string =>\n node.type === 'group' ? node.id : `${node.direction[0]}(${shape(node.start)},${shape(node.end)})`\nlet scrolled: [Element, number, number][] = []\nwatch(\n () => shape(props.modelValue),\n () => {\n scrolled = []\n for (const cell of cells.values())\n for (const el of cell.querySelectorAll('*'))\n if (el.scrollTop || el.scrollLeft) scrolled.push([el, el.scrollTop, el.scrollLeft])\n },\n { flush: 'pre' },\n)\nwatch(\n () => shape(props.modelValue),\n () => {\n const notes = scrolled\n scrolled = []\n const restore = () => {\n for (const [el, top, left] of notes) {\n el.scrollTop = top\n el.scrollLeft = left\n }\n }\n restore()\n // a group whose place appears in this update moves in on the next one\n void nextTick(restore)\n },\n { flush: 'post' },\n)\n\n/* dragging something from outside the dock in */\n\nconst root = useTemplateRef<HTMLElement>('root')\nconst RAPID_REPEAT_MS = 400\nconst RAPID_REPEAT_PX = 8\nlet lastDropPress: { time: number; x: number; y: number } | null = null\n\nfunction isRapidRepeat(event: PointerEvent) {\n const now = Date.now()\n const x = event.clientX\n const y = event.clientY\n const repeated =\n event.detail > 1 ||\n (lastDropPress !== null &&\n now - lastDropPress.time <= RAPID_REPEAT_MS &&\n Math.hypot(x - lastDropPress.x, y - lastDropPress.y) <= RAPID_REPEAT_PX)\n lastDropPress = { time: now, x, y }\n return repeated\n}\n\nfunction startDrop(event: PointerEvent, item: DockDropItem) {\n if (isIgnoredDragPress(event)) return\n // `currentTarget` is gone once the handler returns, after an `await`: then the element pressed\n const target = event.currentTarget ?? event.target\n if (!(target instanceof HTMLElement || target instanceof SVGElement)) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouDock: `startDrop` needs the `pointerdown` event of an element, to know what was pressed.',\n )\n return\n }\n const entry = panels.value.get(item.value)\n if (!props.draggable || entry?.disabled || entry?.draggable === false) {\n if (process.env.NODE_ENV !== 'production' && props.draggable)\n devWarn(\n `[dou-ui] DouDock: \\`startDrop\\` for \"${item.value}\" does nothing, as its panel is ${entry?.disabled ? 'disabled' : 'not draggable'}.`,\n )\n return\n }\n if (isRapidRepeat(event)) return\n const label = item.label ?? entry?.label ?? String(item.value)\n // the browser's own drag of a link or an image would take the pointer away\n target.addEventListener('dragstart', noNativeDrag)\n const release = () => {\n target.removeEventListener('dragstart', noNativeDrag)\n window.removeEventListener('pointerup', release, true)\n window.removeEventListener('pointercancel', release, true)\n }\n window.addEventListener('pointerup', release, true)\n window.addEventListener('pointercancel', release, true)\n let dragged = false\n pressTab(event, {\n el: target as HTMLElement,\n root: target as HTMLElement,\n ghost: { label, tabs: root.value?.querySelector<HTMLElement>('.dou-tabs') },\n drag: () => {\n // open already: a drag of it from its group, so dropping it back in its place does nothing\n const from = locate(item.value)\n return {\n value: item.value,\n label,\n group,\n name: from?.group,\n index: from?.index ?? -1,\n source: target,\n pinned: !!entry?.pinned,\n }\n },\n onStart: () => {\n dragged = true\n lastDropPress = null\n },\n onEnd() {\n if (!dragged) return\n // the release that ends a drag is not a click on the element\n window.addEventListener('click', swallow, { capture: true, once: true })\n setTimeout(() => window.removeEventListener('click', swallow, { capture: true }), 0)\n },\n })\n}\nconst noNativeDrag = (e: Event) => e.preventDefault()\nconst swallow = (click: Event) => {\n click.stopPropagation()\n click.preventDefault()\n}\n\nfunction minFor(direction: 'horizontal' | 'vertical'): SplitterLimit {\n const min = props.min\n if (typeof min !== 'object') return min\n return (direction === 'horizontal' ? min.width : min.height) ?? DEFAULT_MIN\n}\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n for (const direction of ['horizontal', 'vertical'] as const) {\n const min = minFor(direction)\n if (typeof min === 'number' && min > 50)\n devWarn(\n `[dou-ui] DouDock: \\`min\\` of ${min} is a percent, so no group can be split ${direction === 'horizontal' ? 'side by side' : 'top to bottom'}. Write '${min}px' for px.`,\n )\n }\n })\n\n// the size of each group's place, kept up to date so `canSplit` can be read in a render\nconst sizes = shallowReactive(new Map<string, { width: number; height: number }>())\nuseResizeObserver(\n () => [...cells.values()],\n (entries) => {\n for (const entry of entries)\n for (const [id, el] of cells)\n if (el === entry.target) {\n const box = entry.borderBoxSize?.[0]\n sizes.set(id, {\n width: box ? box.inlineSize : entry.contentRect.width,\n height: box ? box.blockSize : entry.contentRect.height,\n })\n }\n },\n { box: 'border-box' },\n)\n\n/**\n * Whether a group has room to split a tab off to `side`: two parts of\n * `min` beside the divider, as dragging to its edge checks. Reactive.\n */\nfunction canSplit(groupId: string, side: DockSide) {\n const el = cells.get(groupId)\n if (!el) return false\n const across = side === 'left' || side === 'right'\n const size = sizes.get(groupId) ?? el.getBoundingClientRect()\n return roomForSplit(across ? size.width : size.height, minFor(across ? 'horizontal' : 'vertical'))\n}\ndefineExpose<DockExpose>({ canSplit, startDrop })\n\nprovide(dockKey, {\n group,\n size: () => props.size,\n closable: () => props.closable,\n addable: () => props.addable,\n min: minFor,\n draggable: () => props.draggable,\n panel,\n slots,\n resize: (node, size) => commit(replaceDockNode(latest, node, { ...node, size })),\n select(target, value) {\n if (findDockGroup(latest, value)?.id === target.id) commit(selectDockTab(latest, value))\n },\n move,\n canDrop,\n drop,\n remove: (value, target) => emit('remove', value, target.id),\n add: (target) => emit('add', target.id),\n use,\n setCell,\n})\n</script>\n\n<template>\n <div ref=\"root\" :class=\"ns.b()\">\n <DockNodeView :node=\"modelValue\" />\n <!-- until its place exists (and on the server) a group renders right here -->\n <Teleport\n v-for=\"item in groups\"\n :key=\"item.id\"\n :to=\"cells.get(item.id) ?? 'body'\"\n :disabled=\"!cells.get(item.id)\"\n >\n <DockGroupView\n :group=\"item\"\n :slotted=\"{ label: !!$slots.label, extra: !!$slots.extra, empty: !!$slots.empty }\"\n />\n </Teleport>\n </div>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"dock.js","names":["_sfc_main"],"sources":["../../../src/components/dock/dock.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n nextTick,\n provide,\n shallowReactive,\n useId,\n useTemplateRef,\n watch,\n watchEffect,\n} from 'vue'\nimport { useResizeObserver } from '../../composables/use-element-size'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { dockKey } from './context'\nimport { roomForSplit } from './drop-side'\nimport DockGroupView from './dock-group.vue'\nimport DockNodeView from './dock-node.vue'\nimport {\n dockGroups,\n findDockGroup,\n mergeDockTab,\n moveDockTab,\n nextDockGroupId,\n replaceDockNode,\n selectDockTab,\n splitDockTab,\n} from './layout'\nimport { isIgnoredDragPress, pressTab } from '../tabs/tab-drag'\nimport type { SplitterLimit } from '../splitter/splitter'\nimport type { TabDrag } from '../tabs/tab-drag'\nimport type { TabsMoveEvent, TabsValue } from '../tabs/tabs'\nimport type {\n DockDropItem,\n DockEmits,\n DockExpose,\n DockLocation,\n DockPanel,\n DockProps,\n DockSlots,\n} from './dock'\nimport type { DockGroup, DockNode, DockSide } from './layout'\n\ndefineOptions({ name: 'DouDock' })\n\nconst DEFAULT_MIN = '120px'\n\nconst props = withDefaults(defineProps<DockProps>(), {\n panels: () => [],\n closable: false,\n addable: false,\n draggable: true,\n min: DEFAULT_MIN,\n})\nconst emit = defineEmits<Omit<DockEmits, 'update:activeGroup'>>()\nconst activeGroup = defineModel<string>('activeGroup')\nconst slots = defineSlots<DockSlots>()\n\nconst ns = useNamespace('dock')\nconst group = `dou-dock-${useId()}`\n\n// Changes made in one go (a drop moves a tab and selects it) build on\n// each other before the new layout comes back through the prop.\nlet latest = props.modelValue\nwatch(\n () => props.modelValue,\n (value) => (latest = value),\n)\nfunction commit(next: DockNode) {\n if (next === latest) return\n latest = next\n emit('update:modelValue', next)\n // a parent that turned the change down keeps its layout: build on that from now on\n void nextTick(() => (latest = props.modelValue))\n}\n\nconst panels = computed(() => new Map(props.panels.map((entry) => [entry.value, entry])))\nfunction panel(value: TabsValue): DockPanel | undefined {\n const found = panels.value.get(value)\n if (!found && process.env.NODE_ENV !== 'production')\n devWarn(\n `[dou-ui] DouDock: the tab \"${value}\" has no entry in \\`panels\\`; it is named by its value.`,\n )\n return found\n}\n\n/** Where a tab is now. */\nfunction locate(value: TabsValue) {\n const found = findDockGroup(latest, value)\n return found && { group: found.id, index: found.tabs.indexOf(value) }\n}\n\n/**\n * Find an existing tab in `target` that shares `value`'s `mergeId` when `value`\n * comes from another group or from outside the dock. Prefers a pinned tab.\n */\nfunction findMergeTarget(target: DockGroup, value: TabsValue): TabsValue | undefined {\n const source = panels.value.get(value)\n if (source?.mergeId === undefined) return undefined\n const from = findDockGroup(latest, value)\n if (from?.id === target.id) return undefined\n let fallback: TabsValue | undefined\n for (const tab of target.tabs) {\n if (tab === value) continue\n const entry = panels.value.get(tab)\n if (entry?.mergeId !== source.mergeId || entry.disabled) continue\n if (entry.pinned) return tab\n if (fallback === undefined) fallback = tab\n }\n return fallback\n}\n\nfunction performMove(\n value: TabsValue,\n from: DockLocation | null,\n targetGroup: DockGroup,\n index: number,\n) {\n const autoMerge = findMergeTarget(targetGroup, value)\n let resolvedMerge = autoMerge\n if (props.beforeMove) {\n const decision = props.beforeMove({\n value,\n from,\n to: { group: targetGroup.id, index },\n targetGroup,\n mergeInto: autoMerge,\n })\n if (decision === false) return\n if (typeof decision === 'object' && decision !== null && 'mergeInto' in decision) {\n resolvedMerge = decision.mergeInto ?? undefined\n }\n }\n if (resolvedMerge !== undefined) {\n if (!targetGroup.tabs.includes(resolvedMerge)) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n `[dou-ui] DouDock: \\`beforeMove\\` returned \\`mergeInto: \"${resolvedMerge}\"\\`, which is not in group \"${targetGroup.id}\". The move was cancelled.`,\n )\n return\n }\n const next = mergeDockTab(latest, value, resolvedMerge)\n const mergedIndex = findDockGroup(next, resolvedMerge)?.tabs.indexOf(resolvedMerge) ?? 0\n commit(next)\n emit('move', {\n value,\n from,\n to: { group: targetGroup.id, index: mergedIndex },\n mergedInto: resolvedMerge,\n })\n use(targetGroup.id)\n return\n }\n commit(moveDockTab(latest, value, targetGroup.id, index))\n emit('move', { value, from, to: { group: targetGroup.id, index } })\n use(targetGroup.id)\n}\n\nfunction move(event: TabsMoveEvent) {\n const from = locate(event.value) ?? null\n const to = event.to.name\n if (to === undefined) return\n const targetGroup = dockGroups(latest).find((item) => item.id === to)\n if (!targetGroup) return\n performMove(event.value, from, targetGroup, event.to.index)\n}\n\nfunction canDrop(drag: TabDrag, target: DockGroup, side: DockSide | 'center') {\n const from = findDockGroup(latest, drag.value)\n // not in the layout yet: it opens anywhere\n if (!from) return true\n // the middle of its own group, or an edge of a group it is alone in, leaves it where it is\n if (from.id === target.id) return side !== 'center' && target.tabs.length > 1\n return true\n}\n\nfunction pinnedInsertIndex(target: DockGroup) {\n let index = 0\n for (let i = 0; i < target.tabs.length; i++) {\n if (panels.value.get(target.tabs[i]!)?.pinned) index = i + 1\n }\n return index\n}\n\nfunction drop(drag: TabDrag, target: DockGroup, side: DockSide | 'center') {\n const from = locate(drag.value) ?? null\n if (!canDrop(drag, target, side)) return\n if (side === 'center') {\n const index = drag.pinned ? pinnedInsertIndex(target) : target.tabs.length\n performMove(drag.value, from, target, index)\n return\n }\n const id = props.createId?.(latest) ?? nextDockGroupId(latest)\n commit(splitDockTab(latest, drag.value, target.id, side, id))\n emit('split', { value: drag.value, from, target: target.id, side, group: id })\n use(id)\n}\n\n/* the group last used */\n\nfunction use(id: string | undefined) {\n // also unbound, it emits only a change\n if (id !== activeGroup.value) activeGroup.value = id\n}\n// a group dragged empty or closed, or one never in the layout, is not the one to open things in\nwatch(\n () =>\n activeGroup.value !== undefined && !findGroup(props.modelValue, activeGroup.value)\n ? activeGroup.value\n : undefined,\n (stale) => stale !== undefined && use(undefined),\n { immediate: true },\n)\n\n// Each group is rendered here, in one flat list, and teleported into its\n// place in the layout: splitting or merging the parts around a group moves\n// it, and its content (state, scroll position) stays as it is.\nconst groups = computed(() => dockGroups(props.modelValue))\nfunction findGroup(layout: DockNode, id: string) {\n return dockGroups(layout).some((item) => item.id === id)\n}\nconst cells = shallowReactive(new Map<string, HTMLElement>())\nfunction setCell(id: string, el: unknown) {\n if (el instanceof HTMLElement) {\n if (cells.get(id) !== el) cells.set(id, el)\n } else if (cells.has(id) && !cells.get(id)!.isConnected) {\n cells.delete(id)\n sizes.delete(id)\n }\n}\n\n// Moving a group in the page resets what scrolled inside it: note the\n// offsets before a change of shape moves groups, and put them back after.\nconst shape = (node: DockNode): string =>\n node.type === 'group' ? node.id : `${node.direction[0]}(${shape(node.start)},${shape(node.end)})`\nlet scrolled: [Element, number, number][] = []\nwatch(\n () => shape(props.modelValue),\n () => {\n scrolled = []\n for (const cell of cells.values())\n for (const el of cell.querySelectorAll('*'))\n if (el.scrollTop || el.scrollLeft) scrolled.push([el, el.scrollTop, el.scrollLeft])\n },\n { flush: 'pre' },\n)\nwatch(\n () => shape(props.modelValue),\n () => {\n const notes = scrolled\n scrolled = []\n const restore = () => {\n for (const [el, top, left] of notes) {\n el.scrollTop = top\n el.scrollLeft = left\n }\n }\n restore()\n // a group whose place appears in this update moves in on the next one\n void nextTick(restore)\n },\n { flush: 'post' },\n)\n\n/* dragging something from outside the dock in */\n\nconst root = useTemplateRef<HTMLElement>('root')\nconst RAPID_REPEAT_MS = 400\nconst RAPID_REPEAT_PX = 8\nlet lastDropPress: { time: number; x: number; y: number } | null = null\n\nfunction isRapidRepeat(event: PointerEvent) {\n const now = Date.now()\n const x = event.clientX\n const y = event.clientY\n const repeated =\n event.detail > 1 ||\n (lastDropPress !== null &&\n now - lastDropPress.time <= RAPID_REPEAT_MS &&\n Math.hypot(x - lastDropPress.x, y - lastDropPress.y) <= RAPID_REPEAT_PX)\n lastDropPress = { time: now, x, y }\n return repeated\n}\n\nfunction startDrop(event: PointerEvent, item: DockDropItem) {\n if (isIgnoredDragPress(event)) return\n // `currentTarget` is gone once the handler returns, after an `await`: then the element pressed\n const target = event.currentTarget ?? event.target\n if (!(target instanceof HTMLElement || target instanceof SVGElement)) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouDock: `startDrop` needs the `pointerdown` event of an element, to know what was pressed.',\n )\n return\n }\n const entry = panels.value.get(item.value)\n if (!props.draggable || entry?.disabled || entry?.draggable === false) {\n if (process.env.NODE_ENV !== 'production' && props.draggable)\n devWarn(\n `[dou-ui] DouDock: \\`startDrop\\` for \"${item.value}\" does nothing, as its panel is ${entry?.disabled ? 'disabled' : 'not draggable'}.`,\n )\n return\n }\n if (isRapidRepeat(event)) return\n const label = item.label ?? entry?.label ?? String(item.value)\n // the browser's own drag of a link or an image would take the pointer away\n target.addEventListener('dragstart', noNativeDrag)\n const release = () => {\n target.removeEventListener('dragstart', noNativeDrag)\n window.removeEventListener('pointerup', release, true)\n window.removeEventListener('pointercancel', release, true)\n }\n window.addEventListener('pointerup', release, true)\n window.addEventListener('pointercancel', release, true)\n let dragged = false\n pressTab(event, {\n el: target as HTMLElement,\n root: target as HTMLElement,\n ghost: { label, tabs: root.value?.querySelector<HTMLElement>('.dou-tabs') },\n drag: () => {\n // open already: a drag of it from its group, so dropping it back in its place does nothing\n const from = locate(item.value)\n return {\n value: item.value,\n label,\n group,\n name: from?.group,\n index: from?.index ?? -1,\n source: target,\n pinned: !!entry?.pinned,\n }\n },\n onStart: () => {\n dragged = true\n lastDropPress = null\n },\n onEnd() {\n if (!dragged) return\n // the release that ends a drag is not a click on the element\n window.addEventListener('click', swallow, { capture: true, once: true })\n setTimeout(() => window.removeEventListener('click', swallow, { capture: true }), 0)\n },\n })\n}\nconst noNativeDrag = (e: Event) => e.preventDefault()\nconst swallow = (click: Event) => {\n click.stopPropagation()\n click.preventDefault()\n}\n\nfunction minFor(direction: 'horizontal' | 'vertical'): SplitterLimit {\n const min = props.min\n if (typeof min !== 'object') return min\n return (direction === 'horizontal' ? min.width : min.height) ?? DEFAULT_MIN\n}\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n for (const direction of ['horizontal', 'vertical'] as const) {\n const min = minFor(direction)\n if (typeof min === 'number' && min > 50)\n devWarn(\n `[dou-ui] DouDock: \\`min\\` of ${min} is a percent, so no group can be split ${direction === 'horizontal' ? 'side by side' : 'top to bottom'}. Write '${min}px' for px.`,\n )\n }\n })\n\n// the size of each group's place, kept up to date so `canSplit` can be read in a render\nconst sizes = shallowReactive(new Map<string, { width: number; height: number }>())\nuseResizeObserver(\n () => [...cells.values()],\n (entries) => {\n for (const entry of entries)\n for (const [id, el] of cells)\n if (el === entry.target) {\n const box = entry.borderBoxSize?.[0]\n sizes.set(id, {\n width: box ? box.inlineSize : entry.contentRect.width,\n height: box ? box.blockSize : entry.contentRect.height,\n })\n }\n },\n { box: 'border-box' },\n)\n\n/**\n * Whether a group has room to split a tab off to `side`: two parts of\n * `min` beside the divider, as dragging to its edge checks. Reactive.\n */\nfunction canSplit(groupId: string, side: DockSide) {\n const el = cells.get(groupId)\n if (!el) return false\n const across = side === 'left' || side === 'right'\n const size = sizes.get(groupId) ?? el.getBoundingClientRect()\n return roomForSplit(across ? size.width : size.height, minFor(across ? 'horizontal' : 'vertical'))\n}\ndefineExpose<DockExpose>({ canSplit, startDrop })\n\nprovide(dockKey, {\n group,\n size: () => props.size,\n closable: () => props.closable,\n addable: () => props.addable,\n min: minFor,\n draggable: () => props.draggable,\n panel,\n slots,\n resize: (node, size) => commit(replaceDockNode(latest, node, { ...node, size })),\n select(target, value) {\n if (findDockGroup(latest, value)?.id === target.id) commit(selectDockTab(latest, value))\n },\n move,\n mergeTarget: (drag, target) => findMergeTarget(target, drag.value),\n canDrop,\n drop,\n remove: (value, target) => emit('remove', value, target.id),\n add: (target) => emit('add', target.id),\n use,\n setCell,\n})\n</script>\n\n<template>\n <div ref=\"root\" :class=\"ns.b()\">\n <DockNodeView :node=\"modelValue\" />\n <!-- until its place exists (and on the server) a group renders right here -->\n <Teleport\n v-for=\"item in groups\"\n :key=\"item.id\"\n :to=\"cells.get(item.id) ?? 'body'\"\n :disabled=\"!cells.get(item.id)\"\n >\n <DockGroupView\n :group=\"item\"\n :slotted=\"{ label: !!$slots.label, extra: !!$slots.extra, empty: !!$slots.empty }\"\n />\n </Teleport>\n </div>\n</template>\n"],"mappings":""}
@@ -6,7 +6,7 @@ import { roomForSplit } from "./drop-side.js";
6
6
  import { isIgnoredDragPress, pressTab } from "../tabs/tab-drag.js";
7
7
  import dock_group_default from "./dock-group.js";
8
8
  import dock_node_default from "./dock-node.js";
9
- import { dockGroups, findDockGroup, moveDockTab, nextDockGroupId, replaceDockNode, selectDockTab, splitDockTab } from "./layout.js";
9
+ import { dockGroups, findDockGroup, mergeDockTab, moveDockTab, nextDockGroupId, replaceDockNode, selectDockTab, splitDockTab } from "./layout.js";
10
10
  import { Fragment, Teleport, computed, createBlock, createElementBlock, createVNode, defineComponent, mergeModels, nextTick, normalizeClass, openBlock, provide, renderList, shallowReactive, unref, useId, useModel, useSlots, useTemplateRef, watch, watchEffect } from "vue";
11
11
  // src/components/dock/dock.vue?vue&type=script&setup=true&lang.ts
12
12
  var DEFAULT_MIN = "120px";
@@ -33,7 +33,8 @@ var dock_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
33
33
  },
34
34
  min: { default: DEFAULT_MIN },
35
35
  activeGroup: {},
36
- createId: {}
36
+ createId: {},
37
+ beforeMove: {}
37
38
  }, {
38
39
  "activeGroup": {},
39
40
  "activeGroupModifiers": {}
@@ -74,21 +75,79 @@ var dock_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
74
75
  index: found.tabs.indexOf(value)
75
76
  };
76
77
  }
77
- function move(event) {
78
- const from = locate(event.value) ?? null;
79
- const to = event.to.name;
80
- if (to === void 0) return;
81
- const index = event.to.index;
82
- commit(moveDockTab(latest, event.value, to, index));
78
+ /**
79
+ * Find an existing tab in `target` that shares `value`'s `mergeId` when `value`
80
+ * comes from another group or from outside the dock. Prefers a pinned tab.
81
+ */
82
+ function findMergeTarget(target, value) {
83
+ const source = panels.value.get(value);
84
+ if (source?.mergeId === void 0) return void 0;
85
+ if (findDockGroup(latest, value)?.id === target.id) return void 0;
86
+ let fallback;
87
+ for (const tab of target.tabs) {
88
+ if (tab === value) continue;
89
+ const entry = panels.value.get(tab);
90
+ if (entry?.mergeId !== source.mergeId || entry.disabled) continue;
91
+ if (entry.pinned) return tab;
92
+ if (fallback === void 0) fallback = tab;
93
+ }
94
+ return fallback;
95
+ }
96
+ function performMove(value, from, targetGroup, index) {
97
+ const autoMerge = findMergeTarget(targetGroup, value);
98
+ let resolvedMerge = autoMerge;
99
+ if (props.beforeMove) {
100
+ const decision = props.beforeMove({
101
+ value,
102
+ from,
103
+ to: {
104
+ group: targetGroup.id,
105
+ index
106
+ },
107
+ targetGroup,
108
+ mergeInto: autoMerge
109
+ });
110
+ if (decision === false) return;
111
+ if (typeof decision === "object" && decision !== null && "mergeInto" in decision) resolvedMerge = decision.mergeInto ?? void 0;
112
+ }
113
+ if (resolvedMerge !== void 0) {
114
+ if (!targetGroup.tabs.includes(resolvedMerge)) {
115
+ if (process.env.NODE_ENV !== "production") devWarn(`[dou-ui] DouDock: \`beforeMove\` returned \`mergeInto: "${resolvedMerge}"\`, which is not in group "${targetGroup.id}". The move was cancelled.`);
116
+ return;
117
+ }
118
+ const next = mergeDockTab(latest, value, resolvedMerge);
119
+ const mergedIndex = findDockGroup(next, resolvedMerge)?.tabs.indexOf(resolvedMerge) ?? 0;
120
+ commit(next);
121
+ emit("move", {
122
+ value,
123
+ from,
124
+ to: {
125
+ group: targetGroup.id,
126
+ index: mergedIndex
127
+ },
128
+ mergedInto: resolvedMerge
129
+ });
130
+ use(targetGroup.id);
131
+ return;
132
+ }
133
+ commit(moveDockTab(latest, value, targetGroup.id, index));
83
134
  emit("move", {
84
- value: event.value,
135
+ value,
85
136
  from,
86
137
  to: {
87
- group: to,
138
+ group: targetGroup.id,
88
139
  index
89
140
  }
90
141
  });
91
- use(to);
142
+ use(targetGroup.id);
143
+ }
144
+ function move(event) {
145
+ const from = locate(event.value) ?? null;
146
+ const to = event.to.name;
147
+ if (to === void 0) return;
148
+ const targetGroup = dockGroups(latest).find((item) => item.id === to);
149
+ if (!targetGroup) return;
150
+ performMove(event.value, from, targetGroup, event.to.index);
92
151
  }
93
152
  function canDrop(drag, target, side) {
94
153
  const from = findDockGroup(latest, drag.value);
@@ -106,16 +165,7 @@ var dock_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
106
165
  if (!canDrop(drag, target, side)) return;
107
166
  if (side === "center") {
108
167
  const index = drag.pinned ? pinnedInsertIndex(target) : target.tabs.length;
109
- commit(moveDockTab(latest, drag.value, target.id, index));
110
- emit("move", {
111
- value: drag.value,
112
- from,
113
- to: {
114
- group: target.id,
115
- index
116
- }
117
- });
118
- use(target.id);
168
+ performMove(drag.value, from, target, index);
119
169
  return;
120
170
  }
121
171
  const id = props.createId?.(latest) ?? nextDockGroupId(latest);
@@ -296,6 +346,7 @@ var dock_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
296
346
  if (findDockGroup(latest, value)?.id === target.id) commit(selectDockTab(latest, value));
297
347
  },
298
348
  move,
349
+ mergeTarget: (drag, target) => findMergeTarget(target, drag.value),
299
350
  canDrop,
300
351
  drop,
301
352
  remove: (value, target) => emit("remove", value, target.id),
@@ -1 +1 @@
1
- {"version":3,"file":"dock.vue_vue_type_script_setup_true_lang.js","names":["$slots","_useModel","_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","_createVNode","DockNodeView","_Fragment","_renderList","_createBlock","_Teleport","DockGroupView"],"sources":["../../../src/components/dock/dock.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n nextTick,\n provide,\n shallowReactive,\n useId,\n useTemplateRef,\n watch,\n watchEffect,\n} from 'vue'\nimport { useResizeObserver } from '../../composables/use-element-size'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { dockKey } from './context'\nimport { roomForSplit } from './drop-side'\nimport DockGroupView from './dock-group.vue'\nimport DockNodeView from './dock-node.vue'\nimport {\n dockGroups,\n findDockGroup,\n moveDockTab,\n nextDockGroupId,\n replaceDockNode,\n selectDockTab,\n splitDockTab,\n} from './layout'\nimport { isIgnoredDragPress, pressTab } from '../tabs/tab-drag'\nimport type { SplitterLimit } from '../splitter/splitter'\nimport type { TabDrag } from '../tabs/tab-drag'\nimport type { TabsMoveEvent, TabsValue } from '../tabs/tabs'\nimport type { DockDropItem, DockEmits, DockExpose, DockPanel, DockProps, DockSlots } from './dock'\nimport type { DockGroup, DockNode, DockSide } from './layout'\n\ndefineOptions({ name: 'DouDock' })\n\nconst DEFAULT_MIN = '120px'\n\nconst props = withDefaults(defineProps<DockProps>(), {\n panels: () => [],\n closable: false,\n addable: false,\n draggable: true,\n min: DEFAULT_MIN,\n})\nconst emit = defineEmits<Omit<DockEmits, 'update:activeGroup'>>()\nconst activeGroup = defineModel<string>('activeGroup')\nconst slots = defineSlots<DockSlots>()\n\nconst ns = useNamespace('dock')\nconst group = `dou-dock-${useId()}`\n\n// Changes made in one go (a drop moves a tab and selects it) build on\n// each other before the new layout comes back through the prop.\nlet latest = props.modelValue\nwatch(\n () => props.modelValue,\n (value) => (latest = value),\n)\nfunction commit(next: DockNode) {\n if (next === latest) return\n latest = next\n emit('update:modelValue', next)\n // a parent that turned the change down keeps its layout: build on that from now on\n void nextTick(() => (latest = props.modelValue))\n}\n\nconst panels = computed(() => new Map(props.panels.map((entry) => [entry.value, entry])))\nfunction panel(value: TabsValue): DockPanel | undefined {\n const found = panels.value.get(value)\n if (!found && process.env.NODE_ENV !== 'production')\n devWarn(\n `[dou-ui] DouDock: the tab \"${value}\" has no entry in \\`panels\\`; it is named by its value.`,\n )\n return found\n}\n\n/** Where a tab is now. */\nfunction locate(value: TabsValue) {\n const found = findDockGroup(latest, value)\n return found && { group: found.id, index: found.tabs.indexOf(value) }\n}\n\nfunction move(event: TabsMoveEvent) {\n const from = locate(event.value) ?? null\n const to = event.to.name\n if (to === undefined) return\n const index = event.to.index\n commit(moveDockTab(latest, event.value, to, index))\n emit('move', { value: event.value, from, to: { group: to, index } })\n use(to)\n}\n\nfunction canDrop(drag: TabDrag, target: DockGroup, side: DockSide | 'center') {\n const from = findDockGroup(latest, drag.value)\n // not in the layout yet: it opens anywhere\n if (!from) return true\n // the middle of its own group, or an edge of a group it is alone in, leaves it where it is\n if (from.id === target.id) return side !== 'center' && target.tabs.length > 1\n return true\n}\n\nfunction pinnedInsertIndex(target: DockGroup) {\n let index = 0\n for (let i = 0; i < target.tabs.length; i++) {\n if (panels.value.get(target.tabs[i]!)?.pinned) index = i + 1\n }\n return index\n}\n\nfunction drop(drag: TabDrag, target: DockGroup, side: DockSide | 'center') {\n const from = locate(drag.value) ?? null\n if (!canDrop(drag, target, side)) return\n if (side === 'center') {\n const index = drag.pinned ? pinnedInsertIndex(target) : target.tabs.length\n commit(moveDockTab(latest, drag.value, target.id, index))\n emit('move', { value: drag.value, from, to: { group: target.id, index } })\n use(target.id)\n return\n }\n const id = props.createId?.(latest) ?? nextDockGroupId(latest)\n commit(splitDockTab(latest, drag.value, target.id, side, id))\n emit('split', { value: drag.value, from, target: target.id, side, group: id })\n use(id)\n}\n\n/* the group last used */\n\nfunction use(id: string | undefined) {\n // also unbound, it emits only a change\n if (id !== activeGroup.value) activeGroup.value = id\n}\n// a group dragged empty or closed, or one never in the layout, is not the one to open things in\nwatch(\n () =>\n activeGroup.value !== undefined && !findGroup(props.modelValue, activeGroup.value)\n ? activeGroup.value\n : undefined,\n (stale) => stale !== undefined && use(undefined),\n { immediate: true },\n)\n\n// Each group is rendered here, in one flat list, and teleported into its\n// place in the layout: splitting or merging the parts around a group moves\n// it, and its content (state, scroll position) stays as it is.\nconst groups = computed(() => dockGroups(props.modelValue))\nfunction findGroup(layout: DockNode, id: string) {\n return dockGroups(layout).some((item) => item.id === id)\n}\nconst cells = shallowReactive(new Map<string, HTMLElement>())\nfunction setCell(id: string, el: unknown) {\n if (el instanceof HTMLElement) {\n if (cells.get(id) !== el) cells.set(id, el)\n } else if (cells.has(id) && !cells.get(id)!.isConnected) {\n cells.delete(id)\n sizes.delete(id)\n }\n}\n\n// Moving a group in the page resets what scrolled inside it: note the\n// offsets before a change of shape moves groups, and put them back after.\nconst shape = (node: DockNode): string =>\n node.type === 'group' ? node.id : `${node.direction[0]}(${shape(node.start)},${shape(node.end)})`\nlet scrolled: [Element, number, number][] = []\nwatch(\n () => shape(props.modelValue),\n () => {\n scrolled = []\n for (const cell of cells.values())\n for (const el of cell.querySelectorAll('*'))\n if (el.scrollTop || el.scrollLeft) scrolled.push([el, el.scrollTop, el.scrollLeft])\n },\n { flush: 'pre' },\n)\nwatch(\n () => shape(props.modelValue),\n () => {\n const notes = scrolled\n scrolled = []\n const restore = () => {\n for (const [el, top, left] of notes) {\n el.scrollTop = top\n el.scrollLeft = left\n }\n }\n restore()\n // a group whose place appears in this update moves in on the next one\n void nextTick(restore)\n },\n { flush: 'post' },\n)\n\n/* dragging something from outside the dock in */\n\nconst root = useTemplateRef<HTMLElement>('root')\nconst RAPID_REPEAT_MS = 400\nconst RAPID_REPEAT_PX = 8\nlet lastDropPress: { time: number; x: number; y: number } | null = null\n\nfunction isRapidRepeat(event: PointerEvent) {\n const now = Date.now()\n const x = event.clientX\n const y = event.clientY\n const repeated =\n event.detail > 1 ||\n (lastDropPress !== null &&\n now - lastDropPress.time <= RAPID_REPEAT_MS &&\n Math.hypot(x - lastDropPress.x, y - lastDropPress.y) <= RAPID_REPEAT_PX)\n lastDropPress = { time: now, x, y }\n return repeated\n}\n\nfunction startDrop(event: PointerEvent, item: DockDropItem) {\n if (isIgnoredDragPress(event)) return\n // `currentTarget` is gone once the handler returns, after an `await`: then the element pressed\n const target = event.currentTarget ?? event.target\n if (!(target instanceof HTMLElement || target instanceof SVGElement)) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouDock: `startDrop` needs the `pointerdown` event of an element, to know what was pressed.',\n )\n return\n }\n const entry = panels.value.get(item.value)\n if (!props.draggable || entry?.disabled || entry?.draggable === false) {\n if (process.env.NODE_ENV !== 'production' && props.draggable)\n devWarn(\n `[dou-ui] DouDock: \\`startDrop\\` for \"${item.value}\" does nothing, as its panel is ${entry?.disabled ? 'disabled' : 'not draggable'}.`,\n )\n return\n }\n if (isRapidRepeat(event)) return\n const label = item.label ?? entry?.label ?? String(item.value)\n // the browser's own drag of a link or an image would take the pointer away\n target.addEventListener('dragstart', noNativeDrag)\n const release = () => {\n target.removeEventListener('dragstart', noNativeDrag)\n window.removeEventListener('pointerup', release, true)\n window.removeEventListener('pointercancel', release, true)\n }\n window.addEventListener('pointerup', release, true)\n window.addEventListener('pointercancel', release, true)\n let dragged = false\n pressTab(event, {\n el: target as HTMLElement,\n root: target as HTMLElement,\n ghost: { label, tabs: root.value?.querySelector<HTMLElement>('.dou-tabs') },\n drag: () => {\n // open already: a drag of it from its group, so dropping it back in its place does nothing\n const from = locate(item.value)\n return {\n value: item.value,\n label,\n group,\n name: from?.group,\n index: from?.index ?? -1,\n source: target,\n pinned: !!entry?.pinned,\n }\n },\n onStart: () => {\n dragged = true\n lastDropPress = null\n },\n onEnd() {\n if (!dragged) return\n // the release that ends a drag is not a click on the element\n window.addEventListener('click', swallow, { capture: true, once: true })\n setTimeout(() => window.removeEventListener('click', swallow, { capture: true }), 0)\n },\n })\n}\nconst noNativeDrag = (e: Event) => e.preventDefault()\nconst swallow = (click: Event) => {\n click.stopPropagation()\n click.preventDefault()\n}\n\nfunction minFor(direction: 'horizontal' | 'vertical'): SplitterLimit {\n const min = props.min\n if (typeof min !== 'object') return min\n return (direction === 'horizontal' ? min.width : min.height) ?? DEFAULT_MIN\n}\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n for (const direction of ['horizontal', 'vertical'] as const) {\n const min = minFor(direction)\n if (typeof min === 'number' && min > 50)\n devWarn(\n `[dou-ui] DouDock: \\`min\\` of ${min} is a percent, so no group can be split ${direction === 'horizontal' ? 'side by side' : 'top to bottom'}. Write '${min}px' for px.`,\n )\n }\n })\n\n// the size of each group's place, kept up to date so `canSplit` can be read in a render\nconst sizes = shallowReactive(new Map<string, { width: number; height: number }>())\nuseResizeObserver(\n () => [...cells.values()],\n (entries) => {\n for (const entry of entries)\n for (const [id, el] of cells)\n if (el === entry.target) {\n const box = entry.borderBoxSize?.[0]\n sizes.set(id, {\n width: box ? box.inlineSize : entry.contentRect.width,\n height: box ? box.blockSize : entry.contentRect.height,\n })\n }\n },\n { box: 'border-box' },\n)\n\n/**\n * Whether a group has room to split a tab off to `side`: two parts of\n * `min` beside the divider, as dragging to its edge checks. Reactive.\n */\nfunction canSplit(groupId: string, side: DockSide) {\n const el = cells.get(groupId)\n if (!el) return false\n const across = side === 'left' || side === 'right'\n const size = sizes.get(groupId) ?? el.getBoundingClientRect()\n return roomForSplit(across ? size.width : size.height, minFor(across ? 'horizontal' : 'vertical'))\n}\ndefineExpose<DockExpose>({ canSplit, startDrop })\n\nprovide(dockKey, {\n group,\n size: () => props.size,\n closable: () => props.closable,\n addable: () => props.addable,\n min: minFor,\n draggable: () => props.draggable,\n panel,\n slots,\n resize: (node, size) => commit(replaceDockNode(latest, node, { ...node, size })),\n select(target, value) {\n if (findDockGroup(latest, value)?.id === target.id) commit(selectDockTab(latest, value))\n },\n move,\n canDrop,\n drop,\n remove: (value, target) => emit('remove', value, target.id),\n add: (target) => emit('add', target.id),\n use,\n setCell,\n})\n</script>\n\n<template>\n <div ref=\"root\" :class=\"ns.b()\">\n <DockNodeView :node=\"modelValue\" />\n <!-- until its place exists (and on the server) a group renders right here -->\n <Teleport\n v-for=\"item in groups\"\n :key=\"item.id\"\n :to=\"cells.get(item.id) ?? 'body'\"\n :disabled=\"!cells.get(item.id)\"\n >\n <DockGroupView\n :group=\"item\"\n :slotted=\"{ label: !!$slots.label, extra: !!$slots.extra, empty: !!$slots.empty }\"\n />\n </Teleport>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;AAoCA,IAAM,cAAc;AA+JpB,IAAM,kBAAkB;AACxB,IAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA9JxB,MAAM,QAAQ;EAOd,MAAM,OAAO;EACb,MAAM,cAAcC,SAAmB,SAAC,aAAa;EACrD,MAAM,QAAQC,SAAA;EAEd,MAAM,KAAK,aAAa,MAAM;EAC9B,MAAM,QAAQ,YAAY,MAAM;EAIhC,IAAI,SAAS,MAAM;EACnB,YACQ,MAAM,aACX,UAAW,SAAS,KACvB;EACA,SAAS,OAAO,MAA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;EACnG;EACA,SAAyB;GAAE;GAAU;EAAU,CAAC;EAEhD,QAAQ,SAAS;GACf;GACA,YAAY,MAAM;GAClB,gBAAgB,MAAM;GACtB,eAAe,MAAM;GACrB,KAAK;GACL,iBAAiB,MAAM;GACvB;GACA;GACA,SAAS,MAAM,SAAS,OAAO,gBAAgB,QAAQ,MAAM;IAAE,GAAG;IAAM;GAAK,CAAC,CAAC;GAC/E,OAAO,QAAQ,OAAO;IACpB,IAAI,cAAc,QAAQ,KAAK,CAAC,EAAE,OAAO,OAAO,IAAI,OAAO,cAAc,QAAQ,KAAK,CAAC;GACzF;GACA;GACA;GACA;GACA,SAAS,OAAO,WAAW,KAAK,UAAU,OAAO,OAAO,EAAE;GAC1D,MAAM,WAAW,KAAK,OAAO,OAAO,EAAE;GACtC;GACA;EACF,CAAC;;GAIC,OAAAC,UAAA,GAAAC,mBAcM,OAAA;IAdG,SAAA;IAAJ,KAAI;IAAQ,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,CAAA;G,IAC1BC,YAAmCC,mBAAA,EAApB,MAAM,QAAA,WAAU,GAAA,MAAA,GAAA,CAAA,MAAA,CAAA,IAE/BL,UAAA,IAAA,GAAAC,mBAUWK,UAAA,MAAAC,WATM,OAAA,QAAR,SAAI;IADb,OAAAP,UAAA,GAAAQ,YAUWC,UAAA;KARR,KAAK,KAAK;KACV,IAAIN,MAAA,KAAA,CAAK,CAAC,IAAI,KAAK,EAAE,KAAA;KACrB,UAAQ,CAAGA,MAAA,KAAA,CAAK,CAAC,IAAI,KAAK,EAAE;I,IAE7BC,YAGEM,oBAAA;KAFC,OAAO;KACP,SAAO;MAAA,OAAA,CAAA,CAAab,KAAAA,OAAO;MAAK,OAAA,CAAA,CAAWA,KAAAA,OAAO;MAAK,OAAA,CAAA,CAAWA,KAAAA,OAAO;KAAK"}
1
+ {"version":3,"file":"dock.vue_vue_type_script_setup_true_lang.js","names":["$slots","_useModel","_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","_createVNode","DockNodeView","_Fragment","_renderList","_createBlock","_Teleport","DockGroupView"],"sources":["../../../src/components/dock/dock.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n nextTick,\n provide,\n shallowReactive,\n useId,\n useTemplateRef,\n watch,\n watchEffect,\n} from 'vue'\nimport { useResizeObserver } from '../../composables/use-element-size'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { dockKey } from './context'\nimport { roomForSplit } from './drop-side'\nimport DockGroupView from './dock-group.vue'\nimport DockNodeView from './dock-node.vue'\nimport {\n dockGroups,\n findDockGroup,\n mergeDockTab,\n moveDockTab,\n nextDockGroupId,\n replaceDockNode,\n selectDockTab,\n splitDockTab,\n} from './layout'\nimport { isIgnoredDragPress, pressTab } from '../tabs/tab-drag'\nimport type { SplitterLimit } from '../splitter/splitter'\nimport type { TabDrag } from '../tabs/tab-drag'\nimport type { TabsMoveEvent, TabsValue } from '../tabs/tabs'\nimport type {\n DockDropItem,\n DockEmits,\n DockExpose,\n DockLocation,\n DockPanel,\n DockProps,\n DockSlots,\n} from './dock'\nimport type { DockGroup, DockNode, DockSide } from './layout'\n\ndefineOptions({ name: 'DouDock' })\n\nconst DEFAULT_MIN = '120px'\n\nconst props = withDefaults(defineProps<DockProps>(), {\n panels: () => [],\n closable: false,\n addable: false,\n draggable: true,\n min: DEFAULT_MIN,\n})\nconst emit = defineEmits<Omit<DockEmits, 'update:activeGroup'>>()\nconst activeGroup = defineModel<string>('activeGroup')\nconst slots = defineSlots<DockSlots>()\n\nconst ns = useNamespace('dock')\nconst group = `dou-dock-${useId()}`\n\n// Changes made in one go (a drop moves a tab and selects it) build on\n// each other before the new layout comes back through the prop.\nlet latest = props.modelValue\nwatch(\n () => props.modelValue,\n (value) => (latest = value),\n)\nfunction commit(next: DockNode) {\n if (next === latest) return\n latest = next\n emit('update:modelValue', next)\n // a parent that turned the change down keeps its layout: build on that from now on\n void nextTick(() => (latest = props.modelValue))\n}\n\nconst panels = computed(() => new Map(props.panels.map((entry) => [entry.value, entry])))\nfunction panel(value: TabsValue): DockPanel | undefined {\n const found = panels.value.get(value)\n if (!found && process.env.NODE_ENV !== 'production')\n devWarn(\n `[dou-ui] DouDock: the tab \"${value}\" has no entry in \\`panels\\`; it is named by its value.`,\n )\n return found\n}\n\n/** Where a tab is now. */\nfunction locate(value: TabsValue) {\n const found = findDockGroup(latest, value)\n return found && { group: found.id, index: found.tabs.indexOf(value) }\n}\n\n/**\n * Find an existing tab in `target` that shares `value`'s `mergeId` when `value`\n * comes from another group or from outside the dock. Prefers a pinned tab.\n */\nfunction findMergeTarget(target: DockGroup, value: TabsValue): TabsValue | undefined {\n const source = panels.value.get(value)\n if (source?.mergeId === undefined) return undefined\n const from = findDockGroup(latest, value)\n if (from?.id === target.id) return undefined\n let fallback: TabsValue | undefined\n for (const tab of target.tabs) {\n if (tab === value) continue\n const entry = panels.value.get(tab)\n if (entry?.mergeId !== source.mergeId || entry.disabled) continue\n if (entry.pinned) return tab\n if (fallback === undefined) fallback = tab\n }\n return fallback\n}\n\nfunction performMove(\n value: TabsValue,\n from: DockLocation | null,\n targetGroup: DockGroup,\n index: number,\n) {\n const autoMerge = findMergeTarget(targetGroup, value)\n let resolvedMerge = autoMerge\n if (props.beforeMove) {\n const decision = props.beforeMove({\n value,\n from,\n to: { group: targetGroup.id, index },\n targetGroup,\n mergeInto: autoMerge,\n })\n if (decision === false) return\n if (typeof decision === 'object' && decision !== null && 'mergeInto' in decision) {\n resolvedMerge = decision.mergeInto ?? undefined\n }\n }\n if (resolvedMerge !== undefined) {\n if (!targetGroup.tabs.includes(resolvedMerge)) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n `[dou-ui] DouDock: \\`beforeMove\\` returned \\`mergeInto: \"${resolvedMerge}\"\\`, which is not in group \"${targetGroup.id}\". The move was cancelled.`,\n )\n return\n }\n const next = mergeDockTab(latest, value, resolvedMerge)\n const mergedIndex = findDockGroup(next, resolvedMerge)?.tabs.indexOf(resolvedMerge) ?? 0\n commit(next)\n emit('move', {\n value,\n from,\n to: { group: targetGroup.id, index: mergedIndex },\n mergedInto: resolvedMerge,\n })\n use(targetGroup.id)\n return\n }\n commit(moveDockTab(latest, value, targetGroup.id, index))\n emit('move', { value, from, to: { group: targetGroup.id, index } })\n use(targetGroup.id)\n}\n\nfunction move(event: TabsMoveEvent) {\n const from = locate(event.value) ?? null\n const to = event.to.name\n if (to === undefined) return\n const targetGroup = dockGroups(latest).find((item) => item.id === to)\n if (!targetGroup) return\n performMove(event.value, from, targetGroup, event.to.index)\n}\n\nfunction canDrop(drag: TabDrag, target: DockGroup, side: DockSide | 'center') {\n const from = findDockGroup(latest, drag.value)\n // not in the layout yet: it opens anywhere\n if (!from) return true\n // the middle of its own group, or an edge of a group it is alone in, leaves it where it is\n if (from.id === target.id) return side !== 'center' && target.tabs.length > 1\n return true\n}\n\nfunction pinnedInsertIndex(target: DockGroup) {\n let index = 0\n for (let i = 0; i < target.tabs.length; i++) {\n if (panels.value.get(target.tabs[i]!)?.pinned) index = i + 1\n }\n return index\n}\n\nfunction drop(drag: TabDrag, target: DockGroup, side: DockSide | 'center') {\n const from = locate(drag.value) ?? null\n if (!canDrop(drag, target, side)) return\n if (side === 'center') {\n const index = drag.pinned ? pinnedInsertIndex(target) : target.tabs.length\n performMove(drag.value, from, target, index)\n return\n }\n const id = props.createId?.(latest) ?? nextDockGroupId(latest)\n commit(splitDockTab(latest, drag.value, target.id, side, id))\n emit('split', { value: drag.value, from, target: target.id, side, group: id })\n use(id)\n}\n\n/* the group last used */\n\nfunction use(id: string | undefined) {\n // also unbound, it emits only a change\n if (id !== activeGroup.value) activeGroup.value = id\n}\n// a group dragged empty or closed, or one never in the layout, is not the one to open things in\nwatch(\n () =>\n activeGroup.value !== undefined && !findGroup(props.modelValue, activeGroup.value)\n ? activeGroup.value\n : undefined,\n (stale) => stale !== undefined && use(undefined),\n { immediate: true },\n)\n\n// Each group is rendered here, in one flat list, and teleported into its\n// place in the layout: splitting or merging the parts around a group moves\n// it, and its content (state, scroll position) stays as it is.\nconst groups = computed(() => dockGroups(props.modelValue))\nfunction findGroup(layout: DockNode, id: string) {\n return dockGroups(layout).some((item) => item.id === id)\n}\nconst cells = shallowReactive(new Map<string, HTMLElement>())\nfunction setCell(id: string, el: unknown) {\n if (el instanceof HTMLElement) {\n if (cells.get(id) !== el) cells.set(id, el)\n } else if (cells.has(id) && !cells.get(id)!.isConnected) {\n cells.delete(id)\n sizes.delete(id)\n }\n}\n\n// Moving a group in the page resets what scrolled inside it: note the\n// offsets before a change of shape moves groups, and put them back after.\nconst shape = (node: DockNode): string =>\n node.type === 'group' ? node.id : `${node.direction[0]}(${shape(node.start)},${shape(node.end)})`\nlet scrolled: [Element, number, number][] = []\nwatch(\n () => shape(props.modelValue),\n () => {\n scrolled = []\n for (const cell of cells.values())\n for (const el of cell.querySelectorAll('*'))\n if (el.scrollTop || el.scrollLeft) scrolled.push([el, el.scrollTop, el.scrollLeft])\n },\n { flush: 'pre' },\n)\nwatch(\n () => shape(props.modelValue),\n () => {\n const notes = scrolled\n scrolled = []\n const restore = () => {\n for (const [el, top, left] of notes) {\n el.scrollTop = top\n el.scrollLeft = left\n }\n }\n restore()\n // a group whose place appears in this update moves in on the next one\n void nextTick(restore)\n },\n { flush: 'post' },\n)\n\n/* dragging something from outside the dock in */\n\nconst root = useTemplateRef<HTMLElement>('root')\nconst RAPID_REPEAT_MS = 400\nconst RAPID_REPEAT_PX = 8\nlet lastDropPress: { time: number; x: number; y: number } | null = null\n\nfunction isRapidRepeat(event: PointerEvent) {\n const now = Date.now()\n const x = event.clientX\n const y = event.clientY\n const repeated =\n event.detail > 1 ||\n (lastDropPress !== null &&\n now - lastDropPress.time <= RAPID_REPEAT_MS &&\n Math.hypot(x - lastDropPress.x, y - lastDropPress.y) <= RAPID_REPEAT_PX)\n lastDropPress = { time: now, x, y }\n return repeated\n}\n\nfunction startDrop(event: PointerEvent, item: DockDropItem) {\n if (isIgnoredDragPress(event)) return\n // `currentTarget` is gone once the handler returns, after an `await`: then the element pressed\n const target = event.currentTarget ?? event.target\n if (!(target instanceof HTMLElement || target instanceof SVGElement)) {\n if (process.env.NODE_ENV !== 'production')\n devWarn(\n '[dou-ui] DouDock: `startDrop` needs the `pointerdown` event of an element, to know what was pressed.',\n )\n return\n }\n const entry = panels.value.get(item.value)\n if (!props.draggable || entry?.disabled || entry?.draggable === false) {\n if (process.env.NODE_ENV !== 'production' && props.draggable)\n devWarn(\n `[dou-ui] DouDock: \\`startDrop\\` for \"${item.value}\" does nothing, as its panel is ${entry?.disabled ? 'disabled' : 'not draggable'}.`,\n )\n return\n }\n if (isRapidRepeat(event)) return\n const label = item.label ?? entry?.label ?? String(item.value)\n // the browser's own drag of a link or an image would take the pointer away\n target.addEventListener('dragstart', noNativeDrag)\n const release = () => {\n target.removeEventListener('dragstart', noNativeDrag)\n window.removeEventListener('pointerup', release, true)\n window.removeEventListener('pointercancel', release, true)\n }\n window.addEventListener('pointerup', release, true)\n window.addEventListener('pointercancel', release, true)\n let dragged = false\n pressTab(event, {\n el: target as HTMLElement,\n root: target as HTMLElement,\n ghost: { label, tabs: root.value?.querySelector<HTMLElement>('.dou-tabs') },\n drag: () => {\n // open already: a drag of it from its group, so dropping it back in its place does nothing\n const from = locate(item.value)\n return {\n value: item.value,\n label,\n group,\n name: from?.group,\n index: from?.index ?? -1,\n source: target,\n pinned: !!entry?.pinned,\n }\n },\n onStart: () => {\n dragged = true\n lastDropPress = null\n },\n onEnd() {\n if (!dragged) return\n // the release that ends a drag is not a click on the element\n window.addEventListener('click', swallow, { capture: true, once: true })\n setTimeout(() => window.removeEventListener('click', swallow, { capture: true }), 0)\n },\n })\n}\nconst noNativeDrag = (e: Event) => e.preventDefault()\nconst swallow = (click: Event) => {\n click.stopPropagation()\n click.preventDefault()\n}\n\nfunction minFor(direction: 'horizontal' | 'vertical'): SplitterLimit {\n const min = props.min\n if (typeof min !== 'object') return min\n return (direction === 'horizontal' ? min.width : min.height) ?? DEFAULT_MIN\n}\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n for (const direction of ['horizontal', 'vertical'] as const) {\n const min = minFor(direction)\n if (typeof min === 'number' && min > 50)\n devWarn(\n `[dou-ui] DouDock: \\`min\\` of ${min} is a percent, so no group can be split ${direction === 'horizontal' ? 'side by side' : 'top to bottom'}. Write '${min}px' for px.`,\n )\n }\n })\n\n// the size of each group's place, kept up to date so `canSplit` can be read in a render\nconst sizes = shallowReactive(new Map<string, { width: number; height: number }>())\nuseResizeObserver(\n () => [...cells.values()],\n (entries) => {\n for (const entry of entries)\n for (const [id, el] of cells)\n if (el === entry.target) {\n const box = entry.borderBoxSize?.[0]\n sizes.set(id, {\n width: box ? box.inlineSize : entry.contentRect.width,\n height: box ? box.blockSize : entry.contentRect.height,\n })\n }\n },\n { box: 'border-box' },\n)\n\n/**\n * Whether a group has room to split a tab off to `side`: two parts of\n * `min` beside the divider, as dragging to its edge checks. Reactive.\n */\nfunction canSplit(groupId: string, side: DockSide) {\n const el = cells.get(groupId)\n if (!el) return false\n const across = side === 'left' || side === 'right'\n const size = sizes.get(groupId) ?? el.getBoundingClientRect()\n return roomForSplit(across ? size.width : size.height, minFor(across ? 'horizontal' : 'vertical'))\n}\ndefineExpose<DockExpose>({ canSplit, startDrop })\n\nprovide(dockKey, {\n group,\n size: () => props.size,\n closable: () => props.closable,\n addable: () => props.addable,\n min: minFor,\n draggable: () => props.draggable,\n panel,\n slots,\n resize: (node, size) => commit(replaceDockNode(latest, node, { ...node, size })),\n select(target, value) {\n if (findDockGroup(latest, value)?.id === target.id) commit(selectDockTab(latest, value))\n },\n move,\n mergeTarget: (drag, target) => findMergeTarget(target, drag.value),\n canDrop,\n drop,\n remove: (value, target) => emit('remove', value, target.id),\n add: (target) => emit('add', target.id),\n use,\n setCell,\n})\n</script>\n\n<template>\n <div ref=\"root\" :class=\"ns.b()\">\n <DockNodeView :node=\"modelValue\" />\n <!-- until its place exists (and on the server) a group renders right here -->\n <Teleport\n v-for=\"item in groups\"\n :key=\"item.id\"\n :to=\"cells.get(item.id) ?? 'body'\"\n :disabled=\"!cells.get(item.id)\"\n >\n <DockGroupView\n :group=\"item\"\n :slotted=\"{ label: !!$slots.label, extra: !!$slots.extra, empty: !!$slots.empty }\"\n />\n </Teleport>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;AA6CA,IAAM,cAAc;AA8NpB,IAAM,kBAAkB;AACxB,IAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA7NxB,MAAM,QAAQ;EAOd,MAAM,OAAO;EACb,MAAM,cAAcC,SAAmB,SAAC,aAAa;EACrD,MAAM,QAAQC,SAAA;EAEd,MAAM,KAAK,aAAa,MAAM;EAC9B,MAAM,QAAQ,YAAY,MAAM;EAIhC,IAAI,SAAS,MAAM;EACnB,YACQ,MAAM,aACX,UAAW,SAAS,KACvB;EACA,SAAS,OAAO,MAAgB;GAC9B,IAAI,SAAS,QAAQ;GACrB,SAAS;GACT,KAAK,qBAAqB,IAAI;GAE9B,eAAqB,SAAS,MAAM,UAAW;EACjD;EAEA,MAAM,SAAS,eAAe,IAAI,IAAI,MAAM,OAAO,KAAK,UAAU,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC,CAAC;EACxF,SAAS,MAAM,OAAyC;GACtD,MAAM,QAAQ,OAAO,MAAM,IAAI,KAAK;GACpC,IAAI,CAAC,SAAA,QAAA,IAAA,aAAkC,cACrC,QACE,8BAA8B,MAAM,wDACtC;GACF,OAAO;EACT;;EAGA,SAAS,OAAO,OAAkB;GAChC,MAAM,QAAQ,cAAc,QAAQ,KAAK;GACzC,OAAO,SAAS;IAAE,OAAO,MAAM;IAAI,OAAO,MAAM,KAAK,QAAQ,KAAK;GAAE;EACtE;;;;;EAMA,SAAS,gBAAgB,QAAmB,OAAyC;GACnF,MAAM,SAAS,OAAO,MAAM,IAAI,KAAK;GACrC,IAAI,QAAQ,YAAY,KAAA,GAA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AAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,CAAA;G,IAC1BC,YAAmCC,mBAAA,EAApB,MAAM,QAAA,WAAU,GAAA,MAAA,GAAA,CAAA,MAAA,CAAA,IAE/BL,UAAA,IAAA,GAAAC,mBAUWK,UAAA,MAAAC,WATM,OAAA,QAAR,SAAI;IADb,OAAAP,UAAA,GAAAQ,YAUWC,UAAA;KARR,KAAK,KAAK;KACV,IAAIN,MAAA,KAAA,CAAK,CAAC,IAAI,KAAK,EAAE,KAAA;KACrB,UAAQ,CAAGA,MAAA,KAAA,CAAK,CAAC,IAAI,KAAK,EAAE;I,IAE7BC,YAGEM,oBAAA;KAFC,OAAO;KACP,SAAO;MAAA,OAAA,CAAA,CAAab,KAAAA,OAAO;MAAK,OAAA,CAAA,CAAWA,KAAAA,OAAO;MAAK,OAAA,CAAA,CAAWA,KAAAA,OAAO;KAAK"}
@@ -1,8 +1,8 @@
1
1
  import { withInstall } from "../../utils/install.js";
2
- import { dockGroups, findDockGroup, moveDockTab, nextDockGroupId, removeDockTab, selectDockTab, splitDockTab } from "./layout.js";
2
+ import { dockGroups, findDockGroup, mergeDockTab, moveDockTab, nextDockGroupId, removeDockTab, selectDockTab, splitDockTab } from "./layout.js";
3
3
  import dock_default from "./dock.js";
4
4
  // src/components/dock/index.ts
5
5
  var DouDock = withInstall(dock_default);
6
- export { DouDock, DouDock as default, dockGroups, findDockGroup, moveDockTab, nextDockGroupId, removeDockTab, selectDockTab, splitDockTab };
6
+ export { DouDock, DouDock as default, dockGroups, findDockGroup, mergeDockTab, moveDockTab, nextDockGroupId, removeDockTab, selectDockTab, splitDockTab };
7
7
 
8
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Dock"],"sources":["../../../src/components/dock/index.ts"],"sourcesContent":["import { withInstall } from '../../utils/install'\nimport Dock from './dock.vue'\n\nexport const DouDock = withInstall(Dock)\nexport default DouDock\n\nexport type * from './dock'\nexport {\n dockGroups,\n findDockGroup,\n moveDockTab,\n nextDockGroupId,\n removeDockTab,\n selectDockTab,\n splitDockTab,\n} from './layout'\nexport type DockInstance = InstanceType<typeof Dock>\n\ndeclare module 'vue' {\n export interface GlobalComponents {\n DouDock: typeof DouDock\n }\n}\n"],"mappings":";;;;AAGA,IAAa,UAAU,YAAYA,YAAI"}
1
+ {"version":3,"file":"index.js","names":["Dock"],"sources":["../../../src/components/dock/index.ts"],"sourcesContent":["import { withInstall } from '../../utils/install'\nimport Dock from './dock.vue'\n\nexport const DouDock = withInstall(Dock)\nexport default DouDock\n\nexport type * from './dock'\nexport {\n dockGroups,\n findDockGroup,\n mergeDockTab,\n moveDockTab,\n nextDockGroupId,\n removeDockTab,\n selectDockTab,\n splitDockTab,\n} from './layout'\nexport type DockInstance = InstanceType<typeof Dock>\n\ndeclare module 'vue' {\n export interface GlobalComponents {\n DouDock: typeof DouDock\n }\n}\n"],"mappings":";;;;AAGA,IAAa,UAAU,YAAYA,YAAI"}
@@ -105,6 +105,17 @@ function removeDockTab(layout, value) {
105
105
  if (!group) return layout;
106
106
  return orEmpty(takeOut(layout, value), group.id);
107
107
  }
108
+ /**
109
+ * Merge a tab into an existing `target` tab: take `value` out of its group
110
+ * (dropping that group once it is empty) and select `target` in its group.
111
+ * Returns a new layout; if `target` is not in the layout, returns it as is.
112
+ */
113
+ function mergeDockTab(layout, value, target) {
114
+ const targetGroup = findDockGroup(layout, target);
115
+ if (!targetGroup) return layout;
116
+ if (value === target) return selectDockTab(layout, target);
117
+ return selectDockTab(orEmpty(takeOut(layout, value, targetGroup.id), targetGroup.id), target);
118
+ }
108
119
  /** Select a tab in its group. Returns a new layout. */
109
120
  function selectDockTab(layout, value) {
110
121
  return mapNode(layout, (node) => node.type === "group" && node.tabs.includes(value) && node.active !== value ? {
@@ -116,6 +127,6 @@ function selectDockTab(layout, value) {
116
127
  function replaceDockNode(layout, node, next) {
117
128
  return mapNode(layout, (current) => current === node ? next : current);
118
129
  }
119
- export { dockGroups, findDockGroup, moveDockTab, nextDockGroupId, removeDockTab, replaceDockNode, selectDockTab, splitDockTab };
130
+ export { dockGroups, findDockGroup, mergeDockTab, moveDockTab, nextDockGroupId, removeDockTab, replaceDockNode, selectDockTab, splitDockTab };
120
131
 
121
132
  //# sourceMappingURL=layout.js.map
@@ -1 +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,QAAQ,MAAgB,KAA2D;CAC1F,MAAM,MAAM,IAAI,IAAI;CACpB,IAAI,QAAQ,MAAM,OAAO;CACzB,IAAI,KAAK,SAAS,SAAS,OAAO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../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/**\n * Merge a tab into an existing `target` tab: take `value` out of its group\n * (dropping that group once it is empty) and select `target` in its group.\n * Returns a new layout; if `target` is not in the layout, returns it as is.\n */\nexport function mergeDockTab(layout: DockNode, value: TabsValue, target: TabsValue): DockNode {\n const targetGroup = findDockGroup(layout, target)\n if (!targetGroup) return layout\n if (value === target) return selectDockTab(layout, target)\n const taken = takeOut(layout, value, targetGroup.id)\n return selectDockTab(orEmpty(taken, targetGroup.id), target)\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,QAAQ,MAAgB,KAA2D;CAC1F,MAAM,MAAM,IAAI,IAAI;CACpB,IAAI,QAAQ,MAAM,OAAO;CACzB,IAAI,KAAK,SAAS,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AAS,KAAK,KAAK,KAAK,WAAW,QAClE;EAAE,GAAG;EAAM,QAAQ;CAAM,IACzB,IACN;AACF;;AAGA,SAAgB,gBAAgB,QAAkB,MAAgB,MAA0B;CAC1F,OAAO,QAAQ,SAAS,YAAa,YAAY,OAAO,OAAO,OAAQ;AACzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"popover.js","names":["_sfc_main"],"sources":["../../../src/components/popover/popover.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, mergeProps, useId, useSlots } from 'vue'\nimport type { CSSProperties } from 'vue'\nimport { getTabbable } from '../../composables/use-focus-trap'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport type { PopoverExpose, PopoverProps, PopoverSlots } from './popover'\nimport { useTeleport } from '../../utils/teleport'\n\ndefineOptions({ name: 'DouPopover', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<PopoverProps>(), {\n placement: 'bottom',\n trigger: 'click',\n disabled: false,\n showDelay: 100,\n hideDelay: 150,\n offset: 8,\n openOnTap: true,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\ndefineSlots<PopoverSlots>()\nconst slots = useSlots()\n\nconst ns = useNamespace('popover')\nconst id = `dou-popover-${useId()}`\nconst titleId = `${id}-title`\nconst hasTitle = computed(() => !!props.title || !!slots.title)\n\nconst popup = usePopup({\n open,\n trigger: () => props.trigger,\n disabled: () => props.disabled,\n placement: () => props.placement,\n offset: () => props.offset,\n showDelay: () => props.showDelay,\n hideDelay: () => props.hideDelay,\n tap: () => props.openOnTap,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle, panelListeners } = popup\n\n// The panel lives at the end of <body>, away from the trigger in tab\n// order. `Tab` from the trigger steps into the panel, and stepping out of\n// either end of the panel lands back on the trigger, from where the\n// browser carries on as usual. Leaving the trigger any other way (`Tab`\n// with nothing to focus in the panel, or `Shift+Tab`) closes the panel, so\n// it doesn't stay open away from the focus.\nfunction onTriggerKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !open.value || !panelRef.value) return\n const first = event.shiftKey ? undefined : getTabbable(panelRef.value)[0]\n if (!first) return popup.hide()\n event.preventDefault()\n first.focus()\n}\n\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !panelRef.value) return\n const tabbable = getTabbable(panelRef.value)\n const trigger = popup.reference() as HTMLElement | null\n if (event.shiftKey && document.activeElement === tabbable[0]) {\n event.preventDefault()\n trigger?.focus()\n } else if (!event.shiftKey && document.activeElement === tabbable.at(-1)) {\n trigger?.focus()\n popup.hide()\n }\n}\n\n// Hover has no keyboard of its own: Enter or Space on the trigger (a click\n// with `detail` 0) opens and closes a hover card too, so a screen reader\n// can reach it. A link trigger keeps Enter for following the link.\nfunction onTriggerClick(event: MouseEvent) {\n if (props.trigger !== 'hover' || event.detail !== 0 || props.disabled) return\n if ((event.currentTarget as Element | null)?.matches('a[href]')) return\n if (open.value) return popup.hide()\n popup.tapped.value = true\n popup.show()\n}\n\nconst triggerProps = computed(() =>\n mergeProps(popup.triggerListeners.value, {\n onKeydown: onTriggerKeydown,\n onClick: onTriggerClick,\n 'aria-haspopup': 'dialog' as const,\n // a hover card a tap or the keyboard opened stays, like a dialog\n 'aria-expanded': props.trigger === 'hover' && !popup.tapped.value ? undefined : open.value,\n 'aria-controls': rendered.value ? id : undefined,\n }),\n)\n\nconst panelClasses = computed(() => [ns.b(), 'dou-floating', ns.is('titled', hasTitle.value)])\nconst cssSize = (value: string | number | undefined) =>\n typeof value === 'number' ? `${value}px` : (value ?? undefined)\nconst panelSizeStyle = computed<CSSProperties>(() => ({\n width: cssSize(props.width),\n ...(props.maxHeight !== undefined && {\n '--dou-popover-max-height': cssSize(props.maxHeight),\n }),\n}))\n\ndefineExpose<PopoverExpose>({ open: () => popup.show(), close: () => popup.dismiss() })\n</script>\n\n<template>\n <OnlyChild ref=\"triggerRef\" v-bind=\"triggerProps\"><slot /></OnlyChild>\n <Teleport v-if=\"rendered\" :to=\"teleportTarget.to\" :disabled=\"teleportTarget.disabled\">\n <Transition appear name=\"dou-floating\">\n <div\n v-show=\"open\"\n :id=\"id\"\n ref=\"panelRef\"\n role=\"dialog\"\n :aria-labelledby=\"hasTitle ? titleId : undefined\"\n :class=\"panelClasses\"\n :style=\"[panelStyle, panelSizeStyle]\"\n :data-placement=\"placement\"\n :data-dou-theme=\"theme\"\n v-bind=\"{ ...$attrs, ...panelListeners }\"\n @keydown=\"onPanelKeydown\"\n >\n <div v-if=\"hasTitle\" :id=\"titleId\" :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </div>\n <div :class=\"ns.e('content')\">\n <slot name=\"content\" :close=\"popup.dismiss\">{{ content }}</slot>\n </div>\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"popover.js","names":["_sfc_main"],"sources":["../../../src/components/popover/popover.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, mergeProps, useId, useSlots } from 'vue'\nimport type { CSSProperties } from 'vue'\nimport { getTabbable } from '../../composables/use-focus-trap'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport type { PopoverExpose, PopoverProps, PopoverSlots } from './popover'\nimport { useTeleport } from '../../utils/teleport'\n\ndefineOptions({ name: 'DouPopover', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<PopoverProps>(), {\n placement: 'bottom',\n trigger: 'click',\n disabled: false,\n showDelay: 100,\n hideDelay: 150,\n offset: 8,\n openOnTap: true,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\ndefineSlots<PopoverSlots>()\nconst slots = useSlots()\n\nconst ns = useNamespace('popover')\nconst id = `dou-popover-${useId()}`\nconst titleId = `${id}-title`\nconst hasTitle = computed(() => !!props.title || !!slots.title)\n\nconst popup = usePopup({\n open,\n trigger: () => props.trigger,\n disabled: () => props.disabled,\n placement: () => props.placement,\n offset: () => props.offset,\n showDelay: () => props.showDelay,\n hideDelay: () => props.hideDelay,\n tap: () => props.openOnTap,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle, panelListeners } = popup\n\n// The panel lives at the end of <body>, away from the trigger in tab\n// order. `Tab` from the trigger steps into the panel, and stepping out of\n// either end of the panel lands back on the trigger, from where the\n// browser carries on as usual. Leaving the trigger any other way (`Tab`\n// with nothing to focus in the panel, or `Shift+Tab`) closes the panel, so\n// it doesn't stay open away from the focus.\nfunction onTriggerKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !open.value || !panelRef.value) return\n const first = event.shiftKey ? undefined : getTabbable(panelRef.value)[0]\n if (!first) return popup.hide()\n event.preventDefault()\n first.focus()\n}\n\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !panelRef.value) return\n const tabbable = getTabbable(panelRef.value)\n const trigger = popup.reference() as HTMLElement | null\n if (event.shiftKey && document.activeElement === tabbable[0]) {\n event.preventDefault()\n trigger?.focus()\n } else if (!event.shiftKey && document.activeElement === tabbable.at(-1)) {\n trigger?.focus()\n popup.hide()\n }\n}\n\n// Hover has no keyboard of its own: Enter or Space on the trigger (a click\n// with `detail` 0) opens and closes a hover card too, so a screen reader\n// can reach it. A link trigger keeps Enter for following the link.\nfunction onTriggerClick(event: MouseEvent) {\n if (props.trigger !== 'hover' || event.detail !== 0 || props.disabled) return\n if ((event.currentTarget as Element | null)?.matches('a[href]')) return\n if (open.value) return popup.hide()\n popup.tapped.value = true\n popup.show()\n}\n\nconst triggerProps = computed(() =>\n mergeProps(popup.triggerListeners.value, {\n onKeydown: onTriggerKeydown,\n onClick: onTriggerClick,\n 'aria-haspopup': 'dialog' as const,\n // a hover card a tap or the keyboard opened stays, like a dialog\n 'aria-expanded': props.trigger === 'hover' && !popup.tapped.value ? undefined : open.value,\n 'aria-controls': rendered.value ? id : undefined,\n }),\n)\n\nconst panelClasses = computed(() => [ns.b(), 'dou-floating', ns.is('titled', hasTitle.value)])\n// CSS `min()` only accepts <length-percentage>, length math functions and\n// var()/env(). Writing unitless strings, intrinsic keywords or malformed values\n// into `--dou-popover-max-*` would make `max-width` / `max-height` invalid at\n// computed-value time (IACVT) and drop the viewport clamp.\nconst CSS_LENGTH_PERCENTAGE =\n /^\\+?(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:e[+-]?\\d+)?(?:%|px|cm|mm|q|in|pc|pt|r?(?:em|ex|cap|ch|ic|lh)|[sld]?v(?:w|h|i|b|min|max)|cq(?:w|h|i|b|min|max))$/i\nconst CSS_MIN_FUNCTION = /^(?:calc|min|max|clamp|round|abs|mod|rem|var|env)\\(/i\nfunction isMinCompatibleSize(value: string): boolean {\n if (CSS_LENGTH_PERCENTAGE.test(value)) return true\n if (!CSS_MIN_FUNCTION.test(value) || !value.endsWith(')')) return false\n const openIndex = value.indexOf('(')\n if (!value.slice(openIndex + 1, -1).trim()) return false\n let depth = 0\n for (let i = openIndex; i < value.length; i++) {\n if (value[i] === '(') depth++\n else if (value[i] === ')') {\n depth--\n if (depth === 0) return i === value.length - 1\n if (depth < 0) return false\n }\n }\n return false\n}\nconst cssSize = (value: string | number | undefined) => {\n if (typeof value === 'number')\n return Number.isFinite(value) && value >= 0 ? `${value}px` : undefined\n const trimmed = value?.trim()\n return trimmed || undefined\n}\nconst panelSizeStyle = computed<CSSProperties>(() => {\n const width = cssSize(props.width)\n const maxHeight = cssSize(props.maxHeight)\n return {\n width,\n ...(width !== undefined &&\n isMinCompatibleSize(width) && {\n '--dou-popover-max-width': width,\n }),\n ...(maxHeight !== undefined &&\n isMinCompatibleSize(maxHeight) && {\n '--dou-popover-max-height': maxHeight,\n }),\n }\n})\n\ndefineExpose<PopoverExpose>({ open: () => popup.show(), close: () => popup.dismiss() })\n</script>\n\n<template>\n <OnlyChild ref=\"triggerRef\" v-bind=\"triggerProps\"><slot /></OnlyChild>\n <Teleport v-if=\"rendered\" :to=\"teleportTarget.to\" :disabled=\"teleportTarget.disabled\">\n <Transition appear name=\"dou-floating\">\n <div\n v-show=\"open\"\n :id=\"id\"\n ref=\"panelRef\"\n role=\"dialog\"\n :aria-labelledby=\"hasTitle ? titleId : undefined\"\n :class=\"panelClasses\"\n :style=\"[panelStyle, panelSizeStyle]\"\n :data-placement=\"placement\"\n :data-dou-theme=\"theme\"\n v-bind=\"{ ...$attrs, ...panelListeners }\"\n @keydown=\"onPanelKeydown\"\n >\n <div v-if=\"hasTitle\" :id=\"titleId\" :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </div>\n <div :class=\"ns.e('content')\">\n <slot name=\"content\" :close=\"popup.dismiss\">{{ content }}</slot>\n </div>\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":""}