@flozy/editor 1.0.5 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. package/dist/Editor/CollaborativeEditor.js +116 -0
  2. package/dist/Editor/CommonEditor.js +132 -0
  3. package/dist/Editor/Editor.css +115 -0
  4. package/dist/Editor/Elements/CodeToText/CodeToText.css +57 -0
  5. package/dist/Editor/Elements/CodeToText/CodeToText.js +112 -0
  6. package/dist/Editor/Elements/CodeToText/CodeToTextButton.js +18 -0
  7. package/dist/Editor/Elements/CodeToText/HtmlCode.js +54 -0
  8. package/dist/Editor/Elements/CodeToText/HtmlContextMenu.js +39 -0
  9. package/dist/Editor/Elements/Color Picker/ColorPicker.css +38 -0
  10. package/dist/Editor/Elements/Color Picker/ColorPicker.js +116 -0
  11. package/dist/Editor/Elements/Color Picker/defaultColors.js +1 -0
  12. package/dist/Editor/Elements/Embed/Embed.css +14 -0
  13. package/dist/Editor/Elements/Embed/Embed.js +94 -0
  14. package/dist/Editor/Elements/Embed/Image.js +70 -0
  15. package/dist/Editor/Elements/Embed/Video.js +62 -0
  16. package/dist/Editor/Elements/Equation/Equation.js +24 -0
  17. package/dist/Editor/Elements/Equation/EquationButton.js +66 -0
  18. package/dist/Editor/Elements/Equation/styles.css +4 -0
  19. package/dist/Editor/Elements/Grid/Grid.js +53 -0
  20. package/dist/Editor/Elements/Grid/GridButton.js +19 -0
  21. package/dist/Editor/Elements/Grid/GridItem.js +53 -0
  22. package/dist/Editor/Elements/ID/Id.js +56 -0
  23. package/dist/Editor/Elements/Link/Link.js +34 -0
  24. package/dist/Editor/Elements/Link/LinkButton.js +77 -0
  25. package/dist/Editor/Elements/Link/styles.css +20 -0
  26. package/dist/Editor/Elements/Mentions/Mentions.js +34 -0
  27. package/dist/Editor/Elements/NewLine/NewLineButton.js +22 -0
  28. package/dist/Editor/Elements/Table/Table.js +15 -0
  29. package/dist/Editor/Elements/Table/TableSelector.css +18 -0
  30. package/dist/Editor/Elements/Table/TableSelector.js +93 -0
  31. package/dist/Editor/Elements/TableContextMenu/TableContextMenu.js +91 -0
  32. package/dist/Editor/Elements/TableContextMenu/styles.css +18 -0
  33. package/dist/Editor/RemoteCursorOverlay/Overlay.js +75 -0
  34. package/dist/Editor/Toolbar/Toolbar.js +166 -0
  35. package/dist/Editor/Toolbar/styles.css +28 -0
  36. package/dist/Editor/Toolbar/toolbarGroups.js +131 -0
  37. package/dist/Editor/Toolbar/toolbarIcons/align-center.svg +1 -0
  38. package/dist/Editor/Toolbar/toolbarIcons/align-left.svg +1 -0
  39. package/dist/Editor/Toolbar/toolbarIcons/align-right.svg +1 -0
  40. package/dist/Editor/Toolbar/toolbarIcons/blockquote.svg +1 -0
  41. package/dist/Editor/Toolbar/toolbarIcons/bold.png +0 -0
  42. package/dist/Editor/Toolbar/toolbarIcons/fontColor.svg +4 -0
  43. package/dist/Editor/Toolbar/toolbarIcons/headingOne.svg +3 -0
  44. package/dist/Editor/Toolbar/toolbarIcons/headingTwo.svg +3 -0
  45. package/dist/Editor/Toolbar/toolbarIcons/italic.png +0 -0
  46. package/dist/Editor/Toolbar/toolbarIcons/link.svg +1 -0
  47. package/dist/Editor/Toolbar/toolbarIcons/orderedList.svg +1 -0
  48. package/dist/Editor/Toolbar/toolbarIcons/strikethrough.png +0 -0
  49. package/dist/Editor/Toolbar/toolbarIcons/subscript.svg +1 -0
  50. package/dist/Editor/Toolbar/toolbarIcons/superscript.svg +1 -0
  51. package/dist/Editor/Toolbar/toolbarIcons/textColor.png +0 -0
  52. package/dist/Editor/Toolbar/toolbarIcons/underline.png +0 -0
  53. package/dist/Editor/Toolbar/toolbarIcons/unlink.svg +1 -0
  54. package/dist/Editor/Toolbar/toolbarIcons/unorderedList.svg +1 -0
  55. package/dist/Editor/YjsProvider.js +9 -0
  56. package/dist/Editor/common/Button.js +21 -0
  57. package/dist/Editor/common/Icon.js +114 -0
  58. package/dist/Editor/common/MentionsPopup.js +54 -0
  59. package/dist/Editor/hooks/useMentions.js +44 -0
  60. package/dist/Editor/hooks/withCollaborative.js +15 -0
  61. package/dist/Editor/hooks/withCommon.js +11 -0
  62. package/dist/Editor/plugins/withEmbeds.js +29 -0
  63. package/dist/Editor/plugins/withEquation.js +8 -0
  64. package/dist/Editor/plugins/withLinks.js +8 -0
  65. package/dist/Editor/plugins/withMentions.js +18 -0
  66. package/dist/Editor/plugins/withTable.js +61 -0
  67. package/dist/Editor/utils/SlateUtilityFunctions.js +224 -0
  68. package/dist/Editor/utils/customHooks/useContextMenu.js +37 -0
  69. package/dist/Editor/utils/customHooks/useFormat.js +21 -0
  70. package/dist/Editor/utils/customHooks/usePopup.js +21 -0
  71. package/dist/Editor/utils/customHooks/useResize.js +47 -0
  72. package/dist/Editor/utils/draftToSlate.js +111 -0
  73. package/dist/Editor/utils/embed.js +24 -0
  74. package/dist/Editor/utils/equation.js +23 -0
  75. package/dist/Editor/utils/events.js +76 -0
  76. package/dist/Editor/utils/grid.js +13 -0
  77. package/dist/Editor/utils/gridItem.js +19 -0
  78. package/dist/Editor/utils/link.js +52 -0
  79. package/dist/Editor/utils/mentions.js +12 -0
  80. package/dist/Editor/utils/paragraph.js +6 -0
  81. package/dist/Editor/utils/serializer.js +28 -0
  82. package/dist/Editor/utils/table.js +129 -0
  83. package/dist/index.js +4 -0
  84. package/package.json +18 -8
