From 68d401a1004c1c85bde79e7d7f3ecb491934a881 Mon Sep 17 00:00:00 2001 From: Alexey Zinoviev Date: Thu, 25 Jul 2024 22:19:26 +0400 Subject: [PATCH] UBERF-7675: Remove heading text action from compact editors (#6143) Signed-off-by: Alexey Zinoviev --- models/text-editor/src/plugin.ts | 3 ++- plugins/text-editor-resources/src/index.ts | 5 +++-- plugins/text-editor-resources/src/kits/editor-kit.ts | 7 ++++++- plugins/text-editor/src/types.ts | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/models/text-editor/src/plugin.ts b/models/text-editor/src/plugin.ts index eaa4be1674..f6629213b7 100644 --- a/models/text-editor/src/plugin.ts +++ b/models/text-editor/src/plugin.ts @@ -30,6 +30,7 @@ export default mergeIds(textEditorId, textEditor, { MoreImageActions: '' as Resource, IsEditableTableActive: '' as Resource, - IsEditable: '' as Resource + IsEditable: '' as Resource, + IsHeadingVisible: '' as Resource } }) diff --git a/plugins/text-editor-resources/src/index.ts b/plugins/text-editor-resources/src/index.ts index a1b18d1a19..234ade4be8 100644 --- a/plugins/text-editor-resources/src/index.ts +++ b/plugins/text-editor-resources/src/index.ts @@ -16,7 +16,7 @@ import { type Resources } from '@hcengineering/platform' import { formatLink } from './kits/default-kit' -import { isEditable } from './kits/editor-kit' +import { isEditable, isHeadingVisible } from './kits/editor-kit' import { openTableOptions, isEditableTableActive } from './components/extension/table/table' import { openImage, expandImage, moreImageActions } from './components/extension/imageExt' @@ -87,6 +87,7 @@ export default async (): Promise => ({ ExpandImage: expandImage, MoreImageActions: moreImageActions, IsEditableTableActive: isEditableTableActive, - IsEditable: isEditable + IsEditable: isEditable, + IsHeadingVisible: isHeadingVisible } }) diff --git a/plugins/text-editor-resources/src/kits/editor-kit.ts b/plugins/text-editor-resources/src/kits/editor-kit.ts index 61206551b5..a9b639fe23 100644 --- a/plugins/text-editor-resources/src/kits/editor-kit.ts +++ b/plugins/text-editor-resources/src/kits/editor-kit.ts @@ -21,7 +21,7 @@ import TableHeader from '@tiptap/extension-table-header' import 'prosemirror-codemark/dist/codemark.css' import { getBlobRef, getClient } from '@hcengineering/presentation' import { CodeBlockExtension, codeBlockOptions, CodeExtension, codeOptions } from '@hcengineering/text' -import textEditor, { type ExtensionCreator, type TextEditorMode } from '@hcengineering/text-editor' +import textEditor, { type ActionContext, type ExtensionCreator, type TextEditorMode } from '@hcengineering/text-editor' import { DefaultKit, type DefaultKitOptions } from './default-kit' import { HardBreakExtension } from '../components/extension/hardBreak' @@ -247,6 +247,7 @@ async function buildEditorKit (): Promise> { element: this.options.toolbar?.element, isHidden: this.options.toolbar?.isHidden, ctx: { + mode, objectId: this.options.objectId, objectClass: this.options.objectClass, objectSpace: this.options.objectSpace @@ -273,3 +274,7 @@ async function buildEditorKit (): Promise> { export async function isEditable (editor: Editor): Promise { return editor.isEditable } + +export async function isHeadingVisible (editor: Editor, ctx: ActionContext): Promise { + return (await isEditable(editor)) && ctx.mode === 'full' +} diff --git a/plugins/text-editor/src/types.ts b/plugins/text-editor/src/types.ts index 2328233a4d..18c8100b41 100644 --- a/plugins/text-editor/src/types.ts +++ b/plugins/text-editor/src/types.ts @@ -99,6 +99,7 @@ export type TextEditorCommand = (props: TextEditorCommandProps) => boolean * @public */ export interface ActionContext { + mode: TextEditorMode objectId?: Ref objectClass?: Ref> objectSpace?: Ref