@atlaskit/editor-plugin-synced-block 4.4.0 → 4.4.1

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 (37) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/afm-cc/tsconfig.json +2 -1
  3. package/afm-jira/tsconfig.json +2 -1
  4. package/afm-products/tsconfig.json +2 -1
  5. package/dist/cjs/pm-plugins/main.js +21 -34
  6. package/dist/cjs/pm-plugins/utils/handle-bodied-sync-block-removal.js +87 -0
  7. package/dist/cjs/syncedBlockPlugin.js +6 -4
  8. package/dist/cjs/types/index.js +1 -0
  9. package/dist/cjs/ui/DeleteConfirmationModal.js +53 -12
  10. package/dist/cjs/ui/Flag.js +44 -17
  11. package/dist/es2019/pm-plugins/main.js +21 -32
  12. package/dist/es2019/pm-plugins/utils/handle-bodied-sync-block-removal.js +74 -0
  13. package/dist/es2019/syncedBlockPlugin.js +6 -4
  14. package/dist/es2019/types/index.js +1 -0
  15. package/dist/es2019/ui/DeleteConfirmationModal.js +56 -12
  16. package/dist/es2019/ui/Flag.js +43 -13
  17. package/dist/esm/pm-plugins/main.js +21 -34
  18. package/dist/esm/pm-plugins/utils/handle-bodied-sync-block-removal.js +80 -0
  19. package/dist/esm/syncedBlockPlugin.js +6 -4
  20. package/dist/esm/types/index.js +1 -0
  21. package/dist/esm/ui/DeleteConfirmationModal.js +53 -12
  22. package/dist/esm/ui/Flag.js +44 -17
  23. package/dist/types/pm-plugins/main.d.ts +3 -2
  24. package/dist/types/pm-plugins/utils/handle-bodied-sync-block-removal.d.ts +9 -0
  25. package/dist/types/pm-plugins/utils/track-sync-blocks.d.ts +2 -11
  26. package/dist/types/syncedBlockPluginType.d.ts +0 -4
  27. package/dist/types/types/index.d.ts +28 -2
  28. package/dist/types/ui/CreateSyncedBlockButton.d.ts +1 -1
  29. package/dist/types/ui/OverflowMenuSection.d.ts +1 -1
  30. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -2
  31. package/dist/types-ts4.5/pm-plugins/utils/handle-bodied-sync-block-removal.d.ts +9 -0
  32. package/dist/types-ts4.5/pm-plugins/utils/track-sync-blocks.d.ts +2 -11
  33. package/dist/types-ts4.5/syncedBlockPluginType.d.ts +0 -4
  34. package/dist/types-ts4.5/types/index.d.ts +28 -2
  35. package/dist/types-ts4.5/ui/CreateSyncedBlockButton.d.ts +1 -1
  36. package/dist/types-ts4.5/ui/OverflowMenuSection.d.ts +1 -1
  37. package/package.json +7 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-synced-block
2
2
 
3
+ ## 4.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`433b512284284`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/433b512284284) -
8
+ [EDITOR-2558] Update bodiedSyncBlock deletion failure flow
9
+ - Updated dependencies
10
+
3
11
  ## 4.4.0
4
12
 
5
13
  ### Minor Changes
@@ -4,7 +4,8 @@
4
4
  "target": "es5",
5
5
  "outDir": "../../../../../confluence/tsDist/@atlaskit__editor-plugin-synced-block",
6
6
  "rootDir": "../",
7
- "composite": true
7
+ "composite": true,
8
+ "noCheck": true
8
9
  },
9
10
  "include": [
10
11
  "../src/**/*.ts",
@@ -4,7 +4,8 @@
4
4
  "target": "es5",
5
5
  "outDir": "../../../../../jira/tsDist/@atlaskit__editor-plugin-synced-block/app",
6
6
  "rootDir": "../",
7
- "composite": true
7
+ "composite": true,
8
+ "noCheck": true
8
9
  },
9
10
  "include": [
10
11
  "../src/**/*.ts",
@@ -4,7 +4,8 @@
4
4
  "target": "es5",
5
5
  "outDir": "../../../../../tsDist/@atlaskit__editor-plugin-synced-block/app",
6
6
  "rootDir": "../",
7
- "composite": true
7
+ "composite": true,
8
+ "noCheck": true
8
9
  },
