@tiptap/extension-youtube 2.0.0-beta.209 → 2.0.0-beta.210
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/dist/index.cjs +249 -0
- package/dist/{packages/extension-youtube/src/youtube.d.ts → index.d.ts} +43 -40
- package/dist/index.js +249 -0
- package/package.json +23 -10
- package/dist/packages/extension-youtube/src/index.d.ts +0 -3
- package/dist/packages/extension-youtube/src/utils.d.ts +0 -25
- package/dist/tiptap-extension-youtube.cjs +0 -226
- package/dist/tiptap-extension-youtube.cjs.map +0 -1
- package/dist/tiptap-extension-youtube.esm.js +0 -221
- package/dist/tiptap-extension-youtube.esm.js.map +0 -1
- package/dist/tiptap-extension-youtube.umd.js +0 -230
- package/dist/tiptap-extension-youtube.umd.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/youtube.ts
|
|
2
|
+
var _core = require('@tiptap/core');
|
|
3
|
+
|
|
4
|
+
// src/utils.ts
|
|
5
|
+
var YOUTUBE_REGEX = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be)(.+)?$/;
|
|
6
|
+
var YOUTUBE_REGEX_GLOBAL = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be)(.+)?$/g;
|
|
7
|
+
var isValidYoutubeUrl = (url) => {
|
|
8
|
+
return url.match(YOUTUBE_REGEX);
|
|
9
|
+
};
|
|
10
|
+
var getYoutubeEmbedUrl = (nocookie) => {
|
|
11
|
+
return nocookie ? "https://www.youtube-nocookie.com/embed/" : "https://www.youtube.com/embed/";
|
|
12
|
+
};
|
|
13
|
+
var getEmbedUrlFromYoutubeUrl = (options) => {
|
|
14
|
+
const {
|
|
15
|
+
url,
|
|
16
|
+
allowFullscreen,
|
|
17
|
+
autoplay,
|
|
18
|
+
ccLanguage,
|
|
19
|
+
ccLoadPolicy,
|
|
20
|
+
controls,
|
|
21
|
+
disableKBcontrols,
|
|
22
|
+
enableIFrameApi,
|
|
23
|
+
endTime,
|
|
24
|
+
interfaceLanguage,
|
|
25
|
+
ivLoadPolicy,
|
|
26
|
+
loop,
|
|
27
|
+
modestBranding,
|
|
28
|
+
nocookie,
|
|
29
|
+
origin,
|
|
30
|
+
playlist,
|
|
31
|
+
progressBarColor,
|
|
32
|
+
startAt
|
|
33
|
+
} = options;
|
|
34
|
+
if (url.includes("/embed/")) {
|
|
35
|
+
return url;
|
|
36
|
+
}
|
|
37
|
+
if (url.includes("youtu.be")) {
|
|
38
|
+
const id = url.split("/").pop();
|
|
39
|
+
if (!id) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return `${getYoutubeEmbedUrl(nocookie)}${id}`;
|
|
43
|
+
}
|
|
44
|
+
const videoIdRegex = /v=([-\w]+)/gm;
|
|
45
|
+
const matches = videoIdRegex.exec(url);
|
|
46
|
+
if (!matches || !matches[1]) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`;
|
|
50
|
+
const params = [];
|
|
51
|
+
if (allowFullscreen === false) {
|
|
52
|
+
params.push("fs=0");
|
|
53
|
+
}
|
|
54
|
+
if (autoplay) {
|
|
55
|
+
params.push("autoplay=1");
|
|
56
|
+
}
|
|
57
|
+
if (ccLanguage) {
|
|
58
|
+
params.push(`cc_lang_pref=${ccLanguage}`);
|
|
59
|
+
}
|
|
60
|
+
if (ccLoadPolicy) {
|
|
61
|
+
params.push("cc_load_policy=1");
|
|
62
|
+
}
|
|
63
|
+
if (!controls) {
|
|
64
|
+
params.push("controls=0");
|
|
65
|
+
}
|
|
66
|
+
if (disableKBcontrols) {
|
|
67
|
+
params.push("disablekb=1");
|
|
68
|
+
}
|
|
69
|
+
if (enableIFrameApi) {
|
|
70
|
+
params.push("enablejsapi=1");
|
|
71
|
+
}
|
|
72
|
+
if (endTime) {
|
|
73
|
+
params.push(`end=${endTime}`);
|
|
74
|
+
}
|
|
75
|
+
if (interfaceLanguage) {
|
|
76
|
+
params.push(`hl=${interfaceLanguage}`);
|
|
77
|
+
}
|
|
78
|
+
if (ivLoadPolicy) {
|
|
79
|
+
params.push(`iv_load_policy=${ivLoadPolicy}`);
|
|
80
|
+
}
|
|
81
|
+
if (loop) {
|
|
82
|
+
params.push("loop=1");
|
|
83
|
+
}
|
|
84
|
+
if (modestBranding) {
|
|
85
|
+
params.push("modestbranding=1");
|
|
86
|
+
}
|
|
87
|
+
if (origin) {
|
|
88
|
+
params.push(`origin=${origin}`);
|
|
89
|
+
}
|
|
90
|
+
if (playlist) {
|
|
91
|
+
params.push(`playlist=${playlist}`);
|
|
92
|
+
}
|
|
93
|
+
if (startAt) {
|
|
94
|
+
params.push(`start=${startAt}`);
|
|
95
|
+
}
|
|
96
|
+
if (progressBarColor) {
|
|
97
|
+
params.push(`color=${progressBarColor}`);
|
|
98
|
+
}
|
|
99
|
+
if (params.length) {
|
|
100
|
+
outputUrl += `?${params.join("&")}`;
|
|
101
|
+
}
|
|
102
|
+
return outputUrl;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/youtube.ts
|
|
106
|
+
var Youtube = _core.Node.create({
|
|
107
|
+
name: "youtube",
|
|
108
|
+
addOptions() {
|
|
109
|
+
return {
|
|
110
|
+
addPasteHandler: true,
|
|
111
|
+
allowFullscreen: true,
|
|
112
|
+
autoplay: false,
|
|
113
|
+
ccLanguage: void 0,
|
|
114
|
+
ccLoadPolicy: void 0,
|
|
115
|
+
controls: true,
|
|
116
|
+
disableKBcontrols: false,
|
|
117
|
+
enableIFrameApi: false,
|
|
118
|
+
endTime: 0,
|
|
119
|
+
height: 480,
|
|
120
|
+
interfaceLanguage: void 0,
|
|
121
|
+
ivLoadPolicy: 0,
|
|
122
|
+
loop: false,
|
|
123
|
+
modestBranding: false,
|
|
124
|
+
HTMLAttributes: {},
|
|
125
|
+
inline: false,
|
|
126
|
+
nocookie: false,
|
|
127
|
+
origin: "",
|
|
128
|
+
playlist: "",
|
|
129
|
+
progressBarColor: void 0,
|
|
130
|
+
width: 640
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
inline() {
|
|
134
|
+
return this.options.inline;
|
|
135
|
+
},
|
|
136
|
+
group() {
|
|
137
|
+
return this.options.inline ? "inline" : "block";
|
|
138
|
+
},
|
|
139
|
+
draggable: true,
|
|
140
|
+
addAttributes() {
|
|
141
|
+
return {
|
|
142
|
+
src: {
|
|
143
|
+
default: null
|
|
144
|
+
},
|
|
145
|
+
start: {
|
|
146
|
+
default: 0
|
|
147
|
+
},
|
|
148
|
+
width: {
|
|
149
|
+
default: this.options.width
|
|
150
|
+
},
|
|
151
|
+
height: {
|
|
152
|
+
default: this.options.height
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
parseHTML() {
|
|
157
|
+
return [
|
|
158
|
+
{
|
|
159
|
+
tag: "div[data-youtube-video] iframe"
|
|
160
|
+
}
|
|
161
|
+
];
|
|
162
|
+
},
|
|
163
|
+
addCommands() {
|
|
164
|
+
return {
|
|
165
|
+
setYoutubeVideo: (options) => ({ commands }) => {
|
|
166
|
+
if (!isValidYoutubeUrl(options.src)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
return commands.insertContent({
|
|
170
|
+
type: this.name,
|
|
171
|
+
attrs: options
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
addPasteRules() {
|
|
177
|
+
if (!this.options.addPasteHandler) {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
return [
|
|
181
|
+
_core.nodePasteRule.call(void 0, {
|
|
182
|
+
find: YOUTUBE_REGEX_GLOBAL,
|
|
183
|
+
type: this.type,
|
|
184
|
+
getAttributes: (match) => {
|
|
185
|
+
return { src: match.input };
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
];
|
|
189
|
+
},
|
|
190
|
+
renderHTML({ HTMLAttributes }) {
|
|
191
|
+
const embedUrl = getEmbedUrlFromYoutubeUrl({
|
|
192
|
+
url: HTMLAttributes.src,
|
|
193
|
+
allowFullscreen: this.options.allowFullscreen,
|
|
194
|
+
autoplay: this.options.autoplay,
|
|
195
|
+
ccLanguage: this.options.ccLanguage,
|
|
196
|
+
ccLoadPolicy: this.options.ccLoadPolicy,
|
|
197
|
+
controls: this.options.controls,
|
|
198
|
+
disableKBcontrols: this.options.disableKBcontrols,
|
|
199
|
+
enableIFrameApi: this.options.enableIFrameApi,
|
|
200
|
+
endTime: this.options.endTime,
|
|
201
|
+
interfaceLanguage: this.options.interfaceLanguage,
|
|
202
|
+
ivLoadPolicy: this.options.ivLoadPolicy,
|
|
203
|
+
loop: this.options.loop,
|
|
204
|
+
modestBranding: this.options.modestBranding,
|
|
205
|
+
nocookie: this.options.nocookie,
|
|
206
|
+
origin: this.options.origin,
|
|
207
|
+
playlist: this.options.playlist,
|
|
208
|
+
progressBarColor: this.options.progressBarColor,
|
|
209
|
+
startAt: HTMLAttributes.start || 0
|
|
210
|
+
});
|
|
211
|
+
HTMLAttributes.src = embedUrl;
|
|
212
|
+
return [
|
|
213
|
+
"div",
|
|
214
|
+
{ "data-youtube-video": "" },
|
|
215
|
+
[
|
|
216
|
+
"iframe",
|
|
217
|
+
_core.mergeAttributes.call(void 0,
|
|
218
|
+
this.options.HTMLAttributes,
|
|
219
|
+
{
|
|
220
|
+
width: this.options.width,
|
|
221
|
+
height: this.options.height,
|
|
222
|
+
allowfullscreen: this.options.allowFullscreen,
|
|
223
|
+
autoplay: this.options.autoplay,
|
|
224
|
+
ccLanguage: this.options.ccLanguage,
|
|
225
|
+
ccLoadPolicy: this.options.ccLoadPolicy,
|
|
226
|
+
disableKBcontrols: this.options.disableKBcontrols,
|
|
227
|
+
enableIFrameApi: this.options.enableIFrameApi,
|
|
228
|
+
endTime: this.options.endTime,
|
|
229
|
+
interfaceLanguage: this.options.interfaceLanguage,
|
|
230
|
+
ivLoadPolicy: this.options.ivLoadPolicy,
|
|
231
|
+
loop: this.options.loop,
|
|
232
|
+
modestBranding: this.options.modestBranding,
|
|
233
|
+
origin: this.options.origin,
|
|
234
|
+
playlist: this.options.playlist,
|
|
235
|
+
progressBarColor: this.options.progressBarColor
|
|
236
|
+
},
|
|
237
|
+
HTMLAttributes
|
|
238
|
+
)
|
|
239
|
+
]
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// src/index.ts
|
|
245
|
+
var src_default = Youtube;
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
exports.Youtube = Youtube; exports.default = src_default;
|
|
@@ -1,40 +1,43 @@
|
|
|
1
|
-
import { Node } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
interface YoutubeOptions {
|
|
4
|
+
addPasteHandler: boolean;
|
|
5
|
+
allowFullscreen: boolean;
|
|
6
|
+
autoplay: boolean;
|
|
7
|
+
ccLanguage?: string;
|
|
8
|
+
ccLoadPolicy?: boolean;
|
|
9
|
+
controls: boolean;
|
|
10
|
+
disableKBcontrols: boolean;
|
|
11
|
+
enableIFrameApi: boolean;
|
|
12
|
+
endTime: number;
|
|
13
|
+
height: number;
|
|
14
|
+
interfaceLanguage?: string;
|
|
15
|
+
ivLoadPolicy: number;
|
|
16
|
+
loop: boolean;
|
|
17
|
+
modestBranding: boolean;
|
|
18
|
+
HTMLAttributes: Record<string, any>;
|
|
19
|
+
inline: boolean;
|
|
20
|
+
nocookie: boolean;
|
|
21
|
+
origin: string;
|
|
22
|
+
playlist: string;
|
|
23
|
+
progressBarColor?: string;
|
|
24
|
+
width: number;
|
|
25
|
+
}
|
|
26
|
+
declare module '@tiptap/core' {
|
|
27
|
+
interface Commands<ReturnType> {
|
|
28
|
+
youtube: {
|
|
29
|
+
/**
|
|
30
|
+
* Insert a youtube video
|
|
31
|
+
*/
|
|
32
|
+
setYoutubeVideo: (options: {
|
|
33
|
+
src: string;
|
|
34
|
+
width?: number;
|
|
35
|
+
height?: number;
|
|
36
|
+
start?: number;
|
|
37
|
+
}) => ReturnType;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
declare const Youtube: Node<YoutubeOptions, any>;
|
|
42
|
+
|
|
43
|
+
export { Youtube, YoutubeOptions, Youtube as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// src/youtube.ts
|
|
2
|
+
import { mergeAttributes, Node, nodePasteRule } from "@tiptap/core";
|
|
3
|
+
|
|
4
|
+
// src/utils.ts
|
|
5
|
+
var YOUTUBE_REGEX = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be)(.+)?$/;
|
|
6
|
+
var YOUTUBE_REGEX_GLOBAL = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be)(.+)?$/g;
|
|
7
|
+
var isValidYoutubeUrl = (url) => {
|
|
8
|
+
return url.match(YOUTUBE_REGEX);
|
|
9
|
+
};
|
|
10
|
+
var getYoutubeEmbedUrl = (nocookie) => {
|
|
11
|
+
return nocookie ? "https://www.youtube-nocookie.com/embed/" : "https://www.youtube.com/embed/";
|
|
12
|
+
};
|
|
13
|
+
var getEmbedUrlFromYoutubeUrl = (options) => {
|
|
14
|
+
const {
|
|
15
|
+
url,
|
|
16
|
+
allowFullscreen,
|
|
17
|
+
autoplay,
|
|
18
|
+
ccLanguage,
|
|
19
|
+
ccLoadPolicy,
|
|
20
|
+
controls,
|
|
21
|
+
disableKBcontrols,
|
|
22
|
+
enableIFrameApi,
|
|
23
|
+
endTime,
|
|
24
|
+
interfaceLanguage,
|
|
25
|
+
ivLoadPolicy,
|
|
26
|
+
loop,
|
|
27
|
+
modestBranding,
|
|
28
|
+
nocookie,
|
|
29
|
+
origin,
|
|
30
|
+
playlist,
|
|
31
|
+
progressBarColor,
|
|
32
|
+
startAt
|
|
33
|
+
} = options;
|
|
34
|
+
if (url.includes("/embed/")) {
|
|
35
|
+
return url;
|
|
36
|
+
}
|
|
37
|
+
if (url.includes("youtu.be")) {
|
|
38
|
+
const id = url.split("/").pop();
|
|
39
|
+
if (!id) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return `${getYoutubeEmbedUrl(nocookie)}${id}`;
|
|
43
|
+
}
|
|
44
|
+
const videoIdRegex = /v=([-\w]+)/gm;
|
|
45
|
+
const matches = videoIdRegex.exec(url);
|
|
46
|
+
if (!matches || !matches[1]) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`;
|
|
50
|
+
const params = [];
|
|
51
|
+
if (allowFullscreen === false) {
|
|
52
|
+
params.push("fs=0");
|
|
53
|
+
}
|
|
54
|
+
if (autoplay) {
|
|
55
|
+
params.push("autoplay=1");
|
|
56
|
+
}
|
|
57
|
+
if (ccLanguage) {
|
|
58
|
+
params.push(`cc_lang_pref=${ccLanguage}`);
|
|
59
|
+
}
|
|
60
|
+
if (ccLoadPolicy) {
|
|
61
|
+
params.push("cc_load_policy=1");
|
|
62
|
+
}
|
|
63
|
+
if (!controls) {
|
|
64
|
+
params.push("controls=0");
|
|
65
|
+
}
|
|
66
|
+
if (disableKBcontrols) {
|
|
67
|
+
params.push("disablekb=1");
|
|
68
|
+
}
|
|
69
|
+
if (enableIFrameApi) {
|
|
70
|
+
params.push("enablejsapi=1");
|
|
71
|
+
}
|
|
72
|
+
if (endTime) {
|
|
73
|
+
params.push(`end=${endTime}`);
|
|
74
|
+
}
|
|
75
|
+
if (interfaceLanguage) {
|
|
76
|
+
params.push(`hl=${interfaceLanguage}`);
|
|
77
|
+
}
|
|
78
|
+
if (ivLoadPolicy) {
|
|
79
|
+
params.push(`iv_load_policy=${ivLoadPolicy}`);
|
|
80
|
+
}
|
|
81
|
+
if (loop) {
|
|
82
|
+
params.push("loop=1");
|
|
83
|
+
}
|
|
84
|
+
if (modestBranding) {
|
|
85
|
+
params.push("modestbranding=1");
|
|
86
|
+
}
|
|
87
|
+
if (origin) {
|
|
88
|
+
params.push(`origin=${origin}`);
|
|
89
|
+
}
|
|
90
|
+
if (playlist) {
|
|
91
|
+
params.push(`playlist=${playlist}`);
|
|
92
|
+
}
|
|
93
|
+
if (startAt) {
|
|
94
|
+
params.push(`start=${startAt}`);
|
|
95
|
+
}
|
|
96
|
+
if (progressBarColor) {
|
|
97
|
+
params.push(`color=${progressBarColor}`);
|
|
98
|
+
}
|
|
99
|
+
if (params.length) {
|
|
100
|
+
outputUrl += `?${params.join("&")}`;
|
|
101
|
+
}
|
|
102
|
+
return outputUrl;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/youtube.ts
|
|
106
|
+
var Youtube = Node.create({
|
|
107
|
+
name: "youtube",
|
|
108
|
+
addOptions() {
|
|
109
|
+
return {
|
|
110
|
+
addPasteHandler: true,
|
|
111
|
+
allowFullscreen: true,
|
|
112
|
+
autoplay: false,
|
|
113
|
+
ccLanguage: void 0,
|
|
114
|
+
ccLoadPolicy: void 0,
|
|
115
|
+
controls: true,
|
|
116
|
+
disableKBcontrols: false,
|
|
117
|
+
enableIFrameApi: false,
|
|
118
|
+
endTime: 0,
|
|
119
|
+
height: 480,
|
|
120
|
+
interfaceLanguage: void 0,
|
|
121
|
+
ivLoadPolicy: 0,
|
|
122
|
+
loop: false,
|
|
123
|
+
modestBranding: false,
|
|
124
|
+
HTMLAttributes: {},
|
|
125
|
+
inline: false,
|
|
126
|
+
nocookie: false,
|
|
127
|
+
origin: "",
|
|
128
|
+
playlist: "",
|
|
129
|
+
progressBarColor: void 0,
|
|
130
|
+
width: 640
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
inline() {
|
|
134
|
+
return this.options.inline;
|
|
135
|
+
},
|
|
136
|
+
group() {
|
|
137
|
+
return this.options.inline ? "inline" : "block";
|
|
138
|
+
},
|
|
139
|
+
draggable: true,
|
|
140
|
+
addAttributes() {
|
|
141
|
+
return {
|
|
142
|
+
src: {
|
|
143
|
+
default: null
|
|
144
|
+
},
|
|
145
|
+
start: {
|
|
146
|
+
default: 0
|
|
147
|
+
},
|
|
148
|
+
width: {
|
|
149
|
+
default: this.options.width
|
|
150
|
+
},
|
|
151
|
+
height: {
|
|
152
|
+
default: this.options.height
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
parseHTML() {
|
|
157
|
+
return [
|
|
158
|
+
{
|
|
159
|
+
tag: "div[data-youtube-video] iframe"
|
|
160
|
+
}
|
|
161
|
+
];
|
|
162
|
+
},
|
|
163
|
+
addCommands() {
|
|
164
|
+
return {
|
|
165
|
+
setYoutubeVideo: (options) => ({ commands }) => {
|
|
166
|
+
if (!isValidYoutubeUrl(options.src)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
return commands.insertContent({
|
|
170
|
+
type: this.name,
|
|
171
|
+
attrs: options
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
addPasteRules() {
|
|
177
|
+
if (!this.options.addPasteHandler) {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
return [
|
|
181
|
+
nodePasteRule({
|
|
182
|
+
find: YOUTUBE_REGEX_GLOBAL,
|
|
183
|
+
type: this.type,
|
|
184
|
+
getAttributes: (match) => {
|
|
185
|
+
return { src: match.input };
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
];
|
|
189
|
+
},
|
|
190
|
+
renderHTML({ HTMLAttributes }) {
|
|
191
|
+
const embedUrl = getEmbedUrlFromYoutubeUrl({
|
|
192
|
+
url: HTMLAttributes.src,
|
|
193
|
+
allowFullscreen: this.options.allowFullscreen,
|
|
194
|
+
autoplay: this.options.autoplay,
|
|
195
|
+
ccLanguage: this.options.ccLanguage,
|
|
196
|
+
ccLoadPolicy: this.options.ccLoadPolicy,
|
|
197
|
+
controls: this.options.controls,
|
|
198
|
+
disableKBcontrols: this.options.disableKBcontrols,
|
|
199
|
+
enableIFrameApi: this.options.enableIFrameApi,
|
|
200
|
+
endTime: this.options.endTime,
|
|
201
|
+
interfaceLanguage: this.options.interfaceLanguage,
|
|
202
|
+
ivLoadPolicy: this.options.ivLoadPolicy,
|
|
203
|
+
loop: this.options.loop,
|
|
204
|
+
modestBranding: this.options.modestBranding,
|
|
205
|
+
nocookie: this.options.nocookie,
|
|
206
|
+
origin: this.options.origin,
|
|
207
|
+
playlist: this.options.playlist,
|
|
208
|
+
progressBarColor: this.options.progressBarColor,
|
|
209
|
+
startAt: HTMLAttributes.start || 0
|
|
210
|
+
});
|
|
211
|
+
HTMLAttributes.src = embedUrl;
|
|
212
|
+
return [
|
|
213
|
+
"div",
|
|
214
|
+
{ "data-youtube-video": "" },
|
|
215
|
+
[
|
|
216
|
+
"iframe",
|
|
217
|
+
mergeAttributes(
|
|
218
|
+
this.options.HTMLAttributes,
|
|
219
|
+
{
|
|
220
|
+
width: this.options.width,
|
|
221
|
+
height: this.options.height,
|
|
222
|
+
allowfullscreen: this.options.allowFullscreen,
|
|
223
|
+
autoplay: this.options.autoplay,
|
|
224
|
+
ccLanguage: this.options.ccLanguage,
|
|
225
|
+
ccLoadPolicy: this.options.ccLoadPolicy,
|
|
226
|
+
disableKBcontrols: this.options.disableKBcontrols,
|
|
227
|
+
enableIFrameApi: this.options.enableIFrameApi,
|
|
228
|
+
endTime: this.options.endTime,
|
|
229
|
+
interfaceLanguage: this.options.interfaceLanguage,
|
|
230
|
+
ivLoadPolicy: this.options.ivLoadPolicy,
|
|
231
|
+
loop: this.options.loop,
|
|
232
|
+
modestBranding: this.options.modestBranding,
|
|
233
|
+
origin: this.options.origin,
|
|
234
|
+
playlist: this.options.playlist,
|
|
235
|
+
progressBarColor: this.options.progressBarColor
|
|
236
|
+
},
|
|
237
|
+
HTMLAttributes
|
|
238
|
+
)
|
|
239
|
+
]
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// src/index.ts
|
|
245
|
+
var src_default = Youtube;
|
|
246
|
+
export {
|
|
247
|
+
Youtube,
|
|
248
|
+
src_default as default
|
|
249
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-youtube",
|
|
3
3
|
"description": "a youtube embed extension for tiptap",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.210",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -15,28 +15,41 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/
|
|
20
|
-
"require": "./dist/
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
|
-
"main": "dist/
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"types": "dist/packages/extension-youtube/src/index.d.ts",
|
|
23
|
+
"main": "dist/index.cjs",
|
|
24
|
+
"module": "dist/index.js",
|
|
25
|
+
"types": "dist/index.d.ts",
|
|
27
26
|
"files": [
|
|
28
27
|
"src",
|
|
29
28
|
"dist"
|
|
30
29
|
],
|
|
31
30
|
"peerDependencies": {
|
|
32
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
31
|
+
"@tiptap/core": "^2.0.0-beta.209"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
34
|
+
"@tiptap/core": "^2.0.0-beta.210"
|
|
36
35
|
},
|
|
37
36
|
"repository": {
|
|
38
37
|
"type": "git",
|
|
39
38
|
"url": "https://github.com/ueberdosis/tiptap",
|
|
40
39
|
"directory": "packages/extension-youtube"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup"
|
|
43
|
+
},
|
|
44
|
+
"tsup": {
|
|
45
|
+
"entry": [
|
|
46
|
+
"src/index.ts"
|
|
47
|
+
],
|
|
48
|
+
"dts": true,
|
|
49
|
+
"splitting": true,
|
|
50
|
+
"format": [
|
|
51
|
+
"esm",
|
|
52
|
+
"cjs"
|
|
53
|
+
]
|
|
41
54
|
}
|
|
42
55
|
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export declare const YOUTUBE_REGEX: RegExp;
|
|
2
|
-
export declare const YOUTUBE_REGEX_GLOBAL: RegExp;
|
|
3
|
-
export declare const isValidYoutubeUrl: (url: string) => RegExpMatchArray | null;
|
|
4
|
-
export interface GetEmbedUrlOptions {
|
|
5
|
-
url: string;
|
|
6
|
-
allowFullscreen?: boolean;
|
|
7
|
-
autoplay?: boolean;
|
|
8
|
-
ccLanguage?: string;
|
|
9
|
-
ccLoadPolicy?: boolean;
|
|
10
|
-
controls?: boolean;
|
|
11
|
-
disableKBcontrols?: boolean;
|
|
12
|
-
enableIFrameApi?: boolean;
|
|
13
|
-
endTime?: number;
|
|
14
|
-
interfaceLanguage?: string;
|
|
15
|
-
ivLoadPolicy?: number;
|
|
16
|
-
loop?: boolean;
|
|
17
|
-
modestBranding?: boolean;
|
|
18
|
-
nocookie?: boolean;
|
|
19
|
-
origin?: string;
|
|
20
|
-
playlist?: string;
|
|
21
|
-
progressBarColor?: string;
|
|
22
|
-
startAt?: number;
|
|
23
|
-
}
|
|
24
|
-
export declare const getYoutubeEmbedUrl: (nocookie?: boolean) => "https://www.youtube-nocookie.com/embed/" | "https://www.youtube.com/embed/";
|
|
25
|
-
export declare const getEmbedUrlFromYoutubeUrl: (options: GetEmbedUrlOptions) => string | null;
|