@edifice.io/tiptap-extensions 2.0.0-develop-rc.0 → 2.0.0-develop-rc.7
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 +1 -1
- package/dist/abbr/abbr.cjs +1 -32
- package/dist/abbr/abbr.d.ts +12 -12
- package/dist/abbr/abbr.js +13 -17
- package/dist/alert/alert.cjs +1 -32
- package/dist/alert/alert.js +22 -20
- package/dist/attachment/attachment.cjs +1 -73
- package/dist/attachment/attachment.d.ts +6 -6
- package/dist/attachment/attachment.js +29 -40
- package/dist/audio/audio.cjs +2 -52
- package/dist/audio/audio.d.ts +13 -17
- package/dist/audio/audio.js +25 -28
- package/dist/font-size/font-size.cjs +1 -48
- package/dist/font-size/font-size.d.ts +13 -13
- package/dist/font-size/font-size.js +17 -29
- package/dist/heading/heading.cjs +1 -61
- package/dist/heading/heading.d.ts +12 -10
- package/dist/heading/heading.js +25 -39
- package/dist/highlight/highlight.cjs +1 -25
- package/dist/highlight/highlight.d.ts +1 -4
- package/dist/highlight/highlight.js +13 -11
- package/dist/hyperlink/hyperlink.cjs +1 -47
- package/dist/hyperlink/hyperlink.d.ts +24 -27
- package/dist/hyperlink/hyperlink.js +19 -21
- package/dist/iframe/iframe.cjs +1 -69
- package/dist/iframe/iframe.d.ts +14 -12
- package/dist/iframe/iframe.js +32 -48
- package/dist/image/custom-image.cjs +1 -162
- package/dist/image/custom-image.d.ts +16 -19
- package/dist/image/custom-image.js +130 -179
- package/dist/index.cjs +1 -43
- package/dist/index.js +21 -21
- package/dist/line-height/line-height.cjs +1 -33
- package/dist/line-height/line-height.js +15 -18
- package/dist/linker/linker.cjs +1 -95
- package/dist/linker/linker.d.ts +17 -17
- package/dist/linker/linker.js +49 -57
- package/dist/mathjax/mathjax.cjs +1 -47
- package/dist/mathjax/mathjax.js +20 -30
- package/dist/paragraph/paragraph.cjs +1 -13
- package/dist/paragraph/paragraph.d.ts +1 -4
- package/dist/paragraph/paragraph.js +8 -6
- package/dist/speech-recognition/speech-recognition.cjs +1 -76
- package/dist/speech-recognition/speech-recognition.cjs.map +1 -1
- package/dist/speech-recognition/speech-recognition.d.ts +12 -12
- package/dist/speech-recognition/speech-recognition.js +41 -57
- package/dist/speech-recognition/speech-recognition.js.map +1 -1
- package/dist/speech-synthesis/speech-synthesis.cjs +1 -32
- package/dist/speech-synthesis/speech-synthesis.d.ts +9 -9
- package/dist/speech-synthesis/speech-synthesis.js +10 -19
- package/dist/table-cell/table-cell.cjs +1 -27
- package/dist/table-cell/table-cell.d.ts +1 -4
- package/dist/table-cell/table-cell.js +12 -17
- package/dist/transform/html-to-json/html-to-json.cjs +1 -4
- package/dist/transform/html-to-json/html-to-json.d.ts +1 -4
- package/dist/transform/html-to-json/html-to-json.js +4 -2
- package/dist/transform/json-to-html/json-to-html.cjs +1 -4
- package/dist/transform/json-to-html/json-to-html.js +4 -2
- package/dist/video/video.cjs +2 -111
- package/dist/video/video.d.ts +19 -28
- package/dist/video/video.js +90 -114
- package/package.json +47 -36
package/dist/iframe/iframe.js
CHANGED
|
@@ -1,85 +1,69 @@
|
|
|
1
|
-
import { Node } from
|
|
1
|
+
import { Node } from "@tiptap/core";
|
|
2
2
|
const Iframe = Node.create({
|
|
3
|
-
name:
|
|
4
|
-
group:
|
|
3
|
+
name: "iframe",
|
|
4
|
+
group: "block",
|
|
5
5
|
atom: !0,
|
|
6
6
|
draggable: !0,
|
|
7
7
|
addOptions() {
|
|
8
8
|
return {
|
|
9
9
|
allowFullscreen: !0,
|
|
10
10
|
HTMLAttributes: {
|
|
11
|
-
class:
|
|
12
|
-
}
|
|
11
|
+
class: "iframe-wrapper"
|
|
12
|
+
}
|
|
13
13
|
};
|
|
14
14
|
},
|
|
15
15
|
addAttributes() {
|
|
16
16
|
return {
|
|
17
17
|
src: {
|
|
18
|
-
default: null
|
|
18
|
+
default: null
|
|
19
19
|
},
|
|
20
20
|
frameborder: {
|
|
21
|
-
default: 0
|
|
21
|
+
default: 0
|
|
22
22
|
},
|
|
23
23
|
allowfullscreen: {
|
|
24
24
|
default: this.options.allowFullscreen,
|
|
25
|
-
parseHTML: () => this.options.allowFullscreen
|
|
25
|
+
parseHTML: () => this.options.allowFullscreen
|
|
26
26
|
},
|
|
27
27
|
width: {
|
|
28
|
-
renderHTML: (attributes) =>
|
|
29
|
-
attributes.width
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
attributes.width === '100%'
|
|
33
|
-
? '100%'
|
|
34
|
-
: parseInt(attributes.width),
|
|
35
|
-
}
|
|
36
|
-
: {},
|
|
37
|
-
parseHTML: (element) => element.getAttribute('width'),
|
|
28
|
+
renderHTML: (attributes) => attributes.width ? {
|
|
29
|
+
width: attributes.width === "100%" ? "100%" : parseInt(attributes.width)
|
|
30
|
+
} : {},
|
|
31
|
+
parseHTML: (element) => element.getAttribute("width")
|
|
38
32
|
},
|
|
39
33
|
height: {
|
|
40
|
-
renderHTML: (attributes) =>
|
|
41
|
-
attributes.height
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
: {},
|
|
46
|
-
parseHTML: (element) => element.getAttribute('height'),
|
|
34
|
+
renderHTML: (attributes) => attributes.height ? {
|
|
35
|
+
height: parseInt(attributes.height)
|
|
36
|
+
} : {},
|
|
37
|
+
parseHTML: (element) => element.getAttribute("height")
|
|
47
38
|
},
|
|
48
39
|
style: {
|
|
49
|
-
renderHTML: (attributes) =>
|
|
50
|
-
attributes.style
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
: {},
|
|
55
|
-
parseHTML: (element) => element.getAttribute('style'),
|
|
56
|
-
},
|
|
40
|
+
renderHTML: (attributes) => attributes.style ? {
|
|
41
|
+
style: attributes.style
|
|
42
|
+
} : {},
|
|
43
|
+
parseHTML: (element) => element.getAttribute("style")
|
|
44
|
+
}
|
|
57
45
|
};
|
|
58
46
|
},
|
|
59
47
|
parseHTML() {
|
|
60
48
|
return [
|
|
61
49
|
{
|
|
62
|
-
tag:
|
|
63
|
-
}
|
|
50
|
+
tag: "iframe"
|
|
51
|
+
}
|
|
64
52
|
];
|
|
65
53
|
},
|
|
66
54
|
renderHTML({ HTMLAttributes }) {
|
|
67
|
-
return [
|
|
55
|
+
return ["div", this.options.HTMLAttributes, ["iframe", HTMLAttributes]];
|
|
68
56
|
},
|
|
69
57
|
addCommands() {
|
|
70
58
|
return {
|
|
71
|
-
setIframe:
|
|
72
|
-
(options)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
node = this.type.create(options);
|
|
76
|
-
return (
|
|
77
|
-
dispatch && tr.replaceRangeWith(selection.from, selection.to, node),
|
|
78
|
-
!0
|
|
79
|
-
);
|
|
80
|
-
},
|
|
59
|
+
setIframe: (options) => ({ tr, dispatch }) => {
|
|
60
|
+
const { selection } = tr, node = this.type.create(options);
|
|
61
|
+
return dispatch && tr.replaceRangeWith(selection.from, selection.to, node), !0;
|
|
62
|
+
}
|
|
81
63
|
};
|
|
82
|
-
}
|
|
64
|
+
}
|
|
83
65
|
});
|
|
84
|
-
export {
|
|
66
|
+
export {
|
|
67
|
+
Iframe
|
|
68
|
+
};
|
|
85
69
|
//# sourceMappingURL=iframe.js.map
|
|
@@ -1,163 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
3
|
-
const core = require('@tiptap/core'),
|
|
4
|
-
Image = require('@tiptap/extension-image'),
|
|
5
|
-
IMAGE_INPUT_REGEX =
|
|
6
|
-
/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,
|
|
7
|
-
CustomImage = Image.extend({
|
|
8
|
-
name: 'custom-image',
|
|
9
|
-
draggable: !0,
|
|
10
|
-
selectable: !0,
|
|
11
|
-
addOptions() {
|
|
12
|
-
var _a;
|
|
13
|
-
return {
|
|
14
|
-
...((_a = this.parent) == null ? void 0 : _a.call(this)),
|
|
15
|
-
inline: !0,
|
|
16
|
-
content: 'inline*',
|
|
17
|
-
sizes: ['small', 'medium', 'large'],
|
|
18
|
-
HTMLAttributes: { class: 'custom-image' },
|
|
19
|
-
};
|
|
20
|
-
},
|
|
21
|
-
addAttributes() {
|
|
22
|
-
var _a;
|
|
23
|
-
return {
|
|
24
|
-
...((_a = this.parent) == null ? void 0 : _a.call(this)),
|
|
25
|
-
size: { default: 'medium', rendered: !1 },
|
|
26
|
-
alt: {
|
|
27
|
-
renderHTML: (attributes) => ({ alt: attributes.alt }),
|
|
28
|
-
parseHTML: (element) => element.getAttribute('alt'),
|
|
29
|
-
},
|
|
30
|
-
title: {
|
|
31
|
-
renderHTML: (attributes) => ({ title: attributes.title }),
|
|
32
|
-
parseHTML: (element) => element.getAttribute('title'),
|
|
33
|
-
},
|
|
34
|
-
width: {
|
|
35
|
-
default: '350',
|
|
36
|
-
renderHTML: (attributes) =>
|
|
37
|
-
attributes.width !== null &&
|
|
38
|
-
attributes.width !== void 0 &&
|
|
39
|
-
!Number.isNaN(attributes.width)
|
|
40
|
-
? { width: parseInt(attributes.width) }
|
|
41
|
-
: {},
|
|
42
|
-
parseHTML: (element) => element.getAttribute('width'),
|
|
43
|
-
},
|
|
44
|
-
height: {
|
|
45
|
-
renderHTML: (attributes) =>
|
|
46
|
-
attributes.height !== null &&
|
|
47
|
-
attributes.height !== void 0 &&
|
|
48
|
-
!Number.isNaN(attributes.height)
|
|
49
|
-
? { height: parseInt(attributes.height) }
|
|
50
|
-
: {},
|
|
51
|
-
parseHTML: (element) => element.getAttribute('height'),
|
|
52
|
-
},
|
|
53
|
-
style: {
|
|
54
|
-
renderHTML: (attributes) =>
|
|
55
|
-
attributes.style ? { style: attributes.style } : {},
|
|
56
|
-
parseHTML: (element) => {
|
|
57
|
-
const style = element.getAttribute('style');
|
|
58
|
-
return style && typeof style == 'string' && style.length > 0
|
|
59
|
-
? {}
|
|
60
|
-
: null;
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
parseHTML() {
|
|
66
|
-
return [
|
|
67
|
-
{
|
|
68
|
-
tag: 'img[src]:not([src^="data:"])',
|
|
69
|
-
getAttrs: (el) => {
|
|
70
|
-
var _a, _b, _c, _d, _e;
|
|
71
|
-
const attr = { src: el.getAttribute('src') };
|
|
72
|
-
return (
|
|
73
|
-
(_a = el.parentElement) != null &&
|
|
74
|
-
_a.className.includes('image-container') &&
|
|
75
|
-
(_b = el.parentElement.style) != null &&
|
|
76
|
-
_b.width &&
|
|
77
|
-
(attr.width = el.parentElement.style.width),
|
|
78
|
-
(_c = el.style) != null &&
|
|
79
|
-
_c.width &&
|
|
80
|
-
(attr.width = el.style.width),
|
|
81
|
-
[
|
|
82
|
-
'happy',
|
|
83
|
-
'proud',
|
|
84
|
-
'dreamy',
|
|
85
|
-
'love',
|
|
86
|
-
'tired',
|
|
87
|
-
'angry',
|
|
88
|
-
'worried',
|
|
89
|
-
'sick',
|
|
90
|
-
'joker',
|
|
91
|
-
'sad',
|
|
92
|
-
].filter((smiley) => attr.src.includes(smiley + '.png')).length >
|
|
93
|
-
0 &&
|
|
94
|
-
((attr.style = {
|
|
95
|
-
width: '1.5em',
|
|
96
|
-
height: '1.5em',
|
|
97
|
-
fontSize:
|
|
98
|
-
(_e =
|
|
99
|
-
(_d = el.parentElement) == null ? void 0 : _d.style) ==
|
|
100
|
-
null
|
|
101
|
-
? void 0
|
|
102
|
-
: _e.fontSize,
|
|
103
|
-
}),
|
|
104
|
-
(attr.width = 'null'),
|
|
105
|
-
(attr.height = 'null')),
|
|
106
|
-
attr
|
|
107
|
-
);
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
];
|
|
111
|
-
},
|
|
112
|
-
renderHTML({ HTMLAttributes }) {
|
|
113
|
-
return [
|
|
114
|
-
'img',
|
|
115
|
-
core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
116
|
-
];
|
|
117
|
-
},
|
|
118
|
-
addInputRules() {
|
|
119
|
-
return [
|
|
120
|
-
core.nodeInputRule({
|
|
121
|
-
find: IMAGE_INPUT_REGEX,
|
|
122
|
-
type: this.type,
|
|
123
|
-
getAttributes: (match) => {
|
|
124
|
-
const [, , alt, src, title] = match;
|
|
125
|
-
return { src, alt, title };
|
|
126
|
-
},
|
|
127
|
-
}),
|
|
128
|
-
];
|
|
129
|
-
},
|
|
130
|
-
addCommands() {
|
|
131
|
-
return {
|
|
132
|
-
setNewImage:
|
|
133
|
-
(attrs) =>
|
|
134
|
-
({ tr, dispatch }) => {
|
|
135
|
-
const { selection } = tr,
|
|
136
|
-
node = this.type.create(attrs);
|
|
137
|
-
return (
|
|
138
|
-
dispatch &&
|
|
139
|
-
tr.replaceRangeWith(selection.from, selection.to, node),
|
|
140
|
-
!0
|
|
141
|
-
);
|
|
142
|
-
},
|
|
143
|
-
setAttributes:
|
|
144
|
-
(attributes) =>
|
|
145
|
-
({ tr, dispatch }) => {
|
|
146
|
-
const { selection } = tr,
|
|
147
|
-
options = {
|
|
148
|
-
...tr.doc.nodeAt(tr.selection.from).attrs,
|
|
149
|
-
...attributes,
|
|
150
|
-
},
|
|
151
|
-
node = this.type.create(options);
|
|
152
|
-
return (
|
|
153
|
-
dispatch &&
|
|
154
|
-
tr.replaceRangeWith(selection.from, selection.to, node),
|
|
155
|
-
!0
|
|
156
|
-
);
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
exports.CustomImage = CustomImage;
|
|
162
|
-
exports.IMAGE_INPUT_REGEX = IMAGE_INPUT_REGEX;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@tiptap/core"),Image=require("@tiptap/extension-image"),IMAGE_INPUT_REGEX=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,CustomImage=Image.extend({name:"custom-image",draggable:!0,selectable:!0,addOptions(){var _a;return{...(_a=this.parent)==null?void 0:_a.call(this),inline:!0,content:"inline*",sizes:["small","medium","large"],HTMLAttributes:{class:"custom-image"}}},addAttributes(){var _a;return{...(_a=this.parent)==null?void 0:_a.call(this),size:{default:"medium",rendered:!1},alt:{renderHTML:attributes=>({alt:attributes.alt}),parseHTML:element=>element.getAttribute("alt")},title:{renderHTML:attributes=>({title:attributes.title}),parseHTML:element=>element.getAttribute("title")},width:{default:"350",renderHTML:attributes=>attributes.width!==null&&attributes.width!==void 0&&!Number.isNaN(attributes.width)?{width:parseInt(attributes.width)}:{},parseHTML:element=>element.getAttribute("width")},height:{renderHTML:attributes=>attributes.height!==null&&attributes.height!==void 0&&!Number.isNaN(attributes.height)?{height:parseInt(attributes.height)}:{},parseHTML:element=>element.getAttribute("height")},style:{renderHTML:attributes=>attributes.style?{style:attributes.style}:{},parseHTML:element=>{const style=element.getAttribute("style");return style&&typeof style=="string"&&style.length>0?{}:null}}}},parseHTML(){return[{tag:'img[src]:not([src^="data:"])',getAttrs:el=>{var _a,_b,_c,_d,_e;const attr={src:el.getAttribute("src")};return(_a=el.parentElement)!=null&&_a.className.includes("image-container")&&(_b=el.parentElement.style)!=null&&_b.width&&(attr.width=el.parentElement.style.width),(_c=el.style)!=null&&_c.width&&(attr.width=el.style.width),["happy","proud","dreamy","love","tired","angry","worried","sick","joker","sad"].filter(smiley=>attr.src.includes(smiley+".png")).length>0&&(attr.style={width:"1.5em",height:"1.5em",fontSize:(_e=(_d=el.parentElement)==null?void 0:_d.style)==null?void 0:_e.fontSize},attr.width="null",attr.height="null"),attr}}]},renderHTML({HTMLAttributes}){return["img",core.mergeAttributes(this.options.HTMLAttributes,HTMLAttributes)]},addInputRules(){return[core.nodeInputRule({find:IMAGE_INPUT_REGEX,type:this.type,getAttributes:match=>{const[,,alt,src,title]=match;return{src,alt,title}}})]},addCommands(){return{setNewImage:attrs=>({tr,dispatch})=>{const{selection}=tr,node=this.type.create(attrs);return dispatch&&tr.replaceRangeWith(selection.from,selection.to,node),!0},setAttributes:attributes=>({tr,dispatch})=>{const{selection}=tr,options={...tr.doc.nodeAt(tr.selection.from).attrs,...attributes},node=this.type.create(options);return dispatch&&tr.replaceRangeWith(selection.from,selection.to,node),!0}}}});exports.CustomImage=CustomImage;exports.IMAGE_INPUT_REGEX=IMAGE_INPUT_REGEX;
|
|
163
2
|
//# sourceMappingURL=custom-image.cjs.map
|
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
export declare const IMAGE_INPUT_REGEX: RegExp;
|
|
2
2
|
export interface CustomImageOptions {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
HTMLAttributes: Record<string, string>;
|
|
4
|
+
sizes: string[];
|
|
5
5
|
}
|
|
6
6
|
interface AttributesProps {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
width: number | string;
|
|
8
|
+
height: number | string;
|
|
9
|
+
size: string;
|
|
10
10
|
}
|
|
11
11
|
declare module '@tiptap/core' {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
interface Commands<ReturnType> {
|
|
13
|
+
customImage: {
|
|
14
|
+
setAttributes: (options: AttributesProps) => ReturnType;
|
|
15
|
+
setNewImage: (options: {
|
|
16
|
+
src: string;
|
|
17
|
+
alt?: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
}) => ReturnType;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
22
|
}
|
|
23
|
-
export declare const CustomImage: import('@tiptap/core').Node<
|
|
24
|
-
CustomImageOptions,
|
|
25
|
-
any
|
|
26
|
-
>;
|
|
23
|
+
export declare const CustomImage: import('@tiptap/core').Node<CustomImageOptions, any>;
|
|
27
24
|
export {};
|
|
@@ -1,181 +1,132 @@
|
|
|
1
|
-
import { mergeAttributes, nodeInputRule } from
|
|
2
|
-
import Image from
|
|
3
|
-
const IMAGE_INPUT_REGEX =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
renderHTML: (attributes) => ({
|
|
31
|
-
alt: attributes.alt,
|
|
32
|
-
}),
|
|
33
|
-
parseHTML: (element) => element.getAttribute('alt'),
|
|
34
|
-
},
|
|
35
|
-
title: {
|
|
36
|
-
renderHTML: (attributes) => ({
|
|
37
|
-
title: attributes.title,
|
|
38
|
-
}),
|
|
39
|
-
parseHTML: (element) => element.getAttribute('title'),
|
|
40
|
-
},
|
|
41
|
-
width: {
|
|
42
|
-
default: '350',
|
|
43
|
-
renderHTML: (attributes) =>
|
|
44
|
-
attributes.width !== null &&
|
|
45
|
-
attributes.width !== void 0 &&
|
|
46
|
-
!Number.isNaN(attributes.width)
|
|
47
|
-
? {
|
|
48
|
-
width: parseInt(attributes.width),
|
|
49
|
-
}
|
|
50
|
-
: {},
|
|
51
|
-
parseHTML: (element) => element.getAttribute('width'),
|
|
52
|
-
},
|
|
53
|
-
height: {
|
|
54
|
-
renderHTML: (attributes) =>
|
|
55
|
-
attributes.height !== null &&
|
|
56
|
-
attributes.height !== void 0 &&
|
|
57
|
-
!Number.isNaN(attributes.height)
|
|
58
|
-
? {
|
|
59
|
-
height: parseInt(attributes.height),
|
|
60
|
-
}
|
|
61
|
-
: {},
|
|
62
|
-
parseHTML: (element) => element.getAttribute('height'),
|
|
63
|
-
},
|
|
64
|
-
style: {
|
|
65
|
-
renderHTML: (attributes) =>
|
|
66
|
-
attributes.style
|
|
67
|
-
? {
|
|
68
|
-
style: attributes.style,
|
|
69
|
-
}
|
|
70
|
-
: {},
|
|
71
|
-
parseHTML: (element) => {
|
|
72
|
-
const style = element.getAttribute('style');
|
|
73
|
-
return style && typeof style == 'string' && style.length > 0
|
|
74
|
-
? {}
|
|
75
|
-
: null;
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
parseHTML() {
|
|
81
|
-
return [
|
|
82
|
-
{
|
|
83
|
-
tag: 'img[src]:not([src^="data:"])',
|
|
84
|
-
getAttrs: (el) => {
|
|
85
|
-
var _a, _b, _c, _d, _e;
|
|
86
|
-
const attr = { src: el.getAttribute('src') };
|
|
87
|
-
return (
|
|
88
|
-
(_a = el.parentElement) != null &&
|
|
89
|
-
_a.className.includes('image-container') &&
|
|
90
|
-
(_b = el.parentElement.style) != null &&
|
|
91
|
-
_b.width &&
|
|
92
|
-
(attr.width = el.parentElement.style.width),
|
|
93
|
-
(_c = el.style) != null &&
|
|
94
|
-
_c.width &&
|
|
95
|
-
(attr.width = el.style.width),
|
|
96
|
-
[
|
|
97
|
-
'happy',
|
|
98
|
-
'proud',
|
|
99
|
-
'dreamy',
|
|
100
|
-
'love',
|
|
101
|
-
'tired',
|
|
102
|
-
'angry',
|
|
103
|
-
'worried',
|
|
104
|
-
'sick',
|
|
105
|
-
'joker',
|
|
106
|
-
'sad',
|
|
107
|
-
].filter((smiley) => attr.src.includes(smiley + '.png')).length >
|
|
108
|
-
0 &&
|
|
109
|
-
((attr.style = {
|
|
110
|
-
width: '1.5em',
|
|
111
|
-
height: '1.5em',
|
|
112
|
-
fontSize:
|
|
113
|
-
(_e =
|
|
114
|
-
(_d = el.parentElement) == null ? void 0 : _d.style) ==
|
|
115
|
-
null
|
|
116
|
-
? void 0
|
|
117
|
-
: _e.fontSize,
|
|
118
|
-
}),
|
|
119
|
-
(attr.width = 'null'),
|
|
120
|
-
(attr.height = 'null')),
|
|
121
|
-
attr
|
|
122
|
-
);
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
];
|
|
126
|
-
},
|
|
127
|
-
renderHTML({ HTMLAttributes }) {
|
|
128
|
-
return [
|
|
129
|
-
'img',
|
|
130
|
-
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
131
|
-
];
|
|
132
|
-
},
|
|
133
|
-
addInputRules() {
|
|
134
|
-
return [
|
|
135
|
-
nodeInputRule({
|
|
136
|
-
find: IMAGE_INPUT_REGEX,
|
|
137
|
-
type: this.type,
|
|
138
|
-
getAttributes: (match) => {
|
|
139
|
-
const [, , alt, src, title] = match;
|
|
140
|
-
return {
|
|
141
|
-
src,
|
|
142
|
-
alt,
|
|
143
|
-
title,
|
|
144
|
-
};
|
|
145
|
-
},
|
|
1
|
+
import { mergeAttributes, nodeInputRule } from "@tiptap/core";
|
|
2
|
+
import Image from "@tiptap/extension-image";
|
|
3
|
+
const IMAGE_INPUT_REGEX = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/, CustomImage = Image.extend({
|
|
4
|
+
name: "custom-image",
|
|
5
|
+
draggable: !0,
|
|
6
|
+
selectable: !0,
|
|
7
|
+
addOptions() {
|
|
8
|
+
var _a;
|
|
9
|
+
return {
|
|
10
|
+
...(_a = this.parent) == null ? void 0 : _a.call(this),
|
|
11
|
+
inline: !0,
|
|
12
|
+
content: "inline*",
|
|
13
|
+
sizes: ["small", "medium", "large"],
|
|
14
|
+
HTMLAttributes: {
|
|
15
|
+
class: "custom-image"
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
addAttributes() {
|
|
20
|
+
var _a;
|
|
21
|
+
return {
|
|
22
|
+
...(_a = this.parent) == null ? void 0 : _a.call(this),
|
|
23
|
+
size: {
|
|
24
|
+
default: "medium",
|
|
25
|
+
rendered: !1
|
|
26
|
+
},
|
|
27
|
+
alt: {
|
|
28
|
+
renderHTML: (attributes) => ({
|
|
29
|
+
alt: attributes.alt
|
|
146
30
|
}),
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
31
|
+
parseHTML: (element) => element.getAttribute("alt")
|
|
32
|
+
},
|
|
33
|
+
title: {
|
|
34
|
+
renderHTML: (attributes) => ({
|
|
35
|
+
title: attributes.title
|
|
36
|
+
}),
|
|
37
|
+
parseHTML: (element) => element.getAttribute("title")
|
|
38
|
+
},
|
|
39
|
+
width: {
|
|
40
|
+
default: "350",
|
|
41
|
+
renderHTML: (attributes) => attributes.width !== null && attributes.width !== void 0 && !Number.isNaN(attributes.width) ? {
|
|
42
|
+
width: parseInt(attributes.width)
|
|
43
|
+
} : {},
|
|
44
|
+
parseHTML: (element) => element.getAttribute("width")
|
|
45
|
+
},
|
|
46
|
+
height: {
|
|
47
|
+
renderHTML: (attributes) => attributes.height !== null && attributes.height !== void 0 && !Number.isNaN(attributes.height) ? {
|
|
48
|
+
height: parseInt(attributes.height)
|
|
49
|
+
} : {},
|
|
50
|
+
parseHTML: (element) => element.getAttribute("height")
|
|
51
|
+
},
|
|
52
|
+
style: {
|
|
53
|
+
renderHTML: (attributes) => attributes.style ? {
|
|
54
|
+
style: attributes.style
|
|
55
|
+
} : {},
|
|
56
|
+
parseHTML: (element) => {
|
|
57
|
+
const style = element.getAttribute("style");
|
|
58
|
+
return style && typeof style == "string" && style.length > 0 ? {} : null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
parseHTML() {
|
|
64
|
+
return [
|
|
65
|
+
{
|
|
66
|
+
tag: 'img[src]:not([src^="data:"])',
|
|
67
|
+
getAttrs: (el) => {
|
|
68
|
+
var _a, _b, _c, _d, _e;
|
|
69
|
+
const attr = { src: el.getAttribute("src") };
|
|
70
|
+
return (_a = el.parentElement) != null && _a.className.includes("image-container") && (_b = el.parentElement.style) != null && _b.width && (attr.width = el.parentElement.style.width), (_c = el.style) != null && _c.width && (attr.width = el.style.width), [
|
|
71
|
+
"happy",
|
|
72
|
+
"proud",
|
|
73
|
+
"dreamy",
|
|
74
|
+
"love",
|
|
75
|
+
"tired",
|
|
76
|
+
"angry",
|
|
77
|
+
"worried",
|
|
78
|
+
"sick",
|
|
79
|
+
"joker",
|
|
80
|
+
"sad"
|
|
81
|
+
].filter((smiley) => attr.src.includes(smiley + ".png")).length > 0 && (attr.style = {
|
|
82
|
+
width: "1.5em",
|
|
83
|
+
height: "1.5em",
|
|
84
|
+
fontSize: (_e = (_d = el.parentElement) == null ? void 0 : _d.style) == null ? void 0 : _e.fontSize
|
|
85
|
+
}, attr.width = "null", attr.height = "null"), attr;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
},
|
|
90
|
+
renderHTML({ HTMLAttributes }) {
|
|
91
|
+
return [
|
|
92
|
+
"img",
|
|
93
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)
|
|
94
|
+
];
|
|
95
|
+
},
|
|
96
|
+
addInputRules() {
|
|
97
|
+
return [
|
|
98
|
+
nodeInputRule({
|
|
99
|
+
find: IMAGE_INPUT_REGEX,
|
|
100
|
+
type: this.type,
|
|
101
|
+
getAttributes: (match) => {
|
|
102
|
+
const [, , alt, src, title] = match;
|
|
103
|
+
return {
|
|
104
|
+
src,
|
|
105
|
+
alt,
|
|
106
|
+
title
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
];
|
|
111
|
+
},
|
|
112
|
+
addCommands() {
|
|
113
|
+
return {
|
|
114
|
+
setNewImage: (attrs) => ({ tr, dispatch }) => {
|
|
115
|
+
const { selection } = tr, node = this.type.create(attrs);
|
|
116
|
+
return dispatch && tr.replaceRangeWith(selection.from, selection.to, node), !0;
|
|
117
|
+
},
|
|
118
|
+
setAttributes: (attributes) => ({ tr, dispatch }) => {
|
|
119
|
+
const { selection } = tr, options = {
|
|
120
|
+
...tr.doc.nodeAt(tr.selection.from).attrs,
|
|
121
|
+
...attributes
|
|
122
|
+
}, node = this.type.create(options);
|
|
123
|
+
return dispatch && tr.replaceRangeWith(selection.from, selection.to, node), !0;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
export {
|
|
129
|
+
CustomImage,
|
|
130
|
+
IMAGE_INPUT_REGEX
|
|
131
|
+
};
|
|
181
132
|
//# sourceMappingURL=custom-image.js.map
|