@flozy/editor 1.1.7 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,7 +16,8 @@ const CollaborativeEditor = props => {
16
16
  onSave,
17
17
  user,
18
18
  socketURL,
19
- apiHOST
19
+ apiHOST,
20
+ ...rest
20
21
  } = props;
21
22
  const convertedContent = draftToSlate({
22
23
  data: content
@@ -105,7 +106,6 @@ const CollaborativeEditor = props => {
105
106
  provider.destroy();
106
107
  setConnected(false);
107
108
  setMessage("Seems your connection is lost... Reload the page to edit the document...");
108
- console.log("closed", provider);
109
109
  });
110
110
  if (authenticated.status === null || !connected === null || !editor) {
111
111
  return /*#__PURE__*/_jsx("h1", {
@@ -122,7 +122,8 @@ const CollaborativeEditor = props => {
122
122
  otherProps: {
123
123
  token: user?.token,
124
124
  API_HOST: apiHOST
125
- }
125
+ },
126
+ ...rest
126
127
  });
127
128
  };
128
129
  export default CollaborativeEditor;
@@ -1,8 +1,8 @@
1
1
  import React, { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { createEditor } from "slate";
2
3
  import { Slate, Editable } from "slate-react";
3
4
  import Toolbar from "./Toolbar/Toolbar";
4
5
  import { getMarked, getBlock } from "./utils/SlateUtilityFunctions";
5
- import "./Editor.css";
6
6
  import CodeToText from "./Elements/CodeToText/CodeToText";
7
7
  import { draftToSlate } from "./utils/draftToSlate";
8
8
  import useMentions from "./hooks/useMentions";
@@ -10,7 +10,10 @@ import MentionsPopup from "./common/MentionsPopup";
10
10
  import { RemoteCursorOverlay } from "./RemoteCursorOverlay/Overlay";
11
11
  import { mentionsEvent, commands } from "./utils/events";
12
12
  import withCommon from "./hooks/withCommon";
13
- import { createEditor } from "slate";
13
+ import DialogWrapper from "./DialogWrapper";
14
+ import useTimeout from "./hooks/useTimeout";
15
+ import "./Editor.css";
16
+ import { serialize } from "./utils/serializer";
14
17
  import { jsx as _jsx } from "react/jsx-runtime";
15
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
16
19
  const Element = props => {
@@ -34,12 +37,17 @@ const CommonEditor = props => {
34
37
  onSave,
35
38
  editor: collaborativeEditor,
36
39
  readOnly,
37
- otherProps
40
+ otherProps,
41
+ timeoutInMS = 1000
38
42
  } = props;
39
43
  const convertedContent = draftToSlate({
40
44
  data: content
41
45
  });
42
46
  const [value, setValue] = useState(convertedContent);
47
+ const [lastUpdated, setLastUpdated] = useState(value);
48
+ const [count] = useTimeout({
49
+ timeoutInMS: timeoutInMS
50
+ });
43
51
  const editor = useMemo(() => {
44
52
  if (collaborativeEditor) return collaborativeEditor;
45
53
  return withCommon(createEditor());
@@ -63,6 +71,11 @@ const CommonEditor = props => {
63
71
  data: content
64
72
  }));
65
73
  }, [id, content]);
74
+ useEffect(() => {
75
+ if (count > 0) {
76
+ updateChanges(value);
77
+ }
78
+ }, [count]);
66
79
  const [htmlAction, setHtmlAction] = useState({
67
80
  showInput: false,
68
81
  html: "",
@@ -82,9 +95,19 @@ const CommonEditor = props => {
82
95
  const handleEditorChange = newValue => {
83
96
  setValue(newValue);
84
97
  const isAstChange = editor.operations.some(op => "set_selection" !== op.type);
85
- if (isAstChange && onSave) {
98
+ if (isAstChange && onSave && timeoutInMS === 0) {
86
99
  // send the value to onSave api
87
- onSave(JSON.stringify(newValue));
100
+ updateChanges(newValue);
101
+ }
102
+ };
103
+ const updateChanges = newValue => {
104
+ const stringify = JSON.stringify(newValue);
105
+ const text = serialize(newValue);
106
+ if (stringify !== lastUpdated && count > 0 && text?.trim().length > 3) {
107
+ onSave(stringify, {
108
+ text: text
109
+ });
110
+ setLastUpdated(stringify);
88
111
  }
89
112
  };
90
113
  const customProps = {
@@ -129,52 +152,55 @@ const CommonEditor = props => {
129
152
  }, [chars, editor, target, mentions, setMentions]);
130
153
  const isReadOnly = readOnly === "readonly";
131
154
  const Overlay = collaborativeEditor && !isReadOnly ? RemoteCursorOverlay : React.Fragment;
132
- return /*#__PURE__*/_jsx("div", {
133
- style: {
134
- display: "flex",
135
- flexDirection: "column",
136
- padding: "0 8px"
137
- },
138
- children: /*#__PURE__*/_jsxs(Slate, {
139
- editor: editor,
140
- initialValue: value,
141
- onChange: handleEditorChange,
142
- children: [/*#__PURE__*/_jsxs(Overlay, {
143
- children: [!isReadOnly ? /*#__PURE__*/_jsx(Toolbar, {
144
- handleCodeToText: handleCodeToText,
145
- customProps: customProps
146
- }) : null, /*#__PURE__*/_jsxs("div", {
147
- className: "editor-wrapper",
148
- style: {
149
- border: "1px solid #f3f3f3",
150
- background: pageProps?.pageColor || "#FFF",
151
- color: pageProps?.color || "#000",
152
- paddingLeft: `${bannerSpacing?.left}px`,
153
- paddingRight: `${bannerSpacing?.right}px`,
154
- paddingTop: `${bannerSpacing?.top}px`,
155
- paddingBottom: `${bannerSpacing?.bottom}px`
156
- },
157
- children: [/*#__PURE__*/_jsx(Editable, {
158
- readOnly: isReadOnly,
159
- placeholder: "Write something",
160
- renderElement: renderElement,
161
- renderLeaf: renderLeaf,
162
- onKeyDown: onKeyDown
163
- }), /*#__PURE__*/_jsx(MentionsPopup, {
164
- mentions: mentions,
165
- setMentions: setMentions,
166
- editor: editor,
167
- target: target,
168
- index: index,
169
- chars: chars
155
+ return /*#__PURE__*/_jsx(DialogWrapper, {
156
+ ...props,
157
+ children: /*#__PURE__*/_jsx("div", {
158
+ style: {
159
+ display: "flex",
160
+ flexDirection: "column",
161
+ padding: "0 8px"
162
+ },
163
+ children: /*#__PURE__*/_jsxs(Slate, {
164
+ editor: editor,
165
+ initialValue: value,
166
+ onChange: handleEditorChange,
167
+ children: [/*#__PURE__*/_jsxs(Overlay, {
168
+ children: [!isReadOnly ? /*#__PURE__*/_jsx(Toolbar, {
169
+ handleCodeToText: handleCodeToText,
170
+ customProps: customProps
171
+ }) : null, /*#__PURE__*/_jsxs("div", {
172
+ className: "editor-wrapper",
173
+ style: {
174
+ border: "1px solid #f3f3f3",
175
+ background: pageProps?.pageColor || "#FFF",
176
+ color: pageProps?.color || "#000",
177
+ paddingLeft: `${bannerSpacing?.left}px`,
178
+ paddingRight: `${bannerSpacing?.right}px`,
179
+ paddingTop: `${bannerSpacing?.top}px`,
180
+ paddingBottom: `${bannerSpacing?.bottom}px`
181
+ },
182
+ children: [/*#__PURE__*/_jsx(Editable, {
183
+ readOnly: isReadOnly,
184
+ placeholder: "Write something",
185
+ renderElement: renderElement,
186
+ renderLeaf: renderLeaf,
187
+ onKeyDown: onKeyDown
188
+ }), /*#__PURE__*/_jsx(MentionsPopup, {
189
+ mentions: mentions,
190
+ setMentions: setMentions,
191
+ editor: editor,
192
+ target: target,
193
+ index: index,
194
+ chars: chars
195
+ })]
170
196
  })]
197
+ }), htmlAction.showInput && /*#__PURE__*/_jsx(CodeToText, {
198
+ ...htmlAction,
199
+ handleCodeToText: handleCodeToText
171
200
  })]
172
- }), htmlAction.showInput && /*#__PURE__*/_jsx(CodeToText, {
173
- ...htmlAction,
174
- handleCodeToText: handleCodeToText
175
- })]
176
- }, id)
201
+ }, id)
202
+ })
177
203
  });
178
204
  };
179
- const CHARACTERS = ["Aayla Secura", "Adi Gallia", "Admiral Dodd Rancit", "Admiral Firmus Piett", "Admiral Gial Ackbar", "Admiral Ozzel", "Admiral Raddus", "Admiral Terrinald Screed", "Admiral Trench", "Admiral U.O. Statura", "Agen Kolar", "Agent Kallus", "Aiolin and Morit Astarte", "Aks Moe", "Almec", "Alton Kastle", "Amee", "AP-5", "Armitage Hux", "Artoo", "Arvel Crynyd", "Asajj Ventress", "Aurra Sing", "AZI-3", "Bala-Tik", "Barada", "Bargwill Tomder", "Baron Papanoida", "Barriss Offee", "Baze Malbus", "Bazine Netal", "BB-8", "BB-9E", "Ben Quadinaros", "Berch Teller", "Beru Lars", "Bib Fortuna", "Biggs Darklighter", "Black Krrsantan", "Bo-Katan Kryze", "Boba Fett", "Bobbajo", "Bodhi Rook", "Borvo the Hutt", "Boss Nass", "Bossk", "Breha Antilles-Organa", "Bren Derlin", "Brendol Hux", "BT-1", "C-3PO", "C1-10P", "Cad Bane", "Caluan Ematt", "Captain Gregor", "Captain Phasma", "Captain Quarsh Panaka", "Captain Rex", "Carlist Rieekan", "Casca Panzoro", "Cassian Andor", "Cassio Tagge", "Cham Syndulla", "Che Amanwe Papanoida", "Chewbacca", "Chi Eekway Papanoida", "Chief Chirpa", "Chirrut Îmwe", "Ciena Ree", "Cin Drallig", "Clegg Holdfast", "Cliegg Lars", "Coleman Kcaj", "Coleman Trebor", "Colonel Kaplan", "Commander Bly", "Commander Cody (CC-2224)", "Commander Fil (CC-3714)", "Commander Fox", "Commander Gree", "Commander Jet", "Commander Wolffe", "Conan Antonio Motti", "Conder Kyl", "Constable Zuvio", "Cordé", "Cpatain Typho", "Crix Madine", "Cut Lawquane", "Dak Ralter", "Dapp", "Darth Bane", "Darth Maul", "Darth Tyranus", "Daultay Dofine", "Del Meeko", "Delian Mors", "Dengar", "Depa Billaba", "Derek Klivian", "Dexter Jettster", "Dineé Ellberger", "DJ", "Doctor Aphra", "Doctor Evazan", "Dogma", "Dormé", "Dr. Cylo", "Droidbait", "Droopy McCool", "Dryden Vos", "Dud Bolt", "Ebe E. Endocott", "Echuu Shen-Jon", "Eeth Koth", "Eighth Brother", "Eirtaé", "Eli Vanto", "Ellé", "Ello Asty", "Embo", "Eneb Ray", "Enfys Nest", "EV-9D9", "Evaan Verlaine", "Even Piell", "Ezra Bridger", "Faro Argyus", "Feral", "Fifth Brother", "Finis Valorum", "Finn", "Fives", "FN-1824", "FN-2003", "Fodesinbeed Annodue", "Fulcrum", "FX-7", "GA-97", "Galen Erso", "Gallius Rax", 'Garazeb "Zeb" Orrelios', "Gardulla the Hutt", "Garrick Versio", "Garven Dreis", "Gavyn Sykes", "Gideon Hask", "Gizor Dellso", "Gonk droid", "Grand Inquisitor", "Greeata Jendowanian", "Greedo", "Greer Sonnel", "Grievous", "Grummgar", "Gungi", "Hammerhead", "Han Solo", "Harter Kalonia", "Has Obbit", "Hera Syndulla", "Hevy", "Hondo Ohnaka", "Huyang", "Iden Versio", "IG-88", "Ima-Gun Di", "Inquisitors", "Inspector Thanoth", "Jabba", "Jacen Syndulla", "Jan Dodonna", "Jango Fett", "Janus Greejatus", "Jar Jar Binks", "Jas Emari", "Jaxxon", "Jek Tono Porkins", "Jeremoch Colton", "Jira", "Jobal Naberrie", "Jocasta Nu", "Joclad Danva", "Joh Yowza", "Jom Barell", "Joph Seastriker", "Jova Tarkin", "Jubnuk", "Jyn Erso", "K-2SO", "Kanan Jarrus", "Karbin", "Karina the Great", "Kes Dameron", "Ketsu Onyo", "Ki-Adi-Mundi", "King Katuunko", "Kit Fisto", "Kitster Banai", "Klaatu", "Klik-Klak", "Korr Sella", "Kylo Ren", "L3-37", "Lama Su", "Lando Calrissian", "Lanever Villecham", "Leia Organa", "Letta Turmond", "Lieutenant Kaydel Ko Connix", "Lieutenant Thire", "Lobot", "Logray", "Lok Durd", "Longo Two-Guns", "Lor San Tekka", "Lorth Needa", "Lott Dod", "Luke Skywalker", "Lumat", "Luminara Unduli", "Lux Bonteri", "Lyn Me", "Lyra Erso", "Mace Windu", "Malakili", "Mama the Hutt", "Mars Guo", "Mas Amedda", "Mawhonic", "Max Rebo", "Maximilian Veers", "Maz Kanata", "ME-8D9", "Meena Tills", "Mercurial Swift", "Mina Bonteri", "Miraj Scintel", "Mister Bones", "Mod Terrik", "Moden Canady", "Mon Mothma", "Moradmin Bast", "Moralo Eval", "Morley", "Mother Talzin", "Nahdar Vebb", "Nahdonnis Praji", "Nien Nunb", "Niima the Hutt", "Nines", "Norra Wexley", "Nute Gunray", "Nuvo Vindi", "Obi-Wan Kenobi", "Odd Ball", "Ody Mandrell", "Omi", "Onaconda Farr", "Oola", "OOM-9", "Oppo Rancisis", "Orn Free Taa", "Oro Dassyne", "Orrimarko", "Osi Sobeck", "Owen Lars", "Pablo-Jill", "Padmé Amidala", "Pagetti Rook", "Paige Tico", "Paploo", "Petty Officer Thanisson", "Pharl McQuarrie", "Plo Koon", "Po Nudo", "Poe Dameron", "Poggle the Lesser", "Pong Krell", "Pooja Naberrie", "PZ-4CO", "Quarrie", "Quay Tolsite", "Queen Apailana", "Queen Jamillia", "Queen Neeyutnee", "Qui-Gon Jinn", "Quiggold", "Quinlan Vos", "R2-D2", "R2-KT", "R3-S6", "R4-P17", "R5-D4", "RA-7", "Rabé", "Rako Hardeen", "Ransolm Casterfo", "Rappertunie", "Ratts Tyerell", "Raymus Antilles", "Ree-Yees", "Reeve Panzoro", "Rey", "Ric Olié", "Riff Tamson", "Riley", "Rinnriyin Di", "Rio Durant", "Rogue Squadron", "Romba", "Roos Tarpals", "Rose Tico", "Rotta the Hutt", "Rukh", "Rune Haako", "Rush Clovis", "Ruwee Naberrie", "Ryoo Naberrie", "Sabé", "Sabine Wren", "Saché", "Saelt-Marae", "Saesee Tiin", "Salacious B. Crumb", "San Hill", "Sana Starros", "Sarco Plank", "Sarkli", "Satine Kryze", "Savage Opress", "Sebulba", "Senator Organa", "Sergeant Kreel", "Seventh Sister", "Shaak Ti", "Shara Bey", "Shmi Skywalker", "Shu Mai", "Sidon Ithano", "Sifo-Dyas", "Sim Aloo", "Siniir Rath Velus", "Sio Bibble", "Sixth Brother", "Slowen Lo", "Sly Moore", "Snaggletooth", "Snap Wexley", "Snoke", "Sola Naberrie", "Sora Bulq", "Strono Tuggs", "Sy Snootles", "Tallissan Lintra", "Tarfful", "Tasu Leech", "Taun We", "TC-14", "Tee Watt Kaa", "Teebo", "Teedo", "Teemto Pagalies", "Temiri Blagg", "Tessek", "Tey How", "Thane Kyrell", "The Bendu", "The Smuggler", "Thrawn", "Tiaan Jerjerrod", "Tion Medon", "Tobias Beckett", "Tulon Voidgazer", "Tup", "U9-C4", "Unkar Plutt", "Val Beckett", "Vanden Willard", "Vice Admiral Amilyn Holdo", "Vober Dand", "WAC-47", "Wag Too", "Wald", "Walrus Man", "Warok", "Wat Tambor", "Watto", "Wedge Antilles", "Wes Janson", "Wicket W. Warrick", "Wilhuff Tarkin", "Wollivan", "Wuher", "Wullf Yularen", "Xamuel Lennox", "Yaddle", "Yarael Poof", "Yoda", "Zam Wesell", "Zev Senesca", "Ziro the Hutt", "Zuckuss"];
205
+ const CHARACTERS = ["Aayla Secura", "Adi Gallia"];
180
206
  export default CommonEditor;
@@ -0,0 +1,43 @@
1
+ import React from "react";
2
+ import { Dialog, DialogTitle, DialogContent, DialogActions, IconButton, Grid } from "@mui/material";
3
+ import CloseIcon from "@mui/icons-material/Close";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ import { jsxs as _jsxs } from "react/jsx-runtime";
6
+ const DialogWrapper = props => {
7
+ const {
8
+ fullScreen,
9
+ onClose,
10
+ children,
11
+ footer
12
+ } = props;
13
+ return fullScreen ? /*#__PURE__*/_jsxs(Dialog, {
14
+ open: fullScreen,
15
+ fullScreen: fullScreen,
16
+ onClose: onClose,
17
+ children: [/*#__PURE__*/_jsx(DialogTitle, {
18
+ children: /*#__PURE__*/_jsx(Grid, {
19
+ children: /*#__PURE__*/_jsx(Grid, {
20
+ style: {
21
+ display: 'flex',
22
+ justifyContent: 'end'
23
+ },
24
+ children: /*#__PURE__*/_jsx(IconButton, {
25
+ onClick: onClose,
26
+ children: /*#__PURE__*/_jsx(CloseIcon, {})
27
+ })
28
+ })
29
+ })
30
+ }), /*#__PURE__*/_jsx(DialogContent, {
31
+ children: children
32
+ }), /*#__PURE__*/_jsx(DialogActions, {
33
+ children: footer
34
+ })]
35
+ }) : children;
36
+ };
37
+ DialogWrapper.defaultProps = {
38
+ fullScreen: false,
39
+ onClose: () => {},
40
+ children: '',
41
+ footer: ''
42
+ };
43
+ export default DialogWrapper;
@@ -32,9 +32,7 @@ const HtmlCode = props => {
32
32
  } else if (e.keyCode === 8) {
33
33
  Transforms.removeNodes(editor);
34
34
  }
35
- // console.log(e);
36
35
  };
37
-
38
36
  useEffect(() => {
39
37
  document.addEventListener("keyup", handleKeyUp);
40
38
  return () => {
@@ -32,7 +32,6 @@ const EquationButton = ({
32
32
  if (!math) return;
33
33
  selection && Transforms.select(editor, selection);
34
34
  insertEquation(editor, math, displayInline);
35
- console.log("btn click");
36
35
  setShowInput(false);
37
36
  };
38
37
  return /*#__PURE__*/_jsxs("div", {
@@ -10,7 +10,6 @@ const UploadSignature = props => {
10
10
  } = props;
11
11
  const [base64, setBase64] = useState(null);
12
12
  const [uploading, setUploading] = useState(false);
13
- console.log(customProps);
14
13
  const onChange = async e => {
15
14
  const file = e.target.files[0];
16
15
  const strImage = await convertBase64(file);
@@ -75,7 +75,6 @@ const StyleBuilder = props => {
75
75
  setTab(newValue);
76
76
  };
77
77
  const onElementPropsChange = data => {
78
- console.log(data);
79
78
  setElementProps({
80
79
  ...elementProps,
81
80
  ...data
@@ -0,0 +1,21 @@
1
+ import { useEffect, useState } from "react";
2
+ let t = null;
3
+ const useTimeout = props => {
4
+ const {
5
+ timeoutInMS
6
+ } = props;
7
+ const [count, setCount] = useState(-1);
8
+ const onReset = () => {
9
+ clearTimeout(t);
10
+ t = setTimeout(() => {
11
+ setCount(count + 1);
12
+ }, timeoutInMS);
13
+ };
14
+ useEffect(() => {
15
+ if (timeoutInMS) {
16
+ onReset();
17
+ }
18
+ }, [timeoutInMS, count]);
19
+ return [count];
20
+ };
21
+ export default useTimeout;
@@ -1,38 +1,16 @@
1
- import { Text } from "slate";
2
- import { getBlock, getMarked } from "./SlateUtilityFunctions.js";
3
- import ReactDOMServer from "react-dom/server";
4
- const {
5
- renderToString
6
- } = ReactDOMServer;
7
1
  export const serialize = node => {
8
2
  try {
9
- if (Text.isText(node)) {
10
- let string = getMarked(node, node.text);
11
- string = renderToString(string);
12
- return string;
3
+ if (!node?.type && node?.text) {
4
+ return node?.text;
13
5
  }
14
- const children = node.children.map(n => serialize(n)).join("");
15
- let block = getBlock({
16
- children,
17
- element: node
18
- });
19
- block = renderToString(block);
6
+ let n = Array.isArray(node) ? node : node?.children;
7
+ n = n && Array.isArray(n) ? n : n ? [n] : [];
8
+ let block = n.map(m => {
9
+ return serialize(m);
10
+ }).join(' ');
20
11
  return block;
21
12
  } catch (err) {
22
13
  console.log(err);
23
14
  return null;
24
15
  }
25
- };
26
- export const serializer = editorValue => {
27
- if (editorValue.length > 0) {
28
- return editorValue.map(n => serialize(n)).join("");
29
- }
30
- };
31
- export const deserializer = body => {
32
- console.log(body);
33
- };
34
- export const convertToHTML = editorWrapper => {
35
- if (editorWrapper && editorWrapper?.current) {
36
- return editorWrapper?.current;
37
- }
38
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"