@vonaffenfels/slate-editor 1.2.18 → 1.2.19

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 (81) hide show
  1. package/.babelrc +43 -43
  2. package/README.md +5 -5
  3. package/componentLoader.js +93 -93
  4. package/package.json +2 -2
  5. package/postcss.config.js +6 -6
  6. package/scss/demo.scss +148 -148
  7. package/scss/sidebarEditor.scss +185 -185
  8. package/scss/toolbar.scss +162 -162
  9. package/src/Blocks/EmptyBlock.js +11 -11
  10. package/src/Blocks/EmptyWrapper.js +4 -4
  11. package/src/Blocks/ErrorBoundary.js +40 -40
  12. package/src/Blocks/LayoutBlock.js +274 -274
  13. package/src/Blocks/LayoutSlot.js +90 -90
  14. package/src/CollapsableMenu/CollapsableMenu.js +48 -48
  15. package/src/Context/StorybookContext.js +6 -6
  16. package/src/ElementAutocomplete.js +134 -134
  17. package/src/Loader.js +137 -137
  18. package/src/Nodes/Default.js +162 -162
  19. package/src/Nodes/Leaf.js +54 -54
  20. package/src/Nodes/Text.js +97 -97
  21. package/src/ObjectId.js +3 -3
  22. package/src/Renderer.js +73 -73
  23. package/src/Serializer/Html.js +42 -42
  24. package/src/Serializer/Serializer.js +371 -371
  25. package/src/Serializer/Text.js +17 -17
  26. package/src/Serializer/ads.js +187 -187
  27. package/src/Serializer/index.js +3 -3
  28. package/src/SidebarEditor/AssetList.js +181 -181
  29. package/src/SidebarEditor/Fields/CloudinaryContentSelect.js +89 -89
  30. package/src/SidebarEditor/Fields/ColorPicker.js +89 -89
  31. package/src/SidebarEditor/Fields/ContentfulContentSelect.js +62 -62
  32. package/src/SidebarEditor/Fields/DateTime.js +55 -55
  33. package/src/SidebarEditor/Fields/MVP.js +66 -66
  34. package/src/SidebarEditor/Fields/MultiSelect.js +13 -13
  35. package/src/SidebarEditor/Fields/RemoteMultiSelect.js +40 -40
  36. package/src/SidebarEditor/Fields/RemoteSelect.js +39 -39
  37. package/src/SidebarEditor/Fields/Select.js +47 -47
  38. package/src/SidebarEditor/Fields/StreamSelect.js +15 -15
  39. package/src/SidebarEditor/Fields/Switch.js +34 -34
  40. package/src/SidebarEditor/Fields/Textarea.js +21 -21
  41. package/src/SidebarEditor/Resizable.js +85 -85
  42. package/src/Storybook.js +151 -151
  43. package/src/Toolbar/Align.js +64 -64
  44. package/src/Toolbar/Anchor.js +94 -94
  45. package/src/Toolbar/Block.js +135 -135
  46. package/src/Toolbar/Element.js +44 -44
  47. package/src/Toolbar/Formats.js +71 -71
  48. package/src/Toolbar/Insert.js +28 -28
  49. package/src/Toolbar/Layout.js +399 -399
  50. package/src/Toolbar/Link.js +164 -164
  51. package/src/Toolbar/Toolbar.js +235 -235
  52. package/src/Tools/Margin.js +51 -51
  53. package/src/Translation/TranslationToolbarButton.js +119 -119
  54. package/src/dev/draftToSlate.json +3147 -3147
  55. package/src/dev/index.css +2 -2
  56. package/src/dev/index.html +10 -10
  57. package/src/dev/index.js +4 -4
  58. package/src/dev/sampleValue1.json +4294 -4294
  59. package/src/dev/sampleValueValid.json +410 -410
  60. package/src/dev/testComponents/TestStory.js +74 -74
  61. package/src/dev/testComponents/TestStory.stories.js +216 -216
  62. package/src/dev/testComponents/TestStory2.js +74 -74
  63. package/src/dev/testComponents/TestStory2.stories.js +197 -197
  64. package/src/dev/testComponents/TestStory3.js +74 -74
  65. package/src/dev/testComponents/TestStory3.stories.js +197 -197
  66. package/src/dev/testSampleValue.json +746 -746
  67. package/src/fromHTML.js +4 -4
  68. package/src/helper/array.js +8 -8
  69. package/src/index.js +10 -10
  70. package/src/plugins/ListItem.js +48 -48
  71. package/src/plugins/SoftBreak.js +23 -23
  72. package/src/toHTML.js +6 -6
  73. package/src/toText.js +6 -6
  74. package/src/util/reduceContentfulResponse.js +64 -64
  75. package/src/util.js +19 -19
  76. package/storyLoader.js +47 -47
  77. package/tailwind.config.js +4 -4
  78. package/webpack.config.build.js +55 -55
  79. package/webpack.config.dev.js +60 -60
  80. package/webpack.config.js +130 -130
  81. package/webpack.config.watch.js +4 -4
