@atlaskit/editor-plugin-synced-block 4.2.13 → 4.2.15

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 +16 -0
  2. package/dist/cjs/editor-actions/index.js +1 -1
  3. package/dist/cjs/editor-commands/index.js +5 -5
  4. package/dist/cjs/nodeviews/bodiedSyncedBlock.js +8 -6
  5. package/dist/cjs/nodeviews/syncedBlock.js +10 -7
  6. package/dist/cjs/pm-plugins/main.js +15 -14
  7. package/dist/cjs/syncedBlockPlugin.js +4 -2
  8. package/dist/cjs/ui/DeleteConfirmationModal.js +1 -1
  9. package/dist/cjs/ui/SyncBlockRefresher.js +1 -1
  10. package/dist/cjs/ui/floating-toolbar.js +1 -1
  11. package/dist/es2019/editor-actions/index.js +1 -1
  12. package/dist/es2019/editor-commands/index.js +5 -5
  13. package/dist/es2019/nodeviews/bodiedSyncedBlock.js +8 -6
  14. package/dist/es2019/nodeviews/syncedBlock.js +10 -8
  15. package/dist/es2019/pm-plugins/main.js +15 -14
  16. package/dist/es2019/syncedBlockPlugin.js +4 -2
  17. package/dist/es2019/ui/DeleteConfirmationModal.js +1 -1
  18. package/dist/es2019/ui/SyncBlockRefresher.js +1 -1
  19. package/dist/es2019/ui/floating-toolbar.js +1 -1
  20. package/dist/esm/editor-actions/index.js +1 -1
  21. package/dist/esm/editor-commands/index.js +5 -5
  22. package/dist/esm/nodeviews/bodiedSyncedBlock.js +8 -6
  23. package/dist/esm/nodeviews/syncedBlock.js +10 -7
  24. package/dist/esm/pm-plugins/main.js +15 -14
  25. package/dist/esm/syncedBlockPlugin.js +4 -2
  26. package/dist/esm/ui/DeleteConfirmationModal.js +1 -1
  27. package/dist/esm/ui/SyncBlockRefresher.js +1 -1
  28. package/dist/esm/ui/floating-toolbar.js +1 -1
  29. package/dist/types/nodeviews/bodiedSyncedBlock.d.ts +0 -3
  30. package/dist/types/nodeviews/syncedBlock.d.ts +0 -3
  31. package/dist/types/pm-plugins/main.d.ts +2 -1
  32. package/dist/types/types/index.d.ts +5 -0
  33. package/dist/types-ts4.5/nodeviews/bodiedSyncedBlock.d.ts +0 -3
  34. package/dist/types-ts4.5/nodeviews/syncedBlock.d.ts +0 -3
  35. package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -1
  36. package/dist/types-ts4.5/types/index.d.ts +5 -0
  37. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-plugin-synced-block
2
2
 
3
+ ## 4.2.15
4
+
5
+ ### Patch Changes
6
+
7
+ - [`a9159bf9608a8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a9159bf9608a8) -
8
+ [ux] Fix edit link disabled on reference sync block by setting syncBlockStore in nodeview from
9
+ plugin state
10
+
11
+ ## 4.2.14
12
+
13
+ ### Patch Changes
14
+
15
+ - [`964b980644f9d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/964b980644f9d) -
16
+ EDITOR-3348 Refactor Synced Block Store Manager
17
+ - Updated dependencies
18
+
3
19
  ## 4.2.13
4
20
 
5
21
  ### Patch Changes
@@ -5,5 +5,5 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.flushBodiedSyncBlocks = void 0;
7
7
  var flushBodiedSyncBlocks = exports.flushBodiedSyncBlocks = function flushBodiedSyncBlocks(syncBlockStore) {
8
- return syncBlockStore.flushBodiedSyncBlocks();
8
+ return syncBlockStore.sourceManager.flush();
9
9
  };
