@atlaskit/editor-synced-block-provider 2.1.2 → 2.2.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 +20 -0
- package/dist/cjs/common/types.js +2 -19
- package/dist/cjs/hooks/useFetchSyncBlockData.js +43 -0
- package/dist/cjs/hooks/useHandleContentChanges.js +13 -0
- package/dist/cjs/index.js +9 -7
- package/dist/cjs/providers/{confluenceContentAPI.js → confluence/confluenceContentAPI.js} +4 -4
- package/dist/cjs/{common → providers}/syncBlockProvider.js +1 -1
- package/dist/cjs/providers/types.js +23 -0
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +123 -0
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +191 -0
- package/dist/cjs/store-manager/syncBlockStoreManager.js +111 -0
- package/dist/cjs/utils/utils.js +1 -17
- package/dist/es2019/common/types.js +1 -3
- package/dist/es2019/hooks/useFetchSyncBlockData.js +32 -0
- package/dist/es2019/hooks/useHandleContentChanges.js +7 -0
- package/dist/es2019/index.js +7 -5
- package/dist/es2019/providers/{confluenceContentAPI.js → confluence/confluenceContentAPI.js} +4 -4
- package/dist/es2019/{common → providers}/syncBlockProvider.js +1 -1
- package/dist/es2019/providers/types.js +2 -0
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +83 -0
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +115 -0
- package/dist/es2019/store-manager/syncBlockStoreManager.js +79 -0
- package/dist/es2019/utils/utils.js +0 -13
- package/dist/esm/common/types.js +1 -17
- package/dist/esm/hooks/useFetchSyncBlockData.js +36 -0
- package/dist/esm/hooks/useHandleContentChanges.js +7 -0
- package/dist/esm/index.js +7 -5
- package/dist/esm/providers/{confluenceContentAPI.js → confluence/confluenceContentAPI.js} +4 -4
- package/dist/esm/{common → providers}/syncBlockProvider.js +1 -1
- package/dist/esm/providers/types.js +16 -0
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +116 -0
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +184 -0
- package/dist/esm/store-manager/syncBlockStoreManager.js +105 -0
- package/dist/esm/utils/utils.js +0 -16
- package/dist/types/common/types.d.ts +12 -25
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +4 -0
- package/dist/types/hooks/useHandleContentChanges.d.ts +3 -0
- package/dist/types/index.d.ts +9 -6
- package/dist/{types-ts4.5/providers → types/providers/confluence}/confluenceContentAPI.d.ts +2 -1
- package/dist/types/providers/{inMemory.d.ts → in-memory/inMemory.d.ts} +1 -1
- package/dist/types/{common → providers}/syncBlockProvider.d.ts +2 -1
- package/dist/types/providers/types.d.ts +17 -0
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +23 -0
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +31 -0
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +36 -0
- package/dist/types/utils/utils.d.ts +1 -2
- package/dist/types-ts4.5/common/types.d.ts +12 -25
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +4 -0
- package/dist/types-ts4.5/hooks/useHandleContentChanges.d.ts +3 -0
- package/dist/types-ts4.5/index.d.ts +9 -6
- package/dist/{types/providers → types-ts4.5/providers/confluence}/confluenceContentAPI.d.ts +2 -1
- package/dist/types-ts4.5/providers/{inMemory.d.ts → in-memory/inMemory.d.ts} +1 -1
- package/dist/types-ts4.5/{common → providers}/syncBlockProvider.d.ts +2 -1
- package/dist/types-ts4.5/providers/types.d.ts +17 -0
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +23 -0
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +31 -0
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +36 -0
- package/dist/types-ts4.5/utils/utils.d.ts +1 -2
- package/package.json +3 -3
- package/dist/cjs/common/syncBlockStoreManager.js +0 -330
- package/dist/es2019/common/syncBlockStoreManager.js +0 -240
- package/dist/esm/common/syncBlockStoreManager.js +0 -323
- package/dist/types/common/syncBlockStoreManager.d.ts +0 -50
- package/dist/types-ts4.5/common/syncBlockStoreManager.d.ts +0 -50
- /package/dist/cjs/providers/{inMemory.js → in-memory/inMemory.js} +0 -0
- /package/dist/es2019/providers/{inMemory.js → in-memory/inMemory.js} +0 -0
- /package/dist/esm/providers/{inMemory.js → in-memory/inMemory.js} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
|
|
2
|
-
import
|
|
2
|
+
import type { SyncBlockData, SyncBlockNode } from '../common/types';
|
|
3
|
+
import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type FetchSyncBlockDataResult } from '../providers/types';
|
|
3
4
|
export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
4
5
|
name: string;
|
|
5
6
|
private fetchProvider;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NodeDataProvider } from '@atlaskit/node-data-provider';
|
|
2
|
+
import type { SyncBlockData, ResourceId, SyncBlockStatus, SyncBlockNode } from '../common/types';
|
|
3
|
+
export type FetchSyncBlockDataResult = SyncBlockData | {
|
|
4
|
+
resourceId?: ResourceId;
|
|
5
|
+
status: SyncBlockStatus;
|
|
6
|
+
};
|
|
7
|
+
export interface ADFFetchProvider {
|
|
8
|
+
fetchData: (resourceId: ResourceId) => Promise<FetchSyncBlockDataResult>;
|
|
9
|
+
}
|
|
10
|
+
export interface ADFWriteProvider {
|
|
11
|
+
writeData: (data: SyncBlockData) => Promise<string>;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, FetchSyncBlockDataResult> {
|
|
14
|
+
abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<ResourceId | undefined>>;
|
|
15
|
+
abstract getSourceId(): ResourceId;
|
|
16
|
+
abstract retrieveSyncBlockSourceUrl(node: SyncBlockNode): Promise<string | undefined>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { BlockInstanceId } from '../common/types';
|
|
3
|
+
import type { FetchSyncBlockDataResult, SyncBlockDataProvider } from '../providers/types';
|
|
4
|
+
export declare class ReferenceSyncBlockStoreManager {
|
|
5
|
+
private dataProvider?;
|
|
6
|
+
private syncBlockCache;
|
|
7
|
+
private syncBlockURLRequests;
|
|
8
|
+
constructor(dataProvider?: SyncBlockDataProvider);
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param localId - The local ID of the sync block to get the source URL for
|
|
12
|
+
* @param resourceId - The resource ID of the sync block to get the source URL for
|
|
13
|
+
* Fetches source URl for a sync block and updates sync block data with the source URL asynchronously.
|
|
14
|
+
*/
|
|
15
|
+
private fetchSyncBlockSourceURL;
|
|
16
|
+
fetchSyncBlockData(syncBlockNode: PMNode): Promise<FetchSyncBlockDataResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Get the URL for a sync block.
|
|
19
|
+
* @param localId - The local ID of the sync block to get the URL for
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getSyncBlockURL(localId: BlockInstanceId): string | undefined;
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { SyncBlockAttrs, SyncBlockNode } from '../common/types';
|
|
5
|
+
import type { SyncBlockDataProvider } from '../providers/types';
|
|
6
|
+
export type ConfirmationCallback = () => Promise<boolean>;
|
|
7
|
+
export declare class SourceSyncBlockStoreManager {
|
|
8
|
+
private dataProvider?;
|
|
9
|
+
private editorView?;
|
|
10
|
+
private syncBlockCache;
|
|
11
|
+
private confirmationCallback?;
|
|
12
|
+
private confirmationTransaction?;
|
|
13
|
+
constructor(dataProvider?: SyncBlockDataProvider);
|
|
14
|
+
/**
|
|
15
|
+
* Add/update a sync block node to/from the local cache
|
|
16
|
+
* @param syncBlockNode - The sync block node to update
|
|
17
|
+
*/
|
|
18
|
+
updateSyncBlockData(syncBlockNode: PMNode): void;
|
|
19
|
+
/**
|
|
20
|
+
* Save content of bodiedSyncBlock nodes in local cache to backend
|
|
21
|
+
*
|
|
22
|
+
* @returns true if saving all nodes successfully, false if fail to save some/all nodes
|
|
23
|
+
*/
|
|
24
|
+
flushBodiedSyncBlocks(): Promise<boolean>;
|
|
25
|
+
setEditorView(editorView: EditorView | undefined): void;
|
|
26
|
+
registerConfirmationCallback(callback: ConfirmationCallback): () => void;
|
|
27
|
+
requireConfirmationBeforeDelete(): boolean;
|
|
28
|
+
createSyncBlockNode(): SyncBlockNode;
|
|
29
|
+
deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
|
|
30
|
+
rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
|
|
2
|
+
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import type { BlockInstanceId, SyncBlockAttrs, SyncBlockNode } from '../common/types';
|
|
5
|
+
import type { FetchSyncBlockDataResult, SyncBlockDataProvider } from '../providers/types';
|
|
6
|
+
import { type ConfirmationCallback } from './sourceSyncBlockStoreManager';
|
|
7
|
+
export declare class SyncBlockStoreManager {
|
|
8
|
+
private referenceSyncBlockStoreManager;
|
|
9
|
+
private sourceSyncBlockStoreManager;
|
|
10
|
+
constructor(dataProvider?: SyncBlockDataProvider);
|
|
11
|
+
fetchSyncBlockData(syncBlockNode: PMNode): Promise<FetchSyncBlockDataResult | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Add/update a sync block node to/from the local cache
|
|
14
|
+
* @param syncBlockNode - The sync block node to update
|
|
15
|
+
*/
|
|
16
|
+
updateSyncBlockData(syncBlockNode: PMNode): void;
|
|
17
|
+
/**
|
|
18
|
+
* Save content of bodiedSyncBlock nodes in local cache to backend
|
|
19
|
+
*
|
|
20
|
+
* @returns true if saving all nodes successfully, false if fail to save some/all nodes
|
|
21
|
+
*/
|
|
22
|
+
flushBodiedSyncBlocks(): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Get the URL for a sync block.
|
|
25
|
+
* @param localId - The local ID of the sync block to get the URL for
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
getSyncBlockURL(localId: BlockInstanceId): string | undefined;
|
|
29
|
+
setEditorView(editorView: EditorView | undefined): void;
|
|
30
|
+
isSourceBlock(node: PMNode): boolean;
|
|
31
|
+
registerConfirmationCallback(callback: ConfirmationCallback): () => void;
|
|
32
|
+
requireConfirmationBeforeDelete(): boolean;
|
|
33
|
+
createSyncBlockNode(): SyncBlockNode;
|
|
34
|
+
deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
|
|
35
|
+
rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
|
|
36
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import type { SyncBlockData
|
|
2
|
+
import type { SyncBlockData } from '../common/types';
|
|
3
3
|
import type { PAGE_TYPE } from './ari';
|
|
4
|
-
export declare const convertSyncBlockPMNodeToSyncBlockNode: (node: PMNode, includeContent?: boolean) => SyncBlockNode;
|
|
5
4
|
export declare const convertSyncBlockPMNodeToSyncBlockData: (node: PMNode) => SyncBlockData;
|
|
6
5
|
export declare const isBlogPageType: (pageType: PAGE_TYPE) => boolean;
|
package/package.json
CHANGED
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@atlaskit/css": "^0.15.0",
|
|
30
30
|
"@atlaskit/editor-json-transformer": "^8.31.0",
|
|
31
31
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
32
|
-
"@atlaskit/node-data-provider": "^7.
|
|
33
|
-
"@atlaskit/primitives": "^16.
|
|
32
|
+
"@atlaskit/node-data-provider": "^7.3.0",
|
|
33
|
+
"@atlaskit/primitives": "^16.1.0",
|
|
34
34
|
"@atlaskit/tokens": "^7.0.0",
|
|
35
35
|
"@babel/runtime": "^7.0.0",
|
|
36
36
|
"@compiled/react": "^0.18.6",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
84
|
"name": "@atlaskit/editor-synced-block-provider",
|
|
85
|
-
"version": "2.1
|
|
85
|
+
"version": "2.2.1",
|
|
86
86
|
"description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
|
|
87
87
|
"author": "Atlassian Pty Ltd",
|
|
88
88
|
"license": "Apache-2.0",
|
|
@@ -1,330 +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.SyncBlockStoreManager = void 0;
|
|
8
|
-
exports.useFetchSyncBlockData = useFetchSyncBlockData;
|
|
9
|
-
exports.useHandleContentChanges = useHandleContentChanges;
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
16
|
-
var _react = require("react");
|
|
17
|
-
var _uuid = _interopRequireDefault(require("uuid"));
|
|
18
|
-
var _ari = require("../utils/ari");
|
|
19
|
-
var _utils = require("../utils/utils");
|
|
20
|
-
var _rebaseTransaction2 = require("./rebase-transaction");
|
|
21
|
-
var _types = require("./types");
|
|
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
|
-
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; }
|
|
24
|
-
// Do this typedef to make it clear that
|
|
25
|
-
// this is a local identifier for a resource for local use
|
|
26
|
-
// A store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
|
|
27
|
-
// Supports create, read, update, and delete operations for sync blocks.
|
|
28
|
-
// Designed to manage local in-memory state and synchronize with an external data provider.
|
|
29
|
-
// Handles caching, debouncing updates, and publish/subscribe for local changes.
|
|
30
|
-
// Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
|
|
31
|
-
var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
32
|
-
function SyncBlockStoreManager(dataProvider) {
|
|
33
|
-
(0, _classCallCheck2.default)(this, SyncBlockStoreManager);
|
|
34
|
-
this.syncBlocks = new Map();
|
|
35
|
-
this.syncBlockURLRequests = new Map();
|
|
36
|
-
this.dataProvider = dataProvider;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* @param node - The sync block node to get the source URL for
|
|
42
|
-
* @returns The source URL for the sync block node if it exists. Otherwise trigger fetch and return undefined, syncBlock will update with URL asynchronously.
|
|
43
|
-
*/
|
|
44
|
-
return (0, _createClass2.default)(SyncBlockStoreManager, [{
|
|
45
|
-
key: "getSyncBlockSourceURL",
|
|
46
|
-
value: function getSyncBlockSourceURL(node) {
|
|
47
|
-
var _this = this;
|
|
48
|
-
var _node$attrs = node.attrs,
|
|
49
|
-
localId = _node$attrs.localId,
|
|
50
|
-
resourceId = _node$attrs.resourceId;
|
|
51
|
-
if (!localId || !resourceId || !this.dataProvider) {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
var existingSyncBlock = this.syncBlocks.get(localId);
|
|
55
|
-
if (!existingSyncBlock) {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
var sourceURL = existingSyncBlock.sourceURL;
|
|
59
|
-
if (sourceURL) {
|
|
60
|
-
return sourceURL;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// if the sync block is a reference block, we need to fetch the URL to the source
|
|
64
|
-
// we could optimise this further by checking if the sync block is on the same page as the source
|
|
65
|
-
if (!this.isSourceBlock(node) && !this.syncBlockURLRequests.get(localId)) {
|
|
66
|
-
var syncBlockNode = (0, _utils.convertSyncBlockPMNodeToSyncBlockNode)(node, false);
|
|
67
|
-
this.syncBlockURLRequests.set(localId, true);
|
|
68
|
-
this.dataProvider.retrieveSyncBlockSourceUrl(syncBlockNode).then(function (sourceURL) {
|
|
69
|
-
var existingSyncBlock = _this.syncBlocks.get(localId);
|
|
70
|
-
if (existingSyncBlock) {
|
|
71
|
-
var syncBlock = _objectSpread(_objectSpread({}, existingSyncBlock), {}, {
|
|
72
|
-
sourceURL: sourceURL
|
|
73
|
-
});
|
|
74
|
-
_this.syncBlocks.set(localId, syncBlock);
|
|
75
|
-
}
|
|
76
|
-
}).finally(function () {
|
|
77
|
-
_this.syncBlockURLRequests.set(localId, false);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
}, {
|
|
83
|
-
key: "fetchSyncBlockData",
|
|
84
|
-
value: function () {
|
|
85
|
-
var _fetchSyncBlockData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(syncBlockNode) {
|
|
86
|
-
var syncNode, data, sourceURL, fetchSyncBlockDataResult;
|
|
87
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
88
|
-
while (1) switch (_context.prev = _context.next) {
|
|
89
|
-
case 0:
|
|
90
|
-
if (['bodiedSyncBlock', 'syncBlock'].includes(syncBlockNode.type.name)) {
|
|
91
|
-
_context.next = 2;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
throw new Error('Node is not a sync block');
|
|
95
|
-
case 2:
|
|
96
|
-
syncNode = (0, _utils.convertSyncBlockPMNodeToSyncBlockNode)(syncBlockNode, false);
|
|
97
|
-
if (this.dataProvider) {
|
|
98
|
-
_context.next = 5;
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
throw new Error('Data provider not set');
|
|
102
|
-
case 5:
|
|
103
|
-
_context.next = 7;
|
|
104
|
-
return this.dataProvider.fetchNodesData([syncNode]);
|
|
105
|
-
case 7:
|
|
106
|
-
data = _context.sent;
|
|
107
|
-
if (data) {
|
|
108
|
-
_context.next = 10;
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
throw new Error('Failed to fetch sync block node data');
|
|
112
|
-
case 10:
|
|
113
|
-
sourceURL = this.getSyncBlockSourceURL(syncBlockNode);
|
|
114
|
-
fetchSyncBlockDataResult = data[0];
|
|
115
|
-
if (!('status' in fetchSyncBlockDataResult)) {
|
|
116
|
-
// only adds it to the map if it did not error out
|
|
117
|
-
this.syncBlocks.set(syncBlockNode.attrs.localId, {
|
|
118
|
-
syncNode: syncNode,
|
|
119
|
-
sourceURL: sourceURL,
|
|
120
|
-
syncBlockData: fetchSyncBlockDataResult
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return _context.abrupt("return", fetchSyncBlockDataResult);
|
|
124
|
-
case 14:
|
|
125
|
-
case "end":
|
|
126
|
-
return _context.stop();
|
|
127
|
-
}
|
|
128
|
-
}, _callee, this);
|
|
129
|
-
}));
|
|
130
|
-
function fetchSyncBlockData(_x) {
|
|
131
|
-
return _fetchSyncBlockData.apply(this, arguments);
|
|
132
|
-
}
|
|
133
|
-
return fetchSyncBlockData;
|
|
134
|
-
}()
|
|
135
|
-
/**
|
|
136
|
-
* Add/update a sync block node to/from the store.
|
|
137
|
-
* @param syncBlockNode - The sync block node to update
|
|
138
|
-
* @param newContent - The updated node content to use for the sync block node
|
|
139
|
-
* @returns True if the sync block node was added/updated
|
|
140
|
-
*/
|
|
141
|
-
}, {
|
|
142
|
-
key: "updateSyncBlockData",
|
|
143
|
-
value: function updateSyncBlockData(syncBlockNode) {
|
|
144
|
-
if (!this.isSourceBlock(syncBlockNode)) {
|
|
145
|
-
throw new Error('Node is not a source sync block');
|
|
146
|
-
}
|
|
147
|
-
if (!this.dataProvider) {
|
|
148
|
-
throw new Error('Data provider not set');
|
|
149
|
-
}
|
|
150
|
-
var _syncBlockNode$attrs = syncBlockNode.attrs,
|
|
151
|
-
localId = _syncBlockNode$attrs.localId,
|
|
152
|
-
resourceId = _syncBlockNode$attrs.resourceId;
|
|
153
|
-
if (!localId || !resourceId) {
|
|
154
|
-
throw new Error('Local ID or resource ID is not set');
|
|
155
|
-
}
|
|
156
|
-
var existingSyncBlock = this.syncBlocks.get(localId);
|
|
157
|
-
var sourceURL = existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.sourceURL;
|
|
158
|
-
var syncBlock = {
|
|
159
|
-
syncNode: (0, _utils.convertSyncBlockPMNodeToSyncBlockNode)(syncBlockNode),
|
|
160
|
-
sourceURL: sourceURL,
|
|
161
|
-
syncBlockData: _objectSpread(_objectSpread({}, (0, _utils.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode)), {}, {
|
|
162
|
-
sourceDocumentAri: resourceId // same as resourceId ARI when content property API
|
|
163
|
-
})
|
|
164
|
-
};
|
|
165
|
-
this.syncBlocks.set(localId, syncBlock);
|
|
166
|
-
|
|
167
|
-
//TODO: EDITOR-1921 - add error analytics
|
|
168
|
-
return !this.isSourceBlock(syncBlockNode) ? Promise.resolve(true) : this.dataProvider.writeNodesData([syncBlock.syncNode], [syncBlock.syncBlockData]).then(function (resourceIds) {
|
|
169
|
-
return resourceIds.every(function (resourceId) {
|
|
170
|
-
return resourceId !== undefined;
|
|
171
|
-
});
|
|
172
|
-
}).catch(function () {
|
|
173
|
-
return false;
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Get the URL for a sync block.
|
|
179
|
-
* @param localId - The local ID of the sync block to get the URL for
|
|
180
|
-
* @returns
|
|
181
|
-
*/
|
|
182
|
-
}, {
|
|
183
|
-
key: "getSyncBlockURL",
|
|
184
|
-
value: function getSyncBlockURL(localId) {
|
|
185
|
-
var syncBlock = this.syncBlocks.get(localId);
|
|
186
|
-
return syncBlock === null || syncBlock === void 0 ? void 0 : syncBlock.sourceURL;
|
|
187
|
-
}
|
|
188
|
-
}, {
|
|
189
|
-
key: "setEditorView",
|
|
190
|
-
value: function setEditorView(editorView) {
|
|
191
|
-
this.editorView = editorView;
|
|
192
|
-
}
|
|
193
|
-
}, {
|
|
194
|
-
key: "isSourceBlock",
|
|
195
|
-
value: function isSourceBlock(node) {
|
|
196
|
-
var _this$dataProvider;
|
|
197
|
-
if (node.type.name !== 'bodiedSyncBlock') {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
var _node$attrs2 = node.attrs,
|
|
201
|
-
resourceId = _node$attrs2.resourceId,
|
|
202
|
-
localId = _node$attrs2.localId;
|
|
203
|
-
var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
|
|
204
|
-
if (!sourceId) {
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
return typeof resourceId === 'string' && typeof sourceId === 'string' && typeof localId === 'string' && resourceId === (0, _ari.resourceIdFromSourceAndLocalId)(sourceId, localId);
|
|
208
|
-
}
|
|
209
|
-
}, {
|
|
210
|
-
key: "registerConfirmationCallback",
|
|
211
|
-
value: function registerConfirmationCallback(callback) {
|
|
212
|
-
var _this2 = this;
|
|
213
|
-
this.confirmationCallback = callback;
|
|
214
|
-
return function () {
|
|
215
|
-
_this2.confirmationCallback = undefined;
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
}, {
|
|
219
|
-
key: "requireConfirmationBeforeDelete",
|
|
220
|
-
value: function requireConfirmationBeforeDelete() {
|
|
221
|
-
return !!this.confirmationCallback;
|
|
222
|
-
}
|
|
223
|
-
}, {
|
|
224
|
-
key: "createSyncBlockNode",
|
|
225
|
-
value: function createSyncBlockNode() {
|
|
226
|
-
var _this$dataProvider2;
|
|
227
|
-
var blockInstanceId = (0, _uuid.default)();
|
|
228
|
-
var sourceId = (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.getSourceId();
|
|
229
|
-
if (!sourceId) {
|
|
230
|
-
throw new Error('Provider of sync block plugin is not set');
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// This should be generated by the data provider implementation as it differs between data providers
|
|
234
|
-
var resourceId = (0, _ari.resourceIdFromSourceAndLocalId)(sourceId, blockInstanceId);
|
|
235
|
-
var syncBlockNode = {
|
|
236
|
-
attrs: {
|
|
237
|
-
resourceId: resourceId,
|
|
238
|
-
localId: blockInstanceId
|
|
239
|
-
},
|
|
240
|
-
type: 'syncBlock'
|
|
241
|
-
};
|
|
242
|
-
return syncBlockNode;
|
|
243
|
-
}
|
|
244
|
-
}, {
|
|
245
|
-
key: "deleteSyncBlocksWithConfirmation",
|
|
246
|
-
value: function () {
|
|
247
|
-
var _deleteSyncBlocksWithConfirmation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(tr, syncBlockIds) {
|
|
248
|
-
var _this3 = this;
|
|
249
|
-
var confirmed, _this$editorView;
|
|
250
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
251
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
252
|
-
case 0:
|
|
253
|
-
if (!this.confirmationCallback) {
|
|
254
|
-
_context2.next = 7;
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
this.confirmationTransaction = tr;
|
|
258
|
-
_context2.next = 4;
|
|
259
|
-
return this.confirmationCallback();
|
|
260
|
-
case 4:
|
|
261
|
-
confirmed = _context2.sent;
|
|
262
|
-
if (confirmed) {
|
|
263
|
-
(_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
|
|
264
|
-
// Need to update the BE on deletion
|
|
265
|
-
syncBlockIds.forEach(function (_ref) {
|
|
266
|
-
var localId = _ref.localId;
|
|
267
|
-
return _this3.syncBlocks.delete(localId);
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
this.confirmationTransaction = undefined;
|
|
271
|
-
case 7:
|
|
272
|
-
case "end":
|
|
273
|
-
return _context2.stop();
|
|
274
|
-
}
|
|
275
|
-
}, _callee2, this);
|
|
276
|
-
}));
|
|
277
|
-
function deleteSyncBlocksWithConfirmation(_x2, _x3) {
|
|
278
|
-
return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
|
|
279
|
-
}
|
|
280
|
-
return deleteSyncBlocksWithConfirmation;
|
|
281
|
-
}()
|
|
282
|
-
}, {
|
|
283
|
-
key: "rebaseTransaction",
|
|
284
|
-
value: function rebaseTransaction(incomingTr, state) {
|
|
285
|
-
if (!this.confirmationTransaction) {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
this.confirmationTransaction = (0, _rebaseTransaction2.rebaseTransaction)(this.confirmationTransaction, incomingTr, state);
|
|
289
|
-
}
|
|
290
|
-
}]);
|
|
291
|
-
}();
|
|
292
|
-
function useFetchSyncBlockData(manager, syncBlockNode) {
|
|
293
|
-
var _useState = (0, _react.useState)(null),
|
|
294
|
-
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
295
|
-
fetchSyncBlockDataResult = _useState2[0],
|
|
296
|
-
setFetchSyncBlockDataResult = _useState2[1];
|
|
297
|
-
var fetchSyncBlockNode = (0, _react.useCallback)(function () {
|
|
298
|
-
manager.fetchSyncBlockData(syncBlockNode).then(function (data) {
|
|
299
|
-
if ('status' in data) {
|
|
300
|
-
// if there is an error, we don't want to replace real existing data with the error data
|
|
301
|
-
if (!fetchSyncBlockDataResult || 'status' in fetchSyncBlockDataResult) {
|
|
302
|
-
setFetchSyncBlockDataResult(data);
|
|
303
|
-
}
|
|
304
|
-
} else {
|
|
305
|
-
setFetchSyncBlockDataResult(data);
|
|
306
|
-
}
|
|
307
|
-
}).catch(function () {
|
|
308
|
-
//TODO: EDITOR-1921 - add error analytics
|
|
309
|
-
if (!fetchSyncBlockDataResult || 'status' in fetchSyncBlockDataResult) {
|
|
310
|
-
setFetchSyncBlockDataResult({
|
|
311
|
-
status: _types.SyncBlockStatus.Errored
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
}, [manager, syncBlockNode, fetchSyncBlockDataResult]);
|
|
316
|
-
(0, _react.useEffect)(function () {
|
|
317
|
-
fetchSyncBlockNode();
|
|
318
|
-
var interval = window.setInterval(fetchSyncBlockNode, 3000);
|
|
319
|
-
return function () {
|
|
320
|
-
window.clearInterval(interval);
|
|
321
|
-
};
|
|
322
|
-
}, [fetchSyncBlockNode]);
|
|
323
|
-
return fetchSyncBlockDataResult;
|
|
324
|
-
}
|
|
325
|
-
function useHandleContentChanges(manager, syncBlockNode) {
|
|
326
|
-
(0, _react.useEffect)(function () {
|
|
327
|
-
//TODO: EDITOR-1921 - add error analytics
|
|
328
|
-
manager.updateSyncBlockData(syncBlockNode);
|
|
329
|
-
}, [manager, syncBlockNode]);
|
|
330
|
-
}
|