Skip to content

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.

fix(engine-render): restore public watermark constants (#8086)

白熱c13b042d18c8
diff --git a/packages/engine-render/src/components/sheets/constants.ts b/packages/engine-render/src/components/sheets/constants.ts
index ad97e6d4e6..00e2d24d64 100644
--- a/packages/engine-render/src/components/sheets/constants.ts
+++ b/packages/engine-render/src/components/sheets/constants.ts
@@ -20,6 +20,8 @@ export const BORDER_Z_INDEX = 50;
export const FONT_EXTENSION_Z_INDEX = 45;
export const BG_Z_INDEX = 21;
export const PRINTING_BG_Z_INDEX = 21;
+export const UNIVER_WATERMARK_LAYER_INDEX = 10;
+export const UNIVER_WATERMARK_STORAGE_KEY = 'UNIVER_WATERMARK_STORAGE_KEY';
export const EXPAND_SIZE_FOR_RENDER_OVERFLOW = 20;
export const MIN_TEXT_RENDER_HEIGHT_IN_SCREEN_PX = 4;
diff --git a/packages/engine-render/src/components/sheets/index.ts b/packages/engine-render/src/components/sheets/index.ts
deleted file mode 100644
index c387ff20df..0000000000
--- a/packages/engine-render/src/components/sheets/index.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.
- */
-
-export * from './column-header';
-export * from './constants';
-export * from './extensions';
-export * from './interfaces';
-export * from './row-header';
-export * from './sheet-component';
-export * from './sheet.render-skeleton';
-export * from './spreadsheet';
-export { calculateCellImageRect } from './util';
-export type { ICellImageRectConfig } from './util';
-export * from './watermark';
diff --git a/packages/engine-render/src/components/sheets/watermark/index.ts b/packages/engine-render/src/components/sheets/watermark/index.ts
deleted file mode 100644
index 2ad8de2829..0000000000
--- a/packages/engine-render/src/components/sheets/watermark/index.ts
+++ /dev/null
@@ -1,22 +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 * from './type';
-export * from './util';
-export * from './watermark-layer';
-
-export const UNIVER_WATERMARK_STORAGE_KEY = 'UNIVER_WATERMARK_STORAGE_KEY';
-export const UNIVER_WATERMARK_LAYER_INDEX = 10;
diff --git a/packages/watermark/src/services/__tests__/watermark.service.spec.ts b/packages/watermark/src/services/__tests__/watermark.service.spec.ts
index db205c2838..04d0754954 100644
--- a/packages/watermark/src/services/__tests__/watermark.service.spec.ts
+++ b/packages/watermark/src/services/__tests__/watermark.service.spec.ts
@@ -14,56 +14,50 @@
* limitations under the License.
*/
+import type { IWatermarkConfigWithType } from '@univerjs/engine-render';
import { ILocalStorageService, Injector } from '@univerjs/core';
-import { UNIVER_WATERMARK_STORAGE_KEY } from '@univerjs/engine-render';
-import { describe, expect, it, vi } from 'vitest';
+import { IWatermarkTypeEnum } from '@univerjs/engine-render';
+import { afterEach, describe, expect, it, vi } from 'vitest';
import { WatermarkService } from '../watermark.service';
-const getItem = vi.fn(async () => ({ type: 'text' }));
-const setItem = vi.fn();
-const removeItem = vi.fn();
-
-class TestLocalStorage {
- getItem = getItem;
- setItem = setItem;
- removeItem = removeItem;
-}
-
describe('WatermarkService', () => {
- it('should get/update/delete/refresh and dispose', async () => {
- getItem.mockClear();
- setItem.mockClear();
- removeItem.mockClear();
- const injector = new Injector();
- injector.add([ILocalStorageService, { useClass: TestLocalStorage as never }]);
+ let injector: Injector;
+
+ afterEach(() => injector.dispose());
+
+ it('reads, updates and deletes the persisted watermark and notifies subscribers', async () => {
+ const config: IWatermarkConfigWithType = { type: IWatermarkTypeEnum.Text, config: {} };
+ const storage: ILocalStorageService = {
+ getItem: vi.fn().mockResolvedValue(config),
+ setItem: vi.fn().mockResolvedValue(config),
+ removeItem: vi.fn().mockResolvedValue(undefined),
+ clear: vi.fn().mockResolvedValue(undefined),
+ key: vi.fn().mockResolvedValue(null),
+ keys: vi.fn().mockResolvedValue([]),
+ iterate: vi.fn().mockResolvedValue(undefined),
+ };
+ injector = new Injector();
+ injector.add([ILocalStorageService, { useValue: storage }]);
injector.add([WatermarkService]);
const service = injector.get(WatermarkService);
- await expect(service.getWatermarkConfig()).resolves.toEqual({ type: 'text' });
- expect(getItem).toHaveBeenCalledWith(UNIVER_WATERMARK_STORAGE_KEY);
+ await expect(service.getWatermarkConfig()).resolves.toEqual(config);
+ expect(storage.getItem).toHaveBeenCalledWith('UNIVER_WATERMARK_STORAGE_KEY');
const updateValues: unknown[] = [];
const refreshValues: number[] = [];
service.updateConfig$.subscribe((value) => updateValues.push(value));
service.refresh$.subscribe((value) => refreshValues.push(value));
- service.updateWatermarkConfig({ type: 'image', config: { image: { url: 'x' } } } as never);
- expect(setItem).toHaveBeenCalledWith(UNIVER_WATERMARK_STORAGE_KEY, {
- type: 'image',
- config: { image: { url: 'x' } },
- });
+ service.updateWatermarkConfig(config);
+ expect(storage.setItem).toHaveBeenCalledWith('UNIVER_WATERMARK_STORAGE_KEY', config);
service.deleteWatermarkConfig();
- expect(removeItem).toHaveBeenCalledWith(UNIVER_WATERMARK_STORAGE_KEY);
- expect(updateValues).toEqual([
- { type: 'image', config: { image: { url: 'x' } } },
- null,
- ]);
+ expect(storage.removeItem).toHaveBeenCalledWith('UNIVER_WATERMARK_STORAGE_KEY');
+ expect(updateValues).toEqual([config, null]);
service.refresh();
expect(refreshValues.length).toBe(1);
expect(refreshValues[0]).toBeTypeOf('number');
-
- service.dispose();
});
});