@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.
Files changed (143) hide show
  1. package/cjs/components/component/menu.js +3 -3
  2. package/cjs/components/component/tooltip.js +3 -3
  3. package/cjs/components/custom/checkBox.js +3 -3
  4. package/cjs/components/custom/group.js +3 -3
  5. package/cjs/components/custom/image.js +3 -3
  6. package/cjs/components/custom/radio.js +3 -3
  7. package/cjs/components/custom/tag.js +3 -3
  8. package/cjs/components/custom/text.js +3 -3
  9. package/cjs/components/custom/vtable-vue-attribute-plugin.js +622 -408
  10. package/cjs/components/list/list-column.js +3 -3
  11. package/cjs/components/pivot/pivot-column-dimension.js +3 -3
  12. package/cjs/components/pivot/pivot-column-header-title.js +3 -3
  13. package/cjs/components/pivot/pivot-corner.js +3 -3
  14. package/cjs/components/pivot/pivot-indicator.js +3 -3
  15. package/cjs/components/pivot/pivot-row-dimension.js +3 -3
  16. package/cjs/components/pivot/pivot-row-header-title.js +3 -3
  17. package/cjs/constants.js +1 -0
  18. package/cjs/edit/editor.js +209 -194
  19. package/cjs/edit/util.js +51 -31
  20. package/cjs/eventsUtils.js +97 -60
  21. package/cjs/hooks/useCellRender.js +27 -20
  22. package/cjs/hooks/useEditorRender.js +75 -52
  23. package/cjs/index.js +5 -5
  24. package/cjs/tables/base-table.vue.js +266 -237
  25. package/cjs/tables/chartModule.js +2 -2
  26. package/cjs/tables/list-table.vue.js +41 -39
  27. package/cjs/tables/pivot-chart.vue.js +35 -37
  28. package/cjs/tables/pivot-table.vue.js +36 -38
  29. package/cjs/utils/customLayoutUtils.js +109 -96
  30. package/cjs/utils/slotUtils.js +85 -88
  31. package/cjs/utils/stringUtils.js +14 -12
  32. package/cjs/utils/vnodeUtils.js +3 -2
  33. package/dist/vue-vtable.js +1715 -1358
  34. package/dist/vue-vtable.min.js +1 -1
  35. package/es/components/component/menu.js +3 -3
  36. package/es/components/component/tooltip.js +3 -3
  37. package/es/components/custom/checkBox.js +3 -3
  38. package/es/components/custom/group.js +3 -3
  39. package/es/components/custom/image.js +3 -3
  40. package/es/components/custom/radio.js +3 -3
  41. package/es/components/custom/tag.js +3 -3
  42. package/es/components/custom/text.js +3 -3
  43. package/es/components/custom/vtable-vue-attribute-plugin.js +622 -408
  44. package/es/components/list/list-column.js +3 -3
  45. package/es/components/pivot/pivot-column-dimension.js +3 -3
  46. package/es/components/pivot/pivot-column-header-title.js +3 -3
  47. package/es/components/pivot/pivot-corner.js +3 -3
  48. package/es/components/pivot/pivot-indicator.js +3 -3
  49. package/es/components/pivot/pivot-row-dimension.js +3 -3
  50. package/es/components/pivot/pivot-row-header-title.js +3 -3
  51. package/es/constants.js +1 -0
  52. package/es/edit/editor.js +209 -194
  53. package/es/edit/util.js +51 -31
  54. package/es/eventsUtils.js +97 -60
  55. package/es/hooks/useCellRender.js +27 -20
  56. package/es/hooks/useEditorRender.js +75 -52
  57. package/es/index.js +3 -3
  58. package/es/tables/base-table.vue.js +266 -237
  59. package/es/tables/chartModule.js +2 -2
  60. package/es/tables/list-table.vue.js +41 -39
  61. package/es/tables/pivot-chart.vue.js +35 -37
  62. package/es/tables/pivot-table.vue.js +36 -38
  63. package/es/utils/customLayoutUtils.js +109 -96
  64. package/es/utils/slotUtils.js +85 -88
  65. package/es/utils/stringUtils.js +14 -12
  66. package/es/utils/vnodeUtils.js +3 -2
  67. package/package.json +5 -5
  68. package/cjs/components/component/menu.d.ts +0 -14
  69. package/cjs/components/component/tooltip.d.ts +0 -11
  70. package/cjs/components/custom/checkBox.d.ts +0 -20
  71. package/cjs/components/custom/custom-layout.d.ts +0 -20
  72. package/cjs/components/custom/group.d.ts +0 -6
  73. package/cjs/components/custom/image.d.ts +0 -6
  74. package/cjs/components/custom/radio.d.ts +0 -17
  75. package/cjs/components/custom/tag.d.ts +0 -16
  76. package/cjs/components/custom/text.d.ts +0 -6
  77. package/cjs/components/custom/vtable-vue-attribute-plugin.d.ts +0 -62
  78. package/cjs/components/index.d.ts +0 -15
  79. package/cjs/components/list/list-column.d.ts +0 -7
  80. package/cjs/components/pivot/pivot-column-dimension.d.ts +0 -11
  81. package/cjs/components/pivot/pivot-column-header-title.d.ts +0 -7
  82. package/cjs/components/pivot/pivot-corner.d.ts +0 -7
  83. package/cjs/components/pivot/pivot-indicator.d.ts +0 -7
  84. package/cjs/components/pivot/pivot-row-dimension.d.ts +0 -11
  85. package/cjs/components/pivot/pivot-row-header-title.d.ts +0 -7
  86. package/cjs/constants.d.ts +0 -1
  87. package/cjs/edit/editor.d.ts +0 -50
  88. package/cjs/edit/index.d.ts +0 -2
  89. package/cjs/edit/util.d.ts +0 -4
  90. package/cjs/eventsUtils.d.ts +0 -120
  91. package/cjs/hooks/index.d.ts +0 -2
  92. package/cjs/hooks/useCellRender.d.ts +0 -2
  93. package/cjs/hooks/useEditorRender.d.ts +0 -2
  94. package/cjs/index.d.ts +0 -6
  95. package/cjs/tables/base-table.vue.d.ts +0 -543
  96. package/cjs/tables/chartModule.d.ts +0 -1
  97. package/cjs/tables/index.d.ts +0 -5
  98. package/cjs/tables/list-table.vue.d.ts +0 -38
  99. package/cjs/tables/pivot-chart.vue.d.ts +0 -38
  100. package/cjs/tables/pivot-table.vue.d.ts +0 -38
  101. package/cjs/utils/customLayoutUtils.d.ts +0 -5
  102. package/cjs/utils/slotUtils.d.ts +0 -28
  103. package/cjs/utils/stringUtils.d.ts +0 -2
  104. package/cjs/utils/vnodeUtils.d.ts +0 -1
  105. package/cjs/utils.d.ts +0 -4
  106. package/es/components/component/menu.d.ts +0 -14
  107. package/es/components/component/tooltip.d.ts +0 -11
  108. package/es/components/custom/checkBox.d.ts +0 -20
  109. package/es/components/custom/custom-layout.d.ts +0 -20
  110. package/es/components/custom/group.d.ts +0 -6
  111. package/es/components/custom/image.d.ts +0 -6
  112. package/es/components/custom/radio.d.ts +0 -17
  113. package/es/components/custom/tag.d.ts +0 -16
  114. package/es/components/custom/text.d.ts +0 -6
  115. package/es/components/custom/vtable-vue-attribute-plugin.d.ts +0 -62
  116. package/es/components/index.d.ts +0 -15
  117. package/es/components/list/list-column.d.ts +0 -7
  118. package/es/components/pivot/pivot-column-dimension.d.ts +0 -11
  119. package/es/components/pivot/pivot-column-header-title.d.ts +0 -7
  120. package/es/components/pivot/pivot-corner.d.ts +0 -7
  121. package/es/components/pivot/pivot-indicator.d.ts +0 -7
  122. package/es/components/pivot/pivot-row-dimension.d.ts +0 -11
  123. package/es/components/pivot/pivot-row-header-title.d.ts +0 -7
  124. package/es/constants.d.ts +0 -1
  125. package/es/edit/editor.d.ts +0 -50
  126. package/es/edit/index.d.ts +0 -2
  127. package/es/edit/util.d.ts +0 -4
  128. package/es/eventsUtils.d.ts +0 -120
  129. package/es/hooks/index.d.ts +0 -2
  130. package/es/hooks/useCellRender.d.ts +0 -2
  131. package/es/hooks/useEditorRender.d.ts +0 -2
  132. package/es/index.d.ts +0 -6
  133. package/es/tables/base-table.vue.d.ts +0 -543
  134. package/es/tables/chartModule.d.ts +0 -1
  135. package/es/tables/index.d.ts +0 -5
  136. package/es/tables/list-table.vue.d.ts +0 -38
  137. package/es/tables/pivot-chart.vue.d.ts +0 -38
  138. package/es/tables/pivot-table.vue.d.ts +0 -38
  139. package/es/utils/customLayoutUtils.d.ts +0 -5
  140. package/es/utils/slotUtils.d.ts +0 -28
  141. package/es/utils/stringUtils.d.ts +0 -2
  142. package/es/utils/vnodeUtils.d.ts +0 -1
  143. package/es/utils.d.ts +0 -4
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- function ListColumn(props) {
4
- return null;
5
- }
3
+ function ListColumn(props) {
4
+ return null;
5
+ }
6
6
  ListColumn.symbol = 'ListColumn';
