From 779319abeeaf7bed8dc8c91cb869f44c0e5da905 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Sat, 2 Mar 2024 07:32:38 +0000 Subject: [PATCH] fix(nc-gui): form rich text placeholder and render as text issue --- packages/nc-gui/components/cell/RichText.vue | 95 +++++++++++-------- .../nc-gui/components/smartsheet/Form.vue | 61 +++++++----- packages/nc-gui/lang/en.json | 1 + 3 files changed, 94 insertions(+), 63 deletions(-) diff --git a/packages/nc-gui/components/cell/RichText.vue b/packages/nc-gui/components/cell/RichText.vue index ba890dcdfb..4038611637 100644 --- a/packages/nc-gui/components/cell/RichText.vue +++ b/packages/nc-gui/components/cell/RichText.vue @@ -6,6 +6,7 @@ import TurndownService from 'turndown' import { marked } from 'marked' import { generateJSON } from '@tiptap/html' import Underline from '@tiptap/extension-underline' +import Placeholder from '@tiptap/extension-placeholder' import { TaskItem } from '@/helpers/dbTiptapExtensions/task-item' import { Link } from '@/helpers/dbTiptapExtensions/links' import { IsExpandedFormOpenInj, IsFormInj, ReadonlyInj, RowHeightInj, onClickOutside } from '#imports' @@ -19,6 +20,8 @@ const props = defineProps<{ isFormField?: boolean autofocus?: boolean isTabPressed?: boolean + placeholder?: string + renderAsText?: boolean }>() const emits = defineEmits(['update:value']) @@ -117,6 +120,10 @@ const tiptapExtensions = [ }), Underline, Link, + Placeholder.configure({ + emptyEditorClass: 'is-editor-empty', + placeholder: props.placeholder, + }), ] const editor = useEditor({ @@ -140,16 +147,6 @@ const editor = useEditor({ }, }) -watch(props, () => { - if (props.isFormField) { - if (props.readOnly) { - editor.value?.setEditable(false) - } else { - editor.value?.setEditable(true) - } - } -}) - const setEditorContent = (contentMd: any, focusEndOfDoc?: boolean) => { if (!editor.value) return @@ -176,8 +173,18 @@ const setEditorContent = (contentMd: any, focusEndOfDoc?: boolean) => { }, 100) } +watch([props, editor], () => { + if (props.isFormField) { + if (props.readOnly && editor.value?.isEditable) { + editor.value?.setEditable(false) + } else if (!editor.value?.isEditable) { + editor.value?.setEditable(true) + } + } +}) + if (props.syncValueChange) { - watch(vModel, () => { + watch([vModel, editor], () => { setEditorContent(vModel.value) }) } @@ -214,34 +221,39 @@ onClickOutside(editorDom, (e) => { }" :tabindex="readOnlyCell || isFormField ? -1 : 0" > -
-
- -
-
- - - -
- +
+ {{ editor?.getText() ?? '' }}
+
@@ -302,6 +314,13 @@ onClickOutside(editorDom, (e) => { } .nc-textarea-rich-editor { + .tiptap p.is-editor-empty:first-child::before { + color: #6a7184; + content: attr(data-placeholder); + float: left; + height: 0; + pointer-events: none; + } .ProseMirror { @apply flex-grow pt-1 border-1 border-gray-200 rounded-lg; diff --git a/packages/nc-gui/components/smartsheet/Form.vue b/packages/nc-gui/components/smartsheet/Form.vue index 47813540ea..cdd0b8fafd 100644 --- a/packages/nc-gui/components/smartsheet/Form.vue +++ b/packages/nc-gui/components/smartsheet/Form.vue @@ -827,6 +827,7 @@ useEventListener( @@ -869,6 +872,7 @@ useEventListener( @@ -935,7 +940,7 @@ useEventListener(