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.

feat(docs-hyper-link): hyper link refactor (#3148)

zhangwf21ce5066295
diff --git a/examples/package.json b/examples/package.json
index 9cc7702343..290ae86522 100644
--- a/examples/package.json
+++ b/examples/package.json
@@ -19,7 +19,6 @@
"@univerjs/docs": "workspace:*",
"@univerjs/docs-drawing": "workspace:*",
"@univerjs/docs-drawing-ui": "workspace:*",
- "@univerjs/docs-hyper-link": "workspace:*",
"@univerjs/docs-hyper-link-ui": "workspace:*",
"@univerjs/docs-mention-ui": "workspace:*",
"@univerjs/docs-thread-comment-ui": "workspace:*",
diff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.ts
index 37a3eb744e..f7094979fd 100644
--- a/examples/src/sheets/main.ts
+++ b/examples/src/sheets/main.ts
@@ -41,8 +41,6 @@ import { FUniver } from '@univerjs/facade';
import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor';
import { UniverSheetsSortUIPlugin } from '@univerjs/sheets-sort-ui';
import { UniverSheetsDrawingUIPlugin } from '@univerjs/sheets-drawing-ui';
-import { UniverDocsHyperLinkPlugin } from '@univerjs/docs-hyper-link';
-
import { enUS, ruRU, viVN, zhCN, zhTW } from '../locales';
import { DEFAULT_WORKBOOK_DATA_DEMO } from '../data/sheets/demo/default-workbook-data-demo';
@@ -73,7 +71,6 @@ univer.registerPlugin(UniverDocsPlugin, { hasScroll: false });
univer.registerPlugin(UniverRenderEnginePlugin);
univer.registerPlugin(UniverUIPlugin, { container: 'app' });
univer.registerPlugin(UniverDocsUIPlugin);
-univer.registerPlugin(UniverDocsHyperLinkPlugin);
univer.registerPlugin(UniverSheetsPlugin, { notExecuteFormula: true });
univer.registerPlugin(UniverSheetsUIPlugin);
diff --git a/examples/src/slides/main.ts b/examples/src/slides/main.ts
index a1fb3a88fb..1b81141e1c 100644
--- a/examples/src/slides/main.ts
+++ b/examples/src/slides/main.ts
@@ -24,7 +24,6 @@ import { UniverUIPlugin } from '@univerjs/ui';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
import { UniverDocsPlugin } from '@univerjs/docs';
import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
-import { UniverDocsHyperLinkPlugin } from '@univerjs/docs-hyper-link';
import { UniverDrawingPlugin } from '@univerjs/drawing';
import { DEFAULT_SLIDE_DATA } from '../data';
import { enUS, ruRU, zhCN } from '../locales';
@@ -45,7 +44,6 @@ univer.registerPlugin(UniverRenderEnginePlugin);
univer.registerPlugin(UniverUIPlugin, { container: 'app' });
univer.registerPlugin(UniverDocsPlugin, { hasScroll: false });
univer.registerPlugin(UniverDocsUIPlugin);
-univer.registerPlugin(UniverDocsHyperLinkPlugin);
// base-render
univer.registerPlugin(UniverFormulaEnginePlugin);
univer.registerPlugin(UniverDrawingPlugin);
diff --git a/packages/core/src/types/interfaces/i-document-data.ts b/packages/core/src/types/interfaces/i-document-data.ts
index 647b418d5d..419de46330 100644
--- a/packages/core/src/types/interfaces/i-document-data.ts
+++ b/packages/core/src/types/interfaces/i-document-data.ts
@@ -338,23 +338,27 @@ export interface ITextRun {
// tab?: BooleanNumber; // if tab,default is false
}
-export interface ICustomRange {
+/**
+ * Block element, link like, disabled to self nested
+ */
+export interface ICustomRange<T extends Record<string, any> = Record<string, any>> {
startIndex: number;
endIndex: number;
rangeId: string;
- rangeType: CustomRangeType;
+ rangeType: CustomRangeType | number;
/**
* display as a whole-entity
*/
wholeEntity?: boolean;
+ /**
+ * properties of custom range,
+ * for example, hyperlink: `{ url: string }`
+ */
+ properties?: T;
}
-// TODO: @weird94 this range should not be built-in. It makes custom ranges not
-// extensible for community users.
+export type IHyperLinkCustomRange = ICustomRange<{ url: string }>;
-/**
- * @deprecated
- */
export enum CustomRangeType {
HYPERLINK,
FIELD, // 17.16 Fields and Hyperlinks
diff --git a/packages/design/src/components/popup/RectPopup.tsx b/packages/design/src/components/popup/RectPopup.tsx
index 7095d4e344..5c40791d4f 100644
--- a/packages/design/src/components/popup/RectPopup.tsx
+++ b/packages/design/src/components/popup/RectPopup.tsx
@@ -35,7 +35,7 @@ export interface IRectPopupProps {
*/
anchorRect: IAbsolutePosition;
excludeRects?: IAbsolutePosition[];
- direction?: 'vertical' | 'horizontal' | 'left' | 'top' | 'right' | 'left' | 'bottom';
+ direction?: 'vertical' | 'horizontal' | 'left' | 'top' | 'right' | 'left' | 'bottom' | 'bottom-center' | 'top-center';
// #region closing behavior
@@ -61,17 +61,25 @@ function calcPopupPosition(layout: IPopupLayoutInfo): { top: number; left: numbe
const { position, width, height, containerHeight, containerWidth, direction = 'vertical' } = layout;
// In y-axis
- if (direction === 'vertical' || direction === 'top' || direction === 'bottom') {
+ if (direction === 'vertical' || direction.includes('top') || direction.includes('bottom')) {
const { left: startX, top: startY, right: endX, bottom: endY } = position;
- const verticalStyle = direction === 'top'
- // const verticalStyle = ((endY + height) > containerHeight || direction === 'top')
+ const verticalStyle = direction.indexOf('top') > -1
? { top: Math.max(startY - height, PUSHING_MINIMUM_GAP) }
: { top: Math.min(endY, containerHeight - height - PUSHING_MINIMUM_GAP) };
- // If the popup element exceed the visible area. We should "push" it back.
- const horizontalStyle = (startX + width) > containerWidth
- ? { left: Math.max(endX - width, PUSHING_MINIMUM_GAP) } // on left
- : { left: Math.min(startX, containerWidth - width - PUSHING_MINIMUM_GAP) }; // on right
+ let horizontalStyle;
+ if (direction.includes('center')) {
+ const rectWidth = endX - startX;
+ const offsetX = (rectWidth - width) / 2;
+ horizontalStyle = {
+ left: startX + offsetX,
+ };
+ } else {
+ // If the popup element exceed the visible area. We should "push" it back.
+ horizontalStyle = (startX + width) > containerWidth
+ ? { left: Math.max(endX - width, PUSHING_MINIMUM_GAP) } // on left
+ : { left: Math.min(startX, containerWidth - width - PUSHING_MINIMUM_GAP) }; // on right
+ }
return { ...verticalStyle, ...horizontalStyle };
}
diff --git a/packages/docs-hyper-link-ui/src/commands/commands/add-link.command.ts b/packages/docs-hyper-link-ui/src/commands/commands/add-link.command.ts
index beea47a214..3517550379 100644
--- a/packages/docs-hyper-link-ui/src/commands/commands/add-link.command.ts
+++ b/packages/docs-hyper-link-ui/src/commands/commands/add-link.command.ts
@@ -14,9 +14,8 @@
* limitations under the License.
*/
-import { CommandType, CustomRangeType, generateRandomId, type ICommand, ICommandService, sequenceExecute } from '@univerjs/core';
+import { CommandType, CustomRangeType, generateRandomId, type ICommand, ICommandService } from '@univerjs/core';
import { addCustomRangeBySelectionFactory } from '@univerjs/docs';
-import { AddDocHyperLinkMutation } from '@univerjs/docs-hyper-link';
export interface IAddDocHyperLinkCommandParams {
payload: string;
@@ -39,15 +38,13 @@ export const AddDocHyperLinkCommand: ICommand<IAddDocHyperLinkCommandParams> = {
{
rangeId: id,
rangeType: CustomRangeType.HYPERLINK,
+ properties: {
+ url: payload,
+ },
}
);
if (doMutation) {
- const hyperLinkMutation = {
- id: AddDocHyperLinkMutation.id,
- params: { unitId, link: { payload, id } },
- };
-
- return (await sequenceExecute([hyperLinkMutation, doMutation], commandService)).result;
+ return commandService.syncExecuteCommand(doMutation.id, doMutation.params);
}
return false;
diff --git a/packages/docs-hyper-link-ui/src/commands/commands/delete-link.command.ts b/packages/docs-hyper-link-ui/src/commands/commands/delete-link.command.ts
index e3659ab8f0..a9156fbc9b 100644
--- a/packages/docs-hyper-link-ui/src/commands/commands/delete-link.command.ts
+++ b/packages/docs-hyper-link-ui/src/commands/commands/delete-link.command.ts
@@ -17,7 +17,6 @@
import type { ICommand } from '@univerjs/core';
import { CommandType, ICommandService } from '@univerjs/core';
import { deleteCustomRangeFactory } from '@univerjs/docs';
-import { DocHyperLinkModel } from '@univerjs/docs-hyper-link';
export interface IDeleteDocHyperLinkMutationParams {
unitId: string;
@@ -34,11 +33,6 @@ export const DeleteDocHyperLinkCommand: ICommand<IDeleteDocHyperLinkMutationPara
}
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, segmentId });
if (!doMutation) {
diff --git a/packages/docs-hyper-link-ui/src/commands/commands/update-link.command.ts b/packages/docs-hyper-link-ui/src/commands/commands/update-link.command.ts
index 9957f1d44c..713d429cf1 100644
--- a/packages/docs-hyper-link-ui/src/commands/commands/update-link.command.ts
+++ b/packages/docs-hyper-link-ui/src/commands/commands/update-link.command.ts
@@ -14,10 +14,8 @@
* limitations under the License.
*/
-import { CommandType, CustomRangeType, DataStreamTreeTokenType, generateRandomId, type ICommand, ICommandService, sequenceExecute } from '@univerjs/core';
+import { CommandType, CustomRangeType, DataStreamTreeTokenType, generateRandomId, type ICommand, ICommandService } 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;
@@ -44,7 +42,7 @@ export const UpdateDocHyperLinkCommand: ICommand<IUpdateDocHyperLinkCommandParam
const newId = generateRandomId();
const replaceSelection = replaceSelectionFactory(accessor, {
- unitId: params.unitId,
+ unitId,
body: {
dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${params.label}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
customRanges: [{
@@ -52,6 +50,9 @@ export const UpdateDocHyperLinkCommand: ICommand<IUpdateDocHyperLinkCommandParam
rangeType: CustomRangeType.HYPERLINK,
startIndex: 0,
endIndex: params.label.length + 1,
+ properties: {
+ url: payload,
+ },
}],
},
selection: {
@@ -66,22 +67,6 @@ export const UpdateDocHyperLinkCommand: ICommand<IUpdateDocHyperLinkCommandParam
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;
+ return commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params);
},
};
diff --git a/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts b/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts
index 6839b61006..1d9b4c24d4 100644
--- a/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts
+++ b/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts
@@ -17,7 +17,6 @@
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) => {
@@ -101,20 +100,22 @@ export const ToggleDocHyperLinkInfoPopupOperation: ICommand<IShowDocHyperLinkInf
},
};
-export const ClickDocHyperLinkOperation: ICommand<{ unitId: string; linkId: string }> = {
+export const ClickDocHyperLinkOperation: ICommand<{ unitId: string; linkId: string; segmentId?: 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;
+ const { unitId, linkId, segmentId } = params;
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const doc = univerInstanceService.getUnit<DocumentDataModel>(unitId, UniverInstanceType.UNIVER_DOC);
+ const body = doc?.getSelfOrHeaderFooterModel(segmentId).getBody();
+ const link = body?.customRanges?.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK)?.properties?.url;
+
+ if (link) {
+ window.open(link, '_blank', 'noopener noreferrer');
}
- window.open(link.payload, '_blank', 'noopener noreferrer');
return true;
},
};
diff --git a/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-clipboard.controller.ts b/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-clipboard.controller.ts
deleted file mode 100644
index d809b26560..0000000000
--- a/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-clipboard.controller.ts
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { DocumentDataModel } from '@univerjs/core';
-import { CustomRangeType, Disposable, ICommandService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, Tools, UniverInstanceType, updateAttributeByDelete } from '@univerjs/core';
-import { TextSelectionManagerService } from '@univerjs/docs';
-import type { IAddDocHyperLinkMutationParams } from '@univerjs/docs-hyper-link';
-import { AddDocHyperLinkMutation, DocHyperLinkModel } from '@univerjs/docs-hyper-link';
-import { IDocClipboardService } from '@univerjs/docs-ui';
-
-@OnLifecycle(LifecycleStages.Ready, DocHyperLinkClipboardController)
-export class DocHyperLinkClipboardController extends Disposable {
- constructor(
- @Inject(IDocClipboardService) private readonly _docClipboardService: IDocClipboardService,
- @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
- @Inject(DocHyperLinkModel) private readonly _hyperLinkModel: DocHyperLinkModel,
- @Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
- @ICommandService private readonly _commandService: ICommandService
- ) {
- super();
-
- this._initClipboard();
- }
-
- private _initClipboard() {
- this.disposeWithMe(this._docClipboardService.addClipboardHook({
- onBeforePaste: (body) => {
- const doc = this._univerInstanceService.getCurrentUnitForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);
- if (!doc) {
- return body;
- }
- const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle();
- const customRanges = doc.getBody()?.customRanges;
-
- const matchedRange = activeRange ?
- customRanges?.find(
- (range) =>
- range.rangeType === CustomRangeType.HYPERLINK &&
- range.startIndex < activeRange.startOffset &&
- range.endIndex > activeRange.endOffset - 1
- )
- : null;
- // insert into current link inside
- if (matchedRange) {
- const { customRanges = [], ...extBody } = body;
- const deleteRanges = customRanges.filter((range) => range.rangeType === CustomRangeType.HYPERLINK);
- const deleteIndexes = deleteRanges.map((i) => [i.startIndex, i.endIndex]).flat().sort((pre, aft) => pre - aft);
- const bodyWithoutLink = {
- ...extBody,
- customRanges: customRanges.filter((range) => range.rangeType !== CustomRangeType.HYPERLINK),
- };
- for (let i = 0; i < deleteIndexes.length; i++) {
- updateAttributeByDelete(bodyWithoutLink, 1, deleteIndexes[i] - i);
- }
- return bodyWithoutLink;
- } else {
- const unitId = doc.getUnitId();
- const customRangeIds = new Set(customRanges?.map((i) => i.rangeType === CustomRangeType.HYPERLINK && i.rangeId));
- body.customRanges?.forEach((range) => {
- if (range.rangeType === CustomRangeType.HYPERLINK) {
- if (customRangeIds.has(range.rangeId)) {
- const link = this._hyperLinkModel.getLink(unitId, range.rangeId);
- if (link) {
- const newId = Tools.generateRandomId();
- this._commandService.executeCommand(
- AddDocHyperLinkMutation.id,
- {
- unitId,
- link: {
- id: newId,
- payload: link.payload,
- },
- } as IAddDocHyperLinkMutationParams
- );
-
- range.rangeId = newId;
- }
- } else if (body.payloads?.[range.rangeId]) {
- const url = body.payloads[range.rangeId];
- this._commandService.executeCommand(
- AddDocHyperLinkMutation.id,
- {
- unitId,
- link: {
- id: range.rangeId,
- payload: url,
- },
- } as IAddDocHyperLinkMutationParams
- );
- }
- }
- });
- }
- return body;
- },
- }));
- }
-}
diff --git a/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-custom-range.controller.ts b/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-custom-range.controller.ts
deleted file mode 100644
index 9fa276636f..0000000000
--- a/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-custom-range.controller.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { CustomRangeType, Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';
-import { DocCustomRangeService } from '@univerjs/docs';
-import type { IAddDocHyperLinkMutationParams } from '@univerjs/docs-hyper-link';
-import { AddDocHyperLinkMutation, DocHyperLinkModel } from '@univerjs/docs-hyper-link';
-
-@OnLifecycle(LifecycleStages.Ready, DocHyperLinkCustomRangeController)
-export class DocHyperLinkCustomRangeController extends Disposable {
- constructor(
- @Inject(DocCustomRangeService) private readonly _docCustomRangeService: DocCustomRangeService,
- @Inject(DocHyperLinkModel) private readonly _docHyperLinkModel: DocHyperLinkModel,
- @ICommandService private readonly _commandService: ICommandService
- ) {
- super();
-
- this._initCustomRangeHooks();
- }
-
- private _initCustomRangeHooks() {
- this.disposeWithMe(
- this._docCustomRangeService.addClipboardHook({
- onCopyCustomRange: (unitId, range) => {
- const { rangeId, rangeType, data, ...ext } = range;
- if (rangeType === CustomRangeType.HYPERLINK) {
- if (data) {
- const id = Tools.generateRandomId();
- this._commandService.executeCommand(
- AddDocHyperLinkMutation.id,
- {
- unitId,
- link: {
- id,
- payload: data,
- },
- } as IAddDocHyperLinkMutationParams
- );
- return {
- ...range,
- rangeId: id,
- };
- }
- const link = this._docHyperLinkModel.getLink(unitId, rangeId);
- if (!link) {
- return range;
- }
- const newId = Tools.generateRandomId();
- this._commandService.executeCommand(
- AddDocHyperLinkMutation.id,
- {
- unitId,
- link: {
- id: newId,
- payload: link.payload,
- },
- } as IAddDocHyperLinkMutationParams
- );
-
- return {
- ...ext,
- rangeId: newId,
- rangeType,
- };
- }
- return range;
- },
- })
- );
- }
-}
diff --git a/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-selection.controller.ts b/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-selection.controller.ts
index db3f6fdb69..426843130a 100644
--- a/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-selection.controller.ts
+++ b/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-selection.controller.ts
@@ -18,7 +18,6 @@ import type { DocumentDataModel } from '@univerjs/core';
import { Disposable, ICommandService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { ISetTextSelectionsOperationParams } from '@univerjs/docs';
import { SetTextSelectionsOperation } from '@univerjs/docs';
-import { IRenderManagerService } from '@univerjs/engine-render';
import { DocHyperLinkPopupService } from '../services/hyper-link-popup.service';
@OnLifecycle(LifecycleStages.Ready, DocHyperLinkSelectionController)
@@ -26,8 +25,7 @@ export class DocHyperLinkSelectionController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
- @Inject(DocHyperLinkPopupService) private readonly _docHyperLinkService: DocHyperLinkPopupService,
- @IRenderManagerService private readonly _renderMangerService: IRenderManagerService
+ @Inject(DocHyperLinkPopupService) private readonly _docHyperLinkService: DocHyperLinkPopupService
) {
super();
diff --git a/packages/docs-hyper-link-ui/src/controllers/render-controllers/hyper-link-event.render-controller.ts b/packages/docs-hyper-link-ui/src/controllers/render-controllers/hyper-link-event.render-controller.ts
index 38383ca402..b1e1176a65 100644
--- a/packages/docs-hyper-link-ui/src/controllers/render-controllers/hyper-link-event.render-controller.ts
+++ b/packages/docs-hyper-link-ui/src/controllers/render-controllers/hyper-link-event.render-controller.ts
@@ -17,8 +17,8 @@
import type { DocumentDataModel } from '@univerjs/core';
import { CustomRangeType, Disposable, ICommandService, Inject } from '@univerjs/core';
import { DocEventManagerService } from '@univerjs/docs-ui';
-import { DocumentEditArea, type IRenderContext, type IRenderModule } from '@univerjs/engine-render';
-import { DocSkeletonManagerService } from '@univerjs/docs';
+import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
+import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';
import { ClickDocHyperLinkOperation, ToggleDocHyperLinkInfoPopupOperation } from '../../commands/operations/popup.operation';
import { DocHyperLinkPopupService } from '../../services/hyper-link-popup.service';
@@ -32,7 +32,8 @@ export class DocHyperLinkEventRenderController extends Disposable implements IRe
@Inject(DocEventManagerService) private readonly _docEventManagerService: DocEventManagerService,
@ICommandService private readonly _commandService: ICommandService,
@Inject(DocHyperLinkPopupService) private readonly _hyperLinkPopupService: DocHyperLinkPopupService,
- @Inject(DocSkeletonManagerService) private readonly _docSkeletonManagerService: DocSkeletonManagerService
+ @Inject(DocSkeletonManagerService) private readonly _docSkeletonManagerService: DocSkeletonManagerService,
+ @Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService
) {
super();
@@ -52,8 +53,9 @@ export class DocHyperLinkEventRenderController extends Disposable implements IRe
this.disposeWithMe(
this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
const link = ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK);
- const editArea = this._skeleton.getViewModel().getEditArea();
- if ((link?.segmentId && editArea === DocumentEditArea.BODY) || (!link?.segmentId && editArea !== DocumentEditArea.BODY)) {
+ const activeRanges = this._textSelectionManagerService.getCurrentTextRanges();
+ const currentSegmentId = activeRanges?.[0].segmentId;
+ if ((link?.segmentId ?? '') !== currentSegmentId) {
this._hideInfoPopup();
return;
}
@@ -86,6 +88,7 @@ export class DocHyperLinkEventRenderController extends Disposable implements IRe
{
unitId: this._context.unitId,
linkId: link.rangeId,
+ segmentId: range.segmentId,
}
);
}
diff --git a/packages/docs-hyper-link-ui/src/index.ts b/packages/docs-hyper-link-ui/src/index.ts
index c530b4af0f..8f6c1a370f 100644
--- a/packages/docs-hyper-link-ui/src/index.ts
+++ b/packages/docs-hyper-link-ui/src/index.ts
@@ -15,5 +15,3 @@
*/
export { UniverDocsHyperLinkUIPlugin } from './plugin';
-
-// export {} from './'
diff --git a/packages/docs-hyper-link-ui/src/locale/en-US.ts b/packages/docs-hyper-link-ui/src/locale/en-US.ts
index c0e484b907..3baaefc32b 100644
--- a/packages/docs-hyper-link-ui/src/locale/en-US.ts
+++ b/packages/docs-hyper-link-ui/src/locale/en-US.ts
@@ -26,7 +26,7 @@ const enUS: typeof zhCN = {
placeholder: 'Please input a link url',
addressError: 'Url is illegal!',
label: 'Label',
- LabelError: 'Please input label of link',
+ labelError: 'Please input label of link',
},
info: {
copy: 'Copy',
diff --git a/packages/docs-hyper-link-ui/src/locale/ru-RU.ts b/packages/docs-hyper-link-ui/src/locale/ru-RU.ts
index ea26fd77f9..7544238fa0 100644
--- a/packages/docs-hyper-link-ui/src/locale/ru-RU.ts
+++ b/packages/docs-hyper-link-ui/src/locale/ru-RU.ts
@@ -24,7 +24,7 @@ const ruRU: typeof zhCN = {
title: 'Ссылка',
address: 'Cсылки',
label: 'Текст',
- LabelError: 'Введите текст ссылки',
+ labelError: 'Введите текст ссылки',
placeholder: 'Пожалуйста, введите URL ссылки',
addressError: 'URL некорректен!',
},
diff --git a/packages/docs-hyper-link-ui/src/locale/vi-VN.ts b/packages/docs-hyper-link-ui/src/locale/vi-VN.ts
index 03a5e7ca86..04f5641070 100644
--- a/packages/docs-hyper-link-ui/src/locale/vi-VN.ts
+++ b/packages/docs-hyper-link-ui/src/locale/vi-VN.ts
@@ -24,7 +24,7 @@ const locale: typeof zhCN = {
title: 'Liên kết',
address: 'Liên kết',
label: 'Nhãn',
- LabelError: 'Vui lòng nhập nhãn liên kết',
+ labelError: 'Vui lòng nhập nhãn liên kết',
placeholder: 'Vui lòng nhập liên kết hợp lệ',
addressError: 'Vui lòng nhập liên kết hợp lệ',
},
diff --git a/packages/docs-hyper-link-ui/src/locale/zh-CN.ts b/packages/docs-hyper-link-ui/src/locale/zh-CN.ts
index c71262ed97..605053ebb3 100644
--- a/packages/docs-hyper-link-ui/src/locale/zh-CN.ts
+++ b/packages/docs-hyper-link-ui/src/locale/zh-CN.ts
@@ -22,7 +22,7 @@ const zhCN = {
title: '链接',
address: '链接',
label: '文本',
- LabelError: '请输入链接文本',
+ labelError: '请输入链接文本',
placeholder: '请输入合法的链接',
addressError: '请输入合法的链接',
diff --git a/packages/docs-hyper-link-ui/src/locale/zh-TW.ts b/packages/docs-hyper-link-ui/src/locale/zh-TW.ts
index 30599512ce..d0d787e8da 100644
--- a/packages/docs-hyper-link-ui/src/locale/zh-TW.ts
+++ b/packages/docs-hyper-link-ui/src/locale/zh-TW.ts
@@ -24,7 +24,7 @@ const locale: typeof zhCN = {
title: '連結',
address: '連結',
label: '文本',
- LabelError: '请输入链接文本',
+ labelError: '请输入链接文本',
placeholder: '請輸入合法的連結',
addressError: '請輸入合法的連結',
},
diff --git a/packages/docs-hyper-link-ui/src/plugin.ts b/packages/docs-hyper-link-ui/src/plugin.ts
index bc67ec721a..a2c5f36cb7 100644
--- a/packages/docs-hyper-link-ui/src/plugin.ts
+++ b/packages/docs-hyper-link-ui/src/plugin.ts
@@ -16,16 +16,14 @@
import { DependentOn, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
-import { UniverDocsHyperLinkPlugin } from '@univerjs/docs-hyper-link';
import { IRenderManagerService } from '@univerjs/engine-render';
+import { UniverDocsHyperLinkPlugin } from '@univerjs/docs-hyper-link';
import { DOC_HYPER_LINK_UI_PLUGIN } from './types/const';
import type { IDocHyperLinkUIConfig } from './controllers/ui.controller';
import { DocHyperLinkUIController } from './controllers/ui.controller';
import { DocHyperLinkPopupService } from './services/hyper-link-popup.service';
import { DocHyperLinkSelectionController } from './controllers/doc-hyper-link-selection.controller';
import { DocHyperLinkRenderController } from './controllers/render-controllers/render.controller';
-import { DocHyperLinkClipboardController } from './controllers/doc-hyper-link-clipboard.controller';
-import { DocHyperLinkCustomRangeController } from './controllers/doc-hyper-link-custom-range.controller';
import { DocHyperLinkEventRenderController } from './controllers/render-controllers/hyper-link-event.render-controller';
@DependentOn(UniverDocsHyperLinkPlugin)
@@ -50,8 +48,6 @@ export class UniverDocsHyperLinkUIPlugin extends Plugin {
},
],
[DocHyperLinkSelectionController],
- [DocHyperLinkClipboardController],
- [DocHyperLinkCustomRangeController],
];
deps.forEach((dep) => {
diff --git a/packages/docs-hyper-link-ui/src/services/hyper-link-popup.service.ts b/packages/docs-hyper-link-ui/src/services/hyper-link-popup.service.ts
index 8545ce1718..f715bf5289 100644
--- a/packages/docs-hyper-link-ui/src/services/hyper-link-popup.service.ts
+++ b/packages/docs-hyper-link-ui/src/services/hyper-link-popup.service.ts
@@ -19,7 +19,6 @@ import { Disposable, Inject, IUniverInstanceService, UniverInstanceType } from '
import { TextSelectionManagerService } from '@univerjs/docs';
import { DocCanvasPopManagerService } from '@univerjs/docs-ui';
import { BehaviorSubject } from 'rxjs';
-import { DocHyperLinkModel } from '@univerjs/docs-hyper-link';
import { DocHyperLinkEdit } from '../views/hyper-link-edit';
import { DocLinkPopup } from '../views/hyper-link-popup';
@@ -47,7 +46,6 @@ export class DocHyperLinkPopupService extends Disposable {
constructor(
@Inject(DocCanvasPopManagerService) private readonly _docCanvasPopupManagerService: DocCanvasPopManagerService,
@Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
- @Inject(DocHyperLinkModel) private readonly _docHyperLinkModel: DocHyperLinkModel,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
) {
super();
@@ -124,9 +122,8 @@ export class DocHyperLinkPopupService extends Disposable {
if (this._infoPopup) {
this._infoPopup.dispose();
}
- const link = this._docHyperLinkModel.getLink(unitId, linkId);
const doc = this._univerInstanceService.getUnit<DocumentDataModel>(unitId, UniverInstanceType.UNIVER_DOC);
- if (!doc || !link) {
+ if (!doc) {
return;
}
const range = doc.getSelfOrHeaderFooterModel(info.segmentId).getBody()?.customRanges?.find((i) => i.rangeId === linkId);
@@ -145,7 +142,8 @@ export class DocHyperLinkPopupService extends Disposable {
},
{
componentKey: DocLinkPopup.componentKey,
- direction: 'top',
+ direction: 'top-center',
+ multipleDirection: 'top',
closeOnSelfTarget: true,
onClickOutside: () => {
this.hideInfoPopup();
diff --git a/packages/docs-hyper-link-ui/src/views/hyper-link-edit/index.tsx b/packages/docs-hyper-link-ui/src/views/hyper-link-edit/index.tsx
index 79f6f38adf..9b48711a52 100644
--- a/packages/docs-hyper-link-ui/src/views/hyper-link-edit/index.tsx
+++ b/packages/docs-hyper-link-ui/src/views/hyper-link-edit/index.tsx
@@ -17,7 +17,6 @@
import { Button, FormLayout, Input } from '@univerjs/design';
import React, { useEffect, useState } from 'react';
import { getBodySlice, ICommandService, IUniverInstanceService, LocaleService, Tools, UniverInstanceType, useDependency, useObservable } from '@univerjs/core';
-import { DocHyperLinkModel } from '@univerjs/docs-hyper-link';
import type { DocumentDataModel } from '@univerjs/core';
import { ITextSelectionRenderManager } from '@univerjs/engine-render';
import { getPlainTextFormBody, TextSelectionManagerService } from '@univerjs/docs';
@@ -44,7 +43,6 @@ function transformUrl(urlStr: string) {
export const DocHyperLinkEdit = () => {
const hyperLinkService = useDependency(DocHyperLinkPopupService);
const localeService = useDependency(LocaleService);
- const hyperLinkModel = useDependency(DocHyperLinkModel);
const editing = useObservable(hyperLinkService.editingLink$);
const commandService = useDependency(ICommandService);
const univerInstanceService = useDependency(IUniverInstanceService);
@@ -65,11 +63,10 @@ export const DocHyperLinkEdit = () => {
}
if (editing) {
- const linkDetail = editing ? hyperLinkModel.getLink(editing.unitId, editing.linkId) : null;
- setLink(linkDetail?.payload ?? '');
const body = doc?.getSelfOrHeaderFooterModel(editing.segmentId)?.getBody();
- const matchedRange = body?.customRanges?.find((i) => linkDetail?.id === i.rangeId);
+ const matchedRange = body?.customRanges?.find((i) => editing?.linkId === i.rangeId);
if (doc && matchedRange) {
+ setLink(matchedRange.properties?.url ?? '');
setLabel(getPlainTextFormBody(getBodySlice(body!, matchedRange.startIndex, matchedRange.endIndex)));
}
return;
@@ -77,10 +74,9 @@ export const DocHyperLinkEdit = () => {
const matchedRange = doc?.getSelfOrHeaderFooterModel(activeRange.segmentId)?.getBody()?.customRanges?.find((i) => Math.max(activeRange.startOffset, i.startIndex) <= Math.min(activeRange.endOffset - 1, i.endIndex));
if (doc && matchedRange) {
- const linkDetail = hyperLinkModel.getLink(doc.getUnitId(), matchedRange.rangeId);
- setLink(linkDetail?.payload ?? '');
+ setLink(matchedRange?.properties?.url ?? '');
}
- }, [doc, editing, hyperLinkModel, textSelectionManagerService, univerInstanceService]);
+ }, [doc, editing, textSelectionManagerService, univerInstanceService]);
useEffect(() => {
textSelectionRenderManager.blurEditor();
@@ -131,7 +127,7 @@ export const DocHyperLinkEdit = () => {
? (
<FormLayout
label={localeService.t('docLink.edit.label')}
- error={showError && !isLegal ? localeService.t('docLink.edit.labelError') : ''}
+ error={showError && !label ? localeService.t('docLink.edit.labelError') : ''}
>
<Input
value={label}
diff --git a/packages/docs-hyper-link-ui/src/views/hyper-link-popup/index.tsx b/packages/docs-hyper-link-ui/src/views/hyper-link-popup/index.tsx
index 406a57251b..56733d501d 100644
--- a/packages/docs-hyper-link-ui/src/views/hyper-link-popup/index.tsx
+++ b/packages/docs-hyper-link-ui/src/views/hyper-link-popup/index.tsx
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-import { ICommandService, LocaleService, useDependency } from '@univerjs/core';
+import type { DocumentDataModel } from '@univerjs/core';
+import { CustomRangeType, ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType, useDependency } from '@univerjs/core';
import React from 'react';
import { CopySingle, LinkSingle, UnlinkSingle, WriteSingle } from '@univerjs/icons';
import cs from 'clsx';
import { MessageType, Tooltip } from '@univerjs/design';
import { IMessageService, useObservable } from '@univerjs/ui';
-import { DocHyperLinkModel } from '@univerjs/docs-hyper-link';
import { DocHyperLinkPopupService } from '../../services/hyper-link-popup.service';
import { DeleteDocHyperLinkCommand } from '../../commands/commands/delete-link.command';
import { ShowDocHyperLinkEditPopupOperation } from '../../commands/operations/popup.operation';
@@ -28,21 +28,26 @@ import styles from './index.module.less';
export const DocLinkPopup = () => {
const hyperLinkService = useDependency(DocHyperLinkPopupService);
- const hyperLinkModel = useDependency(DocHyperLinkModel);
const commandService = useDependency(ICommandService);
const messageService = useDependency(IMessageService);
const localeService = useDependency(LocaleService);
const currentPopup = useObservable(hyperLinkService.showingLink$);
+ const univerInstanceService = useDependency(IUniverInstanceService);
if (!currentPopup) {
return null;
}
const { unitId, linkId, segmentId } = currentPopup;
- const link = hyperLinkModel.getLink(unitId, linkId);
+ const doc = univerInstanceService.getUnit<DocumentDataModel>(unitId, UniverInstanceType.UNIVER_DOC);
+ const body = doc?.getSelfOrHeaderFooterModel(segmentId).getBody();
+ const link = body?.customRanges?.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK);
+
if (!link) {
return null;
}
+ const url = link.properties?.url;
+
return (
<div
className={styles.docLink}
@@ -50,19 +55,19 @@ export const DocLinkPopup = () => {
hyperLinkService.hideInfoPopup();
}}
>
- <div className={cs(styles.docLinkContent)} onClick={() => window.open(link.payload)}>
+ <div className={cs(styles.docLinkContent)} onClick={() => window.open(url)}>
<div className={styles.docLinkType}>
<LinkSingle />
</div>
- <Tooltip showIfEllipsis title={link.payload}>
- <span className={styles.docLinkUrl}>{link.payload}</span>
+ <Tooltip showIfEllipsis title={url}>
+ <span className={styles.docLinkUrl}>{url}</span>
</Tooltip>
</div>
<div className={styles.docLinkOperations}>
<div
className={cs(styles.docLinkOperation)}
onClick={() => {
- navigator.clipboard.writeText(link.payload);
+ navigator.clipboard.writeText(url);
messageService.show({
content: localeService.t('docLink.info.coped'),
type: MessageType.Info,
@@ -91,7 +96,7 @@ export const DocLinkPopup = () => {
onClick={() => {
commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
unitId,
- linkId: link.id,
+ linkId: link.rangeId,
segmentId,
});
}}
diff --git a/packages/docs-hyper-link/README.md b/packages/docs-hyper-link/README.md
index dc5a3ccd16..ea6b280a2f 100644
--- a/packages/docs-hyper-link/README.md
+++ b/packages/docs-hyper-link/README.md
@@ -2,20 +2,28 @@
## Introduction
-`@univerjs/docs-hyper-link` provides the base link function of Univer Docs.
+`@univerjs/docs-hyper-link` provides the link function of Univer Docs.
## Usage
### Installation
```shell
-# Use npm
+# Using npm
npm install @univerjs/docs-hyper-link
-# Use pnpm
+# Using pnpm
pnpm add @univerjs/docs-hyper-link
```
+### Register the plugin
+
+```typescript
+import { UniverDocsHyperLinkUIPlugin} from '@univerjs/docs-hyper-link';
+
+univer.registerPlugin(UniverDocsHyperLinkUIPlugin);
+```
+
<!-- Links -->
[npm-version-shield]: https://img.shields.io/npm/v/@univerjs/docs-hyper-link?style=flat-square
[npm-version-link]: https://npmjs.com/package/@univerjs/docs-hyper-link
diff --git a/packages/docs-hyper-link/package.json b/packages/docs-hyper-link/package.json
index 93dc28a734..61a5a868b3 100644
--- a/packages/docs-hyper-link/package.json
+++ b/packages/docs-hyper-link/package.json
@@ -20,7 +20,8 @@
"keywords": [],
"exports": {
".": "./src/index.ts",
- "./*": "./src/*"
+ "./*": "./src/*",
+ "./locale/*": "./src/locale/*.ts"
},
"main": "./lib/cjs/index.js",
"module": "./lib/es/index.js",
@@ -40,7 +41,8 @@
"require": "./lib/cjs/*",
"types": "./lib/types/index.d.ts"
},
- "./lib/*": "./lib/*"
+ "./lib/*": "./lib/*",
+ "./locale/*": "./lib/locale/*.json"
}
},
"directories": {
@@ -58,13 +60,15 @@
},
"peerDependencies": {
"@univerjs/core": "workspace:*",
+ "@univerjs/docs": "workspace:*",
"rxjs": ">=7.0.0"
},
+ "dependencies": {
+ "@univerjs/icons": "^0.1.74"
+ },
"devDependencies": {
"@univerjs/core": "workspace:*",
- "@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
- "@univerjs/shared": "workspace:*",
"rxjs": "^7.8.1",
"typescript": "^5.5.4",
"vite": "^5.4.2",
@@ -81,6 +85,7 @@
"require": "./lib/cjs/*",
"types": "./lib/types/index.d.ts"
},
- "./lib/*": "./lib/*"
+ "./lib/*": "./lib/*",
+ "./locale/*": "./lib/locale/*.json"
}
}
diff --git a/packages/docs-hyper-link/src/commands/mutations/add-link.mutation.ts b/packages/docs-hyper-link/src/commands/mutations/add-link.mutation.ts
deleted file mode 100644
index 9bba6790f6..0000000000
--- a/packages/docs-hyper-link/src/commands/mutations/add-link.mutation.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { CommandType, type IMutation } from '@univerjs/core';
-import type { IDocHyperLink } from '../../types/interfaces/i-doc-hyper-link';
-import { DocHyperLinkModel } from '../../models/hyper-link.model';
-
-export interface IAddDocHyperLinkMutationParams {
- unitId: string;
- link: IDocHyperLink;
-}
-
-export const AddDocHyperLinkMutation: IMutation<IAddDocHyperLinkMutationParams> = {
- type: CommandType.MUTATION,
- id: 'docs.mutation.add-hyper-link',
- handler(accessor, params: IAddDocHyperLinkMutationParams) {
- if (!params) {
- return false;
- }
-
- const docHyperLinkModel = accessor.get(DocHyperLinkModel);
- return docHyperLinkModel.addLink(params.unitId, params.link);
- },
-};
diff --git a/packages/docs-hyper-link/src/commands/mutations/delete-link.mutation.ts b/packages/docs-hyper-link/src/commands/mutations/delete-link.mutation.ts
deleted file mode 100644
index 15a6c9ebec..0000000000
--- a/packages/docs-hyper-link/src/commands/mutations/delete-link.mutation.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { CommandType, type ICommand } from '@univerjs/core';
-import { DocHyperLinkModel } from '../../models/hyper-link.model';
-
-export interface IDeleteDocHyperLinkMutationParams {
- unitId: string;
- linkId: string;
-}
-
-export const DeleteDocHyperLinkMutation: ICommand<IDeleteDocHyperLinkMutationParams> = {
- type: CommandType.MUTATION,
- id: 'docs.mutation.delete-hyper-link',
- handler(accessor, params) {
- if (!params) {
- return false;
- }
- const docHyperLinkModel = accessor.get(DocHyperLinkModel);
- return docHyperLinkModel.deleteLink(params.unitId, params.linkId);
- },
-};
diff --git a/packages/docs-hyper-link/src/commands/mutations/update-link.mutation.ts b/packages/docs-hyper-link/src/commands/mutations/update-link.mutation.ts
deleted file mode 100644
index 349cf1f24e..0000000000
--- a/packages/docs-hyper-link/src/commands/mutations/update-link.mutation.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { CommandType, type ICommand } from '@univerjs/core';
-import { DocHyperLinkModel } from '../../models/hyper-link.model';
-
-export interface IUpdateDocHyperLinkMutationParams {
- unitId: string;
- linkId: string;
- payload: string;
-}
-
-export const UpdateDocHyperLinkMutation: ICommand<IUpdateDocHyperLinkMutationParams> = {
- type: CommandType.MUTATION,
- id: 'docs.mutation.update-hyper-link',
- handler(accessor, params) {
- if (!params) {
- return false;
- }
-
- const docHyperLinkModel = accessor.get(DocHyperLinkModel);
- return docHyperLinkModel.updateLink(params.unitId, params.linkId, params.payload);
- },
-};
diff --git a/packages/docs-hyper-link/src/controllers/hyper-link.controller.ts b/packages/docs-hyper-link/src/controllers/hyper-link.controller.ts
deleted file mode 100644
index 20525ef9d8..0000000000
--- a/packages/docs-hyper-link/src/controllers/hyper-link.controller.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
-import { AddDocHyperLinkMutation } from '../commands/mutations/add-link.mutation';
-import { UpdateDocHyperLinkMutation } from '../commands/mutations/update-link.mutation';
-import { DeleteDocHyperLinkMutation } from '../commands/mutations/delete-link.mutation';
-
-@OnLifecycle(LifecycleStages.Starting, DocHyperLinkController)
-export class DocHyperLinkController extends Disposable {
- constructor(
- @ICommandService private readonly _commandService: ICommandService
- ) {
- super();
-
- this._initCommands();
- }
-
- private _initCommands() {
- [
- AddDocHyperLinkMutation,
- UpdateDocHyperLinkMutation,
- DeleteDocHyperLinkMutation,
- ].forEach((command) => {
- this.disposeWithMe(this._commandService.registerCommand(command));
- });
- }
-}
diff --git a/packages/docs-hyper-link/src/controllers/resource.controller.ts b/packages/docs-hyper-link/src/controllers/resource.controller.ts
index f8f4850b55..6cd0c362b6 100644
--- a/packages/docs-hyper-link/src/controllers/resource.controller.ts
+++ b/packages/docs-hyper-link/src/controllers/resource.controller.ts
@@ -14,21 +14,19 @@
* limitations under the License.
*/
-import type { DocumentDataModel } from '@univerjs/core';
+import type { DocumentDataModel, ICustomRange } from '@univerjs/core';
import { CustomRangeType, Disposable, Inject, IResourceManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
-import { DOC_HYPER_LINK_PLUGIN } from '../types/const';
-import { DocHyperLinkModel } from '../models/hyper-link.model';
-import type { IDocHyperLink } from '../types/interfaces/i-doc-hyper-link';
+
+export const DOC_HYPER_LINK_PLUGIN = 'DOC_HYPER_LINK_PLUGIN';
interface IDocHyperLinkJSON {
- links: IDocHyperLink[];
+ links: { id: string; payload: string }[];
}
@OnLifecycle(LifecycleStages.Starting, DocHyperLinkResourceController)
export class DocHyperLinkResourceController extends Disposable {
constructor(
@Inject(IResourceManagerService) private readonly _resourceManagerService: IResourceManagerService,
- @Inject(DocHyperLinkModel) private readonly _docHyperLinkModel: DocHyperLinkModel,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
) {
super();
@@ -40,22 +38,64 @@ export class DocHyperLinkResourceController extends Disposable {
pluginName: DOC_HYPER_LINK_PLUGIN,
businesses: [UniverInstanceType.UNIVER_DOC],
onLoad: (unitID: string, resource: IDocHyperLinkJSON) => {
+ const doc = this._univerInstanceService.getUnit<DocumentDataModel>(unitID, UniverInstanceType.UNIVER_DOC);
+ if (!doc) {
+ return;
+ }
+
+ const customRangeMap = new Map<string, ICustomRange>();
+
+ const handleDoc = (model: DocumentDataModel) => {
+ model.getBody()?.customRanges?.forEach((customRange) => {
+ if (customRange.rangeType === CustomRangeType.HYPERLINK) {
+ customRangeMap.set(customRange.rangeId, customRange);
+ }
+ });
+ return customRangeMap;
+ };
+ doc.headerModelMap.forEach((headerModel) => {
+ handleDoc(headerModel);
+ });
+ doc.footerModelMap.forEach((footerModel) => {
+ handleDoc(footerModel);
+ });
+ handleDoc(doc);
+
resource.links.forEach((link) => {
- this._docHyperLinkModel.addLink(unitID, link);
+ const customRange = customRangeMap.get(link.id);
+ if (customRange) {
+ customRange.properties = {
+ ...customRange.properties,
+ url: link.payload,
+ };
+ }
});
},
- onUnLoad: (unitID: string) => {
- this._docHyperLinkModel.deleteUnit(unitID);
- },
+ onUnLoad: (unitID: string) => {},
toJson: (unitID: string) => {
- const links = this._docHyperLinkModel.getUnit(unitID);
const doc = this._univerInstanceService.getUnit<DocumentDataModel>(unitID, UniverInstanceType.UNIVER_DOC);
- const customRanges = doc?.getBody()?.customRanges;
- const set = new Set(customRanges?.filter((i) => i.rangeType === CustomRangeType.HYPERLINK).map((i) => i.rangeId));
+ const links: { id: string; payload: string }[] = [];
+ if (doc) {
+ const handleDoc = (model: DocumentDataModel) => {
+ model.getBody()?.customRanges?.forEach((customRange) => {
+ if (customRange.rangeType === CustomRangeType.HYPERLINK) {
+ links.push({
+ id: customRange.rangeId,
+ payload: customRange.properties?.url || '',
+ });
+ }
+ });
+ };
+ doc.headerModelMap.forEach((headerModel) => {
+ handleDoc(headerModel);
+ });
+ doc.footerModelMap.forEach((footerModel) => {
+ handleDoc(footerModel);
+ });
+ handleDoc(doc);
+ }
- return JSON.stringify({
- links: links.filter((link) => set.has(link.id)),
- });
+ return JSON.stringify({ links });
},
parseJson(bytes: string): IDocHyperLinkJSON {
return JSON.parse(bytes);
diff --git a/packages/docs-hyper-link/src/index.ts b/packages/docs-hyper-link/src/index.ts
index 5e93c857a5..c247ef1a8d 100644
--- a/packages/docs-hyper-link/src/index.ts
+++ b/packages/docs-hyper-link/src/index.ts
@@ -14,15 +14,4 @@
* limitations under the License.
*/
-export { DOC_HYPER_LINK_PLUGIN } from './types/const';
-export { DocHyperLinkModel } from './models/hyper-link.model';
-export type { IDocHyperLink } from './types/interfaces/i-doc-hyper-link';
-export { DocHyperLinkType } from './types/enums/doc-hyper-link-type';
export { UniverDocsHyperLinkPlugin } from './plugin';
-// #region - all commands
-
-export { AddDocHyperLinkMutation, type IAddDocHyperLinkMutationParams } from './commands/mutations/add-link.mutation';
-export { UpdateDocHyperLinkMutation, type IUpdateDocHyperLinkMutationParams } from './commands/mutations/update-link.mutation';
-export { DeleteDocHyperLinkMutation, type IDeleteDocHyperLinkMutationParams } from './commands/mutations/delete-link.mutation';
-
-// #endregion
diff --git a/packages/docs-hyper-link/src/models/hyper-link.model.ts b/packages/docs-hyper-link/src/models/hyper-link.model.ts
deleted file mode 100644
index 3751aacfff..0000000000
--- a/packages/docs-hyper-link/src/models/hyper-link.model.ts
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { Disposable, Tools } from '@univerjs/core';
-import { Subject } from 'rxjs';
-import type { IDocHyperLink } from '../types/interfaces/i-doc-hyper-link';
-
-export type DocLinkUpdate = {
- type: 'add';
- link: IDocHyperLink;
- unitId: string;
-} | {
- type: 'update';
- oldPayload: string;
- link: IDocHyperLink;
- unitId: string;
-} | {
- type: 'delete';
- link: IDocHyperLink;
- unitId: string;
-} | {
- type: 'delete-unit';
- unitId: string;
-};
-
-export class DocHyperLinkModel extends Disposable {
- private readonly _links = new Map<string, Map<string, IDocHyperLink>>();
- private readonly _linkUpdate$ = new Subject<DocLinkUpdate>();
-
- readonly linkUpdate$ = this._linkUpdate$.asObservable();
-
- constructor() {
- super();
-
- this.disposeWithMe(() => {
- this._linkUpdate$.complete();
- });
- }
-
- private _ensureMap(unitId: string) {
- let map = this._links.get(unitId);
-
- if (!map) {
- map = new Map();
- this._links.set(unitId, map);
- }
- return map;
- }
-
- addLink(unitId: string, link: IDocHyperLink) {
- const map = this._ensureMap(unitId);
- link.payload = Tools.normalizeUrl(link.payload);
- map.set(link.id, link);
-
- this._linkUpdate$.next({
- type: 'add',
- link,
- unitId,
- });
-
- return true;
- }
-
- updateLink(unitId: string, id: string, payload: string) {
- const map = this._ensureMap(unitId);
- const link = map.get(id);
- if (!link) {
- return false;
- }
- const oldPayload = link.payload;
- link.payload = payload;
- this._linkUpdate$.next({
- type: 'update',
- link,
- oldPayload,
- unitId,
- });
- return true;
- }
-
- deleteLink(unitId: string, id: string) {
- const map = this._ensureMap(unitId);
- const link = map.get(id);
-
- if (!link) {
- return true;
- }
-
- map.delete(id);
- this._linkUpdate$.next({
- type: 'delete',
- link,
- unitId,
- });
- return false;
- }
-
- getLink(unitId: string, linkId: string) {
- const map = this._ensureMap(unitId);
- return map.get(linkId);
- }
-
- getUnit(unitId: string) {
- const map = this._ensureMap(unitId);
-
- return Array.from(map.values());
- }
-
- deleteUnit(unitId: string) {
- this._links.delete(unitId);
- this._linkUpdate$.next({
- unitId,
- type: 'delete-unit',
- });
- }
-}
-
diff --git a/packages/docs-hyper-link/src/plugin.ts b/packages/docs-hyper-link/src/plugin.ts
index 07cfaa24c8..1a80edb864 100644
--- a/packages/docs-hyper-link/src/plugin.ts
+++ b/packages/docs-hyper-link/src/plugin.ts
@@ -16,10 +16,7 @@
import { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
-import { DOC_HYPER_LINK_PLUGIN } from './types/const';
-import { DocHyperLinkModel } from './models/hyper-link.model';
-import { DocHyperLinkController } from './controllers/hyper-link.controller';
-import { DocHyperLinkResourceController } from './controllers/resource.controller';
+import { DOC_HYPER_LINK_PLUGIN, DocHyperLinkResourceController } from './controllers/resource.controller';
export class UniverDocsHyperLinkPlugin extends Plugin {
static override pluginName = DOC_HYPER_LINK_PLUGIN;
@@ -34,8 +31,6 @@ export class UniverDocsHyperLinkPlugin extends Plugin {
override onStarting(): void {
const deps: Dependency[] = [
- [DocHyperLinkModel],
- [DocHyperLinkController],
[DocHyperLinkResourceController],
];
diff --git a/packages/docs-hyper-link/src/types/const/index.ts b/packages/docs-hyper-link/src/types/const/index.ts
deleted file mode 100644
index 8a76180850..0000000000
--- a/packages/docs-hyper-link/src/types/const/index.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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.
- */
-
-export const DOC_HYPER_LINK_PLUGIN = 'DOC_HYPER_LINK_PLUGIN';
diff --git a/packages/docs-hyper-link/src/types/enums/doc-hyper-link-type.ts b/packages/docs-hyper-link/src/types/enums/doc-hyper-link-type.ts
deleted file mode 100644
index c34640c7fc..0000000000
--- a/packages/docs-hyper-link/src/types/enums/doc-hyper-link-type.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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.
- */
-
-export enum DocHyperLinkType {
- URL,
-}
diff --git a/packages/docs-hyper-link/src/types/interfaces/i-doc-hyper-link.ts b/packages/docs-hyper-link/src/types/interfaces/i-doc-hyper-link.ts
deleted file mode 100644
index fac5d27e4d..0000000000
--- a/packages/docs-hyper-link/src/types/interfaces/i-doc-hyper-link.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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.
- */
-
-export interface IDocHyperLink {
- payload: string;
- id: string;
-}
diff --git a/packages/docs-mention-ui/package.json b/packages/docs-mention-ui/package.json
index bab1aa4f69..80293eacaf 100644
--- a/packages/docs-mention-ui/package.json
+++ b/packages/docs-mention-ui/package.json
@@ -65,7 +65,6 @@
"peerDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/docs": "workspace:*",
- "@univerjs/docs-mention": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/ui": "workspace:*",
@@ -78,7 +77,6 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
- "@univerjs/docs-mention": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/shared": "workspace:*",
diff --git a/packages/docs-mention/src/commands/commands/doc-mention.command.ts b/packages/docs-mention-ui/src/commands/commands/doc-mention.command.ts
similarity index 82%
rename from packages/docs-mention/src/commands/commands/doc-mention.command.ts
rename to packages/docs-mention-ui/src/commands/commands/doc-mention.command.ts
index 90f8a8ea87..ea4ad6ba2b 100644
--- a/packages/docs-mention/src/commands/commands/doc-mention.command.ts
+++ b/packages/docs-mention-ui/src/commands/commands/doc-mention.command.ts
@@ -15,11 +15,9 @@
*/
import type { ICommand, IDocumentBody } from '@univerjs/core';
-import { CommandType, CustomRangeType, DataStreamTreeTokenType, ICommandService, sequenceExecute } from '@univerjs/core';
+import { CommandType, CustomRangeType, DataStreamTreeTokenType, ICommandService } from '@univerjs/core';
import { deleteCustomRangeFactory, replaceSelectionFactory, TextSelectionManagerService } from '@univerjs/docs';
import type { IDocMention } from '../../types/interfaces/i-mention';
-import { AddDocMentionMutation } from '../mutations/doc-mention.mutation';
-import { DocMentionModel } from '../../models/doc-mention.model';
export interface IAddDocMentionCommandParams {
mention: IDocMention;
@@ -51,6 +49,9 @@ export const AddDocMentionCommand: ICommand<IAddDocMentionCommandParams> = {
rangeId: mention.id,
rangeType: CustomRangeType.MENTION,
wholeEntity: true,
+ properties: {
+ mention,
+ },
}],
};
@@ -68,18 +69,10 @@ export const AddDocMentionCommand: ICommand<IAddDocMentionCommandParams> = {
);
if (doMutation) {
- const commentMutation = {
- id: AddDocMentionMutation.id,
- params: {
- unitId,
- mention,
- },
- };
-
- return (await sequenceExecute([commentMutation, doMutation], commandService)).result;
+ return commandService.executeCommand(doMutation.id, doMutation.params);
}
- return true;
+ return false;
},
};
@@ -97,13 +90,8 @@ export const DeleteDocMentionCommand: ICommand<IDeleteDocMentionCommandParams> =
}
const { unitId, mentionId } = params;
const commandService = accessor.get(ICommandService);
- const docMentionModel = accessor.get(DocMentionModel);
- const mention = docMentionModel.getMention(unitId, mentionId);
- if (!mention) {
- return false;
- }
- const doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: mention.id });
+ const doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: mentionId });
if (!doMutation) {
return false;
}
diff --git a/packages/docs-mention-ui/src/commands/operations/mention-popup.operation.ts b/packages/docs-mention-ui/src/commands/operations/mention-popup.operation.ts
index 35c3c27337..6e0b5f701a 100644
--- a/packages/docs-mention-ui/src/commands/operations/mention-popup.operation.ts
+++ b/packages/docs-mention-ui/src/commands/operations/mention-popup.operation.ts
@@ -15,7 +15,7 @@
*/
import { CommandType, type ICommand } from '@univerjs/core';
-import { DocMentionService } from '@univerjs/docs-mention';
+import { DocMentionService } from '../../services/doc-mention.service';
export interface IShowMentionInfoPopupOperationParams {
unitId: string;
diff --git a/packages/docs-mention-ui/src/controllers/doc-mention-custom-range.controller.ts b/packages/docs-mention-ui/src/controllers/doc-mention-custom-range.controller.ts
deleted file mode 100644
index 4955ec1387..0000000000
--- a/packages/docs-mention-ui/src/controllers/doc-mention-custom-range.controller.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { CustomRangeType, Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';
-import { DocCustomRangeService } from '@univerjs/docs';
-import type { IAddDocMentionMutationParams } from '@univerjs/docs-mention';
-import { AddDocMentionMutation, DocMentionModel } from '@univerjs/docs-mention';
-
-@OnLifecycle(LifecycleStages.Ready, DocMentionCustomRangeController)
-export class DocMentionCustomRangeController extends Disposable {
- constructor(
- @Inject(DocCustomRangeService) private readonly _docCustomRangeService: DocCustomRangeService,
- @Inject(DocMentionModel) private readonly _docMentionModel: DocMentionModel,
- @ICommandService private readonly _commandService: ICommandService
- ) {
- super();
-
- this._initCustomRangeHooks();
- }
-
- private _initCustomRangeHooks() {
- this.disposeWithMe(
- this._docCustomRangeService.addClipboardHook({
- onCopyCustomRange: (unitId, range) => {
- const { rangeId, rangeType, data, ...ext } = range;
- if (rangeType === CustomRangeType.MENTION) {
- if (data) {
- const id = Tools.generateRandomId();
- this._docMentionModel.addMention(unitId, {
- id,
- ...JSON.parse(data),
- });
- return {
- ...range,
- rangeId: id,
- };
- }
- const mention = this._docMentionModel.copyMention(unitId, rangeId);
- this._commandService.executeCommand(
- AddDocMentionMutation.id,
- {
- unitId,
- mention,
- } as IAddDocMentionMutationParams
- );
- if (!mention) {
- return range;
- }
-
- return {
- ...ext,
- rangeId: mention.id,
- rangeType,
- };
- }
- return range;
- },
- })
- );
- }
-}
diff --git a/packages/docs-mention-ui/src/controllers/doc-mention-trigger.controller.ts b/packages/docs-mention-ui/src/controllers/doc-mention-trigger.controller.ts
index 1f8551f6d3..fcb4d215f3 100644
--- a/packages/docs-mention-ui/src/controllers/doc-mention-trigger.controller.ts
+++ b/packages/docs-mention-ui/src/controllers/doc-mention-trigger.controller.ts
@@ -17,9 +17,9 @@
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';
import type { IInsertCommandParams } from '@univerjs/docs';
import { DeleteLeftCommand, InsertCommand, MoveCursorOperation, TextSelectionManagerService } from '@univerjs/docs';
-import { DocMentionService } from '@univerjs/docs-mention';
import { DocMentionPopupService } from '../services/doc-mention-popup.service';
import { CloseMentionEditPopupOperation, ShowMentionEditPopupOperation } from '../commands/operations/mention-popup.operation';
+import { DocMentionService } from '../services/doc-mention.service';
@OnLifecycle(LifecycleStages.Rendered, DocMentionTriggerController)
export class DocMentionTriggerController extends Disposable {
diff --git a/packages/docs-mention-ui/src/controllers/doc-mention-ui.controller.ts b/packages/docs-mention-ui/src/controllers/doc-mention-ui.controller.ts
index 19add98d42..ddeea690c8 100644
--- a/packages/docs-mention-ui/src/controllers/doc-mention-ui.controller.ts
+++ b/packages/docs-mention-ui/src/controllers/doc-mention-ui.controller.ts
@@ -18,6 +18,7 @@ import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle } fro
import { ComponentManager } from '@univerjs/ui';
import { CloseMentionEditPopupOperation, CloseMentionInfoPopupOperation, ShowMentionEditPopupOperation, ShowMentionInfoPopupOperation } from '../commands/operations/mention-popup.operation';
import { MentionEditPopup } from '../views/mention-edit-popup';
+import { AddDocMentionCommand, DeleteDocMentionCommand } from '../commands/commands/doc-mention.command';
@OnLifecycle(LifecycleStages.Starting, DocMentionUIController)
export class DocMentionUIController extends Disposable {
@@ -37,6 +38,8 @@ export class DocMentionUIController extends Disposable {
CloseMentionInfoPopupOperation,
ShowMentionEditPopupOperation,
CloseMentionEditPopupOperation,
+ AddDocMentionCommand,
+ DeleteDocMentionCommand,
].forEach((operation) => {
this.disposeWithMe(this._commandService.registerCommand(operation));
});
diff --git a/packages/docs-mention-ui/src/plugin.ts b/packages/docs-mention-ui/src/plugin.ts
index f0a04e9e3a..c4a0d0578f 100644
--- a/packages/docs-mention-ui/src/plugin.ts
+++ b/packages/docs-mention-ui/src/plugin.ts
@@ -14,16 +14,14 @@
* limitations under the License.
*/
-import { DependentOn, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
+import { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
-import { UniverDocsMentionPlugin } from '@univerjs/docs-mention';
import { DOC_MENTION_UI_PLUGIN } from './types/const/const';
import { DocMentionPopupService } from './services/doc-mention-popup.service';
import { DocMentionUIController } from './controllers/doc-mention-ui.controller';
import { DocMentionTriggerController } from './controllers/doc-mention-trigger.controller';
-import { DocMentionCustomRangeController } from './controllers/doc-mention-custom-range.controller';
+import { DocMentionService } from './services/doc-mention.service';
-@DependentOn(UniverDocsMentionPlugin)
export class UniverDocsMentionUIPlugin extends Plugin {
static override pluginName = DOC_MENTION_UI_PLUGIN;
static override type = UniverInstanceType.UNIVER_DOC;
@@ -37,10 +35,10 @@ export class UniverDocsMentionUIPlugin extends Plugin {
override onStarting(): void {
const deps: Dependency[] = [
+ [DocMentionService],
[DocMentionPopupService],
[DocMentionUIController],
[DocMentionTriggerController],
- [DocMentionCustomRangeController],
];
deps.forEach((dep) => {
diff --git a/packages/docs-mention-ui/src/services/doc-mention-popup.service.ts b/packages/docs-mention-ui/src/services/doc-mention-popup.service.ts
index a4839d1deb..cfb6e302e3 100644
--- a/packages/docs-mention-ui/src/services/doc-mention-popup.service.ts
+++ b/packages/docs-mention-ui/src/services/doc-mention-popup.service.ts
@@ -18,8 +18,8 @@ import type { IDisposable, Nullable } from '@univerjs/core';
import { Disposable, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { DocCanvasPopManagerService } from '@univerjs/docs-ui';
import { BehaviorSubject } from 'rxjs';
-import { DocMentionService } from '@univerjs/docs-mention';
import { MentionEditPopup } from '../views/mention-edit-popup';
+import { DocMentionService } from './doc-mention.service';
@OnLifecycle(LifecycleStages.Rendered, DocMentionPopupService)
export class DocMentionPopupService extends Disposable {
diff --git a/packages/docs-mention/src/services/doc-mention.service.ts b/packages/docs-mention-ui/src/services/doc-mention.service.ts
similarity index 100%
rename from packages/docs-mention/src/services/doc-mention.service.ts
rename to packages/docs-mention-ui/src/services/doc-mention.service.ts
diff --git a/packages/docs-mention/src/types/enums/mention-type.ts b/packages/docs-mention-ui/src/types/enums/mention-type.ts
similarity index 100%
rename from packages/docs-mention/src/types/enums/mention-type.ts
rename to packages/docs-mention-ui/src/types/enums/mention-type.ts
diff --git a/packages/docs-mention/src/types/interfaces/i-mention.ts b/packages/docs-mention-ui/src/types/interfaces/i-mention.ts
similarity index 100%
rename from packages/docs-mention/src/types/interfaces/i-mention.ts
rename to packages/docs-mention-ui/src/types/interfaces/i-mention.ts
diff --git a/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsx b/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsx
index f379e9f3ef..2ef6015dce 100644
--- a/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsx
+++ b/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsx
@@ -15,11 +15,13 @@
*/
import { ICommandService, IUniverInstanceService, Tools, UniverInstanceType, useDependency, useObservable, UserManagerService } from '@univerjs/core';
-import { AddDocMentionCommand, type IMention, MentionType } from '@univerjs/docs-mention';
import React, { useEffect } from 'react';
import { ITextSelectionRenderManager } from '@univerjs/engine-render';
import { DocMentionPopupService } from '../../services/doc-mention-popup.service';
import { MentionList } from '../mention-list';
+import { AddDocMentionCommand } from '../../commands/commands/doc-mention.command';
+import { MentionType } from '../../types/enums/mention-type';
+import type { IMention } from '../../types/interfaces/i-mention';
export const MentionEditPopup = () => {
const popupService = useDependency(DocMentionPopupService);
diff --git a/packages/docs-mention-ui/src/views/mention-list/index.tsx b/packages/docs-mention-ui/src/views/mention-list/index.tsx
index 4b0f264e68..d916ce565e 100644
--- a/packages/docs-mention-ui/src/views/mention-list/index.tsx
+++ b/packages/docs-mention-ui/src/views/mention-list/index.tsx
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-import type { IMention } from '@univerjs/docs-mention';
import React, { useEffect, useRef, useState } from 'react';
import cs from 'clsx';
import { KeyCode } from '@univerjs/ui';
+import type { IMention } from '../../types/interfaces/i-mention';
import styles from './index.module.less';
export interface IMentionListProps {
diff --git a/packages/docs-mention/README.md b/packages/docs-mention/README.md
deleted file mode 100644
index 3a6dc1050f..0000000000
--- a/packages/docs-mention/README.md
+++ /dev/null
@@ -1,23 +0,0 @@
-# @univerjs/docs-mention
-
-## Introduction
-
-`@univerjs/docs-mention` package provides the Mention for Docs.
-
-## Usage
-
-### Installation
-
-```shell
-# Using npm
-npm install @univerjs/docs-mention
-
-# Using pnpm
-pnpm add @univerjs/docs-mention
-```
-
-<!-- Links -->
-[npm-version-shield]: https://img.shields.io/npm/v/@univerjs/docs-mention?style=flat-square
-[npm-version-link]: https://npmjs.com/package/@univerjs/docs-mention
-[npm-license-shield]: https://img.shields.io/npm/l/@univerjs/docs-mention?style=flat-square
-[npm-downloads-shield]: https://img.shields.io/npm/dm/@univerjs/docs-mention?style=flat-square
diff --git a/packages/docs-mention/package.json b/packages/docs-mention/package.json
deleted file mode 100644
index 27f75571ba..0000000000
--- a/packages/docs-mention/package.json
+++ /dev/null
@@ -1,94 +0,0 @@
-{
- "name": "@univerjs/docs-mention",
- "version": "0.2.11",
- "private": true,
- "description": "Univer normal ui-plugin-docs",
- "author": "DreamNum <[email protected]>",
- "license": "Apache-2.0",
- "funding": {
- "type": "opencollective",
- "url": "https://opencollective.com/univer"
- },
- "homepage": "https://univer.ai",
- "repository": {
- "type": "git",
- "url": "https://github.com/dream-num/univer"
- },
- "bugs": {
- "url": "https://github.com/dream-num/univer/issues"
- },
- "keywords": [
- "univer"
- ],
- "sideEffects": [
- "**/*.css"
- ],
- "exports": {
- ".": "./src/index.ts",
- "./*": "./src/*"
- },
- "main": "./lib/cjs/index.js",
- "module": "./lib/es/index.js",
- "types": "./lib/types/index.d.ts",
- "publishConfig": {
- "access": "public",
- "main": "./lib/cjs/index.js",
- "module": "./lib/es/index.js",
- "exports": {
- ".": {
- "import": "./lib/es/index.js",
- "require": "./lib/cjs/index.js",
- "types": "./lib/types/index.d.ts"
- },
- "./*": {
- "import": "./lib/es/*",
- "require": "./lib/cjs/*",
- "types": "./lib/types/index.d.ts"
- },
- "./lib/*": "./lib/*"
- }
- },
- "directories": {
- "lib": "lib"
- },
- "files": [
- "lib"
- ],
- "scripts": {
- "test": "vitest run",
- "test:watch": "vitest",
- "coverage": "vitest run --coverage",
- "lint:types": "tsc --noEmit",
- "build": "tsc && vite build",
- "sync:cnpm": "cnpm sync"
- },
- "peerDependencies": {
- "@univerjs/core": "workspace:*",
- "@univerjs/docs": "workspace:*",
- "rxjs": ">=7.0.0"
- },
- "devDependencies": {
- "@types/react": "^18.3.4",
- "@univerjs/core": "workspace:*",
- "@univerjs/docs": "workspace:*",
- "@univerjs/engine-render": "workspace:*",
- "@univerjs/shared": "workspace:*",
- "rxjs": "^7.8.1",
- "typescript": "^5.5.4",
- "vite": "^5.4.2",
- "vitest": "^2.0.5"
- },
- "univerSpace": {
- ".": {
- "import": "./lib/es/index.js",
- "require": "./lib/cjs/index.js",
- "types": "./lib/types/index.d.ts"
- },
- "./*": {
- "import": "./lib/es/*",
- "require": "./lib/cjs/*",
- "types": "./lib/types/index.d.ts"
- },
- "./lib/*": "./lib/*"
- }
-}
diff --git a/packages/docs-mention/src/commands/mutations/doc-mention.mutation.ts b/packages/docs-mention/src/commands/mutations/doc-mention.mutation.ts
deleted file mode 100644
index 16c2c5eb51..0000000000
--- a/packages/docs-mention/src/commands/mutations/doc-mention.mutation.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { CommandType, type ICommand } from '@univerjs/core';
-import { DocMentionModel } from '../../models/doc-mention.model';
-import type { IDocMention } from '../../types/interfaces/i-mention';
-
-export interface IAddDocMentionMutationParams {
- unitId: string;
- mention: IDocMention;
-}
-
-export const AddDocMentionMutation: ICommand<IAddDocMentionMutationParams> = {
- id: 'docs.mutation.add-doc-mention',
- type: CommandType.MUTATION,
- handler(accessor, params) {
- if (!params) {
- return false;
- }
- const { unitId, mention } = params;
- const docMentionModel = accessor.get(DocMentionModel);
- docMentionModel.addMention(unitId, mention);
- return true;
- },
-};
-
-export interface IDeleteDocMentionMutationParams {
- unitId: string;
- id: string;
-}
-
-export const DeleteDocMentionMutation: ICommand<IDeleteDocMentionMutationParams> = {
- id: 'docs.mutation.delete-doc-mention',
- type: CommandType.MUTATION,
- handler(accessor, params) {
- if (!params) {
- return false;
- }
- const { unitId, id } = params;
- const docMentionModel = accessor.get(DocMentionModel);
- docMentionModel.deleteMention(unitId, id);
- return true;
- },
-};
diff --git a/packages/docs-mention/src/controllers/doc-mention-resource.controller.ts b/packages/docs-mention/src/controllers/doc-mention-resource.controller.ts
deleted file mode 100644
index ecfd8473ff..0000000000
--- a/packages/docs-mention/src/controllers/doc-mention-resource.controller.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { DocumentDataModel } from '@univerjs/core';
-import { CustomRangeType, Disposable, Inject, IResourceManagerService, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
-import { DOC_MENTION_PLUGIN } from '../types/const/const';
-import type { IDocMention } from '../types/interfaces/i-mention';
-import { DocMentionModel } from '../models/doc-mention.model';
-
-interface IDocMentionJSON {
- mentions: IDocMention[];
-}
-
-@OnLifecycle(LifecycleStages.Starting, DocMentionResourceController)
-export class DocMentionResourceController extends Disposable {
- constructor(
- @Inject(IResourceManagerService) private readonly _resourceManagerService: IResourceManagerService,
- @Inject(DocMentionModel) private readonly _docMentionModel: DocMentionModel,
- @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
- ) {
- super();
- this._init();
- }
-
- private _init() {
- this._resourceManagerService.registerPluginResource({
- pluginName: DOC_MENTION_PLUGIN,
- businesses: [UniverInstanceType.UNIVER_DOC],
- onLoad: (unitID: string, resource: IDocMentionJSON) => {
- resource.mentions.forEach((mention) => {
- this._docMentionModel.addMention(unitID, mention);
- });
- },
- onUnLoad: (unitID: string) => {
- this._docMentionModel.deleteUnit(unitID);
- },
- toJson: (unitID: string) => {
- const mentions = this._docMentionModel.getUnit(unitID);
- const doc = this._univerInstanceService.getUnit<DocumentDataModel>(unitID, UniverInstanceType.UNIVER_DOC);
- const customRanges = doc?.getBody()?.customRanges;
- const set = new Set(customRanges?.filter((i) => i.rangeType === CustomRangeType.MENTION).map((i) => i.rangeId));
-
- return JSON.stringify({
- mentions: mentions.filter((mention) => set.has(mention.id)),
- });
- },
- parseJson(bytes: string): IDocMentionJSON {
- return JSON.parse(bytes);
- },
- });
- }
-}
diff --git a/packages/docs-mention/src/controllers/doc-mention.controller.ts b/packages/docs-mention/src/controllers/doc-mention.controller.ts
deleted file mode 100644
index c61256861f..0000000000
--- a/packages/docs-mention/src/controllers/doc-mention.controller.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
-import { AddDocMentionMutation, DeleteDocMentionMutation } from '../commands/mutations/doc-mention.mutation';
-import { AddDocMentionCommand, DeleteDocMentionCommand } from '../commands/commands/doc-mention.command';
-
-@OnLifecycle(LifecycleStages.Starting, DocMentionController)
-export class DocMentionController extends Disposable {
- constructor(
- @ICommandService private readonly _commandService: ICommandService
- ) {
- super();
-
- this._initCommands();
- }
-
- private _initCommands() {
- [
- AddDocMentionMutation,
- DeleteDocMentionMutation,
- AddDocMentionCommand,
- DeleteDocMentionCommand,
- ].forEach((command) => {
- this.disposeWithMe(this._commandService.registerCommand(command));
- });
- }
-}
diff --git a/packages/docs-mention/src/index.ts b/packages/docs-mention/src/index.ts
deleted file mode 100644
index ef782b45ec..0000000000
--- a/packages/docs-mention/src/index.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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.
- */
-
-export { DocMentionModel } from './models/doc-mention.model';
-export { DocMentionService } from './services/doc-mention.service';
-export { DOC_MENTION_PLUGIN } from './types/const/const';
-export type { IMention, IDocMention } from './types/interfaces/i-mention';
-export { MentionType } from './types/enums/mention-type';
-export { UniverDocsMentionPlugin } from './plugin';
-
-// #region - all commands
-export { AddDocMentionMutation, DeleteDocMentionMutation } from './commands/mutations/doc-mention.mutation';
-export type { IAddDocMentionMutationParams, IDeleteDocMentionMutationParams } from './commands/mutations/doc-mention.mutation';
-export { AddDocMentionCommand, DeleteDocMentionCommand } from './commands/commands/doc-mention.command';
-export type { IAddDocMentionCommandParams, IDeleteDocMentionCommandParams } from './commands/commands/doc-mention.command';
-// #endregion
diff --git a/packages/docs-mention/src/models/doc-mention.model.ts b/packages/docs-mention/src/models/doc-mention.model.ts
deleted file mode 100644
index cae1185ff1..0000000000
--- a/packages/docs-mention/src/models/doc-mention.model.ts
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { Disposable, Tools } from '@univerjs/core';
-import type { IDocMention } from '../types/interfaces/i-mention';
-
-export class DocMentionModel extends Disposable {
- private _mentionMaps = new Map<string, Map<string, IDocMention>>();
-
- private _ensureMap(unitId: string) {
- let unitMap = this._mentionMaps.get(unitId);
-
- if (!unitMap) {
- unitMap = new Map();
- this._mentionMaps.set(unitId, unitMap);
- }
-
- return unitMap;
- }
-
- addMention(unitId: string, mention: IDocMention) {
- const map = this._ensureMap(unitId);
- map.set(mention.id, mention);
- }
-
- getMention(unitId: string, id: string) {
- const map = this._ensureMap(unitId);
- return map.get(id);
- }
-
- copyMention(unitId: string, id: string) {
- const mention = this.getMention(unitId, id);
-
- if (!mention) {
- return undefined;
- }
-
- const newId = Tools.generateRandomId();
- const newMention = { ...mention, id: newId };
- return newMention;
- }
-
- deleteMention(unitId: string, id: string) {
- const map = this._ensureMap(unitId);
- return map.delete(id);
- }
-
- getUnit(unitId: string) {
- const map = this._mentionMaps.get(unitId);
- return Array.from(map?.values() ?? []);
- }
-
- deleteUnit(unitId: string) {
- this._mentionMaps.delete(unitId);
- }
-}
diff --git a/packages/docs-mention/src/plugin.ts b/packages/docs-mention/src/plugin.ts
deleted file mode 100644
index d52f5c53c7..0000000000
--- a/packages/docs-mention/src/plugin.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
-import type { Dependency } from '@univerjs/core';
-import { DOC_MENTION_PLUGIN } from './types/const/const';
-import { DocMentionModel } from './models/doc-mention.model';
-import { DocMentionController } from './controllers/doc-mention.controller';
-import { DocMentionService } from './services/doc-mention.service';
-import { DocMentionResourceController } from './controllers/doc-mention-resource.controller';
-
-export class UniverDocsMentionPlugin extends Plugin {
- static override pluginName = DOC_MENTION_PLUGIN;
- static override type = UniverInstanceType.UNIVER_DOC;
-
- constructor(
- private _config: unknown,
- @Inject(Injector) protected override _injector: Injector
- ) {
- super();
- }
-
- override onStarting(): void {
- const deps: Dependency[] = [
- [DocMentionModel],
- [DocMentionService],
- [DocMentionController],
- [DocMentionResourceController],
- ];
-
- deps.forEach((dep) => {
- this._injector.add(dep);
- });
- }
-}
diff --git a/packages/docs-mention/src/types/const/const.ts b/packages/docs-mention/src/types/const/const.ts
deleted file mode 100644
index f413ca8adc..0000000000
--- a/packages/docs-mention/src/types/const/const.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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.
- */
-
-export const DOC_MENTION_PLUGIN = 'DOC_MENTION_PLUGIN';
diff --git a/packages/docs-mention/src/vite-env.d.ts b/packages/docs-mention/src/vite-env.d.ts
deleted file mode 100644
index 11f02fe2a0..0000000000
--- a/packages/docs-mention/src/vite-env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-/// <reference types="vite/client" />
diff --git a/packages/docs-mention/tsconfig.json b/packages/docs-mention/tsconfig.json
deleted file mode 100644
index d676ad2a20..0000000000
--- a/packages/docs-mention/tsconfig.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "extends": "@univerjs/shared/tsconfigs/base",
- "compilerOptions": {
- "rootDir": "src",
- "outDir": "lib/types"
- },
- "references": [{ "path": "./tsconfig.node.json" }],
- "include": ["src"]
-}
diff --git a/packages/docs-mention/tsconfig.node.json b/packages/docs-mention/tsconfig.node.json
deleted file mode 100644
index e53dac8868..0000000000
--- a/packages/docs-mention/tsconfig.node.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "extends": "@univerjs/shared/tsconfigs/node",
- "include": ["vite.config.ts"]
-}
diff --git a/packages/docs-mention/vite.config.ts b/packages/docs-mention/vite.config.ts
deleted file mode 100644
index d6d74d882a..0000000000
--- a/packages/docs-mention/vite.config.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import createViteConfig from '@univerjs/shared/vite';
-import pkg from './package.json';
-
-export default ({ mode }) => createViteConfig({
-}, {
- mode,
- pkg,
- features: {
- react: true,
- css: true,
- dom: true,
- },
-});
diff --git a/packages/docs-ui/src/services/clipboard/clipboard.service.ts b/packages/docs-ui/src/services/clipboard/clipboard.service.ts
index b92a748dca..5489e5a4c2 100644
--- a/packages/docs-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/docs-ui/src/services/clipboard/clipboard.service.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import type { DocumentDataModel, ICustomRange, IDisposable, IDocumentBody, IDocumentData, IParagraph, Nullable } from '@univerjs/core';
-import { createIdentifier, CustomRangeType, DataStreamTreeTokenType, Disposable, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, getBodySlice, ICommandService, ILogService, Inject, IUniverInstanceService, normalizeBody, SliceBodyType, toDisposable, Tools, UniverInstanceType } from '@univerjs/core';
+import type { ICustomRange, IDisposable, IDocumentBody, IDocumentData, IParagraph, Nullable } from '@univerjs/core';
+import { createIdentifier, CustomRangeType, DataStreamTreeTokenType, Disposable, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, generateRandomId, getBodySlice, ICommandService, ILogService, Inject, IUniverInstanceService, normalizeBody, SliceBodyType, toDisposable, Tools, UniverInstanceType } from '@univerjs/core';
import { HTML_CLIPBOARD_MIME_TYPE, IClipboardInterfaceService, PLAIN_TEXT_CLIPBOARD_MIME_TYPE } from '@univerjs/ui';
-import { CutContentCommand, DocCustomRangeService, getCursorWhenDelete, getDeleteSelection, InnerPasteCommand, TextSelectionManagerService } from '@univerjs/docs';
+import { copyCustomRange, CutContentCommand, getCursorWhenDelete, getDeleteSelection, InnerPasteCommand, TextSelectionManagerService } from '@univerjs/docs';
import type { RectRange, TextRange } from '@univerjs/engine-render';
import { DOC_RANGE_TYPE } from '@univerjs/engine-render';
import { copyContentCache, extractId, genId } from './copy-content-cache';
@@ -93,8 +93,7 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
@ILogService private readonly _logService: ILogService,
@ICommandService private readonly _commandService: ICommandService,
@IClipboardInterfaceService private readonly _clipboardInterfaceService: IClipboardInterfaceService,
- @Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
- @Inject(DocCustomRangeService) private readonly _docCustomRangeService: DocCustomRangeService
+ @Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService
) {
super();
}
@@ -220,7 +219,9 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
body = hook.onBeforePaste(body);
}
});
- body.customRanges = body.customRanges?.map((range) => this._docCustomRangeService.copyCustomRange(unitId, range));
+
+ // copy custom ranges
+ body.customRanges = body.customRanges?.map(copyCustomRange);
const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle();
const { segmentId, endOffset: activeEndOffset, style } = activeRange || {};
@@ -323,7 +324,6 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
});
}
- // eslint-disable-next-line max-lines-per-function
private _getDocumentBodyInRanges(sliceType: SliceBodyType): Nullable<{
bodyList: IDocumentBody[];
needCache: boolean;
@@ -379,26 +379,6 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
continue;
}
- // TODO: @zhangwei, should be delete?
- if (docBody.customRanges) {
- const deleteRange: ICustomRange[] = [];
- docBody.customRanges.forEach((range) => {
- // should be delete
- if (range.startIndex === range.endIndex) {
- deleteRange.push(range);
- }
- });
- docBody.customRanges = docBody.customRanges.filter((range) => deleteRange.indexOf(range) === -1);
- let text = '';
- let cursor = 0;
- deleteRange.forEach((range) => {
- text += docBody.dataStream.slice(cursor, range.endIndex);
- cursor = range.endIndex + 1;
- });
- text += docBody.dataStream.slice(cursor, docBody.dataStream.length);
- docBody.dataStream = text;
- }
-
results.push(docBody);
}
@@ -437,19 +417,17 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
const dataStream = text.replace(/\n/g, '\r');
if (!text.includes('\r') && Tools.isLegalUrl(text)) {
- const id = Tools.generateRandomId();
- const docDataModel = this._univerInstanceService.getCurrentUnitForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)!;
+ const id = generateRandomId();
const urlText = `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${dataStream}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`;
- const range = this._docCustomRangeService.copyCustomRange(
- docDataModel.getUnitId(),
- {
- startIndex: 0,
- endIndex: urlText.length - 1,
- rangeId: id,
- rangeType: CustomRangeType.HYPERLINK,
- data: text,
- }
- );
+ const range: ICustomRange = {
+ startIndex: 0,
+ endIndex: urlText.length - 1,
+ rangeId: id,
+ rangeType: CustomRangeType.HYPERLINK,
+ properties: {
+ url: text,
+ },
+ };
return {
dataStream: urlText,
diff --git a/packages/docs-ui/src/services/clipboard/html-to-udm/converter.ts b/packages/docs-ui/src/services/clipboard/html-to-udm/converter.ts
index 01efe1dd28..9d69df8ce3 100644
--- a/packages/docs-ui/src/services/clipboard/html-to-udm/converter.ts
+++ b/packages/docs-ui/src/services/clipboard/html-to-udm/converter.ts
@@ -15,7 +15,7 @@
*/
import type { IDocumentBody, IDocumentData, ITable, ITextStyle, Nullable } from '@univerjs/core';
-import { CustomRangeType, DataStreamTreeTokenType, skipParseTagNames, Tools } from '@univerjs/core';
+import { CustomRangeType, DataStreamTreeTokenType, generateRandomId, skipParseTagNames, Tools } from '@univerjs/core';
import { genTableSource, getEmptyTableCell, getEmptyTableRow, getTableColumn } from '@univerjs/docs';
import { extractNodeStyle } from './parse-node-style';
@@ -109,29 +109,9 @@ export class HtmlToUDMService {
}
// TODO: @JOCS, More characters need to be replaced, like `\b`
- let text = node.nodeValue?.replace(/[\r\n]/g, '');
+ const text = node.nodeValue?.replace(/[\r\n]/g, '');
let style;
- if (parent && parent.nodeType === Node.ELEMENT_NODE) {
- if ((parent as Element).tagName.toUpperCase() === 'A') {
- const id = Tools.generateRandomId();
- text = `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${text}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`;
- body.customRanges = [
- ...(body.customRanges ?? []),
- {
- startIndex: body.dataStream.length,
- endIndex: body.dataStream.length + text.length - 1,
- rangeId: id,
- rangeType: CustomRangeType.HYPERLINK,
- },
- ];
- body.payloads = {
- ...body.payloads,
- [id]: (parent as HTMLAnchorElement).href,
- };
- }
- }
-
if (parent && this._styleCache.has(parent)) {
style = this._styleCache.get(parent);
}
@@ -148,6 +128,9 @@ export class HtmlToUDMService {
} else if (skipParseTagNames.includes(node.nodeName.toLowerCase())) {
continue;
} else if (node.nodeType === Node.ELEMENT_NODE) {
+ const element = node as HTMLElement;
+ const linkStart = this._processBeforeLink(element, doc);
+
const parentStyles = parent ? this._styleCache.get(parent) : {};
const styleRule = this._styleRules.find(({ filter }) => matchFilter(node as HTMLElement, filter));
const nodeStyles = styleRule
@@ -171,6 +154,7 @@ export class HtmlToUDMService {
if (afterProcessRule) {
afterProcessRule.handler(doc, node as HTMLElement);
}
+ this._processAfterLink(element, doc, linkStart);
}
}
}
@@ -298,4 +282,32 @@ export class HtmlToUDMService {
}
}
}
+
+ private _processBeforeLink(node: HTMLElement, doc: Partial<IDocumentData>) {
+ const body = doc.body!;
+ const element = node as HTMLElement;
+ const start = body.dataStream.length;
+ if (element.tagName.toUpperCase() === 'A') {
+ body.dataStream += DataStreamTreeTokenType.CUSTOM_RANGE_START;
+ }
+
+ return start;
+ }
+
+ private _processAfterLink(node: HTMLElement, doc: Partial<IDocumentData>, start: number) {
+ const body = doc.body!;
+ const element = node as HTMLElement;
+
+ if (element.tagName.toUpperCase() === 'A') {
+ body.dataStream += DataStreamTreeTokenType.CUSTOM_RANGE_END;
+ body.customRanges = body.customRanges ?? [];
+ body.customRanges.push({
+ startIndex: start,
+ endIndex: body.dataStream.length - 1,
+ rangeId: element.dataset.rangeid ?? generateRandomId(),
+ rangeType: CustomRangeType.HYPERLINK,
+ properties: { url: (element as HTMLAnchorElement).href },
+ });
+ }
+ }
}
diff --git a/packages/docs-ui/src/services/clipboard/udm-to-html/convertor.ts b/packages/docs-ui/src/services/clipboard/udm-to-html/convertor.ts
index c15ea824dd..5c0eb9327e 100644
--- a/packages/docs-ui/src/services/clipboard/udm-to-html/convertor.ts
+++ b/packages/docs-ui/src/services/clipboard/udm-to-html/convertor.ts
@@ -15,7 +15,7 @@
*/
import type { IDocumentBody, IParagraph, ITextRun } from '@univerjs/core';
-import { BaselineOffset, BooleanNumber, DataStreamTreeNodeType, Tools } from '@univerjs/core';
+import { BaselineOffset, BooleanNumber, CustomRangeType, DataStreamTreeNodeType, Tools } from '@univerjs/core';
import type { DataStreamTreeNode } from '@univerjs/engine-render';
import { parseDataStreamToTree } from '@univerjs/engine-render';
@@ -81,8 +81,9 @@ export function covertTextRunToHtml(dataStream: string, textRun: ITextRun): stri
return style.length ? `<span style="${style.join('; ')};">${html}</span>` : html;
}
-export function getBodySliceHtml(body: IDocumentBody, startIndex: number, endIndex: number) {
+function getBodyInlineSlice(body: IDocumentBody, startIndex: number, endIndex: number) {
const { dataStream, textRuns = [] } = body;
+
let cursorIndex = startIndex;
const spanList: string[] = [];
@@ -115,6 +116,35 @@ export function getBodySliceHtml(body: IDocumentBody, startIndex: number, endInd
return spanList.join('');
}
+export function getBodySliceHtml(body: IDocumentBody, startIndex: number, endIndex: number) {
+ const { customRanges = [] } = body;
+ const customRangesInRange = customRanges.filter((range) => range.startIndex >= startIndex && range.endIndex <= endIndex);
+
+ let cursorIndex = startIndex;
+ let html = '';
+ customRangesInRange.forEach((range) => {
+ const { startIndex, endIndex, rangeType, rangeId } = range;
+ const preHtml = getBodyInlineSlice(body, cursorIndex, startIndex);
+ html += preHtml;
+ const sliceHtml = getBodyInlineSlice(body, startIndex + 1, endIndex);
+ switch (rangeType) {
+ case CustomRangeType.HYPERLINK: {
+ html += `<a data-rangeid="${rangeId}" href="${range.properties?.url ?? ''}">${sliceHtml}</a>`;
+ break;
+ }
+
+ default: {
+ html += sliceHtml;
+ break;
+ }
+ }
+ cursorIndex = endIndex + 1;
+ });
+ const endHtml = getBodyInlineSlice(body, cursorIndex, endIndex);
+ html += endHtml;
+ return html;
+}
+
interface IHtmlResult {
html: string;
}
diff --git a/packages/docs-ui/src/services/doc-event-manager.service.ts b/packages/docs-ui/src/services/doc-event-manager.service.ts
index f57de41bdb..479eb73037 100644
--- a/packages/docs-ui/src/services/doc-event-manager.service.ts
+++ b/packages/docs-ui/src/services/doc-event-manager.service.ts
@@ -19,7 +19,7 @@ import { Disposable, fromEventSubject, Inject } from '@univerjs/core';
import { DocSkeletonManagerService } from '@univerjs/docs';
import type { Documents, DocumentSkeleton, IBoundRectNoAngle, IDocumentSkeletonGlyph, IMouseEvent, IPointerEvent, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { CURSOR_TYPE, getLineBounding, NodePositionConvertToCursor, TRANSFORM_CHANGE_OBSERVABLE_TYPE } from '@univerjs/engine-render';
-import { animationFrameScheduler, distinctUntilChanged, filter, map, mergeMap, Subject, take, throttleTime } from 'rxjs';
+import { distinctUntilChanged, filter, map, mergeMap, Subject, take, throttleTime } from 'rxjs';
import { transformOffset2Bound } from './doc-popup-manager.service';
interface ICustomRangeBound {
@@ -173,7 +173,7 @@ export class DocEventManagerService extends Disposable implements IRenderModule
}
private _initEvents() {
- this.disposeWithMe(fromEventSubject(this._context.scene.onPointerMove$).pipe(throttleTime(0, animationFrameScheduler)).subscribe((evt) => {
+ this.disposeWithMe(fromEventSubject(this._context.scene.onPointerMove$).pipe(throttleTime(30)).subscribe((evt) => {
this._hoverCustomRanges$.next(
this._calcActiveRanges(evt)
);
diff --git a/packages/docs-ui/src/services/doc-popup-manager.service.ts b/packages/docs-ui/src/services/doc-popup-manager.service.ts
index da7849ebd9..60e9b24552 100644
--- a/packages/docs-ui/src/services/doc-popup-manager.service.ts
+++ b/packages/docs-ui/src/services/doc-popup-manager.service.ts
@@ -82,6 +82,7 @@ export function transformOffset2Bound(offsetX: number, offsetY: number, scene: S
export interface IDocCanvasPopup extends Pick<IPopup, 'direction' | 'excludeOutside' | 'closeOnSelfTarget' | 'componentKey' | 'offset' | 'onClickOutside' | 'hideOnInvisible'> {
mask?: boolean;
extraProps?: Record<string, any>;
+ multipleDirection?: IPopup['direction'];
}
export const calcDocRangePositions = (range: ITextRangeParam, currentRender: IRender): IBoundRectNoAngle[] | undefined => {
@@ -258,7 +259,7 @@ export class DocCanvasPopManagerService extends Disposable {
attachPopupToRange(range: ITextRangeParam, popup: IDocCanvasPopup): IDisposable {
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)!;
const unitId = workbook.getUnitId();
- const { direction = 'top' } = popup;
+ const { direction = 'top', multipleDirection } = popup;
const currentRender = this._renderManagerService.getRenderById(unitId);
if (!currentRender) {
return {
@@ -269,16 +270,19 @@ export class DocCanvasPopManagerService extends Disposable {
}
const { positions: bounds, positions$: bounds$, disposable } = this._createRangePositionObserver(range, currentRender);
- const position$ = bounds$.pipe(map((bounds) => direction === 'top' ? bounds[0] : bounds[bounds.length - 1]));
+ const position$ = bounds$.pipe(map((bounds) => direction.includes('top') ? bounds[0] : bounds[bounds.length - 1]));
const id = this._globalPopupManagerService.addPopup({
...popup,
unitId,
subUnitId: 'default',
- anchorRect: direction === 'top' ? bounds[0] : bounds[bounds.length - 1],
+ anchorRect: direction.includes('top') ? bounds[0] : bounds[bounds.length - 1],
anchorRect$: position$,
excludeRects: bounds,
excludeRects$: bounds$,
- direction: direction === 'top' ? 'top' : 'bottom',
+ direction:
+ (direction.includes('top') || direction.includes('bottom')) ?
+ bounds.length > 1 ? multipleDirection : direction
+ : 'bottom',
canvasElement: currentRender.engine.getCanvasElement(),
});
diff --git a/packages/docs/src/basics/custom-range-factory.ts b/packages/docs/src/basics/custom-range-factory.ts
index 673c8e58f4..2b63a5abf9 100644
--- a/packages/docs/src/basics/custom-range-factory.ts
+++ b/packages/docs/src/basics/custom-range-factory.ts
@@ -87,7 +87,14 @@ function addCustomRangeTextX(param: IAddCustomRangeParam, body: IDocumentBody) {
return textX;
}
-export function addCustomRangeFactory(param: IAddCustomRangeParam, body: IDocumentBody) {
+export function addCustomRangeFactory(accessor: IAccessor, param: IAddCustomRangeParam, body: IDocumentBody) {
+ const { unitId, segmentId } = param;
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const documentDataModel = univerInstanceService.getUnit<DocumentDataModel>(unitId);
+ if (!documentDataModel) {
+ return false;
+ }
+
const doMutation: IMutationInfo<IRichTextEditingMutationParams> = {
id: RichTextEditingMutation.id,
params: {
@@ -101,7 +108,9 @@ export function addCustomRangeFactory(param: IAddCustomRangeParam, body: IDocume
if (!textX) {
return false;
}
- doMutation.params.actions = jsonX.editOp(textX.serialize());
+
+ const path = getRichTextEditPath(documentDataModel, segmentId);
+ doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
return doMutation;
}
@@ -109,11 +118,12 @@ interface IAddCustomRangeFactoryParam {
rangeId: string;
rangeType: CustomRangeType;
wholeEntity?: boolean;
+ properties?: Record<string, any>;
}
// eslint-disable-next-line max-lines-per-function
export function addCustomRangeBySelectionFactory(accessor: IAccessor, param: IAddCustomRangeFactoryParam) {
- const { rangeId, rangeType, wholeEntity } = param;
+ const { rangeId, rangeType, wholeEntity, properties } = param;
const textSelectionManagerService = accessor.get(TextSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -217,6 +227,7 @@ export function addCustomRangeBySelectionFactory(accessor: IAccessor, param: IAd
startIndex: -(range.endOffset - range.startOffset - deletes.length + 1),
endIndex: 0,
wholeEntity,
+ properties,
},
],
},
diff --git a/packages/docs/src/basics/custom-range.ts b/packages/docs/src/basics/custom-range.ts
index 74d2932988..bbd0aeb34d 100644
--- a/packages/docs/src/basics/custom-range.ts
+++ b/packages/docs/src/basics/custom-range.ts
@@ -15,7 +15,7 @@
*/
import type { ICustomRange, ITextRange } from '@univerjs/core';
-import { DataStreamTreeTokenType } from '@univerjs/core';
+import { DataStreamTreeTokenType, generateRandomId, Tools } from '@univerjs/core';
export function isCustomRangeSplitSymbol(text: string) {
return text === DataStreamTreeTokenType.CUSTOM_RANGE_END || text === DataStreamTreeTokenType.CUSTOM_RANGE_START;
@@ -71,3 +71,10 @@ export function getCustomRangesInterestsWithRange(range: ITextRange, customRange
return result;
}
+
+export function copyCustomRange(range: ICustomRange) {
+ return {
+ ...Tools.deepClone(range),
+ rangeId: generateRandomId(),
+ };
+}
diff --git a/packages/docs/src/commands/commands/break-line.command.ts b/packages/docs/src/commands/commands/break-line.command.ts
index db623921fa..bae4a7fc20 100644
--- a/packages/docs/src/commands/commands/break-line.command.ts
+++ b/packages/docs/src/commands/commands/break-line.command.ts
@@ -16,10 +16,9 @@
import type { ICommand, IParagraph } from '@univerjs/core';
import { BooleanNumber, CommandType, DataStreamTreeTokenType, getBodySlice, ICommandService, IUniverInstanceService, normalizeBody, PresetListType, Tools, updateAttributeByInsert } from '@univerjs/core';
-
import { TextSelectionManagerService } from '../../services/text-selection-manager.service';
import { getInsertSelection } from '../../basics/selection';
-import { DocCustomRangeService } from '../../services/doc-custom-range.service';
+import { copyCustomRange } from '../../basics/custom-range';
import { InsertCommand } from './core-editing.command';
export function generateParagraphs(dataStream: string, prevParagraph?: IParagraph): IParagraph[] {
@@ -65,11 +64,11 @@ export function generateParagraphs(dataStream: string, prevParagraph?: IParagrap
export const BreakLineCommand: ICommand = {
id: 'doc.command.break-line',
type: CommandType.COMMAND,
+
handler: async (accessor) => {
const textSelectionManagerService = accessor.get(TextSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
- const customRangeService = accessor.get(DocCustomRangeService);
const activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle();
const rectRanges = textSelectionManagerService.getCurrentRectRanges();
@@ -103,8 +102,7 @@ export const BreakLineCommand: ICommand = {
// line breaks to 2
if (prevParagraph && prevParagraph.startIndex > endOffset) {
const bodyAfter = normalizeBody(getBodySlice(body, endOffset, prevParagraph.startIndex + 1));
-
- bodyAfter.customRanges = bodyAfter.customRanges?.map((range) => customRangeService.copyCustomRange(unitId, range));
+ bodyAfter.customRanges = bodyAfter.customRanges?.map(copyCustomRange);
const deleteRange = {
startOffset,
diff --git a/packages/docs/src/commands/commands/delete.command.ts b/packages/docs/src/commands/commands/delete.command.ts
index d753a4ca71..e4606aa6a2 100644
--- a/packages/docs/src/commands/commands/delete.command.ts
+++ b/packages/docs/src/commands/commands/delete.command.ts
@@ -18,6 +18,7 @@ import type { IAccessor, ICommand, ICustomBlock, IDocumentBody, IMutationInfo, I
import {
CommandType,
DataStreamTreeTokenType,
+ generateRandomId,
getCustomDecorationSlice,
getCustomRangeSlice,
ICommandService,
@@ -26,6 +27,7 @@ import {
PositionedObjectLayoutType,
TextX,
TextXActionType,
+ Tools,
UpdateDocsAttributeType,
} from '@univerjs/core';
import type { IActiveTextRange, ITextRangeWithStyle, RectRange, TextRange } from '@univerjs/engine-render';
@@ -37,7 +39,6 @@ import type { IRichTextEditingMutationParams } from '../mutations/core-editing.m
import { RichTextEditingMutation } from '../mutations/core-editing.mutation';
import { getDeleteSelection } from '../../basics/selection';
import { getCommandSkeleton, getRichTextEditPath } from '../util';
-import { DocCustomRangeService } from '../../services/doc-custom-range.service';
import { DeleteDirection } from '../../types/enums/delete-direction';
import { CutContentCommand } from './clipboard.inner.command';
import { DeleteCommand, UpdateCommand } from './core-editing.command';
@@ -661,11 +662,13 @@ function getParagraphBody(
): IDocumentBody {
const { textRuns: originTextRuns = [], customBlocks: originCustomBlocks = [] } = body;
const dataStream = body.dataStream.substring(start, end);
- const customRangeService = accessor.get(DocCustomRangeService);
const bodySlice: IDocumentBody = {
dataStream,
- customRanges: getCustomRangeSlice(body, start, end).customRanges.map((range) => customRangeService.copyCustomRange(unitId, range)),
+ customRanges: getCustomRangeSlice(body, start, end).customRanges.map((range) => ({
+ ...Tools.deepClone(range),
+ rangeId: generateRandomId(),
+ })),
customDecorations: getCustomDecorationSlice(body, start, end),
};
diff --git a/packages/docs/src/doc-plugin.ts b/packages/docs/src/doc-plugin.ts
index 774467fe39..b308143694 100644
--- a/packages/docs/src/doc-plugin.ts
+++ b/packages/docs/src/doc-plugin.ts
@@ -56,7 +56,6 @@ import { IMEInputManagerService } from './services/ime-input-manager.service';
import { TextSelectionManagerService } from './services/text-selection-manager.service';
import { DocStateChangeManagerService } from './services/doc-state-change-manager.service';
import { AlignCenterCommand, AlignJustifyCommand, AlignLeftCommand, AlignOperationCommand, AlignRightCommand } from './commands/commands/paragraph-align.command';
-import { DocCustomRangeService } from './services/doc-custom-range.service';
import { DocCustomRangeController } from './controllers/custom-range.controller';
import { DocsRenameMutation } from './commands/mutations/docs-rename.mutation';
import { DocAutoFormatService } from './services/doc-auto-format.service';
@@ -166,7 +165,6 @@ export class UniverDocsPlugin extends Plugin {
},
],
[TextSelectionManagerService],
- [DocCustomRangeService],
[DocAutoFormatService],
// controllers
diff --git a/packages/docs/src/index.ts b/packages/docs/src/index.ts
index e3169236f5..dd09cb99ff 100644
--- a/packages/docs/src/index.ts
+++ b/packages/docs/src/index.ts
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-export { getCustomRangesInterestsWithRange } from './basics/custom-range';
export { getParagraphsInRange, getParagraphsInRanges, findNearestSectionBreak } from './commands/commands/list.command';
export { replaceSelectionFactory } from './basics/replace';
export { makeSelection, getSelectionText, getDeleteSelection, getInsertSelection, isSegmentIntersects } from './basics/selection';
@@ -28,7 +27,6 @@ export { DocSkeletonManagerService } from './services/doc-skeleton-manager.servi
export { TextSelectionManagerService, serializeDocRange } from './services/text-selection-manager.service';
export { DocStateChangeManagerService, type IDocStateChangeParams } from './services/doc-state-change-manager.service';
export { IMEInputManagerService } from './services/ime-input-manager.service';
-export { DocCustomRangeService, type ICustomRangeHook } from './services/doc-custom-range.service';
// #region - all commands
@@ -99,6 +97,7 @@ export { getRichTextEditPath } from './commands/util';
export { getPlainTextFormDocument, getPlainTextFormBody } from './basics/plain-text';
export { addCustomRangeFactory, addCustomRangeBySelectionFactory, deleteCustomRangeFactory } from './basics/custom-range-factory';
export { addCustomDecorationBySelectionFactory, addCustomDecorationFactory, deleteCustomDecorationFactory } from './basics/custom-decoration-factory';
+export { getCustomRangesInterestsWithRange, copyCustomRange } from './basics/custom-range';
export { DocInterceptorService } from './services/doc-interceptor/doc-interceptor.service';
export { DOC_INTERCEPTOR_POINT } from './services/doc-interceptor/interceptor-const';
export { DocAutoFormatService } from './services/doc-auto-format.service';
diff --git a/packages/docs/src/services/doc-custom-range.service.ts b/packages/docs/src/services/doc-custom-range.service.ts
deleted file mode 100644
index 97a5f63768..0000000000
--- a/packages/docs/src/services/doc-custom-range.service.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * 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 { ICustomRange, IDisposable } from '@univerjs/core';
-import { toDisposable } from '@univerjs/core';
-
-export interface ICustomRangeData extends ICustomRange {
- data?: string;
-}
-
-export interface ICustomRangeHook {
- onCopyCustomRange?: (unitId: string, range: ICustomRangeData) => ICustomRange;
-}
-
-export class DocCustomRangeService {
- private _customRangeHooks: ICustomRangeHook[] = [];
-
- addClipboardHook(hook: ICustomRangeHook): IDisposable {
- this._customRangeHooks.push(hook);
-
- return toDisposable(() => {
- const index = this._customRangeHooks.indexOf(hook);
-
- if (index > -1) {
- this._customRangeHooks.splice(index, 1);
- }
- });
- }
-
- copyCustomRange(unitId: string, range: ICustomRangeData) {
- let copy = { ...range };
-
- this._customRangeHooks.forEach((hook) => {
- if (hook.onCopyCustomRange) {
- copy = hook.onCopyCustomRange(unitId, copy);
- }
- });
-
- return copy;
- }
-}
diff --git a/packages/facade/src/apis/docs/f-document.ts b/packages/facade/src/apis/docs/f-document.ts
index d47a2883bd..369e2dab33 100644
--- a/packages/facade/src/apis/docs/f-document.ts
+++ b/packages/facade/src/apis/docs/f-document.ts
@@ -17,9 +17,11 @@
import type { DocumentDataModel, IDocumentData } from '@univerjs/core';
import {
ICommandService,
+ IResourceManagerService,
IUniverInstanceService,
RedoCommand,
UndoCommand,
+ UniverInstanceType,
} from '@univerjs/core';
import { InsertCommand } from '@univerjs/docs';
@@ -29,7 +31,8 @@ export class FDocument {
constructor(
private readonly _documentDataModel: DocumentDataModel,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
- @ICommandService private readonly _commandService: ICommandService
+ @ICommandService private readonly _commandService: ICommandService,
+ @IResourceManagerService private readonly _resourceManagerService: IResourceManagerService
) {
this.id = this._documentDataModel.getUnitId();
}
@@ -43,7 +46,10 @@ export class FDocument {
}
getSnapshot(): IDocumentData {
- return this._documentDataModel.getSnapshot() as IDocumentData;
+ const resources = this._resourceManagerService.getResourcesByType(this.id, UniverInstanceType.UNIVER_DOC);
+ const snapshot = this._documentDataModel.getSnapshot() as IDocumentData;
+ snapshot.resources = resources;
+ return snapshot;
}
undo(): Promise<boolean> {
diff --git a/packages/sheets-hyper-link-ui/package.json b/packages/sheets-hyper-link-ui/package.json
index 482c9a7bfd..d279006243 100644
--- a/packages/sheets-hyper-link-ui/package.json
+++ b/packages/sheets-hyper-link-ui/package.json
@@ -68,7 +68,6 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
- "@univerjs/docs-hyper-link": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/sheets": "workspace:*",
@@ -86,7 +85,6 @@
"devDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/docs": "workspace:*",
- "@univerjs/docs-hyper-link": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/shared": "workspace:*",
diff --git a/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts
index eabcb820f8..2e8b982b3f 100644
--- a/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts
+++ b/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts
@@ -20,7 +20,6 @@ import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
import { ClearSelectionAllCommand, ClearSelectionContentCommand, ClearSelectionFormatCommand, getSheetCommandTarget, SetRangeValuesCommand, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';
import { AddHyperLinkMutation, HyperLinkModel, RemoveHyperLinkMutation } from '@univerjs/sheets-hyper-link';
import { IEditorBridgeService } from '@univerjs/sheets-ui';
-import { DOC_HYPER_LINK_PLUGIN } from '@univerjs/docs-hyper-link';
import { getPlainTextFormDocument } from '@univerjs/docs';
import { isLegalLink, serializeUrl } from '../common/util';
import type { IAddHyperLinkCommandParams } from '../commands/commands/add-hyper-link.command';
@@ -280,10 +279,8 @@ export class SheetHyperLinkSetRangeController extends Disposable {
handler: (data, context, next) => {
if (data?.p) {
const range = data.p.body?.customRanges?.find((i) => i.rangeType === CustomRangeType.HYPERLINK);
- const resource = data.p.resources?.find((i) => i.name === DOC_HYPER_LINK_PLUGIN);
- if (range && resource) {
- const rangeId = range.rangeId;
- const url = JSON.parse(resource.data)?.links?.find((i: { id: string; payload: string }) => i.id === rangeId)?.payload;
+ if (range) {
+ const url = range.properties?.url;
return next({
...data,
diff --git a/packages/umd/package.json b/packages/umd/package.json
index 020c23bd24..ea8832304c 100644
--- a/packages/umd/package.json
+++ b/packages/umd/package.json
@@ -44,8 +44,6 @@
"@univerjs/docs": "workspace:*",
"@univerjs/docs-drawing": "workspace:*",
"@univerjs/docs-drawing-ui": "workspace:*",
- "@univerjs/docs-hyper-link": "workspace:*",
- "@univerjs/docs-hyper-link-ui": "workspace:*",
"@univerjs/docs-thread-comment-ui": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/drawing": "workspace:*",
diff --git a/packages/umd/scripts/index.mjs b/packages/umd/scripts/index.mjs
index 6d6089d3d2..3ebd1e26f9 100644
--- a/packages/umd/scripts/index.mjs
+++ b/packages/umd/scripts/index.mjs
@@ -229,7 +229,6 @@ function buildJS() {
'@univerjs/sheets-drawing-ui',
'@univerjs/docs-drawing',
'@univerjs/docs-drawing-ui',
- '@univerjs/docs-hyper-link',
'@univerjs/docs-hyper-link-ui',
'@univerjs/slides',
'@univerjs/slides-ui',
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 5c3941ae83..ec77b1951f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -216,9 +216,6 @@ importers:
'@univerjs/docs-drawing-ui':
specifier: workspace:*
version: link:../packages/docs-drawing-ui
- '@univerjs/docs-hyper-link':
- specifier: workspace:*
- version: link:../packages/docs-hyper-link
'@univerjs/docs-hyper-link-ui':
specifier: workspace:*
version: link:../packages/docs-hyper-link-ui
@@ -1075,19 +1072,17 @@ importers:
packages/docs-hyper-link:
+ dependencies:
+ '@univerjs/icons':
+ specifier: ^0.1.74
devDependencies:
'@univerjs/core':
specifier: workspace:*
version: link:../core
- '@univerjs/design':
- specifier: workspace:*
- version: link:../design
'@univerjs/docs':
specifier: workspace:*
version: link:../docs
- '@univerjs/shared':
- specifier: workspace:*
- version: link:../../common/shared
rxjs:
specifier: ^7.8.1
version: 7.8.1
@@ -1150,36 +1145,6 @@ importers:
specifier: ^2.0.5
- packages/docs-mention:
- devDependencies:
- '@types/react':
- specifier: ^18.3.4
- version: 18.3.4
- '@univerjs/core':
- specifier: workspace:*
- version: link:../core
- '@univerjs/docs':
- specifier: workspace:*
- version: link:../docs
- '@univerjs/engine-render':
- specifier: workspace:*
- version: link:../engine-render
- '@univerjs/shared':
- specifier: workspace:*
- version: link:../../common/shared
- rxjs:
- specifier: ^7.8.1
- version: 7.8.1
- typescript:
- specifier: ^5.5.4
- version: 5.5.4
- vite:
- specifier: ^5.4.2
- vitest:
- specifier: ^2.0.5
-
packages/docs-mention-ui:
devDependencies:
'@types/react':
@@ -1194,9 +1159,6 @@ importers:
'@univerjs/docs':
specifier: workspace:*
version: link:../docs
- '@univerjs/docs-mention':
- specifier: workspace:*
- version: link:../docs-mention
'@univerjs/docs-ui':
specifier: workspace:*
version: link:../docs-ui
@@ -2280,9 +2242,6 @@ importers:
'@univerjs/docs':
specifier: workspace:*
version: link:../docs
- '@univerjs/docs-hyper-link':
- specifier: workspace:*
- version: link:../docs-hyper-link
'@univerjs/engine-formula':
specifier: workspace:*
version: link:../engine-formula
@@ -2924,12 +2883,6 @@ importers:
'@univerjs/docs-drawing-ui':
specifier: workspace:*
version: link:../docs-drawing-ui
- '@univerjs/docs-hyper-link':
- specifier: workspace:*
- version: link:../docs-hyper-link
- '@univerjs/docs-hyper-link-ui':
- specifier: workspace:*
- version: link:../docs-hyper-link-ui
'@univerjs/docs-thread-comment-ui':
specifier: workspace:*
version: link:../docs-thread-comment-ui
@@ -4688,7 +4641,7 @@ packages:
resolution: {integrity: sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==}
'@protobufjs/[email protected]':
- resolution: {integrity: sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==}
+ resolution: {integrity: sha1-upn7WYYUr2VwDBYZ/wbUVLDYTEU=}
'@protobufjs/[email protected]':
resolution: {integrity: sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==}