@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
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@vonaffenfels/slate-editor",
3
+ "version": "1.0.1",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "prepublish": "yarn run build",
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "build": "rm -rf dist && webpack --config webpack.config.build.js",
10
+ "buildWatch": "rm -rf dist && webpack --config webpack.config.build.js --watch",
11
+ "dev": "webpack serve --config webpack.config.dev.js --open"
12
+ },
13
+ "author": "",
14
+ "license": "ISC",
15
+ "peerDependencies": {
16
+ "react": "17.0.2",
17
+ "react-dom": "17.0.2"
18
+ },
19
+ "devDependencies": {
20
+ "@babel/core": "^7.20.12",
21
+ "@babel/plugin-proposal-class-properties": "^7.12.13",
22
+ "@babel/plugin-proposal-private-methods": "^7.18.6",
23
+ "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
24
+ "@babel/plugin-syntax-dynamic-import": "^7.8.3",
25
+ "@babel/preset-env": "^7.13.15",
26
+ "@babel/preset-react": "^7.13.13",
27
+ "@contentful/forma-36-react-components": "^3.100.7",
28
+ "@fortawesome/fontawesome-svg-core": "^1.2.35",
29
+ "@fortawesome/free-solid-svg-icons": "^5.15.3",
30
+ "@fortawesome/react-fontawesome": "^0.1.14",
31
+ "@tailwindcss/postcss7-compat": "^2.1.0",
32
+ "autoprefixer": "^10.4.13",
33
+ "babel-loader": "^8.2.2",
34
+ "browserify-fs": "^1.0.0",
35
+ "buffer": "^6.0.3",
36
+ "classnames": "2.3.2",
37
+ "clean-webpack-plugin": "^3.0.0",
38
+ "copy-webpack-plugin": "^8.1.1",
39
+ "core-js": "^3.11.0",
40
+ "css-loader": "^5.2.4",
41
+ "dotenv-webpack": "^7.0.2",
42
+ "file-loader": "^6.2.0",
43
+ "graphql": "16.5.0",
44
+ "graphql-tag": "2.12.6",
45
+ "html-webpack-plugin": "^5.3.1",
46
+ "mini-css-extract-plugin": "^1.5.0",
47
+ "next": "^12.3.4",
48
+ "path-browserify": "^1.0.1",
49
+ "postcss": "8.4.14",
50
+ "postcss-import": "^15.1.0",
51
+ "postcss-loader": "^5.2.0",
52
+ "react": "18.2.0",
53
+ "react-dom": "18.2.0",
54
+ "sass": "^1.32.11",
55
+ "sass-loader": "^10.0.1",
56
+ "shortid": "^2.2.16",
57
+ "slate": "^0.62.0",
58
+ "slate-history": "^0.62.0",
59
+ "slate-react": "^0.62.0",
60
+ "slate-when": "^0.2.0",
61
+ "style-loader": "^2.0.0",
62
+ "tailwindcss": "3.3.2",
63
+ "url-loader": "^4.1.1",
64
+ "util": "^0.12.5",
65
+ "walk-sync": "^3.0.0",
66
+ "webpack": "5.73.0",
67
+ "webpack-cli": "^4.6.0",
68
+ "webpack-dev-server": "4.7.4"
69
+ },
70
+ "dependencies": {
71
+ "@svgr/webpack": "^5.5.0",
72
+ "cssnano": "^5.0.1",
73
+ "escape-html": "^1.0.3"
74
+ },
75
+ "gitHead": "06971175660ea52650bfb65a3d68b34a7926475e",
76
+ "publishConfig": {
77
+ "access": "public"
78
+ }
79
+ }
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ plugins: {
3
+ 'postcss-import': {},
4
+ tailwindcss: {},
5
+ autoprefixer: {},
6
+ },
7
+ };
package/scss/demo.scss ADDED
@@ -0,0 +1,142 @@
1
+ html, body, #root {
2
+ height: 100%;
3
+ width: 100%;
4
+ }
5
+
6
+ @media (prefers-color-scheme: dark) {
7
+ .slate-editor {
8
+ color: white;
9
+ }
10
+ }
11
+
12
+ .editor-demo-wrapper {
13
+ display: flex;
14
+ height: 100%;
15
+ justify-content: center;
16
+ width: 100%;
17
+ flex-direction: column;
18
+
19
+ .editor-demo-output {
20
+ width: 100%;
21
+ }
22
+
23
+ .editor-demo {
24
+ display: block;
25
+ flex: 1;
26
+ height: 100%;
27
+ width: 100%;
28
+ position: relative;
29
+
30
+ .editor-demo-editor {
31
+ display: flex;
32
+ height: 100%;
33
+ position: relative;
34
+ width: 100%;
35
+ padding-top: 40px;
36
+
37
+ &.container {
38
+ display: flex;
39
+ flex: 1;
40
+ justify-content: center;
41
+ min-width: 100%;
42
+ min-height: 100%;
43
+ position: relative;
44
+
45
+ &.block-editor-wrapper {
46
+ flex-grow: 1;
47
+ //max-width: 703px;
48
+ //width: 703px; // contentful editor default width
49
+ }
50
+ }
51
+
52
+ &.value {
53
+ textarea {
54
+ max-height: 50px;
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ .test-block {
62
+ background-color: #fefefe;
63
+ border: 1px solid black;
64
+ color: black;
65
+ padding: 5px;
66
+ }
67
+
68
+ .block-editor-content {
69
+ font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
70
+ line-height: 1em;
71
+ }
72
+
73
+ .block-editor-content p {
74
+ margin-bottom: 20px;
75
+ }
76
+
77
+ .block-editor-content h1 {
78
+ font-size: 2em;
79
+ }
80
+
81
+ .block-editor-content h2 {
82
+ font-size: 1.5em;
83
+ }
84
+
85
+ .block-editor-content h3 {
86
+ font-size: 1.3em;
87
+ }
88
+
89
+ .block-editor-content h4 {
90
+ font-size: 1.1em;
91
+ }
92
+
93
+ .block-editor-content h5,
94
+ .block-editor-content h6 {
95
+ font-size: 1em;
96
+ }
97
+
98
+ .block-editor-content ul, .block-editor-content ol {
99
+ margin-block-start: 1em;
100
+ margin-block-end: 1em;
101
+ margin-inline-start: 0px;
102
+ margin-inline-end: 0px;
103
+ padding-inline-start: 40px;
104
+ }
105
+
106
+ .block-editor-content ul {
107
+ list-style-type: disc;
108
+ }
109
+
110
+ .block-editor-content ol {
111
+ list-style-type: decimal;
112
+ }
113
+
114
+ .block-editor-content blockquote {
115
+ display: block;
116
+ background-color: grey;
117
+ padding: 1em;
118
+ }
119
+
120
+ .block-editor-content a,
121
+ .block-editor-content a:visited {
122
+ color: blue;
123
+ cursor: pointer;
124
+ }
125
+
126
+
127
+ .block-editor-content a:hover {
128
+ text-decoration: underline;
129
+ }
130
+
131
+ .editor-mt-16 {
132
+ @apply pt-16 block;
133
+ }
134
+ .editor-mr-16 {
135
+ @apply md:pr-16 block;
136
+ }
137
+ .editor-mb-16 {
138
+ @apply pb-16 block;
139
+ }
140
+ .editor-ml-16 {
141
+ @apply md:pl-16 block;
142
+ }
@@ -0,0 +1,394 @@
1
+ .block-editor-wrapper {
2
+
3
+ position: relative;
4
+ display: flex;
5
+ height: 100%;
6
+ max-height: 100%;
7
+ max-width: 100%;
8
+ width: 100%;
9
+
10
+ &.storybook-active {
11
+ .slate-editor {
12
+ display: none;
13
+ overflow: hidden;
14
+ }
15
+ }
16
+
17
+ .storybook-target {
18
+ display: block;
19
+ height: 100%;
20
+ left: 0px;
21
+ position: fixed;
22
+ top: 0px;
23
+ width: 100%;
24
+ z-index: 1000;
25
+
26
+ &:empty {
27
+ display: none;
28
+ }
29
+
30
+ .storybook-frame {
31
+ height: 100%;
32
+ width: 100%;
33
+
34
+ iframe {
35
+ height: 100%;
36
+ width: 100%;
37
+ }
38
+ }
39
+ }
40
+
41
+ .slate-editor {
42
+ max-height: 100%;
43
+ height: 100%;
44
+ z-index: 100;
45
+ max-width: 100%;
46
+ overflow-y: auto;
47
+ padding: 40px 60px 0 60px;
48
+ position: relative;
49
+ width: 100%;
50
+
51
+ span[data-slate-node="text"] {
52
+ /* eslint-disable-next-line */
53
+ font-family: "Font TWO BR", sans-serif;
54
+ }
55
+
56
+ p[data-slate-node="element"] {
57
+ padding-bottom: 20px;
58
+ position: relative;
59
+ //outline: #CECECE dashed;
60
+
61
+ &:after {
62
+ font-size: 1em;
63
+ content: "P";
64
+ color: #CECECE;
65
+ position: absolute;
66
+ left: -20px;
67
+ text-transform: uppercase;
68
+ top: 1px;
69
+ user-select: none;
70
+ }
71
+ }
72
+
73
+ h1[data-slate-node="element"] {
74
+ font-size: 2em;
75
+ position: relative;
76
+
77
+ &:after {
78
+ content: "h1";
79
+ color: #CECECE;
80
+ position: absolute;
81
+ left: -26px;
82
+ text-transform: uppercase;
83
+ top: 1px;
84
+ user-select: none;
85
+ }
86
+ }
87
+
88
+ h2[data-slate-node="element"] {
89
+ font-size: 1.5em;
90
+ position: relative;
91
+
92
+ &:after {
93
+ content: "h2";
94
+ color: #CECECE;
95
+ position: absolute;
96
+ left: -26px;
97
+ text-transform: uppercase;
98
+ top: 1px;
99
+ user-select: none;
100
+ }
101
+ }
102
+
103
+ h3[data-slate-node="element"] {
104
+ font-size: 1.3em;
105
+ position: relative;
106
+
107
+ &:after {
108
+ content: "h3";
109
+ color: #CECECE;
110
+ position: absolute;
111
+ left: -26px;
112
+ text-transform: uppercase;
113
+ top: 1px;
114
+ user-select: none;
115
+ }
116
+ }
117
+
118
+ h4[data-slate-node="element"] {
119
+ font-size: 1.1em;
120
+ position: relative;
121
+
122
+ &:after {
123
+ content: "h4";
124
+ color: #CECECE;
125
+ position: absolute;
126
+ left: -26px;
127
+ text-transform: uppercase;
128
+ top: 1px;
129
+ user-select: none;
130
+ }
131
+ }
132
+
133
+ h5[data-slate-node="element"] {
134
+ font-size: 1em;
135
+ position: relative;
136
+
137
+ &:after {
138
+ content: "h5";
139
+ color: #CECECE;
140
+ position: absolute;
141
+ left: -26px;
142
+ text-transform: uppercase;
143
+ top: 1px;
144
+ user-select: none;
145
+ }
146
+ }
147
+
148
+ h6[data-slate-node="element"] {
149
+ font-size: 1em;
150
+ position: relative;
151
+
152
+ &:after {
153
+ content: "h6";
154
+ color: #CECECE;
155
+ position: absolute;
156
+ left: -26px;
157
+ text-transform: uppercase;
158
+ top: 1px;
159
+ user-select: none;
160
+ }
161
+ }
162
+
163
+ ul[data-slate-node="element"] {
164
+ list-style: circle;
165
+ }
166
+
167
+ ol[data-slate-node="element"] {
168
+ list-style: decimal;
169
+ }
170
+
171
+ a[data-slate-node="element"] {
172
+ color: rgb(var(--color-secondary));
173
+ text-decoration: underline;
174
+ }
175
+
176
+ div[data-slate-editor="true"] {
177
+ height: 100%;
178
+ }
179
+
180
+ .align-left {
181
+ text-align: left;
182
+ }
183
+
184
+ .align-right {
185
+ text-align: right;
186
+ }
187
+
188
+ .align-center {
189
+ text-align: center;
190
+ }
191
+
192
+ .align-justify {
193
+ text-align: justify;
194
+ }
195
+
196
+ .block-align-left {
197
+ display: inline-block;
198
+ float: left;
199
+ margin-right: 15px;
200
+ }
201
+
202
+ .block-align-undefined {
203
+ display: inline-block;
204
+ }
205
+
206
+ .block-align-right {
207
+ display: inline-block;
208
+ float: right;
209
+ margin-left: 15px;
210
+ }
211
+ }
212
+
213
+ .options-wrapper {
214
+ position: relative;
215
+
216
+ &:hover {
217
+ .options-container {
218
+ display: flex;
219
+ }
220
+ }
221
+
222
+ .options-container {
223
+ display: none;
224
+ flex-direction: row;
225
+ justify-content: center;
226
+ left: 0px;
227
+ position: absolute;
228
+ top: 0px;
229
+ z-index: 200;
230
+ background-color: grey;
231
+ padding: 4px 4px 4px 4px;
232
+
233
+ .options-container-option {
234
+ cursor: pointer;
235
+ width: 26px;
236
+
237
+ > svg {
238
+ width: 100%;
239
+ }
240
+
241
+ &.options-container-option-expand-text {
242
+ width: 100px
243
+ }
244
+
245
+ &.options-container-option-delete {
246
+ color: red;
247
+ }
248
+ }
249
+
250
+ &.options-container-right {
251
+ left: -26px;
252
+ }
253
+ }
254
+ }
255
+
256
+ .layout-slot-option-padding {
257
+
258
+ position: relative;
259
+ width: 20px;
260
+ height: 20px;
261
+ display: inline-block;
262
+
263
+ .layout-slot-option-padding-item {
264
+ background-color: black;
265
+ display: block;
266
+ position: absolute;
267
+ cursor: pointer;
268
+
269
+ &:hover {
270
+ background-color: white;
271
+ z-index: 10
272
+ }
273
+
274
+ &.active {
275
+ background-color: lightgray;
276
+ z-index: 10
277
+ }
278
+ }
279
+
280
+ .layout-slot-option-padding-top {
281
+ height: 5px;
282
+ width: 20px;
283
+ top: 0;
284
+ left: 0;
285
+ }
286
+
287
+ .layout-slot-option-padding-right {
288
+ height: 20px;
289
+ width: 5px;
290
+ right: 0;
291
+ top: 0;
292
+ }
293
+
294
+ .layout-slot-option-padding-bottom {
295
+ height: 5px;
296
+ width: 20px;
297
+ bottom: 0;
298
+ left: 0;
299
+ }
300
+
301
+ .layout-slot-option-padding-left {
302
+ height: 20px;
303
+ width: 5px;
304
+ top: 0;
305
+ left: 0;
306
+ }
307
+ }
308
+
309
+ .layout-block {
310
+ display: flex;
311
+ flex-direction: row;
312
+
313
+ &.article-width {
314
+ width: 44.44444444435556%;
315
+ }
316
+
317
+ &.site-width {
318
+ width: 66.66666666666667%;
319
+ }
320
+
321
+ .layout-slot {
322
+ display: flex;
323
+ flex-direction: column;
324
+ position: relative;
325
+ outline: 1px dashed grey;
326
+
327
+ .layout-slot-options {
328
+ background-color: grey;
329
+ color: white;
330
+ font-size: 24px;
331
+ padding: 10px;
332
+ display: flex;
333
+ flex-direction: row;
334
+ justify-content: space-between;
335
+
336
+ .layout-slot-option {
337
+ text-transform: uppercase;
338
+ display: inline-block;
339
+ }
340
+
341
+ .layout-slot-name {
342
+ text-transform: uppercase;
343
+ display: inline-block;
344
+ }
345
+
346
+ }
347
+
348
+ .layout-slot-content {
349
+ }
350
+
351
+ &.layout-slot-widecol {
352
+ flex-grow: 1;
353
+ }
354
+
355
+ &.layout-slot-maincol {
356
+ flex-grow: 1;
357
+ }
358
+
359
+ &.layout-slot-sidecol {
360
+ flex-grow: 0;
361
+ width: 30%;
362
+ }
363
+
364
+ &.layout-slot-grid-half {
365
+ flex-grow: 0;
366
+ width: 50%;
367
+ }
368
+
369
+ &.layout-slot-grid-3 {
370
+ flex-grow: 0;
371
+ width: 100%;
372
+ }
373
+
374
+ &.layout-slot-grid-2 {
375
+ flex-grow: 0;
376
+ width: 66.6666666666%;
377
+ }
378
+
379
+ &.layout-slot-grid-1 {
380
+ flex-grow: 0;
381
+ width: 33.3333333333%;
382
+ }
383
+
384
+ &.layout-slot-grid-fill {
385
+ flex-grow: 1;
386
+ }
387
+
388
+ &.layout-slot-grid-auto {
389
+ flex-grow: 0;
390
+ width: auto;
391
+ }
392
+ }
393
+ }
394
+ }
@@ -0,0 +1,66 @@
1
+ .storybook-element {
2
+ display: inline;
3
+
4
+ &.storybook-element-float-left {
5
+ float: left;
6
+ }
7
+
8
+ &.storybook-element-float-right {
9
+ float: right;
10
+ }
11
+
12
+ .storybook-element-component {
13
+ user-select: none;
14
+ display: block;
15
+
16
+ &.storybook-inline {
17
+ display: inline-block;
18
+ }
19
+
20
+ .editor-empty-element {
21
+ background-color: red;
22
+ border: 1px solid black;
23
+ min-height: 20px;
24
+ min-width: 100px;
25
+ }
26
+
27
+ .storybook-element-display {
28
+ &:empty {
29
+ display: block;
30
+ background-color: red;
31
+ border: 1px solid black;
32
+ min-height: 30px;
33
+ min-width: 100px;
34
+ }
35
+
36
+ &.storybook-element-display-empty {
37
+ display: block;
38
+ background-color: red;
39
+ border: 1px solid black;
40
+ color: white;
41
+ font-weight: bold;
42
+ font-size: 110%;
43
+ padding: 10px;
44
+ min-height: 30px;
45
+ min-width: 100px;
46
+ position: relative;
47
+
48
+ &::after {
49
+ position: absolute;
50
+ top: 0px;
51
+ left: 0px;
52
+ content: attr(data-content);
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ .storybook-element-error {
59
+ background-color: red;
60
+ padding: 15px;
61
+ font-size: 18px;
62
+ font-weight: bold;
63
+ min-height: 100px;
64
+ min-width: 100px;
65
+ }
66
+ }