@prosekit/extensions 0.0.7 → 0.0.9
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 +315 -0
- package/dist/list/style.css +1 -1
- package/dist/prosekit-extensions-autocomplete.d.ts +3 -31
- package/dist/prosekit-extensions-blockquote.d.ts +2 -11
- package/dist/prosekit-extensions-bold.d.ts +4 -20
- package/dist/prosekit-extensions-code-block.d.ts +5 -0
- package/dist/prosekit-extensions-code-block.js +119 -0
- package/dist/prosekit-extensions-code.d.ts +2 -16
- package/dist/prosekit-extensions-heading.d.ts +5 -16
- package/dist/prosekit-extensions-italic.d.ts +4 -20
- package/dist/prosekit-extensions-link.d.ts +4 -25
- package/dist/prosekit-extensions-list.d.ts +5 -14
- package/dist/prosekit-extensions-list.js +1 -1
- package/dist/prosekit-extensions-mention.d.ts +3 -21
- package/dist/prosekit-extensions-placeholder.d.ts +2 -23
- package/dist/prosekit-extensions-placeholder.js +1 -3
- package/dist/prosekit-extensions-suggestion.d.ts +3 -37
- package/dist/prosekit-extensions-suggestion.js +1 -1
- package/dist/prosekit-extensions.d.ts +1 -2
- package/package.json +15 -5
@@ -0,0 +1,315 @@
|
|
1
|
+
import { CommandArgs } from '@prosekit/core';
|
2
|
+
import { EditorState } from '@prosekit/pm/state';
|
3
|
+
import { Extension } from '@prosekit/core';
|
4
|
+
import { ExtensionTyping } from '@prosekit/core';
|
5
|
+
import type { HLJSApi } from 'highlight.js';
|
6
|
+
import { Options } from 'tsup';
|
7
|
+
import { Plugin as Plugin_2 } from '@prosekit/pm/state';
|
8
|
+
import { PluginKey } from '@prosekit/pm/state';
|
9
|
+
import { Transaction } from '@prosekit/pm/state';
|
10
|
+
import { UserProjectConfigExport } from 'vitest/dist/config.js';
|
11
|
+
|
12
|
+
export declare function addAutocomplete(rule: AutocompleteRule): Extension;
|
13
|
+
|
14
|
+
/** @public */
|
15
|
+
export declare function addBlockquote(): Extension< {
|
16
|
+
NODES: "blockquote";
|
17
|
+
}>;
|
18
|
+
|
19
|
+
export declare function addBlockquoteSpec(): Extension< {
|
20
|
+
NODES: "blockquote";
|
21
|
+
}>;
|
22
|
+
|
23
|
+
/** @public */
|
24
|
+
export declare function addBold(): Extension< {
|
25
|
+
MARKS: "bold";
|
26
|
+
COMMAND_ARGS: {
|
27
|
+
toggleBold: [];
|
28
|
+
};
|
29
|
+
}>;
|
30
|
+
|
31
|
+
export declare function addBoldCommands(): Extension< {
|
32
|
+
COMMAND_ARGS: {
|
33
|
+
toggleBold: [];
|
34
|
+
};
|
35
|
+
}>;
|
36
|
+
|
37
|
+
export declare function addBoldKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
38
|
+
|
39
|
+
export declare function addBoldSpec(): Extension< {
|
40
|
+
MARKS: "bold";
|
41
|
+
}>;
|
42
|
+
|
43
|
+
/**
|
44
|
+
* @public
|
45
|
+
*/
|
46
|
+
export declare function addCode(): Extension< {
|
47
|
+
MARKS: "code";
|
48
|
+
}>;
|
49
|
+
|
50
|
+
/** @public */
|
51
|
+
export declare function addCodeBlock(options?: {
|
52
|
+
hljs?: HLJSApi;
|
53
|
+
}): Extension< {
|
54
|
+
NODES: "codeBlock";
|
55
|
+
COMMAND_ARGS: {
|
56
|
+
setCodeBlockLanguage: [language: string];
|
57
|
+
};
|
58
|
+
}>;
|
59
|
+
|
60
|
+
export declare function addCodeBlockCommands(): Extension< {
|
61
|
+
COMMAND_ARGS: {
|
62
|
+
setCodeBlockLanguage: [language: string];
|
63
|
+
};
|
64
|
+
}>;
|
65
|
+
|
66
|
+
export declare function addCodeBlockHighlight(options: {
|
67
|
+
hljs?: HLJSApi;
|
68
|
+
}): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
69
|
+
|
70
|
+
export declare function addCodeBlockInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
71
|
+
|
72
|
+
export declare function addCodeBlockSpec(): Extension< {
|
73
|
+
NODES: "codeBlock";
|
74
|
+
}>;
|
75
|
+
|
76
|
+
/**
|
77
|
+
* @public
|
78
|
+
*/
|
79
|
+
export declare function addCodeSpec(): Extension< {
|
80
|
+
MARKS: "code";
|
81
|
+
}>;
|
82
|
+
|
83
|
+
/** @public */
|
84
|
+
export declare function addHeading(): Extension< {
|
85
|
+
NODES: "heading";
|
86
|
+
}>;
|
87
|
+
|
88
|
+
export declare function addHeadingInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
89
|
+
|
90
|
+
export declare function addHeadingKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
91
|
+
|
92
|
+
export declare function addHeadingSpec(): Extension< {
|
93
|
+
NODES: "heading";
|
94
|
+
}>;
|
95
|
+
|
96
|
+
/** @public */
|
97
|
+
export declare function addItalic(): Extension< {
|
98
|
+
MARKS: "italic";
|
99
|
+
COMMAND_ARGS: {
|
100
|
+
toggleItalic: [];
|
101
|
+
};
|
102
|
+
}>;
|
103
|
+
|
104
|
+
/** @public */
|
105
|
+
export declare function addItalic_alias_1(): Extension< {
|
106
|
+
MARKS: "link";
|
107
|
+
COMMAND_ARGS: {
|
108
|
+
addLink: [attrs: LinkAttrs];
|
109
|
+
toggleLink: [attrs: LinkAttrs];
|
110
|
+
};
|
111
|
+
}>;
|
112
|
+
|
113
|
+
export declare function addItalicCommands(): Extension< {
|
114
|
+
COMMAND_ARGS: {
|
115
|
+
toggleItalic: [];
|
116
|
+
};
|
117
|
+
}>;
|
118
|
+
|
119
|
+
export declare function addItalicKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
120
|
+
|
121
|
+
export declare function addItalicSpec(): Extension< {
|
122
|
+
MARKS: "italic";
|
123
|
+
}>;
|
124
|
+
|
125
|
+
export declare function addLinkCommands(): Extension< {
|
126
|
+
COMMAND_ARGS: {
|
127
|
+
addLink: [attrs: LinkAttrs];
|
128
|
+
toggleLink: [attrs: LinkAttrs];
|
129
|
+
};
|
130
|
+
}>;
|
131
|
+
|
132
|
+
export declare function addLinkSpec(): Extension< {
|
133
|
+
MARKS: "link";
|
134
|
+
}>;
|
135
|
+
|
136
|
+
/** @public */
|
137
|
+
export declare function addList(): Extension< {
|
138
|
+
NODES: "list";
|
139
|
+
}>;
|
140
|
+
|
141
|
+
export declare function addListInputRules(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
142
|
+
|
143
|
+
export declare function addListKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
144
|
+
|
145
|
+
export declare function addListPlugins(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
146
|
+
|
147
|
+
export declare function addListSpec(): Extension< {
|
148
|
+
NODES: "list";
|
149
|
+
}>;
|
150
|
+
|
151
|
+
/**
|
152
|
+
* @public
|
153
|
+
*/
|
154
|
+
export declare function addMention(): Extension< {
|
155
|
+
NODES: "mention";
|
156
|
+
}>;
|
157
|
+
|
158
|
+
/**
|
159
|
+
* @public
|
160
|
+
*/
|
161
|
+
export declare function addMentionSpec(): Extension< {
|
162
|
+
NODES: "mention";
|
163
|
+
}>;
|
164
|
+
|
165
|
+
/**
|
166
|
+
* Add a placeholder text to the editor when the current block or document is
|
167
|
+
* empty.
|
168
|
+
*/
|
169
|
+
export declare function addPlaceholder(options: PlaceholderOptions): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
170
|
+
|
171
|
+
export declare function addSuggestion(options: SuggestionOptions): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
172
|
+
|
173
|
+
declare class AutocompleteRule {
|
174
|
+
readonly regex: RegExp;
|
175
|
+
readonly onMatch: MatchHandler;
|
176
|
+
readonly onLeave?: VoidFunction;
|
177
|
+
readonly canMatch: (options: {
|
178
|
+
state: EditorState;
|
179
|
+
}) => boolean;
|
180
|
+
constructor(options: {
|
181
|
+
regex: RegExp;
|
182
|
+
onEnter: MatchHandler;
|
183
|
+
onLeave?: VoidFunction;
|
184
|
+
canMatch?: (options: {
|
185
|
+
state: EditorState;
|
186
|
+
}) => boolean;
|
187
|
+
});
|
188
|
+
}
|
189
|
+
export { AutocompleteRule }
|
190
|
+
export { AutocompleteRule as AutocompleteRule_alias_1 }
|
191
|
+
|
192
|
+
declare interface CodeBlockAttrs {
|
193
|
+
language?: string;
|
194
|
+
}
|
195
|
+
export { CodeBlockAttrs }
|
196
|
+
export { CodeBlockAttrs as CodeBlockAttrs_alias_1 }
|
197
|
+
|
198
|
+
export declare function createAutocompletePlugin({ getRules, }: {
|
199
|
+
getRules: () => AutocompleteRule[];
|
200
|
+
}): Plugin_2;
|
201
|
+
|
202
|
+
export declare function createPredictionPlugin(options: SuggestionOptions): Plugin_2;
|
203
|
+
|
204
|
+
export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
205
|
+
|
206
|
+
export declare const default_alias_1: UserProjectConfigExport;
|
207
|
+
|
208
|
+
export declare function defaultCanMatch({ state }: {
|
209
|
+
state: EditorState;
|
210
|
+
}): boolean;
|
211
|
+
|
212
|
+
export declare function defaultIsValid({ state }: {
|
213
|
+
state: EditorState;
|
214
|
+
}): boolean;
|
215
|
+
|
216
|
+
export declare function getPluginState(state: EditorState): PredictionPluginState | undefined;
|
217
|
+
|
218
|
+
export declare function getTrMeta(tr: Transaction): PredictionPluginState;
|
219
|
+
|
220
|
+
export declare interface HeadingAttrs {
|
221
|
+
level: number;
|
222
|
+
}
|
223
|
+
|
224
|
+
/** @public */
|
225
|
+
export declare interface LinkAttrs {
|
226
|
+
href: string;
|
227
|
+
}
|
228
|
+
|
229
|
+
declare type MatchHandler = (options: {
|
230
|
+
state: EditorState;
|
231
|
+
match: RegExpExecArray;
|
232
|
+
from: number;
|
233
|
+
to: number;
|
234
|
+
ignoreMatch: () => void;
|
235
|
+
deleteMatch: () => void;
|
236
|
+
}) => Transaction | null | void;
|
237
|
+
export { MatchHandler }
|
238
|
+
export { MatchHandler as MatchHandler_alias_1 }
|
239
|
+
|
240
|
+
/**
|
241
|
+
* @returns Return a Transaction object if you want to append a transaction to current state (using )
|
242
|
+
*/
|
243
|
+
declare type MatchHandler_2 = (options: {
|
244
|
+
rule: PredictionRule;
|
245
|
+
match: RegExpMatchArray;
|
246
|
+
matchAfter: RegExpMatchArray | null;
|
247
|
+
state: EditorState;
|
248
|
+
dismiss: VoidFunction;
|
249
|
+
deleteMatch: VoidFunction;
|
250
|
+
}) => void;
|
251
|
+
|
252
|
+
export declare interface MentionAttrs {
|
253
|
+
id: string;
|
254
|
+
kind: string;
|
255
|
+
value: string;
|
256
|
+
}
|
257
|
+
|
258
|
+
export declare const OBJECT_REPLACEMENT = "\uFFFC";
|
259
|
+
|
260
|
+
export declare interface PlaceholderOptions {
|
261
|
+
/**
|
262
|
+
* The placeholder text to use.
|
263
|
+
*/
|
264
|
+
placeholder: string;
|
265
|
+
/**
|
266
|
+
* By default, the placeholder text will be shown whenever the current text
|
267
|
+
* cursor is in an empty node. If you only want to show the placeholder when
|
268
|
+
* the whole doc is empty, you can set this option to 'doc'.
|
269
|
+
*
|
270
|
+
* @default 'block'
|
271
|
+
*/
|
272
|
+
strategy?: 'doc' | 'block';
|
273
|
+
}
|
274
|
+
|
275
|
+
export declare const pluginKey: PluginKey<PredictionPluginState>;
|
276
|
+
|
277
|
+
export declare type PredictionPluginState = {
|
278
|
+
active: boolean;
|
279
|
+
ignore: number | null;
|
280
|
+
matching: {
|
281
|
+
rule: AutocompleteRule;
|
282
|
+
from: number;
|
283
|
+
to: number;
|
284
|
+
match: RegExpExecArray;
|
285
|
+
} | null;
|
286
|
+
};
|
287
|
+
|
288
|
+
declare interface PredictionRule {
|
289
|
+
match: RegExp;
|
290
|
+
matchAfter?: RegExp;
|
291
|
+
}
|
292
|
+
export { PredictionRule }
|
293
|
+
export { PredictionRule as PredictionRule_alias_1 }
|
294
|
+
|
295
|
+
export declare function setTrMeta(tr: Transaction, meta: PredictionPluginState): Transaction;
|
296
|
+
|
297
|
+
declare interface SuggestionOptions {
|
298
|
+
rules: PredictionRule[];
|
299
|
+
onMatch: MatchHandler_2;
|
300
|
+
onDeactivate: VoidFunction;
|
301
|
+
/**
|
302
|
+
* You can pass this function if you want to skip the matching in some cases.
|
303
|
+
* By default, the plugin will only run the matching if the current selection
|
304
|
+
* is empty, and the selection is not inside a
|
305
|
+
* [code](https://prosemirror.net/docs/ref/#model.NodeSpec.code) node nor
|
306
|
+
* inside a mark with the name as `code`.
|
307
|
+
*/
|
308
|
+
isValid?: (options: {
|
309
|
+
state: EditorState;
|
310
|
+
}) => boolean;
|
311
|
+
}
|
312
|
+
export { SuggestionOptions }
|
313
|
+
export { SuggestionOptions as SuggestionOptions_alias_1 }
|
314
|
+
|
315
|
+
export { }
|
package/dist/list/style.css
CHANGED
@@ -77,7 +77,7 @@
|
|
77
77
|
opacity: 40%;
|
78
78
|
pointer-events: none;
|
79
79
|
}
|
80
|
-
.prosemirror-flat-list[data-list-kind=toggle][data-list-collapsable][data-list-collapsed] > .list-content > *:nth-child(n
|
80
|
+
.prosemirror-flat-list[data-list-kind=toggle][data-list-collapsable][data-list-collapsed] > .list-content > *:nth-child(n+2) {
|
81
81
|
display: none;
|
82
82
|
}
|
83
83
|
|
@@ -1,31 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
type MatchHandler = (options: {
|
5
|
-
state: EditorState;
|
6
|
-
match: RegExpExecArray;
|
7
|
-
from: number;
|
8
|
-
to: number;
|
9
|
-
ignoreMatch: () => void;
|
10
|
-
deleteMatch: () => void;
|
11
|
-
}) => Transaction | null | void;
|
12
|
-
declare class AutocompleteRule {
|
13
|
-
readonly regex: RegExp;
|
14
|
-
readonly onMatch: MatchHandler;
|
15
|
-
readonly onLeave?: VoidFunction;
|
16
|
-
readonly canMatch: (options: {
|
17
|
-
state: EditorState;
|
18
|
-
}) => boolean;
|
19
|
-
constructor(options: {
|
20
|
-
regex: RegExp;
|
21
|
-
onEnter: MatchHandler;
|
22
|
-
onLeave?: VoidFunction;
|
23
|
-
canMatch?: (options: {
|
24
|
-
state: EditorState;
|
25
|
-
}) => boolean;
|
26
|
-
});
|
27
|
-
}
|
28
|
-
|
29
|
-
declare function addAutocomplete(rule: AutocompleteRule): Extension;
|
30
|
-
|
31
|
-
export { AutocompleteRule, MatchHandler, addAutocomplete };
|
1
|
+
export { addAutocomplete } from './_tsup-dts-rollup';
|
2
|
+
export { AutocompleteRule } from './_tsup-dts-rollup';
|
3
|
+
export { MatchHandler } from './_tsup-dts-rollup';
|
@@ -1,11 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
declare function addBlockquoteSpec(): _prosekit_core.Extension<{
|
4
|
-
NODES: "blockquote";
|
5
|
-
}>;
|
6
|
-
/** @public */
|
7
|
-
declare function addBlockquote(): _prosekit_core.Extension<{
|
8
|
-
NODES: "blockquote";
|
9
|
-
}>;
|
10
|
-
|
11
|
-
export { addBlockquote, addBlockquoteSpec };
|
1
|
+
export { addBlockquoteSpec } from './_tsup-dts-rollup';
|
2
|
+
export { addBlockquote } from './_tsup-dts-rollup';
|
@@ -1,20 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
}>;
|
6
|
-
declare function addBoldCommands(): _prosekit_core.Extension<{
|
7
|
-
COMMAND_ARGS: {
|
8
|
-
toggleBold: [];
|
9
|
-
};
|
10
|
-
}>;
|
11
|
-
declare function addBoldKeymap(): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
|
12
|
-
/** @public */
|
13
|
-
declare function addBold(): _prosekit_core.Extension<{
|
14
|
-
MARKS: "bold";
|
15
|
-
COMMAND_ARGS: {
|
16
|
-
toggleBold: [];
|
17
|
-
};
|
18
|
-
}>;
|
19
|
-
|
20
|
-
export { addBold, addBoldCommands, addBoldKeymap, addBoldSpec };
|
1
|
+
export { addBoldSpec } from './_tsup-dts-rollup';
|
2
|
+
export { addBoldCommands } from './_tsup-dts-rollup';
|
3
|
+
export { addBoldKeymap } from './_tsup-dts-rollup';
|
4
|
+
export { addBold } from './_tsup-dts-rollup';
|
@@ -0,0 +1,5 @@
|
|
1
|
+
export { addCodeBlockSpec } from './_tsup-dts-rollup';
|
2
|
+
export { addCodeBlockInputRule } from './_tsup-dts-rollup';
|
3
|
+
export { addCodeBlockCommands } from './_tsup-dts-rollup';
|
4
|
+
export { addCodeBlock } from './_tsup-dts-rollup';
|
5
|
+
export { CodeBlockAttrs_alias_1 as CodeBlockAttrs } from './_tsup-dts-rollup';
|
@@ -0,0 +1,119 @@
|
|
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(plugin);
|
45
|
+
}
|
46
|
+
var key = new PluginKey("prosekit-code-block-highlight");
|
47
|
+
var blockTypes = ["codeBlock"];
|
48
|
+
function languageExtractor(node) {
|
49
|
+
return node.attrs.language || "javascript";
|
50
|
+
}
|
51
|
+
|
52
|
+
// src/code-block/index.ts
|
53
|
+
function addCodeBlockSpec() {
|
54
|
+
return addNodeSpec({
|
55
|
+
name: "codeBlock",
|
56
|
+
content: "text*",
|
57
|
+
group: "block",
|
58
|
+
code: true,
|
59
|
+
defining: true,
|
60
|
+
marks: "",
|
61
|
+
attrs: { language: { default: "" } },
|
62
|
+
parseDOM: [
|
63
|
+
{
|
64
|
+
tag: "pre",
|
65
|
+
preserveWhitespace: "full",
|
66
|
+
getAttrs: (node) => ({
|
67
|
+
language: node.getAttribute("data-language") || ""
|
68
|
+
})
|
69
|
+
}
|
70
|
+
],
|
71
|
+
toDOM(node) {
|
72
|
+
const attrs = node.attrs;
|
73
|
+
return [
|
74
|
+
"pre",
|
75
|
+
{ "data-language": attrs.language, class: "hljs" },
|
76
|
+
["code", 0]
|
77
|
+
];
|
78
|
+
}
|
79
|
+
});
|
80
|
+
}
|
81
|
+
function addCodeBlockInputRule() {
|
82
|
+
return addInputRule(({ schema }) => {
|
83
|
+
const nodeType = getNodeType(schema, "codeBlock");
|
84
|
+
const getAttrs = (match) => {
|
85
|
+
return { language: match[1] || "" };
|
86
|
+
};
|
87
|
+
const inputRule = textblockTypeInputRule(/^```(\S*)\s$/, nodeType, getAttrs);
|
88
|
+
return [inputRule];
|
89
|
+
});
|
90
|
+
}
|
91
|
+
function addCodeBlockCommands() {
|
92
|
+
return addCommands({
|
93
|
+
setCodeBlockLanguage: (language) => (state, dispatch) => {
|
94
|
+
const pos = state.selection.$from.before();
|
95
|
+
const codeBlock = state.doc.nodeAt(pos);
|
96
|
+
if (!codeBlock || codeBlock.type.name !== "codeBlock") {
|
97
|
+
return false;
|
98
|
+
}
|
99
|
+
const { tr } = state;
|
100
|
+
tr.setNodeMarkup(pos, void 0, { language });
|
101
|
+
dispatch == null ? void 0 : dispatch(tr);
|
102
|
+
return true;
|
103
|
+
}
|
104
|
+
});
|
105
|
+
}
|
106
|
+
function addCodeBlock(options) {
|
107
|
+
return defineExtension([
|
108
|
+
addCodeBlockSpec(),
|
109
|
+
addCodeBlockInputRule(),
|
110
|
+
addCodeBlockHighlight({ hljs: options == null ? void 0 : options.hljs }),
|
111
|
+
addCodeBlockCommands()
|
112
|
+
]);
|
113
|
+
}
|
114
|
+
export {
|
115
|
+
addCodeBlock,
|
116
|
+
addCodeBlockCommands,
|
117
|
+
addCodeBlockInputRule,
|
118
|
+
addCodeBlockSpec
|
119
|
+
};
|
@@ -1,16 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
/**
|
4
|
-
* @public
|
5
|
-
*/
|
6
|
-
declare function addCodeSpec(): _prosekit_core.Extension<{
|
7
|
-
MARKS: "code";
|
8
|
-
}>;
|
9
|
-
/**
|
10
|
-
* @public
|
11
|
-
*/
|
12
|
-
declare function addCode(): _prosekit_core.Extension<{
|
13
|
-
MARKS: "code";
|
14
|
-
}>;
|
15
|
-
|
16
|
-
export { addCode, addCodeSpec };
|
1
|
+
export { addCodeSpec } from './_tsup-dts-rollup';
|
2
|
+
export { addCode } from './_tsup-dts-rollup';
|
@@ -1,16 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
}
|
6
|
-
declare function addHeadingSpec(): _prosekit_core.Extension<{
|
7
|
-
NODES: "heading";
|
8
|
-
}>;
|
9
|
-
declare function addHeadingKeymap(): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
|
10
|
-
declare function addHeadingInputRule(): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
|
11
|
-
/** @public */
|
12
|
-
declare function addHeading(): _prosekit_core.Extension<{
|
13
|
-
NODES: "heading";
|
14
|
-
}>;
|
15
|
-
|
16
|
-
export { HeadingAttrs, addHeading, addHeadingInputRule, addHeadingKeymap, addHeadingSpec };
|
1
|
+
export { addHeadingSpec } from './_tsup-dts-rollup';
|
2
|
+
export { addHeadingKeymap } from './_tsup-dts-rollup';
|
3
|
+
export { addHeadingInputRule } from './_tsup-dts-rollup';
|
4
|
+
export { addHeading } from './_tsup-dts-rollup';
|
5
|
+
export { HeadingAttrs } from './_tsup-dts-rollup';
|
@@ -1,20 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
}>;
|
6
|
-
declare function addItalicCommands(): _prosekit_core.Extension<{
|
7
|
-
COMMAND_ARGS: {
|
8
|
-
toggleItalic: [];
|
9
|
-
};
|
10
|
-
}>;
|
11
|
-
declare function addItalicKeymap(): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
|
12
|
-
/** @public */
|
13
|
-
declare function addItalic(): _prosekit_core.Extension<{
|
14
|
-
MARKS: "italic";
|
15
|
-
COMMAND_ARGS: {
|
16
|
-
toggleItalic: [];
|
17
|
-
};
|
18
|
-
}>;
|
19
|
-
|
20
|
-
export { addItalic, addItalicCommands, addItalicKeymap, addItalicSpec };
|
1
|
+
export { addItalicSpec } from './_tsup-dts-rollup';
|
2
|
+
export { addItalicCommands } from './_tsup-dts-rollup';
|
3
|
+
export { addItalicKeymap } from './_tsup-dts-rollup';
|
4
|
+
export { addItalic } from './_tsup-dts-rollup';
|
@@ -1,25 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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 };
|
1
|
+
export { addLinkSpec } from './_tsup-dts-rollup';
|
2
|
+
export { addLinkCommands } from './_tsup-dts-rollup';
|
3
|
+
export { addItalic_alias_1 as addItalic } from './_tsup-dts-rollup';
|
4
|
+
export { LinkAttrs } from './_tsup-dts-rollup';
|
@@ -1,14 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
}
|
6
|
-
declare function addListPlugins(): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
|
7
|
-
declare function addListKeymap(): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
|
8
|
-
declare function addListInputRules(): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
|
9
|
-
/** @public */
|
10
|
-
declare function addList(): _prosekit_core.Extension<{
|
11
|
-
NODES: "list";
|
12
|
-
}>;
|
13
|
-
|
14
|
-
export { addList, addListInputRules, addListKeymap, addListPlugins, addListSpec };
|
1
|
+
export { addListSpec } from './_tsup-dts-rollup';
|
2
|
+
export { addListPlugins } from './_tsup-dts-rollup';
|
3
|
+
export { addListKeymap } from './_tsup-dts-rollup';
|
4
|
+
export { addListInputRules } from './_tsup-dts-rollup';
|
5
|
+
export { addList } from './_tsup-dts-rollup';
|
@@ -16,7 +16,7 @@ function addListSpec() {
|
|
16
16
|
return addNodeSpec({ ...createListSpec(), name: "list" });
|
17
17
|
}
|
18
18
|
function addListPlugins() {
|
19
|
-
return addPlugin(
|
19
|
+
return addPlugin(({ schema }) => createListPlugins({ schema }));
|
20
20
|
}
|
21
21
|
function addListKeymap() {
|
22
22
|
return addKeymap(listKeymap);
|
@@ -1,21 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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 };
|
1
|
+
export { addMentionSpec } from './_tsup-dts-rollup';
|
2
|
+
export { addMention } from './_tsup-dts-rollup';
|
3
|
+
export { MentionAttrs } from './_tsup-dts-rollup';
|
@@ -1,23 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
interface PlaceholderOptions {
|
4
|
-
/**
|
5
|
-
* The placeholder text to use.
|
6
|
-
*/
|
7
|
-
placeholder: string;
|
8
|
-
/**
|
9
|
-
* By default, the placeholder text will be shown whenever the current text
|
10
|
-
* cursor is in an empty node. If you only want to show the placeholder when
|
11
|
-
* the whole doc is empty, you can set this option to 'doc'.
|
12
|
-
*
|
13
|
-
* @default 'block'
|
14
|
-
*/
|
15
|
-
strategy?: 'doc' | 'block';
|
16
|
-
}
|
17
|
-
/**
|
18
|
-
* Add a placeholder text to the editor when the current block or document is
|
19
|
-
* empty.
|
20
|
-
*/
|
21
|
-
declare function addPlaceholder(options: PlaceholderOptions): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
|
22
|
-
|
23
|
-
export { PlaceholderOptions, addPlaceholder };
|
1
|
+
export { addPlaceholder } from './_tsup-dts-rollup';
|
2
|
+
export { PlaceholderOptions } from './_tsup-dts-rollup';
|
@@ -4,9 +4,7 @@ import "@prosekit/pm/model";
|
|
4
4
|
import { Plugin, PluginKey } from "@prosekit/pm/state";
|
5
5
|
import { Decoration, DecorationSet } from "@prosekit/pm/view";
|
6
6
|
function addPlaceholder(options) {
|
7
|
-
return addPlugin(
|
8
|
-
plugins: [createPlaceholderPlugin(options)]
|
9
|
-
});
|
7
|
+
return addPlugin(createPlaceholderPlugin(options));
|
10
8
|
}
|
11
9
|
function createPlaceholderPlugin(options) {
|
12
10
|
return new Plugin({
|
@@ -1,37 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
interface PredictionRule {
|
5
|
-
match: RegExp;
|
6
|
-
matchAfter?: RegExp;
|
7
|
-
}
|
8
|
-
/**
|
9
|
-
* @returns Return a Transaction object if you want to append a transaction to current state (using )
|
10
|
-
*/
|
11
|
-
type MatchHandler = (options: {
|
12
|
-
rule: PredictionRule;
|
13
|
-
match: RegExpMatchArray;
|
14
|
-
matchAfter: RegExpMatchArray | null;
|
15
|
-
state: EditorState;
|
16
|
-
dismiss: VoidFunction;
|
17
|
-
deleteMatch: VoidFunction;
|
18
|
-
}) => void;
|
19
|
-
interface SuggestionOptions {
|
20
|
-
rules: PredictionRule[];
|
21
|
-
onMatch: MatchHandler;
|
22
|
-
onDeactivate: VoidFunction;
|
23
|
-
/**
|
24
|
-
* You can pass this function if you want to skip the matching in some cases.
|
25
|
-
* By default, the plugin will only run the matching if the current selection
|
26
|
-
* is empty, and the selection is not inside a
|
27
|
-
* [code](https://prosemirror.net/docs/ref/#model.NodeSpec.code) node nor
|
28
|
-
* inside a mark with the name as `code`.
|
29
|
-
*/
|
30
|
-
isValid?: (options: {
|
31
|
-
state: EditorState;
|
32
|
-
}) => boolean;
|
33
|
-
}
|
34
|
-
|
35
|
-
declare function addSuggestion(options: SuggestionOptions): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
|
36
|
-
|
37
|
-
export { PredictionRule, SuggestionOptions, addSuggestion };
|
1
|
+
export { addSuggestion } from './_tsup-dts-rollup';
|
2
|
+
export { PredictionRule } from './_tsup-dts-rollup';
|
3
|
+
export { SuggestionOptions } from './_tsup-dts-rollup';
|
@@ -154,7 +154,7 @@ var MAX_MATCH = 200;
|
|
154
154
|
// src/suggestion/index.ts
|
155
155
|
function addSuggestion(options) {
|
156
156
|
const plugin = createPredictionPlugin(options);
|
157
|
-
return addPlugin(
|
157
|
+
return addPlugin(plugin);
|
158
158
|
}
|
159
159
|
export {
|
160
160
|
addSuggestion
|
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
export { }
|
1
|
+
export {};
|
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.9",
|
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",
|
@@ -96,15 +101,17 @@
|
|
96
101
|
"dist"
|
97
102
|
],
|
98
103
|
"dependencies": {
|
99
|
-
"@prosekit/core": "^0.0.
|
104
|
+
"@prosekit/core": "^0.0.8",
|
100
105
|
"@prosekit/pm": "^0.0.3",
|
101
|
-
"
|
106
|
+
"highlight.js": "^11.8.0",
|
107
|
+
"prosemirror-flat-list": "^0.4.1",
|
108
|
+
"prosemirror-highlightjs": "^0.9.1"
|
102
109
|
},
|
103
110
|
"devDependencies": {
|
104
111
|
"@prosekit/dev": "*",
|
105
112
|
"tsup": "^7.2.0",
|
106
|
-
"typescript": "^5.
|
107
|
-
"vitest": "^0.34.
|
113
|
+
"typescript": "^5.2.2",
|
114
|
+
"vitest": "^0.34.3"
|
108
115
|
},
|
109
116
|
"scripts": {
|
110
117
|
"build:tsup": "tsup",
|
@@ -128,6 +135,9 @@
|
|
128
135
|
"code": [
|
129
136
|
"./dist/prosekit-extensions-code.d.ts"
|
130
137
|
],
|
138
|
+
"code-block": [
|
139
|
+
"./dist/prosekit-extensions-code-block.d.ts"
|
140
|
+
],
|
131
141
|
"heading": [
|
132
142
|
"./dist/prosekit-extensions-heading.d.ts"
|
133
143
|
],
|