9
10
  "include": [
10
11
  "../src/**/*.ts",
@@ -14,6 +14,7 @@ var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider
14
14
  var _bodiedLazySyncedBlock = require("../nodeviews/bodiedLazySyncedBlock");
15
15
  var _lazySyncedBlock = require("../nodeviews/lazySyncedBlock");
16
16
  var _types = require("../types");
17
+ var _handleBodiedSyncBlockRemoval = require("./utils/handle-bodied-sync-block-removal");
17
18
  var _ignoreDomEvent = require("./utils/ignore-dom-event");
18
19
  var _selectionDecorations = require("./utils/selection-decorations");
19
20
  var _trackSyncBlocks4 = require("./utils/track-sync-blocks");
@@ -25,7 +26,9 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
25
26
  var _ref = options || {},
26
27
  _ref$useLongPressSele = _ref.useLongPressSelection,
27
28
  useLongPressSelection = _ref$useLongPressSele === void 0 ? false : _ref$useLongPressSele;
28
- var confirmationTransaction;
29
+ var confirmationTransactionRef = {
30
+ current: undefined
31
+ };
29
32
  return new _safePlugin.SafePlugin({
30
33
  key: syncedBlockPluginKey,
31
34
  state: {
@@ -36,23 +39,25 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
36
39
  syncBlockStore.referenceManager.fetchSyncBlocksData((0, _editorSyncedBlockProvider.convertPMNodesToSyncBlockNodes)(syncBlockNodes));
37
40
  return {
38
41
  selectionDecorationSet: (0, _selectionDecorations.calculateDecorations)(instance.doc, instance.selection, instance.schema),
39
- showFlag: false,
42
+ activeFlag: false,
40
43
  syncBlockStore: syncBlockStore
41
44
  };
42
45
  },
43
46
  apply: function apply(tr, currentPluginState, oldEditorState) {
44
- var _meta$showFlag;
47
+ var _meta$activeFlag, _meta$bodiedSyncBlock;
45
48
  var meta = tr.getMeta(syncedBlockPluginKey);
46
- var showFlag = currentPluginState.showFlag,
47
- selectionDecorationSet = currentPluginState.selectionDecorationSet;
49
+ var activeFlag = currentPluginState.activeFlag,
50
+ selectionDecorationSet = currentPluginState.selectionDecorationSet,
51
+ bodiedSyncBlockDeletionStatus = currentPluginState.bodiedSyncBlockDeletionStatus;
48
52
  var newDecorationSet = selectionDecorationSet.map(tr.mapping, tr.doc);
49
53
  if (!tr.selection.eq(oldEditorState.selection)) {
50
54
  newDecorationSet = (0, _selectionDecorations.calculateDecorations)(tr.doc, tr.selection, tr.doc.type.schema);
51
55
  }
52
56
  return {
53
- showFlag: (_meta$showFlag = meta === null || meta === void 0 ? void 0 : meta.showFlag) !== null && _meta$showFlag !== void 0 ? _meta$showFlag : showFlag,
57
+ activeFlag: (_meta$activeFlag = meta === null || meta === void 0 ? void 0 : meta.activeFlag) !== null && _meta$activeFlag !== void 0 ? _meta$activeFlag : activeFlag,
54
58
  selectionDecorationSet: newDecorationSet,
55
- syncBlockStore: syncBlockStore
59
+ syncBlockStore: syncBlockStore,
60
+ bodiedSyncBlockDeletionStatus: (_meta$bodiedSyncBlock = meta === null || meta === void 0 ? void 0 : meta.bodiedSyncBlockDeletionStatus) !== null && _meta$bodiedSyncBlock !== void 0 ? _meta$bodiedSyncBlock : bodiedSyncBlockDeletionStatus
56
61
  };
57
62
  }
58
63
  },
@@ -121,28 +126,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
121
126
  bodiedSyncBlockAdded = _trackSyncBlocks.added;
122
127
  if (!isOffline) {
123
128
  if (bodiedSyncBlockRemoved.length > 0) {
124
- // If there are source sync blocks being removed, and we need to confirm with user before deleting,
125
- // we block the transaction here, and wait for user confirmation to proceed with deletion.
126
- // See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
127
- // proceed with deletion.
128
- confirmationTransaction = tr;
129
- syncBlockStore.sourceManager.deleteSyncBlocksWithConfirmation(bodiedSyncBlockRemoved.map(function (node) {
130
- return node.attrs;
131
- }), function () {
132
- var _api$core;
133
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function () {
134
- var trToDispatch = tr.setMeta('isConfirmedSyncBlockDeletion', true);
135
- if (!trToDispatch.getMeta(_utils.pmHistoryPluginKey)) {
136
- // bodiedSyncBlock deletion is expected to be permanent (cannot undo)
137
- // For a normal deletion (not triggered by undo), remove it from history so that it cannot be undone
138
- trToDispatch.setMeta('addToHistory', false);
139
- }
140
- return trToDispatch;
141
- });
142
- }).finally(function () {
143
- confirmationTransaction = undefined;
144
- });
145
- return false;
129
+ confirmationTransactionRef.current = tr;
130
+ return (0, _handleBodiedSyncBlockRemoval.handleBodiedSyncBlockRemoval)(tr, bodiedSyncBlockRemoved, syncBlockStore, api, confirmationTransactionRef);
146
131
  }
147
132
  if (bodiedSyncBlockAdded.length > 0) {
148
133
  if (Boolean(tr.getMeta(_utils.pmHistoryPluginKey))) {
@@ -156,8 +141,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
156
141
  // 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
157
142
  // The callback will be evoked by in SourceSyncBlockStoreManager.commitPendingCreation
158
143
  syncBlockStore.sourceManager.registerCreationCallback(function () {
159
- var _api$core2;
160
- api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function () {
144
+ var _api$core;
145
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function () {
161
146
  return tr.setMeta('isCommitSyncBlockCreation', true);
162
147
  });
163
148
  api === null || api === void 0 || api.core.actions.focus();
@@ -186,7 +171,9 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
186
171
  api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
187
172
  var tr = _ref2.tr;
188
173
  return tr.setMeta(syncedBlockPluginKey, {
189
- showFlag: errorFlag
174
+ activeFlag: {
175
+ id: errorFlag
176
+ }
190
177
  });
191
178
  });
192
179
  }, 0);
@@ -199,8 +186,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
199
186
  trs.filter(function (tr) {
200
187
  return tr.docChanged;
201
188
  }).forEach(function (tr) {
202
- if (confirmationTransaction) {
203
- confirmationTransaction = (0, _editorSyncedBlockProvider.rebaseTransaction)(confirmationTransaction, tr, newState);
189
+ if (confirmationTransactionRef.current) {
190
+ confirmationTransactionRef.current = (0, _editorSyncedBlockProvider.rebaseTransaction)(confirmationTransactionRef.current, tr, newState);
204
191
  }
205
192
  });
206
193
  var _iterator = _createForOfIteratorHelper(trs),
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.handleBodiedSyncBlockRemoval = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _utils = require("@atlaskit/editor-common/utils");
10
+ var _types = require("../../types");
11
+ var _main = require("../main");
12
+ 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; }
13
+ 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) { (0, _defineProperty2.default)(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; }
14
+ var onRetry = function onRetry(api, syncBlockStore) {
15
+ return function () {
16
+ var _api$core;
17
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref) {
18
+ var tr = _ref.tr;
19
+ return tr.setMeta(_main.syncedBlockPluginKey, {
20
+ bodiedSyncBlockDeletionStatus: 'processing',
21
+ activeFlag: false
22
+ });
23
+ });
24
+ syncBlockStore.sourceManager.retryDeletion();
25
+ };
26
+ };
27
+ var onDismissed = function onDismissed(syncBlockStore) {
28
+ return function (tr) {
29
+ syncBlockStore.sourceManager.clearPendingDeletion();
30
+ return tr.setMeta(_main.syncedBlockPluginKey, {
31
+ bodiedSyncBlockDeletionStatus: 'none'
32
+ });
33
+ };
34
+ };
35
+ var handleBodiedSyncBlockRemoval = exports.handleBodiedSyncBlockRemoval = function handleBodiedSyncBlockRemoval(tr, bodiedSyncBlockRemoved, syncBlockStore, api, confirmationTransactionRef) {
36
+ // Clear potential old pending deletion to retreat the deletion as first attempt
37
+ syncBlockStore.sourceManager.clearPendingDeletion();
38
+
39
+ // If there are source sync blocks being removed, and we need to confirm with user before deleting,
40
+ // we block the transaction here, and wait for user confirmation to proceed with deletion.
41
+ // See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
42
+ // proceed with deletion.
43
+ syncBlockStore.sourceManager.deleteSyncBlocksWithConfirmation(bodiedSyncBlockRemoved.map(function (node) {
44
+ return node.attrs;
45
+ }), function () {
46
+ var _api$core2;
47
+ var confirmationTransaction = confirmationTransactionRef.current;
48
+ if (!confirmationTransaction) {
49
+ return;
50
+ }
51
+ api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function () {
52
+ var trToDispatch = confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true);
53
+ if (!trToDispatch.getMeta(_utils.pmHistoryPluginKey)) {
54
+ // bodiedSyncBlock deletion is expected to be permanent (cannot undo)
55
+ // For a normal deletion (not triggered by undo), remove it from history so that it cannot be undone
56
+ trToDispatch.setMeta('addToHistory', false);
57
+ }
58
+ return trToDispatch;
59
+ });
60
+ }, function (success) {
61
+ var _api$core3;
62
+ api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref2) {
63
+ var tr = _ref2.tr;
64
+ var newState;
65
+ if (!success) {
66
+ newState = {
67
+ activeFlag: {
68
+ id: _types.FLAG_ID.FAIL_TO_DELETE,
69
+ onRetry: onRetry(api, syncBlockStore),
70
+ onDismissed: onDismissed(syncBlockStore)
71
+ }
72
+ };
73
+ }
74
+ newState = _objectSpread(_objectSpread({}, newState), {}, {
75
+ bodiedSyncBlockDeletionStatus: syncBlockStore.sourceManager.isRetryingDeletion() ?
76
+ // For retry, reset to none directly to clean up the status
77
+ 'none' :
78
+ // For the first attempt, set to completed for deletion modal can close the modal
79
+ 'completed'
80
+ });
81
+ return tr.setMeta(_main.syncedBlockPluginKey, newState);
82
+ });
83
+ }, function () {
84
+ confirmationTransactionRef.current = undefined;
85
+ });
86
+ return false;
87
+ };
@@ -113,11 +113,13 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
113
113
  return;
