Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
refactor(sheets-graphics): remove unused graphics package (#7018)
白熱6cc6918a113b
diff --git a/packages/sheets-graphics/README.md b/packages/sheets-graphics/README.mddeleted file mode 100644index 50e52f33c1..0000000000--- a/packages/sheets-graphics/README.md+++ /dev/null@@ -1,38 +0,0 @@-# @univerjs/sheets-graphics--[](https://npmjs.com/package/@univerjs/sheets-graphics)-[](https://npmjs.com/package/@univerjs/sheets-graphics)-[](https://npmjs.com/package/@univerjs/sheets-graphics)--`@univerjs/sheets-graphics` adds support for drawing simple in-cell graphics on Univer Sheets render surfaces.--## Package Overview--| Package | UMD global | CSS | Locales | Facade entry |-| --- | --- | :---: | :---: | :---: |-| `@univerjs/sheets-graphics` | `UniverSheetsGraphics` | No | No | No |--## Installation--```sh-pnpm add @univerjs/sheets-graphics-# or-npm install @univerjs/sheets-graphics-```--Keep all `@univerjs/*` packages on the same version.--## Usage--```ts-import { UniverSheetsGraphicsPlugin } from '@univerjs/sheets-graphics';--univer.registerPlugin(UniverSheetsGraphicsPlugin);-```--## Resources--- [Documentation](https://docs.univer.ai)-- [NPM package](https://npmjs.com/package/@univerjs/sheets-graphics)-- [GitHub repository](https://github.com/dream-num/univer)-diff --git a/packages/sheets-graphics/package.json b/packages/sheets-graphics/package.jsondeleted file mode 100644index cba0326659..0000000000--- a/packages/sheets-graphics/package.json+++ /dev/null@@ -1,76 +0,0 @@-{- "name": "@univerjs/sheets-graphics",- "version": "0.25.0",- "private": false,- "description": "In-cell graphics rendering support for Univer Sheets.",- "author": "DreamNum Co., Ltd. <[email protected]>",- "license": "Apache-2.0",- "funding": {- "type": "opencollective",- "url": "https://opencollective.com/univer"- },- "homepage": "https://univer.ai",- "repository": {- "type": "git",- "url": "https://github.com/dream-num/univer"- },- "bugs": {- "url": "https://github.com/dream-num/univer/issues"- },- "keywords": [- "univer",- "sheets",- "graphics",- "drawing",- "plugin"- ],- "exports": {- ".": "./src/index.ts",- "./*": "./src/*"- },- "main": "./src/index.ts",- "types": "./lib/types/index.d.ts",- "publishConfig": {- "access": "public",- "main": "./lib/es/index.js",- "module": "./lib/es/index.js",- "exports": {- ".": {- "import": "./lib/es/index.js",- "require": "./lib/cjs/index.js",- "types": "./lib/types/index.d.ts"- },- "./*": {- "import": "./lib/es/*",- "require": "./lib/cjs/*",- "types": "./lib/types/index.d.ts"- },- "./lib/*": "./lib/*"- }- },- "directories": {- "lib": "lib"- },- "files": [- "lib"- ],- "scripts": {- "test": "vitest run",- "test:watch": "vitest",- "coverage": "vitest run --coverage",- "typecheck": "tsc --noEmit",- "build:bundle": "univer-cli build",- "build:types": "tsc -p tsconfig.node.json",- "build": "pnpm run build:bundle && pnpm run build:types"- },- "dependencies": {- "@univerjs/core": "workspace:*",- "@univerjs/engine-render": "workspace:*",- "@univerjs/sheets-ui": "workspace:*"- },- "devDependencies": {- "@univerjs-infra/shared": "workspace:*",- "typescript": "^6.0.3",- "vitest": "^4.1.7"- }-}diff --git a/packages/sheets-graphics/src/common/const.ts b/packages/sheets-graphics/src/common/const.tsdeleted file mode 100644index 46dc2f4480..0000000000--- a/packages/sheets-graphics/src/common/const.ts+++ /dev/null@@ -1,18 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--export const UNIQUE_KEY = 'SheetGraphicsExtension';-export const GRAPHICS_EXTENSION_INDEX = 35;diff --git a/packages/sheets-graphics/src/config/config.ts b/packages/sheets-graphics/src/config/config.tsdeleted file mode 100644index 9a06fed28a..0000000000--- a/packages/sheets-graphics/src/config/config.ts+++ /dev/null@@ -1,27 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { DependencyOverride } from '@univerjs/core';--export const PLUGIN_CONFIG_KEY = 'graphics.config';--export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);--export interface IUniverSheetsGraphicsConfig {- override?: DependencyOverride;-}--export const defaultPluginConfig: IUniverSheetsGraphicsConfig = {};diff --git a/packages/sheets-graphics/src/controllers/graphics-render.controller.spec.ts b/packages/sheets-graphics/src/controllers/graphics-render.controller.spec.tsdeleted file mode 100644index 84ef8172ad..0000000000--- a/packages/sheets-graphics/src/controllers/graphics-render.controller.spec.ts+++ /dev/null@@ -1,107 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { Graphics } from '../views/extensions/graphics.extension';-import { describe, expect, it, vi } from 'vitest';-import { SheetGraphicsRenderController } from './graphics-render.controller';--describe('SheetGraphicsRenderController', () => {- it('should init extension, printing interceptor, and register renderer', () => {- const registered: unknown[] = [];- let interceptorHandler: ((component: unknown, context: { spreadsheet: { register: (obj: unknown) => void } }, next: (component: unknown) => unknown) => unknown) | undefined;-- const context = {- mainComponent: {- getExtensionByKey: vi.fn(() => undefined),- register: vi.fn((ext: unknown) => {- registered.push(ext);- }),- },- };-- const interceptor = {- getInterceptPoints: vi.fn(() => ({ PRINTING_COMPONENT_COLLECT: 'PRINTING_COMPONENT_COLLECT' })),- intercept: vi.fn((_point, config: { handler: typeof interceptorHandler }) => {- interceptorHandler = config.handler;- return { dispose: vi.fn() };- }),- };-- const controller = new SheetGraphicsRenderController(- context as never,- { interceptor } as never- );-- expect(context.mainComponent.getExtensionByKey).toHaveBeenCalled();- expect(context.mainComponent.register).toHaveBeenCalledTimes(1);-- const extension = registered[0] as Graphics;- const renderer = vi.fn();- controller.registerRenderer('feature-a', renderer as never);-- extension.draw(- {} as never,- {} as never,- { getCellByIndexWithNoHeader: vi.fn(() => ({ row: 1, col: 1 })) } as never,- [],- { viewRanges: [{ startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 }] } as never- );- expect(renderer).toHaveBeenCalledTimes(1);-- const copySpy = vi.spyOn(extension, 'copy');- const printSheet = { register: vi.fn() };- const next = vi.fn((value: unknown) => ({ passthrough: value }));- const result = interceptorHandler?.('component-a', { spreadsheet: printSheet }, next);-- expect(copySpy).toHaveBeenCalledTimes(1);- expect(printSheet.register).toHaveBeenCalledTimes(1);- expect(next).toHaveBeenCalledWith('component-a');- expect(result).toEqual({ passthrough: 'component-a' });-- controller.dispose();- });-- it('should skip init extension when extension already exists and keep printing flow', () => {- let interceptorHandler: ((component: unknown, context: { spreadsheet: { register: (obj: unknown) => void } }, next: (component: unknown) => unknown) => unknown) | undefined;- const context = {- mainComponent: {- getExtensionByKey: vi.fn(() => ({})),- register: vi.fn(),- },- };- const interceptor = {- getInterceptPoints: vi.fn(() => ({ PRINTING_COMPONENT_COLLECT: 'PRINTING_COMPONENT_COLLECT' })),- intercept: vi.fn((_point, config: { handler: typeof interceptorHandler }) => {- interceptorHandler = config.handler;- return { dispose: vi.fn() };- }),- };-- const controller = new SheetGraphicsRenderController(- context as never,- { interceptor } as never- );-- expect(context.mainComponent.register).not.toHaveBeenCalled();- expect(() => controller.registerRenderer('noop', vi.fn() as never)).not.toThrow();-- const printSheet = { register: vi.fn() };- const next = vi.fn((value: unknown) => value);- const result = interceptorHandler?.('component-b', { spreadsheet: printSheet }, next);- expect(printSheet.register).not.toHaveBeenCalled();- expect(result).toBe('component-b');- });-});diff --git a/packages/sheets-graphics/src/controllers/graphics-render.controller.ts b/packages/sheets-graphics/src/controllers/graphics-render.controller.tsdeleted file mode 100644index 575a2ccea3..0000000000--- a/packages/sheets-graphics/src/controllers/graphics-render.controller.ts+++ /dev/null@@ -1,62 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { ISelectionCellWithMergeInfo } from '@univerjs/core';-import type { IRenderContext, IRenderModule, Spreadsheet, SpreadsheetSkeleton, UniverRenderingContext } from '@univerjs/engine-render';-import { Disposable, Inject } from '@univerjs/core';-import { SheetPrintInterceptorService } from '@univerjs/sheets-ui';-import { UNIQUE_KEY } from '../common/const';-import { Graphics } from '../views/extensions/graphics.extension';--export class SheetGraphicsRenderController extends Disposable implements IRenderModule {- private _graphicsExtensionInstance: Graphics | null = null;-- constructor(- private readonly _context: IRenderContext,- @Inject(SheetPrintInterceptorService) private readonly _sheetPrintInterceptorService: SheetPrintInterceptorService- ) {- super();- this._initRender();- this._initPrinting();- }-- private _initRender() {- const spreadsheet = this._context.mainComponent as Spreadsheet;- if (spreadsheet && !spreadsheet.getExtensionByKey(UNIQUE_KEY)) {- this._graphicsExtensionInstance = new Graphics();- spreadsheet.register(this._graphicsExtensionInstance);- }- }-- private _initPrinting() {- this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(- this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,- {- handler: (component, context, next) => {- const { spreadsheet } = context;- if (this._graphicsExtensionInstance) {- spreadsheet.register(this._graphicsExtensionInstance.copy());- }- return next(component);- },- }- ));- }-- registerRenderer(key: string, renderer: (ctx: UniverRenderingContext, skeleton: SpreadsheetSkeleton, coordInfo: ISelectionCellWithMergeInfo) => void) {- this._graphicsExtensionInstance?.registerRenderer(key, renderer);- }-}diff --git a/packages/sheets-graphics/src/index.ts b/packages/sheets-graphics/src/index.tsdeleted file mode 100644index 4c79344c8c..0000000000--- a/packages/sheets-graphics/src/index.ts+++ /dev/null@@ -1,19 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--export type { IUniverSheetsGraphicsConfig } from './config/config';-export { SheetGraphicsRenderController } from './controllers/graphics-render.controller';-export { UniverSheetsGraphicsPlugin } from './plugin';diff --git a/packages/sheets-graphics/src/plugin.ts b/packages/sheets-graphics/src/plugin.tsdeleted file mode 100644index 7c91be2d71..0000000000--- a/packages/sheets-graphics/src/plugin.ts+++ /dev/null@@ -1,53 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { Dependency } from '@univerjs/core';-import type { IUniverSheetsGraphicsConfig } from './config/config';-import { IConfigService, Inject, Injector, merge, Plugin, UniverInstanceType } from '@univerjs/core';-import { IRenderManagerService } from '@univerjs/engine-render';-import pkg from '../package.json';-import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './config/config';-import { SheetGraphicsRenderController } from './controllers/graphics-render.controller';--export class UniverSheetsGraphicsPlugin extends Plugin {- static override pluginName = 'UNIVER_SHEET_DRAWING_PLUGIN';- static override packageName = pkg.name;- static override version = pkg.version;-- constructor(- private readonly _config: Partial<IUniverSheetsGraphicsConfig> = defaultPluginConfig,- @Inject(Injector) protected _injector: Injector,- @IConfigService private readonly _configService: IConfigService,- @IRenderManagerService private readonly _renderManagerService: IRenderManagerService- ) {- super();-- const { ...rest } = merge(- {},- defaultPluginConfig,- this._config- );- this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);- }-- override onRendered(): void {- ([- [SheetGraphicsRenderController],- ] as Dependency[]).forEach((dep) => {- this._renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, dep);- });- }-}diff --git a/packages/sheets-graphics/src/views/extensions/graphics.extension.spec.ts b/packages/sheets-graphics/src/views/extensions/graphics.extension.spec.tsdeleted file mode 100644index 6c4ecd20ef..0000000000--- a/packages/sheets-graphics/src/views/extensions/graphics.extension.spec.ts+++ /dev/null@@ -1,93 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import { describe, expect, it, vi } from 'vitest';-import { Graphics } from './graphics.extension';--describe('Graphics extension', () => {- it('should register renderer, draw ranges, copy and dispose', () => {- const graphics = new Graphics();- const rendererA = vi.fn();- const rendererB = vi.fn();- graphics.registerRenderer('a', rendererA);- graphics.registerRenderer('b', rendererB);-- const skeleton = {- getCellByIndexWithNoHeader: vi.fn((row: number, col: number) => {- if (row === 0 && col === 0) {- return undefined;- }- return { row, col };- }),- };-- graphics.draw(- {} as never,- {} as never,- skeleton as never,- [],- {- viewRanges: [{- startRow: 0,- endRow: 1,- startColumn: 0,- endColumn: 0,- }],- } as never- );-- expect(rendererA).toHaveBeenCalledTimes(1);- expect(rendererB).toHaveBeenCalledTimes(1);-- const copied = graphics.copy();- const rendererC = vi.fn();- copied.registerRenderer('c', rendererC);- copied.draw(- {} as never,- {} as never,- skeleton as never,- [],- {- viewRanges: [{- startRow: 1,- endRow: 1,- startColumn: 0,- endColumn: 0,- }],- } as never- );- expect(rendererA).toHaveBeenCalledTimes(2);- expect(rendererB).toHaveBeenCalledTimes(2);- expect(rendererC).toHaveBeenCalledTimes(1);-- copied.dispose();- copied.draw(- {} as never,- {} as never,- skeleton as never,- [],- {- viewRanges: [{- startRow: 1,- endRow: 1,- startColumn: 0,- endColumn: 0,- }],- } as never- );- expect(rendererC).toHaveBeenCalledTimes(1);- });-});diff --git a/packages/sheets-graphics/src/views/extensions/graphics.extension.ts b/packages/sheets-graphics/src/views/extensions/graphics.extension.tsdeleted file mode 100644index 7fa3d67d29..0000000000--- a/packages/sheets-graphics/src/views/extensions/graphics.extension.ts+++ /dev/null@@ -1,63 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { IRange, IScale, ISelectionCellWithMergeInfo } from '@univerjs/core';-import type { IDrawInfo, SpreadsheetSkeleton, UniverRenderingContext } from '@univerjs/engine-render';-import { Range } from '@univerjs/core';-import { SheetExtension } from '@univerjs/engine-render';-import { GRAPHICS_EXTENSION_INDEX, UNIQUE_KEY } from '../../common/const';--type IGraphicsRenderer = (ctx: UniverRenderingContext, skeleton: SpreadsheetSkeleton, coordInfo: ISelectionCellWithMergeInfo) => void;-type IGraphicsRenderMap = Map<string, IGraphicsRenderer>;--export class Graphics extends SheetExtension {- override uKey = UNIQUE_KEY;- protected override Z_INDEX = GRAPHICS_EXTENSION_INDEX;-- private _graphicsRenderMap: IGraphicsRenderMap = new Map();-- public registerRenderer(key: string, renderer: IGraphicsRenderer) {- this._graphicsRenderMap.set(key, renderer);- }-- override draw(ctx: UniverRenderingContext, _parentScale: IScale, skeleton: SpreadsheetSkeleton, diffBounds: IRange[], { viewRanges }: IDrawInfo): void {- const featureTypes = Array.from(this._graphicsRenderMap.keys());- viewRanges.forEach((range) => {- Range.foreach(range, (row, col) => {- const cellPosition = skeleton.getCellByIndexWithNoHeader(row, col);- if (!cellPosition) {- return;- }- featureTypes.forEach((featureType) => {- const renderer = this._graphicsRenderMap.get(featureType);- renderer?.(ctx, skeleton, cellPosition);- });- });- });- }-- override dispose(): void {- this._graphicsRenderMap.clear();- }-- copy() {- const newGraphics = new Graphics();- this._graphicsRenderMap.forEach((renderer, key) => {- newGraphics.registerRenderer(key, renderer);- });- return newGraphics;- }-}diff --git a/packages/sheets-graphics/tsconfig.json b/packages/sheets-graphics/tsconfig.jsondeleted file mode 100644index d4f9172636..0000000000--- a/packages/sheets-graphics/tsconfig.json+++ /dev/null@@ -1,8 +0,0 @@-{- "extends": "@univerjs-infra/shared/tsconfigs/base",- "compilerOptions": {- "rootDir": "src",- "outDir": "lib/types"- },- "include": ["src"]-}diff --git a/packages/sheets-graphics/tsconfig.node.json b/packages/sheets-graphics/tsconfig.node.jsondeleted file mode 100644index 2abfa07367..0000000000--- a/packages/sheets-graphics/tsconfig.node.json+++ /dev/null@@ -1,18 +0,0 @@-{- "extends": "@univerjs-infra/shared/tsconfigs/node",- "compilerOptions": {- "rootDir": "src",- "declaration": true,- "emitDeclarationOnly": true,- "noEmit": false,- "outDir": "lib/types"- },- "include": [- "src"- ],- "exclude": [- "src/**/__tests__/**",- "src/**/*.spec.ts",- "src/**/*.test.ts"- ]-}diff --git a/packages/sheets-graphics/vitest.config.ts b/packages/sheets-graphics/vitest.config.tsdeleted file mode 100644index af97c6d7a2..0000000000--- a/packages/sheets-graphics/vitest.config.ts+++ /dev/null@@ -1,3 +0,0 @@-import createConfig from '@univerjs-infra/shared/vitest';--export default createConfig();diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 76fe53e3de..a1940e2f99 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -2126,28 +2126,6 @@ importers:specifier: ^4.1.7version: 4.1.7(@types/[email protected])(@vitest/[email protected])([email protected])([email protected]([email protected]))([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))- packages/sheets-graphics:- dependencies:- '@univerjs/core':- specifier: workspace:*- version: link:../core- '@univerjs/engine-render':- specifier: workspace:*- version: link:../engine-render- '@univerjs/sheets-ui':- specifier: workspace:*- version: link:../sheets-ui- devDependencies:- '@univerjs-infra/shared':- specifier: workspace:*- version: link:../../common/shared- typescript:- specifier: ^6.0.3- version: 6.0.3- vitest:- specifier: ^4.1.7- version: 4.1.7(@types/[email protected])(@vitest/[email protected])([email protected])([email protected]([email protected]))([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))-packages/sheets-hyper-link:dependencies:'@univerjs/core':