@visactor/vtable-plugins 1.20.0-alpha.2 → 1.20.0-alpha.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/README.md +25 -0
- package/cjs/contextmenu/styles.js +1 -2
- package/cjs/contextmenu/types.js +2 -1
- package/cjs/gantt-export-image.d.ts +9 -2
- package/cjs/gantt-export-image.js +69 -25
- package/cjs/gantt-export-image.js.map +1 -1
- package/cjs/gantt-extensions.d.ts +1 -0
- package/cjs/gantt-extensions.js +21 -0
- package/cjs/gantt-extensions.js.map +1 -0
- package/cjs/table-carousel-animation.js +1 -2
- package/cjs/table-export/util/promise.js +1 -1
- package/cjs/table-export.js +2 -1
- package/dist/vtable-plugins.js +57 -23
- package/dist/vtable-plugins.min.js +10 -10
- package/es/contextmenu/styles.js +1 -2
- package/es/contextmenu/types.js +2 -1
- package/es/gantt-export-image.d.ts +9 -2
- package/es/gantt-export-image.js +44 -24
- package/es/gantt-export-image.js.map +1 -1
- package/es/gantt-extensions.d.ts +1 -0
- package/es/gantt-extensions.js +2 -0
- package/es/gantt-extensions.js.map +1 -0
- package/es/table-carousel-animation.js +1 -2
- package/es/table-export/util/promise.js +1 -1
- package/es/table-export.js +2 -1
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -20,6 +20,31 @@ VTable is not just a high-performance multidimensional data analysis table, but
|
|
|
20
20
|
|
|
21
21
|
# Usage
|
|
22
22
|
|
|
23
|
+
## 可选依赖
|
|
24
|
+
|
|
25
|
+
部分高级功能需要额外的依赖:
|
|
26
|
+
|
|
27
|
+
- **甘特图导出功能**:需要安装 `@visactor/vtable-gantt`
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @visactor/vtable-gantt
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
可以通过两种方式使用:
|
|
34
|
+
|
|
35
|
+
1. 直接从主包导入(推荐,自动处理依赖缺失情况):
|
|
36
|
+
```js
|
|
37
|
+
import { ExportGanttPlugin } from '@visactor/vtable-plugins';
|
|
38
|
+
|
|
39
|
+
const exportPlugin = new ExportGanttPlugin();
|
|
40
|
+
// 如果未安装甘特图依赖,会收到友好的警告信息
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
2. 从专用入口导入(明确表示需要额外依赖):
|
|
44
|
+
```js
|
|
45
|
+
import { ExportGanttPlugin } from '@visactor/vtable-plugins/gantt-extensions';
|
|
46
|
+
```
|
|
47
|
+
|
|
23
48
|
## Installation
|
|
24
49
|
|
|
25
50
|
[npm package](https://www.npmjs.com/package/@visactor/vtable-search)
|
|
@@ -191,5 +191,4 @@ exports.MENU_ITEM_SUBMENU_CLASS = "vtable-context-menu-item-submenu", exports.ME
|
|
|
191
191
|
fontSize: "12px"
|
|
192
192
|
}
|
|
193
193
|
}, exports.createElement = createElement, exports.applyStyles = applyStyles, exports.createIcon = createIcon,
|
|
194
|
-
exports.createNumberInputItem = createNumberInputItem;
|
|
195
|
-
//# sourceMappingURL=styles.js.map
|
|
194
|
+
exports.createNumberInputItem = createNumberInputItem;
|
package/cjs/contextmenu/types.js
CHANGED
|
@@ -119,4 +119,5 @@ exports.DEFAULT_BODY_MENU_ITEMS = [ DEFAULT_MENU_ITEMS[MenuKey.COPY], DEFAULT_ME
|
|
|
119
119
|
exports.DEFAULT_HEADER_MENU_ITEMS = [ DEFAULT_MENU_ITEMS[MenuKey.COPY], DEFAULT_MENU_ITEMS[MenuKey.CUT], DEFAULT_MENU_ITEMS[MenuKey.PASTE], "---", DEFAULT_MENU_ITEMS[MenuKey.INSERT_COLUMN_LEFT], DEFAULT_MENU_ITEMS[MenuKey.INSERT_COLUMN_RIGHT], DEFAULT_MENU_ITEMS[MenuKey.DELETE_COLUMN] ],
|
|
120
120
|
exports.DEFAULT_COLUMN_SERIES_MENU_ITEMS = [ DEFAULT_MENU_ITEMS[MenuKey.COPY], DEFAULT_MENU_ITEMS[MenuKey.CUT], DEFAULT_MENU_ITEMS[MenuKey.PASTE], "---", DEFAULT_MENU_ITEMS[MenuKey.INSERT_COLUMN_LEFT], DEFAULT_MENU_ITEMS[MenuKey.INSERT_COLUMN_RIGHT], DEFAULT_MENU_ITEMS[MenuKey.DELETE_COLUMN] ],
|
|
121
121
|
exports.DEFAULT_ROW_SERIES_MENU_ITEMS = [ DEFAULT_MENU_ITEMS[MenuKey.COPY], DEFAULT_MENU_ITEMS[MenuKey.CUT], DEFAULT_MENU_ITEMS[MenuKey.PASTE], "---", DEFAULT_MENU_ITEMS[MenuKey.INSERT_ROW_ABOVE], DEFAULT_MENU_ITEMS[MenuKey.INSERT_ROW_BELOW], DEFAULT_MENU_ITEMS[MenuKey.DELETE_ROW] ],
|
|
122
|
-
exports.DEFAULT_CORNER_SERIES_MENU_ITEMS = [ DEFAULT_MENU_ITEMS[MenuKey.COPY], DEFAULT_MENU_ITEMS[MenuKey.CUT], DEFAULT_MENU_ITEMS[MenuKey.PASTE] ];
|
|
122
|
+
exports.DEFAULT_CORNER_SERIES_MENU_ITEMS = [ DEFAULT_MENU_ITEMS[MenuKey.COPY], DEFAULT_MENU_ITEMS[MenuKey.CUT], DEFAULT_MENU_ITEMS[MenuKey.PASTE] ];
|
|
123
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
interface IGanttPlugin {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
run: (...args: any[]) => void;
|
|
5
|
+
release?: () => void;
|
|
6
|
+
}
|
|
2
7
|
export interface ExportOptions {
|
|
3
8
|
fileName?: string;
|
|
4
9
|
type?: 'png' | 'jpeg';
|
|
@@ -7,10 +12,11 @@ export interface ExportOptions {
|
|
|
7
12
|
scale?: number;
|
|
8
13
|
download?: boolean;
|
|
9
14
|
}
|
|
10
|
-
export declare class ExportGanttPlugin implements
|
|
15
|
+
export declare class ExportGanttPlugin implements IGanttPlugin {
|
|
11
16
|
id: string;
|
|
12
17
|
name: string;
|
|
13
18
|
private _gantt;
|
|
19
|
+
constructor();
|
|
14
20
|
run(...args: any[]): void;
|
|
15
21
|
exportToImage(options?: ExportOptions): Promise<string | undefined>;
|
|
16
22
|
exportToBase64(options?: Omit<ExportOptions, 'download'>): Promise<string | undefined>;
|
|
@@ -18,3 +24,4 @@ export declare class ExportGanttPlugin implements plugins.IGanttPlugin {
|
|
|
18
24
|
private finalizeExport;
|
|
19
25
|
release(): void;
|
|
20
26
|
}
|
|
27
|
+
export {};
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4
|
+
void 0 === k2 && (k2 = k);
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
|
|
7
|
+
enumerable: !0,
|
|
8
|
+
get: function() {
|
|
9
|
+
return m[k];
|
|
10
|
+
}
|
|
11
|
+
}), Object.defineProperty(o, k2, desc);
|
|
12
|
+
} : function(o, m, k, k2) {
|
|
13
|
+
void 0 === k2 && (k2 = k), o[k2] = m[k];
|
|
14
|
+
}), __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", {
|
|
16
|
+
enumerable: !0,
|
|
17
|
+
value: v
|
|
18
|
+
});
|
|
19
|
+
} : function(o, v) {
|
|
20
|
+
o.default = v;
|
|
21
|
+
}), __importStar = this && this.__importStar || function(mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (null != mod) for (var k in mod) "default" !== k && Object.prototype.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k);
|
|
25
|
+
return __setModuleDefault(result, mod), result;
|
|
26
|
+
}, __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
4
27
|
return new (P || (P = Promise))((function(resolve, reject) {
|
|
5
28
|
function fulfilled(value) {
|
|
6
29
|
try {
|
|
@@ -30,11 +53,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
30
53
|
value: !0
|
|
31
54
|
}), exports.ExportGanttPlugin = void 0;
|
|
32
55
|
|
|
33
|
-
const
|
|
56
|
+
const checkGanttDependency = () => {
|
|
57
|
+
try {
|
|
58
|
+
return require.resolve("@visactor/vtable-gantt"), !0;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return !1;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
34
63
|
|
|
35
64
|
class ExportGanttPlugin {
|
|
36
65
|
constructor() {
|
|
37
|
-
this.id = "gantt-export-helper", this.name = "Gantt Export Helper", this._gantt = null
|
|
66
|
+
this.id = "gantt-export-helper", this.name = "Gantt Export Helper", this._gantt = null,
|
|
67
|
+
checkGanttDependency();
|
|
38
68
|
}
|
|
39
69
|
run(...args) {
|
|
40
70
|
const ganttInstance = args[0];
|
|
@@ -43,6 +73,7 @@ class ExportGanttPlugin {
|
|
|
43
73
|
exportToImage(options = {}) {
|
|
44
74
|
var _a;
|
|
45
75
|
return __awaiter(this, void 0, void 0, (function*() {
|
|
76
|
+
if (!checkGanttDependency()) return;
|
|
46
77
|
if (!this._gantt) return;
|
|
47
78
|
const {fileName: fileName = "gantt-export", type: type = "png", quality: quality = 1, backgroundColor: backgroundColor = "#ffffff", scale: scale = window.devicePixelRatio || 1, download: download = !0} = options;
|
|
48
79
|
try {
|
|
@@ -75,29 +106,42 @@ class ExportGanttPlugin {
|
|
|
75
106
|
}
|
|
76
107
|
createFullSizeContainer(scale) {
|
|
77
108
|
var _a, _b, _c;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
109
|
+
return __awaiter(this, void 0, void 0, (function*() {
|
|
110
|
+
if (!this._gantt) throw new Error("ExportGanttPlugin: Gantt instance not available to create container.");
|
|
111
|
+
const tempContainer = document.createElement("div");
|
|
112
|
+
tempContainer.style.position = "fixed", tempContainer.style.left = "-9999px", tempContainer.style.overflow = "hidden",
|
|
113
|
+
tempContainer.style.width = `${window.innerWidth + 100}px`, tempContainer.style.height = `${window.innerHeight + 100}px`,
|
|
114
|
+
document.body.appendChild(tempContainer);
|
|
115
|
+
const clonedContainer = document.createElement("div"), totalWidth = this._gantt.taskListTableInstance.getAllColsWidth() + this._gantt.getAllDateColsWidth(), totalHeight = this._gantt.getAllRowsHeight();
|
|
116
|
+
clonedContainer.style.width = `${totalWidth}px`, clonedContainer.style.height = `${totalHeight}px`,
|
|
117
|
+
tempContainer.appendChild(clonedContainer);
|
|
118
|
+
try {
|
|
119
|
+
let GanttClass;
|
|
120
|
+
try {
|
|
121
|
+
if (GanttClass = (yield Promise.resolve().then((() => __importStar(require("@visactor/vtable-gantt"))))).Gantt,
|
|
122
|
+
!GanttClass) throw new Error("Gantt class not found in @visactor/vtable-gantt");
|
|
123
|
+
} catch (err) {
|
|
124
|
+
throw new Error("导出甘特图需要安装并正确加载 @visactor/vtable-gantt 依赖\n请执行: npm install @visactor/vtable-gantt");
|
|
125
|
+
}
|
|
126
|
+
const clonedGantt = new GanttClass(clonedContainer, Object.assign(Object.assign({}, this._gantt.options), {
|
|
127
|
+
records: this._gantt.records,
|
|
128
|
+
taskListTable: Object.assign(Object.assign({}, this._gantt.options.taskListTable), {
|
|
129
|
+
tableWidth: void 0,
|
|
130
|
+
minTableWidth: void 0,
|
|
131
|
+
maxTableWidth: void 0
|
|
132
|
+
}),
|
|
133
|
+
plugins: []
|
|
134
|
+
}));
|
|
135
|
+
return clonedGantt.setPixelRatio(scale), (null === (_a = clonedGantt.scenegraph) || void 0 === _a ? void 0 : _a.ganttGroup) && clonedGantt.scenegraph.ganttGroup.setAttribute("clip", !1),
|
|
136
|
+
(null === (_c = null === (_b = clonedGantt.taskListTableInstance) || void 0 === _b ? void 0 : _b.scenegraph) || void 0 === _c ? void 0 : _c.tableGroup) && clonedGantt.taskListTableInstance.scenegraph.tableGroup.setAttribute("clip", !1),
|
|
137
|
+
clonedGantt.scenegraph.stage.render(), {
|
|
138
|
+
tempContainer: tempContainer,
|
|
139
|
+
clonedGantt: clonedGantt
|
|
140
|
+
};
|
|
141
|
+
} catch (err) {
|
|
142
|
+
throw tempContainer && tempContainer.parentNode && tempContainer.remove(), new Error("导出甘特图需要安装 @visactor/vtable-gantt 依赖");
|
|
143
|
+
}
|
|
94
144
|
}));
|
|
95
|
-
return clonedGantt.setPixelRatio(scale), (null === (_a = clonedGantt.scenegraph) || void 0 === _a ? void 0 : _a.ganttGroup) && clonedGantt.scenegraph.ganttGroup.setAttribute("clip", !1),
|
|
96
|
-
(null === (_c = null === (_b = clonedGantt.taskListTableInstance) || void 0 === _b ? void 0 : _b.scenegraph) || void 0 === _c ? void 0 : _c.tableGroup) && clonedGantt.taskListTableInstance.scenegraph.tableGroup.setAttribute("clip", !1),
|
|
97
|
-
clonedGantt.scenegraph.stage.render(), {
|
|
98
|
-
tempContainer: tempContainer,
|
|
99
|
-
clonedGantt: clonedGantt
|
|
100
|
-
};
|
|
101
145
|
}
|
|
102
146
|
finalizeExport(canvas, fileName, type, quality, download = !0) {
|
|
103
147
|
const base64 = canvas.toDataURL(`image/${type}`, quality);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/gantt-export-image.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yDAA+C;AAgB/C,MAAa,iBAAiB;IAA9B;QACE,OAAE,GAAW,qBAAqB,CAAC;QACnC,SAAI,GAAG,qBAAqB,CAAC;QACrB,WAAM,GAAiB,IAAI,CAAC;IAyLtC,CAAC;IAtLC,GAAG,CAAC,GAAG,IAAW;QAChB,MAAM,aAAa,GAAG,IAAI,CAAC,CAAC,CAAU,CAAC;QACvC,IAAI,CAAC,aA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,CAAC,GAAG,CAAC,CAAC;YACzC,IAAI,CAAC,QAAQ,GAAG,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;YACtC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;YACnB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAChC,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SACjC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO;QACL,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;CACF;AA5LD,8CA4LC","file":"gantt-export-image.js","sourcesContent":["import type { plugins } from '@visactor/vtable-gantt';\r\nimport { Gantt } from '@visactor/vtable-gantt';\r\n\r\n// 甘特图导出配置项接口\r\nexport interface ExportOptions {\r\n fileName?: string;\r\n type?: 'png' | 'jpeg';\r\n quality?: number;\r\n backgroundColor?: string;\r\n scale?: number;\r\n download?: boolean;\r\n}\r\n\r\n/**\r\n * 甘特图导出插件\r\n * @description 提供完整的甘特图导出功能,支持高分辨率输出和精准布局保留\r\n */\r\nexport class ExportGanttPlugin implements plugins.IGanttPlugin {\r\n id: string = `gantt-export-helper`;\r\n name = 'Gantt Export Helper';\r\n private _gantt: Gantt | null = null;\r\n\r\n // run 方法,在插件初始化时由 PluginManager调用\r\n run(...args: any[]): void {\r\n const ganttInstance = args[0] as Gantt;\r\n if (!ganttInstance) {\r\n console.error('ExportGanttPlugin: Gantt instance not provided to run method.');\r\n return;\r\n }\r\n this._gantt = ganttInstance;\r\n }\r\n /**\r\n * 执行甘特图导出操作\r\n * @async\r\n * @param {ExportOptions} [options={}] 导出配置选项\r\n * @returns {Promise<string | undefined>} 返回Base64格式的图片数据,或在未初始化时返回 undefined\r\n * @throws {Error} 导出过程中发生错误时抛出异常\r\n */\r\n async exportToImage(options: ExportOptions = {}): Promise<string | undefined> {\r\n if (!this._gantt) {\r\n // 保留这个 error\r\n console.error('ExportGanttPlugin: Gantt instance not available.');\r\n return undefined;\r\n }\r\n\r\n const {\r\n fileName = 'gantt-export',\r\n type = 'png',\r\n quality = 1,\r\n backgroundColor = '#ffffff',\r\n scale = window.devicePixelRatio || 1,\r\n download = true // 默认执行下载\r\n } = options;\r\n\r\n try {\r\n const { tempContainer, clonedGantt } = this.createFullSizeContainer(scale);\r\n\r\n try {\r\n await new Promise(resolve => requestAnimationFrame(resolve));\r\n\r\n const totalWidth =\r\n (clonedGantt.taskListTableInstance.getAllColsWidth() + clonedGantt.getAllDateColsWidth()) * scale;\r\n const totalHeight = clonedGantt.getAllRowsHeight() * scale;\r\n\r\n const exportCanvas = document.createElement('canvas');\r\n exportCanvas.width = totalWidth;\r\n exportCanvas.height = totalHeight;\r\n const ctx = exportCanvas.getContext('2d')!;\r\n\r\n ctx.fillStyle = backgroundColor;\r\n ctx.fillRect(0, 0, totalWidth, totalHeight);\r\n\r\n if (clonedGantt.taskListTableInstance?.canvas) {\r\n ctx.drawImage(\r\n clonedGantt.taskListTableInstance.canvas,\r\n 0,\r\n 0,\r\n clonedGantt.taskListTableInstance.getAllColsWidth() * scale,\r\n totalHeight\r\n );\r\n }\r\n\r\n const splitLineWidth = 3 * scale;\r\n const splitLineX = clonedGantt.taskListTableInstance.getAllColsWidth() * scale;\r\n ctx.fillStyle = 'rgb(225, 228, 232)';\r\n ctx.fillRect(splitLineX - splitLineWidth / 2, 0, splitLineWidth, totalHeight);\r\n\r\n const sourceX = 4 * scale;\r\n const sourceWidth = clonedGantt.canvas.width - sourceX;\r\n\r\n if (clonedGantt.canvas) {\r\n ctx.drawImage(\r\n clonedGantt.canvas,\r\n sourceX,\r\n 0,\r\n sourceWidth,\r\n clonedGantt.canvas.height,\r\n (clonedGantt.taskListTableInstance.getAllColsWidth() + 1.5) * scale,\r\n 0,\r\n (clonedGantt.getAllDateColsWidth() - 1.5) * scale,\r\n totalHeight\r\n );\r\n }\r\n\r\n return this.finalizeExport(exportCanvas, fileName, type, quality, download);\r\n } finally {\r\n tempContainer.remove();\r\n // 确保克隆的甘特图实例被释放\r\n clonedGantt.release();\r\n }\r\n } catch (error) {\r\n console.error('[Gantt Export Plugin] Export failed:', error);\r\n throw new Error(`甘特图导出失败: ${error instanceof Error ? error.message : '未知错误'}`);\r\n }\r\n }\r\n\r\n /**\r\n * 获取甘特图的 Base64 图片数据,不触发下载\r\n * @async\r\n * @param {Omit<ExportOptions, 'download'>} [options={}] 导出配置选项(不包含 download 参数)\r\n * @returns {Promise<string | undefined>} 返回 Base64 格式的图片数据,或在未初始化时返回 undefined\r\n * @throws {Error} 导出过程中发生错误时抛出异常\r\n */\r\n async exportToBase64(options: Omit<ExportOptions, 'download'> = {}): Promise<string | undefined> {\r\n // 调用 exportToImage 方法,但设置 download 为 false\r\n return this.exportToImage({\r\n ...options,\r\n download: false\r\n });\r\n }\r\n\r\n private createFullSizeContainer(scale: number) {\r\n if (!this._gantt) {\r\n // 保留这个 error\r\n throw new Error('ExportGanttPlugin: Gantt instance not available to create container.');\r\n }\r\n\r\n const tempContainer = document.createElement('div');\r\n tempContainer.style.position = 'fixed';\r\n tempContainer.style.left = '-9999px';\r\n tempContainer.style.overflow = 'hidden';\r\n tempContainer.style.width = `${window.innerWidth + 100}px`;\r\n tempContainer.style.height = `${window.innerHeight + 100}px`;\r\n document.body.appendChild(tempContainer);\r\n\r\n const clonedContainer = document.createElement('div');\r\n\r\n const totalWidth = this._gantt.taskListTableInstance.getAllColsWidth() + this._gantt.getAllDateColsWidth();\r\n const totalHeight = this._gantt.getAllRowsHeight();\r\n\r\n clonedContainer.style.width = `${totalWidth}px`;\r\n clonedContainer.style.height = `${totalHeight}px`;\r\n tempContainer.appendChild(clonedContainer);\r\n\r\n const clonedGantt = new Gantt(clonedContainer, {\r\n ...this._gantt.options,\r\n records: this._gantt.records,\r\n taskListTable: {\r\n ...this._gantt.options.taskListTable,\r\n tableWidth: undefined as unknown as number,\r\n minTableWidth: undefined as unknown as number,\r\n maxTableWidth: undefined as unknown as number\r\n },\r\n plugins: []\r\n });\r\n\r\n clonedGantt.setPixelRatio(scale);\r\n\r\n // 禁用裁剪\r\n if ((clonedGantt as any).scenegraph?.ganttGroup) {\r\n (clonedGantt as any).scenegraph.ganttGroup.setAttribute('clip', false);\r\n }\r\n if ((clonedGantt.taskListTableInstance as any)?.scenegraph?.tableGroup) {\r\n (clonedGantt.taskListTableInstance as any).scenegraph.tableGroup.setAttribute('clip', false);\r\n }\r\n\r\n clonedGantt.scenegraph.stage.render();\r\n\r\n return { tempContainer, clonedGantt };\r\n }\r\n private finalizeExport(\r\n canvas: HTMLCanvasElement,\r\n fileName: string,\r\n type: string,\r\n quality: number,\r\n download: boolean = true\r\n ): string {\r\n const base64 = canvas.toDataURL(`image/${type}`, quality);\r\n\r\n // 如果需要下载,则创建下载链接\r\n if (download) {\r\n const link = document.createElement('a');\r\n link.download = `${fileName}.${type}`;\r\n link.href = base64;\r\n document.body.appendChild(link);\r\n link.click();\r\n document.body.removeChild(link);\r\n }\r\n\r\n return base64;\r\n }\r\n\r\n release(): void {\r\n this._gantt = null;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/gantt-export-image.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,oBAAoB,GAAG,GAAG,EAAE;IAChC,IAAI;QAEF,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,IAAI,CACV,4DAA4D;YAC1D,2CAA2C;YAC3C,uCAAuC,CAC1C,CAAC;QACF,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC;AAMF,MAAa,iBAAiB;IAK5B;QAJA,OAAE,GAAW,qBAAqB,CAAC;QACnC,SAAI,GAAG,qBAAqB,CAAC;QACrB,WAAM,GAAiB,IAAI,CAAC;QAIlC,oBAAoB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AAC;IACrB,CAAC;CACF;AA9ND,8CA8NC","file":"gantt-export-image.js","sourcesContent":["/**\r\n * 这个文件提供了甘特图导出功能,但使用了懒加载方式避免强制依赖\r\n * 只有在实际使用时才会尝试加载 @visactor/vtable-gantt\r\n */\r\n\r\n// 使用类型声明而不是直接导入,避免静态依赖\r\ntype Gantt = any;\r\ninterface IGanttPlugin {\r\n id: string;\r\n name: string;\r\n run: (...args: any[]) => void;\r\n release?: () => void;\r\n}\r\n\r\n// 甘特图导出配置项接口\r\nexport interface ExportOptions {\r\n fileName?: string;\r\n type?: 'png' | 'jpeg';\r\n quality?: number;\r\n backgroundColor?: string;\r\n scale?: number;\r\n download?: boolean;\r\n}\r\n\r\n// 检查依赖是否可用\r\nconst checkGanttDependency = () => {\r\n try {\r\n // 不实际导入,只检查是否可用\r\n require.resolve('@visactor/vtable-gantt');\r\n return true;\r\n } catch (e) {\r\n console.warn(\r\n '警告: 使用 ExportGanttPlugin 需要安装 @visactor/vtable-gantt 依赖。\\n' +\r\n '请执行: npm install @visactor/vtable-gantt\\n' +\r\n '更多信息请参考文档: https://visactor.io/vtable'\r\n );\r\n return false;\r\n }\r\n};\r\n\r\n/**\r\n * 甘特图导出插件\r\n * @description 提供完整的甘特图导出功能,支持高分辨率输出和精准布局保留\r\n */\r\nexport class ExportGanttPlugin implements IGanttPlugin {\r\n id: string = `gantt-export-helper`;\r\n name = 'Gantt Export Helper';\r\n private _gantt: Gantt | null = null;\r\n\r\n constructor() {\r\n // 构造时提前检查依赖可用性,以便给开发者更早的反馈\r\n checkGanttDependency();\r\n }\r\n\r\n // run 方法,在插件初始化时由 PluginManager调用\r\n run(...args: any[]): void {\r\n const ganttInstance = args[0] as Gantt;\r\n if (!ganttInstance) {\r\n console.error('ExportGanttPlugin: Gantt instance not provided to run method.');\r\n return;\r\n }\r\n this._gantt = ganttInstance;\r\n }\r\n /**\r\n * 执行甘特图导出操作\r\n * @async\r\n * @param {ExportOptions} [options={}] 导出配置选项\r\n * @returns {Promise<string | undefined>} 返回Base64格式的图片数据,或在未初始化时返回 undefined\r\n * @throws {Error} 导出过程中发生错误时抛出异常\r\n */\r\n async exportToImage(options: ExportOptions = {}): Promise<string | undefined> {\r\n // 初始检查依赖是否存在\r\n if (!checkGanttDependency()) {\r\n return undefined;\r\n }\r\n\r\n if (!this._gantt) {\r\n // 保留这个 error\r\n console.error('ExportGanttPlugin: Gantt instance not available.');\r\n return undefined;\r\n }\r\n\r\n const {\r\n fileName = 'gantt-export',\r\n type = 'png',\r\n quality = 1,\r\n backgroundColor = '#ffffff',\r\n scale = window.devicePixelRatio || 1,\r\n download = true // 默认执行下载\r\n } = options;\r\n\r\n try {\r\n const { tempContainer, clonedGantt } = this.createFullSizeContainer(scale);\r\n\r\n try {\r\n await new Promise(resolve => requestAnimationFrame(resolve));\r\n\r\n const totalWidth =\r\n (clonedGantt.taskListTableInstance.getAllColsWidth() + clonedGantt.getAllDateColsWidth()) * scale;\r\n const totalHeight = clonedGantt.getAllRowsHeight() * scale;\r\n\r\n const exportCanvas = document.createElement('canvas');\r\n exportCanvas.width = totalWidth;\r\n exportCanvas.height = totalHeight;\r\n const ctx = exportCanvas.getContext('2d')!;\r\n\r\n ctx.fillStyle = backgroundColor;\r\n ctx.fillRect(0, 0, totalWidth, totalHeight);\r\n\r\n if (clonedGantt.taskListTableInstance?.canvas) {\r\n ctx.drawImage(\r\n clonedGantt.taskListTableInstance.canvas,\r\n 0,\r\n 0,\r\n clonedGantt.taskListTableInstance.getAllColsWidth() * scale,\r\n totalHeight\r\n );\r\n }\r\n\r\n const splitLineWidth = 3 * scale;\r\n const splitLineX = clonedGantt.taskListTableInstance.getAllColsWidth() * scale;\r\n ctx.fillStyle = 'rgb(225, 228, 232)';\r\n ctx.fillRect(splitLineX - splitLineWidth / 2, 0, splitLineWidth, totalHeight);\r\n\r\n const sourceX = 4 * scale;\r\n const sourceWidth = clonedGantt.canvas.width - sourceX;\r\n\r\n if (clonedGantt.canvas) {\r\n ctx.drawImage(\r\n clonedGantt.canvas,\r\n sourceX,\r\n 0,\r\n sourceWidth,\r\n clonedGantt.canvas.height,\r\n (clonedGantt.taskListTableInstance.getAllColsWidth() + 1.5) * scale,\r\n 0,\r\n (clonedGantt.getAllDateColsWidth() - 1.5) * scale,\r\n totalHeight\r\n );\r\n }\r\n\r\n return this.finalizeExport(exportCanvas, fileName, type, quality, download);\r\n } finally {\r\n tempContainer.remove();\r\n // 确保克隆的甘特图实例被释放\r\n clonedGantt.release();\r\n }\r\n } catch (error) {\r\n console.error('[Gantt Export Plugin] Export failed:', error);\r\n throw new Error(`甘特图导出失败: ${error instanceof Error ? error.message : '未知错误'}`);\r\n }\r\n }\r\n\r\n /**\r\n * 获取甘特图的 Base64 图片数据,不触发下载\r\n * @async\r\n * @param {Omit<ExportOptions, 'download'>} [options={}] 导出配置选项(不包含 download 参数)\r\n * @returns {Promise<string | undefined>} 返回 Base64 格式的图片数据,或在未初始化时返回 undefined\r\n * @throws {Error} 导出过程中发生错误时抛出异常\r\n */\r\n async exportToBase64(options: Omit<ExportOptions, 'download'> = {}): Promise<string | undefined> {\r\n // 调用 exportToImage 方法,但设置 download 为 false\r\n return this.exportToImage({\r\n ...options,\r\n download: false\r\n });\r\n }\r\n\r\n private async createFullSizeContainer(scale: number) {\r\n if (!this._gantt) {\r\n // 保留这个 error\r\n throw new Error('ExportGanttPlugin: Gantt instance not available to create container.');\r\n }\r\n\r\n const tempContainer = document.createElement('div');\r\n tempContainer.style.position = 'fixed';\r\n tempContainer.style.left = '-9999px';\r\n tempContainer.style.overflow = 'hidden';\r\n tempContainer.style.width = `${window.innerWidth + 100}px`;\r\n tempContainer.style.height = `${window.innerHeight + 100}px`;\r\n document.body.appendChild(tempContainer);\r\n\r\n const clonedContainer = document.createElement('div');\r\n\r\n const totalWidth = this._gantt.taskListTableInstance.getAllColsWidth() + this._gantt.getAllDateColsWidth();\r\n const totalHeight = this._gantt.getAllRowsHeight();\r\n\r\n clonedContainer.style.width = `${totalWidth}px`;\r\n clonedContainer.style.height = `${totalHeight}px`;\r\n tempContainer.appendChild(clonedContainer);\r\n\r\n try {\r\n // 动态导入甘特图组件\r\n let GanttClass;\r\n try {\r\n const module = await import('@visactor/vtable-gantt');\r\n GanttClass = module.Gantt;\r\n if (!GanttClass) {\r\n throw new Error('Gantt class not found in @visactor/vtable-gantt');\r\n }\r\n } catch (err) {\r\n console.error('无法加载甘特图组件:', err);\r\n throw new Error(\r\n '导出甘特图需要安装并正确加载 @visactor/vtable-gantt 依赖\\n' + '请执行: npm install @visactor/vtable-gantt'\r\n );\r\n }\r\n\r\n const clonedGantt = new GanttClass(clonedContainer, {\r\n ...this._gantt.options,\r\n records: this._gantt.records,\r\n taskListTable: {\r\n ...this._gantt.options.taskListTable,\r\n tableWidth: undefined as unknown as number,\r\n minTableWidth: undefined as unknown as number,\r\n maxTableWidth: undefined as unknown as number\r\n },\r\n plugins: []\r\n });\r\n\r\n clonedGantt.setPixelRatio(scale);\r\n\r\n // 禁用裁剪\r\n if ((clonedGantt as any).scenegraph?.ganttGroup) {\r\n (clonedGantt as any).scenegraph.ganttGroup.setAttribute('clip', false);\r\n }\r\n if ((clonedGantt.taskListTableInstance as any)?.scenegraph?.tableGroup) {\r\n (clonedGantt.taskListTableInstance as any).scenegraph.tableGroup.setAttribute('clip', false);\r\n }\r\n\r\n clonedGantt.scenegraph.stage.render();\r\n\r\n return { tempContainer, clonedGantt };\r\n } catch (err) {\r\n // 清理创建的DOM元素\r\n if (tempContainer && tempContainer.parentNode) {\r\n tempContainer.remove();\r\n }\r\n console.error('无法导入甘特图组件,请确保已安装 @visactor/vtable-gantt 依赖', err);\r\n throw new Error('导出甘特图需要安装 @visactor/vtable-gantt 依赖');\r\n }\r\n }\r\n private finalizeExport(\r\n canvas: HTMLCanvasElement,\r\n fileName: string,\r\n type: string,\r\n quality: number,\r\n download: boolean = true\r\n ): string {\r\n const base64 = canvas.toDataURL(`image/${type}`, quality);\r\n\r\n // 如果需要下载,则创建下载链接\r\n if (download) {\r\n const link = document.createElement('a');\r\n link.download = `${fileName}.${type}`;\r\n link.href = base64;\r\n document.body.appendChild(link);\r\n link.click();\r\n document.body.removeChild(link);\r\n }\r\n\r\n return base64;\r\n }\r\n\r\n release(): void {\r\n this._gantt = null;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './gantt-export-image';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4
|
+
void 0 === k2 && (k2 = k);
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
|
|
7
|
+
enumerable: !0,
|
|
8
|
+
get: function() {
|
|
9
|
+
return m[k];
|
|
10
|
+
}
|
|
11
|
+
}), Object.defineProperty(o, k2, desc);
|
|
12
|
+
} : function(o, m, k, k2) {
|
|
13
|
+
void 0 === k2 && (k2 = k), o[k2] = m[k];
|
|
14
|
+
}), __exportStar = this && this.__exportStar || function(m, exports) {
|
|
15
|
+
for (var p in m) "default" === p || Object.prototype.hasOwnProperty.call(exports, p) || __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Object.defineProperty(exports, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), __exportStar(require("./gantt-export-image"), exports);
|
|
21
|
+
//# sourceMappingURL=gantt-extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gantt-extensions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAKA,uDAAqC","file":"gantt-extensions.js","sourcesContent":["/**\n * 甘特图相关的插件功能集合\n * 注意:使用这些功能需要额外安装 @visactor/vtable-gantt 依赖\n */\n\nexport * from './gantt-export-image';\n"]}
|
package/cjs/table-export.js
CHANGED
package/dist/vtable-plugins.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@visactor/vtable'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@visactor/vtable', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.VTable = global.VTable || {}, global.VTable.plugins = {}), global.VTable, global.
|
|
5
|
-
})(this, (function (exports, VTable,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@visactor/vtable'), require('crypto'), require('fs'), require('stream'), require('events'), require('buffer'), require('util'), require('string_decoder'), require('path'), require('constants'), require('assert'), require('zlib'), require('os')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@visactor/vtable', 'crypto', 'fs', 'stream', 'events', 'buffer', 'util', 'string_decoder', 'path', 'constants', 'assert', 'zlib', 'os'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.VTable = global.VTable || {}, global.VTable.plugins = {}), global.VTable, global.require$$0$1, global.require$$0$6, global.require$$0$2, global.require$$0$5, global.require$$0$3, global.require$$0$4, global.require$$0$7, global.require$$1, global.require$$0$8, global.require$$5, global.require$$0$9, global.require$$1$1));
|
|
5
|
+
})(this, (function (exports, VTable, require$$0$1, require$$0$6, require$$0$2, require$$0$5, require$$0$3, require$$0$4, require$$0$7, require$$1, require$$0$8, require$$5, require$$0$9, require$$1$1) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
var n = Object.create(null);
|
|
@@ -15417,10 +15417,22 @@
|
|
|
15417
15417
|
}
|
|
15418
15418
|
}
|
|
15419
15419
|
|
|
15420
|
+
const checkGanttDependency = () => {
|
|
15421
|
+
try {
|
|
15422
|
+
require.resolve('@visactor/vtable-gantt');
|
|
15423
|
+
return true;
|
|
15424
|
+
}
|
|
15425
|
+
catch (e) {
|
|
15426
|
+
return false;
|
|
15427
|
+
}
|
|
15428
|
+
};
|
|
15420
15429
|
class ExportGanttPlugin {
|
|
15421
15430
|
id = `gantt-export-helper`;
|
|
15422
15431
|
name = 'Gantt Export Helper';
|
|
15423
15432
|
_gantt = null;
|
|
15433
|
+
constructor() {
|
|
15434
|
+
checkGanttDependency();
|
|
15435
|
+
}
|
|
15424
15436
|
run(...args) {
|
|
15425
15437
|
const ganttInstance = args[0];
|
|
15426
15438
|
if (!ganttInstance) {
|
|
@@ -15429,6 +15441,9 @@
|
|
|
15429
15441
|
this._gantt = ganttInstance;
|
|
15430
15442
|
}
|
|
15431
15443
|
async exportToImage(options = {}) {
|
|
15444
|
+
if (!checkGanttDependency()) {
|
|
15445
|
+
return undefined;
|
|
15446
|
+
}
|
|
15432
15447
|
if (!this._gantt) {
|
|
15433
15448
|
return undefined;
|
|
15434
15449
|
}
|
|
@@ -15474,7 +15489,7 @@
|
|
|
15474
15489
|
download: false
|
|
15475
15490
|
});
|
|
15476
15491
|
}
|
|
15477
|
-
createFullSizeContainer(scale) {
|
|
15492
|
+
async createFullSizeContainer(scale) {
|
|
15478
15493
|
if (!this._gantt) {
|
|
15479
15494
|
throw new Error('ExportGanttPlugin: Gantt instance not available to create container.');
|
|
15480
15495
|
}
|
|
@@ -15491,26 +15506,45 @@
|
|
|
15491
15506
|
clonedContainer.style.width = `${totalWidth}px`;
|
|
15492
15507
|
clonedContainer.style.height = `${totalHeight}px`;
|
|
15493
15508
|
tempContainer.appendChild(clonedContainer);
|
|
15494
|
-
|
|
15495
|
-
|
|
15496
|
-
|
|
15497
|
-
|
|
15498
|
-
|
|
15499
|
-
|
|
15500
|
-
|
|
15501
|
-
|
|
15502
|
-
}
|
|
15503
|
-
|
|
15504
|
-
|
|
15505
|
-
|
|
15506
|
-
|
|
15507
|
-
|
|
15509
|
+
try {
|
|
15510
|
+
let GanttClass;
|
|
15511
|
+
try {
|
|
15512
|
+
const module = await import('@visactor/vtable-gantt');
|
|
15513
|
+
GanttClass = module.Gantt;
|
|
15514
|
+
if (!GanttClass) {
|
|
15515
|
+
throw new Error('Gantt class not found in @visactor/vtable-gantt');
|
|
15516
|
+
}
|
|
15517
|
+
}
|
|
15518
|
+
catch (err) {
|
|
15519
|
+
throw new Error('导出甘特图需要安装并正确加载 @visactor/vtable-gantt 依赖\n' + '请执行: npm install @visactor/vtable-gantt');
|
|
15520
|
+
}
|
|
15521
|
+
const clonedGantt = new GanttClass(clonedContainer, {
|
|
15522
|
+
...this._gantt.options,
|
|
15523
|
+
records: this._gantt.records,
|
|
15524
|
+
taskListTable: {
|
|
15525
|
+
...this._gantt.options.taskListTable,
|
|
15526
|
+
tableWidth: undefined,
|
|
15527
|
+
minTableWidth: undefined,
|
|
15528
|
+
maxTableWidth: undefined
|
|
15529
|
+
},
|
|
15530
|
+
plugins: []
|
|
15531
|
+
});
|
|
15532
|
+
clonedGantt.setPixelRatio(scale);
|
|
15533
|
+
if (clonedGantt.scenegraph?.ganttGroup) {
|
|
15534
|
+
clonedGantt.scenegraph.ganttGroup.setAttribute('clip', false);
|
|
15535
|
+
}
|
|
15536
|
+
if (clonedGantt.taskListTableInstance?.scenegraph?.tableGroup) {
|
|
15537
|
+
clonedGantt.taskListTableInstance.scenegraph.tableGroup.setAttribute('clip', false);
|
|
15538
|
+
}
|
|
15539
|
+
clonedGantt.scenegraph.stage.render();
|
|
15540
|
+
return { tempContainer, clonedGantt };
|
|
15508
15541
|
}
|
|
15509
|
-
|
|
15510
|
-
|
|
15542
|
+
catch (err) {
|
|
15543
|
+
if (tempContainer && tempContainer.parentNode) {
|
|
15544
|
+
tempContainer.remove();
|
|
15545
|
+
}
|
|
15546
|
+
throw new Error('导出甘特图需要安装 @visactor/vtable-gantt 依赖');
|
|
15511
15547
|
}
|
|
15512
|
-
clonedGantt.scenegraph.stage.render();
|
|
15513
|
-
return { tempContainer, clonedGantt };
|
|
15514
15548
|
}
|
|
15515
15549
|
finalizeExport(canvas, fileName, type, quality, download = true) {
|
|
15516
15550
|
const base64 = canvas.toDataURL(`image/${type}`, quality);
|