@prosekit/extensions 0.8.0 → 0.9.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/commit/style.css +1 -1
- package/dist/commit/style.js +0 -0
- package/dist/enter-rule-RdhEA900.js +96 -0
- package/dist/gap-cursor/style.css +6 -3
- package/dist/gap-cursor/style.js +0 -0
- package/dist/input-rule-Gji4N7Oe.js +93 -0
- package/dist/list/style.css +7 -7
- package/dist/list/style.js +0 -0
- package/dist/loro/style.css +13 -9
- package/dist/loro/style.js +0 -0
- package/dist/mark-rule-wEOcDt6i.js +160 -0
- package/dist/placeholder/style.css +3 -3
- package/dist/placeholder/style.js +0 -0
- package/dist/prosekit-extensions-autocomplete.d.ts +33 -3
- package/dist/prosekit-extensions-autocomplete.js +126 -174
- package/dist/prosekit-extensions-blockquote.d.ts +48 -8
- package/dist/prosekit-extensions-blockquote.js +64 -78
- package/dist/prosekit-extensions-bold.d.ts +54 -8
- package/dist/prosekit-extensions-bold.js +61 -73
- package/dist/prosekit-extensions-code-block.d.ts +159 -20
- package/dist/prosekit-extensions-code-block.js +201 -184
- package/dist/prosekit-extensions-code.d.ts +54 -8
- package/dist/prosekit-extensions-code.js +44 -56
- package/dist/prosekit-extensions-commit.d.ts +52 -4
- package/dist/prosekit-extensions-commit.js +140 -183
- package/dist/prosekit-extensions-doc.d.ts +19 -2
- package/dist/prosekit-extensions-doc.js +14 -12
- package/dist/prosekit-extensions-drop-cursor.d.ts +35 -3
- package/dist/prosekit-extensions-drop-cursor.js +14 -8
- package/dist/prosekit-extensions-enter-rule.d.ts +105 -5
- package/dist/prosekit-extensions-enter-rule.js +3 -8
- package/dist/prosekit-extensions-file.d.ts +129 -8
- package/dist/prosekit-extensions-file.js +124 -132
- package/dist/prosekit-extensions-gap-cursor.d.ts +26 -2
- package/dist/prosekit-extensions-gap-cursor.js +21 -9
- package/dist/prosekit-extensions-hard-break.d.ts +53 -0
- package/dist/prosekit-extensions-hard-break.js +58 -0
- package/dist/prosekit-extensions-heading.d.ts +63 -9
- package/dist/prosekit-extensions-heading.js +121 -95
- package/dist/prosekit-extensions-horizontal-rule.d.ts +38 -8
- package/dist/prosekit-extensions-horizontal-rule.js +53 -71
- package/dist/prosekit-extensions-image.d.ts +50 -7
- package/dist/prosekit-extensions-image.js +71 -62
- package/dist/prosekit-extensions-input-rule.d.ts +129 -6
- package/dist/prosekit-extensions-input-rule.js +3 -14
- package/dist/prosekit-extensions-italic.d.ts +54 -8
- package/dist/prosekit-extensions-italic.js +51 -63
- package/dist/prosekit-extensions-link.d.ts +62 -10
- package/dist/prosekit-extensions-link.js +95 -100
- package/dist/prosekit-extensions-list.d.ts +104 -17
- package/dist/prosekit-extensions-list.js +115 -158
- package/dist/prosekit-extensions-loro.d.ts +69 -11
- package/dist/prosekit-extensions-loro.js +49 -77
- package/dist/prosekit-extensions-mark-rule.d.ts +37 -2
- package/dist/prosekit-extensions-mark-rule.js +3 -6
- package/dist/prosekit-extensions-mention.d.ts +39 -4
- package/dist/prosekit-extensions-mention.js +52 -50
- package/dist/prosekit-extensions-mod-click-prevention.d.ts +17 -2
- package/dist/prosekit-extensions-mod-click-prevention.js +20 -16
- package/dist/prosekit-extensions-paragraph.d.ts +60 -7
- package/dist/prosekit-extensions-paragraph.js +46 -45
- package/dist/prosekit-extensions-placeholder.d.ts +33 -2
- package/dist/prosekit-extensions-placeholder.js +39 -56
- package/dist/prosekit-extensions-readonly.d.ts +10 -1
- package/dist/prosekit-extensions-readonly.js +13 -14
- package/dist/prosekit-extensions-search.d.ts +74 -3
- package/dist/prosekit-extensions-search.js +48 -47
- package/dist/prosekit-extensions-strike.d.ts +47 -8
- package/dist/prosekit-extensions-strike.js +44 -49
- package/dist/prosekit-extensions-table.d.ts +231 -26
- package/dist/prosekit-extensions-table.js +3 -34
- package/dist/prosekit-extensions-text-align.d.ts +71 -8
- package/dist/prosekit-extensions-text-align.js +63 -44
- package/dist/prosekit-extensions-text.d.ts +19 -2
- package/dist/prosekit-extensions-text.js +13 -11
- package/dist/prosekit-extensions-underline.d.ts +43 -7
- package/dist/prosekit-extensions-underline.js +33 -37
- package/dist/prosekit-extensions-virtual-selection.d.ts +21 -2
- package/dist/prosekit-extensions-virtual-selection.js +49 -52
- package/dist/prosekit-extensions-yjs.d.ts +90 -14
- package/dist/prosekit-extensions-yjs.js +88 -131
- package/dist/prosekit-extensions.d.ts +1 -1
- package/dist/search/style.css +4 -3
- package/dist/search/style.js +0 -0
- package/dist/shiki-highlighter-chunk-CZGvZlhf.d.ts +18 -0
- package/dist/shiki-highlighter-chunk.d.ts +2 -0
- package/dist/shiki-highlighter-chunk.js +32 -39
- package/dist/table/style.css +10 -13
- package/dist/table/style.js +0 -0
- package/dist/table-DnVliJ6E.js +287 -0
- package/dist/virtual-selection/style.css +2 -2
- package/dist/virtual-selection/style.js +0 -0
- package/dist/yjs/style.css +9 -8
- package/dist/yjs/style.js +0 -0
- package/package.json +81 -54
- package/dist/_tsup-dts-rollup.d.ts +0 -2459
- package/dist/chunk-6UYLCVBX.js +0 -185
- package/dist/chunk-D54VSLLS.js +0 -105
- package/dist/chunk-I2UMHK3L.js +0 -99
- package/dist/chunk-QVFEYPQ6.js +0 -306
@@ -1,8 +1,129 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
import { PlainExtension } from "@prosekit/core";
|
2
|
+
import { EditorView } from "@prosekit/pm/view";
|
3
|
+
|
4
|
+
//#region src/file/file-drop-handler.d.ts
|
5
|
+
interface FileDropHandlerOptions {
|
6
|
+
/**
|
7
|
+
* The editor view.
|
8
|
+
*/
|
9
|
+
view: EditorView;
|
10
|
+
/**
|
11
|
+
* The event that triggered the drop.
|
12
|
+
*/
|
13
|
+
event: DragEvent;
|
14
|
+
/**
|
15
|
+
* The file that was dropped.
|
16
|
+
*/
|
17
|
+
file: File;
|
18
|
+
/**
|
19
|
+
* The position of the document where the file was dropped.
|
20
|
+
*/
|
21
|
+
pos: number;
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* A function that handles one of the files in a drop event.
|
25
|
+
*
|
26
|
+
* Returns `true` if the file was handled and thus should not be handled by
|
27
|
+
* other handlers.
|
28
|
+
*/
|
29
|
+
type FileDropHandler = (options: FileDropHandlerOptions) => boolean | void;
|
30
|
+
declare function defineFileDropHandler(handler: FileDropHandler): PlainExtension;
|
31
|
+
//#endregion
|
32
|
+
//#region src/file/file-paste-handler.d.ts
|
33
|
+
interface FilePasteHandlerOptions {
|
34
|
+
/**
|
35
|
+
* The editor view.
|
36
|
+
*/
|
37
|
+
view: EditorView;
|
38
|
+
/**
|
39
|
+
* The event that triggered the paste.
|
40
|
+
*/
|
41
|
+
event: ClipboardEvent;
|
42
|
+
/**
|
43
|
+
* The file that was pasted.
|
44
|
+
*/
|
45
|
+
file: File;
|
46
|
+
}
|
47
|
+
/**
|
48
|
+
* A function that handles one of the files in a paste event.
|
49
|
+
*
|
50
|
+
* Returns `true` if the file was handled and thus should not be handled by
|
51
|
+
* other handlers.
|
52
|
+
*/
|
53
|
+
type FilePasteHandler = (options: FilePasteHandlerOptions) => boolean | void;
|
54
|
+
declare function defineFilePasteHandler(handler: FilePasteHandler): PlainExtension;
|
55
|
+
//#endregion
|
56
|
+
//#region src/file/file-upload.d.ts
|
57
|
+
/**
|
58
|
+
* An interface representing the upload progress.
|
59
|
+
*/
|
60
|
+
interface UploadProgress {
|
61
|
+
// A number representing the amount of work already performed by the
|
62
|
+
// underlying process.
|
63
|
+
loaded: number;
|
64
|
+
// A number representing the total amount of work that the underlying
|
65
|
+
// process is in the progress of performing.
|
66
|
+
total: number;
|
67
|
+
}
|
68
|
+
interface UploaderOptions {
|
69
|
+
/**
|
70
|
+
* The file to be uploaded.
|
71
|
+
*/
|
72
|
+
file: File;
|
73
|
+
/**
|
74
|
+
* A callback function that should be called with the upload progress updates.
|
75
|
+
*/
|
76
|
+
onProgress: (progress: UploadProgress) => void;
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
* The implementation of the actual upload function. You need to implement this
|
80
|
+
* function to upload files to your desired destination.
|
81
|
+
*/
|
82
|
+
type Uploader<Result> = (options: UploaderOptions) => Promise<Result>;
|
83
|
+
/**
|
84
|
+
* A class that represents a upload task.
|
85
|
+
*/
|
86
|
+
declare class UploadTask<Result> {
|
87
|
+
/**
|
88
|
+
* An [object URL](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL)
|
89
|
+
* representing the file to be uploaded. This URL will be revoked once the
|
90
|
+
* upload is complete successfully.
|
91
|
+
*/
|
92
|
+
readonly objectURL: string;
|
93
|
+
/**
|
94
|
+
* A boolean indicating whether the upload is complete (either successfully or with an error).
|
95
|
+
*/
|
96
|
+
protected done: boolean;
|
97
|
+
/**
|
98
|
+
* A promise that fulfills once the upload is complete, or rejects if an error occurs.
|
99
|
+
*/
|
100
|
+
readonly finished: Promise<Result>;
|
101
|
+
private subscribers;
|
102
|
+
/**
|
103
|
+
* Creates a new upload task. You can find the upload task by its object URL
|
104
|
+
* later using `UploadTask.get()`.
|
105
|
+
*
|
106
|
+
* @param options - The options for the upload task.
|
107
|
+
*/
|
108
|
+
constructor({
|
109
|
+
file,
|
110
|
+
uploader
|
111
|
+
}: {
|
112
|
+
file: File;
|
113
|
+
uploader: Uploader<Result>;
|
114
|
+
});
|
115
|
+
/**
|
116
|
+
* Subscribes to progress updates. Returns a function to unsubscribe.
|
117
|
+
*/
|
118
|
+
subscribeProgress(callback: (progress: UploadProgress) => void): VoidFunction;
|
119
|
+
/**
|
120
|
+
* Finds an upload task by its object URL.
|
121
|
+
*/
|
122
|
+
static get<Result = unknown>(objectURL: string): UploadTask<Result> | undefined;
|
123
|
+
/**
|
124
|
+
* Deletes an upload task by its object URL.
|
125
|
+
*/
|
126
|
+
static delete(objectURL: string): void;
|
127
|
+
}
|
128
|
+
//#endregion
|
129
|
+
export { FileDropHandlerOptions, FilePasteHandlerOptions, UploadProgress, UploadTask, Uploader, UploaderOptions, defineFileDropHandler, defineFilePasteHandler };
|
@@ -1,149 +1,141 @@
|
|
1
|
-
|
2
|
-
import {
|
3
|
-
defineFacet,
|
4
|
-
defineFacetPayload,
|
5
|
-
editorEventFacet
|
6
|
-
} from "@prosekit/core";
|
1
|
+
import { defineFacet, defineFacetPayload, editorEventFacet } from "@prosekit/core";
|
7
2
|
|
8
|
-
|
3
|
+
//#region src/file/helpers.ts
|
9
4
|
function handleFile(view, event, file, handlers) {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
for (let i = handlers.length - 1; i >= 0; i--) {
|
6
|
+
const handler = handlers[i];
|
7
|
+
if (handler({
|
8
|
+
view,
|
9
|
+
event,
|
10
|
+
file
|
11
|
+
})) return true;
|
12
|
+
}
|
13
|
+
return false;
|
17
14
|
}
|
18
|
-
function handleEvent(view, event, handlers,
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
handled = true;
|
24
|
-
}
|
25
|
-
}
|
26
|
-
return handled;
|
15
|
+
function handleEvent(view, event, handlers, getFiles$2) {
|
16
|
+
const files = getFiles$2(event);
|
17
|
+
let handled = false;
|
18
|
+
for (const file of files) if (handleFile(view, event, file, handlers)) handled = true;
|
19
|
+
return handled;
|
27
20
|
}
|
28
21
|
|
29
|
-
|
22
|
+
//#endregion
|
23
|
+
//#region src/file/file-drop-handler.ts
|
30
24
|
function defineFileDropHandler(handler) {
|
31
|
-
|
25
|
+
return defineFacetPayload(facet$1, [handler]);
|
32
26
|
}
|
33
|
-
function getFiles(event) {
|
34
|
-
|
27
|
+
function getFiles$1(event) {
|
28
|
+
return Array.from(event.dataTransfer?.files ?? []);
|
35
29
|
}
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
}
|
30
|
+
const facet$1 = defineFacet({
|
31
|
+
parent: editorEventFacet,
|
32
|
+
singleton: true,
|
33
|
+
reducer: (handlers) => {
|
34
|
+
const dropHandler = (view, event) => {
|
35
|
+
const position = view.posAtCoords({
|
36
|
+
left: event.x,
|
37
|
+
top: event.y
|
38
|
+
});
|
39
|
+
if (!position) return false;
|
40
|
+
const pos = position.inside > 0 ? position.inside : position.pos;
|
41
|
+
return handleEvent(view, event, handlers.map((handler) => (options) => handler({
|
42
|
+
...options,
|
43
|
+
pos
|
44
|
+
})), getFiles$1);
|
45
|
+
};
|
46
|
+
return ["drop", dropHandler];
|
47
|
+
}
|
55
48
|
});
|
56
49
|
|
57
|
-
|
58
|
-
|
59
|
-
defineFacet as defineFacet2,
|
60
|
-
defineFacetPayload as defineFacetPayload2,
|
61
|
-
editorEventFacet as editorEventFacet2
|
62
|
-
} from "@prosekit/core";
|
50
|
+
//#endregion
|
51
|
+
//#region src/file/file-paste-handler.ts
|
63
52
|
function defineFilePasteHandler(handler) {
|
64
|
-
|
53
|
+
return defineFacetPayload(facet, [handler]);
|
65
54
|
}
|
66
|
-
function
|
67
|
-
|
55
|
+
function getFiles(event) {
|
56
|
+
return Array.from(event.clipboardData?.files ?? []);
|
68
57
|
}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
58
|
+
const facet = defineFacet({
|
59
|
+
parent: editorEventFacet,
|
60
|
+
singleton: true,
|
61
|
+
reducer: (handlers) => {
|
62
|
+
const pasteHandler = (view, event) => {
|
63
|
+
return handleEvent(view, event, handlers, getFiles);
|
64
|
+
};
|
65
|
+
return ["paste", pasteHandler];
|
66
|
+
}
|
78
67
|
});
|
79
68
|
|
80
|
-
|
69
|
+
//#endregion
|
70
|
+
//#region src/file/file-upload.ts
|
71
|
+
/**
|
72
|
+
* A class that represents a upload task.
|
73
|
+
*/
|
81
74
|
var UploadTask = class {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
}
|
144
|
-
var store = /* @__PURE__ */ new Map();
|
145
|
-
export {
|
146
|
-
UploadTask,
|
147
|
-
defineFileDropHandler,
|
148
|
-
defineFilePasteHandler
|
75
|
+
/**
|
76
|
+
* An [object URL](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL)
|
77
|
+
* representing the file to be uploaded. This URL will be revoked once the
|
78
|
+
* upload is complete successfully.
|
79
|
+
*/
|
80
|
+
objectURL;
|
81
|
+
/**
|
82
|
+
* A boolean indicating whether the upload is complete (either successfully or with an error).
|
83
|
+
*/
|
84
|
+
done = false;
|
85
|
+
/**
|
86
|
+
* A promise that fulfills once the upload is complete, or rejects if an error occurs.
|
87
|
+
*/
|
88
|
+
finished;
|
89
|
+
subscribers = [];
|
90
|
+
/**
|
91
|
+
* Creates a new upload task. You can find the upload task by its object URL
|
92
|
+
* later using `UploadTask.get()`.
|
93
|
+
*
|
94
|
+
* @param options - The options for the upload task.
|
95
|
+
*/
|
96
|
+
constructor({ file, uploader }) {
|
97
|
+
this.objectURL = URL.createObjectURL(file);
|
98
|
+
this.finished = new Promise((resolve, reject) => {
|
99
|
+
const maybePromise = uploader({
|
100
|
+
file,
|
101
|
+
onProgress: (progress) => {
|
102
|
+
for (const subscriber of this.subscribers) subscriber(progress);
|
103
|
+
}
|
104
|
+
});
|
105
|
+
Promise.resolve(maybePromise).then((result) => {
|
106
|
+
this.done = true;
|
107
|
+
URL.revokeObjectURL(this.objectURL);
|
108
|
+
resolve(result);
|
109
|
+
}, (error) => {
|
110
|
+
this.done = true;
|
111
|
+
reject(new Error("[prosekit] Failed to upload file", { cause: error }));
|
112
|
+
});
|
113
|
+
});
|
114
|
+
store.set(this.objectURL, this);
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* Subscribes to progress updates. Returns a function to unsubscribe.
|
118
|
+
*/
|
119
|
+
subscribeProgress(callback) {
|
120
|
+
this.subscribers.push(callback);
|
121
|
+
return () => {
|
122
|
+
this.subscribers = this.subscribers.filter((subscriber) => subscriber !== callback);
|
123
|
+
};
|
124
|
+
}
|
125
|
+
/**
|
126
|
+
* Finds an upload task by its object URL.
|
127
|
+
*/
|
128
|
+
static get(objectURL) {
|
129
|
+
return store.get(objectURL);
|
130
|
+
}
|
131
|
+
/**
|
132
|
+
* Deletes an upload task by its object URL.
|
133
|
+
*/
|
134
|
+
static delete(objectURL) {
|
135
|
+
store.delete(objectURL);
|
136
|
+
}
|
149
137
|
};
|
138
|
+
const store = new Map();
|
139
|
+
|
140
|
+
//#endregion
|
141
|
+
export { UploadTask, defineFileDropHandler, defineFilePasteHandler };
|
@@ -1,2 +1,26 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { PlainExtension } from "@prosekit/core";
|
2
|
+
import "prosemirror-gapcursor";
|
3
|
+
|
4
|
+
//#region src/gap-cursor/gap-cursor.d.ts
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @internal
|
8
|
+
*/
|
9
|
+
type GapCursorExtension = PlainExtension;
|
10
|
+
/**
|
11
|
+
* Capture clicks near and arrow-key-motion past places that don't have a
|
12
|
+
* normally selectable position nearby, and create a gap cursor selection for
|
13
|
+
* them. The cursor is drawn as an element with class `ProseMirror-gapcursor`.
|
14
|
+
*
|
15
|
+
* You can either include `prosekit/extensions/gap-cursor.css` or add your own
|
16
|
+
* styles to make it visible.
|
17
|
+
*
|
18
|
+
* See
|
19
|
+
* [prosemirror-gapcursor](https://github.com/ProseMirror/prosemirror-gapcursor)
|
20
|
+
* for more information.
|
21
|
+
*
|
22
|
+
* @public
|
23
|
+
*/
|
24
|
+
declare function defineGapCursor(): GapCursorExtension;
|
25
|
+
//#endregion
|
26
|
+
export { GapCursorExtension, defineGapCursor };
|
@@ -1,12 +1,24 @@
|
|
1
|
-
|
2
|
-
import {
|
3
|
-
definePlugin
|
4
|
-
} from "@prosekit/core";
|
1
|
+
import { definePlugin } from "@prosekit/core";
|
5
2
|
import { gapCursor } from "prosemirror-gapcursor";
|
6
|
-
|
3
|
+
|
4
|
+
//#region src/gap-cursor/gap-cursor.ts
|
5
|
+
/**
|
6
|
+
* Capture clicks near and arrow-key-motion past places that don't have a
|
7
|
+
* normally selectable position nearby, and create a gap cursor selection for
|
8
|
+
* them. The cursor is drawn as an element with class `ProseMirror-gapcursor`.
|
9
|
+
*
|
10
|
+
* You can either include `prosekit/extensions/gap-cursor.css` or add your own
|
11
|
+
* styles to make it visible.
|
12
|
+
*
|
13
|
+
* See
|
14
|
+
* [prosemirror-gapcursor](https://github.com/ProseMirror/prosemirror-gapcursor)
|
15
|
+
* for more information.
|
16
|
+
*
|
17
|
+
* @public
|
18
|
+
*/
|
7
19
|
function defineGapCursor() {
|
8
|
-
|
20
|
+
return definePlugin(() => gapCursor());
|
9
21
|
}
|
10
|
-
|
11
|
-
|
12
|
-
};
|
22
|
+
|
23
|
+
//#endregion
|
24
|
+
export { defineGapCursor };
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { Extension, PlainExtension, Union } from "@prosekit/core";
|
2
|
+
import { Command } from "@prosekit/pm/state";
|
3
|
+
import { Attrs } from "@prosekit/pm/model";
|
4
|
+
|
5
|
+
//#region src/hard-break/hard-break-commands.d.ts
|
6
|
+
/**
|
7
|
+
* @internal
|
8
|
+
*/
|
9
|
+
type HardBreakCommandsExtension = Extension<{
|
10
|
+
Commands: {
|
11
|
+
insertHardBreak: [];
|
12
|
+
};
|
13
|
+
}>;
|
14
|
+
/**
|
15
|
+
* @internal
|
16
|
+
*/
|
17
|
+
|
18
|
+
/**
|
19
|
+
* @internal
|
20
|
+
*/
|
21
|
+
declare function defineHardBreakCommands(): HardBreakCommandsExtension;
|
22
|
+
//#endregion
|
23
|
+
//#region src/hard-break/hard-break-spec.d.ts
|
24
|
+
/**
|
25
|
+
* @internal
|
26
|
+
*/
|
27
|
+
type HardBreakSpecExtension = Extension<{
|
28
|
+
Nodes: {
|
29
|
+
hardBreak: Attrs;
|
30
|
+
};
|
31
|
+
}>;
|
32
|
+
/**
|
33
|
+
* @internal
|
34
|
+
*/
|
35
|
+
declare function defineHardBreakSpec(): HardBreakSpecExtension;
|
36
|
+
//#endregion
|
37
|
+
//#region src/hard-break/hard-break.d.ts
|
38
|
+
/**
|
39
|
+
* @internal
|
40
|
+
*/
|
41
|
+
type HardBreakExtension = Union<[HardBreakSpecExtension, HardBreakCommandsExtension]>;
|
42
|
+
/**
|
43
|
+
* @public
|
44
|
+
*/
|
45
|
+
declare function defineHardBreak(): HardBreakExtension;
|
46
|
+
//#endregion
|
47
|
+
//#region src/hard-break/hard-break-keymap.d.ts
|
48
|
+
/**
|
49
|
+
* @internal
|
50
|
+
*/
|
51
|
+
declare function defineHardBreakKeymap(): PlainExtension;
|
52
|
+
//#endregion
|
53
|
+
export { HardBreakCommandsExtension, HardBreakExtension, HardBreakSpecExtension, defineHardBreak, defineHardBreakCommands, defineHardBreakKeymap, defineHardBreakSpec };
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { defineCommands, defineKeymap, defineNodeSpec, insertNode, union } from "@prosekit/core";
|
2
|
+
|
3
|
+
//#region src/hard-break/hard-break-commands.ts
|
4
|
+
/**
|
5
|
+
* @internal
|
6
|
+
*/
|
7
|
+
function insertHardBreak() {
|
8
|
+
return insertNode({ type: "hardBreak" });
|
9
|
+
}
|
10
|
+
/**
|
11
|
+
* @internal
|
12
|
+
*/
|
13
|
+
function defineHardBreakCommands() {
|
14
|
+
return defineCommands({ insertHardBreak });
|
15
|
+
}
|
16
|
+
|
17
|
+
//#endregion
|
18
|
+
//#region src/hard-break/hard-break-keymap.ts
|
19
|
+
/**
|
20
|
+
* @internal
|
21
|
+
*/
|
22
|
+
function defineHardBreakKeymap() {
|
23
|
+
return defineKeymap({
|
24
|
+
"Mod-Enter": insertHardBreak(),
|
25
|
+
"Shift-Enter": insertHardBreak()
|
26
|
+
});
|
27
|
+
}
|
28
|
+
|
29
|
+
//#endregion
|
30
|
+
//#region src/hard-break/hard-break-spec.ts
|
31
|
+
/**
|
32
|
+
* @internal
|
33
|
+
*/
|
34
|
+
function defineHardBreakSpec() {
|
35
|
+
return defineNodeSpec({
|
36
|
+
name: "hardBreak",
|
37
|
+
inline: true,
|
38
|
+
selectable: false,
|
39
|
+
leafText: () => "\n",
|
40
|
+
group: "inline",
|
41
|
+
parseDOM: [{ tag: "br" }],
|
42
|
+
toDOM() {
|
43
|
+
return ["br"];
|
44
|
+
}
|
45
|
+
});
|
46
|
+
}
|
47
|
+
|
48
|
+
//#endregion
|
49
|
+
//#region src/hard-break/hard-break.ts
|
50
|
+
/**
|
51
|
+
* @public
|
52
|
+
*/
|
53
|
+
function defineHardBreak() {
|
54
|
+
return union(defineHardBreakSpec(), defineHardBreakKeymap(), defineHardBreakCommands());
|
55
|
+
}
|
56
|
+
|
57
|
+
//#endregion
|
58
|
+
export { defineHardBreak, defineHardBreakCommands, defineHardBreakKeymap, defineHardBreakSpec };
|
@@ -1,9 +1,63 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
import { Extension, PlainExtension, Union } from "@prosekit/core";
|
2
|
+
|
3
|
+
//#region src/heading/heading-types.d.ts
|
4
|
+
interface HeadingAttrs {
|
5
|
+
level: number;
|
6
|
+
}
|
7
|
+
//#endregion
|
8
|
+
//#region src/heading/heading-commands.d.ts
|
9
|
+
/**
|
10
|
+
* @internal
|
11
|
+
*/
|
12
|
+
type HeadingCommandsExtension = Extension<{
|
13
|
+
Commands: {
|
14
|
+
setHeading: [attrs?: HeadingAttrs | undefined];
|
15
|
+
insertHeading: [attrs?: HeadingAttrs | undefined];
|
16
|
+
toggleHeading: [attrs?: HeadingAttrs | undefined];
|
17
|
+
};
|
18
|
+
}>;
|
19
|
+
/**
|
20
|
+
* @internal
|
21
|
+
*/
|
22
|
+
declare function defineHeadingCommands(): HeadingCommandsExtension;
|
23
|
+
//#endregion
|
24
|
+
//#region src/heading/heading-spec.d.ts
|
25
|
+
/**
|
26
|
+
* @internal
|
27
|
+
*/
|
28
|
+
type HeadingSpecExtension = Extension<{
|
29
|
+
Nodes: {
|
30
|
+
heading: HeadingAttrs;
|
31
|
+
};
|
32
|
+
}>;
|
33
|
+
/**
|
34
|
+
* @internal
|
35
|
+
*/
|
36
|
+
declare function defineHeadingSpec(): HeadingSpecExtension;
|
37
|
+
//#endregion
|
38
|
+
//#region src/heading/heading.d.ts
|
39
|
+
/**
|
40
|
+
* @internal
|
41
|
+
*/
|
42
|
+
type HeadingExtension = Union<[HeadingSpecExtension, HeadingCommandsExtension]>;
|
43
|
+
/**
|
44
|
+
* @public
|
45
|
+
*/
|
46
|
+
declare function defineHeading(): HeadingExtension;
|
47
|
+
//#endregion
|
48
|
+
//#region src/heading/heading-input-rule.d.ts
|
49
|
+
/**
|
50
|
+
* Converts the text block to a heading when `#` is typed at the start of a new
|
51
|
+
* line followed by a space.
|
52
|
+
*
|
53
|
+
* @internal
|
54
|
+
*/
|
55
|
+
declare function defineHeadingInputRule(): PlainExtension;
|
56
|
+
//#endregion
|
57
|
+
//#region src/heading/heading-keymap.d.ts
|
58
|
+
/**
|
59
|
+
* @internal
|
60
|
+
*/
|
61
|
+
declare function defineHeadingKeymap(): PlainExtension;
|
62
|
+
//#endregion
|
63
|
+
export { HeadingAttrs, HeadingCommandsExtension, HeadingExtension, HeadingSpecExtension, defineHeading, defineHeadingCommands, defineHeadingInputRule, defineHeadingKeymap, defineHeadingSpec };
|