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(ui): fix react type error (#120)

Dushusir7e8cbd334f1e
diff --git a/packages/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsx
index 44acc85500..653400088b 100644
--- a/packages/base-ui/src/Components/Menu/Menu.tsx
+++ b/packages/base-ui/src/Components/Menu/Menu.tsx
@@ -1,5 +1,5 @@
import { ICommandService, isRealNum } from '@univerjs/core';
-import { Component, ComponentChild, createRef, Fragment } from 'react';
+import { Component, createRef, Fragment } from 'react';
import { Subscription } from 'rxjs';
import { AppContext } from '../../Common/AppContext';
@@ -117,11 +117,10 @@ export class Menu extends Component<BaseMenuProps, IBaseMenuState> {
};
// eslint-disable-next-line max-lines-per-function
- render() {
+ override render() {
const { context, props, state } = this;
const { className = '', style = '', menu, deep = 0, options, display, value } = props;
const { posStyle, show, menuItems } = state;
-
return (
<ul className={joinClassNames(styles.colsMenu, className)} style={{ ...style, ...posStyle, display: show ? 'block' : 'none' }} ref={this._MenuRef}>
{/* legacy: render selections */}
@@ -199,6 +198,10 @@ export class Menu extends Component<BaseMenuProps, IBaseMenuState> {
</li>
);
})}
+ {/* render submenus */}
+ {menuItems?.map((item: IDisplayMenuItem<IMenuItem>, index) => (
+ <MenuItem menuItem={item} key={index} index={index} onClick={this.handleItemClick.bind(this, item as IMenuButtonItem)} />
+ ))}
</ul>
);
}
@@ -238,7 +241,7 @@ export interface IMenuItemState {
// TODO: this component should have something in common with ToolbarItem
export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
- static override contextType = AppContext;
+ static contextType = AppContext;
private disabledSubscription: Subscription | undefined;
@@ -310,7 +313,7 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
});
};
- override render(): ComponentChild {
+ override render() {
switch (this.props.menuItem.type) {
case MenuItemType.SELECTOR:
return this.renderSelectorType();
@@ -322,7 +325,7 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
}
// button type command should directly execute command
- private renderButtonType(): ComponentChild {
+ private renderButtonType() {
const { menuItem, onClick } = this.props;
const { disabled, value } = this.state;
const { injector } = this.context;
@@ -355,7 +358,7 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
);
}
- private renderSelectorType(): ComponentChild {
+ private renderSelectorType() {
const { menuItem, index } = this.props;
const { disabled, menuItems, value } = this.state;
const item = menuItem as IDisplayMenuItem<IMenuSelectorItem<unknown>>;
@@ -384,7 +387,7 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
);
}
- private renderSubItemsType(): ComponentChild {
+ private renderSubItemsType() {
const { menuItem, index } = this.props;
const { disabled, menuItems } = this.state;
const item = menuItem as IDisplayMenuItem<IMenuSelectorItem<unknown>>;
diff --git a/packages/base-ui/src/Interfaces/SheetBar.ts b/packages/base-ui/src/Interfaces/SheetBar.ts
index ac96008ae5..2cb5897f0d 100644
--- a/packages/base-ui/src/Interfaces/SheetBar.ts
+++ b/packages/base-ui/src/Interfaces/SheetBar.ts
@@ -8,7 +8,7 @@ export interface BaseSheetBarProps extends BaseComponentProps, Omit<BaseSelectPr
index?: string;
color?: string;
sheetId?: string;
- style?: JSX.CSSProperties;
+ style?: React.CSSProperties;
hidden?: BooleanNumber;
addSheet?: () => void;
onMouseDown?: () => void;
diff --git a/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
index a464cff3aa..973792bf44 100644
--- a/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
@@ -3,7 +3,6 @@ import { CanvasView } from '@univerjs/base-sheets';
import { BaseMenuItem, ComponentManager, ICustomLabelType, IMenuItemFactory, IMenuService, MenuPosition } from '@univerjs/base-ui';
import { Disposable } from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
-import { ComponentChildren } from 'react';
import { SheetRightMenuConfig } from '../Basics';
import { RightMenu, RightMenuInput, RightMenuItem } from '../View';
@@ -21,7 +20,7 @@ import {
} from './menu';
export interface RightMenuProps extends BaseMenuItem {
- label?: string | ICustomLabelType | ComponentChildren;
+ label?: string | ICustomLabelType | JSX.Element;
children?: RightMenuProps[];
suffix?: string;
border?: boolean;
diff --git a/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx b/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx
index 555deb3a9b..9f43066c10 100644
--- a/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx
@@ -1,9 +1,10 @@
-import { BaseComponentProps, ICustomComponent, CustomLabel } from '@univerjs/base-ui';
-import { Component, ComponentChildren } from 'react';
+import { BaseComponentProps, CustomLabel, ICustomComponent } from '@univerjs/base-ui';
+import { Component } from 'react';
+
import styles from './index.module.less';
interface IProps extends BaseComponentProps {
- label?: ComponentChildren | ICustomComponent;
+ label?: JSX.Element | ICustomComponent;
id: string;
color: string;
}
@@ -31,7 +32,7 @@ export class ColorSelect extends Component<IProps, IState> {
});
}
- render() {
+ override render() {
const { label } = this.props;
return (
<div className={styles.colorSelect}>
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 320e39b66c..bd7fcfed18 100644
--- a/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
@@ -1,5 +1,6 @@
-import { BaseComponentProps, AppContext, Icon, CustomLabel } from '@univerjs/base-ui';
+import { AppContext, BaseComponentProps, CustomLabel, Icon } from '@univerjs/base-ui';
import { Component } from 'react';
+
import { BORDER_SIZE_CHILDREN } from '../../../Controller/menu/border.menu';
interface IState {
@@ -54,7 +55,7 @@ export class LineBold extends Component<IProps, IState> {
}
}
- render() {
+ override render() {
const { img } = this.state;
const { title, value } = this.props;
const imgComponent = img && this.getImg(img);
diff --git a/packages/ui-plugin-sheets/src/View/Common/Line/LineColor.tsx b/packages/ui-plugin-sheets/src/View/Common/Line/LineColor.tsx
index 73292067ac..387ff51708 100644
--- a/packages/ui-plugin-sheets/src/View/Common/Line/LineColor.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/Line/LineColor.tsx
@@ -38,7 +38,7 @@ export class LineColor extends Component<IProps, IState> {
});
}
- render() {
+ override render() {
const { color } = this.state;
const { label } = this.props;
diff --git a/packages/ui-plugin-sheets/src/View/Common/test.tsx b/packages/ui-plugin-sheets/src/View/Common/test.tsx
deleted file mode 100644
index 76c275599d..0000000000
--- a/packages/ui-plugin-sheets/src/View/Common/test.tsx
+++ /dev/null
@@ -1,16 +0,0 @@
-import { SiderModal } from '@univerjs/base-ui';
-import { Component } from 'react';
-
-type IProps = {};
-
-type IState = {};
-
-export class Test extends Component<IProps, IState> {
- render() {
- return (
- <SiderModal zIndex={92} name="test" title={'test'} style={{ width: '30%', background: 'red' }}>
- Hello
- </SiderModal>
- );
- }
-}
diff --git a/packages/ui-plugin-sheets/src/View/Common/test1.tsx b/packages/ui-plugin-sheets/src/View/Common/test1.tsx
deleted file mode 100644
index 559ca14620..0000000000
--- a/packages/ui-plugin-sheets/src/View/Common/test1.tsx
+++ /dev/null
@@ -1,16 +0,0 @@
-import { SiderModal } from '@univerjs/base-ui';
-import { Component } from 'react';
-
-type IProps = {};
-
-type IState = {};
-
-export class Test1 extends Component<IProps, IState> {
- render() {
- return (
- <SiderModal zIndex={91} name="test1" title={'test1'} style={{ width: '70%', background: '#abcdef' }}>
- Hello 1
- </SiderModal>
- );
- }
-}
diff --git a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
index 528cb624cb..e3bc4df19a 100644
--- a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
@@ -1,7 +1,8 @@
-import { BaseCountBarProps, Button, CountBarComponent, Icon, JSXComponent, Slider, AppContext } from '@univerjs/base-ui';
-import { Component, createRef } from 'react';
+import { AppContext, BaseCountBarProps, Button, CountBarComponent, Icon, JSXComponent, Slider } from '@univerjs/base-ui';
import { ObserverManager, PLUGIN_NAMES } from '@univerjs/core';
import { Injector } from '@wendellhu/redi';
+import { Component, createRef } from 'react';
+
import styles from './index.module.less';
interface CountState {
@@ -90,7 +91,7 @@ export class CountBar extends Component<CountBarProps, CountState> {
(this.context.injector as Injector).get(ObserverManager).getObserver<CountBar>('onCountBarDidMountObservable', PLUGIN_NAMES.SPREADSHEET)?.notifyObservers(this);
}
- render() {
+ override render() {
const { zoom, content } = this.state;
// const PageIcon = this.getComponentRender().renderFunction('PageIcon');
// const LayoutIcon = this.getComponentRender().renderFunction('LayoutIcon');
diff --git a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
index 68481bca5d..5b3d8592f1 100644
--- a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
@@ -1,6 +1,7 @@
import { AppContext, BaseComponentProps, BaseComponentRender, BaseSelectChildrenProps, debounce, Icon } from '@univerjs/base-ui';
-import { Component } from 'react';
import { Nullable } from '@univerjs/core';
+import { Component } from 'react';
+
import styles from './index.module.less';
type FormulaState = {
@@ -71,7 +72,7 @@ export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
});
}
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
// this._context.getObserverManager().getObserver<FormulaBar>('onFormulaBarDidMountObservable')?.notifyObservers(this);
}
@@ -82,7 +83,7 @@ export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
return <Icon />;
}
- render() {
+ override render() {
// TODO: formula bar top left menu: 1. cell edit formula ,use formula list 2. cell selection ,use named range, 3. cell edit no formula, disable select
const { namedRanges, fx } = this.state;
diff --git a/packages/ui-plugin-sheets/src/View/InfoBar/InfoBar.tsx b/packages/ui-plugin-sheets/src/View/InfoBar/InfoBar.tsx
index fc75035cac..6ad2528a95 100644
--- a/packages/ui-plugin-sheets/src/View/InfoBar/InfoBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/InfoBar/InfoBar.tsx
@@ -1,6 +1,7 @@
import { BaseComponentProps, Container, CustomLabel, Input, Tooltip } from '@univerjs/base-ui';
-import { Component } from 'react';
import { Nullable } from '@univerjs/core';
+import { Component } from 'react';
+
import { BaseInfoBarProps } from '../../Controller/InfoBarUIController';
import styles from './index.module.less';
@@ -34,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-sheets/src/View/RichText/CellTextStyle.ts b/packages/ui-plugin-sheets/src/View/RichText/CellTextStyle.ts
index 251c375534..887a371cc5 100644
--- a/packages/ui-plugin-sheets/src/View/RichText/CellTextStyle.ts
+++ b/packages/ui-plugin-sheets/src/View/RichText/CellTextStyle.ts
@@ -1,5 +1,7 @@
+/* eslint-disable max-lines-per-function */
import { $$, selectTextContent, selectTextContentCross, textTrim } from '@univerjs/base-ui';
import { Color } from '@univerjs/core';
+
import styles from './index.module.less';
interface IStyleSetting {
@@ -55,7 +57,7 @@ export class CellTextStyle {
updateFormat(attr: keyof IStyleSetting, foucsStatus: number | string) {
if (attr in this.inlineStyleAffectAttribute) {
// TODO: 不要使用 $$
- let value = this.editor.textContent!;
+ const value = this.editor.textContent!;
if (value.substr(0, 1) !== '=') {
this.updateInlineStringFormat(attr, foucsStatus);
}
@@ -63,7 +65,7 @@ export class CellTextStyle {
}
updateInlineStringFormat(attr: keyof IStyleSetting, value: number | string) {
- let w = window.getSelection();
+ const w = window.getSelection();
let range;
if (w?.type === 'None') {
// range = Store.inlineStringEditRange;
@@ -74,22 +76,22 @@ export class CellTextStyle {
if (!range) return;
// TODO: 不要使用 $$
- let $textEditor = this.editor;
+ const $textEditor = this.editor;
- let endContainer = range.endContainer;
- let startContainer = range.startContainer;
- let endOffset = range.endOffset;
- let startOffset = range.startOffset;
+ const endContainer = range.endContainer;
+ const startContainer = range.startContainer;
+ const endOffset = range.endOffset;
+ const startOffset = range.startOffset;
if ($textEditor) {
if (startContainer === endContainer) {
- let span = startContainer.parentNode as HTMLElement;
+ const span = startContainer.parentNode as HTMLElement;
let spanIndex;
let inherit = false;
- let content = span.innerHTML;
+ const content = span.innerHTML;
- let fullContent = $textEditor.innerHTML;
+ const fullContent = $textEditor.innerHTML;
if (fullContent.substr(0, 5) !== '<span') {
inherit = true;
}
@@ -97,10 +99,10 @@ export class CellTextStyle {
let left = '';
let mid = '';
let right = '';
- let s1 = 0;
- let s2 = startOffset;
- let s3 = endOffset;
- let s4 = content.length;
+ const s1 = 0;
+ const s2 = startOffset;
+ const s3 = endOffset;
+ const s4 = content.length;
left = content.substring(s1, s2);
mid = content.substring(s2, s3);
right = content.substring(s3, s4);
@@ -109,7 +111,7 @@ export class CellTextStyle {
if (left !== '') {
let cssText = span.style.cssText;
if (inherit) {
- let box = span.closest(`.${styles.richTextEditorContainer}`) as HTMLElement;
+ const box = span.closest(`.${styles.richTextEditorContainer}`) as HTMLElement;
if (box != null) {
cssText = this.extendCssText(box.style.cssText, cssText);
}
@@ -121,7 +123,7 @@ export class CellTextStyle {
let cssText = this.getCssText(span.style.cssText, attr, value);
if (inherit) {
- let box = span.closest(`.${styles.richTextEditorContainer}`) as HTMLElement;
+ const box = span.closest(`.${styles.richTextEditorContainer}`) as HTMLElement;
if (box != null) {
cssText = this.extendCssText(box.style.cssText, cssText);
}
@@ -133,7 +135,7 @@ export class CellTextStyle {
if (right !== '') {
let cssText = span.style.cssText;
if (inherit) {
- let box = span.closest(`.${styles.richTextEditorContainer}`) as HTMLElement;
+ const box = span.closest(`.${styles.richTextEditorContainer}`) as HTMLElement;
if (box != null) {
cssText = this.extendCssText(box.style.cssText, cssText);
}
@@ -144,8 +146,8 @@ export class CellTextStyle {
if ((startContainer.parentNode as HTMLElement).tagName === 'SPAN') {
spanIndex = $$('span', $textEditor).indexOf(span);
// spanIndex = $textEditor.find('span').index(span);
- let spanP = span.parentElement?.innerHTML;
- let spanText = span.outerHTML.replace('\\', '');
+ const spanP = span.parentElement?.innerHTML;
+ const spanText = span.outerHTML.replace('\\', '');
const newS = spanP?.replace(spanText, cont);
span.parentElement!.innerHTML = newS!;
// span.replaceWith(cont);
@@ -163,26 +165,24 @@ export class CellTextStyle {
selectTextContent($textEditor.querySelectorAll('span')[seletedNodeIndex]);
} else if ((startContainer.parentNode as HTMLElement).tagName === 'SPAN' && (endContainer.parentNode as HTMLElement).tagName === 'SPAN') {
- let startSpan = startContainer.parentNode as HTMLElement;
- let startSpanIndex;
- let endSpan = endContainer.parentNode as HTMLElement;
- let endSpanIndex;
+ const startSpan = startContainer.parentNode as HTMLElement;
+ const endSpan = endContainer.parentNode as HTMLElement;
- startSpanIndex = $$('span', $textEditor).indexOf(startSpan);
- endSpanIndex = $$('span', $textEditor).indexOf(endSpan);
+ const startSpanIndex = $$('span', $textEditor).indexOf(startSpan);
+ const endSpanIndex = $$('span', $textEditor).indexOf(endSpan);
// startSpanIndex = $textEditor.find('span').index(startSpan);
// endSpanIndex = $textEditor.find('span').index(endSpan);
- let startContent = (startSpan as HTMLElement).innerHTML;
- let endContent = (endSpan as HTMLElement).innerHTML;
+ const startContent = (startSpan as HTMLElement).innerHTML;
+ const endContent = (endSpan as HTMLElement).innerHTML;
let sleft = '';
let sright = '';
let eleft = '';
let eright = '';
- let s1 = 0;
- let s2 = startOffset;
- let s3 = endOffset;
- let s4 = endContent.length;
+ const s1 = 0;
+ const s2 = startOffset;
+ const s3 = endOffset;
+ const s4 = endContent.length;
sleft = startContent.substring(s1, s2);
sright = startContent.substring(s2, startContent.length);
@@ -190,12 +190,12 @@ export class CellTextStyle {
eleft = endContent.substring(0, s3);
eright = endContent.substring(s3, s4);
let spans = Array.prototype.slice.call($textEditor.querySelectorAll('span'));
- let replaceSpans = spans.slice(startSpanIndex, endSpanIndex + 1);
+ const replaceSpans = spans.slice(startSpanIndex, endSpanIndex + 1);
let cont = '';
for (let i = 0; i < startSpanIndex; i++) {
// let span = spans.get(i),
- let span: HTMLElement = spans[`${i}`];
- let content = span.innerHTML;
+ const span: HTMLElement = spans[`${i}`];
+ const content = span.innerHTML;
cont += `<span style='${span.style.cssText}'>${content}</span>`;
}
if (sleft !== '') {
@@ -203,22 +203,22 @@ export class CellTextStyle {
}
if (sright !== '') {
- let cssText = this.getCssText(startSpan.style.cssText, attr, value);
+ const cssText = this.getCssText(startSpan.style.cssText, attr, value);
cont += `<span style='${cssText}'>${sright}</span>`;
}
if (startSpanIndex < endSpanIndex) {
for (let i: number = startSpanIndex + 1; i < endSpanIndex; i++) {
// let span = spans.get(i),
- let span = spans[`${i}`];
- let content = span.innerHTML;
- let cssText = this.getCssText(span.style.cssText, attr, value);
+ const span = spans[`${i}`];
+ const content = span.innerHTML;
+ const cssText = this.getCssText(span.style.cssText, attr, value);
cont += `<span style='${cssText}'>${content}</span>`;
}
}
if (eleft !== '') {
- let cssText = this.getCssText(endSpan.style.cssText, attr, value);
+ const cssText = this.getCssText(endSpan.style.cssText, attr, value);
cont += `<span style='${cssText}'>${eleft}</span>`;
}
@@ -228,8 +228,8 @@ export class CellTextStyle {
for (let i: number = endSpanIndex + 1; i < spans.length; i++) {
// let span = spans.get(i),
- let span = spans[`${i}`];
- let content = span.innerHTML;
+ const span = spans[`${i}`];
+ const content = span.innerHTML;
cont += `<span style='${span.style.cssText}'>${content}</span>`;
}
@@ -259,23 +259,23 @@ export class CellTextStyle {
}
extendCssText(origin: string, cover: string, isLimit = true) {
- let originArray = origin.split(';');
- let coverArray = cover.split(';');
+ const originArray = origin.split(';');
+ const coverArray = cover.split(';');
let newCss = '';
- let addKeyList: Record<string, string | number> = {};
+ const addKeyList: Record<string, string | number> = {};
for (let i = 0; i < originArray.length; i++) {
let so = originArray[i];
let isAdd = true;
so = so.toLowerCase();
- let okey = textTrim(so.substr(0, so.indexOf(':')));
+ const okey = textTrim(so.substr(0, so.indexOf(':')));
/* 不设置文字的大小,解决设置删除线等后字体变大的问题 */
if (okey === 'font-size') {
continue;
}
- let ovalue = textTrim(so.substr(so.indexOf(':') + 1));
+ const ovalue = textTrim(so.substr(so.indexOf(':') + 1));
if (isLimit) {
if (!(okey in this.inlineStyleAffectCssName)) {
@@ -286,8 +286,8 @@ export class CellTextStyle {
for (let a = 0; a < coverArray.length; a++) {
let sc = coverArray[a];
sc = sc.toLowerCase();
- let ckey = textTrim(sc.substr(0, sc.indexOf(':')));
- let cvalue = textTrim(sc.substr(sc.indexOf(':') + 1));
+ const ckey = textTrim(sc.substr(0, sc.indexOf(':')));
+ const cvalue = textTrim(sc.substr(sc.indexOf(':') + 1));
if (okey === ckey) {
newCss += `${ckey}:${cvalue};`;
@@ -306,8 +306,8 @@ export class CellTextStyle {
for (let a = 0; a < coverArray.length; a++) {
let sc = coverArray[a];
sc = sc.toLowerCase();
- let ckey = textTrim(sc.substr(0, sc.indexOf(':')));
- let cvalue = textTrim(sc.substr(sc.indexOf(':') + 1));
+ const ckey = textTrim(sc.substr(0, sc.indexOf(':')));
+ const cvalue = textTrim(sc.substr(sc.indexOf(':') + 1));
if (isLimit) {
if (!(ckey in this.inlineStyleAffectCssName)) {
@@ -324,14 +324,14 @@ export class CellTextStyle {
}
getCssText(cssText: string, attr: keyof IStyleSetting, value: string | number) {
- let styleObj: IStyleSetting = {};
+ const styleObj: IStyleSetting = {};
(styleObj[attr] as string | number) = value;
if (attr === 'un') {
let fontColor = this.getClassWithcss(cssText, 'color');
if (fontColor === '') {
fontColor = '#000000';
}
- let fs = this.getClassWithcss(cssText, 'font-size');
+ const fs = this.getClassWithcss(cssText, 'font-size');
let fsNum = parseInt(fs);
if (fs === '') {
fsNum = 11;
@@ -340,8 +340,8 @@ export class CellTextStyle {
styleObj._fontSize = fsNum;
styleObj._color = fontColor;
}
- let s: string | undefined = this.getFontStyleByCell(styleObj, undefined, undefined, false);
- let ukey = textTrim(s && s.substr(0, s.indexOf(':')));
+ const s: string | undefined = this.getFontStyleByCell(styleObj, undefined, undefined, false);
+ const ukey = textTrim(s && s.substr(0, s.indexOf(':')));
let uvalue = textTrim(s && s.substr(s.indexOf(':') + 1));
uvalue = uvalue.substr(0, uvalue.length - 1);
// let cssText = span.style.cssText;
@@ -353,7 +353,7 @@ export class CellTextStyle {
}
getClassWithcss(cssText: string, ukey: string): string {
- let cssTextArray = cssText.split(';');
+ const cssTextArray = cssText.split(';');
if (ukey == null || ukey.length === 0) {
return cssText;
}
@@ -361,8 +361,8 @@ export class CellTextStyle {
for (let i = 0; i < cssTextArray.length; i++) {
let s = cssTextArray[i];
s = s.toLowerCase();
- let key = textTrim(s.substr(0, s.indexOf(':')));
- let value = textTrim(s.substr(s.indexOf(':') + 1));
+ const key = textTrim(s.substr(0, s.indexOf(':')));
+ const value = textTrim(s.substr(s.indexOf(':') + 1));
if (key === ukey) {
return value;
}
@@ -373,9 +373,9 @@ export class CellTextStyle {
}
removeClassWidthCss(cssText: string, ukey: string) {
- let cssTextArray = cssText.split(';');
+ const cssTextArray = cssText.split(';');
let newCss = '';
- let oUkey = ukey;
+ const oUkey = ukey;
if (ukey == null || ukey.length === 0) {
return cssText;
}
@@ -386,8 +386,8 @@ export class CellTextStyle {
for (let i = 0; i < cssTextArray.length; i++) {
let s = cssTextArray[i];
s = s.toLowerCase();
- let key = textTrim(s.substr(0, s.indexOf(':')));
- let value = textTrim(s.substr(s.indexOf(':') + 1));
+ const key = textTrim(s.substr(0, s.indexOf(':')));
+ const value = textTrim(s.substr(s.indexOf(':') + 1));
if (key === ukey || (oUkey === 'cl' && key === 'lucky-strike') || (oUkey === 'un' && key === 'lucky-underline')) {
continue;
} else if (key.length > 0) {
@@ -402,7 +402,7 @@ export class CellTextStyle {
}
upsetClassWithCss(cssText: string, ukey: string, uvalue: string) {
- let cssTextArray = cssText.split(';');
+ const cssTextArray = cssText.split(';');
let newCss = '';
if (ukey == null || ukey.length === 0) {
return cssText;
@@ -411,8 +411,8 @@ export class CellTextStyle {
for (let i = 0; i < cssTextArray.length; i++) {
let s = cssTextArray[i];
s = s.toLowerCase();
- let key = textTrim(s.substr(0, s.indexOf(':')));
- let value = textTrim(s.substr(s.indexOf(':') + 1));
+ const key = textTrim(s.substr(0, s.indexOf(':')));
+ const value = textTrim(s.substr(s.indexOf(':') + 1));
if (key === ukey) {
newCss += `${key}:${uvalue};`;
} else if (key.length > 0) {
@@ -432,7 +432,7 @@ export class CellTextStyle {
return '';
}
let style = '';
- for (let key in cell) {
+ for (const key in cell) {
let value = cell[key as keyof IStyleSetting];
if (isCheck) {
value = this.checkstatusByCell(cell, key);
@@ -446,7 +446,7 @@ export class CellTextStyle {
}
if (key === 'ff') {
- let f = value;
+ const f = value;
style += `font-family: ${f};`;
}
@@ -490,7 +490,7 @@ export class CellTextStyle {
checkstatusByCell(cell: IStyleSetting, a: string) {
// 获取当前单元格配置 默认值
let foucsStatus: any;
- let tf = { bl: 1, it: 1, ff: 1, cl: 1, un: 1 };
+ const tf = { bl: 1, it: 1, ff: 1, cl: 1, un: 1 };
if (a in tf) {
if (foucsStatus == null) {
diff --git a/packages/ui-plugin-sheets/src/View/RichText/RichText.tsx b/packages/ui-plugin-sheets/src/View/RichText/RichText.tsx
index bef10234b5..e11a2dc2a5 100644
--- a/packages/ui-plugin-sheets/src/View/RichText/RichText.tsx
+++ b/packages/ui-plugin-sheets/src/View/RichText/RichText.tsx
@@ -1,6 +1,7 @@
// import { CellInputHandler } from '@univerjs/sheets-plugin-formula/src/Controller/CellInputHandler';
import { BaseComponentProps, xssDeal } from '@univerjs/base-ui';
-import { Component, createRef } from 'react';
+import { Component, createRef, KeyboardEvent, MouseEventHandler } from 'react';
+
import { CellTextStyle } from './CellTextStyle';
import styles from './index.module.less';
// interface IProps {
@@ -15,7 +16,7 @@ export interface IRichTextState {}
export interface BaseRichTextProps extends BaseComponentProps {
style?: {};
className?: string;
- onClick?: (e: MouseEvent) => void;
+ onClick?: MouseEventHandler<HTMLDivElement>;
text?: string;
}
@@ -68,7 +69,7 @@ export class RichText extends Component<BaseRichTextProps, IRichTextState> {
this.container.current!.style.display = 'none';
}
- onKeyDown(event: KeyboardEvent) {
+ onKeyDown(event: KeyboardEvent<HTMLDivElement>) {
// let ctrlKey = event.ctrlKey;
// let altKey = event.altKey;
// let shiftKey = event.shiftKey;
@@ -137,7 +138,7 @@ export class RichText extends Component<BaseRichTextProps, IRichTextState> {
// }
}
- onKeyUp(event: KeyboardEvent) {
+ onKeyUp(event: KeyboardEvent<HTMLDivElement>) {
const onKeyUp = this.hooks.get('onKeyUp');
onKeyUp && onKeyUp(event);
@@ -169,7 +170,7 @@ export class RichText extends Component<BaseRichTextProps, IRichTextState> {
// this._context.getObserverManager().getObserver<WorkBook>('onAfterChangeUILocaleObservable', 'workbook')?.remove(this._localeObserver);
}
- render() {
+ override render() {
const { style, className = '', onClick, text } = this.props;
return (
<div className={`${styles.richTextEditorContainer} ${className}`} style={style} ref={this.container}>
@@ -177,8 +178,8 @@ export class RichText extends Component<BaseRichTextProps, IRichTextState> {
ref={this.ref}
className={styles.richTextEditor}
onClick={onClick}
- onKeyDown={this.onKeyDown.bind(this)}
- onKeyUp={this.onKeyUp.bind(this)}
+ onKeyDown={(event) => this.onKeyDown(event)}
+ onKeyUp={(event) => this.onKeyUp(event)}
dangerouslySetInnerHTML={{ __html: text || '' }}
contentEditable
></div>
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
index 47d782958e..6d2c8dde3d 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
@@ -1,6 +1,7 @@
import { IMouseEvent } from '@univerjs/base-render';
import { BaseRightMenuProps, IDisplayMenuItem, IMenuItem, Menu, MenuPosition } from '@univerjs/base-ui';
import { Component, createRef } from 'react';
+
import { RightMenuProps } from '../../Controller';
import Style from './index.module.less';
@@ -13,9 +14,9 @@ interface IState {
}
export class RightMenu extends Component<BaseRightMenuProps, IState> {
- ulRef = createRef();
+ ulRef = createRef<Menu>();
- root = createRef();
+ root = createRef<HTMLDivElement>();
constructor(props: BaseRightMenuProps) {
super(props);
@@ -62,7 +63,7 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
this.setState({ visible: true, srcElement: event.target, eventType: event.type }, () => {
new Promise<void>((resolve, reject) => {
- this.ulRef.current.showMenu(true);
+ this.ulRef.current?.showMenu(true);
resolve();
}).then(() => {
// clientX/Y 获取到的是触发点相对于浏览器可视区域左上角距离
@@ -75,9 +76,9 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
const screenW = window.innerWidth;
const screenH = window.innerHeight;
// 获取自定义菜单的宽度/高度
-
- const rootW = this.ulRef.current.base.offsetWidth;
- const rootH = this.ulRef.current.base.offsetHeight;
+ const currentUl = this.ulRef.current?.getMenuRef().current;
+ const rootW = currentUl?.offsetWidth || 0;
+ const rootH = currentUl?.offsetHeight || 0;
// right为true,说明鼠标点击的位置到浏览器的右边界的宽度可以放下菜单。否则,菜单放到左边。
// bottom为true,说明鼠标点击位置到浏览器的下边界的高度可以放下菜单。否则,菜单放到上边。
@@ -86,19 +87,22 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
const bottom = screenH - clickY > rootH;
const top = !bottom;
+ const current = this.root.current;
+ if (!current) return;
+
if (right) {
- this.root.current.style.left = `${clickX}px`;
+ current.style.left = `${clickX}px`;
}
if (left) {
- this.root.current.style.left = `${clickX - rootW}px`;
+ current.style.left = `${clickX - rootW}px`;
}
if (bottom) {
- this.root.current.style.top = `${clickY}px`;
+ current.style.top = `${clickY}px`;
}
if (top) {
- this.root.current.style.top = `${clickY - rootH}px`;
+ current.style.top = `${clickY - rootH}px`;
}
});
});
@@ -124,7 +128,7 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
this.ulRef.current.showMenu(show);
}
- render() {
+ override render() {
const wrapStyles = { ...this.props.style };
const { visible } = this.state;
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuButton.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuButton.tsx
index 18a6564a2f..4e4a5f7072 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuButton.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuButton.tsx
@@ -11,14 +11,16 @@ interface IPropsChildren {
}
export class RightMenuButton extends Component<IProps> {
- render() {
+ override render() {
const { label, children } = this.props;
return (
<div>
{label}
{children.map((item: IPropsChildren, index) => (
- <Button key={index} type="primary">{item.label}</Button>
+ <Button key={index} type="primary">
+ {item.label}
+ </Button>
))}
</div>
);
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
index 600a9e62d5..afb09c860d 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
@@ -1,5 +1,5 @@
import { CustomLabel, ICustomComponentProps, Input } from '@univerjs/base-ui';
-import { Component } from 'react';
+import React, { useState } from 'react';
interface IProps extends ICustomComponentProps<string> {
prefix: string;
@@ -7,27 +7,20 @@ interface IProps extends ICustomComponentProps<string> {
onKeyUp?: (e: Event) => void;
}
-export class RightMenuInput extends Component<IProps> {
- private value = '';
+export const RightMenuInput: React.FC<IProps> = ({ prefix, suffix, onChange }) => {
+ const [inputValue, setInputValue] = useState<string>(''); // Initialized to an empty string
- render() {
- const { prefix, suffix, value } = this.props;
- return (
- <div>
- <CustomLabel label={prefix} />
- <Input type="number" placeholder="1" value={value} onClick={(e) => e.stopPropagation()} onChange={this.onChange.bind(this)}></Input>
- <CustomLabel label={suffix} />
- </div>
- );
- }
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
+ const newValue = e.target.value;
+ setInputValue(newValue);
+ onChange(newValue);
+ };
- // private handleClick(e: Event) {
- // e.stopPropagation();
- // this.props.onChange?.(this.value);
- // }
-
- private onChange(e: Event) {
- const value = (e.target as HTMLInputElement).value;
- this.props.onChange(value);
- }
-}
+ return (
+ <div>
+ <CustomLabel label={prefix} />
+ <Input type="number" placeholder="1" value={inputValue} onClick={(e) => e.stopPropagation()} onChange={handleChange}></Input>
+ <CustomLabel label={suffix} />
+ </div>
+ );
+};
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx
index 64c895f9cf..10f19aceb9 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx
@@ -1,5 +1,6 @@
import { CustomLabel, Icon } from '@univerjs/base-ui';
import { Component } from 'react';
+
import styles from './index.module.less';
interface IProps {
@@ -7,7 +8,7 @@ interface IProps {
}
export class RightMenuItem extends Component<IProps> {
- render() {
+ override render() {
const { label } = this.props;
return (
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
index bcfcee5099..a464eb7026 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
@@ -17,13 +17,13 @@ type SheetState = {
export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
static override contextType = AppContext;
- ref = createRef();
+ ref = createRef<SheetBarMenu>();
- ulRef = createRef();
+ ulRef = createRef<Menu>();
- sheetContainerRef = createRef();
+ sheetContainerRef = createRef<HTMLDivElement>();
- slideTabRoot = createRef();
+ slideTabRoot = createRef<HTMLDivElement>();
sheetContentRef = createRef();
@@ -54,6 +54,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
sheetList: [],
sheetUl: [],
menuList: [],
+ menuItems: [],
};
}
@@ -62,13 +63,6 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
this.setState((prevState) => ({ ...value }), fn);
};
- // TODO@Dushusir remove after refactoring
- // setSheetUlNeo(menuItems: IMenuItem[]) {
- // this.setState({
- // menuItems: buildMenuTree(menuItems),
- // });
- // }
-
// 点击按钮左右滑动
scrollLeft = (e: MouseEvent) => {
this.slideTabBar.getScrollbar().scrollX(this.slideTabBar.getScrollbar().getScrollX() - 50);
@@ -81,7 +75,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
overGrid = () => {};
// Right click to display menu
- contextMenu = (e: MouseEvent) => {
+ contextMenu = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
e.preventDefault();
const target = e.currentTarget as HTMLDivElement;
const worksheetId = target.dataset.id as string;
@@ -97,7 +91,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
};
// Click the button to display the menu, if it is not in the current sheet, only switch the sheet after clicking
- onContextMenuClick = (e: MouseEvent) => {
+ onContextMenuClick = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
e.preventDefault();
const target = e.currentTarget as HTMLDivElement;
@@ -116,8 +110,9 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
};
// 显示下拉
- showSelect = (e: MouseEvent, ref: RefObject<Menu>) => {
- e.stopImmediatePropagation();
+ showSelect = (e: React.MouseEvent<HTMLDivElement, MouseEvent>, ref: RefObject<Menu>) => {
+ e.stopPropagation();
+ e.preventDefault();
const current = ref.current;
if (current) current.showMenu(true);
// 点击外部隐藏子组件
@@ -132,19 +127,20 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
};
// 点击不同sheet页显示ullist
- showUlList = (e: MouseEvent, cb?: () => void) => {
+ showUlList = (e: React.MouseEvent<HTMLDivElement, MouseEvent>, cb?: () => void) => {
new Promise<void>((resolve) => {
const target = e.currentTarget as HTMLDivElement;
const id = target.dataset.id as string;
this.showSelect(e, this.ulRef);
resolve();
}).then(() => {
- const currentTarget = (e.currentTarget as HTMLElement).closest(`.${styles.slideTabItem}`);
+ const currentTarget = (e.target as HTMLElement).closest(`.${styles.slideTabItem}`);
if (currentTarget) {
const currentRect = currentTarget.getBoundingClientRect();
const left = `${currentRect.left}px`;
const bottom = `${currentRect.height}px`;
- const ul = this.ulRef.current.base;
+ const ul = this.ulRef.current?.getMenuRef().current;
+ if (!ul) return;
ul.style.left = left;
ul.style.bottom = bottom;
ul.style.top = 'auto';
@@ -188,7 +184,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
slideTabBarItemActiveClassName: 'univer-slide-tab-active',
slideTabBarItemClassName: 'univer-slide-tab-item',
slideTabBarItemAutoSort: true,
- slideTabRoot: this.slideTabRoot.current,
+ slideTabRoot: this.slideTabRoot.current as HTMLElement,
activeClassNameAutoController: true,
onChangeName: (sheetId: string, name: string) => {
this.props.changeSheetName?.(sheetId, name);
@@ -208,7 +204,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
// Convenient for controller to control sheetBarMenu
showMenuList(show: boolean) {
- this.ref.current.showMenu(show);
+ this.ref.current?.showMenu(show);
}
setSlideTabActive(sheetId: string, cb?: () => void) {
@@ -235,7 +231,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
return currentSheet?.sheetId;
}
- render() {
+ override render() {
const { sheetList, menuList, sheetUl } = this.state;
const { addSheet, selectSheet } = this.props;
@@ -249,9 +245,9 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
<Button className={styles.sheetBarOptionsButton} onClick={addSheet} type="text">
<Icon.Math.AddIcon style={{ fontSize: '20px' }} />
</Button>
- <Button className={styles.sheetBarOptionsButton} onClick={(e: MouseEvent) => this.ref.current.showMenu(true)} type="text">
+ <Button className={styles.sheetBarOptionsButton} onClick={(e: MouseEvent) => this.ref.current?.showMenu(true)} type="text">
<Icon.MenuIcon style={{ fontSize: '20px' }} />
- <SheetBarMenu onClick={selectSheet} menu={menuList as ISheetBarMenuItem[]} ref={this.ref}></SheetBarMenu>
+ <SheetBarMenu menu={menuList as ISheetBarMenuItem[]} ref={this.ref}></SheetBarMenu>
</Button>
</div>
@@ -272,7 +268,13 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
<CustomLabel label={item.label} />
</span>
</div>
- <div className={`${styles.slideTabIcon}`} data-slide-skip="true" style={{ lineHeight: 1 }} data-id={item.sheetId} onClick={this.onContextMenuClick}>
+ <div
+ className={`${styles.slideTabIcon}`}
+ data-slide-skip="true"
+ style={{ lineHeight: 1 }}
+ data-id={item.sheetId}
+ onClick={(e) => this.onContextMenuClick(e)}
+ >
<Icon.NextIcon />
</div>
</div>
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
index 3ddba8e17b..1efdfbc08e 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
@@ -14,7 +14,7 @@ export interface ISheetBarMenuItem {
export interface ISheetBarMenuProps {
menu: ISheetBarMenuItem[];
- style?: JSX.CSSProperties;
+ style?: React.CSSProperties;
onClick?: (e?: MouseEvent) => void;
}
@@ -37,13 +37,13 @@ export class SheetBarMenu extends Component<ISheetBarMenuProps, IState> {
};
}
- handleClick(e: MouseEvent, item: ISheetBarMenuItem) {
+ handleClick(e: React.MouseEvent<HTMLLIElement, MouseEvent>, item: ISheetBarMenuItem) {
e.stopPropagation();
const { onClick } = this.props;
if (item.onClick) {
item.onClick(e);
}
- onClick?.(e);
+ // onClick?.(e);
this.showMenu(false);
window.removeEventListener('click', this.hideMenu, true);
this.selectItem(item.sheetId as string);
@@ -143,7 +143,7 @@ export class SheetBarMenu extends Component<ISheetBarMenuProps, IState> {
}));
}
- render() {
+ override render() {
const { style } = this.props;
const { show, menu } = this.state;
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/Animate.ts b/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/Animate.ts
index a5d0e4e8ba..bcde587bb2 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/Animate.ts
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/Animate.ts
@@ -79,10 +79,10 @@ export class Animate {
let successNumber = 0;
return new Promise<void>((resolve) => {
for (let i = 0; i < animates.length; i++) {
- let animate = animates[i];
- let config = animate._config;
- let success = config.success;
- let loop = config.loop;
+ const animate = animates[i];
+ const config = animate._config;
+ const success = config.success;
+ const loop = config.loop;
if (loop) {
continue;
}
@@ -124,8 +124,8 @@ export class Animate {
let times = Date.now() - this._start;
times = times >= this._config.duration ? this._config.duration : times;
- let val = Tween[this._config.type](times, this._config.begin, this._config.end - this._config.begin, this._config.duration, 0.7);
- let fix = val.toFixed(2);
+ const val = Tween[this._config.type](times, this._config.begin, this._config.end - this._config.begin, this._config.duration, 0.7);
+ const fix = val.toFixed(2);
this._config.receive(fix);
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideTabItem.ts b/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideTabItem.ts
index 1112c1f9a8..44bde2db42 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideTabItem.ts
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideTabItem.ts
@@ -79,7 +79,7 @@ export class SlideTabItem {
this._slideTabBar.updateItems();
if (this._slideTabBar.getConfig().onChangeName && this._slideTabItem.dataset.id) {
- const name = (event.target as HTMLElement).innerText;
+ const name = (event && (event.target as HTMLElement).innerText) || '';
this._slideTabBar.getConfig().onChangeName(this._slideTabItem.dataset.id, name);
}
diff --git a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
index 6433435649..256f7a1ae2 100644
--- a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
@@ -1,16 +1,17 @@
-import { BaseComponentProps, Container, Content, Footer, Header, Layout, Sider, Slot, defaultSkin } from '@univerjs/base-ui';
-import { Component, createRef } from 'react';
-import { Tools } from '@univerjs/core';
+import { BaseComponentProps, Container, Content, defaultSkin, Footer, Header, Layout, Sider, Slot } from '@univerjs/base-ui';
+import { IKeyValue, Tools } from '@univerjs/core';
import cssVars from 'css-vars-ponyfill';
-import style from './index.module.less';
-import { InfoBar } from '../InfoBar';
-import { RightMenu } from '../RightMenu';
+import { Component, createRef } from 'react';
+
+import { ISheetUIPluginConfig } from '../../Basics';
import { CountBar } from '../CountBar';
-import { SheetBar } from '../SheetBar';
import { FormulaBar } from '../FormulaBar';
+import { InfoBar } from '../InfoBar';
import { RichText } from '../RichText';
-import { ISheetUIPluginConfig } from '../../Basics';
+import { RightMenu } from '../RightMenu';
+import { SheetBar } from '../SheetBar';
import { Toolbar } from '../Toolbar';
+import style from './index.module.less';
export interface BaseSheetContainerProps extends BaseComponentProps {
config: ISheetUIPluginConfig;
@@ -47,7 +48,7 @@ export class SheetContainer extends Component<BaseSheetContainerProps> {
* split mouse down
* @param e
*/
- handleSplitBarMouseDown = (e: MouseEvent) => {
+ handleSplitBarMouseDown = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
e = e || window.event; // Compatible with IE browser
// Store the current mouse position
this.leftContentLeft = this.splitLeftRef.current?.getBoundingClientRect().left!;
@@ -102,29 +103,22 @@ export class SheetContainer extends Component<BaseSheetContainerProps> {
changeSkin(container: HTMLElement | string, skin: string) {
// Collect all skins
const root = document.documentElement;
-
const id = typeof container === 'string' ? container : container.id;
-
// get all skins
- const skins: Record<string, CSSModuleClasses> = {
+ const skins: Record<string, IKeyValue> = {
default: defaultSkin,
};
-
// current skin set by user
let currentSkin = skins[skin];
-
// transform "primaryColor" to "--primary-color"
currentSkin = Object.fromEntries(Object.keys(currentSkin).map((item) => [`--${item.replace(/([A-Z0-9])/g, '-$1').toLowerCase()}`, currentSkin[item]]));
// ie11 does not support css variables, use css-vars-ponyfill to handle
if (Tools.isIEBrowser()) {
cssVars({
- // Options...
-
// The container is invalid as rootElement, so the default setting is root.
// Disadvantages: In ie11, only one set of skins can be used for multiple workbooks, and it is the skin set by the last workbook
rootElement: root, // default
-
variables: currentSkin,
});
} else {
@@ -133,13 +127,10 @@ export class SheetContainer extends Component<BaseSheetContainerProps> {
/**
* covert object to style, remove " and replace , to ;
- *
* Example:
- *
* before: {--primary-color:"#0188fb",--primary-color-hover:"#5391ff"}
* after: {--primary-color:#0188fb;--primary-color-hover:#5391ff;}
*/
-
sheet.insertRule(
`#${id} ${JSON.stringify(currentSkin)
.replace(/"/g, '')
@@ -195,7 +186,7 @@ export class SheetContainer extends Component<BaseSheetContainerProps> {
*
* @returns {void}
*/
- render() {
+ override render() {
const { methods } = this.props;
const { layout } = this.props.config;
const config = layout?.sheetContainerConfig!;
@@ -227,7 +218,7 @@ export class SheetContainer extends Component<BaseSheetContainerProps> {
{/* <Slot {...methods.slot}></Slot> */}
{!!config.contentSplit && (
<Container ref={this.splitLeftRef} className={style.contentInnerLeftContainer}>
- <div className={style.hoverCursor} onMouseDown={this.handleSplitBarMouseDown}></div>
+ <div className={style.hoverCursor} onMouseDown={(e) => this.handleSplitBarMouseDown(e)}></div>
</Container>
)}
<Container onContextMenu={(e) => e.preventDefault()} ref={this.contentRef} className={style.contentInnerRightContainer}>
diff --git a/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx b/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx
index 4c33ee51fc..77f5891bcd 100644
--- a/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx
+++ b/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx
@@ -1,5 +1,6 @@
-import { BaseComponentProps } from '@univerjs/base-ui';
+import type { BaseComponentProps } from '@univerjs/base-ui';
import { Component } from 'react';
+
import { SlotGroupProps } from '../../Controller/SlotController';
interface IState {
@@ -44,13 +45,13 @@ export class Slot extends Component<IProps, IState> {
getRender(slotGroup: SlotGroupProps) {
const group: JSX.Element[] = [];
slotGroup.forEach((v, k) => {
- const Slot = slotGroup.get(k)?.component;
+ const Slot = slotGroup.get(k)?.component as React.ComponentType<any>;
const props = slotGroup.get(k)?.props;
if (!Slot) return;
group.push(
<Slot
key={k}
- ref={(ele: Slot) => {
+ ref={(ele: React.ComponentType<any>) => {
this.refMap.set(k, ele);
}}
{...props}
@@ -60,7 +61,7 @@ export class Slot extends Component<IProps, IState> {
return group;
}
- render() {
+ override render() {
const { slotGroup } = this.state;
return <div>{this.getRender(slotGroup)}</div>;
}
diff --git a/packages/ui-plugin-sheets/src/View/Toolbar/DataBar.tsx b/packages/ui-plugin-sheets/src/View/Toolbar/DataBar.tsx
index 12a716f03b..4f000c29ce 100644
--- a/packages/ui-plugin-sheets/src/View/Toolbar/DataBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/Toolbar/DataBar.tsx
@@ -8,12 +8,12 @@ export const DataBar = (props: BarProps) => {
const { list, img, onClick } = props;
const background = `url(${img}) no-repeat`;
- let handleClick = (item: {}, index: number) => {
+ const handleClick = (item: {}, index: number) => {
onClick?.call(this, item, index);
};
return (
- <div style="display: flex;">
+ <div style={{ display: 'flex' }}>
{list.map((item, index) => (
<div key={index} onClick={() => handleClick(item, index)} style={{ width: '28px', height: '26px', background, backgroundPosition: `${item.x} ${item.y}` }}></div>
))}
diff --git a/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx b/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
index 490e53f954..2a34cf47a4 100644
--- a/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
+++ b/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
@@ -1,22 +1,23 @@
-import { AppContext, BaseComponentProps, Button, Container, CustomLabel, debounce, IDisplayMenuItem, IMenuItem, Select, Tooltip } from '@univerjs/base-ui';
+import { AppContext, BaseComponentProps, Container, IDisplayMenuItem, IMenuItem } from '@univerjs/base-ui';
import { Component, createRef } from 'react';
+
import { IToolbarItemProps, SheetContainerUIController } from '../../Controller';
import styles from './index.module.less';
import { ToolbarItem } from './ToolbarItem';
interface IProps extends BaseComponentProps {
- style?: JSX.CSSProperties;
+ style?: React.CSSProperties;
toolList: IToolbarItemProps[];
}
interface IState {
- menuItems: IDisplayMenuItem<IMenuItem>[];
+ menuItems: Array<IDisplayMenuItem<IMenuItem>>;
}
export class Toolbar extends Component<IProps, IState> {
static override contextType = AppContext;
- toolbarRef = createRef();
+ toolbarRef = createRef<HTMLDivElement>();
moreBtnRef = createRef();
@@ -38,17 +39,16 @@ export class Toolbar extends Component<IProps, IState> {
}
setToolbarNeo = (menuItems: Array<IDisplayMenuItem<IMenuItem>>) => {
- this.setState(
- {
- menuItems,
- },
- );
+ this.setState({
+ menuItems,
+ });
};
resetUl = () => {
const wrapper = this.context.injector.get(SheetContainerUIController).getContentRef().current!;
const height = `${(wrapper as HTMLDivElement).offsetHeight}px`;
- const ul = this.toolbarRef.current.querySelectorAll('ul');
+ const ul = this.toolbarRef.current?.querySelectorAll('ul');
+ if (!ul) return;
for (let i = 0; i < ul.length; i++) {
ul[i].style.maxHeight = height;
}
@@ -58,14 +58,13 @@ export class Toolbar extends Component<IProps, IState> {
this.props.getComponent?.(this); // pass the UI to the controller, which is not good...
}
- override componentWillUnmount() {
- }
+ override componentWillUnmount() {}
neoRenderToolbarList() {
return this.state.menuItems.map((item) => <ToolbarItem key={item.id} {...item} />);
}
- render() {
+ override render() {
return (
<Container style={{ position: 'relative' }}>
<div className={`${styles.toolbarWarp} ${styles.toolbar}`} ref={this.toolbarRef}>
diff --git a/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx b/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx
index 9642897df6..6d53a5fd62 100644
--- a/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx
+++ b/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx
@@ -1,6 +1,6 @@
import { AppContext, Button, CustomLabel, IDisplayMenuItem, IMenuButtonItem, IMenuItem, IMenuSelectorItem, IValueOption, MenuItemType, Select, Tooltip } from '@univerjs/base-ui';
import { ICommandService } from '@univerjs/core';
-import { Component, ComponentChild } from 'react';
+import { Component } from 'react';
import { Subscription } from 'rxjs';
import styles from './index.module.less';
@@ -22,8 +22,8 @@ export class ToolbarItem extends Component<IDisplayMenuItem<IMenuItem>, IToolbar
private currentValueSubscription: Subscription | undefined;
- constructor() {
- super();
+ constructor(props: IDisplayMenuItem<IMenuItem>) {
+ super(props);
this.state = {
disabled: false,
@@ -58,7 +58,7 @@ export class ToolbarItem extends Component<IDisplayMenuItem<IMenuItem>, IToolbar
this.currentValueSubscription?.unsubscribe();
}
- render(): ComponentChild {
+ override render() {
switch (this.props.type) {
case MenuItemType.SUBITEMS:
case MenuItemType.SELECTOR:
@@ -68,7 +68,7 @@ export class ToolbarItem extends Component<IDisplayMenuItem<IMenuItem>, IToolbar
}
}
- private renderSelectorType(): ComponentChild {
+ private renderSelectorType() {
const { context, state } = this;
const commandService: ICommandService = context.injector.get(ICommandService);
const { disabled, value } = state;
@@ -81,7 +81,7 @@ export class ToolbarItem extends Component<IDisplayMenuItem<IMenuItem>, IToolbar
<Select
id={id}
title={title}
- children={selections!}
+ children={selections! as IValueOption[]}
options={selections as IValueOption[]}
display={display}
icon={icon}
@@ -95,7 +95,7 @@ export class ToolbarItem extends Component<IDisplayMenuItem<IMenuItem>, IToolbar
);
}
- private renderButtonType(): ComponentChild {
+ private renderButtonType() {
const { props, context, state } = this;
const { disabled, activated } = state;
const { icon, title } = props;