@tiptap/extension-image 2.0.0-beta.2 → 2.0.0-beta.200

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/README.md CHANGED
@@ -7,8 +7,8 @@
7
7
  ## Introduction
8
8
  tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
9
9
 
10
- ## Offical Documentation
10
+ ## Official Documentation
11
11
  Documentation can be found on the [tiptap website](https://tiptap.dev).
12
12
 
13
13
  ## License
14
- tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap-next/blob/main/LICENSE.md).
14
+ tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
@@ -1,12 +1,11 @@
1
- import { Command, Node } from '@tiptap/core';
1
+ import { Node } from '@tiptap/core';
2
2
  export interface ImageOptions {
3
3
  inline: boolean;
4
- HTMLAttributes: {
5
- [key: string]: any;
6
- };
4
+ allowBase64: boolean;
5
+ HTMLAttributes: Record<string, any>;
7
6
  }
8
7
  declare module '@tiptap/core' {
9
- interface Commands {
8
+ interface Commands<ReturnType> {
10
9
  image: {
11
10
  /**
12
11
  * Add an image
@@ -15,9 +14,9 @@ declare module '@tiptap/core' {
15
14
  src: string;
16
15
  alt?: string;
17
16
  title?: string;
18
- }) => Command;
17
+ }) => ReturnType;
19
18
  };
20
19
  }
21
20
  }
22
21
  export declare const inputRegex: RegExp;
23
- export declare const Image: Node<ImageOptions>;
22
+ export declare const Image: Node<ImageOptions, any>;
@@ -4,12 +4,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@tiptap/core');
6
6
 
7
- const inputRegex = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/;
7
+ const inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
8
8
  const Image = core.Node.create({
9
9
  name: 'image',
10
- defaultOptions: {
11
- inline: false,
12
- HTMLAttributes: {},
10
+ addOptions() {
11
+ return {
12
+ inline: false,
13
+ allowBase64: false,
14
+ HTMLAttributes: {},
15
+ };
13
16
  },
14
17
  inline() {
15
18
  return this.options.inline;
@@ -34,7 +37,9 @@ const Image = core.Node.create({
34
37
  parseHTML() {
35
38
  return [
36
39
  {
37
- tag: 'img[src]',
40
+ tag: this.options.allowBase64
41
+ ? 'img[src]'
42
+ : 'img[src]:not([src^="data:"])',
38
43
  },
39
44
  ];
40
45
  },
@@ -43,27 +48,29 @@ const Image = core.Node.create({
43
48
  },
44
49
  addCommands() {
45
50
  return {
46
- setImage: options => ({ tr, dispatch }) => {
47
- const { selection } = tr;
48
- const node = this.type.create(options);
49
- if (dispatch) {
50
- tr.replaceRangeWith(selection.from, selection.to, node);
51
- }
52
- return true;
51
+ setImage: options => ({ commands }) => {
52
+ return commands.insertContent({
53
+ type: this.name,
54
+ attrs: options,
55
+ });
53
56
  },
54
57
  };
55
58
  },
56
59
  addInputRules() {
57
60
  return [
58
- core.nodeInputRule(inputRegex, this.type, match => {
59
- const [, alt, src, title] = match;
60
- return { src, alt, title };
61
+ core.nodeInputRule({
62
+ find: inputRegex,
63
+ type: this.type,
64
+ getAttributes: match => {
65
+ const [, , alt, src, title] = match;
66
+ return { src, alt, title };
67
+ },
61
68
  }),
62
69
  ];
63
70
  },
64
71
  });
65
72
 
66
73
  exports.Image = Image;
67
- exports.default = Image;
74
+ exports["default"] = Image;
68
75
  exports.inputRegex = inputRegex;
69
76
  //# sourceMappingURL=tiptap-extension-image.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-image.cjs.js","sources":["../src/image.ts"],"sourcesContent":["import {\n Command,\n Node,\n nodeInputRule,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface ImageOptions {\n inline: boolean,\n HTMLAttributes: {\n [key: string]: any\n },\n}\n\ndeclare module '@tiptap/core' {\n interface Commands {\n image: {\n /**\n * Add an image\n */\n setImage: (options: { src: string, alt?: string, title?: string }) => Command,\n }\n }\n}\n\nexport const inputRegex = /!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\)/\n\nexport const Image = Node.create<ImageOptions>({\n name: 'image',\n\n defaultOptions: {\n inline: false,\n HTMLAttributes: {},\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 }\n },\n\n parseHTML() {\n return [\n {\n tag: 'img[src]',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n addCommands() {\n return {\n setImage: options => ({ tr, dispatch }) => {\n const { selection } = tr\n const node = this.type.create(options)\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node)\n }\n\n return true\n },\n }\n },\n\n addInputRules() {\n return [\n nodeInputRule(inputRegex, this.type, match => {\n const [, alt, src, title] = match\n\n return { src, alt, title }\n }),\n ]\n },\n})\n"],"names":["Node","mergeAttributes","nodeInputRule"],"mappings":";;;;;;MAyBa,UAAU,GAAG,gDAA+C;MAE5D,KAAK,GAAGA,SAAI,CAAC,MAAM,CAAe;IAC7C,IAAI,EAAE,OAAO;IAEb,cAAc,EAAE;QACd,MAAM,EAAE,KAAK;QACb,cAAc,EAAE,EAAE;KACnB;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;KAC3B;IAED,KAAK;QACH,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;KAChD;IAED,SAAS,EAAE,IAAI;IAEf,aAAa;QACX,OAAO;YACL,GAAG,EAAE;gBACH,OAAO,EAAE,IAAI;aACd;YACD,GAAG,EAAE;gBACH,OAAO,EAAE,IAAI;aACd;YACD,KAAK,EAAE;gBACL,OAAO,EAAE,IAAI;aACd;SACF,CAAA;KACF;IAED,SAAS;QACP,OAAO;YACL;gBACE,GAAG,EAAE,UAAU;aAChB;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE;QAC3B,OAAO,CAAC,KAAK,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAA;KAC7E;IAED,WAAW;QACT,OAAO;YACL,QAAQ,EAAE,OAAO,IAAI,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE;gBACpC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,CAAA;gBACxB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;gBAEtC,IAAI,QAAQ,EAAE;oBACZ,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;iBACxD;gBAED,OAAO,IAAI,CAAA;aACZ;SACF,CAAA;KACF;IAED,aAAa;QACX,OAAO;YACLC,kBAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK;gBACxC,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,CAAA;gBAEjC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;aAC3B,CAAC;SACH,CAAA;KACF;CACF;;;;;;"}
