@prosekit/core 0.5.4 → 0.6.0
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 +66 -20
- package/dist/prosekit-core.d.ts +1 -0
- package/dist/prosekit-core.js +507 -942
- package/package.json +5 -5
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
|
-
|
113
|
+
let tr = state.tr.insert(insertPos, node);
|
114
|
+
setSelectionAround(tr, insertPos + node.nodeSize), dispatch(tr);
|
115
|
+
}
|
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
|
+
};
|
156
129
|
}
|
157
|
-
|
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) {
|
@@ -444,6 +358,11 @@ function toReversed(arr) {
|
|
444
358
|
return (_b = (_a = arr.toReversed) == null ? void 0 : _a.call(arr)) != null ? _b : [...arr].reverse();
|
445
359
|
}
|
446
360
|
|
361
|
+
// src/utils/is-not-null.ts
|
362
|
+
function isNotNull(value) {
|
363
|
+
return value != null;
|
364
|
+
}
|
365
|
+
|
447
366
|
// src/facets/facet-node.ts
|
448
367
|
function zip5(a, b, mapper) {
|
449
368
|
return [
|
@@ -455,108 +374,92 @@ function zip5(a, b, mapper) {
|
|
455
374
|
];
|
456
375
|
}
|
457
376
|
function unionInput(a, b) {
|
458
|
-
|
459
|
-
return null;
|
460
|
-
return uniqPush(a != null ? a : [], b != null ? b : []);
|
377
|
+
return !a && !b ? null : uniqPush(a != null ? a : [], b != null ? b : []);
|
461
378
|
}
|
462
379
|
function subtractInput(a, b) {
|
463
|
-
|
464
|
-
return null;
|
465
|
-
if (!b)
|
466
|
-
return [...a];
|
467
|
-
return arraySubstract(a, b);
|
380
|
+
return a ? b ? arraySubstract(a, b) : [...a] : null;
|
468
381
|
}
|
469
382
|
function unionChildren(a, b) {
|
470
|
-
|
471
|
-
for (
|
472
|
-
|
383
|
+
let merged = new Map(a);
|
384
|
+
for (let [key, valueB] of b.entries()) {
|
385
|
+
let valueA = a.get(key);
|
473
386
|
merged.set(key, valueA ? unionFacetNode(valueA, valueB) : valueB);
|
474
387
|
}
|
475
388
|
return merged;
|
476
389
|
}
|
477
390
|
function subtractChildren(a, b) {
|
478
|
-
|
479
|
-
for (
|
480
|
-
|
481
|
-
|
482
|
-
merged.set(key, subtractFacetNode(valueA, valueB));
|
483
|
-
}
|
391
|
+
let merged = new Map(a);
|
392
|
+
for (let [key, valueB] of b.entries()) {
|
393
|
+
let valueA = a.get(key);
|
394
|
+
valueA && merged.set(key, subtractFacetNode(valueA, valueB));
|
484
395
|
}
|
485
396
|
return merged;
|
486
397
|
}
|
487
398
|
function unionFacetNode(a, b) {
|
488
|
-
assert(a.facet === b.facet)
|
489
|
-
return new FacetNode(
|
399
|
+
return assert(a.facet === b.facet), new FacetNode(
|
490
400
|
a.facet,
|
491
401
|
zip5(a.inputs, b.inputs, unionInput),
|
492
|
-
unionChildren(a.children, b.children)
|
402
|
+
unionChildren(a.children, b.children),
|
403
|
+
a.reducers
|
493
404
|
);
|
494
405
|
}
|
495
406
|
function subtractFacetNode(a, b) {
|
496
|
-
assert(a.facet === b.facet)
|
497
|
-
return new FacetNode(
|
407
|
+
return assert(a.facet === b.facet), new FacetNode(
|
498
408
|
a.facet,
|
499
409
|
zip5(a.inputs, b.inputs, subtractInput),
|
500
|
-
subtractChildren(a.children, b.children)
|
410
|
+
subtractChildren(a.children, b.children),
|
411
|
+
a.reducers
|
501
412
|
);
|
502
413
|
}
|
503
414
|
var FacetNode = class {
|
504
|
-
constructor(facet, inputs = [null, null, null, null, null], children = /* @__PURE__ */ new Map()
|
415
|
+
constructor(facet, inputs = [null, null, null, null, null], children = /* @__PURE__ */ new Map(), reducers = [
|
416
|
+
null,
|
417
|
+
null,
|
418
|
+
null,
|
419
|
+
null,
|
420
|
+
null
|
421
|
+
]) {
|
505
422
|
this.facet = facet;
|
506
423
|
this.inputs = inputs;
|
507
424
|
this.children = children;
|
508
|
-
this.reducers =
|
425
|
+
this.reducers = reducers;
|
509
426
|
this.output = null;
|
510
427
|
}
|
511
428
|
calcOutput() {
|
512
429
|
var _a, _b, _c;
|
513
|
-
|
514
|
-
const output = [null, null, null, null, null];
|
430
|
+
let inputs = [null, null, null, null, null], output = [null, null, null, null, null];
|
515
431
|
for (let pri = 0; pri < 5; pri++) {
|
516
|
-
|
517
|
-
|
518
|
-
inputs[pri] = [...input];
|
519
|
-
}
|
432
|
+
let input = this.inputs[pri];
|
433
|
+
input && (inputs[pri] = [...input]);
|
520
434
|
}
|
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
|
-
}
|
435
|
+
for (let child of this.children.values()) {
|
436
|
+
let childOutput = child.getOutput();
|
437
|
+
for (let pri = 0; pri < 5; pri++)
|
438
|
+
childOutput[pri] && (inputs[pri] || (inputs[pri] = [])).push(childOutput[pri]);
|
529
439
|
}
|
530
440
|
if (this.facet.singleton) {
|
531
|
-
|
532
|
-
const input = inputs.filter(Boolean).flat();
|
441
|
+
let reducer = (_a = this.reducers)[_b = 2 /* default */] || (_a[_b] = this.facet.reducer), input = inputs.filter(isNotNull).flat();
|
533
442
|
output[2 /* default */] = reducer(input);
|
534
|
-
} else
|
443
|
+
} else
|
535
444
|
for (let pri = 0; pri < 5; pri++) {
|
536
|
-
|
445
|
+
let input = inputs[pri];
|
537
446
|
if (input) {
|
538
|
-
|
447
|
+
let reducer = (_c = this.reducers)[pri] || (_c[pri] = this.facet.reducer);
|
539
448
|
output[pri] = reducer(input);
|
540
449
|
}
|
541
450
|
}
|
542
|
-
}
|
543
451
|
return output;
|
544
452
|
}
|
545
453
|
getOutput() {
|
546
|
-
|
547
|
-
this.output = this.calcOutput();
|
548
|
-
}
|
549
|
-
return this.output;
|
454
|
+
return this.output || (this.output = this.calcOutput()), this.output;
|
550
455
|
}
|
551
456
|
getSingletonOutput() {
|
552
|
-
assert(this.facet.singleton);
|
553
|
-
return this.getOutput()[2 /* default */];
|
457
|
+
return assert(this.facet.singleton), this.getOutput()[2 /* default */];
|
554
458
|
}
|
555
459
|
getRootOutput() {
|
556
460
|
assert(this.isRoot());
|
557
|
-
|
558
|
-
assert(output);
|
559
|
-
return output;
|
461
|
+
let output = this.getSingletonOutput();
|
462
|
+
return assert(output), output;
|
560
463
|
}
|
561
464
|
isRoot() {
|
562
465
|
return !this.facet.parent;
|
@@ -567,8 +470,7 @@ var FacetNode = class {
|
|
567
470
|
import { Schema as Schema4 } from "@prosekit/pm/model";
|
568
471
|
|
569
472
|
// src/facets/facet.ts
|
570
|
-
var facetCount = 0
|
571
|
-
var Facet = class {
|
473
|
+
var facetCount = 0, Facet = class {
|
572
474
|
/**
|
573
475
|
* @internal
|
574
476
|
*/
|
@@ -579,10 +481,7 @@ var Facet = class {
|
|
579
481
|
* @internal
|
580
482
|
*/
|
581
483
|
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] : [];
|
484
|
+
assert((_reduce || _reducer) && !(_reduce && _reducer)), this.parent = parent, this.singleton = singleton, this.path = parent ? [...parent.path, this.index] : [];
|
586
485
|
}
|
587
486
|
get reducer() {
|
588
487
|
var _a, _b;
|
@@ -593,7 +492,7 @@ function defineFacet(options) {
|
|
593
492
|
var _a;
|
594
493
|
return new Facet(
|
595
494
|
options.parent,
|
596
|
-
(_a = options.singleton) != null ? _a :
|
495
|
+
(_a = options.singleton) != null ? _a : !1,
|
597
496
|
options.reducer,
|
598
497
|
options.reduce
|
599
498
|
);
|
@@ -602,22 +501,15 @@ function defineFacet(options) {
|
|
602
501
|
// src/facets/root.ts
|
603
502
|
function rootReducer(inputs) {
|
604
503
|
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 });
|
504
|
+
let schema, commands, stateFunc, view;
|
505
|
+
for (let input of inputs)
|
506
|
+
schema = input.schema || schema, commands = input.commands || commands, stateFunc = input.state || stateFunc, view = input.view || view;
|
507
|
+
let state = schema && ((_a = stateFunc == null ? void 0 : stateFunc({ schema })) != null ? _a : { schema });
|
616
508
|
return { schema, state, commands, view };
|
617
509
|
}
|
618
510
|
var rootFacet = new Facet(
|
619
511
|
null,
|
620
|
-
|
512
|
+
!0,
|
621
513
|
rootReducer
|
622
514
|
);
|
623
515
|
|
@@ -625,12 +517,11 @@ var rootFacet = new Facet(
|
|
625
517
|
var schemaFacet = defineFacet({
|
626
518
|
reducer: (specs) => {
|
627
519
|
assert(specs.length <= 1);
|
628
|
-
|
629
|
-
|
630
|
-
return { schema };
|
520
|
+
let spec = specs[0];
|
521
|
+
return { schema: spec ? new Schema4(spec) : null };
|
631
522
|
},
|
632
523
|
parent: rootFacet,
|
633
|
-
singleton:
|
524
|
+
singleton: !0
|
634
525
|
});
|
635
526
|
|
636
527
|
// src/facets/base-extension.ts
|
@@ -644,7 +535,7 @@ var BaseExtension = class {
|
|
644
535
|
*/
|
645
536
|
getTree(priority) {
|
646
537
|
var _a, _b;
|
647
|
-
|
538
|
+
let pri = (_a = priority != null ? priority : this.priority) != null ? _a : 2 /* default */;
|
648
539
|
return (_b = this.trees)[pri] || (_b[pri] = this.createTree(pri));
|
649
540
|
}
|
650
541
|
/**
|
@@ -653,14 +544,13 @@ var BaseExtension = class {
|
|
653
544
|
findFacetOutput(facet) {
|
654
545
|
var _a;
|
655
546
|
let node = this.getTree();
|
656
|
-
for (
|
547
|
+
for (let index of facet.path)
|
657
548
|
node = node == null ? void 0 : node.children.get(index);
|
658
|
-
}
|
659
549
|
return (_a = node == null ? void 0 : node.getOutput()) != null ? _a : null;
|
660
550
|
}
|
661
551
|
get schema() {
|
662
552
|
var _a, _b;
|
663
|
-
|
553
|
+
let output = this.findFacetOutput(schemaFacet);
|
664
554
|
return (_b = (_a = output == null ? void 0 : output.find(Boolean)) == null ? void 0 : _a.schema) != null ? _b : null;
|
665
555
|
}
|
666
556
|
};
|
@@ -680,12 +570,11 @@ var FacetExtensionImpl = class extends BaseExtension {
|
|
680
570
|
*/
|
681
571
|
createTree(priority) {
|
682
572
|
var _a;
|
683
|
-
|
684
|
-
const inputs = [null, null, null, null, null];
|
573
|
+
let pri = (_a = this.priority) != null ? _a : priority, inputs = [null, null, null, null, null];
|
685
574
|
inputs[pri] = [...this.payloads];
|
686
575
|
let node = new FacetNode(this.facet, inputs);
|
687
|
-
|
688
|
-
|
576
|
+
for (; node.facet.parent; ) {
|
577
|
+
let children = /* @__PURE__ */ new Map([[node.facet.index, node]]);
|
689
578
|
node = new FacetNode(node.facet.parent, void 0, children);
|
690
579
|
}
|
691
580
|
return node;
|
@@ -698,37 +587,25 @@ function defineFacetPayload(facet, payloads) {
|
|
698
587
|
// src/facets/state.ts
|
699
588
|
var stateFacet = defineFacet({
|
700
589
|
reduce: () => {
|
701
|
-
let callbacks = []
|
702
|
-
const state = (ctx) => {
|
590
|
+
let callbacks = [], state = (ctx) => {
|
703
591
|
var _a, _b, _c, _d, _e, _f;
|
704
|
-
|
705
|
-
const config = {
|
592
|
+
let configs = callbacks.map((cb) => cb(ctx)), config = {
|
706
593
|
schema: ctx.schema,
|
707
594
|
storedMarks: [],
|
708
595
|
plugins: []
|
709
596
|
};
|
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(
|
597
|
+
for (let c of configs)
|
598
|
+
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 : []);
|
599
|
+
return assert(
|
718
600
|
config.doc || config.schema,
|
719
601
|
"Can't create state without a schema nor a document"
|
720
|
-
);
|
721
|
-
if (config.doc) {
|
722
|
-
config.schema = void 0;
|
723
|
-
}
|
724
|
-
return config;
|
602
|
+
), config.doc && (config.schema = void 0), config;
|
725
603
|
};
|
726
|
-
return function
|
727
|
-
callbacks = inputs;
|
728
|
-
return { state };
|
604
|
+
return function(inputs) {
|
605
|
+
return callbacks = inputs, { state };
|
729
606
|
};
|
730
607
|
},
|
731
|
-
singleton:
|
608
|
+
singleton: !0,
|
732
609
|
parent: rootFacet
|
733
610
|
});
|
734
611
|
|
@@ -738,20 +615,16 @@ import { EditorState } from "@prosekit/pm/state";
|
|
738
615
|
|
739
616
|
// src/utils/get-dom-api.ts
|
740
617
|
function findGlobalBrowserDocument() {
|
741
|
-
if (typeof document
|
618
|
+
if (typeof document != "undefined")
|
742
619
|
return document;
|
743
|
-
|
744
|
-
if (typeof globalThis !== "undefined" && globalThis.document) {
|
620
|
+
if (typeof globalThis != "undefined" && globalThis.document)
|
745
621
|
return globalThis.document;
|
746
|
-
}
|
747
622
|
}
|
748
623
|
function findGlobalBrowserWindow() {
|
749
|
-
if (typeof window
|
624
|
+
if (typeof window != "undefined")
|
750
625
|
return window;
|
751
|
-
|
752
|
-
if (typeof globalThis !== "undefined" && globalThis.window) {
|
626
|
+
if (typeof globalThis != "undefined" && globalThis.window)
|
753
627
|
return globalThis.window;
|
754
|
-
}
|
755
628
|
}
|
756
629
|
function findBrowserDocument(options) {
|
757
630
|
var _a, _b, _c;
|
@@ -762,15 +635,13 @@ function findBrowserWindow(options) {
|
|
762
635
|
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
636
|
}
|
764
637
|
function getBrowserDocument(options) {
|
765
|
-
|
766
|
-
if (doc)
|
767
|
-
return doc;
|
638
|
+
let doc = findBrowserDocument(options);
|
639
|
+
if (doc) return doc;
|
768
640
|
throw new DOMDocumentNotFoundError();
|
769
641
|
}
|
770
642
|
function getBrowserWindow(options) {
|
771
|
-
|
772
|
-
if (win)
|
773
|
-
return win;
|
643
|
+
let win = findBrowserWindow(options);
|
644
|
+
if (win) return win;
|
774
645
|
throw new DOMDocumentNotFoundError();
|
775
646
|
}
|
776
647
|
|
@@ -788,29 +659,20 @@ function nodeFromJSON(json, options) {
|
|
788
659
|
return options.schema.nodeFromJSON(json);
|
789
660
|
}
|
790
661
|
function nodeFromElement(element, options) {
|
791
|
-
|
792
|
-
const schema = options.schema;
|
662
|
+
let Parser = options.DOMParser || DOMParser, schema = options.schema;
|
793
663
|
return Parser.fromSchema(schema).parse(element);
|
794
664
|
}
|
795
665
|
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
|
-
}
|
666
|
+
let Serializer = (options == null ? void 0 : options.DOMSerializer) || DOMSerializer, document2 = getBrowserDocument(options), schema = node.type.schema, serializer = Serializer.fromSchema(schema);
|
667
|
+
return schema.topNodeType !== node.type ? serializer.serializeNode(node, { document: document2 }) : serializer.serializeFragment(
|
668
|
+
node.content,
|
669
|
+
{ document: document2 },
|
670
|
+
document2.createElement("div")
|
671
|
+
);
|
809
672
|
}
|
810
673
|
function elementFromHTML(html, options) {
|
811
|
-
|
812
|
-
|
813
|
-
return parser.parseFromString(`<body><div>${html}</div></body>`, "text/html").body.firstElementChild;
|
674
|
+
let win = getBrowserWindow(options);
|
675
|
+
return new win.DOMParser().parseFromString(`<body><div>${html}</div></body>`, "text/html").body.firstElementChild;
|
814
676
|
}
|
815
677
|
function htmlFromElement(element) {
|
816
678
|
return element.outerHTML;
|
@@ -840,28 +702,14 @@ function defineDefaultState({
|
|
840
702
|
defaultHTML,
|
841
703
|
defaultSelection
|
842
704
|
}) {
|
843
|
-
if (defaultHTML && defaultDoc)
|
705
|
+
if (defaultHTML && defaultDoc)
|
844
706
|
throw new ProseKitError(
|
845
707
|
"Only one of defaultHTML and defaultDoc can be provided"
|
846
708
|
);
|
847
|
-
}
|
848
709
|
return defineFacetPayload(stateFacet, [
|
849
710
|
({ 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;
|
711
|
+
let config = {};
|
712
|
+
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
713
|
}
|
866
714
|
]);
|
867
715
|
}
|
@@ -869,24 +717,19 @@ function defineDefaultState({
|
|
869
717
|
// src/utils/deep-equals.ts
|
870
718
|
import OrderedMap from "orderedmap";
|
871
719
|
function deepEquals(a, b) {
|
872
|
-
if (a === b)
|
873
|
-
return
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
}
|
878
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
720
|
+
if (a === b)
|
721
|
+
return !0;
|
722
|
+
if (!a || !b)
|
723
|
+
return !1;
|
724
|
+
if (Array.isArray(a) && Array.isArray(b))
|
879
725
|
return a.length === b.length && a.every((x, i) => deepEquals(x, b[i]));
|
880
|
-
|
881
|
-
if (a instanceof OrderedMap && b instanceof OrderedMap) {
|
726
|
+
if (a instanceof OrderedMap && b instanceof OrderedMap)
|
882
727
|
return a.size === b.size && deepEquals(a.toObject(), b.toObject());
|
883
|
-
|
884
|
-
|
885
|
-
const aKeys = Object.keys(a);
|
886
|
-
const bKeys = Object.keys(b);
|
728
|
+
if (typeof a == "object" && typeof b == "object") {
|
729
|
+
let aKeys = Object.keys(a), bKeys = Object.keys(b);
|
887
730
|
return aKeys.length === bKeys.length && aKeys.every((key) => deepEquals(a[key], b[key]));
|
888
731
|
}
|
889
|
-
return
|
732
|
+
return !1;
|
890
733
|
}
|
891
734
|
|
892
735
|
// src/editor/builder.ts
|
@@ -894,26 +737,17 @@ import "@prosekit/pm/model";
|
|
894
737
|
|
895
738
|
// src/utils/is-mark-absent.ts
|
896
739
|
function isMarkAbsent(node, from, to, markType, attrs) {
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
if (missing)
|
901
|
-
return false;
|
740
|
+
let mark = attrs ? markType.create(attrs) : markType, missing = !1;
|
741
|
+
return node.nodesBetween(from, to, (node2, pos, parent) => {
|
742
|
+
if (missing) return !1;
|
902
743
|
missing = !mark.isInSet(node2.marks) && !!parent && parent.type.allowsMarkType(markType);
|
903
|
-
});
|
904
|
-
return missing;
|
744
|
+
}), missing;
|
905
745
|
}
|
906
746
|
|
907
747
|
// src/utils/is-mark-active.ts
|
908
748
|
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
|
-
}
|
749
|
+
let { from, $from, to, empty } = state.selection, markType = getMarkType(state.schema, type);
|
750
|
+
return empty ? !!(attrs ? markType.create(attrs) : markType).isInSet(state.storedMarks || $from.marks()) : !isMarkAbsent(state.doc, from, to, markType, attrs);
|
917
751
|
}
|
918
752
|
|
919
753
|
// src/utils/type-assertion.ts
|
@@ -941,66 +775,48 @@ function isAllSelection(sel) {
|
|
941
775
|
|
942
776
|
// src/editor/builder.ts
|
943
777
|
function createNodeBuilder(getState, type) {
|
944
|
-
|
945
|
-
builder.isActive = (attrs) => {
|
946
|
-
|
947
|
-
return state ? isNodeActive(state, type, attrs) :
|
948
|
-
};
|
949
|
-
return builder;
|
778
|
+
let builder = (...args) => buildNode(type, args);
|
779
|
+
return builder.isActive = (attrs) => {
|
780
|
+
let state = getState();
|
781
|
+
return state ? isNodeActive(state, type, attrs) : !1;
|
782
|
+
}, builder;
|
950
783
|
}
|
951
784
|
function createMarkBuilder(getState, type) {
|
952
|
-
|
953
|
-
builder.isActive = (attrs) => {
|
954
|
-
|
955
|
-
return state ? isMarkActive(state, type, attrs) :
|
956
|
-
};
|
957
|
-
return builder;
|
785
|
+
let builder = (...args) => buildMark(type, args);
|
786
|
+
return builder.isActive = (attrs) => {
|
787
|
+
let state = getState();
|
788
|
+
return state ? isMarkActive(state, type, attrs) : !1;
|
789
|
+
}, builder;
|
958
790
|
}
|
959
791
|
function buildMark(type, args) {
|
960
|
-
|
792
|
+
let [attrs, children] = normalizeArgs(args);
|
961
793
|
return flattenChildren(type.schema, children, type.create(attrs));
|
962
794
|
}
|
963
795
|
function buildNode(type, args) {
|
964
|
-
|
965
|
-
|
966
|
-
if (!node) {
|
796
|
+
let [attrs, children] = normalizeArgs(args), node = type.createAndFill(attrs, flattenChildren(type.schema, children));
|
797
|
+
if (!node)
|
967
798
|
throw new ProseKitError(`Couldn't create node ${type.name}`);
|
968
|
-
}
|
969
799
|
return node;
|
970
800
|
}
|
971
801
|
function flattenChildren(schema, children, mark) {
|
972
|
-
|
973
|
-
for (
|
974
|
-
if (typeof child
|
975
|
-
|
976
|
-
|
977
|
-
}
|
978
|
-
} else if (Array.isArray(child)) {
|
802
|
+
let nodes = [];
|
803
|
+
for (let child of children)
|
804
|
+
if (typeof child == "string")
|
805
|
+
child && nodes.push(schema.text(child, mark ? [mark] : null));
|
806
|
+
else if (Array.isArray(child))
|
979
807
|
nodes.push(...flattenChildren(schema, child, mark));
|
980
|
-
|
808
|
+
else if (isProseMirrorNode(child))
|
981
809
|
nodes.push(mark ? child.mark(mark.addToSet(child.marks)) : child);
|
982
|
-
|
810
|
+
else
|
983
811
|
throw new ProseKitError(`Invalid node child: ${typeof child}`);
|
984
|
-
}
|
985
|
-
}
|
986
812
|
return nodes;
|
987
813
|
}
|
988
814
|
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
|
-
}
|
815
|
+
let [attrs, ...children] = args;
|
816
|
+
return isNodeChild(attrs) ? (children.unshift(attrs), [null, children]) : typeof attrs == "object" ? [attrs, children] : [null, children];
|
998
817
|
}
|
999
818
|
function isNodeChild(value) {
|
1000
|
-
|
1001
|
-
return false;
|
1002
|
-
}
|
1003
|
-
return typeof value === "string" || Array.isArray(value) || isProseMirrorNode(value);
|
819
|
+
return value ? typeof value == "string" || Array.isArray(value) || isProseMirrorNode(value) : !1;
|
1004
820
|
}
|
1005
821
|
|
1006
822
|
// src/facets/union-extension.ts
|
@@ -1017,69 +833,59 @@ var UnionExtensionImpl = class extends BaseExtension {
|
|
1017
833
|
*/
|
1018
834
|
createTree(priority) {
|
1019
835
|
var _a;
|
1020
|
-
|
1021
|
-
const extensions = [...this.extension];
|
836
|
+
let pri = (_a = this.priority) != null ? _a : priority, extensions = [...this.extension];
|
1022
837
|
extensions.sort((a, b) => {
|
1023
838
|
var _a2, _b;
|
1024
839
|
return ((_a2 = a.priority) != null ? _a2 : pri) - ((_b = b.priority) != null ? _b : pri);
|
1025
840
|
});
|
1026
|
-
|
1027
|
-
|
841
|
+
let children = extensions.map((ext) => ext.getTree(pri));
|
842
|
+
assert(children.length > 0);
|
843
|
+
let node = children[0];
|
844
|
+
for (let i = 1; i < children.length; i++)
|
845
|
+
node = unionFacetNode(node, children[i]);
|
846
|
+
return node;
|
1028
847
|
}
|
1029
848
|
};
|
1030
849
|
|
1031
850
|
// src/editor/union.ts
|
1032
851
|
function union(extension) {
|
1033
|
-
|
1034
|
-
return new UnionExtensionImpl(
|
852
|
+
let array = Array.isArray(extension) ? extension : [extension];
|
853
|
+
return assert(array.length > 0, "At least one extension is required"), new UnionExtensionImpl(
|
1035
854
|
array
|
1036
855
|
);
|
1037
856
|
}
|
1038
857
|
|
1039
858
|
// src/editor/editor.ts
|
1040
859
|
function createEditor(options) {
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
})
|
1051
|
-
]);
|
1052
|
-
}
|
1053
|
-
return Editor.create(new EditorInstance(extension));
|
860
|
+
let { defaultDoc, defaultHTML, defaultSelection } = options, extension = options.extension;
|
861
|
+
return (defaultDoc || defaultHTML) && (extension = union([
|
862
|
+
extension,
|
863
|
+
defineDefaultState({
|
864
|
+
defaultDoc,
|
865
|
+
defaultHTML,
|
866
|
+
defaultSelection
|
867
|
+
})
|
868
|
+
])), Editor.create(new EditorInstance(extension));
|
1054
869
|
}
|
1055
870
|
var EditorInstance = class {
|
1056
871
|
constructor(extension) {
|
1057
872
|
this.view = null;
|
1058
873
|
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;
|
874
|
+
this.mount = this.mount.bind(this), this.unmount = this.unmount.bind(this), this.tree = extension.getTree();
|
875
|
+
let payload = this.tree.getRootOutput(), schema = payload.schema, stateConfig = payload.state;
|
1065
876
|
assert(schema && stateConfig, "Schema must be defined");
|
1066
|
-
|
1067
|
-
this.cachedState = state
|
1068
|
-
|
1069
|
-
for (const [name, commandCreator] of Object.entries(payload.commands)) {
|
877
|
+
let state = EditorState2.create(stateConfig);
|
878
|
+
if (this.cachedState = state, payload.commands)
|
879
|
+
for (let [name, commandCreator] of Object.entries(payload.commands))
|
1070
880
|
this.defineCommand(name, commandCreator);
|
1071
|
-
|
1072
|
-
|
1073
|
-
this.directEditorProps = { state, ...payload.view };
|
1074
|
-
this.schema = this.directEditorProps.state.schema;
|
1075
|
-
const getState = () => this.getState();
|
881
|
+
this.directEditorProps = { state, ...payload.view }, this.schema = this.directEditorProps.state.schema;
|
882
|
+
let getState = () => this.getState();
|
1076
883
|
this.nodeBuilders = Object.fromEntries(
|
1077
884
|
Object.values(this.schema.nodes).map((type) => [
|
1078
885
|
type.name,
|
1079
886
|
createNodeBuilder(getState, type)
|
1080
887
|
])
|
1081
|
-
)
|
1082
|
-
this.markBuilders = Object.fromEntries(
|
888
|
+
), this.markBuilders = Object.fromEntries(
|
1083
889
|
Object.values(this.schema.marks).map((type) => [
|
1084
890
|
type.name,
|
1085
891
|
createMarkBuilder(getState, type)
|
@@ -1087,121 +893,85 @@ var EditorInstance = class {
|
|
1087
893
|
);
|
1088
894
|
}
|
1089
895
|
getState() {
|
1090
|
-
|
1091
|
-
this.cachedState = this.view.state;
|
1092
|
-
}
|
1093
|
-
return this.cachedState;
|
896
|
+
return this.view && (this.cachedState = this.view.state), this.cachedState;
|
1094
897
|
}
|
1095
898
|
updateExtension(extension, add) {
|
1096
899
|
var _a, _b, _c, _d;
|
1097
|
-
|
1098
|
-
if (!view || view.isDestroyed)
|
900
|
+
let view = this.view;
|
901
|
+
if (!view || view.isDestroyed)
|
1099
902
|
return;
|
1100
|
-
|
1101
|
-
|
1102
|
-
const payload = tree.getRootOutput();
|
1103
|
-
if (payload == null ? void 0 : payload.schema) {
|
903
|
+
let tree = extension.getTree(), payload = tree.getRootOutput();
|
904
|
+
if (payload != null && payload.schema)
|
1104
905
|
throw new ProseKitError("Schema cannot be changed");
|
1105
|
-
|
1106
|
-
if (payload == null ? void 0 : payload.view) {
|
906
|
+
if (payload != null && payload.view)
|
1107
907
|
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 : []];
|
908
|
+
let oldPayload = this.tree.getRootOutput(), oldPlugins = [...(_b = (_a = view.state) == null ? void 0 : _a.plugins) != null ? _b : []];
|
1111
909
|
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 : []];
|
910
|
+
let newPayload = this.tree.getRootOutput(), newPlugins = [...(_d = (_c = newPayload == null ? void 0 : newPayload.state) == null ? void 0 : _c.plugins) != null ? _d : []];
|
1114
911
|
if (!deepEquals(oldPlugins, newPlugins)) {
|
1115
|
-
|
912
|
+
let state = view.state.reconfigure({ plugins: newPlugins });
|
1116
913
|
view.updateState(state);
|
1117
914
|
}
|
1118
|
-
if (
|
1119
|
-
|
1120
|
-
|
1121
|
-
for (const name of names) {
|
915
|
+
if (newPayload != null && newPayload.commands && !deepEquals(oldPayload == null ? void 0 : oldPayload.commands, newPayload == null ? void 0 : newPayload.commands)) {
|
916
|
+
let commands = newPayload.commands, names = Object.keys(commands);
|
917
|
+
for (let name of names)
|
1122
918
|
this.defineCommand(name, commands[name]);
|
1123
|
-
}
|
1124
919
|
}
|
1125
920
|
}
|
1126
921
|
mount(place) {
|
1127
|
-
if (this.view)
|
922
|
+
if (this.view)
|
1128
923
|
throw new ProseKitError("Editor is already mounted");
|
1129
|
-
|
1130
|
-
if (!place) {
|
924
|
+
if (!place)
|
1131
925
|
throw new ProseKitError("Can't mount editor without a place");
|
1132
|
-
}
|
1133
926
|
this.view = new EditorView({ mount: place }, this.directEditorProps);
|
1134
927
|
}
|
1135
928
|
unmount() {
|
1136
|
-
if (!this.view)
|
929
|
+
if (!this.view)
|
1137
930
|
throw new ProseKitError("Editor is not mounted yet");
|
1138
|
-
|
1139
|
-
this.view.destroy();
|
1140
|
-
this.view = null;
|
931
|
+
this.view.destroy(), this.view = null;
|
1141
932
|
}
|
1142
933
|
get mounted() {
|
1143
934
|
return !!this.view && !this.view.isDestroyed;
|
1144
935
|
}
|
1145
936
|
get assertView() {
|
1146
|
-
if (!this.view)
|
937
|
+
if (!this.view)
|
1147
938
|
throw new ProseKitError("Editor is not mounted");
|
1148
|
-
}
|
1149
939
|
return this.view;
|
1150
940
|
}
|
1151
941
|
definePlugins(plugins) {
|
1152
|
-
|
1153
|
-
const state = view.state;
|
1154
|
-
const newPlugins = [...plugins, ...state.plugins];
|
1155
|
-
const newState = state.reconfigure({ plugins: newPlugins });
|
942
|
+
let view = this.assertView, state = view.state, newPlugins = [...plugins, ...state.plugins], newState = state.reconfigure({ plugins: newPlugins });
|
1156
943
|
view.setProps({ state: newState });
|
1157
944
|
}
|
1158
945
|
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 });
|
946
|
+
let view = this.view;
|
947
|
+
if (!view) return;
|
948
|
+
let state = view.state, newPlugins = state.plugins.filter((p) => !plugins.includes(p)), newState = state.reconfigure({ plugins: newPlugins });
|
1165
949
|
view.setProps({ state: newState });
|
1166
950
|
}
|
1167
951
|
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);
|
952
|
+
let applier = (...args) => {
|
953
|
+
let view = this.view;
|
954
|
+
return view ? commandCreator(...args)(view.state, view.dispatch.bind(view), view) : !1;
|
1175
955
|
};
|
1176
956
|
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;
|
957
|
+
let view = this.view;
|
958
|
+
return view ? commandCreator(...args)(view.state, void 0, view) : !1;
|
959
|
+
}, this.commandAppliers[name] = applier;
|
1185
960
|
}
|
1186
961
|
removeCommand(name) {
|
1187
962
|
delete this.commandAppliers[name];
|
1188
963
|
}
|
1189
|
-
}
|
1190
|
-
var Editor = class _Editor {
|
964
|
+
}, Editor = class _Editor {
|
1191
965
|
constructor(instance) {
|
1192
966
|
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);
|
967
|
+
this.instance = instance, this.mount = this.mount.bind(this), this.unmount = this.unmount.bind(this), this.use = this.use.bind(this);
|
1197
968
|
}
|
1198
969
|
/**
|
1199
970
|
* @internal
|
1200
971
|
*/
|
1201
972
|
static create(instance) {
|
1202
|
-
if (!(instance instanceof EditorInstance))
|
973
|
+
if (!(instance instanceof EditorInstance))
|
1203
974
|
throw new TypeError("Invalid EditorInstance");
|
1204
|
-
}
|
1205
975
|
return new _Editor(instance);
|
1206
976
|
}
|
1207
977
|
/**
|
@@ -1230,54 +1000,47 @@ var Editor = class _Editor {
|
|
1230
1000
|
*/
|
1231
1001
|
get focused() {
|
1232
1002
|
var _a, _b;
|
1233
|
-
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b :
|
1003
|
+
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b : !1;
|
1234
1004
|
}
|
1235
1005
|
/**
|
1236
1006
|
* Mount the editor to the given HTML element.
|
1237
1007
|
* Pass `null` or `undefined` to unmount the editor.
|
1238
1008
|
*/
|
1239
1009
|
mount(place) {
|
1240
|
-
if (!place)
|
1010
|
+
if (!place)
|
1241
1011
|
return this.unmount();
|
1242
|
-
|
1243
|
-
this.instance.mount(place);
|
1244
|
-
this.afterMounted.forEach((callback) => callback());
|
1012
|
+
this.instance.mount(place), this.afterMounted.forEach((callback) => callback());
|
1245
1013
|
}
|
1246
1014
|
/**
|
1247
1015
|
* Unmount the editor. This is equivalent to `mount(null)`.
|
1248
1016
|
*/
|
1249
1017
|
unmount() {
|
1250
|
-
|
1251
|
-
this.instance.unmount();
|
1252
|
-
}
|
1018
|
+
this.mounted && this.instance.unmount();
|
1253
1019
|
}
|
1254
1020
|
/**
|
1255
1021
|
* Focus the editor.
|
1256
1022
|
*/
|
1257
1023
|
focus() {
|
1258
1024
|
var _a;
|
1259
|
-
(_a = this.instance.view) == null
|
1025
|
+
(_a = this.instance.view) == null || _a.focus();
|
1260
1026
|
}
|
1261
1027
|
/**
|
1262
1028
|
* Blur the editor.
|
1263
1029
|
*/
|
1264
1030
|
blur() {
|
1265
1031
|
var _a;
|
1266
|
-
(_a = this.instance.view) == null
|
1032
|
+
(_a = this.instance.view) == null || _a.dom.blur();
|
1267
1033
|
}
|
1268
1034
|
use(extension) {
|
1269
1035
|
if (!this.mounted) {
|
1270
|
-
let lazyRemove = null
|
1271
|
-
const lazyCreate = () => {
|
1036
|
+
let lazyRemove = null, lazyCreate = () => {
|
1272
1037
|
lazyRemove = this.use(extension);
|
1273
1038
|
};
|
1274
|
-
this.afterMounted.push(lazyCreate)
|
1275
|
-
|
1276
|
-
lazyRemove == null ? void 0 : lazyRemove();
|
1039
|
+
return this.afterMounted.push(lazyCreate), () => {
|
1040
|
+
lazyRemove == null || lazyRemove();
|
1277
1041
|
};
|
1278
1042
|
}
|
1279
|
-
this.instance.updateExtension(extension,
|
1280
|
-
return () => this.instance.updateExtension(extension, false);
|
1043
|
+
return this.instance.updateExtension(extension, !0), () => this.instance.updateExtension(extension, !1);
|
1281
1044
|
}
|
1282
1045
|
get state() {
|
1283
1046
|
return this.instance.getState();
|
@@ -1292,9 +1055,8 @@ var Editor = class _Editor {
|
|
1292
1055
|
|
1293
1056
|
// src/editor/with-priority.ts
|
1294
1057
|
function withPriority(extension, priority) {
|
1295
|
-
|
1296
|
-
result.priority = priority;
|
1297
|
-
return result;
|
1058
|
+
let result = union(extension);
|
1059
|
+
return result.priority = priority, result;
|
1298
1060
|
}
|
1299
1061
|
|
1300
1062
|
// src/commands/insert-text.ts
|
@@ -1303,21 +1065,13 @@ function insertText({
|
|
1303
1065
|
from,
|
1304
1066
|
to
|
1305
1067
|
}) {
|
1306
|
-
return (state, dispatch) =>
|
1307
|
-
if (text) {
|
1308
|
-
dispatch == null ? void 0 : dispatch(state.tr.insertText(text, from, to));
|
1309
|
-
}
|
1310
|
-
return true;
|
1311
|
-
};
|
1068
|
+
return (state, dispatch) => (text && (dispatch == null || dispatch(state.tr.insertText(text, from, to))), !0);
|
1312
1069
|
}
|
1313
1070
|
|
1314
1071
|
// src/commands/select-all.ts
|
1315
1072
|
import { AllSelection as AllSelection2 } from "@prosekit/pm/state";
|
1316
1073
|
function selectAll() {
|
1317
|
-
return (state, dispatch) =>
|
1318
|
-
dispatch == null ? void 0 : dispatch(state.tr.setSelection(new AllSelection2(state.doc)));
|
1319
|
-
return true;
|
1320
|
-
};
|
1074
|
+
return (state, dispatch) => (dispatch == null || dispatch(state.tr.setSelection(new AllSelection2(state.doc))), !0);
|
1321
1075
|
}
|
1322
1076
|
|
1323
1077
|
// src/commands/wrap.ts
|
@@ -1329,26 +1083,18 @@ function wrap({
|
|
1329
1083
|
attrs
|
1330
1084
|
}) {
|
1331
1085
|
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;
|
1086
|
+
let { $from, $to } = state.selection, range = $from.blockRange($to);
|
1087
|
+
if (!range) return !1;
|
1088
|
+
let wrapping = findWrapping(range, nodeType, attrs);
|
1089
|
+
return wrapping ? (dispatch == null || dispatch(state.tr.wrap(range, wrapping)), !0) : !1;
|
1341
1090
|
};
|
1342
1091
|
}
|
1343
1092
|
|
1344
1093
|
// src/facets/command.ts
|
1345
1094
|
var commandFacet = defineFacet({
|
1346
|
-
reducer: (inputs) => {
|
1347
|
-
const commands = Object.assign({}, ...inputs);
|
1348
|
-
return { commands };
|
1349
|
-
},
|
1095
|
+
reducer: (inputs) => ({ commands: Object.assign({}, ...inputs) }),
|
1350
1096
|
parent: rootFacet,
|
1351
|
-
singleton:
|
1097
|
+
singleton: !0
|
1352
1098
|
});
|
1353
1099
|
|
1354
1100
|
// src/extensions/command.ts
|
@@ -1359,6 +1105,7 @@ function defineBaseCommands() {
|
|
1359
1105
|
return defineCommands({
|
1360
1106
|
insertText,
|
1361
1107
|
insertNode,
|
1108
|
+
removeNode,
|
1362
1109
|
wrap,
|
1363
1110
|
setBlockType,
|
1364
1111
|
setNodeAttrs,
|
@@ -1377,54 +1124,34 @@ import OrderedMap2 from "orderedmap";
|
|
1377
1124
|
var schemaSpecFacet = defineFacet({
|
1378
1125
|
reducer: (specs) => {
|
1379
1126
|
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
|
-
}
|
1127
|
+
let nodes = OrderedMap2.from({}), marks = OrderedMap2.from({}), topNode;
|
1128
|
+
for (let spec of specs)
|
1129
|
+
nodes = nodes.append(spec.nodes), marks = marks.append((_a = spec.marks) != null ? _a : {}), topNode = topNode != null ? topNode : spec.topNode;
|
1388
1130
|
return { nodes, marks, topNode };
|
1389
1131
|
},
|
1390
1132
|
parent: schemaFacet,
|
1391
|
-
singleton:
|
1133
|
+
singleton: !0
|
1392
1134
|
});
|
1393
1135
|
|
1394
1136
|
// src/utils/is-element.ts
|
1395
|
-
var hasElement = typeof Element
|
1137
|
+
var hasElement = typeof Element != "undefined";
|
1396
1138
|
function isElement(value) {
|
1397
1139
|
return hasElement && value instanceof Element;
|
1398
1140
|
}
|
1399
1141
|
|
1400
|
-
// src/utils/is-not-null.ts
|
1401
|
-
function isNotNull(value) {
|
1402
|
-
return value != null;
|
1403
|
-
}
|
1404
|
-
|
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) {
|
1453
|
-
return dom;
|
1454
|
-
}
|
1455
|
-
const [key, value] = attrDOM;
|
1456
|
-
if (!key) {
|
1172
|
+
let attrDOM = toDOM(node.attrs[attr]);
|
1173
|
+
if (!attrDOM)
|
1457
1174
|
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;
|
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,
|