Skip to content

Commit

Permalink
feat(VuetifyTiptap): add removeDefaultWrapper option to remove defaul…
Browse files Browse the repository at this point in the history
…t wrapper

Tiptap will automatically insert an empty <p> tag when in an empty editing state

fix #208
  • Loading branch information
yikoyu committed Jan 18, 2024
1 parent 5407d53 commit fa3c2db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ const content = ref('')
| label | string | undefined | Sets input label |
| hideToolbar | boolean | false | Hidden the toolbar |
| disableToolbar | boolean | false | Disable the toolbar |
| removeDefaultWrapper | boolean | false | Default wrapper when the delete editor is empty |
| maxWidth | string \| number | undefined | Sets the maximum width for the component. |
| minHeight | string \| number | undefined | Sets the minimum height for the component. |
| maxHeight | string \| number | undefined | Sets the maximum height for the component. |
Expand Down
1 change: 1 addition & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ const content = ref('')
| disabled | boolean | false | 禁用输入 |
| label | string | undefined | 设置输入标签 |
| hideToolbar | boolean | false | 隐藏工具栏 |
| removeDefaultWrapper | boolean | false | 删除编辑器为空时默认的包装器 |
| disableToolbar | boolean | false | 禁用工具栏 |
| maxWidth | string \| number | undefined | 输入框最大宽度 |
| minHeight | string \| number | undefined | 输入框最小高度 |
Expand Down
11 changes: 10 additions & 1 deletion src/components/VuetifyTiptap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type HandleKeyDown = NonNullable<EditorOptions['editorProps']['handleKeyDown']>
type OnUpdate = NonNullable<EditorOptions['onUpdate']>
interface Props {
modelValue?: string | JSONContent
modelValue?: string | object
markdownTheme?: string | false
output?: 'html' | 'json' | 'text'
dark?: boolean
Expand All @@ -29,6 +29,7 @@ interface Props {
label?: string
hideToolbar?: boolean
disableToolbar?: boolean
removeDefaultWrapper?: boolean
maxWidth?: string | number
minHeight?: string | number
maxHeight?: string | number
Expand All @@ -55,6 +56,7 @@ const props = withDefaults(defineProps<Props>(), {
label: undefined,
hideToolbar: false,
disableToolbar: false,
removeDefaultWrapper: false,
maxWidth: undefined,
minHeight: undefined,
maxHeight: undefined,
Expand Down Expand Up @@ -147,6 +149,13 @@ const contentDynamicStyles = computed(() => {
})
function getOutput(editor: CoreEditor, output: Props['output']) {
if (props.removeDefaultWrapper) {
if (output === 'html') return editor.isEmpty ? '' : editor.getHTML()
if (output === 'json') return editor.isEmpty ? {} : editor.getJSON()
if (output === 'text') return editor.isEmpty ? '' : editor.getText()
return ''
}
if (output === 'html') return editor.getHTML()
if (output === 'json') return editor.getJSON()
if (output === 'text') return editor.getText()
Expand Down

0 comments on commit fa3c2db

Please sign in to comment.