mirror of
https://github.com/dream-num/univer.git
synced 2026-09-21 05:44:04 +08:00
fix(engine-formula): fix a race condition on engine computing (#5022)
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { LocaleType, LogLevel, Univer, UserManagerService } from '@univerjs/core';
|
||||
import { CellValueType, LocaleType, LogLevel, Univer, UserManagerService } from '@univerjs/core';
|
||||
import { FUniver } from '@univerjs/core/facade';
|
||||
import { defaultTheme } from '@univerjs/design';
|
||||
import { UniverDocsPlugin } from '@univerjs/docs';
|
||||
@@ -23,7 +23,6 @@ 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';
|
||||
@@ -93,9 +92,6 @@ const univer = new Univer({
|
||||
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' });
|
||||
@@ -103,13 +99,13 @@ univer.registerPlugin(UniverDocsUIPlugin);
|
||||
univer.registerPlugin(UniverDocsDrawingUIPlugin);
|
||||
univer.registerPlugin(UniverDocsMentionUIPlugin);
|
||||
|
||||
univer.registerPlugin(UniverSheetsPlugin, { notExecuteFormula: false });
|
||||
univer.registerPlugin(UniverSheetsPlugin);
|
||||
univer.registerPlugin(UniverSheetsUIPlugin);
|
||||
univer.registerPlugin(UniverSheetsNumfmtPlugin);
|
||||
univer.registerPlugin(UniverSheetsZenEditorPlugin);
|
||||
univer.registerPlugin(UniverFormulaEnginePlugin, { notExecuteFormula: false });
|
||||
univer.registerPlugin(UniverFormulaEnginePlugin);
|
||||
univer.registerPlugin(UniverSheetsNumfmtUIPlugin);
|
||||
univer.registerPlugin(UniverSheetsFormulaPlugin, { notExecuteFormula: false });
|
||||
univer.registerPlugin(UniverSheetsFormulaPlugin);
|
||||
univer.registerPlugin(UniverSheetsFormulaUIPlugin);
|
||||
univer.registerPlugin(UniverSheetsDataValidationPlugin);
|
||||
univer.registerPlugin(UniverSheetsConditionalFormattingPlugin);
|
||||
@@ -125,8 +121,6 @@ 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();
|
||||
@@ -142,24 +136,47 @@ setTimeout(() => {
|
||||
}, 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);
|
||||
window.univerAPI = FUniver.newAPI(univer);
|
||||
|
||||
const univerAPI = window.univerAPI;
|
||||
|
||||
univerAPI.createWorkbook({
|
||||
id: 'workbook1',
|
||||
sheetOrder: ['sheet-01'],
|
||||
resources: [
|
||||
],
|
||||
sheets: {
|
||||
'sheet-01': {
|
||||
id: 'sheet-01',
|
||||
name: 'Sheet 01',
|
||||
rowCount: 10,
|
||||
columnCount: 5,
|
||||
cellData: { 0: { 0: { f: "=SUM('[workbook2]Sheet 01'!A1:B2)" } } },
|
||||
rowCount: 20,
|
||||
columnCount: 40,
|
||||
cellData: {
|
||||
0: {
|
||||
1: { t: CellValueType.NUMBER, v: 10 },
|
||||
},
|
||||
5: {
|
||||
0: {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'sheet-02': {
|
||||
id: 'sheet-02',
|
||||
name: 'foobar',
|
||||
rowCount: 20,
|
||||
columnCount: 40,
|
||||
cellData: {
|
||||
5: {
|
||||
0: {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -172,8 +189,8 @@ univerAPI.createWorkbook(
|
||||
'sheet-01': {
|
||||
id: 'sheet-01',
|
||||
name: 'Sheet 01',
|
||||
rowCount: 10,
|
||||
columnCount: 5,
|
||||
rowCount: 20,
|
||||
columnCount: 40,
|
||||
cellData: {
|
||||
0: {
|
||||
0: { v: 1 },
|
||||
@@ -181,7 +198,23 @@ univerAPI.createWorkbook(
|
||||
},
|
||||
1: {
|
||||
0: { v: 3 },
|
||||
1: { v: 1 },
|
||||
1: { v: 4 },
|
||||
},
|
||||
5: {
|
||||
0: {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'sheet-02': {
|
||||
id: 'sheet-02',
|
||||
name: 'foobar',
|
||||
rowCount: 20,
|
||||
columnCount: 40,
|
||||
cellData: {
|
||||
5: {
|
||||
0: {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -192,6 +225,86 @@ univerAPI.createWorkbook(
|
||||
}
|
||||
);
|
||||
|
||||
univerAPI.createWorkbook({
|
||||
id: 'workbook3',
|
||||
sheetOrder: ['sheet-01'],
|
||||
sheets: {
|
||||
'sheet-01': {
|
||||
id: 'sheet-01',
|
||||
name: 'Sheet 01',
|
||||
rowCount: 20,
|
||||
columnCount: 40,
|
||||
cellData: {
|
||||
0: {
|
||||
0: { v: 1 },
|
||||
1: { v: 2 },
|
||||
},
|
||||
1: {
|
||||
0: { v: 3 },
|
||||
1: { v: 4 },
|
||||
},
|
||||
5: {
|
||||
0: {
|
||||
f: "='[workbook1]Sheet 01'!A5 * '[workbook2]Sheet 01'!A5 * '[workbook3]Sheet 01'!A5* '[workbook4]Sheet 01'!A5",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'sheet-02': {
|
||||
id: 'sheet-02',
|
||||
name: 'foobar',
|
||||
rowCount: 20,
|
||||
columnCount: 40,
|
||||
cellData: {
|
||||
5: {
|
||||
0: {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
univerAPI.createWorkbook({
|
||||
id: 'workbook4',
|
||||
sheetOrder: ['sheet-01'],
|
||||
sheets: {
|
||||
'sheet-01': {
|
||||
id: 'sheet-01',
|
||||
name: 'Sheet 01',
|
||||
rowCount: 20,
|
||||
columnCount: 40,
|
||||
cellData: {
|
||||
0: {
|
||||
0: { v: 1 },
|
||||
1: { v: 2 },
|
||||
},
|
||||
1: {
|
||||
0: { v: 3 },
|
||||
1: { v: 4 },
|
||||
},
|
||||
5: {
|
||||
0: {
|
||||
f: "='[workbook1]Sheet 01'!A5 * '[workbook2]Sheet 01'!A5 * '[workbook3]Sheet 01'!A5* '[workbook4]Sheet 01'!A5",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'sheet-02': {
|
||||
id: 'sheet-02',
|
||||
name: 'foobar',
|
||||
rowCount: 20,
|
||||
columnCount: 40,
|
||||
cellData: {
|
||||
5: {
|
||||
0: {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line ts/naming-convention
|
||||
interface Window {
|
||||
|
||||
+2
-423
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ILogService, LocaleType, LogLevel, Univer, UniverInstanceType, UserManagerService } from '@univerjs/core';
|
||||
import { LocaleType, LogLevel, Univer, UniverInstanceType, UserManagerService } from '@univerjs/core';
|
||||
import { FUniver } from '@univerjs/core/facade';
|
||||
import { UniverDebuggerPlugin } from '@univerjs/debugger';
|
||||
import { defaultTheme } from '@univerjs/design';
|
||||
@@ -43,11 +43,10 @@ import { UniverSheetsThreadCommentUIPlugin } from '@univerjs/sheets-thread-comme
|
||||
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';
|
||||
import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor';
|
||||
import { UniverThreadCommentUIPlugin } from '@univerjs/thread-comment-ui';
|
||||
import { BuiltInUIPart, UniverUIPlugin } from '@univerjs/ui';
|
||||
import { UniverUIPlugin } from '@univerjs/ui';
|
||||
|
||||
import { enUS, faIR, frFR, ruRU, viVN, zhCN, zhTW } from '../locales';
|
||||
|
||||
import { ButtonRangeSelector } from './button';
|
||||
import { UniverSheetsCustomMenuPlugin } from './custom-menu';
|
||||
import '@univerjs/sheets/facade';
|
||||
import '@univerjs/ui/facade';
|
||||
@@ -186,423 +185,3 @@ declare global {
|
||||
createNewInstance?: typeof createNewInstance;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-lines-per-function, complexity
|
||||
function initEvent() {
|
||||
const logService = window.univer!.__getInjector().get(ILogService);
|
||||
|
||||
// Workbook Events
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.WorkbookCreated, (params) => {
|
||||
logService.log('===WorkbookCreated', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.WorkbookDisposed, (params) => {
|
||||
logService.log('===WorkbookDisposed', params);
|
||||
});
|
||||
|
||||
// Sheet Lifecycle Events
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetCreate, (params) => {
|
||||
logService.log('===BeforeSheetCreate', params);
|
||||
});
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetCreated, (params) => {
|
||||
logService.log('===SheetCreated', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetDelete, (params) => {
|
||||
logService.log('===BeforeSheetDelete', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetDeleted, (params) => {
|
||||
logService.log('===SheetDeleted', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetMove, (params) => {
|
||||
logService.log('===BeforeSheetMove', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetMoved, (params) => {
|
||||
logService.log('===SheetMoved', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetNameChange, (params) => {
|
||||
logService.log('===BeforeSheetNameChange', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetNameChanged, (params) => {
|
||||
logService.log('===SheetNameChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetHideChange, (params) => {
|
||||
logService.log('===BeforeSheetHideChange', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetHideChanged, (params) => {
|
||||
logService.log('===SheetHideChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CellClicked, (params) => {
|
||||
logService.log('===CellClicked', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CellHover, (params) => {
|
||||
logService.log('===CellHover', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CellPointerDown, (params) => {
|
||||
logService.log('===CellPointerDown', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CellPointerUp, (params) => {
|
||||
logService.log('===CellPointerUp', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CellPointerMove, (params) => {
|
||||
logService.log('===CellPointerMove', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SelectionChanged, (params) => {
|
||||
logService.log('===SelectionChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SelectionMoveStart, (params) => {
|
||||
logService.log('===SelectionMoveStart', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SelectionMoveEnd, (params) => {
|
||||
logService.log('===SelectionMoveEnd', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SelectionMoving, (params) => {
|
||||
logService.log('===SelectionMoving', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetEditStart, (params) => {
|
||||
logService.log('===BeforeSheetEditStart', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetEditStarted, (params) => {
|
||||
logService.log('===SheetEditStarted', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetEditChanging, (params) => {
|
||||
logService.log('===SheetEditChanging', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetEditEnd, (params) => {
|
||||
logService.log('===BeforeSheetEditEnd', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetEditEnded, (params) => {
|
||||
logService.log('===SheetEditEnded', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetValueChanged, (params) => {
|
||||
logService.log('===SheetValueChanged', params);
|
||||
});
|
||||
|
||||
// Clipboard Events
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeClipboardChange, (params) => {
|
||||
logService.log('===BeforeClipboardChange', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ClipboardChanged, (params) => {
|
||||
logService.log('===ClipboardChanged', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeClipboardPaste, (params) => {
|
||||
logService.log('===BeforeClipboardPaste', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ClipboardPasted, (params) => {
|
||||
logService.log('===ClipboardPasted', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeGridlineEnableChange, (params) => {
|
||||
logService.log('===BeforeGridlineEnableChange', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeGridlineColorChange, (params) => {
|
||||
logService.log('===BeforeGridlineColorChange', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.GridlineChanged, (params) => {
|
||||
logService.log('===GridlineChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetZoomChange, (params) => {
|
||||
logService.log('===BeforeSheetZoomChange', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetZoomChanged, (params) => {
|
||||
logService.log('===SheetZoomChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.Scroll, (params) => {
|
||||
logService.log('===Scroll', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetSkeletonChanged, (params) => {
|
||||
logService.log('===SheetSkeletonChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetDataValidationAdd, (params) => {
|
||||
logService.log('===BeforeSheetDataValidationAdd', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetDataValidationChanged, (params) => {
|
||||
logService.log('===SheetDataValidationChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetDataValidatorStatusChanged, (params) => {
|
||||
logService.log('===SheetDataValidatorStatusChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetBeforeRangeFilter, (params) => {
|
||||
logService.log('===SheetBeforeRangeFilter', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetRangeFiltered, (params) => {
|
||||
logService.log('===SheetRangeFiltered', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetBeforeRangeSort, (params) => {
|
||||
logService.log('===SheetBeforeRangeSort', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetRangeSorted, (params) => {
|
||||
logService.log('===SheetRangeSorted', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetBeforeRangeFilterClear, (params) => {
|
||||
logService.log('===SheetBeforeRangeFilterClear', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetRangeFilterCleared, (params) => {
|
||||
logService.log('===SheetRangeFilterCleared', params);
|
||||
});
|
||||
|
||||
// Image Events
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeOverGridImageInsert, (params) => {
|
||||
logService.log('===BeforeOverGridImageInsert', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.OverGridImageInserted, (params) => {
|
||||
logService.log('===OverGridImageInserted', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeOverGridImageChange, (params) => {
|
||||
logService.log('===BeforeOverGridImageChange', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.OverGridImageChanged, (params) => {
|
||||
logService.log('===OverGridImageChanged', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeOverGridImageRemove, (params) => {
|
||||
logService.log('===BeforeOverGridImageRemove', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.OverGridImageRemoved, (params) => {
|
||||
logService.log('===OverGridImageRemoved', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeOverGridImageSelect, (params) => {
|
||||
logService.log('===BeforeOverGridImageSelect', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.OverGridImageSelected, (params) => {
|
||||
logService.log('===OverGridImageSelected', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeCommentAdd, (params) => {
|
||||
logService.log('===BeforeCommentAdd', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CommentAdded, (params) => {
|
||||
logService.log('===CommentAdded', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeCommentUpdate, (params) => {
|
||||
logService.log('===BeforeCommentUpdate', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CommentUpdated, (params) => {
|
||||
logService.log('===CommentUpdated', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeCommentDelete, (params) => {
|
||||
logService.log('===BeforeCommentDelete', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CommentDeleted, (params) => {
|
||||
logService.log('===CommentDeleted', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeCommentResolve, (params) => {
|
||||
logService.log('===BeforeCommentResolve', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CommentResolved, (params) => {
|
||||
logService.log('===CommentResolved', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.RowHeaderClick, (params) => {
|
||||
logService.log('===RowHeaderClick', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.RowHeaderHover, (params) => {
|
||||
logService.log('===RowHeaderHover', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.RowHeaderPointerDown, (params) => {
|
||||
logService.log('===RowHeaderPointerDown', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.RowHeaderPointerUp, (params) => {
|
||||
logService.log('===RowHeaderPointerUp', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ColumnHeaderClick, (params) => {
|
||||
logService.log('===ColumnHeaderClick', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ColumnHeaderHover, (params) => {
|
||||
logService.log('===ColumnHeaderHover', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ColumnHeaderPointerDown, (params) => {
|
||||
logService.log('===ColumnHeaderPointerDown', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ColumnHeaderPointerUp, (params) => {
|
||||
logService.log('===ColumnHeaderPointerUp', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetLinkAdd, (params) => {
|
||||
logService.log('===BeforeSheetLinkAdd', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetLinkUpdate, (params) => {
|
||||
logService.log('===BeforeSheetLinkUpdate', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetLinkCancel, (params) => {
|
||||
logService.log('===BeforeSheetLinkCancel', params);
|
||||
});
|
||||
|
||||
// Drag and Drop Events
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.DragOver, (params) => {
|
||||
logService.log('===DragOver', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.Drop, (params) => {
|
||||
logService.log('===Drop', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CrosshairHighlightColorChanged, (params) => {
|
||||
logService.log('===CrosshairHighlightColorChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CrosshairHighlightEnabledChanged, (params) => {
|
||||
logService.log('===CrosshairHighlightEnabledChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetEditStart, (params) => {
|
||||
const { row, column } = params;
|
||||
if (row === 0 && column === 0) {
|
||||
params.cancel = true;
|
||||
}
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ActiveSheetChanged, (params) => {
|
||||
logService.log('===active sheet changed', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetEditChanging, (params) => {
|
||||
logService.log('===SheetEditChanging', params);
|
||||
});
|
||||
}
|
||||
|
||||
// initEvent();
|
||||
function initFacadeBtns() {
|
||||
window.univerAPI?.registerUIPart(BuiltInUIPart.CUSTOM_HEADER, ButtonRangeSelector);
|
||||
}
|
||||
|
||||
// setTimeout(() => {
|
||||
// const active = window.univerAPI?.getActiveSheet();
|
||||
// console.log('==active', active, window.univerAPI);
|
||||
// if (!active) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// window.univerAPI?.showRangeSelectorDialog({
|
||||
// unitId: active.workbook.getId(),
|
||||
// subUnitId: active.worksheet.getSheetId(),
|
||||
// callback: (ranges, isCancel) => {
|
||||
// console.log('===range selector dialog result', ranges, isCancel);
|
||||
// },
|
||||
// });
|
||||
// }, 5000);
|
||||
|
||||
@@ -0,0 +1,439 @@
|
||||
/**
|
||||
* 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 { ILogService } from '@univerjs/core';
|
||||
import { BuiltInUIPart } from '@univerjs/ui';
|
||||
import { ButtonRangeSelector } from './button';
|
||||
|
||||
// eslint-disable-next-line max-lines-per-function, complexity
|
||||
export function initEvent() {
|
||||
const logService = window.univer!.__getInjector().get(ILogService);
|
||||
|
||||
// Workbook Events
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.WorkbookCreated, (params) => {
|
||||
logService.log('===WorkbookCreated', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.WorkbookDisposed, (params) => {
|
||||
logService.log('===WorkbookDisposed', params);
|
||||
});
|
||||
|
||||
// Sheet Lifecycle Events
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetCreate, (params) => {
|
||||
logService.log('===BeforeSheetCreate', params);
|
||||
});
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetCreated, (params) => {
|
||||
logService.log('===SheetCreated', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetDelete, (params) => {
|
||||
logService.log('===BeforeSheetDelete', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetDeleted, (params) => {
|
||||
logService.log('===SheetDeleted', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetMove, (params) => {
|
||||
logService.log('===BeforeSheetMove', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetMoved, (params) => {
|
||||
logService.log('===SheetMoved', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetNameChange, (params) => {
|
||||
logService.log('===BeforeSheetNameChange', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetNameChanged, (params) => {
|
||||
logService.log('===SheetNameChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetHideChange, (params) => {
|
||||
logService.log('===BeforeSheetHideChange', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetHideChanged, (params) => {
|
||||
logService.log('===SheetHideChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CellClicked, (params) => {
|
||||
logService.log('===CellClicked', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CellHover, (params) => {
|
||||
logService.log('===CellHover', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CellPointerDown, (params) => {
|
||||
logService.log('===CellPointerDown', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CellPointerUp, (params) => {
|
||||
logService.log('===CellPointerUp', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CellPointerMove, (params) => {
|
||||
logService.log('===CellPointerMove', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SelectionChanged, (params) => {
|
||||
logService.log('===SelectionChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SelectionMoveStart, (params) => {
|
||||
logService.log('===SelectionMoveStart', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SelectionMoveEnd, (params) => {
|
||||
logService.log('===SelectionMoveEnd', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SelectionMoving, (params) => {
|
||||
logService.log('===SelectionMoving', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetEditStart, (params) => {
|
||||
logService.log('===BeforeSheetEditStart', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetEditStarted, (params) => {
|
||||
logService.log('===SheetEditStarted', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetEditChanging, (params) => {
|
||||
logService.log('===SheetEditChanging', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetEditEnd, (params) => {
|
||||
logService.log('===BeforeSheetEditEnd', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetEditEnded, (params) => {
|
||||
logService.log('===SheetEditEnded', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetValueChanged, (params) => {
|
||||
logService.log('===SheetValueChanged', params);
|
||||
});
|
||||
|
||||
// Clipboard Events
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeClipboardChange, (params) => {
|
||||
logService.log('===BeforeClipboardChange', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ClipboardChanged, (params) => {
|
||||
logService.log('===ClipboardChanged', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeClipboardPaste, (params) => {
|
||||
logService.log('===BeforeClipboardPaste', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ClipboardPasted, (params) => {
|
||||
logService.log('===ClipboardPasted', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeGridlineEnableChange, (params) => {
|
||||
logService.log('===BeforeGridlineEnableChange', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeGridlineColorChange, (params) => {
|
||||
logService.log('===BeforeGridlineColorChange', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.GridlineChanged, (params) => {
|
||||
logService.log('===GridlineChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetZoomChange, (params) => {
|
||||
logService.log('===BeforeSheetZoomChange', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetZoomChanged, (params) => {
|
||||
logService.log('===SheetZoomChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.Scroll, (params) => {
|
||||
logService.log('===Scroll', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetSkeletonChanged, (params) => {
|
||||
logService.log('===SheetSkeletonChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetDataValidationAdd, (params) => {
|
||||
logService.log('===BeforeSheetDataValidationAdd', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetDataValidationChanged, (params) => {
|
||||
logService.log('===SheetDataValidationChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetDataValidatorStatusChanged, (params) => {
|
||||
logService.log('===SheetDataValidatorStatusChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetBeforeRangeFilter, (params) => {
|
||||
logService.log('===SheetBeforeRangeFilter', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetRangeFiltered, (params) => {
|
||||
logService.log('===SheetRangeFiltered', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetBeforeRangeSort, (params) => {
|
||||
logService.log('===SheetBeforeRangeSort', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetRangeSorted, (params) => {
|
||||
logService.log('===SheetRangeSorted', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetBeforeRangeFilterClear, (params) => {
|
||||
logService.log('===SheetBeforeRangeFilterClear', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetRangeFilterCleared, (params) => {
|
||||
logService.log('===SheetRangeFilterCleared', params);
|
||||
});
|
||||
|
||||
// Image Events
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeOverGridImageInsert, (params) => {
|
||||
logService.log('===BeforeOverGridImageInsert', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.OverGridImageInserted, (params) => {
|
||||
logService.log('===OverGridImageInserted', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeOverGridImageChange, (params) => {
|
||||
logService.log('===BeforeOverGridImageChange', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.OverGridImageChanged, (params) => {
|
||||
logService.log('===OverGridImageChanged', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeOverGridImageRemove, (params) => {
|
||||
logService.log('===BeforeOverGridImageRemove', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.OverGridImageRemoved, (params) => {
|
||||
logService.log('===OverGridImageRemoved', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeOverGridImageSelect, (params) => {
|
||||
logService.log('===BeforeOverGridImageSelect', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.OverGridImageSelected, (params) => {
|
||||
logService.log('===OverGridImageSelected', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeCommentAdd, (params) => {
|
||||
logService.log('===BeforeCommentAdd', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CommentAdded, (params) => {
|
||||
logService.log('===CommentAdded', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeCommentUpdate, (params) => {
|
||||
logService.log('===BeforeCommentUpdate', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CommentUpdated, (params) => {
|
||||
logService.log('===CommentUpdated', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeCommentDelete, (params) => {
|
||||
logService.log('===BeforeCommentDelete', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CommentDeleted, (params) => {
|
||||
logService.log('===CommentDeleted', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeCommentResolve, (params) => {
|
||||
logService.log('===BeforeCommentResolve', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CommentResolved, (params) => {
|
||||
logService.log('===CommentResolved', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.RowHeaderClick, (params) => {
|
||||
logService.log('===RowHeaderClick', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.RowHeaderHover, (params) => {
|
||||
logService.log('===RowHeaderHover', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.RowHeaderPointerDown, (params) => {
|
||||
logService.log('===RowHeaderPointerDown', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.RowHeaderPointerUp, (params) => {
|
||||
logService.log('===RowHeaderPointerUp', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ColumnHeaderClick, (params) => {
|
||||
logService.log('===ColumnHeaderClick', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ColumnHeaderHover, (params) => {
|
||||
logService.log('===ColumnHeaderHover', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ColumnHeaderPointerDown, (params) => {
|
||||
logService.log('===ColumnHeaderPointerDown', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ColumnHeaderPointerUp, (params) => {
|
||||
logService.log('===ColumnHeaderPointerUp', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetLinkAdd, (params) => {
|
||||
logService.log('===BeforeSheetLinkAdd', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetLinkUpdate, (params) => {
|
||||
logService.log('===BeforeSheetLinkUpdate', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetLinkCancel, (params) => {
|
||||
logService.log('===BeforeSheetLinkCancel', params);
|
||||
});
|
||||
|
||||
// Drag and Drop Events
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.DragOver, (params) => {
|
||||
logService.log('===DragOver', params);
|
||||
});
|
||||
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.Drop, (params) => {
|
||||
logService.log('===Drop', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CrosshairHighlightColorChanged, (params) => {
|
||||
logService.log('===CrosshairHighlightColorChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.CrosshairHighlightEnabledChanged, (params) => {
|
||||
logService.log('===CrosshairHighlightEnabledChanged', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.BeforeSheetEditStart, (params) => {
|
||||
const { row, column } = params;
|
||||
if (row === 0 && column === 0) {
|
||||
params.cancel = true;
|
||||
}
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.ActiveSheetChanged, (params) => {
|
||||
logService.log('===active sheet changed', params);
|
||||
});
|
||||
|
||||
// checked
|
||||
window.univerAPI?.addEvent(window.univerAPI.Event.SheetEditChanging, (params) => {
|
||||
logService.log('===SheetEditChanging', params);
|
||||
});
|
||||
}
|
||||
|
||||
// initEvent();
|
||||
export function initFacadeBtns() {
|
||||
window.univerAPI?.registerUIPart(BuiltInUIPart.CUSTOM_HEADER, ButtonRangeSelector);
|
||||
}
|
||||
|
||||
// setTimeout(() => {
|
||||
// const active = window.univerAPI?.getActiveSheet();
|
||||
// console.log('==active', active, window.univerAPI);
|
||||
// if (!active) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// window.univerAPI?.showRangeSelectorDialog({
|
||||
// unitId: active.workbook.getId(),
|
||||
// subUnitId: active.worksheet.getSheetId(),
|
||||
// callback: (ranges, isCancel) => {
|
||||
// console.log('===range selector dialog result', ranges, isCancel);
|
||||
// },
|
||||
// });
|
||||
// }, 5000);
|
||||
@@ -34,7 +34,6 @@ export const DisposeUniverCommand: ICommand = {
|
||||
window.univer?.dispose();
|
||||
window.univer = undefined;
|
||||
window.univerAPI = undefined;
|
||||
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
"dependencies": {
|
||||
"@univerjs/protocol": "0.1.45",
|
||||
"@wendellhu/redi": "0.17.1",
|
||||
"async-lock": "^1.4.1",
|
||||
"dayjs": "^1.11.13",
|
||||
"fast-diff": "1.3.0",
|
||||
"kdbush": "^4.0.2",
|
||||
@@ -86,6 +87,7 @@
|
||||
"rbush": "^4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/async-lock": "^1.4.2",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/numeral": "^2.0.5",
|
||||
"@types/rbush": "^4.0.0",
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 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 AsyncLock from 'async-lock';
|
||||
|
||||
export { AsyncLock };
|
||||
@@ -25,6 +25,7 @@ export { dedupe, groupBy, makeArray, remove, rotate } from './common/array';
|
||||
export { isBooleanString } from './common/boolean';
|
||||
export * from './common/const';
|
||||
export * from './common/di';
|
||||
export * from './common/async';
|
||||
export { shallowEqual } from './common/equal';
|
||||
export { ParagraphStyleBuilder, ParagraphStyleValue, RichTextBuilder, RichTextValue, TextDecorationBuilder, TextStyleBuilder, TextStyleValue } from './docs/data-model/rich-text-builder';
|
||||
export { CanceledError, CustomCommandExecutionError } from './common/error';
|
||||
|
||||
@@ -56,12 +56,9 @@ export class CalculateController extends Disposable {
|
||||
if (command.id === SetFormulaCalculationStopMutation.id) {
|
||||
this._calculateFormulaService.stopFormulaExecution();
|
||||
} else if (command.id === SetFormulaCalculationStartMutation.id) {
|
||||
const params = command.params as ISetFormulaCalculationStartMutation;
|
||||
|
||||
this._calculate(params);
|
||||
this._calculate(command.params as ISetFormulaCalculationStartMutation);
|
||||
} else if (command.id === SetArrayFormulaDataMutation.id) {
|
||||
const params = command.params as ISetArrayFormulaDataMutationParams;
|
||||
|
||||
if (params == null) {
|
||||
return;
|
||||
}
|
||||
@@ -81,9 +78,7 @@ export class CalculateController extends Disposable {
|
||||
const { forceCalculation: forceCalculate = false, dirtyRanges = [], dirtyNameMap = {}, dirtyDefinedNameMap = {}, dirtyUnitFeatureMap = {}, dirtyUnitOtherFormulaMap = {}, clearDependencyTreeCache = {}, maxIteration = DEFAULT_CYCLE_REFERENCE_COUNT, rowData } = formulaDirtyData;
|
||||
|
||||
const formulaData = this._formulaDataModel.getFormulaData();
|
||||
|
||||
const arrayFormulaCellData = this._formulaDataModel.getArrayFormulaCellData();
|
||||
|
||||
// array formula range is used to check whether the newly added array formula conflicts with the existing array formula
|
||||
const arrayFormulaRange = this._formulaDataModel.getArrayFormulaRange();
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { IRange, IUnitRange, Nullable } from '@univerjs/core';
|
||||
import type {
|
||||
IDirtyUnitSheetNameMap,
|
||||
IFeatureDirtyRangeType,
|
||||
@@ -21,10 +22,10 @@ import type {
|
||||
IUnitExcludedCell,
|
||||
} from '../../basics/common';
|
||||
import type { IFormulaDirtyData } from '../../services/current-data.service';
|
||||
import type { IAllRuntimeData } from '../../services/runtime.service';
|
||||
|
||||
import type { IAllRuntimeData } from '../../services/runtime.service';
|
||||
import type { AstRootNode, FunctionNode } from '../ast-node';
|
||||
import { type IRange, type IUnitRange, moveRangeByOffset, type Nullable } from '@univerjs/core';
|
||||
import { moveRangeByOffset } from '@univerjs/core';
|
||||
|
||||
export enum FDtreeStateType {
|
||||
DEFAULT,
|
||||
|
||||
@@ -388,7 +388,6 @@ export class FormulaDependencyGenerator extends Disposable {
|
||||
}
|
||||
|
||||
await this._calculateListByFunctionRefNode(treeList);
|
||||
|
||||
return treeList;
|
||||
}
|
||||
|
||||
@@ -1239,6 +1238,7 @@ export class FormulaDependencyGenerator extends Disposable {
|
||||
* @param treeList
|
||||
*/
|
||||
protected _calculateRunList(treeList: IFormulaDependencyTree[]) {
|
||||
const originalLength = treeList.length;
|
||||
const stack = treeList;
|
||||
const formulaRunList = [];
|
||||
const cacheStack: IFormulaDependencyTree[] = [];
|
||||
|
||||
@@ -332,14 +332,15 @@ export function getReferenceObjectFromCache(trimToken: string, type: ReferenceOb
|
||||
}
|
||||
|
||||
export function getRangeReferenceObjectFromCache(variant1: BaseReferenceObject, variant2: BaseReferenceObject) {
|
||||
let referenceObject: FunctionVariantType = ErrorValueObject.create(ErrorType.NAME);
|
||||
let referenceObject: FunctionVariantType;
|
||||
if (variant1.isCell() && variant2.isCell()) {
|
||||
referenceObject = variant1.unionBy(variant2) as BaseReferenceObject;
|
||||
} else if (variant1.isRow() && variant2.isRow()) {
|
||||
referenceObject = variant1.unionBy(variant2) as BaseReferenceObject;
|
||||
} else if (variant1.isColumn() && variant2.isColumn()) {
|
||||
referenceObject = variant1.unionBy(variant2) as BaseReferenceObject;
|
||||
} else {
|
||||
referenceObject = ErrorValueObject.create(ErrorType.NAME);
|
||||
}
|
||||
|
||||
return referenceObject;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ 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 {
|
||||
AsyncLock,
|
||||
createIdentifier,
|
||||
Disposable,
|
||||
IConfigService,
|
||||
@@ -58,31 +59,26 @@ export const CYCLE_REFERENCE_COUNT = 'cycleReferenceCount';
|
||||
export const EVERY_N_FUNCTION_EXECUTION_PAUSE = 100;
|
||||
|
||||
export interface ICalculateFormulaService {
|
||||
executionInProgressListener$: Observable<IExecutionInProgressParams>;
|
||||
executionCompleteListener$: Observable<IAllRuntimeData>;
|
||||
|
||||
readonly executionInProgressListener$: Observable<IExecutionInProgressParams>;
|
||||
readonly executionCompleteListener$: Observable<IAllRuntimeData>;
|
||||
setRuntimeFeatureCellData(featureId: string, featureData: IRuntimeUnitDataType): void;
|
||||
|
||||
setRuntimeFeatureRange(featureId: string, featureRange: IFeatureDirtyRangeType): void;
|
||||
|
||||
execute(formulaDatasetConfig: IFormulaDatasetConfig): Promise<void>;
|
||||
|
||||
stopFormulaExecution(): void;
|
||||
|
||||
calculate(formulaString: string, transformSuffix?: boolean): void;
|
||||
}
|
||||
|
||||
export const ICalculateFormulaService = createIdentifier<ICalculateFormulaService>('engine-formula.calculate-formula.service');
|
||||
|
||||
export class CalculateFormulaService extends Disposable {
|
||||
export class CalculateFormulaService extends Disposable implements ICalculateFormulaService {
|
||||
protected readonly _executionInProgressListener$ = new Subject<IExecutionInProgressParams>();
|
||||
|
||||
readonly executionInProgressListener$ = this._executionInProgressListener$.asObservable();
|
||||
|
||||
protected readonly _executionCompleteListener$ = new Subject<IAllRuntimeData>();
|
||||
|
||||
readonly executionCompleteListener$ = this._executionCompleteListener$.asObservable();
|
||||
|
||||
private _executeLock = new AsyncLock();
|
||||
|
||||
constructor(
|
||||
@IConfigService protected readonly _configService: IConfigService,
|
||||
@Inject(Lexer) protected readonly _lexer: Lexer,
|
||||
@@ -138,30 +134,28 @@ export class CalculateFormulaService extends Disposable {
|
||||
|
||||
const cycleReferenceCount = (formulaDatasetConfig.maxIteration || DEFAULT_CYCLE_REFERENCE_COUNT) as number;
|
||||
|
||||
for (let i = 0; i < cycleReferenceCount; i++) {
|
||||
this._runtimeService.setFormulaCycleIndex(i);
|
||||
await this._execute();
|
||||
this._executeLock.acquire('FORMULA_EXECUTION_LOCK', async () => {
|
||||
for (let i = 0; i < cycleReferenceCount; i++) {
|
||||
this._runtimeService.setFormulaCycleIndex(i);
|
||||
await this._executeStep();
|
||||
|
||||
FORMULA_REF_TO_ARRAY_CACHE.clear();
|
||||
FORMULA_REF_TO_ARRAY_CACHE.clear();
|
||||
|
||||
const isCycleDependency = this._runtimeService.isCycleDependency();
|
||||
if (!isCycleDependency) {
|
||||
break;
|
||||
const isCycleDependency = this._runtimeService.isCycleDependency();
|
||||
if (!isCycleDependency) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._runtimeService.setFormulaExecuteStage(FormulaExecuteStageType.CALCULATION_COMPLETED);
|
||||
|
||||
this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());
|
||||
|
||||
this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());
|
||||
|
||||
CELL_INVERTED_INDEX_CACHE.clear();
|
||||
|
||||
this._runtimeService.reset();
|
||||
this._runtimeService.setFormulaExecuteStage(FormulaExecuteStageType.CALCULATION_COMPLETED);
|
||||
this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());
|
||||
this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());
|
||||
CELL_INVERTED_INDEX_CACHE.clear();
|
||||
this._runtimeService.reset();
|
||||
});
|
||||
}
|
||||
|
||||
private async _execute() {
|
||||
private async _executeStep() {
|
||||
const executeState = await this._apply();
|
||||
|
||||
if (executeState == null) {
|
||||
@@ -287,9 +281,9 @@ export class CalculateFormulaService extends Disposable {
|
||||
|
||||
// Execute the await every 100 iterations
|
||||
if (i % intervalCount === 0) {
|
||||
/**
|
||||
* For every functions, execute a setTimeout to wait for external command input.
|
||||
*/
|
||||
/**
|
||||
* For every functions, execute a setTimeout to wait for external command input.
|
||||
*/
|
||||
await new Promise((resolve) => {
|
||||
const calCancelTask = requestImmediateMacroTask(resolve);
|
||||
pendingTasks.push(calCancelTask);
|
||||
|
||||
@@ -621,6 +621,7 @@ export class DependencyManagerService extends DependencyManagerBaseService imple
|
||||
id: treeId,
|
||||
});
|
||||
}
|
||||
|
||||
this._dependencyRTreeCache.bulkRemove(searchRanges);
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+16
@@ -1033,6 +1033,9 @@ importers:
|
||||
'@wendellhu/redi':
|
||||
specifier: 0.17.1
|
||||
version: 0.17.1
|
||||
async-lock:
|
||||
specifier: ^1.4.1
|
||||
version: 1.4.1
|
||||
dayjs:
|
||||
specifier: ^1.11.13
|
||||
version: 1.11.13
|
||||
@@ -1061,6 +1064,9 @@ importers:
|
||||
specifier: ^4.0.1
|
||||
version: 4.0.1
|
||||
devDependencies:
|
||||
'@types/async-lock':
|
||||
specifier: ^1.4.2
|
||||
version: 1.4.2
|
||||
'@types/lodash-es':
|
||||
specifier: ^4.17.12
|
||||
version: 4.17.12
|
||||
@@ -5354,6 +5360,9 @@ packages:
|
||||
'@types/aria-query@5.0.4':
|
||||
resolution: {integrity: sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==}
|
||||
|
||||
'@types/async-lock@1.4.2':
|
||||
resolution: {integrity: sha512-HlZ6Dcr205BmNhwkdXqrg2vkFMN2PluI7Lgr8In3B3wE5PiQHhjRqtW/lGdVU9gw+sM0JcIDx2AN+cW8oSWIcw==}
|
||||
|
||||
'@types/babel__core@7.20.5':
|
||||
resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==}
|
||||
|
||||
@@ -6109,6 +6118,9 @@ packages:
|
||||
resolution: {integrity: sha512-hsU18Ae8CDTR6Kgu9DYf0EbCr/a5iGL0rytQDobUcdpYOKokk8LEjVphnXkDkgpi0wYVsqrXuP0bZxJaTqdgoA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
||||
async-lock@1.4.1:
|
||||
resolution: {integrity: sha512-Az2ZTpuytrtqENulXwO3GGv1Bztugx6TT37NIo7imr/Qo0gsYiGtSdBa2B6fsXhTpVZDNfu1Qn3pk531e3q+nQ==}
|
||||
|
||||
async-retry@1.3.3:
|
||||
resolution: {integrity: sha512-wfr/jstw9xNi/0teMHrRW7dsz3Lt5ARhYNZ2ewpadnhaIp5mbALhOAP+EAdsC7t4Z6wqsDVv9+W6gm1Dk9mEyw==}
|
||||
|
||||
@@ -13531,6 +13543,8 @@ snapshots:
|
||||
|
||||
'@types/aria-query@5.0.4': {}
|
||||
|
||||
'@types/async-lock@1.4.2': {}
|
||||
|
||||
'@types/babel__core@7.20.5':
|
||||
dependencies:
|
||||
'@babel/parser': 7.25.4
|
||||
@@ -14433,6 +14447,8 @@ snapshots:
|
||||
|
||||
async-function@1.0.0: {}
|
||||
|
||||
async-lock@1.4.1: {}
|
||||
|
||||
async-retry@1.3.3:
|
||||
dependencies:
|
||||
retry: 0.13.1
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 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, it } from 'vitest';
|
||||
import { expectCalculationResultMatchesSnapshot } from '../__testing__/util';
|
||||
|
||||
describe('Test formula correctness', () => {
|
||||
it('basic sum', () => {
|
||||
expectCalculationResultMatchesSnapshot();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user