@zipify/wysiwyg 4.12.0-beta.2 → 4.12.0-beta.3

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 (48) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +27 -27
  3. package/dist/node.js +21 -21
  4. package/dist/types/enums/Device.d.ts +2 -1
  5. package/dist/types/enums/TextSetting.d.ts +0 -1
  6. package/dist/types/services/NodeFactory.d.ts +1 -1
  7. package/dist/types/utils/clone.d.ts +1 -0
  8. package/dist/types/utils/index.d.ts +1 -1
  9. package/dist/wysiwyg.css +28 -46
  10. package/dist/wysiwyg.mjs +184 -326
  11. package/example/ExampleApp.vue +6 -3
  12. package/example/presets.js +203 -227
  13. package/lib/components/base/NumberField.vue +2 -2
  14. package/lib/components/toolbar/controls/index.js +0 -1
  15. package/lib/components/toolbar/layouts/ToolbarDesktop.vue +0 -2
  16. package/lib/components/toolbar/layouts/ToolbarMobile.vue +0 -2
  17. package/lib/enums/Device.ts +2 -1
  18. package/lib/enums/TextSetting.ts +0 -2
  19. package/lib/extensions/Alignment.js +3 -2
  20. package/lib/extensions/DeviceManager.js +20 -3
  21. package/lib/extensions/FontSize.js +12 -6
  22. package/lib/extensions/LineHeight.js +3 -2
  23. package/lib/extensions/__tests__/Alignment.test.js +14 -2
  24. package/lib/extensions/__tests__/FontSize.test.js +14 -2
  25. package/lib/extensions/__tests__/LineHeight.test.js +14 -2
  26. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +27 -0
  27. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +30 -0
  28. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +27 -0
  29. package/lib/extensions/core/NodeProcessor.js +4 -2
  30. package/lib/extensions/core/__tests__/NodeProcessor.test.js +10 -1
  31. package/lib/extensions/index.js +0 -2
  32. package/lib/services/NodeFactory.ts +1 -1
  33. package/lib/styles/content.css +0 -3
  34. package/lib/utils/clone.ts +3 -0
  35. package/lib/utils/convertFontSize.js +7 -2
  36. package/lib/utils/index.ts +1 -1
  37. package/package.json +3 -2
  38. package/dist/types/components/toolbar/controls/LetterSpacingControl.vue.d.ts +0 -2
  39. package/dist/types/extensions/LetterSpacing.d.ts +0 -2
  40. package/dist/types/utils/convertEmToPx.d.ts +0 -1
  41. package/dist/types/utils/convertLetterSpacing.d.ts +0 -1
  42. package/lib/assets/icons/letter-spacing.svg +0 -3
  43. package/lib/components/toolbar/controls/LetterSpacingControl.vue +0 -96
  44. package/lib/extensions/LetterSpacing.js +0 -78
  45. package/lib/extensions/__tests__/LetterSpacing.test.js +0 -117
  46. package/lib/extensions/__tests__/__snapshots__/LetterSpacing.test.js.snap +0 -121
  47. package/lib/utils/convertEmToPx.ts +0 -8
  48. package/lib/utils/convertLetterSpacing.ts +0 -5
