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): locale

Dushusirc2c951a251c7
diff --git a/packages/base-render/src/Component/Skeleton.ts b/packages/base-render/src/Component/Skeleton.ts
index f9de13a00d..f502aeef69 100644
--- a/packages/base-render/src/Component/Skeleton.ts
+++ b/packages/base-render/src/Component/Skeleton.ts
@@ -23,7 +23,7 @@ export class Skeleton {
return;
}
- const locale = this._context.getLocale();
+ const locale = this._context.getUniver().getGlobalContext().getLocale();
const renderFont = locale.getObject('renderFont');
if (!renderFont) {
locale.load({
diff --git a/packages/base-render/src/RenderEngine.ts b/packages/base-render/src/RenderEngine.ts
index d551ef1cd0..331790fdb3 100644
--- a/packages/base-render/src/RenderEngine.ts
+++ b/packages/base-render/src/RenderEngine.ts
@@ -1,4 +1,4 @@
-import { UniverSheet, Plugin, PLUGIN_NAMES } from '@univerjs/core';
+import { Plugin, PLUGIN_NAMES, Univer } from '@univerjs/core';
import { Engine } from './Engine';
export class RenderEngine extends Plugin {
@@ -13,8 +13,8 @@ export class RenderEngine extends Plugin {
return new RenderEngine();
}
- installTo(universheetInstance: UniverSheet) {
- universheetInstance.installPlugin(this);
+ installTo(univerInstance: Univer) {
+ univerInstance.install(this);
}
getEngine(): Engine {
diff --git a/packages/base-sheets/src/SheetPlugin.ts b/packages/base-sheets/src/SheetPlugin.ts
index ea1f127499..4621e5ea71 100644
--- a/packages/base-sheets/src/SheetPlugin.ts
+++ b/packages/base-sheets/src/SheetPlugin.ts
@@ -2,7 +2,6 @@ import { Engine, RenderEngine } from '@univerjs/base-render';
import { SheetContext, Plugin, PLUGIN_NAMES } from '@univerjs/core';
import { SheetPluginObserve, uninstall } from './Basics/Observer';
-import { en, zh } from './Locale';
import { CANVAS_VIEW_KEY } from './View/Render/BaseView';
import { CanvasView } from './View/Render/CanvasView';
import { RightMenuController, InfoBarController, SheetBarControl, CellEditorController, SheetContainerController, ToolbarController } from './Controller';
@@ -50,15 +49,6 @@ export class SheetPlugin extends Plugin<SheetPluginObserve, SheetContext> {
this.context = context;
install(this);
-
- /**
- * load more Locale object
- */
- context.getLocale().load({
- en,
- zh,
- });
-
this.initController();
this.initCanvasView();
diff --git a/packages/core/src/Basics/Context.ts b/packages/core/src/Basics/Context.ts
index b6090294e8..b5ea41dc95 100644
--- a/packages/core/src/Basics/Context.ts
+++ b/packages/core/src/Basics/Context.ts
@@ -1,15 +1,23 @@
import { IUniverData } from '../Interfaces/IUniverData';
+import { Locale } from '../Shared';
import { ContextBase } from './ContextBase';
/**
* univer context
*/
export class Context extends ContextBase {
+ protected _locale: Locale;
+
constructor(univerData: Partial<IUniverData> = {}) {
super();
+ this._locale = new Locale();
this._locale.initialize();
}
- protected _setObserver(): void {}
+ getLocale(): Locale {
+ return this._locale;
+ }
+
+ protected _setObserver(): void { }
}
diff --git a/packages/core/src/Basics/ContextBase.ts b/packages/core/src/Basics/ContextBase.ts
index 9816ea0667..36f9f4f12b 100644
--- a/packages/core/src/Basics/ContextBase.ts
+++ b/packages/core/src/Basics/ContextBase.ts
@@ -2,7 +2,7 @@ import { CommandManager, UndoManager } from '../Command';
import { ObservableHooks, ObserverManager } from '../Observer';
import { HooksManager } from '../Observer/HooksManager';
import { PluginManager } from '../Plugin';
-import { Locale, Nullable } from '../Shared';
+import { Nullable } from '../Shared';
import { Environment } from './Environment';
import { Univer } from './Univer';
@@ -18,8 +18,6 @@ export abstract class ContextBase {
protected _undoManager: UndoManager;
- protected _locale: Locale;
-
protected _pluginManager: PluginManager;
protected _observerManager: ObserverManager;
@@ -33,7 +31,6 @@ export abstract class ContextBase {
this._commandManager = new CommandManager(this);
this._environment = new Environment();
this._hooksManager = new HooksManager();
- this._locale = new Locale();
this._pluginManager = new PluginManager(this);
this._observerManager = new ObserverManager();
}
@@ -46,10 +43,6 @@ export abstract class ContextBase {
return this._hooksManager.getHooks<T>(path);
}
- getLocale(): Locale {
- return this._locale;
- }
-
getHooksManager(): HooksManager {
return this._hooksManager;
}
diff --git a/packages/core/src/Basics/DocContext.ts b/packages/core/src/Basics/DocContext.ts
index df36aff4b0..54cd0434c7 100644
--- a/packages/core/src/Basics/DocContext.ts
+++ b/packages/core/src/Basics/DocContext.ts
@@ -10,7 +10,6 @@ export class DocContext extends ContextBase {
constructor(univerDocData: Partial<IDocumentData> = {}) {
super();
- this._locale.initialize(univerDocData.locale);
this._document = new DocumentModel(univerDocData, this);
}
diff --git a/packages/core/src/Basics/SheetContext.ts b/packages/core/src/Basics/SheetContext.ts
index a933e27723..0b38f47205 100644
--- a/packages/core/src/Basics/SheetContext.ts
+++ b/packages/core/src/Basics/SheetContext.ts
@@ -14,7 +14,6 @@ export class SheetContext extends ContextBase {
constructor(univerSheetData: Partial<IWorkbookConfig> = {}) {
super();
- this._locale.initialize(univerSheetData.locale);
this._setObserver();
this._workbook = new Workbook(univerSheetData, this);
}
diff --git a/packages/core/src/Basics/SlideContext.ts b/packages/core/src/Basics/SlideContext.ts
index f2366cd313..189cd3e561 100644
--- a/packages/core/src/Basics/SlideContext.ts
+++ b/packages/core/src/Basics/SlideContext.ts
@@ -10,7 +10,6 @@ export class SlideContext extends ContextBase {
constructor(univerSlideData: Partial<ISlideData> = {}) {
super();
- this._locale.initialize(univerSlideData.locale);
this._slide = new SlideModel(univerSlideData, this);
}
diff --git a/packages/core/src/Plugin/Plugin.ts b/packages/core/src/Plugin/Plugin.ts
index 6115499acc..7c526f6fe8 100644
--- a/packages/core/src/Plugin/Plugin.ts
+++ b/packages/core/src/Plugin/Plugin.ts
@@ -1,7 +1,7 @@
import { ContextBase } from '../Basics/ContextBase';
import { Context } from '../Basics/Context';
import { Observable } from '../Observer';
-import { Nullable, PropsFrom } from '../Shared';
+import { Locale, Nullable, PropsFrom } from '../Shared';
import { Univer } from '../Basics';
/**
@@ -11,6 +11,7 @@ export interface BasePlugin {
context: ContextBase;
getContext(): ContextBase;
getGlobalContext(): Context;
+ getLocale(): Locale;
getPluginName(): string;
onCreate(context: ContextBase): void;
onMounted(context: ContextBase): void;
@@ -72,6 +73,10 @@ export abstract class Plugin<Obs = any, O extends ContextBase = ContextBase>
return this.context.getUniver().getGlobalContext();
}
+ getLocale(): Locale {
+ return this.getGlobalContext().getLocale();
+ }
+
getUniver(): Univer {
return this.context.getUniver();
}
diff --git a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
index a0a62f9631..561065a3ea 100644
--- a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
+++ b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
@@ -59,7 +59,7 @@ export class FormulaPlugin extends Plugin<FormulaPluginObserve, SheetContext> {
/**
* load more Locale object
*/
- this.getContext().getLocale().load({
+ this.getLocale().load({
en,
zh,
});
diff --git a/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx b/packages/ui-plugin-sheets/src/SheetUIPlugin.ts
similarity index 97%
rename from packages/ui-plugin-sheets/src/SheetUIPlugin.tsx
rename to packages/ui-plugin-sheets/src/SheetUIPlugin.ts
index 86ff70b9d6..23fe8f26bf 100644
--- a/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx
+++ b/packages/ui-plugin-sheets/src/SheetUIPlugin.ts
@@ -30,11 +30,10 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve, Context> {
initialize(ctx: Context): void {
installObserver(this);
- const context = this.getContext();
/**
* load more Locale object
*/
- context.getLocale().load({
+ this.getLocale().load({
zh,
en,
});
diff --git a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
index c8744db762..b2c94d47af 100644
--- a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
@@ -1,5 +1,4 @@
-import { BaseComponentProps, BaseComponentRender, BaseComponentSheet, Component, debounce, Icon } from '@univerjs/base-ui';
-import { BaseSelectChildrenProps, Select } from '@univerjs/base-sheets';
+import { BaseComponentProps, BaseComponentRender, BaseComponentSheet, BaseSelectChildrenProps, Component, debounce, Icon } from '@univerjs/base-ui';
import styles from './index.module.less';
type FormulaState = {
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/index.module.css b/packages/ui-plugin-sheets/src/View/SheetBar/index.module.css
deleted file mode 100644
index 93f982d224..0000000000
--- a/packages/ui-plugin-sheets/src/View/SheetBar/index.module.css
+++ /dev/null
@@ -1,171 +0,0 @@
-.sheet-bar {
- position: relative;
- height: 31px;
- display: flex;
- flex-direction: row;
- background-color: var(--bg);
-}
-.sheet-bar-options {
- border-right: 1px solid var(--border-color-base);
- display: flex;
- flex-direction: row;
- align-items: center;
- padding-right: 5px;
-}
-.sheet-bar-options-button {
- padding: 0;
- margin: 0;
- border: none;
- height: initial;
- line-height: initial;
- padding-right: 2px;
-}
-.sheet_bar_scroll_button {
- border: none;
- border-left: 1px solid var(--border-color-base);
- padding-left: 5px;
-}
-.slide-tab-bar {
- user-select: none;
- max-width: 100%;
- height: 100%;
- display: flex;
- flex-direction: row;
- align-items: center;
- overflow: auto;
- overflow-y: hidden;
- scrollbar-width: none;
-}
-.slide-tab-bar::-webkit-scrollbar {
- display: none;
-}
-/**
- 高亮标记
- */
-.slide-tab-active {
- position: relative;
-}
-/**
- Tab Item
-*/
-.slide-tab-item {
- user-select: none;
- display: flex;
- flex-direction: column;
- justify-content: center;
- cursor: pointer;
- height: 100%;
- background-color: var(--bg);
-}
-.slide-tab-item:first-child .slide-tab-divider {
- opacity: 0;
-}
-.slide-tab-item:hover {
- background: #efefef;
-}
-.slide-tab-item:hover .slide-tab-divider {
- opacity: 0;
-}
-.slide-tab-item:hover + .slide-tab-item .slide-tab-divider {
- opacity: 0;
-}
-/**
- 内容区域
-*/
-.slide-tab-content {
- display: flex;
- flex-direction: row;
- align-items: center;
- flex-grow: 1;
-}
-.slide-tab-title {
- font-size: 14px;
- color: #676464;
- margin-right: 3px;
- margin-left: 6px;
-}
-.slide-tab-icon {
- width: 16px;
- height: 16px;
- font-size: 15px;
- color: #a1a1a1;
- margin-right: 6px;
-}
-.slide-tab-divider {
- width: 1px;
- height: 16px;
- background: var(--border-color-base);
-}
-.slide-tab-active .slide-tab-content {
- background: #efefef;
- color: #222;
-}
-.slide-tab-active .slide-tab-divider {
- opacity: 0;
-}
-.slide-tab-active + .slide-tab-item .slide-tab-divider {
- opacity: 0;
-}
-/**
- 底部区域
- */
-.slide-tab-footer {
- height: auto;
- width: 100%;
- flex-grow: 0;
-}
-.slide-tab-active-bar {
- height: 2px;
- width: 100%;
-}
-.slide-tab-active .slide-tab-active-bar {
- background: #d0d0d0;
-}
-.sheet-ul .cols-menuitem {
- text-align: left;
- padding: 5px 5px 5px 25px;
-}
-.sheet-ul .select-color-picker-parent .select-item-content {
- width: 100%;
-}
-.sheet-ul .select-color-picker-parent ul {
- padding: 0;
-}
-.sheet-ul .select-color-picker-parent .select-color-picker {
- padding: 0;
-}
-.sheet-ul .select-color-picker-parent .select-color-picker .select-item {
- padding: 0;
-}
-.sheet-bar-menu {
- position: absolute;
- bottom: 120%;
- left: 0;
- padding: 0;
- border: 1px solid rgba(0, 0, 0, 0.2);
- border-radius: 0;
- transition: opacity 218ms;
- background: var(--bg);
- margin: 0;
- outline: 0;
- z-index: 100;
- box-sizing: border-box;
- user-select: none;
-}
-.sheet-bar-menu li {
- list-style: none;
-}
-.sheet-bar-menu .sheet-bar-menu-item {
- position: relative;
- padding: 5px 10px 5px 20px;
-}
-.sheet-bar-menu .sheet-bar-menu-item .sheet-bar-menu-icon {
- position: absolute;
- left: 5px;
- top: 50%;
- transform: translateY(-50%);
-}
-.sheet-bar-menu .sheet-bar-menu-item-hide {
- pointer-events: none;
- color: #eee;
-}
diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/SingleButton.tsx b/packages/ui-plugin-sheets/src/View/ToolBar/SingleButton.tsx
deleted file mode 100644
index 01b41e842d..0000000000
--- a/packages/ui-plugin-sheets/src/View/ToolBar/SingleButton.tsx
+++ /dev/null
@@ -1,68 +0,0 @@
-import { BaseSingleButtonProps, Component, JSXComponent, SingleButtonComponent } from '@univerjs/base-component';
-import { Button, Tooltip } from '@univerjs/style-univer';
-
-import styles from './index.module.less';
-
-export interface SingleButtonProps {
- label?: string | JSX.Element;
- icon?: JSX.Element | string | null | undefined;
- tooltip?: string;
- name?: string;
- key?: string;
- onClick?: (...arg: any[]) => void;
- active?: boolean;
- triggerUpdate?: (func: Function) => void;
-}
-export interface IState {
- active: boolean;
-}
-
-class SingleButton extends Component<SingleButtonProps, IState> {
- initialize(props: SingleButtonProps): void {
- // Mount update function, when updating the selection range, the cell formats corresponding to different ranges are different, and the toolbar status and values need to be updated in real time
- const { triggerUpdate, active } = props;
- triggerUpdate && triggerUpdate(this.update.bind(this));
-
- this.state = {
- active: active || false,
- };
- }
-
- update(active: boolean) {
- this.setState({ active });
- }
-
- onClick() {
- this.setState(
- (prevState: IState) => ({
- active: !prevState.active,
- }),
- () => {
- this.props.onClick && this.props.onClick(this.state.active);
- }
- );
- }
-
- render() {
- const { name, tooltip, label, icon, onClick, key } = this.props;
- const { active } = this.state;
- return (
- <div className={styles.singleButton} key={key}>
- <Tooltip title={tooltip!} placement={'bottom'}>
- <Button type="text" onClick={() => this.onClick()} active={active}>
- {label}
- {icon}
- </Button>
- </Tooltip>
- </div>
- );
- }
-}
-
-export class UniverSingleButton implements SingleButtonComponent {
- render(): JSXComponent<BaseSingleButtonProps> {
- return SingleButton;
- }
-}
-
-export { SingleButton };
diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/index.module.css b/packages/ui-plugin-sheets/src/View/ToolBar/index.module.css
deleted file mode 100644
index 8245552da9..0000000000
--- a/packages/ui-plugin-sheets/src/View/ToolBar/index.module.css
+++ /dev/null
@@ -1,98 +0,0 @@
-.toolbar-warp {
- max-height: fit-content;
- width: 100%;
- overflow: unset;
- box-sizing: border-box;
- font-size: var(--font-size);
- background-color: var(--bg);
- position: relative;
- display: flex;
- align-items: center;
- border-bottom: 1px solid var(--border-color-base);
-}
-.toolbar-warp .single-button.more-hide {
- display: none;
-}
-.toolbar-warp .single-button.more-show {
- display: block;
-}
-.toolbar {
- max-width: 100%;
- color: var(--text-color);
- padding: 0 15px;
- height: 40px;
- position: relative;
- display: flex;
- align-items: center;
-}
-.toolbar > div {
- height: 26px;
- display: inline-block;
- vertical-align: middle;
- margin: 0 3px;
- cursor: pointer;
-}
-.toolbar > div.select-button:hover {
- background-color: #efefef;
-}
-.toolbar .cols-menu {
- overflow-y: auto;
-}
-.toolbar .select-label-string .drop-content > div {
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- width: 90px;
-}
-.toolbar .select-double-string .drop-content > div {
- width: 24px;
-}
-.toolbar .select-color-picker-parent .select-item-content {
- width: 100%;
-}
-.toolbar .select-color-picker-parent ul {
- padding: 0;
-}
-.toolbar .select-color-picker-parent .select-color-picker {
- padding: 0;
-}
-.toolbar .select-color-picker-parent .select-color-picker .select-item {
- padding: 0;
-}
-.toolbar .select-line-bold-parent .select-item-content {
- width: 100%;
-}
-.toolbar button {
- padding: 0;
- height: 26px;
-}
-.toolbar span[role='img'].univericon-nextIcon {
- font-size: 12px;
-}
-.more-button {
- position: absolute;
- right: 15px;
- top: 50%;
- transform: translateY(-50%);
- padding: 0px;
- line-height: 1;
-}
-.more-button.more-show {
- display: block;
-}
-.more-tool {
- padding: 0 10px;
- background-color: var(--bg);
- box-shadow: var(--box-shadow-base);
- position: absolute;
- right: 2em;
- top: 40px;
- z-index: 100;
-}
-.more-tool.more-show {
- display: flex;
-}
-.more-tool button {
- padding: 0px;
- line-height: 1;
-}
diff --git a/packages/ui-plugin-sheets/vite.config.ts b/packages/ui-plugin-sheets/vite.config.ts
index 465ef2808a..db8db63c97 100644
--- a/packages/ui-plugin-sheets/vite.config.ts
+++ b/packages/ui-plugin-sheets/vite.config.ts
@@ -43,6 +43,7 @@ export default defineConfig({
'@univerjs/base-render': '@univerjs/base-render',
'@univerjs/base-sheets': '@univerjs/base-sheets',
'css-vars-ponyfill': 'css-vars-ponyfill',
+ 'preact': 'preact',
},
}),
],