@atlaskit/editor-plugin-synced-block 5.3.12 → 5.3.14

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/afm-cc/tsconfig.json +0 -3
  3. package/afm-jira/tsconfig.json +0 -3
  4. package/afm-products/tsconfig.json +0 -3
  5. package/dist/cjs/editor-commands/index.js +34 -38
  6. package/dist/cjs/nodeviews/bodiedSyncedBlock.js +2 -7
  7. package/dist/cjs/nodeviews/syncedBlock.js +4 -18
  8. package/dist/cjs/pm-plugins/main.js +120 -67
  9. package/dist/cjs/pm-plugins/utils/handle-bodied-sync-block-creation.js +141 -0
  10. package/dist/cjs/pm-plugins/utils/track-sync-blocks.js +2 -2
  11. package/dist/cjs/pm-plugins/utils/utils.js +1 -46
  12. package/dist/cjs/syncedBlockPlugin.js +7 -7
  13. package/dist/cjs/types/index.js +1 -0
  14. package/dist/cjs/ui/DeleteConfirmationModal.js +4 -20
  15. package/dist/cjs/ui/Flag.js +5 -1
  16. package/dist/cjs/ui/SyncBlockLabel.js +4 -10
  17. package/dist/cjs/ui/SyncBlockRefresher.js +7 -9
  18. package/dist/cjs/ui/floating-toolbar.js +6 -3
  19. package/dist/es2019/editor-commands/index.js +34 -38
  20. package/dist/es2019/nodeviews/bodiedSyncedBlock.js +2 -7
  21. package/dist/es2019/nodeviews/syncedBlock.js +4 -15
  22. package/dist/es2019/pm-plugins/main.js +99 -58
  23. package/dist/es2019/pm-plugins/utils/handle-bodied-sync-block-creation.js +134 -0
  24. package/dist/es2019/pm-plugins/utils/track-sync-blocks.js +2 -2
  25. package/dist/es2019/pm-plugins/utils/utils.js +0 -47
  26. package/dist/es2019/syncedBlockPlugin.js +7 -6
  27. package/dist/es2019/types/index.js +1 -0
  28. package/dist/es2019/ui/DeleteConfirmationModal.js +4 -20
  29. package/dist/es2019/ui/Flag.js +5 -0
  30. package/dist/es2019/ui/SyncBlockLabel.js +4 -10
  31. package/dist/es2019/ui/SyncBlockRefresher.js +7 -9
  32. package/dist/es2019/ui/floating-toolbar.js +6 -3
  33. package/dist/esm/editor-commands/index.js +34 -38
  34. package/dist/esm/nodeviews/bodiedSyncedBlock.js +2 -7
  35. package/dist/esm/nodeviews/syncedBlock.js +4 -18
  36. package/dist/esm/pm-plugins/main.js +120 -67
  37. package/dist/esm/pm-plugins/utils/handle-bodied-sync-block-creation.js +134 -0
  38. package/dist/esm/pm-plugins/utils/track-sync-blocks.js +2 -2
  39. package/dist/esm/pm-plugins/utils/utils.js +0 -45
  40. package/dist/esm/syncedBlockPlugin.js +7 -7
  41. package/dist/esm/types/index.js +1 -0
  42. package/dist/esm/ui/DeleteConfirmationModal.js +4 -20
  43. package/dist/esm/ui/Flag.js +5 -1
  44. package/dist/esm/ui/SyncBlockLabel.js +4 -10
  45. package/dist/esm/ui/SyncBlockRefresher.js +7 -9
  46. package/dist/esm/ui/floating-toolbar.js +6 -3
  47. package/dist/types/pm-plugins/main.d.ts +2 -1
  48. package/dist/types/pm-plugins/utils/handle-bodied-sync-block-creation.d.ts +9 -0
  49. package/dist/types/pm-plugins/utils/handle-bodied-sync-block-removal.d.ts +2 -2
  50. package/dist/types/pm-plugins/utils/utils.d.ts +1 -3
  51. package/dist/types/types/index.d.ts +19 -1
  52. package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -1
  53. package/dist/types-ts4.5/pm-plugins/utils/handle-bodied-sync-block-creation.d.ts +9 -0
  54. package/dist/types-ts4.5/pm-plugins/utils/handle-bodied-sync-block-removal.d.ts +2 -2
  55. package/dist/types-ts4.5/pm-plugins/utils/utils.d.ts +1 -3
  56. package/dist/types-ts4.5/types/index.d.ts +19 -1
  57. package/package.json +1 -5
@@ -1,9 +1,10 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2
5
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
3
6
  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; } }
4
7
  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; }
5
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
8
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
8
9
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
9
10
  import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
@@ -15,15 +16,48 @@ import { DecorationSet, Decoration } from '@atlaskit/editor-prosemirror/view';
15
16
  import { convertPMNodesToSyncBlockNodes, rebaseTransaction } from '@atlaskit/editor-synced-block-provider';
