@atlaskit/editor-plugin-synced-block 4.3.15 → 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 (45) hide show
  1. package/CHANGELOG.md +20 -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/editor-commands/index.js +14 -10
  6. package/dist/cjs/pm-plugins/main.js +21 -34
  7. package/dist/cjs/pm-plugins/utils/handle-bodied-sync-block-removal.js +87 -0
  8. package/dist/cjs/syncedBlockPlugin.js +7 -5
  9. package/dist/cjs/types/index.js +1 -0
  10. package/dist/cjs/ui/DeleteConfirmationModal.js +53 -12
  11. package/dist/cjs/ui/Flag.js +44 -17
  12. package/dist/cjs/ui/floating-toolbar.js +1 -1
  13. package/dist/es2019/editor-commands/index.js +6 -6
  14. package/dist/es2019/pm-plugins/main.js +21 -32
  15. package/dist/es2019/pm-plugins/utils/handle-bodied-sync-block-removal.js +74 -0
  16. package/dist/es2019/syncedBlockPlugin.js +7 -5
  17. package/dist/es2019/types/index.js +1 -0
  18. package/dist/es2019/ui/DeleteConfirmationModal.js +56 -12
  19. package/dist/es2019/ui/Flag.js +43 -13
  20. package/dist/es2019/ui/floating-toolbar.js +1 -1
  21. package/dist/esm/editor-commands/index.js +14 -10
  22. package/dist/esm/pm-plugins/main.js +21 -34
  23. package/dist/esm/pm-plugins/utils/handle-bodied-sync-block-removal.js +80 -0
  24. package/dist/esm/syncedBlockPlugin.js +7 -5
  25. package/dist/esm/types/index.js +1 -0
  26. package/dist/esm/ui/DeleteConfirmationModal.js +53 -12
  27. package/dist/esm/ui/Flag.js +44 -17
  28. package/dist/esm/ui/floating-toolbar.js +1 -1
  29. package/dist/types/editor-commands/index.d.ts +2 -2
  30. package/dist/types/pm-plugins/main.d.ts +3 -2
  31. package/dist/types/pm-plugins/utils/handle-bodied-sync-block-removal.d.ts +9 -0
  32. package/dist/types/pm-plugins/utils/track-sync-blocks.d.ts +2 -11
  33. package/dist/types/syncedBlockPluginType.d.ts +0 -4
  34. package/dist/types/types/index.d.ts +28 -2
  35. package/dist/types/ui/CreateSyncedBlockButton.d.ts +1 -1
  36. package/dist/types/ui/OverflowMenuSection.d.ts +1 -1
  37. package/dist/types-ts4.5/editor-commands/index.d.ts +2 -2
  38. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -2
  39. package/dist/types-ts4.5/pm-plugins/utils/handle-bodied-sync-block-removal.d.ts +9 -0
  40. package/dist/types-ts4.5/pm-plugins/utils/track-sync-blocks.d.ts +2 -11
  41. package/dist/types-ts4.5/syncedBlockPluginType.d.ts +0 -4
  42. package/dist/types-ts4.5/types/index.d.ts +28 -2
  43. package/dist/types-ts4.5/ui/CreateSyncedBlockButton.d.ts +1 -1
  44. package/dist/types-ts4.5/ui/OverflowMenuSection.d.ts +1 -1
  45. package/package.json +7 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
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
+
11
+ ## 4.4.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [`676d28a61e356`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/676d28a61e356) -
16
+ Add runtime blockAri generation for endpoint calls, update resourceId generation for create
17
+ reference from toolbar
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies
22
+
3
23
  ## 4.3.15
4
24
 
5
25
  ### Patch 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",
@@ -59,17 +59,21 @@ var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(_
59
59
  // see filterTransaction for more details
60
60
  return tr;
61
61
  };
