@zipify/wysiwyg 2.0.0-0 → 2.0.0-2

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 (80) hide show
  1. package/.eslintrc.js +1 -1
  2. package/config/build/lib.config.js +4 -2
  3. package/dist/cli.js +10 -2
  4. package/dist/wysiwyg.css +12 -6
  5. package/dist/wysiwyg.mjs +1507 -406
  6. package/example/ExampleApp.vue +3 -1
  7. package/lib/__tests__/utils/buildTestExtensions.js +2 -1
  8. package/lib/components/toolbar/controls/StylePresetControl.vue +1 -1
  9. package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +6 -6
  10. package/lib/enums/MarkGroups.js +4 -0
  11. package/lib/enums/TextSettings.js +5 -5
  12. package/lib/enums/index.js +1 -0
  13. package/lib/extensions/BackgroundColor.js +2 -2
  14. package/lib/extensions/FontColor.js +2 -2
  15. package/lib/extensions/FontFamily.js +3 -3
  16. package/lib/extensions/FontSize.js +2 -2
  17. package/lib/extensions/FontStyle.js +2 -2
  18. package/lib/extensions/FontWeight.js +2 -2
  19. package/lib/extensions/Link.js +1 -1
  20. package/lib/extensions/StylePreset.js +2 -2
  21. package/lib/extensions/Superscript.js +5 -2
  22. package/lib/extensions/TextDecoration.js +12 -29
  23. package/lib/extensions/__tests__/Alignment.test.js +2 -2
  24. package/lib/extensions/__tests__/BackgroundColor.test.js +4 -3
  25. package/lib/extensions/__tests__/FontColor.test.js +4 -3
  26. package/lib/extensions/__tests__/FontFamily.test.js +6 -6
  27. package/lib/extensions/__tests__/FontSize.test.js +9 -8
  28. package/lib/extensions/__tests__/FontStyle.test.js +6 -5
  29. package/lib/extensions/__tests__/FontWeight.test.js +2 -2
  30. package/lib/extensions/__tests__/LineHeight.test.js +2 -1
  31. package/lib/extensions/__tests__/Superscript.test.js +102 -0
  32. package/lib/extensions/__tests__/TextDecoration.test.js +20 -24
  33. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +1 -1
  34. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +1 -1
  35. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +19 -23
  36. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +2 -2
  37. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +1 -1
  38. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +13 -17
  39. package/lib/extensions/__tests__/__snapshots__/Superscript.test.js.snap +107 -0
  40. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +102 -102
  41. package/lib/extensions/core/Document.js +2 -1
  42. package/lib/extensions/core/Heading.js +2 -1
  43. package/lib/extensions/core/NodeProcessor.js +51 -19
  44. package/lib/extensions/core/Paragraph.js +2 -1
  45. package/lib/extensions/core/TextProcessor.js +0 -5
  46. package/lib/extensions/core/__tests__/NodeProcessor.test.js +364 -11
  47. package/lib/extensions/core/__tests__/TextProcessor.test.js +1 -22
  48. package/lib/extensions/core/__tests__/__snapshots__/NodeProcessor.test.js.snap +309 -0
  49. package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +7 -27
  50. package/lib/extensions/core/steps/AddNodeMarkStep.js +6 -0
  51. package/lib/extensions/core/steps/AttrStep.js +60 -0
  52. package/lib/extensions/core/steps/RemoveNodeMarkStep.js +6 -0
  53. package/lib/extensions/core/steps/index.js +1 -0
  54. package/lib/extensions/list/List.js +2 -2
  55. package/lib/extensions/list/ListItem.js +2 -2
  56. package/lib/services/NodeFactory.js +73 -13
  57. package/lib/services/__tests__/NodeFactory.test.js +124 -0
  58. package/lib/services/__tests__/__snapshots__/NodeFactory.test.js.snap +326 -0
  59. package/lib/services/index.js +1 -1
  60. package/lib/services/normalizer/BaseNormalizer.js +11 -0
  61. package/lib/services/{BrowserDomParser.js → normalizer/BrowserDomParser.js} +0 -0
  62. package/lib/services/normalizer/ContentNormalizer.js +24 -0
  63. package/lib/services/normalizer/HtmlNormalizer.js +245 -0
  64. package/lib/services/normalizer/JsonNormalizer.js +81 -0
  65. package/lib/services/{__tests__/ContentNormalizer.test.js → normalizer/__tests__/HtmlNormalizer.test.js} +31 -7
  66. package/lib/services/normalizer/__tests__/JsonNormalizer.test.js +70 -0
  67. package/lib/services/normalizer/__tests__/__snapshots__/JsonNormalizer.test.js.snap +159 -0
  68. package/lib/services/normalizer/index.js +1 -0
  69. package/lib/styles/content.css +8 -0
  70. package/lib/utils/__tests__/findMarkByType.test.js +17 -0
  71. package/lib/utils/__tests__/isMarkAppliedToParent.test.js +53 -0
  72. package/lib/utils/__tests__/isNodeFullySelected.test.js +53 -0
  73. package/lib/utils/__tests__/resolveTextPosition.test.js +39 -0
  74. package/lib/utils/index.js +0 -1
  75. package/lib/utils/isMarkAppliedToParent.js +2 -7
  76. package/lib/utils/isNodeFullySelected.js +9 -5
  77. package/lib/utils/resolveTextPosition.js +4 -6
  78. package/package.json +28 -26
  79. package/lib/services/ContentNormalizer.js +0 -194
  80. package/lib/utils/resolveNodePosition.js +0 -6
