@flozy/editor 1.0.0 → 1.0.6
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.
- package/build/asset-manifest.json +14 -0
- package/build/index.html +1 -0
- package/build/static/css/main.71100b24.css +2 -0
- package/build/static/css/main.71100b24.css.map +1 -0
- package/build/static/js/main.dd36b23b.js +3 -0
- package/build/static/js/main.dd36b23b.js.LICENSE.txt +19 -0
- package/build/static/js/main.dd36b23b.js.map +1 -0
- package/package.json +6 -2
- package/.eslintignore +0 -4
- package/.eslintrc.json +0 -6
- package/.github/workflows/npm-publish.yml +0 -33
- package/.husky/pre-commit +0 -1
- package/.storybook/main.js +0 -20
- package/.storybook/preview.js +0 -14
- package/.vscode/extensions.json +0 -7
- package/.vscode/launch.json +0 -15
- package/.vscode/settings.json +0 -22
- package/craco.config.js +0 -16
- package/public/index.html +0 -43
- package/src/components/Editor/CollaborativeEditor.js +0 -119
- package/src/components/Editor/CommonEditor.js +0 -549
- package/src/components/Editor/Editor.css +0 -115
- package/src/components/Editor/Elements/CodeToText/CodeToText.css +0 -57
- package/src/components/Editor/Elements/CodeToText/CodeToText.jsx +0 -115
- package/src/components/Editor/Elements/CodeToText/CodeToTextButton.jsx +0 -16
- package/src/components/Editor/Elements/CodeToText/HtmlCode.jsx +0 -59
- package/src/components/Editor/Elements/CodeToText/HtmlContextMenu.jsx +0 -39
- package/src/components/Editor/Elements/Color Picker/ColorPicker.css +0 -38
- package/src/components/Editor/Elements/Color Picker/ColorPicker.jsx +0 -110
- package/src/components/Editor/Elements/Color Picker/defaultColors.js +0 -34
- package/src/components/Editor/Elements/Embed/Embed.css +0 -14
- package/src/components/Editor/Elements/Embed/Embed.jsx +0 -74
- package/src/components/Editor/Elements/Embed/Image.jsx +0 -82
- package/src/components/Editor/Elements/Embed/Video.jsx +0 -65
- package/src/components/Editor/Elements/Equation/Equation.jsx +0 -19
- package/src/components/Editor/Elements/Equation/EquationButton.jsx +0 -59
- package/src/components/Editor/Elements/Equation/styles.css +0 -4
- package/src/components/Editor/Elements/Grid/Grid.js +0 -48
- package/src/components/Editor/Elements/Grid/GridButton.js +0 -21
- package/src/components/Editor/Elements/Grid/GridItem.js +0 -57
- package/src/components/Editor/Elements/ID/Id.jsx +0 -56
- package/src/components/Editor/Elements/Link/Link.jsx +0 -24
- package/src/components/Editor/Elements/Link/LinkButton.jsx +0 -71
- package/src/components/Editor/Elements/Link/styles.css +0 -20
- package/src/components/Editor/Elements/Mentions/Mentions.jsx +0 -37
- package/src/components/Editor/Elements/NewLine/NewLineButton.js +0 -29
- package/src/components/Editor/Elements/Table/Table.jsx +0 -13
- package/src/components/Editor/Elements/Table/TableSelector.css +0 -18
- package/src/components/Editor/Elements/Table/TableSelector.jsx +0 -76
- package/src/components/Editor/Elements/TableContextMenu/TableContextMenu.jsx +0 -97
- package/src/components/Editor/Elements/TableContextMenu/styles.css +0 -18
- package/src/components/Editor/RemoteCursorOverlay/Overlay.js +0 -78
- package/src/components/Editor/Toolbar/Toolbar.jsx +0 -167
- package/src/components/Editor/Toolbar/styles.css +0 -28
- package/src/components/Editor/Toolbar/toolbarGroups.js +0 -167
- package/src/components/Editor/Toolbar/toolbarIcons/align-center.svg +0 -1
- package/src/components/Editor/Toolbar/toolbarIcons/align-left.svg +0 -1
- package/src/components/Editor/Toolbar/toolbarIcons/align-right.svg +0 -1
- package/src/components/Editor/Toolbar/toolbarIcons/blockquote.svg +0 -1
- package/src/components/Editor/Toolbar/toolbarIcons/bold.png +0 -0
- package/src/components/Editor/Toolbar/toolbarIcons/fontColor.svg +0 -4
- package/src/components/Editor/Toolbar/toolbarIcons/headingOne.svg +0 -3
- package/src/components/Editor/Toolbar/toolbarIcons/headingTwo.svg +0 -3
- package/src/components/Editor/Toolbar/toolbarIcons/italic.png +0 -0
- package/src/components/Editor/Toolbar/toolbarIcons/link.svg +0 -1
- package/src/components/Editor/Toolbar/toolbarIcons/orderedList.svg +0 -1
- package/src/components/Editor/Toolbar/toolbarIcons/strikethrough.png +0 -0
- package/src/components/Editor/Toolbar/toolbarIcons/subscript.svg +0 -1
- package/src/components/Editor/Toolbar/toolbarIcons/superscript.svg +0 -1
- package/src/components/Editor/Toolbar/toolbarIcons/textColor.png +0 -0
- package/src/components/Editor/Toolbar/toolbarIcons/underline.png +0 -0
- package/src/components/Editor/Toolbar/toolbarIcons/unorderedList.svg +0 -1
- package/src/components/Editor/YjsProvider.js +0 -11
- package/src/components/Editor/common/Button.jsx +0 -12
- package/src/components/Editor/common/Icon.jsx +0 -82
- package/src/components/Editor/common/MentionsPopup.jsx +0 -56
- package/src/components/Editor/hooks/useMentions.js +0 -44
- package/src/components/Editor/hooks/withCollaborative.js +0 -15
- package/src/components/Editor/hooks/withCommon.js +0 -17
- package/src/components/Editor/plugins/withEmbeds.js +0 -36
- package/src/components/Editor/plugins/withEquation.js +0 -8
- package/src/components/Editor/plugins/withLinks.js +0 -9
- package/src/components/Editor/plugins/withMentions.js +0 -19
- package/src/components/Editor/plugins/withTable.js +0 -74
- package/src/components/Editor/utils/SlateUtilityFunctions.js +0 -273
- package/src/components/Editor/utils/customHooks/useContextMenu.js +0 -42
- package/src/components/Editor/utils/customHooks/useFormat.js +0 -26
- package/src/components/Editor/utils/customHooks/usePopup.jsx +0 -26
- package/src/components/Editor/utils/customHooks/useResize.js +0 -41
- package/src/components/Editor/utils/draftToSlate.js +0 -104
- package/src/components/Editor/utils/embed.js +0 -18
- package/src/components/Editor/utils/equation.js +0 -22
- package/src/components/Editor/utils/events.js +0 -56
- package/src/components/Editor/utils/grid.js +0 -12
- package/src/components/Editor/utils/gridItem.js +0 -19
- package/src/components/Editor/utils/link.js +0 -53
- package/src/components/Editor/utils/mentions.js +0 -11
- package/src/components/Editor/utils/paragraph.js +0 -4
- package/src/components/Editor/utils/serializer.js +0 -32
- package/src/components/Editor/utils/table.js +0 -151
- package/src/components/index.js +0 -5
- package/src/index.js +0 -1
- package/src/stories/CollaborativeEditor.stories.js +0 -30
- package/src/stories/Editor.stories.js +0 -24
- package/src/stories/EditorSampleProps/ChatSample.js +0 -43
- package/src/stories/EditorSampleProps/LayoutOne.js +0 -551
- /package/{public → build}/favicon.ico +0 -0
- /package/{public → build}/logo192.png +0 -0
- /package/{public → build}/logo512.png +0 -0
- /package/{public → build}/manifest.json +0 -0
- /package/{public → build}/robots.txt +0 -0
- /package/{src/components/Editor/Toolbar/toolbarIcons/unlink.svg → build/static/media/unlink.b8761030d4a17499149d2d61adc064b3.svg} +0 -0
@@ -1,44 +0,0 @@
|
|
1
|
-
import { useEffect, useState } from "react";
|
2
|
-
import { Editor, Range } from "slate";
|
3
|
-
|
4
|
-
const useMentions = (props) => {
|
5
|
-
const { editor, selection } = props;
|
6
|
-
const [mentions, setMentions] = useState({
|
7
|
-
target: null,
|
8
|
-
index: null,
|
9
|
-
search: null,
|
10
|
-
});
|
11
|
-
|
12
|
-
useEffect(() => {
|
13
|
-
if (selection && Range.isCollapsed(selection)) {
|
14
|
-
const [start] = Range.edges(selection);
|
15
|
-
const wordBefore = Editor.before(editor, start, { unit: "word" });
|
16
|
-
const before = wordBefore && Editor.before(editor, wordBefore);
|
17
|
-
const beforeRange = before && Editor.range(editor, before, start);
|
18
|
-
const beforeText = beforeRange && Editor.string(editor, beforeRange);
|
19
|
-
const beforeMatch = beforeText && beforeText.match(/^@(\w+)$/);
|
20
|
-
const after = Editor.after(editor, start);
|
21
|
-
const afterRange = Editor.range(editor, start, after);
|
22
|
-
const afterText = Editor.string(editor, afterRange);
|
23
|
-
const afterMatch = afterText.match(/^(\s|$)/);
|
24
|
-
|
25
|
-
if (beforeMatch && afterMatch) {
|
26
|
-
setMentions({
|
27
|
-
target: beforeRange,
|
28
|
-
search: beforeMatch[1],
|
29
|
-
index: 0,
|
30
|
-
});
|
31
|
-
}
|
32
|
-
} else {
|
33
|
-
setMentions({
|
34
|
-
target: null,
|
35
|
-
search: null,
|
36
|
-
index: null,
|
37
|
-
});
|
38
|
-
}
|
39
|
-
}, [selection, editor]);
|
40
|
-
|
41
|
-
return [mentions, setMentions];
|
42
|
-
};
|
43
|
-
|
44
|
-
export default useMentions;
|
@@ -1,15 +0,0 @@
|
|
1
|
-
import { createEditor } from "slate";
|
2
|
-
import { withYjs, withCursors } from "@slate-yjs/core";
|
3
|
-
|
4
|
-
const withCollaborative = (props) => {
|
5
|
-
const { provider, sharedType, data } = props;
|
6
|
-
return withCursors(
|
7
|
-
withYjs(createEditor(), sharedType, { autoConnect: false }),
|
8
|
-
provider.awareness,
|
9
|
-
{
|
10
|
-
data,
|
11
|
-
}
|
12
|
-
);
|
13
|
-
};
|
14
|
-
|
15
|
-
export default withCollaborative;
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import { withReact } from "slate-react";
|
2
|
-
import { withHistory } from "slate-history";
|
3
|
-
import withLinks from "../plugins/withLinks";
|
4
|
-
import withTables from "../plugins/withTable";
|
5
|
-
import withEmbeds from "../plugins/withEmbeds";
|
6
|
-
import withEquation from "../plugins/withEquation";
|
7
|
-
import withMentions from "../plugins/withMentions";
|
8
|
-
|
9
|
-
const withCommon = (props) => {
|
10
|
-
return withEquation(
|
11
|
-
withHistory(
|
12
|
-
withEmbeds(withTables(withLinks(withMentions(withReact(props)))))
|
13
|
-
)
|
14
|
-
);
|
15
|
-
};
|
16
|
-
|
17
|
-
export default withCommon;
|
@@ -1,36 +0,0 @@
|
|
1
|
-
import {Transforms, Path, Node} from 'slate'
|
2
|
-
|
3
|
-
const withEmbeds = (editor) =>{
|
4
|
-
|
5
|
-
const { isVoid, insertBreak } = editor;
|
6
|
-
|
7
|
-
editor.isVoid = (element) => ['video','image','htmlCode'].includes(element.type) ? true : isVoid(element);
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
editor.insertBreak = (...args) => {
|
12
|
-
const parentPath = Path.parent(editor.selection.focus.path);
|
13
|
-
const parentNode = Node.get(editor, parentPath);
|
14
|
-
// console.log(parentNode);
|
15
|
-
if (editor.isVoid(parentNode)) {
|
16
|
-
const nextPath = Path.next(parentPath);
|
17
|
-
Transforms.insertNodes(
|
18
|
-
editor,
|
19
|
-
{
|
20
|
-
type: 'paragraph',
|
21
|
-
children: [{ text: '' }]
|
22
|
-
},
|
23
|
-
{
|
24
|
-
at: nextPath,
|
25
|
-
select: true // Focus on this node once inserted
|
26
|
-
}
|
27
|
-
);
|
28
|
-
} else {
|
29
|
-
insertBreak(...args);
|
30
|
-
}
|
31
|
-
}
|
32
|
-
return editor;
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
export default withEmbeds
|
@@ -1,19 +0,0 @@
|
|
1
|
-
const withMentions = (editor) => {
|
2
|
-
const { isInline, isVoid, markableVoid } = editor;
|
3
|
-
|
4
|
-
editor.isInline = (element) => {
|
5
|
-
return element.type === "mention" ? true : isInline(element);
|
6
|
-
};
|
7
|
-
|
8
|
-
editor.isVoid = (element) => {
|
9
|
-
return element.type === "mention" ? true : isVoid(element);
|
10
|
-
};
|
11
|
-
|
12
|
-
editor.markableVoid = (element) => {
|
13
|
-
return element.type === "mention" || markableVoid(element);
|
14
|
-
};
|
15
|
-
|
16
|
-
return editor;
|
17
|
-
};
|
18
|
-
|
19
|
-
export default withMentions;
|
@@ -1,74 +0,0 @@
|
|
1
|
-
import { Editor, Range, Point, Element } from "slate";
|
2
|
-
|
3
|
-
const withTable = (editor) => {
|
4
|
-
const { deleteBackward, deleteForward } = editor;
|
5
|
-
|
6
|
-
editor.deleteBackward = (unit) => {
|
7
|
-
const { selection } = editor;
|
8
|
-
if (selection) {
|
9
|
-
const [cell] = Editor.nodes(editor, {
|
10
|
-
match: (n) =>
|
11
|
-
!Editor.isEditor(n) &&
|
12
|
-
Element.isElement(n) &&
|
13
|
-
n.type === "table-cell",
|
14
|
-
});
|
15
|
-
const prevNodePath = Editor.before(editor, selection);
|
16
|
-
|
17
|
-
const [tableNode] = Editor.nodes(editor, {
|
18
|
-
at: prevNodePath,
|
19
|
-
match: (n) =>
|
20
|
-
!Editor.isEditor(n) && Element.isElement && n.type === "table-cell",
|
21
|
-
});
|
22
|
-
|
23
|
-
if (cell) {
|
24
|
-
const [, cellPath] = cell;
|
25
|
-
|
26
|
-
const start = Editor.start(editor, cellPath);
|
27
|
-
if (Point.equals(selection.anchor, start)) {
|
28
|
-
return;
|
29
|
-
}
|
30
|
-
}
|
31
|
-
if (!cell && tableNode) {
|
32
|
-
return;
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
deleteBackward(unit);
|
37
|
-
};
|
38
|
-
editor.deleteForward = (unit) => {
|
39
|
-
const { selection } = editor;
|
40
|
-
if (selection && Range.isCollapsed(selection)) {
|
41
|
-
const [cell] = Editor.nodes(editor, {
|
42
|
-
match: (n) =>
|
43
|
-
!Editor.isEditor(n) &&
|
44
|
-
Element.isElement(n) &&
|
45
|
-
n.type === "table-cell",
|
46
|
-
});
|
47
|
-
|
48
|
-
const prevNodePath = Editor.after(editor, selection);
|
49
|
-
const [tableNode] = Editor.nodes(editor, {
|
50
|
-
at: prevNodePath,
|
51
|
-
match: (n) =>
|
52
|
-
!Editor.isEditor(n) && Element.isElement && n.type === "table-cell",
|
53
|
-
});
|
54
|
-
|
55
|
-
if (cell) {
|
56
|
-
const [, cellPath] = cell;
|
57
|
-
const end = Editor.end(editor, cellPath);
|
58
|
-
|
59
|
-
if (Point.equals(selection.anchor, end)) {
|
60
|
-
return;
|
61
|
-
}
|
62
|
-
}
|
63
|
-
if (!cell && tableNode) {
|
64
|
-
return;
|
65
|
-
}
|
66
|
-
}
|
67
|
-
|
68
|
-
deleteForward(unit);
|
69
|
-
};
|
70
|
-
|
71
|
-
return editor;
|
72
|
-
};
|
73
|
-
|
74
|
-
export default withTable;
|
@@ -1,273 +0,0 @@
|
|
1
|
-
import { Editor, Transforms, Element as SlateElement } from "slate";
|
2
|
-
import Link from "../Elements/Link/Link";
|
3
|
-
import Image from "../Elements/Embed/Image";
|
4
|
-
import Video from "../Elements/Embed/Video";
|
5
|
-
import Equation from "../Elements/Equation/Equation";
|
6
|
-
import HtmlCode from "../Elements/CodeToText/HtmlCode";
|
7
|
-
import Table from "../Elements/Table/Table";
|
8
|
-
import Mentions from "../Elements/Mentions/Mentions";
|
9
|
-
import Grid from "../Elements/Grid/Grid";
|
10
|
-
import GridItem from "../Elements/Grid/GridItem";
|
11
|
-
|
12
|
-
const alignment = ["alignLeft", "alignRight", "alignCenter"];
|
13
|
-
const list_types = ["orderedList", "unorderedList"];
|
14
|
-
|
15
|
-
export const sizeMap = {
|
16
|
-
small: "0.75em",
|
17
|
-
normal: "1em",
|
18
|
-
medium: "1.75em",
|
19
|
-
huge: "2.5em",
|
20
|
-
};
|
21
|
-
export const fontFamilyMap = {
|
22
|
-
sans: "Helvetica,Arial, sans serif",
|
23
|
-
serif: "Georgia, Times New Roaman,serif",
|
24
|
-
monospace: "Monaco, Courier New,monospace",
|
25
|
-
};
|
26
|
-
export const toggleBlock = (editor, format) => {
|
27
|
-
const isActive = isBlockActive(editor, format);
|
28
|
-
const isList = list_types.includes(format);
|
29
|
-
const isIndent = alignment.includes(format);
|
30
|
-
const isAligned = alignment.some((alignmentType) =>
|
31
|
-
isBlockActive(editor, alignmentType)
|
32
|
-
);
|
33
|
-
|
34
|
-
/*If the node is already aligned and change in indent is called we should unwrap it first and split the node to prevent
|
35
|
-
messy, nested DOM structure and bugs due to that.*/
|
36
|
-
if (isAligned && isIndent) {
|
37
|
-
Transforms.unwrapNodes(editor, {
|
38
|
-
match: (n) =>
|
39
|
-
alignment.includes(
|
40
|
-
!Editor.isEditor(n) && SlateElement.isElement(n) && n.type
|
41
|
-
),
|
42
|
-
split: true,
|
43
|
-
});
|
44
|
-
}
|
45
|
-
|
46
|
-
/* Wraping the nodes for alignment, to allow it to co-exist with other block level operations*/
|
47
|
-
if (isIndent) {
|
48
|
-
Transforms.wrapNodes(editor, {
|
49
|
-
type: format,
|
50
|
-
children: [],
|
51
|
-
});
|
52
|
-
return;
|
53
|
-
}
|
54
|
-
Transforms.unwrapNodes(editor, {
|
55
|
-
match: (n) =>
|
56
|
-
list_types.includes(
|
57
|
-
!Editor.isEditor(n) && SlateElement.isElement(n) && n.type
|
58
|
-
),
|
59
|
-
split: true,
|
60
|
-
});
|
61
|
-
|
62
|
-
Transforms.setNodes(editor, {
|
63
|
-
type: isActive ? "paragraph" : isList ? "list-item" : format,
|
64
|
-
});
|
65
|
-
|
66
|
-
if (isList && !isActive) {
|
67
|
-
Transforms.wrapNodes(editor, {
|
68
|
-
type: format,
|
69
|
-
children: [],
|
70
|
-
});
|
71
|
-
}
|
72
|
-
};
|
73
|
-
export const addMarkData = (editor, data) => {
|
74
|
-
Editor.addMark(editor, data.format, data.value);
|
75
|
-
};
|
76
|
-
export const toggleMark = (editor, format) => {
|
77
|
-
const isActive = isMarkActive(editor, format);
|
78
|
-
|
79
|
-
if (isActive) {
|
80
|
-
Editor.removeMark(editor, format);
|
81
|
-
} else {
|
82
|
-
Editor.addMark(editor, format, true);
|
83
|
-
}
|
84
|
-
};
|
85
|
-
export const isMarkActive = (editor, format) => {
|
86
|
-
const marks = Editor.marks(editor);
|
87
|
-
|
88
|
-
return marks ? marks[format] === true : false;
|
89
|
-
};
|
90
|
-
|
91
|
-
export const isBlockActive = (editor, format) => {
|
92
|
-
const [match] = Editor.nodes(editor, {
|
93
|
-
match: (n) =>
|
94
|
-
!Editor.isEditor(n) && SlateElement.isElement(n) && n.type === format,
|
95
|
-
});
|
96
|
-
|
97
|
-
return !!match;
|
98
|
-
};
|
99
|
-
|
100
|
-
export const activeMark = (editor, format) => {
|
101
|
-
const defaultMarkData = {
|
102
|
-
color: "black",
|
103
|
-
bgColor: "black",
|
104
|
-
fontSize: "normal",
|
105
|
-
fontFamily: "sans",
|
106
|
-
};
|
107
|
-
const marks = Editor.marks(editor);
|
108
|
-
const defaultValue = defaultMarkData[format];
|
109
|
-
return marks?.[format] ?? defaultValue;
|
110
|
-
};
|
111
|
-
|
112
|
-
export const getMarked = (leaf, children) => {
|
113
|
-
if (leaf.bold) {
|
114
|
-
children = <strong>{children}</strong>;
|
115
|
-
}
|
116
|
-
|
117
|
-
if (leaf.code) {
|
118
|
-
children = <code>{children}</code>;
|
119
|
-
}
|
120
|
-
|
121
|
-
if (leaf.italic) {
|
122
|
-
children = <em>{children}</em>;
|
123
|
-
}
|
124
|
-
if (leaf.strikethrough) {
|
125
|
-
children = (
|
126
|
-
<span style={{ textDecoration: "line-through" }}>{children}</span>
|
127
|
-
);
|
128
|
-
}
|
129
|
-
if (leaf.underline) {
|
130
|
-
children = <u>{children}</u>;
|
131
|
-
}
|
132
|
-
if (leaf.superscript) {
|
133
|
-
children = <sup>{children}</sup>;
|
134
|
-
}
|
135
|
-
if (leaf.subscript) {
|
136
|
-
children = <sub>{children}</sub>;
|
137
|
-
}
|
138
|
-
if (leaf.color) {
|
139
|
-
children = <span style={{ color: leaf.color }}>{children}</span>;
|
140
|
-
}
|
141
|
-
if (leaf.bgColor) {
|
142
|
-
children = (
|
143
|
-
<span style={{ backgroundColor: leaf.bgColor }}>{children}</span>
|
144
|
-
);
|
145
|
-
}
|
146
|
-
if (leaf.fontSize) {
|
147
|
-
const size = sizeMap[leaf.fontSize];
|
148
|
-
children = <span style={{ fontSize: size }}>{children}</span>;
|
149
|
-
}
|
150
|
-
if (leaf.fontFamily) {
|
151
|
-
const family = fontFamilyMap[leaf.fontFamily];
|
152
|
-
children = <span style={{ fontFamily: family }}>{children}</span>;
|
153
|
-
}
|
154
|
-
return children;
|
155
|
-
};
|
156
|
-
|
157
|
-
export const getBlock = (props) => {
|
158
|
-
const { element, children } = props;
|
159
|
-
const attributes = props.attributes ?? {};
|
160
|
-
|
161
|
-
switch (element.type) {
|
162
|
-
case "headingOne":
|
163
|
-
return (
|
164
|
-
<h1 {...attributes} {...element.attr}>
|
165
|
-
{children}
|
166
|
-
</h1>
|
167
|
-
);
|
168
|
-
case "headingTwo":
|
169
|
-
return (
|
170
|
-
<h2 {...attributes} {...element.attr}>
|
171
|
-
{children}
|
172
|
-
</h2>
|
173
|
-
);
|
174
|
-
case "headingThree":
|
175
|
-
return (
|
176
|
-
<h3 {...attributes} {...element.attr}>
|
177
|
-
{children}
|
178
|
-
</h3>
|
179
|
-
);
|
180
|
-
case "blockquote":
|
181
|
-
return (
|
182
|
-
<blockquote {...attributes} {...element.attr}>
|
183
|
-
{children}
|
184
|
-
</blockquote>
|
185
|
-
);
|
186
|
-
case "alignLeft":
|
187
|
-
return (
|
188
|
-
<div
|
189
|
-
style={{ listStylePosition: "inside" }}
|
190
|
-
{...attributes}
|
191
|
-
{...element.attr}
|
192
|
-
>
|
193
|
-
{children}
|
194
|
-
</div>
|
195
|
-
);
|
196
|
-
case "alignCenter":
|
197
|
-
return (
|
198
|
-
<div
|
199
|
-
style={{
|
200
|
-
display: "flex",
|
201
|
-
alignItems: "center",
|
202
|
-
listStylePosition: "inside",
|
203
|
-
flexDirection: "column",
|
204
|
-
}}
|
205
|
-
{...attributes}
|
206
|
-
{...element.attr}
|
207
|
-
>
|
208
|
-
{children}
|
209
|
-
</div>
|
210
|
-
);
|
211
|
-
case "alignRight":
|
212
|
-
return (
|
213
|
-
<div
|
214
|
-
style={{
|
215
|
-
display: "flex",
|
216
|
-
alignItems: "flex-end",
|
217
|
-
listStylePosition: "inside",
|
218
|
-
flexDirection: "column",
|
219
|
-
}}
|
220
|
-
{...attributes}
|
221
|
-
{...element.attr}
|
222
|
-
>
|
223
|
-
{children}
|
224
|
-
</div>
|
225
|
-
);
|
226
|
-
case "list-item":
|
227
|
-
return (
|
228
|
-
<li {...attributes} {...element.attr}>
|
229
|
-
{children}
|
230
|
-
</li>
|
231
|
-
);
|
232
|
-
case "orderedList":
|
233
|
-
return (
|
234
|
-
<ol type="1" {...attributes}>
|
235
|
-
{children}
|
236
|
-
</ol>
|
237
|
-
);
|
238
|
-
case "unorderedList":
|
239
|
-
return <ul {...attributes}>{children}</ul>;
|
240
|
-
case "link":
|
241
|
-
return <Link {...props} />;
|
242
|
-
case "table":
|
243
|
-
return <Table {...props} />;
|
244
|
-
case "table-row":
|
245
|
-
return <tr {...attributes}>{children}</tr>;
|
246
|
-
case "table-cell":
|
247
|
-
return (
|
248
|
-
<td {...element.attr} {...attributes}>
|
249
|
-
{children}
|
250
|
-
</td>
|
251
|
-
);
|
252
|
-
case "image":
|
253
|
-
return <Image {...props} />;
|
254
|
-
case "video":
|
255
|
-
return <Video {...props} />;
|
256
|
-
case "equation":
|
257
|
-
return <Equation {...props} />;
|
258
|
-
case "htmlCode":
|
259
|
-
return <HtmlCode {...props} />;
|
260
|
-
case "mention":
|
261
|
-
return <Mentions {...props} />;
|
262
|
-
case "grid":
|
263
|
-
return <Grid {...props} />;
|
264
|
-
case "grid-item":
|
265
|
-
return <GridItem {...props} />;
|
266
|
-
default:
|
267
|
-
return (
|
268
|
-
<div {...element.attr} {...attributes}>
|
269
|
-
{children}
|
270
|
-
</div>
|
271
|
-
);
|
272
|
-
}
|
273
|
-
};
|
@@ -1,42 +0,0 @@
|
|
1
|
-
import { useState, useEffect } from 'react';
|
2
|
-
import useFormat from './useFormat.js';
|
3
|
-
|
4
|
-
|
5
|
-
//This hook returns should we show the custom context menu and where to show it.
|
6
|
-
const useContextMenu = (editor,format,setSelection) => {
|
7
|
-
const isFormat = useFormat(editor,format);
|
8
|
-
const [showMenu,setShowMenu] = useState(false);
|
9
|
-
const [menuLocation,setMenuLocation] = useState({
|
10
|
-
top:'0px',
|
11
|
-
left:'0px'
|
12
|
-
});
|
13
|
-
|
14
|
-
const handleClick = ()=>{
|
15
|
-
setShowMenu(false);
|
16
|
-
}
|
17
|
-
const handleContextMenu = (e) => {
|
18
|
-
if(!isFormat) return;
|
19
|
-
setSelection(editor.selection);
|
20
|
-
e.preventDefault();
|
21
|
-
setShowMenu(true);
|
22
|
-
const xPos = e.pageX + "px";
|
23
|
-
const yPos = e.pageY + "px";
|
24
|
-
setMenuLocation({
|
25
|
-
top:yPos,
|
26
|
-
left:xPos
|
27
|
-
})
|
28
|
-
}
|
29
|
-
useEffect(()=>{
|
30
|
-
document.addEventListener('click',handleClick);
|
31
|
-
document.addEventListener('contextmenu',handleContextMenu);
|
32
|
-
|
33
|
-
return ()=>{
|
34
|
-
document.removeEventListener('click',handleClick);
|
35
|
-
document.removeEventListener('contextmenu',handleContextMenu);
|
36
|
-
}
|
37
|
-
},[isFormat])
|
38
|
-
|
39
|
-
return [showMenu,menuLocation];
|
40
|
-
}
|
41
|
-
|
42
|
-
export default useContextMenu;
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import { useEffect, useState } from 'react';
|
2
|
-
import { Editor, Element } from 'slate'
|
3
|
-
|
4
|
-
|
5
|
-
// This hook returns if the node in the current selection matches the format passed to it.
|
6
|
-
const useFormat = (editor,format)=>{
|
7
|
-
const [isFormat,setIsFormat] = useState(false);
|
8
|
-
useEffect(()=>{
|
9
|
-
if(editor.selection){
|
10
|
-
// It matches at the editor.selection location by default, so if null handle it seperately.
|
11
|
-
const [node] = Editor.nodes(editor,{
|
12
|
-
match:n => !Editor.isEditor(n) && Element.isElement(n) && n.type === format
|
13
|
-
})
|
14
|
-
|
15
|
-
setIsFormat(!!node);
|
16
|
-
}
|
17
|
-
else{
|
18
|
-
setIsFormat(false);
|
19
|
-
}
|
20
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
21
|
-
},[editor.selection])
|
22
|
-
|
23
|
-
return isFormat;
|
24
|
-
}
|
25
|
-
|
26
|
-
export default useFormat;
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import { useState, useEffect } from 'react'
|
2
|
-
|
3
|
-
//This hook returns if the click was inside the popUp ref or outside it .
|
4
|
-
function usePopup(popupRef) {
|
5
|
-
const [showPopup,setShowPopup] = useState(false);
|
6
|
-
|
7
|
-
useEffect(()=>{
|
8
|
-
const handleDocumentClick = (e)=>{
|
9
|
-
const clickedComponent = e.target;
|
10
|
-
if(!popupRef?.current?.contains(clickedComponent)){
|
11
|
-
setShowPopup(false);
|
12
|
-
}
|
13
|
-
}
|
14
|
-
document.addEventListener('click',handleDocumentClick);
|
15
|
-
|
16
|
-
return ()=>{
|
17
|
-
document.removeEventListener('click',handleDocumentClick)
|
18
|
-
}
|
19
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
20
|
-
}, [])
|
21
|
-
|
22
|
-
return [showPopup,setShowPopup];
|
23
|
-
}
|
24
|
-
|
25
|
-
export default usePopup
|
26
|
-
|
@@ -1,41 +0,0 @@
|
|
1
|
-
import { useState } from "react";
|
2
|
-
|
3
|
-
const useResize = ({ parentDOM, size: defaultSize }) => {
|
4
|
-
const { width } = parentDOM?.getBoundingClientRect() || { ...defaultSize };
|
5
|
-
const [size, setSize] = useState({
|
6
|
-
height: 300,
|
7
|
-
widthInPercent: 100,
|
8
|
-
...defaultSize,
|
9
|
-
});
|
10
|
-
const [resizing, setResizing] = useState(false);
|
11
|
-
|
12
|
-
const onLoad = (dom) => {
|
13
|
-
setSize({ widthInPercent: 100, height: 300, ...defaultSize });
|
14
|
-
};
|
15
|
-
|
16
|
-
const onMouseDown = () => {
|
17
|
-
document.addEventListener("pointermove", onMouseMove);
|
18
|
-
document.addEventListener("pointerup", onMouseUp);
|
19
|
-
setResizing(true);
|
20
|
-
};
|
21
|
-
const onMouseUp = () => {
|
22
|
-
document.removeEventListener("pointermove", onMouseMove);
|
23
|
-
document.removeEventListener("pointerup", onMouseUp);
|
24
|
-
setResizing(false);
|
25
|
-
};
|
26
|
-
const onMouseMove = (e) => {
|
27
|
-
setSize((currentSize) => {
|
28
|
-
const widthInPX = (currentSize.widthInPercent / 100) * width;
|
29
|
-
const calcWidth = widthInPX + e.movementX;
|
30
|
-
return {
|
31
|
-
width: calcWidth,
|
32
|
-
height: currentSize.height + e.movementY,
|
33
|
-
widthInPercent: (calcWidth / width) * 100,
|
34
|
-
};
|
35
|
-
});
|
36
|
-
};
|
37
|
-
|
38
|
-
return [size, onMouseDown, resizing, onLoad];
|
39
|
-
};
|
40
|
-
|
41
|
-
export default useResize;
|