@zipify/wysiwyg 1.0.0-dev.4 → 1.0.0-dev.5
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/.release-it.json +0 -1
- package/README.md +3 -1
- package/config/jest/setupTests.js +3 -1
- package/example/ExampleApp.vue +39 -31
- package/example/example.js +26 -0
- package/example/presets.js +2 -0
- package/lib/Wysiwyg.vue +6 -0
- package/lib/composables/__tests__/useEditor.test.js +12 -3
- package/lib/composables/useEditor.js +12 -5
- package/lib/extensions/Alignment.js +6 -0
- package/lib/extensions/BackgroundColor.js +8 -1
- package/lib/extensions/FontColor.js +8 -1
- package/lib/extensions/FontFamily.js +7 -0
- package/lib/extensions/FontSize.js +12 -0
- package/lib/extensions/FontStyle.js +11 -0
- package/lib/extensions/FontWeight.js +25 -1
- package/lib/extensions/LineHeight.js +17 -0
- package/lib/extensions/StylePreset.js +30 -3
- package/lib/extensions/TextDecoration.js +11 -0
- package/lib/extensions/__tests__/Alignment.test.js +22 -1
- package/lib/extensions/__tests__/BackgroundColor.test.js +30 -1
- package/lib/extensions/__tests__/CaseStyle.test.js +4 -1
- package/lib/extensions/__tests__/FontColor.test.js +30 -1
- package/lib/extensions/__tests__/FontFamily.test.js +30 -1
- package/lib/extensions/__tests__/FontSize.test.js +30 -1
- package/lib/extensions/__tests__/FontStyle.test.js +38 -1
- package/lib/extensions/__tests__/FontWeight.test.js +58 -1
- package/lib/extensions/__tests__/LineHeight.test.js +41 -1
- package/lib/extensions/__tests__/StylePreset.test.js +76 -1
- package/lib/extensions/__tests__/TextDecoration.test.js +63 -1
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +44 -0
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +91 -0
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +91 -0
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +91 -0
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +99 -0
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +120 -0
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +149 -0
- package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +92 -0
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +167 -2
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +207 -0
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +4 -1
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +9 -4
- package/lib/extensions/core/__tests__/TextProcessor.test.js +4 -1
- package/lib/extensions/index.js +1 -0
- package/lib/extensions/list/List.js +34 -0
- package/lib/extensions/list/__tests__/List.test.js +115 -3
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +457 -6
- package/lib/services/ContentNormalizer.js +113 -0
- package/lib/services/Storage.js +1 -13
- package/lib/services/__tests__/ContentNormalizer.test.js +41 -0
- package/lib/services/__tests__/FavoriteColors.test.js +20 -0
- package/lib/services/__tests__/JsonSerializer.test.js +23 -0
- package/lib/services/__tests__/Storage.test.js +79 -0
- package/lib/services/index.js +1 -0
- package/lib/utils/__tests__/convertColor.test.js +19 -0
- package/lib/utils/__tests__/createKeyboardShortcut.test.js +25 -0
- package/lib/utils/__tests__/renderInlineSetting.test.js +26 -0
- package/lib/utils/convertColor.js +7 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/renderInlineSetting.js +1 -1
- package/package.json +1 -1
|
@@ -241,6 +241,171 @@ Object {
|
|
|
241
241
|
}
|
|
242
242
|
`;
|
|
243
243
|
|
|
244
|
+
exports[`parsing html should get by fallback class 1`] = `
|
|
245
|
+
Object {
|
|
246
|
+
"content": Array [
|
|
247
|
+
Object {
|
|
248
|
+
"attrs": Object {
|
|
249
|
+
"alignment": null,
|
|
250
|
+
"preset": Object {
|
|
251
|
+
"id": "regular-2",
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
"content": Array [
|
|
255
|
+
Object {
|
|
256
|
+
"text": "lorem ipsum",
|
|
257
|
+
"type": "text",
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
"type": "paragraph",
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
"type": "doc",
|
|
264
|
+
}
|
|
265
|
+
`;
|
|
266
|
+
|
|
267
|
+
exports[`parsing html should get by heading tag 1`] = `
|
|
268
|
+
Object {
|
|
269
|
+
"content": Array [
|
|
270
|
+
Object {
|
|
271
|
+
"attrs": Object {
|
|
272
|
+
"alignment": null,
|
|
273
|
+
"level": 3,
|
|
274
|
+
"preset": Object {
|
|
275
|
+
"id": "h3",
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
"content": Array [
|
|
279
|
+
Object {
|
|
280
|
+
"text": "lorem ipsum",
|
|
281
|
+
"type": "text",
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
"type": "heading",
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
"type": "doc",
|
|
288
|
+
}
|
|
289
|
+
`;
|
|
290
|
+
|
|
291
|
+
exports[`parsing html should get by preset class 1`] = `
|
|
292
|
+
Object {
|
|
293
|
+
"content": Array [
|
|
294
|
+
Object {
|
|
295
|
+
"attrs": Object {
|
|
296
|
+
"alignment": null,
|
|
297
|
+
"preset": Object {
|
|
298
|
+
"id": "regular-2",
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
"content": Array [
|
|
302
|
+
Object {
|
|
303
|
+
"text": "lorem ipsum",
|
|
304
|
+
"type": "text",
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
"type": "paragraph",
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
"type": "doc",
|
|
311
|
+
}
|
|
312
|
+
`;
|
|
313
|
+
|
|
314
|
+
exports[`parsing html should set default preset to unstyled paragraph 1`] = `
|
|
315
|
+
Object {
|
|
316
|
+
"content": Array [
|
|
317
|
+
Object {
|
|
318
|
+
"attrs": Object {
|
|
319
|
+
"alignment": null,
|
|
320
|
+
"preset": Object {
|
|
321
|
+
"id": "regular-1",
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
"content": Array [
|
|
325
|
+
Object {
|
|
326
|
+
"text": "lorem ipsum",
|
|
327
|
+
"type": "text",
|
|
328
|
+
},
|
|
329
|
+
],
|
|
330
|
+
"type": "paragraph",
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
"type": "doc",
|
|
334
|
+
}
|
|
335
|
+
`;
|
|
336
|
+
|
|
337
|
+
exports[`parsing html should set null to list item 1`] = `
|
|
338
|
+
Object {
|
|
339
|
+
"content": Array [
|
|
340
|
+
Object {
|
|
341
|
+
"attrs": Object {
|
|
342
|
+
"bullet": Object {
|
|
343
|
+
"type": "disc",
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
"content": Array [
|
|
347
|
+
Object {
|
|
348
|
+
"content": Array [
|
|
349
|
+
Object {
|
|
350
|
+
"attrs": Object {
|
|
351
|
+
"alignment": null,
|
|
352
|
+
"preset": null,
|
|
353
|
+
},
|
|
354
|
+
"content": Array [
|
|
355
|
+
Object {
|
|
356
|
+
"text": "lorem ipsum",
|
|
357
|
+
"type": "text",
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
"type": "paragraph",
|
|
361
|
+
},
|
|
362
|
+
],
|
|
363
|
+
"type": "listItem",
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
"type": "list",
|
|
367
|
+
},
|
|
368
|
+
],
|
|
369
|
+
"type": "doc",
|
|
370
|
+
}
|
|
371
|
+
`;
|
|
372
|
+
|
|
373
|
+
exports[`parsing html should set null to list item with preset 1`] = `
|
|
374
|
+
Object {
|
|
375
|
+
"content": Array [
|
|
376
|
+
Object {
|
|
377
|
+
"attrs": Object {
|
|
378
|
+
"bullet": Object {
|
|
379
|
+
"type": "disc",
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
"content": Array [
|
|
383
|
+
Object {
|
|
384
|
+
"content": Array [
|
|
385
|
+
Object {
|
|
386
|
+
"attrs": Object {
|
|
387
|
+
"alignment": null,
|
|
388
|
+
"preset": null,
|
|
389
|
+
},
|
|
390
|
+
"content": Array [
|
|
391
|
+
Object {
|
|
392
|
+
"text": "lorem ipsum",
|
|
393
|
+
"type": "text",
|
|
394
|
+
},
|
|
395
|
+
],
|
|
396
|
+
"type": "paragraph",
|
|
397
|
+
},
|
|
398
|
+
],
|
|
399
|
+
"type": "listItem",
|
|
400
|
+
},
|
|
401
|
+
],
|
|
402
|
+
"type": "list",
|
|
403
|
+
},
|
|
404
|
+
],
|
|
405
|
+
"type": "doc",
|
|
406
|
+
}
|
|
407
|
+
`;
|
|
408
|
+
|
|
244
409
|
exports[`remove preset customization should remove all attributes 1`] = `
|
|
245
410
|
Object {
|
|
246
411
|
"content": Array [
|
|
@@ -305,6 +470,6 @@ Object {
|
|
|
305
470
|
|
|
306
471
|
exports[`render preset styles should render node without preset 1`] = `"<p class=\\"zw-style\\">test</p>"`;
|
|
307
472
|
|
|
308
|
-
exports[`render preset styles should render preset class 1`] = `"<p class=\\"zw-style zw-
|
|
473
|
+
exports[`render preset styles should render preset class 1`] = `"<p class=\\"zw-style zw ts-regular-1\\">test</p>"`;
|
|
309
474
|
|
|
310
|
-
exports[`render preset styles should render styles 1`] = `" .zw-
|
|
475
|
+
exports[`render preset styles should render styles 1`] = `" .zw.ts-regular-1 { --zw-preset-font-weight: var(--common-regular-1-font-weight, inherit); --zw-preset-mobile-font-size: var(--mobile-regular-1-font-size, inherit); --zw-preset-tablet-font-size: var(--tablet-regular-1-font-size, inherit); --zw-preset-desktop-font-size: var(--desktop-regular-1-font-size, inherit); }"`;
|
|
@@ -199,6 +199,213 @@ Object {
|
|
|
199
199
|
}
|
|
200
200
|
`;
|
|
201
201
|
|
|
202
|
+
exports[`parsing html should get both from paragraph 1`] = `
|
|
203
|
+
Object {
|
|
204
|
+
"content": Array [
|
|
205
|
+
Object {
|
|
206
|
+
"content": Array [
|
|
207
|
+
Object {
|
|
208
|
+
"marks": Array [
|
|
209
|
+
Object {
|
|
210
|
+
"attrs": Object {
|
|
211
|
+
"strike_through": true,
|
|
212
|
+
"underline": true,
|
|
213
|
+
},
|
|
214
|
+
"type": "text_decoration",
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
"text": "test",
|
|
218
|
+
"type": "text",
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
"type": "paragraph",
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
"type": "doc",
|
|
225
|
+
}
|
|
226
|
+
`;
|
|
227
|
+
|
|
228
|
+
exports[`parsing html should get both from text 1`] = `
|
|
229
|
+
Object {
|
|
230
|
+
"content": Array [
|
|
231
|
+
Object {
|
|
232
|
+
"content": Array [
|
|
233
|
+
Object {
|
|
234
|
+
"marks": Array [
|
|
235
|
+
Object {
|
|
236
|
+
"attrs": Object {
|
|
237
|
+
"strike_through": true,
|
|
238
|
+
"underline": true,
|
|
239
|
+
},
|
|
240
|
+
"type": "text_decoration",
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
"text": "lorem",
|
|
244
|
+
"type": "text",
|
|
245
|
+
},
|
|
246
|
+
Object {
|
|
247
|
+
"text": " ipsum",
|
|
248
|
+
"type": "text",
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
"type": "paragraph",
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
"type": "doc",
|
|
255
|
+
}
|
|
256
|
+
`;
|
|
257
|
+
|
|
258
|
+
exports[`parsing html should get strike through from paragraph 1`] = `
|
|
259
|
+
Object {
|
|
260
|
+
"content": Array [
|
|
261
|
+
Object {
|
|
262
|
+
"content": Array [
|
|
263
|
+
Object {
|
|
264
|
+
"marks": Array [
|
|
265
|
+
Object {
|
|
266
|
+
"attrs": Object {
|
|
267
|
+
"strike_through": true,
|
|
268
|
+
"underline": false,
|
|
269
|
+
},
|
|
270
|
+
"type": "text_decoration",
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
"text": "test",
|
|
274
|
+
"type": "text",
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
"type": "paragraph",
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
"type": "doc",
|
|
281
|
+
}
|
|
282
|
+
`;
|
|
283
|
+
|
|
284
|
+
exports[`parsing html should get strike through from text 1`] = `
|
|
285
|
+
Object {
|
|
286
|
+
"content": Array [
|
|
287
|
+
Object {
|
|
288
|
+
"content": Array [
|
|
289
|
+
Object {
|
|
290
|
+
"marks": Array [
|
|
291
|
+
Object {
|
|
292
|
+
"attrs": Object {
|
|
293
|
+
"strike_through": true,
|
|
294
|
+
"underline": false,
|
|
295
|
+
},
|
|
296
|
+
"type": "text_decoration",
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
|
+
"text": "lorem",
|
|
300
|
+
"type": "text",
|
|
301
|
+
},
|
|
302
|
+
Object {
|
|
303
|
+
"text": " ipsum",
|
|
304
|
+
"type": "text",
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
"type": "paragraph",
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
"type": "doc",
|
|
311
|
+
}
|
|
312
|
+
`;
|
|
313
|
+
|
|
314
|
+
exports[`parsing html should get underline from paragraph 1`] = `
|
|
315
|
+
Object {
|
|
316
|
+
"content": Array [
|
|
317
|
+
Object {
|
|
318
|
+
"content": Array [
|
|
319
|
+
Object {
|
|
320
|
+
"marks": Array [
|
|
321
|
+
Object {
|
|
322
|
+
"attrs": Object {
|
|
323
|
+
"strike_through": false,
|
|
324
|
+
"underline": true,
|
|
325
|
+
},
|
|
326
|
+
"type": "text_decoration",
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
"text": "test",
|
|
330
|
+
"type": "text",
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
"type": "paragraph",
|
|
334
|
+
},
|
|
335
|
+
],
|
|
336
|
+
"type": "doc",
|
|
337
|
+
}
|
|
338
|
+
`;
|
|
339
|
+
|
|
340
|
+
exports[`parsing html should get underline from text 1`] = `
|
|
341
|
+
Object {
|
|
342
|
+
"content": Array [
|
|
343
|
+
Object {
|
|
344
|
+
"content": Array [
|
|
345
|
+
Object {
|
|
346
|
+
"marks": Array [
|
|
347
|
+
Object {
|
|
348
|
+
"attrs": Object {
|
|
349
|
+
"strike_through": false,
|
|
350
|
+
"underline": true,
|
|
351
|
+
},
|
|
352
|
+
"type": "text_decoration",
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
"text": "lorem",
|
|
356
|
+
"type": "text",
|
|
357
|
+
},
|
|
358
|
+
Object {
|
|
359
|
+
"text": " ipsum",
|
|
360
|
+
"type": "text",
|
|
361
|
+
},
|
|
362
|
+
],
|
|
363
|
+
"type": "paragraph",
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
"type": "doc",
|
|
367
|
+
}
|
|
368
|
+
`;
|
|
369
|
+
|
|
370
|
+
exports[`parsing html should merge paragraph and text settings 1`] = `
|
|
371
|
+
Object {
|
|
372
|
+
"content": Array [
|
|
373
|
+
Object {
|
|
374
|
+
"content": Array [
|
|
375
|
+
Object {
|
|
376
|
+
"marks": Array [
|
|
377
|
+
Object {
|
|
378
|
+
"attrs": Object {
|
|
379
|
+
"strike_through": true,
|
|
380
|
+
"underline": false,
|
|
381
|
+
},
|
|
382
|
+
"type": "text_decoration",
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
"text": "lorem",
|
|
386
|
+
"type": "text",
|
|
387
|
+
},
|
|
388
|
+
Object {
|
|
389
|
+
"marks": Array [
|
|
390
|
+
Object {
|
|
391
|
+
"attrs": Object {
|
|
392
|
+
"strike_through": false,
|
|
393
|
+
"underline": true,
|
|
394
|
+
},
|
|
395
|
+
"type": "text_decoration",
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
"text": " ipsum",
|
|
399
|
+
"type": "text",
|
|
400
|
+
},
|
|
401
|
+
],
|
|
402
|
+
"type": "paragraph",
|
|
403
|
+
},
|
|
404
|
+
],
|
|
405
|
+
"type": "doc",
|
|
406
|
+
}
|
|
407
|
+
`;
|
|
408
|
+
|
|
202
409
|
exports[`rendering should render both 1`] = `"<p class=\\"zw-style\\"><span style=\\"--zw-text-decoration: underline line-through;\\" class=\\"zw-style\\">hello world</span></p>"`;
|
|
203
410
|
|
|
204
411
|
exports[`rendering should render strike through only 1`] = `"<p class=\\"zw-style\\"><span style=\\"--zw-text-decoration: line-through;\\" class=\\"zw-style\\">hello world</span></p>"`;
|
|
@@ -2,6 +2,7 @@ import { Editor, Extension } from '@tiptap/vue-2';
|
|
|
2
2
|
import { NodeFactory } from '../../../__tests__/utils';
|
|
3
3
|
import { CORE_EXTENSIONS } from '../index';
|
|
4
4
|
import { NodeTypes } from '../../../enums';
|
|
5
|
+
import { ContentNormalizer } from '../../../services';
|
|
5
6
|
|
|
6
7
|
const LineHeight = Extension.create({
|
|
7
8
|
name: 'line_height',
|
|
@@ -20,8 +21,10 @@ const LineHeight = Extension.create({
|
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
function createEditor({ content }) {
|
|
24
|
+
const normalizer = new ContentNormalizer();
|
|
25
|
+
|
|
23
26
|
return new Editor({
|
|
24
|
-
content,
|
|
27
|
+
content: normalizer.normalize(content),
|
|
25
28
|
extensions: CORE_EXTENSIONS.concat(LineHeight) // Included to core extensions
|
|
26
29
|
});
|
|
27
30
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { Editor } from '@tiptap/vue-2';
|
|
2
2
|
import { CORE_EXTENSIONS } from '../index';
|
|
3
3
|
import { NodeFactory } from '../../../__tests__/utils';
|
|
4
|
+
import { ContentNormalizer } from '../../../services';
|
|
4
5
|
|
|
5
6
|
function createEditor() {
|
|
7
|
+
const normalizer = new ContentNormalizer();
|
|
8
|
+
|
|
9
|
+
const content = NodeFactory.doc([
|
|
10
|
+
NodeFactory.paragraph('Lorem ipsum dolor sit amet'),
|
|
11
|
+
NodeFactory.paragraph('consectetur adipisicing elit')
|
|
12
|
+
]);
|
|
13
|
+
|
|
6
14
|
return new Editor({
|
|
7
|
-
content:
|
|
8
|
-
NodeFactory.paragraph('Lorem ipsum dolor sit amet'),
|
|
9
|
-
NodeFactory.paragraph('consectetur adipisicing elit')
|
|
10
|
-
]),
|
|
15
|
+
content: normalizer.normalize(content),
|
|
11
16
|
extensions: CORE_EXTENSIONS // included to core
|
|
12
17
|
});
|
|
13
18
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Editor, Mark } from '@tiptap/vue-2';
|
|
2
2
|
import { NodeFactory } from '../../../__tests__/utils';
|
|
3
3
|
import { CORE_EXTENSIONS } from '../index';
|
|
4
|
+
import { ContentNormalizer } from '../../../services';
|
|
4
5
|
|
|
5
6
|
const MockFontWeight = Mark.create({
|
|
6
7
|
name: 'font_weight',
|
|
@@ -17,8 +18,10 @@ const MockFontWeight = Mark.create({
|
|
|
17
18
|
});
|
|
18
19
|
|
|
19
20
|
function createEditor({ content }) {
|
|
21
|
+
const normalizer = new ContentNormalizer();
|
|
22
|
+
|
|
20
23
|
return new Editor({
|
|
21
|
-
content,
|
|
24
|
+
content: normalizer.normalize(content),
|
|
22
25
|
element: document.createElement('div'),
|
|
23
26
|
extensions: CORE_EXTENSIONS.concat(MockFontWeight)
|
|
24
27
|
});
|
package/lib/extensions/index.js
CHANGED
|
@@ -22,6 +22,7 @@ export const getExtensions = (options) => CORE_EXTENSIONS.concat([
|
|
|
22
22
|
StylePreset.configure({
|
|
23
23
|
presetsRef: options.presetsRef,
|
|
24
24
|
defaultId: options.defaultPresetId,
|
|
25
|
+
baseClass: options.basePresetClass,
|
|
25
26
|
makeVariable: options.makePresetVariable
|
|
26
27
|
}),
|
|
27
28
|
List.configure({
|
|
@@ -21,6 +21,40 @@ export const List = Node.create({
|
|
|
21
21
|
bullet: { isRequired: true }
|
|
22
22
|
}),
|
|
23
23
|
|
|
24
|
+
parseHTML() {
|
|
25
|
+
const HTML_TYPES = {
|
|
26
|
+
a: ListTypes.ROMAN,
|
|
27
|
+
i: ListTypes.LATIN,
|
|
28
|
+
'1': ListTypes.DECIMAL
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const getBulletType = (element) => {
|
|
32
|
+
for (const type of ListTypes.values) {
|
|
33
|
+
const bulletClass = `.${this.options.baseClass}${type}`;
|
|
34
|
+
|
|
35
|
+
if (element.matches(bulletClass)) return type;
|
|
36
|
+
if (HTML_TYPES[element.type.toLowerCase()] === type) return type;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return [
|
|
41
|
+
{
|
|
42
|
+
tag: 'ol',
|
|
43
|
+
|
|
44
|
+
getAttrs: (element) => ({
|
|
45
|
+
bullet: { type: getBulletType(element) || ListTypes.DECIMAL }
|
|
46
|
+
})
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
tag: 'ul',
|
|
50
|
+
|
|
51
|
+
getAttrs: (element) => ({
|
|
52
|
+
bullet: { type: getBulletType(element) || ListTypes.DISC }
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
];
|
|
56
|
+
},
|
|
57
|
+
|
|
24
58
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
25
59
|
const isOrdered = ListTypes.ordered.includes(attrs.bullet.type);
|
|
26
60
|
const tag = isOrdered ? 'ol' : 'ul';
|
|
@@ -5,13 +5,18 @@ import { ListTypes } from '../../../enums';
|
|
|
5
5
|
import { CORE_EXTENSIONS } from '../../core';
|
|
6
6
|
import { StylePreset } from '../../StylePreset';
|
|
7
7
|
import { List } from '../List';
|
|
8
|
+
import { ContentNormalizer } from '../../../services';
|
|
8
9
|
|
|
9
10
|
function createEditor({ content }) {
|
|
11
|
+
const normalizer = new ContentNormalizer();
|
|
12
|
+
|
|
10
13
|
return new Editor({
|
|
11
|
-
content,
|
|
14
|
+
content: normalizer.normalize(content),
|
|
12
15
|
element: document.createElement('div'),
|
|
13
16
|
extensions: CORE_EXTENSIONS.concat(
|
|
14
|
-
List
|
|
17
|
+
List.configure({
|
|
18
|
+
baseClass: 'zw-list--'
|
|
19
|
+
}),
|
|
15
20
|
StylePreset.configure({
|
|
16
21
|
presetsRef: ref([
|
|
17
22
|
{
|
|
@@ -22,7 +27,8 @@ function createEditor({ content }) {
|
|
|
22
27
|
desktop: {}
|
|
23
28
|
}
|
|
24
29
|
]),
|
|
25
|
-
defaultId: 'regular-1'
|
|
30
|
+
defaultId: 'regular-1',
|
|
31
|
+
baseClass: 'zw ts-'
|
|
26
32
|
})
|
|
27
33
|
)
|
|
28
34
|
});
|
|
@@ -128,3 +134,109 @@ describe('apply list', () => {
|
|
|
128
134
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
129
135
|
});
|
|
130
136
|
});
|
|
137
|
+
|
|
138
|
+
describe('parsing html', () => {
|
|
139
|
+
test('should parse disc type by class', () => {
|
|
140
|
+
const editor = createEditor({
|
|
141
|
+
content: '<ul class="zw-list--disc"><li>lorem ipsum</li></ul>'
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('should parse disc as default', () => {
|
|
148
|
+
const editor = createEditor({
|
|
149
|
+
content: '<ul><li>lorem ipsum</li></ul>'
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('should parse circle type by class', () => {
|
|
156
|
+
const editor = createEditor({
|
|
157
|
+
content: '<ul class="zw-list--circle"><li>lorem ipsum</li></ul>'
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('should parse square type by class', () => {
|
|
164
|
+
const editor = createEditor({
|
|
165
|
+
content: '<ul class="zw-list--square"><li>lorem ipsum</li></ul>'
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('should parse decimal type by class', () => {
|
|
172
|
+
const editor = createEditor({
|
|
173
|
+
content: '<ol class="zw-list--decimal"><li>lorem ipsum</li></ol>'
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('should parse decimal as default', () => {
|
|
180
|
+
const editor = createEditor({
|
|
181
|
+
content: '<ol><li>lorem ipsum</li></ol>'
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('should parse decimal type by attribute', () => {
|
|
188
|
+
const editor = createEditor({
|
|
189
|
+
content: '<ol type="1"><li>lorem ipsum</li></ol>'
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('should parse roman type by class', () => {
|
|
196
|
+
const editor = createEditor({
|
|
197
|
+
content: '<ol class="zw-list--roman"><li>lorem ipsum</li></ol>'
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('should parse roman type by lower attribute', () => {
|
|
204
|
+
const editor = createEditor({
|
|
205
|
+
content: '<ol type="a"><li>lorem ipsum</li></ol>'
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('should parse roman type by upper attribute', () => {
|
|
212
|
+
const editor = createEditor({
|
|
213
|
+
content: '<ol type="A"><li>lorem ipsum</li></ol>'
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('should parse latin type by class', () => {
|
|
220
|
+
const editor = createEditor({
|
|
221
|
+
content: '<ol class="zw-list--latin"><li>lorem ipsum</li></ol>'
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('should parse latin type by lower attribute', () => {
|
|
228
|
+
const editor = createEditor({
|
|
229
|
+
content: '<ol type="i"><li>lorem ipsum</li></ol>'
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('should parse latin type by upper attribute', () => {
|
|
236
|
+
const editor = createEditor({
|
|
237
|
+
content: '<ol type="I"><li>lorem ipsum</li></ol>'
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
241
|
+
});
|
|
242
|
+
});
|