@textbus/collaborate 2.0.0-beta.21 → 2.0.0-beta.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ import { Plugin } from '@textbus/core';
2
+ import { Injector } from '@tanbo/di';
3
+ export declare class FixedCaretPlugin implements Plugin {
4
+ scrollContainer: HTMLElement;
5
+ private subscriptions;
6
+ constructor(scrollContainer: HTMLElement);
7
+ setup(injector: Injector): void;
8
+ onDestroy(): void;
9
+ }
@@ -0,0 +1,41 @@
1
+ import { Renderer, Scheduler } from '@textbus/core';
2
+ import { Caret } from '@textbus/browser';
3
+ import { Subscription } from '@tanbo/stream';
4
+ export class FixedCaretPlugin {
5
+ constructor(scrollContainer) {
6
+ Object.defineProperty(this, "scrollContainer", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: scrollContainer
11
+ });
12
+ Object.defineProperty(this, "subscriptions", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: new Subscription()
17
+ });
18
+ }
19
+ setup(injector) {
20
+ const scheduler = injector.get(Scheduler);
21
+ const caret = injector.get(Caret);
22
+ const renderer = injector.get(Renderer);
23
+ let isChanged = false;
24
+ let caretPosition = null;
25
+ renderer.onViewChecked.subscribe(() => {
26
+ isChanged = true;
27
+ });
28
+ this.subscriptions.add(caret.onPositionChange.subscribe(position => {
29
+ if (isChanged && caretPosition && position && !scheduler.hasLocalUpdate) {
30
+ const offset = position.top - caretPosition.top;
31
+ this.scrollContainer.scrollTop += offset;
32
+ isChanged = false;
33
+ }
34
+ caretPosition = position;
35
+ }));
36
+ }
37
+ onDestroy() {
38
+ this.subscriptions.unsubscribe();
39
+ }
40
+ }
41
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZml4ZWQtY2FyZXQucGx1Z2luLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ZpeGVkLWNhcmV0LnBsdWdpbi50cyJdLCJuYW1lcyI6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xzZVxuICAgIGxldCBjYXJldFBvc2l0aW9uOiBDYXJldFBvc2l0aW9uIHwgbnVsbCA9IG51bGxcbiAgICByZW5kZXJlci5vblZpZXdDaGVja2VkLnN1YnNjcmliZSgoKSA9PiB7XG4gICAgICBpc0NoYW5nZWQgPSB0cnVlXG4gICAgfSlcbiAgICB0aGlzLnN1YnNjcmlwdGlvbnMuYWRkKGNhcmV0Lm9uUG9zaXRpb25DaGFuZ2Uuc3Vic2NyaWJlKHBvc2l0aW9uID0+IHtcbiAgICAgIGlmIChpc0NoYW5nZWQgJiYgY2FyZXRQb3NpdGlvbiAmJiBwb3NpdGlvbiAmJiAhc2NoZWR1bGVyLmhhc0xvY2FsVXBkYXRlKSB7XG4gICAgICAgIGNvbnN0IG9mZnNldCA9IHBvc2l0aW9uLnRvcCAtIGNhcmV0UG9zaXRpb24udG9wXG4gICAgICAgIHRoaXMuc2Nyb2xsQ29udGFpbmVyLnNjcm9sbFRvcCArPSBvZmZzZXRcbiAgICAgICAgaXNDaGFuZ2VkID0gZmFsc2VcbiAgICAgIH1cbiAgICAgIGNhcmV0UG9zaXRpb24gPSBwb3NpdGlvblxuICAgIH0pKVxuICB9XG5cbiAgb25EZXN0cm95KCkge1xuICAgIHRoaXMuc3Vic2NyaXB0aW9ucy51bnN1YnNjcmliZSgpXG4gIH1cbn1cbiJdfQ==
@@ -1,4 +1,5 @@
1
1
  import { Module } from '@textbus/core';
2
2
  export * from './collaborate';
3
3
  export * from './collaborate-cursor';
4
+ export * from './fixed-caret.plugin';
4
5
  export declare const collaborateModule: Module;
