@liveblocks/node-prosemirror 2.13.1-emails1 → 2.13.1
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/index.js +21 -111
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -112
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var _core = require('@liveblocks/core');
|
|
|
3
3
|
|
|
4
4
|
// src/version.ts
|
|
5
5
|
var PKG_NAME = "@liveblocks/node-prosemirror";
|
|
6
|
-
var PKG_VERSION = "2.13.1
|
|
6
|
+
var PKG_VERSION = "2.13.1";
|
|
7
7
|
var PKG_FORMAT = "cjs";
|
|
8
8
|
|
|
9
9
|
// ../../node_modules/@tiptap/core/dist/index.js
|
|
@@ -383,7 +383,6 @@ function getSchemaByResolvedExtensions(extensions, editor) {
|
|
|
383
383
|
draggable: callOrReturn(getExtensionField(extension, "draggable", context)),
|
|
384
384
|
code: callOrReturn(getExtensionField(extension, "code", context)),
|
|
385
385
|
whitespace: callOrReturn(getExtensionField(extension, "whitespace", context)),
|
|
386
|
-
linebreakReplacement: callOrReturn(getExtensionField(extension, "linebreakReplacement", context)),
|
|
387
386
|
defining: callOrReturn(getExtensionField(extension, "defining", context)),
|
|
388
387
|
isolating: callOrReturn(getExtensionField(extension, "isolating", context)),
|
|
389
388
|
attrs: Object.fromEntries(extensionAttributes.map((extensionAttribute) => {
|
|
@@ -466,13 +465,6 @@ function isExtensionRulesEnabled(extension, enabled) {
|
|
|
466
465
|
}
|
|
467
466
|
return enabled;
|
|
468
467
|
}
|
|
469
|
-
function getHTMLFromFragment(fragment, schema) {
|
|
470
|
-
const documentFragment = _model.DOMSerializer.fromSchema(schema).serializeFragment(fragment);
|
|
471
|
-
const temporaryDocument = document.implementation.createHTMLDocument();
|
|
472
|
-
const container = temporaryDocument.createElement("div");
|
|
473
|
-
container.appendChild(documentFragment);
|
|
474
|
-
return container.innerHTML;
|
|
475
|
-
}
|
|
476
468
|
var getTextContentFromNodes = ($from, maxMatch = 500) => {
|
|
477
469
|
let textBefore = "";
|
|
478
470
|
const sliceEndPos = $from.parentOffset;
|
|
@@ -577,7 +569,7 @@ function inputRulesPlugin(props) {
|
|
|
577
569
|
init() {
|
|
578
570
|
return null;
|
|
579
571
|
},
|
|
580
|
-
apply(tr, prev
|
|
572
|
+
apply(tr, prev) {
|
|
581
573
|
const stored = tr.getMeta(plugin);
|
|
582
574
|
if (stored) {
|
|
583
575
|
return stored;
|
|
@@ -586,13 +578,7 @@ function inputRulesPlugin(props) {
|
|
|
586
578
|
const isSimulatedInput = !!simulatedInputMeta;
|
|
587
579
|
if (isSimulatedInput) {
|
|
588
580
|
setTimeout(() => {
|
|
589
|
-
|
|
590
|
-
if (typeof text === "string") {
|
|
591
|
-
text = text;
|
|
592
|
-
} else {
|
|
593
|
-
text = getHTMLFromFragment(_model.Fragment.from(text), state.schema);
|
|
594
|
-
}
|
|
595
|
-
const { from } = simulatedInputMeta;
|
|
581
|
+
const { from, text } = simulatedInputMeta;
|
|
596
582
|
const to = from + text.length;
|
|
597
583
|
run$1({
|
|
598
584
|
editor,
|
|
@@ -844,12 +830,7 @@ function pasteRulesPlugin(props) {
|
|
|
844
830
|
let isPastedFromProseMirror = false;
|
|
845
831
|
let isDroppedFromProseMirror = false;
|
|
846
832
|
let pasteEvent = typeof ClipboardEvent !== "undefined" ? new ClipboardEvent("paste") : null;
|
|
847
|
-
let dropEvent;
|
|
848
|
-
try {
|
|
849
|
-
dropEvent = typeof DragEvent !== "undefined" ? new DragEvent("drop") : null;
|
|
850
|
-
} catch (e) {
|
|
851
|
-
dropEvent = null;
|
|
852
|
-
}
|
|
833
|
+
let dropEvent = typeof DragEvent !== "undefined" ? new DragEvent("drop") : null;
|
|
853
834
|
const processEvent = ({ state, from, to, rule, pasteEvt }) => {
|
|
854
835
|
const tr = state.tr;
|
|
855
836
|
const chainableState = createChainableState({
|
|
@@ -868,11 +849,7 @@ function pasteRulesPlugin(props) {
|
|
|
868
849
|
if (!handler || !tr.steps.length) {
|
|
869
850
|
return;
|
|
870
851
|
}
|
|
871
|
-
|
|
872
|
-
dropEvent = typeof DragEvent !== "undefined" ? new DragEvent("drop") : null;
|
|
873
|
-
} catch (e) {
|
|
874
|
-
dropEvent = null;
|
|
875
|
-
}
|
|
852
|
+
dropEvent = typeof DragEvent !== "undefined" ? new DragEvent("drop") : null;
|
|
876
853
|
pasteEvent = typeof ClipboardEvent !== "undefined" ? new ClipboardEvent("paste") : null;
|
|
877
854
|
return tr;
|
|
878
855
|
};
|
|
@@ -917,13 +894,7 @@ function pasteRulesPlugin(props) {
|
|
|
917
894
|
return;
|
|
918
895
|
}
|
|
919
896
|
if (isSimulatedPaste) {
|
|
920
|
-
|
|
921
|
-
if (typeof text === "string") {
|
|
922
|
-
text = text;
|
|
923
|
-
} else {
|
|
924
|
-
text = getHTMLFromFragment(_model.Fragment.from(text), state.schema);
|
|
925
|
-
}
|
|
926
|
-
const { from: from2 } = simulatedPasteMeta;
|
|
897
|
+
const { from: from2, text } = simulatedPasteMeta;
|
|
927
898
|
const to2 = from2 + text.length;
|
|
928
899
|
const pasteEvt = createClipboardPasteEvent(text);
|
|
929
900
|
return processEvent({
|
|
@@ -1447,18 +1418,13 @@ function objectIncludes(object1, object2, options = { strict: true }) {
|
|
|
1447
1418
|
}
|
|
1448
1419
|
function findMarkInSet(marks, type, attributes = {}) {
|
|
1449
1420
|
return marks.find((item) => {
|
|
1450
|
-
return item.type === type && objectIncludes(
|
|
1451
|
-
// Only check equality for the attributes that are provided
|
|
1452
|
-
Object.fromEntries(Object.keys(attributes).map((k) => [k, item.attrs[k]])),
|
|
1453
|
-
attributes
|
|
1454
|
-
);
|
|
1421
|
+
return item.type === type && objectIncludes(item.attrs, attributes);
|
|
1455
1422
|
});
|
|
1456
1423
|
}
|
|
1457
1424
|
function isMarkInSet(marks, type, attributes = {}) {
|
|
1458
1425
|
return !!findMarkInSet(marks, type, attributes);
|
|
1459
1426
|
}
|
|
1460
|
-
function getMarkRange($pos, type, attributes) {
|
|
1461
|
-
var _a;
|
|
1427
|
+
function getMarkRange($pos, type, attributes = {}) {
|
|
1462
1428
|
if (!$pos || !type) {
|
|
1463
1429
|
return;
|
|
1464
1430
|
}
|
|
@@ -1469,7 +1435,6 @@ function getMarkRange($pos, type, attributes) {
|
|
|
1469
1435
|
if (!start.node || !start.node.marks.some((mark2) => mark2.type === type)) {
|
|
1470
1436
|
return;
|
|
1471
1437
|
}
|
|
1472
|
-
attributes = attributes || ((_a = start.node.marks[0]) === null || _a === void 0 ? void 0 : _a.attrs);
|
|
1473
1438
|
const mark = findMarkInSet([...start.node.marks], type, attributes);
|
|
1474
1439
|
if (!mark) {
|
|
1475
1440
|
return;
|
|
@@ -1478,7 +1443,8 @@ function getMarkRange($pos, type, attributes) {
|
|
|
1478
1443
|
let startPos = $pos.start() + start.offset;
|
|
1479
1444
|
let endIndex = startIndex + 1;
|
|
1480
1445
|
let endPos = startPos + start.node.nodeSize;
|
|
1481
|
-
|
|
1446
|
+
findMarkInSet([...start.node.marks], type, attributes);
|
|
1447
|
+
while (startIndex > 0 && mark.isInSet($pos.parent.child(startIndex - 1).marks)) {
|
|
1482
1448
|
startIndex -= 1;
|
|
1483
1449
|
startPos -= $pos.parent.child(startIndex).nodeSize;
|
|
1484
1450
|
}
|
|
@@ -1619,9 +1585,6 @@ function elementFromString(value) {
|
|
|
1619
1585
|
return removeWhitespaces(html);
|
|
1620
1586
|
}
|
|
1621
1587
|
function createNodeFromContent(content, schema, options) {
|
|
1622
|
-
if (content instanceof _model.Node || content instanceof _model.Fragment) {
|
|
1623
|
-
return content;
|
|
1624
|
-
}
|
|
1625
1588
|
options = {
|
|
1626
1589
|
slice: true,
|
|
1627
1590
|
parseOptions: {},
|
|
@@ -1764,14 +1727,6 @@ var insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) =
|
|
|
1764
1727
|
if (isOnlyTextContent) {
|
|
1765
1728
|
if (Array.isArray(value)) {
|
|
1766
1729
|
newContent = value.map((v) => v.text || "").join("");
|
|
1767
|
-
} else if (value instanceof _model.Fragment) {
|
|
1768
|
-
let text = "";
|
|
1769
|
-
value.forEach((node) => {
|
|
1770
|
-
if (node.text) {
|
|
1771
|
-
text += node.text;
|
|
1772
|
-
}
|
|
1773
|
-
});
|
|
1774
|
-
newContent = text;
|
|
1775
1730
|
} else if (typeof value === "object" && !!value && !!value.text) {
|
|
1776
1731
|
newContent = value.text;
|
|
1777
1732
|
} else {
|
|
@@ -2299,22 +2254,18 @@ var setMeta = (key, value) => ({ tr }) => {
|
|
|
2299
2254
|
};
|
|
2300
2255
|
var setNode = (typeOrName, attributes = {}) => ({ state, dispatch, chain }) => {
|
|
2301
2256
|
const type = getNodeType(typeOrName, state.schema);
|
|
2302
|
-
let attributesToCopy;
|
|
2303
|
-
if (state.selection.$anchor.sameParent(state.selection.$head)) {
|
|
2304
|
-
attributesToCopy = state.selection.$anchor.parent.attrs;
|
|
2305
|
-
}
|
|
2306
2257
|
if (!type.isTextblock) {
|
|
2307
2258
|
console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.');
|
|
2308
2259
|
return false;
|
|
2309
2260
|
}
|
|
2310
2261
|
return chain().command(({ commands: commands2 }) => {
|
|
2311
|
-
const canSetBlock = _commands.setBlockType.call(void 0, type,
|
|
2262
|
+
const canSetBlock = _commands.setBlockType.call(void 0, type, attributes)(state);
|
|
2312
2263
|
if (canSetBlock) {
|
|
2313
2264
|
return true;
|
|
2314
2265
|
}
|
|
2315
2266
|
return commands2.clearNodes();
|
|
2316
2267
|
}).command(({ state: updatedState }) => {
|
|
2317
|
-
return _commands.setBlockType.call(void 0, type,
|
|
2268
|
+
return _commands.setBlockType.call(void 0, type, attributes)(updatedState, dispatch);
|
|
2318
2269
|
}).run();
|
|
2319
2270
|
};
|
|
2320
2271
|
var setNodeSelection = (position) => ({ tr, dispatch }) => {
|
|
@@ -2673,59 +2624,18 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
|
|
|
2673
2624
|
tr.selection.ranges.forEach((range) => {
|
|
2674
2625
|
const from = range.$from.pos;
|
|
2675
2626
|
const to = range.$to.pos;
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
if (tr.selection.empty) {
|
|
2681
|
-
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
2682
|
-
if (nodeType && nodeType === node.type) {
|
|
2683
|
-
trimmedFrom = Math.max(pos, from);
|
|
2684
|
-
trimmedTo = Math.min(pos + node.nodeSize, to);
|
|
2685
|
-
lastPos = pos;
|
|
2686
|
-
lastNode = node;
|
|
2687
|
-
}
|
|
2688
|
-
});
|
|
2689
|
-
} else {
|
|
2690
|
-
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
2691
|
-
if (pos < from && nodeType && nodeType === node.type) {
|
|
2692
|
-
trimmedFrom = Math.max(pos, from);
|
|
2693
|
-
trimmedTo = Math.min(pos + node.nodeSize, to);
|
|
2694
|
-
lastPos = pos;
|
|
2695
|
-
lastNode = node;
|
|
2696
|
-
}
|
|
2697
|
-
if (pos >= from && pos <= to) {
|
|
2698
|
-
if (nodeType && nodeType === node.type) {
|
|
2699
|
-
tr.setNodeMarkup(pos, void 0, {
|
|
2700
|
-
...node.attrs,
|
|
2701
|
-
...attributes
|
|
2702
|
-
});
|
|
2703
|
-
}
|
|
2704
|
-
if (markType && node.marks.length) {
|
|
2705
|
-
node.marks.forEach((mark) => {
|
|
2706
|
-
if (markType === mark.type) {
|
|
2707
|
-
const trimmedFrom2 = Math.max(pos, from);
|
|
2708
|
-
const trimmedTo2 = Math.min(pos + node.nodeSize, to);
|
|
2709
|
-
tr.addMark(trimmedFrom2, trimmedTo2, markType.create({
|
|
2710
|
-
...mark.attrs,
|
|
2711
|
-
...attributes
|
|
2712
|
-
}));
|
|
2713
|
-
}
|
|
2714
|
-
});
|
|
2715
|
-
}
|
|
2716
|
-
}
|
|
2717
|
-
});
|
|
2718
|
-
}
|
|
2719
|
-
if (lastNode) {
|
|
2720
|
-
if (lastPos !== void 0) {
|
|
2721
|
-
tr.setNodeMarkup(lastPos, void 0, {
|
|
2722
|
-
...lastNode.attrs,
|
|
2627
|
+
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
2628
|
+
if (nodeType && nodeType === node.type) {
|
|
2629
|
+
tr.setNodeMarkup(pos, void 0, {
|
|
2630
|
+
...node.attrs,
|
|
2723
2631
|
...attributes
|
|
2724
2632
|
});
|
|
2725
2633
|
}
|
|
2726
|
-
if (markType &&
|
|
2727
|
-
|
|
2634
|
+
if (markType && node.marks.length) {
|
|
2635
|
+
node.marks.forEach((mark) => {
|
|
2728
2636
|
if (markType === mark.type) {
|
|
2637
|
+
const trimmedFrom = Math.max(pos, from);
|
|
2638
|
+
const trimmedTo = Math.min(pos + node.nodeSize, to);
|
|
2729
2639
|
tr.addMark(trimmedFrom, trimmedTo, markType.create({
|
|
2730
2640
|
...mark.attrs,
|
|
2731
2641
|
...attributes
|
|
@@ -2733,7 +2643,7 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
|
|
|
2733
2643
|
}
|
|
2734
2644
|
});
|
|
2735
2645
|
}
|
|
2736
|
-
}
|
|
2646
|
+
});
|
|
2737
2647
|
});
|
|
2738
2648
|
}
|
|
2739
2649
|
return true;
|