@@ -19,7 +19,7 @@ var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(_
19
19
 
20
20
  // If the selection is empty, we want to insert the sync block on a new line
21
21
  if (tr.selection.empty) {
22
- var attrs = syncBlockStore.generateBodiedSyncBlockAttrs();
22
+ var attrs = syncBlockStore.sourceManager.generateBodiedSyncBlockAttrs();
23
23
  var paragraphNode = paragraph.createAndFill({});
24
24
  var newBodiedSyncBlockNode = bodiedSyncBlock.createAndFill(attrs, paragraphNode ? [paragraphNode] : []);
25
25
  if (!newBodiedSyncBlockNode) {
@@ -28,7 +28,7 @@ var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(_
28
28
 
29
29
  // Save the new node with empty content to backend
30
30
  // This is so that the node can be copied and referenced without the source being saved/published
31
- syncBlockStore.createBodiedSyncBlockNode(attrs);
31
+ syncBlockStore.sourceManager.createBodiedSyncBlockNode(attrs);
32
32
  if (typeAheadInsert) {
33
33
  tr = typeAheadInsert(newBodiedSyncBlockNode);
34
34
  } else {
@@ -40,7 +40,7 @@ var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(_
40
40
  // TODO: EDITOR-1665 - Raise an error analytics event
41
41
  return false;
42
42
  }
43
- var _attrs = syncBlockStore.generateBodiedSyncBlockAttrs();
43
+ var _attrs = syncBlockStore.sourceManager.generateBodiedSyncBlockAttrs();
44
44
  var _newBodiedSyncBlockNode = bodiedSyncBlock.createAndFill(_attrs, conversionInfo.contentToInclude);
45
45
  if (!_newBodiedSyncBlockNode) {
46
46
  return false;
@@ -48,7 +48,7 @@ var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(_
48
48
 
49
49
  // Save the new node with empty content to backend
50
50
  // This is so that the node can be copied and referenced without the source being saved/published
51
- syncBlockStore.createBodiedSyncBlockNode(_attrs);
51
+ syncBlockStore.sourceManager.createBodiedSyncBlockNode(_attrs);
52
52
  tr.replaceWith(conversionInfo.from > 0 ? conversionInfo.from - 1 : 0, conversionInfo.to, _newBodiedSyncBlockNode).scrollIntoView();
53
53
 
54
54
  // set selection to the end of the previous selection + 1 for the position taken up by the start of the new synced block
@@ -104,7 +104,7 @@ var editSyncedBlockSource = exports.editSyncedBlockSource = function editSyncedB
104
104
  if (!resourceId) {
105
105
  return false;
106
106
  }
107
- var syncBlockURL = syncBlockStore.getSyncBlockURL(resourceId);
107
+ var syncBlockURL = syncBlockStore.referenceManager.getSyncBlockURL(resourceId);
108
108
  if (syncBlockURL) {
109
109
  window.open(syncBlockURL, '_blank');
110
110
  } else {
@@ -28,7 +28,6 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
28
28
  var _this;
29
29
  (0, _classCallCheck2.default)(this, BodiedSyncBlock);
30
30
  _this = _callSuper(this, BodiedSyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
31
- _this.syncBlockStore = props.syncBlockStore;
32
31
  _this.api = props.api;
33
32
  _this.handleConnectivityModeChange();
34
33
  _this.handleViewModeChange();
@@ -89,9 +88,14 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
89
88
  }, {
90
89
  key: "render",
91
90
  value: function render(_props, forwardRef) {
91
+ var _this$api5;
92
+ var syncBlockStore = (_this$api5 = this.api) === null || _this$api5 === void 0 || (_this$api5 = _this$api5.syncedBlock.sharedState) === null || _this$api5 === void 0 || (_this$api5 = _this$api5.currentState()) === null || _this$api5 === void 0 ? void 0 : _this$api5.syncBlockStore;
93
+ if (!syncBlockStore) {
94
+ return null;
95
+ }
92
96
  return /*#__PURE__*/_react.default.createElement(_BodiedSyncBlockWrapper.BodiedSyncBlockWrapper, {
93
97
  ref: forwardRef,
94
- syncBlockStore: this.syncBlockStore,
98
+ syncBlockStore: syncBlockStore,
95
99
  node: this.node
96
100
  });
97
101
  }
@@ -127,8 +131,7 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
127
131
  var bodiedSyncBlockNodeView = exports.bodiedSyncBlockNodeView = function bodiedSyncBlockNodeView(_ref4) {
128
132
  var pluginOptions = _ref4.pluginOptions,
129
133
  pmPluginFactoryParams = _ref4.pmPluginFactoryParams,
130
- api = _ref4.api,
131
- syncBlockStore = _ref4.syncBlockStore;
134
+ api = _ref4.api;
132
135
  return function (node, view, getPos) {
133
136
  var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
134
137
  eventDispatcher = pmPluginFactoryParams.eventDispatcher;
@@ -139,8 +142,7 @@ var bodiedSyncBlockNodeView = exports.bodiedSyncBlockNodeView = function bodiedS
139
142
  view: view,
140
143
  getPos: getPos,
141
144
  portalProviderAPI: portalProviderAPI,
142
- eventDispatcher: eventDispatcher,
143
- syncBlockStore: syncBlockStore
145
+ eventDispatcher: eventDispatcher
144
146
  }).init();
145
147
  };
146
148
  };
@@ -25,7 +25,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
25
25
  (0, _classCallCheck2.default)(this, SyncBlock);
26
26
  _this = _callSuper(this, SyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
27
27
  _this.options = props.options;
28
- _this.syncBlockStore = props.syncBlockStore;
28
+ _this.api = props.api;
29
29
  return _this;
30
30
  }
31
31
  (0, _inherits2.default)(SyncBlock, _ReactNodeView);
@@ -40,6 +40,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
40
40
  key: "render",
41
41
  value: function render() {
42
42
  var _this$options,
43
+ _this$api,
43
44
  _this$options2,
44
45
  _this2 = this;
45
46
  if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.syncedBlockRenderer)) {
@@ -51,16 +52,20 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
51
52
  if (!resourceId || !localId) {
52
53
  return null;
53
54
  }
55
+ var syncBlockStore = (_this$api = this.api) === null || _this$api === void 0 || (_this$api = _this$api.syncedBlock) === null || _this$api === void 0 || (_this$api = _this$api.sharedState.currentState()) === null || _this$api === void 0 ? void 0 : _this$api.syncBlockStore;
56
+ if (!syncBlockStore) {
57
+ return null;
58
+ }
54
59
 
55
60
  // get document node from data provider
56
61
  return /*#__PURE__*/_react.default.createElement(_SyncBlockRendererWrapper.SyncBlockRendererWrapper, {
57
62
  localId: this.node.attrs.localId,
58
63
  syncedBlockRenderer: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.syncedBlockRenderer,
59
64
  useFetchSyncBlockTitle: function useFetchSyncBlockTitle() {
60
- return (0, _editorSyncedBlockProvider.useFetchSyncBlockTitle)(_this2.syncBlockStore, _this2.node);
65
+ return (0, _editorSyncedBlockProvider.useFetchSyncBlockTitle)(syncBlockStore, _this2.node);
61
66
  },
62
67
  useFetchSyncBlockData: function useFetchSyncBlockData() {
63
- return (0, _editorSyncedBlockProvider.useFetchSyncBlockData)(_this2.syncBlockStore, resourceId, localId);
68
+ return (0, _editorSyncedBlockProvider.useFetchSyncBlockData)(syncBlockStore, resourceId, localId);
64
69
  }
65
70
  });
66
71
  }
@@ -76,8 +81,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
76
81
  var syncBlockNodeView = exports.syncBlockNodeView = function syncBlockNodeView(_ref) {
77
82
  var options = _ref.options,
78
83
  pmPluginFactoryParams = _ref.pmPluginFactoryParams,
79
- api = _ref.api,
80
- syncBlockStore = _ref.syncBlockStore;
84
+ api = _ref.api;
81
85
  return function (node, view, getPos) {
82
86
  var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
83
87
  eventDispatcher = pmPluginFactoryParams.eventDispatcher;
@@ -88,8 +92,7 @@ var syncBlockNodeView = exports.syncBlockNodeView = function syncBlockNodeView(_
88
92
  view: view,
89
93
  getPos: getPos,
90
94
  portalProviderAPI: portalProviderAPI,
91
- eventDispatcher: eventDispatcher,
92
- syncBlockStore: syncBlockStore
95
+ eventDispatcher: eventDispatcher
93
96
  }).init();
94
97
  };
95
98
  };
@@ -9,6 +9,7 @@ var _selection = require("@atlaskit/editor-common/selection");
9
9
  var _syncBlock = require("@atlaskit/editor-common/sync-block");
10
10
  var _state = require("@atlaskit/editor-prosemirror/state");
11
11
  var _view = require("@atlaskit/editor-prosemirror/view");
12
+ var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
12
13
  var _bodiedLazySyncedBlock = require("../nodeviews/bodiedLazySyncedBlock");
13
14
  var _lazySyncedBlock = require("../nodeviews/lazySyncedBlock");
14
15
  var _types = require("../types");
@@ -27,10 +28,11 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
27
28
  var syncBlockNodes = instance.doc.children.filter(function (node) {
28
29
  return node.type.name === 'syncBlock';
29
30
  });
30
- syncBlockStore.fetchSyncBlocksData(syncBlockNodes);
31
+ syncBlockStore.referenceManager.fetchSyncBlocksData((0, _editorSyncedBlockProvider.convertPMNodesToSyncBlockNodes)(syncBlockNodes));
31
32
  return {
32
33
  selectionDecorationSet: (0, _selectionDecorations.calculateDecorations)(instance.doc, instance.selection, instance.schema),
33
- showFlag: false
34
+ showFlag: false,
35
+ syncBlockStore: syncBlockStore
34
36
  };
35
37
  },
36
38
  apply: function apply(tr, currentPluginState, oldEditorState) {
@@ -44,7 +46,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
44
46
  }
45
47
  return {
46
48
  showFlag: (_meta$showFlag = meta === null || meta === void 0 ? void 0 : meta.showFlag) !== null && _meta$showFlag !== void 0 ? _meta$showFlag : showFlag,
47
- selectionDecorationSet: newDecorationSet
49
+ selectionDecorationSet: newDecorationSet,
50
+ syncBlockStore: syncBlockStore
48
51
  };
49
52
  }
50
53
  },
@@ -53,14 +56,12 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
53
56
  syncBlock: (0, _lazySyncedBlock.lazySyncBlockView)({
54
57
  options: options,
55
58
  pmPluginFactoryParams: pmPluginFactoryParams,
56
- api: api,
57
- syncBlockStore: syncBlockStore
59
+ api: api
58
60
  }),
59
61
  bodiedSyncBlock: (0, _bodiedLazySyncedBlock.lazyBodiedSyncBlockView)({
60
62
  pluginOptions: options,
61
63
  pmPluginFactoryParams: pmPluginFactoryParams,
62
- api: api,
63
- syncBlockStore: syncBlockStore
64
+ api: api
64
65
  })
65
66
  },
66
67
  decorations: function decorations(state) {
@@ -100,10 +101,10 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
100
101
  }
101
102
  },
102
103
  view: function view(editorView) {
103
- syncBlockStore.setEditorView(editorView);
104
+ syncBlockStore.sourceManager.setEditorView(editorView);
104
105
  return {
105
106
  destroy: function destroy() {
106
- syncBlockStore.setEditorView(undefined);
107
+ syncBlockStore.sourceManager.setEditorView(undefined);
107
108
  }
108
109
  };
109
110
  },
