@kerebron/extension-basic-editor 0.9.3 → 0.9.4
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/esm/NodeCodeBlock.d.ts +12 -2
- package/esm/NodeCodeBlock.js +35 -7
- package/esm/NodeCodeBlock.js.map +1 -1
- package/esm/pairing/PairNodesPlugin.js +4 -2
- package/esm/pairing/PairNodesPlugin.js.map +1 -1
- package/package.json +6 -5
- package/src/NodeCodeBlock.ts +56 -9
- package/src/pairing/PairNodesPlugin.ts +4 -2
package/esm/NodeCodeBlock.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import type { NodeSpec, NodeType } from 'prosemirror-model';
|
|
2
2
|
import { Node } from '@kerebron/editor';
|
|
3
|
-
import { type
|
|
3
|
+
import { type CommandFactories, type CommandShortcuts } from '@kerebron/editor/commands';
|
|
4
|
+
declare module '@kerebron/editor/commands' {
|
|
5
|
+
interface Commands<ReturnType = any> {
|
|
6
|
+
/**
|
|
7
|
+
* Convert a ``` or ```lang fence paragraph into a code block.
|
|
8
|
+
* Bound to Enter for paragraphs that consist solely of a fence.
|
|
9
|
+
*/
|
|
10
|
+
setCodeBlockFromFence: () => ReturnType;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
4
13
|
export declare class NodeCodeBlock extends Node {
|
|
5
14
|
name: string;
|
|
6
15
|
getNodeSpec(): NodeSpec;
|
|
7
|
-
|
|
16
|
+
getCommandFactories(editor: Parameters<Node['getCommandFactories']>[0], type: NodeType): Partial<CommandFactories>;
|
|
17
|
+
getKeyboardShortcuts(): Partial<CommandShortcuts>;
|
|
8
18
|
}
|
package/esm/NodeCodeBlock.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Node } from '@kerebron/editor';
|
|
2
|
-
import {
|
|
2
|
+
import { normalizeLang } from '@kerebron/wasm';
|
|
3
|
+
const FENCE_RE = /^```([a-zA-Z0-9+#-]*)$/;
|
|
3
4
|
export class NodeCodeBlock extends Node {
|
|
4
5
|
name = 'code_block';
|
|
5
6
|
getNodeSpec() {
|
|
@@ -40,12 +41,39 @@ export class NodeCodeBlock extends Node {
|
|
|
40
41
|
},
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
getCommandFactories(editor, type) {
|
|
45
|
+
return {
|
|
46
|
+
'setCodeBlockFromFence': () => {
|
|
47
|
+
return (state, dispatch) => {
|
|
48
|
+
const { $from } = state.selection;
|
|
49
|
+
const parent = $from.parent;
|
|
50
|
+
if (!state.selection.empty || parent.type.name !== 'paragraph') {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const match = FENCE_RE.exec(parent.textContent);
|
|
54
|
+
if (!match)
|
|
55
|
+
return false;
|
|
56
|
+
if (!dispatch)
|
|
57
|
+
return true;
|
|
58
|
+
const start = $from.before();
|
|
59
|
+
const end = $from.after();
|
|
60
|
+
const lang = match[1] ? normalizeLang(match[1]) : undefined;
|
|
61
|
+
const tr = state.tr;
|
|
62
|
+
const node = type.createAndFill({ lang, id: crypto.randomUUID() });
|
|
63
|
+
if (node) {
|
|
64
|
+
tr.insert(tr.mapping.map(start), node);
|
|
65
|
+
tr.delete(tr.mapping.map(start), tr.mapping.map(end));
|
|
66
|
+
}
|
|
67
|
+
dispatch(tr);
|
|
68
|
+
return true;
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
getKeyboardShortcuts() {
|
|
74
|
+
return {
|
|
75
|
+
'Enter': 'setCodeBlockFromFence',
|
|
76
|
+
};
|
|
49
77
|
}
|
|
50
78
|
}
|
|
51
79
|
//# sourceMappingURL=NodeCodeBlock.js.map
|
package/esm/NodeCodeBlock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeCodeBlock.js","sourceRoot":"","sources":["../src/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,KAAK,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;oBACxD,CAAC;oBAED,QAAQ,CAAC,EAAE,CAAC,CAAC;oBACb,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;IAEQ,oBAAoB;QAC3B,OAAO;YACL,OAAO,EAAE,uBAAuB;SACjC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -8,7 +8,9 @@ export const createPairingPlugin = (types) => {
|
|
|
8
8
|
for (const tr of transactions) {
|
|
9
9
|
if (!tr.docChanged)
|
|
10
10
|
continue;
|
|
11
|
-
for (
|
|
11
|
+
for (let idx = 0; idx < tr.steps.length; idx++) {
|
|
12
|
+
const step = tr.steps[idx];
|
|
13
|
+
const doc = tr.docs[idx];
|
|
12
14
|
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
|
|
13
15
|
continue;
|
|
14
16
|
}
|
|
@@ -20,7 +22,7 @@ export const createPairingPlugin = (types) => {
|
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
if (step.from != null && step.to != null && step.from !== step.to) {
|
|
23
|
-
|
|
25
|
+
doc.nodesBetween(step.from, step.to, (node) => {
|
|
24
26
|
if (types.includes(node.type.name)) {
|
|
25
27
|
typesToRebuild.add(node.type.name);
|
|
26
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PairNodesPlugin.js","sourceRoot":"","sources":["../../src/pairing/PairNodesPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAe,EAAE,EAAE;IACrD,OAAO,IAAI,MAAM,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|
2
2
|
"name": "@kerebron/extension-basic-editor",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"module": "./esm/BasicEditorKit.js",
|
|
6
6
|
"exports": {
|
|
@@ -182,11 +182,12 @@
|
|
|
182
182
|
"assets"
|
|
183
183
|
],
|
|
184
184
|
"dependencies": {
|
|
185
|
-
"@kerebron/editor": "0.9.
|
|
186
|
-
"
|
|
185
|
+
"@kerebron/editor": "0.9.4",
|
|
186
|
+
"@kerebron/wasm": "0.9.4",
|
|
187
|
+
"prosemirror-model": "1.25.13",
|
|
187
188
|
"prosemirror-state": "1.4.4",
|
|
188
|
-
"prosemirror-transform": "1.
|
|
189
|
-
"prosemirror-view": "1.
|
|
189
|
+
"prosemirror-transform": "1.12.7",
|
|
190
|
+
"prosemirror-view": "1.44.0",
|
|
190
191
|
"temml": "0.13.4"
|
|
191
192
|
},
|
|
192
193
|
"devDependencies": {
|
package/src/NodeCodeBlock.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import type { NodeSpec, NodeType } from 'prosemirror-model';
|
|
2
2
|
import { Node } from '@kerebron/editor';
|
|
3
3
|
import {
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
} from '@kerebron/editor/
|
|
4
|
+
type CommandFactories,
|
|
5
|
+
type CommandShortcuts,
|
|
6
|
+
} from '@kerebron/editor/commands';
|
|
7
|
+
import { normalizeLang } from '@kerebron/wasm';
|
|
8
|
+
|
|
9
|
+
declare module '@kerebron/editor/commands' {
|
|
10
|
+
interface Commands<ReturnType = any> {
|
|
11
|
+
/**
|
|
12
|
+
* Convert a ``` or ```lang fence paragraph into a code block.
|
|
13
|
+
* Bound to Enter for paragraphs that consist solely of a fence.
|
|
14
|
+
*/
|
|
15
|
+
setCodeBlockFromFence: () => ReturnType;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const FENCE_RE = /^```([a-zA-Z0-9+#-]*)$/;
|
|
7
20
|
|
|
8
21
|
export class NodeCodeBlock extends Node {
|
|
9
22
|
override name = 'code_block';
|
|
@@ -50,11 +63,45 @@ export class NodeCodeBlock extends Node {
|
|
|
50
63
|
};
|
|
51
64
|
}
|
|
52
65
|
|
|
53
|
-
override
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
override getCommandFactories(
|
|
67
|
+
editor: Parameters<Node['getCommandFactories']>[0],
|
|
68
|
+
type: NodeType,
|
|
69
|
+
): Partial<CommandFactories> {
|
|
70
|
+
return {
|
|
71
|
+
'setCodeBlockFromFence': () => {
|
|
72
|
+
return (state, dispatch) => {
|
|
73
|
+
const { $from } = state.selection;
|
|
74
|
+
const parent = $from.parent;
|
|
75
|
+
if (!state.selection.empty || parent.type.name !== 'paragraph') {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const match = FENCE_RE.exec(parent.textContent);
|
|
80
|
+
if (!match) return false;
|
|
81
|
+
if (!dispatch) return true;
|
|
82
|
+
|
|
83
|
+
const start = $from.before();
|
|
84
|
+
const end = $from.after();
|
|
85
|
+
const lang = match[1] ? normalizeLang(match[1]) : undefined;
|
|
86
|
+
|
|
87
|
+
const tr = state.tr;
|
|
88
|
+
|
|
89
|
+
const node = type.createAndFill({ lang, id: crypto.randomUUID() });
|
|
90
|
+
if (node) {
|
|
91
|
+
tr.insert(tr.mapping.map(start), node);
|
|
92
|
+
tr.delete(tr.mapping.map(start), tr.mapping.map(end));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
dispatch(tr);
|
|
96
|
+
return true;
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
override getKeyboardShortcuts(): Partial<CommandShortcuts> {
|
|
103
|
+
return {
|
|
104
|
+
'Enter': 'setCodeBlockFromFence',
|
|
105
|
+
};
|
|
59
106
|
}
|
|
60
107
|
}
|
|
@@ -14,7 +14,9 @@ export const createPairingPlugin = (types: string[]) => {
|
|
|
14
14
|
for (const tr of transactions) {
|
|
15
15
|
if (!tr.docChanged) continue;
|
|
16
16
|
|
|
17
|
-
for (
|
|
17
|
+
for (let idx = 0; idx < tr.steps.length; idx++) {
|
|
18
|
+
const step = tr.steps[idx];
|
|
19
|
+
const doc = tr.docs[idx];
|
|
18
20
|
if (
|
|
19
21
|
!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)
|
|
20
22
|
) {
|
|
@@ -30,7 +32,7 @@ export const createPairingPlugin = (types: string[]) => {
|
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
if (step.from != null && step.to != null && step.from !== step.to) {
|
|
33
|
-
|
|
35
|
+
doc.nodesBetween(step.from, step.to, (node) => {
|
|
34
36
|
if (types.includes(node.type.name)) {
|
|
35
37
|
typesToRebuild.add(node.type.name);
|
|
36
38
|
}
|