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.
Files changed (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/lib/button.js +1 -0
  4. package/lib/icon.js +1 -0
  5. package/lib/index.js +1 -0
  6. package/lib/locale/format.js +56 -0
  7. package/lib/locale/index.js +72 -0
  8. package/lib/locale/lang/en.js +123 -0
  9. package/lib/locale/lang/zh-CN.js +119 -0
  10. package/lib/mixins/locale.js +17 -0
  11. package/lib/theme-chalk/base.css +0 -0
  12. package/lib/theme-chalk/button.css +1 -0
  13. package/lib/theme-chalk/fonts/element-icons.ttf +0 -0
  14. package/lib/theme-chalk/fonts/element-icons.woff +0 -0
  15. package/lib/theme-chalk/fonts/iconfont.1785562768224.ttf +0 -0
  16. package/lib/theme-chalk/fonts/iconfont.1785562768224.woff +0 -0
  17. package/lib/theme-chalk/fonts/iconfont.1785562768224.woff2 +0 -0
  18. package/lib/theme-chalk/icon.css +1 -0
  19. package/lib/theme-chalk/index.css +1 -0
  20. package/lib/theme-chalk/u-table-column.css +0 -0
  21. package/lib/theme-chalk/u-table.css +1 -0
  22. package/lib/theme-chalk/ux-grid.css +1 -0
  23. package/lib/theme-chalk/ux-table-column.css +0 -0
  24. package/lib/u-table-column.js +1 -0
  25. package/lib/u-table.js +1 -0
  26. package/lib/umd/locale/en.js +139 -0
  27. package/lib/umd/locale/zh-CN.js +135 -0
  28. package/lib/umy-ui.common.js +1 -0
  29. package/lib/utils/svg.js +33 -0
  30. package/lib/utils/types.js +35 -0
  31. package/lib/utils/util.js +268 -0
  32. package/lib/ux-grid.js +1 -0
  33. package/lib/ux-table-column.js +1 -0
  34. package/package.json +117 -0
  35. package/packages/button/index.js +7 -0
  36. package/packages/button/src/button-group.vue +10 -0
  37. package/packages/button/src/button.vue +166 -0
  38. package/packages/checkbox/index.js +8 -0
  39. package/packages/checkbox/src/checkbox-button.vue +199 -0
  40. package/packages/checkbox/src/checkbox-group.vue +48 -0
  41. package/packages/checkbox/src/checkbox.vue +222 -0
  42. package/packages/checkbox-button/index.js +8 -0
  43. package/packages/checkbox-group/index.js +8 -0
  44. package/packages/icon/index.js +7 -0
  45. package/packages/icon/src/icon.vue +40 -0
  46. package/packages/input/index.js +2 -0
  47. package/packages/input/src/calcTextareaHeight.js +104 -0
  48. package/packages/input/src/input.vue +424 -0
  49. package/packages/option/index.js +2 -0
  50. package/packages/pagination/index.js +2 -0
  51. package/packages/pagination/src/pager.vue +163 -0
  52. package/packages/pagination/src/pagination.js +386 -0
  53. package/packages/scrollbar/index.js +8 -0
  54. package/packages/scrollbar/src/bar.js +92 -0
  55. package/packages/scrollbar/src/main.js +130 -0
  56. package/packages/scrollbar/src/util.js +34 -0
  57. package/packages/select/index.js +2 -0
  58. package/packages/select/src/navigation-mixin.js +54 -0
  59. package/packages/select/src/option-group.vue +60 -0
  60. package/packages/select/src/option.vue +163 -0
  61. package/packages/select/src/select-dropdown.vue +74 -0
  62. package/packages/select/src/select.vue +889 -0
  63. package/packages/table/index.js +8 -0
  64. package/packages/table/src/config.js +123 -0
  65. package/packages/table/src/dropdown.js +28 -0
  66. package/packages/table/src/filter-panel.vue +194 -0
  67. package/packages/table/src/layout-observer.js +68 -0
  68. package/packages/table/src/store/current.js +71 -0
  69. package/packages/table/src/store/expand.js +65 -0
  70. package/packages/table/src/store/helper.js +37 -0
  71. package/packages/table/src/store/index.js +145 -0
  72. package/packages/table/src/store/tree.js +208 -0
  73. package/packages/table/src/store/watcher.js +448 -0
  74. package/packages/table/src/table-body.js +493 -0
  75. package/packages/table/src/table-column.js +381 -0
  76. package/packages/table/src/table-footer.js +174 -0
  77. package/packages/table/src/table-header.js +537 -0
  78. package/packages/table/src/table-layout.js +231 -0
  79. package/packages/table/src/table.vue +741 -0
  80. package/packages/table/src/util.js +256 -0
  81. package/packages/tag/index.js +8 -0
  82. package/packages/tag/src/tag.vue +58 -0
  83. package/packages/tools/directives/mousewheel.js +18 -0
  84. package/packages/tools/directives/repeat-click.js +24 -0
  85. package/packages/tools/locale/format.js +46 -0
  86. package/packages/tools/locale/index.js +48 -0
  87. package/packages/tools/locale/lang/en.js +120 -0
  88. package/packages/tools/locale/lang/zh-CN.js +116 -0
  89. package/packages/tools/mixins/emitter.js +33 -0
  90. package/packages/tools/mixins/focus.js +9 -0
  91. package/packages/tools/mixins/locale.js +9 -0
  92. package/packages/tools/mixins/migrating.js +54 -0
  93. package/packages/tools/transitions/collapse-transition.js +77 -0
  94. package/packages/tools/utils/after-leave.js +27 -0
  95. package/packages/tools/utils/aria-dialog.js +90 -0
  96. package/packages/tools/utils/aria-utils.js +122 -0
  97. package/packages/tools/utils/clickoutside.js +76 -0
  98. package/packages/tools/utils/date-util.js +292 -0
  99. package/packages/tools/utils/date.js +368 -0
  100. package/packages/tools/utils/dom.js +227 -0
  101. package/packages/tools/utils/menu/aria-menubar.js +14 -0
  102. package/packages/tools/utils/menu/aria-menuitem.js +49 -0
  103. package/packages/tools/utils/menu/aria-submenu.js +59 -0
  104. package/packages/tools/utils/merge.js +15 -0
  105. package/packages/tools/utils/popper.js +1276 -0
  106. package/packages/tools/utils/popup/index.js +218 -0
  107. package/packages/tools/utils/popup/popup-manager.js +194 -0
  108. package/packages/tools/utils/resize-event.js +35 -0
  109. package/packages/tools/utils/scroll-into-view.js +27 -0
  110. package/packages/tools/utils/scrollbar-width.js +29 -0
  111. package/packages/tools/utils/shared.js +7 -0
  112. package/packages/tools/utils/svg.js +1 -0
  113. package/packages/tools/utils/types.js +28 -0
  114. package/packages/tools/utils/util.js +241 -0
  115. package/packages/tools/utils/vdom.js +5 -0
  116. package/packages/tools/utils/vue-popper.js +198 -0
  117. package/packages/tooltip/index.js +8 -0
  118. package/packages/tooltip/src/main.js +241 -0
  119. package/packages/u-table/index.js +4 -0
  120. package/packages/u-table/revise-el-table-mixins/index.js +10 -0
  121. package/packages/u-table/revise-el-table-mixins/table-extend.js +60 -0
  122. package/packages/u-table/revise-el-table-mixins/table.mixins.js +261 -0
  123. package/packages/u-table/revise-el-table-mixins/virtual-table-body-render.js +132 -0
  124. package/packages/u-table/src/u-table.vue +248 -0
  125. package/packages/u-table/u-table-mixins/index.js +483 -0
  126. package/packages/u-table/u-table-tree-mixins/methods.js +120 -0
  127. package/packages/u-table/u-table-tree-mixins/u-table-tree-mixins.js +161 -0
  128. package/packages/u-table-column/index.js +8 -0
  129. package/packages/utils/common.js +27 -0
  130. package/packages/ux-grid/index.js +6 -0
  131. package/packages/ux-grid/mixins/index.js +707 -0
  132. package/packages/ux-grid/src/interceptor.js +6 -0
  133. package/packages/ux-grid/src/ux-grid.vue +301 -0
  134. package/packages/ux-table-column/index.js +10 -0
  135. package/tools/locale/format.js +46 -0
  136. package/tools/locale/index.js +54 -0
  137. package/tools/locale/lang/en.js +120 -0
  138. package/tools/locale/lang/zh-CN.js +116 -0
  139. package/tools/mixins/locale.js +9 -0
  140. package/tools/utils/svg.js +1 -0
  141. package/tools/utils/types.js +28 -0
  142. package/tools/utils/util.js +241 -0
@@ -0,0 +1,145 @@
1
+ import Vue from 'vue';
2
+ import Watcher from './watcher';
3
+ import { arrayFind } from '../../../tools/utils/util';
4
+
5
+ Watcher.prototype.mutations = {
6
+ setData(states, data) {
7
+ const dataInstanceChanged = states._data !== data;
8
+ states._data = data;
9
+ this.execQuery();
10
+ // 数据变化,更新部分数据。
11
+ // 没有使用 computed,而是手动更新部分数据 https://github.com/vuejs/vue/issues/6660#issuecomment-331417140
12
+ this.updateCurrentRow();
13
+ this.updateExpandRows();
14
+ if (states.reserveSelection) {
15
+ this.assertRowKey();
16
+ this.updateSelectionByRowKey();
17
+ } else {
18
+ if (dataInstanceChanged) {
19
+ this.clearSelection();
20
+ } else {
21
+ this.cleanSelection();
22
+ }
23
+ }
24
+ this.updateAllSelected();
25
+
26
+ this.updateTableScrollY();
27
+ },
28
+
29
+ insertColumn(states, column, index, parent) {
30
+ let array = states._columns;
31
+ if (parent) {
32
+ array = parent.children;
33
+ if (!array) array = parent.children = [];
34
+ }
35
+
36
+ if (typeof index !== 'undefined') {
37
+ array.splice(index, 0, column);
38
+ } else {
39
+ array.push(column);
40
+ }
41
+
42
+ if (column.type === 'selection') {
43
+ states.selectable = column.selectable;
44
+ states.reserveSelection = column.reserveSelection;
45
+ }
46
+ if (this.table.$ready) {
47
+ this.updateColumns(); // hack for dynamics insert column
48
+ this.scheduleLayout();
49
+ }
50
+ },
51
+
52
+ removeColumn(states, column, parent) {
53
+ let array = states._columns;
54
+ if (parent) {
55
+ array = parent.children;
56
+ if (!array) array = parent.children = [];
57
+ }
58
+ if (array) {
59
+ array.splice(array.indexOf(column), 1);
60
+ }
61
+
62
+ if (this.table.$ready) {
63
+ this.updateColumns(); // hack for dynamics remove column
64
+ this.scheduleLayout();
65
+ }
66
+ },
67
+
68
+ sort(states, options) {
69
+ const { prop, order } = options;
70
+ if (prop) {
71
+ const column = arrayFind(states.columns, column => column.property === prop);
72
+ if (column) {
73
+ column.order = order;
74
+ this.updateSort(column, prop, order);
75
+ this.commit('changeSortCondition');
76
+ }
77
+ }
78
+ },
79
+
80
+ changeSortCondition(states, options) {
81
+ // 修复 pr https://github.com/ElemeFE/element/pull/15012 导致的 bug
82
+ const { sortingColumn: column, sortProp: prop, sortOrder: order } = states;
83
+ if (order === null) {
84
+ states.sortingColumn = null;
85
+ states.sortProp = null;
86
+ }
87
+ const ingore = { filter: true };
88
+ this.execQuery(ingore);
89
+
90
+ if (!options || !options.silent) {
91
+ this.table.$emit('sort-change', {
92
+ column,
93
+ prop,
94
+ order
95
+ });
96
+ }
97
+
98
+ this.updateTableScrollY();
99
+ },
100
+
101
+ filterChange(states, options) {
102
+ let { column, values, silent } = options;
103
+ const newFilters = this.updateFilters(column, values);
104
+
105
+ this.execQuery();
106
+
107
+ if (!silent) {
108
+ this.table.$emit('filter-change', newFilters);
109
+ }
110
+
111
+ this.updateTableScrollY();
112
+ },
113
+
114
+ toggleAllSelection() {
115
+ this.toggleAllSelection();
116
+ },
117
+
118
+ rowSelectedChanged(states, row) {
119
+ this.toggleRowSelection(row);
120
+ this.updateAllSelected();
121
+ },
122
+
123
+ setHoverRow(states, row) {
124
+ states.hoverRow = row;
125
+ },
126
+
127
+ setCurrentRow(states, row) {
128
+ this.updateCurrentRow(row);
129
+ }
130
+ };
131
+
132
+ Watcher.prototype.commit = function(name, ...args) {
133
+ const mutations = this.mutations;
134
+ if (mutations[name]) {
135
+ mutations[name].apply(this, [this.states].concat(args));
136
+ } else {
137
+ throw new Error(`Action not found: ${name}`);
138
+ }
139
+ };
140
+
141
+ Watcher.prototype.updateTableScrollY = function() {
142
+ Vue.nextTick(this.table.updateScrollY);
143
+ };
144
+
145
+ export default Watcher;
@@ -0,0 +1,208 @@
1
+ import { walkTreeNode, getRowIdentity } from "../util";
2
+
3
+ export default {
4
+ data() {
5
+ return {
6
+ states: {
7
+ // defaultExpandAll 存在于 expand.js 中,这里不重复添加
8
+ // TODO: 拆分为独立的 TreeTale,在 expand 中,展开行的记录是放在 expandRows 中,统一用法
9
+ expandRowKeys: [],
10
+ treeData: {},
11
+ indent: 16,
12
+ lazy: false,
13
+ lazyTreeNodeMap: {},
14
+ lazyColumnIdentifier: "hasChildren",
15
+ childrenColumnName: "children",
16
+ },
17
+ };
18
+ },
19
+
20
+ computed: {
21
+ // 嵌入型的数据,watch 无法是检测到变化 https://github.com/ElemeFE/element/issues/14998
22
+ // TODO: 使用 computed 解决该问题,是否会造成性能问题?
23
+ // @return { id: { level, children } }
24
+ normalizedData() {
25
+ if (!this.states.rowKey) return {};
26
+ const data = this.states.data || [];
27
+ return this.normalize(data);
28
+ },
29
+ // @return { id: { children } }
30
+ // 针对懒加载的情形,不处理嵌套数据
31
+ normalizedLazyNode() {
32
+ const { rowKey, lazyTreeNodeMap, lazyColumnIdentifier } = this.states;
33
+ const keys = Object.keys(lazyTreeNodeMap);
34
+ const res = {};
35
+ if (!keys.length) return res;
36
+ keys.forEach((key) => {
37
+ if (lazyTreeNodeMap[key].length) {
38
+ const item = { children: [] };
39
+ lazyTreeNodeMap[key].forEach((row) => {
40
+ const currentRowKey = getRowIdentity(row, rowKey);
41
+ item.children.push(currentRowKey);
42
+ if (row[lazyColumnIdentifier] && !res[currentRowKey]) {
43
+ res[currentRowKey] = { children: [] };
44
+ }
45
+ });
46
+ res[key] = item;
47
+ }
48
+ });
49
+ return res;
50
+ },
51
+ },
52
+
53
+ watch: {
54
+ normalizedData: "updateTreeData",
55
+ // expandRowKeys 在 TreeTable 中也有使用
56
+ expandRowKeys: "updateTreeData",
57
+ normalizedLazyNode: "updateTreeData",
58
+ },
59
+
60
+ methods: {
61
+ normalize(data) {
62
+ const { childrenColumnName, lazyColumnIdentifier, rowKey, lazy } =
63
+ this.states;
64
+ const res = {};
65
+ walkTreeNode(
66
+ data,
67
+ (parent, children, level) => {
68
+ const parentId = getRowIdentity(parent, rowKey);
69
+ if (Array.isArray(children)) {
70
+ res[parentId] = {
71
+ children: children.map((row) => getRowIdentity(row, rowKey)),
72
+ level,
73
+ };
74
+ } else if (lazy) {
75
+ // 当 children 不存在且 lazy 为 true,该节点即为懒加载的节点
76
+ res[parentId] = {
77
+ children: [],
78
+ lazy: true,
79
+ level,
80
+ };
81
+ }
82
+ },
83
+ childrenColumnName,
84
+ lazyColumnIdentifier
85
+ );
86
+ return res;
87
+ },
88
+
89
+ updateTreeData() {
90
+ const nested = this.normalizedData;
91
+ const normalizedLazyNode = this.normalizedLazyNode;
92
+ const keys = Object.keys(nested);
93
+ const newTreeData = {};
94
+ if (keys.length) {
95
+ const {
96
+ treeData: oldTreeData,
97
+ defaultExpandAll,
98
+ expandRowKeys,
99
+ lazy,
100
+ } = this.states;
101
+ const rootLazyRowKeys = [];
102
+ const getExpanded = (oldValue, key) => {
103
+ const included =
104
+ defaultExpandAll ||
105
+ (expandRowKeys && expandRowKeys.indexOf(key) !== -1);
106
+ return !!((oldValue && oldValue.expanded) || included);
107
+ };
108
+ // 合并 expanded 与 display,确保数据刷新后,状态不变
109
+ keys.forEach((key) => {
110
+ const oldValue = oldTreeData[key];
111
+ const newValue = { ...nested[key] };
112
+ newValue.expanded = getExpanded(oldValue, key);
113
+ if (newValue.lazy) {
114
+ const { loaded = false, loading = false } = oldValue || {};
115
+ newValue.loaded = !!loaded;
116
+ newValue.loading = !!loading;
117
+ rootLazyRowKeys.push(key);
118
+ }
119
+ newTreeData[key] = newValue;
120
+ });
121
+ // 根据懒加载数据更新 treeData
122
+ const lazyKeys = Object.keys(normalizedLazyNode);
123
+ if (lazy && lazyKeys.length && rootLazyRowKeys.length) {
124
+ lazyKeys.forEach((key) => {
125
+ const oldValue = oldTreeData[key];
126
+ const lazyNodeChildren = normalizedLazyNode[key].children;
127
+ if (rootLazyRowKeys.indexOf(key) !== -1) {
128
+ // 懒加载的 root 节点,更新一下原有的数据,原来的 children 一定是空数组
129
+ if (newTreeData[key].children.length !== 0) {
130
+ throw new Error("[ElTable]children must be an empty array.");
131
+ }
132
+ newTreeData[key].children = lazyNodeChildren;
133
+ } else {
134
+ const { loaded = false, loading = false } = oldValue || {};
135
+ newTreeData[key] = {
136
+ lazy: true,
137
+ loaded: !!loaded,
138
+ loading: !!loading,
139
+ expanded: getExpanded(oldValue, key),
140
+ children: lazyNodeChildren,
141
+ level: "",
142
+ };
143
+ }
144
+ });
145
+ }
146
+ }
147
+ this.states.treeData = newTreeData;
148
+ this.updateTableScrollY();
149
+ },
150
+
151
+ updateTreeExpandKeys(value) {
152
+ // 仅仅在包含嵌套数据时才去更新
153
+ if (Object.keys(this.normalizedData).length) {
154
+ this.states.expandRowKeys = value;
155
+ this.updateTreeData();
156
+ }
157
+ },
158
+
159
+ toggleTreeExpansion(row, expanded) {
160
+ this.assertRowKey();
161
+
162
+ const { rowKey, treeData } = this.states;
163
+ const id = getRowIdentity(row, rowKey);
164
+ const data = id && treeData[id];
165
+ const oldExpanded = treeData[id].expanded;
166
+ if (id && data && "expanded" in data) {
167
+ expanded = typeof expanded === "undefined" ? !data.expanded : expanded;
168
+ treeData[id].expanded = expanded;
169
+ if (oldExpanded !== expanded) {
170
+ this.table.$emit("expand-change", row, expanded);
171
+ }
172
+ this.updateTableScrollY();
173
+ }
174
+ },
175
+
176
+ loadOrToggle(row) {
177
+ this.assertRowKey();
178
+ const { lazy, treeData, rowKey } = this.states;
179
+ const id = getRowIdentity(row, rowKey);
180
+ const data = treeData[id];
181
+ if (lazy && data && "loaded" in data && !data.loaded) {
182
+ this.loadData(row, id, data);
183
+ } else {
184
+ this.toggleTreeExpansion(row);
185
+ }
186
+ },
187
+
188
+ loadData(row, key, treeNode) {
189
+ const { load } = this.table;
190
+ const { lazyTreeNodeMap, treeData } = this.states;
191
+ if (load && !treeData[key].loaded) {
192
+ treeData[key].loading = true;
193
+ load(row, treeNode, (data) => {
194
+ if (!Array.isArray(data)) {
195
+ throw new Error("[ElTable] data must be an array");
196
+ }
197
+ treeData[key].loading = false;
198
+ treeData[key].loaded = true;
199
+ treeData[key].expanded = true;
200
+ if (data.length) {
201
+ this.$set(lazyTreeNodeMap, key, data);
202
+ }
203
+ this.table.$emit("expand-change", row, true);
204
+ });
205
+ }
206
+ },
207
+ },
208
+ };