@@ -115,10 +116,10 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
115
116
  // or are from remote (collab) or already confirmed sync block deletion
116
117
  // We only care about local changes that change the document
117
118
  // and are not yet confirmed for sync block deletion
118
- if (!tr.docChanged || !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.requireConfirmationBeforeDelete()) && !syncBlockStore.hasPendingCreation() || Boolean(tr.getMeta('isRemote')) || Boolean(tr.getMeta('isCommitSyncBlockCreation')) || !isOffline && isConfirmedSyncBlockDeletion) {
119
+ if (!tr.docChanged || !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.sourceManager.requireConfirmationBeforeDelete()) && !syncBlockStore.sourceManager.hasPendingCreation() || Boolean(tr.getMeta('isRemote')) || Boolean(tr.getMeta('isCommitSyncBlockCreation')) || !isOffline && isConfirmedSyncBlockDeletion) {
119
120
  return true;
120
121
  }
121
- var _trackSyncBlocks = (0, _trackSyncBlocks3.trackSyncBlocks)(syncBlockStore.isSourceBlock, tr, state),
122
+ var _trackSyncBlocks = (0, _trackSyncBlocks3.trackSyncBlocks)(syncBlockStore.sourceManager.isSourceBlock, tr, state),
122
123
  bodiedSyncBlockRemoved = _trackSyncBlocks.removed,
123
124
  bodiedSyncBlockAdded = _trackSyncBlocks.added;
124
125
  if (!isOffline) {
@@ -127,14 +128,14 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
127
128
  // we block the transaction here, and wait for user confirmation to proceed with deletion.
128
129
  // See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
129
130
  // proceed with deletion.
130
- syncBlockStore.deleteSyncBlocksWithConfirmation(tr, bodiedSyncBlockRemoved);
131
+ syncBlockStore.sourceManager.deleteSyncBlocksWithConfirmation(tr, bodiedSyncBlockRemoved);
131
132
  return false;
132
133
  }
133
134
  if (bodiedSyncBlockAdded.length > 0) {
134
135
  // If there is bodiedSyncBlock node addition and it's waiting for the result of saving the node to backend (syncBlockStore.hasPendingCreation()),
135
136
  // 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
136
137
  // The callback will be evoked by in SourceSyncBlockStoreManager.commitPendingCreation
137
- syncBlockStore.registerCreationCallback(function () {
138
+ syncBlockStore.sourceManager.registerCreationCallback(function () {
138
139
  var _api$core;
139
140
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function () {
140
141
  return tr.setMeta('isCommitSyncBlockCreation', true);
@@ -177,7 +178,7 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
177
178
  trs.filter(function (tr) {
178
179
  return tr.docChanged;
179
180
  }).forEach(function (tr) {
180
- syncBlockStore === null || syncBlockStore === void 0 || syncBlockStore.rebaseTransaction(tr, newState);
181
+ syncBlockStore === null || syncBlockStore === void 0 || syncBlockStore.sourceManager.rebaseTransaction(tr, newState);
181
182
  });
182
183
  return null;
183
184
  }
@@ -113,9 +113,11 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
113
113
  return;
114
114
  }
115
115
  var _syncedBlockPluginKey = _main.syncedBlockPluginKey.getState(editorState),
116
- showFlag = _syncedBlockPluginKey.showFlag;
116
+ showFlag = _syncedBlockPluginKey.showFlag,
117
+ currentSyncBlockStore = _syncedBlockPluginKey.syncBlockStore;
117
118
  return {
118
- showFlag: showFlag
119
+ showFlag: showFlag,
120
+ syncBlockStore: currentSyncBlockStore
119
121
  };
120
122
  }
121
123
  };
@@ -54,7 +54,7 @@ var DeleteConfirmationModal = exports.DeleteConfirmationModal = function DeleteC
54
54
  return confirmedPromise;
55
55
  }, []);
56
56
  (0, _react.useEffect)(function () {
57
- var unregister = syncBlockStoreManager.registerConfirmationCallback(confirmationCallback);
57
+ var unregister = syncBlockStoreManager.sourceManager.registerConfirmationCallback(confirmationCallback);
58
58
  return function () {
59
59
  unregister();
60
60
  };
@@ -27,7 +27,7 @@ var SyncBlockRefresher = exports.SyncBlockRefresher = function SyncBlockRefreshe
27
27
  var _document;
28
28
  // check if document is visible to avoid unnecessary refreshes
29
29
  if (((_document = document) === null || _document === void 0 ? void 0 : _document.visibilityState) === 'visible') {
30
- syncBlockStoreManager.refreshSubscriptions();
30
+ syncBlockStoreManager.referenceManager.refreshSubscriptions();
31
31
  }
32
32
  }, SYNC_BLOCK_FETCH_INTERVAL);
33
33
  } else if (interval !== -1) {
@@ -50,7 +50,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(stat
50
50
  onClick: _editorCommands.copySyncedBlockReferenceToClipboard
51
51
  }, hoverDecorationProps(nodeType, _consts.akEditorSelectedNodeClassName));
52
52
  items.push(copyButton);
