dou-ui 0.1.0-alpha.13 → 0.1.0-alpha.15
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/button/button.js.map +1 -1
- package/dist/components/button/button.vue_vue_type_script_setup_true_lang.js +9 -3
- package/dist/components/button/button.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/color-panel/style.js +1 -0
- package/dist/components/color-picker/style.js +1 -0
- package/dist/components/comment-thread/style.js +2 -0
- package/dist/components/context-menu/context-menu.js.map +1 -1
- package/dist/components/context-menu/context-menu.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/components/context-menu/context-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/copy-button/copy-button.js.map +1 -1
- package/dist/components/copy-button/copy-button.vue_vue_type_script_setup_true_lang.js +13 -5
- package/dist/components/copy-button/copy-button.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dropdown/dropdown-sub.js.map +1 -1
- package/dist/components/dropdown/dropdown-sub.vue_vue_type_script_setup_true_lang.js +8 -3
- package/dist/components/dropdown/dropdown-sub.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dropdown/dropdown.js.map +1 -1
- package/dist/components/dropdown/dropdown.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/components/dropdown/dropdown.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dropdown/dropdown2.js.map +1 -1
- package/dist/components/dropdown/style.js +2 -0
- package/dist/components/field-group/style.js +2 -0
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/input/input.vue_vue_type_script_setup_true_lang.js +22 -7
- package/dist/components/input/input.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/input-number/input-number.js.map +1 -1
- package/dist/components/input-number/input-number.vue_vue_type_script_setup_true_lang.js +22 -7
- package/dist/components/input-number/input-number.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/style.js +2 -0
- package/dist/components/menubar/style.js +2 -0
- package/dist/style.css +1 -1
- package/dist/types/components/dropdown/dropdown.d.ts +7 -0
- package/dist/types/utils/field-action.d.ts +59 -0
- package/dist/utils/field-action.js +139 -0
- package/dist/utils/field-action.js.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","names":["_sfc_main"],"sources":["../../../src/components/button/button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { Comment, Fragment, Text, computed, isVNode } from 'vue'\nimport type { VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { SlotNodes, filled } from '../../utils/slot'\nimport { useFormDisabled, useFormSize } from '../form/use-form-item'\nimport type { ButtonEmits, ButtonProps, ButtonSlots } from './button'\n\ndefineOptions({ name: 'DouButton' })\n\nconst props = withDefaults(defineProps<ButtonProps>(), {\n variant: 'solid',\n tone: 'neutral',\n disabled: false,\n loading: false,\n block: false,\n nativeType: 'button',\n})\nconst emit = defineEmits<ButtonEmits>()\nconst slots = defineSlots<ButtonSlots>()\n\nconst ns = useNamespace('button')\n\n// xs exists only on buttons, so a form or field group never sets it\nconst formSize = useFormSize(() => (props.size === 'xs' ? undefined : props.size))\nconst size = computed(() => (props.size === 'xs' ? 'xs' : formSize.value))\nconst disabled = useFormDisabled(() => props.disabled)\nconst inert = computed(() => disabled.value || props.loading)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.variant),\n ns.m(props.tone),\n ns.m(size.value),\n ns.is('loading', props.loading),\n ns.is('block', props.block),\n])\n\n// An icon passed as the only content of the default slot goes where the\n// leading icon would, so it is centered and the button turns square.\n// Components and svg/img count as icons; anything with text does not.\nfunction hasText(nodes: unknown): boolean {\n return (Array.isArray(nodes) ? nodes : [nodes]).some((node) => {\n if (!isVNode(node)) return typeof node === 'string' && node.trim() !== ''\n if (node.type === Comment) return false\n if (node.type === Text) return String(node.children).trim() !== ''\n if (\n node.type === Fragment ||\n (typeof node.type === 'string' && !['svg', 'img'].includes(node.type))\n )\n return hasText(node.children)\n return false\n })\n}\n\ninterface Layout {\n leading?: VNode[]\n label?: VNode[]\n trailing?: VNode[]\n /** The default slot holds only an icon, so it is sized and centered like one. */\n iconLabel: boolean\n iconOnly: boolean\n}\n\n// Each slot is rendered once a render, on the root's class binding, which is\n// evaluated before the content below it; the content puts down what was\n// rendered. A slot that renders nothing, e.g. a count behind a false `v-if`\n// next to a leading icon, counts as not passed.\nconst layout: Layout = { iconLabel: false, iconOnly: false }\nfunction measure() {\n const leading = filled(slots.leading)\n const label = filled(slots.default)\n const trailing = filled(slots.trailing)\n const iconLabel = !!label && !hasText(label)\n let iconOnly = false\n if (!trailing) iconOnly = label ? !leading && iconLabel : !!(leading || props.loading)\n Object.assign(layout, { leading, label, trailing, iconLabel, iconOnly })\n return iconOnly\n}\n\nfunction onClick(event: MouseEvent) {\n if (inert.value) return\n emit('click', event)\n}\n</script>\n\n<template>\n <button\n :class=\"[classes, ns.is('icon-only', measure())]\"\n :type=\"nativeType\"\n :disabled=\"disabled\"\n :aria-disabled=\"loading || undefined\"\n :aria-busy=\"loading || undefined\"\n @click=\"onClick\"\n >\n <span v-if=\"loading\" :class=\"ns.e('icon')\" aria-hidden=\"true\">\n <span :class=\"ns.e('spinner')\" />\n </span>\n <span v-else-if=\"layout.leading\" :class=\"ns.e('icon')\">\n <SlotNodes :nodes=\"layout.leading\" />\n </span>\n <template v-if=\"layout.label\">\n <span v-if=\"!layout.iconLabel\" :class=\"ns.e('label')\"\n ><SlotNodes :nodes=\"layout.label\"\n /></span>\n <span v-else-if=\"!loading\" :class=\"ns.e('icon')\"><SlotNodes :nodes=\"layout.label\" /></span>\n </template>\n <span v-if=\"layout.trailing\" :class=\"ns.e('icon')\">\n <SlotNodes :nodes=\"layout.trailing\" />\n </span>\n </button>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"button.js","names":["_sfc_main"],"sources":["../../../src/components/button/button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { Comment, Fragment, Text, computed, isVNode, useTemplateRef } from 'vue'\nimport type { VNode } from 'vue'\nimport { useFieldAction } from '../../utils/field-action'\nimport { useNamespace } from '../../utils/namespace'\nimport { SlotNodes, filled } from '../../utils/slot'\nimport { useFormDisabled, useFormSize } from '../form/use-form-item'\nimport type { ButtonEmits, ButtonProps, ButtonSlots } from './button'\n\ndefineOptions({ name: 'DouButton' })\n\nconst props = withDefaults(defineProps<ButtonProps>(), {\n variant: 'solid',\n tone: 'neutral',\n disabled: false,\n loading: false,\n block: false,\n nativeType: 'button',\n})\nconst emit = defineEmits<ButtonEmits>()\nconst slots = defineSlots<ButtonSlots>()\n\nconst ns = useNamespace('button')\n\n// xs exists only on buttons, so a form or field group never sets it\nconst formSize = useFormSize(() => (props.size === 'xs' ? undefined : props.size))\nconst size = computed(() => (props.size === 'xs' ? 'xs' : formSize.value))\n// in a field's prefix or suffix the button acts for the field: disabled\n// with it, and sized by it\nconst root = useTemplateRef<HTMLButtonElement>('root')\nconst fieldAction = useFieldAction(() => root.value)\nconst disabled = useFormDisabled(() => props.disabled || fieldAction.disabled())\nconst inert = computed(() => disabled.value || props.loading)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.variant),\n ns.m(props.tone),\n ns.m(size.value),\n ns.is('loading', props.loading),\n ns.is('block', props.block),\n ns.is('field-action', fieldAction.active.value),\n])\n\n// An icon passed as the only content of the default slot goes where the\n// leading icon would, so it is centered and the button turns square.\n// Components and svg/img count as icons; anything with text does not.\nfunction hasText(nodes: unknown): boolean {\n return (Array.isArray(nodes) ? nodes : [nodes]).some((node) => {\n if (!isVNode(node)) return typeof node === 'string' && node.trim() !== ''\n if (node.type === Comment) return false\n if (node.type === Text) return String(node.children).trim() !== ''\n if (\n node.type === Fragment ||\n (typeof node.type === 'string' && !['svg', 'img'].includes(node.type))\n )\n return hasText(node.children)\n return false\n })\n}\n\ninterface Layout {\n leading?: VNode[]\n label?: VNode[]\n trailing?: VNode[]\n /** The default slot holds only an icon, so it is sized and centered like one. */\n iconLabel: boolean\n iconOnly: boolean\n}\n\n// Each slot is rendered once a render, on the root's class binding, which is\n// evaluated before the content below it; the content puts down what was\n// rendered. A slot that renders nothing, e.g. a count behind a false `v-if`\n// next to a leading icon, counts as not passed.\nconst layout: Layout = { iconLabel: false, iconOnly: false }\nfunction measure() {\n const leading = filled(slots.leading)\n const label = filled(slots.default)\n const trailing = filled(slots.trailing)\n const iconLabel = !!label && !hasText(label)\n let iconOnly = false\n if (!trailing) iconOnly = label ? !leading && iconLabel : !!(leading || props.loading)\n Object.assign(layout, { leading, label, trailing, iconLabel, iconOnly })\n return iconOnly\n}\n\nfunction onClick(event: MouseEvent) {\n if (inert.value) return\n emit('click', event)\n}\n</script>\n\n<template>\n <button\n ref=\"root\"\n :class=\"[classes, ns.is('icon-only', measure())]\"\n :type=\"nativeType\"\n :disabled=\"disabled\"\n :aria-disabled=\"loading || undefined\"\n :aria-busy=\"loading || undefined\"\n @click=\"onClick\"\n >\n <span v-if=\"loading\" :class=\"ns.e('icon')\" aria-hidden=\"true\">\n <span :class=\"ns.e('spinner')\" />\n </span>\n <span v-else-if=\"layout.leading\" :class=\"ns.e('icon')\">\n <SlotNodes :nodes=\"layout.leading\" />\n </span>\n <template v-if=\"layout.label\">\n <span v-if=\"!layout.iconLabel\" :class=\"ns.e('label')\"\n ><SlotNodes :nodes=\"layout.label\"\n /></span>\n <span v-else-if=\"!loading\" :class=\"ns.e('icon')\"><SlotNodes :nodes=\"layout.label\" /></span>\n </template>\n <span v-if=\"layout.trailing\" :class=\"ns.e('icon')\">\n <SlotNodes :nodes=\"layout.trailing\" />\n </span>\n </button>\n</template>\n"],"mappings":""}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useNamespace } from "../../utils/namespace.js";
|
|
2
2
|
import { useFormDisabled, useFormSize } from "../form/use-form-item.js";
|
|
3
|
+
import { useFieldAction } from "../../utils/field-action.js";
|
|
3
4
|
import { SlotNodes, filled } from "../../utils/slot.js";
|
|
4
|
-
import { Comment, Fragment, Text, computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, isVNode, normalizeClass, openBlock, unref, useSlots } from "vue";
|
|
5
|
+
import { Comment, Fragment, Text, computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, isVNode, normalizeClass, openBlock, unref, useSlots, useTemplateRef } from "vue";
|
|
5
6
|
// src/components/button/button.vue?vue&type=script&setup=true&lang.ts
|
|
6
7
|
var _hoisted_1 = [
|
|
7
8
|
"type",
|
|
@@ -38,7 +39,9 @@ var button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCom
|
|
|
38
39
|
const ns = useNamespace("button");
|
|
39
40
|
const formSize = useFormSize(() => props.size === "xs" ? void 0 : props.size);
|
|
40
41
|
const size = computed(() => props.size === "xs" ? "xs" : formSize.value);
|
|
41
|
-
const
|
|
42
|
+
const root = useTemplateRef("root");
|
|
43
|
+
const fieldAction = useFieldAction(() => root.value);
|
|
44
|
+
const disabled = useFormDisabled(() => props.disabled || fieldAction.disabled());
|
|
42
45
|
const inert = computed(() => disabled.value || props.loading);
|
|
43
46
|
const classes = computed(() => [
|
|
44
47
|
ns.b(),
|
|
@@ -46,7 +49,8 @@ var button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCom
|
|
|
46
49
|
ns.m(props.tone),
|
|
47
50
|
ns.m(size.value),
|
|
48
51
|
ns.is("loading", props.loading),
|
|
49
|
-
ns.is("block", props.block)
|
|
52
|
+
ns.is("block", props.block),
|
|
53
|
+
ns.is("field-action", fieldAction.active.value)
|
|
50
54
|
]);
|
|
51
55
|
function hasText(nodes) {
|
|
52
56
|
return (Array.isArray(nodes) ? nodes : [nodes]).some((node) => {
|
|
@@ -83,6 +87,8 @@ var button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCom
|
|
|
83
87
|
}
|
|
84
88
|
return (_ctx, _cache) => {
|
|
85
89
|
return openBlock(), createElementBlock("button", {
|
|
90
|
+
ref_key: "root",
|
|
91
|
+
ref: root,
|
|
86
92
|
class: normalizeClass([classes.value, unref(ns).is("icon-only", measure())]),
|
|
87
93
|
type: __props.nativeType,
|
|
88
94
|
disabled: unref(disabled),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","_createElementVNode","_createVNode","_createCommentVNode","_Fragment"],"sources":["../../../src/components/button/button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { Comment, Fragment, Text, computed, isVNode } from 'vue'\nimport type { VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { SlotNodes, filled } from '../../utils/slot'\nimport { useFormDisabled, useFormSize } from '../form/use-form-item'\nimport type { ButtonEmits, ButtonProps, ButtonSlots } from './button'\n\ndefineOptions({ name: 'DouButton' })\n\nconst props = withDefaults(defineProps<ButtonProps>(), {\n variant: 'solid',\n tone: 'neutral',\n disabled: false,\n loading: false,\n block: false,\n nativeType: 'button',\n})\nconst emit = defineEmits<ButtonEmits>()\nconst slots = defineSlots<ButtonSlots>()\n\nconst ns = useNamespace('button')\n\n// xs exists only on buttons, so a form or field group never sets it\nconst formSize = useFormSize(() => (props.size === 'xs' ? undefined : props.size))\nconst size = computed(() => (props.size === 'xs' ? 'xs' : formSize.value))\nconst disabled = useFormDisabled(() => props.disabled)\nconst inert = computed(() => disabled.value || props.loading)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.variant),\n ns.m(props.tone),\n ns.m(size.value),\n ns.is('loading', props.loading),\n ns.is('block', props.block),\n])\n\n// An icon passed as the only content of the default slot goes where the\n// leading icon would, so it is centered and the button turns square.\n// Components and svg/img count as icons; anything with text does not.\nfunction hasText(nodes: unknown): boolean {\n return (Array.isArray(nodes) ? nodes : [nodes]).some((node) => {\n if (!isVNode(node)) return typeof node === 'string' && node.trim() !== ''\n if (node.type === Comment) return false\n if (node.type === Text) return String(node.children).trim() !== ''\n if (\n node.type === Fragment ||\n (typeof node.type === 'string' && !['svg', 'img'].includes(node.type))\n )\n return hasText(node.children)\n return false\n })\n}\n\ninterface Layout {\n leading?: VNode[]\n label?: VNode[]\n trailing?: VNode[]\n /** The default slot holds only an icon, so it is sized and centered like one. */\n iconLabel: boolean\n iconOnly: boolean\n}\n\n// Each slot is rendered once a render, on the root's class binding, which is\n// evaluated before the content below it; the content puts down what was\n// rendered. A slot that renders nothing, e.g. a count behind a false `v-if`\n// next to a leading icon, counts as not passed.\nconst layout: Layout = { iconLabel: false, iconOnly: false }\nfunction measure() {\n const leading = filled(slots.leading)\n const label = filled(slots.default)\n const trailing = filled(slots.trailing)\n const iconLabel = !!label && !hasText(label)\n let iconOnly = false\n if (!trailing) iconOnly = label ? !leading && iconLabel : !!(leading || props.loading)\n Object.assign(layout, { leading, label, trailing, iconLabel, iconOnly })\n return iconOnly\n}\n\nfunction onClick(event: MouseEvent) {\n if (inert.value) return\n emit('click', event)\n}\n</script>\n\n<template>\n <button\n :class=\"[classes, ns.is('icon-only', measure())]\"\n :type=\"nativeType\"\n :disabled=\"disabled\"\n :aria-disabled=\"loading || undefined\"\n :aria-busy=\"loading || undefined\"\n @click=\"onClick\"\n >\n <span v-if=\"loading\" :class=\"ns.e('icon')\" aria-hidden=\"true\">\n <span :class=\"ns.e('spinner')\" />\n </span>\n <span v-else-if=\"layout.leading\" :class=\"ns.e('icon')\">\n <SlotNodes :nodes=\"layout.leading\" />\n </span>\n <template v-if=\"layout.label\">\n <span v-if=\"!layout.iconLabel\" :class=\"ns.e('label')\"\n ><SlotNodes :nodes=\"layout.label\"\n /></span>\n <span v-else-if=\"!loading\" :class=\"ns.e('icon')\"><SlotNodes :nodes=\"layout.label\" /></span>\n </template>\n <span v-if=\"layout.trailing\" :class=\"ns.e('icon')\">\n <SlotNodes :nodes=\"layout.trailing\" />\n </span>\n </button>\n</template>\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"button.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","_createElementVNode","_createVNode","_createCommentVNode","_Fragment"],"sources":["../../../src/components/button/button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { Comment, Fragment, Text, computed, isVNode, useTemplateRef } from 'vue'\nimport type { VNode } from 'vue'\nimport { useFieldAction } from '../../utils/field-action'\nimport { useNamespace } from '../../utils/namespace'\nimport { SlotNodes, filled } from '../../utils/slot'\nimport { useFormDisabled, useFormSize } from '../form/use-form-item'\nimport type { ButtonEmits, ButtonProps, ButtonSlots } from './button'\n\ndefineOptions({ name: 'DouButton' })\n\nconst props = withDefaults(defineProps<ButtonProps>(), {\n variant: 'solid',\n tone: 'neutral',\n disabled: false,\n loading: false,\n block: false,\n nativeType: 'button',\n})\nconst emit = defineEmits<ButtonEmits>()\nconst slots = defineSlots<ButtonSlots>()\n\nconst ns = useNamespace('button')\n\n// xs exists only on buttons, so a form or field group never sets it\nconst formSize = useFormSize(() => (props.size === 'xs' ? undefined : props.size))\nconst size = computed(() => (props.size === 'xs' ? 'xs' : formSize.value))\n// in a field's prefix or suffix the button acts for the field: disabled\n// with it, and sized by it\nconst root = useTemplateRef<HTMLButtonElement>('root')\nconst fieldAction = useFieldAction(() => root.value)\nconst disabled = useFormDisabled(() => props.disabled || fieldAction.disabled())\nconst inert = computed(() => disabled.value || props.loading)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.variant),\n ns.m(props.tone),\n ns.m(size.value),\n ns.is('loading', props.loading),\n ns.is('block', props.block),\n ns.is('field-action', fieldAction.active.value),\n])\n\n// An icon passed as the only content of the default slot goes where the\n// leading icon would, so it is centered and the button turns square.\n// Components and svg/img count as icons; anything with text does not.\nfunction hasText(nodes: unknown): boolean {\n return (Array.isArray(nodes) ? nodes : [nodes]).some((node) => {\n if (!isVNode(node)) return typeof node === 'string' && node.trim() !== ''\n if (node.type === Comment) return false\n if (node.type === Text) return String(node.children).trim() !== ''\n if (\n node.type === Fragment ||\n (typeof node.type === 'string' && !['svg', 'img'].includes(node.type))\n )\n return hasText(node.children)\n return false\n })\n}\n\ninterface Layout {\n leading?: VNode[]\n label?: VNode[]\n trailing?: VNode[]\n /** The default slot holds only an icon, so it is sized and centered like one. */\n iconLabel: boolean\n iconOnly: boolean\n}\n\n// Each slot is rendered once a render, on the root's class binding, which is\n// evaluated before the content below it; the content puts down what was\n// rendered. A slot that renders nothing, e.g. a count behind a false `v-if`\n// next to a leading icon, counts as not passed.\nconst layout: Layout = { iconLabel: false, iconOnly: false }\nfunction measure() {\n const leading = filled(slots.leading)\n const label = filled(slots.default)\n const trailing = filled(slots.trailing)\n const iconLabel = !!label && !hasText(label)\n let iconOnly = false\n if (!trailing) iconOnly = label ? !leading && iconLabel : !!(leading || props.loading)\n Object.assign(layout, { leading, label, trailing, iconLabel, iconOnly })\n return iconOnly\n}\n\nfunction onClick(event: MouseEvent) {\n if (inert.value) return\n emit('click', event)\n}\n</script>\n\n<template>\n <button\n ref=\"root\"\n :class=\"[classes, ns.is('icon-only', measure())]\"\n :type=\"nativeType\"\n :disabled=\"disabled\"\n :aria-disabled=\"loading || undefined\"\n :aria-busy=\"loading || undefined\"\n @click=\"onClick\"\n >\n <span v-if=\"loading\" :class=\"ns.e('icon')\" aria-hidden=\"true\">\n <span :class=\"ns.e('spinner')\" />\n </span>\n <span v-else-if=\"layout.leading\" :class=\"ns.e('icon')\">\n <SlotNodes :nodes=\"layout.leading\" />\n </span>\n <template v-if=\"layout.label\">\n <span v-if=\"!layout.iconLabel\" :class=\"ns.e('label')\"\n ><SlotNodes :nodes=\"layout.label\"\n /></span>\n <span v-else-if=\"!loading\" :class=\"ns.e('icon')\"><SlotNodes :nodes=\"layout.label\" /></span>\n </template>\n <span v-if=\"layout.trailing\" :class=\"ns.e('icon')\">\n <SlotNodes :nodes=\"layout.trailing\" />\n </span>\n </button>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWA,MAA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AAA,CAAA;I,IACxCE,YACDF,MAAA,SAAA,GAAA,EADa,OAAO,OAAO,M,+BAEX,CAAA,QAAA,WAAlBH,UAAA,GAAAC,mBAA2F,QAAA;;KAA/D,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA,CAAA;I,IAAUE,YAAmCF,MAAA,SAAA,GAAA,EAAvB,OAAO,OAAO,M;IAEjE,OAAO,YAAnBH,UAAA,GAAAC,mBAEO,QAAA;;KAFuB,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA,CAAA;I,IACvCE,YAAsCF,MAAA,SAAA,GAAA,EAA1B,OAAO,OAAO,S"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import '@dou-ui/theme/core.css'
|
|
2
2
|
import '@dou-ui/theme/components/overlay.css'
|
|
3
3
|
import '@dou-ui/theme/components/color-panel.css'
|
|
4
|
+
import '@dou-ui/theme/components/input-number.css'
|
|
4
5
|
import '@dou-ui/theme/components/input.css'
|
|
5
6
|
import '@dou-ui/theme/components/select.css'
|
|
6
7
|
import '@dou-ui/theme/components/spinner.css'
|
|
@@ -2,6 +2,7 @@ import '@dou-ui/theme/core.css'
|
|
|
2
2
|
import '@dou-ui/theme/components/overlay.css'
|
|
3
3
|
import '@dou-ui/theme/components/color-panel.css'
|
|
4
4
|
import '@dou-ui/theme/components/color-picker.css'
|
|
5
|
+
import '@dou-ui/theme/components/input-number.css'
|
|
5
6
|
import '@dou-ui/theme/components/input.css'
|
|
6
7
|
import '@dou-ui/theme/components/picker.css'
|
|
7
8
|
import '@dou-ui/theme/components/select.css'
|
|
@@ -7,6 +7,8 @@ import '@dou-ui/theme/components/color-panel.css'
|
|
|
7
7
|
import '@dou-ui/theme/components/comment-thread.css'
|
|
8
8
|
import '@dou-ui/theme/components/dropdown.css'
|
|
9
9
|
import '@dou-ui/theme/components/icon.css'
|
|
10
|
+
import '@dou-ui/theme/components/input-number.css'
|
|
11
|
+
import '@dou-ui/theme/components/input.css'
|
|
10
12
|
import '@dou-ui/theme/components/kbd.css'
|
|
11
13
|
import '@dou-ui/theme/components/textarea.css'
|
|
12
14
|
import '@dou-ui/theme/components/tooltip.css'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-menu.js","names":["_sfc_main"],"sources":["../../../src/components/context-menu/context-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n onScopeDispose,\n provide,\n ref,\n useId,\n watch,\n} from 'vue'\nimport type { ComponentPublicInstance } from 'vue'\nimport { useFloating } from '../../composables/use-floating'\nimport { useLayer } from '../../composables/use-layer'\nimport { useThemeScope } from '../../composables/use-theme-scope'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild, onlyChildElement } from '../../utils/only-child'\nimport { useZIndex } from '../config-provider/use-config'\nimport { dropdownKey } from '../dropdown/dropdown'\nimport type { DropdownValue } from '../dropdown/dropdown'\nimport { useMenuKeys } from '../dropdown/menu-keys'\nimport type { ContextMenuExpose, ContextMenuProps, ContextMenuSlots } from './context-menu'\nimport DropdownItems from '../dropdown/dropdown-items.vue'\nimport { useItemsWarning } from '../dropdown/items-warning'\nimport { findMenuItem } from '../dropdown/menu-entries'\nimport { useTeleport } from '../../utils/teleport'\nimport { devWarn } from '../../utils/status-check'\n\ndefineOptions({ name: 'DouContextMenu', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ContextMenuProps>(), {\n disabled: false,\n hideOnSelect: true,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\nconst emit = defineEmits<{\n select: [value: DropdownValue | undefined]\n 'update:target': [target: undefined]\n}>()\nconst slots = defineSlots<ContextMenuSlots>()\nuseItemsWarning('ContextMenu', () => !!props.items && !!slots.menu)\n\nconst ns = useNamespace('context-menu')\nconst dropdown = useNamespace('dropdown')\nconst id = `dou-context-menu-${useId()}`\n\nconst triggerRef = ref<ComponentPublicInstance | null>(null)\nconst panelRef = ref<HTMLElement | null>(null)\nconst trigger = () => onlyChildElement(triggerRef.value)\n\n// The menu hangs off a zero-size box at the point that opened it, or off\n// the box it was given, e.g. a button's, so that flipping keeps it clear.\nconst point = ref({ x: 0, y: 0, width: 0, height: 0 })\nconst anchor = {\n getBoundingClientRect: () =>\n new DOMRect(point.value.x, point.value.y, point.value.width, point.value.height),\n}\nconst floating = useFloating(() => anchor, panelRef, {\n open,\n placement: 'bottom-start',\n offset: 2,\n})\n\nconst rendered = ref(open.value)\nconst zIndex = ref<number>()\nconst { next } = useZIndex()\nconst { theme, sync } = useThemeScope(trigger)\n\n// Where focus was before the menu opened, to hand it back on Escape.\nlet restore: HTMLElement | null = null\n\nwatch(open, (value) => {\n if (!value) return\n rendered.value = true\n zIndex.value = next()\n sync()\n})\n\nfunction show(x: number, y: number, box?: { width: number; height: number }) {\n if (props.disabled) return\n point.value = { x, y, width: box?.width ?? 0, height: box?.height ?? 0 }\n if (!open.value) {\n const active = document.activeElement\n restore = active instanceof HTMLElement && !panelRef.value?.contains(active) ? active : null\n }\n open.value = true\n void nextTick(() => {\n floating.update()\n panelRef.value?.focus({ preventScroll: true })\n })\n}\n\nfunction hide() {\n open.value = false\n}\n\nfunction dismiss() {\n // Focus in a submenu counts as in the menu too.\n const active = document.activeElement as HTMLElement | null\n const back = !!(panelRef.value?.contains(active) || active?.closest('.dou-dropdown--sub'))\n hide()\n if (back) (restore ?? (trigger() as HTMLElement | null))?.focus()\n}\n\n// A new right click starts with no target; the events inside set it.\n// Listened to on the document so it runs before them, whatever element the\n// trigger renders now.\nfunction onDocumentContextmenu(event: MouseEvent) {\n if (props.disabled) return\n const el = trigger()\n if (el && event.target instanceof Node && el.contains(event.target))\n emit('update:target', undefined)\n}\nonMounted(() => document.addEventListener('contextmenu', onDocumentContextmenu, true))\nonBeforeUnmount(() => document.removeEventListener('contextmenu', onDocumentContextmenu, true))\n\nfunction onContextmenu(event: MouseEvent) {\n if (props.disabled) return\n if (!press?.fired) cancelPress()\n // Something inside handled this right click already, or the app said no:\n // `false` leaves it to the browser or an outer menu, `preventDefault()` to no one.\n if (event.defaultPrevented) return\n const allowed = props.beforeOpen?.(event)\n if (\n process.env.NODE_ENV !== 'production' &&\n typeof (allowed as unknown as PromiseLike<unknown> | undefined)?.then === 'function'\n )\n devWarn(\n '[dou-ui] DouContextMenu: `beforeOpen` must decide on the spot (return true or false); a Promise is ignored and the menu opens.',\n )\n if (allowed === false || event.defaultPrevented) return\n event.preventDefault()\n // A menu opened from the keyboard has no pointer position: open it at\n // the bottom left of the focused element instead.\n if (event.button === -1 || (event.clientX === 0 && event.clientY === 0)) {\n const source = event.target instanceof Element ? event.target : trigger()\n const box = source?.getBoundingClientRect()\n show(box?.left ?? 0, box?.bottom ?? 0)\n return\n }\n show(event.clientX, event.clientY)\n}\n\n/*\n * A long press opens the menu on touch screens. Safari on iOS never sends\n * `contextmenu` for one, so the press sends its own from where the finger\n * went down: listeners that note which item was pressed keep working.\n * Moving the finger first scrolls instead; the click that follows the press\n * is swallowed so it does not choose the item now under the finger.\n */\nconst LONG_PRESS = 500\nconst SLOP = 8\ninterface Press {\n x: number\n y: number\n timer: number\n el: HTMLElement\n origin: Element\n style: string | null\n fired: boolean\n}\nlet press: Press | null = null\n\nfunction onPointerdown(event: PointerEvent) {\n if (props.disabled || event.pointerType === 'mouse' || !event.isPrimary) return\n cancelPress()\n const el = event.currentTarget as HTMLElement\n const origin = event.target instanceof Element ? event.target : el\n const { clientX: x, clientY: y } = event\n // keep the press from selecting text or raising the system callout\n const style = el.getAttribute('style')\n el.style.setProperty('-webkit-touch-callout', 'none')\n el.style.setProperty('-webkit-user-select', 'none')\n el.style.setProperty('user-select', 'none')\n const timer = window.setTimeout(() => {\n if (!press) return\n press.fired = true\n window.getSelection()?.removeAllRanges()\n const from = press.origin.isConnected ? press.origin : el\n from.dispatchEvent(\n new MouseEvent('contextmenu', {\n bubbles: true,\n cancelable: true,\n composed: true,\n button: 2,\n buttons: 0,\n clientX: x,\n clientY: y,\n }),\n )\n }, LONG_PRESS)\n press = { x, y, timer, el, origin, style, fired: false }\n window.addEventListener('pointermove', onPressMove, { passive: true })\n window.addEventListener('pointerup', onPressEnd)\n window.addEventListener('pointercancel', cancelPress)\n}\n\nfunction onPressMove(event: PointerEvent) {\n if (press && !press.fired && Math.hypot(event.clientX - press.x, event.clientY - press.y) > SLOP)\n cancelPress()\n}\n\nfunction onPressEnd() {\n if (press?.fired) swallowClick()\n cancelPress()\n}\n\nfunction cancelPress() {\n if (!press) return\n window.clearTimeout(press.timer)\n if (press.style === null) press.el.removeAttribute('style')\n else press.el.setAttribute('style', press.style)\n press = null\n window.removeEventListener('pointermove', onPressMove)\n window.removeEventListener('pointerup', onPressEnd)\n window.removeEventListener('pointercancel', cancelPress)\n}\n\nfunction swallow(event: Event) {\n event.preventDefault()\n event.stopPropagation()\n}\n\n/** Drop the click the lifted finger may still produce. */\nfunction swallowClick() {\n window.addEventListener('click', swallow, { capture: true, once: true })\n window.setTimeout(() => window.removeEventListener('click', swallow, { capture: true }), 400)\n}\n\nonScopeDispose(cancelPress)\n\nuseLayer({\n open,\n elements: () => [panelRef.value],\n onEscape: dismiss,\n onOutside: hide,\n})\n\n// The menu stays where it was opened, so scrolling the page under it closes it.\nfunction onScroll(event: Event) {\n if (event.target instanceof Node && panelRef.value?.contains(event.target)) return\n hide()\n}\nwatch(open, (value) => {\n if (typeof window === 'undefined') return\n const method = value ? 'addEventListener' : 'removeEventListener'\n window[method]('scroll', onScroll, { capture: true, passive: true })\n window[method]('resize', hide)\n window[method]('blur', hide)\n})\nonScopeDispose(() => {\n if (typeof window === 'undefined') return\n window.removeEventListener('scroll', onScroll, { capture: true })\n window.removeEventListener('resize', hide)\n window.removeEventListener('blur', hide)\n})\n\nconst onMenuKeydown = useMenuKeys(\n () => panelRef.value,\n () => dismiss(),\n)\n\nprovide(dropdownKey, {\n select(value) {\n findMenuItem(props.items, value)?.run?.()\n emit('select', value)\n if (props.hideOnSelect) dismiss()\n },\n opened: () => open.value,\n hold: () => {},\n release: () => {},\n})\n\nconst panelStyle = computed(() => ({ ...floating.style.value, zIndex: zIndex.value }))\n\ndefineExpose<ContextMenuExpose>({ open: show, close: hide })\n</script>\n\n<template>\n <OnlyChild ref=\"triggerRef\" @contextmenu=\"onContextmenu\" @pointerdown=\"onPointerdown\">\n <slot />\n </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=\"menu\"\n tabindex=\"-1\"\n :class=\"[dropdown.b(), ns.b(), 'dou-floating']\"\n :style=\"panelStyle\"\n :data-placement=\"floating.placement.value\"\n :data-dou-theme=\"theme\"\n v-bind=\"$attrs\"\n @keydown=\"onMenuKeydown\"\n @contextmenu.prevent\n >\n <slot name=\"menu\"><DropdownItems v-if=\"props.items\" :items=\"props.items\" /></slot>\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"context-menu.js","names":["_sfc_main"],"sources":["../../../src/components/context-menu/context-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n onScopeDispose,\n provide,\n ref,\n useAttrs,\n useId,\n watch,\n} from 'vue'\nimport type { ComponentPublicInstance } from 'vue'\nimport { useFloating } from '../../composables/use-floating'\nimport { useLayer } from '../../composables/use-layer'\nimport { useThemeScope } from '../../composables/use-theme-scope'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild, onlyChildElement } from '../../utils/only-child'\nimport { useZIndex } from '../config-provider/use-config'\nimport { dropdownKey } from '../dropdown/dropdown'\nimport type { DropdownValue } from '../dropdown/dropdown'\nimport { useMenuKeys } from '../dropdown/menu-keys'\nimport type { ContextMenuExpose, ContextMenuProps, ContextMenuSlots } from './context-menu'\nimport DropdownItems from '../dropdown/dropdown-items.vue'\nimport { useItemsWarning } from '../dropdown/items-warning'\nimport { findMenuItem } from '../dropdown/menu-entries'\nimport { useTeleport } from '../../utils/teleport'\nimport { devWarn } from '../../utils/status-check'\n\ndefineOptions({ name: 'DouContextMenu', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ContextMenuProps>(), {\n disabled: false,\n hideOnSelect: true,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\nconst emit = defineEmits<{\n select: [value: DropdownValue | undefined]\n 'update:target': [target: undefined]\n}>()\nconst slots = defineSlots<ContextMenuSlots>()\nuseItemsWarning('ContextMenu', () => !!props.items && !!slots.menu)\n\nconst ns = useNamespace('context-menu')\nconst dropdown = useNamespace('dropdown')\nconst id = `dou-context-menu-${useId()}`\n\nconst triggerRef = ref<ComponentPublicInstance | null>(null)\nconst panelRef = ref<HTMLElement | null>(null)\nconst trigger = () => onlyChildElement(triggerRef.value)\n\n// The menu hangs off a zero-size box at the point that opened it, or off\n// the box it was given, e.g. a button's, so that flipping keeps it clear.\nconst point = ref({ x: 0, y: 0, width: 0, height: 0 })\nconst anchor = {\n getBoundingClientRect: () =>\n new DOMRect(point.value.x, point.value.y, point.value.width, point.value.height),\n}\nconst floating = useFloating(() => anchor, panelRef, {\n open,\n placement: 'bottom-start',\n offset: 2,\n})\n\nconst rendered = ref(open.value)\nconst zIndex = ref<number>()\nconst { next } = useZIndex()\nconst { theme, sync } = useThemeScope(trigger)\n\n// Where focus was before the menu opened, to hand it back on Escape.\nlet restore: HTMLElement | null = null\n\nwatch(open, (value) => {\n if (!value) return\n rendered.value = true\n zIndex.value = next()\n sync()\n})\n\nfunction show(x: number, y: number, box?: { width: number; height: number }) {\n if (props.disabled) return\n point.value = { x, y, width: box?.width ?? 0, height: box?.height ?? 0 }\n if (!open.value) {\n const active = document.activeElement\n restore = active instanceof HTMLElement && !panelRef.value?.contains(active) ? active : null\n }\n open.value = true\n void nextTick(() => {\n floating.update()\n panelRef.value?.focus({ preventScroll: true })\n })\n}\n\nfunction hide() {\n open.value = false\n}\n\nfunction dismiss() {\n // Focus in a submenu counts as in the menu too.\n const active = document.activeElement as HTMLElement | null\n const back = !!(panelRef.value?.contains(active) || active?.closest('.dou-dropdown--sub'))\n hide()\n if (back) (restore ?? (trigger() as HTMLElement | null))?.focus()\n}\n\n// A new right click starts with no target; the events inside set it.\n// Listened to on the document so it runs before them, whatever element the\n// trigger renders now.\nfunction onDocumentContextmenu(event: MouseEvent) {\n if (props.disabled) return\n const el = trigger()\n if (el && event.target instanceof Node && el.contains(event.target))\n emit('update:target', undefined)\n}\nonMounted(() => document.addEventListener('contextmenu', onDocumentContextmenu, true))\nonBeforeUnmount(() => document.removeEventListener('contextmenu', onDocumentContextmenu, true))\n\nfunction onContextmenu(event: MouseEvent) {\n if (props.disabled) return\n if (!press?.fired) cancelPress()\n // Something inside handled this right click already, or the app said no:\n // `false` leaves it to the browser or an outer menu, `preventDefault()` to no one.\n if (event.defaultPrevented) return\n const allowed = props.beforeOpen?.(event)\n if (\n process.env.NODE_ENV !== 'production' &&\n typeof (allowed as unknown as PromiseLike<unknown> | undefined)?.then === 'function'\n )\n devWarn(\n '[dou-ui] DouContextMenu: `beforeOpen` must decide on the spot (return true or false); a Promise is ignored and the menu opens.',\n )\n if (allowed === false || event.defaultPrevented) return\n event.preventDefault()\n // A menu opened from the keyboard has no pointer position: open it at\n // the bottom left of the focused element instead.\n if (event.button === -1 || (event.clientX === 0 && event.clientY === 0)) {\n const source = event.target instanceof Element ? event.target : trigger()\n const box = source?.getBoundingClientRect()\n show(box?.left ?? 0, box?.bottom ?? 0)\n return\n }\n show(event.clientX, event.clientY)\n}\n\n/*\n * A long press opens the menu on touch screens. Safari on iOS never sends\n * `contextmenu` for one, so the press sends its own from where the finger\n * went down: listeners that note which item was pressed keep working.\n * Moving the finger first scrolls instead; the click that follows the press\n * is swallowed so it does not choose the item now under the finger.\n */\nconst LONG_PRESS = 500\nconst SLOP = 8\ninterface Press {\n x: number\n y: number\n timer: number\n el: HTMLElement\n origin: Element\n style: string | null\n fired: boolean\n}\nlet press: Press | null = null\n\nfunction onPointerdown(event: PointerEvent) {\n if (props.disabled || event.pointerType === 'mouse' || !event.isPrimary) return\n cancelPress()\n const el = event.currentTarget as HTMLElement\n const origin = event.target instanceof Element ? event.target : el\n const { clientX: x, clientY: y } = event\n // keep the press from selecting text or raising the system callout\n const style = el.getAttribute('style')\n el.style.setProperty('-webkit-touch-callout', 'none')\n el.style.setProperty('-webkit-user-select', 'none')\n el.style.setProperty('user-select', 'none')\n const timer = window.setTimeout(() => {\n if (!press) return\n press.fired = true\n window.getSelection()?.removeAllRanges()\n const from = press.origin.isConnected ? press.origin : el\n from.dispatchEvent(\n new MouseEvent('contextmenu', {\n bubbles: true,\n cancelable: true,\n composed: true,\n button: 2,\n buttons: 0,\n clientX: x,\n clientY: y,\n }),\n )\n }, LONG_PRESS)\n press = { x, y, timer, el, origin, style, fired: false }\n window.addEventListener('pointermove', onPressMove, { passive: true })\n window.addEventListener('pointerup', onPressEnd)\n window.addEventListener('pointercancel', cancelPress)\n}\n\nfunction onPressMove(event: PointerEvent) {\n if (press && !press.fired && Math.hypot(event.clientX - press.x, event.clientY - press.y) > SLOP)\n cancelPress()\n}\n\nfunction onPressEnd() {\n if (press?.fired) swallowClick()\n cancelPress()\n}\n\nfunction cancelPress() {\n if (!press) return\n window.clearTimeout(press.timer)\n if (press.style === null) press.el.removeAttribute('style')\n else press.el.setAttribute('style', press.style)\n press = null\n window.removeEventListener('pointermove', onPressMove)\n window.removeEventListener('pointerup', onPressEnd)\n window.removeEventListener('pointercancel', cancelPress)\n}\n\nfunction swallow(event: Event) {\n event.preventDefault()\n event.stopPropagation()\n}\n\n/** Drop the click the lifted finger may still produce. */\nfunction swallowClick() {\n window.addEventListener('click', swallow, { capture: true, once: true })\n window.setTimeout(() => window.removeEventListener('click', swallow, { capture: true }), 400)\n}\n\nonScopeDispose(cancelPress)\n\nuseLayer({\n open,\n elements: () => [panelRef.value],\n onEscape: dismiss,\n onOutside: hide,\n})\n\n// The menu stays where it was opened, so scrolling the page under it closes it.\nfunction onScroll(event: Event) {\n if (event.target instanceof Node && panelRef.value?.contains(event.target)) return\n hide()\n}\nwatch(open, (value) => {\n if (typeof window === 'undefined') return\n const method = value ? 'addEventListener' : 'removeEventListener'\n window[method]('scroll', onScroll, { capture: true, passive: true })\n window[method]('resize', hide)\n window[method]('blur', hide)\n})\nonScopeDispose(() => {\n if (typeof window === 'undefined') return\n window.removeEventListener('scroll', onScroll, { capture: true })\n window.removeEventListener('resize', hide)\n window.removeEventListener('blur', hide)\n})\n\nconst onMenuKeydown = useMenuKeys(\n () => panelRef.value,\n () => dismiss(),\n)\n\nconst attrs = useAttrs()\n\nprovide(dropdownKey, {\n select(value) {\n findMenuItem(props.items, value)?.run?.()\n emit('select', value)\n if (props.hideOnSelect) dismiss()\n },\n opened: () => open.value,\n hold: () => {},\n release: () => {},\n panelClass: () => attrs.class,\n teleport: () => teleportTarget.value,\n})\n\nconst panelStyle = computed(() => ({ ...floating.style.value, zIndex: zIndex.value }))\n\ndefineExpose<ContextMenuExpose>({ open: show, close: hide })\n</script>\n\n<template>\n <OnlyChild ref=\"triggerRef\" @contextmenu=\"onContextmenu\" @pointerdown=\"onPointerdown\">\n <slot />\n </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=\"menu\"\n tabindex=\"-1\"\n :class=\"[dropdown.b(), ns.b(), 'dou-floating']\"\n :style=\"panelStyle\"\n :data-placement=\"floating.placement.value\"\n :data-dou-theme=\"theme\"\n v-bind=\"$attrs\"\n @keydown=\"onMenuKeydown\"\n @contextmenu.prevent\n >\n <slot name=\"menu\"><DropdownItems v-if=\"props.items\" :items=\"props.items\" /></slot>\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":""}
|
|
@@ -11,7 +11,7 @@ import { useMenuKeys } from "../dropdown/menu-keys.js";
|
|
|
11
11
|
import { findMenuItem } from "../dropdown/menu-entries.js";
|
|
12
12
|
import dropdown_items_default from "../dropdown/dropdown-items.js";
|
|
13
13
|
import { useItemsWarning } from "../dropdown/items-warning.js";
|
|
14
|
-
import { Fragment, Teleport, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, mergeModels, mergeProps, nextTick, onBeforeUnmount, onMounted, onScopeDispose, openBlock, provide, ref, renderSlot, unref, useId, useModel, useSlots, vShow, watch, withCtx, withDirectives, withModifiers } from "vue";
|
|
14
|
+
import { Fragment, Teleport, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, mergeModels, mergeProps, nextTick, onBeforeUnmount, onMounted, onScopeDispose, openBlock, provide, ref, renderSlot, unref, useAttrs, useId, useModel, useSlots, vShow, watch, withCtx, withDirectives, withModifiers } from "vue";
|
|
15
15
|
// src/components/context-menu/context-menu.vue?vue&type=script&setup=true&lang.ts
|
|
16
16
|
var _hoisted_1 = ["data-placement", "data-dou-theme"];
|
|
17
17
|
var LONG_PRESS = 500;
|
|
@@ -224,6 +224,7 @@ var context_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
224
224
|
window.removeEventListener("blur", hide);
|
|
225
225
|
});
|
|
226
226
|
const onMenuKeydown = useMenuKeys(() => panelRef.value, () => dismiss());
|
|
227
|
+
const attrs = useAttrs();
|
|
227
228
|
provide(dropdownKey, {
|
|
228
229
|
select(value) {
|
|
229
230
|
findMenuItem(props.items, value)?.run?.();
|
|
@@ -232,7 +233,9 @@ var context_menu_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
232
233
|
},
|
|
233
234
|
opened: () => open.value,
|
|
234
235
|
hold: () => {},
|
|
235
|
-
release: () => {}
|
|
236
|
+
release: () => {},
|
|
237
|
+
panelClass: () => attrs.class,
|
|
238
|
+
teleport: () => teleportTarget.value
|
|
236
239
|
});
|
|
237
240
|
const panelStyle = computed(() => ({
|
|
238
241
|
...floating.style.value,
|
package/dist/components/context-menu/context-menu.vue_vue_type_script_setup_true_lang.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-menu.vue_vue_type_script_setup_true_lang.js","names":["$attrs","_useModel","_useSlots","_openBlock","_createElementBlock","_Fragment","_createVNode","_unref","_withCtx","_renderSlot","_createBlock","_Teleport","_Transition","_withDirectives","_createElementVNode","_mergeProps","_withModifiers","DropdownItems","_createCommentVNode","_vShow"],"sources":["../../../src/components/context-menu/context-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n onScopeDispose,\n provide,\n ref,\n useId,\n watch,\n} from 'vue'\nimport type { ComponentPublicInstance } from 'vue'\nimport { useFloating } from '../../composables/use-floating'\nimport { useLayer } from '../../composables/use-layer'\nimport { useThemeScope } from '../../composables/use-theme-scope'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild, onlyChildElement } from '../../utils/only-child'\nimport { useZIndex } from '../config-provider/use-config'\nimport { dropdownKey } from '../dropdown/dropdown'\nimport type { DropdownValue } from '../dropdown/dropdown'\nimport { useMenuKeys } from '../dropdown/menu-keys'\nimport type { ContextMenuExpose, ContextMenuProps, ContextMenuSlots } from './context-menu'\nimport DropdownItems from '../dropdown/dropdown-items.vue'\nimport { useItemsWarning } from '../dropdown/items-warning'\nimport { findMenuItem } from '../dropdown/menu-entries'\nimport { useTeleport } from '../../utils/teleport'\nimport { devWarn } from '../../utils/status-check'\n\ndefineOptions({ name: 'DouContextMenu', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ContextMenuProps>(), {\n disabled: false,\n hideOnSelect: true,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\nconst emit = defineEmits<{\n select: [value: DropdownValue | undefined]\n 'update:target': [target: undefined]\n}>()\nconst slots = defineSlots<ContextMenuSlots>()\nuseItemsWarning('ContextMenu', () => !!props.items && !!slots.menu)\n\nconst ns = useNamespace('context-menu')\nconst dropdown = useNamespace('dropdown')\nconst id = `dou-context-menu-${useId()}`\n\nconst triggerRef = ref<ComponentPublicInstance | null>(null)\nconst panelRef = ref<HTMLElement | null>(null)\nconst trigger = () => onlyChildElement(triggerRef.value)\n\n// The menu hangs off a zero-size box at the point that opened it, or off\n// the box it was given, e.g. a button's, so that flipping keeps it clear.\nconst point = ref({ x: 0, y: 0, width: 0, height: 0 })\nconst anchor = {\n getBoundingClientRect: () =>\n new DOMRect(point.value.x, point.value.y, point.value.width, point.value.height),\n}\nconst floating = useFloating(() => anchor, panelRef, {\n open,\n placement: 'bottom-start',\n offset: 2,\n})\n\nconst rendered = ref(open.value)\nconst zIndex = ref<number>()\nconst { next } = useZIndex()\nconst { theme, sync } = useThemeScope(trigger)\n\n// Where focus was before the menu opened, to hand it back on Escape.\nlet restore: HTMLElement | null = null\n\nwatch(open, (value) => {\n if (!value) return\n rendered.value = true\n zIndex.value = next()\n sync()\n})\n\nfunction show(x: number, y: number, box?: { width: number; height: number }) {\n if (props.disabled) return\n point.value = { x, y, width: box?.width ?? 0, height: box?.height ?? 0 }\n if (!open.value) {\n const active = document.activeElement\n restore = active instanceof HTMLElement && !panelRef.value?.contains(active) ? active : null\n }\n open.value = true\n void nextTick(() => {\n floating.update()\n panelRef.value?.focus({ preventScroll: true })\n })\n}\n\nfunction hide() {\n open.value = false\n}\n\nfunction dismiss() {\n // Focus in a submenu counts as in the menu too.\n const active = document.activeElement as HTMLElement | null\n const back = !!(panelRef.value?.contains(active) || active?.closest('.dou-dropdown--sub'))\n hide()\n if (back) (restore ?? (trigger() as HTMLElement | null))?.focus()\n}\n\n// A new right click starts with no target; the events inside set it.\n// Listened to on the document so it runs before them, whatever element the\n// trigger renders now.\nfunction onDocumentContextmenu(event: MouseEvent) {\n if (props.disabled) return\n const el = trigger()\n if (el && event.target instanceof Node && el.contains(event.target))\n emit('update:target', undefined)\n}\nonMounted(() => document.addEventListener('contextmenu', onDocumentContextmenu, true))\nonBeforeUnmount(() => document.removeEventListener('contextmenu', onDocumentContextmenu, true))\n\nfunction onContextmenu(event: MouseEvent) {\n if (props.disabled) return\n if (!press?.fired) cancelPress()\n // Something inside handled this right click already, or the app said no:\n // `false` leaves it to the browser or an outer menu, `preventDefault()` to no one.\n if (event.defaultPrevented) return\n const allowed = props.beforeOpen?.(event)\n if (\n process.env.NODE_ENV !== 'production' &&\n typeof (allowed as unknown as PromiseLike<unknown> | undefined)?.then === 'function'\n )\n devWarn(\n '[dou-ui] DouContextMenu: `beforeOpen` must decide on the spot (return true or false); a Promise is ignored and the menu opens.',\n )\n if (allowed === false || event.defaultPrevented) return\n event.preventDefault()\n // A menu opened from the keyboard has no pointer position: open it at\n // the bottom left of the focused element instead.\n if (event.button === -1 || (event.clientX === 0 && event.clientY === 0)) {\n const source = event.target instanceof Element ? event.target : trigger()\n const box = source?.getBoundingClientRect()\n show(box?.left ?? 0, box?.bottom ?? 0)\n return\n }\n show(event.clientX, event.clientY)\n}\n\n/*\n * A long press opens the menu on touch screens. Safari on iOS never sends\n * `contextmenu` for one, so the press sends its own from where the finger\n * went down: listeners that note which item was pressed keep working.\n * Moving the finger first scrolls instead; the click that follows the press\n * is swallowed so it does not choose the item now under the finger.\n */\nconst LONG_PRESS = 500\nconst SLOP = 8\ninterface Press {\n x: number\n y: number\n timer: number\n el: HTMLElement\n origin: Element\n style: string | null\n fired: boolean\n}\nlet press: Press | null = null\n\nfunction onPointerdown(event: PointerEvent) {\n if (props.disabled || event.pointerType === 'mouse' || !event.isPrimary) return\n cancelPress()\n const el = event.currentTarget as HTMLElement\n const origin = event.target instanceof Element ? event.target : el\n const { clientX: x, clientY: y } = event\n // keep the press from selecting text or raising the system callout\n const style = el.getAttribute('style')\n el.style.setProperty('-webkit-touch-callout', 'none')\n el.style.setProperty('-webkit-user-select', 'none')\n el.style.setProperty('user-select', 'none')\n const timer = window.setTimeout(() => {\n if (!press) return\n press.fired = true\n window.getSelection()?.removeAllRanges()\n const from = press.origin.isConnected ? press.origin : el\n from.dispatchEvent(\n new MouseEvent('contextmenu', {\n bubbles: true,\n cancelable: true,\n composed: true,\n button: 2,\n buttons: 0,\n clientX: x,\n clientY: y,\n }),\n )\n }, LONG_PRESS)\n press = { x, y, timer, el, origin, style, fired: false }\n window.addEventListener('pointermove', onPressMove, { passive: true })\n window.addEventListener('pointerup', onPressEnd)\n window.addEventListener('pointercancel', cancelPress)\n}\n\nfunction onPressMove(event: PointerEvent) {\n if (press && !press.fired && Math.hypot(event.clientX - press.x, event.clientY - press.y) > SLOP)\n cancelPress()\n}\n\nfunction onPressEnd() {\n if (press?.fired) swallowClick()\n cancelPress()\n}\n\nfunction cancelPress() {\n if (!press) return\n window.clearTimeout(press.timer)\n if (press.style === null) press.el.removeAttribute('style')\n else press.el.setAttribute('style', press.style)\n press = null\n window.removeEventListener('pointermove', onPressMove)\n window.removeEventListener('pointerup', onPressEnd)\n window.removeEventListener('pointercancel', cancelPress)\n}\n\nfunction swallow(event: Event) {\n event.preventDefault()\n event.stopPropagation()\n}\n\n/** Drop the click the lifted finger may still produce. */\nfunction swallowClick() {\n window.addEventListener('click', swallow, { capture: true, once: true })\n window.setTimeout(() => window.removeEventListener('click', swallow, { capture: true }), 400)\n}\n\nonScopeDispose(cancelPress)\n\nuseLayer({\n open,\n elements: () => [panelRef.value],\n onEscape: dismiss,\n onOutside: hide,\n})\n\n// The menu stays where it was opened, so scrolling the page under it closes it.\nfunction onScroll(event: Event) {\n if (event.target instanceof Node && panelRef.value?.contains(event.target)) return\n hide()\n}\nwatch(open, (value) => {\n if (typeof window === 'undefined') return\n const method = value ? 'addEventListener' : 'removeEventListener'\n window[method]('scroll', onScroll, { capture: true, passive: true })\n window[method]('resize', hide)\n window[method]('blur', hide)\n})\nonScopeDispose(() => {\n if (typeof window === 'undefined') return\n window.removeEventListener('scroll', onScroll, { capture: true })\n window.removeEventListener('resize', hide)\n window.removeEventListener('blur', hide)\n})\n\nconst onMenuKeydown = useMenuKeys(\n () => panelRef.value,\n () => dismiss(),\n)\n\nprovide(dropdownKey, {\n select(value) {\n findMenuItem(props.items, value)?.run?.()\n emit('select', value)\n if (props.hideOnSelect) dismiss()\n },\n opened: () => open.value,\n hold: () => {},\n release: () => {},\n})\n\nconst panelStyle = computed(() => ({ ...floating.style.value, zIndex: zIndex.value }))\n\ndefineExpose<ContextMenuExpose>({ open: show, close: hide })\n</script>\n\n<template>\n <OnlyChild ref=\"triggerRef\" @contextmenu=\"onContextmenu\" @pointerdown=\"onPointerdown\">\n <slot />\n </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=\"menu\"\n tabindex=\"-1\"\n :class=\"[dropdown.b(), ns.b(), 'dou-floating']\"\n :style=\"panelStyle\"\n :data-placement=\"floating.placement.value\"\n :data-dou-theme=\"theme\"\n v-bind=\"$attrs\"\n @keydown=\"onMenuKeydown\"\n @contextmenu.prevent\n >\n <slot name=\"menu\"><DropdownItems v-if=\"props.items\" :items=\"props.items\" /></slot>\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;AAyJA,IAAM,aAAa;AACnB,IAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA3Hb,MAAM,QAAQ;EAKd,MAAM,iBAAiB,kBAAkB,MAAM,QAAQ;EACvD,MAAM,OAAOC,SAAoB,SAAC,MAA0B;EAC5D,MAAM,OAAO;EAIb,MAAM,QAAQC,SAAA;EACd,gBAAgB,qBAAqB,CAAC,CAAC,MAAM,SAAS,CAAC,CAAC,MAAM,IAAI;EAElE,MAAM,KAAK,aAAa,cAAc;EACtC,MAA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,cAAQ,CAARC,WAAQ,KAAA,QAAA,SAAA,C;;G,SAEM,SAAA,SAAhBN,UAAA,GAAAO,YAmBWC,UAAA;;IAnBgB,IAAIJ,MAAA,cAAA,CAAc,CAAC;IAAK,UAAUA,MAAA,cAAA,CAAc,CAAC;G,IAC1ED,YAiBaM,YAAA;IAjBD,QAAA;IAAO,MAAK;IAAxB,WAAA;;IACE,SAAAJ,cAeM,CAfNK,eAAAC,mBAeM,OAfNC,WAeM;KAbC;KACD,SAAA;KAAJ,KAAI;KACJ,MAAK;KACL,UAAS;KACR,OAAK;MAAGR,MAAA,QAAA,CAAQ,CAAC,EAAC;MAAIA,MAAA,EAAA,CAAE,CAAC,EAAC;MAAA;KAAA;KAC1B,OAAO,WAAA;KACP,kBAAgBA,MAAA,QAAA,CAAQ,CAAC,UAAU;KACnC,kBAAgBA,MAAA,KAAA;IACTP,GAAAA,KAAAA,QAAM;KACb,WAAO,OAAA,OAAA,OAAA,MAAE,GAAA,SAAAO,MAAA,aAAA,KAAAA,MAAA,aAAA,CAAA,CAAA,GAAA,IAAA;KACT,eAAW,OAAA,OAAA,OAAA,KAAAS,oBAAZ,CAAA,GAAoB,CAAA,SAAA,CAAA;I,KAEpBP,WAAkF,KAAA,QAAA,QAAA,CAAA,SAAA,CAA3C,MAAM,SAA3BN,UAAA,GAAAO,YAAyDO,wBAAA;;KAAtB,OAAO,MAAM;I,6EAb1D,CAAAE,OAAA,KAAA,KAAI,C"}
|
|
1
|
+
{"version":3,"file":"context-menu.vue_vue_type_script_setup_true_lang.js","names":["$attrs","_useModel","_useSlots","_openBlock","_createElementBlock","_Fragment","_createVNode","_unref","_withCtx","_renderSlot","_createBlock","_Teleport","_Transition","_withDirectives","_createElementVNode","_mergeProps","_withModifiers","DropdownItems","_createCommentVNode","_vShow"],"sources":["../../../src/components/context-menu/context-menu.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n onScopeDispose,\n provide,\n ref,\n useAttrs,\n useId,\n watch,\n} from 'vue'\nimport type { ComponentPublicInstance } from 'vue'\nimport { useFloating } from '../../composables/use-floating'\nimport { useLayer } from '../../composables/use-layer'\nimport { useThemeScope } from '../../composables/use-theme-scope'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild, onlyChildElement } from '../../utils/only-child'\nimport { useZIndex } from '../config-provider/use-config'\nimport { dropdownKey } from '../dropdown/dropdown'\nimport type { DropdownValue } from '../dropdown/dropdown'\nimport { useMenuKeys } from '../dropdown/menu-keys'\nimport type { ContextMenuExpose, ContextMenuProps, ContextMenuSlots } from './context-menu'\nimport DropdownItems from '../dropdown/dropdown-items.vue'\nimport { useItemsWarning } from '../dropdown/items-warning'\nimport { findMenuItem } from '../dropdown/menu-entries'\nimport { useTeleport } from '../../utils/teleport'\nimport { devWarn } from '../../utils/status-check'\n\ndefineOptions({ name: 'DouContextMenu', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<ContextMenuProps>(), {\n disabled: false,\n hideOnSelect: true,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\nconst emit = defineEmits<{\n select: [value: DropdownValue | undefined]\n 'update:target': [target: undefined]\n}>()\nconst slots = defineSlots<ContextMenuSlots>()\nuseItemsWarning('ContextMenu', () => !!props.items && !!slots.menu)\n\nconst ns = useNamespace('context-menu')\nconst dropdown = useNamespace('dropdown')\nconst id = `dou-context-menu-${useId()}`\n\nconst triggerRef = ref<ComponentPublicInstance | null>(null)\nconst panelRef = ref<HTMLElement | null>(null)\nconst trigger = () => onlyChildElement(triggerRef.value)\n\n// The menu hangs off a zero-size box at the point that opened it, or off\n// the box it was given, e.g. a button's, so that flipping keeps it clear.\nconst point = ref({ x: 0, y: 0, width: 0, height: 0 })\nconst anchor = {\n getBoundingClientRect: () =>\n new DOMRect(point.value.x, point.value.y, point.value.width, point.value.height),\n}\nconst floating = useFloating(() => anchor, panelRef, {\n open,\n placement: 'bottom-start',\n offset: 2,\n})\n\nconst rendered = ref(open.value)\nconst zIndex = ref<number>()\nconst { next } = useZIndex()\nconst { theme, sync } = useThemeScope(trigger)\n\n// Where focus was before the menu opened, to hand it back on Escape.\nlet restore: HTMLElement | null = null\n\nwatch(open, (value) => {\n if (!value) return\n rendered.value = true\n zIndex.value = next()\n sync()\n})\n\nfunction show(x: number, y: number, box?: { width: number; height: number }) {\n if (props.disabled) return\n point.value = { x, y, width: box?.width ?? 0, height: box?.height ?? 0 }\n if (!open.value) {\n const active = document.activeElement\n restore = active instanceof HTMLElement && !panelRef.value?.contains(active) ? active : null\n }\n open.value = true\n void nextTick(() => {\n floating.update()\n panelRef.value?.focus({ preventScroll: true })\n })\n}\n\nfunction hide() {\n open.value = false\n}\n\nfunction dismiss() {\n // Focus in a submenu counts as in the menu too.\n const active = document.activeElement as HTMLElement | null\n const back = !!(panelRef.value?.contains(active) || active?.closest('.dou-dropdown--sub'))\n hide()\n if (back) (restore ?? (trigger() as HTMLElement | null))?.focus()\n}\n\n// A new right click starts with no target; the events inside set it.\n// Listened to on the document so it runs before them, whatever element the\n// trigger renders now.\nfunction onDocumentContextmenu(event: MouseEvent) {\n if (props.disabled) return\n const el = trigger()\n if (el && event.target instanceof Node && el.contains(event.target))\n emit('update:target', undefined)\n}\nonMounted(() => document.addEventListener('contextmenu', onDocumentContextmenu, true))\nonBeforeUnmount(() => document.removeEventListener('contextmenu', onDocumentContextmenu, true))\n\nfunction onContextmenu(event: MouseEvent) {\n if (props.disabled) return\n if (!press?.fired) cancelPress()\n // Something inside handled this right click already, or the app said no:\n // `false` leaves it to the browser or an outer menu, `preventDefault()` to no one.\n if (event.defaultPrevented) return\n const allowed = props.beforeOpen?.(event)\n if (\n process.env.NODE_ENV !== 'production' &&\n typeof (allowed as unknown as PromiseLike<unknown> | undefined)?.then === 'function'\n )\n devWarn(\n '[dou-ui] DouContextMenu: `beforeOpen` must decide on the spot (return true or false); a Promise is ignored and the menu opens.',\n )\n if (allowed === false || event.defaultPrevented) return\n event.preventDefault()\n // A menu opened from the keyboard has no pointer position: open it at\n // the bottom left of the focused element instead.\n if (event.button === -1 || (event.clientX === 0 && event.clientY === 0)) {\n const source = event.target instanceof Element ? event.target : trigger()\n const box = source?.getBoundingClientRect()\n show(box?.left ?? 0, box?.bottom ?? 0)\n return\n }\n show(event.clientX, event.clientY)\n}\n\n/*\n * A long press opens the menu on touch screens. Safari on iOS never sends\n * `contextmenu` for one, so the press sends its own from where the finger\n * went down: listeners that note which item was pressed keep working.\n * Moving the finger first scrolls instead; the click that follows the press\n * is swallowed so it does not choose the item now under the finger.\n */\nconst LONG_PRESS = 500\nconst SLOP = 8\ninterface Press {\n x: number\n y: number\n timer: number\n el: HTMLElement\n origin: Element\n style: string | null\n fired: boolean\n}\nlet press: Press | null = null\n\nfunction onPointerdown(event: PointerEvent) {\n if (props.disabled || event.pointerType === 'mouse' || !event.isPrimary) return\n cancelPress()\n const el = event.currentTarget as HTMLElement\n const origin = event.target instanceof Element ? event.target : el\n const { clientX: x, clientY: y } = event\n // keep the press from selecting text or raising the system callout\n const style = el.getAttribute('style')\n el.style.setProperty('-webkit-touch-callout', 'none')\n el.style.setProperty('-webkit-user-select', 'none')\n el.style.setProperty('user-select', 'none')\n const timer = window.setTimeout(() => {\n if (!press) return\n press.fired = true\n window.getSelection()?.removeAllRanges()\n const from = press.origin.isConnected ? press.origin : el\n from.dispatchEvent(\n new MouseEvent('contextmenu', {\n bubbles: true,\n cancelable: true,\n composed: true,\n button: 2,\n buttons: 0,\n clientX: x,\n clientY: y,\n }),\n )\n }, LONG_PRESS)\n press = { x, y, timer, el, origin, style, fired: false }\n window.addEventListener('pointermove', onPressMove, { passive: true })\n window.addEventListener('pointerup', onPressEnd)\n window.addEventListener('pointercancel', cancelPress)\n}\n\nfunction onPressMove(event: PointerEvent) {\n if (press && !press.fired && Math.hypot(event.clientX - press.x, event.clientY - press.y) > SLOP)\n cancelPress()\n}\n\nfunction onPressEnd() {\n if (press?.fired) swallowClick()\n cancelPress()\n}\n\nfunction cancelPress() {\n if (!press) return\n window.clearTimeout(press.timer)\n if (press.style === null) press.el.removeAttribute('style')\n else press.el.setAttribute('style', press.style)\n press = null\n window.removeEventListener('pointermove', onPressMove)\n window.removeEventListener('pointerup', onPressEnd)\n window.removeEventListener('pointercancel', cancelPress)\n}\n\nfunction swallow(event: Event) {\n event.preventDefault()\n event.stopPropagation()\n}\n\n/** Drop the click the lifted finger may still produce. */\nfunction swallowClick() {\n window.addEventListener('click', swallow, { capture: true, once: true })\n window.setTimeout(() => window.removeEventListener('click', swallow, { capture: true }), 400)\n}\n\nonScopeDispose(cancelPress)\n\nuseLayer({\n open,\n elements: () => [panelRef.value],\n onEscape: dismiss,\n onOutside: hide,\n})\n\n// The menu stays where it was opened, so scrolling the page under it closes it.\nfunction onScroll(event: Event) {\n if (event.target instanceof Node && panelRef.value?.contains(event.target)) return\n hide()\n}\nwatch(open, (value) => {\n if (typeof window === 'undefined') return\n const method = value ? 'addEventListener' : 'removeEventListener'\n window[method]('scroll', onScroll, { capture: true, passive: true })\n window[method]('resize', hide)\n window[method]('blur', hide)\n})\nonScopeDispose(() => {\n if (typeof window === 'undefined') return\n window.removeEventListener('scroll', onScroll, { capture: true })\n window.removeEventListener('resize', hide)\n window.removeEventListener('blur', hide)\n})\n\nconst onMenuKeydown = useMenuKeys(\n () => panelRef.value,\n () => dismiss(),\n)\n\nconst attrs = useAttrs()\n\nprovide(dropdownKey, {\n select(value) {\n findMenuItem(props.items, value)?.run?.()\n emit('select', value)\n if (props.hideOnSelect) dismiss()\n },\n opened: () => open.value,\n hold: () => {},\n release: () => {},\n panelClass: () => attrs.class,\n teleport: () => teleportTarget.value,\n})\n\nconst panelStyle = computed(() => ({ ...floating.style.value, zIndex: zIndex.value }))\n\ndefineExpose<ContextMenuExpose>({ open: show, close: hide })\n</script>\n\n<template>\n <OnlyChild ref=\"triggerRef\" @contextmenu=\"onContextmenu\" @pointerdown=\"onPointerdown\">\n <slot />\n </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=\"menu\"\n tabindex=\"-1\"\n :class=\"[dropdown.b(), ns.b(), 'dou-floating']\"\n :style=\"panelStyle\"\n :data-placement=\"floating.placement.value\"\n :data-dou-theme=\"theme\"\n v-bind=\"$attrs\"\n @keydown=\"onMenuKeydown\"\n @contextmenu.prevent\n >\n <slot name=\"menu\"><DropdownItems v-if=\"props.items\" :items=\"props.items\" /></slot>\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;AA0JA,IAAM,aAAa;AACnB,IAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA3Hb,MAAM,QAAQ;EAKd,MAAM,iBAAiB,kBAAkB,MAAM,QAAQ;EACvD,MAAM,OAAOC,SAAoB,SAAC,MAA0B;EAC5D,MAAM,OAAO;EAIb,MAAM,QAAQC,SAAA;EACd,gBAAgB,qBAAqB,CAAC,CAAC,MAAM,SAAS,CAAC,CAAC,MAAM,IAAI;EAElE,MAAM,KAAK,aAAa,cAAc;EACtC,MAAM,WAAW,aAAa,UAAU;EACxC,MAAM,KAAK,oBAAoB,MAAM;EAErC,MAAM,aAAa,IAAoC,IAAI;EAC3D,MAAM,WAAW,IAAwB,IAAI;EAC7C,MAAM,gBAAgB,iBAAiB,WAAW,KAAK;EAIvD,MAAM,QAAQ,IAAI;GAAE,GAAG;GAAG,GAAG;GAAG,OAAO;GAAG,QAAQ;EAAE,CAAC;EACrD,MAAM,SAAS,EACb,6BACE,IAAI,QAAQ,MAAM,MAAM,GAAG,MAAM,MAAM,GAAG,MAAM,MAAM,OAAO,MAAM,MAAM,MAAM,EACnF;EACA,MAAM,WAAW,kBAAkB,QAAQ,UAAU;GACnD;GACA,WAAW;GACX,QAAQ;EACV,CAAC;EAED,MAAM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,EAAC;MAAIA,MAAA,EAAA,CAAE,CAAC,EAAC;MAAA;KAAA;KAC1B,OAAO,WAAA;KACP,kBAAgBA,MAAA,QAAA,CAAQ,CAAC,UAAU;KACnC,kBAAgBA,MAAA,KAAA;IACTP,GAAAA,KAAAA,QAAM;KACb,WAAO,OAAA,OAAA,OAAA,MAAE,GAAA,SAAAO,MAAA,aAAA,KAAAA,MAAA,aAAA,CAAA,CAAA,GAAA,IAAA;KACT,eAAW,OAAA,OAAA,OAAA,KAAAS,oBAAZ,CAAA,GAAoB,CAAA,SAAA,CAAA;I,KAEpBP,WAAkF,KAAA,QAAA,QAAA,CAAA,SAAA,CAA3C,MAAM,SAA3BN,UAAA,GAAAO,YAAyDO,wBAAA;;KAAtB,OAAO,MAAM;I,6EAb1D,CAAAE,OAAA,KAAA,KAAI,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy-button.js","names":["_sfc_main"],"sources":["../../../src/components/copy-button/copy-button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, CopyIcon } from '@dou-ui/icons'\nimport { computed } from 'vue'\nimport { useClipboard } from '../../composables/use-clipboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouTooltip } from '../tooltip'\nimport type { CopyButtonProps } from './copy-button'\n\n// The root is the tooltip, so attributes go on the button by hand.\ndefineOptions({ name: 'DouCopyButton', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<CopyButtonProps>(), {\n text: '',\n showLabel: false,\n size: 'md',\n variant: 'ghost',\n duration: 2000,\n disabled: false,\n})\nconst emit = defineEmits<{ copy: [text: string]; error: [error: unknown] }>()\n\nconst ns = useNamespace('copy-button')\nconst { t } = useLocale()\n\nconst clipboard = useClipboard({ duration: () => props.duration })\nconst copied = clipboard.copied\n\nasync function copy() {\n if (
|
|
1
|
+
{"version":3,"file":"copy-button.js","names":["_sfc_main"],"sources":["../../../src/components/copy-button/copy-button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, CopyIcon } from '@dou-ui/icons'\nimport { computed, useTemplateRef } from 'vue'\nimport { useClipboard } from '../../composables/use-clipboard'\nimport { useFieldAction } from '../../utils/field-action'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouTooltip } from '../tooltip'\nimport type { CopyButtonProps } from './copy-button'\n\n// The root is the tooltip, so attributes go on the button by hand.\ndefineOptions({ name: 'DouCopyButton', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<CopyButtonProps>(), {\n text: '',\n showLabel: false,\n size: 'md',\n variant: 'ghost',\n duration: 2000,\n disabled: false,\n})\nconst emit = defineEmits<{ copy: [text: string]; error: [error: unknown] }>()\n\nconst ns = useNamespace('copy-button')\n// in a field's prefix or suffix the button acts for the field: disabled\n// with it, and sized by it\nconst root = useTemplateRef<HTMLButtonElement>('root')\nconst fieldAction = useFieldAction(() => root.value)\nconst disabled = computed(() => props.disabled || fieldAction.disabled())\nconst { t } = useLocale()\n\nconst clipboard = useClipboard({ duration: () => props.duration })\nconst copied = clipboard.copied\n\nasync function copy() {\n if (disabled.value) return\n try {\n const text = typeof props.text === 'function' ? await props.text() : props.text\n await clipboard.copy(text)\n emit('copy', text)\n } catch (error) {\n emit('error', error)\n }\n}\n\nconst label = computed(() => props.label ?? t('copyButton.copy'))\nconst copiedLabel = computed(() => props.copiedLabel ?? t('copyButton.copied'))\n</script>\n\n<template>\n <!-- Only the icon shows: its name goes in a tooltip. -->\n <DouTooltip :content=\"copied ? copiedLabel : label\" :disabled=\"showLabel\">\n <button\n ref=\"root\"\n v-bind=\"$attrs\"\n type=\"button\"\n :class=\"[\n ns.b(),\n ns.m(size),\n ns.m(variant),\n ns.is('copied', copied),\n ns.is('labelled', showLabel),\n ns.is('field-action', fieldAction.active.value),\n ]\"\n :disabled=\"disabled\"\n :aria-label=\"copied ? copiedLabel : label\"\n @click=\"copy\"\n >\n <CheckIcon v-if=\"copied\" :class=\"ns.e('icon')\" />\n <CopyIcon v-else :class=\"ns.e('icon')\" />\n <span v-if=\"showLabel\" :class=\"ns.e('label')\">{{ copied ? copiedLabel : label }}</span>\n <span :class=\"ns.e('status')\" role=\"status\">{{ copied ? copiedLabel : '' }}</span>\n </button>\n </DouTooltip>\n</template>\n"],"mappings":""}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useNamespace } from "../../utils/namespace.js";
|
|
2
2
|
import { useLocale } from "../config-provider/use-config.js";
|
|
3
|
+
import { useFieldAction } from "../../utils/field-action.js";
|
|
3
4
|
import { useClipboard } from "../../composables/use-clipboard.js";
|
|
4
5
|
import { DouTooltip } from "../tooltip/index.js";
|
|
5
|
-
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, defineComponent, mergeProps, normalizeClass, openBlock, toDisplayString, unref, withCtx } from "vue";
|
|
6
|
+
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, defineComponent, mergeProps, normalizeClass, openBlock, toDisplayString, unref, useTemplateRef, withCtx } from "vue";
|
|
6
7
|
import { CheckIcon, CopyIcon } from "@dou-ui/icons";
|
|
7
8
|
// src/components/copy-button/copy-button.vue?vue&type=script&setup=true&lang.ts
|
|
8
9
|
var _hoisted_1 = ["disabled", "aria-label"];
|
|
@@ -34,11 +35,14 @@ var copy_button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
34
35
|
const props = __props;
|
|
35
36
|
const emit = __emit;
|
|
36
37
|
const ns = useNamespace("copy-button");
|
|
38
|
+
const root = useTemplateRef("root");
|
|
39
|
+
const fieldAction = useFieldAction(() => root.value);
|
|
40
|
+
const disabled = computed(() => props.disabled || fieldAction.disabled());
|
|
37
41
|
const { t } = useLocale();
|
|
38
42
|
const clipboard = useClipboard({ duration: () => props.duration });
|
|
39
43
|
const copied = clipboard.copied;
|
|
40
44
|
async function copy() {
|
|
41
|
-
if (
|
|
45
|
+
if (disabled.value) return;
|
|
42
46
|
try {
|
|
43
47
|
const text = typeof props.text === "function" ? await props.text() : props.text;
|
|
44
48
|
await clipboard.copy(text);
|
|
@@ -54,16 +58,20 @@ var copy_button_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
54
58
|
content: unref(copied) ? copiedLabel.value : label.value,
|
|
55
59
|
disabled: __props.showLabel
|
|
56
60
|
}, {
|
|
57
|
-
default: withCtx(() => [createElementVNode("button", mergeProps(
|
|
61
|
+
default: withCtx(() => [createElementVNode("button", mergeProps({
|
|
62
|
+
ref_key: "root",
|
|
63
|
+
ref: root
|
|
64
|
+
}, _ctx.$attrs, {
|
|
58
65
|
type: "button",
|
|
59
66
|
class: [
|
|
60
67
|
unref(ns).b(),
|
|
61
68
|
unref(ns).m(__props.size),
|
|
62
69
|
unref(ns).m(__props.variant),
|
|
63
70
|
unref(ns).is("copied", unref(copied)),
|
|
64
|
-
unref(ns).is("labelled", __props.showLabel)
|
|
71
|
+
unref(ns).is("labelled", __props.showLabel),
|
|
72
|
+
unref(ns).is("field-action", unref(fieldAction).active.value)
|
|
65
73
|
],
|
|
66
|
-
disabled:
|
|
74
|
+
disabled: disabled.value,
|
|
67
75
|
"aria-label": unref(copied) ? copiedLabel.value : label.value,
|
|
68
76
|
onClick: copy
|
|
69
77
|
}), [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy-button.vue_vue_type_script_setup_true_lang.js","names":["$attrs","_openBlock","_createBlock","_unref","_withCtx","_createElementVNode","_mergeProps","_normalizeClass","_createElementBlock","_toDisplayString","_createCommentVNode"],"sources":["../../../src/components/copy-button/copy-button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, CopyIcon } from '@dou-ui/icons'\nimport { computed } from 'vue'\nimport { useClipboard } from '../../composables/use-clipboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouTooltip } from '../tooltip'\nimport type { CopyButtonProps } from './copy-button'\n\n// The root is the tooltip, so attributes go on the button by hand.\ndefineOptions({ name: 'DouCopyButton', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<CopyButtonProps>(), {\n text: '',\n showLabel: false,\n size: 'md',\n variant: 'ghost',\n duration: 2000,\n disabled: false,\n})\nconst emit = defineEmits<{ copy: [text: string]; error: [error: unknown] }>()\n\nconst ns = useNamespace('copy-button')\nconst { t } = useLocale()\n\nconst clipboard = useClipboard({ duration: () => props.duration })\nconst copied = clipboard.copied\n\nasync function copy() {\n if (
|
|
1
|
+
{"version":3,"file":"copy-button.vue_vue_type_script_setup_true_lang.js","names":["$attrs","_openBlock","_createBlock","_unref","_withCtx","_createElementVNode","_mergeProps","_normalizeClass","_createElementBlock","_toDisplayString","_createCommentVNode"],"sources":["../../../src/components/copy-button/copy-button.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CheckIcon, CopyIcon } from '@dou-ui/icons'\nimport { computed, useTemplateRef } from 'vue'\nimport { useClipboard } from '../../composables/use-clipboard'\nimport { useFieldAction } from '../../utils/field-action'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouTooltip } from '../tooltip'\nimport type { CopyButtonProps } from './copy-button'\n\n// The root is the tooltip, so attributes go on the button by hand.\ndefineOptions({ name: 'DouCopyButton', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<CopyButtonProps>(), {\n text: '',\n showLabel: false,\n size: 'md',\n variant: 'ghost',\n duration: 2000,\n disabled: false,\n})\nconst emit = defineEmits<{ copy: [text: string]; error: [error: unknown] }>()\n\nconst ns = useNamespace('copy-button')\n// in a field's prefix or suffix the button acts for the field: disabled\n// with it, and sized by it\nconst root = useTemplateRef<HTMLButtonElement>('root')\nconst fieldAction = useFieldAction(() => root.value)\nconst disabled = computed(() => props.disabled || fieldAction.disabled())\nconst { t } = useLocale()\n\nconst clipboard = useClipboard({ duration: () => props.duration })\nconst copied = clipboard.copied\n\nasync function copy() {\n if (disabled.value) return\n try {\n const text = typeof props.text === 'function' ? await props.text() : props.text\n await clipboard.copy(text)\n emit('copy', text)\n } catch (error) {\n emit('error', error)\n }\n}\n\nconst label = computed(() => props.label ?? t('copyButton.copy'))\nconst copiedLabel = computed(() => props.copiedLabel ?? t('copyButton.copied'))\n</script>\n\n<template>\n <!-- Only the icon shows: its name goes in a tooltip. -->\n <DouTooltip :content=\"copied ? copiedLabel : label\" :disabled=\"showLabel\">\n <button\n ref=\"root\"\n v-bind=\"$attrs\"\n type=\"button\"\n :class=\"[\n ns.b(),\n ns.m(size),\n ns.m(variant),\n ns.is('copied', copied),\n ns.is('labelled', showLabel),\n ns.is('field-action', fieldAction.active.value),\n ]\"\n :disabled=\"disabled\"\n :aria-label=\"copied ? copiedLabel : label\"\n @click=\"copy\"\n >\n <CheckIcon v-if=\"copied\" :class=\"ns.e('icon')\" />\n <CopyIcon v-else :class=\"ns.e('icon')\" />\n <span v-if=\"showLabel\" :class=\"ns.e('label')\">{{ copied ? copiedLabel : label }}</span>\n <span :class=\"ns.e('status')\" role=\"status\">{{ copied ? copiedLabel : '' }}</span>\n </button>\n </DouTooltip>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAaA,MAAM,QAAQ;EAQd,MAAM,OAAO;EAEb,MAAM,KAAK,aAAa,aAAa;EAGrC,MAAM,OAAO,eAAkC,MAAM;EACrD,MAAM,cAAc,qBAAqB,KAAK,KAAK;EACnD,MAAM,WAAW,eAAe,MAAM,YAAY,YAAY,SAAS,CAAC;EACxE,MAAM,EAAE,MAAM,UAAU;EAExB,MAAM,YAAY,aAAa,EAAE,gBAAgB,MAAM,SAAS,CAAC;EACjE,MAAM,SAAS,UAAU;EAEzB,eAAe,OAAO;GACpB,IAAI,SAAS,OAAO;GACpB,IAAI;IACF,MAAM,OAAO,OAAO,MAAM,SAAS,aAAa,MAAM,MAAM,KAAK,IAAI,MAAM;IAC3E,MAAM,UAAU,KAAK,IAAI;IACzB,KAAK,QAAQ,IAAI;GACnB,SAAS,OAAO;IAC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MAAA,KAAK,GAAA,CAAA,K;KAC7EE,mBAAkF,QAAA;MAA3E,OAAKE,eAAEJ,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;MAAY,MAAK;KAAY,GAAAM,gBAAAN,MAAA,MAAA,IAAS,YAAA,QAAW,EAAA,GAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown-sub.js","names":["_sfc_main"],"sources":["../../../src/components/dropdown/dropdown-sub.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronRightIcon } from '@dou-ui/icons'\nimport { computed, inject, nextTick, ref, useId, watch } from 'vue'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport { hasHover } from '../../utils/pointer'\nimport { dropdownKey } from './dropdown'\nimport type { DropdownSubProps, DropdownSubSlots } from './dropdown'\nimport { menuItems, useMenuKeys } from './menu-keys'\n\ndefineOptions({ name: 'DouDropdownSub', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<DropdownSubProps>(), {\n disabled: false,\n divided: false,\n placement: 'right-start',\n})\nconst slots = defineSlots<DropdownSubSlots>()\n\nconst ns = useNamespace('dropdown')\nconst id = `dou-dropdown-sub-${useId()}`\nconst dropdown = inject(dropdownKey, null)\n\nconst open = ref(false)\nconst popup = usePopup({\n open,\n trigger: 'manual',\n disabled: () => props.disabled,\n placement: () => props.placement,\n // Sits just over the edge of the parent menu, level with the item.\n offset: 2,\n closeOnOutside: true,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle } = popup\nconst item = () => popup.reference() as HTMLElement | null\n\n// It closes with the menu it belongs to.\nwatch(\n () => dropdown?.opened() ?? true,\n (opened) => !opened && popup.hide(),\n)\n\nasync function openAndFocus() {\n popup.show()\n await nextTick()\n menuItems(panelRef.value)[0]?.focus()\n}\n\n/** Close and put focus back on the item that opened it. */\nfunction back() {\n popup.hide()\n item()?.focus()\n}\n\n// The pointer opens it after a short rest on the item, and leaving both\n// the item and the submenu closes it. A finger or a pen has no hover: a tap opens\n// it, and the finger lifting is not leaving.\nfunction onEnter(event: PointerEvent) {\n if (props.disabled || !hasHover(event.pointerType)) return\n popup.show(100)\n}\nfunction onLeave(event: PointerEvent) {\n if (hasHover(event.pointerType)) popup.hide(150)\n}\n\nfunction onPointermove(event: PointerEvent) {\n const el = event.currentTarget as HTMLElement\n if (!props.disabled && document.activeElement !== el) el.focus({ preventScroll: true })\n}\n\nfunction onItemKeydown(event: KeyboardEvent) {\n if (props.disabled || event.key !== 'ArrowRight') return\n event.preventDefault()\n event.stopPropagation()\n void openAndFocus()\n}\n\nfunction onClick(event: MouseEvent) {\n if (props.disabled) return\n // Enter and Space reach here as a click with `detail` 0.\n if (event.detail === 0) void openAndFocus()\n else popup.show()\n}\n\nconst onMenuKeydown = useMenuKeys(\n () => panelRef.value,\n () => popup.hide(),\n)\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key === 'ArrowLeft') {\n event.preventDefault()\n event.stopPropagation()\n return back()\n }\n if (event.key === 'ArrowRight' && dropdown?.move) {\n event.preventDefault()\n return dropdown.move(1)\n }\n onMenuKeydown(event)\n}\n\nfunction onPanelEnter(event: PointerEvent) {\n if (!hasHover(event.pointerType)) return\n popup.show()\n dropdown?.hold()\n}\nfunction onPanelLeave(event: PointerEvent) {\n if (!hasHover(event.pointerType)) return\n onLeave(event)\n dropdown?.release()\n}\n\nconst classes = computed(() => [\n ns.e('item'),\n ns.e('sub'),\n ns.is('disabled', props.disabled),\n ns.is('open', open.value),\n])\n</script>\n\n<template>\n <div v-if=\"divided\" role=\"separator\" :class=\"ns.e('separator')\" />\n <OnlyChild ref=\"triggerRef\">\n <div\n v-bind=\"$attrs\"\n role=\"menuitem\"\n tabindex=\"-1\"\n aria-haspopup=\"menu\"\n :aria-expanded=\"open\"\n :aria-controls=\"rendered ? id : undefined\"\n :aria-disabled=\"disabled || undefined\"\n :class=\"classes\"\n @click=\"onClick\"\n @keydown=\"onItemKeydown\"\n @pointermove=\"onPointermove\"\n @pointerenter=\"onEnter\"\n @pointerleave=\"onLeave\"\n >\n <span v-if=\"slots.prefix\" :class=\"ns.e('prefix')\"><slot name=\"prefix\" /></span>\n <span :class=\"ns.e('label')\"\n ><slot name=\"title\">{{ title }}</slot></span\n >\n <span :class=\"[ns.e('suffix'), ns.e('arrow')]\" aria-hidden=\"true\"><ChevronRightIcon /></span>\n </div>\n </OnlyChild>\n <Teleport v-if=\"rendered\" to=\"
|
|
1
|
+
{"version":3,"file":"dropdown-sub.js","names":["_sfc_main"],"sources":["../../../src/components/dropdown/dropdown-sub.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronRightIcon } from '@dou-ui/icons'\nimport { computed, inject, nextTick, ref, useId, watch } from 'vue'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport { hasHover } from '../../utils/pointer'\nimport { dropdownKey } from './dropdown'\nimport type { DropdownSubProps, DropdownSubSlots } from './dropdown'\nimport { menuItems, useMenuKeys } from './menu-keys'\n\ndefineOptions({ name: 'DouDropdownSub', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<DropdownSubProps>(), {\n disabled: false,\n divided: false,\n placement: 'right-start',\n})\nconst slots = defineSlots<DropdownSubSlots>()\n\nconst ns = useNamespace('dropdown')\nconst id = `dou-dropdown-sub-${useId()}`\nconst dropdown = inject(dropdownKey, null)\n\nconst open = ref(false)\nconst popup = usePopup({\n open,\n trigger: 'manual',\n disabled: () => props.disabled,\n placement: () => props.placement,\n // Sits just over the edge of the parent menu, level with the item.\n offset: 2,\n closeOnOutside: true,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle } = popup\n\n// It renders where the menu does; a menu kept in place still puts it under body,\n// so it is not clipped by the menu's own scrolling.\nconst teleportTo = computed(() => {\n const target = dropdown?.teleport?.()\n return target && !target.disabled ? target.to : 'body'\n})\nconst item = () => popup.reference() as HTMLElement | null\n\n// It closes with the menu it belongs to.\nwatch(\n () => dropdown?.opened() ?? true,\n (opened) => !opened && popup.hide(),\n)\n\nasync function openAndFocus() {\n popup.show()\n await nextTick()\n menuItems(panelRef.value)[0]?.focus()\n}\n\n/** Close and put focus back on the item that opened it. */\nfunction back() {\n popup.hide()\n item()?.focus()\n}\n\n// The pointer opens it after a short rest on the item, and leaving both\n// the item and the submenu closes it. A finger or a pen has no hover: a tap opens\n// it, and the finger lifting is not leaving.\nfunction onEnter(event: PointerEvent) {\n if (props.disabled || !hasHover(event.pointerType)) return\n popup.show(100)\n}\nfunction onLeave(event: PointerEvent) {\n if (hasHover(event.pointerType)) popup.hide(150)\n}\n\nfunction onPointermove(event: PointerEvent) {\n const el = event.currentTarget as HTMLElement\n if (!props.disabled && document.activeElement !== el) el.focus({ preventScroll: true })\n}\n\nfunction onItemKeydown(event: KeyboardEvent) {\n if (props.disabled || event.key !== 'ArrowRight') return\n event.preventDefault()\n event.stopPropagation()\n void openAndFocus()\n}\n\nfunction onClick(event: MouseEvent) {\n if (props.disabled) return\n // Enter and Space reach here as a click with `detail` 0.\n if (event.detail === 0) void openAndFocus()\n else popup.show()\n}\n\nconst onMenuKeydown = useMenuKeys(\n () => panelRef.value,\n () => popup.hide(),\n)\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key === 'ArrowLeft') {\n event.preventDefault()\n event.stopPropagation()\n return back()\n }\n if (event.key === 'ArrowRight' && dropdown?.move) {\n event.preventDefault()\n return dropdown.move(1)\n }\n onMenuKeydown(event)\n}\n\nfunction onPanelEnter(event: PointerEvent) {\n if (!hasHover(event.pointerType)) return\n popup.show()\n dropdown?.hold()\n}\nfunction onPanelLeave(event: PointerEvent) {\n if (!hasHover(event.pointerType)) return\n onLeave(event)\n dropdown?.release()\n}\n\nconst classes = computed(() => [\n ns.e('item'),\n ns.e('sub'),\n ns.is('disabled', props.disabled),\n ns.is('open', open.value),\n])\n</script>\n\n<template>\n <div v-if=\"divided\" role=\"separator\" :class=\"ns.e('separator')\" />\n <OnlyChild ref=\"triggerRef\">\n <div\n v-bind=\"$attrs\"\n role=\"menuitem\"\n tabindex=\"-1\"\n aria-haspopup=\"menu\"\n :aria-expanded=\"open\"\n :aria-controls=\"rendered ? id : undefined\"\n :aria-disabled=\"disabled || undefined\"\n :class=\"classes\"\n @click=\"onClick\"\n @keydown=\"onItemKeydown\"\n @pointermove=\"onPointermove\"\n @pointerenter=\"onEnter\"\n @pointerleave=\"onLeave\"\n >\n <span v-if=\"slots.prefix\" :class=\"ns.e('prefix')\"><slot name=\"prefix\" /></span>\n <span :class=\"ns.e('label')\"\n ><slot name=\"title\">{{ title }}</slot></span\n >\n <span :class=\"[ns.e('suffix'), ns.e('arrow')]\" aria-hidden=\"true\"><ChevronRightIcon /></span>\n </div>\n </OnlyChild>\n <Teleport v-if=\"rendered\" :to=\"teleportTo\">\n <Transition appear name=\"dou-floating\">\n <div\n v-show=\"open\"\n :id=\"id\"\n ref=\"panelRef\"\n role=\"menu\"\n tabindex=\"-1\"\n :class=\"[ns.b(), ns.m('sub'), 'dou-floating', dropdown?.panelClass?.()]\"\n :style=\"panelStyle\"\n :data-placement=\"placement\"\n :data-dou-theme=\"theme\"\n @keydown=\"onPanelKeydown\"\n @pointerenter=\"onPanelEnter\"\n @pointerleave=\"onPanelLeave\"\n >\n <slot />\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":""}
|
|
@@ -45,6 +45,10 @@ var dropdown_sub_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
45
45
|
closeOnOutside: true
|
|
46
46
|
});
|
|
47
47
|
const { triggerRef, panelRef, rendered, theme, placement, panelStyle } = popup;
|
|
48
|
+
const teleportTo = computed(() => {
|
|
49
|
+
const target = dropdown?.teleport?.();
|
|
50
|
+
return target && !target.disabled ? target.to : "body";
|
|
51
|
+
});
|
|
48
52
|
const item = () => popup.reference();
|
|
49
53
|
watch(() => dropdown?.opened() ?? true, (opened) => !opened && popup.hide());
|
|
50
54
|
async function openAndFocus() {
|
|
@@ -147,7 +151,7 @@ var dropdown_sub_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
147
151
|
}, 512),
|
|
148
152
|
unref(rendered) ? (openBlock(), createBlock(Teleport, {
|
|
149
153
|
key: 1,
|
|
150
|
-
to:
|
|
154
|
+
to: teleportTo.value
|
|
151
155
|
}, [createVNode(Transition, {
|
|
152
156
|
appear: "",
|
|
153
157
|
name: "dou-floating",
|
|
@@ -162,7 +166,8 @@ var dropdown_sub_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
162
166
|
class: normalizeClass([
|
|
163
167
|
unref(ns).b(),
|
|
164
168
|
unref(ns).m("sub"),
|
|
165
|
-
"dou-floating"
|
|
169
|
+
"dou-floating",
|
|
170
|
+
unref(dropdown)?.panelClass?.()
|
|
166
171
|
]),
|
|
167
172
|
style: normalizeStyle(unref(panelStyle)),
|
|
168
173
|
"data-placement": unref(placement),
|
|
@@ -172,7 +177,7 @@ var dropdown_sub_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
|
|
|
172
177
|
onPointerleave: onPanelLeave
|
|
173
178
|
}, [renderSlot(_ctx.$slots, "default")], 46, _hoisted_2), [[vShow, open.value]])]),
|
|
174
179
|
_: 3
|
|
175
|
-
})])) : createCommentVNode("", true)
|
|
180
|
+
})], 8, ["to"])) : createCommentVNode("", true)
|
|
176
181
|
], 64);
|
|
177
182
|
};
|
|
178
183
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown-sub.vue_vue_type_script_setup_true_lang.js","names":["$attrs","_useSlots","_openBlock","_createElementBlock","_Fragment","_normalizeClass","_unref","_createCommentVNode","_createVNode","_withCtx","_createElementVNode","_mergeProps","_renderSlot","_createTextVNode","_toDisplayString","_createBlock","_Teleport","_Transition","_withDirectives","_normalizeStyle","_vShow"],"sources":["../../../src/components/dropdown/dropdown-sub.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronRightIcon } from '@dou-ui/icons'\nimport { computed, inject, nextTick, ref, useId, watch } from 'vue'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport { hasHover } from '../../utils/pointer'\nimport { dropdownKey } from './dropdown'\nimport type { DropdownSubProps, DropdownSubSlots } from './dropdown'\nimport { menuItems, useMenuKeys } from './menu-keys'\n\ndefineOptions({ name: 'DouDropdownSub', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<DropdownSubProps>(), {\n disabled: false,\n divided: false,\n placement: 'right-start',\n})\nconst slots = defineSlots<DropdownSubSlots>()\n\nconst ns = useNamespace('dropdown')\nconst id = `dou-dropdown-sub-${useId()}`\nconst dropdown = inject(dropdownKey, null)\n\nconst open = ref(false)\nconst popup = usePopup({\n open,\n trigger: 'manual',\n disabled: () => props.disabled,\n placement: () => props.placement,\n // Sits just over the edge of the parent menu, level with the item.\n offset: 2,\n closeOnOutside: true,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle } = popup\nconst item = () => popup.reference() as HTMLElement | null\n\n// It closes with the menu it belongs to.\nwatch(\n () => dropdown?.opened() ?? true,\n (opened) => !opened && popup.hide(),\n)\n\nasync function openAndFocus() {\n popup.show()\n await nextTick()\n menuItems(panelRef.value)[0]?.focus()\n}\n\n/** Close and put focus back on the item that opened it. */\nfunction back() {\n popup.hide()\n item()?.focus()\n}\n\n// The pointer opens it after a short rest on the item, and leaving both\n// the item and the submenu closes it. A finger or a pen has no hover: a tap opens\n// it, and the finger lifting is not leaving.\nfunction onEnter(event: PointerEvent) {\n if (props.disabled || !hasHover(event.pointerType)) return\n popup.show(100)\n}\nfunction onLeave(event: PointerEvent) {\n if (hasHover(event.pointerType)) popup.hide(150)\n}\n\nfunction onPointermove(event: PointerEvent) {\n const el = event.currentTarget as HTMLElement\n if (!props.disabled && document.activeElement !== el) el.focus({ preventScroll: true })\n}\n\nfunction onItemKeydown(event: KeyboardEvent) {\n if (props.disabled || event.key !== 'ArrowRight') return\n event.preventDefault()\n event.stopPropagation()\n void openAndFocus()\n}\n\nfunction onClick(event: MouseEvent) {\n if (props.disabled) return\n // Enter and Space reach here as a click with `detail` 0.\n if (event.detail === 0) void openAndFocus()\n else popup.show()\n}\n\nconst onMenuKeydown = useMenuKeys(\n () => panelRef.value,\n () => popup.hide(),\n)\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key === 'ArrowLeft') {\n event.preventDefault()\n event.stopPropagation()\n return back()\n }\n if (event.key === 'ArrowRight' && dropdown?.move) {\n event.preventDefault()\n return dropdown.move(1)\n }\n onMenuKeydown(event)\n}\n\nfunction onPanelEnter(event: PointerEvent) {\n if (!hasHover(event.pointerType)) return\n popup.show()\n dropdown?.hold()\n}\nfunction onPanelLeave(event: PointerEvent) {\n if (!hasHover(event.pointerType)) return\n onLeave(event)\n dropdown?.release()\n}\n\nconst classes = computed(() => [\n ns.e('item'),\n ns.e('sub'),\n ns.is('disabled', props.disabled),\n ns.is('open', open.value),\n])\n</script>\n\n<template>\n <div v-if=\"divided\" role=\"separator\" :class=\"ns.e('separator')\" />\n <OnlyChild ref=\"triggerRef\">\n <div\n v-bind=\"$attrs\"\n role=\"menuitem\"\n tabindex=\"-1\"\n aria-haspopup=\"menu\"\n :aria-expanded=\"open\"\n :aria-controls=\"rendered ? id : undefined\"\n :aria-disabled=\"disabled || undefined\"\n :class=\"classes\"\n @click=\"onClick\"\n @keydown=\"onItemKeydown\"\n @pointermove=\"onPointermove\"\n @pointerenter=\"onEnter\"\n @pointerleave=\"onLeave\"\n >\n <span v-if=\"slots.prefix\" :class=\"ns.e('prefix')\"><slot name=\"prefix\" /></span>\n <span :class=\"ns.e('label')\"\n ><slot name=\"title\">{{ title }}</slot></span\n >\n <span :class=\"[ns.e('suffix'), ns.e('arrow')]\" aria-hidden=\"true\"><ChevronRightIcon /></span>\n </div>\n </OnlyChild>\n <Teleport v-if=\"rendered\" to=\"
|
|
1
|
+
{"version":3,"file":"dropdown-sub.vue_vue_type_script_setup_true_lang.js","names":["$attrs","_useSlots","_openBlock","_createElementBlock","_Fragment","_normalizeClass","_unref","_createCommentVNode","_createVNode","_withCtx","_createElementVNode","_mergeProps","_renderSlot","_createTextVNode","_toDisplayString","_createBlock","_Teleport","_Transition","_withDirectives","_normalizeStyle","_vShow"],"sources":["../../../src/components/dropdown/dropdown-sub.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ChevronRightIcon } from '@dou-ui/icons'\nimport { computed, inject, nextTick, ref, useId, watch } from 'vue'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport { hasHover } from '../../utils/pointer'\nimport { dropdownKey } from './dropdown'\nimport type { DropdownSubProps, DropdownSubSlots } from './dropdown'\nimport { menuItems, useMenuKeys } from './menu-keys'\n\ndefineOptions({ name: 'DouDropdownSub', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<DropdownSubProps>(), {\n disabled: false,\n divided: false,\n placement: 'right-start',\n})\nconst slots = defineSlots<DropdownSubSlots>()\n\nconst ns = useNamespace('dropdown')\nconst id = `dou-dropdown-sub-${useId()}`\nconst dropdown = inject(dropdownKey, null)\n\nconst open = ref(false)\nconst popup = usePopup({\n open,\n trigger: 'manual',\n disabled: () => props.disabled,\n placement: () => props.placement,\n // Sits just over the edge of the parent menu, level with the item.\n offset: 2,\n closeOnOutside: true,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle } = popup\n\n// It renders where the menu does; a menu kept in place still puts it under body,\n// so it is not clipped by the menu's own scrolling.\nconst teleportTo = computed(() => {\n const target = dropdown?.teleport?.()\n return target && !target.disabled ? target.to : 'body'\n})\nconst item = () => popup.reference() as HTMLElement | null\n\n// It closes with the menu it belongs to.\nwatch(\n () => dropdown?.opened() ?? true,\n (opened) => !opened && popup.hide(),\n)\n\nasync function openAndFocus() {\n popup.show()\n await nextTick()\n menuItems(panelRef.value)[0]?.focus()\n}\n\n/** Close and put focus back on the item that opened it. */\nfunction back() {\n popup.hide()\n item()?.focus()\n}\n\n// The pointer opens it after a short rest on the item, and leaving both\n// the item and the submenu closes it. A finger or a pen has no hover: a tap opens\n// it, and the finger lifting is not leaving.\nfunction onEnter(event: PointerEvent) {\n if (props.disabled || !hasHover(event.pointerType)) return\n popup.show(100)\n}\nfunction onLeave(event: PointerEvent) {\n if (hasHover(event.pointerType)) popup.hide(150)\n}\n\nfunction onPointermove(event: PointerEvent) {\n const el = event.currentTarget as HTMLElement\n if (!props.disabled && document.activeElement !== el) el.focus({ preventScroll: true })\n}\n\nfunction onItemKeydown(event: KeyboardEvent) {\n if (props.disabled || event.key !== 'ArrowRight') return\n event.preventDefault()\n event.stopPropagation()\n void openAndFocus()\n}\n\nfunction onClick(event: MouseEvent) {\n if (props.disabled) return\n // Enter and Space reach here as a click with `detail` 0.\n if (event.detail === 0) void openAndFocus()\n else popup.show()\n}\n\nconst onMenuKeydown = useMenuKeys(\n () => panelRef.value,\n () => popup.hide(),\n)\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key === 'ArrowLeft') {\n event.preventDefault()\n event.stopPropagation()\n return back()\n }\n if (event.key === 'ArrowRight' && dropdown?.move) {\n event.preventDefault()\n return dropdown.move(1)\n }\n onMenuKeydown(event)\n}\n\nfunction onPanelEnter(event: PointerEvent) {\n if (!hasHover(event.pointerType)) return\n popup.show()\n dropdown?.hold()\n}\nfunction onPanelLeave(event: PointerEvent) {\n if (!hasHover(event.pointerType)) return\n onLeave(event)\n dropdown?.release()\n}\n\nconst classes = computed(() => [\n ns.e('item'),\n ns.e('sub'),\n ns.is('disabled', props.disabled),\n ns.is('open', open.value),\n])\n</script>\n\n<template>\n <div v-if=\"divided\" role=\"separator\" :class=\"ns.e('separator')\" />\n <OnlyChild ref=\"triggerRef\">\n <div\n v-bind=\"$attrs\"\n role=\"menuitem\"\n tabindex=\"-1\"\n aria-haspopup=\"menu\"\n :aria-expanded=\"open\"\n :aria-controls=\"rendered ? id : undefined\"\n :aria-disabled=\"disabled || undefined\"\n :class=\"classes\"\n @click=\"onClick\"\n @keydown=\"onItemKeydown\"\n @pointermove=\"onPointermove\"\n @pointerenter=\"onEnter\"\n @pointerleave=\"onLeave\"\n >\n <span v-if=\"slots.prefix\" :class=\"ns.e('prefix')\"><slot name=\"prefix\" /></span>\n <span :class=\"ns.e('label')\"\n ><slot name=\"title\">{{ title }}</slot></span\n >\n <span :class=\"[ns.e('suffix'), ns.e('arrow')]\" aria-hidden=\"true\"><ChevronRightIcon /></span>\n </div>\n </OnlyChild>\n <Teleport v-if=\"rendered\" :to=\"teleportTo\">\n <Transition appear name=\"dou-floating\">\n <div\n v-show=\"open\"\n :id=\"id\"\n ref=\"panelRef\"\n role=\"menu\"\n tabindex=\"-1\"\n :class=\"[ns.b(), ns.m('sub'), 'dou-floating', dropdown?.panelClass?.()]\"\n :style=\"panelStyle\"\n :data-placement=\"placement\"\n :data-dou-theme=\"theme\"\n @keydown=\"onPanelKeydown\"\n @pointerenter=\"onPanelEnter\"\n @pointerleave=\"onPanelLeave\"\n >\n <slot />\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAaA,MAAM,QAAQ;EAKd,MAAM,QAAQC,SAAA;EAEd,MAAM,KAAK,aAAa,UAAU;EAClC,MAAM,KAAK,oBAAoB,MAAM;EACrC,MAAM,WAAW,OAAO,aAAa,IAAI;EAEzC,MAAM,OAAO,IAAI,KAAK;EACtB,MAAM,QAAQ,SAAS;GACrB;GACA,SAAS;GACT,gBAAgB,MAAM;GACtB,iBAAiB,MAAM;GAEvB,QAAQ;GACR,gBAAgB;EAClB,CAAC;EACD,MAAM,EAAE,YAAY,UAAU,UAAU,OAAO,WAAW,eAAe;EAIzE,MAAM,aAAa,eAAe;GAChC,MAAM,SAAS,UAAU,WAAW;GACpC,OAAO,UAAU,CAAC,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AAC,EAAC,OAAA,CAAA,CAAA;OAAY,eAAY;M,IAAOE,YAAoBF,MAAA,gBAAA,CAAA,C;;;;IAG1EA,MAAA,QAAA,KAAhBJ,UAAA,GAAAa,YAmBWC,UAAA;;KAnBgB,IAAI,WAAA;I,IAC7BR,YAiBaS,YAAA;KAjBD,QAAA;KAAO,MAAK;KAAxB,WAAA;;KACE,SAAAR,cAeM,CAfNS,eAAAR,mBAeM,OAAA;MAbC;MACD,SAAA;MAAJ,KAAI;MACJ,MAAK;MACL,UAAS;MACR,OAAKL,eAAA;OAAGC,MAAA,EAAA,CAAE,CAAC,EAAC;OAAIA,MAAA,EAAA,CAAE,CAAC,EAAC,KAAA;OAAA;OAAyBA,MAAA,QAAA,CAAQ,EAAE,aAAU;MAAA,CAAA;MACjE,OAAKa,eAAEb,MAAA,UAAA,CAAU;MACjB,kBAAgBA,MAAA,SAAA;MAChB,kBAAgBA,MAAA,KAAA;MAChB,WAAS;MACT,gBAAc;MACd,gBAAc;K,IAEfM,WAAQ,KAAA,QAAA,SAAA,C,qBAbA,CAAAQ,OAAA,KAAA,KAAI,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown.js","names":[],"sources":["../../../src/components/dropdown/dropdown.ts"],"sourcesContent":["import type { InjectionKey } from 'vue'\nimport type { Placement } from '../../composables/use-floating'\nimport type { Size, Tone } from '../../utils/types'\nimport type { ContextMenuEntry } from '../context-menu/context-menu'\n\nexport type DropdownPlacement = Placement\nexport type DropdownTrigger = 'click' | 'hover' | 'manual'\nexport type DropdownValue = string | number\n\nexport interface DropdownProps {\n /** Whether the menu is open, bound with `v-model:open`. */\n open?: boolean\n /** The preferred side, flipped when there is no room. */\n placement?: DropdownPlacement\n /** What opens the menu. Arrow keys on the trigger always do. */\n trigger?: DropdownTrigger\n disabled?: boolean\n /** Close the menu once an item is chosen. */\n hideOnSelect?: boolean\n /** Make the menu at least as wide as the trigger. */\n sameWidth?: boolean\n /** Delay before opening on hover, in ms. */\n showDelay?: number\n /** Delay before closing once the pointer leaves, in ms. */\n hideDelay?: number\n /** The gap to the trigger, in px. */\n offset?: number\n /** Where to render the menu; `false` keeps it in place. */\n teleport?: string | HTMLElement | false\n /**\n * The items as data, in place of the `menu` slot; a chosen item's `run`\n * is called. Ignored when the `menu` slot is given.\n */\n items?: ContextMenuEntry[]\n}\n\nexport interface DropdownEmits {\n 'update:open': [open: boolean]\n /** An item was chosen. */\n select: [value: DropdownValue | undefined]\n}\n\nexport interface DropdownSlots {\n /** The trigger. Its first element receives the listeners and ARIA attributes. */\n default?: () => unknown\n /** The items: `DouDropdownItem`, `DouDropdownSub`, `DouDropdownGroup` and `DouDropdownRadioGroup`. */\n menu?: () => unknown\n}\n\nexport interface DropdownExpose {\n open: () => void\n close: () => void\n}\n\nexport type DropdownItemTone = 'neutral' | 'danger'\n\nexport interface DropdownItemProps {\n /** Passed to the menu's `select` event. */\n value?: DropdownValue\n disabled?: boolean\n /** `danger` for destructive actions. */\n tone?: DropdownItemTone\n /** Draw a separator above the item. */\n divided?: boolean\n /**\n * Make the item a checkbox: it shows a check while `true` and toggles\n * on click. Bound with `v-model:checked`.\n */\n checked?: boolean\n /**\n * A keyboard shortcut to show after the label, e.g. `mod+s`, written as\n * in `useHotkey` and shown the way the platform writes it. It is only\n * shown: bind the key yourself.\n */\n shortcut?: string\n /**\n * A line under the label that says more about the item; the `description`\n * slot replaces it. Screen readers read it after the label, and typing\n * still jumps by the label.\n */\n description?: string\n}\n\nexport interface DropdownItemEmits {\n click: [event: MouseEvent | KeyboardEvent]\n 'update:checked': [checked: boolean]\n}\n\nexport interface DropdownItemSlots {\n default?: () => unknown\n /** Before the label, usually an icon. */\n prefix?: () => unknown\n /** After the label, e.g. a shortcut. */\n suffix?: () => unknown\n /** The line under the label, in place of `description`. */\n description?: () => unknown\n}\n\nexport interface DropdownGroupProps {\n /** The heading above the items; the `label` slot replaces it. */\n label?: string\n /** Draw a separator above the group. */\n divided?: boolean\n}\n\nexport interface DropdownGroupSlots {\n /** The group's items. */\n default?: () => unknown\n /** The heading, in place of `label`. */\n label?: () => unknown\n}\n\nexport interface DropdownRadioGroupProps extends DropdownGroupProps {\n /** The value of the chosen item, bound with `v-model`. */\n modelValue?: DropdownValue\n}\n\nexport interface DropdownRadioGroupEmits {\n 'update:modelValue': [value: DropdownValue]\n}\n\nexport interface DropdownRadioGroupSlots {\n /** `DouDropdownItem`s with a `value`; the one matching `v-model` shows a dot. */\n default?: () => unknown\n /** The heading, in place of `label`. */\n label?: () => unknown\n}\n\nexport interface DropdownRadioGroupContext {\n value: () => DropdownValue | undefined\n pick: (value: DropdownValue) => void\n}\n\nexport const dropdownRadioGroupKey: InjectionKey<DropdownRadioGroupContext> =\n Symbol('DouDropdownRadioGroup')\n\nexport interface DropdownSubProps {\n /** The item's text; the `title` slot replaces it. */\n title?: string\n disabled?: boolean\n /** Draw a separator above the item. */\n divided?: boolean\n /** The preferred side of the submenu, flipped when there is no room. */\n placement?: DropdownPlacement\n}\n\nexport interface DropdownSubSlots {\n /** The submenu's items: `DouDropdownItem`, `DouDropdownSub`, `DouDropdownGroup` and `DouDropdownRadioGroup`. */\n default?: () => unknown\n /** The item's text. */\n title?: () => unknown\n /** Before the text, usually an icon. */\n prefix?: () => unknown\n}\n\nexport type DropdownButtonVariant = 'solid' | 'soft' | 'outline'\n\nexport interface DropdownButtonProps {\n variant?: DropdownButtonVariant\n tone?: Tone\n size?: Size\n /** Disable both halves. */\n disabled?: boolean\n /** Show a spinner on the main half and block it. */\n loading?: boolean\n /** The preferred side of the menu. */\n placement?: DropdownPlacement\n /** What opens the menu from the arrow half. */\n trigger?: Exclude<DropdownTrigger, 'manual'>\n /** Close the menu once an item is chosen. */\n hideOnSelect?: boolean\n}\n\nexport interface DropdownButtonEmits {\n /** The main half was clicked. */\n click: [event: MouseEvent]\n /** An item of the menu was chosen. */\n select: [value: DropdownValue | undefined]\n}\n\nexport interface DropdownButtonSlots {\n /** The main action's label. */\n default?: () => unknown\n /** Before the label, usually an icon. */\n leading?: () => unknown\n /** The items: `DouDropdownItem`, `DouDropdownSub`, `DouDropdownGroup` and `DouDropdownRadioGroup`. */\n menu?: () => unknown\n}\n\nexport interface DropdownContext {\n select: (value: DropdownValue | undefined) => void\n /** Whether the whole menu is open; submenus close with it. */\n opened: () => boolean\n /** The pointer entered or left a submenu, which keeps a hover menu open. */\n hold: () => void\n release: () => void\n /** Left or right out of the menu, when something such as a menubar handles that. */\n move?: (direction: 1 | -1) => void\n}\n\nexport const dropdownKey: InjectionKey<DropdownContext> = Symbol('DouDropdown')\n\n/**\n * Provided by a component that owns dropdowns side by side, such as a\n * menubar: `ArrowLeft` and `ArrowRight` inside a menu go to it.\n */\nexport interface DropdownHost {\n move: (direction: 1 | -1) => void\n}\n\nexport const dropdownHostKey: InjectionKey<DropdownHost> = Symbol('DouDropdownHost')\n"],"mappings":";AAqIA,IAAa,wBACX,OAAO,uBAAuB;
|
|
1
|
+
{"version":3,"file":"dropdown.js","names":[],"sources":["../../../src/components/dropdown/dropdown.ts"],"sourcesContent":["import type { InjectionKey } from 'vue'\nimport type { Placement } from '../../composables/use-floating'\nimport type { Size, Tone } from '../../utils/types'\nimport type { ContextMenuEntry } from '../context-menu/context-menu'\n\nexport type DropdownPlacement = Placement\nexport type DropdownTrigger = 'click' | 'hover' | 'manual'\nexport type DropdownValue = string | number\n\nexport interface DropdownProps {\n /** Whether the menu is open, bound with `v-model:open`. */\n open?: boolean\n /** The preferred side, flipped when there is no room. */\n placement?: DropdownPlacement\n /** What opens the menu. Arrow keys on the trigger always do. */\n trigger?: DropdownTrigger\n disabled?: boolean\n /** Close the menu once an item is chosen. */\n hideOnSelect?: boolean\n /** Make the menu at least as wide as the trigger. */\n sameWidth?: boolean\n /** Delay before opening on hover, in ms. */\n showDelay?: number\n /** Delay before closing once the pointer leaves, in ms. */\n hideDelay?: number\n /** The gap to the trigger, in px. */\n offset?: number\n /** Where to render the menu; `false` keeps it in place. */\n teleport?: string | HTMLElement | false\n /**\n * The items as data, in place of the `menu` slot; a chosen item's `run`\n * is called. Ignored when the `menu` slot is given.\n */\n items?: ContextMenuEntry[]\n}\n\nexport interface DropdownEmits {\n 'update:open': [open: boolean]\n /** An item was chosen. */\n select: [value: DropdownValue | undefined]\n}\n\nexport interface DropdownSlots {\n /** The trigger. Its first element receives the listeners and ARIA attributes. */\n default?: () => unknown\n /** The items: `DouDropdownItem`, `DouDropdownSub`, `DouDropdownGroup` and `DouDropdownRadioGroup`. */\n menu?: () => unknown\n}\n\nexport interface DropdownExpose {\n open: () => void\n close: () => void\n}\n\nexport type DropdownItemTone = 'neutral' | 'danger'\n\nexport interface DropdownItemProps {\n /** Passed to the menu's `select` event. */\n value?: DropdownValue\n disabled?: boolean\n /** `danger` for destructive actions. */\n tone?: DropdownItemTone\n /** Draw a separator above the item. */\n divided?: boolean\n /**\n * Make the item a checkbox: it shows a check while `true` and toggles\n * on click. Bound with `v-model:checked`.\n */\n checked?: boolean\n /**\n * A keyboard shortcut to show after the label, e.g. `mod+s`, written as\n * in `useHotkey` and shown the way the platform writes it. It is only\n * shown: bind the key yourself.\n */\n shortcut?: string\n /**\n * A line under the label that says more about the item; the `description`\n * slot replaces it. Screen readers read it after the label, and typing\n * still jumps by the label.\n */\n description?: string\n}\n\nexport interface DropdownItemEmits {\n click: [event: MouseEvent | KeyboardEvent]\n 'update:checked': [checked: boolean]\n}\n\nexport interface DropdownItemSlots {\n default?: () => unknown\n /** Before the label, usually an icon. */\n prefix?: () => unknown\n /** After the label, e.g. a shortcut. */\n suffix?: () => unknown\n /** The line under the label, in place of `description`. */\n description?: () => unknown\n}\n\nexport interface DropdownGroupProps {\n /** The heading above the items; the `label` slot replaces it. */\n label?: string\n /** Draw a separator above the group. */\n divided?: boolean\n}\n\nexport interface DropdownGroupSlots {\n /** The group's items. */\n default?: () => unknown\n /** The heading, in place of `label`. */\n label?: () => unknown\n}\n\nexport interface DropdownRadioGroupProps extends DropdownGroupProps {\n /** The value of the chosen item, bound with `v-model`. */\n modelValue?: DropdownValue\n}\n\nexport interface DropdownRadioGroupEmits {\n 'update:modelValue': [value: DropdownValue]\n}\n\nexport interface DropdownRadioGroupSlots {\n /** `DouDropdownItem`s with a `value`; the one matching `v-model` shows a dot. */\n default?: () => unknown\n /** The heading, in place of `label`. */\n label?: () => unknown\n}\n\nexport interface DropdownRadioGroupContext {\n value: () => DropdownValue | undefined\n pick: (value: DropdownValue) => void\n}\n\nexport const dropdownRadioGroupKey: InjectionKey<DropdownRadioGroupContext> =\n Symbol('DouDropdownRadioGroup')\n\nexport interface DropdownSubProps {\n /** The item's text; the `title` slot replaces it. */\n title?: string\n disabled?: boolean\n /** Draw a separator above the item. */\n divided?: boolean\n /** The preferred side of the submenu, flipped when there is no room. */\n placement?: DropdownPlacement\n}\n\nexport interface DropdownSubSlots {\n /** The submenu's items: `DouDropdownItem`, `DouDropdownSub`, `DouDropdownGroup` and `DouDropdownRadioGroup`. */\n default?: () => unknown\n /** The item's text. */\n title?: () => unknown\n /** Before the text, usually an icon. */\n prefix?: () => unknown\n}\n\nexport type DropdownButtonVariant = 'solid' | 'soft' | 'outline'\n\nexport interface DropdownButtonProps {\n variant?: DropdownButtonVariant\n tone?: Tone\n size?: Size\n /** Disable both halves. */\n disabled?: boolean\n /** Show a spinner on the main half and block it. */\n loading?: boolean\n /** The preferred side of the menu. */\n placement?: DropdownPlacement\n /** What opens the menu from the arrow half. */\n trigger?: Exclude<DropdownTrigger, 'manual'>\n /** Close the menu once an item is chosen. */\n hideOnSelect?: boolean\n}\n\nexport interface DropdownButtonEmits {\n /** The main half was clicked. */\n click: [event: MouseEvent]\n /** An item of the menu was chosen. */\n select: [value: DropdownValue | undefined]\n}\n\nexport interface DropdownButtonSlots {\n /** The main action's label. */\n default?: () => unknown\n /** Before the label, usually an icon. */\n leading?: () => unknown\n /** The items: `DouDropdownItem`, `DouDropdownSub`, `DouDropdownGroup` and `DouDropdownRadioGroup`. */\n menu?: () => unknown\n}\n\nexport interface DropdownContext {\n select: (value: DropdownValue | undefined) => void\n /** Whether the whole menu is open; submenus close with it. */\n opened: () => boolean\n /** The pointer entered or left a submenu, which keeps a hover menu open. */\n hold: () => void\n release: () => void\n /** Left or right out of the menu, when something such as a menubar handles that. */\n move?: (direction: 1 | -1) => void\n /** The `class` given to the menu; its submenus carry it too, being put elsewhere. */\n panelClass?: () => unknown\n /** Where the menu renders; its submenus go to the same place. */\n teleport?: () => { to: string | HTMLElement; disabled: boolean }\n}\n\nexport const dropdownKey: InjectionKey<DropdownContext> = Symbol('DouDropdown')\n\n/**\n * Provided by a component that owns dropdowns side by side, such as a\n * menubar: `ArrowLeft` and `ArrowRight` inside a menu go to it.\n */\nexport interface DropdownHost {\n move: (direction: 1 | -1) => void\n}\n\nexport const dropdownHostKey: InjectionKey<DropdownHost> = Symbol('DouDropdownHost')\n"],"mappings":";AAqIA,IAAa,wBACX,OAAO,uBAAuB;AAsEhC,IAAa,cAA6C,OAAO,aAAa;AAU9E,IAAa,kBAA8C,OAAO,iBAAiB"}
|