@tiptap/extension-youtube 3.0.0 → 3.0.1
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/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +266 -209
- package/dist/index.cjs.map +1 -1
- package/dist/{packages/extension-youtube/src/youtube.d.ts → index.d.cts} +11 -3
- package/dist/index.d.ts +164 -0
- package/dist/index.js +241 -206
- package/dist/index.js.map +1 -1
- package/package.json +11 -9
- package/src/utils.ts +36 -25
- package/src/youtube.ts +45 -33
- package/dist/index.umd.js +0 -237
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -161
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -255
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
- package/dist/packages/extension-youtube/src/index.d.ts +0 -3
- package/dist/packages/extension-youtube/src/utils.d.ts +0 -25
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Tiptap GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
# @tiptap/extension-youtube
|
|
2
|
+
|
|
2
3
|
[](https://www.npmjs.com/package/@tiptap/extension-youtube)
|
|
3
4
|
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
|
4
5
|
[](https://www.npmjs.com/package/@tiptap/extension-youtube)
|
|
5
6
|
[](https://github.com/sponsors/ueberdosis)
|
|
6
7
|
|
|
7
8
|
## Introduction
|
|
8
|
-
|
|
9
|
+
|
|
10
|
+
Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as _New York Times_, _The Guardian_ or _Atlassian_.
|
|
9
11
|
|
|
10
12
|
## Official Documentation
|
|
13
|
+
|
|
11
14
|
Documentation can be found on the [Tiptap website](https://tiptap.dev).
|
|
12
15
|
|
|
13
16
|
## License
|
|
17
|
+
|
|
14
18
|
Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
package/dist/index.cjs
CHANGED
|
@@ -1,191 +1,267 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
19
|
|
|
3
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Youtube: () => Youtube,
|
|
24
|
+
default: () => index_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
4
27
|
|
|
5
|
-
|
|
28
|
+
// src/youtube.ts
|
|
29
|
+
var import_core = require("@tiptap/core");
|
|
6
30
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
31
|
+
// src/utils.ts
|
|
32
|
+
var YOUTUBE_REGEX = /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtube\.com|youtu\.be|youtube-nocookie\.com))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/;
|
|
33
|
+
var YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtube\.com|youtu\.be|youtube-nocookie\.com))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/g;
|
|
34
|
+
var isValidYoutubeUrl = (url) => {
|
|
35
|
+
return url.match(YOUTUBE_REGEX);
|
|
11
36
|
};
|
|
12
|
-
|
|
13
|
-
|
|
37
|
+
var getYoutubeEmbedUrl = (nocookie, isPlaylist) => {
|
|
38
|
+
if (isPlaylist) {
|
|
39
|
+
return "https://www.youtube-nocookie.com/embed/videoseries?list=";
|
|
40
|
+
}
|
|
41
|
+
return nocookie ? "https://www.youtube-nocookie.com/embed/" : "https://www.youtube.com/embed/";
|
|
14
42
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
if (ccLoadPolicy) {
|
|
49
|
-
params.push('cc_load_policy=1');
|
|
50
|
-
}
|
|
51
|
-
if (!controls) {
|
|
52
|
-
params.push('controls=0');
|
|
53
|
-
}
|
|
54
|
-
if (disableKBcontrols) {
|
|
55
|
-
params.push('disablekb=1');
|
|
56
|
-
}
|
|
57
|
-
if (enableIFrameApi) {
|
|
58
|
-
params.push('enablejsapi=1');
|
|
59
|
-
}
|
|
60
|
-
if (endTime) {
|
|
61
|
-
params.push(`end=${endTime}`);
|
|
43
|
+
var getEmbedUrlFromYoutubeUrl = (options) => {
|
|
44
|
+
const {
|
|
45
|
+
url,
|
|
46
|
+
allowFullscreen,
|
|
47
|
+
autoplay,
|
|
48
|
+
ccLanguage,
|
|
49
|
+
ccLoadPolicy,
|
|
50
|
+
controls,
|
|
51
|
+
disableKBcontrols,
|
|
52
|
+
enableIFrameApi,
|
|
53
|
+
endTime,
|
|
54
|
+
interfaceLanguage,
|
|
55
|
+
ivLoadPolicy,
|
|
56
|
+
loop,
|
|
57
|
+
modestBranding,
|
|
58
|
+
nocookie,
|
|
59
|
+
origin,
|
|
60
|
+
playlist,
|
|
61
|
+
progressBarColor,
|
|
62
|
+
startAt,
|
|
63
|
+
rel
|
|
64
|
+
} = options;
|
|
65
|
+
if (!isValidYoutubeUrl(url)) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (url.includes("/embed/")) {
|
|
69
|
+
return url;
|
|
70
|
+
}
|
|
71
|
+
if (url.includes("youtu.be")) {
|
|
72
|
+
const id = url.split("/").pop();
|
|
73
|
+
if (!id) {
|
|
74
|
+
return null;
|
|
62
75
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
return `${getYoutubeEmbedUrl(nocookie)}${id}`;
|
|
77
|
+
}
|
|
78
|
+
const videoIdRegex = /(?:(v|list)=|shorts\/)([-\w]+)/gm;
|
|
79
|
+
const matches = videoIdRegex.exec(url);
|
|
80
|
+
if (!matches || !matches[2]) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === "list")}${matches[2]}`;
|
|
84
|
+
const params = [];
|
|
85
|
+
if (allowFullscreen === false) {
|
|
86
|
+
params.push("fs=0");
|
|
87
|
+
}
|
|
88
|
+
if (autoplay) {
|
|
89
|
+
params.push("autoplay=1");
|
|
90
|
+
}
|
|
91
|
+
if (ccLanguage) {
|
|
92
|
+
params.push(`cc_lang_pref=${ccLanguage}`);
|
|
93
|
+
}
|
|
94
|
+
if (ccLoadPolicy) {
|
|
95
|
+
params.push("cc_load_policy=1");
|
|
96
|
+
}
|
|
97
|
+
if (!controls) {
|
|
98
|
+
params.push("controls=0");
|
|
99
|
+
}
|
|
100
|
+
if (disableKBcontrols) {
|
|
101
|
+
params.push("disablekb=1");
|
|
102
|
+
}
|
|
103
|
+
if (enableIFrameApi) {
|
|
104
|
+
params.push("enablejsapi=1");
|
|
105
|
+
}
|
|
106
|
+
if (endTime) {
|
|
107
|
+
params.push(`end=${endTime}`);
|
|
108
|
+
}
|
|
109
|
+
if (interfaceLanguage) {
|
|
110
|
+
params.push(`hl=${interfaceLanguage}`);
|
|
111
|
+
}
|
|
112
|
+
if (ivLoadPolicy) {
|
|
113
|
+
params.push(`iv_load_policy=${ivLoadPolicy}`);
|
|
114
|
+
}
|
|
115
|
+
if (loop) {
|
|
116
|
+
params.push("loop=1");
|
|
117
|
+
}
|
|
118
|
+
if (modestBranding) {
|
|
119
|
+
params.push("modestbranding=1");
|
|
120
|
+
}
|
|
121
|
+
if (origin) {
|
|
122
|
+
params.push(`origin=${origin}`);
|
|
123
|
+
}
|
|
124
|
+
if (playlist) {
|
|
125
|
+
params.push(`playlist=${playlist}`);
|
|
126
|
+
}
|
|
127
|
+
if (startAt) {
|
|
128
|
+
params.push(`start=${startAt}`);
|
|
129
|
+
}
|
|
130
|
+
if (progressBarColor) {
|
|
131
|
+
params.push(`color=${progressBarColor}`);
|
|
132
|
+
}
|
|
133
|
+
if (rel !== void 0) {
|
|
134
|
+
params.push(`rel=${rel}`);
|
|
135
|
+
}
|
|
136
|
+
if (params.length) {
|
|
137
|
+
outputUrl += `${matches[1] === "v" ? "?" : "&"}${params.join("&")}`;
|
|
138
|
+
}
|
|
139
|
+
return outputUrl;
|
|
91
140
|
};
|
|
92
141
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (!isValidYoutubeUrl(options.src)) {
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
return commands.insertContent({
|
|
161
|
-
type: this.name,
|
|
162
|
-
attrs: options,
|
|
163
|
-
});
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
},
|
|
167
|
-
addPasteRules() {
|
|
168
|
-
if (!this.options.addPasteHandler) {
|
|
169
|
-
return [];
|
|
142
|
+
// src/youtube.ts
|
|
143
|
+
var Youtube = import_core.Node.create({
|
|
144
|
+
name: "youtube",
|
|
145
|
+
addOptions() {
|
|
146
|
+
return {
|
|
147
|
+
addPasteHandler: true,
|
|
148
|
+
allowFullscreen: true,
|
|
149
|
+
autoplay: false,
|
|
150
|
+
ccLanguage: void 0,
|
|
151
|
+
ccLoadPolicy: void 0,
|
|
152
|
+
controls: true,
|
|
153
|
+
disableKBcontrols: false,
|
|
154
|
+
enableIFrameApi: false,
|
|
155
|
+
endTime: 0,
|
|
156
|
+
height: 480,
|
|
157
|
+
interfaceLanguage: void 0,
|
|
158
|
+
ivLoadPolicy: 0,
|
|
159
|
+
loop: false,
|
|
160
|
+
modestBranding: false,
|
|
161
|
+
HTMLAttributes: {},
|
|
162
|
+
inline: false,
|
|
163
|
+
nocookie: false,
|
|
164
|
+
origin: "",
|
|
165
|
+
playlist: "",
|
|
166
|
+
progressBarColor: void 0,
|
|
167
|
+
width: 640,
|
|
168
|
+
rel: 1
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
inline() {
|
|
172
|
+
return this.options.inline;
|
|
173
|
+
},
|
|
174
|
+
group() {
|
|
175
|
+
return this.options.inline ? "inline" : "block";
|
|
176
|
+
},
|
|
177
|
+
draggable: true,
|
|
178
|
+
addAttributes() {
|
|
179
|
+
return {
|
|
180
|
+
src: {
|
|
181
|
+
default: null
|
|
182
|
+
},
|
|
183
|
+
start: {
|
|
184
|
+
default: 0
|
|
185
|
+
},
|
|
186
|
+
width: {
|
|
187
|
+
default: this.options.width
|
|
188
|
+
},
|
|
189
|
+
height: {
|
|
190
|
+
default: this.options.height
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
parseHTML() {
|
|
195
|
+
return [
|
|
196
|
+
{
|
|
197
|
+
tag: "div[data-youtube-video] iframe"
|
|
198
|
+
}
|
|
199
|
+
];
|
|
200
|
+
},
|
|
201
|
+
addCommands() {
|
|
202
|
+
return {
|
|
203
|
+
setYoutubeVideo: (options) => ({ commands }) => {
|
|
204
|
+
if (!isValidYoutubeUrl(options.src)) {
|
|
205
|
+
return false;
|
|
170
206
|
}
|
|
171
|
-
return
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
207
|
+
return commands.insertContent({
|
|
208
|
+
type: this.name,
|
|
209
|
+
attrs: options
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
addPasteRules() {
|
|
215
|
+
if (!this.options.addPasteHandler) {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
return [
|
|
219
|
+
(0, import_core.nodePasteRule)({
|
|
220
|
+
find: YOUTUBE_REGEX_GLOBAL,
|
|
221
|
+
type: this.type,
|
|
222
|
+
getAttributes: (match) => {
|
|
223
|
+
return { src: match.input };
|
|
224
|
+
}
|
|
225
|
+
})
|
|
226
|
+
];
|
|
227
|
+
},
|
|
228
|
+
renderHTML({ HTMLAttributes }) {
|
|
229
|
+
const embedUrl = getEmbedUrlFromYoutubeUrl({
|
|
230
|
+
url: HTMLAttributes.src,
|
|
231
|
+
allowFullscreen: this.options.allowFullscreen,
|
|
232
|
+
autoplay: this.options.autoplay,
|
|
233
|
+
ccLanguage: this.options.ccLanguage,
|
|
234
|
+
ccLoadPolicy: this.options.ccLoadPolicy,
|
|
235
|
+
controls: this.options.controls,
|
|
236
|
+
disableKBcontrols: this.options.disableKBcontrols,
|
|
237
|
+
enableIFrameApi: this.options.enableIFrameApi,
|
|
238
|
+
endTime: this.options.endTime,
|
|
239
|
+
interfaceLanguage: this.options.interfaceLanguage,
|
|
240
|
+
ivLoadPolicy: this.options.ivLoadPolicy,
|
|
241
|
+
loop: this.options.loop,
|
|
242
|
+
modestBranding: this.options.modestBranding,
|
|
243
|
+
nocookie: this.options.nocookie,
|
|
244
|
+
origin: this.options.origin,
|
|
245
|
+
playlist: this.options.playlist,
|
|
246
|
+
progressBarColor: this.options.progressBarColor,
|
|
247
|
+
startAt: HTMLAttributes.start || 0,
|
|
248
|
+
rel: this.options.rel
|
|
249
|
+
});
|
|
250
|
+
HTMLAttributes.src = embedUrl;
|
|
251
|
+
return [
|
|
252
|
+
"div",
|
|
253
|
+
{ "data-youtube-video": "" },
|
|
254
|
+
[
|
|
255
|
+
"iframe",
|
|
256
|
+
(0, import_core.mergeAttributes)(
|
|
257
|
+
this.options.HTMLAttributes,
|
|
258
|
+
{
|
|
259
|
+
width: this.options.width,
|
|
260
|
+
height: this.options.height,
|
|
261
|
+
allowfullscreen: this.options.allowFullscreen,
|
|
185
262
|
autoplay: this.options.autoplay,
|
|
186
263
|
ccLanguage: this.options.ccLanguage,
|
|
187
264
|
ccLoadPolicy: this.options.ccLoadPolicy,
|
|
188
|
-
controls: this.options.controls,
|
|
189
265
|
disableKBcontrols: this.options.disableKBcontrols,
|
|
190
266
|
enableIFrameApi: this.options.enableIFrameApi,
|
|
191
267
|
endTime: this.options.endTime,
|
|
@@ -193,41 +269,22 @@ const Youtube = core.Node.create({
|
|
|
193
269
|
ivLoadPolicy: this.options.ivLoadPolicy,
|
|
194
270
|
loop: this.options.loop,
|
|
195
271
|
modestBranding: this.options.modestBranding,
|
|
196
|
-
nocookie: this.options.nocookie,
|
|
197
272
|
origin: this.options.origin,
|
|
198
273
|
playlist: this.options.playlist,
|
|
199
274
|
progressBarColor: this.options.progressBarColor,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
'iframe',
|
|
208
|
-
core.mergeAttributes(this.options.HTMLAttributes, {
|
|
209
|
-
width: this.options.width,
|
|
210
|
-
height: this.options.height,
|
|
211
|
-
allowfullscreen: this.options.allowFullscreen,
|
|
212
|
-
autoplay: this.options.autoplay,
|
|
213
|
-
ccLanguage: this.options.ccLanguage,
|
|
214
|
-
ccLoadPolicy: this.options.ccLoadPolicy,
|
|
215
|
-
disableKBcontrols: this.options.disableKBcontrols,
|
|
216
|
-
enableIFrameApi: this.options.enableIFrameApi,
|
|
217
|
-
endTime: this.options.endTime,
|
|
218
|
-
interfaceLanguage: this.options.interfaceLanguage,
|
|
219
|
-
ivLoadPolicy: this.options.ivLoadPolicy,
|
|
220
|
-
loop: this.options.loop,
|
|
221
|
-
modestBranding: this.options.modestBranding,
|
|
222
|
-
origin: this.options.origin,
|
|
223
|
-
playlist: this.options.playlist,
|
|
224
|
-
progressBarColor: this.options.progressBarColor,
|
|
225
|
-
}, HTMLAttributes),
|
|
226
|
-
],
|
|
227
|
-
];
|
|
228
|
-
},
|
|
275
|
+
rel: this.options.rel
|
|
276
|
+
},
|
|
277
|
+
HTMLAttributes
|
|
278
|
+
)
|
|
279
|
+
]
|
|
280
|
+
];
|
|
281
|
+
}
|
|
229
282
|
});
|
|
230
283
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
284
|
+
// src/index.ts
|
|
285
|
+
var index_default = Youtube;
|
|
286
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
287
|
+
0 && (module.exports = {
|
|
288
|
+
Youtube
|
|
289
|
+
});
|
|
290
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/youtube.ts"],"sourcesContent":["export const YOUTUBE_REGEX = /^(https?:\\/\\/)?(www\\.|music\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)\\/(?!channel\\/)(?!@)(.+)?$/\nexport const YOUTUBE_REGEX_GLOBAL = /^(https?:\\/\\/)?(www\\.|music\\.)?(youtube\\.com|youtu\\.be)\\/(?!channel\\/)(?!@)(.+)?$/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,yGAAyG,CAAA;AAC/H,MAAM,oBAAoB,GAAG,oFAAoF,CAAA;AAEjH,MAAM,iBAAiB,GAAG,CAAC,GAAW,KAAI;AAC/C,IAAA,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;AACjC,CAAC,CAAA;AAuBM,MAAM,kBAAkB,GAAG,CAAC,QAAkB,KAAI;IACvD,OAAO,QAAQ,GAAG,yCAAyC,GAAG,gCAAgC,CAAA;AAChG,CAAC,CAAA;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,CAAA;AAEX,IAAA,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE;AAC3B,QAAA,OAAO,IAAI,CAAA;KACZ;;AAGD,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AAC3B,QAAA,OAAO,GAAG,CAAA;KACX;;AAGD,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QAC5B,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,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7B,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,CAAA;KACF;AACF,CAAA;;;;;"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/youtube.ts","../src/utils.ts"],"sourcesContent":["import { Youtube } from './youtube.js'\n\nexport * from './youtube.js'\n\nexport default Youtube\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:\n (options: SetYoutubeVideoOptions) =>\n ({ 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","export const YOUTUBE_REGEX =\n /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu\\.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/\nexport const YOUTUBE_REGEX_GLOBAL =\n /^((?: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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAqD;;;ACA9C,IAAM,gBACX;AACK,IAAM,uBACX;AAEK,IAAM,oBAAoB,CAAC,QAAgB;AAChD,SAAO,IAAI,MAAM,aAAa;AAChC;AAwBO,IAAM,qBAAqB,CAAC,UAAoB,eAAyB;AAC9E,MAAI,YAAY;AACd,WAAO;AAAA,EACT;AACA,SAAO,WAAW,4CAA4C;AAChE;AAEO,IAAM,4BAA4B,CAAC,YAAgC;AACxE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,MAAI,CAAC,kBAAkB,GAAG,GAAG;AAC3B,WAAO;AAAA,EACT;AAGA,MAAI,IAAI,SAAS,SAAS,GAAG;AAC3B,WAAO;AAAA,EACT;AAGA,MAAI,IAAI,SAAS,UAAU,GAAG;AAC5B,UAAM,KAAK,IAAI,MAAM,GAAG,EAAE,IAAI;AAE9B,QA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AAAA,MACvB,kBAAkB,KAAK,QAAQ;AAAA,MAC/B,SAAS,eAAe,SAAS;AAAA,MACjC,KAAK,KAAK,QAAQ;AAAA,IACpB,CAAC;AAED,mBAAe,MAAM;AAErB,WAAO;AAAA,MACL;AAAA,MACA,EAAE,sBAAsB,GAAG;AAAA,MAC3B;AAAA,QACE;AAAA,YACA;AAAA,UACE,KAAK,QAAQ;AAAA,UACb;AAAA,YACE,OAAO,KAAK,QAAQ;AAAA,YACpB,QAAQ,KAAK,QAAQ;AAAA,YACrB,iBAAiB,KAAK,QAAQ;AAAA,YAC9B,UAAU,KAAK,QAAQ;AAAA,YACvB,YAAY,KAAK,QAAQ;AAAA,YACzB,cAAc,KAAK,QAAQ;AAAA,YAC3B,mBAAmB,KAAK,QAAQ;AAAA,YAChC,iBAAiB,KAAK,QAAQ;AAAA,YAC9B,SAAS,KAAK,QAAQ;AAAA,YACtB,mBAAmB,KAAK,QAAQ;AAAA,YAChC,cAAc,KAAK,QAAQ;AAAA,YAC3B,MAAM,KAAK,QAAQ;AAAA,YACnB,gBAAgB,KAAK,QAAQ;AAAA,YAC7B,QAAQ,KAAK,QAAQ;AAAA,YACrB,UAAU,KAAK,QAAQ;AAAA,YACvB,kBAAkB,KAAK,QAAQ;AAAA,YAC/B,KAAK,KAAK,QAAQ;AAAA,UACpB;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AD5UD,IAAO,gBAAQ;","names":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Node } from '@tiptap/core';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
interface YoutubeOptions {
|
|
3
4
|
/**
|
|
4
5
|
* Controls if the paste handler for youtube videos should be added.
|
|
5
6
|
* @default true
|
|
@@ -126,6 +127,12 @@ export interface YoutubeOptions {
|
|
|
126
127
|
* @example 1280
|
|
127
128
|
*/
|
|
128
129
|
width: number;
|
|
130
|
+
/**
|
|
131
|
+
* Controls if the related youtube videos at the end are from the same channel.
|
|
132
|
+
* @default 1
|
|
133
|
+
* @example 0
|
|
134
|
+
*/
|
|
135
|
+
rel: number;
|
|
129
136
|
}
|
|
130
137
|
/**
|
|
131
138
|
* The options for setting a youtube video.
|
|
@@ -152,5 +159,6 @@ declare module '@tiptap/core' {
|
|
|
152
159
|
* This extension adds support for youtube videos.
|
|
153
160
|
* @see https://www.tiptap.dev/api/nodes/youtube
|
|
154
161
|
*/
|
|
155
|
-
|
|
156
|
-
|
|
162
|
+
declare const Youtube: Node<YoutubeOptions, any>;
|
|
163
|
+
|
|
164
|
+
export { Youtube, type YoutubeOptions, Youtube as default };
|