114
114
  }
115
115
  var _syncedBlockPluginKey = _main.syncedBlockPluginKey.getState(editorState),
116
- showFlag = _syncedBlockPluginKey.showFlag,
117
- currentSyncBlockStore = _syncedBlockPluginKey.syncBlockStore;
116
+ activeFlag = _syncedBlockPluginKey.activeFlag,
117
+ currentSyncBlockStore = _syncedBlockPluginKey.syncBlockStore,
118
+ bodiedSyncBlockDeletionStatus = _syncedBlockPluginKey.bodiedSyncBlockDeletionStatus;
118
119
  return {
119
- showFlag: showFlag,
120
- syncBlockStore: currentSyncBlockStore
120
+ activeFlag: activeFlag,
121
+ syncBlockStore: currentSyncBlockStore,
122
+ bodiedSyncBlockDeletionStatus: bodiedSyncBlockDeletionStatus
121
123
  };
122
124
  }
123
125
  };
@@ -8,5 +8,6 @@ var FLAG_ID = exports.FLAG_ID = /*#__PURE__*/function (FLAG_ID) {
8
8
  FLAG_ID["CANNOT_DELETE_WHEN_OFFLINE"] = "cannot-delete-when-offline";
9
9
  FLAG_ID["CANNOT_EDIT_WHEN_OFFLINE"] = "cannot-edit-when-offline";
10
10
  FLAG_ID["CANNOT_CREATE_WHEN_OFFLINE"] = "cannot-create-when-offline";
11
+ FLAG_ID["FAIL_TO_DELETE"] = "fail-to-delete";
11
12
  return FLAG_ID;
12
13
  }({});
