@prosekit/extensions 0.0.5 → 0.0.6
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.
@@ -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
|
});
|
@@ -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,45 @@
|
|
1
|
+
// src/mention/index.ts
|
2
|
+
import { addNodeSpec, defineExtension } from "@prosekit/core";
|
3
|
+
function addMentionSpec() {
|
4
|
+
return addNodeSpec({
|
5
|
+
name: "mention",
|
6
|
+
spec: {
|
7
|
+
atom: true,
|
8
|
+
group: "inline",
|
9
|
+
attrs: {
|
10
|
+
id: {},
|
11
|
+
value: {},
|
12
|
+
kind: { default: "" }
|
13
|
+
},
|
14
|
+
inline: true,
|
15
|
+
leafText: (node) => node.attrs.value.toString(),
|
16
|
+
parseDOM: [
|
17
|
+
{
|
18
|
+
tag: `span[data-mention]`,
|
19
|
+
getAttrs: (dom) => ({
|
20
|
+
id: dom.getAttribute("data-id") || "",
|
21
|
+
kind: dom.getAttribute("data-mention") || "",
|
22
|
+
value: dom.textContent || ""
|
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
|
+
];
|
35
|
+
}
|
36
|
+
}
|
37
|
+
});
|
38
|
+
}
|
39
|
+
function addMention() {
|
40
|
+
return defineExtension([addMentionSpec()]);
|
41
|
+
}
|
42
|
+
export {
|
43
|
+
addMention,
|
44
|
+
addMentionSpec
|
45
|
+
};
|
@@ -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.6",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -68,6 +68,11 @@
|
|
68
68
|
"./list/style.css": {
|
69
69
|
"default": "./dist/list/style.css"
|
70
70
|
},
|
71
|
+
"./mention": {
|
72
|
+
"types": "./dist/prosekit-extensions-mention.d.ts",
|
73
|
+
"import": "./dist/prosekit-extensions-mention.js",
|
74
|
+
"default": "./dist/prosekit-extensions-mention.js"
|
75
|
+
},
|
71
76
|
"./placeholder": {
|
72
77
|
"types": "./dist/prosekit-extensions-placeholder.d.ts",
|
73
78
|
"import": "./dist/prosekit-extensions-placeholder.js",
|
@@ -86,7 +91,7 @@
|
|
86
91
|
"dist"
|
87
92
|
],
|
88
93
|
"dependencies": {
|
89
|
-
"@prosekit/core": "^0.0.
|
94
|
+
"@prosekit/core": "^0.0.6",
|
90
95
|
"@prosekit/pm": "^0.0.3",
|
91
96
|
"prosemirror-flat-list": "^0.3.15"
|
92
97
|
},
|
@@ -127,6 +132,9 @@
|
|
127
132
|
"list": [
|
128
133
|
"./dist/prosekit-extensions-list.d.ts"
|
129
134
|
],
|
135
|
+
"mention": [
|
136
|
+
"./dist/prosekit-extensions-mention.d.ts"
|
137
|
+
],
|
130
138
|
"placeholder": [
|
131
139
|
"./dist/prosekit-extensions-placeholder.d.ts"
|
132
140
|
],
|