@atlaskit/editor-synced-block-provider 3.7.0 → 3.8.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 +11 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +4 -1
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/providers/block-service/blockServiceAPI.js +2 -1
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +2 -2
- package/dist/cjs/utils/resourceId.js +67 -0
- package/dist/es2019/hooks/useFetchSyncBlockData.js +5 -2
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +2 -1
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +1 -1
- package/dist/es2019/utils/resourceId.js +54 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +5 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/providers/block-service/blockServiceAPI.js +2 -1
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +1 -1
- package/dist/esm/utils/resourceId.js +60 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/{types-ts4.5/utils/parseResourceId.d.ts → types/utils/resourceId.d.ts} +1 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/{types/utils/parseResourceId.d.ts → types-ts4.5/utils/resourceId.d.ts} +1 -0
- package/package.json +1 -1
- package/dist/cjs/utils/parseResourceId.js +0 -38
- package/dist/es2019/utils/parseResourceId.js +0 -25
- package/dist/esm/utils/parseResourceId.js +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 3.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`9b427b1878556`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9b427b1878556) -
|
|
8
|
+
EDITOR-2850 create resource-id utils and unify the creation and parse
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
3
14
|
## 3.7.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
|
@@ -118,9 +118,12 @@ var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyn
|
|
|
118
118
|
unsubscribe();
|
|
119
119
|
};
|
|
120
120
|
}, [localId, manager.referenceManager, resourceId]);
|
|
121
|
+
var ssrProviders = (0, _react.useMemo)(function () {
|
|
122
|
+
return resourceId ? manager.referenceManager.getSSRProviders(resourceId) : null;
|
|
123
|
+
}, [resourceId, manager.referenceManager]);
|
|
121
124
|
return {
|
|
122
125
|
isLoading: isLoading,
|
|
123
|
-
ssrProviders:
|
|
126
|
+
ssrProviders: ssrProviders,
|
|
124
127
|
providerFactory: manager.referenceManager.getProviderFactory(resourceId || ''),
|
|
125
128
|
reloadData: reloadData,
|
|
126
129
|
syncBlockInstance: syncBlockInstance
|
package/dist/cjs/index.js
CHANGED
|
@@ -39,6 +39,12 @@ Object.defineProperty(exports, "convertSyncBlockPMNodeToSyncBlockData", {
|
|
|
39
39
|
return _utils.convertSyncBlockPMNodeToSyncBlockData;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
|
+
Object.defineProperty(exports, "createResourceIdForReference", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function get() {
|
|
45
|
+
return _resourceId.createResourceIdForReference;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
42
48
|
Object.defineProperty(exports, "createSyncBlockNode", {
|
|
43
49
|
enumerable: true,
|
|
44
50
|
get: function get() {
|
|
@@ -120,7 +126,7 @@ Object.defineProperty(exports, "getPageIdAndTypeFromConfluencePageAri", {
|
|
|
120
126
|
Object.defineProperty(exports, "parseResourceId", {
|
|
121
127
|
enumerable: true,
|
|
122
128
|
get: function get() {
|
|
123
|
-
return
|
|
129
|
+
return _resourceId.parseResourceId;
|
|
124
130
|
}
|
|
125
131
|
});
|
|
126
132
|
Object.defineProperty(exports, "rebaseTransaction", {
|
|
@@ -191,6 +197,6 @@ var _sourceInfo = require("./clients/confluence/sourceInfo");
|
|
|
191
197
|
var _syncBlockProvider = require("./providers/syncBlockProvider");
|
|
192
198
|
var _syncBlockStoreManager = require("./store-manager/syncBlockStoreManager");
|
|
193
199
|
var _resolveSyncBlockInstance = require("./utils/resolveSyncBlockInstance");
|
|
194
|
-
var
|
|
200
|
+
var _resourceId = require("./utils/resourceId");
|
|
195
201
|
var _utils = require("./utils/utils");
|
|
196
202
|
var _errorHandling = require("./utils/errorHandling");
|
|
@@ -17,6 +17,7 @@ var _ari = require("../../clients/block-service/ari");
|
|
|
17
17
|
var _blockService = require("../../clients/block-service/blockService");
|
|
18
18
|
var _types = require("../../common/types");
|
|
19
19
|
var _errorHandling = require("../../utils/errorHandling");
|
|
20
|
+
var _resourceId3 = require("../../utils/resourceId");
|
|
20
21
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
21
22
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
22
23
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
@@ -722,7 +723,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
722
723
|
}, {
|
|
723
724
|
key: "generateResourceIdForReference",
|
|
724
725
|
value: function generateResourceIdForReference(sourceId) {
|
|
725
|
-
return
|
|
726
|
+
return (0, _resourceId3.createResourceIdForReference)(this.product, this.parentId || '', sourceId);
|
|
726
727
|
}
|
|
727
728
|
}, {
|
|
728
729
|
key: "generateResourceId",
|
|
@@ -16,8 +16,8 @@ var _providerFactory = require("@atlaskit/editor-common/provider-factory");
|
|
|
16
16
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
17
|
var _types = require("../common/types");
|
|
18
18
|
var _errorHandling = require("../utils/errorHandling");
|
|
19
|
-
var _parseResourceId = require("../utils/parseResourceId");
|
|
20
19
|
var _resolveSyncBlockInstance = require("../utils/resolveSyncBlockInstance");
|
|
20
|
+
var _resourceId = require("../utils/resourceId");
|
|
21
21
|
var _utils = require("../utils/utils");
|
|
22
22
|
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; }
|
|
23
23
|
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; }
|
|
@@ -697,7 +697,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
697
697
|
if (!(providerCreator !== null && providerCreator !== void 0 && providerCreator.createSSRMediaProvider)) {
|
|
698
698
|
return null;
|
|
699
699
|
}
|
|
700
|
-
var parsedResourceId = (0,
|
|
700
|
+
var parsedResourceId = (0, _resourceId.parseResourceId)(resourceId);
|
|
701
701
|
if (!parsedResourceId) {
|
|
702
702
|
return null;
|
|
703
703
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.parseResourceId = exports.createResourceIdForReference = void 0;
|
|
8
|
+
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
|
|
9
|
+
var _consts = require("../common/consts");
|
|
10
|
+
var isSyncBlockProduct = function isSyncBlockProduct(product) {
|
|
11
|
+
return _consts.SYNC_BLOCK_PRODUCTS.includes(product);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* Sync Block resourceId utilities
|
|
16
|
+
* --------------------------------
|
|
17
|
+
* Provides helpers to parse and generate the identifier used to
|
|
18
|
+
* reference a synced block across Atlassian products.
|
|
19
|
+
*
|
|
20
|
+
* Format
|
|
21
|
+
* - {product}/{contentId}/{uuid}
|
|
22
|
+
* - product: a recognized `SyncBlockProduct` (e.g. 'confluence-page', 'jira-issue')
|
|
23
|
+
* - contentId: the host content identifier (e.g. page ID or issue ID)
|
|
24
|
+
* - uuid: the UUID for the specific synced block instance
|
|
25
|
+
*
|
|
26
|
+
* Examples
|
|
27
|
+
* - confluence-page/8060929/7f9d9cf8-8483-43ee-99f3-6ca576dbf24d
|
|
28
|
+
*
|
|
29
|
+
* Validation rules (enforced by `parseResourceId`)
|
|
30
|
+
* - Must have exactly three path segments separated by '/'
|
|
31
|
+
* - `product` must be one of `SYNC_BLOCK_PRODUCTS`
|
|
32
|
+
* - No extra segments; returns `undefined` on any invalid input
|
|
33
|
+
*
|
|
34
|
+
* Notes
|
|
35
|
+
* - `product` is a qualified domain like 'confluence-page' or 'jira-issue',
|
|
36
|
+
* not just 'confluence' or 'jira'.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
var parseResourceId = exports.parseResourceId = function parseResourceId(resourceId) {
|
|
40
|
+
if (!resourceId) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
var _resourceId$split = resourceId.split('/'),
|
|
44
|
+
_resourceId$split2 = (0, _toArray2.default)(_resourceId$split),
|
|
45
|
+
product = _resourceId$split2[0],
|
|
46
|
+
contentId = _resourceId$split2[1],
|
|
47
|
+
uuid = _resourceId$split2[2],
|
|
48
|
+
rest = _resourceId$split2.slice(3);
|
|
49
|
+
|
|
50
|
+
// invalid if any part is missing or there are extra parts
|
|
51
|
+
if (!product || !contentId || !uuid || rest.length > 0) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// invalid if product is not recognized
|
|
56
|
+
if (!isSyncBlockProduct(product)) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
product: product,
|
|
61
|
+
contentId: contentId,
|
|
62
|
+
uuid: uuid
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
var createResourceIdForReference = exports.createResourceIdForReference = function createResourceIdForReference(product, contentId, uuid) {
|
|
66
|
+
return "".concat(product, "/").concat(contentId, "/").concat(uuid);
|
|
67
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
3
3
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
4
|
import { SyncBlockError } from '../common/types';
|
|
@@ -81,9 +81,12 @@ export const useFetchSyncBlockData = (manager, resourceId, localId, fireAnalytic
|
|
|
81
81
|
unsubscribe();
|
|
82
82
|
};
|
|
83
83
|
}, [localId, manager.referenceManager, resourceId]);
|
|
84
|
+
const ssrProviders = useMemo(() => {
|
|
85
|
+
return resourceId ? manager.referenceManager.getSSRProviders(resourceId) : null;
|
|
86
|
+
}, [resourceId, manager.referenceManager]);
|
|
84
87
|
return {
|
|
85
88
|
isLoading,
|
|
86
|
-
ssrProviders
|
|
89
|
+
ssrProviders,
|
|
87
90
|
providerFactory: manager.referenceManager.getProviderFactory(resourceId || ''),
|
|
88
91
|
reloadData,
|
|
89
92
|
syncBlockInstance
|
package/dist/es2019/index.js
CHANGED
|
@@ -25,7 +25,7 @@ export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager } from './store
|
|
|
25
25
|
|
|
26
26
|
// utils
|
|
27
27
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
28
|
-
export { parseResourceId } from './utils/
|
|
28
|
+
export { parseResourceId, createResourceIdForReference } from './utils/resourceId';
|
|
29
29
|
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId } from './utils/utils';
|
|
30
30
|
export { fetchErrorPayload } from './utils/errorHandling';
|
|
31
31
|
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|
|
@@ -5,6 +5,7 @@ import { generateBlockAri, generateBlockAriFromReference } from '../../clients/b
|
|
|
5
5
|
import { batchRetrieveSyncedBlocks, BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getReferenceSyncedBlocksByBlockAri, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
6
6
|
import { SyncBlockError } from '../../common/types';
|
|
7
7
|
import { stringifyError } from '../../utils/errorHandling';
|
|
8
|
+
import { createResourceIdForReference } from '../../utils/resourceId';
|
|
8
9
|
const mapBlockError = error => {
|
|
9
10
|
switch (error.status) {
|
|
10
11
|
case 400:
|
|
@@ -478,7 +479,7 @@ class BlockServiceADFWriteProvider {
|
|
|
478
479
|
|
|
479
480
|
// the sourceId is the resourceId of the source synced block.
|
|
480
481
|
generateResourceIdForReference(sourceId) {
|
|
481
|
-
return
|
|
482
|
+
return createResourceIdForReference(this.product, this.parentId || '', sourceId);
|
|
482
483
|
}
|
|
483
484
|
generateResourceId() {
|
|
484
485
|
return crypto.randomUUID();
|
|
@@ -4,8 +4,8 @@ import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
|
|
|
4
4
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
5
|
import { SyncBlockError } from '../common/types';
|
|
6
6
|
import { fetchErrorPayload, getSourceInfoErrorPayload, updateReferenceErrorPayload } from '../utils/errorHandling';
|
|
7
|
-
import { parseResourceId } from '../utils/parseResourceId';
|
|
8
7
|
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
8
|
+
import { parseResourceId } from '../utils/resourceId';
|
|
9
9
|
import { createSyncBlockNode } from '../utils/utils';
|
|
10
10
|
|
|
11
11
|
// A store manager responsible for the lifecycle and state management of reference sync blocks in an editor instance.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SYNC_BLOCK_PRODUCTS } from '../common/consts';
|
|
2
|
+
const isSyncBlockProduct = product => {
|
|
3
|
+
return SYNC_BLOCK_PRODUCTS.includes(product);
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Sync Block resourceId utilities
|
|
8
|
+
* --------------------------------
|
|
9
|
+
* Provides helpers to parse and generate the identifier used to
|
|
10
|
+
* reference a synced block across Atlassian products.
|
|
11
|
+
*
|
|
12
|
+
* Format
|
|
13
|
+
* - {product}/{contentId}/{uuid}
|
|
14
|
+
* - product: a recognized `SyncBlockProduct` (e.g. 'confluence-page', 'jira-issue')
|
|
15
|
+
* - contentId: the host content identifier (e.g. page ID or issue ID)
|
|
16
|
+
* - uuid: the UUID for the specific synced block instance
|
|
17
|
+
*
|
|
18
|
+
* Examples
|
|
19
|
+
* - confluence-page/8060929/7f9d9cf8-8483-43ee-99f3-6ca576dbf24d
|
|
20
|
+
*
|
|
21
|
+
* Validation rules (enforced by `parseResourceId`)
|
|
22
|
+
* - Must have exactly three path segments separated by '/'
|
|
23
|
+
* - `product` must be one of `SYNC_BLOCK_PRODUCTS`
|
|
24
|
+
* - No extra segments; returns `undefined` on any invalid input
|
|
25
|
+
*
|
|
26
|
+
* Notes
|
|
27
|
+
* - `product` is a qualified domain like 'confluence-page' or 'jira-issue',
|
|
28
|
+
* not just 'confluence' or 'jira'.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
export const parseResourceId = resourceId => {
|
|
32
|
+
if (!resourceId) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const [product, contentId, uuid, ...rest] = resourceId.split('/');
|
|
36
|
+
|
|
37
|
+
// invalid if any part is missing or there are extra parts
|
|
38
|
+
if (!product || !contentId || !uuid || rest.length > 0) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// invalid if product is not recognized
|
|
43
|
+
if (!isSyncBlockProduct(product)) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
product,
|
|
48
|
+
contentId,
|
|
49
|
+
uuid
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export const createResourceIdForReference = (product, contentId, uuid) => {
|
|
53
|
+
return `${product}/${contentId}/${uuid}`;
|
|
54
|
+
};
|
|
@@ -4,7 +4,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
7
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
8
8
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
9
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
10
|
import { SyncBlockError } from '../common/types';
|
|
@@ -111,9 +111,12 @@ export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resou
|
|
|
111
111
|
unsubscribe();
|
|
112
112
|
};
|
|
113
113
|
}, [localId, manager.referenceManager, resourceId]);
|
|
114
|
+
var ssrProviders = useMemo(function () {
|
|
115
|
+
return resourceId ? manager.referenceManager.getSSRProviders(resourceId) : null;
|
|
116
|
+
}, [resourceId, manager.referenceManager]);
|
|
114
117
|
return {
|
|
115
118
|
isLoading: isLoading,
|
|
116
|
-
ssrProviders:
|
|
119
|
+
ssrProviders: ssrProviders,
|
|
117
120
|
providerFactory: manager.referenceManager.getProviderFactory(resourceId || ''),
|
|
118
121
|
reloadData: reloadData,
|
|
119
122
|
syncBlockInstance: syncBlockInstance
|
package/dist/esm/index.js
CHANGED
|
@@ -25,7 +25,7 @@ export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager } from './store
|
|
|
25
25
|
|
|
26
26
|
// utils
|
|
27
27
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
28
|
-
export { parseResourceId } from './utils/
|
|
28
|
+
export { parseResourceId, createResourceIdForReference } from './utils/resourceId';
|
|
29
29
|
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId } from './utils/utils';
|
|
30
30
|
export { fetchErrorPayload } from './utils/errorHandling';
|
|
31
31
|
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|
|
@@ -16,6 +16,7 @@ import { generateBlockAri, generateBlockAriFromReference } from '../../clients/b
|
|
|
16
16
|
import { batchRetrieveSyncedBlocks, BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getReferenceSyncedBlocksByBlockAri, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
17
17
|
import { SyncBlockError } from '../../common/types';
|
|
18
18
|
import { stringifyError } from '../../utils/errorHandling';
|
|
19
|
+
import { createResourceIdForReference } from '../../utils/resourceId';
|
|
19
20
|
var mapBlockError = function mapBlockError(error) {
|
|
20
21
|
switch (error.status) {
|
|
21
22
|
case 400:
|
|
@@ -716,7 +717,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
716
717
|
}, {
|
|
717
718
|
key: "generateResourceIdForReference",
|
|
718
719
|
value: function generateResourceIdForReference(sourceId) {
|
|
719
|
-
return
|
|
720
|
+
return createResourceIdForReference(this.product, this.parentId || '', sourceId);
|
|
720
721
|
}
|
|
721
722
|
}, {
|
|
722
723
|
key: "generateResourceId",
|
|
@@ -14,8 +14,8 @@ import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
|
|
|
14
14
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
15
15
|
import { SyncBlockError } from '../common/types';
|
|
16
16
|
import { fetchErrorPayload, getSourceInfoErrorPayload, updateReferenceErrorPayload } from '../utils/errorHandling';
|
|
17
|
-
import { parseResourceId } from '../utils/parseResourceId';
|
|
18
17
|
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
18
|
+
import { parseResourceId } from '../utils/resourceId';
|
|
19
19
|
import { createSyncBlockNode } from '../utils/utils';
|
|
20
20
|
|
|
21
21
|
// A store manager responsible for the lifecycle and state management of reference sync blocks in an editor instance.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import _toArray from "@babel/runtime/helpers/toArray";
|
|
2
|
+
import { SYNC_BLOCK_PRODUCTS } from '../common/consts';
|
|
3
|
+
var isSyncBlockProduct = function isSyncBlockProduct(product) {
|
|
4
|
+
return SYNC_BLOCK_PRODUCTS.includes(product);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Sync Block resourceId utilities
|
|
9
|
+
* --------------------------------
|
|
10
|
+
* Provides helpers to parse and generate the identifier used to
|
|
11
|
+
* reference a synced block across Atlassian products.
|
|
12
|
+
*
|
|
13
|
+
* Format
|
|
14
|
+
* - {product}/{contentId}/{uuid}
|
|
15
|
+
* - product: a recognized `SyncBlockProduct` (e.g. 'confluence-page', 'jira-issue')
|
|
16
|
+
* - contentId: the host content identifier (e.g. page ID or issue ID)
|
|
17
|
+
* - uuid: the UUID for the specific synced block instance
|
|
18
|
+
*
|
|
19
|
+
* Examples
|
|
20
|
+
* - confluence-page/8060929/7f9d9cf8-8483-43ee-99f3-6ca576dbf24d
|
|
21
|
+
*
|
|
22
|
+
* Validation rules (enforced by `parseResourceId`)
|
|
23
|
+
* - Must have exactly three path segments separated by '/'
|
|
24
|
+
* - `product` must be one of `SYNC_BLOCK_PRODUCTS`
|
|
25
|
+
* - No extra segments; returns `undefined` on any invalid input
|
|
26
|
+
*
|
|
27
|
+
* Notes
|
|
28
|
+
* - `product` is a qualified domain like 'confluence-page' or 'jira-issue',
|
|
29
|
+
* not just 'confluence' or 'jira'.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export var parseResourceId = function parseResourceId(resourceId) {
|
|
33
|
+
if (!resourceId) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
var _resourceId$split = resourceId.split('/'),
|
|
37
|
+
_resourceId$split2 = _toArray(_resourceId$split),
|
|
38
|
+
product = _resourceId$split2[0],
|
|
39
|
+
contentId = _resourceId$split2[1],
|
|
40
|
+
uuid = _resourceId$split2[2],
|
|
41
|
+
rest = _resourceId$split2.slice(3);
|
|
42
|
+
|
|
43
|
+
// invalid if any part is missing or there are extra parts
|
|
44
|
+
if (!product || !contentId || !uuid || rest.length > 0) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// invalid if product is not recognized
|
|
49
|
+
if (!isSyncBlockProduct(product)) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
product: product,
|
|
54
|
+
contentId: contentId,
|
|
55
|
+
uuid: uuid
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export var createResourceIdForReference = function createResourceIdForReference(product, contentId, uuid) {
|
|
59
|
+
return "".concat(product, "/").concat(contentId, "/").concat(uuid);
|
|
60
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type { ADFFetchProvider, ADFWriteProvider, SyncBlockDataProvider, SyncBlo
|
|
|
15
15
|
export { type ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
16
16
|
export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager, } from './store-manager/syncBlockStoreManager';
|
|
17
17
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
18
|
-
export { parseResourceId } from './utils/
|
|
18
|
+
export { parseResourceId, createResourceIdForReference } from './utils/resourceId';
|
|
19
19
|
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId, } from './utils/utils';
|
|
20
20
|
export { fetchErrorPayload } from './utils/errorHandling';
|
|
21
21
|
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|
|
@@ -15,7 +15,7 @@ export type { ADFFetchProvider, ADFWriteProvider, SyncBlockDataProvider, SyncBlo
|
|
|
15
15
|
export { type ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
16
16
|
export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager, } from './store-manager/syncBlockStoreManager';
|
|
17
17
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
18
|
-
export { parseResourceId } from './utils/
|
|
18
|
+
export { parseResourceId, createResourceIdForReference } from './utils/resourceId';
|
|
19
19
|
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId, } from './utils/utils';
|
|
20
20
|
export { fetchErrorPayload } from './utils/errorHandling';
|
|
21
21
|
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|
package/package.json
CHANGED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.parseResourceId = void 0;
|
|
8
|
-
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
|
|
9
|
-
var _consts = require("../common/consts");
|
|
10
|
-
var isSyncBlockProduct = function isSyncBlockProduct(product) {
|
|
11
|
-
return _consts.SYNC_BLOCK_PRODUCTS.includes(product);
|
|
12
|
-
};
|
|
13
|
-
var parseResourceId = exports.parseResourceId = function parseResourceId(resourceId) {
|
|
14
|
-
if (!resourceId) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
var _resourceId$split = resourceId.split('/'),
|
|
18
|
-
_resourceId$split2 = (0, _toArray2.default)(_resourceId$split),
|
|
19
|
-
product = _resourceId$split2[0],
|
|
20
|
-
contentId = _resourceId$split2[1],
|
|
21
|
-
uuid = _resourceId$split2[2],
|
|
22
|
-
rest = _resourceId$split2.slice(3);
|
|
23
|
-
|
|
24
|
-
// invalid if any part is missing or there are extra parts
|
|
25
|
-
if (!product || !contentId || !uuid || rest.length > 0) {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// invalid if product is not recognized
|
|
30
|
-
if (!isSyncBlockProduct(product)) {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
product: product,
|
|
35
|
-
contentId: contentId,
|
|
36
|
-
uuid: uuid
|
|
37
|
-
};
|
|
38
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { SYNC_BLOCK_PRODUCTS } from '../common/consts';
|
|
2
|
-
const isSyncBlockProduct = product => {
|
|
3
|
-
return SYNC_BLOCK_PRODUCTS.includes(product);
|
|
4
|
-
};
|
|
5
|
-
export const parseResourceId = resourceId => {
|
|
6
|
-
if (!resourceId) {
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
const [product, contentId, uuid, ...rest] = resourceId.split('/');
|
|
10
|
-
|
|
11
|
-
// invalid if any part is missing or there are extra parts
|
|
12
|
-
if (!product || !contentId || !uuid || rest.length > 0) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// invalid if product is not recognized
|
|
17
|
-
if (!isSyncBlockProduct(product)) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
product,
|
|
22
|
-
contentId,
|
|
23
|
-
uuid
|
|
24
|
-
};
|
|
25
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import _toArray from "@babel/runtime/helpers/toArray";
|
|
2
|
-
import { SYNC_BLOCK_PRODUCTS } from '../common/consts';
|
|
3
|
-
var isSyncBlockProduct = function isSyncBlockProduct(product) {
|
|
4
|
-
return SYNC_BLOCK_PRODUCTS.includes(product);
|
|
5
|
-
};
|
|
6
|
-
export var parseResourceId = function parseResourceId(resourceId) {
|
|
7
|
-
if (!resourceId) {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
var _resourceId$split = resourceId.split('/'),
|
|
11
|
-
_resourceId$split2 = _toArray(_resourceId$split),
|
|
12
|
-
product = _resourceId$split2[0],
|
|
13
|
-
contentId = _resourceId$split2[1],
|
|
14
|
-
uuid = _resourceId$split2[2],
|
|
15
|
-
rest = _resourceId$split2.slice(3);
|
|
16
|
-
|
|
17
|
-
// invalid if any part is missing or there are extra parts
|
|
18
|
-
if (!product || !contentId || !uuid || rest.length > 0) {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// invalid if product is not recognized
|
|
23
|
-
if (!isSyncBlockProduct(product)) {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
product: product,
|
|
28
|
-
contentId: contentId,
|
|
29
|
-
uuid: uuid
|
|
30
|
-
};
|
|
31
|
-
};
|