yy-vue-easytable 2.27.2
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/LICENSE +22 -0
- package/README.md +187 -0
- package/libs/font/demo.css +539 -0
- package/libs/font/demo_index.html +400 -0
- package/libs/font/iconfont.css +57 -0
- package/libs/font/iconfont.eot +0 -0
- package/libs/font/iconfont.js +1 -0
- package/libs/font/iconfont.json +79 -0
- package/libs/font/iconfont.svg +56 -0
- package/libs/font/iconfont.ttf +0 -0
- package/libs/font/iconfont.woff +0 -0
- package/libs/font/iconfont.woff2 +0 -0
- package/libs/locale/lang/af-ZA.js +48 -0
- package/libs/locale/lang/en-US.js +48 -0
- package/libs/locale/lang/fr-FR.js +48 -0
- package/libs/locale/lang/ko-KR.js +48 -0
- package/libs/locale/lang/pt-BR.js +48 -0
- package/libs/locale/lang/ru-RU.js +48 -0
- package/libs/locale/lang/zh-CN.js +48 -0
- package/libs/locale/lang/zh-TW.js +48 -0
- package/libs/locale/lang/zu-ZA.js +48 -0
- package/libs/main.js +1 -0
- package/libs/theme-dark/base.css +1 -0
- package/libs/theme-dark/index.css +1253 -0
- package/libs/theme-dark/var.css +7 -0
- package/libs/theme-dark/ve-checkbox.css +150 -0
- package/libs/theme-dark/ve-contextmenu.css +71 -0
- package/libs/theme-dark/ve-dropdown.css +177 -0
- package/libs/theme-dark/ve-icon.css +10 -0
- package/libs/theme-dark/ve-loading.css +218 -0
- package/libs/theme-dark/ve-pagination.css +136 -0
- package/libs/theme-dark/ve-radio.css +111 -0
- package/libs/theme-dark/ve-select.css +50 -0
- package/libs/theme-dark/ve-table.css +385 -0
- package/libs/theme-default/base.css +1 -0
- package/libs/theme-default/index.css +1253 -0
- package/libs/theme-default/var.css +7 -0
- package/libs/theme-default/ve-checkbox.css +150 -0
- package/libs/theme-default/ve-contextmenu.css +71 -0
- package/libs/theme-default/ve-dropdown.css +177 -0
- package/libs/theme-default/ve-icon.css +10 -0
- package/libs/theme-default/ve-loading.css +218 -0
- package/libs/theme-default/ve-pagination.css +136 -0
- package/libs/theme-default/ve-radio.css +111 -0
- package/libs/theme-default/ve-select.css +50 -0
- package/libs/theme-default/ve-table.css +385 -0
- package/libs/umd/index.js +9 -0
- package/libs/ve-checkbox-group.js +1 -0
- package/libs/ve-checkbox.js +1 -0
- package/libs/ve-contextmenu.js +1 -0
- package/libs/ve-dropdown.js +1 -0
- package/libs/ve-icon.js +1 -0
- package/libs/ve-loading.js +1 -0
- package/libs/ve-locale.js +1 -0
- package/libs/ve-pagination.js +1 -0
- package/libs/ve-radio.js +1 -0
- package/libs/ve-select.js +1 -0
- package/libs/ve-table.js +1 -0
- package/package.json +142 -0
- package/packages/font/demo.css +539 -0
- package/packages/font/demo_index.html +400 -0
- package/packages/font/iconfont.css +57 -0
- package/packages/font/iconfont.eot +0 -0
- package/packages/font/iconfont.js +1 -0
- package/packages/font/iconfont.json +79 -0
- package/packages/font/iconfont.svg +56 -0
- package/packages/font/iconfont.ttf +0 -0
- package/packages/font/iconfont.woff +0 -0
- package/packages/font/iconfont.woff2 +0 -0
- package/packages/index.js +75 -0
- package/packages/src/comps/resize-observer/index.js +2 -0
- package/packages/src/comps/resize-observer/src/index.jsx +38 -0
- package/packages/src/directives/clickoutside.js +31 -0
- package/packages/src/directives/events-outside.js +79 -0
- package/packages/src/directives/focus.js +28 -0
- package/packages/src/locale/index.js +27 -0
- package/packages/src/locale/lang/af-ZA.js +29 -0
- package/packages/src/locale/lang/en-US.js +30 -0
- package/packages/src/locale/lang/fr-FR.js +29 -0
- package/packages/src/locale/lang/ko-KR.js +29 -0
- package/packages/src/locale/lang/pt-BR.js +29 -0
- package/packages/src/locale/lang/ru-RU.js +29 -0
- package/packages/src/locale/lang/zh-CN.js +30 -0
- package/packages/src/locale/lang/zh-TW.js +29 -0
- package/packages/src/locale/lang/zu-ZA.js +29 -0
- package/packages/src/mixins/emitter.js +39 -0
- package/packages/src/utils/animation-frame.js +39 -0
- package/packages/src/utils/auto-resize.js +179 -0
- package/packages/src/utils/constant.js +42 -0
- package/packages/src/utils/dom.js +239 -0
- package/packages/src/utils/event-key-codes.js +53 -0
- package/packages/src/utils/hooks-manager.js +76 -0
- package/packages/src/utils/index.js +161 -0
- package/packages/src/utils/mouse-event.js +24 -0
- package/packages/src/utils/random.js +6 -0
- package/packages/src/utils/request-animation-timeout.js +36 -0
- package/packages/src/utils/resize-event.js +40 -0
- package/packages/src/utils/scroll-bar.js +27 -0
- package/packages/style/ve-checkbox.less +179 -0
- package/packages/style/ve-contextmenu.less +76 -0
- package/packages/style/ve-dropdown.less +204 -0
- package/packages/style/ve-icon.less +3 -0
- package/packages/style/ve-loading.less +242 -0
- package/packages/style/ve-pagination.less +153 -0
- package/packages/style/ve-radio.less +126 -0
- package/packages/style/ve-select.less +48 -0
- package/packages/style/ve-table.less +539 -0
- package/packages/theme-dark/base.less +1 -0
- package/packages/theme-dark/index.less +12 -0
- package/packages/theme-dark/var.less +111 -0
- package/packages/theme-dark/ve-checkbox.less +2 -0
- package/packages/theme-dark/ve-contextmenu.less +2 -0
- package/packages/theme-dark/ve-dropdown.less +2 -0
- package/packages/theme-dark/ve-icon.less +2 -0
- package/packages/theme-dark/ve-loading.less +2 -0
- package/packages/theme-dark/ve-pagination.less +2 -0
- package/packages/theme-dark/ve-radio.less +2 -0
- package/packages/theme-dark/ve-select.less +2 -0
- package/packages/theme-dark/ve-table.less +2 -0
- package/packages/theme-default/base.less +1 -0
- package/packages/theme-default/index.less +12 -0
- package/packages/theme-default/var.less +111 -0
- package/packages/theme-default/ve-checkbox.less +2 -0
- package/packages/theme-default/ve-contextmenu.less +2 -0
- package/packages/theme-default/ve-dropdown.less +2 -0
- package/packages/theme-default/ve-icon.less +2 -0
- package/packages/theme-default/ve-loading.less +2 -0
- package/packages/theme-default/ve-pagination.less +2 -0
- package/packages/theme-default/ve-radio.less +2 -0
- package/packages/theme-default/ve-select.less +2 -0
- package/packages/theme-default/ve-table.less +2 -0
- package/packages/ve-checkbox/index.js +7 -0
- package/packages/ve-checkbox/src/index.jsx +175 -0
- package/packages/ve-checkbox/src/util/constant.js +14 -0
- package/packages/ve-checkbox/src/util/index.js +10 -0
- package/packages/ve-checkbox-group/index.js +7 -0
- package/packages/ve-checkbox-group/src/index.jsx +53 -0
- package/packages/ve-checkbox-group/src/util/constant.js +14 -0
- package/packages/ve-checkbox-group/src/util/index.js +10 -0
- package/packages/ve-contextmenu/index.js +7 -0
- package/packages/ve-contextmenu/src/index.jsx +731 -0
- package/packages/ve-contextmenu/src/util/constant.js +29 -0
- package/packages/ve-contextmenu/src/util/index.js +10 -0
- package/packages/ve-dropdown/index.js +7 -0
- package/packages/ve-dropdown/src/index.jsx +720 -0
- package/packages/ve-dropdown/src/util/constant.js +15 -0
- package/packages/ve-dropdown/src/util/index.js +10 -0
- package/packages/ve-icon/index.js +7 -0
- package/packages/ve-icon/src/index.jsx +52 -0
- package/packages/ve-icon/src/util/constant.js +10 -0
- package/packages/ve-icon/src/util/index.js +10 -0
- package/packages/ve-loading/index.js +8 -0
- package/packages/ve-loading/src/bounce.jsx +50 -0
- package/packages/ve-loading/src/flow.jsx +51 -0
- package/packages/ve-loading/src/grid.jsx +57 -0
- package/packages/ve-loading/src/index.js +106 -0
- package/packages/ve-loading/src/loading.jsx +63 -0
- package/packages/ve-loading/src/plane.jsx +38 -0
- package/packages/ve-loading/src/pulse.jsx +38 -0
- package/packages/ve-loading/src/util/constant.js +31 -0
- package/packages/ve-loading/src/util/index.js +10 -0
- package/packages/ve-loading/src/wave.jsx +53 -0
- package/packages/ve-locale/index.js +28 -0
- package/packages/ve-pagination/index.js +7 -0
- package/packages/ve-pagination/src/index.jsx +304 -0
- package/packages/ve-pagination/src/pager.jsx +166 -0
- package/packages/ve-pagination/src/util/constant.js +16 -0
- package/packages/ve-pagination/src/util/index.js +10 -0
- package/packages/ve-radio/index.js +7 -0
- package/packages/ve-radio/src/index.jsx +121 -0
- package/packages/ve-radio/src/util/constant.js +13 -0
- package/packages/ve-radio/src/util/index.js +10 -0
- package/packages/ve-select/index.js +7 -0
- package/packages/ve-select/src/index.jsx +193 -0
- package/packages/ve-select/src/util/constant.js +13 -0
- package/packages/ve-select/src/util/index.js +10 -0
- package/packages/ve-table/index.js +7 -0
- package/packages/ve-table/src/body/body-checkbox-content.jsx +126 -0
- package/packages/ve-table/src/body/body-radio-content.jsx +113 -0
- package/packages/ve-table/src/body/body-td.jsx +671 -0
- package/packages/ve-table/src/body/body-tr-scrolling.jsx +38 -0
- package/packages/ve-table/src/body/body-tr.jsx +383 -0
- package/packages/ve-table/src/body/expand-tr-icon.jsx +80 -0
- package/packages/ve-table/src/body/expand-tr.jsx +147 -0
- package/packages/ve-table/src/body/index.jsx +943 -0
- package/packages/ve-table/src/colgroup/index.jsx +48 -0
- package/packages/ve-table/src/column-resizer/index.jsx +318 -0
- package/packages/ve-table/src/editor/constant.js +5 -0
- package/packages/ve-table/src/editor/index.jsx +533 -0
- package/packages/ve-table/src/footer/footer-td.jsx +396 -0
- package/packages/ve-table/src/footer/footer-tr.jsx +249 -0
- package/packages/ve-table/src/footer/index.jsx +108 -0
- package/packages/ve-table/src/header/header-checkbox-content.jsx +69 -0
- package/packages/ve-table/src/header/header-filter-content.jsx +100 -0
- package/packages/ve-table/src/header/header-filter-custom-content.jsx +110 -0
- package/packages/ve-table/src/header/header-th.jsx +664 -0
- package/packages/ve-table/src/header/header-tr.jsx +255 -0
- package/packages/ve-table/src/header/index.jsx +195 -0
- package/packages/ve-table/src/index.jsx +4196 -0
- package/packages/ve-table/src/selection/constant.js +5 -0
- package/packages/ve-table/src/selection/index.jsx +1643 -0
- package/packages/ve-table/src/util/clipboard.js +428 -0
- package/packages/ve-table/src/util/constant.js +269 -0
- package/packages/ve-table/src/util/index.js +1585 -0
- package/packages/ve-table/src/util/store.js +14 -0
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
import { clsName, getFixedTotalWidthByColumnKey } from "../util";
|
|
2
|
+
import { INSTANCE_METHODS } from "./constant";
|
|
3
|
+
import { COMPS_NAME, EMIT_EVENTS, HOOKS_NAME } from "../util/constant";
|
|
4
|
+
import emitter from "../../../src/mixins/emitter";
|
|
5
|
+
import focus from "../../../src/directives/focus.js";
|
|
6
|
+
import { autoResize } from "../../../src/utils/auto-resize";
|
|
7
|
+
import { isEmptyValue } from "../../../src/utils/index.js";
|
|
8
|
+
import { getCaretPosition, setCaretPosition } from "../../../src/utils/dom";
|
|
9
|
+
import { debounce } from "lodash";
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
name: COMPS_NAME.VE_TABLE_EDIT_INPUT,
|
|
13
|
+
directives: {
|
|
14
|
+
focus: focus,
|
|
15
|
+
},
|
|
16
|
+
mixins: [emitter],
|
|
17
|
+
props: {
|
|
18
|
+
parentRendered: {
|
|
19
|
+
type: Boolean,
|
|
20
|
+
required: true,
|
|
21
|
+
},
|
|
22
|
+
hooks: {
|
|
23
|
+
type: Object,
|
|
24
|
+
required: true,
|
|
25
|
+
},
|
|
26
|
+
// start input value every time
|
|
27
|
+
inputStartValue: {
|
|
28
|
+
type: [String, Number],
|
|
29
|
+
required: true,
|
|
30
|
+
},
|
|
31
|
+
rowKeyFieldName: {
|
|
32
|
+
type: String,
|
|
33
|
+
default: null,
|
|
34
|
+
},
|
|
35
|
+
// table data
|
|
36
|
+
tableData: {
|
|
37
|
+
type: Array,
|
|
38
|
+
required: true,
|
|
39
|
+
},
|
|
40
|
+
colgroups: {
|
|
41
|
+
type: Array,
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
// cell selection option
|
|
45
|
+
cellSelectionData: {
|
|
46
|
+
type: Object,
|
|
47
|
+
required: true,
|
|
48
|
+
},
|
|
49
|
+
// editing cell
|
|
50
|
+
editingCell: {
|
|
51
|
+
type: Object,
|
|
52
|
+
required: true,
|
|
53
|
+
},
|
|
54
|
+
// is editing cell
|
|
55
|
+
isCellEditing: {
|
|
56
|
+
type: Boolean,
|
|
57
|
+
required: true,
|
|
58
|
+
},
|
|
59
|
+
// has horizontal scroll bar
|
|
60
|
+
hasXScrollBar: {
|
|
61
|
+
type: Boolean,
|
|
62
|
+
required: true,
|
|
63
|
+
},
|
|
64
|
+
// has vertical scroll bar
|
|
65
|
+
hasYScrollBar: {
|
|
66
|
+
type: Boolean,
|
|
67
|
+
required: true,
|
|
68
|
+
},
|
|
69
|
+
// has right fixed column
|
|
70
|
+
hasRightFixedColumn: {
|
|
71
|
+
type: Boolean,
|
|
72
|
+
required: true,
|
|
73
|
+
},
|
|
74
|
+
scrollBarWidth: {
|
|
75
|
+
type: Number,
|
|
76
|
+
required: true,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
data() {
|
|
80
|
+
return {
|
|
81
|
+
textareaInputRef: "textareaInputRef",
|
|
82
|
+
// raw cell value
|
|
83
|
+
rawCellValue: "",
|
|
84
|
+
// display textarea
|
|
85
|
+
displayTextarea: false,
|
|
86
|
+
// virtual scroll overflowViewport
|
|
87
|
+
overflowViewport: false,
|
|
88
|
+
// textarea element rect
|
|
89
|
+
textareaRect: {
|
|
90
|
+
left: 0,
|
|
91
|
+
top: 0,
|
|
92
|
+
},
|
|
93
|
+
// table element
|
|
94
|
+
tableEl: null,
|
|
95
|
+
// cell element
|
|
96
|
+
cellEl: null,
|
|
97
|
+
// auto resize
|
|
98
|
+
autoResize: null,
|
|
99
|
+
// is edit cell focus
|
|
100
|
+
isEditCellFocus: false,
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
computed: {
|
|
104
|
+
// current column
|
|
105
|
+
currentColumn() {
|
|
106
|
+
let result = null;
|
|
107
|
+
|
|
108
|
+
const { colgroups, cellSelectionData } = this;
|
|
109
|
+
|
|
110
|
+
const { currentCell } = cellSelectionData;
|
|
111
|
+
|
|
112
|
+
if (
|
|
113
|
+
!isEmptyValue(currentCell.rowKey) &&
|
|
114
|
+
!isEmptyValue(currentCell.colKey)
|
|
115
|
+
) {
|
|
116
|
+
result = colgroups.find((x) => x.key === currentCell.colKey);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return result;
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
// container class
|
|
123
|
+
containerClass() {
|
|
124
|
+
let result = null;
|
|
125
|
+
|
|
126
|
+
const { displayTextarea, overflowViewport } = this;
|
|
127
|
+
|
|
128
|
+
result = {
|
|
129
|
+
[clsName("edit-input-container")]: true,
|
|
130
|
+
[clsName("edit-input-container-show")]:
|
|
131
|
+
displayTextarea && !overflowViewport,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return result;
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
// container style
|
|
138
|
+
containerStyle() {
|
|
139
|
+
let result = {};
|
|
140
|
+
|
|
141
|
+
const {
|
|
142
|
+
displayTextarea,
|
|
143
|
+
overflowViewport,
|
|
144
|
+
textareaRect,
|
|
145
|
+
currentColumn: column,
|
|
146
|
+
} = this;
|
|
147
|
+
|
|
148
|
+
const { top, left } = textareaRect;
|
|
149
|
+
|
|
150
|
+
if (displayTextarea && !overflowViewport) {
|
|
151
|
+
result = {
|
|
152
|
+
top: top + "px",
|
|
153
|
+
left: left + "px",
|
|
154
|
+
height: null,
|
|
155
|
+
// because @ve-fixed-body-cell-index: 10;
|
|
156
|
+
"z-index": column.fixed ? 10 : 0,
|
|
157
|
+
opacity: 1,
|
|
158
|
+
};
|
|
159
|
+
} else {
|
|
160
|
+
result = {
|
|
161
|
+
top: top + "px",
|
|
162
|
+
left: left + "px",
|
|
163
|
+
height: "1px",
|
|
164
|
+
"z-index": -1,
|
|
165
|
+
opacity: 0,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return result;
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
// textarea class
|
|
173
|
+
textareaClass() {
|
|
174
|
+
let result = null;
|
|
175
|
+
|
|
176
|
+
result = {
|
|
177
|
+
[clsName("edit-input")]: true,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
return result;
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
watch: {
|
|
185
|
+
parentRendered: {
|
|
186
|
+
handler: function (val) {
|
|
187
|
+
if (val) {
|
|
188
|
+
// fixed #471
|
|
189
|
+
this.setTableEl();
|
|
190
|
+
|
|
191
|
+
// add table container scroll hook
|
|
192
|
+
this.hooks.addHook(
|
|
193
|
+
HOOKS_NAME.TABLE_CONTAINER_SCROLL,
|
|
194
|
+
() => {
|
|
195
|
+
if (this.displayTextarea) {
|
|
196
|
+
if (!this.cellEl) {
|
|
197
|
+
this.setCellEl();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
this.debounceSetCellEl();
|
|
201
|
+
this.setTextareaPosition();
|
|
202
|
+
this.debounceSetTextareaPosition();
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
// add table size change hook
|
|
206
|
+
this.hooks.addHook(HOOKS_NAME.TABLE_SIZE_CHANGE, () => {
|
|
207
|
+
this.setTextareaPosition();
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
immediate: true,
|
|
212
|
+
},
|
|
213
|
+
// cell selection key data
|
|
214
|
+
"cellSelectionData.currentCell": {
|
|
215
|
+
handler: function (val) {
|
|
216
|
+
this.isEditCellFocus = false;
|
|
217
|
+
|
|
218
|
+
const { rowKey, colKey } = val;
|
|
219
|
+
if (!isEmptyValue(rowKey) && !isEmptyValue(colKey)) {
|
|
220
|
+
this.setCellEl();
|
|
221
|
+
// wait for selection cell rendered
|
|
222
|
+
this.$nextTick(() => {
|
|
223
|
+
this.setTextareaPosition();
|
|
224
|
+
setTimeout(() => {
|
|
225
|
+
this.isEditCellFocus = true;
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
deep: true,
|
|
231
|
+
immediate: true,
|
|
232
|
+
},
|
|
233
|
+
// watch normal end cell
|
|
234
|
+
"cellSelectionData.normalEndCell": {
|
|
235
|
+
handler: function (val) {
|
|
236
|
+
/*
|
|
237
|
+
trigger editor(textarea) element select
|
|
238
|
+
解决通过点击的区域选择,无法复制的问题
|
|
239
|
+
*/
|
|
240
|
+
if (!isEmptyValue(val.colKey)) {
|
|
241
|
+
this[INSTANCE_METHODS.TEXTAREA_SELECT]();
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
deep: true,
|
|
245
|
+
immediate: true,
|
|
246
|
+
},
|
|
247
|
+
// is editing cell
|
|
248
|
+
isCellEditing: {
|
|
249
|
+
handler: function (val) {
|
|
250
|
+
if (val) {
|
|
251
|
+
this.showTextarea();
|
|
252
|
+
} else {
|
|
253
|
+
this.hideTextarea();
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
deep: true,
|
|
257
|
+
immediate: true,
|
|
258
|
+
},
|
|
259
|
+
inputStartValue: {
|
|
260
|
+
handler: function () {
|
|
261
|
+
this.setRawCellValue();
|
|
262
|
+
},
|
|
263
|
+
immediate: true,
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
|
|
267
|
+
methods: {
|
|
268
|
+
// set table element
|
|
269
|
+
setTableEl() {
|
|
270
|
+
this.$nextTick(() => {
|
|
271
|
+
const tableEl = this.$el.previousElementSibling;
|
|
272
|
+
this.tableEl = tableEl;
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
|
|
276
|
+
// set cell element
|
|
277
|
+
setCellEl() {
|
|
278
|
+
const { cellSelectionData, tableEl } = this;
|
|
279
|
+
|
|
280
|
+
const { rowKey, colKey } = cellSelectionData.currentCell;
|
|
281
|
+
|
|
282
|
+
if (tableEl) {
|
|
283
|
+
const cellEl = tableEl.querySelector(
|
|
284
|
+
`tbody.ve-table-body tr[row-key="${rowKey}"] td[col-key="${colKey}"]`,
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
if (cellEl) {
|
|
288
|
+
this.cellEl = cellEl;
|
|
289
|
+
this.overflowViewport = false;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
|
|
294
|
+
// set textarea position
|
|
295
|
+
setTextareaPosition() {
|
|
296
|
+
const {
|
|
297
|
+
hasXScrollBar,
|
|
298
|
+
hasYScrollBar,
|
|
299
|
+
scrollBarWidth,
|
|
300
|
+
colgroups,
|
|
301
|
+
hasRightFixedColumn,
|
|
302
|
+
currentColumn: column,
|
|
303
|
+
cellEl,
|
|
304
|
+
tableEl,
|
|
305
|
+
} = this;
|
|
306
|
+
|
|
307
|
+
if (cellEl && tableEl) {
|
|
308
|
+
const {
|
|
309
|
+
left: tableLeft,
|
|
310
|
+
top: tableTop,
|
|
311
|
+
right: tableRight,
|
|
312
|
+
bottom: tableBottom,
|
|
313
|
+
} = tableEl.getBoundingClientRect();
|
|
314
|
+
|
|
315
|
+
const {
|
|
316
|
+
left: cellLeft,
|
|
317
|
+
top: cellTop,
|
|
318
|
+
height: cellHeight,
|
|
319
|
+
width: cellWidth,
|
|
320
|
+
right: cellRight,
|
|
321
|
+
bottom: cellBottom,
|
|
322
|
+
} = cellEl.getBoundingClientRect();
|
|
323
|
+
|
|
324
|
+
if (cellHeight && cellWidth) {
|
|
325
|
+
let maxHeight = cellHeight + tableBottom - cellBottom;
|
|
326
|
+
let maxWidth = cellWidth + tableRight - cellRight;
|
|
327
|
+
|
|
328
|
+
// has horizontal scroll bar
|
|
329
|
+
if (hasXScrollBar) {
|
|
330
|
+
maxHeight -= scrollBarWidth;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// has vertical scroll bar
|
|
334
|
+
if (hasYScrollBar) {
|
|
335
|
+
maxWidth -= scrollBarWidth;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/*
|
|
339
|
+
If the right fixed column is included, the max width of the textarea needs to be subtracted from the sum of the right fixed columns
|
|
340
|
+
如果包含右固定列,编辑框最大宽度需要去减去右固定列之和的宽度
|
|
341
|
+
*/
|
|
342
|
+
if (hasRightFixedColumn) {
|
|
343
|
+
if (column && !column.fixed) {
|
|
344
|
+
const rightFixedTotalWidth =
|
|
345
|
+
getFixedTotalWidthByColumnKey({
|
|
346
|
+
colgroups,
|
|
347
|
+
colKey: column.key,
|
|
348
|
+
fixed: "right",
|
|
349
|
+
});
|
|
350
|
+
if (rightFixedTotalWidth) {
|
|
351
|
+
maxWidth -= rightFixedTotalWidth;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
this.autoResize.init(
|
|
357
|
+
this.$refs[this.textareaInputRef],
|
|
358
|
+
{
|
|
359
|
+
minHeight: Math.min(cellHeight, maxHeight),
|
|
360
|
+
maxHeight: maxHeight, // TEXTAREA should never be higher than visible part of the viewport (should not cover the scrollbar)
|
|
361
|
+
minWidth: Math.min(cellWidth, maxWidth),
|
|
362
|
+
maxWidth: maxWidth, // TEXTAREA should never be wider than visible part of the viewport (should not cover the scrollbar)
|
|
363
|
+
},
|
|
364
|
+
true, // observe textarea change\cut\paste etc.
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
this.textareaRect = {
|
|
368
|
+
left: cellLeft - tableLeft,
|
|
369
|
+
top: cellTop - tableTop,
|
|
370
|
+
};
|
|
371
|
+
} else {
|
|
372
|
+
/*
|
|
373
|
+
存在以下可能:
|
|
374
|
+
1、虚拟滚动超出viewport
|
|
375
|
+
2、单元格被删除(通过右键菜单等方式)
|
|
376
|
+
*/
|
|
377
|
+
|
|
378
|
+
// fixed #477
|
|
379
|
+
this.textareaRect = {
|
|
380
|
+
left: 0,
|
|
381
|
+
top: 0,
|
|
382
|
+
};
|
|
383
|
+
this.cellEl = null;
|
|
384
|
+
this.overflowViewport = true;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
|
|
389
|
+
// show textarea
|
|
390
|
+
showTextarea() {
|
|
391
|
+
this.setRawCellValue();
|
|
392
|
+
this.displayTextarea = true;
|
|
393
|
+
},
|
|
394
|
+
|
|
395
|
+
// hide textarea
|
|
396
|
+
hideTextarea() {
|
|
397
|
+
this.displayTextarea = false;
|
|
398
|
+
this.textareaUnObserve();
|
|
399
|
+
},
|
|
400
|
+
|
|
401
|
+
// textarea unObserve
|
|
402
|
+
textareaUnObserve() {
|
|
403
|
+
if (this.autoResize) {
|
|
404
|
+
this.autoResize.unObserve();
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
|
|
408
|
+
// set raw cell value
|
|
409
|
+
setRawCellValue() {
|
|
410
|
+
this.rawCellValue = this.inputStartValue;
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
// textarea value change
|
|
414
|
+
textareaValueChange(val) {
|
|
415
|
+
this.$emit(EMIT_EVENTS.EDIT_INPUT_VALUE_CHANGE, val);
|
|
416
|
+
},
|
|
417
|
+
|
|
418
|
+
// textarea select
|
|
419
|
+
[INSTANCE_METHODS.TEXTAREA_SELECT]() {
|
|
420
|
+
const textareaInputEl = this.$refs[this.textareaInputRef];
|
|
421
|
+
if (textareaInputEl) {
|
|
422
|
+
textareaInputEl.select();
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
|
|
426
|
+
// textarea add new line
|
|
427
|
+
[INSTANCE_METHODS.TEXTAREA_ADD_NEW_LINE]() {
|
|
428
|
+
const { isCellEditing, editingCell } = this;
|
|
429
|
+
|
|
430
|
+
if (isCellEditing) {
|
|
431
|
+
const textareaInputEl = this.$refs[this.textareaInputRef];
|
|
432
|
+
|
|
433
|
+
const caretPosition = getCaretPosition(textareaInputEl);
|
|
434
|
+
|
|
435
|
+
let value = editingCell.row[editingCell.colKey];
|
|
436
|
+
// solve error of number slice method
|
|
437
|
+
value += "";
|
|
438
|
+
|
|
439
|
+
const newValue = `${value.slice(
|
|
440
|
+
0,
|
|
441
|
+
caretPosition,
|
|
442
|
+
)}\n${value.slice(caretPosition)}`;
|
|
443
|
+
|
|
444
|
+
// 直接更新 textarea 值
|
|
445
|
+
textareaInputEl.value = newValue;
|
|
446
|
+
|
|
447
|
+
// 手动赋值不会触发textarea 文本变化事件,需要手动更新 editingCell 值
|
|
448
|
+
this.textareaValueChange(newValue);
|
|
449
|
+
|
|
450
|
+
setCaretPosition(textareaInputEl, caretPosition + 1);
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
created() {
|
|
455
|
+
// debounce set textarea position
|
|
456
|
+
this.debounceSetTextareaPosition = debounce(
|
|
457
|
+
this.setTextareaPosition,
|
|
458
|
+
210,
|
|
459
|
+
);
|
|
460
|
+
// debounce set cell el
|
|
461
|
+
this.debounceSetCellEl = debounce(() => {
|
|
462
|
+
if (this.displayTextarea) {
|
|
463
|
+
if (!this.cellEl) {
|
|
464
|
+
this.setCellEl();
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}, 200);
|
|
468
|
+
},
|
|
469
|
+
mounted() {
|
|
470
|
+
this.autoResize = autoResize();
|
|
471
|
+
},
|
|
472
|
+
destroyed() {
|
|
473
|
+
this.textareaUnObserve();
|
|
474
|
+
},
|
|
475
|
+
render() {
|
|
476
|
+
const {
|
|
477
|
+
containerClass,
|
|
478
|
+
containerStyle,
|
|
479
|
+
textareaClass,
|
|
480
|
+
rawCellValue,
|
|
481
|
+
isCellEditing,
|
|
482
|
+
isEditCellFocus,
|
|
483
|
+
} = this;
|
|
484
|
+
|
|
485
|
+
const containerProps = {
|
|
486
|
+
style: containerStyle,
|
|
487
|
+
class: containerClass,
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
const textareaProps = {
|
|
491
|
+
ref: this.textareaInputRef,
|
|
492
|
+
class: textareaClass,
|
|
493
|
+
directives: [
|
|
494
|
+
{
|
|
495
|
+
name: "focus",
|
|
496
|
+
value: {
|
|
497
|
+
focus: isEditCellFocus,
|
|
498
|
+
},
|
|
499
|
+
},
|
|
500
|
+
],
|
|
501
|
+
domProps: { value: rawCellValue },
|
|
502
|
+
attrs: {
|
|
503
|
+
tabindex: -1,
|
|
504
|
+
},
|
|
505
|
+
on: {
|
|
506
|
+
input: (e) => {
|
|
507
|
+
if (isCellEditing) {
|
|
508
|
+
this.textareaValueChange(e.target.value);
|
|
509
|
+
this.rawCellValue = e.target.value;
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
click: () => {
|
|
513
|
+
this.$emit(EMIT_EVENTS.EDIT_INPUT_CLICK);
|
|
514
|
+
},
|
|
515
|
+
copy: (e) => {
|
|
516
|
+
this.$emit(EMIT_EVENTS.EDIT_INPUT_COPY, e);
|
|
517
|
+
},
|
|
518
|
+
paste: (e) => {
|
|
519
|
+
this.$emit(EMIT_EVENTS.EDIT_INPUT_PASTE, e);
|
|
520
|
+
},
|
|
521
|
+
cut: (e) => {
|
|
522
|
+
this.$emit(EMIT_EVENTS.EDIT_INPUT_CUT, e);
|
|
523
|
+
},
|
|
524
|
+
},
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
return (
|
|
528
|
+
<div {...containerProps}>
|
|
529
|
+
<textarea {...textareaProps}></textarea>
|
|
530
|
+
</div>
|
|
531
|
+
);
|
|
532
|
+
},
|
|
533
|
+
};
|