@prosekit/extensions 0.0.6 → 0.0.8
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/dist/list/style.css +1 -1
- package/dist/prosekit-extensions-blockquote.js +6 -8
- package/dist/prosekit-extensions-bold.js +19 -21
- package/dist/prosekit-extensions-code-block.d.ts +27 -0
- package/dist/prosekit-extensions-code-block.js +123 -0
- package/dist/prosekit-extensions-code.js +3 -5
- package/dist/prosekit-extensions-heading.js +14 -16
- package/dist/prosekit-extensions-italic.js +10 -12
- package/dist/prosekit-extensions-link.d.ts +25 -0
- package/dist/prosekit-extensions-link.js +44 -0
- package/dist/prosekit-extensions-list.js +1 -1
- package/dist/prosekit-extensions-mention.js +27 -29
- package/package.json +23 -5
package/dist/list/style.css
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* ../../node_modules/.pnpm/prosemirror-flat-list@0.
|
1
|
+
/* ../../node_modules/.pnpm/prosemirror-flat-list@0.4.1/node_modules/prosemirror-flat-list/dist/style.css */
|
2
2
|
.prosemirror-flat-list {
|
3
3
|
padding: 0;
|
4
4
|
margin-top: 0;
|
@@ -3,14 +3,12 @@ import { addNodeSpec, defineExtension } from "@prosekit/core";
|
|
3
3
|
function addBlockquoteSpec() {
|
4
4
|
return addNodeSpec({
|
5
5
|
name: "blockquote",
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
return ["blockquote", 0];
|
13
|
-
}
|
6
|
+
content: "block+",
|
7
|
+
group: "block",
|
8
|
+
defining: true,
|
9
|
+
parseDOM: [{ tag: "blockquote" }],
|
10
|
+
toDOM() {
|
11
|
+
return ["blockquote", 0];
|
14
12
|
}
|
15
13
|
});
|
16
14
|
}
|
@@ -9,29 +9,27 @@ import {
|
|
9
9
|
function addBoldSpec() {
|
10
10
|
return addMarkSpec({
|
11
11
|
name: "bold",
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
return typeof value === "string" && /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null;
|
29
|
-
}
|
12
|
+
parseDOM: [
|
13
|
+
{ tag: "strong" },
|
14
|
+
// This works around a Google Docs misbehavior where
|
15
|
+
// pasted content will be inexplicably wrapped in `<b>`
|
16
|
+
// tags with a font-weight normal.
|
17
|
+
{
|
18
|
+
tag: "b",
|
19
|
+
getAttrs: (node) => {
|
20
|
+
return typeof node !== "string" && node.style.fontWeight !== "normal" && null;
|
21
|
+
}
|
22
|
+
},
|
23
|
+
{ style: "font-weight=400", clearMark: (m) => m.type.name == "strong" },
|
24
|
+
{
|
25
|
+
style: "font-weight",
|
26
|
+
getAttrs: (value) => {
|
27
|
+
return typeof value === "string" && /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null;
|
30
28
|
}
|
31
|
-
],
|
32
|
-
toDOM() {
|
33
|
-
return ["em", 0];
|
34
29
|
}
|
30
|
+
],
|
31
|
+
toDOM() {
|
32
|
+
return ["em", 0];
|
35
33
|
}
|
36
34
|
});
|
37
35
|
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import * as _prosekit_core from '@prosekit/core';
|
2
|
+
import { HLJSApi } from 'highlight.js';
|
3
|
+
|
4
|
+
interface CodeBlockAttrs {
|
5
|
+
language?: string;
|
6
|
+
}
|
7
|
+
|
8
|
+
declare function addCodeBlockSpec(): _prosekit_core.Extension<{
|
9
|
+
NODES: "codeBlock";
|
10
|
+
}>;
|
11
|
+
declare function addCodeBlockInputRule(): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
|
12
|
+
declare function addCodeBlockCommands(): _prosekit_core.Extension<{
|
13
|
+
COMMAND_ARGS: {
|
14
|
+
setCodeBlockLanguage: [language: string];
|
15
|
+
};
|
16
|
+
}>;
|
17
|
+
/** @public */
|
18
|
+
declare function addCodeBlock(options?: {
|
19
|
+
hljs?: HLJSApi;
|
20
|
+
}): _prosekit_core.Extension<{
|
21
|
+
NODES: "codeBlock";
|
22
|
+
COMMAND_ARGS: {
|
23
|
+
setCodeBlockLanguage: [language: string];
|
24
|
+
};
|
25
|
+
}>;
|
26
|
+
|
27
|
+
export { CodeBlockAttrs, addCodeBlock, addCodeBlockCommands, addCodeBlockInputRule, addCodeBlockSpec };
|
@@ -0,0 +1,123 @@
|
|
1
|
+
// src/code-block/index.ts
|
2
|
+
import {
|
3
|
+
addCommands,
|
4
|
+
addInputRule,
|
5
|
+
addNodeSpec,
|
6
|
+
defineExtension,
|
7
|
+
getNodeType
|
8
|
+
} from "@prosekit/core";
|
9
|
+
import { textblockTypeInputRule } from "@prosekit/pm/inputrules";
|
10
|
+
|
11
|
+
// src/code-block/code-block-highlight.ts
|
12
|
+
import { addPlugin } from "@prosekit/core";
|
13
|
+
import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
|
14
|
+
import { DecorationSet } from "@prosekit/pm/view";
|
15
|
+
import { getHighlightDecorations } from "prosemirror-highlightjs";
|
16
|
+
function addCodeBlockHighlight(options) {
|
17
|
+
const hljs = options.hljs;
|
18
|
+
const plugin = new ProseMirrorPlugin({
|
19
|
+
key,
|
20
|
+
state: {
|
21
|
+
init(_config, state) {
|
22
|
+
const decorations = hljs ? getHighlightDecorations(
|
23
|
+
state.doc,
|
24
|
+
hljs,
|
25
|
+
blockTypes,
|
26
|
+
languageExtractor
|
27
|
+
) : [];
|
28
|
+
return DecorationSet.create(state.doc, decorations);
|
29
|
+
},
|
30
|
+
apply(tr, set) {
|
31
|
+
if (!tr.docChanged) {
|
32
|
+
return set.map(tr.mapping, tr.doc);
|
33
|
+
}
|
34
|
+
const decorations = hljs ? getHighlightDecorations(tr.doc, hljs, blockTypes, languageExtractor) : [];
|
35
|
+
return DecorationSet.create(tr.doc, decorations);
|
36
|
+
}
|
37
|
+
},
|
38
|
+
props: {
|
39
|
+
decorations(state) {
|
40
|
+
return key.getState(state);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
});
|
44
|
+
return addPlugin({
|
45
|
+
plugins: () => {
|
46
|
+
return [plugin];
|
47
|
+
}
|
48
|
+
});
|
49
|
+
}
|
50
|
+
var key = new PluginKey("prosekit-code-block-highlight");
|
51
|
+
var blockTypes = ["codeBlock"];
|
52
|
+
function languageExtractor(node) {
|
53
|
+
return node.attrs.language || "javascript";
|
54
|
+
}
|
55
|
+
|
56
|
+
// src/code-block/index.ts
|
57
|
+
function addCodeBlockSpec() {
|
58
|
+
return addNodeSpec({
|
59
|
+
name: "codeBlock",
|
60
|
+
content: "text*",
|
61
|
+
group: "block",
|
62
|
+
code: true,
|
63
|
+
defining: true,
|
64
|
+
marks: "",
|
65
|
+
attrs: { language: { default: "" } },
|
66
|
+
parseDOM: [
|
67
|
+
{
|
68
|
+
tag: "pre",
|
69
|
+
preserveWhitespace: "full",
|
70
|
+
getAttrs: (node) => ({
|
71
|
+
language: node.getAttribute("data-language") || ""
|
72
|
+
})
|
73
|
+
}
|
74
|
+
],
|
75
|
+
toDOM(node) {
|
76
|
+
const attrs = node.attrs;
|
77
|
+
return [
|
78
|
+
"pre",
|
79
|
+
{ "data-language": attrs.language, class: "hljs" },
|
80
|
+
["code", 0]
|
81
|
+
];
|
82
|
+
}
|
83
|
+
});
|
84
|
+
}
|
85
|
+
function addCodeBlockInputRule() {
|
86
|
+
return addInputRule(({ schema }) => {
|
87
|
+
const nodeType = getNodeType(schema, "codeBlock");
|
88
|
+
const getAttrs = (match) => {
|
89
|
+
return { language: match[1] || "" };
|
90
|
+
};
|
91
|
+
const inputRule = textblockTypeInputRule(/^```(\S*)\s$/, nodeType, getAttrs);
|
92
|
+
return [inputRule];
|
93
|
+
});
|
94
|
+
}
|
95
|
+
function addCodeBlockCommands() {
|
96
|
+
return addCommands({
|
97
|
+
setCodeBlockLanguage: (language) => (state, dispatch) => {
|
98
|
+
const pos = state.selection.$from.before();
|
99
|
+
const codeBlock = state.doc.nodeAt(pos);
|
100
|
+
if (!codeBlock || codeBlock.type.name !== "codeBlock") {
|
101
|
+
return false;
|
102
|
+
}
|
103
|
+
const { tr } = state;
|
104
|
+
tr.setNodeMarkup(pos, void 0, { language });
|
105
|
+
dispatch == null ? void 0 : dispatch(tr);
|
106
|
+
return true;
|
107
|
+
}
|
108
|
+
});
|
109
|
+
}
|
110
|
+
function addCodeBlock(options) {
|
111
|
+
return defineExtension([
|
112
|
+
addCodeBlockSpec(),
|
113
|
+
addCodeBlockInputRule(),
|
114
|
+
addCodeBlockHighlight({ hljs: options == null ? void 0 : options.hljs }),
|
115
|
+
addCodeBlockCommands()
|
116
|
+
]);
|
117
|
+
}
|
118
|
+
export {
|
119
|
+
addCodeBlock,
|
120
|
+
addCodeBlockCommands,
|
121
|
+
addCodeBlockInputRule,
|
122
|
+
addCodeBlockSpec
|
123
|
+
};
|
@@ -3,11 +3,9 @@ import { addMarkSpec, defineExtension } from "@prosekit/core";
|
|
3
3
|
function addCodeSpec() {
|
4
4
|
return addMarkSpec({
|
5
5
|
name: "code",
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
return ["code", 0];
|
10
|
-
}
|
6
|
+
parseDOM: [{ tag: "code" }],
|
7
|
+
toDOM() {
|
8
|
+
return ["code", 0];
|
11
9
|
}
|
12
10
|
});
|
13
11
|
}
|
@@ -11,22 +11,20 @@ import { textblockTypeInputRule } from "@prosekit/pm/inputrules";
|
|
11
11
|
function addHeadingSpec() {
|
12
12
|
return addNodeSpec({
|
13
13
|
name: "heading",
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
return [`h${node.attrs.level}`, 0];
|
29
|
-
}
|
14
|
+
attrs: { level: { default: 1 } },
|
15
|
+
content: "inline*",
|
16
|
+
group: "block",
|
17
|
+
defining: true,
|
18
|
+
parseDOM: [
|
19
|
+
{ tag: "h1", attrs: { level: 1 } },
|
20
|
+
{ tag: "h2", attrs: { level: 2 } },
|
21
|
+
{ tag: "h3", attrs: { level: 3 } },
|
22
|
+
{ tag: "h4", attrs: { level: 4 } },
|
23
|
+
{ tag: "h5", attrs: { level: 5 } },
|
24
|
+
{ tag: "h6", attrs: { level: 6 } }
|
25
|
+
],
|
26
|
+
toDOM(node) {
|
27
|
+
return [`h${node.attrs.level}`, 0];
|
30
28
|
}
|
31
29
|
});
|
32
30
|
}
|
@@ -9,19 +9,17 @@ import {
|
|
9
9
|
function addItalicSpec() {
|
10
10
|
return addMarkSpec({
|
11
11
|
name: "italic",
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
clearMark: (m) => m.type.name === "italic"
|
20
|
-
}
|
21
|
-
],
|
22
|
-
toDOM() {
|
23
|
-
return ["em", 0];
|
12
|
+
parseDOM: [
|
13
|
+
{ tag: "i" },
|
14
|
+
{ tag: "em" },
|
15
|
+
{ style: "font-style=italic" },
|
16
|
+
{
|
17
|
+
style: "font-style=normal",
|
18
|
+
clearMark: (m) => m.type.name === "italic"
|
24
19
|
}
|
20
|
+
],
|
21
|
+
toDOM() {
|
22
|
+
return ["em", 0];
|
25
23
|
}
|
26
24
|
});
|
27
25
|
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import * as _prosekit_core from '@prosekit/core';
|
2
|
+
|
3
|
+
/** @public */
|
4
|
+
interface LinkAttrs {
|
5
|
+
href: string;
|
6
|
+
}
|
7
|
+
declare function addLinkSpec(): _prosekit_core.Extension<{
|
8
|
+
MARKS: "link";
|
9
|
+
}>;
|
10
|
+
declare function addLinkCommands(): _prosekit_core.Extension<{
|
11
|
+
COMMAND_ARGS: {
|
12
|
+
addLink: [attrs: LinkAttrs];
|
13
|
+
toggleLink: [attrs: LinkAttrs];
|
14
|
+
};
|
15
|
+
}>;
|
16
|
+
/** @public */
|
17
|
+
declare function addItalic(): _prosekit_core.Extension<{
|
18
|
+
MARKS: "link";
|
19
|
+
COMMAND_ARGS: {
|
20
|
+
addLink: [attrs: LinkAttrs];
|
21
|
+
toggleLink: [attrs: LinkAttrs];
|
22
|
+
};
|
23
|
+
}>;
|
24
|
+
|
25
|
+
export { LinkAttrs, addItalic, addLinkCommands, addLinkSpec };
|
@@ -0,0 +1,44 @@
|
|
1
|
+
// src/link/index.ts
|
2
|
+
import {
|
3
|
+
addCommands,
|
4
|
+
addMark,
|
5
|
+
addMarkSpec,
|
6
|
+
defineExtension,
|
7
|
+
toggleMark
|
8
|
+
} from "@prosekit/core";
|
9
|
+
function addLinkSpec() {
|
10
|
+
return addMarkSpec({
|
11
|
+
name: "link",
|
12
|
+
parseDOM: [
|
13
|
+
{
|
14
|
+
tag: "a[href]",
|
15
|
+
getAttrs: (dom) => {
|
16
|
+
return {
|
17
|
+
href: dom.getAttribute("href")
|
18
|
+
};
|
19
|
+
}
|
20
|
+
}
|
21
|
+
],
|
22
|
+
attrs: {
|
23
|
+
href: {}
|
24
|
+
},
|
25
|
+
toDOM(node) {
|
26
|
+
const { href } = node.attrs;
|
27
|
+
return ["a", { href }, 0];
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}
|
31
|
+
function addLinkCommands() {
|
32
|
+
return addCommands({
|
33
|
+
addLink: (attrs) => addMark({ type: "link", attrs }),
|
34
|
+
toggleLink: (attrs) => toggleMark({ type: "link", attrs })
|
35
|
+
});
|
36
|
+
}
|
37
|
+
function addItalic() {
|
38
|
+
return defineExtension([addLinkSpec(), addLinkCommands()]);
|
39
|
+
}
|
40
|
+
export {
|
41
|
+
addItalic,
|
42
|
+
addLinkCommands,
|
43
|
+
addLinkSpec
|
44
|
+
};
|
@@ -13,7 +13,7 @@ import {
|
|
13
13
|
listKeymap
|
14
14
|
} from "prosemirror-flat-list";
|
15
15
|
function addListSpec() {
|
16
|
-
return addNodeSpec({ name: "list"
|
16
|
+
return addNodeSpec({ ...createListSpec(), name: "list" });
|
17
17
|
}
|
18
18
|
function addListPlugins() {
|
19
19
|
return addPlugin({ plugins: ({ schema }) => createListPlugins({ schema }) });
|
@@ -3,36 +3,34 @@ import { addNodeSpec, defineExtension } from "@prosekit/core";
|
|
3
3
|
function addMentionSpec() {
|
4
4
|
return addNodeSpec({
|
5
5
|
name: "mention",
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
})
|
24
|
-
}
|
25
|
-
],
|
26
|
-
toDOM(node) {
|
27
|
-
return [
|
28
|
-
"span",
|
29
|
-
{
|
30
|
-
"data-id": node.attrs.id.toString(),
|
31
|
-
"data-mention": node.attrs.kind.toString()
|
32
|
-
},
|
33
|
-
node.attrs.value.toString()
|
34
|
-
];
|
6
|
+
atom: true,
|
7
|
+
group: "inline",
|
8
|
+
attrs: {
|
9
|
+
id: {},
|
10
|
+
value: {},
|
11
|
+
kind: { default: "" }
|
12
|
+
},
|
13
|
+
inline: true,
|
14
|
+
leafText: (node) => node.attrs.value.toString(),
|
15
|
+
parseDOM: [
|
16
|
+
{
|
17
|
+
tag: `span[data-mention]`,
|
18
|
+
getAttrs: (dom) => ({
|
19
|
+
id: dom.getAttribute("data-id") || "",
|
20
|
+
kind: dom.getAttribute("data-mention") || "",
|
21
|
+
value: dom.textContent || ""
|
22
|
+
})
|
35
23
|
}
|
24
|
+
],
|
25
|
+
toDOM(node) {
|
26
|
+
return [
|
27
|
+
"span",
|
28
|
+
{
|
29
|
+
"data-id": node.attrs.id.toString(),
|
30
|
+
"data-mention": node.attrs.kind.toString()
|
31
|
+
},
|
32
|
+
node.attrs.value.toString()
|
33
|
+
];
|
36
34
|
}
|
37
35
|
});
|
38
36
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/extensions",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.
|
4
|
+
"version": "0.0.8",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -50,6 +50,11 @@
|
|
50
50
|
"import": "./dist/prosekit-extensions-code.js",
|
51
51
|
"default": "./dist/prosekit-extensions-code.js"
|
52
52
|
},
|
53
|
+
"./code-block": {
|
54
|
+
"types": "./dist/prosekit-extensions-code-block.d.ts",
|
55
|
+
"import": "./dist/prosekit-extensions-code-block.js",
|
56
|
+
"default": "./dist/prosekit-extensions-code-block.js"
|
57
|
+
},
|
53
58
|
"./heading": {
|
54
59
|
"types": "./dist/prosekit-extensions-heading.d.ts",
|
55
60
|
"import": "./dist/prosekit-extensions-heading.js",
|
@@ -60,6 +65,11 @@
|
|
60
65
|
"import": "./dist/prosekit-extensions-italic.js",
|
61
66
|
"default": "./dist/prosekit-extensions-italic.js"
|
62
67
|
},
|
68
|
+
"./link": {
|
69
|
+
"types": "./dist/prosekit-extensions-link.d.ts",
|
70
|
+
"import": "./dist/prosekit-extensions-link.js",
|
71
|
+
"default": "./dist/prosekit-extensions-link.js"
|
72
|
+
},
|
63
73
|
"./list": {
|
64
74
|
"types": "./dist/prosekit-extensions-list.d.ts",
|
65
75
|
"import": "./dist/prosekit-extensions-list.js",
|
@@ -91,15 +101,17 @@
|
|
91
101
|
"dist"
|
92
102
|
],
|
93
103
|
"dependencies": {
|
94
|
-
"@prosekit/core": "^0.0.
|
104
|
+
"@prosekit/core": "^0.0.7",
|
95
105
|
"@prosekit/pm": "^0.0.3",
|
96
|
-
"
|
106
|
+
"highlight.js": "^11.8.0",
|
107
|
+
"prosemirror-flat-list": "^0.4.1",
|
108
|
+
"prosemirror-highlightjs": "^0.9.1"
|
97
109
|
},
|
98
110
|
"devDependencies": {
|
99
111
|
"@prosekit/dev": "*",
|
100
|
-
"tsup": "^7.
|
112
|
+
"tsup": "^7.2.0",
|
101
113
|
"typescript": "^5.1.6",
|
102
|
-
"vitest": "^0.
|
114
|
+
"vitest": "^0.34.1"
|
103
115
|
},
|
104
116
|
"scripts": {
|
105
117
|
"build:tsup": "tsup",
|
@@ -123,12 +135,18 @@
|
|
123
135
|
"code": [
|
124
136
|
"./dist/prosekit-extensions-code.d.ts"
|
125
137
|
],
|
138
|
+
"code-block": [
|
139
|
+
"./dist/prosekit-extensions-code-block.d.ts"
|
140
|
+
],
|
126
141
|
"heading": [
|
127
142
|
"./dist/prosekit-extensions-heading.d.ts"
|
128
143
|
],
|
129
144
|
"italic": [
|
130
145
|
"./dist/prosekit-extensions-italic.d.ts"
|
131
146
|
],
|
147
|
+
"link": [
|
148
|
+
"./dist/prosekit-extensions-link.d.ts"
|
149
|
+
],
|
132
150
|
"list": [
|
133
151
|
"./dist/prosekit-extensions-list.d.ts"
|
134
152
|
],
|