@@ -14,8 +14,10 @@ var _hooks = require("@atlaskit/editor-common/hooks");
14
14
  var _messages = require("@atlaskit/editor-common/messages");
15
15
  var _modalDialog = _interopRequireWildcard(require("@atlaskit/modal-dialog"));
16
16
  var _compiled = require("@atlaskit/primitives/compiled");
17
+ var _main = require("../pm-plugins/main");
17
18
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
18
19
  var DeleteConfirmationModal = exports.DeleteConfirmationModal = function DeleteConfirmationModal(_ref) {
20
+ var _api$core2, _api$core4, _api$core6;
19
21
  var syncBlockStoreManager = _ref.syncBlockStoreManager,
20
22
  api = _ref.api;
21
23
  var _useState = (0, _react.useState)(false),
@@ -26,41 +28,79 @@ var DeleteConfirmationModal = exports.DeleteConfirmationModal = function DeleteC
26
28
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
27
29
  syncBlockCount = _useState4[0],
28
30
  setSyncBlockCount = _useState4[1];
29
- var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['connectivity'], function (states) {
30
- var _states$connectivityS;
31
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['connectivity', 'syncedBlock'], function (states) {
32
+ var _states$connectivityS, _states$syncedBlockSt, _states$syncedBlockSt2;
31
33
  return {
32
- mode: (_states$connectivityS = states.connectivityState) === null || _states$connectivityS === void 0 ? void 0 : _states$connectivityS.mode
34
+ mode: (_states$connectivityS = states.connectivityState) === null || _states$connectivityS === void 0 ? void 0 : _states$connectivityS.mode,
35
+ bodiedSyncBlockDeletionStatus: (_states$syncedBlockSt = states.syncedBlockState) === null || _states$syncedBlockSt === void 0 ? void 0 : _states$syncedBlockSt.bodiedSyncBlockDeletionStatus,
36
+ activeFlag: (_states$syncedBlockSt2 = states.syncedBlockState) === null || _states$syncedBlockSt2 === void 0 ? void 0 : _states$syncedBlockSt2.activeFlag
33
37
  };
34
38
  }),
35
- mode = _useSharedPluginState.mode;
39
+ mode = _useSharedPluginState.mode,
40
+ bodiedSyncBlockDeletionStatus = _useSharedPluginState.bodiedSyncBlockDeletionStatus,
41
+ activeFlag = _useSharedPluginState.activeFlag;
36
42
  var _useIntl = (0, _reactIntlNext.useIntl)(),
37
43
  formatMessage = _useIntl.formatMessage;
38
44
  var resolverRef = _react.default.useRef(undefined);
39
- var handleClose = (0, _react.useCallback)(function (confirm) {
45
+ var handleClick = (0, _react.useCallback)(function (confirm) {
40
46
  return function () {
47
+ var _api$core;
41
48
  if (resolverRef.current) {
42
49
  resolverRef.current(confirm);
43
50
  resolverRef.current = undefined;
44
51
  }
45
- setIsOpen(false);
52
+ if (!confirm) {
53
+ setIsOpen(false);
54
+ }
55
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
56
+ var tr = _ref2.tr;
57
+ return tr.setMeta(_main.syncedBlockPluginKey, {
58
+ bodiedSyncBlockDeletionStatus: confirm ? 'processing' : 'none',
59
+ activeFlag: false
60
+ });
61
+ });
46
62
  };
47
- }, []);
63
+ }, [api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions]);
48
64
  var confirmationCallback = (0, _react.useCallback)(function (syncBlockCount) {
49
65
  setIsOpen(true);
50
66
  setSyncBlockCount(syncBlockCount);
51
67
  var confirmedPromise = new Promise(function (resolve) {
52
68
  resolverRef.current = resolve;
53
69
  });
70
+ if (activeFlag) {
71
+ var _api$core3;
72
+ api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref3) {
73
+ var tr = _ref3.tr;
74
+ return tr.setMeta(_main.syncedBlockPluginKey, {
75
+ // Clear flag to avoid potential retry deletion of different blocks
76
+ activeFlag: false
77
+ });
78
+ });
79
+ }
54
80
  return confirmedPromise;