@@ -3,6 +3,7 @@ import { Collaborate } from './collaborate';
3
3
  import { CollaborateCursor } from './collaborate-cursor';
4
4
  export * from './collaborate';
5
5
  export * from './collaborate-cursor';
6
+ export * from './fixed-caret.plugin';
6
7
  export const collaborateModule = {
7
8
  providers: [
8
9
  Collaborate,
@@ -13,4 +14,4 @@ export const collaborateModule = {
13
14
  }
14
15
  ]
15
16
  };
16
- //# sourceMappingURL=data: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SAnLi9maXhlZC1jYXJldC5wbHVnaW4nXG5cbmV4cG9ydCBjb25zdCBjb2xsYWJvcmF0ZU1vZHVsZTogTW9kdWxlID0ge1xuICBwcm92aWRlcnM6IFtcbiAgICBDb2xsYWJvcmF0ZSxcbiAgICBDb2xsYWJvcmF0ZUN1cnNvcixcbiAgICB7XG4gICAgICBwcm92aWRlOiBIaXN0b3J5LFxuICAgICAgdXNlQ2xhc3M6IENvbGxhYm9yYXRlXG4gICAgfVxuICBdXG59XG4iXX0=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/collaborate",
3
- "version": "2.0.0-beta.21",
3
+ "version": "2.0.0-beta.22",
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/public-api.js",
6
6
  "module": "./bundles/public-api.js",
@@ -27,8 +27,8 @@
27
27
  "dependencies": {
28
28
  "@tanbo/di": "^1.1.1",
29
29
  "@tanbo/stream": "^1.0.2",
30
- "@textbus/browser": "^2.0.0-beta.21",
31
- "@textbus/core": "^2.0.0-beta.20",
30
+ "@textbus/browser": "^2.0.0-beta.22",
31
+ "@textbus/core": "^2.0.0-beta.22",
32
32
  "reflect-metadata": "^0.1.13",
33
33
  "y-protocols": "^1.0.5",
34
34
  "yjs": "^13.5.27"
@@ -44,5 +44,5 @@
44
44
  "bugs": {
45
45
  "url": "https://github.com/textbus/textbus.git/issues"
46
46
  },
47
- "gitHead": "754c608280cbab4d50fa385495966bd012d2591a"
47
+ "gitHead": "2ee52d09e59875e4e8fccd769ef395d4fe373b09"
48
48
  }
@@ -0,0 +1,35 @@
1
+ import { Plugin, Renderer, Scheduler } from '@textbus/core'
2
+ import { Injector } from '@tanbo/di'
3
+ import { Caret, CaretPosition } from '@textbus/browser'
4
+ import { Subscription } from '@tanbo/stream'
5
+
6
+ export class FixedCaretPlugin implements Plugin {
7
+ private subscriptions = new Subscription()
8
+
9
+ constructor(public scrollContainer: HTMLElement) {
10
+ }
11
+
12
+ setup(injector: Injector) {
13
+ const scheduler = injector.get(Scheduler)
14
+ const caret = injector.get(Caret)
15
+ const renderer = injector.get(Renderer)
16
+
17
+ let isChanged = false
18
+ let caretPosition: CaretPosition | null = null
19
+ renderer.onViewChecked.subscribe(() => {
20
+ isChanged = true
21
+ })
22
+ this.subscriptions.add(caret.onPositionChange.subscribe(position => {
23
+ if (isChanged && caretPosition && position && !scheduler.hasLocalUpdate) {
24
+ const offset = position.top - caretPosition.top
25
+ this.scrollContainer.scrollTop += offset
26
+ isChanged = false
27
+ }
28
+ caretPosition = position
29
+ }))
30
+ }
31
+
32
+ onDestroy() {
33
+ this.subscriptions.unsubscribe()
34
+ }
35
+ }
package/src/public-api.ts CHANGED
@@ -5,6 +5,7 @@ import { CollaborateCursor } from './collaborate-cursor'
5
5
 
6
6
  export * from './collaborate'
7
7
  export * from './collaborate-cursor'
8
+ export * from './fixed-caret.plugin'
8
9
 
9
10
  export const collaborateModule: Module = {
10
11
  providers: [