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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +22 -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/nodeviews/syncedBlock.js +2 -1
  6. package/dist/cjs/pm-plugins/main.js +57 -36
  7. package/dist/cjs/pm-plugins/utils/handle-bodied-sync-block-removal.js +87 -0
  8. package/dist/cjs/syncedBlockPlugin.js +6 -4
  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/SyncBlockRendererWrapper.js +4 -2
  13. package/dist/es2019/nodeviews/syncedBlock.js +2 -1
  14. package/dist/es2019/pm-plugins/main.js +56 -33
  15. package/dist/es2019/pm-plugins/utils/handle-bodied-sync-block-removal.js +74 -0
  16. package/dist/es2019/syncedBlockPlugin.js +6 -4
  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/SyncBlockRendererWrapper.js +4 -2
  21. package/dist/esm/nodeviews/syncedBlock.js +2 -1
  22. package/dist/esm/pm-plugins/main.js +57 -37
  23. package/dist/esm/pm-plugins/utils/handle-bodied-sync-block-removal.js +80 -0
  24. package/dist/esm/syncedBlockPlugin.js +6 -4
  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/SyncBlockRendererWrapper.js +4 -2
  29. package/dist/types/pm-plugins/main.d.ts +3 -2
  30. package/dist/types/pm-plugins/utils/handle-bodied-sync-block-removal.d.ts +9 -0
  31. package/dist/types/pm-plugins/utils/track-sync-blocks.d.ts +2 -11
  32. package/dist/types/syncedBlockPluginType.d.ts +2 -5
  33. package/dist/types/types/index.d.ts +28 -2
  34. package/dist/types/ui/CreateSyncedBlockButton.d.ts +1 -1
  35. package/dist/types/ui/OverflowMenuSection.d.ts +1 -1
  36. package/dist/types/ui/SyncBlockRendererWrapper.d.ts +5 -3
  37. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -2
  38. package/dist/types-ts4.5/pm-plugins/utils/handle-bodied-sync-block-removal.d.ts +9 -0
  39. package/dist/types-ts4.5/pm-plugins/utils/track-sync-blocks.d.ts +2 -11
  40. package/dist/types-ts4.5/syncedBlockPluginType.d.ts +2 -5
  41. package/dist/types-ts4.5/types/index.d.ts +28 -2
  42. package/dist/types-ts4.5/ui/CreateSyncedBlockButton.d.ts +1 -1
  43. package/dist/types-ts4.5/ui/OverflowMenuSection.d.ts +1 -1
  44. package/dist/types-ts4.5/ui/SyncBlockRendererWrapper.d.ts +5 -3
  45. package/package.json +7 -7
@@ -1,16 +1,20 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
2
  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; } } }; }
2
3
  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; } }
3
4
  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; }
4
7
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
8
  import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
6
9
  import { BodiedSyncBlockSharedCssClassName, SyncBlockStateCssClassName } from '@atlaskit/editor-common/sync-block';
7
- import { pmHistoryPluginKey } from '@atlaskit/editor-common/utils';
10
+ import { mapSlice, pmHistoryPluginKey } from '@atlaskit/editor-common/utils';
8
11
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
9
12
  import { DecorationSet, Decoration } from '@atlaskit/editor-prosemirror/view';
10
13
  import { convertPMNodesToSyncBlockNodes, rebaseTransaction } from '@atlaskit/editor-synced-block-provider';
11
14
  import { lazyBodiedSyncBlockView } from '../nodeviews/bodiedLazySyncedBlock';
12
15
  import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
13
16
  import { FLAG_ID } from '../types';
17
+ import { handleBodiedSyncBlockRemoval } from './utils/handle-bodied-sync-block-removal';
14
18
  import { shouldIgnoreDomEvent } from './utils/ignore-dom-event';
15
19
  import { calculateDecorations } from './utils/selection-decorations';
16
20
  import { hasEditInSyncBlock, trackSyncBlocks } from './utils/track-sync-blocks';
@@ -19,7 +23,9 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
19
23
  var _ref = options || {},
20
24
  _ref$useLongPressSele = _ref.useLongPressSelection,
21
25
  useLongPressSelection = _ref$useLongPressSele === void 0 ? false : _ref$useLongPressSele;