55
- }, []);
81
+ }, [activeFlag, api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions]);
56
82
  (0, _react.useEffect)(function () {
57
83
  var unregister = syncBlockStoreManager.sourceManager.registerConfirmationCallback(confirmationCallback);
58
84
  return function () {
59
85
  unregister();
60
86
  };
61
87
  }, [syncBlockStoreManager, confirmationCallback]);
88
+ (0, _react.useEffect)(function () {
89
+ if (bodiedSyncBlockDeletionStatus === 'completed' && isOpen) {
90
+ var _api$core5;
91
+ // auto close modal once deletion is successful
92
+ setIsOpen(false);
93
+ api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref4) {
94
+ var tr = _ref4.tr;
95
+ return tr.setMeta(_main.syncedBlockPluginKey, {
96
+ // Reset deletion status to have a clean state for next deletion
97
+ bodiedSyncBlockDeletionStatus: 'none'
98
+ });
99
+ });
100
+ }
101
+ }, [api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions, bodiedSyncBlockDeletionStatus, isOpen]);
62
102
  return /*#__PURE__*/_react.default.createElement(_modalDialog.ModalTransition, null, isOpen && /*#__PURE__*/_react.default.createElement(_modalDialog.default, {
63
- onClose: handleClose(false),
103
+ onClose: handleClick(false),
64
104
  testId: "sync-block-delete-confirmation"
65
105
  }, /*#__PURE__*/_react.default.createElement(_modalDialog.ModalHeader, {
66
106
  hasCloseButton: true
@@ -70,11 +110,12 @@ var DeleteConfirmationModal = exports.DeleteConfirmationModal = function DeleteC
70
110
  syncBlockCount: syncBlockCount
71
111
  }))), /*#__PURE__*/_react.default.createElement(_modalDialog.ModalFooter, null, /*#__PURE__*/_react.default.createElement(_new.default, {
72
112
  appearance: "subtle",
73
- onClick: handleClose(false)
113
+ onClick: handleClick(false)
74
114
  }, formatMessage(_messages.syncBlockMessages.deleteConfirmationModalCancelButton)), /*#__PURE__*/_react.default.createElement(_new.default, {
75
115
  appearance: "warning",
76
- onClick: handleClose(true),
116
+ onClick: handleClick(true),
77
117
  autoFocus: true,
78
- isDisabled: mode === 'offline'
118
+ isDisabled: mode === 'offline',
119
+ isLoading: bodiedSyncBlockDeletionStatus === 'processing'
79
120
  }, formatMessage(_messages.syncBlockMessages.deleteConfirmationModalDeleteButton)))));
