@tiptap/core 2.0.0-beta.173 → 2.0.0-beta.176
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/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +3 -0
- package/dist/packages/core/src/index.d.ts +1 -0
- package/dist/packages/core/src/types.d.ts +2 -0
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -1
- package/dist/tiptap-core.cjs.js +34 -25
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +34 -26
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +34 -25
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/Editor.ts +4 -3
- package/src/NodeView.ts +6 -2
- package/src/commands/setTextSelection.ts +1 -1
- package/src/extensions/clipboardTextSerializer.ts +2 -2
- package/src/extensions/keymap.ts +0 -2
- package/src/helpers/generateText.ts +2 -2
- package/src/helpers/getMarkRange.ts +6 -2
- package/src/helpers/getTextBetween.ts +1 -0
- package/src/helpers/{getTextSeralizersFromSchema.ts → getTextSerializersFromSchema.ts} +1 -1
- package/src/helpers/resolveFocusPosition.ts +18 -10
- package/src/index.ts +1 -0
- package/src/types.ts +2 -0
- package/src/utilities/createStyleTag.ts +5 -1
- package/dist/packages/core/src/helpers/getTextSeralizersFromSchema.d.ts +0 -3
package/dist/tiptap-core.umd.js
CHANGED
|
@@ -155,6 +155,7 @@
|
|
|
155
155
|
pos,
|
|
156
156
|
parent,
|
|
157
157
|
index,
|
|
158
|
+
range,
|
|
158
159
|
});
|
|
159
160
|
}
|
|
160
161
|
else if (node.isText) {
|
|
@@ -169,7 +170,7 @@
|
|
|
169
170
|
return text;
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
function
|
|
173
|
+
function getTextSerializersFromSchema(schema) {
|
|
173
174
|
return Object.fromEntries(Object
|
|
174
175
|
.entries(schema.nodes)
|
|
175
176
|
.filter(([, node]) => node.spec.toText)
|
|
@@ -190,7 +191,7 @@
|
|
|
190
191
|
const { ranges } = selection;
|
|
191
192
|
const from = Math.min(...ranges.map(range => range.$from.pos));
|
|
192
193
|
const to = Math.max(...ranges.map(range => range.$to.pos));
|
|
193
|
-
const textSerializers =
|
|
194
|
+
const textSerializers = getTextSerializersFromSchema(schema);
|
|
194
195
|
const range = { from, to };
|
|
195
196
|
return getTextBetween(doc, range, {
|
|
196
197
|
textSerializers,
|
|
@@ -402,7 +403,10 @@
|
|
|
402
403
|
if (!$pos || !type) {
|
|
403
404
|
return;
|
|
404
405
|
}
|
|
405
|
-
|
|
406
|
+
let start = $pos.parent.childAfter($pos.parentOffset);
|
|
407
|
+
if ($pos.parentOffset === start.offset && start.offset !== 0) {
|
|
408
|
+
start = $pos.parent.childBefore($pos.parentOffset);
|
|
409
|
+
}
|
|
406
410
|
if (!start.node) {
|
|
407
411
|
return;
|
|
408
412
|
}
|
|
@@ -410,7 +414,7 @@
|
|
|
410
414
|
if (!mark) {
|
|
411
415
|
return;
|
|
412
416
|
}
|
|
413
|
-
let startIndex =
|
|
417
|
+
let startIndex = start.index;
|
|
414
418
|
let startPos = $pos.start() + start.offset;
|
|
415
419
|
let endIndex = startIndex + 1;
|
|
416
420
|
let endPos = startPos + start.node.nodeSize;
|
|
@@ -506,21 +510,20 @@
|
|
|
506
510
|
if (!position) {
|
|
507
511
|
return null;
|
|
508
512
|
}
|
|
513
|
+
const selectionAtStart = prosemirrorState.Selection.atStart(doc);
|
|
514
|
+
const selectionAtEnd = prosemirrorState.Selection.atEnd(doc);
|
|
509
515
|
if (position === 'start' || position === true) {
|
|
510
|
-
return
|
|
516
|
+
return selectionAtStart;
|
|
511
517
|
}
|
|
512
518
|
if (position === 'end') {
|
|
513
|
-
return
|
|
519
|
+
return selectionAtEnd;
|
|
514
520
|
}
|
|
521
|
+
const minPos = selectionAtStart.from;
|
|
522
|
+
const maxPos = selectionAtEnd.to;
|
|
515
523
|
if (position === 'all') {
|
|
516
|
-
return prosemirrorState.TextSelection.create(doc, 0, doc.content.size);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
const minPos = prosemirrorState.Selection.atStart(doc).from;
|
|
520
|
-
const maxPos = prosemirrorState.Selection.atEnd(doc).to;
|
|
521
|
-
const resolvedFrom = minMax(position, minPos, maxPos);
|
|
522
|
-
const resolvedEnd = minMax(position, minPos, maxPos);
|
|
523
|
-
return prosemirrorState.TextSelection.create(doc, resolvedFrom, resolvedEnd);
|
|
524
|
+
return prosemirrorState.TextSelection.create(doc, minMax(0, minPos, maxPos), minMax(doc.content.size, minPos, maxPos));
|
|
525
|
+
}
|
|
526
|
+
return prosemirrorState.TextSelection.create(doc, minMax(position, minPos, maxPos), minMax(position, minPos, maxPos));
|
|
524
527
|
}
|
|
525
528
|
|
|
526
529
|
const focus = (position = null, options) => ({ editor, view, tr, dispatch, }) => {
|
|
@@ -1192,7 +1195,7 @@
|
|
|
1192
1195
|
? { from: position, to: position }
|
|
1193
1196
|
: position;
|
|
1194
1197
|
const minPos = prosemirrorState.TextSelection.atStart(doc).from;
|
|
1195
|
-
const maxPos = doc.
|
|
1198
|
+
const maxPos = prosemirrorState.TextSelection.atEnd(doc).to;
|
|
1196
1199
|
const resolvedFrom = minMax(from, minPos, maxPos);
|
|
1197
1200
|
const resolvedEnd = minMax(to, minPos, maxPos);
|
|
1198
1201
|
const selection = prosemirrorState.TextSelection.create(doc, resolvedFrom, resolvedEnd);
|
|
@@ -2097,8 +2100,6 @@
|
|
|
2097
2100
|
};
|
|
2098
2101
|
const pcKeymap = {
|
|
2099
2102
|
...baseKeymap,
|
|
2100
|
-
Home: () => this.editor.commands.selectTextblockStart(),
|
|
2101
|
-
End: () => this.editor.commands.selectTextblockEnd(),
|
|
2102
2103
|
};
|
|
2103
2104
|
const macKeymap = {
|
|
2104
2105
|
...baseKeymap,
|
|
@@ -2257,12 +2258,15 @@
|
|
|
2257
2258
|
return JSON.stringify(defaultContent) === JSON.stringify(content);
|
|
2258
2259
|
}
|
|
2259
2260
|
|
|
2260
|
-
function createStyleTag(style) {
|
|
2261
|
+
function createStyleTag(style, nonce) {
|
|
2261
2262
|
const tipTapStyleTag = document.querySelector('style[data-tiptap-style]');
|
|
2262
2263
|
if (tipTapStyleTag !== null) {
|
|
2263
2264
|
return tipTapStyleTag;
|
|
2264
2265
|
}
|
|
2265
2266
|
const styleNode = document.createElement('style');
|
|
2267
|
+
if (nonce) {
|
|
2268
|
+
styleNode.setAttribute('nonce', nonce);
|
|
2269
|
+
}
|
|
2266
2270
|
styleNode.setAttribute('data-tiptap-style', '');
|
|
2267
2271
|
styleNode.innerHTML = style;
|
|
2268
2272
|
document.getElementsByTagName('head')[0].appendChild(styleNode);
|
|
@@ -3218,6 +3222,7 @@ img.ProseMirror-separator {
|
|
|
3218
3222
|
element: document.createElement('div'),
|
|
3219
3223
|
content: '',
|
|
3220
3224
|
injectCSS: true,
|
|
3225
|
+
injectNonce: undefined,
|
|
3221
3226
|
extensions: [],
|
|
3222
3227
|
autofocus: false,
|
|
3223
3228
|
editable: true,
|
|
@@ -3289,7 +3294,7 @@ img.ProseMirror-separator {
|
|
|
3289
3294
|
*/
|
|
3290
3295
|
injectCSS() {
|
|
3291
3296
|
if (this.options.injectCSS && document) {
|
|
3292
|
-
this.css = createStyleTag(style);
|
|
3297
|
+
this.css = createStyleTag(style, this.options.injectNonce);
|
|
3293
3298
|
}
|
|
3294
3299
|
}
|
|
3295
3300
|
/**
|
|
@@ -3520,7 +3525,7 @@ img.ProseMirror-separator {
|
|
|
3520
3525
|
blockSeparator,
|
|
3521
3526
|
textSerializers: {
|
|
3522
3527
|
...textSerializers,
|
|
3523
|
-
...
|
|
3528
|
+
...getTextSerializersFromSchema(this.schema),
|
|
3524
3529
|
},
|
|
3525
3530
|
});
|
|
3526
3531
|
}
|
|
@@ -3716,7 +3721,7 @@ img.ProseMirror-separator {
|
|
|
3716
3721
|
return null;
|
|
3717
3722
|
}
|
|
3718
3723
|
onDragStart(event) {
|
|
3719
|
-
var _a, _b, _c;
|
|
3724
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3720
3725
|
const { view } = this.editor;
|
|
3721
3726
|
const target = event.target;
|
|
3722
3727
|
// get the drag handle element
|
|
@@ -3735,10 +3740,13 @@ img.ProseMirror-separator {
|
|
|
3735
3740
|
if (this.dom !== dragHandle) {
|
|
3736
3741
|
const domBox = this.dom.getBoundingClientRect();
|
|
3737
3742
|
const handleBox = dragHandle.getBoundingClientRect();
|
|
3738
|
-
|
|
3739
|
-
|
|
3743
|
+
// In React, we have to go through nativeEvent to reach offsetX/offsetY.
|
|
3744
|
+
const offsetX = (_c = event.offsetX) !== null && _c !== void 0 ? _c : (_d = event.nativeEvent) === null || _d === void 0 ? void 0 : _d.offsetX;
|
|
3745
|
+
const offsetY = (_e = event.offsetY) !== null && _e !== void 0 ? _e : (_f = event.nativeEvent) === null || _f === void 0 ? void 0 : _f.offsetY;
|
|
3746
|
+
x = handleBox.x - domBox.x + offsetX;
|
|
3747
|
+
y = handleBox.y - domBox.y + offsetY;
|
|
3740
3748
|
}
|
|
3741
|
-
(
|
|
3749
|
+
(_g = event.dataTransfer) === null || _g === void 0 ? void 0 : _g.setDragImage(this.dom, x, y);
|
|
3742
3750
|
// we need to tell ProseMirror that we want to move the whole node
|
|
3743
3751
|
// so we create a NodeSelection
|
|
3744
3752
|
const selection = prosemirrorState.NodeSelection.create(view.state.doc, this.getPos());
|
|
@@ -4256,7 +4264,7 @@ img.ProseMirror-separator {
|
|
|
4256
4264
|
blockSeparator,
|
|
4257
4265
|
textSerializers: {
|
|
4258
4266
|
...textSerializers,
|
|
4259
|
-
...
|
|
4267
|
+
...getTextSerializersFromSchema(schema),
|
|
4260
4268
|
},
|
|
4261
4269
|
});
|
|
4262
4270
|
}
|
|
@@ -4446,6 +4454,7 @@ img.ProseMirror-separator {
|
|
|
4446
4454
|
exports.getSchema = getSchema;
|
|
4447
4455
|
exports.getText = getText;
|
|
4448
4456
|
exports.getTextBetween = getTextBetween;
|
|
4457
|
+
exports.getTextSerializersFromSchema = getTextSerializersFromSchema;
|
|
4449
4458
|
exports.inputRulesPlugin = inputRulesPlugin;
|
|
4450
4459
|
exports.isActive = isActive;
|
|
4451
4460
|
exports.isList = isList;
|