@vonaffenfels/slate-editor 1.0.1

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.
Files changed (77) hide show
  1. package/.babelrc +44 -0
  2. package/README.md +5 -0
  3. package/componentLoader.js +52 -0
  4. package/dist/BlockEditor.css +93 -0
  5. package/dist/BlockEditor.js +2 -0
  6. package/dist/BlockEditor.js.LICENSE.txt +61 -0
  7. package/dist/Renderer.js +2 -0
  8. package/dist/Renderer.js.LICENSE.txt +15 -0
  9. package/dist/fromHTML.js +1 -0
  10. package/dist/index.css +93 -0
  11. package/dist/index.js +2 -0
  12. package/dist/index.js.LICENSE.txt +69 -0
  13. package/dist/toHTML.js +2 -0
  14. package/dist/toHTML.js.LICENSE.txt +23 -0
  15. package/dist/toText.js +2 -0
  16. package/dist/toText.js.LICENSE.txt +23 -0
  17. package/package.json +79 -0
  18. package/postcss.config.js +7 -0
  19. package/scss/demo.scss +142 -0
  20. package/scss/editor.scss +394 -0
  21. package/scss/storybook.scss +66 -0
  22. package/scss/toolbar.scss +160 -0
  23. package/src/BlockEditor.js +252 -0
  24. package/src/Blocks/EmptyBlock.js +12 -0
  25. package/src/Blocks/EmptyWrapper.js +5 -0
  26. package/src/Blocks/ErrorBoundary.js +41 -0
  27. package/src/Blocks/LayoutBlock.js +179 -0
  28. package/src/Blocks/LayoutSlot.js +61 -0
  29. package/src/Context/StorybookContext.js +7 -0
  30. package/src/Nodes/Default.js +151 -0
  31. package/src/Nodes/Element.js +72 -0
  32. package/src/Nodes/Leaf.js +40 -0
  33. package/src/Nodes/Storybook.js +170 -0
  34. package/src/Nodes/StorybookDisplay.js +118 -0
  35. package/src/Nodes/Text.js +67 -0
  36. package/src/Renderer.js +41 -0
  37. package/src/Serializer/Html.js +43 -0
  38. package/src/Serializer/Serializer.js +318 -0
  39. package/src/Serializer/Text.js +18 -0
  40. package/src/Serializer/ads.js +175 -0
  41. package/src/Serializer/index.js +4 -0
  42. package/src/SidebarEditor/SidebarEditorField.js +249 -0
  43. package/src/SidebarEditor.css +90 -0
  44. package/src/SidebarEditor.js +236 -0
  45. package/src/Storybook.js +152 -0
  46. package/src/Toolbar/Align.js +65 -0
  47. package/src/Toolbar/Block.js +121 -0
  48. package/src/Toolbar/Element.js +49 -0
  49. package/src/Toolbar/Formats.js +60 -0
  50. package/src/Toolbar/Insert.js +29 -0
  51. package/src/Toolbar/Layout.js +333 -0
  52. package/src/Toolbar/Link.js +165 -0
  53. package/src/Toolbar/Toolbar.js +164 -0
  54. package/src/Tools/Margin.js +52 -0
  55. package/src/dev/App.js +61 -0
  56. package/src/dev/draftToSlate.json +3148 -0
  57. package/src/dev/index.css +3 -0
  58. package/src/dev/index.html +11 -0
  59. package/src/dev/index.js +5 -0
  60. package/src/dev/sampleValue1.json +4295 -0
  61. package/src/dev/sampleValue2.json +0 -0
  62. package/src/dev/sampleValueValid.json +411 -0
  63. package/src/dev/testComponents/TestStory.js +9 -0
  64. package/src/dev/testComponents/TestStory.stories.js +172 -0
  65. package/src/dev/testSampleValue.json +747 -0
  66. package/src/fromHTML.js +5 -0
  67. package/src/index.js +9 -0
  68. package/src/plugins/ListItem.js +49 -0
  69. package/src/plugins/SoftBreak.js +24 -0
  70. package/src/toHTML.js +7 -0
  71. package/src/toText.js +7 -0
  72. package/src/util.js +20 -0
  73. package/storyLoader.js +46 -0
  74. package/tailwind.config.js +5 -0
  75. package/webpack.config.build.js +53 -0
  76. package/webpack.config.dev.js +61 -0
  77. package/webpack.config.js +117 -0