53
- var disabled = !syncBlockStore.getSyncBlockURL(syncBlockObject.node.attrs.resourceId);
53
+ var disabled = !syncBlockStore.referenceManager.getSyncBlockURL(syncBlockObject.node.attrs.resourceId);
54
54
  if (!isBodiedSyncBlock) {
55
55
  var editSourceButton = _objectSpread({
56
56
  id: 'editor.syncedBlock.editSource',
@@ -1,3 +1,3 @@
1
1
  export const flushBodiedSyncBlocks = syncBlockStore => {
2
- return syncBlockStore.flushBodiedSyncBlocks();
2
+ return syncBlockStore.sourceManager.flush();
3
3
  };
@@ -19,7 +19,7 @@ export const createSyncedBlock = ({
19
19
 
20
20
  // If the selection is empty, we want to insert the sync block on a new line
21
21
  if (tr.selection.empty) {
22
- const attrs = syncBlockStore.generateBodiedSyncBlockAttrs();
22
+ const attrs = syncBlockStore.sourceManager.generateBodiedSyncBlockAttrs();
23
23
  const paragraphNode = paragraph.createAndFill({});
24
24
  const newBodiedSyncBlockNode = bodiedSyncBlock.createAndFill(attrs, paragraphNode ? [paragraphNode] : []);
25
25
  if (!newBodiedSyncBlockNode) {
@@ -28,7 +28,7 @@ export const createSyncedBlock = ({
28
28
 
29
29
  // Save the new node with empty content to backend
30
30
  // This is so that the node can be copied and referenced without the source being saved/published
31
- syncBlockStore.createBodiedSyncBlockNode(attrs);
31
+ syncBlockStore.sourceManager.createBodiedSyncBlockNode(attrs);
32
32
  if (typeAheadInsert) {
33
33
  tr = typeAheadInsert(newBodiedSyncBlockNode);
34
34
  } else {
@@ -40,7 +40,7 @@ export const createSyncedBlock = ({
40
40
  // TODO: EDITOR-1665 - Raise an error analytics event
41
41
  return false;
42
42
  }
43
- const attrs = syncBlockStore.generateBodiedSyncBlockAttrs();
43
+ const attrs = syncBlockStore.sourceManager.generateBodiedSyncBlockAttrs();
44
44
  const newBodiedSyncBlockNode = bodiedSyncBlock.createAndFill(attrs, conversionInfo.contentToInclude);
45
45
  if (!newBodiedSyncBlockNode) {
46
46
  return false;
@@ -48,7 +48,7 @@ export const createSyncedBlock = ({
48
48
 
49
49
  // Save the new node with empty content to backend
50
50
  // This is so that the node can be copied and referenced without the source being saved/published
51
- syncBlockStore.createBodiedSyncBlockNode(attrs);
51
+ syncBlockStore.sourceManager.createBodiedSyncBlockNode(attrs);
52
52
  tr.replaceWith(conversionInfo.from > 0 ? conversionInfo.from - 1 : 0, conversionInfo.to, newBodiedSyncBlockNode).scrollIntoView();
53
53
 
54
54
  // set selection to the end of the previous selection + 1 for the position taken up by the start of the new synced block
@@ -108,7 +108,7 @@ export const editSyncedBlockSource = (syncBlockStore, api) => (state, dispatch,
108
108
  if (!resourceId) {
109
109
  return false;
110
110
  }
111
- const syncBlockURL = syncBlockStore.getSyncBlockURL(resourceId);
111
+ const syncBlockURL = syncBlockStore.referenceManager.getSyncBlockURL(resourceId);
112
112
  if (syncBlockURL) {
113
113
  window.open(syncBlockURL, '_blank');
114
114
  } else {
@@ -10,7 +10,6 @@ const toDOM = () => ['div', {
10
10
  class BodiedSyncBlock extends ReactNodeView {
11
11
  constructor(props) {
12
12
  super(props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props);
13
- this.syncBlockStore = props.syncBlockStore;
14
13
  this.api = props.api;
15
14
  this.handleConnectivityModeChange();
16
15
  this.handleViewModeChange();
@@ -60,9 +59,14 @@ class BodiedSyncBlock extends ReactNodeView {
60
59
  return domRef;
61
60
  }
62
61
  render(_props, forwardRef) {
62
+ var _this$api5, _this$api5$syncedBloc, _this$api5$syncedBloc2;
63
+ const syncBlockStore = (_this$api5 = this.api) === null || _this$api5 === void 0 ? void 0 : (_this$api5$syncedBloc = _this$api5.syncedBlock.sharedState) === null || _this$api5$syncedBloc === void 0 ? void 0 : (_this$api5$syncedBloc2 = _this$api5$syncedBloc.currentState()) === null || _this$api5$syncedBloc2 === void 0 ? void 0 : _this$api5$syncedBloc2.syncBlockStore;
64
+ if (!syncBlockStore) {
65
+ return null;
66
+ }
63
67
  return /*#__PURE__*/React.createElement(BodiedSyncBlockWrapper, {
64
68
  ref: forwardRef,
65
- syncBlockStore: this.syncBlockStore,
69
+ syncBlockStore: syncBlockStore,
66
70
  node: this.node
67
71
  });
68
72
  }
@@ -94,8 +98,7 @@ class BodiedSyncBlock extends ReactNodeView {
94
98
  export const bodiedSyncBlockNodeView = ({
95
99
  pluginOptions,
96
100
  pmPluginFactoryParams,
97
- api,
98
- syncBlockStore
101
+ api
99
102
  }) => (node, view, getPos) => {
100
103
  const {
101
104
  portalProviderAPI,
@@ -108,7 +111,6 @@ export const bodiedSyncBlockNodeView = ({
108
111
  view,
109
112
  getPos,
110
113
  portalProviderAPI,
111
- eventDispatcher,
112
- syncBlockStore
114
+ eventDispatcher
113
115
  }).init();
114
116
  };
@@ -7,7 +7,7 @@ class SyncBlock extends ReactNodeView {
7
7
  constructor(props) {
8
8
  super(props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props);
9
9
  this.options = props.options;
10
- this.syncBlockStore = props.syncBlockStore;
10
+ this.api = props.api;
11
11
  }
12
12
  createDomRef() {
13
13
  const domRef = document.createElement('div');
@@ -15,7 +15,7 @@ class SyncBlock extends ReactNodeView {
15
15
  return domRef;
16
16
  }
17
17
  render() {
18
- var _this$options, _this$options2;
18
+ var _this$options, _this$api, _this$api$syncedBlock, _this$api$syncedBlock2, _this$options2;
19
19
  if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.syncedBlockRenderer)) {
20
20
  return null;
21
21
  }
@@ -26,13 +26,17 @@ class SyncBlock extends ReactNodeView {
26
26
  if (!resourceId || !localId) {
27
27
  return null;
28
28
  }
29
+ const syncBlockStore = (_this$api = this.api) === null || _this$api === void 0 ? void 0 : (_this$api$syncedBlock = _this$api.syncedBlock) === null || _this$api$syncedBlock === void 0 ? void 0 : (_this$api$syncedBlock2 = _this$api$syncedBlock.sharedState.currentState()) === null || _this$api$syncedBlock2 === void 0 ? void 0 : _this$api$syncedBlock2.syncBlockStore;
30
+ if (!syncBlockStore) {
31
+ return null;
32
+ }
29
33
 
30
34
  // get document node from data provider
31
35
  return /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
32
36
  localId: this.node.attrs.localId,
33
37
  syncedBlockRenderer: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.syncedBlockRenderer,
34
- useFetchSyncBlockTitle: () => useFetchSyncBlockTitle(this.syncBlockStore, this.node),
35
- useFetchSyncBlockData: () => useFetchSyncBlockData(this.syncBlockStore, resourceId, localId)
38
+ useFetchSyncBlockTitle: () => useFetchSyncBlockTitle(syncBlockStore, this.node),
39
+ useFetchSyncBlockData: () => useFetchSyncBlockData(syncBlockStore, resourceId, localId)
36
40
  });
37
41
  }
38
42
  destroy() {
@@ -44,8 +48,7 @@ class SyncBlock extends ReactNodeView {
44
48
  export const syncBlockNodeView = ({
45
49
  options,
46
50
  pmPluginFactoryParams,
47
- api,
48
- syncBlockStore
51
+ api
49
52
  }) => (node, view, getPos) => {
50
53
  const {
51
54
  portalProviderAPI,
@@ -58,7 +61,6 @@ export const syncBlockNodeView = ({
58
61
  view,
59
62
  getPos,
60
63
  portalProviderAPI,
61
- eventDispatcher,
62
- syncBlockStore
64
+ eventDispatcher
63
65
  }).init();
64
66
  };
@@ -3,6 +3,7 @@ import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
3
3
  import { BodiedSyncBlockSharedCssClassName, SyncBlockStateCssClassName } from '@atlaskit/editor-common/sync-block';
4
4
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
5
5
  import { DecorationSet, Decoration } from '@atlaskit/editor-prosemirror/view';
6
+ import { convertPMNodesToSyncBlockNodes } from '@atlaskit/editor-synced-block-provider';
6
7
  import { lazyBodiedSyncBlockView } from '../nodeviews/bodiedLazySyncedBlock';
7
8
  import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
8
9
  import { FLAG_ID } from '../types';
@@ -19,10 +20,11 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
19
20
  state: {
20
21
  init(_, instance) {
21
22
  const syncBlockNodes = instance.doc.children.filter(node => node.type.name === 'syncBlock');
22
- syncBlockStore.fetchSyncBlocksData(syncBlockNodes);
23
+ syncBlockStore.referenceManager.fetchSyncBlocksData(convertPMNodesToSyncBlockNodes(syncBlockNodes));
23
24
  return {
24
25
  selectionDecorationSet: calculateDecorations(instance.doc, instance.selection, instance.schema),
25
- showFlag: false
26
+ showFlag: false,
27
+ syncBlockStore: syncBlockStore
26
28
  };
27
29
  },
28
30
  apply: (tr, currentPluginState, oldEditorState) => {
@@ -38,7 +40,8 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
38
40
  }
39
41
  return {
40
42
  showFlag: (_meta$showFlag = meta === null || meta === void 0 ? void 0 : meta.showFlag) !== null && _meta$showFlag !== void 0 ? _meta$showFlag : showFlag,
41
- selectionDecorationSet: newDecorationSet
43
+ selectionDecorationSet: newDecorationSet,
44
+ syncBlockStore: syncBlockStore
42
45
  };
43
46
  }
44
47
  },
@@ -47,14 +50,12 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
47
50
  syncBlock: lazySyncBlockView({
48
51
  options,
49
52
  pmPluginFactoryParams,
50
- api,
51
- syncBlockStore
53
+ api
52
54
  }),
53
55
  bodiedSyncBlock: lazyBodiedSyncBlockView({
54
56
  pluginOptions: options,
55
57
  pmPluginFactoryParams,
56
- api,
57
- syncBlockStore
58
+ api
58
59
  })
59
60
  },
60
61
  decorations: state => {
@@ -94,10 +95,10 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
94
95
  }
95
96
  },
96
97
  view: editorView => {
97
- syncBlockStore.setEditorView(editorView);
98
+ syncBlockStore.sourceManager.setEditorView(editorView);
98
99
  return {
99
100
  destroy() {
100
- syncBlockStore.setEditorView(undefined);
101
+ syncBlockStore.sourceManager.setEditorView(undefined);
101
102
  }
102
103
  };
103
104
  },
@@ -109,27 +110,27 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
109
110
  // or are from remote (collab) or already confirmed sync block deletion
110
111
  // We only care about local changes that change the document
111
112
  // and are not yet confirmed for sync block deletion
112
- if (!tr.docChanged || !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.requireConfirmationBeforeDelete()) && !syncBlockStore.hasPendingCreation() || Boolean(tr.getMeta('isRemote')) || Boolean(tr.getMeta('isCommitSyncBlockCreation')) || !isOffline && isConfirmedSyncBlockDeletion) {
113
+ if (!tr.docChanged || !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.sourceManager.requireConfirmationBeforeDelete()) && !syncBlockStore.sourceManager.hasPendingCreation() || Boolean(tr.getMeta('isRemote')) || Boolean(tr.getMeta('isCommitSyncBlockCreation')) || !isOffline && isConfirmedSyncBlockDeletion) {
113
114
  return true;
114
115
  }
115
116
  const {
116
117
  removed: bodiedSyncBlockRemoved,
117
118
  added: bodiedSyncBlockAdded
118
- } = trackSyncBlocks(syncBlockStore.isSourceBlock, tr, state);
119
+ } = trackSyncBlocks(syncBlockStore.sourceManager.isSourceBlock, tr, state);
119
120
  if (!isOffline) {
120
121
  if (bodiedSyncBlockRemoved.length > 0) {
121
122
  // If there are source sync blocks being removed, and we need to confirm with user before deleting,
122
123
  // we block the transaction here, and wait for user confirmation to proceed with deletion.
123
124
  // See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
124
125
  // proceed with deletion.
125
- syncBlockStore.deleteSyncBlocksWithConfirmation(tr, bodiedSyncBlockRemoved);
126
+ syncBlockStore.sourceManager.deleteSyncBlocksWithConfirmation(tr, bodiedSyncBlockRemoved);
126
127
  return false;
127
128
  }
128
129
  if (bodiedSyncBlockAdded.length > 0) {
129
130
  // If there is bodiedSyncBlock node addition and it's waiting for the result of saving the node to backend (syncBlockStore.hasPendingCreation()),
130
131
  // 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
131
132
  // The callback will be evoked by in SourceSyncBlockStoreManager.commitPendingCreation
132
- syncBlockStore.registerCreationCallback(() => {
133
+ syncBlockStore.sourceManager.registerCreationCallback(() => {
133
134
  var _api$core;
134
135
  api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(() => {
135
136
  return tr.setMeta('isCommitSyncBlockCreation', true);
@@ -170,7 +171,7 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
170
171
  },
171
172
  appendTransaction: (trs, _oldState, newState) => {
172
173
  trs.filter(tr => tr.docChanged).forEach(tr => {
173
- syncBlockStore === null || syncBlockStore === void 0 ? void 0 : syncBlockStore.rebaseTransaction(tr, newState);
174
+ syncBlockStore === null || syncBlockStore === void 0 ? void 0 : syncBlockStore.sourceManager.rebaseTransaction(tr, newState);
174
175
  });
175
176
  return null;
176
177
  }
@@ -95,10 +95,12 @@ export const syncedBlockPlugin = ({
95
95
  return;
96
96
  }
97
97
  const {
98
- showFlag
98
+ showFlag,
99
+ syncBlockStore: currentSyncBlockStore
99
100
  } = syncedBlockPluginKey.getState(editorState);
100
101
  return {
101
- showFlag
102
+ showFlag,
103
+ syncBlockStore: currentSyncBlockStore
102
104
  };
103
105
  }
104
106
  };
@@ -39,7 +39,7 @@ export const DeleteConfirmationModal = ({
39
39
  return confirmedPromise;
40
40
  }, []);
41
41
  useEffect(() => {
42
- const unregister = syncBlockStoreManager.registerConfirmationCallback(confirmationCallback);
42
+ const unregister = syncBlockStoreManager.sourceManager.registerConfirmationCallback(confirmationCallback);
43
43
  return () => {
44
44
  unregister();
45
45
  };
@@ -23,7 +23,7 @@ export const SyncBlockRefresher = ({
23
23
  var _document;
24
24
  // check if document is visible to avoid unnecessary refreshes
25
25
  if (((_document = document) === null || _document === void 0 ? void 0 : _document.visibilityState) === 'visible') {
26
- syncBlockStoreManager.refreshSubscriptions();
26
+ syncBlockStoreManager.referenceManager.refreshSubscriptions();
27
27
  }
28
28
  }, SYNC_BLOCK_FETCH_INTERVAL);
29
29
  } else if (interval !== -1) {
@@ -45,7 +45,7 @@ export const getToolbarConfig = (state, intl, api, syncBlockStore) => {
45
45
  ...hoverDecorationProps(nodeType, akEditorSelectedNodeClassName)
46
46
  };
47
47
  items.push(copyButton);
48
- const disabled = !syncBlockStore.getSyncBlockURL(syncBlockObject.node.attrs.resourceId);
48
+ const disabled = !syncBlockStore.referenceManager.getSyncBlockURL(syncBlockObject.node.attrs.resourceId);
49
49
  if (!isBodiedSyncBlock) {
50
50
  const editSourceButton = {
51
51
  id: 'editor.syncedBlock.editSource',
@@ -1,3 +1,3 @@
1
1
  export var flushBodiedSyncBlocks = function flushBodiedSyncBlocks(syncBlockStore) {
2
- return syncBlockStore.flushBodiedSyncBlocks();
2
+ return syncBlockStore.sourceManager.flush();
3
3
  };
@@ -13,7 +13,7 @@ export var createSyncedBlock = function createSyncedBlock(_ref) {
13
13
 
14
14
  // If the selection is empty, we want to insert the sync block on a new line
15
15
  if (tr.selection.empty) {
16
- var attrs = syncBlockStore.generateBodiedSyncBlockAttrs();
16
+ var attrs = syncBlockStore.sourceManager.generateBodiedSyncBlockAttrs();
17
17
  var paragraphNode = paragraph.createAndFill({});
18
18
  var newBodiedSyncBlockNode = bodiedSyncBlock.createAndFill(attrs, paragraphNode ? [paragraphNode] : []);
19
19
  if (!newBodiedSyncBlockNode) {
@@ -22,7 +22,7 @@ export var createSyncedBlock = function createSyncedBlock(_ref) {
22
22
 
23
23
  // Save the new node with empty content to backend
24
24
  // This is so that the node can be copied and referenced without the source being saved/published
25
- syncBlockStore.createBodiedSyncBlockNode(attrs);
25
+ syncBlockStore.sourceManager.createBodiedSyncBlockNode(attrs);
26
26
  if (typeAheadInsert) {
27
27
  tr = typeAheadInsert(newBodiedSyncBlockNode);
28
28
  } else {
@@ -34,7 +34,7 @@ export var createSyncedBlock = function createSyncedBlock(_ref) {
34
34
  // TODO: EDITOR-1665 - Raise an error analytics event
35
35
  return false;
36
36
  }
37
- var _attrs = syncBlockStore.generateBodiedSyncBlockAttrs();
37
+ var _attrs = syncBlockStore.sourceManager.generateBodiedSyncBlockAttrs();
38
38
  var _newBodiedSyncBlockNode = bodiedSyncBlock.createAndFill(_attrs, conversionInfo.contentToInclude);
39
39
  if (!_newBodiedSyncBlockNode) {
40
40
  return false;
@@ -42,7 +42,7 @@ export var createSyncedBlock = function createSyncedBlock(_ref) {
42
42
 
43
43
  // Save the new node with empty content to backend
44
44
  // This is so that the node can be copied and referenced without the source being saved/published
45
- syncBlockStore.createBodiedSyncBlockNode(_attrs);
45
+ syncBlockStore.sourceManager.createBodiedSyncBlockNode(_attrs);
46
46
  tr.replaceWith(conversionInfo.from > 0 ? conversionInfo.from - 1 : 0, conversionInfo.to, _newBodiedSyncBlockNode).scrollIntoView();
47
47
 
48
48
  // set selection to the end of the previous selection + 1 for the position taken up by the start of the new synced block
@@ -98,7 +98,7 @@ export var editSyncedBlockSource = function editSyncedBlockSource(syncBlockStore
98
98
  if (!resourceId) {
99
99
  return false;
100
100
  }
101
- var syncBlockURL = syncBlockStore.getSyncBlockURL(resourceId);
101
+ var syncBlockURL = syncBlockStore.referenceManager.getSyncBlockURL(resourceId);
102
102
  if (syncBlockURL) {
103
103
  window.open(syncBlockURL, '_blank');
104
104
  } else {
@@ -21,7 +21,6 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
21
21
  var _this;
22
22
  _classCallCheck(this, BodiedSyncBlock);
23
23
  _this = _callSuper(this, BodiedSyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
24
- _this.syncBlockStore = props.syncBlockStore;
25
24
  _this.api = props.api;
26
25
  _this.handleConnectivityModeChange();
27
26
  _this.handleViewModeChange();
@@ -82,9 +81,14 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
82
81
  }, {
83
82
  key: "render",
84
83
  value: function render(_props, forwardRef) {
84
+ var _this$api5;
85
+ var syncBlockStore = (_this$api5 = this.api) === null || _this$api5 === void 0 || (_this$api5 = _this$api5.syncedBlock.sharedState) === null || _this$api5 === void 0 || (_this$api5 = _this$api5.currentState()) === null || _this$api5 === void 0 ? void 0 : _this$api5.syncBlockStore;
86
+ if (!syncBlockStore) {
87
+ return null;
88
+ }
85
89
  return /*#__PURE__*/React.createElement(BodiedSyncBlockWrapper, {
86
90
  ref: forwardRef,
87
- syncBlockStore: this.syncBlockStore,
91
+ syncBlockStore: syncBlockStore,
88
92
  node: this.node
89
93
  });
90
94
  }
@@ -120,8 +124,7 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
120
124
  export var bodiedSyncBlockNodeView = function bodiedSyncBlockNodeView(_ref4) {
121
125
  var pluginOptions = _ref4.pluginOptions,
122
126
  pmPluginFactoryParams = _ref4.pmPluginFactoryParams,
123
- api = _ref4.api,
124
- syncBlockStore = _ref4.syncBlockStore;
127
+ api = _ref4.api;
125
128
  return function (node, view, getPos) {
126
129
  var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
127
130
  eventDispatcher = pmPluginFactoryParams.eventDispatcher;
@@ -132,8 +135,7 @@ export var bodiedSyncBlockNodeView = function bodiedSyncBlockNodeView(_ref4) {
132
135
  view: view,
133
136
  getPos: getPos,
134
137
  portalProviderAPI: portalProviderAPI,
135
- eventDispatcher: eventDispatcher,
136
- syncBlockStore: syncBlockStore
138
+ eventDispatcher: eventDispatcher
137
139
  }).init();
138
140
  };
139
141
  };
@@ -18,7 +18,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
18
18
  _classCallCheck(this, SyncBlock);
19
19
  _this = _callSuper(this, SyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
20
20
  _this.options = props.options;
21
- _this.syncBlockStore = props.syncBlockStore;
21
+ _this.api = props.api;
22
22
  return _this;
23
23
  }
24
24
  _inherits(SyncBlock, _ReactNodeView);
@@ -33,6 +33,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
33
33
  key: "render",
34
34
  value: function render() {
35
35
  var _this$options,
36
+ _this$api,
36
37
  _this$options2,
37
38
  _this2 = this;
38
39
  if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.syncedBlockRenderer)) {
@@ -44,16 +45,20 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
44
45
  if (!resourceId || !localId) {
45
46
  return null;
46
47
  }
48
+ var syncBlockStore = (_this$api = this.api) === null || _this$api === void 0 || (_this$api = _this$api.syncedBlock) === null || _this$api === void 0 || (_this$api = _this$api.sharedState.currentState()) === null || _this$api === void 0 ? void 0 : _this$api.syncBlockStore;
49
+ if (!syncBlockStore) {
50
+ return null;
51
+ }
47
52
 
48
53
  // get document node from data provider
49
54
  return /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
50
55
  localId: this.node.attrs.localId,
51
56
  syncedBlockRenderer: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.syncedBlockRenderer,
52
57
  useFetchSyncBlockTitle: function useFetchSyncBlockTitle() {
53
- return _useFetchSyncBlockTitle(_this2.syncBlockStore, _this2.node);
58
+ return _useFetchSyncBlockTitle(syncBlockStore, _this2.node);
54
59
  },
55
60
  useFetchSyncBlockData: function useFetchSyncBlockData() {
56
- return _useFetchSyncBlockData(_this2.syncBlockStore, resourceId, localId);
61
+ return _useFetchSyncBlockData(syncBlockStore, resourceId, localId);
57
62
  }
58
63
  });
59
64
  }
@@ -69,8 +74,7 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
69
74
  export var syncBlockNodeView = function syncBlockNodeView(_ref) {
70
75
  var options = _ref.options,
71
76
  pmPluginFactoryParams = _ref.pmPluginFactoryParams,
72
- api = _ref.api,
73
- syncBlockStore = _ref.syncBlockStore;
77
+ api = _ref.api;
74
78
  return function (node, view, getPos) {
75
79
  var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
76
80
  eventDispatcher = pmPluginFactoryParams.eventDispatcher;
@@ -81,8 +85,7 @@ export var syncBlockNodeView = function syncBlockNodeView(_ref) {
81
85
  view: view,
82
86
  getPos: getPos,
83
87
  portalProviderAPI: portalProviderAPI,
84
- eventDispatcher: eventDispatcher,
85
- syncBlockStore: syncBlockStore
88
+ eventDispatcher: eventDispatcher
86
89
  }).init();
87
90
  };
88
91
  };
@@ -3,6 +3,7 @@ import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
3
3
  import { BodiedSyncBlockSharedCssClassName, SyncBlockStateCssClassName } from '@atlaskit/editor-common/sync-block';
4
4
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
5
5
  import { DecorationSet, Decoration } from '@atlaskit/editor-prosemirror/view';
6
+ import { convertPMNodesToSyncBlockNodes } from '@atlaskit/editor-synced-block-provider';
6
7
  import { lazyBodiedSyncBlockView } from '../nodeviews/bodiedLazySyncedBlock';
7
8
  import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
8
9
  import { FLAG_ID } from '../types';
@@ -21,10 +22,11 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
21
22
  var syncBlockNodes = instance.doc.children.filter(function (node) {
22
23
  return node.type.name === 'syncBlock';
23
24
  });
24
- syncBlockStore.fetchSyncBlocksData(syncBlockNodes);
25
+ syncBlockStore.referenceManager.fetchSyncBlocksData(convertPMNodesToSyncBlockNodes(syncBlockNodes));
25
26
  return {
26
27
  selectionDecorationSet: calculateDecorations(instance.doc, instance.selection, instance.schema),
27
- showFlag: false
28
+ showFlag: false,
29
+ syncBlockStore: syncBlockStore
28
30
  };
29
31
  },
30
32
  apply: function apply(tr, currentPluginState, oldEditorState) {
@@ -38,7 +40,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
38
40
  }
39
41
  return {
40
42
  showFlag: (_meta$showFlag = meta === null || meta === void 0 ? void 0 : meta.showFlag) !== null && _meta$showFlag !== void 0 ? _meta$showFlag : showFlag,
41
- selectionDecorationSet: newDecorationSet
43
+ selectionDecorationSet: newDecorationSet,
44
+ syncBlockStore: syncBlockStore
42
45
  };
43
46
  }
44
47
  },
@@ -47,14 +50,12 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
47
50
  syncBlock: lazySyncBlockView({
48
51
  options: options,
49
52
  pmPluginFactoryParams: pmPluginFactoryParams,
50
- api: api,
51
- syncBlockStore: syncBlockStore
53
+ api: api
52
54
  }),
53
55
  bodiedSyncBlock: lazyBodiedSyncBlockView({
54
56
  pluginOptions: options,
55
57
  pmPluginFactoryParams: pmPluginFactoryParams,
56
- api: api,
57
- syncBlockStore: syncBlockStore
58
+ api: api
58
59
  })
59
60
  },
60
61
  decorations: function decorations(state) {
@@ -94,10 +95,10 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
94
95
  }
95
96
  },
96
97
  view: function view(editorView) {
97
- syncBlockStore.setEditorView(editorView);
98
+ syncBlockStore.sourceManager.setEditorView(editorView);
98
99
  return {
99
100
  destroy: function destroy() {
100
- syncBlockStore.setEditorView(undefined);
101
+ syncBlockStore.sourceManager.setEditorView(undefined);
101
102
  }
102
103
  };
103
104
  },
@@ -109,10 +110,10 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
109
110
  // or are from remote (collab) or already confirmed sync block deletion
110
111
  // We only care about local changes that change the document
111
112
  // and are not yet confirmed for sync block deletion
112
- if (!tr.docChanged || !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.requireConfirmationBeforeDelete()) && !syncBlockStore.hasPendingCreation() || Boolean(tr.getMeta('isRemote')) || Boolean(tr.getMeta('isCommitSyncBlockCreation')) || !isOffline && isConfirmedSyncBlockDeletion) {
113
+ if (!tr.docChanged || !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.sourceManager.requireConfirmationBeforeDelete()) && !syncBlockStore.sourceManager.hasPendingCreation() || Boolean(tr.getMeta('isRemote')) || Boolean(tr.getMeta('isCommitSyncBlockCreation')) || !isOffline && isConfirmedSyncBlockDeletion) {
113
114
  return true;
114
115
  }
115
- var _trackSyncBlocks = trackSyncBlocks(syncBlockStore.isSourceBlock, tr, state),
116
+ var _trackSyncBlocks = trackSyncBlocks(syncBlockStore.sourceManager.isSourceBlock, tr, state),
116
117
  bodiedSyncBlockRemoved = _trackSyncBlocks.removed,
117
118
  bodiedSyncBlockAdded = _trackSyncBlocks.added;
118
119
  if (!isOffline) {
@@ -121,14 +122,14 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
121
122
  // we block the transaction here, and wait for user confirmation to proceed with deletion.
122
123
  // See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
123
124
  // proceed with deletion.
124
- syncBlockStore.deleteSyncBlocksWithConfirmation(tr, bodiedSyncBlockRemoved);
125
+ syncBlockStore.sourceManager.deleteSyncBlocksWithConfirmation(tr, bodiedSyncBlockRemoved);
125
126
  return false;
126
127
  }
127
128
  if (bodiedSyncBlockAdded.length > 0) {
128
129
  // If there is bodiedSyncBlock node addition and it's waiting for the result of saving the node to backend (syncBlockStore.hasPendingCreation()),
129
130
  // 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
130
131
  // The callback will be evoked by in SourceSyncBlockStoreManager.commitPendingCreation
131
- syncBlockStore.registerCreationCallback(function () {
132
+ syncBlockStore.sourceManager.registerCreationCallback(function () {
132
133
  var _api$core;
133
134
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function () {
134
135
  return tr.setMeta('isCommitSyncBlockCreation', true);
@@ -171,7 +172,7 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
171
172
  trs.filter(function (tr) {
172
173
  return tr.docChanged;
173
174
  }).forEach(function (tr) {
174
- syncBlockStore === null || syncBlockStore === void 0 || syncBlockStore.rebaseTransaction(tr, newState);
175
+ syncBlockStore === null || syncBlockStore === void 0 || syncBlockStore.sourceManager.rebaseTransaction(tr, newState);
175
176
  });
176
177
  return null;
177
178
  }
@@ -106,9 +106,11 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
106
106
  return;
107
107
  }
108
108
  var _syncedBlockPluginKey = syncedBlockPluginKey.getState(editorState),
109
- showFlag = _syncedBlockPluginKey.showFlag;
109
+ showFlag = _syncedBlockPluginKey.showFlag,
110
+ currentSyncBlockStore = _syncedBlockPluginKey.syncBlockStore;
110
111
  return {
111
- showFlag: showFlag
112
+ showFlag: showFlag,
113
+ syncBlockStore: currentSyncBlockStore
112
114
  };
113
115
  }
114
116
  };
@@ -45,7 +45,7 @@ export var DeleteConfirmationModal = function DeleteConfirmationModal(_ref) {
45
45
  return confirmedPromise;
46
46
  }, []);
47
47
  useEffect(function () {
48
- var unregister = syncBlockStoreManager.registerConfirmationCallback(confirmationCallback);
48
+ var unregister = syncBlockStoreManager.sourceManager.registerConfirmationCallback(confirmationCallback);
49
49
  return function () {
50
50
  unregister();
51
51
  };
@@ -21,7 +21,7 @@ export var SyncBlockRefresher = function SyncBlockRefresher(_ref) {
21
21
  var _document;
22
22
  // check if document is visible to avoid unnecessary refreshes
23
23
  if (((_document = document) === null || _document === void 0 ? void 0 : _document.visibilityState) === 'visible') {
24
- syncBlockStoreManager.refreshSubscriptions();
24
+ syncBlockStoreManager.referenceManager.refreshSubscriptions();
25
25
  }
26
26
  }, SYNC_BLOCK_FETCH_INTERVAL);
27
27
  } else if (interval !== -1) {
@@ -41,7 +41,7 @@ export var getToolbarConfig = function getToolbarConfig(state, intl, api, syncBl
41
41
  onClick: copySyncedBlockReferenceToClipboard
42
42
  }, hoverDecorationProps(nodeType, akEditorSelectedNodeClassName));
43
43
  items.push(copyButton);
44
- var disabled = !syncBlockStore.getSyncBlockURL(syncBlockObject.node.attrs.resourceId);
44
+ var disabled = !syncBlockStore.referenceManager.getSyncBlockURL(syncBlockObject.node.attrs.resourceId);
45
45
  if (!isBodiedSyncBlock) {
46
46
  var editSourceButton = _objectSpread({
47
47
  id: 'editor.syncedBlock.editSource',
@@ -5,7 +5,6 @@ import ReactNodeView, { type getPosHandler } from '@atlaskit/editor-common/react
5
5
  import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
6
6
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
7
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
- import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
9
8
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
10
9
  export interface BodiedSyncBlockNodeViewProps extends ReactComponentProps {
11
10
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
@@ -14,13 +13,11 @@ export interface BodiedSyncBlockNodeViewProps extends ReactComponentProps {
14
13
  node: PMNode;
15
14
  pluginOptions: SyncedBlockPluginOptions | undefined;
16
15
  portalProviderAPI: PortalProviderAPI;
17
- syncBlockStore: SyncBlockStoreManager;
18
16
  view: EditorView;
19
17
  }
20
18
  export interface BodiedSyncBlockNodeViewProperties {
21
19
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
22
20
  pluginOptions: SyncedBlockPluginOptions | undefined;
23
21
  pmPluginFactoryParams: PMPluginFactoryParams;
24
- syncBlockStore: SyncBlockStoreManager;
25
22
  }
26
23
  export declare const bodiedSyncBlockNodeView: (props: BodiedSyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: getPosHandler) => ReactNodeView<BodiedSyncBlockNodeViewProps>;
@@ -5,7 +5,6 @@ import type { ReactComponentProps } from '@atlaskit/editor-common/react-node-vie
5
5
  import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
6
6
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
7
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
- import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
9
8
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
10
9
  export interface SyncBlockNodeViewProps extends ReactComponentProps {
11
10
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
@@ -15,13 +14,11 @@ export interface SyncBlockNodeViewProps extends ReactComponentProps {
15
14
  node: PMNode;
16
15
  options: SyncedBlockPluginOptions | undefined;
17
16
  portalProviderAPI: PortalProviderAPI;
18
- syncBlockStore: SyncBlockStoreManager;
19
17
  view: EditorView;
20
18
  }
21
19
  export interface SyncBlockNodeViewProperties {
22
20
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
23
21
  options: SyncedBlockPluginOptions | undefined;
24
22
  pmPluginFactoryParams: PMPluginFactoryParams;
25
- syncBlockStore: SyncBlockStoreManager;
26
23
  }
27
24
  export declare const syncBlockNodeView: (props: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: getPosHandler) => ReactNodeView<SyncBlockNodeViewProps>;
@@ -2,13 +2,14 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
3
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
4
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
- import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
5
+ import { type SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
6
6
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
7
7
  import { FLAG_ID } from '../types';
8
8
  export declare const syncedBlockPluginKey: PluginKey<any>;
9
9
  type SyncedBlockPluginState = {
10
10
  selectionDecorationSet: DecorationSet;
11
11
  showFlag: FLAG_ID | false;
12
+ syncBlockStore: SyncBlockStoreManager;
12
13
  };
13
14
  export declare const createPlugin: (options: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams, syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => SafePlugin<SyncedBlockPluginState>;
14
15
  export {};
@@ -1,3 +1,4 @@
1
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
1
2
  export declare enum FLAG_ID {
2
3
  CANNOT_DELETE_WHEN_OFFLINE = "cannot-delete-when-offline",
3
4
  CANNOT_EDIT_WHEN_OFFLINE = "cannot-edit-when-offline",
@@ -8,4 +9,8 @@ export type SyncedBlockSharedState = {
8
9
  * Whether to show a flag (usually for errors, e.g. fail to delete)
9
10
  */
10
11
  showFlag: FLAG_ID | false;
12
+ /**
13
+ * The current sync block store manager, used to manage fetching and updating sync block data
14
+ */
15
+ syncBlockStore: SyncBlockStoreManager;
11
16
  };
@@ -5,7 +5,6 @@ import ReactNodeView, { type getPosHandler } from '@atlaskit/editor-common/react
5
5
  import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
6
6
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
7
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
- import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
9
8
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
10
9
  export interface BodiedSyncBlockNodeViewProps extends ReactComponentProps {
11
10
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
@@ -14,13 +13,11 @@ export interface BodiedSyncBlockNodeViewProps extends ReactComponentProps {
14
13
  node: PMNode;
15
14
  pluginOptions: SyncedBlockPluginOptions | undefined;
16
15
  portalProviderAPI: PortalProviderAPI;
17
- syncBlockStore: SyncBlockStoreManager;
18
16
  view: EditorView;
19
17
  }
20
18
  export interface BodiedSyncBlockNodeViewProperties {
21
19
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
22
20
  pluginOptions: SyncedBlockPluginOptions | undefined;
23
21
  pmPluginFactoryParams: PMPluginFactoryParams;
24
- syncBlockStore: SyncBlockStoreManager;
25
22
  }
26
23
  export declare const bodiedSyncBlockNodeView: (props: BodiedSyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: getPosHandler) => ReactNodeView<BodiedSyncBlockNodeViewProps>;
@@ -5,7 +5,6 @@ import type { ReactComponentProps } from '@atlaskit/editor-common/react-node-vie
5
5
  import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
6
6
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
7
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
- import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
9
8
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
10
9
  export interface SyncBlockNodeViewProps extends ReactComponentProps {
11
10
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
@@ -15,13 +14,11 @@ export interface SyncBlockNodeViewProps extends ReactComponentProps {
15
14
  node: PMNode;
16
15
  options: SyncedBlockPluginOptions | undefined;
17
16
  portalProviderAPI: PortalProviderAPI;
18
- syncBlockStore: SyncBlockStoreManager;
19
17
  view: EditorView;
20
18
  }
21
19
  export interface SyncBlockNodeViewProperties {
22
20
  api?: ExtractInjectionAPI<SyncedBlockPlugin>;
23
21
  options: SyncedBlockPluginOptions | undefined;
24
22
  pmPluginFactoryParams: PMPluginFactoryParams;
25
- syncBlockStore: SyncBlockStoreManager;
26
23
  }
27
24
  export declare const syncBlockNodeView: (props: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: getPosHandler) => ReactNodeView<SyncBlockNodeViewProps>;
@@ -2,13 +2,14 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
3
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
4
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
- import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
5
+ import { type SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
6
6
  import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
7
7
  import { FLAG_ID } from '../types';
8
8
  export declare const syncedBlockPluginKey: PluginKey<any>;
9
9
  type SyncedBlockPluginState = {
10
10
  selectionDecorationSet: DecorationSet;
11
11
  showFlag: FLAG_ID | false;
12
+ syncBlockStore: SyncBlockStoreManager;
12
13
  };
13
14
  export declare const createPlugin: (options: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams, syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => SafePlugin<SyncedBlockPluginState>;
14
15
  export {};
@@ -1,3 +1,4 @@
1
+ import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
1
2
  export declare enum FLAG_ID {
2
3
  CANNOT_DELETE_WHEN_OFFLINE = "cannot-delete-when-offline",
3
4
  CANNOT_EDIT_WHEN_OFFLINE = "cannot-edit-when-offline",
@@ -8,4 +9,8 @@ export type SyncedBlockSharedState = {
8
9
  * Whether to show a flag (usually for errors, e.g. fail to delete)
9
10
  */
10
11
  showFlag: FLAG_ID | false;
12
+ /**
13
+ * The current sync block store manager, used to manage fetching and updating sync block data
14
+ */
15
+ syncBlockStore: SyncBlockStoreManager;
11
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-synced-block",
3
- "version": "4.2.13",
3
+ "version": "4.2.15",
4
4
  "description": "SyncedBlock plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -56,7 +56,7 @@
56
56
  "react-intl-next": "npm:react-intl@^5.18.1"
57
57
  },
58
58
  "peerDependencies": {
59
- "@atlaskit/editor-common": "^110.32.0",
59
+ "@atlaskit/editor-common": "^110.33.0",
60
60
  "react": "^18.2.0"
61
61
  },
62
62
  "devDependencies": {