@visactor/vue-vtable 1.25.1-alpha.0 → 1.26.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/cjs/components/component/menu.js +3 -3
- package/cjs/components/component/tooltip.js +3 -3
- package/cjs/components/custom/checkBox.js +3 -3
- package/cjs/components/custom/group.js +3 -3
- package/cjs/components/custom/image.js +3 -3
- package/cjs/components/custom/radio.js +3 -3
- package/cjs/components/custom/tag.js +3 -3
- package/cjs/components/custom/text.js +3 -3
- package/cjs/components/custom/vtable-vue-attribute-plugin.js +622 -408
- package/cjs/components/list/list-column.js +3 -3
- package/cjs/components/pivot/pivot-column-dimension.js +3 -3
- package/cjs/components/pivot/pivot-column-header-title.js +3 -3
- package/cjs/components/pivot/pivot-corner.js +3 -3
- package/cjs/components/pivot/pivot-indicator.js +3 -3
- package/cjs/components/pivot/pivot-row-dimension.js +3 -3
- package/cjs/components/pivot/pivot-row-header-title.js +3 -3
- package/cjs/constants.js +1 -0
- package/cjs/edit/editor.js +209 -194
- package/cjs/edit/util.js +51 -31
- package/cjs/eventsUtils.js +97 -60
- package/cjs/hooks/useCellRender.js +27 -20
- package/cjs/hooks/useEditorRender.js +75 -52
- package/cjs/index.js +5 -5
- package/cjs/tables/base-table.vue.js +266 -237
- package/cjs/tables/chartModule.js +2 -2
- package/cjs/tables/list-table.vue.js +41 -39
- package/cjs/tables/pivot-chart.vue.js +35 -37
- package/cjs/tables/pivot-table.vue.js +36 -38
- package/cjs/utils/customLayoutUtils.js +109 -96
- package/cjs/utils/slotUtils.js +85 -88
- package/cjs/utils/stringUtils.js +14 -12
- package/cjs/utils/vnodeUtils.js +3 -2
- package/dist/vue-vtable.js +1715 -1358
- package/dist/vue-vtable.min.js +1 -1
- package/es/components/component/menu.js +3 -3
- package/es/components/component/tooltip.js +3 -3
- package/es/components/custom/checkBox.js +3 -3
- package/es/components/custom/group.js +3 -3
- package/es/components/custom/image.js +3 -3
- package/es/components/custom/radio.js +3 -3
- package/es/components/custom/tag.js +3 -3
- package/es/components/custom/text.js +3 -3
- package/es/components/custom/vtable-vue-attribute-plugin.js +622 -408
- package/es/components/list/list-column.js +3 -3
- package/es/components/pivot/pivot-column-dimension.js +3 -3
- package/es/components/pivot/pivot-column-header-title.js +3 -3
- package/es/components/pivot/pivot-corner.js +3 -3
- package/es/components/pivot/pivot-indicator.js +3 -3
- package/es/components/pivot/pivot-row-dimension.js +3 -3
- package/es/components/pivot/pivot-row-header-title.js +3 -3
- package/es/constants.js +1 -0
- package/es/edit/editor.js +209 -194
- package/es/edit/util.js +51 -31
- package/es/eventsUtils.js +97 -60
- package/es/hooks/useCellRender.js +27 -20
- package/es/hooks/useEditorRender.js +75 -52
- package/es/index.js +3 -3
- package/es/tables/base-table.vue.js +266 -237
- package/es/tables/chartModule.js +2 -2
- package/es/tables/list-table.vue.js +41 -39
- package/es/tables/pivot-chart.vue.js +35 -37
- package/es/tables/pivot-table.vue.js +36 -38
- package/es/utils/customLayoutUtils.js +109 -96
- package/es/utils/slotUtils.js +85 -88
- package/es/utils/stringUtils.js +14 -12
- package/es/utils/vnodeUtils.js +3 -2
- package/package.json +5 -5
- package/cjs/components/component/menu.d.ts +0 -14
- package/cjs/components/component/tooltip.d.ts +0 -11
- package/cjs/components/custom/checkBox.d.ts +0 -20
- package/cjs/components/custom/custom-layout.d.ts +0 -20
- package/cjs/components/custom/group.d.ts +0 -6
- package/cjs/components/custom/image.d.ts +0 -6
- package/cjs/components/custom/radio.d.ts +0 -17
- package/cjs/components/custom/tag.d.ts +0 -16
- package/cjs/components/custom/text.d.ts +0 -6
- package/cjs/components/custom/vtable-vue-attribute-plugin.d.ts +0 -62
- package/cjs/components/index.d.ts +0 -15
- package/cjs/components/list/list-column.d.ts +0 -7
- package/cjs/components/pivot/pivot-column-dimension.d.ts +0 -11
- package/cjs/components/pivot/pivot-column-header-title.d.ts +0 -7
- package/cjs/components/pivot/pivot-corner.d.ts +0 -7
- package/cjs/components/pivot/pivot-indicator.d.ts +0 -7
- package/cjs/components/pivot/pivot-row-dimension.d.ts +0 -11
- package/cjs/components/pivot/pivot-row-header-title.d.ts +0 -7
- package/cjs/constants.d.ts +0 -1
- package/cjs/edit/editor.d.ts +0 -50
- package/cjs/edit/index.d.ts +0 -2
- package/cjs/edit/util.d.ts +0 -4
- package/cjs/eventsUtils.d.ts +0 -120
- package/cjs/hooks/index.d.ts +0 -2
- package/cjs/hooks/useCellRender.d.ts +0 -2
- package/cjs/hooks/useEditorRender.d.ts +0 -2
- package/cjs/index.d.ts +0 -6
- package/cjs/tables/base-table.vue.d.ts +0 -543
- package/cjs/tables/chartModule.d.ts +0 -1
- package/cjs/tables/index.d.ts +0 -5
- package/cjs/tables/list-table.vue.d.ts +0 -38
- package/cjs/tables/pivot-chart.vue.d.ts +0 -38
- package/cjs/tables/pivot-table.vue.d.ts +0 -38
- package/cjs/utils/customLayoutUtils.d.ts +0 -5
- package/cjs/utils/slotUtils.d.ts +0 -28
- package/cjs/utils/stringUtils.d.ts +0 -2
- package/cjs/utils/vnodeUtils.d.ts +0 -1
- package/cjs/utils.d.ts +0 -4
- package/es/components/component/menu.d.ts +0 -14
- package/es/components/component/tooltip.d.ts +0 -11
- package/es/components/custom/checkBox.d.ts +0 -20
- package/es/components/custom/custom-layout.d.ts +0 -20
- package/es/components/custom/group.d.ts +0 -6
- package/es/components/custom/image.d.ts +0 -6
- package/es/components/custom/radio.d.ts +0 -17
- package/es/components/custom/tag.d.ts +0 -16
- package/es/components/custom/text.d.ts +0 -6
- package/es/components/custom/vtable-vue-attribute-plugin.d.ts +0 -62
- package/es/components/index.d.ts +0 -15
- package/es/components/list/list-column.d.ts +0 -7
- package/es/components/pivot/pivot-column-dimension.d.ts +0 -11
- package/es/components/pivot/pivot-column-header-title.d.ts +0 -7
- package/es/components/pivot/pivot-corner.d.ts +0 -7
- package/es/components/pivot/pivot-indicator.d.ts +0 -7
- package/es/components/pivot/pivot-row-dimension.d.ts +0 -11
- package/es/components/pivot/pivot-row-header-title.d.ts +0 -7
- package/es/constants.d.ts +0 -1
- package/es/edit/editor.d.ts +0 -50
- package/es/edit/index.d.ts +0 -2
- package/es/edit/util.d.ts +0 -4
- package/es/eventsUtils.d.ts +0 -120
- package/es/hooks/index.d.ts +0 -2
- package/es/hooks/useCellRender.d.ts +0 -2
- package/es/hooks/useEditorRender.d.ts +0 -2
- package/es/index.d.ts +0 -6
- package/es/tables/base-table.vue.d.ts +0 -543
- package/es/tables/chartModule.d.ts +0 -1
- package/es/tables/index.d.ts +0 -5
- package/es/tables/list-table.vue.d.ts +0 -38
- package/es/tables/pivot-chart.vue.d.ts +0 -38
- package/es/tables/pivot-table.vue.d.ts +0 -38
- package/es/utils/customLayoutUtils.d.ts +0 -5
- package/es/utils/slotUtils.d.ts +0 -28
- package/es/utils/stringUtils.d.ts +0 -2
- package/es/utils/vnodeUtils.d.ts +0 -1
- package/es/utils.d.ts +0 -4
package/cjs/constants.js
CHANGED
package/cjs/edit/editor.js
CHANGED
|
@@ -1,203 +1,218 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var tslib = require('tslib');
|
|
4
3
|
var vutils = require('@visactor/vutils');
|
|
5
4
|
var vue = require('vue');
|
|
6
5
|
var VTable = require('@visactor/vtable');
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
this.nodeMap.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.nodeMap.
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @description: 自定义渲染式编辑器
|
|
9
|
+
*/
|
|
10
|
+
class DynamicRenderEditor {
|
|
11
|
+
constructor(currentContext) {
|
|
12
|
+
this.currentContext = currentContext;
|
|
13
|
+
this.tableContainer = null;
|
|
14
|
+
this.currentValue = null;
|
|
15
|
+
this.wrapContainer = null;
|
|
16
|
+
this.nodeMap = new Map();
|
|
17
|
+
}
|
|
18
|
+
registerNode(tableId, key, getNode) {
|
|
19
|
+
if (!vutils.isValid(tableId) || !vutils.isValid(key) || typeof getNode !== 'function') {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!this.nodeMap.has(tableId)) {
|
|
23
|
+
this.nodeMap.set(tableId, new Map());
|
|
24
|
+
}
|
|
25
|
+
this.nodeMap.get(tableId).set(key, getNode);
|
|
26
|
+
}
|
|
27
|
+
getNode(tableId, key) {
|
|
28
|
+
var _a;
|
|
29
|
+
return (_a = this.nodeMap.get(tableId)) === null || _a === void 0 ? void 0 : _a.get(key);
|
|
30
|
+
}
|
|
31
|
+
removeNode(tableId) {
|
|
32
|
+
this.nodeMap.delete(tableId);
|
|
33
|
+
}
|
|
34
|
+
release(tableId) {
|
|
35
|
+
if (!vutils.isValid(tableId)) {
|
|
36
|
+
this.nodeMap.clear();
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.removeNode(tableId);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async onStart(editorContext) {
|
|
43
|
+
const { value } = editorContext;
|
|
44
|
+
// 先设置初始值(因为校验不通过也会走正常流程)
|
|
45
|
+
this.setValue(value);
|
|
46
|
+
if (!(await this.createElement(editorContext))) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async createElement(editorContext) {
|
|
51
|
+
const { row, col, value, table, container, referencePosition } = editorContext;
|
|
52
|
+
if (!container) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const define = table.getBodyColumnDefine(col, row);
|
|
56
|
+
const { editConfig } = define || {};
|
|
57
|
+
const { id } = table;
|
|
58
|
+
const key = this.getColumnKeyField(define);
|
|
59
|
+
if (!vutils.isValid(key) || !vutils.isValid(id)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (typeof (editConfig === null || editConfig === void 0 ? void 0 : editConfig.editBefore) === 'function') {
|
|
63
|
+
// 编辑前校验
|
|
64
|
+
const v = await editConfig.editBefore(editorContext);
|
|
65
|
+
if (!v) {
|
|
66
|
+
table.showTooltip(col, row, {
|
|
67
|
+
// TODO 多语言
|
|
68
|
+
content: editConfig.disablePrompt || 'This field is not allowed to be edited',
|
|
69
|
+
referencePosition: { rect: referencePosition === null || referencePosition === void 0 ? void 0 : referencePosition.rect, placement: VTable.TYPES.Placement.top },
|
|
70
|
+
style: {
|
|
71
|
+
bgColor: 'black',
|
|
72
|
+
color: 'white',
|
|
73
|
+
arrowMark: true
|
|
74
|
+
},
|
|
75
|
+
disappearDelay: 1000
|
|
76
|
+
});
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const record = table === null || table === void 0 ? void 0 : table.getCellOriginRecord(col, row);
|
|
81
|
+
const renderVNodeFn = this.getNode(id, key);
|
|
82
|
+
if (!renderVNodeFn) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const vnode = vue.h(renderVNodeFn, {
|
|
86
|
+
row,
|
|
87
|
+
col,
|
|
88
|
+
value,
|
|
89
|
+
refValue: vue.customRef((track, trigger) => {
|
|
90
|
+
return {
|
|
91
|
+
get: () => {
|
|
92
|
+
track();
|
|
93
|
+
return this.getValue();
|
|
94
|
+
},
|
|
95
|
+
set: value => {
|
|
96
|
+
this.setValue(value);
|
|
97
|
+
trigger();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}),
|
|
101
|
+
record,
|
|
102
|
+
table,
|
|
103
|
+
onChange: (value) => this.setValue(value)
|
|
104
|
+
});
|
|
105
|
+
if (!vnode || !vue.isVNode(vnode)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
this.checkToPassAppContext(vnode, table);
|
|
109
|
+
// 创建包裹容器
|
|
110
|
+
const wrapContainer = document.createElement('div');
|
|
111
|
+
wrapContainer.style.position = 'absolute';
|
|
112
|
+
wrapContainer.style.width = '100%';
|
|
113
|
+
wrapContainer.style.boxSizing = 'border-box';
|
|
114
|
+
const { bgColor } = table.getCellStyle(col, row) || {};
|
|
115
|
+
wrapContainer.style.backgroundColor = bgColor || '#FFFFFF';
|
|
116
|
+
this.wrapContainer = wrapContainer;
|
|
117
|
+
this.tableContainer = container;
|
|
118
|
+
this.tableContainer.appendChild(wrapContainer);
|
|
119
|
+
vue.render(vnode, wrapContainer);
|
|
120
|
+
// 位置同步
|
|
121
|
+
if (referencePosition === null || referencePosition === void 0 ? void 0 : referencePosition.rect) {
|
|
122
|
+
this.adjustPosition(referencePosition.rect);
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* @description: 校验并传递上下文
|
|
128
|
+
* @param {VNode} vnode
|
|
129
|
+
* @param {any} table
|
|
130
|
+
* @return {*}
|
|
131
|
+
*/
|
|
132
|
+
checkToPassAppContext(vnode, table) {
|
|
133
|
+
var _a, _b, _c, _d;
|
|
134
|
+
try {
|
|
135
|
+
const userAppContext = (_d = (_c = (_b = (_a = table.options) === null || _a === void 0 ? void 0 : _a.customConfig) === null || _b === void 0 ? void 0 : _b.getVueUserAppContext) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : this.currentContext;
|
|
136
|
+
// 简单校验合法性
|
|
137
|
+
if (!!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.components) && !!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.directives)) {
|
|
138
|
+
vnode.appContext = userAppContext;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (error) { }
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @description: 获取渲染式编辑器的列配置主键
|
|
145
|
+
* @param {any} column
|
|
146
|
+
* @return {*}
|
|
147
|
+
*/
|
|
148
|
+
getColumnKeyField(column) {
|
|
149
|
+
const { field, key } = column || {};
|
|
150
|
+
// 兼容取 field
|
|
151
|
+
return vutils.isValid(key) ? key : field;
|
|
152
|
+
}
|
|
153
|
+
getValue() {
|
|
154
|
+
return this.currentValue;
|
|
155
|
+
}
|
|
156
|
+
setValue(value) {
|
|
157
|
+
this.currentValue = value;
|
|
158
|
+
}
|
|
159
|
+
adjustPosition(rect) {
|
|
160
|
+
if (this.wrapContainer) {
|
|
161
|
+
this.wrapContainer.style.top = `${rect.top}px`;
|
|
162
|
+
this.wrapContainer.style.left = `${rect.left}px`;
|
|
163
|
+
this.wrapContainer.style.width = `${rect.width}px`;
|
|
164
|
+
this.wrapContainer.style.height = `${rect.height}px`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async validateValue(value, oldValue, editCell, table) {
|
|
168
|
+
const { col, row } = editCell || {};
|
|
169
|
+
if (!vutils.isValid(col) || !vutils.isValid(row)) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
const define = table.getBodyColumnDefine(col, row);
|
|
173
|
+
const { editConfig } = define || {};
|
|
174
|
+
if (typeof (editConfig === null || editConfig === void 0 ? void 0 : editConfig.validateValue) === 'function') {
|
|
175
|
+
const validate = await editConfig.validateValue({ col, row, value, oldValue, table });
|
|
176
|
+
if (validate === false) {
|
|
177
|
+
const rect = table.getVisibleCellRangeRelativeRect({ col, row });
|
|
178
|
+
table.showTooltip(col, row, {
|
|
179
|
+
content: editConfig.invalidPrompt || 'invalid',
|
|
180
|
+
referencePosition: { rect, placement: VTable.TYPES.Placement.top },
|
|
181
|
+
style: {
|
|
182
|
+
bgColor: 'red',
|
|
183
|
+
color: 'white',
|
|
184
|
+
arrowMark: true
|
|
185
|
+
},
|
|
186
|
+
disappearDelay: 1000
|
|
187
|
+
});
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
return validate;
|
|
191
|
+
}
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
onEnd() {
|
|
195
|
+
if (this.wrapContainer && this.tableContainer) {
|
|
196
|
+
vue.render(null, this.wrapContainer);
|
|
197
|
+
this.tableContainer.removeChild(this.wrapContainer);
|
|
198
|
+
}
|
|
199
|
+
this.wrapContainer = null;
|
|
200
|
+
this.tableContainer = null;
|
|
201
|
+
}
|
|
202
|
+
isEditorElement(target) {
|
|
203
|
+
var _a;
|
|
204
|
+
return ((_a = this.wrapContainer) === null || _a === void 0 ? void 0 : _a.contains(target)) || this.isClickEditorElement(target);
|
|
205
|
+
}
|
|
206
|
+
isClickEditorElement(target) {
|
|
207
|
+
while (target) {
|
|
208
|
+
// 约定的类名
|
|
209
|
+
if (target.classList && target.classList.contains('table-editor-element')) {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
target = target.parentNode;
|
|
213
|
+
}
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
201
216
|
}
|
|
202
217
|
|
|
203
218
|
exports.DynamicRenderEditor = DynamicRenderEditor;
|
package/cjs/edit/util.js
CHANGED
|
@@ -5,37 +5,57 @@ var vutils = require('@visactor/vutils');
|
|
|
5
5
|
var editor = require('./editor.js');
|
|
6
6
|
var constants = require('../constants.js');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @description: 校验动态渲染式编辑器
|
|
10
|
+
* @param {any} column
|
|
11
|
+
* @param {any} getEditCustomNode
|
|
12
|
+
* @return {*}
|
|
13
|
+
*/
|
|
14
|
+
function checkRenderEditor(column, getEditCustomNode) {
|
|
15
|
+
const { editor } = column || {};
|
|
16
|
+
const key = getRenderEditorColumnKeyField(column);
|
|
17
|
+
if (!vutils.isValid(key) || editor !== constants.DYNAMIC_RENDER_EDITOR) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (typeof getEditCustomNode === 'function') {
|
|
21
|
+
column.getEditCustomNode = getEditCustomNode;
|
|
22
|
+
// 处理子列
|
|
23
|
+
if (Array.isArray(column.columns) && column.columns.length) {
|
|
24
|
+
for (const childColumn of column.columns) {
|
|
25
|
+
checkRenderEditor(childColumn, getEditCustomNode);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return typeof column.getEditCustomNode === 'function';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @description: 获取渲染式编辑器的列配置主键
|
|
34
|
+
* @param {any} column
|
|
35
|
+
* @return {*}
|
|
36
|
+
*/
|
|
37
|
+
function getRenderEditorColumnKeyField(column) {
|
|
38
|
+
const { field, key } = column || {};
|
|
39
|
+
// 兼容取 field
|
|
40
|
+
return vutils.isValid(key) ? key : field;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @description: 获取动态渲染式编辑器
|
|
44
|
+
* @param {boolean} create
|
|
45
|
+
* @param {any} currentContext
|
|
46
|
+
* @return {*}
|
|
47
|
+
*/
|
|
48
|
+
function getRenderEditor(create, currentContext) {
|
|
49
|
+
const registeredEditor = VTable.register.editor(constants.DYNAMIC_RENDER_EDITOR);
|
|
50
|
+
let renderEditor = registeredEditor
|
|
51
|
+
? registeredEditor
|
|
52
|
+
: undefined;
|
|
53
|
+
if (!renderEditor && !!create) {
|
|
54
|
+
// 注册自定义编辑器
|
|
55
|
+
renderEditor = new editor.DynamicRenderEditor(currentContext);
|
|
56
|
+
VTable.register.editor(constants.DYNAMIC_RENDER_EDITOR, renderEditor);
|
|
57
|
+
}
|
|
58
|
+
return renderEditor;
|
|
39
59
|
}
|
|
40
60
|
|
|
41
61
|
exports.checkRenderEditor = checkRenderEditor;
|