@tiptap/extension-youtube 2.6.2 → 3.0.0-next.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.
Files changed (172) hide show
  1. package/dist/index.cjs +257 -210
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/{packages/extension-youtube/src/youtube.d.ts → index.d.cts} +5 -3
  4. package/dist/index.d.ts +158 -0
  5. package/dist/index.js +233 -208
  6. package/dist/index.js.map +1 -1
  7. package/package.json +6 -8
  8. package/dist/index.umd.js +0 -237
  9. package/dist/index.umd.js.map +0 -1
  10. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  11. package/dist/packages/core/src/Editor.d.ts +0 -163
  12. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  13. package/dist/packages/core/src/Extension.d.ts +0 -344
  14. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  15. package/dist/packages/core/src/InputRule.d.ts +0 -42
  16. package/dist/packages/core/src/Mark.d.ts +0 -452
  17. package/dist/packages/core/src/Node.d.ts +0 -612
  18. package/dist/packages/core/src/NodePos.d.ts +0 -44
  19. package/dist/packages/core/src/NodeView.d.ts +0 -31
  20. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  21. package/dist/packages/core/src/Tracker.d.ts +0 -11
  22. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  23. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  24. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  25. package/dist/packages/core/src/commands/command.d.ts +0 -18
  26. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  27. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  28. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  29. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  30. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  31. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  32. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  33. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  34. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  35. package/dist/packages/core/src/commands/first.d.ts +0 -14
  36. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  37. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  38. package/dist/packages/core/src/commands/index.d.ts +0 -55
  39. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  40. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  41. package/dist/packages/core/src/commands/join.d.ts +0 -41
  42. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  43. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  44. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  45. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  46. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  47. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  48. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  49. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  50. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  51. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  52. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  53. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  54. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  55. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  56. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  57. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  58. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  59. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  60. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  61. package/dist/packages/core/src/commands/setMeta.d.ts +0 -16
  62. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  63. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  64. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  65. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  66. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  67. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -16
  68. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  69. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  70. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  71. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  72. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  73. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  74. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  75. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  76. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  77. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  78. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  79. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  80. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  81. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  82. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  83. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  84. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  85. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  86. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  87. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  88. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  89. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  90. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  91. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  92. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  93. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  94. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  95. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  96. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  97. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  98. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  99. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  100. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  101. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  102. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  103. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  104. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  105. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  106. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  107. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  108. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  109. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  110. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  111. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  112. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  113. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  114. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  115. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  116. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  117. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  118. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  119. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  120. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  121. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  122. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  123. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  124. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  125. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  126. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  127. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  128. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  129. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -14
  130. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  131. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  132. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  133. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  134. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  135. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  136. package/dist/packages/core/src/index.d.ts +0 -24
  137. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  138. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  139. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  140. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  141. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  142. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  143. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  144. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  145. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -14
  146. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  147. package/dist/packages/core/src/style.d.ts +0 -1
  148. package/dist/packages/core/src/types.d.ts +0 -253
  149. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  150. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  151. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  152. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  153. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  154. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  155. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  156. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  157. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  158. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  159. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  160. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  161. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  162. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  163. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  164. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  165. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  166. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  167. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  168. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  169. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  170. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  171. package/dist/packages/extension-youtube/src/index.d.ts +0 -3
  172. package/dist/packages/extension-youtube/src/utils.d.ts +0 -25