80
121
  };
@@ -12,11 +12,13 @@ var _reactIntlNext = require("react-intl-next");
12
12
  var _hooks = require("@atlaskit/editor-common/hooks");
13
13
  var _messages = require("@atlaskit/editor-common/messages");
14
14
  var _flag = _interopRequireWildcard(require("@atlaskit/flag"));
15
- var _statusError = _interopRequireDefault(require("@atlaskit/icon/core/status-error"));
15
+ var _statusWarning = _interopRequireDefault(require("@atlaskit/icon/core/status-warning"));
16
16
  var _main = require("../pm-plugins/main");
17
17
  var _types = require("../types");
18
18
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
19
- var flagMap = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _types.FLAG_ID.CANNOT_DELETE_WHEN_OFFLINE, {
19
+ 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; }
20
+ 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) { (0, _defineProperty2.default)(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; }
21
+ var flagMap = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _types.FLAG_ID.CANNOT_DELETE_WHEN_OFFLINE, {
20
22
  title: _messages.syncBlockMessages.failToDeleteTitle,
21
23
  description: _messages.syncBlockMessages.failToDeleteWhenOfflineDescription
22
24
  }), _types.FLAG_ID.CANNOT_EDIT_WHEN_OFFLINE, {
@@ -25,43 +27,68 @@ var flagMap = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _d
25
27
  }), _types.FLAG_ID.CANNOT_CREATE_WHEN_OFFLINE, {
26
28
  title: _messages.syncBlockMessages.failToCreateTitle,
27
29
  description: _messages.syncBlockMessages.failToCreateWhenOfflineDescription
30
+ }), _types.FLAG_ID.FAIL_TO_DELETE, {
31
+ title: _messages.syncBlockMessages.cannotDeleteTitle,
32
+ description: _messages.syncBlockMessages.cannotDeleteDescription
28
33
  });