@@ -0,0 +1,28 @@
1
+ import { Text } from 'slate';
2
+ import { getBlock, getMarked } from './SlateUtilityFunctions.js';
3
+ import ReactDOMServer from 'react-dom/server';
4
+ const {
5
+ renderToStaticMarkup
6
+ } = ReactDOMServer;
7
+ export const serialize = node => {
8
+ if (Text.isText(node)) {
9
+ let string = getMarked(node, node.text);
10
+ string = renderToStaticMarkup(string);
11
+ return string;
12
+ }
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
+ };
21
+ export const serializer = editorValue => {
22
+ if (editorValue.length > 0) {
23
+ return editorValue.map(n => serialize(n)).join('');
24
+ }
25
+ };
26
+ export const deserializer = body => {
27
+ console.log(body);
28
+ };
@@ -0,0 +1,129 @@
1
+ import { Transforms, Editor, Range, Element, Path } from "slate";
2
+ export class TableUtil {
3
+ constructor(editor) {
4
+ this.editor = editor;
5
+ }
6
+ insertTable = (rows, columns) => {
7
+ const [tableNode] = Editor.nodes(this.editor, {
8
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table",
9
+ mode: "highest"
10
+ });
11
+ if (tableNode) return;
12
+ if (!rows || !columns) {
13
+ return;
14
+ }
15
+ //Creating a 2-d array of blank string as default text for the table
16
+ const cellText = Array.from({
17
+ length: rows
18
+ }, () => Array.from({
19
+ length: columns
20
+ }, () => ""));
21
+ const newTable = createTableNode(cellText, rows, columns);
22
+ Transforms.insertNodes(this.editor, newTable, {
23
+ // mode: "highest",
24
+ });
25
+ Transforms.insertNodes(this.editor, {
26
+ type: "paragraph",
27
+ children: [{
28
+ text: ""
29
+ }]
30
+ }
31
+ // { mode: "highest" }
32
+ );
33
+ };
34
+
35
+ removeTable = () => {
36
+ Transforms.removeNodes(this.editor, {
37
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
38
+ // mode:'highest'
39
+ });
40
+ };
41
+
42
+ insertRow = action => {
43
+ const {
44
+ selection
45
+ } = this.editor;
46
+ if (!!selection && Range.isCollapsed(selection)) {
47
+ const [tableNode] = Editor.nodes(this.editor, {
48
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-row"
49
+ });
50
+ if (tableNode) {
51
+ const [[table, tablePath]] = Editor.nodes(this.editor, {
52
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
53
+ });
54
+ const [, currentRow] = tableNode;
55
+ const path = action === "after" ? Path.next(currentRow) : currentRow;
56
+ Transforms.insertNodes(this.editor, createRow(Array(table.columns).fill("")), {
57
+ at: path
58
+ });
59
+ Transforms.setNodes(this.editor, {
60
+ rows: table.rows + 1
61
+ }, {
62
+ at: tablePath
63
+ });
64
+ }
65
+ }
66
+ };
67
+ insertColumn = action => {
68
+ const {
69
+ selection
70
+ } = this.editor;
71
+ if (!!selection && Range.isCollapsed(selection)) {
72
+ const [tableNode] = Editor.nodes(this.editor, {
73
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-cell"
74
+ });
75
+ if (tableNode) {
76
+ const [[table, tablePath]] = Editor.nodes(this.editor, {
77
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
78
+ });
79
+ const [, currentCell] = tableNode;
80
+ const startPath = action === "after" ? Path.next(currentCell) : currentCell;
81
+
82
+ // The last two indices of the path represents the row and column. We need to add one cell to each row starting from the first row
83
+ startPath[startPath.length - 2] = 0;
84
+ for (let row = 0; row < table.rows; row++) {
85
+ Transforms.insertNodes(this.editor, createTableCell(""), {
86
+ at: startPath
87
+ });
88
+ startPath[startPath.length - 2]++;
89
+ }
90
+ Transforms.setNodes(this.editor, {
91
+ columns: table.columns + 1
92
+ }, {
93
+ at: tablePath
94
+ });
95
+ }
96
+ }
97
+ };
98
+ }
99
+ const createRow = cellText => {
100
+ const newRow = Array.from(cellText, value => createTableCell(value));
101
+ return {
102
+ type: "table-row",
103
+ children: newRow
104
+ };
105
+ };
106
+ export const createTableCell = text => {
107
+ return {
108
+ type: "table-cell",
109
+ children: [{
110
+ type: "paragraph",
111
+ children: [{
112
+ text
113
+ }]
114
+ }]
115
+ };
116
+ };
117
+ const createTableNode = (cellText, rows, columns) => {
118
+ const tableChildren = Array.from(cellText, value => createRow(value));
119
+ let tableNode = {
120
+ type: "paragraph",
121
+ children: [{
122
+ type: "table",
123
+ children: tableChildren,
124
+ rows,
125
+ columns
126
+ }]
127
+ };
128
+ return tableNode;
129
+ };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import Collaborative from "./Editor/CollaborativeEditor";
2
+ import CommonEditor from "./Editor/CommonEditor";
3
+ export const Editor = CommonEditor;
4
+ export const CollaborativeEditor = Collaborative;
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "An Editor for flozy app brain",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "dist/index.js",
5
9
  "dependencies": {
6
10
  "@emotion/react": "^11.11.1",
7
11
  "@emotion/styled": "^11.11.0",
@@ -18,8 +22,6 @@
18
22
  "interweave": "^13.1.0",
19
23
  "lint-staged": "^13.2.3",
20
24
  "prettier": "^3.0.1",
21
- "react": "^18.2.0",
22
- "react-dom": "^18.2.0",
23
25
  "react-icons": "^4.10.1",
24
26
  "react-katex": "^3.0.1",
25
27
  "react-scripts": "5.0.1",
@@ -31,6 +33,10 @@
31
33
  "y-websocket": "^1.5.0",
32
34
  "yjs": "^13.6.8"
33
35
  },
