Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
weird94 committed Aug 21, 2024
1 parent 73e370c commit 47c7a49
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
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 @@ -30,23 +30,32 @@ export class DocInterceptorService extends Disposable implements IRenderModule {
) {
super();

this.disposeWithMe(this._docSkeletonManagerService.currentViewModel$.subscribe((viewModel) => {
if (viewModel) {
const unitId = viewModel.getDataModel().getUnitId();
if (unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) {
return;
}
const viewModel = this._docSkeletonManagerService.getViewModel();

this.interceptDocumentViewModel(viewModel);
}
}));
const unitId = viewModel.getDataModel().getUnitId();
if (unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) {
return;
}

this.disposeWithMe(this.interceptDocumentViewModel(viewModel));

this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {
priority: -1,
handler: (data, pos, next) => {
return next(data);
},
}));

let disposableCollection = new DisposableCollection();
viewModel.segmentViewModels$.subscribe((segmentViewModels) => {
disposableCollection.dispose();
disposableCollection = new DisposableCollection();
segmentViewModels.forEach((segmentViewModel) => {
disposableCollection.add(this.interceptDocumentViewModel(segmentViewModel));
});
});

this.disposeWithMe(disposableCollection);
}

intercept<T extends IInterceptor<any, any>>(name: T, interceptor: T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ export class DocumentViewModel implements IDisposable {
headerTreeMap: Map<string, DocumentViewModel> = new Map();
footerTreeMap: Map<string, DocumentViewModel> = new Map();

private readonly _segmentViewModels$ = new BehaviorSubject<DocumentViewModel[]>([]);
readonly segmentViewModels$ = this._segmentViewModels$.asObservable();

constructor(private _documentDataModel: DocumentDataModel) {
if (_documentDataModel.getBody() == null) {
return;
Expand Down Expand Up @@ -607,14 +610,18 @@ export class DocumentViewModel implements IDisposable {

private _buildHeaderFooterViewModel() {
const { headerModelMap, footerModelMap } = this._documentDataModel;

const viewModels = [];
for (const [headerId, headerModel] of headerModelMap) {
this.headerTreeMap.set(headerId, new DocumentViewModel(headerModel));
viewModels.push(this.headerTreeMap.get(headerId)!);
}

for (const [footerId, footerModel] of footerModelMap) {
this.footerTreeMap.set(footerId, new DocumentViewModel(footerModel));
viewModels.push(this.footerTreeMap.get(footerId)!);
}

this._segmentViewModels$.next(viewModels);
}

private _getParagraphByIndex(nodes: DataStreamTreeNode[], insertIndex: number): Nullable<DataStreamTreeNode> {
Expand Down

0 comments on commit 47c7a49

Please sign in to comment.