@platejs/ai 50.2.0 → 50.2.2

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.
@@ -3202,7 +3202,7 @@ var removeAnchorAIChat = (editor, options) => {
3202
3202
  // src/react/ai-chat/utils/resetAIChat.ts
3203
3203
  import { KEYS as KEYS8 } from "platejs";
3204
3204
  import { getEditorPlugin as getEditorPlugin2 } from "platejs/react";
3205
- var resetAIChat = (editor) => {
3205
+ var resetAIChat = (editor, { undo = true } = {}) => {
3206
3206
  const { api, getOptions, setOptions } = getEditorPlugin2(
3207
3207
  editor,
3208
3208
  {
@@ -3220,7 +3220,9 @@ var resetAIChat = (editor) => {
3220
3220
  mode: "insert",
3221
3221
  toolName: "generate"
3222
3222
  });
3223
- editor.getTransforms(AIPlugin).ai.undo();
3223
+ if (undo) {
3224
+ editor.getTransforms(AIPlugin).ai.undo();
3225
+ }
3224
3226
  };
3225
3227
 
3226
3228
  // src/react/ai-chat/utils/submitAIChat.ts
@@ -3263,6 +3265,7 @@ var submitAIChat = (editor, input, {
3263
3265
  const selection = blocks.length > 0 ? blocksRange : editor.selection;
3264
3266
  const chatNodes = blocks.length > 0 ? blocks.map((block) => block[0]) : editor.api.fragment();
3265
3267
  setOption("chatNodes", chatNodes);
3268
+ setOption("chatSelection", blocks.length > 0 ? null : editor.selection);
3266
3269
  const ctx = {
3267
3270
  children: editor.children,
3268
3271
  selection: selection ?? null,
@@ -3353,6 +3356,7 @@ var AIChatPlugin = createTPlatePlugin({
3353
3356
  aiEditor: null,
3354
3357
  chat: { messages: [] },
3355
3358
  chatNodes: [],
3359
+ chatSelection: null,
3356
3360
  experimental_lastTextId: null,
3357
3361
  mode: "insert",
3358
3362
  open: false,
@@ -3392,8 +3396,13 @@ var AIChatPlugin = createTPlatePlugin({
3392
3396
  });
3393
3397
  },
3394
3398
  reload: () => {
3395
- const { chat } = getOptions();
3399
+ const { chat, chatNodes, chatSelection } = getOptions();
3396
3400
  editor.getTransforms(AIPlugin).ai.undo();
3401
+ if (chatSelection) {
3402
+ editor.tf.setSelection(chatSelection);
3403
+ } else {
3404
+ editor.getApi(BlockSelectionPlugin4).blockSelection.set(chatNodes.map((node) => node.id));
3405
+ }
3397
3406
  const blocks = editor.getApi(BlockSelectionPlugin4).blockSelection.getNodes();
3398
3407
  const selection = blocks.length > 0 ? editor.api.nodesRange(blocks) : editor.selection;
3399
3408
  const ctx = {
@@ -3413,8 +3422,11 @@ var AIChatPlugin = createTPlatePlugin({
3413
3422
  }
3414
3423
  };
3415
3424
  }).extendApi(({ api, editor, getOptions, setOption, tf, type }) => ({
3416
- hide: ({ focus = true } = {}) => {
3417
- api.aiChat.reset();
3425
+ hide: ({
3426
+ focus = true,
3427
+ undo = true
3428
+ } = {}) => {
3429
+ api.aiChat.reset({ undo });
3418
3430
  setOption("open", false);
3419
3431
  if (focus) {
3420
3432
  if (editor.getOption(BlockSelectionPlugin4, "isSelectingSome")) {
@@ -4028,6 +4040,7 @@ var applyAISuggestions = (editor, content) => {
4028
4040
  });
4029
4041
  }
4030
4042
  });
4043
+ editor.getApi(BlockSelectionPlugin6).blockSelection.set(diffNodes.map((node) => node.id));
4031
4044
  setReplaceIds(diffNodes.map((node) => node.id));
4032
4045
  } else {
4033
4046
  const diffNodes = getDiffNodes(editor, content);