mirror of
https://github.com/dream-num/univer.git
synced 2026-09-24 15:32:18 +08:00
fix(uni-formula-ui): uni formula deps error (#3302)
This commit is contained in:
+39
-6
@@ -14,12 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { DocumentDataModel } from '@univerjs/core';
|
||||
import { CustomRangeType, Disposable, ICommandService, ILogService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
|
||||
import type { IInsertCommandParams } from '@univerjs/docs';
|
||||
import { DeleteLeftCommand, InsertCommand, MoveCursorOperation, TextSelectionManagerService } from '@univerjs/docs';
|
||||
import { IEditorService } from '@univerjs/ui';
|
||||
import { DocEventManagerService } from '@univerjs/docs-ui';
|
||||
|
||||
import { filter, map, mergeMap } from 'rxjs';
|
||||
import { IRenderManagerService } from '@univerjs/engine-render';
|
||||
import { AddDocUniFormulaCommand, RemoveDocUniFormulaCommand, UpdateDocUniFormulaCommand } from '../commands/commands/doc.command';
|
||||
import type { IShowFormulaPopupOperationParams } from '../commands/operations/operation';
|
||||
import { CloseFormulaPopupOperation, ShowFormulaPopupOperation } from '../commands/operations/operation';
|
||||
@@ -35,9 +38,9 @@ export class DocUniFormulaInputController extends Disposable {
|
||||
@IUniverInstanceService private readonly _instanceSrv: IUniverInstanceService,
|
||||
@IEditorService private readonly _editorService: IEditorService,
|
||||
@ILogService private readonly _logService: ILogService,
|
||||
@Inject(DocEventManagerService) private readonly _docEventManagerService: DocEventManagerService,
|
||||
@Inject(UniFormulaPopupService) private readonly _formulaPopupSrv: UniFormulaPopupService,
|
||||
@Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService
|
||||
@Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
|
||||
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService
|
||||
) {
|
||||
super();
|
||||
|
||||
@@ -91,11 +94,16 @@ export class DocUniFormulaInputController extends Disposable {
|
||||
}
|
||||
|
||||
private _initHoverListener(): void {
|
||||
this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((customRanges) => {
|
||||
const focusedUnit = this._instanceSrv.getFocusedUnit();
|
||||
const rangesWithDoc$ = this._instanceSrv.focused$.pipe(
|
||||
map((focused) => focused ? this._instanceSrv.getUnit<DocumentDataModel>(focused, UniverInstanceType.UNIVER_DOC) : null),
|
||||
map((doc) => doc && { doc, docEventManagerService: this._renderManagerService.getRenderById(doc!.getUnitId())?.with(DocEventManagerService) }),
|
||||
filter((info) => !!info),
|
||||
mergeMap((info) => info.docEventManagerService!.hoverCustomRanges$.pipe(map((ranges) => ({ doc: info.doc, ranges }))))
|
||||
);
|
||||
|
||||
this.disposeWithMe(rangesWithDoc$.subscribe(({ doc, ranges: customRanges }) => {
|
||||
if (
|
||||
!focusedUnit ||
|
||||
!doc ||
|
||||
this._formulaPopupSrv.popupInfo?.type === 'new' ||
|
||||
this._formulaPopupSrv.popupLocked
|
||||
) {
|
||||
@@ -108,7 +116,32 @@ export class DocUniFormulaInputController extends Disposable {
|
||||
this._logService.debug('[DocUniFormulaController]: activeCustomRanges', customRanges);
|
||||
this._showPopup({
|
||||
startIndex,
|
||||
unitId: focusedUnit.getUnitId(),
|
||||
unitId: doc.getUnitId(),
|
||||
position: { rangeId },
|
||||
type: 'existing',
|
||||
});
|
||||
} else {
|
||||
if (!this._hovered) {
|
||||
this._closePopup(500);
|
||||
}
|
||||
}
|
||||
}));
|
||||
this.disposeWithMe(rangesWithDoc$.subscribe(({ doc, ranges: customRanges }) => {
|
||||
if (
|
||||
!doc ||
|
||||
this._formulaPopupSrv.popupInfo?.type === 'new' ||
|
||||
this._formulaPopupSrv.popupLocked
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const formulaCustomRange = customRanges.find((range) => range.range.rangeType === CustomRangeType.UNI_FORMULA)?.range;
|
||||
if (formulaCustomRange) {
|
||||
const { startIndex, rangeId } = formulaCustomRange;
|
||||
this._logService.debug('[DocUniFormulaController]: activeCustomRanges', customRanges);
|
||||
this._showPopup({
|
||||
startIndex,
|
||||
unitId: doc.getUnitId(),
|
||||
position: { rangeId },
|
||||
type: 'existing',
|
||||
});
|
||||
|
||||
@@ -104,12 +104,15 @@ export class UniFormulaPopupService extends Disposable {
|
||||
? this._uniFormulaService.getDocFormula(unitId, position.rangeId)?.f ?? '='
|
||||
: '=';
|
||||
|
||||
const disposable = this._docCanvasPopupManagerService.attachPopupToRange(makeSelection(startIndex), {
|
||||
componentKey: DOC_FORMULA_POPUP_KEY,
|
||||
onClickOutside: () => this.closePopup(), // user may update ref range selections
|
||||
direction: 'top',
|
||||
});
|
||||
|
||||
const disposable = this._docCanvasPopupManagerService.attachPopupToRange(
|
||||
makeSelection(startIndex),
|
||||
{
|
||||
componentKey: DOC_FORMULA_POPUP_KEY,
|
||||
onClickOutside: () => this.closePopup(), // user may update ref range selections
|
||||
direction: 'top',
|
||||
},
|
||||
unitId
|
||||
);
|
||||
this._popupInfo$.next({ unitId, disposable, type, f, startIndex, position });
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -116,15 +116,20 @@ export class DocDrawingPopupMenuController extends RxDisposable {
|
||||
}
|
||||
|
||||
const { unitId, subUnitId, drawingId } = drawingParam;
|
||||
|
||||
disposePopups.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(object, {
|
||||
componentKey: COMPONENT_IMAGE_POPUP_MENU,
|
||||
direction: 'horizontal',
|
||||
offset: [2, 0],
|
||||
extraProps: {
|
||||
menuItems: this._getImageMenuItems(unitId, subUnitId, drawingId),
|
||||
const popup = this._canvasPopManagerService.attachPopupToObject(
|
||||
object,
|
||||
{
|
||||
componentKey: COMPONENT_IMAGE_POPUP_MENU,
|
||||
direction: 'horizontal',
|
||||
offset: [2, 0],
|
||||
extraProps: {
|
||||
menuItems: this._getImageMenuItems(unitId, subUnitId, drawingId),
|
||||
},
|
||||
},
|
||||
})));
|
||||
unitId
|
||||
);
|
||||
|
||||
disposePopups.push(this.disposeWithMe(popup));
|
||||
|
||||
const focusDrawings = this._drawingManagerService.getFocusDrawings();
|
||||
|
||||
|
||||
@@ -69,11 +69,17 @@ export const ShowDocHyperLinkEditPopupOperation: ICommand<IShowDocHyperLinkEditP
|
||||
id: 'doc.operation.show-hyper-link-edit-popup',
|
||||
handler(accessor, params) {
|
||||
const linkInfo = params?.link;
|
||||
const univerInstanceService = accessor.get(IUniverInstanceService);
|
||||
if (shouldDisableAddLink(accessor) && !linkInfo) {
|
||||
return false;
|
||||
}
|
||||
const hyperLinkService = accessor.get(DocHyperLinkPopupService);
|
||||
hyperLinkService.showEditPopup(linkInfo);
|
||||
const unitId = linkInfo?.unitId || univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)?.getUnitId();
|
||||
|
||||
if (!unitId) {
|
||||
return false;
|
||||
}
|
||||
hyperLinkService.showEditPopup(unitId, linkInfo);
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -64,7 +64,7 @@ export class DocHyperLinkPopupService extends Disposable {
|
||||
return this._showingLink$.value;
|
||||
}
|
||||
|
||||
showEditPopup(linkInfo: Nullable<ILinkInfo>): Nullable<IDisposable> {
|
||||
showEditPopup(unitId: string, linkInfo: Nullable<ILinkInfo>): Nullable<IDisposable> {
|
||||
if (this._editPopup) {
|
||||
this._editPopup.dispose();
|
||||
}
|
||||
@@ -89,13 +89,15 @@ export class DocHyperLinkPopupService extends Disposable {
|
||||
}]);
|
||||
}
|
||||
}
|
||||
|
||||
if (activeRange) {
|
||||
this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(
|
||||
activeRange,
|
||||
{
|
||||
componentKey: DocHyperLinkEdit.componentKey,
|
||||
direction: 'bottom',
|
||||
}
|
||||
},
|
||||
unitId
|
||||
);
|
||||
return this._editPopup;
|
||||
}
|
||||
@@ -148,7 +150,8 @@ export class DocHyperLinkPopupService extends Disposable {
|
||||
onClickOutside: () => {
|
||||
this.hideInfoPopup();
|
||||
},
|
||||
}
|
||||
},
|
||||
info.unitId
|
||||
);
|
||||
return this._infoPopup;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ export const CloseMentionInfoPopupOperation: ICommand = {
|
||||
|
||||
export interface IShowMentionEditPopupOperationParams {
|
||||
startIndex: number;
|
||||
unitId: string;
|
||||
}
|
||||
|
||||
export const ShowMentionEditPopupOperation: ICommand<IShowMentionEditPopupOperationParams> = {
|
||||
@@ -51,7 +52,7 @@ export const ShowMentionEditPopupOperation: ICommand<IShowMentionEditPopupOperat
|
||||
return false;
|
||||
}
|
||||
const docMentionService = accessor.get(DocMentionService);
|
||||
docMentionService.startEditing(params.startIndex);
|
||||
docMentionService.startEditing({ unitId: params.unitId, index: params.startIndex });
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -43,6 +43,7 @@ export class DocMentionTriggerController extends Disposable {
|
||||
if (params.body.dataStream === '@' && activeRange && !Tools.isDefine(this._docMentionService.editing)) {
|
||||
this._commandService.executeCommand(ShowMentionEditPopupOperation.id, {
|
||||
startIndex: activeRange.startOffset - 1,
|
||||
unitId: params.unitId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export class DocMentionPopupService extends Disposable {
|
||||
|
||||
this.disposeWithMe(this._docMentionService.editing$.subscribe((editing) => {
|
||||
if (editing !== undefined && editing !== null) {
|
||||
this.showEditPopup(editing);
|
||||
this.showEditPopup(editing.unitId, editing.index);
|
||||
} else {
|
||||
this.closeEditPopup();
|
||||
}
|
||||
@@ -54,7 +54,7 @@ export class DocMentionPopupService extends Disposable {
|
||||
|
||||
closeInfoPopup() {}
|
||||
|
||||
showEditPopup(index: number) {
|
||||
showEditPopup(unitId: string, index: number) {
|
||||
this.closeEditPopup();
|
||||
const dispose = this._docCanvasPopupManagerService.attachPopupToRange(
|
||||
{ startOffset: index, endOffset: index, collapsed: true },
|
||||
@@ -64,7 +64,8 @@ export class DocMentionPopupService extends Disposable {
|
||||
this.closeEditPopup();
|
||||
},
|
||||
direction: 'bottom',
|
||||
}
|
||||
},
|
||||
unitId
|
||||
);
|
||||
this._editPopup$.next({ popup: dispose, anchor: index });
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Disposable } from '@univerjs/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
|
||||
export class DocMentionService extends Disposable {
|
||||
private readonly _editing$ = new BehaviorSubject<Nullable<number>>(undefined);
|
||||
private readonly _editing$ = new BehaviorSubject<Nullable<{ unitId: string; index: number }>>(undefined);
|
||||
readonly editing$ = this._editing$.asObservable();
|
||||
|
||||
get editing() {
|
||||
@@ -34,8 +34,8 @@ export class DocMentionService extends Disposable {
|
||||
});
|
||||
}
|
||||
|
||||
startEditing(index: number) {
|
||||
this._editing$.next(index);
|
||||
startEditing(item: { unitId: string; index: number }) {
|
||||
this._editing$.next(item);
|
||||
}
|
||||
|
||||
endEditing() {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { IDisposable, ITextRangeParam } from '@univerjs/core';
|
||||
import { Disposable, DisposableCollection, ICommandService, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
|
||||
import { Disposable, DisposableCollection, ICommandService, Inject, IUniverInstanceService } from '@univerjs/core';
|
||||
import { getLineBounding, IRenderManagerService, NodePositionConvertToCursor, pxToNum } from '@univerjs/engine-render';
|
||||
import type { BaseObject, Documents, IBoundRectNoAngle, IRender, Scene } from '@univerjs/engine-render';
|
||||
import type { IPopup } from '@univerjs/ui';
|
||||
@@ -222,18 +222,10 @@ export class DocCanvasPopManagerService extends Disposable {
|
||||
* @param popup popup item
|
||||
* @returns disposable
|
||||
*/
|
||||
attachPopupToObject(targetObject: BaseObject, popup: IDocCanvasPopup): IDisposable {
|
||||
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)!;
|
||||
const unitId = workbook.getUnitId();
|
||||
// const subUnitId =
|
||||
|
||||
attachPopupToObject(targetObject: BaseObject, popup: IDocCanvasPopup, unitId: string): IDisposable {
|
||||
const currentRender = this._renderManagerService.getRenderById(unitId);
|
||||
if (!currentRender) {
|
||||
return {
|
||||
dispose: () => {
|
||||
// empty
|
||||
},
|
||||
};
|
||||
throw new Error(`Current render not found, unitId: ${unitId}`);
|
||||
}
|
||||
|
||||
const { position, position$, disposable } = this._createObjectPositionObserver(targetObject, currentRender);
|
||||
@@ -256,17 +248,22 @@ export class DocCanvasPopManagerService extends Disposable {
|
||||
};
|
||||
}
|
||||
|
||||
attachPopupToRange(range: ITextRangeParam, popup: IDocCanvasPopup): IDisposable {
|
||||
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)!;
|
||||
const unitId = workbook.getUnitId();
|
||||
/**
|
||||
* attach a popup to doc range
|
||||
* @param range doc range
|
||||
* @param popup popup item
|
||||
* @param unitId unit id
|
||||
* @returns disposable
|
||||
*/
|
||||
attachPopupToRange(range: ITextRangeParam, popup: IDocCanvasPopup, unitId: string): IDisposable {
|
||||
const doc = this._univerInstanceService.getUnit(unitId);
|
||||
if (!doc) {
|
||||
throw new Error(`Document not found, unitId: ${unitId}`);
|
||||
}
|
||||
const { direction = 'top', multipleDirection } = popup;
|
||||
const currentRender = this._renderManagerService.getRenderById(unitId);
|
||||
if (!currentRender) {
|
||||
return {
|
||||
dispose: () => {
|
||||
// empty
|
||||
},
|
||||
};
|
||||
throw new Error(`Current render not found, unitId: ${unitId}`);
|
||||
}
|
||||
|
||||
const { positions: bounds, positions$: bounds$, disposable } = this._createRangePositionObserver(range, currentRender);
|
||||
|
||||
Reference in New Issue
Block a user