@zipify/wysiwyg 1.0.0-dev.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 (255) hide show
  1. package/.editorconfig +18 -0
  2. package/.eslintrc.js +253 -0
  3. package/.github/actions/deploy-example/action.yaml +61 -0
  4. package/.github/actions/lint-css/action.yaml +15 -0
  5. package/.github/actions/lint-js/action.yaml +22 -0
  6. package/.github/actions/setup/action.yaml +19 -0
  7. package/.github/actions/unit-tests/action.yaml +13 -0
  8. package/.github/actions/unit-tests/jest.config.js +8 -0
  9. package/.github/dependabot.yaml +17 -0
  10. package/.github/pull_request_template.md +17 -0
  11. package/.github/workflows/frontend-ci.yaml +120 -0
  12. package/.husky/pre-commit +4 -0
  13. package/.lintstagedrc +12 -0
  14. package/.release-it.json +6 -0
  15. package/.stylelintrc +110 -0
  16. package/README.md +61 -0
  17. package/babel.config.js +15 -0
  18. package/ci/example/deploy.sh +25 -0
  19. package/config/jest/TestEnvironment.js +27 -0
  20. package/config/jest/matchers/index.js +6 -0
  21. package/config/jest/matchers/toElementHasStyle.js +27 -0
  22. package/config/jest/matchers/toVueContainComponent.js +20 -0
  23. package/config/jest/matchers/toVueContainElement.js +34 -0
  24. package/config/jest/matchers/toVueContainLazyComponent.js +19 -0
  25. package/config/jest/matchers/toVueEmpty.js +16 -0
  26. package/config/jest/matchers/toVuexActionHasBeenDispatched.js +19 -0
  27. package/config/jest/setupMatchers.js +4 -0
  28. package/config/jest/setupTests.js +32 -0
  29. package/config/jest/typing.d.ts +14 -0
  30. package/config/svgo.js +22 -0
  31. package/config/webpack/example.config.js +86 -0
  32. package/config/webpack/loaders/index.js +6 -0
  33. package/config/webpack/loaders/js-loader.js +5 -0
  34. package/config/webpack/loaders/style-loader.js +7 -0
  35. package/config/webpack/loaders/svg-loader.js +4 -0
  36. package/config/webpack/loaders/vue-loader.js +4 -0
  37. package/config/webpack/settings.js +9 -0
  38. package/example/ExampleApp.vue +136 -0
  39. package/example/example.html +17 -0
  40. package/example/example.js +19 -0
  41. package/example/fonts.js +474 -0
  42. package/example/presets.js +245 -0
  43. package/example/tooltip/Tooltip.js +241 -0
  44. package/example/tooltip/TooltipManager.js +132 -0
  45. package/example/tooltip/index.js +3 -0
  46. package/example/tooltip/modifiers/TooltipCloseOnScrollModifier.js +73 -0
  47. package/example/tooltip/modifiers/index.js +1 -0
  48. package/example/tooltip/tooltip.css +95 -0
  49. package/jest.config.js +17 -0
  50. package/lib/Wysiwyg.vue +156 -0
  51. package/lib/__mocks__/svgMock.js +1 -0
  52. package/lib/__tests__/utils/NodeFactory.js +67 -0
  53. package/lib/__tests__/utils/index.js +4 -0
  54. package/lib/__tests__/utils/setReadonlyProperty.js +9 -0
  55. package/lib/__tests__/utils/waitAsyncOperation.js +6 -0
  56. package/lib/__tests__/utils/withComponentContext.js +14 -0
  57. package/lib/assets/icons.svg +69 -0
  58. package/lib/components/base/Button.vue +117 -0
  59. package/lib/components/base/ButtonToggle.vue +40 -0
  60. package/lib/components/base/FieldLabel.vue +28 -0
  61. package/lib/components/base/Icon.vue +67 -0
  62. package/lib/components/base/Modal.vue +116 -0
  63. package/lib/components/base/NumberField.vue +242 -0
  64. package/lib/components/base/Range.vue +196 -0
  65. package/lib/components/base/ScrollView.vue +60 -0
  66. package/lib/components/base/__tests__/Button.test.js +50 -0
  67. package/lib/components/base/__tests__/Icon.test.js +56 -0
  68. package/lib/components/base/__tests__/Modal.test.js +69 -0
  69. package/lib/components/base/__tests__/Range.test.js +39 -0
  70. package/lib/components/base/colorPicker/ColorPicker.vue +93 -0
  71. package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +81 -0
  72. package/lib/components/base/colorPicker/composables/index.js +2 -0
  73. package/lib/components/base/colorPicker/composables/usePickerApi.js +35 -0
  74. package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +25 -0
  75. package/lib/components/base/colorPicker/index.js +1 -0
  76. package/lib/components/base/composables/__tests__/useActivatedListener.test.js +89 -0
  77. package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +80 -0
  78. package/lib/components/base/composables/__tests__/useElementRef.test.js +29 -0
  79. package/lib/components/base/composables/__tests__/useModalToggler.test.js +55 -0
  80. package/lib/components/base/composables/__tests__/useNumberValue.test.js +153 -0
  81. package/lib/components/base/composables/__tests__/useScrollView.test.js +43 -0
  82. package/lib/components/base/composables/__tests__/useTempValue.test.js +38 -0
  83. package/lib/components/base/composables/index.js +7 -0
  84. package/lib/components/base/composables/useActivatedListener.js +23 -0
  85. package/lib/components/base/composables/useDeselectionLock.js +35 -0
  86. package/lib/components/base/composables/useElementRef.js +5 -0
  87. package/lib/components/base/composables/useModalToggler.js +58 -0
  88. package/lib/components/base/composables/useNumberValue.js +53 -0
  89. package/lib/components/base/composables/useScrollView.js +22 -0
  90. package/lib/components/base/composables/useTempValue.js +11 -0
  91. package/lib/components/base/dropdown/Dropdown.vue +88 -0
  92. package/lib/components/base/dropdown/DropdownActivator.vue +81 -0
  93. package/lib/components/base/dropdown/DropdownDivider.vue +21 -0
  94. package/lib/components/base/dropdown/DropdownGroup.vue +55 -0
  95. package/lib/components/base/dropdown/DropdownMenu.vue +62 -0
  96. package/lib/components/base/dropdown/DropdownOption.vue +91 -0
  97. package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +54 -0
  98. package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +67 -0
  99. package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +81 -0
  100. package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +41 -0
  101. package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +24 -0
  102. package/lib/components/base/dropdown/composables/index.js +2 -0
  103. package/lib/components/base/dropdown/composables/useActiveOptionManager.js +25 -0
  104. package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +5 -0
  105. package/lib/components/base/dropdown/index.js +2 -0
  106. package/lib/components/base/dropdown/injectionTokens.js +5 -0
  107. package/lib/components/base/index.js +11 -0
  108. package/lib/components/index.js +1 -0
  109. package/lib/components/toolbar/Toolbar.vue +56 -0
  110. package/lib/components/toolbar/ToolbarDevice.vue +35 -0
  111. package/lib/components/toolbar/ToolbarDivider.vue +50 -0
  112. package/lib/components/toolbar/ToolbarFull.vue +94 -0
  113. package/lib/components/toolbar/ToolbarGroup.vue +18 -0
  114. package/lib/components/toolbar/ToolbarRow.vue +19 -0
  115. package/lib/components/toolbar/__tests__/Toolbar.test.js +33 -0
  116. package/lib/components/toolbar/__tests__/ToolbarDivider.test.js +26 -0
  117. package/lib/components/toolbar/controls/AlignmentControl.vue +72 -0
  118. package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +67 -0
  119. package/lib/components/toolbar/controls/BackgroundColorControl.vue +48 -0
  120. package/lib/components/toolbar/controls/CaseStyleControl.vue +54 -0
  121. package/lib/components/toolbar/controls/FontColorControl.vue +48 -0
  122. package/lib/components/toolbar/controls/FontFamilyControl.vue +96 -0
  123. package/lib/components/toolbar/controls/FontSizeControl.vue +45 -0
  124. package/lib/components/toolbar/controls/FontWeightControl.vue +43 -0
  125. package/lib/components/toolbar/controls/ItalicControl.vue +47 -0
  126. package/lib/components/toolbar/controls/LineHeightControl.vue +102 -0
  127. package/lib/components/toolbar/controls/ListControl.vue +86 -0
  128. package/lib/components/toolbar/controls/RemoveFormatControl.vue +37 -0
  129. package/lib/components/toolbar/controls/StrikeThroughControl.vue +44 -0
  130. package/lib/components/toolbar/controls/StylePresetControl.vue +95 -0
  131. package/lib/components/toolbar/controls/SuperscriptControl.vue +44 -0
  132. package/lib/components/toolbar/controls/UnderlineControl.vue +44 -0
  133. package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +51 -0
  134. package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +77 -0
  135. package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +59 -0
  136. package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +43 -0
  137. package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +59 -0
  138. package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +57 -0
  139. package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +47 -0
  140. package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +45 -0
  141. package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +63 -0
  142. package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +120 -0
  143. package/lib/components/toolbar/controls/__tests__/ListControl.test.js +82 -0
  144. package/lib/components/toolbar/controls/__tests__/RemoveFormatControl.test.js +34 -0
  145. package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +44 -0
  146. package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +129 -0
  147. package/lib/components/toolbar/controls/__tests__/SuperscriptControl.test.js +44 -0
  148. package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +44 -0
  149. package/lib/components/toolbar/controls/composables/__tests__/useRecentFonts.test.js +69 -0
  150. package/lib/components/toolbar/controls/composables/index.js +1 -0
  151. package/lib/components/toolbar/controls/composables/useRecentFonts.js +18 -0
  152. package/lib/components/toolbar/controls/index.js +16 -0
  153. package/lib/components/toolbar/index.js +1 -0
  154. package/lib/composables/__tests__/__snapshots__/useEditor.test.js.snap +24 -0
  155. package/lib/composables/__tests__/useEditor.test.js +67 -0
  156. package/lib/composables/__tests__/useToolbar.test.js +56 -0
  157. package/lib/composables/index.js +2 -0
  158. package/lib/composables/useEditor.js +21 -0
  159. package/lib/composables/useToolbar.js +44 -0
  160. package/lib/directives/__tests__/outClick.test.js +86 -0
  161. package/lib/directives/__tests__/tooltip.test.js +39 -0
  162. package/lib/directives/index.js +2 -0
  163. package/lib/directives/outClick.js +37 -0
  164. package/lib/directives/tooltip.js +7 -0
  165. package/lib/enums/Alignments.js +6 -0
  166. package/lib/enums/CaseStyles.js +5 -0
  167. package/lib/enums/Devices.js +15 -0
  168. package/lib/enums/ListTypes.js +23 -0
  169. package/lib/enums/NodeTypes.js +12 -0
  170. package/lib/enums/TextSettings.js +30 -0
  171. package/lib/enums/index.js +6 -0
  172. package/lib/extensions/Alignment.js +67 -0
  173. package/lib/extensions/BackgroundColor.js +28 -0
  174. package/lib/extensions/CaseStyle.js +36 -0
  175. package/lib/extensions/DeviceManager.js +16 -0
  176. package/lib/extensions/FontColor.js +36 -0
  177. package/lib/extensions/FontFamily.js +62 -0
  178. package/lib/extensions/FontSize.js +74 -0
  179. package/lib/extensions/FontStyle.js +62 -0
  180. package/lib/extensions/FontWeight.js +56 -0
  181. package/lib/extensions/LineHeight.js +60 -0
  182. package/lib/extensions/StylePreset.js +168 -0
  183. package/lib/extensions/Superscript.js +5 -0
  184. package/lib/extensions/TextDecoration.js +97 -0
  185. package/lib/extensions/__tests__/Alignment.test.js +107 -0
  186. package/lib/extensions/__tests__/BackgroundColor.test.js +75 -0
  187. package/lib/extensions/__tests__/CaseStyle.test.js +58 -0
  188. package/lib/extensions/__tests__/FontColor.test.js +85 -0
  189. package/lib/extensions/__tests__/FontFamily.test.js +171 -0
  190. package/lib/extensions/__tests__/FontSize.test.js +183 -0
  191. package/lib/extensions/__tests__/FontStyle.test.js +136 -0
  192. package/lib/extensions/__tests__/FontWeight.test.js +151 -0
  193. package/lib/extensions/__tests__/LineHeight.test.js +106 -0
  194. package/lib/extensions/__tests__/StylePreset.test.js +400 -0
  195. package/lib/extensions/__tests__/TextDecoration.test.js +258 -0
  196. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +29 -0
  197. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +28 -0
  198. package/lib/extensions/__tests__/__snapshots__/CaseStyle.test.js.snap +69 -0
  199. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +28 -0
  200. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +158 -0
  201. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +140 -0
  202. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +87 -0
  203. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +140 -0
  204. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +29 -0
  205. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +310 -0
  206. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +206 -0
  207. package/lib/extensions/core/NodeProcessor.js +32 -0
  208. package/lib/extensions/core/SelectionProcessor.js +37 -0
  209. package/lib/extensions/core/TextProcessor.js +57 -0
  210. package/lib/extensions/core/__tests__/NodeProcessor.test.js +120 -0
  211. package/lib/extensions/core/__tests__/SelectionProcessor.test.js +78 -0
  212. package/lib/extensions/core/__tests__/TextProcessor.test.js +61 -0
  213. package/lib/extensions/core/__tests__/__snapshots__/NodeProcessor.test.js.snap +93 -0
  214. package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +43 -0
  215. package/lib/extensions/core/index.js +17 -0
  216. package/lib/extensions/core/inputRules/closeDoubleQuote.js +6 -0
  217. package/lib/extensions/core/inputRules/closeSingleQuote.js +6 -0
  218. package/lib/extensions/core/inputRules/copyright.js +6 -0
  219. package/lib/extensions/core/inputRules/ellipsis.js +6 -0
  220. package/lib/extensions/core/inputRules/emDash.js +6 -0
  221. package/lib/extensions/core/inputRules/index.js +9 -0
  222. package/lib/extensions/core/inputRules/openDoubleQuote.js +6 -0
  223. package/lib/extensions/core/inputRules/openSingleQuote.js +6 -0
  224. package/lib/extensions/core/inputRules/registeredTrademark.js +6 -0
  225. package/lib/extensions/core/inputRules/trademark.js +6 -0
  226. package/lib/extensions/index.js +49 -0
  227. package/lib/extensions/list/List.js +81 -0
  228. package/lib/extensions/list/ListItem.js +12 -0
  229. package/lib/extensions/list/__tests__/List.test.js +130 -0
  230. package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +212 -0
  231. package/lib/extensions/list/index.js +1 -0
  232. package/lib/index.js +1 -0
  233. package/lib/injectionTokens.js +7 -0
  234. package/lib/models/Font.js +37 -0
  235. package/lib/models/__tests__/Font.test.js +58 -0
  236. package/lib/models/index.js +1 -0
  237. package/lib/services/FavoriteColors.js +6 -0
  238. package/lib/services/JsonSerializer.js +15 -0
  239. package/lib/services/Storage.js +49 -0
  240. package/lib/services/index.js +3 -0
  241. package/lib/styles/content.css +39 -0
  242. package/lib/styles/helpers/common.css +3 -0
  243. package/lib/styles/helpers/offsets.css +3 -0
  244. package/lib/styles/helpers/text.css +6 -0
  245. package/lib/styles/main.css +5 -0
  246. package/lib/styles/variables.css +57 -0
  247. package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +40 -0
  248. package/lib/utils/__tests__/capitalize.test.js +11 -0
  249. package/lib/utils/__tests__/renderInlineSetting.test.js +39 -0
  250. package/lib/utils/capitalize.js +3 -0
  251. package/lib/utils/createCommand.js +3 -0
  252. package/lib/utils/createKeyboardShortcut.js +6 -0
  253. package/lib/utils/index.js +4 -0
  254. package/lib/utils/renderInlineSetting.js +17 -0
  255. package/package.json +75 -0