22
- var confirmationTransaction;
26
+ var confirmationTransactionRef = {
27
+ current: undefined
28
+ };
23
29
  return new SafePlugin({
24
30
  key: syncedBlockPluginKey,
25
31
  state: {
@@ -30,23 +36,25 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
30
36
  syncBlockStore.referenceManager.fetchSyncBlocksData(convertPMNodesToSyncBlockNodes(syncBlockNodes));
31
37
  return {
32
38
  selectionDecorationSet: calculateDecorations(instance.doc, instance.selection, instance.schema),
33
- showFlag: false,
39
+ activeFlag: false,
34
40
  syncBlockStore: syncBlockStore
35
41
  };
36
42
  },
37
43
  apply: function apply(tr, currentPluginState, oldEditorState) {
38
- var _meta$showFlag;
44
+ var _meta$activeFlag, _meta$bodiedSyncBlock;
39
45
  var meta = tr.getMeta(syncedBlockPluginKey);
40
- var showFlag = currentPluginState.showFlag,
41
- selectionDecorationSet = currentPluginState.selectionDecorationSet;
46
+ var activeFlag = currentPluginState.activeFlag,
47
+ selectionDecorationSet = currentPluginState.selectionDecorationSet,
48
+ bodiedSyncBlockDeletionStatus = currentPluginState.bodiedSyncBlockDeletionStatus;
42
49
  var newDecorationSet = selectionDecorationSet.map(tr.mapping, tr.doc);
43
50
  if (!tr.selection.eq(oldEditorState.selection)) {
44
51
  newDecorationSet = calculateDecorations(tr.doc, tr.selection, tr.doc.type.schema);
45
52
  }
46
53
  return {
47
- showFlag: (_meta$showFlag = meta === null || meta === void 0 ? void 0 : meta.showFlag) !== null && _meta$showFlag !== void 0 ? _meta$showFlag : showFlag,
54
+ activeFlag: (_meta$activeFlag = meta === null || meta === void 0 ? void 0 : meta.activeFlag) !== null && _meta$activeFlag !== void 0 ? _meta$activeFlag : activeFlag,
48
55
  selectionDecorationSet: newDecorationSet,
49
- syncBlockStore: syncBlockStore
56
+ syncBlockStore: syncBlockStore,
57
+ bodiedSyncBlockDeletionStatus: (_meta$bodiedSyncBlock = meta === null || meta === void 0 ? void 0 : meta.bodiedSyncBlockDeletionStatus) !== null && _meta$bodiedSyncBlock !== void 0 ? _meta$bodiedSyncBlock : bodiedSyncBlockDeletionStatus
50
58
  };
51
59
  }
52
60
  },
@@ -97,6 +105,36 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
97
105
  mousedown: function mousedown(view, event) {
98
106
  return shouldIgnoreDomEvent(view, event, api);
99
107
  }
108
+ },
109
+ transformCopied: function transformCopied(slice, _ref2) {
110
+ var state = _ref2.state;
111
+ var pluginState = syncedBlockPluginKey.getState(state);
112
+ var syncBlockStore = pluginState === null || pluginState === void 0 ? void 0 : pluginState.syncBlockStore;
113
+ var schema = state.schema;
114
+ if (!syncBlockStore) {
115
+ return slice;
116
+ }
117
+ return mapSlice(slice, function (node) {
118
+ if (node.type.name === 'bodiedSyncBlock' && node.attrs.resourceId) {
119
+ try {
120
+ var newResourceId = syncBlockStore.referenceManager.generateResourceIdForReference(node.attrs.resourceId);
121
+ // Convert bodiedSyncBlock to syncBlock
122
+ // The paste transformation will regenrate the localId
123
+ var newAttrs = _objectSpread(_objectSpread({}, node.attrs), {}, {
124
+ resourceId: newResourceId
125
+ });
126
+ var newMarks = schema.nodes.syncBlock.markSet ? node.marks.filter(function (mark) {
127
+ var _schema$nodes$syncBlo;
128
+ return (_schema$nodes$syncBlo = schema.nodes.syncBlock.markSet) === null || _schema$nodes$syncBlo === void 0 ? void 0 : _schema$nodes$syncBlo.includes(mark.type);
129
+ }) : node.marks;
130
+ return schema.nodes.syncBlock.create(newAttrs, null, newMarks);
131
+ } catch (error) {
132
+ // If generateResourceIdForReference died, return the original node
133
+ return node;
134
+ }
135
+ }
136
+ return node;
137
+ });
100
138
  }
101
139
  },
