@platejs/ai 49.1.12 → 49.2.4
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/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +265 -206
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +249 -179
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +4 -2
- package/dist/react/index.d.ts +4 -2
- package/dist/react/index.js +71 -68
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +42 -38
- package/dist/react/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/react/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { toPlatePlugin } from "platejs/react";
|
|
|
5
5
|
import {
|
|
6
6
|
bindFirst,
|
|
7
7
|
createTSlatePlugin,
|
|
8
|
-
KEYS
|
|
8
|
+
KEYS as KEYS2
|
|
9
9
|
} from "platejs";
|
|
10
10
|
|
|
11
11
|
// src/lib/transforms/insertAINodes.ts
|
|
@@ -27,10 +27,12 @@ var insertAINodes = (editor, nodes, {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
// src/lib/transforms/removeAIMarks.ts
|
|
30
|
+
import { getPluginType, KEYS } from "platejs";
|
|
30
31
|
var removeAIMarks = (editor, { at = [] } = {}) => {
|
|
31
|
-
editor.
|
|
32
|
+
const nodeType = getPluginType(editor, KEYS.ai);
|
|
33
|
+
editor.tf.unsetNodes(nodeType, {
|
|
32
34
|
at,
|
|
33
|
-
match: (n) => n
|
|
35
|
+
match: (n) => n[nodeType]
|
|
34
36
|
});
|
|
35
37
|
};
|
|
36
38
|
|
|
@@ -71,7 +73,7 @@ var withAIBatch = (editor, fn, {
|
|
|
71
73
|
|
|
72
74
|
// src/lib/BaseAIPlugin.ts
|
|
73
75
|
var BaseAIPlugin = createTSlatePlugin({
|
|
74
|
-
key:
|
|
76
|
+
key: KEYS2.ai,
|
|
75
77
|
node: { isDecoration: false, isLeaf: true }
|
|
76
78
|
}).extendTransforms(({ editor }) => ({
|
|
77
79
|
insertNodes: bindFirst(insertAINodes, editor),
|
|
@@ -88,16 +90,17 @@ import { BlockSelectionPlugin as BlockSelectionPlugin5 } from "@platejs/selectio
|
|
|
88
90
|
import {
|
|
89
91
|
bindFirst as bindFirst2,
|
|
90
92
|
ElementApi as ElementApi3,
|
|
91
|
-
|
|
93
|
+
getPluginType as getPluginType3,
|
|
94
|
+
KEYS as KEYS11
|
|
92
95
|
} from "platejs";
|
|
93
96
|
import { createTPlatePlugin } from "platejs/react";
|
|
94
97
|
|
|
95
98
|
// src/react/ai-chat/transforms/acceptAIChat.ts
|
|
96
|
-
import { KEYS as
|
|
99
|
+
import { KEYS as KEYS3 } from "platejs";
|
|
97
100
|
import { getEditorPlugin } from "platejs/react";
|
|
98
101
|
var acceptAIChat = (editor) => {
|
|
99
102
|
const { tf } = getEditorPlugin(editor, AIPlugin);
|
|
100
|
-
const api = editor.getApi({ key:
|
|
103
|
+
const api = editor.getApi({ key: KEYS3.ai });
|
|
101
104
|
const lastAINodePath = api.aiChat.node({ at: [], reverse: true })[1];
|
|
102
105
|
withAIBatch(editor, () => {
|
|
103
106
|
tf.ai.removeMarks();
|
|
@@ -115,7 +118,7 @@ var acceptAIChat = (editor) => {
|
|
|
115
118
|
// src/react/ai-chat/transforms/insertBelowAIChat.ts
|
|
116
119
|
import { BlockSelectionPlugin as BlockSelectionPlugin2 } from "@platejs/selection/react";
|
|
117
120
|
import cloneDeep2 from "lodash/cloneDeep.js";
|
|
118
|
-
import { KEYS as
|
|
121
|
+
import { KEYS as KEYS5, PathApi, RangeApi } from "platejs";
|
|
119
122
|
|
|
120
123
|
// src/react/ai-chat/transforms/replaceSelectionAIChat.ts
|
|
121
124
|
import {
|
|
@@ -124,7 +127,7 @@ import {
|
|
|
124
127
|
} from "@platejs/selection/react";
|
|
125
128
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
126
129
|
import {
|
|
127
|
-
KEYS as
|
|
130
|
+
KEYS as KEYS4,
|
|
128
131
|
NodeApi,
|
|
129
132
|
TextApi as TextApi2
|
|
130
133
|
} from "platejs";
|
|
@@ -167,7 +170,7 @@ var replaceSelectionAIChat = (editor, sourceEditor, { format = "single" } = {})
|
|
|
167
170
|
BlockSelectionPlugin,
|
|
168
171
|
"isSelectingSome"
|
|
169
172
|
);
|
|
170
|
-
editor.getApi({ key:
|
|
173
|
+
editor.getApi({ key: KEYS4.ai }).aiChat.hide();
|
|
171
174
|
if (!isBlockSelecting) {
|
|
172
175
|
const firstBlock = editor.api.node({
|
|
173
176
|
block: true,
|
|
@@ -231,7 +234,7 @@ var insertBelowAIChat = (editor, sourceEditor, { format = "single" } = {}) => {
|
|
|
231
234
|
BlockSelectionPlugin2,
|
|
232
235
|
"isSelectingSome"
|
|
233
236
|
);
|
|
234
|
-
editor.getApi({ key:
|
|
237
|
+
editor.getApi({ key: KEYS5.ai }).aiChat.hide();
|
|
235
238
|
const insertBlocksAndSelect = editor.getTransforms(BlockSelectionPlugin2).blockSelection.insertBlocksAndSelect;
|
|
236
239
|
if (isBlockSelecting) {
|
|
237
240
|
const selectedBlocks = editor.getApi(BlockSelectionPlugin2).blockSelection.getNodes();
|
|
@@ -283,12 +286,12 @@ var insertBelowAIChat = (editor, sourceEditor, { format = "single" } = {}) => {
|
|
|
283
286
|
};
|
|
284
287
|
|
|
285
288
|
// src/react/ai-chat/transforms/removeAnchorAIChat.ts
|
|
286
|
-
import { ElementApi, KEYS as
|
|
289
|
+
import { ElementApi, getPluginType as getPluginType2, KEYS as KEYS6 } from "platejs";
|
|
287
290
|
var removeAnchorAIChat = (editor, options) => {
|
|
288
291
|
editor.tf.withoutSaving(() => {
|
|
289
292
|
editor.tf.removeNodes({
|
|
290
293
|
at: [],
|
|
291
|
-
match: (n) => ElementApi.isElement(n) && n.type ===
|
|
294
|
+
match: (n) => ElementApi.isElement(n) && n.type === getPluginType2(editor, KEYS6.aiChat),
|
|
292
295
|
...options
|
|
293
296
|
});
|
|
294
297
|
});
|
|
@@ -301,7 +304,7 @@ import { BlockSelectionPlugin as BlockSelectionPlugin4 } from "@platejs/selectio
|
|
|
301
304
|
// src/react/ai-chat/utils/getMarkdown.ts
|
|
302
305
|
import { serializeMd } from "@platejs/markdown";
|
|
303
306
|
import { BlockSelectionPlugin as BlockSelectionPlugin3 } from "@platejs/selection/react";
|
|
304
|
-
import { KEYS as
|
|
307
|
+
import { KEYS as KEYS7 } from "platejs";
|
|
305
308
|
var getMarkdown = (editor, type) => {
|
|
306
309
|
if (type === "editor") {
|
|
307
310
|
return serializeMd(editor);
|
|
@@ -320,7 +323,7 @@ var getMarkdown = (editor, type) => {
|
|
|
320
323
|
const modifiedFragment = [
|
|
321
324
|
{
|
|
322
325
|
children: fragment[0].children,
|
|
323
|
-
type:
|
|
326
|
+
type: KEYS7.p
|
|
324
327
|
}
|
|
325
328
|
];
|
|
326
329
|
return serializeMd(editor, { value: modifiedFragment });
|
|
@@ -382,11 +385,11 @@ var getEditorPrompt = (editor, {
|
|
|
382
385
|
};
|
|
383
386
|
|
|
384
387
|
// src/react/ai-chat/utils/resetAIChat.ts
|
|
385
|
-
import { KEYS as
|
|
388
|
+
import { KEYS as KEYS8 } from "platejs";
|
|
386
389
|
import { getEditorPlugin as getEditorPlugin2 } from "platejs/react";
|
|
387
390
|
var resetAIChat = (editor) => {
|
|
388
391
|
const { api, getOptions } = getEditorPlugin2(editor, {
|
|
389
|
-
key:
|
|
392
|
+
key: KEYS8.aiChat
|
|
390
393
|
});
|
|
391
394
|
api.aiChat.stop();
|
|
392
395
|
const chat = getOptions().chat;
|
|
@@ -398,7 +401,7 @@ var resetAIChat = (editor) => {
|
|
|
398
401
|
|
|
399
402
|
// src/react/ai-chat/utils/submitAIChat.ts
|
|
400
403
|
import { isSelecting as isSelecting2 } from "@platejs/selection";
|
|
401
|
-
import { KEYS as
|
|
404
|
+
import { KEYS as KEYS9 } from "platejs";
|
|
402
405
|
import { getEditorPlugin as getEditorPlugin3 } from "platejs/react";
|
|
403
406
|
var submitAIChat = (editor, {
|
|
404
407
|
mode,
|
|
@@ -409,7 +412,7 @@ var submitAIChat = (editor, {
|
|
|
409
412
|
const { getOptions, setOption } = getEditorPlugin3(
|
|
410
413
|
editor,
|
|
411
414
|
{
|
|
412
|
-
key:
|
|
415
|
+
key: KEYS9.aiChat
|
|
413
416
|
}
|
|
414
417
|
);
|
|
415
418
|
const { chat, promptTemplate, systemTemplate } = getOptions();
|
|
@@ -448,7 +451,7 @@ var submitAIChat = (editor, {
|
|
|
448
451
|
};
|
|
449
452
|
|
|
450
453
|
// src/react/ai-chat/withAIChat.ts
|
|
451
|
-
import { ElementApi as ElementApi2, KEYS as
|
|
454
|
+
import { ElementApi as ElementApi2, KEYS as KEYS10 } from "platejs";
|
|
452
455
|
var withAIChat = ({
|
|
453
456
|
api,
|
|
454
457
|
editor,
|
|
@@ -490,7 +493,7 @@ var withAIChat = ({
|
|
|
490
493
|
},
|
|
491
494
|
normalizeNode(entry) {
|
|
492
495
|
const [node, path] = entry;
|
|
493
|
-
if (node[
|
|
496
|
+
if (node[KEYS10.ai] && !getOptions().open) {
|
|
494
497
|
tf.ai.removeMarks({ at: path });
|
|
495
498
|
return;
|
|
496
499
|
}
|
|
@@ -506,7 +509,7 @@ var withAIChat = ({
|
|
|
506
509
|
|
|
507
510
|
// src/react/ai-chat/AIChatPlugin.ts
|
|
508
511
|
var AIChatPlugin = createTPlatePlugin({
|
|
509
|
-
key:
|
|
512
|
+
key: KEYS11.aiChat,
|
|
510
513
|
dependencies: ["ai"],
|
|
511
514
|
node: {
|
|
512
515
|
isElement: true
|
|
@@ -514,6 +517,7 @@ var AIChatPlugin = createTPlatePlugin({
|
|
|
514
517
|
options: {
|
|
515
518
|
_blockChunks: "",
|
|
516
519
|
_blockPath: null,
|
|
520
|
+
_mdxName: null,
|
|
517
521
|
aiEditor: null,
|
|
518
522
|
chat: { messages: [] },
|
|
519
523
|
experimental_lastTextId: null,
|
|
@@ -547,12 +551,12 @@ var AIChatPlugin = createTPlatePlugin({
|
|
|
547
551
|
at: path,
|
|
548
552
|
mode: "lowest",
|
|
549
553
|
reverse: true,
|
|
550
|
-
match: (t) => !!t.ai,
|
|
554
|
+
match: (t) => !!t[getPluginType3(editor, KEYS11.ai)],
|
|
551
555
|
...rest
|
|
552
556
|
});
|
|
553
557
|
}
|
|
554
558
|
return editor.api.node({
|
|
555
|
-
match: (n) => n.ai,
|
|
559
|
+
match: (n) => n[getPluginType3(editor, KEYS11.ai)],
|
|
556
560
|
...rest
|
|
557
561
|
});
|
|
558
562
|
},
|
|
@@ -623,7 +627,7 @@ var useAIChatEditor = (editor, content, { parser } = {}) => {
|
|
|
623
627
|
|
|
624
628
|
// src/react/ai-chat/hooks/useChatChunk.ts
|
|
625
629
|
import { useEffect as useEffect2, useRef } from "react";
|
|
626
|
-
import { KEYS as
|
|
630
|
+
import { KEYS as KEYS12 } from "platejs";
|
|
627
631
|
import { usePluginOption as usePluginOption2 } from "platejs/react";
|
|
628
632
|
|
|
629
633
|
// src/react/ai-chat/utils/getLastAssistantMessage.ts
|
|
@@ -643,7 +647,7 @@ var useChatChunk = ({
|
|
|
643
647
|
onFinish
|
|
644
648
|
}) => {
|
|
645
649
|
const { isLoading } = usePluginOption2(
|
|
646
|
-
{ key:
|
|
650
|
+
{ key: KEYS12.aiChat },
|
|
647
651
|
"chat"
|
|
648
652
|
);
|
|
649
653
|
const content = useLastAssistantMessage()?.content;
|
|
@@ -725,20 +729,20 @@ import { serializeMd as serializeMd2 } from "@platejs/markdown";
|
|
|
725
729
|
import debounce from "lodash/debounce.js";
|
|
726
730
|
import {
|
|
727
731
|
bindFirst as bindFirst3,
|
|
728
|
-
KEYS as
|
|
732
|
+
KEYS as KEYS17,
|
|
729
733
|
NodeApi as NodeApi2
|
|
730
734
|
} from "platejs";
|
|
731
735
|
import { createTPlatePlugin as createTPlatePlugin2 } from "platejs/react";
|
|
732
736
|
|
|
733
737
|
// src/react/copilot/renderCopilotBelowNodes.tsx
|
|
734
738
|
import React from "react";
|
|
735
|
-
import { KEYS as
|
|
739
|
+
import { KEYS as KEYS13 } from "platejs";
|
|
736
740
|
import { getEditorPlugin as getEditorPlugin4 } from "platejs/react";
|
|
737
741
|
var renderCopilotBelowNodes = ({
|
|
738
742
|
editor
|
|
739
743
|
}) => {
|
|
740
744
|
const copilot = getEditorPlugin4(editor, {
|
|
741
|
-
key:
|
|
745
|
+
key: KEYS13.copilot
|
|
742
746
|
});
|
|
743
747
|
const { renderGhostText: GhostText } = copilot.getOptions();
|
|
744
748
|
if (!GhostText) return;
|
|
@@ -749,10 +753,10 @@ var renderCopilotBelowNodes = ({
|
|
|
749
753
|
|
|
750
754
|
// src/react/copilot/transforms/acceptCopilot.ts
|
|
751
755
|
import { deserializeInlineMd } from "@platejs/markdown";
|
|
752
|
-
import { KEYS as
|
|
756
|
+
import { KEYS as KEYS14 } from "platejs";
|
|
753
757
|
var acceptCopilot = (editor) => {
|
|
754
758
|
const { suggestionText } = editor.getOptions({
|
|
755
|
-
key:
|
|
759
|
+
key: KEYS14.copilot
|
|
756
760
|
});
|
|
757
761
|
if (!suggestionText?.length) return false;
|
|
758
762
|
editor.tf.insertFragment(deserializeInlineMd(editor, suggestionText));
|
|
@@ -760,7 +764,7 @@ var acceptCopilot = (editor) => {
|
|
|
760
764
|
|
|
761
765
|
// src/react/copilot/transforms/acceptCopilotNextWord.ts
|
|
762
766
|
import { deserializeInlineMd as deserializeInlineMd2 } from "@platejs/markdown";
|
|
763
|
-
import { KEYS as
|
|
767
|
+
import { KEYS as KEYS16 } from "platejs";
|
|
764
768
|
import { getEditorPlugin as getEditorPlugin6 } from "platejs/react";
|
|
765
769
|
|
|
766
770
|
// src/react/copilot/utils/callCompletionApi.ts
|
|
@@ -878,17 +882,17 @@ var getNextWord = ({ text }) => {
|
|
|
878
882
|
};
|
|
879
883
|
|
|
880
884
|
// src/react/copilot/utils/triggerCopilotSuggestion.ts
|
|
881
|
-
import { KEYS as
|
|
885
|
+
import { KEYS as KEYS15 } from "platejs";
|
|
882
886
|
import { getEditorPlugin as getEditorPlugin5 } from "platejs/react";
|
|
883
887
|
var triggerCopilotSuggestion = async (editor) => {
|
|
884
888
|
const { api, getOptions, setOption } = getEditorPlugin5(
|
|
885
889
|
editor,
|
|
886
890
|
{
|
|
887
|
-
key:
|
|
891
|
+
key: KEYS15.copilot
|
|
888
892
|
}
|
|
889
893
|
);
|
|
890
894
|
const { completeOptions, getPrompt, isLoading, triggerQuery } = getOptions();
|
|
891
|
-
if (isLoading || editor.getOptions({ key:
|
|
895
|
+
if (isLoading || editor.getOptions({ key: KEYS15.aiChat }).chat?.isLoading) {
|
|
892
896
|
return false;
|
|
893
897
|
}
|
|
894
898
|
if (!triggerQuery({ editor })) return false;
|
|
@@ -922,7 +926,7 @@ var withoutAbort = (editor, fn) => {
|
|
|
922
926
|
// src/react/copilot/transforms/acceptCopilotNextWord.ts
|
|
923
927
|
var acceptCopilotNextWord = (editor) => {
|
|
924
928
|
const { api, getOptions } = getEditorPlugin6(editor, {
|
|
925
|
-
key:
|
|
929
|
+
key: KEYS16.copilot
|
|
926
930
|
});
|
|
927
931
|
const { getNextWord: getNextWord2, suggestionText } = getOptions();
|
|
928
932
|
if (!suggestionText?.length) {
|
|
@@ -1038,7 +1042,7 @@ var withCopilot = ({
|
|
|
1038
1042
|
|
|
1039
1043
|
// src/react/copilot/CopilotPlugin.tsx
|
|
1040
1044
|
var CopilotPlugin = createTPlatePlugin2({
|
|
1041
|
-
key:
|
|
1045
|
+
key: KEYS17.copilot,
|
|
1042
1046
|
handlers: {
|
|
1043
1047
|
onBlur: ({ api }) => {
|
|
1044
1048
|
api.copilot.reject();
|
|
@@ -1060,7 +1064,7 @@ var CopilotPlugin = createTPlatePlugin2({
|
|
|
1060
1064
|
suggestionNodeId: null,
|
|
1061
1065
|
suggestionText: null,
|
|
1062
1066
|
autoTriggerQuery: ({ editor }) => {
|
|
1063
|
-
if (editor.getOptions({ key:
|
|
1067
|
+
if (editor.getOptions({ key: KEYS17.copilot }).suggestionText) {
|
|
1064
1068
|
return false;
|
|
1065
1069
|
}
|
|
1066
1070
|
const isEmpty = editor.api.isEmpty(editor.selection, { block: true });
|