@visactor/vue-vtable 1.25.0 → 1.25.1-alpha.1

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