@veltra/desktop 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/action/action-group.vue.d.ts +3 -3
- package/dist/components/action/action.vue.d.ts +2 -2
- package/dist/components/auto-complete/auto-complete.js +1 -2
- package/dist/components/auto-complete/auto-complete.js.map +1 -1
- package/dist/components/auto-complete/auto-complete.vue.d.ts +2 -2
- package/dist/components/cascade/cascade.js +1 -2
- package/dist/components/cascade/cascade.js.map +1 -1
- package/dist/components/cascade/cascade.vue.d.ts +5 -5
- package/dist/components/checkbox/checkbox-button.js +1 -2
- package/dist/components/checkbox/checkbox-button.js.map +1 -1
- package/dist/components/checkbox/checkbox.js +1 -2
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/checkbox-group/checkbox-group.js +1 -2
- package/dist/components/checkbox-group/checkbox-group.js.map +1 -1
- package/dist/components/code-editor/code-editor.js +1 -2
- package/dist/components/code-editor/code-editor.js.map +1 -1
- package/dist/components/date-panel/date-panel.vue.d.ts +1 -1
- package/dist/components/date-picker/date-picker.js +1 -2
- package/dist/components/date-picker/date-picker.js.map +1 -1
- package/dist/components/date-picker/date-picker.vue.d.ts +2 -2
- package/dist/components/date-range-picker/date-range-picker.js +1 -2
- package/dist/components/date-range-picker/date-range-picker.js.map +1 -1
- package/dist/components/date-range-picker/date-range-picker.vue.d.ts +2 -2
- package/dist/components/dialog/style2.css +1 -1
- package/dist/components/expression-editor/expression-editor.js +1 -2
- package/dist/components/expression-editor/expression-editor.js.map +1 -1
- package/dist/components/form/form.js.map +1 -1
- package/dist/components/form/form.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/components/form/form.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/form-item/form-item.js.map +1 -1
- package/dist/components/form-item/form-item.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/components/form-item/form-item.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/group-input/group-input.js +1 -2
- package/dist/components/group-input/group-input.js.map +1 -1
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/input/input.vue.d.ts +4 -4
- package/dist/components/input/input.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/components/input/input.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/multi-select/multi-select.js +1 -2
- package/dist/components/multi-select/multi-select.js.map +1 -1
- package/dist/components/multi-select/multi-select.vue.d.ts +4 -4
- package/dist/components/multi-tree-select/multi-tree-select.js +1 -2
- package/dist/components/multi-tree-select/multi-tree-select.js.map +1 -1
- package/dist/components/multi-tree-select/multi-tree-select.vue.d.ts +6 -6
- package/dist/components/notification/notification.vue.d.ts +1 -1
- package/dist/components/number/number.vue.d.ts +1 -1
- package/dist/components/number-input/number-input.js +1 -2
- package/dist/components/number-input/number-input.js.map +1 -1
- package/dist/components/number-input/number-input.vue.d.ts +4 -4
- package/dist/components/number-range-input/number-range-input.js +1 -2
- package/dist/components/number-range-input/number-range-input.js.map +1 -1
- package/dist/components/number-range-input/number-range-input.vue.d.ts +1 -1
- package/dist/components/palette/palette.js +1 -2
- package/dist/components/palette/palette.js.map +1 -1
- package/dist/components/password-input/password-input.js +1 -2
- package/dist/components/password-input/password-input.js.map +1 -1
- package/dist/components/password-input/password-input.vue.d.ts +1 -1
- package/dist/components/pop-confirm/pop-confirm.js +1 -2
- package/dist/components/pop-confirm/pop-confirm.js.map +1 -1
- package/dist/components/pop-confirm/pop-confirm.vue.d.ts +2 -2
- package/dist/components/radio/radio.js +1 -2
- package/dist/components/radio/radio.js.map +1 -1
- package/dist/components/radio-group/radio-group.js +1 -2
- package/dist/components/radio-group/radio-group.js.map +1 -1
- package/dist/components/rich-text-editor/rich-text-editor.js +1 -2
- package/dist/components/rich-text-editor/rich-text-editor.js.map +1 -1
- package/dist/components/rich-text-editor/rich-text-editor.vue.d.ts +1 -1
- package/dist/components/select/select.js +1 -2
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/select/select.vue.d.ts +2 -2
- package/dist/components/slider/slider.js +1 -2
- package/dist/components/slider/slider.js.map +1 -1
- package/dist/components/switch/switch.js +1 -2
- package/dist/components/switch/switch.js.map +1 -1
- package/dist/components/tabs/tabs-horizontal.vue.d.ts +3 -3
- package/dist/components/tabs/tabs-vertical.vue.d.ts +3 -3
- package/dist/components/tabs/tabs.vue.d.ts +3 -3
- package/dist/components/tag/tag.js +1 -2
- package/dist/components/tag/tag.js.map +1 -1
- package/dist/components/textarea/textarea.js +1 -2
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/textarea/textarea.vue.d.ts +4 -4
- package/dist/components/tip/tip.vue.d.ts +1 -1
- package/dist/components/tree/tree.js +1 -2
- package/dist/components/tree/tree.js.map +1 -1
- package/dist/components/tree-select/tree-select.js +1 -2
- package/dist/components/tree-select/tree-select.js.map +1 -1
- package/dist/components/tree-select/tree-select.vue.d.ts +6 -6
- package/package.json +11 -11
- package/src/components/auto-complete/auto-complete.vue +1 -1
- package/src/components/cascade/cascade.vue +1 -1
- package/src/components/checkbox/checkbox-button.vue +1 -1
- package/src/components/checkbox/checkbox.vue +1 -1
- package/src/components/checkbox-group/checkbox-group.vue +1 -1
- package/src/components/code-editor/code-editor.vue +1 -1
- package/src/components/date-picker/date-picker.vue +1 -1
- package/src/components/date-range-picker/date-range-picker.vue +1 -1
- package/src/components/dialog/style.scss +1 -1
- package/src/components/expression-editor/expression-editor.vue +1 -1
- package/src/components/form/form.vue +1 -1
- package/src/components/form-item/form-item.vue +1 -1
- package/src/components/group-input/group-input.vue +1 -1
- package/src/components/input/input.vue +1 -1
- package/src/components/multi-select/multi-select.vue +1 -1
- package/src/components/multi-tree-select/multi-tree-select.vue +1 -1
- package/src/components/number-input/number-input.vue +1 -1
- package/src/components/number-range-input/number-range-input.vue +1 -1
- package/src/components/palette/palette.vue +1 -1
- package/src/components/password-input/password-input.vue +1 -1
- package/src/components/pop-confirm/pop-confirm.vue +1 -1
- package/src/components/radio/radio.vue +1 -1
- package/src/components/radio-group/radio-group.vue +1 -1
- package/src/components/rich-text-editor/rich-text-editor.vue +1 -1
- package/src/components/select/select.vue +1 -1
- package/src/components/slider/slider.vue +1 -1
- package/src/components/switch/switch.vue +1 -1
- package/src/components/tag/tag.vue +1 -1
- package/src/components/textarea/textarea.vue +1 -1
- package/src/components/tree/tree.vue +1 -1
- package/src/components/tree-select/tree-select.vue +1 -1
- package/dist/utils/form-context.js +0 -17
- package/dist/utils/form-context.js.map +0 -1
- package/src/utils/form-context.ts +0 -24
|
@@ -15,23 +15,23 @@ declare const __VLS_base: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {}, {
|
|
|
15
15
|
"update:modelValue": (value: (string | number)[]) => any;
|
|
16
16
|
} & {
|
|
17
17
|
"update:modelValue": (value: any[]) => any;
|
|
18
|
-
clear: () => any;
|
|
19
18
|
change: (checked: Record<string, any>[]) => any;
|
|
19
|
+
clear: () => any;
|
|
20
20
|
}, string, _$vue.PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
21
21
|
"onUpdate:modelValue"?: ((value: any[]) => any) | undefined;
|
|
22
|
-
onClear?: (() => any) | undefined;
|
|
23
22
|
onChange?: ((checked: Record<string, any>[]) => any) | undefined;
|
|
23
|
+
onClear?: (() => any) | undefined;
|
|
24
24
|
}>, {
|
|
25
25
|
expandAll: boolean;
|
|
26
26
|
labelKey: string;
|
|
27
27
|
valueKey: string;
|
|
28
|
-
disabled: boolean;
|
|
29
|
-
readonly: boolean;
|
|
30
|
-
minWidth: string;
|
|
31
|
-
placeholder: string;
|
|
32
28
|
clearable: boolean;
|
|
29
|
+
placeholder: string;
|
|
33
30
|
filterable: boolean;
|
|
34
31
|
visibilityLimit: number;
|
|
32
|
+
minWidth: string;
|
|
33
|
+
disabled: boolean;
|
|
34
|
+
readonly: boolean;
|
|
35
35
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
36
36
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
37
37
|
declare const _default: typeof __VLS_export;
|
|
@@ -5,10 +5,10 @@ import * as _$_veltra_utils0 from "@veltra/utils";
|
|
|
5
5
|
//#region src/components/notification/notification.vue.d.ts
|
|
6
6
|
declare const __VLS_export: _$vue.DefineComponent<NotificationProps, _$_veltra_utils0.DeconstructValue<_NotificationExposed>, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<NotificationProps> & Readonly<{}>, {
|
|
7
7
|
closable: boolean;
|
|
8
|
-
position: "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
9
8
|
duration: number;
|
|
10
9
|
offset: number;
|
|
11
10
|
buttonText: string;
|
|
11
|
+
position: "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
12
12
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
13
13
|
declare const _default: typeof __VLS_export;
|
|
14
14
|
//#endregion
|
|
@@ -3,8 +3,8 @@ import * as _$vue from "vue";
|
|
|
3
3
|
|
|
4
4
|
//#region src/components/number/number.vue.d.ts
|
|
5
5
|
declare const __VLS_export: _$vue.DefineComponent<NumberProps, {}, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<NumberProps> & Readonly<{}>, {
|
|
6
|
-
format: "currency" | "percent" | "decimal";
|
|
7
6
|
duration: number;
|
|
7
|
+
format: "currency" | "percent" | "decimal";
|
|
8
8
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
9
9
|
declare const _default: typeof __VLS_export;
|
|
10
10
|
//#endregion
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import _sfc_main$1 from "../icon/icon.js";
|
|
2
|
-
import { injectFormContext } from "../../utils/form-context.js";
|
|
3
2
|
import input_default from "../input/input.js";
|
|
4
3
|
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, mergeModels, mergeProps, normalizeClass, openBlock, renderSlot, shallowRef, toDisplayString, unref, useModel, useSlots, watch, withCtx, withDirectives, withModifiers } from "vue";
|
|
5
|
-
import { FORM_EMPTY_CONTENT, Tween, bem } from "@veltra/utils";
|
|
4
|
+
import { FORM_EMPTY_CONTENT, Tween, bem, injectFormContext } from "@veltra/utils";
|
|
6
5
|
import { useFormFallbackProps } from "@veltra/compositions";
|
|
7
6
|
import { $n, isUndef, n, o } from "@cat-kit/core";
|
|
8
7
|
import { ArrowDown, ArrowUp, Close } from "@veltra/icons/normal";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-input.js","names":[],"sources":["../../../src/components/number-input/number-input.vue"],"sourcesContent":["<template>\n <u-input\n v-if=\"!readonly\"\n ref=\"inputRef\"\n :class=\"className\"\n :model-value=\"displayed\"\n v-bind=\"inputProps\"\n @update:model-value=\"handleUpdateModelValue\"\n @change=\"handleChange\"\n @keydown.stop=\"handleKeydown\"\n @focus=\"handleFocus\"\n @blur=\"handleBlur\"\n @mouseenter=\"handleMouseEnter\"\n @mouseleave=\"handleMouseLeave\"\n :size=\"size\"\n :readonly=\"readonly\"\n :disabled=\"disabled\"\n :clearable=\"false\"\n >\n <template #suffix v-if=\"hasSuffix\">\n <span :class=\"cls.e('suffix')\">\n <u-icon\n v-if=\"props.clearable\"\n :class=\"[cls.e('clear'), bem.is('hidden', !showClear)]\"\n :title=\"showClear ? '清除' : undefined\"\n @click.stop=\"handleClear\"\n >\n <Close />\n </u-icon>\n <span v-if=\"hasCustomSuffix\" :class=\"cls.e('suffix-content')\">\n {{ suffix }}\n <slot name=\"suffix\" />\n </span>\n </span>\n\n <div v-if=\"showStep\" :class=\"cls.e('step')\">\n <u-icon\n @click=\"increase\"\n v-ripple=\"!disabled && increasable\"\n :class=\"bem.is('disabled', disabled || !increasable)\"\n >\n <ArrowUp />\n </u-icon>\n <u-icon\n @click=\"decrease\"\n v-ripple=\"!disabled && reducible\"\n :class=\"bem.is('disabled', disabled || !reducible)\"\n >\n <ArrowDown />\n </u-icon>\n </div>\n </template>\n\n <template #prefix v-if=\"slots.prefix\">\n <slot name=\"prefix\" />\n </template>\n </u-input>\n\n <template v-else>\n {{ generateDisplayed || FORM_EMPTY_CONTENT }}\n </template>\n</template>\n\n<script lang=\"ts\" setup>\nimport { $n, n, o, isUndef } from '@cat-kit/core'\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { vRipple } from '@veltra/directives'\nimport { ArrowDown, ArrowUp, Close } from '@veltra/icons/normal'\nimport { bem, FORM_EMPTY_CONTENT, Tween } from '@veltra/utils'\nimport { computed, shallowRef, watch } from 'vue'\n\nimport type { NumberInputEmits, NumberInputProps, InputExposed } from '../../types'\nimport { injectFormContext } from '../../utils/form-context'\nimport { UIcon } from '../icon'\nimport { UInput } from '../input'\n\ndefineOptions({\n name: 'NumberInput'\n})\n\nconst props = withDefaults(defineProps<NumberInputProps>(), {\n placeholder: '请输入',\n clearable: true,\n disabled: undefined,\n readonly: undefined\n})\nconst emit = defineEmits<NumberInputEmits>()\n\nconst slots = defineSlots<{\n prefix?: () => any\n suffix?: () => any\n}>()\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {\n size: 'default',\n disabled: false,\n readonly: false\n})\n\nconst inputProps = computed(() => {\n return o(props).pick(['disabled', 'placeholder', 'size', 'prefix'])\n})\n\nconst inputRef = shallowRef<InputExposed>()\n\nconst inputDom = computed(() => inputRef.value?.el)\n\nconst cls = bem('number-input')\n\nconst className = computed(() => {\n return [cls.b, cls.m(size.value)]\n})\n\n/** 实际值 */\nconst model = defineModel<NumberInputProps['modelValue']>()\n\n// 展示值\nconst displayed = shallowRef('')\n\nconst focused = shallowRef(false)\nconst hovered = shallowRef(false)\n\nconst generateDisplayed = computed(() => {\n if (!displayed.value) return ''\n\n return `${props.prefix ?? ''}${displayed.value}${props.suffix ?? ''}`\n})\n\nconst showStep = computed(() => props.step !== undefined && props.step !== false)\n\nconst hasCustomSuffix = computed(() => !!props.suffix || !!slots.suffix)\n\nconst hasSuffix = computed(() => props.clearable || hasCustomSuffix.value || showStep.value)\n\nconst showClear = computed(() => {\n return props.clearable && !disabled.value && displayed.value !== '' && hovered.value\n})\n\n/** 步长 */\nconst stepVal = computed<number>(() => {\n const { step } = props\n if (step === undefined) return 1\n return typeof step === 'boolean' ? 1 : step\n})\n\n/** 是否可增 */\nconst increasable = computed(() => {\n const { max, multiple } = props\n if (isUndef(max) || isUndef(model.value)) return true\n // 如果存在倍数,先将 model.value 除以倍数得到原始值再比较\n const rawValue = multiple ? $n.div(model.value, multiple) : model.value\n return rawValue < max\n})\n\n/** 是否可减 */\nconst reducible = computed(() => {\n const { min, multiple } = props\n if (isUndef(min) || isUndef(model.value)) return true\n // 如果存在倍数,先将 model.value 除以倍数得到原始值再比较\n const rawValue = multiple ? $n.div(model.value, multiple) : model.value\n return rawValue > min\n})\n\n// 通过值和步长值计算默认的最大精度\nconst defaultMaxPrecision = computed(() => {\n const { multiple } = props\n // 如果存在倍数,基于原始值计算精度\n const rawValue =\n multiple && model.value !== undefined ? $n.div(model.value, multiple) : model.value\n return Math.max(\n String(rawValue).split('.')[1]?.length ?? 0,\n String(stepVal.value).split('.')[1]?.length ?? 0\n )\n})\n\n/**\n * 获取展示值\n * @param num 实际值\n */\nfunction getDisplayed(num?: number): string {\n if (!num && num !== 0) return ''\n\n const {\n currency,\n precision,\n minPrecision,\n // 如果没有指定最大精度那么设置默认为值和步长值中的较大值\n maxPrecision = defaultMaxPrecision.value,\n multiple\n } = props\n\n // 如果存在倍数,先将实际值除以倍数得到原始值\n const displayValue = multiple ? $n.div(num, multiple) : num\n\n return currency\n ? n(displayValue).currency('CNY', {\n precision,\n minPrecision,\n maxPrecision\n })\n : n(displayValue).fixed(\n precision ?? {\n minPrecision,\n maxPrecision\n }\n )\n}\n\nwatch(\n [model, focused, () => props.currency],\n ([modelValue, inputFocused]) => {\n if (inputFocused) return\n displayed.value = getDisplayed(modelValue)\n },\n { immediate: true }\n)\n\n/**\n * 解析展示值\n * @param str 展示值\n */\nfunction parseDisplayed(str: string): number | undefined {\n if (!str) return undefined\n\n // 将货币格式去掉再转化为数字\n const number = +str.replace(/,/g, '')\n const { multiple } = props\n\n // 如果解析失败,使用当前值作为回退\n // 如果存在倍数,需要先将 model.value 除以倍数得到原始值\n let result: number | undefined\n if (isNaN(number)) {\n if (model.value === undefined) return undefined\n result = multiple ? $n.div(model.value, multiple) : model.value\n } else {\n result = number\n }\n\n if (result === undefined) return undefined\n\n const { precision, maxPrecision, minPrecision } = props\n\n const fixedResult = +n(result).fixed(\n precision ?? {\n minPrecision,\n maxPrecision\n }\n )\n\n // 如果存在倍数,将原始值乘以倍数返回实际值\n return multiple ? $n.mul(fixedResult, multiple) : fixedResult\n}\n\n/**\n * 获取有效值\n * @param val 值\n */\nfunction getValidValue<T extends undefined | number>(val: T): T {\n if (val === undefined) return val\n const { min, max, multiple } = props\n\n // 如果存在倍数,先将值除以倍数得到原始值进行验证,验证后再乘以倍数\n if (multiple) {\n const rawVal = $n.div(val, multiple)\n let validRawVal = rawVal\n if (min !== undefined && rawVal < min) validRawVal = min\n if (max !== undefined && rawVal > max) validRawVal = max\n return $n.mul(validRawVal, multiple) as T\n }\n\n if (min !== undefined && val < min) return min as T\n if (max !== undefined && val > max) return max as T\n return val\n}\n\nfunction handleUpdateModelValue(input: string): void {\n const newVal = parseDisplayed(input)\n model.value = getValidValue(newVal)\n displayed.value = input\n}\n\nfunction handleClear(): void {\n if (!showClear.value) return\n model.value = undefined\n displayed.value = ''\n emit('clear')\n}\n\n/**\n * 处理输入值变化的函数, 该函数仅在输入框失去焦点时触发,\n * 主要用于在输入非数字的情况下的修正处理\n * @param input 输入的值\n */\nfunction handleChange() {\n emit('change', model.value)\n}\n\nconst tween = new Tween(\n { n: model.value ?? 0 },\n {\n onUpdate(state) {\n const _rawInput = inputDom.value\n if (!_rawInput) return\n const { multiple } = props\n // 如果存在倍数,tween.state.n 存储的是原始值,需要乘以倍数后传给 getDisplayed\n const actualValue = multiple ? $n.mul(state.n, multiple) : state.n\n _rawInput.value = getDisplayed(actualValue)\n },\n // 动画进行的过程值有可能被改变, 因此在onComplete中确保还原的是原本的值\n onComplete() {\n const _rawInput = inputDom.value\n if (!_rawInput) return\n _rawInput.value = getDisplayed(model.value)\n }\n }\n)\n\n/** 增 */\nfunction increase(): void {\n if (disabled.value) return\n const { multiple } = props\n const val = model.value ?? 0\n\n if (multiple) {\n // 如果存在倍数,先将实际值除以倍数得到原始值\n const rawVal = $n.div(val, multiple)\n // 在原始值基础上加步长\n const newRawVal = $n.plus(rawVal, stepVal.value)\n // 乘以倍数得到新的实际值\n const newVal = $n.mul(newRawVal, multiple)\n const target = getValidValue(newVal)\n model.value = target\n // tween 动画在原始值上进行\n tween.state.n = $n.div(target, multiple)\n tween.to({ n: $n.div(target, multiple) })\n } else {\n tween.state.n = val\n const target = getValidValue($n.plus(val, stepVal.value))\n model.value = target\n tween.to({ n: target })\n }\n}\n\n/** 减 */\nfunction decrease(): void {\n if (disabled.value) return\n const { multiple } = props\n const val = model.value ?? 0\n\n if (multiple) {\n // 如果存在倍数,先将实际值除以倍数得到原始值\n const rawVal = $n.div(val, multiple)\n // 在原始值基础上减步长\n const newRawVal = $n.minus(rawVal, stepVal.value)\n // 乘以倍数得到新的实际值\n const newVal = $n.mul(newRawVal, multiple)\n const target = getValidValue(newVal)\n model.value = target\n // tween 动画在原始值上进行\n tween.state.n = $n.div(target, multiple)\n tween.to({ n: $n.div(target, multiple) })\n } else {\n tween.state.n = val\n const target = getValidValue($n.minus(val, stepVal.value))\n model.value = target\n tween.to({ n: target })\n }\n}\n\nfunction handleKeydown(e: KeyboardEvent): void {\n if (!props.step) return\n if (e.key === 'ArrowUp') {\n e.preventDefault()\n return increase()\n }\n if (e.key === 'ArrowDown') {\n e.preventDefault()\n return decrease()\n }\n}\n\nfunction handleFocus(): void {\n focused.value = true\n\n // 如果初始值和当前设置的精度不匹配则进行精度修正\n if (model.value === undefined) return\n const { precision, maxPrecision, minPrecision, multiple } = props\n\n if (multiple) {\n // 如果存在倍数,先除以倍数得到原始值进行精度修正,再乘以倍数\n const rawVal = $n.div(model.value, multiple)\n const fixedRawVal = +n(rawVal).fixed(\n precision ?? {\n maxPrecision,\n minPrecision\n }\n )\n model.value = $n.mul(fixedRawVal, multiple)\n } else {\n model.value = +n(model.value).fixed(\n precision ?? {\n maxPrecision,\n minPrecision\n }\n )\n }\n}\n\nfunction handleBlur(): void {\n focused.value = false\n model.value = props.modelValue\n}\n\nfunction handleMouseEnter(): void {\n hovered.value = true\n}\n\nfunction handleMouseLeave(): void {\n hovered.value = false\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgFA,MAAM,QAAQ;EAMd,MAAM,OAAO;EAEb,MAAM,QAAQ,UAAA;EAKd,MAAM,EAAE,cAAc,mBAAkB;EAExC,MAAM,EAAE,MAAM,UAAU,aAAa,qBAAqB,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE;GAClF,MAAM;GACN,UAAU;GACV,UAAU;GACX,CAAA;EAED,MAAM,aAAa,eAAe;AAChC,UAAO,EAAE,MAAM,CAAC,KAAK;IAAC;IAAY;IAAe;IAAQ;IAAS,CAAA;IACnE;EAED,MAAM,WAAW,YAAyB;EAE1C,MAAM,WAAW,eAAe,SAAS,OAAO,GAAE;EAElD,MAAM,MAAM,IAAI,eAAc;EAE9B,MAAM,YAAY,eAAe;AAC/B,UAAO,CAAC,IAAI,GAAG,IAAI,EAAE,KAAK,MAAM,CAAA;IACjC;;EAGD,MAAM,QAAQ,SAA2C,SAAA,aAAC;EAG1D,MAAM,YAAY,WAAW,GAAE;EAE/B,MAAM,UAAU,WAAW,MAAK;EAChC,MAAM,UAAU,WAAW,MAAK;EAEhC,MAAM,oBAAoB,eAAe;AACv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,CAAC,EAAC,OAAA,CAAA;qCAChC,YAMS,MAAA,YAAA,EAAA;KALN,SAAO;KAEP,OAAK,eAAE,MAAA,IAAG,CAAC,GAAE,YAAa,MAAA,SAAQ,IAAA,CAAK,YAAA,MAAW,CAAA;;4BAExC,CAAX,YAAW,MAAA,QAAA,CAAA,CAAA,CAAA;;0CAHA,MAAA,SAAQ,IAAI,YAAA,MAAW,CAAA,CAAA,EAAA,gBAAA,WAAA,EAKpC,YAMS,MAAA,YAAA,EAAA;KALN,SAAO;KAEP,OAAK,eAAE,MAAA,IAAG,CAAC,GAAE,YAAa,MAAA,SAAQ,IAAA,CAAK,UAAA,MAAS,CAAA;;4BAEpC,CAAb,YAAa,MAAA,UAAA,CAAA,CAAA,CAAA;;0CAHF,MAAA,SAAQ,IAAI,UAAA,MAAS,CAAA,CAAA,CAAA,EAAA,EAAA,IAAA,mBAAA,QAAA,KAAA,CAAA,CAAA;;eAQd,MAAM,SAAA;UAAnB;sBACa,CAAtB,WAAsB,KAAA,QAAA,SAAA,CAAA,CAAA;;;;;;;;uBAI1B,mBAEW,UAAA,EAAA,KAAA,GAAA,EAAA,CAAA,gBAAA,gBADN,kBAAA,SAAqB,MAAA,mBAAkB,CAAA,EAAA,EAAA,CAAA,EAAA,GAAA"}
|
|
1
|
+
{"version":3,"file":"number-input.js","names":[],"sources":["../../../src/components/number-input/number-input.vue"],"sourcesContent":["<template>\n <u-input\n v-if=\"!readonly\"\n ref=\"inputRef\"\n :class=\"className\"\n :model-value=\"displayed\"\n v-bind=\"inputProps\"\n @update:model-value=\"handleUpdateModelValue\"\n @change=\"handleChange\"\n @keydown.stop=\"handleKeydown\"\n @focus=\"handleFocus\"\n @blur=\"handleBlur\"\n @mouseenter=\"handleMouseEnter\"\n @mouseleave=\"handleMouseLeave\"\n :size=\"size\"\n :readonly=\"readonly\"\n :disabled=\"disabled\"\n :clearable=\"false\"\n >\n <template #suffix v-if=\"hasSuffix\">\n <span :class=\"cls.e('suffix')\">\n <u-icon\n v-if=\"props.clearable\"\n :class=\"[cls.e('clear'), bem.is('hidden', !showClear)]\"\n :title=\"showClear ? '清除' : undefined\"\n @click.stop=\"handleClear\"\n >\n <Close />\n </u-icon>\n <span v-if=\"hasCustomSuffix\" :class=\"cls.e('suffix-content')\">\n {{ suffix }}\n <slot name=\"suffix\" />\n </span>\n </span>\n\n <div v-if=\"showStep\" :class=\"cls.e('step')\">\n <u-icon\n @click=\"increase\"\n v-ripple=\"!disabled && increasable\"\n :class=\"bem.is('disabled', disabled || !increasable)\"\n >\n <ArrowUp />\n </u-icon>\n <u-icon\n @click=\"decrease\"\n v-ripple=\"!disabled && reducible\"\n :class=\"bem.is('disabled', disabled || !reducible)\"\n >\n <ArrowDown />\n </u-icon>\n </div>\n </template>\n\n <template #prefix v-if=\"slots.prefix\">\n <slot name=\"prefix\" />\n </template>\n </u-input>\n\n <template v-else>\n {{ generateDisplayed || FORM_EMPTY_CONTENT }}\n </template>\n</template>\n\n<script lang=\"ts\" setup>\nimport { $n, n, o, isUndef } from '@cat-kit/core'\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { vRipple } from '@veltra/directives'\nimport { ArrowDown, ArrowUp, Close } from '@veltra/icons/normal'\nimport { bem, FORM_EMPTY_CONTENT, Tween } from '@veltra/utils'\nimport { injectFormContext } from '@veltra/utils'\nimport { computed, shallowRef, watch } from 'vue'\n\nimport type { NumberInputEmits, NumberInputProps, InputExposed } from '../../types'\nimport { UIcon } from '../icon'\nimport { UInput } from '../input'\n\ndefineOptions({\n name: 'NumberInput'\n})\n\nconst props = withDefaults(defineProps<NumberInputProps>(), {\n placeholder: '请输入',\n clearable: true,\n disabled: undefined,\n readonly: undefined\n})\nconst emit = defineEmits<NumberInputEmits>()\n\nconst slots = defineSlots<{\n prefix?: () => any\n suffix?: () => any\n}>()\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {\n size: 'default',\n disabled: false,\n readonly: false\n})\n\nconst inputProps = computed(() => {\n return o(props).pick(['disabled', 'placeholder', 'size', 'prefix'])\n})\n\nconst inputRef = shallowRef<InputExposed>()\n\nconst inputDom = computed(() => inputRef.value?.el)\n\nconst cls = bem('number-input')\n\nconst className = computed(() => {\n return [cls.b, cls.m(size.value)]\n})\n\n/** 实际值 */\nconst model = defineModel<NumberInputProps['modelValue']>()\n\n// 展示值\nconst displayed = shallowRef('')\n\nconst focused = shallowRef(false)\nconst hovered = shallowRef(false)\n\nconst generateDisplayed = computed(() => {\n if (!displayed.value) return ''\n\n return `${props.prefix ?? ''}${displayed.value}${props.suffix ?? ''}`\n})\n\nconst showStep = computed(() => props.step !== undefined && props.step !== false)\n\nconst hasCustomSuffix = computed(() => !!props.suffix || !!slots.suffix)\n\nconst hasSuffix = computed(() => props.clearable || hasCustomSuffix.value || showStep.value)\n\nconst showClear = computed(() => {\n return props.clearable && !disabled.value && displayed.value !== '' && hovered.value\n})\n\n/** 步长 */\nconst stepVal = computed<number>(() => {\n const { step } = props\n if (step === undefined) return 1\n return typeof step === 'boolean' ? 1 : step\n})\n\n/** 是否可增 */\nconst increasable = computed(() => {\n const { max, multiple } = props\n if (isUndef(max) || isUndef(model.value)) return true\n // 如果存在倍数,先将 model.value 除以倍数得到原始值再比较\n const rawValue = multiple ? $n.div(model.value, multiple) : model.value\n return rawValue < max\n})\n\n/** 是否可减 */\nconst reducible = computed(() => {\n const { min, multiple } = props\n if (isUndef(min) || isUndef(model.value)) return true\n // 如果存在倍数,先将 model.value 除以倍数得到原始值再比较\n const rawValue = multiple ? $n.div(model.value, multiple) : model.value\n return rawValue > min\n})\n\n// 通过值和步长值计算默认的最大精度\nconst defaultMaxPrecision = computed(() => {\n const { multiple } = props\n // 如果存在倍数,基于原始值计算精度\n const rawValue =\n multiple && model.value !== undefined ? $n.div(model.value, multiple) : model.value\n return Math.max(\n String(rawValue).split('.')[1]?.length ?? 0,\n String(stepVal.value).split('.')[1]?.length ?? 0\n )\n})\n\n/**\n * 获取展示值\n * @param num 实际值\n */\nfunction getDisplayed(num?: number): string {\n if (!num && num !== 0) return ''\n\n const {\n currency,\n precision,\n minPrecision,\n // 如果没有指定最大精度那么设置默认为值和步长值中的较大值\n maxPrecision = defaultMaxPrecision.value,\n multiple\n } = props\n\n // 如果存在倍数,先将实际值除以倍数得到原始值\n const displayValue = multiple ? $n.div(num, multiple) : num\n\n return currency\n ? n(displayValue).currency('CNY', {\n precision,\n minPrecision,\n maxPrecision\n })\n : n(displayValue).fixed(\n precision ?? {\n minPrecision,\n maxPrecision\n }\n )\n}\n\nwatch(\n [model, focused, () => props.currency],\n ([modelValue, inputFocused]) => {\n if (inputFocused) return\n displayed.value = getDisplayed(modelValue)\n },\n { immediate: true }\n)\n\n/**\n * 解析展示值\n * @param str 展示值\n */\nfunction parseDisplayed(str: string): number | undefined {\n if (!str) return undefined\n\n // 将货币格式去掉再转化为数字\n const number = +str.replace(/,/g, '')\n const { multiple } = props\n\n // 如果解析失败,使用当前值作为回退\n // 如果存在倍数,需要先将 model.value 除以倍数得到原始值\n let result: number | undefined\n if (isNaN(number)) {\n if (model.value === undefined) return undefined\n result = multiple ? $n.div(model.value, multiple) : model.value\n } else {\n result = number\n }\n\n if (result === undefined) return undefined\n\n const { precision, maxPrecision, minPrecision } = props\n\n const fixedResult = +n(result).fixed(\n precision ?? {\n minPrecision,\n maxPrecision\n }\n )\n\n // 如果存在倍数,将原始值乘以倍数返回实际值\n return multiple ? $n.mul(fixedResult, multiple) : fixedResult\n}\n\n/**\n * 获取有效值\n * @param val 值\n */\nfunction getValidValue<T extends undefined | number>(val: T): T {\n if (val === undefined) return val\n const { min, max, multiple } = props\n\n // 如果存在倍数,先将值除以倍数得到原始值进行验证,验证后再乘以倍数\n if (multiple) {\n const rawVal = $n.div(val, multiple)\n let validRawVal = rawVal\n if (min !== undefined && rawVal < min) validRawVal = min\n if (max !== undefined && rawVal > max) validRawVal = max\n return $n.mul(validRawVal, multiple) as T\n }\n\n if (min !== undefined && val < min) return min as T\n if (max !== undefined && val > max) return max as T\n return val\n}\n\nfunction handleUpdateModelValue(input: string): void {\n const newVal = parseDisplayed(input)\n model.value = getValidValue(newVal)\n displayed.value = input\n}\n\nfunction handleClear(): void {\n if (!showClear.value) return\n model.value = undefined\n displayed.value = ''\n emit('clear')\n}\n\n/**\n * 处理输入值变化的函数, 该函数仅在输入框失去焦点时触发,\n * 主要用于在输入非数字的情况下的修正处理\n * @param input 输入的值\n */\nfunction handleChange() {\n emit('change', model.value)\n}\n\nconst tween = new Tween(\n { n: model.value ?? 0 },\n {\n onUpdate(state) {\n const _rawInput = inputDom.value\n if (!_rawInput) return\n const { multiple } = props\n // 如果存在倍数,tween.state.n 存储的是原始值,需要乘以倍数后传给 getDisplayed\n const actualValue = multiple ? $n.mul(state.n, multiple) : state.n\n _rawInput.value = getDisplayed(actualValue)\n },\n // 动画进行的过程值有可能被改变, 因此在onComplete中确保还原的是原本的值\n onComplete() {\n const _rawInput = inputDom.value\n if (!_rawInput) return\n _rawInput.value = getDisplayed(model.value)\n }\n }\n)\n\n/** 增 */\nfunction increase(): void {\n if (disabled.value) return\n const { multiple } = props\n const val = model.value ?? 0\n\n if (multiple) {\n // 如果存在倍数,先将实际值除以倍数得到原始值\n const rawVal = $n.div(val, multiple)\n // 在原始值基础上加步长\n const newRawVal = $n.plus(rawVal, stepVal.value)\n // 乘以倍数得到新的实际值\n const newVal = $n.mul(newRawVal, multiple)\n const target = getValidValue(newVal)\n model.value = target\n // tween 动画在原始值上进行\n tween.state.n = $n.div(target, multiple)\n tween.to({ n: $n.div(target, multiple) })\n } else {\n tween.state.n = val\n const target = getValidValue($n.plus(val, stepVal.value))\n model.value = target\n tween.to({ n: target })\n }\n}\n\n/** 减 */\nfunction decrease(): void {\n if (disabled.value) return\n const { multiple } = props\n const val = model.value ?? 0\n\n if (multiple) {\n // 如果存在倍数,先将实际值除以倍数得到原始值\n const rawVal = $n.div(val, multiple)\n // 在原始值基础上减步长\n const newRawVal = $n.minus(rawVal, stepVal.value)\n // 乘以倍数得到新的实际值\n const newVal = $n.mul(newRawVal, multiple)\n const target = getValidValue(newVal)\n model.value = target\n // tween 动画在原始值上进行\n tween.state.n = $n.div(target, multiple)\n tween.to({ n: $n.div(target, multiple) })\n } else {\n tween.state.n = val\n const target = getValidValue($n.minus(val, stepVal.value))\n model.value = target\n tween.to({ n: target })\n }\n}\n\nfunction handleKeydown(e: KeyboardEvent): void {\n if (!props.step) return\n if (e.key === 'ArrowUp') {\n e.preventDefault()\n return increase()\n }\n if (e.key === 'ArrowDown') {\n e.preventDefault()\n return decrease()\n }\n}\n\nfunction handleFocus(): void {\n focused.value = true\n\n // 如果初始值和当前设置的精度不匹配则进行精度修正\n if (model.value === undefined) return\n const { precision, maxPrecision, minPrecision, multiple } = props\n\n if (multiple) {\n // 如果存在倍数,先除以倍数得到原始值进行精度修正,再乘以倍数\n const rawVal = $n.div(model.value, multiple)\n const fixedRawVal = +n(rawVal).fixed(\n precision ?? {\n maxPrecision,\n minPrecision\n }\n )\n model.value = $n.mul(fixedRawVal, multiple)\n } else {\n model.value = +n(model.value).fixed(\n precision ?? {\n maxPrecision,\n minPrecision\n }\n )\n }\n}\n\nfunction handleBlur(): void {\n focused.value = false\n model.value = props.modelValue\n}\n\nfunction handleMouseEnter(): void {\n hovered.value = true\n}\n\nfunction handleMouseLeave(): void {\n hovered.value = false\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgFA,MAAM,QAAQ;EAMd,MAAM,OAAO;EAEb,MAAM,QAAQ,UAAA;EAKd,MAAM,EAAE,cAAc,mBAAkB;EAExC,MAAM,EAAE,MAAM,UAAU,aAAa,qBAAqB,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE;GAClF,MAAM;GACN,UAAU;GACV,UAAU;GACX,CAAA;EAED,MAAM,aAAa,eAAe;AAChC,UAAO,EAAE,MAAM,CAAC,KAAK;IAAC;IAAY;IAAe;IAAQ;I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{}, {
|
|
|
15
15
|
"update:modelValue": (value: number | undefined) => any;
|
|
16
16
|
} & {
|
|
17
17
|
"update:modelValue": (value?: number | undefined) => any;
|
|
18
|
-
clear: () => any;
|
|
19
18
|
change: (value?: number | undefined) => any;
|
|
19
|
+
clear: () => any;
|
|
20
20
|
}, string, _$vue.PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
21
21
|
"onUpdate:modelValue"?: ((value?: number | undefined) => any) | undefined;
|
|
22
|
-
onClear?: (() => any) | undefined;
|
|
23
22
|
onChange?: ((value?: number | undefined) => any) | undefined;
|
|
23
|
+
onClear?: (() => any) | undefined;
|
|
24
24
|
}>, {
|
|
25
|
+
clearable: boolean;
|
|
26
|
+
placeholder: string;
|
|
25
27
|
disabled: boolean;
|
|
26
28
|
readonly: boolean;
|
|
27
|
-
placeholder: string;
|
|
28
|
-
clearable: boolean;
|
|
29
29
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
30
30
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
31
31
|
declare const _default: typeof __VLS_export;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { injectFormContext } from "../../utils/form-context.js";
|
|
2
1
|
import _sfc_main$1 from "../number-input/number-input.js";
|
|
3
2
|
import { Fragment, computed, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, getCurrentInstance, mergeModels, mergeProps, nextTick, normalizeClass, onMounted, openBlock, toDisplayString, unref, useModel, watch } from "vue";
|
|
4
|
-
import { FORM_EMPTY_CONTENT, bem } from "@veltra/utils";
|
|
3
|
+
import { FORM_EMPTY_CONTENT, bem, injectFormContext } from "@veltra/utils";
|
|
5
4
|
import { useFormFallbackProps } from "@veltra/compositions";
|
|
6
5
|
import { $n, n, o } from "@cat-kit/core";
|
|
7
6
|
//#region src/components/number-range-input/number-range-input.vue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-range-input.js","names":[],"sources":["../../../src/components/number-range-input/number-range-input.vue"],"sourcesContent":["<template>\n <div v-if=\"!readonly\" :class=\"className\">\n <u-number-input\n v-model=\"startModel\"\n :placeholder=\"startPlaceholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :size=\"size\"\n v-bind=\"numberInputBind\"\n @change=\"emitChange\"\n />\n <span :class=\"cls.e('separator')\">{{ separator }}</span>\n <u-number-input\n v-model=\"endModel\"\n :placeholder=\"endPlaceholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :size=\"size\"\n v-bind=\"numberInputBind\"\n @change=\"emitChange\"\n />\n </div>\n\n <template v-else>\n {{ readonlyText || FORM_EMPTY_CONTENT }}\n </template>\n</template>\n\n<script lang=\"ts\" setup>\nimport { n, $n, o } from '@cat-kit/core'\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem, FORM_EMPTY_CONTENT } from '@veltra/utils'\nimport { computed, getCurrentInstance, nextTick, onMounted, watch } from 'vue'\n\nimport type { NumberRangeInputEmits, NumberRangeInputProps, NumberRangeTuple } from '../../types'\nimport {
|
|
1
|
+
{"version":3,"file":"number-range-input.js","names":[],"sources":["../../../src/components/number-range-input/number-range-input.vue"],"sourcesContent":["<template>\n <div v-if=\"!readonly\" :class=\"className\">\n <u-number-input\n v-model=\"startModel\"\n :placeholder=\"startPlaceholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :size=\"size\"\n v-bind=\"numberInputBind\"\n @change=\"emitChange\"\n />\n <span :class=\"cls.e('separator')\">{{ separator }}</span>\n <u-number-input\n v-model=\"endModel\"\n :placeholder=\"endPlaceholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n :size=\"size\"\n v-bind=\"numberInputBind\"\n @change=\"emitChange\"\n />\n </div>\n\n <template v-else>\n {{ readonlyText || FORM_EMPTY_CONTENT }}\n </template>\n</template>\n\n<script lang=\"ts\" setup>\nimport { n, $n, o } from '@cat-kit/core'\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem, FORM_EMPTY_CONTENT } from '@veltra/utils'\nimport { injectFormContext } from '@veltra/utils'\nimport { computed, getCurrentInstance, nextTick, onMounted, watch } from 'vue'\n\nimport type { NumberRangeInputEmits, NumberRangeInputProps, NumberRangeTuple } from '../../types'\nimport { UNumberInput } from '../number-input'\n\ndefineOptions({\n name: 'NumberRangeInput'\n})\n\nconst props = withDefaults(defineProps<NumberRangeInputProps>(), {\n startPlaceholder: '请输入',\n endPlaceholder: '请输入',\n separator: '~',\n clearable: true,\n disabled: undefined,\n readonly: undefined\n})\n\nconst emit = defineEmits<NumberRangeInputEmits>()\n\nconst inst = getCurrentInstance()\n\nfunction splitBound(): boolean {\n const p = inst?.vnode.props\n if (!p) return false\n return 'start' in p || 'onUpdate:start' in p || 'end' in p || 'onUpdate:end' in p\n}\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {\n size: 'default',\n disabled: false,\n readonly: false\n})\n\nconst cls = bem('number-range-input')\n\nconst className = computed(() => {\n return [cls.b, cls.m(size.value)]\n})\n\nconst model = defineModel<NumberRangeTuple>({\n default: () => [undefined, undefined]\n})\n\nconst startRef = defineModel<number | undefined>('start')\nconst endRef = defineModel<number | undefined>('end')\n\nlet syncGuard = false\n\nfunction normalizeFromSplit(s: number | undefined, e: number | undefined): NumberRangeTuple {\n let nextS = s\n let nextE = e\n if (nextS !== undefined && nextE !== undefined && nextS > nextE) nextE = nextS\n return [nextS, nextE]\n}\n\nwatch(\n model,\n (t) => {\n if (syncGuard) return\n syncGuard = true\n const tuple = t ?? [undefined, undefined]\n if (startRef.value !== tuple[0]) startRef.value = tuple[0]\n if (endRef.value !== tuple[1]) endRef.value = tuple[1]\n nextTick(() => {\n syncGuard = false\n })\n },\n { deep: true }\n)\n\nwatch(\n [startRef, endRef],\n () => {\n if (!splitBound() || syncGuard) return\n syncGuard = true\n const normalized = normalizeFromSplit(startRef.value, endRef.value)\n const cur = model.value ?? [undefined, undefined]\n if (cur[0] !== normalized[0] || cur[1] !== normalized[1]) {\n model.value = normalized\n }\n nextTick(() => {\n syncGuard = false\n })\n },\n { deep: true }\n)\n\nonMounted(() => {\n if (!splitBound()) return\n const cur = model.value ?? [undefined, undefined]\n const hasModel = cur[0] !== undefined || cur[1] !== undefined\n if (hasModel) return\n const normalized = normalizeFromSplit(startRef.value, endRef.value)\n if (cur[0] !== normalized[0] || cur[1] !== normalized[1]) {\n syncGuard = true\n model.value = normalized\n nextTick(() => {\n syncGuard = false\n })\n }\n})\n\nconst numberInputBind = computed(() => {\n return o(props).pick([\n 'clearable',\n 'prefix',\n 'suffix',\n 'step',\n 'min',\n 'max',\n 'currency',\n 'precision',\n 'minPrecision',\n 'maxPrecision',\n 'multiple'\n ])\n})\n\nconst startModel = computed({\n get(): number | undefined {\n return model.value?.[0]\n },\n set(v: number | undefined) {\n const cur = model.value ?? [undefined, undefined]\n const end = cur[1]\n let nextEnd = end\n if (v !== undefined && end !== undefined && v > end) nextEnd = v\n model.value = [v, nextEnd]\n }\n})\n\nconst endModel = computed({\n get(): number | undefined {\n return model.value?.[1]\n },\n set(v: number | undefined) {\n const cur = model.value ?? [undefined, undefined]\n const start = cur[0]\n let nextStart = start\n if (v !== undefined && start !== undefined && v < start) nextStart = v\n model.value = [nextStart, v]\n }\n})\n\nfunction formatNumberPart(num: number): string {\n const { currency, precision, minPrecision, maxPrecision, multiple } = props\n\n const displayValue = multiple ? $n.div(num, multiple) : num\n\n return currency\n ? n(displayValue).currency('CNY', {\n precision,\n minPrecision,\n maxPrecision\n })\n : n(displayValue).fixed(\n precision ?? {\n minPrecision,\n maxPrecision\n }\n )\n}\n\nconst readonlyText = computed(() => {\n const [s, e] = model.value ?? [undefined, undefined]\n if (s === undefined && e === undefined) return ''\n const p = props.prefix ?? ''\n const sfx = props.suffix ?? ''\n const sep = props.separator ?? '~'\n const a = s === undefined ? '—' : formatNumberPart(s)\n const b = e === undefined ? '—' : formatNumberPart(e)\n return `${p}${a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B,mBAAwD,QAAA,EAAjD,OAAK,eAAE,MAAA,IAAG,CAAC,EAAC,YAAA,CAAA,EAAA,EAAA,gBAAkB,QAAA,UAAS,EAAA,EAAA;IAC9C,YAQE,MAAA,YAAA,EARF,WAQE;iBAPS,SAAA;kEAAA,SAAQ,QAAA;KAChB,aAAa,QAAA;KACb,UAAU,MAAA,SAAQ;KAClB,UAAU,MAAA,SAAQ;KAClB,MAAM,MAAA,KAAI;OACH,gBAAA,OAAe,EACtB,UAAQ,YAAU,CAAA,EAAA,MAAA,IAAA;KAAA;KAAA;KAAA;KAAA;KAAA;KAAA,CAAA;0BAIvB,mBAEW,UAAA,EAAA,KAAA,GAAA,EAAA,CAAA,gBAAA,gBADN,aAAA,SAAgB,MAAA,mBAAkB,CAAA,EAAA,EAAA,CAAA,EAAA,GAAA"}
|
|
@@ -24,9 +24,9 @@ declare const __VLS_export: _$vue.DefineComponent<__VLS_PublicProps, {}, {}, {},
|
|
|
24
24
|
"onUpdate:start"?: ((value: number | undefined) => any) | undefined;
|
|
25
25
|
"onUpdate:end"?: ((value: number | undefined) => any) | undefined;
|
|
26
26
|
}>, {
|
|
27
|
+
clearable: boolean;
|
|
27
28
|
disabled: boolean;
|
|
28
29
|
readonly: boolean;
|
|
29
|
-
clearable: boolean;
|
|
30
30
|
startPlaceholder: string;
|
|
31
31
|
endPlaceholder: string;
|
|
32
32
|
separator: string;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { injectFormContext } from "../../utils/form-context.js";
|
|
2
1
|
import _sfc_main$1 from "../tip/tip.js";
|
|
3
2
|
import { HEX2RGBA, HSV2RGB, RGB2HEX, RGB2HSV } from "./color-transform.js";
|
|
4
3
|
import { PaletteDIKey } from "./di.js";
|
|
@@ -8,7 +7,7 @@ import _sfc_main$4 from "./palette-hue.js";
|
|
|
8
7
|
import _sfc_main$5 from "./palette-sv.js";
|
|
9
8
|
import { useHSV } from "./use-hsv.js";
|
|
10
9
|
import { computed, createBlock, createCommentVNode, createElementVNode, createVNode, defineComponent, mergeModels, normalizeClass, normalizeStyle, openBlock, provide, shallowRef, unref, useModel, useTemplateRef, watch, withCtx } from "vue";
|
|
11
|
-
import { bem } from "@veltra/utils";
|
|
10
|
+
import { bem, injectFormContext } from "@veltra/utils";
|
|
12
11
|
import { useFormFallbackProps, useUserAction } from "@veltra/compositions";
|
|
13
12
|
//#region src/components/palette/palette.vue
|
|
14
13
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"palette.js","names":[],"sources":["../../../src/components/palette/palette.vue"],"sourcesContent":["<template>\n <u-tip\n trigger=\"click\"\n :class=\"cls.e('panel')\"\n v-model:visible=\"visible\"\n :disabled=\"disabled || readonly\"\n >\n <span :class=\"className\" :style=\"{ backgroundColor: color }\"> </span>\n\n <template #content>\n <!-- 饱和度和亮度 -->\n <PaletteSV ref=\"palette-sv\" />\n\n <!-- 色相 -->\n <PaletteHue ref=\"palette-hue\" />\n\n <!-- 透明度 -->\n <PaletteAlpha ref=\"palette-alpha\" />\n\n <!-- 颜色切换 -->\n <PaletteColorSwitch v-model:color=\"color\" @clear=\"handleClear\" />\n </template>\n </u-tip>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFormFallbackProps, useUserAction } from '@veltra/compositions'\nimport { bem } from '@veltra/utils'\nimport { computed, provide, shallowRef, useTemplateRef, watch } from 'vue'\n\nimport type { PaletteProps } from '../../types'\nimport {
|
|
1
|
+
{"version":3,"file":"palette.js","names":[],"sources":["../../../src/components/palette/palette.vue"],"sourcesContent":["<template>\n <u-tip\n trigger=\"click\"\n :class=\"cls.e('panel')\"\n v-model:visible=\"visible\"\n :disabled=\"disabled || readonly\"\n >\n <span :class=\"className\" :style=\"{ backgroundColor: color }\"> </span>\n\n <template #content>\n <!-- 饱和度和亮度 -->\n <PaletteSV ref=\"palette-sv\" />\n\n <!-- 色相 -->\n <PaletteHue ref=\"palette-hue\" />\n\n <!-- 透明度 -->\n <PaletteAlpha ref=\"palette-alpha\" />\n\n <!-- 颜色切换 -->\n <PaletteColorSwitch v-model:color=\"color\" @clear=\"handleClear\" />\n </template>\n </u-tip>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFormFallbackProps, useUserAction } from '@veltra/compositions'\nimport { bem } from '@veltra/utils'\nimport { injectFormContext } from '@veltra/utils'\nimport { computed, provide, shallowRef, useTemplateRef, watch } from 'vue'\n\nimport type { PaletteProps } from '../../types'\nimport { UTip } from '../tip'\nimport { HSV2RGB, RGB2HEX, HEX2RGBA, RGB2HSV } from './color-transform'\nimport { PaletteDIKey } from './di'\nimport PaletteAlpha from './palette-alpha.vue'\nimport PaletteColorSwitch from './palette-color-switch.vue'\nimport PaletteHue from './palette-hue.vue'\nimport PaletteSV from './palette-sv.vue'\nimport { useHSV } from './use-hsv'\n\ndefineOptions({\n name: 'Palette'\n})\n\nconst props = withDefaults(defineProps<PaletteProps>(), {\n disabled: undefined,\n readonly: undefined\n})\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props])\n\nconst cls = bem('palette')\n\nconst className = computed(() => {\n return [cls.b, cls.m(size.value), bem.is('no-color', !color.value)]\n})\n\nconst { HSV, alpha, ...rest } = useHSV()\n\nconst color = defineModel<string>()\nconst RGB = computed(() => HSV2RGB(HSV))\nconst { userAction, isUserActive } = useUserAction()\n\nconst visible = shallowRef(false)\n\n/** 清除时跳过一次内部状态到 color 的同步,防止 updateAlpha 把已清空的 color 覆盖回来 */\nlet skipColorUpdate = false\n\nconst handleClear = userAction(() => {\n if (alpha.value !== 1) {\n skipColorUpdate = true\n }\n color.value = ''\n rest.updateAlpha(1)\n visible.value = false\n})\n\nwatch([alpha, RGB], ([alpha, RGB]) => {\n if (skipColorUpdate) {\n skipColorUpdate = false\n return\n }\n color.value = `#${RGB2HEX(RGB, alpha)}`\n})\n\nconst paletteSVRef = useTemplateRef('palette-sv')\nconst paletteHueRef = useTemplateRef('palette-hue')\nconst paletteAlphaRef = useTemplateRef('palette-alpha')\n\nwatch(\n color,\n (color) => {\n if (!color) return\n if (isUserActive()) return\n\n const { RGB, alpha } = HEX2RGBA(color)\n const hsv = RGB2HSV(RGB)\n rest.updateHue(hsv.h)\n rest.updateSV({ s: hsv.s, v: hsv.v })\n rest.updateAlpha(alpha)\n\n paletteSVRef.value?.init()\n paletteHueRef.value?.init()\n paletteAlphaRef.value?.init()\n },\n { immediate: true }\n)\n\nprovide(PaletteDIKey, {\n cls,\n HSV,\n RGB,\n alpha,\n userAction,\n isUserActive,\n ...rest\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6CA,MAAM,QAAQ;EAKd,MAAM,EAAE,cAAc,mBAAkB;EAExC,MAAM,EAAE,MAAM,UAAU,aAAa,qBAAqB,CAAC,aAAa,EAAE,EAAE,MAAM,CAAA;EAElF,MAAM,MAAM,IAAI,UAAS;EAEzB,MAAM,YAAY,eAAe;AAC/B,UAAO;IAAC,IAAI;IAAG,IAAI,EAAE,KAAK,MAAM;IAAE,IAAI,GAAG,YAAY,CAAC,MAAM,MAAM;IAAA;IACnE;EAED,MAAM,EAAE,KAAK,OAAO,GAAG,SAAS,QAAO;EAEvC,MAAM,QAAQ,SAAmB,SAAA,aAAC;EAClC,MAAM,MAAM,eAAe,QAAQ,IAAI,CAAA;EACvC,MAAM,EAAE,YAAY,iBAAiB,eAAc;EAEnD,MAAM,UAAU,WAAW,MAAK;;EAGhC,IAAI,kBAAkB;EAEtB,MAAM,cAAc,iBAAiB;AACnC,OAAI,MAAM,UAAU,EAClB,mBAAkB;AAEpB,SAAM,QAAQ;AACd,QAAK,YAAY,EAAC;AAClB,WAAQ,QAAQ;IACjB;AAED,QAAM,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,SAAS;AACpC,OAAI,iBAAiB;AACnB,sBAAkB;AAClB;;AAEF,SAAM,QAAQ,IAAI,QAAQ,KAAK,MAAM;IACtC;EAED,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from "../icon/icon.js";
|
|
2
|
-
import { injectFormContext } from "../../utils/form-context.js";
|
|
3
2
|
import input_default from "../input/input.js";
|
|
4
3
|
import { Transition, computed, createBlock, createSlots, createVNode, defineComponent, mergeModels, mergeProps, nextTick, normalizeClass, openBlock, renderSlot, shallowRef, unref, useModel, useSlots, withCtx } from "vue";
|
|
5
|
-
import { bem } from "@veltra/utils";
|
|
4
|
+
import { bem, injectFormContext } from "@veltra/utils";
|
|
6
5
|
import { useFormFallbackProps } from "@veltra/compositions";
|
|
7
6
|
import { o } from "@cat-kit/core";
|
|
8
7
|
import { Hide, View } from "@veltra/icons/normal";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-input.js","names":[],"sources":["../../../src/components/password-input/password-input.vue"],"sourcesContent":["<template>\n <u-input\n :class=\"cls.b\"\n :model-value=\"passwordText\"\n v-bind=\"inputProps\"\n :size=\"size\"\n :readonly=\"readonly\"\n :disabled=\"disabled\"\n @native:input=\"handleUpdatePwd\"\n @update:model-value=\"!$event && handleClear()\"\n @suffix:click=\"toggleVisible\"\n >\n <template #suffix>\n <Transition name=\"fade\">\n <UIcon :class=\"cls.e('visibility-toggle')\" :size=\"18\">\n <Hide v-if=\"pwdVisible\" />\n <View v-else />\n </UIcon>\n </Transition>\n </template>\n\n <template #prefix v-if=\"slots.prefix\">\n <slot name=\"prefix\" />\n </template>\n </u-input>\n</template>\n\n<script lang=\"ts\" setup>\nimport { o } from '@cat-kit/core'\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { Hide, View } from '@veltra/icons/normal'\nimport { bem } from '@veltra/utils'\nimport { computed, nextTick, shallowRef } from 'vue'\n\nimport type { PasswordInputProps } from '../../types'\nimport {
|
|
1
|
+
{"version":3,"file":"password-input.js","names":[],"sources":["../../../src/components/password-input/password-input.vue"],"sourcesContent":["<template>\n <u-input\n :class=\"cls.b\"\n :model-value=\"passwordText\"\n v-bind=\"inputProps\"\n :size=\"size\"\n :readonly=\"readonly\"\n :disabled=\"disabled\"\n @native:input=\"handleUpdatePwd\"\n @update:model-value=\"!$event && handleClear()\"\n @suffix:click=\"toggleVisible\"\n >\n <template #suffix>\n <Transition name=\"fade\">\n <UIcon :class=\"cls.e('visibility-toggle')\" :size=\"18\">\n <Hide v-if=\"pwdVisible\" />\n <View v-else />\n </UIcon>\n </Transition>\n </template>\n\n <template #prefix v-if=\"slots.prefix\">\n <slot name=\"prefix\" />\n </template>\n </u-input>\n</template>\n\n<script lang=\"ts\" setup>\nimport { o } from '@cat-kit/core'\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { Hide, View } from '@veltra/icons/normal'\nimport { bem } from '@veltra/utils'\nimport { injectFormContext } from '@veltra/utils'\nimport { computed, nextTick, shallowRef } from 'vue'\n\nimport type { PasswordInputProps } from '../../types'\nimport { UIcon } from '../icon'\nimport { UInput } from '../input'\n\ndefineOptions({\n name: 'PasswordInput'\n})\n\nconst props = withDefaults(defineProps<PasswordInputProps>(), {\n clearable: false,\n disabled: undefined,\n readonly: undefined\n})\n\nconst slots = defineSlots<{\n prefix?: () => any\n}>()\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {\n size: 'default',\n disabled: false,\n readonly: false\n})\n\nconst inputProps = computed(() => {\n return o(props).pick(['clearable', 'disabled', 'placeholder', 'size'])\n})\n\nconst cls = bem('password-input')\n\nconst model = defineModel<string>()\n\nconst passwordChar = '●'\n\nconst handleUpdatePwd = (e: Event): void => {\n const target = e.target as HTMLInputElement\n const val = target.value\n if (!val) {\n model.value = val\n return\n }\n\n // 字符从无到有\n if (!model.value) {\n model.value = val\n return\n }\n\n const pointIndex = target.selectionStart!\n let inputChar = pointIndex === 0 ? '' : val[pointIndex - 1]!\n if (inputChar === passwordChar) inputChar = ''\n\n // 光标右侧字符数量(当前字符长度减去光标位置)\n const rightLen = val.length - pointIndex\n // 光标左侧字符数量 (当光标前的字符是刚刚输入的,则为这个字符前的所有的字符,否则为光标前的所有赐福)\n const leftLen = inputChar === '' ? pointIndex : pointIndex - 1\n\n const leftVal = model.value.slice(0, leftLen)\n const rightVal = rightLen === 0 ? '' : model.value.slice(-rightLen)\n\n model.value = leftVal + inputChar + rightVal\n\n nextTick(() => {\n target.selectionStart = pointIndex\n target.selectionEnd = pointIndex\n })\n}\n\nconst handleClear = (): void => {\n model.value = ''\n}\n\nconst pwdVisible = shallowRef(false)\n\nconst passwordText = computed<string | undefined>(() => {\n if (pwdVisible.value) return model.value\n return model.value ? passwordChar.repeat(model.value.length) : ''\n})\n\nconst toggleVisible = () => {\n pwdVisible.value = !pwdVisible.value\n}\n</script>\n"],"mappings":";;;;;;;;AAqEA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA1BrB,MAAM,QAAQ;EAMd,MAAM,QAAQ,UAAA;EAId,MAAM,EAAE,cAAc,mBAAkB;EAExC,MAAM,EAAE,MAAM,UAAU,aAAa,qBAAqB,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE;GAClF,MAAM;GACN,UAAU;GACV,UAAU;GACX,CAAA;EAED,MAAM,aAAa,eAAe;AAChC,UAAO,EAAE,MAAM,CAAC,KAAK;IAAC;IAAa;IAAY;IAAe;IAAO,CAAA;IACtE;EAED,MAAM,MAAM,IAAI,iBAAgB;EAEhC,MAAM,QAAQ,SAAmB,SAAA,aAAC;EAIlC,MAAM,mBAAmB,MAAmB;GAC1C,MAAM,SAAS,EAAE;GACjB,MAAM,MAAM,OAAO;AACnB,OAAI,CAAC,KAAK;AACR,UAAM,QAAQ;AACd;;AAIF,OAAI,CAAC,MAAM,OAAO;AAChB,UAAM,QAAQ;AACd;;GAGF,MAAM,aAAa,OAAO;GAC1B,IAAI,YAAY,eAAe,IAAI,KAAK,IAAI,aAAa;AACzD,OAAI,cAAc,aAAc,aAAY;GAG5C,MAAM,WAAW,IAAI,SAAS;GAE9B,MAAM,UAAU,cAAc,KAAK,aAAa,aAAa;GAE7D,MAAM,UAAU,MAA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ue.PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
16
16
|
"onUpdate:modelValue"?: ((value: string | undefined) => any) | undefined;
|
|
17
17
|
}>, {
|
|
18
|
+
clearable: boolean;
|
|
18
19
|
disabled: boolean;
|
|
19
20
|
readonly: boolean;
|
|
20
|
-
clearable: boolean;
|
|
21
21
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
22
22
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
23
23
|
declare const _default: typeof __VLS_export;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import _sfc_main$1 from "../icon/icon.js";
|
|
2
|
-
import { injectFormContext } from "../../utils/form-context.js";
|
|
3
2
|
import _sfc_main$2 from "../tip/tip.js";
|
|
4
3
|
import _sfc_main$3 from "../button/button.js";
|
|
5
4
|
import { createBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, ref, renderSlot, resolveDynamicComponent, toDisplayString, unref, withCtx } from "vue";
|
|
6
|
-
import { bem } from "@veltra/utils";
|
|
5
|
+
import { bem, injectFormContext } from "@veltra/utils";
|
|
7
6
|
import { useFormFallbackProps } from "@veltra/compositions";
|
|
8
7
|
import { QuestionFilled } from "@veltra/icons/normal";
|
|
9
8
|
//#region src/components/pop-confirm/pop-confirm.vue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pop-confirm.js","names":[],"sources":["../../../src/components/pop-confirm/pop-confirm.vue"],"sourcesContent":["<template>\n <u-tip\n :class=\"cls.b\"\n :trigger=\"trigger\"\n :direction=\"direction\"\n :alignment=\"alignment\"\n :content-tag=\"contentTag\"\n v-model:visible=\"visible\"\n >\n <slot name=\"reference\" />\n\n <template #content>\n <div :class=\"[cls.m('main'), cls.m(size)]\">\n <u-icon :size=\"16\" :class=\"cls.m('icon')\" :style=\"{ color: iconColor }\">\n <component :is=\"icon\" />\n </u-icon>\n <span>\n {{ title }}\n </span>\n </div>\n <div :class=\"cls.m('action')\">\n <u-button size=\"small\" @click=\"cancel\" type=\"primary\" text>\n {{ cancelText }}\n </u-button>\n \n <u-button size=\"small\" type=\"primary\" @click=\"confirm\">\n {{ confirmText }}\n </u-button>\n </div>\n </template>\n </u-tip>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { QuestionFilled } from '@veltra/icons/normal'\nimport { bem } from '@veltra/utils'\nimport {
|
|
1
|
+
{"version":3,"file":"pop-confirm.js","names":[],"sources":["../../../src/components/pop-confirm/pop-confirm.vue"],"sourcesContent":["<template>\n <u-tip\n :class=\"cls.b\"\n :trigger=\"trigger\"\n :direction=\"direction\"\n :alignment=\"alignment\"\n :content-tag=\"contentTag\"\n v-model:visible=\"visible\"\n >\n <slot name=\"reference\" />\n\n <template #content>\n <div :class=\"[cls.m('main'), cls.m(size)]\">\n <u-icon :size=\"16\" :class=\"cls.m('icon')\" :style=\"{ color: iconColor }\">\n <component :is=\"icon\" />\n </u-icon>\n <span>\n {{ title }}\n </span>\n </div>\n <div :class=\"cls.m('action')\">\n <u-button size=\"small\" @click=\"cancel\" type=\"primary\" text>\n {{ cancelText }}\n </u-button>\n \n <u-button size=\"small\" type=\"primary\" @click=\"confirm\">\n {{ confirmText }}\n </u-button>\n </div>\n </template>\n </u-tip>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { QuestionFilled } from '@veltra/icons/normal'\nimport { bem } from '@veltra/utils'\nimport { injectFormContext } from '@veltra/utils'\nimport { ref } from 'vue'\n\nimport type { PopConfirmProps, PopConfirmEmits } from '../../types'\nimport { UButton } from '../button'\nimport { UIcon } from '../icon'\nimport { UTip } from '../tip'\n\ndefineOptions({\n name: 'PopConfirm'\n})\n\nconst emit = defineEmits<PopConfirmEmits>()\n\nwithDefaults(defineProps<PopConfirmProps>(), {\n trigger: 'click',\n icon: QuestionFilled,\n direction: 'bottom',\n iconColor: '#ffc107',\n confirmText: '确认',\n cancelText: '取消'\n})\n\nconst cls = bem('pop-confirm')\n\nconst visible = ref(false)\n\nconst { formProps } = injectFormContext()\n\nconst { size } = useFormFallbackProps([formProps ?? {}], {\n size: 'default'\n})\n\nconst confirm = () => {\n emit('confirm')\n visible.value = false\n}\n\nconst cancel = () => {\n emit('cancel')\n visible.value = false\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;EAiDA,MAAM,OAAO;EAWb,MAAM,MAAM,IAAI,cAAa;EAE7B,MAAM,UAAU,IAAI,MAAK;EAEzB,MAAM,EAAE,cAAc,mBAAkB;EAExC,MAAM,EAAE,SAAS,qBAAqB,CAAC,aAAa,EAAE,CAAC,EAAE,EACvD,MAAM,WACP,CAAA;EAED,MAAM,gBAAgB;AACpB,QAAK,UAAS;AACd,WAAQ,QAAQ;;EAGlB,MAAM,eAAe;AACnB,QAAK,SAAQ;AACb,WAAQ,QAAQ;;;uBA5EhB,YA6BQ,MAAA,YAAA,EAAA;IA5BL,OAAK,eAAE,MAAA,IAAG,CAAC,EAAC;IACZ,SAAS,QAAA;IACT,WAAW,QAAA;IACX,WAAW,QAAA;IACX,eAAa,QAAA;IACN,SAAS,QAAA;8DAAA,QAAO,QAAA;;IAIb,SAAO,cAQV,CAPN,mBAOM,OAAA,EAPA,OAAK,eAAA,CAAG,MAAA,IAAG,CAAC,EAAC,OAAA,EAAU,MAAA,IAAG,CAAC,EAAE,MAAA,KAAI,CAAA,CAAA,CAAA,EAAA,EAAA,CACrC,YAES,MAAA,YAAA,EAAA;KAFA,MAAM;KAAK,OAAK,eAAE,MAAA,IAAG,CAAC,EAAC,OAAA,CAAA;KAAW,OAAK,eAAA,EAAA,OAAW,QAAA,WAAS,CAAA;;4BAC1C,EAAA,WAAA,EAAxB,YAAwB,wBAAR,QAAA,KAAI,CAAA,EAAA,CAAA;;+BAEtB,mBAEO,QAAA,MAAA,gBADF,QAAA,MAAK,EAAA,EAAA,CAAA,EAAA,EAAA,EAGZ,mBAQM,OAAA,EARA,OAAK,eAAE,MAAA,IAAG,CAAC,EAAC,SAAA,CAAA,EAAA,EAAA;KAChB,YAEW,MAAA,YAAA,EAAA;MAFD,MAAK;MAAS,SAAO;MAAQ,MAAK;MAAU,MAAA;;6BACpC,CAAA,gBAAA,gBAAb,QAAA,WAAU,EAAA,EAAA,CAAA,CAAA;;;+CACJ,UAEX,GAAA;KAAA,YAEW,MAAA,YAAA,EAAA;MAFD,MAAK;MAAQ,MAAK;MAAW,SAAO;;6BAC3B,CAAA,gBAAA,gBAAd,QAAA,YAAW,EAAA,EAAA,CAAA,CAAA;;;;2BAjBK,CAAzB,WAAyB,KAAA,QAAA,YAAA,CAAA,CAAA"}
|
|
@@ -14,9 +14,9 @@ declare const __VLS_base: _$vue.DefineComponent<PopConfirmProps, {}, {}, {}, {},
|
|
|
14
14
|
onConfirm?: (() => any) | undefined;
|
|
15
15
|
onCancel?: (() => any) | undefined;
|
|
16
16
|
}>, {
|
|
17
|
-
direction: TipDirection;
|
|
18
|
-
trigger: "hover" | "click";
|
|
19
17
|
icon: _$vue.Component;
|
|
18
|
+
trigger: "hover" | "click";
|
|
19
|
+
direction: TipDirection;
|
|
20
20
|
iconColor: string;
|
|
21
21
|
confirmText: string;
|
|
22
22
|
cancelText: string;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { injectFormContext } from "../../utils/form-context.js";
|
|
2
1
|
import { Transition, computed, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, mergeModels, normalizeClass, openBlock, renderSlot, toDisplayString, unref, useModel, vModelRadio, withCtx, withDirectives } from "vue";
|
|
3
|
-
import { bem } from "@veltra/utils";
|
|
2
|
+
import { bem, injectFormContext } from "@veltra/utils";
|
|
4
3
|
import { useFormFallbackProps } from "@veltra/compositions";
|
|
5
4
|
//#region src/components/radio/radio.vue
|
|
6
5
|
const _hoisted_1 = ["value", "disabled"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radio.js","names":[],"sources":["../../../src/components/radio/radio.vue"],"sourcesContent":["<template>\n <label :class=\"classList\">\n <!-- radio框 -->\n <section :class=\"cls.e('button')\">\n <input\n type=\"radio\"\n :class=\"cls.e('native')\"\n :value=\"value\"\n v-model=\"model\"\n :disabled=\"disabled\"\n hidden\n />\n\n <transition name=\"zoom-in\">\n <span :class=\"cls.e('inner')\" v-if=\"radioChecked\"></span>\n </transition>\n </section>\n\n <span :class=\"cls.e('label')\">\n <slot>{{ label }}</slot>\n </span>\n </label>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem } from '@veltra/utils'\nimport {
|
|
1
|
+
{"version":3,"file":"radio.js","names":[],"sources":["../../../src/components/radio/radio.vue"],"sourcesContent":["<template>\n <label :class=\"classList\">\n <!-- radio框 -->\n <section :class=\"cls.e('button')\">\n <input\n type=\"radio\"\n :class=\"cls.e('native')\"\n :value=\"value\"\n v-model=\"model\"\n :disabled=\"disabled\"\n hidden\n />\n\n <transition name=\"zoom-in\">\n <span :class=\"cls.e('inner')\" v-if=\"radioChecked\"></span>\n </transition>\n </section>\n\n <span :class=\"cls.e('label')\">\n <slot>{{ label }}</slot>\n </span>\n </label>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem } from '@veltra/utils'\nimport { injectFormContext } from '@veltra/utils'\nimport { computed } from 'vue'\n\nimport type { RadioProps, RadioEmits } from '../../types'\n\ndefineOptions({\n name: 'Radio'\n})\n\nconst model = defineModel<any>()\n\nconst props = withDefaults(defineProps<RadioProps>(), {\n disabled: undefined\n})\n\ndefineEmits<RadioEmits>()\n\nconst cls = bem('radio')\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled } = useFormFallbackProps([formProps ?? {}, props], {\n size: 'default',\n disabled: false\n})\n\nconst radioChecked = computed(() => model.value === props.value)\n\nconst classList = computed(() => {\n return [\n cls.b,\n cls.m(size.value),\n b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CAAA,CAAA,CAAA,EAAA,EAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { injectFormContext } from "../../utils/form-context.js";
|
|
2
1
|
import _sfc_main$1 from "../radio/radio.js";
|
|
3
2
|
import { Fragment, createBlock, createElementBlock, createTextVNode, defineComponent, mergeModels, normalizeClass, openBlock, renderList, toDisplayString, unref, useModel, withCtx } from "vue";
|
|
4
|
-
import { FORM_EMPTY_CONTENT, bem } from "@veltra/utils";
|
|
3
|
+
import { FORM_EMPTY_CONTENT, bem, injectFormContext } from "@veltra/utils";
|
|
5
4
|
import { useFormFallbackProps } from "@veltra/compositions";
|
|
6
5
|
//#region src/components/radio-group/radio-group.vue
|
|
7
6
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radio-group.js","names":[],"sources":["../../../src/components/radio-group/radio-group.vue"],"sourcesContent":["<template>\n <div :class=\"[cls.b, bem.is('block', block), cls.m(size)]\" v-if=\"!readonly\">\n <u-radio\n v-for=\"item of items\"\n :key=\"item[valueKey]\"\n :value=\"item[valueKey]\"\n :model-value=\"model\"\n @update:model-value=\"handleUpdate($event, item)\"\n :disabled=\"disabledItem?.(item) || disabled\"\n :size=\"size\"\n >\n {{ item[labelKey] }}\n </u-radio>\n </div>\n\n <template v-else>\n {{ items.find((item) => item[valueKey] === model)?.[labelKey] || FORM_EMPTY_CONTENT }}\n </template>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem, FORM_EMPTY_CONTENT } from '@veltra/utils'\
|
|
1
|
+
{"version":3,"file":"radio-group.js","names":[],"sources":["../../../src/components/radio-group/radio-group.vue"],"sourcesContent":["<template>\n <div :class=\"[cls.b, bem.is('block', block), cls.m(size)]\" v-if=\"!readonly\">\n <u-radio\n v-for=\"item of items\"\n :key=\"item[valueKey]\"\n :value=\"item[valueKey]\"\n :model-value=\"model\"\n @update:model-value=\"handleUpdate($event, item)\"\n :disabled=\"disabledItem?.(item) || disabled\"\n :size=\"size\"\n >\n {{ item[labelKey] }}\n </u-radio>\n </div>\n\n <template v-else>\n {{ items.find((item) => item[valueKey] === model)?.[labelKey] || FORM_EMPTY_CONTENT }}\n </template>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem, FORM_EMPTY_CONTENT } from '@veltra/utils'\nimport { injectFormContext } from '@veltra/utils'\n\nimport type { RadioGroupProps, RadioGroupEmits } from '../../types'\nimport URadio from '../radio/radio.vue'\n\ndefineOptions({\n name: 'RadioGroup'\n})\n\nconst props = withDefaults(defineProps<RadioGroupProps>(), {\n labelKey: 'label',\n valueKey: 'value',\n disabled: undefined,\n readonly: undefined\n})\n\nconst model = defineModel<any>()\n\nconst emit = defineEmits<RadioGroupEmits>()\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {\n size: 'default',\n disabled: false,\n readonly: false\n})\n\nconst cls = bem('radio-group')\n\nconst handleUpdate = (value: any, item: Record<string, any>) => {\n model.value = value\n emit('change', item)\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCA,MAAM,QAAQ;EAOd,MAAM,QAAQ,SAAgB,SAAA,aAAC;EAE/B,MAAM,OAAO;EAEb,MAAM,EAAE,cAAc,mBAAkB;EAExC,MAAM,EAAE,MAAM,UAAU,aAAa,qBAAqB,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE;GAClF,MAAM;GACN,UAAU;GACV,UAAU;GACX,CAAA;EAED,MAAM,MAAM,IAAI,cAAa;EAE7B,MAAM,gBAAgB,OAAY,SAA8B;AAC9D,SAAM,QAAQ;AACd,QAAK,UAAU,KAAI;;;WAtD+C,MAAA,SAAQ,IAAA,WAAA,EAA1E,mBAYM,OAAA;;IAZA,OAAK,eAAA;KAAG,MAAA,IAAG,CAAC;KAAG,MAAA,IAAG,CAAC,GAAE,SAAU,QAAA,MAAK;KAAG,MAAA,IAAG,CAAC,EAAE,MAAA,KAAI,CAAA;KAAA,CAAA;yBACrD,mBAUU,UAAA,MAAA,WATO,QAAA,QAAR,SAAI;wBADb,YAUU,aAAA;KARP,KAAK,KAAK,QAAA;KACV,OAAO,KAAK,QAAA;KACZ,eAAa,MAAA;KACb,wBAAkB,WAAE,aAAa,QAAQ,KAAI;KAC7C,UAAU,QAAA,eAAe,KAAI,IAAK,MAAA,SAAQ;KAC1C,MAAM,MAAA,KAAI;;4BAES,CAAA,gBAAA,gBAAjB,KAAK,QAAA,UAAQ,EAAA,EAAA,CAAA,CAAA;;;;;;;;;mCAIpB,mBAEW,UAAA,EAAA,KAAA,GAAA,EAAA,CAAA,gBAAA,gBADN,QAAA,MAAM,MAAM,SAAS,KAAK,QAAA,cAAc,MAAA,MAAK,GAAI,QAAA,aAAa,MAAA,mBAAkB,CAAA,EAAA,EAAA,CAAA,EAAA,GAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { injectFormContext } from "../../utils/form-context.js";
|
|
2
1
|
import _sfc_main$1 from "./toolbar.js";
|
|
3
2
|
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, defineComponent, mergeModels, normalizeClass, onBeforeUnmount, onMounted, openBlock, ref, shallowRef, toDisplayString, unref, useModel, useTemplateRef, watch } from "vue";
|
|
4
|
-
import { bem } from "@veltra/utils";
|
|
3
|
+
import { bem, injectFormContext } from "@veltra/utils";
|
|
5
4
|
import { useFormFallbackProps } from "@veltra/compositions";
|
|
6
5
|
import { createEmptyHistoryState, registerHistory } from "@lexical/history";
|
|
7
6
|
import { $generateHtmlFromNodes, $generateNodesFromDOM } from "@lexical/html";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rich-text-editor.js","names":[],"sources":["../../../src/components/rich-text-editor/rich-text-editor.vue"],"sourcesContent":["<template>\n <div :class=\"className\">\n <toolbar\n v-if=\"!isReadonly && toolbarItems.length > 0\"\n :editor=\"editor\"\n :toolbar=\"toolbarItems\"\n :disabled=\"isDisabled\"\n />\n <div :class=\"cls.e('content')\">\n <div\n ref=\"editorContainer\"\n :class=\"cls.e('editable')\"\n :contenteditable=\"!isDisabled && !isReadonly\"\n ></div>\n <div v-if=\"showPlaceholder\" :class=\"cls.e('placeholder')\">\n {{ placeholder }}\n </div>\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { ToolbarItem } from '../../types'\n\nconst LEXICAL_THEME = {\n paragraph: 'u-rte-paragraph',\n heading: {\n h1: 'u-rte-h1',\n h2: 'u-rte-h2',\n h3: 'u-rte-h3',\n h4: 'u-rte-h4',\n h5: 'u-rte-h5',\n h6: 'u-rte-h6'\n },\n text: {\n bold: 'u-rte-bold',\n italic: 'u-rte-italic',\n underline: 'u-rte-underline',\n strikethrough: 'u-rte-strikethrough'\n },\n list: {\n ul: 'u-rte-ul',\n ol: 'u-rte-ol',\n listitem: 'u-rte-li',\n nested: { listitem: 'u-rte-li--nested' }\n },\n quote: 'u-rte-blockquote',\n\n link: 'u-rte-link',\n image: 'u-rte-image'\n}\n\nconst DEFAULT_TOOLBAR: ToolbarItem[] = [\n 'undo',\n 'redo',\n '|',\n 'heading',\n '|',\n 'bold',\n 'italic',\n 'underline',\n 'strikethrough',\n '|',\n 'bullet-list',\n 'ordered-list',\n '|',\n 'blockquote',\n '|',\n 'link'\n]\n</script>\n\n<script lang=\"ts\" setup>\nimport { registerHistory, createEmptyHistoryState } from '@lexical/history'\nimport { $generateHtmlFromNodes, $generateNodesFromDOM } from '@lexical/html'\nimport { LinkNode, AutoLinkNode } from '@lexical/link'\nimport { ListNode, ListItemNode, registerList } from '@lexical/list'\nimport { registerRichText } from '@lexical/rich-text'\nimport { HeadingNode, QuoteNode } from '@lexical/rich-text'\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem } from '@veltra/utils'\nimport { createEditor, $getRoot, $createParagraphNode, type LexicalEditor } from 'lexical'\nimport { computed, onBeforeUnmount, onMounted, ref, shallowRef, useTemplateRef, watch } from 'vue'\n\nimport type { RichTextEditorProps } from '../../types'\nimport { injectFormContext } from '../../utils/form-context'\nimport Toolbar from './toolbar.vue'\n\nconst props = withDefaults(defineProps<RichTextEditorProps>(), {\n disabled: undefined,\n readonly: undefined,\n format: 'html',\n toolbar: () => DEFAULT_TOOLBAR,\n placeholder: ''\n})\n\nconst model = defineModel<string>()\n\nconst cls = bem('rich-text-editor')\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props])\n\nconst isDisabled = computed(() => !!disabled.value)\nconst isReadonly = computed(() => !!readonly.value)\n\nconst className = computed<string[]>(() => {\n return [\n cls.b,\n cls.m(size.value),\n bem.is('disabled', isDisabled.value),\n bem.is('readonly', isReadonly.value)\n ]\n})\n\nconst toolbarItems = computed<ToolbarItem[]>(() => {\n return props.toolbar ?? DEFAULT_TOOLBAR\n})\n\nconst editorContainer = useTemplateRef('editorContainer')\nconst editor = shallowRef<LexicalEditor | null>(null)\nconst showPlaceholder = ref(true)\nlet isComposing = false\nlet cleanupFns: (() => void)[] = []\n\nfunction initEditor() {\n if (!editorContainer.value) return\n\n const editorInstance = createEditor({\n namespace: 'URichTextEditor',\n theme: LEXICAL_THEME,\n nodes: [HeadingNode, QuoteNode, ListNode, ListItemNode, LinkNode, AutoLinkNode],\n editable: !isDisabled.value && !isReadonly.value,\n onError: (error: Error) => {\n console.error('Lexical error:', error)\n }\n })\n\n editorInstance.setRootElement(editorContainer.value)\n\n // Register plugins\n cleanupFns.push(registerRichText(editorInstance))\n cleanupFns.push(registerList(editorInstance))\n cleanupFns.push(registerHistory(editorInstance, createEmptyHistoryState(), 300))\n\n // Set initial value\n if (model.value) {\n setEditorContent(editorInstance, model.value)\n }\n\n // Listen for content changes\n cleanupFns.push(\n editorInstance.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n const root = $getRoot()\n const textContent = root.getTextContent()\n showPlaceholder.value = textContent.trim().length === 0\n\n if (isComposing) return\n\n let value: string\n if (props.format === 'json') {\n value = JSON.stringify(editorState.toJSON())\n } else {\n value = $generateHtmlFromNodes(editorInstance)\n }\n\n // Avoid circular updates: only emit if content really changed\n if (value !== model.value) {\n isComposing = true\n model.value = value\n // Use microtask to reset after Vue processes the update\n queueMicrotask(() => {\n isComposing = false\n })\n }\n })\n })\n )\n\n // Composing event listeners for IME\n const rootElement = editorInstance.getRootElement()\n if (rootElement) {\n const onCompositionStart = () => {\n isComposing = true\n }\n const onCompositionEnd = () => {\n isComposing = false\n }\n rootElement.addEventListener('compositionstart', onCompositionStart)\n rootElement.addEventListener('compositionend', onCompositionEnd)\n cleanupFns.push(() => {\n rootElement.removeEventListener('compositionstart', onCompositionStart)\n rootElement.removeEventListener('compositionend', onCompositionEnd)\n })\n }\n\n editor.value = editorInstance\n}\n\nfunction setEditorContent(editorInstance: LexicalEditor, value: string) {\n editorInstance.update(() => {\n const root = $getRoot()\n root.clear()\n\n if (props.format === 'json') {\n try {\n const parsedState = editorInstance.parseEditorState(value)\n editorInstance.setEditorState(parsedState)\n } catch {\n // If JSON parse fails, treat as empty\n root.append($createParagraphNode())\n }\n } else {\n // HTML format\n const parser = new DOMParser()\n const dom = parser.parseFromString(value, 'text/html')\n const nodes = $generateNodesFromDOM(editorInstance, dom)\n root.append(...nodes)\n }\n })\n}\n\n// Watch external model changes\nwatch(model, (newVal) => {\n if (!editor.value || isComposing) return\n\n const editorInstance = editor.value\n\n // Compare current content to avoid circular updates\n editorInstance.getEditorState().read(() => {\n let currentValue: string\n if (props.format === 'json') {\n currentValue = JSON.stringify(editorInstance.getEditorState().toJSON())\n } else {\n currentValue = $generateHtmlFromNodes(editorInstance)\n }\n\n if (currentValue !== newVal) {\n isComposing = true\n setEditorContent(editorInstance, newVal ?? '')\n queueMicrotask(() => {\n isComposing = false\n })\n }\n })\n})\n\n// Watch disabled/readonly changes\nwatch([isDisabled, isReadonly], () => {\n if (editor.value) {\n editor.value.setEditable(!isDisabled.value && !isReadonly.value)\n }\n})\n\nonMounted(() => {\n initEditor()\n})\n\nonBeforeUnmount(() => {\n cleanupFns.forEach((fn) => fn())\n cleanupFns = []\n editor.value = null\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;AAwBA,MAAM,gBAAgB;CACpB,WAAW;CACX,SAAS;EACP,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACL;CACD,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,WAAW;EACX,eAAe;EAChB;CACD,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,UAAU;EACV,QAAQ,EAAE,UAAU,oBAAmB;EACxC;CACD,OAAO;CAEP,MAAM;CACN,OAAO;CACT;AAEA,MAAM,kBAAiC;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBA,MAAM,QAAQ;EAQd,MAAM,QAAQ,SAAmB,SAAA,aAAC;EAElC,MAAM,MAAM,IAAI,mBAAkB;EAElC,MAAM,EAAE,cAAc,mBAAkB;EAExC,MAAM,EAAE,MAAM,UAAU,aAAa,qBAAqB,CAAC,aAAa,EAAE,EAAE,MAAM,CAAA;EAElF,MAAM,aAAa,eAAe,CAAC,CAAC,SAAS,MAAK;EAClD,MAAM,aAAa,eAAe,CAAC,CAAC,SAAS,MAAK;EAElD,MAAM,YAAY,eAAyB;AACzC,UAAO;IACL,IAAI;IACJ,IAAI,EAAE,KAAK,MAAM;IACjB,IAAI,GAAG,YAAY,WAAW,MAAM;IACpC,IAAI,GAAG,YAAY,WAAW,MAAK;IACrC;IACD;EAED,MAAM,eAAe,eAA8B;AACjD,UAAO,MAAM,WAAW;IACzB;EAED,MAAM,kBAAkB,eAAe,kBAAiB;EACxD,MAAM,SAAS,WAAiC,KAAI;EACpD,MAAM,kBAAkB,IAAI,KAAI;EAChC,IAAI,cAAc;E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A,CAChB,mBAIO,OAAA;aAHD;IAAJ,KAAI;IACH,OAAK,eAAE,MAAA,IAAG,CAAC,EAAC,WAAA,CAAA;IACZ,iBAAe,CAAG,WAAA,SAAU,CAAK,WAAA;6BAEzB,gBAAA,SAAA,WAAA,EAAX,mBAEM,OAAA;;IAFuB,OAAK,eAAE,MAAA,IAAG,CAAC,EAAC,cAAA,CAAA;sBACpC,QAAA,YAAW,EAAA,EAAA,IAAA,mBAAA,QAAA,KAAA,CAAA,EAAA,EAAA,CAAA,EAAA,EAAA"}
|
|
1
|
+
{"version":3,"file":"rich-text-editor.js","names":[],"sources":["../../../src/components/rich-text-editor/rich-text-editor.vue"],"sourcesContent":["<template>\n <div :class=\"className\">\n <toolbar\n v-if=\"!isReadonly && toolbarItems.length > 0\"\n :editor=\"editor\"\n :toolbar=\"toolbarItems\"\n :disabled=\"isDisabled\"\n />\n <div :class=\"cls.e('content')\">\n <div\n ref=\"editorContainer\"\n :class=\"cls.e('editable')\"\n :contenteditable=\"!isDisabled && !isReadonly\"\n ></div>\n <div v-if=\"showPlaceholder\" :class=\"cls.e('placeholder')\">\n {{ placeholder }}\n </div>\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { ToolbarItem } from '../../types'\n\nconst LEXICAL_THEME = {\n paragraph: 'u-rte-paragraph',\n heading: {\n h1: 'u-rte-h1',\n h2: 'u-rte-h2',\n h3: 'u-rte-h3',\n h4: 'u-rte-h4',\n h5: 'u-rte-h5',\n h6: 'u-rte-h6'\n },\n text: {\n bold: 'u-rte-bold',\n italic: 'u-rte-italic',\n underline: 'u-rte-underline',\n strikethrough: 'u-rte-strikethrough'\n },\n list: {\n ul: 'u-rte-ul',\n ol: 'u-rte-ol',\n listitem: 'u-rte-li',\n nested: { listitem: 'u-rte-li--nested' }\n },\n quote: 'u-rte-blockquote',\n\n link: 'u-rte-link',\n image: 'u-rte-image'\n}\n\nconst DEFAULT_TOOLBAR: ToolbarItem[] = [\n 'undo',\n 'redo',\n '|',\n 'heading',\n '|',\n 'bold',\n 'italic',\n 'underline',\n 'strikethrough',\n '|',\n 'bullet-list',\n 'ordered-list',\n '|',\n 'blockquote',\n '|',\n 'link'\n]\n</script>\n\n<script lang=\"ts\" setup>\nimport { registerHistory, createEmptyHistoryState } from '@lexical/history'\nimport { $generateHtmlFromNodes, $generateNodesFromDOM } from '@lexical/html'\nimport { LinkNode, AutoLinkNode } from '@lexical/link'\nimport { ListNode, ListItemNode, registerList } from '@lexical/list'\nimport { registerRichText } from '@lexical/rich-text'\nimport { HeadingNode, QuoteNode } from '@lexical/rich-text'\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem } from '@veltra/utils'\nimport { injectFormContext } from '@veltra/utils'\nimport { createEditor, $getRoot, $createParagraphNode, type LexicalEditor } from 'lexical'\nimport { computed, onBeforeUnmount, onMounted, ref, shallowRef, useTemplateRef, watch } from 'vue'\n\nimport type { RichTextEditorProps } from '../../types'\nimport Toolbar from './toolbar.vue'\n\nconst props = withDefaults(defineProps<RichTextEditorProps>(), {\n disabled: undefined,\n readonly: undefined,\n format: 'html',\n toolbar: () => DEFAULT_TOOLBAR,\n placeholder: ''\n})\n\nconst model = defineModel<string>()\n\nconst cls = bem('rich-text-editor')\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props])\n\nconst isDisabled = computed(() => !!disabled.value)\nconst isReadonly = computed(() => !!readonly.value)\n\nconst className = computed<string[]>(() => {\n return [\n cls.b,\n cls.m(size.value),\n bem.is('disabled', isDisabled.value),\n bem.is('readonly', isReadonly.value)\n ]\n})\n\nconst toolbarItems = computed<ToolbarItem[]>(() => {\n return props.toolbar ?? DEFAULT_TOOLBAR\n})\n\nconst editorContainer = useTemplateRef('editorContainer')\nconst editor = shallowRef<LexicalEditor | null>(null)\nconst showPlaceholder = ref(true)\nlet isComposing = false\nlet cleanupFns: (() => void)[] = []\n\nfunction initEditor() {\n if (!editorContainer.value) return\n\n const editorInstance = createEditor({\n namespace: 'URichTextEditor',\n theme: LEXICAL_THEME,\n nodes: [HeadingNode, QuoteNode, ListNode, ListItemNode, LinkNode, AutoLinkNode],\n editable: !isDisabled.value && !isReadonly.value,\n onError: (error: Error) => {\n console.error('Lexical error:', error)\n }\n })\n\n editorInstance.setRootElement(editorContainer.value)\n\n // Register plugins\n cleanupFns.push(registerRichText(editorInstance))\n cleanupFns.push(registerList(editorInstance))\n cleanupFns.push(registerHistory(editorInstance, createEmptyHistoryState(), 300))\n\n // Set initial value\n if (model.value) {\n setEditorContent(editorInstance, model.value)\n }\n\n // Listen for content changes\n cleanupFns.push(\n editorInstance.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n const root = $getRoot()\n const textContent = root.getTextContent()\n showPlaceholder.value = textContent.trim().length === 0\n\n if (isComposing) return\n\n let value: string\n if (props.format === 'json') {\n value = JSON.stringify(editorState.toJSON())\n } else {\n value = $generateHtmlFromNodes(editorInstance)\n }\n\n // Avoid circular updates: only emit if content really changed\n if (value !== model.value) {\n isComposing = true\n model.value = value\n // Use microtask to reset after Vue processes the update\n queueMicrotask(() => {\n isComposing = false\n })\n }\n })\n })\n )\n\n // Composing event listeners for IME\n const rootElement = editorInstance.getRootElement()\n if (rootElement) {\n const onCompositionStart = () => {\n isComposing = true\n }\n const onCompositionEnd = () => {\n isComposing = false\n }\n rootElement.addEventListener('compositionstart', onCompositionStart)\n rootElement.addEventListener('compositionend', onCompositionEnd)\n cleanupFns.push(() => {\n rootElement.removeEventListener('compositionstart', onCompositionStart)\n rootElement.removeEventListener('compositionend', onCompositionEnd)\n })\n }\n\n editor.value = editorInstance\n}\n\nfunction setEditorContent(editorInstance: LexicalEditor, value: string) {\n editorInstance.update(() => {\n const root = $getRoot()\n root.clear()\n\n if (props.format === 'json') {\n try {\n const parsedState = editorInstance.parseEditorState(value)\n editorInstance.setEditorState(parsedState)\n } catch {\n // If JSON parse fails, treat as empty\n root.append($createParagraphNode())\n }\n } else {\n // HTML format\n const parser = new DOMParser()\n const dom = parser.parseFromString(value, 'text/html')\n const nodes = $generateNodesFromDOM(editorInstance, dom)\n root.append(...nodes)\n }\n })\n}\n\n// Watch external model changes\nwatch(model, (newVal) => {\n if (!editor.value || isComposing) return\n\n const editorInstance = editor.value\n\n // Compare current content to avoid circular updates\n editorInstance.getEditorState().read(() => {\n let currentValue: string\n if (props.format === 'json') {\n currentValue = JSON.stringify(editorInstance.getEditorState().toJSON())\n } else {\n currentValue = $generateHtmlFromNodes(editorInstance)\n }\n\n if (currentValue !== newVal) {\n isComposing = true\n setEditorContent(editorInstance, newVal ?? '')\n queueMicrotask(() => {\n isComposing = false\n })\n }\n })\n})\n\n// Watch disabled/readonly changes\nwatch([isDisabled, isReadonly], () => {\n if (editor.value) {\n editor.value.setEditable(!isDisabled.value && !isReadonly.value)\n }\n})\n\nonMounted(() => {\n initEditor()\n})\n\nonBeforeUnmount(() => {\n cleanupFns.forEach((fn) => fn())\n cleanupFns = []\n editor.value = null\n})\n</script>\n"],"mappings":";;;;;;;;;;;;AAwBA,MAAM,gBAAgB;CACpB,WAAW;CACX,SAAS;EACP,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACL;CACD,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,WAAW;EACX,eAAe;EAChB;CACD,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,UAAU;EACV,QAAQ,EAAE,UAAU,oBAAmB;EACxC;CACD,OAAO;CAEP,MAAM;CACN,OAAO;CACT;AAEA,MAAM,kBAAiC;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBA,MAAM,QAAQ;EAQd,MAAM,QAAQ,SAAmB,SAAA,aAAC;EAElC,MAAM,MAAM,IAAI,mBAAkB;EAElC,MAAM,EAAE,cAAc,mBAAkB;EAExC,MAAM,EAAE,MAAM,UAAU,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I,OAAO,MACT,QAAO,MAAM,YAAY,CAAC,WAAW,SAAS,CAAC,WAAW,MAAK;IAElE;AAED,kBAAgB;AACd,eAAW;IACZ;AAED,wBAAsB;AACpB,cAAW,SAAS,OAAO,IAAI,CAAA;AAC/B,gBAAa,EAAC;AACd,UAAO,QAAQ;IAChB;;uBAvQC,mBAiBM,OAAA,EAjBA,OAAK,eAAE,UAAA,MAAS,EAAA,EAAA,CAAA,CAEX,WAAA,SAAc,aAAA,MAAa,SAAM,KAAA,WAAA,EAD1C,YAKE,aAAA;;IAHC,QAAQ,OAAA;IACR,SAAS,aAAA;IACT,UAAU,WAAA;;;;;2CAEb,mBASM,OAAA,EATA,OAAK,eAAE,MAAA,IAAG,CAAC,EAAC,UAAA,CAAA,EAAA,EAAA,CAChB,mBAIO,OAAA;aAHD;IAAJ,KAAI;IACH,OAAK,eAAE,MAAA,IAAG,CAAC,EAAC,WAAA,CAAA;IACZ,iBAAe,CAAG,WAAA,SAAU,CAAK,WAAA;6BAEzB,gBAAA,SAAA,WAAA,EAAX,mBAEM,OAAA;;IAFuB,OAAK,eAAE,MAAA,IAAG,CAAC,EAAC,cAAA,CAAA;sBACpC,QAAA,YAAW,EAAA,EAAA,IAAA,mBAAA,QAAA,KAAA,CAAA,EAAA,EAAA,CAAA,EAAA,EAAA"}
|
|
@@ -12,9 +12,9 @@ declare const __VLS_export: _$vue.DefineComponent<RichTextEditorProps & {
|
|
|
12
12
|
}> & Readonly<{
|
|
13
13
|
"onUpdate:modelValue"?: ((value: string | undefined) => any) | undefined;
|
|
14
14
|
}>, {
|
|
15
|
+
placeholder: string;
|
|
15
16
|
disabled: boolean;
|
|
16
17
|
readonly: boolean;
|
|
17
|
-
placeholder: string;
|
|
18
18
|
format: RichTextFormat;
|
|
19
19
|
toolbar: ToolbarItem[];
|
|
20
20
|
}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import _sfc_main$1 from "../scroll/scroll.js";
|
|
2
2
|
import _sfc_main$2 from "../icon/icon.js";
|
|
3
|
-
import { injectFormContext } from "../../utils/form-context.js";
|
|
4
3
|
import _sfc_main$3 from "../empty/empty.js";
|
|
5
4
|
import _sfc_main$4 from "../dropdown/dropdown.js";
|
|
6
5
|
import input_default from "../input/input.js";
|
|
7
6
|
import { useOptions } from "./use-options.js";
|
|
8
7
|
import { useKeyboard } from "./use-keyboard.js";
|
|
9
8
|
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createSlots, createTextVNode, createVNode, defineComponent, isRef, mergeModels, mergeProps, nextTick, normalizeClass, normalizeStyle, openBlock, renderList, renderSlot, shallowRef, toDisplayString, unref, useModel, watch, withCtx, withDirectives } from "vue";
|
|
10
|
-
import { FORM_EMPTY_CONTENT, bem, scrollIntoContainerView, withUnit } from "@veltra/utils";
|
|
9
|
+
import { FORM_EMPTY_CONTENT, bem, injectFormContext, scrollIntoContainerView, withUnit } from "@veltra/utils";
|
|
11
10
|
import { useFormFallbackProps, useVirtualizer } from "@veltra/compositions";
|
|
12
11
|
import { o } from "@cat-kit/core";
|
|
13
12
|
import { ArrowDown, Search } from "@veltra/icons/normal";
|