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