-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(EditorSuggestionMenu): expose suggestion matching options #6234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
benjamincanac
merged 10 commits into
nuxt:v4
from
Archetipo95:feat/editor-suggestion-menu-suggestion-options
Apr 11, 2026
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
73c6a2e
feat(EditorMenu): add optional suggestion matching options to EditorMβ¦
Archetipo95 c4daa8f
test(useEditorMenu): add tests for suggestion matching options and deβ¦
Archetipo95 5537ad8
docs(EditorSuggestionMenu): add `suggestion` prop for customizable Tiβ¦
Archetipo95 e786e80
feat(EditorMenu): update suggestion options type to enforce plugin idβ¦
Archetipo95 925af55
chore: revert changelog
benjamincanac 608c236
Merge branch 'v4' into feat/editor-suggestion-menu-suggestion-options
benjamincanac 89413be
up
benjamincanac 784650f
fix: expose `suggestion` prop on all editor menu components
benjamincanac daff3e7
docs(EditorMentionMenu,EditorEmojiMenu): add suggestion prop documentβ¦
benjamincanac 0105940
test(useEditorMenu): enforce exactly one Suggestion call in getSuggesβ¦
benjamincanac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { computed } from 'vue' | ||
| import { beforeEach, describe, expect, it, vi, expectTypeOf } from 'vitest' | ||
| import type { SuggestionOptions } from '@tiptap/suggestion' | ||
| import { useEditorMenu } from '../../src/runtime/composables/useEditorMenu' | ||
| import type { EditorMenuOptions } from '../../src/runtime/composables/useEditorMenu' | ||
| import type { EditorSuggestionMenuProps } from '../../src/runtime/components/EditorSuggestionMenu.vue' | ||
|
|
||
| const { suggestionMock } = vi.hoisted(() => ({ | ||
| suggestionMock: vi.fn((config: any) => config) | ||
| })) | ||
|
|
||
| vi.mock('@tiptap/suggestion', () => ({ | ||
| default: suggestionMock | ||
| })) | ||
|
|
||
| function createEditor() { | ||
| const dom = document.createElement('div') | ||
| const parent = document.createElement('div') | ||
| parent.appendChild(dom) | ||
|
|
||
| return { | ||
| isDestroyed: false, | ||
| view: { | ||
| dom, | ||
| state: { | ||
| tr: { | ||
| setMeta: vi.fn(() => ({})) | ||
| } | ||
| }, | ||
| dispatch: vi.fn() | ||
| } | ||
| } as any | ||
| } | ||
|
|
||
| function createOptions(overrides: Partial<EditorMenuOptions<{ label: string }>> = {}): EditorMenuOptions<{ label: string }> { | ||
| return { | ||
| editor: createEditor(), | ||
| char: ':', | ||
| pluginKey: 'suggestion-menu', | ||
| items: [{ label: 'Alpha' }, { label: 'Beta' }], | ||
| onSelect: vi.fn(), | ||
| renderItem: vi.fn(() => []), | ||
| ui: computed(() => ({ | ||
| content: () => '', | ||
| viewport: () => '', | ||
| group: () => '', | ||
| label: () => '', | ||
| separator: () => '', | ||
| item: () => '', | ||
| itemLeadingIcon: () => '', | ||
| itemWrapper: () => '', | ||
| itemLabel: () => '', | ||
| itemDescription: () => '' | ||
| })), | ||
| ...overrides | ||
| } | ||
| } | ||
|
|
||
| function getSuggestionConfig() { | ||
| const config = suggestionMock.mock.calls[0]?.[0] | ||
|
|
||
| if (!config) { | ||
| throw new Error('Suggestion should be called exactly once') | ||
| } | ||
|
|
||
| return config | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| describe('useEditorMenu', () => { | ||
| beforeEach(() => { | ||
| suggestionMock.mockClear() | ||
| }) | ||
|
|
||
| it('forwards suggestion matching options', () => { | ||
| useEditorMenu(createOptions({ | ||
| suggestion: { | ||
| allowedPrefixes: null, | ||
| allowSpaces: true, | ||
| startOfLine: true | ||
| } | ||
| })) | ||
|
|
||
| const config = getSuggestionConfig() | ||
|
|
||
| expect(config.allowedPrefixes).toBeNull() | ||
| expect(config.allowSpaces).toBe(true) | ||
| expect(config.startOfLine).toBe(true) | ||
| expect(config.char).toBe(':') | ||
| }) | ||
|
|
||
| it('keeps existing defaults when suggestion is omitted', () => { | ||
| useEditorMenu(createOptions()) | ||
|
|
||
| const config = getSuggestionConfig() | ||
| const items = config.items({ query: 'al' }) | ||
|
|
||
| expect(config).not.toHaveProperty('allowedPrefixes') | ||
| expect(items).toEqual([{ label: 'Alpha' }]) | ||
| }) | ||
|
|
||
| it('keeps menu callbacks authoritative over suggestion overrides', () => { | ||
| const suggestionItems = vi.fn(() => []) | ||
| const suggestionCommand = vi.fn() | ||
| const suggestionRender = vi.fn() | ||
|
|
||
| useEditorMenu(createOptions({ | ||
| suggestion: { | ||
| items: suggestionItems, | ||
| command: suggestionCommand, | ||
| render: suggestionRender | ||
| } as Partial<SuggestionOptions> | ||
| })) | ||
|
|
||
| const config = getSuggestionConfig() | ||
|
|
||
| expect(config.items).not.toBe(suggestionItems) | ||
| expect(config.command).not.toBe(suggestionCommand) | ||
| expect(config.render).not.toBe(suggestionRender) | ||
| }) | ||
|
|
||
| it('types suggestion options on the composable and component props', () => { | ||
| expectTypeOf<EditorMenuOptions<{ label: string }>['suggestion']>().toMatchTypeOf<Partial<SuggestionOptions> | undefined>() | ||
| expectTypeOf<EditorSuggestionMenuProps['suggestion']>().toMatchTypeOf<Partial<SuggestionOptions> | undefined>() | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.