@prosekit/extensions 0.0.5 → 0.0.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/dist/list/style.css +1 -1
- package/dist/prosekit-extensions-autocomplete.js +17 -5
- package/dist/prosekit-extensions-blockquote.js +6 -8
- package/dist/prosekit-extensions-bold.js +19 -21
- 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.d.ts +21 -0
- package/dist/prosekit-extensions-mention.js +43 -0
- package/dist/prosekit-extensions-placeholder.js +3 -1
- package/package.json +21 -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;
|
@@ -33,12 +33,12 @@ function setTrMeta(tr, meta) {
|
|
33
33
|
return tr.setMeta(pluginKey, meta);
|
34
34
|
}
|
35
35
|
var pluginKey = new PluginKey(
|
36
|
-
"
|
36
|
+
"prosekit-autocomplete"
|
37
37
|
);
|
38
38
|
|
39
39
|
// src/autocomplete/plugin.ts
|
40
40
|
function createAutocompletePlugin({
|
41
|
-
|
41
|
+
getRules
|
42
42
|
}) {
|
43
43
|
return new Plugin({
|
44
44
|
key: pluginKey,
|
@@ -55,7 +55,7 @@ function createAutocompletePlugin({
|
|
55
55
|
if (meta) {
|
56
56
|
return meta;
|
57
57
|
}
|
58
|
-
const nextValue = calcPluginState(newState,
|
58
|
+
const nextValue = calcPluginState(newState, getRules());
|
59
59
|
if (nextValue.active && prevValue.ignore != null && ((_a = nextValue.matching) == null ? void 0 : _a.from) === prevValue.ignore) {
|
60
60
|
return prevValue;
|
61
61
|
}
|
@@ -167,8 +167,20 @@ function addAutocomplete(rule) {
|
|
167
167
|
return autocompleteFacet.extension([rule]);
|
168
168
|
}
|
169
169
|
var autocompleteFacet = Facet.define({
|
170
|
-
|
171
|
-
|
170
|
+
slot: () => {
|
171
|
+
let localRules = [];
|
172
|
+
const getRules = () => localRules;
|
173
|
+
return {
|
174
|
+
create: (rules) => {
|
175
|
+
localRules = rules;
|
176
|
+
const plugin = createAutocompletePlugin({ getRules });
|
177
|
+
return () => [plugin];
|
178
|
+
},
|
179
|
+
update: (rules) => {
|
180
|
+
localRules = rules;
|
181
|
+
return null;
|
182
|
+
}
|
183
|
+
};
|
172
184
|
},
|
173
185
|
next: pluginFacet
|
174
186
|
});
|
@@ -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
|
}
|
@@ -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 }) });
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import * as _prosekit_core from '@prosekit/core';
|
2
|
+
|
3
|
+
interface MentionAttrs {
|
4
|
+
id: string;
|
5
|
+
kind: string;
|
6
|
+
value: string;
|
7
|
+
}
|
8
|
+
/**
|
9
|
+
* @public
|
10
|
+
*/
|
11
|
+
declare function addMentionSpec(): _prosekit_core.Extension<{
|
12
|
+
NODES: "mention";
|
13
|
+
}>;
|
14
|
+
/**
|
15
|
+
* @public
|
16
|
+
*/
|
17
|
+
declare function addMention(): _prosekit_core.Extension<{
|
18
|
+
NODES: "mention";
|
19
|
+
}>;
|
20
|
+
|
21
|
+
export { MentionAttrs, addMention, addMentionSpec };
|
@@ -0,0 +1,43 @@
|
|
1
|
+
// src/mention/index.ts
|
2
|
+
import { addNodeSpec, defineExtension } from "@prosekit/core";
|
3
|
+
function addMentionSpec() {
|
4
|
+
return addNodeSpec({
|
5
|
+
name: "mention",
|
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
|
+
})
|
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
|
+
];
|
34
|
+
}
|
35
|
+
});
|
36
|
+
}
|
37
|
+
function addMention() {
|
38
|
+
return defineExtension([addMentionSpec()]);
|
39
|
+
}
|
40
|
+
export {
|
41
|
+
addMention,
|
42
|
+
addMentionSpec
|
43
|
+
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// src/placeholder/index.ts
|
2
2
|
import { addPlugin } from "@prosekit/core";
|
3
3
|
import "@prosekit/pm/model";
|
4
|
-
import { Plugin } from "@prosekit/pm/state";
|
4
|
+
import { Plugin, PluginKey } from "@prosekit/pm/state";
|
5
5
|
import { Decoration, DecorationSet } from "@prosekit/pm/view";
|
6
6
|
function addPlaceholder(options) {
|
7
7
|
return addPlugin({
|
@@ -10,6 +10,7 @@ function addPlaceholder(options) {
|
|
10
10
|
}
|
11
11
|
function createPlaceholderPlugin(options) {
|
12
12
|
return new Plugin({
|
13
|
+
key: placeholderPluginKey,
|
13
14
|
props: {
|
14
15
|
decorations: (state) => {
|
15
16
|
if (options.strategy === "doc" && !isDocEmpty(state.doc)) {
|
@@ -25,6 +26,7 @@ function createPlaceholderPlugin(options) {
|
|
25
26
|
}
|
26
27
|
});
|
27
28
|
}
|
29
|
+
var placeholderPluginKey = new PluginKey("prosekit-placeholder");
|
28
30
|
function isDocEmpty(doc) {
|
29
31
|
var _a;
|
30
32
|
return doc.childCount <= 1 && !((_a = doc.firstChild) == null ? void 0 : _a.content.size);
|
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.7",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -60,6 +60,11 @@
|
|
60
60
|
"import": "./dist/prosekit-extensions-italic.js",
|
61
61
|
"default": "./dist/prosekit-extensions-italic.js"
|
62
62
|
},
|
63
|
+
"./link": {
|
64
|
+
"types": "./dist/prosekit-extensions-link.d.ts",
|
65
|
+
"import": "./dist/prosekit-extensions-link.js",
|
66
|
+
"default": "./dist/prosekit-extensions-link.js"
|
67
|
+
},
|
63
68
|
"./list": {
|
64
69
|
"types": "./dist/prosekit-extensions-list.d.ts",
|
65
70
|
"import": "./dist/prosekit-extensions-list.js",
|
@@ -68,6 +73,11 @@
|
|
68
73
|
"./list/style.css": {
|
69
74
|
"default": "./dist/list/style.css"
|
70
75
|
},
|
76
|
+
"./mention": {
|
77
|
+
"types": "./dist/prosekit-extensions-mention.d.ts",
|
78
|
+
"import": "./dist/prosekit-extensions-mention.js",
|
79
|
+
"default": "./dist/prosekit-extensions-mention.js"
|
80
|
+
},
|
71
81
|
"./placeholder": {
|
72
82
|
"types": "./dist/prosekit-extensions-placeholder.d.ts",
|
73
83
|
"import": "./dist/prosekit-extensions-placeholder.js",
|
@@ -86,15 +96,15 @@
|
|
86
96
|
"dist"
|
87
97
|
],
|
88
98
|
"dependencies": {
|
89
|
-
"@prosekit/core": "^0.0.
|
99
|
+
"@prosekit/core": "^0.0.7",
|
90
100
|
"@prosekit/pm": "^0.0.3",
|
91
|
-
"prosemirror-flat-list": "^0.
|
101
|
+
"prosemirror-flat-list": "^0.4.1"
|
92
102
|
},
|
93
103
|
"devDependencies": {
|
94
104
|
"@prosekit/dev": "*",
|
95
|
-
"tsup": "^7.
|
105
|
+
"tsup": "^7.2.0",
|
96
106
|
"typescript": "^5.1.6",
|
97
|
-
"vitest": "^0.
|
107
|
+
"vitest": "^0.34.1"
|
98
108
|
},
|
99
109
|
"scripts": {
|
100
110
|
"build:tsup": "tsup",
|
@@ -124,9 +134,15 @@
|
|
124
134
|
"italic": [
|
125
135
|
"./dist/prosekit-extensions-italic.d.ts"
|
126
136
|
],
|
137
|
+
"link": [
|
138
|
+
"./dist/prosekit-extensions-link.d.ts"
|
139
|
+
],
|
127
140
|
"list": [
|
128
141
|
"./dist/prosekit-extensions-list.d.ts"
|
129
142
|
],
|
143
|
+
"mention": [
|
144
|
+
"./dist/prosekit-extensions-mention.d.ts"
|
145
|
+
],
|
130
146
|
"placeholder": [
|
131
147
|
"./dist/prosekit-extensions-placeholder.d.ts"
|
132
148
|
],
|