naive-ui 2.30.3 → 2.30.6
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/index.js +1829 -1088
- package/dist/index.prod.js +2 -2
- package/es/_internal/scrollbar/src/Scrollbar.js +5 -18
- package/es/_internal/select-menu/src/SelectGroupHeader.d.ts +1 -0
- package/es/_internal/select-menu/src/SelectGroupHeader.js +5 -3
- package/es/_internal/select-menu/src/SelectMenu.d.ts +3 -3
- package/es/_internal/select-menu/src/SelectMenu.js +6 -8
- package/es/_internal/select-menu/src/SelectOption.d.ts +1 -0
- package/es/_internal/select-menu/src/SelectOption.js +11 -5
- package/es/_internal/select-menu/src/interface.d.ts +3 -1
- package/es/_internal/selection/src/Selection.d.ts +0 -2
- package/es/_internal/selection/src/Selection.js +7 -5
- package/es/_mixins/use-theme.js +1 -1
- package/es/_utils/composable/index.d.ts +3 -5
- package/es/_utils/composable/index.js +3 -111
- package/es/_utils/composable/use-collection.d.ts +4 -0
- package/es/_utils/composable/use-collection.js +87 -0
- package/es/_utils/composable/use-deferred-true.d.ts +2 -0
- package/es/_utils/composable/use-deferred-true.js +25 -0
- package/es/_utils/composable/use-reactivated.d.ts +3 -0
- package/es/_utils/composable/use-reactivated.js +20 -0
- package/es/_utils/dom/index.d.ts +1 -0
- package/es/_utils/dom/index.js +1 -0
- package/es/_utils/dom/is-document.d.ts +1 -0
- package/es/_utils/dom/is-document.js +3 -0
- package/es/_utils/event/index.d.ts +2 -0
- package/es/_utils/event/index.js +7 -0
- package/es/_utils/index.d.ts +3 -1
- package/es/_utils/index.js +3 -1
- package/es/_utils/vue/index.d.ts +3 -0
- package/es/_utils/vue/index.js +3 -0
- package/es/_utils/vue/is-node-v-show-false.d.ts +2 -0
- package/es/_utils/vue/is-node-v-show-false.js +6 -0
- package/es/_utils/vue/merge-handlers.d.ts +1 -0
- package/es/_utils/vue/merge-handlers.js +15 -0
- package/es/{_internal/scrollbar/src/Wrapper.d.ts → _utils/vue/wrapper.d.ts} +0 -0
- package/es/{_internal/scrollbar/src/Wrapper.js → _utils/vue/wrapper.js} +0 -0
- package/es/back-top/src/BackTop.d.ts +1 -1
- package/es/back-top/src/BackTop.js +24 -31
- package/es/button/src/Button.js +7 -2
- package/es/cascader/src/Cascader.d.ts +2 -3
- package/es/cascader/src/Cascader.js +26 -22
- package/es/cascader/src/CascaderMenu.d.ts +2 -2
- package/es/cascader/src/CascaderMenu.js +2 -4
- package/es/color-picker/src/ColorInputUnit.js +1 -1
- package/es/data-table/src/DataTable.d.ts +792 -2
- package/es/data-table/src/DataTable.js +10 -5
- package/es/data-table/src/HeaderButton/FilterButton.d.ts +142 -0
- package/es/data-table/src/HeaderButton/FilterMenu.d.ts +142 -0
- package/es/data-table/src/MainTable.d.ts +2 -0
- package/es/data-table/src/MainTable.js +5 -1
- package/es/data-table/src/TableParts/Body.d.ts +144 -0
- package/es/data-table/src/TableParts/Body.js +15 -8
- package/es/data-table/src/TableParts/Cell.d.ts +295 -1
- package/es/data-table/src/TableParts/Cell.js +19 -6
- package/es/data-table/src/TableParts/Header.d.ts +143 -0
- package/es/data-table/src/TableParts/Header.js +6 -2
- package/es/data-table/src/interface.d.ts +14 -7
- package/es/data-table/src/styles/index.cssr.js +7 -2
- package/es/data-table/src/use-check.js +11 -3
- package/es/data-table/src/use-expand.d.ts +5 -3
- package/es/data-table/src/use-expand.js +22 -2
- package/es/data-table/src/utils.d.ts +2 -2
- package/es/data-table/src/utils.js +10 -8
- package/es/data-table/styles/light.d.ts +71 -0
- package/es/date-picker/src/DatePicker.d.ts +2 -1
- package/es/date-picker/src/DatePicker.js +20 -9
- package/es/date-picker/src/panel/month.js +3 -2
- package/es/drawer/src/Drawer.d.ts +1 -1
- package/es/drawer/src/Drawer.js +3 -3
- package/es/drawer/src/DrawerBodyWrapper.d.ts +2 -2
- package/es/dropdown/src/Dropdown.d.ts +4 -0
- package/es/dynamic-tags/src/DynamicTags.js +1 -1
- package/es/grid/src/Grid.d.ts +3 -0
- package/es/grid/src/Grid.js +47 -9
- package/es/grid/src/GridItem.js +2 -1
- package/es/image/src/Image.d.ts +10 -0
- package/es/image/src/Image.js +42 -8
- package/es/image/src/utils.d.ts +11 -0
- package/es/image/src/utils.js +81 -0
- package/es/input/src/Input.d.ts +6 -3
- package/es/input/src/Input.js +56 -31
- package/es/input/src/styles/input-group-label.cssr.js +2 -0
- package/es/input/src/utils.d.ts +7 -1
- package/es/input/src/utils.js +57 -2
- package/es/layout/src/Layout.d.ts +3 -1
- package/es/layout/src/Layout.js +22 -4
- package/es/layout/src/LayoutContent.d.ts +1 -0
- package/es/layout/src/LayoutSider.d.ts +1 -0
- package/es/layout/src/LayoutSider.js +22 -3
- package/es/menu/src/Menu.d.ts +1 -1
- package/es/modal/src/BodyWrapper.d.ts +15 -20
- package/es/modal/src/BodyWrapper.js +38 -33
- package/es/modal/src/Modal.js +14 -9
- package/es/pagination/src/Pagination.d.ts +806 -20
- package/es/pagination/src/Pagination.js +115 -52
- package/es/pagination/src/interface.d.ts +2 -2
- package/es/pagination/src/styles/index.cssr.js +12 -10
- package/es/pagination/src/utils.d.ts +15 -5
- package/es/pagination/src/utils.js +117 -50
- package/es/pagination/styles/dark.js +3 -1
- package/es/pagination/styles/light.d.ts +71 -0
- package/es/pagination/styles/light.js +3 -1
- package/es/popconfirm/src/Popconfirm.d.ts +4 -0
- package/es/popover/src/Popover.d.ts +5 -0
- package/es/popover/src/Popover.js +1 -0
- package/es/popover/src/PopoverBody.d.ts +4 -0
- package/es/popover/src/PopoverBody.js +18 -10
- package/es/popselect/src/Popselect.d.ts +24 -0
- package/es/popselect/src/Popselect.js +12 -7
- package/es/popselect/src/PopselectPanel.d.ts +22 -2
- package/es/popselect/src/PopselectPanel.js +12 -1
- package/es/select/src/Select.d.ts +1 -1
- package/es/select/src/Select.js +5 -2
- package/es/slider/src/Slider.d.ts +1 -1
- package/es/slider/src/Slider.js +13 -5
- package/es/slider/src/styles/index.cssr.js +26 -31
- package/es/space/src/Space.d.ts +26 -0
- package/es/space/src/Space.js +53 -43
- package/es/time-picker/src/TimePicker.d.ts +2 -1
- package/es/time-picker/src/TimePicker.js +18 -8
- package/es/tooltip/index.d.ts +1 -1
- package/es/tooltip/src/Tooltip.d.ts +4 -0
- package/es/tree/src/Tree.d.ts +2 -3
- package/es/tree/src/Tree.js +6 -8
- package/es/tree/src/TreeNode.js +4 -1
- package/es/tree/src/interface.d.ts +0 -1
- package/es/tree/src/keyboard.d.ts +0 -1
- package/es/tree/src/keyboard.js +6 -9
- package/es/tree-select/src/TreeSelect.d.ts +1 -3
- package/es/tree-select/src/TreeSelect.js +14 -16
- package/es/upload/src/UploadDragger.js +2 -2
- package/es/upload/src/UploadFile.d.ts +2 -2
- package/es/upload/src/UploadFile.js +9 -4
- package/es/upload/src/UploadTrigger.js +4 -3
- package/es/upload/src/styles/index.cssr.js +2 -2
- package/es/upload/src/utils.js +1 -15
- package/es/version.d.ts +1 -1
- package/es/version.js +1 -1
- package/lib/_internal/scrollbar/src/Scrollbar.js +6 -19
- package/lib/_internal/select-menu/src/SelectGroupHeader.d.ts +1 -0
- package/lib/_internal/select-menu/src/SelectGroupHeader.js +5 -3
- package/lib/_internal/select-menu/src/SelectMenu.d.ts +3 -3
- package/lib/_internal/select-menu/src/SelectMenu.js +5 -7
- package/lib/_internal/select-menu/src/SelectOption.d.ts +1 -0
- package/lib/_internal/select-menu/src/SelectOption.js +10 -4
- package/lib/_internal/select-menu/src/interface.d.ts +3 -1
- package/lib/_internal/selection/src/Selection.d.ts +0 -2
- package/lib/_internal/selection/src/Selection.js +6 -4
- package/lib/_mixins/use-theme.js +1 -1
- package/lib/_utils/composable/index.d.ts +3 -5
- package/lib/_utils/composable/index.js +9 -116
- package/lib/_utils/composable/use-collection.d.ts +4 -0
- package/lib/_utils/composable/use-collection.js +93 -0
- package/lib/_utils/composable/use-deferred-true.d.ts +2 -0
- package/lib/_utils/composable/use-deferred-true.js +29 -0
- package/lib/_utils/composable/use-reactivated.d.ts +3 -0
- package/lib/_utils/composable/use-reactivated.js +24 -0
- package/lib/_utils/dom/index.d.ts +1 -0
- package/lib/_utils/dom/index.js +5 -0
- package/lib/_utils/dom/is-document.d.ts +1 -0
- package/lib/_utils/dom/is-document.js +7 -0
- package/lib/_utils/event/index.d.ts +2 -0
- package/lib/_utils/event/index.js +12 -0
- package/lib/_utils/index.d.ts +3 -1
- package/lib/_utils/index.js +8 -1
- package/lib/_utils/vue/index.d.ts +3 -0
- package/lib/_utils/vue/index.js +7 -1
- package/lib/_utils/vue/is-node-v-show-false.d.ts +2 -0
- package/lib/_utils/vue/is-node-v-show-false.js +10 -0
- package/lib/_utils/vue/merge-handlers.d.ts +1 -0
- package/lib/_utils/vue/merge-handlers.js +19 -0
- package/lib/{_internal/scrollbar/src/Wrapper.d.ts → _utils/vue/wrapper.d.ts} +0 -0
- package/lib/{_internal/scrollbar/src/Wrapper.js → _utils/vue/wrapper.js} +0 -0
- package/lib/back-top/src/BackTop.d.ts +1 -1
- package/lib/back-top/src/BackTop.js +23 -30
- package/lib/button/src/Button.js +7 -2
- package/lib/cascader/src/Cascader.d.ts +2 -3
- package/lib/cascader/src/Cascader.js +25 -21
- package/lib/cascader/src/CascaderMenu.d.ts +2 -2
- package/lib/cascader/src/CascaderMenu.js +2 -4
- package/lib/color-picker/src/ColorInputUnit.js +1 -1
- package/lib/data-table/src/DataTable.d.ts +792 -2
- package/lib/data-table/src/DataTable.js +10 -5
- package/lib/data-table/src/HeaderButton/FilterButton.d.ts +142 -0
- package/lib/data-table/src/HeaderButton/FilterMenu.d.ts +142 -0
- package/lib/data-table/src/MainTable.d.ts +2 -0
- package/lib/data-table/src/MainTable.js +5 -1
- package/lib/data-table/src/TableParts/Body.d.ts +144 -0
- package/lib/data-table/src/TableParts/Body.js +15 -8
- package/lib/data-table/src/TableParts/Cell.d.ts +295 -1
- package/lib/data-table/src/TableParts/Cell.js +19 -6
- package/lib/data-table/src/TableParts/Header.d.ts +143 -0
- package/lib/data-table/src/TableParts/Header.js +6 -2
- package/lib/data-table/src/interface.d.ts +14 -7
- package/lib/data-table/src/styles/index.cssr.js +7 -2
- package/lib/data-table/src/use-check.js +11 -3
- package/lib/data-table/src/use-expand.d.ts +5 -3
- package/lib/data-table/src/use-expand.js +22 -2
- package/lib/data-table/src/utils.d.ts +2 -2
- package/lib/data-table/src/utils.js +11 -9
- package/lib/data-table/styles/light.d.ts +71 -0
- package/lib/date-picker/src/DatePicker.d.ts +2 -1
- package/lib/date-picker/src/DatePicker.js +19 -8
- package/lib/date-picker/src/panel/month.js +3 -2
- package/lib/drawer/src/Drawer.d.ts +1 -1
- package/lib/drawer/src/Drawer.js +2 -2
- package/lib/drawer/src/DrawerBodyWrapper.d.ts +2 -2
- package/lib/dropdown/src/Dropdown.d.ts +4 -0
- package/lib/dynamic-tags/src/DynamicTags.js +1 -1
- package/lib/grid/src/Grid.d.ts +3 -0
- package/lib/grid/src/Grid.js +45 -7
- package/lib/grid/src/GridItem.js +2 -1
- package/lib/image/src/Image.d.ts +10 -0
- package/lib/image/src/Image.js +41 -7
- package/lib/image/src/utils.d.ts +11 -0
- package/lib/image/src/utils.js +86 -0
- package/lib/input/src/Input.d.ts +6 -3
- package/lib/input/src/Input.js +55 -30
- package/lib/input/src/styles/input-group-label.cssr.js +2 -0
- package/lib/input/src/utils.d.ts +7 -1
- package/lib/input/src/utils.js +60 -4
- package/lib/layout/src/Layout.d.ts +3 -1
- package/lib/layout/src/Layout.js +22 -4
- package/lib/layout/src/LayoutContent.d.ts +1 -0
- package/lib/layout/src/LayoutSider.d.ts +1 -0
- package/lib/layout/src/LayoutSider.js +21 -2
- package/lib/menu/src/Menu.d.ts +1 -1
- package/lib/modal/src/BodyWrapper.d.ts +15 -20
- package/lib/modal/src/BodyWrapper.js +38 -33
- package/lib/modal/src/Modal.js +13 -8
- package/lib/pagination/src/Pagination.d.ts +806 -20
- package/lib/pagination/src/Pagination.js +114 -51
- package/lib/pagination/src/interface.d.ts +2 -2
- package/lib/pagination/src/styles/index.cssr.js +13 -11
- package/lib/pagination/src/utils.d.ts +15 -5
- package/lib/pagination/src/utils.js +118 -53
- package/lib/pagination/styles/dark.js +6 -4
- package/lib/pagination/styles/light.d.ts +71 -0
- package/lib/pagination/styles/light.js +6 -4
- package/lib/popconfirm/src/Popconfirm.d.ts +4 -0
- package/lib/popover/src/Popover.d.ts +5 -0
- package/lib/popover/src/Popover.js +1 -0
- package/lib/popover/src/PopoverBody.d.ts +4 -0
- package/lib/popover/src/PopoverBody.js +18 -10
- package/lib/popselect/src/Popselect.d.ts +24 -0
- package/lib/popselect/src/Popselect.js +10 -5
- package/lib/popselect/src/PopselectPanel.d.ts +22 -2
- package/lib/popselect/src/PopselectPanel.js +12 -1
- package/lib/select/src/Select.d.ts +1 -1
- package/lib/select/src/Select.js +4 -1
- package/lib/slider/src/Slider.d.ts +1 -1
- package/lib/slider/src/Slider.js +12 -4
- package/lib/slider/src/styles/index.cssr.js +26 -31
- package/lib/space/src/Space.d.ts +26 -0
- package/lib/space/src/Space.js +53 -43
- package/lib/time-picker/src/TimePicker.d.ts +2 -1
- package/lib/time-picker/src/TimePicker.js +17 -7
- package/lib/tooltip/index.d.ts +1 -1
- package/lib/tooltip/src/Tooltip.d.ts +4 -0
- package/lib/tree/src/Tree.d.ts +2 -3
- package/lib/tree/src/Tree.js +6 -8
- package/lib/tree/src/TreeNode.js +4 -1
- package/lib/tree/src/interface.d.ts +0 -1
- package/lib/tree/src/keyboard.d.ts +0 -1
- package/lib/tree/src/keyboard.js +6 -9
- package/lib/tree-select/src/TreeSelect.d.ts +1 -3
- package/lib/tree-select/src/TreeSelect.js +13 -15
- package/lib/upload/src/UploadDragger.js +2 -2
- package/lib/upload/src/UploadFile.d.ts +2 -2
- package/lib/upload/src/UploadFile.js +9 -4
- package/lib/upload/src/UploadTrigger.js +3 -2
- package/lib/upload/src/styles/index.cssr.js +2 -2
- package/lib/upload/src/utils.js +1 -15
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +2 -2
- package/volar.d.ts +0 -1
- package/web-types.json +73 -1
package/es/image/src/Image.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { defineComponent, h, inject, ref, toRef, watchEffect, onMounted } from 'vue';
|
|
1
|
+
import { defineComponent, h, inject, ref, toRef, watchEffect, onMounted, onBeforeUnmount } from 'vue';
|
|
2
2
|
import NImagePreview from './ImagePreview';
|
|
3
3
|
import { imageGroupInjectionKey } from './ImageGroup';
|
|
4
4
|
import { useConfig } from '../../_mixins';
|
|
5
5
|
import { imagePreviewSharedProps } from './interface';
|
|
6
|
-
|
|
6
|
+
import { observeIntersection } from './utils';
|
|
7
|
+
const imageProps = Object.assign({ alt: String, height: [String, Number], imgProps: Object, lazy: Boolean, intersectionObserverOptions: Object, objectFit: {
|
|
7
8
|
type: String,
|
|
8
9
|
default: 'fill'
|
|
9
10
|
}, previewSrc: String, fallbackSrc: String, width: [String, Number], src: String, previewDisabled: Boolean, loadDescription: String, onError: Function, onLoad: Function }, imagePreviewSharedProps);
|
|
@@ -37,18 +38,36 @@ export default defineComponent({
|
|
|
37
38
|
previewInst.toggleShow();
|
|
38
39
|
}
|
|
39
40
|
};
|
|
41
|
+
const shouldStartLoadingRef = ref(!props.lazy);
|
|
40
42
|
onMounted(() => {
|
|
41
43
|
var _a;
|
|
42
44
|
(_a = imageRef.value) === null || _a === void 0 ? void 0 : _a.setAttribute('data-group-id', (imageGroupHandle === null || imageGroupHandle === void 0 ? void 0 : imageGroupHandle.groupId) || '');
|
|
43
45
|
});
|
|
46
|
+
onMounted(() => {
|
|
47
|
+
let unobserve;
|
|
48
|
+
const stopWatchHandle = watchEffect(() => {
|
|
49
|
+
unobserve === null || unobserve === void 0 ? void 0 : unobserve();
|
|
50
|
+
unobserve = undefined;
|
|
51
|
+
if (props.lazy) {
|
|
52
|
+
unobserve = observeIntersection(imageRef.value, props.intersectionObserverOptions, shouldStartLoadingRef);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
onBeforeUnmount(() => {
|
|
56
|
+
stopWatchHandle();
|
|
57
|
+
unobserve === null || unobserve === void 0 ? void 0 : unobserve();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
44
60
|
watchEffect(() => {
|
|
45
61
|
var _a;
|
|
46
62
|
void props.src;
|
|
47
63
|
void ((_a = props.imgProps) === null || _a === void 0 ? void 0 : _a.src);
|
|
48
64
|
showErrorRef.value = false;
|
|
49
65
|
});
|
|
66
|
+
const loadedRef = ref(false);
|
|
50
67
|
return Object.assign({ mergedClsPrefix: mergedClsPrefixRef, groupId: imageGroupHandle === null || imageGroupHandle === void 0 ? void 0 : imageGroupHandle.groupId, previewInstRef,
|
|
51
|
-
imageRef, imgProps: imgPropsRef, showError: showErrorRef, mergedOnError: (e) => {
|
|
68
|
+
imageRef, imgProps: imgPropsRef, showError: showErrorRef, shouldStartLoading: shouldStartLoadingRef, loaded: loadedRef, mergedOnError: (e) => {
|
|
69
|
+
if (!shouldStartLoadingRef.value)
|
|
70
|
+
return;
|
|
52
71
|
showErrorRef.value = true;
|
|
53
72
|
const { onError, imgProps: { onError: imgPropsOnError } = {} } = props;
|
|
54
73
|
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
@@ -57,18 +76,33 @@ export default defineComponent({
|
|
|
57
76
|
const { onLoad, imgProps: { onLoad: imgPropsOnLoad } = {} } = props;
|
|
58
77
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad(e);
|
|
59
78
|
imgPropsOnLoad === null || imgPropsOnLoad === void 0 ? void 0 : imgPropsOnLoad(e);
|
|
79
|
+
loadedRef.value = true;
|
|
60
80
|
} }, exposedMethods);
|
|
61
81
|
},
|
|
62
82
|
render() {
|
|
63
|
-
|
|
64
|
-
const
|
|
83
|
+
var _a, _b;
|
|
84
|
+
const { mergedClsPrefix, imgProps = {}, loaded, $attrs } = this;
|
|
85
|
+
const placeholderNode = (_b = (_a = this.$slots).placeholder) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
86
|
+
const imgNode = (h("img", Object.assign({}, imgProps, { class: imgProps.class, ref: "imageRef", width: this.width || imgProps.width, height: this.height || imgProps.height, src: this.showError
|
|
87
|
+
? this.fallbackSrc
|
|
88
|
+
: this.shouldStartLoading
|
|
89
|
+
? this.src || imgProps.src
|
|
90
|
+
: undefined, alt: this.alt || imgProps.alt, "aria-label": this.alt || imgProps.alt, onClick: this.click, onError: this.mergedOnError, onLoad: this.mergedOnLoad, style: [
|
|
91
|
+
imgProps.style || '',
|
|
92
|
+
placeholderNode && !loaded
|
|
93
|
+
? { height: '0', width: '0', visibility: 'hidden' }
|
|
94
|
+
: '',
|
|
95
|
+
{ objectFit: this.objectFit }
|
|
96
|
+
], "data-error": this.showError, "data-preview-src": this.previewSrc || this.src })));
|
|
65
97
|
return (h("div", Object.assign({}, $attrs, { role: "none", class: [
|
|
66
98
|
$attrs.class,
|
|
67
99
|
`${mergedClsPrefix}-image`,
|
|
68
100
|
(this.previewDisabled || this.showError) &&
|
|
69
101
|
`${mergedClsPrefix}-image--preview-disabled`
|
|
70
|
-
] }),
|
|
71
|
-
|
|
72
|
-
|
|
102
|
+
] }),
|
|
103
|
+
this.groupId ? (imgNode) : (h(NImagePreview, { theme: this.theme, themeOverrides: this.themeOverrides, clsPrefix: mergedClsPrefix, ref: "previewInstRef", showToolbar: this.showToolbar, showToolbarTooltip: this.showToolbarTooltip }, {
|
|
104
|
+
default: () => imgNode
|
|
105
|
+
})),
|
|
106
|
+
!loaded && placeholderNode));
|
|
73
107
|
}
|
|
74
108
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
export declare type IntersectionObserverOptions = Omit<IntersectionObserverInit, 'root'> & {
|
|
3
|
+
root?: Element | Document | null | string;
|
|
4
|
+
};
|
|
5
|
+
export declare const resolveOptionsAndHash: (options?: IntersectionObserverOptions | undefined) => {
|
|
6
|
+
hash: string;
|
|
7
|
+
options: Omit<IntersectionObserverInit, "root"> & {
|
|
8
|
+
root: Element | Document;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const observeIntersection: (el: HTMLImageElement | null, options: IntersectionObserverOptions | undefined, shouldStartLoadingRef: Ref<boolean>) => () => void;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const resolveOptionsAndHash = (options = {}) => {
|
|
2
|
+
var _a;
|
|
3
|
+
const { root = null } = options;
|
|
4
|
+
return {
|
|
5
|
+
hash: `${options.rootMargin || '0px 0px 0px 0px'}-${Array.isArray(options.threshold)
|
|
6
|
+
? options.threshold.join(',')
|
|
7
|
+
: (_a = options.threshold) !== null && _a !== void 0 ? _a : '0'}`,
|
|
8
|
+
options: Object.assign(Object.assign({}, options), { root: (typeof root === 'string' ? document.querySelector(root) : root) ||
|
|
9
|
+
document.documentElement })
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
// root -> options -> [observer, elements]
|
|
13
|
+
const observers = new WeakMap();
|
|
14
|
+
const unobserveHandleMap = new WeakMap();
|
|
15
|
+
const shouldStartLoadingRefMap = new WeakMap();
|
|
16
|
+
export const observeIntersection = (el, options, shouldStartLoadingRef) => {
|
|
17
|
+
if (!el)
|
|
18
|
+
return () => { };
|
|
19
|
+
const resolvedOptionsAndHash = resolveOptionsAndHash(options);
|
|
20
|
+
const { root } = resolvedOptionsAndHash.options;
|
|
21
|
+
let rootObservers;
|
|
22
|
+
const _rootObservers = observers.get(root);
|
|
23
|
+
if (_rootObservers) {
|
|
24
|
+
rootObservers = _rootObservers;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
rootObservers = new Map();
|
|
28
|
+
observers.set(root, rootObservers);
|
|
29
|
+
}
|
|
30
|
+
let observer;
|
|
31
|
+
let observerAndObservedElements;
|
|
32
|
+
if (rootObservers.has(resolvedOptionsAndHash.hash)) {
|
|
33
|
+
observerAndObservedElements =
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
35
|
+
rootObservers.get(resolvedOptionsAndHash.hash);
|
|
36
|
+
if (!observerAndObservedElements[1].has(el)) {
|
|
37
|
+
observer = observerAndObservedElements[0];
|
|
38
|
+
observerAndObservedElements[1].add(el);
|
|
39
|
+
observer.observe(el);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
observer = new IntersectionObserver((entries) => {
|
|
44
|
+
entries.forEach((entry) => {
|
|
45
|
+
if (entry.isIntersecting) {
|
|
46
|
+
const _unobserve = unobserveHandleMap.get(entry.target);
|
|
47
|
+
const _shouldStartLoadingRef = shouldStartLoadingRefMap.get(entry.target);
|
|
48
|
+
if (_unobserve)
|
|
49
|
+
_unobserve();
|
|
50
|
+
if (_shouldStartLoadingRef) {
|
|
51
|
+
_shouldStartLoadingRef.value = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}, resolvedOptionsAndHash.options);
|
|
56
|
+
observer.observe(el);
|
|
57
|
+
observerAndObservedElements = [observer, new Set([el])];
|
|
58
|
+
rootObservers.set(resolvedOptionsAndHash.hash, observerAndObservedElements);
|
|
59
|
+
}
|
|
60
|
+
let unobservered = false;
|
|
61
|
+
const unobserve = () => {
|
|
62
|
+
if (unobservered)
|
|
63
|
+
return;
|
|
64
|
+
unobserveHandleMap.delete(el);
|
|
65
|
+
shouldStartLoadingRefMap.delete(el);
|
|
66
|
+
unobservered = true;
|
|
67
|
+
if (observerAndObservedElements[1].has(el)) {
|
|
68
|
+
observerAndObservedElements[0].unobserve(el);
|
|
69
|
+
observerAndObservedElements[1].delete(el);
|
|
70
|
+
}
|
|
71
|
+
if (observerAndObservedElements[1].size <= 0) {
|
|
72
|
+
rootObservers.delete(resolvedOptionsAndHash.hash);
|
|
73
|
+
}
|
|
74
|
+
if (!rootObservers.size) {
|
|
75
|
+
observers.delete(root);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
unobserveHandleMap.set(el, unobserve);
|
|
79
|
+
shouldStartLoadingRefMap.set(el, shouldStartLoadingRef);
|
|
80
|
+
return unobserve;
|
|
81
|
+
};
|
package/es/input/src/Input.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ declare const inputProps: {
|
|
|
61
61
|
type: BooleanConstructor;
|
|
62
62
|
default: undefined;
|
|
63
63
|
};
|
|
64
|
+
allowInput: PropType<(value: string) => boolean>;
|
|
64
65
|
onMousedown: PropType<(e: MouseEvent) => void>;
|
|
65
66
|
onKeydown: PropType<(e: KeyboardEvent) => void>;
|
|
66
67
|
onKeyup: PropType<(e: KeyboardEvent) => void>;
|
|
@@ -330,6 +331,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
330
331
|
type: BooleanConstructor;
|
|
331
332
|
default: undefined;
|
|
332
333
|
};
|
|
334
|
+
allowInput: PropType<(value: string) => boolean>;
|
|
333
335
|
onMousedown: PropType<(e: MouseEvent) => void>;
|
|
334
336
|
onKeydown: PropType<(e: KeyboardEvent) => void>;
|
|
335
337
|
onKeyup: PropType<(e: KeyboardEvent) => void>;
|
|
@@ -587,7 +589,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
587
589
|
handleCompositionEnd: (e: CompositionEvent) => void;
|
|
588
590
|
handleInput: (e: InputEvent | CompositionEvent | Event, index?: 0 | 1, event?: string) => void;
|
|
589
591
|
handleInputBlur: (e: FocusEvent) => void;
|
|
590
|
-
handleInputFocus: (e: FocusEvent) => void;
|
|
592
|
+
handleInputFocus: (e: FocusEvent, index: number) => void;
|
|
591
593
|
handleWrapperBlur: (e: FocusEvent) => void;
|
|
592
594
|
handleWrapperFocus: (e: FocusEvent) => void;
|
|
593
595
|
handleMouseEnter: () => void;
|
|
@@ -598,7 +600,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
598
600
|
handleClear: (e: MouseEvent) => void;
|
|
599
601
|
handlePasswordToggleClick: () => void;
|
|
600
602
|
handlePasswordToggleMousedown: (e: MouseEvent) => void;
|
|
601
|
-
|
|
603
|
+
handleWrapperKeydown: (e: KeyboardEvent) => void;
|
|
602
604
|
handleTextAreaMirrorResize: () => void;
|
|
603
605
|
getTextareaScrollContainer: () => HTMLTextAreaElement | null;
|
|
604
606
|
mergedTheme: import("vue").ComputedRef<{
|
|
@@ -655,7 +657,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
655
657
|
scrollbarWidth: string;
|
|
656
658
|
scrollbarHeight: string;
|
|
657
659
|
scrollbarBorderRadius: string;
|
|
658
|
-
progressRailColor: string;
|
|
660
|
+
progressRailColor: string;
|
|
659
661
|
railColor: string;
|
|
660
662
|
popoverColor: string;
|
|
661
663
|
tableColor: string;
|
|
@@ -887,6 +889,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
887
889
|
type: BooleanConstructor;
|
|
888
890
|
default: undefined;
|
|
889
891
|
};
|
|
892
|
+
allowInput: PropType<(value: string) => boolean>;
|
|
890
893
|
onMousedown: PropType<(e: MouseEvent) => void>;
|
|
891
894
|
onKeydown: PropType<(e: KeyboardEvent) => void>;
|
|
892
895
|
onKeyup: PropType<(e: KeyboardEvent) => void>;
|
package/es/input/src/Input.js
CHANGED
|
@@ -4,15 +4,15 @@ import { getPadding } from 'seemly';
|
|
|
4
4
|
import { VResizeObserver } from 'vueuc';
|
|
5
5
|
import { off, on } from 'evtd';
|
|
6
6
|
import { EyeIcon, EyeOffIcon } from '../../_internal/icons';
|
|
7
|
+
import useRtl from '../../_mixins/use-rtl';
|
|
7
8
|
import { NBaseClear, NBaseIcon, NBaseSuffix, NScrollbar } from '../../_internal';
|
|
8
9
|
import { useTheme, useLocale, useFormItem, useConfig, useThemeClass } from '../../_mixins';
|
|
9
10
|
import { call, createKey, resolveSlot, resolveWrappedSlot, warnOnce } from '../../_utils';
|
|
10
11
|
import { inputLight } from '../styles';
|
|
11
12
|
import { inputInjectionKey } from './interface';
|
|
12
|
-
import {
|
|
13
|
+
import { isEmptyInputValue, useCursor } from './utils';
|
|
13
14
|
import WordCount from './WordCount';
|
|
14
15
|
import style from './styles/input.cssr';
|
|
15
|
-
import useRtl from '../../_mixins/use-rtl';
|
|
16
16
|
const inputProps = Object.assign(Object.assign({}, useTheme.props), { bordered: {
|
|
17
17
|
type: Boolean,
|
|
18
18
|
default: undefined
|
|
@@ -43,7 +43,7 @@ const inputProps = Object.assign(Object.assign({}, useTheme.props), { bordered:
|
|
|
43
43
|
}, showCount: Boolean, loading: {
|
|
44
44
|
type: Boolean,
|
|
45
45
|
default: undefined
|
|
46
|
-
}, onMousedown: Function, onKeydown: Function, onKeyup: Function, onInput: [Function, Array], onFocus: [Function, Array], onBlur: [Function, Array], onClick: [Function, Array], onChange: [Function, Array], onClear: [Function, Array], status: String, 'onUpdate:value': [Function, Array], onUpdateValue: [Function, Array],
|
|
46
|
+
}, allowInput: Function, onMousedown: Function, onKeydown: Function, onKeyup: Function, onInput: [Function, Array], onFocus: [Function, Array], onBlur: [Function, Array], onClick: [Function, Array], onChange: [Function, Array], onClear: [Function, Array], status: String, 'onUpdate:value': [Function, Array], onUpdateValue: [Function, Array],
|
|
47
47
|
/** private */
|
|
48
48
|
textDecoration: [String, Array], attrSize: {
|
|
49
49
|
type: Number,
|
|
@@ -71,6 +71,8 @@ export default defineComponent({
|
|
|
71
71
|
const inputMirrorElRef = ref(null);
|
|
72
72
|
const inputElRef = ref(null);
|
|
73
73
|
const inputEl2Ref = ref(null);
|
|
74
|
+
const currentFocusedInputRef = ref(null);
|
|
75
|
+
const focusedInputCursorControl = useCursor(currentFocusedInputRef);
|
|
74
76
|
const textareaScrollbarInstRef = ref(null);
|
|
75
77
|
// local
|
|
76
78
|
const { localeRef } = useLocale('Input');
|
|
@@ -111,8 +113,8 @@ export default defineComponent({
|
|
|
111
113
|
const { value: mergedValue } = mergedValueRef;
|
|
112
114
|
const { value: mergedPlaceholder } = mergedPlaceholderRef;
|
|
113
115
|
return (!isComposing &&
|
|
114
|
-
(
|
|
115
|
-
(Array.isArray(mergedValue) &&
|
|
116
|
+
(isEmptyInputValue(mergedValue) ||
|
|
117
|
+
(Array.isArray(mergedValue) && isEmptyInputValue(mergedValue[0]))) &&
|
|
116
118
|
mergedPlaceholder[0]);
|
|
117
119
|
});
|
|
118
120
|
const showPlaceholder2Ref = computed(() => {
|
|
@@ -121,8 +123,8 @@ export default defineComponent({
|
|
|
121
123
|
const { value: mergedPlaceholder } = mergedPlaceholderRef;
|
|
122
124
|
return (!isComposing &&
|
|
123
125
|
mergedPlaceholder[1] &&
|
|
124
|
-
(
|
|
125
|
-
(Array.isArray(mergedValue) &&
|
|
126
|
+
(isEmptyInputValue(mergedValue) ||
|
|
127
|
+
(Array.isArray(mergedValue) && isEmptyInputValue(mergedValue[1]))));
|
|
126
128
|
});
|
|
127
129
|
// focus
|
|
128
130
|
const mergedFocusRef = useMemo(() => {
|
|
@@ -320,24 +322,37 @@ export default defineComponent({
|
|
|
320
322
|
syncSource = targetValue;
|
|
321
323
|
if (isComposingRef.value)
|
|
322
324
|
return;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
let { value } = mergedValueRef;
|
|
329
|
-
if (!Array.isArray(value)) {
|
|
330
|
-
value = ['', ''];
|
|
325
|
+
focusedInputCursorControl.recordCursor();
|
|
326
|
+
const isIncomingValueValid = allowInput(targetValue);
|
|
327
|
+
if (isIncomingValueValid) {
|
|
328
|
+
if (!props.pair) {
|
|
329
|
+
event === 'input' ? doUpdateValue(targetValue) : doChange(targetValue);
|
|
331
330
|
}
|
|
332
331
|
else {
|
|
333
|
-
value =
|
|
332
|
+
let { value } = mergedValueRef;
|
|
333
|
+
if (!Array.isArray(value)) {
|
|
334
|
+
value = ['', ''];
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
value = [value[0], value[1]];
|
|
338
|
+
}
|
|
339
|
+
value[index] = targetValue;
|
|
340
|
+
event === 'input' ? doUpdateValue(value) : doChange(value);
|
|
334
341
|
}
|
|
335
|
-
value[index] = changedValue;
|
|
336
|
-
event === 'input' ? doUpdateValue(value) : doChange(value);
|
|
337
342
|
}
|
|
338
343
|
// force update to sync input's view with value
|
|
339
344
|
// if not set, after input, input value won't sync with dom input value
|
|
340
345
|
vm.$forceUpdate();
|
|
346
|
+
if (!isIncomingValueValid) {
|
|
347
|
+
void nextTick(focusedInputCursorControl.restoreCursor);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function allowInput(value) {
|
|
351
|
+
const { allowInput } = props;
|
|
352
|
+
if (typeof allowInput === 'function') {
|
|
353
|
+
return allowInput(value);
|
|
354
|
+
}
|
|
355
|
+
return true;
|
|
341
356
|
}
|
|
342
357
|
function handleInputBlur(e) {
|
|
343
358
|
doUpdateValueBlur(e);
|
|
@@ -351,13 +366,23 @@ export default defineComponent({
|
|
|
351
366
|
activatedRef.value = false;
|
|
352
367
|
}
|
|
353
368
|
dealWithEvent(e, 'blur');
|
|
369
|
+
currentFocusedInputRef.value = null;
|
|
354
370
|
}
|
|
355
|
-
function handleInputFocus(e) {
|
|
371
|
+
function handleInputFocus(e, index) {
|
|
356
372
|
doUpdateValueFocus(e);
|
|
357
373
|
focusedRef.value = true;
|
|
358
374
|
activatedRef.value = true;
|
|
359
375
|
doActivate();
|
|
360
376
|
dealWithEvent(e, 'focus');
|
|
377
|
+
if (index === 0) {
|
|
378
|
+
currentFocusedInputRef.value = inputElRef.value;
|
|
379
|
+
}
|
|
380
|
+
else if (index === 1) {
|
|
381
|
+
currentFocusedInputRef.value = inputEl2Ref.value;
|
|
382
|
+
}
|
|
383
|
+
else if (index === 2) {
|
|
384
|
+
currentFocusedInputRef.value = textareaElRef.value;
|
|
385
|
+
}
|
|
361
386
|
}
|
|
362
387
|
function handleWrapperBlur(e) {
|
|
363
388
|
if (props.passivelyActivated) {
|
|
@@ -477,25 +502,25 @@ export default defineComponent({
|
|
|
477
502
|
};
|
|
478
503
|
on('mouseup', document, hidePassword);
|
|
479
504
|
}
|
|
480
|
-
function
|
|
505
|
+
function handleWrapperKeydown(e) {
|
|
481
506
|
var _a;
|
|
482
507
|
(_a = props.onKeydown) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
483
508
|
switch (e.key) {
|
|
484
509
|
case 'Escape':
|
|
485
|
-
|
|
510
|
+
handleWrapperKeydownEsc();
|
|
486
511
|
break;
|
|
487
512
|
case 'Enter':
|
|
488
|
-
|
|
513
|
+
handleWrapperKeydownEnter(e);
|
|
489
514
|
break;
|
|
490
515
|
}
|
|
491
516
|
}
|
|
492
|
-
function
|
|
517
|
+
function handleWrapperKeydownEnter(e) {
|
|
493
518
|
var _a, _b;
|
|
494
519
|
if (props.passivelyActivated) {
|
|
495
520
|
const { value: focused } = activatedRef;
|
|
496
521
|
if (focused) {
|
|
497
522
|
if (props.internalDeactivateOnEnter) {
|
|
498
|
-
|
|
523
|
+
handleWrapperKeydownEsc();
|
|
499
524
|
}
|
|
500
525
|
return;
|
|
501
526
|
}
|
|
@@ -508,7 +533,7 @@ export default defineComponent({
|
|
|
508
533
|
}
|
|
509
534
|
}
|
|
510
535
|
}
|
|
511
|
-
function
|
|
536
|
+
function handleWrapperKeydownEsc() {
|
|
512
537
|
if (props.passivelyActivated) {
|
|
513
538
|
activatedRef.value = false;
|
|
514
539
|
void nextTick(() => {
|
|
@@ -553,7 +578,7 @@ export default defineComponent({
|
|
|
553
578
|
const { value: wrapperEl } = wrapperElRef;
|
|
554
579
|
if ((wrapperEl === null || wrapperEl === void 0 ? void 0 : wrapperEl.contains(document.activeElement)) &&
|
|
555
580
|
wrapperEl !== document.activeElement) {
|
|
556
|
-
|
|
581
|
+
handleWrapperKeydownEsc();
|
|
557
582
|
}
|
|
558
583
|
}
|
|
559
584
|
function syncMirror(value) {
|
|
@@ -726,7 +751,7 @@ export default defineComponent({
|
|
|
726
751
|
handleClear,
|
|
727
752
|
handlePasswordToggleClick,
|
|
728
753
|
handlePasswordToggleMousedown,
|
|
729
|
-
|
|
754
|
+
handleWrapperKeydown,
|
|
730
755
|
handleTextAreaMirrorResize, getTextareaScrollContainer: () => {
|
|
731
756
|
return textareaElRef.value;
|
|
732
757
|
}, mergedTheme: themeRef, cssVars: inlineThemeDisabled ? undefined : cssVarsRef, themeClass: themeClassHandle === null || themeClassHandle === void 0 ? void 0 : themeClassHandle.themeClass, onRender: themeClassHandle === null || themeClassHandle === void 0 ? void 0 : themeClassHandle.onRender });
|
|
@@ -753,7 +778,7 @@ export default defineComponent({
|
|
|
753
778
|
}
|
|
754
779
|
], style: this.cssVars, tabindex: !this.mergedDisabled && this.passivelyActivated && !this.activated
|
|
755
780
|
? 0
|
|
756
|
-
: undefined, onFocus: this.handleWrapperFocus, onBlur: this.handleWrapperBlur, onClick: this.handleClick, onMousedown: this.handleMouseDown, onMouseenter: this.handleMouseEnter, onMouseleave: this.handleMouseLeave, onCompositionstart: this.handleCompositionStart, onCompositionend: this.handleCompositionEnd, onKeyup: this.onKeyup, onKeydown: this.
|
|
781
|
+
: undefined, onFocus: this.handleWrapperFocus, onBlur: this.handleWrapperBlur, onClick: this.handleClick, onMousedown: this.handleMouseDown, onMouseenter: this.handleMouseEnter, onMouseleave: this.handleMouseLeave, onCompositionstart: this.handleCompositionStart, onCompositionend: this.handleCompositionEnd, onKeyup: this.onKeyup, onKeydown: this.handleWrapperKeydown },
|
|
757
782
|
h("div", { class: `${mergedClsPrefix}-input-wrapper` },
|
|
758
783
|
resolveWrappedSlot($slots.prefix, (children) => children && (h("div", { class: `${mergedClsPrefix}-input__prefix` }, children))),
|
|
759
784
|
this.type === 'textarea' ? (h(NScrollbar, { ref: "textareaScrollbarInstRef", class: `${mergedClsPrefix}-input__textarea`, container: this.getTextareaScrollContainer, triggerDisplayManually: true, useUnifiedContainer: true }, {
|
|
@@ -775,7 +800,7 @@ export default defineComponent({
|
|
|
775
800
|
this.textDecorationStyle[0],
|
|
776
801
|
(_b = this.inputProps) === null || _b === void 0 ? void 0 : _b.style,
|
|
777
802
|
scrollContainerWidthStyle
|
|
778
|
-
], onBlur: this.handleInputBlur, onFocus: this.handleInputFocus, onInput: this.handleInput, onChange: this.handleChange, onScroll: this.handleTextAreaScroll })),
|
|
803
|
+
], onBlur: this.handleInputBlur, onFocus: (e) => this.handleInputFocus(e, 2), onInput: this.handleInput, onChange: this.handleChange, onScroll: this.handleTextAreaScroll })),
|
|
779
804
|
this.showPlaceholder1 ? (h("div", { class: `${mergedClsPrefix}-input__placeholder`, style: [
|
|
780
805
|
this.placeholderStyle,
|
|
781
806
|
scrollContainerWidthStyle
|
|
@@ -797,7 +822,7 @@ export default defineComponent({
|
|
|
797
822
|
(_b = this.inputProps) === null || _b === void 0 ? void 0 : _b.style
|
|
798
823
|
], tabindex: this.passivelyActivated && !this.activated ? -1 : undefined, placeholder: this.mergedPlaceholder[0], disabled: this.mergedDisabled, maxlength: this.maxlength, minlength: this.minlength, value: Array.isArray(this.mergedValue)
|
|
799
824
|
? this.mergedValue[0]
|
|
800
|
-
: this.mergedValue, readonly: this.readonly, autofocus: this.autofocus, size: this.attrSize, onBlur: this.handleInputBlur, onFocus: this.handleInputFocus, onInput: (e) => this.handleInput(e, 0), onChange: (e) => this.handleChange(e, 0) })),
|
|
825
|
+
: this.mergedValue, readonly: this.readonly, autofocus: this.autofocus, size: this.attrSize, onBlur: this.handleInputBlur, onFocus: (e) => this.handleInputFocus(e, 0), onInput: (e) => this.handleInput(e, 0), onChange: (e) => this.handleChange(e, 0) })),
|
|
801
826
|
this.showPlaceholder1 ? (h("div", { class: `${mergedClsPrefix}-input__placeholder` },
|
|
802
827
|
h("span", null, this.mergedPlaceholder[0]))) : null,
|
|
803
828
|
this.autosize ? (h("div", { class: `${mergedClsPrefix}-input__input-mirror`, key: "mirror", ref: "inputMirrorElRef" }, "\u00A0")) : null)),
|
|
@@ -834,7 +859,7 @@ export default defineComponent({
|
|
|
834
859
|
h("div", { class: `${mergedClsPrefix}-input__input` },
|
|
835
860
|
h("input", { ref: "inputEl2Ref", type: this.type, class: `${mergedClsPrefix}-input__input-el`, tabindex: this.passivelyActivated && !this.activated ? -1 : undefined, placeholder: this.mergedPlaceholder[1], disabled: this.mergedDisabled, maxlength: this.maxlength, minlength: this.minlength, value: Array.isArray(this.mergedValue)
|
|
836
861
|
? this.mergedValue[1]
|
|
837
|
-
: undefined, readonly: this.readonly, style: this.textDecorationStyle[1], onBlur: this.handleInputBlur, onFocus: this.handleInputFocus, onInput: (e) => this.handleInput(e, 1), onChange: (e) => this.handleChange(e, 1) }),
|
|
862
|
+
: undefined, readonly: this.readonly, style: this.textDecorationStyle[1], onBlur: this.handleInputBlur, onFocus: (e) => this.handleInputFocus(e, 1), onInput: (e) => this.handleInput(e, 1), onChange: (e) => this.handleChange(e, 1) }),
|
|
838
863
|
this.showPlaceholder2 ? (h("div", { class: `${mergedClsPrefix}-input__placeholder` },
|
|
839
864
|
h("span", null, this.mergedPlaceholder[1]))) : null),
|
|
840
865
|
resolveWrappedSlot($slots.suffix, (children) => {
|
|
@@ -19,6 +19,8 @@ export default cB('input-group-label', `
|
|
|
19
19
|
font-size: var(--n-font-size);
|
|
20
20
|
line-height: var(--n-height);
|
|
21
21
|
height: var(--n-height);
|
|
22
|
+
flex-shrink: 0;
|
|
23
|
+
white-space: nowrap;
|
|
22
24
|
transition:
|
|
23
25
|
color .3s var(--n-bezier),
|
|
24
26
|
background-color .3s var(--n-bezier),
|
package/es/input/src/utils.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
1
2
|
export declare function len(s: string): number;
|
|
2
|
-
export declare function
|
|
3
|
+
export declare function isEmptyInputValue(value: unknown): boolean;
|
|
4
|
+
export interface UseCursorControl {
|
|
5
|
+
recordCursor: () => void;
|
|
6
|
+
restoreCursor: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function useCursor(inputElRef: Ref<HTMLInputElement | HTMLTextAreaElement | null>): UseCursorControl;
|
package/es/input/src/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ref, watch } from 'vue';
|
|
1
2
|
export function len(s) {
|
|
2
3
|
let count = 0;
|
|
3
4
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -6,6 +7,60 @@ export function len(s) {
|
|
|
6
7
|
}
|
|
7
8
|
return count;
|
|
8
9
|
}
|
|
9
|
-
export function
|
|
10
|
-
return
|
|
10
|
+
export function isEmptyInputValue(value) {
|
|
11
|
+
return value === '' || value == null;
|
|
12
|
+
}
|
|
13
|
+
export function useCursor(inputElRef) {
|
|
14
|
+
const selectionRef = ref(null);
|
|
15
|
+
function recordCursor() {
|
|
16
|
+
const { value: input } = inputElRef;
|
|
17
|
+
if (!input || !input.focus) {
|
|
18
|
+
reset();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const { selectionStart, selectionEnd, value } = input;
|
|
22
|
+
if (selectionStart == null || selectionEnd == null) {
|
|
23
|
+
reset();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
selectionRef.value = {
|
|
27
|
+
start: selectionStart,
|
|
28
|
+
end: selectionEnd,
|
|
29
|
+
beforeText: value.slice(0, selectionStart),
|
|
30
|
+
afterText: value.slice(selectionEnd)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function restoreCursor() {
|
|
34
|
+
var _a;
|
|
35
|
+
const { value: selection } = selectionRef;
|
|
36
|
+
const { value: inputEl } = inputElRef;
|
|
37
|
+
if (!selection || !inputEl) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const { value } = inputEl;
|
|
41
|
+
const { start, beforeText, afterText } = selection;
|
|
42
|
+
let startPos = value.length;
|
|
43
|
+
if (value.endsWith(afterText)) {
|
|
44
|
+
startPos = value.length - afterText.length;
|
|
45
|
+
}
|
|
46
|
+
else if (value.startsWith(beforeText)) {
|
|
47
|
+
startPos = beforeText.length;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const beforeLastChar = beforeText[start - 1];
|
|
51
|
+
const newIndex = value.indexOf(beforeLastChar, start - 1);
|
|
52
|
+
if (newIndex !== -1) {
|
|
53
|
+
startPos = newIndex + 1;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
(_a = inputEl.setSelectionRange) === null || _a === void 0 ? void 0 : _a.call(inputEl, startPos, startPos);
|
|
57
|
+
}
|
|
58
|
+
function reset() {
|
|
59
|
+
selectionRef.value = null;
|
|
60
|
+
}
|
|
61
|
+
watch(inputElRef, reset);
|
|
62
|
+
return {
|
|
63
|
+
recordCursor,
|
|
64
|
+
restoreCursor
|
|
65
|
+
};
|
|
11
66
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PropType, CSSProperties, ExtractPropTypes } from 'vue';
|
|
2
2
|
import type { ScrollbarProps } from '../../_internal';
|
|
3
|
-
import { ExtractPublicPropTypes } from '../../_utils';
|
|
3
|
+
import type { ExtractPublicPropTypes } from '../../_utils';
|
|
4
4
|
declare const layoutProps: {
|
|
5
5
|
readonly embedded: BooleanConstructor;
|
|
6
6
|
readonly position: {
|
|
@@ -319,6 +319,7 @@ export declare function createLayoutComponent(isContent: boolean): import("vue")
|
|
|
319
319
|
} | undefined;
|
|
320
320
|
};
|
|
321
321
|
}>;
|
|
322
|
+
handleNativeElScroll: (e: Event) => void;
|
|
322
323
|
cssVars: import("vue").ComputedRef<{
|
|
323
324
|
'--n-bezier': string;
|
|
324
325
|
'--n-color': string;
|
|
@@ -718,6 +719,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
718
719
|
} | undefined;
|
|
719
720
|
};
|
|
720
721
|
}>;
|
|
722
|
+
handleNativeElScroll: (e: Event) => void;
|
|
721
723
|
cssVars: import("vue").ComputedRef<{
|
|
722
724
|
'--n-bezier': string;
|
|
723
725
|
'--n-color': string;
|
package/es/layout/src/Layout.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { h, defineComponent, computed, ref, provide } from 'vue';
|
|
2
2
|
import { NScrollbar } from '../../_internal';
|
|
3
3
|
import { useConfig, useTheme, useThemeClass } from '../../_mixins';
|
|
4
|
+
import { createInjectionKey, useReactivated } from '../../_utils';
|
|
4
5
|
import { layoutLight } from '../styles';
|
|
5
|
-
import style from './styles/layout.cssr';
|
|
6
6
|
import { positionProp } from './interface';
|
|
7
|
-
import
|
|
7
|
+
import style from './styles/layout.cssr';
|
|
8
8
|
const layoutProps = {
|
|
9
9
|
embedded: Boolean,
|
|
10
10
|
position: positionProp,
|
|
@@ -55,6 +55,24 @@ export function createLayoutComponent(isContent) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
provide(layoutInjectionKey, props);
|
|
58
|
+
let scrollX = 0;
|
|
59
|
+
let scrollY = 0;
|
|
60
|
+
const handleNativeElScroll = (e) => {
|
|
61
|
+
var _a;
|
|
62
|
+
const target = e.target;
|
|
63
|
+
scrollX = target.scrollLeft;
|
|
64
|
+
scrollY = target.scrollTop;
|
|
65
|
+
(_a = props.onScroll) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
66
|
+
};
|
|
67
|
+
useReactivated(() => {
|
|
68
|
+
if (props.nativeScrollbar) {
|
|
69
|
+
const el = scrollableElRef.value;
|
|
70
|
+
if (el) {
|
|
71
|
+
el.scrollTop = scrollY;
|
|
72
|
+
el.scrollLeft = scrollX;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
58
76
|
const hasSiderStyle = {
|
|
59
77
|
display: 'flex',
|
|
60
78
|
flexWrap: 'nowrap',
|
|
@@ -77,7 +95,7 @@ export function createLayoutComponent(isContent) {
|
|
|
77
95
|
: undefined;
|
|
78
96
|
return Object.assign({ mergedClsPrefix: mergedClsPrefixRef, scrollableElRef,
|
|
79
97
|
scrollbarInstRef,
|
|
80
|
-
hasSiderStyle, mergedTheme: themeRef, cssVars: inlineThemeDisabled ? undefined : cssVarsRef, themeClass: themeClassHandle === null || themeClassHandle === void 0 ? void 0 : themeClassHandle.themeClass, onRender: themeClassHandle === null || themeClassHandle === void 0 ? void 0 : themeClassHandle.onRender }, exposedMethods);
|
|
98
|
+
hasSiderStyle, mergedTheme: themeRef, handleNativeElScroll, cssVars: inlineThemeDisabled ? undefined : cssVarsRef, themeClass: themeClassHandle === null || themeClassHandle === void 0 ? void 0 : themeClassHandle.themeClass, onRender: themeClassHandle === null || themeClassHandle === void 0 ? void 0 : themeClassHandle.onRender }, exposedMethods);
|
|
81
99
|
},
|
|
82
100
|
render() {
|
|
83
101
|
var _a;
|
|
@@ -90,7 +108,7 @@ export function createLayoutComponent(isContent) {
|
|
|
90
108
|
`${mergedClsPrefix}-layout`,
|
|
91
109
|
`${mergedClsPrefix}-layout--${this.position}-positioned`
|
|
92
110
|
];
|
|
93
|
-
return (h("div", { class: layoutClass, style: this.cssVars }, this.nativeScrollbar ? (h("div", { ref: "scrollableElRef", class: `${mergedClsPrefix}-layout-scroll-container`, style: [this.contentStyle, hasSiderStyle], onScroll: this.
|
|
111
|
+
return (h("div", { class: layoutClass, style: this.cssVars }, this.nativeScrollbar ? (h("div", { ref: "scrollableElRef", class: `${mergedClsPrefix}-layout-scroll-container`, style: [this.contentStyle, hasSiderStyle], onScroll: this.handleNativeElScroll }, this.$slots)) : (h(NScrollbar, Object.assign({}, this.scrollbarProps, { onScroll: this.onScroll, ref: "scrollbarInstRef", theme: this.mergedTheme.peers.Scrollbar, themeOverrides: this.mergedTheme.peerOverrides.Scrollbar, contentStyle: [this.contentStyle, hasSiderStyle] }), this.$slots))));
|
|
94
112
|
}
|
|
95
113
|
});
|
|
96
114
|
}
|
|
@@ -362,6 +362,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
362
362
|
mergedCollapsed: import("vue").ComputedRef<boolean>;
|
|
363
363
|
scrollContainerStyle: import("vue").ComputedRef<CSSProperties>;
|
|
364
364
|
siderPlacement: import("vue").ComputedRef<"left" | "right">;
|
|
365
|
+
handleNativeElScroll: (e: Event) => void;
|
|
365
366
|
handleTransitionend: (e: TransitionEvent) => void;
|
|
366
367
|
handleTriggerClick: () => void;
|
|
367
368
|
inlineThemeDisabled: boolean | undefined;
|