102
140
  filterTransaction: function filterTransaction(tr, state) {
@@ -115,28 +153,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
115
153
  bodiedSyncBlockAdded = _trackSyncBlocks.added;
116
154
  if (!isOffline) {
117
155
  if (bodiedSyncBlockRemoved.length > 0) {
118
- // If there are source sync blocks being removed, and we need to confirm with user before deleting,
119
- // we block the transaction here, and wait for user confirmation to proceed with deletion.
120
- // See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
121
- // proceed with deletion.
122
- confirmationTransaction = tr;
123
- syncBlockStore.sourceManager.deleteSyncBlocksWithConfirmation(bodiedSyncBlockRemoved.map(function (node) {
124
- return node.attrs;
125
- }), function () {
126
- var _api$core;
127
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function () {
128
- var trToDispatch = tr.setMeta('isConfirmedSyncBlockDeletion', true);
129
- if (!trToDispatch.getMeta(pmHistoryPluginKey)) {
130
- // bodiedSyncBlock deletion is expected to be permanent (cannot undo)
131
- // For a normal deletion (not triggered by undo), remove it from history so that it cannot be undone
132
- trToDispatch.setMeta('addToHistory', false);
133
- }
134
- return trToDispatch;
135
- });
136
- }).finally(function () {
137
- confirmationTransaction = undefined;
138
- });
139
- return false;
156
+ confirmationTransactionRef.current = tr;
157
+ return handleBodiedSyncBlockRemoval(tr, bodiedSyncBlockRemoved, syncBlockStore, api, confirmationTransactionRef);
140
158
  }
141
159
  if (bodiedSyncBlockAdded.length > 0) {
142
160
  if (Boolean(tr.getMeta(pmHistoryPluginKey))) {
@@ -150,8 +168,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
150
168
  // 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
151
169
  // The callback will be evoked by in SourceSyncBlockStoreManager.commitPendingCreation
152
170
  syncBlockStore.sourceManager.registerCreationCallback(function () {
153
- var _api$core2;
154
- api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function () {
171
+ var _api$core;
172
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function () {
155
173
  return tr.setMeta('isCommitSyncBlockCreation', true);
156
174
  });
157
175
  api === null || api === void 0 || api.core.actions.focus();
@@ -177,10 +195,12 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
177
195
  if (errorFlag) {
178
196
  // Use setTimeout to dispatch transaction in next tick and avoid re-entrant dispatch
179
197
  setTimeout(function () {
180
- api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
181
- var tr = _ref2.tr;
198
+ api === null || api === void 0 || api.core.actions.execute(function (_ref3) {
199
+ var tr = _ref3.tr;
182
200
  return tr.setMeta(syncedBlockPluginKey, {
183
- showFlag: errorFlag
201
+ activeFlag: {
202
+ id: errorFlag
203
+ }
184
204
  });
185
205
  });
186
206
  }, 0);
@@ -193,8 +213,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
193
213
  trs.filter(function (tr) {
194
214
  return tr.docChanged;
195
215
  }).forEach(function (tr) {
196
- if (confirmationTransaction) {
197
- confirmationTransaction = rebaseTransaction(confirmationTransaction, tr, newState);
216
+ if (confirmationTransactionRef.current) {
217
+ confirmationTransactionRef.current = rebaseTransaction(confirmationTransactionRef.current, tr, newState);
198
218
  }
199
219
  });
200
220
  var _iterator = _createForOfIteratorHelper(trs),
@@ -0,0 +1,80 @@
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 { pmHistoryPluginKey } from '@atlaskit/editor-common/utils';
5
+ import { FLAG_ID } from '../../types';
6
+ import { syncedBlockPluginKey } from '../main';
7
+ var onRetry = function onRetry(api, syncBlockStore) {
8
+ return function () {
9
+ var _api$core;
10
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref) {
11
+ var tr = _ref.tr;
12
+ return tr.setMeta(syncedBlockPluginKey, {
13
+ bodiedSyncBlockDeletionStatus: 'processing',
14
+ activeFlag: false
15
+ });
16
+ });
17
+ syncBlockStore.sourceManager.retryDeletion();
18
+ };
19
+ };
20
+ var onDismissed = function onDismissed(syncBlockStore) {
21
+ return function (tr) {
22
+ syncBlockStore.sourceManager.clearPendingDeletion();
23
+ return tr.setMeta(syncedBlockPluginKey, {
24
+ bodiedSyncBlockDeletionStatus: 'none'
25
+ });
26
+ };
27
+ };
28
+ export var handleBodiedSyncBlockRemoval = function handleBodiedSyncBlockRemoval(tr, bodiedSyncBlockRemoved, syncBlockStore, api, confirmationTransactionRef) {
29
+ // Clear potential old pending deletion to retreat the deletion as first attempt
30
+ syncBlockStore.sourceManager.clearPendingDeletion();
31
+
32
+ // If there are source sync blocks being removed, and we need to confirm with user before deleting,
33
+ // we block the transaction here, and wait for user confirmation to proceed with deletion.
34
+ // See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
35
+ // proceed with deletion.
36
+ syncBlockStore.sourceManager.deleteSyncBlocksWithConfirmation(bodiedSyncBlockRemoved.map(function (node) {
37
+ return node.attrs;
38
+ }), function () {
39
+ var _api$core2;
40
+ var confirmationTransaction = confirmationTransactionRef.current;
41
+ if (!confirmationTransaction) {
42
+ return;
43
+ }
44
+ api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function () {
45
+ var trToDispatch = confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true);
46
+ if (!trToDispatch.getMeta(pmHistoryPluginKey)) {
47
+ // bodiedSyncBlock deletion is expected to be permanent (cannot undo)
48
+ // For a normal deletion (not triggered by undo), remove it from history so that it cannot be undone
49
+ trToDispatch.setMeta('addToHistory', false);
50
+ }
51
+ return trToDispatch;
52
+ });
53
+ }, function (success) {
54
+ var _api$core3;
55
+ api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref2) {
56
+ var tr = _ref2.tr;
57
+ var newState;
58
+ if (!success) {
59
+ newState = {
60
+ activeFlag: {
61
+ id: FLAG_ID.FAIL_TO_DELETE,
62
+ onRetry: onRetry(api, syncBlockStore),
63
+ onDismissed: onDismissed(syncBlockStore)
64
+ }
65
+ };
66
+ }
67
+ newState = _objectSpread(_objectSpread({}, newState), {}, {
68
+ bodiedSyncBlockDeletionStatus: syncBlockStore.sourceManager.isRetryingDeletion() ?
69
+ // For retry, reset to none directly to clean up the status
70
+ 'none' :
71
+ // For the first attempt, set to completed for deletion modal can close the modal
72
+ 'completed'
73
+ });
74
+ return tr.setMeta(syncedBlockPluginKey, newState);
75
+ });
76
+ }, function () {
77
+ confirmationTransactionRef.current = undefined;
78
+ });
79
+ return false;
80
+ };
@@ -106,11 +106,13 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
106
106
  return;
107
107
  }
