Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

chore(formula): formula bar search function less to tailwind (#5029)

Dushusir9f9fb5160620
diff --git a/packages/sheets-formula-ui/src/controllers/formula-ui.controller.ts b/packages/sheets-formula-ui/src/controllers/formula-ui.controller.ts
index 2c20b988a2..cb158cd7de 100644
--- a/packages/sheets-formula-ui/src/controllers/formula-ui.controller.ts
+++ b/packages/sheets-formula-ui/src/controllers/formula-ui.controller.ts
@@ -19,7 +19,7 @@ import { Disposable, ICommandService, Inject, Injector, UniverInstanceType } fro
import { IRenderManagerService } from '@univerjs/engine-render';
import { SheetsUIPart } from '@univerjs/sheets-ui';
-import { BuiltInUIPart, ComponentManager, connectInjector, IMenuManagerService, IShortcutService, IUIPartsService } from '@univerjs/ui';
+import { ComponentManager, connectInjector, IMenuManagerService, IShortcutService, IUIPartsService } from '@univerjs/ui';
import { SheetOnlyPasteFormulaCommand } from '../commands/commands/formula-clipboard.command';
import { SelectEditorFormulaOperation } from '../commands/operations/editor-formula.operation';
import { HelpFunctionOperation } from '../commands/operations/help-function.operation';
@@ -28,7 +28,6 @@ import { MoreFunctionsOperation } from '../commands/operations/more-functions.op
import { ReferenceAbsoluteOperation } from '../commands/operations/reference-absolute.operation';
import { SearchFunctionOperation } from '../commands/operations/search-function.operation';
import { FormulaProgressBar } from '../views/formula-progress/FormulaProgress';
-import { RenderFormulaPromptContent } from '../views/FormulaPromptContainer';
import { MORE_FUNCTIONS_COMPONENT } from '../views/more-functions/interface';
import { MoreFunctions } from '../views/more-functions/MoreFunctions';
import { FormulaEditorShowController } from './formula-editor-show.controller';
@@ -95,7 +94,6 @@ export class FormulaUIController extends Disposable {
}
private _registerComponents(): void {
- this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.CONTENT, () => connectInjector(RenderFormulaPromptContent, this._injector)));
this.disposeWithMe(this._uiPartsService.registerComponent(SheetsUIPart.FORMULA_AUX, () => connectInjector(FormulaProgressBar, this._injector)));
this._componentManager.register(MORE_FUNCTIONS_COMPONENT, MoreFunctions);
diff --git a/packages/sheets-formula-ui/src/views/FormulaPromptContainer.tsx b/packages/sheets-formula-ui/src/views/FormulaPromptContainer.tsx
deleted file mode 100644
index 1567a9a830..0000000000
--- a/packages/sheets-formula-ui/src/views/FormulaPromptContainer.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import React from 'react';
-
-import { HelpFunction } from './prompt/help-function/HelpFunction';
-import { SearchFunction } from './prompt/search-function/SearchFunction';
-
-export function RenderFormulaPromptContent() {
- return (
- <>
- <SearchFunction />
- <HelpFunction />
- </>
- );
-}
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx b/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
index bbf0f2f9ee..6dedc10a73 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
+++ b/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
@@ -25,7 +25,6 @@ import { generateParam } from '../../../services/utils';
import { useEditorPosition } from '../hooks/use-editor-position';
import { useFormulaDescribe } from '../hooks/use-formula-describe';
import { HelpHiddenTip } from './HelpHiddenTip';
-import styles from './index.module.less';
interface IParamsProps {
className?: string;
@@ -34,16 +33,22 @@ interface IParamsProps {
}
const Params = ({ className, title, value }: IParamsProps) => (
- <div className={styles.formulaHelpFunctionContentParams}>
+ <div className="univer-my-2">
<div
className={`
- ${styles.formulaHelpFunctionContentParamsTitle}
+ univer-mb-2 univer-text-[13px] univer-font-medium univer-text-gray-900
${className}
`}
>
{title}
</div>
- <div className={styles.formulaHelpFunctionContentParamsDetail}>{value}</div>
+ <div
+ className={`
+ univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-font-normal univer-text-gray-500
+ `}
+ >
+ {value}
+ </div>
</div>
);
@@ -57,16 +62,16 @@ interface IHelpProps {
const Help = (props: IHelpProps) => {
const { prefix, value, active, onClick } = props;
return (
- <div className={styles.formulaHelpParam}>
- <span className={styles.formulaHelpParamPrefix}>
+ <div>
+ <span>
{prefix}
(
</span>
{value &&
value.map((item: IFunctionParam, i: number) => (
- <span key={item.name} className={styles.formulaHelpParamItem}>
+ <span key={item.name}>
<span
- className={active === i ? styles.formulaHelpFunctionActive : styles.formulaHelpParamActive}
+ className={active === i ? 'univer-text-primary-500' : ''}
onClick={() => onClick(i)}
>
{generateParam(item)}
@@ -122,24 +127,48 @@ export function HelpFunction(props: IHelpFunctionProps) {
)
: (
<RectPopup key="show" portal onClickOutside={() => reset()} anchorRect$={position$} direction="vertical">
- <div className={styles.formulaHelpFunction}>
- <div className={styles.formulaHelpFunctionTitle}>
+ <div
+ className={`
+ univer-m-0 univer-box-border univer-w-[250px] univer-select-none univer-list-none
+ univer-rounded-lg univer-border univer-border-solid univer-border-gray-200 univer-bg-white
+ univer-leading-5 univer-shadow-md univer-outline-none
+ `}
+ >
+ <div
+ className={`
+ univer-box-border univer-flex univer-items-center univer-justify-between univer-border-x-0
+ univer-border-b univer-border-t-0 univer-border-solid univer-border-gray-200 univer-px-4
+ univer-py-3 univer-text-xs univer-font-medium univer-text-gray-900 univer-wrap-anywhere
+ `}
+ >
<Help
prefix={functionInfo.functionName}
value={functionInfo.functionParameter}
active={paramIndex}
onClick={handleSwitchActive}
/>
- <div className={styles.formulaHelpFunctionTitleIcons}>
+ <div className="univer-flex">
<div
- className={styles.formulaHelpFunctionTitleIcon}
+ className={`
+ univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer
+ univer-items-center univer-justify-center univer-rounded univer-border-0
+ univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-500
+ univer-outline-none univer-transition-colors
+ hover:univer-bg-gray-200
+ `}
style={{ transform: contentVisible ? 'rotateZ(-90deg)' : 'rotateZ(90deg)' }}
onClick={() => setContentVisible(!contentVisible)}
>
<MoreSingle />
</div>
<div
- className={styles.formulaHelpFunctionTitleIcon}
+ className={`
+ univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer
+ univer-items-center univer-justify-center univer-rounded univer-border-0
+ univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-600
+ univer-outline-none univer-transition-colors
+ hover:univer-bg-gray-300
+ `}
onClick={onClose}
>
<CloseSingle />
@@ -147,13 +176,16 @@ export function HelpFunction(props: IHelpFunctionProps) {
</div>
</div>
<div
- className={styles.formulaHelpFunctionContent}
+ className={`
+ univer-box-border univer-max-h-[350px] univer-overflow-y-auto univer-px-4 univer-pb-3
+ univer-pt-0
+ `}
style={{
height: contentVisible ? 'unset' : 0,
padding: contentVisible ? 'revert-layer' : 0,
}}
>
- <div className={styles.formulaHelpFunctionContentInner}>
+ <div className="univer-mt-3">
<Params
title={localeService.t('formula.prompt.helpExample')}
value={`${functionInfo.functionName}(${functionInfo.functionParameter
@@ -169,7 +201,7 @@ export function HelpFunction(props: IHelpFunctionProps) {
functionInfo.functionParameter.map((item: IFunctionParam, i: number) => (
<Params
key={i}
- className={paramIndex === i ? styles.formulaHelpFunctionActive : ''}
+ className={paramIndex === i ? 'univer-text-primary-500' : ''}
title={item.name}
value={`${item.require ? required : optional} ${item.detail}`}
/>
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/help-function/index.module.less b/packages/sheets-formula-ui/src/views/formula-editor/help-function/index.module.less
deleted file mode 100644
index bfe186d777..0000000000
--- a/packages/sheets-formula-ui/src/views/formula-editor/help-function/index.module.less
+++ /dev/null
@@ -1,129 +0,0 @@
-@width: 250px;
-@max-height: 350px;
-@icon-size: 24px;
-
-.formula-help-function {
- user-select: none;
-
- box-sizing: border-box;
- width: @width;
- margin: 0;
-
- line-height: 20px;
- list-style: none;
-
- background-color: rgb(var(--bg-color-secondary));
- border: 1px solid rgb(var(--border-color));
- border-radius: var(--border-radius-lg);
- outline: none;
- box-shadow: var(--box-shadow-base);
-
- &-title {
- display: flex;
- align-items: center;
- justify-content: space-between;
-
- box-sizing: border-box;
- padding: var(--padding-base) var(--padding-lg);
-
- font-size: var(--font-size-xxs);
- font-weight: 500;
- color: rgb(var(--text-color));
- overflow-wrap: anywhere;
-
- border-bottom: 1px solid rgb(var(--border-color));
-
- &-icons {
- display: flex;
- }
-
- &-icon {
- cursor: pointer;
-
- display: flex;
- align-items: center;
- justify-content: center;
-
- width: @icon-size;
- height: @icon-size;
- margin-left: var(--margin-xs);
- padding: 0;
-
- font-size: var(--font-size-xs);
- color: rgb(var(--text-color-secondary));
-
- background-color: transparent;
- border: none;
- border-radius: var(--border-radius-base);
- outline: none;
-
- transition: background-color 0.2s;
-
- &:hover {
- background-color: rgb(var(--bg-color-hover));
- }
- }
- }
-
- &-content {
- overflow-y: auto;
- box-sizing: border-box;
- max-height: @max-height;
- padding: 0 var(--padding-lg) var(--padding-base) var(--padding-lg);
-
- &-inner {
- margin-top: var(--margin-sm);
- }
-
- &-params {
- margin: var(--margin-xs) 0;
-
- &-title {
- margin-bottom: var(--margin-xs);
- font-size: var(--font-size-xs);
- font-weight: 500;
- color: rgb(var(--text-color));
- }
-
- &-detail {
- font-size: var(--font-size-xxs);
- font-weight: 400;
- white-space: pre-wrap;
- word-wrap: break-word;
- color: rgb(var(--text-color-secondary));
- }
- }
- }
-
- &-active {
- color: rgb(var(--primary-color));
- }
-}
-
-.formula-help-decorator {
- cursor: pointer;
-
- position: fixed;
- z-index: 10;
-
- display: flex;
- align-items: center;
- justify-content: center;
-
- padding: var(--padding-xs);
-}
-
-.formula-help-param {
- z-index: 1;
- &-prefix {
- z-index: 1;
- }
-
- &-item {
- z-index: 1;
- }
-
- &-active {
- z-index: 1;
- }
-}
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/index.module.less b/packages/sheets-formula-ui/src/views/formula-editor/index.module.less
deleted file mode 100644
index f213596b76..0000000000
--- a/packages/sheets-formula-ui/src/views/formula-editor/index.module.less
+++ /dev/null
@@ -1,35 +0,0 @@
-.sheet-embedding-formula-editor {
- &-active {
- border-color: rgb(var(--hyacinth-500)) !important;
- }
-
- &-wrap {
- height: 32px;
- padding: 6px 8px 2px 6px;
- width: 100%;
- display: flex;
- justify-content: space-around;
- align-items: center;
- gap: 8px;
- border: 1px solid rgb(var(--border-color));
- border-radius: var(--border-radius-base);
- box-sizing: border-box;
- position: relative;
-
- .sheet-embedding-formula-editor-text {
- width: 100%;
- height: 100%;
- position: relative;
- }
- }
-
- &-error {
- border: 1px solid rgb(var(--red-500)) !important;
- }
-
- .sheet-embedding-formula-editor-error-wrap {
- font-size: 12px;
- color: rgb(var(--red-500));
- margin: var(--margin-xxs) 0;
- }
-}
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/index.tsx b/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
index e672e3a33c..218902f362 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
+++ b/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
@@ -40,7 +40,6 @@ import { useSheetSelectionChange } from './hooks/use-sheet-selection-change';
import { useStateRef } from './hooks/use-state-ref';
import { useSwitchSheet } from './hooks/use-switch-sheet';
import { useVerify } from './hooks/use-verify';
-import styles from './index.module.less';
import { SearchFunction } from './search-function/SearchFunction';
import { getFormulaText } from './utils/get-formula-text';
@@ -312,21 +311,33 @@ export const FormulaEditor = forwardRef((props: IFormulaEditorProps, ref: Ref<IF
};
return (
- <div style={style} className={clsx(styles.sheetEmbeddingFormulaEditor, className)}>
+ <div style={style} className={className}>
<div
- className={clsx(styles.sheetEmbeddingFormulaEditorWrap, {
- [styles.sheetEmbeddingFormulaEditorActive]: isFocus,
- [styles.sheetEmbeddingFormulaEditorError]: isError,
- })}
+ className={clsx(
+ `
+ univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-items-center
+ univer-justify-around univer-gap-2 univer-rounded-none univer-border-none univer-p-0
+ `,
+ {
+ 'univer-border-primary-500': isFocus,
+ 'univer-border-red-500': isError,
+ }
+ )}
ref={sheetEmbeddingRef}
>
<div
- className={styles.sheetEmbeddingFormulaEditorText}
+ className="univer-relative univer-h-full univer-w-full"
ref={formulaEditorContainerRef}
onMouseUp={handleMouseUp}
/>
</div>
- {errorText !== undefined ? <div className={styles.sheetEmbeddingFormulaEditorErrorWrap}>{errorText}</div> : null}
+ {errorText !== undefined
+ ? (
+ <div className="univer-my-1 univer-text-xs univer-text-red-500">
+ {errorText}
+ </div>
+ )
+ : null}
{editor
? (
<HelpFunction
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/search-function/SearchFunction.tsx b/packages/sheets-formula-ui/src/views/formula-editor/search-function/SearchFunction.tsx
index 047c5a1bfc..b4de2e5f3a 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/search-function/SearchFunction.tsx
+++ b/packages/sheets-formula-ui/src/views/formula-editor/search-function/SearchFunction.tsx
@@ -23,7 +23,6 @@ import React, { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
import { useEditorPosition } from '../hooks/use-editor-position';
import { useFormulaSearch } from '../hooks/use-formula-search';
import { useStateRef } from '../hooks/use-state-ref';
-import styles from './index.module.less';
interface ISearchFunctionProps {
isFocus: boolean;
@@ -144,18 +143,13 @@ function SearchFunctionFactory(props: ISearchFunctionProps, ref: any) {
}, [searchList]);
function scrollToVisible(liIndex: number) {
- // Get the <li> element
- const liElement = ulRef.current?.querySelectorAll(`.${styles.formulaSearchFunctionItem}`)[
- liIndex
- ] as HTMLLIElement;
+ // Get the <li> element directly from children
+ const ulElement = ulRef.current;
+ if (!ulElement) return;
+ const liElement = ulElement.children[liIndex] as HTMLLIElement;
if (!liElement) return;
- // Get the <ul> element
- const ulElement = liElement.parentNode as HTMLUListElement;
-
- if (!ulElement) return;
-
// Get the height of the <ul> element
const ulRect = ulElement.getBoundingClientRect();
const ulTop = ulRect.top;
@@ -195,7 +189,11 @@ function SearchFunctionFactory(props: ISearchFunctionProps, ref: any) {
return searchList.length > 0 && visible && (
<RectPopup portal anchorRect$={position$} direction="vertical">
<ul
- className={styles.formulaSearchFunction}
+ className={`
+ univer-m-0 univer-box-border univer-max-h-[400px] univer-w-[250px] univer-list-none
+ univer-overflow-y-auto univer-rounded-lg univer-border univer-border-solid univer-border-gray-200
+ univer-bg-white univer-p-2 univer-leading-5 univer-shadow-md univer-outline-none
+ `}
ref={(v) => {
ulRef.current = v!;
if (ref) {
@@ -206,12 +204,13 @@ function SearchFunctionFactory(props: ISearchFunctionProps, ref: any) {
{searchList.map((item, index) => (
<li
key={item.name}
- className={active === index
- ? `
- ${styles.formulaSearchFunctionItem}
- ${styles.formulaSearchFunctionItemActive}
- `
- : styles.formulaSearchFunctionItem}
+ className={`
+ univer-box-border univer-cursor-pointer univer-rounded univer-px-2 univer-py-1
+ univer-text-gray-900 univer-transition-colors
+ ${active === index
+ ? 'univer-bg-gray-200'
+ : ''}
+ `}
onMouseEnter={() => handleLiMouseEnter(index)}
onMouseLeave={handleLiMouseLeave}
onMouseMove={debounceResetMouseState}
@@ -222,11 +221,15 @@ function SearchFunctionFactory(props: ISearchFunctionProps, ref: any) {
}
}}
>
- <span className={styles.formulaSearchFunctionItemName}>
- <span className={styles.formulaSearchFunctionItemNameLight}>{item.name.substring(0, searchText.length)}</span>
+ <span className="univer-text-xs">
+ <span className="univer-text-red-500">{item.name.substring(0, searchText.length)}</span>
<span>{item.name.slice(searchText.length)}</span>
</span>
- <span className={styles.formulaSearchFunctionItemDesc}>{item.desc}</span>
+ <span
+ className="univer-block univer-text-xs univer-text-gray-400"
+ >
+ {item.desc}
+ </span>
</li>
))}
</ul>
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/search-function/index.module.less b/packages/sheets-formula-ui/src/views/formula-editor/search-function/index.module.less
deleted file mode 100644
index 26b7116c17..0000000000
--- a/packages/sheets-formula-ui/src/views/formula-editor/search-function/index.module.less
+++ /dev/null
@@ -1,55 +0,0 @@
-@width: 250px;
-@max-height: 400px;
-
-.formula-search-function {
- overflow-y: auto;
-
- box-sizing: border-box;
- width: @width;
- max-height: @max-height;
- margin: 0;
- padding: var(--padding-sm);
-
- line-height: 20px;
- list-style: none;
-
- background-color: rgb(var(--bg-color-secondary));
- border: 1px solid rgb(var(--border-color));
- border-radius: var(--border-radius-lg);
- outline: none;
- box-shadow: var(--box-shadow-base);
-
- overflow: hidden;
- overflow-y: auto;
-
- &-item {
- cursor: pointer;
-
- box-sizing: border-box;
- padding: var(--padding-xs) var(--padding-sm);
-
- color: rgb(var(--text-color));
-
- border-radius: var(--border-radius-base);
-
- transition: background 0.2s;
-
- &-name {
- font-size: var(--font-size-xxs);
-
- &-light {
- color: rgb(var(--error-color));
- }
- }
-
- &-desc {
- display: block;
- font-size: var(--font-size-xxs);
- color: rgb(var(--grey-500));
- }
-
- &-active {
- background-color: rgb(var(--bg-color-hover));
- }
- }
-}
diff --git a/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx b/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx
index 864ffbfb9e..2a01d793d9 100644
--- a/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx
+++ b/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx
@@ -23,7 +23,6 @@ import { getSheetCommandTarget } from '@univerjs/sheets';
import { IEditorBridgeService, SetCellEditVisibleOperation, useActiveWorkbook } from '@univerjs/sheets-ui';
import { useDependency } from '@univerjs/ui';
import React, { useState } from 'react';
-import styles from './index.module.less';
import { InputParams } from './input-params/InputParams';
import { SelectFunction } from './select-function/SelectFunction';
@@ -64,23 +63,33 @@ export function MoreFunctions() {
}
return (
- <div className={styles.formulaMoreFunctions}>
+ <div className="univer-flex univer-h-full univer-flex-col univer-justify-between univer-leading-5">
{selectFunction && <SelectFunction onChange={setFunctionInfo} />}
{inputParams && <InputParams functionInfo={functionInfo} onChange={() => {}} />}
- <div className={styles.formulaMoreFunctionsOperation}>
+ <div
+ className="univer-flex univer-justify-end"
+ >
{/* TODO@Dushusir: open input params after range selector refactor */}
{inputParams && (
- <Button variant="primary" onClick={handleClickNextPrev}>
+ <Button
+ variant="primary"
+ onClick={handleClickNextPrev}
+ className="univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0"
+ >
{localeService.t('formula.moreFunctions.next')}
</Button>
)}
{inputParams && (
- <Button onClick={handleClickNextPrev}>
+ <Button onClick={handleClickNextPrev} className="univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0">
{localeService.t('formula.moreFunctions.prev')}
</Button>
)}
{selectFunction && !!workbook && (
- <Button variant="primary" onClick={handleConfirm}>
+ <Button
+ variant="primary"
+ onClick={handleConfirm}
+ className="univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0"
+ >
{localeService.t('formula.moreFunctions.confirm')}
</Button>
)}
diff --git a/packages/sheets-formula-ui/src/views/more-functions/function-params/FunctionParams.tsx b/packages/sheets-formula-ui/src/views/more-functions/function-params/FunctionParams.tsx
index 9bd5224fd1..e00056cfbc 100644
--- a/packages/sheets-formula-ui/src/views/more-functions/function-params/FunctionParams.tsx
+++ b/packages/sheets-formula-ui/src/views/more-functions/function-params/FunctionParams.tsx
@@ -16,8 +16,6 @@
import React from 'react';
-import styles from './index.module.less';
-
interface IParamsProps {
className?: string;
title?: string | React.ReactElement;
@@ -27,15 +25,18 @@ interface IParamsProps {
export function FunctionParams(props: IParamsProps) {
const { className, value, title } = props;
return (
- <div className={styles.formulaFunctionParams}>
- <div className={`
- ${styles.formulaFunctionParamsTitle}
- ${className}
- `}
+ <div className="univer-mb-2 univer-text-xs">
+ <div
+ className={`
+ univer-mb-2 univer-font-medium univer-text-gray-500
+ ${className}
+ `}
>
{title}
</div>
- <div className={styles.formulaFunctionParamsDetail}>{value}</div>
+ <div className="univer-font-normal univer-text-gray-900">
+ {value}
+ </div>
</div>
);
}
diff --git a/packages/sheets-formula-ui/src/views/more-functions/function-params/index.module.less b/packages/sheets-formula-ui/src/views/more-functions/function-params/index.module.less
deleted file mode 100644
index 7ab8069e85..0000000000
--- a/packages/sheets-formula-ui/src/views/more-functions/function-params/index.module.less
+++ /dev/null
@@ -1,14 +0,0 @@
-.formula-function-params {
- margin-bottom: var(--margin-xs);
- font-size: var(--font-size-xxs);
-
- &-title {
- font-weight: 500;
- color: rgb(var(--text-color-secondary));
- }
-
- &-detail {
- font-weight: 400;
- color: rgb(var(--text-color));
- }
-}
diff --git a/packages/sheets-formula-ui/src/views/more-functions/index.module.less b/packages/sheets-formula-ui/src/views/more-functions/index.module.less
deleted file mode 100644
index 9af68e5a8b..0000000000
--- a/packages/sheets-formula-ui/src/views/more-functions/index.module.less
+++ /dev/null
@@ -1,18 +0,0 @@
-.formula-more-functions {
- display: flex;
- flex-direction: column;
- justify-content: space-between;
-
- height: 100%;
-
- line-height: 20px;
-
- &-operation {
- display: flex;
- justify-content: flex-end;
-
- > button {
- margin: 0 0 var(--margin-lg) var(--margin-base);
- }
- }
-}
diff --git a/packages/sheets-formula-ui/src/views/more-functions/input-params/InputParams.tsx b/packages/sheets-formula-ui/src/views/more-functions/input-params/InputParams.tsx
index 84059d0b3d..8b66261708 100644
--- a/packages/sheets-formula-ui/src/views/more-functions/input-params/InputParams.tsx
+++ b/packages/sheets-formula-ui/src/views/more-functions/input-params/InputParams.tsx
@@ -19,7 +19,6 @@ import React, { useState } from 'react';
import { FunctionHelp } from '../function-help/FunctionHelp';
import { FunctionParams } from '../function-params/FunctionParams';
-import styles from './index.module.less';
export interface IInputParamsProps {
functionInfo: IFunctionInfo | null;
@@ -53,13 +52,13 @@ export function InputParams(props: IInputParamsProps) {
}
return (
- <div className={styles.formulaInputParams}>
- <div className={styles.formulaInputParamsList}>
+ <div>
+ <div className="univer-h-[364px] univer-overflow-y-auto">
{functionParameter.map((item: IFunctionParam, i: number) => (
<div key={i}>
- <div className={styles.formulaInputParamsListItemName}>{item.name}</div>
+ <div className="univer-text-sm">{item.name}</div>
- <div className={styles.formulaInputParamsListItemSelector}>
+ <div className="univer-mb-2 univer-mt-1">
{/* <RangeSelector
onChange={(range: string) => handleChange(range, i)}
onActive={() => handleActive(i)}
@@ -69,7 +68,7 @@ export function InputParams(props: IInputParamsProps) {
))}
</div>
- <div className={styles.formulaInputParamsInfo}>
+ <div className="univer-flex-1 univer-border-l univer-border-solid univer-border-gray-200 univer-p-3">
<FunctionParams
title={activeIndex === -1
? <FunctionHelp prefix={functionInfo.functionName} value={functionParameter} />
diff --git a/packages/sheets-formula-ui/src/views/more-functions/input-params/index.module.less b/packages/sheets-formula-ui/src/views/more-functions/input-params/index.module.less
deleted file mode 100644
index a93e97efa6..0000000000
--- a/packages/sheets-formula-ui/src/views/more-functions/input-params/index.module.less
+++ /dev/null
@@ -1,18 +0,0 @@
-@params-list-height: 364px;
-
-.formula-input-params {
- &-list {
- overflow-y: auto;
- height: @params-list-height;
-
- &-item {
- &-name {
- font-size: var(--font-size-sm);
- }
-
- &-selector {
- margin: var(--margin-xxs) 0 var(--margin-xs) 0;
- }
- }
- }
-}
diff --git a/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx b/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx
index 6bbd551c24..de1600163c 100644
--- a/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx
+++ b/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx
@@ -27,7 +27,6 @@ import React, { useEffect, useState } from 'react';
import { getFunctionTypeValues } from '../../../services/utils';
import { FunctionHelp } from '../function-help/FunctionHelp';
import { FunctionParams } from '../function-params/FunctionParams';
-import styles from './index.module.less';
export interface ISelectFunctionProps {
onChange: (functionInfo: IFunctionInfo) => void;
@@ -86,7 +85,7 @@ export function SelectFunction(props: ISelectFunctionProps) {
return parts.map((part: string, index: number) => {
if (part.match(regex)) {
return (
- <span key={index} className={styles.formulaSelectFunctionResultItemNameLight}>
+ <span key={index} className="univer-text-red-500">
{part}
</span>
);
@@ -148,7 +147,7 @@ export function SelectFunction(props: ISelectFunctionProps) {
return (
<div>
- <div className={styles.formulaSelectFunctionSelect}>
+ <div className="univer-flex univer-items-center univer-justify-between univer-gap-[10%]">
<Select value={typeSelected} options={options} onChange={handleSelectChange} />
<Input
@@ -161,30 +160,46 @@ export function SelectFunction(props: ISelectFunctionProps) {
/>
</div>
- <ul className={styles.formulaSelectFunctionResult} onKeyDown={handleSelectListKeyDown} tabIndex={-1}>
+ <ul
+ className={`
+ univer-mx-0 univer-mb-0 univer-mt-2 univer-box-border univer-max-h-[364px] univer-w-full
+ univer-select-none univer-list-none univer-overflow-y-auto univer-rounded univer-border
+ univer-border-solid univer-border-gray-200 univer-p-3 univer-outline-none
+ `}
+ onKeyDown={handleSelectListKeyDown}
+ tabIndex={-1}
+ >
{selectList.map(({ name }, index) => (
<li
key={index}
className={active === index
? `
- ${styles.formulaSelectFunctionResultItem}
- ${styles.formulaSelectFunctionResultItemActive}
+ univer-relative univer-box-border univer-cursor-pointer univer-rounded univer-bg-gray-200
+ univer-px-7 univer-py-1 univer-text-[13px] univer-text-gray-900 univer-transition-colors
`
- : styles.formulaSelectFunctionResultItem}
+ : `
+ univer-relative univer-box-border univer-cursor-pointer univer-rounded univer-px-7
+ univer-py-1 univer-text-[13px] univer-text-gray-900 univer-transition-colors
+ `}
onMouseEnter={() => handleLiMouseEnter(index)}
onMouseLeave={handleLiMouseLeave}
onClick={() => setCurrentFunctionInfo(index)}
>
{nameSelected === index && (
- <CheckMarkSingle className={styles.formulaSelectFunctionResultItemSelected} />
+ <CheckMarkSingle
+ className={`
+ univer-absolute univer-left-1.5 univer-top-1/2 univer-inline-flex
+ univer--translate-y-1/2 univer-text-base univer-text-green-500
+ `}
+ />
)}
- <span className={styles.formulaSelectFunctionResultItemName}>{highlightSearchText(name)}</span>
+ <span className="univer-block">{highlightSearchText(name)}</span>
</li>
))}
</ul>
{functionInfo && (
- <div className={styles.formulaSelectFunctionContent}>
+ <div className="univer-mx-0 univer-my-2 univer-max-h-[307px] univer-overflow-y-auto">
<FunctionParams title={functionInfo.functionName} value={functionInfo.description} />
<FunctionParams
diff --git a/packages/sheets-formula-ui/src/views/more-functions/select-function/index.module.less b/packages/sheets-formula-ui/src/views/more-functions/select-function/index.module.less
deleted file mode 100644
index ed7127686c..0000000000
--- a/packages/sheets-formula-ui/src/views/more-functions/select-function/index.module.less
+++ /dev/null
@@ -1,80 +0,0 @@
-@result-height: 364px;
-@result-item-padding-left: 28px;
-@selected-icon-left: 6px;
-@description-height: 307px;
-
-.formula-select-function {
- &-select {
- display: flex;
- gap: 10%;
- align-items: center;
- justify-content: space-between;
- }
-
- &-result {
- user-select: none;
-
- overflow-y: auto;
-
- box-sizing: border-box;
- width: 100%;
- max-height: @result-height;
- margin: 0;
- margin-top: var(--margin-xs);
- padding: var(--padding-base);
-
- list-style: none;
-
- border: 1px solid rgb(var(--border-color));
- border-radius: var(--border-radius-base);
- outline: none;
-
- &-item {
- cursor: pointer;
-
- position: relative;
-
- box-sizing: border-box;
- padding: var(--padding-xs) @result-item-padding-left;
-
- font-size: var(--font-size-xs);
- color: rgb(var(--text-color));
-
- border-radius: var(--border-radius-base);
-
- transition: background 0.2s;
-
- > span {
- display: block;
- }
-
- &-name {
- &-light {
- color: rgb(var(--error-color));
- }
- }
-
- &-selected {
- position: absolute;
- top: 50%;
- left: @selected-icon-left;
- transform: translateY(-50%);
-
- display: inline-flex;
-
- font-size: var(--font-size-lg);
- color: rgb(var(--success-color));
- }
-
- &-active {
- background-color: rgb(var(--bg-color-hover));
- }
- }
- }
-
- &-content {
- overflow-y: auto;
- max-height: @description-height;
- margin: var(--margin-xs) 0;
- }
-}
diff --git a/packages/sheets-formula-ui/src/views/prompt/help-function/HelpFunction.tsx b/packages/sheets-formula-ui/src/views/prompt/help-function/HelpFunction.tsx
deleted file mode 100644
index 26e46fbb08..0000000000
--- a/packages/sheets-formula-ui/src/views/prompt/help-function/HelpFunction.tsx
+++ /dev/null
@@ -1,267 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type { IFunctionInfo, IFunctionParam } from '@univerjs/engine-formula';
-import type { IHelpFunctionOperationParams } from '../../../services/prompt.service';
-import { IUniverInstanceService, LocaleService } from '@univerjs/core';
-import { Popup } from '@univerjs/design';
-import { IEditorService } from '@univerjs/docs-ui';
-import { CloseSingle, DetailsSingle, MoreSingle } from '@univerjs/icons';
-import { ILayoutService, ISidebarService, useDependency, useInjector } from '@univerjs/ui';
-
-import React, { useEffect, useState } from 'react';
-import { throttleTime } from 'rxjs';
-import { IFormulaPromptService } from '../../../services/prompt.service';
-import { generateParam } from '../../../services/utils';
-import { useResizeScrollObserver } from '../resize-scroll-observer';
-import styles from './index.module.less';
-
-export function HelpFunction() {
- const [visible, setVisible] = useState(false);
- const [contentVisible, setContentVisible] = useState(true);
- const [helpVisible, setHelpVisible] = useState(true);
- const [paramIndex, setParamIndex] = useState(0);
- const [offset, setOffset] = useState<[number, number]>([0, 0]);
- const [decoratorPosition, setDecoratorPosition] = useState({ left: 0, top: 0 });
- const [functionInfo, setFunctionInfo] = useState<IFunctionInfo | null>(null);
- const promptService = useDependency(IFormulaPromptService);
- const localeService = useDependency(LocaleService);
- const required = localeService.t('formula.prompt.required');
- const optional = localeService.t('formula.prompt.optional');
-
- const univerInstanceService = useDependency(IUniverInstanceService);
- const editorService = useDependency(IEditorService);
- const sidebarService = useDependency(ISidebarService);
- const injector = useInjector();
-
- // window resize/scroll, update HelpFunction position
- useResizeScrollObserver(updatePosition);
-
- useEffect(() => {
- const subscription = promptService.help$.subscribe((params: IHelpFunctionOperationParams) => {
- const { visible, paramIndex, functionInfo } = params;
- if (!visible) {
- setVisible(visible);
- return;
- }
-
- const position = getPosition();
-
- if (position == null) {
- return;
- }
-
- const { left, top, height } = position;
-
- if (functionInfo.description === '' && functionInfo.functionParameter.length === 0) {
- return;
- }
-
- setOffset([left, top + height]);
- setParamIndex(paramIndex);
- setFunctionInfo(functionInfo);
- setDecoratorPosition({ left, top });
- setVisible(visible);
- });
-
- const sidebarSubscription = sidebarService.scrollEvent$.pipe(throttleTime(100)).subscribe(updatePosition);
-
- return () => {
- subscription?.unsubscribe();
- sidebarSubscription.unsubscribe();
- };
- }, []);
-
- function updatePosition() {
- if (!helpVisible) {
- return;
- }
-
- const position = getPosition();
-
- if (position == null) {
- return;
- }
-
- const { left, top, height } = position;
- setOffset([left, top + height]);
- }
-
- function getPosition() {
- const documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
- if (!documentDataModel) {
- return;
- }
- const editorUnitId = documentDataModel.getUnitId();
-
- if (!editorService.isEditor(editorUnitId)) {
- return;
- }
-
- const editor = editorService.getEditor(editorUnitId);
- return editor?.getBoundingClientRect();
- }
-
- function handleSwitchActive(paramIndex: number) {
- setParamIndex(paramIndex);
- }
-
- function handleClose() {
- setHelpVisible(!helpVisible);
-
- // focus editor
- // FIXME: @Jocs, still need re focus?
- const layoutService = injector.get(ILayoutService);
- layoutService.focus();
- }
-
- return (
- <>
- {helpVisible
- ? (
- <Popup visible={visible} offset={offset}>
- {functionInfo
- ? (
- <div className={styles.formulaHelpFunction}>
- <div className={styles.formulaHelpFunctionTitle}>
- <Help
- prefix={functionInfo.functionName}
- value={functionInfo.functionParameter}
- active={paramIndex}
- onClick={handleSwitchActive}
- />
- <div className={styles.formulaHelpFunctionTitleIcons}>
- <div
- className={styles.formulaHelpFunctionTitleIcon}
- style={{ transform: contentVisible ? 'rotateZ(-90deg)' : 'rotateZ(90deg)' }}
- onClick={() => setContentVisible(!contentVisible)}
- >
- <MoreSingle />
- </div>
- <div
- className={styles.formulaHelpFunctionTitleIcon}
- onClick={handleClose}
- >
- <CloseSingle />
- </div>
- </div>
- </div>
-
- <div
- className={styles.formulaHelpFunctionContent}
- style={{
- height: contentVisible ? 'unset' : 0,
- padding: contentVisible ? 'revert-layer' : 0,
- }}
- >
- <div className={styles.formulaHelpFunctionContentInner}>
- <Params
- title={localeService.t('formula.prompt.helpExample')}
- value={`${functionInfo.functionName}(${functionInfo.functionParameter
- .map((item) => item.example)
- .join(',')})`}
- />
- <Params
- title={localeService.t('formula.prompt.helpAbstract')}
- value={functionInfo.description}
- />
- {functionInfo &&
- functionInfo.functionParameter &&
- functionInfo.functionParameter.map((item: IFunctionParam, i: number) => (
- <Params
- key={i}
- className={paramIndex === i ? styles.formulaHelpFunctionActive : ''}
- title={item.name}
- value={`${item.require ? required : optional} ${item.detail}`}
- />
- ))}
- </div>
- </div>
- </div>
- )
- : (
- <></>
- )}
- </Popup>
- )
- : visible
- ? (
- <div
- className={styles.formulaHelpDecorator}
- onClick={() => setHelpVisible(!helpVisible)}
- style={{ left: decoratorPosition.left - 24, top: decoratorPosition.top }}
- >
- <DetailsSingle />
- </div>
- )
- : (
- <></>
- )}
- </>
- );
-}
-
-interface IParamsProps {
- className?: string;
- title?: string;
- value?: string;
-}
-
-const Params = (props: IParamsProps) => (
- <div className={styles.formulaHelpFunctionContentParams}>
- <div className={`
- ${styles.formulaHelpFunctionContentParamsTitle}
- ${props.className}
- `}
- >
- {props.title}
- </div>
- <div className={styles.formulaHelpFunctionContentParamsDetail}>{props.value}</div>
- </div>
-);
-
-interface IHelpProps {
- prefix?: string;
- value?: IFunctionParam[];
- active: number;
- onClick: (paramIndex: number) => void;
-}
-
-const Help = (props: IHelpProps) => {
- const { prefix, value, active, onClick } = props;
- return (
- <div className={styles.formulaHelpParam}>
- <span className={styles.formulaHelpParamPrefix}>
- {prefix}
- (
- </span>
- {value &&
- value.map((item: IFunctionParam, i: number) => (
- // TODO@Dushusir: more params needs to be active
- <span key={i} className={styles.formulaHelpParamItem}>
- <span
- className={active === i ? styles.formulaHelpFunctionActive : styles.formulaHelpParamActive}
- onClick={() => onClick(i)}
- >
- {generateParam(item)}
- </span>
- {i === value.length - 1 ? '' : ','}
- </span>
- ))}
- )
- </div>
- );
-};
diff --git a/packages/sheets-formula-ui/src/views/prompt/help-function/index.module.less b/packages/sheets-formula-ui/src/views/prompt/help-function/index.module.less
deleted file mode 100644
index bfe186d777..0000000000
--- a/packages/sheets-formula-ui/src/views/prompt/help-function/index.module.less
+++ /dev/null
@@ -1,129 +0,0 @@
-@width: 250px;
-@max-height: 350px;
-@icon-size: 24px;
-
-.formula-help-function {
- user-select: none;
-
- box-sizing: border-box;
- width: @width;
- margin: 0;
-
- line-height: 20px;
- list-style: none;
-
- background-color: rgb(var(--bg-color-secondary));
- border: 1px solid rgb(var(--border-color));
- border-radius: var(--border-radius-lg);
- outline: none;
- box-shadow: var(--box-shadow-base);
-
- &-title {
- display: flex;
- align-items: center;
- justify-content: space-between;
-
- box-sizing: border-box;
- padding: var(--padding-base) var(--padding-lg);
-
- font-size: var(--font-size-xxs);
- font-weight: 500;
- color: rgb(var(--text-color));
- overflow-wrap: anywhere;
-
- border-bottom: 1px solid rgb(var(--border-color));
-
- &-icons {
- display: flex;
- }
-
- &-icon {
- cursor: pointer;
-
- display: flex;
- align-items: center;
- justify-content: center;
-
- width: @icon-size;
- height: @icon-size;
- margin-left: var(--margin-xs);
- padding: 0;
-
- font-size: var(--font-size-xs);
- color: rgb(var(--text-color-secondary));
-
- background-color: transparent;
- border: none;
- border-radius: var(--border-radius-base);
- outline: none;
-
- transition: background-color 0.2s;
-
- &:hover {
- background-color: rgb(var(--bg-color-hover));
- }
- }
- }
-
- &-content {
- overflow-y: auto;
- box-sizing: border-box;
- max-height: @max-height;
- padding: 0 var(--padding-lg) var(--padding-base) var(--padding-lg);
-
- &-inner {
- margin-top: var(--margin-sm);
- }
-
- &-params {
- margin: var(--margin-xs) 0;
-
- &-title {
- margin-bottom: var(--margin-xs);
- font-size: var(--font-size-xs);
- font-weight: 500;
- color: rgb(var(--text-color));
- }
-
- &-detail {
- font-size: var(--font-size-xxs);
- font-weight: 400;
- white-space: pre-wrap;
- word-wrap: break-word;
- color: rgb(var(--text-color-secondary));
- }
- }
- }
-
- &-active {
- color: rgb(var(--primary-color));
- }
-}
-
-.formula-help-decorator {
- cursor: pointer;
-
- position: fixed;
- z-index: 10;
-
- display: flex;
- align-items: center;
- justify-content: center;
-
- padding: var(--padding-xs);
-}
-
-.formula-help-param {
- z-index: 1;
- &-prefix {
- z-index: 1;
- }
-
- &-item {
- z-index: 1;
- }
-
- &-active {
- z-index: 1;
- }
-}
diff --git a/packages/sheets-formula-ui/src/views/prompt/resize-scroll-observer.ts b/packages/sheets-formula-ui/src/views/prompt/resize-scroll-observer.ts
deleted file mode 100644
index 3fd099e325..0000000000
--- a/packages/sheets-formula-ui/src/views/prompt/resize-scroll-observer.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { useEffect } from 'react';
-
-type Callback = () => void;
-
-export const useResizeScrollObserver = (callback: Callback, delay: number = 100): void => {
- useEffect(() => {
- let throttleTimeout: number | null = null;
-
- const throttledCallback = () => {
- if (throttleTimeout === null) {
- throttleTimeout = window.setTimeout(() => {
- callback();
- throttleTimeout = null;
- }, delay);
- }
- };
-
- window.addEventListener('scroll', throttledCallback);
- window.addEventListener('resize', throttledCallback);
-
- return () => {
- if (throttleTimeout !== null) {
- clearTimeout(throttleTimeout);
- }
- window.removeEventListener('scroll', throttledCallback);
- window.removeEventListener('resize', throttledCallback);
- };
- }, [callback, delay]);
-};
-
-export default useResizeScrollObserver;
diff --git a/packages/sheets-formula-ui/src/views/prompt/search-function/SearchFunction.tsx b/packages/sheets-formula-ui/src/views/prompt/search-function/SearchFunction.tsx
deleted file mode 100644
index ff1070df49..0000000000
--- a/packages/sheets-formula-ui/src/views/prompt/search-function/SearchFunction.tsx
+++ /dev/null
@@ -1,184 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type { ISearchItem } from '@univerjs/sheets-formula';
-import type { INavigateParam, ISearchFunctionOperationParams } from '../../../services/prompt.service';
-
-import { Direction, IUniverInstanceService } from '@univerjs/core';
-import { Popup } from '@univerjs/design';
-import { IEditorService } from '@univerjs/docs-ui';
-import { useDependency } from '@univerjs/ui';
-import React, { useEffect, useRef, useState } from 'react';
-import { IFormulaPromptService } from '../../../services/prompt.service';
-import styles from './index.module.less';
-
-export function SearchFunction() {
- const [visible, setVisible] = useState(false);
- const [active, setActive] = useState(0);
- const [offset, setOffset] = useState<[number, number]>([0, 0]);
- const [searchList, setSearchList] = useState<ISearchItem[]>([]);
- const [searchText, setSearchText] = useState<string>('');
- const ulRef = useRef<HTMLUListElement>(null);
- const promptService = useDependency(IFormulaPromptService);
- const univerInstanceService = useDependency(IUniverInstanceService);
- const editorService = useDependency(IEditorService);
-
- useEffect(() => {
- // TODO@Dushusir: How to get updated values in subscribe callback better
- let updatedSearchList: ISearchItem[] = [];
- let updatedActive = 0;
- const subscribeSearch = promptService.search$.subscribe((params: ISearchFunctionOperationParams) => {
- const { visible, searchText, searchList } = params;
- if (!visible) {
- setVisible(visible);
- return;
- }
-
- // const isFocusFormulaEditor = contextService.getContextValue(FOCUSING_FX_BAR_EDITOR);
-
- const position = getPosition();
-
- if (position == null) {
- return;
- }
-
- const { left, top, height } = position;
-
- setSearchText(searchText);
- setSearchList(searchList);
- updatedSearchList = searchList;
- setOffset([left, top + height]);
- setVisible(visible);
- setActive(0); // Reset active state
- updatedActive = 0;
- });
-
- const subscribeNavigate = promptService.navigate$.subscribe((params: INavigateParam) => {
- const { direction } = params;
- if (direction === Direction.UP) {
- let nextActive = updatedActive - 1;
- nextActive = nextActive < 0 ? updatedSearchList.length - 1 : nextActive;
- setActive(nextActive);
- updatedActive = nextActive;
- } else if (direction === Direction.DOWN) {
- let nextActive = updatedActive + 1;
- nextActive = nextActive >= updatedSearchList.length ? 0 : nextActive;
- setActive(nextActive);
- updatedActive = nextActive;
- }
-
- scrollToVisible(updatedActive);
- });
-
- const subscribeAccept = promptService.accept$.subscribe((params: boolean) => {
- const functionName = updatedSearchList[updatedActive].name;
- promptService.acceptFormulaName(functionName);
- });
-
- return () => {
- subscribeSearch?.unsubscribe();
- subscribeNavigate?.unsubscribe();
- subscribeAccept?.unsubscribe();
- };
- }, []);
-
- function getPosition() {
- const documentDataModel = univerInstanceService.getCurrentUniverDocInstance()!;
-
- const editorUnitId = documentDataModel.getUnitId();
-
- if (!editorService.isEditor(editorUnitId)) {
- return;
- }
-
- const editor = editorService.getEditor(editorUnitId);
-
- return editor?.getBoundingClientRect();
- }
-
- function handleLiMouseEnter(index: number) {
- setActive(index);
- }
-
- function handleLiMouseLeave() {
- setActive(-1);
- }
-
- function scrollToVisible(liIndex: number) {
- // Get the <li> element
- const liElement = ulRef.current?.querySelectorAll(`.${styles.formulaSearchFunctionItem}`)[
- liIndex
- ] as HTMLLIElement;
-
- if (!liElement) return;
-
- // Get the <ul> element
- const ulElement = liElement.parentNode as HTMLUListElement;
-
- if (!ulElement) return;
-
- // Get the height of the <ul> element
- const ulRect = ulElement.getBoundingClientRect();
- const ulTop = ulRect.top;
- const ulHeight = ulElement.offsetHeight;
-
- // Get the position and height of the <li> element
- const liRect = liElement.getBoundingClientRect();
- const liTop = liRect.top;
- const liHeight = liRect.height;
-
- // If the <li> element is within the visible area, no scrolling operation is performed
- if (liTop >= 0 && liTop > ulTop && liTop - ulTop + liHeight <= ulHeight) {
- return;
- }
-
- // Calculate scroll position
- const scrollTo = liElement.offsetTop - (ulHeight - liHeight) / 2;
-
- // Perform scrolling operation
- ulElement.scrollTo({
- top: scrollTo,
- behavior: 'smooth',
- });
- }
-
- return searchList.length > 0 && (
- <Popup visible={visible} offset={offset}>
- <ul className={styles.formulaSearchFunction} ref={ulRef}>
- {searchList.map((item, index) => (
- <li
- key={index}
- className={active === index
- ? `
- ${styles.formulaSearchFunctionItem}
- ${styles.formulaSearchFunctionItemActive}
- `
- : styles.formulaSearchFunctionItem}
- onMouseEnter={() => handleLiMouseEnter(index)}
- onMouseLeave={handleLiMouseLeave}
- onClick={() => promptService.acceptFormulaName(item.name)}
- >
- <span className={styles.formulaSearchFunctionItemName}>
- <span className={styles.formulaSearchFunctionItemNameLight}>{item.name.substring(0, searchText.length)}</span>
- <span>{item.name.slice(searchText.length)}</span>
- </span>
- <span className={styles.formulaSearchFunctionItemDesc}>{item.desc}</span>
- </li>
- ))}
- </ul>
- </Popup>
- );
-}
diff --git a/packages/sheets-formula-ui/src/views/prompt/search-function/index.module.less b/packages/sheets-formula-ui/src/views/prompt/search-function/index.module.less
deleted file mode 100644
index 26b7116c17..0000000000
--- a/packages/sheets-formula-ui/src/views/prompt/search-function/index.module.less
+++ /dev/null
@@ -1,55 +0,0 @@
-@width: 250px;
-@max-height: 400px;
-
-.formula-search-function {
- overflow-y: auto;
-
- box-sizing: border-box;
- width: @width;
- max-height: @max-height;
- margin: 0;
- padding: var(--padding-sm);
-
- line-height: 20px;
- list-style: none;
-
- background-color: rgb(var(--bg-color-secondary));
- border: 1px solid rgb(var(--border-color));
- border-radius: var(--border-radius-lg);
- outline: none;
- box-shadow: var(--box-shadow-base);
-
- overflow: hidden;
- overflow-y: auto;
-
- &-item {
- cursor: pointer;
-
- box-sizing: border-box;
- padding: var(--padding-xs) var(--padding-sm);
-
- color: rgb(var(--text-color));
-
- border-radius: var(--border-radius-base);
-
- transition: background 0.2s;
-
- &-name {
- font-size: var(--font-size-xxs);
-
- &-light {
- color: rgb(var(--error-color));
- }
- }
-
- &-desc {
- display: block;
- font-size: var(--font-size-xxs);
- color: rgb(var(--grey-500));
- }
-
- &-active {
- background-color: rgb(var(--bg-color-hover));
- }
- }
-}
diff --git a/packages/sheets-formula-ui/src/views/range-selector/index.module.less b/packages/sheets-formula-ui/src/views/range-selector/index.module.less
deleted file mode 100644
index 36195d04e4..0000000000
--- a/packages/sheets-formula-ui/src/views/range-selector/index.module.less
+++ /dev/null
@@ -1,69 +0,0 @@
-.sheet-range-selector {
- &-text-wrap {
- height: 32px;
- padding: 6px 8px 2px 6px;
- width: 100%;
- display: flex;
- justify-content: space-around;
- align-items: center;
- gap: 8px;
- border: 1px solid rgb(var(--border-color));
- border-radius: var(--border-radius-base);
- box-sizing: border-box;
- position: relative;
- }
-
- &-placeholder {
- font-size: 14px;
- color: rgb(var(--grey-500));
- position: absolute;
- left: 5px;
- bottom: 8px;
- }
-
- &-error {
- border: 1px solid rgb(var(--red-500)) !important;
- }
-
- &-error-wrap {
- font-size: 12px;
- color: rgb(var(--red-500));
- position: absolute;
- bottom: -18px;
- left: 0px;
- }
-
- &-text {
- position: relative;
- height: 22px;
- width: 100%;
- }
-
- &-active {
- border-color: rgb(var(--hyacinth-500));
- }
-
- &-icon {
- cursor: pointer;
- }
-
- &-dialog {
- max-height: 240px;
- overflow-y: auto;
- scrollbar-color: #73737366 transparent;
- scrollbar-gutter: stable;
- scrollbar-width: thin;
-
- &-item {
- display: flex;
- align-items: center;
- justify-content: flex-start;
- gap: 16px;
- margin-bottom: 8px;
-
- &-delete {
- cursor: pointer;
- }
- }
- }
-}
diff --git a/packages/sheets-formula-ui/src/views/range-selector/index.tsx b/packages/sheets-formula-ui/src/views/range-selector/index.tsx
index aea5059184..578fafe86c 100644
--- a/packages/sheets-formula-ui/src/views/range-selector/index.tsx
+++ b/packages/sheets-formula-ui/src/views/range-selector/index.tsx
@@ -18,7 +18,7 @@ import type { IUnitRangeName, Nullable } from '@univerjs/core';
import type { Editor, IRichTextEditorProps } from '@univerjs/docs-ui';
import type { ISelectionWithStyle, ISetSelectionsOperationParams } from '@univerjs/sheets';
import { ICommandService, LocaleService, RichTextBuilder } from '@univerjs/core';
-import { Button, clsx, Dialog, Input, Tooltip } from '@univerjs/design';
+import { Button, Dialog, Input, Tooltip } from '@univerjs/design';
import { IEditorService, RichTextEditor } from '@univerjs/docs-ui';
import { deserializeRangeWithSheet, LexerTreeBuilder, matchToken, sequenceNodeType, serializeRange, serializeRangeWithSheet } from '@univerjs/engine-formula';
import { DeleteSingle, IncreaseSingle, SelectRangeSingle } from '@univerjs/icons';
@@ -28,7 +28,6 @@ import { useEffect, useRef, useState } from 'react';
import { useStateRef } from '../formula-editor/hooks/use-state-ref';
import { useRangesHighlight } from './hooks/use-ranges-highlight';
import { useRangeSelectorSelectionChange } from './hooks/use-selection-change';
-import styles from './index.module.less';
import { verifyRange } from './util';
import { rangePreProcess } from './utils/range-pre-process';
@@ -180,9 +179,18 @@ export function RangeSelectorDialog(props: IRangeSelectorDialogProps) {
)}
onClose={onClose}
>
- <div ref={scrollbarRef} className={clsx(styles.sheetRangeSelectorDialog, '-univer-mx-6 univer-px-6')}>
+ <div
+ ref={scrollbarRef}
+ className={`
+ -univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6 univer-scrollbar-thin
+ univer-scrollbar-track-transparent univer-scrollbar-thumb-[#73737366]
+ `}
+ >
{ranges.map((text, index) => (
- <div key={index} className={styles.sheetRangeSelectorDialogItem}>
+ <div
+ key={index}
+ className="univer-mb-2 univer-flex univer-items-center univer-justify-start univer-gap-4"
+ >
<Input
className="univer-w-full"
placeholder={localeService.t('rangeSelector.placeHolder')}
@@ -191,7 +199,12 @@ export function RangeSelectorDialog(props: IRangeSelectorDialogProps) {
onChange={(value) => handleRangeInput(index, value)}
style={{ borderColor: focusIndex === index ? 'rgb(var(--primary-color))' : undefined }}
/>
- {ranges.length > 1 && <DeleteSingle className={styles.sheetRangeSelectorDialogItemDelete} onClick={() => handleRangeRemove(index)} />}
+ {ranges.length > 1 && (
+ <DeleteSingle
+ className="univer-cursor-pointer"
+ onClick={() => handleRangeRemove(index)}
+ />
+ )}
</div>
))}
{ranges.length < maxRangeCount && (
@@ -320,7 +333,7 @@ export function RangeSelector(props: IRangeSelectorProps) {
}}
icon={(
<Tooltip title={localeService.t('rangeSelector.buttonTooltip')} placement="bottom">
- <SelectRangeSingle className={styles.sheetRangeSelectorIcon} onClick={handleOpenModal} />
+ <SelectRangeSingle className="univer-cursor-pointer" onClick={handleOpenModal} />
</Tooltip>
)}
/>
diff --git a/packages/sheets-ui/src/views/editor-container/index.module.less b/packages/sheets-ui/src/views/editor-container/index.module.less
index f5d57ed5c1..19c13f673a 100644
--- a/packages/sheets-ui/src/views/editor-container/index.module.less
+++ b/packages/sheets-ui/src/views/editor-container/index.module.less
@@ -24,12 +24,5 @@
canvas {
position: absolute;
}
-
- .sheet-embedding-formula-editor-wrap {
- height: auto;
- border: none;
- padding: 0;
- border-radius: 0;
- }
}
}
diff --git a/packages/sheets-ui/src/views/formula-bar/index.module.less b/packages/sheets-ui/src/views/formula-bar/index.module.less
index 5b5261dbc5..94e65c5d99 100644
--- a/packages/sheets-ui/src/views/formula-bar/index.module.less
+++ b/packages/sheets-ui/src/views/formula-bar/index.module.less
@@ -111,14 +111,6 @@
width: 100%;
padding: 0 0 0 10px;
- .sheet-embedding-formula-editor-wrap {
- height: auto;
- border: none;
- padding: 0;
- border-radius: 0;
- height: 100%;
- }
-
.formula-content {
position: relative;