@atlaskit/editor-synced-block-provider 4.3.6 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/hooks/useHandleContentChanges.js +1 -1
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +12 -7
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +16 -6
- package/dist/cjs/store-manager/syncBlockStoreManager.js +7 -2
- package/dist/es2019/hooks/useHandleContentChanges.js +1 -1
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +3 -0
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +16 -6
- package/dist/es2019/store-manager/syncBlockStoreManager.js +5 -2
- package/dist/esm/hooks/useHandleContentChanges.js +1 -1
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +12 -7
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +16 -6
- package/dist/esm/store-manager/syncBlockStoreManager.js +7 -2
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +3 -2
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +3 -1
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +1 -0
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +3 -2
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +3 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 4.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 4.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`dd9c0778c3832`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/dd9c0778c3832) -
|
|
14
|
+
Add \_\_livePage option to syncedBlock plugin and store managers. Add isReferenceBlock/isSyncBlock
|
|
15
|
+
methods. Use predicate functions instead of hardcoded node type names. Fix isDirty logic for
|
|
16
|
+
remote transactions. Fix flush() view-mode return value.
|
|
17
|
+
|
|
3
18
|
## 4.3.6
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -10,6 +10,6 @@ var useHandleContentChanges = exports.useHandleContentChanges = function useHand
|
|
|
10
10
|
// node content is modified by a ProseMirror transaction, which is exactly
|
|
11
11
|
// when the source manager cache needs to be updated.
|
|
12
12
|
(0, _react.useEffect)(function () {
|
|
13
|
-
manager.sourceManager.updateSyncBlockData(syncBlockNode);
|
|
13
|
+
manager.sourceManager.updateSyncBlockData(syncBlockNode, false);
|
|
14
14
|
}, [manager, syncBlockNode]);
|
|
15
15
|
};
|
|
@@ -109,14 +109,19 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
109
109
|
// The provider might have SSR data cache already set, so we need to update the cache in session memory storage
|
|
110
110
|
this.setSSRDataInSessionCache((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getNodeDataCacheKeys());
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Enables or disables real-time GraphQL subscriptions for block updates.
|
|
115
|
-
* When enabled, the store manager will subscribe to real-time updates
|
|
116
|
-
* instead of relying on polling.
|
|
117
|
-
* @param enabled - Whether to enable real-time subscriptions
|
|
118
|
-
*/
|
|
119
112
|
return (0, _createClass2.default)(ReferenceSyncBlockStoreManager, [{
|
|
113
|
+
key: "isReferenceBlock",
|
|
114
|
+
value: function isReferenceBlock(node) {
|
|
115
|
+
return node.type.name === 'syncBlock';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Enables or disables real-time GraphQL subscriptions for block updates.
|
|
120
|
+
* When enabled, the store manager will subscribe to real-time updates
|
|
121
|
+
* instead of relying on polling.
|
|
122
|
+
* @param enabled - Whether to enable real-time subscriptions
|
|
123
|
+
*/
|
|
124
|
+
}, {
|
|
120
125
|
key: "setRealTimeSubscriptionsEnabled",
|
|
121
126
|
value: function setRealTimeSubscriptionsEnabled(enabled) {
|
|
122
127
|
this._subscriptionManager.setRealTimeSubscriptionsEnabled(enabled);
|
|
@@ -26,7 +26,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
26
26
|
// Handles caching, debouncing updates, and publish/subscribe for local changes.
|
|
27
27
|
// Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
|
|
28
28
|
var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
29
|
-
function SourceSyncBlockStoreManager(dataProvider, viewMode) {
|
|
29
|
+
function SourceSyncBlockStoreManager(dataProvider, viewMode, isLivePage) {
|
|
30
30
|
var _this = this;
|
|
31
31
|
(0, _classCallCheck2.default)(this, SourceSyncBlockStoreManager);
|
|
32
32
|
(0, _defineProperty2.default)(this, "hasReceivedContentChange", false);
|
|
@@ -41,6 +41,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
41
41
|
});
|
|
42
42
|
this.dataProvider = dataProvider;
|
|
43
43
|
this.viewMode = viewMode;
|
|
44
|
+
this.isLivePage = isLivePage;
|
|
44
45
|
this.syncBlockCache = new Map();
|
|
45
46
|
this.creationCompletionCallbacks = new Map();
|
|
46
47
|
}
|
|
@@ -76,7 +77,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
76
77
|
*/
|
|
77
78
|
}, {
|
|
78
79
|
key: "updateSyncBlockData",
|
|
79
|
-
value: function updateSyncBlockData(syncBlockNode) {
|
|
80
|
+
value: function updateSyncBlockData(syncBlockNode, isRemote) {
|
|
80
81
|
try {
|
|
81
82
|
if (this.viewMode === 'view' && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8')) {
|
|
82
83
|
return false;
|
|
@@ -99,11 +100,13 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
99
100
|
return true;
|
|
100
101
|
}
|
|
101
102
|
var syncBlockData = (0, _utils.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
|
|
102
|
-
if (cachedBlock) {
|
|
103
|
+
if (cachedBlock && !isRemote) {
|
|
103
104
|
this.hasReceivedContentChange = true;
|
|
104
105
|
}
|
|
106
|
+
var isDirty = !isRemote || !cachedBlock; // if the change is not remote, or the block is not in the cache yet, it's dirty
|
|
105
107
|
this.syncBlockCache.set(resourceId, _objectSpread(_objectSpread({}, syncBlockData), {}, {
|
|
106
|
-
isDirty:
|
|
108
|
+
isDirty: isDirty,
|
|
109
|
+
// if the change is from remote, it's not dirty
|
|
107
110
|
contentFragment: syncBlockNode.content
|
|
108
111
|
}));
|
|
109
112
|
} else {
|
|
@@ -145,7 +148,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
145
148
|
_context.next = 3;
|
|
146
149
|
break;
|
|
147
150
|
}
|
|
148
|
-
return _context.abrupt("return",
|
|
151
|
+
return _context.abrupt("return", true);
|
|
149
152
|
case 3:
|
|
150
153
|
bodiedSyncBlockNodes = [];
|
|
151
154
|
bodiedSyncBlockData = [];
|
|
@@ -256,6 +259,13 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
256
259
|
if (this.viewMode === 'view' && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8')) {
|
|
257
260
|
return false;
|
|
258
261
|
}
|
|
262
|
+
|
|
263
|
+
// Only track unsaved changes in source synced block for live pages
|
|
264
|
+
// classic pages's draft don't publish synced block content to block service and the content itself is saved as part of the draft
|
|
265
|
+
// classic page's publish flow will trigger a flush which only uses the isDirty flag to determine if there are unsaved changes
|
|
266
|
+
if (!this.isLivePage) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
259
269
|
return this.hasReceivedContentChange && Array.from(this.syncBlockCache.values()).some(function (syncBlockData) {
|
|
260
270
|
return syncBlockData.isDirty;
|
|
261
271
|
});
|
|
@@ -356,7 +366,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
356
366
|
}
|
|
357
367
|
if ((0, _platformFeatureFlags.fg)('platform_synced_block_update_refactor')) {
|
|
358
368
|
// add the node to the cache
|
|
359
|
-
this.updateSyncBlockData(node);
|
|
369
|
+
this.updateSyncBlockData(node, false);
|
|
360
370
|
}
|
|
361
371
|
this.creationCompletionCallbacks.set(resourceId, onCompletion);
|
|
362
372
|
(_this$createExperienc = this.createExperience) === null || _this$createExperienc === void 0 || _this$createExperienc.start({});
|
|
@@ -27,16 +27,21 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
27
27
|
// SourceSyncBlockStoreManager is responsible for the lifecycle and state management of source sync blocks in an editor instance.
|
|
28
28
|
// Can be used in both editor and renderer contexts.
|
|
29
29
|
var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
30
|
-
function SyncBlockStoreManager(dataProvider, viewMode) {
|
|
30
|
+
function SyncBlockStoreManager(dataProvider, viewMode, isLivePage) {
|
|
31
31
|
(0, _classCallCheck2.default)(this, SyncBlockStoreManager);
|
|
32
32
|
// In future, if reference manager needs to reach to source manager and read its current in memory cache
|
|
33
33
|
// we can pass the source manager as a parameter to the reference manager constructor
|
|
34
|
-
this.sourceSyncBlockStoreManager = new _sourceSyncBlockStoreManager.SourceSyncBlockStoreManager(dataProvider, viewMode);
|
|
34
|
+
this.sourceSyncBlockStoreManager = new _sourceSyncBlockStoreManager.SourceSyncBlockStoreManager(dataProvider, viewMode, isLivePage);
|
|
35
35
|
this.referenceSyncBlockStoreManager = new _referenceSyncBlockStoreManager.ReferenceSyncBlockStoreManager(dataProvider, viewMode);
|
|
36
36
|
this.dataProvider = dataProvider;
|
|
37
37
|
this.referenceSyncBlockStoreManager.setRealTimeSubscriptionsEnabled(true);
|
|
38
38
|
}
|
|
39
39
|
return (0, _createClass2.default)(SyncBlockStoreManager, [{
|
|
40
|
+
key: "isSyncBlock",
|
|
41
|
+
value: function isSyncBlock(node) {
|
|
42
|
+
return this.sourceSyncBlockStoreManager.isSourceBlock(node) || this.referenceSyncBlockStoreManager.isReferenceBlock(node);
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
40
45
|
key: "fetchReferencesSourceInfo",
|
|
41
46
|
value: function () {
|
|
42
47
|
var _fetchReferencesSourceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resourceId, blockInstanceId, isSourceSyncBlock) {
|
|
@@ -4,6 +4,6 @@ export const useHandleContentChanges = (manager, syncBlockNode) => {
|
|
|
4
4
|
// node content is modified by a ProseMirror transaction, which is exactly
|
|
5
5
|
// when the source manager cache needs to be updated.
|
|
6
6
|
useEffect(() => {
|
|
7
|
-
manager.sourceManager.updateSyncBlockData(syncBlockNode);
|
|
7
|
+
manager.sourceManager.updateSyncBlockData(syncBlockNode, false);
|
|
8
8
|
}, [manager, syncBlockNode]);
|
|
9
9
|
};
|
|
@@ -64,6 +64,9 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
64
64
|
// The provider might have SSR data cache already set, so we need to update the cache in session memory storage
|
|
65
65
|
this.setSSRDataInSessionCache((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getNodeDataCacheKeys());
|
|
66
66
|
}
|
|
67
|
+
isReferenceBlock(node) {
|
|
68
|
+
return node.type.name === 'syncBlock';
|
|
69
|
+
}
|
|
67
70
|
|
|
68
71
|
/**
|
|
69
72
|
* Enables or disables real-time GraphQL subscriptions for block updates.
|
|
@@ -13,7 +13,7 @@ import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
|
|
|
13
13
|
// Handles caching, debouncing updates, and publish/subscribe for local changes.
|
|
14
14
|
// Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
|
|
15
15
|
export class SourceSyncBlockStoreManager {
|
|
16
|
-
constructor(dataProvider, viewMode) {
|
|
16
|
+
constructor(dataProvider, viewMode, isLivePage) {
|
|
17
17
|
_defineProperty(this, "hasReceivedContentChange", false);
|
|
18
18
|
_defineProperty(this, "setPendingDeletion", (Ids, value) => {
|
|
19
19
|
if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
@@ -26,6 +26,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
26
26
|
});
|
|
27
27
|
this.dataProvider = dataProvider;
|
|
28
28
|
this.viewMode = viewMode;
|
|
29
|
+
this.isLivePage = isLivePage;
|
|
29
30
|
this.syncBlockCache = new Map();
|
|
30
31
|
this.creationCompletionCallbacks = new Map();
|
|
31
32
|
}
|
|
@@ -53,7 +54,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
53
54
|
* Add/update a sync block node to/from the local cache
|
|
54
55
|
* @param syncBlockNode - The sync block node to update
|
|
55
56
|
*/
|
|
56
|
-
updateSyncBlockData(syncBlockNode) {
|
|
57
|
+
updateSyncBlockData(syncBlockNode, isRemote) {
|
|
57
58
|
try {
|
|
58
59
|
if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
59
60
|
return false;
|
|
@@ -77,12 +78,14 @@ export class SourceSyncBlockStoreManager {
|
|
|
77
78
|
return true;
|
|
78
79
|
}
|
|
79
80
|
const syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
|
|
80
|
-
if (cachedBlock) {
|
|
81
|
+
if (cachedBlock && !isRemote) {
|
|
81
82
|
this.hasReceivedContentChange = true;
|
|
82
83
|
}
|
|
84
|
+
const isDirty = !isRemote || !cachedBlock; // if the change is not remote, or the block is not in the cache yet, it's dirty
|
|
83
85
|
this.syncBlockCache.set(resourceId, {
|
|
84
86
|
...syncBlockData,
|
|
85
|
-
isDirty:
|
|
87
|
+
isDirty: isDirty,
|
|
88
|
+
// if the change is from remote, it's not dirty
|
|
86
89
|
contentFragment: syncBlockNode.content
|
|
87
90
|
});
|
|
88
91
|
} else {
|
|
@@ -115,7 +118,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
115
118
|
try {
|
|
116
119
|
var _this$saveExperience;
|
|
117
120
|
if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
118
|
-
return
|
|
121
|
+
return true;
|
|
119
122
|
}
|
|
120
123
|
const bodiedSyncBlockNodes = [];
|
|
121
124
|
const bodiedSyncBlockData = [];
|
|
@@ -198,6 +201,13 @@ export class SourceSyncBlockStoreManager {
|
|
|
198
201
|
if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
199
202
|
return false;
|
|
200
203
|
}
|
|
204
|
+
|
|
205
|
+
// Only track unsaved changes in source synced block for live pages
|
|
206
|
+
// classic pages's draft don't publish synced block content to block service and the content itself is saved as part of the draft
|
|
207
|
+
// classic page's publish flow will trigger a flush which only uses the isDirty flag to determine if there are unsaved changes
|
|
208
|
+
if (!this.isLivePage) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
201
211
|
return this.hasReceivedContentChange && Array.from(this.syncBlockCache.values()).some(syncBlockData => syncBlockData.isDirty);
|
|
202
212
|
}
|
|
203
213
|
isPendingCreation(resourceId) {
|
|
@@ -285,7 +295,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
285
295
|
}
|
|
286
296
|
if (fg('platform_synced_block_update_refactor')) {
|
|
287
297
|
// add the node to the cache
|
|
288
|
-
this.updateSyncBlockData(node);
|
|
298
|
+
this.updateSyncBlockData(node, false);
|
|
289
299
|
}
|
|
290
300
|
this.creationCompletionCallbacks.set(resourceId, onCompletion);
|
|
291
301
|
(_this$createExperienc = this.createExperience) === null || _this$createExperienc === void 0 ? void 0 : _this$createExperienc.start({});
|
|
@@ -14,14 +14,17 @@ import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
|
|
|
14
14
|
// SourceSyncBlockStoreManager is responsible for the lifecycle and state management of source sync blocks in an editor instance.
|
|
15
15
|
// Can be used in both editor and renderer contexts.
|
|
16
16
|
export class SyncBlockStoreManager {
|
|
17
|
-
constructor(dataProvider, viewMode) {
|
|
17
|
+
constructor(dataProvider, viewMode, isLivePage) {
|
|
18
18
|
// In future, if reference manager needs to reach to source manager and read its current in memory cache
|
|
19
19
|
// we can pass the source manager as a parameter to the reference manager constructor
|
|
20
|
-
this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider, viewMode);
|
|
20
|
+
this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider, viewMode, isLivePage);
|
|
21
21
|
this.referenceSyncBlockStoreManager = new ReferenceSyncBlockStoreManager(dataProvider, viewMode);
|
|
22
22
|
this.dataProvider = dataProvider;
|
|
23
23
|
this.referenceSyncBlockStoreManager.setRealTimeSubscriptionsEnabled(true);
|
|
24
24
|
}
|
|
25
|
+
isSyncBlock(node) {
|
|
26
|
+
return this.sourceSyncBlockStoreManager.isSourceBlock(node) || this.referenceSyncBlockStoreManager.isReferenceBlock(node);
|
|
27
|
+
}
|
|
25
28
|
async fetchReferencesSourceInfo(resourceId, blockInstanceId, isSourceSyncBlock) {
|
|
26
29
|
try {
|
|
27
30
|
var _this$fetchReferences, _response$references, _this$fetchReferences5, _response$references2;
|
|
@@ -4,6 +4,6 @@ export var useHandleContentChanges = function useHandleContentChanges(manager, s
|
|
|
4
4
|
// node content is modified by a ProseMirror transaction, which is exactly
|
|
5
5
|
// when the source manager cache needs to be updated.
|
|
6
6
|
useEffect(function () {
|
|
7
|
-
manager.sourceManager.updateSyncBlockData(syncBlockNode);
|
|
7
|
+
manager.sourceManager.updateSyncBlockData(syncBlockNode, false);
|
|
8
8
|
}, [manager, syncBlockNode]);
|
|
9
9
|
};
|
|
@@ -102,14 +102,19 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
102
102
|
// The provider might have SSR data cache already set, so we need to update the cache in session memory storage
|
|
103
103
|
this.setSSRDataInSessionCache((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getNodeDataCacheKeys());
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Enables or disables real-time GraphQL subscriptions for block updates.
|
|
108
|
-
* When enabled, the store manager will subscribe to real-time updates
|
|
109
|
-
* instead of relying on polling.
|
|
110
|
-
* @param enabled - Whether to enable real-time subscriptions
|
|
111
|
-
*/
|
|
112
105
|
return _createClass(ReferenceSyncBlockStoreManager, [{
|
|
106
|
+
key: "isReferenceBlock",
|
|
107
|
+
value: function isReferenceBlock(node) {
|
|
108
|
+
return node.type.name === 'syncBlock';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Enables or disables real-time GraphQL subscriptions for block updates.
|
|
113
|
+
* When enabled, the store manager will subscribe to real-time updates
|
|
114
|
+
* instead of relying on polling.
|
|
115
|
+
* @param enabled - Whether to enable real-time subscriptions
|
|
116
|
+
*/
|
|
117
|
+
}, {
|
|
113
118
|
key: "setRealTimeSubscriptionsEnabled",
|
|
114
119
|
value: function setRealTimeSubscriptionsEnabled(enabled) {
|
|
115
120
|
this._subscriptionManager.setRealTimeSubscriptionsEnabled(enabled);
|
|
@@ -19,7 +19,7 @@ import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
|
|
|
19
19
|
// Handles caching, debouncing updates, and publish/subscribe for local changes.
|
|
20
20
|
// Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
|
|
21
21
|
export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
22
|
-
function SourceSyncBlockStoreManager(dataProvider, viewMode) {
|
|
22
|
+
function SourceSyncBlockStoreManager(dataProvider, viewMode, isLivePage) {
|
|
23
23
|
var _this = this;
|
|
24
24
|
_classCallCheck(this, SourceSyncBlockStoreManager);
|
|
25
25
|
_defineProperty(this, "hasReceivedContentChange", false);
|
|
@@ -34,6 +34,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
34
34
|
});
|
|
35
35
|
this.dataProvider = dataProvider;
|
|
36
36
|
this.viewMode = viewMode;
|
|
37
|
+
this.isLivePage = isLivePage;
|
|
37
38
|
this.syncBlockCache = new Map();
|
|
38
39
|
this.creationCompletionCallbacks = new Map();
|
|
39
40
|
}
|
|
@@ -69,7 +70,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
69
70
|
*/
|
|
70
71
|
}, {
|
|
71
72
|
key: "updateSyncBlockData",
|
|
72
|
-
value: function updateSyncBlockData(syncBlockNode) {
|
|
73
|
+
value: function updateSyncBlockData(syncBlockNode, isRemote) {
|
|
73
74
|
try {
|
|
74
75
|
if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
75
76
|
return false;
|
|
@@ -92,11 +93,13 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
92
93
|
return true;
|
|
93
94
|
}
|
|
94
95
|
var syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
|
|
95
|
-
if (cachedBlock) {
|
|
96
|
+
if (cachedBlock && !isRemote) {
|
|
96
97
|
this.hasReceivedContentChange = true;
|
|
97
98
|
}
|
|
99
|
+
var isDirty = !isRemote || !cachedBlock; // if the change is not remote, or the block is not in the cache yet, it's dirty
|
|
98
100
|
this.syncBlockCache.set(resourceId, _objectSpread(_objectSpread({}, syncBlockData), {}, {
|
|
99
|
-
isDirty:
|
|
101
|
+
isDirty: isDirty,
|
|
102
|
+
// if the change is from remote, it's not dirty
|
|
100
103
|
contentFragment: syncBlockNode.content
|
|
101
104
|
}));
|
|
102
105
|
} else {
|
|
@@ -138,7 +141,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
138
141
|
_context.next = 3;
|
|
139
142
|
break;
|
|
140
143
|
}
|
|
141
|
-
return _context.abrupt("return",
|
|
144
|
+
return _context.abrupt("return", true);
|
|
142
145
|
case 3:
|
|
143
146
|
bodiedSyncBlockNodes = [];
|
|
144
147
|
bodiedSyncBlockData = [];
|
|
@@ -249,6 +252,13 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
249
252
|
if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
|
|
250
253
|
return false;
|
|
251
254
|
}
|
|
255
|
+
|
|
256
|
+
// Only track unsaved changes in source synced block for live pages
|
|
257
|
+
// classic pages's draft don't publish synced block content to block service and the content itself is saved as part of the draft
|
|
258
|
+
// classic page's publish flow will trigger a flush which only uses the isDirty flag to determine if there are unsaved changes
|
|
259
|
+
if (!this.isLivePage) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
252
262
|
return this.hasReceivedContentChange && Array.from(this.syncBlockCache.values()).some(function (syncBlockData) {
|
|
253
263
|
return syncBlockData.isDirty;
|
|
254
264
|
});
|
|
@@ -349,7 +359,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
349
359
|
}
|
|
350
360
|
if (fg('platform_synced_block_update_refactor')) {
|
|
351
361
|
// add the node to the cache
|
|
352
|
-
this.updateSyncBlockData(node);
|
|
362
|
+
this.updateSyncBlockData(node, false);
|
|
353
363
|
}
|
|
354
364
|
this.creationCompletionCallbacks.set(resourceId, onCompletion);
|
|
355
365
|
(_this$createExperienc = this.createExperience) === null || _this$createExperienc === void 0 || _this$createExperienc.start({});
|
|
@@ -21,16 +21,21 @@ import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
|
|
|
21
21
|
// SourceSyncBlockStoreManager is responsible for the lifecycle and state management of source sync blocks in an editor instance.
|
|
22
22
|
// Can be used in both editor and renderer contexts.
|
|
23
23
|
export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
24
|
-
function SyncBlockStoreManager(dataProvider, viewMode) {
|
|
24
|
+
function SyncBlockStoreManager(dataProvider, viewMode, isLivePage) {
|
|
25
25
|
_classCallCheck(this, SyncBlockStoreManager);
|
|
26
26
|
// In future, if reference manager needs to reach to source manager and read its current in memory cache
|
|
27
27
|
// we can pass the source manager as a parameter to the reference manager constructor
|
|
28
|
-
this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider, viewMode);
|
|
28
|
+
this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider, viewMode, isLivePage);
|
|
29
29
|
this.referenceSyncBlockStoreManager = new ReferenceSyncBlockStoreManager(dataProvider, viewMode);
|
|
30
30
|
this.dataProvider = dataProvider;
|
|
31
31
|
this.referenceSyncBlockStoreManager.setRealTimeSubscriptionsEnabled(true);
|
|
32
32
|
}
|
|
33
33
|
return _createClass(SyncBlockStoreManager, [{
|
|
34
|
+
key: "isSyncBlock",
|
|
35
|
+
value: function isSyncBlock(node) {
|
|
36
|
+
return this.sourceSyncBlockStoreManager.isSourceBlock(node) || this.referenceSyncBlockStoreManager.isReferenceBlock(node);
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
34
39
|
key: "fetchReferencesSourceInfo",
|
|
35
40
|
value: function () {
|
|
36
41
|
var _fetchReferencesSourceInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceId, blockInstanceId, isSourceSyncBlock) {
|
|
@@ -25,6 +25,7 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
25
25
|
private _providerFactoryManager;
|
|
26
26
|
private _batchFetcher;
|
|
27
27
|
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode);
|
|
28
|
+
isReferenceBlock(node: PMNode): boolean;
|
|
28
29
|
/**
|
|
29
30
|
* Enables or disables real-time GraphQL subscriptions for block updates.
|
|
30
31
|
* When enabled, the store manager will subscribe to real-time updates
|
|
@@ -9,6 +9,7 @@ type OnCompletion = (success: boolean) => void;
|
|
|
9
9
|
type DestroyCallback = () => void;
|
|
10
10
|
export declare class SourceSyncBlockStoreManager {
|
|
11
11
|
private viewMode?;
|
|
12
|
+
private isLivePage?;
|
|
12
13
|
private dataProvider?;
|
|
13
14
|
private fireAnalyticsEvent?;
|
|
14
15
|
private syncBlockCache;
|
|
@@ -21,7 +22,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
21
22
|
private saveExperience;
|
|
22
23
|
private deleteExperience;
|
|
23
24
|
private fetchSourceInfoExperience;
|
|
24
|
-
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode);
|
|
25
|
+
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode, isLivePage?: boolean);
|
|
25
26
|
/**
|
|
26
27
|
* Register a callback to be invoked after flush() completes.
|
|
27
28
|
* Used by the pm-plugin to dispatch a transaction so that
|
|
@@ -34,7 +35,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
34
35
|
* Add/update a sync block node to/from the local cache
|
|
35
36
|
* @param syncBlockNode - The sync block node to update
|
|
36
37
|
*/
|
|
37
|
-
updateSyncBlockData(syncBlockNode: PMNode): boolean;
|
|
38
|
+
updateSyncBlockData(syncBlockNode: PMNode, isRemote: boolean): boolean;
|
|
38
39
|
/**
|
|
39
40
|
* Save content of bodiedSyncBlock nodes in local cache to backend
|
|
40
41
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
3
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import type { BlockInstanceId, ReferencesSourceInfo, ResourceId } from '../common/types';
|
|
4
5
|
import type { SyncBlockDataProviderInterface } from '../providers/types';
|
|
5
6
|
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
@@ -11,7 +12,8 @@ export declare class SyncBlockStoreManager {
|
|
|
11
12
|
private fireAnalyticsEvent?;
|
|
12
13
|
private fetchReferencesExperience;
|
|
13
14
|
private fetchSourceInfoExperience;
|
|
14
|
-
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode);
|
|
15
|
+
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode, isLivePage?: boolean);
|
|
16
|
+
isSyncBlock(node: PMNode): boolean;
|
|
15
17
|
fetchReferencesSourceInfo(resourceId: ResourceId, blockInstanceId: BlockInstanceId, isSourceSyncBlock: boolean): Promise<ReferencesSourceInfo>;
|
|
16
18
|
setFireAnalyticsEvent(fireAnalyticsEvent?: (payload: SyncBlockEventPayload) => void): void;
|
|
17
19
|
get referenceManager(): ReferenceSyncBlockStoreManager;
|
|
@@ -25,6 +25,7 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
25
25
|
private _providerFactoryManager;
|
|
26
26
|
private _batchFetcher;
|
|
27
27
|
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode);
|
|
28
|
+
isReferenceBlock(node: PMNode): boolean;
|
|
28
29
|
/**
|
|
29
30
|
* Enables or disables real-time GraphQL subscriptions for block updates.
|
|
30
31
|
* When enabled, the store manager will subscribe to real-time updates
|
|
@@ -9,6 +9,7 @@ type OnCompletion = (success: boolean) => void;
|
|
|
9
9
|
type DestroyCallback = () => void;
|
|
10
10
|
export declare class SourceSyncBlockStoreManager {
|
|
11
11
|
private viewMode?;
|
|
12
|
+
private isLivePage?;
|
|
12
13
|
private dataProvider?;
|
|
13
14
|
private fireAnalyticsEvent?;
|
|
14
15
|
private syncBlockCache;
|
|
@@ -21,7 +22,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
21
22
|
private saveExperience;
|
|
22
23
|
private deleteExperience;
|
|
23
24
|
private fetchSourceInfoExperience;
|
|
24
|
-
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode);
|
|
25
|
+
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode, isLivePage?: boolean);
|
|
25
26
|
/**
|
|
26
27
|
* Register a callback to be invoked after flush() completes.
|
|
27
28
|
* Used by the pm-plugin to dispatch a transaction so that
|
|
@@ -34,7 +35,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
34
35
|
* Add/update a sync block node to/from the local cache
|
|
35
36
|
* @param syncBlockNode - The sync block node to update
|
|
36
37
|
*/
|
|
37
|
-
updateSyncBlockData(syncBlockNode: PMNode): boolean;
|
|
38
|
+
updateSyncBlockData(syncBlockNode: PMNode, isRemote: boolean): boolean;
|
|
38
39
|
/**
|
|
39
40
|
* Save content of bodiedSyncBlock nodes in local cache to backend
|
|
40
41
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
3
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import type { BlockInstanceId, ReferencesSourceInfo, ResourceId } from '../common/types';
|
|
4
5
|
import type { SyncBlockDataProviderInterface } from '../providers/types';
|
|
5
6
|
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
@@ -11,7 +12,8 @@ export declare class SyncBlockStoreManager {
|
|
|
11
12
|
private fireAnalyticsEvent?;
|
|
12
13
|
private fetchReferencesExperience;
|
|
13
14
|
private fetchSourceInfoExperience;
|
|
14
|
-
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode);
|
|
15
|
+
constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode, isLivePage?: boolean);
|
|
16
|
+
isSyncBlock(node: PMNode): boolean;
|
|
15
17
|
fetchReferencesSourceInfo(resourceId: ResourceId, blockInstanceId: BlockInstanceId, isSourceSyncBlock: boolean): Promise<ReferencesSourceInfo>;
|
|
16
18
|
setFireAnalyticsEvent(fireAnalyticsEvent?: (payload: SyncBlockEventPayload) => void): void;
|
|
17
19
|
get referenceManager(): ReferenceSyncBlockStoreManager;
|
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@atlaskit/editor-prosemirror": "^7.3.0",
|
|
30
30
|
"@atlaskit/node-data-provider": "^9.0.0",
|
|
31
31
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
32
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
32
|
+
"@atlaskit/tmp-editor-statsig": "^56.0.0",
|
|
33
33
|
"@babel/runtime": "^7.0.0",
|
|
34
34
|
"@compiled/react": "^0.20.0",
|
|
35
35
|
"graphql-ws": "^5.14.2",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
"name": "@atlaskit/editor-synced-block-provider",
|
|
84
|
-
"version": "4.
|
|
84
|
+
"version": "4.4.1",
|
|
85
85
|
"description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
|
|
86
86
|
"author": "Atlassian Pty Ltd",
|
|
87
87
|
"license": "Apache-2.0",
|