@@ -0,0 +1,124 @@
1
+ import { NodeFactory } from '../NodeFactory';
2
+ import { ListTypes, TextSettings } from '../../enums';
3
+
4
+ describe('build node', () => {
5
+ test('should build doc node', () => {
6
+ expect(NodeFactory.doc([])).toMatchSnapshot();
7
+ });
8
+
9
+ test('should build list node with text items', () => {
10
+ const node = NodeFactory.list(ListTypes.DISC, [
11
+ 'lorem ipsum 1',
12
+ 'lorem ipsum 2'
13
+ ]);
14
+
15
+ expect(node).toMatchSnapshot();
16
+ });
17
+
18
+ test('should build list node with node items', () => {
19
+ const node = NodeFactory.list(ListTypes.DISC, [
20
+ NodeFactory.paragraph('lorem ipsum 1'),
21
+ NodeFactory.paragraph('lorem ipsum 2')
22
+ ]);
23
+
24
+ expect(node).toMatchSnapshot();
25
+ });
26
+
27
+ test('should build list node with custom list item nodes', () => {
28
+ const node = NodeFactory.list(ListTypes.DISC, [
29
+ NodeFactory.listItem(null, [
30
+ NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
31
+ ], 'lorem ipsum 1'),
32
+
33
+ NodeFactory.listItem(null, [
34
+ NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
35
+ ], 'lorem ipsum 2')
36
+ ]);
37
+
38
+ expect(node).toMatchSnapshot();
39
+ });
40
+
41
+ test('should build heading node', () => {
42
+ const node = NodeFactory.heading(1, 'lorem ipsum');
43
+
44
+ expect(node).toMatchSnapshot();
45
+ });
46
+
47
+ test('should build heading node with attrs', () => {
48
+ const node = NodeFactory.heading(1, { preset: { id: 'h1' } }, 'lorem ipsum');
49
+
50
+ expect(node).toMatchSnapshot();
51
+ });
52
+
53
+ test('should build heading node with marks', () => {
54
+ const node = NodeFactory.heading(1, null, [
55
+ NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
56
+ ], 'lorem ipsum');
57
+
58
+ expect(node).toMatchSnapshot();
59
+ });
60
+
61
+ test('should build heading with custom text node', () => {
62
+ const node = NodeFactory.heading(1, [
63
+ NodeFactory.text('lorem ipsum', [
64
+ NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
65
+ ])
66
+ ]);
67
+
68
+ expect(node).toMatchSnapshot();
69
+ });
70
+
71
+ test('should build paragraph node', () => {
72
+ const node = NodeFactory.paragraph('lorem ipsum');
73
+
74
+ expect(node).toMatchSnapshot();
75
+ });
76
+
77
+ test('should build paragraph node with attrs', () => {
78
+ const node = NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'lorem ipsum');
79
+
80
+ expect(node).toMatchSnapshot();
81
+ });
82
+
83
+ test('should build paragraph node with marks', () => {
84
+ const node = NodeFactory.paragraph(null, [
85
+ NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
86
+ ], 'lorem ipsum');
87
+
88
+ expect(node).toMatchSnapshot();
89
+ });
90
+
91
+ test('should build paragraph with custom text node', () => {
92
+ const node = NodeFactory.paragraph([
93
+ NodeFactory.text('lorem ipsum', [
94
+ NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
95
+ ])
96
+ ]);
97
+
98
+ expect(node).toMatchSnapshot();
99
+ });
100
+
101
+ test('should build text node', () => {
102
+ const node = NodeFactory.text('lorem ipsum');
103
+
104
+ expect(node).toMatchSnapshot();
105
+ });
106
+
107
+ test('should build text node with marks', () => {
108
+ const node = NodeFactory.text('lorem ipsum');
109
+
110
+ expect(node).toMatchSnapshot();
111
+ });
112
+
113
+ test('should build mark', () => {
114
+ const mark = NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' });
115
+
116
+ expect(mark).toMatchSnapshot();
117
+ });
118
+
119
+ test('should populate value to all devices', () => {
120
+ const value = NodeFactory.populateAllDevices('18');
121
+
122
+ expect(value).toMatchSnapshot();
123
+ });
124
+ });
@@ -0,0 +1,326 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`build node should build doc node 1`] = `
4
+ Object {
5
+ "content": Array [],
6
+ "type": "doc",
7
+ }
8
+ `;
9
+
10
+ exports[`build node should build heading node 1`] = `
11
+ Object {
12
+ "attrs": Object {
13
+ "level": 1,
14
+ },
15
+ "content": Array [
16
+ Object {
17
+ "text": "lorem ipsum",
18
+ "type": "text",
19
+ },
20
+ ],
21
+ "type": "heading",
22
+ }
23
+ `;
24
+
25
+ exports[`build node should build heading node with attrs 1`] = `
26
+ Object {
27
+ "attrs": Object {
28
+ "level": 1,
29
+ "preset": Object {
30
+ "id": "h1",
31
+ },
32
+ },
33
+ "content": Array [
34
+ Object {
35
+ "text": "lorem ipsum",
36
+ "type": "text",
37
+ },
38
+ ],
39
+ "type": "heading",
40
+ }
41
+ `;
42
+
43
+ exports[`build node should build heading node with marks 1`] = `
44
+ Object {
45
+ "attrs": Object {
46
+ "level": 1,
47
+ },
48
+ "content": Array [
49
+ Object {
50
+ "text": "lorem ipsum",
51
+ "type": "text",
52
+ },
53
+ ],
54
+ "marks": Array [
55
+ Object {
56
+ "attrs": Object {
57
+ "value": "700",
58
+ },
59
+ "type": "font_weight",
60
+ },
61
+ ],
62
+ "type": "heading",
63
+ }
64
+ `;
65
+
66
+ exports[`build node should build heading with custom text node 1`] = `
67
+ Object {
68
+ "attrs": Object {
69
+ "level": 1,
70
+ },
71
+ "content": Array [
72
+ Object {
73
+ "marks": Array [
74
+ Object {
75
+ "attrs": Object {
76
+ "value": "700",
77
+ },
78
+ "type": "font_weight",
79
+ },
80
+ ],
81
+ "text": "lorem ipsum",
82
+ "type": "text",
83
+ },
84
+ ],
85
+ "type": "heading",
86
+ }
87
+ `;
88
+
89
+ exports[`build node should build list node with custom list item nodes 1`] = `
90
+ Object {
91
+ "attrs": Object {
92
+ "bullet": Object {
93
+ "type": "disc",
94
+ },
95
+ },
96
+ "content": Array [
97
+ Object {
98
+ "content": Array [
99
+ Object {
100
+ "content": Array [
101
+ Object {
102
+ "text": "lorem ipsum 1",
103
+ "type": "text",
104
+ },
105
+ ],
106
+ "type": "paragraph",
107
+ },
108
+ ],
109
+ "marks": Array [
110
+ Object {
111
+ "attrs": Object {
112
+ "value": "700",
113
+ },
114
+ "type": "font_weight",
115
+ },
116
+ ],
117
+ "type": "listItem",
118
+ },
119
+ Object {
120
+ "content": Array [
121
+ Object {
122
+ "content": Array [
123
+ Object {
124
+ "text": "lorem ipsum 2",
125
+ "type": "text",
126
+ },
127
+ ],
128
+ "type": "paragraph",
129
+ },
130
+ ],
131
+ "marks": Array [
132
+ Object {
133
+ "attrs": Object {
134
+ "value": "700",
135
+ },
136
+ "type": "font_weight",
137
+ },
138
+ ],
139
+ "type": "listItem",
140
+ },
141
+ ],
142
+ "type": "list",
143
+ }
144
+ `;
145
+
146
+ exports[`build node should build list node with node items 1`] = `
147
+ Object {
148
+ "attrs": Object {
149
+ "bullet": Object {
150
+ "type": "disc",
151
+ },
152
+ },
153
+ "content": Array [
154
+ Object {
155
+ "content": Array [
156
+ Object {
157
+ "content": Array [
158
+ Object {
159
+ "text": "lorem ipsum 1",
160
+ "type": "text",
161
+ },
162
+ ],
163
+ "type": "paragraph",
164
+ },
165
+ ],
166
+ "type": "listItem",
167
+ },
168
+ Object {
169
+ "content": Array [
170
+ Object {
171
+ "content": Array [
172
+ Object {
173
+ "text": "lorem ipsum 2",
174
+ "type": "text",
175
+ },
176
+ ],
177
+ "type": "paragraph",
178
+ },
179
+ ],
180
+ "type": "listItem",
181
+ },
182
+ ],
183
+ "type": "list",
184
+ }
185
+ `;
186
+
187
+ exports[`build node should build list node with text items 1`] = `
188
+ Object {
189
+ "attrs": Object {
190
+ "bullet": Object {
191
+ "type": "disc",
192
+ },
193
+ },
194
+ "content": Array [
195
+ Object {
196
+ "content": Array [
197
+ Object {
198
+ "content": Array [
199
+ Object {
200
+ "text": "lorem ipsum 1",
201
+ "type": "text",
202
+ },
203
+ ],
204
+ "type": "paragraph",
205
+ },
206
+ ],
207
+ "type": "listItem",
208
+ },
209
+ Object {
210
+ "content": Array [
211
+ Object {
212
+ "content": Array [
213
+ Object {
214
+ "text": "lorem ipsum 2",
215
+ "type": "text",
216
+ },
217
+ ],
218
+ "type": "paragraph",
219
+ },
220
+ ],
221
+ "type": "listItem",
222
+ },
223
+ ],
224
+ "type": "list",
225
+ }
226
+ `;
227
+
228
+ exports[`build node should build mark 1`] = `
229
+ Object {
230
+ "attrs": Object {
231
+ "value": "700",
232
+ },
233
+ "type": "font_weight",
234
+ }
235
+ `;
236
+
237
+ exports[`build node should build paragraph node 1`] = `
238
+ Object {
239
+ "content": Array [
240
+ Object {
241
+ "text": "lorem ipsum",
242
+ "type": "text",
243
+ },
244
+ ],
245
+ "type": "paragraph",
246
+ }
247
+ `;
248
+
249
+ exports[`build node should build paragraph node with attrs 1`] = `
250
+ Object {
251
+ "attrs": Object {
252
+ "preset": Object {
253
+ "id": "regular-1",
254
+ },
255
+ },
256
+ "content": Array [
257
+ Object {
258
+ "text": "lorem ipsum",
259
+ "type": "text",
260
+ },
261
+ ],
262
+ "type": "paragraph",
263
+ }
264
+ `;
265
+
266
+ exports[`build node should build paragraph node with marks 1`] = `
267
+ Object {
268
+ "content": Array [
269
+ Object {
270
+ "text": "lorem ipsum",
271
+ "type": "text",
272
+ },
273
+ ],
274
+ "marks": Array [
275
+ Object {
276
+ "attrs": Object {
277
+ "value": "700",
278
+ },
279
+ "type": "font_weight",
280
+ },
281
+ ],
282
+ "type": "paragraph",
283
+ }
284
+ `;
285
+
286
+ exports[`build node should build paragraph with custom text node 1`] = `
287
+ Object {
288
+ "content": Array [
289
+ Object {
290
+ "marks": Array [
291
+ Object {
292
+ "attrs": Object {
293
+ "value": "700",
294
+ },
295
+ "type": "font_weight",
296
+ },
297
+ ],
298
+ "text": "lorem ipsum",
299
+ "type": "text",
300
+ },
301
+ ],
302
+ "type": "paragraph",
303
+ }
304
+ `;
305
+
306
+ exports[`build node should build text node 1`] = `
307
+ Object {
308
+ "text": "lorem ipsum",
309
+ "type": "text",
310
+ }
311
+ `;
312
+
313
+ exports[`build node should build text node with marks 1`] = `
314
+ Object {
315
+ "text": "lorem ipsum",
316
+ "type": "text",
317
+ }
318
+ `;
319
+
320
+ exports[`build node should populate value to all devices 1`] = `
321
+ Object {
322
+ "desktop": "18",
323
+ "mobile": null,
324
+ "tablet": "18",
325
+ }
326
+ `;
@@ -1,6 +1,6 @@
1
1
  export { JsonSerializer } from './JsonSerializer';
