umy-ui-table 1.2.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/LICENSE +21 -0
- package/README.md +111 -0
- package/lib/button.js +1 -0
- package/lib/icon.js +1 -0
- package/lib/index.js +1 -0
- package/lib/locale/format.js +56 -0
- package/lib/locale/index.js +72 -0
- package/lib/locale/lang/en.js +123 -0
- package/lib/locale/lang/zh-CN.js +119 -0
- package/lib/mixins/locale.js +17 -0
- package/lib/theme-chalk/base.css +0 -0
- package/lib/theme-chalk/button.css +1 -0
- package/lib/theme-chalk/fonts/element-icons.ttf +0 -0
- package/lib/theme-chalk/fonts/element-icons.woff +0 -0
- package/lib/theme-chalk/fonts/iconfont.1785562768224.ttf +0 -0
- package/lib/theme-chalk/fonts/iconfont.1785562768224.woff +0 -0
- package/lib/theme-chalk/fonts/iconfont.1785562768224.woff2 +0 -0
- package/lib/theme-chalk/icon.css +1 -0
- package/lib/theme-chalk/index.css +1 -0
- package/lib/theme-chalk/u-table-column.css +0 -0
- package/lib/theme-chalk/u-table.css +1 -0
- package/lib/theme-chalk/ux-grid.css +1 -0
- package/lib/theme-chalk/ux-table-column.css +0 -0
- package/lib/u-table-column.js +1 -0
- package/lib/u-table.js +1 -0
- package/lib/umd/locale/en.js +139 -0
- package/lib/umd/locale/zh-CN.js +135 -0
- package/lib/umy-ui.common.js +1 -0
- package/lib/utils/svg.js +33 -0
- package/lib/utils/types.js +35 -0
- package/lib/utils/util.js +268 -0
- package/lib/ux-grid.js +1 -0
- package/lib/ux-table-column.js +1 -0
- package/package.json +117 -0
- package/packages/button/index.js +7 -0
- package/packages/button/src/button-group.vue +10 -0
- package/packages/button/src/button.vue +166 -0
- package/packages/checkbox/index.js +8 -0
- package/packages/checkbox/src/checkbox-button.vue +199 -0
- package/packages/checkbox/src/checkbox-group.vue +48 -0
- package/packages/checkbox/src/checkbox.vue +222 -0
- package/packages/checkbox-button/index.js +8 -0
- package/packages/checkbox-group/index.js +8 -0
- package/packages/icon/index.js +7 -0
- package/packages/icon/src/icon.vue +40 -0
- package/packages/input/index.js +2 -0
- package/packages/input/src/calcTextareaHeight.js +104 -0
- package/packages/input/src/input.vue +424 -0
- package/packages/option/index.js +2 -0
- package/packages/pagination/index.js +2 -0
- package/packages/pagination/src/pager.vue +163 -0
- package/packages/pagination/src/pagination.js +386 -0
- package/packages/scrollbar/index.js +8 -0
- package/packages/scrollbar/src/bar.js +92 -0
- package/packages/scrollbar/src/main.js +130 -0
- package/packages/scrollbar/src/util.js +34 -0
- package/packages/select/index.js +2 -0
- package/packages/select/src/navigation-mixin.js +54 -0
- package/packages/select/src/option-group.vue +60 -0
- package/packages/select/src/option.vue +163 -0
- package/packages/select/src/select-dropdown.vue +74 -0
- package/packages/select/src/select.vue +889 -0
- package/packages/table/index.js +8 -0
- package/packages/table/src/config.js +123 -0
- package/packages/table/src/dropdown.js +28 -0
- package/packages/table/src/filter-panel.vue +194 -0
- package/packages/table/src/layout-observer.js +68 -0
- package/packages/table/src/store/current.js +71 -0
- package/packages/table/src/store/expand.js +65 -0
- package/packages/table/src/store/helper.js +37 -0
- package/packages/table/src/store/index.js +145 -0
- package/packages/table/src/store/tree.js +208 -0
- package/packages/table/src/store/watcher.js +448 -0
- package/packages/table/src/table-body.js +493 -0
- package/packages/table/src/table-column.js +381 -0
- package/packages/table/src/table-footer.js +174 -0
- package/packages/table/src/table-header.js +537 -0
- package/packages/table/src/table-layout.js +231 -0
- package/packages/table/src/table.vue +741 -0
- package/packages/table/src/util.js +256 -0
- package/packages/tag/index.js +8 -0
- package/packages/tag/src/tag.vue +58 -0
- package/packages/tools/directives/mousewheel.js +18 -0
- package/packages/tools/directives/repeat-click.js +24 -0
- package/packages/tools/locale/format.js +46 -0
- package/packages/tools/locale/index.js +48 -0
- package/packages/tools/locale/lang/en.js +120 -0
- package/packages/tools/locale/lang/zh-CN.js +116 -0
- package/packages/tools/mixins/emitter.js +33 -0
- package/packages/tools/mixins/focus.js +9 -0
- package/packages/tools/mixins/locale.js +9 -0
- package/packages/tools/mixins/migrating.js +54 -0
- package/packages/tools/transitions/collapse-transition.js +77 -0
- package/packages/tools/utils/after-leave.js +27 -0
- package/packages/tools/utils/aria-dialog.js +90 -0
- package/packages/tools/utils/aria-utils.js +122 -0
- package/packages/tools/utils/clickoutside.js +76 -0
- package/packages/tools/utils/date-util.js +292 -0
- package/packages/tools/utils/date.js +368 -0
- package/packages/tools/utils/dom.js +227 -0
- package/packages/tools/utils/menu/aria-menubar.js +14 -0
- package/packages/tools/utils/menu/aria-menuitem.js +49 -0
- package/packages/tools/utils/menu/aria-submenu.js +59 -0
- package/packages/tools/utils/merge.js +15 -0
- package/packages/tools/utils/popper.js +1276 -0
- package/packages/tools/utils/popup/index.js +218 -0
- package/packages/tools/utils/popup/popup-manager.js +194 -0
- package/packages/tools/utils/resize-event.js +35 -0
- package/packages/tools/utils/scroll-into-view.js +27 -0
- package/packages/tools/utils/scrollbar-width.js +29 -0
- package/packages/tools/utils/shared.js +7 -0
- package/packages/tools/utils/svg.js +1 -0
- package/packages/tools/utils/types.js +28 -0
- package/packages/tools/utils/util.js +241 -0
- package/packages/tools/utils/vdom.js +5 -0
- package/packages/tools/utils/vue-popper.js +198 -0
- package/packages/tooltip/index.js +8 -0
- package/packages/tooltip/src/main.js +241 -0
- package/packages/u-table/index.js +4 -0
- package/packages/u-table/revise-el-table-mixins/index.js +10 -0
- package/packages/u-table/revise-el-table-mixins/table-extend.js +60 -0
- package/packages/u-table/revise-el-table-mixins/table.mixins.js +261 -0
- package/packages/u-table/revise-el-table-mixins/virtual-table-body-render.js +132 -0
- package/packages/u-table/src/u-table.vue +248 -0
- package/packages/u-table/u-table-mixins/index.js +483 -0
- package/packages/u-table/u-table-tree-mixins/methods.js +120 -0
- package/packages/u-table/u-table-tree-mixins/u-table-tree-mixins.js +161 -0
- package/packages/u-table-column/index.js +8 -0
- package/packages/utils/common.js +27 -0
- package/packages/ux-grid/index.js +6 -0
- package/packages/ux-grid/mixins/index.js +707 -0
- package/packages/ux-grid/src/interceptor.js +6 -0
- package/packages/ux-grid/src/ux-grid.vue +301 -0
- package/packages/ux-table-column/index.js +10 -0
- package/tools/locale/format.js +46 -0
- package/tools/locale/index.js +54 -0
- package/tools/locale/lang/en.js +120 -0
- package/tools/locale/lang/zh-CN.js +116 -0
- package/tools/mixins/locale.js +9 -0
- package/tools/utils/svg.js +1 -0
- package/tools/utils/types.js +28 -0
- package/tools/utils/util.js +241 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
import scrollbarWidth from '../../tools/utils/scrollbar-width';
|
|
3
|
+
import { parseHeight } from './util';
|
|
4
|
+
|
|
5
|
+
class TableLayout {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.observers = [];
|
|
8
|
+
this.table = null;
|
|
9
|
+
this.store = null;
|
|
10
|
+
this.columns = null;
|
|
11
|
+
this.fit = true;
|
|
12
|
+
this.showHeader = true;
|
|
13
|
+
|
|
14
|
+
this.height = null;
|
|
15
|
+
this.scrollX = false;
|
|
16
|
+
this.scrollY = false;
|
|
17
|
+
this.bodyWidth = null;
|
|
18
|
+
this.fixedWidth = null;
|
|
19
|
+
this.rightFixedWidth = null;
|
|
20
|
+
this.tableHeight = null;
|
|
21
|
+
this.headerHeight = 44; // Table Header Height
|
|
22
|
+
this.appendHeight = 0; // Append Slot Height
|
|
23
|
+
this.footerHeight = 44; // Table Footer Height
|
|
24
|
+
this.viewportHeight = null; // Table Height - Scroll Bar Height
|
|
25
|
+
this.bodyHeight = null; // Table Height - Table Header Height
|
|
26
|
+
this.fixedBodyHeight = null; // Table Height - Table Header Height - Scroll Bar Height
|
|
27
|
+
this.gutterWidth = scrollbarWidth();
|
|
28
|
+
|
|
29
|
+
for (let name in options) {
|
|
30
|
+
if (options.hasOwnProperty(name)) {
|
|
31
|
+
this[name] = options[name];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!this.table) {
|
|
36
|
+
throw new Error('table is required for Table Layout');
|
|
37
|
+
}
|
|
38
|
+
if (!this.store) {
|
|
39
|
+
throw new Error('store is required for Table Layout');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
updateScrollY() {
|
|
44
|
+
const height = this.height;
|
|
45
|
+
if (height === null) return false;
|
|
46
|
+
const bodyWrapper = this.table.bodyWrapper;
|
|
47
|
+
if (this.table.$el && bodyWrapper) {
|
|
48
|
+
const body = bodyWrapper.querySelector('.el-table__body');
|
|
49
|
+
const prevScrollY = this.scrollY;
|
|
50
|
+
const scrollY = body.offsetHeight > this.bodyHeight;
|
|
51
|
+
this.scrollY = scrollY;
|
|
52
|
+
return prevScrollY !== scrollY;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
setHeight(value, prop = 'height') {
|
|
58
|
+
if (Vue.prototype.$isServer) return;
|
|
59
|
+
const el = this.table.$el;
|
|
60
|
+
value = parseHeight(value);
|
|
61
|
+
this.height = value;
|
|
62
|
+
|
|
63
|
+
if (!el && (value || value === 0)) return Vue.nextTick(() => this.setHeight(value, prop));
|
|
64
|
+
|
|
65
|
+
if (typeof value === 'number') {
|
|
66
|
+
el.style[prop] = value + 'px';
|
|
67
|
+
this.updateElsHeight();
|
|
68
|
+
} else if (typeof value === 'string') {
|
|
69
|
+
el.style[prop] = value;
|
|
70
|
+
this.updateElsHeight();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
setMaxHeight(value) {
|
|
75
|
+
this.setHeight(value, 'max-height');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getFlattenColumns() {
|
|
79
|
+
const flattenColumns = [];
|
|
80
|
+
const columns = this.table.columns;
|
|
81
|
+
columns.forEach((column) => {
|
|
82
|
+
if (column.isColumnGroup) {
|
|
83
|
+
flattenColumns.push.apply(flattenColumns, column.columns);
|
|
84
|
+
} else {
|
|
85
|
+
flattenColumns.push(column);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return flattenColumns;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
updateElsHeight() {
|
|
93
|
+
if (!this.table.$ready) return Vue.nextTick(() => this.updateElsHeight());
|
|
94
|
+
const { headerWrapper, appendWrapper, footerWrapper } = this.table.$refs;
|
|
95
|
+
this.appendHeight = appendWrapper ? appendWrapper.offsetHeight : 0;
|
|
96
|
+
if (this.showHeader && !headerWrapper) return;
|
|
97
|
+
const headerHeight = this.headerHeight = !this.showHeader ? 0 : headerWrapper.offsetHeight;
|
|
98
|
+
if (this.showHeader && headerWrapper.offsetWidth > 0 && (this.table.columns || []).length > 0 && headerHeight < 2) {
|
|
99
|
+
return Vue.nextTick(() => this.updateElsHeight());
|
|
100
|
+
}
|
|
101
|
+
const tableHeight = this.tableHeight = this.table.$el.clientHeight;
|
|
102
|
+
const footerHeight = this.footerHeight = footerWrapper ? footerWrapper.offsetHeight : 0;
|
|
103
|
+
if (this.height !== null) {
|
|
104
|
+
this.bodyHeight = tableHeight - headerHeight - footerHeight + (footerWrapper ? 1 : 0);
|
|
105
|
+
}
|
|
106
|
+
this.fixedBodyHeight = this.scrollX ? (this.bodyHeight - this.gutterWidth) : this.bodyHeight;
|
|
107
|
+
|
|
108
|
+
const noData = !this.table.data || this.table.data.length === 0;
|
|
109
|
+
this.viewportHeight = this.scrollX ? tableHeight - (noData ? 0 : this.gutterWidth) : tableHeight;
|
|
110
|
+
this.updateScrollY();
|
|
111
|
+
this.notifyObservers('scrollable');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
updateColumnsWidth() {
|
|
115
|
+
if (Vue.prototype.$isServer) return;
|
|
116
|
+
const fit = this.fit;
|
|
117
|
+
const bodyWidth = this.table.$el.clientWidth;
|
|
118
|
+
let bodyMinWidth = 0;
|
|
119
|
+
|
|
120
|
+
const flattenColumns = this.getFlattenColumns();
|
|
121
|
+
let flexColumns = flattenColumns.filter((column) => typeof column.width !== 'number');
|
|
122
|
+
|
|
123
|
+
flattenColumns.forEach((column) => { // Clean those columns whose width changed from flex to unflex
|
|
124
|
+
if (typeof column.width === 'number' && column.realWidth) column.realWidth = null;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (flexColumns.length > 0 && fit) {
|
|
128
|
+
flattenColumns.forEach((column) => {
|
|
129
|
+
bodyMinWidth += column.width || column.minWidth || 80;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const scrollYWidth = this.scrollY ? this.gutterWidth : 0;
|
|
133
|
+
|
|
134
|
+
if (bodyMinWidth <= bodyWidth - scrollYWidth) { // DON'T HAVE SCROLL BAR
|
|
135
|
+
this.scrollX = false;
|
|
136
|
+
|
|
137
|
+
const totalFlexWidth = bodyWidth - scrollYWidth - bodyMinWidth;
|
|
138
|
+
|
|
139
|
+
if (flexColumns.length === 1) {
|
|
140
|
+
flexColumns[0].realWidth = (flexColumns[0].minWidth || 80) + totalFlexWidth;
|
|
141
|
+
} else {
|
|
142
|
+
const allColumnsWidth = flexColumns.reduce((prev, column) => prev + (column.minWidth || 80), 0);
|
|
143
|
+
const flexWidthPerPixel = totalFlexWidth / allColumnsWidth;
|
|
144
|
+
let noneFirstWidth = 0;
|
|
145
|
+
|
|
146
|
+
flexColumns.forEach((column, index) => {
|
|
147
|
+
if (index === 0) return;
|
|
148
|
+
const flexWidth = Math.floor((column.minWidth || 80) * flexWidthPerPixel);
|
|
149
|
+
noneFirstWidth += flexWidth;
|
|
150
|
+
column.realWidth = (column.minWidth || 80) + flexWidth;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
flexColumns[0].realWidth = (flexColumns[0].minWidth || 80) + totalFlexWidth - noneFirstWidth;
|
|
154
|
+
}
|
|
155
|
+
} else { // HAVE HORIZONTAL SCROLL BAR
|
|
156
|
+
this.scrollX = true;
|
|
157
|
+
flexColumns.forEach(function(column) {
|
|
158
|
+
column.realWidth = column.minWidth;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
this.bodyWidth = Math.max(bodyMinWidth, bodyWidth);
|
|
163
|
+
this.table.resizeState.width = this.bodyWidth;
|
|
164
|
+
} else {
|
|
165
|
+
flattenColumns.forEach((column) => {
|
|
166
|
+
if (!column.width && !column.minWidth) {
|
|
167
|
+
column.realWidth = 80;
|
|
168
|
+
} else {
|
|
169
|
+
column.realWidth = column.width || column.minWidth;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
bodyMinWidth += column.realWidth;
|
|
173
|
+
});
|
|
174
|
+
this.scrollX = bodyMinWidth > bodyWidth;
|
|
175
|
+
|
|
176
|
+
this.bodyWidth = bodyMinWidth;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const fixedColumns = this.store.states.fixedColumns;
|
|
180
|
+
|
|
181
|
+
if (fixedColumns.length > 0) {
|
|
182
|
+
let fixedWidth = 0;
|
|
183
|
+
fixedColumns.forEach(function(column) {
|
|
184
|
+
fixedWidth += column.realWidth || column.width;
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
this.fixedWidth = fixedWidth;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const rightFixedColumns = this.store.states.rightFixedColumns;
|
|
191
|
+
if (rightFixedColumns.length > 0) {
|
|
192
|
+
let rightFixedWidth = 0;
|
|
193
|
+
rightFixedColumns.forEach(function(column) {
|
|
194
|
+
rightFixedWidth += column.realWidth || column.width;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
this.rightFixedWidth = rightFixedWidth;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
this.notifyObservers('columns');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
addObserver(observer) {
|
|
204
|
+
this.observers.push(observer);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
removeObserver(observer) {
|
|
208
|
+
const index = this.observers.indexOf(observer);
|
|
209
|
+
if (index !== -1) {
|
|
210
|
+
this.observers.splice(index, 1);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
notifyObservers(event) {
|
|
215
|
+
const observers = this.observers;
|
|
216
|
+
observers.forEach((observer) => {
|
|
217
|
+
switch (event) {
|
|
218
|
+
case 'columns':
|
|
219
|
+
observer.onColumnsChange(this);
|
|
220
|
+
break;
|
|
221
|
+
case 'scrollable':
|
|
222
|
+
observer.onScrollableChange(this);
|
|
223
|
+
break;
|
|
224
|
+
default:
|
|
225
|
+
throw new Error(`Table Layout don't have event ${event}.`);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export default TableLayout;
|