@prosekit/extensions 0.11.5 → 0.11.7
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/drop-indicator-E7nCfdnR.js +58 -0
- package/dist/drop-indicator-E7nCfdnR.js.map +1 -0
- package/dist/{enter-rule-RdhEA900.js → enter-rule-5tkoU2Ir.js} +2 -3
- package/dist/enter-rule-5tkoU2Ir.js.map +1 -0
- package/dist/file-nRyo7PMB.js +132 -0
- package/dist/file-nRyo7PMB.js.map +1 -0
- package/dist/index-DY6lIIYV.d.ts +134 -0
- package/dist/index-DY6lIIYV.d.ts.map +1 -0
- package/dist/{input-rule-B17tpW4m.js → input-rule-DO_iy2aT.js} +4 -7
- package/dist/input-rule-DO_iy2aT.js.map +1 -0
- package/dist/{mark-rule-BCqIZMDu.js → mark-rule-CGmswjQ_.js} +1 -1
- package/dist/{mark-rule-BCqIZMDu.js.map → mark-rule-CGmswjQ_.js.map} +1 -1
- package/dist/{paste-rule-DIEJKIje.js → paste-rule-Brej6cWi.js} +2 -3
- package/dist/{paste-rule-DIEJKIje.js.map → paste-rule-Brej6cWi.js.map} +1 -1
- package/dist/prosekit-extensions-autocomplete.js +1 -2
- package/dist/prosekit-extensions-autocomplete.js.map +1 -1
- package/dist/prosekit-extensions-blockquote.js +1 -1
- package/dist/prosekit-extensions-bold.js +1 -1
- package/dist/prosekit-extensions-code-block.d.ts +1 -1
- package/dist/prosekit-extensions-code-block.js +4 -5
- package/dist/prosekit-extensions-code-block.js.map +1 -1
- package/dist/prosekit-extensions-code.js +1 -1
- package/dist/prosekit-extensions-commit.js +2 -4
- package/dist/prosekit-extensions-commit.js.map +1 -1
- package/dist/prosekit-extensions-drop-indicator.d.ts +3 -106
- package/dist/prosekit-extensions-drop-indicator.d.ts.map +1 -1
- package/dist/prosekit-extensions-drop-indicator.js +1 -1
- package/dist/prosekit-extensions-enter-rule.js +1 -1
- package/dist/prosekit-extensions-file.d.ts +2 -126
- package/dist/prosekit-extensions-file.js +2 -128
- package/dist/prosekit-extensions-hard-break.d.ts +0 -4
- package/dist/prosekit-extensions-hard-break.d.ts.map +1 -1
- package/dist/prosekit-extensions-heading.js +1 -1
- package/dist/prosekit-extensions-horizontal-rule.js +1 -1
- package/dist/prosekit-extensions-image.d.ts +135 -3
- package/dist/prosekit-extensions-image.d.ts.map +1 -1
- package/dist/prosekit-extensions-image.js +129 -8
- package/dist/prosekit-extensions-image.js.map +1 -1
- package/dist/prosekit-extensions-input-rule.js +1 -1
- package/dist/prosekit-extensions-italic.js +1 -1
- package/dist/prosekit-extensions-link.js +4 -4
- package/dist/prosekit-extensions-list.js +5 -7
- package/dist/prosekit-extensions-list.js.map +1 -1
- package/dist/prosekit-extensions-mark-rule.js +1 -1
- package/dist/prosekit-extensions-paragraph.d.ts +0 -4
- package/dist/prosekit-extensions-paragraph.d.ts.map +1 -1
- package/dist/prosekit-extensions-paste-rule.js +1 -1
- package/dist/prosekit-extensions-placeholder.js +3 -4
- package/dist/prosekit-extensions-placeholder.js.map +1 -1
- package/dist/prosekit-extensions-search.js +1 -2
- package/dist/prosekit-extensions-search.js.map +1 -1
- package/dist/prosekit-extensions-strike.js +1 -1
- package/dist/prosekit-extensions-table.js +2 -2
- package/dist/prosekit-extensions.d.ts +1 -1
- package/dist/{shiki-highlighter-chunk-DSPM0T27.d.ts → shiki-highlighter-chunk-Cwu1Jr9o.d.ts} +1 -1
- package/dist/{shiki-highlighter-chunk-DSPM0T27.d.ts.map → shiki-highlighter-chunk-Cwu1Jr9o.d.ts.map} +1 -1
- package/dist/shiki-highlighter-chunk.d.ts +1 -1
- package/dist/{table-Bi7WsMI3.js → table-DND_1127.js} +10 -19
- package/dist/{table-Bi7WsMI3.js.map → table-DND_1127.js.map} +1 -1
- package/package.json +8 -7
- package/src/drop-indicator/drop-indicator-facet.ts +6 -28
- package/src/drop-indicator/drop-indicator.ts +3 -5
- package/src/drop-indicator/index.ts +6 -6
- package/src/file/file-upload.ts +19 -6
- package/src/image/image-commands/insert-image.ts +14 -0
- package/src/image/image-commands/upload-image.ts +137 -0
- package/src/image/image-commands.ts +8 -4
- package/src/image/image-upload-handler.ts +96 -0
- package/src/image/index.ts +14 -0
- package/dist/drop-indicator-D1eHOhSi.js +0 -267
- package/dist/drop-indicator-D1eHOhSi.js.map +0 -1
- package/dist/enter-rule-RdhEA900.js.map +0 -1
- package/dist/input-rule-B17tpW4m.js.map +0 -1
- package/dist/prosekit-extensions-file.d.ts.map +0 -1
- package/dist/prosekit-extensions-file.js.map +0 -1
- package/src/drop-indicator/drop-indicator-plugin.ts +0 -147
- package/src/drop-indicator/drop-target.ts +0 -168
- package/src/drop-indicator/types.ts +0 -90
|
@@ -1,129 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UploadTask, defineFileDropHandler, defineFilePasteHandler } from "./file-nRyo7PMB.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
function handleFile(view, event, file, handlers) {
|
|
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;
|
|
14
|
-
}
|
|
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;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/file/file-drop-handler.ts
|
|
24
|
-
function defineFileDropHandler(handler) {
|
|
25
|
-
return defineFacetPayload(facet$1, [handler]);
|
|
26
|
-
}
|
|
27
|
-
function getFiles$1(event) {
|
|
28
|
-
return Array.from(event.dataTransfer?.files ?? []);
|
|
29
|
-
}
|
|
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
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/file/file-paste-handler.ts
|
|
52
|
-
function defineFilePasteHandler(handler) {
|
|
53
|
-
return defineFacetPayload(facet, [handler]);
|
|
54
|
-
}
|
|
55
|
-
function getFiles(event) {
|
|
56
|
-
return Array.from(event.clipboardData?.files ?? []);
|
|
57
|
-
}
|
|
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
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/file/file-upload.ts
|
|
71
|
-
/**
|
|
72
|
-
* A class that represents a upload task.
|
|
73
|
-
*/
|
|
74
|
-
var UploadTask = class {
|
|
75
|
-
/**
|
|
76
|
-
* Creates a new upload task. You can find the upload task by its object URL
|
|
77
|
-
* later using `UploadTask.get()`.
|
|
78
|
-
*
|
|
79
|
-
* @param options - The options for the upload task.
|
|
80
|
-
*/
|
|
81
|
-
constructor({ file, uploader }) {
|
|
82
|
-
this.done = false;
|
|
83
|
-
this.subscribers = [];
|
|
84
|
-
this.objectURL = URL.createObjectURL(file);
|
|
85
|
-
this.finished = new Promise((resolve, reject) => {
|
|
86
|
-
const maybePromise = uploader({
|
|
87
|
-
file,
|
|
88
|
-
onProgress: (progress) => {
|
|
89
|
-
for (const subscriber of this.subscribers) subscriber(progress);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
Promise.resolve(maybePromise).then((result) => {
|
|
93
|
-
this.done = true;
|
|
94
|
-
URL.revokeObjectURL(this.objectURL);
|
|
95
|
-
resolve(result);
|
|
96
|
-
}, (error) => {
|
|
97
|
-
this.done = true;
|
|
98
|
-
reject(new Error("[prosekit] Failed to upload file", { cause: error }));
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
store.set(this.objectURL, this);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Subscribes to progress updates. Returns a function to unsubscribe.
|
|
105
|
-
*/
|
|
106
|
-
subscribeProgress(callback) {
|
|
107
|
-
this.subscribers.push(callback);
|
|
108
|
-
return () => {
|
|
109
|
-
this.subscribers = this.subscribers.filter((subscriber) => subscriber !== callback);
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Finds an upload task by its object URL.
|
|
114
|
-
*/
|
|
115
|
-
static get(objectURL) {
|
|
116
|
-
return store.get(objectURL);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Deletes an upload task by its object URL.
|
|
120
|
-
*/
|
|
121
|
-
static delete(objectURL) {
|
|
122
|
-
store.delete(objectURL);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
const store = /* @__PURE__ */ new Map();
|
|
126
|
-
|
|
127
|
-
//#endregion
|
|
128
|
-
export { UploadTask, defineFileDropHandler, defineFilePasteHandler };
|
|
129
|
-
//# sourceMappingURL=prosekit-extensions-file.js.map
|
|
3
|
+
export { UploadTask, defineFileDropHandler, defineFilePasteHandler };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-hard-break.d.ts","names":[],"sources":["../src/hard-break/hard-break-commands.ts","../src/hard-break/hard-break-spec.ts","../src/hard-break/hard-break.ts","../src/hard-break/hard-break-keymap.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAUY,KAAA,0BAAA,GAA6B,SAAA,CAAA;EAgBzB,QAAA,EAAA
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-hard-break.d.ts","names":[],"sources":["../src/hard-break/hard-break-commands.ts","../src/hard-break/hard-break-spec.ts","../src/hard-break/hard-break.ts","../src/hard-break/hard-break-keymap.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAUY,KAAA,0BAAA,GAA6B,SAAA,CAAA;EAgBzB,QAAA,EAAA;;;;;ACRhB;;iBDQgB,uBAAA,CAAA,GAA2B;;;;;;AAhB/B,KCDA,sBAAA,GAAyB,SDCI,CAAA;EAgBzB,KAAA,EAAA;eCfD;;;AAFf;;;AAAqC,iBASrB,mBAAA,CAAA,CATqB,EASE,sBATF;;;;;ADCrC;AAgBgB,KERJ,kBAAA,GAAqB,KFQM,CAAA,CEPpC,wBAAwB;ADV3B;;;AAAqC,iBCgBrB,eAAA,CAAA,CDhBqB,ECgBF,kBDhBE;;;;;;iBECrB,qBAAA,CAAA,GAAyB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineTextBlockInputRule } from "./input-rule-
|
|
1
|
+
import { defineTextBlockInputRule } from "./input-rule-DO_iy2aT.js";
|
|
2
2
|
import { defineCommands, defineKeymap, defineNodeSpec, insertNode, isAtBlockStart, setBlockType, toggleNode, union, unsetBlockType, withSkipCodeBlock } from "@prosekit/core";
|
|
3
3
|
|
|
4
4
|
//#region src/heading/heading-commands.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineInputRule } from "./input-rule-
|
|
1
|
+
import { defineInputRule } from "./input-rule-DO_iy2aT.js";
|
|
2
2
|
import { defineCommands, defineNodeSpec, getNodeType, union } from "@prosekit/core";
|
|
3
3
|
import { InputRule } from "@prosekit/pm/inputrules";
|
|
4
4
|
import { Fragment, Slice } from "@prosekit/pm/model";
|
|
@@ -1,7 +1,82 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FileDropHandlerOptions, FilePasteHandlerOptions, UploadTask, Uploader } from "./index-DY6lIIYV.js";
|
|
2
|
+
import { Extension, PlainExtension, Union } from "@prosekit/core";
|
|
3
|
+
import { Command } from "@prosekit/pm/state";
|
|
4
|
+
import { EditorView } from "@prosekit/pm/view";
|
|
2
5
|
|
|
3
|
-
//#region src/image/image-
|
|
6
|
+
//#region src/image/image-commands/upload-image.d.ts
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Options for {@link uploadImage}.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
interface UploadImageOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The uploader used to upload the file. It should return a promise that
|
|
16
|
+
* resolves to the URL of the uploaded image.
|
|
17
|
+
*/
|
|
18
|
+
uploader: Uploader<string>;
|
|
19
|
+
/**
|
|
20
|
+
* The file that will be uploaded.
|
|
21
|
+
*/
|
|
22
|
+
file: File;
|
|
23
|
+
/**
|
|
24
|
+
* The position where the image should be inserted. If not provided, the
|
|
25
|
+
* image is inserted at the current selection.
|
|
26
|
+
*/
|
|
27
|
+
pos?: number;
|
|
28
|
+
/**
|
|
29
|
+
* A handler to be called when an error occurs during the upload.
|
|
30
|
+
*/
|
|
31
|
+
onError?: ImageUploadErrorHandler;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Options for the {@link ImageUploadErrorHandler} callback.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
interface ImageUploadErrorHandlerOptions {
|
|
39
|
+
/**
|
|
40
|
+
* The file that was uploaded.
|
|
41
|
+
*/
|
|
42
|
+
file: File;
|
|
43
|
+
/**
|
|
44
|
+
* The error that occurred during the upload.
|
|
45
|
+
*/
|
|
46
|
+
error: unknown;
|
|
47
|
+
/**
|
|
48
|
+
* The upload task that was used to upload the file.
|
|
49
|
+
*/
|
|
50
|
+
uploadTask: UploadTask<string>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A handler to be called when an error occurs during the upload.
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
type ImageUploadErrorHandler = (options: ImageUploadErrorHandlerOptions) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Returns a command that uploads an image file and inserts an image node with a
|
|
60
|
+
* temporary URL which is replaced once the upload completes.
|
|
61
|
+
*
|
|
62
|
+
* @param options
|
|
63
|
+
*
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
declare function uploadImage({
|
|
67
|
+
uploader,
|
|
68
|
+
file,
|
|
69
|
+
pos,
|
|
70
|
+
onError
|
|
71
|
+
}: UploadImageOptions): Command;
|
|
72
|
+
/**
|
|
73
|
+
* Replaces the temporary image URL with the final uploaded URL.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
declare function replaceImageURL(view: EditorView, oldURL: string, newURL: string): void;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/image/image-spec.d.ts
|
|
5
80
|
/**
|
|
6
81
|
* @public
|
|
7
82
|
*/
|
|
@@ -30,6 +105,7 @@ declare function defineImageSpec(): ImageSpecExtension;
|
|
|
30
105
|
type ImageCommandsExtension = Extension<{
|
|
31
106
|
Commands: {
|
|
32
107
|
insertImage: [attrs?: ImageAttrs];
|
|
108
|
+
uploadImage: [options: UploadImageOptions];
|
|
33
109
|
};
|
|
34
110
|
}>;
|
|
35
111
|
/**
|
|
@@ -47,5 +123,61 @@ type ImageExtension = Union<[ImageSpecExtension, ImageCommandsExtension]>;
|
|
|
47
123
|
*/
|
|
48
124
|
declare function defineImage(): ImageExtension;
|
|
49
125
|
//#endregion
|
|
50
|
-
|
|
126
|
+
//#region src/image/image-commands/insert-image.d.ts
|
|
127
|
+
/**
|
|
128
|
+
* Returns a command that inserts an image node with the given attributes at the
|
|
129
|
+
* current selection position.
|
|
130
|
+
*
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
declare function insertImage(attrs?: ImageAttrs): Command;
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/image/image-upload-handler.d.ts
|
|
136
|
+
/**
|
|
137
|
+
* A predicate to determine if the pasted file should be uploaded and inserted as an image.
|
|
138
|
+
*/
|
|
139
|
+
type ImageCanPastePredicate = (options: FilePasteHandlerOptions) => boolean;
|
|
140
|
+
/**
|
|
141
|
+
* A predicate to determine if the dropped file should be uploaded and inserted as an image.
|
|
142
|
+
*/
|
|
143
|
+
type ImageCanDropPredicate = (options: FileDropHandlerOptions) => boolean;
|
|
144
|
+
/**
|
|
145
|
+
* A handler to be called when an error occurs during the upload.
|
|
146
|
+
*/
|
|
147
|
+
interface ImageUploadHandlerOptions {
|
|
148
|
+
/**
|
|
149
|
+
* The uploader used to upload the file. It should return a promise that
|
|
150
|
+
* resolves to the URL of the uploaded image.
|
|
151
|
+
*/
|
|
152
|
+
uploader: Uploader<string>;
|
|
153
|
+
/**
|
|
154
|
+
* A predicate to determine if the pasted file should be uploaded and inserted as an image.
|
|
155
|
+
* If not provided, it defaults to only allowing paste of files with a content type starting with `image/`.
|
|
156
|
+
*/
|
|
157
|
+
canPaste?: ImageCanPastePredicate;
|
|
158
|
+
/**
|
|
159
|
+
* A predicate to determine if the dropped file should be uploaded and inserted as an image.
|
|
160
|
+
* If not provided, it defaults to only allowing drop of files with a content type starting with `image/`.
|
|
161
|
+
*/
|
|
162
|
+
canDrop?: ImageCanDropPredicate;
|
|
163
|
+
/**
|
|
164
|
+
* A handler to be called when an error occurs during the upload.
|
|
165
|
+
* If not provided, it defaults to logging the error to the console.
|
|
166
|
+
*/
|
|
167
|
+
onError?: ImageUploadErrorHandler;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Returns an extension that handles image file uploads when pasting or dropping
|
|
171
|
+
* images into the editor.
|
|
172
|
+
*
|
|
173
|
+
* @param options
|
|
174
|
+
*/
|
|
175
|
+
declare function defineImageUploadHandler({
|
|
176
|
+
uploader,
|
|
177
|
+
canPaste,
|
|
178
|
+
canDrop,
|
|
179
|
+
onError
|
|
180
|
+
}: ImageUploadHandlerOptions): PlainExtension;
|
|
181
|
+
//#endregion
|
|
182
|
+
export { type ImageAttrs, type ImageCanDropPredicate, type ImageCanPastePredicate, type ImageCommandsExtension, type ImageExtension, type ImageSpecExtension, type ImageUploadErrorHandler, type ImageUploadErrorHandlerOptions, type ImageUploadHandlerOptions, type UploadImageOptions, defineImage, defineImageCommands, defineImageSpec, defineImageUploadHandler, insertImage, replaceImageURL, uploadImage };
|
|
51
183
|
//# sourceMappingURL=prosekit-extensions-image.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-image.d.ts","names":[],"sources":["../src/image/image-spec.ts","../src/image/image-commands.ts","../src/image/image.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-image.d.ts","names":[],"sources":["../src/image/image-commands/upload-image.ts","../src/image/image-spec.ts","../src/image/image-commands.ts","../src/image/image.ts","../src/image/image-commands/insert-image.ts","../src/image/image-upload-handler.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAkBA;;AAKY,UALK,kBAAA,CAKL;;;;AAqBZ;EAA+C,QAAA,EArBnC,QAqBmC,CAAA,MAAA,CAAA;;;;EAoBnC,IAAA,EArCJ,IAqCI;EAUI;;;;KAA8B,CAAA,EAAA,MAAA;;;;EAA4C,OAAA,CAAA,EAtC9E,uBAsC8E;AAsC1F;;;;ACxGA;AASA;AAA8B,UD2Bb,8BAAA,CC3Ba;;;;EASd,IAAA,EDsBR,ICtBQ;;;;ECXJ,KAAA,EAAA,OAAA;EAAsB;;;YAAG,EFyCvB,UEzCuB,CAAA,MAAA,CAAA;;AAUrC;;;;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CAAA,MAAA,CAAA;;;;;UAAmC,CAAA,EK/BjD,sBL+BiD;;;AAsC9D;;YKhEY;;AJxCZ;AASA;;SAEW,CAAA,EIkCC,uBJlCD;;;AAOX;;;;ACXA;AAAkC,iBGwDlB,wBAAA,CHxDkB;EAAA,QAAA;EAAA,QAAA;EAAA,OAAA;EAAA;AAAA,CAAA,EG6D/B,yBH7D+B,CAAA,EG6DH,cH7DG"}
|
|
@@ -1,16 +1,100 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UploadTask, defineFileDropHandler, defineFilePasteHandler } from "./file-nRyo7PMB.js";
|
|
2
|
+
import { ProseKitError, defineCommands, defineNodeSpec, insertNode, union } from "@prosekit/core";
|
|
2
3
|
|
|
4
|
+
//#region src/image/image-commands/insert-image.ts
|
|
5
|
+
/**
|
|
6
|
+
* Returns a command that inserts an image node with the given attributes at the
|
|
7
|
+
* current selection position.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
function insertImage(attrs) {
|
|
12
|
+
return insertNode({
|
|
13
|
+
type: "image",
|
|
14
|
+
attrs
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/image/image-commands/upload-image.ts
|
|
20
|
+
/**
|
|
21
|
+
* Returns a command that uploads an image file and inserts an image node with a
|
|
22
|
+
* temporary URL which is replaced once the upload completes.
|
|
23
|
+
*
|
|
24
|
+
* @param options
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
function uploadImage({ uploader, file, pos, onError }) {
|
|
29
|
+
return (state, dispatch, view) => {
|
|
30
|
+
const uploadTask = new UploadTask({
|
|
31
|
+
file,
|
|
32
|
+
uploader
|
|
33
|
+
});
|
|
34
|
+
const objectURL = uploadTask.objectURL;
|
|
35
|
+
const attrs = { src: objectURL };
|
|
36
|
+
uploadTask.finished.then((resultURL) => {
|
|
37
|
+
if (view && view.isDestroyed) return;
|
|
38
|
+
else if (typeof resultURL !== "string") {
|
|
39
|
+
const error = new ProseKitError(`Unexpected upload result. Expected a string but got ${typeof resultURL}`);
|
|
40
|
+
onError?.({
|
|
41
|
+
file,
|
|
42
|
+
error,
|
|
43
|
+
uploadTask
|
|
44
|
+
});
|
|
45
|
+
} else if (!view) {
|
|
46
|
+
const error = new ProseKitError("View must be available to replace the image URL");
|
|
47
|
+
onError?.({
|
|
48
|
+
file,
|
|
49
|
+
error,
|
|
50
|
+
uploadTask
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
replaceImageURL(view, objectURL, resultURL);
|
|
54
|
+
UploadTask.delete(objectURL);
|
|
55
|
+
}
|
|
56
|
+
}).catch((error) => {
|
|
57
|
+
onError?.({
|
|
58
|
+
file,
|
|
59
|
+
error,
|
|
60
|
+
uploadTask
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
return insertNode({
|
|
64
|
+
type: "image",
|
|
65
|
+
attrs,
|
|
66
|
+
pos
|
|
67
|
+
})(state, dispatch, view);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Replaces the temporary image URL with the final uploaded URL.
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
function replaceImageURL(view, oldURL, newURL) {
|
|
76
|
+
const positions = [];
|
|
77
|
+
view.state.doc.descendants((node, pos) => {
|
|
78
|
+
if (node.type.name === "image") {
|
|
79
|
+
if (node.attrs.src === oldURL) positions.push(pos);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
if (positions.length === 0) return;
|
|
83
|
+
const tr = view.state.tr;
|
|
84
|
+
for (const pos of positions) tr.setNodeAttribute(pos, "src", newURL);
|
|
85
|
+
view.dispatch(tr);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
3
89
|
//#region src/image/image-commands.ts
|
|
4
90
|
/**
|
|
5
91
|
* @internal
|
|
6
92
|
*/
|
|
7
93
|
function defineImageCommands() {
|
|
8
|
-
return defineCommands({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
} });
|
|
94
|
+
return defineCommands({
|
|
95
|
+
insertImage,
|
|
96
|
+
uploadImage
|
|
97
|
+
});
|
|
14
98
|
}
|
|
15
99
|
|
|
16
100
|
//#endregion
|
|
@@ -76,5 +160,42 @@ function defineImage() {
|
|
|
76
160
|
}
|
|
77
161
|
|
|
78
162
|
//#endregion
|
|
79
|
-
|
|
163
|
+
//#region src/image/image-upload-handler.ts
|
|
164
|
+
function defaultCanUpload({ file }) {
|
|
165
|
+
return file.type.startsWith("image/");
|
|
166
|
+
}
|
|
167
|
+
const defaultOnError = ({ error }) => {
|
|
168
|
+
console.error("[prosekit] Failed to upload image:", error);
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Returns an extension that handles image file uploads when pasting or dropping
|
|
172
|
+
* images into the editor.
|
|
173
|
+
*
|
|
174
|
+
* @param options
|
|
175
|
+
*/
|
|
176
|
+
function defineImageUploadHandler({ uploader, canPaste = defaultCanUpload, canDrop = defaultCanUpload, onError = defaultOnError }) {
|
|
177
|
+
const handlePaste = (options) => {
|
|
178
|
+
if (!canPaste(options)) return false;
|
|
179
|
+
const { view, file } = options;
|
|
180
|
+
return uploadImage({
|
|
181
|
+
uploader,
|
|
182
|
+
file,
|
|
183
|
+
onError
|
|
184
|
+
})(view.state, view.dispatch, view);
|
|
185
|
+
};
|
|
186
|
+
const handleDrop = (options) => {
|
|
187
|
+
if (!canDrop(options)) return false;
|
|
188
|
+
const { view, file, pos } = options;
|
|
189
|
+
return uploadImage({
|
|
190
|
+
uploader,
|
|
191
|
+
file,
|
|
192
|
+
onError,
|
|
193
|
+
pos
|
|
194
|
+
})(view.state, view.dispatch, view);
|
|
195
|
+
};
|
|
196
|
+
return union(defineFilePasteHandler(handlePaste), defineFileDropHandler(handleDrop));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
export { defineImage, defineImageCommands, defineImageSpec, defineImageUploadHandler, insertImage, replaceImageURL, uploadImage };
|
|
80
201
|
//# sourceMappingURL=prosekit-extensions-image.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-image.js","names":["width: number | null","height: number | null"],"sources":["../src/image/image-commands.ts","../src/image/image-spec.ts","../src/image/image.ts"],"sourcesContent":["import {\n defineCommands,\n insertNode,\n type Extension,\n} from '@prosekit/core'\n\nimport type { ImageAttrs } from './image-spec'\n\n/**\n * @internal\n */\nexport type ImageCommandsExtension = Extension<{\n Commands: {\n insertImage: [attrs?: ImageAttrs]\n }\n}>\n\n/**\n * @internal\n */\nexport function defineImageCommands(): ImageCommandsExtension {\n return defineCommands({\n insertImage: (attrs?: ImageAttrs) => {\n return insertNode({ type: 'image', attrs })\n },\n })\n}\n","import {\n defineNodeSpec,\n type Extension,\n} from '@prosekit/core'\n\n/**\n * @public\n */\nexport interface ImageAttrs {\n src?: string | null\n width?: number | null\n height?: number | null\n}\n\n/**\n * @internal\n */\nexport type ImageSpecExtension = Extension<{\n Nodes: {\n image: ImageAttrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineImageSpec(): ImageSpecExtension {\n return defineNodeSpec({\n name: 'image',\n attrs: {\n src: { default: null, validate: 'string|null' },\n width: { default: null, validate: 'number|null' },\n height: { default: null, validate: 'number|null' },\n },\n group: 'block',\n defining: true,\n draggable: true,\n parseDOM: [\n {\n tag: 'img[src]',\n getAttrs: (element): ImageAttrs => {\n if (typeof element === 'string') {\n return { src: null }\n }\n\n const src = element.getAttribute('src') || null\n\n let width: number | null = null\n let height: number | null = null\n\n const rect = element.getBoundingClientRect()\n if (rect.width > 0 && rect.height > 0) {\n width = rect.width\n height = rect.height\n } else if (\n element instanceof HTMLImageElement\n && element.naturalWidth > 0\n && element.naturalHeight > 0\n ) {\n width = element.naturalWidth\n height = element.naturalHeight\n }\n return { src, width, height }\n },\n },\n ],\n toDOM(node) {\n const attrs = node.attrs as ImageAttrs\n return ['img', attrs]\n },\n })\n}\n","import {\n union,\n type Union,\n} from '@prosekit/core'\n\nimport {\n defineImageCommands,\n type ImageCommandsExtension,\n} from './image-commands'\nimport {\n defineImageSpec,\n type ImageSpecExtension,\n} from './image-spec'\n\n/**\n * @internal\n */\nexport type ImageExtension = Union<[ImageSpecExtension, ImageCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineImage(): ImageExtension {\n return union(defineImageSpec(), defineImageCommands())\n}\n"],"mappings":";;;;;;AAoBA,SAAgB,sBAA8C;AAC5D,QAAO,eAAe,EACpB,cAAc,UAAuB;AACnC,SAAO,WAAW;GAAE,MAAM;GAAS;GAAO,CAAC;IAE9C,CAAC;;;;;;;;ACCJ,SAAgB,kBAAsC;AACpD,QAAO,eAAe;EACpB,MAAM;EACN,OAAO;GACL,KAAK;IAAE,SAAS;IAAM,UAAU;IAAe;GAC/C,OAAO;IAAE,SAAS;IAAM,UAAU;IAAe;GACjD,QAAQ;IAAE,SAAS;IAAM,UAAU;IAAe;GACnD;EACD,OAAO;EACP,UAAU;EACV,WAAW;EACX,UAAU,CACR;GACE,KAAK;GACL,WAAW,YAAwB;AACjC,QAAI,OAAO,YAAY,SACrB,QAAO,EAAE,KAAK,MAAM;IAGtB,MAAM,MAAM,QAAQ,aAAa,MAAM,IAAI;IAE3C,IAAIA,QAAuB;IAC3B,IAAIC,SAAwB;IAE5B,MAAM,OAAO,QAAQ,uBAAuB;AAC5C,QAAI,KAAK,QAAQ,KAAK,KAAK,SAAS,GAAG;AACrC,aAAQ,KAAK;AACb,cAAS,KAAK;eAEd,mBAAmB,oBAChB,QAAQ,eAAe,KACvB,QAAQ,gBAAgB,GAC3B;AACA,aAAQ,QAAQ;AAChB,cAAS,QAAQ;;AAEnB,WAAO;KAAE;KAAK;KAAO;KAAQ;;GAEhC,CACF;EACD,MAAM,MAAM;AAEV,UAAO,CAAC,OADM,KAAK,MACE;;EAExB,CAAC;;;;;;;;AChDJ,SAAgB,cAA8B;AAC5C,QAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-image.js","names":["attrs: ImageAttrs","positions: number[]","width: number | null","height: number | null","defaultOnError: ImageUploadErrorHandler","handlePaste: FilePasteHandler","handleDrop: FileDropHandler"],"sources":["../src/image/image-commands/insert-image.ts","../src/image/image-commands/upload-image.ts","../src/image/image-commands.ts","../src/image/image-spec.ts","../src/image/image.ts","../src/image/image-upload-handler.ts"],"sourcesContent":["import { insertNode } from '@prosekit/core'\nimport type { Command } from '@prosekit/pm/state'\n\nimport type { ImageAttrs } from '../image-spec'\n\n/**\n * Returns a command that inserts an image node with the given attributes at the\n * current selection position.\n *\n * @public\n */\nexport function insertImage(attrs?: ImageAttrs): Command {\n return insertNode({ type: 'image', attrs })\n}\n","import {\n insertNode,\n ProseKitError,\n} from '@prosekit/core'\nimport type { Command } from '@prosekit/pm/state'\nimport type { EditorView } from '@prosekit/pm/view'\n\nimport {\n UploadTask,\n type Uploader,\n} from '../../file'\nimport type { ImageAttrs } from '../image-spec'\n\n/**\n * Options for {@link uploadImage}.\n *\n * @public\n */\nexport interface UploadImageOptions {\n /**\n * The uploader used to upload the file. It should return a promise that\n * resolves to the URL of the uploaded image.\n */\n uploader: Uploader<string>\n /**\n * The file that will be uploaded.\n */\n file: File\n /**\n * The position where the image should be inserted. If not provided, the\n * image is inserted at the current selection.\n */\n pos?: number\n /**\n * A handler to be called when an error occurs during the upload.\n */\n onError?: ImageUploadErrorHandler\n}\n\n/**\n * Options for the {@link ImageUploadErrorHandler} callback.\n *\n * @public\n */\nexport interface ImageUploadErrorHandlerOptions {\n /**\n * The file that was uploaded.\n */\n file: File\n /**\n * The error that occurred during the upload.\n */\n error: unknown\n /**\n * The upload task that was used to upload the file.\n */\n uploadTask: UploadTask<string>\n}\n\n/**\n * A handler to be called when an error occurs during the upload.\n *\n * @public\n */\nexport type ImageUploadErrorHandler = (options: ImageUploadErrorHandlerOptions) => void\n\n/**\n * Returns a command that uploads an image file and inserts an image node with a\n * temporary URL which is replaced once the upload completes.\n *\n * @param options\n *\n * @public\n */\nexport function uploadImage({ uploader, file, pos, onError }: UploadImageOptions): Command {\n return (state, dispatch, view) => {\n const uploadTask = new UploadTask({ file, uploader })\n const objectURL = uploadTask.objectURL\n const attrs: ImageAttrs = { src: objectURL }\n\n uploadTask.finished\n .then((resultURL) => {\n if (view && view.isDestroyed) {\n return\n } else if (typeof resultURL !== 'string') {\n const error = new ProseKitError(\n `Unexpected upload result. Expected a string but got ${typeof resultURL}`,\n )\n onError?.({ file, error, uploadTask })\n } else if (!view) {\n const error = new ProseKitError(\n 'View must be available to replace the image URL',\n )\n onError?.({ file, error, uploadTask })\n } else {\n replaceImageURL(view, objectURL, resultURL)\n UploadTask.delete(objectURL)\n }\n })\n .catch((error) => {\n onError?.({ file, error, uploadTask })\n })\n\n return insertNode({ type: 'image', attrs, pos })(state, dispatch, view)\n }\n}\n\n/**\n * Replaces the temporary image URL with the final uploaded URL.\n *\n * @internal\n */\nexport function replaceImageURL(\n view: EditorView,\n oldURL: string,\n newURL: string,\n): void {\n const positions: number[] = []\n view.state.doc.descendants((node, pos) => {\n if (node.type.name === 'image') {\n const attrs = node.attrs as ImageAttrs\n if (attrs.src === oldURL) {\n positions.push(pos)\n }\n }\n })\n\n if (positions.length === 0) {\n return\n }\n\n const tr = view.state.tr\n for (const pos of positions) {\n tr.setNodeAttribute(pos, 'src', newURL)\n }\n view.dispatch(tr)\n}\n","import {\n defineCommands,\n type Extension,\n} from '@prosekit/core'\n\nimport { insertImage } from './image-commands/insert-image'\nimport {\n uploadImage,\n type UploadImageOptions,\n} from './image-commands/upload-image'\nimport type { ImageAttrs } from './image-spec'\n\n/**\n * @internal\n */\nexport type ImageCommandsExtension = Extension<{\n Commands: {\n insertImage: [attrs?: ImageAttrs]\n uploadImage: [options: UploadImageOptions]\n }\n}>\n\n/**\n * @internal\n */\nexport function defineImageCommands(): ImageCommandsExtension {\n return defineCommands({\n insertImage,\n uploadImage,\n })\n}\n","import {\n defineNodeSpec,\n type Extension,\n} from '@prosekit/core'\n\n/**\n * @public\n */\nexport interface ImageAttrs {\n src?: string | null\n width?: number | null\n height?: number | null\n}\n\n/**\n * @internal\n */\nexport type ImageSpecExtension = Extension<{\n Nodes: {\n image: ImageAttrs\n }\n}>\n\n/**\n * @internal\n */\nexport function defineImageSpec(): ImageSpecExtension {\n return defineNodeSpec({\n name: 'image',\n attrs: {\n src: { default: null, validate: 'string|null' },\n width: { default: null, validate: 'number|null' },\n height: { default: null, validate: 'number|null' },\n },\n group: 'block',\n defining: true,\n draggable: true,\n parseDOM: [\n {\n tag: 'img[src]',\n getAttrs: (element): ImageAttrs => {\n if (typeof element === 'string') {\n return { src: null }\n }\n\n const src = element.getAttribute('src') || null\n\n let width: number | null = null\n let height: number | null = null\n\n const rect = element.getBoundingClientRect()\n if (rect.width > 0 && rect.height > 0) {\n width = rect.width\n height = rect.height\n } else if (\n element instanceof HTMLImageElement\n && element.naturalWidth > 0\n && element.naturalHeight > 0\n ) {\n width = element.naturalWidth\n height = element.naturalHeight\n }\n return { src, width, height }\n },\n },\n ],\n toDOM(node) {\n const attrs = node.attrs as ImageAttrs\n return ['img', attrs]\n },\n })\n}\n","import {\n union,\n type Union,\n} from '@prosekit/core'\n\nimport {\n defineImageCommands,\n type ImageCommandsExtension,\n} from './image-commands'\nimport {\n defineImageSpec,\n type ImageSpecExtension,\n} from './image-spec'\n\n/**\n * @internal\n */\nexport type ImageExtension = Union<[ImageSpecExtension, ImageCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineImage(): ImageExtension {\n return union(defineImageSpec(), defineImageCommands())\n}\n","import {\n union,\n type PlainExtension,\n} from '@prosekit/core'\n\nimport {\n defineFileDropHandler,\n defineFilePasteHandler,\n type FileDropHandler,\n type FileDropHandlerOptions,\n type FilePasteHandler,\n type FilePasteHandlerOptions,\n type Uploader,\n} from '../file'\n\nimport {\n uploadImage,\n type ImageUploadErrorHandler,\n} from './image-commands/upload-image'\n\n/**\n * A predicate to determine if the pasted file should be uploaded and inserted as an image.\n */\nexport type ImageCanPastePredicate = (options: FilePasteHandlerOptions) => boolean\n\n/**\n * A predicate to determine if the dropped file should be uploaded and inserted as an image.\n */\nexport type ImageCanDropPredicate = (options: FileDropHandlerOptions) => boolean\n\n/**\n * A handler to be called when an error occurs during the upload.\n */\nexport interface ImageUploadHandlerOptions {\n /**\n * The uploader used to upload the file. It should return a promise that\n * resolves to the URL of the uploaded image.\n */\n uploader: Uploader<string>\n /**\n * A predicate to determine if the pasted file should be uploaded and inserted as an image.\n * If not provided, it defaults to only allowing paste of files with a content type starting with `image/`.\n */\n canPaste?: ImageCanPastePredicate\n /**\n * A predicate to determine if the dropped file should be uploaded and inserted as an image.\n * If not provided, it defaults to only allowing drop of files with a content type starting with `image/`.\n */\n canDrop?: ImageCanDropPredicate\n /**\n * A handler to be called when an error occurs during the upload.\n * If not provided, it defaults to logging the error to the console.\n */\n onError?: ImageUploadErrorHandler\n}\n\nfunction defaultCanUpload({ file }: { file: File }): boolean {\n // Only handle image files by default\n return file.type.startsWith('image/')\n}\n\nconst defaultOnError: ImageUploadErrorHandler = ({ error }) => {\n console.error('[prosekit] Failed to upload image:', error)\n}\n\n/**\n * Returns an extension that handles image file uploads when pasting or dropping\n * images into the editor.\n *\n * @param options\n */\nexport function defineImageUploadHandler({\n uploader,\n canPaste = defaultCanUpload,\n canDrop = defaultCanUpload,\n onError = defaultOnError,\n}: ImageUploadHandlerOptions): PlainExtension {\n const handlePaste: FilePasteHandler = (options) => {\n if (!canPaste(options)) return false\n const { view, file } = options\n const command = uploadImage({ uploader, file, onError })\n return command(view.state, view.dispatch, view)\n }\n\n const handleDrop: FileDropHandler = (options) => {\n if (!canDrop(options)) return false\n const { view, file, pos } = options\n const command = uploadImage({ uploader, file, onError, pos })\n return command(view.state, view.dispatch, view)\n }\n\n return union(\n defineFilePasteHandler(handlePaste),\n defineFileD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AS,CAAC,CACzC,KAAK,OAAO,KAAK,UAAU,KAAK;;CAGjD,MAAMC,cAA+B,YAAY;AAC/C,MAAI,CAAC,QAAQ,QAAQ,CAAE,QAAO;EAC9B,MAAM,EAAE,MAAM,MAAM,QAAQ;AAE5B,SADgB,YAAY;GAAE;GAAU;GAAM;GAAS;GAAK,CAAC,CAC9C,KAAK,OAAO,KAAK,UAAU,KAAK;;AAGjD,QAAO,MACL,uBAAuB,YAAY,EACnC,sBAAsB,WAAW,CAClC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { createMarkInputRule, defineInputRule, defineMarkInputRule, defineTextBlockInputRule, defineWrappingInputRule } from "./input-rule-
|
|
1
|
+
import { createMarkInputRule, defineInputRule, defineMarkInputRule, defineTextBlockInputRule, defineWrappingInputRule } from "./input-rule-DO_iy2aT.js";
|
|
2
2
|
|
|
3
3
|
export { createMarkInputRule, defineInputRule, defineMarkInputRule, defineTextBlockInputRule, defineWrappingInputRule };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineMarkInputRule } from "./input-rule-
|
|
1
|
+
import { defineMarkInputRule } from "./input-rule-DO_iy2aT.js";
|
|
2
2
|
import { canUseRegexLookbehind, defineCommands, defineKeymap, defineMarkSpec, toggleMark, union } from "@prosekit/core";
|
|
3
3
|
|
|
4
4
|
//#region src/italic/italic-commands.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineInputRule } from "./input-rule-
|
|
2
|
-
import { defineEnterRule } from "./enter-rule-
|
|
3
|
-
import { defineMarkRule } from "./mark-rule-
|
|
4
|
-
import { defineMarkPasteRule } from "./paste-rule-
|
|
1
|
+
import { defineInputRule } from "./input-rule-DO_iy2aT.js";
|
|
2
|
+
import { defineEnterRule } from "./enter-rule-5tkoU2Ir.js";
|
|
3
|
+
import { defineMarkRule } from "./mark-rule-CGmswjQ_.js";
|
|
4
|
+
import { defineMarkPasteRule } from "./paste-rule-Brej6cWi.js";
|
|
5
5
|
import { addMark, defineCommands, defineMarkSpec, expandMark, removeMark, toggleMark, union } from "@prosekit/core";
|
|
6
6
|
import { InputRule } from "@prosekit/pm/inputrules";
|
|
7
7
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { defineInputRule } from "./input-rule-
|
|
2
|
-
import { defineDropIndicator } from "./drop-indicator-
|
|
1
|
+
import { defineInputRule } from "./input-rule-DO_iy2aT.js";
|
|
2
|
+
import { defineDropIndicator } from "./drop-indicator-E7nCfdnR.js";
|
|
3
3
|
import { defineClipboardSerializer, defineCommands, defineKeymap, defineNodeSpec, definePlugin, insertNode, union } from "@prosekit/core";
|
|
4
4
|
import { Plugin } from "@prosekit/pm/state";
|
|
5
5
|
import { chainCommands, deleteSelection } from "@prosekit/pm/commands";
|
|
6
|
-
import { isElementLike } from "@ocavue/utils";
|
|
7
6
|
import { ListDOMSerializer, createDedentListCommand, createIndentListCommand, createListEventPlugin, createListRenderingPlugin, createListSpec, createMoveListCommand, createSafariInputMethodWorkaroundPlugin, createSplitListCommand, createToggleCollapsedCommand, createToggleListCommand, createUnwrapListCommand, createWrapInListCommand, deleteCommand, enterCommand, joinCollapsedListBackward, joinListElements, joinListUp, listInputRules, listToDOM, protectCollapsed, unwrapListSlice } from "prosemirror-flat-list";
|
|
7
|
+
import { isElementLike } from "@ocavue/utils";
|
|
8
8
|
|
|
9
9
|
//#region src/list/list-commands.ts
|
|
10
10
|
function insertList(attrs) {
|
|
@@ -117,8 +117,7 @@ function defineListSerializer() {
|
|
|
117
117
|
return defineClipboardSerializer({
|
|
118
118
|
serializeFragmentWrapper: (fn) => {
|
|
119
119
|
return (...args) => {
|
|
120
|
-
|
|
121
|
-
return joinListElements(dom);
|
|
120
|
+
return joinListElements(fn(...args));
|
|
122
121
|
};
|
|
123
122
|
},
|
|
124
123
|
serializeNodeWrapper: (fn) => {
|
|
@@ -158,9 +157,8 @@ function getMarkers(node) {
|
|
|
158
157
|
* @internal
|
|
159
158
|
*/
|
|
160
159
|
function defineListSpec() {
|
|
161
|
-
const spec = createListSpec();
|
|
162
160
|
return defineNodeSpec({
|
|
163
|
-
...
|
|
161
|
+
...createListSpec(),
|
|
164
162
|
toDOM: (node) => {
|
|
165
163
|
return listToDOM({
|
|
166
164
|
node,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prosekit-extensions-list.js","names":["onDrag: DragEventHandler"],"sources":["../src/list/list-commands.ts","../src/list/list-drop-indicator.ts","../src/list/list-input-rules.ts","../src/list/list-keymap.ts","../src/list/list-plugins.ts","../src/list/list-serializer.ts","../src/list/list-spec.ts","../src/list/list.ts"],"sourcesContent":["import {\n defineCommands,\n insertNode,\n type Extension,\n} from '@prosekit/core'\nimport type { Command } from '@prosekit/pm/state'\nimport {\n createDedentListCommand as dedentList,\n createIndentListCommand as indentList,\n createMoveListCommand as moveList,\n createSplitListCommand as splitList,\n createToggleCollapsedCommand as toggleCollapsed,\n createToggleListCommand as toggleList,\n createUnwrapListCommand as unwrapList,\n createWrapInListCommand as wrapInList,\n type DedentListOptions,\n type IndentListOptions,\n type ListAttributes,\n type ToggleCollapsedOptions,\n type UnwrapListOptions,\n} from 'prosemirror-flat-list'\n\nfunction insertList(attrs?: ListAttributes): Command {\n return insertNode({ type: 'list', attrs })\n}\n\n/**\n * @internal\n */\nexport type ListCommandsExtension = Extension<{\n Commands: {\n dedentList: [options?: DedentListOptions]\n indentList: [options?: IndentListOptions]\n moveList: [direction: 'up' | 'down']\n splitList: []\n toggleCollapsed: [options?: ToggleCollapsedOptions]\n unwrapList: [options?: UnwrapListOptions]\n toggleList: [attrs?: ListAttributes]\n wrapInList: [attrs?: ListAttributes]\n insertList: [attrs?: ListAttributes]\n }\n}>\n\n/**\n * Defines list commands.\n *\n * @internal\n */\nexport function defineListCommands(): ListCommandsExtension {\n return defineCommands({\n dedentList,\n indentList,\n moveList,\n splitList,\n toggleCollapsed,\n unwrapList,\n toggleList,\n wrapInList,\n insertList,\n })\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport type { DragEventHandler } from '../drop-indicator'\nimport { defineDropIndicator } from '../drop-indicator'\n\n/**\n * Configures drop indicator to avoid unexpected drop point.\n *\n * We don't want to drag a list node and drop it as the first\n * child of another list node.\n *\n * @internal\n */\nexport function defineListDropIndicator(): PlainExtension {\n return defineDropIndicator({\n onDrag,\n })\n}\n\nconst onDrag: DragEventHandler = ({ view, pos }): boolean => {\n const slice = view.dragging?.slice\n if (\n slice\n && slice.openStart === 0\n && slice.openEnd === 0\n && slice.content.childCount === 1\n ) {\n const node = slice.content.child(0)\n if (node.type.name === 'list') {\n const $pos = view.state.doc.resolve(pos)\n if ($pos.parent.type.name === 'list' && $pos.index() === 0) {\n return false\n }\n }\n }\n return true\n}\n","import {\n union,\n type Extension,\n} from '@prosekit/core'\nimport { listInputRules } from 'prosemirror-flat-list'\n\nimport { defineInputRule } from '../input-rule'\n\n/**\n * @internal\n */\nexport function defineListInputRules(): Extension {\n return union(listInputRules.map(defineInputRule))\n}\n","import {\n defineKeymap,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n chainCommands,\n deleteSelection,\n} from '@prosekit/pm/commands'\nimport {\n createDedentListCommand,\n createIndentListCommand,\n deleteCommand,\n enterCommand,\n joinCollapsedListBackward,\n joinListUp,\n protectCollapsed,\n} from 'prosemirror-flat-list'\n\n// This is different from the one exported by prosemirror-flat-list, because\n// some commands are moved to `defineBaseKeymap` in `prosekit/core`.\nconst backspaceCommand = chainCommands(\n protectCollapsed,\n deleteSelection,\n joinListUp,\n joinCollapsedListBackward,\n)\n\nconst dedentListCommand = createDedentListCommand()\nconst indentListCommand = createIndentListCommand()\n\nconst listKeymap = {\n 'Enter': enterCommand,\n 'Backspace': backspaceCommand,\n 'Delete': deleteCommand,\n 'Mod-]': indentListCommand,\n 'Mod-[': dedentListCommand,\n 'Tab': indentListCommand,\n 'Shift-Tab': dedentListCommand,\n}\n\n/**\n * Returns a extension that adds key bindings for list.\n *\n * @internal\n */\nexport function defineListKeymap(): PlainExtension {\n return defineKeymap(listKeymap)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport { Plugin } from '@prosekit/pm/state'\nimport {\n createListEventPlugin,\n createListRenderingPlugin,\n createSafariInputMethodWorkaroundPlugin,\n unwrapListSlice,\n} from 'prosemirror-flat-list'\n\nfunction createListClipboardPlugin(): Plugin {\n return new Plugin({\n props: {\n transformCopied: unwrapListSlice,\n },\n })\n}\n\nfunction createListPlugins(): Plugin[] {\n return [\n createListEventPlugin(),\n createListRenderingPlugin(),\n createListClipboardPlugin(),\n createSafariInputMethodWorkaroundPlugin(),\n ]\n}\n\n/**\n * @internal\n */\nexport function defineListPlugins(): PlainExtension {\n return definePlugin(createListPlugins)\n}\n","import { isElementLike } from '@ocavue/utils'\nimport {\n defineClipboardSerializer,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n joinListElements,\n listToDOM,\n} from 'prosemirror-flat-list'\n\n/**\n * @internal\n */\nexport function defineListSerializer(): PlainExtension {\n return defineClipboardSerializer({\n serializeFragmentWrapper: (fn) => {\n return (...args) => {\n const dom = fn(...args)\n return joinListElements(dom)\n }\n },\n serializeNodeWrapper: (fn) => {\n return (...args) => {\n const dom = fn(...args)\n return isElementLike(dom) ? joinListElements(dom) : dom\n }\n },\n nodesFromSchemaWrapper: (fn) => {\n return (...args) => {\n const nodes = fn(...args)\n return {\n ...nodes,\n list: (node) => listToDOM({ node, nativeList: true, getMarkers: () => null }),\n }\n }\n },\n })\n}\n","import {\n defineNodeSpec,\n type Extension,\n} from '@prosekit/core'\nimport type {\n DOMOutputSpec,\n ProseMirrorNode,\n} from '@prosekit/pm/model'\nimport {\n createListSpec,\n listToDOM,\n type ListAttributes,\n} from 'prosemirror-flat-list'\n\nimport type { ListAttrs } from './list-types'\n\n/**\n * @internal\n */\nexport type ListSpecExtension = Extension<{\n Nodes: {\n list: ListAttrs\n }\n}>\n\nfunction getMarkers(node: ProseMirrorNode): DOMOutputSpec[] {\n const attrs = node.attrs as ListAttributes\n switch (attrs.kind) {\n case 'task':\n // Use a `label` element here so that the area around the checkbox is also checkable.\n return [\n [\n 'label',\n [\n 'input',\n { type: 'checkbox', checked: attrs.checked ? '' : undefined },\n ],\n ],\n ]\n default:\n // Always return an empty array so that the marker element is rendered. This\n // is required to make the drop indicator locate the correct position.\n return []\n }\n}\n\n/**\n * @internal\n */\nexport function defineListSpec(): ListSpecExtension {\n const spec = createListSpec()\n\n return defineNodeSpec<'list', ListAttrs>({\n ...spec,\n toDOM: (node) => {\n return listToDOM({ node, getMarkers })\n },\n name: 'list',\n })\n}\n","import {\n union,\n type Union,\n} from '@prosekit/core'\n\nimport {\n defineListCommands,\n type ListCommandsExtension,\n} from './list-commands'\nimport { defineListDropIndicator } from './list-drop-indicator'\nimport { defineListInputRules } from './list-input-rules'\nimport { defineListKeymap } from './list-keymap'\nimport { defineListPlugins } from './list-plugins'\nimport { defineListSerializer } from './list-serializer'\nimport {\n defineListSpec,\n type ListSpecExtension,\n} from './list-spec'\n\n/**\n * @internal\n */\nexport type ListExtension = Union<[ListSpecExtension, ListCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineList(): ListExtension {\n return union(\n defineListSpec(),\n defineListPlugins(),\n defineListKeymap(),\n defineListInputRules(),\n defineListCommands(),\n defineListSerializer(),\n defineListDropIndicator(),\n )\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAS,WAAW,OAAiC;AACnD,QAAO,WAAW;EAAE,MAAM;EAAQ;EAAO,CAAC;;;;;;;AAyB5C,SAAgB,qBAA4C;AAC1D,QAAO,eAAe;EACpB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;;;;;;;;;;;;;AC9CJ,SAAgB,0BAA0C;AACxD,QAAO,oBAAoB,EACzB,QACD,CAAC;;AAGJ,MAAMA,UAA4B,EAAE,MAAM,UAAmB;CAC3D,MAAM,QAAQ,KAAK,UAAU;AAC7B,KACE,SACG,MAAM,cAAc,KACpB,MAAM,YAAY,KAClB,MAA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M,YAAY;MAAM,kBAAkB;MAAM,CAAC;KAC9E;;;EAGN,CAAC;;;;;ACXJ,SAAS,WAAW,MAAwC;CAC1D,MAAM,QAAQ,KAAK;AACnB,SAAQ,MAAM,MAAd;EACE,KAAK,OAEH,QAAO,CACL,CACE,SACA,CACE,SACA;GAAE,MAAM;GAAY,SAAS,MAAM,UAAU,KAAK;GAAW,CAC9D,CACF,CACF;EACH,QAGE,QAAO,EAAE;;;;;;AAOf,SAAgB,iBAAoC;CAClD,MAAM,OAAO,gBAAgB;AAE7B,QAAO,eAAkC;EACvC,GAAG;EACH,QAAQ,SAAS;AACf,UAAO,UAAU;IAAE;IAAM;IAAY,CAAC;;EAExC,MAAM;EACP,CAAC;;;;;;;;AC/BJ,SAAgB,aAA4B;AAC1C,QAAO,MACL,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,CAC1B"}
|
|
1
|
+
{"version":3,"file":"prosekit-extensions-list.js","names":["onDrag: DragEventHandler"],"sources":["../src/list/list-commands.ts","../src/list/list-drop-indicator.ts","../src/list/list-input-rules.ts","../src/list/list-keymap.ts","../src/list/list-plugins.ts","../src/list/list-serializer.ts","../src/list/list-spec.ts","../src/list/list.ts"],"sourcesContent":["import {\n defineCommands,\n insertNode,\n type Extension,\n} from '@prosekit/core'\nimport type { Command } from '@prosekit/pm/state'\nimport {\n createDedentListCommand as dedentList,\n createIndentListCommand as indentList,\n createMoveListCommand as moveList,\n createSplitListCommand as splitList,\n createToggleCollapsedCommand as toggleCollapsed,\n createToggleListCommand as toggleList,\n createUnwrapListCommand as unwrapList,\n createWrapInListCommand as wrapInList,\n type DedentListOptions,\n type IndentListOptions,\n type ListAttributes,\n type ToggleCollapsedOptions,\n type UnwrapListOptions,\n} from 'prosemirror-flat-list'\n\nfunction insertList(attrs?: ListAttributes): Command {\n return insertNode({ type: 'list', attrs })\n}\n\n/**\n * @internal\n */\nexport type ListCommandsExtension = Extension<{\n Commands: {\n dedentList: [options?: DedentListOptions]\n indentList: [options?: IndentListOptions]\n moveList: [direction: 'up' | 'down']\n splitList: []\n toggleCollapsed: [options?: ToggleCollapsedOptions]\n unwrapList: [options?: UnwrapListOptions]\n toggleList: [attrs?: ListAttributes]\n wrapInList: [attrs?: ListAttributes]\n insertList: [attrs?: ListAttributes]\n }\n}>\n\n/**\n * Defines list commands.\n *\n * @internal\n */\nexport function defineListCommands(): ListCommandsExtension {\n return defineCommands({\n dedentList,\n indentList,\n moveList,\n splitList,\n toggleCollapsed,\n unwrapList,\n toggleList,\n wrapInList,\n insertList,\n })\n}\n","import type { PlainExtension } from '@prosekit/core'\n\nimport type { DragEventHandler } from '../drop-indicator'\nimport { defineDropIndicator } from '../drop-indicator'\n\n/**\n * Configures drop indicator to avoid unexpected drop point.\n *\n * We don't want to drag a list node and drop it as the first\n * child of another list node.\n *\n * @internal\n */\nexport function defineListDropIndicator(): PlainExtension {\n return defineDropIndicator({\n onDrag,\n })\n}\n\nconst onDrag: DragEventHandler = ({ view, pos }): boolean => {\n const slice = view.dragging?.slice\n if (\n slice\n && slice.openStart === 0\n && slice.openEnd === 0\n && slice.content.childCount === 1\n ) {\n const node = slice.content.child(0)\n if (node.type.name === 'list') {\n const $pos = view.state.doc.resolve(pos)\n if ($pos.parent.type.name === 'list' && $pos.index() === 0) {\n return false\n }\n }\n }\n return true\n}\n","import {\n union,\n type Extension,\n} from '@prosekit/core'\nimport { listInputRules } from 'prosemirror-flat-list'\n\nimport { defineInputRule } from '../input-rule'\n\n/**\n * @internal\n */\nexport function defineListInputRules(): Extension {\n return union(listInputRules.map(defineInputRule))\n}\n","import {\n defineKeymap,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n chainCommands,\n deleteSelection,\n} from '@prosekit/pm/commands'\nimport {\n createDedentListCommand,\n createIndentListCommand,\n deleteCommand,\n enterCommand,\n joinCollapsedListBackward,\n joinListUp,\n protectCollapsed,\n} from 'prosemirror-flat-list'\n\n// This is different from the one exported by prosemirror-flat-list, because\n// some commands are moved to `defineBaseKeymap` in `prosekit/core`.\nconst backspaceCommand = chainCommands(\n protectCollapsed,\n deleteSelection,\n joinListUp,\n joinCollapsedListBackward,\n)\n\nconst dedentListCommand = createDedentListCommand()\nconst indentListCommand = createIndentListCommand()\n\nconst listKeymap = {\n 'Enter': enterCommand,\n 'Backspace': backspaceCommand,\n 'Delete': deleteCommand,\n 'Mod-]': indentListCommand,\n 'Mod-[': dedentListCommand,\n 'Tab': indentListCommand,\n 'Shift-Tab': dedentListCommand,\n}\n\n/**\n * Returns a extension that adds key bindings for list.\n *\n * @internal\n */\nexport function defineListKeymap(): PlainExtension {\n return defineKeymap(listKeymap)\n}\n","import {\n definePlugin,\n type PlainExtension,\n} from '@prosekit/core'\nimport { Plugin } from '@prosekit/pm/state'\nimport {\n createListEventPlugin,\n createListRenderingPlugin,\n createSafariInputMethodWorkaroundPlugin,\n unwrapListSlice,\n} from 'prosemirror-flat-list'\n\nfunction createListClipboardPlugin(): Plugin {\n return new Plugin({\n props: {\n transformCopied: unwrapListSlice,\n },\n })\n}\n\nfunction createListPlugins(): Plugin[] {\n return [\n createListEventPlugin(),\n createListRenderingPlugin(),\n createListClipboardPlugin(),\n createSafariInputMethodWorkaroundPlugin(),\n ]\n}\n\n/**\n * @internal\n */\nexport function defineListPlugins(): PlainExtension {\n return definePlugin(createListPlugins)\n}\n","import { isElementLike } from '@ocavue/utils'\nimport {\n defineClipboardSerializer,\n type PlainExtension,\n} from '@prosekit/core'\nimport {\n joinListElements,\n listToDOM,\n} from 'prosemirror-flat-list'\n\n/**\n * @internal\n */\nexport function defineListSerializer(): PlainExtension {\n return defineClipboardSerializer({\n serializeFragmentWrapper: (fn) => {\n return (...args) => {\n const dom = fn(...args)\n return joinListElements(dom)\n }\n },\n serializeNodeWrapper: (fn) => {\n return (...args) => {\n const dom = fn(...args)\n return isElementLike(dom) ? joinListElements(dom) : dom\n }\n },\n nodesFromSchemaWrapper: (fn) => {\n return (...args) => {\n const nodes = fn(...args)\n return {\n ...nodes,\n list: (node) => listToDOM({ node, nativeList: true, getMarkers: () => null }),\n }\n }\n },\n })\n}\n","import {\n defineNodeSpec,\n type Extension,\n} from '@prosekit/core'\nimport type {\n DOMOutputSpec,\n ProseMirrorNode,\n} from '@prosekit/pm/model'\nimport {\n createListSpec,\n listToDOM,\n type ListAttributes,\n} from 'prosemirror-flat-list'\n\nimport type { ListAttrs } from './list-types'\n\n/**\n * @internal\n */\nexport type ListSpecExtension = Extension<{\n Nodes: {\n list: ListAttrs\n }\n}>\n\nfunction getMarkers(node: ProseMirrorNode): DOMOutputSpec[] {\n const attrs = node.attrs as ListAttributes\n switch (attrs.kind) {\n case 'task':\n // Use a `label` element here so that the area around the checkbox is also checkable.\n return [\n [\n 'label',\n [\n 'input',\n { type: 'checkbox', checked: attrs.checked ? '' : undefined },\n ],\n ],\n ]\n default:\n // Always return an empty array so that the marker element is rendered. This\n // is required to make the drop indicator locate the correct position.\n return []\n }\n}\n\n/**\n * @internal\n */\nexport function defineListSpec(): ListSpecExtension {\n const spec = createListSpec()\n\n return defineNodeSpec<'list', ListAttrs>({\n ...spec,\n toDOM: (node) => {\n return listToDOM({ node, getMarkers })\n },\n name: 'list',\n })\n}\n","import {\n union,\n type Union,\n} from '@prosekit/core'\n\nimport {\n defineListCommands,\n type ListCommandsExtension,\n} from './list-commands'\nimport { defineListDropIndicator } from './list-drop-indicator'\nimport { defineListInputRules } from './list-input-rules'\nimport { defineListKeymap } from './list-keymap'\nimport { defineListPlugins } from './list-plugins'\nimport { defineListSerializer } from './list-serializer'\nimport {\n defineListSpec,\n type ListSpecExtension,\n} from './list-spec'\n\n/**\n * @internal\n */\nexport type ListExtension = Union<[ListSpecExtension, ListCommandsExtension]>\n\n/**\n * @public\n */\nexport function defineList(): ListExtension {\n return union(\n defineListSpec(),\n defineListPlugins(),\n defineListKeymap(),\n defineListInputRules(),\n defineListCommands(),\n defineListSerializer(),\n defineListDropIndicator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