@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.
- package/.turbo/turbo-build.log +58 -0
- package/.turbo/turbo-format.log +142 -0
- package/.turbo/turbo-lint.log +5 -0
- package/LICENSE +661 -0
- package/dist/abbr/abbr.cjs +33 -0
- package/dist/abbr/abbr.cjs.map +1 -0
- package/dist/abbr/abbr.d.ts +16 -0
- package/dist/abbr/abbr.js +37 -0
- package/dist/abbr/abbr.js.map +1 -0
- package/dist/abbr/index.d.ts +3 -0
- package/dist/alert/alert.cjs +33 -0
- package/dist/alert/alert.cjs.map +1 -0
- package/dist/alert/alert.d.ts +2 -0
- package/dist/alert/alert.js +43 -0
- package/dist/alert/alert.js.map +1 -0
- package/dist/alert/index.d.ts +3 -0
- package/dist/attachment/attachment.cjs +74 -0
- package/dist/attachment/attachment.cjs.map +1 -0
- package/dist/attachment/attachment.d.ts +12 -0
- package/dist/attachment/attachment.js +86 -0
- package/dist/attachment/attachment.js.map +1 -0
- package/dist/attachment/index.d.ts +3 -0
- package/dist/audio/audio.cjs +55 -0
- package/dist/audio/audio.cjs.map +1 -0
- package/dist/audio/audio.d.ts +23 -0
- package/dist/audio/audio.js +55 -0
- package/dist/audio/audio.js.map +1 -0
- package/dist/audio/index.d.ts +3 -0
- package/dist/font-size/font-size.cjs +49 -0
- package/dist/font-size/font-size.cjs.map +1 -0
- package/dist/font-size/font-size.d.ts +19 -0
- package/dist/font-size/font-size.js +51 -0
- package/dist/font-size/font-size.js.map +1 -0
- package/dist/font-size/index.d.ts +3 -0
- package/dist/heading/heading.cjs +62 -0
- package/dist/heading/heading.cjs.map +1 -0
- package/dist/heading/heading.d.ts +17 -0
- package/dist/heading/heading.js +60 -0
- package/dist/heading/heading.js.map +1 -0
- package/dist/heading/index.d.ts +3 -0
- package/dist/highlight/highlight.cjs +26 -0
- package/dist/highlight/highlight.cjs.map +1 -0
- package/dist/highlight/highlight.d.ts +4 -0
- package/dist/highlight/highlight.js +26 -0
- package/dist/highlight/highlight.js.map +1 -0
- package/dist/highlight/index.d.ts +3 -0
- package/dist/hyperlink/hyperlink.cjs +48 -0
- package/dist/hyperlink/hyperlink.cjs.map +1 -0
- package/dist/hyperlink/hyperlink.d.ts +38 -0
- package/dist/hyperlink/hyperlink.js +55 -0
- package/dist/hyperlink/hyperlink.js.map +1 -0
- package/dist/hyperlink/index.d.ts +3 -0
- package/dist/iframe/iframe.cjs +70 -0
- package/dist/iframe/iframe.cjs.map +1 -0
- package/dist/iframe/iframe.d.ts +18 -0
- package/dist/iframe/iframe.js +85 -0
- package/dist/iframe/iframe.js.map +1 -0
- package/dist/iframe/index.d.ts +3 -0
- package/dist/image/custom-image.cjs +163 -0
- package/dist/image/custom-image.cjs.map +1 -0
- package/dist/image/custom-image.d.ts +27 -0
- package/dist/image/custom-image.js +181 -0
- package/dist/image/custom-image.js.map +1 -0
- package/dist/image/index.d.ts +3 -0
- package/dist/index.cjs +44 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/line-height/index.d.ts +3 -0
- package/dist/line-height/line-height.cjs +34 -0
- package/dist/line-height/line-height.cjs.map +1 -0
- package/dist/line-height/line-height.d.ts +2 -0
- package/dist/line-height/line-height.js +36 -0
- package/dist/line-height/line-height.js.map +1 -0
- package/dist/linker/index.d.ts +3 -0
- package/dist/linker/linker.cjs +96 -0
- package/dist/linker/linker.cjs.map +1 -0
- package/dist/linker/linker.d.ts +30 -0
- package/dist/linker/linker.js +104 -0
- package/dist/linker/linker.js.map +1 -0
- package/dist/mathjax/index.d.ts +3 -0
- package/dist/mathjax/mathjax.cjs +48 -0
- package/dist/mathjax/mathjax.cjs.map +1 -0
- package/dist/mathjax/mathjax.d.ts +2 -0
- package/dist/mathjax/mathjax.js +50 -0
- package/dist/mathjax/mathjax.js.map +1 -0
- package/dist/paragraph/index.d.ts +3 -0
- package/dist/paragraph/paragraph.cjs +14 -0
- package/dist/paragraph/paragraph.cjs.map +1 -0
- package/dist/paragraph/paragraph.d.ts +16 -0
- package/dist/paragraph/paragraph.js +14 -0
- package/dist/paragraph/paragraph.js.map +1 -0
- package/dist/speech-recognition/index.d.ts +3 -0
- package/dist/speech-recognition/speech-recognition.cjs +77 -0
- package/dist/speech-recognition/speech-recognition.cjs.map +1 -0
- package/dist/speech-recognition/speech-recognition.d.ts +21 -0
- package/dist/speech-recognition/speech-recognition.js +77 -0
- package/dist/speech-recognition/speech-recognition.js.map +1 -0
- package/dist/speech-synthesis/index.d.ts +3 -0
- package/dist/speech-synthesis/speech-synthesis.cjs +33 -0
- package/dist/speech-synthesis/speech-synthesis.cjs.map +1 -0
- package/dist/speech-synthesis/speech-synthesis.d.ts +18 -0
- package/dist/speech-synthesis/speech-synthesis.js +34 -0
- package/dist/speech-synthesis/speech-synthesis.js.map +1 -0
- package/dist/table-cell/index.d.ts +3 -0
- package/dist/table-cell/table-cell.cjs +28 -0
- package/dist/table-cell/table-cell.cjs.map +1 -0
- package/dist/table-cell/table-cell.d.ts +8 -0
- package/dist/table-cell/table-cell.js +28 -0
- package/dist/table-cell/table-cell.js.map +1 -0
- package/dist/transform/html-to-json/html-to-json.cjs +5 -0
- package/dist/transform/html-to-json/html-to-json.cjs.map +1 -0
- package/dist/transform/html-to-json/html-to-json.d.ts +6 -0
- package/dist/transform/html-to-json/html-to-json.js +4 -0
- package/dist/transform/html-to-json/html-to-json.js.map +1 -0
- package/dist/transform/index.d.ts +3 -0
- package/dist/transform/json-to-html/json-to-html.cjs +5 -0
- package/dist/transform/json-to-html/json-to-html.cjs.map +1 -0
- package/dist/transform/json-to-html/json-to-html.d.ts +3 -0
- package/dist/transform/json-to-html/json-to-html.js +4 -0
- package/dist/transform/json-to-html/json-to-html.js.map +1 -0
- package/dist/video/index.d.ts +3 -0
- package/dist/video/video.cjs +119 -0
- package/dist/video/video.cjs.map +1 -0
- package/dist/video/video.d.ts +34 -0
- package/dist/video/video.js +123 -0
- package/dist/video/video.js.map +1 -0
- package/package.json +133 -0
- package/src/abbr/abbr.ts +57 -0
- package/src/abbr/index.ts +5 -0
- package/src/alert/alert.ts +46 -0
- package/src/alert/index.ts +5 -0
- package/src/attachment/attachment.ts +113 -0
- package/src/attachment/index.ts +5 -0
- package/src/audio/audio.ts +81 -0
- package/src/audio/index.ts +5 -0
- package/src/font-size/font-size.ts +74 -0
- package/src/font-size/index.ts +5 -0
- package/src/heading/heading.ts +90 -0
- package/src/heading/index.ts +5 -0
- package/src/highlight/highlight.ts +27 -0
- package/src/highlight/index.ts +5 -0
- package/src/hyperlink/hyperlink.ts +92 -0
- package/src/hyperlink/index.ts +5 -0
- package/src/iframe/iframe.ts +112 -0
- package/src/iframe/index.ts +5 -0
- package/src/image/custom-image.ts +226 -0
- package/src/image/index.ts +5 -0
- package/src/index.ts +19 -0
- package/src/line-height/index.ts +5 -0
- package/src/line-height/line-height.ts +37 -0
- package/src/linker/index.ts +5 -0
- package/src/linker/linker.ts +153 -0
- package/src/mathjax/index.ts +5 -0
- package/src/mathjax/mathjax.ts +55 -0
- package/src/paragraph/index.ts +5 -0
- package/src/paragraph/paragraph.ts +25 -0
- package/src/speech-recognition/index.ts +5 -0
- package/src/speech-recognition/speech-recognition.ts +123 -0
- package/src/speech-synthesis/index.ts +5 -0
- package/src/speech-synthesis/speech-synthesis.ts +52 -0
- package/src/table-cell/index.ts +5 -0
- package/src/table-cell/table-cell.ts +28 -0
- package/src/transform/html-to-json/html-to-json.ts +5 -0
- package/src/transform/index.ts +4 -0
- package/src/transform/json-to-html/json-to-html.ts +5 -0
- package/src/video/index.ts +5 -0
- package/src/video/video.ts +173 -0
- package/tsconfig.json +20 -0
- 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,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,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,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,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,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
|
+
});
|