@tiptap/extension-image 3.30.2 → 3.30.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,237 +1,181 @@
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);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- Image: () => Image,
24
- default: () => index_default,
25
- inputRegex: () => inputRegex
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
26
4
  });
27
- module.exports = __toCommonJS(index_exports);
28
-
29
- // src/image.ts
30
- var import_core = require("@tiptap/core");
31
- var inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
32
- var Image = import_core.Node.create({
33
- name: "image",
34
- addOptions() {
35
- return {
36
- inline: false,
37
- allowBase64: false,
38
- HTMLAttributes: {},
39
- resize: false
40
- };
41
- },
42
- inline() {
43
- return this.options.inline;
44
- },
45
- group() {
46
- return this.options.inline ? "inline" : "block";
47
- },
48
- draggable: true,
49
- addAttributes() {
50
- return {
51
- src: {
52
- default: null
53
- },
54
- alt: {
55
- default: null
56
- },
57
- title: {
58
- default: null
59
- },
60
- width: {
61
- default: null
62
- },
63
- height: {
64
- default: null
65
- }
66
- };
67
- },
68
- parseHTML() {
69
- return [
70
- {
71
- tag: this.options.allowBase64 ? "img[src]" : 'img[src]:not([src^="data:"])'
72
- }
73
- ];
74
- },
75
- renderHTML({ HTMLAttributes }) {
76
- return ["img", (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes)];
77
- },
78
- parseMarkdown: (token, helpers) => {
79
- return helpers.createNode("image", {
80
- src: token.href,
81
- title: token.title,
82
- alt: token.text
83
- });
84
- },
85
- renderMarkdown: (node) => {
86
- var _a, _b, _c, _d, _e, _f;
87
- const src = (_b = (_a = node.attrs) == null ? void 0 : _a.src) != null ? _b : "";
88
- const alt = (_d = (_c = node.attrs) == null ? void 0 : _c.alt) != null ? _d : "";
89
- const title = (_f = (_e = node.attrs) == null ? void 0 : _e.title) != null ? _f : "";
90
- return title ? `![${alt}](${src} "${title}")` : `![${alt}](${src})`;
91
- },
92
- addNodeView() {
93
- if (!this.options.resize || !this.options.resize.enabled || typeof document === "undefined") {
94
- return null;
95
- }
96
- const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize;
97
- const resizeManagedAttributes = /* @__PURE__ */ new Set(["src", "width", "height"]);
98
- return ({ node, getPos, HTMLAttributes, editor }) => {
99
- const el = document.createElement("img");
100
- el.draggable = false;
101
- const mergedAttributes = (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes);
102
- Object.entries(mergedAttributes).forEach(([key, value]) => {
103
- if (value != null) {
104
- switch (key) {
105
- case "src":
106
- case "width":
107
- case "height":
108
- break;
109
- default:
110
- el.setAttribute(key, value);
111
- break;
112
- }
113
- }
114
- });
115
- if (mergedAttributes.src !== null) {
116
- el.src = mergedAttributes.src;
117
- }
118
- let previousHTMLAttributes = { ...HTMLAttributes };
119
- const syncImageSource = (src) => {
120
- if (typeof src === "string" && src !== "") {
121
- if (el.getAttribute("src") !== src) {
122
- el.src = src;
123
- }
124
- return;
125
- }
126
- if (el.hasAttribute("src")) {
127
- el.removeAttribute("src");
128
- }
129
- if (el.src !== "") {
130
- el.src = "";
131
- }
132
- };
133
- syncImageSource(HTMLAttributes.src);
134
- const onUpdate = (updatedNode) => {
135
- if (updatedNode.type !== node.type) {
136
- return false;
137
- }
138
- const extensionAttributes = editor.extensionManager.attributes.filter(
139
- (attribute) => attribute.type === updatedNode.type.name
140
- );
141
- const newHTMLAttributes = (0, import_core.getRenderedAttributes)(updatedNode, extensionAttributes);
142
- Object.keys(previousHTMLAttributes).forEach((key) => {
143
- if (!resizeManagedAttributes.has(key) && !(key in newHTMLAttributes)) {
144
- el.removeAttribute(key);
145
- }
146
- });
147
- Object.entries(newHTMLAttributes).forEach(([key, value]) => {
148
- if (resizeManagedAttributes.has(key)) {
149
- return;
150
- }
151
- if (value != null) {
152
- el.setAttribute(key, value);
153
- } else {
154
- el.removeAttribute(key);
155
- }
156
- });
157
- syncImageSource(newHTMLAttributes.src);
158
- previousHTMLAttributes = newHTMLAttributes;
159
- return true;
160
- };
161
- const nodeView = new import_core.ResizableNodeView({
162
- element: el,
163
- editor,
164
- node,
165
- getPos,
166
- onResize: (width, height) => {
167
- el.style.width = `${width}px`;
168
- el.style.height = `${height}px`;
169
- },
170
- onCommit: (width, height) => {
171
- const pos = getPos();
172
- if (pos === void 0) {
173
- return;
174
- }
175
- this.editor.chain().setNodeSelection(pos).updateAttributes(this.name, {
176
- width,
177
- height
178
- }).run();
179
- },
180
- onUpdate,
181
- options: {
182
- directions,
183
- min: {
184
- width: minWidth,
185
- height: minHeight
186
- },
187
- preserveAspectRatio: alwaysPreserveAspectRatio === true
188
- }
189
- });
190
- const dom = nodeView.dom;
191
- const showNodeView = () => {
192
- dom.style.visibility = "";
193
- dom.style.pointerEvents = "";
194
- };
195
- dom.style.visibility = "hidden";
196
- dom.style.pointerEvents = "none";
197
- if (el.complete && el.naturalWidth > 0) {
198
- showNodeView();
199
- } else {
200
- el.onload = showNodeView;
201
- el.onerror = showNodeView;
202
- }
203
- return nodeView;
204
- };
205
- },
206
- addCommands() {
207
- return {
208
- setImage: (options) => ({ commands }) => {
209
- return commands.insertContent({
210
- type: this.name,
211
- attrs: options
212
- });
213
- }
214
- };
215
- },
216
- addInputRules() {
217
- return [
218
- (0, import_core.nodeInputRule)({
219
- find: inputRegex,
220
- type: this.type,
221
- getAttributes: (match) => {
222
- const [, , alt, src, title] = match;
223
- return { src, alt, title };
224
- }
225
- })
226
- ];
227
- }
5
+ let _tiptap_core = require("@tiptap/core");
6
+ //#region src/image.ts
7
+ /**
8
+ * Matches an image to a ![image](src "title") on input.
9
+ */
10
+ const inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
11
+ /**
12
+ * This extension allows you to insert images.
13
+ * @see https://www.tiptap.dev/api/nodes/image
14
+ */
15
+ const Image = _tiptap_core.Node.create({
16
+ name: "image",
17
+ addOptions() {
18
+ return {
19
+ inline: false,
20
+ allowBase64: false,
21
+ HTMLAttributes: {},
22
+ resize: false
23
+ };
24
+ },
25
+ inline() {
26
+ return this.options.inline;
27
+ },
28
+ group() {
29
+ return this.options.inline ? "inline" : "block";
30
+ },
31
+ draggable: true,
32
+ addAttributes() {
33
+ return {
34
+ src: { default: null },
35
+ alt: { default: null },
36
+ title: { default: null },
37
+ width: { default: null },
38
+ height: { default: null }
39
+ };
40
+ },
41
+ parseHTML() {
42
+ return [{ tag: this.options.allowBase64 ? "img[src]" : "img[src]:not([src^=\"data:\"])" }];
43
+ },
44
+ renderHTML({ HTMLAttributes }) {
45
+ return ["img", (0, _tiptap_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes)];
46
+ },
47
+ parseMarkdown: (token, helpers) => {
48
+ return helpers.createNode("image", {
49
+ src: token.href,
50
+ title: token.title,
51
+ alt: token.text
52
+ });
53
+ },
54
+ renderMarkdown: (node) => {
55
+ var _node$attrs$src, _node$attrs, _node$attrs$alt, _node$attrs2, _node$attrs$title, _node$attrs3;
56
+ const src = (_node$attrs$src = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.src) !== null && _node$attrs$src !== void 0 ? _node$attrs$src : "";
57
+ const alt = (_node$attrs$alt = (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.alt) !== null && _node$attrs$alt !== void 0 ? _node$attrs$alt : "";
58
+ const title = (_node$attrs$title = (_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.title) !== null && _node$attrs$title !== void 0 ? _node$attrs$title : "";
59
+ return title ? `![${alt}](${src} "${title}")` : `![${alt}](${src})`;
60
+ },
61
+ addNodeView() {
62
+ if (!this.options.resize || !this.options.resize.enabled || typeof document === "undefined") return null;
63
+ const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize;
64
+ const resizeManagedAttributes = /* @__PURE__ */ new Set([
65
+ "src",
66
+ "width",
67
+ "height"
68
+ ]);
69
+ return ({ node, getPos, HTMLAttributes, editor }) => {
70
+ const el = document.createElement("img");
71
+ el.draggable = false;
72
+ const mergedAttributes = (0, _tiptap_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes);
73
+ Object.entries(mergedAttributes).forEach(([key, value]) => {
74
+ if (value != null) switch (key) {
75
+ case "src":
76
+ case "width":
77
+ case "height": break;
78
+ default: el.setAttribute(key, value);
79
+ }
80
+ });
81
+ if (mergedAttributes.src !== null) el.src = mergedAttributes.src;
82
+ let previousHTMLAttributes = { ...HTMLAttributes };
83
+ const syncImageSource = (src) => {
84
+ if (typeof src === "string" && src !== "") {
85
+ if (el.getAttribute("src") !== src) el.src = src;
86
+ return;
87
+ }
88
+ if (el.hasAttribute("src")) el.removeAttribute("src");
89
+ if (el.src !== "") el.src = "";
90
+ };
91
+ syncImageSource(HTMLAttributes.src);
92
+ const onUpdate = (updatedNode) => {
93
+ if (updatedNode.type !== node.type) return false;
94
+ const extensionAttributes = editor.extensionManager.attributes.filter((attribute) => attribute.type === updatedNode.type.name);
95
+ const newHTMLAttributes = (0, _tiptap_core.getRenderedAttributes)(updatedNode, extensionAttributes);
96
+ Object.keys(previousHTMLAttributes).forEach((key) => {
97
+ if (!resizeManagedAttributes.has(key) && !(key in newHTMLAttributes)) el.removeAttribute(key);
98
+ });
99
+ Object.entries(newHTMLAttributes).forEach(([key, value]) => {
100
+ if (resizeManagedAttributes.has(key)) return;
101
+ if (value != null) el.setAttribute(key, value);
102
+ else el.removeAttribute(key);
103
+ });
104
+ syncImageSource(newHTMLAttributes.src);
105
+ previousHTMLAttributes = newHTMLAttributes;
106
+ return true;
107
+ };
108
+ const nodeView = new _tiptap_core.ResizableNodeView({
109
+ element: el,
110
+ editor,
111
+ node,
112
+ getPos,
113
+ onResize: (width, height) => {
114
+ el.style.width = `${width}px`;
115
+ el.style.height = `${height}px`;
116
+ },
117
+ onCommit: (width, height) => {
118
+ const pos = getPos();
119
+ if (pos === void 0) return;
120
+ this.editor.chain().setNodeSelection(pos).updateAttributes(this.name, {
121
+ width,
122
+ height
123
+ }).run();
124
+ },
125
+ onUpdate,
126
+ options: {
127
+ directions,
128
+ min: {
129
+ width: minWidth,
130
+ height: minHeight
131
+ },
132
+ preserveAspectRatio: alwaysPreserveAspectRatio === true
133
+ }
134
+ });
135
+ const dom = nodeView.dom;
136
+ const showNodeView = () => {
137
+ dom.style.visibility = "";
138
+ dom.style.pointerEvents = "";
139
+ };
140
+ dom.style.visibility = "hidden";
141
+ dom.style.pointerEvents = "none";
142
+ if (el.complete && el.naturalWidth > 0) showNodeView();
143
+ else {
144
+ el.onload = showNodeView;
145
+ el.onerror = showNodeView;
146
+ }
147
+ return nodeView;
148
+ };
149
+ },
150
+ addCommands() {
151
+ return { setImage: (options) => ({ commands }) => {
152
+ return commands.insertContent({
153
+ type: this.name,
154
+ attrs: options
155
+ });
156
+ } };
157
+ },
158
+ addInputRules() {
159
+ return [(0, _tiptap_core.nodeInputRule)({
160
+ find: inputRegex,
161
+ type: this.type,
162
+ getAttributes: (match) => {
163
+ const [, , alt, src, title] = match;
164
+ return {
165
+ src,
166
+ alt,
167
+ title
168
+ };
169
+ }
170
+ })];
171
+ }
228
172
  });
173
+ //#endregion
174
+ //#region src/index.ts
175
+ var src_default = Image;
176
+ //#endregion
177
+ exports.Image = Image;
178
+ exports.default = src_default;
179
+ exports.inputRegex = inputRegex;
229
180
 
230
- // src/index.ts
231
- var index_default = Image;
232
- // Annotate the CommonJS export names for ESM import in node:
233
- 0 && (module.exports = {
234
- Image,
235
- inputRegex
236
- });
237
181
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/image.ts"],"sourcesContent":["import { Image } from './image.js'\n\nexport * from './image.js'\n\nexport default Image\n","import type { ResizableNodeViewDirection, ResizableNodeViewOptions } from '@tiptap/core'\nimport {\n getRenderedAttributes,\n mergeAttributes,\n Node,\n nodeInputRule,\n ResizableNodeView,\n} from '@tiptap/core'\n\nexport interface ImageOptions {\n /**\n * Controls if the image node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean\n\n /**\n * Controls if base64 images are allowed. Enable this if you want to allow\n * base64 image urls in the `src` attribute.\n * @default false\n * @example true\n */\n allowBase64: boolean\n\n /**\n * HTML attributes to add to the image element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Controls if the image should be resizable and how the resize is configured.\n * @default false\n * @example { directions: { top: true, right: true, bottom: true, left: true, topLeft: true, topRight: true, bottomLeft: true, bottomRight: true }, minWidth: 100, minHeight: 100 }\n */\n resize:\n | {\n enabled: boolean\n directions?: ResizableNodeViewDirection[]\n minWidth?: number\n minHeight?: number\n alwaysPreserveAspectRatio?: boolean\n }\n | false\n}\n\nexport interface SetImageOptions {\n src: string\n alt?: string\n title?: string\n width?: number\n height?: number\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n image: {\n /**\n * Add an image\n * @param options The image attributes\n * @example\n * editor\n * .commands\n * .setImage({ src: 'https://tiptap.dev/logo.png', alt: 'tiptap', title: 'tiptap logo' })\n */\n setImage: (options: SetImageOptions) => ReturnType\n }\n }\n}\n\n/**\n * Matches an image to a ![image](src \"title\") on input.\n */\nexport const inputRegex = /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/\n\n/**\n * This extension allows you to insert images.\n * @see https://www.tiptap.dev/api/nodes/image\n */\nexport const Image = Node.create<ImageOptions>({\n name: 'image',\n\n addOptions() {\n return {\n inline: false,\n allowBase64: false,\n HTMLAttributes: {},\n resize: false,\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 alt: {\n default: null,\n },\n title: {\n default: null,\n },\n width: {\n default: null,\n },\n height: {\n default: null,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: this.options.allowBase64 ? 'img[src]' : 'img[src]:not([src^=\"data:\"])',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n parseMarkdown: (token, helpers) => {\n return helpers.createNode('image', {\n src: token.href,\n title: token.title,\n alt: token.text,\n })\n },\n\n renderMarkdown: node => {\n const src = node.attrs?.src ?? ''\n const alt = node.attrs?.alt ?? ''\n const title = node.attrs?.title ?? ''\n\n return title ? `![${alt}](${src} \"${title}\")` : `![${alt}](${src})`\n },\n\n addNodeView() {\n if (!this.options.resize || !this.options.resize.enabled || typeof document === 'undefined') {\n return null\n }\n\n const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize\n const resizeManagedAttributes = new Set(['src', 'width', 'height'])\n\n return ({ node, getPos, HTMLAttributes, editor }) => {\n const el = document.createElement('img')\n el.draggable = false\n\n const mergedAttributes = mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)\n\n Object.entries(mergedAttributes).forEach(([key, value]) => {\n if (value != null) {\n switch (key) {\n case 'src':\n case 'width':\n case 'height':\n break\n default:\n el.setAttribute(key, value)\n break\n }\n }\n })\n\n if (mergedAttributes.src !== null) {\n el.src = mergedAttributes.src\n }\n\n let previousHTMLAttributes = { ...HTMLAttributes }\n const syncImageSource = (src: unknown) => {\n if (typeof src === 'string' && src !== '') {\n if (el.getAttribute('src') !== src) {\n el.src = src\n }\n\n return\n }\n\n if (el.hasAttribute('src')) {\n el.removeAttribute('src')\n }\n\n if (el.src !== '') {\n el.src = ''\n }\n }\n\n syncImageSource(HTMLAttributes.src)\n\n const onUpdate: ResizableNodeViewOptions['onUpdate'] = (\n updatedNode: Parameters<typeof getRenderedAttributes>[0],\n ) => {\n if (updatedNode.type !== node.type) {\n return false\n }\n\n const extensionAttributes = editor.extensionManager.attributes.filter(\n attribute => attribute.type === updatedNode.type.name,\n )\n const newHTMLAttributes = getRenderedAttributes(updatedNode, extensionAttributes)\n\n // Remove attributes that were previously rendered but are no longer present\n Object.keys(previousHTMLAttributes).forEach(key => {\n if (!resizeManagedAttributes.has(key) && !(key in newHTMLAttributes)) {\n el.removeAttribute(key)\n }\n })\n\n Object.entries(newHTMLAttributes).forEach(([key, value]) => {\n if (resizeManagedAttributes.has(key)) {\n return\n }\n\n if (value != null) {\n el.setAttribute(key, value)\n } else {\n el.removeAttribute(key)\n }\n })\n\n syncImageSource(newHTMLAttributes.src)\n\n previousHTMLAttributes = newHTMLAttributes\n\n return true\n }\n\n const nodeView = new ResizableNodeView({\n element: el,\n editor,\n node,\n getPos,\n onResize: (width, height) => {\n el.style.width = `${width}px`\n el.style.height = `${height}px`\n },\n onCommit: (width, height) => {\n const pos = getPos()\n if (pos === undefined) {\n return\n }\n\n this.editor\n .chain()\n .setNodeSelection(pos)\n .updateAttributes(this.name, {\n width,\n height,\n })\n .run()\n },\n onUpdate,\n options: {\n directions,\n min: {\n width: minWidth,\n height: minHeight,\n },\n preserveAspectRatio: alwaysPreserveAspectRatio === true,\n },\n })\n\n const dom = nodeView.dom as HTMLElement\n\n // when image is loaded, show the node view to get the correct dimensions\n const showNodeView = () => {\n dom.style.visibility = ''\n dom.style.pointerEvents = ''\n }\n\n dom.style.visibility = 'hidden'\n dom.style.pointerEvents = 'none'\n\n if (el.complete && el.naturalWidth > 0) {\n // A cached image is already complete before this node view mounts, so\n // `load` never fires again and the image would stay hidden forever.\n showNodeView()\n } else {\n el.onload = showNodeView\n // Reveal on error too, so a broken src renders as an inspectable broken\n // image instead of an invisible node.\n el.onerror = showNodeView\n }\n\n return nodeView\n }\n },\n\n addCommands() {\n return {\n setImage:\n options =>\n ({ commands }) => {\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n addInputRules() {\n return [\n nodeInputRule({\n find: inputRegex,\n type: this.type,\n getAttributes: match => {\n const [, , alt, src, title] = match\n\n return { src, alt, title }\n },\n }),\n ]\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAMO;AAoEA,IAAM,aAAa;AAMnB,IAAM,QAAQ,iBAAK,OAAqB;AAAA,EAC7C,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,gBAAgB,CAAC;AAAA,MACjB,QAAQ;AAAA,IACV;AAAA,EACF;AAAA,EAEA,SAAS;AACP,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA,EAEA,QAAQ;AACN,WAAO,KAAK,QAAQ,SAAS,WAAW;AAAA,EAC1C;AAAA,EAEA,WAAW;AAAA,EAEX,gBAAgB;AACd,WAAO;AAAA,MACL,KAAK;AAAA,QACH,SAAS;AAAA,MACX;AAAA,MACA,KAAK;AAAA,QACH,SAAS;AAAA,MACX;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,MACX;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,MACX;AAAA,MACA,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IACJ;AAAA,EACF;AAAA,EAEA,gBAAgB;AACd,WAAO;AAAA,UACL,2BAAc;AAAA,QACZ,MAAM;AAAA,QACN,MAAM,KAAK;AAAA,QACX,eAAe,WAAS;AACtB,gBAAM,CAAC,EAAE,EAAE,KAAK,KAAK,KAAK,IAAI;AAE9B,iBAAO,EAAE,KAAK,KAAK,MAAM;AAAA,QAC3B;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;ADrUD,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"file":"index.cjs","names":["Node","mergeAttributes","getRenderedAttributes","ResizableNodeView","nodeInputRule"],"sources":["../src/image.ts","../src/index.ts"],"sourcesContent":["import type { ResizableNodeViewDirection, ResizableNodeViewOptions } from '@tiptap/core'\nimport {\n getRenderedAttributes,\n mergeAttributes,\n Node,\n nodeInputRule,\n ResizableNodeView,\n} from '@tiptap/core'\n\nexport interface ImageOptions {\n /**\n * Controls if the image node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean\n\n /**\n * Controls if base64 images are allowed. Enable this if you want to allow\n * base64 image urls in the `src` attribute.\n * @default false\n * @example true\n */\n allowBase64: boolean\n\n /**\n * HTML attributes to add to the image element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Controls if the image should be resizable and how the resize is configured.\n * @default false\n * @example { directions: { top: true, right: true, bottom: true, left: true, topLeft: true, topRight: true, bottomLeft: true, bottomRight: true }, minWidth: 100, minHeight: 100 }\n */\n resize:\n | {\n enabled: boolean\n directions?: ResizableNodeViewDirection[]\n minWidth?: number\n minHeight?: number\n alwaysPreserveAspectRatio?: boolean\n }\n | false\n}\n\nexport interface SetImageOptions {\n src: string\n alt?: string\n title?: string\n width?: number\n height?: number\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n image: {\n /**\n * Add an image\n * @param options The image attributes\n * @example\n * editor\n * .commands\n * .setImage({ src: 'https://tiptap.dev/logo.png', alt: 'tiptap', title: 'tiptap logo' })\n */\n setImage: (options: SetImageOptions) => ReturnType\n }\n }\n}\n\n/**\n * Matches an image to a ![image](src \"title\") on input.\n */\nexport const inputRegex = /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/\n\n/**\n * This extension allows you to insert images.\n * @see https://www.tiptap.dev/api/nodes/image\n */\nexport const Image = Node.create<ImageOptions>({\n name: 'image',\n\n addOptions() {\n return {\n inline: false,\n allowBase64: false,\n HTMLAttributes: {},\n resize: false,\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 alt: {\n default: null,\n },\n title: {\n default: null,\n },\n width: {\n default: null,\n },\n height: {\n default: null,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: this.options.allowBase64 ? 'img[src]' : 'img[src]:not([src^=\"data:\"])',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n parseMarkdown: (token, helpers) => {\n return helpers.createNode('image', {\n src: token.href,\n title: token.title,\n alt: token.text,\n })\n },\n\n renderMarkdown: node => {\n const src = node.attrs?.src ?? ''\n const alt = node.attrs?.alt ?? ''\n const title = node.attrs?.title ?? ''\n\n return title ? `![${alt}](${src} \"${title}\")` : `![${alt}](${src})`\n },\n\n addNodeView() {\n if (!this.options.resize || !this.options.resize.enabled || typeof document === 'undefined') {\n return null\n }\n\n const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize\n const resizeManagedAttributes = new Set(['src', 'width', 'height'])\n\n return ({ node, getPos, HTMLAttributes, editor }) => {\n const el = document.createElement('img')\n el.draggable = false\n\n const mergedAttributes = mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)\n\n Object.entries(mergedAttributes).forEach(([key, value]) => {\n if (value != null) {\n switch (key) {\n case 'src':\n case 'width':\n case 'height':\n break\n default:\n el.setAttribute(key, value)\n break\n }\n }\n })\n\n if (mergedAttributes.src !== null) {\n el.src = mergedAttributes.src\n }\n\n let previousHTMLAttributes = { ...HTMLAttributes }\n const syncImageSource = (src: unknown) => {\n if (typeof src === 'string' && src !== '') {\n if (el.getAttribute('src') !== src) {\n el.src = src\n }\n\n return\n }\n\n if (el.hasAttribute('src')) {\n el.removeAttribute('src')\n }\n\n if (el.src !== '') {\n el.src = ''\n }\n }\n\n syncImageSource(HTMLAttributes.src)\n\n const onUpdate: ResizableNodeViewOptions['onUpdate'] = (\n updatedNode: Parameters<typeof getRenderedAttributes>[0],\n ) => {\n if (updatedNode.type !== node.type) {\n return false\n }\n\n const extensionAttributes = editor.extensionManager.attributes.filter(\n attribute => attribute.type === updatedNode.type.name,\n )\n const newHTMLAttributes = getRenderedAttributes(updatedNode, extensionAttributes)\n\n // Remove attributes that were previously rendered but are no longer present\n Object.keys(previousHTMLAttributes).forEach(key => {\n if (!resizeManagedAttributes.has(key) && !(key in newHTMLAttributes)) {\n el.removeAttribute(key)\n }\n })\n\n Object.entries(newHTMLAttributes).forEach(([key, value]) => {\n if (resizeManagedAttributes.has(key)) {\n return\n }\n\n if (value != null) {\n el.setAttribute(key, value)\n } else {\n el.removeAttribute(key)\n }\n })\n\n syncImageSource(newHTMLAttributes.src)\n\n previousHTMLAttributes = newHTMLAttributes\n\n return true\n }\n\n const nodeView = new ResizableNodeView({\n element: el,\n editor,\n node,\n getPos,\n onResize: (width, height) => {\n el.style.width = `${width}px`\n el.style.height = `${height}px`\n },\n onCommit: (width, height) => {\n const pos = getPos()\n if (pos === undefined) {\n return\n }\n\n this.editor\n .chain()\n .setNodeSelection(pos)\n .updateAttributes(this.name, {\n width,\n height,\n })\n .run()\n },\n onUpdate,\n options: {\n directions,\n min: {\n width: minWidth,\n height: minHeight,\n },\n preserveAspectRatio: alwaysPreserveAspectRatio === true,\n },\n })\n\n const dom = nodeView.dom as HTMLElement\n\n // when image is loaded, show the node view to get the correct dimensions\n const showNodeView = () => {\n dom.style.visibility = ''\n dom.style.pointerEvents = ''\n }\n\n dom.style.visibility = 'hidden'\n dom.style.pointerEvents = 'none'\n\n if (el.complete && el.naturalWidth > 0) {\n // A cached image is already complete before this node view mounts, so\n // `load` never fires again and the image would stay hidden forever.\n showNodeView()\n } else {\n el.onload = showNodeView\n // Reveal on error too, so a broken src renders as an inspectable broken\n // image instead of an invisible node.\n el.onerror = showNodeView\n }\n\n return nodeView\n }\n },\n\n addCommands() {\n return {\n setImage:\n options =>\n ({ commands }) => {\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n addInputRules() {\n return [\n nodeInputRule({\n find: inputRegex,\n type: this.type,\n getAttributes: match => {\n const [, , alt, src, title] = match\n\n return { src, alt, title }\n },\n }),\n ]\n },\n})\n","import { Image } from './image.js'\n\nexport * from './image.js'\n\nexport default Image\n"],"mappings":";;;;;;;;;AA2EA,MAAa,aAAa;;;;;AAM1B,MAAa,QAAQA,aAAAA,KAAK,OAAqB;CAC7C,MAAM;CAEN,aAAa;EACX,OAAO;GACL,QAAQ;GACR,aAAa;GACb,gBAAgB,CAAC;GACjB,QAAQ;EACV;CACF;CAEA,SAAS;EACP,OAAO,KAAK,QAAQ;CACtB;CAEA,QAAQ;EACN,OAAO,KAAK,QAAQ,SAAS,WAAW;CAC1C;CAEA,WAAW;CAEX,gBAAgB;EACd,OAAO;GACL,KAAK,EACH,SAAS,KACX;GACA,KAAK,EACH,SAAS,KACX;GACA,OAAO,EACL,SAAS,KACX;GACA,OAAO,EACL,SAAS,KACX;GACA,QAAQ,EACN,SAAS,KACX;EACF;CACF;CAEA,YAAY;EACV,OAAO,CACL,EACE,KAAK,KAAK,QAAQ,cAAc,aAAa,iCAC/C,CACF;CACF;CAEA,WAAW,EAAE,kBAAkB;EAC7B,OAAO,CAAC,QAAA,GAAOC,aAAAA,gBAAAA,CAAgB,KAAK,QAAQ,gBAAgB,cAAc,C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GF,KAAK,OACF,MAAM,CAAC,CACP,iBAAiB,GAAG,CAAC,CACrB,iBAAiB,KAAK,MAAM;MAC3B;MACA;KACF,CAAC,CAAC,CACD,IAAI;IACT;IACA;IACA,SAAS;KACP;KACA,KAAK;MACH,OAAO;MACP,QAAQ;KACV;KACA,qBAAqB,8BAA8B;IACrD;GACF,CAAC;GAED,MAAM,MAAM,SAAS;GAGrB,MAAM,qBAAqB;IACzB,IAAI,MAAM,aAAa;IACvB,IAAI,MAAM,gBAAgB;GAC5B;GAEA,IAAI,MAAM,aAAa;GACvB,IAAI,MAAM,gBAAgB;GAE1B,IAAI,GAAG,YAAY,GAAG,eAAe,GAGnC,aAAa;QACR;IACL,GAAG,SAAS;IAGZ,GAAG,UAAU;GACf;GAEA,OAAO;EACT;CACF;CAEA,cAAc;EACZ,OAAO,EACL,WACE,aACC,EAAE,eAAe;GAChB,OAAO,SAAS,cAAc;IAC5B,MAAM,KAAK;IACX,OAAO;GACT,CAAC;EACH,EACJ;CACF;CAEA,gBAAgB;EACd,OAAO,EAAA,GACLC,aAAAA,cAAAA,CAAc;GACZ,MAAM;GACN,MAAM,KAAK;GACX,gBAAe,UAAS;IACtB,MAAM,KAAK,KAAK,KAAK,SAAS;IAE9B,OAAO;KAAE;KAAK;KAAK;IAAM;GAC3B;EACF,CAAC,CACH;CACF;AACF,CAAC;;;ACrUD,IAAA,cAAe"}
package/dist/index.d.cts CHANGED
@@ -1,59 +1,59 @@
1
- import { Node, ResizableNodeViewDirection } from '@tiptap/core';
2
-
1
+ import { Node, ResizableNodeViewDirection } from "@tiptap/core";
2
+ //#region src/image.d.ts
3
3
  interface ImageOptions {
4
- /**
5
- * Controls if the image node should be inline or not.
6
- * @default false
7
- * @example true
8
- */
9
- inline: boolean;
10
- /**
11
- * Controls if base64 images are allowed. Enable this if you want to allow
12
- * base64 image urls in the `src` attribute.
13
- * @default false
14
- * @example true
15
- */
16
- allowBase64: boolean;
17
- /**
18
- * HTML attributes to add to the image element.
19
- * @default {}
20
- * @example { class: 'foo' }
21
- */
22
- HTMLAttributes: Record<string, any>;
23
- /**
24
- * Controls if the image should be resizable and how the resize is configured.
25
- * @default false
26
- * @example { directions: { top: true, right: true, bottom: true, left: true, topLeft: true, topRight: true, bottomLeft: true, bottomRight: true }, minWidth: 100, minHeight: 100 }
27
- */
28
- resize: {
29
- enabled: boolean;
30
- directions?: ResizableNodeViewDirection[];
31
- minWidth?: number;
32
- minHeight?: number;
33
- alwaysPreserveAspectRatio?: boolean;
34
- } | false;
4
+ /**
5
+ * Controls if the image node should be inline or not.
6
+ * @default false
7
+ * @example true
8
+ */
9
+ inline: boolean;
10
+ /**
11
+ * Controls if base64 images are allowed. Enable this if you want to allow
12
+ * base64 image urls in the `src` attribute.
13
+ * @default false
14
+ * @example true
15
+ */
16
+ allowBase64: boolean;
17
+ /**
18
+ * HTML attributes to add to the image element.
19
+ * @default {}
20
+ * @example { class: 'foo' }
21
+ */
22
+ HTMLAttributes: Record<string, any>;
23
+ /**
24
+ * Controls if the image should be resizable and how the resize is configured.
25
+ * @default false
26
+ * @example { directions: { top: true, right: true, bottom: true, left: true, topLeft: true, topRight: true, bottomLeft: true, bottomRight: true }, minWidth: 100, minHeight: 100 }
27
+ */
28
+ resize: {
29
+ enabled: boolean;
30
+ directions?: ResizableNodeViewDirection[];
31
+ minWidth?: number;
32
+ minHeight?: number;
33
+ alwaysPreserveAspectRatio?: boolean;
34
+ } | false;
35
35
  }
36
36
  interface SetImageOptions {
37
- src: string;
38
- alt?: string;
39
- title?: string;
40
- width?: number;
41
- height?: number;
37
+ src: string;
38
+ alt?: string;
39
+ title?: string;
40
+ width?: number;
41
+ height?: number;
42
42
  }
43
43
  declare module '@tiptap/core' {
44
- interface Commands<ReturnType> {
45
- image: {
46
- /**
47
- * Add an image
48
- * @param options The image attributes
49
- * @example
50
- * editor
51
- * .commands
52
- * .setImage({ src: 'https://tiptap.dev/logo.png', alt: 'tiptap', title: 'tiptap logo' })
53
- */
54
- setImage: (options: SetImageOptions) => ReturnType;
55
- };
56
- }
44
+ interface Commands<ReturnType> {
45
+ image: {
46
+ /**
47
+ * Add an image
48
+ * @param options The image attributes
49
+ * @example
50
+ * editor
51
+ * .commands
52
+ * .setImage({ src: 'https://tiptap.dev/logo.png', alt: 'tiptap', title: 'tiptap logo' })
53
+ */
54
+ setImage: (options: SetImageOptions) => ReturnType;
55
+ };
56
+ }
57
57
  }
58
58
  /**
59
59
  * Matches an image to a ![image](src "title") on input.
@@ -64,5 +64,6 @@ declare const inputRegex: RegExp;
64
64
  * @see https://www.tiptap.dev/api/nodes/image
65
65
  */
66
66
  declare const Image: Node<ImageOptions, any>;
67
-
68
- export { Image, type ImageOptions, type SetImageOptions, Image as default, inputRegex };
67
+ //#endregion
68
+ export { Image, Image as default, ImageOptions, SetImageOptions, inputRegex };
69
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/image.ts"],"mappings":";;UASiB;;;;;;EAMf;;;;;;;EAQA;;;;;;EAOA,gBAAgB;;;;;;EAOhB;IAEM;IACA,aAAa;IACb;IACA;IACA;;;UAKS;EACf;EACA;EACA;EACA;EACA;;;YAIU,SAAS;IACjB;;;;;;;;;MASE,WAAW,SAAS,oBAAoB;;;;;;;cAQjC,YAAU;;;;;cAMV,OAAK,KAAA"}
package/dist/index.d.ts CHANGED
@@ -1,59 +1,59 @@
1
- import { Node, ResizableNodeViewDirection } from '@tiptap/core';
2
-
1
+ import { Node, ResizableNodeViewDirection } from "@tiptap/core";
2
+ //#region src/image.d.ts
3
3
  interface ImageOptions {
4
- /**
5
- * Controls if the image node should be inline or not.
6
- * @default false
7
- * @example true
8
- */
9
- inline: boolean;
10
- /**
11
- * Controls if base64 images are allowed. Enable this if you want to allow
12
- * base64 image urls in the `src` attribute.
13
- * @default false
14
- * @example true
15
- */
16
- allowBase64: boolean;
17
- /**
18
- * HTML attributes to add to the image element.
19
- * @default {}
20
- * @example { class: 'foo' }
21
- */
22
- HTMLAttributes: Record<string, any>;
23
- /**
24
- * Controls if the image should be resizable and how the resize is configured.
25
- * @default false
26
- * @example { directions: { top: true, right: true, bottom: true, left: true, topLeft: true, topRight: true, bottomLeft: true, bottomRight: true }, minWidth: 100, minHeight: 100 }
27
- */
28
- resize: {
29
- enabled: boolean;
30
- directions?: ResizableNodeViewDirection[];
31
- minWidth?: number;
32
- minHeight?: number;
33
- alwaysPreserveAspectRatio?: boolean;
34
- } | false;
4
+ /**
5
+ * Controls if the image node should be inline or not.
6
+ * @default false
7
+ * @example true
8
+ */
9
+ inline: boolean;
10
+ /**
11
+ * Controls if base64 images are allowed. Enable this if you want to allow
12
+ * base64 image urls in the `src` attribute.
13
+ * @default false
14
+ * @example true
15
+ */
16
+ allowBase64: boolean;
17
+ /**
18
+ * HTML attributes to add to the image element.
19
+ * @default {}
20
+ * @example { class: 'foo' }
21
+ */
22
+ HTMLAttributes: Record<string, any>;
23
+ /**
24
+ * Controls if the image should be resizable and how the resize is configured.
25
+ * @default false
26
+ * @example { directions: { top: true, right: true, bottom: true, left: true, topLeft: true, topRight: true, bottomLeft: true, bottomRight: true }, minWidth: 100, minHeight: 100 }
27
+ */
28
+ resize: {
29
+ enabled: boolean;
30
+ directions?: ResizableNodeViewDirection[];
31
+ minWidth?: number;
32
+ minHeight?: number;
33
+ alwaysPreserveAspectRatio?: boolean;
34
+ } | false;
35
35
  }
36
36
  interface SetImageOptions {
37
- src: string;
38
- alt?: string;
39
- title?: string;
40
- width?: number;
41
- height?: number;
37
+ src: string;
38
+ alt?: string;
39
+ title?: string;
40
+ width?: number;
41
+ height?: number;
42
42
  }
43
43
  declare module '@tiptap/core' {
44
- interface Commands<ReturnType> {
45
- image: {
46
- /**
47
- * Add an image
48
- * @param options The image attributes
49
- * @example
50
- * editor
51
- * .commands
52
- * .setImage({ src: 'https://tiptap.dev/logo.png', alt: 'tiptap', title: 'tiptap logo' })
53
- */
54
- setImage: (options: SetImageOptions) => ReturnType;
55
- };
56
- }
44
+ interface Commands<ReturnType> {
45
+ image: {
46
+ /**
47
+ * Add an image
48
+ * @param options The image attributes
49
+ * @example
50
+ * editor
51
+ * .commands
52
+ * .setImage({ src: 'https://tiptap.dev/logo.png', alt: 'tiptap', title: 'tiptap logo' })
53
+ */
54
+ setImage: (options: SetImageOptions) => ReturnType;
55
+ };
56
+ }
57
57
  }
58
58
  /**
59
59
  * Matches an image to a ![image](src "title") on input.
@@ -64,5 +64,6 @@ declare const inputRegex: RegExp;
64
64
  * @see https://www.tiptap.dev/api/nodes/image
65
65
  */
66
66
  declare const Image: Node<ImageOptions, any>;
67
-
68
- export { Image, type ImageOptions, type SetImageOptions, Image as default, inputRegex };
67
+ //#endregion
68
+ export { Image, Image as default, ImageOptions, SetImageOptions, inputRegex };
69
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/image.ts"],"mappings":";;UASiB;;;;;;EAMf;;;;;;;EAQA;;;;;;EAOA,gBAAgB;;;;;;EAOhB;IAEM;IACA,aAAa;IACb;IACA;IACA;;;UAKS;EACf;EACA;EACA;EACA;EACA;;;YAIU,SAAS;IACjB;;;;;;;;;MASE,WAAW,SAAS,oBAAoB;;;;;;;cAQjC,YAAU;;;;;cAMV,OAAK,KAAA"}
package/dist/index.js CHANGED
@@ -1,215 +1,175 @@
1
- // src/image.ts
2
- import {
3
- getRenderedAttributes,
4
- mergeAttributes,
5
- Node,
6
- nodeInputRule,
7
- ResizableNodeView
8
- } from "@tiptap/core";
9
- var inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
10
- var Image = Node.create({
11
- name: "image",
12
- addOptions() {
13
- return {
14
- inline: false,
15
- allowBase64: false,
16
- HTMLAttributes: {},
17
- resize: false
18
- };
19
- },
20
- inline() {
21
- return this.options.inline;
22
- },
23
- group() {
24
- return this.options.inline ? "inline" : "block";
25
- },
26
- draggable: true,
27
- addAttributes() {
28
- return {
29
- src: {
30
- default: null
31
- },
32
- alt: {
33
- default: null
34
- },
35
- title: {
36
- default: null
37
- },
38
- width: {
39
- default: null
40
- },
41
- height: {
42
- default: null
43
- }
44
- };
45
- },
46
- parseHTML() {
47
- return [
48
- {
49
- tag: this.options.allowBase64 ? "img[src]" : 'img[src]:not([src^="data:"])'
50
- }
51
- ];
52
- },
53
- renderHTML({ HTMLAttributes }) {
54
- return ["img", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)];
55
- },
56
- parseMarkdown: (token, helpers) => {
57
- return helpers.createNode("image", {
58
- src: token.href,
59
- title: token.title,
60
- alt: token.text
61
- });
62
- },
63
- renderMarkdown: (node) => {
64
- var _a, _b, _c, _d, _e, _f;
65
- const src = (_b = (_a = node.attrs) == null ? void 0 : _a.src) != null ? _b : "";
66
- const alt = (_d = (_c = node.attrs) == null ? void 0 : _c.alt) != null ? _d : "";
67
- const title = (_f = (_e = node.attrs) == null ? void 0 : _e.title) != null ? _f : "";
68
- return title ? `![${alt}](${src} "${title}")` : `![${alt}](${src})`;
69
- },
70
- addNodeView() {
71
- if (!this.options.resize || !this.options.resize.enabled || typeof document === "undefined") {
72
- return null;
73
- }
74
- const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize;
75
- const resizeManagedAttributes = /* @__PURE__ */ new Set(["src", "width", "height"]);
76
- return ({ node, getPos, HTMLAttributes, editor }) => {
77
- const el = document.createElement("img");
78
- el.draggable = false;
79
- const mergedAttributes = mergeAttributes(this.options.HTMLAttributes, HTMLAttributes);
80
- Object.entries(mergedAttributes).forEach(([key, value]) => {
81
- if (value != null) {
82
- switch (key) {
83
- case "src":
84
- case "width":
85
- case "height":
86
- break;
87
- default:
88
- el.setAttribute(key, value);
89
- break;
90
- }
91
- }
92
- });
93
- if (mergedAttributes.src !== null) {
94
- el.src = mergedAttributes.src;
95
- }
96
- let previousHTMLAttributes = { ...HTMLAttributes };
97
- const syncImageSource = (src) => {
98
- if (typeof src === "string" && src !== "") {
99
- if (el.getAttribute("src") !== src) {
100
- el.src = src;
101
- }
102
- return;
103
- }
104
- if (el.hasAttribute("src")) {
105
- el.removeAttribute("src");
106
- }
107
- if (el.src !== "") {
108
- el.src = "";
109
- }
110
- };
111
- syncImageSource(HTMLAttributes.src);
112
- const onUpdate = (updatedNode) => {
113
- if (updatedNode.type !== node.type) {
114
- return false;
115
- }
116
- const extensionAttributes = editor.extensionManager.attributes.filter(
117
- (attribute) => attribute.type === updatedNode.type.name
118
- );
119
- const newHTMLAttributes = getRenderedAttributes(updatedNode, extensionAttributes);
120
- Object.keys(previousHTMLAttributes).forEach((key) => {
121
- if (!resizeManagedAttributes.has(key) && !(key in newHTMLAttributes)) {
122
- el.removeAttribute(key);
123
- }
124
- });
125
- Object.entries(newHTMLAttributes).forEach(([key, value]) => {
126
- if (resizeManagedAttributes.has(key)) {
127
- return;
128
- }
129
- if (value != null) {
130
- el.setAttribute(key, value);
131
- } else {
132
- el.removeAttribute(key);
133
- }
134
- });
135
- syncImageSource(newHTMLAttributes.src);
136
- previousHTMLAttributes = newHTMLAttributes;
137
- return true;
138
- };
139
- const nodeView = new ResizableNodeView({
140
- element: el,
141
- editor,
142
- node,
143
- getPos,
144
- onResize: (width, height) => {
145
- el.style.width = `${width}px`;
146
- el.style.height = `${height}px`;
147
- },
148
- onCommit: (width, height) => {
149
- const pos = getPos();
150
- if (pos === void 0) {
151
- return;
152
- }
153
- this.editor.chain().setNodeSelection(pos).updateAttributes(this.name, {
154
- width,
155
- height
156
- }).run();
157
- },
158
- onUpdate,
159
- options: {
160
- directions,
161
- min: {
162
- width: minWidth,
163
- height: minHeight
164
- },
165
- preserveAspectRatio: alwaysPreserveAspectRatio === true
166
- }
167
- });
168
- const dom = nodeView.dom;
169
- const showNodeView = () => {
170
- dom.style.visibility = "";
171
- dom.style.pointerEvents = "";
172
- };
173
- dom.style.visibility = "hidden";
174
- dom.style.pointerEvents = "none";
175
- if (el.complete && el.naturalWidth > 0) {
176
- showNodeView();
177
- } else {
178
- el.onload = showNodeView;
179
- el.onerror = showNodeView;
180
- }
181
- return nodeView;
182
- };
183
- },
184
- addCommands() {
185
- return {
186
- setImage: (options) => ({ commands }) => {
187
- return commands.insertContent({
188
- type: this.name,
189
- attrs: options
190
- });
191
- }
192
- };
193
- },
194
- addInputRules() {
195
- return [
196
- nodeInputRule({
197
- find: inputRegex,
198
- type: this.type,
199
- getAttributes: (match) => {
200
- const [, , alt, src, title] = match;
201
- return { src, alt, title };
202
- }
203
- })
204
- ];
205
- }
1
+ import { Node, ResizableNodeView, getRenderedAttributes, mergeAttributes, nodeInputRule } from "@tiptap/core";
2
+ //#region src/image.ts
3
+ /**
4
+ * Matches an image to a ![image](src "title") on input.
5
+ */
6
+ const inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
7
+ /**
8
+ * This extension allows you to insert images.
9
+ * @see https://www.tiptap.dev/api/nodes/image
10
+ */
11
+ const Image = Node.create({
12
+ name: "image",
13
+ addOptions() {
14
+ return {
15
+ inline: false,
16
+ allowBase64: false,
17
+ HTMLAttributes: {},
18
+ resize: false
19
+ };
20
+ },
21
+ inline() {
22
+ return this.options.inline;
23
+ },
24
+ group() {
25
+ return this.options.inline ? "inline" : "block";
26
+ },
27
+ draggable: true,
28
+ addAttributes() {
29
+ return {
30
+ src: { default: null },
31
+ alt: { default: null },
32
+ title: { default: null },
33
+ width: { default: null },
34
+ height: { default: null }
35
+ };
36
+ },
37
+ parseHTML() {
38
+ return [{ tag: this.options.allowBase64 ? "img[src]" : "img[src]:not([src^=\"data:\"])" }];
39
+ },
40
+ renderHTML({ HTMLAttributes }) {
41
+ return ["img", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)];
42
+ },
43
+ parseMarkdown: (token, helpers) => {
44
+ return helpers.createNode("image", {
45
+ src: token.href,
46
+ title: token.title,
47
+ alt: token.text
48
+ });
49
+ },
50
+ renderMarkdown: (node) => {
51
+ var _node$attrs$src, _node$attrs, _node$attrs$alt, _node$attrs2, _node$attrs$title, _node$attrs3;
52
+ const src = (_node$attrs$src = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.src) !== null && _node$attrs$src !== void 0 ? _node$attrs$src : "";
53
+ const alt = (_node$attrs$alt = (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.alt) !== null && _node$attrs$alt !== void 0 ? _node$attrs$alt : "";
54
+ const title = (_node$attrs$title = (_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.title) !== null && _node$attrs$title !== void 0 ? _node$attrs$title : "";
55
+ return title ? `![${alt}](${src} "${title}")` : `![${alt}](${src})`;
56
+ },
57
+ addNodeView() {
58
+ if (!this.options.resize || !this.options.resize.enabled || typeof document === "undefined") return null;
59
+ const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize;
60
+ const resizeManagedAttributes = /* @__PURE__ */ new Set([
61
+ "src",
62
+ "width",
63
+ "height"
64
+ ]);
65
+ return ({ node, getPos, HTMLAttributes, editor }) => {
66
+ const el = document.createElement("img");
67
+ el.draggable = false;
68
+ const mergedAttributes = mergeAttributes(this.options.HTMLAttributes, HTMLAttributes);
69
+ Object.entries(mergedAttributes).forEach(([key, value]) => {
70
+ if (value != null) switch (key) {
71
+ case "src":
72
+ case "width":
73
+ case "height": break;
74
+ default: el.setAttribute(key, value);
75
+ }
76
+ });
77
+ if (mergedAttributes.src !== null) el.src = mergedAttributes.src;
78
+ let previousHTMLAttributes = { ...HTMLAttributes };
79
+ const syncImageSource = (src) => {
80
+ if (typeof src === "string" && src !== "") {
81
+ if (el.getAttribute("src") !== src) el.src = src;
82
+ return;
83
+ }
84
+ if (el.hasAttribute("src")) el.removeAttribute("src");
85
+ if (el.src !== "") el.src = "";
86
+ };
87
+ syncImageSource(HTMLAttributes.src);
88
+ const onUpdate = (updatedNode) => {
89
+ if (updatedNode.type !== node.type) return false;
90
+ const extensionAttributes = editor.extensionManager.attributes.filter((attribute) => attribute.type === updatedNode.type.name);
91
+ const newHTMLAttributes = getRenderedAttributes(updatedNode, extensionAttributes);
92
+ Object.keys(previousHTMLAttributes).forEach((key) => {
93
+ if (!resizeManagedAttributes.has(key) && !(key in newHTMLAttributes)) el.removeAttribute(key);
94
+ });
95
+ Object.entries(newHTMLAttributes).forEach(([key, value]) => {
96
+ if (resizeManagedAttributes.has(key)) return;
97
+ if (value != null) el.setAttribute(key, value);
98
+ else el.removeAttribute(key);
99
+ });
100
+ syncImageSource(newHTMLAttributes.src);
101
+ previousHTMLAttributes = newHTMLAttributes;
102
+ return true;
103
+ };
104
+ const nodeView = new ResizableNodeView({
105
+ element: el,
106
+ editor,
107
+ node,
108
+ getPos,
109
+ onResize: (width, height) => {
110
+ el.style.width = `${width}px`;
111
+ el.style.height = `${height}px`;
112
+ },
113
+ onCommit: (width, height) => {
114
+ const pos = getPos();
115
+ if (pos === void 0) return;
116
+ this.editor.chain().setNodeSelection(pos).updateAttributes(this.name, {
117
+ width,
118
+ height
119
+ }).run();
120
+ },
121
+ onUpdate,
122
+ options: {
123
+ directions,
124
+ min: {
125
+ width: minWidth,
126
+ height: minHeight
127
+ },
128
+ preserveAspectRatio: alwaysPreserveAspectRatio === true
129
+ }
130
+ });
131
+ const dom = nodeView.dom;
132
+ const showNodeView = () => {
133
+ dom.style.visibility = "";
134
+ dom.style.pointerEvents = "";
135
+ };
136
+ dom.style.visibility = "hidden";
137
+ dom.style.pointerEvents = "none";
138
+ if (el.complete && el.naturalWidth > 0) showNodeView();
139
+ else {
140
+ el.onload = showNodeView;
141
+ el.onerror = showNodeView;
142
+ }
143
+ return nodeView;
144
+ };
145
+ },
146
+ addCommands() {
147
+ return { setImage: (options) => ({ commands }) => {
148
+ return commands.insertContent({
149
+ type: this.name,
150
+ attrs: options
151
+ });
152
+ } };
153
+ },
154
+ addInputRules() {
155
+ return [nodeInputRule({
156
+ find: inputRegex,
157
+ type: this.type,
158
+ getAttributes: (match) => {
159
+ const [, , alt, src, title] = match;
160
+ return {
161
+ src,
162
+ alt,
163
+ title
164
+ };
165
+ }
166
+ })];
167
+ }
206
168
  });
169
+ //#endregion
170
+ //#region src/index.ts
171
+ var src_default = Image;
172
+ //#endregion
173
+ export { Image, src_default as default, inputRegex };
207
174
 
208
- // src/index.ts
209
- var index_default = Image;
210
- export {
211
- Image,
212
- index_default as default,
213
- inputRegex
214
- };
215
175
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/image.ts","../src/index.ts"],"sourcesContent":["import type { ResizableNodeViewDirection, ResizableNodeViewOptions } from '@tiptap/core'\nimport {\n getRenderedAttributes,\n mergeAttributes,\n Node,\n nodeInputRule,\n ResizableNodeView,\n} from '@tiptap/core'\n\nexport interface ImageOptions {\n /**\n * Controls if the image node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean\n\n /**\n * Controls if base64 images are allowed. Enable this if you want to allow\n * base64 image urls in the `src` attribute.\n * @default false\n * @example true\n */\n allowBase64: boolean\n\n /**\n * HTML attributes to add to the image element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Controls if the image should be resizable and how the resize is configured.\n * @default false\n * @example { directions: { top: true, right: true, bottom: true, left: true, topLeft: true, topRight: true, bottomLeft: true, bottomRight: true }, minWidth: 100, minHeight: 100 }\n */\n resize:\n | {\n enabled: boolean\n directions?: ResizableNodeViewDirection[]\n minWidth?: number\n minHeight?: number\n alwaysPreserveAspectRatio?: boolean\n }\n | false\n}\n\nexport interface SetImageOptions {\n src: string\n alt?: string\n title?: string\n width?: number\n height?: number\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n image: {\n /**\n * Add an image\n * @param options The image attributes\n * @example\n * editor\n * .commands\n * .setImage({ src: 'https://tiptap.dev/logo.png', alt: 'tiptap', title: 'tiptap logo' })\n */\n setImage: (options: SetImageOptions) => ReturnType\n }\n }\n}\n\n/**\n * Matches an image to a ![image](src \"title\") on input.\n */\nexport const inputRegex = /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/\n\n/**\n * This extension allows you to insert images.\n * @see https://www.tiptap.dev/api/nodes/image\n */\nexport const Image = Node.create<ImageOptions>({\n name: 'image',\n\n addOptions() {\n return {\n inline: false,\n allowBase64: false,\n HTMLAttributes: {},\n resize: false,\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 alt: {\n default: null,\n },\n title: {\n default: null,\n },\n width: {\n default: null,\n },\n height: {\n default: null,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: this.options.allowBase64 ? 'img[src]' : 'img[src]:not([src^=\"data:\"])',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n parseMarkdown: (token, helpers) => {\n return helpers.createNode('image', {\n src: token.href,\n title: token.title,\n alt: token.text,\n })\n },\n\n renderMarkdown: node => {\n const src = node.attrs?.src ?? ''\n const alt = node.attrs?.alt ?? ''\n const title = node.attrs?.title ?? ''\n\n return title ? `![${alt}](${src} \"${title}\")` : `![${alt}](${src})`\n },\n\n addNodeView() {\n if (!this.options.resize || !this.options.resize.enabled || typeof document === 'undefined') {\n return null\n }\n\n const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize\n const resizeManagedAttributes = new Set(['src', 'width', 'height'])\n\n return ({ node, getPos, HTMLAttributes, editor }) => {\n const el = document.createElement('img')\n el.draggable = false\n\n const mergedAttributes = mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)\n\n Object.entries(mergedAttributes).forEach(([key, value]) => {\n if (value != null) {\n switch (key) {\n case 'src':\n case 'width':\n case 'height':\n break\n default:\n el.setAttribute(key, value)\n break\n }\n }\n })\n\n if (mergedAttributes.src !== null) {\n el.src = mergedAttributes.src\n }\n\n let previousHTMLAttributes = { ...HTMLAttributes }\n const syncImageSource = (src: unknown) => {\n if (typeof src === 'string' && src !== '') {\n if (el.getAttribute('src') !== src) {\n el.src = src\n }\n\n return\n }\n\n if (el.hasAttribute('src')) {\n el.removeAttribute('src')\n }\n\n if (el.src !== '') {\n el.src = ''\n }\n }\n\n syncImageSource(HTMLAttributes.src)\n\n const onUpdate: ResizableNodeViewOptions['onUpdate'] = (\n updatedNode: Parameters<typeof getRenderedAttributes>[0],\n ) => {\n if (updatedNode.type !== node.type) {\n return false\n }\n\n const extensionAttributes = editor.extensionManager.attributes.filter(\n attribute => attribute.type === updatedNode.type.name,\n )\n const newHTMLAttributes = getRenderedAttributes(updatedNode, extensionAttributes)\n\n // Remove attributes that were previously rendered but are no longer present\n Object.keys(previousHTMLAttributes).forEach(key => {\n if (!resizeManagedAttributes.has(key) && !(key in newHTMLAttributes)) {\n el.removeAttribute(key)\n }\n })\n\n Object.entries(newHTMLAttributes).forEach(([key, value]) => {\n if (resizeManagedAttributes.has(key)) {\n return\n }\n\n if (value != null) {\n el.setAttribute(key, value)\n } else {\n el.removeAttribute(key)\n }\n })\n\n syncImageSource(newHTMLAttributes.src)\n\n previousHTMLAttributes = newHTMLAttributes\n\n return true\n }\n\n const nodeView = new ResizableNodeView({\n element: el,\n editor,\n node,\n getPos,\n onResize: (width, height) => {\n el.style.width = `${width}px`\n el.style.height = `${height}px`\n },\n onCommit: (width, height) => {\n const pos = getPos()\n if (pos === undefined) {\n return\n }\n\n this.editor\n .chain()\n .setNodeSelection(pos)\n .updateAttributes(this.name, {\n width,\n height,\n })\n .run()\n },\n onUpdate,\n options: {\n directions,\n min: {\n width: minWidth,\n height: minHeight,\n },\n preserveAspectRatio: alwaysPreserveAspectRatio === true,\n },\n })\n\n const dom = nodeView.dom as HTMLElement\n\n // when image is loaded, show the node view to get the correct dimensions\n const showNodeView = () => {\n dom.style.visibility = ''\n dom.style.pointerEvents = ''\n }\n\n dom.style.visibility = 'hidden'\n dom.style.pointerEvents = 'none'\n\n if (el.complete && el.naturalWidth > 0) {\n // A cached image is already complete before this node view mounts, so\n // `load` never fires again and the image would stay hidden forever.\n showNodeView()\n } else {\n el.onload = showNodeView\n // Reveal on error too, so a broken src renders as an inspectable broken\n // image instead of an invisible node.\n el.onerror = showNodeView\n }\n\n return nodeView\n }\n },\n\n addCommands() {\n return {\n setImage:\n options =>\n ({ commands }) => {\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n addInputRules() {\n return [\n nodeInputRule({\n find: inputRegex,\n type: this.type,\n getAttributes: match => {\n const [, , alt, src, title] = match\n\n return { src, alt, title }\n },\n }),\n ]\n },\n})\n","import { Image } from './image.js'\n\nexport * from './image.js'\n\nexport default Image\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAoEA,IAAM,aAAa;AAMnB,IAAM,QAAQ,KAAK,OAAqB;AAAA,EAC7C,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,gBAAgB,CAAC;AAAA,MACjB,QAAQ;AAAA,IACV;AAAA,EACF;AAAA,EAEA,SAAS;AACP,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA,EAEA,QAAQ;AACN,WAAO,KAAK,QAAQ,SAAS,WAAW;AAAA,EAC1C;AAAA,EAEA,WAAW;AAAA,EAEX,gBAAgB;AACd,WAAO;AAAA,MACL,KAAK;AAAA,QACH,SAAS;AAAA,MACX;AAAA,MACA,KAAK;AAAA,QACH,SAAS;AAAA,MACX;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,MACX;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,MACX;AAAA,MACA,QAAQ;AAAA,QACN,SAAS;AAAA,MACX;AAAA,IACF;AAAA,E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,MACL,cAAc;AAAA,QACZ,MAAM;AAAA,QACN,MAAM,KAAK;AAAA,QACX,eAAe,WAAS;AACtB,gBAAM,CAAC,EAAE,EAAE,KAAK,KAAK,KAAK,IAAI;AAE9B,iBAAO,EAAE,KAAK,KAAK,MAAM;AAAA,QAC3B;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;ACrUD,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/image.ts","../src/index.ts"],"sourcesContent":["import type { ResizableNodeViewDirection, ResizableNodeViewOptions } from '@tiptap/core'\nimport {\n getRenderedAttributes,\n mergeAttributes,\n Node,\n nodeInputRule,\n ResizableNodeView,\n} from '@tiptap/core'\n\nexport interface ImageOptions {\n /**\n * Controls if the image node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean\n\n /**\n * Controls if base64 images are allowed. Enable this if you want to allow\n * base64 image urls in the `src` attribute.\n * @default false\n * @example true\n */\n allowBase64: boolean\n\n /**\n * HTML attributes to add to the image element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Controls if the image should be resizable and how the resize is configured.\n * @default false\n * @example { directions: { top: true, right: true, bottom: true, left: true, topLeft: true, topRight: true, bottomLeft: true, bottomRight: true }, minWidth: 100, minHeight: 100 }\n */\n resize:\n | {\n enabled: boolean\n directions?: ResizableNodeViewDirection[]\n minWidth?: number\n minHeight?: number\n alwaysPreserveAspectRatio?: boolean\n }\n | false\n}\n\nexport interface SetImageOptions {\n src: string\n alt?: string\n title?: string\n width?: number\n height?: number\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n image: {\n /**\n * Add an image\n * @param options The image attributes\n * @example\n * editor\n * .commands\n * .setImage({ src: 'https://tiptap.dev/logo.png', alt: 'tiptap', title: 'tiptap logo' })\n */\n setImage: (options: SetImageOptions) => ReturnType\n }\n }\n}\n\n/**\n * Matches an image to a ![image](src \"title\") on input.\n */\nexport const inputRegex = /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/\n\n/**\n * This extension allows you to insert images.\n * @see https://www.tiptap.dev/api/nodes/image\n */\nexport const Image = Node.create<ImageOptions>({\n name: 'image',\n\n addOptions() {\n return {\n inline: false,\n allowBase64: false,\n HTMLAttributes: {},\n resize: false,\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 alt: {\n default: null,\n },\n title: {\n default: null,\n },\n width: {\n default: null,\n },\n height: {\n default: null,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: this.options.allowBase64 ? 'img[src]' : 'img[src]:not([src^=\"data:\"])',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n parseMarkdown: (token, helpers) => {\n return helpers.createNode('image', {\n src: token.href,\n title: token.title,\n alt: token.text,\n })\n },\n\n renderMarkdown: node => {\n const src = node.attrs?.src ?? ''\n const alt = node.attrs?.alt ?? ''\n const title = node.attrs?.title ?? ''\n\n return title ? `![${alt}](${src} \"${title}\")` : `![${alt}](${src})`\n },\n\n addNodeView() {\n if (!this.options.resize || !this.options.resize.enabled || typeof document === 'undefined') {\n return null\n }\n\n const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize\n const resizeManagedAttributes = new Set(['src', 'width', 'height'])\n\n return ({ node, getPos, HTMLAttributes, editor }) => {\n const el = document.createElement('img')\n el.draggable = false\n\n const mergedAttributes = mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)\n\n Object.entries(mergedAttributes).forEach(([key, value]) => {\n if (value != null) {\n switch (key) {\n case 'src':\n case 'width':\n case 'height':\n break\n default:\n el.setAttribute(key, value)\n break\n }\n }\n })\n\n if (mergedAttributes.src !== null) {\n el.src = mergedAttributes.src\n }\n\n let previousHTMLAttributes = { ...HTMLAttributes }\n const syncImageSource = (src: unknown) => {\n if (typeof src === 'string' && src !== '') {\n if (el.getAttribute('src') !== src) {\n el.src = src\n }\n\n return\n }\n\n if (el.hasAttribute('src')) {\n el.removeAttribute('src')\n }\n\n if (el.src !== '') {\n el.src = ''\n }\n }\n\n syncImageSource(HTMLAttributes.src)\n\n const onUpdate: ResizableNodeViewOptions['onUpdate'] = (\n updatedNode: Parameters<typeof getRenderedAttributes>[0],\n ) => {\n if (updatedNode.type !== node.type) {\n return false\n }\n\n const extensionAttributes = editor.extensionManager.attributes.filter(\n attribute => attribute.type === updatedNode.type.name,\n )\n const newHTMLAttributes = getRenderedAttributes(updatedNode, extensionAttributes)\n\n // Remove attributes that were previously rendered but are no longer present\n Object.keys(previousHTMLAttributes).forEach(key => {\n if (!resizeManagedAttributes.has(key) && !(key in newHTMLAttributes)) {\n el.removeAttribute(key)\n }\n })\n\n Object.entries(newHTMLAttributes).forEach(([key, value]) => {\n if (resizeManagedAttributes.has(key)) {\n return\n }\n\n if (value != null) {\n el.setAttribute(key, value)\n } else {\n el.removeAttribute(key)\n }\n })\n\n syncImageSource(newHTMLAttributes.src)\n\n previousHTMLAttributes = newHTMLAttributes\n\n return true\n }\n\n const nodeView = new ResizableNodeView({\n element: el,\n editor,\n node,\n getPos,\n onResize: (width, height) => {\n el.style.width = `${width}px`\n el.style.height = `${height}px`\n },\n onCommit: (width, height) => {\n const pos = getPos()\n if (pos === undefined) {\n return\n }\n\n this.editor\n .chain()\n .setNodeSelection(pos)\n .updateAttributes(this.name, {\n width,\n height,\n })\n .run()\n },\n onUpdate,\n options: {\n directions,\n min: {\n width: minWidth,\n height: minHeight,\n },\n preserveAspectRatio: alwaysPreserveAspectRatio === true,\n },\n })\n\n const dom = nodeView.dom as HTMLElement\n\n // when image is loaded, show the node view to get the correct dimensions\n const showNodeView = () => {\n dom.style.visibility = ''\n dom.style.pointerEvents = ''\n }\n\n dom.style.visibility = 'hidden'\n dom.style.pointerEvents = 'none'\n\n if (el.complete && el.naturalWidth > 0) {\n // A cached image is already complete before this node view mounts, so\n // `load` never fires again and the image would stay hidden forever.\n showNodeView()\n } else {\n el.onload = showNodeView\n // Reveal on error too, so a broken src renders as an inspectable broken\n // image instead of an invisible node.\n el.onerror = showNodeView\n }\n\n return nodeView\n }\n },\n\n addCommands() {\n return {\n setImage:\n options =>\n ({ commands }) => {\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n addInputRules() {\n return [\n nodeInputRule({\n find: inputRegex,\n type: this.type,\n getAttributes: match => {\n const [, , alt, src, title] = match\n\n return { src, alt, title }\n },\n }),\n ]\n },\n})\n","import { Image } from './image.js'\n\nexport * from './image.js'\n\nexport default Image\n"],"mappings":";;;;;AA2EA,MAAa,aAAa;;;;;AAM1B,MAAa,QAAQ,KAAK,OAAqB;CAC7C,MAAM;CAEN,aAAa;EACX,OAAO;GACL,QAAQ;GACR,aAAa;GACb,gBAAgB,CAAC;GACjB,QAAQ;EACV;CACF;CAEA,SAAS;EACP,OAAO,KAAK,QAAQ;CACtB;CAEA,QAAQ;EACN,OAAO,KAAK,QAAQ,SAAS,WAAW;CAC1C;CAEA,WAAW;CAEX,gBAAgB;EACd,OAAO;GACL,KAAK,EACH,SAAS,KACX;GACA,KAAK,EACH,SAAS,KACX;GACA,OAAO,EACL,SAAS,KACX;GACA,OAAO,EACL,SAAS,KACX;GACA,QAAQ,EACN,SAAS,KACX;EACF;CACF;CAEA,YAAY;EACV,OAAO,CACL,EACE,KAAK,KAAK,QAAQ,cAAc,aAAa,iCAC/C,CACF;CACF;CAEA,WAAW,EAAE,kBAAkB;EAC7B,OAAO,CAAC,OAAO,gBAAgB,KAAK,QAAQ,gBAAgB,cAAc,CAAC;CAC7E;CAEA,gBAAgB,OAAO,YAAY;EACjC,OAAO,QAAQ,WAAW,SAAS;GACjC,KAAK,MAAM;GACX,OAAO,MAAM;GACb,KAAK,MAAM;EACb,CAAC;CACH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BAAqB,8BAA8B;IACrD;GACF,CAAC;GAED,MAAM,MAAM,SAAS;GAGrB,MAAM,qBAAqB;IACzB,IAAI,MAAM,aAAa;IACvB,IAAI,MAAM,gBAAgB;GAC5B;GAEA,IAAI,MAAM,aAAa;GACvB,IAAI,MAAM,gBAAgB;GAE1B,IAAI,GAAG,YAAY,GAAG,eAAe,GAGnC,aAAa;QACR;IACL,GAAG,SAAS;IAGZ,GAAG,UAAU;GACf;GAEA,OAAO;EACT;CACF;CAEA,cAAc;EACZ,OAAO,EACL,WACE,aACC,EAAE,eAAe;GAChB,OAAO,SAAS,cAAc;IAC5B,MAAM,KAAK;IACX,OAAO;GACT,CAAC;EACH,EACJ;CACF;CAEA,gBAAgB;EACd,OAAO,CACL,cAAc;GACZ,MAAM;GACN,MAAM,KAAK;GACX,gBAAe,UAAS;IACtB,MAAM,KAAK,KAAK,KAAK,SAAS;IAE9B,OAAO;KAAE;KAAK;KAAK;IAAM;GAC3B;EACF,CAAC,CACH;CACF;AACF,CAAC;;;ACrUD,IAAA,cAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiptap/extension-image",
3
- "version": "3.30.2",
3
+ "version": "3.30.4",
4
4
  "description": "image extension for tiptap",
5
5
  "keywords": [
6
6
  "tiptap",
@@ -39,12 +39,12 @@
39
39
  }
40
40
  },
41
41
  "devDependencies": {
42
- "@tiptap/core": "^3.30.2"
42
+ "@tiptap/core": "^3.30.4"
43
43
  },
44
44
  "peerDependencies": {
45
- "@tiptap/core": "3.30.2"
45
+ "@tiptap/core": "3.30.4"
46
46
  },
47
47
  "scripts": {
48
- "build": "tsup"
48
+ "build": "vp pack"
49
49
  }
50
50
  }