@slate-yjs/core 1.0.4 → 1.0.5
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/CHANGELOG.md +8 -0
- package/dist/applyToYjs/node/moveNode.d.ts.map +1 -1
- package/dist/index.cjs +41 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +41 -16
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +41 -16
- package/dist/index.js.map +1 -1
- package/dist/plugins/withCursors.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/applyToYjs/node/moveNode.ts +39 -13
- package/src/plugins/withCursors.ts +38 -11
package/dist/index.global.js
CHANGED
|
@@ -8194,22 +8194,38 @@ ${err.toString()}`);
|
|
|
8194
8194
|
}
|
|
8195
8195
|
|
|
8196
8196
|
// src/applyToYjs/node/moveNode.ts
|
|
8197
|
-
function
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8197
|
+
function withoutNode(root, path) {
|
|
8198
|
+
if (Text.isText(root)) {
|
|
8199
|
+
throw new Error("Cannot descend into slate text");
|
|
8200
|
+
}
|
|
8201
|
+
const [index, ...rest] = path;
|
|
8202
|
+
const children = [...root.children];
|
|
8203
|
+
if (rest.length === 0) {
|
|
8204
|
+
children.splice(index, 1);
|
|
8205
|
+
} else {
|
|
8206
|
+
children[index] = withoutNode(children[index], rest);
|
|
8203
8207
|
}
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
];
|
|
8208
|
+
return __spreadProps(__spreadValues({}, root), { children });
|
|
8209
|
+
}
|
|
8210
|
+
function moveNode(sharedRoot, slateRoot, op) {
|
|
8208
8211
|
const origin = getYTarget(sharedRoot, slateRoot, op.path);
|
|
8209
|
-
const target = getYTarget(sharedRoot, slateRoot, normalizedNewPath);
|
|
8210
8212
|
const insertDelta = cloneInsertDeltaDeep(origin.targetDelta);
|
|
8211
8213
|
const storedPositions = getStoredPositionsInDeltaAbsolute(sharedRoot, origin.yParent, origin.targetDelta);
|
|
8212
8214
|
origin.yParent.delete(origin.textRange.start, origin.textRange.end - origin.textRange.start);
|
|
8215
|
+
const rootWithoutNode = withoutNode(slateRoot, op.path);
|
|
8216
|
+
const newPath = Path.transform(op.path, op);
|
|
8217
|
+
if (!newPath) {
|
|
8218
|
+
throw new Error("Cannot resolve the target path of a move");
|
|
8219
|
+
}
|
|
8220
|
+
const newParentPath = Path.parent(newPath);
|
|
8221
|
+
const parent = Node.get(rootWithoutNode, newParentPath);
|
|
8222
|
+
if (Text.isText(parent)) {
|
|
8223
|
+
throw new Error("Cannot move slate node into text element");
|
|
8224
|
+
}
|
|
8225
|
+
const target = getYTarget(sharedRoot, rootWithoutNode, [
|
|
8226
|
+
...newParentPath,
|
|
8227
|
+
Math.min(newPath[newPath.length - 1], parent.children.length)
|
|
8228
|
+
]);
|
|
8213
8229
|
const targetLength = getInsertDeltaLength(yTextToInsertDelta(target.yParent));
|
|
8214
8230
|
const deltaApplyYOffset = Math.min(target.textRange.start, targetLength);
|
|
8215
8231
|
const applyDelta2 = [{ retain: deltaApplyYOffset }, ...insertDelta];
|
|
@@ -8679,18 +8695,23 @@ ${err.toString()}`);
|
|
|
8679
8695
|
e.sendCursorData = (cursorData) => {
|
|
8680
8696
|
e.awareness.setLocalStateField(e.cursorDataField, cursorData);
|
|
8681
8697
|
};
|
|
8698
|
+
let hiddenAt;
|
|
8699
|
+
const relativeSelection = () => e.selection ? slateRangeToRelativeRange(e.sharedRoot, e, e.selection) : null;
|
|
8700
|
+
const isSameRange = (a, b) => a === b || !!a && !!b && compareRelativePositions(a.anchor, b.anchor) && compareRelativePositions(a.focus, b.focus);
|
|
8682
8701
|
e.sendCursorPosition = (range) => {
|
|
8683
8702
|
const localState = e.awareness.getLocalState();
|
|
8684
8703
|
const currentRange = localState == null ? void 0 : localState[selectionStateField];
|
|
8685
8704
|
if (!range) {
|
|
8705
|
+
hiddenAt = relativeSelection();
|
|
8686
8706
|
if (currentRange) {
|
|
8687
8707
|
e.awareness.setLocalStateField(e.selectionStateField, null);
|
|
8688
8708
|
}
|
|
8689
8709
|
return;
|
|
8690
8710
|
}
|
|
8691
|
-
|
|
8692
|
-
|
|
8693
|
-
|
|
8711
|
+
hiddenAt = void 0;
|
|
8712
|
+
const relativeRange = slateRangeToRelativeRange(e.sharedRoot, e, range);
|
|
8713
|
+
if (!currentRange || !isSameRange(relativeRange, currentRange)) {
|
|
8714
|
+
e.awareness.setLocalStateField(e.selectionStateField, relativeRange);
|
|
8694
8715
|
}
|
|
8695
8716
|
};
|
|
8696
8717
|
const awarenessChangeListener = (yEvent) => {
|
|
@@ -8724,9 +8745,13 @@ ${err.toString()}`);
|
|
|
8724
8745
|
const { onChange } = e;
|
|
8725
8746
|
e.onChange = () => {
|
|
8726
8747
|
onChange();
|
|
8727
|
-
if (YjsEditor.connected(e)) {
|
|
8728
|
-
|
|
8748
|
+
if (!YjsEditor.connected(e)) {
|
|
8749
|
+
return;
|
|
8750
|
+
}
|
|
8751
|
+
if (hiddenAt !== void 0 && isSameRange(relativeSelection(), hiddenAt)) {
|
|
8752
|
+
return;
|
|
8729
8753
|
}
|
|
8754
|
+
CursorEditor.sendCursorPosition(e);
|
|
8730
8755
|
};
|
|
8731
8756
|
}
|
|
8732
8757
|
};
|