108
108
  var _syncedBlockPluginKey = syncedBlockPluginKey.getState(editorState),
109
- showFlag = _syncedBlockPluginKey.showFlag,
110
- currentSyncBlockStore = _syncedBlockPluginKey.syncBlockStore;
109
+ activeFlag = _syncedBlockPluginKey.activeFlag,
110
+ currentSyncBlockStore = _syncedBlockPluginKey.syncBlockStore,
111
+ bodiedSyncBlockDeletionStatus = _syncedBlockPluginKey.bodiedSyncBlockDeletionStatus;
111
112
  return {
112
- showFlag: showFlag,
113
- syncBlockStore: currentSyncBlockStore
113
+ activeFlag: activeFlag,
114
+ syncBlockStore: currentSyncBlockStore,
115
+ bodiedSyncBlockDeletionStatus: bodiedSyncBlockDeletionStatus
114
116
  };
115
117
  }
116
118
  };
@@ -2,5 +2,6 @@ export var FLAG_ID = /*#__PURE__*/function (FLAG_ID) {
2
2
  FLAG_ID["CANNOT_DELETE_WHEN_OFFLINE"] = "cannot-delete-when-offline";
3
3
  FLAG_ID["CANNOT_EDIT_WHEN_OFFLINE"] = "cannot-edit-when-offline";
4
4
  FLAG_ID["CANNOT_CREATE_WHEN_OFFLINE"] = "cannot-create-when-offline";
5
+ FLAG_ID["FAIL_TO_DELETE"] = "fail-to-delete";
5
6
  return FLAG_ID;
6
7
  }({});
@@ -6,7 +6,9 @@ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'
6
6
  import { syncBlockMessages as messages } from '@atlaskit/editor-common/messages';
7
7
  import ModalDialog, { ModalBody, ModalFooter, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
8
8
  import { Text } from '@atlaskit/primitives/compiled';
9
+ import { syncedBlockPluginKey } from '../pm-plugins/main';
9
10
  export var DeleteConfirmationModal = function DeleteConfirmationModal(_ref) {
11
+ var _api$core2, _api$core4, _api$core6;
10
12
  var syncBlockStoreManager = _ref.syncBlockStoreManager,
11
13
  api = _ref.api;
12
14
  var _useState = useState(false),
@@ -17,41 +19,79 @@ export var DeleteConfirmationModal = function DeleteConfirmationModal(_ref) {
17
19
  _useState4 = _slicedToArray(_useState3, 2),
18
20
  syncBlockCount = _useState4[0],
19
21
  setSyncBlockCount = _useState4[1];
20
- var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['connectivity'], function (states) {
21
- var _states$connectivityS;
22
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['connectivity', 'syncedBlock'], function (states) {
23
+ var _states$connectivityS, _states$syncedBlockSt, _states$syncedBlockSt2;
22
24
  return {
23
- mode: (_states$connectivityS = states.connectivityState) === null || _states$connectivityS === void 0 ? void 0 : _states$connectivityS.mode
25
+ mode: (_states$connectivityS = states.connectivityState) === null || _states$connectivityS === void 0 ? void 0 : _states$connectivityS.mode,
26
+ bodiedSyncBlockDeletionStatus: (_states$syncedBlockSt = states.syncedBlockState) === null || _states$syncedBlockSt === void 0 ? void 0 : _states$syncedBlockSt.bodiedSyncBlockDeletionStatus,
27
+ activeFlag: (_states$syncedBlockSt2 = states.syncedBlockState) === null || _states$syncedBlockSt2 === void 0 ? void 0 : _states$syncedBlockSt2.activeFlag
24
28
  };
25
29
  }),
26
- mode = _useSharedPluginState.mode;
30
+ mode = _useSharedPluginState.mode,
31
+ bodiedSyncBlockDeletionStatus = _useSharedPluginState.bodiedSyncBlockDeletionStatus,
32
+ activeFlag = _useSharedPluginState.activeFlag;
27
33
  var _useIntl = useIntl(),
28
34
  formatMessage = _useIntl.formatMessage;
29
35
  var resolverRef = React.useRef(undefined);
30
- var handleClose = useCallback(function (confirm) {
36
+ var handleClick = useCallback(function (confirm) {
31
37
  return function () {
38
+ var _api$core;
32
39
  if (resolverRef.current) {
33
40
  resolverRef.current(confirm);
34
41
  resolverRef.current = undefined;
35
42
  }
36
- setIsOpen(false);
43
+ if (!confirm) {
44
+ setIsOpen(false);
45
+ }
46
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
47
+ var tr = _ref2.tr;
48
+ return tr.setMeta(syncedBlockPluginKey, {
49
+ bodiedSyncBlockDeletionStatus: confirm ? 'processing' : 'none',
50
+ activeFlag: false
51
+ });
52
+ });
37
53
  };
38
- }, []);
54
+ }, [api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions]);
39
55
  var confirmationCallback = useCallback(function (syncBlockCount) {
40
56
  setIsOpen(true);
41
57
  setSyncBlockCount(syncBlockCount);
42
58
  var confirmedPromise = new Promise(function (resolve) {
43
59
  resolverRef.current = resolve;
44
60
  });
61
+ if (activeFlag) {
62
+ var _api$core3;
63
+ api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref3) {
64
+ var tr = _ref3.tr;
65
+ return tr.setMeta(syncedBlockPluginKey, {
66
+ // Clear flag to avoid potential retry deletion of different blocks
67
+ activeFlag: false
68
+ });
69
+ });
70
+ }
45
71
  return confirmedPromise;
46
- }, []);
72
+ }, [activeFlag, api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions]);
47
73
  useEffect(function () {
48
74
  var unregister = syncBlockStoreManager.sourceManager.registerConfirmationCallback(confirmationCallback);
49
75
  return function () {
50
76
  unregister();
51
77
  };
52
78
  }, [syncBlockStoreManager, confirmationCallback]);
79
+ useEffect(function () {
80
+ if (bodiedSyncBlockDeletionStatus === 'completed' && isOpen) {
81
+ var _api$core5;
82
+ // auto close modal once deletion is successful
83
+ setIsOpen(false);
84
+ api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref4) {
85
+ var tr = _ref4.tr;
86
+ return tr.setMeta(syncedBlockPluginKey, {
87
+ // Reset deletion status to have a clean state for next deletion
88
+ bodiedSyncBlockDeletionStatus: 'none'
89
+ });
90
+ });
91
+ }
92
+ }, [api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions, bodiedSyncBlockDeletionStatus, isOpen]);
53
93
  return /*#__PURE__*/React.createElement(ModalTransition, null, isOpen && /*#__PURE__*/React.createElement(ModalDialog, {
54
- onClose: handleClose(false),
94
+ onClose: handleClick(false),
55
95
  testId: "sync-block-delete-confirmation"
56
96
  }, /*#__PURE__*/React.createElement(ModalHeader, {
57
97
  hasCloseButton: true
@@ -61,11 +101,12 @@ export var DeleteConfirmationModal = function DeleteConfirmationModal(_ref) {
61
101
  syncBlockCount: syncBlockCount
62
102
  }))), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
63
103
  appearance: "subtle",
64
- onClick: handleClose(false)
104
+ onClick: handleClick(false)
65
105
  }, formatMessage(messages.deleteConfirmationModalCancelButton)), /*#__PURE__*/React.createElement(Button, {
66
106
  appearance: "warning",
67
- onClick: handleClose(true),
107
+ onClick: handleClick(true),
68
108
  autoFocus: true,
69
- isDisabled: mode === 'offline'
109
+ isDisabled: mode === 'offline',
110
+ isLoading: bodiedSyncBlockDeletionStatus === 'processing'
70
111
  }, formatMessage(messages.deleteConfirmationModalDeleteButton)))));
