@zipify/wysiwyg 4.1.0 → 4.2.0

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 (204) hide show
  1. package/.editorconfig +1 -1
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.js +63 -4
  4. package/.github/actions/lint-css/action.yaml +2 -2
  5. package/.github/actions/lint-js/action.yaml +7 -7
  6. package/.github/actions/setup/action.yaml +6 -12
  7. package/.github/actions/unit-tests/action.yaml +2 -2
  8. package/.github/dependabot.yaml +12 -12
  9. package/.github/workflows/frontend-ci.yaml +58 -56
  10. package/config/build/cli.config.js +15 -12
  11. package/config/build/{example.config.mjs → example.config.ts} +4 -11
  12. package/config/build/{lib.config.mjs → lib.config.ts} +9 -14
  13. package/config/build/settings.js +9 -3
  14. package/dist/cli.js +17 -2
  15. package/dist/types/Wysiwyg.vue.d.ts +176 -0
  16. package/dist/types/components/base/Button.vue.d.ts +19 -0
  17. package/dist/types/components/base/ButtonToggle.vue.d.ts +19 -0
  18. package/dist/types/components/base/Checkbox.vue.d.ts +10 -0
  19. package/dist/types/components/base/FieldLabel.vue.d.ts +12 -0
  20. package/dist/types/components/base/Icon.vue.d.ts +11 -0
  21. package/dist/types/components/base/Modal.vue.d.ts +28 -0
  22. package/dist/types/components/base/ModalFloating.vue.d.ts +20 -0
  23. package/dist/types/components/base/NumberField.vue.d.ts +22 -0
  24. package/dist/types/components/base/Range.vue.d.ts +16 -0
  25. package/dist/types/components/base/ScrollView.vue.d.ts +7 -0
  26. package/dist/types/components/base/TextField.vue.d.ts +14 -0
  27. package/dist/types/components/base/colorPicker/ColorPicker.vue.d.ts +18 -0
  28. package/dist/types/components/base/colorPicker/composables/index.d.ts +2 -0
  29. package/dist/types/components/base/colorPicker/composables/usePickerApi.d.ts +14 -0
  30. package/dist/types/components/base/colorPicker/composables/usePickerHotkeys.d.ts +5 -0
  31. package/dist/types/components/base/colorPicker/index.d.ts +1 -0
  32. package/dist/types/components/base/composables/index.d.ts +8 -0
  33. package/dist/types/components/base/composables/useActivatedListener.d.ts +7 -0
  34. package/dist/types/components/base/composables/useDeselectionLock.d.ts +4 -0
  35. package/dist/types/components/base/composables/useElementRef.d.ts +1 -0
  36. package/dist/types/components/base/composables/useModalToggler.d.ts +9 -0
  37. package/dist/types/components/base/composables/useNumberValue.d.ts +12 -0
  38. package/dist/types/components/base/composables/useScrollView.d.ts +6 -0
  39. package/dist/types/components/base/composables/useTempValue.d.ts +4 -0
  40. package/dist/types/components/base/composables/useValidator.d.ts +7 -0
  41. package/dist/types/components/base/dropdown/Dropdown.vue.d.ts +22 -0
  42. package/dist/types/components/base/dropdown/DropdownActivator.vue.d.ts +17 -0
  43. package/dist/types/components/base/dropdown/DropdownDivider.vue.d.ts +2 -0
  44. package/dist/types/components/base/dropdown/DropdownGroup.vue.d.ts +14 -0
  45. package/dist/types/components/base/dropdown/DropdownMenu.vue.d.ts +14 -0
  46. package/dist/types/components/base/dropdown/DropdownOption.vue.d.ts +12 -0
  47. package/dist/types/components/base/dropdown/composables/index.d.ts +2 -0
  48. package/dist/types/components/base/dropdown/composables/useActiveOptionManager.d.ts +11 -0
  49. package/dist/types/components/base/dropdown/composables/useDropdownEntityTitle.d.ts +1 -0
  50. package/dist/types/components/base/dropdown/index.d.ts +1 -0
  51. package/dist/types/components/base/dropdown/injectionTokens.d.ts +5 -0
  52. package/dist/types/components/base/index.d.ts +3 -0
  53. package/dist/types/components/index.d.ts +1 -0
  54. package/dist/types/components/toolbar/Toolbar.vue.d.ts +17 -0
  55. package/dist/types/components/toolbar/ToolbarFloating.vue.d.ts +14 -0
  56. package/dist/types/components/toolbar/base/ToolbarDivider.vue.d.ts +32 -0
  57. package/dist/types/components/toolbar/base/ToolbarGroup.vue.d.ts +2 -0
  58. package/dist/types/components/toolbar/base/ToolbarRow.vue.d.ts +2 -0
  59. package/dist/types/components/toolbar/base/index.d.ts +1 -0
  60. package/dist/types/components/toolbar/controls/AlignmentControl.vue.d.ts +4 -0
  61. package/dist/types/components/toolbar/controls/BackgroundColorControl.vue.d.ts +2 -0
  62. package/dist/types/components/toolbar/controls/CaseStyleControl.vue.d.ts +2 -0
  63. package/dist/types/components/toolbar/controls/FontColorControl.vue.d.ts +2 -0
  64. package/dist/types/components/toolbar/controls/FontFamilyControl.vue.d.ts +2 -0
  65. package/dist/types/components/toolbar/controls/FontSizeControl.vue.d.ts +2 -0
  66. package/dist/types/components/toolbar/controls/FontWeightControl.vue.d.ts +2 -0
  67. package/dist/types/components/toolbar/controls/ItalicControl.vue.d.ts +2 -0
  68. package/dist/types/components/toolbar/controls/LineHeightControl.vue.d.ts +2 -0
  69. package/dist/types/components/toolbar/controls/ListControl.vue.d.ts +2 -0
  70. package/dist/types/components/toolbar/controls/RemoveFormatControl.vue.d.ts +2 -0
  71. package/dist/types/components/toolbar/controls/StrikeThroughControl.vue.d.ts +2 -0
  72. package/dist/types/components/toolbar/controls/SuperscriptControl.vue.d.ts +2 -0
  73. package/dist/types/components/toolbar/controls/UnderlineControl.vue.d.ts +2 -0
  74. package/dist/types/components/toolbar/controls/composables/index.d.ts +1 -0
  75. package/dist/types/components/toolbar/controls/composables/useRecentFonts.d.ts +7 -0
  76. package/dist/types/components/toolbar/controls/index.d.ts +2 -0
  77. package/dist/types/components/toolbar/controls/link/LinkControl.vue.d.ts +2 -0
  78. package/dist/types/components/toolbar/controls/link/LinkControlHeader.vue.d.ts +4 -0
  79. package/dist/types/components/toolbar/controls/link/composables/index.d.ts +1 -0
  80. package/dist/types/components/toolbar/controls/link/composables/useLink.d.ts +22 -0
  81. package/dist/types/components/toolbar/controls/link/destination/LinkControlDestination.vue.d.ts +10 -0
  82. package/dist/types/components/toolbar/controls/link/destination/LinkControlPageBlock.vue.d.ts +8 -0
  83. package/dist/types/components/toolbar/controls/link/destination/LinkControlUrl.vue.d.ts +12 -0
  84. package/dist/types/components/toolbar/controls/link/destination/index.d.ts +1 -0
  85. package/dist/types/components/toolbar/controls/link/index.d.ts +1 -0
  86. package/dist/types/components/toolbar/controls/stylePreset/StylePresetControl.vue.d.ts +2 -0
  87. package/dist/types/components/toolbar/controls/stylePreset/StylePresetOption.vue.d.ts +22 -0
  88. package/dist/types/components/toolbar/controls/stylePreset/index.d.ts +1 -0
  89. package/dist/types/components/toolbar/index.d.ts +1 -0
  90. package/dist/types/components/toolbar/layouts/ToolbarDesktop.vue.d.ts +7 -0
  91. package/dist/types/components/toolbar/layouts/ToolbarMobile.vue.d.ts +2 -0
  92. package/dist/types/components/toolbar/layouts/ToolbarPopup.vue.d.ts +7 -0
  93. package/dist/types/components/toolbar/layouts/index.d.ts +1 -0
  94. package/dist/types/composables/index.d.ts +2 -0
  95. package/dist/types/composables/useEditor.d.ts +15 -0
  96. package/dist/types/directives/index.d.ts +2 -0
  97. package/dist/types/directives/outClick.d.ts +9 -0
  98. package/dist/types/directives/tooltip.d.ts +4 -0
  99. package/{lib/entryLib.js → dist/types/entryLib.d.ts} +1 -1
  100. package/dist/types/enums/Alignments.d.ts +7 -0
  101. package/dist/types/enums/CaseStyles.d.ts +5 -0
  102. package/dist/types/enums/Devices.d.ts +7 -0
  103. package/dist/types/enums/LinkDestinations.d.ts +4 -0
  104. package/dist/types/enums/LinkTargets.d.ts +4 -0
  105. package/dist/types/enums/ListTypes.d.ts +10 -0
  106. package/dist/types/enums/MarkGroups.d.ts +4 -0
  107. package/dist/types/enums/NodeTypes.d.ts +9 -0
  108. package/dist/types/enums/TextSettings.d.ts +19 -0
  109. package/dist/types/enums/index.d.ts +9 -0
  110. package/dist/types/extensions/Alignment.d.ts +2 -0
  111. package/dist/types/extensions/BackgroundColor.d.ts +2 -0
  112. package/dist/types/extensions/CaseStyle.d.ts +2 -0
  113. package/dist/types/extensions/DeviceManager.d.ts +2 -0
  114. package/dist/types/extensions/FontColor.d.ts +2 -0
  115. package/dist/types/extensions/FontFamily.d.ts +4 -0
  116. package/dist/types/extensions/FontSize.d.ts +5 -0
  117. package/dist/types/extensions/FontStyle.d.ts +2 -0
  118. package/dist/types/extensions/FontWeight.d.ts +2 -0
  119. package/dist/types/extensions/LineHeight.d.ts +2 -0
  120. package/dist/types/extensions/Link.d.ts +1 -0
  121. package/dist/types/extensions/Margin.d.ts +2 -0
  122. package/dist/types/extensions/StylePreset.d.ts +2 -0
  123. package/dist/types/extensions/Superscript.d.ts +2 -0
  124. package/dist/types/extensions/TextDecoration.d.ts +2 -0
  125. package/dist/types/extensions/core/Document.d.ts +1 -0
  126. package/dist/types/extensions/core/Heading.d.ts +6 -0
  127. package/dist/types/extensions/core/NodeProcessor.d.ts +2 -0
  128. package/dist/types/extensions/core/Paragraph.d.ts +5 -0
  129. package/dist/types/extensions/core/SelectionProcessor.d.ts +4 -0
  130. package/dist/types/extensions/core/TextProcessor.d.ts +2 -0
  131. package/dist/types/extensions/core/index.d.ts +2 -0
  132. package/dist/types/extensions/index.d.ts +1 -0
  133. package/dist/types/extensions/list/List.d.ts +5 -0
  134. package/dist/types/extensions/list/ListItem.d.ts +5 -0
  135. package/dist/types/extensions/list/index.d.ts +1 -0
  136. package/dist/types/extensions/proseMirror/PasteLinkPlugin.d.ts +8 -0
  137. package/dist/types/extensions/proseMirror/PastePlugin.d.ts +22 -0
  138. package/dist/types/extensions/proseMirror/PlaceholderPlugin.d.ts +12 -0
  139. package/dist/types/extensions/proseMirror/ProseMirrorPlugin.d.ts +9 -0
  140. package/dist/types/extensions/proseMirror/index.d.ts +3 -0
  141. package/dist/types/extensions/steps/SetDocAttr.d.ts +19 -0
  142. package/dist/types/extensions/steps/index.d.ts +1 -0
  143. package/dist/types/injectionTokens.d.ts +8 -0
  144. package/dist/types/models/Font.d.ts +17 -0
  145. package/dist/types/models/index.d.ts +2 -0
  146. package/dist/types/regExps.d.ts +6 -0
  147. package/dist/types/services/ContentSerializer.d.ts +15 -0
  148. package/dist/types/services/ContextWindow.d.ts +8 -0
  149. package/dist/types/services/FavoriteColors.d.ts +8 -0
  150. package/dist/types/services/HtmlToJsonParser.d.ts +6 -0
  151. package/dist/types/services/JsonSerializer.d.ts +4 -0
  152. package/dist/types/services/NodeFactory.d.ts +128 -0
  153. package/dist/types/services/NodeSelector.d.ts +9 -0
  154. package/dist/types/services/Storage.d.ts +10 -0
  155. package/dist/types/services/StylePresetRenderer.d.ts +15 -0
  156. package/dist/types/services/index.d.ts +10 -0
  157. package/dist/types/services/normalizer/BaseNormalizer.d.ts +7 -0
  158. package/dist/types/services/normalizer/BrowserDomParser.d.ts +5 -0
  159. package/dist/types/services/normalizer/ContentNormalizer.d.ts +8 -0
  160. package/dist/types/services/normalizer/HtmlNormalizer.d.ts +41 -0
  161. package/dist/types/services/normalizer/JsonNormalizer.d.ts +14 -0
  162. package/dist/types/services/normalizer/index.d.ts +1 -0
  163. package/dist/types/utils/capitalize.d.ts +1 -0
  164. package/dist/types/utils/convertAlignment.d.ts +1 -0
  165. package/dist/types/utils/convertColor.d.ts +1 -0
  166. package/dist/types/utils/convertFontSize.d.ts +1 -0
  167. package/dist/types/utils/convertLineHeight.d.ts +1 -0
  168. package/dist/types/utils/copyMark.d.ts +1 -0
  169. package/dist/types/utils/createCommand.d.ts +1 -0
  170. package/dist/types/utils/createKeyboardShortcut.d.ts +3 -0
  171. package/dist/types/utils/findMarkByType.d.ts +1 -0
  172. package/dist/types/utils/importIcon.d.ts +1 -0
  173. package/{lib/utils/index.js → dist/types/utils/index.d.ts} +1 -0
  174. package/dist/types/utils/isMarkAppliedToParent.d.ts +1 -0
  175. package/dist/types/utils/isNodeFullySelected.d.ts +1 -0
  176. package/dist/types/utils/isWysiwygContent.d.ts +7 -0
  177. package/dist/types/utils/renderInlineSetting.d.ts +4 -0
  178. package/dist/types/utils/resolvePositionOffset.d.ts +1 -0
  179. package/dist/types/utils/resolveTextPosition.d.ts +4 -0
  180. package/dist/wysiwyg.d.ts +1 -0
  181. package/dist/wysiwyg.mjs +194 -152
  182. package/example/ExampleApp.vue +1 -1
  183. package/example/{example.js → example.ts} +1 -1
  184. package/example/index.html +1 -1
  185. package/jest.config.js +20 -5
  186. package/lib/Wysiwyg.vue +16 -12
  187. package/lib/components/base/__tests__/Modal.test.js +2 -2
  188. package/lib/composables/index.ts +2 -0
  189. package/lib/composables/{useEditor.js → useEditor.ts} +24 -7
  190. package/lib/entryLib.ts +6 -0
  191. package/lib/extensions/StylePreset.js +3 -3
  192. package/lib/models/{Font.js → Font.ts} +19 -8
  193. package/lib/models/index.ts +2 -0
  194. package/lib/utils/importIcon.js +1 -1
  195. package/lib/utils/index.ts +17 -0
  196. package/lib/utils/isWysiwygContent.ts +18 -0
  197. package/package.json +47 -33
  198. package/tsconfig.json +32 -0
  199. package/tsconfig.types.json +23 -0
  200. package/lib/composables/index.js +0 -1
  201. package/lib/models/index.js +0 -1
  202. package/lib/utils/isWysiwygContent.js +0 -12
  203. /package/lib/{entryCli.js → entryCli.ts} +0 -0
  204. /package/lib/models/__tests__/{Font.test.js → Font.test.ts} +0 -0
