@flozy/editor 4.7.3 → 4.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -534,7 +534,7 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
534
534
  readOnly: isReadOnly,
535
535
  renderElement: renderElement,
536
536
  renderLeaf: renderLeaf,
537
- decorate: d => decorators(d, editor),
537
+ decorate: decorators,
538
538
  onKeyDown: onKeyDown,
539
539
  onSelect: () => handleCursorScroll(editorWrapper.current)
540
540
  }), !readOnly ? /*#__PURE__*/_jsx(MentionsPopup, {
@@ -584,6 +584,8 @@ const CommonEditor = /*#__PURE__*/forwardRef((props, ref) => {
584
584
  }), htmlAction.showInput && /*#__PURE__*/_jsx(CodeToText, {
585
585
  ...htmlAction,
586
586
  handleCodeToText: handleCodeToText
587
+ }), /*#__PURE__*/_jsx(FontLoader, {
588
+ ...props
587
589
  })]
588
590
  }, id)
589
591
  })
@@ -559,6 +559,7 @@ blockquote {
559
559
 
560
560
  .embed {
561
561
  justify-content: center;
562
+ width: 100%;
562
563
  }
563
564
 
564
565
  .embed img {
@@ -90,7 +90,6 @@ function AIInput({
90
90
  children: [/*#__PURE__*/_jsxs(Box, {
91
91
  component: "div",
92
92
  sx: classes.aiContainer,
93
- ref: refs[0],
94
93
  children: [generatedText ? /*#__PURE__*/_jsx(Typography, {
95
94
  sx: classes.generatedText,
96
95
  style: {
@@ -105,6 +104,7 @@ function AIInput({
105
104
  onSubmit: e => {
106
105
  e.preventDefault();
107
106
  },
107
+ ref: refs[0],
108
108
  children: [/*#__PURE__*/_jsx("div", {
109
109
  className: "icon-container icons-elements",
110
110
  ref: inputWrapperRef,
@@ -116,21 +116,22 @@ function AIInput({
116
116
  children: /*#__PURE__*/_jsx(WaveLoading, {})
117
117
  }) : /*#__PURE__*/_jsx(TextareaAutosize, {
118
118
  className: "ai-input",
119
- placeholder: "Ask AI to write anything...",
119
+ placeholder: fromToolBar ? "" : "Ask AI to write anything...",
120
120
  ref: inputRef,
121
121
  value: inputValue,
122
122
  onChange: onInputChange,
123
+ disabled: fromToolBar,
123
124
  onKeyDown: event => {
124
125
  if (event.key === "Enter" && !event.shiftKey) {
125
126
  event.preventDefault();
126
127
  handleSendBtnClick();
127
128
  }
128
129
  }
129
- }), /*#__PURE__*/_jsxs(Box, {
130
+ }), fromToolBar ? null : /*#__PURE__*/_jsxs(Box, {
130
131
  component: "div",
131
132
  style: classes.sendIconContainer,
132
133
  className: "icons-elements",
133
- children: [/*#__PURE__*/_jsx(IconButton, {
134
+ children: [isMobile ? null : /*#__PURE__*/_jsx(IconButton, {
134
135
  disabled: loading,
135
136
  onClick: () => startRecording(),
136
137
  children: /*#__PURE__*/_jsx(ChatMicIcon, {})
@@ -40,11 +40,9 @@ const scrollToAIInput = editor => {
40
40
  }, 200);
41
41
  };
42
42
  const insertText = (editor, text, 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
- }
43
+ const parsed = new DOMParser().parseFromString(text, "text/html");
44
+ const fragment = deserialize(parsed.body);
45
+ Transforms.insertFragment(editor, fragment, options);
48
46
  };
49
47
  const insertAtNextLine = (editor, text) => {
50
48
  const nextLine = getNextLine(editor);
@@ -201,95 +199,81 @@ function PopoverAIInput({
201
199
  useEffect(() => {
202
200
  selectedEleRef.current = selectedElement;
203
201
  }, [selectedElement]);
204
- const framePayload = (type, option) => {
205
- let payload = {
202
+ 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 {
221
+ insertText(editor, generatedText);
222
+ }
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 = {
206
245
  mode: option.mode || 0,
207
246
  query: option?.inputValue || inputValue
208
247
  };
209
248
  if (option.mode === MODES.translate || option.mode === MODES.rephraseTone) {
210
249
  payload.textOptionInput = type;
211
250
  }
212
- const selectedText = getSelectedText(editor);
213
- const textData = generatedText || selectedText;
214
251
  if (option.mode) {
215
- payload.textData = textData;
216
- } else if (selectedText && Number(payload.mode) === 0) {
217
- payload.query = `${selectedText} \n ${payload.query}`;
252
+ payload.textData = generatedText || window.getSelection().toString();
218
253
  }
219
- const tryAgain = type === "try_again";
220
- if (tryAgain) {
221
- // resetting previous payload
222
- const prevPayload = selectedOption?.payload || {};
223
- payload = prevPayload;
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;
224
263
  }
225
- return payload;
226
- };
227
- const onSend = async (type, option) => {
228
- try {
229
- if (type === "close") {
230
- onClickOutside();
231
- return;
232
- }
233
- if (type === "done") {
234
- // Get the current selection point
235
- const {
236
- anchor
237
- } = editor.selection;
238
- const {
239
- path
240
- } = anchor;
241
- const {
242
- text: selectText
243
- } = Node.get(editor, path);
244
- if (selectText?.length) {
245
- insertAtNextLine(editor, generatedText);
246
- } else {
247
- insertText(editor, generatedText);
248
- }
249
- onClickOutside();
250
- return;
251
- }
252
- if (type === "replace_selection") {
253
- // replace generated text
254
- insertText(editor, generatedText);
255
- onClickOutside();
256
- return;
257
- }
258
- setLoading(true);
259
- const payload = framePayload(type, option);
260
- setSelectedOption({
261
- ...option,
262
- payload
263
- });
264
- const result = await services("infinityAI", payload);
265
- setLoading(false);
266
- setInputValue("");
267
- let {
268
- data: text
269
- } = result || {};
270
- if (!text) {
271
- onClickOutside();
272
- return;
273
- }
274
-
275
- // if (!option.replace) {
264
+ if (!option.replace) {
276
265
  if (type === "continue_writing") {
277
266
  setGeneratedText(generatedText + text);
278
267
  } else {
279
268
  setGeneratedText(text);
280
269
  }
281
-
282
- // return;
283
- // }
284
-
285
- // ** we are not using this insertText right now, AI returned response will not insert into the editor immediately, so option.replace will be false always
286
- // insertText(editor, text);
287
-
288
- // scrollToAIInput();
289
- } catch (err) {
290
- console.error("Error on sending/inserting text", err);
270
+ return;
291
271
  }
272
+ insertText(editor, text);
273
+
274
+ // scrollToAIInput();
292
275
  };
276
+
293
277
  const onInputChange = e => {
294
278
  setInputValue(e.target.value);
295
279
  };
@@ -102,7 +102,6 @@ const Styles = theme => ({
102
102
  customSelectWrapper: {
103
103
  width: "fit-content",
104
104
  marginTop: "4px",
105
- position: "absolute",
106
105
  "@media only screen and (max-width: 600px)": {
107
106
  marginBottom: "4px"
108
107
  }
@@ -209,6 +209,7 @@ const Video = ({
209
209
  }, theme);
210
210
  return /*#__PURE__*/_jsxs(Box, {
211
211
  ...attributes,
212
+ ...element.attr,
212
213
  className: "embed has-hover video dpath",
213
214
  sx: {
214
215
  display: {
@@ -222,7 +223,6 @@ const Video = ({
222
223
  justifyContent: horizantal,
223
224
  alignContent: vertical
224
225
  },
225
- ...element.attr,
226
226
  contentEditable: false,
227
227
  children: [openSetttings ? /*#__PURE__*/_jsx(EmbedPopup, {
228
228
  element: element,
@@ -24,6 +24,9 @@ const SimpleTextStyle = ({
24
24
  color: invertColor(pageColor)
25
25
  }
26
26
  },
27
+ "&.embed": {
28
+ width: "100%"
29
+ },
27
30
  "& .freegrid-section": {
28
31
  "&.enable-1:before": {
29
32
  content: "' '",
@@ -286,7 +286,7 @@ const editorStyles = ({
286
286
  }
287
287
  },
288
288
  "& ::selection": {
289
- color: "inherit",
289
+ color: "black",
290
290
  background: "#EAEBFE"
291
291
  }
292
292
  },
@@ -13,7 +13,6 @@ import PopperHeader from "../PopperHeader";
13
13
  import MiniColorPicker from "./MiniColorPicker";
14
14
  import SelectAlignment from "./SelectAlignment";
15
15
  import SelectFontSize from "./SelectFontSize";
16
- import InfinityAITool from "./InfinityAITool";
17
16
  import { jsx as _jsx } from "react/jsx-runtime";
18
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
19
18
  const DEFAULT_COLOR = {
@@ -27,8 +26,7 @@ const MiniTextFormat = props => {
27
26
  const {
28
27
  classes,
29
28
  editor,
30
- closeMainPopup,
31
- customProps
29
+ closeMainPopup
32
30
  } = props;
33
31
  const [anchorEl, setAnchorEl] = useState(null);
34
32
  const open = Boolean(anchorEl);
@@ -50,7 +48,7 @@ const MiniTextFormat = props => {
50
48
  xs: 12,
51
49
  children: /*#__PURE__*/_jsxs("div", {
52
50
  className: "toolWrapper",
53
- children: [customProps?.hideTools?.includes("infinityAI") ? null : /*#__PURE__*/_jsx(InfinityAITool, {}), /*#__PURE__*/_jsx(SelectTypography, {
51
+ children: [/*#__PURE__*/_jsx(SelectTypography, {
54
52
  classes: classes,
55
53
  editor: editor,
56
54
  closeMainPopup: closeMainPopup
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import { Node } from "slate";
2
3
  import { Dialog, DialogContent, DialogTitle, IconButton } from "@mui/material";
3
4
  import SaveAsTemplate from "../../../StyleBuilder/fieldTypes/saveAsTemplate";
4
5
  import { CloseIcon } from "../../../iconslist";
@@ -12,7 +12,7 @@ const Settings = props => {
12
12
  childType,
13
13
  open,
14
14
  anchorEl,
15
- // placement,
15
+ placement,
16
16
  onClose,
17
17
  editor,
18
18
  classes,
@@ -123,8 +123,8 @@ export function onDropItem(props, parentClass) {
123
123
  dragOver,
124
124
  parentPath,
125
125
  path,
126
- // diffX,
127
- // x: cx,
126
+ diffX,
127
+ x: cx,
128
128
  breakpoint
129
129
  // calX,
130
130
  } = props;
@@ -134,9 +134,7 @@ export function onDropItem(props, parentClass) {
134
134
  let newPath = [];
135
135
  newPath = moveTo;
136
136
  const cCalx = isContainerElement(editor, moveTo, props);
137
- // const posX = parseInt(
138
- // cx - window.innerWidth / 2 + MARGIN_OF[breakpoint] - diffX
139
- // );
137
+ const posX = parseInt(cx - window.innerWidth / 2 + MARGIN_OF[breakpoint] - diffX);
140
138
  const toSectionNode = Node.get(editor, newPath);
141
139
  const addToSectionDOM = ReactEditor.toDOMNode(editor, toSectionNode);
142
140
  const rect = addToSectionDOM.getBoundingClientRect();
@@ -1,16 +1,4 @@
1
1
  import { Editor, Node, Path, Transforms } from "slate";
2
- const getCurrentNodeType = editor => {
3
- if (editor.selection) {
4
- // Get the current node at the selection
5
- const [node] = Editor.nodes(editor, {
6
- match: n => Editor.isBlock(editor, n)
7
- });
8
-
9
- // Return the node's type if it exists
10
- return node ? node[0].type : null;
11
- }
12
- return null;
13
- };
14
2
  const isNodeTextEmpty = node => {
15
3
  const nodeText = Node.string(node);
16
4
  return nodeText.trim() === "";
@@ -26,19 +14,6 @@ const withCustomDeleteBackward = editor => {
26
14
  selection
27
15
  } = editor;
28
16
  if (selection) {
29
- // get the current node
30
- const [freeGridItemNode] = Editor.nodes(editor, {
31
- match: n => n.type === "freegridItem" // Adjust based on your list item type
32
- });
33
-
34
- // if it is freegrid
35
- if (freeGridItemNode && freeGridItemNode[0]) {
36
- const hasText = Node.string(freeGridItemNode[0]);
37
- if (!hasText) {
38
- return;
39
- }
40
- }
41
-
42
17
  // Check if current node is a list item and is the last one
43
18
  const [node] = Editor.nodes(editor, {
44
19
  match: n => n.type === "list-item" // Adjust based on your list item type
@@ -1,6 +1,5 @@
1
- import highlightSelection from "./highlightSelection";
2
1
  import link from "./link";
3
- const decorators = (d, editor) => {
4
- return [...link(d, editor), ...highlightSelection(d, editor)];
2
+ const decorators = d => {
3
+ return [...link(d)];
5
4
  };
6
5
  export default decorators;
@@ -242,15 +242,6 @@ export const getMarked = (leaf, children, theme) => {
242
242
  })
243
243
  });
244
244
  }
245
- if (leaf.highlight) {
246
- children = /*#__PURE__*/_jsx("span", {
247
- style: {
248
- background: "#EAEBFE",
249
- color: "inherit"
250
- },
251
- children: children
252
- });
253
- }
254
245
  if (leaf.decoration === "link") {
255
246
  children = /*#__PURE__*/_jsx("a", {
256
247
  style: {
@@ -483,7 +483,7 @@ export const isFreeGrid = (nodes, types = ["freegrid", "freegridItem", "freegrid
483
483
  }
484
484
  return false;
485
485
  } catch (err) {
486
- console.log("isFreeGrid error:", err);
486
+ console.log('isFreeGrid error:', err);
487
487
  return false;
488
488
  }
489
489
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "4.7.3",
3
+ "version": "4.7.4",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"
@@ -1,22 +0,0 @@
1
- import { Editor, Range, Text } from "slate";
2
- const highlightSelection = ([node, path], editor = {}) => {
3
- if (Text.isText(node) && editor?.selection) {
4
- const intersection = Range.intersection(editor.selection, Editor.range(editor, path));
5
- if (!intersection) {
6
- return [];
7
- }
8
-
9
- // Avoid applying highlight if the range only includes line breaks
10
- const rangeText = Editor.string(editor, intersection);
11
- if (!rangeText.trim()) {
12
- return [];
13
- }
14
- const range = {
15
- highlight: true,
16
- ...intersection
17
- };
18
- return [range];
19
- }
20
- return [];
21
- };
22
- export default highlightSelection;