@atlaskit/editor-plugin-collab-edit 3.7.2 → 3.8.0

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-collab-edit
2
2
 
3
+ ## 3.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#154562](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/154562)
8
+ [`9a3495cb72638`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9a3495cb72638) -
9
+ Support AnalyticsStep filtering for collab
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 3.7.2
4
16
 
5
17
  ### Patch Changes
@@ -201,14 +201,22 @@ var collabEditPlugin = exports.collabEditPlugin = function collabEditPlugin(_ref
201
201
  useNativePlugin = _ref5$useNativePlugin === void 0 ? false : _ref5$useNativePlugin,
202
202
  _ref5$userId = _ref5.userId,
203
203
  userId = _ref5$userId === void 0 ? null : _ref5$userId;
204
+ var transformUnconfirmed = function transformUnconfirmed(steps) {
205
+ var transformed = steps;
206
+ if ((0, _experiments.editorExperiment)('platform_editor_reduce_noisy_steps_ncs', true)) {
207
+ transformed = (0, _mergeUnconfirmed.filterAnalyticsSteps)(transformed);
208
+ }
209
+ if ((0, _experiments.editorExperiment)('platform_editor_offline_editing_web', true)) {
210
+ transformed = (0, _mergeUnconfirmed.mergeUnconfirmedSteps)(transformed, api);
211
+ }
212
+ return transformed;
213
+ };
204
214
  var plugins = [].concat((0, _toConsumableArray2.default)(useNativePlugin ? [{
205
215
  name: 'pmCollab',
206
216
  plugin: function plugin() {
207
217
  return (0, _prosemirrorCollab.collab)({
208
218
  clientID: userId,
209
- transformUnconfirmed: (0, _experiments.editorExperiment)('platform_editor_offline_editing_web', true) ? function (steps) {
210
- return (0, _mergeUnconfirmed.mergeUnconfirmedSteps)(steps, api);
211
- } : undefined
219
+ transformUnconfirmed: transformUnconfirmed
212
220
  });
213
221
  }
214
222
  }, {
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.sendTransaction = void 0;
7
+ var _steps = require("@atlaskit/adf-schema/steps");
7
8
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
8
10
  var _actions = require("../actions");
9
11
  var _pluginKey = require("../main/plugin-key");
10
12
  var sendTransaction = exports.sendTransaction = function sendTransaction(_ref) {
@@ -20,15 +22,23 @@ var sendTransaction = exports.sendTransaction = function sendTransaction(_ref) {
20
22
  return tr.docChanged;
21
23
  });
22
24
  var currentPluginState = _pluginKey.pluginKey.getState(newEditorState);
25
+ var tr = oldEditorState.tr;
26
+ var trNoAnalytics = docChangedTransaction === null || docChangedTransaction === void 0 ? void 0 : docChangedTransaction.steps.reduce(function (nextTr, step) {
27
+ if (!(step instanceof _steps.AnalyticsStep)) {
28
+ return nextTr.step(step);
29
+ }
30
+ return nextTr;
31
+ }, tr);
23
32
  if (!(currentPluginState !== null && currentPluginState !== void 0 && currentPluginState.isReady)) {
24
33
  return;
25
34
  }
35
+ var newTransaction = (0, _experiments.editorExperiment)('platform_editor_reduce_noisy_steps_ncs', true) ? trNoAnalytics : docChangedTransaction;
26
36
  var shouldSendStepForSynchronyCollabProvider = !originalTransaction.getMeta('isRemote') &&
27
37
  // TODO: ED-8995 - We need to do this check to reduce the number of race conditions when working with tables.
28
38
  // This metadata is coming from the scaleTable command in table-resizing plugin
29
- !originalTransaction.getMeta('scaleTable') && docChangedTransaction;
39
+ !originalTransaction.getMeta('scaleTable') && ((0, _experiments.editorExperiment)('platform_editor_reduce_noisy_steps_ncs', true) ? newTransaction === null || newTransaction === void 0 ? void 0 : newTransaction.docChanged : true);
30
40
  if (useNativePlugin || shouldSendStepForSynchronyCollabProvider) {
31
- provider.send(docChangedTransaction, oldEditorState, newEditorState);
41
+ provider.send(newTransaction, oldEditorState, newEditorState);
32
42
  }
33
43
  var prevPluginState = _pluginKey.pluginKey.getState(oldEditorState);
34
44
  var _ref2 = prevPluginState || {},
@@ -4,12 +4,15 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.LockableRebaseable = void 0;
8
+ exports.filterAnalyticsSteps = filterAnalyticsSteps;
7
9
  exports.mergeUnconfirmedSteps = mergeUnconfirmedSteps;
8
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
9
11
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
+ var _steps = require("@atlaskit/adf-schema/steps");
10
13
  var _state = require("@atlaskit/editor-prosemirror/state");
11
14
  // Based on: `packages/editor/prosemirror-collab/src/index.ts`
12
- var LockableRebaseable = /*#__PURE__*/(0, _createClass2.default)(function LockableRebaseable(step, inverted, origin) {
15
+ var LockableRebaseable = exports.LockableRebaseable = /*#__PURE__*/(0, _createClass2.default)(function LockableRebaseable(step, inverted, origin) {
13
16
  (0, _classCallCheck2.default)(this, LockableRebaseable);
14
17
  this.step = step;
15
18
  this.inverted = inverted;
@@ -53,4 +56,21 @@ function mergeUnconfirmedSteps(steps, api) {
53
56
  return acc.concat(new LockableRebaseable(rebaseable.step, rebaseable.inverted, rebaseable.origin instanceof _state.Transaction ? rebaseable.origin.setMeta('isOffline', rebaseable.origin.getMeta('isOffline') === true || isOffline) : rebaseable.origin));
54
57
  }, []);
55
58
  return mergedSteps;
59
+ }
60
+
61
+ /**
62
+ * Filter out AnalyticsStep from the steps.
63
+ *
64
+ * @param steps Rebaseable steps
65
+ * @returns Rebaseable steps
66
+ * @example
67
+ */
68
+ function filterAnalyticsSteps(steps) {
69
+ var filteredSteps = steps.reduce(function (acc, rebaseable) {
70
+ if (rebaseable.step instanceof _steps.AnalyticsStep) {
71
+ return acc;
72
+ }
73
+ return acc.concat(new LockableRebaseable(rebaseable.step, rebaseable.inverted, rebaseable.origin));
74
+ }, []);
75
+ return filteredSteps;
56
76
  }
@@ -8,7 +8,7 @@ import { addSynchronyErrorAnalytics } from './pm-plugins/analytics';
8
8
  import { sendTransaction } from './pm-plugins/events/send-transaction';
9
9
  import { createPlugin } from './pm-plugins/main';
10
10
  import { pluginKey as mainPluginKey } from './pm-plugins/main/plugin-key';
11
- import { mergeUnconfirmedSteps } from './pm-plugins/mergeUnconfirmed';
11
+ import { filterAnalyticsSteps, mergeUnconfirmedSteps } from './pm-plugins/mergeUnconfirmed';
12
12
  import { nativeCollabProviderPlugin } from './pm-plugins/native-collab-provider-plugin';
13
13
  import { sanitizeFilteredStep, createPlugin as trackSpammingStepsPlugin } from './pm-plugins/track-and-filter-spamming-steps';
14
14
  import { createPlugin as createLastOrganicChangePlugin, trackLastOrganicChangePluginKey } from './pm-plugins/track-last-organic-change';
@@ -156,11 +156,21 @@ export const collabEditPlugin = ({
156
156
  useNativePlugin = false,
157
157
  userId = null
158
158
  } = options || {};
159
+ const transformUnconfirmed = steps => {
160
+ let transformed = steps;
161
+ if (editorExperiment('platform_editor_reduce_noisy_steps_ncs', true)) {
162
+ transformed = filterAnalyticsSteps(transformed);
163
+ }
164
+ if (editorExperiment('platform_editor_offline_editing_web', true)) {
165
+ transformed = mergeUnconfirmedSteps(transformed, api);
166
+ }
167
+ return transformed;
168
+ };
159
169
  const plugins = [...(useNativePlugin ? [{
160
170
  name: 'pmCollab',
161
171
  plugin: () => collab({
162
172
  clientID: userId,
163
- transformUnconfirmed: editorExperiment('platform_editor_offline_editing_web', true) ? steps => mergeUnconfirmedSteps(steps, api) : undefined
173
+ transformUnconfirmed
164
174
  })
165
175
  }, {
166
176
  name: 'nativeCollabProviderPlugin',
@@ -1,4 +1,6 @@
1
+ import { AnalyticsStep } from '@atlaskit/adf-schema/steps';
1
2
  import { fg } from '@atlaskit/platform-feature-flags';
3
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
2
4
  import { getSendableSelection } from '../actions';
3
5
  import { pluginKey } from '../main/plugin-key';
4
6
  export const sendTransaction = ({
@@ -12,15 +14,23 @@ export const sendTransaction = ({
12
14
  }) => provider => {
13
15
  const docChangedTransaction = transactions.find(tr => tr.docChanged);
14
16
  const currentPluginState = pluginKey.getState(newEditorState);
17
+ const tr = oldEditorState.tr;
18
+ const trNoAnalytics = docChangedTransaction === null || docChangedTransaction === void 0 ? void 0 : docChangedTransaction.steps.reduce((nextTr, step) => {
19
+ if (!(step instanceof AnalyticsStep)) {
20
+ return nextTr.step(step);
21
+ }
22
+ return nextTr;
23
+ }, tr);
15
24
  if (!(currentPluginState !== null && currentPluginState !== void 0 && currentPluginState.isReady)) {
16
25
  return;
17
26
  }
27
+ const newTransaction = editorExperiment('platform_editor_reduce_noisy_steps_ncs', true) ? trNoAnalytics : docChangedTransaction;
18
28
  const shouldSendStepForSynchronyCollabProvider = !originalTransaction.getMeta('isRemote') &&
19
29
  // TODO: ED-8995 - We need to do this check to reduce the number of race conditions when working with tables.
20
30
  // This metadata is coming from the scaleTable command in table-resizing plugin
21
- !originalTransaction.getMeta('scaleTable') && docChangedTransaction;
31
+ !originalTransaction.getMeta('scaleTable') && (editorExperiment('platform_editor_reduce_noisy_steps_ncs', true) ? newTransaction === null || newTransaction === void 0 ? void 0 : newTransaction.docChanged : true);
22
32
  if (useNativePlugin || shouldSendStepForSynchronyCollabProvider) {
23
- provider.send(docChangedTransaction, oldEditorState, newEditorState);
33
+ provider.send(newTransaction, oldEditorState, newEditorState);
24
34
  }
25
35
  const prevPluginState = pluginKey.getState(oldEditorState);
26
36
  const {
@@ -1,6 +1,7 @@
1
+ import { AnalyticsStep } from '@atlaskit/adf-schema/steps';
1
2
  import { Transaction } from '@atlaskit/editor-prosemirror/state';
2
3
  // Based on: `packages/editor/prosemirror-collab/src/index.ts`
3
- class LockableRebaseable {
4
+ export class LockableRebaseable {
4
5
  constructor(step, inverted, origin) {
5
6
  this.step = step;
6
7
  this.inverted = inverted;
@@ -45,4 +46,21 @@ export function mergeUnconfirmedSteps(steps, api) {
45
46
  return acc.concat(new LockableRebaseable(rebaseable.step, rebaseable.inverted, rebaseable.origin instanceof Transaction ? rebaseable.origin.setMeta('isOffline', rebaseable.origin.getMeta('isOffline') === true || isOffline) : rebaseable.origin));
46
47
  }, []);
47
48
  return mergedSteps;
49
+ }
50
+
51
+ /**
52
+ * Filter out AnalyticsStep from the steps.
53
+ *
54
+ * @param steps Rebaseable steps
55
+ * @returns Rebaseable steps
56
+ * @example
57
+ */
58
+ export function filterAnalyticsSteps(steps) {
59
+ const filteredSteps = steps.reduce((acc, rebaseable) => {
60
+ if (rebaseable.step instanceof AnalyticsStep) {
61
+ return acc;
62
+ }
63
+ return acc.concat(new LockableRebaseable(rebaseable.step, rebaseable.inverted, rebaseable.origin));
64
+ }, []);
65
+ return filteredSteps;
48
66
  }
@@ -14,7 +14,7 @@ import { addSynchronyErrorAnalytics } from './pm-plugins/analytics';
14
14
  import { sendTransaction } from './pm-plugins/events/send-transaction';
15
15
  import { createPlugin } from './pm-plugins/main';
16
16
  import { pluginKey as mainPluginKey } from './pm-plugins/main/plugin-key';
17
- import { mergeUnconfirmedSteps } from './pm-plugins/mergeUnconfirmed';
17
+ import { filterAnalyticsSteps, mergeUnconfirmedSteps } from './pm-plugins/mergeUnconfirmed';
18
18
  import { nativeCollabProviderPlugin } from './pm-plugins/native-collab-provider-plugin';
19
19
  import { sanitizeFilteredStep, createPlugin as trackSpammingStepsPlugin } from './pm-plugins/track-and-filter-spamming-steps';
20
20
  import { createPlugin as createLastOrganicChangePlugin, trackLastOrganicChangePluginKey } from './pm-plugins/track-last-organic-change';
@@ -194,14 +194,22 @@ export var collabEditPlugin = function collabEditPlugin(_ref4) {
194
194
  useNativePlugin = _ref5$useNativePlugin === void 0 ? false : _ref5$useNativePlugin,
195
195
  _ref5$userId = _ref5.userId,
196
196
  userId = _ref5$userId === void 0 ? null : _ref5$userId;
197
+ var transformUnconfirmed = function transformUnconfirmed(steps) {
198
+ var transformed = steps;
199
+ if (editorExperiment('platform_editor_reduce_noisy_steps_ncs', true)) {
200
+ transformed = filterAnalyticsSteps(transformed);
201
+ }
202
+ if (editorExperiment('platform_editor_offline_editing_web', true)) {
203
+ transformed = mergeUnconfirmedSteps(transformed, api);
204
+ }
205
+ return transformed;
206
+ };
197
207
  var plugins = [].concat(_toConsumableArray(useNativePlugin ? [{
198
208
  name: 'pmCollab',
199
209
  plugin: function plugin() {
200
210
  return collab({
201
211
  clientID: userId,
202
- transformUnconfirmed: editorExperiment('platform_editor_offline_editing_web', true) ? function (steps) {
203
- return mergeUnconfirmedSteps(steps, api);
204
- } : undefined
212
+ transformUnconfirmed: transformUnconfirmed
205
213
  });
206
214
  }
207
215
  }, {
@@ -1,4 +1,6 @@
1
+ import { AnalyticsStep } from '@atlaskit/adf-schema/steps';
1
2
  import { fg } from '@atlaskit/platform-feature-flags';
3
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
2
4
  import { getSendableSelection } from '../actions';
3
5
  import { pluginKey } from '../main/plugin-key';
4
6
  export var sendTransaction = function sendTransaction(_ref) {
@@ -14,15 +16,23 @@ export var sendTransaction = function sendTransaction(_ref) {
14
16
  return tr.docChanged;
15
17
  });
16
18
  var currentPluginState = pluginKey.getState(newEditorState);
19
+ var tr = oldEditorState.tr;
20
+ var trNoAnalytics = docChangedTransaction === null || docChangedTransaction === void 0 ? void 0 : docChangedTransaction.steps.reduce(function (nextTr, step) {
21
+ if (!(step instanceof AnalyticsStep)) {
22
+ return nextTr.step(step);
23
+ }
24
+ return nextTr;
25
+ }, tr);
17
26
  if (!(currentPluginState !== null && currentPluginState !== void 0 && currentPluginState.isReady)) {
18
27
  return;
19
28
  }
29
+ var newTransaction = editorExperiment('platform_editor_reduce_noisy_steps_ncs', true) ? trNoAnalytics : docChangedTransaction;
20
30
  var shouldSendStepForSynchronyCollabProvider = !originalTransaction.getMeta('isRemote') &&
21
31
  // TODO: ED-8995 - We need to do this check to reduce the number of race conditions when working with tables.
22
32
  // This metadata is coming from the scaleTable command in table-resizing plugin
23
- !originalTransaction.getMeta('scaleTable') && docChangedTransaction;
33
+ !originalTransaction.getMeta('scaleTable') && (editorExperiment('platform_editor_reduce_noisy_steps_ncs', true) ? newTransaction === null || newTransaction === void 0 ? void 0 : newTransaction.docChanged : true);
24
34
  if (useNativePlugin || shouldSendStepForSynchronyCollabProvider) {
25
- provider.send(docChangedTransaction, oldEditorState, newEditorState);
35
+ provider.send(newTransaction, oldEditorState, newEditorState);
26
36
  }
27
37
  var prevPluginState = pluginKey.getState(oldEditorState);
28
38
  var _ref2 = prevPluginState || {},
@@ -1,8 +1,9 @@
1
1
  import _createClass from "@babel/runtime/helpers/createClass";
2
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import { AnalyticsStep } from '@atlaskit/adf-schema/steps';
3
4
  import { Transaction } from '@atlaskit/editor-prosemirror/state';
4
5
  // Based on: `packages/editor/prosemirror-collab/src/index.ts`
5
- var LockableRebaseable = /*#__PURE__*/_createClass(function LockableRebaseable(step, inverted, origin) {
6
+ export var LockableRebaseable = /*#__PURE__*/_createClass(function LockableRebaseable(step, inverted, origin) {
6
7
  _classCallCheck(this, LockableRebaseable);
7
8
  this.step = step;
8
9
  this.inverted = inverted;
@@ -46,4 +47,21 @@ export function mergeUnconfirmedSteps(steps, api) {
46
47
  return acc.concat(new LockableRebaseable(rebaseable.step, rebaseable.inverted, rebaseable.origin instanceof Transaction ? rebaseable.origin.setMeta('isOffline', rebaseable.origin.getMeta('isOffline') === true || isOffline) : rebaseable.origin));
47
48
  }, []);
48
49
  return mergedSteps;
50
+ }
51
+
52
+ /**
53
+ * Filter out AnalyticsStep from the steps.
54
+ *
55
+ * @param steps Rebaseable steps
56
+ * @returns Rebaseable steps
57
+ * @example
58
+ */
59
+ export function filterAnalyticsSteps(steps) {
60
+ var filteredSteps = steps.reduce(function (acc, rebaseable) {
61
+ if (rebaseable.step instanceof AnalyticsStep) {
62
+ return acc;
63
+ }
64
+ return acc.concat(new LockableRebaseable(rebaseable.step, rebaseable.inverted, rebaseable.origin));
65
+ }, []);
66
+ return filteredSteps;
49
67
  }
@@ -2,7 +2,7 @@ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
2
  import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
3
3
  import type { Transform as ProseMirrorTransform } from '@atlaskit/editor-prosemirror/transform';
4
4
  import type { CollabEditPlugin } from '../collabEditPluginType';
5
- declare class LockableRebaseable {
5
+ export declare class LockableRebaseable {
6
6
  readonly step: ProseMirrorStep;
7
7
  readonly inverted: ProseMirrorStep;
8
8
  readonly origin: ProseMirrorTransform;
@@ -19,4 +19,11 @@ declare class LockableRebaseable {
19
19
  * @returns Rebaseable steps
20
20
  */
21
21
  export declare function mergeUnconfirmedSteps(steps: LockableRebaseable[], api: ExtractInjectionAPI<CollabEditPlugin> | undefined): LockableRebaseable[];
22
- export {};
22
+ /**
23
+ * Filter out AnalyticsStep from the steps.
24
+ *
25
+ * @param steps Rebaseable steps
26
+ * @returns Rebaseable steps
27
+ * @example
28
+ */
29
+ export declare function filterAnalyticsSteps(steps: LockableRebaseable[]): LockableRebaseable[];
@@ -2,7 +2,7 @@ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
2
  import { Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
3
3
  import type { Transform as ProseMirrorTransform } from '@atlaskit/editor-prosemirror/transform';
4
4
  import type { CollabEditPlugin } from '../collabEditPluginType';
5
- declare class LockableRebaseable {
5
+ export declare class LockableRebaseable {
6
6
  readonly step: ProseMirrorStep;
7
7
  readonly inverted: ProseMirrorStep;
8
8
  readonly origin: ProseMirrorTransform;
@@ -19,4 +19,11 @@ declare class LockableRebaseable {
19
19
  * @returns Rebaseable steps
20
20
  */
21
21
  export declare function mergeUnconfirmedSteps(steps: LockableRebaseable[], api: ExtractInjectionAPI<CollabEditPlugin> | undefined): LockableRebaseable[];
22
- export {};
22
+ /**
23
+ * Filter out AnalyticsStep from the steps.
24
+ *
25
+ * @param steps Rebaseable steps
26
+ * @returns Rebaseable steps
27
+ * @example
28
+ */
29
+ export declare function filterAnalyticsSteps(steps: LockableRebaseable[]): LockableRebaseable[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-collab-edit",
3
- "version": "3.7.2",
3
+ "version": "3.8.0",
4
4
  "description": "Collab Edit plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -42,8 +42,8 @@
42
42
  "@atlaskit/editor-prosemirror": "7.0.0",
43
43
  "@atlaskit/editor-shared-styles": "^3.4.0",
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
- "@atlaskit/prosemirror-collab": "^0.16.0",
46
- "@atlaskit/tmp-editor-statsig": "^5.2.0",
45
+ "@atlaskit/prosemirror-collab": "^0.17.0",
46
+ "@atlaskit/tmp-editor-statsig": "^5.5.0",
47
47
  "@babel/runtime": "^7.0.0",
48
48
  "memoize-one": "^6.0.0"
49
49
  },