7
7
 
8
8
  module.exports = ListColumn;
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- function PivotColumnDimension(props) {
4
- return null;
5
- }
3
+ function PivotColumnDimension(props) {
4
+ return null;
5
+ }
6
6
  PivotColumnDimension.symbol = 'PivotColumnDimension';
7
7
 
8
8
  module.exports = PivotColumnDimension;
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- function PivotColumnHeaderTitle(props) {
4
- return null;
5
- }
3
+ function PivotColumnHeaderTitle(props) {
4
+ return null;
5
+ }
6
6
  PivotColumnHeaderTitle.symbol = 'PivotColumnHeaderTitle';
7
7
 
8
8
  module.exports = PivotColumnHeaderTitle;
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- function PivotCorner(props) {
4
- return null;
5
- }
3
+ function PivotCorner(props) {
4
+ return null;
5
+ }
6
6
  PivotCorner.symbol = 'PivotCorner';
7
7
 
8
8
  module.exports = PivotCorner;
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- function PivotIndicator(props) {
4
- return null;
5
- }
3
+ function PivotIndicator(props) {
4
+ return null;
5
+ }
6
6
  PivotIndicator.symbol = 'PivotIndicator';
7
7
 
8
8
  module.exports = PivotIndicator;
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- function PivotRowDimension(props) {
4
- return null;
5
- }
3
+ function PivotRowDimension(props) {
4
+ return null;
5
+ }
6
6
  PivotRowDimension.symbol = 'PivotRowDimension';
