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.

chore(core): add context to Univer,install top level plugin

Dushusire3580dd26ce9
diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsx
index c220cdb155..eab2d10a57 100644
--- a/examples/univer-sheet-ts/src/main.tsx
+++ b/examples/univer-sheet-ts/src/main.tsx
@@ -1,4 +1,4 @@
-import { UniverSheet, UniverDoc, UniverSlide } from '@univer/core';
+import { UniverSheet, UniverDoc, UniverSlide, Univer } from '@univer/core';
import { RenderEngine } from '@univer/base-render';
import { UniverComponentSheet } from '@univer/style-universheet';
import { SheetPlugin } from '@univer/base-sheets';
@@ -42,6 +42,10 @@ const uiDefaultConfigDemo = {
},
};
+const univer = new Univer();
+univer.installPlugin(new RenderEngine())
+univer.installPlugin(new UniverComponentSheet())
+univer.installPlugin(new BaseComponentPlugin());
// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO);
// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO1);
// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO2);
diff --git a/examples/univer-vanilla-ts/src/main.tsx b/examples/univer-vanilla-ts/src/main.tsx
index 1802c9fa46..69bf977c6d 100644
--- a/examples/univer-vanilla-ts/src/main.tsx
+++ b/examples/univer-vanilla-ts/src/main.tsx
@@ -50,6 +50,7 @@ const uiDefaultConfigUp = {
},
};
+// sheet up
const univerSheetUp = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA);
univerSheetUp.installPlugin(new RenderEngine());
@@ -62,6 +63,7 @@ FormulaPlugin.create(DEFAULT_FORMULA_DATA).installTo(univerSheetUp);
univerSheetUp.installPlugin(new ClipboardPlugin());
univerSheetUp.installPlugin(new ImportXlsxPlugin());
+// sheet down
const univerSheetDown = UniverSheet.newInstance();
univerSheetDown.installPlugin(new RenderEngine());
univerSheetDown.installPlugin(new UniverComponentSheet());
diff --git a/packages/core/src/Basics/Context.ts b/packages/core/src/Basics/Context.ts
new file mode 100644
index 0000000000..3a735294a2
--- /dev/null
+++ b/packages/core/src/Basics/Context.ts
@@ -0,0 +1,14 @@
+import { IUniverData } from '../Interfaces/IUniverData';
+import { ContextBase } from './ContextBase';
+
+/**
+ * univer context
+ */
+export class Context extends ContextBase {
+ constructor(univerData: Partial<IUniverData> = {}) {
+ super();
+ this._locale.initialize(univerData.locale);
+ }
+
+ protected _setObserver(): void {}
+}
diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.ts
index 63a667805c..0f9187f3d0 100644
--- a/packages/core/src/Basics/Univer.ts
+++ b/packages/core/src/Basics/Univer.ts
@@ -2,6 +2,8 @@ import { UniverSheet } from './UniverSheet';
import { UniverDoc } from './UniverDoc';
import { UniverSlide } from './UniverSlide';
import { Nullable } from '../Shared';
+import { Context } from './Context';
+import { Plugin } from '../Plugin';
export class Univer {
private _univerSheets: UniverSheet[];
@@ -10,10 +12,14 @@ export class Univer {
private _univerSlides: UniverSlide[];
+ private _context: Context;
+
constructor() {
this._univerSlides = [];
this._univerDocs = [];
this._univerSlides = [];
+
+ this._context = new Context();
}
addUniverSheet(univerSheet: UniverSheet): void {
@@ -42,4 +48,26 @@ export class Univer {
getUniverSlideInstance(id: string): Nullable<UniverSheet> {
return null;
}
+
+ getContext() {
+ return this._context;
+ }
+
+ /**
+ * install plugin
+ *
+ * @param plugin - install plugin
+ */
+ installPlugin(plugin: Plugin): void {
+ this._context.getPluginManager().install(plugin);
+ }
+
+ /**
+ * uninstall plugin
+ *
+ * @param name - plugin name
+ */
+ uninstallPlugin(name: string): void {
+ this._context.getPluginManager().uninstall(name);
+ }
}
diff --git a/packages/core/src/Basics/index.ts b/packages/core/src/Basics/index.ts
index 859ffd53de..1bb5790846 100644
--- a/packages/core/src/Basics/index.ts
+++ b/packages/core/src/Basics/index.ts
@@ -8,6 +8,7 @@ export * from './SlideContext';
export * from './UniverDoc';
export * from './UniverSheet';
export * from './UniverSlide';
+export * from './Univer';
export * from './Version';
export * from './WorkBookObserver';
export * from './WorkBookObserverImpl';
diff --git a/packages/core/src/Interfaces/IUniverData.ts b/packages/core/src/Interfaces/IUniverData.ts
new file mode 100644
index 0000000000..3b80fe1b5d
--- /dev/null
+++ b/packages/core/src/Interfaces/IUniverData.ts
@@ -0,0 +1,5 @@
+import { LocaleType } from '../Enum';
+
+export interface IUniverData {
+ locale: LocaleType;
+}
diff --git a/packages/sheets-plugin-filter/src/FilterPlugin.tsx b/packages/sheets-plugin-filter/src/FilterPlugin.tsx
index 79286be543..15059f1157 100644
--- a/packages/sheets-plugin-filter/src/FilterPlugin.tsx
+++ b/packages/sheets-plugin-filter/src/FilterPlugin.tsx
@@ -6,6 +6,7 @@ import { IConfig } from './IData';
import { FilterButton } from './UI/FilterButton';
import { ACTION_NAMES, FILTER_PLUGIN_NAME } from './Const';
import { Filter, FilterList, IFilterPluginConfig } from './Domain';
+import { Univer } from '@univer/core/src/Basics/Univer';
export class FilterPlugin extends Plugin {
private _filterList: FilterList;
diff --git a/packages/sheets-plugin-formula/src/Controller/ArrayFormLineController.ts b/packages/sheets-plugin-formula/src/Controller/ArrayFormLineController.ts
index 8a94c59933..dc79037bf3 100644
--- a/packages/sheets-plugin-formula/src/Controller/ArrayFormLineController.ts
+++ b/packages/sheets-plugin-formula/src/Controller/ArrayFormLineController.ts
@@ -1,4 +1,4 @@
-import { PLUGIN_NAMES, Workbook } from '@univer/core';
+import { PLUGIN_NAMES, Tools, Workbook } from '@univer/core';
import { Rect, Scene } from '@univer/base-render';
import { SheetPlugin, SheetView } from '@univer/base-sheets';
import { ArrayFormulaDataType } from '@univer/base-formula-engine';
@@ -95,12 +95,13 @@ export class ArrayFormLineControl {
for (let i = 0; i <= range.startColumn - 1; i++) {
offsetLeft += columnManager.getColumnWidth(i);
}
+ const id = Tools.generateRandomId();
// TODO: Gradient shadows
// dark gray #ebebeb
// light gray #fefefe
return [
- new Rect(ARRAY_FORM_LINE_MANAGER_KEY.left, {
+ new Rect(ARRAY_FORM_LINE_MANAGER_KEY.left + id, {
stroke: LINE_COLOR,
strokeWidth: 1,
left: offsetLeft + rowTitleWidth,
@@ -112,7 +113,7 @@ export class ArrayFormLineControl {
shadowColor: 'LightSkyBlue',
shadowBlur: 5,
}),
- new Rect(ARRAY_FORM_LINE_MANAGER_KEY.top, {
+ new Rect(ARRAY_FORM_LINE_MANAGER_KEY.top + id, {
stroke: LINE_COLOR,
strokeWidth: 1,
left: offsetLeft + rowTitleWidth,
@@ -124,7 +125,7 @@ export class ArrayFormLineControl {
shadowColor: 'LightSkyBlue',
shadowBlur: 5,
}),
- new Rect(ARRAY_FORM_LINE_MANAGER_KEY.right, {
+ new Rect(ARRAY_FORM_LINE_MANAGER_KEY.right + id, {
stroke: LINE_COLOR,
strokeWidth: 1,
left: offsetLeft + rowTitleWidth + totalWidth,
@@ -136,7 +137,7 @@ export class ArrayFormLineControl {
shadowColor: 'LightSkyBlue',
shadowBlur: 5,
}),
- new Rect(ARRAY_FORM_LINE_MANAGER_KEY.bottom, {
+ new Rect(ARRAY_FORM_LINE_MANAGER_KEY.bottom + id, {
stroke: LINE_COLOR,
strokeWidth: 1,
left: offsetLeft + rowTitleWidth,
@@ -162,7 +163,12 @@ export class ArrayFormLineControl {
let arrayFormLine = arrayFormLineList[j];
let antPath = arrayFormLine.getPath();
if (antPath) {
- this.getSheetViewScene().removeObjects(antPath);
+ for (let index = 0; index < antPath.length; index++) {
+ const element = antPath[index];
+ element.hide();
+ // element.dispose();
+ }
+ // this.getSheetViewScene().removeObjects(antPath);
}
}
}
@@ -173,6 +179,8 @@ export class ArrayFormLineControl {
*/
private _makeUpdateSceneArrayFormLinePath(): void {
this._deleteSceneAllArrayFormLinePath();
+ // this.getSheetViewScene().makeDirty(true);
+ // this._sheetPlugin.getMainComponent().makeDirty(true);
for (let i = 0; i < this._arrayFormLineModelList.length; i++) {
let arrayFormLineModel = this._arrayFormLineModelList[i];
let arrayFormLineList = arrayFormLineModel.getArrayFormLineList();
@@ -210,6 +218,10 @@ export class ArrayFormLineControl {
this._activeSheetId = this._sheetPlugin.getWorkbook().getActiveSheet().getSheetId();
this._makeUpdateSceneArrayFormLinePath();
});
+ this._sheetPlugin.getObserver('onChangeSelectionObserver')?.add(() => {
+ const currentCell = this._sheetPlugin.getSelectionManager().getCurrentCell();
+ console.log('current cell', currentCell);
+ });
}
/**