@springmicro/rte 0.1.3
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/.eslintrc.cjs +18 -0
- package/README.md +15 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +63921 -0
- package/dist/index.umd.cjs +469 -0
- package/dist/style.css +1 -0
- package/index.html +13 -0
- package/package.json +54 -0
- package/src/App.css +42 -0
- package/src/App.tsx +10 -0
- package/src/contexts/color-context.tsx +53 -0
- package/src/hooks/useSimpleFormik.tsx +74 -0
- package/src/index.css +68 -0
- package/src/index.tsx +3 -0
- package/src/main.tsx +10 -0
- package/src/slate/base-editor.stories.tsx +16 -0
- package/src/slate/base-editor.tsx +116 -0
- package/src/slate/blog-rte.stories.tsx +16 -0
- package/src/slate/blog-rte.tsx +126 -0
- package/src/slate/common/button.tsx +35 -0
- package/src/slate/common/element.tsx +13 -0
- package/src/slate/common/icon.jsx +97 -0
- package/src/slate/components/code-to-text/CodeToTextButton.jsx +19 -0
- package/src/slate/components/code-to-text/HtmlCode.jsx +64 -0
- package/src/slate/components/code-to-text/HtmlContextMenu.jsx +39 -0
- package/src/slate/components/code-to-text/index.jsx +111 -0
- package/src/slate/components/color-picker/color-cursor.stories.tsx +16 -0
- package/src/slate/components/color-picker/color-cursor.tsx +34 -0
- package/src/slate/components/color-picker/color-formats-view.stories.tsx +25 -0
- package/src/slate/components/color-picker/color-formats-view.tsx +115 -0
- package/src/slate/components/color-picker/color-gradient.stories.tsx +48 -0
- package/src/slate/components/color-picker/color-gradient.tsx +128 -0
- package/src/slate/components/color-picker/color-hue.stories.tsx +41 -0
- package/src/slate/components/color-picker/color-hue.tsx +110 -0
- package/src/slate/components/color-picker/color-picker.stories.tsx +25 -0
- package/src/slate/components/color-picker/color-picker.tsx +41 -0
- package/src/slate/components/color-picker/color-popover.stories.tsx +26 -0
- package/src/slate/components/color-picker/color-popover.tsx +58 -0
- package/src/slate/components/color-picker/color-swatch.stories.tsx +16 -0
- package/src/slate/components/color-picker/color-swatch.tsx +76 -0
- package/src/slate/components/color-picker/default-colors.ts +38 -0
- package/src/slate/components/color-picker/slate-color-button.tsx +128 -0
- package/src/slate/components/embed/Embed.jsx +96 -0
- package/src/slate/components/embed/Image.jsx +45 -0
- package/src/slate/components/embed/Video.jsx +65 -0
- package/src/slate/components/equation/Equation.jsx +19 -0
- package/src/slate/components/equation/EquationButton.jsx +68 -0
- package/src/slate/components/id/Id.jsx +57 -0
- package/src/slate/components/image/image.stories.tsx +17 -0
- package/src/slate/components/image/image.tsx +62 -0
- package/src/slate/components/image/insert-image-button.stories.tsx +83 -0
- package/src/slate/components/image/insert-image-button.tsx +132 -0
- package/src/slate/components/image/types.ts +9 -0
- package/src/slate/components/link/Link.jsx +56 -0
- package/src/slate/components/link/LinkButton.tsx +106 -0
- package/src/slate/components/table/Table.jsx +11 -0
- package/src/slate/components/table/TableSelector.jsx +97 -0
- package/src/slate/components/table-context-menu/TableContextMenu.tsx +106 -0
- package/src/slate/custom-types.d.ts +152 -0
- package/src/slate/editor.module.css +226 -0
- package/src/slate/paper-rte.stories.tsx +16 -0
- package/src/slate/paper-rte.tsx +47 -0
- package/src/slate/plugins/withEmbeds.js +33 -0
- package/src/slate/plugins/withEquation.js +8 -0
- package/src/slate/plugins/withImages.ts +69 -0
- package/src/slate/plugins/withLinks.js +9 -0
- package/src/slate/plugins/withTable.js +74 -0
- package/src/slate/serializers/generic.ts +44 -0
- package/src/slate/serializers/types.ts +20 -0
- package/src/slate/toolbar/index.tsx +186 -0
- package/src/slate/toolbar/paper-toolbar.tsx +494 -0
- package/src/slate/toolbar/shortcuts.tsx +77 -0
- package/src/slate/toolbar/toolbar-groups.ts +213 -0
- package/src/slate/types/index.ts +0 -0
- package/src/slate/utils/customHooks/useContextMenu.js +42 -0
- package/src/slate/utils/customHooks/useFormat.js +26 -0
- package/src/slate/utils/customHooks/usePopup.jsx +26 -0
- package/src/slate/utils/customHooks/useResize.js +27 -0
- package/src/slate/utils/embed.js +18 -0
- package/src/slate/utils/equation.js +22 -0
- package/src/slate/utils/index.jsx +267 -0
- package/src/slate/utils/link.js +44 -0
- package/src/slate/utils/p.js +4 -0
- package/src/slate/utils/table.js +131 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +32 -0
- package/tsconfig.node.json +10 -0
- package/vite.config.ts +41 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Transforms, Editor, Range, Element, Path } from "slate"
|
|
2
|
+
|
|
3
|
+
export class TableUtil {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
this.editor = editor
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
insertTable = (rows, columns) => {
|
|
9
|
+
const [tableNode] = Editor.nodes(this.editor, {
|
|
10
|
+
match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table",
|
|
11
|
+
mode: "highest",
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
if (tableNode) return
|
|
15
|
+
if (!rows || !columns) {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
//Creating a 2-d array of blank string as default text for the table
|
|
19
|
+
const cellText = Array.from({ length: rows }, () => Array.from({ length: columns }, () => ""))
|
|
20
|
+
const newTable = createTableNode(cellText, rows, columns)
|
|
21
|
+
|
|
22
|
+
Transforms.insertNodes(this.editor, newTable, {
|
|
23
|
+
mode: "highest",
|
|
24
|
+
})
|
|
25
|
+
Transforms.insertNodes(
|
|
26
|
+
this.editor,
|
|
27
|
+
{ type: "p", children: [{ text: "" }] },
|
|
28
|
+
{ mode: "highest" }
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
removeTable = () => {
|
|
33
|
+
Transforms.removeNodes(this.editor, {
|
|
34
|
+
match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table",
|
|
35
|
+
// mode:'highest'
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
insertRow = (action) => {
|
|
40
|
+
const { selection } = this.editor
|
|
41
|
+
|
|
42
|
+
if (!!selection && Range.isCollapsed(selection)) {
|
|
43
|
+
const [tableNode] = Editor.nodes(this.editor, {
|
|
44
|
+
match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-row",
|
|
45
|
+
})
|
|
46
|
+
if (tableNode) {
|
|
47
|
+
const [[table, tablePath]] = Editor.nodes(this.editor, {
|
|
48
|
+
match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table",
|
|
49
|
+
})
|
|
50
|
+
const [, currentRow] = tableNode
|
|
51
|
+
|
|
52
|
+
const path = action === "after" ? Path.next(currentRow) : currentRow
|
|
53
|
+
|
|
54
|
+
Transforms.insertNodes(this.editor, createRow(Array(table.columns).fill("")), {
|
|
55
|
+
at: path,
|
|
56
|
+
})
|
|
57
|
+
Transforms.setNodes(
|
|
58
|
+
this.editor,
|
|
59
|
+
{ rows: table.rows + 1 },
|
|
60
|
+
{
|
|
61
|
+
at: tablePath,
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
insertColumn = (action) => {
|
|
69
|
+
const { selection } = this.editor
|
|
70
|
+
if (!!selection && Range.isCollapsed(selection)) {
|
|
71
|
+
const [tableNode] = Editor.nodes(this.editor, {
|
|
72
|
+
match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-cell",
|
|
73
|
+
})
|
|
74
|
+
if (tableNode) {
|
|
75
|
+
const [[table, tablePath]] = Editor.nodes(this.editor, {
|
|
76
|
+
match: (n) => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table",
|
|
77
|
+
})
|
|
78
|
+
const [, currentCell] = tableNode
|
|
79
|
+
const startPath = action === "after" ? Path.next(currentCell) : currentCell
|
|
80
|
+
|
|
81
|
+
// 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
|
|
82
|
+
startPath[startPath.length - 2] = 0
|
|
83
|
+
for (let row = 0; row < table.rows; row++) {
|
|
84
|
+
Transforms.insertNodes(this.editor, createTableCell(""), {
|
|
85
|
+
at: startPath,
|
|
86
|
+
})
|
|
87
|
+
startPath[startPath.length - 2]++
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Transforms.setNodes(
|
|
91
|
+
this.editor,
|
|
92
|
+
{ columns: table.columns + 1 },
|
|
93
|
+
{
|
|
94
|
+
at: tablePath,
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const createRow = (cellText) => {
|
|
103
|
+
const newRow = Array.from(cellText, (value) => createTableCell(value))
|
|
104
|
+
return {
|
|
105
|
+
type: "table-row",
|
|
106
|
+
children: newRow,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const createTableCell = (text) => {
|
|
111
|
+
return {
|
|
112
|
+
type: "table-cell",
|
|
113
|
+
children: [
|
|
114
|
+
{
|
|
115
|
+
type: "p",
|
|
116
|
+
children: [{ text }],
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const createTableNode = (cellText, rows, columns) => {
|
|
123
|
+
const tableChildren = Array.from(cellText, (value) => createRow(value))
|
|
124
|
+
let tableNode = {
|
|
125
|
+
type: "table",
|
|
126
|
+
children: tableChildren,
|
|
127
|
+
rows,
|
|
128
|
+
columns,
|
|
129
|
+
}
|
|
130
|
+
return tableNode
|
|
131
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"jsx": "react-jsx",
|
|
16
|
+
|
|
17
|
+
/* Linting */
|
|
18
|
+
"strict": false,
|
|
19
|
+
"noFallthroughCasesInSwitch": true,
|
|
20
|
+
|
|
21
|
+
"paths": {
|
|
22
|
+
"@mui/material": ["../../node_modules/@mui/material"],
|
|
23
|
+
"@springmicro/utils": ["../../node_modules/@springmicro/utils"],
|
|
24
|
+
"react": ["../../node_modules/react"],
|
|
25
|
+
"react-dom": ["../../node_modules/react-dom"],
|
|
26
|
+
"react-icons": ["../../node_modules/react-icons"]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"include": ["src"],
|
|
30
|
+
"exclude": ["src/main.tsx", "**/*.stories.tsx"],
|
|
31
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
32
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import react from "@vitejs/plugin-react";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { defineConfig } from "vite";
|
|
4
|
+
import dts from "vite-plugin-dts";
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [react(), dts({ rollupTypes: true })],
|
|
8
|
+
build: {
|
|
9
|
+
lib: {
|
|
10
|
+
entry: resolve(__dirname, "src/index.tsx"),
|
|
11
|
+
name: "@springmicro/rte",
|
|
12
|
+
fileName: "index",
|
|
13
|
+
},
|
|
14
|
+
rollupOptions: {
|
|
15
|
+
external: [
|
|
16
|
+
"react",
|
|
17
|
+
"react-dom",
|
|
18
|
+
"react-icons",
|
|
19
|
+
"@mui/material",
|
|
20
|
+
"@springmicro/utils",
|
|
21
|
+
],
|
|
22
|
+
output: {
|
|
23
|
+
globals: {
|
|
24
|
+
react: "React",
|
|
25
|
+
"react-dom": "React-dom",
|
|
26
|
+
"react-icons": "React-icons",
|
|
27
|
+
"@mui/material": "MuiMaterial",
|
|
28
|
+
"@springmicro/utils": "SpringMicroUtils",
|
|
29
|
+
},
|
|
30
|
+
// manualChunks(id: string) {
|
|
31
|
+
// if (id.includes("domhandler")) {
|
|
32
|
+
// return "domhandler";
|
|
33
|
+
// }
|
|
34
|
+
// if (id.includes("escape-html")) {
|
|
35
|
+
// return "escape-html";
|
|
36
|
+
// }
|
|
37
|
+
// },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|