@@ -0,0 +1,158 @@
1
+ import { Node } from '@tiptap/core';
2
+
3
+ interface YoutubeOptions {
4
+ /**
5
+ * Controls if the paste handler for youtube videos should be added.
6
+ * @default true
7
+ * @example false
8
+ */
9
+ addPasteHandler: boolean;
10
+ /**
11
+ * Controls if the youtube video should be allowed to go fullscreen.
12
+ * @default true
13
+ * @example false
14
+ */
15
+ allowFullscreen: boolean;
16
+ /**
17
+ * Controls if the youtube video should autoplay.
18
+ * @default false
19
+ * @example true
20
+ */
21
+ autoplay: boolean;
22
+ /**
23
+ * The language of the captions shown in the youtube video.
24
+ * @default undefined
25
+ * @example 'en'
26
+ */
27
+ ccLanguage?: string;
28
+ /**
29
+ * Controls if the captions should be shown in the youtube video.
30
+ * @default undefined
31
+ * @example true
32
+ */
33
+ ccLoadPolicy?: boolean;
34
+ /**
35
+ * Controls if the controls should be shown in the youtube video.
36
+ * @default true
37
+ * @example false
38
+ */
39
+ controls: boolean;
40
+ /**
41
+ * Controls if the keyboard controls should be disabled in the youtube video.
42
+ * @default false
43
+ * @example true
44
+ */
45
+ disableKBcontrols: boolean;
46
+ /**
47
+ * Controls if the iframe api should be enabled in the youtube video.
48
+ * @default false
49
+ * @example true
50
+ */
51
+ enableIFrameApi: boolean;
52
+ /**
53
+ * The end time of the youtube video.
54
+ * @default 0
55
+ * @example 120
56
+ */
57
+ endTime: number;
58
+ /**
59
+ * The height of the youtube video.
60
+ * @default 480
61
+ * @example 720
62
+ */
63
+ height: number;
64
+ /**
65
+ * The language of the youtube video.
66
+ * @default undefined
67
+ * @example 'en'
68
+ */
69
+ interfaceLanguage?: string;
70
+ /**
71
+ * Controls if the video annotations should be shown in the youtube video.
72
+ * @default 0
73
+ * @example 1
74
+ */
75
+ ivLoadPolicy: number;
76
+ /**
77
+ * Controls if the youtube video should loop.
78
+ * @default false
79
+ * @example true
80
+ */
81
+ loop: boolean;
82
+ /**
83
+ * Controls if the youtube video should show a small youtube logo.
84
+ * @default false
85
+ * @example true
86
+ */
87
+ modestBranding: boolean;
88
+ /**
89
+ * The HTML attributes for a youtube video node.
90
+ * @default {}
91
+ * @example { class: 'foo' }
92
+ */
93
+ HTMLAttributes: Record<string, any>;
94
+ /**
95
+ * Controls if the youtube node should be inline or not.
96
+ * @default false
97
+ * @example true
98
+ */
99
+ inline: boolean;
100
+ /**
101
+ * Controls if the youtube video should be loaded from youtube-nocookie.com.
102
+ * @default false
103
+ * @example true
104
+ */
105
+ nocookie: boolean;
106
+ /**
107
+ * The origin of the youtube video.
108
+ * @default ''
109
+ * @example 'https://tiptap.dev'
110
+ */
111
+ origin: string;
112
+ /**
113
+ * The playlist of the youtube video.
114
+ * @default ''
115
+ * @example 'PLQg6GaokU5CwiVmsZ0dZm6VeIg0V5z1tK'
116
+ */
117
+ playlist: string;
118
+ /**
119
+ * The color of the youtube video progress bar.
120
+ * @default undefined
121
+ * @example 'red'
122
+ */
123
+ progressBarColor?: string;
124
+ /**
125
+ * The width of the youtube video.
126
+ * @default 640
127
+ * @example 1280
128
+ */
129
+ width: number;
130
+ }
131
+ /**
132
+ * The options for setting a youtube video.
133
+ */
134
+ type SetYoutubeVideoOptions = {
135
+ src: string;
136
+ width?: number;
137
+ height?: number;
138
+ start?: number;
139
+ };
140
+ declare module '@tiptap/core' {
141
+ interface Commands<ReturnType> {
142
+ youtube: {
143
+ /**
144
+ * Insert a youtube video
145
+ * @param options The youtube video attributes
146
+ * @example editor.commands.setYoutubeVideo({ src: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' })
147
+ */
148
+ setYoutubeVideo: (options: SetYoutubeVideoOptions) => ReturnType;
149
+ };
150
+ }
151
+ }
152
+ /**
153
+ * This extension adds support for youtube videos.
154
+ * @see https://www.tiptap.dev/api/nodes/youtube
155
+ */
156
+ declare const Youtube: Node<YoutubeOptions, any>;
157
+
158
+ export { Youtube, type YoutubeOptions, Youtube as default };
package/dist/index.js CHANGED
@@ -1,187 +1,231 @@
1
- import { Node, nodePasteRule, mergeAttributes } from '@tiptap/core';
1
+ // src/youtube.ts
2
+ import { mergeAttributes, Node, nodePasteRule } from "@tiptap/core";
2
3
 