1
+ {"version":3,"file":"tiptap-extension-image.cjs.js","sources":["../src/image.ts"],"sourcesContent":["import {\n mergeAttributes,\n Node,\n nodeInputRule,\n} from '@tiptap/core'\n\nexport interface ImageOptions {\n inline: boolean,\n allowBase64: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n image: {\n /**\n * Add an image\n */\n setImage: (options: { src: string, alt?: string, title?: string }) => ReturnType,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/\n\nexport const Image = Node.create<ImageOptions>({\n name: 'image',\n\n addOptions() {\n return {\n inline: false,\n allowBase64: false,\n HTMLAttributes: {},\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 }\n },\n\n parseHTML() {\n return [\n {\n tag: this.options.allowBase64\n ? 'img[src]'\n : 'img[src]:not([src^=\"data:\"])',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n addCommands() {\n return {\n setImage: options => ({ 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"],"names":["Node","mergeAttributes","nodeInputRule"],"mappings":";;;;;;AAuBO,MAAM,UAAU,GAAG,2DAA0D;AAEvE,MAAA,KAAK,GAAGA,SAAI,CAAC,MAAM,CAAe;AAC7C,IAAA,IAAI,EAAE,OAAO;IAEb,UAAU,GAAA;QACR,OAAO;AACL,YAAA,MAAM,EAAE,KAAK;AACb,YAAA,WAAW,EAAE,KAAK;AAClB,YAAA,cAAc,EAAE,EAAE;SACnB,CAAA;KACF;IAED,MAAM,GAAA;AACJ,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;KAC3B;IAED,KAAK,GAAA;AACH,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;KAChD;AAED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core';
2
2
 
3
- const inputRegex = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/;
3
+ const inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
4
4
  const Image = Node.create({
5
5
  name: 'image',
6
- defaultOptions: {
7
- inline: false,
8
- HTMLAttributes: {},
6
+ addOptions() {
7
+ return {
8
+ inline: false,
9
+ allowBase64: false,
10
+ HTMLAttributes: {},
11
+ };
9
12
  },
10
13
  inline() {
11
14
  return this.options.inline;
@@ -30,7 +33,9 @@ const Image = Node.create({
30
33
  parseHTML() {
31
34
  return [
32
35
  {
33
- tag: 'img[src]',
36
+ tag: this.options.allowBase64
37
+ ? 'img[src]'
38
+ : 'img[src]:not([src^="data:"])',
34
39
  },
35
40
  ];
36
41
  },
@@ -39,26 +44,27 @@ const Image = Node.create({
39
44
  },
40
45
  addCommands() {
41
46
  return {
42
- setImage: options => ({ tr, dispatch }) => {
43
- const { selection } = tr;
44
- const node = this.type.create(options);
45
- if (dispatch) {
46
- tr.replaceRangeWith(selection.from, selection.to, node);
47
- }
48
- return true;
47
+ setImage: options => ({ commands }) => {
48
+ return commands.insertContent({
49
+ type: this.name,
50
+ attrs: options,
51
+ });
49
52
  },
50
53
  };
51
54
  },
52
55
  addInputRules() {
53
56
  return [
54
- nodeInputRule(inputRegex, this.type, match => {
55
- const [, alt, src, title] = match;
56
- return { src, alt, title };
57
+ nodeInputRule({
58
+ find: inputRegex,
59
+ type: this.type,
60
+ getAttributes: match => {
61
+ const [, , alt, src, title] = match;
62
+ return { src, alt, title };
63
+ },
57
64
  }),
58
65
  ];
59
66
  },
60
67
  });
61
68
 
62
- export default Image;
63
- export { Image, inputRegex };
69
+ export { Image, Image as default, inputRegex };
64
70
  //# sourceMappingURL=tiptap-extension-image.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-image.esm.js","sources":["../src/image.ts"],"sourcesContent":["import {\n Command,\n Node,\n nodeInputRule,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface ImageOptions {\n inline: boolean,\n HTMLAttributes: {\n [key: string]: any\n },\n}\n\ndeclare module '@tiptap/core' {\n interface Commands {\n image: {\n /**\n * Add an image\n */\n setImage: (options: { src: string, alt?: string, title?: string }) => Command,\n }\n }\n}\n\nexport const inputRegex = /!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\)/\n\nexport const Image = Node.create<ImageOptions>({\n name: 'image',\n\n defaultOptions: {\n inline: false,\n HTMLAttributes: {},\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 }\n },\n\n parseHTML() {\n return [\n {\n tag: 'img[src]',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n addCommands() {\n return {\n setImage: options => ({ tr, dispatch }) => {\n const { selection } = tr\n const node = this.type.create(options)\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node)\n }\n\n return true\n },\n }\n },\n\n addInputRules() {\n return [\n nodeInputRule(inputRegex, this.type, match => {\n const [, alt, src, title] = match\n\n return { src, alt, title }\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;MAyBa,UAAU,GAAG,gDAA+C;MAE5D,KAAK,GAAG,IAAI,CAAC,MAAM,CAAe;IAC7C,IAAI,EAAE,OAAO;IAEb,cAAc,EAAE;QACd,MAAM,EAAE,KAAK;QACb,cAAc,EAAE,EAAE;KACnB;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;KAC3B;IAED,KAAK;QACH,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;KAChD;IAED,SAAS,EAAE,IAAI;IAEf,aAAa;QACX,OAAO;YACL,GAAG,EAAE;gBACH,OAAO,EAAE,IAAI;aACd;YACD,GAAG,EAAE;gBACH,OAAO,EAAE,IAAI;aACd;YACD,KAAK,EAAE;gBACL,OAAO,EAAE,IAAI;aACd;SACF,CAAA;KACF;IAED,SAAS;QACP,OAAO;YACL;gBACE,GAAG,EAAE,UAAU;aAChB;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE;QAC3B,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAA;KAC7E;IAED,WAAW;QACT,OAAO;YACL,QAAQ,EAAE,OAAO,IAAI,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE;gBACpC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,CAAA;gBACxB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;gBAEtC,IAAI,QAAQ,EAAE;oBACZ,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;iBACxD;gBAED,OAAO,IAAI,CAAA;aACZ;SACF,CAAA;KACF;IAED,aAAa;QACX,OAAO;YACL,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK;gBACxC,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,CAAA;gBAEjC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;aAC3B,CAAC;SACH,CAAA;KACF;CACF;;;;;"}
1
+ {"version":3,"file":"tiptap-extension-image.esm.js","sources":["../src/image.ts"],"sourcesContent":["import {\n mergeAttributes,\n Node,\n nodeInputRule,\n} from '@tiptap/core'\n\nexport interface ImageOptions {\n inline: boolean,\n allowBase64: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n image: {\n /**\n * Add an image\n */\n setImage: (options: { src: string, alt?: string, title?: string }) => ReturnType,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/\n\nexport const Image = Node.create<ImageOptions>({\n name: 'image',\n\n addOptions() {\n return {\n inline: false,\n allowBase64: false,\n HTMLAttributes: {},\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 }\n },\n\n parseHTML() {\n return [\n {\n tag: this.options.allowBase64\n ? 'img[src]'\n : 'img[src]:not([src^=\"data:\"])',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n addCommands() {\n return {\n setImage: options => ({ 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"],"names":[],"mappings":";;AAuBO,MAAM,UAAU,GAAG,2DAA0D;AAEvE,MAAA,KAAK,GAAG,IAAI,CAAC,MAAM,CAAe;AAC7C,IAAA,IAAI,EAAE,OAAO;IAEb,UAAU,GAAA;QACR,OAAO;AACL,YAAA,MAAM,EAAE,KAAK;AACb,YAAA,WAAW,EAAE,KAAK;AAClB,YAAA,cAAc,EAAE,EAAE;SACnB,CAAA;KACF;IAED,MAAM,GAAA;AACJ,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;KAC3B;IAED,KAAK,GAAA;AACH,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GA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global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['@tiptap/extension-image'] = {}, global.core));
5
- }(this, (function (exports, core) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-image"] = {}, global.core));
5
+ })(this, (function (exports, core) { 'use strict';
6
6
 
7
- const inputRegex = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/;
7
+ const inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
8
8
  const Image = core.Node.create({
9
9
  name: 'image',
10
- defaultOptions: {
11
- inline: false,
12
- HTMLAttributes: {},
10
+ addOptions() {
11
+ return {
12
+ inline: false,
13
+ allowBase64: false,
14
+ HTMLAttributes: {},
15
+ };
13
16
  },
14
17
  inline() {
15
18
  return this.options.inline;
@@ -34,7 +37,9 @@
34
37
  parseHTML() {
35
38
  return [
36
39
  {
37
- tag: 'img[src]',
40
+ tag: this.options.allowBase64
41
+ ? 'img[src]'
42
+ : 'img[src]:not([src^="data:"])',
38
43
  },
39
44
  ];
40
45
  },
@@ -43,31 +48,33 @@
43
48
  },
44
49
  addCommands() {
45
50
  return {
46
- setImage: options => ({ tr, dispatch }) => {
47
- const { selection } = tr;
48
- const node = this.type.create(options);
49
- if (dispatch) {
50
- tr.replaceRangeWith(selection.from, selection.to, node);
51
- }
52
- return true;
51
+ setImage: options => ({ commands }) => {
52
+ return commands.insertContent({
53
+ type: this.name,
54
+ attrs: options,
55
+ });
53
56
  },
54
57
  };
55
58
  },
56
59
  addInputRules() {
57
60
  return [
58
- core.nodeInputRule(inputRegex, this.type, match => {
59
- const [, alt, src, title] = match;
60
- return { src, alt, title };
61
+ core.nodeInputRule({
62
+ find: inputRegex,
63
+ type: this.type,
64
+ getAttributes: match => {
65
+ const [, , alt, src, title] = match;
66
+ return { src, alt, title };
67
+ },
61
68
  }),
62
69
  ];
63
70
  },
64
71
  });
65
72
 
66
73
  exports.Image = Image;
67
- exports.default = Image;
74
+ exports["default"] = Image;
68
75
  exports.inputRegex = inputRegex;
69
76
 
70
77
  Object.defineProperty(exports, '__esModule', { value: true });
71
78
 
72
- })));
79
+ }));
73
80
  //# sourceMappingURL=tiptap-extension-image.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tiptap-extension-image.umd.js","sources":["../src/image.ts"],"sourcesContent":["import {\n Command,\n Node,\n nodeInputRule,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface ImageOptions {\n inline: boolean,\n HTMLAttributes: {\n [key: string]: any\n },\n}\n\ndeclare module '@tiptap/core' {\n interface Commands {\n image: {\n /**\n * Add an image\n */\n setImage: (options: { src: string, alt?: string, title?: string }) => Command,\n }\n }\n}\n\nexport const inputRegex = /!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\)/\n\nexport const Image = Node.create<ImageOptions>({\n name: 'image',\n\n defaultOptions: {\n inline: false,\n HTMLAttributes: {},\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 }\n },\n\n parseHTML() {\n return [\n {\n tag: 'img[src]',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n addCommands() {\n return {\n setImage: options => ({ tr, dispatch }) => {\n const { selection } = tr\n const node = this.type.create(options)\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node)\n }\n\n return true\n },\n }\n },\n\n addInputRules() {\n return [\n nodeInputRule(inputRegex, this.type, match => {\n const [, alt, src, title] = match\n\n return { src, alt, title }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BAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK;kBACxC,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,CAAA;kBAEjC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;eAC3B,CAAC;WACH,CAAA;OACF;GACF;;;;;;;;;;;;"}
1
+ {"version":3,"file":"tiptap-extension-image.umd.js","sources":["../src/image.ts"],"sourcesContent":["import {\n mergeAttributes,\n Node,\n nodeInputRule,\n} from '@tiptap/core'\n\nexport interface ImageOptions {\n inline: boolean,\n allowBase64: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n image: {\n /**\n * Add an image\n */\n setImage: (options: { src: string, alt?: string, title?: string }) => ReturnType,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/\n\nexport const Image = Node.create<ImageOptions>({\n name: 'image',\n\n addOptions() {\n return {\n inline: false,\n allowBase64: false,\n HTMLAttributes: {},\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 }\n },\n\n parseHTML() {\n return [\n {\n tag: this.options.allowBase64\n ? 'img[src]'\n : 'img[src]:not([src^=\"data:\"])',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n addCommands() {\n return {\n setImage: options => ({ 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 }),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C,IAAI;EACf,oBAAA,KAAK,EAAE,OAAO;EACf,iBAAA,CAAC,CAAA;eACH;WACF,CAAA;OACF;MAED,aAAa,GAAA;UACX,OAAO;EACL,YAAAC,kBAAa,CAAC;EACZ,gBAAA,IAAI,EAAE,UAAU;kBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;kBACf,aAAa,EAAE,KAAK,IAAG;sBACrB,MAAM,KAAI,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,CAAA;EAElC,oBAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;mBAC3B;eACF,CAAC;WACH,CAAA;OACF;EACF,CAAA;;;;;;;;;;;;"}
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": "2.0.0-beta.2",
4
+ "version": "2.0.0-beta.200",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -15,14 +15,17 @@
15
15
  "main": "dist/tiptap-extension-image.cjs.js",
16
16
  "umd": "dist/tiptap-extension-image.umd.js",
17
17
  "module": "dist/tiptap-extension-image.esm.js",
18
- "unpkg": "dist/tiptap-extension-image.bundle.umd.min.js",
19
18
  "types": "dist/packages/extension-image/src/index.d.ts",
20
19
  "files": [
21
20
  "src",
22
21
  "dist"
23
22
  ],
24
23
  "peerDependencies": {
25
- "@tiptap/core": "^2.0.0-beta.1"
24
+ "@tiptap/core": "^2.0.0-beta.193"
26
25
  },
27
- "gitHead": "634c1ae4931a8a268c7251f702b2a7d5121f02d2"
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/ueberdosis/tiptap",
29
+ "directory": "packages/extension-image"
30
+ }
28
31
  }
package/src/image.ts CHANGED
@@ -1,36 +1,37 @@
1
1
  import {
2
- Command,
2
+ mergeAttributes,
3
3
  Node,
4
4
  nodeInputRule,
5
- mergeAttributes,
6
5
  } from '@tiptap/core'
7
6
 
8
7
  export interface ImageOptions {
9
8
  inline: boolean,
10
- HTMLAttributes: {
11
- [key: string]: any
12
- },
9
+ allowBase64: boolean,
10
+ HTMLAttributes: Record<string, any>,
13
11
  }
14
12
 
15
13
  declare module '@tiptap/core' {
16
- interface Commands {
14
+ interface Commands<ReturnType> {
17
15
  image: {
18
16
  /**
19
17
  * Add an image
20
18
  */
21
- setImage: (options: { src: string, alt?: string, title?: string }) => Command,
19
+ setImage: (options: { src: string, alt?: string, title?: string }) => ReturnType,
22
20
  }
23
21
  }
24
22
  }
25
23
 
26
- export const inputRegex = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/
24
+ export const inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/
27
25
 
28
26
  export const Image = Node.create<ImageOptions>({
29
27
  name: 'image',
30
28
 
31
- defaultOptions: {
32
- inline: false,
33
- HTMLAttributes: {},
29
+ addOptions() {
30
+ return {
31
+ inline: false,
32
+ allowBase64: false,
33
+ HTMLAttributes: {},
34
+ }
34
35
  },
35
36
 
36
37
  inline() {
@@ -60,7 +61,9 @@ export const Image = Node.create<ImageOptions>({
60
61
  parseHTML() {
61
62
  return [
62
63
  {
63
- tag: 'img[src]',
64
+ tag: this.options.allowBase64
65
+ ? 'img[src]'
66
+ : 'img[src]:not([src^="data:"])',
64
67
  },
65
68
  ]
66
69
  },
@@ -71,25 +74,25 @@ export const Image = Node.create<ImageOptions>({
71
74
 
72
75
  addCommands() {
73
76
  return {
74
- setImage: options => ({ tr, dispatch }) => {
75
- const { selection } = tr
76
- const node = this.type.create(options)
77
-
78
- if (dispatch) {
79
- tr.replaceRangeWith(selection.from, selection.to, node)
80
- }
81
-
82
- return true
77
+ setImage: options => ({ commands }) => {
78
+ return commands.insertContent({
79
+ type: this.name,
80
+ attrs: options,
81
+ })
83
82
  },
84
83
  }
85
84
  },
86
85
 
87
86
  addInputRules() {
88
87
  return [
89
- nodeInputRule(inputRegex, this.type, match => {
90
- const [, alt, src, title] = match
91
-
92
- return { src, alt, title }
88
+ nodeInputRule({
89
+ find: inputRegex,
90
+ type: this.type,
91
+ getAttributes: match => {
92
+ const [,, alt, src, title] = match
93
+
94
+ return { src, alt, title }
95
+ },
93
96
  }),
94
97
  ]
95
98
  },
package/CHANGELOG.md DELETED
@@ -1,123 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [2.0.0-beta.2](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-beta.1...@tiptap/extension-image@2.0.0-beta.2) (2021-04-15)
7
-
8
- **Note:** Version bump only for package @tiptap/extension-image
9
-
10
-
11
-
12
-
13
-
14
- # [2.0.0-beta.1](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-alpha.11...@tiptap/extension-image@2.0.0-beta.1) (2021-03-05)
15
-
16
- **Note:** Version bump only for package @tiptap/extension-image
17
-
18
-
19
-
20
-
21
-
22
- # [2.0.0-alpha.11](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-alpha.10...@tiptap/extension-image@2.0.0-alpha.11) (2021-02-16)
23
-
24
- **Note:** Version bump only for package @tiptap/extension-image
25
-
26
-
27
-
28
-
29
-
30
- # [2.0.0-alpha.10](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-alpha.9...@tiptap/extension-image@2.0.0-alpha.10) (2021-02-07)
31
-
32
- **Note:** Version bump only for package @tiptap/extension-image
33
-
34
-
35
-
36
-
37
-
38
- # [2.0.0-alpha.9](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-alpha.8...@tiptap/extension-image@2.0.0-alpha.9) (2021-02-05)
39
-
40
- **Note:** Version bump only for package @tiptap/extension-image
41
-
42
-
43
-
44
-
45
-
46
- # [2.0.0-alpha.8](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-alpha.7...@tiptap/extension-image@2.0.0-alpha.8) (2021-01-29)
47
-
48
- **Note:** Version bump only for package @tiptap/extension-image
49
-
50
-
51
-
52
-
53
-
54
- # [2.0.0-alpha.7](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-alpha.6...@tiptap/extension-image@2.0.0-alpha.7) (2021-01-29)
55
-
56
- **Note:** Version bump only for package @tiptap/extension-image
57
-
58
-
59
-
60
-
61
-
62
- # [2.0.0-alpha.6](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-alpha.5...@tiptap/extension-image@2.0.0-alpha.6) (2021-01-28)
63
-
64
- **Note:** Version bump only for package @tiptap/extension-image
65
-
66
-
67
-
68
-
69
-
70
- # [2.0.0-alpha.5](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-alpha.4...@tiptap/extension-image@2.0.0-alpha.5) (2020-12-18)
71
-
72
- **Note:** Version bump only for package @tiptap/extension-image
73
-
74
-
75
-
76
-
77
-
78
- # [2.0.0-alpha.4](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-alpha.3...@tiptap/extension-image@2.0.0-alpha.4) (2020-12-02)
79
-
80
- **Note:** Version bump only for package @tiptap/extension-image
81
-
82
-
83
-
84
-
85
-
86
- # [2.0.0-alpha.3](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-alpha.2...@tiptap/extension-image@2.0.0-alpha.3) (2020-11-19)
87
-
88
- **Note:** Version bump only for package @tiptap/extension-image
89
-
90
-
91
-
92
-
93
-
94
- # [2.0.0-alpha.2](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-alpha.1...@tiptap/extension-image@2.0.0-alpha.2) (2020-11-19)
95
-
96
- **Note:** Version bump only for package @tiptap/extension-image
97
-
98
-
99
-
100
-
101
-
102
- # [2.0.0-alpha.1](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@1.0.0-alpha.2...@tiptap/extension-image@2.0.0-alpha.1) (2020-11-18)
103
-
104
- **Note:** Version bump only for package @tiptap/extension-image
105
-
106
-
107
-
108
-
109
-
110
- # [1.0.0-alpha.2](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@1.0.0-alpha.1...@tiptap/extension-image@1.0.0-alpha.2) (2020-11-16)
111
-
112
- **Note:** Version bump only for package @tiptap/extension-image
113
-
114
-
115
-
116
-
117
-
118
- # 1.0.0-alpha.1 (2020-11-16)
119
-
120
-
121
- ### Reverts
122
-
123
- * Revert "use global namespace" ([0c9ce26](https://github.com/ueberdosis/tiptap-next/commit/0c9ce26c02c07d88a757c01b0a9d7f9e2b0b7502))
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020, überdosis GbR
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,2 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@tiptap/core")):"function"==typeof define&&define.amd?define(["exports","@tiptap/core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@tiptap/extension-image"]={},e["@tiptap/core"])}(this,(function(e,t){"use strict";const i=/!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/,n=t.Node.create({name:"image",defaultOptions:{inline:!1,HTMLAttributes:{}},inline(){return this.options.inline},group(){return this.options.inline?"inline":"block"},draggable:!0,addAttributes:()=>({src:{default:null},alt:{default:null},title:{default:null}}),parseHTML:()=>[{tag:"img[src]"}],renderHTML({HTMLAttributes:e}){return["img",t.mergeAttributes(this.options.HTMLAttributes,e)]},addCommands(){return{setImage:e=>({tr:t,dispatch:i})=>{const{selection:n}=t,r=this.type.create(e);return i&&t.replaceRangeWith(n.from,n.to,r),!0}}},addInputRules(){return[t.nodeInputRule(i,this.type,(e=>{const[,t,i,n]=e;return{src:i,alt:t,title:n}}))]}});e.Image=n,e.default=n,e.inputRegex=i,Object.defineProperty(e,"__esModule",{value:!0})}));
2
- //# sourceMappingURL=tiptap-extension-image.bundle.umd.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiptap-extension-image.bundle.umd.min.js","sources":["../src/image.ts"],"sourcesContent":["import {\n Command,\n Node,\n nodeInputRule,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface ImageOptions {\n inline: boolean,\n HTMLAttributes: {\n [key: string]: any\n },\n}\n\ndeclare module '@tiptap/core' {\n interface Commands {\n image: {\n /**\n * Add an image\n */\n setImage: (options: { src: string, alt?: string, title?: string }) => Command,\n }\n }\n}\n\nexport const inputRegex = /!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\)/\n\nexport const Image = Node.create<ImageOptions>({\n name: 'image',\n\n defaultOptions: {\n inline: false,\n HTMLAttributes: {},\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 }\n },\n\n parseHTML() {\n return [\n {\n tag: 'img[src]',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]\n },\n\n addCommands() {\n return {\n setImage: options => ({ tr, dispatch }) => {\n const { selection } = tr\n const node = this.type.create(options)\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node)\n }\n\n return true\n },\n }\n },\n\n addInputRules() {\n return [\n nodeInputRule(inputRegex, this.type, match => {\n const [, alt, src, title] = match\n\n return { src, alt, title }\n }),\n ]\n },\n})\n"],"names":["inputRegex","Image","Node","create","name","defaultOptions","inline","HTMLAttributes","[object Object]","this","options","draggable","addAttributes","src","default","alt","title","parseHTML","tag","mergeAttributes","setImage","tr","dispatch","selection","node","type","replaceRangeWith","from","to","nodeInputRule","match"],"mappings":"mUAyBaA,EAAa,gDAEbC,EAAQC,OAAKC,OAAqB,CAC7CC,KAAM,QAENC,eAAgB,CACdC,QAAQ,EACRC,eAAgB,IAGlBC,SACE,OAAOC,KAAKC,QAAQJ,QAGtBE,QACE,OAAOC,KAAKC,QAAQJ,OAAS,SAAW,SAG1CK,WAAW,EAEXC,cAAa,KACJ,CACLC,IAAK,CACHC,QAAS,MAEXC,IAAK,CACHD,QAAS,MAEXE,MAAO,CACLF,QAAS,QAKfG,UAAS,IACA,CACL,CACEC,IAAK,aAKXV,YAAWD,eAAEA,IACX,MAAO,CAAC,MAAOY,kBAAgBV,KAAKC,QAAQH,eAAgBA,KAG9DC,cACE,MAAO,CACLY,SAAUV,GAAW,EAAGW,GAAAA,EAAIC,SAAAA,MAC1B,MAAMC,UAAEA,GAAcF,EAChBG,EAAOf,KAAKgB,KAAKtB,OAAOO,GAM9B,OAJIY,GACFD,EAAGK,iBAAiBH,EAAUI,KAAMJ,EAAUK,GAAIJ,IAG7C,KAKbhB,gBACE,MAAO,CACLqB,gBAAc7B,EAAYS,KAAKgB,MAAMK,IACnC,OAASf,EAAKF,EAAKG,GAASc,EAE5B,MAAO,CAAEjB,IAAAA,EAAKE,IAAAA,EAAKC,MAAAA"}