slate-vue3 0.3.2 → 0.3.3
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.
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Ref } from 'vue';
|
|
2
2
|
import { BaseRange, NodeMatch, Text } from '../../slate/index.ts';
|
|
3
|
-
import { toRawWeakMap as WeakMap } from '../../share-tools/index.ts';
|
|
4
3
|
import { JsonObject } from '@liveblocks/client';
|
|
5
4
|
import { CursorState } from '../plugins/withCursors';
|
|
6
5
|
import { CaretPosition, SelectionRect } from './utils';
|
|
@@ -9,4 +8,4 @@ export type CursorOverlayData<TCursorData extends JsonObject> = CursorState<TCur
|
|
|
9
8
|
caretPosition: CaretPosition | null;
|
|
10
9
|
selectionRects: SelectionRect[];
|
|
11
10
|
};
|
|
12
|
-
export declare function useRemoteCursorOverlayPositions<TCursorData extends JsonObject, TContainer extends HTMLElement = HTMLDivElement>(containerRef: Ref<TContainer>, shouldGenerateOverlay?: NodeMatch<Text>): readonly [import('vue').ComputedRef<CursorOverlayData<TCursorData>[]>, () =>
|
|
11
|
+
export declare function useRemoteCursorOverlayPositions<TCursorData extends JsonObject, TContainer extends HTMLElement = HTMLDivElement>(containerRef: Ref<TContainer>, shouldGenerateOverlay?: NodeMatch<Text>): readonly [import('vue').ComputedRef<CursorOverlayData<TCursorData>[]>, () => void];
|
package/dist/yjs.js
CHANGED
|
@@ -1294,16 +1294,16 @@ const EDITOR_TO_CURSOR_STORE = new toRawWeakMap();
|
|
|
1294
1294
|
function useRemoteCursorStateStore() {
|
|
1295
1295
|
const editor = useEditor();
|
|
1296
1296
|
const cursors = ref({});
|
|
1297
|
-
const changed =
|
|
1298
|
-
const addChanged = changed.
|
|
1297
|
+
const changed = /* @__PURE__ */ new Set();
|
|
1298
|
+
const addChanged = changed.add.bind(changed);
|
|
1299
1299
|
const changeHandler = (event) => {
|
|
1300
1300
|
event.added.forEach(addChanged);
|
|
1301
1301
|
event.removed.forEach(addChanged);
|
|
1302
1302
|
event.updated.forEach(addChanged);
|
|
1303
|
-
if (changed.
|
|
1303
|
+
if (changed.size === 0) {
|
|
1304
1304
|
return cursors;
|
|
1305
1305
|
}
|
|
1306
|
-
changed.
|
|
1306
|
+
changed.forEach((clientId) => {
|
|
1307
1307
|
const state = CursorEditor.cursorState(editor, clientId);
|
|
1308
1308
|
if (state === null) {
|
|
1309
1309
|
delete cursors.value[clientId.toString()];
|
|
@@ -1311,7 +1311,7 @@ function useRemoteCursorStateStore() {
|
|
|
1311
1311
|
}
|
|
1312
1312
|
cursors.value[clientId] = state;
|
|
1313
1313
|
});
|
|
1314
|
-
changed.
|
|
1314
|
+
changed.clear();
|
|
1315
1315
|
};
|
|
1316
1316
|
const subscribe = () => {
|
|
1317
1317
|
CursorEditor.on(editor, "change", changeHandler);
|
|
@@ -1479,8 +1479,7 @@ function useRemoteCursorOverlayPositions(containerRef, shouldGenerateOverlay) {
|
|
|
1479
1479
|
const cursorStates = useRemoteCursorStates();
|
|
1480
1480
|
const overlayPositionCache = ref(new toRawWeakMap());
|
|
1481
1481
|
const overlayPositions = ref({});
|
|
1482
|
-
|
|
1483
|
-
onUpdated(() => {
|
|
1482
|
+
const flushOverlayCursor = () => {
|
|
1484
1483
|
if (!containerRef.value) {
|
|
1485
1484
|
return;
|
|
1486
1485
|
}
|
|
@@ -1511,7 +1510,13 @@ function useRemoteCursorOverlayPositions(containerRef, shouldGenerateOverlay) {
|
|
|
1511
1510
|
if (overlayPositionsChanged) {
|
|
1512
1511
|
overlayPositions.value = updated;
|
|
1513
1512
|
}
|
|
1514
|
-
}
|
|
1513
|
+
};
|
|
1514
|
+
const refresh = () => {
|
|
1515
|
+
overlayPositionCache.value = new toRawWeakMap();
|
|
1516
|
+
flushOverlayCursor();
|
|
1517
|
+
};
|
|
1518
|
+
useOnResize(containerRef, refresh);
|
|
1519
|
+
onUpdated(flushOverlayCursor);
|
|
1515
1520
|
const overlayData = computed(
|
|
1516
1521
|
() => Object.entries(cursorStates.value).map(([clientId, state]) => {
|
|
1517
1522
|
const range = state.selection && getCursorRange(editor, state);
|
|
@@ -1524,7 +1529,6 @@ function useRemoteCursorOverlayPositions(containerRef, shouldGenerateOverlay) {
|
|
|
1524
1529
|
};
|
|
1525
1530
|
})
|
|
1526
1531
|
);
|
|
1527
|
-
const refresh = () => overlayPositionCache.value = new toRawWeakMap();
|
|
1528
1532
|
return [overlayData, refresh];
|
|
1529
1533
|
}
|
|
1530
1534
|
export {
|