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.

refactor(docs): move editor service to docs-ui (#3486)

Ran Luoae8c940f0b5f
diff --git a/.vscode/settings.json b/.vscode/settings.json
index f57c667140..f59da133a6 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -19,6 +19,7 @@
"compositionend",
"compositionstart",
"compositionupdate",
+ "consts",
"COUNTA",
"CRDT",
"customd",
diff --git a/packages-experimental/debugger/package.json b/packages-experimental/debugger/package.json
index 0dc6640664..3312c0eeed 100644
--- a/packages-experimental/debugger/package.json
+++ b/packages-experimental/debugger/package.json
@@ -57,6 +57,7 @@
"peerDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
+ "@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-drawing-ui": "workspace:*",
@@ -66,6 +67,7 @@
},
"dependencies": {
"@univerjs/core": "workspace:*",
+ "@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/facade": "workspace:*",
"@univerjs/sheets": "workspace:*",
diff --git a/packages-experimental/debugger/src/commands/operations/sidebar.operation.ts b/packages-experimental/debugger/src/commands/operations/sidebar.operation.ts
index 7634d51d6c..57ce3d6e61 100644
--- a/packages-experimental/debugger/src/commands/operations/sidebar.operation.ts
+++ b/packages-experimental/debugger/src/commands/operations/sidebar.operation.ts
@@ -15,7 +15,8 @@
*/
import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
-import { IEditorService, ISidebarService } from '@univerjs/ui';
+import { IEditorService } from '@univerjs/docs-ui';
+import { ISidebarService } from '@univerjs/ui';
import type { IAccessor, ICommand, Workbook } from '@univerjs/core';
import { TEST_EDITOR_CONTAINER_COMPONENT } from '../../views/test-editor/component-name';
diff --git a/packages-experimental/debugger/src/views/test-editor/TestTextEditor.tsx b/packages-experimental/debugger/src/views/test-editor/TestTextEditor.tsx
index 4d5b0eadec..84ddf5974d 100644
--- a/packages-experimental/debugger/src/views/test-editor/TestTextEditor.tsx
+++ b/packages-experimental/debugger/src/views/test-editor/TestTextEditor.tsx
@@ -17,7 +17,7 @@
import { createInternalEditorID, IUniverInstanceService, UniverInstanceType, useDependency } from '@univerjs/core';
import { Input } from '@univerjs/design';
-import { RangeSelector, TextEditor } from '@univerjs/ui';
+import { RangeSelector, TextEditor } from '@univerjs/docs-ui';
import React, { useState } from 'react';
import type { Workbook } from '@univerjs/core';
diff --git a/packages-experimental/uni-formula-ui/src/controllers/doc-formula-input.controller.ts b/packages-experimental/uni-formula-ui/src/controllers/doc-formula-input.controller.ts
index 535868e245..aefdb0e997 100644
--- a/packages-experimental/uni-formula-ui/src/controllers/doc-formula-input.controller.ts
+++ b/packages-experimental/uni-formula-ui/src/controllers/doc-formula-input.controller.ts
@@ -16,9 +16,8 @@
import { CustomRangeType, Disposable, ICommandService, ILogService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
-import { DeleteLeftCommand, DocEventManagerService, InsertCommand, MoveCursorOperation } from '@univerjs/docs-ui';
+import { DeleteLeftCommand, DocEventManagerService, IEditorService, InsertCommand, MoveCursorOperation } from '@univerjs/docs-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
-import { IEditorService } from '@univerjs/ui';
import { filter, map, mergeMap } from 'rxjs';
import type { DocumentDataModel } from '@univerjs/core';
@@ -67,7 +66,7 @@ export class DocUniFormulaInputController extends Disposable {
const { id } = commandInfo;
if (
- currentEditor?.editorUnitId === UNI_FORMULA_EDITOR_ID ||
+ currentEditor?.getEditorId() === UNI_FORMULA_EDITOR_ID ||
focusedUnit?.type !== UniverInstanceType.UNIVER_DOC
) {
return;
diff --git a/packages-experimental/uni-formula-ui/src/controllers/slide-formula-input.controller.ts b/packages-experimental/uni-formula-ui/src/controllers/slide-formula-input.controller.ts
index 84b4363160..d0a52cedd2 100644
--- a/packages-experimental/uni-formula-ui/src/controllers/slide-formula-input.controller.ts
+++ b/packages-experimental/uni-formula-ui/src/controllers/slide-formula-input.controller.ts
@@ -16,9 +16,8 @@
import { Disposable, ICommandService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
-import { InsertCommand } from '@univerjs/docs-ui';
+import { IEditorService, InsertCommand } from '@univerjs/docs-ui';
import { ISlideEditorBridgeService } from '@univerjs/slides-ui';
-import { IEditorService } from '@univerjs/ui';
import type { IInsertCommandParams } from '@univerjs/docs-ui';
import { AddSlideUniFormulaCommand } from '../commands/commands/slide.command';
import { CloseFormulaPopupOperation, ShowFormulaPopupOperation } from '../commands/operations/operation';
@@ -58,7 +57,7 @@ export class SlideUniFormulaInputController extends Disposable {
const { id } = commandInfo;
if (
- currentEditor?.editorUnitId === UNI_FORMULA_EDITOR_ID ||
+ currentEditor?.getEditorId() === UNI_FORMULA_EDITOR_ID ||
focusedUnit?.type !== UniverInstanceType.UNIVER_SLIDE
) {
return;
diff --git a/packages-experimental/uni-formula-ui/src/views/components/DocFormulaPopup.tsx b/packages-experimental/uni-formula-ui/src/views/components/DocFormulaPopup.tsx
index b8047f0c1f..18a72b9f86 100644
--- a/packages-experimental/uni-formula-ui/src/views/components/DocFormulaPopup.tsx
+++ b/packages-experimental/uni-formula-ui/src/views/components/DocFormulaPopup.tsx
@@ -14,17 +14,18 @@
* limitations under the License.
*/
-import React, { useCallback, useEffect, useRef, useState } from 'react';
-import clsx from 'clsx';
-import { TextEditor, useObservable } from '@univerjs/ui';
-import type { IDocumentData, Nullable } from '@univerjs/core';
import { BooleanNumber, createInternalEditorID, DEFAULT_EMPTY_DOCUMENT_VALUE, DocumentFlavor, HorizontalAlign, ICommandService, LocaleService, useDependency, VerticalAlign, WrapStrategy } from '@univerjs/core';
+import { TextEditor } from '@univerjs/docs-ui';
import { CheckMarkSingle, CloseSingle } from '@univerjs/icons';
-import type { IUniFormulaPopupInfo } from '../../services/formula-popup.service';
-import { DOC_FORMULA_POPUP_KEY, UniFormulaPopupService } from '../../services/formula-popup.service';
-
+import { useObservable } from '@univerjs/ui';
+import clsx from 'clsx';
+import React, { useCallback, useEffect, useRef, useState } from 'react';
+import type { IDocumentData, Nullable } from '@univerjs/core';
import { CloseFormulaPopupOperation, ConfirmFormulaPopupCommand } from '../../commands/operations/operation';
+
+import { DOC_FORMULA_POPUP_KEY, UniFormulaPopupService } from '../../services/formula-popup.service';
import styles from './index.module.less';
+import type { IUniFormulaPopupInfo } from '../../services/formula-popup.service';
export const UNI_FORMULA_EDITOR_ID = createInternalEditorID('UNI_FORMULA');
diff --git a/packages-experimental/uniui/src/plugin.ts b/packages-experimental/uniui/src/plugin.ts
index 32f6278851..7dae6cfd0a 100644
--- a/packages-experimental/uniui/src/plugin.ts
+++ b/packages-experimental/uniui/src/plugin.ts
@@ -15,9 +15,8 @@
*/
import { DependentOn, IContextService, ILocalStorageService, Inject, Injector, mergeOverrideWithDependencies, Plugin, Tools } from '@univerjs/core';
+import { EditorService, IEditorService, IRangeSelectorService, RangeSelectorService } from '@univerjs/docs-ui';
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
-import type { Dependency } from '@univerjs/core';
-import type { IUniverUIConfig } from '@univerjs/ui';
import {
BrowserClipboardService,
CanvasFloatDomService,
@@ -35,7 +34,6 @@ import {
DesktopSidebarService,
DesktopZenZoneService,
DISABLE_AUTO_FOCUS_KEY,
- EditorService,
ErrorController,
IBeforeCloseService,
ICanvasPopupService,
@@ -43,7 +41,6 @@ import {
IConfirmService,
IContextMenuService,
IDialogService,
- IEditorService,
IGlobalZoneService,
ILayoutService,
ILeftSidebarService,
@@ -53,7 +50,6 @@ import {
INotificationService,
IPlatformService,
IProgressService,
- IRangeSelectorService,
IShortcutService,
ISidebarService,
IUIController,
@@ -63,7 +59,6 @@ import {
MenuService,
PlatformService,
ProgressService,
- RangeSelectorService,
SharedController,
ShortcutPanelController,
ShortcutPanelService,
@@ -72,13 +67,15 @@ import {
UNIVER_UI_PLUGIN_NAME,
ZIndexManager,
} from '@univerjs/ui';
-import { FlowManagerService } from './services/flow/flow-manager.service';
+import type { Dependency } from '@univerjs/core';
+import type { IUniverUIConfig } from '@univerjs/ui';
import { UniverUniUIController } from './controllers/uniui-desktop.controller';
-import { IUnitGridService, UnitGridService } from './services/unit-grid/unit-grid.service';
+import { UniuiFlowController } from './controllers/uniui-flow.controller';
import { UniuiLeftSidebarController } from './controllers/uniui-leftsidebar.controller';
import { UniuiToolbarController } from './controllers/uniui-toolbar.controller';
-import { UniuiFlowController } from './controllers/uniui-flow.controller';
+import { FlowManagerService } from './services/flow/flow-manager.service';
import { UniToolbarService } from './services/toolbar/uni-toolbar-service';
+import { IUnitGridService, UnitGridService } from './services/unit-grid/unit-grid.service';
const UI_BOOTSTRAP_DELAY = 16;
diff --git a/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx b/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx
index 4453cb4044..92828d8405 100644
--- a/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx
+++ b/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx
@@ -14,16 +14,17 @@
* limitations under the License.
*/
-import React, { useCallback, useLayoutEffect, useState } from 'react';
-import { CheckMarkSingle, CloseSingle, FxSingle } from '@univerjs/icons';
-import type { Nullable, Workbook } from '@univerjs/core';
import { BooleanNumber, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DocumentFlavor, HorizontalAlign, IPermissionService, IUniverInstanceService, Rectangle, ThemeService, UniverInstanceType, useDependency, useObservable, VerticalAlign, WrapStrategy } from '@univerjs/core';
-import { IEditorBridgeService, IFormulaEditorManagerService, useActiveWorkbook } from '@univerjs/sheets-ui';
-import { RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel, WorksheetSetCellValuePermission } from '@univerjs/sheets';
-import { EMPTY, merge, switchMap } from 'rxjs';
+import { TextEditor } from '@univerjs/docs-ui';
import { DeviceInputEventType } from '@univerjs/engine-render';
-import { KeyCode, ProgressBar, TextEditor } from '@univerjs/ui';
+import { CheckMarkSingle, CloseSingle, FxSingle } from '@univerjs/icons';
+import { RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel, WorksheetSetCellValuePermission } from '@univerjs/sheets';
+import { IEditorBridgeService, IFormulaEditorManagerService, useActiveWorkbook } from '@univerjs/sheets-ui';
+import { KeyCode, ProgressBar } from '@univerjs/ui';
import clsx from 'clsx';
+import React, { useCallback, useLayoutEffect, useState } from 'react';
+import { EMPTY, merge, switchMap } from 'rxjs';
+import type { Nullable, Workbook } from '@univerjs/core';
import styles from './index.module.less';
export const UniFormulaBar = () => {
diff --git a/packages/core/src/services/locale/locale.service.ts b/packages/core/src/services/locale/locale.service.ts
index bb2f754ea3..01fa3fd4ef 100644
--- a/packages/core/src/services/locale/locale.service.ts
+++ b/packages/core/src/services/locale/locale.service.ts
@@ -17,9 +17,9 @@
import { BehaviorSubject, Subject } from 'rxjs';
import { Disposable, toDisposable } from '../../shared/lifecycle';
-import type { ILanguagePack, ILocales, LanguageValue } from '../../shared/locale';
import { Tools } from '../../shared/tools';
import { LocaleType } from '../../types/enum/locale-type';
+import type { ILanguagePack, ILocales, LanguageValue } from '../../shared/locale';
/**
* This service provides i18n and timezone / location features to other modules.
diff --git a/packages/core/src/univer.ts b/packages/core/src/univer.ts
index c2f67dc933..50c0b4c412 100644
--- a/packages/core/src/univer.ts
+++ b/packages/core/src/univer.ts
@@ -14,10 +14,12 @@
* limitations under the License.
*/
-import type { Dependency } from './common/di';
import { Injector } from './common/di';
+import { UniverInstanceType } from './common/unit';
import { DocumentDataModel } from './docs/data-model/document-data-model';
+import { AuthzIoLocalService } from './services/authz-io/authz-io-local.service';
+import { IAuthzIoService } from './services/authz-io/type';
import { CommandService, ICommandService } from './services/command/command.service';
import { ConfigService, IConfigService } from './services/config/config.service';
import { ContextService, IContextService } from './services/context/context.service';
@@ -26,33 +28,31 @@ import { IUniverInstanceService, UniverInstanceService } from './services/instan
import { LifecycleStages } from './services/lifecycle/lifecycle';
import { LifecycleInitializerService, LifecycleService } from './services/lifecycle/lifecycle.service';
import { LocaleService } from './services/locale/locale.service';
-import type { LogLevel } from './services/log/log.service';
import { DesktopLogService, ILogService } from './services/log/log.service';
import { PermissionService } from './services/permission/permission.service';
-import { IPermissionService } from './services/permission/type';
-import { ResourceManagerService } from './services/resource-manager/resource-manager.service';
-import { IResourceManagerService } from './services/resource-manager/type';
+import { IPermissionService } from './services/permission/type';
+import { PluginService } from './services/plugin/plugin.service';
+import { mergeOverrideWithDependencies } from './services/plugin/plugin-override';
import { ResourceLoaderService } from './services/resource-loader/resource-loader.service';
import { IResourceLoaderService } from './services/resource-loader/type';
-import type { IStyleSheet } from './services/theme/theme.service';
+import { ResourceManagerService } from './services/resource-manager/resource-manager.service';
+import { IResourceManagerService } from './services/resource-manager/type';
import { ThemeService } from './services/theme/theme.service';
import { IUndoRedoService, LocalUndoRedoService } from './services/undoredo/undoredo.service';
+import { UserManagerService } from './services/user-manager/user-manager.service';
import { Workbook } from './sheets/workbook';
import { SlideDataModel } from './slides/slide-model';
-import type { LocaleType } from './types/enum/locale-type';
-import type { IDocumentData, ISlideData } from './types/interfaces';
+import type { Dependency } from './common/di';
import type { UnitModel, UnitType } from './common/unit';
-import { UniverInstanceType } from './common/unit';
-import { PluginService } from './services/plugin/plugin.service';
+import type { LogLevel } from './services/log/log.service';
import type { Plugin, PluginCtor } from './services/plugin/plugin';
import type { DependencyOverride } from './services/plugin/plugin-override';
-import { mergeOverrideWithDependencies } from './services/plugin/plugin-override';
-import { UserManagerService } from './services/user-manager/user-manager.service';
-import { AuthzIoLocalService } from './services/authz-io/authz-io-local.service';
-import { IAuthzIoService } from './services/authz-io/type';
+import type { IStyleSheet } from './services/theme/theme.service';
import type { ILocales } from './shared';
import type { IWorkbookData } from './sheets/typedef';
+import type { LocaleType } from './types/enum/locale-type';
+import type { IDocumentData, ISlideData } from './types/interfaces';
export interface IUniverConfig {
theme: IStyleSheet;
diff --git a/packages/docs-drawing-ui/src/commands/commands/insert-image.command.ts b/packages/docs-drawing-ui/src/commands/commands/insert-image.command.ts
index 360054ad5d..7cc07d8160 100644
--- a/packages/docs-drawing-ui/src/commands/commands/insert-image.command.ts
+++ b/packages/docs-drawing-ui/src/commands/commands/insert-image.command.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-import type { ICommand, Nullable } from '@univerjs/core';
import { CommandType, UniverInstanceType } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
+import type { ICommand, Nullable } from '@univerjs/core';
import { DocDrawingUpdateRenderController } from '../../controllers/render-controllers/doc-drawing-update.render-controller';
export interface IInsertDocImageCommandParams {
@@ -29,6 +29,7 @@ export const InsertDocImageCommand: ICommand<IInsertDocImageCommandParams> = {
handler: (accessor) => {
const renderManagerService = accessor.get(IRenderManagerService);
return renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_DOC)
- ?.with(DocDrawingUpdateRenderController).insertDocImage() ?? false;
+ ?.with(DocDrawingUpdateRenderController)
+ .insertDocImage() ?? false;
},
};
diff --git a/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-transform-update.controller.ts b/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-transform-update.controller.ts
index 8704f37413..d95cce9c10 100644
--- a/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-transform-update.controller.ts
+++ b/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-transform-update.controller.ts
@@ -26,10 +26,9 @@ import {
PositionedObjectLayoutType,
} from '@univerjs/core';
import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
-import { SetDocZoomRatioOperation } from '@univerjs/docs-ui';
+import { IEditorService, SetDocZoomRatioOperation } from '@univerjs/docs-ui';
import { IDrawingManagerService } from '@univerjs/drawing';
import { Liquid, TRANSFORM_CHANGE_OBSERVABLE_TYPE } from '@univerjs/engine-render';
-import { IEditorService } from '@univerjs/ui';
import { debounceTime, filter } from 'rxjs';
import type { DocumentDataModel, ICommandInfo, IDrawingParam, ITransformState } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
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 31c734a199..109acb2637 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
@@ -53,7 +53,7 @@ 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 activeRanges = this._docSelectionManagerService.getCurrentTextRanges();
+ const activeRanges = this._docSelectionManagerService.getTextRanges();
const currentSegmentId = activeRanges?.[0].segmentId;
if ((link?.segmentId ?? '') !== currentSegmentId) {
this._hideInfoPopup();
diff --git a/packages/docs-hyper-link-ui/src/plugin.ts b/packages/docs-hyper-link-ui/src/plugin.ts
index 00ec99022f..73c9c43019 100644
--- a/packages/docs-hyper-link-ui/src/plugin.ts
+++ b/packages/docs-hyper-link-ui/src/plugin.ts
@@ -15,17 +15,17 @@
*/
import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
-import type { Dependency } from '@univerjs/core';
-import { IRenderManagerService } from '@univerjs/engine-render';
import { UniverDocsHyperLinkPlugin } from '@univerjs/docs-hyper-link';
-import { DOC_HYPER_LINK_UI_PLUGIN } from './types/const';
-import { DocHyperLinkUIController } from './controllers/ui.controller';
-import { DocHyperLinkPopupService } from './services/hyper-link-popup.service';
+import { IRenderManagerService } from '@univerjs/engine-render';
+import type { Dependency } from '@univerjs/core';
+import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
import { DocHyperLinkSelectionController } from './controllers/doc-hyper-link-selection.controller';
-import { DocHyperLinkRenderController } from './controllers/render-controllers/render.controller';
import { DocHyperLinkEventRenderController } from './controllers/render-controllers/hyper-link-event.render-controller';
+import { DocHyperLinkRenderController } from './controllers/render-controllers/render.controller';
+import { DocHyperLinkUIController } from './controllers/ui.controller';
+import { DocHyperLinkPopupService } from './services/hyper-link-popup.service';
+import { DOC_HYPER_LINK_UI_PLUGIN } from './types/const';
import type { IUniverDocsHyperLinkUIConfig } from './controllers/config.schema';
-import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
@DependentOn(UniverDocsHyperLinkPlugin)
export class UniverDocsHyperLinkUIPlugin extends Plugin {
diff --git a/packages/docs-ui/package.json b/packages/docs-ui/package.json
index e9fe227462..e1b53509b3 100644
--- a/packages/docs-ui/package.json
+++ b/packages/docs-ui/package.json
@@ -68,6 +68,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
+ "@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/ui": "workspace:*",
"clsx": ">=2.0.0",
@@ -78,6 +79,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
+ "@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons": "^0.1.78",
"@univerjs/ui": "workspace:*",
diff --git a/packages/docs-ui/src/basics/custom-decoration-factory.ts b/packages/docs-ui/src/basics/custom-decoration-factory.ts
index c4a2edb63f..b20f79c234 100644
--- a/packages/docs-ui/src/basics/custom-decoration-factory.ts
+++ b/packages/docs-ui/src/basics/custom-decoration-factory.ts
@@ -88,7 +88,7 @@ export function addCustomDecorationBySelectionFactory(accessor: IAccessor, param
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
- const selections = docSelectionManagerService.getCurrentTextRanges();
+ const selections = docSelectionManagerService.getTextRanges();
if (!selections) {
return false;
}
diff --git a/packages/docs-ui/src/basics/editor.ts b/packages/docs-ui/src/basics/editor.ts
new file mode 100644
index 0000000000..5a05995649
--- /dev/null
+++ b/packages/docs-ui/src/basics/editor.ts
@@ -0,0 +1,39 @@
+/**
+ * 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 function isElementVisible(element: HTMLElement | null) {
+ if (!element) return false;
+
+ const style = window.getComputedStyle(element);
+
+ if (style.display === 'none' ||
+ style.visibility === 'hidden' ||
+ style.opacity === '0') {
+ return false;
+ }
+
+ const rect = element.getBoundingClientRect();
+ if (rect.width === 0 || rect.height === 0) {
+ return false;
+ }
+
+ if (rect.bottom < 0 || rect.top > window.innerHeight ||
+ rect.right < 0 || rect.left > window.innerWidth) {
+ return false;
+ }
+
+ return true;
+}
diff --git a/packages/docs-ui/src/commands/commands/__tests__/clipboard.command.spec.ts b/packages/docs-ui/src/commands/commands/__tests__/clipboard.command.spec.ts
index f82dfe9047..ccbe06a155 100644
--- a/packages/docs-ui/src/commands/commands/__tests__/clipboard.command.spec.ts
+++ b/packages/docs-ui/src/commands/commands/__tests__/clipboard.command.spec.ts
@@ -124,12 +124,12 @@ describe('test cases in clipboard', () => {
const selectionManager = get(DocSelectionManagerService);
- selectionManager.setCurrentSelection({
+ selectionManager.__TEST_ONLY_setCurrentSelection({
unitId: 'test-doc',
subUnitId: '',
});
- selectionManager.add([
+ selectionManager.__TEST_ONLY_add([
{
startOffset: 0,
endOffset: 5,
@@ -137,7 +137,7 @@ describe('test cases in clipboard', () => {
},
]);
- selectionManager.add([
+ selectionManager.__TEST_ONLY_add([
{
startOffset: 10,
endOffset: 15,
diff --git a/packages/docs-ui/src/commands/commands/__tests__/inline-format.command.spec.ts b/packages/docs-ui/src/commands/commands/__tests__/inline-format.command.spec.ts
index 4e4e86346d..4081ef278b 100644
--- a/packages/docs-ui/src/commands/commands/__tests__/inline-format.command.spec.ts
+++ b/packages/docs-ui/src/commands/commands/__tests__/inline-format.command.spec.ts
@@ -65,12 +65,12 @@ describe('Test inline format commands', () => {
const selectionManager = get(DocSelectionManagerService);
- selectionManager.setCurrentSelection({
+ selectionManager.__TEST_ONLY_setCurrentSelection({
unitId: 'test-doc',
subUnitId: 'test-doc',
});
- selectionManager.add([
+ selectionManager.__TEST_ONLY_add([
{
startOffset: 0,
endOffset: 5,
@@ -78,7 +78,7 @@ describe('Test inline format commands', () => {
},
]);
- selectionManager.add([
+ selectionManager.__TEST_ONLY_add([
{
startOffset: 20,
endOffset: 30,
diff --git a/packages/docs-ui/src/commands/commands/__tests__/replace-content.command.spec.ts b/packages/docs-ui/src/commands/commands/__tests__/replace-content.command.spec.ts
index 1d8985ed5f..e5aaf568ff 100644
--- a/packages/docs-ui/src/commands/commands/__tests__/replace-content.command.spec.ts
+++ b/packages/docs-ui/src/commands/commands/__tests__/replace-content.command.spec.ts
@@ -70,12 +70,12 @@ describe('replace or cover content of document', () => {
const selectionManager = get(DocSelectionManagerService);
- selectionManager.setCurrentSelection({
+ selectionManager.__TEST_ONLY_setCurrentSelection({
unitId: 'test-doc',
subUnitId: '',
});
- selectionManager.add([
+ selectionManager.__TEST_ONLY_add([
{
startOffset: 5,
endOffset: 5,
diff --git a/packages/docs-ui/src/commands/commands/break-line.command.ts b/packages/docs-ui/src/commands/commands/break-line.command.ts
index 255e2d803f..77907baad3 100644
--- a/packages/docs-ui/src/commands/commands/break-line.command.ts
+++ b/packages/docs-ui/src/commands/commands/break-line.command.ts
@@ -69,7 +69,7 @@ export const BreakLineCommand: ICommand = {
const commandService = accessor.get(ICommandService);
const activeTextRange = docSelectionManagerService.getActiveTextRange();
- const rectRanges = docSelectionManagerService.getCurrentRectRanges();
+ const rectRanges = docSelectionManagerService.getRectRanges();
if (activeTextRange == null) {
return false;
}
diff --git a/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts b/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts
index 909cf55bcd..a63c99efdb 100644
--- a/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts
+++ b/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts
@@ -89,7 +89,7 @@ export const InnerPasteCommand: ICommand<IInnerPasteCommandParams> = {
const commandService = accessor.get(ICommandService);
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
- const selections = docSelectionManagerService.getCurrentTextRanges();
+ const selections = docSelectionManagerService.getTextRanges();
const { body, tableSource, drawings } = doc;
if (!Array.isArray(selections) || selections.length === 0 || body == null) {
return false;
@@ -464,8 +464,8 @@ export const CutContentCommand: ICommand<IInnerCutCommandParams> = {
const commandService = accessor.get(ICommandService);
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
- const selections = params.selections ?? docSelectionManagerService.getCurrentTextRanges();
- const rectRanges = docSelectionManagerService.getCurrentRectRanges();
+ const selections = params.selections ?? docSelectionManagerService.getTextRanges();
+ const rectRanges = docSelectionManagerService.getRectRanges();
if (
(!Array.isArray(selections) || selections.length === 0)
diff --git a/packages/docs-ui/src/commands/commands/delete.command.ts b/packages/docs-ui/src/commands/commands/delete.command.ts
index 3d56c3a28c..46178e7a7b 100644
--- a/packages/docs-ui/src/commands/commands/delete.command.ts
+++ b/packages/docs-ui/src/commands/commands/delete.command.ts
@@ -153,7 +153,7 @@ export const MergeTwoParagraphCommand: ICommand<IMergeTwoParagraphParams> = {
const { direction, range } = params;
const activeRange = docSelectionManagerService.getActiveTextRange();
- const ranges = docSelectionManagerService.getCurrentTextRanges();
+ const ranges = docSelectionManagerService.getTextRanges();
if (activeRange == null || ranges == null) {
return false;
@@ -309,8 +309,8 @@ export const DeleteLeftCommand: ICommand = {
const unitId = docDataModel.getUnitId();
const docSkeletonManagerService = getCommandSkeleton(accessor, unitId);
const activeRange = docSelectionManagerService.getActiveTextRange();
- const rectRanges = docSelectionManagerService.getCurrentRectRanges();
- const ranges = docSelectionManagerService.getCurrentTextRanges();
+ const rectRanges = docSelectionManagerService.getRectRanges();
+ const ranges = docSelectionManagerService.getTextRanges();
const skeleton = docSkeletonManagerService?.getSkeleton();
if (skeleton == null) {
@@ -524,8 +524,8 @@ export const DeleteRightCommand: ICommand = {
const commandService = accessor.get(ICommandService);
const activeRange = docSelectionManagerService.getActiveTextRange();
- const rectRanges = docSelectionManagerService.getCurrentRectRanges();
- const ranges = docSelectionManagerService.getCurrentTextRanges();
+ const rectRanges = docSelectionManagerService.getRectRanges();
+ const ranges = docSelectionManagerService.getTextRanges();
const skeleton = docSkeletonManagerService?.getSkeleton();
if (rectRanges?.length) {
diff --git a/packages/docs-ui/src/commands/commands/replace-content.command.ts b/packages/docs-ui/src/commands/commands/replace-content.command.ts
index f438b83c43..7228da1bb5 100644
--- a/packages/docs-ui/src/commands/commands/replace-content.command.ts
+++ b/packages/docs-ui/src/commands/commands/replace-content.command.ts
@@ -43,7 +43,7 @@ export const ReplaceContentCommand: ICommand<IReplaceContentCommandParams> = {
const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
const prevBody = docDataModel?.getSnapshot().body;
- const selections = docSelectionManagerService.getCurrentTextRanges();
+ const selections = docSelectionManagerService.getTextRanges();
if (docDataModel == null || prevBody == null) {
return false;
diff --git a/packages/docs-ui/src/commands/commands/table/doc-table-delete.command.ts b/packages/docs-ui/src/commands/commands/table/doc-table-delete.command.ts
index 967e3ef90f..2d684eaa5c 100644
--- a/packages/docs-ui/src/commands/commands/table/doc-table-delete.command.ts
+++ b/packages/docs-ui/src/commands/commands/table/doc-table-delete.command.ts
@@ -33,7 +33,7 @@ export const DocTableDeleteRowsCommand: ICommand<IDocTableDeleteRowsCommandParam
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
- const activeRectRanges = docSelectionManagerService.getCurrentRectRanges();
+ const activeRectRanges = docSelectionManagerService.getRectRanges();
const activeTextRange = docSelectionManagerService.getActiveTextRange();
const rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
@@ -139,7 +139,7 @@ export const DocTableDeleteColumnsCommand: ICommand<IDocTableDeleteColumnsComman
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
- const activeRectRanges = docSelectionManagerService.getCurrentRectRanges();
+ const activeRectRanges = docSelectionManagerService.getRectRanges();
const activeTextRange = docSelectionManagerService.getActiveTextRange();
const rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
@@ -256,7 +256,7 @@ export const DocTableDeleteTableCommand: ICommand<IDocTableDeleteTableCommandPar
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
- const activeRectRanges = docSelectionManagerService.getCurrentRectRanges();
+ const activeRectRanges = docSelectionManagerService.getRectRanges();
const activeTextRange = docSelectionManagerService.getActiveTextRange();
const rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
diff --git a/packages/docs-ui/src/commands/commands/table/doc-table-insert.command.ts b/packages/docs-ui/src/commands/commands/table/doc-table-insert.command.ts
index cb146528b3..fe3ec245fa 100644
--- a/packages/docs-ui/src/commands/commands/table/doc-table-insert.command.ts
+++ b/packages/docs-ui/src/commands/commands/table/doc-table-insert.command.ts
@@ -101,7 +101,7 @@ export const DocTableInsertRowCommand: ICommand<IDocTableInsertRowCommandParams>
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
- const activeRectRanges = docSelectionManagerService.getCurrentRectRanges();
+ const activeRectRanges = docSelectionManagerService.getRectRanges();
const activeTextRange = docSelectionManagerService.getActiveTextRange();
const rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
@@ -212,7 +212,7 @@ export const DocTableInsertColumnCommand: ICommand<IDocTableInsertColumnCommandP
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
- const activeRectRanges = docSelectionManagerService.getCurrentRectRanges();
+ const activeRectRanges = docSelectionManagerService.getRectRanges();
const activeTextRange = docSelectionManagerService.getActiveTextRange();
const rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
diff --git a/packages/ui/src/components/editor/TextEditor.tsx b/packages/docs-ui/src/components/editor/TextEditor.tsx
similarity index 95%
rename from packages/ui/src/components/editor/TextEditor.tsx
rename to packages/docs-ui/src/components/editor/TextEditor.tsx
index d934f192e0..9a527b73b6 100644
--- a/packages/ui/src/components/editor/TextEditor.tsx
+++ b/packages/docs-ui/src/components/editor/TextEditor.tsx
@@ -17,10 +17,10 @@
import { debounce, isInternalEditorID, LocaleService, useDependency } from '@univerjs/core';
import React, { useEffect, useRef, useState } from 'react';
import type { IDocumentData, Nullable } from '@univerjs/core';
-import { IEditorService } from '../../services/editor/editor.service';
-import { isElementVisible } from '../../utils/util';
+import { isElementVisible } from '../../basics/editor';
+import { IEditorService } from '../../services/editor/editor-manager.service';
import styles from './index.module.less';
-import type { Editor, IEditorCanvasStyle } from '../../services/editor/editor.service';
+import type { Editor, IEditorCanvasStyle } from '../../services/editor/editor';
type MyComponentProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
@@ -88,6 +88,7 @@ export interface ITextEditorProps {
/**
* The component to render toolbar item label and menu item label.
* @param props
+ * @deprecated The business side encapsulates its own Editor component.
*/
export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onChange' | 'onActive'>): JSX.Element | null {
const {
@@ -157,7 +158,7 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
isSheetEditor,
canvasStyle,
isSingle,
- isReadonly,
+ readonly: isReadonly,
isSingleChoice,
onlyInputFormula,
onlyInputRange,
@@ -228,13 +229,13 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
}
// WTF: should not use editorService to sync values. All editors instance would be notified!
- if (editor.editorUnitId !== id) {
+ if (editor.getEditorId() !== id) {
return;
}
const focusEditor = editorService.getFocusEditor();
- if (focusEditor && focusEditor.editorUnitId !== id) {
+ if (focusEditor && focusEditor.getEditorId() !== id) {
return;
}
@@ -257,7 +258,7 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
}
editor.update({
- isReadonly, isSingle, isSingleChoice, onlyInputContent, onlyInputFormula, onlyInputRange, openForSheetSubUnitId, openForSheetUnitId,
+ readonly: isReadonly, isSingle, isSingleChoice, onlyInputContent, onlyInputFormula, onlyInputRange, openForSheetSubUnitId, openForSheetUnitId,
});
}, [isReadonly, isSingle, isSingleChoice, onlyInputContent, onlyInputFormula, onlyInputRange, openForSheetSubUnitId, openForSheetUnitId]);
diff --git a/packages/ui/src/components/editor/index.module.less b/packages/docs-ui/src/components/editor/index.module.less
similarity index 100%
rename from packages/ui/src/components/editor/index.module.less
rename to packages/docs-ui/src/components/editor/index.module.less
diff --git a/packages/ui/src/components/range-selector/RangeSelector.tsx b/packages/docs-ui/src/components/range-selector/RangeSelector.tsx
similarity index 99%
rename from packages/ui/src/components/range-selector/RangeSelector.tsx
rename to packages/docs-ui/src/components/range-selector/RangeSelector.tsx
index d71f70e427..3aeba59cf6 100644
--- a/packages/ui/src/components/range-selector/RangeSelector.tsx
+++ b/packages/docs-ui/src/components/range-selector/RangeSelector.tsx
@@ -18,14 +18,14 @@ import { IUniverInstanceService, LocaleService, ThemeService, UniverInstanceType
import { Button, Dialog, Input, Tooltip } from '@univerjs/design';
import { getRangeWithRefsString, isReferenceStringWithEffectiveColumn, serializeRange, serializeRangeWithSheet, serializeRangeWithSpreadsheet } from '@univerjs/engine-formula';
import { CloseSingle, DeleteSingle, IncreaseSingle, SelectRangeSingle } from '@univerjs/icons';
-import clsx from 'clsx';
+import { useEvent } from '@univerjs/ui';
+import clsx from 'clsx';
import React, { useEffect, useRef, useState } from 'react';
import type { IUnitRangeWithName, Nullable, Workbook } from '@univerjs/core';
-import { IEditorService } from '../../services/editor/editor.service';
+import { IEditorService } from '../../services/editor/editor-manager.service';
import { IRangeSelectorService } from '../../services/range-selector/range-selector.service';
import { TextEditor } from '../editor/TextEditor';
-import { useEvent } from '../hooks/event';
import styles from './index.module.less';
export interface IRangeSelectorProps {
diff --git a/packages/ui/src/components/range-selector/index.module.less b/packages/docs-ui/src/components/range-selector/index.module.less
similarity index 100%
rename from packages/ui/src/components/range-selector/index.module.less
rename to packages/docs-ui/src/components/range-selector/index.module.less
diff --git a/packages/docs-ui/src/controllers/doc-header-footer.controller.ts b/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
index 6d3a1b658b..34fad14855 100644
--- a/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
+++ b/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
@@ -17,13 +17,14 @@
import { BooleanNumber, Disposable, DocumentFlavor, ICommandService, Inject, IUniverInstanceService, LocaleService, toDisposable, Tools } from '@univerjs/core';
import { DocSkeletonManagerService } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService, PageLayoutType, Path, Rect, Vector2 } from '@univerjs/engine-render';
-import { ComponentManager, IEditorService } from '@univerjs/ui';
+import { ComponentManager } from '@univerjs/ui';
import type { DocumentDataModel } from '@univerjs/core';
import type { Documents, DocumentViewModel, IMouseEvent, IPageRenderConfig, IPathProps, IPointerEvent, IRenderContext, IRenderModule, RenderComponentType } from '@univerjs/engine-render';
import type { Nullable } from 'vitest';
import { neoGetDocObject } from '../basics/component-tools';
import { CoreHeaderFooterCommand } from '../commands/commands/doc-header-footer.command';
+import { IEditorService } from '../services/editor/editor-manager.service';
import { DocSelectionRenderService } from '../services/selection/doc-selection-render.service';
import { COMPONENT_DOC_HEADER_FOOTER_PANEL } from '../views/header-footer/panel/component-name';
import { DocHeaderFooterPanel } from '../views/header-footer/panel/DocHeaderFooterPanel';
diff --git a/packages/docs-ui/src/controllers/doc-move-cursor.controller.ts b/packages/docs-ui/src/controllers/doc-move-cursor.controller.ts
index 4044de3c7e..14aa5bd127 100644
--- a/packages/docs-ui/src/controllers/doc-move-cursor.controller.ts
+++ b/packages/docs-ui/src/controllers/doc-move-cursor.controller.ts
@@ -99,7 +99,7 @@ export class DocMoveCursorController extends Disposable {
// eslint-disable-next-line max-lines-per-function, complexity
private _handleShiftMoveSelection(direction: Direction) {
const activeRange = this._textSelectionManagerService.getActiveTextRange();
- const allRanges = this._textSelectionManagerService.getCurrentTextRanges()!;
+ const allRanges = this._textSelectionManagerService.getTextRanges()!;
const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
if (docDataModel == null) {
return;
@@ -217,7 +217,7 @@ export class DocMoveCursorController extends Disposable {
// eslint-disable-next-line max-lines-per-function, complexity
private _handleMoveCursor(direction: Direction) {
const activeRange = this._textSelectionManagerService.getActiveTextRange();
- const allRanges = this._textSelectionManagerService.getCurrentTextRanges();
+ const allRanges = this._textSelectionManagerService.getTextRanges();
const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
if (docDataModel == null) {
return false;
diff --git a/packages/docs-ui/src/controllers/menu/context-menu.ts b/packages/docs-ui/src/controllers/menu/context-menu.ts
index 299afa105a..a41d188274 100644
--- a/packages/docs-ui/src/controllers/menu/context-menu.ts
+++ b/packages/docs-ui/src/controllers/menu/context-menu.ts
@@ -58,8 +58,9 @@ const getDisableWhenSelectionNotInTableObservable = (accessor: IAccessor) => {
return new Observable<boolean>((subscriber) => {
const observable = docSelectionManagerService.textSelection$.subscribe(() => {
- const rectRanges = docSelectionManagerService.getCurrentRectRanges();
+ const rectRanges = docSelectionManagerService.getRectRanges();
const activeRange = docSelectionManagerService.getActiveTextRange();
+
if (rectRanges && rectRanges.length && inSameTable(rectRanges)) {
subscriber.next(false);
return;
diff --git a/packages/docs-ui/src/controllers/render-controllers/back-scroll.render-controller.ts b/packages/docs-ui/src/controllers/render-controllers/back-scroll.render-controller.ts
index 6f96011915..4e5115dced 100644
--- a/packages/docs-ui/src/controllers/render-controllers/back-scroll.render-controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/back-scroll.render-controller.ts
@@ -16,11 +16,11 @@
import { Inject, RxDisposable } from '@univerjs/core';
import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
-import { IEditorService } from '@univerjs/ui';
import { takeUntil } from 'rxjs';
import type { DocumentDataModel, ITextRange, Nullable } from '@univerjs/core';
import type { Documents, INodePosition, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { VIEWPORT_KEY } from '../../basics/docs-view-key';
+import { IEditorService } from '../../services/editor/editor-manager.service';
import { NodePositionConvertToCursor } from '../../services/selection/convert-text-range';
import { getAnchorBounding } from '../../services/selection/text-range';
diff --git a/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.ts
index f4e965609f..346fe54a5a 100644
--- a/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.ts
@@ -17,13 +17,14 @@
import { checkForSubstrings, Disposable, ICommandService, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
import { IRenderManagerService, ScrollBar } from '@univerjs/engine-render';
-import { IEditorService, SetEditorResizeOperation } from '@univerjs/ui';
+import { SetEditorResizeOperation } from '@univerjs/ui';
import { fromEvent } from 'rxjs';
import type { DocumentDataModel, ICommandInfo, Nullable, Workbook } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { VIEWPORT_KEY } from '../../basics/docs-view-key';
import { CoverContentCommand } from '../../commands/commands/replace-content.command';
+import { IEditorService } from '../../services/editor/editor-manager.service';
import { DocSelectionRenderService } from '../../services/selection/doc-selection-render.service';
export class DocEditorBridgeController extends Disposable implements IRenderModule {
@@ -54,7 +55,7 @@ export class DocEditorBridgeController extends Disposable implements IRenderModu
);
this._editorService.getAllEditor().forEach((editor) => {
- const unitId = editor.editorUnitId;
+ const unitId = editor.getEditorId();
if (unitId !== this._context.unitId) {
return;
@@ -189,7 +190,7 @@ export class DocEditorBridgeController extends Disposable implements IRenderModu
const focusEditor = this._editorService.getFocusEditor();
- if (editor == null || editor.isSheetEditor() || (focusEditor && focusEditor.editorUnitId === unitId)) {
+ if (editor == null || editor.isSheetEditor() || (focusEditor && focusEditor.getEditorId() === unitId)) {
return;
}
@@ -201,7 +202,7 @@ export class DocEditorBridgeController extends Disposable implements IRenderModu
private _initialFocus() {
this.disposeWithMe(
this._editorService.focus$.subscribe((textRange) => {
- if (this._editorService.getFocusEditor()?.editorUnitId !== this._context.unitId) {
+ if (this._editorService.getFocusEditor()?.getEditorId() !== this._context.unitId) {
return;
}
diff --git a/packages/docs-ui/src/controllers/render-controllers/doc-selection-render.controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc-selection-render.controller.ts
index 89a51d50e3..4d33dd1a30 100644
--- a/packages/docs-ui/src/controllers/render-controllers/doc-selection-render.controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/doc-selection-render.controller.ts
@@ -17,12 +17,12 @@
import { Disposable, ICommandService, Inject, isInternalEditorID, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
import { CURSOR_TYPE, DocumentEditArea, PageLayoutType, Vector2 } from '@univerjs/engine-render';
-import { IEditorService } from '@univerjs/ui';
import type { DocumentDataModel, ICommandInfo } from '@univerjs/core';
import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, RenderComponentType } from '@univerjs/engine-render';
import { neoGetDocObject } from '../../basics/component-tools';
import { SetDocZoomRatioOperation } from '../../commands/operations/set-doc-zoom-ratio.operation';
+import { IEditorService } from '../../services/editor/editor-manager.service';
import { DocSelectionRenderService } from '../../services/selection/doc-selection-render.service';
import type { ISetDocZoomRatioOperationParams } from '../../commands/operations/set-doc-zoom-ratio.operation';
@@ -242,7 +242,7 @@ export class DocSelectionRenderController extends Disposable implements IRenderM
const params = command.params as ISetDocZoomRatioOperationParams;
const { unitId: documentId } = params;
- const unitId = this._docSelectionManagerService.getCurrentSelection()?.unitId;
+ const unitId = this._docSelectionManagerService.__getCurrentSelection()?.unitId;
if (documentId !== unitId) {
return;
@@ -255,8 +255,6 @@ export class DocSelectionRenderController extends Disposable implements IRenderM
}
private _skeletonListener() {
- let init = false;
-
// Change text selection runtime(skeleton, scene) and update text selection manager current selection.
this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe((skeleton) => {
if (!skeleton) return;
@@ -264,21 +262,22 @@ export class DocSelectionRenderController extends Disposable implements IRenderM
const { unitId } = this._context;
const isInternalEditor = isInternalEditorID(unitId);
- if (init || !isInternalEditorID(this._context.unitId)) {
- // The initial cursor is set at the beginning of the document,
- // and can be set to the previous cursor position in the future.
- // The skeleton of the editor has not been calculated at this moment, and it is determined whether it is an editor by its ID.
- if (!isInternalEditor) {
- this._docSelectionManagerService.replaceTextRanges([
- {
- startOffset: 0,
- endOffset: 0,
- },
- ], false);
- }
+ // The initial cursor is set at the beginning of the document,
+ // and can be set to the previous cursor position in the future.
+ // The skeleton of the editor has not been calculated at this moment, and it is determined whether it is an editor by its ID.
+ if (!isInternalEditor) {
+ //TODO: @JOCS Only for docs. move to docs in the future.
+ this._docSelectionRenderService.focus();
+ this._docSelectionManagerService.replaceDocRanges([
+ {
+ startOffset: 0,
+ endOffset: 0,
+ },
+ ], {
+ unitId,
+ subUnitId: unitId,
+ }, false);
}
-
- init = true;
}));
}
}
diff --git a/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.ts
index 8cb93d4341..1c0f236a4c 100644
--- a/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.ts
@@ -17,12 +17,12 @@
import { FOCUSING_DOC, ICommandService, IContextService, Inject, RxDisposable } from '@univerjs/core';
import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
import { DocBackground, Documents, IRenderManagerService, Layer, PageLayoutType, ScrollBar, Viewport } from '@univerjs/engine-render';
-import { IEditorService } from '@univerjs/ui';
import { takeUntil } from 'rxjs';
import type { DocumentDataModel, EventState, ICommandInfo, Nullable } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import type { DocumentSkeleton, IRenderContext, IRenderModule, IWheelEvent } from '@univerjs/engine-render';
import { DOCS_COMPONENT_BACKGROUND_LAYER_INDEX, DOCS_COMPONENT_DEFAULT_Z_INDEX, DOCS_COMPONENT_HEADER_LAYER_INDEX, DOCS_COMPONENT_MAIN_LAYER_INDEX, DOCS_VIEW_KEY, VIEWPORT_KEY } from '../../basics/docs-view-key';
+import { IEditorService } from '../../services/editor/editor-manager.service';
import { DocSelectionRenderService } from '../../services/selection/doc-selection-render.service';
export class DocRenderController extends RxDisposable implements IRenderModule {
diff --git a/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts b/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts
index 8dee5f234e..b16b83f877 100644
--- a/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts
@@ -24,13 +24,13 @@ import {
} from '@univerjs/core';
import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
-import { IEditorService } from '@univerjs/ui';
import type { DocumentDataModel, ICommandInfo } from '@univerjs/core';
import type { IRenderContext, IRenderModule, IWheelEvent } from '@univerjs/engine-render';
import { neoGetDocObject } from '../../basics/component-tools';
import { SetDocZoomRatioCommand } from '../../commands/commands/set-doc-zoom-ratio.command';
import { SetDocZoomRatioOperation } from '../../commands/operations/set-doc-zoom-ratio.operation';
import { DocPageLayoutService } from '../../services/doc-page-layout.service';
+import { IEditorService } from '../../services/editor/editor-manager.service';
import type { ISetDocZoomRatioOperationParams } from '../../commands/operations/set-doc-zoom-ratio.operation';
export class DocZoomRenderController extends Disposable implements IRenderModule {
diff --git a/packages/docs-ui/src/docs-ui-plugin.ts b/packages/docs-ui/src/docs-ui-plugin.ts
index 78405cf6fc..dafec943e6 100644
--- a/packages/docs-ui/src/docs-ui-plugin.ts
+++ b/packages/docs-ui/src/docs-ui-plugin.ts
@@ -25,7 +25,7 @@ import { ICommandService,
} from '@univerjs/core';
import { DocInterceptorService, DocSkeletonManagerService } from '@univerjs/docs';
import { IRenderManagerService } from '@univerjs/engine-render';
-import { IEditorService, IShortcutService } from '@univerjs/ui';
+import { IShortcutService } from '@univerjs/ui';
import type { Dependency } from '@univerjs/core';
import { DOC_UI_PLUGIN_NAME } from './basics/const/plugin-name';
import { AfterSpaceCommand, EnterCommand, TabCommand } from './commands/commands/auto-format.command';
@@ -76,6 +76,8 @@ import { DocPageLayoutService } from './services/doc-page-layout.service';
import { DocCanvasPopManagerService } from './services/doc-popup-manager.service';
import { DocStateChangeManagerService } from './services/doc-state-change-manager.service';
import { DocsRenderService } from './services/docs-render.service';
+import { EditorService, IEditorService } from './services/editor/editor-manager.service';
+import { IRangeSelectorService, RangeSelectorService } from './services/range-selector/range-selector.service';
import { DocSelectionRenderService } from './services/selection/doc-selection-render.service';
import { BreakLineShortcut, DeleteLeftShortcut, DeleteRightShortcut } from './shortcuts/core-editing.shortcut';
import {
@@ -94,7 +96,7 @@ import type { IUniverDocsUIConfig } from './controllers/config.schema';
export class UniverDocsUIPlugin extends Plugin {
static override pluginName = DOC_UI_PLUGIN_NAME;
- static override type = UniverInstanceType.UNIVER_DOC;
+ // static override type = UniverInstanceType.UNIVER_DOC;
constructor(
private readonly _config: Partial<IUniverDocsUIConfig> = defaultPluginConfig,
@@ -112,7 +114,6 @@ export class UniverDocsUIPlugin extends Plugin {
this._configService.setConfig('menu', menu, { merge: true });
}
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
-
this._initDependencies(_injector);
this._initializeShortcut();
this._initCommand();
@@ -229,6 +230,8 @@ export class UniverDocsUIPlugin extends Plugin {
[DocParagraphSettingController],
// Services
+ [IEditorService, { useClass: EditorService }],
+ [IRangeSelectorService, { useClass: RangeSelectorService }],
[IDocClipboardService, { useClass: DocClipboardService }],
[DocCanvasPopManagerService],
[DocsRenderService],
diff --git a/packages/docs-ui/src/index.ts b/packages/docs-ui/src/index.ts
index 8cc05e0716..69306ae033 100644
--- a/packages/docs-ui/src/index.ts
+++ b/packages/docs-ui/src/index.ts
@@ -98,12 +98,14 @@ export { MoveCursorOperation } from './commands/operations/doc-cursor.operation'
export { SelectAllOperation } from './commands/operations/select-all.operation';
export { type ISetDocZoomRatioOperationParams, SetDocZoomRatioOperation } from './commands/operations/set-doc-zoom-ratio.operation';
export { getCommandSkeleton, getRichTextEditPath } from './commands/util';
+export { TextEditor } from './components/editor/TextEditor';
+export { RangeSelector } from './components/range-selector/RangeSelector';
export { DocUIController } from './controllers/doc-ui.controller';
export { menuSchema } from './controllers/menu.schema';
export { DocBackScrollRenderController } from './controllers/render-controllers/back-scroll.render-controller';
+
export { DocRenderController } from './controllers/render-controllers/doc.render-controller';
export * from './docs-ui-plugin';
-
export * from './services';
export { IDocClipboardService } from './services/clipboard/clipboard.service';
export { DocEventManagerService } from './services/doc-event-manager.service';
@@ -111,7 +113,11 @@ export { DocIMEInputManagerService } from './services/doc-ime-input-manager.serv
export { DocCanvasPopManagerService } from './services/doc-popup-manager.service';
export { DocStateChangeManagerService } from './services/doc-state-change-manager.service';
export { DocsRenderService } from './services/docs-render.service';
+export { Editor } from './services/editor/editor';
+export { EditorService, IEditorService } from './services/editor/editor-manager.service';
+export { type IRangeSelectorRange, IRangeSelectorService, RangeSelectorService } from './services/range-selector/range-selector.service';
export { isInSameTableCell, isValidRectRange, NodePositionConvertToRectRange } from './services/selection/convert-rect-range';
+
export { NodePositionConvertToCursor } from './services/selection/convert-text-range';
export { getOneTextSelectionRange } from './services/selection/convert-text-range';
export type { IEditorInputConfig } from './services/selection/doc-selection-render.service';
diff --git a/packages/docs-ui/src/services/clipboard/clipboard.service.ts b/packages/docs-ui/src/services/clipboard/clipboard.service.ts
index 68af054d2e..10c2880a7b 100644
--- a/packages/docs-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/docs-ui/src/services/clipboard/clipboard.service.ts
@@ -151,8 +151,8 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
endOffset: activeEndOffset,
style,
} = this._docSelectionManagerService.getActiveTextRange() ?? {};
- const textRanges = this._docSelectionManagerService.getCurrentTextRanges() ?? [];
- const rectRanges = this._docSelectionManagerService.getCurrentRectRanges() ?? [];
+ const textRanges = this._docSelectionManagerService.getTextRanges() ?? [];
+ const rectRanges = this._docSelectionManagerService.getRectRanges() ?? [];
if (segmentId == null) {
this._logService.error('[DocClipboardController] segmentId is not existed');
@@ -226,7 +226,7 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
const activeRange = this._docSelectionManagerService.getActiveTextRange();
const { segmentId, endOffset: activeEndOffset, style } = activeRange || {};
- const ranges = this._docSelectionManagerService.getCurrentTextRanges();
+ const ranges = this._docSelectionManagerService.getTextRanges();
if (segmentId == null) {
this._logService.error('[DocClipboardController] segmentId does not exist!');
diff --git a/packages/ui/src/services/editor/editor.service.ts b/packages/docs-ui/src/services/editor/editor-manager.service.ts
similarity index 73%
rename from packages/ui/src/services/editor/editor.service.ts
rename to packages/docs-ui/src/services/editor/editor-manager.service.ts
index d2f9e29370..3919396444 100644
--- a/packages/ui/src/services/editor/editor.service.ts
+++ b/packages/docs-ui/src/services/editor/editor-manager.service.ts
@@ -14,54 +14,27 @@
* limitations under the License.
*/
-import { createIdentifier, DEFAULT_EMPTY_DOCUMENT_VALUE, DEFAULT_STYLES, Disposable, EDITOR_ACTIVATED, FOCUSING_EDITOR_INPUT_FORMULA, FOCUSING_EDITOR_STANDALONE, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, HorizontalAlign, IContextService, Inject, IUniverInstanceService, toDisposable, UniverInstanceType, VerticalAlign } from '@univerjs/core';
+import { createIdentifier, DEFAULT_EMPTY_DOCUMENT_VALUE, Disposable, EDITOR_ACTIVATED, FOCUSING_EDITOR_INPUT_FORMULA, FOCUSING_EDITOR_STANDALONE, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, HorizontalAlign, ICommandService, IContextService, Inject, IUndoRedoService, IUniverInstanceService, toDisposable, UniverInstanceType, VerticalAlign } from '@univerjs/core';
+import { DocSelectionManagerService } from '@univerjs/docs';
import { isReferenceStrings, LexerTreeBuilder, operatorToken } from '@univerjs/engine-formula';
import { IRenderManagerService } from '@univerjs/engine-render';
-import { Subject } from 'rxjs';
-import type { DocumentDataModel, IDisposable, IDocumentBody, IDocumentData, IDocumentStyle, IPosition, Nullable, Workbook } from '@univerjs/core';
-import type { IRender, ISuccinctDocRangeParam, Scene } from '@univerjs/engine-render';
+import { fromEvent, Subject } from 'rxjs';
+import type { DocumentDataModel, IDisposable, IDocumentBody, IDocumentData, Nullable, Workbook } from '@univerjs/core';
+import type { ISuccinctDocRangeParam, Scene } from '@univerjs/engine-render';
import type { Observable } from 'rxjs';
+import { Editor } from './editor';
+import type { IEditorConfigParams, IEditorStateParams } from './editor';
-export interface IEditorStateParam extends Partial<IPosition> {
- visible?: boolean;
-}
-
-export interface IEditorCanvasStyle {
- fontSize?: number;
-}
-
-export interface IEditorConfigParam {
- editorUnitId: string;
-
- initialSnapshot?: IDocumentData;
- cancelDefaultResizeListener?: boolean;
- canvasStyle?: IEditorCanvasStyle;
-
- isSheetEditor: boolean;
- /**
- * If the editor is for formula editing.
- * @deprecated this is a temp fix before refactoring editor.
- */
- isFormulaEditor: boolean;
- isSingle: boolean;
- isReadonly: boolean;
-
- onlyInputFormula: boolean;
- onlyInputRange: boolean;
- onlyInputContent: boolean;
-
- isSingleChoice: boolean;
-
- openForSheetUnitId: Nullable<string>;
- openForSheetSubUnitId: Nullable<string>;
-
-}
-
-export interface IEditorSetParam extends IEditorConfigParam, IEditorStateParam {
- render: IRender;
- documentDataModel: DocumentDataModel;
- editorDom: HTMLDivElement;
-}
+/**
+ * Not these elements will be considered as editor blur.
+ */
+const editorFocusInElements = [
+ 'univer-editor',
+ 'univer-range-selector',
+ 'univer-range-selector-editor',
+ 'univer-render-canvas',
+ 'univer-text-editor-container-placeholder',
+];
export interface IEditorSetValueParam {
editorUnitId: string;
@@ -73,182 +46,10 @@ export interface IEditorInputFormulaParam {
formulaString: string;
}
-export class Editor {
- private _focus = false;
-
- private _valueLegality = true;
-
- private _openForSheetUnitId: Nullable<string>;
-
- private _openForSheetSubUnitId: Nullable<string>;
-
- constructor(private _param: IEditorSetParam) {
- this._openForSheetUnitId = this._param.openForSheetUnitId;
- this._openForSheetSubUnitId = this._param.openForSheetSubUnitId;
- }
-
- get documentDataModel() {
- return this._param.documentDataModel;
- }
-
- get editorUnitId() {
- return this._param.editorUnitId;
- }
-
- get cancelDefaultResizeListener() {
- return this._param.cancelDefaultResizeListener;
- }
-
- get render() {
- return this._param.render;
- }
-
- isSingleChoice() {
- return this._param.isSingleChoice;
- }
-
- setOpenForSheetUnitId(unitId: Nullable<string>) {
- this._openForSheetUnitId = unitId;
- }
-
- getOpenForSheetUnitId() {
- return this._openForSheetUnitId;
- }
-
- setOpenForSheetSubUnitId(subUnitId: Nullable<string>) {
- this._openForSheetSubUnitId = subUnitId;
- }
-
- getOpenForSheetSubUnitId() {
- return this._openForSheetSubUnitId;
- }
-
- isValueLegality() {
- return this._valueLegality === true;
- }
-
- setValueLegality(state = true) {
- this._valueLegality = state;
- }
-
- isFocus() {
- return this._focus;
- }
-
- setFocus(state = false) {
- this._focus = state;
- }
-
- isSingle() {
- return this._param.isSingle === true || this.onlyInputRange();
- }
-
- isReadOnly() {
- return this._param.isReadonly === true;
- }
-
- onlyInputContent() {
- return this._param.onlyInputContent === true;
- }
-
- onlyInputFormula() {
- return this._param.onlyInputFormula === true;
- }
-
- onlyInputRange() {
- return this._param.onlyInputRange === true;
- }
-
- getBoundingClientRect() {
- return this._param.editorDom.getBoundingClientRect();
- }
-
- isVisible() {
- return this._param.visible;
- }
-
- isSheetEditor() {
- return this._param.isSheetEditor === true;
- }
-
- /** @deprecated */
- isFormulaEditor() {
- return this._param.isFormulaEditor === true;
- }
-
- getValue() {
- const value = this._param.documentDataModel.getBody()?.dataStream || '';
- return value.replace(/\r\n/g, '').replace(/\n/g, '').replace(/\n/g, '');
- }
-
- getBody() {
- return this._param.documentDataModel.getBody();
- }
-
- update(param: Partial<IEditorSetParam>) {
- this._param = {
- ...this._param,
- ...param,
- };
- }
-
- verticalAlign() {
- const documentDataModel = this._param?.documentDataModel;
-
- if (documentDataModel == null) {
- return;
- }
-
- const { width, height } = this._param.editorDom.getBoundingClientRect();
-
- if (height === 0 || width === 0) {
- return;
- }
-
- if (!this.isSingle()) {
- documentDataModel.updateDocumentDataPageSize(width, undefined);
- return;
- }
-
- let fontSize = DEFAULT_STYLES.fs;
-
- if (this._param.canvasStyle?.fontSize) {
- fontSize = this._param.canvasStyle.fontSize;
- }
-
- const top = (height - (fontSize * 4 / 3)) / 2 - 2;
-
- documentDataModel.updateDocumentDataMargin({
- t: top < 0 ? 0 : top,
- });
-
- documentDataModel.updateDocumentDataPageSize(undefined, undefined);
- }
-
- updateCanvasStyle() {
- const documentDataModel = this._param.documentDataModel;
- if (documentDataModel == null) {
- return;
- }
-
- const documentStyle: IDocumentStyle = {};
-
- if (this._param.canvasStyle?.fontSize) {
- if (documentStyle.textStyle == null) {
- documentStyle.textStyle = {};
- }
-
- documentStyle.textStyle.fs = this._param.canvasStyle.fontSize;
- }
-
- documentDataModel.updateDocumentStyle(documentStyle);
- }
-}
-
export interface IEditorService {
getEditor(id?: string): Readonly<Nullable<Editor>>;
- register(config: IEditorConfigParam, container: HTMLDivElement): IDisposable;
+ register(config: IEditorConfigParams, container: HTMLDivElement): IDisposable;
isVisible(id: string): Nullable<boolean>;
@@ -329,7 +130,7 @@ export class EditorService extends Disposable implements IEditorService, IDispos
private _focusEditorUnitId: Nullable<string>;
- private readonly _state$ = new Subject<Nullable<IEditorStateParam>>();
+ private readonly _state$ = new Subject<Nullable<IEditorStateParams>>();
readonly state$ = this._state$.asObservable();
private _currentSheetUnitId: Nullable<string>;
@@ -369,19 +170,51 @@ export class EditorService extends Disposable implements IEditorService, IDispos
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
@Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder,
- @IContextService private readonly _contextService: IContextService
+ @Inject(DocSelectionManagerService) private readonly _docSelectionManagerService: DocSelectionManagerService,
+ @IContextService private readonly _contextService: IContextService,
+ @ICommandService private readonly _commandService: ICommandService,
+ @IUndoRedoService private readonly _undoRedoService: IUndoRedoService
) {
super();
+
+ this._initUniverFocusListener();
}
+ // REFACTOR: @Gggpound The specific business processing should not be placed here,
+ // I moved from the layout service. https://github.com/dream-num/univer-pro/issues/1708
+ private _initUniverFocusListener() {
+ this.disposeWithMe(
+ fromEvent(window, 'focusin').subscribe((event) => {
+ const target = event.target as HTMLElement;
+
+ this._blurSheetEditor(target);
+ })
+ );
+ }
+
+ private _blurSheetEditor(target: HTMLElement) {
+ if (editorFocusInElements.some((item) => target.classList.contains(item))) {
+ return;
+ }
+
+ // NOTE: Note that the focus editor will not be docs' editor but calling `this._editorService.blur()` will blur doc's editor.
+ const focusEditor = this.getFocusEditor();
+ if (focusEditor && focusEditor.isSheetEditor() !== true) {
+ this.blur();
+ }
+ }
+
+ /** @deprecated */
setFocusId(id: Nullable<string>) {
this._focusEditorUnitId = id;
}
+ /** @deprecated */
getFocusId() {
return this._focusEditorUnitId;
}
+ /** @deprecated */
getFocusEditor() {
if (this._focusEditorUnitId) {
return this.getEditor(this._focusEditorUnitId);
@@ -417,10 +250,12 @@ export class EditorService extends Disposable implements IEditorService, IDispos
this.blur();
}
+ /** @deprecated */
changeSpreadsheetFocusState(state: boolean) {
this._spreadsheetFocusState = state;
}
+ /** @deprecated */
getSpreadsheetFocusState() {
return this._spreadsheetFocusState;
}
@@ -475,6 +310,7 @@ export class EditorService extends Disposable implements IEditorService, IDispos
return !this.getSpreadsheetFocusState();
}
+ /** @deprecated */
blur() {
if (!this._spreadsheetFocusState) {
this._closeRangePrompt$.next(null);
@@ -493,6 +329,7 @@ export class EditorService extends Disposable implements IEditorService, IDispos
this._blur$.next(null);
}
+ /** @deprecated */
focus(editorUnitId: string | undefined = this._univerInstanceService.getCurrentUniverDocInstance()?.getUnitId()) {
if (editorUnitId == null) {
return;
@@ -515,15 +352,18 @@ export class EditorService extends Disposable implements IEditorService, IDispos
});
}
+ /** @deprecated */
setFormula(formulaString: string, editorUnitId = this._getCurrentEditorUnitId()) {
this._inputFormula$.next({ formulaString, editorUnitId });
}
+ /** @deprecated */
setValue(val: string, editorUnitId: string = this._getCurrentEditorUnitId()) {
this.setValueNoRefresh(val, editorUnitId);
this._refreshValueChange(editorUnitId);
}
+ /** @deprecated */
setValueNoRefresh(val: string, editorUnitId: string) {
this._setValue$.next({
body: {
@@ -535,6 +375,7 @@ export class EditorService extends Disposable implements IEditorService, IDispos
this.resize(editorUnitId);
}
+ /** @deprecated */
getValue(id: string) {
const editor = this.getEditor(id);
if (editor == null) {
@@ -543,11 +384,13 @@ export class EditorService extends Disposable implements IEditorService, IDispos
return editor.getValue();
}
+ /** @deprecated */
setRichValue(body: IDocumentBody, editorUnitId: string = this._getCurrentEditorUnitId()) {
this._setValue$.next({ body, editorUnitId });
this._refreshValueChange(editorUnitId);
}
+ /** @deprecated */
getRichValue(id: string) {
const editor = this.getEditor(id);
if (editor == null) {
@@ -566,10 +409,12 @@ export class EditorService extends Disposable implements IEditorService, IDispos
return this._editors.get(id);
}
+ /** @deprecated */
getAllEditor() {
return this._editors;
}
+ /** @deprecated */
getFirstEditor() {
return [...this.getAllEditor().values()][0];
}
@@ -589,23 +434,27 @@ export class EditorService extends Disposable implements IEditorService, IDispos
return this.getEditor(id)?.isVisible();
}
+ /** @deprecated */
setOperationSheetUnitId(unitId: Nullable<string>) {
this._currentSheetUnitId = unitId;
}
+ /** @deprecated */
getOperationSheetUnitId() {
return this._currentSheetUnitId;
}
+ /** @deprecated */
setOperationSheetSubUnitId(sheetId: Nullable<string>) {
this._currentSheetSubUnitId = sheetId;
}
+ /** @deprecated */
getOperationSheetSubUnitId() {
return this._currentSheetSubUnitId;
}
- register(config: IEditorConfigParam, container: HTMLDivElement): IDisposable {
+ register(config: IEditorConfigParams, container: HTMLDivElement): IDisposable {
const { initialSnapshot, editorUnitId, canvasStyle = {} } = config;
const documentDataModel = this._univerInstanceService.getUnit<DocumentDataModel>(editorUnitId, UniverInstanceType.UNIVER_DOC)
@@ -624,12 +473,18 @@ export class EditorService extends Disposable implements IEditorService, IDispos
if (render) {
render.engine.setContainer(container);
- const editor = new Editor({ ...config, render, documentDataModel, editorDom: container, canvasStyle });
+ const editor = new Editor(
+ { ...config, render, documentDataModel, editorDom: container, canvasStyle },
+ this._univerInstanceService,
+ this._docSelectionManagerService,
+ this._commandService,
+ this._undoRedoService
+ );
this._editors.set(editorUnitId, editor);
- // Delete scroll bar
- // FIXME@Jocs: should add a configuration when creating a renderer, not delete it.
+ // Delete scroll bar
+ // FIXME@Jocs: should add a configuration when creating a renderer, not delete it.
(render.mainComponent?.getScene() as Scene)?.getViewports()?.[0].getScrollBar()?.dispose();
if (!editor.isSheetEditor()) {
diff --git a/packages/docs-ui/src/services/editor/editor.ts b/packages/docs-ui/src/services/editor/editor.ts
new file mode 100644
index 0000000000..10a364b09c
--- /dev/null
+++ b/packages/docs-ui/src/services/editor/editor.ts
@@ -0,0 +1,528 @@
+/**
+ * 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 { DEFAULT_STYLES, Disposable, UniverInstanceType } from '@univerjs/core';
+import { type Observable, Subject } from 'rxjs';
+import type { DocumentDataModel, ICommandService, IDocumentData, IDocumentStyle, IPosition, IUndoRedoService, IUniverInstanceService, Nullable } from '@univerjs/core';
+import type { DocSelectionManagerService } from '@univerjs/docs';
+import type { IDocSelectionInnerParam, IRender, ISuccinctDocRangeParam, ITextRangeWithStyle } from '@univerjs/engine-render';
+import { ReplaceContentCommand } from '../../commands/commands/replace-content.command';
+import { DocSelectionRenderService, type IEditorInputConfig } from '../selection/doc-selection-render.service';
+
+interface IEditorEvent {
+ target: IEditor;
+ data: IDocumentData;
+}
+
+interface IEditorInputEvent extends IEditorEvent {
+ content: string; // Returns a string with the inserted characters. This may be an empty string if the change doesn't insert text (for example, when deleting characters).
+ // Returns a Boolean value indicating if the event is fired after compositionstart and before compositionend.
+ isComposing: boolean;
+}
+
+interface IEditor {
+ // Events.
+ // Emit change event when editor lose focus.
+ change$: Observable<IEditorEvent>;
+ // The input event fires when the value of a editor has been changed as a direct result of a user action.
+ input$: Observable<IEditorInputEvent>;
+ // paste event.
+ paste$: Observable<IEditorInputConfig>;
+ // Editor get focus.
+ focus$: Observable<IEditorInputConfig>;
+ // Editor lose focus.
+ blur$: Observable<IEditorInputConfig>;
+ // Emit when doc selection changed.
+ selectionChange$: Observable<IDocSelectionInnerParam>;
+
+ // Methods
+ // The focused editor is the editor that will receive keyboard and similar events by default.
+ focus(): void;
+ // The Editor.blur() method removes keyboard focus from the current editor.
+ blur(): void;
+ // has focus.
+ isFocus(): boolean;
+ // Selects the entire content of the editor.
+ // Calling editor.select() will not necessarily focus the editor, so it is often used with Editor.focus
+ select(): void;
+ // Selects the specified range of characters within editor.
+ setSelectionRanges(ranges: ISuccinctDocRangeParam[]): void;
+ // Get current doc ranges. include text range and rect range.
+ getSelectionRanges(): ITextRangeWithStyle[];
+ // get editor id.
+ getEditorId(): string;
+ // get document data.
+ getDocumentData(): IDocumentData;
+ // Set the new document data.
+ setDocumentData(data: IDocumentData): void;
+ // Clear the undo redo history of this editor.
+ clearUndoRedoHistory(): void;
+}
+
+export interface IEditorStateParams extends Partial<IPosition> {
+ visible?: boolean;
+}
+
+export interface IEditorCanvasStyle {
+ fontSize?: number;
+}
+
+export interface IEditorConfigParams {
+ initialSnapshot?: IDocumentData;
+ cancelDefaultResizeListener?: boolean;
+ canvasStyle?: IEditorCanvasStyle;
+ // A Boolean attribute which, if present, indicates that the editor should automatically have focus.
+ // No more than one editor in the document may have the autofocus attribute.
+ // If put on more than one editor, the first one with the attribute receives focus.
+ autofocus?: boolean; // default false.
+ // Boolean. The value is not editable
+ readonly?: boolean;
+
+ // The unique id of editor.
+ editorUnitId: string;
+ /**
+ * @deprecated The implementer makes its own judgment.
+ */
+ isSheetEditor: boolean;
+ /**
+ * If the editor is for formula editing.
+ * @deprecated this is a temp fix before refactoring editor.
+ */
+ isFormulaEditor: boolean;
+ /**
+ * @deprecated The implementer makes its own judgment.
+ */
+ isSingle: boolean;
+ /**
+ * @deprecated The implementer makes its own judgment.
+ */
+ onlyInputFormula: boolean;
+ /**
+ * @deprecated The implementer makes its own judgment.
+ */
+ onlyInputRange: boolean;
+ /**
+ * @deprecated The implementer makes its own judgment.
+ */
+ onlyInputContent: boolean;
+ /**
+ * @deprecated The implementer makes its own judgment.
+ */
+ isSingleChoice: boolean;
+ /**
+ * @deprecated The implementer makes its own judgment.
+ */
+ openForSheetUnitId: Nullable<string>;
+ /**
+ * @deprecated The implementer makes its own judgment.
+ */
+ openForSheetSubUnitId: Nullable<string>;
+}
+
+export interface IEditorOptions extends IEditorConfigParams, IEditorStateParams {
+ render: IRender;
+ documentDataModel: DocumentDataModel;
+ editorDom: HTMLDivElement;
+}
+
+export class Editor extends Disposable implements IEditor {
+ // Emit change event when editor lose focus.
+ private readonly _change$ = new Subject<IEditorEvent>();
+ change$: Observable<IEditorEvent> = this._change$.asObservable();
+
+ // The input event fires when the value of a editor has been changed as a direct result of a user action.
+ private readonly _input$ = new Subject<IEditorInputEvent>();
+ input$: Observable<IEditorInputEvent> = this._input$.asObservable();
+
+ // paste event.
+ private readonly _paste$ = new Subject<IEditorInputConfig>();
+ paste$: Observable<IEditorInputConfig> = this._paste$.asObservable();
+
+ // Editor get focus.
+ private _focus = false;
+ private readonly _focus$ = new Subject<IEditorInputConfig>();
+ focus$: Observable<IEditorInputConfig> = this._focus$.asObservable();
+
+ // Editor lose focus.
+ private readonly _blur$ = new Subject<IEditorInputConfig>();
+ blur$: Observable<IEditorInputConfig> = this._blur$.asObservable();
+
+ // Emit when doc selection changed.
+ private readonly _selectionChange$ = new Subject<IDocSelectionInnerParam>();
+ selectionChange$: Observable<IDocSelectionInnerParam> = this._selectionChange$.asObservable();
+
+ private _valueLegality = true;
+
+ private _openForSheetUnitId: Nullable<string>;
+
+ private _openForSheetSubUnitId: Nullable<string>;
+
+ constructor(
+ private _param: IEditorOptions,
+ private _univerInstanceService: IUniverInstanceService,
+ private _docSelectionManagerService: DocSelectionManagerService,
+ private _commandService: ICommandService,
+ private _undoRedoService: IUndoRedoService
+ ) {
+ super();
+ this._openForSheetUnitId = this._param.openForSheetUnitId;
+ this._openForSheetSubUnitId = this._param.openForSheetSubUnitId;
+
+ this._listenSelection();
+ }
+
+ private _listenSelection() {
+ const docSelectionRenderService = this._param.render.with(DocSelectionRenderService);
+
+ this.disposeWithMe(
+ docSelectionRenderService.onBlur$.subscribe((e) => {
+ this._blur$.next(e);
+
+ const data = this.getDocumentData();
+
+ this._change$.next({
+ target: this,
+ data,
+ });
+ })
+ );
+
+ this.disposeWithMe(
+ docSelectionRenderService.onFocus$.subscribe((e) => {
+ this._focus$.next(e);
+ })
+ );
+
+ this.disposeWithMe(
+ docSelectionRenderService.onPaste$.subscribe((e) => {
+ this._paste$.next(e);
+ })
+ );
+
+ this.disposeWithMe(
+ docSelectionRenderService.onInput$.subscribe((e) => {
+ const { content = '' } = e;
+ const data = this.getDocumentData();
+
+ this._input$.next({
+ target: this,
+ content,
+ data,
+ isComposing: false,
+ });
+ })
+ );
+
+ this.disposeWithMe(
+ this._docSelectionManagerService.textSelection$.subscribe((e) => {
+ if (e == null) {
+ return;
+ }
+
+ const { unitId, subUnitId, ...params } = e;
+ const editorId = this.getEditorId();
+
+ if (unitId === editorId) {
+ this._selectionChange$.next(params);
+ }
+ })
+ );
+ }
+
+ focus() {
+ const curDoc = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
+ const editorUnitId = this.getEditorId();
+ // Step 1: set current editor to currentDocUnit.
+ if (curDoc == null || curDoc.getUnitId() !== editorUnitId) {
+ this._univerInstanceService.setCurrentUnitForType(editorUnitId);
+ }
+
+ // Step 2: Focus this input element.
+ const docSelectionRenderService = this._param.render.with(DocSelectionRenderService);
+ docSelectionRenderService.focus();
+
+ // Step 3: Sets the selection of the last selection, and if not, to the beginning of the document.
+ const lastSelectionInfo = this._docSelectionManagerService.getDocRanges({
+ unitId: editorUnitId,
+ subUnitId: editorUnitId,
+ });
+
+ if (lastSelectionInfo) {
+ this._docSelectionManagerService.replaceDocRanges(lastSelectionInfo, {
+ unitId: editorUnitId,
+ subUnitId: editorUnitId,
+ }, false);
+ }
+
+ this._focus = true;
+ }
+
+ blur(): void {
+ const docSelectionRenderService = this._param.render.with(DocSelectionRenderService);
+
+ docSelectionRenderService.blur();
+
+ this._focus = false;
+ }
+
+ // Selects the entire content of the editor.
+ // Calling editor.select() will not necessarily focus the editor, so it is often used with Editor.focus
+ select(): void {
+ const documentData = this.getDocumentData();
+
+ return this.setSelectionRanges([{
+ startOffset: 0,
+ endOffset: documentData.body ? documentData.body.dataStream.length - 2 : 0,
+ }]);
+ }
+
+ // Selects the specified range of characters within editor.
+ setSelectionRanges(ranges: ISuccinctDocRangeParam[]): void {
+ const editorUnitId = this.getEditorId();
+ const params = {
+ unitId: editorUnitId,
+ subUnitId: editorUnitId,
+ };
+
+ return this._docSelectionManagerService.replaceDocRanges(ranges, params, false);
+ }
+
+ // Get current doc ranges. include text range and rect range.
+ getSelectionRanges(): ITextRangeWithStyle[] {
+ const editorUnitId = this.getEditorId();
+ const params = {
+ unitId: editorUnitId,
+ subUnitId: editorUnitId,
+ };
+
+ return this._docSelectionManagerService.getDocRanges(params);
+ }
+
+ // get editor id.
+ getEditorId(): string {
+ return this._param.editorUnitId;
+ }
+
+ // get document data.
+ getDocumentData(): IDocumentData {
+ const editorUnitId = this.getEditorId();
+ const docDataModel = this._univerInstanceService.getUnit<DocumentDataModel>(editorUnitId, UniverInstanceType.UNIVER_DOC)!;
+
+ return docDataModel.getSnapshot();
+ }
+
+ // Set the new document data.
+ setDocumentData(data: IDocumentData, textRanges: Nullable<ITextRangeWithStyle[]>) {
+ const { id, body } = data;
+
+ this._commandService.executeCommand(ReplaceContentCommand.id, {
+ unitId: id,
+ body,
+ textRanges,
+ });
+ }
+
+ // Clear the undo redo history of this editor.
+ clearUndoRedoHistory(): void {
+ const editorUnitId = this.getEditorId();
+
+ return this._undoRedoService.clearUndoRedo(editorUnitId);
+ }
+
+ /**
+ * @deprecated use getDocumentData.
+ */
+ get documentDataModel() {
+ return this._param.documentDataModel;
+ }
+
+ /**
+ * @deprecated use getEditorId.
+ */
+ get editorUnitId() {
+ return this._param.editorUnitId;
+ }
+
+ get cancelDefaultResizeListener() {
+ return this._param.cancelDefaultResizeListener;
+ }
+
+ get render() {
+ return this._param.render;
+ }
+
+ isSingleChoice() {
+ return this._param.isSingleChoice;
+ }
+
+ /** @deprecated */
+ setOpenForSheetUnitId(unitId: Nullable<string>) {
+ this._openForSheetUnitId = unitId;
+ }
+
+ /** @deprecated */
+ getOpenForSheetUnitId() {
+ return this._openForSheetUnitId;
+ }
+
+ /** @deprecated */
+ setOpenForSheetSubUnitId(subUnitId: Nullable<string>) {
+ this._openForSheetSubUnitId = subUnitId;
+ }
+
+ /** @deprecated */
+ getOpenForSheetSubUnitId() {
+ return this._openForSheetSubUnitId;
+ }
+
+ /** @deprecated */
+ isValueLegality() {
+ return this._valueLegality === true;
+ }
+
+ /** @deprecated */
+ setValueLegality(state = true) {
+ this._valueLegality = state;
+ }
+
+ isFocus() {
+ return this._focus;
+ }
+
+ /** @deprecated */
+ setFocus(state = false) {
+ this._focus = state;
+ }
+
+ /** @deprecated */
+ isSingle() {
+ return this._param.isSingle === true || this.onlyInputRange();
+ }
+
+ isReadOnly() {
+ return this._param.readonly === true;
+ }
+
+ /** @deprecated */
+ onlyInputContent() {
+ return this._param.onlyInputContent === true;
+ }
+
+ /** @deprecated */
+ onlyInputFormula() {
+ return this._param.onlyInputFormula === true;
+ }
+
+ /** @deprecated */
+ onlyInputRange() {
+ return this._param.onlyInputRange === true;
+ }
+
+ getBoundingClientRect() {
+ return this._param.editorDom.getBoundingClientRect();
+ }
+
+ isVisible() {
+ return this._param.visible;
+ }
+
+ /** @deprecated */
+ isSheetEditor() {
+ return this._param.isSheetEditor === true;
+ }
+
+ /** @deprecated */
+ isFormulaEditor() {
+ return this._param.isFormulaEditor === true;
+ }
+
+ /**
+ * @deprecated use getDocumentData.
+ */
+ getValue() {
+ const value = this._param.documentDataModel.getBody()?.dataStream || '';
+ return value.replace(/\r\n/g, '').replace(/\n/g, '').replace(/\n/g, '');
+ }
+
+ /**
+ * @deprecated use getDocumentData.
+ */
+ getBody() {
+ return this._param.documentDataModel.getBody();
+ }
+
+ /**
+ * @deprecated.
+ */
+ update(param: Partial<IEditorOptions>) {
+ this._param = {
+ ...this._param,
+ ...param,
+ };
+ }
+
+ verticalAlign() {
+ const documentDataModel = this._param?.documentDataModel;
+
+ if (documentDataModel == null) {
+ return;
+ }
+
+ const { width, height } = this._param.editorDom.getBoundingClientRect();
+
+ if (height === 0 || width === 0) {
+ return;
+ }
+
+ if (!this.isSingle()) {
+ documentDataModel.updateDocumentDataPageSize(width, undefined);
+ return;
+ }
+
+ let fontSize = DEFAULT_STYLES.fs;
+
+ if (this._param.canvasStyle?.fontSize) {
+ fontSize = this._param.canvasStyle.fontSize;
+ }
+
+ const top = (height - (fontSize * 4 / 3)) / 2 - 2;
+
+ documentDataModel.updateDocumentDataMargin({
+ t: top < 0 ? 0 : top,
+ });
+
+ documentDataModel.updateDocumentDataPageSize(undefined, undefined);
+ }
+
+ updateCanvasStyle() {
+ const documentDataModel = this._param.documentDataModel;
+ if (documentDataModel == null) {
+ return;
+ }
+
+ const documentStyle: IDocumentStyle = {};
+
+ if (this._param.canvasStyle?.fontSize) {
+ if (documentStyle.textStyle == null) {
+ documentStyle.textStyle = {};
+ }
+
+ documentStyle.textStyle.fs = this._param.canvasStyle.fontSize;
+ }
+
+ documentDataModel.updateDocumentStyle(documentStyle);
+ }
+}
diff --git a/packages/ui/src/services/range-selector/range-selector.service.ts b/packages/docs-ui/src/services/range-selector/range-selector.service.ts
similarity index 100%
rename from packages/ui/src/services/range-selector/range-selector.service.ts
rename to packages/docs-ui/src/services/range-selector/range-selector.service.ts
index 5d2d2f35b1..efea722f27 100644
--- a/packages/ui/src/services/range-selector/range-selector.service.ts
+++ b/packages/docs-ui/src/services/range-selector/range-selector.service.ts
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-import type { IDisposable, IUnitRange, Nullable } from '@univerjs/core';
import { createIdentifier, Disposable } from '@univerjs/core';
-import type { Observable } from 'rxjs';
import { BehaviorSubject, Subject } from 'rxjs';
+import type { IDisposable, IUnitRange, Nullable } from '@univerjs/core';
+import type { Observable } from 'rxjs';
export interface IRangeSelectorRange extends IUnitRange {
sheetName: string;
diff --git a/packages/docs-ui/src/services/selection/doc-selection-render.service.ts b/packages/docs-ui/src/services/selection/doc-selection-render.service.ts
index 2c3438eb29..4d5917a6d8 100644
--- a/packages/docs-ui/src/services/selection/doc-selection-render.service.ts
+++ b/packages/docs-ui/src/services/selection/doc-selection-render.service.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import { DataStreamTreeTokenType, DOC_RANGE_TYPE, ILogService, Inject, RxDisposable } from '@univerjs/core';
+import { DataStreamTreeTokenType, DOC_RANGE_TYPE, ILogService, Inject, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
import { DocSkeletonManagerService } from '@univerjs/docs';
import { CURSOR_TYPE, getSystemHighlightColor, NORMAL_TEXT_SELECTION_PLUGIN_STYLE, PageLayoutType, ScrollTimer, Vector2 } from '@univerjs/engine-render';
import { ILayoutService } from '@univerjs/ui';
-import { BehaviorSubject, fromEvent, Subject } from 'rxjs';
+import { BehaviorSubject, fromEvent, Subject, takeUntil } from 'rxjs';
import type { DocumentDataModel, Nullable } from '@univerjs/core';
import type { Documents, Engine, IDocSelectionInnerParam, IFindNodeRestrictions, IMouseEvent, INodeInfo, INodePosition, IPointerEvent, IRenderContext, IRenderModule, IScrollObserverParam, ISuccinctDocRangeParam, ITextRangeWithStyle, ITextSelectionStyle } from '@univerjs/engine-render';
import type { Subscription } from 'rxjs';
@@ -40,7 +40,7 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
private readonly _onKeydown$ = new BehaviorSubject<Nullable<IEditorInputConfig>>(null);
readonly onKeydown$ = this._onKeydown$.asObservable();
- private readonly _onInput$ = new BehaviorSubject<Nullable<IEditorInputConfig>>(null);
+ private readonly _onInput$ = new Subject<IEditorInputConfig>();
readonly onInput$ = this._onInput$.asObservable();
private readonly _onCompositionstart$ = new BehaviorSubject<Nullable<IEditorInputConfig>>(null);
@@ -55,16 +55,16 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
private readonly _onSelectionStart$ = new BehaviorSubject<Nullable<INodePosition>>(null);
readonly onSelectionStart$ = this._onSelectionStart$.asObservable();
- private readonly _onPaste$ = new Subject<Nullable<IEditorInputConfig>>();
+ private readonly _onPaste$ = new Subject<IEditorInputConfig>();
readonly onPaste$ = this._onPaste$.asObservable();
private readonly _textSelectionInner$ = new BehaviorSubject<Nullable<IDocSelectionInnerParam>>(null);
readonly textSelectionInner$ = this._textSelectionInner$.asObservable();
- private readonly _onFocus$ = new Subject<Nullable<IEditorInputConfig>>();
+ private readonly _onFocus$ = new Subject<IEditorInputConfig>();
readonly onFocus$ = this._onFocus$.asObservable();
- private readonly _onBlur$ = new Subject<Nullable<IEditorInputConfig>>();
+ private readonly _onBlur$ = new Subject<IEditorInputConfig>();
readonly onBlur$ = this._onBlur$.asObservable();
private readonly _onPointerDown$ = new Subject<void>();
@@ -100,17 +100,37 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
private _scenePointerMoveSubs: Array<Subscription> = [];
private _scenePointerUpSubs: Array<Subscription> = [];
private _editorFocusing = true;
+ // When the user switches editors, whether to clear the doc ranges.
+ private _reserveRanges = false;
constructor(
private readonly _context: IRenderContext<DocumentDataModel>,
@ILayoutService private readonly _layoutService: ILayoutService,
@ILogService private readonly _logService: ILogService,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@Inject(DocSkeletonManagerService) private readonly _docSkeletonManagerService: DocSkeletonManagerService
) {
super();
this._initDOM();
this._registerContainer();
this._setSystemHighlightColorToStyle();
+ this._listenCurrentUnitChange();
+ }
+
+ private _listenCurrentUnitChange() {
+ this._univerInstanceService.getCurrentTypeOfUnit$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)
+ .pipe(takeUntil(this.dispose$))
+ .subscribe((documentModel) => {
+ if (documentModel == null) {
+ return;
+ }
+
+ const unitId = documentModel.getUnitId();
+
+ if (unitId !== this._context.unitId && !this._reserveRanges) {
+ this.removeAllRanges();
+ }
+ });
}
get activeViewPort() {
@@ -133,6 +153,10 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
return this._currentSegmentPage;
}
+ setReserveRangesStatus(status: boolean) {
+ this._reserveRanges = status;
+ }
+
private _setRangeStyle(style: ITextSelectionStyle = NORMAL_TEXT_SELECTION_PLUGIN_STYLE) {
this._selectionStyle = style;
}
@@ -235,6 +259,9 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
this._updateInputPosition();
}
+ /**
+ * @deprecated
+ */
activate(x: number, y: number, force = false) {
const isFocusing = this._input === document.activeElement;
this._container.style.left = `${x}px`;
@@ -261,17 +288,26 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
this._input.blur();
}
+ /**
+ * @deprecated
+ */
focusEditor(): void {
this._editorFocusing = true;
this.focus();
}
+ /**
+ * @deprecated
+ */
blurEditor(): void {
this._editorFocusing = false;
this.blur();
}
// FIXME: for editor cell editor we don't need to blur the input element
+ /**
+ * @deprecated
+ */
deactivate() {
this._container.style.left = '0px';
this._container.style.top = '0px';
@@ -670,6 +706,20 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
this._rectRangeList = newRanges;
}
+ private _removeCollapsedTextRange() {
+ const oldTextRanges = this._rangeList;
+
+ this._rangeList = [];
+
+ for (const textRange of oldTextRanges) {
+ if (textRange.collapsed) {
+ textRange.dispose();
+ } else {
+ this._rangeList.push(textRange);
+ }
+ }
+ }
+
private _removeAllRanges() {
this._removeAllTextRanges();
this._removeAllRectRanges();
@@ -1049,13 +1099,13 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
})
);
- this.disposeWithMe(
- fromEvent(this._input, 'pointerdown').subscribe((e) => {
- this._eventHandle(e, () => {
- this._onBlur$.next();
- });
- })
- );
+ // this.disposeWithMe(
+ // fromEvent(this._input, 'pointerdown').subscribe((e) => {
+ // this._eventHandle(e, () => {
+ // this._onBlur$.next();
+ // });
+ // })
+ // );
this.disposeWithMe(
fromEvent(this._input, 'blur').subscribe((e) => {
@@ -1137,3 +1187,4 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
this._onPointerDown$.complete();
}
}
+
diff --git a/packages/docs/src/doc-plugin.ts b/packages/docs/src/doc-plugin.ts
index f0eb2a4d8e..a5767ef3ff 100644
--- a/packages/docs/src/doc-plugin.ts
+++ b/packages/docs/src/doc-plugin.ts
@@ -20,7 +20,6 @@ import {
Inject,
Injector,
Plugin,
- UniverInstanceType,
} from '@univerjs/core';
import type { Dependency, ICommand } from '@univerjs/core';
import { RichTextEditingMutation } from './commands/mutations/core-editing.mutation';
@@ -36,7 +35,7 @@ const PLUGIN_NAME = 'DOCS_PLUGIN';
export class UniverDocsPlugin extends Plugin {
static override pluginName = PLUGIN_NAME;
- static override type = UniverInstanceType.UNIVER_DOC;
+ // static override type = UniverInstanceType.UNIVER_DOC;
constructor(
private readonly _config: Partial<IUniverDocsConfig> = defaultPluginConfig,
diff --git a/packages/docs/src/services/doc-selection-manager.service.ts b/packages/docs/src/services/doc-selection-manager.service.ts
index 34edf3a34a..2b5f0b6333 100644
--- a/packages/docs/src/services/doc-selection-manager.service.ts
+++ b/packages/docs/src/services/doc-selection-manager.service.ts
@@ -39,7 +39,7 @@ export interface IRefreshSelectionParam extends IDocSelectionManagerSearchParam
};
}
-interface ITextSelectionManagerInsertParam extends IDocSelectionManagerSearchParam, IDocSelectionInnerParam {}
+export interface ITextSelectionManagerInsertParam extends IDocSelectionManagerSearchParam, IDocSelectionInnerParam {}
type ITextSelectionInfo = Map<string, Map<string, IDocSelectionInnerParam>>;
@@ -83,44 +83,46 @@ export class DocSelectionManagerService extends RxDisposable {
});
}
- getCurrentSelection() {
+ __getCurrentSelection() {
return this._currentSelection;
}
- // Get textRanges, style, segmentId
- /**
- * @deprecated
- */
- getCurrentSelectionInfo() {
- return this._getTextRanges(this._currentSelection);
+ getSelectionInfo(params: Nullable<IDocSelectionManagerSearchParam> = this._currentSelection) {
+ return this._getTextRanges(params);
}
- refreshSelection() {
- if (this._currentSelection == null) {
+ refreshSelection(params: Nullable<IDocSelectionManagerSearchParam> = this._currentSelection) {
+ if (params == null) {
return;
}
- this._refresh(this._currentSelection);
+ this._refresh(params);
}
// **Only used in test case** because this does not go through the render layer.
- setCurrentSelection(param: IDocSelectionManagerSearchParam) {
+ __TEST_ONLY_setCurrentSelection(param: IDocSelectionManagerSearchParam) {
this._currentSelection = param;
this._refresh(param);
}
- getCurrentTextRanges(): Readonly<Nullable<ITextRangeWithStyle[]>> {
- return this._getTextRanges(this._currentSelection)?.textRanges;
+ getTextRanges(
+ params: Nullable<IDocSelectionManagerSearchParam> = this._currentSelection
+ ): Readonly<Nullable<ITextRangeWithStyle[]>> {
+ return this._getTextRanges(params)?.textRanges;
}
- getCurrentRectRanges(): Readonly<Nullable<IRectRangeWithStyle[]>> {
- return this._getTextRanges(this._currentSelection)?.rectRanges;
+ getRectRanges(
+ params: Nullable<IDocSelectionManagerSearchParam> = this._currentSelection
+ ): Readonly<Nullable<IRectRangeWithStyle[]>> {
+ return this._getTextRanges(params)?.rectRanges;
}
- getDocRanges() {
- const textRanges = this.getCurrentTextRanges() ?? [];
- const rectRanges = this.getCurrentRectRanges() ?? [];
+ getDocRanges(
+ params: Nullable<IDocSelectionManagerSearchParam> = this._currentSelection
+ ) {
+ const textRanges = this.getTextRanges(params) ?? [];
+ const rectRanges = this.getRectRanges(params) ?? [];
// Sort ranges by startOffset in ascending order.
const allRanges = [...textRanges, ...rectRanges]
.filter((range) => range.startOffset != null && range.endOffset != null)
@@ -163,7 +165,7 @@ export class DocSelectionManagerService extends RxDisposable {
}
// **Only used in test case** because this does not go through the render layer.
- add(textRanges: ITextRangeWithStyle[], isEditing = true) {
+ __TEST_ONLY_add(textRanges: ITextRangeWithStyle[], isEditing = true) {
if (this._currentSelection == null) {
return;
}
@@ -179,15 +181,37 @@ export class DocSelectionManagerService extends RxDisposable {
});
}
- replaceTextRanges(docRanges: ISuccinctDocRangeParam[], isEditing = true, options?: { [key: string]: boolean }) {
- if (this._currentSelection == null) {
+ // Use to replace the current editor selection.
+ /**
+ * @deprecated pls use replaceDocRanges.
+ */
+ replaceTextRanges(
+ docRanges: ISuccinctDocRangeParam[],
+ isEditing = true,
+ options?: { [key: string]: boolean }
+ ) {
+ return this.replaceDocRanges(
+ docRanges,
+ this._currentSelection,
+ isEditing,
+ options
+ );
+ }
+
+ replaceDocRanges(
+ docRanges: ISuccinctDocRangeParam[],
+ params: Nullable<IDocSelectionManagerSearchParam> = this._currentSelection,
+ isEditing = true,
+ options?: { [key: string]: boolean }
+ ) {
+ if (params == null) {
return;
}
// Remove all textRanges.
// Add new textRanges.
- const { unitId, subUnitId } = this._currentSelection;
+ const { unitId, subUnitId } = params;
this._refreshSelection$.next({
unitId,
@@ -245,21 +269,7 @@ export class DocSelectionManagerService extends RxDisposable {
}
private _setCurrentSelectionNotRefresh(param: IDocSelectionManagerSearchParam) {
- const { unitId, subUnitId } = this._currentSelection ?? {};
- const { unitId: newUnitId, subUnitId: newSubUnitId } = param;
-
- if (unitId !== newUnitId || subUnitId !== newSubUnitId) {
- if (unitId && subUnitId) {
- this._refreshSelection$.next({
- unitId,
- subUnitId,
- docRanges: [],
- isEditing: false,
- });
- }
-
- this._currentSelection = param;
- }
+ this._currentSelection = param;
}
private _getTextRanges(param: Nullable<IDocSelectionManagerSearchParam>) {
diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts
index a7c05c87b0..58bb538d79 100644
--- a/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts
+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/line-adjustment.ts
@@ -14,17 +14,17 @@
* limitations under the License.
*/
-import type { IParagraphStyle } from '@univerjs/core';
import { HorizontalAlign } from '@univerjs/core';
-import type { IDocumentSkeletonDivide, IDocumentSkeletonLine, IDocumentSkeletonPage } from '../../../../../basics/i-document-skeleton-cached';
-import { getFontConfigFromLastGlyph, getGlyphGroupWidth, lineIterator } from '../../tools';
-import { createHyphenDashGlyph, glyphShrinkLeft, glyphShrinkRight, setGlyphGroupLeft } from '../../model/glyph';
+import type { IParagraphStyle } from '@univerjs/core';
import { hasCJK, hasCJKText, isCjkLeftAlignedPunctuation, isCjkRightAlignedPunctuation } from '../../../../../basics/tools';
import { BreakPointType } from '../../line-breaker/break';
-import type { DocumentViewModel } from '../../../view-model/document-view-model';
-import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';
-import type { ISectionBreakConfig } from '../../../../../basics';
import { isLetter } from '../../line-breaker/enhancers/utils';
+import { createHyphenDashGlyph, glyphShrinkLeft, glyphShrinkRight, setGlyphGroupLeft } from '../../model/glyph';
+import { getFontConfigFromLastGlyph, getGlyphGroupWidth, lineIterator } from '../../tools';
+import type { ISectionBreakConfig } from '../../../../../basics';
+import type { IDocumentSkeletonDivide, IDocumentSkeletonLine, IDocumentSkeletonPage } from '../../../../../basics/i-document-skeleton-cached';
+import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';
+import type { DocumentViewModel } from '../../../view-model/document-view-model';
// How much a character should hang into the end margin.
// For more discussion, see:
diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/paragraph-layout.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/paragraph-layout.ts
index 47a88d02a3..fdf03593ab 100644
--- a/packages/engine-render/src/components/docs/layout/block/paragraph/paragraph-layout.ts
+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/paragraph-layout.ts
@@ -15,16 +15,16 @@
*/
import { DataStreamTreeNodeType } from '@univerjs/core';
+import { clearFontCreateConfigCache } from '../../tools';
+import { createTableSkeleton } from '../table';
+import { lineAdjustment } from './line-adjustment';
+import { lineBreaking } from './linebreaking';
+import { shaping } from './shaping';
import type { IDocumentSkeletonPage } from '../../../../../basics/i-document-skeleton-cached';
import type { ISectionBreakConfig } from '../../../../../basics/interfaces';
-import type { ILayoutContext } from '../../tools';
-import { clearFontCreateConfigCache } from '../../tools';
import type { DataStreamTreeNode } from '../../../view-model/data-stream-tree-node';
import type { DocumentViewModel } from '../../../view-model/document-view-model';
-import { createTableSkeleton } from '../table';
-import { shaping } from './shaping';
-import { lineBreaking } from './linebreaking';
-import { lineAdjustment } from './line-adjustment';
+import type { ILayoutContext } from '../../tools';
export function dealWidthParagraph(
ctx: ILayoutContext,
diff --git a/packages/sheets-conditional-formatting-ui/package.json b/packages/sheets-conditional-formatting-ui/package.json
index ca484a2ba4..2328c26294 100644
--- a/packages/sheets-conditional-formatting-ui/package.json
+++ b/packages/sheets-conditional-formatting-ui/package.json
@@ -67,6 +67,7 @@
"peerDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
+ "@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/sheets": "workspace:*",
@@ -81,6 +82,7 @@
"dependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
+ "@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons": "^0.1.78",
diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/colorScale.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/colorScale.tsx
index eb3cf25bca..81ad9b0c73 100644
--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/colorScale.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/colorScale.tsx
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-import React, { useEffect, useMemo, useState } from 'react';
import { createInternalEditorID, IUniverInstanceService, LocaleService, UniverInstanceType, useDependency } from '@univerjs/core';
-import type { Workbook } from '@univerjs/core';
import { InputNumber, Select } from '@univerjs/design';
-import { TextEditor } from '@univerjs/ui';
+import { TextEditor } from '@univerjs/docs-ui';
import { CFRuleType, CFValueType, createDefaultValueByValueType, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';
+import React, { useEffect, useMemo, useState } from 'react';
+import type { Workbook } from '@univerjs/core';
import type { IColorScale, IConditionalFormattingRuleConfig } from '@univerjs/sheets-conditional-formatting';
import { ColorPicker } from '../../color-picker';
-import stylesBase from '../index.module.less';
import { Preview } from '../../preview';
+import stylesBase from '../index.module.less';
import styles from './index.module.less';
import type { IStyleEditorProps } from './type';
diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsx
index 7b187cdbeb..13ab223ea1 100644
--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsx
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-import React, { useEffect, useMemo, useRef, useState } from 'react';
-import { Checkbox, InputNumber, Radio, RadioGroup, Select } from '@univerjs/design';
import { createInternalEditorID, IUniverInstanceService, LocaleService, UniverInstanceType, useDependency } from '@univerjs/core';
-import type { Workbook } from '@univerjs/core';
-import { TextEditor } from '@univerjs/ui';
+import { Checkbox, InputNumber, Radio, RadioGroup, Select } from '@univerjs/design';
+import { TextEditor } from '@univerjs/docs-ui';
import { CFRuleType, CFValueType, createDefaultValueByValueType, defaultDataBarNativeColor, defaultDataBarPositiveColor, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';
+import React, { useEffect, useMemo, useRef, useState } from 'react';
+import type { Workbook } from '@univerjs/core';
import type { IConditionalFormattingRuleConfig, IValueConfig } from '@univerjs/sheets-conditional-formatting';
import { ColorPicker } from '../../color-picker';
-import stylesBase from '../index.module.less';
import { Preview } from '../../preview';
+import stylesBase from '../index.module.less';
import styles from './index.module.less';
import type { IStyleEditorProps } from './type';
diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/formula.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/formula.tsx
index 3d24d20242..de856e3d6a 100644
--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/formula.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/formula.tsx
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-import React, { useEffect, useState } from 'react';
import { createInternalEditorID, IUniverInstanceService, LocaleService, UniverInstanceType, useDependency } from '@univerjs/core';
-import type { Workbook } from '@univerjs/core';
-import { TextEditor } from '@univerjs/ui';
+import { TextEditor } from '@univerjs/docs-ui';
import { CFRuleType, CFSubRuleType, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';
+import React, { useEffect, useState } from 'react';
+import type { Workbook } from '@univerjs/core';
import type { IAverageHighlightCell, IConditionalFormattingRuleConfig, IHighlightCell, IRankHighlightCell } from '@univerjs/sheets-conditional-formatting';
import { ConditionalStyleEditor } from '../../conditional-style-editor';
-import stylesBase from '../index.module.less';
import { Preview } from '../../preview';
import { WrapperError } from '../../wrapper-error/WrapperError';
+import stylesBase from '../index.module.less';
import styles from './index.module.less';
import type { IStyleEditorProps } from './type';
diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/iconSet.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/iconSet.tsx
index 5eab1b8608..a6bae92a69 100644
--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/iconSet.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/iconSet.tsx
@@ -14,22 +14,23 @@
* limitations under the License.
*/
-import React, { forwardRef, useEffect, useMemo, useState } from 'react';
-import set from 'lodash.set';
-import get from 'lodash.get';
+import { createInternalEditorID, IUniverInstanceService, LocaleService, Tools, UniverInstanceType, useDependency } from '@univerjs/core';
+import { Checkbox, Dropdown, InputNumber, Select } from '@univerjs/design';
+import { TextEditor } from '@univerjs/docs-ui';
import { MoreDownSingle, SlashSingle } from '@univerjs/icons';
-import { Checkbox, Dropdown, InputNumber, Select } from '@univerjs/design';
-import { createInternalEditorID, IUniverInstanceService, LocaleService, Tools, UniverInstanceType, useDependency } from '@univerjs/core';
+import { CFNumberOperator, CFRuleType, CFSubRuleType, CFValueType, compareWithNumber, createDefaultValue, EMPTY_ICON_TYPE, getOppositeOperator, iconGroup, iconMap, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';
+import { ILayoutService, useScrollYOverContainer } from '@univerjs/ui';
+import get from 'lodash.get';
+import set from 'lodash.set';
+import React, { forwardRef, useEffect, useMemo, useState } from 'react';
import type { Workbook } from '@univerjs/core';
-import { ILayoutService, TextEditor, useScrollYOverContainer } from '@univerjs/ui';
import type { IIconSet, IIconType } from '@univerjs/sheets-conditional-formatting';
-import { CFNumberOperator, CFRuleType, CFSubRuleType, CFValueType, compareWithNumber, createDefaultValue, EMPTY_ICON_TYPE, getOppositeOperator, iconGroup, iconMap, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';
import stylesBase from '../index.module.less';
-import type { IStyleEditorProps } from './type';
import styles from './index.module.less';
+import type { IStyleEditorProps } from './type';
const getIcon = (iconType: string, iconId: string | number) => {
const arr = iconMap[iconType] || [];
diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx
index f893746893..c807274397 100644
--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx
@@ -14,32 +14,32 @@
* limitations under the License.
*/
-import React, { useEffect, useMemo, useRef, useState } from 'react';
-import type { IRange, IUnitRange, Workbook } from '@univerjs/core';
import { createInternalEditorID, ICommandService, InterceptorManager, IUniverInstanceService, LocaleService, UniverInstanceType, useDependency } from '@univerjs/core';
-import { serializeRange } from '@univerjs/engine-formula';
import { Button, Select } from '@univerjs/design';
+import { RangeSelector } from '@univerjs/docs-ui';
+import { serializeRange } from '@univerjs/engine-formula';
+import { RemoveSheetMutation, setEndForRange, SetWorksheetActiveOperation, SheetsSelectionsService } from '@univerjs/sheets';
-import { RangeSelector } from '@univerjs/ui';
+import { CFRuleType, CFSubRuleType, ConditionalFormattingRuleModel, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';
+import React, { useEffect, useMemo, useRef, useState } from 'react';
+import type { IRange, IUnitRange, Workbook } from '@univerjs/core';
import type { IRemoveSheetMutationParams } from '@univerjs/sheets';
-import { RemoveSheetMutation, setEndForRange, SetWorksheetActiveOperation, SheetsSelectionsService } from '@univerjs/sheets';
import type { IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';
-import { CFRuleType, CFSubRuleType, ConditionalFormattingRuleModel, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';
-import type { IAddCfCommandParams } from '../../../commands/commands/add-cf.command';
import { AddCfCommand } from '../../../commands/commands/add-cf.command';
-import type { ISetCfCommandParams } from '../../../commands/commands/set-cf.command';
import { SetCfCommand } from '../../../commands/commands/set-cf.command';
-
import styleBase from '../index.module.less';
-import type { IStyleEditorProps } from './type';
-import { beforeSubmit, submit } from './type';
import { ColorScaleStyleEditor } from './colorScale';
+
import { DataBarStyleEditor } from './dataBar';
-import { RankStyleEditor } from './rank';
-import { HighlightCellStyleEditor } from './highlightCell';
import { FormulaStyleEditor } from './formula';
-import styles from './index.module.less';
+import { HighlightCellStyleEditor } from './highlightCell';
import { IconSet } from './iconSet';
+import styles from './index.module.less';
+import { RankStyleEditor } from './rank';
+import { beforeSubmit, submit } from './type';
+import type { IAddCfCommandParams } from '../../../commands/commands/add-cf.command';
+import type { ISetCfCommandParams } from '../../../commands/commands/set-cf.command';
+import type { IStyleEditorProps } from './type';
interface IRuleEditProps {
rule?: IConditionFormattingRule;
diff --git a/packages/sheets-data-validation/src/views/detail/index.tsx b/packages/sheets-data-validation/src/views/detail/index.tsx
index 048b39d61f..862fad3bb3 100644
--- a/packages/sheets-data-validation/src/views/detail/index.tsx
+++ b/packages/sheets-data-validation/src/views/detail/index.tsx
@@ -17,8 +17,9 @@
import { createInternalEditorID, debounce, ICommandService, isUnitRangesEqual, isValidRange, LocaleService, RedoCommand, shallowEqual, UndoCommand, useDependency } from '@univerjs/core';
import { DataValidationModel, DataValidatorRegistryScope, DataValidatorRegistryService, getRuleOptions, getRuleSetting, TWO_FORMULA_OPERATOR_COUNT } from '@univerjs/data-validation';
import { Button, FormLayout, Select } from '@univerjs/design';
+import { RangeSelector } from '@univerjs/docs-ui';
import { serializeRange } from '@univerjs/engine-formula';
-import { ComponentManager, RangeSelector, useEvent, useObservable } from '@univerjs/ui';
+import { ComponentManager, useEvent, useObservable } from '@univerjs/ui';
import React, { useEffect, useMemo, useState } from 'react';
import type { DataValidationOperator, DataValidationType, IDataValidationRuleBase, IDataValidationRuleOptions, IExecutionOptions, ISheetDataValidationRule, IUnitRange } from '@univerjs/core';
import { RemoveSheetDataValidationCommand, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand } from '../../commands/commands/data-validation.command';
diff --git a/packages/sheets-data-validation/src/views/formula-input/custom-formula-input.tsx b/packages/sheets-data-validation/src/views/formula-input/custom-formula-input.tsx
index 47990fb220..570e8c921e 100644
--- a/packages/sheets-data-validation/src/views/formula-input/custom-formula-input.tsx
+++ b/packages/sheets-data-validation/src/views/formula-input/custom-formula-input.tsx
@@ -14,12 +14,12 @@
* limitations under the License.
*/
+import { createInternalEditorID } from '@univerjs/core';
import { FormLayout } from '@univerjs/design';
-import React from 'react';
-import { TextEditor } from '@univerjs/ui';
+import { TextEditor } from '@univerjs/docs-ui';
+import React from 'react';
import type { IFormulaInputProps } from '@univerjs/data-validation';
-import { createInternalEditorID } from '@univerjs/core';
export function CustomFormulaInput(props: IFormulaInputProps) {
const { unitId, subUnitId, value, onChange, showError, validResult } = props;
diff --git a/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx b/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx
index ef6075cbf1..6e34bb3757 100644
--- a/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx
+++ b/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx
@@ -14,19 +14,20 @@
* limitations under the License.
*/
-import { TextEditor, useEvent, useObservable } from '@univerjs/ui';
-import React, { useEffect, useMemo, useRef, useState } from 'react';
-import { DraggableList, FormLayout, Input, Radio, RadioGroup, Select } from '@univerjs/design';
import { createInternalEditorID, DataValidationType, isFormulaString, LocaleService, Tools, useDependency } from '@univerjs/core';
import { DataValidationModel, DataValidatorRegistryService, type IFormulaInputProps } from '@univerjs/data-validation';
+import { DraggableList, FormLayout, Input, Radio, RadioGroup, Select } from '@univerjs/design';
+import { TextEditor } from '@univerjs/docs-ui';
import { DeleteSingle, IncreaseSingle, SequenceSingle } from '@univerjs/icons';
+import { useEvent, useObservable } from '@univerjs/ui';
import cs from 'clsx';
+import React, { useEffect, useMemo, useRef, useState } from 'react';
import { debounceTime } from 'rxjs';
-import { deserializeListOptions, serializeListOptions } from '../../validators/util';
import { DROP_DOWN_DEFAULT_COLOR } from '../../common/const';
-import type { ListValidator } from '../../validators';
import { DataValidationFormulaController } from '../../controllers/dv-formula.controller';
+import { deserializeListOptions, serializeListOptions } from '../../validators/util';
import styles from './index.module.less';
+import type { ListValidator } from '../../validators';
const DEFAULT_COLOR_PRESET = [
'#FFFFFF',
diff --git a/packages/sheets-formula/src/commands/operations/__tests__/create-command-test-bed.ts b/packages/sheets-formula/src/commands/operations/__tests__/create-command-test-bed.ts
index 7dd5ff6f1a..3b254b232b 100644
--- a/packages/sheets-formula/src/commands/operations/__tests__/create-command-test-bed.ts
+++ b/packages/sheets-formula/src/commands/operations/__tests__/create-command-test-bed.ts
@@ -14,13 +14,14 @@
* limitations under the License.
*/
-import type { Dependency, IWorkbookData } from '@univerjs/core';
import { AuthzIoLocalService, IAuthzIoService, ILogService, Inject, Injector, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
+import { DocSelectionManagerService } from '@univerjs/docs';
+import { EditorService, IEditorService } from '@univerjs/docs-ui';
import { LexerTreeBuilder } from '@univerjs/engine-formula';
-import { RangeProtectionRuleModel, SheetInterceptorService, SheetsSelectionsService, WorkbookPermissionService, WorksheetPermissionService, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets';
-import { EditorService, IEditorService } from '@univerjs/ui';
import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';
+import { RangeProtectionRuleModel, SheetInterceptorService, SheetsSelectionsService, WorkbookPermissionService, WorksheetPermissionService, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets';
import { EditorBridgeService, IEditorBridgeService, ISheetSelectionRenderService, SheetSelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
+import type { Dependency, IWorkbookData } from '@univerjs/core';
import { FormulaPromptService, IFormulaPromptService } from '../../../services/prompt.service';
const TEST_WORKBOOK_DATA_DEMO = (): IWorkbookData => ({
@@ -68,6 +69,7 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies?
injector.add([ISheetSelectionRenderService, { useClass: SheetSelectionRenderService }]);
injector.add([SheetsSelectionsService]);
injector.add([LexerTreeBuilder]);
+ injector.add([DocSelectionManagerService]);
injector.add([IFormulaPromptService, { useClass: FormulaPromptService }]);
injector.add([IEditorBridgeService, { useClass: EditorBridgeService }]);
injector.add([IEditorService, { useClass: EditorService }]);
diff --git a/packages/sheets-formula/src/commands/operations/__tests__/insert-function.operation.spec.ts b/packages/sheets-formula/src/commands/operations/__tests__/insert-function.operation.spec.ts
index 51f89e3b72..8721876eb0 100644
--- a/packages/sheets-formula/src/commands/operations/__tests__/insert-function.operation.spec.ts
+++ b/packages/sheets-formula/src/commands/operations/__tests__/insert-function.operation.spec.ts
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import type { Injector, Univer } from '@univerjs/core';
import { ICommandService, IUniverInstanceService, RANGE_TYPE, RedoCommand, UndoCommand } from '@univerjs/core';
import {
SetRangeValuesCommand,
@@ -23,9 +22,9 @@ import {
SheetsSelectionsService,
} from '@univerjs/sheets';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import type { Injector, Univer } from '@univerjs/core';
import { InsertFunctionCommand } from '../../commands/insert-function.command';
-import type { IInsertFunctionOperationParams } from '../insert-function.operation';
import {
InsertFunctionOperation,
isMultiRowsColumnsRange,
@@ -33,6 +32,7 @@ import {
isSingleCell,
} from '../insert-function.operation';
import { createCommandTestBed } from './create-command-test-bed';
+import type { IInsertFunctionOperationParams } from '../insert-function.operation';
describe('Test insert function operation', () => {
let univer: Univer;
diff --git a/packages/sheets-formula/src/commands/operations/insert-function.operation.ts b/packages/sheets-formula/src/commands/operations/insert-function.operation.ts
index b6f867399b..aac7762928 100644
--- a/packages/sheets-formula/src/commands/operations/insert-function.operation.ts
+++ b/packages/sheets-formula/src/commands/operations/insert-function.operation.ts
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import type { IAccessor, ICellData, ICommand, IRange, Nullable, ObjectMatrix } from '@univerjs/core';
import {
CellValueType,
CommandType,
@@ -25,6 +24,7 @@ import {
IUniverInstanceService,
Rectangle,
} from '@univerjs/core';
+import { IEditorService } from '@univerjs/docs-ui';
import { serializeRange } from '@univerjs/engine-formula';
import {
getCellAtRowCol,
@@ -33,9 +33,9 @@ import {
SheetsSelectionsService,
} from '@univerjs/sheets';
-import { IEditorService } from '@univerjs/ui';
-import type { IInsertFunction } from '../commands/insert-function.command';
+import type { IAccessor, ICellData, ICommand, IRange, Nullable, ObjectMatrix } from '@univerjs/core';
import { InsertFunctionCommand } from '../commands/insert-function.command';
+import type { IInsertFunction } from '../commands/insert-function.command';
export interface IInsertFunctionOperationParams {
/**
diff --git a/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.ts b/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.ts
index e2d2fd1ee3..6c71233fb8 100644
--- a/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.ts
+++ b/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.ts
@@ -15,11 +15,12 @@
*/
import { ILogService, Inject, Injector, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
+import { DocSelectionManagerService } from '@univerjs/docs';
+import { EditorService, IEditorService } from '@univerjs/docs-ui';
import { CalculateFormulaService, DefinedNamesService, FormulaCurrentConfigService, FormulaDataModel, FormulaRuntimeService, IDefinedNamesService, IFormulaCurrentConfigService, IFormulaRuntimeService, LexerTreeBuilder } from '@univerjs/engine-formula';
import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';
import { IRefSelectionsService, RangeProtectionRuleModel, SheetInterceptorService, SheetsSelectionsService, WorkbookPermissionService, WorksheetPermissionService, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets';
import { EditorBridgeService, IEditorBridgeService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
-import { EditorService, IEditorService } from '@univerjs/ui';
import type { Dependency, IWorkbookData, Workbook } from '@univerjs/core';
const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = {
@@ -87,6 +88,7 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies?
injector.add([CalculateFormulaService]);
injector.add([FormulaDataModel]);
injector.add([LexerTreeBuilder]);
+ injector.add([DocSelectionManagerService]);
injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]);
injector.add([IFormulaRuntimeService, { useClass: FormulaRuntimeService }]);
injector.add([IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }]);
diff --git a/packages/sheets-formula/src/controllers/prompt.controller.ts b/packages/sheets-formula/src/controllers/prompt.controller.ts
index 3a9989365e..cf360e8b69 100644
--- a/packages/sheets-formula/src/controllers/prompt.controller.ts
+++ b/packages/sheets-formula/src/controllers/prompt.controller.ts
@@ -42,7 +42,7 @@ import {
DocSelectionManagerService,
DocSkeletonManagerService,
} from '@univerjs/docs';
-import { DocSelectionRenderService, MoveCursorOperation, ReplaceContentCommand } from '@univerjs/docs-ui';
+import { DocSelectionRenderService, IEditorService, MoveCursorOperation, ReplaceContentCommand } from '@univerjs/docs-ui';
import {
compareToken,
deserializeRangeWithSheet,
@@ -77,7 +77,7 @@ import {
MoveSelectionCommand,
SheetSkeletonManagerService,
} from '@univerjs/sheets-ui';
-import { IContextMenuService, IEditorService, ILayoutService, KeyCode, MetaKeys, SetEditorResizeOperation, UNI_DISABLE_CHANGING_FOCUS_KEY } from '@univerjs/ui';
+import { IContextMenuService, ILayoutService, KeyCode, MetaKeys, SetEditorResizeOperation, UNI_DISABLE_CHANGING_FOCUS_KEY } from '@univerjs/ui';
import { distinctUntilChanged, distinctUntilKeyChanged } from 'rxjs';
import type {
DocumentDataModel,
@@ -89,13 +89,13 @@ import type {
Nullable,
Workbook,
} from '@univerjs/core';
+import type { Editor } from '@univerjs/docs-ui';
import type { IAbsoluteRefTypeForRange, ISequenceNode } from '@univerjs/engine-formula';
import type {
ISelectionWithStyle,
} from '@univerjs/sheets';
import type { EditorBridgeService, SelectionShape } from '@univerjs/sheets-ui';
-import type { Editor } from '@univerjs/ui';
import { SelectEditorFormulaOperation } from '../commands/operations/editor-formula.operation';
import { HelpFunctionOperation } from '../commands/operations/help-function.operation';
import { ReferenceAbsoluteOperation } from '../commands/operations/reference-absolute.operation';
diff --git a/packages/sheets-formula/src/controllers/update-formula.controller.ts b/packages/sheets-formula/src/controllers/update-formula.controller.ts
index eaa7b1d8ee..f9cd88a625 100644
--- a/packages/sheets-formula/src/controllers/update-formula.controller.ts
+++ b/packages/sheets-formula/src/controllers/update-formula.controller.ts
@@ -31,6 +31,7 @@ import {
Tools,
UniverInstanceType,
} from '@univerjs/core';
+import { IEditorService } from '@univerjs/docs-ui';
import { deserializeRangeWithSheet,
ErrorType,
FormulaDataModel,
@@ -79,7 +80,6 @@ import {
SheetInterceptorService,
SheetsSelectionsService,
} from '@univerjs/sheets';
-import { IEditorService } from '@univerjs/ui';
import { filter, map, merge } from 'rxjs';
import type {
@@ -178,7 +178,6 @@ export class UpdateFormulaController extends Disposable {
@Inject(Injector) readonly _injector: Injector
) {
super();
-
this._initialize();
}
diff --git a/packages/sheets-formula/src/views/more-functions/MoreFunctions.tsx b/packages/sheets-formula/src/views/more-functions/MoreFunctions.tsx
index 48a3fbf479..1c3d3f0988 100644
--- a/packages/sheets-formula/src/views/more-functions/MoreFunctions.tsx
+++ b/packages/sheets-formula/src/views/more-functions/MoreFunctions.tsx
@@ -16,10 +16,10 @@
import { LocaleService, useDependency } from '@univerjs/core';
import { Button } from '@univerjs/design';
-import type { IFunctionInfo } from '@univerjs/engine-formula';
-import { IEditorService } from '@univerjs/ui';
-import React, { useState } from 'react';
+import { IEditorService } from '@univerjs/docs-ui';
import { useActiveWorkbook } from '@univerjs/sheets-ui';
+import React, { useState } from 'react';
+import type { IFunctionInfo } from '@univerjs/engine-formula';
import styles from './index.module.less';
import { InputParams } from './input-params/InputParams';
import { SelectFunction } from './select-function/SelectFunction';
diff --git a/packages/sheets-formula/src/views/prompt/help-function/HelpFunction.tsx b/packages/sheets-formula/src/views/prompt/help-function/HelpFunction.tsx
index d06a7993ae..cb9d6d8909 100644
--- a/packages/sheets-formula/src/views/prompt/help-function/HelpFunction.tsx
+++ b/packages/sheets-formula/src/views/prompt/help-function/HelpFunction.tsx
@@ -16,10 +16,11 @@
import { IUniverInstanceService, LocaleService, useDependency, useInjector } from '@univerjs/core';
import { Popup } from '@univerjs/design';
+import { IEditorService } from '@univerjs/docs-ui';
import { CloseSingle, DetailsSingle, MoreSingle } from '@univerjs/icons';
-import { IEditorService, ILayoutService, ISidebarService } from '@univerjs/ui';
-import React, { useEffect, useState } from 'react';
+import { ILayoutService, ISidebarService } from '@univerjs/ui';
+import React, { useEffect, useState } from 'react';
import { throttleTime } from 'rxjs';
import type { IFunctionInfo, IFunctionParam } from '@univerjs/engine-formula';
import { IFormulaPromptService } from '../../../services/prompt.service';
diff --git a/packages/sheets-formula/src/views/prompt/search-function/SearchFunction.tsx b/packages/sheets-formula/src/views/prompt/search-function/SearchFunction.tsx
index b167c05060..073574c188 100644
--- a/packages/sheets-formula/src/views/prompt/search-function/SearchFunction.tsx
+++ b/packages/sheets-formula/src/views/prompt/search-function/SearchFunction.tsx
@@ -16,8 +16,8 @@
import { Direction, IUniverInstanceService, useDependency } from '@univerjs/core';
import { Popup } from '@univerjs/design';
-import { IEditorService } from '@univerjs/ui';
+import { IEditorService } from '@univerjs/docs-ui';
import React, { useEffect, useRef, useState } from 'react';
import { IFormulaPromptService } from '../../../services/prompt.service';
import styles from './index.module.less';
diff --git a/packages/sheets-hyper-link-ui/src/services/popup.service.ts b/packages/sheets-hyper-link-ui/src/services/popup.service.ts
index 1324eee2c6..ec16912cc8 100644
--- a/packages/sheets-hyper-link-ui/src/services/popup.service.ts
+++ b/packages/sheets-hyper-link-ui/src/services/popup.service.ts
@@ -16,9 +16,9 @@
import { BuildTextUtils, createInternalEditorID, CustomRangeType, Disposable, DOCS_ZEN_EDITOR_UNIT_ID_KEY, Inject, Injector, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
-import { DocCanvasPopManagerService } from '@univerjs/docs-ui';
+import { DocCanvasPopManagerService, IEditorService, IRangeSelectorService } from '@univerjs/docs-ui';
import { getCustomRangePosition, getEditingCustomRangePosition, IEditorBridgeService, SheetCanvasPopManagerService } from '@univerjs/sheets-ui';
-import { IEditorService, IRangeSelectorService, IZenZoneService } from '@univerjs/ui';
+import { IZenZoneService } from '@univerjs/ui';
import { BehaviorSubject, Subject } from 'rxjs';
import type { DocumentDataModel, ICustomRange, IDisposable, INeedCheckDisposable, ITextRange, Nullable, Workbook } from '@univerjs/core';
import type { IBoundRectNoAngle } from '@univerjs/engine-render';
diff --git a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx
index 3c0d099f13..6574bee395 100644
--- a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx
+++ b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx
@@ -17,11 +17,12 @@
import { BuildTextUtils, createInternalEditorID, CustomRangeType, DOCS_ZEN_EDITOR_UNIT_ID_KEY, FOCUSING_SHEET, generateRandomId, getOriginCellValue, ICommandService, IContextService, isValidRange, IUniverInstanceService, LocaleService, Tools, UniverInstanceType, useDependency } from '@univerjs/core';
import { Button, FormLayout, Input, Select } from '@univerjs/design';
import { DocSelectionManagerService } from '@univerjs/docs';
+import { RangeSelector } from '@univerjs/docs-ui';
import { deserializeRangeWithSheet, IDefinedNamesService, serializeRange, serializeRangeToRefString, serializeRangeWithSheet } from '@univerjs/engine-formula';
import { SetSelectionsOperation, SetWorksheetActiveOperation } from '@univerjs/sheets';
import { SheetHyperLinkType } from '@univerjs/sheets-hyper-link';
import { IEditorBridgeService, IMarkSelectionService, ScrollToRangeOperation } from '@univerjs/sheets-ui';
-import { IZenZoneService, KeyCode, RangeSelector, useEvent, useObservable } from '@univerjs/ui';
+import { IZenZoneService, KeyCode, useEvent, useObservable } from '@univerjs/ui';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import type { DocumentDataModel, IUnitRangeWithName, Nullable, Workbook } from '@univerjs/core';
import type { ISetSelectionsOperationParams } from '@univerjs/sheets';
diff --git a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts
index 03a424cd09..28b328d402 100644
--- a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts
+++ b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import type { ICellData, Injector, IStyleData, Nullable, Univer, Workbook } from '@univerjs/core';
import {
CellValueType,
ICommandService,
@@ -25,6 +24,9 @@ import {
UndoCommand,
UniverInstanceType,
} from '@univerjs/core';
+import { DocSelectionManagerService } from '@univerjs/docs';
+import { EditorService, IEditorService } from '@univerjs/docs-ui';
+import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';
import {
AddWorksheetMergeMutation,
RemoveWorksheetMergeMutation,
@@ -32,20 +34,20 @@ import {
SetSelectionsOperation,
SheetsSelectionsService,
} from '@univerjs/sheets';
-import { EditorService, IEditorService, IPlatformService, IShortcutService, PlatformService, ShortcutService } from '@univerjs/ui';
-import { beforeEach, describe, expect, it } from 'vitest';
-import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';
+import { IPlatformService, IShortcutService, PlatformService, ShortcutService } from '@univerjs/ui';
+import { beforeEach, describe, expect, it } from 'vitest';
+import type { ICellData, Injector, IStyleData, Nullable, Univer, Workbook } from '@univerjs/core';
import { AutoFillController } from '../../../controllers/auto-fill.controller';
import { AutoFillService, IAutoFillService } from '../../../services/auto-fill/auto-fill.service';
import { APPLY_TYPE } from '../../../services/auto-fill/type';
import { EditorBridgeService, IEditorBridgeService } from '../../../services/editor-bridge.service';
-import { SheetSkeletonManagerService } from '../../../services/sheet-skeleton-manager.service';
-import { RefillCommand } from '../refill.command';
-import { AutoClearContentCommand, AutoFillCommand } from '../auto-fill.command';
-import { SheetsRenderService } from '../../../services/sheets-render.service';
import { ISheetSelectionRenderService } from '../../../services/selection/base-selection-render.service';
import { SheetSelectionRenderService } from '../../../services/selection/selection-render.service';
+import { SheetSkeletonManagerService } from '../../../services/sheet-skeleton-manager.service';
+import { SheetsRenderService } from '../../../services/sheets-render.service';
+import { AutoClearContentCommand, AutoFillCommand } from '../auto-fill.command';
+import { RefillCommand } from '../refill.command';
import { createCommandTestBed } from './create-command-test-bed';
const theme = {
@@ -284,6 +286,7 @@ describe('Test auto fill rules in controller', () => {
beforeEach(() => {
const testBed = createCommandTestBed(TEST_WORKBOOK_DATA, [
+ [DocSelectionManagerService],
[ISheetSelectionRenderService, { useClass: SheetSelectionRenderService }],
[IAutoFillService, { useClass: AutoFillService }],
[IShortcutService, { useClass: ShortcutService }],
diff --git a/packages/sheets-ui/src/commands/operations/sidebar-defined-name.operation.ts b/packages/sheets-ui/src/commands/operations/sidebar-defined-name.operation.ts
index d12c5b0928..e292d85a5b 100644
--- a/packages/sheets-ui/src/commands/operations/sidebar-defined-name.operation.ts
+++ b/packages/sheets-ui/src/commands/operations/sidebar-defined-name.operation.ts
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-import type { IAccessor, ICommand } from '@univerjs/core';
import { CommandType, IUniverInstanceService, LocaleService } from '@univerjs/core';
-import { IEditorService, ISidebarService } from '@univerjs/ui';
+import { IEditorService } from '@univerjs/docs-ui';
import { getSheetCommandTarget } from '@univerjs/sheets';
+import { ISidebarService } from '@univerjs/ui';
+import type { IAccessor, ICommand } from '@univerjs/core';
import { DEFINED_NAME_CONTAINER } from '../../views/defined-name/component-name';
export interface IUIComponentCommandParams {
diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
index 73f96a9788..113307ae85 100644
--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
@@ -45,7 +45,7 @@ import {
DocSkeletonManagerService,
RichTextEditingMutation,
} from '@univerjs/docs';
-import { VIEWPORT_KEY as DOC_VIEWPORT_KEY, DOCS_COMPONENT_MAIN_LAYER_INDEX, DocSelectionRenderService, MoveCursorOperation, MoveSelectionOperation } from '@univerjs/docs-ui';
+import { VIEWPORT_KEY as DOC_VIEWPORT_KEY, DOCS_COMPONENT_MAIN_LAYER_INDEX, DocSelectionRenderService, IEditorService, MoveCursorOperation, MoveSelectionOperation } from '@univerjs/docs-ui';
import { IFunctionService, LexerTreeBuilder, matchToken } from '@univerjs/engine-formula';
import {
convertTextRotation,
@@ -57,7 +57,7 @@ import {
ScrollBar,
} from '@univerjs/engine-render';
import { ClearSelectionFormatCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetSelectionsOperation, SetWorksheetActivateCommand, SheetsSelectionsService } from '@univerjs/sheets';
-import { IEditorService, ILayoutService, KeyCode, SetEditorResizeOperation } from '@univerjs/ui';
+import { ILayoutService, KeyCode, SetEditorResizeOperation } from '@univerjs/ui';
import { distinctUntilChanged, filter } from 'rxjs';
import type { DocumentDataModel, ICellData, ICommandInfo, IDisposable, IDocumentBody, IDocumentData, IPosition, IStyleData, Nullable, UnitModel, Workbook } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
diff --git a/packages/sheets-ui/src/controllers/render-controllers/editor-bridge.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/editor-bridge.render-controller.ts
index 96824b78ed..db7454cea1 100644
--- a/packages/sheets-ui/src/controllers/render-controllers/editor-bridge.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/render-controllers/editor-bridge.render-controller.ts
@@ -14,24 +14,24 @@
* limitations under the License.
*/
-import type { ICommandInfo, IDisposable, IExecutionOptions, Nullable, Workbook } from '@univerjs/core';
import { DisposableCollection, ICommandService, Inject, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
-import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
+import { IRangeSelectorService } from '@univerjs/docs-ui';
import { DeviceInputEventType } from '@univerjs/engine-render';
-import type { ISelectionWithStyle } from '@univerjs/sheets';
import {
COMMAND_LISTENER_SKELETON_CHANGE,
SetWorksheetActiveOperation,
SheetsSelectionsService,
} from '@univerjs/sheets';
import { merge } from 'rxjs';
-import { IRangeSelectorService } from '@univerjs/ui';
+import type { ICommandInfo, IDisposable, IExecutionOptions, Nullable, Workbook } from '@univerjs/core';
+import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
+import type { ISelectionWithStyle } from '@univerjs/sheets';
import { SetZoomRatioCommand } from '../../commands/commands/set-zoom-ratio.command';
import { SetActivateCellEditOperation } from '../../commands/operations/activate-cell-edit.operation';
import { SetCellEditVisibleOperation } from '../../commands/operations/cell-edit.operation';
-import type { ICurrentEditCellParam, IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';
import { IEditorBridgeService } from '../../services/editor-bridge.service';
import { getSheetObject } from '../utils/component-tools';
+import type { ICurrentEditCellParam, IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';
// TODO: wzhudev: this should be merged with Edit EditingRenderController.
diff --git a/packages/sheets-ui/src/services/editor-bridge.service.ts b/packages/sheets-ui/src/services/editor-bridge.service.ts
index c6d495d523..2c30b3079f 100644
--- a/packages/sheets-ui/src/services/editor-bridge.service.ts
+++ b/packages/sheets-ui/src/services/editor-bridge.service.ts
@@ -32,10 +32,9 @@ import {
toDisposable,
UniverInstanceType,
} from '@univerjs/core';
-import { getCanvasOffsetByEngine } from '@univerjs/docs-ui';
+import { getCanvasOffsetByEngine, IEditorService } from '@univerjs/docs-ui';
import { convertTextRotation, DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';
import { IRefSelectionsService } from '@univerjs/sheets';
-import { IEditorService } from '@univerjs/ui';
import { BehaviorSubject } from 'rxjs';
import type { ICellData, ICellDataForSheetInterceptor, IDisposable, IPosition, ISelectionCell, Nullable, Workbook } from '@univerjs/core';
import type { Engine, IDocumentLayoutObject, Scene } from '@univerjs/engine-render';
diff --git a/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx b/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx
index 83565f9e85..c7223ce98a 100644
--- a/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx
+++ b/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx
@@ -17,10 +17,10 @@
import { AbsoluteRefType, createInternalEditorID, IUniverInstanceService, LocaleService, Tools, UniverInstanceType, useDependency } from '@univerjs/core';
import { Button, Input, Radio, RadioGroup, Select } from '@univerjs/design';
+import { RangeSelector, TextEditor } from '@univerjs/docs-ui';
import { IDefinedNamesService, type IDefinedNamesServiceParam, IFunctionService, isReferenceStrings, isReferenceStringWithEffectiveColumn, LexerTreeBuilder, operatorToken, serializeRangeToRefString } from '@univerjs/engine-formula';
import { hasCJKText } from '@univerjs/engine-render';
import { ErrorSingle } from '@univerjs/icons';
-import { RangeSelector, TextEditor } from '@univerjs/ui';
import React, { useEffect, useState } from 'react';
import type { IUnitRange, Nullable, Workbook } from '@univerjs/core';
import { SCOPE_WORKBOOK_VALUE } from './component-name';
diff --git a/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx b/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
index 78b2c26297..e53ced3615 100644
--- a/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
+++ b/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
@@ -14,12 +14,13 @@
* limitations under the License.
*/
-import type { IDocumentData } from '@univerjs/core';
import { DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DocumentFlavor, IContextService, useDependency } from '@univerjs/core';
-import React, { useEffect, useState } from 'react';
-
+import { IEditorService, TextEditor } from '@univerjs/docs-ui';
import { FIX_ONE_PIXEL_BLUR_OFFSET } from '@univerjs/engine-render';
-import { DISABLE_AUTO_FOCUS_KEY, IEditorService, TextEditor, useObservable } from '@univerjs/ui';
+
+import { DISABLE_AUTO_FOCUS_KEY, useObservable } from '@univerjs/ui';
+import React, { useEffect, useState } from 'react';
+import type { IDocumentData } from '@univerjs/core';
import { ICellEditorManagerService } from '../../services/editor/cell-editor-manager.service';
import styles from './index.module.less';
diff --git a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
index b7a013d9e1..c175a98423 100644
--- a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
+++ b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
@@ -14,21 +14,22 @@
* limitations under the License.
*/
-import type { IDocumentData, Nullable, Workbook } from '@univerjs/core';
import { BooleanNumber, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DocumentFlavor, HorizontalAlign, IPermissionService, IUniverInstanceService, Rectangle, ThemeService, UniverInstanceType, useDependency, useObservable, VerticalAlign, WrapStrategy } from '@univerjs/core';
+import { TextEditor } from '@univerjs/docs-ui';
import { DeviceInputEventType } from '@univerjs/engine-render';
import { CheckMarkSingle, CloseSingle, DropdownSingle, FxSingle } from '@univerjs/icons';
-import { KeyCode, ProgressBar, TextEditor } from '@univerjs/ui';
+import { RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel, WorksheetSetCellValuePermission } from '@univerjs/sheets';
+import { KeyCode, ProgressBar } from '@univerjs/ui';
import clsx from 'clsx';
import React, { useEffect, useLayoutEffect, useState } from 'react';
-import { RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel, WorksheetSetCellValuePermission } from '@univerjs/sheets';
import { EMPTY, merge, switchMap } from 'rxjs';
+import type { IDocumentData, Nullable, Workbook } from '@univerjs/core';
+import { useActiveWorkbook } from '../../components/hook';
import { IFormulaEditorManagerService } from '../../services/editor/formula-editor-manager.service';
+
import { IEditorBridgeService } from '../../services/editor-bridge.service';
import { DefinedName } from '../defined-name/DefinedName';
-
-import { useActiveWorkbook } from '../../components/hook';
import styles from './index.module.less';
enum ArrowDirection {
diff --git a/packages/sheets-ui/src/views/permission/panel-detail/index.tsx b/packages/sheets-ui/src/views/permission/panel-detail/index.tsx
index f0c26ecc0f..db66419597 100644
--- a/packages/sheets-ui/src/views/permission/panel-detail/index.tsx
+++ b/packages/sheets-ui/src/views/permission/panel-detail/index.tsx
@@ -14,21 +14,22 @@
* limitations under the License.
*/
-import React, { useEffect, useState } from 'react';
-import { Avatar, FormLayout, Input, Radio, RadioGroup, Select } from '@univerjs/design';
import { createInternalEditorID, IAuthzIoService, isValidRange, IUniverInstanceService, LocaleService, RANGE_TYPE, Rectangle, UniverInstanceType, useDependency, UserManagerService } from '@univerjs/core';
-import type { IRange, Workbook } from '@univerjs/core';
-import { IDialogService, ISidebarService, RangeSelector, useObservable } from '@univerjs/ui';
-import { RangeProtectionRuleModel, setEndForRange, SheetsSelectionsService, WorksheetProtectionRuleModel } from '@univerjs/sheets';
+import { Avatar, FormLayout, Input, Radio, RadioGroup, Select } from '@univerjs/design';
+import { RangeSelector } from '@univerjs/docs-ui';
import { serializeRange } from '@univerjs/engine-formula';
-import type { ICollaborator, IUser } from '@univerjs/protocol';
import { ObjectScope, UnitAction, UnitObject, UnitRole } from '@univerjs/protocol';
+import { RangeProtectionRuleModel, setEndForRange, SheetsSelectionsService, WorksheetProtectionRuleModel } from '@univerjs/sheets';
+import { IDialogService, ISidebarService, useObservable } from '@univerjs/ui';
import clsx from 'clsx';
-import { UserEmptyBase64 } from '../user-dialog/constant';
-import Spin from '../spin';
+import React, { useEffect, useState } from 'react';
+import type { IRange, Workbook } from '@univerjs/core';
+import type { ICollaborator, IUser } from '@univerjs/protocol';
+import { UNIVER_SHEET_PERMISSION_USER_DIALOG, UNIVER_SHEET_PERMISSION_USER_DIALOG_ID } from '../../../consts/permission';
import { editState, SheetPermissionPanelModel, viewState } from '../../../services/permission/sheet-permission-panel.model';
import { SheetPermissionUserManagerService } from '../../../services/permission/sheet-permission-user-list.service';
-import { UNIVER_SHEET_PERMISSION_USER_DIALOG, UNIVER_SHEET_PERMISSION_USER_DIALOG_ID } from '../../../consts/permission';
+import Spin from '../spin';
+import { UserEmptyBase64 } from '../user-dialog/constant';
import styles from './index.module.less';
export const SheetPermissionPanelDetail = ({ fromSheetBar }: { fromSheetBar: boolean }) => {
diff --git a/packages/slides-ui/src/controllers/slide-editing.render-controller.ts b/packages/slides-ui/src/controllers/slide-editing.render-controller.ts
index 0185062442..c4034ba6e9 100644
--- a/packages/slides-ui/src/controllers/slide-editing.render-controller.ts
+++ b/packages/slides-ui/src/controllers/slide-editing.render-controller.ts
@@ -40,7 +40,7 @@ import {
DocSkeletonManagerService,
RichTextEditingMutation,
} from '@univerjs/docs';
-import { VIEWPORT_KEY as DOC_VIEWPORT_KEY, DOCS_COMPONENT_MAIN_LAYER_INDEX, DOCS_VIEW_KEY, DocSelectionRenderService, MoveCursorOperation, MoveSelectionOperation } from '@univerjs/docs-ui';
+import { VIEWPORT_KEY as DOC_VIEWPORT_KEY, DOCS_COMPONENT_MAIN_LAYER_INDEX, DOCS_VIEW_KEY, DocSelectionRenderService, IEditorService, MoveCursorOperation, MoveSelectionOperation } from '@univerjs/docs-ui';
import {
convertTextRotation,
DeviceInputEventType,
@@ -50,7 +50,7 @@ import {
Rect,
ScrollBar,
} from '@univerjs/engine-render';
-import { IEditorService, ILayoutService, KeyCode } from '@univerjs/ui';
+import { ILayoutService, KeyCode } from '@univerjs/ui';
import { filter } from 'rxjs';
import type {
ICommandInfo,
diff --git a/packages/slides-ui/src/services/slide-editor-bridge.service.ts b/packages/slides-ui/src/services/slide-editor-bridge.service.ts
index 7665588840..097236eade 100644
--- a/packages/slides-ui/src/services/slide-editor-bridge.service.ts
+++ b/packages/slides-ui/src/services/slide-editor-bridge.service.ts
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import type { IDisposable, IDocumentBody, IDocumentData, IDocumentSettings, IDocumentStyle, IParagraph, IParagraphStyle, IPosition, Nullable } from '@univerjs/core';
import {
createIdentifier,
Disposable,
@@ -26,13 +25,14 @@ import {
IContextService,
VerticalAlign,
} from '@univerjs/core';
-import type { Engine, IDocumentLayoutObject, RichText, Scene } from '@univerjs/engine-render';
+import { IEditorService } from '@univerjs/docs-ui';
import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';
import { SLIDE_KEY } from '@univerjs/slides';
+import { BehaviorSubject, Subject } from 'rxjs';
+import type { IDisposable, IDocumentBody, IDocumentData, IDocumentSettings, IDocumentStyle, IParagraph, IParagraphStyle, IPosition, Nullable } from '@univerjs/core';
+import type { Engine, IDocumentLayoutObject, RichText, Scene } from '@univerjs/engine-render';
import type { KeyCode } from '@univerjs/ui';
-import { IEditorService } from '@univerjs/ui';
import type { Observable } from 'rxjs';
-import { BehaviorSubject, Subject } from 'rxjs';
import { SLIDE_EDITOR_ID } from '../const';
// TODO same as @univerjs/slides/views/render/adaptors/index.js
diff --git a/packages/slides-ui/src/views/editor-container/EditorContainer.tsx b/packages/slides-ui/src/views/editor-container/EditorContainer.tsx
index 75589a8591..72f77408aa 100644
--- a/packages/slides-ui/src/views/editor-container/EditorContainer.tsx
+++ b/packages/slides-ui/src/views/editor-container/EditorContainer.tsx
@@ -14,15 +14,16 @@
* limitations under the License.
*/
-import type { IDocumentData } from '@univerjs/core';
import { DEFAULT_EMPTY_DOCUMENT_VALUE, DocumentFlavor, IContextService, useDependency } from '@univerjs/core';
-import React, { useEffect, useState } from 'react';
-
+import { IEditorService, TextEditor } from '@univerjs/docs-ui';
import { FIX_ONE_PIXEL_BLUR_OFFSET } from '@univerjs/engine-render';
-import { DISABLE_AUTO_FOCUS_KEY, IEditorService, TextEditor, useObservable } from '@univerjs/ui';
+
+import { DISABLE_AUTO_FOCUS_KEY, useObservable } from '@univerjs/ui';
+import React, { useEffect, useState } from 'react';
+import type { IDocumentData } from '@univerjs/core';
+import { SLIDE_EDITOR_ID } from '../../const';
// import { ICellEditorManagerService } from '../../services/editor/cell-editor-manager.service';
import { ISlideEditorManagerService } from '../../services/slide-editor-manager.service';
-import { SLIDE_EDITOR_ID } from '../../const';
import styles from './index.module.less';
interface ICellIEditorProps { }
diff --git a/packages/ui/src/components/custom-label/CustomLabel.tsx b/packages/ui/src/components/custom-label/CustomLabel.tsx
index b693ae465d..9a8235a91d 100644
--- a/packages/ui/src/components/custom-label/CustomLabel.tsx
+++ b/packages/ui/src/components/custom-label/CustomLabel.tsx
@@ -15,13 +15,12 @@
*/
import { ColorKit, LocaleService, useDependency } from '@univerjs/core';
-import React from 'react';
-import type { Observable } from 'rxjs';
+import React, { useEffect, useState } from 'react';
import { isObservable } from 'rxjs';
+import type { Observable } from 'rxjs';
import { ComponentManager } from '../../common/component-manager';
import type { IMenuSelectorItem } from '../../services/menu/menu';
-import { useObservable } from '../hooks/observable';
export type ICustomLabelProps<T = undefined> = {
value?: string | number | undefined;
@@ -42,21 +41,38 @@ export function CustomLabel(props: ICustomLabelProps): JSX.Element | null {
const { title, icon, label, value, value$ } = props;
const localeService = useDependency(LocaleService);
const componentManager = useDependency(ComponentManager);
+ const [realValue, setRealValue] = useState(value);
+ const [realIcon, setRealIcon] = useState('');
const nodes = [];
let index = 0;
- let realValue = value;
- if (value$) {
- realValue = useObservable(value$, undefined, true);
- }
+ useEffect(() => {
+ if (value$) {
+ const subscription = value$.subscribe((v) => {
+ setRealValue(v);
+ });
- let realIcon;
- if (isObservable(icon)) {
- realIcon = useObservable(icon, undefined, true);
- } else {
- realIcon = icon;
- }
+ return () => {
+ subscription.unsubscribe();
+ };
+ }
+ }, []);
+
+ useEffect(() => {
+ let subscription = null;
+ if (isObservable(icon)) {
+ subscription = icon.subscribe((v) => {
+ setRealIcon(v);
+ });
+ } else {
+ setRealIcon(icon ?? '');
+ }
+
+ return () => {
+ subscription?.unsubscribe();
+ };
+ }, []);
// if value is not valid, use primary color
let isValid = false;
diff --git a/packages/ui/src/components/hooks/observable.ts b/packages/ui/src/components/hooks/observable.ts
index 86b384ad6e..3a70200e1f 100644
--- a/packages/ui/src/components/hooks/observable.ts
+++ b/packages/ui/src/components/hooks/observable.ts
@@ -16,8 +16,8 @@
/* eslint-disable ts/no-explicit-any */
-import type { Nullable } from '@univerjs/core';
import { useEffect, useMemo, useRef, useState } from 'react';
+import type { Nullable } from '@univerjs/core';
import type { Observable, Subscription } from 'rxjs';
type ObservableOrFn<T> = Observable<T> | (() => Observable<T>);
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts
index 674edd9c4f..d85a83e555 100644
--- a/packages/ui/src/index.ts
+++ b/packages/ui/src/index.ts
@@ -20,7 +20,6 @@ export * from './common';
export { getHeaderFooterMenuHiddenObservable, getMenuHiddenObservable } from './common/menu-hidden-observable';
export { mergeMenuConfigs } from './common/menu-merge-configs';
export * from './components';
-export { TextEditor } from './components/editor/TextEditor';
export { useEvent } from './components/hooks/event';
export { t } from './components/hooks/locale';
export { useObservable } from './components/hooks/observable';
@@ -28,7 +27,6 @@ export { useVirtualList } from './components/hooks/virtual-list';
export { Menu } from './components/menu/desktop/Menu';
export { type INotificationOptions, type NotificationType } from './components/notification/Notification';
export { ProgressBar } from './components/progress-bar/ProgressBar';
-export { RangeSelector } from './components/range-selector/RangeSelector';
export { UNI_DISABLE_CHANGING_FOCUS_KEY } from './const';
export { type IUniverUIConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
export { ErrorController } from './controllers/error/error.controller';
@@ -62,7 +60,6 @@ export {
export { DesktopDialogService } from './services/dialog/desktop-dialog.service';
export { IDialogService } from './services/dialog/dialog.service';
export { CanvasFloatDomService, type IFloatDomLayout } from './services/dom/canvas-dom-layer.service';
-export { Editor, EditorService, IEditorService } from './services/editor/editor.service';
export { DesktopGlobalZoneService } from './services/global-zone/desktop-global-zone.service';
export { IGlobalZoneService } from './services/global-zone/global-zone.service';
export { DesktopLayoutService, ILayoutService } from './services/layout/layout.service';
@@ -106,7 +103,6 @@ export { BuiltInUIPart, IUIPartsService, UIPartsService } from './services/parts
export { IPlatformService, PlatformService } from './services/platform/platform.service';
export { CanvasPopupService, ICanvasPopupService, type IPopup } from './services/popup/canvas-popup.service';
export { type IProgressCount, IProgressService, type IProgressStep, ProgressService } from './services/progress/progress.service';
-export { type IRangeSelectorRange, IRangeSelectorService, RangeSelectorService } from './services/range-selector/range-selector.service';
export { KeyCode, MetaKeys } from './services/shortcut/keycode';
export { type IShortcutItem, IShortcutService, ShortcutService } from './services/shortcut/shortcut.service';
export { ShortcutPanelService } from './services/shortcut/shortcut-panel.service';
diff --git a/packages/ui/src/mobile-ui-plugin.ts b/packages/ui/src/mobile-ui-plugin.ts
index 7d101d809d..61b8ba53c5 100644
--- a/packages/ui/src/mobile-ui-plugin.ts
+++ b/packages/ui/src/mobile-ui-plugin.ts
@@ -15,17 +15,14 @@
*/
import { DependentOn, ILocalStorageService, Inject, Injector, mergeOverrideWithDependencies, Plugin } from '@univerjs/core';
-import type { Dependency } from '@univerjs/core';
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
-import { CanvasPopupService, ICanvasPopupService } from './services/popup/canvas-popup.service';
-import { DesktopGlobalZoneService } from './services/global-zone/desktop-global-zone.service';
-import { IGlobalZoneService } from './services/global-zone/global-zone.service';
+import type { Dependency } from '@univerjs/core';
import { ComponentManager } from './common/component-manager';
import { ZIndexManager } from './common/z-index-manager';
import { ErrorController } from './controllers/error/error.controller';
import { SharedController } from './controllers/shared-shortcut.controller';
-import type { IUniverUIConfig } from './controllers/config.schema';
import { IUIController } from './controllers/ui/ui.controller';
+import { MobileUIController } from './controllers/ui/ui-mobile.controller';
import { DesktopBeforeCloseService, IBeforeCloseService } from './services/before-close/before-close.service';
import { BrowserClipboardService, IClipboardInterfaceService } from './services/clipboard/clipboard-interface.service';
import { IConfirmService } from './services/confirm/confirm.service';
@@ -33,27 +30,28 @@ import { DesktopConfirmService } from './services/confirm/desktop-confirm.servic
import { ContextMenuService, IContextMenuService } from './services/contextmenu/contextmenu.service';
import { DesktopDialogService } from './services/dialog/desktop-dialog.service';
import { IDialogService } from './services/dialog/dialog.service';
+import { CanvasFloatDomService } from './services/dom/canvas-dom-layer.service';
+import { DesktopGlobalZoneService } from './services/global-zone/desktop-global-zone.service';
+import { IGlobalZoneService } from './services/global-zone/global-zone.service';
import { DesktopLayoutService, ILayoutService } from './services/layout/layout.service';
import { DesktopLocalStorageService } from './services/local-storage/local-storage.service';
import { IMenuService, MenuService } from './services/menu/menu.service';
+import { IMenuManagerService, MenuManagerService } from './services/menu/menu-manager.service';
import { DesktopMessageService } from './services/message/desktop-message.service';
import { IMessageService } from './services/message/message.service';
import { DesktopNotificationService } from './services/notification/desktop-notification.service';
import { INotificationService } from './services/notification/notification.service';
+import { IUIPartsService, UIPartsService } from './services/parts/parts.service';
import { IPlatformService, PlatformService } from './services/platform/platform.service';
+import { CanvasPopupService, ICanvasPopupService } from './services/popup/canvas-popup.service';
+import { IProgressService, ProgressService } from './services/progress/progress.service';
import { IShortcutService, ShortcutService } from './services/shortcut/shortcut.service';
import { ShortcutPanelService } from './services/shortcut/shortcut-panel.service';
import { DesktopSidebarService } from './services/sidebar/desktop-sidebar.service';
import { ISidebarService } from './services/sidebar/sidebar.service';
import { DesktopZenZoneService } from './services/zen-zone/desktop-zen-zone.service';
import { IZenZoneService } from './services/zen-zone/zen-zone.service';
-import { EditorService, IEditorService } from './services/editor/editor.service';
-import { IRangeSelectorService, RangeSelectorService } from './services/range-selector/range-selector.service';
-import { IProgressService, ProgressService } from './services/progress/progress.service';
-import { IUIPartsService, UIPartsService } from './services/parts/parts.service';
-import { CanvasFloatDomService } from './services/dom/canvas-dom-layer.service';
-import { MobileUIController } from './controllers/ui/ui-mobile.controller';
-import { IMenuManagerService, MenuManagerService } from './services/menu/menu-manager.service';
+import type { IUniverUIConfig } from './controllers/config.schema';
export const UNIVER_MOBILE_UI_PLUGIN_NAME = 'UNIVER_MOBILE_UI_PLUGIN';
@@ -95,8 +93,6 @@ export class UniverMobileUIPlugin extends Plugin {
[IMessageService, { useClass: DesktopMessageService, lazy: true }],
[ILocalStorageService, { useClass: DesktopLocalStorageService, lazy: true }],
[IBeforeCloseService, { useClass: DesktopBeforeCloseService }],
- [IEditorService, { useClass: EditorService }],
- [IRangeSelectorService, { useClass: RangeSelectorService }],
[ICanvasPopupService, { useClass: CanvasPopupService }],
[IProgressService, { useClass: ProgressService }],
[CanvasFloatDomService],
diff --git a/packages/ui/src/services/layout/layout.service.ts b/packages/ui/src/services/layout/layout.service.ts
index 8f71a2113a..0ec1c64290 100644
--- a/packages/ui/src/services/layout/layout.service.ts
+++ b/packages/ui/src/services/layout/layout.service.ts
@@ -14,10 +14,9 @@
* limitations under the License.
*/
-import type { ContextService, IDisposable, Nullable } from '@univerjs/core';
import { createIdentifier, Disposable, DocumentDataModel, FOCUSING_UNIVER_EDITOR, IContextService, IUniverInstanceService, LifecycleStages, OnLifecycle, remove, SlideDataModel, toDisposable, UniverInstanceType, Workbook } from '@univerjs/core';
import { fromEvent } from 'rxjs';
-import { IEditorService } from '../editor/editor.service';
+import type { ContextService, IDisposable, Nullable } from '@univerjs/core';
type FocusHandlerFn = (unitId: string) => void;
@@ -32,17 +31,6 @@ const givingBackFocusElements = [
'univer-workbench-layout',
];
-/**
- * Not these elements will be considered as editor blur.
- */
-const editorFocusInElements = [
- 'univer-editor',
- 'univer-range-selector',
- 'univer-range-selector-editor',
- 'univer-render-canvas',
- 'univer-text-editor-container-placeholder',
-];
-
export interface ILayoutService {
readonly isFocused: boolean;
@@ -87,8 +75,7 @@ export class DesktopLayoutService extends Disposable implements ILayoutService {
constructor(
@IContextService private readonly _contextService: ContextService,
- @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
- @IEditorService private readonly _editorService: IEditorService
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
) {
super();
@@ -178,8 +165,6 @@ export class DesktopLayoutService extends Disposable implements ILayoutService {
fromEvent(window, 'focusin').subscribe((event) => {
const target = event.target as HTMLElement;
- this._blurSheetEditor(target);
-
if (givingBackFocusElements.some((item) => target.classList.contains(item))) {
queueMicrotask(() => this.focus());
return;
@@ -200,18 +185,6 @@ export class DesktopLayoutService extends Disposable implements ILayoutService {
private _initEditorStatus(): void {
this._contextService.setContextValue(FOCUSING_UNIVER_EDITOR, getFocusingUniverEditorStatus());
}
-
- private _blurSheetEditor(target: HTMLElement) {
- if (editorFocusInElements.some((item) => target.classList.contains(item))) {
- return;
- }
-
- // NOTE: Note that the focus editor will not be docs' editor but calling `this._editorService.blur()` will blur doc's editor.
- const focusEditor = this._editorService.getFocusEditor();
- if (focusEditor && focusEditor.isSheetEditor() !== true) {
- this._editorService.blur();
- }
- }
}
function getFocusingUniverEditorStatus(): boolean {
diff --git a/packages/ui/src/ui-plugin.ts b/packages/ui/src/ui-plugin.ts
index 9c9235edf3..98f17736d2 100644
--- a/packages/ui/src/ui-plugin.ts
+++ b/packages/ui/src/ui-plugin.ts
@@ -34,7 +34,6 @@ import { ContextMenuService, IContextMenuService } from './services/contextmenu/
import { DesktopDialogService } from './services/dialog/desktop-dialog.service';
import { IDialogService } from './services/dialog/dialog.service';
import { CanvasFloatDomService } from './services/dom/canvas-dom-layer.service';
-import { EditorService, IEditorService } from './services/editor/editor.service';
import { DesktopGlobalZoneService } from './services/global-zone/desktop-global-zone.service';
import { IGlobalZoneService } from './services/global-zone/global-zone.service';
import { DesktopLayoutService, ILayoutService } from './services/layout/layout.service';
@@ -51,7 +50,6 @@ import { IUIPartsService, UIPartsService } from './services/parts/parts.service'
import { IPlatformService, PlatformService } from './services/platform/platform.service';
import { CanvasPopupService, ICanvasPopupService } from './services/popup/canvas-popup.service';
import { IProgressService, ProgressService } from './services/progress/progress.service';
-import { IRangeSelectorService, RangeSelectorService } from './services/range-selector/range-selector.service';
import { IShortcutService, ShortcutService } from './services/shortcut/shortcut.service';
import { ShortcutPanelService } from './services/shortcut/shortcut-panel.service';
import { DesktopSidebarService } from './services/sidebar/desktop-sidebar.service';
@@ -114,8 +112,6 @@ export class UniverUIPlugin extends Plugin {
[ILocalStorageService, { useClass: DesktopLocalStorageService, lazy: true }],
[IBeforeCloseService, { useClass: DesktopBeforeCloseService }],
[ILocalFileService, { useClass: DesktopLocalFileService }],
- [IEditorService, { useClass: EditorService }],
- [IRangeSelectorService, { useClass: RangeSelectorService }],
[ICanvasPopupService, { useClass: CanvasPopupService }],
[IProgressService, { useClass: ProgressService }],
[CanvasFloatDomService],
diff --git a/packages/ui/src/utils/util.ts b/packages/ui/src/utils/util.ts
index f6f3d74caa..0f0e600798 100644
--- a/packages/ui/src/utils/util.ts
+++ b/packages/ui/src/utils/util.ts
@@ -21,27 +21,3 @@ export function textTrim(x: string): string {
}
return x.replace(/^\s+|\s+$/gm, '');
}
-
-export function isElementVisible(element: HTMLElement | null) {
- if (!element) return false;
-
- const style = window.getComputedStyle(element);
-
- if (style.display === 'none' ||
- style.visibility === 'hidden' ||
- style.opacity === '0') {
- return false;
- }
-
- const rect = element.getBoundingClientRect();
- if (rect.width === 0 || rect.height === 0) {
- return false;
- }
-
- if (rect.bottom < 0 || rect.top > window.innerHeight ||
- rect.right < 0 || rect.left > window.innerWidth) {
- return false;
- }
-
- return true;
-}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 70284041da..ba04d70726 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -10,7 +10,7 @@ importers:
devDependencies:
'@antfu/eslint-config':
specifier: 3.5.1
'@commitlint/cli':
specifier: ^19.5.0
version: 19.5.0(@types/[email protected])([email protected])
@@ -461,6 +461,9 @@ importers:
'@univerjs/design':
specifier: workspace:*
version: link:../../packages/design
+ '@univerjs/docs-ui':
+ specifier: workspace:*
+ version: link:../../packages/docs-ui
'@univerjs/engine-render':
specifier: workspace:*
version: link:../../packages/engine-render
@@ -1304,6 +1307,9 @@ importers:
'@univerjs/docs':
specifier: workspace:*
version: link:../docs
+ '@univerjs/engine-formula':
+ specifier: workspace:*
+ version: link:../engine-formula
'@univerjs/engine-render':
specifier: workspace:*
version: link:../engine-render
@@ -1774,6 +1780,9 @@ importers:
'@univerjs/design':
specifier: workspace:*
version: link:../design
+ '@univerjs/docs-ui':
+ specifier: workspace:*
+ version: link:../docs-ui
'@univerjs/engine-formula':
specifier: workspace:*
version: link:../engine-formula
@@ -10411,7 +10420,7 @@ snapshots:
dependencies:
'@babel/runtime': 7.25.0
dependencies:
'@antfu/install-pkg': 0.4.1
'@clack/prompts': 0.7.0
@@ -10420,7 +10429,7 @@ snapshots:
'@stylistic/eslint-plugin': 2.8.0([email protected]([email protected]))([email protected])
'@typescript-eslint/parser': 8.5.0([email protected]([email protected]))([email protected])
eslint: 9.10.0([email protected])
eslint-config-flat-gitignore: 0.3.0([email protected]([email protected]))
eslint-flat-config-utils: 0.4.0
@@ -12491,7 +12500,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
eslint: 9.10.0([email protected])
optionalDependencies: