Socket
Socket
Sign inDemoInstall

@tiptap/extension-youtube

Package Overview
Dependencies
Maintainers
5
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tiptap/extension-youtube - npm Package Compare versions

Comparing version 3.0.0-next.0 to 3.0.0-next.1

dist/index.d.cts

439

dist/index.js

@@ -1,185 +0,229 @@

import { Node, nodePasteRule, mergeAttributes } from '@tiptap/core';
// src/youtube.ts
import { mergeAttributes, Node, nodePasteRule } from "@tiptap/core";
const YOUTUBE_REGEX = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be|youtube-nocookie\.com)\/(?!channel\/)(?!@)(.+)?$/;
const YOUTUBE_REGEX_GLOBAL = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be)\/(?!channel\/)(?!@)(.+)?$/g;
const isValidYoutubeUrl = (url) => {
return url.match(YOUTUBE_REGEX);
// src/utils.ts
var YOUTUBE_REGEX = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be|youtube-nocookie\.com)\/(?!channel\/)(?!@)(.+)?$/;
var YOUTUBE_REGEX_GLOBAL = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be)\/(?!channel\/)(?!@)(.+)?$/g;
var isValidYoutubeUrl = (url) => {
return url.match(YOUTUBE_REGEX);
};
const getYoutubeEmbedUrl = (nocookie) => {
return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/';
var getYoutubeEmbedUrl = (nocookie) => {
return nocookie ? "https://www.youtube-nocookie.com/embed/" : "https://www.youtube.com/embed/";
};
const getEmbedUrlFromYoutubeUrl = (options) => {
const { url, allowFullscreen, autoplay, ccLanguage, ccLoadPolicy, controls, disableKBcontrols, enableIFrameApi, endTime, interfaceLanguage, ivLoadPolicy, loop, modestBranding, nocookie, origin, playlist, progressBarColor, startAt, } = options;
if (!isValidYoutubeUrl(url)) {
return null;
var getEmbedUrlFromYoutubeUrl = (options) => {
const {
url,
allowFullscreen,
autoplay,
ccLanguage,
ccLoadPolicy,
controls,
disableKBcontrols,
enableIFrameApi,
endTime,
interfaceLanguage,
ivLoadPolicy,
loop,
modestBranding,
nocookie,
origin,
playlist,
progressBarColor,
startAt
} = options;
if (!isValidYoutubeUrl(url)) {
return null;
}
if (url.includes("/embed/")) {
return url;
}
if (url.includes("youtu.be")) {
const id = url.split("/").pop();
if (!id) {
return null;
}
// if is already an embed url, return it
if (url.includes('/embed/')) {
return url;
}
// if is a youtu.be url, get the id after the /
if (url.includes('youtu.be')) {
const id = url.split('/').pop();
if (!id) {
return null;
}
return `${getYoutubeEmbedUrl(nocookie)}${id}`;
}
const videoIdRegex = /(?:v=|shorts\/)([-\w]+)/gm;
const matches = videoIdRegex.exec(url);
if (!matches || !matches[1]) {
return null;
}
let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`;
const params = [];
if (allowFullscreen === false) {
params.push('fs=0');
}
if (autoplay) {
params.push('autoplay=1');
}
if (ccLanguage) {
params.push(`cc_lang_pref=${ccLanguage}`);
}
if (ccLoadPolicy) {
params.push('cc_load_policy=1');
}
if (!controls) {
params.push('controls=0');
}
if (disableKBcontrols) {
params.push('disablekb=1');
}
if (enableIFrameApi) {
params.push('enablejsapi=1');
}
if (endTime) {
params.push(`end=${endTime}`);
}
if (interfaceLanguage) {
params.push(`hl=${interfaceLanguage}`);
}
if (ivLoadPolicy) {
params.push(`iv_load_policy=${ivLoadPolicy}`);
}
if (loop) {
params.push('loop=1');
}
if (modestBranding) {
params.push('modestbranding=1');
}
if (origin) {
params.push(`origin=${origin}`);
}
if (playlist) {
params.push(`playlist=${playlist}`);
}
if (startAt) {
params.push(`start=${startAt}`);
}
if (progressBarColor) {
params.push(`color=${progressBarColor}`);
}
if (params.length) {
outputUrl += `?${params.join('&')}`;
}
return outputUrl;
return `${getYoutubeEmbedUrl(nocookie)}${id}`;
}
const videoIdRegex = /(?:v=|shorts\/)([-\w]+)/gm;
const matches = videoIdRegex.exec(url);
if (!matches || !matches[1]) {
return null;
}
let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`;
const params = [];
if (allowFullscreen === false) {
params.push("fs=0");
}
if (autoplay) {
params.push("autoplay=1");
}
if (ccLanguage) {
params.push(`cc_lang_pref=${ccLanguage}`);
}
if (ccLoadPolicy) {
params.push("cc_load_policy=1");
}
if (!controls) {
params.push("controls=0");
}
if (disableKBcontrols) {
params.push("disablekb=1");
}
if (enableIFrameApi) {
params.push("enablejsapi=1");
}
if (endTime) {
params.push(`end=${endTime}`);
}
if (interfaceLanguage) {
params.push(`hl=${interfaceLanguage}`);
}
if (ivLoadPolicy) {
params.push(`iv_load_policy=${ivLoadPolicy}`);
}
if (loop) {
params.push("loop=1");
}
if (modestBranding) {
params.push("modestbranding=1");
}
if (origin) {
params.push(`origin=${origin}`);
}
if (playlist) {
params.push(`playlist=${playlist}`);
}
if (startAt) {
params.push(`start=${startAt}`);
}
if (progressBarColor) {
params.push(`color=${progressBarColor}`);
}
if (params.length) {
outputUrl += `?${params.join("&")}`;
}
return outputUrl;
};
/**
* This extension adds support for youtube videos.
* @see https://www.tiptap.dev/api/nodes/youtube
*/
const Youtube = Node.create({
name: 'youtube',
addOptions() {
return {
addPasteHandler: true,
allowFullscreen: true,
autoplay: false,
ccLanguage: undefined,
ccLoadPolicy: undefined,
controls: true,
disableKBcontrols: false,
enableIFrameApi: false,
endTime: 0,
height: 480,
interfaceLanguage: undefined,
ivLoadPolicy: 0,
loop: false,
modestBranding: false,
HTMLAttributes: {},
inline: false,
nocookie: false,
origin: '',
playlist: '',
progressBarColor: undefined,
width: 640,
};
},
inline() {
return this.options.inline;
},
group() {
return this.options.inline ? 'inline' : 'block';
},
draggable: true,
addAttributes() {
return {
src: {
default: null,
},
start: {
default: 0,
},
width: {
default: this.options.width,
},
height: {
default: this.options.height,
},
};
},
parseHTML() {
return [
{
tag: 'div[data-youtube-video] iframe',
},
];
},
addCommands() {
return {
setYoutubeVideo: (options) => ({ commands }) => {
if (!isValidYoutubeUrl(options.src)) {
return false;
}
return commands.insertContent({
type: this.name,
attrs: options,
});
},
};
},
addPasteRules() {
if (!this.options.addPasteHandler) {
return [];
// src/youtube.ts
var Youtube = Node.create({
name: "youtube",
addOptions() {
return {
addPasteHandler: true,
allowFullscreen: true,
autoplay: false,
ccLanguage: void 0,
ccLoadPolicy: void 0,
controls: true,
disableKBcontrols: false,
enableIFrameApi: false,
endTime: 0,
height: 480,
interfaceLanguage: void 0,
ivLoadPolicy: 0,
loop: false,
modestBranding: false,
HTMLAttributes: {},
inline: false,
nocookie: false,
origin: "",
playlist: "",
progressBarColor: void 0,
width: 640
};
},
inline() {
return this.options.inline;
},
group() {
return this.options.inline ? "inline" : "block";
},
draggable: true,
addAttributes() {
return {
src: {
default: null
},
start: {
default: 0
},
width: {
default: this.options.width
},
height: {
default: this.options.height
}
};
},
parseHTML() {
return [
{
tag: "div[data-youtube-video] iframe"
}
];
},
addCommands() {
return {
setYoutubeVideo: (options) => ({ commands }) => {
if (!isValidYoutubeUrl(options.src)) {
return false;
}
return [
nodePasteRule({
find: YOUTUBE_REGEX_GLOBAL,
type: this.type,
getAttributes: match => {
return { src: match.input };
},
}),
];
},
renderHTML({ HTMLAttributes }) {
const embedUrl = getEmbedUrlFromYoutubeUrl({
url: HTMLAttributes.src,
allowFullscreen: this.options.allowFullscreen,
return commands.insertContent({
type: this.name,
attrs: options
});
}
};
},
addPasteRules() {
if (!this.options.addPasteHandler) {
return [];
}
return [
nodePasteRule({
find: YOUTUBE_REGEX_GLOBAL,
type: this.type,
getAttributes: (match) => {
return { src: match.input };
}
})
];
},
renderHTML({ HTMLAttributes }) {
const embedUrl = getEmbedUrlFromYoutubeUrl({
url: HTMLAttributes.src,
allowFullscreen: this.options.allowFullscreen,
autoplay: this.options.autoplay,
ccLanguage: this.options.ccLanguage,
ccLoadPolicy: this.options.ccLoadPolicy,
controls: this.options.controls,
disableKBcontrols: this.options.disableKBcontrols,
enableIFrameApi: this.options.enableIFrameApi,
endTime: this.options.endTime,
interfaceLanguage: this.options.interfaceLanguage,
ivLoadPolicy: this.options.ivLoadPolicy,
loop: this.options.loop,
modestBranding: this.options.modestBranding,
nocookie: this.options.nocookie,
origin: this.options.origin,
playlist: this.options.playlist,
progressBarColor: this.options.progressBarColor,
startAt: HTMLAttributes.start || 0
});
HTMLAttributes.src = embedUrl;
return [
"div",
{ "data-youtube-video": "" },
[
"iframe",
mergeAttributes(
this.options.HTMLAttributes,
{
width: this.options.width,
height: this.options.height,
allowfullscreen: this.options.allowFullscreen,
autoplay: this.options.autoplay,
ccLanguage: this.options.ccLanguage,
ccLoadPolicy: this.options.ccLoadPolicy,
controls: this.options.controls,
disableKBcontrols: this.options.disableKBcontrols,

@@ -192,38 +236,19 @@ enableIFrameApi: this.options.enableIFrameApi,

modestBranding: this.options.modestBranding,
nocookie: this.options.nocookie,
origin: this.options.origin,
playlist: this.options.playlist,
progressBarColor: this.options.progressBarColor,
startAt: HTMLAttributes.start || 0,
});
HTMLAttributes.src = embedUrl;
return [
'div',
{ 'data-youtube-video': '' },
[
'iframe',
mergeAttributes(this.options.HTMLAttributes, {
width: this.options.width,
height: this.options.height,
allowfullscreen: this.options.allowFullscreen,
autoplay: this.options.autoplay,
ccLanguage: this.options.ccLanguage,
ccLoadPolicy: this.options.ccLoadPolicy,
disableKBcontrols: this.options.disableKBcontrols,
enableIFrameApi: this.options.enableIFrameApi,
endTime: this.options.endTime,
interfaceLanguage: this.options.interfaceLanguage,
ivLoadPolicy: this.options.ivLoadPolicy,
loop: this.options.loop,
modestBranding: this.options.modestBranding,
origin: this.options.origin,
playlist: this.options.playlist,
progressBarColor: this.options.progressBarColor,
}, HTMLAttributes),
],
];
},
progressBarColor: this.options.progressBarColor
},
HTMLAttributes
)
]
];
}
});
export { Youtube, Youtube as default };
//# sourceMappingURL=index.js.map
// src/index.ts
var src_default = Youtube;
export {
Youtube,
src_default as default
};
//# sourceMappingURL=index.js.map
{
"name": "@tiptap/extension-youtube",
"description": "a youtube embed extension for tiptap",
"version": "3.0.0-next.0",
"version": "3.0.0-next.1",
"homepage": "https://tiptap.dev",

@@ -18,3 +18,3 @@ "keywords": [

".": {
"types": "./dist/packages/extension-youtube/src/index.d.ts",
"types": "./dist/index.d.ts",
"import": "./dist/index.js",

@@ -26,4 +26,3 @@ "require": "./dist/index.cjs"

"module": "dist/index.js",
"umd": "dist/index.umd.js",
"types": "dist/packages/extension-youtube/src/index.d.ts",
"types": "dist/index.d.ts",
"files": [

@@ -34,6 +33,6 @@ "src",

"devDependencies": {
"@tiptap/core": "^3.0.0-next.0"
"@tiptap/core": "^3.0.0-next.1"
},
"peerDependencies": {
"@tiptap/core": "^3.0.0-next.0"
"@tiptap/core": "^3.0.0-next.1"
},

@@ -46,5 +45,4 @@ "repository": {

"scripts": {
"clean": "rm -rf dist",
"build": "npm run clean && rollup -c"
"build": "tsup"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc