@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
|
@@ -43,6 +43,7 @@ export * from './helpers/getNodeAttributes';
|
|
|
43
43
|
export * from './helpers/getNodeType';
|
|
44
44
|
export * from './helpers/getText';
|
|
45
45
|
export * from './helpers/getTextBetween';
|
|
46
|
+
export * from './helpers/getTextSerializersFromSchema';
|
|
46
47
|
export * from './helpers/isActive';
|
|
47
48
|
export * from './helpers/isList';
|
|
48
49
|
export * from './helpers/isMarkActive';
|
|
@@ -53,6 +53,7 @@ export interface EditorOptions {
|
|
|
53
53
|
content: Content;
|
|
54
54
|
extensions: Extensions;
|
|
55
55
|
injectCSS: boolean;
|
|
56
|
+
injectNonce: string | undefined;
|
|
56
57
|
autofocus: FocusPosition;
|
|
57
58
|
editable: boolean;
|
|
58
59
|
editorProps: EditorProps;
|
|
@@ -204,6 +205,7 @@ export declare type TextSerializer = (props: {
|
|
|
204
205
|
pos: number;
|
|
205
206
|
parent: ProseMirrorNode;
|
|
206
207
|
index: number;
|
|
208
|
+
range: Range;
|
|
207
209
|
}) => string;
|
|
208
210
|
export declare type ExtendedRegExpMatchArray = RegExpMatchArray & {
|
|
209
211
|
data?: Record<string, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createStyleTag(style: string): HTMLStyleElement;
|
|
1
|
+
export declare function createStyleTag(style: string, nonce?: string): HTMLStyleElement;
|
package/dist/tiptap-core.cjs.js
CHANGED
|
@@ -161,6 +161,7 @@ function getTextBetween(startNode, range, options) {
|
|
|
161
161
|
pos,
|
|
162
162
|
parent,
|
|
163
163
|
index,
|
|
164
|
+
range,
|
|
164
165
|
});
|
|
165
166
|
}
|
|
166
167
|
else if (node.isText) {
|
|
@@ -175,7 +176,7 @@ function getTextBetween(startNode, range, options) {
|
|
|
175
176
|
return text;
|
|
176
177
|
}
|
|
177
178
|
|
|
178
|
-
function
|
|
179
|
+
function getTextSerializersFromSchema(schema) {
|
|
179
180
|
return Object.fromEntries(Object
|
|
180
181
|
.entries(schema.nodes)
|
|
181
182
|
.filter(([, node]) => node.spec.toText)
|
|
@@ -196,7 +197,7 @@ const ClipboardTextSerializer = Extension.create({
|
|
|
196
197
|
const { ranges } = selection;
|
|
197
198
|
const from = Math.min(...ranges.map(range => range.$from.pos));
|
|
198
199
|
const to = Math.max(...ranges.map(range => range.$to.pos));
|
|
199
|
-
const textSerializers =
|
|
200
|
+
const textSerializers = getTextSerializersFromSchema(schema);
|
|
200
201
|
const range = { from, to };
|
|
201
202
|
return getTextBetween(doc, range, {
|
|
202
203
|
textSerializers,
|
|
@@ -408,7 +409,10 @@ function getMarkRange($pos, type, attributes = {}) {
|
|
|
408
409
|
if (!$pos || !type) {
|
|
409
410
|
return;
|
|
410
411
|
}
|
|
411
|
-
|
|
412
|
+
let start = $pos.parent.childAfter($pos.parentOffset);
|
|
413
|
+
if ($pos.parentOffset === start.offset && start.offset !== 0) {
|
|
414
|
+
start = $pos.parent.childBefore($pos.parentOffset);
|
|
415
|
+
}
|
|
412
416
|
if (!start.node) {
|
|
413
417
|
return;
|
|
414
418
|
}
|
|
@@ -416,7 +420,7 @@ function getMarkRange($pos, type, attributes = {}) {
|
|
|
416
420
|
if (!mark) {
|
|
417
421
|
return;
|
|
418
422
|
}
|
|
419
|
-
let startIndex =
|
|
423
|
+
let startIndex = start.index;
|
|
420
424
|
let startPos = $pos.start() + start.offset;
|
|
421
425
|
let endIndex = startIndex + 1;
|
|
422
426
|
let endPos = startPos + start.node.nodeSize;
|
|
@@ -512,21 +516,20 @@ function resolveFocusPosition(doc, position = null) {
|
|
|
512
516
|
if (!position) {
|
|
513
517
|
return null;
|
|
514
518
|
}
|
|
519
|
+
const selectionAtStart = prosemirrorState.Selection.atStart(doc);
|
|
520
|
+
const selectionAtEnd = prosemirrorState.Selection.atEnd(doc);
|
|
515
521
|
if (position === 'start' || position === true) {
|
|
516
|
-
return
|
|
522
|
+
return selectionAtStart;
|
|
517
523
|
}
|
|
518
524
|
if (position === 'end') {
|
|
519
|
-
return
|
|
525
|
+
return selectionAtEnd;
|
|
520
526
|
}
|
|
527
|
+
const minPos = selectionAtStart.from;
|
|
528
|
+
const maxPos = selectionAtEnd.to;
|
|
521
529
|
if (position === 'all') {
|
|
522
|
-
return prosemirrorState.TextSelection.create(doc, 0, doc.content.size);
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
const minPos = prosemirrorState.Selection.atStart(doc).from;
|
|
526
|
-
const maxPos = prosemirrorState.Selection.atEnd(doc).to;
|
|
527
|
-
const resolvedFrom = minMax(position, minPos, maxPos);
|
|
528
|
-
const resolvedEnd = minMax(position, minPos, maxPos);
|
|
529
|
-
return prosemirrorState.TextSelection.create(doc, resolvedFrom, resolvedEnd);
|
|
530
|
+
return prosemirrorState.TextSelection.create(doc, minMax(0, minPos, maxPos), minMax(doc.content.size, minPos, maxPos));
|
|
531
|
+
}
|
|
532
|
+
return prosemirrorState.TextSelection.create(doc, minMax(position, minPos, maxPos), minMax(position, minPos, maxPos));
|
|
530
533
|
}
|
|
531
534
|
|
|
532
535
|
const focus = (position = null, options) => ({ editor, view, tr, dispatch, }) => {
|
|
@@ -1198,7 +1201,7 @@ const setTextSelection = position => ({ tr, dispatch }) => {
|
|
|
1198
1201
|
? { from: position, to: position }
|
|
1199
1202
|
: position;
|
|
1200
1203
|
const minPos = prosemirrorState.TextSelection.atStart(doc).from;
|
|
1201
|
-
const maxPos = doc.
|
|
1204
|
+
const maxPos = prosemirrorState.TextSelection.atEnd(doc).to;
|
|
1202
1205
|
const resolvedFrom = minMax(from, minPos, maxPos);
|
|
1203
1206
|
const resolvedEnd = minMax(to, minPos, maxPos);
|
|
1204
1207
|
const selection = prosemirrorState.TextSelection.create(doc, resolvedFrom, resolvedEnd);
|
|
@@ -2103,8 +2106,6 @@ const Keymap = Extension.create({
|
|
|
2103
2106
|
};
|
|
2104
2107
|
const pcKeymap = {
|
|
2105
2108
|
...baseKeymap,
|
|
2106
|
-
Home: () => this.editor.commands.selectTextblockStart(),
|
|
2107
|
-
End: () => this.editor.commands.selectTextblockEnd(),
|
|
2108
2109
|
};
|
|
2109
2110
|
const macKeymap = {
|
|
2110
2111
|
...baseKeymap,
|
|
@@ -2263,12 +2264,15 @@ function isNodeEmpty(node) {
|
|
|
2263
2264
|
return JSON.stringify(defaultContent) === JSON.stringify(content);
|
|
2264
2265
|
}
|
|
2265
2266
|
|
|
2266
|
-
function createStyleTag(style) {
|
|
2267
|
+
function createStyleTag(style, nonce) {
|
|
2267
2268
|
const tipTapStyleTag = document.querySelector('style[data-tiptap-style]');
|
|
2268
2269
|
if (tipTapStyleTag !== null) {
|
|
2269
2270
|
return tipTapStyleTag;
|
|
2270
2271
|
}
|
|
2271
2272
|
const styleNode = document.createElement('style');
|
|
2273
|
+
if (nonce) {
|
|
2274
|
+
styleNode.setAttribute('nonce', nonce);
|
|
2275
|
+
}
|
|
2272
2276
|
styleNode.setAttribute('data-tiptap-style', '');
|
|
2273
2277
|
styleNode.innerHTML = style;
|
|
2274
2278
|
document.getElementsByTagName('head')[0].appendChild(styleNode);
|
|
@@ -3224,6 +3228,7 @@ class Editor extends EventEmitter {
|
|
|
3224
3228
|
element: document.createElement('div'),
|
|
3225
3229
|
content: '',
|
|
3226
3230
|
injectCSS: true,
|
|
3231
|
+
injectNonce: undefined,
|
|
3227
3232
|
extensions: [],
|
|
3228
3233
|
autofocus: false,
|
|
3229
3234
|
editable: true,
|
|
@@ -3295,7 +3300,7 @@ class Editor extends EventEmitter {
|
|
|
3295
3300
|
*/
|
|
3296
3301
|
injectCSS() {
|
|
3297
3302
|
if (this.options.injectCSS && document) {
|
|
3298
|
-
this.css = createStyleTag(style);
|
|
3303
|
+
this.css = createStyleTag(style, this.options.injectNonce);
|
|
3299
3304
|
}
|
|
3300
3305
|
}
|
|
3301
3306
|
/**
|
|
@@ -3526,7 +3531,7 @@ class Editor extends EventEmitter {
|
|
|
3526
3531
|
blockSeparator,
|
|
3527
3532
|
textSerializers: {
|
|
3528
3533
|
...textSerializers,
|
|
3529
|
-
...
|
|
3534
|
+
...getTextSerializersFromSchema(this.schema),
|
|
3530
3535
|
},
|
|
3531
3536
|
});
|
|
3532
3537
|
}
|
|
@@ -3722,7 +3727,7 @@ class NodeView {
|
|
|
3722
3727
|
return null;
|
|
3723
3728
|
}
|
|
3724
3729
|
onDragStart(event) {
|
|
3725
|
-
var _a, _b, _c;
|
|
3730
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3726
3731
|
const { view } = this.editor;
|
|
3727
3732
|
const target = event.target;
|
|
3728
3733
|
// get the drag handle element
|
|
@@ -3741,10 +3746,13 @@ class NodeView {
|
|
|
3741
3746
|
if (this.dom !== dragHandle) {
|
|
3742
3747
|
const domBox = this.dom.getBoundingClientRect();
|
|
3743
3748
|
const handleBox = dragHandle.getBoundingClientRect();
|
|
3744
|
-
|
|
3745
|
-
|
|
3749
|
+
// In React, we have to go through nativeEvent to reach offsetX/offsetY.
|
|
3750
|
+
const offsetX = (_c = event.offsetX) !== null && _c !== void 0 ? _c : (_d = event.nativeEvent) === null || _d === void 0 ? void 0 : _d.offsetX;
|
|
3751
|
+
const offsetY = (_e = event.offsetY) !== null && _e !== void 0 ? _e : (_f = event.nativeEvent) === null || _f === void 0 ? void 0 : _f.offsetY;
|
|
3752
|
+
x = handleBox.x - domBox.x + offsetX;
|
|
3753
|
+
y = handleBox.y - domBox.y + offsetY;
|
|
3746
3754
|
}
|
|
3747
|
-
(
|
|
3755
|
+
(_g = event.dataTransfer) === null || _g === void 0 ? void 0 : _g.setDragImage(this.dom, x, y);
|
|
3748
3756
|
// we need to tell ProseMirror that we want to move the whole node
|
|
3749
3757
|
// so we create a NodeSelection
|
|
3750
3758
|
const selection = prosemirrorState.NodeSelection.create(view.state.doc, this.getPos());
|
|
@@ -4262,7 +4270,7 @@ function generateText(doc, extensions, options) {
|
|
|
4262
4270
|
blockSeparator,
|
|
4263
4271
|
textSerializers: {
|
|
4264
4272
|
...textSerializers,
|
|
4265
|
-
...
|
|
4273
|
+
...getTextSerializersFromSchema(schema),
|
|
4266
4274
|
},
|
|
4267
4275
|
});
|
|
4268
4276
|
}
|
|
@@ -4452,6 +4460,7 @@ exports.getNodeType = getNodeType;
|
|
|
4452
4460
|
exports.getSchema = getSchema;
|
|
4453
4461
|
exports.getText = getText;
|
|
4454
4462
|
exports.getTextBetween = getTextBetween;
|
|
4463
|
+
exports.getTextSerializersFromSchema = getTextSerializersFromSchema;
|
|
4455
4464
|
exports.inputRulesPlugin = inputRulesPlugin;
|
|
4456
4465
|
exports.isActive = isActive;
|
|
4457
4466
|
exports.isList = isList;
|