@prosekit/extensions 0.0.0-next-20231120040948 → 0.0.0-next-20240427133255
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/_tsup-dts-rollup.d.ts +560 -91
- package/dist/chunk-ASTUC4KT.js +111 -0
- package/dist/chunk-DYFRBXUX.js +56 -0
- package/dist/list/style.css +17 -12
- package/dist/prosekit-extensions-autocomplete.js +8 -4
- package/dist/prosekit-extensions-blockquote.d.ts +1 -0
- package/dist/prosekit-extensions-blockquote.js +12 -1
- package/dist/prosekit-extensions-code-block.d.ts +14 -4
- package/dist/prosekit-extensions-code-block.js +171 -75
- package/dist/prosekit-extensions-drop-cursor.d.ts +2 -0
- package/dist/prosekit-extensions-drop-cursor.js +9 -0
- package/dist/prosekit-extensions-enter-rule.d.ts +5 -0
- package/dist/prosekit-extensions-enter-rule.js +8 -0
- package/dist/prosekit-extensions-heading.js +20 -14
- package/dist/prosekit-extensions-image.js +1 -0
- package/dist/prosekit-extensions-input-rule.d.ts +3 -0
- package/dist/prosekit-extensions-input-rule.js +10 -0
- package/dist/prosekit-extensions-link.d.ts +2 -0
- package/dist/prosekit-extensions-link.js +63 -5
- package/dist/prosekit-extensions-list.d.ts +1 -0
- package/dist/prosekit-extensions-list.js +7 -2
- package/dist/prosekit-extensions-mark-rule.d.ts +3 -0
- package/dist/prosekit-extensions-mark-rule.js +173 -0
- package/dist/prosekit-extensions-mention.d.ts +1 -0
- package/dist/prosekit-extensions-mention.js +15 -2
- package/dist/prosekit-extensions-placeholder.js +4 -1
- package/dist/prosekit-extensions-readonly.d.ts +1 -0
- package/dist/prosekit-extensions-readonly.js +16 -0
- package/dist/prosekit-extensions-table.d.ts +7 -0
- package/dist/prosekit-extensions-table.js +197 -0
- package/dist/prosekit-extensions-virtual-selection.d.ts +1 -0
- package/dist/prosekit-extensions-virtual-selection.js +58 -0
- package/dist/shiki-import-25BJYIO2.js +5 -0
- package/dist/table/style.css +34 -0
- package/dist/virtual-selection/style.css +6 -0
- package/package.json +71 -15
- package/dist/prosekit-extensions-suggestion.d.ts +0 -3
- package/dist/prosekit-extensions-suggestion.js +0 -161
- package/src/index.ts +0 -1
@@ -0,0 +1,58 @@
|
|
1
|
+
// src/virtual-selection/index.ts
|
2
|
+
import { definePlugin } from "@prosekit/core";
|
3
|
+
import {
|
4
|
+
PluginKey,
|
5
|
+
ProseMirrorPlugin
|
6
|
+
} from "@prosekit/pm/state";
|
7
|
+
import { Decoration, DecorationSet } from "@prosekit/pm/view";
|
8
|
+
function defineVirtualSelection() {
|
9
|
+
return definePlugin(virtualSelectionPlugin);
|
10
|
+
}
|
11
|
+
var key = new PluginKey("prosekit-virtual-selection");
|
12
|
+
function getFocusMeta(tr) {
|
13
|
+
return tr.getMeta(key);
|
14
|
+
}
|
15
|
+
function setFocusMeta(tr, value) {
|
16
|
+
return tr.setMeta(key, value);
|
17
|
+
}
|
18
|
+
function getFocusState(state) {
|
19
|
+
return key.getState(state);
|
20
|
+
}
|
21
|
+
var virtualSelectionPlugin = new ProseMirrorPlugin({
|
22
|
+
key,
|
23
|
+
state: {
|
24
|
+
init: () => false,
|
25
|
+
apply: (tr, value) => {
|
26
|
+
var _a;
|
27
|
+
return (_a = getFocusMeta(tr)) != null ? _a : value;
|
28
|
+
}
|
29
|
+
},
|
30
|
+
props: {
|
31
|
+
handleDOMEvents: {
|
32
|
+
focus: (view) => {
|
33
|
+
view.dispatch(setFocusMeta(view.state.tr, false));
|
34
|
+
},
|
35
|
+
blur: (view) => {
|
36
|
+
const { dom, root } = view;
|
37
|
+
const activeElement = root.activeElement;
|
38
|
+
if (activeElement === dom)
|
39
|
+
return;
|
40
|
+
view.dispatch(setFocusMeta(view.state.tr, true));
|
41
|
+
}
|
42
|
+
},
|
43
|
+
decorations: (state) => {
|
44
|
+
const { selection, doc } = state;
|
45
|
+
if (selection.empty || !getFocusState(state)) {
|
46
|
+
return null;
|
47
|
+
}
|
48
|
+
return DecorationSet.create(doc, [
|
49
|
+
Decoration.inline(selection.from, selection.to, {
|
50
|
+
class: "prosekit-virtual-selection"
|
51
|
+
})
|
52
|
+
]);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
});
|
56
|
+
export {
|
57
|
+
defineVirtualSelection
|
58
|
+
};
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/* src/table/style.css */
|
2
|
+
.ProseMirror .tableWrapper {
|
3
|
+
overflow-x: auto;
|
4
|
+
}
|
5
|
+
.ProseMirror table {
|
6
|
+
border-collapse: collapse;
|
7
|
+
table-layout: fixed;
|
8
|
+
width: 100%;
|
9
|
+
overflow: hidden;
|
10
|
+
}
|
11
|
+
.ProseMirror td,
|
12
|
+
.ProseMirror th {
|
13
|
+
vertical-align: top;
|
14
|
+
box-sizing: border-box;
|
15
|
+
position: relative;
|
16
|
+
border-width: 1px;
|
17
|
+
}
|
18
|
+
.ProseMirror .column-resize-handle {
|
19
|
+
position: absolute;
|
20
|
+
right: -2px;
|
21
|
+
top: 0;
|
22
|
+
bottom: 0;
|
23
|
+
width: 4px;
|
24
|
+
z-index: 20;
|
25
|
+
background-color: HighlightText;
|
26
|
+
pointer-events: none;
|
27
|
+
}
|
28
|
+
.ProseMirror.resize-cursor {
|
29
|
+
cursor: ew-resize;
|
30
|
+
cursor: col-resize;
|
31
|
+
}
|
32
|
+
.ProseMirror .selectedCell {
|
33
|
+
background-color: Highlight;
|
34
|
+
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/extensions",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next-
|
4
|
+
"version": "0.0.0-next-20240427133255",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -30,6 +30,11 @@
|
|
30
30
|
"import": "./dist/prosekit-extensions.js",
|
31
31
|
"default": "./dist/prosekit-extensions.js"
|
32
32
|
},
|
33
|
+
"./mark-rule": {
|
34
|
+
"types": "./dist/prosekit-extensions-mark-rule.d.ts",
|
35
|
+
"import": "./dist/prosekit-extensions-mark-rule.js",
|
36
|
+
"default": "./dist/prosekit-extensions-mark-rule.js"
|
37
|
+
},
|
33
38
|
"./autocomplete": {
|
34
39
|
"types": "./dist/prosekit-extensions-autocomplete.d.ts",
|
35
40
|
"import": "./dist/prosekit-extensions-autocomplete.js",
|
@@ -55,6 +60,16 @@
|
|
55
60
|
"import": "./dist/prosekit-extensions-code-block.js",
|
56
61
|
"default": "./dist/prosekit-extensions-code-block.js"
|
57
62
|
},
|
63
|
+
"./drop-cursor": {
|
64
|
+
"types": "./dist/prosekit-extensions-drop-cursor.d.ts",
|
65
|
+
"import": "./dist/prosekit-extensions-drop-cursor.js",
|
66
|
+
"default": "./dist/prosekit-extensions-drop-cursor.js"
|
67
|
+
},
|
68
|
+
"./enter-rule": {
|
69
|
+
"types": "./dist/prosekit-extensions-enter-rule.d.ts",
|
70
|
+
"import": "./dist/prosekit-extensions-enter-rule.js",
|
71
|
+
"default": "./dist/prosekit-extensions-enter-rule.js"
|
72
|
+
},
|
58
73
|
"./heading": {
|
59
74
|
"types": "./dist/prosekit-extensions-heading.d.ts",
|
60
75
|
"import": "./dist/prosekit-extensions-heading.js",
|
@@ -65,6 +80,11 @@
|
|
65
80
|
"import": "./dist/prosekit-extensions-image.js",
|
66
81
|
"default": "./dist/prosekit-extensions-image.js"
|
67
82
|
},
|
83
|
+
"./input-rule": {
|
84
|
+
"types": "./dist/prosekit-extensions-input-rule.d.ts",
|
85
|
+
"import": "./dist/prosekit-extensions-input-rule.js",
|
86
|
+
"default": "./dist/prosekit-extensions-input-rule.js"
|
87
|
+
},
|
68
88
|
"./italic": {
|
69
89
|
"types": "./dist/prosekit-extensions-italic.d.ts",
|
70
90
|
"import": "./dist/prosekit-extensions-italic.js",
|
@@ -96,37 +116,55 @@
|
|
96
116
|
"./placeholder/style.css": {
|
97
117
|
"default": "./dist/placeholder/style.css"
|
98
118
|
},
|
119
|
+
"./readonly": {
|
120
|
+
"types": "./dist/prosekit-extensions-readonly.d.ts",
|
121
|
+
"import": "./dist/prosekit-extensions-readonly.js",
|
122
|
+
"default": "./dist/prosekit-extensions-readonly.js"
|
123
|
+
},
|
99
124
|
"./strike": {
|
100
125
|
"types": "./dist/prosekit-extensions-strike.d.ts",
|
101
126
|
"import": "./dist/prosekit-extensions-strike.js",
|
102
127
|
"default": "./dist/prosekit-extensions-strike.js"
|
103
128
|
},
|
104
|
-
"./
|
105
|
-
"types": "./dist/prosekit-extensions-
|
106
|
-
"import": "./dist/prosekit-extensions-
|
107
|
-
"default": "./dist/prosekit-extensions-
|
129
|
+
"./table": {
|
130
|
+
"types": "./dist/prosekit-extensions-table.d.ts",
|
131
|
+
"import": "./dist/prosekit-extensions-table.js",
|
132
|
+
"default": "./dist/prosekit-extensions-table.js"
|
133
|
+
},
|
134
|
+
"./table/style.css": {
|
135
|
+
"default": "./dist/table/style.css"
|
108
136
|
},
|
109
137
|
"./underline": {
|
110
138
|
"types": "./dist/prosekit-extensions-underline.d.ts",
|
111
139
|
"import": "./dist/prosekit-extensions-underline.js",
|
112
140
|
"default": "./dist/prosekit-extensions-underline.js"
|
141
|
+
},
|
142
|
+
"./virtual-selection": {
|
143
|
+
"types": "./dist/prosekit-extensions-virtual-selection.d.ts",
|
144
|
+
"import": "./dist/prosekit-extensions-virtual-selection.js",
|
145
|
+
"default": "./dist/prosekit-extensions-virtual-selection.js"
|
146
|
+
},
|
147
|
+
"./virtual-selection/style.css": {
|
148
|
+
"default": "./dist/virtual-selection/style.css"
|
113
149
|
}
|
114
150
|
},
|
115
151
|
"files": [
|
116
152
|
"dist"
|
117
153
|
],
|
118
154
|
"dependencies": {
|
119
|
-
"@prosekit/core": "0.0.0-next-
|
120
|
-
"@prosekit/pm": "0.0.0-next-
|
121
|
-
"
|
122
|
-
"prosemirror-flat-list": "^0.
|
123
|
-
"prosemirror-
|
155
|
+
"@prosekit/core": "0.0.0-next-20240427133255",
|
156
|
+
"@prosekit/pm": "0.0.0-next-20240427133255",
|
157
|
+
"prosemirror-dropcursor": "^1.8.1",
|
158
|
+
"prosemirror-flat-list": "^0.5.0",
|
159
|
+
"prosemirror-highlight": "^0.5.0",
|
160
|
+
"prosemirror-tables": "^1.3.7",
|
161
|
+
"shiki": "^1.3.0"
|
124
162
|
},
|
125
163
|
"devDependencies": {
|
126
164
|
"@prosekit/dev": "*",
|
127
|
-
"tsup": "^8.0.
|
128
|
-
"typescript": "^5.
|
129
|
-
"vitest": "^
|
165
|
+
"tsup": "^8.0.2",
|
166
|
+
"typescript": "^5.4.5",
|
167
|
+
"vitest": "^1.5.2"
|
130
168
|
},
|
131
169
|
"scripts": {
|
132
170
|
"build:tsup": "tsup",
|
@@ -138,6 +176,9 @@
|
|
138
176
|
".": [
|
139
177
|
"./dist/prosekit-extensions.d.ts"
|
140
178
|
],
|
179
|
+
"mark-rule": [
|
180
|
+
"./dist/prosekit-extensions-mark-rule.d.ts"
|
181
|
+
],
|
141
182
|
"autocomplete": [
|
142
183
|
"./dist/prosekit-extensions-autocomplete.d.ts"
|
143
184
|
],
|
@@ -153,12 +194,21 @@
|
|
153
194
|
"code-block": [
|
154
195
|
"./dist/prosekit-extensions-code-block.d.ts"
|
155
196
|
],
|
197
|
+
"drop-cursor": [
|
198
|
+
"./dist/prosekit-extensions-drop-cursor.d.ts"
|
199
|
+
],
|
200
|
+
"enter-rule": [
|
201
|
+
"./dist/prosekit-extensions-enter-rule.d.ts"
|
202
|
+
],
|
156
203
|
"heading": [
|
157
204
|
"./dist/prosekit-extensions-heading.d.ts"
|
158
205
|
],
|
159
206
|
"image": [
|
160
207
|
"./dist/prosekit-extensions-image.d.ts"
|
161
208
|
],
|
209
|
+
"input-rule": [
|
210
|
+
"./dist/prosekit-extensions-input-rule.d.ts"
|
211
|
+
],
|
162
212
|
"italic": [
|
163
213
|
"./dist/prosekit-extensions-italic.d.ts"
|
164
214
|
],
|
@@ -174,14 +224,20 @@
|
|
174
224
|
"placeholder": [
|
175
225
|
"./dist/prosekit-extensions-placeholder.d.ts"
|
176
226
|
],
|
227
|
+
"readonly": [
|
228
|
+
"./dist/prosekit-extensions-readonly.d.ts"
|
229
|
+
],
|
177
230
|
"strike": [
|
178
231
|
"./dist/prosekit-extensions-strike.d.ts"
|
179
232
|
],
|
180
|
-
"
|
181
|
-
"./dist/prosekit-extensions-
|
233
|
+
"table": [
|
234
|
+
"./dist/prosekit-extensions-table.d.ts"
|
182
235
|
],
|
183
236
|
"underline": [
|
184
237
|
"./dist/prosekit-extensions-underline.d.ts"
|
238
|
+
],
|
239
|
+
"virtual-selection": [
|
240
|
+
"./dist/prosekit-extensions-virtual-selection.d.ts"
|
185
241
|
]
|
186
242
|
}
|
187
243
|
}
|
@@ -1,161 +0,0 @@
|
|
1
|
-
// src/suggestion/index.ts
|
2
|
-
import { definePlugin } from "@prosekit/core";
|
3
|
-
|
4
|
-
// src/suggestion/plugin.ts
|
5
|
-
import { ProseKitError } from "@prosekit/core";
|
6
|
-
import { Plugin, PluginKey } from "@prosekit/pm/state";
|
7
|
-
import { Decoration, DecorationSet } from "@prosekit/pm/view";
|
8
|
-
|
9
|
-
// src/suggestion/is-valid.ts
|
10
|
-
import "@prosekit/pm/model";
|
11
|
-
import "@prosekit/pm/state";
|
12
|
-
function defaultIsValid({ state }) {
|
13
|
-
return state.selection.empty && !isInsideCode(state.selection.$from);
|
14
|
-
}
|
15
|
-
function isInsideCode($pos) {
|
16
|
-
for (let d = $pos.depth; d > 0; d--) {
|
17
|
-
if ($pos.node(d).type.spec.code) {
|
18
|
-
return true;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
return $pos.marks().some((mark) => mark.type.name === "code");
|
22
|
-
}
|
23
|
-
|
24
|
-
// src/suggestion/plugin.ts
|
25
|
-
var pluginKey = new PluginKey("prosemirror-prediction");
|
26
|
-
function getPluginState(state) {
|
27
|
-
return pluginKey.getState(state);
|
28
|
-
}
|
29
|
-
function getTrMeta(tr) {
|
30
|
-
return tr.getMeta(pluginKey);
|
31
|
-
}
|
32
|
-
function setTrMeta(tr, meta) {
|
33
|
-
return tr.setMeta(pluginKey, meta);
|
34
|
-
}
|
35
|
-
function createPredictionPlugin(options) {
|
36
|
-
if (options.rules.length === 0) {
|
37
|
-
throw new ProseKitError(
|
38
|
-
"You can't create a prediction plugin without rules"
|
39
|
-
);
|
40
|
-
}
|
41
|
-
const { onMatch, onDeactivate, isValid = defaultIsValid } = options;
|
42
|
-
return new Plugin({
|
43
|
-
key: pluginKey,
|
44
|
-
state: {
|
45
|
-
init: () => {
|
46
|
-
return { active: false, ignore: null, matching: null };
|
47
|
-
},
|
48
|
-
apply: (tr, prevValue, oldState, newState) => {
|
49
|
-
var _a;
|
50
|
-
const meta = getTrMeta(tr);
|
51
|
-
if (!tr.docChanged && oldState.selection.eq(newState.selection) && !meta) {
|
52
|
-
return prevValue;
|
53
|
-
}
|
54
|
-
if (meta) {
|
55
|
-
return meta;
|
56
|
-
}
|
57
|
-
if (!isValid({ state: newState })) {
|
58
|
-
return { active: false, ignore: null, matching: null };
|
59
|
-
}
|
60
|
-
const nextValue = calcPluginState(newState, options.rules);
|
61
|
-
if (nextValue.active && prevValue.ignore != null && ((_a = nextValue.matching) == null ? void 0 : _a.from) === prevValue.ignore) {
|
62
|
-
return prevValue;
|
63
|
-
}
|
64
|
-
return nextValue;
|
65
|
-
}
|
66
|
-
},
|
67
|
-
view: () => ({
|
68
|
-
update: (view, prevState) => {
|
69
|
-
const prevPluginState = getPluginState(prevState);
|
70
|
-
const currPluginState = getPluginState(view.state);
|
71
|
-
if ((currPluginState == null ? void 0 : currPluginState.active) && currPluginState.matching && currPluginState.matching.from !== currPluginState.ignore) {
|
72
|
-
const { from, to } = currPluginState.matching;
|
73
|
-
const dismiss = () => {
|
74
|
-
view.dispatch(
|
75
|
-
setTrMeta(view.state.tr, {
|
76
|
-
active: false,
|
77
|
-
ignore: from,
|
78
|
-
matching: null
|
79
|
-
})
|
80
|
-
);
|
81
|
-
};
|
82
|
-
const textContent = view.state.doc.textBetween(from, to, "\uFFFC");
|
83
|
-
const deleteMatch = () => {
|
84
|
-
if (view.state.doc.textBetween(from, to, "\uFFFC") === textContent) {
|
85
|
-
view.dispatch(view.state.tr.delete(from, to));
|
86
|
-
}
|
87
|
-
};
|
88
|
-
onMatch({
|
89
|
-
rule: currPluginState.matching.rule,
|
90
|
-
match: currPluginState.matching.match,
|
91
|
-
matchAfter: currPluginState.matching.matchAfter,
|
92
|
-
state: view.state,
|
93
|
-
dismiss,
|
94
|
-
deleteMatch
|
95
|
-
});
|
96
|
-
} else if (prevPluginState == null ? void 0 : prevPluginState.active) {
|
97
|
-
onDeactivate();
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}),
|
101
|
-
props: {
|
102
|
-
decorations: (state) => {
|
103
|
-
const pluginState = getPluginState(state);
|
104
|
-
if ((pluginState == null ? void 0 : pluginState.active) && pluginState.matching) {
|
105
|
-
const { from, to } = pluginState.matching;
|
106
|
-
const deco = Decoration.inline(from, to, {
|
107
|
-
class: "prosemirror-prediction-match"
|
108
|
-
});
|
109
|
-
return DecorationSet.create(state.doc, [deco]);
|
110
|
-
}
|
111
|
-
return null;
|
112
|
-
}
|
113
|
-
}
|
114
|
-
});
|
115
|
-
}
|
116
|
-
function calcPluginState(state, rules) {
|
117
|
-
const { $anchor } = state.selection;
|
118
|
-
const matchAfter = rules.some((rule) => rule.matchAfter);
|
119
|
-
const parentOffset = $anchor.parentOffset;
|
120
|
-
const textBefore = $anchor.parent.textBetween(
|
121
|
-
Math.max(0, parentOffset - MAX_MATCH),
|
122
|
-
parentOffset,
|
123
|
-
null,
|
124
|
-
"\uFFFC"
|
125
|
-
);
|
126
|
-
const textAfter = matchAfter ? $anchor.parent.textBetween(
|
127
|
-
parentOffset,
|
128
|
-
Math.min(parentOffset + MAX_MATCH, $anchor.parent.content.size),
|
129
|
-
null
|
130
|
-
) : "";
|
131
|
-
for (const rule of rules) {
|
132
|
-
const match = textBefore.match(rule.match);
|
133
|
-
const matchAfter2 = rule.matchAfter ? textAfter.match(rule.matchAfter) : null;
|
134
|
-
if ((match == null ? void 0 : match.index) != null) {
|
135
|
-
const from = $anchor.pos - textBefore.length + match.index;
|
136
|
-
const to = $anchor.pos + (matchAfter2 ? matchAfter2[0].length : 0);
|
137
|
-
return {
|
138
|
-
active: true,
|
139
|
-
ignore: null,
|
140
|
-
matching: {
|
141
|
-
rule,
|
142
|
-
from,
|
143
|
-
to,
|
144
|
-
match,
|
145
|
-
matchAfter: matchAfter2
|
146
|
-
}
|
147
|
-
};
|
148
|
-
}
|
149
|
-
}
|
150
|
-
return { active: false };
|
151
|
-
}
|
152
|
-
var MAX_MATCH = 200;
|
153
|
-
|
154
|
-
// src/suggestion/index.ts
|
155
|
-
function defineSuggestion(options) {
|
156
|
-
const plugin = createPredictionPlugin(options);
|
157
|
-
return definePlugin(plugin);
|
158
|
-
}
|
159
|
-
export {
|
160
|
-
defineSuggestion
|
161
|
-
};
|
package/src/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {}
|