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.

fix(*): fix ts errors (#195)

白熱307904d3c674
diff --git a/packages/base-ui/src/Common/SlotManager.ts b/packages/base-ui/src/Common/SlotManager.ts
index f15210eab0..d7d13605f4 100644
--- a/packages/base-ui/src/Common/SlotManager.ts
+++ b/packages/base-ui/src/Common/SlotManager.ts
@@ -9,7 +9,7 @@ export type SlotComponent = {
};
export type SlotGroupProps = Map<string, Map<string, SlotComponent>>;
-export type SlotList = Map<string, Slot>;
+export type SlotList = Map<string, typeof Slot>;
export class SlotManager {
// slot配置
@@ -18,7 +18,7 @@ export class SlotManager {
// slot实例
private _slotList: SlotList = new Map();
- getComponent = (ref: Slot) => {
+ getComponent = (ref: any) => {
this._slotList.set(ref.props.name, ref);
const slot = this._slotGroup.get(ref.props.name);
if (!slot) return;
@@ -34,7 +34,7 @@ export class SlotManager {
slot.set(component.name, component);
}
- const item = this._slotList.get(slotName);
+ const item = this._slotList.get(slotName) as any;
item?.setSlot(component, cb);
}
@@ -45,17 +45,17 @@ export class SlotManager {
if (!SlotComponent) return;
const component = SlotComponent.get(name);
if (!component) return;
- slot.removeSlot(component);
+ (slot as any).removeSlot(component);
}
- getSlot(slotName: string): Nullable<Slot> {
+ getSlot(slotName: string): Nullable<typeof Slot> {
const slot = this._slotList.get(slotName);
if (slot) return slot;
}
removeSlot(name: string) {
this._slotGroup.delete(name);
- const slot = this._slotList.get(name);
+ const slot = this._slotList.get(name) as any;
if (slot) {
slot.setSlotAll(new Map());
this._slotList.delete(name);
diff --git a/packages/base-ui/src/index.ts b/packages/base-ui/src/index.ts
index 703cbe890b..bfa54fdd0f 100644
--- a/packages/base-ui/src/index.ts
+++ b/packages/base-ui/src/index.ts
@@ -5,7 +5,7 @@ export * from './Common';
export * from './Components';
export { SharedController } from './controllers/shared-shortcut.controller';
export { IUIController } from './controllers/ui/ui.controller';
-export { IDesktopUIController } from './controllers/ui/ui-desktop.controller';
+export { type IDesktopUIController } from './controllers/ui/ui-desktop.controller';
export * from './Enum';
export * from './Helpers';
export * from './Locale';
@@ -19,16 +19,16 @@ export {
PLAIN_TEXT_CLIPBOARD_MIME_TYPE,
} from './services/clipboard/clipboard-interface.service';
export {
- ICustomComponentOption,
- ICustomComponentProps,
- IDisplayMenuItem,
- IMenuButtonItem,
- IMenuItem,
- IMenuItemFactory,
- IMenuSelectorItem,
+ type ICustomComponentOption,
+ type ICustomComponentProps,
+ type IDisplayMenuItem,
+ type IMenuButtonItem,
+ type IMenuItem,
+ type IMenuItemFactory,
+ type IMenuSelectorItem,
isCustomComponentOption,
isValueOptions,
- IValueOption,
+ type IValueOption,
MenuItemType,
MenuPosition,
} from './services/menu/menu';
@@ -39,5 +39,5 @@ export { DesktopNotificationService } from './services/notification/desktop-noti
export { INotificationService } from './services/notification/notification.service';
export { DesktopPlatformService, IPlatformService } from './services/platform/platform.service';
export { KeyCode, MetaKeys } from './services/shortcut/keycode';
-export { DesktopShortcutService, IShortcutItem, IShortcutService } from './services/shortcut/shortcut.service';
+export { DesktopShortcutService, type IShortcutItem, IShortcutService } from './services/shortcut/shortcut.service';
export * from './Utils';
diff --git a/packages/base-ui/src/views/components/toolbar/toolbar-item.tsx b/packages/base-ui/src/views/components/toolbar/toolbar-item.tsx
index cfc8e91a51..1ad9e5c90d 100644
--- a/packages/base-ui/src/views/components/toolbar/toolbar-item.tsx
+++ b/packages/base-ui/src/views/components/toolbar/toolbar-item.tsx
@@ -28,6 +28,8 @@ export interface IToolbarItemStatus {
export class ToolbarItem extends Component<IDisplayMenuItem<IMenuItem>, IToolbarItemStatus> {
static override contextType = AppContext;
+ declare context: React.ContextType<typeof AppContext>;
+
private disabledSubscription: Subscription | undefined;
private activatedSubscription: Subscription | undefined;
@@ -133,7 +135,6 @@ export class ToolbarItem extends Component<IDisplayMenuItem<IMenuItem>, IToolbar
<Button
active={activated}
className={styles.textButton}
- type="text"
disabled={disabled}
onClick={() => commandService.executeCommand(props.id)}
>
diff --git a/packages/base-ui/src/views/components/toolbar/toolbar.tsx b/packages/base-ui/src/views/components/toolbar/toolbar.tsx
index b8aef54a52..5e461183f2 100644
--- a/packages/base-ui/src/views/components/toolbar/toolbar.tsx
+++ b/packages/base-ui/src/views/components/toolbar/toolbar.tsx
@@ -27,8 +27,6 @@ export class Toolbar extends Component<IToolbarProps, IToolbarState> {
moreToolRef = createRef();
- SelectRef = createRef();
-
clientWidth = 0;
constructor(props: IToolbarProps) {
diff --git a/packages/core/src/services/locale/locale.service.ts b/packages/core/src/services/locale/locale.service.ts
index c852acfd2b..528531f720 100644
--- a/packages/core/src/services/locale/locale.service.ts
+++ b/packages/core/src/services/locale/locale.service.ts
@@ -47,7 +47,7 @@ export class LocaleService extends Disposable {
this.disposeWithMe(toDisposable(() => this._locale$.complete()));
}
- t(key: string): string {
+ t(key?: string): string {
return this.get(key);
}
diff --git a/packages/ui-plugin-docs/src/Basics/Observer.ts b/packages/ui-plugin-docs/src/Basics/Observer.ts
index 041a3959f8..bc7c5b9571 100644
--- a/packages/ui-plugin-docs/src/Basics/Observer.ts
+++ b/packages/ui-plugin-docs/src/Basics/Observer.ts
@@ -1,7 +1,7 @@
import { Observable } from '@univerjs/core';
import { DocUIPlugin } from '../doc-ui-plugin';
-import { DocContainer } from '../View';
+import { DocContainer } from '../View/DocContainer';
export type DocUIPluginObserve = {
onUIDidMount: Observable<DocContainer>;
diff --git a/packages/ui-plugin-docs/src/Controller/DocContainerUIController.ts b/packages/ui-plugin-docs/src/Controller/DocContainerUIController.ts
index 89e73b655a..797024f622 100644
--- a/packages/ui-plugin-docs/src/Controller/DocContainerUIController.ts
+++ b/packages/ui-plugin-docs/src/Controller/DocContainerUIController.ts
@@ -3,7 +3,7 @@ import { LocaleService, LocaleType, ObserverManager } from '@univerjs/core';
import { Inject, Injector, SkipSelf } from '@wendellhu/redi';
import { IDocUIPluginConfig } from '../Basics';
-import { DocContainer } from '../View';
+import { DocContainer } from '../View/DocContainer';
export class DocContainerUIController {
private _docContainer: DocContainer;
diff --git a/packages/ui-plugin-docs/src/View/App.tsx b/packages/ui-plugin-docs/src/View/App.tsx
deleted file mode 100644
index ac5fe1af5a..0000000000
--- a/packages/ui-plugin-docs/src/View/App.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-import { AppContext, BaseComponentProps, ComponentManager } from '@univerjs/base-ui';
-import { LocaleService, LocaleType } from '@univerjs/core';
-import { Component } from 'react';
-
-import { BaseDocContainerProps, DocContainer } from './DocContainer';
-
-export interface BaseUIProps extends BaseComponentProps {
- locale: LocaleType;
- localeService: LocaleService;
- UIConfig: BaseDocContainerProps;
- componentManager: ComponentManager;
- changeLocale: (locale: string) => void;
-}
-
-interface IState {
- locale: LocaleType;
-}
-
-export class App extends Component<BaseUIProps, IState> {
- constructor(props: BaseUIProps) {
- super(props);
- this.state = {
- locale: this.props.locale,
- };
- }
-
- setLocale(e: Event) {
- const value = (e.target as HTMLSelectElement).value as LocaleType;
- this.props.changeLocale(value);
- this.setState({
- locale: value,
- });
- }
-
- render() {
- const { localeService, injector, UIConfig, componentManager } = this.props;
- const { locale } = this.state;
-
- return (
- <AppContext.Provider
- value={{
- locale,
- componentManager,
- localeService,
- injector,
- }}
- >
- <div
- style={{
- position: 'fixed',
- right: '250px',
- top: '14px',
- fontSize: '14px',
- zIndex: 100,
- }}
- className="univer-dev-operation"
- >
- <span
- style={{
- display: 'inline-block',
- width: 70,
- margin: '5px 0 0 5px',
- }}
- >
- Language
- </span>
- <select value={locale} onChange={this.setLocale.bind(this)} style={{ width: 70 }}>
- <option value="en">English</option>
- <option value="zh">中文</option>
- </select>
- </div>
- <DocContainer {...UIConfig} />
- </AppContext.Provider>
- );
- }
-}
diff --git a/packages/ui-plugin-docs/src/View/DocContainer/DocContainer.tsx b/packages/ui-plugin-docs/src/View/DocContainer/DocContainer.tsx
index 3fd7da127f..53f23e5340 100644
--- a/packages/ui-plugin-docs/src/View/DocContainer/DocContainer.tsx
+++ b/packages/ui-plugin-docs/src/View/DocContainer/DocContainer.tsx
@@ -39,7 +39,7 @@ export class DocContainer extends Component<BaseDocContainerProps> {
* split mouse down
* @param e
*/
- handleSplitBarMouseDown = (e: MouseEvent) => {
+ handleSplitBarMouseDown = (e: React.MouseEvent) => {
e = e || window.event; // Compatible with IE browser
// Store the current mouse position
this.leftContentLeft = this.splitLeftRef.current?.getBoundingClientRect().left!;
diff --git a/packages/ui-plugin-docs/src/View/index.tsx b/packages/ui-plugin-docs/src/View/index.tsx
deleted file mode 100644
index 9b23721a7c..0000000000
--- a/packages/ui-plugin-docs/src/View/index.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-import { isElement } from '@univerjs/base-ui';
-import { createRoot } from 'react-dom/client';
-
-import { App, BaseUIProps } from './App';
-
-interface BaseDicUIConfig extends BaseUIProps {
- container?: HTMLElement | string;
-}
-
-export class UI {
- constructor(props: BaseDicUIConfig) {
- this._initialize(props);
- }
-
- static create(props: BaseDicUIConfig) {
- return new UI(props);
- }
-
- private _initialize(props: BaseDicUIConfig) {
- let renderContainer: HTMLElement;
- const container = props.container;
-
- if (typeof container === 'string') {
- const containerDOM = document.getElementById(container);
- if (containerDOM == null) {
- renderContainer = document.createElement('div');
- renderContainer.id = container;
- } else {
- renderContainer = containerDOM;
- }
- } else if (isElement(container)) {
- renderContainer = container!;
- } else {
- renderContainer = document.createElement('div');
- renderContainer.id = 'univer';
- }
-
- const root = createRoot(renderContainer);
- root.render(<App {...props} />);
- }
-}
-
-export * from './DocContainer';
diff --git a/packages/ui-plugin-docs/src/doc-ui-plugin.ts b/packages/ui-plugin-docs/src/doc-ui-plugin.ts
index 2d2dd7091e..2766b5c8e5 100644
--- a/packages/ui-plugin-docs/src/doc-ui-plugin.ts
+++ b/packages/ui-plugin-docs/src/doc-ui-plugin.ts
@@ -5,7 +5,6 @@ import { DefaultDocUiConfig, IDocUIPluginConfig, installObserver } from './Basic
import { DOC_UI_PLUGIN_NAME } from './Basics/Const/PLUGIN_NAME';
import { AppUIController } from './Controller';
import { DocClipboardController } from './Controller/clipboard.controller';
-import { en } from './Locale';
import { DocClipboardService, IDocClipboardService } from './services/clipboard/clipboard.service';
export class DocUIPlugin extends Plugin<any> {
@@ -23,10 +22,6 @@ export class DocUIPlugin extends Plugin<any> {
}
override onRendered(): void {
- this._localService.getLocale().load({
- en,
- });
-
installObserver(this);
this._initModules();
diff --git a/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx b/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
index d632c2a27e..3d1cda52b9 100644
--- a/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
@@ -1,16 +1,17 @@
import { AppContext, BaseComponentProps, CustomLabel, Icon } from '@univerjs/base-ui';
+import { BorderStyleTypes } from '@univerjs/core';
import { Component } from 'react';
import { BORDER_SIZE_CHILDREN, LINE_BOLD_LABEL } from '../../../controller/menu/border.menu';
interface IState {
- img: string;
+ img: BorderStyleTypes;
}
interface IProps extends BaseComponentProps {
label: string;
title: string;
- value: string;
+ value: BorderStyleTypes;
}
export class LineBold extends Component<IProps, IState> {
@@ -18,6 +19,8 @@ export class LineBold extends Component<IProps, IState> {
static override contextType = AppContext;
+ declare context: React.ContextType<typeof AppContext>;
+
constructor(props: IProps) {
super(props);
this.initialize();
@@ -25,7 +28,7 @@ export class LineBold extends Component<IProps, IState> {
initialize() {
this.state = {
- img: '',
+ img: BorderStyleTypes.NONE,
};
}
@@ -39,17 +42,17 @@ export class LineBold extends Component<IProps, IState> {
});
}
- setImg(img: string = '') {
+ setImg(img: BorderStyleTypes = BorderStyleTypes.NONE) {
this.setState({
img,
});
}
- getImg(img: string) {
+ getImg(img: BorderStyleTypes) {
if (!img) return null;
const span = document.querySelector('.base-sheets-line-bold') as HTMLDivElement;
const props = { width: span.offsetWidth };
- const Img = this.context.componentManager.get(img);
+ const Img = this.context.componentManager.get(img as unknown as string) as any;
if (Img) {
return <Img {...(props as any)} />;
}
diff --git a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
index 90b44d9d7d..21d7bd216b 100644
--- a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
@@ -13,7 +13,7 @@ interface CountState {
}
interface CountBarProps extends BaseComponentProps {
- changeRatio: (ratio: string) => void;
+ changeRatio?: (ratio: string) => void;
onChange?: (value: string) => void;
}
diff --git a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
index 7df5663a8a..7fa9095168 100644
--- a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
@@ -21,6 +21,8 @@ export interface BaseFormulaBarProps extends BaseComponentProps {}
export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
static override contextType = AppContext;
+ declare context: React.ContextType<typeof AppContext>;
+
// formulaContent = createRef<HTMLDivElement>();
constructor(props: BaseFormulaBarProps) {
@@ -48,7 +50,7 @@ export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
// console.dir(value);
};
- printChange = (e: KeyboardEvent) => {
+ printChange = (e: React.KeyboardEvent) => {
this.onkeyUp(e.target);
};
@@ -77,7 +79,7 @@ export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
getIcon(name: string) {
const componentManager = this.context.componentManager;
- const Icon = componentManager?.get(name);
+ const Icon = componentManager?.get(name) as any;
return <Icon />;
}
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
index f3463eaa1a..8c0c7db819 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
@@ -37,7 +37,7 @@ export interface BaseSheetBarProps extends BaseComponentProps, Omit<BaseSelectPr
style?: React.CSSProperties;
hidden?: BooleanNumber;
addSheet?: () => void;
- onMouseDown?: (e: MouseEvent) => void;
+ onMouseDown?: (e: React.MouseEvent) => void;
selectSheet?: (slideItemIndex: number) => void;
changeSheetName?: (sheetId: string, name: string) => void;
dragEnd?: (elements: HTMLElement[]) => void;
@@ -146,7 +146,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
};
// 隐藏下拉
- hideSelect = (e: MouseEvent) => {
+ hideSelect = () => {
this.setState({
showMenu: false,
});
@@ -275,7 +275,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
index: `${index}`,
selected: sheet.getStatus() === BooleanNumber.TRUE,
color: (sheet.getTabColor() as string) ?? undefined,
- onMouseDown: (e: MouseEvent) => {
+ onMouseDown: () => {
const worksheetId = sheet.getSheetId();
// this.setState({
// activeKey: worksheetId,
@@ -332,10 +332,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
<Icon.Math.AddIcon style={{ fontSize: '20px' }} />
</Button>
{/* all sheets button */}
- <Button
- className={styles.sheetBarOptionsButton}
- onClick={(e: MouseEvent) => this.ref.current?.showMenu(true)}
- >
+ <Button className={styles.sheetBarOptionsButton} onClick={() => this.ref.current?.showMenu(true)}>
<Icon.MenuIcon style={{ fontSize: '20px' }} />
<SheetBarMenu menu={menuList as ISheetBarMenuItem[]}></SheetBarMenu>
</Button>
@@ -406,10 +403,10 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
{/* prev next scroll button */}
<div className={`${styles.sheetBarOptions} ${styles.sheetBarScrollButton}`}>
- <Button className={styles.sheetBarOptionsButton} onClick={this.scrollLeft}>
+ <Button className={styles.sheetBarOptionsButton}>
<Icon.NextIcon rotate={90} style={{ padding: '5px' }} />
</Button>
- <Button className={styles.sheetBarOptionsButton} onClick={this.scrollRight}>
+ <Button className={styles.sheetBarOptionsButton}>
<Icon.NextIcon rotate={-90} style={{ padding: '5px' }} />
</Button>
</div>
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
index d714380e9f..6b607eeeae 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
@@ -9,7 +9,7 @@ export interface ISheetBarMenuItem {
selected?: boolean;
index?: string;
sheetId?: string;
- onClick?: (e?: MouseEvent) => void;
+ onClick?: (e?: React.MouseEvent) => void;
}
export interface ISheetBarMenuProps {
diff --git a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
index 333d698fb3..83ca0edc8f 100644
--- a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
@@ -13,8 +13,8 @@ export interface BaseSheetContainerProps extends BaseComponentProps {
export function RenderSheetFooter() {
return (
<>
- <SheetBar></SheetBar>
- <CountBar></CountBar>
+ <SheetBar />
+ <CountBar />
</>
);
}
diff --git a/packages/ui-plugin-sheets/src/controller/clipboard/clipboard.controller.ts b/packages/ui-plugin-sheets/src/controller/clipboard/clipboard.controller.ts
index 9cb7760e35..cb6f063dc7 100644
--- a/packages/ui-plugin-sheets/src/controller/clipboard/clipboard.controller.ts
+++ b/packages/ui-plugin-sheets/src/controller/clipboard/clipboard.controller.ts
@@ -287,7 +287,7 @@ export class SheetClipboardController extends Disposable {
},
onPasteCells(range, matrix) {
- return self._onPasteCells(range, matrix, workbookId, worksheetId);
+ return self._onPasteCells(range, matrix, workbookId!, worksheetId!);
},
onAfterPaste(success) {
diff --git a/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor.command.ts b/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor.command.ts
index c8adada3b7..13fa6f213f 100644
--- a/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor.command.ts
+++ b/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor.command.ts
@@ -8,5 +8,7 @@ export const QuitCellEditorCommand: ICommand = {
handler: async (accessor) => {
const cellEditorService = accessor.get(ICellEditorService);
cellEditorService.quitEditing();
+
+ return true;
},
};
diff --git a/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts b/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
index 093365fdd8..80c8ca81ce 100644
--- a/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
+++ b/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
@@ -5,7 +5,6 @@ import { Dependency, Inject, Injector } from '@wendellhu/redi';
import { SHEET_UI_PLUGIN_NAME } from './Basics';
import { SheetClipboardController } from './controller/clipboard/clipboard.controller';
import { SheetUIController } from './controller/sheet-ui.controller';
-import { en } from './Locale';
import { ICellEditorService } from './services/cell-editor/cell-editor.service';
import { DesktopCellEditorService } from './services/cell-editor/cell-editor-desktop.service';
import { ISheetClipboardService, SheetClipboardService } from './services/clipboard/clipboard.service';
@@ -21,10 +20,6 @@ export class SheetUIPlugin extends Plugin {
}
override onStarting(injector: Injector): void {
- this._localeService.getLocale().load({
- en,
- });
-
(
[
// legacy managers
diff --git a/packages/ui-plugin-slides/src/Basics/Observer.ts b/packages/ui-plugin-slides/src/Basics/Observer.ts
index 44d7dd3622..63e22b84a2 100644
--- a/packages/ui-plugin-slides/src/Basics/Observer.ts
+++ b/packages/ui-plugin-slides/src/Basics/Observer.ts
@@ -1,7 +1,7 @@
import { Observable } from '@univerjs/core';
import { SlideUIPlugin } from '../SlideUIPlugin';
-import { SlideContainer } from '../View';
+import { SlideContainer } from '../View/SlideContainer';
export type SlideUIPluginObserve = {
onUIDidMount: Observable<SlideContainer>;
diff --git a/packages/ui-plugin-slides/src/Controller/SlideContainerUIController.ts b/packages/ui-plugin-slides/src/Controller/SlideContainerUIController.ts
index b82d06c091..f01e41db3b 100644
--- a/packages/ui-plugin-slides/src/Controller/SlideContainerUIController.ts
+++ b/packages/ui-plugin-slides/src/Controller/SlideContainerUIController.ts
@@ -3,7 +3,7 @@ import { LocaleService, LocaleType, ObserverManager } from '@univerjs/core';
import { Inject, Injector, Self, SkipSelf } from '@wendellhu/redi';
import { ISlideUIPluginConfig } from '../Basics';
-import { SlideContainer } from '../View';
+import { SlideContainer } from '../View/SlideContainer';
import { InfoBarUIController } from './InfoBarUIController';
import { SlideBarUIController } from './SlideBarUIController';
import { ToolbarUIController } from './ToolbarUIController';
diff --git a/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts
index 4cba02b05c..df611fae56 100644
--- a/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts
+++ b/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts
@@ -12,10 +12,9 @@ import {
WrapStrategy,
} from '@univerjs/core';
import { Inject, SkipSelf } from '@wendellhu/redi';
-import { ComponentChildren } from 'react';
import { DefaultToolbarConfig, SLIDE_UI_PLUGIN_NAME, SlideToolbarConfig } from '../Basics';
-import { Toolbar } from '../View';
+import { Toolbar } from '../View/Toolbar';
import { TEXT_ROTATE_CHILDREN } from '../View/Toolbar/Const';
import styles from '../View/Toolbar/index.module.less';
@@ -35,7 +34,7 @@ export interface IToolbarItemProps extends BaseToolbarSelectProps {
toolbarType?: ToolbarType;
tooltip?: string; //tooltip文字
border?: boolean;
- suffix?: ComponentChildren;
+ suffix?: React.ReactNode;
}
export class ToolbarUIController {
@@ -254,7 +253,7 @@ export class ToolbarUIController {
}
hideTooltip() {
- const dom = this._toolbar.base as HTMLDivElement;
+ const dom = (this._toolbar as any).current as HTMLDivElement;
const tooltip = dom.querySelectorAll(`.${styles.tooltipTitle}.${styles.bottom}`);
tooltip.forEach((item) => {
(item as HTMLSpanElement).style.display = 'none';
diff --git a/packages/ui-plugin-slides/src/View/App.tsx b/packages/ui-plugin-slides/src/View/App.tsx
deleted file mode 100644
index b0754bcf70..0000000000
--- a/packages/ui-plugin-slides/src/View/App.tsx
+++ /dev/null
@@ -1,75 +0,0 @@
-import { AppContext, BaseComponentProps, ComponentManager } from '@univerjs/base-ui';
-import { LocaleService, LocaleType } from '@univerjs/core';
-import { Component } from 'react';
-
-import { BaseSlideContainerProps, SlideContainer } from './SlideContainer';
-
-export interface BaseUIProps extends BaseComponentProps {
- locale: LocaleType;
- UIConfig: BaseSlideContainerProps;
- componentManager: ComponentManager;
- changeLocale: (locale: string) => void;
-}
-
-interface IState {
- locale: LocaleType;
-}
-
-export class App extends Component<BaseUIProps, IState> {
- constructor(props: BaseUIProps) {
- super(props);
- this.state = {
- locale: this.props.locale,
- };
- }
-
- setLocale(e: Event) {
- const value = (e.target as HTMLSelectElement).value as LocaleType;
- this.props.changeLocale(value);
- this.setState({
- locale: value,
- });
- }
-
- render() {
- const { UIConfig, componentManager, injector } = this.props;
- const { locale } = this.state;
- const localeService = injector.get(LocaleService);
-
- return (
- <AppContext.Provider
- value={{
- localeService,
- locale,
- componentManager,
- }}
- >
- <div
- style={{
- position: 'fixed',
- right: '250px',
- top: '14px',
- fontSize: '14px',
- zIndex: 100,
- }}
- className="univer-dev-operation"
- >
- <span
- style={{
- display: 'inline-block',
- width: 70,
- margin: '5px 0 0 5px',
- }}
- >
- Language
- </span>
- <select value={locale} onChange={this.setLocale.bind(this)} style={{ width: 70 }}>
- <option value="en">English</option>
- <option value="zh">中文</option>
- </select>
- </div>
- <SlideContainer {...UIConfig} />
- </AppContext.Provider>
- );
- }
-}
diff --git a/packages/ui-plugin-slides/src/View/InfoBar/InfoBar.tsx b/packages/ui-plugin-slides/src/View/InfoBar/InfoBar.tsx
index ed4ecaa875..8f03101fa9 100644
--- a/packages/ui-plugin-slides/src/View/InfoBar/InfoBar.tsx
+++ b/packages/ui-plugin-slides/src/View/InfoBar/InfoBar.tsx
@@ -35,7 +35,7 @@ export class InfoBar extends Component<IProps, IState> {
});
}
- render() {
+ override render() {
const { renameSheet } = this.props;
if (!this.state.infoList) return;
diff --git a/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx b/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
index d61417653f..cc2eec4ffd 100644
--- a/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
+++ b/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
@@ -65,7 +65,7 @@ export class SlideBar extends Component<IProps, SlideBarState> {
this.props.activeSlide(pageId);
}
- render() {
+ override render() {
const { addSlide } = this.props;
const { slideList } = this.state;
@@ -84,9 +84,7 @@ export class SlideBar extends Component<IProps, SlideBarState> {
))}
</div>
<div className={styles.slideAddButton}>
- <Button type="text" onClick={addSlide}>
- +
- </Button>
+ <Button onClick={addSlide}>+</Button>
</div>
</div>
);
diff --git a/packages/ui-plugin-slides/src/View/SlideContainer/SlideContainer.tsx b/packages/ui-plugin-slides/src/View/SlideContainer/SlideContainer.tsx
index 327f93cf06..3fd960a11a 100644
--- a/packages/ui-plugin-slides/src/View/SlideContainer/SlideContainer.tsx
+++ b/packages/ui-plugin-slides/src/View/SlideContainer/SlideContainer.tsx
@@ -42,7 +42,7 @@ export class SlideContainer extends Component<BaseSlideContainerProps> {
* split mouse down
* @param e
*/
- handleSplitBarMouseDown = (e: MouseEvent) => {
+ handleSplitBarMouseDown = (e: React.MouseEvent) => {
e = e || window.event; // Compatible with IE browser
// Store the current mouse position
this.leftContentLeft = this.splitLeftRef.current?.getBoundingClientRect().left!;
diff --git a/packages/ui-plugin-slides/src/View/Toolbar/DataBar.tsx b/packages/ui-plugin-slides/src/View/Toolbar/DataBar.tsx
index 70cf08ca22..0c6a0945bb 100644
--- a/packages/ui-plugin-slides/src/View/Toolbar/DataBar.tsx
+++ b/packages/ui-plugin-slides/src/View/Toolbar/DataBar.tsx
@@ -13,7 +13,7 @@ export const DataBar = (props: BarProps) => {
};
return (
- <div style="display: flex;">
+ <div style={{ display: 'flex' }}>
{list.map((item, index) => (
<div
key={index}
diff --git a/packages/ui-plugin-slides/src/View/Toolbar/Toolbar.tsx b/packages/ui-plugin-slides/src/View/Toolbar/Toolbar.tsx
index e3bc392c68..9a6fe2705d 100644
--- a/packages/ui-plugin-slides/src/View/Toolbar/Toolbar.tsx
+++ b/packages/ui-plugin-slides/src/View/Toolbar/Toolbar.tsx
@@ -16,7 +16,7 @@ import { IToolbarItemProps } from '../../Controller';
import styles from './index.module.less';
interface IProps extends BaseComponentProps {
- style?: JSX.CSSProperties;
+ style?: React.CSSProperties;
toolList: IToolbarItemProps[];
}
@@ -31,13 +31,11 @@ interface IState {
export class Toolbar extends Component<IProps, IState> {
static override contextType = AppContext;
- toolbarRef = createRef();
+ toolbarRef = createRef<HTMLDivElement>();
- moreBtnRef = createRef();
+ moreBtnRef = createRef<HTMLDivElement>();
- moreToolRef = createRef();
-
- SelectRef = createRef();
+ moreToolRef = createRef<HTMLDivElement>();
clientWidth = 0;
@@ -79,7 +77,7 @@ export class Toolbar extends Component<IProps, IState> {
};
hide = (e: Event) => {
- if (this.moreToolRef.current.contains(e.target)) return;
+ if (this.moreToolRef.current?.contains(e.target as Node)) return;
e.stopImmediatePropagation();
this.setState({ showMore: false });
document.removeEventListener('click', this.hide, true);
@@ -89,8 +87,8 @@ export class Toolbar extends Component<IProps, IState> {
if (!this.clientWidth) {
this.clientWidth = document.documentElement.clientWidth;
}
- const list = this.toolbarRef.current.querySelectorAll(`.${styles.toolbarWarp} > div`);
- const moreButtonWidth = this.moreBtnRef.current.clientWidth;
+ const list = this.toolbarRef.current?.querySelectorAll(`.${styles.toolbarWarp} > div`)!;
+ const moreButtonWidth = this.moreBtnRef.current?.clientWidth ?? 0;
let width = 60 + moreButtonWidth;
let index = null;
@@ -127,7 +125,7 @@ export class Toolbar extends Component<IProps, IState> {
toolWidth += list[i].clientWidth + 6;
}
- const moreList = this.moreToolRef.current.querySelectorAll(`.${styles.moreTool} > div`);
+ const moreList = this.moreToolRef.current?.querySelectorAll(`.${styles.moreTool} > div`)!;
let moreIndex = null;
let last = false; //最后一个元素
@@ -176,14 +174,15 @@ export class Toolbar extends Component<IProps, IState> {
};
resetUl = () => {
- const wrapper = this.getContext()
+ // @ts-ignore
+ const wrapper = this.context()
.getPluginManager()
.getPluginByName<SlideUIPlugin>(SLIDE_UI_PLUGIN_NAME)
?.getAppUIController()
.getSlideContainerController()
.getContentRef().current!;
const height = `${(wrapper as HTMLDivElement).offsetHeight}px`;
- const ul = this.toolbarRef.current.querySelectorAll('ul');
+ const ul = this.toolbarRef.current?.querySelectorAll('ul')!;
for (let i = 0; i < ul.length; i++) {
ul[i].style.maxHeight = height;
}
@@ -205,13 +204,7 @@ export class Toolbar extends Component<IProps, IState> {
if (item.show) {
return (
<Tooltip key={index} title={item.tooltip} placement={'bottom'}>
- <Button
- unActive={item.unActive}
- className={styles.textButton}
- type="text"
- active={item.active}
- onClick={item.onClick}
- >
+ <Button className={styles.textButton} active={item.active} onClick={item.onClick}>
<CustomLabel label={item.label} />
</Button>
</Tooltip>
@@ -242,7 +235,7 @@ export class Toolbar extends Component<IProps, IState> {
});
}
- render() {
+ override render() {
const { defaultToolList, moreToolList, showMore } = this.state;
return (
@@ -259,7 +252,7 @@ export class Toolbar extends Component<IProps, IState> {
title={(<CustomLabel label="toolbar.toolMoreTip" />) as unknown as string}
placement={'bottom'}
>
- <Button type="text" onClick={this.showMore}>
+ <Button onClick={this.showMore}>
<div style={{ fontSize: '14px' }}>
<CustomLabel label="toolbar.toolMore" />
</div>
diff --git a/packages/ui-plugin-slides/src/View/index.tsx b/packages/ui-plugin-slides/src/View/index.tsx
deleted file mode 100644
index a0bac79c33..0000000000
--- a/packages/ui-plugin-slides/src/View/index.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-import { isElement } from '@univerjs/base-ui';
-import { createRoot } from 'react-dom/client';
-
-import { App, BaseUIProps } from './App';
-
-interface BaseSlideUIConfig extends BaseUIProps {
- container?: HTMLElement | string;
-}
-
-export class UI {
- constructor(props: BaseSlideUIConfig) {
- this._initialize(props);
- }
-
- static create(props: BaseSlideUIConfig) {
- return new UI(props);
- }
-
- private _initialize(props: BaseSlideUIConfig) {
- let renderContainer: HTMLElement;
- const container = props.container;
-
- if (typeof container === 'string') {
- const containerDOM = document.getElementById(container);
- if (containerDOM == null) {
- renderContainer = document.createElement('div');
- renderContainer.id = container;
- } else {
- renderContainer = containerDOM;
- }
- } else if (isElement(container)) {
- renderContainer = container!;
- } else {
- renderContainer = document.createElement('div');
- renderContainer.id = 'univer';
- }
-
- const root = createRoot(renderContainer);
- root.render(<App {...props} />);
- }
-}
-
-export * from './SlideContainer';
-export * from './Toolbar';