@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.esm.js
CHANGED
|
@@ -157,6 +157,7 @@ function getTextBetween(startNode, range, options) {
|
|
|
157
157
|
pos,
|
|
158
158
|
parent,
|
|
159
159
|
index,
|
|
160
|
+
range,
|
|
160
161
|
});
|
|
161
162
|
}
|
|
162
163
|
else if (node.isText) {
|
|
@@ -171,7 +172,7 @@ function getTextBetween(startNode, range, options) {
|
|
|
171
172
|
return text;
|
|
172
173
|
}
|
|
173
174
|
|
|
174
|
-
function
|
|
175
|
+
function getTextSerializersFromSchema(schema) {
|
|
175
176
|
return Object.fromEntries(Object
|
|
176
177
|
.entries(schema.nodes)
|
|
177
178
|
.filter(([, node]) => node.spec.toText)
|
|
@@ -192,7 +193,7 @@ const ClipboardTextSerializer = Extension.create({
|
|
|
192
193
|
const { ranges } = selection;
|
|
193
194
|
const from = Math.min(...ranges.map(range => range.$from.pos));
|
|
194
195
|
const to = Math.max(...ranges.map(range => range.$to.pos));
|
|
195
|
-
const textSerializers =
|
|
196
|
+
const textSerializers = getTextSerializersFromSchema(schema);
|
|
196
197
|
const range = { from, to };
|
|
197
198
|
return getTextBetween(doc, range, {
|
|
198
199
|
textSerializers,
|
|
@@ -404,7 +405,10 @@ function getMarkRange($pos, type, attributes = {}) {
|
|
|
404
405
|
if (!$pos || !type) {
|
|
405
406
|
return;
|
|
406
407
|
}
|
|
407
|
-
|
|
408
|
+
let start = $pos.parent.childAfter($pos.parentOffset);
|
|
409
|
+
if ($pos.parentOffset === start.offset && start.offset !== 0) {
|
|
410
|
+
start = $pos.parent.childBefore($pos.parentOffset);
|
|
411
|
+
}
|
|
408
412
|
if (!start.node) {
|
|
409
413
|
return;
|
|
410
414
|
}
|
|
@@ -412,7 +416,7 @@ function getMarkRange($pos, type, attributes = {}) {
|
|
|
412
416
|
if (!mark) {
|
|
413
417
|
return;
|
|
414
418
|
}
|
|
415
|
-
let startIndex =
|
|
419
|
+
let startIndex = start.index;
|
|
416
420
|
let startPos = $pos.start() + start.offset;
|
|
417
421
|
let endIndex = startIndex + 1;
|
|
418
422
|
let endPos = startPos + start.node.nodeSize;
|
|
@@ -508,21 +512,20 @@ function resolveFocusPosition(doc, position = null) {
|
|
|
508
512
|
if (!position) {
|
|
509
513
|
return null;
|
|
510
514
|
}
|
|
515
|
+
const selectionAtStart = Selection.atStart(doc);
|
|
516
|
+
const selectionAtEnd = Selection.atEnd(doc);
|
|
511
517
|
if (position === 'start' || position === true) {
|
|
512
|
-
return
|
|
518
|
+
return selectionAtStart;
|
|
513
519
|
}
|
|
514
520
|
if (position === 'end') {
|
|
515
|
-
return
|
|
521
|
+
return selectionAtEnd;
|
|
516
522
|
}
|
|
523
|
+
const minPos = selectionAtStart.from;
|
|
524
|
+
const maxPos = selectionAtEnd.to;
|
|
517
525
|
if (position === 'all') {
|
|
518
|
-
return TextSelection.create(doc, 0, doc.content.size);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
const minPos = Selection.atStart(doc).from;
|
|
522
|
-
const maxPos = Selection.atEnd(doc).to;
|
|
523
|
-
const resolvedFrom = minMax(position, minPos, maxPos);
|
|
524
|
-
const resolvedEnd = minMax(position, minPos, maxPos);
|
|
525
|
-
return TextSelection.create(doc, resolvedFrom, resolvedEnd);
|
|
526
|
+
return TextSelection.create(doc, minMax(0, minPos, maxPos), minMax(doc.content.size, minPos, maxPos));
|
|
527
|
+
}
|
|
528
|
+
return TextSelection.create(doc, minMax(position, minPos, maxPos), minMax(position, minPos, maxPos));
|
|
526
529
|
}
|
|
527
530
|
|
|
528
531
|
const focus = (position = null, options) => ({ editor, view, tr, dispatch, }) => {
|
|
@@ -1194,7 +1197,7 @@ const setTextSelection = position => ({ tr, dispatch }) => {
|
|
|
1194
1197
|
? { from: position, to: position }
|
|
1195
1198
|
: position;
|
|
1196
1199
|
const minPos = TextSelection.atStart(doc).from;
|
|
1197
|
-
const maxPos = doc.
|
|
1200
|
+
const maxPos = TextSelection.atEnd(doc).to;
|
|
1198
1201
|
const resolvedFrom = minMax(from, minPos, maxPos);
|
|
1199
1202
|
const resolvedEnd = minMax(to, minPos, maxPos);
|
|
1200
1203
|
const selection = TextSelection.create(doc, resolvedFrom, resolvedEnd);
|
|
@@ -2099,8 +2102,6 @@ const Keymap = Extension.create({
|
|
|
2099
2102
|
};
|
|
2100
2103
|
const pcKeymap = {
|
|
2101
2104
|
...baseKeymap,
|
|
2102
|
-
Home: () => this.editor.commands.selectTextblockStart(),
|
|
2103
|
-
End: () => this.editor.commands.selectTextblockEnd(),
|
|
2104
2105
|
};
|
|
2105
2106
|
const macKeymap = {
|
|
2106
2107
|
...baseKeymap,
|
|
@@ -2259,12 +2260,15 @@ function isNodeEmpty(node) {
|
|
|
2259
2260
|
return JSON.stringify(defaultContent) === JSON.stringify(content);
|
|
2260
2261
|
}
|
|
2261
2262
|
|
|
2262
|
-
function createStyleTag(style) {
|
|
2263
|
+
function createStyleTag(style, nonce) {
|
|
2263
2264
|
const tipTapStyleTag = document.querySelector('style[data-tiptap-style]');
|
|
2264
2265
|
if (tipTapStyleTag !== null) {
|
|
2265
2266
|
return tipTapStyleTag;
|
|
2266
2267
|
}
|
|
2267
2268
|
const styleNode = document.createElement('style');
|
|
2269
|
+
if (nonce) {
|
|
2270
|
+
styleNode.setAttribute('nonce', nonce);
|
|
2271
|
+
}
|
|
2268
2272
|
styleNode.setAttribute('data-tiptap-style', '');
|
|
2269
2273
|
styleNode.innerHTML = style;
|
|
2270
2274
|
document.getElementsByTagName('head')[0].appendChild(styleNode);
|
|
@@ -3220,6 +3224,7 @@ class Editor extends EventEmitter {
|
|
|
3220
3224
|
element: document.createElement('div'),
|
|
3221
3225
|
content: '',
|
|
3222
3226
|
injectCSS: true,
|
|
3227
|
+
injectNonce: undefined,
|
|
3223
3228
|
extensions: [],
|
|
3224
3229
|
autofocus: false,
|
|
3225
3230
|
editable: true,
|
|
@@ -3291,7 +3296,7 @@ class Editor extends EventEmitter {
|
|
|
3291
3296
|
*/
|
|
3292
3297
|
injectCSS() {
|
|
3293
3298
|
if (this.options.injectCSS && document) {
|
|
3294
|
-
this.css = createStyleTag(style);
|
|
3299
|
+
this.css = createStyleTag(style, this.options.injectNonce);
|
|
3295
3300
|
}
|
|
3296
3301
|
}
|
|
3297
3302
|
/**
|
|
@@ -3522,7 +3527,7 @@ class Editor extends EventEmitter {
|
|
|
3522
3527
|
blockSeparator,
|
|
3523
3528
|
textSerializers: {
|
|
3524
3529
|
...textSerializers,
|
|
3525
|
-
...
|
|
3530
|
+
...getTextSerializersFromSchema(this.schema),
|
|
3526
3531
|
},
|
|
3527
3532
|
});
|
|
3528
3533
|
}
|
|
@@ -3718,7 +3723,7 @@ class NodeView {
|
|
|
3718
3723
|
return null;
|
|
3719
3724
|
}
|
|
3720
3725
|
onDragStart(event) {
|
|
3721
|
-
var _a, _b, _c;
|
|
3726
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3722
3727
|
const { view } = this.editor;
|
|
3723
3728
|
const target = event.target;
|
|
3724
3729
|
// get the drag handle element
|
|
@@ -3737,10 +3742,13 @@ class NodeView {
|
|
|
3737
3742
|
if (this.dom !== dragHandle) {
|
|
3738
3743
|
const domBox = this.dom.getBoundingClientRect();
|
|
3739
3744
|
const handleBox = dragHandle.getBoundingClientRect();
|
|
3740
|
-
|
|
3741
|
-
|
|
3745
|
+
// In React, we have to go through nativeEvent to reach offsetX/offsetY.
|
|
3746
|
+
const offsetX = (_c = event.offsetX) !== null && _c !== void 0 ? _c : (_d = event.nativeEvent) === null || _d === void 0 ? void 0 : _d.offsetX;
|
|
3747
|
+
const offsetY = (_e = event.offsetY) !== null && _e !== void 0 ? _e : (_f = event.nativeEvent) === null || _f === void 0 ? void 0 : _f.offsetY;
|
|
3748
|
+
x = handleBox.x - domBox.x + offsetX;
|
|
3749
|
+
y = handleBox.y - domBox.y + offsetY;
|
|
3742
3750
|
}
|
|
3743
|
-
(
|
|
3751
|
+
(_g = event.dataTransfer) === null || _g === void 0 ? void 0 : _g.setDragImage(this.dom, x, y);
|
|
3744
3752
|
// we need to tell ProseMirror that we want to move the whole node
|
|
3745
3753
|
// so we create a NodeSelection
|
|
3746
3754
|
const selection = NodeSelection.create(view.state.doc, this.getPos());
|
|
@@ -4258,7 +4266,7 @@ function generateText(doc, extensions, options) {
|
|
|
4258
4266
|
blockSeparator,
|
|
4259
4267
|
textSerializers: {
|
|
4260
4268
|
...textSerializers,
|
|
4261
|
-
...
|
|
4269
|
+
...getTextSerializersFromSchema(schema),
|
|
4262
4270
|
},
|
|
4263
4271
|
});
|
|
4264
4272
|
}
|
|
@@ -4413,5 +4421,5 @@ function posToDOMRect(view, from, to) {
|
|
|
4413
4421
|
};
|
|
4414
4422
|
}
|
|
4415
4423
|
|
|
4416
|
-
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, defaultBlockAt, escapeForRegEx, extensions, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, inputRulesPlugin, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, markInputRule, markPasteRule, mergeAttributes, nodeInputRule, pasteRulesPlugin, posToDOMRect, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
|
|
4424
|
+
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, defaultBlockAt, escapeForRegEx, extensions, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, getTextSerializersFromSchema, inputRulesPlugin, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, markInputRule, markPasteRule, mergeAttributes, nodeInputRule, pasteRulesPlugin, posToDOMRect, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
|
|
4417
4425
|
//# sourceMappingURL=tiptap-core.esm.js.map
|