@slate-yjs/core 1.0.6 → 1.0.7
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 +6 -0
- package/dist/applyToYjs/node/splitNode.d.ts.map +1 -1
- package/dist/applyToYjs/text/insertText.d.ts +1 -1
- package/dist/applyToYjs/text/insertText.d.ts.map +1 -1
- package/dist/applyToYjs/text/removeText.d.ts +1 -1
- package/dist/applyToYjs/text/removeText.d.ts.map +1 -1
- package/dist/applyToYjs/types.d.ts +2 -2
- package/dist/applyToYjs/types.d.ts.map +1 -1
- package/dist/index.cjs +341 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +3157 -568
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +329 -94
- package/dist/index.js.map +1 -1
- package/dist/model/types.d.ts +11 -11
- package/dist/model/types.d.ts.map +1 -1
- package/dist/plugins/withCursors.d.ts +11 -11
- package/dist/plugins/withCursors.d.ts.map +1 -1
- package/dist/plugins/withYHistory.d.ts +2 -2
- package/dist/plugins/withYHistory.d.ts.map +1 -1
- package/dist/plugins/withYjs.d.ts +3 -3
- package/dist/plugins/withYjs.d.ts.map +1 -1
- package/dist/utils/object.d.ts +4 -4
- package/dist/utils/object.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/applyToSlate/textEvent.ts +1 -1
- package/src/applyToYjs/node/splitNode.ts +40 -12
- package/src/applyToYjs/text/insertText.ts +1 -1
- package/src/applyToYjs/text/removeText.ts +1 -1
- package/src/model/types.ts +1 -1
- package/src/utils/object.ts +5 -3
- package/src/utils/position.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Y from 'yjs';
|
|
2
2
|
import { YjsEditor } from './withYjs';
|
|
3
|
-
export
|
|
3
|
+
export type YHistoryEditor = YjsEditor & {
|
|
4
4
|
undoManager: Y.UndoManager;
|
|
5
5
|
withoutSavingOrigin: unknown;
|
|
6
6
|
undo: () => void;
|
|
@@ -13,7 +13,7 @@ export declare const YHistoryEditor: {
|
|
|
13
13
|
isSaving(editor: YHistoryEditor): boolean;
|
|
14
14
|
withoutSaving(editor: YHistoryEditor, fn: () => void): void;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export type WithYHistoryOptions = NonNullable<ConstructorParameters<typeof Y.UndoManager>[1]> & {
|
|
17
17
|
withoutSavingOrigin?: unknown;
|
|
18
18
|
};
|
|
19
19
|
export declare function withYHistory<T extends YjsEditor>(editor: T, { withoutSavingOrigin, trackedOrigins, ...options }?: WithYHistoryOptions): T & YHistoryEditor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withYHistory.d.ts","sourceRoot":"","sources":["../../src/plugins/withYHistory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAMzB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAOtC,
|
|
1
|
+
{"version":3,"file":"withYHistory.d.ts","sourceRoot":"","sources":["../../src/plugins/withYHistory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAMzB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAOtC,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG;IACvC,WAAW,EAAE,CAAC,CAAC,WAAW,CAAC;IAE3B,mBAAmB,EAAE,OAAO,CAAC;IAE7B,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,cAAc;4BACD,OAAO,GAAG,KAAK,IAAI,cAAc;oBAUzC,cAAc;oBAId,cAAc;qBAIb,cAAc,GAAG,OAAO;0BAInB,cAAc,MAAM,MAAM,IAAI;CAGrD,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAC3C,qBAAqB,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAC/C,GAAG;IACF,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,EAC9C,MAAM,EAAE,CAAC,EACT,EACE,mBAAmD,EACnD,cAA8C,EAC9C,GAAG,OAAO,EACX,GAAE,mBAAwB,GAC1B,CAAC,GAAG,cAAc,CAsHpB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseEditor, Descendant, Editor, Operation, Point } from 'slate';
|
|
2
2
|
import * as Y from 'yjs';
|
|
3
|
-
|
|
3
|
+
type LocalChange = {
|
|
4
4
|
op: Operation;
|
|
5
5
|
doc: Descendant[];
|
|
6
6
|
origin: unknown;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type YjsEditor = BaseEditor & {
|
|
9
9
|
sharedRoot: Y.XmlText;
|
|
10
10
|
localOrigin: unknown;
|
|
11
11
|
positionStorageOrigin: unknown;
|
|
@@ -33,7 +33,7 @@ export declare const YjsEditor: {
|
|
|
33
33
|
position(editor: YjsEditor, key: string): Point | null | undefined;
|
|
34
34
|
storedPositionsRelative(editor: YjsEditor): Record<string, Y.RelativePosition>;
|
|
35
35
|
};
|
|
36
|
-
export
|
|
36
|
+
export type WithYjsOptions = {
|
|
37
37
|
autoConnect?: boolean;
|
|
38
38
|
localOrigin?: unknown;
|
|
39
39
|
positionStorageOrigin?: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withYjs.d.ts","sourceRoot":"","sources":["../../src/plugins/withYjs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAczB,
|
|
1
|
+
{"version":3,"file":"withYjs.d.ts","sourceRoot":"","sources":["../../src/plugins/withYjs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE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,MAAM,SAAS,KAAK,GAAG,IAAI;iCAWpC,SAAS,OAAO,MAAM,GAAG,IAAI;qBASzC,SAAS,OAAO,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS;oCAUxD,SAAS,GAChB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,gBAAgB,CAAC;CAGtC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IAGtB,WAAW,CAAC,EAAE,OAAO,CAAC;IAGtB,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EACtC,MAAM,EAAE,CAAC,EACT,UAAU,EAAE,CAAC,CAAC,OAAO,EACrB,EACE,WAAW,EACX,qBAAqB,EACrB,WAAmB,GACpB,GAAE,cAAmB,GACrB,CAAC,GAAG,SAAS,CAyIf"}
|
package/dist/utils/object.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
type InspectableObject = Record<string | number | symbol, unknown>;
|
|
2
2
|
export declare function isPlainObject(o: unknown): o is InspectableObject;
|
|
3
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): {
|
|
4
|
+
export declare function pick<TObj extends object, TKeys extends keyof TObj>(obj: TObj, ...keys: TKeys[]): Pick<TObj, TKeys>;
|
|
5
|
+
export declare function omit<TObj extends object, TKeys extends keyof TObj>(obj: TObj, ...keys: TKeys[]): Omit<TObj, TKeys>;
|
|
6
|
+
export declare function omitNullEntries<TObj extends object>(obj: TObj): {
|
|
7
7
|
[K in keyof TObj]: TObj[K] extends null ? never : K;
|
|
8
8
|
};
|
|
9
9
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA,KAAK,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,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM,IAAI,EAChE,GAAG,EAAE,IAAI,EACT,GAAG,IAAI,EAAE,KAAK,EAAE,GACf,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAInB;AAED,wBAAgB,IAAI,CAAC,IAAI,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM,IAAI,EAChE,GAAG,EAAE,IAAI,EACT,GAAG,IAAI,EAAE,KAAK,EAAE,GACf,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAInB;AAED,wBAAgB,eAAe,CAAC,IAAI,SAAS,MAAM,EACjD,GAAG,EAAE,IAAI,GACR;KACA,CAAC,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC;CACpD,CAIA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slate-yjs/core",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.7",
|
|
5
5
|
"description": "Yjs binding for Slate.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"slate",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"types": "dist/index.d.ts",
|
|
20
20
|
"files": [
|
|
21
21
|
"dist",
|
|
22
|
+
"!dist/tsconfig.tsbuildinfo",
|
|
22
23
|
"src",
|
|
23
24
|
"CHANGELOG.md"
|
|
24
25
|
],
|
|
@@ -30,8 +31,8 @@
|
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"slate": "^0.147.4",
|
|
32
33
|
"slate-hyperscript": "^0.138.3",
|
|
33
|
-
"tsup": "^
|
|
34
|
-
"typescript": "^
|
|
34
|
+
"tsup": "^9.0.0",
|
|
35
|
+
"typescript": "^6.0.3",
|
|
35
36
|
"yjs": "^13.6.33"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"y-protocols": "^1.0.7"
|
|
47
48
|
},
|
|
48
49
|
"scripts": {
|
|
49
|
-
"build": "tsup && tsc --emitDeclarationOnly",
|
|
50
|
+
"build": "tsup && tsc --emitDeclarationOnly --tsBuildInfoFile dist/tsconfig.tsbuildinfo",
|
|
50
51
|
"dev": "tsup --watch"
|
|
51
52
|
}
|
|
52
53
|
}
|
|
@@ -266,7 +266,7 @@ export function translateYTextEvent(
|
|
|
266
266
|
);
|
|
267
267
|
|
|
268
268
|
const properties = Object.fromEntries(
|
|
269
|
-
keyChanges.map(([key]) => [key, targetElement
|
|
269
|
+
keyChanges.map(([key]) => [key, Reflect.get(targetElement, key)])
|
|
270
270
|
);
|
|
271
271
|
|
|
272
272
|
ops.push({ type: 'set_node', newProperties, properties, path: slatePath });
|
|
@@ -58,10 +58,16 @@ export function splitNode(
|
|
|
58
58
|
0
|
|
59
59
|
);
|
|
60
60
|
|
|
61
|
+
// Copy the shorter side into a new Yjs type and keep the longer side in
|
|
62
|
+
// place, so fewer remote cursors and concurrent edits are moved.
|
|
63
|
+
const copyHead = ySplitOffset < length - ySplitOffset;
|
|
64
|
+
const copyStart = copyHead ? 0 : ySplitOffset;
|
|
65
|
+
const copyLength = copyHead ? ySplitOffset : length - ySplitOffset;
|
|
66
|
+
|
|
61
67
|
const splitDelta = sliceInsertDelta(
|
|
62
68
|
yTextToInsertDelta(target.yTarget),
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
copyStart,
|
|
70
|
+
copyLength
|
|
65
71
|
);
|
|
66
72
|
const clonedDelta = cloneInsertDeltaDeep(splitDelta);
|
|
67
73
|
|
|
@@ -69,22 +75,44 @@ export function splitNode(
|
|
|
69
75
|
sharedRoot,
|
|
70
76
|
target.yTarget,
|
|
71
77
|
splitDelta,
|
|
72
|
-
|
|
78
|
+
copyStart
|
|
73
79
|
);
|
|
74
80
|
|
|
75
81
|
const toInsert = new Y.XmlText();
|
|
76
82
|
toInsert.applyDelta(clonedDelta, PRESERVE_CONTENT);
|
|
77
83
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
if (copyHead) {
|
|
85
|
+
// The copy becomes the first node and keeps the current properties. The
|
|
86
|
+
// original becomes the second node and gets op.properties.
|
|
87
|
+
const { yTarget } = target;
|
|
88
|
+
const attributes = yTarget.getAttributes();
|
|
89
|
+
Object.entries(attributes).forEach(([key, value]) => {
|
|
90
|
+
toInsert.setAttribute(key, value);
|
|
91
|
+
});
|
|
92
|
+
Object.keys(attributes).forEach((key) => {
|
|
93
|
+
if (!(key in op.properties)) {
|
|
94
|
+
yTarget.removeAttribute(key);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
Object.entries(op.properties).forEach(([key, value]) => {
|
|
98
|
+
if (attributes[key] !== value) {
|
|
99
|
+
yTarget.setAttribute(key, value);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
81
102
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
103
|
+
yTarget.delete(0, splitTarget.textRange.start);
|
|
104
|
+
target.yParent.insertEmbed(target.textRange.start, toInsert);
|
|
105
|
+
} else {
|
|
106
|
+
Object.entries(op.properties).forEach(([key, value]) => {
|
|
107
|
+
toInsert.setAttribute(key, value);
|
|
108
|
+
});
|
|
86
109
|
|
|
87
|
-
|
|
110
|
+
target.yTarget.delete(
|
|
111
|
+
splitTarget.textRange.start,
|
|
112
|
+
target.yTarget.length - splitTarget.textRange.start
|
|
113
|
+
);
|
|
114
|
+
target.yParent.insertEmbed(target.textRange.end, toInsert);
|
|
115
|
+
}
|
|
88
116
|
|
|
89
117
|
restoreStoredPositionsWithDeltaAbsolute(
|
|
90
118
|
sharedRoot,
|
|
@@ -92,6 +120,6 @@ export function splitNode(
|
|
|
92
120
|
storedPositions,
|
|
93
121
|
clonedDelta,
|
|
94
122
|
0,
|
|
95
|
-
|
|
123
|
+
copyStart
|
|
96
124
|
);
|
|
97
125
|
}
|
package/src/model/types.ts
CHANGED
package/src/utils/object.ts
CHANGED
|
@@ -66,7 +66,7 @@ export function deepEquals(
|
|
|
66
66
|
return true;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export function pick<TObj, TKeys extends keyof TObj>(
|
|
69
|
+
export function pick<TObj extends object, TKeys extends keyof TObj>(
|
|
70
70
|
obj: TObj,
|
|
71
71
|
...keys: TKeys[]
|
|
72
72
|
): Pick<TObj, TKeys> {
|
|
@@ -75,7 +75,7 @@ export function pick<TObj, TKeys extends keyof TObj>(
|
|
|
75
75
|
) as Pick<TObj, TKeys>;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
export function omit<TObj, TKeys extends keyof TObj>(
|
|
78
|
+
export function omit<TObj extends object, TKeys extends keyof TObj>(
|
|
79
79
|
obj: TObj,
|
|
80
80
|
...keys: TKeys[]
|
|
81
81
|
): Omit<TObj, TKeys> {
|
|
@@ -84,7 +84,9 @@ export function omit<TObj, TKeys extends keyof TObj>(
|
|
|
84
84
|
) as Omit<TObj, TKeys>;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
export function omitNullEntries<TObj>(
|
|
87
|
+
export function omitNullEntries<TObj extends object>(
|
|
88
|
+
obj: TObj
|
|
89
|
+
): {
|
|
88
90
|
[K in keyof TObj]: TObj[K] extends null ? never : K;
|
|
89
91
|
} {
|
|
90
92
|
return Object.fromEntries(
|
package/src/utils/position.ts
CHANGED
|
@@ -169,7 +169,7 @@ function getAbsolutePositionsInTextRange(
|
|
|
169
169
|
|
|
170
170
|
return position.assoc >= 0
|
|
171
171
|
? position.index >= textRange.start && position.index < textRange.end
|
|
172
|
-
: position.index > textRange.start && position.index
|
|
172
|
+
: position.index > textRange.start && position.index <= textRange.end;
|
|
173
173
|
})
|
|
174
174
|
);
|
|
175
175
|
}
|