@textbus/collaborate 4.0.0-alpha.27 → 4.0.0-alpha.28
Sign up to get free protection for your applications and to get access to all the features.
- package/bundles/index.esm.js +44 -51
- package/bundles/index.js +41 -48
- package/package.json +3 -3
package/bundles/index.esm.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Injectable, Inject, Optional } from '@viewfly/core';
|
2
2
|
import { Subject, map, filter } from '@tanbo/stream';
|
3
|
-
import { makeError, HISTORY_STACK_SIZE, ChangeOrigin,
|
4
|
-
import { Doc, UndoManager, Map, Array, Text, createAbsolutePositionFromRelativePosition, createRelativePositionFromTypeIndex } from 'yjs';
|
3
|
+
import { makeError, HISTORY_STACK_SIZE, ChangeOrigin, createObjectProxy, createArrayProxy, Slot, RootComponentRef, Scheduler, Registry, Selection, History } from '@textbus/core';
|
4
|
+
import { Doc, UndoManager, Map, Array as Array$1, Text, createAbsolutePositionFromRelativePosition, createRelativePositionFromTypeIndex } from 'yjs';
|
5
5
|
|
6
6
|
/******************************************************************************
|
7
7
|
Copyright (c) Microsoft Corporation.
|
@@ -269,25 +269,23 @@ let Collaborate = class Collaborate {
|
|
269
269
|
}
|
270
270
|
syncSharedMapToLocalMap(sharedMap, localMap, parent) {
|
271
271
|
sharedMap.forEach((value, key) => {
|
272
|
-
localMap
|
272
|
+
localMap[key] = this.createLocalModelBySharedByModel(value, parent);
|
273
273
|
});
|
274
274
|
this.syncObject(sharedMap, localMap, parent);
|
275
275
|
}
|
276
276
|
createLocalMapBySharedMap(sharedMap, parent) {
|
277
|
-
const localMap =
|
277
|
+
const localMap = createObjectProxy({}, parent);
|
278
278
|
this.syncSharedMapToLocalMap(sharedMap, localMap, parent);
|
279
279
|
return localMap;
|
280
280
|
}
|
281
281
|
createLocalArrayBySharedArray(sharedArray, parent) {
|
282
|
-
const localArray =
|
283
|
-
sharedArray.
|
284
|
-
localArray.insert(this.createLocalModelBySharedByModel(item, parent));
|
285
|
-
});
|
282
|
+
const localArray = createArrayProxy([], parent);
|
283
|
+
localArray.push(...sharedArray.map(item => this.createLocalModelBySharedByModel(item, parent)));
|
286
284
|
this.syncArray(sharedArray, localArray, parent);
|
287
285
|
return localArray;
|
288
286
|
}
|
289
287
|
syncLocalMapToSharedMap(localMap, sharedMap, parent) {
|
290
|
-
localMap.forEach((
|
288
|
+
Object.entries(localMap).forEach(([key, value]) => {
|
291
289
|
sharedMap.set(key, this.createSharedModelByLocalModel(value, parent));
|
292
290
|
});
|
293
291
|
this.syncObject(sharedMap, localMap, parent);
|
@@ -298,7 +296,7 @@ let Collaborate = class Collaborate {
|
|
298
296
|
return sharedMap;
|
299
297
|
}
|
300
298
|
createSharedArrayByLocalArray(localArray, parent) {
|
301
|
-
const sharedArray = new Array();
|
299
|
+
const sharedArray = new Array$1();
|
302
300
|
localArray.forEach(value => {
|
303
301
|
sharedArray.push([this.createSharedModelByLocalModel(value, parent)]);
|
304
302
|
});
|
@@ -363,37 +361,29 @@ let Collaborate = class Collaborate {
|
|
363
361
|
this.syncSlot(sharedSlot, localSlot);
|
364
362
|
return localSlot;
|
365
363
|
}
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
// private createSharedModelByLocalModel(sharedModel: any, parent: Component<any>): any
|
370
|
-
createSharedModelByLocalModel(sharedModel, parent) {
|
371
|
-
if (sharedModel instanceof MapModel) {
|
372
|
-
return this.createSharedMapByLocalMap(sharedModel, parent);
|
364
|
+
createSharedModelByLocalModel(localModel, parent) {
|
365
|
+
if (localModel instanceof Slot) {
|
366
|
+
return this.createSharedSlotByLocalSlot(localModel);
|
373
367
|
}
|
374
|
-
if (
|
375
|
-
return this.createSharedArrayByLocalArray(
|
368
|
+
if (Array.isArray(localModel)) {
|
369
|
+
return this.createSharedArrayByLocalArray(localModel, parent);
|
376
370
|
}
|
377
|
-
if (
|
378
|
-
return this.
|
371
|
+
if (typeof localModel === 'object' && localModel !== null) {
|
372
|
+
return this.createSharedMapByLocalMap(localModel, parent);
|
379
373
|
}
|
380
|
-
return
|
374
|
+
return localModel;
|
381
375
|
}
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
// private createLocalModelBySharedByModel(localModel: any, parent: Component<any>): any
|
386
|
-
createLocalModelBySharedByModel(localModel, parent) {
|
387
|
-
if (localModel instanceof Map) {
|
388
|
-
return this.createLocalMapBySharedMap(localModel, parent);
|
376
|
+
createLocalModelBySharedByModel(sharedModel, parent) {
|
377
|
+
if (sharedModel instanceof Map) {
|
378
|
+
return this.createLocalMapBySharedMap(sharedModel, parent);
|
389
379
|
}
|
390
|
-
if (
|
391
|
-
return this.createLocalArrayBySharedArray(
|
380
|
+
if (sharedModel instanceof Array$1) {
|
381
|
+
return this.createLocalArrayBySharedArray(sharedModel, parent);
|
392
382
|
}
|
393
|
-
if (
|
394
|
-
return this.createLocalSlotBySharedSlot(
|
383
|
+
if (sharedModel instanceof Text) {
|
384
|
+
return this.createLocalSlotBySharedSlot(sharedModel);
|
395
385
|
}
|
396
|
-
return
|
386
|
+
return sharedModel;
|
397
387
|
}
|
398
388
|
getAbstractSelection(position) {
|
399
389
|
const anchorPosition = createAbsolutePositionFromRelativePosition(position.anchor, this.yDoc);
|
@@ -567,7 +557,7 @@ let Collaborate = class Collaborate {
|
|
567
557
|
});
|
568
558
|
});
|
569
559
|
this.slotMap.set(localSlot, sharedSlot);
|
570
|
-
localSlot.destroyCallbacks.push(() => {
|
560
|
+
localSlot.changeMarker.destroyCallbacks.push(() => {
|
571
561
|
this.slotMap.delete(localSlot);
|
572
562
|
sharedSlot.unobserve(syncRemote);
|
573
563
|
sub.unsubscribe();
|
@@ -599,23 +589,29 @@ let Collaborate = class Collaborate {
|
|
599
589
|
* @private
|
600
590
|
*/
|
601
591
|
syncArray(sharedArray, localArray, parent) {
|
602
|
-
const sub = localArray.
|
592
|
+
const sub = localArray.__changeMarker__.onSelfChange.subscribe((actions) => {
|
603
593
|
this.runLocalUpdate(() => {
|
604
594
|
let index = 0;
|
605
|
-
for (const action of
|
595
|
+
for (const action of actions) {
|
606
596
|
switch (action.type) {
|
607
597
|
case 'retain':
|
608
598
|
index = action.offset;
|
609
599
|
break;
|
610
600
|
case 'insert':
|
611
601
|
{
|
612
|
-
const data =
|
602
|
+
const data = action.ref.map(item => {
|
603
|
+
return this.createSharedModelByLocalModel(item, parent);
|
604
|
+
});
|
613
605
|
sharedArray.insert(index, [data]);
|
614
606
|
}
|
615
607
|
break;
|
616
608
|
case 'delete':
|
617
609
|
sharedArray.delete(index, 1);
|
618
610
|
break;
|
611
|
+
case 'setIndex':
|
612
|
+
sharedArray.delete(action.index, 1);
|
613
|
+
sharedArray.insert(action.index, this.createSharedModelByLocalModel(action.ref, parent));
|
614
|
+
break;
|
619
615
|
}
|
620
616
|
}
|
621
617
|
});
|
@@ -623,28 +619,25 @@ let Collaborate = class Collaborate {
|
|
623
619
|
const syncRemote = (ev, tr) => {
|
624
620
|
this.runRemoteUpdate(tr, () => {
|
625
621
|
let index = 0;
|
626
|
-
localArray.retain(index);
|
627
622
|
ev.delta.forEach((action) => {
|
628
623
|
if (Reflect.has(action, 'retain')) {
|
629
624
|
index += action.retain;
|
630
|
-
localArray.retain(index);
|
631
625
|
}
|
632
626
|
else if (action.insert) {
|
633
|
-
action.insert.
|
634
|
-
|
635
|
-
localArray.insert(value);
|
636
|
-
index++;
|
627
|
+
const data = action.insert.map((item) => {
|
628
|
+
return this.createLocalModelBySharedByModel(item, parent);
|
637
629
|
});
|
630
|
+
localArray.splice(index, 0, ...data);
|
631
|
+
index += data.length;
|
638
632
|
}
|
639
633
|
else if (action.delete) {
|
640
|
-
localArray.
|
641
|
-
localArray.delete(action.delete);
|
634
|
+
localArray.splice(index, action.delete);
|
642
635
|
}
|
643
636
|
});
|
644
637
|
});
|
645
638
|
};
|
646
639
|
sharedArray.observe(syncRemote);
|
647
|
-
localArray.destroyCallbacks.push(() => {
|
640
|
+
localArray.__changeMarker__.destroyCallbacks.push(() => {
|
648
641
|
sub.unsubscribe();
|
649
642
|
sharedArray.unobserve(syncRemote);
|
650
643
|
});
|
@@ -662,18 +655,18 @@ let Collaborate = class Collaborate {
|
|
662
655
|
ev.changes.keys.forEach((item, key) => {
|
663
656
|
if (item.action === 'add' || item.action === 'update') {
|
664
657
|
const value = sharedObject.get(key);
|
665
|
-
localObject
|
658
|
+
localObject[key] = this.createLocalModelBySharedByModel(value, parent);
|
666
659
|
}
|
667
660
|
else {
|
668
|
-
|
661
|
+
Reflect.deleteProperty(localObject, key);
|
669
662
|
}
|
670
663
|
});
|
671
664
|
});
|
672
665
|
};
|
673
666
|
sharedObject.observe(syncRemote);
|
674
|
-
const sub = localObject.
|
667
|
+
const sub = localObject.__changeMarker__.onSelfChange.subscribe((actions) => {
|
675
668
|
this.runLocalUpdate(() => {
|
676
|
-
for (const action of
|
669
|
+
for (const action of actions) {
|
677
670
|
switch (action.type) {
|
678
671
|
case 'propSet':
|
679
672
|
sharedObject.set(action.key, this.createSharedModelByLocalModel(action.value, parent));
|
package/bundles/index.js
CHANGED
@@ -271,25 +271,23 @@ exports.Collaborate = class Collaborate {
|
|
271
271
|
}
|
272
272
|
syncSharedMapToLocalMap(sharedMap, localMap, parent) {
|
273
273
|
sharedMap.forEach((value, key) => {
|
274
|
-
localMap
|
274
|
+
localMap[key] = this.createLocalModelBySharedByModel(value, parent);
|
275
275
|
});
|
276
276
|
this.syncObject(sharedMap, localMap, parent);
|
277
277
|
}
|
278
278
|
createLocalMapBySharedMap(sharedMap, parent) {
|
279
|
-
const localMap =
|
279
|
+
const localMap = core.createObjectProxy({}, parent);
|
280
280
|
this.syncSharedMapToLocalMap(sharedMap, localMap, parent);
|
281
281
|
return localMap;
|
282
282
|
}
|
283
283
|
createLocalArrayBySharedArray(sharedArray, parent) {
|
284
|
-
const localArray =
|
285
|
-
sharedArray.
|
286
|
-
localArray.insert(this.createLocalModelBySharedByModel(item, parent));
|
287
|
-
});
|
284
|
+
const localArray = core.createArrayProxy([], parent);
|
285
|
+
localArray.push(...sharedArray.map(item => this.createLocalModelBySharedByModel(item, parent)));
|
288
286
|
this.syncArray(sharedArray, localArray, parent);
|
289
287
|
return localArray;
|
290
288
|
}
|
291
289
|
syncLocalMapToSharedMap(localMap, sharedMap, parent) {
|
292
|
-
localMap.forEach((
|
290
|
+
Object.entries(localMap).forEach(([key, value]) => {
|
293
291
|
sharedMap.set(key, this.createSharedModelByLocalModel(value, parent));
|
294
292
|
});
|
295
293
|
this.syncObject(sharedMap, localMap, parent);
|
@@ -365,37 +363,29 @@ exports.Collaborate = class Collaborate {
|
|
365
363
|
this.syncSlot(sharedSlot, localSlot);
|
366
364
|
return localSlot;
|
367
365
|
}
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
// private createSharedModelByLocalModel(sharedModel: any, parent: Component<any>): any
|
372
|
-
createSharedModelByLocalModel(sharedModel, parent) {
|
373
|
-
if (sharedModel instanceof core.MapModel) {
|
374
|
-
return this.createSharedMapByLocalMap(sharedModel, parent);
|
366
|
+
createSharedModelByLocalModel(localModel, parent) {
|
367
|
+
if (localModel instanceof core.Slot) {
|
368
|
+
return this.createSharedSlotByLocalSlot(localModel);
|
375
369
|
}
|
376
|
-
if (
|
377
|
-
return this.createSharedArrayByLocalArray(
|
370
|
+
if (Array.isArray(localModel)) {
|
371
|
+
return this.createSharedArrayByLocalArray(localModel, parent);
|
378
372
|
}
|
379
|
-
if (
|
380
|
-
return this.
|
373
|
+
if (typeof localModel === 'object' && localModel !== null) {
|
374
|
+
return this.createSharedMapByLocalMap(localModel, parent);
|
381
375
|
}
|
382
|
-
return
|
376
|
+
return localModel;
|
383
377
|
}
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
// private createLocalModelBySharedByModel(localModel: any, parent: Component<any>): any
|
388
|
-
createLocalModelBySharedByModel(localModel, parent) {
|
389
|
-
if (localModel instanceof yjs.Map) {
|
390
|
-
return this.createLocalMapBySharedMap(localModel, parent);
|
378
|
+
createLocalModelBySharedByModel(sharedModel, parent) {
|
379
|
+
if (sharedModel instanceof yjs.Map) {
|
380
|
+
return this.createLocalMapBySharedMap(sharedModel, parent);
|
391
381
|
}
|
392
|
-
if (
|
393
|
-
return this.createLocalArrayBySharedArray(
|
382
|
+
if (sharedModel instanceof yjs.Array) {
|
383
|
+
return this.createLocalArrayBySharedArray(sharedModel, parent);
|
394
384
|
}
|
395
|
-
if (
|
396
|
-
return this.createLocalSlotBySharedSlot(
|
385
|
+
if (sharedModel instanceof yjs.Text) {
|
386
|
+
return this.createLocalSlotBySharedSlot(sharedModel);
|
397
387
|
}
|
398
|
-
return
|
388
|
+
return sharedModel;
|
399
389
|
}
|
400
390
|
getAbstractSelection(position) {
|
401
391
|
const anchorPosition = yjs.createAbsolutePositionFromRelativePosition(position.anchor, this.yDoc);
|
@@ -569,7 +559,7 @@ exports.Collaborate = class Collaborate {
|
|
569
559
|
});
|
570
560
|
});
|
571
561
|
this.slotMap.set(localSlot, sharedSlot);
|
572
|
-
localSlot.destroyCallbacks.push(() => {
|
562
|
+
localSlot.changeMarker.destroyCallbacks.push(() => {
|
573
563
|
this.slotMap.delete(localSlot);
|
574
564
|
sharedSlot.unobserve(syncRemote);
|
575
565
|
sub.unsubscribe();
|
@@ -601,23 +591,29 @@ exports.Collaborate = class Collaborate {
|
|
601
591
|
* @private
|
602
592
|
*/
|
603
593
|
syncArray(sharedArray, localArray, parent) {
|
604
|
-
const sub = localArray.
|
594
|
+
const sub = localArray.__changeMarker__.onSelfChange.subscribe((actions) => {
|
605
595
|
this.runLocalUpdate(() => {
|
606
596
|
let index = 0;
|
607
|
-
for (const action of
|
597
|
+
for (const action of actions) {
|
608
598
|
switch (action.type) {
|
609
599
|
case 'retain':
|
610
600
|
index = action.offset;
|
611
601
|
break;
|
612
602
|
case 'insert':
|
613
603
|
{
|
614
|
-
const data =
|
604
|
+
const data = action.ref.map(item => {
|
605
|
+
return this.createSharedModelByLocalModel(item, parent);
|
606
|
+
});
|
615
607
|
sharedArray.insert(index, [data]);
|
616
608
|
}
|
617
609
|
break;
|
618
610
|
case 'delete':
|
619
611
|
sharedArray.delete(index, 1);
|
620
612
|
break;
|
613
|
+
case 'setIndex':
|
614
|
+
sharedArray.delete(action.index, 1);
|
615
|
+
sharedArray.insert(action.index, this.createSharedModelByLocalModel(action.ref, parent));
|
616
|
+
break;
|
621
617
|
}
|
622
618
|
}
|
623
619
|
});
|
@@ -625,28 +621,25 @@ exports.Collaborate = class Collaborate {
|
|
625
621
|
const syncRemote = (ev, tr) => {
|
626
622
|
this.runRemoteUpdate(tr, () => {
|
627
623
|
let index = 0;
|
628
|
-
localArray.retain(index);
|
629
624
|
ev.delta.forEach((action) => {
|
630
625
|
if (Reflect.has(action, 'retain')) {
|
631
626
|
index += action.retain;
|
632
|
-
localArray.retain(index);
|
633
627
|
}
|
634
628
|
else if (action.insert) {
|
635
|
-
action.insert.
|
636
|
-
|
637
|
-
localArray.insert(value);
|
638
|
-
index++;
|
629
|
+
const data = action.insert.map((item) => {
|
630
|
+
return this.createLocalModelBySharedByModel(item, parent);
|
639
631
|
});
|
632
|
+
localArray.splice(index, 0, ...data);
|
633
|
+
index += data.length;
|
640
634
|
}
|
641
635
|
else if (action.delete) {
|
642
|
-
localArray.
|
643
|
-
localArray.delete(action.delete);
|
636
|
+
localArray.splice(index, action.delete);
|
644
637
|
}
|
645
638
|
});
|
646
639
|
});
|
647
640
|
};
|
648
641
|
sharedArray.observe(syncRemote);
|
649
|
-
localArray.destroyCallbacks.push(() => {
|
642
|
+
localArray.__changeMarker__.destroyCallbacks.push(() => {
|
650
643
|
sub.unsubscribe();
|
651
644
|
sharedArray.unobserve(syncRemote);
|
652
645
|
});
|
@@ -664,18 +657,18 @@ exports.Collaborate = class Collaborate {
|
|
664
657
|
ev.changes.keys.forEach((item, key) => {
|
665
658
|
if (item.action === 'add' || item.action === 'update') {
|
666
659
|
const value = sharedObject.get(key);
|
667
|
-
localObject
|
660
|
+
localObject[key] = this.createLocalModelBySharedByModel(value, parent);
|
668
661
|
}
|
669
662
|
else {
|
670
|
-
|
663
|
+
Reflect.deleteProperty(localObject, key);
|
671
664
|
}
|
672
665
|
});
|
673
666
|
});
|
674
667
|
};
|
675
668
|
sharedObject.observe(syncRemote);
|
676
|
-
const sub = localObject.
|
669
|
+
const sub = localObject.__changeMarker__.onSelfChange.subscribe((actions) => {
|
677
670
|
this.runLocalUpdate(() => {
|
678
|
-
for (const action of
|
671
|
+
for (const action of actions) {
|
679
672
|
switch (action.type) {
|
680
673
|
case 'propSet':
|
681
674
|
sharedObject.set(action.key, this.createSharedModelByLocalModel(action.value, parent));
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@textbus/collaborate",
|
3
|
-
"version": "4.0.0-alpha.
|
3
|
+
"version": "4.0.0-alpha.28",
|
4
4
|
"description": "Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.",
|
5
5
|
"main": "./bundles/index.js",
|
6
6
|
"module": "./bundles/index.esm.js",
|
@@ -26,7 +26,7 @@
|
|
26
26
|
],
|
27
27
|
"dependencies": {
|
28
28
|
"@tanbo/stream": "^1.2.3",
|
29
|
-
"@textbus/core": "^4.0.0-alpha.
|
29
|
+
"@textbus/core": "^4.0.0-alpha.28",
|
30
30
|
"@viewfly/core": "^0.6.0",
|
31
31
|
"reflect-metadata": "^0.1.13",
|
32
32
|
"y-protocols": "^1.0.5",
|
@@ -50,5 +50,5 @@
|
|
50
50
|
"bugs": {
|
51
51
|
"url": "https://github.com/textbus/textbus.git/issues"
|
52
52
|
},
|
53
|
-
"gitHead": "
|
53
|
+
"gitHead": "afb457beb39742c7e00f78b71cd24e13443bae56"
|
54
54
|
}
|