@flozy/editor 1.1.4 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. package/dist/Editor/CollaborativeEditor.js +6 -1
  2. package/dist/Editor/CommonEditor.js +16 -2
  3. package/dist/Editor/Editor.css +15 -3
  4. package/dist/Editor/Elements/Button/EditorButton.js +3 -3
  5. package/dist/Editor/Elements/Carousel/Carousel.js +19 -5
  6. package/dist/Editor/Elements/Carousel/CarouselItem.js +5 -1
  7. package/dist/Editor/Elements/ChipText/ChipText.js +44 -0
  8. package/dist/Editor/Elements/ChipText/ChipTextButton.js +64 -0
  9. package/dist/Editor/Elements/ChipText/ChipTextPopup.js +24 -0
  10. package/dist/Editor/Elements/DrawerMenu/DrawerMenu.js +66 -0
  11. package/dist/Editor/Elements/DrawerMenu/DrawerMenuButton.js +21 -0
  12. package/dist/Editor/Elements/Link/Link.js +5 -5
  13. package/dist/Editor/Elements/Link/LinkButton.js +50 -37
  14. package/dist/Editor/Elements/Table/Table.js +160 -10
  15. package/dist/Editor/Elements/Table/TableCell.js +55 -143
  16. package/dist/Editor/Elements/Table/table.css +13 -0
  17. package/dist/Editor/Toolbar/Toolbar.js +12 -0
  18. package/dist/Editor/Toolbar/toolbarGroups.js +6 -0
  19. package/dist/Editor/common/ColorPickerButton.js +65 -0
  20. package/dist/Editor/common/StyleBuilder/chipTextStyle.js +35 -0
  21. package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +8 -14
  22. package/dist/Editor/common/StyleBuilder/index.js +8 -3
  23. package/dist/Editor/common/StyleBuilder/pageSettingsStyle.js +12 -0
  24. package/dist/Editor/plugins/withLinks.js +40 -2
  25. package/dist/Editor/plugins/withTable.js +10 -1
  26. package/dist/Editor/service/fileupload.js +1 -1
  27. package/dist/Editor/utils/SlateUtilityFunctions.js +10 -0
  28. package/dist/Editor/utils/customHooks/useTableResize.js +46 -0
  29. package/dist/Editor/utils/insertChipText.js +49 -0
  30. package/dist/Editor/utils/insertDrawerMenu.js +52 -0
  31. package/dist/Editor/utils/table.js +26 -3
  32. package/package.json +2 -1
@@ -1,8 +1,46 @@
1
+ import { Transforms, Element, Node } from "slate";
2
+ const INLINE_ELLEMENTS = ["link", "chip-text", "drawer"];
1
3
  const withLinks = editor => {
2
4
  const {
3
- isInline
5
+ isInline,
6
+ deleteBackward,
7
+ normalizeNode
4
8
  } = editor;
5
- editor.isInline = element => element.type === 'link' ? true : isInline(element);
9
+ editor.isInline = element => INLINE_ELLEMENTS.indexOf(element.type) > -1 ? true : isInline(element);
10
+
11
+ // remove empty inline
12
+ editor.normalizeNode = entry => {
13
+ const [node, path] = entry;
14
+ if (Element.isElement(node) && node.type === "paragraph") {
15
+ const children = Array.from(Node.children(editor, path));
16
+ for (const [child, childPath] of children) {
17
+ // remove link nodes whose text value is empty string.
18
+ // empty text links happen when you move from link to next line or delete link line.
19
+ if (Element.isElement(child) && INLINE_ELLEMENTS.indexOf(child.type) > -1 && child.children[0].text === "") {
20
+ if (children.length === 1) {
21
+ Transforms.removeNodes(editor, {
22
+ at: path
23
+ });
24
+ Transforms.insertNodes(editor, {
25
+ type: "paragraph",
26
+ children: [{
27
+ text: ""
28
+ }]
29
+ });
30
+ } else {
31
+ Transforms.removeNodes(editor, {
32
+ at: childPath
33
+ });
34
+ }
35
+ return;
36
+ }
37
+ }
38
+ }
39
+ normalizeNode(entry);
40
+ };
41
+ editor.deleteBackward = unit => {
42
+ deleteBackward(unit);
43
+ };
6
44
  return editor;
7
45
  };
