@atlaskit/editor-plugin-synced-block 6.0.33 → 6.0.35

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,25 @@
1
1
  # @atlaskit/editor-plugin-synced-block
2
2
 
3
+ ## 6.0.35
4
+
5
+ ### Patch Changes
6
+
7
+ - [`827be3d512390`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/827be3d512390) -
8
+ Refactor source synced block cache update to use appendTransaction instead of nodeview update.
9
+ Behind fg('platform_synced_block_update_refactor'):
10
+ - Moves cache update from nodeview update() to PM plugin appendTransaction hook, filtering out
11
+ non-user changes (remote collab, table auto-scale, dirty transactions)
12
+ - Moves initial cache population from nodeview constructor to PM plugin state.init()
13
+ - Optimises updateSyncBlockData with Fragment.eq() for O(1) comparison instead of toJSON() +
14
+ lodash/isEqual
15
+ - Updated dependencies
16
+
17
+ ## 6.0.34
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies
22
+
3
23
  ## 6.0.33
4
24
 
5
25
  ### Patch Changes
@@ -17,6 +17,7 @@ var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/rea
17
17
  var _syncBlock = require("@atlaskit/editor-common/sync-block");
18
18
  var _editorPluginConnectivity = require("@atlaskit/editor-plugin-connectivity");
19
19
  var _model = require("@atlaskit/editor-prosemirror/model");
20
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
20
21
  var _BodiedSyncBlockWrapper = require("../ui/BodiedSyncBlockWrapper");
21
22
  var _SyncBlockLabel = require("../ui/SyncBlockLabel");
22
23
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
@@ -172,8 +173,7 @@ var toDOM = function toDOM(node) {
172
173
  };
173
174
  var BodiedSyncBlock = exports.BodiedSyncBlock = /*#__PURE__*/function () {
174
175
  function BodiedSyncBlock(node, view, getPos, api, nodeViewPortalProviderAPI, syncBlockStore) {
175
- var _this4 = this,
176
- _this$syncedBlockStor;
176
+ var _this4 = this;
177
177
  (0, _classCallCheck2.default)(this, BodiedSyncBlock);
178
178
  this.node = node;
179
179
  this.view = view;
@@ -206,7 +206,11 @@ var BodiedSyncBlock = exports.BodiedSyncBlock = /*#__PURE__*/function () {
206
206
  this.handleViewModeChange();
207
207
 
208
208
  // update sync block data on initial creation
209
- (_this$syncedBlockStor = this.syncedBlockStore) === null || _this$syncedBlockStor === void 0 || _this$syncedBlockStor.sourceManager.updateSyncBlockData(node);
209
+ // When fg is ON, cache is populated in state.init() and updated in appendTransaction
210
+ if (!(0, _platformFeatureFlags.fg)('platform_synced_block_update_refactor')) {
211
+ var _this$syncedBlockStor;
212
+ (_this$syncedBlockStor = this.syncedBlockStore) === null || _this$syncedBlockStor === void 0 || _this$syncedBlockStor.sourceManager.updateSyncBlockData(node);
213
+ }
210
214
  }
211
215
  return (0, _createClass2.default)(BodiedSyncBlock, [{
212
216
  key: "updateContentEditable",
@@ -262,8 +266,12 @@ var BodiedSyncBlock = exports.BodiedSyncBlock = /*#__PURE__*/function () {
262
266
  return false;
263
267
  }
264
268
  if (node !== this.node) {
265
- var _this$syncedBlockStor2;
266
- (_this$syncedBlockStor2 = this.syncedBlockStore) === null || _this$syncedBlockStor2 === void 0 || _this$syncedBlockStor2.sourceManager.updateSyncBlockData(node);
269
+ // When fg is ON, cache updates are handled in appendTransaction where we can
270
+ // filter out non-user changes (remote collab, table auto-scale, etc.)
271
+ if (!(0, _platformFeatureFlags.fg)('platform_synced_block_update_refactor')) {
272
+ var _this$syncedBlockStor2;
273
+ (_this$syncedBlockStor2 = this.syncedBlockStore) === null || _this$syncedBlockStor2 === void 0 || _this$syncedBlockStor2.sourceManager.updateSyncBlockData(node);
274
+ }
267
275
  }
268
276
  this.node = node;
269
277
  return true;
@@ -10,6 +10,7 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
12
  var _analytics = require("@atlaskit/editor-common/analytics");
13
+ var _collab = require("@atlaskit/editor-common/collab");
13
14
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
14
15
  var _selection = require("@atlaskit/editor-common/selection");
15
16
  var _syncBlock = require("@atlaskit/editor-common/sync-block");
@@ -284,6 +285,16 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
284
285
  return node.type.name === 'syncBlock';
285
286
  });
286
287
  syncBlockStore.referenceManager.fetchSyncBlocksData((0, _editorSyncedBlockProvider.convertPMNodesToSyncBlockNodes)(syncBlockNodes));
288
+
289
+ // Populate source sync block cache from initial document
290
+ // When fg is ON, this replaces the constructor call in the nodeview
291
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_update_refactor')) {
292
+ instance.doc.forEach(function (node) {
293
+ if (syncBlockStore.sourceManager.isSourceBlock(node)) {
294
+ syncBlockStore.sourceManager.updateSyncBlockData(node);
295
+ }
296
+ });
297
+ }
287
298
  return {
288
299
  selectionDecorationSet: (0, _selectionDecorations.calculateDecorations)(instance.doc, instance.selection, instance.schema),
289
300
  activeFlag: false,
@@ -503,6 +514,23 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
503
514
  });
504
515
  },
