@slate-yjs/core 0.1.1 → 0.2.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/README.md +3 -0
- package/dist/applyToSlate/index.d.ts +19 -19
- package/dist/applyToSlate/index.d.ts.map +1 -1
- package/dist/applyToSlate/textEvent.d.ts +3 -3
- package/dist/applyToSlate/textEvent.d.ts.map +1 -1
- package/dist/applyToYjs/index.d.ts +3 -3
- package/dist/applyToYjs/node/index.d.ts +3 -3
- package/dist/applyToYjs/node/insertNode.d.ts +3 -3
- package/dist/applyToYjs/node/mergeNode.d.ts +3 -3
- package/dist/applyToYjs/node/moveNode.d.ts +3 -3
- package/dist/applyToYjs/node/removeNode.d.ts +3 -3
- package/dist/applyToYjs/node/setNode.d.ts +3 -3
- package/dist/applyToYjs/node/splitNode.d.ts +3 -3
- package/dist/applyToYjs/text/index.d.ts +3 -3
- package/dist/applyToYjs/text/insertText.d.ts +3 -3
- package/dist/applyToYjs/text/removeText.d.ts +3 -3
- package/dist/applyToYjs/types.d.ts +8 -8
- package/dist/index.cjs +1280 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.global.js +10418 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +1257 -10
- package/dist/index.js.map +1 -1
- package/dist/model/types.d.ts +37 -37
- package/dist/plugins/index.d.ts +3 -3
- package/dist/plugins/withCursors.d.ts +38 -38
- package/dist/plugins/withYHistory.d.ts +19 -14
- package/dist/plugins/withYHistory.d.ts.map +1 -1
- package/dist/plugins/withYjs.d.ts +42 -39
- package/dist/plugins/withYjs.d.ts.map +1 -1
- package/dist/utils/clone.d.ts +4 -4
- package/dist/utils/convert.d.ts +7 -7
- package/dist/utils/delta.d.ts +7 -6
- package/dist/utils/delta.d.ts.map +1 -1
- package/dist/utils/location.d.ts +11 -11
- package/dist/utils/object.d.ts +9 -6
- package/dist/utils/object.d.ts.map +1 -1
- package/dist/utils/position.d.ts +19 -19
- package/dist/utils/position.d.ts.map +1 -1
- package/dist/utils/slate.d.ts +2 -2
- package/dist/utils/slate.d.ts.map +1 -1
- package/dist/utils/yjs.d.ts +4 -4
- package/package.json +12 -12
- package/src/applyToSlate/index.ts +2 -2
- package/src/applyToSlate/textEvent.ts +21 -20
- package/src/plugins/withYHistory.ts +109 -65
- package/src/plugins/withYjs.ts +68 -33
- package/src/utils/delta.ts +36 -1
- package/src/utils/object.ts +65 -20
- package/src/utils/position.ts +1 -1
- package/src/utils/slate.ts +3 -3
- package/test/collaboration/addMark/acrossMarks.tsx +40 -0
- package/test/collaboration/addMark/acrossMarksSame.tsx +36 -0
- package/test/collaboration/addMark/atBeginningOfDocument.tsx +27 -0
- package/test/collaboration/addMark/atEndOfDocument.tsx +30 -0
- package/test/collaboration/addMark/withOtherMarks.tsx +31 -0
- package/test/collaboration/insertNode/atBeginningOfDocument.tsx +28 -0
- package/test/collaboration/insertNode/atEndOfDocument.tsx +28 -0
- package/test/collaboration/insertNode/inTheMiddle.tsx +30 -0
- package/test/collaboration/insertText/atBeginningOfBlock.tsx +26 -0
- package/test/collaboration/insertText/atBeginningOfDocument.tsx +26 -0
- package/test/collaboration/insertText/atEndOfBlock.tsx +26 -0
- package/test/collaboration/insertText/atEndOfDocument.tsx +26 -0
- package/test/collaboration/insertText/inTheMiddle.tsx +32 -0
- package/test/collaboration/insertText/inTheMiddleOfNestedBlock.tsx +30 -0
- package/test/collaboration/insertText/insideMarks.tsx +28 -0
- package/test/collaboration/insertText/withEmptyString.tsx +25 -0
- package/test/collaboration/insertText/withEntities.tsx +28 -0
- package/test/collaboration/insertText/withMarks.tsx +25 -0
- package/test/collaboration/insertText/withUnicode.tsx +28 -0
- package/test/collaboration/mergeNode/afterADeleteBackward.tsx +27 -0
- package/test/collaboration/mergeNode/onMixedNestedNodes.tsx +29 -0
- package/test/collaboration/mergeNode/onMixedTypeNodes.tsx +27 -0
- package/test/collaboration/mergeNode/withUnicode.tsx +25 -0
- package/test/collaboration/moveNode/downward/whenBlockBecomesNested.tsx +43 -0
- package/test/collaboration/moveNode/downward/whenBlockBecomesNonNested.tsx +41 -0
- package/test/collaboration/moveNode/downward/whenBlockStaysNested.tsx +38 -0
- package/test/collaboration/moveNode/downward/whenBlockStaysNonNested.tsx +30 -0
- package/test/collaboration/moveNode/upward/whenBlockBecomesNested.tsx +43 -0
- package/test/collaboration/moveNode/upward/whenBlockBecomesNonNested.tsx +41 -0
- package/test/collaboration/moveNode/upward/whenBlockStaysNested.tsx +38 -0
- package/test/collaboration/moveNode/upward/whenBlockStaysNonNested.tsx +30 -0
- package/test/collaboration/removeMark/inTheMiddleOfText.tsx +43 -0
- package/test/collaboration/removeMark/withAddMark.tsx +31 -0
- package/test/collaboration/removeMark/withOtherMarks.tsx +47 -0
- package/test/collaboration/removeNode/atBeginningOfDocument.tsx +26 -0
- package/test/collaboration/removeNode/atEndOfDocument.tsx +26 -0
- package/test/collaboration/removeNode/nestedBlock.tsx +28 -0
- package/test/collaboration/removeNode/wrapperBlock.tsx +28 -0
- package/test/collaboration/removeText/atBeginningOfDocument.tsx +34 -0
- package/test/collaboration/removeText/atEndOfDocument.tsx +37 -0
- package/test/collaboration/removeText/withUnicode.tsx +29 -0
- package/test/collaboration/setNode/atBeginningOfDocument.tsx +27 -0
- package/test/collaboration/setNode/atEndOfDocument.tsx +27 -0
- package/test/collaboration/setNode/onDataChange.tsx +35 -0
- package/test/collaboration/setNode/onDataChangeOnInline.tsx +35 -0
- package/test/collaboration/setNode/onResetBlock.tsx +27 -0
- package/test/collaboration/setNode/withAChangeOfType.tsx +26 -0
- package/test/collaboration/splitNode/atBeginningOfDocument.tsx +28 -0
- package/test/collaboration/splitNode/atEndOfBlock.tsx +27 -0
- package/test/collaboration/splitNode/atEndOfDocument.tsx +27 -0
- package/test/collaboration/splitNode/onNonDefaultBlock.tsx +27 -0
- package/test/collaboration/splitNode/withMultipleSubNodes.tsx +32 -0
- package/test/collaboration/splitNode/withUnicode.tsx +29 -0
- package/test/index.test.ts +66 -0
- package/test/{types.d.ts → slate.d.ts} +0 -0
- package/test/withTestingElements.ts +46 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/tsup.config.ts +32 -0
- package/dist/applyToSlate/Untitled-1.d.ts +0 -101
- package/dist/applyToSlate/Untitled-1.d.ts.map +0 -1
- package/dist/applyToSlate/index.js +0 -32
- package/dist/applyToSlate/index.js.map +0 -1
- package/dist/applyToSlate/textEvent.js +0 -166
- package/dist/applyToSlate/textEvent.js.map +0 -1
- package/dist/applyToYjs/index.js +0 -17
- package/dist/applyToYjs/index.js.map +0 -1
- package/dist/applyToYjs/node/index.js +0 -15
- package/dist/applyToYjs/node/index.js.map +0 -1
- package/dist/applyToYjs/node/insertNode.js +0 -12
- package/dist/applyToYjs/node/insertNode.js.map +0 -1
- package/dist/applyToYjs/node/mergeNode.js +0 -32
- package/dist/applyToYjs/node/mergeNode.js.map +0 -1
- package/dist/applyToYjs/node/moveNode.js +0 -28
- package/dist/applyToYjs/node/moveNode.js.map +0 -1
- package/dist/applyToYjs/node/removeNode.js +0 -6
- package/dist/applyToYjs/node/removeNode.js.map +0 -1
- package/dist/applyToYjs/node/setNode.js +0 -21
- package/dist/applyToYjs/node/setNode.js.map +0 -1
- package/dist/applyToYjs/node/splitNode.js +0 -50
- package/dist/applyToYjs/node/splitNode.js.map +0 -1
- package/dist/applyToYjs/text/index.js +0 -7
- package/dist/applyToYjs/text/index.js.map +0 -1
- package/dist/applyToYjs/text/insertText.js +0 -12
- package/dist/applyToYjs/text/insertText.js.map +0 -1
- package/dist/applyToYjs/text/removeText.js +0 -6
- package/dist/applyToYjs/text/removeText.js.map +0 -1
- package/dist/applyToYjs/types.js +0 -2
- package/dist/applyToYjs/types.js.map +0 -1
- package/dist/index.modern.js +0 -2
- package/dist/index.modern.js.map +0 -1
- package/dist/index.module.js +0 -2
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/model/types.js +0 -2
- package/dist/model/types.js.map +0 -1
- package/dist/plugins/index.js +0 -4
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/withCursors.js +0 -145
- package/dist/plugins/withCursors.js.map +0 -1
- package/dist/plugins/withYHistory.js +0 -66
- package/dist/plugins/withYHistory.js.map +0 -1
- package/dist/plugins/withYjs.js +0 -155
- package/dist/plugins/withYjs.js.map +0 -1
- package/dist/utils/clone.js +0 -23
- package/dist/utils/clone.js.map +0 -1
- package/dist/utils/convert.js +0 -35
- package/dist/utils/convert.js.map +0 -1
- package/dist/utils/delta.js +0 -42
- package/dist/utils/delta.js.map +0 -1
- package/dist/utils/location.js +0 -111
- package/dist/utils/location.js.map +0 -1
- package/dist/utils/object.js +0 -27
- package/dist/utils/object.js.map +0 -1
- package/dist/utils/position.js +0 -140
- package/dist/utils/position.js.map +0 -1
- package/dist/utils/slate.js +0 -6
- package/dist/utils/slate.js.map +0 -1
- package/dist/utils/yjs.js +0 -7
- package/dist/utils/yjs.js.map +0 -1
- package/test/collaboration.test.ts +0 -395
- package/test/concurrent.test.ts +0 -233
- package/test/testEditor.ts +0 -134
- package/test/utils.ts +0 -64
package/dist/utils/object.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
declare type InspectableObject = Record<string | number | symbol, unknown>;
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function deepEquals(
|
|
4
|
-
export declare function pick<TObj
|
|
5
|
-
export declare function omit<TObj
|
|
6
|
-
export {
|
|
1
|
+
declare type InspectableObject = Record<string | number | symbol, unknown>;
|
|
2
|
+
export declare function isPlainObject(o: unknown): o is InspectableObject;
|
|
3
|
+
export declare function deepEquals(node: InspectableObject, another: InspectableObject): boolean;
|
|
4
|
+
export declare function pick<TObj, TKeys extends keyof TObj>(obj: TObj, ...keys: TKeys[]): Pick<TObj, TKeys>;
|
|
5
|
+
export declare function omit<TObj, TKeys extends keyof TObj>(obj: TObj, ...keys: TKeys[]): Omit<TObj, TKeys>;
|
|
6
|
+
export declare function omitNullEntries<TObj>(obj: TObj): {
|
|
7
|
+
[K in keyof TObj]: TObj[K] extends null ? never : K;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
7
10
|
//# sourceMappingURL=object.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA,aAAK,iBAAiB,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA,aAAK,iBAAiB,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC;AAMnE,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,iBAAiB,CAwBhE;AAID,wBAAgB,UAAU,CACxB,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CA6BT;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,KAAK,SAAS,MAAM,IAAI,EACjD,GAAG,EAAE,IAAI,EACT,GAAG,IAAI,EAAE,KAAK,EAAE,GACf,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAInB;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,KAAK,SAAS,MAAM,IAAI,EACjD,GAAG,EAAE,IAAI,EACT,GAAG,IAAI,EAAE,KAAK,EAAE,GACf,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAInB;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,GAAG;KAC/C,CAAC,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC;CACpD,CAIA"}
|
package/dist/utils/position.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { BasePoint, BaseRange, Node } from 'slate';
|
|
2
|
-
import * as Y from 'yjs';
|
|
3
|
-
import { InsertDelta, RelativeRange } from '../model/types';
|
|
4
|
-
export declare const STORED_POSITION_PREFIX = "__slateYjsStoredPosition_";
|
|
5
|
-
export declare function slatePointToRelativePosition(sharedRoot: Y.XmlText, slateRoot: Node, point: BasePoint): Y.RelativePosition;
|
|
6
|
-
export declare function absolutePositionToSlatePoint(sharedRoot: Y.XmlText, slateRoot: Node, { type, index, assoc }: Y.AbsolutePosition): BasePoint | null;
|
|
7
|
-
export declare function relativePositionToSlatePoint(sharedRoot: Y.XmlText, slateRoot: Node, pos: Y.RelativePosition): BasePoint | null;
|
|
8
|
-
export declare function getStoredPosition(sharedRoot: Y.XmlText, key: string): Y.RelativePosition | null;
|
|
9
|
-
export declare function getStoredPositions(sharedRoot: Y.XmlText): Record<string, Y.RelativePosition>;
|
|
10
|
-
export declare function removeStoredPosition(sharedRoot: Y.XmlText, key: string): void;
|
|
11
|
-
export declare function setStoredPosition(sharedRoot: Y.XmlText, key: string, position: Y.RelativePosition): void;
|
|
12
|
-
export declare function getStoredPositionsInDeltaAbsolute(sharedRoot: Y.XmlText, yText: Y.XmlText, delta: InsertDelta, deltaOffset?: number): {
|
|
13
|
-
'': {
|
|
14
|
-
[k: string]: Y.AbsolutePosition;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export declare function restoreStoredPositionsWithDeltaAbsolute(sharedRoot: Y.XmlText, yText: Y.XmlText, absolutePositions: Record<string, Record<string, Y.AbsolutePosition>>, delta: InsertDelta, newDeltaOffset?: number, previousDeltaOffset?: number, path?: string): void;
|
|
18
|
-
export declare function slateRangeToRelativeRange(sharedRoot: Y.XmlText, slateRoot: Node, range: BaseRange): RelativeRange;
|
|
19
|
-
export declare function relativeRangeToSlateRange(sharedRoot: Y.XmlText, slateRoot: Node, range: RelativeRange): BaseRange | null;
|
|
1
|
+
import { BasePoint, BaseRange, Node } from 'slate';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
import { InsertDelta, RelativeRange } from '../model/types';
|
|
4
|
+
export declare const STORED_POSITION_PREFIX = "__slateYjsStoredPosition_";
|
|
5
|
+
export declare function slatePointToRelativePosition(sharedRoot: Y.XmlText, slateRoot: Node, point: BasePoint): Y.RelativePosition;
|
|
6
|
+
export declare function absolutePositionToSlatePoint(sharedRoot: Y.XmlText, slateRoot: Node, { type, index, assoc }: Y.AbsolutePosition): BasePoint | null;
|
|
7
|
+
export declare function relativePositionToSlatePoint(sharedRoot: Y.XmlText, slateRoot: Node, pos: Y.RelativePosition): BasePoint | null;
|
|
8
|
+
export declare function getStoredPosition(sharedRoot: Y.XmlText, key: string): Y.RelativePosition | null;
|
|
9
|
+
export declare function getStoredPositions(sharedRoot: Y.XmlText): Record<string, Y.RelativePosition>;
|
|
10
|
+
export declare function removeStoredPosition(sharedRoot: Y.XmlText, key: string): void;
|
|
11
|
+
export declare function setStoredPosition(sharedRoot: Y.XmlText, key: string, position: Y.RelativePosition): void;
|
|
12
|
+
export declare function getStoredPositionsInDeltaAbsolute(sharedRoot: Y.XmlText, yText: Y.XmlText, delta: InsertDelta, deltaOffset?: number): {
|
|
13
|
+
'': {
|
|
14
|
+
[k: string]: Y.AbsolutePosition;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare function restoreStoredPositionsWithDeltaAbsolute(sharedRoot: Y.XmlText, yText: Y.XmlText, absolutePositions: Record<string, Record<string, Y.AbsolutePosition>>, delta: InsertDelta, newDeltaOffset?: number, previousDeltaOffset?: number, path?: string): void;
|
|
18
|
+
export declare function slateRangeToRelativeRange(sharedRoot: Y.XmlText, slateRoot: Node, range: BaseRange): RelativeRange;
|
|
19
|
+
export declare function relativeRangeToSlateRange(sharedRoot: Y.XmlText, slateRoot: Node, range: RelativeRange): BaseRange | null;
|
|
20
20
|
//# sourceMappingURL=position.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/utils/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/utils/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAQ,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,aAAa,EAAa,MAAM,gBAAgB,CAAC;AAKvE,eAAO,MAAM,sBAAsB,8BAA8B,CAAC;AAElE,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,CAAC,CAAC,OAAO,EACrB,SAAS,EAAE,IAAI,EACf,KAAK,EAAE,SAAS,GACf,CAAC,CAAC,gBAAgB,CAkBpB;AAED,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,CAAC,CAAC,OAAO,EACrB,SAAS,EAAE,IAAI,EACf,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,gBAAgB,GACzC,SAAS,GAAG,IAAI,CAwBlB;AAED,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,CAAC,CAAC,OAAO,EACrB,SAAS,EAAE,IAAI,EACf,GAAG,EAAE,CAAC,CAAC,gBAAgB,GACtB,SAAS,GAAG,IAAI,CAWlB;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,CAAC,CAAC,OAAO,EACrB,GAAG,EAAE,MAAM,GACV,CAAC,CAAC,gBAAgB,GAAG,IAAI,CAO3B;AAED,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,CAAC,CAAC,OAAO,GACpB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,gBAAgB,CAAC,CASpC;AAsBD,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,QAEtE;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,CAAC,CAAC,OAAO,EACrB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,CAAC,CAAC,gBAAgB,QAM7B;AAkDD,wBAAgB,iCAAiC,CAC/C,UAAU,EAAE,CAAC,CAAC,OAAO,EACrB,KAAK,EAAE,CAAC,CAAC,OAAO,EAChB,KAAK,EAAE,WAAW,EAClB,WAAW,SAAI;;;;EAqBhB;AAED,wBAAgB,uCAAuC,CACrD,UAAU,EAAE,CAAC,CAAC,OAAO,EACrB,KAAK,EAAE,CAAC,CAAC,OAAO,EAChB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,gBAAgB,CAAC,CAAC,EACrE,KAAK,EAAE,WAAW,EAClB,cAAc,SAAI,EAClB,mBAAmB,SAAI,EACvB,IAAI,SAAK,QA+BV;AAED,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,CAAC,CAAC,OAAO,EACrB,SAAS,EAAE,IAAI,EACf,KAAK,EAAE,SAAS,GACf,aAAa,CAKf;AAED,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,CAAC,CAAC,OAAO,EACrB,SAAS,EAAE,IAAI,EACf,KAAK,EAAE,aAAa,GACnB,SAAS,GAAG,IAAI,CAsBlB"}
|
package/dist/utils/slate.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function getProperties<TNode extends Descendant>(node: TNode): Omit<TNode, TNode extends
|
|
1
|
+
import { BaseText, Descendant } from 'slate';
|
|
2
|
+
export declare function getProperties<TNode extends Descendant>(node: TNode): Omit<TNode, TNode extends BaseText ? 'text' : 'children'>;
|
|
3
3
|
//# sourceMappingURL=slate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slate.d.ts","sourceRoot":"","sources":["../../src/utils/slate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"slate.d.ts","sourceRoot":"","sources":["../../src/utils/slate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAQ,MAAM,OAAO,CAAC;AAGnD,wBAAgB,aAAa,CAAC,KAAK,SAAS,UAAU,EACpD,IAAI,EAAE,KAAK,GACV,IAAI,CAAC,KAAK,EAAE,KAAK,SAAS,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC,CAK3D"}
|
package/dist/utils/yjs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as Y from 'yjs';
|
|
2
|
-
export declare function assertDocumentAttachment<T extends Y.AbstractType<any>>(sharedType: T): asserts sharedType is T & {
|
|
3
|
-
doc: NonNullable<T['doc']>;
|
|
4
|
-
};
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
export declare function assertDocumentAttachment<T extends Y.AbstractType<any>>(sharedType: T): asserts sharedType is T & {
|
|
3
|
+
doc: NonNullable<T['doc']>;
|
|
4
|
+
};
|
|
5
5
|
//# sourceMappingURL=yjs.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slate-yjs/core",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"description": "Yjs binding for Slate.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"slate",
|
|
@@ -9,18 +9,17 @@
|
|
|
9
9
|
"collaborative"
|
|
10
10
|
],
|
|
11
11
|
"type": "module",
|
|
12
|
-
"source": "src/index.ts",
|
|
13
12
|
"exports": {
|
|
14
13
|
"require": "./dist/index.cjs",
|
|
15
|
-
"default": "./dist/index.
|
|
14
|
+
"default": "./dist/index.js"
|
|
16
15
|
},
|
|
17
16
|
"main": "dist/index.cjs",
|
|
18
|
-
"module": "dist/index.
|
|
19
|
-
"unpkg": "dist/index.
|
|
17
|
+
"module": "dist/index.js",
|
|
18
|
+
"unpkg": "dist/index.global.js",
|
|
20
19
|
"types": "dist/index.d.ts",
|
|
21
20
|
"scripts": {
|
|
22
|
-
"build": "yarn run
|
|
23
|
-
"dev": "yarn run
|
|
21
|
+
"build": "yarn run tsup && tsc --emitDeclarationOnly",
|
|
22
|
+
"dev": "yarn run tsup --watch"
|
|
24
23
|
},
|
|
25
24
|
"repository": {
|
|
26
25
|
"type": "git",
|
|
@@ -28,14 +27,15 @@
|
|
|
28
27
|
},
|
|
29
28
|
"license": "MIT",
|
|
30
29
|
"devDependencies": {
|
|
31
|
-
"
|
|
32
|
-
"slate": ">=0.70.0",
|
|
30
|
+
"slate": "0.75.0",
|
|
33
31
|
"slate-hyperscript": "^0.67.0",
|
|
34
|
-
"
|
|
32
|
+
"tsup": "^5.12.1",
|
|
33
|
+
"typescript": "^4.4.4",
|
|
34
|
+
"yjs": "^13.5.29"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"slate": "
|
|
38
|
-
"yjs": "^13.5.
|
|
37
|
+
"slate": ">=0.70.0",
|
|
38
|
+
"yjs": "^13.5.29"
|
|
39
39
|
},
|
|
40
40
|
"bugs": {
|
|
41
41
|
"url": "https://github.com/BitPhinix/slate-yjs/issues"
|
|
@@ -12,7 +12,7 @@ import { translateYTextEvent } from './textEvent';
|
|
|
12
12
|
export function translateYjsEvent(
|
|
13
13
|
sharedRoot: Y.XmlText,
|
|
14
14
|
editor: Editor,
|
|
15
|
-
event: Y.YEvent
|
|
15
|
+
event: Y.YEvent<Y.XmlText>
|
|
16
16
|
): Operation[] {
|
|
17
17
|
if (event instanceof Y.YTextEvent) {
|
|
18
18
|
return translateYTextEvent(sharedRoot, editor, event);
|
|
@@ -32,7 +32,7 @@ export function translateYjsEvent(
|
|
|
32
32
|
export function applyYjsEvents(
|
|
33
33
|
sharedRoot: Y.XmlText,
|
|
34
34
|
editor: Editor,
|
|
35
|
-
events: Y.YEvent[]
|
|
35
|
+
events: Y.YEvent<Y.XmlText>[]
|
|
36
36
|
) {
|
|
37
37
|
Editor.withoutNormalizing(editor, () => {
|
|
38
38
|
events.forEach((event) => {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
getSlatePath,
|
|
8
8
|
yOffsetToSlateOffsets,
|
|
9
9
|
} from '../utils/location';
|
|
10
|
-
import { deepEquals, pick } from '../utils/object';
|
|
10
|
+
import { deepEquals, omitNullEntries, pick } from '../utils/object';
|
|
11
11
|
import { getProperties } from '../utils/slate';
|
|
12
12
|
|
|
13
13
|
function applyDelta(node: Element, slatePath: Path, delta: Delta): Operation[] {
|
|
@@ -34,55 +34,56 @@ function applyDelta(node: Element, slatePath: Path, delta: Delta): Operation[] {
|
|
|
34
34
|
);
|
|
35
35
|
const [endPathOffset, endTextOffset] = yOffsetToSlateOffsets(
|
|
36
36
|
node,
|
|
37
|
-
yOffset
|
|
37
|
+
yOffset,
|
|
38
|
+
{ assoc: -1 }
|
|
38
39
|
);
|
|
39
40
|
|
|
40
41
|
for (
|
|
41
|
-
let pathOffset =
|
|
42
|
-
endTextOffset === 0 ? endPathOffset - 1 : endPathOffset;
|
|
42
|
+
let pathOffset = endPathOffset;
|
|
43
43
|
pathOffset >= startPathOffset;
|
|
44
44
|
pathOffset--
|
|
45
45
|
) {
|
|
46
46
|
const child = node.children[pathOffset];
|
|
47
|
-
|
|
47
|
+
const childPath = [...slatePath, pathOffset];
|
|
48
48
|
|
|
49
49
|
const newProperties = change.attributes;
|
|
50
|
+
const properties = pick(
|
|
51
|
+
node,
|
|
52
|
+
...(Object.keys(change.attributes) as Array<keyof Element>)
|
|
53
|
+
);
|
|
50
54
|
|
|
51
55
|
if (
|
|
52
56
|
Text.isText(child) &&
|
|
53
57
|
(pathOffset === startPathOffset || pathOffset === endPathOffset)
|
|
54
58
|
) {
|
|
55
59
|
const start = pathOffset === startPathOffset ? startTextOffset : 0;
|
|
56
|
-
|
|
60
|
+
const end =
|
|
57
61
|
pathOffset === endPathOffset ? endTextOffset : child.text.length;
|
|
58
62
|
|
|
59
|
-
|
|
60
|
-
if (start !== 0) {
|
|
63
|
+
if (end !== child.text.length) {
|
|
61
64
|
ops.push({
|
|
62
65
|
type: 'split_node',
|
|
63
66
|
path: childPath,
|
|
64
|
-
position:
|
|
65
|
-
properties:
|
|
67
|
+
position: end,
|
|
68
|
+
properties: getProperties(child),
|
|
66
69
|
});
|
|
67
|
-
|
|
68
|
-
childPath = Path.next(childPath);
|
|
69
|
-
end -= start;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
if (
|
|
72
|
+
if (start !== 0) {
|
|
73
73
|
ops.push({
|
|
74
74
|
type: 'split_node',
|
|
75
75
|
path: childPath,
|
|
76
|
-
position:
|
|
77
|
-
properties: {
|
|
76
|
+
position: start,
|
|
77
|
+
properties: omitNullEntries({
|
|
78
|
+
...getProperties(child),
|
|
79
|
+
...newProperties,
|
|
80
|
+
}),
|
|
78
81
|
});
|
|
82
|
+
|
|
83
|
+
continue;
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
|
|
82
|
-
const properties = pick(
|
|
83
|
-
node,
|
|
84
|
-
...(Object.keys(change.attributes) as Array<keyof Element>)
|
|
85
|
-
);
|
|
86
87
|
ops.push({
|
|
87
88
|
type: 'set_node',
|
|
88
89
|
newProperties,
|
|
@@ -8,10 +8,15 @@ import {
|
|
|
8
8
|
import { YjsEditor } from './withYjs';
|
|
9
9
|
|
|
10
10
|
const LAST_SELECTION: WeakMap<Editor, RelativeRange | null> = new WeakMap();
|
|
11
|
+
const DEFAULT_WITHOUT_SAVING_ORIGIN = Symbol(
|
|
12
|
+
'slate-yjs-history-without-saving'
|
|
13
|
+
);
|
|
11
14
|
|
|
12
15
|
export type YHistoryEditor = YjsEditor & {
|
|
13
16
|
undoManager: Y.UndoManager;
|
|
14
17
|
|
|
18
|
+
withoutSavingOrigin: unknown;
|
|
19
|
+
|
|
15
20
|
undo: () => void;
|
|
16
21
|
redo: () => void;
|
|
17
22
|
};
|
|
@@ -22,7 +27,8 @@ export const YHistoryEditor = {
|
|
|
22
27
|
YjsEditor.isYjsEditor(value) &&
|
|
23
28
|
(value as YHistoryEditor).undoManager instanceof Y.UndoManager &&
|
|
24
29
|
typeof (value as YHistoryEditor).undo === 'function' &&
|
|
25
|
-
typeof (value as YHistoryEditor).redo === 'function'
|
|
30
|
+
typeof (value as YHistoryEditor).redo === 'function' &&
|
|
31
|
+
'withoutSavingOrigin' in value
|
|
26
32
|
);
|
|
27
33
|
},
|
|
28
34
|
|
|
@@ -33,15 +39,26 @@ export const YHistoryEditor = {
|
|
|
33
39
|
canRedo(editor: YHistoryEditor) {
|
|
34
40
|
return editor.undoManager.redoStack.length > 0;
|
|
35
41
|
},
|
|
42
|
+
|
|
43
|
+
isSaving(editor: YHistoryEditor): boolean {
|
|
44
|
+
return editor.undoManager.trackedOrigins.has(YjsEditor.origin(editor));
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
withoutSaving(editor: YHistoryEditor, fn: () => void) {
|
|
48
|
+
YjsEditor.withOrigin(editor, editor.withoutSavingOrigin, fn);
|
|
49
|
+
},
|
|
36
50
|
};
|
|
37
51
|
|
|
38
52
|
export type WithYHistoryOptions = NonNullable<
|
|
39
53
|
ConstructorParameters<typeof Y.UndoManager>[1]
|
|
40
|
-
|
|
54
|
+
> & {
|
|
55
|
+
withoutSavingOrigin?: unknown;
|
|
56
|
+
};
|
|
41
57
|
|
|
42
58
|
export function withYHistory<T extends YjsEditor>(
|
|
43
59
|
editor: T,
|
|
44
60
|
{
|
|
61
|
+
withoutSavingOrigin = DEFAULT_WITHOUT_SAVING_ORIGIN,
|
|
45
62
|
trackedOrigins = new Set([editor.localOrigin]),
|
|
46
63
|
...options
|
|
47
64
|
}: WithYHistoryOptions = {}
|
|
@@ -53,7 +70,10 @@ export function withYHistory<T extends YjsEditor>(
|
|
|
53
70
|
...options,
|
|
54
71
|
});
|
|
55
72
|
|
|
56
|
-
|
|
73
|
+
e.undoManager = undoManager;
|
|
74
|
+
e.withoutSavingOrigin = withoutSavingOrigin;
|
|
75
|
+
|
|
76
|
+
const { onChange, isLocalOrigin } = e;
|
|
57
77
|
e.onChange = () => {
|
|
58
78
|
onChange();
|
|
59
79
|
|
|
@@ -63,76 +83,100 @@ export function withYHistory<T extends YjsEditor>(
|
|
|
63
83
|
);
|
|
64
84
|
};
|
|
65
85
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
86
|
+
e.isLocalOrigin = (origin) =>
|
|
87
|
+
origin === e.withoutSavingOrigin || isLocalOrigin(origin);
|
|
88
|
+
|
|
89
|
+
const handleStackItemAdded = ({
|
|
90
|
+
stackItem,
|
|
91
|
+
}: {
|
|
92
|
+
stackItem: HistoryStackItem;
|
|
93
|
+
type: 'redo' | 'undo';
|
|
94
|
+
}) => {
|
|
95
|
+
stackItem.meta.set(
|
|
96
|
+
'selection',
|
|
97
|
+
e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection)
|
|
98
|
+
);
|
|
99
|
+
stackItem.meta.set('selectionBefore', LAST_SELECTION.get(e));
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const handleStackItemUpdated = ({
|
|
103
|
+
stackItem,
|
|
104
|
+
}: {
|
|
105
|
+
stackItem: HistoryStackItem;
|
|
106
|
+
type: 'redo' | 'undo';
|
|
107
|
+
}) => {
|
|
108
|
+
stackItem.meta.set(
|
|
109
|
+
'selection',
|
|
110
|
+
e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection)
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const handleStackItemPopped = ({
|
|
115
|
+
stackItem,
|
|
116
|
+
type,
|
|
117
|
+
}: {
|
|
118
|
+
stackItem: HistoryStackItem;
|
|
119
|
+
type: 'redo' | 'undo';
|
|
120
|
+
}) => {
|
|
121
|
+
// TODO: Change once https://github.com/yjs/yjs/issues/353 is resolved
|
|
122
|
+
const inverseStack =
|
|
123
|
+
type === 'undo' ? undoManager.redoStack : undoManager.undoStack;
|
|
124
|
+
const inverseItem = inverseStack[inverseStack.length - 1];
|
|
125
|
+
if (inverseItem) {
|
|
126
|
+
inverseItem.meta.set('selection', stackItem.meta.get('selectionBefore'));
|
|
127
|
+
inverseItem.meta.set('selectionBefore', stackItem.meta.get('selection'));
|
|
77
128
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}: {
|
|
86
|
-
stackItem: HistoryStackItem;
|
|
87
|
-
type: 'redo' | 'undo';
|
|
88
|
-
}) => {
|
|
89
|
-
// TODO: Change once https://github.com/yjs/yjs/issues/353 is resolved
|
|
90
|
-
const inverseStack =
|
|
91
|
-
type === 'undo' ? undoManager.redoStack : undoManager.undoStack;
|
|
92
|
-
const inverseItem = inverseStack[inverseStack.length - 1];
|
|
93
|
-
if (inverseItem) {
|
|
94
|
-
inverseItem.meta.set(
|
|
95
|
-
'selection',
|
|
96
|
-
stackItem.meta.get('selectionBefore')
|
|
97
|
-
);
|
|
98
|
-
inverseItem.meta.set(
|
|
99
|
-
'selectionBefore',
|
|
100
|
-
stackItem.meta.get('selection')
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const relativeSelection = stackItem.meta.get(
|
|
105
|
-
'selectionBefore'
|
|
106
|
-
) as RelativeRange | null;
|
|
107
|
-
|
|
108
|
-
if (!relativeSelection) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const selection = relativeRangeToSlateRange(
|
|
113
|
-
e.sharedRoot,
|
|
114
|
-
e,
|
|
115
|
-
relativeSelection
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
if (!selection) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
Transforms.select(e, selection);
|
|
129
|
+
|
|
130
|
+
const relativeSelection = stackItem.meta.get(
|
|
131
|
+
'selectionBefore'
|
|
132
|
+
) as RelativeRange | null;
|
|
133
|
+
|
|
134
|
+
if (!relativeSelection) {
|
|
135
|
+
return;
|
|
123
136
|
}
|
|
124
|
-
);
|
|
125
137
|
|
|
126
|
-
|
|
138
|
+
const selection = relativeRangeToSlateRange(
|
|
139
|
+
e.sharedRoot,
|
|
140
|
+
e,
|
|
141
|
+
relativeSelection
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
if (!selection) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
Transforms.select(e, selection);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const { connect, disconnect } = e;
|
|
152
|
+
e.connect = () => {
|
|
153
|
+
connect();
|
|
154
|
+
|
|
155
|
+
undoManager.on('stack-item-added', handleStackItemAdded);
|
|
156
|
+
undoManager.on('stack-item-popped', handleStackItemPopped);
|
|
157
|
+
undoManager.on('stack-item-updated', handleStackItemUpdated);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
e.disconnect = () => {
|
|
161
|
+
undoManager.off('stack-item-added', handleStackItemAdded);
|
|
162
|
+
undoManager.off('stack-item-popped', handleStackItemPopped);
|
|
163
|
+
undoManager.off('stack-item-updated', handleStackItemUpdated);
|
|
164
|
+
|
|
165
|
+
disconnect();
|
|
166
|
+
};
|
|
127
167
|
|
|
128
168
|
e.undo = () => {
|
|
129
|
-
YjsEditor.
|
|
130
|
-
|
|
169
|
+
if (YjsEditor.connected(e)) {
|
|
170
|
+
YjsEditor.flushLocalChanges(e);
|
|
171
|
+
e.undoManager.undo();
|
|
172
|
+
}
|
|
131
173
|
};
|
|
132
174
|
|
|
133
175
|
e.redo = () => {
|
|
134
|
-
YjsEditor.
|
|
135
|
-
|
|
176
|
+
if (YjsEditor.connected(e)) {
|
|
177
|
+
YjsEditor.flushLocalChanges(e);
|
|
178
|
+
e.undoManager.redo();
|
|
179
|
+
}
|
|
136
180
|
};
|
|
137
181
|
|
|
138
182
|
return e;
|