29
34
  var Flag = exports.Flag = function Flag(_ref) {
30
35
  var api = _ref.api;
31
- var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['syncedBlock'], function (states) {
32
- var _states$syncedBlockSt;
36
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['syncedBlock', 'connectivity'], function (states) {
37
+ var _states$syncedBlockSt, _states$connectivityS;
33
38
  return {
34
- showFlag: (_states$syncedBlockSt = states.syncedBlockState) === null || _states$syncedBlockSt === void 0 ? void 0 : _states$syncedBlockSt.showFlag
39
+ activeFlag: (_states$syncedBlockSt = states.syncedBlockState) === null || _states$syncedBlockSt === void 0 ? void 0 : _states$syncedBlockSt.activeFlag,
40
+ mode: (_states$connectivityS = states.connectivityState) === null || _states$connectivityS === void 0 ? void 0 : _states$connectivityS.mode
35
41
  };
36
42
  }),
37
- showFlag = _useSharedPluginState.showFlag;
43
+ activeFlag = _useSharedPluginState.activeFlag,
44
+ mode = _useSharedPluginState.mode;
38
45
  var _useIntl = (0, _reactIntlNext.useIntl)(),
39
46
  formatMessage = _useIntl.formatMessage;
40
- if (!showFlag) {
47
+ if (!activeFlag) {
41
48
  return;
42
49
  }
43
- var _flagMap$showFlag = flagMap[showFlag],
44
- title = _flagMap$showFlag.title,
45
- description = _flagMap$showFlag.description;
46
- var onDismissed = function onDismissed() {
50
+ var _flagMap$activeFlag$i = flagMap[activeFlag.id],
51
+ title = _flagMap$activeFlag$i.title,
52
+ description = _flagMap$activeFlag$i.description;
53
+ var onRetry = activeFlag.onRetry,
54
+ onDismissedCallback = activeFlag.onDismissed;
55
+
56
+ // Retry button often involves network request, hence we dismiss the flag in offline mode to avoid retry
57
+ if (mode === 'offline' && !!onRetry) {
47
58
  api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
48
59
  var tr = _ref2.tr;
49
60
  tr.setMeta(_main.syncedBlockPluginKey, {
50
- showFlag: false
61
+ activeFlag: false
51
62
  });
52
63
  return tr;
53
64
  });
65
+ return;
66
+ }
67
+ var onDismissed = function onDismissed() {
68
+ api === null || api === void 0 || api.core.actions.execute(function (_ref3) {
69
+ var tr = _ref3.tr;
70
+ onDismissedCallback === null || onDismissedCallback === void 0 || onDismissedCallback(tr);
71
+ var oldMeta = tr.getMeta(_main.syncedBlockPluginKey);
72
+ tr.setMeta(_main.syncedBlockPluginKey, _objectSpread(_objectSpread({}, oldMeta), {}, {
73
+ activeFlag: false
74
+ }));
75
+ return tr;
76
+ });
54
77
  api === null || api === void 0 || api.core.actions.focus();
55
78
  };
56
79
  return /*#__PURE__*/_react.default.createElement(_flag.FlagGroup, null, /*#__PURE__*/_react.default.createElement(_flag.default, {
57
80
  onDismissed: onDismissed,
58
81
  title: formatMessage(title),
59
82
  description: formatMessage(description),
60
- id: showFlag,
61
- testId: showFlag,
62
- icon: /*#__PURE__*/_react.default.createElement(_statusError.default, {
83
+ id: activeFlag.id,
84
+ testId: activeFlag.id,
85
+ icon: /*#__PURE__*/_react.default.createElement(_statusWarning.default, {
63
86
  label: "",
64
- color: "var(--ds-icon-danger, #C9372C)"
65
- })
87
+ color: "var(--ds-icon-warning, #E06C00)"
88
+ }),
89
+ actions: onRetry ? [{
90
+ content: formatMessage(_messages.syncBlockMessages.deleteRetryButton),
91
+ onClick: onRetry
92
+ }] : undefined
66
93
  }));
67
94
  };
@@ -8,6 +8,7 @@ import { convertPMNodesToSyncBlockNodes, rebaseTransaction } from '@atlaskit/edi
8
8
  import { lazyBodiedSyncBlockView } from '../nodeviews/bodiedLazySyncedBlock';
9
9
  import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
10
10
  import { FLAG_ID } from '../types';
11
+ import { handleBodiedSyncBlockRemoval } from './utils/handle-bodied-sync-block-removal';
11
12
  import { shouldIgnoreDomEvent } from './utils/ignore-dom-event';
12
13
  import { calculateDecorations } from './utils/selection-decorations';
13
14
  import { hasEditInSyncBlock, trackSyncBlocks } from './utils/track-sync-blocks';
@@ -16,7 +17,9 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
16
17
  const {
17
18
  useLongPressSelection = false
18
19
  } = options || {};
