slate-vue3 0.3.1 → 0.3.2
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/slate-yjs/hooks/useRemoteCursorStateStore.d.ts +1 -2
- package/dist/slate-yjs/hooks/utils.d.ts +1 -4
- package/dist/slate-yjs/utils/clone.d.ts +2 -2
- package/dist/slate-yjs/utils/convert.d.ts +3 -3
- package/dist/slate-yjs/utils/delta.d.ts +2 -2
- package/dist/slate-yjs/utils/location.d.ts +3 -3
- package/dist/slate-yjs/utils/position.d.ts +13 -13
- package/dist/slate-yjs/utils/yjs.d.ts +2 -2
- package/dist/yjs.js +40 -67
- package/package.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { JsonObject } from '@liveblocks/client';
|
|
2
2
|
import { Store } from './utils';
|
|
3
|
-
import {
|
|
3
|
+
import { CursorState } from '../plugins/withCursors';
|
|
4
4
|
export type CursorStore<TCursorData extends JsonObject = JsonObject> = Store<Record<string, CursorState<TCursorData>>>;
|
|
5
|
-
export declare function createRemoteCursorStateStore<TCursorData extends JsonObject>(editor: CursorEditor<TCursorData>): CursorStore<TCursorData>;
|
|
6
5
|
export declare function useRemoteCursorStateStore<TCursorData extends JsonObject = JsonObject>(): CursorStore<TCursorData>;
|
|
@@ -4,10 +4,7 @@ import { DOMEditor } from '../../slate-dom/index.ts';
|
|
|
4
4
|
import { JsonObject } from '@liveblocks/client';
|
|
5
5
|
import { CursorEditor, CursorState } from '../plugins/withCursors';
|
|
6
6
|
export declare function useOnResize<T extends HTMLElement>(_ref: Ref<T>, onResize: () => void): void;
|
|
7
|
-
export type Store<T> = readonly [
|
|
8
|
-
(onStoreChange: () => void) => () => void,
|
|
9
|
-
() => T
|
|
10
|
-
];
|
|
7
|
+
export type Store<T> = readonly [() => () => void, Ref<T>];
|
|
11
8
|
export declare function getCursorRange<TCursorData extends JsonObject = JsonObject>(editor: CursorEditor<TCursorData>, cursorState: CursorState<TCursorData>): Range | null;
|
|
12
9
|
export type SelectionRect = {
|
|
13
10
|
width: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import { XmlText } from 'yjs';
|
|
1
2
|
import { InsertDelta } from '../model/types';
|
|
2
|
-
import * as Y from 'yjs';
|
|
3
3
|
export declare function cloneInsertDeltaDeep(delta: InsertDelta): InsertDelta;
|
|
4
|
-
export declare function cloneDeep(yText:
|
|
4
|
+
export declare function cloneDeep(yText: XmlText): XmlText;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Element, Node } from '../../slate/index.ts';
|
|
2
2
|
import { DeltaInsert, InsertDelta } from '../model/types';
|
|
3
|
-
import
|
|
4
|
-
export declare function yTextToSlateElement(yText:
|
|
3
|
+
import { XmlText } from 'yjs';
|
|
4
|
+
export declare function yTextToSlateElement(yText: XmlText): Element;
|
|
5
5
|
export declare function deltaInsertToSlateNode(insert: DeltaInsert): Node;
|
|
6
6
|
export declare function slateNodesToInsertDelta(nodes: Node[]): InsertDelta;
|
|
7
|
-
export declare function slateElementToYText({ children, ...attributes }: Element):
|
|
7
|
+
export declare function slateElementToYText({ children, ...attributes }: Element): XmlText;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { XmlText } from 'yjs';
|
|
1
2
|
import { DeltaInsert, InsertDelta } from '../model/types';
|
|
2
|
-
import * as Y from 'yjs';
|
|
3
3
|
export declare function normalizeInsertDelta(delta: InsertDelta): InsertDelta;
|
|
4
|
-
export declare function yTextToInsertDelta(yText:
|
|
4
|
+
export declare function yTextToInsertDelta(yText: XmlText): InsertDelta;
|
|
5
5
|
export declare function getInsertLength({ insert }: DeltaInsert): number;
|
|
6
6
|
export declare function getInsertDeltaLength(delta: InsertDelta): number;
|
|
7
7
|
export declare function sliceInsertDelta(delta: InsertDelta, start: number, length: number): InsertDelta;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Element, Node, Path } from '../../slate/index.ts';
|
|
2
2
|
import { YTarget } from '../model/types';
|
|
3
|
-
import
|
|
3
|
+
import { XmlText } from 'yjs';
|
|
4
4
|
export declare function getSlateNodeYLength(node: Node | undefined): number;
|
|
5
5
|
export declare function slatePathOffsetToYOffset(element: Element, pathOffset: number): number;
|
|
6
|
-
export declare function getYTarget(yRoot:
|
|
6
|
+
export declare function getYTarget(yRoot: XmlText, slateRoot: Node, path: Path): YTarget;
|
|
7
7
|
export declare function yOffsetToSlateOffsets(parent: Element, yOffset: number, opts?: {
|
|
8
8
|
assoc?: number;
|
|
9
9
|
insert?: boolean;
|
|
10
10
|
}): [number, number];
|
|
11
|
-
export declare function getSlatePath(sharedRoot:
|
|
11
|
+
export declare function getSlatePath(sharedRoot: XmlText, slateRoot: Node, yText: XmlText): Path;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { BasePoint, BaseRange, Node } from '../../slate/index.ts';
|
|
2
|
+
import { AbsolutePosition, RelativePosition, XmlText } from 'yjs';
|
|
2
3
|
import { InsertDelta, RelativeRange } from '../model/types';
|
|
3
|
-
import * as Y from 'yjs';
|
|
4
4
|
export declare const STORED_POSITION_PREFIX = "__slateYjsStoredPosition_";
|
|
5
|
-
export declare function slatePointToRelativePosition(sharedRoot:
|
|
6
|
-
export declare function absolutePositionToSlatePoint(sharedRoot:
|
|
7
|
-
export declare function relativePositionToSlatePoint(sharedRoot:
|
|
8
|
-
export declare function getStoredPosition(sharedRoot:
|
|
9
|
-
export declare function getStoredPositions(sharedRoot:
|
|
10
|
-
export declare function removeStoredPosition(sharedRoot:
|
|
11
|
-
export declare function setStoredPosition(sharedRoot:
|
|
12
|
-
export declare function getStoredPositionsInDeltaAbsolute(sharedRoot:
|
|
5
|
+
export declare function slatePointToRelativePosition(sharedRoot: XmlText, slateRoot: Node, point: BasePoint): RelativePosition;
|
|
6
|
+
export declare function absolutePositionToSlatePoint(sharedRoot: XmlText, slateRoot: Node, { type, index, assoc }: AbsolutePosition): BasePoint | null;
|
|
7
|
+
export declare function relativePositionToSlatePoint(sharedRoot: XmlText, slateRoot: Node, pos: RelativePosition): BasePoint | null;
|
|
8
|
+
export declare function getStoredPosition(sharedRoot: XmlText, key: string): RelativePosition | null;
|
|
9
|
+
export declare function getStoredPositions(sharedRoot: XmlText): Record<string, RelativePosition>;
|
|
10
|
+
export declare function removeStoredPosition(sharedRoot: XmlText, key: string): void;
|
|
11
|
+
export declare function setStoredPosition(sharedRoot: XmlText, key: string, position: RelativePosition): void;
|
|
12
|
+
export declare function getStoredPositionsInDeltaAbsolute(sharedRoot: XmlText, yText: XmlText, delta: InsertDelta, deltaOffset?: number): {
|
|
13
13
|
'': {
|
|
14
|
-
[k: string]:
|
|
14
|
+
[k: string]: AbsolutePosition;
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
-
export declare function restoreStoredPositionsWithDeltaAbsolute(sharedRoot:
|
|
18
|
-
export declare function slateRangeToRelativeRange(sharedRoot:
|
|
19
|
-
export declare function relativeRangeToSlateRange(sharedRoot:
|
|
17
|
+
export declare function restoreStoredPositionsWithDeltaAbsolute(sharedRoot: XmlText, yText: XmlText, absolutePositions: Record<string, Record<string, AbsolutePosition>>, delta: InsertDelta, newDeltaOffset?: number, previousDeltaOffset?: number, path?: string): void;
|
|
18
|
+
export declare function slateRangeToRelativeRange(sharedRoot: XmlText, slateRoot: Node, range: BaseRange): RelativeRange;
|
|
19
|
+
export declare function relativeRangeToSlateRange(sharedRoot: XmlText, slateRoot: Node, range: RelativeRange): BaseRange | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare function assertDocumentAttachment<T extends
|
|
1
|
+
import { AbstractType } from 'yjs';
|
|
2
|
+
export declare function assertDocumentAttachment<T extends AbstractType<any>>(sharedType: T): asserts sharedType is T & {
|
|
3
3
|
doc: NonNullable<T['doc']>;
|
|
4
4
|
};
|
package/dist/yjs.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { d as isPlainObject, T as Text, N as Node, P as Path, E as Editor, t as toRawWeakMap, c as Transforms, R as Range } from "./batch-dirty-paths-DdGxRyrT.js";
|
|
2
2
|
import { toRaw, ref, onMounted, onUnmounted, watch, onUpdated, computed } from "vue";
|
|
3
|
-
import
|
|
4
|
-
import { XmlText, YTextEvent, UndoManager, compareRelativePositions } from "yjs";
|
|
3
|
+
import { XmlText, YTextEvent, createRelativePositionFromTypeIndex, createAbsolutePositionFromRelativePosition, createRelativePositionFromJSON, decodeRelativePosition, encodeRelativePosition, UndoManager, compareRelativePositions } from "yjs";
|
|
5
4
|
import { L as Location } from "./location-BQJIMGOU.js";
|
|
6
5
|
import { g as useEditor, e as useFocused } from "./use-focused-C0jEAq2w.js";
|
|
7
6
|
import { D as DOMEditor } from "./hotkeys-CmyQAN4Q.js";
|
|
@@ -142,7 +141,7 @@ function slateElementToYText({
|
|
|
142
141
|
children,
|
|
143
142
|
...attributes
|
|
144
143
|
}) {
|
|
145
|
-
const yElement = new
|
|
144
|
+
const yElement = new XmlText();
|
|
146
145
|
Object.entries(attributes).forEach(([key, value]) => {
|
|
147
146
|
yElement.setAttribute(key, value);
|
|
148
147
|
});
|
|
@@ -177,7 +176,7 @@ function getYTarget(yRoot, slateRoot, path) {
|
|
|
177
176
|
}
|
|
178
177
|
const yTarget = (_a = targetDelta[0]) == null ? void 0 : _a.insert;
|
|
179
178
|
if (childPath.length > 0) {
|
|
180
|
-
if (!(yTarget instanceof
|
|
179
|
+
if (!(yTarget instanceof XmlText)) {
|
|
181
180
|
throw new Error(
|
|
182
181
|
"Path doesn't match yText, cannot descent into non-yText"
|
|
183
182
|
);
|
|
@@ -187,7 +186,7 @@ function getYTarget(yRoot, slateRoot, path) {
|
|
|
187
186
|
return {
|
|
188
187
|
yParent: yRoot,
|
|
189
188
|
textRange: { start: yOffset, end: yOffset + targetLength },
|
|
190
|
-
yTarget: yTarget instanceof
|
|
189
|
+
yTarget: yTarget instanceof XmlText ? yTarget : void 0,
|
|
191
190
|
slateParent: slateRoot,
|
|
192
191
|
slateTarget: targetNode,
|
|
193
192
|
targetDelta
|
|
@@ -226,7 +225,7 @@ function getSlatePath(sharedRoot, slateRoot, yText) {
|
|
|
226
225
|
if (!yParent) {
|
|
227
226
|
throw new Error("yText isn't a descendant of root element");
|
|
228
227
|
}
|
|
229
|
-
if (!(yParent instanceof
|
|
228
|
+
if (!(yParent instanceof XmlText)) {
|
|
230
229
|
throw new Error("Unexpected y parent type");
|
|
231
230
|
}
|
|
232
231
|
yNodePath.unshift(yParent);
|
|
@@ -478,7 +477,7 @@ function cloneInsertDeltaDeep(delta) {
|
|
|
478
477
|
});
|
|
479
478
|
}
|
|
480
479
|
function cloneDeep(yText) {
|
|
481
|
-
const clone = new
|
|
480
|
+
const clone = new XmlText();
|
|
482
481
|
const attributes = yText.getAttributes();
|
|
483
482
|
Object.entries(attributes).forEach(([key, value]) => {
|
|
484
483
|
clone.setAttribute(key, value);
|
|
@@ -506,14 +505,14 @@ function slatePointToRelativePosition(sharedRoot, slateRoot, point) {
|
|
|
506
505
|
);
|
|
507
506
|
}
|
|
508
507
|
const index = textRange.start + point.offset;
|
|
509
|
-
return
|
|
508
|
+
return createRelativePositionFromTypeIndex(
|
|
510
509
|
yParent,
|
|
511
510
|
index,
|
|
512
511
|
index === textRange.end ? -1 : 0
|
|
513
512
|
);
|
|
514
513
|
}
|
|
515
514
|
function absolutePositionToSlatePoint(sharedRoot, slateRoot, { type, index, assoc }) {
|
|
516
|
-
if (!(type instanceof
|
|
515
|
+
if (!(type instanceof XmlText)) {
|
|
517
516
|
throw new Error("Absolute position points to a non-XMLText");
|
|
518
517
|
}
|
|
519
518
|
const parentPath = getSlatePath(sharedRoot, slateRoot, type);
|
|
@@ -536,7 +535,7 @@ function relativePositionToSlatePoint(sharedRoot, slateRoot, pos) {
|
|
|
536
535
|
if (!sharedRoot.doc) {
|
|
537
536
|
throw new Error("sharedRoot isn't attach to a yDoc");
|
|
538
537
|
}
|
|
539
|
-
const absPos =
|
|
538
|
+
const absPos = createAbsolutePositionFromRelativePosition(
|
|
540
539
|
pos,
|
|
541
540
|
sharedRoot.doc
|
|
542
541
|
);
|
|
@@ -547,13 +546,13 @@ function getStoredPosition(sharedRoot, key) {
|
|
|
547
546
|
if (!rawPosition) {
|
|
548
547
|
return null;
|
|
549
548
|
}
|
|
550
|
-
return
|
|
549
|
+
return decodeRelativePosition(rawPosition);
|
|
551
550
|
}
|
|
552
551
|
function getStoredPositions(sharedRoot) {
|
|
553
552
|
return Object.fromEntries(
|
|
554
553
|
Object.entries(sharedRoot.getAttributes()).filter(([key]) => key.startsWith(STORED_POSITION_PREFIX)).map(([key, position]) => [
|
|
555
554
|
key.slice(STORED_POSITION_PREFIX.length),
|
|
556
|
-
|
|
555
|
+
createRelativePositionFromJSON(position)
|
|
557
556
|
])
|
|
558
557
|
);
|
|
559
558
|
}
|
|
@@ -563,8 +562,8 @@ function getStoredPositionsAbsolute(sharedRoot) {
|
|
|
563
562
|
Object.entries(sharedRoot.getAttributes()).filter(([key]) => key.startsWith(STORED_POSITION_PREFIX)).map(
|
|
564
563
|
([key, position]) => [
|
|
565
564
|
key.slice(STORED_POSITION_PREFIX.length),
|
|
566
|
-
|
|
567
|
-
|
|
565
|
+
createAbsolutePositionFromRelativePosition(
|
|
566
|
+
decodeRelativePosition(position),
|
|
568
567
|
sharedRoot.doc
|
|
569
568
|
)
|
|
570
569
|
]
|
|
@@ -577,7 +576,7 @@ function removeStoredPosition(sharedRoot, key) {
|
|
|
577
576
|
function setStoredPosition(sharedRoot, key, position) {
|
|
578
577
|
sharedRoot.setAttribute(
|
|
579
578
|
STORED_POSITION_PREFIX + key,
|
|
580
|
-
|
|
579
|
+
encodeRelativePosition(position)
|
|
581
580
|
);
|
|
582
581
|
}
|
|
583
582
|
function getAbsolutePositionsInTextRange(absolutePositions, yTarget, textRange) {
|
|
@@ -599,7 +598,7 @@ function getAbsolutePositionsInYText(absolutePositions, yText, parentPath = "")
|
|
|
599
598
|
};
|
|
600
599
|
const insertDelta = yTextToInsertDelta(yText);
|
|
601
600
|
insertDelta.forEach(({ insert }, i) => {
|
|
602
|
-
if (insert instanceof
|
|
601
|
+
if (insert instanceof XmlText) {
|
|
603
602
|
Object.assign(
|
|
604
603
|
positions,
|
|
605
604
|
getAbsolutePositionsInYText(
|
|
@@ -621,7 +620,7 @@ function getStoredPositionsInDeltaAbsolute(sharedRoot, yText, delta, deltaOffset
|
|
|
621
620
|
})
|
|
622
621
|
};
|
|
623
622
|
delta.forEach(({ insert }, i) => {
|
|
624
|
-
if (insert instanceof
|
|
623
|
+
if (insert instanceof XmlText) {
|
|
625
624
|
Object.assign(
|
|
626
625
|
positions,
|
|
627
626
|
getAbsolutePositionsInYText(absolutePositions, insert, i.toString())
|
|
@@ -637,7 +636,7 @@ function restoreStoredPositionsWithDeltaAbsolute(sharedRoot, yText, absolutePosi
|
|
|
637
636
|
setStoredPosition(
|
|
638
637
|
sharedRoot,
|
|
639
638
|
key,
|
|
640
|
-
|
|
639
|
+
createRelativePositionFromTypeIndex(
|
|
641
640
|
yText,
|
|
642
641
|
position.index - previousDeltaOffset + newDeltaOffset,
|
|
643
642
|
position.assoc
|
|
@@ -646,7 +645,7 @@ function restoreStoredPositionsWithDeltaAbsolute(sharedRoot, yText, absolutePosi
|
|
|
646
645
|
});
|
|
647
646
|
}
|
|
648
647
|
delta.forEach(({ insert }, i) => {
|
|
649
|
-
if (insert instanceof
|
|
648
|
+
if (insert instanceof XmlText) {
|
|
650
649
|
restoreStoredPositionsWithDeltaAbsolute(
|
|
651
650
|
sharedRoot,
|
|
652
651
|
insert,
|
|
@@ -1292,72 +1291,46 @@ function withCursors(editor, awareness, {
|
|
|
1292
1291
|
return e;
|
|
1293
1292
|
}
|
|
1294
1293
|
const EDITOR_TO_CURSOR_STORE = new toRawWeakMap();
|
|
1295
|
-
function
|
|
1296
|
-
|
|
1297
|
-
const
|
|
1298
|
-
const
|
|
1299
|
-
const
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
event.added.forEach(addChanged);
|
|
1306
|
-
event.removed.forEach(addChanged);
|
|
1307
|
-
event.updated.forEach(addChanged);
|
|
1308
|
-
onStoreChangeListeners.forEach((listener) => listener());
|
|
1309
|
-
};
|
|
1310
|
-
CursorEditor.on(editor, "change", changeHandler);
|
|
1311
|
-
}
|
|
1312
|
-
return () => {
|
|
1313
|
-
onStoreChangeListeners.delete(onStoreChange);
|
|
1314
|
-
if (changeHandler && onStoreChangeListeners.size === 0) {
|
|
1315
|
-
CursorEditor.off(editor, "change", changeHandler);
|
|
1316
|
-
changeHandler = null;
|
|
1317
|
-
}
|
|
1318
|
-
};
|
|
1319
|
-
};
|
|
1320
|
-
const getSnapshot = () => {
|
|
1321
|
-
if (changed.size === 0) {
|
|
1294
|
+
function useRemoteCursorStateStore() {
|
|
1295
|
+
const editor = useEditor();
|
|
1296
|
+
const cursors = ref({});
|
|
1297
|
+
const changed = ref(/* @__PURE__ */ new Set());
|
|
1298
|
+
const addChanged = changed.value.add.bind(changed.value);
|
|
1299
|
+
const changeHandler = (event) => {
|
|
1300
|
+
event.added.forEach(addChanged);
|
|
1301
|
+
event.removed.forEach(addChanged);
|
|
1302
|
+
event.updated.forEach(addChanged);
|
|
1303
|
+
if (changed.value.size === 0) {
|
|
1322
1304
|
return cursors;
|
|
1323
1305
|
}
|
|
1324
|
-
changed.forEach((clientId) => {
|
|
1306
|
+
changed.value.forEach((clientId) => {
|
|
1325
1307
|
const state = CursorEditor.cursorState(editor, clientId);
|
|
1326
1308
|
if (state === null) {
|
|
1327
|
-
delete cursors[clientId.toString()];
|
|
1309
|
+
delete cursors.value[clientId.toString()];
|
|
1328
1310
|
return;
|
|
1329
1311
|
}
|
|
1330
|
-
cursors[clientId] = state;
|
|
1312
|
+
cursors.value[clientId] = state;
|
|
1331
1313
|
});
|
|
1332
|
-
changed.clear();
|
|
1333
|
-
cursors = { ...cursors };
|
|
1334
|
-
return cursors;
|
|
1314
|
+
changed.value.clear();
|
|
1335
1315
|
};
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
const
|
|
1341
|
-
if (existing) {
|
|
1342
|
-
return existing;
|
|
1343
|
-
}
|
|
1344
|
-
const store = createRemoteCursorStateStore(editor);
|
|
1316
|
+
const subscribe = () => {
|
|
1317
|
+
CursorEditor.on(editor, "change", changeHandler);
|
|
1318
|
+
return () => CursorEditor.off(editor, "change", changeHandler);
|
|
1319
|
+
};
|
|
1320
|
+
const store = [subscribe, cursors];
|
|
1345
1321
|
EDITOR_TO_CURSOR_STORE.set(editor, store);
|
|
1346
1322
|
return store;
|
|
1347
1323
|
}
|
|
1348
1324
|
function useRemoteCursorStates() {
|
|
1349
|
-
const [subscribe,
|
|
1350
|
-
const snapshot = ref(getSnapshot());
|
|
1351
|
-
const handleStoreChange = () => snapshot.value = getSnapshot();
|
|
1325
|
+
const [subscribe, cursors] = useRemoteCursorStateStore();
|
|
1352
1326
|
let unsubscribe;
|
|
1353
1327
|
onMounted(() => {
|
|
1354
|
-
unsubscribe = subscribe(
|
|
1355
|
-
handleStoreChange();
|
|
1328
|
+
unsubscribe = subscribe();
|
|
1356
1329
|
});
|
|
1357
1330
|
onUnmounted(() => {
|
|
1358
1331
|
unsubscribe == null ? void 0 : unsubscribe();
|
|
1359
1332
|
});
|
|
1360
|
-
return
|
|
1333
|
+
return cursors;
|
|
1361
1334
|
}
|
|
1362
1335
|
function useUnsetCursorPositionOnBlur() {
|
|
1363
1336
|
const editor = useEditor();
|