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.

fix(docs-ui): auto-focus newly created documents (#7283)

白熱c154161a95f7
diff --git a/packages/core/src/docs/data-model/document-data-model.ts b/packages/core/src/docs/data-model/document-data-model.ts
index 44853ced55..d5e0d9298a 100644
--- a/packages/core/src/docs/data-model/document-data-model.ts
+++ b/packages/core/src/docs/data-model/document-data-model.ts
@@ -18,9 +18,9 @@ import type { Nullable } from '../../shared';
import type { IDocumentBody, IDocumentData, IDocumentRenderConfig, IDocumentStyle, IDrawings, IListData } from '../../types/interfaces/i-document-data';
import type { IPaddingData } from '../../types/interfaces/i-style-data';
import type { JSONXActions } from './json-x/json-x';
-import { mergeWith } from 'lodash-es';
import { BehaviorSubject } from 'rxjs';
import { isInternalEditorID } from '../../common/const';
+import { mergeWith } from '../../common/lodash';
import { UnitModel, UniverInstanceType } from '../../common/unit';
import { generateRandomId } from '../../shared/random-id';
import { Tools } from '../../shared/tools';
diff --git a/packages/docs-ui/src/plugin.ts b/packages/docs-ui/src/plugin.ts
index 673b6eb2cb..784697793f 100644
--- a/packages/docs-ui/src/plugin.ts
+++ b/packages/docs-ui/src/plugin.ts
@@ -14,13 +14,12 @@
* limitations under the License.
*/
-import type { Dependency } from '@univerjs/core';
+import type { Dependency, DocumentDataModel } from '@univerjs/core';
import type { IUniverDocsUIConfig } from './config/config';
import {
DependentOn,
ICommandService,
IConfigService,
- ILogService,
Inject,
Injector,
IUniverInstanceService,
@@ -178,7 +177,6 @@ export class UniverDocsUIPlugin extends Plugin {
@Inject(Injector) override _injector: Injector,
@IRenderManagerService private readonly _renderManagerSrv: IRenderManagerService,
@ICommandService private _commandService: ICommandService,
- @ILogService private _logService: ILogService,
@IConfigService private readonly _configService: IConfigService
) {
super();
@@ -201,7 +199,7 @@ export class UniverDocsUIPlugin extends Plugin {
override onReady(): void {
this._initRenderBasics();
- this._markDocAsFocused();
+ this._initAutoFocus();
touchDependencies(this._injector, [
[DocsRenderService],
@@ -392,25 +390,19 @@ export class UniverDocsUIPlugin extends Plugin {
dependencies.forEach((d) => injector.add(d));
}
- private _markDocAsFocused() {
+ private _initAutoFocus() {
const currentService = this._injector.get(IUniverInstanceService);
const editorService = this._injector.get(IEditorService);
- try {
- const doc = currentService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
- if (!doc) return;
-
- const id = doc.getUnitId();
- const createOptions = currentService.getUnitCreateOptions(id);
- if (createOptions?.makeCurrent === false) {
+ this.disposeWithMe(currentService.getCurrentTypeOfUnit$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC).subscribe((doc) => {
+ if (!doc) {
return;
}
+ const id = doc.getUnitId();
if (!editorService.isEditor(id)) {
- currentService.focusUnit(doc.getUnitId());
+ currentService.focusUnit(id);
}
- } catch (err) {
- this._logService.warn(err);
- }
+ }));
}
private _initRenderBasics(): void {
diff --git a/packages/engine-formula/src/engine/analysis/lexer-node.ts b/packages/engine-formula/src/engine/analysis/lexer-node.ts
index e7f219fd0c..48eebc69fa 100644
--- a/packages/engine-formula/src/engine/analysis/lexer-node.ts
+++ b/packages/engine-formula/src/engine/analysis/lexer-node.ts
@@ -19,9 +19,9 @@ import type { Nullable } from '@univerjs/core';
import type { LambdaPrivacyVarType } from '../ast-node/base-ast-node';
import { DEFAULT_TOKEN_TYPE_ROOT } from '../../basics/token-type';
-interface LexerNodeJson {
+interface ILexerNodeJson {
token: string;
- children: Array<LexerNodeJson | string>;
+ children: Array<ILexerNodeJson | string>;
}
export class LexerNode {
@@ -173,7 +173,7 @@ export class LexerNode {
const token = this.getToken();
const children = this.getChildren();
- const childrenSerialization: Array<LexerNodeJson | string> = [];
+ const childrenSerialization: Array<ILexerNodeJson | string> = [];
const childrenCount = children.length;
for (let i = 0; i < childrenCount; i++) {
const item = children[i];
diff --git a/packages/engine-formula/src/functions/logical/groupby/index.ts b/packages/engine-formula/src/functions/logical/groupby/index.ts
index c59057b07e..1fa5272a49 100644
--- a/packages/engine-formula/src/functions/logical/groupby/index.ts
+++ b/packages/engine-formula/src/functions/logical/groupby/index.ts
@@ -26,13 +26,13 @@ import { FUNCTION_NAMES_LOGICAL } from '../function-names';
type GroupByAggregatorName = 'SUM' | 'COUNT' | 'COUNTA' | 'PERCENTOF' | 'MIN' | 'MAX' | 'ARRAYTOTEXT';
-interface ArrayInput {
+interface IArrayInput {
rowCount: number;
columnCount: number;
valueAt: (row: number, column: number) => BaseValueObject;
}
-interface GroupByGroup {
+interface IGroupByGroup {
key: BaseValueObject[];
values: BaseValueObject[][];
}
@@ -80,7 +80,7 @@ export class Groupby extends BaseFunction {
const groupColumnCount = rowFields.columnCount;
const valueColumnCount = values.columnCount;
const outputValueColumnCount = this._outputValueColumnCount(valueColumnCount, aggregators.length);
- const groups: GroupByGroup[] = [];
+ const groups: IGroupByGroup[] = [];
const allValues = Array.from({ length: valueColumnCount }, () => [] as BaseValueObject[]);
for (let row = 0; row < rowFields.rowCount; row++) {
@@ -161,7 +161,7 @@ export class Groupby extends BaseFunction {
});
}
- private _arrayInput(variant: FunctionVariantType | null): ArrayInput | ErrorValueObject {
+ private _arrayInput(variant: FunctionVariantType | null): IArrayInput | ErrorValueObject {
if (variant == null) {
return ErrorValueObject.create(ErrorType.VALUE);
}
@@ -332,7 +332,7 @@ export class Groupby extends BaseFunction {
return `${typeof value.getValue()}:${String(value.getValue())}`;
}
- private _sortGroups(groups: GroupByGroup[], sortColumn?: number): void {
+ private _sortGroups(groups: IGroupByGroup[], sortColumn?: number): void {
const descending = sortColumn != null && sortColumn < 0;
const sortIndex = sortColumn == null ? undefined : Math.abs(sortColumn) - 1;
groups.sort((left, right) => {
diff --git a/packages/engine-render/src/basics/path2.ts b/packages/engine-render/src/basics/path2.ts
index 0196f5580a..1b809b9451 100644
--- a/packages/engine-render/src/basics/path2.ts
+++ b/packages/engine-render/src/basics/path2.ts
@@ -19,7 +19,7 @@ import { Vector2 } from './vector2';
export const INITIAL_Path2: Vector2[] = [new Vector2(0, 0), new Vector2(1, 1)];
-interface Line {
+interface ILine {
from: Vector2;
to: Vector2;
}
@@ -63,7 +63,7 @@ export class Path2 {
return crossPoint;
}
- private _intersection(line1: Line, line2: Line): Vector2 | false {
+ private _intersection(line1: ILine, line2: ILine): Vector2 | false {
const a = line1.from;
const b = line1.to;
const c = line2.from;
diff --git a/packages/network/src/services/http/interceptors/__tests__/merge-interceptor.spec.ts b/packages/network/src/services/http/interceptors/__tests__/merge-interceptor.spec.ts
index 9e36cc3cdf..faa7d8b183 100644
--- a/packages/network/src/services/http/interceptors/__tests__/merge-interceptor.spec.ts
+++ b/packages/network/src/services/http/interceptors/__tests__/merge-interceptor.spec.ts
@@ -57,12 +57,12 @@ describe('test "HTTPMergeInterceptor"', () => {
it('two requests were created, but only one was a real request', async () => {
const path = 'http://example.com';
- interface Request { ids: string[] };
- interface Response { list: number[] };
- const response: Response = { list: [1, 2] };
+ interface IRequest { ids: string[] };
+ interface IResponse { list: number[] };
+ const response: IResponse = { list: [1, 2] };
httpService.registerHTTPInterceptor({
priority: 999,
- interceptor: MergeInterceptorFactory<Request, Response>({
+ interceptor: MergeInterceptorFactory<IRequest, IResponse>({
isMatch(config) {
return config.url === path;
},
@@ -86,8 +86,8 @@ describe('test "HTTPMergeInterceptor"', () => {
}),
});
- const request1 = httpService.post<Response>(path, { body: { ids: [1] } });
- const request2 = httpService.post<Response>(path, { body: { ids: [2] } });
+ const request1 = httpService.post<IResponse>(path, { body: { ids: [1] } });
+ const request2 = httpService.post<IResponse>(path, { body: { ids: [2] } });
request1.then((e) => {
expect(e.body.list).toEqual(response.list);
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx
index 634850d9a9..8bec7ff626 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx
@@ -357,7 +357,7 @@ const IconSetRuleEdit = (props: {
>
{icon
? <img src={icon} className="univer-size-4" draggable={false} />
- : <SlashDoubleIcon className="univer-size-4" />}
+ : <SlashDoubleIcon />}
<MoreDownIcon />
</div>
</Dropdown>
diff --git a/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx b/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx
index 2e1493a7d8..55aa587443 100644
--- a/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx
+++ b/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx
@@ -1387,7 +1387,7 @@ function ContextMenuMenuItem(props: IContextMenuMenuItemProps) {
<div
ref={submenuElementRef}
dir={direction}
- {...{ [CONTEXT_MENU_SUBMENU_PORTAL_ATTR]: 'true' }}
+ data-u-context-menu-submenu="true"
className="univer-z-[1080] univer-w-max univer-max-w-[calc(100vw-16px)]"
style={{
position: 'fixed',