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.

chore: add docs consumeContentInsertRange export (#7178)

wpxp12345656eca208275e
diff --git a/packages/docs-ui/src/commands/commands/set-heading.command.ts b/packages/docs-ui/src/commands/commands/set-heading.command.ts
index b2b5e212bc..5cf01adde0 100644
--- a/packages/docs-ui/src/commands/commands/set-heading.command.ts
+++ b/packages/docs-ui/src/commands/commands/set-heading.command.ts
@@ -31,7 +31,7 @@ import {
TextXActionType,
UniverInstanceType,
} from '@univerjs/core';
-import { DocContentInsertService, DocSelectionManagerService, RichTextEditingMutation } from '@univerjs/docs';
+import { consumeContentInsertRange, DocSelectionManagerService, RichTextEditingMutation } from '@univerjs/docs';
export interface ISetParagraphNamedStyleCommandParams {
value: NamedStyleType;
@@ -102,14 +102,6 @@ export const SetParagraphNamedStyleCommand: ICommand<ISetParagraphNamedStyleComm
},
};
-function consumeContentInsertRange(accessor: IAccessor, unitId: string) {
- try {
- return accessor.get(DocContentInsertService).consumeInsertRange(unitId);
- } catch {
- return null;
- }
-}
-
function insertNamedStyleParagraph(
accessor: IAccessor,
doc: DocumentDataModel,
diff --git a/packages/docs-ui/src/services/doc-paragraph-menu.service.ts b/packages/docs-ui/src/services/doc-paragraph-menu.service.ts
index 8f10d1b190..8f367dedd1 100644
--- a/packages/docs-ui/src/services/doc-paragraph-menu.service.ts
+++ b/packages/docs-ui/src/services/doc-paragraph-menu.service.ts
@@ -112,7 +112,7 @@ interface IDocExpandedSelectionState {
}
export class DocParagraphMenuService extends Disposable implements IRenderModule {
- private _paragrahMenu: {
+ private _paragraphMenu: {
paragraph: IMutiPageParagraphBound;
target: IDocBlockMenuTarget;
blockRange?: IDocumentBlockRange;
@@ -129,11 +129,11 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
private _slashMenuRequestNonce = 0;
get activeParagraph() {
- return this._paragrahMenu?.paragraph;
+ return this._paragraphMenu?.paragraph;
}
get activeTarget() {
- return this._paragrahMenu?.target ?? null;
+ return this._paragraphMenu?.target ?? null;
}
setBlockMenuDragging(isDragging: boolean) {
@@ -163,7 +163,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
}
private _isCursorInActiveParagraph() {
- if (!this._paragrahMenu) {
+ if (!this._paragraphMenu) {
return false;
}
@@ -174,8 +174,8 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
if (
!activeTextRange?.collapsed ||
- activeTextRange.startOffset < this._paragrahMenu.paragraph.paragraphStart ||
- activeTextRange.startOffset > this._paragrahMenu.paragraph.paragraphEnd
+ activeTextRange.startOffset < this._paragraphMenu.paragraph.paragraphStart ||
+ activeTextRange.startOffset > this._paragraphMenu.paragraph.paragraphEnd
) {
return false;
}
@@ -223,8 +223,8 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
}
setParagraphMenuActive(active: boolean) {
- if (this._paragrahMenu) {
- this._paragrahMenu.active = active;
+ if (this._paragraphMenu) {
+ this._paragraphMenu.active = active;
}
}
@@ -251,7 +251,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
return;
}
- if (this._paragrahMenu?.target.kind === DocumentBlockType.TABLE) {
+ if (this._paragraphMenu?.target.kind === DocumentBlockType.TABLE) {
return;
}
@@ -265,7 +265,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
!this._floatMenuService.floatMenu &&
!this._context.unit.getDisabled()
) {
- if (this._paragrahMenu?.active) {
+ if (this._paragraphMenu?.active) {
return;
}
@@ -302,7 +302,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
this.disposeWithMe(this._docSelectionManagerService.textSelection$.subscribe(({ textRanges, rectRanges }) => {
const selectionState = this._getExpandedSelectionState([...textRanges, ...rectRanges]);
- if (selectionState.hasExpandedTextRange || (selectionState.hasRectRange && this._paragrahMenu?.target.kind !== DocumentBlockType.TABLE)) {
+ if (selectionState.hasExpandedTextRange || (selectionState.hasRectRange && this._paragraphMenu?.target.kind !== DocumentBlockType.TABLE)) {
this.hideParagraphMenu(true);
}
}));
@@ -314,7 +314,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
}
lastScrollY = e.scrollY;
- if (this._paragrahMenu?.blockRange) {
+ if (this._paragraphMenu?.blockRange) {
return;
}
if (this._isBlockMenuDragging) {
@@ -429,7 +429,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
private _getSlashMenuParagraph(config: IEditorInputConfig): IMutiPageParagraphBound | null {
const activeRange = this._getCollapsedTextRange(config);
const offset = activeRange?.startOffset;
- const activeParagraph = this._paragrahMenu?.paragraph ?? null;
+ const activeParagraph = this._paragraphMenu?.paragraph ?? null;
if (activeParagraph && offset != null && offset >= activeParagraph.paragraphStart && offset <= activeParagraph.paragraphEnd) {
return activeParagraph;
@@ -478,7 +478,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
return;
}
- if (this._paragrahMenu?.target.key === target.key) {
+ if (this._paragraphMenu?.target.key === target.key) {
return;
}
@@ -521,7 +521,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
this._context.unitId
);
- this._paragrahMenu = {
+ this._paragraphMenu = {
paragraph: targetParagraph,
target,
blockRange,
@@ -565,7 +565,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
return;
}
- if (this._paragrahMenu?.target.key === target.key) {
+ if (this._paragraphMenu?.target.key === target.key) {
return;
}
@@ -595,7 +595,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
this._context.unitId
);
- this._paragrahMenu = {
+ this._paragraphMenu = {
paragraph,
target,
disposable,
@@ -605,7 +605,7 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
}
private _shouldKeepCurrentCellMenuForTable(table: ICustomTable): boolean {
- const target = this._paragrahMenu?.target;
+ const target = this._paragraphMenu?.target;
if (!target || target.kind === DocumentBlockType.TABLE || !target.cellRange) {
return false;
}
@@ -665,9 +665,9 @@ export class DocParagraphMenuService extends Disposable implements IRenderModule
return;
}
- if (this._paragrahMenu && ((this._paragrahMenu.disposable.canDispose() || force))) {
- this._paragrahMenu.disposable.dispose();
- this._paragrahMenu = null;
+ if (this._paragraphMenu && ((this._paragraphMenu.disposable.canDispose() || force))) {
+ this._paragraphMenu.disposable.dispose();
+ this._paragraphMenu = null;
this._isSlashMenuActive = false;
this._slashMenuRequest$.next(null);
this._activeTarget$.next(null);
diff --git a/packages/docs-ui/src/services/index.ts b/packages/docs-ui/src/services/index.ts
index 73adb187e5..b0dd716b83 100644
--- a/packages/docs-ui/src/services/index.ts
+++ b/packages/docs-ui/src/services/index.ts
@@ -18,5 +18,6 @@ export { default as PastePluginLark } from './clipboard/html-to-udm/paste-plugin
export { default as PastePluginUniver } from './clipboard/html-to-udm/paste-plugins/plugin-univer';
export { default as PastePluginWord } from './clipboard/html-to-udm/paste-plugins/plugin-word';
export { type IPastePlugin } from './clipboard/html-to-udm/paste-plugins/type';
+export type { IDocBlockMenuTarget } from './doc-paragraph-menu.service';
export { calcDocFitToWidthScale, DocViewScaleService, normalizeDocFitToWidthOptions, resolveDocFitBaseWidth, resolveDocViewScale } from './doc-view-scale';
export type { ICalcDocFitToWidthScaleParams, IResolveDocFitBaseWidthParams } from './doc-view-scale';
diff --git a/packages/docs/src/index.ts b/packages/docs/src/index.ts
index 5ac3189593..dce12ba6ef 100644
--- a/packages/docs/src/index.ts
+++ b/packages/docs/src/index.ts
@@ -46,3 +46,4 @@ export {
deleteCustomRangeFactory,
} from './utils/custom-range-factory';
export { replaceSelectionFactory } from './utils/replace-selection-factory';
+export { consumeContentInsertRange } from './utils/util';
diff --git a/packages/docs/src/utils/util.ts b/packages/docs/src/utils/util.ts
new file mode 100644
index 0000000000..4d066ee6bb
--- /dev/null
+++ b/packages/docs/src/utils/util.ts
@@ -0,0 +1,26 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { IAccessor } from '@univerjs/core';
+import { DocContentInsertService } from '../services/doc-content-insert.service';
+
+export function consumeContentInsertRange(accessor: IAccessor, unitId: string) {
+ try {
+ return accessor.get(DocContentInsertService).consumeInsertRange(unitId);
+ } catch {
+ return null;
+ }
+}