@@ -0,0 +1,5 @@
1
+ const fromHTML = (htmlValue) => {
2
+
3
+ };
4
+
5
+ export default fromHTML;
package/src/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import BlockEditor from "./BlockEditor";
2
+ import Renderer from "./Renderer";
3
+ import {HtmlSerializer} from "./Serializer";
4
+
5
+ export {
6
+ BlockEditor,
7
+ Renderer,
8
+ HtmlSerializer,
9
+ };
@@ -0,0 +1,49 @@
1
+ import {ReactEditor} from "slate-react";
2
+ import {Transforms} from "slate";
3
+
4
+ export const ListItemPlugin = {
5
+ onKeyDown(event, editor) {
6
+ if (event.key !== 'Enter') {
7
+ return;
8
+ }
9
+
10
+ if (event.shiftKey === true) {
11
+ return;
12
+ }
13
+
14
+ if (!editor.selection) {
15
+ return;
16
+ }
17
+
18
+ const [node, index] = ReactEditor.toDOMPoint(editor, editor.selection.anchor);
19
+
20
+ if (isNodeBelowLi(node)) {
21
+ event.preventDefault();
22
+ Transforms.insertNodes(editor, {
23
+ at: editor.selection.anchor.path,
24
+ match: node => {
25
+ return node.type === "list-item";
26
+ },
27
+ type: "list-item",
28
+ children: [{text: ""}],
29
+ });
30
+ return true;
31
+ }
32
+ },
33
+ };
34
+
35
+ const isNodeBelowLi = (node) => {
36
+ if (node.tagName === "LI") {
37
+ return true;
38
+ }
39
+
40
+ if (node.parentElement) {
41
+ if (node.parentElement.tagName === "LI") {
42
+ return true;
43
+ }
44
+
45
+ return isNodeBelowLi(node.parentElement);
46
+ }
47
+
48
+ return false;
49
+ };
@@ -0,0 +1,24 @@
1
+ import {
2
+ getNodeFromPath, getNodeParentFromPath,
3
+ } from "../util";
4
+
5
+ export const SoftBreakPlugin = {
6
+ onKeyDown(event, editor) {
7
+ if (event.key !== 'Enter') {
8
+ return;
9
+ }
10
+
11
+ if (event.shiftKey === false) {
12
+ event.preventDefault();
13
+ if (editor.selection) {
14
+ return editor.insertNode({
15
+ type: "paragraph",
16
+ children: [{text: ""}],
17
+ });
18
+ }
19
+ }
20
+
21
+ event.preventDefault();
22
+ editor.insertText('\n');
23
+ },
24
+ };
package/src/toHTML.js ADDED
@@ -0,0 +1,7 @@
1
+ import {HtmlSerializer} from "./Serializer/Html";
2
+
3
+ const toHTML = (editorValue) => {
4
+ return HtmlSerializer(editorValue);
5
+ };
6
+
7
+ export default toHTML;
package/src/toText.js ADDED
@@ -0,0 +1,7 @@
1
+ import {TextSerializer} from "./Serializer/Text";
2
+
3
+ const toText = (editorValue) => {
4
+ return TextSerializer(editorValue);
5
+ };
6
+
7
+ export default toText;
package/src/util.js ADDED
@@ -0,0 +1,20 @@
1
+ export const getNodeFromPath = (editor, path) => {
2
+ let internalPath = [...path];
3
+ if (internalPath.length === 0) {
4
+ return editor;
5
+ }
6
+
7
+ const currPath = internalPath.shift();
8
+
9
+ return getNodeFromPath(editor?.children?.[currPath], internalPath);
10
+ };
11
+
12
+ export const getNodeParentFromPath = (editor, path) => {
13
+ let internalPath = [...path];
14
+ if (internalPath.length === 1) {
15
+ return editor;
16
+ }
17
+
18
+ const currPath = internalPath.shift();
19
+ return getNodeParentFromPath(editor?.children?.[currPath], internalPath);
20
+ };
package/storyLoader.js ADDED
@@ -0,0 +1,46 @@
1
+ const walkSync = require("walk-sync");
2
+
3
+ module.exports = async function storiesLoader() {
4
+ const options = this.getOptions();
5
+
6
+ const files = walkSync(options.storiesRoot, {
7
+ directories: false,
8
+ globs: ["**/*.stories.js", "**/*.stories.jsx", "**/*.stories.ts"],
9
+ });
10
+
11
+ console.log(`Found ${files.length} stories in ${options.storiesRoot}`);
12
+
13
+ return `
14
+ export default async () => Promise.all([${files.map(file => "import('" + options.storiesImportRoot + "/" + file + "')").join(",")}]).then(modules => modules.reduce((curr, module) => {
15
+ const story = {};
16
+ const baseStory = module.default;
17
+
18
+ story.id = baseStory.id;
19
+ story.argTypes = baseStory.argTypes;
20
+ story.storyContext = baseStory.storyContext;
21
+ story.title = baseStory.title;
22
+ story.stories = [
23
+ {
24
+ title: baseStory.title,
25
+ args: baseStory.args
26
+ }
27
+ ]
28
+
29
+ for(let exportName in module) {
30
+
31
+ if(module && module.hasOwnProperty(exportName) && exportName !== "default") {
32
+ const exportedStory = module[exportName];
33
+
34
+ if(exportedStory) {
35
+ story.stories.push({
36
+ title: exportName,
37
+ args: exportedStory.args
38
+ })
39
+ }
40
+ }
41
+ }
42
+
43
+ return [...curr, story];
44
+ }, []))
45
+ `;
46
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ content: [
3
+ './src/**/*.js',
4
+ ],
5
+ };
@@ -0,0 +1,53 @@
1
+ const path = require('path');
2
+ const config = require("./webpack.config");
3
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4
+
5
+ config.externals = {
6
+ react: "react",
7
+ "react-dom": "react-dom",
8
+ "prop-types": "prop-types",
9
+ };
10
+
11
+ config.module = {
12
+ rules: [
13
+ {
14
+ test: /\.js$/,
15
+ include: [
16
+ path.resolve(__dirname, 'src'),
17
+ path.resolve(
18
+ __dirname, '..', '..', '@frontend', 'components',
19
+ ), // symlinks!
20
+ ],
21
+ exclude: [
22
+ path.resolve(
23
+ __dirname, '..', '..', '@frontend', 'components', 'node_modules',
24
+ ),
25
+ ],
26
+ loader: 'babel-loader',
27
+ },
28
+ {
29
+ test: /\.s[ac]ss$/i,
30
+ include: path.resolve(__dirname, 'scss'),
31
+ use: [
32
+ {
33
+ loader: MiniCssExtractPlugin.loader,
34
+ options: {esModule: false},
35
+ },
36
+ "css-loader",
37
+ "sass-loader",
38
+ ],
39
+ },
40
+ {
41
+ test: /\.css$/,
42
+ use: [
43
+ {
44
+ loader: MiniCssExtractPlugin.loader,
45
+ options: {esModule: false},
46
+ },
47
+ 'css-loader',
48
+ ],
49
+ },
50
+ ],
51
+ };
52
+
53
+ module.exports = config;
@@ -0,0 +1,61 @@
1
+ const path = require('path');
2
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
3
+ const config = require("./webpack.config");
4
+ const Dotenv = require("dotenv-webpack");
5
+
6
+ config.mode = "development";
7
+ config.watchOptions = {ignored: ['dist/**', 'node_modules/**']};
8
+ config.cache = {type: "memory"};
9
+
10
+ config.resolve.alias.react = path.resolve(__dirname, '../../node_modules/react');
11
+ config.resolve.alias["react-dom"] = path.resolve(__dirname, '../../node_modules/react-dom');
12
+ config.resolve.alias.storybookStories = path.resolve(__dirname, 'storyLoader.js');
13
+
14
+ config.entry.dev = './src/dev/index.js';
15
+ config.module.rules.unshift({
16
+ test: /storyLoader.js/i,
17
+ use: [
18
+ {
19
+ loader: path.resolve(__dirname + "/storyLoader.js"),
20
+ options: {
21
+ storiesRoot: path.resolve(__dirname + "/src/dev/testComponents"),
22
+ storiesImportRoot: "@vonaffenfels/slate-editor/src/dev/testComponents",
23
+ },
24
+ },
25
+ ],
26
+ });
27
+ config.module.rules.unshift({
28
+ test: /componentLoader.js/i,
29
+ use: [
30
+ {
31
+ loader: "@vonaffenfels/slate-editor/componentLoader.js",
32
+ options: {
33
+ componentRoot: path.resolve(__dirname + "/src/dev/testComponents"),
34
+ componentImportRoot: "@vonaffenfels/slate-editor/src/dev/testComponents",
35
+ },
36
+ },
37
+ ],
38
+ })
39
+
40
+ config.devtool = 'inline-source-map';
41
+
42
+ config.plugins.push(new Dotenv());
43
+ config.plugins.push(new HtmlWebpackPlugin({
44
+ title: 'Development',
45
+ filename: 'index.html',
46
+ template: path.join(
47
+ __dirname, 'src', 'dev', 'index.html',
48
+ ),
49
+ }));
50
+
51
+ config.devServer = {
52
+ static: {
53
+ serveIndex: true,
54
+ publicPath: path.join(__dirname, 'dist'),
55
+ },
56
+ compress: true,
57
+ liveReload: true,
58
+ port: 9000,
59
+ };
60
+
61
+ module.exports = config;
@@ -0,0 +1,117 @@
1
+ const path = require('path');
2
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
3
+ const Dotenv = require("dotenv-webpack");
4
+ const {readFileSync} = require("fs");
5
+ const babelConfig = JSON.parse(readFileSync(__dirname + "/.babelrc").toString());
6
+
7
+ module.exports = {
8
+ mode: 'production',
9
+ entry: {
10
+ BlockEditor: './src/BlockEditor.js',
11
+ Renderer: './src/Renderer.js',
12
+ toHTML: './src/toHTML.js',
13
+ fromHTML: './src/fromHTML.js',
14
+ toText: './src/toText.js',
15
+ index: './src/index.js',
16
+ },
17
+ module: {
18
+ rules: [
19
+ {
20
+ test: /\.js$/,
21
+ include: [
22
+ path.resolve(__dirname, 'src'),
23
+ ],
24
+ use: [
25
+ {
26
+ loader: 'babel-loader',
27
+ options: babelConfig,
28
+ },
29
+ ],
30
+ },
31
+ {
32
+ test: /\.s[ac]ss$/i,
33
+ include: path.resolve(__dirname, 'scss'),
34
+ use: [
35
+ "style-loader",
36
+ "css-loader",
37
+ "sass-loader",
38
+ ],
39
+ },
40
+ {
41
+ test: /\.css$/i,
42
+ use: [
43
+ 'style-loader',
44
+ {
45
+ loader: 'css-loader',
46
+ options: {importLoaders: 1},
47
+ },
48
+ {loader: 'postcss-loader'},
49
+ ],
50
+ },
51
+ {
52
+ test: /\.svg$/,
53
+ exclude: /node_modules/,
54
+ resourceQuery: {not: [/url/]}, // exclude react component if *.svg?url
55
+ use: [
56
+ {
57
+ loader: '@svgr/webpack',
58
+ options: {
59
+ dimensions: false,
60
+ svgo: false,
61
+ },
62
+ },
63
+ ],
64
+ },
65
+ {
66
+ test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
67
+ use: [
68
+ {
69
+ loader: 'file-loader',
70
+ options: {
71
+ name: '[name].[ext]',
72
+ outputPath: 'fonts/',
73
+ },
74
+ },
75
+ ],
76
+ },
77
+ {
78
+ test: /\.(png)(\?v=\d+\.\d+\.\d+)?$/,
79
+ use: [
80
+ {
81
+ loader: 'file-loader',
82
+ options: {
83
+ name: '[name].[ext]',
84
+ outputPath: 'img/',
85
+ },
86
+ },
87
+ ],
88
+ },
89
+ ],
90
+ },
91
+ resolve: {
92
+ extensions: ['.js', '.json', '.jsx'],
93
+ fallback: {
94
+ stream: false,
95
+ buffer: false,
96
+ util: false,
97
+ path: false,
98
+ fs: false,
99
+ timers: false,
100
+ },
101
+ alias: {
102
+ scss: path.resolve(__dirname, 'scss'),
103
+ "@vonaffenfels/slate-editor/dist": path.resolve(__dirname, 'src'),
104
+ },
105
+ },
106
+ plugins: [
107
+ new Dotenv({systemvars: true}),
108
+ new MiniCssExtractPlugin({}),
109
+ ],
110
+ output: {
111
+ filename: '[name].js',
112
+ libraryTarget: "umd",
113
+ publicPath: "/dist/",
114
+ globalObject: "this",
115
+ path: path.resolve(__dirname, 'dist'),
116
+ },
117
+ };