8
46
  export default withLinks;
@@ -1,10 +1,19 @@
1
- import { Editor, Range, Point, Element } from "slate";
1
+ import { Editor, Range, Point, Element, Transforms } from "slate";
2
2
  const NON_DELETABLE_BLOCKS = ["table-cell", "carousel-item"];
3
3
  const withTable = editor => {
4
4
  const {
5
5
  deleteBackward,
6
6
  deleteForward
7
7
  } = editor;
8
+ editor.insertData = data => {
9
+ try {
10
+ const text = data.getData("text/plain");
11
+ Transforms.insertText(editor, text);
12
+ return;
13
+ } catch (err) {
14
+ console.log(err);
15
+ }
16
+ };
8
17
  editor.deleteBackward = unit => {
9
18
  const {
10
19
  selection
@@ -1,6 +1,6 @@
1
1
  export const uploadFile = async (formData, props) => {
2
2
  try {
3
- const response = await fetch(`${props.API_HOST}/api/v1/general/notes/file_upload`, {
3
+ const response = await fetch(`${props.API_HOST}/general/notes/file_upload`, {
4
4
  method: "POST",
5
5
  headers: {
6
6
  "Content-Type": "application/json",
@@ -21,6 +21,8 @@ import Carousel from "../Elements/Carousel/Carousel";
21
21
  import CarouselItem from "../Elements/Carousel/CarouselItem";
22
22
  import ImageTextWrapper from "../Elements/ImageText/ImageTextWrapper";
23
23
  import ImageText from "../Elements/ImageText/ImageText";
24
+ import ChipText from "../Elements/ChipText/ChipText";
25
+ import DrawerMenu from "../Elements/DrawerMenu/DrawerMenu";
24
26
  import { jsx as _jsx } from "react/jsx-runtime";
25
27
  const alignment = ["alignLeft", "alignRight", "alignCenter"];
26
28
  const list_types = ["orderedList", "unorderedList"];
@@ -343,6 +345,14 @@ export const getBlock = props => {
343
345
  return /*#__PURE__*/_jsx(CarouselItem, {
344
346
  ...props
345
347
  });
348
+ case "chip-text":
349
+ return /*#__PURE__*/_jsx(ChipText, {
350
+ ...props
351
+ });
352
+ case "drawer":
353
+ return /*#__PURE__*/_jsx(DrawerMenu, {
354
+ ...props
355
+ });
346
356
  default:
347
357
  return /*#__PURE__*/_jsx("div", {
348
358
  ...element.attr,
@@ -0,0 +1,46 @@
1
+ import { useState } from "react";
2
+ const useTableResize = ({
3
+ parentDOM,
4
+ size: defaultSize
5
+ }) => {
6
+ const {
7
+ width
8
+ } = parentDOM?.getBoundingClientRect() || {
9
+ ...defaultSize
10
+ };
11
+ const [size, setSize] = useState({
12
+ height: 300,
13
+ widthInPercent: 100,
14
+ ...defaultSize
15
+ });
16
+ const [resizing, setResizing] = useState(false);
17
+ const onLoad = defaultSize => {
18
+ setSize({
19
+ widthInPercent: 100,
20
+ height: 300,
21
+ ...defaultSize
22
+ });
23
+ };
24
+ const onMouseDown = () => {
25
+ document.addEventListener("pointermove", onMouseMove);
26
+ document.addEventListener("pointerup", onMouseUp);
27
+ setResizing(true);
28
+ };
29
+ const onMouseUp = () => {
30
+ document.removeEventListener("pointermove", onMouseMove);
31
+ document.removeEventListener("pointerup", onMouseUp);
32
+ setResizing(false);
33
+ };
34
+ const onMouseMove = e => {
35
+ setSize(currentSize => {
36
+ const calcWidth = currentSize?.width + e.movementX;
37
+ return {
38
+ width: calcWidth,
39
+ height: currentSize.height + e.movementY,
40
+ widthInPercent: calcWidth / width * 100
41
+ };
42
+ });
43
+ };
44
+ return [size, onMouseDown, resizing, onLoad];
45
+ };
46
+ export default useTableResize;
@@ -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,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.4",
3
+ "version": "1.1.6",
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",