@zipify/wysiwyg 1.0.0-dev.6 → 1.0.0-dev.60

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 (216) hide show
  1. package/.editorconfig +1 -1
  2. package/.eslintrc.js +2 -2
  3. package/.github/dependabot.yaml +1 -0
  4. package/.lintstagedrc +2 -2
  5. package/.release-it.json +3 -1
  6. package/.stylelintrc +0 -4
  7. package/README.md +2 -2
  8. package/config/jest/setupTests.js +0 -3
  9. package/config/vite/example.config.js +25 -0
  10. package/config/vite/lib.config.js +28 -0
  11. package/config/{webpack → vite}/settings.js +0 -0
  12. package/dist/wysiwyg.css +1 -837
  13. package/dist/wysiwyg.mjs +18339 -0
  14. package/example/ExampleApp.vue +21 -2
  15. package/example/example.js +0 -3
  16. package/example/{example.html → index.html} +1 -0
  17. package/example/pageBlocks.js +31 -0
  18. package/example/presets.js +2 -2
  19. package/example/tooltip/Tooltip.js +1 -1
  20. package/jest.config.js +3 -1
  21. package/lib/Wysiwyg.vue +51 -26
  22. package/lib/__tests__/utils/NodeFactory.js +13 -0
  23. package/lib/__tests__/utils/withComponentContext.js +1 -1
  24. package/lib/assets/icons/link.svg +3 -0
  25. package/lib/assets/icons/unlink.svg +3 -0
  26. package/lib/components/base/Button.vue +22 -2
  27. package/lib/components/base/Checkbox.vue +89 -0
  28. package/lib/components/base/FieldLabel.vue +2 -1
  29. package/lib/components/base/Icon.vue +3 -3
  30. package/lib/components/base/Modal.vue +1 -2
  31. package/lib/components/base/NumberField.vue +2 -2
  32. package/lib/components/base/Range.vue +1 -1
  33. package/lib/components/base/ScrollView.vue +1 -3
  34. package/lib/components/base/TextField.vue +106 -0
  35. package/lib/components/base/__tests__/Modal.test.js +7 -2
  36. package/lib/components/base/__tests__/TextField.test.js +57 -0
  37. package/lib/components/base/__tests__/__snapshots__/TextField.test.js.snap +9 -0
  38. package/lib/components/base/colorPicker/ColorPicker.vue +2 -2
  39. package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +1 -1
  40. package/lib/components/base/colorPicker/composables/usePickerApi.js +3 -3
  41. package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +3 -2
  42. package/lib/components/base/composables/__tests__/useActivatedListener.test.js +1 -1
  43. package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +1 -1
  44. package/lib/components/base/composables/__tests__/useElementRef.test.js +1 -1
  45. package/lib/components/base/composables/__tests__/useModalToggler.test.js +1 -1
  46. package/lib/components/base/composables/__tests__/useNumberValue.test.js +1 -1
  47. package/lib/components/base/composables/__tests__/useScrollView.test.js +1 -1
  48. package/lib/components/base/composables/__tests__/useTempValue.test.js +1 -1
  49. package/lib/components/base/composables/__tests__/useValidator.test.js +44 -0
  50. package/lib/components/base/composables/index.js +1 -0
  51. package/lib/components/base/composables/useActivatedListener.js +1 -1
  52. package/lib/components/base/composables/useDeselectionLock.js +1 -1
  53. package/lib/components/base/composables/useElementRef.js +1 -1
  54. package/lib/components/base/composables/useModalToggler.js +1 -1
  55. package/lib/components/base/composables/useScrollView.js +1 -1
  56. package/lib/components/base/composables/useTempValue.js +1 -1
  57. package/lib/components/base/composables/useValidator.js +23 -0
  58. package/lib/components/base/dropdown/Dropdown.vue +16 -4
  59. package/lib/components/base/dropdown/DropdownActivator.vue +19 -3
  60. package/lib/components/base/dropdown/DropdownGroup.vue +1 -1
  61. package/lib/components/base/dropdown/DropdownMenu.vue +1 -1
  62. package/lib/components/base/dropdown/DropdownOption.vue +1 -1
  63. package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +1 -1
  64. package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +1 -1
  65. package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +1 -1
  66. package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +1 -1
  67. package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +1 -1
  68. package/lib/components/base/dropdown/composables/useActiveOptionManager.js +1 -1
  69. package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +1 -1
  70. package/lib/components/base/index.js +3 -1
  71. package/lib/components/toolbar/Toolbar.vue +49 -9
  72. package/lib/components/toolbar/ToolbarDivider.vue +1 -1
  73. package/lib/components/toolbar/ToolbarFull.vue +10 -2
  74. package/lib/components/toolbar/ToolbarRow.vue +1 -0
  75. package/lib/components/toolbar/__tests__/Toolbar.test.js +6 -0
  76. package/lib/components/toolbar/controls/AlignmentControl.vue +1 -1
  77. package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +1 -1
  78. package/lib/components/toolbar/controls/BackgroundColorControl.vue +1 -1
  79. package/lib/components/toolbar/controls/CaseStyleControl.vue +1 -1
  80. package/lib/components/toolbar/controls/FontColorControl.vue +1 -1
  81. package/lib/components/toolbar/controls/FontFamilyControl.vue +1 -1
  82. package/lib/components/toolbar/controls/FontSizeControl.vue +8 -1
  83. package/lib/components/toolbar/controls/FontWeightControl.vue +1 -1
  84. package/lib/components/toolbar/controls/ItalicControl.vue +1 -1
  85. package/lib/components/toolbar/controls/LineHeightControl.vue +1 -1
  86. package/lib/components/toolbar/controls/ListControl.vue +68 -34
  87. package/lib/components/toolbar/controls/RemoveFormatControl.vue +1 -1
  88. package/lib/components/toolbar/controls/StrikeThroughControl.vue +1 -1
  89. package/lib/components/toolbar/controls/StylePresetControl.vue +15 -2
  90. package/lib/components/toolbar/controls/SuperscriptControl.vue +1 -1
  91. package/lib/components/toolbar/controls/UnderlineControl.vue +2 -2
  92. package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +1 -1
  93. package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +1 -1
  94. package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +1 -1
  95. package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +1 -1
  96. package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +1 -1
  97. package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +1 -1
  98. package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +1 -1
  99. package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +1 -1
  100. package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +1 -1
  101. package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +1 -1
  102. package/lib/components/toolbar/controls/__tests__/ListControl.test.js +18 -3
  103. package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +1 -1
  104. package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +17 -1
  105. package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +5 -1
  106. package/lib/components/toolbar/controls/composables/useRecentFonts.js +1 -1
  107. package/lib/components/toolbar/controls/index.js +1 -0
  108. package/lib/components/toolbar/controls/link/LinkControl.vue +155 -0
  109. package/lib/components/toolbar/controls/link/LinkControlApply.vue +35 -0
  110. package/lib/components/toolbar/controls/link/LinkControlHeader.vue +67 -0
  111. package/lib/components/toolbar/controls/link/__tests__/LinkControl.test.js +79 -0
  112. package/lib/components/toolbar/controls/link/__tests__/LinkControlHeader.test.js +42 -0
  113. package/lib/components/toolbar/controls/link/composables/__tests__/__snapshots__/useLink.test.js.snap +8 -0
  114. package/lib/components/toolbar/controls/link/composables/__tests__/useLink.test.js +114 -0
  115. package/lib/components/toolbar/controls/link/composables/index.js +1 -0
  116. package/lib/components/toolbar/controls/link/composables/useLink.js +61 -0
  117. package/lib/components/toolbar/controls/link/destination/LinkControlDestination.vue +103 -0
  118. package/lib/components/toolbar/controls/link/destination/LinkControlPageBlock.vue +54 -0
  119. package/lib/components/toolbar/controls/link/destination/LinkControlUrl.vue +52 -0
  120. package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlPageBlock.test.js +36 -0
  121. package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlUrl.test.js +46 -0
  122. package/lib/components/toolbar/controls/link/destination/__tests__/__snapshots__/LinkControlPageBlock.test.js.snap +9 -0
  123. package/lib/components/toolbar/controls/link/destination/__tests__/__snapshots__/LinkControlUrl.test.js.snap +17 -0
  124. package/lib/components/toolbar/controls/link/destination/index.js +1 -0
  125. package/lib/components/toolbar/controls/link/index.js +1 -0
  126. package/lib/composables/__tests__/useEditor.test.js +3 -3
  127. package/lib/composables/useEditor.js +6 -8
  128. package/lib/composables/useToolbar.js +23 -28
  129. package/lib/directives/__tests__/outClick.test.js +6 -0
  130. package/lib/directives/outClick.js +19 -6
  131. package/lib/enums/Alignments.js +10 -1
  132. package/lib/enums/LinkDestinations.js +4 -0
  133. package/lib/enums/LinkTargets.js +4 -0
  134. package/lib/enums/TextSettings.js +3 -1
  135. package/lib/enums/index.js +2 -0
  136. package/lib/extensions/Alignment.js +22 -8
  137. package/lib/extensions/BackgroundColor.js +15 -7
  138. package/lib/extensions/DeviceManager.js +2 -5
  139. package/lib/extensions/FontColor.js +15 -7
  140. package/lib/extensions/FontFamily.js +26 -9
  141. package/lib/extensions/FontSize.js +32 -13
  142. package/lib/extensions/FontStyle.js +24 -14
  143. package/lib/extensions/FontWeight.js +25 -15
  144. package/lib/extensions/LineHeight.js +32 -29
  145. package/lib/extensions/Link.js +90 -0
  146. package/lib/extensions/StylePreset.js +20 -19
  147. package/lib/extensions/TextDecoration.js +46 -13
  148. package/lib/extensions/__tests__/Alignment.test.js +13 -7
  149. package/lib/extensions/__tests__/BackgroundColor.test.js +12 -6
  150. package/lib/extensions/__tests__/CaseStyle.test.js +3 -5
  151. package/lib/extensions/__tests__/FontColor.test.js +12 -6
  152. package/lib/extensions/__tests__/FontFamily.test.js +33 -8
  153. package/lib/extensions/__tests__/FontSize.test.js +15 -8
  154. package/lib/extensions/__tests__/FontStyle.test.js +12 -6
  155. package/lib/extensions/__tests__/FontWeight.test.js +20 -6
  156. package/lib/extensions/__tests__/LineHeight.test.js +24 -12
  157. package/lib/extensions/__tests__/Link.test.js +102 -0
  158. package/lib/extensions/__tests__/StylePreset.test.js +71 -8
  159. package/lib/extensions/__tests__/TextDecoration.test.js +52 -6
  160. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +26 -2
  161. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +30 -1
  162. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +18 -1
  163. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +88 -1
  164. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +33 -2
  165. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +25 -4
  166. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +47 -1
  167. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +26 -2
  168. package/lib/extensions/__tests__/__snapshots__/Link.test.js.snap +225 -0
  169. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +6 -2
  170. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +183 -3
  171. package/lib/extensions/core/CopyPasteProcessor.js +10 -0
  172. package/lib/extensions/core/NodeProcessor.js +1 -1
  173. package/lib/extensions/core/TextProcessor.js +10 -0
  174. package/lib/extensions/core/__tests__/NodeProcessor.test.js +3 -5
  175. package/lib/extensions/core/__tests__/SelectionProcessor.test.js +3 -5
  176. package/lib/extensions/core/__tests__/TextProcessor.test.js +138 -12
  177. package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +26 -0
  178. package/lib/extensions/core/index.js +11 -2
  179. package/lib/extensions/core/plugins/PastePlugin.js +57 -0
  180. package/lib/extensions/core/plugins/ProseMirrorPlugin.js +20 -0
  181. package/lib/extensions/core/plugins/index.js +1 -0
  182. package/lib/extensions/index.js +46 -34
  183. package/lib/extensions/list/List.js +2 -3
  184. package/lib/extensions/list/__tests__/List.test.js +5 -8
  185. package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +60 -20
  186. package/lib/injectionTokens.js +2 -1
  187. package/lib/services/ContentNormalizer.js +122 -29
  188. package/lib/services/ContextWidnow.js +23 -0
  189. package/lib/services/__tests__/ContentNormalizer.test.js +96 -7
  190. package/lib/services/__tests__/FavoriteColors.test.js +1 -1
  191. package/lib/services/index.js +1 -0
  192. package/lib/styles/content.css +102 -13
  193. package/lib/styles/helpers/offsets.css +16 -0
  194. package/lib/styles/variables.css +6 -0
  195. package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +4 -4
  196. package/lib/utils/__tests__/convertAlignment.test.js +16 -0
  197. package/lib/utils/__tests__/convertFontSize.test.js +21 -0
  198. package/lib/utils/__tests__/convertLineHeight.test.js +21 -0
  199. package/lib/utils/convertAlignment.js +12 -0
  200. package/lib/utils/convertColor.js +1 -1
  201. package/lib/utils/convertFontSize.js +8 -0
  202. package/lib/utils/convertLineHeight.js +17 -0
  203. package/lib/utils/importIcon.js +7 -6
  204. package/lib/utils/index.js +3 -0
  205. package/lib/utils/renderInlineSetting.js +1 -1
  206. package/package.json +26 -31
  207. package/config/webpack/example.config.js +0 -88
  208. package/config/webpack/lib.config.js +0 -40
  209. package/config/webpack/loaders/index.js +0 -6
  210. package/config/webpack/loaders/js-loader.js +0 -5
  211. package/config/webpack/loaders/style-loader.js +0 -9
  212. package/config/webpack/loaders/svg-loader.js +0 -4
  213. package/config/webpack/loaders/vue-loader.js +0 -4
  214. package/dist/wysiwyg.js +0 -2
  215. package/dist/wysiwyg.js.LICENSE.txt +0 -1
  216. package/lib/composables/__tests__/useToolbar.test.js +0 -56
