@visactor/vue-vtable 1.17.3-alpha.9 → 1.17.3
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/custom/vtable-vue-attribute-plugin.d.ts +5 -0
- package/cjs/components/custom/vtable-vue-attribute-plugin.js +27 -6
- package/cjs/edit/editor.d.ts +4 -1
- package/cjs/edit/editor.js +14 -2
- package/cjs/edit/util.d.ts +1 -1
- package/cjs/edit/util.js +2 -2
- package/cjs/hooks/useCellRender.js +14 -4
- package/cjs/hooks/useEditorRender.js +2 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/utils/customLayoutUtils.js +1 -1
- package/dist/vue-vtable.js +59 -14
- package/dist/vue-vtable.min.js +1 -1
- package/es/components/custom/vtable-vue-attribute-plugin.d.ts +5 -0
- package/es/components/custom/vtable-vue-attribute-plugin.js +27 -6
- package/es/edit/editor.d.ts +4 -1
- package/es/edit/editor.js +14 -2
- package/es/edit/util.d.ts +1 -1
- package/es/edit/util.js +2 -2
- package/es/hooks/useCellRender.js +15 -5
- package/es/hooks/useEditorRender.js +3 -2
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/utils/customLayoutUtils.js +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { IGraphic, IPlugin, IStage } from '@visactor/vtable/es/vrender';
|
|
2
2
|
import { HtmlAttributePlugin } from '@visactor/vtable/es/vrender';
|
|
3
|
+
import type { VNode } from 'vue';
|
|
3
4
|
export declare class VTableVueAttributePlugin extends HtmlAttributePlugin implements IPlugin {
|
|
5
|
+
name: string;
|
|
4
6
|
htmlMap: Record<string, {
|
|
5
7
|
wrapContainer: HTMLElement;
|
|
6
8
|
nativeContainer: HTMLElement;
|
|
@@ -16,10 +18,13 @@ export declare class VTableVueAttributePlugin extends HtmlAttributePlugin implem
|
|
|
16
18
|
}>;
|
|
17
19
|
private renderQueue;
|
|
18
20
|
private isRendering;
|
|
21
|
+
currentContext?: any;
|
|
22
|
+
constructor(currentContext?: any);
|
|
19
23
|
renderGraphicHTML(graphic: IGraphic): void;
|
|
20
24
|
private scheduleRender;
|
|
21
25
|
doRenderGraphic(graphic: IGraphic): void;
|
|
22
26
|
private getGraphicOptions;
|
|
27
|
+
checkToPassAppContext(vnode: VNode, graphic: IGraphic): void;
|
|
23
28
|
checkNeedRender(graphic: IGraphic): boolean;
|
|
24
29
|
checkInViewport(graphic: IGraphic): boolean;
|
|
25
30
|
checkDom(dom: HTMLElement): boolean;
|
|
@@ -6,10 +6,12 @@ var vutils = require('@visactor/vutils');
|
|
|
6
6
|
var vue = require('vue');
|
|
7
7
|
|
|
8
8
|
class VTableVueAttributePlugin extends vrender.HtmlAttributePlugin {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(
|
|
9
|
+
constructor(currentContext) {
|
|
10
|
+
super();
|
|
11
|
+
this.name = 'VTableVueAttributePlugin';
|
|
11
12
|
this.renderQueue = new Set();
|
|
12
13
|
this.isRendering = false;
|
|
14
|
+
this.currentContext = currentContext;
|
|
13
15
|
}
|
|
14
16
|
renderGraphicHTML(graphic) {
|
|
15
17
|
if (!this.checkNeedRender(graphic)) {
|
|
@@ -40,6 +42,9 @@ class VTableVueAttributePlugin extends vrender.HtmlAttributePlugin {
|
|
|
40
42
|
doRenderGraphic(graphic) {
|
|
41
43
|
var _a;
|
|
42
44
|
const { id, options } = this.getGraphicOptions(graphic);
|
|
45
|
+
if (!id) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
43
48
|
const stage = graphic.stage;
|
|
44
49
|
const { element, container: expectedContainer } = options;
|
|
45
50
|
const actualContainer = expectedContainer ? checkFrozenContainer(graphic) : expectedContainer;
|
|
@@ -48,9 +53,13 @@ class VTableVueAttributePlugin extends vrender.HtmlAttributePlugin {
|
|
|
48
53
|
this.removeElement(id);
|
|
49
54
|
targetMap = null;
|
|
50
55
|
}
|
|
56
|
+
this.checkToPassAppContext(element, graphic);
|
|
51
57
|
if (!targetMap || !this.checkDom(targetMap.wrapContainer)) {
|
|
52
58
|
const { wrapContainer, nativeContainer } = this.getWrapContainer(stage, actualContainer, { id, options });
|
|
53
59
|
if (wrapContainer) {
|
|
60
|
+
const dataRenderId = `${this.renderId}`;
|
|
61
|
+
wrapContainer.id = id;
|
|
62
|
+
wrapContainer.setAttribute('data-vue-renderId', dataRenderId);
|
|
54
63
|
vue.render(element, wrapContainer);
|
|
55
64
|
targetMap = {
|
|
56
65
|
wrapContainer,
|
|
@@ -75,12 +84,24 @@ class VTableVueAttributePlugin extends vrender.HtmlAttributePlugin {
|
|
|
75
84
|
}
|
|
76
85
|
getGraphicOptions(graphic) {
|
|
77
86
|
var _a;
|
|
78
|
-
const { vue } = graphic.attribute;
|
|
87
|
+
const { vue } = (graphic === null || graphic === void 0 ? void 0 : graphic.attribute) || {};
|
|
79
88
|
if (!vue) {
|
|
80
89
|
return null;
|
|
81
90
|
}
|
|
82
|
-
const id = vutils.isNil(vue.id) ?
|
|
83
|
-
return { id
|
|
91
|
+
const id = vutils.isNil(vue.id) ? (_a = graphic.id) !== null && _a !== void 0 ? _a : graphic._uid : vue.id;
|
|
92
|
+
return { id: `vue_${id}`, options: vue };
|
|
93
|
+
}
|
|
94
|
+
checkToPassAppContext(vnode, graphic) {
|
|
95
|
+
var _a, _b, _c, _d;
|
|
96
|
+
try {
|
|
97
|
+
const { stage } = getTargetGroup(graphic);
|
|
98
|
+
const { table } = stage || {};
|
|
99
|
+
const userAppContext = (_d = (_c = (_b = (_a = table === null || table === void 0 ? void 0 : 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;
|
|
100
|
+
if (!!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.components) && !!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.directives)) {
|
|
101
|
+
vnode.appContext = userAppContext;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (error) { }
|
|
84
105
|
}
|
|
85
106
|
checkNeedRender(graphic) {
|
|
86
107
|
const { id, options } = this.getGraphicOptions(graphic) || {};
|
|
@@ -190,7 +211,7 @@ class VTableVueAttributePlugin extends vrender.HtmlAttributePlugin {
|
|
|
190
211
|
if (!positionChanged) {
|
|
191
212
|
return;
|
|
192
213
|
}
|
|
193
|
-
const { pointerEvents
|
|
214
|
+
const { pointerEvents, penetrateEventList = ['wheel'] } = options;
|
|
194
215
|
const calculateStyle = this.parseDefaultStyleFromGraphic(graphic);
|
|
195
216
|
const style = this.convertCellStyle(graphic);
|
|
196
217
|
Object.assign(calculateStyle, Object.assign(Object.assign(Object.assign({ overflow: 'hidden' }, (style || {})), (rest || {})), { transform: `translate(${offsetX}px, ${offsetTop}px)`, boxSizing: 'border-box', display: visible !== false ? display || 'block' : 'none', pointerEvents: pointerEvents === true ? 'all' : pointerEvents || 'none', position: 'absolute' }));
|
package/cjs/edit/editor.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { VNode } from 'vue';
|
|
1
2
|
export interface DynamicRenderEditorParams {
|
|
2
3
|
row: number;
|
|
3
4
|
col: number;
|
|
@@ -23,13 +24,15 @@ export declare class DynamicRenderEditor {
|
|
|
23
24
|
tableContainer: HTMLElement | null;
|
|
24
25
|
currentValue: string | null;
|
|
25
26
|
nodeMap?: Map<string | number, Map<string | number, (params: DynamicRenderEditorParams) => any>>;
|
|
26
|
-
|
|
27
|
+
currentContext?: any;
|
|
28
|
+
constructor(currentContext?: any);
|
|
27
29
|
registerNode(tableId?: string | number, key?: string | number, getNode?: () => (params: DynamicRenderEditorParams) => any): void;
|
|
28
30
|
getNode(tableId?: string | number, key?: string | number): (params: DynamicRenderEditorParams) => any;
|
|
29
31
|
removeNode(tableId: string | number): void;
|
|
30
32
|
release(tableId?: string | number): void;
|
|
31
33
|
onStart(editorContext: any): Promise<void>;
|
|
32
34
|
createElement(editorContext: any): Promise<boolean>;
|
|
35
|
+
checkToPassAppContext(vnode: VNode, table: any): void;
|
|
33
36
|
getColumnKeyField(column: any): any;
|
|
34
37
|
getValue(): string;
|
|
35
38
|
setValue(value: any): void;
|
package/cjs/edit/editor.js
CHANGED
|
@@ -6,7 +6,8 @@ var vue = require('vue');
|
|
|
6
6
|
var VTable = require('@visactor/vtable');
|
|
7
7
|
|
|
8
8
|
class DynamicRenderEditor {
|
|
9
|
-
constructor() {
|
|
9
|
+
constructor(currentContext) {
|
|
10
|
+
this.currentContext = currentContext;
|
|
10
11
|
this.tableContainer = null;
|
|
11
12
|
this.currentValue = null;
|
|
12
13
|
this.wrapContainer = null;
|
|
@@ -81,10 +82,11 @@ class DynamicRenderEditor {
|
|
|
81
82
|
value,
|
|
82
83
|
table,
|
|
83
84
|
onChange: (value) => this.setValue(value)
|
|
84
|
-
})) === null || _b === void 0 ? void 0 : _b
|
|
85
|
+
})) === null || _b === void 0 ? void 0 : _b.find((node) => (node === null || node === void 0 ? void 0 : node.type) !== Symbol.for('v-cmt'));
|
|
85
86
|
if (!vnode || !vue.isVNode(vnode)) {
|
|
86
87
|
return false;
|
|
87
88
|
}
|
|
89
|
+
this.checkToPassAppContext(vnode, table);
|
|
88
90
|
const wrapContainer = document.createElement('div');
|
|
89
91
|
wrapContainer.style.position = 'absolute';
|
|
90
92
|
wrapContainer.style.width = '100%';
|
|
@@ -101,6 +103,16 @@ class DynamicRenderEditor {
|
|
|
101
103
|
return true;
|
|
102
104
|
});
|
|
103
105
|
}
|
|
106
|
+
checkToPassAppContext(vnode, table) {
|
|
107
|
+
var _a, _b, _c, _d;
|
|
108
|
+
try {
|
|
109
|
+
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;
|
|
110
|
+
if (!!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.components) && !!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.directives)) {
|
|
111
|
+
vnode.appContext = userAppContext;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (error) { }
|
|
115
|
+
}
|
|
104
116
|
getColumnKeyField(column) {
|
|
105
117
|
const { field, key } = column || {};
|
|
106
118
|
return vutils.isValid(key) ? key : field;
|
package/cjs/edit/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { DynamicRenderEditor } from './editor';
|
|
2
2
|
export declare function checkRenderEditor(column: any, getEditCustomNode?: any): boolean;
|
|
3
3
|
export declare function getRenderEditorColumnKeyField(column: any): any;
|
|
4
|
-
export declare function getRenderEditor(create?: boolean): DynamicRenderEditor;
|
|
4
|
+
export declare function getRenderEditor(create?: boolean, currentContext?: any): DynamicRenderEditor;
|
package/cjs/edit/util.js
CHANGED
|
@@ -21,10 +21,10 @@ function getRenderEditorColumnKeyField(column) {
|
|
|
21
21
|
const { field, key } = column || {};
|
|
22
22
|
return vutils.isValid(key) ? key : field;
|
|
23
23
|
}
|
|
24
|
-
function getRenderEditor(create) {
|
|
24
|
+
function getRenderEditor(create, currentContext) {
|
|
25
25
|
let renderEditor = VTable.register.editor(DYNAMIC_RENDER_EDITOR);
|
|
26
26
|
if (!renderEditor && !!create) {
|
|
27
|
-
renderEditor = new editor.DynamicRenderEditor();
|
|
27
|
+
renderEditor = new editor.DynamicRenderEditor(currentContext);
|
|
28
28
|
VTable.register.editor(DYNAMIC_RENDER_EDITOR, renderEditor);
|
|
29
29
|
}
|
|
30
30
|
return renderEditor;
|
|
@@ -2,17 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
var vue = require('vue');
|
|
4
4
|
var vtableVueAttributePlugin = require('../components/custom/vtable-vue-attribute-plugin.js');
|
|
5
|
+
var vutils = require('@visactor/vutils');
|
|
5
6
|
|
|
6
7
|
function useCellRender(props, tableRef) {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const instance = vue.getCurrentInstance();
|
|
10
|
+
const createReactContainer = (_b = (_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.customConfig) === null || _b === void 0 ? void 0 : _b.createReactContainer;
|
|
7
11
|
vue.watchEffect(() => {
|
|
8
|
-
var _a, _b;
|
|
9
|
-
if (!
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
if (!createReactContainer) {
|
|
10
14
|
return;
|
|
11
15
|
}
|
|
12
|
-
|
|
16
|
+
const pluginService = (_c = (_b = (_a = tableRef.value) === null || _a === void 0 ? void 0 : _a.scenegraph) === null || _b === void 0 ? void 0 : _b.stage) === null || _c === void 0 ? void 0 : _c.pluginService;
|
|
17
|
+
if (!pluginService) {
|
|
13
18
|
return;
|
|
14
19
|
}
|
|
15
|
-
|
|
20
|
+
const exist = pluginService.findPluginsByName('VTableVueAttributePlugin');
|
|
21
|
+
if (vutils.isArray(exist) && !!exist.length) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const plugin = new vtableVueAttributePlugin.VTableVueAttributePlugin(instance === null || instance === void 0 ? void 0 : instance.appContext);
|
|
25
|
+
pluginService.register(plugin);
|
|
16
26
|
});
|
|
17
27
|
}
|
|
18
28
|
|
|
@@ -7,6 +7,7 @@ require('@visactor/vtable');
|
|
|
7
7
|
var util = require('../edit/util.js');
|
|
8
8
|
|
|
9
9
|
function useEditorRender(props, tableRef) {
|
|
10
|
+
const instance = vue.getCurrentInstance();
|
|
10
11
|
const validColumns = vue.computed(() => {
|
|
11
12
|
var _a;
|
|
12
13
|
const columns = (_a = props.options) === null || _a === void 0 ? void 0 : _a.columns;
|
|
@@ -31,7 +32,7 @@ function useEditorRender(props, tableRef) {
|
|
|
31
32
|
renderEditor.removeNode(id);
|
|
32
33
|
}
|
|
33
34
|
else if (validColumns.value.length > 0) {
|
|
34
|
-
renderEditor = util.getRenderEditor(true);
|
|
35
|
+
renderEditor = util.getRenderEditor(true, instance === null || instance === void 0 ? void 0 : instance.appContext);
|
|
35
36
|
}
|
|
36
37
|
validColumns.value.forEach(column => {
|
|
37
38
|
const { getEditCustomNode } = column;
|
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -40,7 +40,7 @@ function _interopNamespaceDefault(e) {
|
|
|
40
40
|
|
|
41
41
|
var VTable__namespace = /*#__PURE__*/_interopNamespaceDefault(VTable);
|
|
42
42
|
|
|
43
|
-
const version = "1.17.3
|
|
43
|
+
const version = "1.17.3";
|
|
44
44
|
|
|
45
45
|
exports.VTable = VTable__namespace;
|
|
46
46
|
Object.defineProperty(exports, 'register', {
|
|
@@ -53,7 +53,7 @@ function createCustomLayout(children, isHeader, args) {
|
|
|
53
53
|
const subChildren = resolveChildren(childChildren);
|
|
54
54
|
if (vutils.isObject(props === null || props === void 0 ? void 0 : props.vue)) {
|
|
55
55
|
const { element } = props.vue;
|
|
56
|
-
const targetVNode = element !== null && element !== void 0 ? element : subChildren
|
|
56
|
+
const targetVNode = element !== null && element !== void 0 ? element : subChildren.find(node => (node === null || node === void 0 ? void 0 : node.type) !== Symbol.for('v-cmt'));
|
|
57
57
|
Object.assign(child.props.vue, {
|
|
58
58
|
element: vue.isVNode(targetVNode) ? targetVNode : null,
|
|
59
59
|
container: isHeader ? (_a = args === null || args === void 0 ? void 0 : args.table) === null || _a === void 0 ? void 0 : _a.headerDomContainer : (_b = args === null || args === void 0 ? void 0 : args.table) === null || _b === void 0 ? void 0 : _b.bodyDomContainer
|
package/dist/vue-vtable.js
CHANGED
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
const subChildren = resolveChildren(childChildren);
|
|
70
70
|
if (vutils.isObject(props?.vue)) {
|
|
71
71
|
const { element } = props.vue;
|
|
72
|
-
const targetVNode = element ?? subChildren
|
|
72
|
+
const targetVNode = element ?? subChildren.find(node => node?.type !== Symbol.for('v-cmt'));
|
|
73
73
|
Object.assign(child.props.vue, {
|
|
74
74
|
element: vue.isVNode(targetVNode) ? targetVNode : null,
|
|
75
75
|
container: isHeader ? args?.table?.headerDomContainer : args?.table?.bodyDomContainer
|
|
@@ -134,7 +134,9 @@
|
|
|
134
134
|
tableContainer;
|
|
135
135
|
currentValue;
|
|
136
136
|
nodeMap;
|
|
137
|
-
|
|
137
|
+
currentContext;
|
|
138
|
+
constructor(currentContext) {
|
|
139
|
+
this.currentContext = currentContext;
|
|
138
140
|
this.tableContainer = null;
|
|
139
141
|
this.currentValue = null;
|
|
140
142
|
this.wrapContainer = null;
|
|
@@ -204,10 +206,11 @@
|
|
|
204
206
|
value,
|
|
205
207
|
table,
|
|
206
208
|
onChange: (value) => this.setValue(value)
|
|
207
|
-
})?.
|
|
209
|
+
})?.find((node) => node?.type !== Symbol.for('v-cmt'));
|
|
208
210
|
if (!vnode || !vue.isVNode(vnode)) {
|
|
209
211
|
return false;
|
|
210
212
|
}
|
|
213
|
+
this.checkToPassAppContext(vnode, table);
|
|
211
214
|
const wrapContainer = document.createElement('div');
|
|
212
215
|
wrapContainer.style.position = 'absolute';
|
|
213
216
|
wrapContainer.style.width = '100%';
|
|
@@ -223,6 +226,15 @@
|
|
|
223
226
|
}
|
|
224
227
|
return true;
|
|
225
228
|
}
|
|
229
|
+
checkToPassAppContext(vnode, table) {
|
|
230
|
+
try {
|
|
231
|
+
const userAppContext = table.options?.customConfig?.getVueUserAppContext?.() ?? this.currentContext;
|
|
232
|
+
if (!!userAppContext?.components && !!userAppContext?.directives) {
|
|
233
|
+
vnode.appContext = userAppContext;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch (error) { }
|
|
237
|
+
}
|
|
226
238
|
getColumnKeyField(column) {
|
|
227
239
|
const { field, key } = column || {};
|
|
228
240
|
return vutils.isValid(key) ? key : field;
|
|
@@ -307,10 +319,10 @@
|
|
|
307
319
|
const { field, key } = column || {};
|
|
308
320
|
return vutils.isValid(key) ? key : field;
|
|
309
321
|
}
|
|
310
|
-
function getRenderEditor(create) {
|
|
322
|
+
function getRenderEditor(create, currentContext) {
|
|
311
323
|
let renderEditor = VTable.register.editor(DYNAMIC_RENDER_EDITOR);
|
|
312
324
|
if (!renderEditor && !!create) {
|
|
313
|
-
renderEditor = new DynamicRenderEditor();
|
|
325
|
+
renderEditor = new DynamicRenderEditor(currentContext);
|
|
314
326
|
VTable.register.editor(DYNAMIC_RENDER_EDITOR, renderEditor);
|
|
315
327
|
}
|
|
316
328
|
return renderEditor;
|
|
@@ -470,6 +482,7 @@
|
|
|
470
482
|
const TABLE_EVENTS_KEYS = Object.keys(TABLE_EVENTS);
|
|
471
483
|
|
|
472
484
|
function useEditorRender(props, tableRef) {
|
|
485
|
+
const instance = vue.getCurrentInstance();
|
|
473
486
|
const validColumns = vue.computed(() => {
|
|
474
487
|
const columns = props.options?.columns;
|
|
475
488
|
if (!vutils.isArray(columns)) {
|
|
@@ -493,7 +506,7 @@
|
|
|
493
506
|
renderEditor.removeNode(id);
|
|
494
507
|
}
|
|
495
508
|
else if (validColumns.value.length > 0) {
|
|
496
|
-
renderEditor = getRenderEditor(true);
|
|
509
|
+
renderEditor = getRenderEditor(true, instance?.appContext);
|
|
497
510
|
}
|
|
498
511
|
validColumns.value.forEach(column => {
|
|
499
512
|
const { getEditCustomNode } = column;
|
|
@@ -516,8 +529,14 @@
|
|
|
516
529
|
}
|
|
517
530
|
|
|
518
531
|
class VTableVueAttributePlugin extends vrender.HtmlAttributePlugin {
|
|
532
|
+
name = 'VTableVueAttributePlugin';
|
|
519
533
|
renderQueue = new Set();
|
|
520
534
|
isRendering = false;
|
|
535
|
+
currentContext;
|
|
536
|
+
constructor(currentContext) {
|
|
537
|
+
super();
|
|
538
|
+
this.currentContext = currentContext;
|
|
539
|
+
}
|
|
521
540
|
renderGraphicHTML(graphic) {
|
|
522
541
|
if (!this.checkNeedRender(graphic)) {
|
|
523
542
|
return;
|
|
@@ -546,6 +565,9 @@
|
|
|
546
565
|
}
|
|
547
566
|
doRenderGraphic(graphic) {
|
|
548
567
|
const { id, options } = this.getGraphicOptions(graphic);
|
|
568
|
+
if (!id) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
549
571
|
const stage = graphic.stage;
|
|
550
572
|
const { element, container: expectedContainer } = options;
|
|
551
573
|
const actualContainer = expectedContainer ? checkFrozenContainer(graphic) : expectedContainer;
|
|
@@ -554,9 +576,13 @@
|
|
|
554
576
|
this.removeElement(id);
|
|
555
577
|
targetMap = null;
|
|
556
578
|
}
|
|
579
|
+
this.checkToPassAppContext(element, graphic);
|
|
557
580
|
if (!targetMap || !this.checkDom(targetMap.wrapContainer)) {
|
|
558
581
|
const { wrapContainer, nativeContainer } = this.getWrapContainer(stage, actualContainer, { id, options });
|
|
559
582
|
if (wrapContainer) {
|
|
583
|
+
const dataRenderId = `${this.renderId}`;
|
|
584
|
+
wrapContainer.id = id;
|
|
585
|
+
wrapContainer.setAttribute('data-vue-renderId', dataRenderId);
|
|
560
586
|
vue.render(element, wrapContainer);
|
|
561
587
|
targetMap = {
|
|
562
588
|
wrapContainer,
|
|
@@ -580,12 +606,23 @@
|
|
|
580
606
|
}
|
|
581
607
|
}
|
|
582
608
|
getGraphicOptions(graphic) {
|
|
583
|
-
const { vue } = graphic
|
|
609
|
+
const { vue } = graphic?.attribute || {};
|
|
584
610
|
if (!vue) {
|
|
585
611
|
return null;
|
|
586
612
|
}
|
|
587
|
-
const id = vutils.isNil(vue.id) ?
|
|
588
|
-
return { id
|
|
613
|
+
const id = vutils.isNil(vue.id) ? graphic.id ?? graphic._uid : vue.id;
|
|
614
|
+
return { id: `vue_${id}`, options: vue };
|
|
615
|
+
}
|
|
616
|
+
checkToPassAppContext(vnode, graphic) {
|
|
617
|
+
try {
|
|
618
|
+
const { stage } = getTargetGroup(graphic);
|
|
619
|
+
const { table } = stage || {};
|
|
620
|
+
const userAppContext = table?.options?.customConfig?.getVueUserAppContext?.() ?? this.currentContext;
|
|
621
|
+
if (!!userAppContext?.components && !!userAppContext?.directives) {
|
|
622
|
+
vnode.appContext = userAppContext;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
catch (error) { }
|
|
589
626
|
}
|
|
590
627
|
checkNeedRender(graphic) {
|
|
591
628
|
const { id, options } = this.getGraphicOptions(graphic) || {};
|
|
@@ -693,7 +730,7 @@
|
|
|
693
730
|
if (!positionChanged) {
|
|
694
731
|
return;
|
|
695
732
|
}
|
|
696
|
-
const { pointerEvents
|
|
733
|
+
const { pointerEvents, penetrateEventList = ['wheel'] } = options;
|
|
697
734
|
const calculateStyle = this.parseDefaultStyleFromGraphic(graphic);
|
|
698
735
|
const style = this.convertCellStyle(graphic);
|
|
699
736
|
Object.assign(calculateStyle, {
|
|
@@ -818,14 +855,22 @@
|
|
|
818
855
|
}
|
|
819
856
|
|
|
820
857
|
function useCellRender(props, tableRef) {
|
|
858
|
+
const instance = vue.getCurrentInstance();
|
|
859
|
+
const createReactContainer = props?.options?.customConfig?.createReactContainer;
|
|
821
860
|
vue.watchEffect(() => {
|
|
822
|
-
if (!
|
|
861
|
+
if (!createReactContainer) {
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
const pluginService = tableRef.value?.scenegraph?.stage?.pluginService;
|
|
865
|
+
if (!pluginService) {
|
|
823
866
|
return;
|
|
824
867
|
}
|
|
825
|
-
|
|
868
|
+
const exist = pluginService.findPluginsByName('VTableVueAttributePlugin');
|
|
869
|
+
if (vutils.isArray(exist) && !!exist.length) {
|
|
826
870
|
return;
|
|
827
871
|
}
|
|
828
|
-
|
|
872
|
+
const plugin = new VTableVueAttributePlugin(instance?.appContext);
|
|
873
|
+
pluginService.register(plugin);
|
|
829
874
|
});
|
|
830
875
|
}
|
|
831
876
|
|
|
@@ -1257,7 +1302,7 @@
|
|
|
1257
1302
|
}
|
|
1258
1303
|
CheckBox.symbol = 'CheckBox';
|
|
1259
1304
|
|
|
1260
|
-
const version = "1.17.3
|
|
1305
|
+
const version = "1.17.3";
|
|
1261
1306
|
|
|
1262
1307
|
exports.VTable = VTable__namespace;
|
|
1263
1308
|
Object.defineProperty(exports, 'register', {
|
package/dist/vue-vtable.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@visactor/vtable"),require("vue"),require("@visactor/vutils"),require("@visactor/vtable/es/vrender")):"function"==typeof define&&define.amd?define(["exports","@visactor/vtable","vue","@visactor/vutils","@visactor/vtable/es/vrender"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VueVTable={},e.VTable,e.Vue,e.VUtils,e.VTable.vrender)}(this,(function(e,t,n,o,r){"use strict";function i(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var l=i(t);function a(e){return e.replace(/-([a-z])/g,(e=>e[1].toUpperCase()))}function s(e){const t={};for(const n in e)if(e.hasOwnProperty(n)){t[a(n)]=e[n]}return t}function u(e){return e.flatMap((e=>Array.isArray(e.children)?u(e.children):e))}function c(e,t,r){const i={Group:l.CustomLayout.Group,Image:l.CustomLayout.Image,Text:l.CustomLayout.Text,Tag:l.CustomLayout.Tag,Radio:l.CustomLayout.Radio,CheckBox:l.CustomLayout.CheckBox};return{rootComponent:function e(l){if(!l)return null;const{type:u,children:c}=l,d=s(l.props),p=i[u?.symbol||u?.name];if(!p)return null;const h=new p({...d});!function(e,t){Object.keys(t).forEach((n=>{if(function(e,t){return e.startsWith("on")&&o.isFunction(t[e])}(n,t)){let o;o=n.startsWith("on")?n.slice(2).toLowerCase():a(n.slice(2)).toLowerCase(),e.addEventListener(o,t[n])}}))}(h,d);const C=function(e){return e?.default?.()||e||[]}(c);if(o.isObject(d?.vue)){const{element:e}=d.vue,o=e??C[0];return Object.assign(l.props.vue,{element:n.isVNode(o)?o:null,container:t?r?.table?.headerDomContainer:r?.table?.bodyDomContainer}),h}return C.forEach((t=>{const n=e(t);n?h.add(n):t.type===Symbol.for("v-fgt")&&t.children.forEach((t=>{const n=e(t);n&&h.add(n)}))})),h}(e)}}function d(e,t){return n=>{const{table:o,row:r,col:i,rect:l}=n,a=o.getCellOriginRecord(i,r),{height:s,width:u}=l??o.getCellRect(i,r),d=t?"headerCustomLayout":"customLayout";if(!e[d])return null;const p=e[d]({table:o,row:r,col:i,rect:l,record:a,height:s,width:u})[0],{rootComponent:h}=c(p,t,n);return{rootContainer:h,renderDefault:!1}}}class p{wrapContainer;tableContainer;currentValue;nodeMap;constructor(){this.tableContainer=null,this.currentValue=null,this.wrapContainer=null,this.nodeMap=new Map}registerNode(e,t,n){o.isValid(e)&&o.isValid(t)&&"function"==typeof n&&(this.nodeMap.has(e)||this.nodeMap.set(e,new Map),this.nodeMap.get(e).set(t,n))}getNode(e,t){return this.nodeMap.get(e)?.get(t)}removeNode(e){this.nodeMap.delete(e)}release(e){o.isValid(e)?this.removeNode(e):this.nodeMap.clear()}async onStart(e){const{value:t}=e;this.setValue(t),await this.createElement(e)}async createElement(e){const{row:r,col:i,value:l,table:a,container:s,referencePosition:u}=e;if(!s)return!1;const c=a.getBodyColumnDefine(i,r),{editConfig:d}=c||{},{id:p}=a,h=this.getColumnKeyField(c);if(!o.isValid(h)||!o.isValid(p))return!1;if("function"==typeof d?.editBefore){if(!await d.editBefore(e))return a.showTooltip(i,r,{content:d.disablePrompt||"This field is not allowed to be edited",referencePosition:{rect:u?.rect,placement:t.TYPES.Placement.top},style:{bgColor:"black",color:"white",arrowMark:!0},disappearDelay:1e3}),!1}const C=this.getNode(p,h)?.({row:r,col:i,value:l,table:a,onChange:e=>this.setValue(e)})?.[0];if(!C||!n.isVNode(C))return!1;const m=document.createElement("div");m.style.position="absolute",m.style.width="100%",m.style.boxSizing="border-box";const{bgColor:y}=a.getCellStyle(i,r)||{};return m.style.backgroundColor=y||"#FFFFFF",this.wrapContainer=m,this.tableContainer=s,this.tableContainer.appendChild(m),n.render(C,m),u?.rect&&this.adjustPosition(u.rect),!0}getColumnKeyField(e){const{field:t,key:n}=e||{};return o.isValid(n)?n:t}getValue(){return this.currentValue}setValue(e){this.currentValue=e}adjustPosition(e){this.wrapContainer&&(this.wrapContainer.style.top=`${e.top}px`,this.wrapContainer.style.left=`${e.left}px`,this.wrapContainer.style.width=`${e.width}px`,this.wrapContainer.style.height=`${e.height}px`)}async validateValue(e,n,r,i){const{col:l,row:a}=r||{};if(!o.isValid(l)||!o.isValid(a))return!0;const s=i.getBodyColumnDefine(l,a),{editConfig:u}=s||{};if("function"==typeof u?.validateValue){const o=await u.validateValue({col:l,row:a,value:e,oldValue:n,table:i});if(!1===o){const e=i.getVisibleCellRangeRelativeRect({col:l,row:a});return i.showTooltip(l,a,{content:u.invalidPrompt||"invalid",referencePosition:{rect:e,placement:t.TYPES.Placement.top},style:{bgColor:"red",color:"white",arrowMark:!0},disappearDelay:1e3}),!1}return o}return!0}onEnd(){this.wrapContainer&&this.tableContainer&&(n.render(null,this.wrapContainer),this.tableContainer.removeChild(this.wrapContainer)),this.wrapContainer=null,this.tableContainer=null}isEditorElement(e){return this.wrapContainer?.contains(e)||this.isClickEditorElement(e)}isClickEditorElement(e){for(;e;){if(e.classList&&e.classList.contains("table-editor-element"))return!0;e=e.parentNode}return!1}}const h="dynamic-render-editor";function C(e,t){const{editor:n}=e||{},r=m(e);return!(!o.isValid(r)||n!==h)&&("function"==typeof t?(e.getEditCustomNode=t,!0):"function"==typeof e.getEditCustomNode)}function m(e){const{field:t,key:n}=e||{};return o.isValid(n)?n:t}function y(e){let n=t.register.editor(h);return!n&&e&&(n=new p,t.register.editor(h,n)),n}function f(e){const t={columns:[],columnHeaderTitle:[],rows:[],rowHeaderTitle:[],indicators:[],corner:{},tooltip:{},menu:{}},n={PivotColumnDimension:"columns",PivotColumnHeaderTitle:"columnHeaderTitle",PivotRowDimension:"rows",PivotRowHeaderTitle:"rowHeaderTitle",PivotCorner:"corner",PivotIndicator:"indicators",Tooltip:"tooltip",Menu:"menu"};return e.forEach((e=>{e.props=s(e.props);const o=e.type?.symbol||e.type?.name,r=n[o];r&&(Array.isArray(t[r])?e.props.hasOwnProperty("objectHandler")?t[r].push(e.props.objectHandler):t[r].push(e.props):t[r]=e.props)})),t}function g(e,t){return{...e,columns:t.columns&&t.columns.length?t.columns:e.columns,columnHeaderTitle:t.columnHeaderTitle&&t.columnHeaderTitle.length?t.columnHeaderTitle:e.columnHeaderTitle,rows:t.rows&&t.rows.length?t.rows:e.rows,rowHeaderTitle:t.rowHeaderTitle&&t.rowHeaderTitle.length?t.rowHeaderTitle:e.rowHeaderTitle,indicators:t.indicators&&t.indicators.length?t.indicators:e.indicators,corner:Object.keys(e.corner||{}).length?e.corner:t.corner,tooltip:Object.keys(t.tooltip||{}).length?t.tooltip:e.tooltip,menu:Object.keys(t.menu||{}).length?t.menu:e.menu}}const E={...t.ListTable.EVENT_TYPE,...t.PivotTable.EVENT_TYPE,...t.PivotChart.EVENT_TYPE},v={onClickCell:E.CLICK_CELL,onDblClickCell:E.DBLCLICK_CELL,onMouseDownCell:E.MOUSEDOWN_CELL,onMouseUpCell:E.MOUSEUP_CELL,onSelectedCell:E.SELECTED_CELL,onKeyDown:E.KEYDOWN,onMouseEnterTable:E.MOUSEENTER_TABLE,onMouseLeaveTable:E.MOUSELEAVE_TABLE,onMouseDownTable:E.MOUSEDOWN_TABLE,onMouseMoveCell:E.MOUSEMOVE_CELL,onMouseEnterCell:E.MOUSEENTER_CELL,onMouseLeaveCell:E.MOUSELEAVE_CELL,onContextMenuCell:E.CONTEXTMENU_CELL,onResizeColumn:E.RESIZE_COLUMN,onResizeColumnEnd:E.RESIZE_COLUMN_END,onChangeHeaderPosition:E.CHANGE_HEADER_POSITION,onChangeHeaderPositionStart:E.CHANGE_HEADER_POSITION_START,onChangeHeaderPositionFail:E.CHANGE_HEADER_POSITION_FAIL,onSortClick:E.SORT_CLICK,onFreezeClick:E.FREEZE_CLICK,onScroll:E.SCROLL,onDropdownMenuClick:E.DROPDOWN_MENU_CLICK,onMouseOverChartSymbol:E.MOUSEOVER_CHART_SYMBOL,onDragSelectEnd:E.DRAG_SELECT_END,onDropdownIconClick:E.DROPDOWN_ICON_CLICK,onDropdownMenuClear:E.DROPDOWN_MENU_CLEAR,onTreeHierarchyStateChange:E.TREE_HIERARCHY_STATE_CHANGE,onShowMenu:E.SHOW_MENU,onHideMenu:E.HIDE_MENU,onIconClick:E.ICON_CLICK,onLegendItemClick:E.LEGEND_ITEM_CLICK,onLegendItemHover:E.LEGEND_ITEM_HOVER,onLegendItemUnHover:E.LEGEND_ITEM_UNHOVER,onLegendChange:E.LEGEND_CHANGE,onMouseEnterAxis:E.MOUSEENTER_AXIS,onMouseLeaveAxis:E.MOUSELEAVE_AXIS,onCheckboxStateChange:E.CHECKBOX_STATE_CHANGE,onRadioStateChange:E.RADIO_STATE_CHANGE,onAfterRender:E.AFTER_RENDER,onInitialized:E.INITIALIZED,onPivotSortClick:E.PIVOT_SORT_CLICK,onDrillMenuClick:E.DRILLMENU_CLICK,onVChartEventType:E.VCHART_EVENT_TYPE,onChangeCellValue:E.CHANGE_CELL_VALUE,onMousedownFillHandle:E.MOUSEDOWN_FILL_HANDLE,onDragFillHandleEnd:E.DRAG_FILL_HANDLE_END,onDblclickFillHandle:E.DBLCLICK_FILL_HANDLE,onScrollVerticalEnd:E.SCROLL_VERTICAL_END,onScrollHorizontalEnd:E.SCROLL_HORIZONTAL_END,onChangCellValue:E.CHANGE_CELL_VALUE},b=Object.keys(v);function w(e,t){const r=n.computed((()=>{const t=e.options?.columns;return o.isArray(t)?t.filter((e=>!!o.isObject(e)&&!!C(e))):[]}));function i(){return t.value?.id}n.watchEffect((()=>{!function(){const e=i();if(!o.isValid(e))return;let t=y();t?t.removeNode(e):r.value.length>0&&(t=y(!0));r.value.forEach((n=>{const{getEditCustomNode:o}=n,r=m(n);t.registerNode(e,r,o),delete n.editCustomNode}))}()})),n.onBeforeUnmount((()=>{!function(){const e=i();if(!o.isValid(e))return;const t=y();t?.release(e)}()}))}class T extends r.HtmlAttributePlugin{renderQueue=new Set;isRendering=!1;renderGraphicHTML(e){this.checkNeedRender(e)&&(this.renderQueue.add(e),this.scheduleRender())}scheduleRender(){this.isRendering||(this.isRendering=!0,requestAnimationFrame((()=>{this.renderQueue.forEach((e=>{try{this.doRenderGraphic(e)}catch(t){const{id:n}=this.getGraphicOptions(e)||{};this.removeElement(n,!0)}})),this.renderQueue.clear(),this.isRendering=!1})))}doRenderGraphic(e){const{id:t,options:o}=this.getGraphicOptions(e),r=e.stage,{element:i,container:l}=o,a=l?function(e){const{col:t,row:n,stage:o}=L(e);let r=e.attribute.vue?.container;const{table:i}=o;r===i.bodyDomContainer?t<i.frozenColCount&&n>=i.rowCount-i.bottomFrozenRowCount?r=i.bottomFrozenBodyDomContainer:t>=i.colCount-i.rightFrozenColCount&&n>=i.rowCount-i.bottomFrozenRowCount?r=i.rightFrozenBottomDomContainer:n>=i.rowCount-i.bottomFrozenRowCount?r=i.bottomFrozenBodyDomContainer:t<i.frozenColCount?r=i.frozenBodyDomContainer:t>=i.colCount-i.rightFrozenColCount&&(r=i.rightFrozenBodyDomContainer):r===i.headerDomContainer&&(t<i.frozenColCount?r=i.frozenHeaderDomContainer:t>=i.colCount-i.rightFrozenColCount&&(r=i.rightFrozenHeaderDomContainer));return r}(e):l;let s=this.htmlMap?.[t];if(s&&a&&a!==s.container&&(this.removeElement(t),s=null),s&&this.checkDom(s.wrapContainer))n.render(i,s.wrapContainer);else{const{wrapContainer:l,nativeContainer:u}=this.getWrapContainer(r,a,{id:t,options:o});l&&(n.render(i,l),s={wrapContainer:l,nativeContainer:u,container:a,renderId:this.renderId,graphic:e,isInViewport:!0,lastPosition:null,lastStyle:{}},this.htmlMap[t]=s)}s&&(this.updateStyleOfWrapContainer(e,r,s.wrapContainer,s.nativeContainer),s.renderId=this.renderId)}getGraphicOptions(e){const{vue:t}=e.attribute;if(!t)return null;return{id:o.isNil(t.id)?`${e.id??e._uid}_vue`:t.id,options:t}}checkNeedRender(e){const{id:t,options:n}=this.getGraphicOptions(e)||{};if(!t)return!1;if(!e.stage)return!1;const{element:o}=n;if(!o)return!1;return this.checkInViewport(e)}checkInViewport(e){const{stage:t,globalAABBBounds:n}=e;if(!t)return!1;const o=100,{AABBBounds:r}=t,i=r.x1-o,l=r.x2+o,a=r.y1-o,s=r.y2+o;return n.x1<l&&n.x2>i&&n.y1<s&&n.y2>a}checkDom(e){return!!e&&document.contains(e)}removeAllDom(e){this.htmlMap&&(Object.keys(this.htmlMap).forEach((e=>{this.removeElement(e,!0)})),this.htmlMap=null)}removeElement(e,t){const o=this.htmlMap?.[e];if(!o)return;const{wrapContainer:r}=o;r&&(n.render(null,r),t?(this.checkDom(r)&&super.removeElement(e),delete this.htmlMap[e]):(r.remove(),o.isInViewport=!1),this.removeWrapContainerEventListener(r))}getWrapContainer(e,t,n){let o;o=t?"string"==typeof t?r.application.global.getElementById(t):t:e.window.getContainer();const{id:i}=n||{},l=this.htmlMap?.[i];if(l&&!l.isInViewport){const{wrapContainer:e}=l;return this.checkDom(e)||o.appendChild(e),{wrapContainer:e,nativeContainer:o}}return{wrapContainer:r.application.global.createDom({tagName:"div",parent:o}),nativeContainer:o}}updateStyleOfWrapContainer(e,t,n,i){const{attribute:l,type:a}=e,{vue:s,width:u,height:c,visible:d,display:p,...h}=l||{},{x:C,y:m}=this.calculatePosition(e,s.anchorType),{left:y,top:f}=this.calculateOffset(t,i,C,m),{id:g}=this.getGraphicOptions(e)||{},E=g?this.htmlMap[g]:null;if(!E)return;if(!(!E.lastPosition||E.lastPosition.x!==y||E.lastPosition.y!==f))return;const{pointerEvents:v=!0,penetrateEventList:b=["wheel"]}=s,w=this.parseDefaultStyleFromGraphic(e),T=this.convertCellStyle(e);Object.assign(w,{overflow:"hidden",...T||{},...h||{},transform:`translate(${y}px, ${f}px)`,boxSizing:"border-box",display:!1!==d?p||"block":"none",pointerEvents:!0===v?"all":v||"none",position:"absolute"}),"none"!==w.pointerEvents&&(this.removeWrapContainerEventListener(n),o.uniqArray(b).forEach((e=>{"wheel"===e&&(n.addEventListener("wheel",this.onWheel),n.addEventListener("wheel",(e=>e.preventDefault()),!0))}))),"text"===a&&"position"===s.anchorType&&Object.assign(w,this.getTransformOfText(e)),this.applyUserStyles(s,w,{offsetX:y,offsetTop:f,graphic:e,wrapContainer:n});!o.isEqual(E.lastStyle,w)&&(r.application.global.updateDom(n,{width:u,height:c,style:w}),E.lastStyle=w)}convertCellStyle(e){const{col:t,row:n,stage:r}=L(e),i=r?.table?.getCellStyle(t,n);if(!o.isObject(i))return;const{lineHeight:l,padding:a,...s}=i;return{...s,padding:o.isArray(a)?a.map((e=>`${e}px`)).join(" "):a}}calculatePosition(e,t){const n=e.globalAABBBounds;if("position"===t||n.empty()){const t=e.globalTransMatrix;return{x:t.e,y:t.f}}return o.calculateAnchorOfBounds(n,t||"top-left")}calculateOffset(e,t,n,o){const i=r.application.global.getElementTopLeft(t,!1),l=e.window.getTopLeft(!1);return{left:n+l.left-i.left,top:o+l.top-i.top}}applyUserStyles(e,t,n){if(o.isFunction(e.style)){const o=e.style({top:n.offsetTop,left:n.offsetX,width:n.graphic.globalAABBBounds.width(),height:n.graphic.globalAABBBounds.height()},n.graphic,n.wrapContainer);Object.assign(t,o)}else o.isObject(e.style)?Object.assign(t,e.style):o.isString(e.style)&&Object.assign(t,o.styleStringToObject(e.style))}}function L(e){for(;e?.parent;){if("custom-container"===e.name)return e;e=e.parent}return{col:-1,row:-1,stage:null}}var S=n.defineComponent({__name:"base-table",props:{type:{type:String,required:!1},options:{type:null,required:!1},records:{type:Array,required:!1},width:{type:[Number,String],required:!1,default:"100%"},height:{type:[Number,String],required:!1,default:"100%"},onReady:{type:Function,required:!1},onError:{type:Function,required:!1},keepColumnWidthChange:{type:Boolean,required:!1},onClickCell:{type:null,required:!1},onDblClickCell:{type:null,required:!1},onMouseDownCell:{type:null,required:!1},onMouseUpCell:{type:null,required:!1},onSelectedCell:{type:null,required:!1},onKeyDown:{type:null,required:!1},onMouseEnterTable:{type:null,required:!1},onMouseLeaveTable:{type:null,required:!1},onMouseDownTable:{type:null,required:!1},onMouseMoveCell:{type:null,required:!1},onMouseEnterCell:{type:null,required:!1},onMouseLeaveCell:{type:null,required:!1},onContextMenuCell:{type:null,required:!1},onResizeColumn:{type:null,required:!1},onResizeColumnEnd:{type:null,required:!1},onChangeHeaderPosition:{type:null,required:!1},onChangeHeaderPositionStart:{type:null,required:!1},onChangeHeaderPositionFail:{type:null,required:!1},onSortClick:{type:null,required:!1},onFreezeClick:{type:null,required:!1},onScroll:{type:null,required:!1},onDropdownMenuClick:{type:null,required:!1},onMouseOverChartSymbol:{type:null,required:!1},onDragSelectEnd:{type:null,required:!1},onDropdownIconClick:{type:null,required:!1},onDropdownMenuClear:{type:null,required:!1},onTreeHierarchyStateChange:{type:null,required:!1},onShowMenu:{type:null,required:!1},onHideMenu:{type:null,required:!1},onIconClick:{type:null,required:!1},onLegendItemClick:{type:null,required:!1},onLegendItemHover:{type:null,required:!1},onLegendItemUnHover:{type:null,required:!1},onLegendChange:{type:null,required:!1},onMouseEnterAxis:{type:null,required:!1},onMouseLeaveAxis:{type:null,required:!1},onCheckboxStateChange:{type:null,required:!1},onRadioStateChange:{type:null,required:!1},onAfterRender:{type:null,required:!1},onInitialized:{type:null,required:!1},onPivotSortClick:{type:null,required:!1},onDrillMenuClick:{type:null,required:!1},onVChartEventType:{type:null,required:!1},onChangeCellValue:{type:null,required:!1},onMousedownFillHandle:{type:null,required:!1},onDragFillHandleEnd:{type:null,required:!1},onDblclickFillHandle:{type:null,required:!1},onScrollVerticalEnd:{type:null,required:!1},onScrollHorizontalEnd:{type:null,required:!1}},emits:b,setup(e,{expose:o,emit:r}){const i=e,l=n.ref(null),a=n.shallowRef(null),s=n.ref(new Map),u=n.ref([]),c=n.ref([]);w(i,a),function(e,t){n.watchEffect((()=>{e?.options?.customConfig?.createReactContainer&&t.value&&t.value.scenegraph.stage.pluginService.register(new T)}))}(i,a),o({vTableInstance:a});const d=n.computed((()=>"number"==typeof i.width?`${i.width}px`:i.width)),p=n.computed((()=>"number"==typeof i.height?`${i.height}px`:i.height)),h=r,C=(e,t)=>{const n=new e(l.value,t);a.value=n,s.value.clear(),u.value=[],c.value=[],n.on("resize_column_end",(e=>{if(!i.keepColumnWidthChange)return;const{col:t,colWidths:o}=e,r=o[t];if(n.isPivotTable()){const e=n.getCellHeaderPaths(t,n.columnHeaderLevelCount);let o=null;o="rowHeader"===e.cellLocation?e.rowHeaderPaths:e.colHeaderPaths;let i=!1;for(let e=0;e<u.value.length;e++){const t=u.value[e];JSON.stringify(t.dimensions)===JSON.stringify(o)&&(t.width=r,i=!0)}i||u.value.push({dimensions:o,width:r})}else{const e=n.getBodyColumnDefine(t,0);e?.key&&s.value.set(e.key,r)}}))},m=()=>{if(!l.value)return;a.value&&a.value.release();const e=()=>void 0!==i.records&&null!==i.records&&i.records.length>0?i.records:i.options.records;try{switch(i.type){case"list":C(t.ListTable,{...i.options,records:e()});break;case"pivot":C(t.PivotTable,{...i.options,records:e()});break;case"chart":C(t.PivotChart,{...i.options,records:e()})}n=a.value,b.forEach((e=>{n.on(v[e],(t=>{h(e,t)}))})),i.onReady?.(a.value,!0)}catch(e){i.onError?.(e)}var n},y=e=>{if(a.value)try{if(i.keepColumnWidthChange){const t=function(e,t,n){if(n.isPivotTable())return t;const o=[];return e.forEach(((e,t)=>{o.push({key:t,width:e})})),o}(s.value,u.value,a.value);e={...e,columnWidthConfig:t,columnWidthConfigForRowHeader:t}}switch(i.type){case"list":a.value instanceof t.ListTable&&a.value.updateOption(e);break;case"pivot":a.value instanceof t.PivotTable&&a.value.updateOption(e);break;case"chart":a.value instanceof t.PivotChart&&a.value.updateOption(e)}}catch(e){i.onError?.(e)}};return n.onMounted(m),n.onBeforeUnmount((()=>{a.value?.release()})),n.watch((()=>i.options),((e,t)=>{a.value?y(e):m()})),n.watch((()=>i.records),((e,t)=>{a.value?y({...i.options,records:e}):m()}),{deep:!0}),(e,t)=>(n.openBlock(),n.createElementBlock("div",{ref_key:"vTableContainer",ref:l,style:n.normalizeStyle([{width:d.value,height:p.value},{position:"relative"}])},null,4))}}),O=n.defineComponent({__name:"list-table",props:{options:{type:Object,required:!0},records:{type:Array,required:!1},width:{type:[String,Number],required:!1},height:{type:[String,Number],required:!1}},setup(e,{expose:t}){const o=e,r=n.ref(null),i=n.useSlots(),l=n.computed((()=>{const e=function(e){const t={columns:[],tooltip:{},menu:{}},n={ListColumn:"columns",Tooltip:"tooltip",Menu:"menu"};return e.forEach((e=>{e.props=s(e.props);const o=e.type?.symbol||e.type?.name,r=n[o];r&&("columns"===r&&e.children&&(e.children.customLayout&&(e.props.customLayout=d(e.children)),e.children.headerCustomLayout&&(e.props.headerCustomLayout=d(e.children,!0)),C(e.props,e.children.edit)),Array.isArray(t[r])?t[r].push(e.props):t[r]=e.props)})),t}(u(i.default?.()||[]));return g(o.options,e)}));return t({vTableInstance:n.computed((()=>r.value?.vTableInstance||null))}),(e,t)=>(n.openBlock(),n.createElementBlock(n.Fragment,null,[n.createVNode(S,n.mergeProps({type:"list",options:l.value,records:e.records,width:e.width,height:e.height,ref_key:"baseTableRef",ref:r},e.$attrs),null,16,["options","records","width","height"]),n.renderSlot(e.$slots,"default")],64))}}),M=n.defineComponent({__name:"pivot-table",props:{options:{type:Object,required:!0},records:{type:Array,required:!1},width:{type:[String,Number],required:!1},height:{type:[String,Number],required:!1}},setup(e,{expose:t}){const o=e,r=n.shallowRef(null),i=n.useSlots(),l=n.computed((()=>{const e=f(u(i.default?.()||[]));return g(o.options,e)}));return t({vTableInstance:n.computed((()=>r.value?.vTableInstance||null))}),(e,t)=>(n.openBlock(),n.createElementBlock(n.Fragment,null,[n.createVNode(S,n.mergeProps({type:"pivot",options:l.value,records:e.records,width:e.width,height:e.height,ref_key:"baseTableRef",ref:r},e.$attrs),null,16,["options","records","width","height"]),n.renderSlot(e.$slots,"default")],64))}}),_=n.defineComponent({__name:"pivot-chart",props:{options:{type:Object,required:!0},records:{type:Array,required:!1},width:{type:[String,Number],required:!1},height:{type:[String,Number],required:!1}},setup(e,{expose:t}){const o=e,r=n.shallowRef(null),i=n.useSlots(),l=n.computed((()=>{const e=f(u(i.default?.()||[]));return g(o.options,e)}));return t({vTableInstance:n.computed((()=>r.value?.vTableInstance||null))}),(e,t)=>(n.openBlock(),n.createElementBlock(n.Fragment,null,[n.createVNode(S,n.mergeProps({type:"chart",options:l.value,records:e.records,width:e.width,height:e.height,ref_key:"baseTableRef",ref:r},e.$attrs),null,16,["options","records","width","height"]),n.renderSlot(e.$slots,"default")],64))}});function D(e){return null}function N(e){return null}function R(e){return null}function H(e){return null}function I(e){return null}function P(e){return null}function q(e){return null}function k(e){return null}function A(e){return null}function V(){return null}function B(){return null}function x(){return null}function F(e){return null}function U(e){return null}function j(e){return null}D.symbol="ListColumn",N.symbol="PivotColumnDimension",R.symbol="PivotRowDimension",H.symbol="PivotColumnHeaderTitle",I.symbol="PivotRowHeaderTitle",P.symbol="PivotIndicator",q.symbol="PivotCorner",k.symbol="Menu",A.symbol="Tooltip",V.symbol="Group",B.symbol="Image",x.symbol="Text",F.symbol="Tag",U.symbol="Radio",j.symbol="CheckBox";e.VTable=l,Object.defineProperty(e,"register",{enumerable:!0,get:function(){return t.register}}),e.CheckBox=j,e.Group=V,e.Image=B,e.ListColumn=D,e.ListTable=O,e.Menu=k,e.PivotChart=_,e.PivotColumnDimension=N,e.PivotColumnHeaderTitle=H,e.PivotCorner=q,e.PivotIndicator=P,e.PivotRowDimension=R,e.PivotRowHeaderTitle=I,e.PivotTable=M,e.Radio=U,e.Tag=F,e.Text=x,e.Tooltip=A,e.registerChartModule=(e,t)=>{l.register.chartModule(e,t)},e.version="1.17.3-alpha.9"}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@visactor/vtable"),require("vue"),require("@visactor/vutils"),require("@visactor/vtable/es/vrender")):"function"==typeof define&&define.amd?define(["exports","@visactor/vtable","vue","@visactor/vutils","@visactor/vtable/es/vrender"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VueVTable={},e.VTable,e.Vue,e.VUtils,e.VTable.vrender)}(this,(function(e,t,n,o,r){"use strict";function i(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var l=i(t);function a(e){return e.replace(/-([a-z])/g,(e=>e[1].toUpperCase()))}function s(e){const t={};for(const n in e)if(e.hasOwnProperty(n)){t[a(n)]=e[n]}return t}function u(e){return e.flatMap((e=>Array.isArray(e.children)?u(e.children):e))}function c(e,t,r){const i={Group:l.CustomLayout.Group,Image:l.CustomLayout.Image,Text:l.CustomLayout.Text,Tag:l.CustomLayout.Tag,Radio:l.CustomLayout.Radio,CheckBox:l.CustomLayout.CheckBox};return{rootComponent:function e(l){if(!l)return null;const{type:u,children:c}=l,d=s(l.props),p=i[u?.symbol||u?.name];if(!p)return null;const h=new p({...d});!function(e,t){Object.keys(t).forEach((n=>{if(function(e,t){return e.startsWith("on")&&o.isFunction(t[e])}(n,t)){let o;o=n.startsWith("on")?n.slice(2).toLowerCase():a(n.slice(2)).toLowerCase(),e.addEventListener(o,t[n])}}))}(h,d);const C=function(e){return e?.default?.()||e||[]}(c);if(o.isObject(d?.vue)){const{element:e}=d.vue,o=e??C.find((e=>e?.type!==Symbol.for("v-cmt")));return Object.assign(l.props.vue,{element:n.isVNode(o)?o:null,container:t?r?.table?.headerDomContainer:r?.table?.bodyDomContainer}),h}return C.forEach((t=>{const n=e(t);n?h.add(n):t.type===Symbol.for("v-fgt")&&t.children.forEach((t=>{const n=e(t);n&&h.add(n)}))})),h}(e)}}function d(e,t){return n=>{const{table:o,row:r,col:i,rect:l}=n,a=o.getCellOriginRecord(i,r),{height:s,width:u}=l??o.getCellRect(i,r),d=t?"headerCustomLayout":"customLayout";if(!e[d])return null;const p=e[d]({table:o,row:r,col:i,rect:l,record:a,height:s,width:u})[0],{rootComponent:h}=c(p,t,n);return{rootContainer:h,renderDefault:!1}}}class p{wrapContainer;tableContainer;currentValue;nodeMap;currentContext;constructor(e){this.currentContext=e,this.tableContainer=null,this.currentValue=null,this.wrapContainer=null,this.nodeMap=new Map}registerNode(e,t,n){o.isValid(e)&&o.isValid(t)&&"function"==typeof n&&(this.nodeMap.has(e)||this.nodeMap.set(e,new Map),this.nodeMap.get(e).set(t,n))}getNode(e,t){return this.nodeMap.get(e)?.get(t)}removeNode(e){this.nodeMap.delete(e)}release(e){o.isValid(e)?this.removeNode(e):this.nodeMap.clear()}async onStart(e){const{value:t}=e;this.setValue(t),await this.createElement(e)}async createElement(e){const{row:r,col:i,value:l,table:a,container:s,referencePosition:u}=e;if(!s)return!1;const c=a.getBodyColumnDefine(i,r),{editConfig:d}=c||{},{id:p}=a,h=this.getColumnKeyField(c);if(!o.isValid(h)||!o.isValid(p))return!1;if("function"==typeof d?.editBefore){if(!await d.editBefore(e))return a.showTooltip(i,r,{content:d.disablePrompt||"This field is not allowed to be edited",referencePosition:{rect:u?.rect,placement:t.TYPES.Placement.top},style:{bgColor:"black",color:"white",arrowMark:!0},disappearDelay:1e3}),!1}const C=this.getNode(p,h)?.({row:r,col:i,value:l,table:a,onChange:e=>this.setValue(e)})?.find((e=>e?.type!==Symbol.for("v-cmt")));if(!C||!n.isVNode(C))return!1;this.checkToPassAppContext(C,a);const m=document.createElement("div");m.style.position="absolute",m.style.width="100%",m.style.boxSizing="border-box";const{bgColor:y}=a.getCellStyle(i,r)||{};return m.style.backgroundColor=y||"#FFFFFF",this.wrapContainer=m,this.tableContainer=s,this.tableContainer.appendChild(m),n.render(C,m),u?.rect&&this.adjustPosition(u.rect),!0}checkToPassAppContext(e,t){try{const n=t.options?.customConfig?.getVueUserAppContext?.()??this.currentContext;n?.components&&n?.directives&&(e.appContext=n)}catch(e){}}getColumnKeyField(e){const{field:t,key:n}=e||{};return o.isValid(n)?n:t}getValue(){return this.currentValue}setValue(e){this.currentValue=e}adjustPosition(e){this.wrapContainer&&(this.wrapContainer.style.top=`${e.top}px`,this.wrapContainer.style.left=`${e.left}px`,this.wrapContainer.style.width=`${e.width}px`,this.wrapContainer.style.height=`${e.height}px`)}async validateValue(e,n,r,i){const{col:l,row:a}=r||{};if(!o.isValid(l)||!o.isValid(a))return!0;const s=i.getBodyColumnDefine(l,a),{editConfig:u}=s||{};if("function"==typeof u?.validateValue){const o=await u.validateValue({col:l,row:a,value:e,oldValue:n,table:i});if(!1===o){const e=i.getVisibleCellRangeRelativeRect({col:l,row:a});return i.showTooltip(l,a,{content:u.invalidPrompt||"invalid",referencePosition:{rect:e,placement:t.TYPES.Placement.top},style:{bgColor:"red",color:"white",arrowMark:!0},disappearDelay:1e3}),!1}return o}return!0}onEnd(){this.wrapContainer&&this.tableContainer&&(n.render(null,this.wrapContainer),this.tableContainer.removeChild(this.wrapContainer)),this.wrapContainer=null,this.tableContainer=null}isEditorElement(e){return this.wrapContainer?.contains(e)||this.isClickEditorElement(e)}isClickEditorElement(e){for(;e;){if(e.classList&&e.classList.contains("table-editor-element"))return!0;e=e.parentNode}return!1}}const h="dynamic-render-editor";function C(e,t){const{editor:n}=e||{},r=m(e);return!(!o.isValid(r)||n!==h)&&("function"==typeof t?(e.getEditCustomNode=t,!0):"function"==typeof e.getEditCustomNode)}function m(e){const{field:t,key:n}=e||{};return o.isValid(n)?n:t}function y(e,n){let o=t.register.editor(h);return!o&&e&&(o=new p(n),t.register.editor(h,o)),o}function f(e){const t={columns:[],columnHeaderTitle:[],rows:[],rowHeaderTitle:[],indicators:[],corner:{},tooltip:{},menu:{}},n={PivotColumnDimension:"columns",PivotColumnHeaderTitle:"columnHeaderTitle",PivotRowDimension:"rows",PivotRowHeaderTitle:"rowHeaderTitle",PivotCorner:"corner",PivotIndicator:"indicators",Tooltip:"tooltip",Menu:"menu"};return e.forEach((e=>{e.props=s(e.props);const o=e.type?.symbol||e.type?.name,r=n[o];r&&(Array.isArray(t[r])?e.props.hasOwnProperty("objectHandler")?t[r].push(e.props.objectHandler):t[r].push(e.props):t[r]=e.props)})),t}function g(e,t){return{...e,columns:t.columns&&t.columns.length?t.columns:e.columns,columnHeaderTitle:t.columnHeaderTitle&&t.columnHeaderTitle.length?t.columnHeaderTitle:e.columnHeaderTitle,rows:t.rows&&t.rows.length?t.rows:e.rows,rowHeaderTitle:t.rowHeaderTitle&&t.rowHeaderTitle.length?t.rowHeaderTitle:e.rowHeaderTitle,indicators:t.indicators&&t.indicators.length?t.indicators:e.indicators,corner:Object.keys(e.corner||{}).length?e.corner:t.corner,tooltip:Object.keys(t.tooltip||{}).length?t.tooltip:e.tooltip,menu:Object.keys(t.menu||{}).length?t.menu:e.menu}}const E={...t.ListTable.EVENT_TYPE,...t.PivotTable.EVENT_TYPE,...t.PivotChart.EVENT_TYPE},v={onClickCell:E.CLICK_CELL,onDblClickCell:E.DBLCLICK_CELL,onMouseDownCell:E.MOUSEDOWN_CELL,onMouseUpCell:E.MOUSEUP_CELL,onSelectedCell:E.SELECTED_CELL,onKeyDown:E.KEYDOWN,onMouseEnterTable:E.MOUSEENTER_TABLE,onMouseLeaveTable:E.MOUSELEAVE_TABLE,onMouseDownTable:E.MOUSEDOWN_TABLE,onMouseMoveCell:E.MOUSEMOVE_CELL,onMouseEnterCell:E.MOUSEENTER_CELL,onMouseLeaveCell:E.MOUSELEAVE_CELL,onContextMenuCell:E.CONTEXTMENU_CELL,onResizeColumn:E.RESIZE_COLUMN,onResizeColumnEnd:E.RESIZE_COLUMN_END,onChangeHeaderPosition:E.CHANGE_HEADER_POSITION,onChangeHeaderPositionStart:E.CHANGE_HEADER_POSITION_START,onChangeHeaderPositionFail:E.CHANGE_HEADER_POSITION_FAIL,onSortClick:E.SORT_CLICK,onFreezeClick:E.FREEZE_CLICK,onScroll:E.SCROLL,onDropdownMenuClick:E.DROPDOWN_MENU_CLICK,onMouseOverChartSymbol:E.MOUSEOVER_CHART_SYMBOL,onDragSelectEnd:E.DRAG_SELECT_END,onDropdownIconClick:E.DROPDOWN_ICON_CLICK,onDropdownMenuClear:E.DROPDOWN_MENU_CLEAR,onTreeHierarchyStateChange:E.TREE_HIERARCHY_STATE_CHANGE,onShowMenu:E.SHOW_MENU,onHideMenu:E.HIDE_MENU,onIconClick:E.ICON_CLICK,onLegendItemClick:E.LEGEND_ITEM_CLICK,onLegendItemHover:E.LEGEND_ITEM_HOVER,onLegendItemUnHover:E.LEGEND_ITEM_UNHOVER,onLegendChange:E.LEGEND_CHANGE,onMouseEnterAxis:E.MOUSEENTER_AXIS,onMouseLeaveAxis:E.MOUSELEAVE_AXIS,onCheckboxStateChange:E.CHECKBOX_STATE_CHANGE,onRadioStateChange:E.RADIO_STATE_CHANGE,onAfterRender:E.AFTER_RENDER,onInitialized:E.INITIALIZED,onPivotSortClick:E.PIVOT_SORT_CLICK,onDrillMenuClick:E.DRILLMENU_CLICK,onVChartEventType:E.VCHART_EVENT_TYPE,onChangeCellValue:E.CHANGE_CELL_VALUE,onMousedownFillHandle:E.MOUSEDOWN_FILL_HANDLE,onDragFillHandleEnd:E.DRAG_FILL_HANDLE_END,onDblclickFillHandle:E.DBLCLICK_FILL_HANDLE,onScrollVerticalEnd:E.SCROLL_VERTICAL_END,onScrollHorizontalEnd:E.SCROLL_HORIZONTAL_END,onChangCellValue:E.CHANGE_CELL_VALUE},b=Object.keys(v);function w(e,t){const r=n.getCurrentInstance(),i=n.computed((()=>{const t=e.options?.columns;return o.isArray(t)?t.filter((e=>!!o.isObject(e)&&!!C(e))):[]}));function l(){return t.value?.id}n.watchEffect((()=>{!function(){const e=l();if(!o.isValid(e))return;let t=y();t?t.removeNode(e):i.value.length>0&&(t=y(!0,r?.appContext));i.value.forEach((n=>{const{getEditCustomNode:o}=n,r=m(n);t.registerNode(e,r,o),delete n.editCustomNode}))}()})),n.onBeforeUnmount((()=>{!function(){const e=l();if(!o.isValid(e))return;const t=y();t?.release(e)}()}))}class T extends r.HtmlAttributePlugin{name="VTableVueAttributePlugin";renderQueue=new Set;isRendering=!1;currentContext;constructor(e){super(),this.currentContext=e}renderGraphicHTML(e){this.checkNeedRender(e)&&(this.renderQueue.add(e),this.scheduleRender())}scheduleRender(){this.isRendering||(this.isRendering=!0,requestAnimationFrame((()=>{this.renderQueue.forEach((e=>{try{this.doRenderGraphic(e)}catch(t){const{id:n}=this.getGraphicOptions(e)||{};this.removeElement(n,!0)}})),this.renderQueue.clear(),this.isRendering=!1})))}doRenderGraphic(e){const{id:t,options:o}=this.getGraphicOptions(e);if(!t)return;const r=e.stage,{element:i,container:l}=o,a=l?function(e){const{col:t,row:n,stage:o}=L(e);let r=e.attribute.vue?.container;const{table:i}=o;r===i.bodyDomContainer?t<i.frozenColCount&&n>=i.rowCount-i.bottomFrozenRowCount?r=i.bottomFrozenBodyDomContainer:t>=i.colCount-i.rightFrozenColCount&&n>=i.rowCount-i.bottomFrozenRowCount?r=i.rightFrozenBottomDomContainer:n>=i.rowCount-i.bottomFrozenRowCount?r=i.bottomFrozenBodyDomContainer:t<i.frozenColCount?r=i.frozenBodyDomContainer:t>=i.colCount-i.rightFrozenColCount&&(r=i.rightFrozenBodyDomContainer):r===i.headerDomContainer&&(t<i.frozenColCount?r=i.frozenHeaderDomContainer:t>=i.colCount-i.rightFrozenColCount&&(r=i.rightFrozenHeaderDomContainer));return r}(e):l;let s=this.htmlMap?.[t];if(s&&a&&a!==s.container&&(this.removeElement(t),s=null),this.checkToPassAppContext(i,e),s&&this.checkDom(s.wrapContainer))n.render(i,s.wrapContainer);else{const{wrapContainer:l,nativeContainer:u}=this.getWrapContainer(r,a,{id:t,options:o});if(l){const o=`${this.renderId}`;l.id=t,l.setAttribute("data-vue-renderId",o),n.render(i,l),s={wrapContainer:l,nativeContainer:u,container:a,renderId:this.renderId,graphic:e,isInViewport:!0,lastPosition:null,lastStyle:{}},this.htmlMap[t]=s}}s&&(this.updateStyleOfWrapContainer(e,r,s.wrapContainer,s.nativeContainer),s.renderId=this.renderId)}getGraphicOptions(e){const{vue:t}=e?.attribute||{};if(!t)return null;return{id:`vue_${o.isNil(t.id)?e.id??e._uid:t.id}`,options:t}}checkToPassAppContext(e,t){try{const{stage:n}=L(t),{table:o}=n||{},r=o?.options?.customConfig?.getVueUserAppContext?.()??this.currentContext;r?.components&&r?.directives&&(e.appContext=r)}catch(e){}}checkNeedRender(e){const{id:t,options:n}=this.getGraphicOptions(e)||{};if(!t)return!1;if(!e.stage)return!1;const{element:o}=n;if(!o)return!1;return this.checkInViewport(e)}checkInViewport(e){const{stage:t,globalAABBBounds:n}=e;if(!t)return!1;const o=100,{AABBBounds:r}=t,i=r.x1-o,l=r.x2+o,a=r.y1-o,s=r.y2+o;return n.x1<l&&n.x2>i&&n.y1<s&&n.y2>a}checkDom(e){return!!e&&document.contains(e)}removeAllDom(e){this.htmlMap&&(Object.keys(this.htmlMap).forEach((e=>{this.removeElement(e,!0)})),this.htmlMap=null)}removeElement(e,t){const o=this.htmlMap?.[e];if(!o)return;const{wrapContainer:r}=o;r&&(n.render(null,r),t?(this.checkDom(r)&&super.removeElement(e),delete this.htmlMap[e]):(r.remove(),o.isInViewport=!1),this.removeWrapContainerEventListener(r))}getWrapContainer(e,t,n){let o;o=t?"string"==typeof t?r.application.global.getElementById(t):t:e.window.getContainer();const{id:i}=n||{},l=this.htmlMap?.[i];if(l&&!l.isInViewport){const{wrapContainer:e}=l;return this.checkDom(e)||o.appendChild(e),{wrapContainer:e,nativeContainer:o}}return{wrapContainer:r.application.global.createDom({tagName:"div",parent:o}),nativeContainer:o}}updateStyleOfWrapContainer(e,t,n,i){const{attribute:l,type:a}=e,{vue:s,width:u,height:c,visible:d,display:p,...h}=l||{},{x:C,y:m}=this.calculatePosition(e,s.anchorType),{left:y,top:f}=this.calculateOffset(t,i,C,m),{id:g}=this.getGraphicOptions(e)||{},E=g?this.htmlMap[g]:null;if(!E)return;if(!(!E.lastPosition||E.lastPosition.x!==y||E.lastPosition.y!==f))return;const{pointerEvents:v,penetrateEventList:b=["wheel"]}=s,w=this.parseDefaultStyleFromGraphic(e),T=this.convertCellStyle(e);Object.assign(w,{overflow:"hidden",...T||{},...h||{},transform:`translate(${y}px, ${f}px)`,boxSizing:"border-box",display:!1!==d?p||"block":"none",pointerEvents:!0===v?"all":v||"none",position:"absolute"}),"none"!==w.pointerEvents&&(this.removeWrapContainerEventListener(n),o.uniqArray(b).forEach((e=>{"wheel"===e&&(n.addEventListener("wheel",this.onWheel),n.addEventListener("wheel",(e=>e.preventDefault()),!0))}))),"text"===a&&"position"===s.anchorType&&Object.assign(w,this.getTransformOfText(e)),this.applyUserStyles(s,w,{offsetX:y,offsetTop:f,graphic:e,wrapContainer:n});!o.isEqual(E.lastStyle,w)&&(r.application.global.updateDom(n,{width:u,height:c,style:w}),E.lastStyle=w)}convertCellStyle(e){const{col:t,row:n,stage:r}=L(e),i=r?.table?.getCellStyle(t,n);if(!o.isObject(i))return;const{lineHeight:l,padding:a,...s}=i;return{...s,padding:o.isArray(a)?a.map((e=>`${e}px`)).join(" "):a}}calculatePosition(e,t){const n=e.globalAABBBounds;if("position"===t||n.empty()){const t=e.globalTransMatrix;return{x:t.e,y:t.f}}return o.calculateAnchorOfBounds(n,t||"top-left")}calculateOffset(e,t,n,o){const i=r.application.global.getElementTopLeft(t,!1),l=e.window.getTopLeft(!1);return{left:n+l.left-i.left,top:o+l.top-i.top}}applyUserStyles(e,t,n){if(o.isFunction(e.style)){const o=e.style({top:n.offsetTop,left:n.offsetX,width:n.graphic.globalAABBBounds.width(),height:n.graphic.globalAABBBounds.height()},n.graphic,n.wrapContainer);Object.assign(t,o)}else o.isObject(e.style)?Object.assign(t,e.style):o.isString(e.style)&&Object.assign(t,o.styleStringToObject(e.style))}}function L(e){for(;e?.parent;){if("custom-container"===e.name)return e;e=e.parent}return{col:-1,row:-1,stage:null}}var S=n.defineComponent({__name:"base-table",props:{type:{type:String,required:!1},options:{type:null,required:!1},records:{type:Array,required:!1},width:{type:[Number,String],required:!1,default:"100%"},height:{type:[Number,String],required:!1,default:"100%"},onReady:{type:Function,required:!1},onError:{type:Function,required:!1},keepColumnWidthChange:{type:Boolean,required:!1},onClickCell:{type:null,required:!1},onDblClickCell:{type:null,required:!1},onMouseDownCell:{type:null,required:!1},onMouseUpCell:{type:null,required:!1},onSelectedCell:{type:null,required:!1},onKeyDown:{type:null,required:!1},onMouseEnterTable:{type:null,required:!1},onMouseLeaveTable:{type:null,required:!1},onMouseDownTable:{type:null,required:!1},onMouseMoveCell:{type:null,required:!1},onMouseEnterCell:{type:null,required:!1},onMouseLeaveCell:{type:null,required:!1},onContextMenuCell:{type:null,required:!1},onResizeColumn:{type:null,required:!1},onResizeColumnEnd:{type:null,required:!1},onChangeHeaderPosition:{type:null,required:!1},onChangeHeaderPositionStart:{type:null,required:!1},onChangeHeaderPositionFail:{type:null,required:!1},onSortClick:{type:null,required:!1},onFreezeClick:{type:null,required:!1},onScroll:{type:null,required:!1},onDropdownMenuClick:{type:null,required:!1},onMouseOverChartSymbol:{type:null,required:!1},onDragSelectEnd:{type:null,required:!1},onDropdownIconClick:{type:null,required:!1},onDropdownMenuClear:{type:null,required:!1},onTreeHierarchyStateChange:{type:null,required:!1},onShowMenu:{type:null,required:!1},onHideMenu:{type:null,required:!1},onIconClick:{type:null,required:!1},onLegendItemClick:{type:null,required:!1},onLegendItemHover:{type:null,required:!1},onLegendItemUnHover:{type:null,required:!1},onLegendChange:{type:null,required:!1},onMouseEnterAxis:{type:null,required:!1},onMouseLeaveAxis:{type:null,required:!1},onCheckboxStateChange:{type:null,required:!1},onRadioStateChange:{type:null,required:!1},onAfterRender:{type:null,required:!1},onInitialized:{type:null,required:!1},onPivotSortClick:{type:null,required:!1},onDrillMenuClick:{type:null,required:!1},onVChartEventType:{type:null,required:!1},onChangeCellValue:{type:null,required:!1},onMousedownFillHandle:{type:null,required:!1},onDragFillHandleEnd:{type:null,required:!1},onDblclickFillHandle:{type:null,required:!1},onScrollVerticalEnd:{type:null,required:!1},onScrollHorizontalEnd:{type:null,required:!1}},emits:b,setup(e,{expose:r,emit:i}){const l=e,a=n.ref(null),s=n.shallowRef(null),u=n.ref(new Map),c=n.ref([]),d=n.ref([]);w(l,s),function(e,t){const r=n.getCurrentInstance(),i=e?.options?.customConfig?.createReactContainer;n.watchEffect((()=>{if(!i)return;const e=t.value?.scenegraph?.stage?.pluginService;if(!e)return;const n=e.findPluginsByName("VTableVueAttributePlugin");if(o.isArray(n)&&n.length)return;const l=new T(r?.appContext);e.register(l)}))}(l,s),r({vTableInstance:s});const p=n.computed((()=>"number"==typeof l.width?`${l.width}px`:l.width)),h=n.computed((()=>"number"==typeof l.height?`${l.height}px`:l.height)),C=i,m=(e,t)=>{const n=new e(a.value,t);s.value=n,u.value.clear(),c.value=[],d.value=[],n.on("resize_column_end",(e=>{if(!l.keepColumnWidthChange)return;const{col:t,colWidths:o}=e,r=o[t];if(n.isPivotTable()){const e=n.getCellHeaderPaths(t,n.columnHeaderLevelCount);let o=null;o="rowHeader"===e.cellLocation?e.rowHeaderPaths:e.colHeaderPaths;let i=!1;for(let e=0;e<c.value.length;e++){const t=c.value[e];JSON.stringify(t.dimensions)===JSON.stringify(o)&&(t.width=r,i=!0)}i||c.value.push({dimensions:o,width:r})}else{const e=n.getBodyColumnDefine(t,0);e?.key&&u.value.set(e.key,r)}}))},y=()=>{if(!a.value)return;s.value&&s.value.release();const e=()=>void 0!==l.records&&null!==l.records&&l.records.length>0?l.records:l.options.records;try{switch(l.type){case"list":m(t.ListTable,{...l.options,records:e()});break;case"pivot":m(t.PivotTable,{...l.options,records:e()});break;case"chart":m(t.PivotChart,{...l.options,records:e()})}n=s.value,b.forEach((e=>{n.on(v[e],(t=>{C(e,t)}))})),l.onReady?.(s.value,!0)}catch(e){l.onError?.(e)}var n},f=e=>{if(s.value)try{if(l.keepColumnWidthChange){const t=function(e,t,n){if(n.isPivotTable())return t;const o=[];return e.forEach(((e,t)=>{o.push({key:t,width:e})})),o}(u.value,c.value,s.value);e={...e,columnWidthConfig:t,columnWidthConfigForRowHeader:t}}switch(l.type){case"list":s.value instanceof t.ListTable&&s.value.updateOption(e);break;case"pivot":s.value instanceof t.PivotTable&&s.value.updateOption(e);break;case"chart":s.value instanceof t.PivotChart&&s.value.updateOption(e)}}catch(e){l.onError?.(e)}};return n.onMounted(y),n.onBeforeUnmount((()=>{s.value?.release()})),n.watch((()=>l.options),((e,t)=>{s.value?f(e):y()})),n.watch((()=>l.records),((e,t)=>{s.value?f({...l.options,records:e}):y()}),{deep:!0}),(e,t)=>(n.openBlock(),n.createElementBlock("div",{ref_key:"vTableContainer",ref:a,style:n.normalizeStyle([{width:p.value,height:h.value},{position:"relative"}])},null,4))}}),O=n.defineComponent({__name:"list-table",props:{options:{type:Object,required:!0},records:{type:Array,required:!1},width:{type:[String,Number],required:!1},height:{type:[String,Number],required:!1}},setup(e,{expose:t}){const o=e,r=n.ref(null),i=n.useSlots(),l=n.computed((()=>{const e=function(e){const t={columns:[],tooltip:{},menu:{}},n={ListColumn:"columns",Tooltip:"tooltip",Menu:"menu"};return e.forEach((e=>{e.props=s(e.props);const o=e.type?.symbol||e.type?.name,r=n[o];r&&("columns"===r&&e.children&&(e.children.customLayout&&(e.props.customLayout=d(e.children)),e.children.headerCustomLayout&&(e.props.headerCustomLayout=d(e.children,!0)),C(e.props,e.children.edit)),Array.isArray(t[r])?t[r].push(e.props):t[r]=e.props)})),t}(u(i.default?.()||[]));return g(o.options,e)}));return t({vTableInstance:n.computed((()=>r.value?.vTableInstance||null))}),(e,t)=>(n.openBlock(),n.createElementBlock(n.Fragment,null,[n.createVNode(S,n.mergeProps({type:"list",options:l.value,records:e.records,width:e.width,height:e.height,ref_key:"baseTableRef",ref:r},e.$attrs),null,16,["options","records","width","height"]),n.renderSlot(e.$slots,"default")],64))}}),M=n.defineComponent({__name:"pivot-table",props:{options:{type:Object,required:!0},records:{type:Array,required:!1},width:{type:[String,Number],required:!1},height:{type:[String,Number],required:!1}},setup(e,{expose:t}){const o=e,r=n.shallowRef(null),i=n.useSlots(),l=n.computed((()=>{const e=f(u(i.default?.()||[]));return g(o.options,e)}));return t({vTableInstance:n.computed((()=>r.value?.vTableInstance||null))}),(e,t)=>(n.openBlock(),n.createElementBlock(n.Fragment,null,[n.createVNode(S,n.mergeProps({type:"pivot",options:l.value,records:e.records,width:e.width,height:e.height,ref_key:"baseTableRef",ref:r},e.$attrs),null,16,["options","records","width","height"]),n.renderSlot(e.$slots,"default")],64))}}),_=n.defineComponent({__name:"pivot-chart",props:{options:{type:Object,required:!0},records:{type:Array,required:!1},width:{type:[String,Number],required:!1},height:{type:[String,Number],required:!1}},setup(e,{expose:t}){const o=e,r=n.shallowRef(null),i=n.useSlots(),l=n.computed((()=>{const e=f(u(i.default?.()||[]));return g(o.options,e)}));return t({vTableInstance:n.computed((()=>r.value?.vTableInstance||null))}),(e,t)=>(n.openBlock(),n.createElementBlock(n.Fragment,null,[n.createVNode(S,n.mergeProps({type:"chart",options:l.value,records:e.records,width:e.width,height:e.height,ref_key:"baseTableRef",ref:r},e.$attrs),null,16,["options","records","width","height"]),n.renderSlot(e.$slots,"default")],64))}});function D(e){return null}function N(e){return null}function A(e){return null}function P(e){return null}function R(e){return null}function I(e){return null}function H(e){return null}function k(e){return null}function q(e){return null}function V(){return null}function x(){return null}function B(){return null}function F(e){return null}function U(e){return null}function j(e){return null}D.symbol="ListColumn",N.symbol="PivotColumnDimension",A.symbol="PivotRowDimension",P.symbol="PivotColumnHeaderTitle",R.symbol="PivotRowHeaderTitle",I.symbol="PivotIndicator",H.symbol="PivotCorner",k.symbol="Menu",q.symbol="Tooltip",V.symbol="Group",x.symbol="Image",B.symbol="Text",F.symbol="Tag",U.symbol="Radio",j.symbol="CheckBox";e.VTable=l,Object.defineProperty(e,"register",{enumerable:!0,get:function(){return t.register}}),e.CheckBox=j,e.Group=V,e.Image=x,e.ListColumn=D,e.ListTable=O,e.Menu=k,e.PivotChart=_,e.PivotColumnDimension=N,e.PivotColumnHeaderTitle=P,e.PivotCorner=H,e.PivotIndicator=I,e.PivotRowDimension=A,e.PivotRowHeaderTitle=R,e.PivotTable=M,e.Radio=U,e.Tag=F,e.Text=B,e.Tooltip=q,e.registerChartModule=(e,t)=>{l.register.chartModule(e,t)},e.version="1.17.3"}));
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { IGraphic, IPlugin, IStage } from '@visactor/vtable/es/vrender';
|
|
2
2
|
import { HtmlAttributePlugin } from '@visactor/vtable/es/vrender';
|
|
3
|
+
import type { VNode } from 'vue';
|
|
3
4
|
export declare class VTableVueAttributePlugin extends HtmlAttributePlugin implements IPlugin {
|
|
5
|
+
name: string;
|
|
4
6
|
htmlMap: Record<string, {
|
|
5
7
|
wrapContainer: HTMLElement;
|
|
6
8
|
nativeContainer: HTMLElement;
|
|
@@ -16,10 +18,13 @@ export declare class VTableVueAttributePlugin extends HtmlAttributePlugin implem
|
|
|
16
18
|
}>;
|
|
17
19
|
private renderQueue;
|
|
18
20
|
private isRendering;
|
|
21
|
+
currentContext?: any;
|
|
22
|
+
constructor(currentContext?: any);
|
|
19
23
|
renderGraphicHTML(graphic: IGraphic): void;
|
|
20
24
|
private scheduleRender;
|
|
21
25
|
doRenderGraphic(graphic: IGraphic): void;
|
|
22
26
|
private getGraphicOptions;
|
|
27
|
+
checkToPassAppContext(vnode: VNode, graphic: IGraphic): void;
|
|
23
28
|
checkNeedRender(graphic: IGraphic): boolean;
|
|
24
29
|
checkInViewport(graphic: IGraphic): boolean;
|
|
25
30
|
checkDom(dom: HTMLElement): boolean;
|
|
@@ -4,10 +4,12 @@ import { isNil, uniqArray, isEqual, isObject, isArray, calculateAnchorOfBounds,
|
|
|
4
4
|
import { render } from 'vue';
|
|
5
5
|
|
|
6
6
|
class VTableVueAttributePlugin extends HtmlAttributePlugin {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(
|
|
7
|
+
constructor(currentContext) {
|
|
8
|
+
super();
|
|
9
|
+
this.name = 'VTableVueAttributePlugin';
|
|
9
10
|
this.renderQueue = new Set();
|
|
10
11
|
this.isRendering = false;
|
|
12
|
+
this.currentContext = currentContext;
|
|
11
13
|
}
|
|
12
14
|
renderGraphicHTML(graphic) {
|
|
13
15
|
if (!this.checkNeedRender(graphic)) {
|
|
@@ -38,6 +40,9 @@ class VTableVueAttributePlugin extends HtmlAttributePlugin {
|
|
|
38
40
|
doRenderGraphic(graphic) {
|
|
39
41
|
var _a;
|
|
40
42
|
const { id, options } = this.getGraphicOptions(graphic);
|
|
43
|
+
if (!id) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
41
46
|
const stage = graphic.stage;
|
|
42
47
|
const { element, container: expectedContainer } = options;
|
|
43
48
|
const actualContainer = expectedContainer ? checkFrozenContainer(graphic) : expectedContainer;
|
|
@@ -46,9 +51,13 @@ class VTableVueAttributePlugin extends HtmlAttributePlugin {
|
|
|
46
51
|
this.removeElement(id);
|
|
47
52
|
targetMap = null;
|
|
48
53
|
}
|
|
54
|
+
this.checkToPassAppContext(element, graphic);
|
|
49
55
|
if (!targetMap || !this.checkDom(targetMap.wrapContainer)) {
|
|
50
56
|
const { wrapContainer, nativeContainer } = this.getWrapContainer(stage, actualContainer, { id, options });
|
|
51
57
|
if (wrapContainer) {
|
|
58
|
+
const dataRenderId = `${this.renderId}`;
|
|
59
|
+
wrapContainer.id = id;
|
|
60
|
+
wrapContainer.setAttribute('data-vue-renderId', dataRenderId);
|
|
52
61
|
render(element, wrapContainer);
|
|
53
62
|
targetMap = {
|
|
54
63
|
wrapContainer,
|
|
@@ -73,12 +82,24 @@ class VTableVueAttributePlugin extends HtmlAttributePlugin {
|
|
|
73
82
|
}
|
|
74
83
|
getGraphicOptions(graphic) {
|
|
75
84
|
var _a;
|
|
76
|
-
const { vue } = graphic.attribute;
|
|
85
|
+
const { vue } = (graphic === null || graphic === void 0 ? void 0 : graphic.attribute) || {};
|
|
77
86
|
if (!vue) {
|
|
78
87
|
return null;
|
|
79
88
|
}
|
|
80
|
-
const id = isNil(vue.id) ?
|
|
81
|
-
return { id
|
|
89
|
+
const id = isNil(vue.id) ? (_a = graphic.id) !== null && _a !== void 0 ? _a : graphic._uid : vue.id;
|
|
90
|
+
return { id: `vue_${id}`, options: vue };
|
|
91
|
+
}
|
|
92
|
+
checkToPassAppContext(vnode, graphic) {
|
|
93
|
+
var _a, _b, _c, _d;
|
|
94
|
+
try {
|
|
95
|
+
const { stage } = getTargetGroup(graphic);
|
|
96
|
+
const { table } = stage || {};
|
|
97
|
+
const userAppContext = (_d = (_c = (_b = (_a = table === null || table === void 0 ? void 0 : 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;
|
|
98
|
+
if (!!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.components) && !!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.directives)) {
|
|
99
|
+
vnode.appContext = userAppContext;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) { }
|
|
82
103
|
}
|
|
83
104
|
checkNeedRender(graphic) {
|
|
84
105
|
const { id, options } = this.getGraphicOptions(graphic) || {};
|
|
@@ -188,7 +209,7 @@ class VTableVueAttributePlugin extends HtmlAttributePlugin {
|
|
|
188
209
|
if (!positionChanged) {
|
|
189
210
|
return;
|
|
190
211
|
}
|
|
191
|
-
const { pointerEvents
|
|
212
|
+
const { pointerEvents, penetrateEventList = ['wheel'] } = options;
|
|
192
213
|
const calculateStyle = this.parseDefaultStyleFromGraphic(graphic);
|
|
193
214
|
const style = this.convertCellStyle(graphic);
|
|
194
215
|
Object.assign(calculateStyle, Object.assign(Object.assign(Object.assign({ overflow: 'hidden' }, (style || {})), (rest || {})), { transform: `translate(${offsetX}px, ${offsetTop}px)`, boxSizing: 'border-box', display: visible !== false ? display || 'block' : 'none', pointerEvents: pointerEvents === true ? 'all' : pointerEvents || 'none', position: 'absolute' }));
|
package/es/edit/editor.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { VNode } from 'vue';
|
|
1
2
|
export interface DynamicRenderEditorParams {
|
|
2
3
|
row: number;
|
|
3
4
|
col: number;
|
|
@@ -23,13 +24,15 @@ export declare class DynamicRenderEditor {
|
|
|
23
24
|
tableContainer: HTMLElement | null;
|
|
24
25
|
currentValue: string | null;
|
|
25
26
|
nodeMap?: Map<string | number, Map<string | number, (params: DynamicRenderEditorParams) => any>>;
|
|
26
|
-
|
|
27
|
+
currentContext?: any;
|
|
28
|
+
constructor(currentContext?: any);
|
|
27
29
|
registerNode(tableId?: string | number, key?: string | number, getNode?: () => (params: DynamicRenderEditorParams) => any): void;
|
|
28
30
|
getNode(tableId?: string | number, key?: string | number): (params: DynamicRenderEditorParams) => any;
|
|
29
31
|
removeNode(tableId: string | number): void;
|
|
30
32
|
release(tableId?: string | number): void;
|
|
31
33
|
onStart(editorContext: any): Promise<void>;
|
|
32
34
|
createElement(editorContext: any): Promise<boolean>;
|
|
35
|
+
checkToPassAppContext(vnode: VNode, table: any): void;
|
|
33
36
|
getColumnKeyField(column: any): any;
|
|
34
37
|
getValue(): string;
|
|
35
38
|
setValue(value: any): void;
|
package/es/edit/editor.js
CHANGED
|
@@ -4,7 +4,8 @@ import { isVNode, render } from 'vue';
|
|
|
4
4
|
import { TYPES } from '@visactor/vtable';
|
|
5
5
|
|
|
6
6
|
class DynamicRenderEditor {
|
|
7
|
-
constructor() {
|
|
7
|
+
constructor(currentContext) {
|
|
8
|
+
this.currentContext = currentContext;
|
|
8
9
|
this.tableContainer = null;
|
|
9
10
|
this.currentValue = null;
|
|
10
11
|
this.wrapContainer = null;
|
|
@@ -79,10 +80,11 @@ class DynamicRenderEditor {
|
|
|
79
80
|
value,
|
|
80
81
|
table,
|
|
81
82
|
onChange: (value) => this.setValue(value)
|
|
82
|
-
})) === null || _b === void 0 ? void 0 : _b
|
|
83
|
+
})) === null || _b === void 0 ? void 0 : _b.find((node) => (node === null || node === void 0 ? void 0 : node.type) !== Symbol.for('v-cmt'));
|
|
83
84
|
if (!vnode || !isVNode(vnode)) {
|
|
84
85
|
return false;
|
|
85
86
|
}
|
|
87
|
+
this.checkToPassAppContext(vnode, table);
|
|
86
88
|
const wrapContainer = document.createElement('div');
|
|
87
89
|
wrapContainer.style.position = 'absolute';
|
|
88
90
|
wrapContainer.style.width = '100%';
|
|
@@ -99,6 +101,16 @@ class DynamicRenderEditor {
|
|
|
99
101
|
return true;
|
|
100
102
|
});
|
|
101
103
|
}
|
|
104
|
+
checkToPassAppContext(vnode, table) {
|
|
105
|
+
var _a, _b, _c, _d;
|
|
106
|
+
try {
|
|
107
|
+
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;
|
|
108
|
+
if (!!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.components) && !!(userAppContext === null || userAppContext === void 0 ? void 0 : userAppContext.directives)) {
|
|
109
|
+
vnode.appContext = userAppContext;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (error) { }
|
|
113
|
+
}
|
|
102
114
|
getColumnKeyField(column) {
|
|
103
115
|
const { field, key } = column || {};
|
|
104
116
|
return isValid(key) ? key : field;
|
package/es/edit/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { DynamicRenderEditor } from './editor';
|
|
2
2
|
export declare function checkRenderEditor(column: any, getEditCustomNode?: any): boolean;
|
|
3
3
|
export declare function getRenderEditorColumnKeyField(column: any): any;
|
|
4
|
-
export declare function getRenderEditor(create?: boolean): DynamicRenderEditor;
|
|
4
|
+
export declare function getRenderEditor(create?: boolean, currentContext?: any): DynamicRenderEditor;
|
package/es/edit/util.js
CHANGED
|
@@ -19,10 +19,10 @@ function getRenderEditorColumnKeyField(column) {
|
|
|
19
19
|
const { field, key } = column || {};
|
|
20
20
|
return isValid(key) ? key : field;
|
|
21
21
|
}
|
|
22
|
-
function getRenderEditor(create) {
|
|
22
|
+
function getRenderEditor(create, currentContext) {
|
|
23
23
|
let renderEditor = register.editor(DYNAMIC_RENDER_EDITOR);
|
|
24
24
|
if (!renderEditor && !!create) {
|
|
25
|
-
renderEditor = new DynamicRenderEditor();
|
|
25
|
+
renderEditor = new DynamicRenderEditor(currentContext);
|
|
26
26
|
register.editor(DYNAMIC_RENDER_EDITOR, renderEditor);
|
|
27
27
|
}
|
|
28
28
|
return renderEditor;
|
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
import { watchEffect } from 'vue';
|
|
1
|
+
import { getCurrentInstance, watchEffect } from 'vue';
|
|
2
2
|
import { VTableVueAttributePlugin } from '../components/custom/vtable-vue-attribute-plugin.js';
|
|
3
|
+
import { isArray } from '@visactor/vutils';
|
|
3
4
|
|
|
4
5
|
function useCellRender(props, tableRef) {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const instance = getCurrentInstance();
|
|
8
|
+
const createReactContainer = (_b = (_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.customConfig) === null || _b === void 0 ? void 0 : _b.createReactContainer;
|
|
5
9
|
watchEffect(() => {
|
|
6
|
-
var _a, _b;
|
|
7
|
-
if (!
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
if (!createReactContainer) {
|
|
8
12
|
return;
|
|
9
13
|
}
|
|
10
|
-
|
|
14
|
+
const pluginService = (_c = (_b = (_a = tableRef.value) === null || _a === void 0 ? void 0 : _a.scenegraph) === null || _b === void 0 ? void 0 : _b.stage) === null || _c === void 0 ? void 0 : _c.pluginService;
|
|
15
|
+
if (!pluginService) {
|
|
11
16
|
return;
|
|
12
17
|
}
|
|
13
|
-
|
|
18
|
+
const exist = pluginService.findPluginsByName('VTableVueAttributePlugin');
|
|
19
|
+
if (isArray(exist) && !!exist.length) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const plugin = new VTableVueAttributePlugin(instance === null || instance === void 0 ? void 0 : instance.appContext);
|
|
23
|
+
pluginService.register(plugin);
|
|
14
24
|
});
|
|
15
25
|
}
|
|
16
26
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { computed, watchEffect, onBeforeUnmount } from 'vue';
|
|
1
|
+
import { getCurrentInstance, computed, watchEffect, onBeforeUnmount } from 'vue';
|
|
2
2
|
import { isArray, isObject, isValid } from '@visactor/vutils';
|
|
3
3
|
import 'tslib';
|
|
4
4
|
import '@visactor/vtable';
|
|
5
5
|
import { checkRenderEditor, getRenderEditor, getRenderEditorColumnKeyField } from '../edit/util.js';
|
|
6
6
|
|
|
7
7
|
function useEditorRender(props, tableRef) {
|
|
8
|
+
const instance = getCurrentInstance();
|
|
8
9
|
const validColumns = computed(() => {
|
|
9
10
|
var _a;
|
|
10
11
|
const columns = (_a = props.options) === null || _a === void 0 ? void 0 : _a.columns;
|
|
@@ -29,7 +30,7 @@ function useEditorRender(props, tableRef) {
|
|
|
29
30
|
renderEditor.removeNode(id);
|
|
30
31
|
}
|
|
31
32
|
else if (validColumns.value.length > 0) {
|
|
32
|
-
renderEditor = getRenderEditor(true);
|
|
33
|
+
renderEditor = getRenderEditor(true, instance === null || instance === void 0 ? void 0 : instance.appContext);
|
|
33
34
|
}
|
|
34
35
|
validColumns.value.forEach(column => {
|
|
35
36
|
const { getEditCustomNode } = column;
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -21,6 +21,6 @@ export { default as Tag } from './components/custom/tag.js';
|
|
|
21
21
|
export { default as Radio } from './components/custom/radio.js';
|
|
22
22
|
export { default as CheckBox } from './components/custom/checkBox.js';
|
|
23
23
|
|
|
24
|
-
const version = "1.17.3
|
|
24
|
+
const version = "1.17.3";
|
|
25
25
|
|
|
26
26
|
export { version };
|
|
@@ -32,7 +32,7 @@ function createCustomLayout(children, isHeader, args) {
|
|
|
32
32
|
const subChildren = resolveChildren(childChildren);
|
|
33
33
|
if (isObject(props === null || props === void 0 ? void 0 : props.vue)) {
|
|
34
34
|
const { element } = props.vue;
|
|
35
|
-
const targetVNode = element !== null && element !== void 0 ? element : subChildren
|
|
35
|
+
const targetVNode = element !== null && element !== void 0 ? element : subChildren.find(node => (node === null || node === void 0 ? void 0 : node.type) !== Symbol.for('v-cmt'));
|
|
36
36
|
Object.assign(child.props.vue, {
|
|
37
37
|
element: isVNode(targetVNode) ? targetVNode : null,
|
|
38
38
|
container: isHeader ? (_a = args === null || args === void 0 ? void 0 : args.table) === null || _a === void 0 ? void 0 : _a.headerDomContainer : (_b = args === null || args === void 0 ? void 0 : args.table) === null || _b === void 0 ? void 0 : _b.bodyDomContainer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/vue-vtable",
|
|
3
|
-
"version": "1.17.3
|
|
3
|
+
"version": "1.17.3",
|
|
4
4
|
"description": "The vue version of VTable",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@visactor/
|
|
47
|
-
"@visactor/
|
|
46
|
+
"@visactor/vutils": "~0.19.1",
|
|
47
|
+
"@visactor/vtable": "1.17.3"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@arco-design/web-vue": "^2.11.0",
|