Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/web-pkg/src/editor/components/TextEditorToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ const visible = computed(() => {
if (unref(textEditor.readonly)) {
return false
}
if (unref(textEditor.contentType) === 'plain-text') {
return false
}
return !!unref(textEditor.editor)
})

Expand Down
38 changes: 31 additions & 7 deletions packages/web-pkg/src/editor/composables/strategies/plainText.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Editor } from '@tiptap/vue-3'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import HardBreak from '@tiptap/extension-hard-break'
import { Extension } from '@tiptap/core'
import { EditorActionGroup } from '../useEditorActions'
import StarterKit from '@tiptap/starter-kit'
import { EditorActionGroup, useEditorActions } from '../useEditorActions'
import { ContentTypeStrategy } from './types'
import { TextEditorState } from '../../types'
import { useGettext } from 'vue3-gettext'

export const useStrategyPlainText = (editorState: TextEditorState): ContentTypeStrategy => {
const { $gettext } = useGettext()

const editorContentType = () => {
return 'plainText'
}
Expand All @@ -35,11 +35,35 @@ export const useStrategyPlainText = (editorState: TextEditorState): ContentTypeS
}

const extensions = (): Extension[] => {
return [Document, Paragraph, Text, HardBreak]
return [
StarterKit.configure({
blockquote: false,
bold: false,
bulletList: false,
code: false,
codeBlock: false,
dropcursor: false,
gapcursor: false,
heading: false,
horizontalRule: false,
italic: false,
listItem: false,
listKeymap: false,
orderedList: false,
strike: false
})
]
}

const { undo, redo } = useEditorActions(editorState)
const editorActionGroups = (): EditorActionGroup[] => {
return []
return [
{
id: 'history',
title: $gettext('History'),
actions: [undo(), redo()]
}
]
}

return {
Expand Down
6 changes: 5 additions & 1 deletion packages/web-pkg/src/editor/composables/useTextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export function useTextEditor(options: TextEditorOptions): TextEditorInstance {
const extensions = strategy.extensions()
if (options.slashCommands !== false) {
const resolvedGroups = strategy.editorActionGroups()
if (resolvedGroups.length > 0) {
const hasSlashCommandItems = resolvedGroups.some((group) =>
group.actions.some((action) => action.showInSlashCommands !== false)
)

if (hasSlashCommandItems) {
extensions.push(
SlashCommands.configure({ getGroups: () => resolvedGroups }) as (typeof extensions)[number]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('useTextEditor', () => {
expect(pluginNames).toContain('slashCommands')
})

it('does not register the extension for plain-text (no action groups)', () => {
it('does not register the extension for plain-text when all actions are hidden in slash commands', () => {
const { result } = createEditor({
contentType: 'plain-text',
modelValue: toRef('hi'),
Expand Down
32 changes: 22 additions & 10 deletions packages/web-pkg/tests/unit/editor/strategies/plainText.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
import { vi, describe, it, expect } from 'vitest'
import { vi, describe, it, expect, beforeEach } from 'vitest'
import { ref } from 'vue'
import type { TextEditorState } from '../../../../src/editor/types'
import { useStrategyPlainText } from '../../../../src/editor/composables/strategies/plainText'
import { createTestingPinia } from '@opencloud-eu/web-test-helpers'

vi.mock('vue3-gettext', () => ({
useGettext: () => ({ $gettext: (text: string) => text })
}))

function createStrategy() {
const state: TextEditorState = { sourceMode: ref(false) }
return useStrategyPlainText(state)
}

describe('useStrategyPlainText', () => {
beforeEach(() => {
createTestingPinia()
})

describe('extensions', () => {
it('returns base extensions only', () => {
it('returns a starter kit extension', () => {
const strategy = createStrategy()
const names = strategy.extensions().map((e) => e.name)
expect(names).toContain('doc')
expect(names).toContain('paragraph')
expect(names).toContain('text')
expect(names).toContain('hardBreak')
expect(names).not.toContain('bold')
expect(names).not.toContain('italic')
expect(names).toEqual(['starterKit'])
})
})

describe('editorActionGroups', () => {
it('returns empty array', () => {
it('returns history group with undo and redo', () => {
const strategy = createStrategy()
expect(strategy.editorActionGroups()).toEqual([])
expect(strategy.editorActionGroups()).toHaveLength(1)
expect(strategy.editorActionGroups()[0]).toMatchObject({
id: 'history',
title: 'History'
})
expect(strategy.editorActionGroups()[0].actions.map((action) => action.id)).toEqual([
'undo',
'redo'
])
})
})

Expand Down
Loading