authscape 1.0.738 → 1.0.742

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.
@@ -1,69 +1,47 @@
1
- import React, { useState, useEffect } from "react";
2
- import { convertToRaw, EditorState, ContentState, convertFromHTML } from "draft-js";
3
- import draftToHtml from "draftjs-to-html";
1
+ import React, { useEffect, useCallback } from "react";
4
2
  import dynamic from 'next/dynamic';
5
3
  import Box from "@mui/material/Box";
6
4
  import Button from "@mui/material/Button";
7
5
 
8
- const Editor = dynamic(
9
- () => import('react-draft-wysiwyg').then(mod => mod.Editor),
10
- { ssr: false }
11
- )
6
+ // Dynamically import the editor to avoid SSR issues
7
+ const LexicalEditor = dynamic(
8
+ () => import('./LexicalEditor').then(mod => mod.LexicalEditor),
9
+ { ssr: false }
10
+ );
12
11
 
13
- export const RichTextEditor = ({html, onSave, height = 400, isDisabled = false}) => {
14
-
15
- const [editorState, setEditorState] = useState(EditorState.createEmpty());
16
- const onEditorStateChange = function (editorState) {
17
- setEditorState(editorState);
18
- };
12
+ export const RichTextEditor = ({ html, onSave, height = 400, isDisabled = false }) => {
13
+ const [editorHtml, setEditorHtml] = React.useState(html || '');
19
14
 
20
15
  useEffect(() => {
21
-
22
- if (html != null)
23
- {
24
- const contentBlock = convertFromHTML(html);
25
- if (contentBlock) {
26
- const contentState = ContentState.createFromBlockArray(contentBlock.contentBlocks);
27
- const editorState = EditorState.createWithContent(contentState);
28
- setEditorState(editorState);
29
- }
16
+ if (html != null) {
17
+ setEditorHtml(html);
30
18
  }
19
+ }, [html]);
20
+
21
+ const handleChange = useCallback((newHtml) => {
22
+ setEditorHtml(newHtml);
23
+ }, []);
31
24
 
32
- }, [html])
33
-
34
25
  return (
35
26
  <>
36
- <Editor
37
- editorState={editorState}
38
- toolbarClassName="toolbarClassName"
39
- wrapperClassName="wrapperClassName"
40
- editorClassName="editorClassName"
41
- readOnly={isDisabled}
42
- editorStyle={{height:height}}
43
- onEditorStateChange={onEditorStateChange}
44
- // mention={{
45
- // separator: " ",
46
- // trigger: "@",
47
- // suggestions: [
48
- // { text: "APPLE", value: "apple" },
49
- // { text: "BANANA", value: "banana", url: "banana" },
50
- // { text: "CHERRY", value: "cherry", url: "cherry" },
51
- // { text: "DURIAN", value: "durian", url: "durian" },
52
- // { text: "EGGFRUIT", value: "eggfruit", url: "eggfruit" },
53
- // { text: "FIG", value: "fig", url: "fig" },
54
- // { text: "GRAPEFRUIT", value: "grapefruit", url: "grapefruit" },
55
- // { text: "HONEYDEW", value: "honeydew", url: "honeydew" }
56
- // ]
57
- // }}
27
+ <LexicalEditor
28
+ initialHtml={html}
29
+ onChange={handleChange}
30
+ height={height}
31
+ isDisabled={isDisabled}
58
32
  />
59
- <hr/>
60
- <Box sx={{textAlign:"right"}}>
61
- <Button variant="contained" disabled={isDisabled} onClick={async () => {
62
-
63
- await onSave(draftToHtml(convertToRaw(editorState.getCurrentContent())));
64
-
65
- }}>Save</Button>
66
- </Box>
33
+ <hr />
34
+ <Box sx={{ textAlign: "right" }}>
35
+ <Button
36
+ variant="contained"
37
+ disabled={isDisabled}
38
+ onClick={async () => {
39
+ await onSave(editorHtml);
40
+ }}
41
+ >
42
+ Save
43
+ </Button>
44
+ </Box>
67
45
  </>
68
46
  );
69
- }
47
+ };