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
13 changes: 6 additions & 7 deletions packages/web-pkg/src/editor/composables/strategies/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,20 @@ export const useStrategyHtml = (editorState: TextEditorState): ContentTypeStrate
underline,
strikethrough,
heading,
paragraph,
heading1,
heading2,
heading3,
heading4,
blockquote,
codeBlock,
alignLeft,
alignCenter,
alignRight,
alignJustify,
bulletList,
orderedList,
taskList,
blockquote,
codeBlock,
horizontalRule,
tableMenu,
createTable,
Expand Down Expand Up @@ -119,10 +120,13 @@ export const useStrategyHtml = (editorState: TextEditorState): ContentTypeStrate
title: $gettext('Formatting'),
actions: [
heading(),
paragraph(),
heading1(),
heading2(),
heading3(),
heading4(),
blockquote(),
codeBlock(),
fontSize(),
lineHeight(),
backgroundColor(),
Expand All @@ -143,11 +147,6 @@ export const useStrategyHtml = (editorState: TextEditorState): ContentTypeStrate
title: $gettext('Lists'),
actions: [bulletList(), orderedList(), taskList()]
},
{
id: 'blocks',
title: $gettext('Blocks'),
actions: [blockquote(), codeBlock()]
},
{
id: 'insert',
title: $gettext('Insert'),
Expand Down
13 changes: 6 additions & 7 deletions packages/web-pkg/src/editor/composables/strategies/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ export const useStrategyMarkdown = (editorState: TextEditorState): ContentTypeSt
italic,
strikethrough,
heading,
paragraph,
heading1,
heading2,
heading3,
heading4,
blockquote,
codeBlock,
bulletList,
orderedList,
taskList,
blockquote,
codeBlock,
horizontalRule,
image,
imageUrl,
Expand Down Expand Up @@ -94,10 +95,13 @@ export const useStrategyMarkdown = (editorState: TextEditorState): ContentTypeSt
title: $gettext('Formatting'),
actions: [
heading(),
paragraph(),
heading1(),
heading2(),
heading3(),
heading4(),
blockquote(),
codeBlock(),
bold(),
italic(),
strikethrough()
Expand All @@ -108,11 +112,6 @@ export const useStrategyMarkdown = (editorState: TextEditorState): ContentTypeSt
title: $gettext('Lists'),
actions: [bulletList(), orderedList(), taskList()]
},
{
id: 'blocks',
title: $gettext('Blocks'),
actions: [blockquote(), codeBlock()]
},
{
id: 'insert',
title: $gettext('Insert'),
Expand Down
57 changes: 47 additions & 10 deletions packages/web-pkg/src/editor/composables/useEditorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,54 @@ export function useEditorActions(

// Heading actions
const heading = (): EditorAction => ({
id: 'heading',
title: $gettext('Heading'),
icon: 'heading',
id: 'turn-into',
title: $gettext('Turn into'),
icon: 'text',
activeIcon: (editor) => {
for (const level of [1, 2, 3, 4] as const) {
if (editor.isActive('heading', { level })) {
return { icon: `h-${level}` }
for (const action of [
heading1(),
heading2(),
heading3(),
heading4(),
blockquote(),
codeBlock()
]) {
if (action.isActive?.(editor)) {
return { icon: action.icon }
}
}

return undefined
},
isActive: (editor) => editor.isActive('heading'),
isActive: (editor) =>
editor.isActive('heading') || editor.isActive('blockquote') || editor.isActive('codeBlock'),
showInSlashCommands: false,
childActions: [heading1(), heading2(), heading3(), heading4()]
childActions: [
paragraph(),
heading1(),
heading2(),
heading3(),
heading4(),
blockquote(),
codeBlock()
]
})

const paragraph = (): EditorAction => ({
id: 'paragraph',
title: $gettext('Paragraph'),
description: $gettext('Text paragraph'),
icon: 'text',
keywords: ['paragraph', 'text'],
toolbarAction: (editor) => editor.chain().focus().setParagraph().run(),
slashCommandAction: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).setNode('paragraph').run()
},
Comment thread
AlexAndBear marked this conversation as resolved.
isActive: (editor) => {
const { $from } = editor.state.selection
return $from.parent.type.name === 'paragraph' && $from.depth === 1
},
showInToolbar: false
})

const heading1 = (): EditorAction => ({
Expand Down Expand Up @@ -350,7 +384,8 @@ export function useEditorActions(
slashCommandAction: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).toggleBlockquote().run()
},
isActive: (editor) => editor.isActive('blockquote')
isActive: (editor) => editor.isActive('blockquote'),
showInToolbar: false
})

const codeBlock = (): EditorAction => ({
Expand All @@ -363,7 +398,8 @@ export function useEditorActions(
slashCommandAction: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).toggleCodeBlock().run()
},
isActive: (editor) => editor.isActive('codeBlock')
isActive: (editor) => editor.isActive('codeBlock'),
showInToolbar: false
})

// List actions
Expand Down Expand Up @@ -679,6 +715,7 @@ export function useEditorActions(
toggleSourceMode,
// Text formatting
heading,
paragraph,
heading1,
heading2,
heading3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ describe('useEditorActions', () => {
})

describe('heading', () => {
const getParagraphAction = () => {
return actions.heading().childActions!.find(({ id }) => id === 'paragraph')!
}

describe('paragraph', () => {
it('toolbarAction sets paragraph', () => {
const editor = createMockEditor()
getParagraphAction().toolbarAction!(editor)
expect(editor._chain.setParagraph).toHaveBeenCalled()
expect(editor._chain.run).toHaveBeenCalled()
})

it('slashCommandAction deletes range then sets paragraph node', () => {
const editor = createMockEditor()
getParagraphAction().slashCommandAction!({ editor, range: mockRange })
expect(editor._chain.deleteRange).toHaveBeenCalledWith(mockRange)
expect(editor._chain.setNode).toHaveBeenCalledWith('paragraph')
expect(editor._chain.run).toHaveBeenCalled()
})
})

const blockActions: ReadonlyArray<{
name: 'heading1' | 'heading2' | 'heading3' | 'heading4'
markName: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ describe('useStrategyMarkdown', () => {
const groupIds = strategy.editorActionGroups().map((g) => g.id)
expect(groupIds).toContain('formatting')
expect(groupIds).toContain('lists')
expect(groupIds).toContain('blocks')
expect(groupIds).toContain('insert')
})
})
Expand Down