Skip to content

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

refactor: remove unused code and fix label translation (#7414)

白熱11b646ae996b
diff --git a/packages/core/src/bases/base-data-model.ts b/packages/core/src/bases/base-data-model.ts
index d4aadf8b9d..acebd998b0 100644
--- a/packages/core/src/bases/base-data-model.ts
+++ b/packages/core/src/bases/base-data-model.ts
@@ -15,7 +15,14 @@
*/
import type { Observable } from 'rxjs';
-import type { CellValue, IBaseCellData, IBaseSnapshot, IFieldSnapshot, IRecordSnapshot, ITableSnapshot } from './typedef';
+import type {
+ CellValue,
+ IBaseCellData,
+ IBaseSnapshot,
+ IFieldSnapshot,
+ IRecordSnapshot,
+ ITableSnapshot,
+} from './typedef';
import { BehaviorSubject } from 'rxjs';
import { UnitModel, UniverInstanceType } from '../common/unit';
import { Tools } from '../shared/tools';
diff --git a/packages/core/src/shared/sequence.ts b/packages/core/src/shared/sequence.ts
index 85797cc04f..07db4c4590 100644
--- a/packages/core/src/shared/sequence.ts
+++ b/packages/core/src/shared/sequence.ts
@@ -36,7 +36,6 @@ export function ABCToNumber(a: string) {
const orderA = 'A'.charCodeAt(0);
const orderZ = 'Z'.charCodeAt(0);
const order_a = 'a'.charCodeAt(0);
-const order_z = 'z'.charCodeAt(0);
/**
* column subscript number to letters
diff --git a/packages/data-validation/src/__tests__/data-validation.integration.spec.ts b/packages/data-validation/src/__tests__/data-validation.integration.spec.ts
index ad3b6abd61..e2638f559d 100644
--- a/packages/data-validation/src/__tests__/data-validation.integration.spec.ts
+++ b/packages/data-validation/src/__tests__/data-validation.integration.spec.ts
@@ -26,7 +26,11 @@ import {
UniverInstanceType,
} from '@univerjs/core';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { AddDataValidationMutation, RemoveDataValidationMutation, UpdateDataValidationMutation } from '../commands/mutations/data-validation.mutation';
+import {
+ AddDataValidationMutation,
+ RemoveDataValidationMutation,
+ UpdateDataValidationMutation,
+} from '../commands/mutations/data-validation.mutation';
import { DataValidationResourceController } from '../controllers/dv-resource.controller';
import { DataValidationModel } from '../models/data-validation-model';
import { UpdateRuleType } from '../types/enum/update-rule-type';
diff --git a/packages/docs-drawing-ui/src/controllers/doc-drawing-transformer-update.controller.ts b/packages/docs-drawing-ui/src/controllers/doc-drawing-transformer-update.controller.ts
index d4ae27e272..2bbf73722d 100644
--- a/packages/docs-drawing-ui/src/controllers/doc-drawing-transformer-update.controller.ts
+++ b/packages/docs-drawing-ui/src/controllers/doc-drawing-transformer-update.controller.ts
@@ -209,7 +209,6 @@ export class DocDrawingTransformerController extends Disposable {
);
const throttleMultipleDrawingUpdate = throttle(this._updateMultipleDrawingDocTransform.bind(this), 50);
- const throttleNonInlineMoveUpdate = throttle(this._nonInlineDrawingTransform.bind(this), 50);
this.disposeWithMe(
toDisposable(
@@ -234,10 +233,6 @@ export class DocDrawingTransformerController extends Disposable {
return;
}
- if (drawingCache && drawingCache.drawing.layoutType !== PositionedObjectLayoutType.INLINE) {
- // throttleNonInlineMoveUpdate(drawingCache.drawing, object, true);
- }
-
if (drawingCache && drawingCache.drawing.layoutType === PositionedObjectLayoutType.INLINE && offsetX != null && offsetY != null) {
this._updateInlineDrawingAnchor(drawingCache.drawing, offsetX, offsetY);
}
diff --git a/packages/docs-ui/src/views/paragraph-setting/Setting.tsx b/packages/docs-ui/src/views/paragraph-setting/Setting.tsx
index 949e5e65ac..6708c83e7c 100644
--- a/packages/docs-ui/src/views/paragraph-setting/Setting.tsx
+++ b/packages/docs-ui/src/views/paragraph-setting/Setting.tsx
@@ -42,28 +42,26 @@ const ALIGNMENT_OPTIONS = [
] satisfies Array<{ label: LocaleKey; value: string; icon: ReactNode }>;
const ParagraphSettingSection = (props: {
- titleKey: LocaleKey;
+ title: string;
children: ReactNode;
first?: boolean;
}) => {
- const { titleKey, children, first = false } = props;
- const localeService = useDependency(LocaleService);
+ const { title, children, first = false } = props;
return (
<section className={clsx(!first && 'univer-mt-5')}>
- <div className="univer-text-sm univer-font-medium univer-leading-5">{localeService.t(titleKey)}</div>
+ <div className="univer-text-sm univer-font-medium univer-leading-5">{title}</div>
<div className="univer-mt-3">{children}</div>
</section>
);
};
const ParagraphSettingRow = (props: {
- labelKey: LocaleKey;
+ label: string;
unit?: string;
children: ReactNode;
}) => {
- const { labelKey, unit, children } = props;
- const localeService = useDependency(LocaleService);
+ const { label, unit, children } = props;
return (
<div
@@ -76,7 +74,7 @@ const ParagraphSettingRow = (props: {
dark:!univer-text-gray-100
"
>
- {localeService.t(labelKey)}
+ {label}
{unit}
</div>
<div className="univer-w-full univer-min-w-0">
@@ -140,7 +138,7 @@ export function ParagraphSetting() {
return (
<div className="univer-box-border univer-w-full">
- <ParagraphSettingSection titleKey="docs-ui.doc.paragraphSetting.alignment" first>
+ <ParagraphSettingSection title={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.alignment')} first>
<div
className={clsx(`
univer-flex univer-grid-cols-4 univer-items-center univer-justify-around univer-gap-2
@@ -176,32 +174,32 @@ export function ParagraphSetting() {
</div>
</ParagraphSettingSection>
- <ParagraphSettingSection titleKey="docs-ui.doc.paragraphSetting.indentation">
+ <ParagraphSettingSection title={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.indentation')}>
<div className="univer-grid univer-gap-3">
- <ParagraphSettingRow labelKey="docs-ui.doc.paragraphSetting.left" unit="(px)">
+ <ParagraphSettingRow label={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.left')} unit="(px)">
<AutoFocusInputNumber value={indentStart} onChange={(v) => setIndentStart(v ?? 0)} />
</ParagraphSettingRow>
- <ParagraphSettingRow labelKey="docs-ui.doc.paragraphSetting.right" unit="(px)">
+ <ParagraphSettingRow label={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.right')} unit="(px)">
<AutoFocusInputNumber value={indentEnd} onChange={(v) => setIndentEnd(v ?? 0)} />
</ParagraphSettingRow>
- <ParagraphSettingRow labelKey="docs-ui.doc.paragraphSetting.firstLine" unit="(px)">
+ <ParagraphSettingRow label={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.firstLine')} unit="(px)">
<AutoFocusInputNumber value={indentFirstLine} onChange={(v) => setIndentFirstLine(v ?? 0)} />
</ParagraphSettingRow>
- <ParagraphSettingRow labelKey="docs-ui.doc.paragraphSetting.hanging" unit="(px)">
+ <ParagraphSettingRow label={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.hanging')} unit="(px)">
<AutoFocusInputNumber value={hanging} onChange={(v) => setHanging(v ?? 0)} />
</ParagraphSettingRow>
</div>
</ParagraphSettingSection>
- <ParagraphSettingSection titleKey="docs-ui.doc.paragraphSetting.spacing">
+ <ParagraphSettingSection title={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.spacing')}>
<div className="univer-grid univer-gap-3">
- <ParagraphSettingRow labelKey="docs-ui.doc.paragraphSetting.before" unit="(px)">
+ <ParagraphSettingRow label={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.before')} unit="(px)">
<AutoFocusInputNumber value={spaceAbove} onChange={(v) => setSpaceAbove(v ?? 0)} />
</ParagraphSettingRow>
- <ParagraphSettingRow labelKey="docs-ui.doc.paragraphSetting.after" unit="(px)">
+ <ParagraphSettingRow label={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.after')} unit="(px)">
<AutoFocusInputNumber value={spaceBelow} onChange={(v) => setSpaceBelow(v ?? 0)} />
</ParagraphSettingRow>
- <ParagraphSettingRow labelKey="docs-ui.doc.paragraphSetting.lineSpace">
+ <ParagraphSettingRow label={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.lineSpace')}>
<div className="univer-flex univer-w-full univer-flex-col univer-gap-2">
<Select
className="univer-w-full"
diff --git a/packages/drawing-ui/src/views/image-popup-menu/ImagePopupMenu.tsx b/packages/drawing-ui/src/views/image-popup-menu/ImagePopupMenu.tsx
index c889496cb4..4e07504b58 100644
--- a/packages/drawing-ui/src/views/image-popup-menu/ImagePopupMenu.tsx
+++ b/packages/drawing-ui/src/views/image-popup-menu/ImagePopupMenu.tsx
@@ -204,11 +204,15 @@ function ToolbarGroup(props: { children: ReactNode }) {
);
}
-function ToolbarButton(props: { titleKey: string; active?: boolean; disabled?: boolean; children: ReactNode; onClick: () => void }) {
- const localeService = useDependency(LocaleService);
-
+function ToolbarButton(props: {
+ title: string;
+ active?: boolean;
+ disabled?: boolean;
+ children: ReactNode;
+ onClick: () => void;
+}) {
return (
- <Tooltip title={localeService.t(props.titleKey as LocaleKey)} placement="bottom">
+ <Tooltip title={props.title} placement="bottom">
<button
type="button"
disabled={props.disabled}
@@ -395,7 +399,7 @@ function DocImageFloatingToolbar(props: IDocImageFloatingToolbarProps) {
return (
<ToolbarButton
key={`${item.commandId}-${item.index}`}
- titleKey={item.label}
+ title={localeService.t(item.label as LocaleKey)}
disabled={item.disable}
onClick={() => executeMenuItem(item)}
>
@@ -476,7 +480,7 @@ function DocChartFloatingToolbar(props: Pick<IDocImageFloatingToolbarProps, 'men
return (
<ToolbarButton
key={`${item.commandId}-${item.index}`}
- titleKey={item.label}
+ title={localeService.t(item.label as LocaleKey)}
disabled={item.disable}
onClick={() => executeMenuItem(item)}
>
diff --git a/packages/engine-formula/src/controllers/calculate.controller.ts b/packages/engine-formula/src/controllers/calculate.controller.ts
index ac63fc0c60..c26fc7f3f3 100644
--- a/packages/engine-formula/src/controllers/calculate.controller.ts
+++ b/packages/engine-formula/src/controllers/calculate.controller.ts
@@ -104,10 +104,21 @@ export class CalculateController extends Disposable {
);
}
- private async _calculate(
- formulaDirtyData: Partial<IFormulaDirtyData>
- ) {
- const { forceCalculation: forceCalculate = false, dirtyRanges = [], dirtyNameMap = {}, dirtyDefinedNameMap = {}, dirtySuperTableMap = {}, dirtyUnitFeatureMap = {}, dirtyUnitOtherFormulaMap = {}, clearDependencyTreeCache = {}, maxIteration = DEFAULT_CYCLE_REFERENCE_COUNT, rowData, externalReferences, isCalculateTreeModel = false } = formulaDirtyData;
+ private async _calculate(formulaDirtyData: Partial<IFormulaDirtyData>) {
+ const {
+ forceCalculation: forceCalculate = false,
+ dirtyRanges = [],
+ dirtyNameMap = {},
+ dirtyDefinedNameMap = {},
+ dirtySuperTableMap = {},
+ dirtyUnitFeatureMap = {},
+ dirtyUnitOtherFormulaMap = {},
+ clearDependencyTreeCache = {},
+ maxIteration = DEFAULT_CYCLE_REFERENCE_COUNT,
+ rowData,
+ externalReferences,
+ isCalculateTreeModel = false,
+ } = formulaDirtyData;
const formulaData = this._formulaDataModel.getFormulaData();
const arrayFormulaCellData = this._formulaDataModel.getArrayFormulaCellData();
@@ -276,7 +287,15 @@ export class CalculateController extends Disposable {
}
private async _applyResult(data: IAllRuntimeData) {
- const { unitData, unitOtherData, arrayFormulaRange, arrayFormulaCellData, clearArrayFormulaCellData, arrayFormulaEmbedded, imageFormulaData, dependencyTreeModelData } = data;
+ const {
+ unitData,
+ unitOtherData,
+ arrayFormulaRange,
+ arrayFormulaCellData,
+ clearArrayFormulaCellData,
+ arrayFormulaEmbedded,
+ imageFormulaData,
+ } = data;
if (!unitData) {
this._applyTreeResult(data);
diff --git a/packages/engine-render/src/basics/drawing-effect.ts b/packages/engine-render/src/basics/drawing-effect.ts
index c42145647e..e4c8b09d88 100644
--- a/packages/engine-render/src/basics/drawing-effect.ts
+++ b/packages/engine-render/src/basics/drawing-effect.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
+import type { IGlowEffect, IShadowEffect } from '@univerjs/core';
import type { IBoundRectNoAngle } from './vector2';
-// eslint-disable-next-line import/consistent-type-specifier-style -- Keep type and value imports from one package together.
-import { ColorKit, type IGlowEffect, type IShadowEffect } from '@univerjs/core';
+import { ColorKit } from '@univerjs/core';
// Canvas blur visually spans about twice the DrawingML glow radius. This factor is verified against PowerPoint output.
const DRAWINGML_GLOW_BLUR_SCALE = 0.5;
diff --git a/packages/engine-render/src/basics/unit-convert.ts b/packages/engine-render/src/basics/unit-convert.ts
deleted file mode 100644
index 82196f3d44..0000000000
--- a/packages/engine-render/src/basics/unit-convert.ts
+++ /dev/null
@@ -1,44 +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.
- */
-
-const whiteListKeyForPt = new Set(['', '']);
-
-function isNotEmpty(value: unknown) {
- if (value === null && value === undefined) {
- return false;
- }
- return true;
-}
-
-// export function convertPtToPxBatch(value: IDocumentData, key?: string, parent?: any) {
-// if (Tools.isObject(value) || Tools.isArray(value)) {
-// for (let subKey of Object.keys(value)) {
-// convertPtToPxBatch(value[subKey], subKey, value);
-// }
-// } else if (key && whiteListKeyForPt.has(key) && isNotEmpty(value)) {
-// parent[key] = ptToPx(value);
-// }
-// }
-
-// export function convertPxToPtBatch(value: IDocumentData, key?: string, parent?: any) {
-// if (Tools.isObject(value) || Tools.isArray(value)) {
-// for (let subKey of Object.keys(value)) {
-// convertPtToPxBatch(value[subKey], subKey, value);
-// }
-// } else if (key && whiteListKeyForPt.has(key) && isNotEmpty(value)) {
-// parent[key] = pxToPt(value);
-// }
-// }
diff --git a/packages/engine-render/src/shape/scroll-bar.ts b/packages/engine-render/src/shape/scroll-bar.ts
index 178eba6889..163b1313a0 100644
--- a/packages/engine-render/src/shape/scroll-bar.ts
+++ b/packages/engine-render/src/shape/scroll-bar.ts
@@ -60,7 +60,6 @@ export interface IScrollBarProps {
const MIN_THUMB_SIZE = 17;
const DEFAULT_TRACK_SIZE = 10;
const DEFAULT_TRACK_BORDER_SIZE = 1;
-const HOVER_TRACK_SIZE = 10;
const DEFAULT_THUMB_MARGIN = 2;
const HOVER_THUMB_MARGIN = 1;
const BAR_DRAG_SCROLL_THROTTLE_MS = 32;
@@ -770,7 +769,6 @@ export class ScrollBar extends Disposable {
}
private _horizonHoverFunc(color: string, evt: unknown, state: EventState) {
- // this._trackThickness = HOVER_TRACK_SIZE;
this._hThumbMargin = HOVER_THUMB_MARGIN;
this._resizeHorizontal();
this._resizeRightBottomCorner();
@@ -804,7 +802,6 @@ export class ScrollBar extends Disposable {
thumb.setProps({
fill: color,
});
- // this._trackThickness = HOVER_TRACK_SIZE;
this._resizeHorizontal();
this.makeViewDirty(true);
};
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 7a9bf8421a..6af0329449 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
@@ -28,16 +28,11 @@ import { useEditorPosition } from '../hooks/use-editor-position';
import { useFormulaDescribe } from '../hooks/use-formula-describe';
import { HelpHiddenTip } from './HelpHiddenTip';
-interface IParamsProps {
+function Params({ className, title, value }: {
className?: string;
- title?: string;
- titleKey?: LocaleKey;
+ title: string;
value?: string;
-}
-
-const Params = ({ className, title, titleKey, value }: IParamsProps) => {
- const localeService = useDependency(LocaleService);
-
+}) {
return (
<div className="univer-my-2">
<div
@@ -46,7 +41,7 @@ const Params = ({ className, title, titleKey, value }: IParamsProps) => {
dark:!univer-text-white
`, className)}
>
- {titleKey ? localeService.t(titleKey) : title}
+ {title}
</div>
<div
className="univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500"
@@ -55,17 +50,16 @@ const Params = ({ className, title, titleKey, value }: IParamsProps) => {
</div>
</div>
);
-};
+}
-interface IHelpProps {
+function Help(props: {
prefix?: string;
value?: IFunctionParam[];
active: number;
onClick: (paramIndex: number) => void;
-}
-
-const Help = (props: IHelpProps) => {
+}) {
const { prefix, value, active, onClick } = props;
+
return (
<div>
<span>
@@ -87,17 +81,15 @@ const Help = (props: IHelpProps) => {
)
</div>
);
-};
+}
-interface IHelpFunctionProps {
+export function HelpFunction(props: {
onParamsSwitch?: (index: number) => void;
onClose?: () => void;
editor: Editor;
isFocus: boolean;
formulaText: string;
-};
-
-export function HelpFunction(props: IHelpFunctionProps) {
+}) {
const { onParamsSwitch = noop, onClose: propColose = noop, isFocus, editor, formulaText } = props;
const { functionInfo, paramIndex, reset } = useFormulaDescribe(isFocus, formulaText, editor);
const editorBridgeService = useDependency(IEditorBridgeService);
@@ -194,13 +186,13 @@ export function HelpFunction(props: IHelpFunctionProps) {
>
<div className="univer-mt-3">
<Params
- titleKey="sheets-formula-ui.prompt.helpExample"
+ title={localeService.t<LocaleKey>('sheets-formula-ui.prompt.helpExample')}
value={`${functionInfo.functionName}(${functionInfo.functionParameter
.map((item) => item.example)
.join(',')})`}
/>
<Params
- titleKey="sheets-formula-ui.prompt.helpAbstract"
+ title={localeService.t<LocaleKey>('sheets-formula-ui.prompt.helpAbstract')}
value={functionInfo.description}
/>
{functionInfo &&
diff --git a/packages/ui/src/utils/cell.ts b/packages/ui/src/utils/cell.ts
index 2fc4776d05..24540ef28a 100644
--- a/packages/ui/src/utils/cell.ts
+++ b/packages/ui/src/utils/cell.ts
@@ -923,12 +923,6 @@ function getStyles(styleText: string): Record<string, any> {
return output;
}
-function extractColorFromString(str: string) {
- const regex = /#([0-9a-f]{3,6})\b|rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)/gi;
- const matches = str.match(regex);
- return matches ? matches[0] : null;
-}
-
function getPtFontSizeByPx(size: number) {
const ptSize = Math.round(size * PX_TO_PT_RATIO);
diff --git a/packages/ui/src/views/components/sidebar/Sidebar.tsx b/packages/ui/src/views/components/sidebar/Sidebar.tsx
index 8d73ce351e..376db0b7f2 100644
--- a/packages/ui/src/views/components/sidebar/Sidebar.tsx
+++ b/packages/ui/src/views/components/sidebar/Sidebar.tsx
@@ -41,7 +41,6 @@ export interface ISidebarMethodOptions {
const MIN_SIDEBAR_WIDTH = 280;
const MAX_SIDEBAR_WIDTH = 800;
-const DEFAULT_SIDEBAR_WIDTH = 384;
export function Sidebar() {
const localeService = useDependency(LocaleService);
diff --git a/packages/ui/src/views/emoji-picker/EmojiPicker.tsx b/packages/ui/src/views/emoji-picker/EmojiPicker.tsx
index 500f809e62..9e54f422d1 100644
--- a/packages/ui/src/views/emoji-picker/EmojiPicker.tsx
+++ b/packages/ui/src/views/emoji-picker/EmojiPicker.tsx
@@ -239,7 +239,7 @@ export function EmojiPicker(props: IEmojiPickerProps) {
>
<CategoryButton
selected={!isSearching && activeTab === 'recent'}
- titleKey="ui.emojiPicker.recents"
+ title={localeService.t<LocaleKey>('ui.emojiPicker.recents')}
onClick={() => scrollToSection('recent')}
>
<RecentIcon />
@@ -248,7 +248,7 @@ export function EmojiPicker(props: IEmojiPickerProps) {
<CategoryButton
key={category.key}
selected={!isSearching && activeTab === category.key}
- titleKey={category.titleKey}
+ title={localeService.t(category.titleKey)}
onClick={() => scrollToSection(category.key)}
>
<CategoryIcon category={category.key} />
@@ -332,15 +332,13 @@ function EmojiGrid(props: {
);
}
-function CategoryButton(props: { children: ReactElement; onClick: () => void; selected: boolean; titleKey: LocaleKey }) {
- const localeService = useDependency(LocaleService);
-
+function CategoryButton(props: { children: ReactElement; onClick: () => void; selected: boolean; title: string }) {
return (
<button
type="button"
- aria-label={localeService.t(props.titleKey)}
+ aria-label={props.title}
aria-selected={props.selected}
- title={localeService.t(props.titleKey)}
+ title={props.title}
className={clsx(
`
univer-flex univer-h-[30px] univer-flex-1 univer-cursor-pointer univer-items-center