@platejs/ai 49.1.12 → 49.2.1
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 +2 -2
package/dist/react/index.js
CHANGED
|
@@ -63,7 +63,7 @@ module.exports = __toCommonJS(react_exports);
|
|
|
63
63
|
var import_react = require("platejs/react");
|
|
64
64
|
|
|
65
65
|
// src/lib/BaseAIPlugin.ts
|
|
66
|
-
var
|
|
66
|
+
var import_platejs3 = require("platejs");
|
|
67
67
|
|
|
68
68
|
// src/lib/transforms/insertAINodes.ts
|
|
69
69
|
var insertAINodes = (editor, nodes, {
|
|
@@ -84,19 +84,21 @@ var insertAINodes = (editor, nodes, {
|
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
// src/lib/transforms/removeAIMarks.ts
|
|
87
|
+
var import_platejs = require("platejs");
|
|
87
88
|
var removeAIMarks = (editor, { at = [] } = {}) => {
|
|
88
|
-
editor.
|
|
89
|
+
const nodeType = (0, import_platejs.getPluginType)(editor, import_platejs.KEYS.ai);
|
|
90
|
+
editor.tf.unsetNodes(nodeType, {
|
|
89
91
|
at,
|
|
90
|
-
match: (n) => n
|
|
92
|
+
match: (n) => n[nodeType]
|
|
91
93
|
});
|
|
92
94
|
};
|
|
93
95
|
|
|
94
96
|
// src/lib/transforms/removeAINodes.ts
|
|
95
|
-
var
|
|
97
|
+
var import_platejs2 = require("platejs");
|
|
96
98
|
var removeAINodes = (editor, { at = [] } = {}) => {
|
|
97
99
|
editor.tf.removeNodes({
|
|
98
100
|
at,
|
|
99
|
-
match: (n) =>
|
|
101
|
+
match: (n) => import_platejs2.TextApi.isText(n) && !!n.ai
|
|
100
102
|
});
|
|
101
103
|
};
|
|
102
104
|
|
|
@@ -127,14 +129,14 @@ var withAIBatch = (editor, fn, {
|
|
|
127
129
|
};
|
|
128
130
|
|
|
129
131
|
// src/lib/BaseAIPlugin.ts
|
|
130
|
-
var BaseAIPlugin = (0,
|
|
131
|
-
key:
|
|
132
|
+
var BaseAIPlugin = (0, import_platejs3.createTSlatePlugin)({
|
|
133
|
+
key: import_platejs3.KEYS.ai,
|
|
132
134
|
node: { isDecoration: false, isLeaf: true }
|
|
133
135
|
}).extendTransforms(({ editor }) => ({
|
|
134
|
-
insertNodes: (0,
|
|
135
|
-
removeMarks: (0,
|
|
136
|
-
removeNodes: (0,
|
|
137
|
-
undo: (0,
|
|
136
|
+
insertNodes: (0, import_platejs3.bindFirst)(insertAINodes, editor),
|
|
137
|
+
removeMarks: (0, import_platejs3.bindFirst)(removeAIMarks, editor),
|
|
138
|
+
removeNodes: (0, import_platejs3.bindFirst)(removeAINodes, editor),
|
|
139
|
+
undo: (0, import_platejs3.bindFirst)(undoAI, editor)
|
|
138
140
|
}));
|
|
139
141
|
|
|
140
142
|
// src/react/ai/AIPlugin.ts
|
|
@@ -142,15 +144,15 @@ var AIPlugin = (0, import_react.toPlatePlugin)(BaseAIPlugin);
|
|
|
142
144
|
|
|
143
145
|
// src/react/ai-chat/AIChatPlugin.ts
|
|
144
146
|
var import_react9 = require("@platejs/selection/react");
|
|
145
|
-
var
|
|
147
|
+
var import_platejs12 = require("platejs");
|
|
146
148
|
var import_react10 = require("platejs/react");
|
|
147
149
|
|
|
148
150
|
// src/react/ai-chat/transforms/acceptAIChat.ts
|
|
149
|
-
var
|
|
151
|
+
var import_platejs4 = require("platejs");
|
|
150
152
|
var import_react2 = require("platejs/react");
|
|
151
153
|
var acceptAIChat = (editor) => {
|
|
152
154
|
const { tf } = (0, import_react2.getEditorPlugin)(editor, AIPlugin);
|
|
153
|
-
const api = editor.getApi({ key:
|
|
155
|
+
const api = editor.getApi({ key: import_platejs4.KEYS.ai });
|
|
154
156
|
const lastAINodePath = api.aiChat.node({ at: [], reverse: true })[1];
|
|
155
157
|
withAIBatch(editor, () => {
|
|
156
158
|
tf.ai.removeMarks();
|
|
@@ -168,12 +170,12 @@ var acceptAIChat = (editor) => {
|
|
|
168
170
|
// src/react/ai-chat/transforms/insertBelowAIChat.ts
|
|
169
171
|
var import_react4 = require("@platejs/selection/react");
|
|
170
172
|
var import_cloneDeep2 = __toESM(require("lodash/cloneDeep.js"));
|
|
171
|
-
var
|
|
173
|
+
var import_platejs6 = require("platejs");
|
|
172
174
|
|
|
173
175
|
// src/react/ai-chat/transforms/replaceSelectionAIChat.ts
|
|
174
176
|
var import_react3 = require("@platejs/selection/react");
|
|
175
177
|
var import_cloneDeep = __toESM(require("lodash/cloneDeep.js"));
|
|
176
|
-
var
|
|
178
|
+
var import_platejs5 = require("platejs");
|
|
177
179
|
var createFormattedBlocks = ({
|
|
178
180
|
blocks,
|
|
179
181
|
format,
|
|
@@ -181,12 +183,12 @@ var createFormattedBlocks = ({
|
|
|
181
183
|
}) => {
|
|
182
184
|
if (format === "none") return (0, import_cloneDeep.default)(blocks);
|
|
183
185
|
const [sourceNode] = sourceBlock;
|
|
184
|
-
const firstTextEntry =
|
|
186
|
+
const firstTextEntry = import_platejs5.NodeApi.firstText(sourceNode);
|
|
185
187
|
if (!firstTextEntry) return null;
|
|
186
|
-
const blockProps =
|
|
187
|
-
const textProps =
|
|
188
|
+
const blockProps = import_platejs5.NodeApi.extractProps(sourceNode);
|
|
189
|
+
const textProps = import_platejs5.NodeApi.extractProps(firstTextEntry[0]);
|
|
188
190
|
const applyTextFormatting = (node) => {
|
|
189
|
-
if (
|
|
191
|
+
if (import_platejs5.TextApi.isText(node)) {
|
|
190
192
|
return { ...textProps, ...node };
|
|
191
193
|
}
|
|
192
194
|
if (node.children) {
|
|
@@ -213,7 +215,7 @@ var replaceSelectionAIChat = (editor, sourceEditor, { format = "single" } = {})
|
|
|
213
215
|
import_react3.BlockSelectionPlugin,
|
|
214
216
|
"isSelectingSome"
|
|
215
217
|
);
|
|
216
|
-
editor.getApi({ key:
|
|
218
|
+
editor.getApi({ key: import_platejs5.KEYS.ai }).aiChat.hide();
|
|
217
219
|
if (!isBlockSelecting) {
|
|
218
220
|
const firstBlock = editor.api.node({
|
|
219
221
|
block: true,
|
|
@@ -277,7 +279,7 @@ var insertBelowAIChat = (editor, sourceEditor, { format = "single" } = {}) => {
|
|
|
277
279
|
import_react4.BlockSelectionPlugin,
|
|
278
280
|
"isSelectingSome"
|
|
279
281
|
);
|
|
280
|
-
editor.getApi({ key:
|
|
282
|
+
editor.getApi({ key: import_platejs6.KEYS.ai }).aiChat.hide();
|
|
281
283
|
const insertBlocksAndSelect = editor.getTransforms(import_react4.BlockSelectionPlugin).blockSelection.insertBlocksAndSelect;
|
|
282
284
|
if (isBlockSelecting) {
|
|
283
285
|
const selectedBlocks = editor.getApi(import_react4.BlockSelectionPlugin).blockSelection.getNodes();
|
|
@@ -285,7 +287,7 @@ var insertBelowAIChat = (editor, sourceEditor, { format = "single" } = {}) => {
|
|
|
285
287
|
if (!selectedIds || selectedIds.size === 0) return;
|
|
286
288
|
const lastBlock = selectedBlocks.at(-1);
|
|
287
289
|
if (!lastBlock) return;
|
|
288
|
-
const nextPath =
|
|
290
|
+
const nextPath = import_platejs6.PathApi.next(lastBlock[1]);
|
|
289
291
|
if (format === "none") {
|
|
290
292
|
insertBlocksAndSelect((0, import_cloneDeep2.default)(sourceEditor.children), {
|
|
291
293
|
at: nextPath
|
|
@@ -302,7 +304,7 @@ var insertBelowAIChat = (editor, sourceEditor, { format = "single" } = {}) => {
|
|
|
302
304
|
at: nextPath
|
|
303
305
|
});
|
|
304
306
|
} else {
|
|
305
|
-
const [, end] =
|
|
307
|
+
const [, end] = import_platejs6.RangeApi.edges(editor.selection);
|
|
306
308
|
const endPath = [end.path[0]];
|
|
307
309
|
const currentBlock = editor.api.node({
|
|
308
310
|
at: endPath,
|
|
@@ -312,7 +314,7 @@ var insertBelowAIChat = (editor, sourceEditor, { format = "single" } = {}) => {
|
|
|
312
314
|
if (!currentBlock) return;
|
|
313
315
|
if (format === "none") {
|
|
314
316
|
insertBlocksAndSelect((0, import_cloneDeep2.default)(sourceEditor.children), {
|
|
315
|
-
at:
|
|
317
|
+
at: import_platejs6.PathApi.next(endPath)
|
|
316
318
|
});
|
|
317
319
|
return;
|
|
318
320
|
}
|
|
@@ -323,18 +325,18 @@ var insertBelowAIChat = (editor, sourceEditor, { format = "single" } = {}) => {
|
|
|
323
325
|
});
|
|
324
326
|
if (!formattedBlocks) return;
|
|
325
327
|
insertBlocksAndSelect(formattedBlocks, {
|
|
326
|
-
at:
|
|
328
|
+
at: import_platejs6.PathApi.next(endPath)
|
|
327
329
|
});
|
|
328
330
|
}
|
|
329
331
|
};
|
|
330
332
|
|
|
331
333
|
// src/react/ai-chat/transforms/removeAnchorAIChat.ts
|
|
332
|
-
var
|
|
334
|
+
var import_platejs7 = require("platejs");
|
|
333
335
|
var removeAnchorAIChat = (editor, options) => {
|
|
334
336
|
editor.tf.withoutSaving(() => {
|
|
335
337
|
editor.tf.removeNodes({
|
|
336
338
|
at: [],
|
|
337
|
-
match: (n) =>
|
|
339
|
+
match: (n) => import_platejs7.ElementApi.isElement(n) && n.type === (0, import_platejs7.getPluginType)(editor, import_platejs7.KEYS.aiChat),
|
|
338
340
|
...options
|
|
339
341
|
});
|
|
340
342
|
});
|
|
@@ -347,7 +349,7 @@ var import_react6 = require("@platejs/selection/react");
|
|
|
347
349
|
// src/react/ai-chat/utils/getMarkdown.ts
|
|
348
350
|
var import_markdown = require("@platejs/markdown");
|
|
349
351
|
var import_react5 = require("@platejs/selection/react");
|
|
350
|
-
var
|
|
352
|
+
var import_platejs8 = require("platejs");
|
|
351
353
|
var getMarkdown = (editor, type) => {
|
|
352
354
|
if (type === "editor") {
|
|
353
355
|
return (0, import_markdown.serializeMd)(editor);
|
|
@@ -366,7 +368,7 @@ var getMarkdown = (editor, type) => {
|
|
|
366
368
|
const modifiedFragment = [
|
|
367
369
|
{
|
|
368
370
|
children: fragment[0].children,
|
|
369
|
-
type:
|
|
371
|
+
type: import_platejs8.KEYS.p
|
|
370
372
|
}
|
|
371
373
|
];
|
|
372
374
|
return (0, import_markdown.serializeMd)(editor, { value: modifiedFragment });
|
|
@@ -428,11 +430,11 @@ var getEditorPrompt = (editor, {
|
|
|
428
430
|
};
|
|
429
431
|
|
|
430
432
|
// src/react/ai-chat/utils/resetAIChat.ts
|
|
431
|
-
var
|
|
433
|
+
var import_platejs9 = require("platejs");
|
|
432
434
|
var import_react7 = require("platejs/react");
|
|
433
435
|
var resetAIChat = (editor) => {
|
|
434
436
|
const { api, getOptions } = (0, import_react7.getEditorPlugin)(editor, {
|
|
435
|
-
key:
|
|
437
|
+
key: import_platejs9.KEYS.aiChat
|
|
436
438
|
});
|
|
437
439
|
api.aiChat.stop();
|
|
438
440
|
const chat = getOptions().chat;
|
|
@@ -444,7 +446,7 @@ var resetAIChat = (editor) => {
|
|
|
444
446
|
|
|
445
447
|
// src/react/ai-chat/utils/submitAIChat.ts
|
|
446
448
|
var import_selection2 = require("@platejs/selection");
|
|
447
|
-
var
|
|
449
|
+
var import_platejs10 = require("platejs");
|
|
448
450
|
var import_react8 = require("platejs/react");
|
|
449
451
|
var submitAIChat = (editor, {
|
|
450
452
|
mode,
|
|
@@ -455,7 +457,7 @@ var submitAIChat = (editor, {
|
|
|
455
457
|
const { getOptions, setOption } = (0, import_react8.getEditorPlugin)(
|
|
456
458
|
editor,
|
|
457
459
|
{
|
|
458
|
-
key:
|
|
460
|
+
key: import_platejs10.KEYS.aiChat
|
|
459
461
|
}
|
|
460
462
|
);
|
|
461
463
|
const { chat, promptTemplate, systemTemplate } = getOptions();
|
|
@@ -494,7 +496,7 @@ var submitAIChat = (editor, {
|
|
|
494
496
|
};
|
|
495
497
|
|
|
496
498
|
// src/react/ai-chat/withAIChat.ts
|
|
497
|
-
var
|
|
499
|
+
var import_platejs11 = require("platejs");
|
|
498
500
|
var withAIChat = ({
|
|
499
501
|
api,
|
|
500
502
|
editor,
|
|
@@ -536,11 +538,11 @@ var withAIChat = ({
|
|
|
536
538
|
},
|
|
537
539
|
normalizeNode(entry) {
|
|
538
540
|
const [node, path] = entry;
|
|
539
|
-
if (node[
|
|
541
|
+
if (node[import_platejs11.KEYS.ai] && !getOptions().open) {
|
|
540
542
|
tf.ai.removeMarks({ at: path });
|
|
541
543
|
return;
|
|
542
544
|
}
|
|
543
|
-
if (
|
|
545
|
+
if (import_platejs11.ElementApi.isElement(node) && node.type === type && !getOptions().open) {
|
|
544
546
|
editor.getTransforms(AIChatPlugin).aiChat.removeAnchor({ at: path });
|
|
545
547
|
return;
|
|
546
548
|
}
|
|
@@ -552,7 +554,7 @@ var withAIChat = ({
|
|
|
552
554
|
|
|
553
555
|
// src/react/ai-chat/AIChatPlugin.ts
|
|
554
556
|
var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
555
|
-
key:
|
|
557
|
+
key: import_platejs12.KEYS.aiChat,
|
|
556
558
|
dependencies: ["ai"],
|
|
557
559
|
node: {
|
|
558
560
|
isElement: true
|
|
@@ -560,6 +562,7 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
|
560
562
|
options: {
|
|
561
563
|
_blockChunks: "",
|
|
562
564
|
_blockPath: null,
|
|
565
|
+
_mdxName: null,
|
|
563
566
|
aiEditor: null,
|
|
564
567
|
chat: { messages: [] },
|
|
565
568
|
experimental_lastTextId: null,
|
|
@@ -574,14 +577,14 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
|
574
577
|
}
|
|
575
578
|
}).overrideEditor(withAIChat).extendApi(({ editor, getOption, getOptions, setOption, type }) => {
|
|
576
579
|
return {
|
|
577
|
-
reset: (0,
|
|
578
|
-
submit: (0,
|
|
580
|
+
reset: (0, import_platejs12.bindFirst)(resetAIChat, editor),
|
|
581
|
+
submit: (0, import_platejs12.bindFirst)(submitAIChat, editor),
|
|
579
582
|
node: (options = {}) => {
|
|
580
583
|
const { anchor = false, streaming = false, ...rest } = options;
|
|
581
584
|
if (anchor) {
|
|
582
585
|
return editor.api.node({
|
|
583
586
|
at: [],
|
|
584
|
-
match: (n) =>
|
|
587
|
+
match: (n) => import_platejs12.ElementApi.isElement(n) && n.type === type,
|
|
585
588
|
...rest
|
|
586
589
|
});
|
|
587
590
|
}
|
|
@@ -593,12 +596,12 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
|
593
596
|
at: path,
|
|
594
597
|
mode: "lowest",
|
|
595
598
|
reverse: true,
|
|
596
|
-
match: (t) => !!t.ai,
|
|
599
|
+
match: (t) => !!t[(0, import_platejs12.getPluginType)(editor, import_platejs12.KEYS.ai)],
|
|
597
600
|
...rest
|
|
598
601
|
});
|
|
599
602
|
}
|
|
600
603
|
return editor.api.node({
|
|
601
|
-
match: (n) => n.ai,
|
|
604
|
+
match: (n) => n[(0, import_platejs12.getPluginType)(editor, import_platejs12.KEYS.ai)],
|
|
602
605
|
...rest
|
|
603
606
|
});
|
|
604
607
|
},
|
|
@@ -640,10 +643,10 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
|
640
643
|
setOption("open", true);
|
|
641
644
|
}
|
|
642
645
|
})).extendTransforms(({ editor }) => ({
|
|
643
|
-
accept: (0,
|
|
644
|
-
insertBelow: (0,
|
|
645
|
-
removeAnchor: (0,
|
|
646
|
-
replaceSelection: (0,
|
|
646
|
+
accept: (0, import_platejs12.bindFirst)(acceptAIChat, editor),
|
|
647
|
+
insertBelow: (0, import_platejs12.bindFirst)(insertBelowAIChat, editor),
|
|
648
|
+
removeAnchor: (0, import_platejs12.bindFirst)(removeAnchorAIChat, editor),
|
|
649
|
+
replaceSelection: (0, import_platejs12.bindFirst)(replaceSelectionAIChat, editor)
|
|
647
650
|
}));
|
|
648
651
|
|
|
649
652
|
// src/react/ai-chat/hooks/useAIChatEditor.ts
|
|
@@ -669,7 +672,7 @@ var useAIChatEditor = (editor, content, { parser } = {}) => {
|
|
|
669
672
|
|
|
670
673
|
// src/react/ai-chat/hooks/useChatChunk.ts
|
|
671
674
|
var import_react14 = require("react");
|
|
672
|
-
var
|
|
675
|
+
var import_platejs13 = require("platejs");
|
|
673
676
|
var import_react15 = require("platejs/react");
|
|
674
677
|
|
|
675
678
|
// src/react/ai-chat/utils/getLastAssistantMessage.ts
|
|
@@ -689,7 +692,7 @@ var useChatChunk = ({
|
|
|
689
692
|
onFinish
|
|
690
693
|
}) => {
|
|
691
694
|
const { isLoading } = (0, import_react15.usePluginOption)(
|
|
692
|
-
{ key:
|
|
695
|
+
{ key: import_platejs13.KEYS.aiChat },
|
|
693
696
|
"chat"
|
|
694
697
|
);
|
|
695
698
|
const content = useLastAssistantMessage()?.content;
|
|
@@ -769,18 +772,18 @@ var useEditorChat = ({
|
|
|
769
772
|
// src/react/copilot/CopilotPlugin.tsx
|
|
770
773
|
var import_markdown6 = require("@platejs/markdown");
|
|
771
774
|
var import_debounce = __toESM(require("lodash/debounce.js"));
|
|
772
|
-
var
|
|
775
|
+
var import_platejs19 = require("platejs");
|
|
773
776
|
var import_react23 = require("platejs/react");
|
|
774
777
|
|
|
775
778
|
// src/react/copilot/renderCopilotBelowNodes.tsx
|
|
776
779
|
var import_react19 = __toESM(require("react"));
|
|
777
|
-
var
|
|
780
|
+
var import_platejs14 = require("platejs");
|
|
778
781
|
var import_react20 = require("platejs/react");
|
|
779
782
|
var renderCopilotBelowNodes = ({
|
|
780
783
|
editor
|
|
781
784
|
}) => {
|
|
782
785
|
const copilot = (0, import_react20.getEditorPlugin)(editor, {
|
|
783
|
-
key:
|
|
786
|
+
key: import_platejs14.KEYS.copilot
|
|
784
787
|
});
|
|
785
788
|
const { renderGhostText: GhostText } = copilot.getOptions();
|
|
786
789
|
if (!GhostText) return;
|
|
@@ -791,10 +794,10 @@ var renderCopilotBelowNodes = ({
|
|
|
791
794
|
|
|
792
795
|
// src/react/copilot/transforms/acceptCopilot.ts
|
|
793
796
|
var import_markdown3 = require("@platejs/markdown");
|
|
794
|
-
var
|
|
797
|
+
var import_platejs15 = require("platejs");
|
|
795
798
|
var acceptCopilot = (editor) => {
|
|
796
799
|
const { suggestionText } = editor.getOptions({
|
|
797
|
-
key:
|
|
800
|
+
key: import_platejs15.KEYS.copilot
|
|
798
801
|
});
|
|
799
802
|
if (!suggestionText?.length) return false;
|
|
800
803
|
editor.tf.insertFragment((0, import_markdown3.deserializeInlineMd)(editor, suggestionText));
|
|
@@ -802,7 +805,7 @@ var acceptCopilot = (editor) => {
|
|
|
802
805
|
|
|
803
806
|
// src/react/copilot/transforms/acceptCopilotNextWord.ts
|
|
804
807
|
var import_markdown4 = require("@platejs/markdown");
|
|
805
|
-
var
|
|
808
|
+
var import_platejs17 = require("platejs");
|
|
806
809
|
var import_react22 = require("platejs/react");
|
|
807
810
|
|
|
808
811
|
// src/react/copilot/utils/callCompletionApi.ts
|
|
@@ -920,17 +923,17 @@ var getNextWord = ({ text }) => {
|
|
|
920
923
|
};
|
|
921
924
|
|
|
922
925
|
// src/react/copilot/utils/triggerCopilotSuggestion.ts
|
|
923
|
-
var
|
|
926
|
+
var import_platejs16 = require("platejs");
|
|
924
927
|
var import_react21 = require("platejs/react");
|
|
925
928
|
var triggerCopilotSuggestion = async (editor) => {
|
|
926
929
|
const { api, getOptions, setOption } = (0, import_react21.getEditorPlugin)(
|
|
927
930
|
editor,
|
|
928
931
|
{
|
|
929
|
-
key:
|
|
932
|
+
key: import_platejs16.KEYS.copilot
|
|
930
933
|
}
|
|
931
934
|
);
|
|
932
935
|
const { completeOptions, getPrompt, isLoading, triggerQuery } = getOptions();
|
|
933
|
-
if (isLoading || editor.getOptions({ key:
|
|
936
|
+
if (isLoading || editor.getOptions({ key: import_platejs16.KEYS.aiChat }).chat?.isLoading) {
|
|
934
937
|
return false;
|
|
935
938
|
}
|
|
936
939
|
if (!triggerQuery({ editor })) return false;
|
|
@@ -964,7 +967,7 @@ var withoutAbort = (editor, fn) => {
|
|
|
964
967
|
// src/react/copilot/transforms/acceptCopilotNextWord.ts
|
|
965
968
|
var acceptCopilotNextWord = (editor) => {
|
|
966
969
|
const { api, getOptions } = (0, import_react22.getEditorPlugin)(editor, {
|
|
967
|
-
key:
|
|
970
|
+
key: import_platejs17.KEYS.copilot
|
|
968
971
|
});
|
|
969
972
|
const { getNextWord: getNextWord2, suggestionText } = getOptions();
|
|
970
973
|
if (!suggestionText?.length) {
|
|
@@ -981,7 +984,7 @@ var acceptCopilotNextWord = (editor) => {
|
|
|
981
984
|
|
|
982
985
|
// src/react/copilot/withCopilot.ts
|
|
983
986
|
var import_markdown5 = require("@platejs/markdown");
|
|
984
|
-
var
|
|
987
|
+
var import_platejs18 = require("platejs");
|
|
985
988
|
var getPatchString = (editor, operations) => {
|
|
986
989
|
let string = "";
|
|
987
990
|
for (const operation of operations) {
|
|
@@ -1043,7 +1046,7 @@ var withCopilot = ({
|
|
|
1043
1046
|
},
|
|
1044
1047
|
setSelection(props) {
|
|
1045
1048
|
setSelection(props);
|
|
1046
|
-
if (editor.selection && (!prevSelection || !
|
|
1049
|
+
if (editor.selection && (!prevSelection || !import_platejs18.RangeApi.equals(prevSelection, editor.selection)) && getOptions().autoTriggerQuery({ editor }) && editor.api.isFocused()) {
|
|
1047
1050
|
void api.copilot.triggerSuggestion();
|
|
1048
1051
|
}
|
|
1049
1052
|
prevSelection = editor.selection;
|
|
@@ -1078,7 +1081,7 @@ var withCopilot = ({
|
|
|
1078
1081
|
|
|
1079
1082
|
// src/react/copilot/CopilotPlugin.tsx
|
|
1080
1083
|
var CopilotPlugin = (0, import_react23.createTPlatePlugin)({
|
|
1081
|
-
key:
|
|
1084
|
+
key: import_platejs19.KEYS.copilot,
|
|
1082
1085
|
handlers: {
|
|
1083
1086
|
onBlur: ({ api }) => {
|
|
1084
1087
|
api.copilot.reject();
|
|
@@ -1100,14 +1103,14 @@ var CopilotPlugin = (0, import_react23.createTPlatePlugin)({
|
|
|
1100
1103
|
suggestionNodeId: null,
|
|
1101
1104
|
suggestionText: null,
|
|
1102
1105
|
autoTriggerQuery: ({ editor }) => {
|
|
1103
|
-
if (editor.getOptions({ key:
|
|
1106
|
+
if (editor.getOptions({ key: import_platejs19.KEYS.copilot }).suggestionText) {
|
|
1104
1107
|
return false;
|
|
1105
1108
|
}
|
|
1106
1109
|
const isEmpty = editor.api.isEmpty(editor.selection, { block: true });
|
|
1107
1110
|
if (isEmpty) return false;
|
|
1108
1111
|
const blockAbove = editor.api.block();
|
|
1109
1112
|
if (!blockAbove) return false;
|
|
1110
|
-
const blockString =
|
|
1113
|
+
const blockString = import_platejs19.NodeApi.string(blockAbove[0]);
|
|
1111
1114
|
return blockString.at(-1) === " ";
|
|
1112
1115
|
},
|
|
1113
1116
|
getPrompt: ({ editor }) => {
|
|
@@ -1127,15 +1130,15 @@ var CopilotPlugin = (0, import_react23.createTPlatePlugin)({
|
|
|
1127
1130
|
}).overrideEditor(withCopilot).extendSelectors(({ getOptions }) => ({
|
|
1128
1131
|
isSuggested: (id) => getOptions().suggestionNodeId === id
|
|
1129
1132
|
})).extendTransforms(({ editor }) => ({
|
|
1130
|
-
accept: (0,
|
|
1131
|
-
acceptNextWord: (0,
|
|
1133
|
+
accept: (0, import_platejs19.bindFirst)(acceptCopilot, editor),
|
|
1134
|
+
acceptNextWord: (0, import_platejs19.bindFirst)(acceptCopilotNextWord, editor)
|
|
1132
1135
|
})).extendApi(
|
|
1133
1136
|
({ api, editor, getOptions, setOption, setOptions }) => {
|
|
1134
1137
|
const debounceDelay = getOptions().debounceDelay;
|
|
1135
|
-
let triggerSuggestion = (0,
|
|
1138
|
+
let triggerSuggestion = (0, import_platejs19.bindFirst)(triggerCopilotSuggestion, editor);
|
|
1136
1139
|
if (debounceDelay) {
|
|
1137
1140
|
triggerSuggestion = (0, import_debounce.default)(
|
|
1138
|
-
(0,
|
|
1141
|
+
(0, import_platejs19.bindFirst)(triggerCopilotSuggestion, editor),
|
|
1139
1142
|
debounceDelay
|
|
1140
1143
|
);
|
|
1141
1144
|
}
|