@edifice.io/tiptap-extensions 1.5.16-develop-rc.2

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 (171) hide show
  1. package/.turbo/turbo-build.log +58 -0
  2. package/.turbo/turbo-format.log +142 -0
  3. package/.turbo/turbo-lint.log +5 -0
  4. package/LICENSE +661 -0
  5. package/dist/abbr/abbr.cjs +33 -0
  6. package/dist/abbr/abbr.cjs.map +1 -0
  7. package/dist/abbr/abbr.d.ts +16 -0
  8. package/dist/abbr/abbr.js +37 -0
  9. package/dist/abbr/abbr.js.map +1 -0
  10. package/dist/abbr/index.d.ts +3 -0
  11. package/dist/alert/alert.cjs +33 -0
  12. package/dist/alert/alert.cjs.map +1 -0
  13. package/dist/alert/alert.d.ts +2 -0
  14. package/dist/alert/alert.js +43 -0
  15. package/dist/alert/alert.js.map +1 -0
  16. package/dist/alert/index.d.ts +3 -0
  17. package/dist/attachment/attachment.cjs +74 -0
  18. package/dist/attachment/attachment.cjs.map +1 -0
  19. package/dist/attachment/attachment.d.ts +12 -0
  20. package/dist/attachment/attachment.js +86 -0
  21. package/dist/attachment/attachment.js.map +1 -0
  22. package/dist/attachment/index.d.ts +3 -0
  23. package/dist/audio/audio.cjs +55 -0
  24. package/dist/audio/audio.cjs.map +1 -0
  25. package/dist/audio/audio.d.ts +23 -0
  26. package/dist/audio/audio.js +55 -0
  27. package/dist/audio/audio.js.map +1 -0
  28. package/dist/audio/index.d.ts +3 -0
  29. package/dist/font-size/font-size.cjs +49 -0
  30. package/dist/font-size/font-size.cjs.map +1 -0
  31. package/dist/font-size/font-size.d.ts +19 -0
  32. package/dist/font-size/font-size.js +51 -0
  33. package/dist/font-size/font-size.js.map +1 -0
  34. package/dist/font-size/index.d.ts +3 -0
  35. package/dist/heading/heading.cjs +62 -0
  36. package/dist/heading/heading.cjs.map +1 -0
  37. package/dist/heading/heading.d.ts +17 -0
  38. package/dist/heading/heading.js +60 -0
  39. package/dist/heading/heading.js.map +1 -0
  40. package/dist/heading/index.d.ts +3 -0
  41. package/dist/highlight/highlight.cjs +26 -0
  42. package/dist/highlight/highlight.cjs.map +1 -0
  43. package/dist/highlight/highlight.d.ts +4 -0
  44. package/dist/highlight/highlight.js +26 -0
  45. package/dist/highlight/highlight.js.map +1 -0
  46. package/dist/highlight/index.d.ts +3 -0
  47. package/dist/hyperlink/hyperlink.cjs +48 -0
  48. package/dist/hyperlink/hyperlink.cjs.map +1 -0
  49. package/dist/hyperlink/hyperlink.d.ts +38 -0
  50. package/dist/hyperlink/hyperlink.js +55 -0
  51. package/dist/hyperlink/hyperlink.js.map +1 -0
  52. package/dist/hyperlink/index.d.ts +3 -0
  53. package/dist/iframe/iframe.cjs +70 -0
  54. package/dist/iframe/iframe.cjs.map +1 -0
  55. package/dist/iframe/iframe.d.ts +18 -0
  56. package/dist/iframe/iframe.js +85 -0
  57. package/dist/iframe/iframe.js.map +1 -0
  58. package/dist/iframe/index.d.ts +3 -0
  59. package/dist/image/custom-image.cjs +163 -0
  60. package/dist/image/custom-image.cjs.map +1 -0
  61. package/dist/image/custom-image.d.ts +27 -0
  62. package/dist/image/custom-image.js +181 -0
  63. package/dist/image/custom-image.js.map +1 -0
  64. package/dist/image/index.d.ts +3 -0
  65. package/dist/index.cjs +44 -0
  66. package/dist/index.cjs.map +1 -0
  67. package/dist/index.d.ts +19 -0
  68. package/dist/index.js +44 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/line-height/index.d.ts +3 -0
  71. package/dist/line-height/line-height.cjs +34 -0
  72. package/dist/line-height/line-height.cjs.map +1 -0
  73. package/dist/line-height/line-height.d.ts +2 -0
  74. package/dist/line-height/line-height.js +36 -0
  75. package/dist/line-height/line-height.js.map +1 -0
  76. package/dist/linker/index.d.ts +3 -0
  77. package/dist/linker/linker.cjs +96 -0
  78. package/dist/linker/linker.cjs.map +1 -0
  79. package/dist/linker/linker.d.ts +30 -0
  80. package/dist/linker/linker.js +104 -0
  81. package/dist/linker/linker.js.map +1 -0
  82. package/dist/mathjax/index.d.ts +3 -0
  83. package/dist/mathjax/mathjax.cjs +48 -0
  84. package/dist/mathjax/mathjax.cjs.map +1 -0
  85. package/dist/mathjax/mathjax.d.ts +2 -0
  86. package/dist/mathjax/mathjax.js +50 -0
  87. package/dist/mathjax/mathjax.js.map +1 -0
  88. package/dist/paragraph/index.d.ts +3 -0
  89. package/dist/paragraph/paragraph.cjs +14 -0
  90. package/dist/paragraph/paragraph.cjs.map +1 -0
  91. package/dist/paragraph/paragraph.d.ts +16 -0
  92. package/dist/paragraph/paragraph.js +14 -0
  93. package/dist/paragraph/paragraph.js.map +1 -0
  94. package/dist/speech-recognition/index.d.ts +3 -0
  95. package/dist/speech-recognition/speech-recognition.cjs +77 -0
  96. package/dist/speech-recognition/speech-recognition.cjs.map +1 -0
  97. package/dist/speech-recognition/speech-recognition.d.ts +21 -0
  98. package/dist/speech-recognition/speech-recognition.js +77 -0
  99. package/dist/speech-recognition/speech-recognition.js.map +1 -0
  100. package/dist/speech-synthesis/index.d.ts +3 -0
  101. package/dist/speech-synthesis/speech-synthesis.cjs +33 -0
  102. package/dist/speech-synthesis/speech-synthesis.cjs.map +1 -0
  103. package/dist/speech-synthesis/speech-synthesis.d.ts +18 -0
  104. package/dist/speech-synthesis/speech-synthesis.js +34 -0
  105. package/dist/speech-synthesis/speech-synthesis.js.map +1 -0
  106. package/dist/table-cell/index.d.ts +3 -0
  107. package/dist/table-cell/table-cell.cjs +28 -0
  108. package/dist/table-cell/table-cell.cjs.map +1 -0
  109. package/dist/table-cell/table-cell.d.ts +8 -0
  110. package/dist/table-cell/table-cell.js +28 -0
  111. package/dist/table-cell/table-cell.js.map +1 -0
  112. package/dist/transform/html-to-json/html-to-json.cjs +5 -0
  113. package/dist/transform/html-to-json/html-to-json.cjs.map +1 -0
  114. package/dist/transform/html-to-json/html-to-json.d.ts +6 -0
  115. package/dist/transform/html-to-json/html-to-json.js +4 -0
  116. package/dist/transform/html-to-json/html-to-json.js.map +1 -0
  117. package/dist/transform/index.d.ts +3 -0
  118. package/dist/transform/json-to-html/json-to-html.cjs +5 -0
  119. package/dist/transform/json-to-html/json-to-html.cjs.map +1 -0
  120. package/dist/transform/json-to-html/json-to-html.d.ts +3 -0
  121. package/dist/transform/json-to-html/json-to-html.js +4 -0
  122. package/dist/transform/json-to-html/json-to-html.js.map +1 -0
  123. package/dist/video/index.d.ts +3 -0
  124. package/dist/video/video.cjs +119 -0
  125. package/dist/video/video.cjs.map +1 -0
  126. package/dist/video/video.d.ts +34 -0
  127. package/dist/video/video.js +123 -0
  128. package/dist/video/video.js.map +1 -0
  129. package/package.json +133 -0
  130. package/src/abbr/abbr.ts +57 -0
  131. package/src/abbr/index.ts +5 -0
  132. package/src/alert/alert.ts +46 -0
  133. package/src/alert/index.ts +5 -0
  134. package/src/attachment/attachment.ts +113 -0
  135. package/src/attachment/index.ts +5 -0
  136. package/src/audio/audio.ts +81 -0
  137. package/src/audio/index.ts +5 -0
  138. package/src/font-size/font-size.ts +74 -0
  139. package/src/font-size/index.ts +5 -0
  140. package/src/heading/heading.ts +90 -0
  141. package/src/heading/index.ts +5 -0
  142. package/src/highlight/highlight.ts +27 -0
  143. package/src/highlight/index.ts +5 -0
  144. package/src/hyperlink/hyperlink.ts +92 -0
  145. package/src/hyperlink/index.ts +5 -0
  146. package/src/iframe/iframe.ts +112 -0
  147. package/src/iframe/index.ts +5 -0
  148. package/src/image/custom-image.ts +226 -0
  149. package/src/image/index.ts +5 -0
  150. package/src/index.ts +19 -0
  151. package/src/line-height/index.ts +5 -0
  152. package/src/line-height/line-height.ts +37 -0
  153. package/src/linker/index.ts +5 -0
  154. package/src/linker/linker.ts +153 -0
  155. package/src/mathjax/index.ts +5 -0
  156. package/src/mathjax/mathjax.ts +55 -0
  157. package/src/paragraph/index.ts +5 -0
  158. package/src/paragraph/paragraph.ts +25 -0
  159. package/src/speech-recognition/index.ts +5 -0
  160. package/src/speech-recognition/speech-recognition.ts +123 -0
  161. package/src/speech-synthesis/index.ts +5 -0
  162. package/src/speech-synthesis/speech-synthesis.ts +52 -0
  163. package/src/table-cell/index.ts +5 -0
  164. package/src/table-cell/table-cell.ts +28 -0
  165. package/src/transform/html-to-json/html-to-json.ts +5 -0
  166. package/src/transform/index.ts +4 -0
  167. package/src/transform/json-to-html/json-to-html.ts +5 -0
  168. package/src/video/index.ts +5 -0
  169. package/src/video/video.ts +173 -0
  170. package/tsconfig.json +20 -0
  171. package/vite.config.ts +46 -0
