@flozy/editor 4.4.1 → 4.4.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -40,9 +40,11 @@ const scrollToAIInput = editor => {
|
|
40
40
|
}, 200);
|
41
41
|
};
|
42
42
|
const insertText = (editor, text, options) => {
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
if (text?.length) {
|
44
|
+
const parsed = new DOMParser().parseFromString(text, "text/html");
|
45
|
+
const fragment = deserialize(parsed.body);
|
46
|
+
Transforms.insertFragment(editor, fragment, options);
|
47
|
+
}
|
46
48
|
};
|
47
49
|
const insertAtNextLine = (editor, text) => {
|
48
50
|
const nextLine = getNextLine(editor);
|
@@ -200,80 +202,83 @@ function PopoverAIInput({
|
|
200
202
|
selectedEleRef.current = selectedElement;
|
201
203
|
}, [selectedElement]);
|
202
204
|
const onSend = async (type, option) => {
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
205
|
+
try {
|
206
|
+
if (type === "close") {
|
207
|
+
onClickOutside();
|
208
|
+
return;
|
209
|
+
}
|
210
|
+
if (type === "done") {
|
211
|
+
// Get the current selection point
|
212
|
+
const {
|
213
|
+
anchor
|
214
|
+
} = editor.selection;
|
215
|
+
const {
|
216
|
+
path
|
217
|
+
} = anchor;
|
218
|
+
const {
|
219
|
+
text: selectText
|
220
|
+
} = Node.get(editor, path);
|
221
|
+
if (selectText?.length) {
|
222
|
+
insertAtNextLine(editor, generatedText);
|
223
|
+
} else {
|
224
|
+
insertText(editor, generatedText);
|
225
|
+
}
|
226
|
+
onClickOutside();
|
227
|
+
return;
|
228
|
+
}
|
229
|
+
if (type === "replace_selection") {
|
230
|
+
// replace generated text
|
221
231
|
insertText(editor, generatedText);
|
232
|
+
onClickOutside();
|
233
|
+
return;
|
222
234
|
}
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
}
|
232
|
-
if (type === "speech_to_text") {
|
233
|
-
setGeneratedText(option.text);
|
234
|
-
return;
|
235
|
-
}
|
236
|
-
if (type === "try_again") {
|
237
|
-
// resetting the previous option and try again
|
238
|
-
option = selectedOption;
|
239
|
-
type = selectedOption.value;
|
240
|
-
} else {
|
241
|
-
setSelectedOption(option);
|
242
|
-
}
|
243
|
-
setLoading(true);
|
244
|
-
const payload = {
|
245
|
-
mode: option.mode || 0,
|
246
|
-
query: option?.inputValue || inputValue
|
247
|
-
};
|
248
|
-
if (option.mode === MODES.translate || option.mode === MODES.rephraseTone) {
|
249
|
-
payload.textOptionInput = type;
|
250
|
-
}
|
251
|
-
if (option.mode) {
|
252
|
-
payload.textData = generatedText || window.getSelection().toString();
|
253
|
-
}
|
254
|
-
const result = await services("infinityAI", payload);
|
255
|
-
setLoading(false);
|
256
|
-
setInputValue("");
|
257
|
-
let {
|
258
|
-
data: text
|
259
|
-
} = result || {};
|
260
|
-
if (!text) {
|
261
|
-
onClickOutside();
|
262
|
-
return;
|
263
|
-
}
|
264
|
-
if (!option.replace) {
|
265
|
-
if (type === "continue_writing") {
|
266
|
-
setGeneratedText(generatedText + text);
|
235
|
+
if (type === "speech_to_text") {
|
236
|
+
setGeneratedText(option.text);
|
237
|
+
return;
|
238
|
+
}
|
239
|
+
if (type === "try_again") {
|
240
|
+
// resetting the previous option and try again
|
241
|
+
option = selectedOption;
|
242
|
+
type = selectedOption.value;
|
267
243
|
} else {
|
268
|
-
|
244
|
+
setSelectedOption(option);
|
269
245
|
}
|
270
|
-
|
271
|
-
|
272
|
-
|
246
|
+
setLoading(true);
|
247
|
+
const payload = {
|
248
|
+
mode: option.mode || 0,
|
249
|
+
query: option?.inputValue || inputValue
|
250
|
+
};
|
251
|
+
if (option.mode === MODES.translate || option.mode === MODES.rephraseTone) {
|
252
|
+
payload.textOptionInput = type;
|
253
|
+
}
|
254
|
+
if (option.mode) {
|
255
|
+
payload.textData = generatedText || window.getSelection().toString();
|
256
|
+
}
|
257
|
+
const result = await services("infinityAI", payload);
|
258
|
+
setLoading(false);
|
259
|
+
setInputValue("");
|
260
|
+
let {
|
261
|
+
data: text
|
262
|
+
} = result || {};
|
263
|
+
if (!text) {
|
264
|
+
onClickOutside();
|
265
|
+
return;
|
266
|
+
}
|
267
|
+
if (!option.replace) {
|
268
|
+
if (type === "continue_writing") {
|
269
|
+
setGeneratedText(generatedText + text);
|
270
|
+
} else {
|
271
|
+
setGeneratedText(text);
|
272
|
+
}
|
273
|
+
return;
|
274
|
+
}
|
275
|
+
insertText(editor, text);
|
273
276
|
|
274
|
-
|
277
|
+
// scrollToAIInput();
|
278
|
+
} catch (err) {
|
279
|
+
console.error("Error on sending/inserting text", err);
|
280
|
+
}
|
275
281
|
};
|
276
|
-
|
277
282
|
const onInputChange = e => {
|
278
283
|
setInputValue(e.target.value);
|
279
284
|
};
|