@flozy/editor 1.1.5 → 1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/Editor/CollaborativeEditor.js +6 -1
- package/dist/Editor/CommonEditor.js +17 -3
- package/dist/Editor/Editor.css +15 -3
- package/dist/Editor/Elements/AppHeader/AppHeader.js +221 -0
- package/dist/Editor/Elements/AppHeader/AppHeaderButton.js +19 -0
- package/dist/Editor/Elements/AppHeader/AppHeaderPopup.js +20 -0
- package/dist/Editor/Elements/Button/EditorButton.js +3 -3
- package/dist/Editor/Elements/Carousel/Carousel.js +19 -5
- package/dist/Editor/Elements/Carousel/CarouselItem.js +5 -1
- package/dist/Editor/Elements/ChipText/ChipText.js +44 -0
- package/dist/Editor/Elements/ChipText/ChipTextButton.js +64 -0
- package/dist/Editor/Elements/ChipText/ChipTextPopup.js +24 -0
- package/dist/Editor/Elements/DrawerMenu/DrawerMenu.js +66 -0
- package/dist/Editor/Elements/DrawerMenu/DrawerMenuButton.js +21 -0
- package/dist/Editor/Elements/Link/Link.js +5 -5
- package/dist/Editor/Elements/Link/LinkButton.js +50 -37
- package/dist/Editor/Elements/PageSettings/PageSettingsButton.js +27 -21
- package/dist/Editor/Elements/Table/Table.js +160 -10
- package/dist/Editor/Elements/Table/TableCell.js +55 -143
- package/dist/Editor/Elements/Table/table.css +13 -0
- package/dist/Editor/Toolbar/Toolbar.js +18 -0
- package/dist/Editor/Toolbar/toolbarGroups.js +9 -0
- package/dist/Editor/common/ColorPickerButton.js +65 -0
- package/dist/Editor/common/StyleBuilder/appHeaderStyle.js +63 -0
- package/dist/Editor/common/StyleBuilder/chipTextStyle.js +35 -0
- package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +8 -14
- package/dist/Editor/common/StyleBuilder/fieldTypes/index.js +3 -1
- package/dist/Editor/common/StyleBuilder/fieldTypes/menusArray.js +114 -0
- package/dist/Editor/common/StyleBuilder/index.js +8 -3
- package/dist/Editor/common/StyleBuilder/pageSettingsStyle.js +20 -0
- package/dist/Editor/plugins/withLinks.js +40 -2
- package/dist/Editor/plugins/withTable.js +10 -1
- package/dist/Editor/utils/SlateUtilityFunctions.js +15 -0
- package/dist/Editor/utils/customHooks/useTableResize.js +46 -0
- package/dist/Editor/utils/insertAppHeader.js +55 -0
- package/dist/Editor/utils/insertChipText.js +49 -0
- package/dist/Editor/utils/insertDrawerMenu.js +52 -0
- package/dist/Editor/utils/serializer.js +26 -16
- package/dist/Editor/utils/table.js +26 -3
- package/package.json +2 -1
@@ -0,0 +1,49 @@
|
|
1
|
+
import { Editor, Transforms, Path, Range, Element } from "slate";
|
2
|
+
export const createChipTextNode = (href, showInNewTab, text) => ({
|
3
|
+
type: "chip-text",
|
4
|
+
href,
|
5
|
+
target: showInNewTab ? "_blank" : "_self",
|
6
|
+
children: [{
|
7
|
+
text
|
8
|
+
}]
|
9
|
+
});
|
10
|
+
export const insertChipText = (editor, {
|
11
|
+
url,
|
12
|
+
showInNewTab
|
13
|
+
}) => {
|
14
|
+
const {
|
15
|
+
selection
|
16
|
+
} = editor;
|
17
|
+
const chipText = createChipTextNode(url, showInNewTab, "Chip Text");
|
18
|
+
if (!!selection) {
|
19
|
+
const [parent, parentPath] = Editor.parent(editor, selection.focus.path);
|
20
|
+
if (editor.isVoid(parent)) {
|
21
|
+
Transforms.insertNodes(editor, {
|
22
|
+
type: "paragraph",
|
23
|
+
children: [chipText]
|
24
|
+
}, {
|
25
|
+
at: Path.next(parentPath),
|
26
|
+
select: true
|
27
|
+
});
|
28
|
+
} else if (Range.isCollapsed(selection)) {
|
29
|
+
Transforms.insertNodes(editor, chipText, {
|
30
|
+
select: true
|
31
|
+
});
|
32
|
+
} else {
|
33
|
+
Transforms.wrapNodes(editor, chipText, {
|
34
|
+
split: true
|
35
|
+
});
|
36
|
+
}
|
37
|
+
} else {
|
38
|
+
Transforms.insertNodes(editor, {
|
39
|
+
type: "paragraph",
|
40
|
+
children: [chipText]
|
41
|
+
});
|
42
|
+
}
|
43
|
+
};
|
44
|
+
export const removeChipText = (editor, path) => {
|
45
|
+
Transforms.unwrapNodes(editor, {
|
46
|
+
at: path,
|
47
|
+
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "chip-text"
|
48
|
+
});
|
49
|
+
};
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { Editor, Transforms, Path, Range, Element } from "slate";
|
2
|
+
export const createDrawerMenuNode = ({
|
3
|
+
text
|
4
|
+
}) => ({
|
5
|
+
type: "drawer",
|
6
|
+
anchor: "left",
|
7
|
+
menus: [{
|
8
|
+
type: "menu",
|
9
|
+
text: "Menu 1",
|
10
|
+
url: "http://google.com"
|
11
|
+
}],
|
12
|
+
children: [{
|
13
|
+
text: "Menu"
|
14
|
+
}]
|
15
|
+
});
|
16
|
+
export const insertDrawerMenu = (editor, props) => {
|
17
|
+
const {
|
18
|
+
selection
|
19
|
+
} = editor;
|
20
|
+
const drawerMenu = createDrawerMenuNode(props);
|
21
|
+
if (!!selection) {
|
22
|
+
const [parent, parentPath] = Editor.parent(editor, selection.focus.path);
|
23
|
+
if (editor.isVoid(parent)) {
|
24
|
+
Transforms.insertNodes(editor, {
|
25
|
+
type: "paragraph",
|
26
|
+
children: [drawerMenu]
|
27
|
+
}, {
|
28
|
+
at: Path.next(parentPath),
|
29
|
+
select: true
|
30
|
+
});
|
31
|
+
} else if (Range.isCollapsed(selection)) {
|
32
|
+
Transforms.insertNodes(editor, drawerMenu, {
|
33
|
+
select: true
|
34
|
+
});
|
35
|
+
} else {
|
36
|
+
Transforms.wrapNodes(editor, drawerMenu, {
|
37
|
+
split: true
|
38
|
+
});
|
39
|
+
}
|
40
|
+
} else {
|
41
|
+
Transforms.insertNodes(editor, {
|
42
|
+
type: "paragraph",
|
43
|
+
children: [drawerMenu]
|
44
|
+
});
|
45
|
+
}
|
46
|
+
};
|
47
|
+
export const removeDrawerMenu = (editor, path) => {
|
48
|
+
Transforms.unwrapNodes(editor, {
|
49
|
+
at: path,
|
50
|
+
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "drawer"
|
51
|
+
});
|
52
|
+
};
|
@@ -1,28 +1,38 @@
|
|
1
|
-
import { Text } from
|
2
|
-
import { getBlock, getMarked } from
|
3
|
-
import ReactDOMServer from
|
1
|
+
import { Text } from "slate";
|
2
|
+
import { getBlock, getMarked } from "./SlateUtilityFunctions.js";
|
3
|
+
import ReactDOMServer from "react-dom/server";
|
4
4
|
const {
|
5
|
-
|
5
|
+
renderToString
|
6
6
|
} = ReactDOMServer;
|
7
7
|
export const serialize = node => {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
try {
|
9
|
+
if (Text.isText(node)) {
|
10
|
+
let string = getMarked(node, node.text);
|
11
|
+
string = renderToString(string);
|
12
|
+
return string;
|
13
|
+
}
|
14
|
+
const children = node.children.map(n => serialize(n)).join("");
|
15
|
+
let block = getBlock({
|
16
|
+
children,
|
17
|
+
element: node
|
18
|
+
});
|
19
|
+
block = renderToString(block);
|
20
|
+
return block;
|
21
|
+
} catch (err) {
|
22
|
+
console.log(err);
|
23
|
+
return null;
|
12
24
|
}
|
13
|
-
const children = node.children.map(n => serialize(n)).join('');
|
14
|
-
let block = getBlock({
|
15
|
-
children,
|
16
|
-
element: node
|
17
|
-
});
|
18
|
-
block = renderToStaticMarkup(block);
|
19
|
-
return block;
|
20
25
|
};
|
21
26
|
export const serializer = editorValue => {
|
22
27
|
if (editorValue.length > 0) {
|
23
|
-
return editorValue.map(n => serialize(n)).join(
|
28
|
+
return editorValue.map(n => serialize(n)).join("");
|
24
29
|
}
|
25
30
|
};
|
26
31
|
export const deserializer = body => {
|
27
32
|
console.log(body);
|
33
|
+
};
|
34
|
+
export const convertToHTML = editorWrapper => {
|
35
|
+
if (editorWrapper && editorWrapper?.current) {
|
36
|
+
return editorWrapper?.current;
|
37
|
+
}
|
28
38
|
};
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import { Transforms, Editor, Range, Element, Path } from "slate";
|
1
|
+
import { Transforms, Editor, Range, Element, Path, Node } from "slate";
|
2
|
+
import { ReactEditor } from "slate-react";
|
2
3
|
const prefixKey = (obj, pk = "") => {
|
3
4
|
return Object.keys(obj).reduce((a, b) => {
|
4
5
|
a[`${pk}${b}`] = obj[b];
|
@@ -54,6 +55,30 @@ export class TableUtil {
|
|
54
55
|
});
|
55
56
|
};
|
56
57
|
|
58
|
+
getDOMNode = path => {
|
59
|
+
try {
|
60
|
+
const [tableNode] = Editor.nodes(this.editor, {
|
61
|
+
at: path,
|
62
|
+
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
|
63
|
+
});
|
64
|
+
const tableDOM = ReactEditor.toDOMNode(this.editor, tableNode[0]);
|
65
|
+
return tableDOM;
|
66
|
+
} catch (err) {
|
67
|
+
console.log(err);
|
68
|
+
}
|
69
|
+
};
|
70
|
+
getTotalWidth = (path, colCount = 0) => {
|
71
|
+
try {
|
72
|
+
let totalWidth = 0;
|
73
|
+
for (let i = 0; i < colCount; i++) {
|
74
|
+
const dom = ReactEditor.toDOMNode(this.editor, Node.get(this.editor, [...path, 0, i]));
|
75
|
+
totalWidth += parseFloat(dom.style.width);
|
76
|
+
}
|
77
|
+
return totalWidth;
|
78
|
+
} catch (err) {
|
79
|
+
console.log(err);
|
80
|
+
}
|
81
|
+
};
|
57
82
|
insertRow = action => {
|
58
83
|
const {
|
59
84
|
selection
|
@@ -172,7 +197,6 @@ export class TableUtil {
|
|
172
197
|
selection
|
173
198
|
} = this.editor;
|
174
199
|
if (!!selection && Range.isCollapsed(selection)) {
|
175
|
-
console.log("styleProps", styleProps);
|
176
200
|
const tableProps = parseByPrefixKey(styleProps, "table.");
|
177
201
|
const rowProps = parseByPrefixKey(styleProps, "row.");
|
178
202
|
const cellProps = parseByPrefixKey(styleProps, "col.");
|
@@ -181,7 +205,6 @@ export class TableUtil {
|
|
181
205
|
currentRowPath,
|
182
206
|
currentTablePath
|
183
207
|
} = paths;
|
184
|
-
console.log(tableProps, rowProps, cellProps);
|
185
208
|
Transforms.setNodes(this.editor, {
|
186
209
|
...tableProps
|
187
210
|
}, {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@flozy/editor",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.7",
|
4
4
|
"description": "An Editor for flozy app brain",
|
5
5
|
"files": [
|
6
6
|
"dist"
|
@@ -22,6 +22,7 @@
|
|
22
22
|
"interweave": "^13.1.0",
|
23
23
|
"lint-staged": "^13.2.3",
|
24
24
|
"prettier": "^3.0.1",
|
25
|
+
"react-best-gradient-color-picker": "^2.2.23",
|
25
26
|
"react-datepicker": "^4.18.0",
|
26
27
|
"react-icons": "^4.10.1",
|
27
28
|
"react-katex": "^3.0.1",
|