@kerebron/extension-basic-editor 0.4.31 → 0.5.1
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 +4 -4
- package/esm/BasicEditorKit.d.ts +5 -0
- package/esm/BasicEditorKit.d.ts.map +1 -0
- package/esm/BasicEditorKit.js +97 -0
- package/esm/BasicEditorKit.js.map +1 -0
- package/esm/ExtensionBasicEditor.d.ts +1 -44
- package/esm/ExtensionBasicEditor.d.ts.map +1 -1
- package/esm/ExtensionBasicEditor.js +3 -90
- package/esm/ExtensionBasicEditor.js.map +1 -1
- package/esm/NodeIframe.d.ts +8 -0
- package/esm/NodeIframe.d.ts.map +1 -0
- package/esm/NodeIframe.js +35 -0
- package/esm/NodeIframe.js.map +1 -0
- package/esm/NodeImage.d.ts +3 -0
- package/esm/NodeImage.d.ts.map +1 -1
- package/esm/NodeImage.js +190 -2
- package/esm/NodeImage.js.map +1 -1
- package/esm/NodeInlineShortCode.d.ts +3 -0
- package/esm/NodeInlineShortCode.d.ts.map +1 -1
- package/esm/NodeInlineShortCode.js +42 -4
- package/esm/NodeInlineShortCode.js.map +1 -1
- package/package.json +11 -5
- package/src/BasicEditorKit.ts +101 -0
- package/src/ExtensionBasicEditor.ts +3 -91
- package/src/NodeIframe.ts +37 -0
- package/src/NodeImage.ts +209 -2
- package/src/NodeInlineShortCode.ts +72 -7
|
@@ -10,8 +10,23 @@ export function fixCharacters(text) {
|
|
|
10
10
|
.replace(/\u201d/g, '"')
|
|
11
11
|
.replace(/\u201c/g, '"');
|
|
12
12
|
}
|
|
13
|
+
function replaceAllNodesOfType(tr, doc, oldType, factory) {
|
|
14
|
+
const replacements = [];
|
|
15
|
+
doc.descendants((node, pos) => {
|
|
16
|
+
if (node.type === oldType) {
|
|
17
|
+
replacements.push({ node, pos });
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
console.log('replaceAllNodesOfType', replacements.length);
|
|
21
|
+
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
22
|
+
const { node, pos } = replacements[i];
|
|
23
|
+
const newNode = factory(node, tr.doc.type.schema);
|
|
24
|
+
tr = tr.replaceWith(pos, pos + node.nodeSize, newNode);
|
|
25
|
+
}
|
|
26
|
+
return tr;
|
|
27
|
+
}
|
|
13
28
|
export class NodeInlineShortCode extends Node {
|
|
14
|
-
name = '
|
|
29
|
+
name = 'shortcode_inline';
|
|
15
30
|
requires = ['doc'];
|
|
16
31
|
getNodeSpec() {
|
|
17
32
|
return {
|
|
@@ -19,12 +34,21 @@ export class NodeInlineShortCode extends Node {
|
|
|
19
34
|
group: 'inline',
|
|
20
35
|
selectable: true,
|
|
21
36
|
attrs: {
|
|
22
|
-
content: {
|
|
37
|
+
content: {
|
|
38
|
+
default: '',
|
|
39
|
+
},
|
|
23
40
|
},
|
|
24
41
|
atom: true,
|
|
25
|
-
parseDOM: [{
|
|
42
|
+
parseDOM: [{
|
|
43
|
+
tag: 'span.kb-shortcode-inline',
|
|
44
|
+
getAttrs: (dom) => ({ content: dom.textContent || null }),
|
|
45
|
+
}],
|
|
26
46
|
toDOM(node) {
|
|
27
|
-
return [
|
|
47
|
+
return [
|
|
48
|
+
'span',
|
|
49
|
+
{ class: 'kb-shortcode-inline' },
|
|
50
|
+
node.attrs.content || '',
|
|
51
|
+
];
|
|
28
52
|
},
|
|
29
53
|
};
|
|
30
54
|
}
|
|
@@ -36,5 +60,19 @@ export class NodeInlineShortCode extends Node {
|
|
|
36
60
|
}),
|
|
37
61
|
];
|
|
38
62
|
}
|
|
63
|
+
getCommandFactories(editor, type) {
|
|
64
|
+
return {
|
|
65
|
+
'renderShortCode': (createReplacementNode) => {
|
|
66
|
+
return (state, dispatch) => {
|
|
67
|
+
let tr = state.tr;
|
|
68
|
+
tr = replaceAllNodesOfType(tr, state.doc, type, createReplacementNode);
|
|
69
|
+
if (tr.docChanged && dispatch) {
|
|
70
|
+
dispatch(tr);
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
39
77
|
}
|
|
40
78
|
//# sourceMappingURL=NodeInlineShortCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeInlineShortCode.js","sourceRoot":"","sources":["../src/NodeInlineShortCode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NodeInlineShortCode.js","sourceRoot":"","sources":["../src/NodeInlineShortCode.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kerebron/extension-basic-editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"module": "./esm/
|
|
5
|
+
"module": "./esm/BasicEditorKit.js",
|
|
6
6
|
"exports": {
|
|
7
|
+
"./BasicEditorKit": {
|
|
8
|
+
"import": "./esm/BasicEditorKit.js"
|
|
9
|
+
},
|
|
7
10
|
"./ExtensionBasicEditor": {
|
|
8
11
|
"import": "./esm/ExtensionBasicEditor.js"
|
|
9
12
|
},
|
|
@@ -34,6 +37,9 @@
|
|
|
34
37
|
"./ExtensionHtml": {
|
|
35
38
|
"import": "./esm/ExtensionHtml.js"
|
|
36
39
|
},
|
|
40
|
+
"./ExtensionTextAlign": {
|
|
41
|
+
"import": "./esm/ExtensionTextAlign.js"
|
|
42
|
+
},
|
|
37
43
|
"./NodeDocument": {
|
|
38
44
|
"import": "./esm/NodeDocument.js"
|
|
39
45
|
},
|
|
@@ -106,8 +112,8 @@
|
|
|
106
112
|
"./MarkSubscript": {
|
|
107
113
|
"import": "./esm/MarkSubscript.js"
|
|
108
114
|
},
|
|
109
|
-
"./
|
|
110
|
-
"import": "./
|
|
115
|
+
"./assets/*.css": {
|
|
116
|
+
"import": "./assets/*.css"
|
|
111
117
|
}
|
|
112
118
|
},
|
|
113
119
|
"scripts": {},
|
|
@@ -116,7 +122,7 @@
|
|
|
116
122
|
"src"
|
|
117
123
|
],
|
|
118
124
|
"dependencies": {
|
|
119
|
-
"@kerebron/editor": "0.
|
|
125
|
+
"@kerebron/editor": "0.5.1",
|
|
120
126
|
"prosemirror-history": "1.4.1",
|
|
121
127
|
"prosemirror-model": "1.25.3",
|
|
122
128
|
"prosemirror-state": "1.4.3",
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { AnyExtensionOrReq, EditorKit } from '@kerebron/editor';
|
|
2
|
+
|
|
3
|
+
import { ExtensionSelection } from './ExtensionSelection.js';
|
|
4
|
+
import { ExtensionBaseKeymap } from './ExtensionBaseKeymap.js';
|
|
5
|
+
import { ExtensionDropcursor } from './ExtensionDropcursor.js';
|
|
6
|
+
import { ExtensionGapcursor } from './ExtensionGapcursor.js';
|
|
7
|
+
import { ExtensionHtml } from './ExtensionHtml.js';
|
|
8
|
+
import { ExtensionMediaUpload } from './ExtensionMediaUpload.js';
|
|
9
|
+
import { ExtensionRemoteSelection } from './remote-selection/ExtensionRemoteSelection.js';
|
|
10
|
+
import { ExtensionTextAlign } from './ExtensionTextAlign.js';
|
|
11
|
+
|
|
12
|
+
import { MarkLink } from './MarkLink.js';
|
|
13
|
+
import { MarkStrong } from './MarkStrong.js';
|
|
14
|
+
import { MarkItalic } from './MarkItalic.js';
|
|
15
|
+
import { MarkUnderline } from './MarkUnderline.js';
|
|
16
|
+
import { MarkStrike } from './MarkStrike.js';
|
|
17
|
+
import { MarkCode } from './MarkCode.js';
|
|
18
|
+
import { MarkChange } from './MarkChange.js';
|
|
19
|
+
import { MarkBookmark } from './MarkBookmark.js';
|
|
20
|
+
import { MarkTextColor } from './MarkTextColor.js';
|
|
21
|
+
import { MarkHighlight } from './MarkHighlight.js';
|
|
22
|
+
import { MarkSuperscript } from './MarkSuperscript.js';
|
|
23
|
+
import { MarkSubscript } from './MarkSubscript.js';
|
|
24
|
+
|
|
25
|
+
import { NodeDocument } from './NodeDocument.js';
|
|
26
|
+
import { NodeText } from './NodeText.js';
|
|
27
|
+
import { NodeCodeBlock } from './NodeCodeBlock.js';
|
|
28
|
+
import { NodeBookmark } from './NodeBookmark.js';
|
|
29
|
+
import { NodeParagraph } from './NodeParagraph.js';
|
|
30
|
+
import { NodeHardBreak } from './NodeHardBreak.js';
|
|
31
|
+
import { NodeHorizontalRule } from './NodeHorizontalRule.js';
|
|
32
|
+
import { NodeOrderedList } from './NodeOrderedList.js';
|
|
33
|
+
import { NodeBulletList } from './NodeBulletList.js';
|
|
34
|
+
import { NodeListItem } from './NodeListItem.js';
|
|
35
|
+
import { NodeImage } from './NodeImage.js';
|
|
36
|
+
import { NodeVideo } from './NodeVideo.js';
|
|
37
|
+
import { NodeBlockquote } from './NodeBlockquote.js';
|
|
38
|
+
import { NodeAside } from './NodeAside.js';
|
|
39
|
+
import { NodeHeading } from './NodeHeading.js';
|
|
40
|
+
import { NodeMath } from './NodeMath.js';
|
|
41
|
+
import { NodeDefinitionList } from './NodeDefinitionList.js';
|
|
42
|
+
import { NodeDefinitionTerm } from './NodeDefinitionTerm.js';
|
|
43
|
+
import { NodeDefinitionDesc } from './NodeDefinitionDesc.js';
|
|
44
|
+
import { NodeFrontmatter } from './NodeFrontmatter.js';
|
|
45
|
+
import { NodeTaskList } from './NodeTaskList.js';
|
|
46
|
+
import { NodeTaskItem } from './NodeTaskItem.js';
|
|
47
|
+
import { NodeInlineShortCode } from './NodeInlineShortCode.js';
|
|
48
|
+
import { NodeIframe } from './NodeIframe.js';
|
|
49
|
+
|
|
50
|
+
export class BasicEditorKit implements EditorKit {
|
|
51
|
+
getExtensions(): AnyExtensionOrReq[] {
|
|
52
|
+
return [
|
|
53
|
+
new ExtensionBaseKeymap(),
|
|
54
|
+
new ExtensionDropcursor(),
|
|
55
|
+
new ExtensionGapcursor(),
|
|
56
|
+
new ExtensionHtml(),
|
|
57
|
+
new ExtensionMediaUpload(),
|
|
58
|
+
new ExtensionRemoteSelection(),
|
|
59
|
+
new ExtensionSelection(),
|
|
60
|
+
new ExtensionTextAlign(),
|
|
61
|
+
new NodeDocument(),
|
|
62
|
+
new NodeText(),
|
|
63
|
+
new NodeParagraph(),
|
|
64
|
+
new NodeHardBreak(),
|
|
65
|
+
new NodeCodeBlock(),
|
|
66
|
+
new NodeBookmark(),
|
|
67
|
+
new NodeHorizontalRule(),
|
|
68
|
+
new NodeOrderedList(),
|
|
69
|
+
new NodeBulletList(),
|
|
70
|
+
new NodeListItem(),
|
|
71
|
+
new NodeTaskList(),
|
|
72
|
+
new NodeTaskItem(),
|
|
73
|
+
new NodeDefinitionList(),
|
|
74
|
+
new NodeDefinitionTerm(),
|
|
75
|
+
new NodeDefinitionDesc(),
|
|
76
|
+
new NodeTaskList(),
|
|
77
|
+
new NodeTaskItem(),
|
|
78
|
+
new NodeFrontmatter(),
|
|
79
|
+
new NodeImage(),
|
|
80
|
+
new NodeVideo(),
|
|
81
|
+
new NodeBlockquote(),
|
|
82
|
+
new NodeAside(),
|
|
83
|
+
new NodeHeading(),
|
|
84
|
+
new NodeMath(),
|
|
85
|
+
new NodeInlineShortCode(),
|
|
86
|
+
new NodeIframe(),
|
|
87
|
+
new MarkLink(),
|
|
88
|
+
new MarkItalic(),
|
|
89
|
+
new MarkStrong(),
|
|
90
|
+
new MarkUnderline(),
|
|
91
|
+
new MarkStrike(),
|
|
92
|
+
new MarkCode(),
|
|
93
|
+
new MarkChange(),
|
|
94
|
+
new MarkBookmark(),
|
|
95
|
+
new MarkTextColor(),
|
|
96
|
+
new MarkHighlight(),
|
|
97
|
+
new MarkSuperscript(),
|
|
98
|
+
new MarkSubscript(),
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -1,97 +1,9 @@
|
|
|
1
1
|
import { Extension } from '@kerebron/editor';
|
|
2
|
-
import {
|
|
3
|
-
import { ExtensionBaseKeymap } from './ExtensionBaseKeymap.js';
|
|
4
|
-
import { ExtensionDropcursor } from './ExtensionDropcursor.js';
|
|
5
|
-
import { ExtensionGapcursor } from './ExtensionGapcursor.js';
|
|
6
|
-
import { ExtensionHtml } from './ExtensionHtml.js';
|
|
7
|
-
import { ExtensionMediaUpload } from './ExtensionMediaUpload.js';
|
|
8
|
-
import { ExtensionRemoteSelection } from './remote-selection/ExtensionRemoteSelection.js';
|
|
9
|
-
import { ExtensionTextAlign } from './ExtensionTextAlign.js';
|
|
2
|
+
import { BasicEditorKit } from './BasicEditorKit.js';
|
|
10
3
|
|
|
11
|
-
|
|
12
|
-
import { MarkStrong } from './MarkStrong.js';
|
|
13
|
-
import { MarkItalic } from './MarkItalic.js';
|
|
14
|
-
import { MarkUnderline } from './MarkUnderline.js';
|
|
15
|
-
import { MarkStrike } from './MarkStrike.js';
|
|
16
|
-
import { MarkCode } from './MarkCode.js';
|
|
17
|
-
import { MarkChange } from './MarkChange.js';
|
|
18
|
-
import { MarkBookmark } from './MarkBookmark.js';
|
|
19
|
-
import { MarkTextColor } from './MarkTextColor.js';
|
|
20
|
-
import { MarkHighlight } from './MarkHighlight.js';
|
|
21
|
-
import { MarkSuperscript } from './MarkSuperscript.js';
|
|
22
|
-
import { MarkSubscript } from './MarkSubscript.js';
|
|
23
|
-
|
|
24
|
-
import { NodeDocument } from './NodeDocument.js';
|
|
25
|
-
import { NodeText } from './NodeText.js';
|
|
26
|
-
import { NodeCodeBlock } from './NodeCodeBlock.js';
|
|
27
|
-
import { NodeBookmark } from './NodeBookmark.js';
|
|
28
|
-
import { NodeParagraph } from './NodeParagraph.js';
|
|
29
|
-
import { NodeHardBreak } from './NodeHardBreak.js';
|
|
30
|
-
import { NodeHorizontalRule } from './NodeHorizontalRule.js';
|
|
31
|
-
import { NodeOrderedList } from './NodeOrderedList.js';
|
|
32
|
-
import { NodeBulletList } from './NodeBulletList.js';
|
|
33
|
-
import { NodeListItem } from './NodeListItem.js';
|
|
34
|
-
import { NodeImage } from './NodeImage.js';
|
|
35
|
-
import { NodeVideo } from './NodeVideo.js';
|
|
36
|
-
import { NodeBlockquote } from './NodeBlockquote.js';
|
|
37
|
-
import { NodeAside } from './NodeAside.js';
|
|
38
|
-
import { NodeHeading } from './NodeHeading.js';
|
|
39
|
-
import { NodeMath } from './NodeMath.js';
|
|
40
|
-
import { NodeDefinitionList } from './NodeDefinitionList.js';
|
|
41
|
-
import { NodeDefinitionTerm } from './NodeDefinitionTerm.js';
|
|
42
|
-
import { NodeDefinitionDesc } from './NodeDefinitionDesc.js';
|
|
43
|
-
import { NodeFrontmatter } from './NodeFrontmatter.js';
|
|
44
|
-
import { NodeTaskList } from './NodeTaskList.js';
|
|
45
|
-
import { NodeTaskItem } from './NodeTaskItem.js';
|
|
46
|
-
import { NodeInlineShortCode } from './NodeInlineShortCode.js';
|
|
4
|
+
const kit = new BasicEditorKit();
|
|
47
5
|
|
|
48
6
|
export class ExtensionBasicEditor extends Extension {
|
|
49
7
|
name = 'basic-editor';
|
|
50
|
-
requires =
|
|
51
|
-
new ExtensionBaseKeymap(),
|
|
52
|
-
new ExtensionDropcursor(),
|
|
53
|
-
new ExtensionGapcursor(),
|
|
54
|
-
new ExtensionHtml(),
|
|
55
|
-
new ExtensionMediaUpload(),
|
|
56
|
-
new ExtensionRemoteSelection(),
|
|
57
|
-
new ExtensionSelection(),
|
|
58
|
-
new ExtensionTextAlign(),
|
|
59
|
-
new NodeDocument(),
|
|
60
|
-
new NodeText(),
|
|
61
|
-
new NodeParagraph(),
|
|
62
|
-
new NodeHardBreak(),
|
|
63
|
-
new NodeCodeBlock(),
|
|
64
|
-
new NodeBookmark(),
|
|
65
|
-
new NodeHorizontalRule(),
|
|
66
|
-
new NodeOrderedList(),
|
|
67
|
-
new NodeBulletList(),
|
|
68
|
-
new NodeListItem(),
|
|
69
|
-
new NodeTaskList(),
|
|
70
|
-
new NodeTaskItem(),
|
|
71
|
-
new NodeDefinitionList(),
|
|
72
|
-
new NodeDefinitionTerm(),
|
|
73
|
-
new NodeDefinitionDesc(),
|
|
74
|
-
new NodeTaskList(),
|
|
75
|
-
new NodeTaskItem(),
|
|
76
|
-
new NodeFrontmatter(),
|
|
77
|
-
new NodeImage(),
|
|
78
|
-
new NodeVideo(),
|
|
79
|
-
new NodeBlockquote(),
|
|
80
|
-
new NodeAside(),
|
|
81
|
-
new NodeHeading(),
|
|
82
|
-
new NodeMath(),
|
|
83
|
-
new NodeInlineShortCode(),
|
|
84
|
-
new MarkLink(),
|
|
85
|
-
new MarkItalic(),
|
|
86
|
-
new MarkStrong(),
|
|
87
|
-
new MarkUnderline(),
|
|
88
|
-
new MarkStrike(),
|
|
89
|
-
new MarkCode(),
|
|
90
|
-
new MarkChange(),
|
|
91
|
-
new MarkBookmark(),
|
|
92
|
-
new MarkTextColor(),
|
|
93
|
-
new MarkHighlight(),
|
|
94
|
-
new MarkSuperscript(),
|
|
95
|
-
new MarkSubscript(),
|
|
96
|
-
];
|
|
8
|
+
requires = kit.getExtensions();
|
|
97
9
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type NodeSpec } from 'prosemirror-model';
|
|
2
|
+
import { Node } from '@kerebron/editor';
|
|
3
|
+
|
|
4
|
+
export class NodeIframe extends Node {
|
|
5
|
+
override name = 'iframe';
|
|
6
|
+
requires = ['doc'];
|
|
7
|
+
|
|
8
|
+
override getNodeSpec(): NodeSpec {
|
|
9
|
+
return {
|
|
10
|
+
inline: true,
|
|
11
|
+
attrs: {
|
|
12
|
+
src: {},
|
|
13
|
+
class: { default: null },
|
|
14
|
+
alt: { default: null },
|
|
15
|
+
title: { default: null },
|
|
16
|
+
},
|
|
17
|
+
group: 'inline',
|
|
18
|
+
draggable: true,
|
|
19
|
+
parseDOM: [
|
|
20
|
+
{
|
|
21
|
+
tag: 'iframe[src]',
|
|
22
|
+
getAttrs(dom: HTMLElement) {
|
|
23
|
+
return {
|
|
24
|
+
src: dom.getAttribute('src'),
|
|
25
|
+
title: dom.getAttribute('title'),
|
|
26
|
+
alt: dom.getAttribute('alt'),
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
toDOM(node) {
|
|
32
|
+
const { src, alt, title } = node.attrs;
|
|
33
|
+
return ['iframe', { src, alt, title, class: node.attrs.class }];
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/NodeImage.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type NodeSpec } from 'prosemirror-model';
|
|
2
|
+
import type { Node as PmNode } from 'prosemirror-model';
|
|
3
|
+
import type { EditorView, NodeViewConstructor } from 'prosemirror-view';
|
|
2
4
|
import { Node } from '@kerebron/editor';
|
|
5
|
+
import type { CoreEditor } from '@kerebron/editor';
|
|
3
6
|
|
|
4
7
|
export class NodeImage extends Node {
|
|
5
8
|
override name = 'image';
|
|
@@ -12,6 +15,8 @@ export class NodeImage extends Node {
|
|
|
12
15
|
src: {},
|
|
13
16
|
alt: { default: null },
|
|
14
17
|
title: { default: null },
|
|
18
|
+
width: { default: null },
|
|
19
|
+
height: { default: null },
|
|
15
20
|
},
|
|
16
21
|
group: 'inline',
|
|
17
22
|
draggable: true,
|
|
@@ -23,14 +28,216 @@ export class NodeImage extends Node {
|
|
|
23
28
|
src: dom.getAttribute('src'),
|
|
24
29
|
title: dom.getAttribute('title'),
|
|
25
30
|
alt: dom.getAttribute('alt'),
|
|
31
|
+
width: dom.getAttribute('width') || dom.style.width || null,
|
|
32
|
+
height: dom.getAttribute('height') || dom.style.height || null,
|
|
26
33
|
};
|
|
27
34
|
},
|
|
28
35
|
},
|
|
29
36
|
],
|
|
30
37
|
toDOM(node) {
|
|
31
|
-
const { src, alt, title } = node.attrs;
|
|
32
|
-
|
|
38
|
+
const { src, alt, title, width, height } = node.attrs;
|
|
39
|
+
const attrs: Record<string, string> = { src };
|
|
40
|
+
if (alt) attrs.alt = alt;
|
|
41
|
+
if (title) attrs.title = title;
|
|
42
|
+
if (width) attrs.width = width;
|
|
43
|
+
if (height) attrs.height = height;
|
|
44
|
+
return ['img', attrs];
|
|
33
45
|
},
|
|
34
46
|
};
|
|
35
47
|
}
|
|
48
|
+
|
|
49
|
+
override getNodeView(editor: CoreEditor): NodeViewConstructor {
|
|
50
|
+
return (node: PmNode, view: EditorView, getPos) => {
|
|
51
|
+
// Create wrapper div for the image with resize handles
|
|
52
|
+
const wrapper = document.createElement('span');
|
|
53
|
+
wrapper.className = 'kb-image-wrapper';
|
|
54
|
+
wrapper.contentEditable = 'false';
|
|
55
|
+
|
|
56
|
+
// Create the image element
|
|
57
|
+
const img = document.createElement('img');
|
|
58
|
+
img.src = node.attrs.src;
|
|
59
|
+
if (node.attrs.alt) img.alt = node.attrs.alt;
|
|
60
|
+
if (node.attrs.title) img.title = node.attrs.title;
|
|
61
|
+
if (node.attrs.width) {
|
|
62
|
+
img.style.width = typeof node.attrs.width === 'number'
|
|
63
|
+
? `${node.attrs.width}px`
|
|
64
|
+
: node.attrs.width;
|
|
65
|
+
}
|
|
66
|
+
if (node.attrs.height) {
|
|
67
|
+
img.style.height = typeof node.attrs.height === 'number'
|
|
68
|
+
? `${node.attrs.height}px`
|
|
69
|
+
: node.attrs.height;
|
|
70
|
+
}
|
|
71
|
+
img.draggable = false;
|
|
72
|
+
|
|
73
|
+
wrapper.appendChild(img);
|
|
74
|
+
|
|
75
|
+
// Create resize handles
|
|
76
|
+
const positions = ['nw', 'ne', 'sw', 'se'] as const;
|
|
77
|
+
const handles: HTMLElement[] = [];
|
|
78
|
+
|
|
79
|
+
for (const pos of positions) {
|
|
80
|
+
const handle = document.createElement('span');
|
|
81
|
+
handle.className =
|
|
82
|
+
`kb-image-resize-handle kb-image-resize-handle-${pos}`;
|
|
83
|
+
handle.dataset.position = pos;
|
|
84
|
+
handles.push(handle);
|
|
85
|
+
wrapper.appendChild(handle);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let isResizing = false;
|
|
89
|
+
let startX = 0;
|
|
90
|
+
let startY = 0;
|
|
91
|
+
let startWidth = 0;
|
|
92
|
+
let startHeight = 0;
|
|
93
|
+
let aspectRatio = 1;
|
|
94
|
+
let activeHandle: string | null = null;
|
|
95
|
+
|
|
96
|
+
const onMouseDown = (e: MouseEvent) => {
|
|
97
|
+
const target = e.target as HTMLElement;
|
|
98
|
+
if (!target.classList.contains('kb-image-resize-handle')) return;
|
|
99
|
+
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
e.stopPropagation();
|
|
102
|
+
|
|
103
|
+
isResizing = true;
|
|
104
|
+
activeHandle = target.dataset.position || null;
|
|
105
|
+
startX = e.clientX;
|
|
106
|
+
startY = e.clientY;
|
|
107
|
+
|
|
108
|
+
const rect = img.getBoundingClientRect();
|
|
109
|
+
startWidth = rect.width;
|
|
110
|
+
startHeight = rect.height;
|
|
111
|
+
aspectRatio = startWidth / startHeight;
|
|
112
|
+
|
|
113
|
+
wrapper.classList.add('kb-image-resizing');
|
|
114
|
+
|
|
115
|
+
document.addEventListener('mousemove', onMouseMove);
|
|
116
|
+
document.addEventListener('mouseup', onMouseUp);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const onMouseMove = (e: MouseEvent) => {
|
|
120
|
+
if (!isResizing) return;
|
|
121
|
+
|
|
122
|
+
const deltaX = e.clientX - startX;
|
|
123
|
+
const deltaY = e.clientY - startY;
|
|
124
|
+
|
|
125
|
+
let newWidth = startWidth;
|
|
126
|
+
let newHeight = startHeight;
|
|
127
|
+
|
|
128
|
+
// Calculate new dimensions based on which handle is being dragged
|
|
129
|
+
switch (activeHandle) {
|
|
130
|
+
case 'se':
|
|
131
|
+
newWidth = startWidth + deltaX;
|
|
132
|
+
newHeight = e.shiftKey
|
|
133
|
+
? startHeight + deltaY
|
|
134
|
+
: newWidth / aspectRatio;
|
|
135
|
+
break;
|
|
136
|
+
case 'sw':
|
|
137
|
+
newWidth = startWidth - deltaX;
|
|
138
|
+
newHeight = e.shiftKey
|
|
139
|
+
? startHeight + deltaY
|
|
140
|
+
: newWidth / aspectRatio;
|
|
141
|
+
break;
|
|
142
|
+
case 'ne':
|
|
143
|
+
newWidth = startWidth + deltaX;
|
|
144
|
+
newHeight = e.shiftKey
|
|
145
|
+
? startHeight - deltaY
|
|
146
|
+
: newWidth / aspectRatio;
|
|
147
|
+
break;
|
|
148
|
+
case 'nw':
|
|
149
|
+
newWidth = startWidth - deltaX;
|
|
150
|
+
newHeight = e.shiftKey
|
|
151
|
+
? startHeight - deltaY
|
|
152
|
+
: newWidth / aspectRatio;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Ensure minimum size
|
|
157
|
+
newWidth = Math.max(50, newWidth);
|
|
158
|
+
newHeight = Math.max(50, newHeight);
|
|
159
|
+
|
|
160
|
+
img.style.width = `${Math.round(newWidth)}px`;
|
|
161
|
+
img.style.height = `${Math.round(newHeight)}px`;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const onMouseUp = () => {
|
|
165
|
+
if (!isResizing) return;
|
|
166
|
+
|
|
167
|
+
isResizing = false;
|
|
168
|
+
activeHandle = null;
|
|
169
|
+
wrapper.classList.remove('kb-image-resizing');
|
|
170
|
+
|
|
171
|
+
document.removeEventListener('mousemove', onMouseMove);
|
|
172
|
+
document.removeEventListener('mouseup', onMouseUp);
|
|
173
|
+
|
|
174
|
+
// Get the new dimensions and update the node
|
|
175
|
+
const newWidth = Math.round(img.getBoundingClientRect().width);
|
|
176
|
+
const newHeight = Math.round(img.getBoundingClientRect().height);
|
|
177
|
+
|
|
178
|
+
const pos = getPos();
|
|
179
|
+
if (typeof pos === 'number') {
|
|
180
|
+
const tr = view.state.tr.setNodeMarkup(pos, undefined, {
|
|
181
|
+
...node.attrs,
|
|
182
|
+
width: `${newWidth}px`,
|
|
183
|
+
height: `${newHeight}px`,
|
|
184
|
+
});
|
|
185
|
+
view.dispatch(tr);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
wrapper.addEventListener('mousedown', onMouseDown);
|
|
190
|
+
|
|
191
|
+
// Add click handler to select the image
|
|
192
|
+
wrapper.addEventListener('click', (e) => {
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
const pos = getPos();
|
|
195
|
+
if (typeof pos === 'number') {
|
|
196
|
+
const $pos = view.state.doc.resolve(pos);
|
|
197
|
+
const selection = view.state.selection.constructor.near($pos);
|
|
198
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
dom: wrapper,
|
|
204
|
+
update: (updatedNode: PmNode) => {
|
|
205
|
+
if (updatedNode.type.name !== 'image') return false;
|
|
206
|
+
|
|
207
|
+
img.src = updatedNode.attrs.src;
|
|
208
|
+
if (updatedNode.attrs.alt) img.alt = updatedNode.attrs.alt;
|
|
209
|
+
if (updatedNode.attrs.title) img.title = updatedNode.attrs.title;
|
|
210
|
+
if (updatedNode.attrs.width) {
|
|
211
|
+
img.style.width = typeof updatedNode.attrs.width === 'number'
|
|
212
|
+
? `${updatedNode.attrs.width}px`
|
|
213
|
+
: updatedNode.attrs.width;
|
|
214
|
+
} else {
|
|
215
|
+
img.style.width = '';
|
|
216
|
+
}
|
|
217
|
+
if (updatedNode.attrs.height) {
|
|
218
|
+
img.style.height = typeof updatedNode.attrs.height === 'number'
|
|
219
|
+
? `${updatedNode.attrs.height}px`
|
|
220
|
+
: updatedNode.attrs.height;
|
|
221
|
+
} else {
|
|
222
|
+
img.style.height = '';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return true;
|
|
226
|
+
},
|
|
227
|
+
destroy: () => {
|
|
228
|
+
wrapper.removeEventListener('mousedown', onMouseDown);
|
|
229
|
+
document.removeEventListener('mousemove', onMouseMove);
|
|
230
|
+
document.removeEventListener('mouseup', onMouseUp);
|
|
231
|
+
},
|
|
232
|
+
stopEvent: (event: Event) => {
|
|
233
|
+
// Allow selection events to pass through
|
|
234
|
+
return event.type === 'mousedown' &&
|
|
235
|
+
(event.target as HTMLElement).classList.contains(
|
|
236
|
+
'kb-image-resize-handle',
|
|
237
|
+
);
|
|
238
|
+
},
|
|
239
|
+
ignoreMutation: () => true,
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
}
|
|
36
243
|
}
|