16
17
  import { fg } from '@atlaskit/platform-feature-flags';
17
18
  import { lazyBodiedSyncBlockView } from '../nodeviews/bodiedLazySyncedBlock';
18
- import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
19
19
  import { SyncBlock as SyncBlockView } from '../nodeviews/syncedBlock';
20
20
  import { FLAG_ID } from '../types';
21
+ import { handleBodiedSyncBlockCreation } from './utils/handle-bodied-sync-block-creation';
21
22
  import { handleBodiedSyncBlockRemoval } from './utils/handle-bodied-sync-block-removal';
22
23
  import { shouldIgnoreDomEvent } from './utils/ignore-dom-event';
23
24
  import { calculateDecorations } from './utils/selection-decorations';
24
25
  import { hasEditInSyncBlock, trackSyncBlocks } from './utils/track-sync-blocks';
25
26
  import { sliceFullyContainsNode } from './utils/utils';
26
27
  export var syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
28
+ var mapRetryCreationPosMap = function mapRetryCreationPosMap(oldMap, newRetryCreationPos, mapPos) {
29
+ var resourceId = newRetryCreationPos === null || newRetryCreationPos === void 0 ? void 0 : newRetryCreationPos.resourceId;
30
+ var newMap = new Map(oldMap);
31
+ if (resourceId) {
32
+ var pos = newRetryCreationPos.pos;
33
+ if (!pos) {
34
+ newMap.delete(resourceId);
35
+ } else {
36
+ newMap.set(resourceId, pos);
37
+ }
38
+ }
39
+ if (newMap.size === 0) {
40
+ return newMap;
41
+ }
42
+ var _iterator = _createForOfIteratorHelper(newMap.entries()),
43
+ _step;
44
+ try {
45
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
46
+ var _step$value = _slicedToArray(_step.value, 2),
47
+ id = _step$value[0],
48
+ _pos = _step$value[1];
49
+ newMap.set(id, {
50
+ from: mapPos(_pos.from),
51
+ to: mapPos(_pos.to)
52
+ });
53
+ }
54
+ } catch (err) {
55
+ _iterator.e(err);
56
+ } finally {
57
+ _iterator.f();
58
+ }
59
+ return newMap;
60
+ };
27
61
  var showCopiedFlag = function showCopiedFlag(api) {
28
62
  // Use setTimeout to dispatch transaction in next tick and avoid re-entrant dispatch
29
63
  setTimeout(function () {
@@ -57,7 +91,7 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
57
91
  var unpublishedFlagShown = new Set();
58
92
 
59
93
  // Set up callback to detect unpublished sync blocks when they're fetched
60
- fg('platform_synced_block_dogfooding') && syncBlockStore.referenceManager.setOnUnpublishedSyncBlockDetected(function (resourceId) {
94
+ syncBlockStore.referenceManager.setOnUnpublishedSyncBlockDetected(function (resourceId) {
61
95
  // Only show the flag once per sync block
62
96
  if (!unpublishedFlagShown.has(resourceId)) {
63
97
  unpublishedFlagShown.add(resourceId);
@@ -85,7 +119,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
85
119
  return {
86
120
  selectionDecorationSet: calculateDecorations(instance.doc, instance.selection, instance.schema),
87
121
  activeFlag: false,
88
- syncBlockStore: syncBlockStore
122
+ syncBlockStore: syncBlockStore,
123
+ retryCreationPosMap: new Map()
89
124
  };
90
125
  },
91
126
  apply: function apply(tr, currentPluginState, oldEditorState) {
@@ -93,22 +128,29 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
93
128
  var meta = tr.getMeta(syncedBlockPluginKey);
94
129
  var activeFlag = currentPluginState.activeFlag,
95
130
  selectionDecorationSet = currentPluginState.selectionDecorationSet,
96
- bodiedSyncBlockDeletionStatus = currentPluginState.bodiedSyncBlockDeletionStatus;
131
+ bodiedSyncBlockDeletionStatus = currentPluginState.bodiedSyncBlockDeletionStatus,
132
+ retryCreationPosMap = currentPluginState.retryCreationPosMap;
97
133
  var newDecorationSet = selectionDecorationSet.map(tr.mapping, tr.doc);
98
134
  if (!tr.selection.eq(oldEditorState.selection)) {
99
135
  newDecorationSet = calculateDecorations(tr.doc, tr.selection, tr.doc.type.schema);
100
136
  }
137
+ var newRetryCreationPosMap = retryCreationPosMap;
138
+ if (fg('platform_synced_block_patch_1')) {
139
+ var newPosEntry = meta === null || meta === void 0 ? void 0 : meta.retryCreationPos;
140
+ newRetryCreationPosMap = mapRetryCreationPosMap(retryCreationPosMap, newPosEntry, tr.mapping.map.bind(tr.mapping));
141
+ }
101
142
  return {
102
143
  activeFlag: (_meta$activeFlag = meta === null || meta === void 0 ? void 0 : meta.activeFlag) !== null && _meta$activeFlag !== void 0 ? _meta$activeFlag : activeFlag,
103
144
  selectionDecorationSet: newDecorationSet,
104
145
  syncBlockStore: syncBlockStore,
146
+ retryCreationPosMap: newRetryCreationPosMap,
105
147
  bodiedSyncBlockDeletionStatus: (_meta$bodiedSyncBlock = meta === null || meta === void 0 ? void 0 : meta.bodiedSyncBlockDeletionStatus) !== null && _meta$bodiedSyncBlock !== void 0 ? _meta$bodiedSyncBlock : bodiedSyncBlockDeletionStatus
106
148
  };
107
149
  }
108
150
  },
109
151
  props: {
110
152
  nodeViews: {
111
- syncBlock: fg('platform_synced_block_dogfooding') ? function (node, view, getPos, _decorations) {
153
+ syncBlock: function syncBlock(node, view, getPos, _decorations) {
112
154
  // To support SSR, pass `syncBlockStore` here
113
155
  // and do not use lazy loading.
114
156
  // We cannot start rendering and then load `syncBlockStore` asynchronously,
@@ -123,11 +165,7 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
123
165
  eventDispatcher: pmPluginFactoryParams.eventDispatcher,
124
166
  syncBlockStore: syncBlockStore
125
167
  }).init();
126
- } : lazySyncBlockView({
127
- options: options,
128
- pmPluginFactoryParams: pmPluginFactoryParams,
129
- api: api
130
- }),
168
+ },
131
169
  bodiedSyncBlock: lazyBodiedSyncBlockView({
132
170
  pluginOptions: options,
133
171
  pmPluginFactoryParams: pmPluginFactoryParams,
@@ -135,13 +173,16 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
135
173
  })
136
174
  },
137
175
  decorations: function decorations(state) {
138
- var _syncedBlockPluginKey, _syncedBlockPluginKey2, _api$connectivity, _api$editorViewMode;
139
- var selectionDecorationSet = (_syncedBlockPluginKey = (_syncedBlockPluginKey2 = syncedBlockPluginKey.getState(state)) === null || _syncedBlockPluginKey2 === void 0 ? void 0 : _syncedBlockPluginKey2.selectionDecorationSet) !== null && _syncedBlockPluginKey !== void 0 ? _syncedBlockPluginKey : DecorationSet.empty;
176
+ var _currentPluginState$s, _api$connectivity, _api$editorViewMode;
177
+ var currentPluginState = syncedBlockPluginKey.getState(state);
178
+ var selectionDecorationSet = (_currentPluginState$s = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.selectionDecorationSet) !== null && _currentPluginState$s !== void 0 ? _currentPluginState$s : DecorationSet.empty;
179
+ var syncBlockStore = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.syncBlockStore;
140
180
  var doc = state.doc;
141
181
  var isOffline = isOfflineMode(api === null || api === void 0 || (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.sharedState.currentState()) === null || _api$connectivity === void 0 ? void 0 : _api$connectivity.mode);
142
182
  var isViewMode = (api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 || (_api$editorViewMode = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.mode) === 'view';
143
183
  var offlineDecorations = [];
144
184
  var viewModeDecorations = [];
185
+ var loadingDecorations = [];
145
186
  state.doc.descendants(function (node, pos) {
146
187
  if (node.type.name === 'bodiedSyncBlock' && isOffline) {
147
188
  offlineDecorations.push(Decoration.node(pos, pos + node.nodeSize, {
@@ -153,8 +194,13 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
153
194
  class: SyncBlockStateCssClassName.viewModeClassName
154
195
  }));
155
196
  }
197
+ if (node.type.name === 'bodiedSyncBlock' && syncBlockStore.sourceManager.isPendingCreation(node.attrs.resourceId) && fg('platform_synced_block_patch_1')) {
198
+ loadingDecorations.push(Decoration.node(pos, pos + node.nodeSize, {
199
+ class: SyncBlockStateCssClassName.creationLoadingClassName
200
+ }));
201
+ }
156
202
  });
157
- return selectionDecorationSet.add(doc, offlineDecorations).add(doc, viewModeDecorations);
203
+ return selectionDecorationSet.add(doc, offlineDecorations).add(doc, viewModeDecorations).add(doc, loadingDecorations);
158
204
  },
159
205
  handleClickOn: createSelectionClickHandler(['bodiedSyncBlock'], function (target) {
160
206
  return !!target.closest(".".concat(BodiedSyncBlockSharedCssClassName.prefix));
@@ -215,9 +261,15 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
215
261
  var _api$connectivity2;
216
262
  var isOffline = isOfflineMode(api === null || api === void 0 || (_api$connectivity2 = api.connectivity) === null || _api$connectivity2 === void 0 || (_api$connectivity2 = _api$connectivity2.sharedState.currentState()) === null || _api$connectivity2 === void 0 ? void 0 : _api$connectivity2.mode);
217
263
  var isConfirmedSyncBlockDeletion = Boolean(tr.getMeta('isConfirmedSyncBlockDeletion'));
264
+ var hasNoPendingRequest = fg('platform_synced_block_patch_1') ? false :
265
+ // requireConfirmationBeforeDelete is always true, so this evaluates to false and hence redundant
266
+ !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.sourceManager.requireConfirmationBeforeDelete()) && !syncBlockStore.sourceManager.hasPendingCreation();
267
+ var isCommitsCreation = fg('platform_synced_block_patch_1') ? false :
268
+ // For patch 1, we don't intercept the insert transaction, hence it's redundant
269
+ Boolean(tr.getMeta('isCommitSyncBlockCreation'));
218
270
 
219
271
  // Track newly added reference sync blocks before processing the transaction
220
- if (tr.docChanged && !tr.getMeta('isRemote') && fg('platform_synced_block_dogfooding')) {
272
+ if (tr.docChanged && !tr.getMeta('isRemote')) {
221
273
  var _trackSyncBlocks = trackSyncBlocks(function (node) {
222
274
  return node.type.name === 'syncBlock';
223
275
  }, tr, state),
@@ -235,50 +287,47 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
235
287
  // or are from remote (collab) or already confirmed sync block deletion
236
288
  // We only care about local changes that change the document
237
289
  // and are not yet confirmed for sync block deletion
238
- if (!tr.docChanged || !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.sourceManager.requireConfirmationBeforeDelete()) && !syncBlockStore.sourceManager.hasPendingCreation() || Boolean(tr.getMeta('isRemote')) || Boolean(tr.getMeta('isCommitSyncBlockCreation')) || !isOffline && isConfirmedSyncBlockDeletion) {
290
+ if (!tr.docChanged || hasNoPendingRequest || Boolean(tr.getMeta('isRemote')) || isCommitsCreation || !isOffline && isConfirmedSyncBlockDeletion) {
239
291
  return true;
240
292
  }
241
293
  var _trackSyncBlocks2 = trackSyncBlocks(syncBlockStore.sourceManager.isSourceBlock, tr, state),
242
294
  bodiedSyncBlockRemoved = _trackSyncBlocks2.removed,
243
295
  bodiedSyncBlockAdded = _trackSyncBlocks2.added;
244
296
  if (!isOffline) {
245
- if (fg('platform_synced_block_dogfooding')) {
246
- var _trackSyncBlocks3 = trackSyncBlocks(function (node) {
247
- return node.type.name === 'syncBlock';
248
- }, tr, state),
249
- syncBlockRemoved = _trackSyncBlocks3.removed,
250
- syncBlockAdded = _trackSyncBlocks3.added;
251
- syncBlockRemoved.forEach(function (syncBlock) {
252
- var _api$analytics;
253
- api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.fireAnalyticsEvent({
254
- action: ACTION.DELETED,
255
- actionSubject: ACTION_SUBJECT.SYNCED_BLOCK,
256
- actionSubjectId: ACTION_SUBJECT_ID.REFERENCE_SYNCED_BLOCK_DELETE,
257
- attributes: {
258
- resourceId: syncBlock.attrs.resourceId,
259
- blockInstanceId: syncBlock.attrs.localId
260
- },
261
- eventType: EVENT_TYPE.OPERATIONAL
262
- });
297
+ var _trackSyncBlocks3 = trackSyncBlocks(function (node) {
298
+ return node.type.name === 'syncBlock';
299
+ }, tr, state),
300
+ syncBlockRemoved = _trackSyncBlocks3.removed,
301
+ syncBlockAdded = _trackSyncBlocks3.added;
302
+ syncBlockRemoved.forEach(function (syncBlock) {
303
+ var _api$analytics;
304
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.fireAnalyticsEvent({
305
+ action: ACTION.DELETED,
306
+ actionSubject: ACTION_SUBJECT.SYNCED_BLOCK,
307
+ actionSubjectId: ACTION_SUBJECT_ID.REFERENCE_SYNCED_BLOCK_DELETE,
308
+ attributes: {
309
+ resourceId: syncBlock.attrs.resourceId,
310
+ blockInstanceId: syncBlock.attrs.localId
311
+ },
312
+ eventType: EVENT_TYPE.OPERATIONAL
263
313
  });
264
- syncBlockAdded.forEach(function (syncBlock) {
265
- var _api$analytics2;
266
- api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || (_api$analytics2 = _api$analytics2.actions) === null || _api$analytics2 === void 0 || _api$analytics2.fireAnalyticsEvent({
267
- action: ACTION.INSERTED,
268
- actionSubject: ACTION_SUBJECT.SYNCED_BLOCK,
269
- actionSubjectId: ACTION_SUBJECT_ID.REFERENCE_SYNCED_BLOCK_CREATE,
270
- attributes: {
271
- resourceId: syncBlock.attrs.resourceId,
272
- blockInstanceId: syncBlock.attrs.localId
273
- },
274
- eventType: EVENT_TYPE.OPERATIONAL
275
- });
314
+ });
315
+ syncBlockAdded.forEach(function (syncBlock) {
316
+ var _api$analytics2;
317
+ api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || (_api$analytics2 = _api$analytics2.actions) === null || _api$analytics2 === void 0 || _api$analytics2.fireAnalyticsEvent({
318
+ action: ACTION.INSERTED,
319
+ actionSubject: ACTION_SUBJECT.SYNCED_BLOCK,
320
+ actionSubjectId: ACTION_SUBJECT_ID.REFERENCE_SYNCED_BLOCK_CREATE,
321
+ attributes: {
322
+ resourceId: syncBlock.attrs.resourceId,
323
+ blockInstanceId: syncBlock.attrs.localId
324
+ },
325
+ eventType: EVENT_TYPE.OPERATIONAL
276
326
  });
277
- }
278
- ;
327
+ });
279
328
  if (bodiedSyncBlockRemoved.length > 0) {
280
329
  confirmationTransactionRef.current = tr;
281
- return handleBodiedSyncBlockRemoval(bodiedSyncBlockRemoved, syncBlockStore, api, confirmationTransactionRef, fg('platform_synced_block_dogfooding') ? getDeleteReason(tr) : undefined);
330
+ return handleBodiedSyncBlockRemoval(bodiedSyncBlockRemoved, syncBlockStore, api, confirmationTransactionRef, getDeleteReason(tr));
282
331
  }
283
332
  if (bodiedSyncBlockAdded.length > 0) {
284
333
  if (Boolean(tr.getMeta(pmHistoryPluginKey))) {
@@ -287,18 +336,22 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
287
336
  // After true is returned here and the node is created, we delete the node in the filterTransaction immediately, which cancels out the creation
288
337
  return true;
289
338
  }
290
-
291
- // If there is bodiedSyncBlock node addition and it's waiting for the result of saving the node to backend (syncBlockStore.hasPendingCreation()),
292
- // we need to intercept the transaction and save it in insert callback so that we only insert it to the document when backend call if backend call is successful
293
- // The callback will be evoked by in SourceSyncBlockStoreManager.commitPendingCreation
294
- syncBlockStore.sourceManager.registerCreationCallback(function () {
295
- var _api$core;
296
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function () {
297
- return tr.setMeta('isCommitSyncBlockCreation', true);
339
+ if (fg('platform_synced_block_patch_1')) {
340
+ handleBodiedSyncBlockCreation(bodiedSyncBlockAdded, state, api);
341
+ return true;
342
+ } else {
343
+ // If there is bodiedSyncBlock node addition and it's waiting for the result of saving the node to backend (syncBlockStore.hasPendingCreation()),
344
+ // we need to intercept the transaction and save it in insert callback so that we only insert it to the document when backend call if backend call is successful
345
+ // The callback will be evoked by in SourceSyncBlockStoreManager.commitPendingCreation
346
+ syncBlockStore.sourceManager.registerCreationCallback(function () {
347
+ var _api$core;
348
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function () {
349
+ return tr.setMeta('isCommitSyncBlockCreation', true);
350
+ });
351
+ api === null || api === void 0 || api.core.actions.focus();
298
352
  });
299
- api === null || api === void 0 || api.core.actions.focus();
300
- });
301
- return false;
353
+ return false;
354
+ }
302
355
  }
303
356
  } else {
304
357
  var _trackSyncBlocks4 = trackSyncBlocks(function (node) {
@@ -341,11 +394,11 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
341
394
  confirmationTransactionRef.current = rebaseTransaction(confirmationTransactionRef.current, tr, newState);
342
395
  }
343
396
  });
344
- var _iterator = _createForOfIteratorHelper(trs),
345
- _step;
397
+ var _iterator2 = _createForOfIteratorHelper(trs),
398
+ _step2;
346
399
  try {
347
400
  var _loop = function _loop() {
348
- var tr = _step.value;
401
+ var tr = _step2.value;
349
402
  if (!tr.getMeta(pmHistoryPluginKey)) {
350
403
  return 0; // continue
351
404
  }
@@ -366,15 +419,15 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
366
419
  }
367
420
  },
368
421
  _ret;
369
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
422
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
370
423
  _ret = _loop();
371
424
  if (_ret === 0) continue;
372
425
  if (_ret) return _ret.v;
373
426
  }
374
427
  } catch (err) {
375
- _iterator.e(err);
428
+ _iterator2.e(err);
376
429
  } finally {
377
- _iterator.f();
430
+ _iterator2.f();
378
431
  }
379
432
  return null;
380
433
  }
@@ -0,0 +1,134 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
5
+ import { FLAG_ID } from '../../types';
6
+ import { syncedBlockPluginKey } from '../main';
7
+ var onRetry = function onRetry(api, resourceId) {
8
+ return function () {
9
+ var _api$core, _api$core2;
10
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.focus();
11
+ api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref) {
12
+ var _api$syncedBlock, _api$syncedBlock2;
13
+ var tr = _ref.tr;
14
+ var pos = api === null || api === void 0 || (_api$syncedBlock = api.syncedBlock) === null || _api$syncedBlock === void 0 || (_api$syncedBlock = _api$syncedBlock.sharedState.currentState()) === null || _api$syncedBlock === void 0 || (_api$syncedBlock = _api$syncedBlock.retryCreationPosMap) === null || _api$syncedBlock === void 0 ? void 0 : _api$syncedBlock.get(resourceId);
15
+ var from = pos === null || pos === void 0 ? void 0 : pos.from;
16
+ var to = pos === null || pos === void 0 ? void 0 : pos.to;
17
+ if (from === undefined || to === undefined) {
18
+ return tr;
19
+ }
20
+ tr.setSelection(TextSelection.create(tr.doc, from, to)).setMeta(syncedBlockPluginKey, {
21
+ activeFlag: false
22
+ });
23
+ api === null || api === void 0 || (_api$syncedBlock2 = api.syncedBlock) === null || _api$syncedBlock2 === void 0 || _api$syncedBlock2.commands.insertSyncedBlock()({
24
+ tr: tr
25
+ });
26
+ return tr;
27
+ });
28
+ };
29
+ };
30
+ var getRevertCreationPos = function getRevertCreationPos(api, doc, resourceId) {
31
+ var _api$syncedBlock3;
32
+ var retryCreationPos = api === null || api === void 0 || (_api$syncedBlock3 = api.syncedBlock) === null || _api$syncedBlock3 === void 0 || (_api$syncedBlock3 = _api$syncedBlock3.sharedState.currentState()) === null || _api$syncedBlock3 === void 0 || (_api$syncedBlock3 = _api$syncedBlock3.retryCreationPosMap) === null || _api$syncedBlock3 === void 0 ? void 0 : _api$syncedBlock3.get(resourceId);
33
+ if (retryCreationPos) {
34
+ return retryCreationPos;
35
+ }
36
+
37
+ // Fallback to find the positions in case BE call returns before plugin state becomes available
38
+ // which is highly unlikely
39
+ var currentPos;
40
+ doc.descendants(function (node, pos) {
41
+ if (currentPos) {
42
+ return false;
43
+ }
44
+ if (node.type.name === 'bodiedSyncBlock' && resourceId === node.attrs.resourceId) {
45
+ currentPos = {
46
+ from: pos,
47
+ to: pos + node.nodeSize
48
+ };
49
+ return false;
50
+ }
51
+ });
52
+ return currentPos;
53
+ };
54
+ var buildRevertCreationTr = function buildRevertCreationTr(tr, pos) {
55
+ var _tr$doc$nodeAt;
56
+ var content = (_tr$doc$nodeAt = tr.doc.nodeAt(pos.from)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.content;
57
+ if (content) {
58
+ tr.replaceWith(pos.from, pos.to, content);
59
+ var contentFrom = tr.mapping.map(pos.from);
60
+ tr.setSelection(TextSelection.create(tr.doc, contentFrom, contentFrom + content.size));
61
+ } else {
62
+ tr.delete(pos.from, pos.to);
63
+ }
64
+ return tr;
65
+ };
66
+
67
+ /**
68
+ *
69
+ * Save the new bodiedSyncBlock to backend with empty content and handles revert (if failed) and retry flow
70
+ */
71
+ export var handleBodiedSyncBlockCreation = function handleBodiedSyncBlockCreation(bodiedSyncBlockAdded, editorState, api) {
72
+ var syncBlockStore = syncedBlockPluginKey.getState(editorState).syncBlockStore;
73
+ bodiedSyncBlockAdded.forEach(function (node) {
74
+ if (node.from === undefined || node.to === undefined) {
75
+ return;
76
+ }
77
+ var retryCreationPos = {
78
+ from: node.from,
79
+ to: node.to
80
+ };
81
+ var resourceId = node.attrs.resourceId;
82
+ setTimeout(function () {
83
+ var _api$core3;
84
+ api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref2) {
85
+ var tr = _ref2.tr;
86
+ return tr.setMeta(syncedBlockPluginKey, {
87
+ retryCreationPos: {
88
+ resourceId: resourceId,
89
+ pos: retryCreationPos
90
+ }
91
+ });
92
+ });
93
+ });
94
+ syncBlockStore.sourceManager.createBodiedSyncBlockNode(node.attrs, function (success) {
95
+ if (success) {
96
+ var _api$core4, _api$core5;
97
+ api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref3) {
98
+ var tr = _ref3.tr;
99
+ return tr.setMeta(syncedBlockPluginKey, {
100
+ retryCreationPos: {
101
+ resourceId: resourceId,
102
+ pos: undefined
103
+ }
104
+ });
105
+ });
106
+ api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.focus();
107
+ } else {
108
+ var _api$core6;
109
+ api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.execute(function (_ref4) {
110
+ var tr = _ref4.tr;
111
+ var revertCreationPos = getRevertCreationPos(api, tr.doc, resourceId);
112
+ if (!revertCreationPos) {
113
+ return tr;
114
+ }
115
+ var revertTr = buildRevertCreationTr(tr, revertCreationPos);
116
+ return revertTr.setMeta('isConfirmedSyncBlockDeletion', true).setMeta('addToHistory', false).setMeta(syncedBlockPluginKey, {
117
+ activeFlag: {
118
+ id: FLAG_ID.CANNOT_CREATE_SYNC_BLOCK,
119
+ onRetry: onRetry(api, resourceId),
120
+ onDismissed: function onDismissed(tr) {
121
+ return tr.setMeta(syncedBlockPluginKey, _objectSpread(_objectSpread({}, tr.getMeta(syncedBlockPluginKey)), {}, {
122
+ retryCreationPos: {
123
+ resourceId: resourceId,
124
+ pos: undefined
125
+ }
126
+ }));
127
+ }
128
+ }
129
+ });
130
+ });
131
+ }
132
+ }, node.node);
133
+ });
134
+ };
@@ -3,7 +3,6 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
3
3
  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; }
4
4
  import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
5
5
  import { findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
6
- import { fg } from '@atlaskit/platform-feature-flags';
7
6
  export var trackSyncBlocks = function trackSyncBlocks(predicate, tr, state) {
8
7
  var removed = {};
9
8
  var added = {};
@@ -23,7 +22,7 @@ export var trackSyncBlocks = function trackSyncBlocks(predicate, tr, state) {
23
22
  var hasBodiedSyncBlockChanges = replaceSteps.some(function (step, idx) {
24
23
  var from = step.from,
25
24
  to = step.to;
26
- var docAtStep = fg('platform_synced_block_dogfooding') ? tr.docs[idx] : state.doc;
25
+ var docAtStep = tr.docs[idx];
27
26
  var hasChange = false;
28
27
  if (from !== to) {
29
28
  step.getMap().forEach(function (oldStart, oldEnd) {
@@ -70,6 +69,7 @@ export var trackSyncBlocks = function trackSyncBlocks(predicate, tr, state) {
70
69
  var syncBlockAttr = node.attrs;
71
70
  syncBlockMapNew[syncBlockAttr.localId] = {
72
71
  attrs: syncBlockAttr,
72
+ node: node,
73
73
  from: offset,
74
74
  to: offset + node.nodeSize
75
75
  };
@@ -1,9 +1,6 @@
1
1
  import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection';
2
2
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
4
3
  import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
- import { CellSelection, findTable } from '@atlaskit/editor-tables';
6
- import { fg } from '@atlaskit/platform-feature-flags';
7
4
  export var findSyncBlock = function findSyncBlock(schema, selection) {
8
5
  var syncBlock = schema.nodes.syncBlock;
9
6
  return findSelectedNodeOfType(syncBlock)(selection);
@@ -28,48 +25,6 @@ var UNSUPPORTED_NODE_TYPES = new Set(['inlineExtension', 'extension', 'bodiedExt
28
25
  * or false if conversion is not possible
29
26
  */
30
27
  export var canBeConvertedToSyncBlock = function canBeConvertedToSyncBlock(selection) {
31
- return fg('platform_synced_block_dogfooding') ? canBeConvertedToSyncBlockNew(selection) : canBeConvertedToSyncBlockOld(selection);
32
- };
33
- export var canBeConvertedToSyncBlockOld = function canBeConvertedToSyncBlockOld(selection) {
34
- var schema = selection.$from.doc.type.schema;
35
- var nodes = schema.nodes;
36
- var from = selection.from;
37
- var to = selection.to;
38
- var contentToInclude = selection.content().content;
39
- if (selection instanceof CellSelection) {
40
- var table = findTable(selection);
41
- if (!table) {
42
- return false;
43
- }
44
- contentToInclude = Fragment.from([table.node]);
45
- from = table.pos;
46
- to = table.pos + table.node.nodeSize;
47
- } else if (selection instanceof TextSelection) {
48
- var trueParent = findParentNodeOfType([nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.blockquote])(selection);
49
- if (trueParent) {
50
- contentToInclude = Fragment.from([trueParent.node]);
51
- from = trueParent.pos;
52
- to = trueParent.pos + trueParent.node.nodeSize;
53
- }
54
- }
55
- var canBeConverted = true;
56
- selection.$from.doc.nodesBetween(from, to, function (node) {
57
- if (UNSUPPORTED_NODE_TYPES.has(node.type.name)) {
58
- canBeConverted = false;
59
- return false;
60
- }
61
- });
62
- if (!canBeConverted) {
63
- return false;
64
- }
65
- contentToInclude = removeBreakoutMarks(contentToInclude);
66
- return {
67
- contentToInclude: contentToInclude,
68
- from: from,
69
- to: to
70
- };
71
- };
72
- export var canBeConvertedToSyncBlockNew = function canBeConvertedToSyncBlockNew(selection) {
73
28
  var _expandSelectionToBlo = expandSelectionToBlockRange(selection),
74
29
  $from = _expandSelectionToBlo.$from,
75
30
  range = _expandSelectionToBlo.range;
@@ -1,11 +1,9 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
1
  import React from 'react';
3
2
  import { bodiedSyncBlock, syncBlock } from '@atlaskit/adf-schema';
4
3
  import { blockTypeMessages } from '@atlaskit/editor-common/messages';
5
4
  import { IconSyncBlock } from '@atlaskit/editor-common/quick-insert';
6
5
  import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
7
6
  import Lozenge from '@atlaskit/lozenge';
8
- import { fg } from '@atlaskit/platform-feature-flags';
9
7
  import { flushBodiedSyncBlocks as _flushBodiedSyncBlocks, flushSyncBlocks } from './editor-actions';
10
8
  import { copySyncedBlockReferenceToClipboardEditorCommand, createSyncedBlock } from './editor-commands';
11
9
  import { createPlugin, syncedBlockPluginKey } from './pm-plugins/main';
@@ -43,7 +41,7 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
43
41
  plugin: function plugin(params) {
44
42
  return createPlugin(config, params, syncBlockStore, api);
45
43
  }
46
- }].concat(_toConsumableArray(fg('platform_synced_block_dogfooding') ? [{
44
+ }, {
47
45
  name: 'menuAndToolbarExperiencesPlugin',
48
46
  plugin: function plugin() {
49
47
  return getMenuAndToolbarExperiencesPlugin({
@@ -54,7 +52,7 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
54
52
  }
55
53
  });
56
54
  }
57
- }] : []));
55
+ }];
58
56
  },
59
57
  commands: {
60
58
  copySyncedBlockReferenceToClipboard: function copySyncedBlockReferenceToClipboard(inputMethod) {
@@ -114,7 +112,7 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
114
112
  fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions.fireAnalyticsEvent
115
113
  });
116
114
  },
117
- testId: fg('platform_synced_block_dogfooding') ? SYNCED_BLOCK_BUTTON_TEST_ID.quickInsertCreate : undefined
115
+ testId: SYNCED_BLOCK_BUTTON_TEST_ID.quickInsertCreate
118
116
  }];
119
117
  },
120
118
  floatingToolbar: function floatingToolbar(state, intl) {
@@ -145,11 +143,13 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
145
143
  var _syncedBlockPluginKey = syncedBlockPluginKey.getState(editorState),
146
144
  activeFlag = _syncedBlockPluginKey.activeFlag,
147
145
  currentSyncBlockStore = _syncedBlockPluginKey.syncBlockStore,
148
- bodiedSyncBlockDeletionStatus = _syncedBlockPluginKey.bodiedSyncBlockDeletionStatus;
146
+ bodiedSyncBlockDeletionStatus = _syncedBlockPluginKey.bodiedSyncBlockDeletionStatus,
147
+ retryCreationPosMap = _syncedBlockPluginKey.retryCreationPosMap;
149
148
  return {
150
149
  activeFlag: activeFlag,
151
150
  syncBlockStore: currentSyncBlockStore,
152
- bodiedSyncBlockDeletionStatus: bodiedSyncBlockDeletionStatus
151
+ bodiedSyncBlockDeletionStatus: bodiedSyncBlockDeletionStatus,
152
+ retryCreationPosMap: retryCreationPosMap
153
153
  };
154
154
  }
155
155
  };
@@ -5,6 +5,7 @@ export var FLAG_ID = /*#__PURE__*/function (FLAG_ID) {
5
5
  FLAG_ID["FAIL_TO_DELETE"] = "fail-to-delete";
6
6
  FLAG_ID["SYNC_BLOCK_COPIED"] = "sync-block-copied";
7
7
  FLAG_ID["UNPUBLISHED_SYNC_BLOCK_PASTED"] = "unpublished-sync-block-pasted";
8
+ FLAG_ID["CANNOT_CREATE_SYNC_BLOCK"] = "cannot-create-sync-block";
8
9
  return FLAG_ID;
9
10
  }({});
10
11
  export var SYNCED_BLOCK_BUTTON_TEST_ID = {