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.

xiugai

tonytonychopper1237ad84dbfbd97
diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsx
index e2ed9e8d26..fd7be3883b 100644
--- a/examples/univer-sheet-ts/src/main.tsx
+++ b/examples/univer-sheet-ts/src/main.tsx
@@ -67,7 +67,7 @@ univer.install(
container: 'universheet',
})
);
-// FormulaPlugin.create(DEFAULT_FORMULA_DATA_DEMO1).installTo(universheet);
+FormulaPlugin.create(DEFAULT_FORMULA_DATA_DEMO).installTo(universheet);
// sheets-plugin-ui univer.install(new SheetsUI)
// sheets-plugin-ui univer.install(new SheetsUI
// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO);
diff --git a/packages/base-ui/src/BaseComponent.ts b/packages/base-ui/src/BaseComponent.ts
index 623e481d90..826b95261c 100644
--- a/packages/base-ui/src/BaseComponent.ts
+++ b/packages/base-ui/src/BaseComponent.ts
@@ -54,17 +54,11 @@ export interface BaseButtonProps extends BaseComponentProps {
style?: JSX.CSSProperties;
unActive?: boolean;
}
-export interface BaseCellRangeModalProps extends BaseComponentProps {
- placeholderProps?: string;
- valueProps?: string;
-}
+
// component class
export interface ButtonComponent extends BaseComponent<BaseButtonProps> {
render(): JSXComponent<BaseButtonProps>;
}
-export interface CellRangeModalComponent extends BaseComponent<BaseCellRangeModalProps> {
- render(): JSXComponent<BaseCellRangeModalProps>;
-}
// component type
export type PropsFrom<T> = T extends BaseComponent<infer Props> ? Props : void;
diff --git a/packages/base-ui/src/Components/CellRange/CellRange.tsx b/packages/base-ui/src/Components/CellRange/CellRange.tsx
new file mode 100644
index 0000000000..c9ae28d4ec
--- /dev/null
+++ b/packages/base-ui/src/Components/CellRange/CellRange.tsx
@@ -0,0 +1,89 @@
+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';
+
+export interface BaseCellRangeModalProps extends BaseComponentProps {
+ value?: string;
+ placeholder?: string;
+ title?: string;
+ contentPlaceholder?: string;
+ onClick?: (e: Event) => void;
+ onChange?: (e: Event) => void;
+}
+
+type IState = {
+ value: string;
+ show: boolean;
+};
+
+export class CellRange extends Component<BaseCellRangeModalProps, IState> {
+ ref = createRef();
+
+ group: ModalButtonGroup[];
+
+ constructor(props: BaseCellRangeModalProps) {
+ super();
+
+ this.state = {
+ value: props.value ?? '',
+ show: false,
+ };
+
+ this.group = [
+ {
+ label: 'button.confirm',
+ type: 'primary',
+ onClick: props.onClick,
+ },
+ ];
+ }
+
+ showModal(show: boolean) {
+ this.setState({
+ show,
+ });
+ }
+
+ /**
+ * modify input value when success
+ */
+ handleOk = (e: Event) => {
+ const { onClick } = this.props;
+ const value = this.ref.current.getValue();
+ onClick?.(e);
+ this.showModal(false);
+ };
+
+ handleChange = (e: Event) => {
+ const { onChange } = this.props;
+ onChange?.(e);
+ };
+
+ componentWillReceiveProps(props: BaseCellRangeModalProps) {
+ if (props.value !== this.state.value) {
+ this.setState({
+ value: props.value,
+ });
+ }
+ }
+
+ render() {
+ const { placeholder, title, contentPlaceholder } = this.props;
+ const { value, show } = this.state;
+
+ return (
+ <div className={styles.cellRangeModal}>
+ <Input placeholder={placeholder} value={value} onChange={this.handleChange}></Input>
+ <span className={styles.cellModalIcon} onClick={() => this.showModal(true)}>
+ <Icon.Sheet.TableIcon />
+ </span>
+ <Modal title={title} visible={show} group={this.group}>
+ <Input readonly={true} placeholder={contentPlaceholder} value={value} ref={this.ref}></Input>
+ </Modal>
+ </div>
+ );
+ }
+}
diff --git a/packages/base-ui/src/Components/CellRangeModal/cell-range-modal-zh.md b/packages/base-ui/src/Components/CellRange/cell-range-zh.md
similarity index 95%
rename from packages/base-ui/src/Components/CellRangeModal/cell-range-modal-zh.md
rename to packages/base-ui/src/Components/CellRange/cell-range-zh.md
index 1461c186f5..9437dd87f1 100644
--- a/packages/base-ui/src/Components/CellRangeModal/cell-range-modal-zh.md
+++ b/packages/base-ui/src/Components/CellRange/cell-range-zh.md
@@ -1,45 +1,45 @@
----
-category: Components
-type: 通用
-title: CellRangeModal
-subtitle: 范围选择组件
-cover: ''
----
-
-## 介绍
-
-范围选择组件
-
-## API
-
-属性说明如下:
-
-```jsx
-type ModalButtonGroup = {
- name?: string,
- label?: string,
- onClick?: (e?: any) => void,
- type?: string,
-};
-
-interface ModalProps extends ModalBaseProps {
- show?: boolean;
- name?: string;
-}
-```
-
-| 属性 | 说明 | 类型 | 默认值 |
-
-| placeholderProps | 范围选择输入框占位符 | string | - |
-| valueProps | 范围 | string | - |
-| placeholderState | 范围选择确定框占位符 | string | - |
-| modalData | 范围选择确定模态框内容 | ModalProps | - |
-| value | 范围选择确定框值 | string | - |
-
-## 案例
-
-```jsx
-import { CellRangeModal } from '@univerjs/style-univer';
-
-<CellRangeModal placeholderProps="请使用字符串" valueProps="A10:B10"></CellRangeModal>;
-```
+---
+category: Components
+type: 通用
+title: CellRangeModal
+subtitle: 范围选择组件
+cover: ''
+---
+
+## 介绍
+
+范围选择组件
+
+## API
+
+属性说明如下:
+
+```jsx
+type ModalButtonGroup = {
+ name?: string,
+ label?: string,
+ onClick?: (e?: any) => void,
+ type?: string,
+};
+
+interface ModalProps extends ModalBaseProps {
+ show?: boolean;
+ name?: string;
+}
+```
+
+| 属性 | 说明 | 类型 | 默认值 |
+
+| placeholderProps | 范围选择输入框占位符 | string | - |
+| valueProps | 范围 | string | - |
+| placeholderState | 范围选择确定框占位符 | string | - |
+| modalData | 范围选择确定模态框内容 | ModalProps | - |
+| value | 范围选择确定框值 | string | - |
+
+## 案例
+
+```jsx
+import { CellRangeModal } from '@univerjs/style-univer';
+
+<CellRangeModal placeholderProps="请使用字符串" valueProps="A10:B10"></CellRangeModal>;
+```
diff --git a/packages/base-ui/src/Components/CellRangeModal/cell-range-modal.md b/packages/base-ui/src/Components/CellRange/cell-range.md
similarity index 95%
rename from packages/base-ui/src/Components/CellRangeModal/cell-range-modal.md
rename to packages/base-ui/src/Components/CellRange/cell-range.md
index 84a7c5a049..3bfa8b72e7 100644
--- a/packages/base-ui/src/Components/CellRangeModal/cell-range-modal.md
+++ b/packages/base-ui/src/Components/CellRange/cell-range.md
@@ -1,44 +1,44 @@
----
-category: Components
-type: General
-title: CellRangeModal
-cover: ''
----
-
-## Introduce
-
-CellRangeModal Component
-
-## API
-
-Property Introduction:
-
-```jsx
-type ModalButtonGroup = {
- name?: string,
- label?: string,
- onClick?: (e?: any) => void,
- type?: string,
-};
-
-interface ModalProps extends ModalBaseProps {
- show?: boolean;
- name?: string;
-}
-```
-
-| Property | Description | Type | Default |
-
-| placeholderProps | placeholders of Range select input | string | - |
-| valueProps | range value | string | - |
-| placeholderState | placeholder of Range selection confirmation input | string | - |
-| modalData | contents of the range selection modal | ModalProps | - |
-| value | range value of range selection modal | string | - |
-
-## Case
-
-```jsx
-import { CellRangeModal } from '@univerjs/style-univer';
-
-<CellRangeModal placeholderProps="请使用字符串" valueProps="A10:B10"></CellRangeModal>;
-```
+---
+category: Components
+type: General
+title: CellRangeModal
+cover: ''
+---
+
+## Introduce
+
+CellRangeModal Component
+
+## API
+
+Property Introduction:
+
+```jsx
+type ModalButtonGroup = {
+ name?: string,
+ label?: string,
+ onClick?: (e?: any) => void,
+ type?: string,
+};
+
+interface ModalProps extends ModalBaseProps {
+ show?: boolean;
+ name?: string;
+}
+```
+
+| Property | Description | Type | Default |
+
+| placeholderProps | placeholders of Range select input | string | - |
+| valueProps | range value | string | - |
+| placeholderState | placeholder of Range selection confirmation input | string | - |
+| modalData | contents of the range selection modal | ModalProps | - |
+| value | range value of range selection modal | string | - |
+
+## Case
+
+```jsx
+import { CellRangeModal } from '@univerjs/style-univer';
+
+<CellRangeModal placeholderProps="请使用字符串" valueProps="A10:B10"></CellRangeModal>;
+```
diff --git a/packages/base-ui/src/Components/CellRangeModal/index.module.less b/packages/base-ui/src/Components/CellRange/index.module.less
similarity index 100%
rename from packages/base-ui/src/Components/CellRangeModal/index.module.less
rename to packages/base-ui/src/Components/CellRange/index.module.less
diff --git a/packages/base-ui/src/Components/CellRange/index.ts b/packages/base-ui/src/Components/CellRange/index.ts
new file mode 100644
index 0000000000..0fa08e1641
--- /dev/null
+++ b/packages/base-ui/src/Components/CellRange/index.ts
@@ -0,0 +1 @@
+export * from './CellRange';
diff --git a/packages/base-ui/src/Components/CellRangeModal/CellRangeModal.tsx b/packages/base-ui/src/Components/CellRangeModal/CellRangeModal.tsx
deleted file mode 100644
index 7b45e6b627..0000000000
--- a/packages/base-ui/src/Components/CellRangeModal/CellRangeModal.tsx
+++ /dev/null
@@ -1,170 +0,0 @@
-import { SheetContext, Workbook, Worksheet } from '@univerjs/core';
-import { BaseCellRangeModalProps, CellRangeModalComponent, JSXComponent } from '../../BaseComponent';
-import { Component, createRef } from '../../Framework';
-import { Icon, Input, Modal, ModalProps } from '../index';
-import styles from './index.module.less';
-
-// type BaseCellRangeModalProps = {
-// placeholderProps?: string;
-// valueProps?: string;
-// };
-type CellModalState = {
- modalData: ModalProps[];
- placeholderState: placeholder;
- value: string;
-};
-
-type placeholder = {
- name?: string;
- label?: string;
-};
-
-export class CellRangeModal extends Component<BaseCellRangeModalProps, CellModalState> {
- ref = createRef();
- // refProp = createRef();
-
- state = {
- modalData: [
- {
- name: 'dataValidation.selectCellRange2',
- show: false,
- group: [
- {
- name: 'button.confirm',
- type: 'primary',
- onClick: () => this.handleOk(),
- },
- {
- name: 'button.cancel',
- },
- ],
- },
- ],
- placeholderState: {
- name: 'dataValidation.selectCellRange2',
- },
- value: '',
- };
-
- showModal = (name: string, isShow: boolean) => {
- let { modalData } = this.state;
- const index = modalData.findIndex((item) => item.name === name);
- if (index > -1) {
- modalData[index].show = isShow;
- }
- this.setValue({ modalData });
- };
-
- /**
- * modify input value when success
- */
- handleOk = () => {
- const value = this.ref.current.getValue();
- this.showModal('dataValidation.selectCellRange2', false);
- this.setValue({ value });
- // this.refProp.current.setValue(value);
- };
-
- setLocale() {
- const locale = this.context.locale;
-
- this.setState((prevState) => {
- let { modalData, placeholderState } = prevState;
- modalData.forEach((item) => {
- item.title = locale.get(item.locale);
- if (item.group && item.group.length) {
- item.group.forEach((ele) => {
- ele.label = locale.get(ele.locale);
- });
- }
- });
-
- placeholderState.label = locale.get(placeholderState.name);
-
- return {
- modalData,
- placeholderState,
- };
- });
- }
-
- setValue = (value: object, fn?: () => void) => {
- this.setState(
- (prevState) => ({
- ...value,
- }),
- fn
- );
- };
-
- componentWillReceiveProps(nextProps: BaseCellRangeModalProps) {
- this.setValue({ value: nextProps.valueProps });
- }
-
- componentDidMount() {
- this.setValue({ value: this.props.valueProps });
- // init Locale message
- this.setLocale();
-
- const cellRangeContext = this._context as SheetContext;
- // when change Locale, update Locale message
- // do not use componentWillUpdate,it will listen all state changes
- this._localeObserver = this._context
- .getObserverManager()
- .getObserver<Workbook>('onAfterChangeUILocaleObservable', 'workbook')
- ?.add(() => {
- this.setLocale();
- });
-
- this._localeObserver1 = this._context
- .getObserverManager()
- .getObserver<Worksheet>('onAfterSetSelectionObservable', 'worksheet')
- ?.add((text) => {
- console.dir(text);
- });
- }
-
- componentWillUnmount() {
- // this._context.getObserverManager().getObserver<Workbook>('onAfterChangeUILocaleObservable', 'workbook')?.remove(this._localeObserver);
- // this._context.onAfterChangeUILocaleObservable.remove(this._localeObserver);
- }
-
- // change cell range
- changeRange = (e: Event) => {
- const target = e.target as HTMLInputElement;
- this.setValue({ value: target.value });
- };
-
- // 点击的时候设置selection
- showRange = () => {
- this.showModal('dataValidation.selectCellRange2', true);
- this._context.getWorkBook().getActiveSheet()?.getSelection().setSelection({ selection: this.state.value });
- };
-
- render(props: BaseCellRangeModalProps, state: CellModalState) {
- const { modalData, placeholderState, value } = state;
- const { placeholderProps } = props;
- return (
- <div className={styles.cellRangeModal}>
- <Input placeholder={placeholderProps} value={value} onChange={(e: Event) => this.changeRange(e)}></Input>
- <span className={styles.cellModalIcon} onClick={this.showRange}>
- <Icon.Sheet.TableIcon />
- </span>
- {modalData.map((item) => {
- if (!item.show) return;
- return (
- <Modal title={item.title} visible={item.show} group={item.group} onCancel={item.onCancel}>
- <Input readonly={true} placeholder={placeholderState.label} value={value} ref={this.ref}></Input>
- </Modal>
- );
- })}
- </div>
- );
- }
-}
-
-export class UniverCellRangeModal implements CellRangeModalComponent {
- render(): JSXComponent<BaseCellRangeModalProps> {
- return CellRangeModal;
- }
-}
diff --git a/packages/base-ui/src/Components/CellRangeModal/index.ts b/packages/base-ui/src/Components/CellRangeModal/index.ts
deleted file mode 100644
index 70b432dbf4..0000000000
--- a/packages/base-ui/src/Components/CellRangeModal/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './CellRangeModal';
diff --git a/packages/base-ui/src/Components/Confirm/Confirm.tsx b/packages/base-ui/src/Components/Confirm/Confirm.tsx
new file mode 100644
index 0000000000..930de2bc86
--- /dev/null
+++ b/packages/base-ui/src/Components/Confirm/Confirm.tsx
@@ -0,0 +1,70 @@
+import { Component } from '../../Framework';
+import { Modal } from '../Modal';
+import styles from './index.module.less';
+
+interface BaseConfirmProps {
+ title: string;
+ content: string;
+ onClick?: () => void;
+ show?: boolean;
+}
+
+interface IState {
+ show: boolean;
+}
+
+export class Confirm extends Component<BaseConfirmProps, IState> {
+ constructor(props: BaseConfirmProps) {
+ super();
+ this.state = {
+ show: props.show ?? false,
+ };
+ }
+
+ showModal(show: boolean) {
+ this.setState({
+ show,
+ });
+ }
+
+ handleClick() {
+ const { onClick } = this.props;
+ onClick?.();
+ this.showModal(false);
+ }
+
+ getGroup() {
+ const group = [
+ {
+ label: this.getLocale('button.confirm'),
+ type: 'primary',
+ onClick: () => this.handleClick(),
+ },
+ {
+ label: this.getLocale('button.cancel'),
+ onClick: () => this.showModal(false),
+ },
+ ];
+ return group;
+ }
+
+ componentWillReceiveProps(props: BaseConfirmProps): void {
+ if (props.show !== this.props.show) {
+ this.setState({
+ show: props.show,
+ });
+ }
+ }
+
+ render() {
+ const { title, content } = this.props;
+ const { show } = this.state;
+ return (
+ <div className={styles.confirmModal}>
+ <Modal visible={show} isDrag={true} title={title} group={this.getGroup()}>
+ {content}
+ </Modal>
+ </div>
+ );
+ }
+}
diff --git a/packages/base-ui/src/Components/Confirm/index.module.less b/packages/base-ui/src/Components/Confirm/index.module.less
new file mode 100644
index 0000000000..cf4347d7e9
--- /dev/null
+++ b/packages/base-ui/src/Components/Confirm/index.module.less
@@ -0,0 +1,27 @@
+@import '../../Basics/CSS/Skin/base.module.less';
+
+.confirm-modal {
+ .modal-mask {
+ background-color: rgba(255, 255, 255, 0.6);
+ }
+
+ .modal-header {
+ position: relative;
+ }
+
+ .modal-close {
+ position: absolute;
+ right: 1.5rem;
+ top: 0
+ }
+
+ .drag {
+ box-shadow: 0 4px 16px rgb(0 0 0 / 20%);
+ background-clip: padding-box;
+ border: 1px solid rgba(0, 0, 0, .333)
+ }
+
+ .modal-body {
+ color: rgba(0, 0, 0, 0.6);
+ }
+}
\ No newline at end of file
diff --git a/packages/base-ui/src/Components/Confirm/index.ts b/packages/base-ui/src/Components/Confirm/index.ts
new file mode 100644
index 0000000000..d8e1c97b8c
--- /dev/null
+++ b/packages/base-ui/src/Components/Confirm/index.ts
@@ -0,0 +1 @@
+export * from './Confirm';
diff --git a/packages/base-ui/src/Components/Drag/Drag.tsx b/packages/base-ui/src/Components/Drag/Drag.tsx
index 3bab80c82b..f94384fc01 100644
--- a/packages/base-ui/src/Components/Drag/Drag.tsx
+++ b/packages/base-ui/src/Components/Drag/Drag.tsx
@@ -95,13 +95,13 @@ class Drag extends Component<BaseDragProps, IState> {
}
render() {
- const { isDrag } = this.props;
+ const { isDrag, className = '' } = this.props;
return (
<>
{isDrag ? (
<div
ref={this.root}
- className={styles.drag}
+ className={`${styles.drag} ${className}`}
style={{ top: this.state.top, left: this.state.left }}
onMouseUp={this.onMouseUp.bind(this)}
onMouseDown={this.onMouseDown.bind(this)}
diff --git a/packages/base-ui/src/Components/FormatModal/FormatModal.tsx b/packages/base-ui/src/Components/FormatModal/FormatModal.tsx
index 17a627e6fe..390f0e69ea 100644
--- a/packages/base-ui/src/Components/FormatModal/FormatModal.tsx
+++ b/packages/base-ui/src/Components/FormatModal/FormatModal.tsx
@@ -1,7 +1,6 @@
import { Nullable, Observer, Workbook } from '@univerjs/core';
import { Component } from '../../Framework';
-import { JSXComponent } from '../../BaseComponent';
-import { BaseFormatModalProps, FormatModalComponent } from '../../Interfaces';
+import { BaseFormatModalProps } from '../../Interfaces';
import { Modal, Ul } from '../index';
import styles from './index.module.less';
@@ -161,9 +160,3 @@ export class FormatModal extends Component<BaseFormatModalProps, FormatModalStat
);
}
}
-
-export class UniverFormatModal implements FormatModalComponent {
- render(): JSXComponent<BaseFormatModalProps> {
- return FormatModal;
- }
-}
diff --git a/packages/base-ui/src/Components/Item/Item.tsx b/packages/base-ui/src/Components/Item/Item.tsx
index e23150f51f..b79e483eb0 100644
--- a/packages/base-ui/src/Components/Item/Item.tsx
+++ b/packages/base-ui/src/Components/Item/Item.tsx
@@ -11,12 +11,6 @@ export interface BaseItemProps extends BaseMenuItem {
}
export class Item extends Component<BaseItemProps> {
- // getLabelLocale(label: ComponentChildren) {
- // if (typeof label === 'string') {
- // return this.getLocale(label);
- // }
- // }
-
render() {
const { selected, label, suffix, disabled } = this.props;
return (
@@ -28,7 +22,6 @@ export class Item extends Component<BaseItemProps> {
) : (
''
)}
- {/* <span className={styles.selectItemContent}>{this.getLabelLocale(label)}</span> */}
<span className={styles.selectItemContent}>{label}</span>
{suffix ? <span className={styles.selectItemSuffix}>{suffix}</span> : ''}
</div>
diff --git a/packages/base-ui/src/Components/Modal/Modal.tsx b/packages/base-ui/src/Components/Modal/Modal.tsx
index 162a831af3..3adb83b5cd 100644
--- a/packages/base-ui/src/Components/Modal/Modal.tsx
+++ b/packages/base-ui/src/Components/Modal/Modal.tsx
@@ -65,7 +65,7 @@ class Modal extends Component<BaseModalProps, IState> {
}}
></div>
) : null}
- <Drag isDrag={isDrag}>
+ <Drag isDrag={isDrag} className={styles.modalDrag}>
<div
className={`${isDrag ? styles.modalDargWrapper : styles.modalWrapper}`}
style={{
@@ -91,7 +91,7 @@ class Modal extends Component<BaseModalProps, IState> {
<div className={styles.modalFooter}>
{group.map((item) => (
<Button type={item.type} onClick={() => this.handleClick(item.onClick)}>
- {item.label}
+ {this.getLocale(item.label)}
</Button>
))}
</div>
diff --git a/packages/base-ui/src/Components/Modal/index.module.less b/packages/base-ui/src/Components/Modal/index.module.less
index f17667da01..0d2e2aea23 100644
--- a/packages/base-ui/src/Components/Modal/index.module.less
+++ b/packages/base-ui/src/Components/Modal/index.module.less
@@ -21,6 +21,12 @@
background-color: rgba(255, 255, 255, 1);
}
+.modal-drag {
+ box-shadow: 0 4px 16px rgb(0 0 0 / 20%);
+ background-clip: padding-box;
+ border: 1px solid rgba(0, 0, 0, .333)
+}
+
.modal-darg-wrapper {
width: 50%;
overflow: auto;
@@ -54,4 +60,4 @@
margin-right: 0.5em;
font-size: 1rem !important;
}
-}
+}
\ No newline at end of file
diff --git a/packages/base-ui/src/Components/Prompt/Prompt.tsx b/packages/base-ui/src/Components/Prompt/Prompt.tsx
new file mode 100644
index 0000000000..001bfe705d
--- /dev/null
+++ b/packages/base-ui/src/Components/Prompt/Prompt.tsx
@@ -0,0 +1,70 @@
+import { Component } from '../../Framework';
+import { Modal } from '../Modal';
+import styles from './index.module.less';
+
+interface BaseConfirmProps {
+ title: string;
+ content: string;
+ onClick?: () => void;
+ show?: boolean;
+}
+
+interface IState {
+ show: boolean;
+}
+
+export class Prompt extends Component<BaseConfirmProps, IState> {
+ constructor(props: BaseConfirmProps) {
+ super();
+ this.state = {
+ show: props.show ?? false,
+ };
+ }
+
+ showModal(show: boolean) {
+ this.setState({
+ show,
+ });
+ }
+
+ handleClick() {
+ const { onClick } = this.props;
+ onClick?.();
+ this.showModal(false);
+ }
+
+ getGroup() {
+ const group = [
+ {
+ label: this.getLocale('button.confirm'),
+ type: 'primary',
+ onClick: () => this.handleClick(),
+ },
+ {
+ label: this.getLocale('button.cancel'),
+ onClick: () => this.showModal(false),
+ },
+ ];
+ return group;
+ }
+
+ componentWillReceiveProps(props: BaseConfirmProps): void {
+ if (props.show !== this.props.show) {
+ this.setState({
+ show: props.show,
+ });
+ }
+ }
+
+ render() {
+ const { title, content } = this.props;
+ const { show } = this.state;
+ return (
+ <div className={styles.confirmModal}>
+ <Modal visible={show} isDrag={true} title={title} group={this.getGroup()}>
+ {content}
+ </Modal>
+ </div>
+ );
+ }
+}
diff --git a/packages/base-ui/src/Components/Prompt/index.module.less b/packages/base-ui/src/Components/Prompt/index.module.less
new file mode 100644
index 0000000000..cf4347d7e9
--- /dev/null
+++ b/packages/base-ui/src/Components/Prompt/index.module.less
@@ -0,0 +1,27 @@
+@import '../../Basics/CSS/Skin/base.module.less';
+
+.confirm-modal {
+ .modal-mask {
+ background-color: rgba(255, 255, 255, 0.6);
+ }
+
+ .modal-header {
+ position: relative;
+ }
+
+ .modal-close {
+ position: absolute;
+ right: 1.5rem;
+ top: 0
+ }
+
+ .drag {
+ box-shadow: 0 4px 16px rgb(0 0 0 / 20%);
+ background-clip: padding-box;
+ border: 1px solid rgba(0, 0, 0, .333)
+ }
+
+ .modal-body {
+ color: rgba(0, 0, 0, 0.6);
+ }
+}
\ No newline at end of file
diff --git a/packages/base-ui/src/Components/Prompt/index.ts b/packages/base-ui/src/Components/Prompt/index.ts
new file mode 100644
index 0000000000..1987f18263
--- /dev/null
+++ b/packages/base-ui/src/Components/Prompt/index.ts
@@ -0,0 +1 @@
+export * from './Prompt';
diff --git a/packages/base-ui/src/Components/Select/Select.tsx b/packages/base-ui/src/Components/Select/Select.tsx
index bcb9059f39..5dc2feb266 100644
--- a/packages/base-ui/src/Components/Select/Select.tsx
+++ b/packages/base-ui/src/Components/Select/Select.tsx
@@ -1,5 +1,6 @@
+import { PureComponent } from 'preact/compat';
import { Icon } from '..';
-import { ComponentChildren, Component, createRef, RefObject } from '../../Framework';
+import { ComponentChildren, createRef, RefObject } from '../../Framework';
import { BaseMenuItem } from '../../Interfaces';
import { Dropdown } from '../Dropdown';
import { Input } from '../Input';
@@ -58,7 +59,7 @@ interface IState {
value: any;
}
-export class Select extends Component<BaseSelectProps, IState> {
+export class Select extends PureComponent<BaseSelectProps, IState> {
ColorRef: any;
onClick: (...arg: any) => void;
@@ -224,8 +225,8 @@ export class Select extends Component<BaseSelectProps, IState> {
}
componentWillReceiveProps(nextProps: BaseSelectProps) {
- this.props = Object.assign(this.props, nextProps);
- this.initData();
+ // this.props = Object.assign(this.props, nextProps);
+ // this.initData();
}
resetMenu(children: BaseSelectChildrenProps[], hideSelectedIcon?: boolean) {
diff --git a/packages/base-ui/src/Components/index.ts b/packages/base-ui/src/Components/index.ts
index ce9e5422f8..2117427990 100644
--- a/packages/base-ui/src/Components/index.ts
+++ b/packages/base-ui/src/Components/index.ts
@@ -1,7 +1,6 @@
import { Avatar } from './Avatar';
import { Button } from './Button';
import { BorderLine } from './CanvasIcon';
-import { CellRangeModal } from './CellRangeModal';
import { Checkbox, CheckboxGroup } from './Checkbox';
import { Collapse, Panel } from './Collapse';
import { ColorPicker } from './ColorPicker';
@@ -25,8 +24,12 @@ import { Tab, TabPane } from './Tabs';
import { Tooltip } from './Tooltip';
import { Ul } from './Ul';
+export * from './Prompt';
+
export * from './Select';
+export * from './CellRange';
+
export {
Avatar,
Button,
@@ -52,7 +55,6 @@ export {
FormatModal,
Checkbox,
CheckboxGroup,
- CellRangeModal,
Tab,
TabPane,
ColorPickerCircleButton,
diff --git a/packages/base-ui/src/Interfaces/Drag.ts b/packages/base-ui/src/Interfaces/Drag.ts
index a7e24cbe9f..5401101cbb 100644
--- a/packages/base-ui/src/Interfaces/Drag.ts
+++ b/packages/base-ui/src/Interfaces/Drag.ts
@@ -2,6 +2,7 @@ import { BaseComponent, JSXComponent } from '../BaseComponent';
export interface BaseDragProps {
isDrag: boolean;
+ className: string;
}
export interface DragComponent extends BaseComponent<BaseDragProps> {
diff --git a/packages/core/src/Shared/ObjectMatrix.ts b/packages/core/src/Shared/ObjectMatrix.ts
index 455e8c8db3..00dea32a2e 100644
--- a/packages/core/src/Shared/ObjectMatrix.ts
+++ b/packages/core/src/Shared/ObjectMatrix.ts
@@ -145,6 +145,7 @@ export class ObjectMatrix<T> {
insertRows(rowIndex: number, matrix: ObjectMatrix<T>) {
this._option.inserts(rowIndex, matrix._option);
+ console.dir(this._option);
}
spliceColumns(start: number, count: number): ObjectMatrix<T> {
diff --git a/packages/core/src/Sheets/Apply/InsertDataColumn.ts b/packages/core/src/Sheets/Apply/InsertDataColumn.ts
index ca5673736e..ea9cc04cf3 100644
--- a/packages/core/src/Sheets/Apply/InsertDataColumn.ts
+++ b/packages/core/src/Sheets/Apply/InsertDataColumn.ts
@@ -1,6 +1,7 @@
import { ICellData } from '../../Interfaces';
import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';
-import { CommandUnit, IInsertColumnDataActionData } from '../../Command';
+import { CommandUnit } from '../../Command';
+import { IInsertColumnDataActionData } from '../Action';
/**
*
diff --git a/packages/core/src/Sheets/Apply/InsertDataRow.ts b/packages/core/src/Sheets/Apply/InsertDataRow.ts
index a77de18e07..7195177e83 100644
--- a/packages/core/src/Sheets/Apply/InsertDataRow.ts
+++ b/packages/core/src/Sheets/Apply/InsertDataRow.ts
@@ -1,6 +1,7 @@
import { ICellData } from '../../Interfaces';
import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';
-import { CommandUnit, IInsertRowDataActionData } from '../../Command';
+import { CommandUnit } from '../../Command';
+import { IInsertRowDataActionData } from '../Action';
/**
*
diff --git a/packages/core/src/Sheets/Apply/InsertRow.ts b/packages/core/src/Sheets/Apply/InsertRow.ts
index ddf76ab1da..e9958b1816 100644
--- a/packages/core/src/Sheets/Apply/InsertRow.ts
+++ b/packages/core/src/Sheets/Apply/InsertRow.ts
@@ -1,6 +1,7 @@
import { IRowData } from '../../Interfaces';
import { ObjectArray, ObjectArrayPrimitiveType } from '../../Shared';
-import { CommandUnit, IInsertRowActionData } from '../../Command';
+import { CommandUnit } from '../../Command';
+import { IInsertRowActionData } from '../Action';
/**
* Inserts addData into rowData
diff --git a/packages/sheets-plugin-formula/src/Basic/Const/FunctionList.ts b/packages/sheets-plugin-formula/src/Basic/Const/FunctionList.ts
index 0703c201c0..60bb14ca26 100644
--- a/packages/sheets-plugin-formula/src/Basic/Const/FunctionList.ts
+++ b/packages/sheets-plugin-formula/src/Basic/Const/FunctionList.ts
@@ -33,52 +33,52 @@ export interface FormulaType {
export const SelectCategoryType = [
{
- locale: 'formula.formulaMore.Math',
+ label: 'formula.formulaMore.Math',
},
{
- locale: 'formula.formulaMore.Statistical',
+ label: 'formula.formulaMore.Statistical',
},
{
- locale: 'formula.formulaMore.Lookup',
+ label: 'formula.formulaMore.Lookup',
},
{
- locale: 'formula.formulaMore.universheet',
+ label: 'formula.formulaMore.universheet',
},
{
- locale: 'formula.formulaMore.dataMining',
+ label: 'formula.formulaMore.dataMining',
},
{
- locale: 'formula.formulaMore.Database',
+ label: 'formula.formulaMore.Database',
},
{
- locale: 'formula.formulaMore.Date',
+ label: 'formula.formulaMore.Date',
},
{
- locale: 'formula.formulaMore.Filter',
+ label: 'formula.formulaMore.Filter',
},
{
- locale: 'formula.formulaMore.Financial',
+ label: 'formula.formulaMore.Financial',
},
{
- locale: 'formula.formulaMore.Engineering',
+ label: 'formula.formulaMore.Engineering',
},
{
- locale: 'formula.formulaMore.Logical',
+ label: 'formula.formulaMore.Logical',
},
{
- locale: 'formula.formulaMore.Operator',
+ label: 'formula.formulaMore.Operator',
},
{
- locale: 'formula.formulaMore.Text',
+ label: 'formula.formulaMore.Text',
},
{
- locale: 'formula.formulaMore.Parser',
+ label: 'formula.formulaMore.Parser',
},
{
- locale: 'formula.formulaMore.Array',
+ label: 'formula.formulaMore.Array',
},
{
- locale: 'formula.formulaMore.other',
+ label: 'formula.formulaMore.other',
},
];
@@ -106,8 +106,19 @@ export const FunList: FormulaType[] = [
],
},
{
- n: 'SUMIF1',
- t: 1,
+ n: 'TAN',
+ t: 0,
+ d: 'formula.functionList.TAN.d',
+ p: [
+ {
+ name: 'formula.functionList.TAN.p.rangeNumber.name',
+ detail: 'formula.functionList.TAN.p.rangeNumber.detail',
+ },
+ ],
+ },
+ {
+ n: 'SUMIF2',
+ t: 2,
d: 'formula.functionList.SUMIF.d',
},
{
@@ -141,7 +152,3 @@ export const FunList: FormulaType[] = [
d: 'formula.functionList.SUMIF.d',
},
];
-
-// export { SelectCategoryType, FunList };
-
-// export type { FunctionList, P };
diff --git a/packages/sheets-plugin-formula/src/Basic/index.ts b/packages/sheets-plugin-formula/src/Basic/index.ts
index cf54b84a75..744f1ab56c 100644
--- a/packages/sheets-plugin-formula/src/Basic/index.ts
+++ b/packages/sheets-plugin-formula/src/Basic/index.ts
@@ -1,3 +1,3 @@
export * from './Cache';
export * from './Const';
-export * from './Interfaces'
+export * from './Interfaces';
diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaController.tsx b/packages/sheets-plugin-formula/src/Controller/FormulaController.tsx
index 4e0c1a0592..d955f9dd30 100644
--- a/packages/sheets-plugin-formula/src/Controller/FormulaController.tsx
+++ b/packages/sheets-plugin-formula/src/Controller/FormulaController.tsx
@@ -81,39 +81,7 @@ export class FormulaController {
// ],
// });
- this._initialize();
- }
-
- private _initialize() {
- this._sheetPlugin
- .getContext()
- .getContextObserver('onAfterChangeActiveSheetObservable')
- .add(() => {
- this._activeSheetId = this._sheetPlugin.getWorkbook().getActiveSheet().getSheetId();
- this.clearArrayFormulaLineControl();
- this.renderArrayFormulaLineControl();
- });
-
- this._sheetPlugin.getObserver('onChangeSelectionObserver')?.add(() => {
- this.clearArrayFormulaLineControl();
- this.renderArrayFormulaLineControl();
- });
- }
-
- private _initRegisterComponent() {
- // this._sheetPlugin.registerComponent(FORMULA_PLUGIN_NAME + FormulaLabel.name, FormulaLabel);
- this._plugin
- .getContext()
- .getUniver()
- .getGlobalContext()
- .getPluginManager()
- .getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)
- .getAppUIController()
- .getSheetContainerController()
- .getMainSlotController()
- .addSlot(FORMULA_PLUGIN_NAME + FormulaLabel.name, {
- component: FormulaLabel,
- });
+ // this._initialize();
}
getDataModel() {
@@ -148,42 +116,6 @@ export class FormulaController {
return this.getWorkbook().getUnitId();
}
- private _toInterpreterCalculateProps(): IInterpreterDatasetConfig {
- const workbook = this._context.getWorkBook();
- const sheets = workbook.getSheets();
- const sheetData: SheetDataType = {};
- const unitData: UnitDataType = {};
- const sheetNameMap: SheetNameMapType = {};
-
- const currentUnitId = workbook.getUnitId();
-
- for (let sheet of sheets) {
- sheetData[sheet.getSheetId()] = sheet.getCellMatrix();
- sheetNameMap[sheet.getName()] = sheet.getSheetId();
- }
-
- unitData[currentUnitId] = sheetData;
-
- const formulaData = this._formulaDataModel.getFormulaData();
-
- const activeSheet = workbook.getActiveSheet();
-
- const rowCount = activeSheet.getRowCount();
- const columnCount = activeSheet.getColumnCount();
-
- return {
- unitData,
- formulaData,
- sheetNameMap,
- currentRow: -1,
- currentColumn: -1,
- currentSheetId: '',
- currentUnitId,
- rowCount,
- columnCount,
- };
- }
-
addArrayFormulaData(value: ArrayFormulaDataType) {
this._formulaDataModel.setArrayFormulaData(value);
@@ -219,4 +151,56 @@ export class FormulaController {
}
});
}
+
+ private _initRegisterComponent() {
+ // this._sheetPlugin.registerComponent(FORMULA_PLUGIN_NAME + FormulaLabel.name, FormulaLabel);
+ this._plugin
+ .getContext()
+ .getUniver()
+ .getGlobalContext()
+ .getPluginManager()
+ .getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)
+ .getAppUIController()
+ .getSheetContainerController()
+ .getMainSlotController()
+ .addSlot(FORMULA_PLUGIN_NAME + FormulaLabel.name, {
+ component: FormulaLabel,
+ });
+ }
+
+ private _toInterpreterCalculateProps(): IInterpreterDatasetConfig {
+ const workbook = this._context.getWorkBook();
+ const sheets = workbook.getSheets();
+ const sheetData: SheetDataType = {};
+ const unitData: UnitDataType = {};
+ const sheetNameMap: SheetNameMapType = {};
+
+ const currentUnitId = workbook.getUnitId();
+
+ for (let sheet of sheets) {
+ sheetData[sheet.getSheetId()] = sheet.getCellMatrix();
+ sheetNameMap[sheet.getName()] = sheet.getSheetId();
+ }
+
+ unitData[currentUnitId] = sheetData;
+
+ const formulaData = this._formulaDataModel.getFormulaData();
+
+ const activeSheet = workbook.getActiveSheet();
+
+ const rowCount = activeSheet.getRowCount();
+ const columnCount = activeSheet.getColumnCount();
+
+ return {
+ unitData,
+ formulaData,
+ sheetNameMap,
+ currentRow: -1,
+ currentColumn: -1,
+ currentSheetId: '',
+ currentUnitId,
+ rowCount,
+ columnCount,
+ };
+ }
}
diff --git a/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts b/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts
index a5ef5719de..edcfbe02e8 100644
--- a/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts
+++ b/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts
@@ -1,13 +1,14 @@
import { ComponentChildren } from '@univerjs/base-ui';
-import { SheetPlugin, CellRangeModal } from '@univerjs/base-sheets';
+import { SheetPlugin } from '@univerjs/base-sheets';
import { PLUGIN_NAMES } from '@univerjs/core';
-import { FORMULA_PLUGIN_NAME, FunctionList, FunList, SelectCategoryType } from '../Basic';
+import { SheetUIPlugin, SHEET_UI_PLUGIN_NAME } from '@univerjs/ui-plugin-sheets';
+import { FormulaType, FORMULA_PLUGIN_NAME, FunList, SelectCategoryType } from '../Basic';
import { FormulaPlugin } from '../FormulaPlugin';
import { SearchFormulaContent } from '../View/UI/SearchFormulaModal/SearchFormulaContent';
import { SearchFormulaModal } from '../View/UI/SearchFormulaModal/SearchFormulaModal';
import { SearchItem } from '../View/UI/SearchFormulaModal/SearchItem';
-interface Label {
+export interface Label {
type?: string;
locale?: string;
label?: string;
@@ -21,19 +22,18 @@ export interface ILabel extends Label {
}
export interface FunListILabel extends Label {
- children?: FunctionList[];
- onClick: (value: FunctionList) => void;
+ children?: FormulaType[];
+ onClick: (value: FormulaType) => void;
}
export interface FunParams {
- funParams: FunctionList;
+ funParams: FormulaType;
}
interface CustomComponent {
name?: string;
props: {
- input?: ILabel;
- select?: ILabel;
+ select?: Label[];
funList?: FunListILabel;
funParams?: FunParams;
calcLocale?: string;
@@ -83,29 +83,21 @@ export class SearchFormulaController {
show: false,
group: [
{
- locale: 'button.confirm',
+ label: 'button.confirm',
type: 'primary',
onClick: this.showSearchItemModal.bind(this),
},
{
- locale: 'button.cancel',
+ label: 'button.cancel',
},
],
onCancel: () => this.showFormulaModal('SearchFormula', false),
children: {
name: FORMULA_PLUGIN_NAME + SearchFormulaContent.name,
props: {
- input: {
- locale: 'formula.formulaMore.findFunctionTitle',
- placeholderLocale: 'formula.formulaMore.tipInputFunctionName',
- },
- select: {
- locale: 'formula.formulaMore.selectCategory',
- children: SelectCategoryType,
- },
+ select: SelectCategoryType,
funList: {
onClick: this.selectFunParams.bind(this),
- locale: 'formula.formulaMore.selectFunctionTitle',
children: FunList,
},
},
@@ -118,11 +110,11 @@ export class SearchFormulaController {
mask: false,
group: [
{
- locale: 'button.confirm',
+ label: 'button.confirm',
type: 'primary',
},
{
- locale: 'button.cancel',
+ label: 'button.cancel',
},
],
onCancel: () => this.showFormulaModal('SearchItem', false),
@@ -157,104 +149,10 @@ export class SearchFormulaController {
},
};
- // this._initRegisterComponent();
-
this._initialize();
}
- private _initialize() {
- this._plugin.getObserver('onSearchFormulaModalDidMountObservable')!.add((component) => {
- this._formulaModal = component;
-
- this._modalData = this._resetLabel(this._modalData);
- this._cellRangeModalData = this._resetLabel(this._cellRangeModalData);
- });
-
- this._plugin.getObserver('onSearchItemDidMountObservable')!.add((component) => {
- this._searchItem = component;
- });
-
- const sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
- sheetPlugin.getObserver('onChangeSelectionObserver')?.add((selection) => {
- const info = selection.getCurrentCellInfo();
- // this._searchItem.changeRange(info?.startColumn.toString() ?? '');
- });
- }
-
- private _initRegisterComponent() {
- const sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
- sheetPlugin.registerModal(FORMULA_PLUGIN_NAME + SearchFormulaModal.name, SearchFormulaModal);
- sheetPlugin.registerModal(FORMULA_PLUGIN_NAME + SearchItem.name, SearchItem);
- sheetPlugin.registerComponent(FORMULA_PLUGIN_NAME + SearchFormulaContent.name, SearchFormulaContent);
- }
-
- private _resetLocale(label: string[] | string) {
- const locale = this._plugin.context.getLocale();
-
- let str = '';
-
- if (label instanceof Array) {
- label.forEach((item) => {
- if (item.includes('.')) {
- str += locale.get(item);
- } else {
- str += item;
- }
- });
- } else {
- if (label.includes('.')) {
- str = locale.get(label);
- } else {
- str += label;
- }
- }
-
- return str;
- }
-
- private _findLocale(obj: any) {
- for (let k in obj) {
- if (k === 'locale') {
- obj.label = this._resetLocale(obj[k]);
- } else if (k.endsWith('Locale')) {
- const index = k.indexOf('Locale');
- obj[k.slice(0, index)] = this._resetLocale(obj[k]);
- } else if (!obj[k].$$typeof) {
- if (Object.prototype.toString.call(obj[k]) === '[object Object]') {
- this._findLocale(obj[k]);
- } else if (Object.prototype.toString.call(obj[k]) === '[object Array]') {
- this._resetLabel(obj[k]);
- }
- }
- }
-
- return obj;
- }
-
- private _resetLabel(list: any) {
- if (list instanceof Array) {
- for (let i = 0; i < list.length; i++) {
- let item = list[i];
-
- item = this._findLocale(item);
-
- if (item.children) {
- item.children = this._resetLabel(item.children);
- }
- }
-
- return list;
- }
- if (list instanceof Object) {
- list = this._findLocale(list);
- // for (let k in list) {
- // list[k] = this._findLocale(list[k]);
- // }
- return list;
- }
- }
-
- selectFunParams(value: FunctionList) {
+ selectFunParams(value: FormulaType) {
this._funParams.funParams = value;
}
@@ -279,4 +177,29 @@ export class SearchFormulaController {
this.showFormulaModal('SearchFormula', false);
this.showFormulaModal('SearchItem', true);
}
+
+ private _initialize() {
+ this._initRegisterComponent();
+
+ const sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
+ sheetPlugin.getObserver('onChangeSelectionObserver')?.add((selection) => {
+ const info = selection.getCurrentCellInfo();
+ // this._searchItem.changeRange(info?.startColumn.toString() ?? '');
+ });
+ }
+
+ private _initRegisterComponent() {
+ const sheetUiPlugin = this._plugin.getContext().getUniver().getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);
+ const ComponentManager = sheetUiPlugin.getComponentManager();
+ sheetUiPlugin.addSlot(FORMULA_PLUGIN_NAME + SearchFormulaModal.name, {
+ component: SearchFormulaModal,
+ props: {
+ getComponent: (ref: SearchFormulaModal) => {
+ this._formulaModal = ref;
+ },
+ },
+ });
+ ComponentManager.register(FORMULA_PLUGIN_NAME + SearchItem.name, SearchItem);
+ ComponentManager.register(FORMULA_PLUGIN_NAME + SearchFormulaContent.name, SearchFormulaContent);
+ }
}
diff --git a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
index 561065a3ea..063348c56d 100644
--- a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
+++ b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
@@ -1,6 +1,6 @@
import { SheetContext, IOCContainer, UniverSheet, Plugin } from '@univerjs/core';
import { FormulaEnginePlugin } from '@univerjs/base-formula-engine';
-import { CellEditExtensionManager, CellInputExtensionManager } from '@univerjs/base-ui';
+import { CellEditExtensionManager, CellInputExtensionManager, Icon } from '@univerjs/base-ui';
import { SheetUIPlugin, SHEET_UI_PLUGIN_NAME } from '@univerjs/ui-plugin-sheets';
import { zh, en } from './Locale';
@@ -16,14 +16,14 @@ import { SearchFormulaController } from './Controller/SearchFormulaModalControll
import { FormulaPromptController } from './Controller/FormulaPromptController';
export class FormulaPlugin extends Plugin<FormulaPluginObserve, SheetContext> {
+ protected _formulaActionExtensionFactory: FormulaActionExtensionFactory;
+
private _formulaController: FormulaController;
private _searchFormulaController: SearchFormulaController;
private _formulaPromptController: FormulaPromptController;
- protected _formulaActionExtensionFactory: FormulaActionExtensionFactory;
-
constructor(private _config?: IFormulaConfig) {
super(FORMULA_PLUGIN_NAME);
}
@@ -51,6 +51,14 @@ export class FormulaPlugin extends Plugin<FormulaPluginObserve, SheetContext> {
this._formulaController.setFormulaEngine(formulaEngine as FormulaEnginePlugin);
firstLoader(this._formulaController);
+ sheetPlugin.getComponentManager().register('FxIcon', Icon.Math.FxIcon);
+
+ sheetPlugin.setFx({
+ onClick: () => {
+ this._searchFormulaController.showFormulaModal('SearchFormula', true);
+ },
+ icon: 'FxIcon',
+ });
});
}
@@ -110,7 +118,7 @@ export class FormulaPlugin extends Plugin<FormulaPluginObserve, SheetContext> {
registerExtension() {
const cellEditRegister = CellEditExtensionManager.create();
- cellEditRegister.add(new FormulaCellEditExtensionFactory(this));
+ cellEditRegister.add(new FormulaCellEditExtensionFactory());
const cellInputRegister = CellInputExtensionManager.create();
cellInputRegister.add(new FormulaCellInputExtensionFactory(this));
diff --git a/packages/sheets-plugin-formula/src/Locale/en.ts b/packages/sheets-plugin-formula/src/Locale/en.ts
index ade9ca39f5..17eead579a 100644
--- a/packages/sheets-plugin-formula/src/Locale/en.ts
+++ b/packages/sheets-plugin-formula/src/Locale/en.ts
@@ -237,7 +237,7 @@ export default {
formulaMore: {
valueTitle: 'Value',
tipSelectDataRange: 'Select data range',
- tipDataRangeTile: 'Data range',
+ tipDataRangeTitle: 'Data range',
findFunctionTitle: 'Search function',
tipInputFunctionName: 'Function name or brief description of function',
whole: 'Whole',
diff --git a/packages/sheets-plugin-formula/src/Locale/zh.ts b/packages/sheets-plugin-formula/src/Locale/zh.ts
index 8f47351f06..5828658362 100644
--- a/packages/sheets-plugin-formula/src/Locale/zh.ts
+++ b/packages/sheets-plugin-formula/src/Locale/zh.ts
@@ -219,7 +219,7 @@ export default {
formulaMore: {
valueTitle: '值',
tipSelectDataRange: '选取数据范围',
- tipDataRangeTile: '数据范围',
+ tipDataRangeTitle: '数据范围',
findFunctionTitle: '查找函数',
tipInputFunctionName: '请输入您要查找的函数名称或函数功能的简要描述',
whole: '全部',
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 f6d983424a..a0b2b2aad1 100644
--- a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaContent.tsx
+++ b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaContent.tsx
@@ -1,32 +1,24 @@
-import { BaseComponentRender, BaseComponentSheet, Component, createRef, debounce, Select } from '@univerjs/base-ui';
-import { FunctionList } from '../../../Basic';
-import { FunListILabel, ILabel } from '../../../Controller/SearchFormulaModalController';
+import { BaseComponentProps, Component, createRef, debounce, Input, Select } from '@univerjs/base-ui';
+import { FormulaType } from '../../../Basic';
+import { FunListILabel, Label } from '../../../Controller/SearchFormulaModalController';
import styles from './index.module.less';
-interface IProps {
- input: ILabel;
- select: ILabel;
+interface IProps extends BaseComponentProps {
+ select: Label[];
funList: FunListILabel;
}
interface IState {
- functionList: FunctionList[] | undefined;
+ functionList: FormulaType[] | undefined;
type: number;
}
export class SearchFormulaContent extends Component<IProps, IState> {
- private _render: BaseComponentRender;
-
functionListRef = createRef();
initialize() {
- const component = this.getContext().getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;
- this._render = component.getComponentRender();
-
- const functionList = this.props.funList.children?.filter((item) => item.t === 0);
-
this.state = {
- functionList,
+ functionList: undefined,
type: 0,
};
}
@@ -52,10 +44,10 @@ export class SearchFormulaContent extends Component<IProps, IState> {
selectType(value: string, index: number) {
const { funList } = this.props;
- const children = funList.children?.filter((item) => item.t === index);
+ const functionList = funList.children?.filter((item) => item.t === index);
this.setState(
{
- functionList: children,
+ functionList: this.getFunctionList(functionList ?? []),
type: index,
},
() => {
@@ -65,7 +57,16 @@ export class SearchFormulaContent extends Component<IProps, IState> {
}
componentDidMount() {
- this.highLightLi(0);
+ const functionList = this.getFunctionList(this.props.funList.children?.filter((item) => item.t === 0) ?? []);
+ this.setState(
+ {
+ functionList,
+ type: 0,
+ },
+ () => {
+ this.highLightLi(0);
+ }
+ );
}
highLightLi(index: number) {
@@ -77,32 +78,57 @@ export class SearchFormulaContent extends Component<IProps, IState> {
item[index].click();
}
- handleClick(item: FunctionList, index: number) {
+ handleClick(item: FormulaType, index: number) {
const { funList } = this.props;
this.highLightLi(index);
funList.onClick(item);
}
+ /**
+ * 国际化
+ */
+ getSelect() {
+ const { select } = this.props;
+ const arr = [];
+ for (let i = 0; i < select.length; i++) {
+ arr.push({
+ label: this.getLocale(select[i].label),
+ });
+ }
+ return arr;
+ }
+
+ getFunctionList(list: FormulaType[]) {
+ const functionList = JSON.parse(JSON.stringify(list));
+ for (let i = 0; i < functionList.length; i++) {
+ for (let k in functionList[i]) {
+ 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]);
+ }
+ }
+ }
+ return functionList;
+ }
+
render() {
- const Input = this._render.renderFunction('Input');
- const { input, select, funList } = this.props;
const { functionList } = this.state;
- if (!input) return;
return (
<div className={styles.functionModal}>
<div className={styles.functionSearch}>
- <div className={styles.functionLabel}>{input.label}</div>
- <Input placeholder={input.placeholder} onChange={debounce(this.changeInput.bind(this), 50)} />
+ <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>
<div className={styles.functionSelect}>
- <div className={styles.functionLabel}>{select.label}</div>
+ <div className={styles.functionLabel}>{this.getLocale('formula.formulaMore.selectCategory')}</div>
<div className={styles.functionSelector}>
- <Select onClick={this.selectType.bind(this)} type={0} children={select.children} hideSelectedIcon={true}></Select>
+ <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}>{funList.label}</div>
+ <div className={styles.functionLabel}>{this.getLocale('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 600b012bf9..cfc0d91e79 100644
--- a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaModal.tsx
+++ b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaModal.tsx
@@ -1,38 +1,29 @@
-import { BaseComponentRender, BaseComponentSheet, Component } from '@univerjs/base-ui';
-import { PLUGIN_NAMES } from '@univerjs/core';
-import { SheetPlugin } from '@univerjs/base-sheets';
-import { FORMULA_PLUGIN_NAME } from '../../../Basic';
+import { BaseComponentProps, Component, Modal } from '@univerjs/base-ui';
+import { SheetUIPlugin, SHEET_UI_PLUGIN_NAME } from '@univerjs/ui-plugin-sheets';
import { SearchFormulaModalData } from '../../../Controller/SearchFormulaModalController';
-import { FormulaPlugin } from '../../../FormulaPlugin';
-interface IProps {}
+interface IProps extends BaseComponentProps {}
interface IState {
modalData: SearchFormulaModalData[];
}
export class SearchFormulaModal extends Component<IProps, IState> {
- private _render: BaseComponentRender;
-
initialize() {
- const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;
- this._render = component.getComponentRender();
-
this.state = {
modalData: [],
};
}
componentDidMount() {
- const plugin = this._context.getPluginManager().getPluginByName<FormulaPlugin>(FORMULA_PLUGIN_NAME)!;
- plugin.getObserver('onSearchFormulaModalDidMountObservable')!.notifyObservers(this);
+ this.props.getComponent?.(this);
}
setModal(modalData: SearchFormulaModalData[]) {
- const SheetPlugin = this._context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
+ const componentManager = this.getContext().getPluginManager().getPluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)?.getComponentManager();
modalData.forEach((item) => {
- const Label = SheetPlugin.getRegisterComponent(item.children.name!);
+ const Label = componentManager?.get(item.children.name!);
if (Label) {
const props = item.children.props ?? {};
item.modal = <Label {...props} />;
@@ -45,7 +36,6 @@ export class SearchFormulaModal extends Component<IProps, IState> {
}
render() {
- const Modal = this._render.renderFunction('Modal');
const { modalData } = this.state;
// Set Provider for entire Container
return (
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 d206ac8534..58909980fc 100644
--- a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchItem.tsx
+++ b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchItem.tsx
@@ -1,17 +1,15 @@
-import { Component } from '@univerjs/base-ui';
-import { FORMULA_PLUGIN_NAME, P } from '../../../Basic';
+import { BaseComponentProps, CellRange, Component } from '@univerjs/base-ui';
+import { FormulaParamType } from '../../../Basic';
import { FunParams } from '../../../Controller/SearchFormulaModalController';
-import { FormulaPlugin } from '../../../FormulaPlugin';
import styles from './index.module.less';
-interface IProps {
+interface IProps extends BaseComponentProps {
funParams: FunParams;
calc: string;
- onTableClick: () => void;
}
interface IState {
- description: P;
+ description: FormulaParamType;
rangeList: string[];
index: number;
}
@@ -26,9 +24,6 @@ export class SearchItem extends Component<IProps, IState> {
}
componentDidMount() {
- const plugin = this.getContext().getPluginManager().getPluginByName<FormulaPlugin>(FORMULA_PLUGIN_NAME)!;
- plugin.getObserver('onSearchItemDidMountObservable')!.notifyObservers(this);
-
const { funParams } = this.props;
const description = funParams?.funParams.p?.[0];
this.setState({
@@ -55,7 +50,7 @@ export class SearchItem extends Component<IProps, IState> {
}
render() {
- const { funParams, calc, onTableClick } = this.props;
+ const { funParams, calc } = this.props;
const { description, rangeList } = this.state;
if (!funParams) return;
@@ -65,8 +60,14 @@ export class SearchItem extends Component<IProps, IState> {
<div className={styles.functionParamList}>
{funParams.funParams?.p?.map((item, index) => (
<div>
- <span>{item.name}:</span>
- <CellRange onTableClick={onTableClick} value={rangeList[index]} onClick={() => this.handleClick(index)}></CellRange>
+ <span>{item.name}:</span>
+ <div onClick={() => this.handleClick(index)}>
+ <CellRange
+ contentPlaceholder={this.getLocale('formula.formulaMore.tipDataRangeTitle')}
+ title={this.getLocale('formula.formulaMore.tipSelectDataRange')}
+ value={rangeList[index]}
+ ></CellRange>
+ </div>
<span>={'{}'}</span>
</div>
))}
diff --git a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/index.module.less b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/index.module.less
index 3b0a17c1cd..3907c476a3 100644
--- a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/index.module.less
+++ b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/index.module.less
@@ -29,6 +29,11 @@
border: 1px solid var(--border-color-base);
border-radius: var(--border-radius-base);
+ .select-component {
+ height: auto;
+ margin: 0;
+ }
+
.select-button {
margin: 0;
}
diff --git a/packages/ui-plugin-sheets/src/Controller/SlotController.ts b/packages/ui-plugin-sheets/src/Controller/SlotController.ts
index f7047ac08c..626b324943 100644
--- a/packages/ui-plugin-sheets/src/Controller/SlotController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/SlotController.ts
@@ -17,7 +17,7 @@ export class SlotController {
this._slot = ref;
};
- addSlot<O, T = null>(name: string, slot: SlotComponentProps, cb?: () => void) {
+ addSlot(name: string, slot: SlotComponentProps, cb?: () => void) {
if (this._slotGroup.get(name)) return;
this._slotGroup.set(name, {
component: slot.component,
diff --git a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
index 10621548a7..8c6eeba77f 100644
--- a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
@@ -390,7 +390,7 @@ export class ToolbarUIController {
},
show: this._config.mergeCell,
onClick: (value: string) => {
- this.setMerge(value);
+ this.setMerge(value ?? 'all');
this.hideTooltip();
},
name: 'mergeCell',
@@ -739,14 +739,6 @@ export class ToolbarUIController {
this._plugin.getComponentManager().register(SHEET_UI_PLUGIN_NAME + LineColor.name, LineColor);
this._plugin.getComponentManager().register(SHEET_UI_PLUGIN_NAME + LineBold.name, LineBold);
- // this._sheetPlugin.getObserver('onChangeSelectionObserver')?.add(() => {
- // const manager = this._sheetPlugin.getSelectionManager();
- // const range = manager?.getCurrentCell();
- // if (range) {
- // this._changeToolbarState(range);
- // }
- // });
-
CommandManager.getCommandObservers().add(({ actions }) => {
if (!actions || actions.length === 0) return;
const action = actions[0] as SheetActionBase<ISheetActionData, ISheetActionData, void>;
diff --git a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts b/packages/ui-plugin-sheets/src/SheetUIPlugin.ts
index 0c5e46799e..ae29ea2e75 100644
--- a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts
+++ b/packages/ui-plugin-sheets/src/SheetUIPlugin.ts
@@ -5,6 +5,8 @@ import { RenderEngine } from '@univerjs/base-render';
import { DefaultSheetUiConfig, installObserver, ISheetUIPluginConfig, SheetUIPluginObserve, SHEET_UI_PLUGIN_NAME } from './Basics';
import { zh, en } from './Locale';
import { AppUIController } from './Controller/AppUIController';
+import { Fx } from './View/FormulaBar';
+import { SlotComponentProps } from './Controller/SlotController';
export class SheetUIPlugin extends Plugin<SheetUIPluginObserve, Context> {
private _appUIController: AppUIController;
@@ -97,6 +99,10 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve, Context> {
this._appUIController.getSheetContainerController().getFormulaBarUIController().getFormulaBar().setFormulaContent(str);
}
+ setFx(fx: Fx) {
+ this._appUIController.getSheetContainerController().getFormulaBarUIController().getFormulaBar().setFx(fx);
+ }
+
/**
* This API is used in plugins for initialization that depends on UI rendering
* @param cb
@@ -105,4 +111,8 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve, Context> {
UIDidMount(cb: Function) {
this._appUIController.getSheetContainerController().UIDidMount(cb);
}
+
+ addSlot(name: string, slot: SlotComponentProps, cb?: () => void) {
+ this._appUIController.getSheetContainerController().getMainSlotController().addSlot(name, slot, cb);
+ }
}
diff --git a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
index f0780bd7cf..234578fed4 100644
--- a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
@@ -1,10 +1,19 @@
import { BaseComponentProps, BaseComponentRender, BaseSelectChildrenProps, Component, debounce, Icon } from '@univerjs/base-ui';
+import { Nullable } from '@univerjs/core';
+import { SHEET_UI_PLUGIN_NAME } from '../../Basics';
+import { SheetUIPlugin } from '../../SheetUIPlugin';
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 {}
@@ -24,6 +33,7 @@ export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
],
spanClass: styles.formulaGrey,
formulaContent: '',
+ fx: null,
};
this.onkeyUp = debounce(this.onkeyUp, 300);
@@ -43,6 +53,12 @@ export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
});
}
+ setFx(fx: Fx) {
+ this.setState({
+ fx,
+ });
+ }
+
setNamedRanges(namedRanges: BaseSelectChildrenProps[]) {
this.setState({
namedRanges,
@@ -54,9 +70,15 @@ export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
// this._context.getObserverManager().getObserver<FormulaBar>('onFormulaBarDidMountObservable')?.notifyObservers(this);
}
+ getIcon(name: string) {
+ const componentManager = this.getContext().getPluginManager().getPluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)?.getComponentManager();
+ 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 } = state;
+ const { namedRanges, fx } = state;
return (
<div className={styles.formulaBox}>
@@ -69,9 +91,11 @@ export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
<span className={state.spanClass}>
<Icon.Format.CorrectIcon />
</span>
- <span className={styles.formulaBlack}>
- <Icon.Math.FxIcon />
- </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)}>
diff --git a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
index 557c9cb7fb..ca592fb74c 100644
--- a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
@@ -230,6 +230,7 @@ export class SheetContainer extends Component<BaseSheetContainerProps> {
{config.rightMenu && <RightMenu {...methods.rightMenu}></RightMenu>}
{<RichText {...methods.cellEditor}></RichText>}
</Container>
+ {/* <Prompt show={true} title="123" content="235" /> */}
{/* extend main content */}
</Content>
diff --git a/test.html b/test.html
index 914ef6cba9..9291bc5892 100644
--- a/test.html
+++ b/test.html
@@ -23,16 +23,7 @@
<button>click</button>
</body>
<script>
- const btn = document.querySelector('button')
- const dom = document.querySelector('div')
- btn.onclick = () => {
- dom.style.position = 'fixed'
- dom.style.left = '0'
- dom.style.top = '0'
- dom.style.width = '100vw'
- dom.style.height = '100vh'
- dom.style.zIndex = '999'
- }
+
</script>
</html>
\ No newline at end of file