@prosekit/core 0.0.0-next-20240602042411 → 0.0.0-next-20240616145703
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 +48 -2
- package/dist/prosekit-core.d.ts +1 -0
- package/dist/prosekit-core.js +502 -937
- package/package.json +4 -4
package/dist/prosekit-core.js
CHANGED
@@ -7,15 +7,13 @@ import "@prosekit/pm/model";
|
|
7
7
|
|
8
8
|
// src/error.ts
|
9
9
|
var ProseKitError = class extends Error {
|
10
|
-
}
|
11
|
-
var EditorNotFoundError = class extends ProseKitError {
|
10
|
+
}, EditorNotFoundError = class extends ProseKitError {
|
12
11
|
constructor() {
|
13
12
|
super(
|
14
13
|
"Unable to find editor. Pass it as an argument or call this function inside a ProseKit component."
|
15
14
|
);
|
16
15
|
}
|
17
|
-
}
|
18
|
-
var DOMDocumentNotFoundError = class extends ProseKitError {
|
16
|
+
}, DOMDocumentNotFoundError = class extends ProseKitError {
|
19
17
|
constructor() {
|
20
18
|
super(
|
21
19
|
"Unable to find browser Document. When not in the browser environment, you need to pass a DOM Document."
|
@@ -25,11 +23,10 @@ var DOMDocumentNotFoundError = class extends ProseKitError {
|
|
25
23
|
|
26
24
|
// src/utils/get-mark-type.ts
|
27
25
|
function getMarkType(schema, type) {
|
28
|
-
if (typeof type
|
29
|
-
|
30
|
-
if (!markType)
|
26
|
+
if (typeof type == "string") {
|
27
|
+
let markType = schema.marks[type];
|
28
|
+
if (!markType)
|
31
29
|
throw new ProseKitError(`Cannot find mark type "${type}"`);
|
32
|
-
}
|
33
30
|
return markType;
|
34
31
|
}
|
35
32
|
return type;
|
@@ -39,14 +36,8 @@ function getMarkType(schema, type) {
|
|
39
36
|
function addMark(options) {
|
40
37
|
return (state, dispatch) => {
|
41
38
|
var _a, _b;
|
42
|
-
|
43
|
-
|
44
|
-
const to = (_b = options.to) != null ? _b : state.selection.to;
|
45
|
-
if (from > to) {
|
46
|
-
return false;
|
47
|
-
}
|
48
|
-
dispatch == null ? void 0 : dispatch(state.tr.addMark(from, to, mark));
|
49
|
-
return true;
|
39
|
+
let mark = getMarkType(state.schema, options.type).create(options.attrs), from = (_a = options.from) != null ? _a : state.selection.from, to = (_b = options.to) != null ? _b : state.selection.to;
|
40
|
+
return from > to ? !1 : (dispatch == null || dispatch(state.tr.addMark(from, to, mark)), !0);
|
50
41
|
};
|
51
42
|
}
|
52
43
|
|
@@ -54,52 +45,26 @@ function addMark(options) {
|
|
54
45
|
import { TextSelection } from "@prosekit/pm/state";
|
55
46
|
function expandMark(options) {
|
56
47
|
return (state, dispatch) => {
|
57
|
-
|
58
|
-
|
59
|
-
const from = expandMarkBefore(state.selection.$from, predicate);
|
60
|
-
const to = expandMarkAfter(state.selection.$to, predicate);
|
61
|
-
if (from === state.selection.from && to === state.selection.to) {
|
62
|
-
return false;
|
63
|
-
}
|
64
|
-
if (dispatch) {
|
65
|
-
dispatch(state.tr.setSelection(TextSelection.create(state.doc, from, to)));
|
66
|
-
}
|
67
|
-
return true;
|
48
|
+
let markType = getMarkType(state.schema, options.type), predicate = (mark) => mark.type === markType, from = expandMarkBefore(state.selection.$from, predicate), to = expandMarkAfter(state.selection.$to, predicate);
|
49
|
+
return from === state.selection.from && to === state.selection.to ? !1 : (dispatch && dispatch(state.tr.setSelection(TextSelection.create(state.doc, from, to))), !0);
|
68
50
|
};
|
69
51
|
}
|
70
52
|
function expandMarkBefore($pos, predicate) {
|
71
|
-
|
72
|
-
if (!$pos.marks().some(predicate))
|
53
|
+
let { parent } = $pos;
|
54
|
+
if (!$pos.marks().some(predicate))
|
73
55
|
return $pos.pos;
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
for (let i = index; i >= 0; i--) {
|
78
|
-
const node = parent.child(i);
|
79
|
-
if (node.marks.some(predicate)) {
|
80
|
-
boundaryIndex = i;
|
81
|
-
} else {
|
82
|
-
break;
|
83
|
-
}
|
84
|
-
}
|
56
|
+
let index = $pos.index(), boundaryIndex = index;
|
57
|
+
for (let i = index; i >= 0 && parent.child(i).marks.some(predicate); i--)
|
58
|
+
boundaryIndex = i;
|
85
59
|
return $pos.posAtIndex(boundaryIndex);
|
86
60
|
}
|
87
61
|
function expandMarkAfter($pos, predicate) {
|
88
|
-
|
89
|
-
if (!$pos.marks().some(predicate))
|
62
|
+
let { parent } = $pos;
|
63
|
+
if (!$pos.marks().some(predicate))
|
90
64
|
return $pos.pos;
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
let boundaryIndex = index;
|
95
|
-
for (let i = index; i < childCount; i++) {
|
96
|
-
const node = parent.child(i);
|
97
|
-
if (node.marks.some(predicate)) {
|
98
|
-
boundaryIndex = i;
|
99
|
-
} else {
|
100
|
-
break;
|
101
|
-
}
|
102
|
-
}
|
65
|
+
let index = Math.max(0, $pos.indexAfter() - 1), childCount = parent.childCount, boundaryIndex = index;
|
66
|
+
for (let i = index; i < childCount && parent.child(i).marks.some(predicate); i++)
|
67
|
+
boundaryIndex = i;
|
103
68
|
return $pos.posAtIndex(boundaryIndex) + parent.child(boundaryIndex).nodeSize;
|
104
69
|
}
|
105
70
|
|
@@ -109,19 +74,17 @@ import { insertPoint } from "@prosekit/pm/transform";
|
|
109
74
|
|
110
75
|
// src/utils/assert.ts
|
111
76
|
function assert(condition, message = "Assertion failed") {
|
112
|
-
if (!condition)
|
77
|
+
if (!condition)
|
113
78
|
throw new ProseKitError(message);
|
114
|
-
}
|
115
79
|
}
|
116
80
|
|
117
81
|
// src/utils/get-node-type.ts
|
118
82
|
import "@prosekit/pm/model";
|
119
83
|
function getNodeType(schema, type) {
|
120
|
-
if (typeof type
|
121
|
-
|
122
|
-
if (!nodeType)
|
84
|
+
if (typeof type == "string") {
|
85
|
+
let nodeType = schema.nodes[type];
|
86
|
+
if (!nodeType)
|
123
87
|
throw new ProseKitError(`Cannot find ProseMirror node type "${type}"`);
|
124
|
-
}
|
125
88
|
return nodeType;
|
126
89
|
}
|
127
90
|
return type;
|
@@ -130,9 +93,7 @@ function getNodeType(schema, type) {
|
|
130
93
|
// src/utils/set-selection-around.ts
|
131
94
|
import { TextSelection as TextSelection2 } from "@prosekit/pm/state";
|
132
95
|
function setSelectionAround(tr, pos) {
|
133
|
-
|
134
|
-
const $pos = tr.doc.resolve(pos > docSize ? docSize : pos < 0 ? 0 : pos);
|
135
|
-
const selection = TextSelection2.between($pos, $pos);
|
96
|
+
let docSize = tr.doc.content.size, $pos = tr.doc.resolve(pos > docSize ? docSize : pos < 0 ? 0 : pos), selection = TextSelection2.between($pos, $pos);
|
136
97
|
tr.setSelection(selection);
|
137
98
|
}
|
138
99
|
|
@@ -140,21 +101,43 @@ function setSelectionAround(tr, pos) {
|
|
140
101
|
function insertNode(options) {
|
141
102
|
return (state, dispatch) => {
|
142
103
|
var _a;
|
143
|
-
|
104
|
+
let node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createAndFill(options.attrs) : null;
|
144
105
|
assert(node, "You must provide either a node or a type");
|
145
|
-
|
106
|
+
let insertPos = insertPoint(
|
146
107
|
state.doc,
|
147
108
|
(_a = options.pos) != null ? _a : state.selection.to,
|
148
109
|
node.type
|
149
110
|
);
|
150
|
-
if (insertPos == null)
|
151
|
-
return false;
|
111
|
+
if (insertPos == null) return !1;
|
152
112
|
if (dispatch) {
|
153
|
-
|
154
|
-
setSelectionAround(tr, insertPos + node.nodeSize);
|
155
|
-
dispatch(tr);
|
113
|
+
let tr = state.tr.insert(insertPos, node);
|
114
|
+
setSelectionAround(tr, insertPos + node.nodeSize), dispatch(tr);
|
156
115
|
}
|
157
|
-
return
|
116
|
+
return !0;
|
117
|
+
};
|
118
|
+
}
|
119
|
+
|
120
|
+
// src/utils/find-parent-node.ts
|
121
|
+
function findParentNode(nodeType, $pos) {
|
122
|
+
for (let depth = $pos.depth; depth > 0; depth -= 1)
|
123
|
+
if ($pos.node(depth).type === nodeType) {
|
124
|
+
let from = $pos.before(depth), to = $pos.after(depth);
|
125
|
+
return {
|
126
|
+
from,
|
127
|
+
to
|
128
|
+
};
|
129
|
+
}
|
130
|
+
return {
|
131
|
+
from: null,
|
132
|
+
to: null
|
133
|
+
};
|
134
|
+
}
|
135
|
+
|
136
|
+
// src/commands/remove-node.ts
|
137
|
+
function removeNode(options) {
|
138
|
+
return (state, dispatch) => {
|
139
|
+
let nodeType = getNodeType(state.schema, options.type), $pos = typeof options.pos == "number" ? state.doc.resolve(options.pos) : state.selection.$anchor, { from, to } = findParentNode(nodeType, $pos);
|
140
|
+
return from == null || to == null || from > to ? !1 : (dispatch == null || dispatch(state.tr.delete(from, to)), !0);
|
158
141
|
};
|
159
142
|
}
|
160
143
|
|
@@ -164,15 +147,8 @@ import "@prosekit/pm/state";
|
|
164
147
|
function removeMark(options) {
|
165
148
|
return (state, dispatch) => {
|
166
149
|
var _a, _b;
|
167
|
-
|
168
|
-
|
169
|
-
const from = (_a = options.from) != null ? _a : state.selection.from;
|
170
|
-
const to = (_b = options.to) != null ? _b : state.selection.to;
|
171
|
-
if (from > to) {
|
172
|
-
return false;
|
173
|
-
}
|
174
|
-
dispatch == null ? void 0 : dispatch(state.tr.removeMark(from, to, mark));
|
175
|
-
return true;
|
150
|
+
let markType = getMarkType(state.schema, options.type), mark = options.attrs ? markType.create(options.attrs) : markType, from = (_a = options.from) != null ? _a : state.selection.from, to = (_b = options.to) != null ? _b : state.selection.to;
|
151
|
+
return from > to ? !1 : (dispatch == null || dispatch(state.tr.removeMark(from, to, mark)), !0);
|
176
152
|
};
|
177
153
|
}
|
178
154
|
|
@@ -182,10 +158,9 @@ import "@prosekit/pm/state";
|
|
182
158
|
// src/utils/get-custom-selection.ts
|
183
159
|
import { TextSelection as TextSelection3 } from "@prosekit/pm/state";
|
184
160
|
function getCustomSelection(state, from, to) {
|
185
|
-
|
161
|
+
let pos = from != null ? from : to;
|
186
162
|
if (pos != null) {
|
187
|
-
|
188
|
-
const $to = state.doc.resolve(to != null ? to : pos);
|
163
|
+
let $from = state.doc.resolve(from != null ? from : pos), $to = state.doc.resolve(to != null ? to : pos);
|
189
164
|
return TextSelection3.between($from, $to);
|
190
165
|
}
|
191
166
|
return state.selection;
|
@@ -194,34 +169,28 @@ function getCustomSelection(state, from, to) {
|
|
194
169
|
// src/commands/set-block-type.ts
|
195
170
|
function setBlockType(options) {
|
196
171
|
return (state, dispatch) => {
|
197
|
-
|
198
|
-
const selection = getCustomSelection(state, options.from, options.to);
|
199
|
-
const attrs = options.attrs;
|
200
|
-
let applicable = false;
|
172
|
+
let nodeType = getNodeType(state.schema, options.type), selection = getCustomSelection(state, options.from, options.to), attrs = options.attrs, applicable = !1;
|
201
173
|
for (let i = 0; i < selection.ranges.length && !applicable; i++) {
|
202
|
-
|
174
|
+
let {
|
203
175
|
$from: { pos: from },
|
204
176
|
$to: { pos: to }
|
205
177
|
} = selection.ranges[i];
|
206
178
|
state.doc.nodesBetween(from, to, (node, pos) => {
|
207
|
-
if (applicable)
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType);
|
216
|
-
}
|
179
|
+
if (applicable) return !1;
|
180
|
+
if (!(!node.isTextblock || node.hasMarkup(nodeType, attrs)))
|
181
|
+
if (node.type == nodeType)
|
182
|
+
applicable = !0;
|
183
|
+
else {
|
184
|
+
let $pos = state.doc.resolve(pos), index = $pos.index();
|
185
|
+
applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType);
|
186
|
+
}
|
217
187
|
});
|
218
188
|
}
|
219
|
-
if (!applicable)
|
220
|
-
return false;
|
189
|
+
if (!applicable) return !1;
|
221
190
|
if (dispatch) {
|
222
|
-
|
223
|
-
for (
|
224
|
-
|
191
|
+
let tr = state.tr;
|
192
|
+
for (let range of selection.ranges) {
|
193
|
+
let {
|
225
194
|
$from: { pos: from },
|
226
195
|
$to: { pos: to }
|
227
196
|
} = range;
|
@@ -229,48 +198,34 @@ function setBlockType(options) {
|
|
229
198
|
}
|
230
199
|
dispatch(tr.scrollIntoView());
|
231
200
|
}
|
232
|
-
return
|
201
|
+
return !0;
|
233
202
|
};
|
234
203
|
}
|
235
204
|
|
236
205
|
// src/utils/get-node-types.ts
|
237
206
|
import "@prosekit/pm/model";
|
238
207
|
function getNodeTypes(schema, types) {
|
239
|
-
|
240
|
-
return types.map((type) => getNodeType(schema, type));
|
241
|
-
}
|
242
|
-
return [getNodeType(schema, types)];
|
208
|
+
return Array.isArray(types) ? types.map((type) => getNodeType(schema, type)) : [getNodeType(schema, types)];
|
243
209
|
}
|
244
210
|
|
245
211
|
// src/commands/set-node-attrs.ts
|
246
212
|
function setNodeAttrs(options) {
|
247
213
|
return (state, dispatch) => {
|
248
214
|
var _a, _b;
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
positions.push(pos);
|
256
|
-
}
|
257
|
-
if (!dispatch && positions.length > 0) {
|
258
|
-
return false;
|
259
|
-
}
|
260
|
-
});
|
261
|
-
if (positions.length === 0) {
|
262
|
-
return false;
|
263
|
-
}
|
215
|
+
let nodeTypes = getNodeTypes(state.schema, options.type), from = (_a = options.pos) != null ? _a : state.selection.from, to = (_b = options.pos) != null ? _b : state.selection.to, positions = [];
|
216
|
+
if (state.doc.nodesBetween(from, to, (node, pos) => {
|
217
|
+
if (nodeTypes.includes(node.type) && positions.push(pos), !dispatch && positions.length > 0)
|
218
|
+
return !1;
|
219
|
+
}), positions.length === 0)
|
220
|
+
return !1;
|
264
221
|
if (dispatch) {
|
265
|
-
|
266
|
-
for (
|
267
|
-
for (
|
222
|
+
let { tr } = state;
|
223
|
+
for (let pos of positions)
|
224
|
+
for (let [key, value] of Object.entries(options.attrs))
|
268
225
|
tr.setNodeAttribute(pos, key, value);
|
269
|
-
}
|
270
|
-
}
|
271
226
|
dispatch(tr);
|
272
227
|
}
|
273
|
-
return
|
228
|
+
return !0;
|
274
229
|
};
|
275
230
|
}
|
276
231
|
|
@@ -278,83 +233,59 @@ function setNodeAttrs(options) {
|
|
278
233
|
import "@prosekit/pm/model";
|
279
234
|
import "@prosekit/pm/state";
|
280
235
|
function markApplies(doc, ranges, type) {
|
281
|
-
for (
|
282
|
-
let can = $from.depth == 0 ? doc.inlineContent && doc.type.allowsMarkType(type) :
|
283
|
-
doc.nodesBetween($from.pos, $to.pos, (node) => {
|
284
|
-
if (can)
|
285
|
-
return false;
|
236
|
+
for (let { $from, $to } of ranges) {
|
237
|
+
let can = $from.depth == 0 ? doc.inlineContent && doc.type.allowsMarkType(type) : !1;
|
238
|
+
if (doc.nodesBetween($from.pos, $to.pos, (node) => {
|
239
|
+
if (can) return !1;
|
286
240
|
can = node.inlineContent && node.type.allowsMarkType(type);
|
287
|
-
});
|
288
|
-
if (can)
|
289
|
-
return true;
|
241
|
+
}), can) return !0;
|
290
242
|
}
|
291
|
-
return
|
243
|
+
return !1;
|
292
244
|
}
|
293
245
|
function baseToggleMark(markType, attrs = null, options) {
|
294
|
-
|
246
|
+
let removeWhenPresent = (options && options.removeWhenPresent) !== !1;
|
295
247
|
return function(state, dispatch) {
|
296
|
-
|
248
|
+
let { empty, $cursor, ranges } = state.selection;
|
297
249
|
if (empty && !$cursor || !markApplies(state.doc, ranges, markType))
|
298
|
-
return
|
299
|
-
if (dispatch)
|
300
|
-
if ($cursor)
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
(
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
Math.max(0, r.$from.pos - pos),
|
321
|
-
Math.min(node.nodeSize, r.$to.pos - pos)
|
322
|
-
)
|
323
|
-
));
|
324
|
-
});
|
325
|
-
return !missing;
|
326
|
-
});
|
327
|
-
}
|
328
|
-
for (const { $from, $to } of ranges) {
|
329
|
-
if (!add) {
|
250
|
+
return !1;
|
251
|
+
if (dispatch)
|
252
|
+
if ($cursor)
|
253
|
+
markType.isInSet(state.storedMarks || $cursor.marks()) ? dispatch(state.tr.removeStoredMark(markType)) : dispatch(state.tr.addStoredMark(markType.create(attrs)));
|
254
|
+
else {
|
255
|
+
let add, tr = state.tr;
|
256
|
+
removeWhenPresent ? add = !ranges.some(
|
257
|
+
(r) => state.doc.rangeHasMark(r.$from.pos, r.$to.pos, markType)
|
258
|
+
) : add = !ranges.every((r) => {
|
259
|
+
let missing = !1;
|
260
|
+
return tr.doc.nodesBetween(r.$from.pos, r.$to.pos, (node, pos, parent) => {
|
261
|
+
if (missing) return !1;
|
262
|
+
missing = !markType.isInSet(node.marks) && !!parent && parent.type.allowsMarkType(markType) && !(node.isText && /^\s*$/.test(
|
263
|
+
node.textBetween(
|
264
|
+
Math.max(0, r.$from.pos - pos),
|
265
|
+
Math.min(node.nodeSize, r.$to.pos - pos)
|
266
|
+
)
|
267
|
+
));
|
268
|
+
}), !missing;
|
269
|
+
});
|
270
|
+
for (let { $from, $to } of ranges)
|
271
|
+
if (!add)
|
330
272
|
tr.removeMark($from.pos, $to.pos, markType);
|
331
|
-
|
332
|
-
let from = $from.pos, to = $to.pos;
|
333
|
-
|
334
|
-
const spaceStart = start && start.isText ? /^\s*/.exec(start.text)[0].length : 0;
|
335
|
-
const spaceEnd = end && end.isText ? /\s*$/.exec(end.text)[0].length : 0;
|
336
|
-
if (from + spaceStart < to) {
|
337
|
-
from += spaceStart;
|
338
|
-
to -= spaceEnd;
|
339
|
-
}
|
340
|
-
tr.addMark(from, to, markType.create(attrs));
|
273
|
+
else {
|
274
|
+
let from = $from.pos, to = $to.pos, start = $from.nodeAfter, end = $to.nodeBefore, spaceStart = start && start.isText ? /^\s*/.exec(start.text)[0].length : 0, spaceEnd = end && end.isText ? /\s*$/.exec(end.text)[0].length : 0;
|
275
|
+
from + spaceStart < to && (from += spaceStart, to -= spaceEnd), tr.addMark(from, to, markType.create(attrs));
|
341
276
|
}
|
342
|
-
}
|
343
277
|
dispatch(tr.scrollIntoView());
|
344
278
|
}
|
345
|
-
|
346
|
-
return true;
|
279
|
+
return !0;
|
347
280
|
};
|
348
281
|
}
|
349
282
|
function toggleMark({
|
350
283
|
type,
|
351
284
|
attrs
|
352
285
|
}) {
|
353
|
-
return (state, dispatch, view) => {
|
354
|
-
|
355
|
-
|
356
|
-
})(state, dispatch, view);
|
357
|
-
};
|
286
|
+
return (state, dispatch, view) => baseToggleMark(getMarkType(state.schema, type), attrs, {
|
287
|
+
removeWhenPresent: !1
|
288
|
+
})(state, dispatch, view);
|
358
289
|
}
|
359
290
|
|
360
291
|
// src/commands/toggle-node.ts
|
@@ -364,26 +295,22 @@ import "@prosekit/pm/state";
|
|
364
295
|
|
365
296
|
// src/utils/attrs-match.ts
|
366
297
|
function attrsMatch(nodeOrMark, attrs) {
|
367
|
-
|
368
|
-
for (
|
369
|
-
if (currentAttrs[key] !== value)
|
370
|
-
return
|
371
|
-
|
372
|
-
}
|
373
|
-
return true;
|
298
|
+
let currentAttrs = nodeOrMark.attrs;
|
299
|
+
for (let [key, value] of Object.entries(attrs))
|
300
|
+
if (currentAttrs[key] !== value)
|
301
|
+
return !1;
|
302
|
+
return !0;
|
374
303
|
}
|
375
304
|
|
376
305
|
// src/utils/is-node-active.ts
|
377
306
|
function isNodeActive(state, type, attrs) {
|
378
|
-
|
379
|
-
const nodeType = getNodeType(state.schema, type);
|
307
|
+
let $pos = state.selection.$from, nodeType = getNodeType(state.schema, type);
|
380
308
|
for (let depth = $pos.depth; depth >= 0; depth--) {
|
381
|
-
|
382
|
-
if (node.type === nodeType && (!attrs || attrsMatch(node, attrs)))
|
383
|
-
return
|
384
|
-
}
|
309
|
+
let node = $pos.node(depth);
|
310
|
+
if (node.type === nodeType && (!attrs || attrsMatch(node, attrs)))
|
311
|
+
return !0;
|
385
312
|
}
|
386
|
-
return
|
313
|
+
return !1;
|
387
314
|
}
|
388
315
|
|
389
316
|
// src/commands/toggle-node.ts
|
@@ -393,13 +320,10 @@ function toggleNode({
|
|
393
320
|
}) {
|
394
321
|
return (state, dispatch, view) => {
|
395
322
|
if (isNodeActive(state, type, attrs)) {
|
396
|
-
|
397
|
-
|
398
|
-
return false;
|
399
|
-
}
|
400
|
-
return setBlockType2(defaultType)(state, dispatch, view);
|
323
|
+
let defaultType = state.schema.topNodeType.contentMatch.defaultType;
|
324
|
+
return defaultType ? setBlockType2(defaultType)(state, dispatch, view) : !1;
|
401
325
|
} else {
|
402
|
-
|
326
|
+
let nodeType = getNodeType(state.schema, type);
|
403
327
|
return setBlockType2(nodeType, attrs)(state, dispatch, view);
|
404
328
|
}
|
405
329
|
};
|
@@ -414,26 +338,16 @@ import { EditorView } from "@prosekit/pm/view";
|
|
414
338
|
import { Selection } from "@prosekit/pm/state";
|
415
339
|
|
416
340
|
// src/types/priority.ts
|
417
|
-
var Priority = /* @__PURE__ */ ((Priority2) => {
|
418
|
-
Priority2[Priority2["lowest"] = 0] = "lowest";
|
419
|
-
Priority2[Priority2["low"] = 1] = "low";
|
420
|
-
Priority2[Priority2["default"] = 2] = "default";
|
421
|
-
Priority2[Priority2["high"] = 3] = "high";
|
422
|
-
Priority2[Priority2["highest"] = 4] = "highest";
|
423
|
-
return Priority2;
|
424
|
-
})(Priority || {});
|
341
|
+
var Priority = /* @__PURE__ */ ((Priority2) => (Priority2[Priority2.lowest = 0] = "lowest", Priority2[Priority2.low = 1] = "low", Priority2[Priority2.default = 2] = "default", Priority2[Priority2.high = 3] = "high", Priority2[Priority2.highest = 4] = "highest", Priority2))(Priority || {});
|
425
342
|
|
426
343
|
// src/facets/base-extension.ts
|
427
344
|
import "@prosekit/pm/model";
|
428
345
|
|
429
346
|
// src/utils/array.ts
|
430
347
|
function uniqPush(prev, next) {
|
431
|
-
|
432
|
-
for (
|
433
|
-
|
434
|
-
result.push(item);
|
435
|
-
}
|
436
|
-
}
|
348
|
+
let result = [...prev];
|
349
|
+
for (let item of next)
|
350
|
+
result.includes(item) || result.push(item);
|
437
351
|
return result;
|
438
352
|
}
|
439
353
|
function arraySubstract(a, b) {
|
@@ -455,108 +369,92 @@ function zip5(a, b, mapper) {
|
|
455
369
|
];
|
456
370
|
}
|
457
371
|
function unionInput(a, b) {
|
458
|
-
|
459
|
-
return null;
|
460
|
-
return uniqPush(a != null ? a : [], b != null ? b : []);
|
372
|
+
return !a && !b ? null : uniqPush(a != null ? a : [], b != null ? b : []);
|
461
373
|
}
|
462
374
|
function subtractInput(a, b) {
|
463
|
-
|
464
|
-
return null;
|
465
|
-
if (!b)
|
466
|
-
return [...a];
|
467
|
-
return arraySubstract(a, b);
|
375
|
+
return a ? b ? arraySubstract(a, b) : [...a] : null;
|
468
376
|
}
|
469
377
|
function unionChildren(a, b) {
|
470
|
-
|
471
|
-
for (
|
472
|
-
|
378
|
+
let merged = new Map(a);
|
379
|
+
for (let [key, valueB] of b.entries()) {
|
380
|
+
let valueA = a.get(key);
|
473
381
|
merged.set(key, valueA ? unionFacetNode(valueA, valueB) : valueB);
|
474
382
|
}
|
475
383
|
return merged;
|
476
384
|
}
|
477
385
|
function subtractChildren(a, b) {
|
478
|
-
|
479
|
-
for (
|
480
|
-
|
481
|
-
|
482
|
-
merged.set(key, subtractFacetNode(valueA, valueB));
|
483
|
-
}
|
386
|
+
let merged = new Map(a);
|
387
|
+
for (let [key, valueB] of b.entries()) {
|
388
|
+
let valueA = a.get(key);
|
389
|
+
valueA && merged.set(key, subtractFacetNode(valueA, valueB));
|
484
390
|
}
|
485
391
|
return merged;
|
486
392
|
}
|
487
393
|
function unionFacetNode(a, b) {
|
488
|
-
assert(a.facet === b.facet)
|
489
|
-
return new FacetNode(
|
394
|
+
return assert(a.facet === b.facet), new FacetNode(
|
490
395
|
a.facet,
|
491
396
|
zip5(a.inputs, b.inputs, unionInput),
|
492
|
-
unionChildren(a.children, b.children)
|
397
|
+
unionChildren(a.children, b.children),
|
398
|
+
a.reducers
|
493
399
|
);
|
494
400
|
}
|
495
401
|
function subtractFacetNode(a, b) {
|
496
|
-
assert(a.facet === b.facet)
|
497
|
-
return new FacetNode(
|
402
|
+
return assert(a.facet === b.facet), new FacetNode(
|
498
403
|
a.facet,
|
499
404
|
zip5(a.inputs, b.inputs, subtractInput),
|
500
|
-
subtractChildren(a.children, b.children)
|
405
|
+
subtractChildren(a.children, b.children),
|
406
|
+
a.reducers
|
501
407
|
);
|
502
408
|
}
|
503
409
|
var FacetNode = class {
|
504
|
-
constructor(facet, inputs = [null, null, null, null, null], children = /* @__PURE__ */ new Map()
|
410
|
+
constructor(facet, inputs = [null, null, null, null, null], children = /* @__PURE__ */ new Map(), reducers = [
|
411
|
+
null,
|
412
|
+
null,
|
413
|
+
null,
|
414
|
+
null,
|
415
|
+
null
|
416
|
+
]) {
|
505
417
|
this.facet = facet;
|
506
418
|
this.inputs = inputs;
|
507
419
|
this.children = children;
|
508
|
-
this.reducers =
|
420
|
+
this.reducers = reducers;
|
509
421
|
this.output = null;
|
510
422
|
}
|
511
423
|
calcOutput() {
|
512
424
|
var _a, _b, _c;
|
513
|
-
|
514
|
-
const output = [null, null, null, null, null];
|
425
|
+
let inputs = [null, null, null, null, null], output = [null, null, null, null, null];
|
515
426
|
for (let pri = 0; pri < 5; pri++) {
|
516
|
-
|
517
|
-
|
518
|
-
inputs[pri] = [...input];
|
519
|
-
}
|
427
|
+
let input = this.inputs[pri];
|
428
|
+
input && (inputs[pri] = [...input]);
|
520
429
|
}
|
521
|
-
for (
|
522
|
-
|
523
|
-
for (let pri = 0; pri < 5; pri++)
|
524
|
-
|
525
|
-
const input = inputs[pri] || (inputs[pri] = []);
|
526
|
-
input.push(childOutput[pri]);
|
527
|
-
}
|
528
|
-
}
|
430
|
+
for (let child of this.children.values()) {
|
431
|
+
let childOutput = child.getOutput();
|
432
|
+
for (let pri = 0; pri < 5; pri++)
|
433
|
+
childOutput[pri] && (inputs[pri] || (inputs[pri] = [])).push(childOutput[pri]);
|
529
434
|
}
|
530
435
|
if (this.facet.singleton) {
|
531
|
-
|
532
|
-
const input = inputs.filter(Boolean).flat();
|
436
|
+
let reducer = (_a = this.reducers)[_b = 2 /* default */] || (_a[_b] = this.facet.reducer), input = inputs.filter(Boolean).flat();
|
533
437
|
output[2 /* default */] = reducer(input);
|
534
|
-
} else
|
438
|
+
} else
|
535
439
|
for (let pri = 0; pri < 5; pri++) {
|
536
|
-
|
440
|
+
let input = inputs[pri];
|
537
441
|
if (input) {
|
538
|
-
|
442
|
+
let reducer = (_c = this.reducers)[pri] || (_c[pri] = this.facet.reducer);
|
539
443
|
output[pri] = reducer(input);
|
540
444
|
}
|
541
445
|
}
|
542
|
-
}
|
543
446
|
return output;
|
544
447
|
}
|
545
448
|
getOutput() {
|
546
|
-
|
547
|
-
this.output = this.calcOutput();
|
548
|
-
}
|
549
|
-
return this.output;
|
449
|
+
return this.output || (this.output = this.calcOutput()), this.output;
|
550
450
|
}
|
551
451
|
getSingletonOutput() {
|
552
|
-
assert(this.facet.singleton);
|
553
|
-
return this.getOutput()[2 /* default */];
|
452
|
+
return assert(this.facet.singleton), this.getOutput()[2 /* default */];
|
554
453
|
}
|
555
454
|
getRootOutput() {
|
556
455
|
assert(this.isRoot());
|
557
|
-
|
558
|
-
assert(output);
|
559
|
-
return output;
|
456
|
+
let output = this.getSingletonOutput();
|
457
|
+
return assert(output), output;
|
560
458
|
}
|
561
459
|
isRoot() {
|
562
460
|
return !this.facet.parent;
|
@@ -567,8 +465,7 @@ var FacetNode = class {
|
|
567
465
|
import { Schema as Schema4 } from "@prosekit/pm/model";
|
568
466
|
|
569
467
|
// src/facets/facet.ts
|
570
|
-
var facetCount = 0
|
571
|
-
var Facet = class {
|
468
|
+
var facetCount = 0, Facet = class {
|
572
469
|
/**
|
573
470
|
* @internal
|
574
471
|
*/
|
@@ -579,10 +476,7 @@ var Facet = class {
|
|
579
476
|
* @internal
|
580
477
|
*/
|
581
478
|
this.index = facetCount++;
|
582
|
-
assert((_reduce || _reducer) && !(_reduce && _reducer));
|
583
|
-
this.parent = parent;
|
584
|
-
this.singleton = singleton;
|
585
|
-
this.path = parent ? [...parent.path, this.index] : [];
|
479
|
+
assert((_reduce || _reducer) && !(_reduce && _reducer)), this.parent = parent, this.singleton = singleton, this.path = parent ? [...parent.path, this.index] : [];
|
586
480
|
}
|
587
481
|
get reducer() {
|
588
482
|
var _a, _b;
|
@@ -593,7 +487,7 @@ function defineFacet(options) {
|
|
593
487
|
var _a;
|
594
488
|
return new Facet(
|
595
489
|
options.parent,
|
596
|
-
(_a = options.singleton) != null ? _a :
|
490
|
+
(_a = options.singleton) != null ? _a : !1,
|
597
491
|
options.reducer,
|
598
492
|
options.reduce
|
599
493
|
);
|
@@ -602,22 +496,15 @@ function defineFacet(options) {
|
|
602
496
|
// src/facets/root.ts
|
603
497
|
function rootReducer(inputs) {
|
604
498
|
var _a;
|
605
|
-
let schema;
|
606
|
-
let
|
607
|
-
|
608
|
-
let
|
609
|
-
for (const input of inputs) {
|
610
|
-
schema = input.schema || schema;
|
611
|
-
commands = input.commands || commands;
|
612
|
-
stateFunc = input.state || stateFunc;
|
613
|
-
view = input.view || view;
|
614
|
-
}
|
615
|
-
const state = schema && ((_a = stateFunc == null ? void 0 : stateFunc({ schema })) != null ? _a : { schema });
|
499
|
+
let schema, commands, stateFunc, view;
|
500
|
+
for (let input of inputs)
|
501
|
+
schema = input.schema || schema, commands = input.commands || commands, stateFunc = input.state || stateFunc, view = input.view || view;
|
502
|
+
let state = schema && ((_a = stateFunc == null ? void 0 : stateFunc({ schema })) != null ? _a : { schema });
|
616
503
|
return { schema, state, commands, view };
|
617
504
|
}
|
618
505
|
var rootFacet = new Facet(
|
619
506
|
null,
|
620
|
-
|
507
|
+
!0,
|
621
508
|
rootReducer
|
622
509
|
);
|
623
510
|
|
@@ -625,12 +512,11 @@ var rootFacet = new Facet(
|
|
625
512
|
var schemaFacet = defineFacet({
|
626
513
|
reducer: (specs) => {
|
627
514
|
assert(specs.length <= 1);
|
628
|
-
|
629
|
-
|
630
|
-
return { schema };
|
515
|
+
let spec = specs[0];
|
516
|
+
return { schema: spec ? new Schema4(spec) : null };
|
631
517
|
},
|
632
518
|
parent: rootFacet,
|
633
|
-
singleton:
|
519
|
+
singleton: !0
|
634
520
|
});
|
635
521
|
|
636
522
|
// src/facets/base-extension.ts
|
@@ -644,7 +530,7 @@ var BaseExtension = class {
|
|
644
530
|
*/
|
645
531
|
getTree(priority) {
|
646
532
|
var _a, _b;
|
647
|
-
|
533
|
+
let pri = (_a = priority != null ? priority : this.priority) != null ? _a : 2 /* default */;
|
648
534
|
return (_b = this.trees)[pri] || (_b[pri] = this.createTree(pri));
|
649
535
|
}
|
650
536
|
/**
|
@@ -653,14 +539,13 @@ var BaseExtension = class {
|
|
653
539
|
findFacetOutput(facet) {
|
654
540
|
var _a;
|
655
541
|
let node = this.getTree();
|
656
|
-
for (
|
542
|
+
for (let index of facet.path)
|
657
543
|
node = node == null ? void 0 : node.children.get(index);
|
658
|
-
}
|
659
544
|
return (_a = node == null ? void 0 : node.getOutput()) != null ? _a : null;
|
660
545
|
}
|
661
546
|
get schema() {
|
662
547
|
var _a, _b;
|
663
|
-
|
548
|
+
let output = this.findFacetOutput(schemaFacet);
|
664
549
|
return (_b = (_a = output == null ? void 0 : output.find(Boolean)) == null ? void 0 : _a.schema) != null ? _b : null;
|
665
550
|
}
|
666
551
|
};
|
@@ -680,12 +565,11 @@ var FacetExtensionImpl = class extends BaseExtension {
|
|
680
565
|
*/
|
681
566
|
createTree(priority) {
|
682
567
|
var _a;
|
683
|
-
|
684
|
-
const inputs = [null, null, null, null, null];
|
568
|
+
let pri = (_a = this.priority) != null ? _a : priority, inputs = [null, null, null, null, null];
|
685
569
|
inputs[pri] = [...this.payloads];
|
686
570
|
let node = new FacetNode(this.facet, inputs);
|
687
|
-
|
688
|
-
|
571
|
+
for (; node.facet.parent; ) {
|
572
|
+
let children = /* @__PURE__ */ new Map([[node.facet.index, node]]);
|
689
573
|
node = new FacetNode(node.facet.parent, void 0, children);
|
690
574
|
}
|
691
575
|
return node;
|
@@ -698,37 +582,25 @@ function defineFacetPayload(facet, payloads) {
|
|
698
582
|
// src/facets/state.ts
|
699
583
|
var stateFacet = defineFacet({
|
700
584
|
reduce: () => {
|
701
|
-
let callbacks = []
|
702
|
-
const state = (ctx) => {
|
585
|
+
let callbacks = [], state = (ctx) => {
|
703
586
|
var _a, _b, _c, _d, _e, _f;
|
704
|
-
|
705
|
-
const config = {
|
587
|
+
let configs = callbacks.map((cb) => cb(ctx)), config = {
|
706
588
|
schema: ctx.schema,
|
707
589
|
storedMarks: [],
|
708
590
|
plugins: []
|
709
591
|
};
|
710
|
-
for (
|
711
|
-
config.schema = (_a = config.schema) != null ? _a : c.schema;
|
712
|
-
|
713
|
-
config.selection = (_c = config.selection) != null ? _c : c.selection;
|
714
|
-
config.storedMarks = [...config.storedMarks, ...(_d = c.storedMarks) != null ? _d : []];
|
715
|
-
config.plugins = uniqPush((_e = config.plugins) != null ? _e : [], (_f = c.plugins) != null ? _f : []);
|
716
|
-
}
|
717
|
-
assert(
|
592
|
+
for (let c of configs)
|
593
|
+
config.schema = (_a = config.schema) != null ? _a : c.schema, config.doc = (_b = config.doc) != null ? _b : c.doc, config.selection = (_c = config.selection) != null ? _c : c.selection, config.storedMarks = [...config.storedMarks, ...(_d = c.storedMarks) != null ? _d : []], config.plugins = uniqPush((_e = config.plugins) != null ? _e : [], (_f = c.plugins) != null ? _f : []);
|
594
|
+
return assert(
|
718
595
|
config.doc || config.schema,
|
719
596
|
"Can't create state without a schema nor a document"
|
720
|
-
);
|
721
|
-
if (config.doc) {
|
722
|
-
config.schema = void 0;
|
723
|
-
}
|
724
|
-
return config;
|
597
|
+
), config.doc && (config.schema = void 0), config;
|
725
598
|
};
|
726
|
-
return function
|
727
|
-
callbacks = inputs;
|
728
|
-
return { state };
|
599
|
+
return function(inputs) {
|
600
|
+
return callbacks = inputs, { state };
|
729
601
|
};
|
730
602
|
},
|
731
|
-
singleton:
|
603
|
+
singleton: !0,
|
732
604
|
parent: rootFacet
|
733
605
|
});
|
734
606
|
|
@@ -738,20 +610,16 @@ import { EditorState } from "@prosekit/pm/state";
|
|
738
610
|
|
739
611
|
// src/utils/get-dom-api.ts
|
740
612
|
function findGlobalBrowserDocument() {
|
741
|
-
if (typeof document
|
613
|
+
if (typeof document != "undefined")
|
742
614
|
return document;
|
743
|
-
|
744
|
-
if (typeof globalThis !== "undefined" && globalThis.document) {
|
615
|
+
if (typeof globalThis != "undefined" && globalThis.document)
|
745
616
|
return globalThis.document;
|
746
|
-
}
|
747
617
|
}
|
748
618
|
function findGlobalBrowserWindow() {
|
749
|
-
if (typeof window
|
619
|
+
if (typeof window != "undefined")
|
750
620
|
return window;
|
751
|
-
|
752
|
-
if (typeof globalThis !== "undefined" && globalThis.window) {
|
621
|
+
if (typeof globalThis != "undefined" && globalThis.window)
|
753
622
|
return globalThis.window;
|
754
|
-
}
|
755
623
|
}
|
756
624
|
function findBrowserDocument(options) {
|
757
625
|
var _a, _b, _c;
|
@@ -762,15 +630,13 @@ function findBrowserWindow(options) {
|
|
762
630
|
return (_d = (_b = (_a = options == null ? void 0 : options.document) == null ? void 0 : _a.defaultView) != null ? _b : findGlobalBrowserWindow()) != null ? _d : (_c = findBrowserDocument(options)) == null ? void 0 : _c.defaultView;
|
763
631
|
}
|
764
632
|
function getBrowserDocument(options) {
|
765
|
-
|
766
|
-
if (doc)
|
767
|
-
return doc;
|
633
|
+
let doc = findBrowserDocument(options);
|
634
|
+
if (doc) return doc;
|
768
635
|
throw new DOMDocumentNotFoundError();
|
769
636
|
}
|
770
637
|
function getBrowserWindow(options) {
|
771
|
-
|
772
|
-
if (win)
|
773
|
-
return win;
|
638
|
+
let win = findBrowserWindow(options);
|
639
|
+
if (win) return win;
|
774
640
|
throw new DOMDocumentNotFoundError();
|
775
641
|
}
|
776
642
|
|
@@ -788,29 +654,20 @@ function nodeFromJSON(json, options) {
|
|
788
654
|
return options.schema.nodeFromJSON(json);
|
789
655
|
}
|
790
656
|
function nodeFromElement(element, options) {
|
791
|
-
|
792
|
-
const schema = options.schema;
|
657
|
+
let Parser = options.DOMParser || DOMParser, schema = options.schema;
|
793
658
|
return Parser.fromSchema(schema).parse(element);
|
794
659
|
}
|
795
660
|
function elementFromNode(node, options) {
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
} else {
|
803
|
-
return serializer.serializeFragment(
|
804
|
-
node.content,
|
805
|
-
{ document: document2 },
|
806
|
-
document2.createElement("div")
|
807
|
-
);
|
808
|
-
}
|
661
|
+
let Serializer = (options == null ? void 0 : options.DOMSerializer) || DOMSerializer, document2 = getBrowserDocument(options), schema = node.type.schema, serializer = Serializer.fromSchema(schema);
|
662
|
+
return schema.topNodeType !== node.type ? serializer.serializeNode(node, { document: document2 }) : serializer.serializeFragment(
|
663
|
+
node.content,
|
664
|
+
{ document: document2 },
|
665
|
+
document2.createElement("div")
|
666
|
+
);
|
809
667
|
}
|
810
668
|
function elementFromHTML(html, options) {
|
811
|
-
|
812
|
-
|
813
|
-
return parser.parseFromString(`<body><div>${html}</div></body>`, "text/html").body.firstElementChild;
|
669
|
+
let win = getBrowserWindow(options);
|
670
|
+
return new win.DOMParser().parseFromString(`<body><div>${html}</div></body>`, "text/html").body.firstElementChild;
|
814
671
|
}
|
815
672
|
function htmlFromElement(element) {
|
816
673
|
return element.outerHTML;
|
@@ -840,28 +697,14 @@ function defineDefaultState({
|
|
840
697
|
defaultHTML,
|
841
698
|
defaultSelection
|
842
699
|
}) {
|
843
|
-
if (defaultHTML && defaultDoc)
|
700
|
+
if (defaultHTML && defaultDoc)
|
844
701
|
throw new ProseKitError(
|
845
702
|
"Only one of defaultHTML and defaultDoc can be provided"
|
846
703
|
);
|
847
|
-
}
|
848
704
|
return defineFacetPayload(stateFacet, [
|
849
705
|
({ schema }) => {
|
850
|
-
|
851
|
-
|
852
|
-
if (typeof defaultHTML === "string") {
|
853
|
-
defaultDoc = jsonFromHTML(defaultHTML, { schema });
|
854
|
-
} else {
|
855
|
-
defaultDoc = jsonFromElement(defaultHTML, { schema });
|
856
|
-
}
|
857
|
-
}
|
858
|
-
if (defaultDoc) {
|
859
|
-
config.doc = schema.nodeFromJSON(defaultDoc);
|
860
|
-
if (defaultSelection) {
|
861
|
-
config.selection = Selection.fromJSON(config.doc, defaultSelection);
|
862
|
-
}
|
863
|
-
}
|
864
|
-
return config;
|
706
|
+
let config = {};
|
707
|
+
return defaultHTML && (typeof defaultHTML == "string" ? defaultDoc = jsonFromHTML(defaultHTML, { schema }) : defaultDoc = jsonFromElement(defaultHTML, { schema })), defaultDoc && (config.doc = schema.nodeFromJSON(defaultDoc), defaultSelection && (config.selection = Selection.fromJSON(config.doc, defaultSelection))), config;
|
865
708
|
}
|
866
709
|
]);
|
867
710
|
}
|
@@ -869,24 +712,19 @@ function defineDefaultState({
|
|
869
712
|
// src/utils/deep-equals.ts
|
870
713
|
import OrderedMap from "orderedmap";
|
871
714
|
function deepEquals(a, b) {
|
872
|
-
if (a === b)
|
873
|
-
return
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
}
|
878
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
715
|
+
if (a === b)
|
716
|
+
return !0;
|
717
|
+
if (!a || !b)
|
718
|
+
return !1;
|
719
|
+
if (Array.isArray(a) && Array.isArray(b))
|
879
720
|
return a.length === b.length && a.every((x, i) => deepEquals(x, b[i]));
|
880
|
-
|
881
|
-
if (a instanceof OrderedMap && b instanceof OrderedMap) {
|
721
|
+
if (a instanceof OrderedMap && b instanceof OrderedMap)
|
882
722
|
return a.size === b.size && deepEquals(a.toObject(), b.toObject());
|
883
|
-
|
884
|
-
|
885
|
-
const aKeys = Object.keys(a);
|
886
|
-
const bKeys = Object.keys(b);
|
723
|
+
if (typeof a == "object" && typeof b == "object") {
|
724
|
+
let aKeys = Object.keys(a), bKeys = Object.keys(b);
|
887
725
|
return aKeys.length === bKeys.length && aKeys.every((key) => deepEquals(a[key], b[key]));
|
888
726
|
}
|
889
|
-
return
|
727
|
+
return !1;
|
890
728
|
}
|
891
729
|
|
892
730
|
// src/editor/builder.ts
|
@@ -894,26 +732,17 @@ import "@prosekit/pm/model";
|
|
894
732
|
|
895
733
|
// src/utils/is-mark-absent.ts
|
896
734
|
function isMarkAbsent(node, from, to, markType, attrs) {
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
if (missing)
|
901
|
-
return false;
|
735
|
+
let mark = attrs ? markType.create(attrs) : markType, missing = !1;
|
736
|
+
return node.nodesBetween(from, to, (node2, pos, parent) => {
|
737
|
+
if (missing) return !1;
|
902
738
|
missing = !mark.isInSet(node2.marks) && !!parent && parent.type.allowsMarkType(markType);
|
903
|
-
});
|
904
|
-
return missing;
|
739
|
+
}), missing;
|
905
740
|
}
|
906
741
|
|
907
742
|
// src/utils/is-mark-active.ts
|
908
743
|
function isMarkActive(state, type, attrs) {
|
909
|
-
|
910
|
-
|
911
|
-
if (empty) {
|
912
|
-
const mark = attrs ? markType.create(attrs) : markType;
|
913
|
-
return !!mark.isInSet(state.storedMarks || $from.marks());
|
914
|
-
} else {
|
915
|
-
return !isMarkAbsent(state.doc, from, to, markType, attrs);
|
916
|
-
}
|
744
|
+
let { from, $from, to, empty } = state.selection, markType = getMarkType(state.schema, type);
|
745
|
+
return empty ? !!(attrs ? markType.create(attrs) : markType).isInSet(state.storedMarks || $from.marks()) : !isMarkAbsent(state.doc, from, to, markType, attrs);
|
917
746
|
}
|
918
747
|
|
919
748
|
// src/utils/type-assertion.ts
|
@@ -941,66 +770,48 @@ function isAllSelection(sel) {
|
|
941
770
|
|
942
771
|
// src/editor/builder.ts
|
943
772
|
function createNodeBuilder(getState, type) {
|
944
|
-
|
945
|
-
builder.isActive = (attrs) => {
|
946
|
-
|
947
|
-
return state ? isNodeActive(state, type, attrs) :
|
948
|
-
};
|
949
|
-
return builder;
|
773
|
+
let builder = (...args) => buildNode(type, args);
|
774
|
+
return builder.isActive = (attrs) => {
|
775
|
+
let state = getState();
|
776
|
+
return state ? isNodeActive(state, type, attrs) : !1;
|
777
|
+
}, builder;
|
950
778
|
}
|
951
779
|
function createMarkBuilder(getState, type) {
|
952
|
-
|
953
|
-
builder.isActive = (attrs) => {
|
954
|
-
|
955
|
-
return state ? isMarkActive(state, type, attrs) :
|
956
|
-
};
|
957
|
-
return builder;
|
780
|
+
let builder = (...args) => buildMark(type, args);
|
781
|
+
return builder.isActive = (attrs) => {
|
782
|
+
let state = getState();
|
783
|
+
return state ? isMarkActive(state, type, attrs) : !1;
|
784
|
+
}, builder;
|
958
785
|
}
|
959
786
|
function buildMark(type, args) {
|
960
|
-
|
787
|
+
let [attrs, children] = normalizeArgs(args);
|
961
788
|
return flattenChildren(type.schema, children, type.create(attrs));
|
962
789
|
}
|
963
790
|
function buildNode(type, args) {
|
964
|
-
|
965
|
-
|
966
|
-
if (!node) {
|
791
|
+
let [attrs, children] = normalizeArgs(args), node = type.createAndFill(attrs, flattenChildren(type.schema, children));
|
792
|
+
if (!node)
|
967
793
|
throw new ProseKitError(`Couldn't create node ${type.name}`);
|
968
|
-
}
|
969
794
|
return node;
|
970
795
|
}
|
971
796
|
function flattenChildren(schema, children, mark) {
|
972
|
-
|
973
|
-
for (
|
974
|
-
if (typeof child
|
975
|
-
|
976
|
-
|
977
|
-
}
|
978
|
-
} else if (Array.isArray(child)) {
|
797
|
+
let nodes = [];
|
798
|
+
for (let child of children)
|
799
|
+
if (typeof child == "string")
|
800
|
+
child && nodes.push(schema.text(child, mark ? [mark] : null));
|
801
|
+
else if (Array.isArray(child))
|
979
802
|
nodes.push(...flattenChildren(schema, child, mark));
|
980
|
-
|
803
|
+
else if (isProseMirrorNode(child))
|
981
804
|
nodes.push(mark ? child.mark(mark.addToSet(child.marks)) : child);
|
982
|
-
|
805
|
+
else
|
983
806
|
throw new ProseKitError(`Invalid node child: ${typeof child}`);
|
984
|
-
}
|
985
|
-
}
|
986
807
|
return nodes;
|
987
808
|
}
|
988
809
|
function normalizeArgs(args) {
|
989
|
-
|
990
|
-
|
991
|
-
children.unshift(attrs);
|
992
|
-
return [null, children];
|
993
|
-
} else if (typeof attrs === "object") {
|
994
|
-
return [attrs, children];
|
995
|
-
} else {
|
996
|
-
return [null, children];
|
997
|
-
}
|
810
|
+
let [attrs, ...children] = args;
|
811
|
+
return isNodeChild(attrs) ? (children.unshift(attrs), [null, children]) : typeof attrs == "object" ? [attrs, children] : [null, children];
|
998
812
|
}
|
999
813
|
function isNodeChild(value) {
|
1000
|
-
|
1001
|
-
return false;
|
1002
|
-
}
|
1003
|
-
return typeof value === "string" || Array.isArray(value) || isProseMirrorNode(value);
|
814
|
+
return value ? typeof value == "string" || Array.isArray(value) || isProseMirrorNode(value) : !1;
|
1004
815
|
}
|
1005
816
|
|
1006
817
|
// src/facets/union-extension.ts
|
@@ -1017,69 +828,59 @@ var UnionExtensionImpl = class extends BaseExtension {
|
|
1017
828
|
*/
|
1018
829
|
createTree(priority) {
|
1019
830
|
var _a;
|
1020
|
-
|
1021
|
-
const extensions = [...this.extension];
|
831
|
+
let pri = (_a = this.priority) != null ? _a : priority, extensions = [...this.extension];
|
1022
832
|
extensions.sort((a, b) => {
|
1023
833
|
var _a2, _b;
|
1024
834
|
return ((_a2 = a.priority) != null ? _a2 : pri) - ((_b = b.priority) != null ? _b : pri);
|
1025
835
|
});
|
1026
|
-
|
1027
|
-
|
836
|
+
let children = extensions.map((ext) => ext.getTree(pri));
|
837
|
+
assert(children.length > 0);
|
838
|
+
let node = children[0];
|
839
|
+
for (let i = 1; i < children.length; i++)
|
840
|
+
node = unionFacetNode(node, children[i]);
|
841
|
+
return node;
|
1028
842
|
}
|
1029
843
|
};
|
1030
844
|
|
1031
845
|
// src/editor/union.ts
|
1032
846
|
function union(extension) {
|
1033
|
-
|
1034
|
-
return new UnionExtensionImpl(
|
847
|
+
let array = Array.isArray(extension) ? extension : [extension];
|
848
|
+
return assert(array.length > 0, "At least one extension is required"), new UnionExtensionImpl(
|
1035
849
|
array
|
1036
850
|
);
|
1037
851
|
}
|
1038
852
|
|
1039
853
|
// src/editor/editor.ts
|
1040
854
|
function createEditor(options) {
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
})
|
1051
|
-
]);
|
1052
|
-
}
|
1053
|
-
return Editor.create(new EditorInstance(extension));
|
855
|
+
let { defaultDoc, defaultHTML, defaultSelection } = options, extension = options.extension;
|
856
|
+
return (defaultDoc || defaultHTML) && (extension = union([
|
857
|
+
extension,
|
858
|
+
defineDefaultState({
|
859
|
+
defaultDoc,
|
860
|
+
defaultHTML,
|
861
|
+
defaultSelection
|
862
|
+
})
|
863
|
+
])), Editor.create(new EditorInstance(extension));
|
1054
864
|
}
|
1055
865
|
var EditorInstance = class {
|
1056
866
|
constructor(extension) {
|
1057
867
|
this.view = null;
|
1058
868
|
this.commandAppliers = {};
|
1059
|
-
this.mount = this.mount.bind(this);
|
1060
|
-
|
1061
|
-
this.tree = extension.getTree();
|
1062
|
-
const payload = this.tree.getRootOutput();
|
1063
|
-
const schema = payload.schema;
|
1064
|
-
const stateConfig = payload.state;
|
869
|
+
this.mount = this.mount.bind(this), this.unmount = this.unmount.bind(this), this.tree = extension.getTree();
|
870
|
+
let payload = this.tree.getRootOutput(), schema = payload.schema, stateConfig = payload.state;
|
1065
871
|
assert(schema && stateConfig, "Schema must be defined");
|
1066
|
-
|
1067
|
-
this.cachedState = state
|
1068
|
-
|
1069
|
-
for (const [name, commandCreator] of Object.entries(payload.commands)) {
|
872
|
+
let state = EditorState2.create(stateConfig);
|
873
|
+
if (this.cachedState = state, payload.commands)
|
874
|
+
for (let [name, commandCreator] of Object.entries(payload.commands))
|
1070
875
|
this.defineCommand(name, commandCreator);
|
1071
|
-
|
1072
|
-
|
1073
|
-
this.directEditorProps = { state, ...payload.view };
|
1074
|
-
this.schema = this.directEditorProps.state.schema;
|
1075
|
-
const getState = () => this.getState();
|
876
|
+
this.directEditorProps = { state, ...payload.view }, this.schema = this.directEditorProps.state.schema;
|
877
|
+
let getState = () => this.getState();
|
1076
878
|
this.nodeBuilders = Object.fromEntries(
|
1077
879
|
Object.values(this.schema.nodes).map((type) => [
|
1078
880
|
type.name,
|
1079
881
|
createNodeBuilder(getState, type)
|
1080
882
|
])
|
1081
|
-
)
|
1082
|
-
this.markBuilders = Object.fromEntries(
|
883
|
+
), this.markBuilders = Object.fromEntries(
|
1083
884
|
Object.values(this.schema.marks).map((type) => [
|
1084
885
|
type.name,
|
1085
886
|
createMarkBuilder(getState, type)
|
@@ -1087,121 +888,85 @@ var EditorInstance = class {
|
|
1087
888
|
);
|
1088
889
|
}
|
1089
890
|
getState() {
|
1090
|
-
|
1091
|
-
this.cachedState = this.view.state;
|
1092
|
-
}
|
1093
|
-
return this.cachedState;
|
891
|
+
return this.view && (this.cachedState = this.view.state), this.cachedState;
|
1094
892
|
}
|
1095
893
|
updateExtension(extension, add) {
|
1096
894
|
var _a, _b, _c, _d;
|
1097
|
-
|
1098
|
-
if (!view || view.isDestroyed)
|
895
|
+
let view = this.view;
|
896
|
+
if (!view || view.isDestroyed)
|
1099
897
|
return;
|
1100
|
-
|
1101
|
-
|
1102
|
-
const payload = tree.getRootOutput();
|
1103
|
-
if (payload == null ? void 0 : payload.schema) {
|
898
|
+
let tree = extension.getTree(), payload = tree.getRootOutput();
|
899
|
+
if (payload != null && payload.schema)
|
1104
900
|
throw new ProseKitError("Schema cannot be changed");
|
1105
|
-
|
1106
|
-
if (payload == null ? void 0 : payload.view) {
|
901
|
+
if (payload != null && payload.view)
|
1107
902
|
throw new ProseKitError("View cannot be changed");
|
1108
|
-
|
1109
|
-
const oldPayload = this.tree.getRootOutput();
|
1110
|
-
const oldPlugins = [...(_b = (_a = view.state) == null ? void 0 : _a.plugins) != null ? _b : []];
|
903
|
+
let oldPayload = this.tree.getRootOutput(), oldPlugins = [...(_b = (_a = view.state) == null ? void 0 : _a.plugins) != null ? _b : []];
|
1111
904
|
this.tree = add ? unionFacetNode(this.tree, tree) : subtractFacetNode(this.tree, tree);
|
1112
|
-
|
1113
|
-
const newPlugins = [...(_d = (_c = newPayload == null ? void 0 : newPayload.state) == null ? void 0 : _c.plugins) != null ? _d : []];
|
905
|
+
let newPayload = this.tree.getRootOutput(), newPlugins = [...(_d = (_c = newPayload == null ? void 0 : newPayload.state) == null ? void 0 : _c.plugins) != null ? _d : []];
|
1114
906
|
if (!deepEquals(oldPlugins, newPlugins)) {
|
1115
|
-
|
907
|
+
let state = view.state.reconfigure({ plugins: newPlugins });
|
1116
908
|
view.updateState(state);
|
1117
909
|
}
|
1118
|
-
if (
|
1119
|
-
|
1120
|
-
|
1121
|
-
for (const name of names) {
|
910
|
+
if (newPayload != null && newPayload.commands && !deepEquals(oldPayload == null ? void 0 : oldPayload.commands, newPayload == null ? void 0 : newPayload.commands)) {
|
911
|
+
let commands = newPayload.commands, names = Object.keys(commands);
|
912
|
+
for (let name of names)
|
1122
913
|
this.defineCommand(name, commands[name]);
|
1123
|
-
}
|
1124
914
|
}
|
1125
915
|
}
|
1126
916
|
mount(place) {
|
1127
|
-
if (this.view)
|
917
|
+
if (this.view)
|
1128
918
|
throw new ProseKitError("Editor is already mounted");
|
1129
|
-
|
1130
|
-
if (!place) {
|
919
|
+
if (!place)
|
1131
920
|
throw new ProseKitError("Can't mount editor without a place");
|
1132
|
-
}
|
1133
921
|
this.view = new EditorView({ mount: place }, this.directEditorProps);
|
1134
922
|
}
|
1135
923
|
unmount() {
|
1136
|
-
if (!this.view)
|
924
|
+
if (!this.view)
|
1137
925
|
throw new ProseKitError("Editor is not mounted yet");
|
1138
|
-
|
1139
|
-
this.view.destroy();
|
1140
|
-
this.view = null;
|
926
|
+
this.view.destroy(), this.view = null;
|
1141
927
|
}
|
1142
928
|
get mounted() {
|
1143
929
|
return !!this.view && !this.view.isDestroyed;
|
1144
930
|
}
|
1145
931
|
get assertView() {
|
1146
|
-
if (!this.view)
|
932
|
+
if (!this.view)
|
1147
933
|
throw new ProseKitError("Editor is not mounted");
|
1148
|
-
}
|
1149
934
|
return this.view;
|
1150
935
|
}
|
1151
936
|
definePlugins(plugins) {
|
1152
|
-
|
1153
|
-
const state = view.state;
|
1154
|
-
const newPlugins = [...plugins, ...state.plugins];
|
1155
|
-
const newState = state.reconfigure({ plugins: newPlugins });
|
937
|
+
let view = this.assertView, state = view.state, newPlugins = [...plugins, ...state.plugins], newState = state.reconfigure({ plugins: newPlugins });
|
1156
938
|
view.setProps({ state: newState });
|
1157
939
|
}
|
1158
940
|
removePlugins(plugins) {
|
1159
|
-
|
1160
|
-
if (!view)
|
1161
|
-
|
1162
|
-
const state = view.state;
|
1163
|
-
const newPlugins = state.plugins.filter((p) => !plugins.includes(p));
|
1164
|
-
const newState = state.reconfigure({ plugins: newPlugins });
|
941
|
+
let view = this.view;
|
942
|
+
if (!view) return;
|
943
|
+
let state = view.state, newPlugins = state.plugins.filter((p) => !plugins.includes(p)), newState = state.reconfigure({ plugins: newPlugins });
|
1165
944
|
view.setProps({ state: newState });
|
1166
945
|
}
|
1167
946
|
defineCommand(name, commandCreator) {
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
return false;
|
1172
|
-
}
|
1173
|
-
const command = commandCreator(...args);
|
1174
|
-
return command(view.state, view.dispatch.bind(view), view);
|
947
|
+
let applier = (...args) => {
|
948
|
+
let view = this.view;
|
949
|
+
return view ? commandCreator(...args)(view.state, view.dispatch.bind(view), view) : !1;
|
1175
950
|
};
|
1176
951
|
applier.canApply = (...args) => {
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
}
|
1181
|
-
const command = commandCreator(...args);
|
1182
|
-
return command(view.state, void 0, view);
|
1183
|
-
};
|
1184
|
-
this.commandAppliers[name] = applier;
|
952
|
+
let view = this.view;
|
953
|
+
return view ? commandCreator(...args)(view.state, void 0, view) : !1;
|
954
|
+
}, this.commandAppliers[name] = applier;
|
1185
955
|
}
|
1186
956
|
removeCommand(name) {
|
1187
957
|
delete this.commandAppliers[name];
|
1188
958
|
}
|
1189
|
-
}
|
1190
|
-
var Editor = class _Editor {
|
959
|
+
}, Editor = class _Editor {
|
1191
960
|
constructor(instance) {
|
1192
961
|
this.afterMounted = [];
|
1193
|
-
this.instance = instance;
|
1194
|
-
this.mount = this.mount.bind(this);
|
1195
|
-
this.unmount = this.unmount.bind(this);
|
1196
|
-
this.use = this.use.bind(this);
|
962
|
+
this.instance = instance, this.mount = this.mount.bind(this), this.unmount = this.unmount.bind(this), this.use = this.use.bind(this);
|
1197
963
|
}
|
1198
964
|
/**
|
1199
965
|
* @internal
|
1200
966
|
*/
|
1201
967
|
static create(instance) {
|
1202
|
-
if (!(instance instanceof EditorInstance))
|
968
|
+
if (!(instance instanceof EditorInstance))
|
1203
969
|
throw new TypeError("Invalid EditorInstance");
|
1204
|
-
}
|
1205
970
|
return new _Editor(instance);
|
1206
971
|
}
|
1207
972
|
/**
|
@@ -1230,54 +995,47 @@ var Editor = class _Editor {
|
|
1230
995
|
*/
|
1231
996
|
get focused() {
|
1232
997
|
var _a, _b;
|
1233
|
-
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b :
|
998
|
+
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b : !1;
|
1234
999
|
}
|
1235
1000
|
/**
|
1236
1001
|
* Mount the editor to the given HTML element.
|
1237
1002
|
* Pass `null` or `undefined` to unmount the editor.
|
1238
1003
|
*/
|
1239
1004
|
mount(place) {
|
1240
|
-
if (!place)
|
1005
|
+
if (!place)
|
1241
1006
|
return this.unmount();
|
1242
|
-
|
1243
|
-
this.instance.mount(place);
|
1244
|
-
this.afterMounted.forEach((callback) => callback());
|
1007
|
+
this.instance.mount(place), this.afterMounted.forEach((callback) => callback());
|
1245
1008
|
}
|
1246
1009
|
/**
|
1247
1010
|
* Unmount the editor. This is equivalent to `mount(null)`.
|
1248
1011
|
*/
|
1249
1012
|
unmount() {
|
1250
|
-
|
1251
|
-
this.instance.unmount();
|
1252
|
-
}
|
1013
|
+
this.mounted && this.instance.unmount();
|
1253
1014
|
}
|
1254
1015
|
/**
|
1255
1016
|
* Focus the editor.
|
1256
1017
|
*/
|
1257
1018
|
focus() {
|
1258
1019
|
var _a;
|
1259
|
-
(_a = this.instance.view) == null
|
1020
|
+
(_a = this.instance.view) == null || _a.focus();
|
1260
1021
|
}
|
1261
1022
|
/**
|
1262
1023
|
* Blur the editor.
|
1263
1024
|
*/
|
1264
1025
|
blur() {
|
1265
1026
|
var _a;
|
1266
|
-
(_a = this.instance.view) == null
|
1027
|
+
(_a = this.instance.view) == null || _a.dom.blur();
|
1267
1028
|
}
|
1268
1029
|
use(extension) {
|
1269
1030
|
if (!this.mounted) {
|
1270
|
-
let lazyRemove = null
|
1271
|
-
const lazyCreate = () => {
|
1031
|
+
let lazyRemove = null, lazyCreate = () => {
|
1272
1032
|
lazyRemove = this.use(extension);
|
1273
1033
|
};
|
1274
|
-
this.afterMounted.push(lazyCreate)
|
1275
|
-
|
1276
|
-
lazyRemove == null ? void 0 : lazyRemove();
|
1034
|
+
return this.afterMounted.push(lazyCreate), () => {
|
1035
|
+
lazyRemove == null || lazyRemove();
|
1277
1036
|
};
|
1278
1037
|
}
|
1279
|
-
this.instance.updateExtension(extension,
|
1280
|
-
return () => this.instance.updateExtension(extension, false);
|
1038
|
+
return this.instance.updateExtension(extension, !0), () => this.instance.updateExtension(extension, !1);
|
1281
1039
|
}
|
1282
1040
|
get state() {
|
1283
1041
|
return this.instance.getState();
|
@@ -1292,9 +1050,8 @@ var Editor = class _Editor {
|
|
1292
1050
|
|
1293
1051
|
// src/editor/with-priority.ts
|
1294
1052
|
function withPriority(extension, priority) {
|
1295
|
-
|
1296
|
-
result.priority = priority;
|
1297
|
-
return result;
|
1053
|
+
let result = union(extension);
|
1054
|
+
return result.priority = priority, result;
|
1298
1055
|
}
|
1299
1056
|
|
1300
1057
|
// src/commands/insert-text.ts
|
@@ -1303,21 +1060,13 @@ function insertText({
|
|
1303
1060
|
from,
|
1304
1061
|
to
|
1305
1062
|
}) {
|
1306
|
-
return (state, dispatch) =>
|
1307
|
-
if (text) {
|
1308
|
-
dispatch == null ? void 0 : dispatch(state.tr.insertText(text, from, to));
|
1309
|
-
}
|
1310
|
-
return true;
|
1311
|
-
};
|
1063
|
+
return (state, dispatch) => (text && (dispatch == null || dispatch(state.tr.insertText(text, from, to))), !0);
|
1312
1064
|
}
|
1313
1065
|
|
1314
1066
|
// src/commands/select-all.ts
|
1315
1067
|
import { AllSelection as AllSelection2 } from "@prosekit/pm/state";
|
1316
1068
|
function selectAll() {
|
1317
|
-
return (state, dispatch) =>
|
1318
|
-
dispatch == null ? void 0 : dispatch(state.tr.setSelection(new AllSelection2(state.doc)));
|
1319
|
-
return true;
|
1320
|
-
};
|
1069
|
+
return (state, dispatch) => (dispatch == null || dispatch(state.tr.setSelection(new AllSelection2(state.doc))), !0);
|
1321
1070
|
}
|
1322
1071
|
|
1323
1072
|
// src/commands/wrap.ts
|
@@ -1329,26 +1078,18 @@ function wrap({
|
|
1329
1078
|
attrs
|
1330
1079
|
}) {
|
1331
1080
|
return (state, dispatch) => {
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
const wrapping = findWrapping(range, nodeType, attrs);
|
1337
|
-
if (!wrapping)
|
1338
|
-
return false;
|
1339
|
-
dispatch == null ? void 0 : dispatch(state.tr.wrap(range, wrapping));
|
1340
|
-
return true;
|
1081
|
+
let { $from, $to } = state.selection, range = $from.blockRange($to);
|
1082
|
+
if (!range) return !1;
|
1083
|
+
let wrapping = findWrapping(range, nodeType, attrs);
|
1084
|
+
return wrapping ? (dispatch == null || dispatch(state.tr.wrap(range, wrapping)), !0) : !1;
|
1341
1085
|
};
|
1342
1086
|
}
|
1343
1087
|
|
1344
1088
|
// src/facets/command.ts
|
1345
1089
|
var commandFacet = defineFacet({
|
1346
|
-
reducer: (inputs) => {
|
1347
|
-
const commands = Object.assign({}, ...inputs);
|
1348
|
-
return { commands };
|
1349
|
-
},
|
1090
|
+
reducer: (inputs) => ({ commands: Object.assign({}, ...inputs) }),
|
1350
1091
|
parent: rootFacet,
|
1351
|
-
singleton:
|
1092
|
+
singleton: !0
|
1352
1093
|
});
|
1353
1094
|
|
1354
1095
|
// src/extensions/command.ts
|
@@ -1359,6 +1100,7 @@ function defineBaseCommands() {
|
|
1359
1100
|
return defineCommands({
|
1360
1101
|
insertText,
|
1361
1102
|
insertNode,
|
1103
|
+
removeNode,
|
1362
1104
|
wrap,
|
1363
1105
|
setBlockType,
|
1364
1106
|
setNodeAttrs,
|
@@ -1377,22 +1119,17 @@ import OrderedMap2 from "orderedmap";
|
|
1377
1119
|
var schemaSpecFacet = defineFacet({
|
1378
1120
|
reducer: (specs) => {
|
1379
1121
|
var _a;
|
1380
|
-
let nodes = OrderedMap2.from({});
|
1381
|
-
let
|
1382
|
-
|
1383
|
-
for (const spec of specs) {
|
1384
|
-
nodes = nodes.append(spec.nodes);
|
1385
|
-
marks = marks.append((_a = spec.marks) != null ? _a : {});
|
1386
|
-
topNode = topNode != null ? topNode : spec.topNode;
|
1387
|
-
}
|
1122
|
+
let nodes = OrderedMap2.from({}), marks = OrderedMap2.from({}), topNode;
|
1123
|
+
for (let spec of specs)
|
1124
|
+
nodes = nodes.append(spec.nodes), marks = marks.append((_a = spec.marks) != null ? _a : {}), topNode = topNode != null ? topNode : spec.topNode;
|
1388
1125
|
return { nodes, marks, topNode };
|
1389
1126
|
},
|
1390
1127
|
parent: schemaFacet,
|
1391
|
-
singleton:
|
1128
|
+
singleton: !0
|
1392
1129
|
});
|
1393
1130
|
|
1394
1131
|
// src/utils/is-element.ts
|
1395
|
-
var hasElement = typeof Element
|
1132
|
+
var hasElement = typeof Element != "undefined";
|
1396
1133
|
function isElement(value) {
|
1397
1134
|
return hasElement && value instanceof Element;
|
1398
1135
|
}
|
@@ -1404,27 +1141,17 @@ function isNotNull(value) {
|
|
1404
1141
|
|
1405
1142
|
// src/extensions/node-spec.ts
|
1406
1143
|
function defineNodeSpec(options) {
|
1407
|
-
|
1408
|
-
return defineFacetPayload(nodeSpecFacet, [payload]);
|
1144
|
+
return defineFacetPayload(nodeSpecFacet, [[options, void 0]]);
|
1409
1145
|
}
|
1410
1146
|
function defineNodeAttr(options) {
|
1411
|
-
|
1412
|
-
return defineFacetPayload(nodeSpecFacet, [payload]);
|
1147
|
+
return defineFacetPayload(nodeSpecFacet, [[void 0, options]]);
|
1413
1148
|
}
|
1414
1149
|
var nodeSpecFacet = defineFacet({
|
1415
1150
|
reducer: (payloads) => {
|
1416
|
-
let nodes = OrderedMap3.from({});
|
1417
|
-
let
|
1418
|
-
|
1419
|
-
|
1420
|
-
for (const { name, topNode, ...spec } of specPayloads) {
|
1421
|
-
assert(!nodes.get(name), `Node type ${name} can only be defined once`);
|
1422
|
-
if (topNode) {
|
1423
|
-
topNodeName = name;
|
1424
|
-
}
|
1425
|
-
nodes = nodes.addToStart(name, spec);
|
1426
|
-
}
|
1427
|
-
for (const {
|
1151
|
+
let nodes = OrderedMap3.from({}), topNodeName, specPayloads = payloads.map((input) => input[0]).filter(isNotNull), attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
|
1152
|
+
for (let { name, topNode, ...spec } of specPayloads)
|
1153
|
+
assert(!nodes.get(name), `Node type ${name} can only be defined once`), topNode && (topNodeName = name), nodes = nodes.addToStart(name, spec);
|
1154
|
+
for (let {
|
1428
1155
|
type,
|
1429
1156
|
attr,
|
1430
1157
|
default: defaultValue,
|
@@ -1432,87 +1159,57 @@ var nodeSpecFacet = defineFacet({
|
|
1432
1159
|
toDOM,
|
1433
1160
|
parseDOM
|
1434
1161
|
} of attrPayloads) {
|
1435
|
-
|
1436
|
-
assert(spec, `Node type ${type} must be defined`)
|
1437
|
-
if (!spec.attrs) {
|
1438
|
-
spec.attrs = {};
|
1439
|
-
}
|
1440
|
-
spec.attrs[attr] = {
|
1162
|
+
let spec = nodes.get(type);
|
1163
|
+
if (assert(spec, `Node type ${type} must be defined`), spec.attrs || (spec.attrs = {}), spec.attrs[attr] = {
|
1441
1164
|
default: defaultValue,
|
1442
1165
|
splittable
|
1443
|
-
}
|
1444
|
-
|
1445
|
-
const existingToDom = spec.toDOM;
|
1166
|
+
}, toDOM && spec.toDOM) {
|
1167
|
+
let existingToDom = spec.toDOM;
|
1446
1168
|
spec.toDOM = (node) => {
|
1447
|
-
|
1448
|
-
if (!dom)
|
1169
|
+
let dom = existingToDom(node);
|
1170
|
+
if (!dom)
|
1449
1171
|
return dom;
|
1450
|
-
|
1451
|
-
|
1452
|
-
if (!attrDOM) {
|
1172
|
+
let attrDOM = toDOM(node.attrs[attr]);
|
1173
|
+
if (!attrDOM)
|
1453
1174
|
return dom;
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
dom[1],
|
1465
|
-
key,
|
1466
|
-
value
|
1467
|
-
),
|
1468
|
-
...dom.slice(2)
|
1469
|
-
];
|
1470
|
-
} else {
|
1471
|
-
return [dom[0], { [key]: value }, ...dom.slice(1)];
|
1472
|
-
}
|
1473
|
-
} else if (isElement(dom)) {
|
1474
|
-
setElementAttribute(dom, key, value);
|
1475
|
-
} else if (typeof dom === "object" && "dom" in dom && isElement(dom.dom)) {
|
1476
|
-
setElementAttribute(dom.dom, key, value);
|
1477
|
-
}
|
1478
|
-
return dom;
|
1175
|
+
let [key, value] = attrDOM;
|
1176
|
+
return key ? Array.isArray(dom) ? typeof dom[1] == "object" ? [
|
1177
|
+
dom[0],
|
1178
|
+
setObjectAttribute(
|
1179
|
+
dom[1],
|
1180
|
+
key,
|
1181
|
+
value
|
1182
|
+
),
|
1183
|
+
...dom.slice(2)
|
1184
|
+
] : [dom[0], { [key]: value }, ...dom.slice(1)] : (isElement(dom) ? setElementAttribute(dom, key, value) : typeof dom == "object" && "dom" in dom && isElement(dom.dom) && setElementAttribute(dom.dom, key, value), dom) : dom;
|
1479
1185
|
};
|
1480
1186
|
}
|
1481
|
-
if (parseDOM && spec.parseDOM)
|
1482
|
-
for (
|
1483
|
-
|
1484
|
-
const existingAttrs = rule.attrs;
|
1187
|
+
if (parseDOM && spec.parseDOM)
|
1188
|
+
for (let rule of spec.parseDOM) {
|
1189
|
+
let existingGetAttrs = rule.getAttrs, existingAttrs = rule.attrs;
|
1485
1190
|
rule.getAttrs = (dom) => {
|
1486
1191
|
var _a;
|
1487
|
-
|
1488
|
-
if (attrs ===
|
1192
|
+
let attrs = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs;
|
1193
|
+
if (attrs === !1 || !dom || !isElement(dom))
|
1489
1194
|
return attrs != null ? attrs : null;
|
1490
|
-
|
1491
|
-
const value = parseDOM(dom);
|
1195
|
+
let value = parseDOM(dom);
|
1492
1196
|
return {
|
1493
1197
|
...attrs,
|
1494
1198
|
[attr]: value
|
1495
1199
|
};
|
1496
1200
|
};
|
1497
1201
|
}
|
1498
|
-
}
|
1499
1202
|
}
|
1500
1203
|
return { nodes, topNode: topNodeName };
|
1501
1204
|
},
|
1502
1205
|
parent: schemaSpecFacet,
|
1503
|
-
singleton:
|
1206
|
+
singleton: !0
|
1504
1207
|
});
|
1505
1208
|
function setObjectAttribute(obj, key, value) {
|
1506
|
-
|
1507
|
-
value = `${value}${obj.style || ""}`;
|
1508
|
-
}
|
1509
|
-
return { ...obj, [key]: value };
|
1209
|
+
return key === "style" && (value = `${value}${obj.style || ""}`), { ...obj, [key]: value };
|
1510
1210
|
}
|
1511
1211
|
function setElementAttribute(element, key, value) {
|
1512
|
-
|
1513
|
-
value = `${value}${element.getAttribute("style") || ""}`;
|
1514
|
-
}
|
1515
|
-
element.setAttribute(key, value);
|
1212
|
+
key === "style" && (value = `${value}${element.getAttribute("style") || ""}`), element.setAttribute(key, value);
|
1516
1213
|
}
|
1517
1214
|
|
1518
1215
|
// src/extensions/doc.ts
|
@@ -1520,7 +1217,7 @@ function defineDoc() {
|
|
1520
1217
|
return defineNodeSpec({
|
1521
1218
|
name: "doc",
|
1522
1219
|
content: "block+",
|
1523
|
-
topNode:
|
1220
|
+
topNode: !0
|
1524
1221
|
});
|
1525
1222
|
}
|
1526
1223
|
|
@@ -1531,35 +1228,27 @@ import { PluginKey, ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm
|
|
1531
1228
|
import "@prosekit/pm/model";
|
1532
1229
|
import { Plugin as Plugin2 } from "@prosekit/pm/state";
|
1533
1230
|
function definePlugin(plugin) {
|
1534
|
-
if (plugin instanceof Plugin2)
|
1231
|
+
if (plugin instanceof Plugin2)
|
1535
1232
|
return defineFacetPayload(pluginFacet, [() => [plugin]]);
|
1536
|
-
|
1537
|
-
if (Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin2)) {
|
1233
|
+
if (Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin2))
|
1538
1234
|
return defineFacetPayload(pluginFacet, [() => plugin]);
|
1539
|
-
|
1540
|
-
if (typeof plugin === "function") {
|
1235
|
+
if (typeof plugin == "function")
|
1541
1236
|
return defineFacetPayload(pluginFacet, [plugin]);
|
1542
|
-
}
|
1543
1237
|
throw new TypeError("Invalid plugin");
|
1544
1238
|
}
|
1545
1239
|
var pluginFacet = defineFacet({
|
1546
|
-
reducer: (payloads) => {
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
}
|
1559
|
-
}
|
1560
|
-
plugins.reverse();
|
1561
|
-
return { plugins };
|
1562
|
-
};
|
1240
|
+
reducer: (payloads) => ({ schema }) => {
|
1241
|
+
let plugins = [];
|
1242
|
+
for (let payload of payloads)
|
1243
|
+
if (payload instanceof Plugin2)
|
1244
|
+
plugins.push(payload);
|
1245
|
+
else if (Array.isArray(payload) && payload.every((p) => p instanceof Plugin2))
|
1246
|
+
plugins.push(...payload);
|
1247
|
+
else if (typeof payload == "function")
|
1248
|
+
plugins.push(...[payload({ schema })].flat());
|
1249
|
+
else
|
1250
|
+
throw new ProseKitError("Invalid plugin");
|
1251
|
+
return plugins.reverse(), { plugins };
|
1563
1252
|
},
|
1564
1253
|
parent: stateFacet
|
1565
1254
|
});
|
@@ -1576,28 +1265,19 @@ function defineUnmountHandler(handler) {
|
|
1576
1265
|
}
|
1577
1266
|
var pluginViewFacet = defineFacet({
|
1578
1267
|
reduce: () => {
|
1579
|
-
let mountHandlers = []
|
1580
|
-
let updateHandlers = [];
|
1581
|
-
let unmountHandlers = [];
|
1582
|
-
const plugin = new ProseMirrorPlugin2({
|
1268
|
+
let mountHandlers = [], updateHandlers = [], unmountHandlers = [], plugin = new ProseMirrorPlugin2({
|
1583
1269
|
key: pluginKey,
|
1584
|
-
view: (view) => {
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
});
|
1596
|
-
const register = (input) => {
|
1597
|
-
mountHandlers = [];
|
1598
|
-
updateHandlers = [];
|
1599
|
-
unmountHandlers = [];
|
1600
|
-
for (const args of input) {
|
1270
|
+
view: (view) => (mountHandlers.forEach((fn) => fn(view)), {
|
1271
|
+
update: (view2, prevState) => {
|
1272
|
+
updateHandlers.forEach((fn) => fn(view2, prevState));
|
1273
|
+
},
|
1274
|
+
destroy: () => {
|
1275
|
+
unmountHandlers.forEach((fn) => fn());
|
1276
|
+
}
|
1277
|
+
})
|
1278
|
+
}), register = (input) => {
|
1279
|
+
mountHandlers = [], updateHandlers = [], unmountHandlers = [];
|
1280
|
+
for (let args of input)
|
1601
1281
|
switch (args[0]) {
|
1602
1282
|
case "mount":
|
1603
1283
|
mountHandlers.push(args[1]);
|
@@ -1609,24 +1289,19 @@ var pluginViewFacet = defineFacet({
|
|
1609
1289
|
unmountHandlers.push(args[1]);
|
1610
1290
|
break;
|
1611
1291
|
}
|
1612
|
-
}
|
1613
1292
|
};
|
1614
|
-
return function
|
1615
|
-
register(input);
|
1616
|
-
return plugin;
|
1293
|
+
return function(input) {
|
1294
|
+
return register(input), plugin;
|
1617
1295
|
};
|
1618
1296
|
},
|
1619
1297
|
parent: pluginFacet,
|
1620
|
-
singleton:
|
1621
|
-
});
|
1622
|
-
var pluginKey = new PluginKey("prosekit-plugin-view-handler");
|
1298
|
+
singleton: !0
|
1299
|
+
}), pluginKey = new PluginKey("prosekit-plugin-view-handler");
|
1623
1300
|
|
1624
1301
|
// src/extensions/events/doc-change.ts
|
1625
1302
|
function defineDocChangeHandler(handler) {
|
1626
1303
|
return defineUpdateHandler((view, prevState) => {
|
1627
|
-
|
1628
|
-
handler(view, prevState);
|
1629
|
-
}
|
1304
|
+
view.state.doc.eq(prevState.doc) || handler(view, prevState);
|
1630
1305
|
});
|
1631
1306
|
}
|
1632
1307
|
|
@@ -1640,26 +1315,20 @@ function combineEventHandlers() {
|
|
1640
1315
|
_handlers = toReversed(handlers);
|
1641
1316
|
}
|
1642
1317
|
function combinedEventHandler(...args) {
|
1643
|
-
for (
|
1644
|
-
if (handler(...args))
|
1645
|
-
return
|
1646
|
-
|
1647
|
-
}
|
1648
|
-
return false;
|
1318
|
+
for (let handler of _handlers)
|
1319
|
+
if (handler(...args))
|
1320
|
+
return !0;
|
1321
|
+
return !1;
|
1649
1322
|
}
|
1650
1323
|
return [setHandlers, combinedEventHandler];
|
1651
1324
|
}
|
1652
1325
|
|
1653
1326
|
// src/utils/group-entries.ts
|
1654
1327
|
function groupEntries(entries) {
|
1655
|
-
|
1656
|
-
for (
|
1657
|
-
|
1658
|
-
|
1659
|
-
map[key] = [value];
|
1660
|
-
} else {
|
1661
|
-
values.push(value);
|
1662
|
-
}
|
1328
|
+
let map = {};
|
1329
|
+
for (let [key, value] of entries) {
|
1330
|
+
let values = map[key];
|
1331
|
+
values ? values.push(value) : map[key] = [value];
|
1663
1332
|
}
|
1664
1333
|
return map;
|
1665
1334
|
}
|
@@ -1672,42 +1341,33 @@ function defineDOMEventHandler(event, handler) {
|
|
1672
1341
|
}
|
1673
1342
|
var domEventFacet = defineFacet({
|
1674
1343
|
reduce: () => {
|
1675
|
-
|
1676
|
-
const combinedHandlerMap = {};
|
1677
|
-
let plugin = null;
|
1678
|
-
const update = (payloads) => {
|
1344
|
+
let setHandlersMap = {}, combinedHandlerMap = {}, plugin = null, update = (payloads) => {
|
1679
1345
|
var _a;
|
1680
|
-
let hasNewEvent =
|
1681
|
-
for (
|
1346
|
+
let hasNewEvent = !1;
|
1347
|
+
for (let [event] of payloads)
|
1682
1348
|
if (!setHandlersMap[event]) {
|
1683
|
-
hasNewEvent =
|
1684
|
-
|
1349
|
+
hasNewEvent = !0;
|
1350
|
+
let [setHandlers, combinedHandler] = combineEventHandlers();
|
1685
1351
|
setHandlersMap[event] = setHandlers;
|
1686
|
-
|
1687
|
-
return combinedHandler(view, eventObject);
|
1688
|
-
};
|
1352
|
+
let e = (view, eventObject) => combinedHandler(view, eventObject);
|
1689
1353
|
combinedHandlerMap[event] = e;
|
1690
1354
|
}
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
const handlers = (_a = map[event]) != null ? _a : [];
|
1355
|
+
let map = groupEntries(payloads);
|
1356
|
+
for (let [event, setHandlers] of Object.entries(setHandlersMap)) {
|
1357
|
+
let handlers = (_a = map[event]) != null ? _a : [];
|
1695
1358
|
setHandlers(handlers);
|
1696
1359
|
}
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
});
|
1702
|
-
}
|
1360
|
+
hasNewEvent && (plugin = new ProseMirrorPlugin3({
|
1361
|
+
key: new PluginKey2("prosekit-dom-event-handler"),
|
1362
|
+
props: { handleDOMEvents: combinedHandlerMap }
|
1363
|
+
}));
|
1703
1364
|
};
|
1704
|
-
return function
|
1705
|
-
update(inputs);
|
1706
|
-
return plugin != null ? plugin : [];
|
1365
|
+
return function(inputs) {
|
1366
|
+
return update(inputs), plugin != null ? plugin : [];
|
1707
1367
|
};
|
1708
1368
|
},
|
1709
1369
|
parent: pluginFacet,
|
1710
|
-
singleton:
|
1370
|
+
singleton: !0
|
1711
1371
|
});
|
1712
1372
|
|
1713
1373
|
// src/extensions/events/editor-event.ts
|
@@ -1750,45 +1410,18 @@ function defineScrollToSelectionHandler(handler) {
|
|
1750
1410
|
}
|
1751
1411
|
var editorEventFacet = defineFacet({
|
1752
1412
|
reduce: () => {
|
1753
|
-
|
1754
|
-
return (entries) =>
|
1755
|
-
update(entries);
|
1756
|
-
return plugin;
|
1757
|
-
};
|
1413
|
+
let [update, plugin] = setupEditorEventPlugin();
|
1414
|
+
return (entries) => (update(entries), plugin);
|
1758
1415
|
},
|
1759
1416
|
parent: pluginFacet,
|
1760
|
-
singleton:
|
1417
|
+
singleton: !0
|
1761
1418
|
});
|
1762
1419
|
function setupEditorEventPlugin() {
|
1763
|
-
|
1764
|
-
const [setKeyPressHandlers, handleKeyPress] = combineEventHandlers();
|
1765
|
-
const [setTextInputHandlers, handleTextInput] = combineEventHandlers();
|
1766
|
-
const [setClickOnHandlers, handleClickOn] = combineEventHandlers();
|
1767
|
-
const [setClickHandlers, handleClick] = combineEventHandlers();
|
1768
|
-
const [setDoubleClickOnHandlers, handleDoubleClickOn] = combineEventHandlers();
|
1769
|
-
const [setDoubleClickHandlers, handleDoubleClick] = combineEventHandlers();
|
1770
|
-
const [setTripleClickOnHandlers, handleTripleClickOn] = combineEventHandlers();
|
1771
|
-
const [setTripleClickHandlers, handleTripleClick] = combineEventHandlers();
|
1772
|
-
const [setPasteHandlers, handlePaste] = combineEventHandlers();
|
1773
|
-
const [setDropHandlers, handleDrop] = combineEventHandlers();
|
1774
|
-
const [setScrollToSelectionHandlers, handleScrollToSelection] = combineEventHandlers();
|
1775
|
-
const update = (entries) => {
|
1420
|
+
let [setKeyDownHandlers, handleKeyDown] = combineEventHandlers(), [setKeyPressHandlers, handleKeyPress] = combineEventHandlers(), [setTextInputHandlers, handleTextInput] = combineEventHandlers(), [setClickOnHandlers, handleClickOn] = combineEventHandlers(), [setClickHandlers, handleClick] = combineEventHandlers(), [setDoubleClickOnHandlers, handleDoubleClickOn] = combineEventHandlers(), [setDoubleClickHandlers, handleDoubleClick] = combineEventHandlers(), [setTripleClickOnHandlers, handleTripleClickOn] = combineEventHandlers(), [setTripleClickHandlers, handleTripleClick] = combineEventHandlers(), [setPasteHandlers, handlePaste] = combineEventHandlers(), [setDropHandlers, handleDrop] = combineEventHandlers(), [setScrollToSelectionHandlers, handleScrollToSelection] = combineEventHandlers(), update = (entries) => {
|
1776
1421
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
1777
|
-
|
1778
|
-
setKeyDownHandlers((_a = map.keyDown) != null ? _a : []);
|
1779
|
-
|
1780
|
-
setTextInputHandlers((_c = map.textInput) != null ? _c : []);
|
1781
|
-
setClickOnHandlers((_d = map.clickOn) != null ? _d : []);
|
1782
|
-
setClickHandlers((_e = map.click) != null ? _e : []);
|
1783
|
-
setDoubleClickOnHandlers((_f = map.doubleClickOn) != null ? _f : []);
|
1784
|
-
setDoubleClickHandlers((_g = map.doubleClick) != null ? _g : []);
|
1785
|
-
setTripleClickOnHandlers((_h = map.tripleClickOn) != null ? _h : []);
|
1786
|
-
setTripleClickHandlers((_i = map.tripleClick) != null ? _i : []);
|
1787
|
-
setPasteHandlers((_j = map.paste) != null ? _j : []);
|
1788
|
-
setDropHandlers((_k = map.drop) != null ? _k : []);
|
1789
|
-
setScrollToSelectionHandlers((_l = map.scrollToSelection) != null ? _l : []);
|
1790
|
-
};
|
1791
|
-
const plugin = new ProseMirrorPlugin4({
|
1422
|
+
let map = groupEntries(entries);
|
1423
|
+
setKeyDownHandlers((_a = map.keyDown) != null ? _a : []), setKeyPressHandlers((_b = map.keyPress) != null ? _b : []), setTextInputHandlers((_c = map.textInput) != null ? _c : []), setClickOnHandlers((_d = map.clickOn) != null ? _d : []), setClickHandlers((_e = map.click) != null ? _e : []), setDoubleClickOnHandlers((_f = map.doubleClickOn) != null ? _f : []), setDoubleClickHandlers((_g = map.doubleClick) != null ? _g : []), setTripleClickOnHandlers((_h = map.tripleClickOn) != null ? _h : []), setTripleClickHandlers((_i = map.tripleClick) != null ? _i : []), setPasteHandlers((_j = map.paste) != null ? _j : []), setDropHandlers((_k = map.drop) != null ? _k : []), setScrollToSelectionHandlers((_l = map.scrollToSelection) != null ? _l : []);
|
1424
|
+
}, plugin = new ProseMirrorPlugin4({
|
1792
1425
|
key: new PluginKey3("prosekit-editor-event"),
|
1793
1426
|
props: {
|
1794
1427
|
handleKeyDown,
|
@@ -1810,11 +1443,9 @@ function setupEditorEventPlugin() {
|
|
1810
1443
|
|
1811
1444
|
// src/extensions/events/focus.ts
|
1812
1445
|
function defineFocusChangeHandler(handler) {
|
1813
|
-
const handleFocus = () => handler(true);
|
1814
|
-
const handleBlur = () => handler(false);
|
1815
1446
|
return defineFacetPayload(domEventFacet, [
|
1816
|
-
["focus",
|
1817
|
-
["blur",
|
1447
|
+
["focus", () => handler(!0)],
|
1448
|
+
["blur", () => handler(!1)]
|
1818
1449
|
]);
|
1819
1450
|
}
|
1820
1451
|
|
@@ -1822,7 +1453,7 @@ function defineFocusChangeHandler(handler) {
|
|
1822
1453
|
import { history, redo, undo } from "@prosekit/pm/history";
|
1823
1454
|
|
1824
1455
|
// src/utils/env.ts
|
1825
|
-
var isApple = typeof navigator
|
1456
|
+
var isApple = typeof navigator != "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : !1;
|
1826
1457
|
|
1827
1458
|
// src/extensions/keymap.ts
|
1828
1459
|
import {
|
@@ -1849,42 +1480,30 @@ function defineKeymap(keymap) {
|
|
1849
1480
|
}
|
1850
1481
|
function defineBaseKeymap(options) {
|
1851
1482
|
var _a;
|
1852
|
-
|
1483
|
+
let priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */;
|
1853
1484
|
return withPriority(defineKeymap(customBaseKeymap), priority);
|
1854
1485
|
}
|
1855
1486
|
var keymapFacet = defineFacet({
|
1856
1487
|
reduce: () => {
|
1857
|
-
let handler = null
|
1858
|
-
const handlerWrapper = (view, event) => {
|
1859
|
-
if (handler)
|
1860
|
-
return handler(view, event);
|
1861
|
-
return false;
|
1862
|
-
};
|
1863
|
-
const plugin = new Plugin3({
|
1488
|
+
let handler = null, handlerWrapper = (view, event) => handler ? handler(view, event) : !1, plugin = new Plugin3({
|
1864
1489
|
key: keymapPluginKey,
|
1865
1490
|
props: { handleKeyDown: handlerWrapper }
|
1866
1491
|
});
|
1867
|
-
return (keymaps) =>
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
);
|
1874
|
-
return plugin;
|
1875
|
-
};
|
1492
|
+
return (keymaps) => (handler = keydownHandler(
|
1493
|
+
mergeKeymaps(
|
1494
|
+
// The keymap at the end have a higher priority.
|
1495
|
+
toReversed(keymaps)
|
1496
|
+
)
|
1497
|
+
), plugin);
|
1876
1498
|
},
|
1877
1499
|
parent: pluginFacet,
|
1878
|
-
singleton:
|
1500
|
+
singleton: !0
|
1879
1501
|
});
|
1880
1502
|
function mergeKeymaps(keymaps) {
|
1881
|
-
|
1882
|
-
for (
|
1883
|
-
for (
|
1884
|
-
|
1885
|
-
commands.push(command);
|
1886
|
-
}
|
1887
|
-
}
|
1503
|
+
let bindings = {};
|
1504
|
+
for (let keymap of keymaps)
|
1505
|
+
for (let [key, command] of Object.entries(keymap))
|
1506
|
+
(bindings[key] || (bindings[key] = [])).push(command);
|
1888
1507
|
return Object.fromEntries(
|
1889
1508
|
Object.entries(bindings).map(([key, commands]) => [
|
1890
1509
|
key,
|
@@ -1896,14 +1515,11 @@ var keymapPluginKey = new PluginKey4("prosekit-keymap");
|
|
1896
1515
|
|
1897
1516
|
// src/extensions/history.ts
|
1898
1517
|
function defineHistory() {
|
1899
|
-
|
1518
|
+
let keymap = {
|
1900
1519
|
"Mod-z": undo,
|
1901
1520
|
"Shift-Mod-z": redo
|
1902
1521
|
};
|
1903
|
-
|
1904
|
-
keymap["Mod-y"] = redo;
|
1905
|
-
}
|
1906
|
-
return union([
|
1522
|
+
return isApple || (keymap["Mod-y"] = redo), union([
|
1907
1523
|
definePlugin(history()),
|
1908
1524
|
defineKeymap(keymap),
|
1909
1525
|
defineCommands({
|
@@ -1915,93 +1531,64 @@ function defineHistory() {
|
|
1915
1531
|
|
1916
1532
|
// src/extensions/mark-spec.ts
|
1917
1533
|
function defineMarkSpec(options) {
|
1918
|
-
|
1919
|
-
return defineFacetPayload(markSpecFacet, [payload]);
|
1534
|
+
return defineFacetPayload(markSpecFacet, [[options, void 0]]);
|
1920
1535
|
}
|
1921
1536
|
function defineMarkAttr(options) {
|
1922
|
-
|
1923
|
-
return defineFacetPayload(markSpecFacet, [payload]);
|
1537
|
+
return defineFacetPayload(markSpecFacet, [[void 0, options]]);
|
1924
1538
|
}
|
1925
1539
|
var markSpecFacet = defineFacet({
|
1926
1540
|
reducer: (payloads) => {
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
for (const { name, ...spec } of specPayloads) {
|
1931
|
-
if (marks[name]) {
|
1541
|
+
let marks = {}, specPayloads = payloads.map((input) => input[0]).filter(isNotNull), attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
|
1542
|
+
for (let { name, ...spec } of specPayloads) {
|
1543
|
+
if (marks[name])
|
1932
1544
|
throw new ProseKitError(`Mark type ${name} has already been defined`);
|
1933
|
-
}
|
1934
1545
|
marks[name] = spec;
|
1935
1546
|
}
|
1936
|
-
for (
|
1547
|
+
for (let {
|
1937
1548
|
type,
|
1938
1549
|
attr,
|
1939
1550
|
default: defaultValue,
|
1940
1551
|
toDOM,
|
1941
1552
|
parseDOM
|
1942
1553
|
} of attrPayloads) {
|
1943
|
-
|
1944
|
-
if (!spec)
|
1554
|
+
let spec = marks[type];
|
1555
|
+
if (!spec)
|
1945
1556
|
throw new ProseKitError(
|
1946
1557
|
`Mark type ${type} must be defined before defining attributes`
|
1947
1558
|
);
|
1948
|
-
}
|
1949
|
-
|
1950
|
-
spec.attrs = {};
|
1951
|
-
}
|
1952
|
-
spec.attrs[attr] = { default: defaultValue };
|
1953
|
-
if (toDOM && spec.toDOM) {
|
1954
|
-
const existingToDom = spec.toDOM;
|
1559
|
+
if (spec.attrs || (spec.attrs = {}), spec.attrs[attr] = { default: defaultValue }, toDOM && spec.toDOM) {
|
1560
|
+
let existingToDom = spec.toDOM;
|
1955
1561
|
spec.toDOM = (mark, inline) => {
|
1956
|
-
|
1957
|
-
if (!dom)
|
1958
|
-
return dom;
|
1959
|
-
}
|
1960
|
-
const attrDOM = toDOM(mark.attrs[attr]);
|
1961
|
-
if (!attrDOM) {
|
1562
|
+
let dom = existingToDom(mark, inline);
|
1563
|
+
if (!dom)
|
1962
1564
|
return dom;
|
1963
|
-
|
1964
|
-
|
1965
|
-
if (!key) {
|
1565
|
+
let attrDOM = toDOM(mark.attrs[attr]);
|
1566
|
+
if (!attrDOM)
|
1966
1567
|
return dom;
|
1967
|
-
|
1968
|
-
|
1969
|
-
if (typeof dom[1] === "object") {
|
1970
|
-
return [dom[0], { ...dom[1], [key]: value }, ...dom.slice(2)];
|
1971
|
-
} else {
|
1972
|
-
return [dom[0], { [key]: value }, ...dom.slice(1)];
|
1973
|
-
}
|
1974
|
-
} else if (isElement(dom)) {
|
1975
|
-
dom.setAttribute(key, value);
|
1976
|
-
} else if (typeof dom === "object" && "dom" in dom && isElement(dom.dom)) {
|
1977
|
-
dom.dom.setAttribute(key, value);
|
1978
|
-
}
|
1979
|
-
return dom;
|
1568
|
+
let [key, value] = attrDOM;
|
1569
|
+
return key ? Array.isArray(dom) ? typeof dom[1] == "object" ? [dom[0], { ...dom[1], [key]: value }, ...dom.slice(2)] : [dom[0], { [key]: value }, ...dom.slice(1)] : (isElement(dom) ? dom.setAttribute(key, value) : typeof dom == "object" && "dom" in dom && isElement(dom.dom) && dom.dom.setAttribute(key, value), dom) : dom;
|
1980
1570
|
};
|
1981
1571
|
}
|
1982
|
-
if (parseDOM && spec.parseDOM)
|
1983
|
-
for (
|
1984
|
-
|
1985
|
-
const existingAttrs = rule.attrs;
|
1572
|
+
if (parseDOM && spec.parseDOM)
|
1573
|
+
for (let rule of spec.parseDOM) {
|
1574
|
+
let existingGetAttrs = rule.getAttrs, existingAttrs = rule.attrs;
|
1986
1575
|
rule.getAttrs = (dom) => {
|
1987
1576
|
var _a;
|
1988
|
-
|
1989
|
-
if (attrs ===
|
1577
|
+
let attrs = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs;
|
1578
|
+
if (attrs === !1 || !dom || !isElement(dom))
|
1990
1579
|
return attrs != null ? attrs : null;
|
1991
|
-
|
1992
|
-
const value = parseDOM(dom);
|
1580
|
+
let value = parseDOM(dom);
|
1993
1581
|
return {
|
1994
1582
|
...attrs,
|
1995
1583
|
[attr]: value
|
1996
1584
|
};
|
1997
1585
|
};
|
1998
1586
|
}
|
1999
|
-
}
|
2000
1587
|
}
|
2001
1588
|
return { marks, nodes: {} };
|
2002
1589
|
},
|
2003
1590
|
parent: schemaSpecFacet,
|
2004
|
-
singleton:
|
1591
|
+
singleton: !0
|
2005
1592
|
});
|
2006
1593
|
|
2007
1594
|
// src/extensions/node-view.ts
|
@@ -2012,12 +1599,9 @@ function defineNodeView(options) {
|
|
2012
1599
|
}
|
2013
1600
|
var nodeViewFacet = defineFacet({
|
2014
1601
|
reducer: (inputs) => {
|
2015
|
-
|
2016
|
-
for (
|
2017
|
-
|
2018
|
-
nodeViews[input.name] = input.constructor;
|
2019
|
-
}
|
2020
|
-
}
|
1602
|
+
let nodeViews = {};
|
1603
|
+
for (let input of inputs)
|
1604
|
+
nodeViews[input.name] || (nodeViews[input.name] = input.constructor);
|
2021
1605
|
return () => [
|
2022
1606
|
new ProseMirrorPlugin5({
|
2023
1607
|
key: new PluginKey5("prosekit-node-view"),
|
@@ -2036,26 +1620,18 @@ function defineNodeViewFactory(options) {
|
|
2036
1620
|
}
|
2037
1621
|
var nodeViewFactoryFacet = defineFacet({
|
2038
1622
|
reducer: (inputs) => {
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
} else {
|
2047
|
-
options[group] || (options[group] = []);
|
2048
|
-
options[group].push({
|
2049
|
-
name: input.name,
|
2050
|
-
args: input.args
|
2051
|
-
});
|
2052
|
-
}
|
1623
|
+
let nodeViews = {}, options = {}, factories = {};
|
1624
|
+
for (let input of inputs) {
|
1625
|
+
let group = input.group;
|
1626
|
+
input.name == null ? factories[group] = input.factory : (options[group] || (options[group] = []), options[group].push({
|
1627
|
+
name: input.name,
|
1628
|
+
args: input.args
|
1629
|
+
}));
|
2053
1630
|
}
|
2054
|
-
for (
|
2055
|
-
|
2056
|
-
for (
|
1631
|
+
for (let [group, factory] of Object.entries(factories)) {
|
1632
|
+
let groupOptions = options[group] || [];
|
1633
|
+
for (let { name, args } of groupOptions)
|
2057
1634
|
nodeViews[name] = factory(args);
|
2058
|
-
}
|
2059
1635
|
}
|
2060
1636
|
return () => [
|
2061
1637
|
new ProseMirrorPlugin6({
|
@@ -2093,13 +1669,8 @@ function defineText() {
|
|
2093
1669
|
|
2094
1670
|
// src/utils/cache.ts
|
2095
1671
|
function cache(fn) {
|
2096
|
-
let result
|
2097
|
-
return () =>
|
2098
|
-
if (result === void 0) {
|
2099
|
-
result = fn();
|
2100
|
-
}
|
2101
|
-
return result;
|
2102
|
-
};
|
1672
|
+
let result;
|
1673
|
+
return () => (result === void 0 && (result = fn()), result);
|
2103
1674
|
}
|
2104
1675
|
|
2105
1676
|
// src/utils/can-use-regex-lookbehind.ts
|
@@ -2107,7 +1678,7 @@ var canUseRegexLookbehind = cache(() => {
|
|
2107
1678
|
try {
|
2108
1679
|
return "ab".replace(new RegExp("(?<=a)b", "g"), "c") === "ac";
|
2109
1680
|
} catch (error) {
|
2110
|
-
return
|
1681
|
+
return !1;
|
2111
1682
|
}
|
2112
1683
|
});
|
2113
1684
|
|
@@ -2118,9 +1689,8 @@ var clsx = clsxLite;
|
|
2118
1689
|
// src/utils/default-block-at.ts
|
2119
1690
|
function defaultBlockAt(match) {
|
2120
1691
|
for (let i = 0; i < match.edgeCount; i++) {
|
2121
|
-
|
2122
|
-
if (type.isTextblock && !type.hasRequiredAttrs())
|
2123
|
-
return type;
|
1692
|
+
let { type } = match.edge(i);
|
1693
|
+
if (type.isTextblock && !type.hasRequiredAttrs()) return type;
|
2124
1694
|
}
|
2125
1695
|
return null;
|
2126
1696
|
}
|
@@ -2128,8 +1698,7 @@ function defaultBlockAt(match) {
|
|
2128
1698
|
// src/utils/get-id.ts
|
2129
1699
|
var id = 0;
|
2130
1700
|
function getId() {
|
2131
|
-
id = (id + 1) % Number.MAX_SAFE_INTEGER
|
2132
|
-
return `id:${id}`;
|
1701
|
+
return id = (id + 1) % Number.MAX_SAFE_INTEGER, `id:${id}`;
|
2133
1702
|
}
|
2134
1703
|
|
2135
1704
|
// src/utils/is-in-code-block.ts
|
@@ -2142,7 +1711,7 @@ function isInCodeBlock(selection) {
|
|
2142
1711
|
|
2143
1712
|
// src/utils/maybe-run.ts
|
2144
1713
|
function maybeRun(value, ...args) {
|
2145
|
-
return typeof value
|
1714
|
+
return typeof value == "function" ? value(...args) : value;
|
2146
1715
|
}
|
2147
1716
|
|
2148
1717
|
// src/utils/unicode.ts
|
@@ -2150,12 +1719,7 @@ var OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
|
|
2150
1719
|
|
2151
1720
|
// src/utils/with-skip-code-block.ts
|
2152
1721
|
function withSkipCodeBlock(command) {
|
2153
|
-
return (state, dispatch, view) =>
|
2154
|
-
if (isInCodeBlock(state.selection)) {
|
2155
|
-
return false;
|
2156
|
-
}
|
2157
|
-
return command(state, dispatch, view);
|
2158
|
-
};
|
1722
|
+
return (state, dispatch, view) => isInCodeBlock(state.selection) ? !1 : command(state, dispatch, view);
|
2159
1723
|
}
|
2160
1724
|
export {
|
2161
1725
|
Editor,
|
@@ -2233,6 +1797,7 @@ export {
|
|
2233
1797
|
nodeFromJSON,
|
2234
1798
|
pluginFacet,
|
2235
1799
|
removeMark,
|
1800
|
+
removeNode,
|
2236
1801
|
setBlockType,
|
2237
1802
|
setNodeAttrs,
|
2238
1803
|
stateFromJSON,
|