@atlaskit/editor-plugin-collab-edit 2.0.0 → 2.0.2
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 +16 -0
- package/dist/cjs/collabEditPlugin.js +21 -2
- package/dist/cjs/pm-plugins/actions.js +14 -2
- package/dist/cjs/pm-plugins/analytics.js +6 -1
- package/dist/cjs/pm-plugins/events/handlers.js +12 -1
- package/dist/cjs/pm-plugins/events/initialize.js +4 -1
- package/dist/cjs/pm-plugins/main/index.js +13 -1
- package/dist/cjs/pm-plugins/main/plugin-state.js +11 -0
- package/dist/cjs/pm-plugins/mergeUnconfirmed.js +85 -0
- package/dist/cjs/pm-plugins/utils.js +38 -8
- package/dist/es2019/collabEditPlugin.js +20 -2
- package/dist/es2019/pm-plugins/actions.js +12 -2
- package/dist/es2019/pm-plugins/analytics.js +6 -1
- package/dist/es2019/pm-plugins/events/handlers.js +13 -1
- package/dist/es2019/pm-plugins/events/initialize.js +4 -1
- package/dist/es2019/pm-plugins/main/index.js +13 -1
- package/dist/es2019/pm-plugins/main/plugin-state.js +14 -0
- package/dist/es2019/pm-plugins/mergeUnconfirmed.js +66 -0
- package/dist/es2019/pm-plugins/utils.js +39 -10
- package/dist/esm/collabEditPlugin.js +21 -2
- package/dist/esm/pm-plugins/actions.js +12 -2
- package/dist/esm/pm-plugins/analytics.js +6 -1
- package/dist/esm/pm-plugins/events/handlers.js +13 -1
- package/dist/esm/pm-plugins/events/initialize.js +4 -1
- package/dist/esm/pm-plugins/main/index.js +13 -1
- package/dist/esm/pm-plugins/main/plugin-state.js +11 -0
- package/dist/esm/pm-plugins/mergeUnconfirmed.js +78 -0
- package/dist/esm/pm-plugins/utils.js +39 -10
- package/dist/types/pm-plugins/mergeUnconfirmed.d.ts +24 -0
- package/dist/types-ts4.5/pm-plugins/mergeUnconfirmed.d.ts +24 -0
- package/package.json +7 -4
|
@@ -30,6 +30,9 @@ export class PluginState {
|
|
|
30
30
|
get sessionId() {
|
|
31
31
|
return this.sid;
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
// Ignored via go/ees005
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
33
36
|
constructor(decorations, participants, sessionId, collabInitalised = false, onError) {
|
|
34
37
|
// eslint-disable-next-line no-console
|
|
35
38
|
_defineProperty(this, "onError", error => console.error(error));
|
|
@@ -128,6 +131,8 @@ export class PluginState {
|
|
|
128
131
|
}
|
|
129
132
|
},
|
|
130
133
|
from
|
|
134
|
+
// Ignored via go/ees005
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
131
136
|
} = step;
|
|
132
137
|
const pos = getValidPos(tr, size ? Math.min(from + size, tr.doc.nodeSize - 3) : Math.max(from, 1));
|
|
133
138
|
add = add.concat(createTelepointers(pos, pos, sessionId, false, this.getInitial(sessionId)));
|
|
@@ -142,10 +147,14 @@ export class PluginState {
|
|
|
142
147
|
// Remove any selection decoration within the change range,
|
|
143
148
|
// takes care of the issue when after pasting we end up with a dead selection
|
|
144
149
|
tr.steps.filter(isReplaceStep).forEach(s => {
|
|
150
|
+
// Ignored via go/ees005
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
145
152
|
const {
|
|
146
153
|
from,
|
|
147
154
|
to
|
|
148
155
|
} = s;
|
|
156
|
+
// Ignored via go/ees005
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
149
158
|
this.decorationSet.find(from, to).forEach(deco => {
|
|
150
159
|
// `type` is private, `from` and `to` are public in latest version
|
|
151
160
|
// `from` != `to` means it's a selection
|
|
@@ -158,6 +167,8 @@ export class PluginState {
|
|
|
158
167
|
const {
|
|
159
168
|
selection
|
|
160
169
|
} = tr;
|
|
170
|
+
// Ignored via go/ees005
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
161
172
|
this.decorationSet.find().forEach(deco => {
|
|
162
173
|
if (deco.type.toDOM) {
|
|
163
174
|
const hasTelepointerDimClass = deco.type.toDOM.classList.contains(TELEPOINTER_DIM_CLASS);
|
|
@@ -206,6 +217,9 @@ export class PluginState {
|
|
|
206
217
|
static eq(a, b) {
|
|
207
218
|
return a.participants === b.participants && a.sessionId === b.sessionId && a.isReady === b.isReady;
|
|
208
219
|
}
|
|
220
|
+
|
|
221
|
+
// Ignored via go/ees005
|
|
222
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
209
223
|
static init(config) {
|
|
210
224
|
const {
|
|
211
225
|
doc,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
|
|
2
|
+
function isLockable(step) {
|
|
3
|
+
return (step === null || step === void 0 ? void 0 : step.lockStep) !== undefined;
|
|
4
|
+
}
|
|
5
|
+
const createLockableProseMirrorStep = step => {
|
|
6
|
+
let stepIsLocked = false;
|
|
7
|
+
if (isLockable(step)) {
|
|
8
|
+
return step;
|
|
9
|
+
}
|
|
10
|
+
return new Proxy(step, {
|
|
11
|
+
get(target, prop, receiver) {
|
|
12
|
+
if (prop === 'lockStep') {
|
|
13
|
+
return () => {
|
|
14
|
+
stepIsLocked = true;
|
|
15
|
+
};
|
|
16
|
+
} else if (prop === 'isLocked') {
|
|
17
|
+
return () => {
|
|
18
|
+
return stepIsLocked;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return Reflect.get(target, prop, receiver);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Based on: `packages/editor/prosemirror-collab/src/index.ts`
|
|
27
|
+
class LockableRebaseable {
|
|
28
|
+
constructor(step, inverted, origin) {
|
|
29
|
+
this.step = step;
|
|
30
|
+
this.inverted = inverted;
|
|
31
|
+
this.origin = origin;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class LockableProseMirrorStep extends ProseMirrorStep {}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Merge a set of steps together to reduce the total number of steps stored in memory.
|
|
38
|
+
*
|
|
39
|
+
* All steps passing through here should be "lockable" (ie. can be locked by the document service)
|
|
40
|
+
* so that it can be indicated they have already been sent (or are about to be sent) to the backend
|
|
41
|
+
* and cannot be merged.
|
|
42
|
+
*
|
|
43
|
+
* @param steps Rebaseable steps
|
|
44
|
+
* @returns Rebaseable steps
|
|
45
|
+
*/
|
|
46
|
+
export function mergeUnconfirmedSteps(steps) {
|
|
47
|
+
const mergedSteps = steps.reduce((acc, rebaseable) => {
|
|
48
|
+
var _lastStep$step$isLock, _lastStep$step, _rebaseable$step$isLo, _rebaseable$step;
|
|
49
|
+
const lastStep = acc[acc.length - 1];
|
|
50
|
+
if (lastStep && ((_lastStep$step$isLock = (_lastStep$step = lastStep.step).isLocked) === null || _lastStep$step$isLock === void 0 ? void 0 : _lastStep$step$isLock.call(_lastStep$step)) !== true && ((_rebaseable$step$isLo = (_rebaseable$step = rebaseable.step).isLocked) === null || _rebaseable$step$isLo === void 0 ? void 0 : _rebaseable$step$isLo.call(_rebaseable$step)) !== true) {
|
|
51
|
+
const mergedStep = lastStep.step.merge(rebaseable.step);
|
|
52
|
+
const inverted = rebaseable.inverted.merge(lastStep.inverted);
|
|
53
|
+
// Always take the origin of the new step.
|
|
54
|
+
// We use this in packages/editor/collab-provider/src/document/document-service.ts:commitUnconfirmedSteps
|
|
55
|
+
// to confirm that the last transaction has been sent. Since we're taking the latest this still works as expected
|
|
56
|
+
// As we want to wait until all the transactions have been pushed through
|
|
57
|
+
const origin = lastStep.origin;
|
|
58
|
+
if (mergedStep && inverted) {
|
|
59
|
+
acc[acc.length - 1] = new LockableRebaseable(createLockableProseMirrorStep(mergedStep), inverted, origin);
|
|
60
|
+
return acc;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return acc.concat(new LockableRebaseable(createLockableProseMirrorStep(rebaseable.step), rebaseable.inverted, rebaseable.origin));
|
|
64
|
+
}, []);
|
|
65
|
+
return mergedSteps;
|
|
66
|
+
}
|
|
@@ -2,13 +2,15 @@ import { AnalyticsStep, SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
|
2
2
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { processRawValueWithoutValidation } from '@atlaskit/editor-common/process-raw-value';
|
|
4
4
|
import { ZERO_WIDTH_JOINER } from '@atlaskit/editor-common/whitespace';
|
|
5
|
-
import { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
-
import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { Transaction, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
6
|
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
8
7
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
9
8
|
import { avatarColors } from '@atlaskit/editor-shared-styles/consts';
|
|
10
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
|
-
export const findPointers = (id, decorations) => decorations.find()
|
|
10
|
+
export const findPointers = (id, decorations) => decorations.find()
|
|
11
|
+
// Ignored via go/ees005
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
.reduce((arr, deco) => deco.spec.pointer.sessionId === id ? arr.concat(deco) : arr, []);
|
|
12
14
|
function style(options) {
|
|
13
15
|
const color = options && options.color || 'black';
|
|
14
16
|
return `border-right: 2px solid ${color}; margin-right: -2px;`;
|
|
@@ -27,13 +29,19 @@ export function getAvatarColor(str) {
|
|
|
27
29
|
color: avatarColors[index]
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
|
-
export const createTelepointers = (from, to, sessionId, isSelection, initial
|
|
32
|
+
export const createTelepointers = (from, to, sessionId, isSelection, initial
|
|
33
|
+
// Ignored via go/ees005
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
35
|
+
) => {
|
|
31
36
|
let decorations = [];
|
|
32
37
|
const avatarColor = getAvatarColor(sessionId);
|
|
33
38
|
const color = avatarColor.index.toString();
|
|
34
39
|
if (isSelection) {
|
|
35
40
|
const className = `telepointer color-${color} telepointer-selection`;
|
|
36
|
-
decorations.push(
|
|
41
|
+
decorations.push(
|
|
42
|
+
// Ignored via go/ees005
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
Decoration.inline(from, to, {
|
|
37
45
|
class: className,
|
|
38
46
|
'data-initial': initial
|
|
39
47
|
}, {
|
|
@@ -53,24 +61,36 @@ export const createTelepointers = (from, to, sessionId, isSelection, initial) =>
|
|
|
53
61
|
color: avatarColor.color
|
|
54
62
|
})};`;
|
|
55
63
|
cursor.setAttribute('data-initial', initial);
|
|
56
|
-
return decorations.concat(
|
|
64
|
+
return decorations.concat(
|
|
65
|
+
// Ignored via go/ees005
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
Decoration.widget(to, spaceJoinerAfter, {
|
|
57
68
|
pointer: {
|
|
58
69
|
sessionId
|
|
59
70
|
},
|
|
60
71
|
key: `telepointer-${sessionId}-zero`
|
|
61
|
-
})).concat(
|
|
72
|
+
})).concat(
|
|
73
|
+
// Ignored via go/ees005
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
Decoration.widget(to, cursor, {
|
|
62
76
|
pointer: {
|
|
63
77
|
sessionId
|
|
64
78
|
},
|
|
65
79
|
key: `telepointer-${sessionId}`
|
|
66
|
-
})).concat(
|
|
80
|
+
})).concat(
|
|
81
|
+
// Ignored via go/ees005
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
Decoration.widget(to, spaceJoinerBefore, {
|
|
67
84
|
pointer: {
|
|
68
85
|
sessionId
|
|
69
86
|
},
|
|
70
87
|
key: `telepointer-${sessionId}-zero`
|
|
71
88
|
}));
|
|
72
89
|
};
|
|
73
|
-
export const replaceDocument = (doc, state, version, options, reserveCursor, editorAnalyticsAPI
|
|
90
|
+
export const replaceDocument = (doc, state, version, options, reserveCursor, editorAnalyticsAPI
|
|
91
|
+
// Ignored via go/ees005
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
93
|
+
) => {
|
|
74
94
|
const {
|
|
75
95
|
schema,
|
|
76
96
|
tr
|
|
@@ -82,11 +102,15 @@ export const replaceDocument = (doc, state, version, options, reserveCursor, edi
|
|
|
82
102
|
hasContent = !!(parsedDoc !== null && parsedDoc !== void 0 && parsedDoc.childCount);
|
|
83
103
|
content = parsedDoc === null || parsedDoc === void 0 ? void 0 : parsedDoc.content;
|
|
84
104
|
} else {
|
|
105
|
+
// Ignored via go/ees005
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
107
|
content = (doc.content || []).map(child => schema.nodeFromJSON(child));
|
|
86
108
|
hasContent = Array.isArray(content) && !!content.length;
|
|
87
109
|
}
|
|
88
110
|
if (hasContent) {
|
|
89
111
|
tr.setMeta('addToHistory', false);
|
|
112
|
+
// Ignored via go/ees005
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
90
114
|
tr.replaceWith(0, state.doc.nodeSize - 2, content);
|
|
91
115
|
const selection = state.selection;
|
|
92
116
|
if (reserveCursor) {
|
|
@@ -112,7 +136,10 @@ export const replaceDocument = (doc, state, version, options, reserveCursor, edi
|
|
|
112
136
|
}
|
|
113
137
|
return tr;
|
|
114
138
|
};
|
|
115
|
-
export const scrollToCollabCursor = (editorView, participants, sessionId, index, editorAnalyticsAPI
|
|
139
|
+
export const scrollToCollabCursor = (editorView, participants, sessionId, index, editorAnalyticsAPI
|
|
140
|
+
// Ignored via go/ees005
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
142
|
+
) => {
|
|
116
143
|
const selectedUser = participants[index];
|
|
117
144
|
if (selectedUser && selectedUser.cursorPos !== undefined && selectedUser.sessionId !== sessionId) {
|
|
118
145
|
const {
|
|
@@ -135,6 +162,8 @@ export const scrollToCollabCursor = (editorView, participants, sessionId, index,
|
|
|
135
162
|
};
|
|
136
163
|
export const getPositionOfTelepointer = (sessionId, decorationSet) => {
|
|
137
164
|
let scrollPosition;
|
|
165
|
+
// Ignored via go/ees005
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
138
167
|
decorationSet.find().forEach(deco => {
|
|
139
168
|
if (deco.type.spec.pointer.sessionId === sessionId) {
|
|
140
169
|
scrollPosition = deco.from;
|
|
@@ -7,11 +7,13 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
7
7
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
8
8
|
import { JSONTransformer } from '@atlaskit/editor-json-transformer';
|
|
9
9
|
import { AddMarkStep, AddNodeMarkStep } from '@atlaskit/editor-prosemirror/transform';
|
|
10
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
11
|
import { collab, getCollabState, sendableSteps } from '@atlaskit/prosemirror-collab';
|
|
11
12
|
import { addSynchronyErrorAnalytics } from './pm-plugins/analytics';
|
|
12
13
|
import { sendTransaction } from './pm-plugins/events/send-transaction';
|
|
13
14
|
import { createPlugin } from './pm-plugins/main';
|
|
14
15
|
import { pluginKey as mainPluginKey } from './pm-plugins/main/plugin-key';
|
|
16
|
+
import { mergeUnconfirmedSteps } from './pm-plugins/mergeUnconfirmed';
|
|
15
17
|
import { nativeCollabProviderPlugin } from './pm-plugins/native-collab-provider-plugin';
|
|
16
18
|
import { sanitizeFilteredStep, createPlugin as trackSpammingStepsPlugin } from './pm-plugins/track-and-filter-spamming-steps';
|
|
17
19
|
import { createPlugin as createLastOrganicChangePlugin, trackLastOrganicChangePluginKey } from './pm-plugins/track-last-organic-change';
|
|
@@ -144,16 +146,32 @@ export var collabEditPlugin = function collabEditPlugin(_ref4) {
|
|
|
144
146
|
},
|
|
145
147
|
getCurrentCollabState: function getCurrentCollabState() {
|
|
146
148
|
var _getCollabState;
|
|
149
|
+
// Ignored via go/ees005
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
147
151
|
var adfDocument = new JSONTransformer().encode(editorViewRef.current.state.doc);
|
|
148
152
|
return {
|
|
149
153
|
content: adfDocument,
|
|
154
|
+
// Ignored via go/ees005
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
150
156
|
version: ((_getCollabState = getCollabState(editorViewRef.current.state)) === null || _getCollabState === void 0 ? void 0 : _getCollabState.version) || 0,
|
|
157
|
+
// Ignored via go/ees005
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
151
159
|
sendableSteps: sendableSteps(editorViewRef.current.state)
|
|
152
160
|
};
|
|
153
161
|
},
|
|
162
|
+
// Ignored via go/ees005
|
|
163
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
164
|
validatePMJSONDocument: function validatePMJSONDocument(doc) {
|
|
165
|
+
// Ignored via go/ees005
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
155
167
|
var content = (doc.content || []).map(function (child) {
|
|
156
|
-
return
|
|
168
|
+
return (
|
|
169
|
+
// Ignored via go/ees005
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
171
|
+
// Ignored via go/ees005
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
173
|
+
editorViewRef.current.state.schema.nodeFromJSON(child)
|
|
174
|
+
);
|
|
157
175
|
});
|
|
158
176
|
return content.every(function (node) {
|
|
159
177
|
try {
|
|
@@ -175,7 +193,8 @@ export var collabEditPlugin = function collabEditPlugin(_ref4) {
|
|
|
175
193
|
name: 'pmCollab',
|
|
176
194
|
plugin: function plugin() {
|
|
177
195
|
return collab({
|
|
178
|
-
clientID: userId
|
|
196
|
+
clientID: userId,
|
|
197
|
+
transformUnconfirmed: fg('platform_editor_merge_unconfirmed_steps') ? mergeUnconfirmedSteps : undefined
|
|
179
198
|
});
|
|
180
199
|
}
|
|
181
200
|
}, {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
// Ignored via go/ees005
|
|
2
|
+
// eslint-disable-next-line import/no-namespace
|
|
1
3
|
import * as allAdfSchemaSteps from '@atlaskit/adf-schema/steps';
|
|
4
|
+
// Ignored via go/ees005
|
|
5
|
+
// eslint-disable-next-line import/no-namespace
|
|
2
6
|
import * as allAtlaskitCustomSteps from '@atlaskit/custom-steps';
|
|
3
7
|
import { AllSelection, NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
8
|
import { Step } from '@atlaskit/editor-prosemirror/transform';
|
|
@@ -12,7 +16,10 @@ export var registerAllCustomSteps = function registerAllCustomSteps() {
|
|
|
12
16
|
Object.entries(allAtlaskitCustomSteps).forEach(function () {});
|
|
13
17
|
Object.entries(allAdfSchemaSteps).forEach(function () {});
|
|
14
18
|
};
|
|
15
|
-
export var handleInit = function handleInit(initData, view, options, editorAnalyticsApi
|
|
19
|
+
export var handleInit = function handleInit(initData, view, options, editorAnalyticsApi
|
|
20
|
+
// Ignored via go/ees005
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
22
|
+
) {
|
|
16
23
|
var doc = initData.doc,
|
|
17
24
|
json = initData.json,
|
|
18
25
|
version = initData.version,
|
|
@@ -67,7 +74,10 @@ export var applyRemoteData = function applyRemoteData(remoteData, view, options)
|
|
|
67
74
|
applyRemoteSteps(json, view, userIds, options);
|
|
68
75
|
}
|
|
69
76
|
};
|
|
70
|
-
export var applyRemoteSteps = function applyRemoteSteps(json, view, userIds, options
|
|
77
|
+
export var applyRemoteSteps = function applyRemoteSteps(json, view, userIds, options
|
|
78
|
+
// Ignored via go/ees005
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
80
|
+
) {
|
|
71
81
|
if (!json || !json.length) {
|
|
72
82
|
return;
|
|
73
83
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { getDocStructure } from '@atlaskit/editor-common/core-utils';
|
|
3
3
|
import { sniffUserBrowserExtensions } from '@atlaskit/editor-common/utils';
|
|
4
|
-
export var addSynchronyErrorAnalytics = function addSynchronyErrorAnalytics(state, tr, featureFlags, editorAnalyticsApi
|
|
4
|
+
export var addSynchronyErrorAnalytics = function addSynchronyErrorAnalytics(state, tr, featureFlags, editorAnalyticsApi
|
|
5
|
+
// Ignored via go/ees005
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
7
|
+
) {
|
|
5
8
|
return function (error) {
|
|
6
9
|
var browserExtensions = sniffUserBrowserExtensions({
|
|
7
10
|
extensions: ['grammarly']
|
|
@@ -16,6 +19,8 @@ export var addSynchronyErrorAnalytics = function addSynchronyErrorAnalytics(stat
|
|
|
16
19
|
}
|
|
17
20
|
};
|
|
18
21
|
if (featureFlags.synchronyErrorDocStructure) {
|
|
22
|
+
// Ignored via go/ees005
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
19
24
|
payload.attributes.docStructure = getDocStructure(state.doc, {
|
|
20
25
|
compact: true
|
|
21
26
|
});
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { applyRemoteData, handleActivityAck, handleActivityJoin, handleConnection, handleInit, handlePresence, handleTelePointer } from '../actions';
|
|
2
2
|
import { addSynchronyEntityAnalytics, addSynchronyErrorAnalytics } from '../analytics';
|
|
3
|
+
|
|
4
|
+
// Ignored via go/ees005
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
|
|
7
|
+
// Ignored via go/ees005
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
|
|
10
|
+
// Ignored via go/ees005
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
12
|
var effect = function effect(fn, eq) {
|
|
4
13
|
var previousDeps;
|
|
5
14
|
var cleanup;
|
|
@@ -15,7 +24,10 @@ var effect = function effect(fn, eq) {
|
|
|
15
24
|
return cleanup;
|
|
16
25
|
};
|
|
17
26
|
};
|
|
18
|
-
export var subscribe = effect(
|
|
27
|
+
export var subscribe = effect(
|
|
28
|
+
// Ignored via go/ees005
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
30
|
+
function (view, provider, options, featureFlags, _providerFactory, editorAnalyticsApi) {
|
|
19
31
|
var entityRef;
|
|
20
32
|
var entityHandlers = {
|
|
21
33
|
disconnectedHandler: function disconnectedHandler() {
|
|
@@ -11,7 +11,10 @@ var initCollab = function initCollab(collabEditProvider, view) {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
|
-
var initNewCollab = function initNewCollab(collabEditProvider, view, editorApi, onSyncUpError
|
|
14
|
+
var initNewCollab = function initNewCollab(collabEditProvider, view, editorApi, onSyncUpError
|
|
15
|
+
// Ignored via go/ees005
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
17
|
+
) {
|
|
15
18
|
collabEditProvider.setup({
|
|
16
19
|
getState: function getState() {
|
|
17
20
|
return view.state;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// It is important to get all steps in that package
|
|
2
|
+
|
|
3
|
+
// Ignored via go/ees005
|
|
4
|
+
// eslint-disable-next-line import/no-namespace
|
|
2
5
|
import * as adfCustomSteps from '@atlaskit/adf-schema/steps';
|
|
3
6
|
// It is important to get all steps in that package
|
|
7
|
+
// Ignored via go/ees005
|
|
8
|
+
// eslint-disable-next-line import/no-namespace
|
|
4
9
|
import * as atlaskKitCustomSteps from '@atlaskit/custom-steps';
|
|
5
10
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, fireAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
6
11
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
@@ -38,14 +43,21 @@ var enforceCustomStepRegisters = function enforceCustomStepRegisters() {
|
|
|
38
43
|
// @ts-expect-error
|
|
39
44
|
tryToRegisterStep(adfCustomSteps);
|
|
40
45
|
};
|
|
41
|
-
export var createPlugin = function createPlugin(dispatch, providerFactory, providerResolver, collabProviderCallback, options, featureFlags, pluginInjectionApi
|
|
46
|
+
export var createPlugin = function createPlugin(dispatch, providerFactory, providerResolver, collabProviderCallback, options, featureFlags, pluginInjectionApi
|
|
47
|
+
// Ignored via go/ees005
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
49
|
+
) {
|
|
42
50
|
enforceCustomStepRegisters();
|
|
43
51
|
return new SafePlugin({
|
|
44
52
|
key: pluginKey,
|
|
45
53
|
state: {
|
|
54
|
+
// Ignored via go/ees005
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
56
|
init: function init(config) {
|
|
47
57
|
return PluginState.init(config);
|
|
48
58
|
},
|
|
59
|
+
// Ignored via go/ees005
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
49
61
|
apply: function apply(transaction, prevPluginState, _oldEditorState, _newEditorState) {
|
|
50
62
|
var pluginState = prevPluginState.apply(transaction);
|
|
51
63
|
dispatch(pluginKey, pluginState);
|
|
@@ -23,6 +23,8 @@ export var getValidPos = function getValidPos(tr, pos) {
|
|
|
23
23
|
return endOfDocPos;
|
|
24
24
|
};
|
|
25
25
|
export var PluginState = /*#__PURE__*/function () {
|
|
26
|
+
// Ignored via go/ees005
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
26
28
|
function PluginState(decorations, participants, sessionId) {
|
|
27
29
|
var collabInitalised = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
28
30
|
var onError = arguments.length > 4 ? arguments[4] : undefined;
|
|
@@ -151,9 +153,13 @@ export var PluginState = /*#__PURE__*/function () {
|
|
|
151
153
|
// Remove any selection decoration within the change range,
|
|
152
154
|
// takes care of the issue when after pasting we end up with a dead selection
|
|
153
155
|
tr.steps.filter(isReplaceStep).forEach(function (s) {
|
|
156
|
+
// Ignored via go/ees005
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
158
|
var _ref2 = s,
|
|
155
159
|
from = _ref2.from,
|
|
156
160
|
to = _ref2.to;
|
|
161
|
+
// Ignored via go/ees005
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
163
|
_this.decorationSet.find(from, to).forEach(function (deco) {
|
|
158
164
|
// `type` is private, `from` and `to` are public in latest version
|
|
159
165
|
// `from` != `to` means it's a selection
|
|
@@ -164,6 +170,8 @@ export var PluginState = /*#__PURE__*/function () {
|
|
|
164
170
|
});
|
|
165
171
|
}
|
|
166
172
|
var selection = tr.selection;
|
|
173
|
+
// Ignored via go/ees005
|
|
174
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
167
175
|
this.decorationSet.find().forEach(function (deco) {
|
|
168
176
|
if (deco.type.toDOM) {
|
|
169
177
|
var hasTelepointerDimClass = deco.type.toDOM.classList.contains(TELEPOINTER_DIM_CLASS);
|
|
@@ -212,6 +220,9 @@ export var PluginState = /*#__PURE__*/function () {
|
|
|
212
220
|
value: function eq(a, b) {
|
|
213
221
|
return a.participants === b.participants && a.sessionId === b.sessionId && a.isReady === b.isReady;
|
|
214
222
|
}
|
|
223
|
+
|
|
224
|
+
// Ignored via go/ees005
|
|
225
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
215
226
|
}, {
|
|
216
227
|
key: "init",
|
|
217
228
|
value: function init(config) {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
2
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
6
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
7
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
8
|
+
import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
|
|
9
|
+
function isLockable(step) {
|
|
10
|
+
return (step === null || step === void 0 ? void 0 : step.lockStep) !== undefined;
|
|
11
|
+
}
|
|
12
|
+
var createLockableProseMirrorStep = function createLockableProseMirrorStep(step) {
|
|
13
|
+
var stepIsLocked = false;
|
|
14
|
+
if (isLockable(step)) {
|
|
15
|
+
return step;
|
|
16
|
+
}
|
|
17
|
+
return new Proxy(step, {
|
|
18
|
+
get: function get(target, prop, receiver) {
|
|
19
|
+
if (prop === 'lockStep') {
|
|
20
|
+
return function () {
|
|
21
|
+
stepIsLocked = true;
|
|
22
|
+
};
|
|
23
|
+
} else if (prop === 'isLocked') {
|
|
24
|
+
return function () {
|
|
25
|
+
return stepIsLocked;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return Reflect.get(target, prop, receiver);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Based on: `packages/editor/prosemirror-collab/src/index.ts`
|
|
34
|
+
var LockableRebaseable = /*#__PURE__*/_createClass(function LockableRebaseable(step, inverted, origin) {
|
|
35
|
+
_classCallCheck(this, LockableRebaseable);
|
|
36
|
+
this.step = step;
|
|
37
|
+
this.inverted = inverted;
|
|
38
|
+
this.origin = origin;
|
|
39
|
+
});
|
|
40
|
+
var LockableProseMirrorStep = /*#__PURE__*/function (_ProseMirrorStep) {
|
|
41
|
+
function LockableProseMirrorStep() {
|
|
42
|
+
_classCallCheck(this, LockableProseMirrorStep);
|
|
43
|
+
return _callSuper(this, LockableProseMirrorStep, arguments);
|
|
44
|
+
}
|
|
45
|
+
_inherits(LockableProseMirrorStep, _ProseMirrorStep);
|
|
46
|
+
return _createClass(LockableProseMirrorStep);
|
|
47
|
+
}(ProseMirrorStep);
|
|
48
|
+
/**
|
|
49
|
+
* Merge a set of steps together to reduce the total number of steps stored in memory.
|
|
50
|
+
*
|
|
51
|
+
* All steps passing through here should be "lockable" (ie. can be locked by the document service)
|
|
52
|
+
* so that it can be indicated they have already been sent (or are about to be sent) to the backend
|
|
53
|
+
* and cannot be merged.
|
|
54
|
+
*
|
|
55
|
+
* @param steps Rebaseable steps
|
|
56
|
+
* @returns Rebaseable steps
|
|
57
|
+
*/
|
|
58
|
+
export function mergeUnconfirmedSteps(steps) {
|
|
59
|
+
var mergedSteps = steps.reduce(function (acc, rebaseable) {
|
|
60
|
+
var _lastStep$step$isLock, _lastStep$step, _rebaseable$step$isLo, _rebaseable$step;
|
|
61
|
+
var lastStep = acc[acc.length - 1];
|
|
62
|
+
if (lastStep && ((_lastStep$step$isLock = (_lastStep$step = lastStep.step).isLocked) === null || _lastStep$step$isLock === void 0 ? void 0 : _lastStep$step$isLock.call(_lastStep$step)) !== true && ((_rebaseable$step$isLo = (_rebaseable$step = rebaseable.step).isLocked) === null || _rebaseable$step$isLo === void 0 ? void 0 : _rebaseable$step$isLo.call(_rebaseable$step)) !== true) {
|
|
63
|
+
var mergedStep = lastStep.step.merge(rebaseable.step);
|
|
64
|
+
var _inverted = rebaseable.inverted.merge(lastStep.inverted);
|
|
65
|
+
// Always take the origin of the new step.
|
|
66
|
+
// We use this in packages/editor/collab-provider/src/document/document-service.ts:commitUnconfirmedSteps
|
|
67
|
+
// to confirm that the last transaction has been sent. Since we're taking the latest this still works as expected
|
|
68
|
+
// As we want to wait until all the transactions have been pushed through
|
|
69
|
+
var _origin = lastStep.origin;
|
|
70
|
+
if (mergedStep && _inverted) {
|
|
71
|
+
acc[acc.length - 1] = new LockableRebaseable(createLockableProseMirrorStep(mergedStep), _inverted, _origin);
|
|
72
|
+
return acc;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return acc.concat(new LockableRebaseable(createLockableProseMirrorStep(rebaseable.step), rebaseable.inverted, rebaseable.origin));
|
|
76
|
+
}, []);
|
|
77
|
+
return mergedSteps;
|
|
78
|
+
}
|