@visactor/vtable-plugins 1.19.1-alpha.1 → 1.19.2

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.
@@ -67,7 +67,7 @@ class ExportGanttPlugin {
67
67
  var _a;
68
68
  return __awaiter(this, void 0, void 0, (function*() {
69
69
  if (!this._gantt) return;
70
- const {fileName: fileName = "gantt-export", type: type = "png", quality: quality = 1, backgroundColor: backgroundColor = "#ffffff", scale: scale = window.devicePixelRatio || 1} = options;
70
+ const {fileName: fileName = "gantt-export", type: type = "png", quality: quality = 1, backgroundColor: backgroundColor = "#ffffff", scale: scale = window.devicePixelRatio || 1, download: download = !0} = options;
71
71
  try {
72
72
  const {tempContainer: tempContainer, clonedGantt: clonedGantt} = this.createFullSizeContainer(scale);
73
73
  try {
@@ -80,7 +80,7 @@ class ExportGanttPlugin {
80
80
  ctx.fillStyle = "rgb(225, 228, 232)", ctx.fillRect(splitLineX - splitLineWidth / 2, 0, splitLineWidth, totalHeight);
81
81
  const sourceX = 4 * scale, sourceWidth = clonedGantt.canvas.width - sourceX;
82
82
  return clonedGantt.canvas && ctx.drawImage(clonedGantt.canvas, sourceX, 0, sourceWidth, clonedGantt.canvas.height, (clonedGantt.taskListTableInstance.getAllColsWidth() + 1.5) * scale, 0, (clonedGantt.getAllDateColsWidth() - 1.5) * scale, totalHeight),
83
- this.finalizeExport(exportCanvas, fileName, type, quality);
83
+ this.finalizeExport(exportCanvas, fileName, type, quality, download);
84
84
  } finally {
85
85
  tempContainer.remove(), clonedGantt.release();
86
86
  }
@@ -89,6 +89,13 @@ class ExportGanttPlugin {
89
89
  }
90
90
  }));
91
91
  }
92
+ exportToBase64(options = {}) {
93
+ return __awaiter(this, void 0, void 0, (function*() {
94
+ return this.exportToImage(Object.assign(Object.assign({}, options), {
95
+ download: !1
96
+ }));
97
+ }));
98
+ }
92
99
  createFullSizeContainer(scale) {
93
100
  var _a, _b, _c;
94
101
  if (!this._gantt) throw new Error("ExportGanttPlugin: Gantt instance not available to create container.");
@@ -105,7 +112,8 @@ class ExportGanttPlugin {
105
112
  tableWidth: void 0,
106
113
  minTableWidth: void 0,
107
114
  maxTableWidth: void 0
108
- })
115
+ }),
116
+ plugins: []
109
117
  }));
110
118
  return clonedGantt.setPixelRatio(scale), (null === (_a = clonedGantt.scenegraph) || void 0 === _a ? void 0 : _a.ganttGroup) && clonedGantt.scenegraph.ganttGroup.setAttribute("clip", !1),
111
119
  (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),
@@ -114,10 +122,14 @@ class ExportGanttPlugin {
114
122
  clonedGantt: clonedGantt
115
123
  };
116
124
  }
