mirror of
https://github.com/dream-num/univer.git
synced 2026-09-19 10:29:12 +08:00
fix(docs-ui): auto-focus newly created documents (#7283)
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user