@wangeditor-next/yjs 0.1.0
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 +4 -0
- package/dist/applyToSlate/index.d.ts +19 -0
- package/dist/applyToSlate/textEvent.d.ts +3 -0
- package/dist/applyToYjs/index.d.ts +3 -0
- package/dist/applyToYjs/node/index.d.ts +3 -0
- package/dist/applyToYjs/node/insertNode.d.ts +3 -0
- package/dist/applyToYjs/node/mergeNode.d.ts +3 -0
- package/dist/applyToYjs/node/moveNode.d.ts +3 -0
- package/dist/applyToYjs/node/removeNode.d.ts +3 -0
- package/dist/applyToYjs/node/setNode.d.ts +3 -0
- package/dist/applyToYjs/node/splitNode.d.ts +3 -0
- package/dist/applyToYjs/text/index.d.ts +3 -0
- package/dist/applyToYjs/text/insertText.d.ts +3 -0
- package/dist/applyToYjs/text/removeText.d.ts +3 -0
- package/dist/applyToYjs/types.d.ts +8 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/module/custom-types.d.ts +41 -0
- package/dist/plugins/index.d.ts +3 -0
- package/dist/plugins/withCursors.d.ts +55 -0
- package/dist/plugins/withYHistory.d.ts +34 -0
- package/dist/plugins/withYjs.d.ts +52 -0
- package/dist/utils/clone.d.ts +4 -0
- package/dist/utils/convert.d.ts +7 -0
- package/dist/utils/delta.d.ts +7 -0
- package/dist/utils/location.d.ts +11 -0
- package/dist/utils/object.d.ts +9 -0
- package/dist/utils/position.d.ts +19 -0
- package/dist/utils/slate.d.ts +2 -0
- package/dist/utils/yjs.d.ts +4 -0
- package/package.json +67 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Descendant, Editor, Element, Node } from 'slate';
|
|
2
|
+
import type Y from 'yjs';
|
|
3
|
+
export declare type DeltaAttributes = {
|
|
4
|
+
retain: number;
|
|
5
|
+
attributes: Record<string, unknown>;
|
|
6
|
+
};
|
|
7
|
+
export declare type DeltaRetain = {
|
|
8
|
+
retain: number;
|
|
9
|
+
};
|
|
10
|
+
export declare type DeltaDelete = {
|
|
11
|
+
delete: number;
|
|
12
|
+
};
|
|
13
|
+
export declare type DeltaInsert = {
|
|
14
|
+
insert: string | Y.XmlText;
|
|
15
|
+
attributes?: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
export declare type InsertDelta = Array<DeltaInsert>;
|
|
18
|
+
export declare type Delta = Array<DeltaRetain | DeltaDelete | DeltaInsert | DeltaAttributes>;
|
|
19
|
+
export declare type TextRange = {
|
|
20
|
+
start: number;
|
|
21
|
+
end: number;
|
|
22
|
+
};
|
|
23
|
+
export declare type HistoryStackItem = {
|
|
24
|
+
meta: Map<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
export declare type YTarget = {
|
|
27
|
+
textRange: TextRange;
|
|
28
|
+
yParent: Y.XmlText;
|
|
29
|
+
slateParent: Element | Editor;
|
|
30
|
+
yTarget?: Y.XmlText;
|
|
31
|
+
slateTarget?: Node;
|
|
32
|
+
targetDelta: InsertDelta;
|
|
33
|
+
};
|
|
34
|
+
export declare type RelativeRange = {
|
|
35
|
+
anchor: Y.RelativePosition;
|
|
36
|
+
focus: Y.RelativePosition;
|
|
37
|
+
};
|
|
38
|
+
export declare type NodeElement = {
|
|
39
|
+
type: string;
|
|
40
|
+
children: Descendant[];
|
|
41
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Range } from 'slate';
|
|
2
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
3
|
+
import * as Y from 'yjs';
|
|
4
|
+
import { RelativeRange } from '../module/custom-types';
|
|
5
|
+
import { YjsEditor } from './withYjs';
|
|
6
|
+
export declare type CursorStateChangeEvent = {
|
|
7
|
+
added: number[];
|
|
8
|
+
updated: number[];
|
|
9
|
+
removed: number[];
|
|
10
|
+
};
|
|
11
|
+
export declare type RemoteCursorChangeEventListener = (event: CursorStateChangeEvent) => void;
|
|
12
|
+
export declare type CursorState<TCursorData extends Record<string, unknown> = Record<string, unknown>> = {
|
|
13
|
+
relativeSelection: RelativeRange | null;
|
|
14
|
+
data?: TCursorData;
|
|
15
|
+
clientId: number;
|
|
16
|
+
};
|
|
17
|
+
export declare type CursorEditor<TCursorData extends Record<string, unknown> = Record<string, unknown>> = YjsEditor & {
|
|
18
|
+
awareness: Awareness;
|
|
19
|
+
cursorDataField: string;
|
|
20
|
+
selectionStateField: string;
|
|
21
|
+
sendCursorPosition: (range: Range | null) => void;
|
|
22
|
+
sendCursorData: (data: TCursorData) => void;
|
|
23
|
+
};
|
|
24
|
+
export declare const CursorEditor: {
|
|
25
|
+
isCursorEditor(value: unknown): value is CursorEditor<Record<string, unknown>>;
|
|
26
|
+
sendCursorPosition<TCursorData extends Record<string, unknown>>(editor: CursorEditor<TCursorData>, range?: Range | null): void;
|
|
27
|
+
sendCursorData<TCursorData_1 extends Record<string, unknown>>(editor: CursorEditor<TCursorData_1>, data: TCursorData_1): void;
|
|
28
|
+
on<TCursorData_2 extends Record<string, unknown>>(editor: CursorEditor<TCursorData_2>, event: 'change', handler: RemoteCursorChangeEventListener): void;
|
|
29
|
+
off<TCursorData_3 extends Record<string, unknown>>(editor: CursorEditor<TCursorData_3>, event: 'change', listener: RemoteCursorChangeEventListener): void;
|
|
30
|
+
cursorState<TCursorData_4 extends Record<string, unknown>>(editor: CursorEditor<TCursorData_4>, clientId: number): CursorState<TCursorData_4> | null;
|
|
31
|
+
cursorStates<TCursorData_5 extends Record<string, unknown>>(editor: CursorEditor<TCursorData_5>): Record<string, CursorState<TCursorData_5>>;
|
|
32
|
+
};
|
|
33
|
+
export declare type WithCursorsOptions<TCursorData extends Record<string, unknown> = Record<string, unknown>> = {
|
|
34
|
+
cursorStateField?: string;
|
|
35
|
+
cursorDataField?: string;
|
|
36
|
+
data?: TCursorData;
|
|
37
|
+
autoSend?: boolean;
|
|
38
|
+
};
|
|
39
|
+
export declare function withCursors<TCursorData extends Record<string, unknown>>(awareness: Awareness, options?: WithCursorsOptions<TCursorData>): <T extends YjsEditor>(editor: T) => T & import("slate").BaseEditor & {
|
|
40
|
+
sharedRoot: Y.XmlText;
|
|
41
|
+
localOrigin: unknown;
|
|
42
|
+
positionStorageOrigin: unknown;
|
|
43
|
+
applyRemoteEvents: (events: Y.YEvent<Y.XmlText>[], origin: unknown) => void;
|
|
44
|
+
storeLocalChange: (op: import("slate").BaseOperation) => void;
|
|
45
|
+
flushLocalChanges: () => void;
|
|
46
|
+
isLocalOrigin: (origin: unknown) => boolean;
|
|
47
|
+
connect: () => void;
|
|
48
|
+
disconnect: () => void;
|
|
49
|
+
} & {
|
|
50
|
+
awareness: Awareness;
|
|
51
|
+
cursorDataField: string;
|
|
52
|
+
selectionStateField: string;
|
|
53
|
+
sendCursorPosition: (range: import("slate").BaseRange | null) => void;
|
|
54
|
+
sendCursorData: (data: TCursorData) => void;
|
|
55
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
import { YjsEditor } from './withYjs';
|
|
3
|
+
export declare type YHistoryEditor = YjsEditor & {
|
|
4
|
+
undoManager: Y.UndoManager;
|
|
5
|
+
withoutSavingOrigin: unknown;
|
|
6
|
+
undo: () => void;
|
|
7
|
+
redo: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const YHistoryEditor: {
|
|
10
|
+
isYHistoryEditor(value: unknown): value is YHistoryEditor;
|
|
11
|
+
canUndo(editor: YHistoryEditor): boolean;
|
|
12
|
+
canRedo(editor: YHistoryEditor): boolean;
|
|
13
|
+
isSaving(editor: YHistoryEditor): boolean;
|
|
14
|
+
withoutSaving(editor: YHistoryEditor, fn: () => void): void;
|
|
15
|
+
};
|
|
16
|
+
export declare type WithYHistoryOptions = NonNullable<ConstructorParameters<typeof Y.UndoManager>[1]> & {
|
|
17
|
+
withoutSavingOrigin?: unknown;
|
|
18
|
+
};
|
|
19
|
+
export declare function withYHistory(options?: WithYHistoryOptions): <T extends YjsEditor>(editor: T) => T & import("slate").BaseEditor & {
|
|
20
|
+
sharedRoot: Y.XmlText;
|
|
21
|
+
localOrigin: unknown;
|
|
22
|
+
positionStorageOrigin: unknown;
|
|
23
|
+
applyRemoteEvents: (events: Y.YEvent<Y.XmlText>[], origin: unknown) => void;
|
|
24
|
+
storeLocalChange: (op: import("slate").BaseOperation) => void;
|
|
25
|
+
flushLocalChanges: () => void;
|
|
26
|
+
isLocalOrigin: (origin: unknown) => boolean;
|
|
27
|
+
connect: () => void;
|
|
28
|
+
disconnect: () => void;
|
|
29
|
+
} & {
|
|
30
|
+
undoManager: Y.UndoManager;
|
|
31
|
+
withoutSavingOrigin: unknown;
|
|
32
|
+
undo: () => void;
|
|
33
|
+
redo: () => void;
|
|
34
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BaseEditor, Descendant, Operation, Point } from 'slate';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
declare type LocalChange = {
|
|
4
|
+
op: Operation;
|
|
5
|
+
doc: Descendant[];
|
|
6
|
+
origin: unknown;
|
|
7
|
+
};
|
|
8
|
+
export declare type YjsEditor = BaseEditor & {
|
|
9
|
+
sharedRoot: Y.XmlText;
|
|
10
|
+
localOrigin: unknown;
|
|
11
|
+
positionStorageOrigin: unknown;
|
|
12
|
+
applyRemoteEvents: (events: Y.YEvent<Y.XmlText>[], origin: unknown) => void;
|
|
13
|
+
storeLocalChange: (op: Operation) => void;
|
|
14
|
+
flushLocalChanges: () => void;
|
|
15
|
+
isLocalOrigin: (origin: unknown) => boolean;
|
|
16
|
+
connect: () => void;
|
|
17
|
+
disconnect: () => void;
|
|
18
|
+
};
|
|
19
|
+
export declare const YjsEditor: {
|
|
20
|
+
isYjsEditor(value: unknown): value is YjsEditor;
|
|
21
|
+
localChanges(editor: YjsEditor): LocalChange[];
|
|
22
|
+
applyRemoteEvents(editor: YjsEditor, events: Y.YEvent<Y.XmlText>[], origin: unknown): void;
|
|
23
|
+
storeLocalChange(editor: YjsEditor, op: Operation): void;
|
|
24
|
+
flushLocalChanges(editor: YjsEditor): void;
|
|
25
|
+
connected(editor: YjsEditor): boolean;
|
|
26
|
+
connect(editor: YjsEditor): void;
|
|
27
|
+
disconnect(editor: YjsEditor): void;
|
|
28
|
+
isLocal(editor: YjsEditor): boolean;
|
|
29
|
+
origin(editor: YjsEditor): unknown;
|
|
30
|
+
withOrigin(editor: YjsEditor, origin: unknown, fn: () => void): void;
|
|
31
|
+
storePosition(editor: YjsEditor, key: string, point: Point): void;
|
|
32
|
+
removeStoredPosition(editor: YjsEditor, key: string): void;
|
|
33
|
+
position(editor: YjsEditor, key: string): Point | null | undefined;
|
|
34
|
+
storedPositionsRelative(editor: YjsEditor): Record<string, Y.RelativePosition>;
|
|
35
|
+
};
|
|
36
|
+
export declare type WithYjsOptions = {
|
|
37
|
+
autoConnect?: boolean;
|
|
38
|
+
localOrigin?: unknown;
|
|
39
|
+
positionStorageOrigin?: unknown;
|
|
40
|
+
};
|
|
41
|
+
export declare function withYjs(sharedRoot: Y.XmlText, options?: WithYjsOptions): <T extends BaseEditor>(editor: T) => T & BaseEditor & {
|
|
42
|
+
sharedRoot: Y.XmlText;
|
|
43
|
+
localOrigin: unknown;
|
|
44
|
+
positionStorageOrigin: unknown;
|
|
45
|
+
applyRemoteEvents: (events: Y.YEvent<Y.XmlText>[], origin: unknown) => void;
|
|
46
|
+
storeLocalChange: (op: import("slate").BaseOperation) => void;
|
|
47
|
+
flushLocalChanges: () => void;
|
|
48
|
+
isLocalOrigin: (origin: unknown) => boolean;
|
|
49
|
+
connect: () => void;
|
|
50
|
+
disconnect: () => void;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Element, Node } from 'slate';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
import { DeltaInsert, InsertDelta } from '../module/custom-types';
|
|
4
|
+
export declare function yTextToSlateElement(yText: Y.XmlText): Element;
|
|
5
|
+
export declare function deltaInsertToSlateNode(insert: DeltaInsert): Node;
|
|
6
|
+
export declare function slateNodesToInsertDelta(nodes: Node[]): InsertDelta;
|
|
7
|
+
export declare function slateElementToYText({ children, ...attributes }: Element): Y.XmlText;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
import { DeltaInsert, InsertDelta } from '../module/custom-types';
|
|
3
|
+
export declare function normalizeInsertDelta(delta: InsertDelta): InsertDelta;
|
|
4
|
+
export declare function yTextToInsertDelta(yText: Y.XmlText): InsertDelta;
|
|
5
|
+
export declare function getInsertLength({ insert }: DeltaInsert): number;
|
|
6
|
+
export declare function getInsertDeltaLength(delta: InsertDelta): number;
|
|
7
|
+
export declare function sliceInsertDelta(delta: InsertDelta, start: number, length: number): InsertDelta;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Element, Node, Path } from 'slate';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
import { YTarget } from '../module/custom-types';
|
|
4
|
+
export declare function getSlateNodeYLength(node: Node | undefined): number;
|
|
5
|
+
export declare function slatePathOffsetToYOffset(element: Element, pathOffset: number): number;
|
|
6
|
+
export declare function getYTarget(yRoot: Y.XmlText, slateRoot: Node, path: Path): YTarget;
|
|
7
|
+
export declare function yOffsetToSlateOffsets(parent: Element, yOffset: number, opts?: {
|
|
8
|
+
assoc?: number;
|
|
9
|
+
insert?: boolean;
|
|
10
|
+
}): [number, number];
|
|
11
|
+
export declare function getSlatePath(sharedRoot: Y.XmlText, slateRoot: Node, yText: Y.XmlText): Path;
|
|
@@ -0,0 +1,9 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BasePoint, BaseRange, Node } from 'slate';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
import { InsertDelta, RelativeRange } from '../module/custom-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;
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wangeditor-next/yjs",
|
|
3
|
+
"sideEffects": false,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"author": "cycleccc <2991205548@qq.com>",
|
|
6
|
+
"contributors": [],
|
|
7
|
+
"description": "Yjs binding for wangeditor-next.",
|
|
8
|
+
"homepage": "https://github.com/cycleccc/wangEditor#readme",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"slate",
|
|
11
|
+
"wangEditor",
|
|
12
|
+
"yjs",
|
|
13
|
+
"collaborative"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"module": "dist/index.esm.js",
|
|
19
|
+
"unpkg": "dist/index.global.js",
|
|
20
|
+
"exports": {
|
|
21
|
+
"require": "./dist/index.js",
|
|
22
|
+
"default": "./dist/index.esm.js"
|
|
23
|
+
},
|
|
24
|
+
"browser": {
|
|
25
|
+
"./dist/index.js": "./dist/index.js",
|
|
26
|
+
"./dist/index.esm.js": "./dist/index.esm.js"
|
|
27
|
+
},
|
|
28
|
+
"directories": {
|
|
29
|
+
"lib": "dist",
|
|
30
|
+
"test": "__tests__"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/cycleccc/wangEditor.git"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"test": "jest",
|
|
44
|
+
"test-c": "jest --coverage",
|
|
45
|
+
"dev": "cross-env NODE_ENV=development rollup -c rollup.config.js",
|
|
46
|
+
"dev-watch": "cross-env NODE_ENV=development rollup -c rollup.config.js -w",
|
|
47
|
+
"build": "cross-env NODE_ENV=production rollup -c rollup.config.js",
|
|
48
|
+
"dev-size-stats": "cross-env NODE_ENV=development:size_stats rollup -c rollup.config.js",
|
|
49
|
+
"size-stats": "cross-env NODE_ENV=production:size_stats rollup -c rollup.config.js"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@wangeditor-next/core": "1.x",
|
|
53
|
+
"slate": "^0.72.0",
|
|
54
|
+
"yjs": "^13.5.29"
|
|
55
|
+
},
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/cycleccc/wangEditor/issues"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"y-protocols": "^1.0.5"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"slate": "^0.72.0",
|
|
64
|
+
"typescript": "^4.6.3",
|
|
65
|
+
"yjs": "^13.5.29"
|
|
66
|
+
}
|
|
67
|
+
}
|