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
chore: move more features to lazy load (#3775)
Wenzhao Hue1aeec05da47
diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.tsindex cf44a665b8..88c1e342cb 100644--- a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts+++ b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts@@ -19,6 +19,7 @@ import { generateSnapshotName } from '../const';const SHEET_MAIN_CANVAS_ID = '#univer-sheet-main-canvas';const isCI = !!process.env.CI;+test('diff default sheet toolbar', async () => {const browser = await chromium.launch({headless: !!isCI, // Set to false to see the browser window@@ -42,6 +43,7 @@ test('diff default sheet toolbar', async () => {});await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });});+test('diff default sheet content', async ({ page }) => {await page.goto('http://localhost:3000/sheets/');await page.waitForTimeout(2000);diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-ci-chromium-linux.pngindex 0a35162d3e..5e25967cf8 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.pngindex 650c2f46b6..d575956f13 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.pngindex 34b6520c24..82f15024c0 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/mergedCellsRendering-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/mergedCellsRendering-ci-chromium-linux.pngindex 499134f34c..52f1e4253f 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/mergedCellsRendering-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/mergedCellsRendering-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/mergedCellsRenderingScrolling-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/mergedCellsRenderingScrolling-ci-chromium-linux.pngindex 499134f34c..52f1e4253f 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/mergedCellsRenderingScrolling-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/mergedCellsRenderingScrolling-ci-chromium-linux.png differdiff --git a/examples/src/sheets/lazy.ts b/examples/src/sheets/lazy.tsindex 47523fce1f..49ff91fe9a 100644--- a/examples/src/sheets/lazy.ts+++ b/examples/src/sheets/lazy.ts@@ -15,42 +15,16 @@*/import type { Plugin, PluginCtor } from '@univerjs/core';-import { UniverActionRecorderPlugin } from '@univerjs/action-recorder';-import { UniverDebuggerPlugin } from '@univerjs/debugger';import { UniverSheetsConditionalFormattingUIPlugin } from '@univerjs/sheets-conditional-formatting-ui';-import { UniverSheetsCrosshairHighlightPlugin } from '@univerjs/sheets-crosshair-highlight';+import { UniverSheetsDataValidationUIPlugin } from '@univerjs/sheets-data-validation-ui';import { UniverSheetsDrawingUIPlugin } from '@univerjs/sheets-drawing-ui';import { UniverSheetsFilterUIPlugin } from '@univerjs/sheets-filter-ui';-import { UniverSheetsFindReplacePlugin } from '@univerjs/sheets-find-replace';-import { UniverSheetsHyperLinkUIPlugin } from '@univerjs/sheets-hyper-link-ui';-import { UniverUniscriptPlugin } from '@univerjs/uniscript';export default function getLazyPlugins(): Array<[PluginCtor<Plugin>] | [PluginCtor<Plugin>, unknown]> {return [- [UniverUniscriptPlugin, {- getWorkerUrl(_: string, label: string) {- if (label === 'json') {- return '/vs/language/json/json.worker.js';- }- if (label === 'css' || label === 'scss' || label === 'less') {- return '/vs/language/css/css.worker.js';- }- if (label === 'html' || label === 'handlebars' || label === 'razor') {- return '/vs/language/html/html.worker.js';- }- if (label === 'typescript' || label === 'javascript') {- return '/vs/language/typescript/ts.worker.js';- }- return '/vs/editor/editor.worker.js';- },- }],+ [UniverSheetsDataValidationUIPlugin],[UniverSheetsConditionalFormattingUIPlugin],- [UniverActionRecorderPlugin],- [UniverSheetsHyperLinkUIPlugin],- [UniverSheetsCrosshairHighlightPlugin],[UniverSheetsFilterUIPlugin, { useRemoteFilterValuesGenerator: false }],[UniverSheetsDrawingUIPlugin],- [UniverSheetsFindReplacePlugin],- [UniverDebuggerPlugin],];}diff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.tsindex 2bc2766f95..596c27d1f0 100644--- a/examples/src/sheets/main.ts+++ b/examples/src/sheets/main.ts@@ -18,6 +18,7 @@ import type { Nullable } from '@univerjs/core';import type { IUniverRPCMainThreadConfig } from '@univerjs/rpc';import type { IThreadCommentMentionDataSource } from '@univerjs/thread-comment-ui';import { LocaleType, LogLevel, Univer, UniverInstanceType, UserManagerService } from '@univerjs/core';+import { UniverDebuggerPlugin } from '@univerjs/debugger';import { defaultTheme } from '@univerjs/design';import { UniverDocsPlugin } from '@univerjs/docs';import { UniverDocsUIPlugin } from '@univerjs/docs-ui';@@ -29,13 +30,12 @@ import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';import { UniverSheetsPlugin } from '@univerjs/sheets';import { UniverSheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting';import { UniverSheetsDataValidationPlugin } from '@univerjs/sheets-data-validation';-import { UniverSheetsDataValidationUIPlugin } from '@univerjs/sheets-data-validation-ui';import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula';import { UniverSheetsFormulaUIPlugin } from '@univerjs/sheets-formula-ui';import { UniverSheetsHyperLinkPlugin } from '@univerjs/sheets-hyper-link';import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';-import { UniverSheetsSortUIPlugin } from '@univerjs/sheets-sort-ui';+import { UniverSheetsSortPlugin } from '@univerjs/sheets-sort';import { IThreadCommentMentionDataService, UniverSheetsThreadCommentPlugin, UniverThreadCommentUIPlugin } from '@univerjs/sheets-thread-comment';import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor';@@ -46,6 +46,7 @@ import { enUS, faIR, ruRU, viVN, zhCN, zhTW } from '../locales';const IS_E2E: boolean = !!process.env.IS_E2E;const LOAD_LAZY_PLUGINS_TIMEOUT = 1_000;+const LOAD_VERY_LAZY_PLUGINS_TIMEOUT = 3_000;export const mockUser = {userID: 'Owner_qxVnhPbQ',@@ -109,16 +110,20 @@ univer.registerPlugin(UniverFormulaEnginePlugin, { notExecuteFormula: true });univer.registerPlugin(UniverSheetsFormulaPlugin, { notExecuteFormula: true });univer.registerPlugin(UniverSheetsFormulaUIPlugin);univer.registerPlugin(UniverSheetsDataValidationPlugin);-univer.registerPlugin(UniverSheetsDataValidationUIPlugin);univer.registerPlugin(UniverSheetsConditionalFormattingPlugin);univer.registerPlugin(UniverSheetsFilterPlugin);+univer.registerPlugin(UniverSheetsSortPlugin);univer.registerPlugin(UniverSheetsHyperLinkPlugin);-univer.registerPlugin(UniverSheetsSortUIPlugin);univer.registerPlugin(UniverThreadCommentUIPlugin, {overrides: [[IThreadCommentMentionDataService, { useClass: CustomMentionDataService }]],});univer.registerPlugin(UniverSheetsThreadCommentPlugin);+// If we are running in e2e platform, we should immediately register the debugger plugin.+if (IS_E2E) {+ univer.registerPlugin(UniverDebuggerPlugin);+}+const injector = univer.__getInjector();const userManagerService = injector.get(UserManagerService);userManagerService.setCurrentUser(mockUser);@@ -135,6 +140,13 @@ setTimeout(() => {});}, LOAD_LAZY_PLUGINS_TIMEOUT);+setTimeout(() => {+ import('./very-lazy').then((lazy) => {+ const plugins = lazy.default();+ plugins.forEach((p) => univer.registerPlugin(p[0], p[1]));+ });+}, LOAD_VERY_LAZY_PLUGINS_TIMEOUT);+window.univer = univer;window.univerAPI = FUniver.newAPI(univer);diff --git a/examples/src/sheets/very-lazy.ts b/examples/src/sheets/very-lazy.tsnew file mode 100644index 0000000000..520185190c--- /dev/null+++ b/examples/src/sheets/very-lazy.ts@@ -0,0 +1,61 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * 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 { Plugin, PluginCtor } from '@univerjs/core';+import { UniverActionRecorderPlugin } from '@univerjs/action-recorder';+import { UniverDebuggerPlugin } from '@univerjs/debugger';+import { UniverSheetsCrosshairHighlightPlugin } from '@univerjs/sheets-crosshair-highlight';+import { UniverSheetsFindReplacePlugin } from '@univerjs/sheets-find-replace';+import { UniverSheetsHyperLinkUIPlugin } from '@univerjs/sheets-hyper-link-ui';+import { UniverSheetsSortUIPlugin } from '@univerjs/sheets-sort-ui';+import { UniverUniscriptPlugin } from '@univerjs/uniscript';++/* eslint-disable-next-line node/prefer-global/process */+const IS_E2E: boolean = !!process.env.IS_E2E;++export default function getVeryLazyPlugins() {+ const plugins: Array<[PluginCtor<Plugin>] | [PluginCtor<Plugin>, unknown]> = [+ [UniverUniscriptPlugin, {+ getWorkerUrl(_: string, label: string) {+ if (label === 'json') {+ return '/vs/language/json/json.worker.js';+ }+ if (label === 'css' || label === 'scss' || label === 'less') {+ return '/vs/language/css/css.worker.js';+ }+ if (label === 'html' || label === 'handlebars' || label === 'razor') {+ return '/vs/language/html/html.worker.js';+ }+ if (label === 'typescript' || label === 'javascript') {+ return '/vs/language/typescript/ts.worker.js';+ }+ return '/vs/editor/editor.worker.js';+ },+ }],+ [UniverActionRecorderPlugin],+ [UniverSheetsHyperLinkUIPlugin],+ [UniverSheetsSortUIPlugin],+ [UniverSheetsCrosshairHighlightPlugin],+ [UniverSheetsFindReplacePlugin],+ ];++ if (!IS_E2E) {+ plugins.push([UniverDebuggerPlugin]);+ }++ return plugins;+}+