package/src/fromHTML.js CHANGED
@@ -1,5 +1,5 @@
1
- const fromHTML = (htmlValue) => {
2
-
3
- };
4
-
1
+ const fromHTML = (htmlValue) => {
2
+
3
+ };
4
+
5
5
  export default fromHTML;
@@ -1,9 +1,9 @@
1
- export const swapArrayElements = (array, index1, index2) => {
2
- let newArray = JSON.parse(JSON.stringify(array));
3
-
4
- let temp = newArray[index1];
5
- newArray[index1] = newArray[index2];
6
- newArray[index2] = temp;
7
-
8
- return newArray;
1
+ export const swapArrayElements = (array, index1, index2) => {
2
+ let newArray = JSON.parse(JSON.stringify(array));
3
+
4
+ let temp = newArray[index1];
5
+ newArray[index1] = newArray[index2];
6
+ newArray[index2] = temp;
7
+
8
+ return newArray;
9
9
  };
package/src/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import "../scss/editor.scss";
2
-
3
- import BlockEditor from "./BlockEditor";
4
- import Renderer from "./Renderer";
5
- import {HtmlSerializer} from "./Serializer";
6
-
7
- export {
8
- BlockEditor,
9
- Renderer,
10
- HtmlSerializer,
1
+ import "../scss/editor.scss";
2
+
3
+ import BlockEditor from "./BlockEditor";
4
+ import Renderer from "./Renderer";
5
+ import {HtmlSerializer} from "./Serializer";
6
+
7
+ export {
8
+ BlockEditor,
9
+ Renderer,
10
+ HtmlSerializer,
11
11
  };
@@ -1,49 +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;
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
49
  };
@@ -1,24 +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
- },
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
24
  };
package/src/toHTML.js CHANGED
@@ -1,7 +1,7 @@
1
- import {HtmlSerializer} from "./Serializer/Html";
2
-
3
- const toHTML = (editorValue) => {
4
- return HtmlSerializer(editorValue);
5
- };
6
-
1
+ import {HtmlSerializer} from "./Serializer/Html";
2
+
3
+ const toHTML = (editorValue) => {
4
+ return HtmlSerializer(editorValue);
5
+ };
6
+
7
7
  export default toHTML;
package/src/toText.js CHANGED
@@ -1,7 +1,7 @@
1
- import {TextSerializer} from "./Serializer/Text";
2
-
3
- const toText = (editorValue) => {
4
- return TextSerializer(editorValue);
5
- };
6
-
1
+ import {TextSerializer} from "./Serializer/Text";
2
+
3
+ const toText = (editorValue) => {
4
+ return TextSerializer(editorValue);
5
+ };
6
+
7
7
  export default toText;
