dou-ui 0.1.0-alpha.13 → 0.1.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/dist/components/button/button.js.map +1 -1
  2. package/dist/components/button/button.vue_vue_type_script_setup_true_lang.js +9 -3
  3. package/dist/components/button/button.vue_vue_type_script_setup_true_lang.js.map +1 -1
  4. package/dist/components/color-panel/style.js +1 -0
  5. package/dist/components/color-picker/style.js +1 -0
  6. package/dist/components/comment-thread/style.js +2 -0
  7. package/dist/components/copy-button/copy-button.js.map +1 -1
  8. package/dist/components/copy-button/copy-button.vue_vue_type_script_setup_true_lang.js +13 -5
  9. package/dist/components/copy-button/copy-button.vue_vue_type_script_setup_true_lang.js.map +1 -1
  10. package/dist/components/dropdown/style.js +2 -0
  11. package/dist/components/field-group/style.js +2 -0
  12. package/dist/components/input/input.js.map +1 -1
  13. package/dist/components/input/input.vue_vue_type_script_setup_true_lang.js +22 -7
  14. package/dist/components/input/input.vue_vue_type_script_setup_true_lang.js.map +1 -1
  15. package/dist/components/input-number/input-number.js.map +1 -1
  16. package/dist/components/input-number/input-number.vue_vue_type_script_setup_true_lang.js +22 -7
  17. package/dist/components/input-number/input-number.vue_vue_type_script_setup_true_lang.js.map +1 -1
  18. package/dist/components/menu/style.js +2 -0
  19. package/dist/components/menubar/style.js +2 -0
  20. package/dist/style.css +1 -1
  21. package/dist/types/utils/field-action.d.ts +59 -0
  22. package/dist/utils/field-action.js +139 -0
  23. package/dist/utils/field-action.js.map +1 -0
  24. 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 disabled = useFormDisabled(() => props.disabled);
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUA,MAAM,QAAQ;EAQd,MAAM,OAAO;EACb,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,QAAQ;EAGhC,MAAM,WAAW,kBAAmB,MAAM,SAAS,OAAO,KAAA,IAAY,MAAM,IAAK;EACjF,MAAM,OAAO,eAAgB,MAAM,SAAS,OAAO,OAAO,SAAS,KAAM;EACzE,MAAM,WAAW,sBAAsB,MAAM,QAAQ;EACrD,MAAM,QAAQ,eAAe,SAAS,SAAS,MAAM,OAAO;EAE5D,MAAM,UAAU,eAAe;GAC7B,GAAG,EAAE;GACL,GAAG,EAAE,MAAM,OAAO;GAClB,GAAG,EAAE,MAAM,IAAI;GACf,GAAG,EAAE,KAAK,KAAK;GACf,GAAG,GAAG,WAAW,MAAM,OAAO;GAC9B,GAAG,GAAG,SAAS,MAAM,KAAK;EAC5B,CAAC;EAKD,SAAS,QAAQ,OAAyB;GACxC,QAAQ,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK,EAAA,CAAG,MAAM,SAAS;IAC7D,IAAI,CAAC,QAAQ,IAAI,GAAG,OAAO,OAAO,SAAS,YA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A,CAAE,CAAC,EAAC,SAAA,CAAA,E,oBAEH,OAAO,WAAxBH,UAAA,GAAAC,mBAEO,QAAA;;KAF2B,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA,CAAA;I,IAC3CE,YAAqCF,MAAA,SAAA,GAAA,EAAzB,OAAO,OAAO,Q;IAEZ,OAAO,SAAvBH,UAAA,GAAAC,mBAKWM,UAAA,EAAA,KAAA,EAAA,GAAA,CAJI,CAAA,OAAO,aAApBP,UAAA,GAAAC,mBAES,QAAA;;KAFuB,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,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
+ {"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,MAAM,QAAQ;EAQd,MAAM,OAAO;EACb,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,QAAQ;EAGhC,MAAM,WAAW,kBAAmB,MAAM,SAAS,OAAO,KAAA,IAAY,MAAM,IAAK;EACjF,MAAM,OAAO,eAAgB,MAAM,SAAS,OAAO,OAAO,SAAS,KAAM;EAGzE,MAAM,OAAO,eAAkC,MAAM;EACrD,MAAM,cAAc,qBAAqB,KAAK,KAAK;EACnD,MAAM,WAAW,sBAAsB,MAAM,YAAY,YAAY,SAAS,CAAC;EAC/E,MAAM,QAAQ,eAAe,SAAS,SAAS,MAAM,OAAO;EAE5D,M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AO,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":"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 (props.disabled) 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 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 ]\"\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
+ {"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 (props.disabled) return;
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(_ctx.$attrs, {
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: __props.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 (props.disabled) 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 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 ]\"\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYA,MAAM,QAAQ;EAQd,MAAM,OAAO;EAEb,MAAM,KAAK,aAAa,aAAa;EACrC,MAAM,EAAE,MAAM,UAAU;EAExB,MAAM,YAAY,aAAa,EAAE,gBAAgB,MAAM,SAAS,CAAC;EACjE,MAAM,SAAS,UAAU;EAEzB,eAAe,OAAO;GACpB,IAAI,MAAM,UAAU;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;IACd,KAAK,SAAS,KAAK;GACrB;EACF;EAEA,MAAM,QAAQ,eAAe,MAAM,SAAS,EAAE,iBAAiB,CAAC;EAChE,MAAM,cAAc,eAAe,MAAM,eAAe,EAAE,mBAAmB,CAAC;;GAK5E,OAAAC,UAAA,GAAAC,YAoBaC,MAAA,UAAA,GAAA;IApBA,SAASA,MAAA,MAAA,IAAS,YAAA,QAAc,MAAA;IAAQ,UAAU,QAAA;;IAC7D,SAAAC,cAkBS,CAlBTC,mBAkBS,UAlBTC,WACUN,KAiBD,QAjBO;KACd,MAAK;KACJ,OAAK;MAAYG,MAAA,EAAA,CAAE,CAAC,EAAC;MAAYA,MAAA,EAAA,CAAE,CAAC,EAAE,QAAA,IAAI;MAAWA,MAAA,EAAA,CAAE,CAAC,EAAE,QAAA,OAAO;MAAWA,MAAA,EAAA,CAAE,CAAC,GAAE,UAAWA,MAAA,MAAA,CAAM;MAAWA,MAAA,EAAA,CAAE,CAAC,GAAE,YAAa,QAAA,SAAS;;KAOxI,UAAU,QAAA;KACV,cAAYA,MAAA,MAAA,IAAS,YAAA,QAAc,MAAA;KACnC,SAAO;;KAESA,MAAA,MAAA,KAAjBF,UAAA,GAAAC,YAAiDC,MAAA,SAAA,GAAA;;MAAvB,OAAKI,eAAEJ,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA,CAAA;K,2BACrCF,UAAA,GAAAC,YAAyCC,MAAA,QAAA,GAAA;;MAAvB,OAAKI,eAAEJ,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA,CAAA;;KACjB,QAAA,aAAZF,UAAA,GAAAO,mBAAuF,QAAA;;MAA/D,OAAKD,eAAEJ,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,CAAA;KAAc,GAAAM,gBAAAN,MAAA,MAAA,IAAS,YAAA,QAAc,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
+ {"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 </DouToolt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EAAA,CAAE,CAAC,GAAE,gBAAiBA,MAAA,WAAA,CAAW,CAAC,OAAO,KAAK;;KAQjM,UAAU,SAAA;KACV,cAAYA,MAAA,MAAA,IAAS,YAAA,QAAc,MAAA;KACnC,SAAO;;KAESA,MAAA,MAAA,KAAjBF,UAAA,GAAAC,YAAiDC,MAAA,SAAA,GAAA;;MAAvB,OAAKI,eAAEJ,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA,CAAA;K,2BACrCF,UAAA,GAAAC,YAAyCC,MAAA,QAAA,GAAA;;MAAvB,OAAKI,eAAEJ,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA,CAAA;;KACjB,QAAA,aAAZF,UAAA,GAAAO,mBAAuF,QAAA;;MAA/D,OAAKD,eAAEJ,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,CAAA;KAAc,GAAAM,gBAAAN,MAAA,MAAA,IAAS,YAAA,QAAc,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"}
@@ -4,4 +4,6 @@ import '@dou-ui/theme/components/button.css'
4
4
  import '@dou-ui/theme/components/color-panel.css'
5
5
  import '@dou-ui/theme/components/dropdown.css'
6
6
  import '@dou-ui/theme/components/icon.css'
7
+ import '@dou-ui/theme/components/input-number.css'
8
+ import '@dou-ui/theme/components/input.css'
7
9
  import '@dou-ui/theme/components/field-group.css'
@@ -1,3 +1,5 @@
1
1
  import '@dou-ui/theme/core.css'
2
2
  import '@dou-ui/theme/components/color-panel.css'
3
+ import '@dou-ui/theme/components/input-number.css'
4
+ import '@dou-ui/theme/components/input.css'
3
5
  import '@dou-ui/theme/components/field-group.css'
@@ -1 +1 @@
1
- {"version":3,"file":"input.js","names":["_sfc_main"],"sources":["../../../src/components/input/input.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CloseIcon, EyeIcon, EyeOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useAttrs, useTemplateRef } from 'vue'\nimport type { StyleValue } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { useFormDisabled, useFormItem, useFormReadonly, useFormSize } from '../form/use-form-item'\nimport type { InputExpose, InputProps, InputSlots } from './input'\n\ndefineOptions({ name: 'DouInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<InputProps>(), {\n disabled: false,\n readonly: false,\n invalid: false,\n clearable: false,\n type: 'text',\n showPassword: false,\n showCount: false,\n})\nconst model = defineModel<string>({ default: '' })\nconst emit = defineEmits<{ clear: [] }>()\nconst slots = defineSlots<InputSlots>()\n\nconst ns = useNamespace('input')\nconst { t } = useLocale()\nconst { formItem } = useFormItem()\nconst size = useFormSize(() => props.size)\nconst disabled = useFormDisabled(() => props.disabled)\nconst readonly = useFormReadonly(() => props.readonly)\nconst invalid = computed(() => props.invalid || !!formItem?.invalid.value)\n\n// `class` and `style` dress the field; every other attribute (placeholder,\n// name, autocomplete, listeners...) belongs to the native input. Inside a\n// form item the input also takes the item's id and description, unless\n// the caller sets them.\nconst attrs = useAttrs()\nconst inputAttrs = computed(() => {\n const { class: _class, style: _style, ...rest } = attrs\n if (!formItem) return rest\n return {\n id: formItem.inputId,\n 'aria-describedby': formItem.describedBy.value,\n 'aria-required': formItem.required.value || undefined,\n ...rest,\n }\n})\n\nconst inputRef = useTemplateRef<HTMLInputElement>('input')\n\nconst revealed = ref(false)\nconst nativeType = computed(() =>\n props.type === 'password' && props.showPassword && revealed.value ? 'text' : props.type,\n)\n\nconst maxLength = computed(() => {\n const value = Number(attrs.maxlength ?? attrs.maxLength)\n return Number.isFinite(value) && value > 0 ? value : undefined\n})\n// Count what a person sees as characters, so an emoji counts once.\nconst count = computed(() => [...model.value].length)\n\nconst showClear = computed(\n () => props.clearable && !disabled.value && !readonly.value && model.value !== '',\n)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(size.value),\n ns.is('disabled', disabled.value),\n ns.is('readonly', readonly.value),\n ns.is('invalid', invalid.value),\n attrs.class,\n])\n\nasync function clear() {\n model.value = ''\n emit('clear')\n formItem?.trigger('change', { lazy: true })\n await nextTick()\n inputRef.value?.focus()\n}\n\n// Pressing the padding or a plain affix should land in the text without\n// first blurring it. Interactive content inside an affix keeps its own focus.\nfunction onMousedown(event: MouseEvent) {\n const target = event.target as HTMLElement\n if (target === inputRef.value || target.closest('button, a, input, select, textarea')) return\n event.preventDefault()\n inputRef.value?.focus()\n}\n\ndefineExpose<InputExpose>({\n get input() {\n return inputRef.value\n },\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n select: () => inputRef.value?.select(),\n})\n</script>\n\n<template>\n <span :class=\"classes\" :style=\"attrs.style as StyleValue\" @mousedown=\"onMousedown\">\n <span v-if=\"slots.prefix\" :class=\"[ns.e('affix'), ns.e('prefix')]\">\n <slot name=\"prefix\" />\n </span>\n <input\n ref=\"input\"\n v-model=\"model\"\n v-bind=\"inputAttrs\"\n :class=\"ns.e('native')\"\n :type=\"nativeType\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :aria-invalid=\"invalid || undefined\"\n @input=\"formItem?.trigger('change', { lazy: true })\"\n @blur=\"formItem?.trigger('blur')\"\n />\n <button\n v-if=\"showClear\"\n type=\"button\"\n tabindex=\"-1\"\n :class=\"ns.e('clear')\"\n :aria-label=\"t('input.clear')\"\n @mousedown.prevent\n @click=\"clear\"\n >\n <CloseIcon />\n </button>\n <button\n v-if=\"type === 'password' && showPassword\"\n type=\"button\"\n :class=\"ns.e('reveal')\"\n :aria-label=\"t(revealed ? 'input.hidePassword' : 'input.showPassword')\"\n :aria-pressed=\"revealed\"\n :disabled=\"disabled\"\n @mousedown.prevent\n @click=\"revealed = !revealed\"\n >\n <EyeOffIcon v-if=\"revealed\" />\n <EyeIcon v-else />\n </button>\n <span v-if=\"showCount\" :class=\"ns.e('count')\" aria-hidden=\"true\">\n {{ maxLength ? `${count} / ${maxLength}` : count }}\n </span>\n <span v-if=\"slots.suffix\" :class=\"[ns.e('affix'), ns.e('suffix')]\">\n <slot name=\"suffix\" />\n </span>\n </span>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"input.js","names":["_sfc_main"],"sources":["../../../src/components/input/input.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CloseIcon, EyeIcon, EyeOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useAttrs, useTemplateRef } from 'vue'\nimport type { StyleValue } from 'vue'\nimport { FieldAffix } from '../../utils/field-action'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { useFormDisabled, useFormItem, useFormReadonly, useFormSize } from '../form/use-form-item'\nimport type { InputExpose, InputProps, InputSlots } from './input'\n\ndefineOptions({ name: 'DouInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<InputProps>(), {\n disabled: false,\n readonly: false,\n invalid: false,\n clearable: false,\n type: 'text',\n showPassword: false,\n showCount: false,\n})\nconst model = defineModel<string>({ default: '' })\nconst emit = defineEmits<{ clear: [] }>()\nconst slots = defineSlots<InputSlots>()\n\nconst ns = useNamespace('input')\nconst { t } = useLocale()\nconst { formItem } = useFormItem()\nconst size = useFormSize(() => props.size)\nconst disabled = useFormDisabled(() => props.disabled)\nconst readonly = useFormReadonly(() => props.readonly)\nconst invalid = computed(() => props.invalid || !!formItem?.invalid.value)\n\n// `class` and `style` dress the field; every other attribute (placeholder,\n// name, autocomplete, listeners...) belongs to the native input. Inside a\n// form item the input also takes the item's id and description, unless\n// the caller sets them.\nconst attrs = useAttrs()\nconst inputAttrs = computed(() => {\n const { class: _class, style: _style, ...rest } = attrs\n if (!formItem) return rest\n return {\n id: formItem.inputId,\n 'aria-describedby': formItem.describedBy.value,\n 'aria-required': formItem.required.value || undefined,\n ...rest,\n }\n})\n\nconst inputRef = useTemplateRef<HTMLInputElement>('input')\n\nconst revealed = ref(false)\nconst nativeType = computed(() =>\n props.type === 'password' && props.showPassword && revealed.value ? 'text' : props.type,\n)\n\nconst maxLength = computed(() => {\n const value = Number(attrs.maxlength ?? attrs.maxLength)\n return Number.isFinite(value) && value > 0 ? value : undefined\n})\n// Count what a person sees as characters, so an emoji counts once.\nconst count = computed(() => [...model.value].length)\n\nconst showClear = computed(\n () => props.clearable && !disabled.value && !readonly.value && model.value !== '',\n)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(size.value),\n ns.is('disabled', disabled.value),\n ns.is('readonly', readonly.value),\n ns.is('invalid', invalid.value),\n attrs.class,\n])\n\nasync function clear() {\n model.value = ''\n emit('clear')\n formItem?.trigger('change', { lazy: true })\n await nextTick()\n inputRef.value?.focus()\n}\n\n// Pressing the padding or a plain affix should land in the text without\n// first blurring it. Interactive content inside an affix keeps its own focus.\nfunction onMousedown(event: MouseEvent) {\n const target = event.target as HTMLElement\n if (target === inputRef.value || target.closest('button, a, input, select, textarea')) return\n event.preventDefault()\n inputRef.value?.focus()\n}\n\ndefineExpose<InputExpose>({\n get input() {\n return inputRef.value\n },\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n select: () => inputRef.value?.select(),\n})\n</script>\n\n<template>\n <span :class=\"classes\" :style=\"attrs.style as StyleValue\" @mousedown=\"onMousedown\">\n <FieldAffix\n v-if=\"slots.prefix\"\n side=\"start\"\n :class=\"[ns.e('affix'), ns.e('prefix')]\"\n :disabled=\"disabled\"\n :render=\"slots.prefix\"\n />\n <input\n ref=\"input\"\n v-model=\"model\"\n v-bind=\"inputAttrs\"\n :class=\"ns.e('native')\"\n :type=\"nativeType\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :aria-invalid=\"invalid || undefined\"\n @input=\"formItem?.trigger('change', { lazy: true })\"\n @blur=\"formItem?.trigger('blur')\"\n />\n <button\n v-if=\"showClear\"\n type=\"button\"\n tabindex=\"-1\"\n :class=\"ns.e('clear')\"\n :aria-label=\"t('input.clear')\"\n @mousedown.prevent\n @click=\"clear\"\n >\n <CloseIcon />\n </button>\n <button\n v-if=\"type === 'password' && showPassword\"\n type=\"button\"\n :class=\"ns.e('reveal')\"\n :aria-label=\"t(revealed ? 'input.hidePassword' : 'input.showPassword')\"\n :aria-pressed=\"revealed\"\n :disabled=\"disabled\"\n @mousedown.prevent\n @click=\"revealed = !revealed\"\n >\n <EyeOffIcon v-if=\"revealed\" />\n <EyeIcon v-else />\n </button>\n <span v-if=\"showCount\" :class=\"ns.e('count')\" aria-hidden=\"true\">\n {{ maxLength ? `${count} / ${maxLength}` : count }}\n </span>\n <FieldAffix\n v-if=\"slots.suffix\"\n side=\"end\"\n :class=\"[ns.e('affix'), ns.e('suffix')]\"\n :disabled=\"disabled\"\n :render=\"slots.suffix\"\n />\n </span>\n</template>\n"],"mappings":""}
@@ -1,7 +1,8 @@
1
1
  import { useNamespace } from "../../utils/namespace.js";
2
2
  import { useLocale } from "../config-provider/use-config.js";
3
3
  import { useFormDisabled, useFormItem, useFormReadonly, useFormSize } from "../form/use-form-item.js";
4
- import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, mergeModels, mergeProps, nextTick, normalizeClass, normalizeStyle, openBlock, ref, renderSlot, toDisplayString, unref, useAttrs, useModel, useSlots, useTemplateRef, vModelDynamic, withDirectives, withModifiers } from "vue";
4
+ import { FieldAffix } from "../../utils/field-action.js";
5
+ import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, mergeModels, mergeProps, nextTick, normalizeClass, normalizeStyle, openBlock, ref, toDisplayString, unref, useAttrs, useModel, useSlots, useTemplateRef, vModelDynamic, withDirectives, withModifiers } from "vue";
5
6
  import { CloseIcon, EyeIcon, EyeOffIcon } from "@dou-ui/icons";
6
7
  // src/components/input/input.vue?vue&type=script&setup=true&lang.ts
7
8
  var _hoisted_1 = [
@@ -120,10 +121,17 @@ var input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComp
120
121
  style: normalizeStyle(unref(attrs).style),
121
122
  onMousedown
122
123
  }, [
123
- slots.prefix ? (openBlock(), createElementBlock("span", {
124
+ slots.prefix ? (openBlock(), createBlock(unref(FieldAffix), {
124
125
  key: 0,
125
- class: normalizeClass([unref(ns).e("affix"), unref(ns).e("prefix")])
126
- }, [renderSlot(_ctx.$slots, "prefix")], 2)) : createCommentVNode("", true),
126
+ side: "start",
127
+ class: normalizeClass([unref(ns).e("affix"), unref(ns).e("prefix")]),
128
+ disabled: unref(disabled),
129
+ render: slots.prefix
130
+ }, null, 8, [
131
+ "class",
132
+ "disabled",
133
+ "render"
134
+ ])) : createCommentVNode("", true),
127
135
  withDirectives(createElementVNode("input", mergeProps({
128
136
  ref: "input",
129
137
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => model.value = $event)
@@ -160,10 +168,17 @@ var input_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComp
160
168
  class: normalizeClass(unref(ns).e("count")),
161
169
  "aria-hidden": "true"
162
170
  }, toDisplayString(maxLength.value ? `${count.value} / ${maxLength.value}` : count.value), 3)) : createCommentVNode("", true),
163
- slots.suffix ? (openBlock(), createElementBlock("span", {
171
+ slots.suffix ? (openBlock(), createBlock(unref(FieldAffix), {
164
172
  key: 4,
165
- class: normalizeClass([unref(ns).e("affix"), unref(ns).e("suffix")])
166
- }, [renderSlot(_ctx.$slots, "suffix")], 2)) : createCommentVNode("", true)
173
+ side: "end",
174
+ class: normalizeClass([unref(ns).e("affix"), unref(ns).e("suffix")]),
175
+ disabled: unref(disabled),
176
+ render: slots.suffix
177
+ }, null, 8, [
178
+ "class",
179
+ "disabled",
180
+ "render"
181
+ ])) : createCommentVNode("", true)
167
182
  ], 38);
168
183
  };
169
184
  }
@@ -1 +1 @@
1
- {"version":3,"file":"input.vue_vue_type_script_setup_true_lang.js","names":["_useModel","_useSlots","_openBlock","_createElementBlock","_normalizeClass","_normalizeStyle","_unref","_renderSlot","_createCommentVNode","_withDirectives","_createElementVNode","_mergeProps","_vModelDynamic","_withModifiers","_createVNode","_createBlock","_toDisplayString"],"sources":["../../../src/components/input/input.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CloseIcon, EyeIcon, EyeOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useAttrs, useTemplateRef } from 'vue'\nimport type { StyleValue } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { useFormDisabled, useFormItem, useFormReadonly, useFormSize } from '../form/use-form-item'\nimport type { InputExpose, InputProps, InputSlots } from './input'\n\ndefineOptions({ name: 'DouInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<InputProps>(), {\n disabled: false,\n readonly: false,\n invalid: false,\n clearable: false,\n type: 'text',\n showPassword: false,\n showCount: false,\n})\nconst model = defineModel<string>({ default: '' })\nconst emit = defineEmits<{ clear: [] }>()\nconst slots = defineSlots<InputSlots>()\n\nconst ns = useNamespace('input')\nconst { t } = useLocale()\nconst { formItem } = useFormItem()\nconst size = useFormSize(() => props.size)\nconst disabled = useFormDisabled(() => props.disabled)\nconst readonly = useFormReadonly(() => props.readonly)\nconst invalid = computed(() => props.invalid || !!formItem?.invalid.value)\n\n// `class` and `style` dress the field; every other attribute (placeholder,\n// name, autocomplete, listeners...) belongs to the native input. Inside a\n// form item the input also takes the item's id and description, unless\n// the caller sets them.\nconst attrs = useAttrs()\nconst inputAttrs = computed(() => {\n const { class: _class, style: _style, ...rest } = attrs\n if (!formItem) return rest\n return {\n id: formItem.inputId,\n 'aria-describedby': formItem.describedBy.value,\n 'aria-required': formItem.required.value || undefined,\n ...rest,\n }\n})\n\nconst inputRef = useTemplateRef<HTMLInputElement>('input')\n\nconst revealed = ref(false)\nconst nativeType = computed(() =>\n props.type === 'password' && props.showPassword && revealed.value ? 'text' : props.type,\n)\n\nconst maxLength = computed(() => {\n const value = Number(attrs.maxlength ?? attrs.maxLength)\n return Number.isFinite(value) && value > 0 ? value : undefined\n})\n// Count what a person sees as characters, so an emoji counts once.\nconst count = computed(() => [...model.value].length)\n\nconst showClear = computed(\n () => props.clearable && !disabled.value && !readonly.value && model.value !== '',\n)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(size.value),\n ns.is('disabled', disabled.value),\n ns.is('readonly', readonly.value),\n ns.is('invalid', invalid.value),\n attrs.class,\n])\n\nasync function clear() {\n model.value = ''\n emit('clear')\n formItem?.trigger('change', { lazy: true })\n await nextTick()\n inputRef.value?.focus()\n}\n\n// Pressing the padding or a plain affix should land in the text without\n// first blurring it. Interactive content inside an affix keeps its own focus.\nfunction onMousedown(event: MouseEvent) {\n const target = event.target as HTMLElement\n if (target === inputRef.value || target.closest('button, a, input, select, textarea')) return\n event.preventDefault()\n inputRef.value?.focus()\n}\n\ndefineExpose<InputExpose>({\n get input() {\n return inputRef.value\n },\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n select: () => inputRef.value?.select(),\n})\n</script>\n\n<template>\n <span :class=\"classes\" :style=\"attrs.style as StyleValue\" @mousedown=\"onMousedown\">\n <span v-if=\"slots.prefix\" :class=\"[ns.e('affix'), ns.e('prefix')]\">\n <slot name=\"prefix\" />\n </span>\n <input\n ref=\"input\"\n v-model=\"model\"\n v-bind=\"inputAttrs\"\n :class=\"ns.e('native')\"\n :type=\"nativeType\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :aria-invalid=\"invalid || undefined\"\n @input=\"formItem?.trigger('change', { lazy: true })\"\n @blur=\"formItem?.trigger('blur')\"\n />\n <button\n v-if=\"showClear\"\n type=\"button\"\n tabindex=\"-1\"\n :class=\"ns.e('clear')\"\n :aria-label=\"t('input.clear')\"\n @mousedown.prevent\n @click=\"clear\"\n >\n <CloseIcon />\n </button>\n <button\n v-if=\"type === 'password' && showPassword\"\n type=\"button\"\n :class=\"ns.e('reveal')\"\n :aria-label=\"t(revealed ? 'input.hidePassword' : 'input.showPassword')\"\n :aria-pressed=\"revealed\"\n :disabled=\"disabled\"\n @mousedown.prevent\n @click=\"revealed = !revealed\"\n >\n <EyeOffIcon v-if=\"revealed\" />\n <EyeIcon v-else />\n </button>\n <span v-if=\"showCount\" :class=\"ns.e('count')\" aria-hidden=\"true\">\n {{ maxLength ? `${count} / ${maxLength}` : count }}\n </span>\n <span v-if=\"slots.suffix\" :class=\"[ns.e('affix'), ns.e('suffix')]\">\n <slot name=\"suffix\" />\n </span>\n </span>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWA,MAAM,QAAQ;EASd,MAAM,QAAQA,SAAmB,SAAA,YAAgB;EACjD,MAAM,OAAO;EACb,MAAM,QAAQC,SAAA;EAEd,MAAM,KAAK,aAAa,OAAO;EAC/B,MAAM,EAAE,MAAM,UAAU;EACxB,MAAM,EAAE,aAAa,YAAY;EACjC,MAAM,OAAO,kBAAkB,MAAM,IAAI;EACzC,MAAM,WAAW,sBAAsB,MAAM,QAAQ;EACrD,MAAM,WAAW,sBAAsB,MAAM,QAAQ;EACrD,MAAM,UAAU,eAAe,MAAM,WAAW,CAAC,CAAC,UAAU,QAAQ,KAAK;EAMzE,MAAM,QAAQ,SAAS;EACvB,MAAM,aAAa,eAAe;GAChC,MAAM,EAAE,OAAO,QAAQ,OAAO,QAAQ,GAAG,SAAS;GAClD,IAAI,CAAC,UAAU,OAAO;GACtB,OAAO;IACL,IAAI,SAAS;IACb,oBAAoB,SAAS,YAAY;IACzC,iBAAiB,SAAS,SAAS,SAAS,KAAA;IAC5C,GAAG;GACL;EACF,CAAC;EAED,MAAM,WAAW,eAAiC,OAAO;EAEzD,MAAM,WAAW,IAAI,KAAK;EAC1B,MAAM,aAAa,eACjB,MAAM,SAAS,cAAc,MAAM,gBAAgB,SAAS,QAAQ,SAAS,MAAM,IACrF;EAEA,MAAM,YAAY,eAAe;GAC/B,MAAM,QAAQ,OAAO,MAAM,aAAa,MAAM,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,MAAA,UAAA,GAAA,EAAA,KAAA,EAAA,CAAA,MAC9BJ,UAAA,GAAAa,YAAkBT,MAAA,OAAA,GAAA,EAAA,KAAA,EAAA,CAAA,E;IAER,QAAA,aAAZJ,UAAA,GAAAC,mBAEO,QAAA;;KAFiB,OAAKC,eAAEE,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,CAAA;KAAW,eAAY;IACrD,GAAAU,gBAAA,UAAA,QAAS,GAAM,MAAA,MAAK,KAAM,UAAA,UAAc,MAAA,KAAK,GAAA,CAAA,K;IAEtC,MAAM,UAAlBd,UAAA,GAAAC,mBAEO,QAAA;;KAFoB,OAAKC,eAAA,CAAGE,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,GAAWA,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA,CAAA;I,IACpDC,WAAsB,KAAA,QAAA,QAAA,C"}
1
+ {"version":3,"file":"input.vue_vue_type_script_setup_true_lang.js","names":["_useModel","_useSlots","_openBlock","_createElementBlock","_normalizeClass","_normalizeStyle","_unref","_createBlock","_createCommentVNode","_withDirectives","_createElementVNode","_mergeProps","_vModelDynamic","_withModifiers","_createVNode","_toDisplayString"],"sources":["../../../src/components/input/input.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CloseIcon, EyeIcon, EyeOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useAttrs, useTemplateRef } from 'vue'\nimport type { StyleValue } from 'vue'\nimport { FieldAffix } from '../../utils/field-action'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { useFormDisabled, useFormItem, useFormReadonly, useFormSize } from '../form/use-form-item'\nimport type { InputExpose, InputProps, InputSlots } from './input'\n\ndefineOptions({ name: 'DouInput', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<InputProps>(), {\n disabled: false,\n readonly: false,\n invalid: false,\n clearable: false,\n type: 'text',\n showPassword: false,\n showCount: false,\n})\nconst model = defineModel<string>({ default: '' })\nconst emit = defineEmits<{ clear: [] }>()\nconst slots = defineSlots<InputSlots>()\n\nconst ns = useNamespace('input')\nconst { t } = useLocale()\nconst { formItem } = useFormItem()\nconst size = useFormSize(() => props.size)\nconst disabled = useFormDisabled(() => props.disabled)\nconst readonly = useFormReadonly(() => props.readonly)\nconst invalid = computed(() => props.invalid || !!formItem?.invalid.value)\n\n// `class` and `style` dress the field; every other attribute (placeholder,\n// name, autocomplete, listeners...) belongs to the native input. Inside a\n// form item the input also takes the item's id and description, unless\n// the caller sets them.\nconst attrs = useAttrs()\nconst inputAttrs = computed(() => {\n const { class: _class, style: _style, ...rest } = attrs\n if (!formItem) return rest\n return {\n id: formItem.inputId,\n 'aria-describedby': formItem.describedBy.value,\n 'aria-required': formItem.required.value || undefined,\n ...rest,\n }\n})\n\nconst inputRef = useTemplateRef<HTMLInputElement>('input')\n\nconst revealed = ref(false)\nconst nativeType = computed(() =>\n props.type === 'password' && props.showPassword && revealed.value ? 'text' : props.type,\n)\n\nconst maxLength = computed(() => {\n const value = Number(attrs.maxlength ?? attrs.maxLength)\n return Number.isFinite(value) && value > 0 ? value : undefined\n})\n// Count what a person sees as characters, so an emoji counts once.\nconst count = computed(() => [...model.value].length)\n\nconst showClear = computed(\n () => props.clearable && !disabled.value && !readonly.value && model.value !== '',\n)\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(size.value),\n ns.is('disabled', disabled.value),\n ns.is('readonly', readonly.value),\n ns.is('invalid', invalid.value),\n attrs.class,\n])\n\nasync function clear() {\n model.value = ''\n emit('clear')\n formItem?.trigger('change', { lazy: true })\n await nextTick()\n inputRef.value?.focus()\n}\n\n// Pressing the padding or a plain affix should land in the text without\n// first blurring it. Interactive content inside an affix keeps its own focus.\nfunction onMousedown(event: MouseEvent) {\n const target = event.target as HTMLElement\n if (target === inputRef.value || target.closest('button, a, input, select, textarea')) return\n event.preventDefault()\n inputRef.value?.focus()\n}\n\ndefineExpose<InputExpose>({\n get input() {\n return inputRef.value\n },\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n select: () => inputRef.value?.select(),\n})\n</script>\n\n<template>\n <span :class=\"classes\" :style=\"attrs.style as StyleValue\" @mousedown=\"onMousedown\">\n <FieldAffix\n v-if=\"slots.prefix\"\n side=\"start\"\n :class=\"[ns.e('affix'), ns.e('prefix')]\"\n :disabled=\"disabled\"\n :render=\"slots.prefix\"\n />\n <input\n ref=\"input\"\n v-model=\"model\"\n v-bind=\"inputAttrs\"\n :class=\"ns.e('native')\"\n :type=\"nativeType\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :aria-invalid=\"invalid || undefined\"\n @input=\"formItem?.trigger('change', { lazy: true })\"\n @blur=\"formItem?.trigger('blur')\"\n />\n <button\n v-if=\"showClear\"\n type=\"button\"\n tabindex=\"-1\"\n :class=\"ns.e('clear')\"\n :aria-label=\"t('input.clear')\"\n @mousedown.prevent\n @click=\"clear\"\n >\n <CloseIcon />\n </button>\n <button\n v-if=\"type === 'password' && showPassword\"\n type=\"button\"\n :class=\"ns.e('reveal')\"\n :aria-label=\"t(revealed ? 'input.hidePassword' : 'input.showPassword')\"\n :aria-pressed=\"revealed\"\n :disabled=\"disabled\"\n @mousedown.prevent\n @click=\"revealed = !revealed\"\n >\n <EyeOffIcon v-if=\"revealed\" />\n <EyeIcon v-else />\n </button>\n <span v-if=\"showCount\" :class=\"ns.e('count')\" aria-hidden=\"true\">\n {{ maxLength ? `${count} / ${maxLength}` : count }}\n </span>\n <FieldAffix\n v-if=\"slots.suffix\"\n side=\"end\"\n :class=\"[ns.e('affix'), ns.e('suffix')]\"\n :disabled=\"disabled\"\n :render=\"slots.suffix\"\n />\n </span>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYA,MAAM,QAAQ;EASd,MAAM,QAAQA,SAAmB,SAAA,YAAgB;EACjD,MAAM,OAAO;EACb,MAAM,QAAQC,SAAA;EAEd,MAAM,KAAK,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C,OAAA,GAAWA,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA,CAAA;KAC3B,UAAUA,MAAA,QAAA;KACV,QAAQ,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"input-number.js","names":["_sfc_main"],"sources":["../../../src/components/input-number/input-number.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CloseIcon, MinusIcon, PlusIcon } from '@dou-ui/icons'\nimport { computed, onBeforeUnmount, ref, useAttrs, useTemplateRef, watch } from 'vue'\nimport type { HTMLAttributes, StyleValue } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { useFormDisabled, useFormItem, useFormReadonly, useFormSize } from '../form/use-form-item'\nimport type { InputNumberExpose, InputNumberProps, InputNumberSlots } from './input-number'\n\ndefineOptions({ name: 'DouInputNumber', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<InputNumberProps>(), {\n min: -Infinity,\n max: Infinity,\n step: 1,\n disabled: false,\n readonly: false,\n invalid: false,\n controls: true,\n clearable: false,\n})\nconst model = defineModel<number | null>({ default: null })\nconst emit = defineEmits<{ change: [value: number | null, oldValue: number | null]; clear: [] }>()\nconst slots = defineSlots<InputNumberSlots>()\n\nconst ns = useNamespace('input-number')\nconst { t, locale } = useLocale()\nconst { formItem } = useFormItem()\nconst size = useFormSize(() => props.size)\nconst disabled = useFormDisabled(() => props.disabled)\nconst readonly = useFormReadonly(() => props.readonly)\nconst invalid = computed(() => props.invalid || !!formItem?.invalid.value)\nconst editable = computed(() => !disabled.value && !readonly.value)\n\nconst attrs = useAttrs()\nconst inputAttrs = computed(() => {\n const { class: _class, style: _style, ...rest } = attrs\n if (!formItem) return rest\n return {\n id: formItem.inputId,\n 'aria-describedby': formItem.describedBy.value,\n 'aria-required': formItem.required.value || undefined,\n ...rest,\n }\n})\n\n// The on-screen keyboard: digits only for whole numbers. The iOS number\n// pads have no minus key, so a range that reaches below zero gets the full\n// keyboard. An `inputmode` attribute overrides this.\nconst inputMode = computed((): HTMLAttributes['inputmode'] => {\n if (typeof attrs.inputmode === 'string') return attrs.inputmode as HTMLAttributes['inputmode']\n if (Number.isFinite(props.min) && props.min < 0) return 'text'\n return props.precision === 0 ? 'numeric' : 'decimal'\n})\n\nconst inputRef = useTemplateRef<HTMLInputElement>('input')\n\nfunction decimals(value: number) {\n const [digits = '', exponent] = String(value).split('e')\n const fraction = digits.split('.')[1]?.length ?? 0\n return Math.max(0, fraction - Number(exponent ?? 0))\n}\n\n// Round through the decimal notation, so 1.005 rounds to 1.01 and\n// 0.1 + 0.2 lands on 0.3.\nfunction round(value: number, places: number) {\n return Number(`${Math.round(Number(`${value}e${places}`))}e-${places}`)\n}\n\nconst clamp = (value: number) => Math.min(Math.max(value, props.min), props.max)\n\nfunction normalize(value: number) {\n return clamp(props.precision === undefined ? value : round(value, props.precision))\n}\n\nfunction format(value: number | null) {\n if (value === null || Number.isNaN(value)) return ''\n return props.precision === undefined ? String(value) : value.toFixed(props.precision)\n}\n\n// How the value reads while the field is not being edited.\nconst formatter = computed(() => {\n const option = props.format\n if (!option) return undefined\n if (typeof option === 'function') return option\n const digits =\n props.precision === undefined\n ? {}\n : { minimumFractionDigits: props.precision, maximumFractionDigits: props.precision }\n const intl = new Intl.NumberFormat(locale.value.name, { ...digits, ...option })\n return (value: number) => intl.format(value)\n})\nconst focused = ref(false)\n\n/** `null` for an empty field, `NaN` for text that is not a number. */\nfunction parse(text: string) {\n const trimmed = text.trim()\n if (trimmed === '') return null\n // Accept the full-width digits and signs an IME may produce.\n const ascii = trimmed\n .replace(/[0-9]/g, (digit) => String(digit.charCodeAt(0) - 0xff10))\n .replace(/[.。]/g, '.')\n .replace(/[-−]/g, '-')\n return /^[+-]?(\\d+\\.?\\d*|\\.\\d+)(e[+-]?\\d+)?$/i.test(ascii) ? Number(ascii) : Number.NaN\n}\n\n// What the field shows. It follows the model, except while the user is\n// typing something that is not a number yet, such as `-` or `1.`.\nconst text = ref(format(model.value))\n// The value as of the last commit, reported as `oldValue` by `change`.\nlet committed = model.value\n\n// A value that does not match the text came from outside, not from typing.\nwatch(model, (value) => {\n if (parse(text.value) === value) return\n text.value = format(value)\n committed = value\n})\n\nfunction commit(value: number | null) {\n model.value = value\n text.value = format(value)\n if (value !== committed) {\n const old = committed\n committed = value\n emit('change', value, old)\n formItem?.trigger('change')\n }\n}\n\nfunction onInput(event: Event) {\n text.value = (event.target as HTMLInputElement).value\n const value = parse(text.value)\n // Only report values that would survive the commit unchanged, so a\n // half-typed number never reaches the model out of range.\n if (value === null || (!Number.isNaN(value) && value === normalize(value))) {\n model.value = value\n formItem?.trigger('change', { lazy: true })\n }\n}\n\nfunction onChange() {\n const value = parse(text.value)\n commit(Number.isNaN(value) ? model.value : value === null ? null : normalize(value))\n}\n\n// The plain text while editing, the formatted value otherwise.\nconst shown = computed(() =>\n focused.value || !formatter.value || model.value === null || Number.isNaN(model.value)\n ? text.value\n : formatter.value(model.value),\n)\n\nfunction onBlur() {\n focused.value = false\n onChange()\n formItem?.trigger('blur')\n}\n\nconst showClear = computed(() => props.clearable && editable.value && model.value !== null)\n\nfunction clear() {\n commit(null)\n emit('clear')\n inputRef.value?.focus()\n}\n\nfunction stepBy(count: number) {\n if (!editable.value) return\n const parsed = parse(text.value)\n const from = parsed === null || Number.isNaN(parsed) ? (model.value ?? 0) : parsed\n const next = round(from + props.step * count, Math.max(decimals(from), decimals(props.step)))\n commit(normalize(next))\n}\n\nconst canIncrease = computed(() => editable.value && (model.value ?? -Infinity) < props.max)\nconst canDecrease = computed(() => editable.value && (model.value ?? Infinity) > props.min)\n\nfunction onKeydown(event: KeyboardEvent) {\n if (!editable.value) return\n const steps: Record<string, number> = { ArrowUp: 1, ArrowDown: -1, PageUp: 10, PageDown: -10 }\n if (event.key in steps) {\n event.preventDefault()\n stepBy(steps[event.key]!)\n } else if (event.key === 'Home' && Number.isFinite(props.min)) {\n event.preventDefault()\n commit(props.min)\n } else if (event.key === 'End' && Number.isFinite(props.max)) {\n event.preventDefault()\n commit(props.max)\n } else if (event.key === 'Enter') {\n onChange()\n }\n}\n\n// Holding a step key repeats the step, slowly at first.\nlet timer: ReturnType<typeof setTimeout> | undefined\n// The key being held: 1 for increase, -1 for decrease, 0 for none.\nconst held = ref(0)\n\nfunction stopRepeat() {\n clearTimeout(timer)\n timer = undefined\n held.value = 0\n}\n\nfunction startRepeat(count: number) {\n stopRepeat()\n if (!(count > 0 ? canIncrease.value : canDecrease.value)) return\n held.value = count\n stepBy(count)\n const repeat = (delay: number) => {\n timer = setTimeout(() => {\n // A key that reaches the limit turns disabled, so stop there.\n if (!(count > 0 ? canIncrease.value : canDecrease.value)) return stopRepeat()\n stepBy(count)\n repeat(50)\n }, delay)\n }\n repeat(400)\n}\n\nfunction onStepPointerdown(event: PointerEvent, count: number) {\n // Touch goes through the key pad below.\n if (event.pointerType === 'touch' || event.button !== 0) return\n startRepeat(count)\n // The pointer may come up over a key that turned disabled, so listen\n // on the window.\n window.addEventListener('pointerup', stopRepeat, { once: true })\n}\n\n// On touch the keys are too small to aim at, so the first press only\n// enlarges them. Keeping the finger down and sliding onto a key steps\n// with it, and the pad shrinks back as soon as that finger lifts. After a\n// plain press the pad stays, later taps step as usual, and it shrinks back\n// after a tap elsewhere or a short pause.\nconst COLLAPSE_DELAY = 2000\n// How far a finger slides from where the pad opened before it counts.\nconst SLIDE_THRESHOLD = 6\n\nconst keysRef = useTemplateRef<HTMLElement>('keys')\nconst expanded = ref(false)\nlet idle: ReturnType<typeof setTimeout> | undefined\n\nfunction onOutsidePointerdown(event: PointerEvent) {\n if (!keysRef.value?.contains(event.target as Node)) collapse()\n}\n\nfunction expand() {\n clearTimeout(idle)\n if (expanded.value) return\n expanded.value = true\n document.addEventListener('pointerdown', onOutsidePointerdown, true)\n}\n\nfunction collapse() {\n clearTimeout(idle)\n stopRepeat()\n expanded.value = false\n document.removeEventListener('pointerdown', onOutsidePointerdown, true)\n}\n\n/** The key under a finger at `y`: 1 above the middle, -1 below, 0 on the seam. */\nfunction keyAt(y: number) {\n const box = keysRef.value!.getBoundingClientRect()\n const middle = box.top + box.height / 2\n return Math.abs(y - middle) <= 2 ? 0 : y < middle ? 1 : -1\n}\n\nfunction onKeysPointerdown(event: PointerEvent) {\n if (event.pointerType !== 'touch' || !editable.value) return\n // Keep the keyboard closed and the page still while the finger is down.\n event.preventDefault()\n const keys = event.currentTarget as HTMLElement\n keys.setPointerCapture?.(event.pointerId)\n const opened = !expanded.value\n expand()\n const startY = event.clientY\n let slid = !opened\n let stepped = false\n const follow = (y: number) => {\n slid ||= Math.abs(y - startY) >= SLIDE_THRESHOLD\n const count = slid ? keyAt(y) : 0\n if (count === held.value) return\n stepped ||= count !== 0\n if (count) startRepeat(count)\n else stopRepeat()\n }\n follow(startY)\n const move = (e: PointerEvent) => {\n if (e.pointerId === event.pointerId) follow(e.clientY)\n }\n const end = (e: PointerEvent) => {\n if (e.pointerId !== event.pointerId) return\n stopRepeat()\n keys.removeEventListener('pointermove', move)\n keys.removeEventListener('pointerup', end)\n keys.removeEventListener('pointercancel', end)\n // A press that opened the pad and slid to adjust is done when lifted.\n if (opened && stepped) return collapse()\n clearTimeout(idle)\n idle = setTimeout(collapse, COLLAPSE_DELAY)\n }\n keys.addEventListener('pointermove', move)\n keys.addEventListener('pointerup', end)\n keys.addEventListener('pointercancel', end)\n}\n\nwatch(editable, (value) => value || collapse())\n\nonBeforeUnmount(collapse)\n\nfunction onMousedown(event: MouseEvent) {\n const target = event.target as HTMLElement\n if (target === inputRef.value || target.closest('a, input, select, textarea')) return\n event.preventDefault()\n inputRef.value?.focus()\n}\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(size.value),\n ns.is('disabled', disabled.value),\n ns.is('readonly', readonly.value),\n ns.is('invalid', invalid.value),\n ns.is('controls', props.controls),\n ns.is('expanded', expanded.value),\n attrs.class,\n])\n\ndefineExpose<InputNumberExpose>({\n get input() {\n return inputRef.value\n },\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n increase: (count = 1) => stepBy(count),\n decrease: (count = 1) => stepBy(-count),\n})\n</script>\n\n<template>\n <span :class=\"classes\" :style=\"attrs.style as StyleValue\" @mousedown=\"onMousedown\">\n <span v-if=\"slots.prefix\" :class=\"[ns.e('affix'), ns.e('prefix')]\">\n <slot name=\"prefix\" />\n </span>\n <input\n ref=\"input\"\n v-bind=\"inputAttrs\"\n :class=\"ns.e('native')\"\n type=\"text\"\n :inputmode=\"inputMode\"\n autocomplete=\"off\"\n role=\"spinbutton\"\n :value=\"shown\"\n :placeholder=\"placeholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :aria-valuenow=\"model ?? undefined\"\n :aria-valuetext=\"formatter && model !== null ? formatter(model) : undefined\"\n :aria-valuemin=\"Number.isFinite(min) ? min : undefined\"\n :aria-valuemax=\"Number.isFinite(max) ? max : undefined\"\n :aria-invalid=\"invalid || undefined\"\n @input=\"onInput\"\n @focus=\"focused = true\"\n @blur=\"onBlur\"\n @keydown=\"onKeydown\"\n />\n <button\n v-if=\"showClear\"\n type=\"button\"\n tabindex=\"-1\"\n :class=\"ns.e('clear')\"\n :aria-label=\"t('inputNumber.clear')\"\n @mousedown.prevent\n @click=\"clear\"\n >\n <CloseIcon />\n </button>\n <span v-if=\"slots.suffix\" :class=\"[ns.e('affix'), ns.e('suffix')]\">\n <slot name=\"suffix\" />\n </span>\n <span v-if=\"controls\" :class=\"ns.e('controls')\">\n <span ref=\"keys\" :class=\"ns.e('keys')\" @pointerdown=\"onKeysPointerdown\">\n <button\n type=\"button\"\n tabindex=\"-1\"\n :class=\"[ns.e('step'), ns.e('increase'), ns.is('held', held === 1)]\"\n :aria-label=\"t('inputNumber.increase')\"\n :disabled=\"!canIncrease\"\n @mousedown.prevent\n @pointerdown=\"onStepPointerdown($event, 1)\"\n @pointerleave=\"$event.pointerType === 'touch' || stopRepeat()\"\n @pointercancel=\"stopRepeat\"\n >\n <PlusIcon />\n </button>\n <button\n type=\"button\"\n tabindex=\"-1\"\n :class=\"[ns.e('step'), ns.e('decrease'), ns.is('held', held === -1)]\"\n :aria-label=\"t('inputNumber.decrease')\"\n :disabled=\"!canDecrease\"\n @mousedown.prevent\n @pointerdown=\"onStepPointerdown($event, -1)\"\n @pointerleave=\"$event.pointerType === 'touch' || stopRepeat()\"\n @pointercancel=\"stopRepeat\"\n >\n <MinusIcon />\n </button>\n </span>\n </span>\n </span>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"input-number.js","names":["_sfc_main"],"sources":["../../../src/components/input-number/input-number.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CloseIcon, MinusIcon, PlusIcon } from '@dou-ui/icons'\nimport { computed, onBeforeUnmount, ref, useAttrs, useTemplateRef, watch } from 'vue'\nimport type { HTMLAttributes, StyleValue } from 'vue'\nimport { FieldAffix } from '../../utils/field-action'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { useFormDisabled, useFormItem, useFormReadonly, useFormSize } from '../form/use-form-item'\nimport type { InputNumberExpose, InputNumberProps, InputNumberSlots } from './input-number'\n\ndefineOptions({ name: 'DouInputNumber', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<InputNumberProps>(), {\n min: -Infinity,\n max: Infinity,\n step: 1,\n disabled: false,\n readonly: false,\n invalid: false,\n controls: true,\n clearable: false,\n})\nconst model = defineModel<number | null>({ default: null })\nconst emit = defineEmits<{ change: [value: number | null, oldValue: number | null]; clear: [] }>()\nconst slots = defineSlots<InputNumberSlots>()\n\nconst ns = useNamespace('input-number')\nconst { t, locale } = useLocale()\nconst { formItem } = useFormItem()\nconst size = useFormSize(() => props.size)\nconst disabled = useFormDisabled(() => props.disabled)\nconst readonly = useFormReadonly(() => props.readonly)\nconst invalid = computed(() => props.invalid || !!formItem?.invalid.value)\nconst editable = computed(() => !disabled.value && !readonly.value)\n\nconst attrs = useAttrs()\nconst inputAttrs = computed(() => {\n const { class: _class, style: _style, ...rest } = attrs\n if (!formItem) return rest\n return {\n id: formItem.inputId,\n 'aria-describedby': formItem.describedBy.value,\n 'aria-required': formItem.required.value || undefined,\n ...rest,\n }\n})\n\n// The on-screen keyboard: digits only for whole numbers. The iOS number\n// pads have no minus key, so a range that reaches below zero gets the full\n// keyboard. An `inputmode` attribute overrides this.\nconst inputMode = computed((): HTMLAttributes['inputmode'] => {\n if (typeof attrs.inputmode === 'string') return attrs.inputmode as HTMLAttributes['inputmode']\n if (Number.isFinite(props.min) && props.min < 0) return 'text'\n return props.precision === 0 ? 'numeric' : 'decimal'\n})\n\nconst inputRef = useTemplateRef<HTMLInputElement>('input')\n\nfunction decimals(value: number) {\n const [digits = '', exponent] = String(value).split('e')\n const fraction = digits.split('.')[1]?.length ?? 0\n return Math.max(0, fraction - Number(exponent ?? 0))\n}\n\n// Round through the decimal notation, so 1.005 rounds to 1.01 and\n// 0.1 + 0.2 lands on 0.3.\nfunction round(value: number, places: number) {\n return Number(`${Math.round(Number(`${value}e${places}`))}e-${places}`)\n}\n\nconst clamp = (value: number) => Math.min(Math.max(value, props.min), props.max)\n\nfunction normalize(value: number) {\n return clamp(props.precision === undefined ? value : round(value, props.precision))\n}\n\nfunction format(value: number | null) {\n if (value === null || Number.isNaN(value)) return ''\n return props.precision === undefined ? String(value) : value.toFixed(props.precision)\n}\n\n// How the value reads while the field is not being edited.\nconst formatter = computed(() => {\n const option = props.format\n if (!option) return undefined\n if (typeof option === 'function') return option\n const digits =\n props.precision === undefined\n ? {}\n : { minimumFractionDigits: props.precision, maximumFractionDigits: props.precision }\n const intl = new Intl.NumberFormat(locale.value.name, { ...digits, ...option })\n return (value: number) => intl.format(value)\n})\nconst focused = ref(false)\n\n/** `null` for an empty field, `NaN` for text that is not a number. */\nfunction parse(text: string) {\n const trimmed = text.trim()\n if (trimmed === '') return null\n // Accept the full-width digits and signs an IME may produce.\n const ascii = trimmed\n .replace(/[0-9]/g, (digit) => String(digit.charCodeAt(0) - 0xff10))\n .replace(/[.。]/g, '.')\n .replace(/[-−]/g, '-')\n return /^[+-]?(\\d+\\.?\\d*|\\.\\d+)(e[+-]?\\d+)?$/i.test(ascii) ? Number(ascii) : Number.NaN\n}\n\n// What the field shows. It follows the model, except while the user is\n// typing something that is not a number yet, such as `-` or `1.`.\nconst text = ref(format(model.value))\n// The value as of the last commit, reported as `oldValue` by `change`.\nlet committed = model.value\n\n// A value that does not match the text came from outside, not from typing.\nwatch(model, (value) => {\n if (parse(text.value) === value) return\n text.value = format(value)\n committed = value\n})\n\nfunction commit(value: number | null) {\n model.value = value\n text.value = format(value)\n if (value !== committed) {\n const old = committed\n committed = value\n emit('change', value, old)\n formItem?.trigger('change')\n }\n}\n\nfunction onInput(event: Event) {\n text.value = (event.target as HTMLInputElement).value\n const value = parse(text.value)\n // Only report values that would survive the commit unchanged, so a\n // half-typed number never reaches the model out of range.\n if (value === null || (!Number.isNaN(value) && value === normalize(value))) {\n model.value = value\n formItem?.trigger('change', { lazy: true })\n }\n}\n\nfunction onChange() {\n const value = parse(text.value)\n commit(Number.isNaN(value) ? model.value : value === null ? null : normalize(value))\n}\n\n// The plain text while editing, the formatted value otherwise.\nconst shown = computed(() =>\n focused.value || !formatter.value || model.value === null || Number.isNaN(model.value)\n ? text.value\n : formatter.value(model.value),\n)\n\nfunction onBlur() {\n focused.value = false\n onChange()\n formItem?.trigger('blur')\n}\n\nconst showClear = computed(() => props.clearable && editable.value && model.value !== null)\n\nfunction clear() {\n commit(null)\n emit('clear')\n inputRef.value?.focus()\n}\n\nfunction stepBy(count: number) {\n if (!editable.value) return\n const parsed = parse(text.value)\n const from = parsed === null || Number.isNaN(parsed) ? (model.value ?? 0) : parsed\n const next = round(from + props.step * count, Math.max(decimals(from), decimals(props.step)))\n commit(normalize(next))\n}\n\nconst canIncrease = computed(() => editable.value && (model.value ?? -Infinity) < props.max)\nconst canDecrease = computed(() => editable.value && (model.value ?? Infinity) > props.min)\n\nfunction onKeydown(event: KeyboardEvent) {\n if (!editable.value) return\n const steps: Record<string, number> = { ArrowUp: 1, ArrowDown: -1, PageUp: 10, PageDown: -10 }\n if (event.key in steps) {\n event.preventDefault()\n stepBy(steps[event.key]!)\n } else if (event.key === 'Home' && Number.isFinite(props.min)) {\n event.preventDefault()\n commit(props.min)\n } else if (event.key === 'End' && Number.isFinite(props.max)) {\n event.preventDefault()\n commit(props.max)\n } else if (event.key === 'Enter') {\n onChange()\n }\n}\n\n// Holding a step key repeats the step, slowly at first.\nlet timer: ReturnType<typeof setTimeout> | undefined\n// The key being held: 1 for increase, -1 for decrease, 0 for none.\nconst held = ref(0)\n\nfunction stopRepeat() {\n clearTimeout(timer)\n timer = undefined\n held.value = 0\n}\n\nfunction startRepeat(count: number) {\n stopRepeat()\n if (!(count > 0 ? canIncrease.value : canDecrease.value)) return\n held.value = count\n stepBy(count)\n const repeat = (delay: number) => {\n timer = setTimeout(() => {\n // A key that reaches the limit turns disabled, so stop there.\n if (!(count > 0 ? canIncrease.value : canDecrease.value)) return stopRepeat()\n stepBy(count)\n repeat(50)\n }, delay)\n }\n repeat(400)\n}\n\nfunction onStepPointerdown(event: PointerEvent, count: number) {\n // Touch goes through the key pad below.\n if (event.pointerType === 'touch' || event.button !== 0) return\n startRepeat(count)\n // The pointer may come up over a key that turned disabled, so listen\n // on the window.\n window.addEventListener('pointerup', stopRepeat, { once: true })\n}\n\n// On touch the keys are too small to aim at, so the first press only\n// enlarges them. Keeping the finger down and sliding onto a key steps\n// with it, and the pad shrinks back as soon as that finger lifts. After a\n// plain press the pad stays, later taps step as usual, and it shrinks back\n// after a tap elsewhere or a short pause.\nconst COLLAPSE_DELAY = 2000\n// How far a finger slides from where the pad opened before it counts.\nconst SLIDE_THRESHOLD = 6\n\nconst keysRef = useTemplateRef<HTMLElement>('keys')\nconst expanded = ref(false)\nlet idle: ReturnType<typeof setTimeout> | undefined\n\nfunction onOutsidePointerdown(event: PointerEvent) {\n if (!keysRef.value?.contains(event.target as Node)) collapse()\n}\n\nfunction expand() {\n clearTimeout(idle)\n if (expanded.value) return\n expanded.value = true\n document.addEventListener('pointerdown', onOutsidePointerdown, true)\n}\n\nfunction collapse() {\n clearTimeout(idle)\n stopRepeat()\n expanded.value = false\n document.removeEventListener('pointerdown', onOutsidePointerdown, true)\n}\n\n/** The key under a finger at `y`: 1 above the middle, -1 below, 0 on the seam. */\nfunction keyAt(y: number) {\n const box = keysRef.value!.getBoundingClientRect()\n const middle = box.top + box.height / 2\n return Math.abs(y - middle) <= 2 ? 0 : y < middle ? 1 : -1\n}\n\nfunction onKeysPointerdown(event: PointerEvent) {\n if (event.pointerType !== 'touch' || !editable.value) return\n // Keep the keyboard closed and the page still while the finger is down.\n event.preventDefault()\n const keys = event.currentTarget as HTMLElement\n keys.setPointerCapture?.(event.pointerId)\n const opened = !expanded.value\n expand()\n const startY = event.clientY\n let slid = !opened\n let stepped = false\n const follow = (y: number) => {\n slid ||= Math.abs(y - startY) >= SLIDE_THRESHOLD\n const count = slid ? keyAt(y) : 0\n if (count === held.value) return\n stepped ||= count !== 0\n if (count) startRepeat(count)\n else stopRepeat()\n }\n follow(startY)\n const move = (e: PointerEvent) => {\n if (e.pointerId === event.pointerId) follow(e.clientY)\n }\n const end = (e: PointerEvent) => {\n if (e.pointerId !== event.pointerId) return\n stopRepeat()\n keys.removeEventListener('pointermove', move)\n keys.removeEventListener('pointerup', end)\n keys.removeEventListener('pointercancel', end)\n // A press that opened the pad and slid to adjust is done when lifted.\n if (opened && stepped) return collapse()\n clearTimeout(idle)\n idle = setTimeout(collapse, COLLAPSE_DELAY)\n }\n keys.addEventListener('pointermove', move)\n keys.addEventListener('pointerup', end)\n keys.addEventListener('pointercancel', end)\n}\n\nwatch(editable, (value) => value || collapse())\n\nonBeforeUnmount(collapse)\n\nfunction onMousedown(event: MouseEvent) {\n const target = event.target as HTMLElement\n if (target === inputRef.value || target.closest('a, input, select, textarea')) return\n event.preventDefault()\n inputRef.value?.focus()\n}\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(size.value),\n ns.is('disabled', disabled.value),\n ns.is('readonly', readonly.value),\n ns.is('invalid', invalid.value),\n ns.is('controls', props.controls),\n ns.is('expanded', expanded.value),\n attrs.class,\n])\n\ndefineExpose<InputNumberExpose>({\n get input() {\n return inputRef.value\n },\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n increase: (count = 1) => stepBy(count),\n decrease: (count = 1) => stepBy(-count),\n})\n</script>\n\n<template>\n <span :class=\"classes\" :style=\"attrs.style as StyleValue\" @mousedown=\"onMousedown\">\n <FieldAffix\n v-if=\"slots.prefix\"\n side=\"start\"\n :class=\"[ns.e('affix'), ns.e('prefix')]\"\n :disabled=\"disabled\"\n :render=\"slots.prefix\"\n />\n <input\n ref=\"input\"\n v-bind=\"inputAttrs\"\n :class=\"ns.e('native')\"\n type=\"text\"\n :inputmode=\"inputMode\"\n autocomplete=\"off\"\n role=\"spinbutton\"\n :value=\"shown\"\n :placeholder=\"placeholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :aria-valuenow=\"model ?? undefined\"\n :aria-valuetext=\"formatter && model !== null ? formatter(model) : undefined\"\n :aria-valuemin=\"Number.isFinite(min) ? min : undefined\"\n :aria-valuemax=\"Number.isFinite(max) ? max : undefined\"\n :aria-invalid=\"invalid || undefined\"\n @input=\"onInput\"\n @focus=\"focused = true\"\n @blur=\"onBlur\"\n @keydown=\"onKeydown\"\n />\n <button\n v-if=\"showClear\"\n type=\"button\"\n tabindex=\"-1\"\n :class=\"ns.e('clear')\"\n :aria-label=\"t('inputNumber.clear')\"\n @mousedown.prevent\n @click=\"clear\"\n >\n <CloseIcon />\n </button>\n <FieldAffix\n v-if=\"slots.suffix\"\n side=\"end\"\n :class=\"[ns.e('affix'), ns.e('suffix')]\"\n :disabled=\"disabled\"\n :render=\"slots.suffix\"\n />\n <span v-if=\"controls\" :class=\"ns.e('controls')\">\n <span ref=\"keys\" :class=\"ns.e('keys')\" @pointerdown=\"onKeysPointerdown\">\n <button\n type=\"button\"\n tabindex=\"-1\"\n :class=\"[ns.e('step'), ns.e('increase'), ns.is('held', held === 1)]\"\n :aria-label=\"t('inputNumber.increase')\"\n :disabled=\"!canIncrease\"\n @mousedown.prevent\n @pointerdown=\"onStepPointerdown($event, 1)\"\n @pointerleave=\"$event.pointerType === 'touch' || stopRepeat()\"\n @pointercancel=\"stopRepeat\"\n >\n <PlusIcon />\n </button>\n <button\n type=\"button\"\n tabindex=\"-1\"\n :class=\"[ns.e('step'), ns.e('decrease'), ns.is('held', held === -1)]\"\n :aria-label=\"t('inputNumber.decrease')\"\n :disabled=\"!canDecrease\"\n @mousedown.prevent\n @pointerdown=\"onStepPointerdown($event, -1)\"\n @pointerleave=\"$event.pointerType === 'touch' || stopRepeat()\"\n @pointercancel=\"stopRepeat\"\n >\n <MinusIcon />\n </button>\n </span>\n </span>\n </span>\n</template>\n"],"mappings":""}
@@ -1,7 +1,8 @@
1
1
  import { useNamespace } from "../../utils/namespace.js";
2
2
  import { useLocale } from "../config-provider/use-config.js";
3
3
  import { useFormDisabled, useFormItem, useFormReadonly, useFormSize } from "../form/use-form-item.js";
4
- import { computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, mergeModels, mergeProps, normalizeClass, normalizeStyle, onBeforeUnmount, openBlock, ref, renderSlot, unref, useAttrs, useModel, useSlots, useTemplateRef, watch, withModifiers } from "vue";
4
+ import { FieldAffix } from "../../utils/field-action.js";
5
+ import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, mergeModels, mergeProps, normalizeClass, normalizeStyle, onBeforeUnmount, openBlock, ref, unref, useAttrs, useModel, useSlots, useTemplateRef, watch, withModifiers } from "vue";
5
6
  import { CloseIcon, MinusIcon, PlusIcon } from "@dou-ui/icons";
6
7
  // src/components/input-number/input-number.vue?vue&type=script&setup=true&lang.ts
7
8
  var _hoisted_1 = [
@@ -314,10 +315,17 @@ var input_number_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
314
315
  style: normalizeStyle(unref(attrs).style),
315
316
  onMousedown
316
317
  }, [
317
- slots.prefix ? (openBlock(), createElementBlock("span", {
318
+ slots.prefix ? (openBlock(), createBlock(unref(FieldAffix), {
318
319
  key: 0,
319
- class: normalizeClass([unref(ns).e("affix"), unref(ns).e("prefix")])
320
- }, [renderSlot(_ctx.$slots, "prefix")], 2)) : createCommentVNode("", true),
320
+ side: "start",
321
+ class: normalizeClass([unref(ns).e("affix"), unref(ns).e("prefix")]),
322
+ disabled: unref(disabled),
323
+ render: slots.prefix
324
+ }, null, 8, [
325
+ "class",
326
+ "disabled",
327
+ "render"
328
+ ])) : createCommentVNode("", true),
321
329
  createElementVNode("input", mergeProps({ ref: "input" }, inputAttrs.value, {
322
330
  class: unref(ns).e("native"),
323
331
  type: "text",
@@ -347,10 +355,17 @@ var input_number_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
347
355
  onMousedown: _cache[1] || (_cache[1] = withModifiers(() => {}, ["prevent"])),
348
356
  onClick: clear
349
357
  }, [createVNode(unref(CloseIcon))], 42, _hoisted_2)) : createCommentVNode("", true),
350
- slots.suffix ? (openBlock(), createElementBlock("span", {
358
+ slots.suffix ? (openBlock(), createBlock(unref(FieldAffix), {
351
359
  key: 2,
352
- class: normalizeClass([unref(ns).e("affix"), unref(ns).e("suffix")])
353
- }, [renderSlot(_ctx.$slots, "suffix")], 2)) : createCommentVNode("", true),
360
+ side: "end",
361
+ class: normalizeClass([unref(ns).e("affix"), unref(ns).e("suffix")]),
362
+ disabled: unref(disabled),
363
+ render: slots.suffix
364
+ }, null, 8, [
365
+ "class",
366
+ "disabled",
367
+ "render"
368
+ ])) : createCommentVNode("", true),
354
369
  __props.controls ? (openBlock(), createElementBlock("span", {
355
370
  key: 3,
356
371
  class: normalizeClass(unref(ns).e("controls"))