@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.
- package/.babelrc +44 -0
- package/README.md +5 -0
- package/componentLoader.js +52 -0
- package/dist/BlockEditor.css +93 -0
- package/dist/BlockEditor.js +2 -0
- package/dist/BlockEditor.js.LICENSE.txt +61 -0
- package/dist/Renderer.js +2 -0
- package/dist/Renderer.js.LICENSE.txt +15 -0
- package/dist/fromHTML.js +1 -0
- package/dist/index.css +93 -0
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +69 -0
- package/dist/toHTML.js +2 -0
- package/dist/toHTML.js.LICENSE.txt +23 -0
- package/dist/toText.js +2 -0
- package/dist/toText.js.LICENSE.txt +23 -0
- package/package.json +79 -0
- package/postcss.config.js +7 -0
- package/scss/demo.scss +142 -0
- package/scss/editor.scss +394 -0
- package/scss/storybook.scss +66 -0
- package/scss/toolbar.scss +160 -0
- package/src/BlockEditor.js +252 -0
- package/src/Blocks/EmptyBlock.js +12 -0
- package/src/Blocks/EmptyWrapper.js +5 -0
- package/src/Blocks/ErrorBoundary.js +41 -0
- package/src/Blocks/LayoutBlock.js +179 -0
- package/src/Blocks/LayoutSlot.js +61 -0
- package/src/Context/StorybookContext.js +7 -0
- package/src/Nodes/Default.js +151 -0
- package/src/Nodes/Element.js +72 -0
- package/src/Nodes/Leaf.js +40 -0
- package/src/Nodes/Storybook.js +170 -0
- package/src/Nodes/StorybookDisplay.js +118 -0
- package/src/Nodes/Text.js +67 -0
- package/src/Renderer.js +41 -0
- package/src/Serializer/Html.js +43 -0
- package/src/Serializer/Serializer.js +318 -0
- package/src/Serializer/Text.js +18 -0
- package/src/Serializer/ads.js +175 -0
- package/src/Serializer/index.js +4 -0
- package/src/SidebarEditor/SidebarEditorField.js +249 -0
- package/src/SidebarEditor.css +90 -0
- package/src/SidebarEditor.js +236 -0
- package/src/Storybook.js +152 -0
- package/src/Toolbar/Align.js +65 -0
- package/src/Toolbar/Block.js +121 -0
- package/src/Toolbar/Element.js +49 -0
- package/src/Toolbar/Formats.js +60 -0
- package/src/Toolbar/Insert.js +29 -0
- package/src/Toolbar/Layout.js +333 -0
- package/src/Toolbar/Link.js +165 -0
- package/src/Toolbar/Toolbar.js +164 -0
- package/src/Tools/Margin.js +52 -0
- package/src/dev/App.js +61 -0
- package/src/dev/draftToSlate.json +3148 -0
- package/src/dev/index.css +3 -0
- package/src/dev/index.html +11 -0
- package/src/dev/index.js +5 -0
- package/src/dev/sampleValue1.json +4295 -0
- package/src/dev/sampleValue2.json +0 -0
- package/src/dev/sampleValueValid.json +411 -0
- package/src/dev/testComponents/TestStory.js +9 -0
- package/src/dev/testComponents/TestStory.stories.js +172 -0
- package/src/dev/testSampleValue.json +747 -0
- package/src/fromHTML.js +5 -0
- package/src/index.js +9 -0
- package/src/plugins/ListItem.js +49 -0
- package/src/plugins/SoftBreak.js +24 -0
- package/src/toHTML.js +7 -0
- package/src/toText.js +7 -0
- package/src/util.js +20 -0
- package/storyLoader.js +46 -0
- package/tailwind.config.js +5 -0
- package/webpack.config.build.js +53 -0
- package/webpack.config.dev.js +61 -0
- package/webpack.config.js +117 -0
package/src/fromHTML.js
ADDED
package/src/index.js
ADDED
|
@@ -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
package/src/toText.js
ADDED
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,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
|
+
};
|