@@ -3,5 +3,6 @@ export const InjectionTokens = Object.freeze({
3
3
  FONT_SIZES: Symbol('fontSizes'),
4
4
  EDITOR: Symbol('editor'),
5
5
  LOCAL_STORAGE: Symbol('localStorage'),
6
- FAVORITE_COLORS: Symbol('favoriteColors')
6
+ FAVORITE_COLORS: Symbol('favoriteColors'),
7
+ PAGE_BLOCKS: Symbol('pageBlocks')
7
8
  });
@@ -1,42 +1,112 @@
1
+ import { ContextWindow } from './ContextWidnow';
2
+
1
3
  export class ContentNormalizer {
2
- static NORMALIZING_STYLE_BLACKLIST = ['text-align', 'line-height'];
4
+ static PARSER = new DOMParser();
5
+ static BLOCK_STYLES = ['text-align', 'line-height'];
6
+ static BLOCK_NODE_NAMES = ['P', 'H1', 'H2', 'H3', 'H4'];
7
+
8
+ static ASSIGN_STYLE_RULES = [
9
+ {
10
+ tag: /^(b|strong)$/,
11
+ ignore: /font-weight/
12
+ },
13
+ {
14
+ tag: /^i$/,
15
+ ignore: /font-style/
16
+ },
17
+ {
18
+ tag: /^s$/,
19
+ ignore: /text-decoration(.+)?/
20
+ }
21
+ ];
22
+
23
+ static normalize(content) {
24
+ const options = {
25
+ content,
26
+ parser: ContentNormalizer.PARSER
27
+ };
28
+
29
+ return new ContentNormalizer(options).normalize();
30
+ }
3
31
 
4
- normalize(content) {
5
- if (typeof content !== 'string') return content;
32
+ constructor({ content, parser }) {
33
+ this._content = content;
34
+ this._parser = parser;
35
+ this._dom = null;
36
+ }
6
37
 
7
- return this._normalizeTextContent(content);
38
+ normalize() {
39
+ if (typeof this._content !== 'string') {
40
+ return this._content;
41
+ }
42
+ return this._normalizeTextContent();
8
43
  }
9
44
 
10
- _normalizeTextContent(content) {
11
- const parser = new DOMParser();
12
- const dom = parser.parseFromString(content, 'text/html');
45
+ _normalizeTextContent() {
46
+ this._dom = this._parser.parseFromString(this._content, 'text/html');
13
47
 
14
- this._iterateNodes(dom, this._normalizeStructure.bind(this), (node) => node.tagName === 'SPAN');
15
- this._iterateNodes(dom, this._normalizeStyles.bind(this), (node) => node.tagName !== 'SPAN');
48
+ this._iterateNodes(this._removeEmptyNodes, this._isBlockNode);
49
+ this._iterateNodes(this._normalizeListItems, (node) => node.tagName === 'LI');
50
+ this._iterateNodes(this._normalizeSettingsStructure, (node) => node.tagName === 'SPAN');
51
+ this._iterateNodes(this._normalizeStyles, (node) => node.tagName !== 'SPAN');
16
52
 
17
- return dom.body.innerHTML;
53
+ return this._dom.body.innerHTML;
18
54
  }
19
55
 
20
- _iterateNodes(dom, handler, condition) {
21
- const iterator = dom.createNodeIterator(dom.body, NodeFilter.SHOW_ELEMENT, {
22
- acceptNode: (node) => condition(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT
56
+ _iterateNodes(handler, condition = () => true) {
57
+ const iterator = this._dom.createNodeIterator(this._dom.body, NodeFilter.SHOW_ELEMENT, {
58
+ acceptNode: (node) => condition.call(this, node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT
23
59
  });
24
60
  let currentNode = iterator.nextNode();
25
61
 
26
62
  while (currentNode) {
27
- handler(currentNode);
63
+ handler.call(this, currentNode);
28
64
  currentNode = iterator.nextNode();
29
65
  }
30
66
  }
31
67
 
32
- _normalizeStructure(element) {
33
- const isTextChildren = Array.from(element.childNodes)
34
- .every((node) => node.nodeType === Node.TEXT_NODE);
68
+ _removeEmptyNodes(node) {
69
+ if (!node.innerHTML.replace(/\n/g, '').trim()) {
70
+ node.remove();
71
+ }
72
+ }
73
+
74
+ _normalizeListItems(itemEl) {
75
+ const fragment = new DocumentFragment();
76
+ const children = Array.from(itemEl.childNodes);
77
+ let capturingParagraph;
35
78
 
36
- if (isTextChildren) return;
79
+ const append = (node) => {
80
+ this._assignElementProperties(node, itemEl, ContentNormalizer.BLOCK_STYLES);
81
+ fragment.append(node);
82
+ };
83
+
84
+ this._assignElementProperties(itemEl, itemEl.parentElement, ContentNormalizer.BLOCK_STYLES);
85
+
86
+ for (const node of children) {
87
+ if (node.tagName === 'P') {
88
+ append(node);
89
+ capturingParagraph = null;
90
+ continue;
91
+ }
92
+
93
+ if (!capturingParagraph) {
94
+ capturingParagraph = document.createElement('p');
95
+ append(capturingParagraph);
96
+ }
97
+
98
+ capturingParagraph.append(node);
99
+ }
100
+
101
+ itemEl.append(fragment);
102
+ this._removeStyleProperties(itemEl, ContentNormalizer.BLOCK_STYLES);
103
+ }
104
+
105
+ _normalizeSettingsStructure(element) {
106
+ if (this._isOnlyTextContent(element)) return;
37
107
 
38
108
  const cloned = element.cloneNode(true);
39
- const migratingStyles = this._getMigratingStyles(element);
109
+ const migratingStyles = this._getMigratingStyles(element, { customProperties: true });
40
110
  const content = [];
41
111
 
42
112
  for (const node of cloned.childNodes) {
@@ -54,8 +124,12 @@ export class ContentNormalizer {
54
124
  }
55
125
 
56
126
  _normalizeStyles(element) {
127
+ if (!this._isBlockNode(element) && this._isOnlyTextContent(element)) return;
128
+
57
129
  const properties = this._getMigratingStyles(element);
58
130
 
131
+ if (!properties.length) return;
132
+
59
133
  for (const node of element.childNodes) {
60
134
  const child = this._wrapTextNode(element, node);
61
135
 
@@ -65,16 +139,25 @@ export class ContentNormalizer {
65
139
  this._removeStyleProperties(element, properties);
66
140
  }
67
141
 
68
- _getMigratingStyles(element) {
69
- const blacklist = ContentNormalizer.NORMALIZING_STYLE_BLACKLIST;
142
+ _isOnlyTextContent(node) {
143
+ return Array.from(node.childNodes).every((node) => node.nodeType === Node.TEXT_NODE);
144
+ }
145
+
146
+ _isBlockNode(node) {
147
+ return ContentNormalizer.BLOCK_NODE_NAMES.includes(node.tagName);
148
+ }
149
+
150
+ _getMigratingStyles(element, { customProperties } = {}) {
151
+ const blacklist = ContentNormalizer.BLOCK_STYLES;
70
152
  const properties = [];
71
153
 
72
154
  for (let index = 0; index < element.style.length; index++) {
73
155
  const property = element.style.item(index);
74
156
 
75
- if (!blacklist.includes(property)) {
76
- properties.push(property);
77
- }
157
+ if (blacklist.includes(property)) continue;
158
+ if (!customProperties && property.startsWith('--')) continue;
159
+
160
+ properties.push(property);
78
161
  }
79
162
 
80
163
  return properties;
@@ -83,7 +166,7 @@ export class ContentNormalizer {
83
166
  _wrapTextNode(parent, node) {
84
167
  if (node.nodeType !== Node.TEXT_NODE) return node;
85
168
 
86
- const span = document.createElement('span');
169
+ const span = ContextWindow.document.createElement('span');
87
170
 
88
171
  span.append(node.cloneNode());
89
172
  parent.replaceChild(span, node);
@@ -93,14 +176,24 @@ export class ContentNormalizer {
93
176
 
94
177
  _assignElementProperties(target, source, properties) {
95
178
  for (const property of properties) {
96
- if (target.style.getPropertyValue(property)) {
97
- continue;
98
- }
179
+ const value = source.style.getPropertyValue(property);
99
180
 
100
- target.style.setProperty(property, source.style.getPropertyValue(property));
181
+ if (value && this._canAssignElementProperty(target, source, property)) {
182
+ target.style.setProperty(property, value);
183
+ }
101
184
  }
102
185
  }
103
186
 
187
+ _canAssignElementProperty(target, source, property) {
188
+ if (target.style.getPropertyValue(property)) return false;
189
+
190
+ return ContentNormalizer.ASSIGN_STYLE_RULES.every((rule) => {
191
+ if (!rule.tag.test(target.tagName.toLowerCase())) return true;
192
+
193
+ return !rule.ignore.test(property);
194
+ });
195
+ }
196
+
104
197
  _removeStyleProperties(element, properties) {
105
198
  for (const property of properties) {
106
199
  element.style.removeProperty(property);
@@ -0,0 +1,23 @@
1
+ export class ContextWindow {
2
+ static window = window;
3
+
4
+ static use(window) {
5
+ this.window = window;
6
+ }
7
+
8
+ static get document() {
9
+ return this.window.document;
10
+ }
11
+
12
+ static get body() {
13
+ return this.document.body;
14
+ }
15
+
16
+ static get head() {
17
+ return this.document.head;
18
+ }
19
+
20
+ static getComputedStyle(element) {
21
+ return this.window.getComputedStyle(element);
22
+ }
23
+ }
@@ -1,13 +1,11 @@
1
1
  import { ContentNormalizer } from '../ContentNormalizer';
2
2
  import { NodeFactory } from '../../__tests__/utils';
3
3
 
4
- const normalize = (content) => new ContentNormalizer().normalize(content);
5
-
6
- describe('normalize text settings', () => {
4
+ describe('normalize text content', () => {
7
5
  test('should ignore json content', () => {
8
6
  const content = NodeFactory.doc([NodeFactory.paragraph('Test')]);
9
7
 
10
- expect(normalize(content)).toBe(content);
8
+ expect(ContentNormalizer.normalize(content)).toBe(content);
11
9
  });
12
10
 
13
11
  test('should flat structure', () => {
@@ -18,14 +16,14 @@ describe('normalize text settings', () => {
18
16
  '<span style="background-color: rgb(255, 0, 0); color: rgb(255, 255, 255);">sum</span>' +
19
17
  '</p>';
20
18
 
21
- expect(normalize(input)).toBe(output);
19
+ expect(ContentNormalizer.normalize(input)).toBe(output);
22
20
  });
23
21
 
24
22
  test('should move styles from paragraph to text', () => {
25
23
  const input = '<p style="background-color: red;">lorem ipsum</p>';
26
24
  const output = '<p><span style="background-color: red;">lorem ipsum</span></p>';
27
25
 
28
- expect(normalize(input)).toBe(output);
26
+ expect(ContentNormalizer.normalize(input)).toBe(output);
29
27
  });
30
28
 
31
29
  test('should move styles from paragraph to unstyled text', () => {
@@ -36,6 +34,97 @@ describe('normalize text settings', () => {
36
34
  '<span style="color: white; background-color: red;">one</span' +
37
35
  '></p>';
38
36
 
39
- expect(normalize(input)).toBe(output);
37
+ expect(ContentNormalizer.normalize(input)).toBe(output);
38
+ });
39
+
40
+ test('should wrap list content in paragraph', () => {
41
+ const input = '<ul><li style="line-height: 2;">lorem impsum</li></ul>';
42
+ const output = '<ul><li><p style="line-height: 2;">lorem impsum</p></li></ul>';
43
+
44
+ expect(ContentNormalizer.normalize(input)).toBe(output);
45
+ });
46
+
47
+ test('should keep order in list nodes', () => {
48
+ const input = '<ul><li style="line-height: 2;"><span style="font-weight: 700">lorem</span> impsum</li></ul>';
49
+ const output = '<ul>' +
50
+ '<li>' +
51
+ '<p style="line-height: 2;"><span style="font-weight: 700">lorem</span> impsum</p>' +
52
+ '</li>' +
53
+ '</ul>';
54
+
55
+ expect(ContentNormalizer.normalize(input)).toBe(output);
56
+ });
57
+
58
+ test('should wrap non paragraph list content', () => {
59
+ const input = '<ul>' +
60
+ '<li style="line-height: 2;">' +
61
+ '<span style="font-weight: 700">lorem</span> impsum' +
62
+ '<p>paragraph text</p>' +
63
+ '</li>' +
64
+ '</ul>';
65
+ const output = '<ul>' +
66
+ '<li>' +
67
+ '<p style="line-height: 2;"><span style="font-weight: 700">lorem</span> impsum</p>' +
68
+ '<p style="line-height: 2;">paragraph text</p>' +
69
+ '</li>' +
70
+ '</ul>';
71
+
72
+ expect(ContentNormalizer.normalize(input)).toBe(output);
73
+ });
74
+
75
+ test('should ignore empty nodes', () => {
76
+ const input = '<p>lorem ipsum 1</p><p></p><p>lorem ipsum 2</p>';
77
+ const output = '<p>lorem ipsum 1</p><p>lorem ipsum 2</p>';
78
+
79
+ expect(ContentNormalizer.normalize(input)).toBe(output);
80
+ });
81
+
82
+ test('should ignore space only nodes', () => {
83
+ const input = '<p>lorem ipsum 1</p><p> </p><p>lorem ipsum 2</p>';
84
+ const output = '<p>lorem ipsum 1</p><p>lorem ipsum 2</p>';
85
+
86
+ expect(ContentNormalizer.normalize(input)).toBe(output);
87
+ });
88
+
89
+ test('should ignore newline chapters only nodes', () => {
90
+ const input = '<p>lorem ipsum 1</p><p>\n</p><p>lorem ipsum 2</p>';
91
+ const output = '<p>lorem ipsum 1</p><p>lorem ipsum 2</p>';
92
+
93
+ expect(ContentNormalizer.normalize(input)).toBe(output);
94
+ });
95
+
96
+ test('should not ignore setting', () => {
97
+ const input = '<p style="text-decoration-line: underline;">lorem ipsum</p>';
98
+ const output = '<p><span style="text-decoration-line: underline;">lorem ipsum</span></p>';
99
+
100
+ expect(ContentNormalizer.normalize(input)).toBe(output);
101
+ });
102
+
103
+ test('should not assign font-weight to b tag', () => {
104
+ const input = '<p style="font-weight: 400;"><b>lorem ipsum</b></p>';
105
+ const output = '<p><b>lorem ipsum</b></p>';
106
+
107
+ expect(ContentNormalizer.normalize(input)).toBe(output);
108
+ });
109
+
110
+ test('should not assign font-style to i tag', () => {
111
+ const input = '<p style="font-style: normal;"><i>lorem ipsum</i></p>';
112
+ const output = '<p><i>lorem ipsum</i></p>';
113
+
114
+ expect(ContentNormalizer.normalize(input)).toBe(output);
115
+ });
116
+
117
+ test('should not assign text-decoration to s tag', () => {
118
+ const input = '<p style="text-decoration-line: initial;"><s>lorem ipsum</s></p>';
119
+ const output = '<p><s>lorem ipsum</s></p>';
120
+
121
+ expect(ContentNormalizer.normalize(input)).toBe(output);
122
+ });
123
+
124
+ test('should assign block styles from list to paragraph', () => {
125
+ const input = '<ul style="line-height: 2;"><li>lorem ipsum</li></ul>';
126
+ const output = '<ul style="line-height: 2;"><li><p style="line-height: 2;">lorem ipsum</p></li></ul>';
127
+
128
+ expect(ContentNormalizer.normalize(input)).toBe(output);
40
129
  });
41
130
  });
@@ -1,4 +1,4 @@
1
- import { ref } from '@vue/composition-api';
1
+ import { ref } from 'vue';
2
2
  import { FavoriteColors } from '../FavoriteColors';
3
3
 
4
4
  function createService({ colors, onUpdate }) {
@@ -2,3 +2,4 @@ export { JsonSerializer } from './JsonSerializer';
2
2
  export { Storage } from './Storage';
3
3
  export { FavoriteColors } from './FavoriteColors';
4
4
  export { ContentNormalizer } from './ContentNormalizer';
5
+ export { ContextWindow } from './ContextWidnow';
@@ -2,7 +2,15 @@
2
2
  outline: none;
3
3
  }
4
4
 
5
- .zw-style {
5
+ .zw-wysiwyg__placeholder:first-child:last-child::before {
6
+ content: attr(data-placeholder);
7
+ color: rgb(var(--zw-color-n70));
8
+ float: left;
9
+ height: 0;
10
+ pointer-events: none;
11
+ }
12
+
13
+ .zw-style.zw-style.zw-style {
6
14
  font-weight: var(--zw-font-weight, var(--zw-preset-font-weight));
7
15
  font-family: var(--zw-font-family, var(--zw-preset-font-family));
8
16
  color: var(--zw-font-color, var(--zw-preset-color));
@@ -13,27 +21,108 @@
13
21
 
14
22
  @media (min-width: 1200px) {
15
23
 
16
- .zw-style {
17
- font-size: var(--zw-desktop-font-size, var(--zw-preset-desktop-font-size));
18
- text-align: var(--zw-desktop-text-align, var(--zw-preset-desktop-text-align));
19
- line-height: var(--zw-desktop-line-height, var(--zw-preset-desktop-line-height));
24
+ .zw-style.zw-style.zw-style {
25
+ font-size: var(--zw-font-size-desktop, var(--zw-preset-desktop-font-size));
26
+ text-align: var(--zw-text-align-desktop, var(--zw-preset-desktop-text-align));
27
+ line-height: var(--zw-line-height-desktop, var(--zw-preset-desktop-line-height));
20
28
  }
21
29
  }
22
30
 
23
31
  @media (min-width: 769px) and (max-width: 1199.98px) {
24
32
 
25
- .zw-style {
26
- font-size: var(--zw-tablet-font-size, var(--zw-preset-tablet-font-size));
27
- text-align: var(--zw-tablet-text-align, var(--zw-preset-tablet-text-align));
28
- line-height: var(--zw-tablet-line-height, var(--zw-preset-tablet-line-height));
33
+ .zw-style.zw-style.zw-style {
34
+ font-size: var(--zw-font-size-tablet, var(--zw-preset-tablet-font-size));
35
+ text-align: var(--zw-text-align-tablet, var(--zw-preset-tablet-text-align));
36
+ line-height: var(--zw-line-height-tablet, var(--zw-preset-tablet-line-height));
29
37
  }
30
38
  }
31
39
 
32
40
  @media (max-width: 768.98px) {
33
41
 
34
- .zw-style {
35
- font-size: var(--zw-mobile-font-size, var(--zw-preset-mobile-font-size));
36
- text-align: var(--zw-mobile-text-align, var(--zw-preset-mobile-text-align));
37
- line-height: var(--zw-mobile-line-height, var(--zw-preset-mobile-line-height));
42
+ .zw-style.zw-style.zw-style {
43
+ font-size: var(--zw-font-size-mobile, var(--zw-preset-mobile-font-size));
44
+ text-align: var(--zw-text-align-mobile, var(--zw-preset-mobile-text-align));
45
+ line-height: var(--zw-line-height-mobile, var(--zw-preset-mobile-line-height));
38
46
  }
39
47
  }
48
+
49
+
50
+ /* ProseMirror styles */
51
+
52
+
53
+ .ProseMirror {
54
+ position: relative;
55
+ }
56
+
57
+ .ProseMirror {
58
+ word-wrap: break-word;
59
+ white-space: pre-wrap;
60
+ white-space: break-spaces;
61
+ -webkit-font-variant-ligatures: none;
62
+ font-variant-ligatures: none;
63
+ font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */
64
+ }
65
+
66
+ .ProseMirror [contenteditable="false"] {
67
+ white-space: normal;
68
+ }
69
+
70
+ .ProseMirror [contenteditable="false"] [contenteditable="true"] {
71
+ white-space: pre-wrap;
72
+ }
73
+
74
+ .ProseMirror pre {
75
+ white-space: pre-wrap;
76
+ }
77
+
78
+ img.ProseMirror-separator {
79
+ display: inline !important;
80
+ border: none !important;
81
+ margin: 0 !important;
82
+ width: 1px !important;
83
+ height: 1px !important;
84
+ }
85
+
86
+ .ProseMirror-gapcursor {
87
+ display: none;
88
+ pointer-events: none;
89
+ position: absolute;
90
+ margin: 0;
91
+ }
92
+
93
+ .ProseMirror-gapcursor::after {
94
+ content: "";
95
+ display: block;
96
+ position: absolute;
97
+ top: -2px;
98
+ width: 20px;
99
+ border-top: 1px solid #000;
100
+ animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
101
+ }
102
+
103
+ @keyframes ProseMirror-cursor-blink {
104
+
105
+ to {
106
+ visibility: hidden;
107
+ }
108
+ }
109
+
110
+ .ProseMirror-hideselection *::selection {
111
+ background: transparent;
112
+ }
113
+
114
+ .ProseMirror-hideselection *::-moz-selection {
115
+ background: transparent;
116
+ }
117
+
118
+ .ProseMirror-hideselection * {
119
+ caret-color: transparent;
120
+ }
121
+
122
+ .ProseMirror-focused .ProseMirror-gapcursor {
123
+ display: block;
124
+ }
125
+
126
+ .tippy-box[data-animation=fade][data-state=hidden] {
127
+ opacity: 0
128
+ }
@@ -1,3 +1,19 @@
1
+ .zw-margin-bottom--xxs {
2
+ margin-bottom: var(--zw-offset-xxs);
3
+ }
4
+
1
5
  .zw-margin-bottom--xs {
2
6
  margin-bottom: var(--zw-offset-xs);
3
7
  }
8
+
9
+ .zw-margin-bottom--sm {
10
+ margin-bottom: var(--zw-offset-sm);
11
+ }
12
+
13
+ .zw-margin-bottom--md {
14
+ margin-bottom: var(--zw-offset-md);
15
+ }
16
+
17
+ .zw-margin-right--xs {
18
+ margin-right: var(--zw-offset-xs);
19
+ }
@@ -8,13 +8,17 @@
8
8
  --zw-color-n80: 196, 196, 196; /* #C4C4C4 */
9
9
  --zw-color-n85: 217, 217, 217; /* #D9D9D9 */
10
10
  --zw-color-n90: 230, 230, 230; /* #E6E6E6 */
11
+ --zw-color-n200: 194, 200, 209; /* #C2C8D1 */
11
12
  --zw-color-black: 0, 0, 0;
12
13
  --zw-color-white: 255, 255, 255;
14
+ --zw-color-green: 59, 180, 74; /* #3BB44A */
15
+ --zw-color-red: 234, 58, 58; /* #EA3A3A */
13
16
 
14
17
  --zw-offset-xxs: 4px;
15
18
  --zw-offset-xs: 8px;
16
19
  --zw-offset-xsm: 12px;
17
20
  --zw-offset-sm: 16px;
21
+ --zw-offset-md: 24px;
18
22
 
19
23
  --zw-font-weight-thin: 400;
20
24
  --zw-font-weight-semibold: 500;
@@ -42,6 +46,8 @@ $builder-N90: #E6E6E6;
42
46
  $builder-N94: #F0F0F0;
43
47
  $builder-N96: #F5F5F5;
44
48
  $builder-N98: #FAFAFA;
49
+ $builder-N200: #C2C8D1;
50
+ $builder-R50: #EA3A3A;
45
51
 
46
52
  $font-size-xxs: 12px;
47
53
  $font-size-xs: 14px;
@@ -5,7 +5,7 @@ Array [
5
5
  "span",
6
6
  Object {
7
7
  "class": "zw-style",
8
- "style": "--zw-mobile-font-size: 12px; --zw-tablet-font-size: 14px; --zw-desktop-font-size: 16px;",
8
+ "style": "--zw-mobile-font-size:12px;--zw-tablet-font-size:14px;--zw-desktop-font-size:16px;",
9
9
  },
10
10
  0,
11
11
  ]
@@ -16,7 +16,7 @@ Array [
16
16
  "span",
17
17
  Object {
18
18
  "class": "zw-style",
19
- "style": "--zw-desktop-font-size: 16px;",
19
+ "style": "--zw-desktop-font-size:16px;",
20
20
  },
21
21
  0,
22
22
  ]
@@ -27,7 +27,7 @@ Array [
27
27
  "span",
28
28
  Object {
29
29
  "class": "zw-style",
30
- "style": "--zw-font-size: 12px;",
30
+ "style": "--zw-font-size:12px;",
31
31
  },
32
32
  0,
33
33
  ]
@@ -35,6 +35,6 @@ Array [
35
35
 
36
36
  exports[`render settings should render unwrapped styles 1`] = `
37
37
  Object {
38
- "style": "--zw-desktop-font-size: 16px;",
38
+ "style": "--zw-desktop-font-size:16px;",
39
39
  }
40
40
  `;
@@ -0,0 +1,16 @@
1
+ import { convertAlignment } from '../convertAlignment';
2
+ import { Alignments } from '../../enums';
3
+
4
+ describe('convert alignment', () => {
5
+ test('should try convert non supported value', () => {
6
+ expect(convertAlignment('start')).toBe(Alignments.LEFT);
7
+ });
8
+
9
+ test('should not change supported value', () => {
10
+ expect(convertAlignment('center')).toBe(Alignments.CENTER);
11
+ });
12
+
13
+ test('should return null if cannot convert', () => {
14
+ expect(convertAlignment('test-test')).toBe(null);
15
+ });
16
+ });
@@ -0,0 +1,21 @@
1
+ import { convertFontSize } from '../convertFontSize';
2
+
3
+ describe('convert font size', () => {
4
+ const createWrapper = ({ fontSize }) => {
5
+ const wrapperEl = document.createElement('div');
6
+
7
+ wrapperEl.style.fontSize = `${fontSize}px`;
8
+
9
+ return wrapperEl;
10
+ };
11
+
12
+ test('should format px values', () => {
13
+ expect(convertFontSize('20px')).toBe(20);
14
+ });
15
+
16
+ test('should parse em value', () => {
17
+ const wrapperEl = createWrapper({ fontSize: 24 });
18
+
19
+ expect(convertFontSize('1.5em', wrapperEl)).toBe(36);
20
+ });
21
+ });
@@ -0,0 +1,21 @@
1
+ import { convertLineHeight } from '../convertLineHeight';
2
+
3
+ describe('convert line height', () => {
4
+ const createWrapper = ({ fontSize }) => {
5
+ const wrapperEl = document.createElement('div');
6
+
7
+ wrapperEl.style.fontSize = `${fontSize}px`;
8
+
9
+ return wrapperEl;
10
+ };
11
+
12
+ test('should allow relative values', () => {
13
+ expect(convertLineHeight('1.2')).toBe('1.2');
14
+ });
15
+
16
+ test('should convert px to relative', () => {
17
+ const wrapperEl = createWrapper({ fontSize: 20 });
18
+
19
+ expect(convertLineHeight('24px', wrapperEl)).toBe('1.20');
20
+ });
21
+ });