@@ -1,65 +1,65 @@
1
- export const reduceContentfulResponse = (item, paths) => {
2
-
3
- if (Array.isArray(item)) {
4
- return item.map(v => reduceContentfulResponse(v, paths));
5
- }
6
-
7
- if (!paths?.length || !item) {
8
- return item;
9
- }
10
-
11
- const defaultPaths = [
12
- "__typename",
13
- "sys.id",
14
- "sys.contentType.sys.id",
15
- ];
16
- const mergedPaths = [...defaultPaths, ...paths];
17
-
18
- const result = {
19
- sys: {
20
- id: item?.sys?.id,
21
- },
22
- };
23
-
24
- for (let i = 0; i < mergedPaths.length; i++) {
25
- const path = mergedPaths[i];
26
-
27
- setByPath(result, path, getByPath(item, path));
28
- }
29
-
30
- return result;
31
- };
32
-
33
- export const getByPath = (obj, path) => {
34
- if (!obj || !path) {
35
- return;
36
- }
37
-
38
- const pathParts = path.split(".");
39
-
40
- if (pathParts.length === 1) {
41
- return obj?.[pathParts[0]];
42
- } else {
43
- const currPart = pathParts.shift();
44
- return getByPath(obj?.[currPart], pathParts.join("."));
45
- }
46
- };
47
-
48
- export const setByPath = (obj, path, value) => {
49
- const pathParts = path.split(".");
50
- let objPointer = obj;
51
-
52
- for (let i = 0; i < pathParts.length; i++) {
53
- const pathPart = pathParts[i];
54
-
55
- if (i === pathParts.length - 1) {
56
- objPointer[pathPart] = value;
57
- } else if (objPointer[pathPart] === undefined) {
58
- objPointer[pathPart] = {};
59
- }
60
-
61
- objPointer = objPointer[pathPart];
62
- }
63
-
64
- return obj;
1
+ export const reduceContentfulResponse = (item, paths) => {
2
+
3
+ if (Array.isArray(item)) {
4
+ return item.map(v => reduceContentfulResponse(v, paths));
5
+ }
6
+
7
+ if (!paths?.length || !item) {
8
+ return item;
9
+ }
10
+
11
+ const defaultPaths = [
12
+ "__typename",
13
+ "sys.id",
14
+ "sys.contentType.sys.id",
15
+ ];
16
+ const mergedPaths = [...defaultPaths, ...paths];
17
+
18
+ const result = {
19
+ sys: {
20
+ id: item?.sys?.id,
21
+ },
22
+ };
23
+
24
+ for (let i = 0; i < mergedPaths.length; i++) {
25
+ const path = mergedPaths[i];
26
+
27
+ setByPath(result, path, getByPath(item, path));
28
+ }
29
+
30
+ return result;
31
+ };
32
+
33
+ export const getByPath = (obj, path) => {
34
+ if (!obj || !path) {
35
+ return;
36
+ }
37
+
38
+ const pathParts = path.split(".");
39
+
40
+ if (pathParts.length === 1) {
41
+ return obj?.[pathParts[0]];
42
+ } else {
43
+ const currPart = pathParts.shift();
44
+ return getByPath(obj?.[currPart], pathParts.join("."));
45
+ }
46
+ };
47
+
48
+ export const setByPath = (obj, path, value) => {
49
+ const pathParts = path.split(".");
50
+ let objPointer = obj;
51
+
52
+ for (let i = 0; i < pathParts.length; i++) {
53
+ const pathPart = pathParts[i];
54
+
55
+ if (i === pathParts.length - 1) {
56
+ objPointer[pathPart] = value;
57
+ } else if (objPointer[pathPart] === undefined) {
58
+ objPointer[pathPart] = {};
59
+ }
60
+
61
+ objPointer = objPointer[pathPart];
62
+ }
63
+
64
+ return obj;
65
65
  };
package/src/util.js CHANGED
@@ -1,20 +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);
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
20
  };
package/storyLoader.js CHANGED
@@ -1,48 +1,48 @@
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
- this.addContextDependency(options.storiesRoot);
12
- console.log(`Found ${files.length} stories in ${options.storiesRoot}`);
13
-
14
- return `
15
- export default async () => Promise.all([${files.map(file => "import('" + options.storiesImportRoot + "/" + file + "')").join(",")}]).then(modules => modules.reduce((curr, module) => {
16
- const story = {};
17
- const baseStory = module.default;
18
-
19
- story.id = baseStory.id;
20
- story.argTypes = baseStory.argTypes;
21
- story.storyContext = baseStory.storyContext;
22
- story.portalContext = baseStory.portalContext;
23
- story.title = baseStory.title;
24
- story.stories = [
25
- {
26
- title: baseStory.title,
27
- args: baseStory.args
28
- }
29
- ]
30
-
31
- for(let exportName in module) {
32
-
33
- if(module && module.hasOwnProperty(exportName) && exportName !== "default") {
34
- const exportedStory = module[exportName];
35
-
36
- if(exportedStory) {
37
- story.stories.push({
38
- title: exportName,
39
- args: exportedStory.args
40
- })
41
- }
42
- }
43
- }
44
-
45
- return [...curr, story];
46
- }, []))
47
- `;
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
+ this.addContextDependency(options.storiesRoot);
12
+ console.log(`Found ${files.length} stories in ${options.storiesRoot}`);
13
+
14
+ return `
15
+ export default async () => Promise.all([${files.map(file => "import('" + options.storiesImportRoot + "/" + file + "')").join(",")}]).then(modules => modules.reduce((curr, module) => {
16
+ const story = {};
17
+ const baseStory = module.default;
18
+
19
+ story.id = baseStory.id;
20
+ story.argTypes = baseStory.argTypes;
21
+ story.storyContext = baseStory.storyContext;
22
+ story.portalContext = baseStory.portalContext;
23
+ story.title = baseStory.title;
24
+ story.stories = [
25
+ {
26
+ title: baseStory.title,
27
+ args: baseStory.args
28
+ }
29
+ ]
30
+
31
+ for(let exportName in module) {
32
+
33
+ if(module && module.hasOwnProperty(exportName) && exportName !== "default") {
34
+ const exportedStory = module[exportName];
35
+
36
+ if(exportedStory) {
37
+ story.stories.push({
38
+ title: exportName,
39
+ args: exportedStory.args
40
+ })
41
+ }
42
+ }
43
+ }
44
+
45
+ return [...curr, story];
46
+ }, []))
47
+ `;
48
48
  };
