@prosekit/core 0.3.0 → 0.3.1
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 +218 -0
- package/dist/prosekit-core.d.ts +26 -0
- package/dist/prosekit-core.js +210 -17
- package/package.json +2 -2
@@ -5,6 +5,7 @@ import { Command } from '@prosekit/pm/state';
|
|
5
5
|
import type { ConditionalExcept } from 'type-fest';
|
6
6
|
import type { ContentMatch } from '@prosekit/pm/model';
|
7
7
|
import type { DirectEditorProps } from '@prosekit/pm/view';
|
8
|
+
import type { DOMEventMap } from '@prosekit/pm/view';
|
8
9
|
import { EditorState } from '@prosekit/pm/state';
|
9
10
|
import type { EditorStateConfig } from '@prosekit/pm/state';
|
10
11
|
import { EditorView } from '@prosekit/pm/view';
|
@@ -15,6 +16,7 @@ import type { MarkSpec } from '@prosekit/pm/model';
|
|
15
16
|
import { MarkType } from '@prosekit/pm/model';
|
16
17
|
import { MarkType as MarkType_2 } from 'prosemirror-model';
|
17
18
|
import { Node as Node_2 } from 'prosemirror-model';
|
19
|
+
import type { Node as Node_3 } from '@prosekit/pm/model';
|
18
20
|
import { NodeSelection } from '@prosekit/pm/state';
|
19
21
|
import type { NodeSpec } from '@prosekit/pm/model';
|
20
22
|
import { NodeType } from '@prosekit/pm/model';
|
@@ -30,6 +32,7 @@ import type { SchemaSpec } from '@prosekit/pm/model';
|
|
30
32
|
import { Selection as Selection_2 } from '@prosekit/pm/state';
|
31
33
|
import { Selection as Selection_3 } from 'prosemirror-state';
|
32
34
|
import type { Simplify } from 'type-fest';
|
35
|
+
import type { Slice } from '@prosekit/pm/model';
|
33
36
|
import { TextSelection } from '@prosekit/pm/state';
|
34
37
|
import { Transaction } from '@prosekit/pm/state';
|
35
38
|
import type { UnionToIntersection } from 'type-fest';
|
@@ -122,6 +125,14 @@ declare interface BaseNodeViewOptions {
|
|
122
125
|
export { BaseNodeViewOptions }
|
123
126
|
export { BaseNodeViewOptions as BaseNodeViewOptions_alias_1 }
|
124
127
|
|
128
|
+
declare type ClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
|
129
|
+
export { ClickHandler }
|
130
|
+
export { ClickHandler as ClickHandler_alias_1 }
|
131
|
+
|
132
|
+
declare type ClickOnHandler = (view: EditorView, pos: number, node: Node_3, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
|
133
|
+
export { ClickOnHandler }
|
134
|
+
export { ClickOnHandler as ClickOnHandler_alias_1 }
|
135
|
+
|
125
136
|
/**
|
126
137
|
* A utility for constructing `className` strings conditionally.
|
127
138
|
*
|
@@ -135,6 +146,8 @@ export { clsx as clsx_alias_1 }
|
|
135
146
|
|
136
147
|
export declare function collectNodes(content: NodeContent): ProseMirrorNode[];
|
137
148
|
|
149
|
+
export declare function combineEventHandlers<Handler extends (...args: any[]) => boolean | void, Args extends Parameters<Handler> = Parameters<Handler>>(): readonly [(handlers: Handler[]) => void, (...args: Args) => boolean];
|
150
|
+
|
138
151
|
export declare interface CommandApplier<Args extends any[] = any[]> {
|
139
152
|
(...args: Args): boolean;
|
140
153
|
canApply(...args: Args): boolean;
|
@@ -281,6 +294,24 @@ declare function defineBaseKeymap(options?: {
|
|
281
294
|
export { defineBaseKeymap }
|
282
295
|
export { defineBaseKeymap as defineBaseKeymap_alias_1 }
|
283
296
|
|
297
|
+
/**
|
298
|
+
* @public
|
299
|
+
*
|
300
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleClick}
|
301
|
+
*/
|
302
|
+
declare function defineClickHandler(handler: ClickHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
303
|
+
export { defineClickHandler }
|
304
|
+
export { defineClickHandler as defineClickHandler_alias_1 }
|
305
|
+
|
306
|
+
/**
|
307
|
+
* @public
|
308
|
+
*
|
309
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleClickOn}
|
310
|
+
*/
|
311
|
+
declare function defineClickOnHandler(handler: ClickOnHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
312
|
+
export { defineClickOnHandler }
|
313
|
+
export { defineClickOnHandler as defineClickOnHandler_alias_1 }
|
314
|
+
|
284
315
|
declare function defineCommands<T extends Record<string, CommandCreator> = Record<string, CommandCreator>>(commands: T): Extension<{
|
285
316
|
COMMAND_ARGS: {
|
286
317
|
[K in keyof T]: Parameters<T[K]>;
|
@@ -311,6 +342,42 @@ declare function defineDocChangeHandler(handler: DocChangeHandler): Extension<Ex
|
|
311
342
|
export { defineDocChangeHandler }
|
312
343
|
export { defineDocChangeHandler as defineDocChangeHandler_alias_1 }
|
313
344
|
|
345
|
+
/**
|
346
|
+
* Register a new event handler for the given event type.
|
347
|
+
*
|
348
|
+
* @public
|
349
|
+
*/
|
350
|
+
declare function defineDOMEventHandler<Event extends keyof DOMEventMap = string>(event: Event, handler: DOMEventHandler<Event>): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
351
|
+
export { defineDOMEventHandler }
|
352
|
+
export { defineDOMEventHandler as defineDOMEventHandler_alias_1 }
|
353
|
+
|
354
|
+
/**
|
355
|
+
* @public
|
356
|
+
*
|
357
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleDoubleClick}
|
358
|
+
*/
|
359
|
+
declare function defineDoubleClickHandler(handler: DoubleClickHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
360
|
+
export { defineDoubleClickHandler }
|
361
|
+
export { defineDoubleClickHandler as defineDoubleClickHandler_alias_1 }
|
362
|
+
|
363
|
+
/**
|
364
|
+
* @public
|
365
|
+
*
|
366
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleDoubleClickOn}
|
367
|
+
*/
|
368
|
+
declare function defineDoubleClickOnHandler(handler: DoubleClickOnHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
369
|
+
export { defineDoubleClickOnHandler }
|
370
|
+
export { defineDoubleClickOnHandler as defineDoubleClickOnHandler_alias_1 }
|
371
|
+
|
372
|
+
/**
|
373
|
+
* @public
|
374
|
+
*
|
375
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleDrop}
|
376
|
+
*/
|
377
|
+
declare function defineDropHandler(handler: DropHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
378
|
+
export { defineDropHandler }
|
379
|
+
export { defineDropHandler as defineDropHandler_alias_1 }
|
380
|
+
|
314
381
|
/**
|
315
382
|
* Registers a event handler that is called when the editor gains or loses focus.
|
316
383
|
*
|
@@ -332,6 +399,15 @@ redo: [];
|
|
332
399
|
export { defineHistory }
|
333
400
|
export { defineHistory as defineHistory_alias_1 }
|
334
401
|
|
402
|
+
/**
|
403
|
+
* @public
|
404
|
+
*
|
405
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyDown}
|
406
|
+
*/
|
407
|
+
declare function defineKeyDownHandler(handler: KeyDownHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
408
|
+
export { defineKeyDownHandler }
|
409
|
+
export { defineKeyDownHandler as defineKeyDownHandler_alias_1 }
|
410
|
+
|
335
411
|
/**
|
336
412
|
* @public
|
337
413
|
*/
|
@@ -339,6 +415,15 @@ declare function defineKeymap(keymap: Keymap): Extension;
|
|
339
415
|
export { defineKeymap }
|
340
416
|
export { defineKeymap as defineKeymap_alias_1 }
|
341
417
|
|
418
|
+
/**
|
419
|
+
* @public
|
420
|
+
*
|
421
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyPress}
|
422
|
+
*/
|
423
|
+
declare function defineKeyPressHandler(handler: KeyPressHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
424
|
+
export { defineKeyPressHandler }
|
425
|
+
export { defineKeyPressHandler as defineKeyPressHandler_alias_1 }
|
426
|
+
|
342
427
|
/**
|
343
428
|
* @public
|
344
429
|
*/
|
@@ -415,6 +500,15 @@ export declare function defineParagraphSpec(): Extension< {
|
|
415
500
|
NODES: "paragraph";
|
416
501
|
}>;
|
417
502
|
|
503
|
+
/**
|
504
|
+
* @public
|
505
|
+
*
|
506
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handlePaste}
|
507
|
+
*/
|
508
|
+
declare function definePasteHandler(handler: PasteHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
509
|
+
export { definePasteHandler }
|
510
|
+
export { definePasteHandler as definePasteHandler_alias_1 }
|
511
|
+
|
418
512
|
/**
|
419
513
|
* Adds a ProseMirror plugin to the editor.
|
420
514
|
*
|
@@ -429,6 +523,15 @@ declare function definePlugin(plugin: Plugin_2 | Plugin_2[] | ((context: {
|
|
429
523
|
export { definePlugin }
|
430
524
|
export { definePlugin as definePlugin_alias_1 }
|
431
525
|
|
526
|
+
/**
|
527
|
+
* @public
|
528
|
+
*
|
529
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleScrollToSelection}
|
530
|
+
*/
|
531
|
+
declare function defineScrollToSelectionHandler(handler: ScrollToSelectionHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
532
|
+
export { defineScrollToSelectionHandler }
|
533
|
+
export { defineScrollToSelectionHandler as defineScrollToSelectionHandler_alias_1 }
|
534
|
+
|
432
535
|
/**
|
433
536
|
* @public
|
434
537
|
*/
|
@@ -438,6 +541,33 @@ NODES: "text";
|
|
438
541
|
export { defineText }
|
439
542
|
export { defineText as defineText_alias_1 }
|
440
543
|
|
544
|
+
/**
|
545
|
+
* @public
|
546
|
+
*
|
547
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleTextInput}
|
548
|
+
*/
|
549
|
+
declare function defineTextInputHandler(handler: TextInputHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
550
|
+
export { defineTextInputHandler }
|
551
|
+
export { defineTextInputHandler as defineTextInputHandler_alias_1 }
|
552
|
+
|
553
|
+
/**
|
554
|
+
* @public
|
555
|
+
*
|
556
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleTripleClick}
|
557
|
+
*/
|
558
|
+
declare function defineTripleClickHandler(handler: TripleClickHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
559
|
+
export { defineTripleClickHandler }
|
560
|
+
export { defineTripleClickHandler as defineTripleClickHandler_alias_1 }
|
561
|
+
|
562
|
+
/**
|
563
|
+
* @public
|
564
|
+
*
|
565
|
+
* See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleTripleClickOn}
|
566
|
+
*/
|
567
|
+
declare function defineTripleClickOnHandler(handler: TripleClickOnHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
568
|
+
export { defineTripleClickOnHandler }
|
569
|
+
export { defineTripleClickOnHandler as defineTripleClickOnHandler_alias_1 }
|
570
|
+
|
441
571
|
/**
|
442
572
|
* Registers a event handler that is called when the editor view is unmounted.
|
443
573
|
*
|
@@ -468,6 +598,40 @@ declare type DocChangeHandler = (view: EditorView, prevState: EditorState) => vo
|
|
468
598
|
export { DocChangeHandler }
|
469
599
|
export { DocChangeHandler as DocChangeHandler_alias_1 }
|
470
600
|
|
601
|
+
/**
|
602
|
+
* @internal
|
603
|
+
*/
|
604
|
+
export declare const domEventFacet: Facet<DOMEventPayload, PluginPayload>;
|
605
|
+
|
606
|
+
/**
|
607
|
+
* A function to handle the events fired on the editable DOM element. Returns
|
608
|
+
* `true` to indicate that it handled the given event. you are responsible for
|
609
|
+
* calling `preventDefault` yourself (or not, if you want to allow the default
|
610
|
+
* behavior).
|
611
|
+
*
|
612
|
+
* @public
|
613
|
+
*/
|
614
|
+
declare type DOMEventHandler<Event extends keyof DOMEventMap = string> = (view: EditorView, event: DOMEventMap[Event]) => boolean | void;
|
615
|
+
export { DOMEventHandler }
|
616
|
+
export { DOMEventHandler as DOMEventHandler_alias_1 }
|
617
|
+
|
618
|
+
/**
|
619
|
+
* @internal
|
620
|
+
*/
|
621
|
+
export declare type DOMEventPayload = [event: string, handler: DOMEventHandler];
|
622
|
+
|
623
|
+
declare type DoubleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
|
624
|
+
export { DoubleClickHandler }
|
625
|
+
export { DoubleClickHandler as DoubleClickHandler_alias_1 }
|
626
|
+
|
627
|
+
declare type DoubleClickOnHandler = (view: EditorView, pos: number, node: Node_3, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
|
628
|
+
export { DoubleClickOnHandler }
|
629
|
+
export { DoubleClickOnHandler as DoubleClickOnHandler_alias_1 }
|
630
|
+
|
631
|
+
declare type DropHandler = (view: EditorView, event: DragEvent, slice: Slice, moved: boolean) => boolean | void;
|
632
|
+
export { DropHandler }
|
633
|
+
export { DropHandler as DropHandler_alias_1 }
|
634
|
+
|
471
635
|
/**
|
472
636
|
* @public
|
473
637
|
*/
|
@@ -768,6 +932,12 @@ declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
|
|
768
932
|
export { getNodeType }
|
769
933
|
export { getNodeType as getNodeType_alias_1 }
|
770
934
|
|
935
|
+
export declare type GroupedEntries<T extends Record<string, any>> = {
|
936
|
+
[K in keyof T]?: T[K][];
|
937
|
+
};
|
938
|
+
|
939
|
+
export declare function groupEntries<T extends Record<string, any>>(entries: ObjectEntries<T>[]): GroupedEntries<T>;
|
940
|
+
|
771
941
|
/**
|
772
942
|
* Returns a command that inserts the given node at the current selection or at
|
773
943
|
* the given position.
|
@@ -897,6 +1067,10 @@ declare function jsonFromState(state: EditorState): StateJSON;
|
|
897
1067
|
export { jsonFromState }
|
898
1068
|
export { jsonFromState as jsonFromState_alias_1 }
|
899
1069
|
|
1070
|
+
declare type KeyDownHandler = (view: EditorView, event: KeyboardEvent) => boolean | void;
|
1071
|
+
export { KeyDownHandler }
|
1072
|
+
export { KeyDownHandler as KeyDownHandler_alias_1 }
|
1073
|
+
|
900
1074
|
/**
|
901
1075
|
* @public
|
902
1076
|
*/
|
@@ -920,6 +1094,10 @@ declare type KeymapPayload = Keymap;
|
|
920
1094
|
export { KeymapPayload }
|
921
1095
|
export { KeymapPayload as KeymapPayload_alias_1 }
|
922
1096
|
|
1097
|
+
declare type KeyPressHandler = (view: EditorView, event: KeyboardEvent) => boolean | void;
|
1098
|
+
export { KeyPressHandler }
|
1099
|
+
export { KeyPressHandler as KeyPressHandler_alias_1 }
|
1100
|
+
|
923
1101
|
/**
|
924
1102
|
* @public
|
925
1103
|
*/
|
@@ -1097,8 +1275,27 @@ declare const OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
|
|
1097
1275
|
export { OBJECT_REPLACEMENT_CHARACTER }
|
1098
1276
|
export { OBJECT_REPLACEMENT_CHARACTER as OBJECT_REPLACEMENT_CHARACTER_alias_1 }
|
1099
1277
|
|
1278
|
+
/**
|
1279
|
+
* @internal
|
1280
|
+
*
|
1281
|
+
* @example
|
1282
|
+
*
|
1283
|
+
* ```
|
1284
|
+
* type MyObject = { a: 1; b: 'B' }
|
1285
|
+
* type MyEntries = ObjectEntries<MyObject>
|
1286
|
+
* // ^ ["a", 1] | ["b", "B"]
|
1287
|
+
*
|
1288
|
+
*/
|
1289
|
+
export declare type ObjectEntries<T extends Record<string, any>> = {
|
1290
|
+
[K in keyof T]: [K, T[K]];
|
1291
|
+
}[keyof T];
|
1292
|
+
|
1100
1293
|
export declare function objectEqual<T>(a: T, b: T): boolean;
|
1101
1294
|
|
1295
|
+
declare type PasteHandler = (view: EditorView, event: ClipboardEvent, slice: Slice) => boolean | void;
|
1296
|
+
export { PasteHandler }
|
1297
|
+
export { PasteHandler as PasteHandler_alias_1 }
|
1298
|
+
|
1102
1299
|
declare type Payload = unknown;
|
1103
1300
|
|
1104
1301
|
export declare type Payloads = PayloadTuple[];
|
@@ -1176,6 +1373,10 @@ export declare const schemaFacet: Facet<SchemaPayload, SchemaPayload>;
|
|
1176
1373
|
|
1177
1374
|
export declare type SchemaPayload = SchemaSpec;
|
1178
1375
|
|
1376
|
+
declare type ScrollToSelectionHandler = (view: EditorView) => boolean;
|
1377
|
+
export { ScrollToSelectionHandler }
|
1378
|
+
export { ScrollToSelectionHandler as ScrollToSelectionHandler_alias_1 }
|
1379
|
+
|
1179
1380
|
/**
|
1180
1381
|
* Returns a command that selects the whole document.
|
1181
1382
|
*
|
@@ -1238,6 +1439,11 @@ export { setNodeAttrs as setNodeAttrs_alias_1 }
|
|
1238
1439
|
|
1239
1440
|
export declare function setSelectionAround(tr: Transaction, pos: number): void;
|
1240
1441
|
|
1442
|
+
/**
|
1443
|
+
* @internal
|
1444
|
+
*/
|
1445
|
+
export declare type Setter<T> = (value: T) => void;
|
1446
|
+
|
1241
1447
|
/**
|
1242
1448
|
* @internal
|
1243
1449
|
*/
|
@@ -1289,6 +1495,10 @@ export declare type StatePayload = (ctx: {
|
|
1289
1495
|
schema: Schema;
|
1290
1496
|
}) => EditorStateConfig;
|
1291
1497
|
|
1498
|
+
declare type TextInputHandler = (view: EditorView, from: number, to: number, text: string) => boolean | void;
|
1499
|
+
export { TextInputHandler }
|
1500
|
+
export { TextInputHandler as TextInputHandler_alias_1 }
|
1501
|
+
|
1292
1502
|
export declare type ToCommandApplier<T extends CommandArgs> = {
|
1293
1503
|
[K in keyof T]: CommandApplier<T[K]>;
|
1294
1504
|
};
|
@@ -1326,6 +1536,14 @@ declare function toggleNode({ type, attrs, }: {
|
|
1326
1536
|
export { toggleNode }
|
1327
1537
|
export { toggleNode as toggleNode_alias_1 }
|
1328
1538
|
|
1539
|
+
declare type TripleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
|
1540
|
+
export { TripleClickHandler }
|
1541
|
+
export { TripleClickHandler as TripleClickHandler_alias_1 }
|
1542
|
+
|
1543
|
+
declare type TripleClickOnHandler = (view: EditorView, pos: number, node: Node_3, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
|
1544
|
+
export { TripleClickOnHandler }
|
1545
|
+
export { TripleClickOnHandler as TripleClickOnHandler_alias_1 }
|
1546
|
+
|
1329
1547
|
declare type Tuple5<T> = [T, T, T, T, T];
|
1330
1548
|
|
1331
1549
|
/**
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -20,6 +20,32 @@ export { DefaultStateOptions } from './_tsup-dts-rollup';
|
|
20
20
|
export { defineDoc } from './_tsup-dts-rollup';
|
21
21
|
export { defineDocChangeHandler } from './_tsup-dts-rollup';
|
22
22
|
export { DocChangeHandler } from './_tsup-dts-rollup';
|
23
|
+
export { defineDOMEventHandler } from './_tsup-dts-rollup';
|
24
|
+
export { DOMEventHandler } from './_tsup-dts-rollup';
|
25
|
+
export { defineClickHandler } from './_tsup-dts-rollup';
|
26
|
+
export { defineClickOnHandler } from './_tsup-dts-rollup';
|
27
|
+
export { defineDoubleClickHandler } from './_tsup-dts-rollup';
|
28
|
+
export { defineDoubleClickOnHandler } from './_tsup-dts-rollup';
|
29
|
+
export { defineDropHandler } from './_tsup-dts-rollup';
|
30
|
+
export { defineKeyDownHandler } from './_tsup-dts-rollup';
|
31
|
+
export { defineKeyPressHandler } from './_tsup-dts-rollup';
|
32
|
+
export { definePasteHandler } from './_tsup-dts-rollup';
|
33
|
+
export { defineScrollToSelectionHandler } from './_tsup-dts-rollup';
|
34
|
+
export { defineTextInputHandler } from './_tsup-dts-rollup';
|
35
|
+
export { defineTripleClickHandler } from './_tsup-dts-rollup';
|
36
|
+
export { defineTripleClickOnHandler } from './_tsup-dts-rollup';
|
37
|
+
export { ClickHandler } from './_tsup-dts-rollup';
|
38
|
+
export { ClickOnHandler } from './_tsup-dts-rollup';
|
39
|
+
export { DoubleClickHandler } from './_tsup-dts-rollup';
|
40
|
+
export { DoubleClickOnHandler } from './_tsup-dts-rollup';
|
41
|
+
export { DropHandler } from './_tsup-dts-rollup';
|
42
|
+
export { KeyDownHandler } from './_tsup-dts-rollup';
|
43
|
+
export { KeyPressHandler } from './_tsup-dts-rollup';
|
44
|
+
export { PasteHandler } from './_tsup-dts-rollup';
|
45
|
+
export { ScrollToSelectionHandler } from './_tsup-dts-rollup';
|
46
|
+
export { TextInputHandler } from './_tsup-dts-rollup';
|
47
|
+
export { TripleClickHandler } from './_tsup-dts-rollup';
|
48
|
+
export { TripleClickOnHandler } from './_tsup-dts-rollup';
|
23
49
|
export { defineFocusChangeHandler } from './_tsup-dts-rollup';
|
24
50
|
export { FocusChangeHandler } from './_tsup-dts-rollup';
|
25
51
|
export { defineMountHandler } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -1442,21 +1442,201 @@ function defineDocChangeHandler(handler) {
|
|
1442
1442
|
});
|
1443
1443
|
}
|
1444
1444
|
|
1445
|
-
// src/extensions/events/
|
1445
|
+
// src/extensions/events/dom-event.ts
|
1446
1446
|
import { PluginKey as PluginKey2, ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1447
|
+
|
1448
|
+
// src/utils/combine-event-handlers.ts
|
1449
|
+
function combineEventHandlers() {
|
1450
|
+
let _handlers = [];
|
1451
|
+
function setHandlers(handlers) {
|
1452
|
+
_handlers = handlers;
|
1453
|
+
}
|
1454
|
+
function combinedEventHandler(...args) {
|
1455
|
+
for (const handler of _handlers) {
|
1456
|
+
if (handler(...args)) {
|
1457
|
+
return true;
|
1458
|
+
}
|
1459
|
+
}
|
1460
|
+
return false;
|
1461
|
+
}
|
1462
|
+
return [setHandlers, combinedEventHandler];
|
1463
|
+
}
|
1464
|
+
|
1465
|
+
// src/utils/group-entries.ts
|
1466
|
+
function groupEntries(entries) {
|
1467
|
+
const map = {};
|
1468
|
+
for (const [key, value] of entries) {
|
1469
|
+
const values = map[key];
|
1470
|
+
if (!values) {
|
1471
|
+
map[key] = [value];
|
1472
|
+
} else {
|
1473
|
+
values.push(value);
|
1474
|
+
}
|
1475
|
+
}
|
1476
|
+
return map;
|
1477
|
+
}
|
1478
|
+
|
1479
|
+
// src/extensions/events/dom-event.ts
|
1480
|
+
function defineDOMEventHandler(event, handler) {
|
1481
|
+
return domEventFacet.extension([
|
1482
|
+
[event, handler]
|
1483
|
+
]);
|
1484
|
+
}
|
1485
|
+
var domEventFacet = Facet.define({
|
1486
|
+
converter: () => {
|
1487
|
+
const setHandlersMap = {};
|
1488
|
+
const combinedHandlerMap = {};
|
1489
|
+
const update = (payloads) => {
|
1490
|
+
let hasNewEvent = false;
|
1491
|
+
for (const [event] of payloads) {
|
1492
|
+
if (!setHandlersMap[event]) {
|
1493
|
+
hasNewEvent = true;
|
1494
|
+
const [setHandlers, combinedHandler] = combineEventHandlers();
|
1495
|
+
setHandlersMap[event] = setHandlers;
|
1496
|
+
combinedHandlerMap[event] = combinedHandler;
|
1497
|
+
}
|
1498
|
+
}
|
1499
|
+
const map = groupEntries(payloads);
|
1500
|
+
for (const [event, handlers] of Object.entries(map)) {
|
1501
|
+
const setHandlers = setHandlersMap[event];
|
1502
|
+
setHandlers(handlers != null ? handlers : []);
|
1503
|
+
}
|
1504
|
+
if (hasNewEvent) {
|
1505
|
+
return new ProseMirrorPlugin2({
|
1506
|
+
key: new PluginKey2("prosekit-dom-event-handler"),
|
1507
|
+
props: { handleDOMEvents: combinedHandlerMap }
|
1508
|
+
});
|
1509
|
+
} else {
|
1510
|
+
return null;
|
1511
|
+
}
|
1512
|
+
};
|
1513
|
+
return {
|
1514
|
+
create: (payloads) => {
|
1515
|
+
const plugin = update(payloads);
|
1516
|
+
return plugin ? () => plugin : () => [];
|
1517
|
+
},
|
1518
|
+
update: (payloads) => {
|
1519
|
+
const plugin = update(payloads);
|
1520
|
+
return plugin ? () => plugin : null;
|
1521
|
+
}
|
1522
|
+
};
|
1523
|
+
},
|
1524
|
+
next: pluginFacet,
|
1525
|
+
singleton: true
|
1526
|
+
});
|
1527
|
+
|
1528
|
+
// src/extensions/events/editor-event.ts
|
1529
|
+
import { PluginKey as PluginKey3, ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state";
|
1530
|
+
function defineKeyDownHandler(handler) {
|
1531
|
+
return editorEventFacet.extension([["keyDown", handler]]);
|
1532
|
+
}
|
1533
|
+
function defineKeyPressHandler(handler) {
|
1534
|
+
return editorEventFacet.extension([["keyPress", handler]]);
|
1535
|
+
}
|
1536
|
+
function defineTextInputHandler(handler) {
|
1537
|
+
return editorEventFacet.extension([["textInput", handler]]);
|
1538
|
+
}
|
1539
|
+
function defineClickOnHandler(handler) {
|
1540
|
+
return editorEventFacet.extension([["clickOn", handler]]);
|
1541
|
+
}
|
1542
|
+
function defineClickHandler(handler) {
|
1543
|
+
return editorEventFacet.extension([["click", handler]]);
|
1544
|
+
}
|
1545
|
+
function defineDoubleClickOnHandler(handler) {
|
1546
|
+
return editorEventFacet.extension([["doubleClickOn", handler]]);
|
1547
|
+
}
|
1548
|
+
function defineDoubleClickHandler(handler) {
|
1549
|
+
return editorEventFacet.extension([["doubleClick", handler]]);
|
1550
|
+
}
|
1551
|
+
function defineTripleClickOnHandler(handler) {
|
1552
|
+
return editorEventFacet.extension([["tripleClickOn", handler]]);
|
1553
|
+
}
|
1554
|
+
function defineTripleClickHandler(handler) {
|
1555
|
+
return editorEventFacet.extension([["tripleClick", handler]]);
|
1556
|
+
}
|
1557
|
+
function definePasteHandler(handler) {
|
1558
|
+
return editorEventFacet.extension([["paste", handler]]);
|
1559
|
+
}
|
1560
|
+
function defineDropHandler(handler) {
|
1561
|
+
return editorEventFacet.extension([["drop", handler]]);
|
1562
|
+
}
|
1563
|
+
function defineScrollToSelectionHandler(handler) {
|
1564
|
+
return editorEventFacet.extension([["scrollToSelection", handler]]);
|
1565
|
+
}
|
1566
|
+
var editorEventFacet = Facet.define({
|
1567
|
+
converter: () => {
|
1568
|
+
const [update, plugin] = setupEditorEventPlugin();
|
1569
|
+
return {
|
1570
|
+
create: (entries) => {
|
1571
|
+
update(entries);
|
1572
|
+
return () => plugin;
|
1573
|
+
},
|
1574
|
+
update: (entries) => {
|
1575
|
+
update(entries);
|
1576
|
+
return null;
|
1456
1577
|
}
|
1578
|
+
};
|
1579
|
+
},
|
1580
|
+
next: pluginFacet,
|
1581
|
+
singleton: true
|
1582
|
+
});
|
1583
|
+
function setupEditorEventPlugin() {
|
1584
|
+
const [setKeyDownHandlers, handleKeyDown] = combineEventHandlers();
|
1585
|
+
const [setKeyPressHandlers, handleKeyPress] = combineEventHandlers();
|
1586
|
+
const [setTextInputHandlers, handleTextInput] = combineEventHandlers();
|
1587
|
+
const [setClickOnHandlers, handleClickOn] = combineEventHandlers();
|
1588
|
+
const [setClickHandlers, handleClick] = combineEventHandlers();
|
1589
|
+
const [setDoubleClickOnHandlers, handleDoubleClickOn] = combineEventHandlers();
|
1590
|
+
const [setDoubleClickHandlers, handleDoubleClick] = combineEventHandlers();
|
1591
|
+
const [setTripleClickOnHandlers, handleTripleClickOn] = combineEventHandlers();
|
1592
|
+
const [setTripleClickHandlers, handleTripleClick] = combineEventHandlers();
|
1593
|
+
const [setPasteHandlers, handlePaste] = combineEventHandlers();
|
1594
|
+
const [setDropHandlers, handleDrop] = combineEventHandlers();
|
1595
|
+
const [setScrollToSelectionHandlers, handleScrollToSelection] = combineEventHandlers();
|
1596
|
+
const update = (entries) => {
|
1597
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
1598
|
+
const map = groupEntries(entries);
|
1599
|
+
setKeyDownHandlers((_a = map.keyDown) != null ? _a : []);
|
1600
|
+
setKeyPressHandlers((_b = map.keyPress) != null ? _b : []);
|
1601
|
+
setTextInputHandlers((_c = map.textInput) != null ? _c : []);
|
1602
|
+
setClickOnHandlers((_d = map.clickOn) != null ? _d : []);
|
1603
|
+
setClickHandlers((_e = map.click) != null ? _e : []);
|
1604
|
+
setDoubleClickOnHandlers((_f = map.doubleClickOn) != null ? _f : []);
|
1605
|
+
setDoubleClickHandlers((_g = map.doubleClick) != null ? _g : []);
|
1606
|
+
setTripleClickOnHandlers((_h = map.tripleClickOn) != null ? _h : []);
|
1607
|
+
setTripleClickHandlers((_i = map.tripleClick) != null ? _i : []);
|
1608
|
+
setPasteHandlers((_j = map.paste) != null ? _j : []);
|
1609
|
+
setDropHandlers((_k = map.drop) != null ? _k : []);
|
1610
|
+
setScrollToSelectionHandlers((_l = map.scrollToSelection) != null ? _l : []);
|
1611
|
+
};
|
1612
|
+
const plugin = new ProseMirrorPlugin3({
|
1613
|
+
key: new PluginKey3("prosekit-editor-handler"),
|
1614
|
+
props: {
|
1615
|
+
handleKeyDown,
|
1616
|
+
handleKeyPress,
|
1617
|
+
handleTextInput,
|
1618
|
+
handleClickOn,
|
1619
|
+
handleClick,
|
1620
|
+
handleDoubleClickOn,
|
1621
|
+
handleDoubleClick,
|
1622
|
+
handleTripleClickOn,
|
1623
|
+
handleTripleClick,
|
1624
|
+
handlePaste,
|
1625
|
+
handleDrop,
|
1626
|
+
handleScrollToSelection
|
1457
1627
|
}
|
1458
1628
|
});
|
1459
|
-
return
|
1629
|
+
return [update, plugin];
|
1630
|
+
}
|
1631
|
+
|
1632
|
+
// src/extensions/events/focus.ts
|
1633
|
+
function defineFocusChangeHandler(handler) {
|
1634
|
+
const handleFocus = () => handler(true);
|
1635
|
+
const handleBlur = () => handler(false);
|
1636
|
+
return domEventFacet.extension([
|
1637
|
+
["focus", handleFocus],
|
1638
|
+
["blur", handleBlur]
|
1639
|
+
]);
|
1460
1640
|
}
|
1461
1641
|
|
1462
1642
|
// src/extensions/history.ts
|
@@ -1468,7 +1648,7 @@ var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigat
|
|
1468
1648
|
// src/extensions/keymap.ts
|
1469
1649
|
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
1470
1650
|
import { keydownHandler } from "@prosekit/pm/keymap";
|
1471
|
-
import { Plugin as Plugin3, PluginKey as
|
1651
|
+
import { Plugin as Plugin3, PluginKey as PluginKey4 } from "@prosekit/pm/state";
|
1472
1652
|
function defineKeymap(keymap) {
|
1473
1653
|
return keymapFacet.extension([keymap]);
|
1474
1654
|
}
|
@@ -1519,7 +1699,7 @@ function mergeKeymaps(keymaps) {
|
|
1519
1699
|
])
|
1520
1700
|
);
|
1521
1701
|
}
|
1522
|
-
var keymapPluginKey = new
|
1702
|
+
var keymapPluginKey = new PluginKey4("prosekit-keymap");
|
1523
1703
|
|
1524
1704
|
// src/extensions/history.ts
|
1525
1705
|
function defineHistory() {
|
@@ -1632,7 +1812,7 @@ var markSpecFacet = Facet.define({
|
|
1632
1812
|
});
|
1633
1813
|
|
1634
1814
|
// src/extensions/node-view.ts
|
1635
|
-
import { ProseMirrorPlugin as
|
1815
|
+
import { ProseMirrorPlugin as ProseMirrorPlugin4 } from "@prosekit/pm/state";
|
1636
1816
|
import "@prosekit/pm/view";
|
1637
1817
|
function defineNodeView(options) {
|
1638
1818
|
return nodeViewFacet.extension([options]);
|
@@ -1645,13 +1825,13 @@ var nodeViewFacet = Facet.define({
|
|
1645
1825
|
nodeViews[input.name] = input.constructor;
|
1646
1826
|
}
|
1647
1827
|
}
|
1648
|
-
return () => [new
|
1828
|
+
return () => [new ProseMirrorPlugin4({ props: { nodeViews } })];
|
1649
1829
|
},
|
1650
1830
|
next: pluginFacet
|
1651
1831
|
});
|
1652
1832
|
|
1653
1833
|
// src/extensions/node-view-effect.ts
|
1654
|
-
import { ProseMirrorPlugin as
|
1834
|
+
import { ProseMirrorPlugin as ProseMirrorPlugin5 } from "@prosekit/pm/state";
|
1655
1835
|
import "@prosekit/pm/view";
|
1656
1836
|
function defineNodeViewFactory(options) {
|
1657
1837
|
return nodeViewFactoryFacet.extension([options]);
|
@@ -1679,7 +1859,7 @@ var nodeViewFactoryFacet = Facet.define({
|
|
1679
1859
|
nodeViews[name] = factory(args);
|
1680
1860
|
}
|
1681
1861
|
}
|
1682
|
-
return () => [new
|
1862
|
+
return () => [new ProseMirrorPlugin5({ props: { nodeViews } })];
|
1683
1863
|
},
|
1684
1864
|
next: pluginFacet
|
1685
1865
|
});
|
@@ -1763,12 +1943,20 @@ export {
|
|
1763
1943
|
defaultBlockAt,
|
1764
1944
|
defineBaseCommands,
|
1765
1945
|
defineBaseKeymap,
|
1946
|
+
defineClickHandler,
|
1947
|
+
defineClickOnHandler,
|
1766
1948
|
defineCommands,
|
1949
|
+
defineDOMEventHandler,
|
1767
1950
|
defineDefaultState,
|
1768
1951
|
defineDoc,
|
1769
1952
|
defineDocChangeHandler,
|
1953
|
+
defineDoubleClickHandler,
|
1954
|
+
defineDoubleClickOnHandler,
|
1955
|
+
defineDropHandler,
|
1770
1956
|
defineFocusChangeHandler,
|
1771
1957
|
defineHistory,
|
1958
|
+
defineKeyDownHandler,
|
1959
|
+
defineKeyPressHandler,
|
1772
1960
|
defineKeymap,
|
1773
1961
|
defineMarkAttr,
|
1774
1962
|
defineMarkSpec,
|
@@ -1778,8 +1966,13 @@ export {
|
|
1778
1966
|
defineNodeView,
|
1779
1967
|
defineNodeViewFactory,
|
1780
1968
|
defineParagraph,
|
1969
|
+
definePasteHandler,
|
1781
1970
|
definePlugin,
|
1971
|
+
defineScrollToSelectionHandler,
|
1782
1972
|
defineText,
|
1973
|
+
defineTextInputHandler,
|
1974
|
+
defineTripleClickHandler,
|
1975
|
+
defineTripleClickOnHandler,
|
1783
1976
|
defineUnmountHandler,
|
1784
1977
|
defineUpdateHandler,
|
1785
1978
|
expandMark,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/core",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.3.
|
4
|
+
"version": "0.3.1",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -42,7 +42,7 @@
|
|
42
42
|
},
|
43
43
|
"devDependencies": {
|
44
44
|
"@prosekit/dev": "*",
|
45
|
-
"tsup": "^8.0.
|
45
|
+
"tsup": "^8.0.2",
|
46
46
|
"typescript": "^5.3.3",
|
47
47
|
"vitest": "^1.2.2"
|
48
48
|
},
|