117
- finalizeExport(canvas, fileName, type, quality) {
118
- const base64 = canvas.toDataURL(`image/${type}`, quality), link = document.createElement("a");
119
- return link.download = `${fileName}.${type}`, link.href = base64, document.body.appendChild(link),
120
- link.click(), document.body.removeChild(link), base64;
125
+ finalizeExport(canvas, fileName, type, quality, download = !0) {
126
+ const base64 = canvas.toDataURL(`image/${type}`, quality);
127
+ if (download) {
128
+ const link = document.createElement("a");
129
+ link.download = `${fileName}.${type}`, link.href = base64, document.body.appendChild(link),
130
+ link.click(), document.body.removeChild(link);
131
+ }
132
+ return base64;
121
133
  }
122
134
  release() {
123
135
  this._gantt = null;
@@ -1 +1 @@
1
- {"version":3,"sources":["gantt-export-image.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oEAAsD;AAgBtD,MAAa,iBAAiB;IAA9B;QACI,OAAE,GAAG,qBAAqB,CAAC;QAC3B,SAAI,GAAG,qBAAqB,CAAC;QACrB,WAAM,GAA6B,IAAI,CAAC;IA+JpD,CAAC;IA5JG,GAAG,CAAC,GAAG,IAAW;QACd,MAAM,aAAa,GAAG,IAAI,CAAC,CAAC,CAAsB,CAAC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AAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,OAAO;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;CACJ;AAlKD,8CAkKC","file":"gantt-export-image.js","sourcesContent":["import * as VTableGantt 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}\r\n\r\n\r\n/**\r\n * 甘特图导出插件\r\n * @description 提供完整的甘特图导出功能,支持高分辨率输出和精准布局保留\r\n */\r\nexport class ExportGanttPlugin implements VTableGantt.plugins.IGanttPlugin {\r\n id = 'gantt-export-helper';\r\n name = 'Gantt Export Helper';\r\n private _gantt: VTableGantt.Gantt | null = null;\r\n\r\n // run 方法,在插件初始化时由 PluginManager调用\r\n run(...args: any[]): void {\r\n const ganttInstance = args[0] as VTableGantt.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 * 执行甘特图导出操作\r\n * @async\r\n * @param {ExportOptions} [options={}] 导出配置选项\r\n * @returns {Promise<string | undefined>} 返回Base64格式的图片数据,或在未初始化时返回 undefined\r\n * @throws {Error} 导出过程中发生错误时抛出异常\r\n */\r\n public 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 } = 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 = (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, 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(\r\n splitLineX - splitLineWidth / 2,\r\n 0,\r\n splitLineWidth,\r\n totalHeight\r\n );\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, 0,\r\n sourceWidth, clonedGantt.canvas.height,\r\n (clonedGantt.taskListTableInstance.getAllColsWidth() + 1.5) * scale, 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);\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 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 VTableGantt.Gantt(clonedContainer, {\r\n ...this._gantt.options,\r\n records: JSON.parse(JSON.stringify(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 });\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\r\n private finalizeExport(canvas: HTMLCanvasElement, fileName: string, type: string, quality: number): string {\r\n const base64 = canvas.toDataURL(`image/${type}`, quality);\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 return base64;\r\n }\r\n \r\n release(): void {\r\n this._gantt = null;\r\n }\r\n}"]}
1
+ {"version":3,"sources":["gantt-export-image.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oEAAsD;AAgBtD,MAAa,iBAAiB;IAA9B;QACE,OAAE,GAAG,qBAAqB,CAAC;QAC3B,SAAI,GAAG,qBAAqB,CAAC;QACrB,WAAM,GAA6B,IAAI,CAAC;IAyLlD,CAAC;IAtLC,GAAG,CAAC,GAAG,IAAW;QAChB,MAAM,aAAa,GAAG,IAAI,CAAC,CAAC,CAAsB,CAAC;QACnD,IAAI,CAAC,aAAa,EAAE;YAClB,OAAO,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAC;YAC/E,OAAO;SACR;QACD,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC;IAC9B,CAAC;IAQK,aAAa,CAAC,UAAyB,EAAE;;;YAC7C,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBAEhB,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;gBAClE,OAAO,SAAS,CAAC;aAClB;YAED,MAAM,EACJ,QAAQ,GAAG,cAAc,EACzB,IAAI,GAAG,KAAK,EACZ,OAAO,GAAG,CAAC,EACX,eAAe,GAAG,SAAS,EAC3B,KAAK,GAAG,MAAM,CAAC,gBAAgB,IAAI,CAAC,EACpC,QAAQ,GAAG,IAAI,EAChB,GAAG,OAAO,CAAC;YAEZ,IAAI;gBACF,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;gBAE3E,IAAI;oBACF,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;oBAE7D,MAAM,UAAU,GACd,CAAC,WAAW,CAAC,qB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;QACD,IAAI,MAAA,MAAC,WAAW,CAAC,qBAA6B,0CAAE,UAAU,0CAAE,UAAU,EAAE;YACrE,WAAW,CAAC,qBAA6B,CAAC,UAAU,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SAC9F;QAED,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAEtC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC;IACxC,CAAC;IACO,cAAc,CACpB,MAAyB,EACzB,QAAgB,EAChB,IAAY,EACZ,OAAe,EACf,WAAoB,IAAI;QAExB,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;QAG1D,IAAI,QAAQ,EAAE;YACZ,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,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 * as VTableGantt 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 VTableGantt.plugins.IGanttPlugin {\r\n id = 'gantt-export-helper';\r\n name = 'Gantt Export Helper';\r\n private _gantt: VTableGantt.Gantt | null = null;\r\n\r\n // run 方法,在插件初始化时由 PluginManager调用\r\n run(...args: any[]): void {\r\n const ganttInstance = args[0] as VTableGantt.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 VTableGantt.Gantt(clonedContainer, {\r\n ...this._gantt.options,\r\n records: JSON.parse(JSON.stringify(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"]}
package/cjs/index.d.ts CHANGED
@@ -12,3 +12,4 @@ export * from './table-carousel-animation';
12
12
  export * from './rotate-table';
13
13
  export * from './gantt-export-image';
14
14
  export * from './wps-fill-handle';
15
+ export * from './excel-import';
package/cjs/index.js CHANGED
@@ -23,5 +23,6 @@ __exportStar(require("./column-series"), exports), __exportStar(require("./row-s
23
23
  __exportStar(require("./highlight-header-when-select-cell"), exports), __exportStar(require("./excel-edit-cell-keyboard"), exports),
24
24
  __exportStar(require("./types"), exports), __exportStar(require("./focus-highlight"), exports),
25
25
  __exportStar(require("./table-carousel-animation"), exports), __exportStar(require("./rotate-table"), exports),
26
- __exportStar(require("./gantt-export-image"), exports), __exportStar(require("./wps-fill-handle"), exports);
26
+ __exportStar(require("./gantt-export-image"), exports), __exportStar(require("./wps-fill-handle"), exports),
27
+ __exportStar(require("./excel-import"), exports);
27
28
  //# sourceMappingURL=index.js.map
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,qDAAmC;AACnC,qDAAmC;AACnC,mDAAiC;AACjC,kDAAgC;AAChC,+CAA6B;AAC7B,sEAAoD;AACpD,6DAA2C;AAC3C,0CAAwB;AACxB,oDAAkC;AAClC,6DAA2C;AAC3C,iDAA+B;AAC/B,uDAAqC;AACrC,oDAAkC","file":"index.js","sourcesContent":["export * from './carousel-animation';\nexport * from './invert-highlight';\nexport * from './header-highlight';\nexport * from './add-row-column';\nexport * from './column-series';\nexport * from './row-series';\nexport * from './highlight-header-when-select-cell';\nexport * from './excel-edit-cell-keyboard';\nexport * from './types';\nexport * from './focus-highlight';\nexport * from './table-carousel-animation';\nexport * from './rotate-table';\nexport * from './gantt-export-image';\nexport * from './wps-fill-handle';\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,qDAAmC;AACnC,qDAAmC;AACnC,mDAAiC;AACjC,kDAAgC;AAChC,+CAA6B;AAC7B,sEAAoD;AACpD,6DAA2C;AAC3C,0CAAwB;AACxB,oDAAkC;AAClC,6DAA2C;AAC3C,iDAA+B;AAC/B,uDAAqC;AACrC,oDAAkC;AAClC,iDAA+B","file":"index.js","sourcesContent":["export * from './carousel-animation';\nexport * from './invert-highlight';\nexport * from './header-highlight';\nexport * from './add-row-column';\nexport * from './column-series';\nexport * from './row-series';\nexport * from './highlight-header-when-select-cell';\nexport * from './excel-edit-cell-keyboard';\nexport * from './types';\nexport * from './focus-highlight';\nexport * from './table-carousel-animation';\nexport * from './rotate-table';\nexport * from './gantt-export-image';\nexport * from './wps-fill-handle';\nexport * from './excel-import';\n"]}