7
7
 
8
8
  module.exports = PivotRowDimension;
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- function PivotRowHeaderTitle(props) {
4
- return null;
5
- }
3
+ function PivotRowHeaderTitle(props) {
4
+ return null;
5
+ }
6
6
  PivotRowHeaderTitle.symbol = 'PivotRowHeaderTitle';
7
7
 
8
8
  module.exports = PivotRowHeaderTitle;
package/cjs/constants.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ /** 动态渲染编辑器名称 */
3
4
  const DYNAMIC_RENDER_EDITOR = 'dynamic-render-editor';
4
5
 
5
6
  exports.DYNAMIC_RENDER_EDITOR = DYNAMIC_RENDER_EDITOR;
@@ -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
- class DynamicRenderEditor {
9
- constructor(currentContext) {
10
- this.currentContext = currentContext;
11
- this.tableContainer = null;
12
- this.currentValue = null;
13
- this.wrapContainer = null;
14
- this.nodeMap = new Map();
15
- }
16
- registerNode(tableId, key, getNode) {
17
- if (!vutils.isValid(tableId) || !vutils.isValid(key) || typeof getNode !== 'function') {
18
- return;
19
- }
20
- if (!this.nodeMap.has(tableId)) {
21
- this.nodeMap.set(tableId, new Map());
22
- }
23
- this.nodeMap.get(tableId).set(key, getNode);
24
- }
25
- getNode(tableId, key) {
26
- var _a;
27
- return (_a = this.nodeMap.get(tableId)) === null || _a === void 0 ? void 0 : _a.get(key);
28
- }
29
- removeNode(tableId) {
30
- this.nodeMap.delete(tableId);
31
- }
32
- release(tableId) {
33
- if (!vutils.isValid(tableId)) {
34
- this.nodeMap.clear();
35
- }
36
- else {
37
- this.removeNode(tableId);
38
- }
39
- }
40
- onStart(editorContext) {
41
- return tslib.__awaiter(this, void 0, void 0, function* () {
42
- const { value } = editorContext;
43
- this.setValue(value);
44
- if (!(yield this.createElement(editorContext))) {
45
- return;
46
- }
47
- });
48
- }
49
- createElement(editorContext) {
50
- return tslib.__awaiter(this, void 0, void 0, function* () {
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
- const v = yield editConfig.editBefore(editorContext);
64
- if (!v) {
65
- table.showTooltip(col, row, {
66
- content: editConfig.disablePrompt || 'This field is not allowed to be edited',
67
- referencePosition: { rect: referencePosition === null || referencePosition === void 0 ? void 0 : referencePosition.rect, placement: VTable.TYPES.Placement.top },
68
- style: {
69
- bgColor: 'black',
70
- color: 'white',
71
- arrowMark: true
72
- },
73
- disappearDelay: 1000
74
- });
75
- return false;
76
- }
77
- }
78
- const record = table === null || table === void 0 ? void 0 : table.getCellOriginRecord(col, row);
79
- const renderVNodeFn = this.getNode(id, key);
80
- if (!renderVNodeFn) {
81
- return false;
82
- }
83
- const vnode = vue.h(renderVNodeFn, {
84
- row,
85
- col,
86
- value,
87
- refValue: vue.customRef((track, trigger) => {
88
- return {
89
- get: () => {
90
- track();
91
- return this.getValue();
92
- },
93
- set: value => {
94
- this.setValue(value);
95
- trigger();
96
- }
97
- };
98
- }),
99
- record,
100
- table,
101
- onChange: (value) => this.setValue(value)
102
- });
103
- if (!vnode || !vue.isVNode(vnode)) {
104
- return false;
105
- }
106
- this.checkToPassAppContext(vnode, table);
107
- const wrapContainer = document.createElement('div');
108
- wrapContainer.style.position = 'absolute';
109
- wrapContainer.style.width = '100%';
110
- wrapContainer.style.boxSizing = 'border-box';
111
- const { bgColor } = table.getCellStyle(col, row) || {};
112
- wrapContainer.style.backgroundColor = bgColor || '#FFFFFF';
113
- this.wrapContainer = wrapContainer;
114
- this.tableContainer = container;
115
- this.tableContainer.appendChild(wrapContainer);
116
- vue.render(vnode, wrapContainer);
117
- if (referencePosition === null || referencePosition === void 0 ? void 0 : referencePosition.rect) {
118
- this.adjustPosition(referencePosition.rect);
119
- }
120
- return true;
121
- });
122
- }
123
- checkToPassAppContext(vnode, table) {
124
- var _a, _b, _c, _d;
125
- try {
126
- 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;
127
- if (!!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.components) && !!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.directives)) {
128
- vnode.appContext = userAppContext;
129
- }
130
- }
131
- catch (error) { }
132
- }
133
- getColumnKeyField(column) {
134
- const { field, key } = column || {};
135
- return vutils.isValid(key) ? key : field;
136
- }
137
- getValue() {
138
- return this.currentValue;
139
- }
140
- setValue(value) {
141
- this.currentValue = value;
142
- }
143
- adjustPosition(rect) {
144
- if (this.wrapContainer) {
145
- this.wrapContainer.style.top = `${rect.top}px`;
146
- this.wrapContainer.style.left = `${rect.left}px`;
147
- this.wrapContainer.style.width = `${rect.width}px`;
148
- this.wrapContainer.style.height = `${rect.height}px`;
149
- }
150
- }
151
- validateValue(value, oldValue, editCell, table) {
152
- return tslib.__awaiter(this, void 0, void 0, function* () {
153
- const { col, row } = editCell || {};
154
- if (!vutils.isValid(col) || !vutils.isValid(row)) {
155
- return true;
156
- }
157
- const define = table.getBodyColumnDefine(col, row);
158
- const { editConfig } = define || {};
159
- if (typeof (editConfig === null || editConfig === void 0 ? void 0 : editConfig.validateValue) === 'function') {
160
- const validate = yield editConfig.validateValue({ col, row, value, oldValue, table });
161
- if (validate === false) {
162
- const rect = table.getVisibleCellRangeRelativeRect({ col, row });
163
- table.showTooltip(col, row, {
164
- content: editConfig.invalidPrompt || 'invalid',
165
- referencePosition: { rect, placement: VTable.TYPES.Placement.top },
166
- style: {
167
- bgColor: 'red',
168
- color: 'white',
169
- arrowMark: true
170
- },
171
- disappearDelay: 1000
172
- });
173
- return false;
174
- }
175
- return validate;
176
- }
177
- return true;
178
- });
179
- }
180
- onEnd() {
181
- if (this.wrapContainer && this.tableContainer) {
182
- vue.render(null, this.wrapContainer);
183
- this.tableContainer.removeChild(this.wrapContainer);
184
- }
185
- this.wrapContainer = null;
186
- this.tableContainer = null;
187
- }
188
- isEditorElement(target) {
189
- var _a;
190
- return ((_a = this.wrapContainer) === null || _a === void 0 ? void 0 : _a.contains(target)) || this.isClickEditorElement(target);
191
- }
192
- isClickEditorElement(target) {
193
- while (target) {
194
- if (target.classList && target.classList.contains('table-editor-element')) {
195
- return true;
196
- }
197
- target = target.parentNode;
198
- }
199
- return false;
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
- function checkRenderEditor(column, getEditCustomNode) {
9
- const { editor } = column || {};
10
- const key = getRenderEditorColumnKeyField(column);
11
- if (!vutils.isValid(key) || editor !== constants.DYNAMIC_RENDER_EDITOR) {
12
- return false;
13
- }
14
- if (typeof getEditCustomNode === 'function') {
15
- column.getEditCustomNode = getEditCustomNode;
16
- if (Array.isArray(column.columns) && column.columns.length) {
17
- for (const childColumn of column.columns) {
18
- checkRenderEditor(childColumn, getEditCustomNode);
19
- }
20
- }
21
- return true;
22
- }
23
- return typeof column.getEditCustomNode === 'function';
24
- }
25
- function getRenderEditorColumnKeyField(column) {
26
- const { field, key } = column || {};
27
- return vutils.isValid(key) ? key : field;
28
- }
29
- function getRenderEditor(create, currentContext) {
30
- const registeredEditor = VTable.register.editor(constants.DYNAMIC_RENDER_EDITOR);
31
- let renderEditor = registeredEditor
32
- ? registeredEditor
33
- : undefined;
34
- if (!renderEditor && !!create) {
35
- renderEditor = new editor.DynamicRenderEditor(currentContext);
36
- VTable.register.editor(constants.DYNAMIC_RENDER_EDITOR, renderEditor);
37
- }
38
- return renderEditor;
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;