@tiptap/extension-image 3.12.0 → 3.13.0

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
@@ -90,11 +90,11 @@ var Image = import_core.Node.create({
90
90
  return title ? `![${alt}](${src} "${title}")` : `![${alt}](${src})`;
91
91
  },
92
92
  addNodeView() {
93
- if (!this.options.resize || !this.options.resize.enabled || typeof document === "undefined" || !this.editor.isEditable) {
93
+ if (!this.options.resize || !this.options.resize.enabled || typeof document === "undefined") {
94
94
  return null;
95
95
  }
96
96
  const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize;
97
- return ({ node, getPos, HTMLAttributes }) => {
97
+ return ({ node, getPos, HTMLAttributes, editor }) => {
98
98
  const el = document.createElement("img");
99
99
  Object.entries(HTMLAttributes).forEach(([key, value]) => {
100
100
  if (value != null) {
@@ -111,6 +111,7 @@ var Image = import_core.Node.create({
111
111
  el.src = HTMLAttributes.src;
112
112
  const nodeView = new import_core.ResizableNodeView({
113
113
  element: el,
114
+ editor,
114
115
  node,
115
116
  getPos,
116
117
  onResize: (width, height) => {
@@ -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 } from '@tiptap/core'\nimport { mergeAttributes, Node, nodeInputRule, ResizableNodeView } 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 (\n !this.options.resize ||\n !this.options.resize.enabled ||\n typeof document === 'undefined' ||\n !this.editor.isEditable\n ) {\n return null\n }\n\n const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize\n\n return ({ node, getPos, HTMLAttributes }) => {\n const el = document.createElement('img')\n\n Object.entries(HTMLAttributes).forEach(([key, value]) => {\n if (value != null) {\n switch (key) {\n case 'width':\n case 'height':\n break\n default:\n el.setAttribute(key, value)\n break\n }\n }\n })\n\n el.src = HTMLAttributes.src\n\n const nodeView = new ResizableNodeView({\n element: el,\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: (updatedNode, _decorations, _innerDecorations) => {\n if (updatedNode.type !== node.type) {\n return false\n }\n\n return true\n },\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 dom.style.visibility = 'hidden'\n dom.style.pointerEvents = 'none'\n el.onload = () => {\n dom.style.visibility = ''\n dom.style.pointerEvents = ''\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,kBAAwE;AAoEjE,IAAM,aAAa;AAM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YACH,OAAO;AAAA,YACP,QAAQ;AAAA,UACV;AAAA,UACA,qBAAqB,8BAA8B;AAAA,QACrD;AAAA,MACF,CAAC;AAED,YAAM,MAAM,SAAS;AAGrB,UAAI,MAAM,aAAa;AACvB,UAAI,MAAM,gBAAgB;AAC1B,SAAG,SAAS,MAAM;AAChB,YAAI,MAAM,aAAa;AACvB,YAAI,MAAM,gBAAgB;AAAA,MAC5B;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,UACE,aACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,SAAS,cAAc;AAAA,UAC5B,MAAM,KAAK;AAAA,UACX,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,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;;;AD3PD,IAAO,gBAAQ;","names":[]}
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 } from '@tiptap/core'\nimport { mergeAttributes, Node, nodeInputRule, ResizableNodeView } 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\n return ({ node, getPos, HTMLAttributes, editor }) => {\n const el = document.createElement('img')\n\n Object.entries(HTMLAttributes).forEach(([key, value]) => {\n if (value != null) {\n switch (key) {\n case 'width':\n case 'height':\n break\n default:\n el.setAttribute(key, value)\n break\n }\n }\n })\n\n el.src = HTMLAttributes.src\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: (updatedNode, _decorations, _innerDecorations) => {\n if (updatedNode.type !== node.type) {\n return false\n }\n\n return true\n },\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 dom.style.visibility = 'hidden'\n dom.style.pointerEvents = 'none'\n el.onload = () => {\n dom.style.visibility = ''\n dom.style.pointerEvents = ''\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;;;AC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S;AAAA,UACP;AAAA,UACA,KAAK;AAAA,YACH,OAAO;AAAA,YACP,QAAQ;AAAA,UACV;AAAA,UACA,qBAAqB,8BAA8B;AAAA,QACrD;AAAA,MACF,CAAC;AAED,YAAM,MAAM,SAAS;AAGrB,UAAI,MAAM,aAAa;AACvB,UAAI,MAAM,gBAAgB;AAC1B,SAAG,SAAS,MAAM;AAChB,YAAI,MAAM,aAAa;AACvB,YAAI,MAAM,gBAAgB;AAAA,MAC5B;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,UACE,aACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,SAAS,cAAc;AAAA,UAC5B,MAAM,KAAK;AAAA,UACX,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,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;;;ADvPD,IAAO,gBAAQ;","names":[]}
package/dist/index.js CHANGED
@@ -62,11 +62,11 @@ var Image = Node.create({
62
62
  return title ? `![${alt}](${src} "${title}")` : `![${alt}](${src})`;
63
63
  },
64
64
  addNodeView() {
65
- if (!this.options.resize || !this.options.resize.enabled || typeof document === "undefined" || !this.editor.isEditable) {
65
+ if (!this.options.resize || !this.options.resize.enabled || typeof document === "undefined") {
66
66
  return null;
67
67
  }
68
68
  const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize;
69
- return ({ node, getPos, HTMLAttributes }) => {
69
+ return ({ node, getPos, HTMLAttributes, editor }) => {
70
70
  const el = document.createElement("img");
71
71
  Object.entries(HTMLAttributes).forEach(([key, value]) => {
72
72
  if (value != null) {
@@ -83,6 +83,7 @@ var Image = Node.create({
83
83
  el.src = HTMLAttributes.src;
84
84
  const nodeView = new ResizableNodeView({
85
85
  element: el,
86
+ editor,
86
87
  node,
87
88
  getPos,
88
89
  onResize: (width, height) => {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/image.ts","../src/index.ts"],"sourcesContent":["import type { ResizableNodeViewDirection } from '@tiptap/core'\nimport { mergeAttributes, Node, nodeInputRule, ResizableNodeView } 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 (\n !this.options.resize ||\n !this.options.resize.enabled ||\n typeof document === 'undefined' ||\n !this.editor.isEditable\n ) {\n return null\n }\n\n const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize\n\n return ({ node, getPos, HTMLAttributes }) => {\n const el = document.createElement('img')\n\n Object.entries(HTMLAttributes).forEach(([key, value]) => {\n if (value != null) {\n switch (key) {\n case 'width':\n case 'height':\n break\n default:\n el.setAttribute(key, value)\n break\n }\n }\n })\n\n el.src = HTMLAttributes.src\n\n const nodeView = new ResizableNodeView({\n element: el,\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: (updatedNode, _decorations, _innerDecorations) => {\n if (updatedNode.type !== node.type) {\n return false\n }\n\n return true\n },\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 dom.style.visibility = 'hidden'\n dom.style.pointerEvents = 'none'\n el.onload = () => {\n dom.style.visibility = ''\n dom.style.pointerEvents = ''\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,SAAS,iBAAiB,MAAM,eAAe,yBAAyB;AAoEjE,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,SAA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AAM,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;;;AC3PD,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/image.ts","../src/index.ts"],"sourcesContent":["import type { ResizableNodeViewDirection } from '@tiptap/core'\nimport { mergeAttributes, Node, nodeInputRule, ResizableNodeView } 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\n return ({ node, getPos, HTMLAttributes, editor }) => {\n const el = document.createElement('img')\n\n Object.entries(HTMLAttributes).forEach(([key, value]) => {\n if (value != null) {\n switch (key) {\n case 'width':\n case 'height':\n break\n default:\n el.setAttribute(key, value)\n break\n }\n }\n })\n\n el.src = HTMLAttributes.src\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: (updatedNode, _decorations, _innerDecorations) => {\n if (updatedNode.type !== node.type) {\n return false\n }\n\n return true\n },\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 dom.style.visibility = 'hidden'\n dom.style.pointerEvents = 'none'\n el.onload = () => {\n dom.style.visibility = ''\n dom.style.pointerEvents = ''\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,SAAS,iBAAiB,MAAM,eAAe,yBAAyB;AAoEjE,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,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K;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;;;ACvPD,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/extension-image",
3
3
  "description": "image extension for tiptap",
4
- "version": "3.12.0",
4
+ "version": "3.13.0",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -31,10 +31,10 @@
31
31
  "dist"
32
32
  ],
33
33
  "devDependencies": {
34
- "@tiptap/core": "^3.12.0"
34
+ "@tiptap/core": "^3.13.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "@tiptap/core": "^3.12.0"
37
+ "@tiptap/core": "^3.13.0"
38
38
  },
39
39
  "repository": {
40
40
  "type": "git",
package/src/image.ts CHANGED
@@ -144,18 +144,13 @@ export const Image = Node.create<ImageOptions>({
144
144
  },
145
145
 
146
146
  addNodeView() {
147
- if (
148
- !this.options.resize ||
149
- !this.options.resize.enabled ||
150
- typeof document === 'undefined' ||
151
- !this.editor.isEditable
152
- ) {
147
+ if (!this.options.resize || !this.options.resize.enabled || typeof document === 'undefined') {
153
148
  return null
154
149
  }
155
150
 
156
151
  const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize
157
152
 
158
- return ({ node, getPos, HTMLAttributes }) => {
153
+ return ({ node, getPos, HTMLAttributes, editor }) => {
159
154
  const el = document.createElement('img')
160
155
 
161
156
  Object.entries(HTMLAttributes).forEach(([key, value]) => {
@@ -175,6 +170,7 @@ export const Image = Node.create<ImageOptions>({
175
170
 
176
171
  const nodeView = new ResizableNodeView({
177
172
  element: el,
173
+ editor,
178
174
  node,
179
175
  getPos,
180
176
  onResize: (width, height) => {