Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docs-ui): link & checklist can't work on header-footer #3107

Merged
merged 48 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
8d06bb2
feat: support event manager service
weird94 Aug 16, 2024
b7d054d
feat: update click
weird94 Aug 16, 2024
5c53a1e
feat: update
weird94 Aug 16, 2024
a6c46d6
feat: update
weird94 Aug 16, 2024
e5d7e5d
feat: temp
weird94 Aug 17, 2024
f9528c5
feat: update
weird94 Aug 17, 2024
e4ba0b2
Merge remote-tracking branch 'origin/dev' into feat/doc-hover
weird94 Aug 17, 2024
35fc4ae
feat: update
weird94 Aug 17, 2024
ea68962
feat: update
weird94 Aug 17, 2024
159b3d6
feat: update
weird94 Aug 17, 2024
2024262
feat: update
weird94 Aug 17, 2024
4265569
feat: update
weird94 Aug 17, 2024
e703592
feat: update
weird94 Aug 19, 2024
de51171
fix: code review
weird94 Aug 19, 2024
2770b93
fix: code review
weird94 Aug 19, 2024
929ca3f
feat: update
weird94 Aug 19, 2024
b3afd6b
Merge branch 'dev' into feat/doc-hover
weird94 Aug 19, 2024
ce5f50f
feat: update
weird94 Aug 19, 2024
1d00f7e
Merge branch 'feat/doc-hover' of github.com:dream-num/univer into fea…
weird94 Aug 19, 2024
4128807
feat: update
weird94 Aug 19, 2024
1be529f
feat: update
weird94 Aug 19, 2024
04217af
feat: update
weird94 Aug 19, 2024
3c0fc2a
feat: update
weird94 Aug 19, 2024
12eb445
feat: update
weird94 Aug 19, 2024
8624c37
feat: update
weird94 Aug 19, 2024
651be68
feat: updtae
weird94 Aug 19, 2024
8f994d0
feat: i18n
weird94 Aug 19, 2024
591a163
Merge branch 'dev' into feat/doc-hover
weird94 Aug 19, 2024
494264b
feat: update
weird94 Aug 19, 2024
a4ff395
Merge branch 'feat/doc-hover' of github.com:dream-num/univer into fea…
weird94 Aug 19, 2024
fe02662
feat: update
weird94 Aug 19, 2024
14c1718
feat: update
weird94 Aug 19, 2024
a83ca4d
feat: lint
weird94 Aug 19, 2024
a4fd33b
feat: update
weird94 Aug 19, 2024
40287be
feat: update
weird94 Aug 20, 2024
1015142
feat: update
weird94 Aug 20, 2024
d790090
fix: table checklist
weird94 Aug 20, 2024
1ad1628
feat: update
weird94 Aug 20, 2024
907d353
feat: update
weird94 Aug 20, 2024
ec0c688
feat: update
weird94 Aug 20, 2024
a73ed30
feat: update
weird94 Aug 20, 2024
4e565e8
fix: delete link on header
weird94 Aug 21, 2024
5b7cbaf
fix: editor
weird94 Aug 21, 2024
29604bc
feat: footer header not equal
weird94 Aug 21, 2024
2599e4f
feat: update
weird94 Aug 21, 2024
ea05586
feat: update
weird94 Aug 21, 2024
73e370c
feat: update
weird94 Aug 21, 2024
47c7a49
feat: update
weird94 Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CustomRangeType, Disposable, ICommandService, ILogService, Inject, IUni
import type { IInsertCommandParams } from '@univerjs/docs';
import { DeleteLeftCommand, InsertCommand, MoveCursorOperation, TextSelectionManagerService } from '@univerjs/docs';
import { IEditorService } from '@univerjs/ui';
import { DocHoverManagerService } from '@univerjs/docs-ui';
import { DocEventManagerService } from '@univerjs/docs-ui';

