@atlaskit/editor-synced-block-provider 8.0.2 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +9 -9
- package/dist/cjs/utils/utils.js +32 -18
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +10 -10
- package/dist/es2019/utils/utils.js +32 -18
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +10 -10
- package/dist/esm/utils/utils.js +31 -18
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 8.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`100d833307949`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/100d833307949) -
|
|
8
|
+
Allow panel_c1 inside bodied sync blocks
|
|
9
|
+
|
|
3
10
|
## 8.0.2
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -237,19 +237,19 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
237
237
|
var providerData = (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 || (_this$dataProvider2 = _this$dataProvider2.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.data;
|
|
238
238
|
if (providerData) {
|
|
239
239
|
// Initial provider cache data can come from SSR/prefetch and bypass updateCache(),
|
|
240
|
-
// so
|
|
241
|
-
return this.
|
|
240
|
+
// so normalize legacy reference payloads here before rendering.
|
|
241
|
+
return this.normalizeReferenceData(providerData);
|
|
242
242
|
}
|
|
243
243
|
return this.getFromSessionCache(resourceId);
|
|
244
244
|
}
|
|
245
245
|
}, {
|
|
246
|
-
key: "
|
|
247
|
-
value: function
|
|
246
|
+
key: "normalizeReferenceData",
|
|
247
|
+
value: function normalizeReferenceData(syncBlock) {
|
|
248
248
|
var _syncBlock$data;
|
|
249
|
-
if (!((_syncBlock$data = syncBlock.data) !== null && _syncBlock$data !== void 0 && _syncBlock$data.content)) {
|
|
249
|
+
if (!((_syncBlock$data = syncBlock.data) !== null && _syncBlock$data !== void 0 && (_syncBlock$data = _syncBlock$data.content) !== null && _syncBlock$data !== void 0 && _syncBlock$data.length)) {
|
|
250
250
|
return syncBlock;
|
|
251
251
|
}
|
|
252
|
-
var content = (0, _utils.
|
|
252
|
+
var content = (0, _utils.normalizeSyncBlockJSONContent)(syncBlock.data.content);
|
|
253
253
|
if (content === syncBlock.data.content) {
|
|
254
254
|
return syncBlock;
|
|
255
255
|
}
|
|
@@ -276,8 +276,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
276
276
|
return undefined;
|
|
277
277
|
}
|
|
278
278
|
// Session cache entries written before this sanitizer existed may still include
|
|
279
|
-
//
|
|
280
|
-
return this.
|
|
279
|
+
// annotation marks or panel_c1 nodes, so keep this read-time safety net for legacy data.
|
|
280
|
+
return this.normalizeReferenceData(JSON.parse(raw));
|
|
281
281
|
} catch (error) {
|
|
282
282
|
(0, _monitoring.logException)(error, {
|
|
283
283
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/getFromSessionCache'
|
|
@@ -687,7 +687,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
687
687
|
}, {
|
|
688
688
|
key: "updateCache",
|
|
689
689
|
value: function updateCache(syncBlock) {
|
|
690
|
-
var sanitizedSyncBlock = this.
|
|
690
|
+
var sanitizedSyncBlock = this.normalizeReferenceData(syncBlock);
|
|
691
691
|
var resourceId = sanitizedSyncBlock.resourceId;
|
|
692
692
|
if (resourceId) {
|
|
693
693
|
var _this$dataProvider3;
|
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -4,58 +4,72 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.stripAnnotationMarksFromJSONContent = exports.getSourceProductFromResourceIdSafe = exports.getContentIdAndProductFromResourceId = exports.createSyncBlockNode = exports.convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockJSONNodeToSyncBlockNode = exports.convertPMNodesToSyncBlockNodes = exports.convertPMNodeToSyncBlockNode = exports.convertContentUpdatedAt = void 0;
|
|
7
|
+
exports.stripAnnotationMarksFromJSONContent = exports.normalizeSyncBlockJSONContent = exports.getSourceProductFromResourceIdSafe = exports.getContentIdAndProductFromResourceId = exports.createSyncBlockNode = exports.convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockJSONNodeToSyncBlockNode = exports.convertPMNodesToSyncBlockNodes = exports.convertPMNodeToSyncBlockNode = exports.convertContentUpdatedAt = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
10
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
11
|
/* eslint-disable require-unicode-regexp */
|
|
12
12
|
|
|
13
|
-
var
|
|
14
|
-
var
|
|
13
|
+
var _normalizeSyncBlockJSONContentInternal = function normalizeSyncBlockJSONContentInternal(content, options) {
|
|
14
|
+
var normalizedContent;
|
|
15
15
|
content.forEach(function (contentNode, index) {
|
|
16
16
|
var _contentNode$marks;
|
|
17
17
|
if (!contentNode) {
|
|
18
|
-
var
|
|
19
|
-
(
|
|
18
|
+
var _normalizedContent;
|
|
19
|
+
(_normalizedContent = normalizedContent) === null || _normalizedContent === void 0 || _normalizedContent.push(contentNode);
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
var hasAnnotationMark = (_contentNode$marks = contentNode.marks) === null || _contentNode$marks === void 0 ? void 0 : _contentNode$marks.some(function (mark) {
|
|
23
23
|
return mark.type === 'annotation';
|
|
24
24
|
});
|
|
25
|
-
var
|
|
25
|
+
var shouldConvertPanelC1 = options.convertPanelC1ToPanel && contentNode.type === 'panel_c1';
|
|
26
|
+
var childContent = contentNode.content ? _normalizeSyncBlockJSONContentInternal(contentNode.content, options) : undefined;
|
|
26
27
|
var hasContentChanged = childContent !== undefined && childContent !== contentNode.content;
|
|
27
|
-
if (!hasAnnotationMark && !hasContentChanged) {
|
|
28
|
-
var
|
|
29
|
-
(
|
|
28
|
+
if (!hasAnnotationMark && !shouldConvertPanelC1 && !hasContentChanged) {
|
|
29
|
+
var _normalizedContent2;
|
|
30
|
+
(_normalizedContent2 = normalizedContent) === null || _normalizedContent2 === void 0 || _normalizedContent2.push(contentNode);
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
|
-
if (!
|
|
33
|
-
|
|
33
|
+
if (!normalizedContent) {
|
|
34
|
+
normalizedContent = content.slice(0, index);
|
|
35
|
+
}
|
|
36
|
+
var normalizedNode = _objectSpread({}, contentNode);
|
|
37
|
+
if (shouldConvertPanelC1) {
|
|
38
|
+
normalizedNode.type = 'panel';
|
|
34
39
|
}
|
|
35
|
-
var strippedNode = _objectSpread({}, contentNode);
|
|
36
40
|
if (hasAnnotationMark) {
|
|
37
41
|
var _contentNode$marks2;
|
|
38
42
|
var marks = (_contentNode$marks2 = contentNode.marks) === null || _contentNode$marks2 === void 0 ? void 0 : _contentNode$marks2.filter(function (mark) {
|
|
39
43
|
return mark.type !== 'annotation';
|
|
40
44
|
});
|
|
41
45
|
if (marks && marks.length > 0) {
|
|
42
|
-
|
|
46
|
+
normalizedNode.marks = marks;
|
|
43
47
|
} else {
|
|
44
|
-
delete
|
|
48
|
+
delete normalizedNode.marks;
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
if (hasContentChanged && childContent) {
|
|
48
|
-
|
|
52
|
+
normalizedNode.content = childContent;
|
|
49
53
|
}
|
|
50
|
-
|
|
54
|
+
normalizedContent.push(normalizedNode);
|
|
55
|
+
});
|
|
56
|
+
return normalizedContent !== null && normalizedContent !== void 0 ? normalizedContent : content;
|
|
57
|
+
};
|
|
58
|
+
var stripAnnotationMarksFromJSONContent = exports.stripAnnotationMarksFromJSONContent = function stripAnnotationMarksFromJSONContent(content) {
|
|
59
|
+
return _normalizeSyncBlockJSONContentInternal(content, {
|
|
60
|
+
convertPanelC1ToPanel: false
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
var normalizeSyncBlockJSONContent = exports.normalizeSyncBlockJSONContent = function normalizeSyncBlockJSONContent(content) {
|
|
64
|
+
return _normalizeSyncBlockJSONContentInternal(content, {
|
|
65
|
+
convertPanelC1ToPanel: true
|
|
51
66
|
});
|
|
52
|
-
return strippedContent !== null && strippedContent !== void 0 ? strippedContent : content;
|
|
53
67
|
};
|
|
54
68
|
var convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNodeToSyncBlockData(node) {
|
|
55
69
|
var content = node.content.toJSON();
|
|
56
70
|
return {
|
|
57
71
|
blockInstanceId: node.attrs.localId,
|
|
58
|
-
content: content ?
|
|
72
|
+
content: content ? normalizeSyncBlockJSONContent(content) : content,
|
|
59
73
|
resourceId: node.attrs.resourceId
|
|
60
74
|
};
|
|
61
75
|
};
|
|
@@ -6,7 +6,7 @@ import { SyncBlockError } from '../common/types';
|
|
|
6
6
|
import { cacheDeletionForcedPayload, fetchErrorPayload, fetchSuccessPayload, getSourceInfoErrorPayload, sourceInfoOrphanedPayload, updateReferenceErrorPayload } from '../utils/errorHandling';
|
|
7
7
|
import { getFetchExperience, getFetchSourceInfoExperience, getSaveReferenceExperience } from '../utils/experienceTracking';
|
|
8
8
|
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
9
|
-
import { createSyncBlockNode, getSourceProductFromResourceIdSafe,
|
|
9
|
+
import { createSyncBlockNode, getSourceProductFromResourceIdSafe, normalizeSyncBlockJSONContent } from '../utils/utils';
|
|
10
10
|
import { SyncBlockBatchFetcher } from './syncBlockBatchFetcher';
|
|
11
11
|
import { syncBlockInMemorySessionCache } from './syncBlockInMemorySessionCache';
|
|
12
12
|
import { SyncBlockProviderFactoryManager } from './syncBlockProviderFactoryManager';
|
|
@@ -164,17 +164,17 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
164
164
|
const providerData = (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : (_this$dataProvider2$g = _this$dataProvider2.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider2$g === void 0 ? void 0 : _this$dataProvider2$g.data;
|
|
165
165
|
if (providerData) {
|
|
166
166
|
// Initial provider cache data can come from SSR/prefetch and bypass updateCache(),
|
|
167
|
-
// so
|
|
168
|
-
return this.
|
|
167
|
+
// so normalize legacy reference payloads here before rendering.
|
|
168
|
+
return this.normalizeReferenceData(providerData);
|
|
169
169
|
}
|
|
170
170
|
return this.getFromSessionCache(resourceId);
|
|
171
171
|
}
|
|
172
|
-
|
|
173
|
-
var _syncBlock$data;
|
|
174
|
-
if (!((_syncBlock$data = syncBlock.data) !== null && _syncBlock$data !== void 0 && _syncBlock$data.content)) {
|
|
172
|
+
normalizeReferenceData(syncBlock) {
|
|
173
|
+
var _syncBlock$data, _syncBlock$data$conte;
|
|
174
|
+
if (!((_syncBlock$data = syncBlock.data) !== null && _syncBlock$data !== void 0 && (_syncBlock$data$conte = _syncBlock$data.content) !== null && _syncBlock$data$conte !== void 0 && _syncBlock$data$conte.length)) {
|
|
175
175
|
return syncBlock;
|
|
176
176
|
}
|
|
177
|
-
const content =
|
|
177
|
+
const content = normalizeSyncBlockJSONContent(syncBlock.data.content);
|
|
178
178
|
if (content === syncBlock.data.content) {
|
|
179
179
|
return syncBlock;
|
|
180
180
|
}
|
|
@@ -199,8 +199,8 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
199
199
|
return undefined;
|
|
200
200
|
}
|
|
201
201
|
// Session cache entries written before this sanitizer existed may still include
|
|
202
|
-
//
|
|
203
|
-
return this.
|
|
202
|
+
// annotation marks or panel_c1 nodes, so keep this read-time safety net for legacy data.
|
|
203
|
+
return this.normalizeReferenceData(JSON.parse(raw));
|
|
204
204
|
} catch (error) {
|
|
205
205
|
logException(error, {
|
|
206
206
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/getFromSessionCache'
|
|
@@ -552,7 +552,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
552
552
|
}
|
|
553
553
|
}
|
|
554
554
|
updateCache(syncBlock) {
|
|
555
|
-
const sanitizedSyncBlock = this.
|
|
555
|
+
const sanitizedSyncBlock = this.normalizeReferenceData(syncBlock);
|
|
556
556
|
const {
|
|
557
557
|
resourceId
|
|
558
558
|
} = sanitizedSyncBlock;
|
|
@@ -1,50 +1,64 @@
|
|
|
1
1
|
/* eslint-disable require-unicode-regexp */
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
let
|
|
3
|
+
const normalizeSyncBlockJSONContentInternal = (content, options) => {
|
|
4
|
+
var _normalizedContent3;
|
|
5
|
+
let normalizedContent;
|
|
6
6
|
content.forEach((contentNode, index) => {
|
|
7
7
|
var _contentNode$marks;
|
|
8
8
|
if (!contentNode) {
|
|
9
|
-
var
|
|
10
|
-
(
|
|
9
|
+
var _normalizedContent;
|
|
10
|
+
(_normalizedContent = normalizedContent) === null || _normalizedContent === void 0 ? void 0 : _normalizedContent.push(contentNode);
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
const hasAnnotationMark = (_contentNode$marks = contentNode.marks) === null || _contentNode$marks === void 0 ? void 0 : _contentNode$marks.some(mark => mark.type === 'annotation');
|
|
14
|
-
const
|
|
14
|
+
const shouldConvertPanelC1 = options.convertPanelC1ToPanel && contentNode.type === 'panel_c1';
|
|
15
|
+
const childContent = contentNode.content ? normalizeSyncBlockJSONContentInternal(contentNode.content, options) : undefined;
|
|
15
16
|
const hasContentChanged = childContent !== undefined && childContent !== contentNode.content;
|
|
16
|
-
if (!hasAnnotationMark && !hasContentChanged) {
|
|
17
|
-
var
|
|
18
|
-
(
|
|
17
|
+
if (!hasAnnotationMark && !shouldConvertPanelC1 && !hasContentChanged) {
|
|
18
|
+
var _normalizedContent2;
|
|
19
|
+
(_normalizedContent2 = normalizedContent) === null || _normalizedContent2 === void 0 ? void 0 : _normalizedContent2.push(contentNode);
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
|
-
if (!
|
|
22
|
-
|
|
22
|
+
if (!normalizedContent) {
|
|
23
|
+
normalizedContent = content.slice(0, index);
|
|
23
24
|
}
|
|
24
|
-
const
|
|
25
|
+
const normalizedNode = {
|
|
25
26
|
...contentNode
|
|
26
27
|
};
|
|
28
|
+
if (shouldConvertPanelC1) {
|
|
29
|
+
normalizedNode.type = 'panel';
|
|
30
|
+
}
|
|
27
31
|
if (hasAnnotationMark) {
|
|
28
32
|
var _contentNode$marks2;
|
|
29
33
|
const marks = (_contentNode$marks2 = contentNode.marks) === null || _contentNode$marks2 === void 0 ? void 0 : _contentNode$marks2.filter(mark => mark.type !== 'annotation');
|
|
30
34
|
if (marks && marks.length > 0) {
|
|
31
|
-
|
|
35
|
+
normalizedNode.marks = marks;
|
|
32
36
|
} else {
|
|
33
|
-
delete
|
|
37
|
+
delete normalizedNode.marks;
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
if (hasContentChanged && childContent) {
|
|
37
|
-
|
|
41
|
+
normalizedNode.content = childContent;
|
|
38
42
|
}
|
|
39
|
-
|
|
43
|
+
normalizedContent.push(normalizedNode);
|
|
44
|
+
});
|
|
45
|
+
return (_normalizedContent3 = normalizedContent) !== null && _normalizedContent3 !== void 0 ? _normalizedContent3 : content;
|
|
46
|
+
};
|
|
47
|
+
export const stripAnnotationMarksFromJSONContent = content => {
|
|
48
|
+
return normalizeSyncBlockJSONContentInternal(content, {
|
|
49
|
+
convertPanelC1ToPanel: false
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export const normalizeSyncBlockJSONContent = content => {
|
|
53
|
+
return normalizeSyncBlockJSONContentInternal(content, {
|
|
54
|
+
convertPanelC1ToPanel: true
|
|
40
55
|
});
|
|
41
|
-
return (_strippedContent3 = strippedContent) !== null && _strippedContent3 !== void 0 ? _strippedContent3 : content;
|
|
42
56
|
};
|
|
43
57
|
export const convertSyncBlockPMNodeToSyncBlockData = node => {
|
|
44
58
|
const content = node.content.toJSON();
|
|
45
59
|
return {
|
|
46
60
|
blockInstanceId: node.attrs.localId,
|
|
47
|
-
content: content ?
|
|
61
|
+
content: content ? normalizeSyncBlockJSONContent(content) : content,
|
|
48
62
|
resourceId: node.attrs.resourceId
|
|
49
63
|
};
|
|
50
64
|
};
|
|
@@ -16,7 +16,7 @@ import { SyncBlockError } from '../common/types';
|
|
|
16
16
|
import { cacheDeletionForcedPayload, fetchErrorPayload, fetchSuccessPayload, getSourceInfoErrorPayload, sourceInfoOrphanedPayload, updateReferenceErrorPayload } from '../utils/errorHandling';
|
|
17
17
|
import { getFetchExperience, getFetchSourceInfoExperience, getSaveReferenceExperience } from '../utils/experienceTracking';
|
|
18
18
|
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
19
|
-
import { createSyncBlockNode, getSourceProductFromResourceIdSafe,
|
|
19
|
+
import { createSyncBlockNode, getSourceProductFromResourceIdSafe, normalizeSyncBlockJSONContent } from '../utils/utils';
|
|
20
20
|
import { SyncBlockBatchFetcher } from './syncBlockBatchFetcher';
|
|
21
21
|
import { syncBlockInMemorySessionCache } from './syncBlockInMemorySessionCache';
|
|
22
22
|
import { SyncBlockProviderFactoryManager } from './syncBlockProviderFactoryManager';
|
|
@@ -230,19 +230,19 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
230
230
|
var providerData = (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 || (_this$dataProvider2 = _this$dataProvider2.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.data;
|
|
231
231
|
if (providerData) {
|
|
232
232
|
// Initial provider cache data can come from SSR/prefetch and bypass updateCache(),
|
|
233
|
-
// so
|
|
234
|
-
return this.
|
|
233
|
+
// so normalize legacy reference payloads here before rendering.
|
|
234
|
+
return this.normalizeReferenceData(providerData);
|
|
235
235
|
}
|
|
236
236
|
return this.getFromSessionCache(resourceId);
|
|
237
237
|
}
|
|
238
238
|
}, {
|
|
239
|
-
key: "
|
|
240
|
-
value: function
|
|
239
|
+
key: "normalizeReferenceData",
|
|
240
|
+
value: function normalizeReferenceData(syncBlock) {
|
|
241
241
|
var _syncBlock$data;
|
|
242
|
-
if (!((_syncBlock$data = syncBlock.data) !== null && _syncBlock$data !== void 0 && _syncBlock$data.content)) {
|
|
242
|
+
if (!((_syncBlock$data = syncBlock.data) !== null && _syncBlock$data !== void 0 && (_syncBlock$data = _syncBlock$data.content) !== null && _syncBlock$data !== void 0 && _syncBlock$data.length)) {
|
|
243
243
|
return syncBlock;
|
|
244
244
|
}
|
|
245
|
-
var content =
|
|
245
|
+
var content = normalizeSyncBlockJSONContent(syncBlock.data.content);
|
|
246
246
|
if (content === syncBlock.data.content) {
|
|
247
247
|
return syncBlock;
|
|
248
248
|
}
|
|
@@ -269,8 +269,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
269
269
|
return undefined;
|
|
270
270
|
}
|
|
271
271
|
// Session cache entries written before this sanitizer existed may still include
|
|
272
|
-
//
|
|
273
|
-
return this.
|
|
272
|
+
// annotation marks or panel_c1 nodes, so keep this read-time safety net for legacy data.
|
|
273
|
+
return this.normalizeReferenceData(JSON.parse(raw));
|
|
274
274
|
} catch (error) {
|
|
275
275
|
logException(error, {
|
|
276
276
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/getFromSessionCache'
|
|
@@ -680,7 +680,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
680
680
|
}, {
|
|
681
681
|
key: "updateCache",
|
|
682
682
|
value: function updateCache(syncBlock) {
|
|
683
|
-
var sanitizedSyncBlock = this.
|
|
683
|
+
var sanitizedSyncBlock = this.normalizeReferenceData(syncBlock);
|
|
684
684
|
var resourceId = sanitizedSyncBlock.resourceId;
|
|
685
685
|
if (resourceId) {
|
|
686
686
|
var _this$dataProvider3;
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -3,53 +3,66 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
4
|
/* eslint-disable require-unicode-regexp */
|
|
5
5
|
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var _normalizeSyncBlockJSONContentInternal = function normalizeSyncBlockJSONContentInternal(content, options) {
|
|
7
|
+
var normalizedContent;
|
|
8
8
|
content.forEach(function (contentNode, index) {
|
|
9
9
|
var _contentNode$marks;
|
|
10
10
|
if (!contentNode) {
|
|
11
|
-
var
|
|
12
|
-
(
|
|
11
|
+
var _normalizedContent;
|
|
12
|
+
(_normalizedContent = normalizedContent) === null || _normalizedContent === void 0 || _normalizedContent.push(contentNode);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
var hasAnnotationMark = (_contentNode$marks = contentNode.marks) === null || _contentNode$marks === void 0 ? void 0 : _contentNode$marks.some(function (mark) {
|
|
16
16
|
return mark.type === 'annotation';
|
|
17
17
|
});
|
|
18
|
-
var
|
|
18
|
+
var shouldConvertPanelC1 = options.convertPanelC1ToPanel && contentNode.type === 'panel_c1';
|
|
19
|
+
var childContent = contentNode.content ? _normalizeSyncBlockJSONContentInternal(contentNode.content, options) : undefined;
|
|
19
20
|
var hasContentChanged = childContent !== undefined && childContent !== contentNode.content;
|
|
20
|
-
if (!hasAnnotationMark && !hasContentChanged) {
|
|
21
|
-
var
|
|
22
|
-
(
|
|
21
|
+
if (!hasAnnotationMark && !shouldConvertPanelC1 && !hasContentChanged) {
|
|
22
|
+
var _normalizedContent2;
|
|
23
|
+
(_normalizedContent2 = normalizedContent) === null || _normalizedContent2 === void 0 || _normalizedContent2.push(contentNode);
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
|
-
if (!
|
|
26
|
-
|
|
26
|
+
if (!normalizedContent) {
|
|
27
|
+
normalizedContent = content.slice(0, index);
|
|
28
|
+
}
|
|
29
|
+
var normalizedNode = _objectSpread({}, contentNode);
|
|
30
|
+
if (shouldConvertPanelC1) {
|
|
31
|
+
normalizedNode.type = 'panel';
|
|
27
32
|
}
|
|
28
|
-
var strippedNode = _objectSpread({}, contentNode);
|
|
29
33
|
if (hasAnnotationMark) {
|
|
30
34
|
var _contentNode$marks2;
|
|
31
35
|
var marks = (_contentNode$marks2 = contentNode.marks) === null || _contentNode$marks2 === void 0 ? void 0 : _contentNode$marks2.filter(function (mark) {
|
|
32
36
|
return mark.type !== 'annotation';
|
|
33
37
|
});
|
|
34
38
|
if (marks && marks.length > 0) {
|
|
35
|
-
|
|
39
|
+
normalizedNode.marks = marks;
|
|
36
40
|
} else {
|
|
37
|
-
delete
|
|
41
|
+
delete normalizedNode.marks;
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
if (hasContentChanged && childContent) {
|
|
41
|
-
|
|
45
|
+
normalizedNode.content = childContent;
|
|
42
46
|
}
|
|
43
|
-
|
|
47
|
+
normalizedContent.push(normalizedNode);
|
|
48
|
+
});
|
|
49
|
+
return normalizedContent !== null && normalizedContent !== void 0 ? normalizedContent : content;
|
|
50
|
+
};
|
|
51
|
+
export var stripAnnotationMarksFromJSONContent = function stripAnnotationMarksFromJSONContent(content) {
|
|
52
|
+
return _normalizeSyncBlockJSONContentInternal(content, {
|
|
53
|
+
convertPanelC1ToPanel: false
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
export var normalizeSyncBlockJSONContent = function normalizeSyncBlockJSONContent(content) {
|
|
57
|
+
return _normalizeSyncBlockJSONContentInternal(content, {
|
|
58
|
+
convertPanelC1ToPanel: true
|
|
44
59
|
});
|
|
45
|
-
return strippedContent !== null && strippedContent !== void 0 ? strippedContent : content;
|
|
46
60
|
};
|
|
47
|
-
export { _stripAnnotationMarksFromJSONContent as stripAnnotationMarksFromJSONContent };
|
|
48
61
|
export var convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNodeToSyncBlockData(node) {
|
|
49
62
|
var content = node.content.toJSON();
|
|
50
63
|
return {
|
|
51
64
|
blockInstanceId: node.attrs.localId,
|
|
52
|
-
content: content ?
|
|
65
|
+
content: content ? normalizeSyncBlockJSONContent(content) : content,
|
|
53
66
|
resourceId: node.attrs.resourceId
|
|
54
67
|
};
|
|
55
68
|
};
|
|
@@ -70,7 +70,7 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
70
70
|
generateResourceIdForReference(sourceId: ResourceId): ResourceId;
|
|
71
71
|
updateFireAnalyticsEvent(fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): void;
|
|
72
72
|
getInitialSyncBlockData(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
73
|
-
private
|
|
73
|
+
private normalizeReferenceData;
|
|
74
74
|
private updateSessionCache;
|
|
75
75
|
private getFromSessionCache;
|
|
76
76
|
fetchSyncBlockSourceInfoBySourceAri(sourceAri: string, hasAccess?: boolean): Promise<SyncBlockSourceInfo | undefined>;
|
|
@@ -2,6 +2,7 @@ import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
|
|
|
2
2
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import type { SyncBlockData, BlockInstanceId, ResourceId, SyncBlockNode, SyncBlockProduct } from '../common/types';
|
|
4
4
|
export declare const stripAnnotationMarksFromJSONContent: <T extends JSONNode | undefined>(content: T[]) => T[];
|
|
5
|
+
export declare const normalizeSyncBlockJSONContent: <T extends JSONNode | undefined>(content: T[]) => T[];
|
|
5
6
|
export declare const convertSyncBlockPMNodeToSyncBlockData: (node: PMNode) => SyncBlockData;
|
|
6
7
|
export declare const createSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
|
|
7
8
|
export declare const convertSyncBlockJSONNodeToSyncBlockNode: (node: JSONNode) => SyncBlockNode | undefined;
|
package/package.json
CHANGED