@@ -1,117 +0,0 @@
1
- import { Editor, Extension } from '@tiptap/vue-3';
2
- import { ref } from 'vue';
3
- import { buildTestExtensions } from '../../__tests__/utils';
4
- import { createCommand } from '../../utils';
5
- import { DeviceManager } from '../DeviceManager';
6
- import { LetterSpacing } from '../LetterSpacing';
7
- import { ContentNormalizer, NodeFactory } from '../../services';
8
- import { TextSetting } from '../../enums';
9
-
10
- const MockStylePreset = Extension.create({
11
- name: TextSetting.STYLE_PRESET,
12
-
13
- addCommands() {
14
- return {
15
- getPreset: createCommand(() => ref({
16
- mobile: { letter_spacing: null },
17
- tablet: { letter_spacing: null },
18
- desktop: { letter_spacing: null }
19
- }))
20
- };
21
- }
22
- });
23
-
24
- function createEditor({ content, wrapperEl } = {}) {
25
- return new Editor({
26
- content: ContentNormalizer.normalize(content),
27
- extensions: buildTestExtensions({
28
- include: [
29
- MockStylePreset,
30
- DeviceManager.configure({
31
- device: ref('desktop')
32
- }),
33
- LetterSpacing.configure({ wrapperRef: ref(wrapperEl ?? document.createElement('div')) })
34
- ]
35
- })
36
- });
37
- }
38
-
39
- const createContent = (attrs) => NodeFactory.doc([
40
- NodeFactory.paragraph(attrs, [
41
- NodeFactory.text('hello world')
42
- ])
43
- ]);
44
-
45
- describe('LetterSpacing extension', () => {
46
- describe('get value', () => {
47
- test('should get from selection', () => {
48
- const editor = createEditor({
49
- content: NodeFactory.doc([
50
- NodeFactory.paragraph({}, [
51
- NodeFactory.text('hello world', [
52
- NodeFactory.mark(TextSetting.LETTER_SPACING, {
53
- mobile: '',
54
- tablet: '',
55
- desktop: '-0.7px'
56
- })
57
- ])
58
- ])
59
- ])
60
- });
61
-
62
- editor.commands.selectAll();
63
-
64
- expect(editor.commands.getLetterSpacing().value).toBe('-0.7px');
65
- });
66
-
67
- test('should get default value from preset when null', () => {
68
- const editor = createEditor({
69
- content: createContent({ letter_spacing: null })
70
- });
71
-
72
- expect(editor.commands.getDefaultLetterSpacing().value).toBe(null);
73
- });
74
- });
75
-
76
- describe('apply value', () => {
77
- test('should change value', () => {
78
- const editor = createEditor({
79
- content: createContent({ letter_spacing: null })
80
- });
81
-
82
- editor.commands.selectAll();
83
- editor.commands.applyLetterSpacing('-1');
84
-
85
- expect(editor.getJSON()).toMatchSnapshot();
86
- });
87
-
88
- test('should apply value 0', () => {
89
- const editor = createEditor({
90
- content: createContent({ letter_spacing: 2 })
91
- });
92
-
93
- editor.commands.selectAll();
94
- editor.commands.applyLetterSpacing(0);
95
-
96
- expect(editor.getJSON()).toMatchSnapshot();
97
- });
98
- });
99
-
100
- describe('parsing html', () => {
101
- test('should parse inline letter-spacing px to value with px preserved', () => {
102
- const editor = createEditor({
103
- content: '<p style="letter-spacing: -0.7px">test</p>'
104
- });
105
-
106
- expect(editor.getJSON()).toMatchSnapshot();
107
- });
108
-
109
- test('should parse custom var style', () => {
110
- const editor = createEditor({
111
- content: '<p style="--zw-letter-spacing-desktop: -0.7px;--zw-letter-spacing-tablet: 0px;--zw-letter-spacing-mobile: 3.6px">test</p>'
112
- });
113
-
114
- expect(editor.getJSON()).toMatchSnapshot();
115
- });
116
- });
117
- });
@@ -1,121 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`LetterSpacing extension apply value should apply value 0 1`] = `
4
- Object {
5
- "attrs": Object {
6
- "meta": Object {},
7
- },
8
- "content": Array [
9
- Object {
10
- "content": Array [
11
- Object {
12
- "text": "hello world",
13
- "type": "text",
14
- },
15
- ],
16
- "marks": Array [
17
- Object {
18
- "attrs": Object {
19
- "desktop": 0,
20
- "mobile": null,
21
- "tablet": null,
22
- },
23
- "type": "letter_spacing",
24
- },
25
- ],
26
- "type": "paragraph",
27
- },
28
- ],
29
- "type": "doc",
30
- }
31
- `;
32
-
33
- exports[`LetterSpacing extension apply value should change value 1`] = `
34
- Object {
35
- "attrs": Object {
36
- "meta": Object {},
37
- },
38
- "content": Array [
39
- Object {
40
- "content": Array [
41
- Object {
42
- "text": "hello world",
43
- "type": "text",
44
- },
45
- ],
46
- "marks": Array [
47
- Object {
48
- "attrs": Object {
49
- "desktop": "-1",
50
- "mobile": null,
51
- "tablet": null,
52
- },
53
- "type": "letter_spacing",
54
- },
55
- ],
56
- "type": "paragraph",
57
- },
58
- ],
59
- "type": "doc",
60
- }
61
- `;
62
-
63
- exports[`LetterSpacing extension parsing html should parse custom var style 1`] = `
64
- Object {
65
- "attrs": Object {
66
- "meta": Object {},
67
- },
68
- "content": Array [
69
- Object {
70
- "content": Array [
71
- Object {
72
- "text": "test",
73
- "type": "text",
74
- },
75
- ],
76
- "marks": Array [
77
- Object {
78
- "attrs": Object {
79
- "desktop": "-0.7px",
80
- "mobile": "3.6px",
81
- "tablet": "0px",
82
- },
83
- "type": "letter_spacing",
84
- },
85
- ],
86
- "type": "paragraph",
87
- },
88
- ],
89
- "type": "doc",
90
- }
91
- `;
92
-
93
- exports[`LetterSpacing extension parsing html should parse inline letter-spacing px to value with px preserved 1`] = `
94
- Object {
95
- "attrs": Object {
96
- "meta": Object {},
97
- },
98
- "content": Array [
99
- Object {
100
- "content": Array [
101
- Object {
102
- "text": "test",
103
- "type": "text",
104
- },
105
- ],
106
- "marks": Array [
107
- Object {
108
- "attrs": Object {
109
- "desktop": "-0.7px",
110
- "mobile": "-0.7px",
111
- "tablet": "-0.7px",
112
- },
113
- "type": "letter_spacing",
114
- },
115
- ],
116
- "type": "paragraph",
117
- },
118
- ],
119
- "type": "doc",
120
- }
121
- `;
@@ -1,8 +0,0 @@
1
- import { ContextWindow } from '../services';
2
-
3
- export function convertEmToPx(value: string, wrapperEl: HTMLElement): number {
4
- const containerValue = ContextWindow.getComputedStyle(wrapperEl).fontSize;
5
- const size = parseFloat(value) * parseFloat(containerValue);
6
-
7
- return Math.round(size * 10) / 10;
8
- }
@@ -1,5 +0,0 @@
1
- import { convertEmToPx } from './convertEmToPx';
2
-
3
- export function convertLetterSpacing(value: string, wrapperEl: HTMLElement): number {
4
- return String(value).includes('em') ? convertEmToPx(value, wrapperEl) : parseFloat(value);
5
- }