@flozy/editor 4.4.1 → 4.4.3

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
- const parsed = new DOMParser().parseFromString(text, "text/html");
44
- const fragment = deserialize(parsed.body);
45
- Transforms.insertFragment(editor, fragment, options);
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
- if (type === "close") {
204
- onClickOutside();
205
- return;
206
- }
207
- if (type === "done") {
208
- // Get the current selection point
209
- const {
210
- anchor
211
- } = editor.selection;
212
- const {
213
- path
214
- } = anchor;
215
- const {
216
- text: selectText
217
- } = Node.get(editor, path);
218
- if (selectText?.length) {
219
- insertAtNextLine(editor, generatedText);
220
- } else {
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
- onClickOutside();
224
- return;
225
- }
226
- if (type === "replace_selection") {
227
- // replace generated text
228
- insertText(editor, generatedText);
229
- onClickOutside();
230
- return;
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
- setGeneratedText(text);
244
+ setSelectedOption(option);
269
245
  }
270
- return;
271
- }
272
- insertText(editor, text);
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
- // scrollToAIInput();
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
  };
@@ -54,7 +54,7 @@ const useResize = ({
54
54
  const calc = {
55
55
  width: Math.max(calcWidth, 140),
56
56
  height: Math.max(calcHeight, 50),
57
- widthInPercent: cWP > 100 ? 100 : cWP
57
+ widthInPercent: cWP > 100 ? 100 : Math.max(cWP, 15)
58
58
  };
59
59
  latest = calc;
60
60
  return calc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "4.4.1",
3
+ "version": "4.4.3",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"