@atlaskit/collab-provider 7.1.1 → 7.1.5

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.
@@ -1,57 +1,11 @@
1
1
  import { EditorState, Transaction } from 'prosemirror-state';
2
- import { Step } from 'prosemirror-transform';
3
2
  import { Emitter } from '../emitter';
4
- import { Metadata, StepJson } from '../channel';
5
- import { CollabEditProvider, CollabEventTelepointerData as EditorCollabTelepointerData, CollabEventConnectionData as EditorCollabConnetedData, CollabEventInitData as EditorCollabInitData, CollabEventRemoteData as EditorCollabData, CollabEventPresenceData as EditorCollabPresenceData } from '@atlaskit/editor-common/collab';
6
- import { Config } from '../types';
7
- import { DisconnectReason } from '../disconnected-reason-mapper';
3
+ import { CollabEditProvider, ResolvedEditorState } from '@atlaskit/editor-common/collab';
4
+ import type { Config, Metadata, CollabEvents } from '../types';
5
+ import { SyncUpErrorFunction } from '@atlaskit/editor-common/types';
8
6
  export declare const CATCHUP_THROTTLE: number;
9
7
  export declare const MAX_STEP_REJECTED_ERROR = 15;
10
- export declare type CollabConnectedPayload = EditorCollabConnetedData;
11
- export interface CollabDisconnectedPayload {
12
- reason: DisconnectReason;
13
- sid: string;
14
- }
15
- export interface CollabErrorPayload {
16
- status: number;
17
- code: string;
18
- message: string;
19
- }
20
- export interface CollabInitPayload extends EditorCollabInitData {
21
- doc: any;
22
- version: number;
23
- userId?: string;
24
- metadata?: Metadata;
25
- }
26
- export interface CollabDataPayload extends EditorCollabData {
27
- version: number;
28
- json: StepJson[];
29
- userIds: string[];
30
- }
31
- export declare type CollabTelepointerPayload = EditorCollabTelepointerData;
32
- export declare type CollabPresencePayload = EditorCollabPresenceData;
33
- export declare type CollabMetadataPayload = Metadata;
34
- export declare type CollabLocalStepsPayload = {
35
- steps: Step[];
36
- };
37
- export interface CollabEvents {
38
- 'metadata:changed': CollabMetadataPayload;
39
- init: CollabInitPayload;
40
- connected: CollabConnectedPayload;
41
- disconnected: CollabDisconnectedPayload;
42
- data: CollabDataPayload;
43
- telepointer: CollabTelepointerPayload;
44
- presence: CollabPresencePayload;
45
- 'local-steps': CollabLocalStepsPayload;
46
- error: CollabErrorPayload;
47
- entity: any;
48
- }
49
- declare type EditorStateGetter = () => EditorState;
50
- declare type InitializeOptions = {
51
- getState: EditorStateGetter;
52
- clientId: string;
53
- };
54
- declare type BaseEvents = Pick<CollabEditProvider<CollabEvents>, 'initialize' | 'send' | 'sendMessage'>;
8
+ declare type BaseEvents = Pick<CollabEditProvider<CollabEvents>, 'setup' | 'send' | 'sendMessage'>;
55
9
  export declare class Provider extends Emitter<CollabEvents> implements BaseEvents {
56
10
  private participants;
57
11
  private channel;
@@ -60,6 +14,8 @@ export declare class Provider extends Emitter<CollabEvents> implements BaseEvent
60
14
  private metadata;
61
15
  private stepRejectCounter;
62
16
  private analyticsClient?;
17
+ private isChannelInitialized;
18
+ private onSyncUpError?;
63
19
  private sessionId?;
64
20
  private clientId?;
65
21
  private userId?;
@@ -67,12 +23,16 @@ export declare class Provider extends Emitter<CollabEvents> implements BaseEvent
67
23
  private presenceUpdateTimeout?;
68
24
  private disconnectedAt?;
69
25
  constructor(config: Config);
26
+ private initializeChannel;
70
27
  /**
71
28
  * Called by collab plugin in editor when it's ready to
72
29
  * initialize a collab session.
73
30
  */
74
- initialize(getState: EditorStateGetter): this;
75
- initialize(options: InitializeOptions): this;
31
+ initialize(getState: () => EditorState): this;
32
+ setup({ getState, onSyncUpError, }: {
33
+ getState: () => EditorState;
34
+ onSyncUpError?: SyncUpErrorFunction;
35
+ }): this;
76
36
  /**
77
37
  * We can use this function to throttle/delay
78
38
  * Any send steps operation
@@ -155,18 +115,7 @@ export declare class Provider extends Emitter<CollabEvents> implements BaseEvent
155
115
  setTitle(title: string, broadcast?: boolean): void;
156
116
  setEditorWidth(editorWidth: string, broadcast?: boolean): void;
157
117
  setMetadata(metadata: Metadata): void;
158
- /**
159
- * Get latest state.
160
- *
161
- * NOTE: Should this actually convert to ADF instead?
162
- */
163
- getFinalAcknowledgedState(): Promise<{
164
- content: {
165
- [key: string]: any;
166
- };
167
- title: string | number | boolean;
168
- stepVersion: number;
169
- }>;
118
+ getFinalAcknowledgedState: () => Promise<ResolvedEditorState>;
170
119
  /**
171
120
  * Unsubscribe from all events emitted by this provider.
172
121
  */
@@ -1,6 +1,9 @@
1
- import { CollabParticipant } from '@atlaskit/editor-common/collab';
2
- import { AnalyticsWebClient } from '@atlaskit/analytics-listeners';
3
- import { Manager } from 'socket.io-client';
1
+ import type { Transaction } from 'prosemirror-state';
2
+ import type { Step } from 'prosemirror-transform';
3
+ import type { CollabParticipant, CollabEventTelepointerData as EditorCollabTelepointerData, CollabEventConnectionData as EditorCollabConnetedData, CollabEventInitData as EditorCollabInitData, CollabEventRemoteData as EditorCollabData, CollabEventPresenceData as EditorCollabPresenceData } from '@atlaskit/editor-common/collab';
4
+ import type { AnalyticsWebClient } from '@atlaskit/analytics-listeners';
5
+ import type { Manager } from 'socket.io-client';
6
+ import type { DisconnectReason } from './disconnected-reason-mapper';
4
7
  export interface Storage {
5
8
  get(key: string): Promise<string>;
6
9
  set(key: string, value: string): Promise<void>;
@@ -33,4 +36,125 @@ export declare type EventHandler = () => void;
33
36
  export interface Lifecycle {
34
37
  on(event: LifecycleEvents, handler: EventHandler): void;
35
38
  }
39
+ export declare type CollabConnectedPayload = EditorCollabConnetedData;
40
+ export interface CollabDisconnectedPayload {
41
+ reason: DisconnectReason;
42
+ sid: string;
43
+ }
44
+ export interface CollabErrorPayload {
45
+ status: number;
46
+ code: string;
47
+ message: string;
48
+ }
49
+ export interface CollabInitPayload extends EditorCollabInitData {
50
+ doc: any;
51
+ version: number;
52
+ userId?: string;
53
+ metadata?: Metadata;
54
+ }
55
+ export interface CollabDataPayload extends EditorCollabData {
56
+ version: number;
57
+ json: StepJson[];
58
+ userIds: string[];
59
+ }
60
+ export declare type CollabTelepointerPayload = EditorCollabTelepointerData;
61
+ export declare type CollabPresencePayload = EditorCollabPresenceData;
62
+ export declare type CollabMetadataPayload = Metadata;
63
+ export declare type CollabLocalStepsPayload = {
64
+ steps: Step[];
65
+ };
66
+ export interface CollabEvents {
67
+ 'metadata:changed': CollabMetadataPayload;
68
+ init: CollabInitPayload;
69
+ connected: CollabConnectedPayload;
70
+ disconnected: CollabDisconnectedPayload;
71
+ data: CollabDataPayload;
72
+ telepointer: CollabTelepointerPayload;
73
+ presence: CollabPresencePayload;
74
+ 'local-steps': CollabLocalStepsPayload;
75
+ error: CollabErrorPayload;
76
+ entity: any;
77
+ }
78
+ export interface Metadata {
79
+ [key: string]: string | number | boolean;
80
+ }
81
+ export declare type InitPayload = {
82
+ doc: any;
83
+ version: number;
84
+ userId?: string;
85
+ metadata?: Metadata;
86
+ };
87
+ export declare type PresencePayload = {
88
+ sessionId: string;
89
+ userId: string;
90
+ clientId: string;
91
+ timestamp: number;
92
+ };
93
+ export declare type TelepointerPayload = PresencePayload & {
94
+ selection: {
95
+ type: 'textSelection' | 'nodeSelection';
96
+ anchor: number;
97
+ head: number;
98
+ };
99
+ };
100
+ export declare type StepJson = {
101
+ from?: number;
102
+ to?: number;
103
+ stepType?: string;
104
+ clientId: string;
105
+ userId: string;
106
+ };
107
+ export declare type StepsPayload = {
108
+ version: number;
109
+ steps: StepJson[];
110
+ };
111
+ export declare type ErrorPayload = {
112
+ message: string;
113
+ data?: {
114
+ status: number;
115
+ code?: string;
116
+ meta?: string;
117
+ };
118
+ };
119
+ export declare type ChannelEvent = {
120
+ connected: {
121
+ sid: string;
122
+ initialized: boolean;
123
+ };
124
+ init: InitPayload;
125
+ reconnected: null;
126
+ 'presence:joined': PresencePayload;
127
+ presence: PresencePayload;
128
+ 'participant:left': PresencePayload;
129
+ 'participant:telepointer': TelepointerPayload;
130
+ 'participant:updated': PresencePayload;
131
+ 'steps:commit': StepsPayload & {
132
+ userId: string;
133
+ };
134
+ 'steps:added': StepsPayload;
135
+ 'metadata:changed': Metadata;
136
+ error: ErrorPayload;
137
+ disconnect: {
138
+ reason: string;
139
+ };
140
+ };
141
+ export interface CatchupResponse {
142
+ doc?: string;
143
+ version?: number;
144
+ stepMaps?: any[];
145
+ metadata?: Metadata;
146
+ }
147
+ export interface CatchupOptions {
148
+ getCurrentPmVersion: () => number;
149
+ fetchCatchup: (fromVersion: number) => Promise<CatchupResponse>;
150
+ fitlerQueue: (condition: (stepsPayload: StepsPayload) => boolean) => void;
151
+ getUnconfirmedSteps: () => {
152
+ version: number;
153
+ steps: Step<any>[];
154
+ clientID: string | number;
155
+ origins: Transaction<any>[];
156
+ } | null | undefined;
157
+ updateDocumentWithMetadata: ({ doc, version, metadata, reserveCursor, }: CollabInitPayload) => void;
158
+ applyLocalsteps: (steps: Step[]) => void;
159
+ }
36
160
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "7.1.1",
3
+ "version": "7.1.5",
4
4
  "description": "A provider for collaborative editing.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -22,12 +22,13 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@atlaskit/analytics-gas-types": "5.0.5",
25
- "@atlaskit/analytics-listeners": "^8.0.0",
26
- "@atlaskit/editor-common": "^61.0.0",
27
- "@atlaskit/util-service-support": "^6.0.0",
25
+ "@atlaskit/analytics-listeners": "^8.2.0",
26
+ "@atlaskit/editor-common": "^64.0.0",
27
+ "@atlaskit/editor-json-transformer": "^8.7.0",
28
+ "@atlaskit/util-service-support": "^6.1.0",
28
29
  "@babel/runtime": "^7.0.0",
29
30
  "eventemitter2": "^4.1.0",
30
- "lodash": "^4.17.15",
31
+ "lodash": "^4.17.21",
31
32
  "prosemirror-collab": "^1.2.2",
32
33
  "prosemirror-state": "1.3.4",
33
34
  "prosemirror-transform": "1.3.2",
@@ -43,7 +44,7 @@
43
44
  }
44
45
  },
45
46
  "devDependencies": {
46
- "@atlaskit/editor-test-helpers": "^15.6.0",
47
+ "@atlaskit/editor-test-helpers": "^16.1.0",
47
48
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
48
49
  "@types/prosemirror-collab": "^1.1.1",
49
50
  "@types/prosemirror-model": "^1.11.0",
@@ -52,4 +53,4 @@
52
53
  "typescript": "3.9.6"
53
54
  },
54
55
  "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1"
55
- }
56
+ }