62
- var copySyncedBlockReferenceToClipboardEditorCommand = exports.copySyncedBlockReferenceToClipboardEditorCommand = function copySyncedBlockReferenceToClipboardEditorCommand(_ref2) {
63
- var tr = _ref2.tr;
64
- if (copySyncedBlockReferenceToClipboardInternal(tr.doc.type.schema, tr.selection)) {
65
- return tr;
66
- }
67
- return null;
62
+ var copySyncedBlockReferenceToClipboardEditorCommand = exports.copySyncedBlockReferenceToClipboardEditorCommand = function copySyncedBlockReferenceToClipboardEditorCommand(syncBlockStore) {
63
+ return function (_ref2) {
64
+ var tr = _ref2.tr;
65
+ if (copySyncedBlockReferenceToClipboardInternal(tr.doc.type.schema, tr.selection, syncBlockStore)) {
66
+ return tr;
67
+ }
68
+ return null;
69
+ };
68
70
  };
69
- var copySyncedBlockReferenceToClipboard = exports.copySyncedBlockReferenceToClipboard = function copySyncedBlockReferenceToClipboard(state, _dispatch, _view) {
70
- return copySyncedBlockReferenceToClipboardInternal(state.tr.doc.type.schema, state.tr.selection);
71
+ var copySyncedBlockReferenceToClipboard = exports.copySyncedBlockReferenceToClipboard = function copySyncedBlockReferenceToClipboard(syncBlockStore) {
72
+ return function (state, _dispatch, _view) {
73
+ return copySyncedBlockReferenceToClipboardInternal(state.tr.doc.type.schema, state.tr.selection, syncBlockStore);
74
+ };
71
75
  };
72
- var copySyncedBlockReferenceToClipboardInternal = function copySyncedBlockReferenceToClipboardInternal(schema, selection) {
76
+ var copySyncedBlockReferenceToClipboardInternal = function copySyncedBlockReferenceToClipboardInternal(schema, selection, syncBlockStore) {
73
77
  var syncBlockFindResult = (0, _utils2.findSyncBlockOrBodiedSyncBlock)(schema, selection);
74
78
  if (!syncBlockFindResult) {
75
79
  return false;
@@ -81,7 +85,7 @@ var copySyncedBlockReferenceToClipboardInternal = function copySyncedBlockRefere
81
85
 
82
86
  // create sync block reference node
83
87
  referenceSyncBlockNode = syncBlock.createAndFill({
84
- resourceId: syncBlockFindResult.node.attrs.resourceId
88
+ resourceId: syncBlockStore.referenceManager.generateResourceIdForReference(syncBlockFindResult.node.attrs.resourceId)
85
89
  });
86
90
  if (!referenceSyncBlockNode) {
87
91
  return false;
@@ -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
+ };
@@ -48,7 +48,7 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
48
48
  },
49
49
  commands: {
50
50
  copySyncedBlockReferenceToClipboard: function copySyncedBlockReferenceToClipboard() {
51
- return _editorCommands.copySyncedBlockReferenceToClipboardEditorCommand;
51
+ return (0, _editorCommands.copySyncedBlockReferenceToClipboardEditorCommand)(syncBlockStore);
52
52
  },
53
53
  insertSyncedBlock: function insertSyncedBlock() {
54
54
  return function (_ref2) {
@@ -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
  };
@@ -47,7 +47,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(stat
47
47
  title: formatMessage(_messages.syncBlockMessages.copySyncBlockLabel),
48
48
  showTitle: false,
49
49
  tooltipContent: formatMessage(_messages.syncBlockMessages.copySyncBlockTooltip),
50
- onClick: _editorCommands.copySyncedBlockReferenceToClipboard
50
+ onClick: (0, _editorCommands.copySyncedBlockReferenceToClipboard)(syncBlockStore)
51
51
  }, hoverDecorationProps(nodeType, _consts.akEditorSelectedNodeClassName));
52
52
  items.push(copyButton);
53
53
  var disabled = !syncBlockStore.referenceManager.getSyncBlockURL(syncBlockObject.node.attrs.resourceId);
@@ -59,18 +59,18 @@ export const createSyncedBlock = ({
59
59
  // see filterTransaction for more details
60
60
  return tr;
61
61
  };
62
- export const copySyncedBlockReferenceToClipboardEditorCommand = ({
62
+ export const copySyncedBlockReferenceToClipboardEditorCommand = syncBlockStore => ({
63
63
  tr
64
64
  }) => {
65
- if (copySyncedBlockReferenceToClipboardInternal(tr.doc.type.schema, tr.selection)) {
65
+ if (copySyncedBlockReferenceToClipboardInternal(tr.doc.type.schema, tr.selection, syncBlockStore)) {
66
66
  return tr;
67
67
  }
68
68
  return null;
69
69
  };
70
- export const copySyncedBlockReferenceToClipboard = (state, _dispatch, _view) => {
71
- return copySyncedBlockReferenceToClipboardInternal(state.tr.doc.type.schema, state.tr.selection);
70
+ export const copySyncedBlockReferenceToClipboard = syncBlockStore => (state, _dispatch, _view) => {
71
+ return copySyncedBlockReferenceToClipboardInternal(state.tr.doc.type.schema, state.tr.selection, syncBlockStore);
72
72
  };
73
- const copySyncedBlockReferenceToClipboardInternal = (schema, selection) => {
73
+ const copySyncedBlockReferenceToClipboardInternal = (schema, selection, syncBlockStore) => {
74
74
  const syncBlockFindResult = findSyncBlockOrBodiedSyncBlock(schema, selection);
75
75
  if (!syncBlockFindResult) {
76
76
  return false;
@@ -86,7 +86,7 @@ const copySyncedBlockReferenceToClipboardInternal = (schema, selection) => {
86
86
 
87
87
  // create sync block reference node
88
88
  referenceSyncBlockNode = syncBlock.createAndFill({
89
- resourceId: syncBlockFindResult.node.attrs.resourceId
89
+ resourceId: syncBlockStore.referenceManager.generateResourceIdForReference(syncBlockFindResult.node.attrs.resourceId)
90
90
  });
91
91
  if (!referenceSyncBlockNode) {
92
92
  return false;