@tiptap/extension-youtube 2.11.5 → 2.11.6

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 CHANGED
@@ -9,11 +9,14 @@ const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtub
9
9
  const isValidYoutubeUrl = (url) => {
10
10
  return url.match(YOUTUBE_REGEX);
11
11
  };
12
- const getYoutubeEmbedUrl = (nocookie) => {
12
+ const getYoutubeEmbedUrl = (nocookie, isPlaylist) => {
13
+ if (isPlaylist) {
14
+ return 'https://www.youtube-nocookie.com/embed/videoseries?list=';
15
+ }
13
16
  return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/';
14
17
  };
15
18
  const getEmbedUrlFromYoutubeUrl = (options) => {
16
- const { url, allowFullscreen, autoplay, ccLanguage, ccLoadPolicy, controls, disableKBcontrols, enableIFrameApi, endTime, interfaceLanguage, ivLoadPolicy, loop, modestBranding, nocookie, origin, playlist, progressBarColor, startAt, } = options;
19
+ const { url, allowFullscreen, autoplay, ccLanguage, ccLoadPolicy, controls, disableKBcontrols, enableIFrameApi, endTime, interfaceLanguage, ivLoadPolicy, loop, modestBranding, nocookie, origin, playlist, progressBarColor, startAt, rel, } = options;
17
20
  if (!isValidYoutubeUrl(url)) {
18
21
  return null;
19
22
  }
@@ -29,12 +32,12 @@ const getEmbedUrlFromYoutubeUrl = (options) => {
29
32
  }
30
33
  return `${getYoutubeEmbedUrl(nocookie)}${id}`;
31
34
  }
32
- const videoIdRegex = /(?:v=|shorts\/)([-\w]+)/gm;
35
+ const videoIdRegex = /(?:(v|list)=|shorts\/)([-\w]+)/gm;
33
36
  const matches = videoIdRegex.exec(url);
34
- if (!matches || !matches[1]) {
37
+ if (!matches || !matches[2]) {
35
38
  return null;
36
39
  }
37
- let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`;
40
+ let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === 'list')}${matches[2]}`;
38
41
  const params = [];
39
42
  if (allowFullscreen === false) {
40
43
  params.push('fs=0');
@@ -84,8 +87,11 @@ const getEmbedUrlFromYoutubeUrl = (options) => {
84
87
  if (progressBarColor) {
85
88
  params.push(`color=${progressBarColor}`);
86
89
  }
90
+ if (rel !== undefined) {
91
+ params.push(`rel=${rel}`);
92
+ }
87
93
  if (params.length) {
88
- outputUrl += `?${params.join('&')}`;
94
+ outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`;
89
95
  }
90
96
  return outputUrl;
91
97
  };
@@ -119,6 +125,7 @@ const Youtube = core.Node.create({
119
125
  playlist: '',
120
126
  progressBarColor: undefined,
121
127
  width: 640,
128
+ rel: 1,
122
129
  };
123
130
  },
124
131
  inline() {
@@ -198,6 +205,7 @@ const Youtube = core.Node.create({
198
205
  playlist: this.options.playlist,
199
206
  progressBarColor: this.options.progressBarColor,
200
207
  startAt: HTMLAttributes.start || 0,
208
+ rel: this.options.rel,
201
209
  });
202
210
  HTMLAttributes.src = embedUrl;
203
211
  return [
@@ -222,6 +230,7 @@ const Youtube = core.Node.create({
222
230
  origin: this.options.origin,
223
231
  playlist: this.options.playlist,
224
232
  progressBarColor: this.options.progressBarColor,
233
+ rel: this.options.rel,
225
234
  }, HTMLAttributes),
226
235
  ],
227
236
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/youtube.ts"],"sourcesContent":["export const YOUTUBE_REGEX = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/\nexport const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/g\n\nexport const isValidYoutubeUrl = (url: string) => {\n return url.match(YOUTUBE_REGEX)\n}\n\nexport interface GetEmbedUrlOptions {\n url: string;\n allowFullscreen?: boolean;\n autoplay?: boolean;\n ccLanguage?:string;\n ccLoadPolicy?:boolean;\n controls?: boolean;\n disableKBcontrols?: boolean,\n enableIFrameApi?: boolean;\n endTime?: number;\n interfaceLanguage?: string;\n ivLoadPolicy?: number;\n loop?: boolean;\n modestBranding?: boolean;\n nocookie?: boolean;\n origin?: string;\n playlist?: string;\n progressBarColor?: string;\n startAt?: number;\n}\n\nexport const getYoutubeEmbedUrl = (nocookie?: boolean) => {\n return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/'\n}\n\nexport const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {\n const {\n url,\n allowFullscreen,\n autoplay,\n ccLanguage,\n ccLoadPolicy,\n controls,\n disableKBcontrols,\n enableIFrameApi,\n endTime,\n interfaceLanguage,\n ivLoadPolicy,\n loop,\n modestBranding,\n nocookie,\n origin,\n playlist,\n progressBarColor,\n startAt,\n } = options\n\n if (!isValidYoutubeUrl(url)) {\n return null\n }\n\n // if is already an embed url, return it\n if (url.includes('/embed/')) {\n return url\n }\n\n // if is a youtu.be url, get the id after the /\n if (url.includes('youtu.be')) {\n const id = url.split('/').pop()\n\n if (!id) {\n return null\n }\n return `${getYoutubeEmbedUrl(nocookie)}${id}`\n }\n\n const videoIdRegex = /(?:v=|shorts\\/)([-\\w]+)/gm\n const matches = videoIdRegex.exec(url)\n\n if (!matches || !matches[1]) {\n return null\n }\n\n let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`\n\n const params = []\n\n if (allowFullscreen === false) {\n params.push('fs=0')\n }\n\n if (autoplay) {\n params.push('autoplay=1')\n }\n\n if (ccLanguage) {\n params.push(`cc_lang_pref=${ccLanguage}`)\n }\n\n if (ccLoadPolicy) {\n params.push('cc_load_policy=1')\n }\n\n if (!controls) {\n params.push('controls=0')\n }\n\n if (disableKBcontrols) {\n params.push('disablekb=1')\n }\n\n if (enableIFrameApi) {\n params.push('enablejsapi=1')\n }\n\n if (endTime) {\n params.push(`end=${endTime}`)\n }\n\n if (interfaceLanguage) {\n params.push(`hl=${interfaceLanguage}`)\n }\n\n if (ivLoadPolicy) {\n params.push(`iv_load_policy=${ivLoadPolicy}`)\n }\n\n if (loop) {\n params.push('loop=1')\n }\n\n if (modestBranding) {\n params.push('modestbranding=1')\n }\n\n if (origin) {\n params.push(`origin=${origin}`)\n }\n\n if (playlist) {\n params.push(`playlist=${playlist}`)\n }\n\n if (startAt) {\n params.push(`start=${startAt}`)\n }\n\n if (progressBarColor) {\n params.push(`color=${progressBarColor}`)\n }\n\n if (params.length) {\n outputUrl += `?${params.join('&')}`\n }\n\n return outputUrl\n}\n","import { mergeAttributes, Node, nodePasteRule } from '@tiptap/core'\n\nimport { getEmbedUrlFromYoutubeUrl, isValidYoutubeUrl, YOUTUBE_REGEX_GLOBAL } from './utils.js'\n\nexport interface YoutubeOptions {\n /**\n * Controls if the paste handler for youtube videos should be added.\n * @default true\n * @example false\n */\n addPasteHandler: boolean;\n\n /**\n * Controls if the youtube video should be allowed to go fullscreen.\n * @default true\n * @example false\n */\n allowFullscreen: boolean;\n\n /**\n * Controls if the youtube video should autoplay.\n * @default false\n * @example true\n */\n autoplay: boolean;\n\n /**\n * The language of the captions shown in the youtube video.\n * @default undefined\n * @example 'en'\n */\n ccLanguage?: string;\n\n /**\n * Controls if the captions should be shown in the youtube video.\n * @default undefined\n * @example true\n */\n ccLoadPolicy?: boolean;\n\n /**\n * Controls if the controls should be shown in the youtube video.\n * @default true\n * @example false\n */\n controls: boolean;\n\n /**\n * Controls if the keyboard controls should be disabled in the youtube video.\n * @default false\n * @example true\n */\n disableKBcontrols: boolean;\n\n /**\n * Controls if the iframe api should be enabled in the youtube video.\n * @default false\n * @example true\n */\n enableIFrameApi: boolean;\n\n /**\n * The end time of the youtube video.\n * @default 0\n * @example 120\n */\n endTime: number;\n\n /**\n * The height of the youtube video.\n * @default 480\n * @example 720\n */\n height: number;\n\n /**\n * The language of the youtube video.\n * @default undefined\n * @example 'en'\n */\n interfaceLanguage?: string;\n\n /**\n * Controls if the video annotations should be shown in the youtube video.\n * @default 0\n * @example 1\n */\n ivLoadPolicy: number;\n\n /**\n * Controls if the youtube video should loop.\n * @default false\n * @example true\n */\n loop: boolean;\n\n /**\n * Controls if the youtube video should show a small youtube logo.\n * @default false\n * @example true\n */\n modestBranding: boolean;\n\n /**\n * The HTML attributes for a youtube video node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>;\n\n /**\n * Controls if the youtube node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean;\n\n /**\n * Controls if the youtube video should be loaded from youtube-nocookie.com.\n * @default false\n * @example true\n */\n nocookie: boolean;\n\n /**\n * The origin of the youtube video.\n * @default ''\n * @example 'https://tiptap.dev'\n */\n origin: string;\n\n /**\n * The playlist of the youtube video.\n * @default ''\n * @example 'PLQg6GaokU5CwiVmsZ0dZm6VeIg0V5z1tK'\n */\n playlist: string;\n\n /**\n * The color of the youtube video progress bar.\n * @default undefined\n * @example 'red'\n */\n progressBarColor?: string;\n\n /**\n * The width of the youtube video.\n * @default 640\n * @example 1280\n */\n width: number;\n}\n\n/**\n * The options for setting a youtube video.\n */\ntype SetYoutubeVideoOptions = { src: string, width?: number, height?: number, start?: number }\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n youtube: {\n /**\n * Insert a youtube video\n * @param options The youtube video attributes\n * @example editor.commands.setYoutubeVideo({ src: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' })\n */\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ReturnType,\n }\n }\n}\n\n/**\n * This extension adds support for youtube videos.\n * @see https://www.tiptap.dev/api/nodes/youtube\n */\nexport const Youtube = Node.create<YoutubeOptions>({\n name: 'youtube',\n\n addOptions() {\n return {\n addPasteHandler: true,\n allowFullscreen: true,\n autoplay: false,\n ccLanguage: undefined,\n ccLoadPolicy: undefined,\n controls: true,\n disableKBcontrols: false,\n enableIFrameApi: false,\n endTime: 0,\n height: 480,\n interfaceLanguage: undefined,\n ivLoadPolicy: 0,\n loop: false,\n modestBranding: false,\n HTMLAttributes: {},\n inline: false,\n nocookie: false,\n origin: '',\n playlist: '',\n progressBarColor: undefined,\n width: 640,\n }\n },\n\n inline() {\n return this.options.inline\n },\n\n group() {\n return this.options.inline ? 'inline' : 'block'\n },\n\n draggable: true,\n\n addAttributes() {\n return {\n src: {\n default: null,\n },\n start: {\n default: 0,\n },\n width: {\n default: this.options.width,\n },\n height: {\n default: this.options.height,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'div[data-youtube-video] iframe',\n },\n ]\n },\n\n addCommands() {\n return {\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ({ commands }) => {\n if (!isValidYoutubeUrl(options.src)) {\n return false\n }\n\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n addPasteRules() {\n if (!this.options.addPasteHandler) {\n return []\n }\n\n return [\n nodePasteRule({\n find: YOUTUBE_REGEX_GLOBAL,\n type: this.type,\n getAttributes: match => {\n return { src: match.input }\n },\n }),\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const embedUrl = getEmbedUrlFromYoutubeUrl({\n url: HTMLAttributes.src,\n allowFullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n controls: this.options.controls,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n nocookie: this.options.nocookie,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n startAt: HTMLAttributes.start || 0,\n })\n\n HTMLAttributes.src = embedUrl\n\n return [\n 'div',\n { 'data-youtube-video': '' },\n [\n 'iframe',\n mergeAttributes(\n this.options.HTMLAttributes,\n {\n width: this.options.width,\n height: this.options.height,\n allowfullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n },\n HTMLAttributes,\n ),\n ],\n ]\n },\n})\n"],"names":["Node","nodePasteRule","mergeAttributes"],"mappings":";;;;;;AAAO,MAAM,aAAa,GAAG,yIAAyI;AAC/J,MAAM,oBAAoB,GAAG,0IAA0I;AAEvK,MAAM,iBAAiB,GAAG,CAAC,GAAW,KAAI;AAC/C,IAAA,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC;AACjC,CAAC;AAuBM,MAAM,kBAAkB,GAAG,CAAC,QAAkB,KAAI;IACvD,OAAO,QAAQ,GAAG,yCAAyC,GAAG,gCAAgC;AAChG,CAAC;AAEM,MAAM,yBAAyB,GAAG,CAAC,OAA2B,KAAI;AACvE,IAAA,MAAM,EACJ,GAAG,EACH,eAAe,EACf,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,OAAO,EACP,iBAAiB,EACjB,YAAY,EACZ,IAAI,EACJ,cAAc,EACd,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,OAAO,GACR,GAAG,OAAO;AAEX,IAAA,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE;AAC3B,QA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AAiB;AACjD,oBAAA,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;AACvC,oBAAA,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;AACvB,oBAAA,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc;AAC3C,oBAAA,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;AAC3B,oBAAA,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;AAC/B,oBAAA,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB;AAChD,iBAAA,EACD,cAAc,CACf;AACF,aAAA;SACF;KACF;AACF,CAAA;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/youtube.ts"],"sourcesContent":["export const YOUTUBE_REGEX = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/\nexport const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/g\n\nexport const isValidYoutubeUrl = (url: string) => {\n return url.match(YOUTUBE_REGEX)\n}\n\nexport interface GetEmbedUrlOptions {\n url: string;\n allowFullscreen?: boolean;\n autoplay?: boolean;\n ccLanguage?:string;\n ccLoadPolicy?:boolean;\n controls?: boolean;\n disableKBcontrols?: boolean,\n enableIFrameApi?: boolean;\n endTime?: number;\n interfaceLanguage?: string;\n ivLoadPolicy?: number;\n loop?: boolean;\n modestBranding?: boolean;\n nocookie?: boolean;\n origin?: string;\n playlist?: string;\n progressBarColor?: string;\n startAt?: number;\n rel?: number;\n}\n\nexport const getYoutubeEmbedUrl = (nocookie?: boolean, isPlaylist?:boolean) => {\n if (isPlaylist) {\n return 'https://www.youtube-nocookie.com/embed/videoseries?list='\n }\n return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/'\n}\n\nexport const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {\n const {\n url,\n allowFullscreen,\n autoplay,\n ccLanguage,\n ccLoadPolicy,\n controls,\n disableKBcontrols,\n enableIFrameApi,\n endTime,\n interfaceLanguage,\n ivLoadPolicy,\n loop,\n modestBranding,\n nocookie,\n origin,\n playlist,\n progressBarColor,\n startAt,\n rel,\n } = options\n\n if (!isValidYoutubeUrl(url)) {\n return null\n }\n\n // if is already an embed url, return it\n if (url.includes('/embed/')) {\n return url\n }\n\n // if is a youtu.be url, get the id after the /\n if (url.includes('youtu.be')) {\n const id = url.split('/').pop()\n\n if (!id) {\n return null\n }\n return `${getYoutubeEmbedUrl(nocookie)}${id}`\n }\n\n const videoIdRegex = /(?:(v|list)=|shorts\\/)([-\\w]+)/gm\n const matches = videoIdRegex.exec(url)\n\n if (!matches || !matches[2]) {\n return null\n }\n\n let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === 'list')}${matches[2]}`\n\n const params = []\n\n if (allowFullscreen === false) {\n params.push('fs=0')\n }\n\n if (autoplay) {\n params.push('autoplay=1')\n }\n\n if (ccLanguage) {\n params.push(`cc_lang_pref=${ccLanguage}`)\n }\n\n if (ccLoadPolicy) {\n params.push('cc_load_policy=1')\n }\n\n if (!controls) {\n params.push('controls=0')\n }\n\n if (disableKBcontrols) {\n params.push('disablekb=1')\n }\n\n if (enableIFrameApi) {\n params.push('enablejsapi=1')\n }\n\n if (endTime) {\n params.push(`end=${endTime}`)\n }\n\n if (interfaceLanguage) {\n params.push(`hl=${interfaceLanguage}`)\n }\n\n if (ivLoadPolicy) {\n params.push(`iv_load_policy=${ivLoadPolicy}`)\n }\n\n if (loop) {\n params.push('loop=1')\n }\n\n if (modestBranding) {\n params.push('modestbranding=1')\n }\n\n if (origin) {\n params.push(`origin=${origin}`)\n }\n\n if (playlist) {\n params.push(`playlist=${playlist}`)\n }\n\n if (startAt) {\n params.push(`start=${startAt}`)\n }\n\n if (progressBarColor) {\n params.push(`color=${progressBarColor}`)\n }\n\n if (rel !== undefined) {\n params.push(`rel=${rel}`)\n }\n\n if (params.length) {\n outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`\n }\n\n return outputUrl\n}\n","import { mergeAttributes, Node, nodePasteRule } from '@tiptap/core'\n\nimport { getEmbedUrlFromYoutubeUrl, isValidYoutubeUrl, YOUTUBE_REGEX_GLOBAL } from './utils.js'\n\nexport interface YoutubeOptions {\n /**\n * Controls if the paste handler for youtube videos should be added.\n * @default true\n * @example false\n */\n addPasteHandler: boolean;\n\n /**\n * Controls if the youtube video should be allowed to go fullscreen.\n * @default true\n * @example false\n */\n allowFullscreen: boolean;\n\n /**\n * Controls if the youtube video should autoplay.\n * @default false\n * @example true\n */\n autoplay: boolean;\n\n /**\n * The language of the captions shown in the youtube video.\n * @default undefined\n * @example 'en'\n */\n ccLanguage?: string;\n\n /**\n * Controls if the captions should be shown in the youtube video.\n * @default undefined\n * @example true\n */\n ccLoadPolicy?: boolean;\n\n /**\n * Controls if the controls should be shown in the youtube video.\n * @default true\n * @example false\n */\n controls: boolean;\n\n /**\n * Controls if the keyboard controls should be disabled in the youtube video.\n * @default false\n * @example true\n */\n disableKBcontrols: boolean;\n\n /**\n * Controls if the iframe api should be enabled in the youtube video.\n * @default false\n * @example true\n */\n enableIFrameApi: boolean;\n\n /**\n * The end time of the youtube video.\n * @default 0\n * @example 120\n */\n endTime: number;\n\n /**\n * The height of the youtube video.\n * @default 480\n * @example 720\n */\n height: number;\n\n /**\n * The language of the youtube video.\n * @default undefined\n * @example 'en'\n */\n interfaceLanguage?: string;\n\n /**\n * Controls if the video annotations should be shown in the youtube video.\n * @default 0\n * @example 1\n */\n ivLoadPolicy: number;\n\n /**\n * Controls if the youtube video should loop.\n * @default false\n * @example true\n */\n loop: boolean;\n\n /**\n * Controls if the youtube video should show a small youtube logo.\n * @default false\n * @example true\n */\n modestBranding: boolean;\n\n /**\n * The HTML attributes for a youtube video node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>;\n\n /**\n * Controls if the youtube node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean;\n\n /**\n * Controls if the youtube video should be loaded from youtube-nocookie.com.\n * @default false\n * @example true\n */\n nocookie: boolean;\n\n /**\n * The origin of the youtube video.\n * @default ''\n * @example 'https://tiptap.dev'\n */\n origin: string;\n\n /**\n * The playlist of the youtube video.\n * @default ''\n * @example 'PLQg6GaokU5CwiVmsZ0dZm6VeIg0V5z1tK'\n */\n playlist: string;\n\n /**\n * The color of the youtube video progress bar.\n * @default undefined\n * @example 'red'\n */\n progressBarColor?: string;\n\n /**\n * The width of the youtube video.\n * @default 640\n * @example 1280\n */\n width: number;\n\n /**\n * Controls if the related youtube videos at the end are from the same channel.\n * @default 1\n * @example 0\n */\n rel: number;\n}\n\n/**\n * The options for setting a youtube video.\n */\ntype SetYoutubeVideoOptions = { src: string, width?: number, height?: number, start?: number }\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n youtube: {\n /**\n * Insert a youtube video\n * @param options The youtube video attributes\n * @example editor.commands.setYoutubeVideo({ src: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' })\n */\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ReturnType,\n }\n }\n}\n\n/**\n * This extension adds support for youtube videos.\n * @see https://www.tiptap.dev/api/nodes/youtube\n */\nexport const Youtube = Node.create<YoutubeOptions>({\n name: 'youtube',\n\n addOptions() {\n return {\n addPasteHandler: true,\n allowFullscreen: true,\n autoplay: false,\n ccLanguage: undefined,\n ccLoadPolicy: undefined,\n controls: true,\n disableKBcontrols: false,\n enableIFrameApi: false,\n endTime: 0,\n height: 480,\n interfaceLanguage: undefined,\n ivLoadPolicy: 0,\n loop: false,\n modestBranding: false,\n HTMLAttributes: {},\n inline: false,\n nocookie: false,\n origin: '',\n playlist: '',\n progressBarColor: undefined,\n width: 640,\n rel: 1,\n }\n },\n\n inline() {\n return this.options.inline\n },\n\n group() {\n return this.options.inline ? 'inline' : 'block'\n },\n\n draggable: true,\n\n addAttributes() {\n return {\n src: {\n default: null,\n },\n start: {\n default: 0,\n },\n width: {\n default: this.options.width,\n },\n height: {\n default: this.options.height,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'div[data-youtube-video] iframe',\n },\n ]\n },\n\n addCommands() {\n return {\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ({ commands }) => {\n if (!isValidYoutubeUrl(options.src)) {\n return false\n }\n\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n addPasteRules() {\n if (!this.options.addPasteHandler) {\n return []\n }\n\n return [\n nodePasteRule({\n find: YOUTUBE_REGEX_GLOBAL,\n type: this.type,\n getAttributes: match => {\n return { src: match.input }\n },\n }),\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const embedUrl = getEmbedUrlFromYoutubeUrl({\n url: HTMLAttributes.src,\n allowFullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n controls: this.options.controls,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n nocookie: this.options.nocookie,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n startAt: HTMLAttributes.start || 0,\n rel: this.options.rel,\n })\n\n HTMLAttributes.src = embedUrl\n\n return [\n 'div',\n { 'data-youtube-video': '' },\n [\n 'iframe',\n mergeAttributes(\n this.options.HTMLAttributes,\n {\n width: this.options.width,\n height: this.options.height,\n allowfullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n rel: this.options.rel,\n },\n HTMLAttributes,\n ),\n ],\n ]\n },\n})\n"],"names":["Node","nodePasteRule","mergeAttributes"],"mappings":";;;;;;AAAO,MAAM,aAAa,GAAG,yIAAyI;AAC/J,MAAM,oBAAoB,GAAG,0IAA0I;AAEvK,MAAM,iBAAiB,GAAG,CAAC,GAAW,KAAI;AAC/C,IAAA,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC;AACjC,CAAC;AAwBM,MAAM,kBAAkB,GAAG,CAAC,QAAkB,EAAE,UAAmB,KAAI;IAC5E,IAAI,UAAU,EAAE;AACd,QAAA,OAAO,0DAA0D;;IAEnE,OAAO,QAAQ,GAAG,yCAAyC,GAAG,gCAAgC;AAChG,CAAC;AAEM,MAAM,yBAAyB,GAAG,CAAC,OAA2B,KAAI;AACvE,IAAA,MAAM,EACJ,GAAG,EACH,eAAe,EACf,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,OAAO,EACP,iBAAiB,EACjB,YAAY,EACZ,IAAI,EACJ,cAAc,EACd,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,OAAO,EACP,GAAG,GACJ,GAAG,OAAO;AAEX,IAAA,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE;AAC3B,QAAA,OAAO,IAAI;;;AAIb,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AAC3B,QAAA,OAAO,GAAG;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E,IAAI,CAAC,OAAO,CAAC,iBAAiB;AACjD,oBAAA,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe;AAC7C,oBAAA,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;AAC7B,oBAAA,iBAAiB,EAAE,IAAI,CAAC,OAAO,CAAC,iBAAiB;AACjD,oBAAA,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;AACvC,oBAAA,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;AACvB,oBAAA,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc;AAC3C,oBAAA,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;AAC3B,oBAAA,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;AAC/B,oBAAA,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB;AAC/C,oBAAA,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;AACtB,iBAAA,EACD,cAAc,CACf;AACF,aAAA;SACF;KACF;AACF,CAAA;;;;;"}
package/dist/index.js CHANGED
@@ -5,11 +5,14 @@ const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtub
5
5
  const isValidYoutubeUrl = (url) => {
6
6
  return url.match(YOUTUBE_REGEX);
7
7
  };
8
- const getYoutubeEmbedUrl = (nocookie) => {
8
+ const getYoutubeEmbedUrl = (nocookie, isPlaylist) => {
9
+ if (isPlaylist) {
10
+ return 'https://www.youtube-nocookie.com/embed/videoseries?list=';
11
+ }
9
12
  return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/';
10
13
  };
11
14
  const getEmbedUrlFromYoutubeUrl = (options) => {
12
- const { url, allowFullscreen, autoplay, ccLanguage, ccLoadPolicy, controls, disableKBcontrols, enableIFrameApi, endTime, interfaceLanguage, ivLoadPolicy, loop, modestBranding, nocookie, origin, playlist, progressBarColor, startAt, } = options;
15
+ const { url, allowFullscreen, autoplay, ccLanguage, ccLoadPolicy, controls, disableKBcontrols, enableIFrameApi, endTime, interfaceLanguage, ivLoadPolicy, loop, modestBranding, nocookie, origin, playlist, progressBarColor, startAt, rel, } = options;
13
16
  if (!isValidYoutubeUrl(url)) {
14
17
  return null;
15
18
  }
@@ -25,12 +28,12 @@ const getEmbedUrlFromYoutubeUrl = (options) => {
25
28
  }
26
29
  return `${getYoutubeEmbedUrl(nocookie)}${id}`;
27
30
  }
28
- const videoIdRegex = /(?:v=|shorts\/)([-\w]+)/gm;
31
+ const videoIdRegex = /(?:(v|list)=|shorts\/)([-\w]+)/gm;
29
32
  const matches = videoIdRegex.exec(url);
30
- if (!matches || !matches[1]) {
33
+ if (!matches || !matches[2]) {
31
34
  return null;
32
35
  }
33
- let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`;
36
+ let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === 'list')}${matches[2]}`;
34
37
  const params = [];
35
38
  if (allowFullscreen === false) {
36
39
  params.push('fs=0');
@@ -80,8 +83,11 @@ const getEmbedUrlFromYoutubeUrl = (options) => {
80
83
  if (progressBarColor) {
81
84
  params.push(`color=${progressBarColor}`);
82
85
  }
86
+ if (rel !== undefined) {
87
+ params.push(`rel=${rel}`);
88
+ }
83
89
  if (params.length) {
84
- outputUrl += `?${params.join('&')}`;
90
+ outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`;
85
91
  }
86
92
  return outputUrl;
87
93
  };
@@ -115,6 +121,7 @@ const Youtube = Node.create({
115
121
  playlist: '',
116
122
  progressBarColor: undefined,
117
123
  width: 640,
124
+ rel: 1,
118
125
  };
119
126
  },
120
127
  inline() {
@@ -194,6 +201,7 @@ const Youtube = Node.create({
194
201
  playlist: this.options.playlist,
195
202
  progressBarColor: this.options.progressBarColor,
196
203
  startAt: HTMLAttributes.start || 0,
204
+ rel: this.options.rel,
197
205
  });
198
206
  HTMLAttributes.src = embedUrl;
199
207
  return [
@@ -218,6 +226,7 @@ const Youtube = Node.create({
218
226
  origin: this.options.origin,
219
227
  playlist: this.options.playlist,
220
228
  progressBarColor: this.options.progressBarColor,
229
+ rel: this.options.rel,
221
230
  }, HTMLAttributes),
222
231
  ],
223
232
  ];
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/utils.ts","../src/youtube.ts"],"sourcesContent":["export const YOUTUBE_REGEX = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/\nexport const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/g\n\nexport const isValidYoutubeUrl = (url: string) => {\n return url.match(YOUTUBE_REGEX)\n}\n\nexport interface GetEmbedUrlOptions {\n url: string;\n allowFullscreen?: boolean;\n autoplay?: boolean;\n ccLanguage?:string;\n ccLoadPolicy?:boolean;\n controls?: boolean;\n disableKBcontrols?: boolean,\n enableIFrameApi?: boolean;\n endTime?: number;\n interfaceLanguage?: string;\n ivLoadPolicy?: number;\n loop?: boolean;\n modestBranding?: boolean;\n nocookie?: boolean;\n origin?: string;\n playlist?: string;\n progressBarColor?: string;\n startAt?: number;\n}\n\nexport const getYoutubeEmbedUrl = (nocookie?: boolean) => {\n return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/'\n}\n\nexport const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {\n const {\n url,\n allowFullscreen,\n autoplay,\n ccLanguage,\n ccLoadPolicy,\n controls,\n disableKBcontrols,\n enableIFrameApi,\n endTime,\n interfaceLanguage,\n ivLoadPolicy,\n loop,\n modestBranding,\n nocookie,\n origin,\n playlist,\n progressBarColor,\n startAt,\n } = options\n\n if (!isValidYoutubeUrl(url)) {\n return null\n }\n\n // if is already an embed url, return it\n if (url.includes('/embed/')) {\n return url\n }\n\n // if is a youtu.be url, get the id after the /\n if (url.includes('youtu.be')) {\n const id = url.split('/').pop()\n\n if (!id) {\n return null\n }\n return `${getYoutubeEmbedUrl(nocookie)}${id}`\n }\n\n const videoIdRegex = /(?:v=|shorts\\/)([-\\w]+)/gm\n const matches = videoIdRegex.exec(url)\n\n if (!matches || !matches[1]) {\n return null\n }\n\n let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`\n\n const params = []\n\n if (allowFullscreen === false) {\n params.push('fs=0')\n }\n\n if (autoplay) {\n params.push('autoplay=1')\n }\n\n if (ccLanguage) {\n params.push(`cc_lang_pref=${ccLanguage}`)\n }\n\n if (ccLoadPolicy) {\n params.push('cc_load_policy=1')\n }\n\n if (!controls) {\n params.push('controls=0')\n }\n\n if (disableKBcontrols) {\n params.push('disablekb=1')\n }\n\n if (enableIFrameApi) {\n params.push('enablejsapi=1')\n }\n\n if (endTime) {\n params.push(`end=${endTime}`)\n }\n\n if (interfaceLanguage) {\n params.push(`hl=${interfaceLanguage}`)\n }\n\n if (ivLoadPolicy) {\n params.push(`iv_load_policy=${ivLoadPolicy}`)\n }\n\n if (loop) {\n params.push('loop=1')\n }\n\n if (modestBranding) {\n params.push('modestbranding=1')\n }\n\n if (origin) {\n params.push(`origin=${origin}`)\n }\n\n if (playlist) {\n params.push(`playlist=${playlist}`)\n }\n\n if (startAt) {\n params.push(`start=${startAt}`)\n }\n\n if (progressBarColor) {\n params.push(`color=${progressBarColor}`)\n }\n\n if (params.length) {\n outputUrl += `?${params.join('&')}`\n }\n\n return outputUrl\n}\n","import { mergeAttributes, Node, nodePasteRule } from '@tiptap/core'\n\nimport { getEmbedUrlFromYoutubeUrl, isValidYoutubeUrl, YOUTUBE_REGEX_GLOBAL } from './utils.js'\n\nexport interface YoutubeOptions {\n /**\n * Controls if the paste handler for youtube videos should be added.\n * @default true\n * @example false\n */\n addPasteHandler: boolean;\n\n /**\n * Controls if the youtube video should be allowed to go fullscreen.\n * @default true\n * @example false\n */\n allowFullscreen: boolean;\n\n /**\n * Controls if the youtube video should autoplay.\n * @default false\n * @example true\n */\n autoplay: boolean;\n\n /**\n * The language of the captions shown in the youtube video.\n * @default undefined\n * @example 'en'\n */\n ccLanguage?: string;\n\n /**\n * Controls if the captions should be shown in the youtube video.\n * @default undefined\n * @example true\n */\n ccLoadPolicy?: boolean;\n\n /**\n * Controls if the controls should be shown in the youtube video.\n * @default true\n * @example false\n */\n controls: boolean;\n\n /**\n * Controls if the keyboard controls should be disabled in the youtube video.\n * @default false\n * @example true\n */\n disableKBcontrols: boolean;\n\n /**\n * Controls if the iframe api should be enabled in the youtube video.\n * @default false\n * @example true\n */\n enableIFrameApi: boolean;\n\n /**\n * The end time of the youtube video.\n * @default 0\n * @example 120\n */\n endTime: number;\n\n /**\n * The height of the youtube video.\n * @default 480\n * @example 720\n */\n height: number;\n\n /**\n * The language of the youtube video.\n * @default undefined\n * @example 'en'\n */\n interfaceLanguage?: string;\n\n /**\n * Controls if the video annotations should be shown in the youtube video.\n * @default 0\n * @example 1\n */\n ivLoadPolicy: number;\n\n /**\n * Controls if the youtube video should loop.\n * @default false\n * @example true\n */\n loop: boolean;\n\n /**\n * Controls if the youtube video should show a small youtube logo.\n * @default false\n * @example true\n */\n modestBranding: boolean;\n\n /**\n * The HTML attributes for a youtube video node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>;\n\n /**\n * Controls if the youtube node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean;\n\n /**\n * Controls if the youtube video should be loaded from youtube-nocookie.com.\n * @default false\n * @example true\n */\n nocookie: boolean;\n\n /**\n * The origin of the youtube video.\n * @default ''\n * @example 'https://tiptap.dev'\n */\n origin: string;\n\n /**\n * The playlist of the youtube video.\n * @default ''\n * @example 'PLQg6GaokU5CwiVmsZ0dZm6VeIg0V5z1tK'\n */\n playlist: string;\n\n /**\n * The color of the youtube video progress bar.\n * @default undefined\n * @example 'red'\n */\n progressBarColor?: string;\n\n /**\n * The width of the youtube video.\n * @default 640\n * @example 1280\n */\n width: number;\n}\n\n/**\n * The options for setting a youtube video.\n */\ntype SetYoutubeVideoOptions = { src: string, width?: number, height?: number, start?: number }\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n youtube: {\n /**\n * Insert a youtube video\n * @param options The youtube video attributes\n * @example editor.commands.setYoutubeVideo({ src: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' })\n */\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ReturnType,\n }\n }\n}\n\n/**\n * This extension adds support for youtube videos.\n * @see https://www.tiptap.dev/api/nodes/youtube\n */\nexport const Youtube = Node.create<YoutubeOptions>({\n name: 'youtube',\n\n addOptions() {\n return {\n addPasteHandler: true,\n allowFullscreen: true,\n autoplay: false,\n ccLanguage: undefined,\n ccLoadPolicy: undefined,\n controls: true,\n disableKBcontrols: false,\n enableIFrameApi: false,\n endTime: 0,\n height: 480,\n interfaceLanguage: undefined,\n ivLoadPolicy: 0,\n loop: false,\n modestBranding: false,\n HTMLAttributes: {},\n inline: false,\n nocookie: false,\n origin: '',\n playlist: '',\n progressBarColor: undefined,\n width: 640,\n }\n },\n\n inline() {\n return this.options.inline\n },\n\n group() {\n return this.options.inline ? 'inline' : 'block'\n },\n\n draggable: true,\n\n addAttributes() {\n return {\n src: {\n default: null,\n },\n start: {\n default: 0,\n },\n width: {\n default: this.options.width,\n },\n height: {\n default: this.options.height,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'div[data-youtube-video] iframe',\n },\n ]\n },\n\n addCommands() {\n return {\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ({ commands }) => {\n if (!isValidYoutubeUrl(options.src)) {\n return false\n }\n\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n addPasteRules() {\n if (!this.options.addPasteHandler) {\n return []\n }\n\n return [\n nodePasteRule({\n find: YOUTUBE_REGEX_GLOBAL,\n type: this.type,\n getAttributes: match => {\n return { src: match.input }\n },\n }),\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const embedUrl = getEmbedUrlFromYoutubeUrl({\n url: HTMLAttributes.src,\n allowFullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n controls: this.options.controls,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n nocookie: this.options.nocookie,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n startAt: HTMLAttributes.start || 0,\n })\n\n HTMLAttributes.src = embedUrl\n\n return [\n 'div',\n { 'data-youtube-video': '' },\n [\n 'iframe',\n mergeAttributes(\n this.options.HTMLAttributes,\n {\n width: this.options.width,\n height: this.options.height,\n allowfullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n },\n HTMLAttributes,\n ),\n ],\n ]\n },\n})\n"],"names":[],"mappings":";;AAAO,MAAM,aAAa,GAAG,yIAAyI;AAC/J,MAAM,oBAAoB,GAAG,0IAA0I;AAEvK,MAAM,iBAAiB,GAAG,CAAC,GAAW,KA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CAAC,OAAO,CAAC,KAAK;AACzB,oBAAA,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;AAC3B,oBAAA,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe;AAC7C,oBAAA,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;AAC/B,oBAAA,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;AACnC,oBAAA,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;AACvC,oBAAA,iBAAiB,EAAE,IAAI,CAAC,OAAO,CAAC,iBAAiB;AACjD,oBAAA,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe;AAC7C,oBAAA,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;AAC7B,oBAAA,iBAAiB,EAAE,IAAI,CAAC,OAAO,CAAC,iBAAiB;AACjD,oBAAA,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;AACvC,oBAAA,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;AACvB,oBAAA,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc;AAC3C,oBAAA,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;AAC3B,oBAAA,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;AAC/B,oBAAA,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB;AAChD,iBAAA,EACD,cAAc,CACf;AACF,aAAA;SACF;KACF;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/utils.ts","../src/youtube.ts"],"sourcesContent":["export const YOUTUBE_REGEX = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/\nexport const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/g\n\nexport const isValidYoutubeUrl = (url: string) => {\n return url.match(YOUTUBE_REGEX)\n}\n\nexport interface GetEmbedUrlOptions {\n url: string;\n allowFullscreen?: boolean;\n autoplay?: boolean;\n ccLanguage?:string;\n ccLoadPolicy?:boolean;\n controls?: boolean;\n disableKBcontrols?: boolean,\n enableIFrameApi?: boolean;\n endTime?: number;\n interfaceLanguage?: string;\n ivLoadPolicy?: number;\n loop?: boolean;\n modestBranding?: boolean;\n nocookie?: boolean;\n origin?: string;\n playlist?: string;\n progressBarColor?: string;\n startAt?: number;\n rel?: number;\n}\n\nexport const getYoutubeEmbedUrl = (nocookie?: boolean, isPlaylist?:boolean) => {\n if (isPlaylist) {\n return 'https://www.youtube-nocookie.com/embed/videoseries?list='\n }\n return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/'\n}\n\nexport const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {\n const {\n url,\n allowFullscreen,\n autoplay,\n ccLanguage,\n ccLoadPolicy,\n controls,\n disableKBcontrols,\n enableIFrameApi,\n endTime,\n interfaceLanguage,\n ivLoadPolicy,\n loop,\n modestBranding,\n nocookie,\n origin,\n playlist,\n progressBarColor,\n startAt,\n rel,\n } = options\n\n if (!isValidYoutubeUrl(url)) {\n return null\n }\n\n // if is already an embed url, return it\n if (url.includes('/embed/')) {\n return url\n }\n\n // if is a youtu.be url, get the id after the /\n if (url.includes('youtu.be')) {\n const id = url.split('/').pop()\n\n if (!id) {\n return null\n }\n return `${getYoutubeEmbedUrl(nocookie)}${id}`\n }\n\n const videoIdRegex = /(?:(v|list)=|shorts\\/)([-\\w]+)/gm\n const matches = videoIdRegex.exec(url)\n\n if (!matches || !matches[2]) {\n return null\n }\n\n let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === 'list')}${matches[2]}`\n\n const params = []\n\n if (allowFullscreen === false) {\n params.push('fs=0')\n }\n\n if (autoplay) {\n params.push('autoplay=1')\n }\n\n if (ccLanguage) {\n params.push(`cc_lang_pref=${ccLanguage}`)\n }\n\n if (ccLoadPolicy) {\n params.push('cc_load_policy=1')\n }\n\n if (!controls) {\n params.push('controls=0')\n }\n\n if (disableKBcontrols) {\n params.push('disablekb=1')\n }\n\n if (enableIFrameApi) {\n params.push('enablejsapi=1')\n }\n\n if (endTime) {\n params.push(`end=${endTime}`)\n }\n\n if (interfaceLanguage) {\n params.push(`hl=${interfaceLanguage}`)\n }\n\n if (ivLoadPolicy) {\n params.push(`iv_load_policy=${ivLoadPolicy}`)\n }\n\n if (loop) {\n params.push('loop=1')\n }\n\n if (modestBranding) {\n params.push('modestbranding=1')\n }\n\n if (origin) {\n params.push(`origin=${origin}`)\n }\n\n if (playlist) {\n params.push(`playlist=${playlist}`)\n }\n\n if (startAt) {\n params.push(`start=${startAt}`)\n }\n\n if (progressBarColor) {\n params.push(`color=${progressBarColor}`)\n }\n\n if (rel !== undefined) {\n params.push(`rel=${rel}`)\n }\n\n if (params.length) {\n outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`\n }\n\n return outputUrl\n}\n","import { mergeAttributes, Node, nodePasteRule } from '@tiptap/core'\n\nimport { getEmbedUrlFromYoutubeUrl, isValidYoutubeUrl, YOUTUBE_REGEX_GLOBAL } from './utils.js'\n\nexport interface YoutubeOptions {\n /**\n * Controls if the paste handler for youtube videos should be added.\n * @default true\n * @example false\n */\n addPasteHandler: boolean;\n\n /**\n * Controls if the youtube video should be allowed to go fullscreen.\n * @default true\n * @example false\n */\n allowFullscreen: boolean;\n\n /**\n * Controls if the youtube video should autoplay.\n * @default false\n * @example true\n */\n autoplay: boolean;\n\n /**\n * The language of the captions shown in the youtube video.\n * @default undefined\n * @example 'en'\n */\n ccLanguage?: string;\n\n /**\n * Controls if the captions should be shown in the youtube video.\n * @default undefined\n * @example true\n */\n ccLoadPolicy?: boolean;\n\n /**\n * Controls if the controls should be shown in the youtube video.\n * @default true\n * @example false\n */\n controls: boolean;\n\n /**\n * Controls if the keyboard controls should be disabled in the youtube video.\n * @default false\n * @example true\n */\n disableKBcontrols: boolean;\n\n /**\n * Controls if the iframe api should be enabled in the youtube video.\n * @default false\n * @example true\n */\n enableIFrameApi: boolean;\n\n /**\n * The end time of the youtube video.\n * @default 0\n * @example 120\n */\n endTime: number;\n\n /**\n * The height of the youtube video.\n * @default 480\n * @example 720\n */\n height: number;\n\n /**\n * The language of the youtube video.\n * @default undefined\n * @example 'en'\n */\n interfaceLanguage?: string;\n\n /**\n * Controls if the video annotations should be shown in the youtube video.\n * @default 0\n * @example 1\n */\n ivLoadPolicy: number;\n\n /**\n * Controls if the youtube video should loop.\n * @default false\n * @example true\n */\n loop: boolean;\n\n /**\n * Controls if the youtube video should show a small youtube logo.\n * @default false\n * @example true\n */\n modestBranding: boolean;\n\n /**\n * The HTML attributes for a youtube video node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>;\n\n /**\n * Controls if the youtube node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean;\n\n /**\n * Controls if the youtube video should be loaded from youtube-nocookie.com.\n * @default false\n * @example true\n */\n nocookie: boolean;\n\n /**\n * The origin of the youtube video.\n * @default ''\n * @example 'https://tiptap.dev'\n */\n origin: string;\n\n /**\n * The playlist of the youtube video.\n * @default ''\n * @example 'PLQg6GaokU5CwiVmsZ0dZm6VeIg0V5z1tK'\n */\n playlist: string;\n\n /**\n * The color of the youtube video progress bar.\n * @default undefined\n * @example 'red'\n */\n progressBarColor?: string;\n\n /**\n * The width of the youtube video.\n * @default 640\n * @example 1280\n */\n width: number;\n\n /**\n * Controls if the related youtube videos at the end are from the same channel.\n * @default 1\n * @example 0\n */\n rel: number;\n}\n\n/**\n * The options for setting a youtube video.\n */\ntype SetYoutubeVideoOptions = { src: string, width?: number, height?: number, start?: number }\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n youtube: {\n /**\n * Insert a youtube video\n * @param options The youtube video attributes\n * @example editor.commands.setYoutubeVideo({ src: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' })\n */\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ReturnType,\n }\n }\n}\n\n/**\n * This extension adds support for youtube videos.\n * @see https://www.tiptap.dev/api/nodes/youtube\n */\nexport const Youtube = Node.create<YoutubeOptions>({\n name: 'youtube',\n\n addOptions() {\n return {\n addPasteHandler: true,\n allowFullscreen: true,\n autoplay: false,\n ccLanguage: undefined,\n ccLoadPolicy: undefined,\n controls: true,\n disableKBcontrols: false,\n enableIFrameApi: false,\n endTime: 0,\n height: 480,\n interfaceLanguage: undefined,\n ivLoadPolicy: 0,\n loop: false,\n modestBranding: false,\n HTMLAttributes: {},\n inline: false,\n nocookie: false,\n origin: '',\n playlist: '',\n progressBarColor: undefined,\n width: 640,\n rel: 1,\n }\n },\n\n inline() {\n return this.options.inline\n },\n\n group() {\n return this.options.inline ? 'inline' : 'block'\n },\n\n draggable: true,\n\n addAttributes() {\n return {\n src: {\n default: null,\n },\n start: {\n default: 0,\n },\n width: {\n default: this.options.width,\n },\n height: {\n default: this.options.height,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'div[data-youtube-video] iframe',\n },\n ]\n },\n\n addCommands() {\n return {\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ({ commands }) => {\n if (!isValidYoutubeUrl(options.src)) {\n return false\n }\n\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n addPasteRules() {\n if (!this.options.addPasteHandler) {\n return []\n }\n\n return [\n nodePasteRule({\n find: YOUTUBE_REGEX_GLOBAL,\n type: this.type,\n getAttributes: match => {\n return { src: match.input }\n },\n }),\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const embedUrl = getEmbedUrlFromYoutubeUrl({\n url: HTMLAttributes.src,\n allowFullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n controls: this.options.controls,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n nocookie: this.options.nocookie,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n startAt: HTMLAttributes.start || 0,\n rel: this.options.rel,\n })\n\n HTMLAttributes.src = embedUrl\n\n return [\n 'div',\n { 'data-youtube-video': '' },\n [\n 'iframe',\n mergeAttributes(\n this.options.HTMLAttributes,\n {\n width: this.options.width,\n height: this.options.height,\n allowfullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n rel: this.options.rel,\n },\n HTMLAttributes,\n ),\n ],\n ]\n },\n})\n"],"names":[],"mappings":";;AAAO,MAAM,aAAa,GAAG,yIAAyI;AAC/J,MAAM,oBAAoB,GAAG,0IAA0I;AAEvK,MAAM,iBAAiB,GAAG,CAAC,GAAW,KAAI;AAC/C,IAAA,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC;AACjC,CAAC;AAwBM,MAAM,kBAAkB,GAAG,CAAC,QAAkB,EAAE,UAAmB,KAAI;IAC5E,IAAI,UAAU,EAAE;AACd,QAAA,OAAO,0DAA0D;;IAEnE,OAAO,QAAQ,GAAG,yCAAyC,GA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= (url) => {
10
10
  return url.match(YOUTUBE_REGEX);
11
11
  };
12
- const getYoutubeEmbedUrl = (nocookie) => {
12
+ const getYoutubeEmbedUrl = (nocookie, isPlaylist) => {
13
+ if (isPlaylist) {
14
+ return 'https://www.youtube-nocookie.com/embed/videoseries?list=';
15
+ }
13
16
  return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/';
14
17
  };
15
18
  const getEmbedUrlFromYoutubeUrl = (options) => {
16
- const { url, allowFullscreen, autoplay, ccLanguage, ccLoadPolicy, controls, disableKBcontrols, enableIFrameApi, endTime, interfaceLanguage, ivLoadPolicy, loop, modestBranding, nocookie, origin, playlist, progressBarColor, startAt, } = options;
19
+ const { url, allowFullscreen, autoplay, ccLanguage, ccLoadPolicy, controls, disableKBcontrols, enableIFrameApi, endTime, interfaceLanguage, ivLoadPolicy, loop, modestBranding, nocookie, origin, playlist, progressBarColor, startAt, rel, } = options;
17
20
  if (!isValidYoutubeUrl(url)) {
18
21
  return null;
19
22
  }
@@ -29,12 +32,12 @@
29
32
  }
30
33
  return `${getYoutubeEmbedUrl(nocookie)}${id}`;
31
34
  }
32
- const videoIdRegex = /(?:v=|shorts\/)([-\w]+)/gm;
35
+ const videoIdRegex = /(?:(v|list)=|shorts\/)([-\w]+)/gm;
33
36
  const matches = videoIdRegex.exec(url);
34
- if (!matches || !matches[1]) {
37
+ if (!matches || !matches[2]) {
35
38
  return null;
36
39
  }
37
- let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`;
40
+ let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === 'list')}${matches[2]}`;
38
41
  const params = [];
39
42
  if (allowFullscreen === false) {
40
43
  params.push('fs=0');
@@ -84,8 +87,11 @@
84
87
  if (progressBarColor) {
85
88
  params.push(`color=${progressBarColor}`);
86
89
  }
90
+ if (rel !== undefined) {
91
+ params.push(`rel=${rel}`);
92
+ }
87
93
  if (params.length) {
88
- outputUrl += `?${params.join('&')}`;
94
+ outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`;
89
95
  }
90
96
  return outputUrl;
91
97
  };
@@ -119,6 +125,7 @@
119
125
  playlist: '',
120
126
  progressBarColor: undefined,
121
127
  width: 640,
128
+ rel: 1,
122
129
  };
123
130
  },
124
131
  inline() {
@@ -198,6 +205,7 @@
198
205
  playlist: this.options.playlist,
199
206
  progressBarColor: this.options.progressBarColor,
200
207
  startAt: HTMLAttributes.start || 0,
208
+ rel: this.options.rel,
201
209
  });
202
210
  HTMLAttributes.src = embedUrl;
203
211
  return [
@@ -222,6 +230,7 @@
222
230
  origin: this.options.origin,
223
231
  playlist: this.options.playlist,
224
232
  progressBarColor: this.options.progressBarColor,
233
+ rel: this.options.rel,
225
234
  }, HTMLAttributes),
226
235
  ],
227
236
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/utils.ts","../src/youtube.ts"],"sourcesContent":["export const YOUTUBE_REGEX = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/\nexport const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/g\n\nexport const isValidYoutubeUrl = (url: string) => {\n return url.match(YOUTUBE_REGEX)\n}\n\nexport interface GetEmbedUrlOptions {\n url: string;\n allowFullscreen?: boolean;\n autoplay?: boolean;\n ccLanguage?:string;\n ccLoadPolicy?:boolean;\n controls?: boolean;\n disableKBcontrols?: boolean,\n enableIFrameApi?: boolean;\n endTime?: number;\n interfaceLanguage?: string;\n ivLoadPolicy?: number;\n loop?: boolean;\n modestBranding?: boolean;\n nocookie?: boolean;\n origin?: string;\n playlist?: string;\n progressBarColor?: string;\n startAt?: number;\n}\n\nexport const getYoutubeEmbedUrl = (nocookie?: boolean) => {\n return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/'\n}\n\nexport const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {\n const {\n url,\n allowFullscreen,\n autoplay,\n ccLanguage,\n ccLoadPolicy,\n controls,\n disableKBcontrols,\n enableIFrameApi,\n endTime,\n interfaceLanguage,\n ivLoadPolicy,\n loop,\n modestBranding,\n nocookie,\n origin,\n playlist,\n progressBarColor,\n startAt,\n } = options\n\n if (!isValidYoutubeUrl(url)) {\n return null\n }\n\n // if is already an embed url, return it\n if (url.includes('/embed/')) {\n return url\n }\n\n // if is a youtu.be url, get the id after the /\n if (url.includes('youtu.be')) {\n const id = url.split('/').pop()\n\n if (!id) {\n return null\n }\n return `${getYoutubeEmbedUrl(nocookie)}${id}`\n }\n\n const videoIdRegex = /(?:v=|shorts\\/)([-\\w]+)/gm\n const matches = videoIdRegex.exec(url)\n\n if (!matches || !matches[1]) {\n return null\n }\n\n let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`\n\n const params = []\n\n if (allowFullscreen === false) {\n params.push('fs=0')\n }\n\n if (autoplay) {\n params.push('autoplay=1')\n }\n\n if (ccLanguage) {\n params.push(`cc_lang_pref=${ccLanguage}`)\n }\n\n if (ccLoadPolicy) {\n params.push('cc_load_policy=1')\n }\n\n if (!controls) {\n params.push('controls=0')\n }\n\n if (disableKBcontrols) {\n params.push('disablekb=1')\n }\n\n if (enableIFrameApi) {\n params.push('enablejsapi=1')\n }\n\n if (endTime) {\n params.push(`end=${endTime}`)\n }\n\n if (interfaceLanguage) {\n params.push(`hl=${interfaceLanguage}`)\n }\n\n if (ivLoadPolicy) {\n params.push(`iv_load_policy=${ivLoadPolicy}`)\n }\n\n if (loop) {\n params.push('loop=1')\n }\n\n if (modestBranding) {\n params.push('modestbranding=1')\n }\n\n if (origin) {\n params.push(`origin=${origin}`)\n }\n\n if (playlist) {\n params.push(`playlist=${playlist}`)\n }\n\n if (startAt) {\n params.push(`start=${startAt}`)\n }\n\n if (progressBarColor) {\n params.push(`color=${progressBarColor}`)\n }\n\n if (params.length) {\n outputUrl += `?${params.join('&')}`\n }\n\n return outputUrl\n}\n","import { mergeAttributes, Node, nodePasteRule } from '@tiptap/core'\n\nimport { getEmbedUrlFromYoutubeUrl, isValidYoutubeUrl, YOUTUBE_REGEX_GLOBAL } from './utils.js'\n\nexport interface YoutubeOptions {\n /**\n * Controls if the paste handler for youtube videos should be added.\n * @default true\n * @example false\n */\n addPasteHandler: boolean;\n\n /**\n * Controls if the youtube video should be allowed to go fullscreen.\n * @default true\n * @example false\n */\n allowFullscreen: boolean;\n\n /**\n * Controls if the youtube video should autoplay.\n * @default false\n * @example true\n */\n autoplay: boolean;\n\n /**\n * The language of the captions shown in the youtube video.\n * @default undefined\n * @example 'en'\n */\n ccLanguage?: string;\n\n /**\n * Controls if the captions should be shown in the youtube video.\n * @default undefined\n * @example true\n */\n ccLoadPolicy?: boolean;\n\n /**\n * Controls if the controls should be shown in the youtube video.\n * @default true\n * @example false\n */\n controls: boolean;\n\n /**\n * Controls if the keyboard controls should be disabled in the youtube video.\n * @default false\n * @example true\n */\n disableKBcontrols: boolean;\n\n /**\n * Controls if the iframe api should be enabled in the youtube video.\n * @default false\n * @example true\n */\n enableIFrameApi: boolean;\n\n /**\n * The end time of the youtube video.\n * @default 0\n * @example 120\n */\n endTime: number;\n\n /**\n * The height of the youtube video.\n * @default 480\n * @example 720\n */\n height: number;\n\n /**\n * The language of the youtube video.\n * @default undefined\n * @example 'en'\n */\n interfaceLanguage?: string;\n\n /**\n * Controls if the video annotations should be shown in the youtube video.\n * @default 0\n * @example 1\n */\n ivLoadPolicy: number;\n\n /**\n * Controls if the youtube video should loop.\n * @default false\n * @example true\n */\n loop: boolean;\n\n /**\n * Controls if the youtube video should show a small youtube logo.\n * @default false\n * @example true\n */\n modestBranding: boolean;\n\n /**\n * The HTML attributes for a youtube video node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>;\n\n /**\n * Controls if the youtube node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean;\n\n /**\n * Controls if the youtube video should be loaded from youtube-nocookie.com.\n * @default false\n * @example true\n */\n nocookie: boolean;\n\n /**\n * The origin of the youtube video.\n * @default ''\n * @example 'https://tiptap.dev'\n */\n origin: string;\n\n /**\n * The playlist of the youtube video.\n * @default ''\n * @example 'PLQg6GaokU5CwiVmsZ0dZm6VeIg0V5z1tK'\n */\n playlist: string;\n\n /**\n * The color of the youtube video progress bar.\n * @default undefined\n * @example 'red'\n */\n progressBarColor?: string;\n\n /**\n * The width of the youtube video.\n * @default 640\n * @example 1280\n */\n width: number;\n}\n\n/**\n * The options for setting a youtube video.\n */\ntype SetYoutubeVideoOptions = { src: string, width?: number, height?: number, start?: number }\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n youtube: {\n /**\n * Insert a youtube video\n * @param options The youtube video attributes\n * @example editor.commands.setYoutubeVideo({ src: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' })\n */\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ReturnType,\n }\n }\n}\n\n/**\n * This extension adds support for youtube videos.\n * @see https://www.tiptap.dev/api/nodes/youtube\n */\nexport const Youtube = Node.create<YoutubeOptions>({\n name: 'youtube',\n\n addOptions() {\n return {\n addPasteHandler: true,\n allowFullscreen: true,\n autoplay: false,\n ccLanguage: undefined,\n ccLoadPolicy: undefined,\n controls: true,\n disableKBcontrols: false,\n enableIFrameApi: false,\n endTime: 0,\n height: 480,\n interfaceLanguage: undefined,\n ivLoadPolicy: 0,\n loop: false,\n modestBranding: false,\n HTMLAttributes: {},\n inline: false,\n nocookie: false,\n origin: '',\n playlist: '',\n progressBarColor: undefined,\n width: 640,\n }\n },\n\n inline() {\n return this.options.inline\n },\n\n group() {\n return this.options.inline ? 'inline' : 'block'\n },\n\n draggable: true,\n\n addAttributes() {\n return {\n src: {\n default: null,\n },\n start: {\n default: 0,\n },\n width: {\n default: this.options.width,\n },\n height: {\n default: this.options.height,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'div[data-youtube-video] iframe',\n },\n ]\n },\n\n addCommands() {\n return {\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ({ commands }) => {\n if (!isValidYoutubeUrl(options.src)) {\n return false\n }\n\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n addPasteRules() {\n if (!this.options.addPasteHandler) {\n return []\n }\n\n return [\n nodePasteRule({\n find: YOUTUBE_REGEX_GLOBAL,\n type: this.type,\n getAttributes: match => {\n return { src: match.input }\n },\n }),\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const embedUrl = getEmbedUrlFromYoutubeUrl({\n url: HTMLAttributes.src,\n allowFullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n controls: this.options.controls,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n nocookie: this.options.nocookie,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n startAt: HTMLAttributes.start || 0,\n })\n\n HTMLAttributes.src = embedUrl\n\n return [\n 'div',\n { 'data-youtube-video': '' },\n [\n 'iframe',\n mergeAttributes(\n this.options.HTMLAttributes,\n {\n width: this.options.width,\n height: this.options.height,\n allowfullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n },\n HTMLAttributes,\n ),\n ],\n ]\n },\n})\n"],"names":["Node","nodePasteRule","mergeAttributes"],"mappings":";;;;;;EAAO,MAAM,aAAa,GAAG,yIAAyI;EAC/J,MAAM,oBAAoB,GAAG,0IAA0I;EAEvK,MAAM,iBAAiB,GAAG,CAAC,GAAW,KAAI;EAC/C,IAAA,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC;EACjC,CAAC;EAuBM,MAAM,kBAAkB,GAAG,CAAC,QAAkB,KAAI;MACvD,OAAO,QAAQ,GAAG,yCAAyC,GAAG,gCAAgC;EAChG,CAAC;EAEM,MAAM,yBAAyB,GAAG,CAAC,OAA2B,KAAI;EACvE,IAAA,MAAM,EACJ,GAAG,EACH,eAAe,EACf,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,OAAO,EACP,iBAAiB,EACjB,YAAY,EACZ,IAAI,EACJ,cAAc,EACd,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,OAAO,GACR,GAAG,OAAO;EAEX,IAAA,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE;EAC3B,QAAA,OAAO,IAAI;;;EAIb,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;EAC3B,QAAA,OAAO,GAAG;;;EAIZ,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;UAC5B,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE;UAE/B,IAAI,CAAC,EAAE,EAAE;EACP,YAAA,OAAO,IAAI;;UAEb,OAAO,CAAA,EAAG,kBAAkB,CAAC,QAAQ,CAAC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iBAAA,EACD,cAAc,CACf;EACF,aAAA;WACF;OACF;EACF,CAAA;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/utils.ts","../src/youtube.ts"],"sourcesContent":["export const YOUTUBE_REGEX = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/\nexport const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/g\n\nexport const isValidYoutubeUrl = (url: string) => {\n return url.match(YOUTUBE_REGEX)\n}\n\nexport interface GetEmbedUrlOptions {\n url: string;\n allowFullscreen?: boolean;\n autoplay?: boolean;\n ccLanguage?:string;\n ccLoadPolicy?:boolean;\n controls?: boolean;\n disableKBcontrols?: boolean,\n enableIFrameApi?: boolean;\n endTime?: number;\n interfaceLanguage?: string;\n ivLoadPolicy?: number;\n loop?: boolean;\n modestBranding?: boolean;\n nocookie?: boolean;\n origin?: string;\n playlist?: string;\n progressBarColor?: string;\n startAt?: number;\n rel?: number;\n}\n\nexport const getYoutubeEmbedUrl = (nocookie?: boolean, isPlaylist?:boolean) => {\n if (isPlaylist) {\n return 'https://www.youtube-nocookie.com/embed/videoseries?list='\n }\n return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/'\n}\n\nexport const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {\n const {\n url,\n allowFullscreen,\n autoplay,\n ccLanguage,\n ccLoadPolicy,\n controls,\n disableKBcontrols,\n enableIFrameApi,\n endTime,\n interfaceLanguage,\n ivLoadPolicy,\n loop,\n modestBranding,\n nocookie,\n origin,\n playlist,\n progressBarColor,\n startAt,\n rel,\n } = options\n\n if (!isValidYoutubeUrl(url)) {\n return null\n }\n\n // if is already an embed url, return it\n if (url.includes('/embed/')) {\n return url\n }\n\n // if is a youtu.be url, get the id after the /\n if (url.includes('youtu.be')) {\n const id = url.split('/').pop()\n\n if (!id) {\n return null\n }\n return `${getYoutubeEmbedUrl(nocookie)}${id}`\n }\n\n const videoIdRegex = /(?:(v|list)=|shorts\\/)([-\\w]+)/gm\n const matches = videoIdRegex.exec(url)\n\n if (!matches || !matches[2]) {\n return null\n }\n\n let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === 'list')}${matches[2]}`\n\n const params = []\n\n if (allowFullscreen === false) {\n params.push('fs=0')\n }\n\n if (autoplay) {\n params.push('autoplay=1')\n }\n\n if (ccLanguage) {\n params.push(`cc_lang_pref=${ccLanguage}`)\n }\n\n if (ccLoadPolicy) {\n params.push('cc_load_policy=1')\n }\n\n if (!controls) {\n params.push('controls=0')\n }\n\n if (disableKBcontrols) {\n params.push('disablekb=1')\n }\n\n if (enableIFrameApi) {\n params.push('enablejsapi=1')\n }\n\n if (endTime) {\n params.push(`end=${endTime}`)\n }\n\n if (interfaceLanguage) {\n params.push(`hl=${interfaceLanguage}`)\n }\n\n if (ivLoadPolicy) {\n params.push(`iv_load_policy=${ivLoadPolicy}`)\n }\n\n if (loop) {\n params.push('loop=1')\n }\n\n if (modestBranding) {\n params.push('modestbranding=1')\n }\n\n if (origin) {\n params.push(`origin=${origin}`)\n }\n\n if (playlist) {\n params.push(`playlist=${playlist}`)\n }\n\n if (startAt) {\n params.push(`start=${startAt}`)\n }\n\n if (progressBarColor) {\n params.push(`color=${progressBarColor}`)\n }\n\n if (rel !== undefined) {\n params.push(`rel=${rel}`)\n }\n\n if (params.length) {\n outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`\n }\n\n return outputUrl\n}\n","import { mergeAttributes, Node, nodePasteRule } from '@tiptap/core'\n\nimport { getEmbedUrlFromYoutubeUrl, isValidYoutubeUrl, YOUTUBE_REGEX_GLOBAL } from './utils.js'\n\nexport interface YoutubeOptions {\n /**\n * Controls if the paste handler for youtube videos should be added.\n * @default true\n * @example false\n */\n addPasteHandler: boolean;\n\n /**\n * Controls if the youtube video should be allowed to go fullscreen.\n * @default true\n * @example false\n */\n allowFullscreen: boolean;\n\n /**\n * Controls if the youtube video should autoplay.\n * @default false\n * @example true\n */\n autoplay: boolean;\n\n /**\n * The language of the captions shown in the youtube video.\n * @default undefined\n * @example 'en'\n */\n ccLanguage?: string;\n\n /**\n * Controls if the captions should be shown in the youtube video.\n * @default undefined\n * @example true\n */\n ccLoadPolicy?: boolean;\n\n /**\n * Controls if the controls should be shown in the youtube video.\n * @default true\n * @example false\n */\n controls: boolean;\n\n /**\n * Controls if the keyboard controls should be disabled in the youtube video.\n * @default false\n * @example true\n */\n disableKBcontrols: boolean;\n\n /**\n * Controls if the iframe api should be enabled in the youtube video.\n * @default false\n * @example true\n */\n enableIFrameApi: boolean;\n\n /**\n * The end time of the youtube video.\n * @default 0\n * @example 120\n */\n endTime: number;\n\n /**\n * The height of the youtube video.\n * @default 480\n * @example 720\n */\n height: number;\n\n /**\n * The language of the youtube video.\n * @default undefined\n * @example 'en'\n */\n interfaceLanguage?: string;\n\n /**\n * Controls if the video annotations should be shown in the youtube video.\n * @default 0\n * @example 1\n */\n ivLoadPolicy: number;\n\n /**\n * Controls if the youtube video should loop.\n * @default false\n * @example true\n */\n loop: boolean;\n\n /**\n * Controls if the youtube video should show a small youtube logo.\n * @default false\n * @example true\n */\n modestBranding: boolean;\n\n /**\n * The HTML attributes for a youtube video node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>;\n\n /**\n * Controls if the youtube node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean;\n\n /**\n * Controls if the youtube video should be loaded from youtube-nocookie.com.\n * @default false\n * @example true\n */\n nocookie: boolean;\n\n /**\n * The origin of the youtube video.\n * @default ''\n * @example 'https://tiptap.dev'\n */\n origin: string;\n\n /**\n * The playlist of the youtube video.\n * @default ''\n * @example 'PLQg6GaokU5CwiVmsZ0dZm6VeIg0V5z1tK'\n */\n playlist: string;\n\n /**\n * The color of the youtube video progress bar.\n * @default undefined\n * @example 'red'\n */\n progressBarColor?: string;\n\n /**\n * The width of the youtube video.\n * @default 640\n * @example 1280\n */\n width: number;\n\n /**\n * Controls if the related youtube videos at the end are from the same channel.\n * @default 1\n * @example 0\n */\n rel: number;\n}\n\n/**\n * The options for setting a youtube video.\n */\ntype SetYoutubeVideoOptions = { src: string, width?: number, height?: number, start?: number }\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n youtube: {\n /**\n * Insert a youtube video\n * @param options The youtube video attributes\n * @example editor.commands.setYoutubeVideo({ src: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' })\n */\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ReturnType,\n }\n }\n}\n\n/**\n * This extension adds support for youtube videos.\n * @see https://www.tiptap.dev/api/nodes/youtube\n */\nexport const Youtube = Node.create<YoutubeOptions>({\n name: 'youtube',\n\n addOptions() {\n return {\n addPasteHandler: true,\n allowFullscreen: true,\n autoplay: false,\n ccLanguage: undefined,\n ccLoadPolicy: undefined,\n controls: true,\n disableKBcontrols: false,\n enableIFrameApi: false,\n endTime: 0,\n height: 480,\n interfaceLanguage: undefined,\n ivLoadPolicy: 0,\n loop: false,\n modestBranding: false,\n HTMLAttributes: {},\n inline: false,\n nocookie: false,\n origin: '',\n playlist: '',\n progressBarColor: undefined,\n width: 640,\n rel: 1,\n }\n },\n\n inline() {\n return this.options.inline\n },\n\n group() {\n return this.options.inline ? 'inline' : 'block'\n },\n\n draggable: true,\n\n addAttributes() {\n return {\n src: {\n default: null,\n },\n start: {\n default: 0,\n },\n width: {\n default: this.options.width,\n },\n height: {\n default: this.options.height,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'div[data-youtube-video] iframe',\n },\n ]\n },\n\n addCommands() {\n return {\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ({ commands }) => {\n if (!isValidYoutubeUrl(options.src)) {\n return false\n }\n\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n addPasteRules() {\n if (!this.options.addPasteHandler) {\n return []\n }\n\n return [\n nodePasteRule({\n find: YOUTUBE_REGEX_GLOBAL,\n type: this.type,\n getAttributes: match => {\n return { src: match.input }\n },\n }),\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const embedUrl = getEmbedUrlFromYoutubeUrl({\n url: HTMLAttributes.src,\n allowFullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n controls: this.options.controls,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n nocookie: this.options.nocookie,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n startAt: HTMLAttributes.start || 0,\n rel: this.options.rel,\n })\n\n HTMLAttributes.src = embedUrl\n\n return [\n 'div',\n { 'data-youtube-video': '' },\n [\n 'iframe',\n mergeAttributes(\n this.options.HTMLAttributes,\n {\n width: this.options.width,\n height: this.options.height,\n allowfullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n rel: this.options.rel,\n },\n HTMLAttributes,\n ),\n ],\n ]\n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AI,CAAC,OAAO,CAAC,cAAc;EAC3C,oBAAA,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;EAC3B,oBAAA,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;EAC/B,oBAAA,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB;EAC/C,oBAAA,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;EACtB,iBAAA,EACD,cAAc,CACf;EACF,aAAA;WACF;OACF;EACF,CAAA;;;;;;;;;;;"}
package/dist/utils.d.ts CHANGED
@@ -20,7 +20,8 @@ export interface GetEmbedUrlOptions {
20
20
  playlist?: string;
21
21
  progressBarColor?: string;
22
22
  startAt?: number;
23
+ rel?: number;
23
24
  }
24
- export declare const getYoutubeEmbedUrl: (nocookie?: boolean) => "https://www.youtube-nocookie.com/embed/" | "https://www.youtube.com/embed/";
25
+ export declare const getYoutubeEmbedUrl: (nocookie?: boolean, isPlaylist?: boolean) => "https://www.youtube-nocookie.com/embed/videoseries?list=" | "https://www.youtube-nocookie.com/embed/" | "https://www.youtube.com/embed/";
25
26
  export declare const getEmbedUrlFromYoutubeUrl: (options: GetEmbedUrlOptions) => string | null;
26
27
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAA4I,CAAA;AACtK,eAAO,MAAM,oBAAoB,QAA6I,CAAA;AAE9K,eAAO,MAAM,iBAAiB,QAAS,MAAM,4BAE5C,CAAA;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAC,MAAM,CAAC;IACnB,YAAY,CAAC,EAAC,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;I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c,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,kBAAkB,cAAe,OAAO,eAAc,OAAO,8IAKzE,CAAA;AAED,eAAO,MAAM,yBAAyB,YAAa,kBAAkB,kBA8HpE,CAAA"}
package/dist/youtube.d.ts CHANGED
@@ -126,6 +126,12 @@ export interface YoutubeOptions {
126
126
  * @example 1280
127
127
  */
128
128
  width: number;
129
+ /**
130
+ * Controls if the related youtube videos at the end are from the same channel.
131
+ * @default 1
132
+ * @example 0
133
+ */
134
+ rel: number;
129
135
  }
130
136
  /**
131
137
  * The options for setting a youtube video.
@@ -1 +1 @@
1
- {"version":3,"file":"youtube.d.ts","sourceRoot":"","sources":["../src/youtube.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,IAAI,EAAiB,MAAM,cAAc,CAAA;AAInE,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,eAAe,EAAE,OAAO,CAAC;IAEzB;;;;OAIG;IACH,eAAe,EAAE,OAAO,CAAC;IAEzB;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,iBAAiB,EAAE,OAAO,CAAC;IAE3B;;;;OAIG;IACH,eAAe,EAAE,OAAO,CAAC;IAEzB;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;;O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eAAe,EAAE,CAAC,OAAO,EAAE,sBAAsB,KAAK,UAAU,CAAC;SAClE,CAAA;KACF;CACF;AAED;;;GAGG;AACH,eAAO,MAAM,OAAO,2BAwJlB,CAAA"}
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.11.5",
4
+ "version": "2.11.6",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -29,7 +29,7 @@
29
29
  "dist"
30
30
  ],
31
31
  "devDependencies": {
32
- "@tiptap/core": "^2.11.5"
32
+ "@tiptap/core": "^2.11.6"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@tiptap/core": "^2.7.0"
package/src/utils.ts CHANGED
@@ -24,9 +24,13 @@ export interface GetEmbedUrlOptions {
24
24
  playlist?: string;
25
25
  progressBarColor?: string;
26
26
  startAt?: number;
27
+ rel?: number;
27
28
  }
28
29
 
29
- export const getYoutubeEmbedUrl = (nocookie?: boolean) => {
30
+ export const getYoutubeEmbedUrl = (nocookie?: boolean, isPlaylist?:boolean) => {
31
+ if (isPlaylist) {
32
+ return 'https://www.youtube-nocookie.com/embed/videoseries?list='
33
+ }
30
34
  return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/'
31
35
  }
32
36
 
@@ -50,6 +54,7 @@ export const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {
50
54
  playlist,
51
55
  progressBarColor,
52
56
  startAt,
57
+ rel,
53
58
  } = options
54
59
 
55
60
  if (!isValidYoutubeUrl(url)) {
@@ -71,14 +76,14 @@ export const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {
71
76
  return `${getYoutubeEmbedUrl(nocookie)}${id}`
72
77
  }
73
78
 
74
- const videoIdRegex = /(?:v=|shorts\/)([-\w]+)/gm
79
+ const videoIdRegex = /(?:(v|list)=|shorts\/)([-\w]+)/gm
75
80
  const matches = videoIdRegex.exec(url)
76
81
 
77
- if (!matches || !matches[1]) {
82
+ if (!matches || !matches[2]) {
78
83
  return null
79
84
  }
80
85
 
81
- let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`
86
+ let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === 'list')}${matches[2]}`
82
87
 
83
88
  const params = []
84
89
 
@@ -146,8 +151,12 @@ export const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {
146
151
  params.push(`color=${progressBarColor}`)
147
152
  }
148
153
 
154
+ if (rel !== undefined) {
155
+ params.push(`rel=${rel}`)
156
+ }
157
+
149
158
  if (params.length) {
150
- outputUrl += `?${params.join('&')}`
159
+ outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`
151
160
  }
152
161
 
153
162
  return outputUrl
package/src/youtube.ts CHANGED
@@ -149,6 +149,13 @@ export interface YoutubeOptions {
149
149
  * @example 1280
150
150
  */
151
151
  width: number;
152
+
153
+ /**
154
+ * Controls if the related youtube videos at the end are from the same channel.
155
+ * @default 1
156
+ * @example 0
157
+ */
158
+ rel: number;
152
159
  }
153
160
 
154
161
  /**
@@ -199,6 +206,7 @@ export const Youtube = Node.create<YoutubeOptions>({
199
206
  playlist: '',
200
207
  progressBarColor: undefined,
201
208
  width: 640,
209
+ rel: 1,
202
210
  }
203
211
  },
204
212
 
@@ -288,6 +296,7 @@ export const Youtube = Node.create<YoutubeOptions>({
288
296
  playlist: this.options.playlist,
289
297
  progressBarColor: this.options.progressBarColor,
290
298
  startAt: HTMLAttributes.start || 0,
299
+ rel: this.options.rel,
291
300
  })
292
301
 
293
302
  HTMLAttributes.src = embedUrl
@@ -316,6 +325,7 @@ export const Youtube = Node.create<YoutubeOptions>({
316
325
  origin: this.options.origin,
317
326
  playlist: this.options.playlist,
318
327
  progressBarColor: this.options.progressBarColor,
328
+ rel: this.options.rel,
319
329
  },
320
330
  HTMLAttributes,
321
331
  ),