@@ -0,0 +1,55 @@
1
+ import { Node } from '@tiptap/core';
2
+
3
+ export const MathJax = Node.create({
4
+ name: 'mathjaxnode',
5
+ group: 'inline',
6
+ inline: true,
7
+ atom: false,
8
+ selectable: true,
9
+
10
+ parseHTML() {
11
+ return [
12
+ {
13
+ tag: 'mathjax',
14
+ },
15
+ ];
16
+ },
17
+
18
+ addAttributes() {
19
+ return {
20
+ equation: {
21
+ default: null,
22
+ parseHTML: (element: any) => {
23
+ const children = [...element.childNodes];
24
+ const textNodes = children.filter((child) => child.nodeType === 3);
25
+ return textNodes.length > 0
26
+ ? textNodes[textNodes.length - 1].nodeValue
27
+ : null;
28
+ },
29
+ },
30
+ };
31
+ },
32
+
33
+ renderHTML({ HTMLAttributes }) {
34
+ let equation = (HTMLAttributes.equation || '')
35
+ // Get what is between \begin{equation}{... ...}\end{equation}
36
+ // Or between \begin{equation}... ...\end{equation} without enclosing brackets
37
+ .replaceAll(
38
+ /(?:\\)?begin{equation}\s*\n?\s*{(.+?)}\n?\s*?(?:\\)?end{equation}/gm,
39
+ '$$$1$$',
40
+ )
41
+ .replaceAll(
42
+ /(?:\\)?begin{equation}\s*\n?\s*(.+?)\n?\s*?(?:\\)?end{equation}/gm,
43
+ '$$$1$$',
44
+ );
45
+ if (equation.length > 0) {
46
+ if (equation.charAt(0) !== '$') {
47
+ equation = `$${equation}`;
48
+ }
49
+ if (equation.charAt(equation.length - 1) !== '$') {
50
+ equation = `${equation}$`;
51
+ }
52
+ }
53
+ return ['span', {}, equation];
54
+ },
55
+ });
@@ -0,0 +1,5 @@
1
+ import { Paragraph } from './paragraph';
2
+
3
+ export * from './paragraph';
4
+
5
+ export default Paragraph;
@@ -0,0 +1,25 @@
1
+ import { Paragraph as TiptapParagraph } from '@tiptap/extension-paragraph';
2
+
3
+ /**
4
+ * Extends `Paragraph` extension from TipTap.
5
+ *
6
+ * This extension is used to parse documents in old-format (version 0),
7
+ * where text alignments were applied on a <div> wrapping a <span>.
8
+ * The new format is a <p> with style attributes.
9
+ *
10
+ * For example :
11
+ * `<div style="text-align: right;"><span style="font-size: 20pt;">A right-aligned text</span></div>`
12
+ * is now parsed and rendered as
13
+ * `<p style="text-align: right;"><span style="font-size: 20pt;">A right-aligned text</span></p>`
14
+ */
15
+ export const Paragraph = TiptapParagraph.extend({
16
+ parseHTML() {
17
+ const parentRules = this.parent?.() ?? [];
18
+ return [
19
+ ...parentRules,
20
+ {
21
+ tag: 'div[style]:has(> span)',
22
+ },
23
+ ];
24
+ },
25
+ });
@@ -0,0 +1,5 @@
1
+ import { SpeechRecognition } from './speech-recognition';
2
+
3
+ export * from './speech-recognition';
4
+
5
+ export default SpeechRecognition;
@@ -0,0 +1,123 @@
1
+ import { Node } from '@tiptap/core';
2
+
3
+ export interface SpeechRecognitionOptions {
4
+ lang: string;
5
+ }
6
+
7
+ declare module '@tiptap/core' {
8
+ interface Commands<ReturnType> {
9
+ SpeechRecognition: {
10
+ startSpeechRecognition: () => ReturnType;
11
+ stopSpeechRecognition: () => ReturnType;
12
+ isSpeechRecognitionStarted: () => boolean;
13
+ };
14
+ }
15
+ }
16
+
17
+ class SR_Node<O = any, S = any> extends Node<O, S> {
18
+ protected constructor() {
19
+ super();
20
+ }
21
+
22
+ recognition: SpeechRecognition | undefined;
23
+ readonly isStarted: boolean = false;
24
+
25
+ static create<O = any, S = any>(config?: any) {
26
+ return Node.create(config) as SR_Node<O, S>;
27
+ }
28
+ }
29
+
30
+ export const SpeechRecognition = SR_Node.create<SpeechRecognitionOptions>({
31
+ name: 'SpeechRecognition',
32
+
33
+ addOptions() {
34
+ return {
35
+ lang: 'fr-FR',
36
+ };
37
+ },
38
+
39
+ onCreate() {
40
+ if (
41
+ !('SpeechRecognition' in window || 'webkitSpeechRecognition' in window)
42
+ ) {
43
+ console.warn(
44
+ '"speechrecognition extension from @edifice.io/tiptap-extensions" requires a browser supporting the SpeechRecognition API".',
45
+ );
46
+ }
47
+ },
48
+
49
+ addCommands() {
50
+ return {
51
+ startSpeechRecognition:
52
+ () =>
53
+ ({ commands }) => {
54
+ const SpeechRecognition =
55
+ window.SpeechRecognition || window.webkitSpeechRecognition;
56
+ this.recognition = new SpeechRecognition();
57
+
58
+ this.recognition.lang = this.options.lang;
59
+ this.recognition.interimResults = true;
60
+ this.recognition.maxAlternatives = 1;
61
+ this.recognition.continuous = true;
62
+
63
+ this.recognition.start();
64
+
65
+ // Memoize initial caret positions
66
+ let { from, to } = this.editor.state.selection;
67
+
68
+ this.recognition.onresult = (event: SpeechRecognitionEvent) => {
69
+ let currentResult = '';
70
+
71
+ // Add to the currentResult variable the content of the last recognized sentence
72
+ for (let i = event.resultIndex; i < event.results.length; i++) {
73
+ currentResult += event.results[i][0].transcript;
74
+ }
75
+
76
+ // Is this the final recognition ?
77
+ const isFinal = event.results[event.results.length - 1].isFinal;
78
+
79
+ // Replace selection by the last recognized sentence (+ style and select, if not final)
80
+ this.editor.commands.deleteRange({ from, to });
81
+ this.editor.commands.insertContentAt(
82
+ from,
83
+ isFinal ? currentResult : `<code>${currentResult}</code>`,
84
+ { updateSelection: !isFinal },
85
+ );
86
+ to = this.editor.state.selection.to;
87
+
88
+ if (isFinal) {
89
+ // Next content will go after last insertion
90
+ from = to;
91
+ }
92
+ };
93
+
94
+ this.recognition.onerror = (event: SpeechRecognitionErrorEvent) => {
95
+ // TODO create a "feedback" tiptap extension, to display user friendly error messages ?
96
+ console.log(
97
+ `[speechrecognition from @edifice.io/tiptap-extensions][error][${event.error}]: ${event.message}`,
98
+ );
99
+ };
100
+
101
+ this.recognition.onstart = () => {
102
+ this.isStarted = true;
103
+ };
104
+
105
+ this.recognition.onend = () => {
106
+ this.isStarted = false;
107
+ };
108
+
109
+ return commands;
110
+ },
111
+
112
+ stopSpeechRecognition:
113
+ () =>
114
+ ({ commands }) => {
115
+ this.recognition.stop();
116
+ this.editor.commands.focus();
117
+ return commands;
118
+ },
119
+
120
+ isSpeechRecognitionStarted: () => () => this.isStarted,
121
+ };
122
+ },
123
+ });
@@ -0,0 +1,5 @@
1
+ import { SpeechSynthesis } from './speech-synthesis';
2
+
3
+ export * from './speech-synthesis';
4
+
5
+ export default SpeechSynthesis;
@@ -0,0 +1,52 @@
1
+ import { Node } from '@tiptap/core';
2
+
3
+ export interface SpeechSynthesisOptions {
4
+ lang: string;
5
+ pitch: number;
6
+ }
7
+
8
+ declare module '@tiptap/core' {
9
+ interface Commands<ReturnType> {
10
+ speechSynthesis: {
11
+ startSpeechSynthesis: () => ReturnType;
12
+ stopSpeechSynthesis: () => ReturnType;
13
+ };
14
+ }
15
+ }
16
+
17
+ class SS_Node<O = any, S = any> extends Node<O, S> {
18
+ static create<O = any, S = any>(config?: any) {
19
+ return Node.create(config) as SS_Node<O, S>;
20
+ }
21
+ }
22
+
23
+ export const SpeechSynthesis = SS_Node.create<SpeechSynthesisOptions>({
24
+ name: 'speechSynthesis',
25
+ addOptions() {
26
+ return {
27
+ lang: 'fr-FR',
28
+ pitch: 1,
29
+ };
30
+ },
31
+ addCommands() {
32
+ return {
33
+ startSpeechSynthesis:
34
+ () =>
35
+ ({ commands }) => {
36
+ this.speechSynthesis = new SpeechSynthesisUtterance();
37
+ this.speechSynthesis.lang = this.options.lang;
38
+ this.speechSynthesis.pitch = this.options.pitch;
39
+ this.speechSynthesis.text = this.editor.getText();
40
+
41
+ window.speechSynthesis.speak(this.speechSynthesis);
42
+ return commands;
43
+ },
44
+ stopSpeechSynthesis:
45
+ () =>
46
+ ({ commands }) => {
47
+ window.speechSynthesis.cancel();
48
+ return commands;
49
+ },
50
+ };
51
+ },
52
+ });
@@ -0,0 +1,5 @@
1
+ import { TableCell } from './table-cell';
2
+
3
+ export * from './table-cell';
4
+
5
+ export default TableCell;
@@ -0,0 +1,28 @@
1
+ import { TableCell as TipTapTableCell } from '@tiptap/extension-table-cell';
2
+
3
+ /**
4
+ * This custom extension allows setting a background-color to table cells.
5
+ * Apply with ̀`editor.chain().focus().setCellAttribute("backgroundColor", color).run()`
6
+ */
7
+ export const TableCell = TipTapTableCell.extend({
8
+ addAttributes() {
9
+ return {
10
+ ...this.parent?.(),
11
+ backgroundColor: {
12
+ default: null,
13
+ renderHTML: (attributes: { backgroundColor?: string }) => {
14
+ if (!attributes.backgroundColor) {
15
+ return {};
16
+ }
17
+
18
+ return {
19
+ style: `background-color: ${attributes.backgroundColor}`,
20
+ };
21
+ },
22
+ parseHTML: (element: { style?: { backgroundColor: string } }) => {
23
+ return element.style?.backgroundColor?.replace(/['"]+/g, '');
24
+ },
25
+ },
26
+ };
27
+ },
28
+ });
@@ -0,0 +1,5 @@
1
+ import { Extensions, HTMLContent, generateJSON } from '@tiptap/core';
2
+
3
+ export default (html: HTMLContent, extensions: Extensions) => {
4
+ return generateJSON(html, extensions);
5
+ };
@@ -0,0 +1,4 @@
1
+ import htmlToJson from './html-to-json/html-to-json';
2
+ import jsonToHtml from './json-to-html/json-to-html';
3
+
4
+ export { htmlToJson, jsonToHtml };
@@ -0,0 +1,5 @@
1
+ import { Extensions, JSONContent, generateHTML } from '@tiptap/core';
2
+
3
+ export default (json: JSONContent, extensions: Extensions) => {
4
+ return generateHTML(json, extensions);
5
+ };
@@ -0,0 +1,5 @@
1
+ import { Video } from './video';
2
+
3
+ export * from './video';
4
+
5
+ export default Video;
@@ -0,0 +1,173 @@
1
+ import { mergeAttributes, Node, nodeInputRule } from '@tiptap/core';
2
+
3
+ export interface VideoOptions {
4
+ url: string;
5
+ width: number;
6
+ height: number;
7
+ HTMLAttributes: Record<string, any>;
8
+ }
9
+
10
+ declare module '@tiptap/core' {
11
+ interface Commands<ReturnType> {
12
+ video: {
13
+ /**
14
+ * Set a video node
15
+ * @param options.updateSelection set to true will select the newly inserted content
16
+ */
17
+ setVideo: (
18
+ id: string,
19
+ src: string,
20
+ isCaptation: boolean,
21
+ width?: number,
22
+ height?: number,
23
+ controls?: boolean,
24
+ controlslist?: string,
25
+ options?: { updateSelection: boolean },
26
+ ) => ReturnType;
27
+ /**
28
+ * Toggle a video
29
+ */
30
+ toggleVideo: (src: string) => ReturnType;
31
+ };
32
+ }
33
+ }
34
+
35
+ const VIDEO_INPUT_REGEX = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/;
36
+
37
+ export const Video = Node.create({
38
+ name: 'video',
39
+ group: 'block',
40
+ draggable: true,
41
+ selectable: true,
42
+
43
+ addAttributes() {
44
+ return {
45
+ src: {
46
+ default: null,
47
+ parseHTML: (el: any) => (el as HTMLSpanElement).getAttribute('src'),
48
+ renderHTML: (attrs: any) => ({ src: attrs.src }),
49
+ },
50
+ controls: {
51
+ default: true,
52
+ parseHTML: (el: any) => {
53
+ if ((el as HTMLSpanElement).getAttribute('controls')) {
54
+ return (el as HTMLSpanElement).getAttribute('controls');
55
+ } else if ((el as HTMLSpanElement).hasAttribute('controls')) {
56
+ return true;
57
+ } else {
58
+ return false;
59
+ }
60
+ },
61
+ renderHTML: (attrs: any) => ({ controls: attrs.controls }),
62
+ },
63
+ documentId: {
64
+ default: '',
65
+ renderHTML: (attributes: any) => {
66
+ return { 'data-document-id': attributes.documentId };
67
+ },
68
+ parseHTML: (element: any) => element.getAttribute('data-document-id'),
69
+ },
70
+ isCaptation: {
71
+ default: false,
72
+ renderHTML: (attributes: any) => {
73
+ return { 'data-document-is-captation': attributes.isCaptation };
74
+ },
75
+ parseHTML: (element: any) =>
76
+ element.getAttribute('data-document-is-captation'),
77
+ },
78
+ videoResolution: {
79
+ default: '404x720',
80
+ renderHTML: (attributes: any) => {
81
+ return { 'data-video-resolution': attributes.videoResolution };
82
+ },
83
+ parseHTML: (element: any) =>
84
+ element.getAttribute('data-video-resolution'),
85
+ },
86
+ width: {
87
+ renderHTML: (attributes: any) => {
88
+ return {
89
+ width: parseInt(attributes.width),
90
+ };
91
+ },
92
+ parseHTML: (element) => element.getAttribute('width'),
93
+ },
94
+ height: {
95
+ renderHTML: (attributes: any) => {
96
+ return {
97
+ height: parseInt(attributes.height),
98
+ };
99
+ },
100
+ parseHTML: (element) => element.getAttribute('height'),
101
+ },
102
+ };
103
+ },
104
+
105
+ parseHTML() {
106
+ return [
107
+ {
108
+ tag: 'div.video-wrapper>video,video',
109
+ getAttrs: (el: any) => ({
110
+ src: (el as HTMLVideoElement).getAttribute('src'),
111
+ }),
112
+ },
113
+ ];
114
+ },
115
+
116
+ renderHTML({ HTMLAttributes }) {
117
+ return [
118
+ 'div',
119
+ { class: 'video-wrapper' },
120
+ ['video', mergeAttributes(HTMLAttributes)],
121
+ ];
122
+ },
123
+
124
+ addCommands() {
125
+ return {
126
+ setVideo:
127
+ (
128
+ id: string,
129
+ src: string,
130
+ isCaptation: boolean,
131
+ width = 350,
132
+ height = 197,
133
+ controls = true,
134
+ controlslist = 'nodownload',
135
+ options,
136
+ ) =>
137
+ ({ commands, state }) => {
138
+ return commands.insertContentAt(
139
+ state.selection,
140
+ `<video
141
+ controls="${controls}"
142
+ controlslist="${controlslist}"
143
+ src="${src}"
144
+ width="${width}"
145
+ height="${height}"
146
+ data-document-id="${id}"
147
+ data-document-is-captation="${isCaptation}"
148
+ data-video-resolution="${width}x${height}" />`,
149
+ options,
150
+ );
151
+ },
152
+
153
+ toggleVideo:
154
+ () =>
155
+ ({ commands }) =>
156
+ commands.toggleNode(this.name, 'paragraph'),
157
+ };
158
+ },
159
+
160
+ addInputRules() {
161
+ return [
162
+ nodeInputRule({
163
+ find: VIDEO_INPUT_REGEX,
164
+ type: this.type,
165
+ getAttributes: (match) => {
166
+ const [, , src] = match;
167
+
168
+ return { src };
169
+ },
170
+ }),
171
+ ];
172
+ },
173
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2016",
4
+ "module": "ESNext",
5
+ "lib": ["ES2016", "DOM"],
6
+ "resolveJsonModule": true,
7
+ "moduleResolution": "node",
8
+ "declaration": true,
9
+ "isolatedModules": true,
10
+ "esModuleInterop": true,
11
+ "noEmit": true,
12
+ "noUnusedLocals": true,
13
+ "noUnusedParameters": false,
14
+ "noImplicitReturns": false,
15
+ "skipLibCheck": true,
16
+ "sourceMap": true
17
+ },
18
+ "exclude": ["dist", "node_modules"],
19
+ "include": ["src"]
20
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { resolve } from 'path';
2
+
3
+ import { defineConfig } from 'vite';
4
+ import dts from 'vite-plugin-dts';
5
+
6
+ import { dependencies } from './package.json';
7
+
8
+ export default defineConfig({
9
+ esbuild: {
10
+ minifyIdentifiers: false,
11
+ },
12
+ build: {
13
+ sourcemap: true,
14
+ lib: {
15
+ entry: {
16
+ index: resolve(__dirname, 'src/index.ts'),
17
+ },
18
+ formats: ['es', 'cjs'],
19
+ },
20
+ rollupOptions: {
21
+ output: [
22
+ {
23
+ preserveModules: true,
24
+ preserveModulesRoot: 'src',
25
+ entryFileNames: ({ name: fileName }) => {
26
+ return `${fileName}.js`;
27
+ },
28
+ },
29
+ {
30
+ preserveModules: true,
31
+ preserveModulesRoot: 'src',
32
+ format: 'cjs',
33
+ entryFileNames: ({ name: fileName }) => {
34
+ return `${fileName}.cjs`;
35
+ },
36
+ },
37
+ ],
38
+ external: [...Object.keys(dependencies)],
39
+ },
40
+ },
41
+ plugins: [
42
+ dts({
43
+ tsconfigPath: './tsconfig.json',
44
+ }),
45
+ ],
46
+ });