@tiptap/core 2.0.0-beta.175 → 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 +24 -12
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +24 -13
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +24 -12
- 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/extensions/clipboardTextSerializer.ts +2 -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/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;
|
|
@@ -2260,12 +2264,15 @@ function isNodeEmpty(node) {
|
|
|
2260
2264
|
return JSON.stringify(defaultContent) === JSON.stringify(content);
|
|
2261
2265
|
}
|
|
2262
2266
|
|
|
2263
|
-
function createStyleTag(style) {
|
|
2267
|
+
function createStyleTag(style, nonce) {
|
|
2264
2268
|
const tipTapStyleTag = document.querySelector('style[data-tiptap-style]');
|
|
2265
2269
|
if (tipTapStyleTag !== null) {
|
|
2266
2270
|
return tipTapStyleTag;
|
|
2267
2271
|
}
|
|
2268
2272
|
const styleNode = document.createElement('style');
|
|
2273
|
+
if (nonce) {
|
|
2274
|
+
styleNode.setAttribute('nonce', nonce);
|
|
2275
|
+
}
|
|
2269
2276
|
styleNode.setAttribute('data-tiptap-style', '');
|
|
2270
2277
|
styleNode.innerHTML = style;
|
|
2271
2278
|
document.getElementsByTagName('head')[0].appendChild(styleNode);
|
|
@@ -3221,6 +3228,7 @@ class Editor extends EventEmitter {
|
|
|
3221
3228
|
element: document.createElement('div'),
|
|
3222
3229
|
content: '',
|
|
3223
3230
|
injectCSS: true,
|
|
3231
|
+
injectNonce: undefined,
|
|
3224
3232
|
extensions: [],
|
|
3225
3233
|
autofocus: false,
|
|
3226
3234
|
editable: true,
|
|
@@ -3292,7 +3300,7 @@ class Editor extends EventEmitter {
|
|
|
3292
3300
|
*/
|
|
3293
3301
|
injectCSS() {
|
|
3294
3302
|
if (this.options.injectCSS && document) {
|
|
3295
|
-
this.css = createStyleTag(style);
|
|
3303
|
+
this.css = createStyleTag(style, this.options.injectNonce);
|
|
3296
3304
|
}
|
|
3297
3305
|
}
|
|
3298
3306
|
/**
|
|
@@ -3523,7 +3531,7 @@ class Editor extends EventEmitter {
|
|
|
3523
3531
|
blockSeparator,
|
|
3524
3532
|
textSerializers: {
|
|
3525
3533
|
...textSerializers,
|
|
3526
|
-
...
|
|
3534
|
+
...getTextSerializersFromSchema(this.schema),
|
|
3527
3535
|
},
|
|
3528
3536
|
});
|
|
3529
3537
|
}
|
|
@@ -3719,7 +3727,7 @@ class NodeView {
|
|
|
3719
3727
|
return null;
|
|
3720
3728
|
}
|
|
3721
3729
|
onDragStart(event) {
|
|
3722
|
-
var _a, _b, _c;
|
|
3730
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3723
3731
|
const { view } = this.editor;
|
|
3724
3732
|
const target = event.target;
|
|
3725
3733
|
// get the drag handle element
|
|
@@ -3738,10 +3746,13 @@ class NodeView {
|
|
|
3738
3746
|
if (this.dom !== dragHandle) {
|
|
3739
3747
|
const domBox = this.dom.getBoundingClientRect();
|
|
3740
3748
|
const handleBox = dragHandle.getBoundingClientRect();
|
|
3741
|
-
|
|
3742
|
-
|
|
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;
|
|
3743
3754
|
}
|
|
3744
|
-
(
|
|
3755
|
+
(_g = event.dataTransfer) === null || _g === void 0 ? void 0 : _g.setDragImage(this.dom, x, y);
|
|
3745
3756
|
// we need to tell ProseMirror that we want to move the whole node
|
|
3746
3757
|
// so we create a NodeSelection
|
|
3747
3758
|
const selection = prosemirrorState.NodeSelection.create(view.state.doc, this.getPos());
|
|
@@ -4259,7 +4270,7 @@ function generateText(doc, extensions, options) {
|
|
|
4259
4270
|
blockSeparator,
|
|
4260
4271
|
textSerializers: {
|
|
4261
4272
|
...textSerializers,
|
|
4262
|
-
...
|
|
4273
|
+
...getTextSerializersFromSchema(schema),
|
|
4263
4274
|
},
|
|
4264
4275
|
});
|
|
4265
4276
|
}
|
|
@@ -4449,6 +4460,7 @@ exports.getNodeType = getNodeType;
|
|
|
4449
4460
|
exports.getSchema = getSchema;
|
|
4450
4461
|
exports.getText = getText;
|
|
4451
4462
|
exports.getTextBetween = getTextBetween;
|
|
4463
|
+
exports.getTextSerializersFromSchema = getTextSerializersFromSchema;
|
|
4452
4464
|
exports.inputRulesPlugin = inputRulesPlugin;
|
|
4453
4465
|
exports.isActive = isActive;
|
|
4454
4466
|
exports.isList = isList;
|