@textbus/collaborate 4.0.0-alpha.34 → 4.0.0-alpha.36

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.
@@ -60,7 +60,6 @@ export declare class Collaborate implements History {
60
60
  * 双向同步数组
61
61
  * @param sharedArray
62
62
  * @param localArray
63
- * @param parent
64
63
  * @private
65
64
  */
66
65
  private syncArray;
@@ -68,7 +67,6 @@ export declare class Collaborate implements History {
68
67
  * 双向同步对象
69
68
  * @param sharedObject
70
69
  * @param localObject
71
- * @param parent
72
70
  * @private
73
71
  */
74
72
  private syncObject;
@@ -258,7 +258,7 @@ let Collaborate = class Collaborate {
258
258
  let state = root.get('state');
259
259
  if (!state) {
260
260
  state = new Map();
261
- this.syncLocalMapToSharedMap(rootComponent.state, state, rootComponent);
261
+ this.syncLocalMapToSharedMap(rootComponent.state, state);
262
262
  this.yDoc.transact(() => {
263
263
  root.set('state', state);
264
264
  });
@@ -267,43 +267,43 @@ let Collaborate = class Collaborate {
267
267
  Object.keys(rootComponent.state).forEach(key => {
268
268
  Reflect.deleteProperty(rootComponent.state, key);
269
269
  });
270
- this.syncSharedMapToLocalMap(state, rootComponent.state, rootComponent);
270
+ this.syncSharedMapToLocalMap(state, rootComponent.state);
271
271
  }
272
272
  }
273
- syncSharedMapToLocalMap(sharedMap, localMap, parent) {
273
+ syncSharedMapToLocalMap(sharedMap, localMap) {
274
274
  sharedMap.forEach((value, key) => {
275
- localMap[key] = this.createLocalModelBySharedByModel(value, parent);
275
+ localMap[key] = this.createLocalModelBySharedByModel(value);
276
276
  });
277
- this.syncObject(sharedMap, localMap, parent);
277
+ this.syncObject(sharedMap, localMap);
278
278
  }
279
- createLocalMapBySharedMap(sharedMap, parent) {
280
- const localMap = createObjectProxy({}, parent);
281
- this.syncSharedMapToLocalMap(sharedMap, localMap, parent);
279
+ createLocalMapBySharedMap(sharedMap) {
280
+ const localMap = createObjectProxy({});
281
+ this.syncSharedMapToLocalMap(sharedMap, localMap);
282
282
  return localMap;
283
283
  }
284
- createLocalArrayBySharedArray(sharedArray, parent) {
285
- const localArray = createArrayProxy([], parent);
286
- localArray.push(...sharedArray.map(item => this.createLocalModelBySharedByModel(item, parent)));
287
- this.syncArray(sharedArray, localArray, parent);
284
+ createLocalArrayBySharedArray(sharedArray) {
285
+ const localArray = createArrayProxy([]);
286
+ localArray.push(...sharedArray.map(item => this.createLocalModelBySharedByModel(item)));
287
+ this.syncArray(sharedArray, localArray);
288
288
  return localArray;
289
289
  }
290
- syncLocalMapToSharedMap(localMap, sharedMap, parent) {
290
+ syncLocalMapToSharedMap(localMap, sharedMap) {
291
291
  Object.entries(localMap).forEach(([key, value]) => {
292
- sharedMap.set(key, this.createSharedModelByLocalModel(value, parent));
292
+ sharedMap.set(key, this.createSharedModelByLocalModel(value));
293
293
  });
294
- this.syncObject(sharedMap, localMap, parent);
294
+ this.syncObject(sharedMap, localMap);
295
295
  }
296
- createSharedMapByLocalMap(localMap, parent) {
296
+ createSharedMapByLocalMap(localMap) {
297
297
  const sharedMap = new Map();
298
- this.syncLocalMapToSharedMap(localMap, sharedMap, parent);
298
+ this.syncLocalMapToSharedMap(localMap, sharedMap);
299
299
  return sharedMap;
300
300
  }
301
- createSharedArrayByLocalArray(localArray, parent) {
301
+ createSharedArrayByLocalArray(localArray) {
302
302
  const sharedArray = new Array$1();
303
303
  localArray.forEach(value => {
304
- sharedArray.push([this.createSharedModelByLocalModel(value, parent)]);
304
+ sharedArray.push([this.createSharedModelByLocalModel(value)]);
305
305
  });
306
- this.syncArray(sharedArray, localArray, parent);
306
+ this.syncArray(sharedArray, localArray);
307
307
  return sharedArray;
308
308
  }
309
309
  createSharedSlotByLocalSlot(localSlot) {
@@ -364,24 +364,24 @@ let Collaborate = class Collaborate {
364
364
  this.syncSlot(sharedSlot, localSlot);
365
365
  return localSlot;
366
366
  }
367
- createSharedModelByLocalModel(localModel, parent) {
367
+ createSharedModelByLocalModel(localModel) {
368
368
  if (localModel instanceof Slot) {
369
369
  return this.createSharedSlotByLocalSlot(localModel);
370
370
  }
371
371
  if (Array.isArray(localModel)) {
372
- return this.createSharedArrayByLocalArray(localModel, parent);
372
+ return this.createSharedArrayByLocalArray(localModel);
373
373
  }
374
374
  if (typeof localModel === 'object' && localModel !== null) {
375
- return this.createSharedMapByLocalMap(localModel, parent);
375
+ return this.createSharedMapByLocalMap(localModel);
376
376
  }
377
377
  return localModel;
378
378
  }
379
- createLocalModelBySharedByModel(sharedModel, parent) {
379
+ createLocalModelBySharedByModel(sharedModel) {
380
380
  if (sharedModel instanceof Map) {
381
- return this.createLocalMapBySharedMap(sharedModel, parent);
381
+ return this.createLocalMapBySharedMap(sharedModel);
382
382
  }
383
383
  if (sharedModel instanceof Array$1) {
384
- return this.createLocalArrayBySharedArray(sharedModel, parent);
384
+ return this.createLocalArrayBySharedArray(sharedModel);
385
385
  }
386
386
  if (sharedModel instanceof Text) {
387
387
  return this.createLocalSlotBySharedSlot(sharedModel);
@@ -560,7 +560,7 @@ let Collaborate = class Collaborate {
560
560
  });
561
561
  });
562
562
  this.slotMap.set(localSlot, sharedSlot);
563
- localSlot.changeMarker.destroyCallbacks.push(() => {
563
+ localSlot.__changeMarker__.destroyCallbacks.push(() => {
564
564
  this.slotMap.delete(localSlot);
565
565
  sharedSlot.unobserve(syncRemote);
566
566
  sub.unsubscribe();
@@ -568,7 +568,7 @@ let Collaborate = class Collaborate {
568
568
  }
569
569
  createSharedComponentByLocalComponent(component) {
570
570
  const sharedComponent = new Map();
571
- const sharedState = this.createSharedMapByLocalMap(component.state, component);
571
+ const sharedState = this.createSharedMapByLocalMap(component.state);
572
572
  sharedComponent.set('name', component.name);
573
573
  sharedComponent.set('state', sharedState);
574
574
  return sharedComponent;
@@ -576,9 +576,8 @@ let Collaborate = class Collaborate {
576
576
  createLocalComponentBySharedComponent(yMap) {
577
577
  const componentName = yMap.get('name');
578
578
  const sharedState = yMap.get('state');
579
- const instance = this.registry.createComponentByData(componentName, (component) => {
580
- return this.createLocalMapBySharedMap(sharedState, component);
581
- });
579
+ const state = this.createLocalMapBySharedMap(sharedState);
580
+ const instance = this.registry.createComponentByData(componentName, state);
582
581
  if (instance) {
583
582
  return instance;
584
583
  }
@@ -588,10 +587,9 @@ let Collaborate = class Collaborate {
588
587
  * 双向同步数组
589
588
  * @param sharedArray
590
589
  * @param localArray
591
- * @param parent
592
590
  * @private
593
591
  */
594
- syncArray(sharedArray, localArray, parent) {
592
+ syncArray(sharedArray, localArray) {
595
593
  const sub = localArray.__changeMarker__.onSelfChange.subscribe((actions) => {
596
594
  this.runLocalUpdate(() => {
597
595
  let index = 0;
@@ -603,7 +601,7 @@ let Collaborate = class Collaborate {
603
601
  case 'insert':
604
602
  {
605
603
  const data = action.ref.map(item => {
606
- return this.createSharedModelByLocalModel(item, parent);
604
+ return this.createSharedModelByLocalModel(item);
607
605
  });
608
606
  sharedArray.insert(index, data);
609
607
  }
@@ -613,7 +611,7 @@ let Collaborate = class Collaborate {
613
611
  break;
614
612
  case 'setIndex':
615
613
  sharedArray.delete(action.index, 1);
616
- sharedArray.insert(action.index, [this.createSharedModelByLocalModel(action.ref, parent)]);
614
+ sharedArray.insert(action.index, [this.createSharedModelByLocalModel(action.ref)]);
617
615
  break;
618
616
  }
619
617
  }
@@ -628,7 +626,7 @@ let Collaborate = class Collaborate {
628
626
  }
629
627
  else if (action.insert) {
630
628
  const data = action.insert.map((item) => {
631
- return this.createLocalModelBySharedByModel(item, parent);
629
+ return this.createLocalModelBySharedByModel(item);
632
630
  });
633
631
  localArray.splice(index, 0, ...data);
634
632
  index += data.length;
@@ -649,16 +647,15 @@ let Collaborate = class Collaborate {
649
647
  * 双向同步对象
650
648
  * @param sharedObject
651
649
  * @param localObject
652
- * @param parent
653
650
  * @private
654
651
  */
655
- syncObject(sharedObject, localObject, parent) {
652
+ syncObject(sharedObject, localObject) {
656
653
  const syncRemote = (ev, tr) => {
657
654
  this.runRemoteUpdate(tr, () => {
658
655
  ev.changes.keys.forEach((item, key) => {
659
656
  if (item.action === 'add' || item.action === 'update') {
660
657
  const value = sharedObject.get(key);
661
- localObject[key] = this.createLocalModelBySharedByModel(value, parent);
658
+ localObject[key] = this.createLocalModelBySharedByModel(value);
662
659
  }
663
660
  else {
664
661
  Reflect.deleteProperty(localObject, key);
@@ -672,7 +669,7 @@ let Collaborate = class Collaborate {
672
669
  for (const action of actions) {
673
670
  switch (action.type) {
674
671
  case 'propSet':
675
- sharedObject.set(action.key, this.createSharedModelByLocalModel(action.value, parent));
672
+ sharedObject.set(action.key, this.createSharedModelByLocalModel(action.value));
676
673
  break;
677
674
  case 'propDelete':
678
675
  sharedObject.delete(action.key);
package/bundles/index.js CHANGED
@@ -260,7 +260,7 @@ exports.Collaborate = class Collaborate {
260
260
  let state = root.get('state');
261
261
  if (!state) {
262
262
  state = new yjs.Map();
263
- this.syncLocalMapToSharedMap(rootComponent.state, state, rootComponent);
263
+ this.syncLocalMapToSharedMap(rootComponent.state, state);
264
264
  this.yDoc.transact(() => {
265
265
  root.set('state', state);
266
266
  });
@@ -269,43 +269,43 @@ exports.Collaborate = class Collaborate {
269
269
  Object.keys(rootComponent.state).forEach(key => {
270
270
  Reflect.deleteProperty(rootComponent.state, key);
271
271
  });
272
- this.syncSharedMapToLocalMap(state, rootComponent.state, rootComponent);
272
+ this.syncSharedMapToLocalMap(state, rootComponent.state);
273
273
  }
274
274
  }
275
- syncSharedMapToLocalMap(sharedMap, localMap, parent) {
275
+ syncSharedMapToLocalMap(sharedMap, localMap) {
276
276
  sharedMap.forEach((value, key) => {
277
- localMap[key] = this.createLocalModelBySharedByModel(value, parent);
277
+ localMap[key] = this.createLocalModelBySharedByModel(value);
278
278
  });
279
- this.syncObject(sharedMap, localMap, parent);
279
+ this.syncObject(sharedMap, localMap);
280
280
  }
281
- createLocalMapBySharedMap(sharedMap, parent) {
282
- const localMap = core.createObjectProxy({}, parent);
283
- this.syncSharedMapToLocalMap(sharedMap, localMap, parent);
281
+ createLocalMapBySharedMap(sharedMap) {
282
+ const localMap = core.createObjectProxy({});
283
+ this.syncSharedMapToLocalMap(sharedMap, localMap);
284
284
  return localMap;
285
285
  }
286
- createLocalArrayBySharedArray(sharedArray, parent) {
287
- const localArray = core.createArrayProxy([], parent);
288
- localArray.push(...sharedArray.map(item => this.createLocalModelBySharedByModel(item, parent)));
289
- this.syncArray(sharedArray, localArray, parent);
286
+ createLocalArrayBySharedArray(sharedArray) {
287
+ const localArray = core.createArrayProxy([]);
288
+ localArray.push(...sharedArray.map(item => this.createLocalModelBySharedByModel(item)));
289
+ this.syncArray(sharedArray, localArray);
290
290
  return localArray;
291
291
  }
292
- syncLocalMapToSharedMap(localMap, sharedMap, parent) {
292
+ syncLocalMapToSharedMap(localMap, sharedMap) {
293
293
  Object.entries(localMap).forEach(([key, value]) => {
294
- sharedMap.set(key, this.createSharedModelByLocalModel(value, parent));
294
+ sharedMap.set(key, this.createSharedModelByLocalModel(value));
295
295
  });
296
- this.syncObject(sharedMap, localMap, parent);
296
+ this.syncObject(sharedMap, localMap);
297
297
  }
298
- createSharedMapByLocalMap(localMap, parent) {
298
+ createSharedMapByLocalMap(localMap) {
299
299
  const sharedMap = new yjs.Map();
300
- this.syncLocalMapToSharedMap(localMap, sharedMap, parent);
300
+ this.syncLocalMapToSharedMap(localMap, sharedMap);
301
301
  return sharedMap;
302
302
  }
303
- createSharedArrayByLocalArray(localArray, parent) {
303
+ createSharedArrayByLocalArray(localArray) {
304
304
  const sharedArray = new yjs.Array();
305
305
  localArray.forEach(value => {
306
- sharedArray.push([this.createSharedModelByLocalModel(value, parent)]);
306
+ sharedArray.push([this.createSharedModelByLocalModel(value)]);
307
307
  });
308
- this.syncArray(sharedArray, localArray, parent);
308
+ this.syncArray(sharedArray, localArray);
309
309
  return sharedArray;
310
310
  }
311
311
  createSharedSlotByLocalSlot(localSlot) {
@@ -366,24 +366,24 @@ exports.Collaborate = class Collaborate {
366
366
  this.syncSlot(sharedSlot, localSlot);
367
367
  return localSlot;
368
368
  }
369
- createSharedModelByLocalModel(localModel, parent) {
369
+ createSharedModelByLocalModel(localModel) {
370
370
  if (localModel instanceof core.Slot) {
371
371
  return this.createSharedSlotByLocalSlot(localModel);
372
372
  }
373
373
  if (Array.isArray(localModel)) {
374
- return this.createSharedArrayByLocalArray(localModel, parent);
374
+ return this.createSharedArrayByLocalArray(localModel);
375
375
  }
376
376
  if (typeof localModel === 'object' && localModel !== null) {
377
- return this.createSharedMapByLocalMap(localModel, parent);
377
+ return this.createSharedMapByLocalMap(localModel);
378
378
  }
379
379
  return localModel;
380
380
  }
381
- createLocalModelBySharedByModel(sharedModel, parent) {
381
+ createLocalModelBySharedByModel(sharedModel) {
382
382
  if (sharedModel instanceof yjs.Map) {
383
- return this.createLocalMapBySharedMap(sharedModel, parent);
383
+ return this.createLocalMapBySharedMap(sharedModel);
384
384
  }
385
385
  if (sharedModel instanceof yjs.Array) {
386
- return this.createLocalArrayBySharedArray(sharedModel, parent);
386
+ return this.createLocalArrayBySharedArray(sharedModel);
387
387
  }
388
388
  if (sharedModel instanceof yjs.Text) {
389
389
  return this.createLocalSlotBySharedSlot(sharedModel);
@@ -562,7 +562,7 @@ exports.Collaborate = class Collaborate {
562
562
  });
563
563
  });
564
564
  this.slotMap.set(localSlot, sharedSlot);
565
- localSlot.changeMarker.destroyCallbacks.push(() => {
565
+ localSlot.__changeMarker__.destroyCallbacks.push(() => {
566
566
  this.slotMap.delete(localSlot);
567
567
  sharedSlot.unobserve(syncRemote);
568
568
  sub.unsubscribe();
@@ -570,7 +570,7 @@ exports.Collaborate = class Collaborate {
570
570
  }
571
571
  createSharedComponentByLocalComponent(component) {
572
572
  const sharedComponent = new yjs.Map();
573
- const sharedState = this.createSharedMapByLocalMap(component.state, component);
573
+ const sharedState = this.createSharedMapByLocalMap(component.state);
574
574
  sharedComponent.set('name', component.name);
575
575
  sharedComponent.set('state', sharedState);
576
576
  return sharedComponent;
@@ -578,9 +578,8 @@ exports.Collaborate = class Collaborate {
578
578
  createLocalComponentBySharedComponent(yMap) {
579
579
  const componentName = yMap.get('name');
580
580
  const sharedState = yMap.get('state');
581
- const instance = this.registry.createComponentByData(componentName, (component) => {
582
- return this.createLocalMapBySharedMap(sharedState, component);
583
- });
581
+ const state = this.createLocalMapBySharedMap(sharedState);
582
+ const instance = this.registry.createComponentByData(componentName, state);
584
583
  if (instance) {
585
584
  return instance;
586
585
  }
@@ -590,10 +589,9 @@ exports.Collaborate = class Collaborate {
590
589
  * 双向同步数组
591
590
  * @param sharedArray
592
591
  * @param localArray
593
- * @param parent
594
592
  * @private
595
593
  */
596
- syncArray(sharedArray, localArray, parent) {
594
+ syncArray(sharedArray, localArray) {
597
595
  const sub = localArray.__changeMarker__.onSelfChange.subscribe((actions) => {
598
596
  this.runLocalUpdate(() => {
599
597
  let index = 0;
@@ -605,7 +603,7 @@ exports.Collaborate = class Collaborate {
605
603
  case 'insert':
606
604
  {
607
605
  const data = action.ref.map(item => {
608
- return this.createSharedModelByLocalModel(item, parent);
606
+ return this.createSharedModelByLocalModel(item);
609
607
  });
610
608
  sharedArray.insert(index, data);
611
609
  }
@@ -615,7 +613,7 @@ exports.Collaborate = class Collaborate {
615
613
  break;
616
614
  case 'setIndex':
617
615
  sharedArray.delete(action.index, 1);
618
- sharedArray.insert(action.index, [this.createSharedModelByLocalModel(action.ref, parent)]);
616
+ sharedArray.insert(action.index, [this.createSharedModelByLocalModel(action.ref)]);
619
617
  break;
620
618
  }
621
619
  }
@@ -630,7 +628,7 @@ exports.Collaborate = class Collaborate {
630
628
  }
631
629
  else if (action.insert) {
632
630
  const data = action.insert.map((item) => {
633
- return this.createLocalModelBySharedByModel(item, parent);
631
+ return this.createLocalModelBySharedByModel(item);
634
632
  });
635
633
  localArray.splice(index, 0, ...data);
636
634
  index += data.length;
@@ -651,16 +649,15 @@ exports.Collaborate = class Collaborate {
651
649
  * 双向同步对象
652
650
  * @param sharedObject
653
651
  * @param localObject
654
- * @param parent
655
652
  * @private
656
653
  */
657
- syncObject(sharedObject, localObject, parent) {
654
+ syncObject(sharedObject, localObject) {
658
655
  const syncRemote = (ev, tr) => {
659
656
  this.runRemoteUpdate(tr, () => {
660
657
  ev.changes.keys.forEach((item, key) => {
661
658
  if (item.action === 'add' || item.action === 'update') {
662
659
  const value = sharedObject.get(key);
663
- localObject[key] = this.createLocalModelBySharedByModel(value, parent);
660
+ localObject[key] = this.createLocalModelBySharedByModel(value);
664
661
  }
665
662
  else {
666
663
  Reflect.deleteProperty(localObject, key);
@@ -674,7 +671,7 @@ exports.Collaborate = class Collaborate {
674
671
  for (const action of actions) {
675
672
  switch (action.type) {
676
673
  case 'propSet':
677
- sharedObject.set(action.key, this.createSharedModelByLocalModel(action.value, parent));
674
+ sharedObject.set(action.key, this.createSharedModelByLocalModel(action.value));
678
675
  break;
679
676
  case 'propDelete':
680
677
  sharedObject.delete(action.key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/collaborate",
3
- "version": "4.0.0-alpha.34",
3
+ "version": "4.0.0-alpha.36",
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.34",
29
+ "@textbus/core": "^4.0.0-alpha.36",
30
30
  "@viewfly/core": "^0.6.3",
31
31
  "reflect-metadata": "^0.1.13",
32
32
  "y-websocket": "^1.4.3",
@@ -50,5 +50,5 @@
50
50
  "bugs": {
51
51
  "url": "https://github.com/textbus/textbus.git/issues"
52
52
  },
53
- "gitHead": "b6f9bfbce3135865fc0c8a3e6b622a7040019634"
53
+ "gitHead": "dbcf24938a558780bc752cdcd3633d0e21a7a0d9"
54
54
  }