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.

refactor: remove redundant preact abstract class (#81)

白熱43f3c53334f7
diff --git a/.husky/commit-msg b/.husky/commit-msg
old mode 100644
new mode 100755
diff --git a/packages/base-ui/src/BaseComponent.ts b/packages/base-ui/src/BaseComponent.ts
index 065b71e63f..27d6b5c8bc 100644
--- a/packages/base-ui/src/BaseComponent.ts
+++ b/packages/base-ui/src/BaseComponent.ts
@@ -1,7 +1,8 @@
+import { ComponentClass } from 'preact';
+import { ForwardFn } from 'preact/compat';
import { BasePlugin } from '@univerjs/core';
import { Context } from '@univerjs/core/src/Basics/Context';
import { Injector } from '@wendellhu/redi';
-import { ComponentClass, ForwardFn } from './Framework';
import { Description } from './Interfaces';
// TODO Button const enum; BaseComponentSheet => BaseComponentXXX
diff --git a/packages/base-ui/src/Components/Button/Button.tsx b/packages/base-ui/src/Components/Button/Button.tsx
index c19ce0108a..c654189131 100644
--- a/packages/base-ui/src/Components/Button/Button.tsx
+++ b/packages/base-ui/src/Components/Button/Button.tsx
@@ -1,5 +1,5 @@
+import { Component } from 'preact';
import { BaseButtonProps } from '../../BaseComponent';
-import { Component } from '../../Framework';
import { joinClassNames } from '../../Utils';
import { LoadingIcon } from '../Icon';
@@ -118,4 +118,4 @@ class Button extends Component<BaseButtonProps, IState> {
}
}
-export default Button;
\ No newline at end of file
+export default Button;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDot.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDot.tsx
index 2b61674b93..5d033d44d5 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDot.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDot.tsx
@@ -1,5 +1,5 @@
+import { Component, createRef, RefObject } from 'preact';
import { JSXComponent } from '../../../BaseComponent';
-import { Component, createRef, RefObject } from '../../../Framework';
import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
@@ -14,7 +14,7 @@ class BorderDashDot extends Component<IProps, IState> {
drawLine(ref: RefObject<CanvasIcon>) {
const canvas = ref.current! as unknown as HTMLCanvasElement;
- let ctx = canvas.getContext('2d')!;
+ const ctx = canvas.getContext('2d')!;
this.ref.current.setLineDash(ctx, 'DashDot', 'h', 0, 5, 100, 5);
ctx.stroke();
ctx.closePath();
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDotDot.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDotDot.tsx
index 8424e72e61..fb0efac38d 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDotDot.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDotDot.tsx
@@ -1,5 +1,5 @@
+import { Component, createRef, RefObject } from 'preact';
import { JSXComponent } from '../../../BaseComponent';
-import { Component, createRef, RefObject } from '../../../Framework';
import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
@@ -14,7 +14,7 @@ class BorderDashDotDot extends Component<IProps, IState> {
drawLine(ref: RefObject<CanvasIcon>) {
const canvas = ref.current! as unknown as HTMLCanvasElement;
- let ctx = canvas.getContext('2d')!;
+ const ctx = canvas.getContext('2d')!;
this.ref.current.setLineDash(ctx, 'DashDotDot', 'h', 0, 5, 100, 5);
ctx.stroke();
ctx.closePath();
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDotted.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDotted.tsx
index d2c79e5911..ce311d8892 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDotted.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDotted.tsx
@@ -1,5 +1,5 @@
+import { Component, createRef, RefObject } from 'preact';
import { JSXComponent } from '../../../BaseComponent';
-import { Component, createRef, RefObject } from '../../../Framework';
import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
@@ -14,7 +14,7 @@ class BorderDotted extends Component<IProps, IState> {
drawLine(ref: RefObject<CanvasIcon>) {
const canvas = ref.current! as unknown as HTMLCanvasElement;
- let ctx = canvas.getContext('2d')!;
+ const ctx = canvas.getContext('2d')!;
this.ref.current.setLineDash(ctx, 'Dotted', 'h', 0, 5, 100, 5);
ctx.stroke();
ctx.closePath();
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderHair.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderHair.tsx
index 0cdb0cc217..5f0d7aea08 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderHair.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderHair.tsx
@@ -1,5 +1,5 @@
+import { Component, createRef, RefObject } from 'preact';
import { JSXComponent } from '../../../BaseComponent';
-import { Component, createRef, RefObject } from '../../../Framework';
import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
@@ -14,7 +14,7 @@ class BorderHair extends Component<IProps, IState> {
drawLine(ref: RefObject<CanvasIcon>) {
const canvas = ref.current! as unknown as HTMLCanvasElement;
- let ctx = canvas.getContext('2d')!;
+ const ctx = canvas.getContext('2d')!;
this.ref.current.setLineDash(ctx, 'Hair', 'h', 0, 5, 100, 5);
ctx.stroke();
ctx.closePath();
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMedium.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMedium.tsx
index be42b56bff..8bff801354 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMedium.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMedium.tsx
@@ -1,5 +1,5 @@
+import { Component, createRef, RefObject } from 'preact';
import { JSXComponent } from '../../../BaseComponent';
-import { Component, createRef, RefObject } from '../../../Framework';
import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
@@ -14,7 +14,7 @@ class BorderMedium extends Component<IProps, IState> {
drawLine(ref: RefObject<CanvasIcon>) {
const canvas = ref.current! as unknown as HTMLCanvasElement;
- let ctx = canvas.getContext('2d')!;
+ const ctx = canvas.getContext('2d')!;
this.ref.current.setLineDash(ctx, 'Medium', 'h', 0, 5, 100, 5);
ctx.stroke();
ctx.closePath();
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDot.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDot.tsx
index 062494a01d..4ba45285e5 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDot.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDot.tsx
@@ -1,5 +1,5 @@
+import { Component, createRef, RefObject } from 'preact';
import { JSXComponent } from '../../../BaseComponent';
-import { Component, createRef, RefObject } from '../../../Framework';
import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
@@ -14,7 +14,7 @@ class BorderMediumDashDot extends Component<IProps, IState> {
drawLine(ref: RefObject<CanvasIcon>) {
const canvas = ref.current! as unknown as HTMLCanvasElement;
- let ctx = canvas.getContext('2d')!;
+ const ctx = canvas.getContext('2d')!;
this.ref.current.setLineDash(ctx, 'MediumDashDot', 'h', 0, 5, 100, 5);
ctx.stroke();
ctx.closePath();
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDotDot.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDotDot.tsx
index ed52206ec4..0d70e2ad14 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDotDot.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDotDot.tsx
@@ -1,5 +1,5 @@
+import { Component, createRef, RefObject } from 'preact';
import { JSXComponent } from '../../../BaseComponent';
-import { Component, createRef, RefObject } from '../../../Framework';
import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
@@ -14,7 +14,7 @@ class BorderMediumDashDotDot extends Component<IProps, IState> {
drawLine(ref: RefObject<CanvasIcon>) {
const canvas = ref.current! as unknown as HTMLCanvasElement;
- let ctx = canvas.getContext('2d')!;
+ const ctx = canvas.getContext('2d')!;
this.ref.current.setLineDash(ctx, 'MediumDashDotDot', 'h', 0, 5, 100, 5);
ctx.stroke();
ctx.closePath();
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashed.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashed.tsx
index dcb35e087d..3270fdeaaf 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashed.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashed.tsx
@@ -1,5 +1,5 @@
+import { Component, createRef, RefObject } from 'preact';
import { JSXComponent } from '../../../BaseComponent';
-import { Component, createRef, RefObject } from '../../../Framework';
import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
@@ -14,7 +14,7 @@ class BorderMediumDashed extends Component<IProps, IState> {
drawLine(ref: RefObject<CanvasIcon>) {
const canvas = ref.current! as unknown as HTMLCanvasElement;
- let ctx = canvas.getContext('2d')!;
+ const ctx = canvas.getContext('2d')!;
this.ref.current.setLineDash(ctx, 'MediumDashed', 'h', 0, 5, 100, 5);
ctx.stroke();
ctx.closePath();
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThick.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThick.tsx
index 4b92c80122..1a703a89dd 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThick.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThick.tsx
@@ -1,5 +1,5 @@
+import { Component, createRef, RefObject } from 'preact';
import { JSXComponent } from '../../../BaseComponent';
-import { Component, createRef, RefObject } from '../../../Framework';
import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
@@ -14,7 +14,7 @@ class BorderThick extends Component<IProps, IState> {
drawLine(ref: RefObject<CanvasIcon>) {
const canvas = ref.current! as unknown as HTMLCanvasElement;
- let ctx = canvas.getContext('2d')!;
+ const ctx = canvas.getContext('2d')!;
this.ref.current.setLineDash(ctx, 'Thick', 'h', 0, 5, 100, 5);
ctx.stroke();
ctx.closePath();
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThin.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThin.tsx
index 6b13047eae..b828a84d4d 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThin.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThin.tsx
@@ -1,5 +1,5 @@
+import { Component, createRef, RefObject } from 'preact';
import { JSXComponent } from '../../../BaseComponent';
-import { Component, createRef, RefObject } from '../../../Framework';
import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
@@ -14,7 +14,7 @@ class BorderThin extends Component<IProps, IState> {
drawLine(ref: RefObject<CanvasIcon>) {
const canvas = ref.current! as unknown as HTMLCanvasElement;
- let ctx = canvas.getContext('2d')!;
+ const ctx = canvas.getContext('2d')!;
this.ref.current.setLineDash(ctx, 'Thin', 'h', 0, 5, 100, 5);
ctx.stroke();
ctx.closePath();
diff --git a/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.tsx b/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.tsx
index d435c988d2..8f4658e45c 100644
--- a/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.tsx
@@ -1,4 +1,4 @@
-import { Component, createRef, RefObject } from '../../Framework';
+import { Component, createRef, RefObject } from 'preact';
import Style from './index.module.less';
type IProps = {
@@ -11,7 +11,7 @@ type IState = {};
class CanvasIcon extends Component<IProps, IState> {
canvasRef = createRef();
- componentDidMount() {
+ override componentDidMount() {
this.drawLine();
}
@@ -31,7 +31,7 @@ class CanvasIcon extends Component<IProps, IState> {
* @param line_ed End Y
*/
setLineDash(ctx: CanvasRenderingContext2D, type: string, hv: string, m_st: number, m_ed: number, line_st: number, line_ed: number) {
- let borderType: { [index: string]: string } = {
+ const borderType: { [index: string]: string } = {
'0': 'none',
'1': 'Thin',
'2': 'Hair',
diff --git a/packages/base-ui/src/Components/CellRange/CellRange.tsx b/packages/base-ui/src/Components/CellRange/CellRange.tsx
index c9ae28d4ec..ecd55311d8 100644
--- a/packages/base-ui/src/Components/CellRange/CellRange.tsx
+++ b/packages/base-ui/src/Components/CellRange/CellRange.tsx
@@ -1,6 +1,6 @@
+import { Component, createRef } from 'preact';
import { Icon, Modal } from '..';
import { BaseComponentProps } from '../../BaseComponent';
-import { Component, createRef } from '../../Framework';
import { ModalButtonGroup } from '../../Interfaces';
import { Input } from '../Input';
import styles from './index.module.less';
@@ -62,7 +62,7 @@ export class CellRange extends Component<BaseCellRangeModalProps, IState> {
onChange?.(e);
};
- componentWillReceiveProps(props: BaseCellRangeModalProps) {
+ override componentWillReceiveProps(props: BaseCellRangeModalProps) {
if (props.value !== this.state.value) {
this.setState({
value: props.value,
diff --git a/packages/base-ui/src/Components/Checkbox/Checkbox.tsx b/packages/base-ui/src/Components/Checkbox/Checkbox.tsx
index b0c4cdf6fd..37ad72184a 100644
--- a/packages/base-ui/src/Components/Checkbox/Checkbox.tsx
+++ b/packages/base-ui/src/Components/Checkbox/Checkbox.tsx
@@ -1,5 +1,5 @@
+import { Component } from 'preact';
import { JSXComponent } from '../../BaseComponent';
-import { Component } from '../../Framework';
import { BaseCheckboxProps, CheckboxComponent } from '../../Interfaces';
import { joinClassNames } from '../../Utils';
import styles from './index.module.less';
@@ -19,14 +19,14 @@ type CheckboxState = {
};
export class Checkbox extends Component<BaseCheckboxProps, CheckboxState> {
- state = {
+ override state = {
classes: this.props.className ? `${this.props.className} ${styles.checkBox}` : styles.checkBox,
check: true,
};
handleStyle = (checked?: boolean, disabled?: boolean) => {
// Decide whether to check or disable based on the checkbox style
- let classGroup = joinClassNames(styles.checkBox, {
+ const classGroup = joinClassNames(styles.checkBox, {
[`${styles.checkBox}-checked`]: checked,
[`${styles.checkBox}-disabled`]: disabled,
}) as string;
@@ -34,11 +34,11 @@ export class Checkbox extends Component<BaseCheckboxProps, CheckboxState> {
this.setState((prevState) => ({ classes: classGroup, check: checked }));
};
- componentWillMount() {
+ override componentWillMount() {
this.handleStyle(this.props.checked, this.props.disabled);
}
- componentWillReceiveProps(nextProps: BaseCheckboxProps) {
+ override componentWillReceiveProps(nextProps: BaseCheckboxProps) {
this.handleStyle(nextProps.checked, nextProps.disabled);
}
diff --git a/packages/base-ui/src/Components/Checkbox/Group.tsx b/packages/base-ui/src/Components/Checkbox/Group.tsx
index 4e50d4b50f..a9b434921d 100644
--- a/packages/base-ui/src/Components/Checkbox/Group.tsx
+++ b/packages/base-ui/src/Components/Checkbox/Group.tsx
@@ -1,5 +1,5 @@
+import { useRef } from 'preact/hooks';
import { JSXComponent } from '../../BaseComponent';
-import { useRef } from '../../Framework';
import { BaseCheckboxGroupProps, CheckboxGroupComponent } from '../../Interfaces';
import { Checkbox } from './Checkbox';
import styles from './index.module.less';
@@ -20,8 +20,8 @@ import styles from './index.module.less';
// };
export const CheckboxGroup = (props: BaseCheckboxGroupProps) => {
- let { options, onChange, disabled, name } = props;
- let ref = useRef<HTMLDivElement>(null);
+ const { options, onChange, disabled, name } = props;
+ const ref = useRef<HTMLDivElement>(null);
if (disabled) {
options.forEach((item) => {
@@ -36,10 +36,10 @@ export const CheckboxGroup = (props: BaseCheckboxGroupProps) => {
const handelChange = () => {
if (!onChange) return;
- let input = ref.current?.querySelectorAll('label input');
- let value: string[] = [];
+ const input = ref.current?.querySelectorAll('label input');
+ const value: string[] = [];
input?.forEach((item) => {
- let element = item as HTMLInputElement;
+ const element = item as HTMLInputElement;
if (element.checked) {
value.push(element.value);
}
diff --git a/packages/base-ui/src/Components/Collapse/Collapse.tsx b/packages/base-ui/src/Components/Collapse/Collapse.tsx
index b46e8253ba..f0d7d74b8e 100644
--- a/packages/base-ui/src/Components/Collapse/Collapse.tsx
+++ b/packages/base-ui/src/Components/Collapse/Collapse.tsx
@@ -1,5 +1,5 @@
+import { useState } from 'preact/hooks';
import { JSXComponent } from '../../BaseComponent';
-import { useState } from '../../Framework';
import { BasePanelProps, BaseCollapseProps, CollapseComponent, PanelComponent } from '../../Interfaces';
import { joinClassNames } from '../../Utils';
import { Icon } from '../index';
@@ -16,10 +16,10 @@ import Style from './index.module.less';
const Panel = (props: BasePanelProps) => {
const { header, children } = props;
- let [panelBodyClassName, setPanelBodyClassName] = useState(joinClassNames(Style.panelBody));
+ const [panelBodyClassName, setPanelBodyClassName] = useState(joinClassNames(Style.panelBody));
const handelClick = () => {
- let classname: string | undefined = panelBodyClassName;
+ const classname: string | undefined = panelBodyClassName;
if ((classname as string).includes('active')) {
setPanelBodyClassName(joinClassNames(Style.panelBody));
} else {
diff --git a/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx b/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx
index c0e2c67547..1571ef6ceb 100644
--- a/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx
+++ b/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx
@@ -1,219 +1,228 @@
-import { BaseColorPickerProps, ColorPickerComponent, Component, createRef, JSXComponent } from '../..';
-import { Button, Tooltip } from '../index';
-import { ColorPickerPanel } from './ColorPickerPanel';
-import styles from './index.module.less';
-
-let allColor = [
- ['#000', '#444', '#666', '#999', '#ccc', '#eee', '#f3f3f3', '#fff'],
- ['#f00', '#f90', '#ff0', '#0f0', '#0ff', '#00f', '#90f', '#f0f'],
- ['#f4cccc', '#fce5cd', '#fff2cc', '#d9ead3', '#d0e0e3', '#cfe2f3', '#d9d2e9', '#ead1dc'],
- ['#ea9999', '#f9cb9c', '#ffe599', '#b6d7a8', '#a2c4c9', '#9fc5e8', '#b4a7d6', '#d5a6bd'],
- ['#e06666', '#f6b26b', '#ffd966', '#93c47d', '#76a5af', '#6fa8dc', '#8e7cc3', '#c27ba0'],
- ['#c00', '#e69138', '#f1c232', '#6aa84f', '#45818e', '#3d85c6', '#674ea7', '#a64d79'],
- ['#900', '#b45f06', '#bf9000', '#38761d', '#134f5c', '#0b5394', '#351c75', '#741b47'],
- ['#600', '#783f04', '#7f6000', '#274e13', '#0c343d', '#073763', '#20124d', '#4c1130'],
-];
-
-interface IState {
- presetColors: string[][];
- defaultColor: string;
- afterColor: string;
- rgb: boolean;
- setting: boolean;
- styles?: JSX.CSSProperties;
- currentLocale: string;
- root: Element | null;
-}
-
-class ColorPicker extends Component<BaseColorPickerProps, IState> {
- ulRef = createRef();
-
- initialize(props: BaseColorPickerProps) {
- this.state = {
- presetColors: allColor,
- defaultColor: props.color || '#000',
- afterColor: props.color || '#000',
- rgb: true,
- setting: false,
- styles: {},
- currentLocale: '',
- root: null,
- };
- }
-
- /**
- * Gets the selected color
- * @param {string} presetColor new color
- * @param {boolean} val true:Close color selector
- */
- onChange = (presetColor: string) => {
- this.props.onChange && this.props.onChange(presetColor);
- this.setState({
- afterColor: presetColor,
- });
- };
-
- /**
- * confirm color
- *
- * @eventProperty
- */
- onClick = (color: string, e: MouseEvent) => {
- this.props.onClick && this.props.onClick(color, e);
- // this.hideSelect();
- };
-
- /**
- * cancel and close
- *
- * @eventProperty
- */
- onCancel = () => {
- this.props.onCancel && this.props.onCancel();
- // this.hideSelect();
- };
-
- hideSelect = (e?: MouseEvent) => {
- if (e && this.ulRef.current.contains(e.target)) return;
-
- this.setState((prevState) => ({ styles: { display: 'none' } }));
-
- document.removeEventListener('click', this.hideSelect, true);
- };
-
- showSelect = (root?: Element) => {
- this.setState((prevState) => ({ styles: { display: 'block' } }));
- // 点击外部隐藏子组件
- document.addEventListener('click', this.hideSelect, true);
- };
-
- /**
- *
- * @param root Locate according to root
- * @param ele Element to locate
- * @returns
- */
- getOffset = (root: Element, ele: Element) => {
- const rootRect = root.getBoundingClientRect();
- const eleRect = this.ulRef.current.getBoundingClientRect();
- const w = document.documentElement.clientWidth || document.body.clientWidth;
- const h = document.documentElement.clientHeight || document.body.clientHeight;
-
- let left: number = 0;
- let top: number = 0;
-
- top = rootRect.top + eleRect.height > h ? rootRect.top - eleRect.height : rootRect.top + rootRect.height;
- left = rootRect.left + eleRect.width > w ? w - eleRect.width : rootRect.left;
-
- return { left, top };
- };
-
- /**
- * Custom switch
- * @param e
- */
- onSwitch = (e: Event) => {
- e.stopImmediatePropagation();
-
- new Promise((resolve, reject) => {
- this.setState({ setting: !this.state.setting });
- resolve('end');
- }).then(() => {
- if (this.state.root) {
- const { top, left } = this.getOffset(this.state.root!, this.ulRef.current);
- this.ulRef.current.style.left = `${left}px`;
- this.ulRef.current.style.top = `${top}px`;
- }
- });
- };
-
- componentDidMount() {
- this.props.getComponent?.(this);
- }
-
- render() {
- const obj = Object.assign(this.state.styles || {}, this.props.style);
-
- return (
- <div className={`${styles.colorPickerOuter} ${this.props.className}`} ref={this.ulRef} style={{ ...obj }}>
- <div
- className={styles.colorPicker}
- onClick={(e: MouseEvent) => {
- // e.stopImmediatePropagation();
- }}
- >
- <div className={styles.picker}>
- <div className={styles.pickerSwatches}>
- {this.state.presetColors.map((presetColor) => (
- <div className={styles.pickerSwatchesItem}>
- {presetColor.map((item) => (
- <span className={styles.pickerSwatch} style={{ background: item }}>
- <Tooltip title={item} placement="top">
- <button
- key={item}
- className={styles.pickerSwatchBtn}
- style={{ background: item }}
- onClick={(e: MouseEvent) => {
- // this.hideSelect();
- this.props.onClick && this.props.onClick(item, e);
- }}
- />
- </Tooltip>
- </span>
- ))}
- </div>
- ))}
- </div>
- <div onClick={(e) => e.stopImmediatePropagation()}>
- <Button onClick={this.onSwitch}>{this.state.setting ? this.getLocale('colorPicker.collapse') : this.getLocale('colorPicker.customColor')}</Button>
- </div>
- </div>
-
- {this.state.setting ? (
- <div className={styles.colorfulWarp}>
- <ColorPickerPanel color={this.state.defaultColor} rgb={this.state.rgb} onChange={this.onChange.bind(this)} />
-
- <div>
- <Button
- type="primary"
- onClick={(e: MouseEvent) => {
- this.onClick?.(this.state.afterColor, e);
- // this.hideSelect();
- }}
- >
- {this.getLocale('colorPicker.confirmColor')}
- </Button>
- <Button
- danger
- onClick={(e: MouseEvent) => {
- this.onCancel();
- }}
- >
- {this.getLocale('colorPicker.cancelColor')}
- </Button>
- <Button
- onClick={(e: MouseEvent) => {
- e.stopPropagation();
- this.setState({
- rgb: !this.state.rgb,
- });
- }}
- >
- {this.getLocale('colorPicker.change')}
- </Button>
- </div>
- </div>
- ) : null}
- </div>
- </div>
- );
- }
-}
-
-export class UniverColorPicker implements ColorPickerComponent {
- render(): JSXComponent<BaseColorPickerProps> {
- return ColorPicker;
- }
-}
-
-export { ColorPicker };
+import { Component, createRef } from 'preact';
+import { BaseColorPickerProps, ColorPickerComponent, JSXComponent } from '../..';
+import { Button, Tooltip } from '../index';
+import { ColorPickerPanel } from './ColorPickerPanel';
+import { CustomLabel } from '../CustomLabel';
+import styles from './index.module.less';
+
+const allColor = [
+ ['#000', '#444', '#666', '#999', '#ccc', '#eee', '#f3f3f3', '#fff'],
+ ['#f00', '#f90', '#ff0', '#0f0', '#0ff', '#00f', '#90f', '#f0f'],
+ ['#f4cccc', '#fce5cd', '#fff2cc', '#d9ead3', '#d0e0e3', '#cfe2f3', '#d9d2e9', '#ead1dc'],
+ ['#ea9999', '#f9cb9c', '#ffe599', '#b6d7a8', '#a2c4c9', '#9fc5e8', '#b4a7d6', '#d5a6bd'],
+ ['#e06666', '#f6b26b', '#ffd966', '#93c47d', '#76a5af', '#6fa8dc', '#8e7cc3', '#c27ba0'],
+ ['#c00', '#e69138', '#f1c232', '#6aa84f', '#45818e', '#3d85c6', '#674ea7', '#a64d79'],
+ ['#900', '#b45f06', '#bf9000', '#38761d', '#134f5c', '#0b5394', '#351c75', '#741b47'],
+ ['#600', '#783f04', '#7f6000', '#274e13', '#0c343d', '#073763', '#20124d', '#4c1130'],
+];
+
+interface IState {
+ presetColors: string[][];
+ defaultColor: string;
+ afterColor: string;
+ rgb: boolean;
+ setting: boolean;
+ styles?: JSX.CSSProperties;
+ currentLocale: string;
+ root: Element | null;
+}
+
+class ColorPicker extends Component<BaseColorPickerProps, IState> {
+ ulRef = createRef();
+
+ constructor(props: BaseColorPickerProps) {
+ super();
+ this.initialize(props);
+ }
+
+ initialize(props: BaseColorPickerProps) {
+ this.state = {
+ presetColors: allColor,
+ defaultColor: props.color || '#000',
+ afterColor: props.color || '#000',
+ rgb: true,
+ setting: false,
+ styles: {},
+ currentLocale: '',
+ root: null,
+ };
+ }
+
+ /**
+ * Gets the selected color
+ * @param {string} presetColor new color
+ * @param {boolean} val true:Close color selector
+ */
+ onChange = (presetColor: string) => {
+ this.props.onChange && this.props.onChange(presetColor);
+ this.setState({
+ afterColor: presetColor,
+ });
+ };
+
+ /**
+ * confirm color
+ *
+ * @eventProperty
+ */
+ onClick = (color: string, e: MouseEvent) => {
+ this.props.onClick && this.props.onClick(color, e);
+ // this.hideSelect();
+ };
+
+ /**
+ * cancel and close
+ *
+ * @eventProperty
+ */
+ onCancel = () => {
+ this.props.onCancel && this.props.onCancel();
+ // this.hideSelect();
+ };
+
+ hideSelect = (e?: MouseEvent) => {
+ if (e && this.ulRef.current.contains(e.target)) return;
+
+ this.setState((prevState) => ({ styles: { display: 'none' } }));
+
+ document.removeEventListener('click', this.hideSelect, true);
+ };
+
+ showSelect = (root?: Element) => {
+ this.setState((prevState) => ({ styles: { display: 'block' } }));
+ // 点击外部隐藏子组件
+ document.addEventListener('click', this.hideSelect, true);
+ };
+
+ /**
+ *
+ * @param root Locate according to root
+ * @param ele Element to locate
+ * @returns
+ */
+ getOffset = (root: Element, ele: Element) => {
+ const rootRect = root.getBoundingClientRect();
+ const eleRect = this.ulRef.current.getBoundingClientRect();
+ const w = document.documentElement.clientWidth || document.body.clientWidth;
+ const h = document.documentElement.clientHeight || document.body.clientHeight;
+
+ let left: number = 0;
+ let top: number = 0;
+
+ top = rootRect.top + eleRect.height > h ? rootRect.top - eleRect.height : rootRect.top + rootRect.height;
+ left = rootRect.left + eleRect.width > w ? w - eleRect.width : rootRect.left;
+
+ return { left, top };
+ };
+
+ /**
+ * Custom switch
+ * @param e
+ */
+ onSwitch = (e: Event) => {
+ e.stopImmediatePropagation();
+
+ new Promise((resolve, reject) => {
+ this.setState({ setting: !this.state.setting });
+ resolve('end');
+ }).then(() => {
+ if (this.state.root) {
+ const { top, left } = this.getOffset(this.state.root!, this.ulRef.current);
+ this.ulRef.current.style.left = `${left}px`;
+ this.ulRef.current.style.top = `${top}px`;
+ }
+ });
+ };
+
+ componentDidMount() {
+ this.props.getComponent?.(this);
+ }
+
+ render() {
+ const obj = Object.assign(this.state.styles || {}, this.props.style);
+
+ return (
+ <div className={`${styles.colorPickerOuter} ${this.props.className}`} ref={this.ulRef} style={{ ...obj }}>
+ <div
+ className={styles.colorPicker}
+ onClick={(e: MouseEvent) => {
+ // e.stopImmediatePropagation();
+ }}
+ >
+ <div className={styles.picker}>
+ <div className={styles.pickerSwatches}>
+ {this.state.presetColors.map((presetColor) => (
+ <div className={styles.pickerSwatchesItem}>
+ {presetColor.map((item) => (
+ <span className={styles.pickerSwatch} style={{ background: item }}>
+ <Tooltip title={item} placement="top">
+ <button
+ key={item}
+ className={styles.pickerSwatchBtn}
+ style={{ background: item }}
+ onClick={(e: MouseEvent) => {
+ // this.hideSelect();
+ this.props.onClick && this.props.onClick(item, e);
+ }}
+ />
+ </Tooltip>
+ </span>
+ ))}
+ </div>
+ ))}
+ </div>
+ <div onClick={(e) => e.stopImmediatePropagation()}>
+ <Button onClick={this.onSwitch}>
+ {this.state.setting ? <CustomLabel label="colorPicker.collapse" /> : <CustomLabel label="colorPicker.customColor" />}
+ </Button>
+ </div>
+ </div>
+
+ {this.state.setting ? (
+ <div className={styles.colorfulWarp}>
+ <ColorPickerPanel color={this.state.defaultColor} rgb={this.state.rgb} onChange={this.onChange.bind(this)} />
+
+ <div>
+ <Button
+ type="primary"
+ onClick={(e: MouseEvent) => {
+ this.onClick?.(this.state.afterColor, e);
+ // this.hideSelect();
+ }}
+ >
+ <CustomLabel label="colorPicker.confirmColor" />
+ </Button>
+ <Button
+ danger
+ onClick={(e: MouseEvent) => {
+ this.onCancel();
+ }}
+ >
+ <CustomLabel label="colorPicker.cancelColor" />
+ </Button>
+ <Button
+ onClick={(e: MouseEvent) => {
+ e.stopPropagation();
+ this.setState({
+ rgb: !this.state.rgb,
+ });
+ }}
+ >
+ <CustomLabel label="colorPicker.change" />
+ </Button>
+ </div>
+ </div>
+ ) : null}
+ </div>
+ </div>
+ );
+ }
+}
+
+export class UniverColorPicker implements ColorPickerComponent {
+ render(): JSXComponent<BaseColorPickerProps> {
+ return ColorPicker;
+ }
+}
+
+export { ColorPicker };
diff --git a/packages/base-ui/src/Components/ColorPicker/ColorPickerPanel/ColorPickerPanel.tsx b/packages/base-ui/src/Components/ColorPicker/ColorPickerPanel/ColorPickerPanel.tsx
index 7696d8df51..84d4b58290 100644
--- a/packages/base-ui/src/Components/ColorPicker/ColorPickerPanel/ColorPickerPanel.tsx
+++ b/packages/base-ui/src/Components/ColorPicker/ColorPickerPanel/ColorPickerPanel.tsx
@@ -1,5 +1,5 @@
+import { Component } from 'preact';
import { HexColorInput, RgbaStringColorPicker } from 'react-colorful';
-import { Component } from '../../../Framework';
import { debounce } from '../../../Utils';
import { RgbaColorInput } from '../RgbaColorInput';
@@ -16,6 +16,11 @@ interface IState {
}
class ColorPickerPanel extends Component<IProps, IState> {
+ constructor(props: IProps) {
+ super();
+ this.initialize(props);
+ }
+
initialize(props: IProps) {
this.state = {
color: props.color || '#000',
diff --git a/packages/base-ui/src/Components/ColorPicker/RgbaColorInput/RgbaColorInput.tsx b/packages/base-ui/src/Components/ColorPicker/RgbaColorInput/RgbaColorInput.tsx
index 303cc18b9d..e5f3a6c142 100644
--- a/packages/base-ui/src/Components/ColorPicker/RgbaColorInput/RgbaColorInput.tsx
+++ b/packages/base-ui/src/Components/ColorPicker/RgbaColorInput/RgbaColorInput.tsx
@@ -1,31 +1,31 @@
-import { Color, Nullable } from '@univerjs/core';
-import { useRef } from '../../../Framework';
-import { Input } from '../../Input';
-
-interface IProps {
- color: Nullable<string>;
- onChange: (...arg: any) => void;
-}
-
-export const RgbaColorInput = (props: IProps) => {
- let { color } = props;
- if (!color) return null;
- let rgba;
- if (color.indexOf('#') > -1) {
- color = Color.hexToRgbString(color);
- if (!color) return null;
- rgba = color.replace('rgba(', '').replace(')', '').split(',');
- } else if (color.indexOf('rgba') > -1) {
- rgba = color.replace('rgba(', '').replace(')', '').split(',');
- } else {
- rgba = color.replace('rgb(', '').replace(')', '').split(',');
- rgba.push('1');
- }
-
- let inputRef = useRef<HTMLInputElement>(null);
- const onChange = () => {
- props.onChange((inputRef.current! as any).base.value);
- };
-
- return <Input ref={inputRef} type="text" value={`rgba(${rgba})`} onChange={onChange} />;
-};
+import { Color, Nullable } from '@univerjs/core';
+import { useRef } from 'preact/hooks';
+import { Input } from '../../Input';
+
+interface IProps {
+ color: Nullable<string>;
+ onChange: (...arg: any) => void;
+}
+
+export const RgbaColorInput = (props: IProps) => {
+ let { color } = props;
+ if (!color) return null;
+ let rgba;
+ if (color.indexOf('#') > -1) {
+ color = Color.hexToRgbString(color);
+ if (!color) return null;
+ rgba = color.replace('rgba(', '').replace(')', '').split(',');
+ } else if (color.indexOf('rgba') > -1) {
+ rgba = color.replace('rgba(', '').replace(')', '').split(',');
+ } else {
+ rgba = color.replace('rgb(', '').replace(')', '').split(',');
+ rgba.push('1');
+ }
+
+ const inputRef = useRef<HTMLInputElement>(null);
+ const onChange = () => {
+ props.onChange((inputRef.current! as any).base.value);
+ };
+
+ return <Input ref={inputRef} type="text" value={`rgba(${rgba})`} onChange={onChange} />;
+};
diff --git a/packages/base-ui/src/Components/ColorPickerCircleButton/ColorPickerCircleButton.tsx b/packages/base-ui/src/Components/ColorPickerCircleButton/ColorPickerCircleButton.tsx
index d8d495ff95..3a55e3ff97 100644
--- a/packages/base-ui/src/Components/ColorPickerCircleButton/ColorPickerCircleButton.tsx
+++ b/packages/base-ui/src/Components/ColorPickerCircleButton/ColorPickerCircleButton.tsx
@@ -1,43 +1,43 @@
-import { JSXComponent } from '../../BaseComponent';
-import { Component, createRef } from '../../Framework';
-import { BaseColorPickerCircleButtonProps, ColorPickerCircleButtonComponent } from '../../Interfaces';
-import { NextIcon } from '../Icon';
-import { ColorPicker } from '../index';
-import Styles from './index.module.less';
-
-interface IState {}
-
-/**
- * e2e test,check Components.playwright.test.ts
- */
-export class ColorPickerCircleButton extends Component<BaseColorPickerCircleButtonProps, IState> {
- ref = createRef<HTMLDivElement>();
-
- colorRef = createRef();
-
- /**
- * handle ColorSelectButton Click,show color picker
- */
- handleColorSelectButtonClick = (e: Event) => {
- e.stopImmediatePropagation();
- this.colorRef.current.showSelect(this.ref.current);
- };
-
- render(props: BaseColorPickerCircleButtonProps) {
- const { color, onClick, onCancel, style, colorPickerStyle } = props;
-
- return (
- <div style={style} className={Styles.colorPickerCircleButton} ref={this.ref} onClick={this.handleColorSelectButtonClick}>
- <span className={`${Styles.colorSelectCircle} ${Styles.verticalMiddle}`} style={{ backgroundColor: color }}></span>
- <NextIcon className={Styles.verticalMiddle} />
- <ColorPicker color={color} onClick={onClick} onCancel={onCancel} style={colorPickerStyle} ref={this.colorRef} />
- </div>
- );
- }
-}
-
-export class UniverColorPickerCircleButton implements ColorPickerCircleButtonComponent {
- render(): JSXComponent<BaseColorPickerCircleButtonProps> {
- return ColorPickerCircleButton;
- }
-}
+import { Component, createRef } from 'preact';
+import { JSXComponent } from '../../BaseComponent';
+import { BaseColorPickerCircleButtonProps, ColorPickerCircleButtonComponent } from '../../Interfaces';
+import { NextIcon } from '../Icon';
+import { ColorPicker } from '../index';
+import Styles from './index.module.less';
+
+interface IState {}
+
+/**
+ * e2e test,check Components.playwright.test.ts
+ */
+export class ColorPickerCircleButton extends Component<BaseColorPickerCircleButtonProps, IState> {
+ ref = createRef<HTMLDivElement>();
+
+ colorRef = createRef();
+
+ /**
+ * handle ColorSelectButton Click,show color picker
+ */
+ handleColorSelectButtonClick = (e: Event) => {
+ e.stopImmediatePropagation();
+ this.colorRef.current.showSelect(this.ref.current);
+ };
+
+ render(props: BaseColorPickerCircleButtonProps) {
+ const { color, onClick, onCancel, style, colorPickerStyle } = props;
+
+ return (
+ <div style={style} className={Styles.colorPickerCircleButton} ref={this.ref} onClick={this.handleColorSelectButtonClick}>
+ <span className={`${Styles.colorSelectCircle} ${Styles.verticalMiddle}`} style={{ backgroundColor: color }}></span>
+ <NextIcon className={Styles.verticalMiddle} />
+ <ColorPicker color={color} onClick={onClick} onCancel={onCancel} style={colorPickerStyle} ref={this.colorRef} />
+ </div>
+ );
+ }
+}
+
+export class UniverColorPickerCircleButton implements ColorPickerCircleButtonComponent {
+ render(): JSXComponent<BaseColorPickerCircleButtonProps> {
+ return ColorPickerCircleButton;
+ }
+}
diff --git a/packages/base-ui/src/Components/Confirm/Confirm.tsx b/packages/base-ui/src/Components/Confirm/Confirm.tsx
index 930de2bc86..a39766161d 100644
--- a/packages/base-ui/src/Components/Confirm/Confirm.tsx
+++ b/packages/base-ui/src/Components/Confirm/Confirm.tsx
@@ -1,5 +1,6 @@
-import { Component } from '../../Framework';
+import { Component } from 'preact';
import { Modal } from '../Modal';
+import { CustomLabel } from '../CustomLabel';
import styles from './index.module.less';
interface BaseConfirmProps {
@@ -36,19 +37,19 @@ export class Confirm extends Component<BaseConfirmProps, IState> {
getGroup() {
const group = [
{
- label: this.getLocale('button.confirm'),
+ label: <CustomLabel label="button.confirm" />,
type: 'primary',
onClick: () => this.handleClick(),
},
{
- label: this.getLocale('button.cancel'),
+ label: <CustomLabel label="button.cancel" />,
onClick: () => this.showModal(false),
},
];
return group;
}
- componentWillReceiveProps(props: BaseConfirmProps): void {
+ override componentWillReceiveProps(props: BaseConfirmProps): void {
if (props.show !== this.props.show) {
this.setState({
show: props.show,
diff --git a/packages/base-ui/src/Components/Container/Container.tsx b/packages/base-ui/src/Components/Container/Container.tsx
index 9448c9d0d3..89b05340b2 100644
--- a/packages/base-ui/src/Components/Container/Container.tsx
+++ b/packages/base-ui/src/Components/Container/Container.tsx
@@ -1,4 +1,5 @@
-import { ComponentChildren, forwardRef, Ref } from '../../Framework';
+import { ComponentChildren, Ref } from 'preact';
+import { forwardRef } from 'preact/compat';
type IProps = {
children?: ComponentChildren;
diff --git a/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx b/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx
new file mode 100644
index 0000000000..e31cb80baf
--- /dev/null
+++ b/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx
@@ -0,0 +1,28 @@
+import { isValidElement } from 'preact';
+import { useContext } from 'preact/hooks';
+import { AppContext, CustomComponent } from '../../Common';
+import { BaseCustomLabelProps } from '../../Interfaces';
+
+export function CustomLabel(props: BaseCustomLabelProps): JSX.Element | null {
+ const context = useContext(AppContext);
+ const { label } = props;
+
+ function getLocale(name: string) {
+ return context.localeService?.t(name);
+ }
+
+ if (typeof label === 'string') {
+ return <>{getLocale(label)}</>;
+ }
+ if (isValidElement(label)) {
+ return label;
+ }
+ if (label) {
+ const Label = context.componentManager?.get((label as CustomComponent).name) as any;
+ if (Label) {
+ const props = (label as CustomComponent).props ?? {};
+ return <Label {...props} />;
+ }
+ }
+ return null;
+}
diff --git a/packages/base-ui/src/Components/CustomLabel/index.ts b/packages/base-ui/src/Components/CustomLabel/index.ts
new file mode 100644
index 0000000000..4f5055db8e
--- /dev/null
+++ b/packages/base-ui/src/Components/CustomLabel/index.ts
@@ -0,0 +1 @@
+export * from './CustomLabel';
diff --git a/packages/base-ui/src/Components/Drag/Drag-back.tsx b/packages/base-ui/src/Components/Drag/Drag-back.tsx
index 16f67ede32..167682c3a1 100644
--- a/packages/base-ui/src/Components/Drag/Drag-back.tsx
+++ b/packages/base-ui/src/Components/Drag/Drag-back.tsx
@@ -1,4 +1,4 @@
-import { Component, createRef } from '../../Framework';
+import { Component, createRef } from 'preact';
import { JSXComponent } from '../../BaseComponent';
import { BaseDragProps, DragComponent } from '../../Interfaces';
import styles from './index.module.less';
@@ -22,6 +22,11 @@ interface IState {
class Drag extends Component<BaseDragProps, IState> {
root = createRef();
+ constructor(props: BaseDragProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
left: '',
@@ -45,8 +50,8 @@ class Drag extends Component<BaseDragProps, IState> {
onMouseDown(e: MouseEvent) {
// e.stopPropagation();
// if (!((e.target as Element).className === styles.drag)) return;
- let offsetX = e.offsetX;
- let offsetY = e.offsetY;
+ const offsetX = e.offsetX;
+ const offsetY = e.offsetY;
this.setState(
{
offsetX,
@@ -60,16 +65,16 @@ class Drag extends Component<BaseDragProps, IState> {
onMouseMove = (e: MouseEvent) => {
// e.stopPropagation();
- let offsetX = this.state.offsetX;
- let offsetY = this.state.offsetY;
+ const offsetX = this.state.offsetX;
+ const offsetY = this.state.offsetY;
// if (e.x === offsetX && e.y === offsetY) return;
- let x = e.x;
- let y = e.y;
+ const x = e.x;
+ const y = e.y;
- let left = `${x - offsetX}px`;
- let top = `${y - offsetY}px`;
+ const left = `${x - offsetX}px`;
+ const top = `${y - offsetY}px`;
this.setState({
top,
left,
diff --git a/packages/base-ui/src/Components/Drag/Drag.tsx b/packages/base-ui/src/Components/Drag/Drag.tsx
index d3d8a6874a..69c86d32aa 100644
--- a/packages/base-ui/src/Components/Drag/Drag.tsx
+++ b/packages/base-ui/src/Components/Drag/Drag.tsx
@@ -1,4 +1,4 @@
-import { Component, createRef } from '../../Framework';
+import { Component, createRef } from 'preact';
import { JSXComponent } from '../../BaseComponent';
import { BaseDragProps, DragComponent } from '../../Interfaces';
import styles from './index.module.less';
@@ -8,8 +8,6 @@ interface IState {}
class Drag extends Component<BaseDragProps, IState> {
root = createRef();
- initialize() {}
-
initDragDialog() {
// Drag and drop function (mainly to trigger three events: onpointerdown\onpointermove\onpointerup)
const drag = this.root.current;
diff --git a/packages/base-ui/src/Components/Dropdown/Dropdown.tsx b/packages/base-ui/src/Components/Dropdown/Dropdown.tsx
index 02b08eaa6e..2206601a15 100644
--- a/packages/base-ui/src/Components/Dropdown/Dropdown.tsx
+++ b/packages/base-ui/src/Components/Dropdown/Dropdown.tsx
@@ -1,6 +1,7 @@
+import { createRef } from 'preact';
+import { PureComponent } from 'preact/compat';
import { Icon } from '..';
import { JSXComponent } from '../../BaseComponent';
-import { PureComponent, createRef } from '../../Framework';
import { BaseDropdownProps, DropdownComponent } from '../../Interfaces';
import { Menu } from '../Menu';
import { Tooltip } from '../Tooltip';
@@ -17,6 +18,11 @@ export class Dropdown extends PureComponent<BaseDropdownProps, IState> {
IconRef = createRef<HTMLDivElement>();
+ constructor(props: BaseDropdownProps) {
+ super(props);
+ this.initialize();
+ }
+
handleClick = (e: MouseEvent) => {
this.props.onClick?.();
this.props.onMainClick?.();
@@ -42,7 +48,7 @@ export class Dropdown extends PureComponent<BaseDropdownProps, IState> {
componentDidMount() {
const { placement } = this.props;
- let style: Record<string, string | number> = { position: 'absolute' };
+ const style: Record<string, string | number> = { position: 'absolute' };
if (!placement || placement === 'Bottom') {
style.left = 0;
style.top = '100%';
diff --git a/packages/base-ui/src/Components/FilterSelect/FilterSelect.tsx b/packages/base-ui/src/Components/FilterSelect/FilterSelect.tsx
index 3ca5872022..cb43e7f8f0 100644
--- a/packages/base-ui/src/Components/FilterSelect/FilterSelect.tsx
+++ b/packages/base-ui/src/Components/FilterSelect/FilterSelect.tsx
@@ -1,113 +1,113 @@
-// import { JSXComponent } from '../../BaseComponent';
-// import { Component, createRef } from '../../Framework';
-// import { BaseFilterSelectProps, FilterSelectComponent } from '../../Interfaces';
-// import { ColorPicker, Icon, Ul } from '../index';
-// import styles from './index.module.less';
-
-// // interface IProps {}
-// interface IState {
-// list: List[];
-// sheetUl: any;
-// }
-
-// class FilterSelect extends Component<BaseFilterSelectProps, IState> {
-// buttonRef = createRef();
-
-// root = createRef();
-
-// initialize(props: BaseFilterSelectProps) {
-// this.state = {
-// list: [
-// { content: '以A-Z升序排列', onClick: this.printContent.bind(this, '以A-Z升序排列') },
-// { content: '以Z-A降序排列', onClick: this.printContent.bind(this, '以Z-A降序排列') },
-// {
-// content: '按颜色筛选',
-// onClick: this.printContent.bind(this, '按颜色筛选'),
-// children: [{ content: <ColorPicker color="#000" onClick={() => {}} onCancel={() => {}} style={{ display: 'flex' }} />, type: 'jsx' }],
-// },
-// { content: '按条件过滤', onClick: this.printContent.bind(this, '按条件过滤') },
-// { content: '按值过滤', onClick: this.printContent.bind(this, '按值过滤') },
-// ],
-// sheetUl: [
-// {
-// label: '删除',
-// },
-// {
-// label: '复制',
-// },
-// {
-// label: '重命名',
-// },
-// {
-// label: '更改颜色',
-// icon: <Icon.Format.RightIcon />,
-
-// children: [
-// {
-// label: <ColorPicker style={{ visibility: 'visible', position: 'relative', boxShadow: 'none' }} color="#000" onClick={() => {}} onCancel={() => {}} />,
-// isJsx: true,
-// },
-// ],
-// },
-// {
-// label: '隐藏',
-// border: true,
-// },
-// {
-// label: '取消隐藏',
-// },
-// {
-// label: '向左移',
-// border: true,
-// },
-// {
-// label: '向右移',
-// },
-// ],
-// };
-// }
-
-// printContent(val: string) {
-// console.log(val);
-// }
-
-// onClick(e: MouseEvent) {
-// e.preventDefault();
-// this.root.current.showSelect();
-// }
-
-// handleClick = (e: Event) => {
-// if (this.buttonRef.current.contains(e.target)) return;
-// this.root.current.hideSelect();
-// };
-
-// // TODO:remove to show select
-// componentDidMount() {
-// // 添加右键点击、点击事件监听
-// document.addEventListener('click', this.handleClick);
-// }
-
-// componentWillUnmount() {
-// // 移除事件监听
-// document.removeEventListener('click', this.handleClick);
-// }
-
-// render() {
-// return (
-// <div className={styles.filterSelect}>
-// <span ref={this.buttonRef} onClick={this.onClick.bind(this)}>
-// <Icon.Format.NextIcon />
-// </span>
-// <Ul children={this.state.sheetUl} ref={this.root}></Ul>
-// </div>
-// );
-// }
-// }
-
-// export class UniverFilterSelect implements FilterSelectComponent {
-// render(): JSXComponent<BaseFilterSelectProps> {
-// return FilterSelect;
-// }
-// }
-
-// export { FilterSelect };
+// import { JSXComponent } from '../../BaseComponent';
+// import { Component, createRef } from 'preact';
+// import { BaseFilterSelectProps, FilterSelectComponent } from '../../Interfaces';
+// import { ColorPicker, Icon, Ul } from '../index';
+// import styles from './index.module.less';
+
+// // interface IProps {}
+// interface IState {
+// list: List[];
+// sheetUl: any;
+// }
+
+// class FilterSelect extends Component<BaseFilterSelectProps, IState> {
+// buttonRef = createRef();
+
+// root = createRef();
+
+// initialize(props: BaseFilterSelectProps) {
+// this.state = {
+// list: [
+// { content: '以A-Z升序排列', onClick: this.printContent.bind(this, '以A-Z升序排列') },
+// { content: '以Z-A降序排列', onClick: this.printContent.bind(this, '以Z-A降序排列') },
+// {
+// content: '按颜色筛选',
+// onClick: this.printContent.bind(this, '按颜色筛选'),
+// children: [{ content: <ColorPicker color="#000" onClick={() => {}} onCancel={() => {}} style={{ display: 'flex' }} />, type: 'jsx' }],
+// },
+// { content: '按条件过滤', onClick: this.printContent.bind(this, '按条件过滤') },
+// { content: '按值过滤', onClick: this.printContent.bind(this, '按值过滤') },
+// ],
+// sheetUl: [
+// {
+// label: '删除',
+// },
+// {
+// label: '复制',
+// },
+// {
+// label: '重命名',
+// },
+// {
+// label: '更改颜色',
+// icon: <Icon.Format.RightIcon />,
+
+// children: [
+// {
+// label: <ColorPicker style={{ visibility: 'visible', position: 'relative', boxShadow: 'none' }} color="#000" onClick={() => {}} onCancel={() => {}} />,
+// isJsx: true,
+// },
+// ],
+// },
+// {
+// label: '隐藏',
+// border: true,
+// },
+// {
+// label: '取消隐藏',
+// },
+// {
+// label: '向左移',
+// border: true,
+// },
+// {
+// label: '向右移',
+// },
+// ],
+// };
+// }
+
+// printContent(val: string) {
+// console.log(val);
+// }
+
+// onClick(e: MouseEvent) {
+// e.preventDefault();
+// this.root.current.showSelect();
+// }
+
+// handleClick = (e: Event) => {
+// if (this.buttonRef.current.contains(e.target)) return;
+// this.root.current.hideSelect();
+// };
+
+// // TODO:remove to show select
+// componentDidMount() {
+// // 添加右键点击、点击事件监听
+// document.addEventListener('click', this.handleClick);
+// }
+
+// componentWillUnmount() {
+// // 移除事件监听
+// document.removeEventListener('click', this.handleClick);
+// }
+
+// render() {
+// return (
+// <div className={styles.filterSelect}>
+// <span ref={this.buttonRef} onClick={this.onClick.bind(this)}>
+// <Icon.Format.NextIcon />
+// </span>
+// <Ul children={this.state.sheetUl} ref={this.root}></Ul>
+// </div>
+// );
+// }
+// }
+
+// export class UniverFilterSelect implements FilterSelectComponent {
+// render(): JSXComponent<BaseFilterSelectProps> {
+// return FilterSelect;
+// }
+// }
+
+// export { FilterSelect };
diff --git a/packages/base-ui/src/Components/FormatModal/FormatModal.tsx b/packages/base-ui/src/Components/FormatModal/FormatModal.tsx
index 8fe9f55f0e..6655047a75 100644
--- a/packages/base-ui/src/Components/FormatModal/FormatModal.tsx
+++ b/packages/base-ui/src/Components/FormatModal/FormatModal.tsx
@@ -1,162 +1,162 @@
-// import { Nullable, Observer, Workbook } from '@univerjs/core';
-// import { Component } from '../../Framework';
-// import { BaseFormatModalProps } from '../../Interfaces';
-// import { Modal, Ul } from '../index';
-// import styles from './index.module.less';
-
-// // interface FormatModalProps extends UlProps, ModalProps {
-// // children?: any;
-// // }
-
-// type localeProps = {
-// name: string;
-// value: string;
-// };
-
-// type FormatModalState = {
-// data: BaseFormatModalProps[];
-// };
-
-// export class FormatModal extends Component<BaseFormatModalProps, FormatModalState> {
-// refs: Ul[] = [];
-
-// ModalRefs: Modal[] = [];
-
-// private _localeObserver: Nullable<Observer<Workbook>>;
-
-// initialize(props: BaseFormatModalProps) {
-// // super(props);
-
-// this.state = {
-// data: [
-// {
-// name: 'format.titleCurrency',
-// show: false,
-// group: [
-// {
-// locale: 'button.confirm',
-// type: 'primary',
-// },
-// {
-// locale: 'button.cancel',
-// },
-// ],
-// onCancel: () => this.showModal('format.titleCurrency', false),
-// },
-// {
-// name: 'format.titleDateTime',
-// show: false,
-// group: [
-// {
-// locale: 'button.confirm',
-// type: 'primary',
-// },
-// {
-// locale: 'button.cancel',
-// },
-// ],
-// onCancel: () => this.showModal('format.titleDateTime', false),
-// },
-// {
-// name: 'format.titleNumber',
-// show: false,
-// group: [
-// {
-// locale: 'button.confirm',
-// type: 'primary',
-// },
-// {
-// locale: 'button.cancel',
-// },
-// ],
-// onCancel: () => this.showModal('format.titleNumber', false),
-// },
-// ],
-// };
-// }
-
-// setLocale() {
-// const locale = this.context.locale;
-// let data = this.state.data;
-// data.forEach((item) => {
-// item.title = locale.get(item.name);
-// if (item.name === 'format.titleCurrency') {
-// item.children = locale.get('currencyDetail').map((ele: localeProps) => ({
-// label: ele.name,
-// icon: ele.value,
-// }));
-// } else if (item.name === 'format.titleDateTime') {
-// item.children = locale.get('dateFmtList').map((ele: localeProps) => ({
-// label: ele.name,
-// icon: ele.value,
-// }));
-// } else if (item.name === 'format.titleNumber') {
-// item.children = locale.get('numFmtList').map((ele: localeProps) => ({
-// label: ele.name,
-// icon: ele.value,
-// }));
-// }
-// if (item.group?.length) {
-// item.group.forEach((ele) => {
-// ele.label = locale.get(ele.locale);
-// });
-// }
-// });
-// this.setState((prevState) => ({
-// data,
-// }));
-// }
-
-// setValue = (value: object, fn?: () => void) => {
-// this.setState(
-// (prevState) => ({
-// ...value,
-// }),
-// fn
-// );
-// };
-
-// // show modal
-// showModal = (name: string, isShow: boolean) => {
-// let data = this.state.data;
-// let index = data.findIndex((item) => item.name === name);
-// if (index > -1) {
-// data[index].show = isShow;
-// this.setValue({ data }, () => ({ data }));
-// }
-// };
-
-// componentWillMount() {
-// this.setLocale();
-
-// this._localeObserver = this._context
-// .getObserverManager()
-// .getObserver<Workbook>('onAfterChangeUILocaleObservable', 'workbook')
-// ?.add(() => {
-// this.setLocale();
-// });
-// }
-
-// componentWillUnmount() {
-// // this._context.getObserverManager().getObserver<Workbook>('onAfterChangeUILocaleObservable', 'workbook')?.remove(this._localeObserver);
-// }
-
-// render(props: BaseFormatModalProps, state: FormatModalState) {
-// const { data } = state;
-// return (
-// <>
-// {data.map((item, index) => {
-// if (item.show) {
-// return (
-// <Modal title={item.title} className={styles.formatModal} group={item.group} visible={item.show} onCancel={item.onCancel}>
-// {item.label}
-// <Ul show={true} children={item.children} ref={(ele: Ul) => (this.refs[index] = ele)}></Ul>
-// </Modal>
-// );
-// }
-// return <></>;
-// })}
-// </>
-// );
-// }
-// }
+// import { Nullable, Observer, Workbook } from '@univerjs/core';
+// import { Component } from 'preact';
+// import { BaseFormatModalProps } from '../../Interfaces';
+// import { Modal, Ul } from '../index';
+// import styles from './index.module.less';
+
+// // interface FormatModalProps extends UlProps, ModalProps {
+// // children?: any;
+// // }
+
+// type localeProps = {
+// name: string;
+// value: string;
+// };
+
+// type FormatModalState = {
+// data: BaseFormatModalProps[];
+// };
+
+// export class FormatModal extends Component<BaseFormatModalProps, FormatModalState> {
+// refs: Ul[] = [];
+
+// ModalRefs: Modal[] = [];
+
+// private _localeObserver: Nullable<Observer<Workbook>>;
+
+// initialize(props: BaseFormatModalProps) {
+// // super(props);
+
+// this.state = {
+// data: [
+// {
+// name: 'format.titleCurrency',
+// show: false,
+// group: [
+// {
+// locale: 'button.confirm',
+// type: 'primary',
+// },
+// {
+// locale: 'button.cancel',
+// },
+// ],
+// onCancel: () => this.showModal('format.titleCurrency', false),
+// },
+// {
+// name: 'format.titleDateTime',
+// show: false,
+// group: [
+// {
+// locale: 'button.confirm',
+// type: 'primary',
+// },
+// {
+// locale: 'button.cancel',
+// },
+// ],
+// onCancel: () => this.showModal('format.titleDateTime', false),
+// },
+// {
+// name: 'format.titleNumber',
+// show: false,
+// group: [
+// {
+// locale: 'button.confirm',
+// type: 'primary',
+// },
+// {
+// locale: 'button.cancel',
+// },
+// ],
+// onCancel: () => this.showModal('format.titleNumber', false),
+// },
+// ],
+// };
+// }
+
+// setLocale() {
+// const locale = this.context.locale;
+// let data = this.state.data;
+// data.forEach((item) => {
+// item.title = locale.get(item.name);
+// if (item.name === 'format.titleCurrency') {
+// item.children = locale.get('currencyDetail').map((ele: localeProps) => ({
+// label: ele.name,
+// icon: ele.value,
+// }));
+// } else if (item.name === 'format.titleDateTime') {
+// item.children = locale.get('dateFmtList').map((ele: localeProps) => ({
+// label: ele.name,
+// icon: ele.value,
+// }));
+// } else if (item.name === 'format.titleNumber') {
+// item.children = locale.get('numFmtList').map((ele: localeProps) => ({
+// label: ele.name,
+// icon: ele.value,
+// }));
+// }
+// if (item.group?.length) {
+// item.group.forEach((ele) => {
+// ele.label = locale.get(ele.locale);
+// });
+// }
+// });
+// this.setState((prevState) => ({
+// data,
+// }));
+// }
+
+// setValue = (value: object, fn?: () => void) => {
+// this.setState(
+// (prevState) => ({
+// ...value,
+// }),
+// fn
+// );
+// };
+
+// // show modal
+// showModal = (name: string, isShow: boolean) => {
+// let data = this.state.data;
+// let index = data.findIndex((item) => item.name === name);
+// if (index > -1) {
+// data[index].show = isShow;
+// this.setValue({ data }, () => ({ data }));
+// }
+// };
+
+// componentWillMount() {
+// this.setLocale();
+
+// this._localeObserver = this._context
+// .getObserverManager()
+// .getObserver<Workbook>('onAfterChangeUILocaleObservable', 'workbook')
+// ?.add(() => {
+// this.setLocale();
+// });
+// }
+
+// componentWillUnmount() {
+// // this._context.getObserverManager().getObserver<Workbook>('onAfterChangeUILocaleObservable', 'workbook')?.remove(this._localeObserver);
+// }
+
+// render(props: BaseFormatModalProps, state: FormatModalState) {
+// const { data } = state;
+// return (
+// <>
+// {data.map((item, index) => {
+// if (item.show) {
+// return (
+// <Modal title={item.title} className={styles.formatModal} group={item.group} visible={item.show} onCancel={item.onCancel}>
+// {item.label}
+// <Ul show={true} children={item.children} ref={(ele: Ul) => (this.refs[index] = ele)}></Ul>
+// </Modal>
+// );
+// }
+// return <></>;
+// })}
+// </>
+// );
+// }
+// }
diff --git a/packages/base-ui/src/Components/Grid/Grid.tsx b/packages/base-ui/src/Components/Grid/Grid.tsx
index f9d31eef3b..2e1a7bd682 100644
--- a/packages/base-ui/src/Components/Grid/Grid.tsx
+++ b/packages/base-ui/src/Components/Grid/Grid.tsx
@@ -1,4 +1,4 @@
-import { ComponentChildren } from '../../Framework';
+import { ComponentChildren } from 'preact';
type BaseGridProps = {
children?: ComponentChildren;
diff --git a/packages/base-ui/src/Components/Input/input.tsx b/packages/base-ui/src/Components/Input/input.tsx
index 7b650f7219..9fc0c883fc 100644
--- a/packages/base-ui/src/Components/Input/input.tsx
+++ b/packages/base-ui/src/Components/Input/input.tsx
@@ -1,4 +1,4 @@
-import { Component, createRef } from '../../Framework';
+import { Component, createRef } from 'preact';
import { JSXComponent } from '../../BaseComponent';
import { BaseInputProps, InputComponent } from '../../Interfaces';
import { joinClassNames } from '../../Utils';
@@ -30,6 +30,11 @@ type IState = {
export class Input extends Component<BaseInputProps, IState> {
ref = createRef();
+ constructor(props: BaseInputProps) {
+ super();
+ this.initialize(props);
+ }
+
initialize(props: BaseInputProps) {
// super(props);
this.state = {
diff --git a/packages/base-ui/src/Components/Item/Item.tsx b/packages/base-ui/src/Components/Item/Item.tsx
index 3cdde9ccd3..6c81007bf7 100644
--- a/packages/base-ui/src/Components/Item/Item.tsx
+++ b/packages/base-ui/src/Components/Item/Item.tsx
@@ -1,6 +1,7 @@
-import { ComponentChildren, Component } from '../../Framework';
+import { ComponentChildren, Component } from 'preact';
import { BaseMenuItem } from '../../Interfaces';
import { joinClassNames } from '../../Utils';
+import { CustomLabel } from '../CustomLabel';
import styles from './index.module.less';
import { Icon } from '..';
@@ -22,8 +23,16 @@ export class Item extends Component<BaseItemProps> {
) : (
''
)}
- <span className={styles.selectItemContent}>{this.getLabel(label)}</span>
- {suffix ? <span className={styles.selectItemSuffix}>{this.getLabel(suffix)}</span> : ''}
+ <span className={styles.selectItemContent}>
+ <CustomLabel label={label} />
+ </span>
+ {suffix ? (
+ <span className={styles.selectItemSuffix}>
+ <CustomLabel label={suffix} />
+ </span>
+ ) : (
+ ''
+ )}
</div>
);
}
diff --git a/packages/base-ui/src/Components/Layout/Layout.tsx b/packages/base-ui/src/Components/Layout/Layout.tsx
index bf27fae2f7..01ae8cd918 100644
--- a/packages/base-ui/src/Components/Layout/Layout.tsx
+++ b/packages/base-ui/src/Components/Layout/Layout.tsx
@@ -1,4 +1,5 @@
-import { Component, createRef, forwardRef, Ref } from '../../Framework';
+import { Component, createRef, Ref } from 'preact';
+import { forwardRef } from 'preact/compat';
import { BaseLayoutProps } from '../../Interfaces';
import { getFirstChildren } from '../../Utils';
import styles from './index.module.less';
@@ -25,7 +26,7 @@ export class Layout extends Component<BaseLayoutProps, IState> {
// If the first child element contains the `aside` component, the layout needs to be changed to horizontal arrangement
componentDidMount() {
if (this.ref.current) {
- let children = getFirstChildren(this.ref.current);
+ const children = getFirstChildren(this.ref.current);
const childrens = children instanceof Array ? children : [children];
for (const ele of childrens) {
diff --git a/packages/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsx
index 454398978d..2ff2ab05a9 100644
--- a/packages/base-ui/src/Components/Menu/Menu.tsx
+++ b/packages/base-ui/src/Components/Menu/Menu.tsx
@@ -1,6 +1,7 @@
-import { Component, createRef } from '../../Framework';
+import { Component, createRef } from 'preact';
import { BaseMenuProps, BaseMenuState, BaseMenuItem, BaseMenuStyle } from '../../Interfaces';
import { joinClassNames } from '../../Utils';
+import { CustomLabel } from '../CustomLabel';
import styles from './index.module.less';
export class Menu extends Component<BaseMenuProps, BaseMenuState> {
@@ -8,6 +9,11 @@ export class Menu extends Component<BaseMenuProps, BaseMenuState> {
private _refs: Menu[] = [];
+ constructor(props: BaseMenuProps) {
+ super(props);
+ this.initialize();
+ }
+
getMenuRef = () => this._MenuRef;
handleClick = (e: MouseEvent, item: BaseMenuItem, index: number) => {
@@ -44,7 +50,7 @@ export class Menu extends Component<BaseMenuProps, BaseMenuState> {
getStyle = () => {
const current = this._MenuRef.current;
if (!current) return;
- let style: BaseMenuStyle = {};
+ const style: BaseMenuStyle = {};
const curPosition = current.getBoundingClientRect();
let docPosition;
const { dom, parent } = this.props;
@@ -63,7 +69,7 @@ export class Menu extends Component<BaseMenuProps, BaseMenuState> {
if (parent) {
current.style.position = 'fixed';
// 获取固定定位后 父元素正确的位置信息
- let parPosition = current.parentElement?.getBoundingClientRect();
+ const parPosition = current.parentElement?.getBoundingClientRect();
if (!parPosition) return;
if (parPosition.right + curPosition.width > docPosition.right) {
style.left = `${parPosition.left - curPosition.width}px`;
@@ -117,7 +123,7 @@ export class Menu extends Component<BaseMenuProps, BaseMenuState> {
this.mouseLeave(e, index);
}}
>
- {this.getLabel(item.label)}
+ <CustomLabel label={item.label} />
{item.children ? (
<Menu
ref={(ele: Menu) => (this._refs[index] = ele)}
diff --git a/packages/base-ui/src/Components/Modal/Modal.tsx b/packages/base-ui/src/Components/Modal/Modal.tsx
index 3adb83b5cd..91f17a713f 100644
--- a/packages/base-ui/src/Components/Modal/Modal.tsx
+++ b/packages/base-ui/src/Components/Modal/Modal.tsx
@@ -1,114 +1,120 @@
-import { Component } from '../../Framework';
-import { JSXComponent } from '../../BaseComponent';
-import { BaseModalProps, ModalComponent } from '../../Interfaces';
-import { Button } from '../Button';
-import { Drag } from '../Drag';
-import * as Icon from '../Icon';
-import styles from './index.module.less';
-
-interface IState {
- visible: boolean;
-}
-
-class Modal extends Component<BaseModalProps, IState> {
- initialize() {
- this.state = {
- visible: this.props.visible ?? false,
- };
- }
-
- handleClickCancel = (cb: Function | undefined) => {
- // this.setState({ visible: false });
- if (cb) cb();
- };
-
- showModal = (value: boolean) => {
- this.setState((prevState) => ({
- visible: value,
- }));
- };
-
- componentWillReceiveProps(props: BaseModalProps) {
- if (props.visible !== this.state.visible) {
- this.setState({
- visible: props.visible,
- });
- }
- }
-
- // maskClick = (e: MouseEvent) => {
- // const mask = document.querySelector(`.${styles.modalMask}`);
- // if (e.target === mask) {
- // this.showModal(false);
- // this.props.maskClick?.();
- // }
- // };
- handleClick = (cb?: () => void) => {
- this.showModal(false);
- if (cb) cb();
- };
-
- render() {
- const { title, width = 500, top = 0, style, children, className = '', group = [], isDrag = false, mask = true, footer = true } = this.props;
- const { visible } = this.state;
-
- return (
- <>
- {visible ? (
- <div className={className}>
- {mask ? (
- <div
- className={styles.modalMask}
- onClick={(e) => {
- this.props.onCancel?.(e);
- this.showModal(false);
- }}
- ></div>
- ) : null}
- <Drag isDrag={isDrag} className={styles.modalDrag}>
- <div
- className={`${isDrag ? styles.modalDargWrapper : styles.modalWrapper}`}
- style={{
- width: `${width}px`,
- // top: `${top}px`,
- ...style,
- }}
- >
- <div className={styles.modalHeader}>
- <span>{title}</span>
- <span
- className={styles.modalClose}
- onClick={(e) => {
- this.props.onCancel?.(e);
- this.showModal(false);
- }}
- >
- <Icon.Other.Close></Icon.Other.Close>
- </span>
- </div>
- <div className={styles.modalBody}>{children}</div>
- {footer ? (
- <div className={styles.modalFooter}>
- {group.map((item) => (
- <Button type={item.type} onClick={() => this.handleClick(item.onClick)}>
- {this.getLocale(item.label)}
- </Button>
- ))}
- </div>
- ) : null}
- </div>
- </Drag>
- </div>
- ) : null}
- </>
- );
- }
-}
-
-export class UniverModal implements ModalComponent {
- render(): JSXComponent<BaseModalProps> {
- return Modal;
- }
-}
-
-export { Modal };
+import { Component } from 'preact';
+import { JSXComponent } from '../../BaseComponent';
+import { BaseModalProps, ModalComponent } from '../../Interfaces';
+import { Button } from '../Button';
+import { Drag } from '../Drag';
+import * as Icon from '../Icon';
+import { CustomLabel } from '../CustomLabel';
+import styles from './index.module.less';
+
+interface IState {
+ visible: boolean;
+}
+
+class Modal extends Component<BaseModalProps, IState> {
+ constructor(props: BaseModalProps) {
+ super(props);
+ this.initialize();
+ }
+
+ initialize() {
+ this.state = {
+ visible: this.props.visible ?? false,
+ };
+ }
+
+ handleClickCancel = (cb: Function | undefined) => {
+ // this.setState({ visible: false });
+ if (cb) cb();
+ };
+
+ showModal = (value: boolean) => {
+ this.setState((prevState) => ({
+ visible: value,
+ }));
+ };
+
+ override componentWillReceiveProps(props: BaseModalProps) {
+ if (props.visible !== this.state.visible) {
+ this.setState({
+ visible: props.visible,
+ });
+ }
+ }
+
+ // maskClick = (e: MouseEvent) => {
+ // const mask = document.querySelector(`.${styles.modalMask}`);
+ // if (e.target === mask) {
+ // this.showModal(false);
+ // this.props.maskClick?.();
+ // }
+ // };
+ handleClick = (cb?: () => void) => {
+ this.showModal(false);
+ if (cb) cb();
+ };
+
+ render() {
+ const { title, width = 500, top = 0, style, children, className = '', group = [], isDrag = false, mask = true, footer = true } = this.props;
+ const { visible } = this.state;
+
+ return (
+ <>
+ {visible ? (
+ <div className={className}>
+ {mask ? (
+ <div
+ className={styles.modalMask}
+ onClick={(e) => {
+ this.props.onCancel?.(e);
+ this.showModal(false);
+ }}
+ ></div>
+ ) : null}
+ <Drag isDrag={isDrag} className={styles.modalDrag}>
+ <div
+ className={`${isDrag ? styles.modalDargWrapper : styles.modalWrapper}`}
+ style={{
+ width: `${width}px`,
+ // top: `${top}px`,
+ ...style,
+ }}
+ >
+ <div className={styles.modalHeader}>
+ <span>{title}</span>
+ <span
+ className={styles.modalClose}
+ onClick={(e) => {
+ this.props.onCancel?.(e);
+ this.showModal(false);
+ }}
+ >
+ <Icon.Other.Close></Icon.Other.Close>
+ </span>
+ </div>
+ <div className={styles.modalBody}>{children}</div>
+ {footer ? (
+ <div className={styles.modalFooter}>
+ {group.map((item) => (
+ <Button type={item.type} onClick={() => this.handleClick(item.onClick)}>
+ <CustomLabel label={item.label} />
+ </Button>
+ ))}
+ </div>
+ ) : null}
+ </div>
+ </Drag>
+ </div>
+ ) : null}
+ </>
+ );
+ }
+}
+
+export class UniverModal implements ModalComponent {
+ render(): JSXComponent<BaseModalProps> {
+ return Modal;
+ }
+}
+
+export { Modal };
diff --git a/packages/base-ui/src/Components/Prompt/Prompt.tsx b/packages/base-ui/src/Components/Prompt/Prompt.tsx
index dfaf66734d..fd1cef7c60 100644
--- a/packages/base-ui/src/Components/Prompt/Prompt.tsx
+++ b/packages/base-ui/src/Components/Prompt/Prompt.tsx
@@ -1,5 +1,6 @@
-import { Component } from '../../Framework';
+import { Component } from 'preact';
import { Modal } from '../Modal';
+import { CustomLabel } from '../CustomLabel';
import styles from './index.module.less';
interface BaseConfirmProps {
@@ -36,12 +37,12 @@ export class Prompt extends Component<BaseConfirmProps, IState> {
getGroup() {
const group = [
{
- label: this.getLocale('button.confirm'),
+ label: <CustomLabel label="button.confirm" />,
type: 'primary',
onClick: () => this.handleClick(),
},
{
- label: this.getLocale('button.cancel'),
+ label: <CustomLabel label="button.cancel" />,
onClick: () => this.showModal(false),
},
];
@@ -61,8 +62,8 @@ export class Prompt extends Component<BaseConfirmProps, IState> {
const { show } = this.state;
return (
<div className={styles.confirmModal}>
- <Modal visible={show} isDrag={true} title={this.getLocale(title)} group={this.getGroup()}>
- {this.getLocale(content)}
+ <Modal visible={show} isDrag={true} title={<CustomLabel label={title} />} group={this.getGroup()}>
+ <CustomLabel label={content} />
</Modal>
</div>
);
diff --git a/packages/base-ui/src/Components/Radio/Radio.tsx b/packages/base-ui/src/Components/Radio/Radio.tsx
index 8c46a9ab55..292c48a6a7 100644
--- a/packages/base-ui/src/Components/Radio/Radio.tsx
+++ b/packages/base-ui/src/Components/Radio/Radio.tsx
@@ -1,4 +1,4 @@
-import { Component, VNode, cloneElement } from '../../Framework';
+import { Component, VNode, cloneElement } from 'preact';
import { JSXComponent } from '../../BaseComponent';
import { BaseRadioGroupProps, BaseRadioIProps, RadioComponent } from '../../Interfaces';
import styles from './index.module.less';
@@ -29,11 +29,11 @@ class RadioGroup extends Component<BaseRadioGroupProps, IState> {
return (
<div className={`${vertical ? styles.radioGroup : ''} ${className || ''}`}>
{this.props.children.map((item: VNode<BaseRadioIProps>) => {
- let isActive = this.props.active === item.props.value;
+ const isActive = this.props.active === item.props.value;
/**
- *
+ *
* Use item as VNode
- *
+ *
* fix : No overload matches this call.
Overload 1 of 2, '(vnode: VNode<any>, props?: any, ...children: ComponentChildren[]): VNode<any>', gave the following error.
Argument of type 'Radio & ComponentChildren' is not assignable to parameter of type 'VNode<any>'.
diff --git a/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.tsx b/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.tsx
index b2aded133d..efe89e26ed 100644
--- a/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.tsx
+++ b/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.tsx
@@ -1,188 +1,188 @@
-import { useEffect, useRef } from '../../Framework';
-import { JSXComponent } from '../../BaseComponent';
-import { BaseResizeDialogProps, ResizeDialogComponent } from '../../Interfaces';
-import styles from './index.module.less';
-
-export const ResizeDialog = (props: BaseResizeDialogProps) => {
- let { left = 0, top = 0, width = 100, height = 50, children, ratio = 1 } = props;
- const ref = useRef<HTMLDivElement>(null);
- const resizeRef = useRef<HTMLDivElement>(null);
-
- useEffect(() => {
- const dialog = ref.current;
- if (!dialog) return;
- dialog.style.width = `${width * ratio}px`;
- dialog.style.height = `${height * ratio}px`;
- dialog.style.left = `${left * ratio}px`;
- dialog.style.top = `${top * ratio}px`;
-
- // window.addEventListener('mousemove', mouseMove);
- // window.addEventListener('mouseup', mouseUp);
- // window.addEventListener('click', handleClick);
-
- // return () => {
- // TODO:应该在元素隐藏后即remove监听
- // window.removeEventListener('mousemove', mouseMove);
- // window.removeEventListener('mouseup', mouseUp);
- // window.removeEventListener('click', handleClick);
- // };
- }, []);
- let pastMove = [0, 0];
- let currentMove = [0, 0];
- let move = false;
- let resize = false;
- let resizeItem: any = null;
-
- const cancelHighlight = () => {
- if (!ref.current) return;
- const parent = ref.current.parentElement;
- if (!parent) return;
- const dom = parent.querySelectorAll(`.${styles.dialogResize}`);
- dom.forEach((item) => {
- item.classList.remove(styles.dialogResizeActive);
- });
- };
- const highLight = (e: Event) => {
- if (!ref.current || !resizeRef.current) return;
- const classList = resizeRef.current.classList;
- if (!ref.current.contains(e.target as HTMLElement)) {
- if (classList.contains(styles.dialogResizeActive)) {
- classList.remove(styles.dialogResizeActive);
- }
- } else {
- classList.add(styles.dialogResizeActive);
- }
- };
- const handleClick = (e: MouseEvent) => {
- e.stopPropagation();
- cancelHighlight();
- highLight(e);
- };
- const mouseDown = (e: MouseEvent) => {
- window.addEventListener('mousemove', mouseMove);
- window.addEventListener('mouseup', mouseUp);
- window.addEventListener('click', handleClick);
- e.stopPropagation();
- cancelHighlight();
- highLight(e);
- pastMove = [e.pageX, e.pageY];
- move = true;
- };
- const resizeMouseDown = (e: MouseEvent) => {
- e.stopPropagation();
- const target = e.target as HTMLElement;
- if (!target.className.includes(`${styles.resizeItem}`)) return;
- resizeItem = target;
- pastMove = [e.pageX, e.pageY];
- resize = true;
- };
- const mouseMove = (e: MouseEvent) => {
- e.stopPropagation();
- if (!ref.current) return;
- const parent = ref.current.parentElement;
- if (!parent) return;
- if (!parent.contains(e.target as HTMLElement)) return;
-
- if (!move && !resize) return;
- const dialog = ref.current;
- if (!dialog) return;
- currentMove = [e.pageX, e.pageY];
-
- left = parseFloat(dialog.style.left) + currentMove[0] - pastMove[0];
- left = left < 0 ? 0 : left;
- if (left + ref.current.offsetWidth > parent.offsetWidth) {
- left = parent.offsetWidth - ref.current.offsetWidth;
- }
- top = parseFloat(dialog.style.top) + currentMove[1] - pastMove[1];
- top = top < 0 ? 0 : top;
-
- if (top + ref.current.offsetHeight > parent.offsetHeight) {
- top = parent.offsetHeight - ref.current.offsetHeight;
- }
-
- if (resize) {
- let width;
- let height;
- const type = resizeItem.dataset.type;
- if (type === 'rm' || type === 'rb' || type === 'rt') {
- width = parseFloat(dialog.style.width) + currentMove[0] - pastMove[0];
- if (width < 10) width = 10;
- if (left + width > parent.offsetWidth) {
- width = parent.offsetWidth - left;
- }
- dialog.style.width = `${width}px`;
- }
- if (type === 'lm' || type === 'lb' || type === 'lt') {
- width = parseFloat(dialog.style.width) - (currentMove[0] - pastMove[0]);
- if (width < 10) width = 10;
- if (left + width > parent.offsetWidth) {
- width = parent.offsetWidth - left;
- }
- dialog.style.width = `${width}px`;
- dialog.style.left = `${left}px`;
- }
- if (type === 'lb' || type === 'mb' || type === 'rb') {
- height = parseFloat(dialog.style.height) + currentMove[1] - pastMove[1];
- if (height < 10) height = 10;
- if (height + top > parent.offsetHeight) {
- height = parent.offsetHeight - top;
- }
- dialog.style.height = `${height}px`;
- }
- if (type === 'lt' || type === 'mt' || type === 'rt') {
- height = parseFloat(dialog.style.height) - (currentMove[1] - pastMove[1]);
- if (height < 10) height = 10;
- if (height + top > parent.offsetHeight) {
- height = parent.offsetHeight - top;
- }
- dialog.style.height = `${height}px`;
- dialog.style.top = `${top}px`;
- }
- }
- if (move) {
- dialog.style.left = `${left}px`;
- dialog.style.top = `${top}px`;
- }
-
- pastMove = currentMove;
- };
- const mouseUp = (e: MouseEvent) => {
- window.removeEventListener('mousemove', mouseMove);
- window.removeEventListener('mouseup', mouseUp);
- window.removeEventListener('click', handleClick);
- e.stopPropagation();
- if (!move && !resize) return;
- const dialog = ref.current;
- if (!dialog) return;
- move = false;
- resize = false;
- };
-
- return (
- <div className={styles.resizeDialog} ref={ref}>
- <div className={styles.dialogMove} onMouseDown={mouseDown}>
- <div className={`${styles.moveItem} ${styles.moveTop}`}></div>
- <div className={`${styles.moveItem} ${styles.moveRight}`}></div>
- <div className={`${styles.moveItem} ${styles.moveBottom}`}></div>
- <div className={`${styles.moveItem} ${styles.moveLeft}`}></div>
- </div>
- <div className={styles.dialogResize} onMouseDown={resizeMouseDown} ref={resizeRef}>
- <div data-type="lt" className={`${styles.resizeItem} ${styles.resizeLt}`}></div>
- <div data-type="mt" className={`${styles.resizeItem} ${styles.resizeMt}`}></div>
- <div data-type="lm" className={`${styles.resizeItem} ${styles.resizeLm}`}></div>
- <div data-type="rm" className={`${styles.resizeItem} ${styles.resizeRm}`}></div>
- <div data-type="rt" className={`${styles.resizeItem} ${styles.resizeRt}`}></div>
- <div data-type="lb" className={`${styles.resizeItem} ${styles.resizeLb}`}></div>
- <div data-type="mb" className={`${styles.resizeItem} ${styles.resizeMb}`}></div>
- <div data-type="rb" className={`${styles.resizeItem} ${styles.resizeRb}`}></div>
- </div>
- <div className={styles.dialogContent}>{children}</div>
- </div>
- );
-};
-
-export class UniverResizeDialog implements ResizeDialogComponent {
- render(): JSXComponent<BaseResizeDialogProps> {
- return ResizeDialog;
- }
-}
+import { useEffect, useRef } from 'preact/hooks';
+import { JSXComponent } from '../../BaseComponent';
+import { BaseResizeDialogProps, ResizeDialogComponent } from '../../Interfaces';
+import styles from './index.module.less';
+
+export const ResizeDialog = (props: BaseResizeDialogProps) => {
+ let { left = 0, top = 0, width = 100, height = 50, children, ratio = 1 } = props;
+ const ref = useRef<HTMLDivElement>(null);
+ const resizeRef = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ const dialog = ref.current;
+ if (!dialog) return;
+ dialog.style.width = `${width * ratio}px`;
+ dialog.style.height = `${height * ratio}px`;
+ dialog.style.left = `${left * ratio}px`;
+ dialog.style.top = `${top * ratio}px`;
+
+ // window.addEventListener('mousemove', mouseMove);
+ // window.addEventListener('mouseup', mouseUp);
+ // window.addEventListener('click', handleClick);
+
+ // return () => {
+ // TODO:应该在元素隐藏后即remove监听
+ // window.removeEventListener('mousemove', mouseMove);
+ // window.removeEventListener('mouseup', mouseUp);
+ // window.removeEventListener('click', handleClick);
+ // };
+ }, []);
+ let pastMove = [0, 0];
+ let currentMove = [0, 0];
+ let move = false;
+ let resize = false;
+ let resizeItem: any = null;
+
+ const cancelHighlight = () => {
+ if (!ref.current) return;
+ const parent = ref.current.parentElement;
+ if (!parent) return;
+ const dom = parent.querySelectorAll(`.${styles.dialogResize}`);
+ dom.forEach((item) => {
+ item.classList.remove(styles.dialogResizeActive);
+ });
+ };
+ const highLight = (e: Event) => {
+ if (!ref.current || !resizeRef.current) return;
+ const classList = resizeRef.current.classList;
+ if (!ref.current.contains(e.target as HTMLElement)) {
+ if (classList.contains(styles.dialogResizeActive)) {
+ classList.remove(styles.dialogResizeActive);
+ }
+ } else {
+ classList.add(styles.dialogResizeActive);
+ }
+ };
+ const handleClick = (e: MouseEvent) => {
+ e.stopPropagation();
+ cancelHighlight();
+ highLight(e);
+ };
+ const mouseDown = (e: MouseEvent) => {
+ window.addEventListener('mousemove', mouseMove);
+ window.addEventListener('mouseup', mouseUp);
+ window.addEventListener('click', handleClick);
+ e.stopPropagation();
+ cancelHighlight();
+ highLight(e);
+ pastMove = [e.pageX, e.pageY];
+ move = true;
+ };
+ const resizeMouseDown = (e: MouseEvent) => {
+ e.stopPropagation();
+ const target = e.target as HTMLElement;
+ if (!target.className.includes(`${styles.resizeItem}`)) return;
+ resizeItem = target;
+ pastMove = [e.pageX, e.pageY];
+ resize = true;
+ };
+ const mouseMove = (e: MouseEvent) => {
+ e.stopPropagation();
+ if (!ref.current) return;
+ const parent = ref.current.parentElement;
+ if (!parent) return;
+ if (!parent.contains(e.target as HTMLElement)) return;
+
+ if (!move && !resize) return;
+ const dialog = ref.current;
+ if (!dialog) return;
+ currentMove = [e.pageX, e.pageY];
+
+ left = parseFloat(dialog.style.left) + currentMove[0] - pastMove[0];
+ left = left < 0 ? 0 : left;
+ if (left + ref.current.offsetWidth > parent.offsetWidth) {
+ left = parent.offsetWidth - ref.current.offsetWidth;
+ }
+ top = parseFloat(dialog.style.top) + currentMove[1] - pastMove[1];
+ top = top < 0 ? 0 : top;
+
+ if (top + ref.current.offsetHeight > parent.offsetHeight) {
+ top = parent.offsetHeight - ref.current.offsetHeight;
+ }
+
+ if (resize) {
+ let width;
+ let height;
+ const type = resizeItem.dataset.type;
+ if (type === 'rm' || type === 'rb' || type === 'rt') {
+ width = parseFloat(dialog.style.width) + currentMove[0] - pastMove[0];
+ if (width < 10) width = 10;
+ if (left + width > parent.offsetWidth) {
+ width = parent.offsetWidth - left;
+ }
+ dialog.style.width = `${width}px`;
+ }
+ if (type === 'lm' || type === 'lb' || type === 'lt') {
+ width = parseFloat(dialog.style.width) - (currentMove[0] - pastMove[0]);
+ if (width < 10) width = 10;
+ if (left + width > parent.offsetWidth) {
+ width = parent.offsetWidth - left;
+ }
+ dialog.style.width = `${width}px`;
+ dialog.style.left = `${left}px`;
+ }
+ if (type === 'lb' || type === 'mb' || type === 'rb') {
+ height = parseFloat(dialog.style.height) + currentMove[1] - pastMove[1];
+ if (height < 10) height = 10;
+ if (height + top > parent.offsetHeight) {
+ height = parent.offsetHeight - top;
+ }
+ dialog.style.height = `${height}px`;
+ }
+ if (type === 'lt' || type === 'mt' || type === 'rt') {
+ height = parseFloat(dialog.style.height) - (currentMove[1] - pastMove[1]);
+ if (height < 10) height = 10;
+ if (height + top > parent.offsetHeight) {
+ height = parent.offsetHeight - top;
+ }
+ dialog.style.height = `${height}px`;
+ dialog.style.top = `${top}px`;
+ }
+ }
+ if (move) {
+ dialog.style.left = `${left}px`;
+ dialog.style.top = `${top}px`;
+ }
+
+ pastMove = currentMove;
+ };
+ const mouseUp = (e: MouseEvent) => {
+ window.removeEventListener('mousemove', mouseMove);
+ window.removeEventListener('mouseup', mouseUp);
+ window.removeEventListener('click', handleClick);
+ e.stopPropagation();
+ if (!move && !resize) return;
+ const dialog = ref.current;
+ if (!dialog) return;
+ move = false;
+ resize = false;
+ };
+
+ return (
+ <div className={styles.resizeDialog} ref={ref}>
+ <div className={styles.dialogMove} onMouseDown={mouseDown}>
+ <div className={`${styles.moveItem} ${styles.moveTop}`}></div>
+ <div className={`${styles.moveItem} ${styles.moveRight}`}></div>
+ <div className={`${styles.moveItem} ${styles.moveBottom}`}></div>
+ <div className={`${styles.moveItem} ${styles.moveLeft}`}></div>
+ </div>
+ <div className={styles.dialogResize} onMouseDown={resizeMouseDown} ref={resizeRef}>
+ <div data-type="lt" className={`${styles.resizeItem} ${styles.resizeLt}`}></div>
+ <div data-type="mt" className={`${styles.resizeItem} ${styles.resizeMt}`}></div>
+ <div data-type="lm" className={`${styles.resizeItem} ${styles.resizeLm}`}></div>
+ <div data-type="rm" className={`${styles.resizeItem} ${styles.resizeRm}`}></div>
+ <div data-type="rt" className={`${styles.resizeItem} ${styles.resizeRt}`}></div>
+ <div data-type="lb" className={`${styles.resizeItem} ${styles.resizeLb}`}></div>
+ <div data-type="mb" className={`${styles.resizeItem} ${styles.resizeMb}`}></div>
+ <div data-type="rb" className={`${styles.resizeItem} ${styles.resizeRb}`}></div>
+ </div>
+ <div className={styles.dialogContent}>{children}</div>
+ </div>
+ );
+};
+
+export class UniverResizeDialog implements ResizeDialogComponent {
+ render(): JSXComponent<BaseResizeDialogProps> {
+ return ResizeDialog;
+ }
+}
diff --git a/packages/base-ui/src/Components/SearchTree/SearchTree.tsx b/packages/base-ui/src/Components/SearchTree/SearchTree.tsx
index 35f37f2e92..597c53bf5c 100644
--- a/packages/base-ui/src/Components/SearchTree/SearchTree.tsx
+++ b/packages/base-ui/src/Components/SearchTree/SearchTree.tsx
@@ -1,4 +1,4 @@
-import { Component, createRef } from '../../Framework';
+import { Component, createRef } from 'preact';
import { JSXComponent } from '../../BaseComponent';
import { BaseSearchTreeProps, SearchTreeComponent } from '../../Interfaces';
import * as Icon from '../Icon';
@@ -18,6 +18,11 @@ interface IState {
class SearchTree extends Component<BaseSearchTreeProps, IState> {
input = createRef();
+ constructor(props: BaseSearchTreeProps) {
+ super();
+ this.initialize(props);
+ }
+
initialize(props: BaseSearchTreeProps) {
this.state = {
searchValue: '',
@@ -40,7 +45,7 @@ class SearchTree extends Component<BaseSearchTreeProps, IState> {
* @param event
*/
onInput(event: Event) {
- let searchValue = this.input.current.value;
+ const searchValue = this.input.current.value;
this.setState({
searchValue,
});
@@ -52,8 +57,8 @@ class SearchTree extends Component<BaseSearchTreeProps, IState> {
* @param val
*/
search(val: string) {
- let data = this.state.data;
- let dataClone = data.filter((item) => item.label.includes(val));
+ const data = this.state.data;
+ const dataClone = data.filter((item) => item.label.includes(val));
this.setState({
dataClone,
});
@@ -64,7 +69,7 @@ class SearchTree extends Component<BaseSearchTreeProps, IState> {
* @param index
*/
onClick(index: number) {
- let data = this.state.dataClone;
+ const data = this.state.dataClone;
data[index].checked = !data[index].checked;
this.setState({
dataClone: data,
@@ -75,7 +80,7 @@ class SearchTree extends Component<BaseSearchTreeProps, IState> {
* 全选
*/
clickAll() {
- let data = this.state.dataClone;
+ const data = this.state.dataClone;
data.forEach((item) => {
item.checked = true;
});
@@ -88,7 +93,7 @@ class SearchTree extends Component<BaseSearchTreeProps, IState> {
* 清除
*/
clickClean() {
- let data = this.state.dataClone;
+ const data = this.state.dataClone;
data.forEach((item) => {
item.checked = false;
});
@@ -101,7 +106,7 @@ class SearchTree extends Component<BaseSearchTreeProps, IState> {
* 反选
*/
clickInvert() {
- let data = this.state.dataClone;
+ const data = this.state.dataClone;
data.forEach((item) => {
item.checked = !item.checked;
});
diff --git a/packages/base-ui/src/Components/Select/Select.tsx b/packages/base-ui/src/Components/Select/Select.tsx
index 1fe12e99f6..b7ebc70f59 100644
--- a/packages/base-ui/src/Components/Select/Select.tsx
+++ b/packages/base-ui/src/Components/Select/Select.tsx
@@ -1,10 +1,12 @@
+import { ComponentChildren, createRef, RefObject } from 'preact';
+import { PureComponent } from 'preact/compat';
import { Icon } from '..';
import { CustomComponent } from '../../Common';
-import { ComponentChildren, createRef, RefObject, PureComponent } from '../../Framework';
import { BaseMenuItem } from '../../Interfaces';
import { Dropdown } from '../Dropdown';
import { Input } from '../Input';
import { BaseItemProps, Item } from '../Item/Item';
+import { CustomLabel } from '../CustomLabel';
import styles from './index.module.less';
export enum SelectTypes {
@@ -60,6 +62,11 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
onPressEnter: (...arg: any[]) => void;
+ constructor(props: BaseSelectProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
const { children = [], hideSelectedIcon } = this.props;
const list = this.resetMenu(children, hideSelectedIcon);
@@ -140,8 +147,8 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
const getLabel = (label: ComponentChildren) => {
if (label !== null) {
if (label === '') return;
- let index = children.findIndex((item) => label === item.label);
- let list = this.handleSelected(index < 0 ? null : index);
+ const index = children.findIndex((item) => label === item.label);
+ const list = this.handleSelected(index < 0 ? null : index);
this.setState({
content: label,
menu: list,
@@ -149,7 +156,7 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
} else {
let index = children.findIndex((item) => item.selected);
if (index < 0) index = 0;
- let list = this.handleSelected(index);
+ const list = this.handleSelected(index);
const item = children[index];
this.setState({
@@ -271,7 +278,9 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
return (
<div className={`${styles.selectSingle} ${className}`}>
<Dropdown onMainClick={onMainClick} tooltip={tooltip} menu={{ menu, onClick: this.onClick }} showArrow>
- <div>{this.getLabel(content)}</div>
+ <div>
+ <CustomLabel label={content} />
+ </div>
</Dropdown>
</div>
);
@@ -304,7 +313,9 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
return (
<div className={`${styles.selectDouble} ${className}`}>
<Dropdown onClick={onClick} tooltip={tooltip} menu={{ menu, onClick: this.onClick }} icon={<Icon.NextIcon />}>
- <div className={styles.selectLabel}>{this.getLabel(content)}</div>
+ <div className={styles.selectLabel}>
+ <CustomLabel label={content} />
+ </div>
</Dropdown>
</div>
);
@@ -317,7 +328,9 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
return (
<div className={`${styles.selectDouble} ${className}`}>
<Dropdown tooltip={tooltip} menu={{ menu, onClick: this.onClick }} showArrow>
- <div className={styles.selectLabel}>{this.getLabel(label)}</div>
+ <div className={styles.selectLabel}>
+ <CustomLabel label={content} />
+ </div>
</Dropdown>
</div>
);
@@ -329,7 +342,9 @@ export class Select extends PureComponent<BaseSelectProps, IState> {
return (
<div className={`${styles.selectDouble} ${className}`}>
<Dropdown tooltip={tooltip} onClick={onClick} menu={{ menu, onClick: this.onClick }} icon={<Icon.NextIcon />}>
- <div className={styles.selectLabel}>{this.getLabel(label)}</div>
+ <div className={styles.selectLabel}>
+ <CustomLabel label={label} />
+ </div>
</Dropdown>
</div>
);
diff --git a/packages/base-ui/src/Components/SiderModal/SiderModal.tsx b/packages/base-ui/src/Components/SiderModal/SiderModal.tsx
index 7d8925efa5..a15d0b5f67 100644
--- a/packages/base-ui/src/Components/SiderModal/SiderModal.tsx
+++ b/packages/base-ui/src/Components/SiderModal/SiderModal.tsx
@@ -1,4 +1,4 @@
-import { Component } from '../../Framework';
+import { Component } from 'preact';
import { BaseSiderModalProps } from '../../Interfaces';
import { Icon } from '../index';
import Style from './index.module.less';
@@ -9,6 +9,11 @@ type IState = {
};
class SiderModal extends Component<BaseSiderModalProps, IState> {
+ constructor(props: BaseSiderModalProps) {
+ super();
+ this.initialize(props);
+ }
+
initialize(props: BaseSiderModalProps) {
this.state = {
zIndex: props.zIndex ?? 0,
diff --git a/packages/base-ui/src/Components/Slider/Slider.tsx b/packages/base-ui/src/Components/Slider/Slider.tsx
index 12e1918772..0ee7dc9892 100644
--- a/packages/base-ui/src/Components/Slider/Slider.tsx
+++ b/packages/base-ui/src/Components/Slider/Slider.tsx
@@ -1,4 +1,4 @@
-import { Component, createRef } from '../../Framework';
+import { Component, createRef } from 'preact';
import { JSXComponent } from '../../BaseComponent';
import { BaseSliderRangeProps, BaseSliderSingleProps, SliderComponent } from '../../Interfaces';
import { randomId } from '../../Utils';
@@ -18,6 +18,11 @@ export class Slider extends Component<BaseSliderRangeProps | BaseSliderSinglePro
ref = createRef();
+ constructor(props: BaseSliderSingleProps | BaseSliderRangeProps) {
+ super();
+ this.initialize(props);
+ }
+
initialize(props: BaseSliderSingleProps | BaseSliderRangeProps) {
this.state = {
valuePrev: 0,
@@ -38,7 +43,7 @@ export class Slider extends Component<BaseSliderRangeProps | BaseSliderSinglePro
onClick = (index: number, e: MouseEvent) => {
const { min = 0, max = 100, step = 1 } = this.props;
const target = e.currentTarget as HTMLElement;
- let track = e.offsetX;
+ const track = e.offsetX;
const width = target.offsetWidth;
if (track < 0 || track > width) return;
let value = (track / this.width) * (max - min);
@@ -56,9 +61,9 @@ export class Slider extends Component<BaseSliderRangeProps | BaseSliderSinglePro
* 控制input样式
*/
changeInputValue = (index: number, value: number | string) => {
- let parentNode = this.ref.current;
- let input = parentNode.getElementsByTagName('input')[index];
- let id = input.id;
+ const parentNode = this.ref.current;
+ const input = parentNode.getElementsByTagName('input')[index];
+ const id = input.id;
parentNode.style.setProperty(`--${id}`, value);
if (!index) {
@@ -85,9 +90,9 @@ export class Slider extends Component<BaseSliderRangeProps | BaseSliderSinglePro
componentDidMount() {
const { min = 0, max = 100, range } = this.props;
- let diff = max - min;
+ const diff = max - min;
- let slider = this.ref.current;
+ const slider = this.ref.current;
this.width = slider.offsetWidth;
slider.style.cssText += `--${this.idPrev}: ${this.state.valuePrev}; --${this.idNext}: ${this.state.valueNext}`;
diff --git a/packages/base-ui/src/Components/Slot/Slot.tsx b/packages/base-ui/src/Components/Slot/Slot.tsx
index 33af23e1d8..725b0908cf 100644
--- a/packages/base-ui/src/Components/Slot/Slot.tsx
+++ b/packages/base-ui/src/Components/Slot/Slot.tsx
@@ -1,6 +1,7 @@
+import { Component } from 'preact';
import { BaseComponentProps } from '../../BaseComponent';
import { SlotComponent } from '../../Common/SlotManager';
-import { Component } from '../../Framework';
+import { AppContext } from '../../Common';
interface IState {
slotGroup: Map<string, SlotComponent>;
@@ -11,15 +12,22 @@ interface IProps extends BaseComponentProps {
}
export class Slot extends Component<IProps, IState> {
+ static override contextType = AppContext;
+
private _refs: any[] = [];
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
slotGroup: new Map(),
};
}
- componentDidMount(): void {
+ override componentDidMount(): void {
this.props.getComponent?.(this);
}
@@ -68,7 +76,7 @@ export class Slot extends Component<IProps, IState> {
slotGroup.forEach((item, index) => {
const Label = this.context.componentManager.get(item.component.name);
if (Label) {
- arr.push(<Label ref={(ref: any) => (this._refs[index as any] = ref)} {...item.component.props}></Label>);
+ arr.push(<Label ref={(ref: any) => (this._refs[index as any] = ref)} {...item.component.props} />);
}
});
return arr;
diff --git a/packages/base-ui/src/Components/Tabs/Tabs.tsx b/packages/base-ui/src/Components/Tabs/Tabs.tsx
index 2ff7d9fbdf..3c80f3ac8e 100644
--- a/packages/base-ui/src/Components/Tabs/Tabs.tsx
+++ b/packages/base-ui/src/Components/Tabs/Tabs.tsx
@@ -1,139 +1,140 @@
-import { JSXComponent } from '../../BaseComponent';
-import { JSX, PureComponent, toChildArray } from '../../Framework';
-import { BaseTabProps, BaseTabPaneProps, TabComponent, TabPaneComponent } from '../../Interfaces';
-import { randomId, joinClassNames } from '../../Utils';
-import styles from './index.module.less';
-
-// interface IProps {
-// className?: string;
-// style?: JSX.CSSProperties;
-// children?: any;
-// }
-
-// interface TabBaseProps extends IProps {
-// // type?: 'line' | 'card';
-// type?: 'card';
-// activeKey?: string;
-// // defaultActiveKey?: string;
-// // tabBarGutter?: number;
-// // tabBarStyle?: Record<string, string>;
-// // tabPosition?: 'left' | 'right' | 'top' | 'bottom';
-// // onChange?: (activeKey: string) => void;
-// onTabClick?: (activeKey: string, e: Event) => void;
-// }
-
-// interface TabPaneProps {
-// active?: boolean;
-// tab?: JSX.Element | string;
-// keys?: string;
-// id?: string;
-// className?: string;
-// style?: JSX.CSSProperties;
-// children?: ComponentChildren;
-// }
-
-type BaseTabState = {
- active: string;
-};
-
-export class Tab extends PureComponent<BaseTabProps> {
- state = {
- active: '',
- };
-
- setValue = (value: object, fn?: () => void) => {
- this.setState(
- (prevState) => ({
- ...value,
- }),
- fn
- );
- };
-
- componentWillMount() {
- this.setValue({ active: this.props.activeKey, children: this.props.children });
- }
-
- // generate tab navlist
- parseNavList = () => {
- const { active } = this.state;
- return toChildArray(this.props.children).map((node) => {
- const { tab, keys } = (node as JSX.Element).props;
- const id = `${randomId('tab')}-${keys}`;
- if (active === keys) {
- return (
- <div id={id} onClick={this.handleClick} className={joinClassNames(styles.tabsTab, styles.tabsTabActive)}>
- {tab}
- </div>
- );
- }
- return (
- <div id={id} onClick={this.handleClick} className={styles.tabsTab}>
- {tab}
- </div>
- );
- });
- };
-
- handleClick = (e: Event) => {
- const id = (e.target as HTMLElement).id;
- const index = id.lastIndexOf('-');
- const value = id.slice(index + 1);
-
- this.setValue({ active: value });
-
- this.props.onTabClick?.(value, e);
- };
-
- render(props: BaseTabProps, state: BaseTabState) {
- const { children, type = 'line', className = '' } = props;
- const classes = joinClassNames(
- styles.tabs,
- {
- [`${styles.tabs}-card`]: type === 'card',
- },
- className
- );
- // if (type == 'line') {
- // return <div></div>;
- // }
- return (
- <div className={classes}>
- <div className={styles.tabsNav}>
- <div className={styles.tabsNavWrap}>
- <div className={styles.tabsNavList}>{this.parseNavList()}</div>
- </div>
- </div>
- <div className={styles.tabsContent}>
- {children.map((item: JSX.Element) => (
- <TabPane keys={item.props.keys} active={item.props.keys === this.state.active}>
- {item.props.children}
- </TabPane>
- ))}
- </div>
- </div>
- );
- }
-}
-
-// tab content
-export const TabPane = (props: BaseTabPaneProps) => {
- const { id, keys, style, children, active } = props;
- return (
- <div id={id && `${id}-panel-${keys}`} role="tabpanel" style={{ ...style }} className={joinClassNames(styles.tabsPanel, active && styles.tabsPanelActive)}>
- {active && children}
- </div>
- );
-};
-
-export class UniverTab implements TabComponent {
- render(): JSXComponent<BaseTabProps> {
- return Tab;
- }
-}
-
-export class UniverTabPane implements TabPaneComponent {
- render(): JSXComponent<BaseTabProps> {
- return TabPane;
- }
-}
+import { JSX, toChildArray } from 'preact';
+import { PureComponent } from 'preact/compat';
+import { JSXComponent } from '../../BaseComponent';
+import { BaseTabProps, BaseTabPaneProps, TabComponent, TabPaneComponent } from '../../Interfaces';
+import { randomId, joinClassNames } from '../../Utils';
+import styles from './index.module.less';
+
+// interface IProps {
+// className?: string;
+// style?: JSX.CSSProperties;
+// children?: any;
+// }
+
+// interface TabBaseProps extends IProps {
+// // type?: 'line' | 'card';
+// type?: 'card';
+// activeKey?: string;
+// // defaultActiveKey?: string;
+// // tabBarGutter?: number;
+// // tabBarStyle?: Record<string, string>;
+// // tabPosition?: 'left' | 'right' | 'top' | 'bottom';
+// // onChange?: (activeKey: string) => void;
+// onTabClick?: (activeKey: string, e: Event) => void;
+// }
+
+// interface TabPaneProps {
+// active?: boolean;
+// tab?: JSX.Element | string;
+// keys?: string;
+// id?: string;
+// className?: string;
+// style?: JSX.CSSProperties;
+// children?: ComponentChildren;
+// }
+
+type BaseTabState = {
+ active: string;
+};
+
+export class Tab extends PureComponent<BaseTabProps> {
+ state = {
+ active: '',
+ };
+
+ setValue = (value: object, fn?: () => void) => {
+ this.setState(
+ (prevState) => ({
+ ...value,
+ }),
+ fn
+ );
+ };
+
+ componentWillMount() {
+ this.setValue({ active: this.props.activeKey, children: this.props.children });
+ }
+
+ // generate tab navlist
+ parseNavList = () => {
+ const { active } = this.state;
+ return toChildArray(this.props.children).map((node) => {
+ const { tab, keys } = (node as JSX.Element).props;
+ const id = `${randomId('tab')}-${keys}`;
+ if (active === keys) {
+ return (
+ <div id={id} onClick={this.handleClick} className={joinClassNames(styles.tabsTab, styles.tabsTabActive)}>
+ {tab}
+ </div>
+ );
+ }
+ return (
+ <div id={id} onClick={this.handleClick} className={styles.tabsTab}>
+ {tab}
+ </div>
+ );
+ });
+ };
+
+ handleClick = (e: Event) => {
+ const id = (e.target as HTMLElement).id;
+ const index = id.lastIndexOf('-');
+ const value = id.slice(index + 1);
+
+ this.setValue({ active: value });
+
+ this.props.onTabClick?.(value, e);
+ };
+
+ render(props: BaseTabProps, state: BaseTabState) {
+ const { children, type = 'line', className = '' } = props;
+ const classes = joinClassNames(
+ styles.tabs,
+ {
+ [`${styles.tabs}-card`]: type === 'card',
+ },
+ className
+ );
+ // if (type == 'line') {
+ // return <div></div>;
+ // }
+ return (
+ <div className={classes}>
+ <div className={styles.tabsNav}>
+ <div className={styles.tabsNavWrap}>
+ <div className={styles.tabsNavList}>{this.parseNavList()}</div>
+ </div>
+ </div>
+ <div className={styles.tabsContent}>
+ {children.map((item: JSX.Element) => (
+ <TabPane keys={item.props.keys} active={item.props.keys === this.state.active}>
+ {item.props.children}
+ </TabPane>
+ ))}
+ </div>
+ </div>
+ );
+ }
+}
+
+// tab content
+export const TabPane = (props: BaseTabPaneProps) => {
+ const { id, keys, style, children, active } = props;
+ return (
+ <div id={id && `${id}-panel-${keys}`} role="tabpanel" style={{ ...style }} className={joinClassNames(styles.tabsPanel, active && styles.tabsPanelActive)}>
+ {active && children}
+ </div>
+ );
+};
+
+export class UniverTab implements TabComponent {
+ render(): JSXComponent<BaseTabProps> {
+ return Tab;
+ }
+}
+
+export class UniverTabPane implements TabPaneComponent {
+ render(): JSXComponent<BaseTabProps> {
+ return TabPane;
+ }
+}
diff --git a/packages/base-ui/src/Components/Tooltip/Tooltip.tsx b/packages/base-ui/src/Components/Tooltip/Tooltip.tsx
index 6977756d9b..cdf5f9dca2 100644
--- a/packages/base-ui/src/Components/Tooltip/Tooltip.tsx
+++ b/packages/base-ui/src/Components/Tooltip/Tooltip.tsx
@@ -1,6 +1,9 @@
-import { Component, createRef } from '../../Framework';
+import { createRef } from 'preact';
+import { useState, useContext } from 'preact/hooks';
import { BaseTooltipProps } from '../../Interfaces';
import { joinClassNames } from '../../Utils';
+import { AppContext } from '../../Common';
+import { CustomLabel } from '../CustomLabel';
import style from './index.module.less';
@@ -28,45 +31,47 @@ const placementClassNames: { [index: string]: string } = {
right: style.right,
};
-export class Tooltip extends Component<BaseTooltipProps, TooltipState> {
- tooltip = createRef<HTMLDivElement>();
+export function Tooltip(props: BaseTooltipProps) {
+ const context = useContext(AppContext);
+ const tooltip = createRef<HTMLDivElement>();
+ const [state, setState] = useState<TooltipState>({
+ placement: props.placement || 'top',
+ placementClassName: joinClassNames(style.tooltipTitle, placementClassNames[props.placement || 'top']),
+ top: '',
+ left: '',
+ show: false,
+ });
- override initialize(props: BaseTooltipProps) {
- this.state = {
- placement: props.placement || 'top',
- placementClassName: joinClassNames(style.tooltipTitle, placementClassNames[props.placement || 'top']),
- top: '',
- left: '',
- show: false,
- };
- }
-
- handleMouseOver() {
- if (this.tooltip && this.tooltip.current) {
- const tooltipInfo = this.tooltip.current.getBoundingClientRect();
+ function handleMouseOver() {
+ if (tooltip?.current) {
+ const tooltipInfo = tooltip.current.getBoundingClientRect();
const top = tooltipInfo.height;
const left = tooltipInfo.width;
- if (this.state.placement === 'bottom') {
- this.setState({
+ if (state.placement === 'bottom') {
+ setState({
+ ...state,
top: top + 10,
left: left / 2,
show: true,
});
- } else if (this.state.placement === 'left') {
- this.setState({
+ } else if (state.placement === 'left') {
+ setState({
+ ...state,
top: top / 2,
left: left + 5,
show: true,
});
- } else if (this.state.placement === 'right') {
- this.setState({
+ } else if (state.placement === 'right') {
+ setState({
+ ...state,
top: top / 2,
left: -left - 10,
show: true,
});
} else {
- this.setState({
+ setState({
+ ...state,
top: -top - 20,
left: left / 2,
show: true,
@@ -75,33 +80,32 @@ export class Tooltip extends Component<BaseTooltipProps, TooltipState> {
}
}
- handleMouseLeave() {
- this.setState({
+ function handleMouseLeave() {
+ setState({
+ ...state,
show: false,
});
}
- render() {
- return (
- <div ref={this.tooltip} className={style.tooltipGroup} style={this.props.styles}>
- <div className={style.tooltipBody} onMouseEnter={this.handleMouseOver.bind(this)} onMouseLeave={this.handleMouseLeave.bind(this)}>
- {this.props.children}
- </div>
-
- {this.props.title ? (
- <span
- className={this.state.placementClassName}
- style={{
- top: `${this.state.top}px`,
- left: `${this.state.left}px`,
- display: `${this.state.show ? 'block' : 'none'}`,
- }}
- >
- {this.getLabel(this.props.title)}
- <span className={style.tooltipTriangle}></span>
- </span>
- ) : null}
+ return (
+ <div ref={tooltip} className={style.tooltipGroup} style={props.styles}>
+ <div className={style.tooltipBody} onMouseEnter={handleMouseOver} onMouseLeave={handleMouseLeave}>
+ {props.children}
</div>
- );
- }
+
+ {props.title ? (
+ <span
+ className={state.placementClassName}
+ style={{
+ top: `${state.top}px`,
+ left: `${state.left}px`,
+ display: `${state.show ? 'block' : 'none'}`,
+ }}
+ >
+ <CustomLabel label={props.title} />
+ <span className={style.tooltipTriangle}></span>
+ </span>
+ ) : null}
+ </div>
+ );
}
diff --git a/packages/base-ui/src/Components/index.ts b/packages/base-ui/src/Components/index.ts
index cd87e103dc..8744cffba5 100644
--- a/packages/base-ui/src/Components/index.ts
+++ b/packages/base-ui/src/Components/index.ts
@@ -6,6 +6,7 @@ import { Collapse, Panel } from './Collapse';
import { ColorPicker } from './ColorPicker';
import { ColorPickerCircleButton } from './ColorPickerCircleButton';
import { Container } from './Container';
+import { CustomLabel } from './CustomLabel';
// import { FormatModal } from './FormatModal';
import * as Icon from './Icon/index';
import { Input } from './Input';
@@ -43,6 +44,7 @@ export {
Header,
Footer,
Content,
+ CustomLabel,
Sider,
Tooltip,
Icon,
diff --git a/packages/base-ui/src/Framework/Preact.tsx b/packages/base-ui/src/Framework/Preact.tsx
deleted file mode 100644
index 37f985c794..0000000000
--- a/packages/base-ui/src/Framework/Preact.tsx
+++ /dev/null
@@ -1,94 +0,0 @@
-import {
- cloneElement,
- Component as PreactComponent,
- ComponentChildren,
- ComponentClass,
- createRef,
- JSX,
- RefObject,
- render,
- VNode,
- PreactContext,
- Ref,
- toChildArray,
- isValidElement,
-} from 'preact';
-import { ForwardFn, forwardRef, PureComponent as PreactPureComponent } from 'preact/compat';
-import { useRef, useState, useEffect } from 'preact/hooks';
-import { AppContext, AppContextValues, CustomComponent } from '../Common';
-
-/**
- * Wrap the framework for easy switching of the underlying framework
- */
-abstract class Component<P = {}, S = {}> extends PreactComponent<P, S> {
- static override contextType: PreactContext<Partial<AppContextValues>> = AppContext;
-
- constructor(props?: P) {
- super(props);
- this.initialize(props);
- }
-
- getLocale(name?: string) {
- if (!name) return;
- return this.context.localeService.t(name);
- }
-
- getLabel(label: string | CustomComponent | ComponentChildren) {
- if (typeof label === 'string') {
- return this.getLocale(label);
- }
- if (isValidElement(label)) {
- return label;
- }
- if (label) {
- const Label = this.context.componentManager.get((label as CustomComponent).name);
- if (Label) {
- const props = (label as CustomComponent).props ?? {};
- return <Label {...props}></Label>;
- }
- }
- return null;
- }
-
- protected initialize(props?: P): void {
- //
- }
-}
-
-abstract class PureComponent<P = {}, S = {}> extends PreactPureComponent<P, S> {
- static override contextType: PreactContext<Partial<AppContextValues>> = AppContext;
-
- constructor(props?: P) {
- super(props);
- this.initialize(props);
- }
-
- getLocale(name: string) {
- return this.context.localeService.t(name);
- }
-
- getLabel(label: string | CustomComponent | ComponentChildren) {
- if (typeof label === 'string') {
- return this.getLocale(label);
- }
- if (isValidElement(label)) {
- return label;
- }
- if (label) {
- const Label = this.context.componentManager.get((label as CustomComponent).name);
- if (Label) {
- const props = (label as CustomComponent).props ?? {};
- return <Label {...props}></Label>;
- }
- }
- return null;
- }
-
- protected initialize(props?: P): void {
- //
- }
-}
-
-export { render, Component, forwardRef, createRef, PureComponent, cloneElement, useRef, useState, useEffect, toChildArray };
-
-export type { ComponentChildren, ComponentClass, ForwardFn, JSX, RefObject, VNode, PreactContext, Ref };
diff --git a/packages/base-ui/src/Framework/React.ts b/packages/base-ui/src/Framework/React.ts
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/packages/base-ui/src/Framework/index.ts b/packages/base-ui/src/Framework/index.ts
deleted file mode 100644
index 4d435328eb..0000000000
--- a/packages/base-ui/src/Framework/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './Preact';
diff --git a/packages/base-ui/src/Interfaces/Collapse.ts b/packages/base-ui/src/Interfaces/Collapse.ts
index b1d0ea8eb4..7e14b2e3d6 100644
--- a/packages/base-ui/src/Interfaces/Collapse.ts
+++ b/packages/base-ui/src/Interfaces/Collapse.ts
@@ -1,5 +1,5 @@
+import { ComponentChildren } from 'preact';
import { BaseComponent, JSXComponent } from '../BaseComponent';
-import { ComponentChildren } from '../Framework';
export interface BasePanelProps {
children: ComponentChildren;
diff --git a/packages/base-ui/src/Interfaces/Container.ts b/packages/base-ui/src/Interfaces/Container.ts
index ec1802a45d..e4069c236f 100644
--- a/packages/base-ui/src/Interfaces/Container.ts
+++ b/packages/base-ui/src/Interfaces/Container.ts
@@ -1,5 +1,5 @@
+import { ComponentChildren } from 'preact';
import { BaseComponent, BaseComponentProps, JSXComponent } from '../BaseComponent';
-import { ComponentChildren } from '../Framework';
export interface BaseContainerProps extends BaseComponentProps {
children?: ComponentChildren;
diff --git a/packages/base-ui/src/Interfaces/CustomLabel.ts b/packages/base-ui/src/Interfaces/CustomLabel.ts
new file mode 100644
index 0000000000..276d4d1d24
--- /dev/null
+++ b/packages/base-ui/src/Interfaces/CustomLabel.ts
@@ -0,0 +1,11 @@
+import { ComponentChildren } from 'preact';
+import { BaseComponent, JSXComponent } from '../BaseComponent';
+import { CustomComponent } from '../Common';
+
+export interface BaseCustomLabelProps {
+ label: string | CustomComponent | ComponentChildren;
+}
+
+export interface CustomLabelComponent extends BaseComponent<BaseCustomLabelProps> {
+ render(): JSXComponent<BaseCustomLabelProps>;
+}
diff --git a/packages/base-ui/src/Interfaces/Menu.ts b/packages/base-ui/src/Interfaces/Menu.ts
index 02250648f1..e625d2a785 100644
--- a/packages/base-ui/src/Interfaces/Menu.ts
+++ b/packages/base-ui/src/Interfaces/Menu.ts
@@ -1,5 +1,5 @@
+import { ComponentChildren, JSX } from 'preact';
import { BaseComponent, JSXComponent } from '../BaseComponent';
-import { ComponentChildren, JSX } from '../Framework';
export interface BaseMenuItem {
className?: string;
diff --git a/packages/base-ui/src/Interfaces/Modal.ts b/packages/base-ui/src/Interfaces/Modal.ts
index 2bfc9e6b63..e1ee2a4a0f 100644
--- a/packages/base-ui/src/Interfaces/Modal.ts
+++ b/packages/base-ui/src/Interfaces/Modal.ts
@@ -1,44 +1,44 @@
-import { BaseComponent, JSXComponent } from '../BaseComponent';
-import { ComponentChildren } from '../Framework';
-
-export interface BaseModalProps {
- title?: string;
- width?: number;
- top?: number;
- style?: JSX.CSSProperties;
- children?: ComponentChildren;
- className?: string;
- group?: ModalButtonGroup[];
- maskClick?: () => void;
- /** 模态框是否可以拖动 */
- isDrag?: boolean;
-
- /** 模态框是否可见 */
- visible?: boolean;
-
- /** 是否显示遮罩 */
- mask?: boolean;
-
- /** 是否显示底部 */
- footer?: boolean;
-
- /** 点击遮罩层或右上角叉或取消按钮的回调 */
- onCancel?: (e: Event) => void;
- ref?: any;
-}
-
-export type ModalButtonGroup = {
- locale?: string;
- label?: string;
- onClick?: (e?: any) => void;
- type?: string;
-};
-
-export interface ModalProps extends BaseModalProps {
- show?: boolean;
- locale?: string;
-}
-
-export interface ModalComponent extends BaseComponent<BaseModalProps> {
- render(): JSXComponent<BaseModalProps>;
-}
+import { ComponentChildren } from 'preact';
+import { BaseComponent, JSXComponent } from '../BaseComponent';
+
+export interface BaseModalProps {
+ title?: string | JSX.Element;
+ width?: number;
+ top?: number;
+ style?: JSX.CSSProperties;
+ children?: ComponentChildren;
+ className?: string;
+ group?: ModalButtonGroup[];
+ maskClick?: () => void;
+ /** 模态框是否可以拖动 */
+ isDrag?: boolean;
+
+ /** 模态框是否可见 */
+ visible?: boolean;
+
+ /** 是否显示遮罩 */
+ mask?: boolean;
+
+ /** 是否显示底部 */
+ footer?: boolean;
+
+ /** 点击遮罩层或右上角叉或取消按钮的回调 */
+ onCancel?: (e: Event) => void;
+ ref?: any;
+}
+
+export type ModalButtonGroup = {
+ locale?: string;
+ label?: string;
+ onClick?: (e?: any) => void;
+ type?: string;
+};
+
+export interface ModalProps extends BaseModalProps {
+ show?: boolean;
+ locale?: string;
+}
+
+export interface ModalComponent extends BaseComponent<BaseModalProps> {
+ render(): JSXComponent<BaseModalProps>;
+}
diff --git a/packages/base-ui/src/Interfaces/Radio.ts b/packages/base-ui/src/Interfaces/Radio.ts
index 3f59551425..ebfac87652 100644
--- a/packages/base-ui/src/Interfaces/Radio.ts
+++ b/packages/base-ui/src/Interfaces/Radio.ts
@@ -1,5 +1,5 @@
+import { VNode } from 'preact';
import { BaseComponent, JSXComponent } from '../BaseComponent';
-import { VNode } from '../Framework';
export interface BaseRadioIProps {
value: string;
diff --git a/packages/base-ui/src/Interfaces/ResizeDialog.ts b/packages/base-ui/src/Interfaces/ResizeDialog.ts
index 651233d77f..b0aa831f27 100644
--- a/packages/base-ui/src/Interfaces/ResizeDialog.ts
+++ b/packages/base-ui/src/Interfaces/ResizeDialog.ts
@@ -1,5 +1,5 @@
+import { ComponentChildren } from 'preact';
import { BaseComponent, BaseComponentProps, JSXComponent } from '../BaseComponent';
-import { ComponentChildren } from '../Framework';
export interface BaseResizeDialogProps extends BaseComponentProps {
left: number;
diff --git a/packages/base-ui/src/Interfaces/RightMenu.ts b/packages/base-ui/src/Interfaces/RightMenu.ts
index 67ee1cd5c7..d2a0283abe 100644
--- a/packages/base-ui/src/Interfaces/RightMenu.ts
+++ b/packages/base-ui/src/Interfaces/RightMenu.ts
@@ -1,5 +1,5 @@
+import { ComponentChildren } from 'preact';
import { BaseComponent, BaseComponentProps, JSXComponent } from '../BaseComponent';
-import { ComponentChildren } from '../Framework';
export interface List {
content: ComponentChildren;
diff --git a/packages/base-ui/src/Interfaces/SiderModal.ts b/packages/base-ui/src/Interfaces/SiderModal.ts
index 8f377839dd..754cf0331e 100644
--- a/packages/base-ui/src/Interfaces/SiderModal.ts
+++ b/packages/base-ui/src/Interfaces/SiderModal.ts
@@ -1,18 +1,18 @@
-import { BaseComponent, JSXComponent } from '../BaseComponent';
-import { ComponentChildren, RefObject } from '../Framework';
-
-export interface BaseSiderModalProps {
- name: string;
- title: string | any;
- show?: boolean;
- children?: ComponentChildren;
- footer?: ComponentChildren;
- ref?: RefObject<HTMLElement>;
- className?: string;
- zIndex?: number;
- style?: JSX.CSSProperties;
-}
-
-export interface SiderModalComponent extends BaseComponent<BaseSiderModalProps> {
- render(): JSXComponent<BaseSiderModalProps>;
-}
+import { ComponentChildren, RefObject } from 'preact';
+import { BaseComponent, JSXComponent } from '../BaseComponent';
+
+export interface BaseSiderModalProps {
+ name: string;
+ title: string | any;
+ show?: boolean;
+ children?: ComponentChildren;
+ footer?: ComponentChildren;
+ ref?: RefObject<HTMLElement>;
+ className?: string;
+ zIndex?: number;
+ style?: JSX.CSSProperties;
+}
+
+export interface SiderModalComponent extends BaseComponent<BaseSiderModalProps> {
+ render(): JSXComponent<BaseSiderModalProps>;
+}
diff --git a/packages/base-ui/src/Interfaces/Slider.ts b/packages/base-ui/src/Interfaces/Slider.ts
index 2e2eb55bb4..cd63a3c93e 100644
--- a/packages/base-ui/src/Interfaces/Slider.ts
+++ b/packages/base-ui/src/Interfaces/Slider.ts
@@ -1,5 +1,5 @@
+import { RefObject } from 'preact';
import { BaseComponent, BaseComponentProps, JSXComponent } from '../BaseComponent';
-import { RefObject } from '../Framework';
interface SliderBaseProps {
min?: number;
diff --git a/packages/base-ui/src/Interfaces/Tooltip.ts b/packages/base-ui/src/Interfaces/Tooltip.ts
index 2f0f8b76cc..4ba8d529b8 100644
--- a/packages/base-ui/src/Interfaces/Tooltip.ts
+++ b/packages/base-ui/src/Interfaces/Tooltip.ts
@@ -1,5 +1,5 @@
+import { ComponentChildren } from 'preact';
import { BaseComponent, BaseComponentProps, JSXComponent } from '../BaseComponent';
-import { ComponentChildren } from '../Framework';
export interface BaseTooltipProps extends BaseComponentProps {
[index: number]: string;
diff --git a/packages/base-ui/src/Interfaces/index.ts b/packages/base-ui/src/Interfaces/index.ts
index 3be059c5dc..ab456f489c 100644
--- a/packages/base-ui/src/Interfaces/index.ts
+++ b/packages/base-ui/src/Interfaces/index.ts
@@ -6,6 +6,7 @@ export * from './ColorPicker';
export * from './ColorPickerCircleButton';
export * from './Container';
export * from './CountBar';
+export * from './CustomLabel';
export * from './Drag';
export * from './FilterSelect';
// export * from './FormatModal';
diff --git a/packages/base-ui/src/Utils/util.ts b/packages/base-ui/src/Utils/util.ts
index c53ebc5455..89b24c7746 100644
--- a/packages/base-ui/src/Utils/util.ts
+++ b/packages/base-ui/src/Utils/util.ts
@@ -1,250 +1,250 @@
-import { Component, RefObject } from '../Framework';
-
-/**
- * check element
- * @param element
- * @returns
- */
-export function isElement(element: any) {
- return element instanceof Element || element instanceof HTMLDocument;
-}
-
-export const isDOM =
- typeof HTMLElement === 'object'
- ? (obj: any) => obj instanceof HTMLElement
- : (obj: any) => obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';
-
-/**
- * DOM selector
- * @param {String} selector css selector
- * @param {String} context parent DOM
- */
-export function $$(selector: string, context?: HTMLElement | Document) {
- context = context || document;
- const elements = context.querySelectorAll(selector);
-
- return elements.length === 1 ? Array.prototype.slice.call(elements)[0] : Array.prototype.slice.call(elements);
-}
-
-/**
- * add classname
- * @param className
- * @param selector
- * @param context
- */
-export function addClass(className: string, selector: HTMLElement | string, context?: HTMLElement | Document) {
- if (typeof selector !== 'string') {
- selector.classList.add(className);
- return;
- }
-
- context = context || document;
- const elements = Array.prototype.slice.call(context.querySelectorAll(selector));
-
- elements.forEach((ele) => {
- ele.classList.add(className);
- });
-}
-/**
- * remove classname
- * @param className
- * @param selector
- * @param context
- */
-export function removeClass(className: string, selector: HTMLElement | string, context?: HTMLElement | Document) {
- if (typeof selector !== 'string') {
- selector.classList.remove(className);
- return;
- }
-
- context = context || document;
- const elements = Array.prototype.slice.call(context.querySelectorAll(selector));
-
- elements.forEach((ele) => {
- ele.classList.remove(className);
- });
-}
-/**
- * Return the first matched element by provided selector, traversing from current element up through its ancestors in the DOM tree.
- * Native - IE10+
- * reference: https://github.com/nefe/You-Dont-Need-jQuery#1.6
- * @param {Element} el
- * @param {string} selector
- */
-export function closest(el: any, selector: string) {
- const matchesSelector = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
-
- while (el) {
- if (matchesSelector.call(el, selector)) {
- return el;
- }
- el = el.parentElement;
- }
- return null;
-}
-
-/**
- * generate random id
- */
-export function randomId(prefix: string) {
- prefix = prefix ? `${prefix}-` : '';
- return (
- prefix +
- Math.random()
- .toString(36)
- .replace(/[^a-z]+/g, '')
- .substr(2, 10)
- );
-}
-
-/**
- * 获取第一级子元素
- * @param obj
- * @returns
- */
-export function getFirstChildren(obj: HTMLElement) {
- const objChild = [];
- const objs = obj.getElementsByTagName('*');
- for (let i = 0, j = objs.length; i < j; ++i) {
- if (objs[i].nodeType !== 1) {
- // alert(objs[i].nodeType);
- continue;
- }
- const temp: HTMLElement | any = objs[i].parentNode;
- if (temp && temp.nodeType === 1) {
- if (temp === obj) {
- objChild[objChild.length] = objs[i];
- }
- } else if (temp && temp.parentNode === obj) {
- objChild[objChild.length] = objs[i];
- }
- }
- return objChild;
-}
-/**
- * join className
- */
-export function joinClassNames(...args: any) {
- if (!args.length) return;
- let result = '';
- args.forEach((item: any) => {
- if (item instanceof Object) {
- for (const k in item) {
- if (item[k]) {
- result += ` ${k}`;
- }
- }
- } else {
- result += item ? ` ${item}` : '';
- }
- });
- return result;
-}
-
-export const getNodeIndex = (elm: any) => [...elm.parentNode.children].indexOf(elm);
-
-// 防抖
-export function debounce(fn: Function, time: number) {
- let timer: any = null;
- return (...arg: any) => {
- clearTimeout(timer);
- timer = setTimeout(() => {
- fn(...arg);
- }, time);
- };
-}
-
-export function selectTextContent(ele: Node) {
- if (window.getSelection) {
- // all browsers, except IE before version 9
- const range = document.createRange();
- const content = ele.firstChild;
- if (content) {
- range.setStart(content, 0);
- range.setEnd(content, (content as Text).length);
- if (range.startContainer && isInPage(range.startContainer)) {
- window.getSelection()?.removeAllRanges();
- window.getSelection()?.addRange(range);
- }
- }
- }
-}
-
-export function selectTextContentCross(sEle: Node, eEle: Node) {
- if (window.getSelection) {
- const range = document.createRange();
- const sContent = sEle.firstChild;
- const eContent = eEle.firstChild;
- if (sContent && eContent) {
- range.setStart(sContent, 0);
- range.setEnd(eContent, (eContent as Text).length);
- if (range.startContainer && isInPage(range.startContainer)) {
- window.getSelection()?.removeAllRanges();
- window.getSelection()?.addRange(range);
- }
- }
- }
-}
-
-export function isInPage(node: Node) {
- return node === document.body ? false : document.body.contains(node);
-}
-
-export function textTrim(x: string): string {
- if (x.length === 0) {
- // if (x == null || x.length == 0) {
- return x;
- }
- return x.replace(/^\s+|\s+$/gm, '');
-}
-
-export function getRefElement(ref: RefObject<HTMLElement | Component> | Component) {
- if (isDOM((ref as RefObject<HTMLElement>).current)) {
- return (ref as RefObject<HTMLElement>).current as HTMLElement;
- }
- const refCurrent = (ref as RefObject<Component>).current as Component<{}, {}>;
-
- if (refCurrent) {
- return refCurrent?.base as HTMLElement;
- }
- return (ref as Component).base as HTMLElement;
-}
-
-export function printableCharacter(keycode: number) {
- const valid =
- (keycode > 47 && keycode < 58) || // number keys
- keycode === 32 ||
- keycode === 13 || // spacebar & return key(s) (if you want to allow carriage returns)
- (keycode > 64 && keycode < 91) || // letter keys
- (keycode > 95 && keycode < 112) || // numpad keys
- (keycode > 185 && keycode < 193) || // ;=,-./` (in order)
- (keycode > 218 && keycode < 223); // [\]' (in order)
-
- return valid;
-}
-
-export function xssDeal(str: string) {
- if (typeof str !== 'string') return str;
- return str.replace(/<script>/g, '&lt;script&gt;').replace(/<\/script>/, '&lt;/script&gt;');
-}
-
-export function setLastCaretPosition(dom: HTMLElement) {
- const range = window.getSelection();
- range && range.selectAllChildren(dom);
- range && range.collapseToEnd();
-}
-
-export function isCtrlPressed(event: KeyboardEvent) {
- let isCtrl = false;
-
- // Determine the corresponding key code of the Ctrl key according to the operating system
- if (navigator.userAgent.indexOf('Mac') !== -1) {
- // Mac
- isCtrl = event.metaKey;
- } else {
- // Windows
- isCtrl = event.ctrlKey;
- }
-
- return isCtrl;
-}
+import { Component, RefObject } from 'preact';
+
+/**
+ * check element
+ * @param element
+ * @returns
+ */
+export function isElement(element: any) {
+ return element instanceof Element || element instanceof HTMLDocument;
+}
+
+export const isDOM =
+ typeof HTMLElement === 'object'
+ ? (obj: any) => obj instanceof HTMLElement
+ : (obj: any) => obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';
+
+/**
+ * DOM selector
+ * @param {String} selector css selector
+ * @param {String} context parent DOM
+ */
+export function $$(selector: string, context?: HTMLElement | Document) {
+ context = context || document;
+ const elements = context.querySelectorAll(selector);
+
+ return elements.length === 1 ? Array.prototype.slice.call(elements)[0] : Array.prototype.slice.call(elements);
+}
+
+/**
+ * add classname
+ * @param className
+ * @param selector
+ * @param context
+ */
+export function addClass(className: string, selector: HTMLElement | string, context?: HTMLElement | Document) {
+ if (typeof selector !== 'string') {
+ selector.classList.add(className);
+ return;
+ }
+
+ context = context || document;
+ const elements = Array.prototype.slice.call(context.querySelectorAll(selector));
+
+ elements.forEach((ele) => {
+ ele.classList.add(className);
+ });
+}
+/**
+ * remove classname
+ * @param className
+ * @param selector
+ * @param context
+ */
+export function removeClass(className: string, selector: HTMLElement | string, context?: HTMLElement | Document) {
+ if (typeof selector !== 'string') {
+ selector.classList.remove(className);
+ return;
+ }
+
+ context = context || document;
+ const elements = Array.prototype.slice.call(context.querySelectorAll(selector));
+
+ elements.forEach((ele) => {
+ ele.classList.remove(className);
+ });
+}
+/**
+ * Return the first matched element by provided selector, traversing from current element up through its ancestors in the DOM tree.
+ * Native - IE10+
+ * reference: https://github.com/nefe/You-Dont-Need-jQuery#1.6
+ * @param {Element} el
+ * @param {string} selector
+ */
+export function closest(el: any, selector: string) {
+ const matchesSelector = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
+
+ while (el) {
+ if (matchesSelector.call(el, selector)) {
+ return el;
+ }
+ el = el.parentElement;
+ }
+ return null;
+}
+
+/**
+ * generate random id
+ */
+export function randomId(prefix: string) {
+ prefix = prefix ? `${prefix}-` : '';
+ return (
+ prefix +
+ Math.random()
+ .toString(36)
+ .replace(/[^a-z]+/g, '')
+ .substr(2, 10)
+ );
+}
+
+/**
+ * 获取第一级子元素
+ * @param obj
+ * @returns
+ */
+export function getFirstChildren(obj: HTMLElement) {
+ const objChild = [];
+ const objs = obj.getElementsByTagName('*');
+ for (let i = 0, j = objs.length; i < j; ++i) {
+ if (objs[i].nodeType !== 1) {
+ // alert(objs[i].nodeType);
+ continue;
+ }
+ const temp: HTMLElement | any = objs[i].parentNode;
+ if (temp && temp.nodeType === 1) {
+ if (temp === obj) {
+ objChild[objChild.length] = objs[i];
+ }
+ } else if (temp && temp.parentNode === obj) {
+ objChild[objChild.length] = objs[i];
+ }
+ }
+ return objChild;
+}
+/**
+ * join className
+ */
+export function joinClassNames(...args: any) {
+ if (!args.length) return;
+ let result = '';
+ args.forEach((item: any) => {
+ if (item instanceof Object) {
+ for (const k in item) {
+ if (item[k]) {
+ result += ` ${k}`;
+ }
+ }
+ } else {
+ result += item ? ` ${item}` : '';
+ }
+ });
+ return result;
+}
+
+export const getNodeIndex = (elm: any) => [...elm.parentNode.children].indexOf(elm);
+
+// 防抖
+export function debounce(fn: Function, time: number) {
+ let timer: any = null;
+ return (...arg: any) => {
+ clearTimeout(timer);
+ timer = setTimeout(() => {
+ fn(...arg);
+ }, time);
+ };
+}
+
+export function selectTextContent(ele: Node) {
+ if (window.getSelection) {
+ // all browsers, except IE before version 9
+ const range = document.createRange();
+ const content = ele.firstChild;
+ if (content) {
+ range.setStart(content, 0);
+ range.setEnd(content, (content as Text).length);
+ if (range.startContainer && isInPage(range.startContainer)) {
+ window.getSelection()?.removeAllRanges();
+ window.getSelection()?.addRange(range);
+ }
+ }
+ }
+}
+
+export function selectTextContentCross(sEle: Node, eEle: Node) {
+ if (window.getSelection) {
+ const range = document.createRange();
+ const sContent = sEle.firstChild;
+ const eContent = eEle.firstChild;
+ if (sContent && eContent) {
+ range.setStart(sContent, 0);
+ range.setEnd(eContent, (eContent as Text).length);
+ if (range.startContainer && isInPage(range.startContainer)) {
+ window.getSelection()?.removeAllRanges();
+ window.getSelection()?.addRange(range);
+ }
+ }
+ }
+}
+
+export function isInPage(node: Node) {
+ return node === document.body ? false : document.body.contains(node);
+}
+
+export function textTrim(x: string): string {
+ if (x.length === 0) {
+ // if (x == null || x.length == 0) {
+ return x;
+ }
+ return x.replace(/^\s+|\s+$/gm, '');
+}
+
+export function getRefElement(ref: RefObject<HTMLElement | Component> | Component) {
+ if (isDOM((ref as RefObject<HTMLElement>).current)) {
+ return (ref as RefObject<HTMLElement>).current as HTMLElement;
+ }
+ const refCurrent = (ref as RefObject<Component>).current as Component<{}, {}>;
+
+ if (refCurrent) {
+ return refCurrent?.base as HTMLElement;
+ }
+ return (ref as Component).base as HTMLElement;
+}
+
+export function printableCharacter(keycode: number) {
+ const valid =
+ (keycode > 47 && keycode < 58) || // number keys
+ keycode === 32 ||
+ keycode === 13 || // spacebar & return key(s) (if you want to allow carriage returns)
+ (keycode > 64 && keycode < 91) || // letter keys
+ (keycode > 95 && keycode < 112) || // numpad keys
+ (keycode > 185 && keycode < 193) || // ;=,-./` (in order)
+ (keycode > 218 && keycode < 223); // [\]' (in order)
+
+ return valid;
+}
+
+export function xssDeal(str: string) {
+ if (typeof str !== 'string') return str;
+ return str.replace(/<script>/g, '&lt;script&gt;').replace(/<\/script>/, '&lt;/script&gt;');
+}
+
+export function setLastCaretPosition(dom: HTMLElement) {
+ const range = window.getSelection();
+ range && range.selectAllChildren(dom);
+ range && range.collapseToEnd();
+}
+
+export function isCtrlPressed(event: KeyboardEvent) {
+ let isCtrl = false;
+
+ // Determine the corresponding key code of the Ctrl key according to the operating system
+ if (navigator.userAgent.indexOf('Mac') !== -1) {
+ // Mac
+ isCtrl = event.metaKey;
+ } else {
+ // Windows
+ isCtrl = event.ctrlKey;
+ }
+
+ return isCtrl;
+}
diff --git a/packages/base-ui/src/index.ts b/packages/base-ui/src/index.ts
index b4aa35e848..e8c65d7b76 100644
--- a/packages/base-ui/src/index.ts
+++ b/packages/base-ui/src/index.ts
@@ -6,7 +6,6 @@ export * from './Utils';
export * from './Helpers';
export * from './Components';
export * from './BaseComponent';
-export * from './Framework';
export * from './UIPlugin';
export { IMenuService, IMenuItem, MenuPosition, DesktopMenuService } from './services/menu/menu.service';
diff --git a/packages/sheets-plugin-filter/src/UI/FilterButton.tsx b/packages/sheets-plugin-filter/src/UI/FilterButton.tsx
index 5eb75abd81..b163fcdf27 100644
--- a/packages/sheets-plugin-filter/src/UI/FilterButton.tsx
+++ b/packages/sheets-plugin-filter/src/UI/FilterButton.tsx
@@ -1,4 +1,5 @@
-import { BaseSelectProps, Component, Icon, Select } from '@univerjs/base-ui';
+import { BaseSelectProps, Icon, Select } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { Nullable, Observer, Workbook } from '@univerjs/core';
import { IProps } from '../IData';
import { FilterPlugin } from '../FilterPlugin';
@@ -12,7 +13,12 @@ interface IState {
export class FilterButton extends Component<IProps, IState> {
protected _localeObserver: Nullable<Observer<Workbook>>;
- override initialize(props: IProps) {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize(props);
+ }
+
+ initialize(props: IProps) {
this.state = {
filter: {
locale: 'filter',
diff --git a/packages/sheets-plugin-find/src/View/UI/FindModal.tsx b/packages/sheets-plugin-find/src/View/UI/FindModal.tsx
index aca6773b20..faa7efdbdf 100644
--- a/packages/sheets-plugin-find/src/View/UI/FindModal.tsx
+++ b/packages/sheets-plugin-find/src/View/UI/FindModal.tsx
@@ -1,4 +1,5 @@
-import { BaseCheckboxGroupOptions, BaseComponentProps, Button, CellRange, CheckboxGroup, Component, createRef, Icon, Input, Modal, Select } from '@univerjs/base-ui';
+import { BaseCheckboxGroupOptions, BaseComponentProps, Button, CellRange, CheckboxGroup, Icon, Input, Modal, Select, CustomLabel } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import { BaseItemProps } from '@univerjs/base-ui/src/Components/Item/Item';
import styles from './index.module.less';
@@ -102,7 +103,7 @@ export class FindModal extends Component<IProps, IState> {
getMatchGroup() {
const arr: BaseCheckboxGroupOptions[] = JSON.parse(JSON.stringify(this._matchGroup));
arr.forEach((element: BaseCheckboxGroupOptions) => {
- element.label = this.getLocale(element.label as string);
+ element.label = <CustomLabel label={element.label} />;
});
return arr;
}
@@ -111,7 +112,7 @@ export class FindModal extends Component<IProps, IState> {
getSelect() {
const arr: BaseItemProps[] = JSON.parse(JSON.stringify(this._select));
arr.forEach((element: BaseCheckboxGroupOptions) => {
- element.label = this.getLocale(element.label as string);
+ element.label = <CustomLabel label={element.label} />;
});
return arr;
}
@@ -192,11 +193,15 @@ export class FindModal extends Component<IProps, IState> {
isDrag
footer={false}
mask={false}
- title={this.getLocale(hideAdvanced ? 'find.find' : 'find.findLabel')}
+ title={<CustomLabel label={hideAdvanced ? 'find.find' : 'find.findLabel'} />}
visible={show}
>
<div className={styles.box}>
- {hideAdvanced ? null : <span>{this.getLocale('find.find')}</span>}
+ {hideAdvanced ? null : (
+ <span>
+ <CustomLabel label="find.find" />
+ </span>
+ )}
<Input ref={this._searchRef} onPressEnter={this.findNext.bind(this)}></Input>
{count ? (
<div className={styles.count}>
@@ -212,17 +217,21 @@ export class FindModal extends Component<IProps, IState> {
</div>
{hideAdvanced ? (
<p style={{ display: hideAdvanced ? 'block' : 'none' }} onClick={() => this.handleHideAdvanced(false)}>
- {this.getLocale('find.replace')}/{this.getLocale('find.advanced')}
+ <CustomLabel label="find.replace" />/<CustomLabel label="find.advanced" />
<Icon.Format.NextIcon />
</p>
) : (
<>
<div className={styles.box}>
- <span>{this.getLocale('find.replaceWith')}</span>
+ <span>
+ <CustomLabel label="find.replaceWith" />
+ </span>
<Input ref={this._replaceRef}></Input>
</div>
<div className={styles.box}>
- <span>{this.getLocale('find.search')}</span>
+ <span>
+ <CustomLabel label="find.search" />
+ </span>
<Select onClick={this.selectSearch.bind(this)} type={0} children={this.getSelect()}></Select>
{showRange ? <CellRange /> : null}
</div>
@@ -231,10 +240,18 @@ export class FindModal extends Component<IProps, IState> {
<CheckboxGroup options={this.getMatchGroup()} onChange={this.handleChange.bind(this)}></CheckboxGroup>
</div>
<div className={styles.buttonGroup}>
- <Button type="primary">{this.getLocale('button.cancel')}</Button>
- <Button onClick={this.replaceAll.bind(this)}>{this.getLocale('find.allReplaceBtn')}</Button>
- <Button onClick={this.replaceText.bind(this)}>{this.getLocale('find.replace')}</Button>
- <Button onClick={this.findNext.bind(this)}>{this.getLocale('find.find')}</Button>
+ <Button type="primary">
+ <CustomLabel label="button.cancel" />
+ </Button>
+ <Button onClick={this.replaceAll.bind(this)}>
+ <CustomLabel label="find.allReplaceBtn" />
+ </Button>
+ <Button onClick={this.replaceText.bind(this)}>
+ <CustomLabel label="find.replace" />
+ </Button>
+ <Button onClick={this.findNext.bind(this)}>
+ <CustomLabel label="find.find" />
+ </Button>
</div>
</>
)}
diff --git a/packages/sheets-plugin-find/src/View/UI/LocationContent.tsx b/packages/sheets-plugin-find/src/View/UI/LocationContent.tsx
index 4a81f76c97..0e47dc4888 100644
--- a/packages/sheets-plugin-find/src/View/UI/LocationContent.tsx
+++ b/packages/sheets-plugin-find/src/View/UI/LocationContent.tsx
@@ -1,4 +1,4 @@
-import { Component } from '@univerjs/base-ui';
+import { Component } from 'preact';
type LocationProps = {
config: any;
diff --git a/packages/sheets-plugin-formula/src/View/UI/FormulaLabel.tsx b/packages/sheets-plugin-formula/src/View/UI/FormulaLabel.tsx
index 47f83c8c77..c1f872c819 100644
--- a/packages/sheets-plugin-formula/src/View/UI/FormulaLabel.tsx
+++ b/packages/sheets-plugin-formula/src/View/UI/FormulaLabel.tsx
@@ -1,4 +1,5 @@
-import { Component, Icon } from '@univerjs/base-ui';
+import { Icon } from '@univerjs/base-ui';
+import { Component } from 'preact';
interface IProps {
label: string;
@@ -7,12 +8,6 @@ interface IProps {
export class FormulaLabel extends Component<IProps> {
// private _render: BaseComponentRender;
- override initialize() {
- // super();
- // const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;
- // this._render = component.getComponentRender();
- }
-
render() {
// const SumIcon = this._render.renderFunction('SumIcon');
const { label } = this.props;
diff --git a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx
index 9e5639c1cd..7fea85842c 100644
--- a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx
+++ b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx
@@ -1,137 +1,150 @@
-import { BaseComponentProps, Component, createRef } from '@univerjs/base-ui';
-import { IKeyValue } from '@univerjs/core';
-import { FormulaParamType, FormulaType } from '../../../Basics';
-import styles from './index.module.less';
-
-interface IProps extends BaseComponentProps {
- funName: any;
- paramIndex: number;
-}
-
-interface IState {
- activeIndex: number;
- functionInfo: FormulaType;
- helpFormulaActive: boolean;
- position: {
- left: number;
- top: number;
- };
-}
-
-export class HelpFunction extends Component<IProps, IState> {
- contentRef = createRef<HTMLDivElement>();
-
- override initialize() {
- this.state = {
- activeIndex: 0,
- functionInfo: {},
- helpFormulaActive: false,
- position: {
- left: 0,
- top: 0,
- },
- };
- }
-
- override componentWillMount() {}
-
- override componentDidMount() {
- this.props.getComponent?.(this);
- }
-
- updateState(helpFormulaActive: boolean, activeIndex: number = 0, functionInfo: FormulaType = {}, position = { left: 0, top: 0 }, cb?: () => void) {
- this.setState(
- {
- helpFormulaActive,
- functionInfo,
- activeIndex,
- position,
- },
- cb
- );
- }
-
- getState() {
- return this.state;
- }
-
- getContentRef() {
- return this.contentRef;
- }
-
- render(props: IProps, state: IState) {
- const { activeIndex, functionInfo, helpFormulaActive, position } = state;
-
- return (
- <div
- className={styles.helpFunction}
- style={{ display: helpFormulaActive ? 'block' : 'none', position: 'absolute', left: `${position.left}px`, top: `${position.top}px` }}
- ref={this.contentRef}
- >
- <div class={styles.helpFunctionTitle}>
- <Help title={functionInfo.n} value={functionInfo.p} type="name" active={activeIndex} />
- </div>
- <div className={styles.helpFunctionContent}>
- <div>{this.getLocale('formula.formulaMore.helpExample')}</div>
- <Help title={functionInfo.n} value={functionInfo.p} type="example" active={activeIndex} />
- <Params title={this.getLocale('formula.formulaMore.helpAbstract')} value={this.getLocale(functionInfo.d)} />
- <>
- {functionInfo &&
- functionInfo.p &&
- functionInfo.p.map((item: FormulaParamType, i: number) => (
- <Params
- className={activeIndex === i ? styles.helpFunctionActive : ''}
- title={this.getLocale(item.name)}
- value={this.getLocale(item.detail)}
- active={activeIndex}
- />
- ))}
- </>
- </div>
- </div>
- );
- }
-}
-
-interface IParamsProps {
- className?: string;
- title?: string;
- value?: string;
- active?: number;
-}
-
-interface IParamsState {}
-
-const Params = (props: IParamsProps) => (
- <div className={`${styles.helpFunctionContentParams} ${props.className}`}>
- <div className={styles.helpFunctionContentTitle}>{props.title}</div>
- <div className={styles.helpFunctionContentDetail}>{props.value}</div>
- </div>
-);
-
-interface IHelpProps {
- title?: string;
- value?: FormulaParamType[];
- type: string;
- active: number;
-}
-
-interface IHelpState {}
-
-class Help extends Component<IHelpProps, IHelpState> {
- render(props: IHelpProps, state: IHelpState) {
- return (
- <div>
- <span>
- {props.title}
- {'('}
- </span>
- {props.value &&
- props.value.map((item: FormulaParamType, i: number) => (
- <span className={props.active === i ? styles.helpFunctionActive : ''}>{this.getLocale((item as IKeyValue)[`${props.type}`])},</span>
- ))}
- <span>{')'}</span>
- </div>
- );
- }
-}
+import { BaseComponentProps, CustomLabel } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
+import { IKeyValue } from '@univerjs/core';
+import { FormulaParamType, FormulaType } from '../../../Basics';
+import styles from './index.module.less';
+
+interface IProps extends BaseComponentProps {
+ funName: any;
+ paramIndex: number;
+}
+
+interface IState {
+ activeIndex: number;
+ functionInfo: FormulaType;
+ helpFormulaActive: boolean;
+ position: {
+ left: number;
+ top: number;
+ };
+}
+
+export class HelpFunction extends Component<IProps, IState> {
+ contentRef = createRef<HTMLDivElement>();
+
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
+ initialize() {
+ this.state = {
+ activeIndex: 0,
+ functionInfo: {},
+ helpFormulaActive: false,
+ position: {
+ left: 0,
+ top: 0,
+ },
+ };
+ }
+
+ override componentWillMount() {}
+
+ override componentDidMount() {
+ this.props.getComponent?.(this);
+ }
+
+ updateState(helpFormulaActive: boolean, activeIndex: number = 0, functionInfo: FormulaType = {}, position = { left: 0, top: 0 }, cb?: () => void) {
+ this.setState(
+ {
+ helpFormulaActive,
+ functionInfo,
+ activeIndex,
+ position,
+ },
+ cb
+ );
+ }
+
+ getState() {
+ return this.state;
+ }
+
+ getContentRef() {
+ return this.contentRef;
+ }
+
+ render(props: IProps, state: IState) {
+ const { activeIndex, functionInfo, helpFormulaActive, position } = state;
+
+ return (
+ <div
+ className={styles.helpFunction}
+ style={{ display: helpFormulaActive ? 'block' : 'none', position: 'absolute', left: `${position.left}px`, top: `${position.top}px` }}
+ ref={this.contentRef}
+ >
+ <div class={styles.helpFunctionTitle}>
+ <Help title={functionInfo.n} value={functionInfo.p} type="name" active={activeIndex} />
+ </div>
+ <div className={styles.helpFunctionContent}>
+ <div>
+ <CustomLabel label="formula.formulaMore.helpExample" />
+ </div>
+ <Help title={functionInfo.n} value={functionInfo.p} type="example" active={activeIndex} />
+ <Params
+ title={(<CustomLabel label="formula.formulaMore.helpAbstract" />) as unknown as string}
+ value={(<CustomLabel label={functionInfo.d} />) as unknown as string}
+ />
+ <>
+ {functionInfo &&
+ functionInfo.p &&
+ functionInfo.p.map((item: FormulaParamType, i: number) => (
+ <Params
+ className={activeIndex === i ? styles.helpFunctionActive : ''}
+ title={(<CustomLabel label={item.name} />) as unknown as string}
+ value={(<CustomLabel label={item.detail} />) as unknown as string}
+ active={activeIndex}
+ />
+ ))}
+ </>
+ </div>
+ </div>
+ );
+ }
+}
+
+interface IParamsProps {
+ className?: string;
+ title?: string;
+ value?: string;
+ active?: number;
+}
+
+interface IParamsState {}
+
+const Params = (props: IParamsProps) => (
+ <div className={`${styles.helpFunctionContentParams} ${props.className}`}>
+ <div className={styles.helpFunctionContentTitle}>{props.title}</div>
+ <div className={styles.helpFunctionContentDetail}>{props.value}</div>
+ </div>
+);
+
+interface IHelpProps {
+ title?: string;
+ value?: FormulaParamType[];
+ type: string;
+ active: number;
+}
+
+interface IHelpState {}
+
+class Help extends Component<IHelpProps, IHelpState> {
+ render(props: IHelpProps, state: IHelpState) {
+ return (
+ <div>
+ <span>
+ {props.title}
+ {'('}
+ </span>
+ {props.value &&
+ props.value.map((item: FormulaParamType, i: number) => (
+ <span className={props.active === i ? styles.helpFunctionActive : ''}>
+ <CustomLabel label={(item as IKeyValue)[`${props.type}`]} />,
+ </span>
+ ))}
+ <span>{')'}</span>
+ </div>
+ );
+ }
+}
diff --git a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx
index e0c117f7f1..bdf05e0917 100644
--- a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx
+++ b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx
@@ -1,84 +1,92 @@
-import { BaseComponentProps, Component, createRef } from '@univerjs/base-ui';
-import { IKeyValue } from '@univerjs/core';
-import styles from './index.module.less';
-
-interface IProps extends BaseComponentProps {}
-
-interface IState {
- lang: string;
- locale: [];
- formulaValue: string;
- formula: IKeyValue[];
- functionList: any;
- selectIndex: number;
- searchActive: boolean;
- position: {
- left: number;
- top: number;
- };
-}
-
-export class SearchFunction extends Component<IProps, IState> {
- contentRef = createRef<HTMLUListElement>();
-
- override initialize() {
- this.state = {
- lang: '',
- locale: [],
- formulaValue: '',
- functionList: [],
- selectIndex: 0,
- formula: [],
- searchActive: false,
- position: {
- left: 0,
- top: 0,
- },
- };
- }
-
- override componentDidMount() {
- this.props.getComponent?.(this);
- }
-
- override componentWillUpdate(nextProps: any) {}
-
- onKeyDown(event: Event) {}
-
- getContentRef() {
- return this.contentRef;
- }
-
- /**
- *
- * @param searchActive
- * @param formula
- * @param selectIndex
- */
- updateState(searchActive: boolean, formula: IKeyValue[] = [], selectIndex: number = 0, position = { left: 0, top: 0 }, cb?: () => void) {
- this.setState({ searchActive, formula, selectIndex, position }, cb);
- }
-
- getState() {
- return this.state;
- }
-
- render(props: IProps, state: IState) {
- const { selectIndex, formula, searchActive, position } = state;
- return (
- <ul
- className={styles.searchFunction}
- onKeyDown={this.onKeyDown.bind(this)}
- style={{ display: searchActive ? 'block' : 'none', position: 'absolute', left: `${position.left}px`, top: `${position.top}px` }}
- ref={this.contentRef}
- >
- {formula.map((item: any, i: number) => (
- <li className={selectIndex === i ? styles.searchFunctionActive : ''}>
- <div className={styles.formulaName}>{item.n}</div>
- <div className={styles.formulaDetail}>{this.getLocale(item.d)}</div>
- </li>
- ))}
- </ul>
- );
- }
-}
+import { BaseComponentProps, CustomLabel } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
+import { IKeyValue } from '@univerjs/core';
+import styles from './index.module.less';
+
+interface IProps extends BaseComponentProps {}
+
+interface IState {
+ lang: string;
+ locale: [];
+ formulaValue: string;
+ formula: IKeyValue[];
+ functionList: any;
+ selectIndex: number;
+ searchActive: boolean;
+ position: {
+ left: number;
+ top: number;
+ };
+}
+
+export class SearchFunction extends Component<IProps, IState> {
+ contentRef = createRef<HTMLUListElement>();
+
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
+ initialize() {
+ this.state = {
+ lang: '',
+ locale: [],
+ formulaValue: '',
+ functionList: [],
+ selectIndex: 0,
+ formula: [],
+ searchActive: false,
+ position: {
+ left: 0,
+ top: 0,
+ },
+ };
+ }
+
+ override componentDidMount() {
+ this.props.getComponent?.(this);
+ }
+
+ override componentWillUpdate(nextProps: any) {}
+
+ onKeyDown(event: Event) {}
+
+ getContentRef() {
+ return this.contentRef;
+ }
+
+ /**
+ *
+ * @param searchActive
+ * @param formula
+ * @param selectIndex
+ */
+ updateState(searchActive: boolean, formula: IKeyValue[] = [], selectIndex: number = 0, position = { left: 0, top: 0 }, cb?: () => void) {
+ this.setState({ searchActive, formula, selectIndex, position }, cb);
+ }
+
+ getState() {
+ return this.state;
+ }
+
+ render(props: IProps, state: IState) {
+ const { selectIndex, formula, searchActive, position } = state;
+ return (
+ <ul
+ className={styles.searchFunction}
+ onKeyDown={this.onKeyDown.bind(this)}
+ style={{ display: searchActive ? 'block' : 'none', position: 'absolute', left: `${position.left}px`, top: `${position.top}px` }}
+ ref={this.contentRef}
+ >
+ {formula.map((item: any, i: number) => (
+ <li className={selectIndex === i ? styles.searchFunctionActive : ''}>
+ <div className={styles.formulaName}>{item.n}</div>
+ <div className={styles.formulaDetail}>
+ <CustomLabel label={item.d} />
+ </div>
+ </li>
+ ))}
+ </ul>
+ );
+ }
+}
diff --git a/packages/sheets-plugin-formula/src/View/UI/IfGenerate/ifGenerate.tsx b/packages/sheets-plugin-formula/src/View/UI/IfGenerate/ifGenerate.tsx
index d2db336c00..3cae92338c 100644
--- a/packages/sheets-plugin-formula/src/View/UI/IfGenerate/ifGenerate.tsx
+++ b/packages/sheets-plugin-formula/src/View/UI/IfGenerate/ifGenerate.tsx
@@ -1,4 +1,5 @@
-import { BaseButtonProps, BaseModalProps, BaseSelectProps, Component, FunctionComponent, Button, Modal, Select } from '@univerjs/base-ui';
+import { BaseButtonProps, BaseModalProps, BaseSelectProps, FunctionComponent, Button, Modal, Select, AppContext } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { Nullable, Observer, Workbook } from '@univerjs/core';
import { IConfig } from '../../../Basics/Interfaces/IFormula';
import styles from './index.module.less';
@@ -17,6 +18,8 @@ interface IState {
}
class IfGenerate extends Component<IProps, IState> {
+ static override contextType = AppContext;
+
Button: FunctionComponent<BaseButtonProps>;
Modal: FunctionComponent<BaseModalProps>;
diff --git a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaContent.tsx b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaContent.tsx
index aed45b1da7..230f2c53f9 100644
--- a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaContent.tsx
+++ b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaContent.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, createRef, debounce, Input, Select } from '@univerjs/base-ui';
+import { BaseComponentProps, debounce, Input, Select, CustomLabel } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import { FormulaType, FunListILabel, Label } from '../../../Basics';
import styles from './index.module.less';
@@ -15,7 +16,12 @@ interface IState {
export class SearchFormulaContent extends Component<IProps, IState> {
functionListRef = createRef();
- override initialize() {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
+ initialize() {
this.state = {
functionList: undefined,
type: 0,
@@ -87,12 +93,12 @@ export class SearchFormulaContent extends Component<IProps, IState> {
/**
* 国际化
*/
- getSelect(): Array<{ label: string }> {
+ getSelect(): Array<{ label: string | JSX.Element }> {
const { select } = this.props;
- const arr: Array<{ label: string }> = [];
+ const arr: Array<{ label: string | JSX.Element }> = [];
for (let i = 0; i < select.length; i++) {
arr.push({
- label: this.getLocale(select[i].label),
+ label: <CustomLabel label={select[i].label} />,
});
}
return arr;
@@ -105,7 +111,7 @@ export class SearchFormulaContent extends Component<IProps, IState> {
if (functionList[i][k] instanceof Array) {
functionList[i][k] = this.getFunctionList(functionList[i][k]);
} else if (typeof functionList[i][k] === 'string') {
- functionList[i][k] = this.getLocale(functionList[i][k]);
+ functionList[i][k] = <CustomLabel label={functionList[i][k]} />;
}
}
}
@@ -118,17 +124,26 @@ export class SearchFormulaContent extends Component<IProps, IState> {
return (
<div className={styles.functionModal}>
<div className={styles.functionSearch}>
- <div className={styles.functionLabel}>{this.getLocale('formula.formulaMore.findFunctionTitle')}</div>
- <Input placeholder={this.getLocale('formula.formulaMore.tipInputFunctionName')} onChange={debounce(this.changeInput.bind(this), 50)} />
+ <div className={styles.functionLabel}>
+ <CustomLabel label="formula.formulaMore.findFunctionTitle" />;
+ </div>
+ <Input
+ placeholder={(<CustomLabel label="formula.formulaMore.tipInputFunctionName" />) as unknown as string}
+ onChange={debounce(this.changeInput.bind(this), 50)}
+ />
</div>
<div className={styles.functionSelect}>
- <div className={styles.functionLabel}>{this.getLocale('formula.formulaMore.selectCategory')}</div>
+ <div className={styles.functionLabel}>
+ <CustomLabel label="formula.formulaMore.selectCategory" />
+ </div>
<div className={styles.functionSelector}>
<Select onClick={this.selectType.bind(this)} type={0} children={this.getSelect()} hideSelectedIcon={true}></Select>
</div>
</div>
<div className={styles.functionList} ref={this.functionListRef}>
- <div className={styles.functionLabel}>{this.getLocale('formula.formulaMore.selectFunctionTitle')}</div>
+ <div className={styles.functionLabel}>
+ <CustomLabel label="formula.formulaMore.selectFunctionTitle" />
+ </div>
<ul className={styles.functionLists}>
{functionList?.map((item, index) => (
<li className={`${styles.functionListsItem}`} onClick={() => this.handleClick(item, index)}>
diff --git a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaModal.tsx b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaModal.tsx
index bd31f589ce..bfa7579ee8 100644
--- a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaModal.tsx
+++ b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaModal.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, Modal } from '@univerjs/base-ui';
+import { BaseComponentProps, Modal } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { SearchFormulaModalData } from '../../../Basics/Interfaces/IFormula';
interface IProps extends BaseComponentProps {}
@@ -8,7 +9,12 @@ interface IState {
}
export class SearchFormulaModal extends Component<IProps, IState> {
- override initialize() {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
+ initialize() {
this.state = {
modalData: [],
};
diff --git a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchItem.tsx b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchItem.tsx
index 0eb5c5b6c8..3a1e89ef6d 100644
--- a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchItem.tsx
+++ b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchItem.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, CellRange, Component } from '@univerjs/base-ui';
+import { BaseComponentProps, CellRange, CustomLabel } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { FormulaParamType, FunParams } from '../../../Basics';
import styles from './index.module.less';
@@ -14,7 +15,12 @@ interface IState {
}
export class SearchItem extends Component<IProps, IState> {
- override initialize() {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
+ initialize() {
this.state = {
description: {},
rangeList: [],
@@ -62,10 +68,10 @@ export class SearchItem extends Component<IProps, IState> {
<span>{item.name}:</span>
<div onClick={() => this.handleClick(index)}>
<CellRange
- contentPlaceholder={this.getLocale('formula.formulaMore.tipDataRangeTitle')}
- title={this.getLocale('formula.formulaMore.tipSelectDataRange')}
+ contentPlaceholder={(<CustomLabel label="formula.formulaMore.tipDataRangeTitle" />) as unknown as string}
+ title={(<CustomLabel label="formula.formulaMore.tipSelectDataRange" />) as unknown as string}
value={rangeList[index]}
- ></CellRange>
+ />
</div>
<span>={'{}'}</span>
</div>
diff --git a/packages/sheets-plugin-image/src/View/UI/ImagePanel/ImagePanelUI.tsx b/packages/sheets-plugin-image/src/View/UI/ImagePanel/ImagePanelUI.tsx
index 8e51931ca7..e259787ad1 100644
--- a/packages/sheets-plugin-image/src/View/UI/ImagePanel/ImagePanelUI.tsx
+++ b/packages/sheets-plugin-image/src/View/UI/ImagePanel/ImagePanelUI.tsx
@@ -1,4 +1,5 @@
-import { ColorPickerCircleButton, Component, SiderModal, VNode } from '@univerjs/base-ui';
+import { ColorPickerCircleButton, SiderModal } from '@univerjs/base-ui';
+import { Component, VNode } from 'preact';
import { BorderType, NormalType } from '../../../Basics';
import Style from './ImagePanelUI.module.less';
@@ -18,6 +19,11 @@ export class ImagePanelUI extends Component<ImagePanelUIProps> {
private _radius: number;
+ constructor(props: ImagePanelUIProps) {
+ super(props);
+ this.initialize(props);
+ }
+
initialize(props: ImagePanelUIProps) {
const imagePlugin = this.getContext().getPluginManager().getPluginByName<OverGridImagePlugin>(OVER_GRID_IMAGE_PLUGIN_NAME)!;
this.state = {};
@@ -109,17 +115,4 @@ export class ImagePanelUI extends Component<ImagePanelUIProps> {
</SiderModal>
);
}
-
- closed() {
- // const plugin: SheetPlugin = this.getPluginByName(PLUGIN_NAMES.SPREADSHEET)!;
- // plugin.showSiderByName(OVER_GRID_IMAGE_PLUGIN_NAME, false);
- }
-
- componentWillMount() {
- console.log('componentWillMount');
- }
-
- componentWillUnmount() {
- console.log('componentWillUnmount');
- }
}
diff --git a/packages/sheets-plugin-image/src/View/UI/ImageUploadButton/ImageUploadButtonUI.tsx b/packages/sheets-plugin-image/src/View/UI/ImageUploadButton/ImageUploadButtonUI.tsx
index a093145f8e..cbb6e27609 100644
--- a/packages/sheets-plugin-image/src/View/UI/ImageUploadButton/ImageUploadButtonUI.tsx
+++ b/packages/sheets-plugin-image/src/View/UI/ImageUploadButton/ImageUploadButtonUI.tsx
@@ -1,10 +1,15 @@
-import { Component } from '@univerjs/base-ui';
+import { Component } from 'preact';
export interface ImageUploadButtonUIProps {
chooseCallback: (url: string, file: File) => void;
}
export class ImageUploadButtonUI extends Component<ImageUploadButtonUIProps> {
+ constructor(props: ImageUploadButtonUIProps) {
+ super(props);
+ this.initialize(props);
+ }
+
initialize(props: ImageUploadButtonUIProps) {
this.state = {};
}
diff --git a/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsx b/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsx
index 50a2169374..438b555cc5 100644
--- a/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsx
+++ b/packages/sheets-plugin-numfmt/src/View/UI/FormatContent.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentRender, BaseComponentSheet, Component, createRef } from '@univerjs/base-ui';
+import { BaseComponentRender, BaseComponentSheet } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import styles from './index.module.less';
interface IProps {
@@ -15,6 +16,11 @@ export class FormatContent extends Component<IProps, IState> {
private _ref = createRef();
+ constructor(props: IProps) {
+ super(props);
+ this.initialize(props);
+ }
+
initialize(props: IProps) {
const component = this.getContext().getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;
this._render = component.getComponentRender();
diff --git a/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsx b/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsx
index 066cadb492..fa8b136b94 100644
--- a/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsx
+++ b/packages/sheets-plugin-numfmt/src/View/UI/NumfmtModal.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, BaseComponentRender, BaseComponentSheet, Component } from '@univerjs/base-ui';
+import { BaseComponentProps, BaseComponentRender, BaseComponentSheet } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { SheetPlugin } from '@univerjs/base-sheets';
import { PLUGIN_NAMES } from '@univerjs/core';
import { NUMFMT_PLUGIN_NAME } from '../../Basics/Const';
@@ -14,6 +15,11 @@ interface IState {
export class NumfmtModal extends Component<IProps, IState> {
private _render: BaseComponentRender;
+ constructor(props: IProps) {
+ super(props);
+ this.initialize(props);
+ }
+
initialize(props: IProps): void {
const component = this.getContext().getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;
this._render = component.getComponentRender();
@@ -23,7 +29,7 @@ export class NumfmtModal extends Component<IProps, IState> {
};
}
- componentDidMount(): void {
+ override componentDidMount(): void {
const plugin = this.getContext().getPluginManager().getPluginByName<NumfmtPlugin>(NUMFMT_PLUGIN_NAME)!;
plugin.getObserver('onNumfmtModalDidMountObservable')!.notifyObservers(this);
}
diff --git a/packages/sheets-plugin-operation/src/UI/ClipboardInput.tsx b/packages/sheets-plugin-operation/src/UI/ClipboardInput.tsx
index 72b64046ab..7df15d7659 100644
--- a/packages/sheets-plugin-operation/src/UI/ClipboardInput.tsx
+++ b/packages/sheets-plugin-operation/src/UI/ClipboardInput.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentRender, Component, Input } from '@univerjs/base-ui';
+import { BaseComponentRender, Input } from '@univerjs/base-ui';
+import { Component } from 'preact';
interface IProps {
prefix?: string;
@@ -10,8 +11,6 @@ interface IProps {
export class ClipboardInput extends Component<IProps> {
private _render: BaseComponentRender;
- override initialize() {}
-
render() {
const { prefix, placeholder1, suffix, placeholder2 } = this.props;
diff --git a/packages/ui-plugin-docs/src/View/App.tsx b/packages/ui-plugin-docs/src/View/App.tsx
index 39c76ef86e..2cce44f431 100644
--- a/packages/ui-plugin-docs/src/View/App.tsx
+++ b/packages/ui-plugin-docs/src/View/App.tsx
@@ -1,10 +1,11 @@
-import { AppContext, BaseComponentProps, Component, ComponentManager } from '@univerjs/base-ui';
+import { AppContext, BaseComponentProps, ComponentManager } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { LocaleService, LocaleType } from '@univerjs/core';
import { BaseDocContainerProps, DocContainer } from './DocContainer';
export interface BaseUIProps extends BaseComponentProps {
locale: LocaleType;
- localeService: LocaleService,
+ localeService: LocaleService;
UIConfig: BaseDocContainerProps;
componentManager: ComponentManager;
changeLocale: (locale: string) => void;
@@ -71,4 +72,4 @@ export class App extends Component<BaseUIProps, IState> {
</AppContext.Provider>
);
}
-}
\ No newline at end of file
+}
diff --git a/packages/ui-plugin-docs/src/View/Common/ColorSelect/ColorSelect.tsx b/packages/ui-plugin-docs/src/View/Common/ColorSelect/ColorSelect.tsx
index f84ed44a36..063faf6de1 100644
--- a/packages/ui-plugin-docs/src/View/Common/ColorSelect/ColorSelect.tsx
+++ b/packages/ui-plugin-docs/src/View/Common/ColorSelect/ColorSelect.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, ComponentChildren, CustomComponent } from '@univerjs/base-ui';
+import { BaseComponentProps, CustomComponent, CustomLabel } from '@univerjs/base-ui';
+import { Component, ComponentChildren } from 'preact';
import styles from './index.module.less';
interface IProps extends BaseComponentProps {
@@ -12,11 +13,11 @@ interface IState {
}
export class ColorSelect extends Component<IProps, IState> {
- componentDidMount(): void {
+ override componentDidMount(): void {
this.props.getComponent?.(this);
}
- componentWillReceiveProps(props: IProps) {
+ override componentWillReceiveProps(props: IProps) {
this.setState({
color: props.color,
});
@@ -32,7 +33,9 @@ export class ColorSelect extends Component<IProps, IState> {
const { label } = this.props;
return (
<div className={styles.colorSelect}>
- <div>{this.getLabel(label)}</div>
+ <div>
+ <CustomLabel label={label} />
+ </div>
<div className={styles.colorSelectLine} style={{ background: this.state.color }}></div>
</div>
);
diff --git a/packages/ui-plugin-docs/src/View/DocContainer/DocContainer.tsx b/packages/ui-plugin-docs/src/View/DocContainer/DocContainer.tsx
index 3231d58b80..10001f7b18 100644
--- a/packages/ui-plugin-docs/src/View/DocContainer/DocContainer.tsx
+++ b/packages/ui-plugin-docs/src/View/DocContainer/DocContainer.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, Container, Content, createRef, Footer, Header, Layout, Sider } from '@univerjs/base-ui';
+import { BaseComponentProps, Container, Content, Footer, Header, Layout, Sider } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import defaultSkin from '@univerjs/base-ui/Basics/CSS/Skin/default.module.less';
import { Tools } from '@univerjs/core';
import cssVars from 'css-vars-ponyfill';
@@ -34,7 +35,7 @@ export class DocContainer extends Component<BaseDocContainerProps> {
this.changeSkin(props.config.container as string, 'default');
}
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
}
@@ -96,7 +97,7 @@ export class DocContainer extends Component<BaseDocContainerProps> {
*/
changeSkin(container: HTMLElement | string, skin: string) {
// Collect all skins
- let root = document.documentElement;
+ const root = document.documentElement;
const id = typeof container === 'string' ? container : container.id;
@@ -124,7 +125,7 @@ export class DocContainer extends Component<BaseDocContainerProps> {
});
} else {
// set css variable
- let doc = getSkinStyleDoc(id);
+ const doc = getSkinStyleDoc(id);
/**
* covert object to style, remove " and replace , to ;
diff --git a/packages/ui-plugin-docs/src/View/InfoBar/InfoBar.tsx b/packages/ui-plugin-docs/src/View/InfoBar/InfoBar.tsx
index bd84f63a9b..c462f39ddf 100644
--- a/packages/ui-plugin-docs/src/View/InfoBar/InfoBar.tsx
+++ b/packages/ui-plugin-docs/src/View/InfoBar/InfoBar.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, Container, Input, Tooltip } from '@univerjs/base-ui';
+import { BaseComponentProps, Container, Input, Tooltip, CustomLabel } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { Nullable } from '@univerjs/core';
import { BaseInfoBarProps } from '../../Controller/InfoBarUIController';
import styles from './index.module.less';
@@ -12,6 +13,11 @@ interface IProps extends BaseComponentProps {
}
export class InfoBar extends Component<IProps, IState> {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
infoList: null,
@@ -49,8 +55,12 @@ export class InfoBar extends Component<IProps, IState> {
<Input bordered={false} value={sheet.label} onBlur={renameSheet} />
</Tooltip>
</div>
- <div className={styles.infoDetailUpdate}>{this.getLabel(update.label)}</div>
- <div className={styles.infoDetailSave}>{this.getLabel(save.label)}</div>
+ <div className={styles.infoDetailUpdate}>
+ <CustomLabel label={update.label} />
+ </div>
+ <div className={styles.infoDetailSave}>
+ <CustomLabel label={save.label} />
+ </div>
</Container>
);
}
diff --git a/packages/ui-plugin-docs/src/View/Toolbar/Toolbar.tsx b/packages/ui-plugin-docs/src/View/Toolbar/Toolbar.tsx
index 65f40c6df8..e1985f8834 100644
--- a/packages/ui-plugin-docs/src/View/Toolbar/Toolbar.tsx
+++ b/packages/ui-plugin-docs/src/View/Toolbar/Toolbar.tsx
@@ -1,4 +1,5 @@
-import { AppContext, AppContextValues, BaseComponentProps, Button, Component, Container, createRef, debounce, PreactContext, Select, Tooltip } from '@univerjs/base-ui';
+import { AppContext, BaseComponentProps, Button, Container, debounce, Select, Tooltip, CustomLabel } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import { DocUIPlugin } from '../..';
import { DOC_UI_PLUGIN_NAME } from '../../Basics';
import { IToolbarItemProps } from '../../Controller';
@@ -18,7 +19,7 @@ interface IState {
}
export class Toolbar extends Component<IProps, IState> {
- static contextType: PreactContext<Partial<AppContextValues>> = AppContext;
+ static override contextType = AppContext;
toolbarRef = createRef();
@@ -37,7 +38,12 @@ export class Toolbar extends Component<IProps, IState> {
this.setToolbarListWidth();
}, 50);
- override initialize() {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
+ initialize() {
this.state = {
// Button contains main button and drop down arrow, translation file contains main and right
showMore: false,
@@ -54,7 +60,7 @@ export class Toolbar extends Component<IProps, IState> {
* TODO : 点击其他地方需要隐藏more buttons
*/
showMore = () => {
- let showMore = this.state.showMore;
+ const showMore = this.state.showMore;
this.setState({ showMore: !showMore });
if (!showMore) {
@@ -182,7 +188,7 @@ export class Toolbar extends Component<IProps, IState> {
return (
<Tooltip title={item.tooltip} placement={'bottom'}>
<Button unActive={item.unActive} className={styles.textButton} type="text" active={item.active} onClick={item.onClick}>
- {this.getLabel(item.label)}
+ <CustomLabel label={item.label} />
</Button>
</Tooltip>
);
@@ -220,9 +226,11 @@ export class Toolbar extends Component<IProps, IState> {
{this.getToolbarList(defaultToolList)}
<div ref={this.moreBtnRef} className={styles.moreButton} style={{ visibility: moreToolList.length ? 'visible' : 'hidden' }}>
- <Tooltip title={this.getLocale('toolbar.toolMoreTip')} placement={'bottom'}>
+ <Tooltip title={(<CustomLabel label="toolbar.toolMoreTip" />) as unknown as string} placement={'bottom'}>
<Button type="text" onClick={this.showMore}>
- <div style={{ fontSize: '14px' }}>{this.getLocale('toolbar.toolMore')}</div>
+ <div style={{ fontSize: '14px' }}>
+ <CustomLabel label="toolbar.toolMore" />
+ </div>
</Button>
</Tooltip>
</div>
diff --git a/packages/ui-plugin-docs/src/View/index.tsx b/packages/ui-plugin-docs/src/View/index.tsx
index e4c0ec1953..e318d14674 100644
--- a/packages/ui-plugin-docs/src/View/index.tsx
+++ b/packages/ui-plugin-docs/src/View/index.tsx
@@ -1,4 +1,5 @@
-import { isElement, render } from '@univerjs/base-ui';
+import { isElement } from '@univerjs/base-ui';
+import { render } from 'preact';
import { App, BaseUIProps } from './App';
interface BaseDicUIConfig extends BaseUIProps {
diff --git a/packages/ui-plugin-sheets/src/View/App.tsx b/packages/ui-plugin-sheets/src/View/App.tsx
index 22529fd834..604733d0d1 100644
--- a/packages/ui-plugin-sheets/src/View/App.tsx
+++ b/packages/ui-plugin-sheets/src/View/App.tsx
@@ -1,4 +1,5 @@
-import { AppContext, BaseComponentProps, Component, ComponentManager, ZIndexManager } from '@univerjs/base-ui';
+import { AppContext, BaseComponentProps, ComponentManager, ZIndexManager } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { LocaleService, LocaleType, ObserverManager } from '@univerjs/core';
import { BaseSheetContainerProps, SheetContainer } from './SheetContainer';
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 f84ed44a36..063faf6de1 100644
--- a/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, ComponentChildren, CustomComponent } from '@univerjs/base-ui';
+import { BaseComponentProps, CustomComponent, CustomLabel } from '@univerjs/base-ui';
+import { Component, ComponentChildren } from 'preact';
import styles from './index.module.less';
interface IProps extends BaseComponentProps {
@@ -12,11 +13,11 @@ interface IState {
}
export class ColorSelect extends Component<IProps, IState> {
- componentDidMount(): void {
+ override componentDidMount(): void {
this.props.getComponent?.(this);
}
- componentWillReceiveProps(props: IProps) {
+ override componentWillReceiveProps(props: IProps) {
this.setState({
color: props.color,
});
@@ -32,7 +33,9 @@ export class ColorSelect extends Component<IProps, IState> {
const { label } = this.props;
return (
<div className={styles.colorSelect}>
- <div>{this.getLabel(label)}</div>
+ <div>
+ <CustomLabel label={label} />
+ </div>
<div className={styles.colorSelectLine} style={{ background: this.state.color }}></div>
</div>
);
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 c861364dfb..df156665dd 100644
--- a/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, Icon } from '@univerjs/base-ui';
+import { BaseComponentProps, AppContext, Icon, CustomLabel } from '@univerjs/base-ui';
+import { Component } from 'preact';
interface IState {
img: string;
@@ -10,17 +11,24 @@ interface IProps extends BaseComponentProps {
}
export class LineBold extends Component<IProps, IState> {
+ static override contextType = AppContext;
+
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
img: '',
};
}
- componentDidMount(): void {
+ override componentDidMount(): void {
this.props.getComponent?.(this);
}
- componentWillReceiveProps(props: IProps) {
+ override componentWillReceiveProps(props: IProps) {
this.setState({
img: props.img,
});
@@ -48,7 +56,7 @@ export class LineBold extends Component<IProps, IState> {
return (
<div style={{ paddingBottom: '3px', width: '100%', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span className={'base-sheets-line-bold'} style={{ position: 'relative' }}>
- {this.getLabel(label)}
+ <CustomLabel label={label} />
<div style={{ width: '100%', height: 0, position: 'absolute', left: 0, bottom: '14px' }}>{img.length ? this.getImg(img) : ''}</div>
</span>
<Icon.RightIcon />
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 009a7874b8..76a7e703db 100644
--- a/packages/ui-plugin-sheets/src/View/Common/Line/LineColor.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/Line/LineColor.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, Icon } from '@univerjs/base-ui';
+import { BaseComponentProps, CustomLabel, Icon } from '@univerjs/base-ui';
+import { Component } from 'preact';
interface IState {
color: string;
@@ -10,17 +11,22 @@ interface IProps extends BaseComponentProps {
}
export class LineColor extends Component<IProps, IState> {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
color: this.props.color,
};
}
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
}
- componentWillReceiveProps(props: IProps): void {
+ override componentWillReceiveProps(props: IProps): void {
this.setState({
color: props.color,
});
@@ -38,7 +44,9 @@ export class LineColor extends Component<IProps, IState> {
return (
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
- <span style={{ display: 'inline-block', borderBottom: `3px solid ${color}` }}>{this.getLabel(label)}</span>
+ <span style={{ display: 'inline-block', borderBottom: `3px solid ${color}` }}>
+ <CustomLabel label={label} />
+ </span>
<Icon.RightIcon />
</div>
);
diff --git a/packages/ui-plugin-sheets/src/View/Common/test.tsx b/packages/ui-plugin-sheets/src/View/Common/test.tsx
index d0042659d6..05713f083a 100644
--- a/packages/ui-plugin-sheets/src/View/Common/test.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/test.tsx
@@ -1,4 +1,5 @@
-import { Component, SiderModal } from '@univerjs/base-ui';
+import { SiderModal } from '@univerjs/base-ui';
+import { Component } from 'preact';
type IProps = {};
diff --git a/packages/ui-plugin-sheets/src/View/Common/test1.tsx b/packages/ui-plugin-sheets/src/View/Common/test1.tsx
index d784220a24..8b34752b20 100644
--- a/packages/ui-plugin-sheets/src/View/Common/test1.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/test1.tsx
@@ -1,4 +1,5 @@
-import { Component, SiderModal } from '@univerjs/base-ui';
+import { SiderModal } from '@univerjs/base-ui';
+import { Component } from 'preact';
type IProps = {};
diff --git a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
index de2033b9a3..c1d7debc7b 100644
--- a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
@@ -1,4 +1,5 @@
-import { BaseCountBarProps, Button, Component, CountBarComponent, createRef, Icon, JSXComponent, Slider } from '@univerjs/base-ui';
+import { BaseCountBarProps, Button, CountBarComponent, Icon, JSXComponent, Slider, AppContext } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import { ObserverManager, PLUGIN_NAMES } from '@univerjs/core';
import { Injector } from '@wendellhu/redi';
import styles from './index.module.less';
@@ -13,13 +14,20 @@ interface CountBarProps extends BaseCountBarProps {
}
export class CountBar extends Component<CountBarProps, CountState> {
+ static override contextType = AppContext;
+
max = 400;
min = 0;
ref = createRef();
- override initialize(props: CountBarProps) {
+ constructor(props: CountBarProps) {
+ super(props);
+ this.initialize(props);
+ }
+
+ initialize(props: CountBarProps) {
this.state = {
zoom: 100,
content: '',
@@ -45,7 +53,7 @@ export class CountBar extends Component<CountBarProps, CountState> {
}
onChange = (e: Event) => {
- let target = e.target as HTMLInputElement;
+ const target = e.target as HTMLInputElement;
if (this.props.onChange) {
this.props.onChange(target.value);
}
@@ -58,7 +66,7 @@ export class CountBar extends Component<CountBarProps, CountState> {
};
addZoom = () => {
- let number = Math.floor(this.state.zoom / 10);
+ const number = Math.floor(this.state.zoom / 10);
let value = (number + 1) * 10;
if (value >= this.max) value = this.max;
this.setValue({ zoom: value });
@@ -68,7 +76,7 @@ export class CountBar extends Component<CountBarProps, CountState> {
};
reduceZoom = () => {
- let number = Math.ceil(this.state.zoom / 10);
+ const number = Math.ceil(this.state.zoom / 10);
let value = (number - 1) * 10;
if (value <= this.min) value = this.min;
this.setValue({ zoom: value });
diff --git a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
index cc6732e0a8..ead482c725 100644
--- a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
@@ -1,107 +1,113 @@
-import { BaseComponentProps, BaseComponentRender, BaseSelectChildrenProps, Component, debounce, Icon } from '@univerjs/base-ui';
-import { Nullable } from '@univerjs/core';
-import styles from './index.module.less';
-
-type FormulaState = {
- namedRanges: BaseSelectChildrenProps[];
- spanClass: string;
- formulaContent: string;
- fx: Nullable<Fx>;
-};
-
-export type Fx = {
- icon: string;
- onClick: () => void;
-};
-
-export interface BaseFormulaBarProps extends BaseComponentProps {}
-
-export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
- private _render: BaseComponentRender;
-
- // formulaContent = createRef<HTMLDivElement>();
-
- initialize(props?: BaseFormulaBarProps) {
- this.state = {
- namedRanges: [
- {
- value: '1',
- label: '1',
- },
- ],
- spanClass: styles.formulaGrey,
- formulaContent: '',
- fx: null,
- };
-
- this.onkeyUp = debounce(this.onkeyUp, 300);
- }
-
- onkeyUp = (value: any) => {
- // console.dir(value);
- };
-
- printChange = (e: KeyboardEvent) => {
- this.onkeyUp(e.target);
- };
-
- setFormulaContent(value: string) {
- this.setState({
- formulaContent: value,
- });
- }
-
- setFx(fx: Fx) {
- this.setState({
- fx,
- });
- }
-
- setNamedRanges(namedRanges: BaseSelectChildrenProps[]) {
- this.setState({
- namedRanges,
- });
- }
-
- componentDidMount() {
- this.props.getComponent?.(this);
- // this._context.getObserverManager().getObserver<FormulaBar>('onFormulaBarDidMountObservable')?.notifyObservers(this);
- }
-
- getIcon(name: string) {
- const componentManager = this.context.componentManager;
- const Icon = componentManager?.get(name);
- return <Icon />;
- }
-
- render(props: BaseFormulaBarProps, state: FormulaState) {
- // 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 } = state;
-
- return (
- <div className={styles.formulaBox}>
- {/* <Select children={namedRanges} type={0}></Select> */}
- <div className={styles.formulaBar}>
- <div className={styles.formulaIcon}>
- <span className={state.spanClass}>
- <Icon.Format.CloseIcon />
- </span>
- <span className={state.spanClass}>
- <Icon.Format.CorrectIcon />
- </span>
- {fx ? (
- <span className={styles.formulaBlack} onClick={fx.onClick}>
- {this.getIcon(fx.icon)}
- </span>
- ) : null}
- </div>
- <div className={styles.formulaInput}>
- <div autoFocus contentEditable={true} className={styles.formulaContent} onKeyUp={(e) => this.printChange(e)}>
- {state.formulaContent}
- </div>
- </div>
- </div>
- </div>
- );
- }
-}
+import { BaseComponentProps, BaseComponentRender, BaseSelectChildrenProps, debounce, Icon } from '@univerjs/base-ui';
+import { Component } from 'preact';
+import { Nullable } from '@univerjs/core';
+import styles from './index.module.less';
+
+type FormulaState = {
+ namedRanges: BaseSelectChildrenProps[];
+ spanClass: string;
+ formulaContent: string;
+ fx: Nullable<Fx>;
+};
+
+export type Fx = {
+ icon: string;
+ onClick: () => void;
+};
+
+export interface BaseFormulaBarProps extends BaseComponentProps {}
+
+export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
+ private _render: BaseComponentRender;
+
+ // formulaContent = createRef<HTMLDivElement>();
+
+ constructor(props: BaseFormulaBarProps) {
+ super(props);
+ this.initialize(props);
+ }
+
+ initialize(props?: BaseFormulaBarProps) {
+ this.state = {
+ namedRanges: [
+ {
+ value: '1',
+ label: '1',
+ },
+ ],
+ spanClass: styles.formulaGrey,
+ formulaContent: '',
+ fx: null,
+ };
+
+ this.onkeyUp = debounce(this.onkeyUp, 300);
+ }
+
+ onkeyUp = (value: any) => {
+ // console.dir(value);
+ };
+
+ printChange = (e: KeyboardEvent) => {
+ this.onkeyUp(e.target);
+ };
+
+ setFormulaContent(value: string) {
+ this.setState({
+ formulaContent: value,
+ });
+ }
+
+ setFx(fx: Fx) {
+ this.setState({
+ fx,
+ });
+ }
+
+ setNamedRanges(namedRanges: BaseSelectChildrenProps[]) {
+ this.setState({
+ namedRanges,
+ });
+ }
+
+ componentDidMount() {
+ this.props.getComponent?.(this);
+ // this._context.getObserverManager().getObserver<FormulaBar>('onFormulaBarDidMountObservable')?.notifyObservers(this);
+ }
+
+ getIcon(name: string) {
+ const componentManager = this.context.componentManager;
+ const Icon = componentManager?.get(name);
+ return <Icon />;
+ }
+
+ render(props: BaseFormulaBarProps, state: FormulaState) {
+ // 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 } = state;
+
+ return (
+ <div className={styles.formulaBox}>
+ {/* <Select children={namedRanges} type={0}></Select> */}
+ <div className={styles.formulaBar}>
+ <div className={styles.formulaIcon}>
+ <span className={state.spanClass}>
+ <Icon.Format.CloseIcon />
+ </span>
+ <span className={state.spanClass}>
+ <Icon.Format.CorrectIcon />
+ </span>
+ {fx ? (
+ <span className={styles.formulaBlack} onClick={fx.onClick}>
+ {this.getIcon(fx.icon)}
+ </span>
+ ) : null}
+ </div>
+ <div className={styles.formulaInput}>
+ <div autoFocus contentEditable={true} className={styles.formulaContent} onKeyUp={(e) => this.printChange(e)}>
+ {state.formulaContent}
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+ }
+}
diff --git a/packages/ui-plugin-sheets/src/View/InfoBar/InfoBar.tsx b/packages/ui-plugin-sheets/src/View/InfoBar/InfoBar.tsx
index bd84f63a9b..05de343d25 100644
--- a/packages/ui-plugin-sheets/src/View/InfoBar/InfoBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/InfoBar/InfoBar.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, Container, Input, Tooltip } from '@univerjs/base-ui';
+import { BaseComponentProps, Container, CustomLabel, Input, Tooltip } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { Nullable } from '@univerjs/core';
import { BaseInfoBarProps } from '../../Controller/InfoBarUIController';
import styles from './index.module.less';
@@ -12,13 +13,18 @@ interface IProps extends BaseComponentProps {
}
export class InfoBar extends Component<IProps, IState> {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
infoList: null,
};
}
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
}
@@ -49,8 +55,12 @@ export class InfoBar extends Component<IProps, IState> {
<Input bordered={false} value={sheet.label} onBlur={renameSheet} />
</Tooltip>
</div>
- <div className={styles.infoDetailUpdate}>{this.getLabel(update.label)}</div>
- <div className={styles.infoDetailSave}>{this.getLabel(save.label)}</div>
+ <div className={styles.infoDetailUpdate}>
+ <CustomLabel label={update.label} />
+ </div>
+ <div className={styles.infoDetailSave}>
+ <CustomLabel label={save.label} />
+ </div>
</Container>
);
}
diff --git a/packages/ui-plugin-sheets/src/View/RichText/RichText.tsx b/packages/ui-plugin-sheets/src/View/RichText/RichText.tsx
index bb19ee6674..29b01313b5 100644
--- a/packages/ui-plugin-sheets/src/View/RichText/RichText.tsx
+++ b/packages/ui-plugin-sheets/src/View/RichText/RichText.tsx
@@ -1,5 +1,6 @@
// import { CellInputHandler } from '@univerjs/sheets-plugin-formula/src/Controller/CellInputHandler';
-import { BaseComponentProps, Component, createRef, xssDeal } from '@univerjs/base-ui';
+import { BaseComponentProps, xssDeal } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import { CellTextStyle } from './CellTextStyle';
import styles from './index.module.less';
// interface IProps {
@@ -42,6 +43,11 @@ export class RichText extends Component<BaseRichTextProps, IRichTextState> {
hooks = new Map<string, (args: any) => void>();
+ constructor(props: BaseRichTextProps) {
+ super(props);
+ this.initialize(props);
+ }
+
initialize(props: BaseRichTextProps) {}
setValue(value: string) {
@@ -147,9 +153,9 @@ export class RichText extends Component<BaseRichTextProps, IRichTextState> {
/**
* init
*/
- componentWillMount() {}
+ override componentWillMount() {}
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
this.cellTextStyle = new CellTextStyle(this.ref.current!);
@@ -159,7 +165,7 @@ export class RichText extends Component<BaseRichTextProps, IRichTextState> {
/**
* destory
*/
- componentWillUnmount() {
+ override componentWillUnmount() {
// this._context.getObserverManager().getObserver<WorkBook>('onAfterChangeUILocaleObservable', 'workbook')?.remove(this._localeObserver);
}
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
index 05d85ba254..b5432d0e7e 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
@@ -1,5 +1,6 @@
import { IMouseEvent } from '@univerjs/base-render';
-import { BaseRightMenuProps, Component, createRef, Menu } from '@univerjs/base-ui';
+import { BaseRightMenuProps, Menu } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import { RightMenuProps } from '../../Controller';
import Style from './index.module.less';
@@ -15,6 +16,11 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
root = createRef();
+ constructor(props: BaseRightMenuProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
visible: false,
@@ -31,13 +37,13 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
}
// TODO:添加到具体的元素
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
// 添加右键点击、点击事件监听
document.addEventListener('click', this.handleClick);
}
- componentWillUnmount() {
+ override componentWillUnmount() {
// 移除事件监听
document.removeEventListener('click', this.handleClick);
}
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuButton.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuButton.tsx
index 95228d2c55..1fe7f97b88 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuButton.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuButton.tsx
@@ -1,4 +1,5 @@
-import { Button, Component } from '@univerjs/base-ui';
+import { Button } from '@univerjs/base-ui';
+import { Component } from 'preact';
interface IProps {
label: string;
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
index 827cf31b6c..993f34d7a4 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
@@ -1,4 +1,5 @@
-import { Component, Input } from '@univerjs/base-ui';
+import { CustomLabel, Input } from '@univerjs/base-ui';
+import { Component } from 'preact';
interface IProps {
prefix: string;
@@ -20,9 +21,9 @@ export class RightMenuInput extends Component<IProps> {
const { prefix, suffix } = this.props;
return (
<div>
- {this.getLabel(prefix)}
+ <CustomLabel label={prefix} />
<Input onPressEnter={this.handleKeyUp.bind(this)} type="number" placeholder="1" onClick={this.handleClick}></Input>
- {this.getLabel(suffix)}
+ <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 09b9071f81..d9d5d1dffe 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx
@@ -1,4 +1,5 @@
-import { Component, Icon } from '@univerjs/base-ui';
+import { CustomLabel, Icon } from '@univerjs/base-ui';
+import { Component } from 'preact';
import styles from './index.module.less';
interface IProps {
@@ -11,7 +12,7 @@ export class RightMenuItem extends Component<IProps> {
return (
<div className={styles.rightMenuItem}>
- {this.getLabel(label)}
+ <CustomLabel label={label} />
<Icon.Format.RightIcon />
</div>
);
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
index 1e8fa29198..e306e97f3f 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
@@ -1,5 +1,6 @@
-import { BaseMenuItem, BaseSheetBarProps, Button, Component, createRef, Icon, Menu, RefObject } from '@univerjs/base-ui';
-import { SheetBarMenu, SheetBarMenuItem } from './SheetBarMenu';
+import { BaseMenuItem, BaseSheetBarProps, Button, CustomLabel, Icon, Menu } from '@univerjs/base-ui';
+import { RefObject, Component, createRef } from 'preact';
+import { SheetBarMenu, ISheetBarMenuItem } from './SheetBarMenu';
import styles from './index.module.less';
import { SlideTabBar } from '../../Basics/SlideTabBar/SlideTabBar';
@@ -37,6 +38,11 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
private _renderKey: number = 1;
+ constructor(props: BaseSheetBarProps) {
+ super(props);
+ this.initialize(props);
+ }
+
initialize(props: BaseSheetBarProps) {
this.state = {
sheetList: [],
@@ -128,7 +134,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
);
};
- componentDidUpdate() {
+ override componentDidUpdate() {
if (this.slideTabBar) {
this.slideTabBar.destroy();
}
@@ -147,7 +153,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
});
}
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
}
@@ -166,7 +172,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
</Button>
<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 SheetBarMenuItem[]} ref={this.ref}></SheetBarMenu>
+ <SheetBarMenu onClick={selectSheet} menu={menuList as ISheetBarMenuItem[]} ref={this.ref}></SheetBarMenu>
</Button>
</div>
@@ -185,7 +191,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
<div className={`${styles.slideTabDivider}`}></div>
<div className={`${styles.slideTabTitle}`}>
<span className={`${styles.slideTabSpan}`} style={{ padding: '2px 5px 2px 5px' }}>
- {this.getLabel(item.label)}
+ <CustomLabel label={item.label} />
</span>
</div>
<div className={`${styles.slideTabIcon}`} data-slide-skip="true" style={{ lineHeight: 1 }} data-id={item.sheetId} onClick={this.contextMenu}>
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
index d29d7180c8..87bc63059c 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
@@ -1,7 +1,8 @@
-import { Component, Icon, joinClassNames } from '@univerjs/base-ui';
+import { CustomLabel, Icon, joinClassNames } from '@univerjs/base-ui';
+import { Component } from 'preact';
import styles from './index.module.less';
-export interface SheetBarMenuItem {
+export interface ISheetBarMenuItem {
label?: string;
hide?: boolean;
selected?: boolean;
@@ -10,8 +11,8 @@ export interface SheetBarMenuItem {
onClick?: (e?: MouseEvent) => void;
}
-export interface SheetBarMenuProps {
- menu: SheetBarMenuItem[];
+export interface ISheetBarMenuProps {
+ menu: ISheetBarMenuItem[];
style?: JSX.CSSProperties;
onClick?: (e?: MouseEvent) => void;
}
@@ -20,14 +21,19 @@ interface IState {
show: boolean;
}
-export class SheetBarMenu extends Component<SheetBarMenuProps, IState> {
+export class SheetBarMenu extends Component<ISheetBarMenuProps, IState> {
+ constructor(props: ISheetBarMenuProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
show: false,
};
}
- handleClick(e: MouseEvent, item: SheetBarMenuItem) {
+ handleClick(e: MouseEvent, item: ISheetBarMenuItem) {
e.stopPropagation();
const { onClick } = this.props;
if (item.onClick) {
@@ -59,7 +65,9 @@ export class SheetBarMenu extends Component<SheetBarMenuProps, IState> {
<span className={styles.sheetBarMenuIcon}>
<EffIcon item={item}></EffIcon>
</span>
- <span className={styles.sheetBarMenuTitle}>{this.getLabel(item.label ?? '')}</span>
+ <span className={styles.sheetBarMenuTitle}>
+ <CustomLabel label={item.label ?? ''} />
+ </span>
</li>
))}
</ul>
@@ -67,7 +75,7 @@ export class SheetBarMenu extends Component<SheetBarMenuProps, IState> {
}
}
-function EffIcon(props: { item: SheetBarMenuItem }) {
+function EffIcon(props: { item: ISheetBarMenuItem }) {
if (props.item.hide) {
return <Icon.HideIcon />;
}
diff --git a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
index d9e8c79300..a57b2cfcba 100644
--- a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, Container, Content, createRef, Footer, Header, Layout, Sider, Slot, defaultSkin } from '@univerjs/base-ui';
+import { BaseComponentProps, Container, Content, Footer, Header, Layout, Sider, Slot, defaultSkin } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import { Tools } from '@univerjs/core';
import cssVars from 'css-vars-ponyfill';
import style from './index.module.less';
@@ -100,7 +101,7 @@ export class SheetContainer extends Component<BaseSheetContainerProps> {
*/
changeSkin(container: HTMLElement | string, skin: string) {
// Collect all skins
- let root = document.documentElement;
+ const root = document.documentElement;
const id = typeof container === 'string' ? container : container.id;
@@ -128,7 +129,7 @@ export class SheetContainer extends Component<BaseSheetContainerProps> {
});
} else {
// set css variable
- let sheet = getSkinStyleSheet(id);
+ const sheet = getSkinStyleSheet(id);
/**
* covert object to style, remove " and replace , to ;
diff --git a/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx b/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx
index f2fbbd5bba..f6fb5db3c4 100644
--- a/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx
+++ b/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component } from '@univerjs/base-ui';
+import { BaseComponentProps } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { SlotGroupProps } from '../../Controller/SlotController';
interface IState {
@@ -12,13 +13,18 @@ interface IProps extends BaseComponentProps {
export class Slot extends Component<IProps, IState> {
refMap = new Map();
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
slotGroup: new Map(),
};
}
- componentDidMount(): void {
+ override componentDidMount(): void {
this.props.getComponent?.(this);
}
diff --git a/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx b/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
index b16f3fa939..fc31326b14 100644
--- a/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
+++ b/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
@@ -1,4 +1,5 @@
-import { AppContext, AppContextValues, BaseComponentProps, Button, Component, Container, createRef, debounce, IMenuItem, PreactContext, Select, Tooltip } from '@univerjs/base-ui';
+import { AppContext, BaseComponentProps, Button, Container, CustomLabel, debounce, IMenuItem, Select, Tooltip } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import { IToolbarItemProps, SheetContainerUIController } from '../../Controller';
import styles from './index.module.less';
import { ToolbarItem } from './ToolbarItem';
@@ -18,7 +19,7 @@ interface IState {
}
export class Toolbar extends Component<IProps, IState> {
- static override contextType: PreactContext<Partial<AppContextValues>> = AppContext;
+ static override contextType = AppContext;
toolbarRef = createRef();
@@ -37,7 +38,12 @@ export class Toolbar extends Component<IProps, IState> {
this.setToolbarListWidth();
}, 50);
- override initialize() {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
+ initialize() {
this.state = {
// Button contains main button and drop down arrow, translation file contains main and right
showMore: false,
@@ -201,7 +207,7 @@ export class Toolbar extends Component<IProps, IState> {
return (
<Tooltip title={item.tooltip} placement={'bottom'}>
<Button unActive={item.unActive} className={styles.textButton} type="text" active={item.active} onClick={item.onClick}>
- {this.getLabel(item.label)}
+ <CustomLabel label={item.label} />
</Button>
</Tooltip>
);
@@ -242,7 +248,9 @@ export class Toolbar extends Component<IProps, IState> {
<div ref={this.moreBtnRef} className={styles.moreButton} style={{ visibility: moreToolList.length ? 'visible' : 'hidden' }}>
<Tooltip title={'toolbar.toolMoreTip'} placement={'bottom'}>
<Button type="text" onClick={this.showMore}>
- <div style={{ fontSize: '14px' }}>{this.getLocale('toolbar.toolMore')}</div>
+ <div style={{ fontSize: '14px' }}>
+ <CustomLabel label={'toolbar.toolMore'} />
+ </div>
</Button>
</Tooltip>
</div>
@@ -259,4 +267,4 @@ export class Toolbar extends Component<IProps, IState> {
</Container>
);
}
-}
\ No newline at end of file
+}
diff --git a/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx b/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx
index ca6e721924..a72f02ea25 100644
--- a/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx
+++ b/packages/ui-plugin-sheets/src/View/Toolbar/ToolbarItem.tsx
@@ -1,7 +1,7 @@
-import { ComponentChild, ComponentChildren, isValidElement } from 'preact';
+import { ComponentChild, Component } from 'preact';
import { Subscription } from 'rxjs';
-import { IMenuItem, Button, Tooltip, Component, CustomComponent } from '@univerjs/base-ui';
+import { AppContext, IMenuItem, Button, Tooltip, CustomLabel } from '@univerjs/base-ui';
import { ICommandService } from '@univerjs/core';
import styles from './index.module.less';
@@ -11,6 +11,7 @@ export interface IToolbarItemStatus {
}
export class ToolbarItem extends Component<IMenuItem, IToolbarItemStatus> {
+ static override contextType = AppContext;
private disabledSubscription: Subscription | undefined;
constructor() {
@@ -39,26 +40,9 @@ export class ToolbarItem extends Component<IMenuItem, IToolbarItemStatus> {
return (
<Tooltip title={props.title} placement="bottom">
<Button className={styles.textButton} type="text" disabled={disabled} onClick={() => commandService.executeCommand(props.id)}>
- {this.getLabel({ name: props.icon })}
+ <CustomLabel label={{ name: props.icon }} />
</Button>
</Tooltip>
);
}
-
- override getLabel(label: string | CustomComponent | ComponentChildren) {
- if (typeof label === 'string') {
- return this.getLocale(label);
- }
- if (isValidElement(label)) {
- return label;
- }
- if (label) {
- const Label = this.context.componentManager.get((label as CustomComponent).name);
- if (Label) {
- const props = (label as CustomComponent).props ?? {};
- return <Label {...props}></Label>;
- }
- }
- return null;
- }
-}
\ No newline at end of file
+}
diff --git a/packages/ui-plugin-sheets/src/View/index.tsx b/packages/ui-plugin-sheets/src/View/index.tsx
index 8b72e66a87..308c9a167a 100644
--- a/packages/ui-plugin-sheets/src/View/index.tsx
+++ b/packages/ui-plugin-sheets/src/View/index.tsx
@@ -1,4 +1,5 @@
-import { isElement, render } from '@univerjs/base-ui';
+import { isElement } from '@univerjs/base-ui';
+import { render } from 'preact';
import { App, BaseUIProps } from './App';
interface BaseSheetUIConfig extends BaseUIProps {
diff --git a/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts
index c9f05d1721..1143bf4567 100644
--- a/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts
+++ b/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts
@@ -1,5 +1,6 @@
import { BorderInfo } from '@univerjs/base-slides';
-import { BaseSelectChildrenProps, BaseSelectProps, ColorPicker, ComponentChildren, ComponentManager } from '@univerjs/base-ui';
+import { BaseSelectChildrenProps, BaseSelectProps, ColorPicker, ComponentManager } from '@univerjs/base-ui';
+import { ComponentChildren } from 'preact';
import { BorderType, CommandManager, HorizontalAlign, ICurrentUniverService, IKeyValue, ObserverManager, Tools, UIObserver, VerticalAlign, WrapStrategy } from '@univerjs/core';
import { Inject, SkipSelf } from '@wendellhu/redi';
import { DefaultToolbarConfig, SlideToolbarConfig, SLIDE_UI_PLUGIN_NAME } from '../Basics';
diff --git a/packages/ui-plugin-slides/src/View/App.tsx b/packages/ui-plugin-slides/src/View/App.tsx
index d728073077..be547dd733 100644
--- a/packages/ui-plugin-slides/src/View/App.tsx
+++ b/packages/ui-plugin-slides/src/View/App.tsx
@@ -1,4 +1,5 @@
-import { AppContext, BaseComponentProps, Component, ComponentManager } from '@univerjs/base-ui';
+import { AppContext, BaseComponentProps, ComponentManager } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { LocaleService, LocaleType } from '@univerjs/core';
import { BaseSlideContainerProps, SlideContainer } from './SlideContainer';
diff --git a/packages/ui-plugin-slides/src/View/Common/ColorSelect/ColorSelect.tsx b/packages/ui-plugin-slides/src/View/Common/ColorSelect/ColorSelect.tsx
index f84ed44a36..063faf6de1 100644
--- a/packages/ui-plugin-slides/src/View/Common/ColorSelect/ColorSelect.tsx
+++ b/packages/ui-plugin-slides/src/View/Common/ColorSelect/ColorSelect.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, ComponentChildren, CustomComponent } from '@univerjs/base-ui';
+import { BaseComponentProps, CustomComponent, CustomLabel } from '@univerjs/base-ui';
+import { Component, ComponentChildren } from 'preact';
import styles from './index.module.less';
interface IProps extends BaseComponentProps {
@@ -12,11 +13,11 @@ interface IState {
}
export class ColorSelect extends Component<IProps, IState> {
- componentDidMount(): void {
+ override componentDidMount(): void {
this.props.getComponent?.(this);
}
- componentWillReceiveProps(props: IProps) {
+ override componentWillReceiveProps(props: IProps) {
this.setState({
color: props.color,
});
@@ -32,7 +33,9 @@ export class ColorSelect extends Component<IProps, IState> {
const { label } = this.props;
return (
<div className={styles.colorSelect}>
- <div>{this.getLabel(label)}</div>
+ <div>
+ <CustomLabel label={label} />
+ </div>
<div className={styles.colorSelectLine} style={{ background: this.state.color }}></div>
</div>
);
diff --git a/packages/ui-plugin-slides/src/View/Common/Line/LineBold.tsx b/packages/ui-plugin-slides/src/View/Common/Line/LineBold.tsx
index 1b2b6e5f73..01520fca4f 100644
--- a/packages/ui-plugin-slides/src/View/Common/Line/LineBold.tsx
+++ b/packages/ui-plugin-slides/src/View/Common/Line/LineBold.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, Icon } from '@univerjs/base-ui';
+import { BaseComponentProps, Icon, CustomLabel } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { SlideUIPlugin } from '../../..';
import { SLIDE_UI_PLUGIN_NAME } from '../../../Basics';
@@ -12,17 +13,22 @@ interface IProps extends BaseComponentProps {
}
export class LineBold extends Component<IProps, IState> {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
img: '',
};
}
- componentDidMount(): void {
+ override componentDidMount(): void {
this.props.getComponent?.(this);
}
- componentWillReceiveProps(props: IProps) {
+ override componentWillReceiveProps(props: IProps) {
this.setState({
img: props.img,
});
@@ -49,7 +55,7 @@ export class LineBold extends Component<IProps, IState> {
return (
<div style={{ paddingBottom: '3px', width: '100%', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span className={'base-sheets-line-bold'} style={{ position: 'relative' }}>
- {this.getLocale(label)}
+ <CustomLabel label={label} />
<div style={{ width: '100%', height: 0, position: 'absolute', left: 0, bottom: '14px' }}>{img.length ? this.getImg(img) : ''}</div>
</span>
<Icon.RightIcon />
diff --git a/packages/ui-plugin-slides/src/View/Common/Line/LineColor.tsx b/packages/ui-plugin-slides/src/View/Common/Line/LineColor.tsx
index 6d5ac26047..76a7e703db 100644
--- a/packages/ui-plugin-slides/src/View/Common/Line/LineColor.tsx
+++ b/packages/ui-plugin-slides/src/View/Common/Line/LineColor.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, Icon } from '@univerjs/base-ui';
+import { BaseComponentProps, CustomLabel, Icon } from '@univerjs/base-ui';
+import { Component } from 'preact';
interface IState {
color: string;
@@ -10,17 +11,22 @@ interface IProps extends BaseComponentProps {
}
export class LineColor extends Component<IProps, IState> {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
color: this.props.color,
};
}
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
}
- componentWillReceiveProps(props: IProps): void {
+ override componentWillReceiveProps(props: IProps): void {
this.setState({
color: props.color,
});
@@ -38,7 +44,9 @@ export class LineColor extends Component<IProps, IState> {
return (
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
- <span style={{ display: 'inline-block', borderBottom: `3px solid ${color}` }}>{this.getLocale(label)}</span>
+ <span style={{ display: 'inline-block', borderBottom: `3px solid ${color}` }}>
+ <CustomLabel label={label} />
+ </span>
<Icon.RightIcon />
</div>
);
diff --git a/packages/ui-plugin-slides/src/View/InfoBar/InfoBar.tsx b/packages/ui-plugin-slides/src/View/InfoBar/InfoBar.tsx
index 43d8889957..8bdb5ebc5f 100644
--- a/packages/ui-plugin-slides/src/View/InfoBar/InfoBar.tsx
+++ b/packages/ui-plugin-slides/src/View/InfoBar/InfoBar.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, Container, Input, Tooltip } from '@univerjs/base-ui';
+import { BaseComponentProps, Container, CustomLabel, Input, Tooltip } from '@univerjs/base-ui';
+import { Component } from 'preact';
import { Nullable } from '@univerjs/core';
import { BaseInfoBarProps } from '../../Controller/InfoBarUIController';
import styles from './index.module.less';
@@ -12,13 +13,18 @@ interface IProps extends BaseComponentProps {
}
export class InfoBar extends Component<IProps, IState> {
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
infoList: null,
};
}
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
}
@@ -49,8 +55,12 @@ export class InfoBar extends Component<IProps, IState> {
<Input bordered={false} value={slide.label} onBlur={renameSheet} />
</Tooltip>
</div>
- <div className={styles.infoDetailUpdate}>{this.getLabel(update.label)}</div>
- <div className={styles.infoDetailSave}>{this.getLabel(save.label)}</div>
+ <div className={styles.infoDetailUpdate}>
+ <CustomLabel label={update.label} />
+ </div>
+ <div className={styles.infoDetailSave}>
+ <CustomLabel label={save.label} />
+ </div>
</Container>
);
}
diff --git a/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx b/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
index 8289455018..3db6aad17a 100644
--- a/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
+++ b/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
@@ -1,4 +1,5 @@
-import { AppContext, AppContextValues, BaseComponentProps, Button, Component, createRef, PreactContext } from '@univerjs/base-ui';
+import { AppContext, BaseComponentProps, Button } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import { ISlidePage } from '@univerjs/core';
import styles from './index.module.less';
@@ -13,17 +14,22 @@ interface IProps extends BaseComponentProps {
}
export class SlideBar extends Component<IProps, SlideBarState> {
- static contextType: PreactContext<Partial<AppContextValues>> = AppContext;
+ static override contextType = AppContext;
slideBarRef = createRef<HTMLDivElement>();
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
slideList: [],
};
}
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
}
diff --git a/packages/ui-plugin-slides/src/View/SlideContainer/SlideContainer.tsx b/packages/ui-plugin-slides/src/View/SlideContainer/SlideContainer.tsx
index 25468962ff..c2fd7f17b2 100644
--- a/packages/ui-plugin-slides/src/View/SlideContainer/SlideContainer.tsx
+++ b/packages/ui-plugin-slides/src/View/SlideContainer/SlideContainer.tsx
@@ -1,4 +1,5 @@
-import { BaseComponentProps, Component, Container, Content, createRef, Footer, Header, Layout, Sider } from '@univerjs/base-ui';
+import { BaseComponentProps, Container, Content, Footer, Header, Layout, Sider } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import defaultSkin from '@univerjs/base-ui/Basics/CSS/Skin/default.module.less';
import { Tools } from '@univerjs/core';
import cssVars from 'css-vars-ponyfill';
@@ -31,11 +32,11 @@ export class SlideContainer extends Component<BaseSlideContainerProps> {
contentRef = createRef<HTMLDivElement>();
constructor(props: BaseSlideContainerProps) {
- super();
+ super(props);
this.changeSkin(props.config.container as string, 'default');
}
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
}
@@ -97,7 +98,7 @@ export class SlideContainer extends Component<BaseSlideContainerProps> {
*/
changeSkin(container: HTMLElement | string, skin: string) {
// Collect all skins
- let root = document.documentElement;
+ const root = document.documentElement;
const id = typeof container === 'string' ? container : container.id;
@@ -125,7 +126,7 @@ export class SlideContainer extends Component<BaseSlideContainerProps> {
});
} else {
// set css variable
- let sheet = getSkinStyleSheet(id);
+ const sheet = getSkinStyleSheet(id);
/**
* covert object to style, remove " and replace , to ;
diff --git a/packages/ui-plugin-slides/src/View/Toolbar/Toolbar.tsx b/packages/ui-plugin-slides/src/View/Toolbar/Toolbar.tsx
index 530e4147c1..b530a4d05e 100644
--- a/packages/ui-plugin-slides/src/View/Toolbar/Toolbar.tsx
+++ b/packages/ui-plugin-slides/src/View/Toolbar/Toolbar.tsx
@@ -1,4 +1,5 @@
-import { AppContext, AppContextValues, BaseComponentProps, Button, Component, Container, createRef, debounce, PreactContext, Select, Tooltip } from '@univerjs/base-ui';
+import { AppContext, BaseComponentProps, Button, Container, debounce, Select, Tooltip, CustomLabel } from '@univerjs/base-ui';
+import { Component, createRef } from 'preact';
import { SlideUIPlugin } from '../..';
import { SLIDE_UI_PLUGIN_NAME } from '../../Basics';
import { IToolbarItemProps } from '../../Controller';
@@ -18,7 +19,7 @@ interface IState {
}
export class Toolbar extends Component<IProps, IState> {
- static contextType: PreactContext<Partial<AppContextValues>> = AppContext;
+ static override contextType = AppContext;
toolbarRef = createRef();
@@ -37,6 +38,11 @@ export class Toolbar extends Component<IProps, IState> {
this.setToolbarListWidth();
}, 50);
+ constructor(props: IProps) {
+ super(props);
+ this.initialize();
+ }
+
initialize() {
this.state = {
// Button contains main button and drop down arrow, translation file contains main and right
@@ -54,7 +60,7 @@ export class Toolbar extends Component<IProps, IState> {
* TODO : 点击其他地方需要隐藏more buttons
*/
showMore = () => {
- let showMore = this.state.showMore;
+ const showMore = this.state.showMore;
this.setState({ showMore: !showMore });
if (!showMore) {
@@ -171,12 +177,12 @@ export class Toolbar extends Component<IProps, IState> {
}
};
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
window.addEventListener('resize', this.debounceSetToolbarListWidth);
}
- componentWillUnmount() {
+ override componentWillUnmount() {
window.removeEventListener('resize', this.debounceSetToolbarListWidth);
}
@@ -188,7 +194,7 @@ export class Toolbar extends Component<IProps, IState> {
return (
<Tooltip title={item.tooltip} placement={'bottom'}>
<Button unActive={item.unActive} className={styles.textButton} type="text" active={item.active} onClick={item.onClick}>
- {this.getLabel(item.label)}
+ <CustomLabel label={item.label} />
</Button>
</Tooltip>
);
@@ -226,9 +232,11 @@ export class Toolbar extends Component<IProps, IState> {
{this.getToolbarList(defaultToolList)}
<div ref={this.moreBtnRef} className={styles.moreButton} style={{ visibility: moreToolList.length ? 'visible' : 'hidden' }}>
- <Tooltip title={this.getLocale('toolbar.toolMoreTip')} placement={'bottom'}>
+ <Tooltip title={(<CustomLabel label="toolbar.toolMoreTip" />) as unknown as string} placement={'bottom'}>
<Button type="text" onClick={this.showMore}>
- <div style={{ fontSize: '14px' }}>{this.getLocale('toolbar.toolMore')}</div>
+ <div style={{ fontSize: '14px' }}>
+ <CustomLabel label="toolbar.toolMore" />
+ </div>
</Button>
</Tooltip>
</div>
diff --git a/packages/ui-plugin-slides/src/View/index.tsx b/packages/ui-plugin-slides/src/View/index.tsx
index 92f17109d3..d44ab2bb86 100644
--- a/packages/ui-plugin-slides/src/View/index.tsx
+++ b/packages/ui-plugin-slides/src/View/index.tsx
@@ -1,4 +1,5 @@
-import { isElement, render } from '@univerjs/base-ui';
+import { isElement } from '@univerjs/base-ui';
+import { render } from 'preact';
import { App, BaseUIProps } from './App';
interface BaseSlideUIConfig extends BaseUIProps {