@flozy/editor 1.1.8 → 1.2.0

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.
@@ -91,7 +91,7 @@ const CollaborativeEditor = props => {
91
91
  });
92
92
  provider.on("authenticationFailed", () => {
93
93
  setAuthenticated({
94
- status: false,
94
+ status: 'error',
95
95
  scope: null
96
96
  });
97
97
  });
@@ -107,7 +107,12 @@ const CollaborativeEditor = props => {
107
107
  setConnected(false);
108
108
  setMessage("Seems your connection is lost... Reload the page to edit the document...");
109
109
  });
110
- if (authenticated.status === null || !connected === null || !editor) {
110
+ if (authenticated.status === 'error') {
111
+ return /*#__PURE__*/_jsx("h1", {
112
+ "data-status": connected,
113
+ children: "Authentication Error"
114
+ });
115
+ } else if (authenticated.status === null || !connected === null || !editor) {
111
116
  return /*#__PURE__*/_jsx("h1", {
112
117
  "data-status": connected,
113
118
  children: message || "Loading..."
@@ -1,6 +1,7 @@
1
- import React, { useCallback, useEffect, useMemo, useState } from "react";
1
+ import React, { useRef, useCallback, useEffect, useMemo, useState } from "react";
2
2
  import { createEditor } from "slate";
3
3
  import { Slate, Editable } from "slate-react";
4
+ import html2canvas from "html2canvas";
4
5
  import Toolbar from "./Toolbar/Toolbar";
5
6
  import { getMarked, getBlock } from "./utils/SlateUtilityFunctions";
6
7
  import CodeToText from "./Elements/CodeToText/CodeToText";
@@ -40,11 +41,12 @@ const CommonEditor = props => {
40
41
  otherProps,
41
42
  timeoutInMS = 1000
42
43
  } = props;
44
+ const editorWrapper = useRef();
43
45
  const convertedContent = draftToSlate({
44
46
  data: content
45
47
  });
46
48
  const [value, setValue] = useState(convertedContent);
47
- const [lastUpdated, setLastUpdated] = useState(value);
49
+ const [lastUpdated, setLastUpdated] = useState(JSON.stringify(convertedContent));
48
50
  const [count] = useTimeout({
49
51
  timeoutInMS: timeoutInMS
50
52
  });
@@ -102,11 +104,19 @@ const CommonEditor = props => {
102
104
  };
103
105
  const updateChanges = newValue => {
104
106
  const stringify = JSON.stringify(newValue);
105
- if (stringify !== lastUpdated) {
106
- onSave(stringify, {
107
- text: serialize(newValue)
108
- });
109
- setLastUpdated(stringify);
107
+ const text = serialize(newValue);
108
+ if (stringify !== lastUpdated && count > 0 && text?.trim().length > 3 && onSave) {
109
+ if (editorWrapper && editorWrapper?.current) {
110
+ html2canvas(editorWrapper?.current, {
111
+ height: 350
112
+ }).then(c => {
113
+ onSave(stringify, {
114
+ text: text,
115
+ thumbnail: c.toDataURL()
116
+ });
117
+ setLastUpdated(stringify);
118
+ });
119
+ }
110
120
  }
111
121
  };
112
122
  const customProps = {
@@ -168,6 +178,7 @@ const CommonEditor = props => {
168
178
  handleCodeToText: handleCodeToText,
169
179
  customProps: customProps
170
180
  }) : null, /*#__PURE__*/_jsxs("div", {
181
+ ref: editorWrapper,
171
182
  className: "editor-wrapper",
172
183
  style: {
173
184
  border: "1px solid #f3f3f3",
@@ -4,7 +4,7 @@ const useTimeout = props => {
4
4
  const {
5
5
  timeoutInMS
6
6
  } = props;
7
- const [count, setCount] = useState(0);
7
+ const [count, setCount] = useState(-1);
8
8
  const onReset = () => {
9
9
  clearTimeout(t);
10
10
  t = setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"
@@ -18,6 +18,7 @@
18
18
  "@testing-library/jest-dom": "^5.16.5",
19
19
  "@testing-library/react": "^13.4.0",
20
20
  "@testing-library/user-event": "^13.5.0",
21
+ "html2canvas": "^1.4.1",
21
22
  "husky": "^8.0.3",
22
23
  "interweave": "^13.1.0",
23
24
  "lint-staged": "^13.2.3",