Skip to content

Commit

Permalink
Merge pull request #4101 from udecode/fix/suggestion
Browse files Browse the repository at this point in the history
Fix/suggestion
  • Loading branch information
felixfeng33 authored Feb 21, 2025
2 parents 968faef + 1a6c82e commit 1eb477f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-lamps-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-suggestion': patch
---

Fix suggestion `api.node` when pass id.
6 changes: 3 additions & 3 deletions packages/suggestion/src/lib/BaseSuggestionPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
TSuggestionText,
} from './types';

import { getSuggestionKeyId } from './utils';
import { getSuggestionKey, getSuggestionKeyId } from './utils';
import { withSuggestion } from './withSuggestion';

export const SUGGESTION_KEYS = {
Expand All @@ -41,7 +41,7 @@ export type BaseSuggestionConfig = PluginConfig<
dataList: (node: TSuggestionText) => TInlineSuggestionData[];
isBlockSuggestion: (node: TElement) => node is TSuggestionElement;
node: (
options?: EditorNodesOptions & { isText?: boolean }
options?: EditorNodesOptions & { id?: string; isText?: boolean }
) => NodeEntry<TSuggestionElement | TSuggestionText> | undefined;
nodeId: (node: TElement | TSuggestionText) => string | undefined;
nodes: (
Expand Down Expand Up @@ -131,7 +131,7 @@ export const BaseSuggestionPlugin = createTSlatePlugin<BaseSuggestionConfig>({
if (isText && !TextApi.isText(n)) return false;
if (id) {
if (TextApi.isText(n)) {
return !!n[getSuggestionKeyId(n)!];
return !!n[getSuggestionKey(id)];
}
if (
ElementApi.isElement(n) &&
Expand Down
2 changes: 1 addition & 1 deletion packages/suggestion/src/lib/utils/getSuggestionKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { BaseSuggestionPlugin } from '../BaseSuggestionPlugin';
import { getInlineSuggestionData } from './getSuggestionId';

export const getSuggestionKey = (id = '0') =>
export const getSuggestionKey = (id = '0'): string =>
`${BaseSuggestionPlugin.key}_${id}`;

export const isSuggestionKey = (key: string) =>
Expand Down

0 comments on commit 1eb477f

Please sign in to comment.