import { AddDocUniFormulaCommand, RemoveDocUniFormulaCommand, UpdateDocUniFormulaCommand } from '../commands/commands/doc.command';
import type { IShowFormulaPopupOperationParams } from '../commands/operations/operation';
Expand All @@ -35,7 +35,7 @@ export class DocUniFormulaInputController extends Disposable {
@IUniverInstanceService private readonly _instanceSrv: IUniverInstanceService,
@IEditorService private readonly _editorService: IEditorService,
@ILogService private readonly _logService: ILogService,
@Inject(DocHoverManagerService) private readonly _docHoverManagerSrv: DocHoverManagerService,
@Inject(DocEventManagerService) private readonly _docEventManagerService: DocEventManagerService,
@Inject(UniFormulaPopupService) private readonly _formulaPopupSrv: UniFormulaPopupService,
@Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService
) {
Expand Down Expand Up @@ -91,7 +91,7 @@ export class DocUniFormulaInputController extends Disposable {
}

private _initHoverListener(): void {
this.disposeWithMe(this._docHoverManagerSrv.activeCustomRanges$.subscribe((customRanges) => {
this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((customRanges) => {
const focusedUnit = this._instanceSrv.getFocusedUnit();

if (
Expand All @@ -102,7 +102,7 @@ export class DocUniFormulaInputController extends Disposable {
return;
}

const formulaCustomRange = customRanges.find((range) => range.rangeType === CustomRangeType.UNI_FORMULA);
const formulaCustomRange = customRanges.find((range) => range.range.rangeType === CustomRangeType.UNI_FORMULA)?.range;
if (formulaCustomRange) {
const { startIndex, rangeId } = formulaCustomRange;
this._logService.debug('[DocUniFormulaController]: activeCustomRanges', customRanges);
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/docs/data-model/document-data-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,15 @@ export class DocumentDataModel extends DocumentDataModelSimple {
for (const headerId in headers) {
const header = headers[headerId];
this.headerModelMap.set(headerId, new DocumentDataModel(header));
this.headerModelMap.get(headerId)!.updateDocumentId(this.getUnitId());
}
}

if (footers) {
for (const footerId in footers) {
const footer = footers[footerId];
this.footerModelMap.set(footerId, new DocumentDataModel(footer));
this.footerModelMap.get(footerId)!.updateDocumentId(this.getUnitId());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { DocHyperLinkModel } from '@univerjs/docs-hyper-link';
export interface IDeleteDocHyperLinkMutationParams {
unitId: string;
linkId: string;
segmentId?: string;
}

export const DeleteDocHyperLinkCommand: ICommand<IDeleteDocHyperLinkMutationParams> = {
Expand All @@ -31,15 +32,15 @@ export const DeleteDocHyperLinkCommand: ICommand<IDeleteDocHyperLinkMutationPara
if (!params) {
return false;
}
const { unitId, linkId } = params;
const { unitId, linkId, segmentId } = params;
const commandService = accessor.get(ICommandService);
const hyperLinkModel = accessor.get(DocHyperLinkModel);
const link = hyperLinkModel.getLink(unitId, linkId);
if (!link) {
return false;
}

const doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: linkId });
const doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: linkId, segmentId });
if (!doMutation) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
* limitations under the License.
*/

import { CommandType, type ICommand, ICommandService } from '@univerjs/core';
import { UpdateDocHyperLinkMutation } from '@univerjs/docs-hyper-link';
import { CommandType, CustomRangeType, DataStreamTreeTokenType, generateRandomId, type ICommand, ICommandService, sequenceExecute } from '@univerjs/core';
import { replaceSelectionFactory, TextSelectionManagerService } from '@univerjs/docs';
import type { IAddDocHyperLinkMutationParams } from '@univerjs/docs-hyper-link';
import { AddDocHyperLinkMutation } from '@univerjs/docs-hyper-link';

export interface IUpdateDocHyperLinkCommandParams {
unitId: string;
linkId: string;
payload: string;
label: string;
segmentId: string;
}

export const UpdateDocHyperLinkCommand: ICommand<IUpdateDocHyperLinkCommandParams> = {
Expand All @@ -30,8 +34,54 @@ export const UpdateDocHyperLinkCommand: ICommand<IUpdateDocHyperLinkCommandParam
if (!params) {
return false;
}

const { unitId, payload, segmentId } = params;
const commandService = accessor.get(ICommandService);
return commandService.syncExecuteCommand(UpdateDocHyperLinkMutation.id, params);
const selectionService = accessor.get(TextSelectionManagerService);
const currentSelection = selectionService.getActiveTextRange();
if (!currentSelection) {
return false;
}

const newId = generateRandomId();
const replaceSelection = replaceSelectionFactory(accessor, {
unitId: params.unitId,
body: {
dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${params.label}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
customRanges: [{
rangeId: newId,
rangeType: CustomRangeType.HYPERLINK,
startIndex: 0,
endIndex: params.label.length + 1,
}],
},
selection: {
startOffset: currentSelection.startOffset!,
endOffset: currentSelection.endOffset!,
collapsed: false,
segmentId,
},
});

if (!replaceSelection) {
return false;
}

// doc don't support undo now
// so use an new id to replace the old link
// in case of undo or redo
const addLinkMutation = {
id: AddDocHyperLinkMutation.id,
params: {
unitId,
link: {
id: newId,
payload,
},
} as IAddDocHyperLinkMutationParams,
};

const result = sequenceExecute([addLinkMutation, replaceSelection], commandService);

return result.result;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,17 @@
* limitations under the License.
*/

import type { DocumentDataModel, IAccessor, ICommand } from '@univerjs/core';
import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSkeletonManagerService, serializeDocRange, TextSelectionManagerService } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';
import type { DocumentDataModel, IAccessor, ICommand, ITextRange } from '@univerjs/core';
import { CommandType, CustomRangeType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { getCustomRangesInterestsWithRange, TextSelectionManagerService } from '@univerjs/docs';
import { DocHyperLinkModel } from '@univerjs/docs-hyper-link';
import { DocHyperLinkPopupService } from '../../services/hyper-link-popup.service';

export const shouldDisableAddLink = (accessor: IAccessor) => {
const textSelectionService = accessor.get(TextSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const textRanges = textSelectionService.getCurrentTextRanges()?.map(serializeDocRange);
const renderManagerService = accessor.get(IRenderManagerService);
const render = renderManagerService.getCurrent();
const skeleton = render?.with(DocSkeletonManagerService).getSkeleton();
const editArea = skeleton?.getViewModel().getEditArea();
if (editArea === DocumentEditArea.FOOTER || editArea === DocumentEditArea.HEADER) {
return true;
}
if (!textRanges || textRanges.length > 1) {
const textRanges = textSelectionService.getDocRanges();
if (!textRanges.length || textRanges.length > 1) {
return true;
}

Expand All @@ -41,14 +34,15 @@ export const shouldDisableAddLink = (accessor: IAccessor) => {
return true;
}

const paragraphs = doc.getBody()?.paragraphs;
const body = doc.getSelfOrHeaderFooterModel(activeRange.segmentId).getBody();
const paragraphs = body?.paragraphs;
if (!paragraphs) {
return true;
}

for (let i = 0, len = paragraphs.length; i < len; i++) {
const p = paragraphs[i];
if (activeRange.startOffset <= p.startIndex && activeRange.endOffset > p.startIndex) {
if (activeRange.startOffset! <= p.startIndex && activeRange.endOffset! > p.startIndex) {
return true;
}

Expand All @@ -57,20 +51,23 @@ export const shouldDisableAddLink = (accessor: IAccessor) => {
}
}

return false;
const insertCustomRanges = getCustomRangesInterestsWithRange(activeRange as ITextRange, body.customRanges ?? []);
// can't insert hyperlink in range contains other custom ranges
return !insertCustomRanges.every((range) => range.rangeType === CustomRangeType.HYPERLINK);
};

export interface IShowDocHyperLinkEditPopupOperationParams {
link?: {
unitId: string;
linkId: string;
rangeIndex: number;
segmentId?: string;
segmentPage?: number;
};
}

export const ShowDocHyperLinkEditPopupOperation: ICommand<IShowDocHyperLinkEditPopupOperationParams> = {
type: CommandType.OPERATION,
id: 'docs.operation.show-hyper-link-edit-popup',
id: 'doc.operation.show-hyper-link-edit-popup',
handler(accessor, params) {
const linkInfo = params?.link;
if (shouldDisableAddLink(accessor) && !linkInfo) {
Expand All @@ -81,3 +78,43 @@ export const ShowDocHyperLinkEditPopupOperation: ICommand<IShowDocHyperLinkEditP
return true;
},
};

export interface IShowDocHyperLinkInfoPopupOperationParams {
linkId: string;
segmentId?: string;
unitId: string;
segmentPage?: number;
}

export const ToggleDocHyperLinkInfoPopupOperation: ICommand<IShowDocHyperLinkInfoPopupOperationParams> = {
type: CommandType.OPERATION,
id: 'doc.operation.toggle-hyper-link-info-popup',
handler(accessor, params) {
const hyperLinkService = accessor.get(DocHyperLinkPopupService);
if (!params) {
hyperLinkService.hideInfoPopup();
return true;
}

hyperLinkService.showInfoPopup(params);
return true;
},
};

export const ClickDocHyperLinkOperation: ICommand<{ unitId: string; linkId: string }> = {
type: CommandType.OPERATION,
id: 'doc.operation.click-hyper-link',
handler(accessor, params) {
if (!params) {
return false;
}
const { unitId, linkId } = params;
const docLinkModel = accessor.get(DocHyperLinkModel);
const link = docLinkModel.getLink(unitId, linkId);
if (!link) {
return false;
}
window.open(link.payload, '_blank', 'noopener noreferrer');
return true;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import type { DocumentDataModel } from '@univerjs/core';
import { Disposable, ICommandService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { ISetTextSelectionsOperationParams } from '@univerjs/docs';
import { DocSkeletonManagerService, SetTextSelectionsOperation } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';
import { SetTextSelectionsOperation } from '@univerjs/docs';
import { IRenderManagerService } from '@univerjs/engine-render';
import { DocHyperLinkPopupService } from '../services/hyper-link-popup.service';

@OnLifecycle(LifecycleStages.Ready, DocHyperLinkSelectionController)
Expand All @@ -39,30 +39,25 @@ export class DocHyperLinkSelectionController extends Disposable {
this._commandService.onCommandExecuted((commandInfo) => {
if (commandInfo.id === SetTextSelectionsOperation.id) {
const params = commandInfo.params as ISetTextSelectionsOperationParams;
const { unitId, ranges } = params;
const render = this._renderMangerService.getRenderById(unitId);
const skeleton = render?.with(DocSkeletonManagerService).getSkeleton();
const editArea = skeleton?.getViewModel().getEditArea();
if (editArea !== DocumentEditArea.BODY) {
this._docHyperLinkService.hideInfoPopup();
this._docHyperLinkService.hideEditPopup();
return;
}
const { unitId, ranges, segmentId } = params;

const doc = this._univerInstanceService.getUnit<DocumentDataModel>(unitId, UniverInstanceType.UNIVER_DOC);
const primary = ranges[0];
if (primary && doc) {
const { startOffset, endOffset, collapsed } = primary;
const customRanges = doc.getBody()?.customRanges;
if (collapsed) { // cursor
const { startOffset, endOffset, collapsed, segmentPage } = primary;
const customRanges = doc.getSelfOrHeaderFooterModel(segmentId)?.getBody()?.customRanges;
if (collapsed) {
// cursor
const index = customRanges?.findIndex((value) => (value.startIndex) < startOffset && value.endIndex > endOffset - 1) ?? -1;
if (index > -1) {
const customRange = customRanges![index];
this._docHyperLinkService.showInfoPopup({ unitId, linkId: customRange.rangeId, rangeIndex: index });
this._docHyperLinkService.showInfoPopup({ unitId, linkId: customRange.rangeId, segmentId, segmentPage });
return;
}
} else { // range
if (customRanges?.find((value) => value.startIndex <= startOffset && value.endIndex >= (endOffset - 1))) {
} else {
// range
const range = customRanges?.find((value) => value.startIndex <= startOffset && value.endIndex >= (endOffset - 1));
if (range) {
return;
}
}
Expand Down
Loading
Loading