@@ -51,7 +51,7 @@
51
51
 
52
52
  <script>
53
53
  import { computed, onMounted, ref, unref } from 'vue';
54
- import { Wysiwyg } from '../lib/entryLib';
54
+ import { Wysiwyg } from '@/entryLib';
55
55
  import { FONTS } from './fonts';
56
56
  import { PRESETS, renderPresetVariable } from './presets';
57
57
  import { PAGE_BLOCKS } from './pageBlocks';
@@ -1,5 +1,5 @@
1
1
  import { createApp, h } from 'vue';
2
- import ExampleApp from './ExampleApp';
2
+ import ExampleApp from './ExampleApp.vue';
3
3
  import { loadFonts } from './fonts';
4
4
  import { renderPresets } from './presets';
5
5
  import { tooltipManager } from './tooltip';
@@ -13,6 +13,6 @@
13
13
  </head>
14
14
  <body>
15
15
  <div data-app></div>
16
- <script type="module" src="./example.js"></script>
16
+ <script type="module" src="example.ts"></script>
17
17
  </body>
18
18
  </html>
package/jest.config.js CHANGED
@@ -1,14 +1,29 @@
1
+ const tsconfig = require('./tsconfig.json');
2
+
3
+ const jsTransform = ['esbuild-jest', {
4
+ sourcemap: 'inline'
5
+ }];
6
+
7
+ const formatAlias = ([name, [path]]) => [
8
+ `^${name.replace('/*', '/(.*)')}`,
9
+ `<rootDir>/${path.replace('/*', '/$1')}`
10
+ ];
11
+
12
+ const aliases = Object.fromEntries(Object.entries(tsconfig.compilerOptions.paths).map(formatAlias));
13
+
1
14
  module.exports = {
2
- testMatch: ['<rootDir>/**/*.test.js'],
3
- moduleFileExtensions: ['js', 'json', 'vue', 'scss'],
15
+ testMatch: ['<rootDir>/**/*.test.{ts,js}'],
16
+ moduleFileExtensions: ['js', 'ts', 'json', 'vue', 'scss'],
4
17
  transform: {
5
- '^.+\\.js$': 'babel-jest',
18
+ '^.+\\.js$': jsTransform,
19
+ '^.+\\.ts$': jsTransform,
6
20
  '^.+\\.vue$': '@vue/vue3-jest',
7
21
  'node_modules/@zipify/.+': 'babel-jest'
8
22
  },
9
23
  transformIgnorePatterns: ['node_modules/(?!@zipify)/'],
10
24
  moduleNameMapper: {
11
- '^.+\\.svg$': '<rootDir>/lib/__mocks__/svgMock.js'
25
+ '^.+\\.svg$': '<rootDir>/lib/__mocks__/svgMock.js',
26
+ ...aliases
12
27
  },
13
28
  snapshotFormat: {
14
29
  printBasicPrototype: true
@@ -19,7 +34,7 @@ module.exports = {
19
34
  },
20
35
  setupFilesAfterEnv: ['<rootDir>/config/jest/setupMatchers.js'],
21
36
  setupFiles: ['<rootDir>/config/jest/setupTests.js'],
22
- collectCoverageFrom: ['<rootDir>/lib/**/*.{js,vue}'],
37
+ collectCoverageFrom: ['<rootDir>/lib/**/*.{ts,js,vue}'],
23
38
  coverageReporters: ['html-spa'],
24
39
  coveragePathIgnorePatterns: ['/node_modules/']
25
40
  };
package/lib/Wysiwyg.vue CHANGED
@@ -13,23 +13,20 @@
13
13
  </div>
14
14
  </template>
15
15
 
16
- <script setup>
16
+ <script lang="ts" setup>
17
17
  import { EditorContent } from '@tiptap/vue-3';
18
+ import type { Content, JSONContent } from '@tiptap/core';
18
19
  import { provide, toRef, ref, computed } from 'vue';
20
+ import type { PropType } from 'vue';
19
21
  import { Toolbar } from './components';
20
22
  import { useEditor } from './composables';
21
23
  import { buildExtensions } from './extensions';
22
24
  import { InjectionTokens } from './injectionTokens';
23
25
  import { ContextWindow, FavoriteColors, Storage } from './services';
24
26
  import { Devices } from './enums';
25
- import { Font } from './models';
27
+ import { Font, type IFontJson } from './models';
26
28
 
27
29
  const props = defineProps({
28
- modelValue: {
29
- type: [String, Object],
30
- required: true
31
- },
32
-
33
30
  presets: {
34
31
  type: Array,
35
32
  required: true
@@ -56,7 +53,7 @@ const props = defineProps({
56
53
  },
57
54
 
58
55
  fonts: {
59
- type: Array,
56
+ type: Array as PropType<IFontJson[]>,
60
57
  required: true
61
58
  },
62
59
 
@@ -122,10 +119,14 @@ const props = defineProps({
122
119
  });
123
120
 
124
121
  const emit = defineEmits( [
125
- 'update:model-value',
126
122
  'update-favorite-colors'
127
123
  ]);
128
124
 
125
+ const modelValue = defineModel<Content>({
126
+ type: [String, Object],
127
+ required: true
128
+ });
129
+
129
130
  const MIN_FONT_SIZE = 5;
130
131
  const MAX_FONT_SIZE = 112;
131
132
 
@@ -136,12 +137,12 @@ const wysiwygRef = ref(null);
136
137
  const wrapperRef = computed(() => wysiwygRef.value || document.body);
137
138
  const isToolbarVisible = computed(() => props.active && !props.readonly);
138
139
 
139
- const onChange = (content) => emit('update:model-value', content);
140
+ const onChange = (content: JSONContent) => modelValue.value = content;
140
141
 
141
142
  const pageBlocks = toRef(props, 'pageBlocks');
142
143
 
143
144
  const { editor, getContent } = useEditor({
144
- content: toRef(props, 'modelValue'),
145
+ content: modelValue,
145
146
  onChange,
146
147
  isReadonlyRef: toRef(props, 'readonly'),
147
148
 
@@ -167,9 +168,12 @@ const fontSizes = new Array(MAX_FONT_SIZE - MIN_FONT_SIZE + 1)
167
168
 
168
169
  const favoriteColors = new FavoriteColors({
169
170
  listRef: toRef(props, 'favoriteColors'),
170
- triggerUpdate: (colors) => emit('update-favorite-colors', colors)
171
+ triggerUpdate: (colors: string[]) => emit('update-favorite-colors', colors)
171
172
  });
172
173
 
174
+ // Requires a lot of effort to add types right now
175
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
176
+ // @ts-expect-error
173
177
  const getContentCustomization = () => editor.commands.getContentCustomization();
174
178
 
175
179
  provide(InjectionTokens.EDITOR, editor);
@@ -1,4 +1,4 @@
1
- import { nextTick, ref } from 'vue';
1
+ import { nextTick, reactive, ref } from 'vue';
2
2
  import { shallowMount } from '@vue/test-utils';
3
3
  import { InjectionTokens } from '../../../injectionTokens';
4
4
  import Modal from '../Modal';
@@ -9,7 +9,7 @@ jest.mock('../composables', () => ({
9
9
  useModalToggler: jest.fn()
10
10
  }));
11
11
 
12
- const createToggler = (isOpened) => ({
12
+ const createToggler = (isOpened) => reactive({
13
13
  close: jest.fn(),
14
14
  isOpened: ref(isOpened ?? true)
15
15
  });
@@ -0,0 +1,2 @@
1
+ export { useEditor } from './useEditor';
2
+ export type { IUseEditorProps, IUseEditorReturn } from './useEditor';
@@ -1,12 +1,29 @@
1
- import { Editor } from '@tiptap/vue-3';
1
+ import { type AnyExtension, Editor } from '@tiptap/vue-3';
2
+ import type { Content } from '@tiptap/core';
2
3
  import { onUnmounted, watch, reactive, unref } from 'vue';
3
- import { ContentNormalizer } from '../services';
4
- import { markWysiwygContent } from '../utils';
4
+ import type { Ref, UnwrapNestedRefs } from 'vue';
5
+ import { ContentNormalizer } from '@/services';
6
+ import { markWysiwygContent } from '@/utils';
7
+ import type { WysiwygContent } from '@/utils';
5
8
 
6
- export function useEditor({ content, onChange, extensions, isReadonlyRef }) {
7
- let editor;
9
+ export interface IUseEditorProps {
10
+ content: Ref<Content>;
11
+ onChange: (content: WysiwygContent) => void;
12
+ extensions: AnyExtension[];
13
+ isReadonlyRef: Ref<boolean>;
8
14
 
9
- const getContent = () => markWysiwygContent(editor.getJSON());
15
+ }
16
+
17
+ export interface IUseEditorReturn {
18
+ editor: Editor;
19
+ getContent(): WysiwygContent;
20
+ }
21
+
22
+ export function useEditor({ content, onChange, extensions, isReadonlyRef }: IUseEditorProps): IUseEditorReturn {
23
+ // eslint-disable-next-line prefer-const
24
+ let editor: UnwrapNestedRefs<Editor>;
25
+
26
+ const getContent = (): WysiwygContent => markWysiwygContent(editor.getJSON());
10
27
 
11
28
  editor = reactive(new Editor({
12
29
  content: ContentNormalizer.normalize(content.value),
@@ -33,5 +50,5 @@ export function useEditor({ content, onChange, extensions, isReadonlyRef }) {
33
50
 
34
51
  watch(isReadonlyRef, (isReadonly) => editor.setEditable(!isReadonly, false));
35
52
 
36
- return { editor, getContent };
53
+ return { editor: editor as Editor, getContent };
37
54
  }
@@ -0,0 +1,6 @@
1
+ export { default as Wysiwyg } from './Wysiwyg.vue';
2
+ export { NodeFactory, HtmlToJsonParser } from './services';
3
+ export { NodeTypes, TextSettings, Alignments } from './enums';
4
+ export { isWysiwygContent, unmarkWysiwygContent, markWysiwygContent } from './utils';
5
+ export * from './components/base';
6
+ export { InjectionTokens } from './injectionTokens';
@@ -1,8 +1,8 @@
1
1
  import { Extension } from '@tiptap/vue-3';
2
2
  import { computed, toRef, unref } from 'vue';
3
- import { createCommand } from '../utils';
4
- import { NodeTypes, TextSettings } from '../enums';
5
- import { ContextWindow } from '../services';
3
+ import { createCommand } from '@/utils';
4
+ import { NodeTypes, TextSettings } from '@/enums';
5
+ import { ContextWindow } from '@/services';
6
6
 
7
7
  export const StylePreset = Extension.create({
8
8
  name: TextSettings.STYLE_PRESET,
@@ -1,37 +1,48 @@
1
+ export interface IFontJson {
2
+ name: string;
3
+ category: string;
4
+ styles: string[];
5
+ }
6
+
1
7
  export class Font {
2
- constructor({ name, category, styles }) {
8
+ name: string;
9
+ category: string;
10
+ styles: string[];
11
+ weights: string[];
12
+
13
+ constructor({ name, category, styles }: IFontJson) {
3
14
  this.name = name;
4
15
  this.category = category;
5
16
  this.styles = styles;
6
- this.weights = this._getWeights();
17
+ this.weights = this.getWeights();
7
18
  }
8
19
 
9
- _getWeights() {
20
+ private getWeights(): string[] {
10
21
  const weights = this.styles.map((style) => style.replace('i', ''));
11
22
 
12
23
  return Array.from(new Set(weights));
13
24
  }
14
25
 
15
- isWeightSupported(weight) {
26
+ isWeightSupported(weight: string): boolean {
16
27
  return this.weights.includes(weight);
17
28
  }
18
29
 
19
- isItalicSupported(weight) {
30
+ isItalicSupported(weight: string): boolean {
20
31
  return this.styles.includes(`${weight}i`);
21
32
  }
22
33
 
23
- isWeightItalicOnly(weight) {
34
+ isWeightItalicOnly(weight: string): boolean {
24
35
  return this.isItalicSupported(weight) && !this.styles.includes(weight);
25
36
  }
26
37
 
27
- findClosestWeight(searchedWeight) {
38
+ findClosestWeight(searchingWeight: string): string {
28
39
  const weights = this.weights.map((weight) => parseInt(weight));
29
40
 
30
41
  let closestWeight;
31
42
  let closestDifferance = null;
32
43
 
33
44
  for (const weight of weights) {
34
- const differance = Math.abs(searchedWeight - weight);
45
+ const differance = Math.abs(Number(searchingWeight) - weight);
35
46
 
36
47
  if (closestDifferance === null || differance < closestDifferance) {
37
48
  closestDifferance = differance;
@@ -0,0 +1,2 @@
1
+ export { Font } from './Font';
2
+ export type { IFontJson } from './Font';
@@ -1,4 +1,4 @@
1
- const modules = import.meta.glob('../assets/icons/*.svg', { as: 'raw', eager: true });
1
+ const modules = import.meta.glob('../assets/icons/*.svg', { query: '?raw', eager: true, import: 'default' });
2
2
 
3
3
  export function importIcon(name) {
4
4
  return modules[`../assets/icons/${name}.svg`] || '';
@@ -0,0 +1,17 @@
1
+ export { createCommand } from './createCommand';
2
+ export { renderInlineSetting, renderMark } from './renderInlineSetting';
3
+ export { capitalize } from './capitalize';
4
+ export { createKeyboardShortcut } from './createKeyboardShortcut';
5
+ export { convertColor } from './convertColor';
6
+ export { convertLineHeight } from './convertLineHeight';
7
+ export { convertFontSize } from './convertFontSize';
8
+ export { convertAlignment } from './convertAlignment';
9
+ export { importIcon } from './importIcon';
10
+ export { isWysiwygContent, markWysiwygContent, unmarkWysiwygContent } from './isWysiwygContent';
11
+ export type { WysiwygContent } from './isWysiwygContent';
12
+ export { resolveTextPosition } from './resolveTextPosition';
13
+ export { resolvePositionOffset } from './resolvePositionOffset';
14
+ export { isNodeFullySelected } from './isNodeFullySelected';
15
+ export { isMarkAppliedToParent } from './isMarkAppliedToParent';
16
+ export { findMarkByType } from './findMarkByType';
17
+ export { copyMark } from './copyMark';
@@ -0,0 +1,18 @@
1
+ import type { JSONContent } from '@tiptap/core';
2
+
3
+ export interface WysiwygContent extends JSONContent{
4
+ __wswg__: true;
5
+ }
6
+
7
+ export function isWysiwygContent(content: string | object): content is JSONContent {
8
+ return typeof content === 'object' && (content as WysiwygContent).__wswg__;
9
+ }
10
+
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ export function unmarkWysiwygContent({ __wswg__, ...content }: WysiwygContent): JSONContent {
13
+ return content;
14
+ }
15
+
16
+ export function markWysiwygContent(content: JSONContent): WysiwygContent {
17
+ return { ...content, __wswg__: true };
18
+ }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@zipify/wysiwyg",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "Zipify modification of TipTap text editor",
5
5
  "main": "dist/wysiwyg.mjs",
6
+ "types": "dist/wysiwyg.d.ts",
6
7
  "bin": {
7
8
  "zipify-wysiwyg": "bin/cli"
8
9
  },
@@ -17,12 +18,13 @@
17
18
  "url": "https://github.com/ZipifyApps/ZipifyWysiwyg/issues"
18
19
  },
19
20
  "scripts": {
20
- "lib:build": "vite build --config config/build/lib.config.mjs",
21
+ "lib:build": "npm run lib:build-types && vite build --config config/build/lib.config.ts",
22
+ "lib:build-types": "vue-tsc -P ./tsconfig.types.json",
21
23
  "lib:release": "[ -f .env ] && export $(cat .env | xargs) && release-it",
22
24
  "cli:build": "NODE_ENV=production rollup --config config/build/cli.config.js --bundleConfigAsCjs",
23
25
  "cli:dev": "NODE_ENV=development rollup --config config/build/cli.config.js --bundleConfigAsCjs --watch",
24
- "example:start": "NODE_ENV=development vite serve --config config/build/example.config.mjs",
25
- "example:build": "NODE_ENV=production vite build --config config/build/example.config.mjs",
26
+ "example:start": "NODE_ENV=development vite serve --config config/build/example.config.ts",
27
+ "example:build": "NODE_ENV=production vite build --config config/build/example.config.ts",
26
28
  "test:unit": "jest .",
27
29
  "lint:js": "eslint ./lib",
28
30
  "lint:css": "stylelint ./lib/**/*.{css,vue}",
@@ -30,7 +32,7 @@
30
32
  "prepare": "husky install"
31
33
  },
32
34
  "dependencies": {
33
- "@floating-ui/vue": "^1.0.2",
35
+ "@floating-ui/vue": "^1.0.6",
34
36
  "@tiptap/core": "^2.1.13",
35
37
  "@tiptap/extension-document": "^2.1.13",
36
38
  "@tiptap/extension-heading": "^2.1.13",
@@ -41,14 +43,14 @@
41
43
  "@tiptap/extension-text": "^2.1.13",
42
44
  "@tiptap/pm": "^2.1.13",
43
45
  "@tiptap/vue-3": "^2.1.13",
44
- "commander": "^11.1.0",
45
- "jsdom": "^23.0.1",
46
+ "commander": "^12.0.0",
47
+ "jsdom": "^24.0.0",
46
48
  "lodash": "^4.17.21",
47
49
  "simplebar": "^6.2.5"
48
50
  },
49
51
  "peerDependencies": {
50
- "@zipify/colorpicker": "^3.1",
51
- "vue": "^3.2"
52
+ "@zipify/colorpicker": "^3.2",
53
+ "vue": "^3.4"
52
54
  },
53
55
  "peerDependenciesMeta": {
54
56
  "@zipify/colorpicker": {
@@ -59,42 +61,54 @@
59
61
  }
60
62
  },
61
63
  "devDependencies": {
62
- "@babel/core": "^7.23.6",
63
- "@babel/eslint-parser": "^7.23.3",
64
- "@babel/plugin-transform-runtime": "^7.23.6",
65
- "@babel/preset-env": "^7.23.6",
66
- "@babel/runtime": "^7.23.6",
64
+ "@babel/core": "^7.24.0",
65
+ "@babel/eslint-parser": "^7.23.10",
66
+ "@babel/plugin-transform-runtime": "^7.24.0",
67
+ "@babel/preset-env": "^7.24.0",
68
+ "@babel/runtime": "^7.24.0",
67
69
  "@optimize-lodash/rollup-plugin": "^4.0.4",
68
- "@rollup/plugin-babel": "^6.0.4",
70
+ "@rollup/plugin-alias": "^5.1.0",
69
71
  "@rollup/plugin-commonjs": "^25.0.7",
70
- "@rollup/plugin-json": "^6.0.1",
72
+ "@rollup/plugin-json": "^6.1.0",
71
73
  "@rollup/plugin-node-resolve": "^15.2.3",
72
74
  "@rollup/plugin-replace": "^5.0.5",
73
75
  "@rollup/plugin-terser": "^0.4.4",
74
- "@vitejs/plugin-vue": "^4.5.2",
75
- "@vue/test-utils": "^2.4.3",
76
+ "@rushstack/eslint-patch": "^1.7.2",
77
+ "@types/jest": "^29.5.12",
78
+ "@types/node": "^20.10.0",
79
+ "@typescript-eslint/eslint-plugin": "^7.2.0",
80
+ "@typescript-eslint/parser": "^7.2.0",
81
+ "@vitejs/plugin-vue": "^5.0.4",
82
+ "@vue/eslint-config-typescript": "^13.0.0",
83
+ "@vue/test-utils": "^2.4.5",
84
+ "@vue/tsconfig": "^0.5.1",
76
85
  "@vue/vue3-jest": "^29.2.6",
77
- "@zipify/colorpicker": "^3.1.0",
78
- "@zipify/eslint-config": "^1.4.1",
86
+ "@zipify/colorpicker": "^3.2.0",
87
+ "@zipify/eslint-config": "^1.5.0",
79
88
  "babel-jest": "^29.7.0",
80
- "eslint": "^8.55.0",
81
- "eslint-plugin-import": "^2.29.0",
82
- "eslint-plugin-jest": "^27.6.0",
83
- "eslint-plugin-vue": "^9.19.2",
84
- "husky": "^8.0.3",
89
+ "esbuild-jest": "^0.5.0",
90
+ "eslint": "^8.57.0",
91
+ "eslint-import-resolver-alias": "^1.1.2",
92
+ "eslint-plugin-import": "^2.29.1",
93
+ "eslint-plugin-jest": "^27.9.0",
94
+ "eslint-plugin-vue": "^9.23.0",
95
+ "husky": "^9.0.11",
85
96
  "jest": "^29.7.0",
86
97
  "jest-environment-jsdom": "^29.7.0",
87
- "lint-staged": "^15.2.0",
88
- "postcss-html": "^1.5.0",
89
- "release-it": "^17.0.1",
90
- "rollup": "^4.8.0",
98
+ "lint-staged": "^15.2.2",
99
+ "postcss-html": "^1.6.0",
100
+ "release-it": "^17.1.1",
101
+ "rollup": "^4.13.0",
102
+ "rollup-plugin-esbuild": "^6.1.1",
91
103
  "stylelint": "^14.16.1",
92
- "svgo": "^3.1.0",
93
- "vite": "^5.0.7",
94
- "vue": "3.3.11"
104
+ "svgo": "^3.2.0",
105
+ "typescript": "^5.4.2",
106
+ "vite": "^5.1.6",
107
+ "vue": "3.4.21",
108
+ "vue-tsc": "^2.0.6"
95
109
  },
96
110
  "engines": {
97
- "node": ">=18.12.0"
111
+ "node": ">=20.10.0"
98
112
  },
99
113
  "engineStrict": true,
100
114
  "os": [
package/tsconfig.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "extends": [
3
+ "@vue/tsconfig/tsconfig.dom.json"
4
+ ],
5
+ "compilerOptions": {
6
+ "allowSyntheticDefaultImports": true,
7
+ "allowJs": true,
8
+ "moduleDetection": "force",
9
+ "isolatedModules": true,
10
+ "noUncheckedIndexedAccess": true,
11
+ "strictNullChecks": true,
12
+ "baseUrl": "./",
13
+ "skipLibCheck": true,
14
+ "paths": {
15
+ "@/*": ["lib/*"]
16
+ },
17
+ "types": [
18
+ "jest",
19
+ "@types/jest",
20
+ "@types/node"
21
+ ]
22
+ },
23
+ "include": [
24
+ "lib/**/*",
25
+ "example/**/*",
26
+ "config/**/*"
27
+ ],
28
+ "exclude": [
29
+ "node_modules",
30
+ "dist"
31
+ ]
32
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": ["./tsconfig.json"],
3
+ "compilerOptions": {
4
+ "noEmit": false,
5
+ "declaration": true,
6
+ "emitDeclarationOnly": true,
7
+ "outDir": "dist/types",
8
+ "rootDir": "lib"
9
+ },
10
+ "include": [
11
+ "lib/**/*.ts",
12
+ "lib/**/*.js",
13
+ "lib/**/*.vue"
14
+ ],
15
+ "exclude": [
16
+ "node_modules/**",
17
+ "dist/**",
18
+ "**/__tests__/**",
19
+ "**/__mocks__/**",
20
+ "lib/entryCli.ts",
21
+ "lib/cli/**"
22
+ ]
23
+ }
@@ -1 +0,0 @@
1
- export { useEditor } from './useEditor';
@@ -1 +0,0 @@
1
- export { Font } from './Font';
@@ -1,12 +0,0 @@
1
- export function isWysiwygContent(content) {
2
- return typeof content === 'object' && content.__wswg__;
3
- }
4
-
5
- // eslint-disable-next-line no-unused-vars
6
- export function unmarkWysiwygContent({ __wswg__, ...content }) {
7
- return content;
8
- }
9
-
10
- export function markWysiwygContent(content) {
11
- return { ...content, __wswg__: true };
12
- }
File without changes