@@ -0,0 +1,43 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`transform text should keep text marks 1`] = `
4
+ Object {
5
+ "content": Array [
6
+ Object {
7
+ "content": Array [
8
+ Object {
9
+ "marks": Array [
10
+ Object {
11
+ "attrs": Object {
12
+ "value": "700",
13
+ },
14
+ "type": "font_weight",
15
+ },
16
+ ],
17
+ "text": "hELLO world",
18
+ "type": "text",
19
+ },
20
+ ],
21
+ "type": "paragraph",
22
+ },
23
+ ],
24
+ "type": "doc",
25
+ }
26
+ `;
27
+
28
+ exports[`transform text should transform selected text 1`] = `
29
+ Object {
30
+ "content": Array [
31
+ Object {
32
+ "content": Array [
33
+ Object {
34
+ "text": "hELLO world",
35
+ "type": "text",
36
+ },
37
+ ],
38
+ "type": "paragraph",
39
+ },
40
+ ],
41
+ "type": "doc",
42
+ }
43
+ `;
@@ -0,0 +1,17 @@
1
+ import Document from '@tiptap/extension-document';
2
+ import Paragraph from '@tiptap/extension-paragraph';
3
+ import Text from '@tiptap/extension-text';
4
+ import { NodeProcessor } from './NodeProcessor';
5
+ import { TextProcessor } from './TextProcessor';
6
+ import { SelectionProcessor } from './SelectionProcessor';
7
+
8
+ export const CORE_EXTENSIONS = [
9
+ Document,
10
+ Paragraph.configure({
11
+ HTMLAttributes: { class: 'zw-style' }
12
+ }),
13
+ Text,
14
+ NodeProcessor,
15
+ TextProcessor,
16
+ SelectionProcessor
17
+ ];
@@ -0,0 +1,6 @@
1
+ import { textInputRule } from '@tiptap/core';
2
+
3
+ export const closeDoubleQuote = textInputRule({
4
+ find: /"/,
5
+ replace: '”'
6
+ });
@@ -0,0 +1,6 @@
1
+ import { textInputRule } from '@tiptap/core';
2
+
3
+ export const closeSingleQuote = textInputRule({
4
+ find: /'/,
5
+ replace: '’'
6
+ });
@@ -0,0 +1,6 @@
1
+ import { textInputRule } from '@tiptap/core';
2
+
3
+ export const copyright = textInputRule({
4
+ find: /\(c\)/i,
5
+ replace: '©'
6
+ });
@@ -0,0 +1,6 @@
1
+ import { textInputRule } from '@tiptap/core';
2
+
3
+ export const ellipsis = textInputRule({
4
+ find: /\.\.\./,
5
+ replace: '…'
6
+ });
@@ -0,0 +1,6 @@
1
+ import { textInputRule } from '@tiptap/core';
2
+
3
+ export const emDash = textInputRule({
4
+ find: /--/,
5
+ replace: '—'
6
+ });
@@ -0,0 +1,9 @@
1
+ export { closeDoubleQuote } from './closeDoubleQuote';
2
+ export { closeSingleQuote } from './closeSingleQuote';
3
+ export { copyright } from './copyright';
4
+ export { ellipsis } from './ellipsis';
5
+ export { emDash } from './emDash';
6
+ export { openDoubleQuote } from './openDoubleQuote';
7
+ export { openSingleQuote } from './openSingleQuote';
8
+ export { registeredTrademark } from './registeredTrademark';
9
+ export { trademark } from './trademark';
@@ -0,0 +1,6 @@
1
+ import { textInputRule } from '@tiptap/core';
2
+
3
+ export const openDoubleQuote = textInputRule({
4
+ find: /(?:^|[\s{[(<'"\u2018\u201C])(")/,
5
+ replace: '“'
6
+ });
@@ -0,0 +1,6 @@
1
+ import { textInputRule } from '@tiptap/core';
2
+
3
+ export const openSingleQuote = textInputRule({
4
+ find: /(?:^|[\s{[(<'"\u2018\u201C])(')/,
5
+ replace: '‘'
6
+ });
@@ -0,0 +1,6 @@
1
+ import { textInputRule } from '@tiptap/core';
2
+
3
+ export const registeredTrademark = textInputRule({
4
+ find: /\(r\)/i,
5
+ replace: '®'
6
+ });
@@ -0,0 +1,6 @@
1
+ import { textInputRule } from '@tiptap/core';
2
+
3
+ export const trademark = textInputRule({
4
+ find: /\(tm\)/i,
5
+ replace: '™'
6
+ });
@@ -0,0 +1,49 @@
1
+ import History from '@tiptap/extension-history';
2
+ import { CORE_EXTENSIONS } from './core';
3
+ import { FontFamily } from './FontFamily';
4
+ import { StylePreset } from './StylePreset';
5
+ import { FontWeight } from './FontWeight';
6
+ import { FontSize } from './FontSize';
7
+ import { FontColor } from './FontColor';
8
+ import { BackgroundColor } from './BackgroundColor';
9
+ import { DeviceManager } from './DeviceManager';
10
+ import { FontStyle } from './FontStyle';
11
+ import { TextDecoration } from './TextDecoration';
12
+ import { CaseStyle } from './CaseStyle';
13
+ import { Alignment } from './Alignment';
14
+ import { LineHeight } from './LineHeight';
15
+ import { List } from './list';
16
+ import { Superscript } from './Superscript';
17
+
18
+ export { CORE_EXTENSIONS };
19
+
20
+ export const getExtensions = (options) => CORE_EXTENSIONS.concat([
21
+ History,
22
+ StylePreset.configure({
23
+ presetsRef: options.presetsRef,
24
+ defaultId: options.defaultPresetId,
25
+ makeVariable: options.makePresetVariable
26
+ }),
27
+ List.configure({
28
+ baseClass: options.baseListClass
29
+ }),
30
+ DeviceManager.configure({
31
+ deviceRef: options.deviceRef
32
+ }),
33
+ FontFamily.configure({
34
+ fonts: options.fonts
35
+ }),
36
+ FontWeight,
37
+ FontSize.configure({
38
+ minSize: options.minFontSize,
39
+ maxSize: options.maxFontSize
40
+ }),
41
+ FontColor,
42
+ BackgroundColor,
43
+ FontStyle,
44
+ TextDecoration,
45
+ CaseStyle,
46
+ Superscript,
47
+ Alignment,
48
+ LineHeight
49
+ ]);
@@ -0,0 +1,81 @@
1
+ import { Node, wrappingInputRule } from '@tiptap/vue-2';
2
+ import { computed } from '@vue/composition-api';
3
+ import { createCommand } from '../../utils';
4
+ import { ListTypes, NodeTypes } from '../../enums';
5
+ import { ListItem } from './ListItem';
6
+
7
+ export const List = Node.create({
8
+ name: NodeTypes.LIST,
9
+ content: `${NodeTypes.LIST_ITEM}+`,
10
+ group: 'block list',
11
+
12
+ addExtensions: () => [
13
+ ListItem
14
+ ],
15
+
16
+ addOptions: () => ({
17
+ baseClass: ''
18
+ }),
19
+
20
+ addAttributes: () => ({
21
+ bullet: { isRequired: true }
22
+ }),
23
+
24
+ renderHTML({ HTMLAttributes: attrs }) {
25
+ const isOrdered = ListTypes.ordered.includes(attrs.bullet.type);
26
+ const tag = isOrdered ? 'ol' : 'ul';
27
+ const bulletClass = this.options.baseClass + attrs.bullet.type;
28
+
29
+ return [tag, { class: bulletClass }, 0];
30
+ },
31
+
32
+ addCommands() {
33
+ return {
34
+ getListType: createCommand(({ commands }) => {
35
+ const attribute = commands.getBlockAttributes('bullet', { type: null });
36
+
37
+ return computed(() => attribute.value.type ?? null);
38
+ }),
39
+
40
+ applyList: createCommand(({ commands, chain }, type) => {
41
+ const currentType = commands.getListType().value;
42
+
43
+ // Remove List
44
+ if (currentType === type) {
45
+ commands.applyDefaultPreset();
46
+ return;
47
+ }
48
+
49
+ return chain().removeList()._addList(type).run();
50
+ }),
51
+
52
+ _addList: createCommand(({ chain }, type) => {
53
+ return chain()
54
+ .removePreset()
55
+ .toggleList(NodeTypes.LIST, NodeTypes.LIST_ITEM)
56
+ .setBlockAttributes('bullet', { type })
57
+ .run();
58
+ }),
59
+
60
+ removeList: createCommand(({ commands }) => {
61
+ commands.liftListItem(NodeTypes.LIST_ITEM);
62
+ })
63
+ };
64
+ },
65
+
66
+ addInputRules() {
67
+ const wrappingListRule = (bullet, regex) => wrappingInputRule({
68
+ find: regex,
69
+ type: this.type,
70
+ getAttributes: { bullet: { type: bullet } },
71
+ joinPredicate: (_, { attrs }) => attrs.bullet.type === bullet
72
+ });
73
+
74
+ return [
75
+ wrappingListRule(ListTypes.DISC, /^\s*([-+*])\s$/),
76
+ wrappingListRule(ListTypes.DECIMAL, /^(\d+)\.\s$/),
77
+ wrappingListRule(ListTypes.LATIN, /^([ivx]{1,3})\.\s$/i),
78
+ wrappingListRule(ListTypes.ROMAN, /^([a-z])\.\s$/i)
79
+ ];
80
+ }
81
+ });
@@ -0,0 +1,12 @@
1
+ import Base from '@tiptap/extension-list-item';
2
+ import { NodeTypes } from '../../enums';
3
+
4
+ export const ListItem = Base.extend({
5
+ name: NodeTypes.LIST_ITEM,
6
+
7
+ addKeyboardShortcuts() {
8
+ const { Enter } = this.parent();
9
+
10
+ return { Enter };
11
+ }
12
+ });
@@ -0,0 +1,130 @@
1
+ import { Editor } from '@tiptap/vue-2';
2
+ import { ref } from '@vue/composition-api';
3
+ import { NodeFactory } from '../../../__tests__/utils';
4
+ import { ListTypes } from '../../../enums';
5
+ import { CORE_EXTENSIONS } from '../../core';
6
+ import { StylePreset } from '../../StylePreset';
7
+ import { List } from '../List';
8
+
9
+ function createEditor({ content }) {
10
+ return new Editor({
11
+ content,
12
+ element: document.createElement('div'),
13
+ extensions: CORE_EXTENSIONS.concat(
14
+ List,
15
+ StylePreset.configure({
16
+ presetsRef: ref([
17
+ {
18
+ id: 'regular-1',
19
+ common: {},
20
+ mobile: {},
21
+ tablet: {},
22
+ desktop: {}
23
+ }
24
+ ]),
25
+ defaultId: 'regular-1'
26
+ })
27
+ )
28
+ });
29
+ }
30
+
31
+ describe('get list type', () => {
32
+ test('should get list from selection', () => {
33
+ const editor = createEditor({
34
+ content: NodeFactory.doc([
35
+ NodeFactory.list(ListTypes.LATIN, [
36
+ NodeFactory.paragraph('Item 1'),
37
+ NodeFactory.paragraph('Item 2')
38
+ ])
39
+ ])
40
+ });
41
+
42
+ editor.commands.selectAll();
43
+
44
+ expect(editor.commands.getListType().value).toBe(ListTypes.LATIN);
45
+ });
46
+
47
+ test('should return null if no list in selection', () => {
48
+ const editor = createEditor({
49
+ content: NodeFactory.doc([
50
+ NodeFactory.paragraph('Plain text')
51
+ ])
52
+ });
53
+
54
+ editor.commands.selectAll();
55
+
56
+ expect(editor.commands.getListType().value).toBe(null);
57
+ });
58
+ });
59
+
60
+ describe('apply list', () => {
61
+ test('should apply list to text', () => {
62
+ const editor = createEditor({
63
+ content: NodeFactory.doc([
64
+ NodeFactory.paragraph('Plain text')
65
+ ])
66
+ });
67
+
68
+ editor.chain().selectAll().applyList(ListTypes.LATIN).run();
69
+
70
+ expect(editor.getJSON()).toMatchSnapshot();
71
+ });
72
+
73
+ test('should remove list', () => {
74
+ const editor = createEditor({
75
+ content: NodeFactory.doc([
76
+ NodeFactory.list(ListTypes.LATIN, [
77
+ NodeFactory.paragraph('Item 1'),
78
+ NodeFactory.paragraph('Item 2')
79
+ ])
80
+ ])
81
+ });
82
+
83
+ editor.chain().selectAll().removeList().run();
84
+
85
+ expect(editor.getJSON()).toMatchSnapshot();
86
+ });
87
+
88
+ test('should toggle list', () => {
89
+ const editor = createEditor({
90
+ content: NodeFactory.doc([
91
+ NodeFactory.list(ListTypes.LATIN, [
92
+ NodeFactory.paragraph('Item 1'),
93
+ NodeFactory.paragraph('Item 2')
94
+ ])
95
+ ])
96
+ });
97
+
98
+ editor.chain().selectAll().applyList(ListTypes.LATIN).run();
99
+
100
+ expect(editor.getJSON()).toMatchSnapshot();
101
+ });
102
+
103
+ test('should change list type', () => {
104
+ const editor = createEditor({
105
+ content: NodeFactory.doc([
106
+ NodeFactory.list(ListTypes.LATIN, [
107
+ NodeFactory.paragraph('Item 1'),
108
+ NodeFactory.paragraph('Item 2')
109
+ ])
110
+ ])
111
+ });
112
+
113
+ editor.chain().selectAll().applyList(ListTypes.ROMAN).run();
114
+
115
+ expect(editor.getJSON()).toMatchSnapshot();
116
+ });
117
+
118
+ test('should remove preset', () => {
119
+ const editor = createEditor({
120
+ content: NodeFactory.doc([
121
+ NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'Item 1'),
122
+ NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'Item 2')
123
+ ])
124
+ });
125
+
126
+ editor.chain().selectAll().applyList(ListTypes.LATIN).run();
127
+
128
+ expect(editor.getJSON()).toMatchSnapshot();
129
+ });
130
+ });
@@ -0,0 +1,212 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`apply list should apply list to text 1`] = `
4
+ Object {
5
+ "content": Array [
6
+ Object {
7
+ "attrs": Object {
8
+ "bullet": Object {
9
+ "type": "latin",
10
+ },
11
+ },
12
+ "content": Array [
13
+ Object {
14
+ "content": Array [
15
+ Object {
16
+ "attrs": Object {
17
+ "preset": null,
18
+ },
19
+ "content": Array [
20
+ Object {
21
+ "text": "Plain text",
22
+ "type": "text",
23
+ },
24
+ ],
25
+ "type": "paragraph",
26
+ },
27
+ ],
28
+ "type": "listItem",
29
+ },
30
+ ],
31
+ "type": "list",
32
+ },
33
+ ],
34
+ "type": "doc",
35
+ }
36
+ `;
37
+
38
+ exports[`apply list should change list type 1`] = `
39
+ Object {
40
+ "content": Array [
41
+ Object {
42
+ "attrs": Object {
43
+ "bullet": Object {
44
+ "type": "roman",
45
+ },
46
+ },
47
+ "content": Array [
48
+ Object {
49
+ "content": Array [
50
+ Object {
51
+ "attrs": Object {
52
+ "preset": null,
53
+ },
54
+ "content": Array [
55
+ Object {
56
+ "text": "Item 1",
57
+ "type": "text",
58
+ },
59
+ ],
60
+ "type": "paragraph",
61
+ },
62
+ ],
63
+ "type": "listItem",
64
+ },
65
+ Object {
66
+ "content": Array [
67
+ Object {
68
+ "attrs": Object {
69
+ "preset": null,
70
+ },
71
+ "content": Array [
72
+ Object {
73
+ "text": "Item 2",
74
+ "type": "text",
75
+ },
76
+ ],
77
+ "type": "paragraph",
78
+ },
79
+ ],
80
+ "type": "listItem",
81
+ },
82
+ ],
83
+ "type": "list",
84
+ },
85
+ ],
86
+ "type": "doc",
87
+ }
88
+ `;
89
+
90
+ exports[`apply list should remove list 1`] = `
91
+ Object {
92
+ "content": Array [
93
+ Object {
94
+ "attrs": Object {
95
+ "preset": Object {
96
+ "id": "regular-1",
97
+ },
98
+ },
99
+ "content": Array [
100
+ Object {
101
+ "text": "Item 1",
102
+ "type": "text",
103
+ },
104
+ ],
105
+ "type": "paragraph",
106
+ },
107
+ Object {
108
+ "attrs": Object {
109
+ "preset": Object {
110
+ "id": "regular-1",
111
+ },
112
+ },
113
+ "content": Array [
114
+ Object {
115
+ "text": "Item 2",
116
+ "type": "text",
117
+ },
118
+ ],
119
+ "type": "paragraph",
120
+ },
121
+ ],
122
+ "type": "doc",
123
+ }
124
+ `;
125
+
126
+ exports[`apply list should remove preset 1`] = `
127
+ Object {
128
+ "content": Array [
129
+ Object {
130
+ "attrs": Object {
131
+ "bullet": Object {
132
+ "type": "latin",
133
+ },
134
+ },
135
+ "content": Array [
136
+ Object {
137
+ "content": Array [
138
+ Object {
139
+ "attrs": Object {
140
+ "preset": null,
141
+ },
142
+ "content": Array [
143
+ Object {
144
+ "text": "Item 1",
145
+ "type": "text",
146
+ },
147
+ ],
148
+ "type": "paragraph",
149
+ },
150
+ ],
151
+ "type": "listItem",
152
+ },
153
+ Object {
154
+ "content": Array [
155
+ Object {
156
+ "attrs": Object {
157
+ "preset": null,
158
+ },
159
+ "content": Array [
160
+ Object {
161
+ "text": "Item 2",
162
+ "type": "text",
163
+ },
164
+ ],
165
+ "type": "paragraph",
166
+ },
167
+ ],
168
+ "type": "listItem",
169
+ },
170
+ ],
171
+ "type": "list",
172
+ },
173
+ ],
174
+ "type": "doc",
175
+ }
176
+ `;
177
+
178
+ exports[`apply list should toggle list 1`] = `
179
+ Object {
180
+ "content": Array [
181
+ Object {
182
+ "attrs": Object {
183
+ "preset": Object {
184
+ "id": "regular-1",
185
+ },
186
+ },
187
+ "content": Array [
188
+ Object {
189
+ "text": "Item 1",
190
+ "type": "text",
191
+ },
192
+ ],
193
+ "type": "paragraph",
194
+ },
195
+ Object {
196
+ "attrs": Object {
197
+ "preset": Object {
198
+ "id": "regular-1",
199
+ },
200
+ },
201
+ "content": Array [
202
+ Object {
203
+ "text": "Item 2",
204
+ "type": "text",
205
+ },
206
+ ],
207
+ "type": "paragraph",
208
+ },
209
+ ],
210
+ "type": "doc",
211
+ }
212
+ `;
@@ -0,0 +1 @@
1
+ export { List } from './List';
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default as Wysiwyg } from './Wysiwyg';
@@ -0,0 +1,7 @@
1
+ export const InjectionTokens = Object.freeze({
2
+ FONTS: Symbol('fonts'),
3
+ FONT_SIZES: Symbol('fontSizes'),
4
+ EDITOR: Symbol('editor'),
5
+ LOCAL_STORAGE: Symbol('localStorage'),
6
+ FAVORITE_COLORS: Symbol('favoriteColors')
7
+ });
@@ -0,0 +1,37 @@
1
+ export class Font {
2
+ constructor({ name, category, styles }) {
3
+ this.name = name;
4
+ this.category = category;
5
+ this.styles = styles;
6
+ }
7
+
8
+ get weights() {
9
+ return this.styles.filter((style) => !style.endsWith('i'));
10
+ }
11
+
12
+ isWeightSupported(weight) {
13
+ return this.styles.includes(weight);
14
+ }
15
+
16
+ isItalicSupported(weight) {
17
+ return this.styles.includes(`${weight}i`);
18
+ }
19
+
20
+ findClosestWeight(searchedWeight) {
21
+ const weights = this.weights.map((weight) => parseInt(weight));
22
+
23
+ let closestWeight;
24
+ let closestDifferance = null;
25
+
26
+ for (const weight of weights) {
27
+ const differance = Math.abs(searchedWeight - weight);
28
+
29
+ if (closestDifferance === null || differance < closestDifferance) {
30
+ closestDifferance = differance;
31
+ closestWeight = weight;
32
+ }
33
+ }
34
+
35
+ return String(closestWeight);
36
+ }
37
+ }