@platejs/ai 53.1.6 → 53.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.
@@ -1,4 +1,4 @@
1
- import * as platejs13 from "platejs";
1
+ import * as platejs0 from "platejs";
2
2
  import { Descendant, History, OmitFirst, Path, PluginConfig, SlateEditor, TLocation, Value } from "platejs";
3
3
 
4
4
  //#region src/lib/transforms/aiStreamSnapshot.d.ts
@@ -67,31 +67,31 @@ type BaseAIPluginConfig = PluginConfig<'ai', {}, {}, {
67
67
  undo: OmitFirst<typeof undoAI>;
68
68
  };
69
69
  }>;
70
- declare const BaseAIPlugin: platejs13.SlatePlugin<PluginConfig<"ai", {}, {}, {
70
+ declare const BaseAIPlugin: platejs0.SlatePlugin<PluginConfig<"ai", {}, {}, {
71
71
  ai: {
72
- acceptPreview: ((_value?: platejs13.Value | undefined) => boolean) & ((_value?: platejs13.Value | undefined) => boolean);
72
+ acceptPreview: ((_value?: platejs0.Value | undefined) => boolean) & ((_value?: platejs0.Value | undefined) => boolean);
73
73
  beginPreview: ((args_0?: {
74
- originalBlocks?: platejs13.Value;
74
+ originalBlocks?: platejs0.Value;
75
75
  } | undefined) => boolean) & ((args_0?: {
76
- originalBlocks?: platejs13.Value;
76
+ originalBlocks?: platejs0.Value;
77
77
  } | undefined) => boolean);
78
78
  cancelPreview: (() => boolean) & (() => boolean);
79
79
  discardPreview: (() => boolean) & (() => boolean);
80
80
  hasPreview: (() => boolean) & (() => boolean);
81
- insertNodes: ((nodes: platejs13.Descendant[], args_1?: {
82
- target?: platejs13.Path;
83
- } | undefined) => void) & ((nodes: platejs13.Descendant[], args_1?: {
84
- target?: platejs13.Path;
81
+ insertNodes: ((nodes: platejs0.Descendant[], args_1?: {
82
+ target?: platejs0.Path;
83
+ } | undefined) => void) & ((nodes: platejs0.Descendant[], args_1?: {
84
+ target?: platejs0.Path;
85
85
  } | undefined) => void);
86
86
  removeMarks: ((args_0?: {
87
- at?: platejs13.TLocation;
87
+ at?: platejs0.TLocation;
88
88
  } | undefined) => void) & ((args_0?: {
89
- at?: platejs13.TLocation;
89
+ at?: platejs0.TLocation;
90
90
  } | undefined) => void);
91
91
  removeNodes: ((args_0?: {
92
- at?: platejs13.Path;
92
+ at?: platejs0.Path;
93
93
  } | undefined) => void) & ((args_0?: {
94
- at?: platejs13.Path;
94
+ at?: platejs0.Path;
95
95
  } | undefined) => void);
96
96
  undo: (() => void) & (() => void);
97
97
  };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as hasAIPreview, S as discardAIPreview, _ as insertAINodes, a as EditorPromptParams, b as beginAIPreview, c as AIMode, d as BaseAIPluginConfig, f as AIBatch, g as removeAIMarks, h as removeAINodes, i as EditorPrompt, l as AIToolName, m as undoAI, n as MarkdownType, o as PromptConfig, p as withAIBatch, r as replacePlaceholders, s as getEditorPrompt, t as getMarkdown, u as BaseAIPlugin, v as AI_PREVIEW_KEY, x as cancelAIPreview, y as acceptAIPreview } from "./index-tNeux7Mo";
1
+ import { C as hasAIPreview, S as discardAIPreview, _ as insertAINodes, a as EditorPromptParams, b as beginAIPreview, c as AIMode, d as BaseAIPluginConfig, f as AIBatch, g as removeAIMarks, h as removeAINodes, i as EditorPrompt, l as AIToolName, m as undoAI, n as MarkdownType, o as PromptConfig, p as withAIBatch, r as replacePlaceholders, s as getEditorPrompt, t as getMarkdown, u as BaseAIPlugin, v as AI_PREVIEW_KEY, x as cancelAIPreview, y as acceptAIPreview } from "./index-D2hJDomP";
2
2
  export { AIBatch, AIMode, AIToolName, AI_PREVIEW_KEY, BaseAIPlugin, BaseAIPluginConfig, EditorPrompt, EditorPromptParams, MarkdownType, PromptConfig, acceptAIPreview, beginAIPreview, cancelAIPreview, discardAIPreview, getEditorPrompt, getMarkdown, hasAIPreview, insertAINodes, removeAIMarks, removeAINodes, replacePlaceholders, undoAI, withAIBatch };
@@ -1,5 +1,5 @@
1
- import { c as AIMode, d as BaseAIPluginConfig, i as EditorPrompt, l as AIToolName } from "../index-tNeux7Mo";
2
- import * as platejs0 from "platejs";
1
+ import { c as AIMode, d as BaseAIPluginConfig, i as EditorPrompt, l as AIToolName } from "../index-D2hJDomP";
2
+ import * as platejs12 from "platejs";
3
3
  import { Descendant, EditorNodesOptions, ExtendConfig, NodeEntry, OmitFirst, Path, PluginConfig, Range, RemoveNodesOptions, SlateEditor, TElement, TIdElement, TRange, TTableElement, TText } from "platejs";
4
4
  import { DeserializeMdOptions, SerializeMdOptions } from "@platejs/markdown";
5
5
  import * as platejs_react0 from "platejs/react";
@@ -11,31 +11,31 @@ import { TriggerComboboxPluginOptions } from "@platejs/combobox";
11
11
 
12
12
  //#region src/react/ai/AIPlugin.d.ts
13
13
  type AIPluginConfig = ExtendConfig<BaseAIPluginConfig>;
14
- declare const AIPlugin: platejs_react0.PlatePlugin<platejs0.PluginConfig<"ai", {}, {}, {
14
+ declare const AIPlugin: platejs_react0.PlatePlugin<platejs12.PluginConfig<"ai", {}, {}, {
15
15
  ai: {
16
- acceptPreview: ((_value?: platejs0.Value | undefined) => boolean) & ((_value?: platejs0.Value | undefined) => boolean);
16
+ acceptPreview: ((_value?: platejs12.Value | undefined) => boolean) & ((_value?: platejs12.Value | undefined) => boolean);
17
17
  beginPreview: ((args_0?: {
18
- originalBlocks?: platejs0.Value;
18
+ originalBlocks?: platejs12.Value;
19
19
  } | undefined) => boolean) & ((args_0?: {
20
- originalBlocks?: platejs0.Value;
20
+ originalBlocks?: platejs12.Value;
21
21
  } | undefined) => boolean);
22
22
  cancelPreview: (() => boolean) & (() => boolean);
23
23
  discardPreview: (() => boolean) & (() => boolean);
24
24
  hasPreview: (() => boolean) & (() => boolean);
25
- insertNodes: ((nodes: platejs0.Descendant[], args_1?: {
26
- target?: platejs0.Path;
27
- } | undefined) => void) & ((nodes: platejs0.Descendant[], args_1?: {
28
- target?: platejs0.Path;
25
+ insertNodes: ((nodes: platejs12.Descendant[], args_1?: {
26
+ target?: platejs12.Path;
27
+ } | undefined) => void) & ((nodes: platejs12.Descendant[], args_1?: {
28
+ target?: platejs12.Path;
29
29
  } | undefined) => void);
30
30
  removeMarks: ((args_0?: {
31
- at?: platejs0.TLocation;
31
+ at?: platejs12.TLocation;
32
32
  } | undefined) => void) & ((args_0?: {
33
- at?: platejs0.TLocation;
33
+ at?: platejs12.TLocation;
34
34
  } | undefined) => void);
35
35
  removeNodes: ((args_0?: {
36
- at?: platejs0.Path;
36
+ at?: platejs12.Path;
37
37
  } | undefined) => void) & ((args_0?: {
38
- at?: platejs0.Path;
38
+ at?: platejs12.Path;
39
39
  } | undefined) => void);
40
40
  undo: (() => void) & (() => void);
41
41
  };
@@ -223,7 +223,7 @@ declare const AIChatPlugin: platejs_react0.PlatePlugin<PluginConfig<"aiChat", {
223
223
  reload: () => void;
224
224
  show: () => void;
225
225
  stop: () => void;
226
- }, "node" | "stop" | "reset" | "submit">> & Record<"aiChat", {
226
+ }, "node" | "reset" | "stop" | "submit">> & Record<"aiChat", {
227
227
  hide: ({
228
228
  focus,
229
229
  undo
@@ -244,7 +244,7 @@ declare const AIChatPlugin: platejs_react0.PlatePlugin<PluginConfig<"aiChat", {
244
244
  insertBelow: (sourceEditor: SlateEditor, args_1?: {
245
245
  format?: "all" | "none" | "single";
246
246
  } | undefined) => void;
247
- removeAnchor: (options?: platejs0.RemoveNodesOptions | undefined) => void;
247
+ removeAnchor: (options?: platejs12.RemoveNodesOptions | undefined) => void;
248
248
  replaceSelection: (sourceEditor: SlateEditor, args_1?: {
249
249
  format?: "all" | "none" | "single";
250
250
  } | undefined) => void;
@@ -262,7 +262,7 @@ declare const withAIChat: OverrideEditor<AIChatPluginConfig>;
262
262
  */
263
263
  declare const useAIChatEditor: (editor: SlateEditor, content: string, {
264
264
  parser
265
- }?: DeserializeMdOptions) => platejs0.Value;
265
+ }?: DeserializeMdOptions) => platejs12.Value;
266
266
  //#endregion
267
267
  //#region src/react/ai-chat/hooks/useChatChunk.d.ts
268
268
  declare const useChatChunk: ({
@@ -298,7 +298,7 @@ declare const useEditorChat: ({
298
298
  }: UseEditorChatOptions) => void;
299
299
  //#endregion
300
300
  //#region src/react/ai-chat/streaming/streamDeserializeInlineMd.d.ts
301
- declare const streamDeserializeInlineMd: (editor: PlateEditor, text: string, options?: DeserializeMdOptions) => platejs0.Descendant[] | {
301
+ declare const streamDeserializeInlineMd: (editor: PlateEditor, text: string, options?: DeserializeMdOptions) => platejs12.Descendant[] | {
302
302
  text: string;
303
303
  }[];
304
304
  //#endregion
@@ -317,7 +317,7 @@ type SteamInsertChunkOptions = {
317
317
  };
318
318
  declare const getInsertPreviewStart: (editor: SlateEditor) => {
319
319
  path: Path;
320
- startBlock: platejs0.TElement | platejs0.TText | undefined;
320
+ startBlock: platejs12.TElement | platejs12.TText | undefined;
321
321
  startInEmptyParagraph: boolean;
322
322
  };
323
323
  /** @experimental */
@@ -947,6 +947,7 @@ const withoutDeserializeInMdx = (editor, input) => {
947
947
 
948
948
  //#endregion
949
949
  //#region src/react/ai-chat/streaming/streamSerializeMd.ts
950
+ const STREAM_LINE_BREAK_PLACEHOLDER = "platejs-stream-line-break";
950
951
  const trimEndHeading = (editor, value) => {
951
952
  const headingKeys = new Set([
952
953
  KEYS.h1,
@@ -977,9 +978,40 @@ const trimEndHeading = (editor, value) => {
977
978
  value
978
979
  };
979
980
  };
981
+ const escapeEmbeddedTextLineBreaks = (nodes) => {
982
+ let hasLineBreaks = false;
983
+ const value = nodes.map((node) => {
984
+ if (TextApi.isText(node)) {
985
+ if (node.text !== "\n" && node.text.includes("\n")) {
986
+ hasLineBreaks = true;
987
+ return {
988
+ ...node,
989
+ text: node.text.replaceAll("\n", STREAM_LINE_BREAK_PLACEHOLDER)
990
+ };
991
+ }
992
+ return node;
993
+ }
994
+ if (ElementApi.isElement(node)) {
995
+ const escapedChildren = escapeEmbeddedTextLineBreaks(node.children);
996
+ if (escapedChildren.hasLineBreaks) {
997
+ hasLineBreaks = true;
998
+ return {
999
+ ...node,
1000
+ children: escapedChildren.value
1001
+ };
1002
+ }
1003
+ }
1004
+ return node;
1005
+ });
1006
+ return {
1007
+ hasLineBreaks,
1008
+ value
1009
+ };
1010
+ };
980
1011
  const streamSerializeMd = (editor, options, chunk) => {
981
1012
  const { value: optionsValue, ...restOptions } = options;
982
- const { value } = trimEndHeading(editor, optionsValue ?? editor.children);
1013
+ const { value: trimmedValue } = trimEndHeading(editor, optionsValue ?? editor.children);
1014
+ const { hasLineBreaks, value } = escapeEmbeddedTextLineBreaks(trimmedValue);
983
1015
  let result = "";
984
1016
  result = editor.getApi(MarkdownPlugin).markdown.serialize({
985
1017
  value,
@@ -991,6 +1023,15 @@ const streamSerializeMd = (editor, options, chunk) => {
991
1023
  result = result.replace(/&#x20;/g, " ");
992
1024
  result = result.replace(/&#x200B;/g, " ");
993
1025
  result = result.replace(/\u200B/g, "");
1026
+ if (hasLineBreaks) result = result.replaceAll(STREAM_LINE_BREAK_PLACEHOLDER, "\n");
1027
+ if (trimmedChunk.includes("\n") && trimmedChunk !== "\n\n") {
1028
+ const trimmedResult = result.trimEnd();
1029
+ if (trimmedResult.endsWith("\n<br />")) result = trimmedResult.slice(0, -6);
1030
+ else {
1031
+ const trailingWhitespaceBreakSuffix = `${trimmedChunk}\n`;
1032
+ if (result.endsWith(trailingWhitespaceBreakSuffix)) result = result.slice(0, -trailingWhitespaceBreakSuffix.length);
1033
+ }
1034
+ }
994
1035
  if (trimmedChunk !== "\n\n") result = result.trimEnd() + trimmedChunk;
995
1036
  if (chunk.endsWith("\n\n")) {
996
1037
  if (result === "\n") result = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platejs/ai",
3
- "version": "53.1.6",
3
+ "version": "53.2.2",
4
4
  "description": "Text AI plugin for Plate",
5
5
  "keywords": [
6
6
  "plate",
@@ -32,7 +32,7 @@
32
32
  "fastest-levenshtein": "1.0.16",
33
33
  "lodash": "^4.17.21",
34
34
  "react-compiler-runtime": "^1.0.0",
35
- "@platejs/markdown": "^53.1.5",
35
+ "@platejs/markdown": "^53.2.2",
36
36
  "@platejs/selection": "^53.1.6",
37
37
  "@platejs/suggestion": "^53.0.3",
38
38
  "@platejs/table": "^53.0.9"
@@ -41,7 +41,7 @@
41
41
  "@ai-sdk/react": "^3.0.0",
42
42
  "ai": "^6.0.0",
43
43
  "@plate/scripts": "1.0.0",
44
- "platejs": "^53.1.2"
44
+ "platejs": "^53.2.1"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "platejs": ">=53.0.7",