505
516
  appendTransaction: function appendTransaction(trs, oldState, newState) {
517
+ // Update source sync block cache for user-initiated changes only
518
+ // When fg is ON, cache updates are handled here instead of in the nodeview update()
519
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_update_refactor')) {
520
+ var isUserChange = function isUserChange(tr) {
521
+ return tr.docChanged && !(0, _collab.isDirtyTransaction)(tr) && !tr.getMeta('isRemote');
522
+ };
523
+ var hasSourceBlockEdit = trs.some(function (tr) {
524
+ return isUserChange(tr) && (0, _trackSyncBlocks6.hasEditInSyncBlock)(tr, oldState);
525
+ });
526
+ if (hasSourceBlockEdit) {
527
+ newState.doc.forEach(function (node) {
528
+ if (syncBlockStore.sourceManager.isSourceBlock(node)) {
529
+ syncBlockStore.sourceManager.updateSyncBlockData(node);
530
+ }
531
+ });
532
+ }
533
+ }
506
534
  trs.filter(function (tr) {
507
535
  return tr.docChanged;
508
536
  }).forEach(function (tr) {
@@ -5,6 +5,7 @@ import ReactNodeView from '@atlaskit/editor-common/react-node-view';
5
5
  import { BodiedSyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
6
6
  import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
7
7
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
8
9
  import { BodiedSyncBlockWrapper } from '../ui/BodiedSyncBlockWrapper';
9
10
  import { SyncBlockLabel } from '../ui/SyncBlockLabel';
10
11
  const toDOMOld = () => ['div', {
@@ -138,7 +139,6 @@ const toDOM = node => ['div', {
138
139
  }, 0]];
139
140
  export class BodiedSyncBlock {
140
141
  constructor(node, view, getPos, api, nodeViewPortalProviderAPI, syncBlockStore) {
141
- var _this$syncedBlockStor;
142
142
  this.node = node;
143
143
  this.view = view;
144
144
  this.getPos = getPos;
@@ -171,7 +171,11 @@ export class BodiedSyncBlock {
171
171
  this.handleViewModeChange();
172
172
 
173
173
  // update sync block data on initial creation
174
- (_this$syncedBlockStor = this.syncedBlockStore) === null || _this$syncedBlockStor === void 0 ? void 0 : _this$syncedBlockStor.sourceManager.updateSyncBlockData(node);
174
+ // When fg is ON, cache is populated in state.init() and updated in appendTransaction
175
+ if (!fg('platform_synced_block_update_refactor')) {
176
+ var _this$syncedBlockStor;
177
+ (_this$syncedBlockStor = this.syncedBlockStore) === null || _this$syncedBlockStor === void 0 ? void 0 : _this$syncedBlockStor.sourceManager.updateSyncBlockData(node);
178
+ }
175
179
  }
176
180
  updateContentEditable({
177
181
  nextConnectivityMode,
@@ -218,8 +222,12 @@ export class BodiedSyncBlock {
218
222
  return false;
219
223
  }
220
224
  if (node !== this.node) {
221
- var _this$syncedBlockStor2;
222
- (_this$syncedBlockStor2 = this.syncedBlockStore) === null || _this$syncedBlockStor2 === void 0 ? void 0 : _this$syncedBlockStor2.sourceManager.updateSyncBlockData(node);
225
+ // When fg is ON, cache updates are handled in appendTransaction where we can
226
+ // filter out non-user changes (remote collab, table auto-scale, etc.)
227
+ if (!fg('platform_synced_block_update_refactor')) {
228
+ var _this$syncedBlockStor2;
229
+ (_this$syncedBlockStor2 = this.syncedBlockStore) === null || _this$syncedBlockStor2 === void 0 ? void 0 : _this$syncedBlockStor2.sourceManager.updateSyncBlockData(node);
230
+ }
223
231
  }
224
232
  this.node = node;
225
233
  return true;
@@ -1,5 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
3
+ import { isDirtyTransaction } from '@atlaskit/editor-common/collab';
3
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
5
  import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
5
6
  import { BodiedSyncBlockSharedCssClassName, SyncBlockStateCssClassName } from '@atlaskit/editor-common/sync-block';
@@ -245,6 +246,16 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
245
246
  init(_, instance) {
246
247
  const syncBlockNodes = instance.doc.children.filter(node => node.type.name === 'syncBlock');
247
248
  syncBlockStore.referenceManager.fetchSyncBlocksData(convertPMNodesToSyncBlockNodes(syncBlockNodes));
249
+
250
+ // Populate source sync block cache from initial document
251
+ // When fg is ON, this replaces the constructor call in the nodeview
252
+ if (fg('platform_synced_block_update_refactor')) {
253
+ instance.doc.forEach(node => {
254
+ if (syncBlockStore.sourceManager.isSourceBlock(node)) {
255
+ syncBlockStore.sourceManager.updateSyncBlockData(node);
256
+ }
257
+ });
258
+ }
248
259
  return {
249
260
  selectionDecorationSet: calculateDecorations(instance.doc, instance.selection, instance.schema),
250
261
  activeFlag: false,
@@ -467,6 +478,19 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
467
478
  });
468
479
  },
469
480
  appendTransaction: (trs, oldState, newState) => {
481
+ // Update source sync block cache for user-initiated changes only
482
+ // When fg is ON, cache updates are handled here instead of in the nodeview update()
483
+ if (fg('platform_synced_block_update_refactor')) {
484
+ const isUserChange = tr => tr.docChanged && !isDirtyTransaction(tr) && !tr.getMeta('isRemote');
485
+ const hasSourceBlockEdit = trs.some(tr => isUserChange(tr) && hasEditInSyncBlock(tr, oldState));
486
+ if (hasSourceBlockEdit) {
487
+ newState.doc.forEach(node => {
488
+ if (syncBlockStore.sourceManager.isSourceBlock(node)) {
489
+ syncBlockStore.sourceManager.updateSyncBlockData(node);
490
+ }
491
+ });
492
+ }
493
+ }
470
494
  trs.filter(tr => tr.docChanged).forEach(tr => {
471
495
  if (confirmationTransactionRef.current) {
472
496
  confirmationTransactionRef.current = rebaseTransaction(confirmationTransactionRef.current, tr, newState);
@@ -12,6 +12,7 @@ import ReactNodeView from '@atlaskit/editor-common/react-node-view';
12
12
  import { BodiedSyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
13
13
  import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
14
14
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
15
+ import { fg } from '@atlaskit/platform-feature-flags';
15
16
  import { BodiedSyncBlockWrapper } from '../ui/BodiedSyncBlockWrapper';
16
17
  import { SyncBlockLabel } from '../ui/SyncBlockLabel';
17
18
  var toDOMOld = function toDOMOld() {
@@ -165,8 +166,7 @@ var toDOM = function toDOM(node) {
165
166
  };
166
167
  export var BodiedSyncBlock = /*#__PURE__*/function () {
167
168
  function BodiedSyncBlock(node, view, getPos, api, nodeViewPortalProviderAPI, syncBlockStore) {
168
- var _this4 = this,
169
- _this$syncedBlockStor;
169
+ var _this4 = this;
170
170
  _classCallCheck(this, BodiedSyncBlock);
171
171
  this.node = node;
172
172
  this.view = view;
@@ -199,7 +199,11 @@ export var BodiedSyncBlock = /*#__PURE__*/function () {
199
199
  this.handleViewModeChange();
200
200
 
201
201
  // update sync block data on initial creation
202
- (_this$syncedBlockStor = this.syncedBlockStore) === null || _this$syncedBlockStor === void 0 || _this$syncedBlockStor.sourceManager.updateSyncBlockData(node);
202
+ // When fg is ON, cache is populated in state.init() and updated in appendTransaction
203
+ if (!fg('platform_synced_block_update_refactor')) {
204
+ var _this$syncedBlockStor;
205
+ (_this$syncedBlockStor = this.syncedBlockStore) === null || _this$syncedBlockStor === void 0 || _this$syncedBlockStor.sourceManager.updateSyncBlockData(node);
206
+ }
203
207
  }
204
208
  return _createClass(BodiedSyncBlock, [{
205
209
  key: "updateContentEditable",
@@ -255,8 +259,12 @@ export var BodiedSyncBlock = /*#__PURE__*/function () {
255
259
  return false;
256
260
  }
257
261
  if (node !== this.node) {
258
- var _this$syncedBlockStor2;
259
- (_this$syncedBlockStor2 = this.syncedBlockStore) === null || _this$syncedBlockStor2 === void 0 || _this$syncedBlockStor2.sourceManager.updateSyncBlockData(node);
262
+ // When fg is ON, cache updates are handled in appendTransaction where we can
263
+ // filter out non-user changes (remote collab, table auto-scale, etc.)
264
+ if (!fg('platform_synced_block_update_refactor')) {
265
+ var _this$syncedBlockStor2;
266
+ (_this$syncedBlockStor2 = this.syncedBlockStore) === null || _this$syncedBlockStor2 === void 0 || _this$syncedBlockStor2.sourceManager.updateSyncBlockData(node);
267
+ }
260
268
  }
261
269
  this.node = node;
262
270
  return true;
@@ -8,6 +8,7 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
8
8
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
9
9
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
10
10
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
11
+ import { isDirtyTransaction } from '@atlaskit/editor-common/collab';
11
12
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
12
13
  import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
13
14
  import { BodiedSyncBlockSharedCssClassName, SyncBlockStateCssClassName } from '@atlaskit/editor-common/sync-block';
@@ -277,6 +278,16 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
277
278
  return node.type.name === 'syncBlock';
278
279
  });
279
280
  syncBlockStore.referenceManager.fetchSyncBlocksData(convertPMNodesToSyncBlockNodes(syncBlockNodes));
281
+
282
+ // Populate source sync block cache from initial document
283
+ // When fg is ON, this replaces the constructor call in the nodeview
284
+ if (fg('platform_synced_block_update_refactor')) {
285
+ instance.doc.forEach(function (node) {
286
+ if (syncBlockStore.sourceManager.isSourceBlock(node)) {
287
+ syncBlockStore.sourceManager.updateSyncBlockData(node);
288
+ }
289
+ });
290
+ }
280
291
  return {
281
292
  selectionDecorationSet: calculateDecorations(instance.doc, instance.selection, instance.schema),
282
293
  activeFlag: false,
@@ -496,6 +507,23 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
496
507
  });
497
508
  },
498
509
  appendTransaction: function appendTransaction(trs, oldState, newState) {
510
+ // Update source sync block cache for user-initiated changes only
511
+ // When fg is ON, cache updates are handled here instead of in the nodeview update()
512
+ if (fg('platform_synced_block_update_refactor')) {
513
+ var isUserChange = function isUserChange(tr) {
514
+ return tr.docChanged && !isDirtyTransaction(tr) && !tr.getMeta('isRemote');
515
+ };
516
+ var hasSourceBlockEdit = trs.some(function (tr) {
517
+ return isUserChange(tr) && hasEditInSyncBlock(tr, oldState);
518
+ });
519
+ if (hasSourceBlockEdit) {
520
+ newState.doc.forEach(function (node) {
521
+ if (syncBlockStore.sourceManager.isSourceBlock(node)) {
522
+ syncBlockStore.sourceManager.updateSyncBlockData(node);
523
+ }
524
+ });
525
+ }
526
+ }
499
527
  trs.filter(function (tr) {
500
528
  return tr.docChanged;
501
529
  }).forEach(function (tr) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-synced-block",
3
- "version": "6.0.33",
3
+ "version": "6.0.35",
4
4
  "description": "SyncedBlock plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -54,7 +54,7 @@
54
54
  "@atlaskit/platform-feature-flags": "^1.1.0",
55
55
  "@atlaskit/primitives": "^18.1.0",
56
56
  "@atlaskit/spinner": "19.0.12",
57
- "@atlaskit/tmp-editor-statsig": "^50.0.0",
57
+ "@atlaskit/tmp-editor-statsig": "^51.1.0",
58
58
  "@atlaskit/tokens": "11.4.0",
59
59
  "@atlaskit/tooltip": "^21.0.0",
60
60
  "@atlaskit/visually-hidden": "^3.0.0",
@@ -120,6 +120,9 @@
120
120
  "platform_editor_block_menu_divider_patch": {
121
121
  "type": "boolean"
122
122
  },
123
+ "platform_synced_block_update_refactor": {
124
+ "type": "boolean"
125
+ },
123
126
  "platform_synced_block_patch_7": {
124
127
  "type": "boolean"
125
128
  },