@flozy/editor 4.7.2 → 4.7.4

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.
@@ -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, {
@@ -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
  }
@@ -58,8 +58,15 @@ const Embed = ({
58
58
  url: img
59
59
  };
60
60
  setFormData(fd);
61
+ let extProps = {};
62
+ if (format === "video") {
63
+ extProps = {
64
+ aspectRatio: "16 / 9"
65
+ };
66
+ }
61
67
  handleFormSubmit({
62
- ...fd
68
+ ...fd,
69
+ ...extProps
63
70
  });
64
71
  };
65
72
  return /*#__PURE__*/_jsxs(_Fragment, {
@@ -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
@@ -5,6 +5,7 @@ import LinkSettings from "../../../LinkSettings";
5
5
  import { insertLink, removeLink } from "../../../../utils/link";
6
6
  import { getBlockActive, isBlockActive, upateBlockActive } from "../../../../utils/SlateUtilityFunctions";
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
+ import { Fragment as _Fragment } from "react/jsx-runtime";
8
9
  const Link = props => {
9
10
  const {
10
11
  onClose,
@@ -138,18 +139,20 @@ const Link = props => {
138
139
  console.log(err);
139
140
  }
140
141
  };
141
- return /*#__PURE__*/_jsx(LinkSettings, {
142
- handleClose: onClose,
143
- onSave: d => {
144
- const upData = getTransformedData(d);
145
- onSave({
146
- ...upData
147
- });
148
- onClose();
149
- },
150
- ...(blockProps || {}),
151
- customProps: customProps,
152
- theme: theme
142
+ return /*#__PURE__*/_jsx(_Fragment, {
143
+ children: blockProps ? /*#__PURE__*/_jsx(LinkSettings, {
144
+ handleClose: onClose,
145
+ onSave: d => {
146
+ const upData = getTransformedData(d);
147
+ onSave({
148
+ ...upData
149
+ });
150
+ onClose();
151
+ },
152
+ ...(blockProps || {}),
153
+ customProps: customProps,
154
+ theme: theme
155
+ }) : null
153
156
  });
154
157
  };
155
158
  export default Link;
@@ -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();
@@ -107,7 +107,9 @@ const ELEMENTS_LIST = [{
107
107
  icon: /*#__PURE__*/_jsx(Icon, {
108
108
  icon: "video"
109
109
  }),
110
- onInsert: editor => insertDefaultEmbed(editor, "video")
110
+ onInsert: editor => insertDefaultEmbed(editor, "video", "", {
111
+ aspectRatio: "16 / 9"
112
+ })
111
113
  }, {
112
114
  name: "Embed",
113
115
  desc: "",
@@ -16,14 +16,14 @@ const embedVideoStyle = [{
16
16
  key: "aspectRatio",
17
17
  type: "textOptions",
18
18
  options: [{
19
- text: "Cover (Default)",
20
- value: ""
21
- }, {
22
- text: "16:9",
19
+ text: "16:9 (Default)",
23
20
  value: "16 / 9"
24
21
  }, {
25
22
  text: "9:16",
26
23
  value: "9 / 16"
24
+ }, {
25
+ text: "Custom",
26
+ value: ""
27
27
  }],
28
28
  renderOption: option => {
29
29
  return /*#__PURE__*/_jsx("span", {
@@ -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: {
@@ -1,11 +1,12 @@
1
1
  import { Transforms } from "slate";
2
2
  import insertNewLine from "./insertNewLine";
3
- export const insertDefaultEmbed = (editor, type, defaultURL = "") => {
3
+ export const insertDefaultEmbed = (editor, type, defaultURL = "", extProps = {}) => {
4
4
  try {
5
5
  const url = defaultURL ? defaultURL : type === "image" ? "" : "";
6
6
  insertEmbed(editor, {
7
7
  url,
8
- images: []
8
+ images: [],
9
+ ...extProps
9
10
  }, type);
10
11
  } catch (err) {
11
12
  console.log(err);
@@ -14,7 +15,8 @@ export const insertDefaultEmbed = (editor, type, defaultURL = "") => {
14
15
  export const createEmbedNode = (type, {
15
16
  url,
16
17
  alt,
17
- images
18
+ images,
19
+ ...rest
18
20
  }) => ({
19
21
  type,
20
22
  alt,
@@ -23,6 +25,7 @@ export const createEmbedNode = (type, {
23
25
  children: [{
24
26
  text: " "
25
27
  }],
28
+ ...(rest || {}),
26
29
  size: {
27
30
  xs: {
28
31
  widthInPercent: "100",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "4.7.2",
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;