@platejs/ai 50.2.0 → 50.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import * as platejs_react from 'platejs/react';
2
2
  import { PlateEditor, OverrideEditor, RenderNodeWrapperProps } from 'platejs/react';
3
3
  import * as platejs from 'platejs';
4
- import { ExtendConfig, SlateEditor, Range, NodeEntry, TElement, PluginConfig, Path, TIdElement, OmitFirst, EditorNodesOptions, TText, Descendant, RemoveNodesOptions } from 'platejs';
4
+ import { ExtendConfig, SlateEditor, Range, NodeEntry, TElement, PluginConfig, Path, TIdElement, TRange, OmitFirst, EditorNodesOptions, TText, Descendant, RemoveNodesOptions } from 'platejs';
5
5
  import { B as BaseAIPluginConfig, b as AIMode, E as EditorPrompt, A as AIToolName } from '../getEditorPrompt-C7EEuMw8.mjs';
6
6
  import { UIMessage, ChatRequestOptions } from 'ai';
7
7
  import { Range as Range$1 } from 'slate';
@@ -82,6 +82,7 @@ type AIChatPluginConfig = PluginConfig<'aiChat', {
82
82
  aiEditor: SlateEditor | null;
83
83
  chat: UseChatHelpers<ChatMessage>;
84
84
  chatNodes: TIdElement[];
85
+ chatSelection: TRange | null;
85
86
  /** @deprecated Use api.aiChat.node({streaming:true}) instead */
86
87
  experimental_lastTextId: string | null;
87
88
  /**
@@ -129,6 +130,7 @@ declare const AIChatPlugin: platejs_react.PlatePlugin<PluginConfig<"aiChat", {
129
130
  aiEditor: SlateEditor | null;
130
131
  chat: UseChatHelpers<ChatMessage>;
131
132
  chatNodes: TIdElement[];
133
+ chatSelection: TRange | null;
132
134
  /** @deprecated Use api.aiChat.node({streaming:true}) instead */
133
135
  experimental_lastTextId: string | null;
134
136
  /**
@@ -1,7 +1,7 @@
1
1
  import * as platejs_react from 'platejs/react';
2
2
  import { PlateEditor, OverrideEditor, RenderNodeWrapperProps } from 'platejs/react';
3
3
  import * as platejs from 'platejs';
4
- import { ExtendConfig, SlateEditor, Range, NodeEntry, TElement, PluginConfig, Path, TIdElement, OmitFirst, EditorNodesOptions, TText, Descendant, RemoveNodesOptions } from 'platejs';
4
+ import { ExtendConfig, SlateEditor, Range, NodeEntry, TElement, PluginConfig, Path, TIdElement, TRange, OmitFirst, EditorNodesOptions, TText, Descendant, RemoveNodesOptions } from 'platejs';
5
5
  import { B as BaseAIPluginConfig, b as AIMode, E as EditorPrompt, A as AIToolName } from '../getEditorPrompt-C7EEuMw8.js';
6
6
  import { UIMessage, ChatRequestOptions } from 'ai';
7
7
  import { Range as Range$1 } from 'slate';
@@ -82,6 +82,7 @@ type AIChatPluginConfig = PluginConfig<'aiChat', {
82
82
  aiEditor: SlateEditor | null;
83
83
  chat: UseChatHelpers<ChatMessage>;
84
84
  chatNodes: TIdElement[];
85
+ chatSelection: TRange | null;
85
86
  /** @deprecated Use api.aiChat.node({streaming:true}) instead */
86
87
  experimental_lastTextId: string | null;
87
88
  /**
@@ -129,6 +130,7 @@ declare const AIChatPlugin: platejs_react.PlatePlugin<PluginConfig<"aiChat", {
129
130
  aiEditor: SlateEditor | null;
130
131
  chat: UseChatHelpers<ChatMessage>;
131
132
  chatNodes: TIdElement[];
133
+ chatSelection: TRange | null;
132
134
  /** @deprecated Use api.aiChat.node({streaming:true}) instead */
133
135
  experimental_lastTextId: string | null;
134
136
  /**
@@ -3313,6 +3313,7 @@ var submitAIChat = (editor, input, {
3313
3313
  const selection = blocks.length > 0 ? blocksRange : editor.selection;
3314
3314
  const chatNodes = blocks.length > 0 ? blocks.map((block) => block[0]) : editor.api.fragment();
3315
3315
  setOption("chatNodes", chatNodes);
3316
+ setOption("chatSelection", blocks.length > 0 ? null : editor.selection);
3316
3317
  const ctx = {
3317
3318
  children: editor.children,
3318
3319
  selection: selection ?? null,
@@ -3403,6 +3404,7 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
3403
3404
  aiEditor: null,
3404
3405
  chat: { messages: [] },
3405
3406
  chatNodes: [],
3407
+ chatSelection: null,
3406
3408
  experimental_lastTextId: null,
3407
3409
  mode: "insert",
3408
3410
  open: false,
@@ -3442,8 +3444,13 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
3442
3444
  });
3443
3445
  },
3444
3446
  reload: () => {
3445
- const { chat } = getOptions();
3447
+ const { chat, chatNodes, chatSelection } = getOptions();
3446
3448
  editor.getTransforms(AIPlugin).ai.undo();
3449
+ if (chatSelection) {
3450
+ editor.tf.setSelection(chatSelection);
3451
+ } else {
3452
+ editor.getApi(import_react9.BlockSelectionPlugin).blockSelection.set(chatNodes.map((node) => node.id));
3453
+ }
3447
3454
  const blocks = editor.getApi(import_react9.BlockSelectionPlugin).blockSelection.getNodes();
3448
3455
  const selection = blocks.length > 0 ? editor.api.nodesRange(blocks) : editor.selection;
3449
3456
  const ctx = {
@@ -4059,6 +4066,7 @@ var applyAISuggestions = (editor, content) => {
4059
4066
  });
4060
4067
  }
4061
4068
  });
4069
+ editor.getApi(import_react19.BlockSelectionPlugin).blockSelection.set(diffNodes.map((node) => node.id));
4062
4070
  setReplaceIds(diffNodes.map((node) => node.id));
4063
4071
  } else {
4064
4072
  const diffNodes = getDiffNodes(editor, content);