@platejs/ai 50.3.3 → 50.3.5

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.
@@ -66,7 +66,7 @@ declare const resetAIChat: (editor: PlateEditor, { undo }?: {
66
66
  undo?: boolean;
67
67
  }) => void;
68
68
 
69
- declare const submitAIChat: (editor: PlateEditor, input: string, { mode, options, prompt, toolName, }?: {
69
+ declare const submitAIChat: (editor: PlateEditor, input: string, { mode, options, prompt, toolName: toolNameProps, }?: {
70
70
  mode?: AIMode;
71
71
  options?: ChatRequestOptions;
72
72
  prompt?: EditorPrompt;
@@ -66,7 +66,7 @@ declare const resetAIChat: (editor: PlateEditor, { undo }?: {
66
66
  undo?: boolean;
67
67
  }) => void;
68
68
 
69
- declare const submitAIChat: (editor: PlateEditor, input: string, { mode, options, prompt, toolName, }?: {
69
+ declare const submitAIChat: (editor: PlateEditor, input: string, { mode, options, prompt, toolName: toolNameProps, }?: {
70
70
  mode?: AIMode;
71
71
  options?: ChatRequestOptions;
72
72
  prompt?: EditorPrompt;
@@ -619,7 +619,7 @@ var resetAIChat = (editor, { undo = true } = {}) => {
619
619
  _replaceIds: [],
620
620
  chatNodes: [],
621
621
  mode: "insert",
622
- toolName: "generate"
622
+ toolName: null
623
623
  });
624
624
  if (undo) {
625
625
  editor.getTransforms(AIPlugin).ai.undo();
@@ -635,7 +635,7 @@ var submitAIChat = (editor, input, {
635
635
  mode,
636
636
  options,
637
637
  prompt,
638
- toolName
638
+ toolName: toolNameProps
639
639
  } = {}) => {
640
640
  const { getOptions, setOption } = (0, import_react8.getEditorPlugin)(
641
641
  editor,
@@ -643,7 +643,8 @@ var submitAIChat = (editor, input, {
643
643
  key: import_platejs12.KEYS.aiChat
644
644
  }
645
645
  );
646
- const { chat } = getOptions();
646
+ const { chat, toolName: toolNameOption } = getOptions();
647
+ const toolName = toolNameProps ?? toolNameOption ?? null;
647
648
  if (!prompt && input?.length === 0) {
648
649
  return;
649
650
  }
@@ -657,20 +658,30 @@ var submitAIChat = (editor, input, {
657
658
  editor.getTransforms(AIPlugin).ai.undo();
658
659
  }
659
660
  setOption("mode", mode);
660
- setOption("toolName", toolName ?? null);
661
+ setOption("toolName", toolName);
661
662
  const blocks = editor.getApi(import_react7.BlockSelectionPlugin).blockSelection.getNodes();
662
663
  const blocksRange = editor.api.nodesRange(blocks);
663
664
  const promptText = getEditorPrompt(editor, {
664
665
  prompt
665
666
  });
666
667
  const selection = blocks.length > 0 ? blocksRange : editor.selection;
667
- const chatNodes = blocks.length > 0 ? blocks.map((block) => block[0]) : editor.api.fragment();
668
+ let chatNodes;
669
+ if (blocks.length > 0) {
670
+ chatNodes = blocks.map((block) => block[0]);
671
+ } else {
672
+ const selectionBlocks = editor.api.blocks({ mode: "highest" });
673
+ if (selectionBlocks.length > 1) {
674
+ chatNodes = selectionBlocks.map((block) => block[0]);
675
+ } else {
676
+ chatNodes = editor.api.fragment();
677
+ }
678
+ }
668
679
  setOption("chatNodes", chatNodes);
669
680
  setOption("chatSelection", blocks.length > 0 ? null : editor.selection);
670
681
  const ctx = {
671
682
  children: editor.children,
672
683
  selection: selection ?? null,
673
- toolName: toolName ?? null
684
+ toolName
674
685
  };
675
686
  void chat.sendMessage?.(
676
687
  {
@@ -1385,12 +1396,13 @@ var import_react19 = require("@platejs/selection/react");
1385
1396
  var import_suggestion3 = require("@platejs/suggestion");
1386
1397
  var import_platejs21 = require("platejs");
1387
1398
  var applyAISuggestions = (editor, content) => {
1399
+ editor.getApi({ key: import_platejs21.KEYS.cursorOverlay })?.cursorOverlay?.removeCursor("selection");
1388
1400
  const isBlockSelecting = editor.getOption(
1389
1401
  import_react19.BlockSelectionPlugin,
1390
1402
  "isSelectingSome"
1391
1403
  );
1392
1404
  const { chatNodes } = editor.getOptions(AIChatPlugin);
1393
- if (isBlockSelecting) {
1405
+ if (isBlockSelecting || editor.api.blocks({ mode: "highest" }).length > 1) {
1394
1406
  const setReplaceIds = (ids) => {
1395
1407
  editor.setOption(AIChatPlugin, "_replaceIds", ids);
1396
1408
  };