@liveblocks/node-prosemirror 2.12.3-emails1 → 2.13.1-emails1
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 +111 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -22
- 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.
|
|
6
|
+
var PKG_VERSION = "2.13.1-emails1";
|
|
7
7
|
var PKG_FORMAT = "cjs";
|
|
8
8
|
|
|
9
9
|
// ../../node_modules/@tiptap/core/dist/index.js
|
|
@@ -383,6 +383,7 @@ 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)),
|
|
386
387
|
defining: callOrReturn(getExtensionField(extension, "defining", context)),
|
|
387
388
|
isolating: callOrReturn(getExtensionField(extension, "isolating", context)),
|
|
388
389
|
attrs: Object.fromEntries(extensionAttributes.map((extensionAttribute) => {
|
|
@@ -465,6 +466,13 @@ function isExtensionRulesEnabled(extension, enabled) {
|
|
|
465
466
|
}
|
|
466
467
|
return enabled;
|
|
467
468
|
}
|
|
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
|
+
}
|
|
468
476
|
var getTextContentFromNodes = ($from, maxMatch = 500) => {
|
|
469
477
|
let textBefore = "";
|
|
470
478
|
const sliceEndPos = $from.parentOffset;
|
|
@@ -569,7 +577,7 @@ function inputRulesPlugin(props) {
|
|
|
569
577
|
init() {
|
|
570
578
|
return null;
|
|
571
579
|
},
|
|
572
|
-
apply(tr, prev) {
|
|
580
|
+
apply(tr, prev, state) {
|
|
573
581
|
const stored = tr.getMeta(plugin);
|
|
574
582
|
if (stored) {
|
|
575
583
|
return stored;
|
|
@@ -578,7 +586,13 @@ function inputRulesPlugin(props) {
|
|
|
578
586
|
const isSimulatedInput = !!simulatedInputMeta;
|
|
579
587
|
if (isSimulatedInput) {
|
|
580
588
|
setTimeout(() => {
|
|
581
|
-
|
|
589
|
+
let { text } = simulatedInputMeta;
|
|
590
|
+
if (typeof text === "string") {
|
|
591
|
+
text = text;
|
|
592
|
+
} else {
|
|
593
|
+
text = getHTMLFromFragment(_model.Fragment.from(text), state.schema);
|
|
594
|
+
}
|
|
595
|
+
const { from } = simulatedInputMeta;
|
|
582
596
|
const to = from + text.length;
|
|
583
597
|
run$1({
|
|
584
598
|
editor,
|
|
@@ -830,7 +844,12 @@ function pasteRulesPlugin(props) {
|
|
|
830
844
|
let isPastedFromProseMirror = false;
|
|
831
845
|
let isDroppedFromProseMirror = false;
|
|
832
846
|
let pasteEvent = typeof ClipboardEvent !== "undefined" ? new ClipboardEvent("paste") : null;
|
|
833
|
-
let dropEvent
|
|
847
|
+
let dropEvent;
|
|
848
|
+
try {
|
|
849
|
+
dropEvent = typeof DragEvent !== "undefined" ? new DragEvent("drop") : null;
|
|
850
|
+
} catch (e) {
|
|
851
|
+
dropEvent = null;
|
|
852
|
+
}
|
|
834
853
|
const processEvent = ({ state, from, to, rule, pasteEvt }) => {
|
|
835
854
|
const tr = state.tr;
|
|
836
855
|
const chainableState = createChainableState({
|
|
@@ -849,7 +868,11 @@ function pasteRulesPlugin(props) {
|
|
|
849
868
|
if (!handler || !tr.steps.length) {
|
|
850
869
|
return;
|
|
851
870
|
}
|
|
852
|
-
|
|
871
|
+
try {
|
|
872
|
+
dropEvent = typeof DragEvent !== "undefined" ? new DragEvent("drop") : null;
|
|
873
|
+
} catch (e) {
|
|
874
|
+
dropEvent = null;
|
|
875
|
+
}
|
|
853
876
|
pasteEvent = typeof ClipboardEvent !== "undefined" ? new ClipboardEvent("paste") : null;
|
|
854
877
|
return tr;
|
|
855
878
|
};
|
|
@@ -894,7 +917,13 @@ function pasteRulesPlugin(props) {
|
|
|
894
917
|
return;
|
|
895
918
|
}
|
|
896
919
|
if (isSimulatedPaste) {
|
|
897
|
-
|
|
920
|
+
let { text } = simulatedPasteMeta;
|
|
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;
|
|
898
927
|
const to2 = from2 + text.length;
|
|
899
928
|
const pasteEvt = createClipboardPasteEvent(text);
|
|
900
929
|
return processEvent({
|
|
@@ -1418,13 +1447,18 @@ function objectIncludes(object1, object2, options = { strict: true }) {
|
|
|
1418
1447
|
}
|
|
1419
1448
|
function findMarkInSet(marks, type, attributes = {}) {
|
|
1420
1449
|
return marks.find((item) => {
|
|
1421
|
-
return item.type === type && objectIncludes(
|
|
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
|
+
);
|
|
1422
1455
|
});
|
|
1423
1456
|
}
|
|
1424
1457
|
function isMarkInSet(marks, type, attributes = {}) {
|
|
1425
1458
|
return !!findMarkInSet(marks, type, attributes);
|
|
1426
1459
|
}
|
|
1427
|
-
function getMarkRange($pos, type, attributes
|
|
1460
|
+
function getMarkRange($pos, type, attributes) {
|
|
1461
|
+
var _a;
|
|
1428
1462
|
if (!$pos || !type) {
|
|
1429
1463
|
return;
|
|
1430
1464
|
}
|
|
@@ -1435,6 +1469,7 @@ function getMarkRange($pos, type, attributes = {}) {
|
|
|
1435
1469
|
if (!start.node || !start.node.marks.some((mark2) => mark2.type === type)) {
|
|
1436
1470
|
return;
|
|
1437
1471
|
}
|
|
1472
|
+
attributes = attributes || ((_a = start.node.marks[0]) === null || _a === void 0 ? void 0 : _a.attrs);
|
|
1438
1473
|
const mark = findMarkInSet([...start.node.marks], type, attributes);
|
|
1439
1474
|
if (!mark) {
|
|
1440
1475
|
return;
|
|
@@ -1443,8 +1478,7 @@ function getMarkRange($pos, type, attributes = {}) {
|
|
|
1443
1478
|
let startPos = $pos.start() + start.offset;
|
|
1444
1479
|
let endIndex = startIndex + 1;
|
|
1445
1480
|
let endPos = startPos + start.node.nodeSize;
|
|
1446
|
-
|
|
1447
|
-
while (startIndex > 0 && mark.isInSet($pos.parent.child(startIndex - 1).marks)) {
|
|
1481
|
+
while (startIndex > 0 && isMarkInSet([...$pos.parent.child(startIndex - 1).marks], type, attributes)) {
|
|
1448
1482
|
startIndex -= 1;
|
|
1449
1483
|
startPos -= $pos.parent.child(startIndex).nodeSize;
|
|
1450
1484
|
}
|
|
@@ -1585,6 +1619,9 @@ function elementFromString(value) {
|
|
|
1585
1619
|
return removeWhitespaces(html);
|
|
1586
1620
|
}
|
|
1587
1621
|
function createNodeFromContent(content, schema, options) {
|
|
1622
|
+
if (content instanceof _model.Node || content instanceof _model.Fragment) {
|
|
1623
|
+
return content;
|
|
1624
|
+
}
|
|
1588
1625
|
options = {
|
|
1589
1626
|
slice: true,
|
|
1590
1627
|
parseOptions: {},
|
|
@@ -1727,6 +1764,14 @@ var insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) =
|
|
|
1727
1764
|
if (isOnlyTextContent) {
|
|
1728
1765
|
if (Array.isArray(value)) {
|
|
1729
1766
|
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;
|
|
1730
1775
|
} else if (typeof value === "object" && !!value && !!value.text) {
|
|
1731
1776
|
newContent = value.text;
|
|
1732
1777
|
} else {
|
|
@@ -2254,18 +2299,22 @@ var setMeta = (key, value) => ({ tr }) => {
|
|
|
2254
2299
|
};
|
|
2255
2300
|
var setNode = (typeOrName, attributes = {}) => ({ state, dispatch, chain }) => {
|
|
2256
2301
|
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
|
+
}
|
|
2257
2306
|
if (!type.isTextblock) {
|
|
2258
2307
|
console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.');
|
|
2259
2308
|
return false;
|
|
2260
2309
|
}
|
|
2261
2310
|
return chain().command(({ commands: commands2 }) => {
|
|
2262
|
-
const canSetBlock = _commands.setBlockType.call(void 0, type, attributes)(state);
|
|
2311
|
+
const canSetBlock = _commands.setBlockType.call(void 0, type, { ...attributesToCopy, ...attributes })(state);
|
|
2263
2312
|
if (canSetBlock) {
|
|
2264
2313
|
return true;
|
|
2265
2314
|
}
|
|
2266
2315
|
return commands2.clearNodes();
|
|
2267
2316
|
}).command(({ state: updatedState }) => {
|
|
2268
|
-
return _commands.setBlockType.call(void 0, type, attributes)(updatedState, dispatch);
|
|
2317
|
+
return _commands.setBlockType.call(void 0, type, { ...attributesToCopy, ...attributes })(updatedState, dispatch);
|
|
2269
2318
|
}).run();
|
|
2270
2319
|
};
|
|
2271
2320
|
var setNodeSelection = (position) => ({ tr, dispatch }) => {
|
|
@@ -2624,18 +2673,59 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
|
|
|
2624
2673
|
tr.selection.ranges.forEach((range) => {
|
|
2625
2674
|
const from = range.$from.pos;
|
|
2626
2675
|
const to = range.$to.pos;
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2676
|
+
let lastPos;
|
|
2677
|
+
let lastNode;
|
|
2678
|
+
let trimmedFrom;
|
|
2679
|
+
let trimmedTo;
|
|
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,
|
|
2631
2723
|
...attributes
|
|
2632
2724
|
});
|
|
2633
2725
|
}
|
|
2634
|
-
if (markType &&
|
|
2635
|
-
|
|
2726
|
+
if (markType && lastNode.marks.length) {
|
|
2727
|
+
lastNode.marks.forEach((mark) => {
|
|
2636
2728
|
if (markType === mark.type) {
|
|
2637
|
-
const trimmedFrom = Math.max(pos, from);
|
|
2638
|
-
const trimmedTo = Math.min(pos + node.nodeSize, to);
|
|
2639
2729
|
tr.addMark(trimmedFrom, trimmedTo, markType.create({
|
|
2640
2730
|
...mark.attrs,
|
|
2641
2731
|
...attributes
|
|
@@ -2643,7 +2733,7 @@ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }
|
|
|
2643
2733
|
}
|
|
2644
2734
|
});
|
|
2645
2735
|
}
|
|
2646
|
-
}
|
|
2736
|
+
}
|
|
2647
2737
|
});
|
|
2648
2738
|
}
|
|
2649
2739
|
return true;
|