71
112
  };
@@ -1,13 +1,15 @@
1
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; }
2
4
  import React from 'react';
3
5
  import { useIntl } from 'react-intl-next';
4
6
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
5
7
  import { syncBlockMessages as messages } from '@atlaskit/editor-common/messages';
6
8
  import AkFlag, { FlagGroup } from '@atlaskit/flag';
7
- import StatusErrorIcon from '@atlaskit/icon/core/status-error';
9
+ import StatusWarningIcon from '@atlaskit/icon/core/status-warning';
8
10
  import { syncedBlockPluginKey } from '../pm-plugins/main';
9
11
  import { FLAG_ID } from '../types';
10
- var flagMap = _defineProperty(_defineProperty(_defineProperty({}, FLAG_ID.CANNOT_DELETE_WHEN_OFFLINE, {
12
+ var flagMap = _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FLAG_ID.CANNOT_DELETE_WHEN_OFFLINE, {
11
13
  title: messages.failToDeleteTitle,
12
14
  description: messages.failToDeleteWhenOfflineDescription
13
15
  }), FLAG_ID.CANNOT_EDIT_WHEN_OFFLINE, {
@@ -16,43 +18,68 @@ var flagMap = _defineProperty(_defineProperty(_defineProperty({}, FLAG_ID.CANNOT
16
18
  }), FLAG_ID.CANNOT_CREATE_WHEN_OFFLINE, {
17
19
  title: messages.failToCreateTitle,
18
20
  description: messages.failToCreateWhenOfflineDescription
21
+ }), FLAG_ID.FAIL_TO_DELETE, {
22
+ title: messages.cannotDeleteTitle,
23
+ description: messages.cannotDeleteDescription
19
24
  });
20
25
  export var Flag = function Flag(_ref) {
21
26
  var api = _ref.api;
22
- var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['syncedBlock'], function (states) {
23
- var _states$syncedBlockSt;
27
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['syncedBlock', 'connectivity'], function (states) {
28
+ var _states$syncedBlockSt, _states$connectivityS;
24
29
  return {
25
- showFlag: (_states$syncedBlockSt = states.syncedBlockState) === null || _states$syncedBlockSt === void 0 ? void 0 : _states$syncedBlockSt.showFlag
30
+ activeFlag: (_states$syncedBlockSt = states.syncedBlockState) === null || _states$syncedBlockSt === void 0 ? void 0 : _states$syncedBlockSt.activeFlag,
31
+ mode: (_states$connectivityS = states.connectivityState) === null || _states$connectivityS === void 0 ? void 0 : _states$connectivityS.mode
26
32
  };
27
33
  }),
28
- showFlag = _useSharedPluginState.showFlag;
34
+ activeFlag = _useSharedPluginState.activeFlag,
35
+ mode = _useSharedPluginState.mode;
29
36
  var _useIntl = useIntl(),
30
37
  formatMessage = _useIntl.formatMessage;
31
- if (!showFlag) {
38
+ if (!activeFlag) {
32
39
  return;
33
40
  }
34
- var _flagMap$showFlag = flagMap[showFlag],
35
- title = _flagMap$showFlag.title,
36
- description = _flagMap$showFlag.description;
37
- var onDismissed = function onDismissed() {
41
+ var _flagMap$activeFlag$i = flagMap[activeFlag.id],
42
+ title = _flagMap$activeFlag$i.title,
43
+ description = _flagMap$activeFlag$i.description;
44
+ var onRetry = activeFlag.onRetry,
45
+ onDismissedCallback = activeFlag.onDismissed;
46
+
47
+ // Retry button often involves network request, hence we dismiss the flag in offline mode to avoid retry
48
+ if (mode === 'offline' && !!onRetry) {
38
49
  api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
39
50
  var tr = _ref2.tr;
40
51
  tr.setMeta(syncedBlockPluginKey, {
41
- showFlag: false
52
+ activeFlag: false
42
53
  });
43
54
  return tr;
44
55
  });
56
+ return;
57
+ }
58
+ var onDismissed = function onDismissed() {
59
+ api === null || api === void 0 || api.core.actions.execute(function (_ref3) {
60
+ var tr = _ref3.tr;
61
+ onDismissedCallback === null || onDismissedCallback === void 0 || onDismissedCallback(tr);
62
+ var oldMeta = tr.getMeta(syncedBlockPluginKey);
63
+ tr.setMeta(syncedBlockPluginKey, _objectSpread(_objectSpread({}, oldMeta), {}, {
64
+ activeFlag: false
65
+ }));
66
+ return tr;
67
+ });
45
68
  api === null || api === void 0 || api.core.actions.focus();
46
69
  };
47
70
  return /*#__PURE__*/React.createElement(FlagGroup, null, /*#__PURE__*/React.createElement(AkFlag, {
48
71
  onDismissed: onDismissed,
49
72
  title: formatMessage(title),
50
73
  description: formatMessage(description),
51
- id: showFlag,
52
- testId: showFlag,
53
- icon: /*#__PURE__*/React.createElement(StatusErrorIcon, {
74
+ id: activeFlag.id,
75
+ testId: activeFlag.id,
76
+ icon: /*#__PURE__*/React.createElement(StatusWarningIcon, {
54
77
  label: "",
55
- color: "var(--ds-icon-danger, #C9372C)"
56
- })
78
+ color: "var(--ds-icon-warning, #E06C00)"
79
+ }),
80
+ actions: onRetry ? [{
81
+ content: formatMessage(messages.deleteRetryButton),
82
+ onClick: onRetry
83
+ }] : undefined
57
84
  }));
58
85
  };
@@ -6,14 +6,16 @@ var SyncBlockRendererWrapperComponent = function SyncBlockRendererWrapperCompone
6
6
  var syncedBlockRenderer = _ref.syncedBlockRenderer,
7
7
  useFetchSyncBlockData = _ref.useFetchSyncBlockData,
8
8
  localId = _ref.localId,
9
- useFetchSyncBlockTitle = _ref.useFetchSyncBlockTitle;
9
+ useFetchSyncBlockTitle = _ref.useFetchSyncBlockTitle,
10
+ api = _ref.api;
10
11
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
11
12
  "data-testid": SyncBlockRendererWrapperDataId
12
13
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
13
14
  ,
14
15
  className: SyncBlockSharedCssClassName.renderer
15
16
  }, syncedBlockRenderer({
16
- useFetchSyncBlockData: useFetchSyncBlockData
17
+ useFetchSyncBlockData: useFetchSyncBlockData,
18
+ api: api
17
19
  })), /*#__PURE__*/React.createElement(SyncBlockLabel, {
18
20
  isSource: false,
19
21
  useFetchSyncBlockTitle: useFetchSyncBlockTitle,
@@ -4,11 +4,12 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
4
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
5
  import { type SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
6
6
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
7
- import { FLAG_ID } from '../types';
7
+ import { type ActiveFlag, type BodiedSyncBlockDeletionStatus } from '../types';
8
8
  export declare const syncedBlockPluginKey: PluginKey<any>;
9
9
  type SyncedBlockPluginState = {
10
+ activeFlag: ActiveFlag;
11
+ bodiedSyncBlockDeletionStatus?: BodiedSyncBlockDeletionStatus;
10
12
  selectionDecorationSet: DecorationSet;
11
- showFlag: FLAG_ID | false;
12
13
  syncBlockStore: SyncBlockStoreManager;
13
14
  };
14
15
  export declare const createPlugin: (options: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams, syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => SafePlugin<SyncedBlockPluginState>;
@@ -0,0 +1,9 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
+ import type { SyncedBlockPlugin } from '../../syncedBlockPluginType';
5
+ import { type SyncBlockInfo } from '../../types';
6
+ export type ConfirmationTransactionRef = {
7
+ current: Transaction | undefined;
8
+ };
9
+ export declare const handleBodiedSyncBlockRemoval: (tr: Transaction, bodiedSyncBlockRemoved: SyncBlockInfo[], syncBlockStore: SyncBlockStoreManager, api: ExtractInjectionAPI<SyncedBlockPlugin> | undefined, confirmationTransactionRef: ConfirmationTransactionRef) => boolean;
@@ -1,17 +1,8 @@
1
1
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
3
- import type { SyncBlockAttrs } from '../../syncedBlockPluginType';
4
3
  export declare const trackSyncBlocks: (predicate: (node: PMNode) => boolean, tr: Transaction, state: EditorState) => {
5
- removed: {
6
- attrs: SyncBlockAttrs;
7
- from?: number;
8
- to?: number;
9
- }[];
10
- added: {
11
- attrs: SyncBlockAttrs;
12
- from?: number;
13
- to?: number;
14
- }[];
4
+ removed: import("../../types").SyncBlockInfo[];
5
+ added: import("../../types").SyncBlockInfo[];
15
6
  };
16
7
  /**
17
8
  *
@@ -1,5 +1,5 @@
1
1
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
- import type { EditorCommand, LongPressSelectionPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { EditorCommand, ExtractInjectionAPI, LongPressSelectionPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
3
  import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
4
4
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
5
5
  import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls';
@@ -36,6 +36,7 @@ export type SyncedBlockEditorProps = {
36
36
  popupsMountPoint: HTMLElement;
37
37
  };
38
38
  export type SyncedBlockRendererProps = {
39
+ api?: ExtractInjectionAPI<SyncedBlockPlugin>;
39
40
  useFetchSyncBlockData: () => UseFetchSyncBlockDataResult;
40
41
  };
41
42
  export interface SyncedBlockPluginOptions extends LongPressSelectionPluginOptions {
@@ -71,7 +72,3 @@ export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
71
72
  pluginConfiguration: SyncedBlockPluginOptions | undefined;
72
73
  sharedState: SyncedBlockSharedState | undefined;
73
74
  }>;
74
- export type SyncBlockAttrs = {
75
- localId: string;
76
- resourceId: string;
77
- };
@@ -1,16 +1,42 @@
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
1
2
  import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
2
3
  export declare enum FLAG_ID {
3
4
  CANNOT_DELETE_WHEN_OFFLINE = "cannot-delete-when-offline",
4
5
  CANNOT_EDIT_WHEN_OFFLINE = "cannot-edit-when-offline",
5
- CANNOT_CREATE_WHEN_OFFLINE = "cannot-create-when-offline"
6
+ CANNOT_CREATE_WHEN_OFFLINE = "cannot-create-when-offline",
7
+ FAIL_TO_DELETE = "fail-to-delete"
6
8
  }
9
+ type FlagConfig = {
10
+ id: FLAG_ID;
11
+ onDismissed?: (tr: Transaction) => Transaction | void;
12
+ onRetry?: () => void;
13
+ };
14
+ export type BodiedSyncBlockDeletionStatus = 'none' | 'processing' | 'completed';
15
+ export type ActiveFlag = FlagConfig | false;
7
16
  export type SyncedBlockSharedState = {
8
17
  /**
9
18
  * Whether to show a flag (usually for errors, e.g. fail to delete)
10
19
  */
11
- showFlag: FLAG_ID | false;
20
+ activeFlag: ActiveFlag;
21
+ /**
22
+ * Whether the plugin is currently saving bodiedSyncBlock deletion to backend
23
+ */
24
+ bodiedSyncBlockDeletionStatus?: BodiedSyncBlockDeletionStatus;
12
25
  /**
13
26
  * The current sync block store manager, used to manage fetching and updating sync block data
14
27
  */
15
28
  syncBlockStore: SyncBlockStoreManager;
16
29
  };
30
+ export type SyncBlockAttrs = {
31
+ localId: string;
32
+ resourceId: string;
33
+ };
34
+ export type SyncBlockInfo = {
35
+ attrs: SyncBlockAttrs;
36
+ from?: number;
37
+ to?: number;
38
+ };
39
+ export type SyncBlockMap = {
40
+ [key: string]: SyncBlockInfo;
41
+ };
42
+ export {};
@@ -4,5 +4,5 @@ import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
4
4
  type CreateSyncedBlockButtonProps = {
5
5
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
6
6
  };
7
- export declare const CreateSyncedBlockButton: ({ api }: CreateSyncedBlockButtonProps) => React.JSX.Element;
7
+ export declare const CreateSyncedBlockButton: ({ api, }: CreateSyncedBlockButtonProps) => React.JSX.Element;
8
8
  export {};
@@ -2,5 +2,5 @@ import React from 'react';
2
2
  type OverflowMenuSectionProps = {
3
3
  children: React.ReactNode;
4
4
  };
5
- export declare const OverflowMenuSection: ({ children }: OverflowMenuSectionProps) => React.JSX.Element | null;
5
+ export declare const OverflowMenuSection: ({ children, }: OverflowMenuSectionProps) => React.JSX.Element | null;
6
6
  export {};