@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
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
+
import uuid from 'uuid';
|
|
6
|
+
import { rebaseTransaction as _rebaseTransaction } from '../common/rebase-transaction';
|
|
7
|
+
import { resourceIdFromSourceAndLocalId } from '../utils/ari';
|
|
8
|
+
import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
|
|
9
|
+
export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
10
|
+
function SourceSyncBlockStoreManager(dataProvider) {
|
|
11
|
+
_classCallCheck(this, SourceSyncBlockStoreManager);
|
|
12
|
+
this.dataProvider = dataProvider;
|
|
13
|
+
this.syncBlockCache = new Map();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Add/update a sync block node to/from the local cache
|
|
18
|
+
* @param syncBlockNode - The sync block node to update
|
|
19
|
+
*/
|
|
20
|
+
return _createClass(SourceSyncBlockStoreManager, [{
|
|
21
|
+
key: "updateSyncBlockData",
|
|
22
|
+
value: function updateSyncBlockData(syncBlockNode) {
|
|
23
|
+
try {
|
|
24
|
+
var _syncBlockNode$attrs = syncBlockNode.attrs,
|
|
25
|
+
localId = _syncBlockNode$attrs.localId,
|
|
26
|
+
resourceId = _syncBlockNode$attrs.resourceId;
|
|
27
|
+
if (!localId || !resourceId) {
|
|
28
|
+
throw new Error('Local ID or resource ID is not set');
|
|
29
|
+
}
|
|
30
|
+
var syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
|
|
31
|
+
this.syncBlockCache.set(localId, syncBlockData);
|
|
32
|
+
} catch (_unused) {
|
|
33
|
+
//TODO: EDITOR-1921 - add error analytics
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Save content of bodiedSyncBlock nodes in local cache to backend
|
|
39
|
+
*
|
|
40
|
+
* @returns true if saving all nodes successfully, false if fail to save some/all nodes
|
|
41
|
+
*/
|
|
42
|
+
}, {
|
|
43
|
+
key: "flushBodiedSyncBlocks",
|
|
44
|
+
value: (function () {
|
|
45
|
+
var _flushBodiedSyncBlocks = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
46
|
+
var bodiedSyncBlockNodes, bodiedSyncBlockData, resourceIds;
|
|
47
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
48
|
+
while (1) switch (_context.prev = _context.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
_context.prev = 0;
|
|
51
|
+
if (this.dataProvider) {
|
|
52
|
+
_context.next = 3;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
throw new Error('Data provider not set');
|
|
56
|
+
case 3:
|
|
57
|
+
bodiedSyncBlockNodes = [];
|
|
58
|
+
bodiedSyncBlockData = [];
|
|
59
|
+
Array.from(this.syncBlockCache.values()).forEach(function (syncBlockData) {
|
|
60
|
+
bodiedSyncBlockNodes.push({
|
|
61
|
+
type: 'bodiedSyncBlock',
|
|
62
|
+
attrs: {
|
|
63
|
+
localId: syncBlockData.blockInstanceId,
|
|
64
|
+
resourceId: syncBlockData.resourceId
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
bodiedSyncBlockData.push(syncBlockData);
|
|
68
|
+
});
|
|
69
|
+
if (!(bodiedSyncBlockNodes.length === 0)) {
|
|
70
|
+
_context.next = 8;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
return _context.abrupt("return", Promise.resolve(true));
|
|
74
|
+
case 8:
|
|
75
|
+
_context.next = 10;
|
|
76
|
+
return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
|
|
77
|
+
case 10:
|
|
78
|
+
resourceIds = _context.sent;
|
|
79
|
+
return _context.abrupt("return", resourceIds.every(function (resourceId) {
|
|
80
|
+
return resourceId !== undefined;
|
|
81
|
+
}));
|
|
82
|
+
case 14:
|
|
83
|
+
_context.prev = 14;
|
|
84
|
+
_context.t0 = _context["catch"](0);
|
|
85
|
+
return _context.abrupt("return", false);
|
|
86
|
+
case 17:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context.stop();
|
|
89
|
+
}
|
|
90
|
+
}, _callee, this, [[0, 14]]);
|
|
91
|
+
}));
|
|
92
|
+
function flushBodiedSyncBlocks() {
|
|
93
|
+
return _flushBodiedSyncBlocks.apply(this, arguments);
|
|
94
|
+
}
|
|
95
|
+
return flushBodiedSyncBlocks;
|
|
96
|
+
}())
|
|
97
|
+
}, {
|
|
98
|
+
key: "setEditorView",
|
|
99
|
+
value: function setEditorView(editorView) {
|
|
100
|
+
this.editorView = editorView;
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
key: "registerConfirmationCallback",
|
|
104
|
+
value: function registerConfirmationCallback(callback) {
|
|
105
|
+
var _this = this;
|
|
106
|
+
this.confirmationCallback = callback;
|
|
107
|
+
return function () {
|
|
108
|
+
_this.confirmationCallback = undefined;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}, {
|
|
112
|
+
key: "requireConfirmationBeforeDelete",
|
|
113
|
+
value: function requireConfirmationBeforeDelete() {
|
|
114
|
+
return !!this.confirmationCallback;
|
|
115
|
+
}
|
|
116
|
+
}, {
|
|
117
|
+
key: "createSyncBlockNode",
|
|
118
|
+
value: function createSyncBlockNode() {
|
|
119
|
+
var _this$dataProvider;
|
|
120
|
+
var blockInstanceId = uuid();
|
|
121
|
+
var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
|
|
122
|
+
if (!sourceId) {
|
|
123
|
+
throw new Error('Provider of sync block plugin is not set');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// This should be generated by the data provider implementation as it differs between data providers
|
|
127
|
+
var resourceId = resourceIdFromSourceAndLocalId(sourceId, blockInstanceId);
|
|
128
|
+
var syncBlockNode = {
|
|
129
|
+
attrs: {
|
|
130
|
+
resourceId: resourceId,
|
|
131
|
+
localId: blockInstanceId
|
|
132
|
+
},
|
|
133
|
+
type: 'bodiedSyncBlock'
|
|
134
|
+
};
|
|
135
|
+
return syncBlockNode;
|
|
136
|
+
}
|
|
137
|
+
}, {
|
|
138
|
+
key: "deleteSyncBlocksWithConfirmation",
|
|
139
|
+
value: function () {
|
|
140
|
+
var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(tr, syncBlockIds) {
|
|
141
|
+
var _this2 = this;
|
|
142
|
+
var confirmed, _this$editorView;
|
|
143
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
144
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
145
|
+
case 0:
|
|
146
|
+
if (!this.confirmationCallback) {
|
|
147
|
+
_context2.next = 7;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
this.confirmationTransaction = tr;
|
|
151
|
+
_context2.next = 4;
|
|
152
|
+
return this.confirmationCallback();
|
|
153
|
+
case 4:
|
|
154
|
+
confirmed = _context2.sent;
|
|
155
|
+
if (confirmed) {
|
|
156
|
+
(_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
|
|
157
|
+
// Need to update the BE on deletion
|
|
158
|
+
syncBlockIds.forEach(function (_ref) {
|
|
159
|
+
var localId = _ref.localId;
|
|
160
|
+
return _this2.syncBlockCache.delete(localId);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
this.confirmationTransaction = undefined;
|
|
164
|
+
case 7:
|
|
165
|
+
case "end":
|
|
166
|
+
return _context2.stop();
|
|
167
|
+
}
|
|
168
|
+
}, _callee2, this);
|
|
169
|
+
}));
|
|
170
|
+
function deleteSyncBlocksWithConfirmation(_x, _x2) {
|
|
171
|
+
return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
|
|
172
|
+
}
|
|
173
|
+
return deleteSyncBlocksWithConfirmation;
|
|
174
|
+
}()
|
|
175
|
+
}, {
|
|
176
|
+
key: "rebaseTransaction",
|
|
177
|
+
value: function rebaseTransaction(incomingTr, state) {
|
|
178
|
+
if (!this.confirmationTransaction) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
this.confirmationTransaction = _rebaseTransaction(this.confirmationTransaction, incomingTr, state);
|
|
182
|
+
}
|
|
183
|
+
}]);
|
|
184
|
+
}();
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
|
|
4
|
+
import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
|
|
5
|
+
|
|
6
|
+
// A store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
|
|
7
|
+
// Supports create, read, update, and delete operations for sync blocks.
|
|
8
|
+
// Designed to manage local in-memory state and synchronize with an external data provider.
|
|
9
|
+
// Handles caching, debouncing updates, and publish/subscribe for local changes.
|
|
10
|
+
// Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
|
|
11
|
+
export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
12
|
+
function SyncBlockStoreManager(dataProvider) {
|
|
13
|
+
_classCallCheck(this, SyncBlockStoreManager);
|
|
14
|
+
this.referenceSyncBlockStoreManager = new ReferenceSyncBlockStoreManager(dataProvider);
|
|
15
|
+
this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider);
|
|
16
|
+
}
|
|
17
|
+
return _createClass(SyncBlockStoreManager, [{
|
|
18
|
+
key: "fetchSyncBlockData",
|
|
19
|
+
value: function fetchSyncBlockData(syncBlockNode) {
|
|
20
|
+
if (this.isSourceBlock(syncBlockNode)) {
|
|
21
|
+
return Promise.reject(new Error('Invalid sync block node type provided for fetchSyncBlockData'));
|
|
22
|
+
}
|
|
23
|
+
return this.referenceSyncBlockStoreManager.fetchSyncBlockData(syncBlockNode);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Add/update a sync block node to/from the local cache
|
|
28
|
+
* @param syncBlockNode - The sync block node to update
|
|
29
|
+
*/
|
|
30
|
+
}, {
|
|
31
|
+
key: "updateSyncBlockData",
|
|
32
|
+
value: function updateSyncBlockData(syncBlockNode) {
|
|
33
|
+
if (this.isSourceBlock(syncBlockNode)) {
|
|
34
|
+
this.sourceSyncBlockStoreManager.updateSyncBlockData(syncBlockNode);
|
|
35
|
+
} else {
|
|
36
|
+
throw new Error('Invalid sync block node type provided for updateSyncBlockData');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Save content of bodiedSyncBlock nodes in local cache to backend
|
|
42
|
+
*
|
|
43
|
+
* @returns true if saving all nodes successfully, false if fail to save some/all nodes
|
|
44
|
+
*/
|
|
45
|
+
}, {
|
|
46
|
+
key: "flushBodiedSyncBlocks",
|
|
47
|
+
value: function flushBodiedSyncBlocks() {
|
|
48
|
+
// only applicable to source sync block, for now (will be refactored further)
|
|
49
|
+
return this.sourceSyncBlockStoreManager.flushBodiedSyncBlocks();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get the URL for a sync block.
|
|
54
|
+
* @param localId - The local ID of the sync block to get the URL for
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
}, {
|
|
58
|
+
key: "getSyncBlockURL",
|
|
59
|
+
value: function getSyncBlockURL(localId) {
|
|
60
|
+
// only applicable to reference sync block, for now (will be refactored further)
|
|
61
|
+
return this.referenceSyncBlockStoreManager.getSyncBlockURL(localId);
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "setEditorView",
|
|
65
|
+
value: function setEditorView(editorView) {
|
|
66
|
+
// only applicable to source sync block, for now (will be refactored further)
|
|
67
|
+
this.sourceSyncBlockStoreManager.setEditorView(editorView);
|
|
68
|
+
}
|
|
69
|
+
}, {
|
|
70
|
+
key: "isSourceBlock",
|
|
71
|
+
value: function isSourceBlock(node) {
|
|
72
|
+
return node.type.name === 'bodiedSyncBlock';
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
key: "registerConfirmationCallback",
|
|
76
|
+
value: function registerConfirmationCallback(callback) {
|
|
77
|
+
// only applicable to source sync block, for now (will be refactored further)
|
|
78
|
+
return this.sourceSyncBlockStoreManager.registerConfirmationCallback(callback);
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "requireConfirmationBeforeDelete",
|
|
82
|
+
value: function requireConfirmationBeforeDelete() {
|
|
83
|
+
// only applicable to source sync block, for now (will be refactored further)
|
|
84
|
+
return this.sourceSyncBlockStoreManager.requireConfirmationBeforeDelete();
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: "createSyncBlockNode",
|
|
88
|
+
value: function createSyncBlockNode() {
|
|
89
|
+
// only applicable to source sync block, for now (will be refactored further)
|
|
90
|
+
return this.sourceSyncBlockStoreManager.createSyncBlockNode();
|
|
91
|
+
}
|
|
92
|
+
}, {
|
|
93
|
+
key: "deleteSyncBlocksWithConfirmation",
|
|
94
|
+
value: function deleteSyncBlocksWithConfirmation(tr, syncBlockIds) {
|
|
95
|
+
// only applicable to source sync block, for now (will be refactored further)
|
|
96
|
+
return this.sourceSyncBlockStoreManager.deleteSyncBlocksWithConfirmation(tr, syncBlockIds);
|
|
97
|
+
}
|
|
98
|
+
}, {
|
|
99
|
+
key: "rebaseTransaction",
|
|
100
|
+
value: function rebaseTransaction(incomingTr, state) {
|
|
101
|
+
// only applicable to source sync block, for now (will be refactored further)
|
|
102
|
+
this.sourceSyncBlockStoreManager.rebaseTransaction(incomingTr, state);
|
|
103
|
+
}
|
|
104
|
+
}]);
|
|
105
|
+
}();
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
import { JSONTransformer } from '@atlaskit/editor-json-transformer';
|
|
2
|
-
export var convertSyncBlockPMNodeToSyncBlockNode = function convertSyncBlockPMNodeToSyncBlockNode(node) {
|
|
3
|
-
var includeContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
4
|
-
var transformer = new JSONTransformer();
|
|
5
|
-
var toJSON = function toJSON(node) {
|
|
6
|
-
return transformer.encodeNode(node);
|
|
7
|
-
};
|
|
8
|
-
return {
|
|
9
|
-
type: 'syncBlock',
|
|
10
|
-
attrs: {
|
|
11
|
-
localId: node.attrs.localId,
|
|
12
|
-
resourceId: node.attrs.resourceId
|
|
13
|
-
},
|
|
14
|
-
content: includeContent ? node.content.content.map(toJSON) : undefined
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
1
|
export var convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNodeToSyncBlockData(node) {
|
|
18
2
|
return {
|
|
19
3
|
blockInstanceId: node.attrs.localId,
|
|
@@ -1,42 +1,29 @@
|
|
|
1
1
|
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
2
|
import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
|
|
3
|
-
|
|
3
|
+
export type BlockInstanceId = string;
|
|
4
|
+
export type ResourceId = string;
|
|
4
5
|
export type SyncBlockAttrs = {
|
|
5
|
-
localId:
|
|
6
|
-
resourceId:
|
|
6
|
+
localId: BlockInstanceId;
|
|
7
|
+
resourceId: ResourceId;
|
|
7
8
|
};
|
|
8
|
-
export
|
|
9
|
+
export interface SyncBlockNode extends JSONNode {
|
|
9
10
|
attrs: SyncBlockAttrs;
|
|
10
|
-
content?: Array<JSONNode>;
|
|
11
|
-
type: 'syncBlock';
|
|
12
|
-
}
|
|
11
|
+
content?: Array<JSONNode | undefined>;
|
|
12
|
+
type: 'syncBlock' | 'bodiedSyncBlock';
|
|
13
|
+
}
|
|
13
14
|
export declare enum SyncBlockStatus {
|
|
14
15
|
Errored = "errored",
|
|
15
16
|
NotFound = "not_found",
|
|
16
17
|
Unauthorized = "unauthorized"
|
|
17
18
|
}
|
|
18
|
-
export
|
|
19
|
-
blockInstanceId:
|
|
19
|
+
export interface SyncBlockData {
|
|
20
|
+
blockInstanceId: BlockInstanceId;
|
|
20
21
|
content: Array<ADFEntity>;
|
|
21
22
|
createdAt?: string;
|
|
22
23
|
createdBy?: string;
|
|
23
24
|
isSynced?: boolean;
|
|
24
|
-
resourceId:
|
|
25
|
+
resourceId: ResourceId;
|
|
25
26
|
sourceDocumentAri?: string;
|
|
27
|
+
sourceURL?: string;
|
|
26
28
|
updatedAt?: string;
|
|
27
|
-
};
|
|
28
|
-
export type FetchSyncBlockDataResult = SyncBlockData | {
|
|
29
|
-
resourceId?: string;
|
|
30
|
-
status: SyncBlockStatus;
|
|
31
|
-
};
|
|
32
|
-
export interface ADFFetchProvider {
|
|
33
|
-
fetchData: (resourceId: string) => Promise<FetchSyncBlockDataResult>;
|
|
34
|
-
}
|
|
35
|
-
export interface ADFWriteProvider {
|
|
36
|
-
writeData: (data: SyncBlockData) => Promise<string>;
|
|
37
|
-
}
|
|
38
|
-
export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, FetchSyncBlockDataResult> {
|
|
39
|
-
abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<string | undefined>>;
|
|
40
|
-
abstract getSourceId(): string;
|
|
41
|
-
abstract retrieveSyncBlockSourceUrl(node: SyncBlockNode): Promise<string | undefined>;
|
|
42
29
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { FetchSyncBlockDataResult } from '../providers/types';
|
|
3
|
+
import type { SyncBlockStoreManager } from '../store-manager/syncBlockStoreManager';
|
|
4
|
+
export declare const useFetchSyncBlockData: (manager: SyncBlockStoreManager, syncBlockNode: PMNode) => FetchSyncBlockDataResult | null;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './
|
|
2
|
-
export { SyncBlockStoreManager
|
|
3
|
-
export
|
|
1
|
+
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './providers/syncBlockProvider';
|
|
2
|
+
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
3
|
+
export { useFetchSyncBlockData } from './hooks/useFetchSyncBlockData';
|
|
4
|
+
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
5
|
+
export type { SyncBlockData, SyncBlockNode } from './common/types';
|
|
6
|
+
export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, FetchSyncBlockDataResult, } from './providers/types';
|
|
4
7
|
export { SyncBlockStatus } from './common/types';
|
|
5
|
-
export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
|
|
8
|
+
export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/in-memory/inMemory';
|
|
6
9
|
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
7
|
-
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluenceContentAPI';
|
|
10
|
+
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluence/confluenceContentAPI';
|
|
8
11
|
export { getConfluencePageAri } from './utils/ari';
|
|
9
|
-
export {
|
|
12
|
+
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|
|
10
13
|
export { rebaseTransaction } from './common/rebase-transaction';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type SyncBlockData } from '../../common/types';
|
|
2
|
+
import type { ADFFetchProvider, ADFWriteProvider, FetchSyncBlockDataResult } from '../types';
|
|
2
3
|
/**
|
|
3
4
|
* Configuration for Content API providers
|
|
4
5
|
*/
|
|
@@ -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;
|
|
@@ -1,42 +1,29 @@
|
|
|
1
1
|
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
2
|
import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
|
|
3
|
-
|
|
3
|
+
export type BlockInstanceId = string;
|
|
4
|
+
export type ResourceId = string;
|
|
4
5
|
export type SyncBlockAttrs = {
|
|
5
|
-
localId:
|
|
6
|
-
resourceId:
|
|
6
|
+
localId: BlockInstanceId;
|
|
7
|
+
resourceId: ResourceId;
|
|
7
8
|
};
|
|
8
|
-
export
|
|
9
|
+
export interface SyncBlockNode extends JSONNode {
|
|
9
10
|
attrs: SyncBlockAttrs;
|
|
10
|
-
content?: Array<JSONNode>;
|
|
11
|
-
type: 'syncBlock';
|
|
12
|
-
}
|
|
11
|
+
content?: Array<JSONNode | undefined>;
|
|
12
|
+
type: 'syncBlock' | 'bodiedSyncBlock';
|
|
13
|
+
}
|
|
13
14
|
export declare enum SyncBlockStatus {
|
|
14
15
|
Errored = "errored",
|
|
15
16
|
NotFound = "not_found",
|
|
16
17
|
Unauthorized = "unauthorized"
|
|
17
18
|
}
|
|
18
|
-
export
|
|
19
|
-
blockInstanceId:
|
|
19
|
+
export interface SyncBlockData {
|
|
20
|
+
blockInstanceId: BlockInstanceId;
|
|
20
21
|
content: Array<ADFEntity>;
|
|
21
22
|
createdAt?: string;
|
|
22
23
|
createdBy?: string;
|
|
23
24
|
isSynced?: boolean;
|
|
24
|
-
resourceId:
|
|
25
|
+
resourceId: ResourceId;
|
|
25
26
|
sourceDocumentAri?: string;
|
|
27
|
+
sourceURL?: string;
|
|
26
28
|
updatedAt?: string;
|
|
27
|
-
};
|
|
28
|
-
export type FetchSyncBlockDataResult = SyncBlockData | {
|
|
29
|
-
resourceId?: string;
|
|
30
|
-
status: SyncBlockStatus;
|
|
31
|
-
};
|
|
32
|
-
export interface ADFFetchProvider {
|
|
33
|
-
fetchData: (resourceId: string) => Promise<FetchSyncBlockDataResult>;
|
|
34
|
-
}
|
|
35
|
-
export interface ADFWriteProvider {
|
|
36
|
-
writeData: (data: SyncBlockData) => Promise<string>;
|
|
37
|
-
}
|
|
38
|
-
export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, FetchSyncBlockDataResult> {
|
|
39
|
-
abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<string | undefined>>;
|
|
40
|
-
abstract getSourceId(): string;
|
|
41
|
-
abstract retrieveSyncBlockSourceUrl(node: SyncBlockNode): Promise<string | undefined>;
|
|
42
29
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { FetchSyncBlockDataResult } from '../providers/types';
|
|
3
|
+
import type { SyncBlockStoreManager } from '../store-manager/syncBlockStoreManager';
|
|
4
|
+
export declare const useFetchSyncBlockData: (manager: SyncBlockStoreManager, syncBlockNode: PMNode) => FetchSyncBlockDataResult | null;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './
|
|
2
|
-
export { SyncBlockStoreManager
|
|
3
|
-
export
|
|
1
|
+
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './providers/syncBlockProvider';
|
|
2
|
+
export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
3
|
+
export { useFetchSyncBlockData } from './hooks/useFetchSyncBlockData';
|
|
4
|
+
export { useHandleContentChanges } from './hooks/useHandleContentChanges';
|
|
5
|
+
export type { SyncBlockData, SyncBlockNode } from './common/types';
|
|
6
|
+
export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, FetchSyncBlockDataResult, } from './providers/types';
|
|
4
7
|
export { SyncBlockStatus } from './common/types';
|
|
5
|
-
export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
|
|
8
|
+
export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/in-memory/inMemory';
|
|
6
9
|
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
7
|
-
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluenceContentAPI';
|
|
10
|
+
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluence/confluenceContentAPI';
|
|
8
11
|
export { getConfluencePageAri } from './utils/ari';
|
|
9
|
-
export {
|
|
12
|
+
export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
|
|
10
13
|
export { rebaseTransaction } from './common/rebase-transaction';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type SyncBlockData } from '../../common/types';
|
|
2
|
+
import type { ADFFetchProvider, ADFWriteProvider, FetchSyncBlockDataResult } from '../types';
|
|
2
3
|
/**
|
|
3
4
|
* Configuration for Content API providers
|
|
4
5
|
*/
|