@slate-yjs/core 1.0.9 → 1.1.1
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 +12 -0
- package/dist/applyToSlate/textEvent.d.ts.map +1 -1
- package/dist/index.cjs +16 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.global.js +14 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +21 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/applyToSlate/textEvent.ts +32 -6
- package/src/index.ts +5 -0
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Editor,
|
|
3
|
+
Element,
|
|
4
|
+
InsertTextOperation,
|
|
5
|
+
Node,
|
|
6
|
+
Operation,
|
|
7
|
+
Path,
|
|
8
|
+
Text,
|
|
9
|
+
} from 'slate';
|
|
2
10
|
import * as Y from 'yjs';
|
|
3
11
|
import { Delta } from '../model/types';
|
|
4
12
|
import { deltaInsertToSlateNode } from '../utils/convert';
|
|
@@ -166,16 +174,34 @@ function applyDelta(node: Element, slatePath: Path, delta: Delta): Operation[] {
|
|
|
166
174
|
* Since we're not actually using slate to update the node
|
|
167
175
|
* this is a simulation
|
|
168
176
|
*/
|
|
177
|
+
// Inserting text doesn't change a node's properties, so look past
|
|
178
|
+
// inserts into this node for the operation that last set them. An
|
|
179
|
+
// insert_text is only emitted directly after another operation on the
|
|
180
|
+
// same path, so this ends at the operation that set this node's
|
|
181
|
+
// properties.
|
|
182
|
+
let propsOpIndex = ops.length - 1;
|
|
183
|
+
while (
|
|
184
|
+
propsOpIndex >= 0 &&
|
|
185
|
+
ops[propsOpIndex].type === 'insert_text' &&
|
|
186
|
+
Path.equals(
|
|
187
|
+
(ops[propsOpIndex] as InsertTextOperation).path,
|
|
188
|
+
childPath
|
|
189
|
+
)
|
|
190
|
+
) {
|
|
191
|
+
propsOpIndex -= 1;
|
|
192
|
+
}
|
|
193
|
+
const propsOp = ops[propsOpIndex];
|
|
194
|
+
|
|
169
195
|
let currentProps = getProperties(child);
|
|
170
|
-
if (
|
|
171
|
-
currentProps =
|
|
196
|
+
if (propsOp?.type === 'insert_node') {
|
|
197
|
+
currentProps = propsOp.node;
|
|
172
198
|
} else if (
|
|
173
|
-
|
|
174
|
-
Path.equals(
|
|
199
|
+
propsOp?.type === 'set_node' &&
|
|
200
|
+
Path.equals(propsOp.path, childPath)
|
|
175
201
|
) {
|
|
176
202
|
currentProps = omitNullEntries({
|
|
177
203
|
...currentProps,
|
|
178
|
-
...
|
|
204
|
+
...propsOp.newProperties,
|
|
179
205
|
});
|
|
180
206
|
}
|
|
181
207
|
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { translateYjsEvent } from './applyToSlate';
|
|
2
|
+
import { applySlateOp } from './applyToYjs';
|
|
1
3
|
import { RelativeRange } from './model/types';
|
|
2
4
|
import {
|
|
3
5
|
CursorEditor,
|
|
@@ -44,4 +46,7 @@ export {
|
|
|
44
46
|
relativeRangeToSlateRange,
|
|
45
47
|
slatePointToRelativePosition,
|
|
46
48
|
relativePositionToSlatePoint,
|
|
49
|
+
// Low-level translation
|
|
50
|
+
translateYjsEvent,
|
|
51
|
+
applySlateOp,
|
|
47
52
|
};
|