tiptap-essentials 1.2.1 → 2.0.0-beta.3

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.
@@ -0,0 +1,16 @@
1
+ import { type TableOptions as TiptapTableOptions } from '@tiptap/extension-table';
2
+ export interface TableOptions extends TiptapTableOptions {
3
+ /**
4
+ * What a screen reader calls the region a table too wide for the page
5
+ * scrolls in, which a keyboard can then reach. Without one, the table
6
+ * scrolls in a plain box.
7
+ */
8
+ region: string | null;
9
+ }
10
+ /**
11
+ * Tiptap's table, written inside a box it scrolls in when it is too wide for
12
+ * the page, and without the column widths Tiptap gives every table. The
13
+ * editor draws its own copy without the region's tab stop: inside the editable
14
+ * area, one would take the focus from the editor whenever a cell is clicked.
15
+ */
16
+ export declare const Table: import("@tiptap/core").Node<TableOptions, any>;
package/dist/table.js ADDED
@@ -0,0 +1,45 @@
1
+ import { mergeAttributes } from '@tiptap/core';
2
+ import { Table as TiptapTable } from '@tiptap/extension-table';
3
+ /**
4
+ * Tiptap's table, written inside a box it scrolls in when it is too wide for
5
+ * the page, and without the column widths Tiptap gives every table. The
6
+ * editor draws its own copy without the region's tab stop: inside the editable
7
+ * area, one would take the focus from the editor whenever a cell is clicked.
8
+ */
9
+ export const Table = TiptapTable.extend({
10
+ addOptions() {
11
+ return {
12
+ ...this.parent(),
13
+ HTMLAttributes: { class: 'tiptap-table' },
14
+ region: null
15
+ };
16
+ },
17
+ renderHTML({ HTMLAttributes }) {
18
+ const { region } = this.options;
19
+ const box = region
20
+ ? { role: 'region', tabindex: '0', 'aria-label': region }
21
+ : {};
22
+ return [
23
+ 'div',
24
+ { class: 'table-responsive', ...box },
25
+ [
26
+ 'table',
27
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
28
+ ['tbody', 0]
29
+ ]
30
+ ];
31
+ },
32
+ addNodeView() {
33
+ return ({ HTMLAttributes }) => {
34
+ const dom = document.createElement('div');
35
+ dom.className = 'table-responsive';
36
+ const table = dom.appendChild(document.createElement('table'));
37
+ const attributes = mergeAttributes(this.options.HTMLAttributes, HTMLAttributes);
38
+ for (const [name, value] of Object.entries(attributes)) {
39
+ table.setAttribute(name, String(value));
40
+ }
41
+ const contentDOM = table.appendChild(document.createElement('tbody'));
42
+ return { dom, contentDOM };
43
+ };
44
+ }
45
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Tiptap's text style, reading a span only where a style a text keeps is on
3
+ * it — a colour of the palette, one of the sizes. A span whose every style is
4
+ * dropped, a colour off the palette or a font, is read as its text, where
5
+ * Tiptap's would keep it as a bare span.
6
+ */
7
+ export declare const TextStyle: import("@tiptap/core").Mark<import("@tiptap/extension-text-style").TextStyleOptions, any>;
@@ -0,0 +1,38 @@
1
+ import { getAttributesFromExtensions } from '@tiptap/core';
2
+ import { TextStyle as TiptapTextStyle } from '@tiptap/extension-text-style';
3
+ /**
4
+ * Tiptap's text style, reading a span only where a style a text keeps is on
5
+ * it — a colour of the palette, one of the sizes. A span whose every style is
6
+ * dropped, a colour off the palette or a font, is read as its text, where
7
+ * Tiptap's would keep it as a bare span.
8
+ */
9
+ export const TextStyle = TiptapTextStyle.extend({
10
+ parseHTML() {
11
+ const { editor, name } = this;
12
+ const [styled] = (this.parent?.() ?? []);
13
+ let styles;
14
+ // The text's styles are read as a body is, the editor built by then.
15
+ const keepsAStyle = (element) => {
16
+ if (!editor) {
17
+ return element.hasAttribute('style');
18
+ }
19
+ styles ??= getAttributesFromExtensions(editor.extensionManager.extensions).filter(({ type }) => type === name);
20
+ return styles.some(({ attribute }) => {
21
+ const value = attribute.parseHTML?.(element);
22
+ return typeof value === 'string' ? value.trim() !== '' : value != null;
23
+ });
24
+ };
25
+ return [
26
+ {
27
+ tag: 'span',
28
+ consuming: false,
29
+ getAttrs: (element) => {
30
+ // Tiptap's reading of a styled span hands the styles of a span
31
+ // inside it on to that span, which is read on its own.
32
+ styled?.getAttrs?.(element);
33
+ return keepsAStyle(element) ? {} : false;
34
+ }
35
+ }
36
+ ];
37
+ }
38
+ });
@@ -0,0 +1,44 @@
1
+ import { Extension } from '@tiptap/core';
2
+ import type { ImageOptions } from '@tiptap/extension-image';
3
+ import { type SuperscriptExtensionOptions } from '@tiptap/extension-superscript';
4
+ import { type TableKitOptions } from '@tiptap/extension-table';
5
+ import { type TextAlignOptions } from '@tiptap/extension-text-align';
6
+ import { type TextStyleKitOptions } from '@tiptap/extension-text-style';
7
+ import type { YoutubeOptions } from '@tiptap/extension-youtube';
8
+ import { type StarterKitOptions } from '@tiptap/starter-kit';
9
+ import { type BlockSpacingOptions } from './block-spacing.js';
10
+ import { type ColorOptions } from './color.js';
11
+ import { type FontSizeOptions } from './font-size.js';
12
+ import { type HighlightOptions } from './highlight.js';
13
+ import { type LineHeightOptions } from './line-height.js';
14
+ import { type TableOptions } from './table.js';
15
+ type Part<Options> = Partial<Options> | false;
16
+ export interface TiptapEssentialsOptions {
17
+ starterKit: Part<StarterKitOptions>;
18
+ /** TableKit's options, its table being the library's. */
19
+ tableKit: (Partial<Omit<TableKitOptions, 'table'>> & {
20
+ table?: Part<TableOptions>;
21
+ }) | false;
22
+ /**
23
+ * TextStyleKit's options, its text style, font size, colour and line height
24
+ * being the library's.
25
+ */
26
+ textStyleKit: (Partial<Omit<TextStyleKitOptions, 'fontSize' | 'color' | 'lineHeight'>> & {
27
+ fontSize?: Part<FontSizeOptions>;
28
+ color?: Part<ColorOptions>;
29
+ lineHeight?: Part<LineHeightOptions>;
30
+ }) | false;
31
+ highlight: Part<HighlightOptions>;
32
+ blockSpacing: Part<BlockSpacingOptions>;
33
+ textAlign: Part<TextAlignOptions>;
34
+ superscript: Part<SuperscriptExtensionOptions>;
35
+ image: Part<ImageOptions>;
36
+ youtube: Part<YoutubeOptions>;
37
+ plainSpaces: Record<string, never> | false;
38
+ }
39
+ /**
40
+ * Tiptap's kits and the library's own parts as one extension, each part
41
+ * configured, or left out by `false`, through the option of its name.
42
+ */
43
+ export declare const TiptapEssentials: Extension<TiptapEssentialsOptions, any>;
44
+ export {};
@@ -1,226 +1,98 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.TiptapEssentials = void 0;
7
- var _core = require("@tiptap/core");
8
- var _extensionBlockquote = _interopRequireDefault(require("@tiptap/extension-blockquote"));
9
- var _extensionBold = _interopRequireDefault(require("@tiptap/extension-bold"));
10
- var _extensionBulletList = _interopRequireDefault(require("@tiptap/extension-bullet-list"));
11
- var _extensionCode = _interopRequireDefault(require("@tiptap/extension-code"));
12
- var _extensionCodeBlock = _interopRequireDefault(require("@tiptap/extension-code-block"));
13
- var _extensionDocument = _interopRequireDefault(require("@tiptap/extension-document"));
14
- var _extensionDropcursor = _interopRequireDefault(require("@tiptap/extension-dropcursor"));
15
- var _extensionGapcursor = _interopRequireDefault(require("@tiptap/extension-gapcursor"));
16
- var _extensionHardBreak = _interopRequireDefault(require("@tiptap/extension-hard-break"));
17
- var _extensionHeading = _interopRequireDefault(require("@tiptap/extension-heading"));
18
- var _extensionHistory = _interopRequireDefault(require("@tiptap/extension-history"));
19
- var _extensionHorizontalRule = _interopRequireDefault(require("@tiptap/extension-horizontal-rule"));
20
- var _extensionImage = _interopRequireDefault(require("@tiptap/extension-image"));
21
- var _extensionItalic = _interopRequireDefault(require("@tiptap/extension-italic"));
22
- var _extensionLink = _interopRequireDefault(require("@tiptap/extension-link"));
23
- var _extensionListItem = _interopRequireDefault(require("@tiptap/extension-list-item"));
24
- var _extensionOrderedList = _interopRequireDefault(require("@tiptap/extension-ordered-list"));
25
- var _extensionParagraph = _interopRequireDefault(require("@tiptap/extension-paragraph"));
26
- var _extensionStrike = _interopRequireDefault(require("@tiptap/extension-strike"));
27
- var _extensionSuperscript = _interopRequireDefault(require("@tiptap/extension-superscript"));
28
- var _extensionTable = _interopRequireDefault(require("@tiptap/extension-table"));
29
- var _extensionTableCell = _interopRequireDefault(require("@tiptap/extension-table-cell"));
30
- var _extensionTableHeader = _interopRequireDefault(require("@tiptap/extension-table-header"));
31
- var _extensionTableRow = _interopRequireDefault(require("@tiptap/extension-table-row"));
32
- var _extensionText = _interopRequireDefault(require("@tiptap/extension-text"));
33
- var _extensionTextAlign = _interopRequireDefault(require("@tiptap/extension-text-align"));
34
- var _extensionUnderline = _interopRequireDefault(require("@tiptap/extension-underline"));
35
- var _spanWrapper = require("./marks/span-wrapper");
36
- var _iframe = require("./nodes/iframe");
37
- var _youtube = require("./extensions/youtube");
38
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
39
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
40
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
41
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
42
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
43
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
44
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
45
- var TiptapEssentials = _core.Extension.create({
46
- name: 'tiptapEssentials',
47
- addOptions: function addOptions() {
48
- var _this$parent;
49
- return _objectSpread(_objectSpread({}, (_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.call(this)), {}, {
50
- blockquote: true,
51
- bold: true,
52
- bulletList: true,
53
- code: true,
54
- codeBlock: true,
55
- document: true,
56
- dropcursor: true,
57
- gapcursor: true,
58
- hardBreak: true,
59
- heading: true,
60
- history: true,
61
- horizontalRule: true,
62
- iframe: true,
63
- image: true,
64
- italic: true,
65
- link: true,
66
- listItem: true,
67
- orderedList: true,
68
- paragraph: true,
69
- spanWrapper: true,
70
- strike: true,
71
- superscript: true,
72
- table: true,
73
- tableCell: true,
74
- tableHeader: true,
75
- tableRow: true,
76
- text: true,
77
- textAlign: true,
78
- underline: true,
79
- youtube: true
80
- });
81
- },
82
- addExtensions: function addExtensions() {
83
- var extensions = [];
84
- if (this.options.blockquote !== false) {
85
- extensions.push(_extensionBlockquote["default"]);
86
- }
87
- if (this.options.bold !== false) {
88
- extensions.push(_extensionBold["default"]);
89
- }
90
- if (this.options.bulletList !== false) {
91
- extensions.push(_extensionBulletList["default"]);
92
- }
93
- if (this.options.code !== false) {
94
- extensions.push(_extensionCode["default"]);
95
- }
96
- if (this.options.codeBlock !== false) {
97
- extensions.push(_extensionCodeBlock["default"]);
98
- }
99
- if (this.options.document !== false) {
100
- extensions.push(_extensionDocument["default"]);
101
- }
102
- if (this.options.dropcursor !== false) {
103
- extensions.push(_extensionDropcursor["default"]);
104
- }
105
- if (this.options.gapcursor !== false) {
106
- extensions.push(_extensionGapcursor["default"]);
107
- }
108
- if (this.options.hardBreak !== false) {
109
- extensions.push(_extensionHardBreak["default"]);
110
- }
111
- if (this.options.heading !== false) {
112
- extensions.push(_extensionHeading["default"]);
113
- }
114
- if (this.options.history !== false) {
115
- extensions.push(_extensionHistory["default"]);
116
- }
117
- if (this.options.horizontalRule !== false) {
118
- extensions.push(_extensionHorizontalRule["default"]);
119
- }
120
- if (this.options.iframe !== false) {
121
- extensions.push(_iframe.Iframe);
122
- }
123
- if (this.options.image !== false) {
124
- extensions.push(_extensionImage["default"].extend({
125
- addAttributes: function addAttributes() {
126
- return _objectSpread(_objectSpread({}, this.parent()), {}, {
127
- srcset: {
128
- "default": null
129
- },
130
- sizes: {
131
- "default": null
1
+ import { Extension } from '@tiptap/core';
2
+ import Superscript, {} from '@tiptap/extension-superscript';
3
+ import { TableKit } from '@tiptap/extension-table';
4
+ import TextAlign, {} from '@tiptap/extension-text-align';
5
+ import { TextStyleKit } from '@tiptap/extension-text-style';
6
+ import StarterKit, {} from '@tiptap/starter-kit';
7
+ import { BlockSpacing } from './block-spacing.js';
8
+ import { Color } from './color.js';
9
+ import { FontSize } from './font-size.js';
10
+ import { Highlight } from './highlight.js';
11
+ import { Image } from './image.js';
12
+ import { LineHeight } from './line-height.js';
13
+ import { PlainSpaces } from './plain-spaces.js';
14
+ import { Table } from './table.js';
15
+ import { TextStyle } from './text-style.js';
16
+ import { Youtube } from './youtube.js';
17
+ /**
18
+ * Tiptap's kits and the library's own parts as one extension, each part
19
+ * configured, or left out by `false`, through the option of its name.
20
+ */
21
+ export const TiptapEssentials = Extension.create({
22
+ name: 'tiptapEssentials',
23
+ addOptions() {
24
+ return {
25
+ starterKit: {},
26
+ tableKit: {},
27
+ textStyleKit: {},
28
+ textAlign: {
29
+ types: ['heading', 'paragraph'],
30
+ alignments: ['start', 'end', 'left', 'center', 'right', 'justify']
132
31
  },
133
- classNames: {
134
- "default": null
135
- },
136
- style: {
137
- "default": null
138
- },
139
- loading: {
140
- "default": 'lazy'
141
- }
142
- });
32
+ highlight: {},
33
+ blockSpacing: {},
34
+ superscript: {},
35
+ image: {},
36
+ youtube: {},
37
+ plainSpaces: {}
38
+ };
39
+ },
40
+ addExtensions() {
41
+ const { starterKit, tableKit, textStyleKit, highlight, blockSpacing, textAlign, superscript, image, youtube, plainSpaces } = this.options;
42
+ const extensions = [];
43
+ if (starterKit !== false) {
44
+ extensions.push(StarterKit.configure(starterKit));
143
45
  }
144
- }));
145
- }
146
- if (this.options.italic !== false) {
147
- extensions.push(_extensionItalic["default"]);
148
- }
149
- if (this.options.link !== false) {
150
- extensions.push(_extensionLink["default"].extend({
151
- addAttributes: function addAttributes() {
152
- return _objectSpread(_objectSpread({}, this.parent()), {}, {
153
- title: {
154
- "default": null
155
- },
156
- "class": {
157
- "default": 'tiptap-link'
46
+ if (tableKit !== false) {
47
+ const { table = {}, ...rest } = tableKit;
48
+ extensions.push(TableKit.configure({ ...rest, table: false }));
49
+ if (table !== false) {
50
+ extensions.push(Table.configure(table));
158
51
  }
159
- });
160
52
  }
161
- }));
162
- }
163
- if (this.options.listItem !== false) {
164
- extensions.push(_extensionListItem["default"]);
165
- }
166
- if (this.options.orderedList !== false) {
167
- extensions.push(_extensionOrderedList["default"]);
168
- }
169
- if (this.options.paragraph !== false) {
170
- extensions.push(_extensionParagraph["default"]);
171
- }
172
- if (this.options.spanWrapper !== false) {
173
- extensions.push(_spanWrapper.SpanWrapper);
174
- }
175
- if (this.options.strike !== false) {
176
- extensions.push(_extensionStrike["default"]);
177
- }
178
- if (this.options.superscript !== false) {
179
- extensions.push(_extensionSuperscript["default"]);
180
- }
181
- if (this.options.table !== false) {
182
- extensions.push(_extensionTable["default"].extend({
183
- renderHTML: function renderHTML(_ref) {
184
- var HTMLAttributes = _ref.HTMLAttributes;
185
- return ['div', {
186
- "class": 'table-responsive'
187
- }, ['table', HTMLAttributes, ['tbody', 0]]];
188
- },
189
- addAttributes: function addAttributes() {
190
- var _this$parent2;
191
- return _objectSpread(_objectSpread({}, (_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.call(this)), {}, {
192
- "class": {
193
- "default": 'tiptap-table'
53
+ if (textStyleKit !== false) {
54
+ const { fontSize = {}, color = {}, lineHeight = {}, textStyle = {}, ...rest } = textStyleKit;
55
+ extensions.push(TextStyleKit.configure({
56
+ ...rest,
57
+ fontSize: false,
58
+ color: false,
59
+ lineHeight: false,
60
+ textStyle: false
61
+ }));
62
+ if (textStyle !== false) {
63
+ extensions.push(TextStyle.configure(textStyle));
64
+ }
65
+ if (fontSize !== false) {
66
+ extensions.push(FontSize.configure(fontSize));
67
+ }
68
+ if (color !== false) {
69
+ extensions.push(Color.configure(color));
70
+ }
71
+ if (lineHeight !== false) {
72
+ extensions.push(LineHeight.configure(lineHeight));
194
73
  }
195
- });
196
74
  }
197
- }));
198
- }
199
- if (this.options.tableCell !== false) {
200
- extensions.push(_extensionTableCell["default"]);
201
- }
202
- if (this.options.tableHeader !== false) {
203
- extensions.push(_extensionTableHeader["default"]);
204
- }
205
- if (this.options.tableRow !== false) {
206
- extensions.push(_extensionTableRow["default"]);
207
- }
208
- if (this.options.text !== false) {
209
- extensions.push(_extensionText["default"]);
210
- }
211
- if (this.options.textAlign !== false) {
212
- extensions.push(_extensionTextAlign["default"].configure({
213
- types: ['heading', 'paragraph'],
214
- alignments: ['start', 'end', 'left', 'center', 'right', 'justify']
215
- }));
216
- }
217
- if (this.options.underline !== false) {
218
- extensions.push(_extensionUnderline["default"]);
219
- }
220
- if (this.options.youtube !== false) {
221
- extensions.push(_youtube.Youtube);
75
+ if (highlight !== false) {
76
+ extensions.push(Highlight.configure(highlight));
77
+ }
78
+ if (blockSpacing !== false) {
79
+ extensions.push(BlockSpacing.configure(blockSpacing));
80
+ }
81
+ if (textAlign !== false) {
82
+ extensions.push(TextAlign.configure(textAlign));
83
+ }
84
+ if (superscript !== false) {
85
+ extensions.push(Superscript.configure(superscript));
86
+ }
87
+ if (image !== false) {
88
+ extensions.push(Image.configure(image));
89
+ }
90
+ if (youtube !== false) {
91
+ extensions.push(Youtube.configure(youtube));
92
+ }
93
+ if (plainSpaces !== false) {
94
+ extensions.push(PlainSpaces);
95
+ }
96
+ return extensions;
222
97
  }
223
- return extensions;
224
- }
225
98
  });
226
- exports.TiptapEssentials = TiptapEssentials;
@@ -0,0 +1,21 @@
1
+ declare module '@tiptap/core' {
2
+ interface Commands<ReturnType> {
3
+ titledYoutube: {
4
+ /** Inserts a video, named by its title. */
5
+ setYoutubeVideo: (options: {
6
+ src: string;
7
+ title: string;
8
+ start?: number;
9
+ width?: number | string;
10
+ height?: number | string;
11
+ }) => ReturnType;
12
+ };
13
+ }
14
+ }
15
+ /**
16
+ * Tiptap's YouTube video, named by a title, which a page names its thumbnail
17
+ * and its player by. The editor draws it as its thumbnail: drawing the player
18
+ * would load YouTube's for every video as the editor opens. Read as well from
19
+ * the frame 1.x wrote, a bare `<iframe>` of a YouTube address.
20
+ */
21
+ export declare const Youtube: import("@tiptap/core").Node<import("@tiptap/extension-youtube").YoutubeOptions, any>;
@@ -0,0 +1,50 @@
1
+ import TiptapYoutube from '@tiptap/extension-youtube';
2
+ // What a body keeps of a video's frame: Tiptap writes a dozen more, each of
3
+ // them in its address as well.
4
+ const KEPT = ['src', 'title', 'width', 'height', 'allowfullscreen'];
5
+ const VIDEO_ID = /(?:[?&]v=|\/embed\/|youtu\.be\/|\/shorts\/|\/live\/)([\w-]{11})/;
6
+ /**
7
+ * Tiptap's YouTube video, named by a title, which a page names its thumbnail
8
+ * and its player by. The editor draws it as its thumbnail: drawing the player
9
+ * would load YouTube's for every video as the editor opens. Read as well from
10
+ * the frame 1.x wrote, a bare `<iframe>` of a YouTube address.
11
+ */
12
+ export const Youtube = TiptapYoutube.extend({
13
+ addAttributes() {
14
+ return {
15
+ ...this.parent?.(),
16
+ title: { default: null }
17
+ };
18
+ },
19
+ parseHTML() {
20
+ return [
21
+ ...(this.parent?.() ?? []),
22
+ {
23
+ tag: 'iframe[src]',
24
+ getAttrs: (element) => element
25
+ .getAttribute('src')
26
+ ?.startsWith('https://www.youtube.com/embed/')
27
+ ? null
28
+ : false
29
+ }
30
+ ];
31
+ },
32
+ renderHTML(props) {
33
+ const [tag, box, [, frame]] = this.parent(props);
34
+ const kept = Object.fromEntries(Object.entries(frame).filter(([name]) => KEPT.includes(name)));
35
+ return [tag, box, ['iframe', kept]];
36
+ },
37
+ addNodeView() {
38
+ return ({ node }) => {
39
+ const dom = document.createElement('div');
40
+ dom.setAttribute('data-youtube-video', '');
41
+ const thumbnail = dom.appendChild(document.createElement('img'));
42
+ const id = VIDEO_ID.exec(String(node.attrs['src'] ?? ''))?.[1];
43
+ if (id) {
44
+ thumbnail.setAttribute('src', `https://i.ytimg.com/vi/${id}/hqdefault.jpg`);
45
+ }
46
+ thumbnail.setAttribute('alt', String(node.attrs['title'] ?? ''));
47
+ return { dom };
48
+ };
49
+ }
50
+ });
package/package.json CHANGED
@@ -1,52 +1,54 @@
1
1
  {
2
2
  "name": "tiptap-essentials",
3
- "version": "1.2.1",
3
+ "version": "2.0.0-beta.3",
4
4
  "description": "Essential extensions of Tiptap",
5
- "main": "index.js",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ },
11
+ "./samples": {
12
+ "types": "./dist/samples.d.ts",
13
+ "default": "./dist/samples.js"
14
+ }
15
+ },
16
+ "types": "./dist/index.d.ts",
17
+ "files": [
18
+ "dist"
19
+ ],
6
20
  "scripts": {
7
- "build": "babel src -d dist",
8
- "prepublish": "npm run build"
21
+ "build": "rm -rf dist && tsc",
22
+ "test": "vitest run",
23
+ "prepack": "npm run build",
24
+ "prepublishOnly": "npm test",
25
+ "write-samples": "npm run build && node scripts/write-samples.mjs"
9
26
  },
10
27
  "repository": {
11
28
  "type": "git",
12
29
  "url": "git://github.com/musaffa/tiptap-essentials.git"
13
30
  },
31
+ "peerDependencies": {
32
+ "@tiptap/core": "^3.35.0",
33
+ "@tiptap/pm": "^3.35.0"
34
+ },
14
35
  "dependencies": {
15
- "@tiptap/core": "^2.11.9",
16
- "@tiptap/pm": "^2.11.9",
17
- "@tiptap/extension-blockquote": "^2.11.9",
18
- "@tiptap/extension-bold": "^2.11.9",
19
- "@tiptap/extension-bullet-list": "^2.11.9",
20
- "@tiptap/extension-code": "^2.11.9",
21
- "@tiptap/extension-code-block": "^2.11.9",
22
- "@tiptap/extension-document": "^2.11.9",
23
- "@tiptap/extension-dropcursor": "^2.11.9",
24
- "@tiptap/extension-gapcursor": "^2.11.9",
25
- "@tiptap/extension-hard-break": "^2.11.9",
26
- "@tiptap/extension-heading": "^2.11.9",
27
- "@tiptap/extension-history": "^2.11.9",
28
- "@tiptap/extension-horizontal-rule": "^2.11.9",
29
- "@tiptap/extension-image": "^2.11.9",
30
- "@tiptap/extension-italic": "^2.11.9",
31
- "@tiptap/extension-link": "^2.11.9",
32
- "@tiptap/extension-list-item": "^2.11.9",
33
- "@tiptap/extension-ordered-list": "^2.11.9",
34
- "@tiptap/extension-paragraph": "^2.11.9",
35
- "@tiptap/extension-strike": "^2.11.9",
36
- "@tiptap/extension-superscript": "^2.11.9",
37
- "@tiptap/extension-table": "^2.11.9",
38
- "@tiptap/extension-table-cell": "^2.11.9",
39
- "@tiptap/extension-table-header": "^2.11.9",
40
- "@tiptap/extension-table-row": "^2.11.9",
41
- "@tiptap/extension-text": "^2.11.9",
42
- "@tiptap/extension-text-align": "^2.11.9",
43
- "@tiptap/extension-underline": "^2.11.9"
36
+ "@tiptap/extension-highlight": "^3.35.0",
37
+ "@tiptap/extension-image": "^3.35.0",
38
+ "@tiptap/extension-superscript": "^3.35.0",
39
+ "@tiptap/extension-table": "^3.35.0",
40
+ "@tiptap/extension-text-align": "^3.35.0",
41
+ "@tiptap/extension-text-style": "^3.35.0",
42
+ "@tiptap/extension-youtube": "^3.35.0",
43
+ "@tiptap/starter-kit": "^3.35.0"
44
44
  },
45
- "author": "Ahmad Musaffa",
46
- "license": "MIT",
47
45
  "devDependencies": {
48
- "@babel/cli": "^7.16.0",
49
- "@babel/core": "^7.16.0",
50
- "@babel/preset-env": "^7.16.0"
51
- }
46
+ "@tiptap/core": "3.35.0",
47
+ "@tiptap/pm": "3.35.0",
48
+ "happy-dom": "^21.0.4",
49
+ "typescript": "^6.0.3",
50
+ "vitest": "^5.1.1"
51
+ },
52
+ "author": "Ahmad Musaffa",
53
+ "license": "MIT"
52
54
  }