Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add multi units playground #4666

Merged
merged 6 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/esbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ const entryPoints = [
// sheets-multi
'./src/sheets-multi/main.tsx',

// sheets-multi-units
'./src/sheets-multi-units/main.ts',

// sheets-uniscript
'./src/sheets-uniscript/main.ts',

Expand Down
3 changes: 3 additions & 0 deletions examples/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function Examples() {
}, {
title: '🗂️ Sheets Multi Instance',
href: './sheets-multi/',
}, {
title: '🏡 Sheets Multi Units',
href: './sheets-multi-units/',
}, {
title: '📄 Sheets Uniscript',
href: './sheets-uniscript/',
Expand Down
30 changes: 30 additions & 0 deletions examples/src/sheets-multi-units/lazy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* 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 { Plugin, PluginCtor } from '@univerjs/core';
import { UniverSheetsConditionalFormattingUIPlugin } from '@univerjs/sheets-conditional-formatting-ui';
import { UniverSheetsDataValidationUIPlugin } from '@univerjs/sheets-data-validation-ui';
import { UniverSheetsDrawingUIPlugin } from '@univerjs/sheets-drawing-ui';
import { UniverSheetsFilterUIPlugin } from '@univerjs/sheets-filter-ui';

export default function getLazyPlugins(): Array<[PluginCtor<Plugin>] | [PluginCtor<Plugin>, unknown]> {
return [
[UniverSheetsDataValidationUIPlugin],
[UniverSheetsConditionalFormattingUIPlugin],
[UniverSheetsFilterUIPlugin, { useRemoteFilterValuesGenerator: false }],
[UniverSheetsDrawingUIPlugin],
];
}
201 changes: 201 additions & 0 deletions examples/src/sheets-multi-units/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/**
* 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 { LocaleType, LogLevel, Univer, UserManagerService } from '@univerjs/core';
import { FUniver } from '@univerjs/core/facade';
import { defaultTheme } from '@univerjs/design';
import { UniverDocsPlugin } from '@univerjs/docs';
import { UniverDocsDrawingUIPlugin } from '@univerjs/docs-drawing-ui';
import { UniverDocsMentionUIPlugin } from '@univerjs/docs-mention-ui';
import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
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 { 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 { UniverSheetsNumfmtUIPlugin } from '@univerjs/sheets-numfmt-ui';
import { UniverSheetsSortPlugin } from '@univerjs/sheets-sort';
import { UniverSheetsBindingSourcePlugin } from '@univerjs/sheets-source-binding';
import { UniverSheetsThreadCommentPlugin } from '@univerjs/sheets-thread-comment';
import { UniverSheetsThreadCommentUIPlugin } from '@univerjs/sheets-thread-comment-ui';
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';
import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor';
import { UniverThreadCommentUIPlugin } from '@univerjs/thread-comment-ui';
import { UniverUIPlugin } from '@univerjs/ui';

import { enUS, faIR, frFR, ruRU, viVN, zhCN, zhTW } from '../locales';

import '@univerjs/sheets/facade';
import '@univerjs/ui/facade';
import '@univerjs/docs-ui/facade';
import '@univerjs/sheets-ui/facade';
import '@univerjs/sheets-data-validation/facade';
import '@univerjs/engine-formula/facade';
import '@univerjs/sheets-filter/facade';
import '@univerjs/sheets-formula/facade';
import '@univerjs/sheets-numfmt/facade';
import '@univerjs/sheets-hyper-link-ui/facade';
import '@univerjs/sheets-thread-comment/facade';
import '@univerjs/sheets-conditional-formatting/facade';
import '@univerjs/sheets-find-replace/facade';
import '@univerjs/sheets-drawing-ui/facade';
import '@univerjs/sheets-zen-editor/facade';
import '@univerjs/sheets-source-binding/facade';
import '@univerjs/sheets-crosshair-highlight/facade';
import '@univerjs/sheets-sort/facade';

import '../global.css';
import './styles';

const LOAD_LAZY_PLUGINS_TIMEOUT = 100;
const LOAD_VERY_LAZY_PLUGINS_TIMEOUT = 1_000;

export const mockUser = {
userID: 'Owner_qxVnhPbQ',
name: 'Owner',
avatar: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAInSURBVHgBtZU9TxtBEIbfWRzFSIdkikhBSqRQkJqkCKTCFkqVInSUSaT0wC8w/gXxD4gU2nRJkXQWhAZowDUUWKIwEgWWbEEB3mVmx3dn4DA2nB/ppNuPeWd29mMIPXDr+RxwtgRHeW6+guNPRxogqnL7Dwz9psJ27S4NShaeZTH3kwXy6I81dlRKcmRui88swdq9AcSFL7Buz1Vmlns64MiLsCjzwnIYHLH57tbfFbs7KRaXyEU8FVZofqccOfA5l7Q8LPIkGrwnb2RPNEXWFVMUF3L+kDCk0btDDAMzOm5YfAHDwp4tG74wnzAsiOYMnJ3GoDybA7IT98/jm5+JNnfiIzAS6LlqHQBN/i6b2t/cV1Hh6BfwYlHnHP4AXi5q/8kmMMpOs8+BixZw/Fd6xUEHEbnkgclvQP2fGp7uShRKnQ3G32rkjV1th8JhIGG7tR/JyjGteSOZELwGMmNqIIigRCLRh2OZIE6BjItdd7pCW6Uhm1zzkUtungSxwEUzNpQ+GQumtH1ej1MqgmNT6vwmhCq5yuwq56EYTbgeQUz3yvrpV1b4ok3nYJ+eYhgYmjRUqErx2EDq0Fr8FhG++iqVGqxlUJI/70Ar0UgJaWHj6hYVHJrfKssAHot1JfqwE9WVWzXZVd5z2Ws/4PnmtEjkXeKJDvxUecLbWOXH/DP6QQ4J72NS0adedp1aseBfXP8odlZFfPvBF7SN/8hky1TYuPOAXAEipMx15u5ToAAAAABJRU5ErkJggg==',
anonymous: false,
canBindAnonymous: false,
};

// univer
const univer = new Univer({
theme: defaultTheme,
locale: LocaleType.ZH_CN,
locales: {
[LocaleType.ZH_CN]: zhCN,
[LocaleType.EN_US]: enUS,
[LocaleType.FR_FR]: frFR,
[LocaleType.RU_RU]: ruRU,
[LocaleType.ZH_TW]: zhTW,
[LocaleType.VI_VN]: viVN,
[LocaleType.FA_IR]: faIR,
},
logLevel: LogLevel.VERBOSE,
});

const worker = new Worker(new URL('./worker.js', import.meta.url), { type: 'module' });
univer.registerPlugin(UniverRPCMainThreadPlugin, { workerURL: worker });

univer.registerPlugin(UniverDocsPlugin);
univer.registerPlugin(UniverRenderEnginePlugin);
univer.registerPlugin(UniverUIPlugin, { container: 'app' });
univer.registerPlugin(UniverDocsUIPlugin);
univer.registerPlugin(UniverDocsDrawingUIPlugin);
univer.registerPlugin(UniverDocsMentionUIPlugin);

univer.registerPlugin(UniverSheetsPlugin, { notExecuteFormula: false });
univer.registerPlugin(UniverSheetsUIPlugin);
univer.registerPlugin(UniverSheetsNumfmtPlugin);
univer.registerPlugin(UniverSheetsZenEditorPlugin);
univer.registerPlugin(UniverFormulaEnginePlugin, { notExecuteFormula: false });
univer.registerPlugin(UniverSheetsNumfmtUIPlugin);
univer.registerPlugin(UniverSheetsFormulaPlugin, { notExecuteFormula: false });
univer.registerPlugin(UniverSheetsFormulaUIPlugin);
univer.registerPlugin(UniverSheetsDataValidationPlugin);
univer.registerPlugin(UniverSheetsConditionalFormattingPlugin);
univer.registerPlugin(UniverSheetsFilterPlugin);
univer.registerPlugin(UniverSheetsSortPlugin);
univer.registerPlugin(UniverSheetsHyperLinkPlugin);
univer.registerPlugin(UniverThreadCommentUIPlugin);
univer.registerPlugin(UniverSheetsThreadCommentPlugin);
univer.registerPlugin(UniverSheetsThreadCommentUIPlugin);
univer.registerPlugin(UniverSheetsBindingSourcePlugin);

const injector = univer.__getInjector();
const userManagerService = injector.get(UserManagerService);
userManagerService.setCurrentUser(mockUser);

// create univer sheet instances

setTimeout(() => {
import('./lazy').then((lazy) => {
const plugins = lazy.default();
plugins.forEach((p) => univer.registerPlugin(p[0], p[1]));
});
}, 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);

univer.onDispose(() => {
worker.terminate();
window.univer = undefined;
window.univerAPI = undefined;
});

window.univer = univer;
const univerAPI = window.univerAPI = FUniver.newAPI(univer);

univerAPI.createWorkbook({
id: 'workbook1',
sheetOrder: ['sheet-01'],
sheets: {
'sheet-01': {
id: 'sheet-01',
name: 'Sheet 01',
rowCount: 10,
columnCount: 5,
cellData: { 0: { 0: { f: "=SUM('[workbook2]Sheet 01'!A1:B2)" } } },
},
},
});

univerAPI.createWorkbook(
{
id: 'workbook2',
sheetOrder: ['sheet-01'],
sheets: {
'sheet-01': {
id: 'sheet-01',
name: 'Sheet 01',
rowCount: 10,
columnCount: 5,
cellData: {
0: {
0: { v: 1 },
1: { v: 2 },
},
1: {
0: { v: 3 },
1: { v: 1 },
},
},
},
},
},
{
makeCurrent: false,
}
);

declare global {
// eslint-disable-next-line ts/naming-convention
interface Window {
univer?: Univer;
univerAPI?: ReturnType<typeof FUniver.newAPI>;
}
}
32 changes: 32 additions & 0 deletions examples/src/sheets-multi-units/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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 '@univerjs/sheets-ui/lib/index.css';
import '@univerjs/ui/lib/index.css';
import '@univerjs/design/lib/index.css';
import '@univerjs/docs-ui/lib/index.css';
import '@univerjs/sheets-formula-ui/lib/index.css';
import '@univerjs/sheets-numfmt-ui/lib/index.css';
import '@univerjs/drawing-ui/lib/index.css';
import '@univerjs/docs-drawing-ui/lib/index.css';
import '@univerjs/sheets-data-validation-ui/lib/index.css';
import '@univerjs/sheets-filter-ui/lib/index.css';
import '@univerjs/find-replace/lib/index.css';
import '@univerjs/sheets-hyper-link-ui/lib/index.css';
import '@univerjs/sheets-sort-ui/lib/index.css';
import '@univerjs/thread-comment-ui/lib/index.css';
import '@univerjs/sheets-zen-editor/lib/index.css';
import '@univerjs/uniscript/lib/index.css';
63 changes: 63 additions & 0 deletions examples/src/sheets-multi-units/very-lazy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* 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 { 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';
import { UniverWatermarkPlugin } from '@univerjs/watermark';

/* 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]> = [

[UniverActionRecorderPlugin],
[UniverSheetsHyperLinkUIPlugin],
[UniverSheetsSortUIPlugin],
[UniverSheetsCrosshairHighlightPlugin],
[UniverSheetsFindReplacePlugin],
[UniverWatermarkPlugin],
];

if (!IS_E2E) {
plugins.push([UniverDebuggerPlugin]);
plugins.push([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';
},
}]);
}

return plugins;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {

import type { IUniverEngineFormulaConfig } from '../controller/config.schema';
import type { LexerNode } from '../engine/analysis/lexer-node';
import type { FunctionVariantType } from '../engine/reference-object/base-reference-object';
import type { IAllRuntimeData, IExecutionInProgressParams } from './runtime.service';
import {
createIdentifier,
Expand All @@ -44,7 +45,9 @@ import { AstTreeBuilder } from '../engine/analysis/parser';
import { ErrorNode } from '../engine/ast-node/base-ast-node';
import { IFormulaDependencyGenerator } from '../engine/dependency/formula-dependency';
import { Interpreter } from '../engine/interpreter/interpreter';
import { FORMULA_REF_TO_ARRAY_CACHE, type FunctionVariantType } from '../engine/reference-object/base-reference-object';
import { FORMULA_REF_TO_ARRAY_CACHE } from '../engine/reference-object/base-reference-object';
import { ErrorValueObjectCache } from '../engine/value-object/base-value-object';
import { StringValueObjectCache } from '../engine/value-object/primitive-object';
import { IFormulaCurrentConfigService } from './current-data.service';
import { FormulaExecuteStageType, IFormulaRuntimeService } from './runtime.service';

Expand Down Expand Up @@ -92,6 +95,17 @@ export class CalculateFormulaService extends Disposable {
super();
}

override dispose() {
super.dispose();

this._executionInProgressListener$.complete();
this._executionCompleteListener$.complete();
FORMULA_REF_TO_ARRAY_CACHE.clear();
CELL_INVERTED_INDEX_CACHE.clear();
ErrorValueObjectCache.clear();
StringValueObjectCache.clear();
}

/**
* Stop the execution of the formula.
*/
Expand Down
Loading