dou-ui 0.1.0-alpha.21 → 0.1.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js +19 -14
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-input/chat-input2.js.map +1 -1
- package/dist/components/chat-list/chat-list.js.map +1 -1
- package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js +51 -19
- package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-list/chat-list2.js.map +1 -1
- package/dist/components/chat-message/chat-message.js.map +1 -1
- package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js +52 -12
- package/dist/components/chat-message/chat-message.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-message/chat-message2.js.map +1 -1
- package/dist/components/chat-plan/chat-plan.js.map +1 -1
- package/dist/components/chat-plan/chat-plan.vue_vue_type_script_setup_true_lang.js +22 -9
- package/dist/components/chat-plan/chat-plan.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-plan/chat-plan2.js.map +1 -1
- package/dist/components/code-block/code-block.js.map +1 -1
- package/dist/components/code-block/code-block.vue_vue_type_script_setup_true_lang.js +144 -7
- package/dist/components/code-block/code-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dock/dock-group.js.map +1 -1
- package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js +4 -2
- package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dock/dock.js.map +1 -1
- package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js +30 -4
- package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dock/style.js +1 -0
- package/dist/components/form/form.vue_vue_type_script_setup_true_lang.js +1 -0
- package/dist/components/form/form.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/form/form2.js.map +1 -1
- package/dist/components/image/image-preview.js.map +1 -1
- package/dist/components/image/image-preview.vue_vue_type_script_setup_true_lang.js +63 -95
- package/dist/components/image/image-preview.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/image/use-preview-viewport.js +619 -0
- package/dist/components/image/use-preview-viewport.js.map +1 -0
- package/dist/components/image/viewport.js +142 -0
- package/dist/components/image/viewport.js.map +1 -0
- package/dist/components/link/link.js.map +1 -1
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js +59 -14
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js +13 -3
- package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/splitter/splitter.js.map +1 -1
- package/dist/components/splitter/splitter.vue_vue_type_script_setup_true_lang.js +111 -41
- package/dist/components/splitter/splitter.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/style.js +1 -0
- package/dist/components/tabs/tab-button.js +6 -0
- package/dist/components/tabs/tab-button.js.map +1 -0
- package/dist/components/tabs/tab-button.vue_vue_type_script_setup_true_lang.js +108 -0
- package/dist/components/tabs/tab-button.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/tabs/tab-drag.js +10 -2
- package/dist/components/tabs/tab-drag.js.map +1 -1
- package/dist/components/tabs/tab-panel.js.map +1 -1
- package/dist/components/tabs/tab-panel.vue_vue_type_script_setup_true_lang.js +4 -0
- package/dist/components/tabs/tab-panel.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js +430 -181
- package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/tabs2.js.map +1 -1
- package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js +77 -34
- package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/virtual-list/virtual-list2.js.map +1 -1
- package/dist/composables/use-floating.js +60 -8
- package/dist/composables/use-floating.js.map +1 -1
- package/dist/composables/use-measured-sizes.js +7 -3
- package/dist/composables/use-measured-sizes.js.map +1 -1
- package/dist/composables/use-popup.js +3 -0
- package/dist/composables/use-popup.js.map +1 -1
- package/dist/composables/use-touch-scroll.js +141 -29
- package/dist/composables/use-touch-scroll.js.map +1 -1
- package/dist/locale/en.js +3 -2
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/zh-cn.js +3 -2
- package/dist/locale/zh-cn.js.map +1 -1
- package/dist/locale/zh-tw.js +3 -2
- package/dist/locale/zh-tw.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/components/chat-list/chat-list.d.ts +13 -0
- package/dist/types/components/chat-list/index.d.ts +2 -0
- package/dist/types/components/chat-message/chat-message.d.ts +19 -0
- package/dist/types/components/chat-message/chat-message.vue.d.ts +1 -0
- package/dist/types/components/chat-message/index.d.ts +3 -0
- package/dist/types/components/chat-plan/chat-plan.d.ts +3 -1
- package/dist/types/components/chat-plan/chat-plan.vue.d.ts +1 -0
- package/dist/types/components/chat-plan/index.d.ts +3 -0
- package/dist/types/components/code-block/code-block.d.ts +23 -0
- package/dist/types/components/code-block/code-block.vue.d.ts +8 -2
- package/dist/types/components/code-block/index.d.ts +19 -3
- package/dist/types/components/dock/dock.d.ts +6 -0
- package/dist/types/components/image/image.d.ts +1 -1
- package/dist/types/components/image/use-preview-viewport.d.ts +48 -0
- package/dist/types/components/image/viewport.d.ts +58 -0
- package/dist/types/components/link/index.d.ts +3 -0
- package/dist/types/components/link/link.d.ts +12 -3
- package/dist/types/components/link/link.vue.d.ts +1 -0
- package/dist/types/components/popover/index.d.ts +3 -0
- package/dist/types/components/popover/popover.d.ts +7 -0
- package/dist/types/components/popover/popover.vue.d.ts +1 -0
- package/dist/types/components/splitter/index.d.ts +6 -9
- package/dist/types/components/splitter/splitter.d.ts +31 -4
- package/dist/types/components/splitter/splitter.vue.d.ts +3 -4
- package/dist/types/components/tabs/index.d.ts +3 -0
- package/dist/types/components/tabs/tab-button.vue.d.ts +28 -0
- package/dist/types/components/tabs/tab-drag.d.ts +8 -0
- package/dist/types/components/tabs/tab-panel.vue.d.ts +1 -0
- package/dist/types/components/tabs/tabs.d.ts +6 -0
- package/dist/types/composables/use-floating.d.ts +1 -1
- package/dist/types/composables/use-measured-sizes.d.ts +2 -0
- package/dist/types/composables/use-touch-scroll.d.ts +8 -0
- package/dist/types/locale/types.d.ts +6 -3
- package/package.json +3 -3
|
@@ -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 { 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 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 = 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')\n\nfunction startDrop(event: PointerEvent, item: DockDropItem) {\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 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 }\n },\n onStart: () => (dragged = true),\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 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":""}
|
|
@@ -3,13 +3,15 @@ import { devWarn } from "../../utils/status-check.js";
|
|
|
3
3
|
import { useResizeObserver } from "../../composables/use-element-size.js";
|
|
4
4
|
import { dockKey } from "./context.js";
|
|
5
5
|
import { roomForSplit } from "./drop-side.js";
|
|
6
|
-
import { pressTab } from "../tabs/tab-drag.js";
|
|
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
9
|
import { dockGroups, findDockGroup, 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";
|
|
13
|
+
var RAPID_REPEAT_MS = 400;
|
|
14
|
+
var RAPID_REPEAT_PX = 8;
|
|
13
15
|
var dock_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
14
16
|
name: "DouDock",
|
|
15
17
|
__name: "dock",
|
|
@@ -94,11 +96,16 @@ var dock_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
94
96
|
if (from.id === target.id) return side !== "center" && target.tabs.length > 1;
|
|
95
97
|
return true;
|
|
96
98
|
}
|
|
99
|
+
function pinnedInsertIndex(target) {
|
|
100
|
+
let index = 0;
|
|
101
|
+
for (let i = 0; i < target.tabs.length; i++) if (panels.value.get(target.tabs[i])?.pinned) index = i + 1;
|
|
102
|
+
return index;
|
|
103
|
+
}
|
|
97
104
|
function drop(drag, target, side) {
|
|
98
105
|
const from = locate(drag.value) ?? null;
|
|
99
106
|
if (!canDrop(drag, target, side)) return;
|
|
100
107
|
if (side === "center") {
|
|
101
|
-
const index = target.tabs.length;
|
|
108
|
+
const index = drag.pinned ? pinnedInsertIndex(target) : target.tabs.length;
|
|
102
109
|
commit(moveDockTab(latest, drag.value, target.id, index));
|
|
103
110
|
emit("move", {
|
|
104
111
|
value: drag.value,
|
|
@@ -162,7 +169,21 @@ var dock_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
162
169
|
nextTick(restore);
|
|
163
170
|
}, { flush: "post" });
|
|
164
171
|
const root = useTemplateRef("root");
|
|
172
|
+
let lastDropPress = null;
|
|
173
|
+
function isRapidRepeat(event) {
|
|
174
|
+
const now = Date.now();
|
|
175
|
+
const x = event.clientX;
|
|
176
|
+
const y = event.clientY;
|
|
177
|
+
const repeated = event.detail > 1 || lastDropPress !== null && now - lastDropPress.time <= RAPID_REPEAT_MS && Math.hypot(x - lastDropPress.x, y - lastDropPress.y) <= RAPID_REPEAT_PX;
|
|
178
|
+
lastDropPress = {
|
|
179
|
+
time: now,
|
|
180
|
+
x,
|
|
181
|
+
y
|
|
182
|
+
};
|
|
183
|
+
return repeated;
|
|
184
|
+
}
|
|
165
185
|
function startDrop(event, item) {
|
|
186
|
+
if (isIgnoredDragPress(event)) return;
|
|
166
187
|
const target = event.currentTarget ?? event.target;
|
|
167
188
|
if (!(target instanceof HTMLElement || target instanceof SVGElement)) {
|
|
168
189
|
if (process.env.NODE_ENV !== "production") devWarn("[dou-ui] DouDock: `startDrop` needs the `pointerdown` event of an element, to know what was pressed.");
|
|
@@ -173,6 +194,7 @@ var dock_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
173
194
|
if (process.env.NODE_ENV !== "production" && props.draggable) devWarn(`[dou-ui] DouDock: \`startDrop\` for "${item.value}" does nothing, as its panel is ${entry?.disabled ? "disabled" : "not draggable"}.`);
|
|
174
195
|
return;
|
|
175
196
|
}
|
|
197
|
+
if (isRapidRepeat(event)) return;
|
|
176
198
|
const label = item.label ?? entry?.label ?? String(item.value);
|
|
177
199
|
target.addEventListener("dragstart", noNativeDrag);
|
|
178
200
|
const release = () => {
|
|
@@ -198,10 +220,14 @@ var dock_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
198
220
|
group,
|
|
199
221
|
name: from?.group,
|
|
200
222
|
index: from?.index ?? -1,
|
|
201
|
-
source: target
|
|
223
|
+
source: target,
|
|
224
|
+
pinned: !!entry?.pinned
|
|
202
225
|
};
|
|
203
226
|
},
|
|
204
|
-
onStart: () =>
|
|
227
|
+
onStart: () => {
|
|
228
|
+
dragged = true;
|
|
229
|
+
lastDropPress = null;
|
|
230
|
+
},
|
|
205
231
|
onEnd() {
|
|
206
232
|
if (!dragged) return;
|
|
207
233
|
window.addEventListener("click", swallow, {
|
|
@@ -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 { 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 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 = 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')\n\nfunction startDrop(event: PointerEvent, item: DockDropItem) {\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 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 }\n },\n onStart: () => (dragged = true),\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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEpB,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;GA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,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 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,MAAgB;GAC9B,IAAI,SAAS,QAAQ;GACrB,SAAS;GACT,KAAK,qBAAqB,IAAI;GAE9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
5
|
+
import '@dou-ui/theme/components/popover.css'
|
|
5
6
|
import '@dou-ui/theme/components/splitter.css'
|
|
6
7
|
import '@dou-ui/theme/components/tabs.css'
|
|
7
8
|
import '@dou-ui/theme/components/tooltip.css'
|
|
@@ -132,6 +132,7 @@ var form_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
132
132
|
ns.b(),
|
|
133
133
|
ns.m(props.layout),
|
|
134
134
|
ns.m(`label-${props.labelAlign}`),
|
|
135
|
+
ns.is("fixed-label", !!labelWidth.value),
|
|
135
136
|
ns.is("disabled", props.disabled),
|
|
136
137
|
ns.is("readonly", props.readonly)
|
|
137
138
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_normalizeStyle","_withModifiers","_renderSlot"],"sources":["../../../src/components/form/form.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, provide } from 'vue'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useNamespace } from '../../utils/namespace'\nimport { formKey, formShowErrorsKey } from './form'\nimport type {\n FormEmits,\n FormErrors,\n FormExpose,\n FormItemHandle,\n FormProps,\n FormSlots,\n} from './form'\nimport { toArray } from './rules'\n\ndefineOptions({ name: 'DouForm' })\n\nconst props = withDefaults(defineProps<FormProps>(), {\n layout: 'vertical',\n labelAlign: 'start',\n disabled: false,\n readonly: false,\n requiredMark: true,\n scrollToError: true,\n})\nconst emit = defineEmits<FormEmits>()\ndefineSlots<FormSlots>()\n\nconst ns = useNamespace('form')\nconst reducedMotion = useReducedMotion()\n\nconst items = new Set<FormItemHandle>()\n\nprovide(formKey, {\n model: () => props.model,\n rules: () => props.rules,\n schema: () => props.schema,\n layout: computed(() => props.layout),\n size: computed(() => props.size),\n disabled: computed(() => props.disabled),\n readonly: computed(() => props.readonly),\n requiredMark: computed(() => props.requiredMark),\n register: (item) => items.add(item),\n unregister: (item) => items.delete(item),\n})\n\n/** Items in document order, optionally narrowed to some paths. */\nfunction pick(paths?: string | string[]) {\n const wanted = paths === undefined ? undefined : toArray(paths)\n const list = [...items].filter((item) => {\n const prop = item.prop()\n return prop !== undefined && (!wanted || wanted.includes(prop))\n })\n list.sort((a, b) => {\n const [x, y] = [a.el(), b.el()]\n if (!x || !y) return 0\n return x.compareDocumentPosition(y) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1\n })\n return list\n}\n\nasync function validate(paths?: string | string[]) {\n const targets = pick(paths)\n const messages = await Promise.all(targets.map((item) => item.validate()))\n const errors: Record<string, string> = {}\n targets.forEach((item, index) => {\n const message = messages[index]\n if (message) errors[item.prop()!] = message\n })\n return { valid: Object.keys(errors).length === 0, errors }\n}\n\nfunction resetFields(paths?: string | string[]) {\n for (const item of pick(paths)) item.reset()\n}\n\nfunction clearValidate(paths?: string | string[]) {\n for (const item of pick(paths)) item.clear()\n}\n\nfunction showErrors(errors: Partial<FormErrors>) {\n const byPath = new Map(pick().map((item) => [item.prop()!, item]))\n const missed: string[] = []\n for (const [path, message] of Object.entries(errors)) {\n // `items[0].name`, as many servers write it, is `items.0.name` here.\n const item = byPath.get(path) ?? byPath.get(path.replace(/\\[(\\d+)\\]/g, '.$1'))\n if (item) item.setError(message ?? '')\n else if (message) missed.push(path)\n }\n return missed\n}\n\nfunction setErrors(errors: Partial<FormErrors>) {\n const missed = showErrors(errors)\n if (missed.length && process.env.NODE_ENV !== 'production')\n console.warn(\n `[dou-ui] DouForm.setErrors: no field shows ${missed.map((path) => `\"${path}\"`).join(', ')}. Show these errors elsewhere, e.g. above the form.`,\n )\n return missed\n}\n\nfunction scrollToField(prop: string) {\n const [item] = pick(prop)\n item?.el()?.scrollIntoView?.({\n block: 'center',\n behavior: reducedMotion.value ? 'auto' : 'smooth',\n })\n item?.focus()\n}\n\nasync function onSubmit() {\n const { valid, errors } = await validate()\n if (valid) {\n emit('submit', props.model ?? {})\n return\n }\n if (props.scrollToError) {\n const first = Object.keys(errors)[0]\n if (first) scrollToField(first)\n }\n emit('invalid', errors)\n}\n\nfunction onReset() {\n resetFields()\n emit('reset')\n}\n\nconst labelWidth = computed(() =>\n typeof props.labelWidth === 'number' ? `${props.labelWidth}px` : props.labelWidth,\n)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.layout),\n ns.m(`label-${props.labelAlign}`),\n ns.is('disabled', props.disabled),\n ns.is('readonly', props.readonly),\n])\n\nconst exposed: FormExpose = { validate, resetFields, clearValidate, scrollToField, setErrors }\n// Kept off the public type: read through `showFormErrors`.\nObject.defineProperty(exposed, formShowErrorsKey, { value: showErrors })\ndefineExpose<FormExpose>(exposed)\n</script>\n\n<template>\n <form\n :class=\"classes\"\n :style=\"labelWidth ? { '--dou-form-label-width': labelWidth } : undefined\"\n novalidate\n @submit.prevent=\"onSubmit\"\n @reset.prevent=\"onReset\"\n >\n <slot />\n </form>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBA,MAAM,QAAQ;EAQd,MAAM,OAAO;EAGb,MAAM,KAAK,aAAa,MAAM;EAC9B,MAAM,gBAAgB,iBAAiB;EAEvC,MAAM,wBAAQ,IAAI,IAAoB;EAEtC,QAAQ,SAAS;GACf,aAAa,MAAM;GACnB,aAAa,MAAM;GACnB,cAAc,MAAM;GACpB,QAAQ,eAAe,MAAM,MAAM;GACnC,MAAM,eAAe,MAAM,IAAI;GAC/B,UAAU,eAAe,MAAM,QAAQ;GACvC,UAAU,eAAe,MAAM,QAAQ;GACvC,cAAc,eAAe,MAAM,YAAY;GAC/C,WAAW,SAAS,MAAM,IAAI,IAAI;GAClC,aAAa,SAAS,MAAM,OAAO,IAAI;EACzC,CAAC;;EAGD,SAAS,KAAK,OAA2B;GACvC,MAAM,SAAS,UAAU,KAAA,IAAY,KAAA,IAAY,QAAQ,KAAK;GAC9D,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,SAAS;IACvC,MAAM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AKC,eAAE,WAAA,QAAU,EAAA,0BAA+B,WAAA,MAAU,IAAK,KAAA,CAAS;IACzE,YAAA;IACC,UAAMC,cAAU,UAAQ,CAAA,SAAA,CAAA;IACxB,SAAKA,cAAU,SAAO,CAAA,SAAA,CAAA;G,IAEvBC,WAAQ,KAAA,QAAA,SAAA,C"}
|
|
1
|
+
{"version":3,"file":"form.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_normalizeStyle","_withModifiers","_renderSlot"],"sources":["../../../src/components/form/form.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, provide } from 'vue'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useNamespace } from '../../utils/namespace'\nimport { formKey, formShowErrorsKey } from './form'\nimport type {\n FormEmits,\n FormErrors,\n FormExpose,\n FormItemHandle,\n FormProps,\n FormSlots,\n} from './form'\nimport { toArray } from './rules'\n\ndefineOptions({ name: 'DouForm' })\n\nconst props = withDefaults(defineProps<FormProps>(), {\n layout: 'vertical',\n labelAlign: 'start',\n disabled: false,\n readonly: false,\n requiredMark: true,\n scrollToError: true,\n})\nconst emit = defineEmits<FormEmits>()\ndefineSlots<FormSlots>()\n\nconst ns = useNamespace('form')\nconst reducedMotion = useReducedMotion()\n\nconst items = new Set<FormItemHandle>()\n\nprovide(formKey, {\n model: () => props.model,\n rules: () => props.rules,\n schema: () => props.schema,\n layout: computed(() => props.layout),\n size: computed(() => props.size),\n disabled: computed(() => props.disabled),\n readonly: computed(() => props.readonly),\n requiredMark: computed(() => props.requiredMark),\n register: (item) => items.add(item),\n unregister: (item) => items.delete(item),\n})\n\n/** Items in document order, optionally narrowed to some paths. */\nfunction pick(paths?: string | string[]) {\n const wanted = paths === undefined ? undefined : toArray(paths)\n const list = [...items].filter((item) => {\n const prop = item.prop()\n return prop !== undefined && (!wanted || wanted.includes(prop))\n })\n list.sort((a, b) => {\n const [x, y] = [a.el(), b.el()]\n if (!x || !y) return 0\n return x.compareDocumentPosition(y) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1\n })\n return list\n}\n\nasync function validate(paths?: string | string[]) {\n const targets = pick(paths)\n const messages = await Promise.all(targets.map((item) => item.validate()))\n const errors: Record<string, string> = {}\n targets.forEach((item, index) => {\n const message = messages[index]\n if (message) errors[item.prop()!] = message\n })\n return { valid: Object.keys(errors).length === 0, errors }\n}\n\nfunction resetFields(paths?: string | string[]) {\n for (const item of pick(paths)) item.reset()\n}\n\nfunction clearValidate(paths?: string | string[]) {\n for (const item of pick(paths)) item.clear()\n}\n\nfunction showErrors(errors: Partial<FormErrors>) {\n const byPath = new Map(pick().map((item) => [item.prop()!, item]))\n const missed: string[] = []\n for (const [path, message] of Object.entries(errors)) {\n // `items[0].name`, as many servers write it, is `items.0.name` here.\n const item = byPath.get(path) ?? byPath.get(path.replace(/\\[(\\d+)\\]/g, '.$1'))\n if (item) item.setError(message ?? '')\n else if (message) missed.push(path)\n }\n return missed\n}\n\nfunction setErrors(errors: Partial<FormErrors>) {\n const missed = showErrors(errors)\n if (missed.length && process.env.NODE_ENV !== 'production')\n console.warn(\n `[dou-ui] DouForm.setErrors: no field shows ${missed.map((path) => `\"${path}\"`).join(', ')}. Show these errors elsewhere, e.g. above the form.`,\n )\n return missed\n}\n\nfunction scrollToField(prop: string) {\n const [item] = pick(prop)\n item?.el()?.scrollIntoView?.({\n block: 'center',\n behavior: reducedMotion.value ? 'auto' : 'smooth',\n })\n item?.focus()\n}\n\nasync function onSubmit() {\n const { valid, errors } = await validate()\n if (valid) {\n emit('submit', props.model ?? {})\n return\n }\n if (props.scrollToError) {\n const first = Object.keys(errors)[0]\n if (first) scrollToField(first)\n }\n emit('invalid', errors)\n}\n\nfunction onReset() {\n resetFields()\n emit('reset')\n}\n\nconst labelWidth = computed(() =>\n typeof props.labelWidth === 'number' ? `${props.labelWidth}px` : props.labelWidth,\n)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.layout),\n ns.m(`label-${props.labelAlign}`),\n ns.is('fixed-label', !!labelWidth.value),\n ns.is('disabled', props.disabled),\n ns.is('readonly', props.readonly),\n])\n\nconst exposed: FormExpose = { validate, resetFields, clearValidate, scrollToField, setErrors }\n// Kept off the public type: read through `showFormErrors`.\nObject.defineProperty(exposed, formShowErrorsKey, { value: showErrors })\ndefineExpose<FormExpose>(exposed)\n</script>\n\n<template>\n <form\n :class=\"classes\"\n :style=\"labelWidth ? { '--dou-form-label-width': labelWidth } : undefined\"\n novalidate\n @submit.prevent=\"onSubmit\"\n @reset.prevent=\"onReset\"\n >\n <slot />\n </form>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBA,MAAM,QAAQ;EAQd,MAAM,OAAO;EAGb,MAAM,KAAK,aAAa,MAAM;EAC9B,MAAM,gBAAgB,iBAAiB;EAEvC,MAAM,wBAAQ,IAAI,IAAoB;EAEtC,QAAQ,SAAS;GACf,aAAa,MAAM;GACnB,aAAa,MAAM;GACnB,cAAc,MAAM;GACpB,QAAQ,eAAe,MAAM,MAAM;GACnC,MAAM,eAAe,MAAM,IAAI;GAC/B,UAAU,eAAe,MAAM,QAAQ;GACvC,UAAU,eAAe,MAAM,QAAQ;GACvC,cAAc,eAAe,MAAM,YAAY;GAC/C,WAAW,SAAS,MAAM,IAAI,IAAI;GAClC,aAAa,SAAS,MAAM,OAAO,IAAI;EACzC,CAAC;;EAGD,SAAS,KAAK,OAA2B;GACvC,MAAM,SAAS,UAAU,KAAA,IAAY,KAAA,IAAY,QAAQ,KAAK;GAC9D,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,SAAS;IACvC,MAAM,OAAO,KAAK,KAAK;IACvB,OAAO,SAAS,KAAA,MAAc,CAAC,UAAU,OAAO,SAAS,IAAI;GAC/D,CAAC;GACD,KAAK,MAAM,GAAG,MAAM;IAClB,MAAM,CAAC,GAAG,KAAK,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,CAAC;IAC9B,IAAI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A,CAAA;G,IAEvBC,WAAQ,KAAA,QAAA,SAAA,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form2.js","names":["_sfc_main"],"sources":["../../../src/components/form/form.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, provide } from 'vue'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useNamespace } from '../../utils/namespace'\nimport { formKey, formShowErrorsKey } from './form'\nimport type {\n FormEmits,\n FormErrors,\n FormExpose,\n FormItemHandle,\n FormProps,\n FormSlots,\n} from './form'\nimport { toArray } from './rules'\n\ndefineOptions({ name: 'DouForm' })\n\nconst props = withDefaults(defineProps<FormProps>(), {\n layout: 'vertical',\n labelAlign: 'start',\n disabled: false,\n readonly: false,\n requiredMark: true,\n scrollToError: true,\n})\nconst emit = defineEmits<FormEmits>()\ndefineSlots<FormSlots>()\n\nconst ns = useNamespace('form')\nconst reducedMotion = useReducedMotion()\n\nconst items = new Set<FormItemHandle>()\n\nprovide(formKey, {\n model: () => props.model,\n rules: () => props.rules,\n schema: () => props.schema,\n layout: computed(() => props.layout),\n size: computed(() => props.size),\n disabled: computed(() => props.disabled),\n readonly: computed(() => props.readonly),\n requiredMark: computed(() => props.requiredMark),\n register: (item) => items.add(item),\n unregister: (item) => items.delete(item),\n})\n\n/** Items in document order, optionally narrowed to some paths. */\nfunction pick(paths?: string | string[]) {\n const wanted = paths === undefined ? undefined : toArray(paths)\n const list = [...items].filter((item) => {\n const prop = item.prop()\n return prop !== undefined && (!wanted || wanted.includes(prop))\n })\n list.sort((a, b) => {\n const [x, y] = [a.el(), b.el()]\n if (!x || !y) return 0\n return x.compareDocumentPosition(y) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1\n })\n return list\n}\n\nasync function validate(paths?: string | string[]) {\n const targets = pick(paths)\n const messages = await Promise.all(targets.map((item) => item.validate()))\n const errors: Record<string, string> = {}\n targets.forEach((item, index) => {\n const message = messages[index]\n if (message) errors[item.prop()!] = message\n })\n return { valid: Object.keys(errors).length === 0, errors }\n}\n\nfunction resetFields(paths?: string | string[]) {\n for (const item of pick(paths)) item.reset()\n}\n\nfunction clearValidate(paths?: string | string[]) {\n for (const item of pick(paths)) item.clear()\n}\n\nfunction showErrors(errors: Partial<FormErrors>) {\n const byPath = new Map(pick().map((item) => [item.prop()!, item]))\n const missed: string[] = []\n for (const [path, message] of Object.entries(errors)) {\n // `items[0].name`, as many servers write it, is `items.0.name` here.\n const item = byPath.get(path) ?? byPath.get(path.replace(/\\[(\\d+)\\]/g, '.$1'))\n if (item) item.setError(message ?? '')\n else if (message) missed.push(path)\n }\n return missed\n}\n\nfunction setErrors(errors: Partial<FormErrors>) {\n const missed = showErrors(errors)\n if (missed.length && process.env.NODE_ENV !== 'production')\n console.warn(\n `[dou-ui] DouForm.setErrors: no field shows ${missed.map((path) => `\"${path}\"`).join(', ')}. Show these errors elsewhere, e.g. above the form.`,\n )\n return missed\n}\n\nfunction scrollToField(prop: string) {\n const [item] = pick(prop)\n item?.el()?.scrollIntoView?.({\n block: 'center',\n behavior: reducedMotion.value ? 'auto' : 'smooth',\n })\n item?.focus()\n}\n\nasync function onSubmit() {\n const { valid, errors } = await validate()\n if (valid) {\n emit('submit', props.model ?? {})\n return\n }\n if (props.scrollToError) {\n const first = Object.keys(errors)[0]\n if (first) scrollToField(first)\n }\n emit('invalid', errors)\n}\n\nfunction onReset() {\n resetFields()\n emit('reset')\n}\n\nconst labelWidth = computed(() =>\n typeof props.labelWidth === 'number' ? `${props.labelWidth}px` : props.labelWidth,\n)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.layout),\n ns.m(`label-${props.labelAlign}`),\n ns.is('disabled', props.disabled),\n ns.is('readonly', props.readonly),\n])\n\nconst exposed: FormExpose = { validate, resetFields, clearValidate, scrollToField, setErrors }\n// Kept off the public type: read through `showFormErrors`.\nObject.defineProperty(exposed, formShowErrorsKey, { value: showErrors })\ndefineExpose<FormExpose>(exposed)\n</script>\n\n<template>\n <form\n :class=\"classes\"\n :style=\"labelWidth ? { '--dou-form-label-width': labelWidth } : undefined\"\n novalidate\n @submit.prevent=\"onSubmit\"\n @reset.prevent=\"onReset\"\n >\n <slot />\n </form>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"form2.js","names":["_sfc_main"],"sources":["../../../src/components/form/form.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, provide } from 'vue'\nimport { useReducedMotion } from '../../composables/use-motion'\nimport { useNamespace } from '../../utils/namespace'\nimport { formKey, formShowErrorsKey } from './form'\nimport type {\n FormEmits,\n FormErrors,\n FormExpose,\n FormItemHandle,\n FormProps,\n FormSlots,\n} from './form'\nimport { toArray } from './rules'\n\ndefineOptions({ name: 'DouForm' })\n\nconst props = withDefaults(defineProps<FormProps>(), {\n layout: 'vertical',\n labelAlign: 'start',\n disabled: false,\n readonly: false,\n requiredMark: true,\n scrollToError: true,\n})\nconst emit = defineEmits<FormEmits>()\ndefineSlots<FormSlots>()\n\nconst ns = useNamespace('form')\nconst reducedMotion = useReducedMotion()\n\nconst items = new Set<FormItemHandle>()\n\nprovide(formKey, {\n model: () => props.model,\n rules: () => props.rules,\n schema: () => props.schema,\n layout: computed(() => props.layout),\n size: computed(() => props.size),\n disabled: computed(() => props.disabled),\n readonly: computed(() => props.readonly),\n requiredMark: computed(() => props.requiredMark),\n register: (item) => items.add(item),\n unregister: (item) => items.delete(item),\n})\n\n/** Items in document order, optionally narrowed to some paths. */\nfunction pick(paths?: string | string[]) {\n const wanted = paths === undefined ? undefined : toArray(paths)\n const list = [...items].filter((item) => {\n const prop = item.prop()\n return prop !== undefined && (!wanted || wanted.includes(prop))\n })\n list.sort((a, b) => {\n const [x, y] = [a.el(), b.el()]\n if (!x || !y) return 0\n return x.compareDocumentPosition(y) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1\n })\n return list\n}\n\nasync function validate(paths?: string | string[]) {\n const targets = pick(paths)\n const messages = await Promise.all(targets.map((item) => item.validate()))\n const errors: Record<string, string> = {}\n targets.forEach((item, index) => {\n const message = messages[index]\n if (message) errors[item.prop()!] = message\n })\n return { valid: Object.keys(errors).length === 0, errors }\n}\n\nfunction resetFields(paths?: string | string[]) {\n for (const item of pick(paths)) item.reset()\n}\n\nfunction clearValidate(paths?: string | string[]) {\n for (const item of pick(paths)) item.clear()\n}\n\nfunction showErrors(errors: Partial<FormErrors>) {\n const byPath = new Map(pick().map((item) => [item.prop()!, item]))\n const missed: string[] = []\n for (const [path, message] of Object.entries(errors)) {\n // `items[0].name`, as many servers write it, is `items.0.name` here.\n const item = byPath.get(path) ?? byPath.get(path.replace(/\\[(\\d+)\\]/g, '.$1'))\n if (item) item.setError(message ?? '')\n else if (message) missed.push(path)\n }\n return missed\n}\n\nfunction setErrors(errors: Partial<FormErrors>) {\n const missed = showErrors(errors)\n if (missed.length && process.env.NODE_ENV !== 'production')\n console.warn(\n `[dou-ui] DouForm.setErrors: no field shows ${missed.map((path) => `\"${path}\"`).join(', ')}. Show these errors elsewhere, e.g. above the form.`,\n )\n return missed\n}\n\nfunction scrollToField(prop: string) {\n const [item] = pick(prop)\n item?.el()?.scrollIntoView?.({\n block: 'center',\n behavior: reducedMotion.value ? 'auto' : 'smooth',\n })\n item?.focus()\n}\n\nasync function onSubmit() {\n const { valid, errors } = await validate()\n if (valid) {\n emit('submit', props.model ?? {})\n return\n }\n if (props.scrollToError) {\n const first = Object.keys(errors)[0]\n if (first) scrollToField(first)\n }\n emit('invalid', errors)\n}\n\nfunction onReset() {\n resetFields()\n emit('reset')\n}\n\nconst labelWidth = computed(() =>\n typeof props.labelWidth === 'number' ? `${props.labelWidth}px` : props.labelWidth,\n)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.layout),\n ns.m(`label-${props.labelAlign}`),\n ns.is('fixed-label', !!labelWidth.value),\n ns.is('disabled', props.disabled),\n ns.is('readonly', props.readonly),\n])\n\nconst exposed: FormExpose = { validate, resetFields, clearValidate, scrollToField, setErrors }\n// Kept off the public type: read through `showFormErrors`.\nObject.defineProperty(exposed, formShowErrorsKey, { value: showErrors })\ndefineExpose<FormExpose>(exposed)\n</script>\n\n<template>\n <form\n :class=\"classes\"\n :style=\"labelWidth ? { '--dou-form-label-width': labelWidth } : undefined\"\n novalidate\n @submit.prevent=\"onSubmit\"\n @reset.prevent=\"onReset\"\n >\n <slot />\n </form>\n</template>\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-preview.js","names":["_sfc_main"],"sources":["../../../src/components/image/image-preview.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ChevronLeftIcon,\n ChevronRightIcon,\n CloseIcon,\n DownloadIcon,\n FlipHorizontalIcon,\n FlipVerticalIcon,\n MaximizeIcon,\n RotateCcwIcon,\n RotateCwIcon,\n ZoomInIcon,\n ZoomOutIcon,\n} from '@dou-ui/icons'\nimport { computed, ref, useId, useTemplateRef, watch } from 'vue'\nimport { useModal } from '../../composables/use-modal'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport type { ImagePreviewProps } from './image'\nimport {
|
|
1
|
+
{"version":3,"file":"image-preview.js","names":["_sfc_main"],"sources":["../../../src/components/image/image-preview.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ChevronLeftIcon,\n ChevronRightIcon,\n CloseIcon,\n DownloadIcon,\n FlipHorizontalIcon,\n FlipVerticalIcon,\n MaximizeIcon,\n RotateCcwIcon,\n RotateCwIcon,\n ZoomInIcon,\n ZoomOutIcon,\n} from '@dou-ui/icons'\nimport { computed, nextTick, ref, useId, useTemplateRef, watch } from 'vue'\nimport { useModal } from '../../composables/use-modal'\nimport { useNamespace } from '../../utils/namespace'\nimport { useTeleport } from '../../utils/teleport'\nimport { useLocale } from '../config-provider/use-config'\nimport type { ImagePreviewProps } from './image'\nimport { downloadImage, normalizePreview } from './preview'\nimport { usePreviewViewport } from './use-preview-viewport'\n\ndefineOptions({ name: 'DouImagePreview', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ImagePreviewProps>(), {\n images: () => [],\n loop: false,\n minScale: 0.25,\n maxScale: 4,\n closeOnMask: true,\n teleport: undefined,\n downloadable: false,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\nconst index = defineModel<number>('index', { default: 0 })\nconst emit = defineEmits<{ close: [] }>()\n\nconst ns = useNamespace('image-preview')\nconst { t } = useLocale()\nconst id = `dou-image-preview-${useId()}`\n\nconst list = computed(() => normalizePreview(props.images))\nconst count = computed(() => list.value.length)\nconst current = computed(() => list.value[Math.min(index.value, count.value - 1)])\n\n/* the view */\n\nconst failed = ref(false)\nconst root = useTemplateRef<HTMLElement>('root')\nconst stage = useTemplateRef<HTMLElement>('stage')\nconst image = useTemplateRef<HTMLImageElement>('image')\n\nconst {\n scale,\n flip,\n interacting,\n dragging,\n canPan,\n transform,\n reset,\n zoom,\n turn,\n mirror,\n syncBounds,\n canCloseOnMask,\n consumeMaskClick,\n onPointerdown,\n onPointermove,\n onPointerup,\n onPointercancel,\n onDblclick,\n onWheel,\n} = usePreviewViewport({\n stageRef: stage,\n imageRef: image,\n active: () => open.value && !!current.value && !failed.value,\n minScale: () => props.minScale,\n maxScale: () => props.maxScale,\n})\n\nwatch([index, open], () => {\n reset()\n failed.value = false\n if (open.value) void nextTick(syncBounds)\n})\n\nconst canPrev = computed(() => count.value > 1 && (props.loop || index.value > 0))\nconst canNext = computed(() => count.value > 1 && (props.loop || index.value < count.value - 1))\nfunction go(step: 1 | -1) {\n if (step < 0 ? !canPrev.value : !canNext.value) return\n index.value = (index.value + step + count.value) % count.value\n}\n\nfunction close() {\n open.value = false\n emit('close')\n}\n\nconst { rendered, zIndex, theme, maskListeners } = useModal({\n open,\n root,\n panel: root,\n closeOnEscape: true,\n closeOnMask: () => props.closeOnMask && canCloseOnMask(),\n lockScroll: true,\n requestClose: close,\n})\n\n/* input */\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.target instanceof HTMLButtonElement && (event.key === 'Enter' || event.key === ' '))\n return\n const actions: Record<string, () => void> = {\n ArrowLeft: () => go(-1),\n ArrowRight: () => go(1),\n '+': () => zoom(1),\n '=': () => zoom(1),\n '-': () => zoom(-1),\n '0': reset,\n r: () => turn(90),\n R: () => turn(-90),\n h: () => mirror('x'),\n v: () => mirror('y'),\n }\n const action = actions[event.key]\n if (!action) return\n event.preventDefault()\n action()\n}\n\nfunction onStagePointerdown(event: PointerEvent) {\n maskListeners.onPointerdown(event)\n onPointerdown(event)\n}\n\nfunction onStageClick(event: MouseEvent) {\n if (consumeMaskClick()) {\n maskListeners.onClick(event)\n }\n}\n\nconst label = computed(() =>\n count.value > 1\n ? t('image.counter', { index: Math.min(index.value, count.value - 1) + 1, total: count.value })\n : '',\n)\n</script>\n\n<template>\n <Teleport v-if=\"rendered\" :to=\"teleportTarget.to\" :disabled=\"teleportTarget.disabled\">\n <Transition appear name=\"dou-image-preview\">\n <div\n v-show=\"open\"\n :id=\"id\"\n ref=\"root\"\n role=\"dialog\"\n aria-modal=\"true\"\n tabindex=\"-1\"\n :aria-label=\"current?.alt || t('image.preview')\"\n v-bind=\"$attrs\"\n :class=\"ns.b()\"\n :style=\"{ zIndex }\"\n :data-dou-theme=\"theme\"\n @keydown=\"onKeydown\"\n >\n <div\n ref=\"stage\"\n :class=\"[ns.e('stage'), ns.is('movable', canPan), ns.is('dragging', dragging)]\"\n @pointerdown=\"onStagePointerdown\"\n @pointermove=\"onPointermove\"\n @pointerup=\"onPointerup\"\n @pointercancel=\"onPointercancel\"\n @click=\"onStageClick\"\n @wheel=\"onWheel\"\n >\n <img\n v-if=\"current && !failed\"\n ref=\"image\"\n :key=\"current.src\"\n :class=\"[\n ns.e('image'),\n ns.is('movable', canPan),\n ns.is('dragging', dragging),\n ns.is('interacting', interacting),\n ]\"\n :src=\"current.src\"\n :alt=\"current.alt ?? ''\"\n :style=\"{ transform }\"\n draggable=\"false\"\n @load=\"syncBounds\"\n @error=\"failed = true\"\n @dblclick=\"onDblclick\"\n />\n <div v-else-if=\"current\" :class=\"ns.e('error')\">{{ t('image.error') }}</div>\n </div>\n\n <button\n v-if=\"count > 1\"\n type=\"button\"\n :class=\"[ns.e('nav'), ns.is('prev', true)]\"\n :disabled=\"!canPrev\"\n :aria-label=\"t('image.prev')\"\n @click=\"go(-1)\"\n >\n <ChevronLeftIcon />\n </button>\n <button\n v-if=\"count > 1\"\n type=\"button\"\n :class=\"[ns.e('nav'), ns.is('next', true)]\"\n :disabled=\"!canNext\"\n :aria-label=\"t('image.next')\"\n @click=\"go(1)\"\n >\n <ChevronRightIcon />\n </button>\n\n <button type=\"button\" :class=\"ns.e('close')\" :aria-label=\"t('image.close')\" @click=\"close\">\n <CloseIcon />\n </button>\n\n <div :class=\"ns.e('toolbar')\" role=\"toolbar\" :aria-label=\"t('image.preview')\">\n <span v-if=\"label\" :class=\"ns.e('counter')\" aria-live=\"polite\">{{ label }}</span>\n <button\n type=\"button\"\n :class=\"ns.e('tool')\"\n :disabled=\"scale <= minScale\"\n :aria-label=\"t('image.zoomOut')\"\n @click=\"zoom(-1)\"\n >\n <ZoomOutIcon />\n </button>\n <span :class=\"ns.e('scale')\" aria-live=\"polite\">{{ Math.round(scale * 100) }}%</span>\n <button\n type=\"button\"\n :class=\"ns.e('tool')\"\n :disabled=\"scale >= maxScale\"\n :aria-label=\"t('image.zoomIn')\"\n @click=\"zoom(1)\"\n >\n <ZoomInIcon />\n </button>\n <span :class=\"ns.e('divider')\" aria-hidden=\"true\" />\n <button\n type=\"button\"\n :class=\"ns.e('tool')\"\n :aria-label=\"t('image.rotateLeft')\"\n @click=\"turn(-90)\"\n >\n <RotateCcwIcon />\n </button>\n <button\n type=\"button\"\n :class=\"ns.e('tool')\"\n :aria-label=\"t('image.rotateRight')\"\n @click=\"turn(90)\"\n >\n <RotateCwIcon />\n </button>\n <button\n type=\"button\"\n :class=\"ns.e('tool')\"\n :aria-label=\"t('image.flipHorizontal')\"\n :aria-pressed=\"flip.x < 0\"\n @click=\"mirror('x')\"\n >\n <FlipHorizontalIcon />\n </button>\n <button\n type=\"button\"\n :class=\"ns.e('tool')\"\n :aria-label=\"t('image.flipVertical')\"\n :aria-pressed=\"flip.y < 0\"\n @click=\"mirror('y')\"\n >\n <FlipVerticalIcon />\n </button>\n <button type=\"button\" :class=\"ns.e('tool')\" :aria-label=\"t('image.reset')\" @click=\"reset\">\n <MaximizeIcon />\n </button>\n <template v-if=\"downloadable && current\">\n <span :class=\"ns.e('divider')\" aria-hidden=\"true\" />\n <button\n type=\"button\"\n :class=\"ns.e('tool')\"\n :aria-label=\"t('image.download')\"\n @click=\"downloadImage(current.src)\"\n >\n <DownloadIcon />\n </button>\n </template>\n </div>\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":""}
|