3
- const YOUTUBE_REGEX = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be|youtube-nocookie\.com)\/(?!channel\/)(?!@)(.+)?$/;
4
- const YOUTUBE_REGEX_GLOBAL = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be)\/(?!channel\/)(?!@)(.+)?$/g;
5
- const isValidYoutubeUrl = (url) => {
6
- return url.match(YOUTUBE_REGEX);
4
+ // src/utils.ts
5
+ var YOUTUBE_REGEX = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be|youtube-nocookie\.com)\/(?!channel\/)(?!@)(.+)?$/;
6
+ var YOUTUBE_REGEX_GLOBAL = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be)\/(?!channel\/)(?!@)(.+)?$/g;
7
+ var isValidYoutubeUrl = (url) => {
8
+ return url.match(YOUTUBE_REGEX);
7
9
  };
8
- const getYoutubeEmbedUrl = (nocookie) => {
9
- return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/';
10
+ var getYoutubeEmbedUrl = (nocookie) => {
11
+ return nocookie ? "https://www.youtube-nocookie.com/embed/" : "https://www.youtube.com/embed/";
10
12
  };
11
- const getEmbedUrlFromYoutubeUrl = (options) => {
12
- const { url, allowFullscreen, autoplay, ccLanguage, ccLoadPolicy, controls, disableKBcontrols, enableIFrameApi, endTime, interfaceLanguage, ivLoadPolicy, loop, modestBranding, nocookie, origin, playlist, progressBarColor, startAt, } = options;
13
- if (!isValidYoutubeUrl(url)) {
14
- return null;
15
- }
16
- // if is already an embed url, return it
17
- if (url.includes('/embed/')) {
18
- return url;
19
- }
20
- // if is a youtu.be url, get the id after the /
21
- if (url.includes('youtu.be')) {
22
- const id = url.split('/').pop();
23
- if (!id) {
24
- return null;
25
- }
26
- return `${getYoutubeEmbedUrl(nocookie)}${id}`;
27
- }
28
- const videoIdRegex = /(?:v=|shorts\/)([-\w]+)/gm;
29
- const matches = videoIdRegex.exec(url);
30
- if (!matches || !matches[1]) {
31
- return null;
32
- }
33
- let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`;
34
- const params = [];
35
- if (allowFullscreen === false) {
36
- params.push('fs=0');
37
- }
38
- if (autoplay) {
39
- params.push('autoplay=1');
40
- }
41
- if (ccLanguage) {
42
- params.push(`cc_lang_pref=${ccLanguage}`);
43
- }
44
- if (ccLoadPolicy) {
45
- params.push('cc_load_policy=1');
46
- }
47
- if (!controls) {
48
- params.push('controls=0');
49
- }
50
- if (disableKBcontrols) {
51
- params.push('disablekb=1');
52
- }
53
- if (enableIFrameApi) {
54
- params.push('enablejsapi=1');
55
- }
56
- if (endTime) {
57
- params.push(`end=${endTime}`);
58
- }
59
- if (interfaceLanguage) {
60
- params.push(`hl=${interfaceLanguage}`);
61
- }
62
- if (ivLoadPolicy) {
63
- params.push(`iv_load_policy=${ivLoadPolicy}`);
64
- }
65
- if (loop) {
66
- params.push('loop=1');
67
- }
68
- if (modestBranding) {
69
- params.push('modestbranding=1');
70
- }
71
- if (origin) {
72
- params.push(`origin=${origin}`);
73
- }
74
- if (playlist) {
75
- params.push(`playlist=${playlist}`);
76
- }
77
- if (startAt) {
78
- params.push(`start=${startAt}`);
79
- }
80
- if (progressBarColor) {
81
- params.push(`color=${progressBarColor}`);
82
- }
83
- if (params.length) {
84
- outputUrl += `?${params.join('&')}`;
85
- }
86
- return outputUrl;
13
+ var getEmbedUrlFromYoutubeUrl = (options) => {
14
+ const {
15
+ url,
16
+ allowFullscreen,
17
+ autoplay,
18
+ ccLanguage,
19
+ ccLoadPolicy,
20
+ controls,
21
+ disableKBcontrols,
22
+ enableIFrameApi,
23
+ endTime,
24
+ interfaceLanguage,
25
+ ivLoadPolicy,
26
+ loop,
27
+ modestBranding,
28
+ nocookie,
29
+ origin,
30
+ playlist,
31
+ progressBarColor,
32
+ startAt
33
+ } = options;
34
+ if (!isValidYoutubeUrl(url)) {
35
+ return null;
36
+ }
37
+ if (url.includes("/embed/")) {
38
+ return url;
39
+ }
40
+ if (url.includes("youtu.be")) {
41
+ const id = url.split("/").pop();
42
+ if (!id) {
43
+ return null;
44
+ }
45
+ return `${getYoutubeEmbedUrl(nocookie)}${id}`;
46
+ }
47
+ const videoIdRegex = /(?:v=|shorts\/)([-\w]+)/gm;
48
+ const matches = videoIdRegex.exec(url);
49
+ if (!matches || !matches[1]) {
50
+ return null;
51
+ }
52
+ let outputUrl = `${getYoutubeEmbedUrl(nocookie)}${matches[1]}`;
53
+ const params = [];
54
+ if (allowFullscreen === false) {
55
+ params.push("fs=0");
56
+ }
57
+ if (autoplay) {
58
+ params.push("autoplay=1");
59
+ }
60
+ if (ccLanguage) {
61
+ params.push(`cc_lang_pref=${ccLanguage}`);
62
+ }
63
+ if (ccLoadPolicy) {
64
+ params.push("cc_load_policy=1");
65
+ }
66
+ if (!controls) {
67
+ params.push("controls=0");
68
+ }
69
+ if (disableKBcontrols) {
70
+ params.push("disablekb=1");
71
+ }
72
+ if (enableIFrameApi) {
73
+ params.push("enablejsapi=1");
74
+ }
75
+ if (endTime) {
76
+ params.push(`end=${endTime}`);
77
+ }
78
+ if (interfaceLanguage) {
79
+ params.push(`hl=${interfaceLanguage}`);
80
+ }
81
+ if (ivLoadPolicy) {
82
+ params.push(`iv_load_policy=${ivLoadPolicy}`);
83
+ }
84
+ if (loop) {
85
+ params.push("loop=1");
86
+ }
87
+ if (modestBranding) {
88
+ params.push("modestbranding=1");
89
+ }
90
+ if (origin) {
91
+ params.push(`origin=${origin}`);
92
+ }
93
+ if (playlist) {
94
+ params.push(`playlist=${playlist}`);
95
+ }
96
+ if (startAt) {
97
+ params.push(`start=${startAt}`);
98
+ }
99
+ if (progressBarColor) {
100
+ params.push(`color=${progressBarColor}`);
101
+ }
102
+ if (params.length) {
103
+ outputUrl += `?${params.join("&")}`;
104
+ }
105
+ return outputUrl;
87
106
  };
88
107
 
89
- /**
90
- * This extension adds support for youtube videos.
91
- * @see https://www.tiptap.dev/api/nodes/youtube
92
- */
93
- const Youtube = Node.create({
94
- name: 'youtube',
95
- addOptions() {
96
- return {
97
- addPasteHandler: true,
98
- allowFullscreen: true,
99
- autoplay: false,
100
- ccLanguage: undefined,
101
- ccLoadPolicy: undefined,
102
- controls: true,
103
- disableKBcontrols: false,
104
- enableIFrameApi: false,
105
- endTime: 0,
106
- height: 480,
107
- interfaceLanguage: undefined,
108
- ivLoadPolicy: 0,
109
- loop: false,
110
- modestBranding: false,
111
- HTMLAttributes: {},
112
- inline: false,
113
- nocookie: false,
114
- origin: '',
115
- playlist: '',
116
- progressBarColor: undefined,
117
- width: 640,
118
- };
119
- },
120
- inline() {
121
- return this.options.inline;
122
- },
123
- group() {
124
- return this.options.inline ? 'inline' : 'block';
125
- },
126
- draggable: true,
127
- addAttributes() {
128
- return {
129
- src: {
130
- default: null,
131
- },
132
- start: {
133
- default: 0,
134
- },
135
- width: {
136
- default: this.options.width,
137
- },
138
- height: {
139
- default: this.options.height,
140
- },
141
- };
142
- },
143
- parseHTML() {
144
- return [
145
- {
146
- tag: 'div[data-youtube-video] iframe',
147
- },
148
- ];
149
- },
150
- addCommands() {
151
- return {
152
- setYoutubeVideo: (options) => ({ commands }) => {
153
- if (!isValidYoutubeUrl(options.src)) {
154
- return false;
155
- }
156
- return commands.insertContent({
157
- type: this.name,
158
- attrs: options,
159
- });
160
- },
161
- };
162
- },
163
- addPasteRules() {
164
- if (!this.options.addPasteHandler) {
165
- return [];
108
+ // src/youtube.ts
109
+ var Youtube = Node.create({
110
+ name: "youtube",
111
+ addOptions() {
112
+ return {
113
+ addPasteHandler: true,
114
+ allowFullscreen: true,
115
+ autoplay: false,
116
+ ccLanguage: void 0,
117
+ ccLoadPolicy: void 0,
118
+ controls: true,
119
+ disableKBcontrols: false,
120
+ enableIFrameApi: false,
121
+ endTime: 0,
122
+ height: 480,
123
+ interfaceLanguage: void 0,
124
+ ivLoadPolicy: 0,
125
+ loop: false,
126
+ modestBranding: false,
127
+ HTMLAttributes: {},
128
+ inline: false,
129
+ nocookie: false,
130
+ origin: "",
131
+ playlist: "",
132
+ progressBarColor: void 0,
133
+ width: 640
134
+ };
135
+ },
136
+ inline() {
137
+ return this.options.inline;
138
+ },
139
+ group() {
140
+ return this.options.inline ? "inline" : "block";
141
+ },
142
+ draggable: true,
143
+ addAttributes() {
144
+ return {
145
+ src: {
146
+ default: null
147
+ },
148
+ start: {
149
+ default: 0
150
+ },
151
+ width: {
152
+ default: this.options.width
153
+ },
154
+ height: {
155
+ default: this.options.height
156
+ }
157
+ };
158
+ },
159
+ parseHTML() {
160
+ return [
161
+ {
162
+ tag: "div[data-youtube-video] iframe"
163
+ }
164
+ ];
165
+ },
166
+ addCommands() {
167
+ return {
168
+ setYoutubeVideo: (options) => ({ commands }) => {
169
+ if (!isValidYoutubeUrl(options.src)) {
170
+ return false;
171
+ }
172
+ return commands.insertContent({
173
+ type: this.name,
174
+ attrs: options
175
+ });
176
+ }
177
+ };
178
+ },
179
+ addPasteRules() {
180
+ if (!this.options.addPasteHandler) {
181
+ return [];
182
+ }
183
+ return [
184
+ nodePasteRule({
185
+ find: YOUTUBE_REGEX_GLOBAL,
186
+ type: this.type,
187
+ getAttributes: (match) => {
188
+ return { src: match.input };
166
189
  }
167
- return [
168
- nodePasteRule({
169
- find: YOUTUBE_REGEX_GLOBAL,
170
- type: this.type,
171
- getAttributes: match => {
172
- return { src: match.input };
173
- },
174
- }),
175
- ];
176
- },
177
- renderHTML({ HTMLAttributes }) {
178
- const embedUrl = getEmbedUrlFromYoutubeUrl({
179
- url: HTMLAttributes.src,
180
- allowFullscreen: this.options.allowFullscreen,
190
+ })
191
+ ];
192
+ },
193
+ renderHTML({ HTMLAttributes }) {
194
+ const embedUrl = getEmbedUrlFromYoutubeUrl({
195
+ url: HTMLAttributes.src,
196
+ allowFullscreen: this.options.allowFullscreen,
197
+ autoplay: this.options.autoplay,
198
+ ccLanguage: this.options.ccLanguage,
199
+ ccLoadPolicy: this.options.ccLoadPolicy,
200
+ controls: this.options.controls,
201
+ disableKBcontrols: this.options.disableKBcontrols,
202
+ enableIFrameApi: this.options.enableIFrameApi,
203
+ endTime: this.options.endTime,
204
+ interfaceLanguage: this.options.interfaceLanguage,
205
+ ivLoadPolicy: this.options.ivLoadPolicy,
206
+ loop: this.options.loop,
207
+ modestBranding: this.options.modestBranding,
208
+ nocookie: this.options.nocookie,
209
+ origin: this.options.origin,
210
+ playlist: this.options.playlist,
211
+ progressBarColor: this.options.progressBarColor,
212
+ startAt: HTMLAttributes.start || 0
213
+ });
214
+ HTMLAttributes.src = embedUrl;
215
+ return [
216
+ "div",
217
+ { "data-youtube-video": "" },
218
+ [
219
+ "iframe",
220
+ mergeAttributes(
221
+ this.options.HTMLAttributes,
222
+ {
223
+ width: this.options.width,
224
+ height: this.options.height,
225
+ allowfullscreen: this.options.allowFullscreen,
181
226
  autoplay: this.options.autoplay,
182
227
  ccLanguage: this.options.ccLanguage,
183
228
  ccLoadPolicy: this.options.ccLoadPolicy,
184
- controls: this.options.controls,
185
229
  disableKBcontrols: this.options.disableKBcontrols,
186
230
  enableIFrameApi: this.options.enableIFrameApi,
187
231
  endTime: this.options.endTime,
@@ -189,40 +233,21 @@ const Youtube = Node.create({
189
233
  ivLoadPolicy: this.options.ivLoadPolicy,
190
234
  loop: this.options.loop,
191
235
  modestBranding: this.options.modestBranding,
192
- nocookie: this.options.nocookie,
193
236
  origin: this.options.origin,
194
237
  playlist: this.options.playlist,
195
- progressBarColor: this.options.progressBarColor,
196
- startAt: HTMLAttributes.start || 0,
197
- });
198
- HTMLAttributes.src = embedUrl;
199
- return [
200
- 'div',
201
- { 'data-youtube-video': '' },
202
- [
203
- 'iframe',
204
- mergeAttributes(this.options.HTMLAttributes, {
205
- width: this.options.width,
206
- height: this.options.height,
207
- allowfullscreen: this.options.allowFullscreen,
208
- autoplay: this.options.autoplay,
209
- ccLanguage: this.options.ccLanguage,
210
- ccLoadPolicy: this.options.ccLoadPolicy,
211
- disableKBcontrols: this.options.disableKBcontrols,
212
- enableIFrameApi: this.options.enableIFrameApi,
213
- endTime: this.options.endTime,
214
- interfaceLanguage: this.options.interfaceLanguage,
215
- ivLoadPolicy: this.options.ivLoadPolicy,
216
- loop: this.options.loop,
217
- modestBranding: this.options.modestBranding,
218
- origin: this.options.origin,
219
- playlist: this.options.playlist,
220
- progressBarColor: this.options.progressBarColor,
221
- }, HTMLAttributes),
222
- ],
223
- ];
224
- },
238
+ progressBarColor: this.options.progressBarColor
239
+ },
240
+ HTMLAttributes
241
+ )
242
+ ]
243
+ ];
244
+ }
225
245
  });
226
246
 
227
- export { Youtube, Youtube as default };
228
- //# sourceMappingURL=index.js.map
247
+ // src/index.ts
248
+ var src_default = Youtube;
249
+ export {
250
+ Youtube,
251
+ src_default as default
252
+ };
253
+ //# sourceMappingURL=index.js.map