19
- let confirmationTransaction;
20
+ const confirmationTransactionRef = {
21
+ current: undefined
22
+ };
20
23
  return new SafePlugin({
21
24
  key: syncedBlockPluginKey,
22
25
  state: {
@@ -25,25 +28,27 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
25
28
  syncBlockStore.referenceManager.fetchSyncBlocksData(convertPMNodesToSyncBlockNodes(syncBlockNodes));
26
29
  return {
27
30
  selectionDecorationSet: calculateDecorations(instance.doc, instance.selection, instance.schema),
28
- showFlag: false,
31
+ activeFlag: false,
29
32
  syncBlockStore: syncBlockStore
30
33
  };
31
34
  },
32
35
  apply: (tr, currentPluginState, oldEditorState) => {
33
- var _meta$showFlag;
36
+ var _meta$activeFlag, _meta$bodiedSyncBlock;
34
37
  const meta = tr.getMeta(syncedBlockPluginKey);
35
38
  const {
36
- showFlag,
37
- selectionDecorationSet
39
+ activeFlag,
40
+ selectionDecorationSet,
41
+ bodiedSyncBlockDeletionStatus
38
42
  } = currentPluginState;
39
43
  let newDecorationSet = selectionDecorationSet.map(tr.mapping, tr.doc);
40
44
  if (!tr.selection.eq(oldEditorState.selection)) {
41
45
  newDecorationSet = calculateDecorations(tr.doc, tr.selection, tr.doc.type.schema);
42
46
  }
43
47
  return {
44
- showFlag: (_meta$showFlag = meta === null || meta === void 0 ? void 0 : meta.showFlag) !== null && _meta$showFlag !== void 0 ? _meta$showFlag : showFlag,
48
+ activeFlag: (_meta$activeFlag = meta === null || meta === void 0 ? void 0 : meta.activeFlag) !== null && _meta$activeFlag !== void 0 ? _meta$activeFlag : activeFlag,
45
49
  selectionDecorationSet: newDecorationSet,
46
- syncBlockStore: syncBlockStore
50
+ syncBlockStore: syncBlockStore,
51
+ bodiedSyncBlockDeletionStatus: (_meta$bodiedSyncBlock = meta === null || meta === void 0 ? void 0 : meta.bodiedSyncBlockDeletionStatus) !== null && _meta$bodiedSyncBlock !== void 0 ? _meta$bodiedSyncBlock : bodiedSyncBlockDeletionStatus
47
52
  };
48
53
  }
49
54
  },
@@ -113,26 +118,8 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
113
118
  } = trackSyncBlocks(syncBlockStore.sourceManager.isSourceBlock, tr, state);
114
119
  if (!isOffline) {
115
120
  if (bodiedSyncBlockRemoved.length > 0) {
116
- // If there are source sync blocks being removed, and we need to confirm with user before deleting,
117
- // we block the transaction here, and wait for user confirmation to proceed with deletion.
118
- // See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
119
- // proceed with deletion.
120
- confirmationTransaction = tr;
121
- syncBlockStore.sourceManager.deleteSyncBlocksWithConfirmation(bodiedSyncBlockRemoved.map(node => node.attrs), () => {
122
- var _api$core;
123
- api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(() => {
124
- const trToDispatch = tr.setMeta('isConfirmedSyncBlockDeletion', true);
125
- if (!trToDispatch.getMeta(pmHistoryPluginKey)) {
126
- // bodiedSyncBlock deletion is expected to be permanent (cannot undo)
127
- // For a normal deletion (not triggered by undo), remove it from history so that it cannot be undone
128
- trToDispatch.setMeta('addToHistory', false);
129
- }
130
- return trToDispatch;
131
- });
132
- }).finally(() => {
133
- confirmationTransaction = undefined;
134
- });
135
- return false;
121
+ confirmationTransactionRef.current = tr;
122
+ return handleBodiedSyncBlockRemoval(tr, bodiedSyncBlockRemoved, syncBlockStore, api, confirmationTransactionRef);
136
123
  }
137
124
  if (bodiedSyncBlockAdded.length > 0) {
138
125
  if (Boolean(tr.getMeta(pmHistoryPluginKey))) {
@@ -146,8 +133,8 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
146
133
  // 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
147
134
  // The callback will be evoked by in SourceSyncBlockStoreManager.commitPendingCreation
148
135
  syncBlockStore.sourceManager.registerCreationCallback(() => {
149
- var _api$core2;
150
- api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(() => {
136
+ var _api$core;
137
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(() => {
151
138
  return tr.setMeta('isCommitSyncBlockCreation', true);
152
139
  });
153
140
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
@@ -176,7 +163,9 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
176
163
  tr
177
164
  }) => {
178
165
  return tr.setMeta(syncedBlockPluginKey, {
179
- showFlag: errorFlag
166
+ activeFlag: {
167
+ id: errorFlag
168
+ }
180
169
  });
181
170
  });
182
171
  }, 0);
@@ -187,8 +176,8 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
187
176
  },
188
177
  appendTransaction: (trs, oldState, newState) => {
189
178
  trs.filter(tr => tr.docChanged).forEach(tr => {
190
- if (confirmationTransaction) {
191
- confirmationTransaction = rebaseTransaction(confirmationTransaction, tr, newState);
179
+ if (confirmationTransactionRef.current) {
180
+ confirmationTransactionRef.current = rebaseTransaction(confirmationTransactionRef.current, tr, newState);
192
181
  }
193
182
  });
194
183
  for (const tr of trs) {