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.

feat(sheet): add auto fill ui & optimize the menu logic (#453)

YuHonga1f7a1e4dfb7
diff --git a/.vscode/settings.json b/.vscode/settings.json
index c488390e9d..1219e2fae8 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,6 +1,7 @@
{
"editor.codeActionsOnSave": {
- "source.fixAll.eslint": true
+ "source.fixAll.eslint": true,
+ "source.fixAll.stylelint": true
},
"javascript.preferences.importModuleSpecifier": "relative",
"typescript.preferences.importModuleSpecifier": "relative",
diff --git a/packages/ui-plugin-sheets/src/controllers/auto-fill.controller.ts b/packages/ui-plugin-sheets/src/controllers/auto-fill.controller.ts
index f61931470b..22be9da8ff 100644
--- a/packages/ui-plugin-sheets/src/controllers/auto-fill.controller.ts
+++ b/packages/ui-plugin-sheets/src/controllers/auto-fill.controller.ts
@@ -1,7 +1,9 @@
import { getCellInfoInMergeData } from '@univerjs/base-render';
+import { SelectionManagerService } from '@univerjs/base-sheets';
import {
Direction,
Disposable,
+ DisposableCollection,
ICellData,
ICommandService,
IRange,
@@ -12,6 +14,7 @@ import {
toDisposable,
Tools,
} from '@univerjs/core';
+import { Inject } from '@wendellhu/redi';
import { AutoClearContentCommand, AutoFillCommand } from '../commands/commands/auto-fill.command';
import { IAutoFillService } from '../services/auto-fill/auto-fill.service';
@@ -21,22 +24,25 @@ import {
APPLY_FUNCTIONS,
APPLY_TYPE,
APPLY_TYPE_IN_USE,
+ DATA_TYPE,
ICopyDataPiece,
IRuleConfirmedData,
} from '../services/auto-fill/type';
-import { IControlFillConfig, ISelectionRenderService } from '../services/selection/selection-render.service';
+import { ISelectionRenderService } from '../services/selection/selection-render.service';
-@OnLifecycle(LifecycleStages.Ready, AutoFillController)
+@OnLifecycle(LifecycleStages.Steady, AutoFillController)
export class AutoFillController extends Disposable {
private _direction: Direction | null = null;
private _beforeApplyData: Array<Array<Nullable<ICellData>>> = [];
private _applyType: APPLY_TYPE_IN_USE = APPLY_TYPE.SERIES;
private _hasFillingStyle: boolean = true;
+ private _copyData: ICopyDataPiece[] = [];
constructor(
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@ISelectionRenderService private readonly _selectionRenderService: ISelectionRenderService,
@ICommandService private readonly _commandService: ICommandService,
- @IAutoFillService private readonly _autoFillService: IAutoFillService
+ @IAutoFillService private readonly _autoFillService: IAutoFillService,
+ @Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService
) {
super();
this._init();
@@ -51,13 +57,55 @@ export class AutoFillController extends Disposable {
}
private _onSelectionControlFillChanged() {
+ const disposableCollection = new DisposableCollection();
this.disposeWithMe(
toDisposable(
- this._selectionRenderService.controlFillConfig$.subscribe((config: IControlFillConfig | null) => {
- if (!config) {
- return;
- }
- this._handleFillDrag(config.oldRange, config.newRange);
+ this._selectionManagerService.selectionInfo$.subscribe(() => {
+ // Each range change requires re-listening
+ disposableCollection.dispose();
+
+ const selectionControls = this._selectionRenderService.getCurrentControls();
+ selectionControls.forEach((controlSelection) => {
+ disposableCollection.add(
+ toDisposable(
+ controlSelection.selectionFilled$.subscribe((filled) => {
+ if (filled == null) {
+ return;
+ }
+ const { startColumn, endColumn, startRow, endRow } = controlSelection.model;
+ const {
+ startColumn: newStartColumn,
+ endColumn: newEndColumn,
+ startRow: newStartRow,
+ endRow: newEndRow,
+ } = filled || {};
+ // if no change happened, return
+ if (
+ startColumn === newStartColumn &&
+ endColumn === newEndColumn &&
+ startRow === newStartRow &&
+ endRow === newEndRow
+ ) {
+ return;
+ }
+
+ const sourceRange = {
+ startColumn,
+ endColumn,
+ startRow,
+ endRow,
+ };
+ const destRange = {
+ startColumn: newStartColumn || startColumn,
+ endColumn: newEndColumn || endColumn,
+ startRow: newStartRow || startRow,
+ endRow: newEndRow || endRow,
+ };
+ this._handleFillDrag(sourceRange, destRange);
+ })
+ )
+ );
+ });
})
)
);
@@ -378,6 +426,8 @@ export class AutoFillController extends Disposable {
} else if (destRange.endColumn > sourceRange.endColumn) {
direction = Direction.RIGHT;
applyRange.startColumn = sourceRange.endColumn + 1;
+ } else {
+ return;
}
this._direction = direction;
@@ -397,7 +447,14 @@ export class AutoFillController extends Disposable {
}
this._beforeApplyData = applyData;
this._autoFillService.setRanges(destRange, sourceRange, applyRange);
- this._autoFillService.setApplyType(APPLY_TYPE.SERIES);
+ this._copyData = this._getCopyData(sourceRange, direction);
+ if (this._hasSeries(this._copyData)) {
+ this._autoFillService.setDisableApplyType(APPLY_TYPE.SERIES, false);
+ this._autoFillService.setApplyType(APPLY_TYPE.SERIES);
+ } else {
+ this._autoFillService.setDisableApplyType(APPLY_TYPE.SERIES, true);
+ this._autoFillService.setApplyType(APPLY_TYPE.COPY);
+ }
}
// auto fill entry
@@ -425,7 +482,7 @@ export class AutoFillController extends Disposable {
endColumn: applyEndColumn,
} = applyRange;
- const copyData = this._getCopyData(sourceRange, direction);
+ const copyData = this._copyData;
let csLen;
if (direction === Direction.DOWN || direction === Direction.UP) {
@@ -510,4 +567,16 @@ export class AutoFillController extends Disposable {
applyMergeRanges,
});
}
+
+ private _hasSeries(copyData: ICopyDataPiece[]) {
+ return copyData.some((copyDataPiece) => {
+ const res = Object.keys(copyDataPiece).some((type) => {
+ if (copyDataPiece[type as DATA_TYPE]?.length && type !== DATA_TYPE.OTHER) {
+ return true;
+ }
+ return false;
+ });
+ return res;
+ });
+ }
}
diff --git a/packages/ui-plugin-sheets/src/locale/en-US.ts b/packages/ui-plugin-sheets/src/locale/en-US.ts
index 01b7093d66..b872f45428 100644
--- a/packages/ui-plugin-sheets/src/locale/en-US.ts
+++ b/packages/ui-plugin-sheets/src/locale/en-US.ts
@@ -546,4 +546,10 @@ export default {
clickToCopy: 'click to copy',
copied: 'copied!',
},
+ autoFill: {
+ copy: 'Copy Cell',
+ series: 'Fill Series',
+ formatOnly: 'Format Only',
+ noFormat: 'No Format',
+ },
};
diff --git a/packages/ui-plugin-sheets/src/locale/zh-CN.ts b/packages/ui-plugin-sheets/src/locale/zh-CN.ts
index 5bcf7fce9c..722dd6a7d8 100644
--- a/packages/ui-plugin-sheets/src/locale/zh-CN.ts
+++ b/packages/ui-plugin-sheets/src/locale/zh-CN.ts
@@ -410,4 +410,10 @@ export default {
clickToCopy: '点击复制数值',
copied: '数据复制成功,快去粘贴数据吧!',
},
+ autoFill: {
+ copy: '复制单元格',
+ series: '填充序列',
+ formatOnly: '仅填充格式',
+ noFormat: '不带格式填充',
+ },
};
diff --git a/packages/ui-plugin-sheets/src/services/auto-fill/auto-fill.service.ts b/packages/ui-plugin-sheets/src/services/auto-fill/auto-fill.service.ts
index 0fa08430cb..3abb5db0ff 100644
--- a/packages/ui-plugin-sheets/src/services/auto-fill/auto-fill.service.ts
+++ b/packages/ui-plugin-sheets/src/services/auto-fill/auto-fill.service.ts
@@ -10,7 +10,15 @@ import {
import { createIdentifier, Inject } from '@wendellhu/redi';
import { BehaviorSubject, Observable } from 'rxjs';
-import { chnNumberRule, chnWeek2Rule, chnWeek3Rule, extendNumberRule, numberRule, otherRule } from './rules';
+import {
+ chnNumberRule,
+ chnWeek2Rule,
+ chnWeek3Rule,
+ extendNumberRule,
+ loopSeriesRule,
+ numberRule,
+ otherRule,
+} from './rules';
import { APPLY_TYPE, IAutoFillRule } from './type';
export interface IAutoFillService {
@@ -22,7 +30,16 @@ export interface IAutoFillService {
getRanges(): { sourceRange: IRange | null; destRange: IRange | null; applyRange: IRange | null };
setFillingStyle(isFillingStyle: boolean): void;
applyType$: Observable<APPLY_TYPE>;
+ menu$: Observable<IApplyMenuItem[]>;
+ setDisableApplyType: (type: APPLY_TYPE, disable: boolean) => void;
+}
+
+export interface IApplyMenuItem {
+ label: string;
+ value: APPLY_TYPE;
+ disable: boolean;
}
+
@OnLifecycle(LifecycleStages.Rendered, AutoFillService)
export class AutoFillService extends Disposable implements IAutoFillService {
private _rules: IAutoFillRule[] = [];
@@ -32,6 +49,30 @@ export class AutoFillService extends Disposable implements IAutoFillService {
private _destRange: IRange | null = null;
private _applyRange: IRange | null = null;
readonly applyType$ = this._applyType$.asObservable();
+
+ private readonly _menu$: BehaviorSubject<IApplyMenuItem[]> = new BehaviorSubject<IApplyMenuItem[]>([
+ {
+ label: 'autoFill.copy',
+ value: APPLY_TYPE.COPY,
+ disable: false,
+ },
+ {
+ label: 'autoFill.series',
+ value: APPLY_TYPE.SERIES,
+ disable: false,
+ },
+ {
+ label: 'autoFill.formatOnly',
+ value: APPLY_TYPE.ONLY_FORMAT,
+ disable: false,
+ },
+ {
+ label: 'autoFill.noFormat',
+ value: APPLY_TYPE.NO_FORMAT,
+ disable: false,
+ },
+ ]);
+ readonly menu$ = this._menu$.asObservable();
constructor(
@Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,
@Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,
@@ -42,7 +83,15 @@ export class AutoFillService extends Disposable implements IAutoFillService {
}
private _init() {
- this._rules = [numberRule, extendNumberRule, chnNumberRule, chnWeek2Rule, chnWeek3Rule, otherRule];
+ this._rules = [
+ numberRule,
+ extendNumberRule,
+ chnNumberRule,
+ chnWeek2Rule,
+ chnWeek3Rule,
+ loopSeriesRule,
+ otherRule,
+ ];
// this._applyType = APPLY_TYPE.SERIES;
this._isFillingStyle = true;
}
@@ -80,6 +129,20 @@ export class AutoFillService extends Disposable implements IAutoFillService {
applyRange: this._applyRange,
};
}
+
+ setDisableApplyType(type: APPLY_TYPE, disable: boolean) {
+ this._menu$.next(
+ this._menu$.getValue().map((item) => {
+ if (item.value === type) {
+ return {
+ ...item,
+ disable,
+ };
+ }
+ return item;
+ })
+ );
+ }
}
export const IAutoFillService = createIdentifier<AutoFillService>('univer.auto-fill-service');
diff --git a/packages/ui-plugin-sheets/src/services/auto-fill/rules.ts b/packages/ui-plugin-sheets/src/services/auto-fill/rules.ts
index 92a4c34cdb..5dc5f42fd7 100644
--- a/packages/ui-plugin-sheets/src/services/auto-fill/rules.ts
+++ b/packages/ui-plugin-sheets/src/services/auto-fill/rules.ts
@@ -6,17 +6,22 @@ import {
fillChnWeek,
fillCopy,
fillExtendNumber,
+ fillLoopSeries,
fillSeries,
+ getLoopSeriesInfo,
isChnNumber,
isChnWeek2,
+ isChnWeek3,
isEqualDiff,
+ isLoopSeries,
matchExtendNumber,
} from './tools';
import { APPLY_TYPE, DATA_TYPE, IAutoFillRule } from './type';
export const numberRule: IAutoFillRule = {
type: DATA_TYPE.NUMBER,
- match: (cellData) => typeof cellData?.v === 'number',
+ match: (cellData) => typeof cellData?.v === 'number' || !isNaN(Number(cellData?.v)),
+ // TODO@yuhongz: not the good way to match number, will be changed after cell type is supported
isContinue: (prev, cur) => {
if (prev.type === DATA_TYPE.NUMBER) {
return true;
@@ -225,7 +230,7 @@ export const chnWeek2Rule: IAutoFillRule = {
export const chnWeek3Rule: IAutoFillRule = {
type: DATA_TYPE.CHN_WEEK3,
- match: (cellData) => isChnWeek2(cellData?.m || ''),
+ match: (cellData) => isChnWeek3(cellData?.m || ''),
isContinue: (prev, cur) => prev.type === DATA_TYPE.CHN_WEEK3,
applyFunctions: {
[APPLY_TYPE.SERIES]: (data, len, direction) => {
@@ -273,3 +278,51 @@ export const chnWeek3Rule: IAutoFillRule = {
},
},
};
+
+export const loopSeriesRule: IAutoFillRule = {
+ type: DATA_TYPE.LOOP_SERIES,
+ match: (cellData) => isLoopSeries(cellData?.m || ''),
+ isContinue: (prev, cur) => {
+ if (prev.type === DATA_TYPE.LOOP_SERIES) {
+ return getLoopSeriesInfo(prev.cellData?.m || '').name === getLoopSeriesInfo(cur?.m || '').name;
+ }
+ return false;
+ },
+ applyFunctions: {
+ [APPLY_TYPE.SERIES]: (data, len, direction) => {
+ const isReverse = direction === Direction.LEFT || direction === Direction.UP;
+ const { series } = getLoopSeriesInfo(data[0]?.m || '');
+ if (data.length === 1) {
+ return fillCopy(data, len);
+ }
+ const dataNumArr = [];
+ let cycleIndex = 0;
+ for (let i = 0; i < data.length; i++) {
+ const formattedValue = data[i]?.m;
+ if (formattedValue) {
+ if (formattedValue === series[0]) {
+ if (i === 0) {
+ dataNumArr.push(0);
+ } else {
+ cycleIndex++;
+ dataNumArr.push(cycleIndex * series.length);
+ }
+ } else {
+ dataNumArr.push(series.indexOf(formattedValue) + cycleIndex * 7);
+ }
+ }
+ }
+
+ if (isReverse) {
+ data.reverse();
+ dataNumArr.reverse();
+ }
+
+ if (isEqualDiff(dataNumArr)) {
+ const step = dataNumArr[1] - dataNumArr[0];
+ return fillLoopSeries(data, len, step, series);
+ }
+ return fillCopy(data, len);
+ },
+ },
+};
diff --git a/packages/ui-plugin-sheets/src/services/auto-fill/tools.ts b/packages/ui-plugin-sheets/src/services/auto-fill/tools.ts
index a69c578646..3fcae9ffed 100644
--- a/packages/ui-plugin-sheets/src/services/auto-fill/tools.ts
+++ b/packages/ui-plugin-sheets/src/services/auto-fill/tools.ts
@@ -498,7 +498,7 @@ export function fillChnWeek(data: Array<Nullable<ICellData>>, len: number, step:
const keywordMap = [
['日', '一', '二', '三', '四', '五', '六'],
['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
- ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五'],
+ ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
];
if (weekType >= keywordMap.length) return [];
const keyword = keywordMap[weekType];
@@ -560,3 +560,75 @@ export function fillChnNumber(data: Array<Nullable<ICellData>>, len: number, ste
return applyData;
}
+
+const LOOP_SERIES: { [key: string]: string[] } = {
+ enWeek1: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
+ enWeek2: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
+ enMonth1: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
+ enMonth2: [
+ 'January',
+ 'February',
+ 'March',
+ 'April',
+ 'May',
+ 'June',
+ 'July',
+ 'August',
+ 'September',
+ 'October',
+ 'November',
+ 'December',
+ ],
+ chnMonth1: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
+ chnMonth2: ['正月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '腊月'],
+ chHour1: ['子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥'],
+ chHour2: ['子时', '丑时', '寅时', '卯时', '辰时', '巳时', '午时', '未时', '申时', '酉时', '戌时', '亥时'],
+ chYear1: ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸'],
+ chSeason1: ['春', '夏', '秋', '冬'],
+ chSeason2: ['春季', '夏季', '秋季', '冬季'],
+};
+
+export function isLoopSeries(txt: string) {
+ let isLoopSeries = false;
+ Object.keys(LOOP_SERIES).forEach((key) => {
+ if (LOOP_SERIES[key].includes(txt)) {
+ isLoopSeries = true;
+ }
+ });
+ return isLoopSeries;
+}
+
+export function getLoopSeriesInfo(txt: string) {
+ let name = '';
+ const series: string[] = [];
+ Object.keys(LOOP_SERIES).forEach((key) => {
+ if (LOOP_SERIES[key].includes(txt)) {
+ name = key;
+ series.push(...LOOP_SERIES[key]);
+ }
+ });
+ return { name, series };
+}
+
+export function fillLoopSeries(data: Array<Nullable<ICellData>>, len: number, step: number, series: string[]) {
+ const seriesLen = series.length;
+ const applyData = [];
+
+ for (let i = 1; i <= len; i++) {
+ const index = (i - 1) % data.length;
+ const d = Tools.deepClone(data[index]);
+
+ const last = data[data.length - 1]?.m;
+ const num = series.indexOf(last as string) + step * i;
+
+ const rsd = num % seriesLen;
+ if (d) {
+ d.m = series[rsd];
+ d.v = series[rsd];
+
+ applyData.push(d);
+ }
+ }
+
+ return applyData;
+}
diff --git a/packages/ui-plugin-sheets/src/services/auto-fill/type.ts b/packages/ui-plugin-sheets/src/services/auto-fill/type.ts
index e001ea1af4..5771ff8c6a 100644
--- a/packages/ui-plugin-sheets/src/services/auto-fill/type.ts
+++ b/packages/ui-plugin-sheets/src/services/auto-fill/type.ts
@@ -7,6 +7,7 @@ export enum DATA_TYPE {
CHN_NUMBER = 'chnNumber',
CHN_WEEK2 = 'chnWeek2',
CHN_WEEK3 = 'chnWeek3',
+ LOOP_SERIES = 'loopSeries',
OTHER = 'other',
}
diff --git a/packages/ui-plugin-sheets/src/services/selection/selection-render.service.ts b/packages/ui-plugin-sheets/src/services/selection/selection-render.service.ts
index ba15613fe8..7b7a4c83bf 100644
--- a/packages/ui-plugin-sheets/src/services/selection/selection-render.service.ts
+++ b/packages/ui-plugin-sheets/src/services/selection/selection-render.service.ts
@@ -227,43 +227,6 @@ export class SelectionRenderService implements ISelectionRenderService {
} else {
control.disableHeaderHighlight();
}
- // update drag observer
- control.selectionFilled$.subscribe((filled) => {
- if (filled == null) {
- return;
- }
- const { startColumn, endColumn, startRow, endRow } = control.model;
- const {
- startColumn: newStartColumn,
- endColumn: newEndColumn,
- startRow: newStartRow,
- endRow: newEndRow,
- } = filled || {};
- // if no change happened, return
- if (
- startColumn === newStartColumn &&
- endColumn === newEndColumn &&
- startRow === newStartRow &&
- endRow === newEndRow
- ) {
- return;
- }
- this._controlFillConfig$.next({
- oldRange: {
- startColumn,
- endColumn,
- startRow,
- endRow,
- },
- newRange: {
- startColumn: newStartColumn || startColumn,
- endColumn: newEndColumn || endColumn,
- startRow: newStartRow || startRow,
- endRow: newEndRow || endRow,
- },
- });
- });
-
currentControls.push(control);
}
diff --git a/packages/ui-plugin-sheets/src/views/operate-container/SmartButton.tsx b/packages/ui-plugin-sheets/src/views/operate-container/AutoFillPopupMenu.tsx
similarity index 66%
rename from packages/ui-plugin-sheets/src/views/operate-container/SmartButton.tsx
rename to packages/ui-plugin-sheets/src/views/operate-container/AutoFillPopupMenu.tsx
index 688a64cfc2..797519fe7c 100644
--- a/packages/ui-plugin-sheets/src/views/operate-container/SmartButton.tsx
+++ b/packages/ui-plugin-sheets/src/views/operate-container/AutoFillPopupMenu.tsx
@@ -1,7 +1,7 @@
import { IRenderManagerService } from '@univerjs/base-render';
-import { ICommandInfo, ICommandService, IUniverInstanceService, toDisposable } from '@univerjs/core';
-import { Button, Dropdown } from '@univerjs/design';
-import { CheckMarkSingle, Paste } from '@univerjs/icons';
+import { ICommandInfo, ICommandService, IUniverInstanceService, LocaleService, toDisposable } from '@univerjs/core';
+import { Dropdown } from '@univerjs/design';
+import { Autofill, CheckMarkSingle, MoreDownSingle } from '@univerjs/icons';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useCallback, useEffect, useState } from 'react';
@@ -25,52 +25,31 @@ export interface IAnchorPoint {
col: number;
}
-export interface ISmartButtonMenuItem {
+export interface IAutoFillPopupMenuItem {
label: string;
- value?: any;
- selected?: boolean;
+ value?: APPLY_TYPE;
index: number;
+ disable: boolean;
}
const useUpdate = () => {
- const [_, setState] = useState({});
+ const [, setState] = useState({});
return useCallback(() => setState({}), []);
};
-const menu = [
- {
- index: 0,
- label: 'copy',
- value: APPLY_TYPE.COPY,
- },
- {
- index: 1,
- label: 'series',
- value: APPLY_TYPE.SERIES,
- },
- {
- index: 2,
- label: 'format only',
- value: APPLY_TYPE.ONLY_FORMAT,
- },
- {
- index: 3,
- label: 'no format',
- value: APPLY_TYPE.NO_FORMAT,
- },
-];
-
-export const SmartButton: React.FC<{}> = () => {
+export const AutoFillPopupMenu: React.FC<{}> = () => {
const commandService = useDependency(ICommandService);
const sheetSkeletonManagerService = useDependency(SheetSkeletonManagerService);
const currentUniverService = useDependency(IUniverInstanceService);
const renderManagerService = useDependency(IRenderManagerService);
const selectionRenderService = useDependency(ISelectionRenderService);
const autoFillService = useDependency(IAutoFillService);
+ const localeService = useDependency(LocaleService);
+ const [menu, setMenu] = useState<IAutoFillPopupMenuItem[]>([]);
const [visible, setVisible] = useState(false);
const [anchor, setAnchor] = useState<IAnchorPoint>({ row: -1, col: -1 });
- const [selected, setSelected] = useState<number>(1);
+ const [selected, setSelected] = useState<APPLY_TYPE>(APPLY_TYPE.SERIES);
const forceUpdate = useUpdate();
const sheetObject = getSheetObject(currentUniverService, renderManagerService);
@@ -96,10 +75,19 @@ export const SmartButton: React.FC<{}> = () => {
return disposable.dispose;
}, [forceUpdate, commandService]);
+ useEffect(() => {
+ const disposable = toDisposable(
+ autoFillService.menu$.subscribe((menu) => {
+ setMenu(menu.map((i) => ({ ...i, index: menu.indexOf(i) })));
+ })
+ );
+ return disposable.dispose;
+ }, [autoFillService]);
+
useEffect(() => {
const disposable = toDisposable(
autoFillService.applyType$.subscribe((type) => {
- setSelected(menu.find((i) => i.value === type)?.index ?? 0);
+ setSelected(type);
})
);
return disposable.dispose;
@@ -123,26 +111,32 @@ export const SmartButton: React.FC<{}> = () => {
setVisible(visible);
};
- const handleClick = (item: ISmartButtonMenuItem) => {
+ const handleClick = (item: IAutoFillPopupMenuItem) => {
commandService.executeCommand(RefillCommand.id, { type: item.value });
};
+
+ const availableMenu = menu.filter((item) => !item.disable);
return (
<div style={{ left: `${relativeX}px`, top: `${relativeY}px`, position: 'absolute' }}>
<Dropdown
- placement="bottomRight"
+ placement="bottomLeft"
trigger={['click']}
overlay={
- <ul className={styles.smartButtonMenu} style={{ ...styles }}>
- {menu.map((item) => (
+ <ul className={styles.AutoFillPopupMenu} style={{ ...styles }}>
+ {availableMenu.map((item) => (
<li
key={item.index}
- onClick={(e) => handleClick(item)}
- className={styles.smartButtonMenuItem}
+ onClick={() => handleClick(item)}
+ className={styles.AutoFillPopupMenuItem}
>
- <span className={styles.smartButtonMenuItemIcon}>
- {item.index === selected ? <CheckMarkSingle /> : ''}
+ <span className={styles.AutoFillPopupMenuItemIcon}>
+ {item.value === selected ? (
+ <CheckMarkSingle style={{ color: 'rgb(var(--green-700, #409f11))' }} />
+ ) : (
+ ''
+ )}
</span>
- <span className={styles.smartButtonMenuItemTitle}>{item.label}</span>
+ <span className={styles.AutoFillPopupMenuItemTitle}>{localeService.t(item.label)}</span>
</li>
))}
</ul>
@@ -150,9 +144,13 @@ export const SmartButton: React.FC<{}> = () => {
visible={visible}
onVisibleChange={onVisibleChange}
>
- <Button size="small">
- <Paste style={{ color: 'green' }}></Paste>
- </Button>
+ <div className={styles.btnContainer}>
+ <Autofill
+ style={{ color: '#35322B', marginRight: '8px' }}
+ extend={{ colorChannel1: 'rgb(var(--green-700, #409f11))' }}
+ ></Autofill>
+ <MoreDownSingle style={{ color: '#CCCCCC', fontSize: '8px' }}></MoreDownSingle>
+ </div>
</Dropdown>
</div>
);
diff --git a/packages/ui-plugin-sheets/src/views/operate-container/OperateContainer.tsx b/packages/ui-plugin-sheets/src/views/operate-container/OperateContainer.tsx
index a9e4eb37d2..f112acbe99 100644
--- a/packages/ui-plugin-sheets/src/views/operate-container/OperateContainer.tsx
+++ b/packages/ui-plugin-sheets/src/views/operate-container/OperateContainer.tsx
@@ -1,8 +1,8 @@
+import { AutoFillPopupMenu } from './AutoFillPopupMenu';
import styles from './index.module.less';
-import { SmartButton } from './SmartButton';
export const OperateContainer: React.FC = () => (
<div className={styles.operateContainer}>
- <SmartButton></SmartButton>
+ <AutoFillPopupMenu></AutoFillPopupMenu>
</div>
);
diff --git a/packages/ui-plugin-sheets/src/views/operate-container/index.module.less b/packages/ui-plugin-sheets/src/views/operate-container/index.module.less
index 7cea341c5c..08a67039bd 100644
--- a/packages/ui-plugin-sheets/src/views/operate-container/index.module.less
+++ b/packages/ui-plugin-sheets/src/views/operate-container/index.module.less
@@ -18,6 +18,8 @@
box-sizing: border-box;
min-width: @smart-button-menu-min-width;
+ margin-top: 0;
+ margin-bottom: 0;
padding: var(--padding-sm);
font-size: var(--font-size-base);
@@ -36,12 +38,22 @@
position: relative;
+ display: flex;
+ align-items: center;
+
box-sizing: border-box;
+ width: 134px;
+ height: 28px;
padding: var(--padding-xs) 0 var(--padding-xs) @item-padding-left;
- color: rgb(var(--text-color));
+ font-size: 13px;
+ font-weight: 400;
+ font-style: normal;
+ line-height: 20px; /* 153.846% */
+ color: rgb(var(--black, #35322B));
text-align: left;
+ border-radius: 4px;
border-radius: var(--border-radius-base);
transition: background .2s;
@@ -55,6 +67,10 @@
top: 50%;
left: var(--padding-xs);
transform: translateY(-50%);
+
+ display: flex;
+ align-items: center;
+ justify-content: center;
}
&-title {
@@ -65,5 +81,26 @@
&-hide {
color: rgb(var(--text-color-secondary));
}
+
+ &:hover {
+ background: rgb(var(--grey-100));
+ }
+ }
+}
+
+.btn-container {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ width: 56px;
+ height: 32px;
+
+ background: white;
+ border: 1px solid rgb(var(--grey-200, #E5E5E5));
+ border-radius: 4px;
+
+ &:hover {
+ background: rgb(var(--grey-100, #f5f5f5));
}
}