@prosekit/extensions 0.0.0-next-20230709090937 → 0.0.0-next-20231120040948
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 +459 -0
- package/dist/list/style.css +2 -2
- package/dist/prosekit-extensions-autocomplete.d.ts +3 -0
- package/dist/prosekit-extensions-autocomplete.js +190 -0
- package/dist/prosekit-extensions-blockquote.d.ts +2 -11
- package/dist/prosekit-extensions-blockquote.js +13 -15
- package/dist/prosekit-extensions-bold.d.ts +4 -20
- package/dist/prosekit-extensions-bold.js +35 -37
- package/dist/prosekit-extensions-code-block.d.ts +5 -0
- package/dist/prosekit-extensions-code-block.js +110 -13
- package/dist/prosekit-extensions-code.d.ts +4 -16
- package/dist/prosekit-extensions-code.js +28 -12
- package/dist/prosekit-extensions-heading.d.ts +6 -15
- package/dist/prosekit-extensions-heading.js +67 -39
- package/dist/prosekit-extensions-image.d.ts +4 -0
- package/dist/prosekit-extensions-image.js +48 -0
- package/dist/prosekit-extensions-italic.d.ts +4 -20
- package/dist/prosekit-extensions-italic.js +29 -31
- package/dist/prosekit-extensions-link.d.ts +4 -0
- package/dist/prosekit-extensions-link.js +44 -0
- package/dist/prosekit-extensions-list.d.ts +6 -14
- package/dist/prosekit-extensions-list.js +54 -24
- package/dist/prosekit-extensions-mention.d.ts +3 -0
- package/dist/prosekit-extensions-mention.js +43 -0
- package/dist/prosekit-extensions-placeholder.d.ts +2 -23
- package/dist/prosekit-extensions-placeholder.js +8 -7
- package/dist/prosekit-extensions-strike.d.ts +4 -0
- package/dist/prosekit-extensions-strike.js +47 -0
- package/dist/prosekit-extensions-suggestion.d.ts +3 -37
- package/dist/prosekit-extensions-suggestion.js +7 -5
- package/dist/prosekit-extensions-underline.d.ts +4 -0
- package/dist/prosekit-extensions-underline.js +45 -0
- package/dist/prosekit-extensions.d.ts +1 -2
- package/package.json +65 -7
- package/dist/prosekit-extensions-horizontal-rule.js +0 -23
@@ -0,0 +1,459 @@
|
|
1
|
+
import { CommandArgs } from '@prosekit/core';
|
2
|
+
import { DedentListOptions } from 'prosemirror-flat-list';
|
3
|
+
import { EditorState } from '@prosekit/pm/state';
|
4
|
+
import { Extension } from '@prosekit/core';
|
5
|
+
import { ExtensionTyping } from '@prosekit/core';
|
6
|
+
import type { HLJSApi } from 'highlight.js';
|
7
|
+
import { IndentListOptions } from 'prosemirror-flat-list';
|
8
|
+
import { ListAttributes } from 'prosemirror-flat-list';
|
9
|
+
import { NodeRange } from 'prosemirror-model';
|
10
|
+
import { Options } from 'tsup';
|
11
|
+
import { Plugin as Plugin_2 } from '@prosekit/pm/state';
|
12
|
+
import { PluginKey } from '@prosekit/pm/state';
|
13
|
+
import { ToggleCollapsedOptions } from 'prosemirror-flat-list';
|
14
|
+
import { Transaction } from '@prosekit/pm/state';
|
15
|
+
import { UnwrapListOptions } from 'prosemirror-flat-list';
|
16
|
+
import { UserProjectConfigExport } from 'vitest/dist/config.js';
|
17
|
+
|
18
|
+
declare class AutocompleteRule {
|
19
|
+
readonly regex: RegExp;
|
20
|
+
readonly onMatch: MatchHandler;
|
21
|
+
readonly onLeave?: VoidFunction;
|
22
|
+
readonly canMatch: (options: {
|
23
|
+
state: EditorState;
|
24
|
+
}) => boolean;
|
25
|
+
constructor(options: {
|
26
|
+
regex: RegExp;
|
27
|
+
onEnter: MatchHandler;
|
28
|
+
onLeave?: VoidFunction;
|
29
|
+
canMatch?: (options: {
|
30
|
+
state: EditorState;
|
31
|
+
}) => boolean;
|
32
|
+
});
|
33
|
+
}
|
34
|
+
export { AutocompleteRule }
|
35
|
+
export { AutocompleteRule as AutocompleteRule_alias_1 }
|
36
|
+
|
37
|
+
declare interface CodeBlockAttrs {
|
38
|
+
language?: string;
|
39
|
+
}
|
40
|
+
export { CodeBlockAttrs }
|
41
|
+
export { CodeBlockAttrs as CodeBlockAttrs_alias_1 }
|
42
|
+
|
43
|
+
export declare function createAutocompletePlugin({ getRules, }: {
|
44
|
+
getRules: () => AutocompleteRule[];
|
45
|
+
}): Plugin_2;
|
46
|
+
|
47
|
+
export declare function createPredictionPlugin(options: SuggestionOptions): Plugin_2;
|
48
|
+
|
49
|
+
export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
50
|
+
|
51
|
+
export declare const default_alias_1: UserProjectConfigExport;
|
52
|
+
|
53
|
+
export declare function defaultCanMatch({ state }: {
|
54
|
+
state: EditorState;
|
55
|
+
}): boolean;
|
56
|
+
|
57
|
+
export declare function defaultIsValid({ state }: {
|
58
|
+
state: EditorState;
|
59
|
+
}): boolean;
|
60
|
+
|
61
|
+
export declare function defineAutocomplete(rule: AutocompleteRule): Extension;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* @public
|
65
|
+
*/
|
66
|
+
export declare function defineBlockquote(): Extension< {
|
67
|
+
NODES: "blockquote";
|
68
|
+
}>;
|
69
|
+
|
70
|
+
export declare function defineBlockquoteSpec(): Extension< {
|
71
|
+
NODES: "blockquote";
|
72
|
+
}>;
|
73
|
+
|
74
|
+
/**
|
75
|
+
* @public
|
76
|
+
*/
|
77
|
+
export declare function defineBold(): Extension< {
|
78
|
+
MARKS: "bold";
|
79
|
+
COMMAND_ARGS: {
|
80
|
+
toggleBold: [];
|
81
|
+
};
|
82
|
+
}>;
|
83
|
+
|
84
|
+
export declare function defineBoldCommands(): Extension< {
|
85
|
+
COMMAND_ARGS: {
|
86
|
+
toggleBold: [];
|
87
|
+
};
|
88
|
+
}>;
|
89
|
+
|
90
|
+
export declare function defineBoldKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
91
|
+
|
92
|
+
export declare function defineBoldSpec(): Extension< {
|
93
|
+
MARKS: "bold";
|
94
|
+
}>;
|
95
|
+
|
96
|
+
/**
|
97
|
+
* @public
|
98
|
+
*/
|
99
|
+
export declare function defineCode(): Extension< {
|
100
|
+
MARKS: "code";
|
101
|
+
COMMAND_ARGS: {
|
102
|
+
toggleCode: [];
|
103
|
+
};
|
104
|
+
}>;
|
105
|
+
|
106
|
+
/**
|
107
|
+
* @public
|
108
|
+
*/
|
109
|
+
export declare function defineCodeBlock(options?: {
|
110
|
+
hljs?: HLJSApi;
|
111
|
+
}): Extension< {
|
112
|
+
NODES: "codeBlock";
|
113
|
+
COMMAND_ARGS: {
|
114
|
+
setCodeBlockLanguage: [language: string];
|
115
|
+
};
|
116
|
+
}>;
|
117
|
+
|
118
|
+
export declare function defineCodeBlockCommands(): Extension< {
|
119
|
+
COMMAND_ARGS: {
|
120
|
+
setCodeBlockLanguage: [language: string];
|
121
|
+
};
|
122
|
+
}>;
|
123
|
+
|
124
|
+
export declare function defineCodeBlockHighlight(options: {
|
125
|
+
hljs?: HLJSApi;
|
126
|
+
}): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
127
|
+
|
128
|
+
export declare function defineCodeBlockInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
129
|
+
|
130
|
+
export declare function defineCodeBlockSpec(): Extension< {
|
131
|
+
NODES: "codeBlock";
|
132
|
+
}>;
|
133
|
+
|
134
|
+
export declare function defineCodeCommands(): Extension< {
|
135
|
+
COMMAND_ARGS: {
|
136
|
+
toggleCode: [];
|
137
|
+
};
|
138
|
+
}>;
|
139
|
+
|
140
|
+
/**
|
141
|
+
* @public
|
142
|
+
*/
|
143
|
+
export declare function defineCodeSpec(): Extension< {
|
144
|
+
MARKS: "code";
|
145
|
+
}>;
|
146
|
+
|
147
|
+
/**
|
148
|
+
* @public
|
149
|
+
*/
|
150
|
+
export declare function defineHeading(): Extension< {
|
151
|
+
NODES: "heading";
|
152
|
+
COMMAND_ARGS: {
|
153
|
+
setHeading: [attrs?: HeadingAttrs | undefined];
|
154
|
+
insertHeading: [attrs?: HeadingAttrs | undefined];
|
155
|
+
toggleHeading: [attrs?: HeadingAttrs | undefined];
|
156
|
+
};
|
157
|
+
}>;
|
158
|
+
|
159
|
+
export declare function defineHeadingCommands(): Extension< {
|
160
|
+
COMMAND_ARGS: {
|
161
|
+
setHeading: [attrs?: HeadingAttrs | undefined];
|
162
|
+
insertHeading: [attrs?: HeadingAttrs | undefined];
|
163
|
+
toggleHeading: [attrs?: HeadingAttrs | undefined];
|
164
|
+
};
|
165
|
+
}>;
|
166
|
+
|
167
|
+
export declare function defineHeadingInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
168
|
+
|
169
|
+
export declare function defineHeadingKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
170
|
+
|
171
|
+
export declare function defineHeadingSpec(): Extension< {
|
172
|
+
NODES: "heading";
|
173
|
+
}>;
|
174
|
+
|
175
|
+
/**
|
176
|
+
* @public
|
177
|
+
*/
|
178
|
+
export declare function defineImage(): Extension< {
|
179
|
+
NODES: "image";
|
180
|
+
COMMAND_ARGS: {
|
181
|
+
insertImage: [attrs?: ImageAttrs | undefined];
|
182
|
+
};
|
183
|
+
}>;
|
184
|
+
|
185
|
+
export declare function defineImageCommands(): Extension< {
|
186
|
+
COMMAND_ARGS: {
|
187
|
+
insertImage: [attrs?: ImageAttrs | undefined];
|
188
|
+
};
|
189
|
+
}>;
|
190
|
+
|
191
|
+
export declare function defineImageSpec(): Extension< {
|
192
|
+
NODES: "image";
|
193
|
+
}>;
|
194
|
+
|
195
|
+
/**
|
196
|
+
* @public
|
197
|
+
*/
|
198
|
+
export declare function defineItalic(): Extension< {
|
199
|
+
MARKS: "italic";
|
200
|
+
COMMAND_ARGS: {
|
201
|
+
toggleItalic: [];
|
202
|
+
};
|
203
|
+
}>;
|
204
|
+
|
205
|
+
export declare function defineItalicCommands(): Extension< {
|
206
|
+
COMMAND_ARGS: {
|
207
|
+
toggleItalic: [];
|
208
|
+
};
|
209
|
+
}>;
|
210
|
+
|
211
|
+
export declare function defineItalicKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
212
|
+
|
213
|
+
export declare function defineItalicKeymap_alias_1(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
214
|
+
|
215
|
+
export declare function defineItalicSpec(): Extension< {
|
216
|
+
MARKS: "italic";
|
217
|
+
}>;
|
218
|
+
|
219
|
+
/**
|
220
|
+
* @public
|
221
|
+
*/
|
222
|
+
export declare function defineLink(): Extension< {
|
223
|
+
MARKS: "link";
|
224
|
+
COMMAND_ARGS: {
|
225
|
+
addLink: [attrs: LinkAttrs];
|
226
|
+
toggleLink: [attrs: LinkAttrs];
|
227
|
+
};
|
228
|
+
}>;
|
229
|
+
|
230
|
+
export declare function defineLinkCommands(): Extension< {
|
231
|
+
COMMAND_ARGS: {
|
232
|
+
addLink: [attrs: LinkAttrs];
|
233
|
+
toggleLink: [attrs: LinkAttrs];
|
234
|
+
};
|
235
|
+
}>;
|
236
|
+
|
237
|
+
export declare function defineLinkSpec(): Extension< {
|
238
|
+
MARKS: "link";
|
239
|
+
}>;
|
240
|
+
|
241
|
+
/**
|
242
|
+
* @public
|
243
|
+
*/
|
244
|
+
export declare function defineList(): Extension< {
|
245
|
+
NODES: "list";
|
246
|
+
COMMAND_ARGS: {
|
247
|
+
dedentList: [options?: DedentListOptions | undefined];
|
248
|
+
indentList: [options?: IndentListOptions | undefined];
|
249
|
+
moveList: [direction: "up" | "down"];
|
250
|
+
splitList: [];
|
251
|
+
toggleCollapsed: [(ToggleCollapsedOptions | undefined)?];
|
252
|
+
toggleList: [attrs: ListAttributes];
|
253
|
+
unwrapList: [options?: UnwrapListOptions | undefined];
|
254
|
+
wrapInList: [getAttrs: ListAttributes | ((range: NodeRange) => ListAttributes | null)];
|
255
|
+
insertList: [attrs?: ListAttributes | undefined];
|
256
|
+
};
|
257
|
+
}>;
|
258
|
+
|
259
|
+
export declare function defineListCommands(): Extension< {
|
260
|
+
COMMAND_ARGS: {
|
261
|
+
dedentList: [options?: DedentListOptions | undefined];
|
262
|
+
indentList: [options?: IndentListOptions | undefined];
|
263
|
+
moveList: [direction: "up" | "down"];
|
264
|
+
splitList: [];
|
265
|
+
toggleCollapsed: [(ToggleCollapsedOptions | undefined)?];
|
266
|
+
toggleList: [attrs: ListAttributes];
|
267
|
+
unwrapList: [options?: UnwrapListOptions | undefined];
|
268
|
+
wrapInList: [getAttrs: ListAttributes | ((range: NodeRange) => ListAttributes | null)];
|
269
|
+
insertList: [attrs?: ListAttributes | undefined];
|
270
|
+
};
|
271
|
+
}>;
|
272
|
+
|
273
|
+
export declare function defineListInputRules(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
274
|
+
|
275
|
+
/**
|
276
|
+
* Returns a extension that adds key bindings for list.
|
277
|
+
*
|
278
|
+
* @public
|
279
|
+
*/
|
280
|
+
export declare function defineListKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
281
|
+
|
282
|
+
export declare function defineListPlugins(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
283
|
+
|
284
|
+
export declare function defineListSpec(): Extension< {
|
285
|
+
NODES: "list";
|
286
|
+
}>;
|
287
|
+
|
288
|
+
/**
|
289
|
+
* @public
|
290
|
+
*/
|
291
|
+
export declare function defineMention(): Extension< {
|
292
|
+
NODES: "mention";
|
293
|
+
}>;
|
294
|
+
|
295
|
+
/**
|
296
|
+
* @public
|
297
|
+
*/
|
298
|
+
export declare function defineMentionSpec(): Extension< {
|
299
|
+
NODES: "mention";
|
300
|
+
}>;
|
301
|
+
|
302
|
+
/**
|
303
|
+
* Add a placeholder text to the editor when the current block or document is
|
304
|
+
* empty.
|
305
|
+
*/
|
306
|
+
export declare function definePlaceholder(options: PlaceholderOptions): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
307
|
+
|
308
|
+
/**
|
309
|
+
* @public
|
310
|
+
*/
|
311
|
+
export declare function defineStrike(): Extension< {
|
312
|
+
MARKS: "strike";
|
313
|
+
COMMAND_ARGS: {
|
314
|
+
toggleStrike: [];
|
315
|
+
};
|
316
|
+
}>;
|
317
|
+
|
318
|
+
export declare function defineStrikeCommands(): Extension< {
|
319
|
+
COMMAND_ARGS: {
|
320
|
+
toggleStrike: [];
|
321
|
+
};
|
322
|
+
}>;
|
323
|
+
|
324
|
+
export declare function defineStrikeKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
325
|
+
|
326
|
+
export declare function defineStrikeSpec(): Extension< {
|
327
|
+
MARKS: "strike";
|
328
|
+
}>;
|
329
|
+
|
330
|
+
export declare function defineSuggestion(options: SuggestionOptions): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
331
|
+
|
332
|
+
/**
|
333
|
+
* @public
|
334
|
+
*/
|
335
|
+
export declare function defineUnderline(): Extension< {
|
336
|
+
MARKS: "underline";
|
337
|
+
COMMAND_ARGS: {
|
338
|
+
toggleUnderline: [];
|
339
|
+
};
|
340
|
+
}>;
|
341
|
+
|
342
|
+
export declare function defineUnderlineCommands(): Extension< {
|
343
|
+
COMMAND_ARGS: {
|
344
|
+
toggleUnderline: [];
|
345
|
+
};
|
346
|
+
}>;
|
347
|
+
|
348
|
+
export declare function defineUnderlineKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
349
|
+
|
350
|
+
export declare function defineUnderlineSpec(): Extension< {
|
351
|
+
MARKS: "underline";
|
352
|
+
}>;
|
353
|
+
|
354
|
+
export declare function getPluginState(state: EditorState): PredictionPluginState | undefined;
|
355
|
+
|
356
|
+
export declare function getTrMeta(tr: Transaction): PredictionPluginState;
|
357
|
+
|
358
|
+
export declare interface HeadingAttrs {
|
359
|
+
level: number;
|
360
|
+
}
|
361
|
+
|
362
|
+
export declare interface ImageAttrs {
|
363
|
+
src?: string | null;
|
364
|
+
}
|
365
|
+
|
366
|
+
/**
|
367
|
+
* @public
|
368
|
+
*/
|
369
|
+
export declare interface LinkAttrs {
|
370
|
+
href: string;
|
371
|
+
}
|
372
|
+
|
373
|
+
declare type MatchHandler = (options: {
|
374
|
+
state: EditorState;
|
375
|
+
match: RegExpExecArray;
|
376
|
+
from: number;
|
377
|
+
to: number;
|
378
|
+
ignoreMatch: () => void;
|
379
|
+
deleteMatch: () => void;
|
380
|
+
}) => Transaction | null | void;
|
381
|
+
export { MatchHandler }
|
382
|
+
export { MatchHandler as MatchHandler_alias_1 }
|
383
|
+
|
384
|
+
/**
|
385
|
+
* @returns Return a Transaction object if you want to append a transaction to current state (using )
|
386
|
+
*/
|
387
|
+
declare type MatchHandler_2 = (options: {
|
388
|
+
rule: PredictionRule;
|
389
|
+
match: RegExpMatchArray;
|
390
|
+
matchAfter: RegExpMatchArray | null;
|
391
|
+
state: EditorState;
|
392
|
+
dismiss: VoidFunction;
|
393
|
+
deleteMatch: VoidFunction;
|
394
|
+
}) => void;
|
395
|
+
|
396
|
+
export declare interface MentionAttrs {
|
397
|
+
id: string;
|
398
|
+
kind: string;
|
399
|
+
value: string;
|
400
|
+
}
|
401
|
+
|
402
|
+
export declare const OBJECT_REPLACEMENT = "\uFFFC";
|
403
|
+
|
404
|
+
export declare interface PlaceholderOptions {
|
405
|
+
/**
|
406
|
+
* The placeholder text to use.
|
407
|
+
*/
|
408
|
+
placeholder: string;
|
409
|
+
/**
|
410
|
+
* By default, the placeholder text will be shown whenever the current text
|
411
|
+
* cursor is in an empty node. If you only want to show the placeholder when
|
412
|
+
* the whole doc is empty, you can set this option to 'doc'.
|
413
|
+
*
|
414
|
+
* @default 'block'
|
415
|
+
*/
|
416
|
+
strategy?: 'doc' | 'block';
|
417
|
+
}
|
418
|
+
|
419
|
+
export declare const pluginKey: PluginKey<PredictionPluginState>;
|
420
|
+
|
421
|
+
export declare interface PredictionPluginState {
|
422
|
+
active: boolean;
|
423
|
+
ignore: number | null;
|
424
|
+
matching: {
|
425
|
+
rule: AutocompleteRule;
|
426
|
+
from: number;
|
427
|
+
to: number;
|
428
|
+
match: RegExpExecArray;
|
429
|
+
} | null;
|
430
|
+
}
|
431
|
+
|
432
|
+
declare interface PredictionRule {
|
433
|
+
match: RegExp;
|
434
|
+
matchAfter?: RegExp;
|
435
|
+
}
|
436
|
+
export { PredictionRule }
|
437
|
+
export { PredictionRule as PredictionRule_alias_1 }
|
438
|
+
|
439
|
+
export declare function setTrMeta(tr: Transaction, meta: PredictionPluginState): Transaction;
|
440
|
+
|
441
|
+
declare interface SuggestionOptions {
|
442
|
+
rules: PredictionRule[];
|
443
|
+
onMatch: MatchHandler_2;
|
444
|
+
onDeactivate: VoidFunction;
|
445
|
+
/**
|
446
|
+
* You can pass this function if you want to skip the matching in some cases.
|
447
|
+
* By default, the plugin will only run the matching if the current selection
|
448
|
+
* is empty, and the selection is not inside a
|
449
|
+
* [code](https://prosemirror.net/docs/ref/#model.NodeSpec.code) node nor
|
450
|
+
* inside a mark with the name as `code`.
|
451
|
+
*/
|
452
|
+
isValid?: (options: {
|
453
|
+
state: EditorState;
|
454
|
+
}) => boolean;
|
455
|
+
}
|
456
|
+
export { SuggestionOptions }
|
457
|
+
export { SuggestionOptions as SuggestionOptions_alias_1 }
|
458
|
+
|
459
|
+
export { }
|
package/dist/list/style.css
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* ../../node_modules/.pnpm/prosemirror-flat-list@0.3
|
1
|
+
/* ../../node_modules/.pnpm/prosemirror-flat-list@0.4.3/node_modules/prosemirror-flat-list/dist/style.css */
|
2
2
|
.prosemirror-flat-list {
|
3
3
|
padding: 0;
|
4
4
|
margin-top: 0;
|
@@ -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
|
|
@@ -0,0 +1,190 @@
|
|
1
|
+
// src/autocomplete/index.ts
|
2
|
+
import {
|
3
|
+
Facet,
|
4
|
+
pluginFacet
|
5
|
+
} from "@prosekit/core";
|
6
|
+
|
7
|
+
// src/autocomplete/plugin.ts
|
8
|
+
import { Plugin } from "@prosekit/pm/state";
|
9
|
+
import { Decoration, DecorationSet } from "@prosekit/pm/view";
|
10
|
+
|
11
|
+
// src/autocomplete/helpers.ts
|
12
|
+
import "@prosekit/pm/model";
|
13
|
+
import { PluginKey } from "@prosekit/pm/state";
|
14
|
+
function defaultCanMatch({ state }) {
|
15
|
+
return state.selection.empty && !isInsideCode(state.selection.$from);
|
16
|
+
}
|
17
|
+
function isInsideCode($pos) {
|
18
|
+
for (let d = $pos.depth; d > 0; d--) {
|
19
|
+
if ($pos.node(d).type.spec.code) {
|
20
|
+
return true;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
return $pos.marks().some((mark) => mark.type.name === "code");
|
24
|
+
}
|
25
|
+
var OBJECT_REPLACEMENT = "\uFFFC";
|
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
|
+
var pluginKey = new PluginKey(
|
36
|
+
"prosekit-autocomplete"
|
37
|
+
);
|
38
|
+
|
39
|
+
// src/autocomplete/plugin.ts
|
40
|
+
function createAutocompletePlugin({
|
41
|
+
getRules
|
42
|
+
}) {
|
43
|
+
return new Plugin({
|
44
|
+
key: pluginKey,
|
45
|
+
state: {
|
46
|
+
init: () => {
|
47
|
+
return { active: false, ignore: null, matching: null };
|
48
|
+
},
|
49
|
+
apply: (tr, prevValue, oldState, newState) => {
|
50
|
+
var _a;
|
51
|
+
const meta = getTrMeta(tr);
|
52
|
+
if (!tr.docChanged && oldState.selection.eq(newState.selection) && !meta) {
|
53
|
+
return prevValue;
|
54
|
+
}
|
55
|
+
if (meta) {
|
56
|
+
return meta;
|
57
|
+
}
|
58
|
+
const nextValue = calcPluginState(newState, getRules());
|
59
|
+
if (nextValue.active && prevValue.ignore != null && ((_a = nextValue.matching) == null ? void 0 : _a.from) === prevValue.ignore) {
|
60
|
+
return prevValue;
|
61
|
+
}
|
62
|
+
return nextValue;
|
63
|
+
}
|
64
|
+
},
|
65
|
+
view: () => ({
|
66
|
+
update: (view, prevState) => {
|
67
|
+
var _a, _b, _c;
|
68
|
+
const prevValue = getPluginState(prevState);
|
69
|
+
const currValue = getPluginState(view.state);
|
70
|
+
if ((prevValue == null ? void 0 : prevValue.active) && prevValue.matching && prevValue.matching.rule !== ((_a = currValue == null ? void 0 : currValue.matching) == null ? void 0 : _a.rule)) {
|
71
|
+
(_c = (_b = prevValue.matching.rule).onLeave) == null ? void 0 : _c.call(_b);
|
72
|
+
}
|
73
|
+
if ((currValue == null ? void 0 : currValue.active) && currValue.matching && currValue.matching.from !== currValue.ignore) {
|
74
|
+
const { from, to, match, rule } = currValue.matching;
|
75
|
+
const textContent = view.state.doc.textBetween(
|
76
|
+
from,
|
77
|
+
to,
|
78
|
+
OBJECT_REPLACEMENT
|
79
|
+
);
|
80
|
+
const deleteMatch = () => {
|
81
|
+
if (view.state.doc.textBetween(from, to, OBJECT_REPLACEMENT) === textContent) {
|
82
|
+
view.dispatch(view.state.tr.delete(from, to));
|
83
|
+
}
|
84
|
+
};
|
85
|
+
const ignoreMatch = () => {
|
86
|
+
view.dispatch(
|
87
|
+
setTrMeta(view.state.tr, {
|
88
|
+
active: false,
|
89
|
+
ignore: from,
|
90
|
+
matching: null
|
91
|
+
})
|
92
|
+
);
|
93
|
+
};
|
94
|
+
rule.onMatch({
|
95
|
+
state: view.state,
|
96
|
+
match,
|
97
|
+
from,
|
98
|
+
to,
|
99
|
+
deleteMatch,
|
100
|
+
ignoreMatch
|
101
|
+
});
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}),
|
105
|
+
props: {
|
106
|
+
decorations: (state) => {
|
107
|
+
const pluginState = getPluginState(state);
|
108
|
+
if ((pluginState == null ? void 0 : pluginState.active) && pluginState.matching) {
|
109
|
+
const { from, to } = pluginState.matching;
|
110
|
+
const deco = Decoration.inline(from, to, {
|
111
|
+
class: "prosemirror-prediction-match"
|
112
|
+
});
|
113
|
+
return DecorationSet.create(state.doc, [deco]);
|
114
|
+
}
|
115
|
+
return null;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
});
|
119
|
+
}
|
120
|
+
var MAX_MATCH = 200;
|
121
|
+
function calcPluginState(state, rules) {
|
122
|
+
const $pos = state.selection.$from;
|
123
|
+
const parentOffset = $pos.parentOffset;
|
124
|
+
const textBefore = $pos.parent.textBetween(
|
125
|
+
Math.max(0, parentOffset - MAX_MATCH),
|
126
|
+
parentOffset,
|
127
|
+
null,
|
128
|
+
OBJECT_REPLACEMENT
|
129
|
+
);
|
130
|
+
for (const rule of rules) {
|
131
|
+
if (!rule.canMatch({ state })) {
|
132
|
+
continue;
|
133
|
+
}
|
134
|
+
rule.regex.lastIndex = 0;
|
135
|
+
const match = rule.regex.exec(textBefore);
|
136
|
+
if (!match) {
|
137
|
+
continue;
|
138
|
+
}
|
139
|
+
const from = $pos.pos - textBefore.length + match.index;
|
140
|
+
return {
|
141
|
+
active: true,
|
142
|
+
ignore: null,
|
143
|
+
matching: {
|
144
|
+
rule,
|
145
|
+
match,
|
146
|
+
from,
|
147
|
+
to: $pos.pos
|
148
|
+
}
|
149
|
+
};
|
150
|
+
}
|
151
|
+
return { active: false, ignore: null, matching: null };
|
152
|
+
}
|
153
|
+
|
154
|
+
// src/autocomplete/rule.ts
|
155
|
+
var AutocompleteRule = class {
|
156
|
+
constructor(options) {
|
157
|
+
var _a;
|
158
|
+
this.regex = options.regex;
|
159
|
+
this.onMatch = options.onEnter;
|
160
|
+
this.onLeave = options.onLeave;
|
161
|
+
this.canMatch = (_a = options.canMatch) != null ? _a : defaultCanMatch;
|
162
|
+
}
|
163
|
+
};
|
164
|
+
|
165
|
+
// src/autocomplete/index.ts
|
166
|
+
function defineAutocomplete(rule) {
|
167
|
+
return autocompleteFacet.extension([rule]);
|
168
|
+
}
|
169
|
+
var autocompleteFacet = Facet.define({
|
170
|
+
converter: () => {
|
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
|
+
};
|
184
|
+
},
|
185
|
+
next: pluginFacet
|
186
|
+
});
|
187
|
+
export {
|
188
|
+
AutocompleteRule,
|
189
|
+
defineAutocomplete
|
190
|
+
};
|
@@ -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 { defineBlockquoteSpec } from './_tsup-dts-rollup';
|
2
|
+
export { defineBlockquote } from './_tsup-dts-rollup';
|