@@ -1,5 +1,5 @@
1
- module.exports = {
2
- content: [
3
- './src/**/*.js',
4
- ],
1
+ module.exports = {
2
+ content: [
3
+ './src/**/*.js',
4
+ ],
5
5
  };
@@ -1,56 +1,56 @@
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
- next: "next",
8
- "react-dom": "react-dom",
9
- "prop-types": "prop-types",
10
- };
11
-
12
- config.module = {
13
- rules: [
14
- {
15
- test: /\.js$/,
16
- include: [
17
- path.resolve(__dirname, 'src'),
18
- path.resolve(
19
- __dirname, '..', '..', '@frontend', 'components',
20
- ), // symlinks!
21
- ],
22
- exclude: [
23
- path.resolve(
24
- __dirname, '..', '..', '@frontend', 'components', 'node_modules',
25
- ),
26
- ],
27
- loader: 'babel-loader',
28
- },
29
- {
30
- test: /\.s[ac]ss$/i,
31
- include: path.resolve(__dirname, 'scss'),
32
- use: [
33
- {
34
- loader: MiniCssExtractPlugin.loader,
35
- options: {esModule: false},
36
- },
37
- "css-loader",
38
- "sass-loader",
39
- {loader: 'postcss-loader'},
40
- ],
41
- },
42
- {
43
- test: /\.css$/,
44
- use: [
45
- {
46
- loader: MiniCssExtractPlugin.loader,
47
- options: {esModule: false},
48
- },
49
- 'css-loader',
50
- {loader: 'postcss-loader'},
51
- ],
52
- },
53
- ],
54
- };
55
-
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
+ next: "next",
8
+ "react-dom": "react-dom",
9
+ "prop-types": "prop-types",
10
+ };
11
+
12
+ config.module = {
13
+ rules: [
14
+ {
15
+ test: /\.js$/,
16
+ include: [
17
+ path.resolve(__dirname, 'src'),
18
+ path.resolve(
19
+ __dirname, '..', '..', '@frontend', 'components',
20
+ ), // symlinks!
21
+ ],
22
+ exclude: [
23
+ path.resolve(
24
+ __dirname, '..', '..', '@frontend', 'components', 'node_modules',
25
+ ),
26
+ ],
27
+ loader: 'babel-loader',
28
+ },
29
+ {
30
+ test: /\.s[ac]ss$/i,
31
+ include: path.resolve(__dirname, 'scss'),
32
+ use: [
33
+ {
34
+ loader: MiniCssExtractPlugin.loader,
35
+ options: {esModule: false},
36
+ },
37
+ "css-loader",
38
+ "sass-loader",
39
+ {loader: 'postcss-loader'},
40
+ ],
41
+ },
42
+ {
43
+ test: /\.css$/,
44
+ use: [
45
+ {
46
+ loader: MiniCssExtractPlugin.loader,
47
+ options: {esModule: false},
48
+ },
49
+ 'css-loader',
50
+ {loader: 'postcss-loader'},
51
+ ],
52
+ },
53
+ ],
54
+ };
55
+
56
56
  module.exports = config;