@edifice.io/tiptap-extensions 1.5.16-develop-rc.2 → 2.0.0-develop-rc.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/README.md +63 -0
- package/package.json +5 -2
- package/.turbo/turbo-build.log +0 -58
- package/.turbo/turbo-format.log +0 -142
- package/.turbo/turbo-lint.log +0 -5
- package/src/abbr/abbr.ts +0 -57
- package/src/abbr/index.ts +0 -5
- package/src/alert/alert.ts +0 -46
- package/src/alert/index.ts +0 -5
- package/src/attachment/attachment.ts +0 -113
- package/src/attachment/index.ts +0 -5
- package/src/audio/audio.ts +0 -81
- package/src/audio/index.ts +0 -5
- package/src/font-size/font-size.ts +0 -74
- package/src/font-size/index.ts +0 -5
- package/src/heading/heading.ts +0 -90
- package/src/heading/index.ts +0 -5
- package/src/highlight/highlight.ts +0 -27
- package/src/highlight/index.ts +0 -5
- package/src/hyperlink/hyperlink.ts +0 -92
- package/src/hyperlink/index.ts +0 -5
- package/src/iframe/iframe.ts +0 -112
- package/src/iframe/index.ts +0 -5
- package/src/image/custom-image.ts +0 -226
- package/src/image/index.ts +0 -5
- package/src/index.ts +0 -19
- package/src/line-height/index.ts +0 -5
- package/src/line-height/line-height.ts +0 -37
- package/src/linker/index.ts +0 -5
- package/src/linker/linker.ts +0 -153
- package/src/mathjax/index.ts +0 -5
- package/src/mathjax/mathjax.ts +0 -55
- package/src/paragraph/index.ts +0 -5
- package/src/paragraph/paragraph.ts +0 -25
- package/src/speech-recognition/index.ts +0 -5
- package/src/speech-recognition/speech-recognition.ts +0 -123
- package/src/speech-synthesis/index.ts +0 -5
- package/src/speech-synthesis/speech-synthesis.ts +0 -52
- package/src/table-cell/index.ts +0 -5
- package/src/table-cell/table-cell.ts +0 -28
- package/src/transform/html-to-json/html-to-json.ts +0 -5
- package/src/transform/index.ts +0 -4
- package/src/transform/json-to-html/json-to-html.ts +0 -5
- package/src/video/index.ts +0 -5
- package/src/video/video.ts +0 -173
- package/tsconfig.json +0 -20
- package/vite.config.ts +0 -46
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import '@tiptap/extension-text-style';
|
|
2
|
-
|
|
3
|
-
import { Extension } from '@tiptap/core';
|
|
4
|
-
|
|
5
|
-
export type FontSizeOptions = {
|
|
6
|
-
types: string[];
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
declare module '@tiptap/core' {
|
|
10
|
-
interface Commands<ReturnType> {
|
|
11
|
-
fontSize: {
|
|
12
|
-
/**
|
|
13
|
-
* Set the font size
|
|
14
|
-
*/
|
|
15
|
-
setFontSize: (fontSize: string) => ReturnType;
|
|
16
|
-
/**
|
|
17
|
-
* Unset the font size
|
|
18
|
-
*/
|
|
19
|
-
unsetFontSize: () => ReturnType;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const FontSize = Extension.create<FontSizeOptions>({
|
|
25
|
-
name: 'fontSize',
|
|
26
|
-
|
|
27
|
-
addOptions() {
|
|
28
|
-
return {
|
|
29
|
-
types: ['textStyle'],
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
addGlobalAttributes() {
|
|
34
|
-
return [
|
|
35
|
-
{
|
|
36
|
-
types: this.options.types,
|
|
37
|
-
attributes: {
|
|
38
|
-
fontSize: {
|
|
39
|
-
default: null,
|
|
40
|
-
parseHTML: (element) =>
|
|
41
|
-
element.style.fontSize?.replace(/['"]+/g, ''),
|
|
42
|
-
renderHTML: (attributes) => {
|
|
43
|
-
if (!attributes.fontSize) {
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
style: `font-size: ${attributes.fontSize}`,
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
];
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
addCommands() {
|
|
58
|
-
return {
|
|
59
|
-
setFontSize:
|
|
60
|
-
(fontSize) =>
|
|
61
|
-
({ chain }) => {
|
|
62
|
-
return chain().setMark('textStyle', { fontSize }).run();
|
|
63
|
-
},
|
|
64
|
-
unsetFontSize:
|
|
65
|
-
() =>
|
|
66
|
-
({ chain }) => {
|
|
67
|
-
return chain()
|
|
68
|
-
.setMark('textStyle', { fontSize: null })
|
|
69
|
-
.removeEmptyTextStyle()
|
|
70
|
-
.run();
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
});
|
package/src/font-size/index.ts
DELETED
package/src/heading/heading.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { mergeAttributes } from '@tiptap/core';
|
|
2
|
-
import { Heading } from '@tiptap/extension-heading';
|
|
3
|
-
import '@tiptap/extension-text-style';
|
|
4
|
-
|
|
5
|
-
export declare type Level = 1 | 2;
|
|
6
|
-
|
|
7
|
-
interface Options {
|
|
8
|
-
levels: Level[];
|
|
9
|
-
HTMLAttributes: Record<string, any>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
declare module '@tiptap/core' {
|
|
13
|
-
interface Commands<ReturnType> {
|
|
14
|
-
customHeading: {
|
|
15
|
-
/**
|
|
16
|
-
* Apply Heading Level
|
|
17
|
-
*/
|
|
18
|
-
setCustomHeading: (attributes: { level: Level }) => ReturnType;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const CustomHeading = Heading.extend<Options>({
|
|
24
|
-
name: 'customHeading',
|
|
25
|
-
|
|
26
|
-
addOptions() {
|
|
27
|
-
return {
|
|
28
|
-
...this.parent?.(),
|
|
29
|
-
HTMLAttributes: {},
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
parseHTML() {
|
|
34
|
-
return this.options.levels.map((level: Level) => ({
|
|
35
|
-
tag: `h${level}`,
|
|
36
|
-
attrs: { level },
|
|
37
|
-
}));
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
renderHTML({ node, HTMLAttributes }) {
|
|
41
|
-
const hasLevel = this.options.levels.includes(node.attrs.level);
|
|
42
|
-
const level = hasLevel ? node.attrs.level : this.options.levels[0];
|
|
43
|
-
|
|
44
|
-
return [
|
|
45
|
-
`h${level}`,
|
|
46
|
-
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
47
|
-
0,
|
|
48
|
-
];
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
addCommands() {
|
|
52
|
-
return {
|
|
53
|
-
setCustomHeading:
|
|
54
|
-
(attributes) =>
|
|
55
|
-
({ tr, dispatch, commands }) => {
|
|
56
|
-
if (!this.options.levels.includes(attributes.level)) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const { selection } = tr;
|
|
61
|
-
const { from, to } = selection;
|
|
62
|
-
|
|
63
|
-
tr.doc.nodesBetween(from, to, (node, pos) => {
|
|
64
|
-
if (node.isBlock && from >= pos && to <= pos + node.nodeSize) {
|
|
65
|
-
/* get node content and iterate through */
|
|
66
|
-
node.content.forEach((content) => {
|
|
67
|
-
/* get content marks and iterate through */
|
|
68
|
-
content.marks.forEach((mark) => {
|
|
69
|
-
/* find textStyle mark and if has fontSize attrs */
|
|
70
|
-
if (
|
|
71
|
-
mark.type.name === 'textStyle' &&
|
|
72
|
-
mark.attrs['fontSize'] &&
|
|
73
|
-
mark.attrs['fontSize'] !== null
|
|
74
|
-
) {
|
|
75
|
-
/* remove any fontSize attr to reset heading style */
|
|
76
|
-
tr = tr.removeMark(pos, pos + node.nodeSize, mark.type);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
if (dispatch) {
|
|
84
|
-
dispatch(tr);
|
|
85
|
-
}
|
|
86
|
-
return commands.setHeading({ level: attributes.level });
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
});
|
package/src/heading/index.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import Highlight from '@tiptap/extension-highlight';
|
|
2
|
-
|
|
3
|
-
export const CustomHighlight = Highlight.extend({
|
|
4
|
-
name: 'customHighlight',
|
|
5
|
-
|
|
6
|
-
addOptions() {
|
|
7
|
-
return {
|
|
8
|
-
...this.parent?.(),
|
|
9
|
-
multicolor: true,
|
|
10
|
-
HTMLAttributes: {},
|
|
11
|
-
};
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
parseHTML() {
|
|
15
|
-
return [
|
|
16
|
-
{
|
|
17
|
-
...this.parent?.(),
|
|
18
|
-
style: 'background-color',
|
|
19
|
-
getAttrs: (style) => {
|
|
20
|
-
return {
|
|
21
|
-
color: style,
|
|
22
|
-
};
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
];
|
|
26
|
-
},
|
|
27
|
-
});
|
package/src/highlight/index.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { Link } from '@tiptap/extension-link';
|
|
2
|
-
|
|
3
|
-
/** Our own model of an hyperlink in a rich document. */
|
|
4
|
-
export type HyperlinkAttributes = {
|
|
5
|
-
href: string | null;
|
|
6
|
-
target: '_blank' | null;
|
|
7
|
-
title: string | null;
|
|
8
|
-
text: string | null;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
declare module '@tiptap/core' {
|
|
12
|
-
interface Commands<ReturnType> {
|
|
13
|
-
hyperlink: {
|
|
14
|
-
/**
|
|
15
|
-
* Set an hyperlink mark
|
|
16
|
-
*/
|
|
17
|
-
setLink: (attributes: Partial<HyperlinkAttributes>) => ReturnType;
|
|
18
|
-
/**
|
|
19
|
-
* Toggle an hyperlink mark
|
|
20
|
-
*/
|
|
21
|
-
toggleLink: (attributes: {
|
|
22
|
-
href: string;
|
|
23
|
-
target?: string | null;
|
|
24
|
-
}) => ReturnType;
|
|
25
|
-
/**
|
|
26
|
-
* Unset an hyperlink mark
|
|
27
|
-
*/
|
|
28
|
-
unsetLink: () => ReturnType;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Hyperlink (external links), extends `Link` extension from TipTap.
|
|
35
|
-
*
|
|
36
|
-
* Links to external resources MUST NOT have a `data-id` nor a `data-app-prefix` attribute.
|
|
37
|
-
* The `target` attribute has to be sanitized, so it is overriden.
|
|
38
|
-
*/
|
|
39
|
-
export const Hyperlink = Link.extend({
|
|
40
|
-
name: 'hyperlink',
|
|
41
|
-
|
|
42
|
-
parseHTML() {
|
|
43
|
-
return [
|
|
44
|
-
{
|
|
45
|
-
tag: 'a[href]:not([href *= "javascript:" i])',
|
|
46
|
-
// Be sure no data-id and data-app-prefix attribute exists :
|
|
47
|
-
// it would then be an Linker, not an Hyperlink !
|
|
48
|
-
getAttrs: (node: HTMLAnchorElement) => {
|
|
49
|
-
// See https://prosemirror.net/docs/ref/version/0.18.0.html#model.ParseRule.getAttrs
|
|
50
|
-
if (
|
|
51
|
-
node.getAttribute('data-id') &&
|
|
52
|
-
node.getAttribute('data-app-prefix')
|
|
53
|
-
)
|
|
54
|
-
return false;
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
];
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
addOptions() {
|
|
61
|
-
return {
|
|
62
|
-
...this.parent?.(),
|
|
63
|
-
openOnClick: false,
|
|
64
|
-
HTMLAttributes: {
|
|
65
|
-
...this.parent?.().HTMLAttributes,
|
|
66
|
-
target: null,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
/* Manage `title` and `target` attributes. */
|
|
72
|
-
addAttributes() {
|
|
73
|
-
return {
|
|
74
|
-
// Preserve attributes of parent extension...
|
|
75
|
-
...this.parent?.(),
|
|
76
|
-
// ...then add or override the following :
|
|
77
|
-
//------------------
|
|
78
|
-
target: {
|
|
79
|
-
default: this.options.HTMLAttributes.target,
|
|
80
|
-
// Sanitize target value
|
|
81
|
-
parseHTML: (element) =>
|
|
82
|
-
element.getAttribute('target') !== '_blank' ? null : '_blank',
|
|
83
|
-
renderHTML: (attributes) => ({
|
|
84
|
-
target: attributes['target'],
|
|
85
|
-
}),
|
|
86
|
-
},
|
|
87
|
-
title: {
|
|
88
|
-
default: this.options.HTMLAttributes.title,
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
},
|
|
92
|
-
});
|
package/src/hyperlink/index.ts
DELETED
package/src/iframe/iframe.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { Node } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
export interface IframeOptions {
|
|
4
|
-
allowFullscreen: boolean;
|
|
5
|
-
HTMLAttributes: {
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
declare module '@tiptap/core' {
|
|
11
|
-
interface Commands<ReturnType> {
|
|
12
|
-
iframe: {
|
|
13
|
-
/**
|
|
14
|
-
* Add an iframe
|
|
15
|
-
*/
|
|
16
|
-
setIframe: (options: { src: string }) => ReturnType;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const Iframe = Node.create<IframeOptions>({
|
|
22
|
-
name: 'iframe',
|
|
23
|
-
group: 'block',
|
|
24
|
-
atom: true,
|
|
25
|
-
draggable: true,
|
|
26
|
-
|
|
27
|
-
addOptions() {
|
|
28
|
-
return {
|
|
29
|
-
allowFullscreen: true,
|
|
30
|
-
HTMLAttributes: {
|
|
31
|
-
class: 'iframe-wrapper',
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
addAttributes() {
|
|
37
|
-
return {
|
|
38
|
-
src: {
|
|
39
|
-
default: null,
|
|
40
|
-
},
|
|
41
|
-
frameborder: {
|
|
42
|
-
default: 0,
|
|
43
|
-
},
|
|
44
|
-
allowfullscreen: {
|
|
45
|
-
default: this.options.allowFullscreen,
|
|
46
|
-
parseHTML: () => this.options.allowFullscreen,
|
|
47
|
-
},
|
|
48
|
-
width: {
|
|
49
|
-
renderHTML: (attributes) => {
|
|
50
|
-
return attributes.width
|
|
51
|
-
? {
|
|
52
|
-
width:
|
|
53
|
-
attributes.width === '100%'
|
|
54
|
-
? '100%'
|
|
55
|
-
: parseInt(attributes.width),
|
|
56
|
-
}
|
|
57
|
-
: {};
|
|
58
|
-
},
|
|
59
|
-
parseHTML: (element) => element.getAttribute('width'),
|
|
60
|
-
},
|
|
61
|
-
height: {
|
|
62
|
-
renderHTML: (attributes) => {
|
|
63
|
-
return attributes.height
|
|
64
|
-
? {
|
|
65
|
-
height: parseInt(attributes.height),
|
|
66
|
-
}
|
|
67
|
-
: {};
|
|
68
|
-
},
|
|
69
|
-
parseHTML: (element) => element.getAttribute('height'),
|
|
70
|
-
},
|
|
71
|
-
style: {
|
|
72
|
-
renderHTML: (attributes) => {
|
|
73
|
-
return attributes.style
|
|
74
|
-
? {
|
|
75
|
-
style: attributes.style,
|
|
76
|
-
}
|
|
77
|
-
: {};
|
|
78
|
-
},
|
|
79
|
-
parseHTML: (element) => element.getAttribute('style'),
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
parseHTML() {
|
|
85
|
-
return [
|
|
86
|
-
{
|
|
87
|
-
tag: 'iframe',
|
|
88
|
-
},
|
|
89
|
-
];
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
renderHTML({ HTMLAttributes }) {
|
|
93
|
-
return ['div', this.options.HTMLAttributes, ['iframe', HTMLAttributes]];
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
addCommands() {
|
|
97
|
-
return {
|
|
98
|
-
setIframe:
|
|
99
|
-
(options: { src: string }) =>
|
|
100
|
-
({ tr, dispatch }) => {
|
|
101
|
-
const { selection } = tr;
|
|
102
|
-
const node = this.type.create(options);
|
|
103
|
-
|
|
104
|
-
if (dispatch) {
|
|
105
|
-
tr.replaceRangeWith(selection.from, selection.to, node);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return true;
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
});
|
package/src/iframe/index.ts
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { mergeAttributes, nodeInputRule } from '@tiptap/core';
|
|
2
|
-
import Image from '@tiptap/extension-image';
|
|
3
|
-
|
|
4
|
-
export const IMAGE_INPUT_REGEX =
|
|
5
|
-
/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;
|
|
6
|
-
|
|
7
|
-
export interface CustomImageOptions {
|
|
8
|
-
HTMLAttributes: Record<string, string>;
|
|
9
|
-
sizes: string[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface AttributesProps {
|
|
13
|
-
width: number | string;
|
|
14
|
-
height: number | string;
|
|
15
|
-
size: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare module '@tiptap/core' {
|
|
19
|
-
interface Commands<ReturnType> {
|
|
20
|
-
customImage: {
|
|
21
|
-
setAttributes: (options: AttributesProps) => ReturnType;
|
|
22
|
-
setNewImage: (options: {
|
|
23
|
-
src: string;
|
|
24
|
-
alt?: string;
|
|
25
|
-
title?: string;
|
|
26
|
-
}) => ReturnType;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const CustomImage = Image.extend<CustomImageOptions>({
|
|
32
|
-
name: 'custom-image',
|
|
33
|
-
draggable: true,
|
|
34
|
-
selectable: true,
|
|
35
|
-
|
|
36
|
-
addOptions() {
|
|
37
|
-
return {
|
|
38
|
-
...this.parent?.(),
|
|
39
|
-
inline: true,
|
|
40
|
-
content: 'inline*',
|
|
41
|
-
sizes: ['small', 'medium', 'large'],
|
|
42
|
-
HTMLAttributes: {
|
|
43
|
-
class: 'custom-image',
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
addAttributes() {
|
|
49
|
-
return {
|
|
50
|
-
...this.parent?.(),
|
|
51
|
-
size: {
|
|
52
|
-
default: 'medium',
|
|
53
|
-
rendered: false,
|
|
54
|
-
},
|
|
55
|
-
alt: {
|
|
56
|
-
renderHTML: (attributes) => {
|
|
57
|
-
return {
|
|
58
|
-
alt: attributes.alt,
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
parseHTML: (element) => element.getAttribute('alt'),
|
|
62
|
-
},
|
|
63
|
-
title: {
|
|
64
|
-
renderHTML: (attributes) => {
|
|
65
|
-
return {
|
|
66
|
-
title: attributes.title,
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
parseHTML: (element) => element.getAttribute('title'),
|
|
70
|
-
},
|
|
71
|
-
width: {
|
|
72
|
-
default: '350',
|
|
73
|
-
renderHTML: (attributes) => {
|
|
74
|
-
if (
|
|
75
|
-
attributes.width !== null &&
|
|
76
|
-
attributes.width !== undefined &&
|
|
77
|
-
!Number.isNaN(attributes.width)
|
|
78
|
-
) {
|
|
79
|
-
return {
|
|
80
|
-
width: parseInt(attributes.width),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
return {};
|
|
84
|
-
},
|
|
85
|
-
parseHTML: (element) => element.getAttribute('width'),
|
|
86
|
-
},
|
|
87
|
-
height: {
|
|
88
|
-
renderHTML: (attributes) => {
|
|
89
|
-
if (
|
|
90
|
-
attributes.height !== null &&
|
|
91
|
-
attributes.height !== undefined &&
|
|
92
|
-
!Number.isNaN(attributes.height)
|
|
93
|
-
) {
|
|
94
|
-
return {
|
|
95
|
-
height: parseInt(attributes.height),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return {};
|
|
99
|
-
},
|
|
100
|
-
parseHTML: (element) => element.getAttribute('height'),
|
|
101
|
-
},
|
|
102
|
-
style: {
|
|
103
|
-
renderHTML: (attributes) => {
|
|
104
|
-
return attributes.style
|
|
105
|
-
? {
|
|
106
|
-
style: attributes.style,
|
|
107
|
-
}
|
|
108
|
-
: {};
|
|
109
|
-
},
|
|
110
|
-
parseHTML: (element) => {
|
|
111
|
-
const style = element.getAttribute('style');
|
|
112
|
-
return style && typeof style === 'string' && style.length > 0
|
|
113
|
-
? {}
|
|
114
|
-
: null;
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
parseHTML() {
|
|
121
|
-
return [
|
|
122
|
-
{
|
|
123
|
-
tag: 'img[src]:not([src^="data:"])',
|
|
124
|
-
getAttrs: (el: HTMLImageElement) => {
|
|
125
|
-
const attr = { src: el.getAttribute('src') };
|
|
126
|
-
// Check old content format and get the width from the parent element
|
|
127
|
-
if (el.parentElement?.className.includes('image-container')) {
|
|
128
|
-
if (el.parentElement.style?.width) {
|
|
129
|
-
attr['width'] = el.parentElement.style.width;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (el.style?.width) {
|
|
133
|
-
attr['width'] = el.style.width;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Check old content smiley
|
|
137
|
-
const oldSmileyList = [
|
|
138
|
-
'happy',
|
|
139
|
-
'proud',
|
|
140
|
-
'dreamy',
|
|
141
|
-
'love',
|
|
142
|
-
'tired',
|
|
143
|
-
'angry',
|
|
144
|
-
'worried',
|
|
145
|
-
'sick',
|
|
146
|
-
'joker',
|
|
147
|
-
'sad',
|
|
148
|
-
];
|
|
149
|
-
if (
|
|
150
|
-
oldSmileyList.filter((smiley) => attr.src.includes(smiley + '.png'))
|
|
151
|
-
.length > 0
|
|
152
|
-
) {
|
|
153
|
-
attr['style'] = {
|
|
154
|
-
width: '1.5em',
|
|
155
|
-
height: '1.5em',
|
|
156
|
-
fontSize: el.parentElement?.style?.fontSize,
|
|
157
|
-
};
|
|
158
|
-
attr['width'] = 'null';
|
|
159
|
-
attr['height'] = 'null';
|
|
160
|
-
}
|
|
161
|
-
return attr;
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
];
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
renderHTML({ HTMLAttributes }) {
|
|
168
|
-
return [
|
|
169
|
-
'img',
|
|
170
|
-
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
171
|
-
];
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
addInputRules() {
|
|
175
|
-
return [
|
|
176
|
-
nodeInputRule({
|
|
177
|
-
find: IMAGE_INPUT_REGEX,
|
|
178
|
-
type: this.type,
|
|
179
|
-
getAttributes: (match) => {
|
|
180
|
-
const [, , alt, src, title] = match;
|
|
181
|
-
|
|
182
|
-
return {
|
|
183
|
-
src,
|
|
184
|
-
alt,
|
|
185
|
-
title,
|
|
186
|
-
};
|
|
187
|
-
},
|
|
188
|
-
}),
|
|
189
|
-
];
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
addCommands() {
|
|
193
|
-
return {
|
|
194
|
-
setNewImage:
|
|
195
|
-
(attrs) =>
|
|
196
|
-
({ tr, dispatch }) => {
|
|
197
|
-
const { selection } = tr;
|
|
198
|
-
const node = this.type.create(attrs);
|
|
199
|
-
|
|
200
|
-
if (dispatch) {
|
|
201
|
-
tr.replaceRangeWith(selection.from, selection.to, node);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return true;
|
|
205
|
-
},
|
|
206
|
-
setAttributes:
|
|
207
|
-
(attributes) =>
|
|
208
|
-
({ tr, dispatch }) => {
|
|
209
|
-
const { selection } = tr;
|
|
210
|
-
|
|
211
|
-
const nodeAttrs = tr.doc.nodeAt(tr.selection.from);
|
|
212
|
-
const options = {
|
|
213
|
-
...nodeAttrs.attrs,
|
|
214
|
-
...attributes,
|
|
215
|
-
};
|
|
216
|
-
const node = this.type.create(options);
|
|
217
|
-
|
|
218
|
-
if (dispatch) {
|
|
219
|
-
tr.replaceRangeWith(selection.from, selection.to, node);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return true;
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
},
|
|
226
|
-
});
|
package/src/image/index.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from './abbr';
|
|
2
|
-
export * from './alert';
|
|
3
|
-
export * from './attachment';
|
|
4
|
-
export * from './audio';
|
|
5
|
-
export * from './font-size';
|
|
6
|
-
export * from './heading';
|
|
7
|
-
export * from './highlight';
|
|
8
|
-
export * from './hyperlink';
|
|
9
|
-
export * from './iframe';
|
|
10
|
-
export * from './image';
|
|
11
|
-
export * from './line-height';
|
|
12
|
-
export * from './linker';
|
|
13
|
-
export * from './mathjax';
|
|
14
|
-
export * from './paragraph';
|
|
15
|
-
export * from './speech-recognition';
|
|
16
|
-
export * from './speech-synthesis';
|
|
17
|
-
export * from './table-cell';
|
|
18
|
-
export * from './transform';
|
|
19
|
-
export * from './video';
|