@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.
- package/dist/react/index.d.mts +11 -3
- package/dist/react/index.d.ts +11 -3
- package/dist/react/index.js +18 -5
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +18 -5
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as platejs_react from 'platejs/react';
|
|
2
2
|
import { PlateEditor, OverrideEditor, RenderNodeWrapperProps } from 'platejs/react';
|
|
3
3
|
import * as platejs from 'platejs';
|
|
4
|
-
import { ExtendConfig, SlateEditor, Range, NodeEntry, TElement, PluginConfig, Path, TIdElement, OmitFirst, EditorNodesOptions, TText, Descendant, RemoveNodesOptions } from 'platejs';
|
|
4
|
+
import { ExtendConfig, SlateEditor, Range, NodeEntry, TElement, PluginConfig, Path, TIdElement, TRange, OmitFirst, EditorNodesOptions, TText, Descendant, RemoveNodesOptions } from 'platejs';
|
|
5
5
|
import { B as BaseAIPluginConfig, b as AIMode, E as EditorPrompt, A as AIToolName } from '../getEditorPrompt-C7EEuMw8.mjs';
|
|
6
6
|
import { UIMessage, ChatRequestOptions } from 'ai';
|
|
7
7
|
import { Range as Range$1 } from 'slate';
|
|
@@ -63,7 +63,9 @@ declare const replaceSelectionAIChat: (editor: PlateEditor, sourceEditor: SlateE
|
|
|
63
63
|
format?: "all" | "none" | "single";
|
|
64
64
|
}) => void;
|
|
65
65
|
|
|
66
|
-
declare const resetAIChat: (editor: PlateEditor
|
|
66
|
+
declare const resetAIChat: (editor: PlateEditor, { undo }?: {
|
|
67
|
+
undo?: boolean;
|
|
68
|
+
}) => void;
|
|
67
69
|
|
|
68
70
|
declare const submitAIChat: (editor: PlateEditor, input: string, { mode, options, prompt, toolName, }?: {
|
|
69
71
|
mode?: AIMode;
|
|
@@ -82,6 +84,7 @@ type AIChatPluginConfig = PluginConfig<'aiChat', {
|
|
|
82
84
|
aiEditor: SlateEditor | null;
|
|
83
85
|
chat: UseChatHelpers<ChatMessage>;
|
|
84
86
|
chatNodes: TIdElement[];
|
|
87
|
+
chatSelection: TRange | null;
|
|
85
88
|
/** @deprecated Use api.aiChat.node({streaming:true}) instead */
|
|
86
89
|
experimental_lastTextId: string | null;
|
|
87
90
|
/**
|
|
@@ -102,6 +105,7 @@ type AIChatPluginConfig = PluginConfig<'aiChat', {
|
|
|
102
105
|
submit: OmitFirst<typeof submitAIChat>;
|
|
103
106
|
hide: (options?: {
|
|
104
107
|
focus?: boolean;
|
|
108
|
+
undo?: boolean;
|
|
105
109
|
}) => void;
|
|
106
110
|
node: (options?: EditorNodesOptions & {
|
|
107
111
|
anchor?: boolean;
|
|
@@ -129,6 +133,7 @@ declare const AIChatPlugin: platejs_react.PlatePlugin<PluginConfig<"aiChat", {
|
|
|
129
133
|
aiEditor: SlateEditor | null;
|
|
130
134
|
chat: UseChatHelpers<ChatMessage>;
|
|
131
135
|
chatNodes: TIdElement[];
|
|
136
|
+
chatSelection: TRange | null;
|
|
132
137
|
/** @deprecated Use api.aiChat.node({streaming:true}) instead */
|
|
133
138
|
experimental_lastTextId: string | null;
|
|
134
139
|
/**
|
|
@@ -149,6 +154,7 @@ declare const AIChatPlugin: platejs_react.PlatePlugin<PluginConfig<"aiChat", {
|
|
|
149
154
|
submit: OmitFirst<typeof submitAIChat>;
|
|
150
155
|
hide: (options?: {
|
|
151
156
|
focus?: boolean;
|
|
157
|
+
undo?: boolean;
|
|
152
158
|
}) => void;
|
|
153
159
|
node: (options?: EditorNodesOptions & {
|
|
154
160
|
anchor?: boolean;
|
|
@@ -163,6 +169,7 @@ declare const AIChatPlugin: platejs_react.PlatePlugin<PluginConfig<"aiChat", {
|
|
|
163
169
|
submit: OmitFirst<typeof submitAIChat>;
|
|
164
170
|
hide: (options?: {
|
|
165
171
|
focus?: boolean;
|
|
172
|
+
undo?: boolean;
|
|
166
173
|
}) => void;
|
|
167
174
|
node: (options?: EditorNodesOptions & {
|
|
168
175
|
anchor?: boolean;
|
|
@@ -172,8 +179,9 @@ declare const AIChatPlugin: platejs_react.PlatePlugin<PluginConfig<"aiChat", {
|
|
|
172
179
|
show: () => void;
|
|
173
180
|
stop: () => void;
|
|
174
181
|
}, "node" | "stop" | "reset" | "submit">> & Record<"aiChat", {
|
|
175
|
-
hide: ({ focus }?: {
|
|
182
|
+
hide: ({ focus, undo, }?: {
|
|
176
183
|
focus?: boolean;
|
|
184
|
+
undo?: boolean;
|
|
177
185
|
}) => void;
|
|
178
186
|
show: () => void;
|
|
179
187
|
}>, {
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as platejs_react from 'platejs/react';
|
|
2
2
|
import { PlateEditor, OverrideEditor, RenderNodeWrapperProps } from 'platejs/react';
|
|
3
3
|
import * as platejs from 'platejs';
|
|
4
|
-
import { ExtendConfig, SlateEditor, Range, NodeEntry, TElement, PluginConfig, Path, TIdElement, OmitFirst, EditorNodesOptions, TText, Descendant, RemoveNodesOptions } from 'platejs';
|
|
4
|
+
import { ExtendConfig, SlateEditor, Range, NodeEntry, TElement, PluginConfig, Path, TIdElement, TRange, OmitFirst, EditorNodesOptions, TText, Descendant, RemoveNodesOptions } from 'platejs';
|
|
5
5
|
import { B as BaseAIPluginConfig, b as AIMode, E as EditorPrompt, A as AIToolName } from '../getEditorPrompt-C7EEuMw8.js';
|
|
6
6
|
import { UIMessage, ChatRequestOptions } from 'ai';
|
|
7
7
|
import { Range as Range$1 } from 'slate';
|
|
@@ -63,7 +63,9 @@ declare const replaceSelectionAIChat: (editor: PlateEditor, sourceEditor: SlateE
|
|
|
63
63
|
format?: "all" | "none" | "single";
|
|
64
64
|
}) => void;
|
|
65
65
|
|
|
66
|
-
declare const resetAIChat: (editor: PlateEditor
|
|
66
|
+
declare const resetAIChat: (editor: PlateEditor, { undo }?: {
|
|
67
|
+
undo?: boolean;
|
|
68
|
+
}) => void;
|
|
67
69
|
|
|
68
70
|
declare const submitAIChat: (editor: PlateEditor, input: string, { mode, options, prompt, toolName, }?: {
|
|
69
71
|
mode?: AIMode;
|
|
@@ -82,6 +84,7 @@ type AIChatPluginConfig = PluginConfig<'aiChat', {
|
|
|
82
84
|
aiEditor: SlateEditor | null;
|
|
83
85
|
chat: UseChatHelpers<ChatMessage>;
|
|
84
86
|
chatNodes: TIdElement[];
|
|
87
|
+
chatSelection: TRange | null;
|
|
85
88
|
/** @deprecated Use api.aiChat.node({streaming:true}) instead */
|
|
86
89
|
experimental_lastTextId: string | null;
|
|
87
90
|
/**
|
|
@@ -102,6 +105,7 @@ type AIChatPluginConfig = PluginConfig<'aiChat', {
|
|
|
102
105
|
submit: OmitFirst<typeof submitAIChat>;
|
|
103
106
|
hide: (options?: {
|
|
104
107
|
focus?: boolean;
|
|
108
|
+
undo?: boolean;
|
|
105
109
|
}) => void;
|
|
106
110
|
node: (options?: EditorNodesOptions & {
|
|
107
111
|
anchor?: boolean;
|
|
@@ -129,6 +133,7 @@ declare const AIChatPlugin: platejs_react.PlatePlugin<PluginConfig<"aiChat", {
|
|
|
129
133
|
aiEditor: SlateEditor | null;
|
|
130
134
|
chat: UseChatHelpers<ChatMessage>;
|
|
131
135
|
chatNodes: TIdElement[];
|
|
136
|
+
chatSelection: TRange | null;
|
|
132
137
|
/** @deprecated Use api.aiChat.node({streaming:true}) instead */
|
|
133
138
|
experimental_lastTextId: string | null;
|
|
134
139
|
/**
|
|
@@ -149,6 +154,7 @@ declare const AIChatPlugin: platejs_react.PlatePlugin<PluginConfig<"aiChat", {
|
|
|
149
154
|
submit: OmitFirst<typeof submitAIChat>;
|
|
150
155
|
hide: (options?: {
|
|
151
156
|
focus?: boolean;
|
|
157
|
+
undo?: boolean;
|
|
152
158
|
}) => void;
|
|
153
159
|
node: (options?: EditorNodesOptions & {
|
|
154
160
|
anchor?: boolean;
|
|
@@ -163,6 +169,7 @@ declare const AIChatPlugin: platejs_react.PlatePlugin<PluginConfig<"aiChat", {
|
|
|
163
169
|
submit: OmitFirst<typeof submitAIChat>;
|
|
164
170
|
hide: (options?: {
|
|
165
171
|
focus?: boolean;
|
|
172
|
+
undo?: boolean;
|
|
166
173
|
}) => void;
|
|
167
174
|
node: (options?: EditorNodesOptions & {
|
|
168
175
|
anchor?: boolean;
|
|
@@ -172,8 +179,9 @@ declare const AIChatPlugin: platejs_react.PlatePlugin<PluginConfig<"aiChat", {
|
|
|
172
179
|
show: () => void;
|
|
173
180
|
stop: () => void;
|
|
174
181
|
}, "node" | "stop" | "reset" | "submit">> & Record<"aiChat", {
|
|
175
|
-
hide: ({ focus }?: {
|
|
182
|
+
hide: ({ focus, undo, }?: {
|
|
176
183
|
focus?: boolean;
|
|
184
|
+
undo?: boolean;
|
|
177
185
|
}) => void;
|
|
178
186
|
show: () => void;
|
|
179
187
|
}>, {
|
package/dist/react/index.js
CHANGED
|
@@ -3252,7 +3252,7 @@ var removeAnchorAIChat = (editor, options) => {
|
|
|
3252
3252
|
// src/react/ai-chat/utils/resetAIChat.ts
|
|
3253
3253
|
var import_platejs10 = require("platejs");
|
|
3254
3254
|
var import_react6 = require("platejs/react");
|
|
3255
|
-
var resetAIChat = (editor) => {
|
|
3255
|
+
var resetAIChat = (editor, { undo = true } = {}) => {
|
|
3256
3256
|
const { api, getOptions, setOptions } = (0, import_react6.getEditorPlugin)(
|
|
3257
3257
|
editor,
|
|
3258
3258
|
{
|
|
@@ -3270,7 +3270,9 @@ var resetAIChat = (editor) => {
|
|
|
3270
3270
|
mode: "insert",
|
|
3271
3271
|
toolName: "generate"
|
|
3272
3272
|
});
|
|
3273
|
-
|
|
3273
|
+
if (undo) {
|
|
3274
|
+
editor.getTransforms(AIPlugin).ai.undo();
|
|
3275
|
+
}
|
|
3274
3276
|
};
|
|
3275
3277
|
|
|
3276
3278
|
// src/react/ai-chat/utils/submitAIChat.ts
|
|
@@ -3313,6 +3315,7 @@ var submitAIChat = (editor, input, {
|
|
|
3313
3315
|
const selection = blocks.length > 0 ? blocksRange : editor.selection;
|
|
3314
3316
|
const chatNodes = blocks.length > 0 ? blocks.map((block) => block[0]) : editor.api.fragment();
|
|
3315
3317
|
setOption("chatNodes", chatNodes);
|
|
3318
|
+
setOption("chatSelection", blocks.length > 0 ? null : editor.selection);
|
|
3316
3319
|
const ctx = {
|
|
3317
3320
|
children: editor.children,
|
|
3318
3321
|
selection: selection ?? null,
|
|
@@ -3403,6 +3406,7 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
|
3403
3406
|
aiEditor: null,
|
|
3404
3407
|
chat: { messages: [] },
|
|
3405
3408
|
chatNodes: [],
|
|
3409
|
+
chatSelection: null,
|
|
3406
3410
|
experimental_lastTextId: null,
|
|
3407
3411
|
mode: "insert",
|
|
3408
3412
|
open: false,
|
|
@@ -3442,8 +3446,13 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
|
3442
3446
|
});
|
|
3443
3447
|
},
|
|
3444
3448
|
reload: () => {
|
|
3445
|
-
const { chat } = getOptions();
|
|
3449
|
+
const { chat, chatNodes, chatSelection } = getOptions();
|
|
3446
3450
|
editor.getTransforms(AIPlugin).ai.undo();
|
|
3451
|
+
if (chatSelection) {
|
|
3452
|
+
editor.tf.setSelection(chatSelection);
|
|
3453
|
+
} else {
|
|
3454
|
+
editor.getApi(import_react9.BlockSelectionPlugin).blockSelection.set(chatNodes.map((node) => node.id));
|
|
3455
|
+
}
|
|
3447
3456
|
const blocks = editor.getApi(import_react9.BlockSelectionPlugin).blockSelection.getNodes();
|
|
3448
3457
|
const selection = blocks.length > 0 ? editor.api.nodesRange(blocks) : editor.selection;
|
|
3449
3458
|
const ctx = {
|
|
@@ -3463,8 +3472,11 @@ var AIChatPlugin = (0, import_react10.createTPlatePlugin)({
|
|
|
3463
3472
|
}
|
|
3464
3473
|
};
|
|
3465
3474
|
}).extendApi(({ api, editor, getOptions, setOption, tf, type }) => ({
|
|
3466
|
-
hide: ({
|
|
3467
|
-
|
|
3475
|
+
hide: ({
|
|
3476
|
+
focus = true,
|
|
3477
|
+
undo = true
|
|
3478
|
+
} = {}) => {
|
|
3479
|
+
api.aiChat.reset({ undo });
|
|
3468
3480
|
setOption("open", false);
|
|
3469
3481
|
if (focus) {
|
|
3470
3482
|
if (editor.getOption(import_react9.BlockSelectionPlugin, "isSelectingSome")) {
|
|
@@ -4059,6 +4071,7 @@ var applyAISuggestions = (editor, content) => {
|
|
|
4059
4071
|
});
|
|
4060
4072
|
}
|
|
4061
4073
|
});
|
|
4074
|
+
editor.getApi(import_react19.BlockSelectionPlugin).blockSelection.set(diffNodes.map((node) => node.id));
|
|
4062
4075
|
setReplaceIds(diffNodes.map((node) => node.id));
|
|
4063
4076
|
} else {
|
|
4064
4077
|
const diffNodes = getDiffNodes(editor, content);
|