2
2
  export { Storage } from './Storage';
3
3
  export { FavoriteColors } from './FavoriteColors';
4
- export { ContentNormalizer } from './ContentNormalizer';
4
+ export { ContentNormalizer } from './normalizer';
5
5
  export { ContextWindow } from './ContextWidnow';
6
6
  export { NodeFactory } from './NodeFactory';
@@ -0,0 +1,11 @@
1
+ export class BaseNormalizer {
2
+ content;
3
+
4
+ constructor({ content }) {
5
+ this.content = content;
6
+ }
7
+
8
+ normalize() {
9
+ throw new Error('Implement abstract method');
10
+ }
11
+ }
@@ -0,0 +1,24 @@
1
+ import { BrowserDomParser } from './BrowserDomParser';
2
+ import { HtmlNormalizer } from './HtmlNormalizer';
3
+ import { JsonNormalizer } from './JsonNormalizer';
4
+
5
+ export class ContentNormalizer {
6
+ static build(content, options = {}) {
7
+ return typeof content === 'string' ? this.#buildHtml(content, options) : this.#buildJson(content);
8
+ }
9
+
10
+ static #buildHtml(content, options) {
11
+ return new HtmlNormalizer({
12
+ content,
13
+ parser: options.parser || new BrowserDomParser()
14
+ });
15
+ }
16
+
17
+ static #buildJson(content) {
18
+ return new JsonNormalizer({ content });
19
+ }
20
+
21
+ static normalize(content, options = {}) {
22
+ return ContentNormalizer.build(content, options).normalize();
23
+ }
24
+ }