@platejs/ai 53.1.5 → 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.
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +42 -1
- package/package.json +4 -4
package/dist/react/index.d.ts
CHANGED
|
@@ -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" | "
|
|
226
|
+
}, "node" | "reset" | "stop" | "submit">> & Record<"aiChat", {
|
|
227
227
|
hide: ({
|
|
228
228
|
focus,
|
|
229
229
|
undo
|
package/dist/react/index.js
CHANGED
|
@@ -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(/ /g, " ");
|
|
992
1024
|
result = result.replace(/​/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.
|
|
3
|
+
"version": "53.2.2",
|
|
4
4
|
"description": "Text AI plugin for Plate",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plate",
|
|
@@ -32,16 +32,16 @@
|
|
|
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.
|
|
35
|
+
"@platejs/markdown": "^53.2.2",
|
|
36
|
+
"@platejs/selection": "^53.1.6",
|
|
36
37
|
"@platejs/suggestion": "^53.0.3",
|
|
37
|
-
"@platejs/selection": "^53.0.0",
|
|
38
38
|
"@platejs/table": "^53.0.9"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
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
|
|
44
|
+
"platejs": "^53.2.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"platejs": ">=53.0.7",
|