@opentiny/vue-renderless 3.13.1 → 3.14.0
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/action-sheet/index.js +20 -13
- package/action-sheet/vue.js +8 -7
- package/amount/index.js +100 -25
- package/amount/vue.js +102 -26
- package/anchor/index.js +1 -0
- package/area/index.js +8 -8
- package/area/vue.js +5 -5
- package/async-flowchart/index.js +16 -3
- package/autocomplete/index.js +58 -14
- package/autocomplete/vue.js +40 -12
- package/badge/index.js +12 -0
- package/badge/vue.js +6 -4
- package/breadcrumb/vue.js +3 -1
- package/breadcrumb-item/vue.js +6 -2
- package/button/index.js +5 -1
- package/calendar/index.js +2 -86
- package/calendar-bar/index.js +18 -4
- package/calendar-view/index.js +5 -1
- package/calendar-view/vue.js +16 -3
- package/card-group/vue.js +4 -2
- package/cascader/index.js +86 -34
- package/cascader/vue.js +61 -20
- package/cascader-menu/index.js +7 -7
- package/cascader-menu/vue.js +2 -3
- package/cascader-mobile/index.js +36 -23
- package/cascader-mobile/vue.js +6 -0
- package/cascader-node/index.js +13 -1
- package/cascader-node/vue.js +15 -4
- package/cascader-panel/index.js +1 -1
- package/cascader-select/column-index.js +150 -0
- package/cascader-select/column.js +120 -0
- package/cascader-select/index.js +29 -165
- package/cascader-select/usePicker.js +251 -0
- package/cascader-select/useTouch.js +65 -0
- package/cascader-select/vue.js +35 -47
- package/cell/vue.js +2 -1
- package/chart-bar/index.js +2 -3
- package/chart-core/deps/constants.js +43 -43
- package/chart-core/index.js +1 -1
- package/chart-gauge/index.js +2 -2
- package/chart-heatmap/index.js +17 -10
- package/chart-line/index.js +8 -9
- package/chart-tree/index.js +2 -2
- package/chart-waterfall/index.js +4 -6
- package/checkbox/index.js +18 -1
- package/checkbox/vue.js +15 -7
- package/checkbox-group/vue.js +1 -0
- package/col/vue.js +1 -1
- package/collapse/index.js +3 -3
- package/color-select-panel/vue.js +0 -7
- package/column-list-item/index.js +17 -1
- package/column-list-item/vue.js +8 -3
- package/common/date.js +7 -5
- package/common/deps/clickoutside.js +6 -2
- package/common/deps/dom.js +19 -4
- package/common/deps/popper.js +44 -11
- package/common/deps/resize-event.js +1 -0
- package/common/deps/touch-emulator.js +4 -1
- package/common/deps/tree-model/node.js +2 -2
- package/common/deps/tree-model/tree-store.js +2 -13
- package/common/deps/useRect.js +25 -0
- package/common/deps/vue-popper.js +38 -20
- package/common/index.js +2 -2
- package/common/runtime.js +1 -1
- package/common/string.js +2 -2
- package/common/type.js +2 -1
- package/common/validate/rules/enum.js +1 -1
- package/common/validate/rules/pattern.js +2 -2
- package/common/validate/rules/range.js +8 -5
- package/common/validate/rules/required.js +1 -1
- package/common/validate/rules/type.js +5 -5
- package/common/validate/rules/whitespace.js +1 -1
- package/common/validate/util.js +15 -16
- package/common/validate/validations/integer.js +1 -1
- package/common/validate/validations/method.js +1 -1
- package/currency/index.js +74 -7
- package/currency/vue.js +21 -5
- package/date-panel/index.js +16 -0
- package/date-panel/vue.js +8 -2
- package/date-picker-mobile/index.js +12 -0
- package/date-picker-mobile/vue.js +7 -1
- package/date-range/vue.js +14 -6
- package/date-table/index.js +5 -0
- package/date-table/vue.js +3 -1
- package/dialog-box/index.js +46 -14
- package/dialog-box/vue.js +30 -7
- package/dialog-select/index.js +6 -3
- package/dialog-select/vue.js +8 -4
- package/drawer/index.js +27 -5
- package/drawer/vue.js +14 -7
- package/dropdown/index.js +7 -7
- package/dropdown/vue.js +6 -2
- package/dropdown-item/index.js +9 -1
- package/dropdown-item/mf.js +6 -10
- package/dropdown-item/vue.js +20 -7
- package/dropdown-menu/index.js +20 -7
- package/dropdown-menu/vue.js +4 -3
- package/exception/index.js +2 -7
- package/exception/vue.js +7 -10
- package/fall-menu/index.js +5 -1
- package/fall-menu/vue.js +13 -2
- package/file-upload/index.js +68 -18
- package/file-upload/vue.js +38 -8
- package/filter-box/index.js +1 -0
- package/float-button/index.js +42 -0
- package/float-button/vue.js +101 -0
- package/floating-button/index.js +62 -16
- package/floating-button/vue.js +27 -9
- package/flowchart/index.js +134 -25
- package/flowchart/node.js +13 -4
- package/flowchart/vue.js +16 -4
- package/form/vue.js +8 -0
- package/form-item/index.js +5 -5
- package/form-item/vue.js +3 -1
- package/fullscreen/index.js +5 -5
- package/fullscreen/vue.js +3 -3
- package/grid/plugins/export.js +5 -2
- package/grid/utils/column.js +1 -0
- package/grid/utils/dom.js +7 -1
- package/image/index.js +6 -1
- package/image/vue.js +6 -3
- package/image-viewer/index.js +62 -51
- package/image-viewer/vue.js +17 -5
- package/input/index.js +81 -20
- package/input/vue.js +44 -18
- package/ip-address/index.js +61 -19
- package/ip-address/vue.js +22 -4
- package/link/vue.js +3 -1
- package/loading/index.js +2 -2
- package/loading/vue.js +8 -2
- package/logout/index.js +1 -1
- package/menu/index.js +15 -2
- package/menu/vue.js +22 -17
- package/mind-map/index.js +47 -0
- package/mind-map/vue.js +53 -0
- package/modal/index.js +44 -4
- package/modal/vue.js +18 -4
- package/multi-select/index.js +186 -11
- package/multi-select/vue.js +60 -15
- package/multi-select-item/index.js +23 -0
- package/multi-select-item/vue.js +31 -0
- package/numeric/index.js +46 -12
- package/numeric/vue.js +44 -19
- package/option/index.js +27 -9
- package/option/vue.js +37 -21
- package/option-group/index.js +3 -3
- package/package.json +1 -1
- package/pager/index.js +18 -4
- package/pager/vue.js +16 -5
- package/picker/index.js +258 -49
- package/picker/mb.js +42 -0
- package/picker/vue.js +70 -17
- package/picker-column/index.js +1 -1
- package/pop-upload/vue.js +3 -0
- package/popconfirm/index.js +3 -6
- package/popconfirm/vue.js +1 -1
- package/popeditor/index.js +71 -32
- package/popeditor/vue.js +15 -11
- package/popover/index.js +4 -4
- package/popover/vue.js +6 -6
- package/popup/index.js +3 -3
- package/popup/vue.js +5 -5
- package/pull-refresh/index.js +13 -13
- package/pull-refresh/vue.js +5 -4
- package/radio/index.js +0 -17
- package/radio/vue.js +4 -10
- package/rate/index.js +1 -1
- package/rate/vue.js +0 -2
- package/record/index.js +4 -1
- package/rich-text/clipboard.js +54 -0
- package/rich-text/index.js +192 -0
- package/rich-text/module/file-upload.js +107 -0
- package/rich-text/module/image-drop.js +63 -0
- package/rich-text/module/image-upload.js +89 -0
- package/rich-text/options.js +141 -0
- package/rich-text/table-module.js +382 -0
- package/rich-text/vue.js +102 -0
- package/{rich-text-edtior → rich-text-editor}/index.js +2 -2
- package/{rich-text-edtior → rich-text-editor}/vue.js +2 -5
- package/scrollbar/index.js +11 -11
- package/scrollbar/vue-bar.js +3 -3
- package/scrollbar/vue.js +5 -5
- package/search/index.js +9 -9
- package/search/vue.js +8 -6
- package/select/index.js +457 -389
- package/select/vue.js +257 -161
- package/select-dropdown/index.js +61 -3
- package/select-dropdown/vue.js +85 -8
- package/select-view/index.js +3 -1
- package/selected-box/index.js +2 -0
- package/selected-box/vue.js +6 -3
- package/signature/index.js +241 -0
- package/signature/vue.js +88 -0
- package/skeleton/index.js +14 -0
- package/skeleton/vue.js +15 -0
- package/skeleton-item/vue.js +15 -0
- package/slider/index.js +70 -17
- package/slider/vue.js +16 -7
- package/split/index.js +5 -3
- package/split/vue.js +4 -6
- package/standard-list-item/index.js +15 -1
- package/standard-list-item/vue.js +6 -5
- package/steps/index.js +25 -2
- package/steps/slide-bar.js +8 -1
- package/steps/vue.js +15 -3
- package/tab-item-mf/vue.js +14 -8
- package/tab-nav/index.js +30 -5
- package/tab-nav/vue.js +16 -4
- package/tabbar/vue.js +9 -3
- package/tabbar-item/vue.js +3 -2
- package/tabs/index.js +16 -4
- package/tabs/vue.js +2 -1
- package/tabs-mf/index.js +20 -6
- package/tabs-mf/vue-nav.js +26 -11
- package/tabs-mf/vue.js +7 -7
- package/tabs-mf/wheel.js +1 -0
- package/tag/index.js +1 -1
- package/tag-group/index.js +2 -1
- package/time/index.js +5 -2
- package/time/vue.js +1 -1
- package/time-line/index.js +3 -3
- package/time-line/vue.js +2 -2
- package/time-picker-mobile/index.js +24 -5
- package/time-picker-mobile/vue.js +17 -7
- package/time-range/index.js +2 -0
- package/timeline-item/vue.js +1 -1
- package/tooltip/index.js +6 -3
- package/tooltip/vue.js +4 -4
- package/transfer/index.js +20 -22
- package/transfer/vue.js +1 -6
- package/transfer-panel/vue.js +3 -5
- package/tree/index.js +21 -4
- package/tree/vue.js +10 -8
- package/tree-menu/index.js +31 -5
- package/tree-menu/vue.js +28 -15
- package/tree-node/index.js +18 -18
- package/tree-node/vue.js +6 -5
- package/types/action-sheet.type.d.ts +118 -1
- package/types/alert.type.d.ts +1 -1
- package/types/amount.type.d.ts +168 -1
- package/types/area.type.d.ts +134 -1
- package/types/async-flowchart.type.d.ts +72 -0
- package/types/autocomplete.type.d.ts +199 -1
- package/types/badge.type.d.ts +3 -1
- package/types/breadcrumb-item.type.d.ts +2 -0
- package/types/breadcrumb.type.d.ts +2 -0
- package/types/button-group.type.d.ts +3 -3
- package/types/button.type.d.ts +4 -0
- package/types/cascader-menu.type.d.ts +3 -4
- package/types/cascader-node.type.d.ts +5 -2
- package/types/cascader-panel.type-2bd03be3.d.ts +241 -0
- package/types/cascader-panel.type.d.ts +3 -241
- package/types/cascader.type.d.ts +329 -1
- package/types/checkbox.type.d.ts +9 -3
- package/types/collapse.type.d.ts +20 -3
- package/types/date-picker.type.d.ts +37 -0
- package/types/dialog-box.type.d.ts +13 -3
- package/types/drawer.type.d.ts +133 -1
- package/types/{dropdown-item.type-8ea6c633.d.ts → dropdown-item.type-8475a549.d.ts} +7 -13
- package/types/dropdown-item.type.d.ts +1 -1
- package/types/dropdown-menu.type.d.ts +1 -1
- package/types/dropdown.type.d.ts +1 -5
- package/types/fall-menu.type.d.ts +94 -1
- package/types/file-upload.type.d.ts +1 -1
- package/types/float-button.type.d.ts +123 -0
- package/types/form-item.type.d.ts +1 -1
- package/types/{form.type-d0fd42f3.d.ts → form.type-222799ae.d.ts} +5 -2
- package/types/form.type.d.ts +1 -1
- package/types/{index-e0250f63.d.ts → index-b012f687.d.ts} +9 -0
- package/types/input.type.d.ts +1 -5
- package/types/ip-address.type.d.ts +160 -1
- package/types/link.type.d.ts +6 -3
- package/types/loading.type.d.ts +7 -0
- package/types/milestone.type.d.ts +1 -1
- package/types/mind-map.type.d.ts +20 -0
- package/types/modal.type.d.ts +29 -2
- package/types/numeric.type.d.ts +41 -10
- package/types/pager.type.d.ts +13 -1
- package/types/picker.type.d.ts +18 -0
- package/types/popconfirm.type.d.ts +86 -1
- package/types/popeditor.type.d.ts +5 -1
- package/types/popover.type.d.ts +3 -3
- package/types/progress.type.d.ts +3 -1
- package/types/radio.type.d.ts +0 -4
- package/types/rate.type.d.ts +236 -1
- package/types/search.type.d.ts +88 -1
- package/types/shared.type.d.ts +1 -1
- package/types/skeleton-item.type.d.ts +38 -0
- package/types/skeleton.type.d.ts +45 -0
- package/types/slider.type.d.ts +49 -10
- package/types/steps.type.d.ts +15 -4
- package/types/switch.type.d.ts +3 -3
- package/types/tab-bar.type.d.ts +1 -1
- package/types/tab-nav.type.d.ts +7 -2
- package/types/tabs.type.d.ts +9 -1
- package/types/tag-group.type.d.ts +64 -1
- package/types/{time-line.type-d7daa669.d.ts → time-line.type-b155cb4f.d.ts} +12 -0
- package/types/time-line.type.d.ts +1 -1
- package/types/timeline-item.type.d.ts +1 -1
- package/types/tooltip.type.d.ts +2 -2
- package/types/transfer.type.d.ts +185 -1
- package/types/tree-menu.type.d.ts +210 -1
- package/types/upload-dragger.type.d.ts +2 -2
- package/types/{upload-list.type-343e8c11.d.ts → upload-list.type-a29aea50.d.ts} +31 -8
- package/types/upload-list.type.d.ts +1 -1
- package/types/upload.type.d.ts +1 -1
- package/types/user-head.type.d.ts +146 -1
- package/types/wizard.type.d.ts +1 -0
- package/upload/index.js +64 -34
- package/upload/vue.js +9 -5
- package/upload-dragger/index.js +22 -20
- package/upload-list/index.js +24 -18
- package/upload-list/vue.js +9 -4
- package/user/index.js +34 -25
- package/user/vue.js +1 -1
- package/user-head/index.js +3 -3
- package/watermark/index.js +11 -0
- package/wheel/index.js +3 -0
- package/wizard/vue.js +4 -2
- package/common/deps/modal-queue.js +0 -6
- package/common/deps/requestAnimationFrame.js +0 -25
package/pager/index.js
CHANGED
|
@@ -34,11 +34,11 @@ const computedTotalText = ({ props, t }) => () => {
|
|
|
34
34
|
const HUNDRED_THOUSAND = 1e5;
|
|
35
35
|
const MILLION = 1e6;
|
|
36
36
|
const TEN_MILLION = 1e7;
|
|
37
|
-
if (totals
|
|
37
|
+
if (totals < HUNDRED_THOUSAND) {
|
|
38
38
|
return String(totals);
|
|
39
|
-
} else if (totals
|
|
39
|
+
} else if (totals < MILLION) {
|
|
40
40
|
return t("ui.page.hundredThousand");
|
|
41
|
-
} else if (totals
|
|
41
|
+
} else if (totals < TEN_MILLION) {
|
|
42
42
|
return t("ui.page.million");
|
|
43
43
|
} else {
|
|
44
44
|
return t("ui.page.tenMillion");
|
|
@@ -61,7 +61,7 @@ const watchInternalCurrentPage = ({ state, emit }) => (currentPage) => {
|
|
|
61
61
|
if (state.jumperValue !== value) {
|
|
62
62
|
state.jumperValue = value;
|
|
63
63
|
}
|
|
64
|
-
emit("update:
|
|
64
|
+
emit("update:current-page", currentPage);
|
|
65
65
|
emit("current-change", currentPage);
|
|
66
66
|
state.lastEmittedPage = -1;
|
|
67
67
|
};
|
|
@@ -89,6 +89,17 @@ const watchPageSize = ({ state }) => (pageSize) => {
|
|
|
89
89
|
const watchTotal = ({ state }) => (total) => {
|
|
90
90
|
state.internalTotal = total;
|
|
91
91
|
};
|
|
92
|
+
const watchShowSizes = ({ nextTick, vm }) => (newVal) => {
|
|
93
|
+
if (newVal) {
|
|
94
|
+
nextTick(() => {
|
|
95
|
+
const width = vm.$refs.pageSize[0].getBoundingClientRect().width;
|
|
96
|
+
const popover = document.querySelectorAll(".tiny-pager__selector");
|
|
97
|
+
Array.from(popover).forEach((ele) => {
|
|
98
|
+
ele.style.width = width + "px";
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
92
103
|
const handleSizeChange = ({ props, state, api, emit, vm }) => (val) => {
|
|
93
104
|
val = Number(val);
|
|
94
105
|
if (val !== state.internalPageSize) {
|
|
@@ -322,6 +333,7 @@ const emitChange = ({ state, nextTick, emit }) => () => {
|
|
|
322
333
|
const setTotal = ({ state }) => (val) => {
|
|
323
334
|
state.internalTotal = val;
|
|
324
335
|
};
|
|
336
|
+
const clickSizes = () => (e) => e.stopPropagation();
|
|
325
337
|
export {
|
|
326
338
|
beforeChangeHandler,
|
|
327
339
|
beforeJumperChangeHandler,
|
|
@@ -329,6 +341,7 @@ export {
|
|
|
329
341
|
beforeSizeChangeHandler,
|
|
330
342
|
buildBeforePageChangeParam,
|
|
331
343
|
canJumperGo,
|
|
344
|
+
clickSizes,
|
|
332
345
|
computedInternalLayout,
|
|
333
346
|
computedInternalPageCount,
|
|
334
347
|
computedShowPager,
|
|
@@ -354,5 +367,6 @@ export {
|
|
|
354
367
|
watchInternalPageCount,
|
|
355
368
|
watchPageSize,
|
|
356
369
|
watchPageSizes,
|
|
370
|
+
watchShowSizes,
|
|
357
371
|
watchTotal
|
|
358
372
|
};
|
package/pager/vue.js
CHANGED
|
@@ -25,12 +25,14 @@ import {
|
|
|
25
25
|
getValidCurrentPage,
|
|
26
26
|
emitChange,
|
|
27
27
|
setTotal,
|
|
28
|
+
clickSizes,
|
|
28
29
|
watchInternalCurrentPage,
|
|
29
30
|
watchPageSizes,
|
|
30
31
|
watchCurrentPage,
|
|
31
32
|
watchInternalPageCount,
|
|
32
33
|
watchPageSize,
|
|
33
|
-
watchTotal
|
|
34
|
+
watchTotal,
|
|
35
|
+
watchShowSizes
|
|
34
36
|
} from "./index";
|
|
35
37
|
const api = [
|
|
36
38
|
"state",
|
|
@@ -54,9 +56,11 @@ const api = [
|
|
|
54
56
|
"buildBeforePageChangeParam",
|
|
55
57
|
"getValidCurrentPage",
|
|
56
58
|
"emitChange",
|
|
57
|
-
"setTotal"
|
|
59
|
+
"setTotal",
|
|
60
|
+
"clickSizes"
|
|
58
61
|
];
|
|
59
|
-
const renderless = (props, { reactive, computed, watch }, { emit, vm, nextTick, t }) => {
|
|
62
|
+
const renderless = (props, { reactive, computed, watch }, { emit, vm, nextTick, t, designConfig }) => {
|
|
63
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
60
64
|
const api2 = {};
|
|
61
65
|
const state = reactive({
|
|
62
66
|
showSizes: false,
|
|
@@ -70,7 +74,11 @@ const renderless = (props, { reactive, computed, watch }, { emit, vm, nextTick,
|
|
|
70
74
|
showPager: computed(() => api2.computedShowPager()),
|
|
71
75
|
internalLayout: computed(() => api2.computedInternalLayout()),
|
|
72
76
|
totalText: computed(() => api2.computedTotalText()),
|
|
73
|
-
internalPageCount: computed(() => api2.computedInternalPageCount())
|
|
77
|
+
internalPageCount: computed(() => api2.computedInternalPageCount()),
|
|
78
|
+
showJumperSufix: (_b = (_a = designConfig == null ? void 0 : designConfig.state) == null ? void 0 : _a.showJumperSufix) != null ? _b : true,
|
|
79
|
+
align: props.align || ((_c = designConfig == null ? void 0 : designConfig.state) == null ? void 0 : _c.align) || "left",
|
|
80
|
+
totalI18n: ((_d = designConfig == null ? void 0 : designConfig.state) == null ? void 0 : _d.totalI18n) || "totals",
|
|
81
|
+
totalFixedLeft: (_g = (_f = props.totalFixedLeft) != null ? _f : (_e = designConfig == null ? void 0 : designConfig.state) == null ? void 0 : _e.totalFixedLeft) != null ? _g : false
|
|
74
82
|
});
|
|
75
83
|
Object.assign(api2, {
|
|
76
84
|
state,
|
|
@@ -99,13 +107,15 @@ const renderless = (props, { reactive, computed, watch }, { emit, vm, nextTick,
|
|
|
99
107
|
buildBeforePageChangeParam: buildBeforePageChangeParam({ state }),
|
|
100
108
|
emitChange: emitChange({ state, nextTick, emit }),
|
|
101
109
|
setTotal: setTotal({ state }),
|
|
110
|
+
clickSizes: clickSizes(),
|
|
102
111
|
// watch
|
|
103
112
|
watchInternalCurrentPage: watchInternalCurrentPage({ state, emit }),
|
|
104
113
|
watchPageSizes: watchPageSizes({ state, props }),
|
|
105
114
|
watchCurrentPage: watchCurrentPage({ state, api: api2 }),
|
|
106
115
|
watchInternalPageCount: watchInternalPageCount({ state, api: api2 }),
|
|
107
116
|
watchPageSize: watchPageSize({ state }),
|
|
108
|
-
watchTotal: watchTotal({ state })
|
|
117
|
+
watchTotal: watchTotal({ state }),
|
|
118
|
+
watchShowSizes: watchShowSizes({ nextTick, vm })
|
|
109
119
|
});
|
|
110
120
|
state.internalCurrentPage = api2.getValidCurrentPage(props.currentPage);
|
|
111
121
|
watch(() => state.internalCurrentPage, api2.watchInternalCurrentPage);
|
|
@@ -114,6 +124,7 @@ const renderless = (props, { reactive, computed, watch }, { emit, vm, nextTick,
|
|
|
114
124
|
watch(() => state.internalPageCount, api2.watchInternalPageCount);
|
|
115
125
|
watch(() => props.pageSize, api2.watchPageSize, { immediate: true });
|
|
116
126
|
watch(() => props.total, api2.watchTotal);
|
|
127
|
+
watch(() => state.showSizes, api2.watchShowSizes);
|
|
117
128
|
return api2;
|
|
118
129
|
};
|
|
119
130
|
export {
|
package/picker/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { toDate, getDateWithNewTimezone, getStrTimezone, getLocalTimezone } from
|
|
|
6
6
|
import { isNumber, isDate } from "../common/type";
|
|
7
7
|
import userPopper from "../common/deps/vue-popper";
|
|
8
8
|
import { DATEPICKER } from "../common";
|
|
9
|
-
import { formatDate, parseDate, isDateObject, getWeekNumber } from "../common/deps/date-util";
|
|
9
|
+
import { formatDate, parseDate, isDateObject, getWeekNumber, prevDate, nextDate } from "../common/deps/date-util";
|
|
10
10
|
import { extend } from "../common/object";
|
|
11
11
|
import { isFunction } from "../common/type";
|
|
12
12
|
import globalTimezone from "./timezone";
|
|
@@ -28,9 +28,8 @@ const getPanel = ({ DatePanel, DateRangePanel, MonthRangePanel, YearRangePanel,
|
|
|
28
28
|
return DatePanel;
|
|
29
29
|
};
|
|
30
30
|
const watchPickerVisible = ({ api, vm, dispatch, emit, props, state }) => (value) => {
|
|
31
|
-
if (props.readonly || state.pickerDisabled)
|
|
31
|
+
if (props.readonly || state.pickerDisabled || state.isMobileScreen)
|
|
32
32
|
return;
|
|
33
|
-
}
|
|
34
33
|
if (value) {
|
|
35
34
|
api.showPicker();
|
|
36
35
|
state.valueOnOpen = Array.isArray(props.modelValue) ? [...props.modelValue] : props.modelValue;
|
|
@@ -41,6 +40,9 @@ const watchPickerVisible = ({ api, vm, dispatch, emit, props, state }) => (value
|
|
|
41
40
|
if (props.validateEvent) {
|
|
42
41
|
dispatch("FormItem", "form.blur");
|
|
43
42
|
}
|
|
43
|
+
if (props.changeOnConfirm && !valueEquals(props.modelValue, state.oldValue)) {
|
|
44
|
+
emit("update:modelValue", state.oldValue);
|
|
45
|
+
}
|
|
44
46
|
emit("blur", vm);
|
|
45
47
|
api.blur();
|
|
46
48
|
}
|
|
@@ -72,16 +74,24 @@ const getMode = ({ state }) => () => {
|
|
|
72
74
|
}
|
|
73
75
|
return DATEPICKER.Day;
|
|
74
76
|
};
|
|
75
|
-
const formatAsFormatAndType = ({ api }) => (value, customFormat, type) => {
|
|
76
|
-
if (!value)
|
|
77
|
+
const formatAsFormatAndType = ({ api }) => (value, customFormat, type, formatObj) => {
|
|
78
|
+
if (!value)
|
|
77
79
|
return null;
|
|
78
|
-
}
|
|
79
80
|
const formatter = (api.typeValueResolveMap()[type] || api.typeValueResolveMap().default).formatter;
|
|
80
81
|
const format = customFormat || DATEPICKER.DateFormats[type];
|
|
81
|
-
return formatter(value, format);
|
|
82
|
+
return formatter(value, format, formatObj);
|
|
82
83
|
};
|
|
83
84
|
const displayValue = ({ api, props, state }) => () => {
|
|
84
|
-
const
|
|
85
|
+
const formatObj = {
|
|
86
|
+
rangeSeparator: props.rangeSeparator
|
|
87
|
+
};
|
|
88
|
+
const formattedValue = api.formatAsFormatAndType(
|
|
89
|
+
state.parsedValue,
|
|
90
|
+
state.format,
|
|
91
|
+
state.type,
|
|
92
|
+
props.rangeSeparator,
|
|
93
|
+
formatObj
|
|
94
|
+
);
|
|
85
95
|
if (Array.isArray(state.userInput)) {
|
|
86
96
|
return [
|
|
87
97
|
state.userInput[0] || formattedValue && formattedValue[0] || "",
|
|
@@ -110,7 +120,7 @@ const parsedValue = ({ api, props, state, t }) => () => {
|
|
|
110
120
|
return props.modelValue;
|
|
111
121
|
}
|
|
112
122
|
const valueIsDateObject = isDateObject(props.modelValue) || Array.isArray(props.modelValue) && props.modelValue.every(isDateObject);
|
|
113
|
-
const { from, to, isServiceTimezone } = state.timezone;
|
|
123
|
+
const { from, to, isServiceTimezone, timezoneOffset } = state.timezone;
|
|
114
124
|
if (valueIsDateObject && !isServiceTimezone) {
|
|
115
125
|
return props.modelValue;
|
|
116
126
|
}
|
|
@@ -125,18 +135,18 @@ const parsedValue = ({ api, props, state, t }) => () => {
|
|
|
125
135
|
}
|
|
126
136
|
const result = api.parseAsFormatAndType(date, state.valueFormat, state.type, props.rangeSeparator);
|
|
127
137
|
if (Array.isArray(result)) {
|
|
128
|
-
return result.map((date2) => getDateWithNewTimezone(date2, from, to));
|
|
138
|
+
return result.map((date2) => getDateWithNewTimezone(date2, from, to, timezoneOffset));
|
|
129
139
|
}
|
|
130
|
-
return getDateWithNewTimezone(result || props.modelValue, from, to);
|
|
140
|
+
return getDateWithNewTimezone(result || props.modelValue, from, to, timezoneOffset);
|
|
131
141
|
}
|
|
132
142
|
const trans = (value) => typeof value === "string" || isNumber(value) ? toDate(value) : value;
|
|
133
|
-
const values = [].concat(props.modelValue).map((val) => getDateWithNewTimezone(trans(val), from, to));
|
|
143
|
+
const values = [].concat(props.modelValue).map((val) => getDateWithNewTimezone(trans(val), from, to, timezoneOffset));
|
|
134
144
|
return values.length > 1 ? values : values[0];
|
|
135
145
|
};
|
|
136
146
|
const getTimezone = ({ props, utils }) => () => {
|
|
137
|
-
const { dbTimezone, timezone, isutc8, type = "date", iso8601 } = props;
|
|
147
|
+
const { dbTimezone, timezone, isutc8, type = "date", iso8601, timezoneOffset } = props;
|
|
138
148
|
const setting = utils.getDateFormat && utils.getDateFormat();
|
|
139
|
-
const { DbTimezone, Timezone } = setting || {};
|
|
149
|
+
const { DbTimezone, Timezone, TimezoneOffset } = setting || {};
|
|
140
150
|
const cur = getLocalTimezone();
|
|
141
151
|
const isTzNumber = (z) => typeof z === "number" && z >= -12 && z <= 12;
|
|
142
152
|
if (!~type.indexOf("datetime")) {
|
|
@@ -144,6 +154,7 @@ const getTimezone = ({ props, utils }) => () => {
|
|
|
144
154
|
}
|
|
145
155
|
let serveTimezone = isTzNumber(dbTimezone) ? dbTimezone : isTzNumber(DbTimezone) ? DbTimezone : cur;
|
|
146
156
|
let clientTimezone = isTzNumber(timezone) ? timezone : isTzNumber(Timezone) ? Timezone : cur;
|
|
157
|
+
let clientTimezoneOffset = isNumber(timezoneOffset) ? timezoneOffset : isNumber(TimezoneOffset) ? TimezoneOffset : 0;
|
|
147
158
|
const value = props.modelValue;
|
|
148
159
|
const str = (Array.isArray(value) ? value[0] : value) || "";
|
|
149
160
|
const match = typeof str === "string" && str.match(/(-|\+)(\d{2}):?(\d{2})$/);
|
|
@@ -153,7 +164,8 @@ const getTimezone = ({ props, utils }) => () => {
|
|
|
153
164
|
return {
|
|
154
165
|
from: serveTimezone,
|
|
155
166
|
to: isutc8 ? 8 : clientTimezone,
|
|
156
|
-
isServiceTimezone: !!setting
|
|
167
|
+
isServiceTimezone: !!setting,
|
|
168
|
+
timezoneOffset: clientTimezoneOffset
|
|
157
169
|
};
|
|
158
170
|
};
|
|
159
171
|
const nullOrString = (value) => {
|
|
@@ -182,11 +194,12 @@ const dateFormatter = ({ t }) => (value, format) => {
|
|
|
182
194
|
}
|
|
183
195
|
return formatDate(value, format, t);
|
|
184
196
|
};
|
|
185
|
-
const dateParser = ({ t }) => (text, format) => {
|
|
197
|
+
const dateParser = ({ t, props }) => (text, format) => {
|
|
186
198
|
if (format === DATEPICKER.TimesTamp) {
|
|
187
199
|
return new Date(Number(text));
|
|
188
200
|
}
|
|
189
|
-
|
|
201
|
+
const value = props.autoFormat ? formatText({ text, format }) : text;
|
|
202
|
+
return parseDate(value, format, t);
|
|
190
203
|
};
|
|
191
204
|
const rangeFormatter = (api) => (value, format) => {
|
|
192
205
|
if (Array.isArray(value) && value.length === 2) {
|
|
@@ -227,24 +240,43 @@ const getDefaultOfTypeValueResolveMap = () => ({
|
|
|
227
240
|
return text === void 0 || text === "" ? null : text;
|
|
228
241
|
}
|
|
229
242
|
});
|
|
230
|
-
const getWeekOfTypeValueResolveMap = ({ t, api }) => ({
|
|
231
|
-
formatter(value, format) {
|
|
243
|
+
const getWeekOfTypeValueResolveMap = ({ t, props, api }) => ({
|
|
244
|
+
formatter(value, format, formatObj) {
|
|
232
245
|
const weekDate = getWeekData(value);
|
|
233
246
|
let week = getWeekNumber(weekDate);
|
|
234
247
|
let month = weekDate.getMonth();
|
|
235
248
|
const trueDate = new Date(weekDate);
|
|
249
|
+
const { rangeSeparator = "-", type = "format" } = formatObj;
|
|
236
250
|
if (week === 1 && month === 11) {
|
|
237
251
|
trueDate.setHours(0, 0, 0, 0);
|
|
238
252
|
trueDate.setDate(trueDate.getDate() + 3 - (trueDate.getDay() + 6) % 7);
|
|
239
253
|
}
|
|
240
|
-
let date
|
|
241
|
-
|
|
254
|
+
let date;
|
|
255
|
+
if (type === "format" && !/W/.test(format)) {
|
|
256
|
+
const { start, end } = getWeekRange(value, format, t, props.pickerOptions);
|
|
257
|
+
date = `${start} ${rangeSeparator} ${end}`;
|
|
258
|
+
} else {
|
|
259
|
+
date = formatDate(trueDate, format, t);
|
|
260
|
+
date = /WW/.test(date) ? date.replace(/WW/, week < 10 ? "0" + week : week) : date.replace(/W/, week);
|
|
261
|
+
}
|
|
242
262
|
return date;
|
|
243
263
|
},
|
|
244
264
|
parser(text, format) {
|
|
245
265
|
return api.typeValueResolveMap().date.parser(text, format);
|
|
246
266
|
}
|
|
247
267
|
});
|
|
268
|
+
const getWeekRange = (value, format, t, pickerOptions) => {
|
|
269
|
+
const firstDayOfWeek = pickerOptions && pickerOptions.firstDayOfWeek ? pickerOptions.firstDayOfWeek : 7;
|
|
270
|
+
const dayOffset = (value.getDay() - firstDayOfWeek + 7) % 7;
|
|
271
|
+
const startDate = prevDate(value, dayOffset);
|
|
272
|
+
const endDate = nextDate(startDate, 6);
|
|
273
|
+
const start = formatDate(startDate, format, t);
|
|
274
|
+
const end = formatDate(endDate, format, t);
|
|
275
|
+
return {
|
|
276
|
+
start,
|
|
277
|
+
end
|
|
278
|
+
};
|
|
279
|
+
};
|
|
248
280
|
const getNumberOfTypeValueResolveMap = () => ({
|
|
249
281
|
formatter(value) {
|
|
250
282
|
return value ? String(value) : "";
|
|
@@ -264,9 +296,9 @@ const getDatesOfTypeValueResolveMap = (api) => ({
|
|
|
264
296
|
);
|
|
265
297
|
}
|
|
266
298
|
});
|
|
267
|
-
const typeValueResolveMap = ({ api, t }) => () => ({
|
|
299
|
+
const typeValueResolveMap = ({ api, props, t }) => () => ({
|
|
268
300
|
default: getDefaultOfTypeValueResolveMap(),
|
|
269
|
-
week: getWeekOfTypeValueResolveMap({ t, api }),
|
|
301
|
+
week: getWeekOfTypeValueResolveMap({ t, props, api }),
|
|
270
302
|
date: { formatter: api.dateFormatter, parser: api.dateParser },
|
|
271
303
|
datetime: { formatter: api.dateFormatter, parser: api.dateParser },
|
|
272
304
|
daterange: { formatter: api.rangeFormatter, parser: api.rangeParser },
|
|
@@ -305,7 +337,7 @@ const secondInputId = ({ props, state }) => () => {
|
|
|
305
337
|
}
|
|
306
338
|
return obj;
|
|
307
339
|
};
|
|
308
|
-
const focus = ({ api, props, vm }) => () => !props.isRange ? vm.$refs.reference.focus() : api.handleFocus();
|
|
340
|
+
const focus = ({ api, props, vm }) => () => !props.isRange ? vm.$refs.reference.querySelector("input").focus() : api.handleFocus();
|
|
309
341
|
const blur = (state) => () => state.refInput.forEach((input) => input.blur());
|
|
310
342
|
const parseValue = ({ api, props, state }) => (value) => {
|
|
311
343
|
const isParsed = isDateObject(value) || Array.isArray(value) && value.every(isDateObject);
|
|
@@ -314,10 +346,12 @@ const parseValue = ({ api, props, state }) => (value) => {
|
|
|
314
346
|
}
|
|
315
347
|
return value;
|
|
316
348
|
};
|
|
317
|
-
const formatToValue = ({ api,
|
|
349
|
+
const formatToValue = ({ api, state }) => (date) => {
|
|
318
350
|
const isFormattable = isDateObject(date) || Array.isArray(date) && date.every(isDateObject);
|
|
319
351
|
if (state.valueFormat && isFormattable) {
|
|
320
|
-
return api.formatAsFormatAndType(date, state.valueFormat, state.type,
|
|
352
|
+
return api.formatAsFormatAndType(date, state.valueFormat, state.type, {
|
|
353
|
+
type: "value-format"
|
|
354
|
+
});
|
|
321
355
|
}
|
|
322
356
|
return date;
|
|
323
357
|
};
|
|
@@ -354,18 +388,20 @@ const handleChange = ({ api, state }) => () => {
|
|
|
354
388
|
state.userInput = null;
|
|
355
389
|
}
|
|
356
390
|
};
|
|
357
|
-
const handleStartInput = (state) => (event) => {
|
|
391
|
+
const handleStartInput = ({ state, props, api }) => (event) => {
|
|
392
|
+
const value = props.autoFormat ? api.formatInputValue({ event, prevValue: state.displayValue[0] }) : event.target.value;
|
|
358
393
|
if (state.userInput) {
|
|
359
|
-
state.userInput = [
|
|
394
|
+
state.userInput = [value, state.userInput[1]];
|
|
360
395
|
} else {
|
|
361
|
-
state.userInput = [
|
|
396
|
+
state.userInput = [value, null];
|
|
362
397
|
}
|
|
363
398
|
};
|
|
364
|
-
const handleEndInput = (state) => (event) => {
|
|
399
|
+
const handleEndInput = ({ state, props, api }) => (event) => {
|
|
400
|
+
const value = props.autoFormat ? api.formatInputValue({ event, prevValue: state.displayValue[1] }) : event.target.value;
|
|
365
401
|
if (state.userInput) {
|
|
366
|
-
state.userInput = [state.userInput[0],
|
|
402
|
+
state.userInput = [state.userInput[0], value];
|
|
367
403
|
} else {
|
|
368
|
-
state.userInput = [null,
|
|
404
|
+
state.userInput = [null, value];
|
|
369
405
|
}
|
|
370
406
|
};
|
|
371
407
|
const handleStartChange = ({ api, state }) => () => {
|
|
@@ -463,13 +499,19 @@ const handleClose = ({ api, props, state }) => () => {
|
|
|
463
499
|
state.pickerVisible = false;
|
|
464
500
|
if (state.type === DATEPICKER.Dates) {
|
|
465
501
|
const oldValue = api.parseAsFormatAndType(state.valueOnOpen, state.valueFormat, state.type, props.rangeSeparator) || state.valueOnOpen;
|
|
466
|
-
api.emitInput(oldValue);
|
|
502
|
+
api.emitInput(oldValue, true);
|
|
467
503
|
}
|
|
468
504
|
};
|
|
469
|
-
const handleFocus = ({ emit, vm, state }) => () => {
|
|
505
|
+
const handleFocus = ({ emit, vm, state, api }) => () => {
|
|
470
506
|
const type = state.type;
|
|
471
|
-
if (DATEPICKER.TriggerTypes.includes(type)
|
|
472
|
-
state.
|
|
507
|
+
if (DATEPICKER.TriggerTypes.includes(type)) {
|
|
508
|
+
if (state.isMobileScreen && state.isDateMobileComponent) {
|
|
509
|
+
api.dateMobileToggle(true);
|
|
510
|
+
} else if (state.isMobileScreen && state.isTimeMobileComponent) {
|
|
511
|
+
api.timeMobileToggle(true);
|
|
512
|
+
} else {
|
|
513
|
+
state.pickerVisible = true;
|
|
514
|
+
}
|
|
473
515
|
}
|
|
474
516
|
emit("focus", vm.$refs.reference);
|
|
475
517
|
};
|
|
@@ -533,13 +575,17 @@ const showPicker = ({ api, nextTick, updatePopper, state }) => () => {
|
|
|
533
575
|
state.pickerVisible = state.picker.state.visible = true;
|
|
534
576
|
state.picker.state.value = state.parsedValue;
|
|
535
577
|
state.picker.resetView && state.picker.resetView();
|
|
536
|
-
|
|
537
|
-
|
|
578
|
+
nextTick(() => {
|
|
579
|
+
updatePopper(state.picker.$el);
|
|
580
|
+
state.picker.adjustSpinners && state.picker.adjustSpinners();
|
|
581
|
+
});
|
|
538
582
|
};
|
|
539
583
|
const handlePick = ({ state, api }) => (date = "", visible = false) => {
|
|
584
|
+
if (!state.picker)
|
|
585
|
+
return;
|
|
540
586
|
state.userInput = null;
|
|
541
587
|
state.pickerVisible = state.picker.state.visible = visible;
|
|
542
|
-
api.emitInput(date);
|
|
588
|
+
api.emitInput(date, visible);
|
|
543
589
|
state.date = date;
|
|
544
590
|
state.picker.resetView && state.picker.resetView();
|
|
545
591
|
};
|
|
@@ -659,18 +705,21 @@ const emitChange = ({ api, dispatch, emit, props, state }) => (val) => {
|
|
|
659
705
|
api.emitDbTime(props.value);
|
|
660
706
|
}
|
|
661
707
|
};
|
|
662
|
-
const emitInput = ({ api, emit, props, state }) => (val) => {
|
|
708
|
+
const emitInput = ({ api, emit, props, state }) => (val, visible = false) => {
|
|
663
709
|
let value = val;
|
|
664
|
-
const { from, to } = state.timezone;
|
|
710
|
+
const { from, to, timezoneOffset } = state.timezone;
|
|
665
711
|
if (props.type === "datetime") {
|
|
666
|
-
value = getDateWithNewTimezone(value, to, from);
|
|
712
|
+
value = getDateWithNewTimezone(value, to, from, -timezoneOffset);
|
|
667
713
|
} else if (props.type === "datetimerange" && Array.isArray(value)) {
|
|
668
|
-
value = value.map((val2) => getDateWithNewTimezone(val2, to, from));
|
|
714
|
+
value = value.map((val2) => getDateWithNewTimezone(val2, to, from, -timezoneOffset));
|
|
669
715
|
}
|
|
670
716
|
const formatted = api.formatToValue(value) || val;
|
|
671
717
|
if (!valueEquals(props.modelValue, formatted)) {
|
|
672
718
|
emit("update:modelValue", formatted);
|
|
673
719
|
}
|
|
720
|
+
if (!visible && !valueEquals(state.oldValue, formatted)) {
|
|
721
|
+
state.oldValue = formatted;
|
|
722
|
+
}
|
|
674
723
|
};
|
|
675
724
|
const isValidValue = ({ api, state }) => (value) => {
|
|
676
725
|
if (!state.picker) {
|
|
@@ -686,10 +735,10 @@ const watchIsRange = ({ api, state, TimePanel, TimeRangePanel }) => (value) => {
|
|
|
686
735
|
state.panel = value ? TimeRangePanel : TimePanel;
|
|
687
736
|
api.mountPicker();
|
|
688
737
|
};
|
|
689
|
-
const getType = ({ props }) => () => {
|
|
690
|
-
if (
|
|
738
|
+
const getType = ({ parent, props }) => () => {
|
|
739
|
+
if (parent.componentName === DATEPICKER.DatePicker) {
|
|
691
740
|
return props.type;
|
|
692
|
-
} else if (
|
|
741
|
+
} else if (parent.componentName === DATEPICKER.TimePicker) {
|
|
693
742
|
return props.isRange ? DATEPICKER.TimeRange : DATEPICKER.Time;
|
|
694
743
|
}
|
|
695
744
|
return DATEPICKER.TimeSelect;
|
|
@@ -702,7 +751,9 @@ const watchModelValue = ({ api, props, state, dispatch }) => (value, oldValue) =
|
|
|
702
751
|
api.parseString(state.historyInput && state.historyInput[1])
|
|
703
752
|
];
|
|
704
753
|
}
|
|
705
|
-
|
|
754
|
+
if (props.changeCompat) {
|
|
755
|
+
api.emitChange(props.modelValue);
|
|
756
|
+
}
|
|
706
757
|
if (!valueEquals(value, oldValue) && !state.pickerVisible && props.validateEvent) {
|
|
707
758
|
dispatch("FormItem", "form.change", value);
|
|
708
759
|
}
|
|
@@ -724,7 +775,7 @@ const computedTriggerClass = ({ props, state }) => () => props.suffixIcon || pro
|
|
|
724
775
|
const computedHaveTrigger = ({ props }) => () => typeof props.showTrigger !== "undefined" ? props.showTrigger : DATEPICKER.TriggerTypes.includes(props.type);
|
|
725
776
|
const initPopper = ({ props, hooks, vnode }) => {
|
|
726
777
|
const { reactive, watch, toRefs, onBeforeUnmount, onDeactivated } = hooks;
|
|
727
|
-
const { emit,
|
|
778
|
+
const { emit, vm, slots, nextTick } = vnode;
|
|
728
779
|
const placementMap = DATEPICKER.PlacementMap;
|
|
729
780
|
return userPopper({
|
|
730
781
|
reactive,
|
|
@@ -739,7 +790,7 @@ const initPopper = ({ props, hooks, vnode }) => {
|
|
|
739
790
|
placement: placementMap[props.align] || placementMap.left
|
|
740
791
|
}),
|
|
741
792
|
toRefs,
|
|
742
|
-
|
|
793
|
+
vm,
|
|
743
794
|
slots,
|
|
744
795
|
nextTick,
|
|
745
796
|
onBeforeUnmount,
|
|
@@ -795,6 +846,161 @@ const setInputPaddingLeft = ({ props, state, vm, nextTick }) => () => {
|
|
|
795
846
|
});
|
|
796
847
|
}
|
|
797
848
|
};
|
|
849
|
+
const getSelectionStart = ({ value, format, regx, event }) => {
|
|
850
|
+
const formatMatchArr = format.match(regx);
|
|
851
|
+
let selectionStart = getSelectionStartIndex(event);
|
|
852
|
+
let I = 0;
|
|
853
|
+
if (value !== "") {
|
|
854
|
+
const match = value.match(/[0-9]/g);
|
|
855
|
+
I = match === null ? 0 : match.length;
|
|
856
|
+
for (let i = 0; i < formatMatchArr.length; i++) {
|
|
857
|
+
I -= Math.max(formatMatchArr[i].length, 2);
|
|
858
|
+
}
|
|
859
|
+
I = I >= 0 ? 1 : 0;
|
|
860
|
+
I === 1 && selectionStart >= value.length && (selectionStart = value.length - 1);
|
|
861
|
+
}
|
|
862
|
+
return { selectionStart, I };
|
|
863
|
+
};
|
|
864
|
+
const getNum = (value, format, regx) => {
|
|
865
|
+
let len = value.length;
|
|
866
|
+
if (format && regx) {
|
|
867
|
+
const formatMatchArr = format.match(regx);
|
|
868
|
+
len = Math.max(len, formatMatchArr.join("").length);
|
|
869
|
+
}
|
|
870
|
+
let num = { str: "", arr: [] };
|
|
871
|
+
for (let i = 0; i < len; i++) {
|
|
872
|
+
let char = value.charAt(i) ? value.charAt(i) : "00";
|
|
873
|
+
if (/[0-9]/.test(char)) {
|
|
874
|
+
num.str += char;
|
|
875
|
+
} else {
|
|
876
|
+
num.arr[i] = 1;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return num;
|
|
880
|
+
};
|
|
881
|
+
const getSelectionStartIndex = (event) => {
|
|
882
|
+
const inputElem = event.target;
|
|
883
|
+
return inputElem.selectionStart - (event.data ? event.data.length : 0);
|
|
884
|
+
};
|
|
885
|
+
const getNumAndSelectionStart = ({ value, format, regx, event, needSelectionStart }) => {
|
|
886
|
+
if (needSelectionStart) {
|
|
887
|
+
let { selectionStart, I } = getSelectionStart({ value, format, regx, event });
|
|
888
|
+
let valueStr;
|
|
889
|
+
if (event.data) {
|
|
890
|
+
valueStr = value.substring(0, selectionStart) + event.data + value.substring(selectionStart + I);
|
|
891
|
+
selectionStart++;
|
|
892
|
+
} else {
|
|
893
|
+
valueStr = value;
|
|
894
|
+
}
|
|
895
|
+
const numStr = getNum(valueStr);
|
|
896
|
+
return { numStr, selectionStart };
|
|
897
|
+
} else {
|
|
898
|
+
const numStr = getNum(value, format, regx);
|
|
899
|
+
return { numStr };
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
const checkFormat = ({ value, format, startIndex, selectionStart, regx, needSelectionStart }) => {
|
|
903
|
+
if (!needSelectionStart && regx.lastIndex === 0 || needSelectionStart && regx.lastIndex === 0 && selectionStart >= startIndex) {
|
|
904
|
+
const subFormat = `(?<=${format.substring(0, startIndex)})(\\s*\\S*\\s*)+`;
|
|
905
|
+
const pattern = new RegExp(subFormat, "g");
|
|
906
|
+
const res = format.match(pattern);
|
|
907
|
+
if (res) {
|
|
908
|
+
value += res[0];
|
|
909
|
+
selectionStart = value.length;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return { value, selectionStart };
|
|
913
|
+
};
|
|
914
|
+
const moveStart = (inputElem, moveStartIndex) => {
|
|
915
|
+
if (inputElem.setSelectionRange) {
|
|
916
|
+
inputElem.focus();
|
|
917
|
+
setTimeout(() => {
|
|
918
|
+
inputElem.setSelectionRange(moveStartIndex, moveStartIndex);
|
|
919
|
+
}, 0);
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
const handleInput = ({ state, props, api }) => (val, event) => {
|
|
923
|
+
event = val.target ? val : event;
|
|
924
|
+
if (props.autoFormat) {
|
|
925
|
+
const value = api.formatInputValue({ event, prevValue: state.displayValue });
|
|
926
|
+
state.userInput = value;
|
|
927
|
+
} else {
|
|
928
|
+
const val2 = event.target.value;
|
|
929
|
+
state.userInput = val2;
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
const formatInputValue = ({ props, state }) => ({ event, prevValue = "" }) => {
|
|
933
|
+
const val = event.target.value;
|
|
934
|
+
const inputData = event.data;
|
|
935
|
+
const format = state.type === "time-select" ? "HH:mm" : props.format || DATEPICKER.DateFormats[state.type];
|
|
936
|
+
if (inputData && inputData.charCodeAt() >= 48 && inputData.charCodeAt() <= 57) {
|
|
937
|
+
return formatText({ event, format, text: prevValue, needSelectionStart: true });
|
|
938
|
+
} else {
|
|
939
|
+
return val;
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
const formatText = ({ event, text, format, needSelectionStart = false }) => {
|
|
943
|
+
if (!format)
|
|
944
|
+
return text;
|
|
945
|
+
let cursorOffset = 0;
|
|
946
|
+
let value = "";
|
|
947
|
+
let regx = /yyyy|yyy|yy|y|MM|M|dd|d|HH|hh|H|h|mm|m|ss|s|WW|W|w/g;
|
|
948
|
+
let startIndex = 0;
|
|
949
|
+
let { numStr, selectionStart } = getNumAndSelectionStart({
|
|
950
|
+
value: text,
|
|
951
|
+
format,
|
|
952
|
+
regx,
|
|
953
|
+
event,
|
|
954
|
+
needSelectionStart
|
|
955
|
+
});
|
|
956
|
+
let matchResult = regx.exec(format);
|
|
957
|
+
while (numStr.str !== "" && matchResult !== null) {
|
|
958
|
+
let subStr;
|
|
959
|
+
let newNum;
|
|
960
|
+
let subLen;
|
|
961
|
+
const endIndex = matchResult.index;
|
|
962
|
+
if (startIndex >= 0) {
|
|
963
|
+
value += format.substring(startIndex, endIndex);
|
|
964
|
+
}
|
|
965
|
+
selectionStart >= startIndex + cursorOffset && selectionStart <= endIndex + cursorOffset && (selectionStart = selectionStart + endIndex - startIndex);
|
|
966
|
+
startIndex = regx.lastIndex;
|
|
967
|
+
subLen = startIndex - endIndex;
|
|
968
|
+
subStr = numStr.str.substring(0, subLen);
|
|
969
|
+
const firstMatchChar = matchResult[0].charAt(0);
|
|
970
|
+
const firstChar = parseInt(subStr.charAt(0), 10);
|
|
971
|
+
if (numStr.str.length > 1) {
|
|
972
|
+
const secondChar = numStr.str.charAt(1);
|
|
973
|
+
newNum = 10 * firstChar + parseInt(secondChar, 10);
|
|
974
|
+
} else {
|
|
975
|
+
newNum = firstChar;
|
|
976
|
+
}
|
|
977
|
+
if (numStr.arr[endIndex + 1] || firstMatchChar === "M" && newNum > 12 || firstMatchChar === "d" && newNum > 31 || ["H", "h"].includes(firstMatchChar) && newNum > 23 || "ms".includes(firstMatchChar) && newNum > 59) {
|
|
978
|
+
subStr = matchResult[0].length === 2 ? "0" + firstChar : firstChar;
|
|
979
|
+
selectionStart++;
|
|
980
|
+
} else {
|
|
981
|
+
if (subLen === 1) {
|
|
982
|
+
subStr = String(newNum);
|
|
983
|
+
subLen++;
|
|
984
|
+
cursorOffset++;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
value += subStr;
|
|
988
|
+
numStr.str = numStr.str.substring(subLen);
|
|
989
|
+
matchResult = regx.exec(format);
|
|
990
|
+
}
|
|
991
|
+
const { value: val, selectionStart: cursorPos } = checkFormat({
|
|
992
|
+
value,
|
|
993
|
+
format,
|
|
994
|
+
startIndex,
|
|
995
|
+
selectionStart,
|
|
996
|
+
regx,
|
|
997
|
+
needSelectionStart
|
|
998
|
+
});
|
|
999
|
+
value = val;
|
|
1000
|
+
selectionStart = cursorPos;
|
|
1001
|
+
needSelectionStart && moveStart(event.target, selectionStart);
|
|
1002
|
+
return value;
|
|
1003
|
+
};
|
|
798
1004
|
export {
|
|
799
1005
|
blur,
|
|
800
1006
|
computedFormat,
|
|
@@ -809,6 +1015,8 @@ export {
|
|
|
809
1015
|
firstInputId,
|
|
810
1016
|
focus,
|
|
811
1017
|
formatAsFormatAndType,
|
|
1018
|
+
formatInputValue,
|
|
1019
|
+
formatText,
|
|
812
1020
|
formatToString,
|
|
813
1021
|
formatToValue,
|
|
814
1022
|
getMode,
|
|
@@ -826,6 +1034,7 @@ export {
|
|
|
826
1034
|
handleEnterDisplayOnlyContent,
|
|
827
1035
|
handleEnterPickerlabel,
|
|
828
1036
|
handleFocus,
|
|
1037
|
+
handleInput,
|
|
829
1038
|
handleKeydown,
|
|
830
1039
|
handleMouseEnter,
|
|
831
1040
|
handlePick,
|