36
+ "peerDependencies": {
37
+ "react": "^18.2.0",
38
+ "react-dom": "^18.2.0"
39
+ },
34
40
  "scripts": {
35
41
  "prepare": "husky install .husky",
36
42
  "lint": "./node_modules/.bin/eslint --ignore-path .gitignore . --fix",
@@ -39,7 +45,8 @@
39
45
  "test": "craco test --passWithNoTests",
40
46
  "eject": "react-scripts eject",
41
47
  "storybook": "storybook dev -p 6006",
42
- "build-storybook": "storybook build"
48
+ "build-storybook": "storybook build",
49
+ "publish:npm": "rm -rf dist && mkdir dist && babel src/components -d dist --copy-files"
43
50
  },
44
51
  "eslintConfig": {
45
52
  "extends": [
@@ -71,7 +78,9 @@
71
78
  ]
72
79
  },
73
80
  "devDependencies": {
81
+ "@babel/cli": "^7.23.0",
74
82
  "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
83
+ "@babel/preset-react": "^7.22.15",
75
84
  "@craco/craco": "^7.1.0",
76
85
  "@storybook/addon-essentials": "^7.4.0",
77
86
  "@storybook/addon-interactions": "^7.4.0",
@@ -104,8 +113,9 @@
104
113
  "bugs": {
105
114
  "url": "https://github.com/Flozy-App/editor/issues"
106
115
  },
107
- "files": [
108
- "dist"
109
- ],
110
- "main": "dist/index.js"
116
+ "babel": {
117
+ "presets": [
118
+ "@babel/preset-react"
119
+ ]
120
+ }
111
121
  }