tiptap/packages
Steven DeMartini f55171fb43
fix: types for Suggestion command, allowing generic overrides (#4136)
* Fix typing for Suggestion `command` with new MentionAttrs generic

As of
7cae9673f0,
new generics were added for Suggestion options and props. However,
there is a subtle bug in the current typing: the object selected with
the suggestion `command` need not have the same types as the `items` in
the suggestion options. For instance, in Tiptap's official demo
https://tiptap.dev/api/nodes/mention, the suggestion `items` are all
`string`s, but the selected Mention is of type `{id: string}` (which are
the attributes of the Mention node, as the Mention extension requires):

```ts
  const selectItem = index => {
    const item = props.items[index]

    if (item) {
      props.command({ id: item })
    }
  }
```

i.e., there should be no restriction that when you select something with
the suggestion `command`, it must use the identical structure as the
suggested items. When using the suggestion plugin with the Mention
extension, for instance, the value passed to the SuggestionProps
`props.command()` function must be a `Record<string, any>`, as it's
directly/exclusively used to set the `attrs` of a `Node` via
`insertContentAt` (and you need not use that shape for suggestion
options, as in the Tiptap example above):
44996d60be/packages/extension-mention/src/mention.ts (L42)
f869507396/packages/core/src/types.ts (L79)

This fixes the typing so that suggestions can correctly refer separately
to their own items (of any type), while ensuring the `command`ed item be
of whatever type is necessary (and so in the Mention context, could be
restricted further).

* Add generics to override selected suggestion type

---------

Co-authored-by: Steven DeMartini <sjdemartini@users.noreply.github.com>
2024-05-17 05:12:04 +02:00
..
core v2.4.0 2024-05-14 14:45:38 +02:00
extension-blockquote v2.4.0 2024-05-14 14:45:38 +02:00
extension-bold v2.4.0 2024-05-14 14:45:38 +02:00
extension-bubble-menu v2.4.0 2024-05-14 14:45:38 +02:00
extension-bullet-list v2.4.0 2024-05-14 14:45:38 +02:00
extension-character-count v2.4.0 2024-05-14 14:45:38 +02:00
extension-code v2.4.0 2024-05-14 14:45:38 +02:00
extension-code-block v2.4.0 2024-05-14 14:45:38 +02:00
extension-code-block-lowlight v2.4.0 2024-05-14 14:45:38 +02:00
extension-collaboration v2.4.0 2024-05-14 14:45:38 +02:00
extension-collaboration-cursor v2.4.0 2024-05-14 14:45:38 +02:00
extension-color v2.4.0 2024-05-14 14:45:38 +02:00
extension-document v2.4.0 2024-05-14 14:45:38 +02:00
extension-dropcursor v2.4.0 2024-05-14 14:45:38 +02:00
extension-floating-menu v2.4.0 2024-05-14 14:45:38 +02:00
extension-focus v2.4.0 2024-05-14 14:45:38 +02:00
extension-font-family v2.4.0 2024-05-14 14:45:38 +02:00
extension-gapcursor v2.4.0 2024-05-14 14:45:38 +02:00
extension-hard-break v2.4.0 2024-05-14 14:45:38 +02:00
extension-heading v2.4.0 2024-05-14 14:45:38 +02:00
extension-highlight v2.4.0 2024-05-14 14:45:38 +02:00
extension-history v2.4.0 2024-05-14 14:45:38 +02:00
extension-horizontal-rule v2.4.0 2024-05-14 14:45:38 +02:00
extension-image v2.4.0 2024-05-14 14:45:38 +02:00
extension-italic v2.4.0 2024-05-14 14:45:38 +02:00
extension-link fix: disable parsing javascript: links, add tests 2024-05-16 17:10:15 +02:00
extension-list-item v2.4.0 2024-05-14 14:45:38 +02:00
extension-list-keymap v2.4.0 2024-05-14 14:45:38 +02:00
extension-mention fix: types for Suggestion command, allowing generic overrides (#4136) 2024-05-17 05:12:04 +02:00
extension-ordered-list v2.4.0 2024-05-14 14:45:38 +02:00
extension-paragraph v2.4.0 2024-05-14 14:45:38 +02:00
extension-placeholder v2.4.0 2024-05-14 14:45:38 +02:00
extension-strike v2.4.0 2024-05-14 14:45:38 +02:00
extension-subscript v2.4.0 2024-05-14 14:45:38 +02:00
extension-superscript v2.4.0 2024-05-14 14:45:38 +02:00
extension-table v2.4.0 2024-05-14 14:45:38 +02:00
extension-table-cell v2.4.0 2024-05-14 14:45:38 +02:00
extension-table-header v2.4.0 2024-05-14 14:45:38 +02:00
extension-table-row v2.4.0 2024-05-14 14:45:38 +02:00
extension-task-item v2.4.0 2024-05-14 14:45:38 +02:00
extension-task-list v2.4.0 2024-05-14 14:45:38 +02:00
extension-text v2.4.0 2024-05-14 14:45:38 +02:00
extension-text-align v2.4.0 2024-05-14 14:45:38 +02:00
extension-text-style v2.4.0 2024-05-14 14:45:38 +02:00
extension-typography v2.4.0 2024-05-14 14:45:38 +02:00
extension-underline v2.4.0 2024-05-14 14:45:38 +02:00
extension-youtube v2.4.0 2024-05-14 14:45:38 +02:00
html v2.4.0 2024-05-14 14:45:38 +02:00
pm v2.4.0 2024-05-14 14:45:38 +02:00
react v2.4.0 2024-05-14 14:45:38 +02:00
starter-kit v2.4.0 2024-05-14 14:45:38 +02:00
suggestion fix: types for Suggestion command, allowing generic overrides (#4136) 2024-05-17 05:12:04 +02:00
vue-2 v2.4.0 2024-05-14 14:45:38 +02:00
vue-3 v2.4.0 2024-05-14 14:45:38 +02:00