@tiptap/extension-image 2.0.0-beta.3 → 2.0.0-beta.30
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/LICENSE.md +1 -1
- package/README.md +2 -2
- package/dist/packages/extension-image/src/image.d.ts +6 -7
- package/dist/tiptap-extension-image.cjs.js +23 -16
- package/dist/tiptap-extension-image.cjs.js.map +1 -1
- package/dist/tiptap-extension-image.esm.js +23 -17
- package/dist/tiptap-extension-image.esm.js.map +1 -1
- package/dist/tiptap-extension-image.umd.js +26 -19
- package/dist/tiptap-extension-image.umd.js.map +1 -1
- package/package.json +7 -3
- package/src/image.ts +28 -25
- package/CHANGELOG.md +0 -131
- package/dist/tiptap-extension-image.bundle.umd.min.js +0 -2
- package/dist/tiptap-extension-image.bundle.umd.min.js.map +0 -1
package/LICENSE.md
CHANGED
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
|
-
##
|
|
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
|
|
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 {
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
2
|
export interface ImageOptions {
|
|
3
3
|
inline: boolean;
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
}) =>
|
|
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 =
|
|
7
|
+
const inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
|
|
8
8
|
const Image = core.Node.create({
|
|
9
9
|
name: 'image',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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:
|
|
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 => ({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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(
|
|
59
|
-
|
|
60
|
-
|
|
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
|
|
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
|
|
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,IAAA,SAAS,EAAE,IAAI;IAEf,aAAa,GAAA;QACX,OAAO;AACL,YAAA,GAAG,EAAE;AACH,gBAAA,OAAO,EAAE,IAAI;AACd,aAAA;AACD,YAAA,GAAG,EAAE;AACH,gBAAA,OAAO,EAAE,IAAI;AACd,aAAA;AACD,YAAA,KAAK,EAAE;AACL,gBAAA,OAAO,EAAE,IAAI;AACd,aAAA;SACF,CAAA;KACF;IAED,SAAS,GAAA;QACP,OAAO;AACL,YAAA;AACE,gBAAA,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW;AAC3B,sBAAE,UAAU;AACZ,sBAAE,8BAA8B;AACnC,aAAA;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE,EAAA;AAC3B,QAAA,OAAO,CAAC,KAAK,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAA;KAC7E;IAED,WAAW,GAAA;QACT,OAAO;YACL,QAAQ,EAAE,OAAO,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAI;gBACpC,OAAO,QAAQ,CAAC,aAAa,CAAC;oBAC5B,IAAI,EAAE,IAAI,CAAC,IAAI;AACf,oBAAA,KAAK,EAAE,OAAO;AACf,iBAAA,CAAC,CAAA;aACH;SACF,CAAA;KACF;IAED,aAAa,GAAA;QACX,OAAO;AACL,YAAAC,kBAAa,CAAC;AACZ,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,aAAa,EAAE,KAAK,IAAG;oBACrB,MAAM,KAAI,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,CAAA;AAElC,oBAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;iBAC3B;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;;;"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Node, mergeAttributes, nodeInputRule } from '@tiptap/core';
|
|
2
2
|
|
|
3
|
-
const inputRegex =
|
|
3
|
+
const inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
|
|
4
4
|
const Image = Node.create({
|
|
5
5
|
name: 'image',
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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:
|
|
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 => ({
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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(
|
|
55
|
-
|
|
56
|
-
|
|
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
|
|
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
|
|
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,U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IAAI,CAAC,IAAI;gBACf,aAAa,EAAE,KAAK,IAAG;oBACrB,MAAM,KAAI,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,CAAA;AAElC,oBAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;iBAC3B;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
(function (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[
|
|
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 =
|
|
7
|
+
const inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
|
|
8
8
|
const Image = core.Node.create({
|
|
9
9
|
name: 'image',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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:
|
|
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 => ({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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(
|
|
59
|
-
|
|
60
|
-
|
|
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
|
|
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
|
|
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 }),\n ]\n },\n})\n"],"names":["Node","mergeAttributes","nodeInputRule"],"mappings":";;;;;;AAuBO,QAAM,UAAU,GAAG,2DAA0D;AAEvE,QAAA,KAAK,GAAGA,SAAI,CAAC,MAAM,CAAe;EAC7C,IAAA,IAAI,EAAE,OAAO;MAEb,UAAU,GAAA;UACR,OAAO;EACL,YAAA,MAAM,EAAE,KAAK;EACb,YAAA,WAAW,EAAE,KAAK;EAClB,YAAA,cAAc,EAAE,EAAE;WACnB,CAAA;OACF;MAED,MAAM,GAAA;EACJ,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;OAC3B;MAED,KAAK,GAAA;EACH,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;OAChD;EAED,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
|
|
2
2
|
"name": "@tiptap/extension-image",
|
|
3
3
|
"description": "image extension for tiptap",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.30",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -15,7 +15,6 @@
|
|
|
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",
|
|
@@ -24,5 +23,10 @@
|
|
|
24
23
|
"peerDependencies": {
|
|
25
24
|
"@tiptap/core": "^2.0.0-beta.1"
|
|
26
25
|
},
|
|
27
|
-
"
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/ueberdosis/tiptap",
|
|
29
|
+
"directory": "packages/extension-image"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "591c0807a2ab5c34b4b7fe12c12511fe4f493ebd"
|
|
28
32
|
}
|
package/src/image.ts
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
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
|
-
|
|
11
|
-
|
|
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 }) =>
|
|
19
|
+
setImage: (options: { src: string, alt?: string, title?: string }) => ReturnType,
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
export const inputRegex =
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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:
|
|
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 => ({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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,131 +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.3](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-image@2.0.0-beta.2...@tiptap/extension-image@2.0.0-beta.3) (2021-04-16)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [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)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [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)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# [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)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# [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)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
# [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)
|
|
47
|
-
|
|
48
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
# [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)
|
|
55
|
-
|
|
56
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
# [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)
|
|
63
|
-
|
|
64
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
# [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)
|
|
71
|
-
|
|
72
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
# [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)
|
|
79
|
-
|
|
80
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
# [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)
|
|
87
|
-
|
|
88
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
# [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)
|
|
95
|
-
|
|
96
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
# [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)
|
|
103
|
-
|
|
104
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
# [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)
|
|
111
|
-
|
|
112
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
# [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)
|
|
119
|
-
|
|
120
|
-
**Note:** Version bump only for package @tiptap/extension-image
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
# 1.0.0-alpha.1 (2020-11-16)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
### Reverts
|
|
130
|
-
|
|
131
|
-
* Revert "use global namespace" ([0c9ce26](https://github.com/ueberdosis/tiptap-next/commit/0c9ce26c02c07d88a757c01b0a9d7f9e2b0b7502))
|
|
@@ -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"}
|