@atlaskit/editor-synced-block-provider 0.2.0 → 0.4.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 +14 -0
- package/dist/cjs/common/rebase-transaction.js +31 -0
- package/dist/cjs/common/syncBlockProvider.js +24 -12
- package/dist/cjs/common/syncBlockStoreManager.js +24 -11
- package/dist/cjs/index.js +34 -1
- package/dist/cjs/providers/confluenceContentAPI.js +238 -0
- package/dist/cjs/utils/ari.js +42 -0
- package/dist/cjs/utils/contentProperty.js +192 -0
- package/dist/es2019/common/rebase-transaction.js +26 -0
- package/dist/es2019/common/syncBlockProvider.js +25 -13
- package/dist/es2019/common/syncBlockStoreManager.js +18 -7
- package/dist/es2019/index.js +5 -2
- package/dist/es2019/providers/confluenceContentAPI.js +150 -0
- package/dist/es2019/utils/ari.js +32 -0
- package/dist/es2019/utils/contentProperty.js +160 -0
- package/dist/esm/common/rebase-transaction.js +26 -0
- package/dist/esm/common/syncBlockProvider.js +24 -12
- package/dist/esm/common/syncBlockStoreManager.js +24 -11
- package/dist/esm/index.js +5 -2
- package/dist/esm/providers/confluenceContentAPI.js +232 -0
- package/dist/esm/utils/ari.js +36 -0
- package/dist/esm/utils/contentProperty.js +185 -0
- package/dist/types/common/rebase-transaction.d.ts +11 -0
- package/dist/types/common/syncBlockProvider.d.ts +3 -1
- package/dist/types/common/syncBlockStoreManager.d.ts +5 -2
- package/dist/types/common/types.d.ts +1 -0
- package/dist/types/index.d.ts +5 -2
- package/dist/types/providers/confluenceContentAPI.d.ts +41 -0
- package/dist/types/utils/ari.d.ts +10 -0
- package/dist/types/utils/contentProperty.d.ts +61 -0
- package/dist/types-ts4.5/common/rebase-transaction.d.ts +11 -0
- package/dist/types-ts4.5/common/syncBlockProvider.d.ts +3 -1
- package/dist/types-ts4.5/common/syncBlockStoreManager.d.ts +5 -2
- package/dist/types-ts4.5/common/types.d.ts +1 -0
- package/dist/types-ts4.5/index.d.ts +5 -2
- package/dist/types-ts4.5/providers/confluenceContentAPI.d.ts +41 -0
- package/dist/types-ts4.5/utils/ari.d.ts +10 -0
- package/dist/types-ts4.5/utils/contentProperty.d.ts +61 -0
- package/package.json +2 -2
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
import { getConfluencePageAri } from './ari';
|
|
7
|
+
var COMMON_HEADERS = {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
Accept: 'application/json'
|
|
10
|
+
};
|
|
11
|
+
var AGG_HEADERS = {
|
|
12
|
+
'X-ExperimentalApi': 'confluence-agg-beta'
|
|
13
|
+
};
|
|
14
|
+
var GRAPHQL_ENDPOINT = '/gateway/api/graphql';
|
|
15
|
+
var GET_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_GET';
|
|
16
|
+
var CREATE_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_CREATE';
|
|
17
|
+
var UPDATE_OPERATION_NAME = 'EDITOR_SYNCED_BLOCK_UPDATE';
|
|
18
|
+
/**
|
|
19
|
+
* Query to get the page property by key
|
|
20
|
+
* @param documentARI
|
|
21
|
+
* @param key
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
var GET_QUERY = "query ".concat(GET_OPERATION_NAME, " ($id: ID!, $keys: [String]!) {\n\t\t\t\t\tconfluence {\n\t\t\t\t\t\tpage (id: $id) {\n\t\t\t\t\t\t\tproperties(keys: $keys) {\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}");
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Query to create a page property with key and value
|
|
28
|
+
* @param documentARI
|
|
29
|
+
* @param key
|
|
30
|
+
* @param value
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
var CREATE_QUERY = "mutation ".concat(CREATE_OPERATION_NAME, " ($input: ConfluenceCreatePagePropertyInput!){\n\t\t\t\t\t\tconfluence {\n\t\t\t\t\t\t\tcreatePageProperty(input: $input) {\n\t\t\t\t\t\t\t\tpageProperty {\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}");
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Query to update a page property with key and value without bumping the version
|
|
37
|
+
* @param documentARI
|
|
38
|
+
* @param key
|
|
39
|
+
* @param value
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
var UPDATE_QUERY = "mutation ".concat(UPDATE_OPERATION_NAME, " ($input: ConfluenceUpdateValuePagePropertyInput!) {\n\t\t\t\t\t\tconfluence {\n\t\t\t\t\t\t\tupdateValuePageProperty(input: $input) {\n\t\t\t\t\t\t\t\tpageProperty {\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}");
|
|
43
|
+
export var getContentProperty = /*#__PURE__*/function () {
|
|
44
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
45
|
+
var pageId, key, cloudId, documentARI, bodyData, response, contentProperty;
|
|
46
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
47
|
+
while (1) switch (_context.prev = _context.next) {
|
|
48
|
+
case 0:
|
|
49
|
+
pageId = _ref.pageId, key = _ref.key, cloudId = _ref.cloudId;
|
|
50
|
+
documentARI = getConfluencePageAri(pageId, cloudId);
|
|
51
|
+
bodyData = {
|
|
52
|
+
query: GET_QUERY,
|
|
53
|
+
operationName: GET_OPERATION_NAME,
|
|
54
|
+
variables: {
|
|
55
|
+
id: documentARI,
|
|
56
|
+
keys: [key]
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
_context.next = 5;
|
|
60
|
+
return fetch(GRAPHQL_ENDPOINT, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
|
|
63
|
+
body: JSON.stringify(bodyData)
|
|
64
|
+
});
|
|
65
|
+
case 5:
|
|
66
|
+
response = _context.sent;
|
|
67
|
+
if (response.ok) {
|
|
68
|
+
_context.next = 8;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
throw new Error("Failed to get content property: ".concat(response.statusText));
|
|
72
|
+
case 8:
|
|
73
|
+
_context.next = 10;
|
|
74
|
+
return response.json();
|
|
75
|
+
case 10:
|
|
76
|
+
contentProperty = _context.sent;
|
|
77
|
+
return _context.abrupt("return", contentProperty);
|
|
78
|
+
case 12:
|
|
79
|
+
case "end":
|
|
80
|
+
return _context.stop();
|
|
81
|
+
}
|
|
82
|
+
}, _callee);
|
|
83
|
+
}));
|
|
84
|
+
return function getContentProperty(_x) {
|
|
85
|
+
return _ref2.apply(this, arguments);
|
|
86
|
+
};
|
|
87
|
+
}();
|
|
88
|
+
export var updateContentProperty = /*#__PURE__*/function () {
|
|
89
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
|
|
90
|
+
var pageId, key, value, cloudId, documentARI, bodyData, response, contentProperty;
|
|
91
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
92
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
93
|
+
case 0:
|
|
94
|
+
pageId = _ref3.pageId, key = _ref3.key, value = _ref3.value, cloudId = _ref3.cloudId;
|
|
95
|
+
documentARI = getConfluencePageAri(pageId, cloudId);
|
|
96
|
+
bodyData = {
|
|
97
|
+
query: UPDATE_QUERY,
|
|
98
|
+
operationName: UPDATE_OPERATION_NAME,
|
|
99
|
+
variables: {
|
|
100
|
+
input: {
|
|
101
|
+
pageId: documentARI,
|
|
102
|
+
key: key,
|
|
103
|
+
value: value,
|
|
104
|
+
useSameVersion: true
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
_context2.next = 5;
|
|
109
|
+
return fetch(GRAPHQL_ENDPOINT, {
|
|
110
|
+
method: 'POST',
|
|
111
|
+
headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
|
|
112
|
+
body: JSON.stringify(bodyData)
|
|
113
|
+
});
|
|
114
|
+
case 5:
|
|
115
|
+
response = _context2.sent;
|
|
116
|
+
if (response.ok) {
|
|
117
|
+
_context2.next = 8;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
throw new Error("Failed to update content property: ".concat(response.statusText));
|
|
121
|
+
case 8:
|
|
122
|
+
_context2.next = 10;
|
|
123
|
+
return response.json();
|
|
124
|
+
case 10:
|
|
125
|
+
contentProperty = _context2.sent;
|
|
126
|
+
return _context2.abrupt("return", contentProperty);
|
|
127
|
+
case 12:
|
|
128
|
+
case "end":
|
|
129
|
+
return _context2.stop();
|
|
130
|
+
}
|
|
131
|
+
}, _callee2);
|
|
132
|
+
}));
|
|
133
|
+
return function updateContentProperty(_x2) {
|
|
134
|
+
return _ref4.apply(this, arguments);
|
|
135
|
+
};
|
|
136
|
+
}();
|
|
137
|
+
export var createContentProperty = /*#__PURE__*/function () {
|
|
138
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
|
|
139
|
+
var pageId, key, value, cloudId, documentARI, escapedValue, bodyData, response, contentProperty;
|
|
140
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
141
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
142
|
+
case 0:
|
|
143
|
+
pageId = _ref5.pageId, key = _ref5.key, value = _ref5.value, cloudId = _ref5.cloudId;
|
|
144
|
+
documentARI = getConfluencePageAri(pageId, cloudId); // eslint-disable-next-line require-unicode-regexp
|
|
145
|
+
escapedValue = value.replace(/"/g, '\\"');
|
|
146
|
+
bodyData = {
|
|
147
|
+
query: CREATE_QUERY,
|
|
148
|
+
operationName: CREATE_OPERATION_NAME,
|
|
149
|
+
variables: {
|
|
150
|
+
input: {
|
|
151
|
+
pageId: documentARI,
|
|
152
|
+
key: key,
|
|
153
|
+
value: escapedValue
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
_context3.next = 6;
|
|
158
|
+
return fetch(GRAPHQL_ENDPOINT, {
|
|
159
|
+
method: 'POST',
|
|
160
|
+
headers: _objectSpread(_objectSpread({}, COMMON_HEADERS), AGG_HEADERS),
|
|
161
|
+
body: JSON.stringify(bodyData)
|
|
162
|
+
});
|
|
163
|
+
case 6:
|
|
164
|
+
response = _context3.sent;
|
|
165
|
+
if (response.ok) {
|
|
166
|
+
_context3.next = 9;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
throw new Error("Failed to create content property: ".concat(response.statusText));
|
|
170
|
+
case 9:
|
|
171
|
+
_context3.next = 11;
|
|
172
|
+
return response.json();
|
|
173
|
+
case 11:
|
|
174
|
+
contentProperty = _context3.sent;
|
|
175
|
+
return _context3.abrupt("return", contentProperty);
|
|
176
|
+
case 13:
|
|
177
|
+
case "end":
|
|
178
|
+
return _context3.stop();
|
|
179
|
+
}
|
|
180
|
+
}, _callee3);
|
|
181
|
+
}));
|
|
182
|
+
return function createContentProperty(_x3) {
|
|
183
|
+
return _ref6.apply(this, arguments);
|
|
184
|
+
};
|
|
185
|
+
}();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
/**
|
|
3
|
+
* Rebase `currentTr` over `incomingTr` based on the provided `state`.
|
|
4
|
+
* This function adjusts the steps in `currentTr` to account for the changes made by `incomingTr`.
|
|
5
|
+
*
|
|
6
|
+
* @param currentTr - The transaction to be rebased.
|
|
7
|
+
* @param incomingTr - The transaction that has already been applied to the state.
|
|
8
|
+
* @param state - The editor state after applying `incomingTr`.
|
|
9
|
+
* @returns A new transaction that represents `currentTr` rebased over `incomingTr`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const rebaseTransaction: (currentTr: Transaction, incomingTr: Transaction, state: EditorState) => Transaction;
|
|
@@ -20,5 +20,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
20
20
|
* @returns the resource ids of the nodes that were written
|
|
21
21
|
*/
|
|
22
22
|
writeNodesData: (nodes: SyncBlockNode[], data: SyncBlockData[]) => Promise<Array<string | undefined>>;
|
|
23
|
+
getSourceId: () => string;
|
|
23
24
|
}
|
|
24
|
-
export declare const useFetchDocNode: (editorView: EditorView, node: PMNode, defaultDocNode: DocNode, provider?:
|
|
25
|
+
export declare const useFetchDocNode: (editorView: EditorView, node: PMNode, defaultDocNode: DocNode, provider?: SyncBlockDataProvider) => DocNode;
|
|
26
|
+
export declare const useMemoizedSyncedBlockProvider: (fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string) => SyncBlockProvider;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
2
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
5
|
import type { SyncBlockAttrs, SyncBlockDataProvider, SyncBlockNode } from './types';
|
|
6
6
|
export interface SyncBlock {
|
|
@@ -17,12 +17,15 @@ export declare class SyncBlockStoreManager {
|
|
|
17
17
|
private syncBlocks;
|
|
18
18
|
private confirmationCallback?;
|
|
19
19
|
private editorView?;
|
|
20
|
-
|
|
20
|
+
private dataProvider?;
|
|
21
|
+
private confirmationTransaction?;
|
|
22
|
+
constructor(dataProvider?: SyncBlockDataProvider);
|
|
21
23
|
setEditorView(editorView: EditorView | undefined): void;
|
|
22
24
|
isSourceBlock(node: PMNode): boolean;
|
|
23
25
|
registerConfirmationCallback(callback: ConfirmationCallback): () => void;
|
|
24
26
|
requireConfirmationBeforeDelete(): boolean;
|
|
25
27
|
createSyncBlockNode(): SyncBlockNode;
|
|
26
28
|
deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
|
|
29
|
+
rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
|
|
27
30
|
}
|
|
28
31
|
export {};
|
|
@@ -22,4 +22,5 @@ export interface ADFWriteProvider {
|
|
|
22
22
|
}
|
|
23
23
|
export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockData> {
|
|
24
24
|
abstract writeNodesData: (nodes: SyncBlockNode[], data: SyncBlockData[]) => Promise<Array<string | undefined>>;
|
|
25
|
+
abstract getSourceId: () => string;
|
|
25
26
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export { SyncBlockProvider as SyncedBlockProvider, useFetchDocNode, } from './common/syncBlockProvider';
|
|
1
|
+
export { SyncBlockProvider as SyncedBlockProvider, useFetchDocNode, useMemoizedSyncedBlockProvider, } from './common/syncBlockProvider';
|
|
2
2
|
export { SyncBlockStoreManager } from './common/syncBlockStoreManager';
|
|
3
3
|
export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockData, SyncBlockNode, } from './common/types';
|
|
4
4
|
export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
|
|
5
|
-
export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
|
|
6
5
|
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
6
|
+
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluenceContentAPI';
|
|
7
|
+
export { getConfluencePageAri } from './utils/ari';
|
|
8
|
+
export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
|
|
9
|
+
export { rebaseTransaction } from './common/rebase-transaction';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
|
+
import type { ADFFetchProvider, ADFWriteProvider, SyncBlockData } from '../common/types';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for Content API providers
|
|
5
|
+
*/
|
|
6
|
+
interface ContentAPIConfig {
|
|
7
|
+
cloudId: string;
|
|
8
|
+
contentPropertyKey: string;
|
|
9
|
+
}
|
|
10
|
+
export type SyncedBlockContentPropertyValue = {
|
|
11
|
+
content?: ADFEntity;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* ADFFetchProvider implementation that fetches synced block data from Confluence Content API
|
|
15
|
+
*/
|
|
16
|
+
declare class ConfluenceADFFetchProvider implements ADFFetchProvider {
|
|
17
|
+
private config;
|
|
18
|
+
constructor(config: ContentAPIConfig);
|
|
19
|
+
fetchData(resourceId: string): Promise<SyncBlockData>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* ADFWriteProvider implementation that writes synced block data to Confluence Content API
|
|
23
|
+
*/
|
|
24
|
+
declare class ConfluenceADFWriteProvider implements ADFWriteProvider {
|
|
25
|
+
private config;
|
|
26
|
+
constructor(config: ContentAPIConfig);
|
|
27
|
+
private createNewContentProperty;
|
|
28
|
+
writeData(sourceId: string, localId: string, data: ADFEntity, resourceId?: string): Promise<string>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convenience function to create providers with default content property key
|
|
32
|
+
*/
|
|
33
|
+
export declare const createContentAPIProvidersWithDefaultKey: (cloudId: string) => {
|
|
34
|
+
fetchProvider: ConfluenceADFFetchProvider;
|
|
35
|
+
writeProvider: ConfluenceADFWriteProvider;
|
|
36
|
+
};
|
|
37
|
+
export declare const useMemoizedContentAPIProviders: (cloudId: string) => {
|
|
38
|
+
fetchProvider: ConfluenceADFFetchProvider;
|
|
39
|
+
writeProvider: ConfluenceADFWriteProvider;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const getConfluencePageAri: (pageId: string, cloudId: string) => string;
|
|
2
|
+
export declare const getPageIdFromAri: (ari: string) => string;
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param ari ari:cloud:confluence:<cloudId>:page/<pageId>/<localId>
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const getLocalIdFromAri: (ari: string) => string;
|
|
9
|
+
export declare const getContentPropertyAri: (contentPropertyId: string, cloudId: string) => string;
|
|
10
|
+
export declare const getContentPropertyIdFromAri: (ari: string) => string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
type GetContentPropertyOptions = {
|
|
2
|
+
cloudId: string;
|
|
3
|
+
key: string;
|
|
4
|
+
pageId: string;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
};
|
|
7
|
+
type CreateContentPropertyOptions = {
|
|
8
|
+
cloudId: string;
|
|
9
|
+
key: string;
|
|
10
|
+
pageId: string;
|
|
11
|
+
value: string;
|
|
12
|
+
};
|
|
13
|
+
type UpdateContentPropertyOptions = {
|
|
14
|
+
cloudId: string;
|
|
15
|
+
key: string;
|
|
16
|
+
pageId: string;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
export type GetContentPropertyResult = {
|
|
21
|
+
data: {
|
|
22
|
+
confluence: {
|
|
23
|
+
page: {
|
|
24
|
+
properties: [
|
|
25
|
+
{
|
|
26
|
+
key: string | null;
|
|
27
|
+
value: string | null;
|
|
28
|
+
}
|
|
29
|
+
] | null;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type UpdateContentPropertyResult = {
|
|
35
|
+
data: {
|
|
36
|
+
confluence: {
|
|
37
|
+
updateValuePageProperty: {
|
|
38
|
+
pageProperty: {
|
|
39
|
+
key: string | null;
|
|
40
|
+
value: string | null;
|
|
41
|
+
} | null;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export type CreateContentPropertyResult = {
|
|
47
|
+
data: {
|
|
48
|
+
confluence: {
|
|
49
|
+
createPageProperty: {
|
|
50
|
+
pageProperty: {
|
|
51
|
+
key: string | null;
|
|
52
|
+
value: string | null;
|
|
53
|
+
} | null;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export declare const getContentProperty: ({ pageId, key, cloudId, }: GetContentPropertyOptions) => Promise<GetContentPropertyResult>;
|
|
59
|
+
export declare const updateContentProperty: ({ pageId, key, value, cloudId, }: UpdateContentPropertyOptions) => Promise<UpdateContentPropertyResult>;
|
|
60
|
+
export declare const createContentProperty: ({ pageId, key, value, cloudId, }: CreateContentPropertyOptions) => Promise<CreateContentPropertyResult>;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
/**
|
|
3
|
+
* Rebase `currentTr` over `incomingTr` based on the provided `state`.
|
|
4
|
+
* This function adjusts the steps in `currentTr` to account for the changes made by `incomingTr`.
|
|
5
|
+
*
|
|
6
|
+
* @param currentTr - The transaction to be rebased.
|
|
7
|
+
* @param incomingTr - The transaction that has already been applied to the state.
|
|
8
|
+
* @param state - The editor state after applying `incomingTr`.
|
|
9
|
+
* @returns A new transaction that represents `currentTr` rebased over `incomingTr`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const rebaseTransaction: (currentTr: Transaction, incomingTr: Transaction, state: EditorState) => Transaction;
|
|
@@ -20,5 +20,7 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
20
20
|
* @returns the resource ids of the nodes that were written
|
|
21
21
|
*/
|
|
22
22
|
writeNodesData: (nodes: SyncBlockNode[], data: SyncBlockData[]) => Promise<Array<string | undefined>>;
|
|
23
|
+
getSourceId: () => string;
|
|
23
24
|
}
|
|
24
|
-
export declare const useFetchDocNode: (editorView: EditorView, node: PMNode, defaultDocNode: DocNode, provider?:
|
|
25
|
+
export declare const useFetchDocNode: (editorView: EditorView, node: PMNode, defaultDocNode: DocNode, provider?: SyncBlockDataProvider) => DocNode;
|
|
26
|
+
export declare const useMemoizedSyncedBlockProvider: (fetchProvider: ADFFetchProvider, writeProvider: ADFWriteProvider, sourceId: string) => SyncBlockProvider;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
2
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
5
|
import type { SyncBlockAttrs, SyncBlockDataProvider, SyncBlockNode } from './types';
|
|
6
6
|
export interface SyncBlock {
|
|
@@ -17,12 +17,15 @@ export declare class SyncBlockStoreManager {
|
|
|
17
17
|
private syncBlocks;
|
|
18
18
|
private confirmationCallback?;
|
|
19
19
|
private editorView?;
|
|
20
|
-
|
|
20
|
+
private dataProvider?;
|
|
21
|
+
private confirmationTransaction?;
|
|
22
|
+
constructor(dataProvider?: SyncBlockDataProvider);
|
|
21
23
|
setEditorView(editorView: EditorView | undefined): void;
|
|
22
24
|
isSourceBlock(node: PMNode): boolean;
|
|
23
25
|
registerConfirmationCallback(callback: ConfirmationCallback): () => void;
|
|
24
26
|
requireConfirmationBeforeDelete(): boolean;
|
|
25
27
|
createSyncBlockNode(): SyncBlockNode;
|
|
26
28
|
deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
|
|
29
|
+
rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
|
|
27
30
|
}
|
|
28
31
|
export {};
|
|
@@ -22,4 +22,5 @@ export interface ADFWriteProvider {
|
|
|
22
22
|
}
|
|
23
23
|
export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockData> {
|
|
24
24
|
abstract writeNodesData: (nodes: SyncBlockNode[], data: SyncBlockData[]) => Promise<Array<string | undefined>>;
|
|
25
|
+
abstract getSourceId: () => string;
|
|
25
26
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export { SyncBlockProvider as SyncedBlockProvider, useFetchDocNode, } from './common/syncBlockProvider';
|
|
1
|
+
export { SyncBlockProvider as SyncedBlockProvider, useFetchDocNode, useMemoizedSyncedBlockProvider, } from './common/syncBlockProvider';
|
|
2
2
|
export { SyncBlockStoreManager } from './common/syncBlockStoreManager';
|
|
3
3
|
export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockData, SyncBlockNode, } from './common/types';
|
|
4
4
|
export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
|
|
5
|
-
export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
|
|
6
5
|
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
6
|
+
export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders, } from './providers/confluenceContentAPI';
|
|
7
|
+
export { getConfluencePageAri } from './utils/ari';
|
|
8
|
+
export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
|
|
9
|
+
export { rebaseTransaction } from './common/rebase-transaction';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
|
+
import type { ADFFetchProvider, ADFWriteProvider, SyncBlockData } from '../common/types';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for Content API providers
|
|
5
|
+
*/
|
|
6
|
+
interface ContentAPIConfig {
|
|
7
|
+
cloudId: string;
|
|
8
|
+
contentPropertyKey: string;
|
|
9
|
+
}
|
|
10
|
+
export type SyncedBlockContentPropertyValue = {
|
|
11
|
+
content?: ADFEntity;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* ADFFetchProvider implementation that fetches synced block data from Confluence Content API
|
|
15
|
+
*/
|
|
16
|
+
declare class ConfluenceADFFetchProvider implements ADFFetchProvider {
|
|
17
|
+
private config;
|
|
18
|
+
constructor(config: ContentAPIConfig);
|
|
19
|
+
fetchData(resourceId: string): Promise<SyncBlockData>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* ADFWriteProvider implementation that writes synced block data to Confluence Content API
|
|
23
|
+
*/
|
|
24
|
+
declare class ConfluenceADFWriteProvider implements ADFWriteProvider {
|
|
25
|
+
private config;
|
|
26
|
+
constructor(config: ContentAPIConfig);
|
|
27
|
+
private createNewContentProperty;
|
|
28
|
+
writeData(sourceId: string, localId: string, data: ADFEntity, resourceId?: string): Promise<string>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convenience function to create providers with default content property key
|
|
32
|
+
*/
|
|
33
|
+
export declare const createContentAPIProvidersWithDefaultKey: (cloudId: string) => {
|
|
34
|
+
fetchProvider: ConfluenceADFFetchProvider;
|
|
35
|
+
writeProvider: ConfluenceADFWriteProvider;
|
|
36
|
+
};
|
|
37
|
+
export declare const useMemoizedContentAPIProviders: (cloudId: string) => {
|
|
38
|
+
fetchProvider: ConfluenceADFFetchProvider;
|
|
39
|
+
writeProvider: ConfluenceADFWriteProvider;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const getConfluencePageAri: (pageId: string, cloudId: string) => string;
|
|
2
|
+
export declare const getPageIdFromAri: (ari: string) => string;
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param ari ari:cloud:confluence:<cloudId>:page/<pageId>/<localId>
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const getLocalIdFromAri: (ari: string) => string;
|
|
9
|
+
export declare const getContentPropertyAri: (contentPropertyId: string, cloudId: string) => string;
|
|
10
|
+
export declare const getContentPropertyIdFromAri: (ari: string) => string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
type GetContentPropertyOptions = {
|
|
2
|
+
cloudId: string;
|
|
3
|
+
key: string;
|
|
4
|
+
pageId: string;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
};
|
|
7
|
+
type CreateContentPropertyOptions = {
|
|
8
|
+
cloudId: string;
|
|
9
|
+
key: string;
|
|
10
|
+
pageId: string;
|
|
11
|
+
value: string;
|
|
12
|
+
};
|
|
13
|
+
type UpdateContentPropertyOptions = {
|
|
14
|
+
cloudId: string;
|
|
15
|
+
key: string;
|
|
16
|
+
pageId: string;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
export type GetContentPropertyResult = {
|
|
21
|
+
data: {
|
|
22
|
+
confluence: {
|
|
23
|
+
page: {
|
|
24
|
+
properties: [
|
|
25
|
+
{
|
|
26
|
+
key: string | null;
|
|
27
|
+
value: string | null;
|
|
28
|
+
}
|
|
29
|
+
] | null;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type UpdateContentPropertyResult = {
|
|
35
|
+
data: {
|
|
36
|
+
confluence: {
|
|
37
|
+
updateValuePageProperty: {
|
|
38
|
+
pageProperty: {
|
|
39
|
+
key: string | null;
|
|
40
|
+
value: string | null;
|
|
41
|
+
} | null;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export type CreateContentPropertyResult = {
|
|
47
|
+
data: {
|
|
48
|
+
confluence: {
|
|
49
|
+
createPageProperty: {
|
|
50
|
+
pageProperty: {
|
|
51
|
+
key: string | null;
|
|
52
|
+
value: string | null;
|
|
53
|
+
} | null;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export declare const getContentProperty: ({ pageId, key, cloudId, }: GetContentPropertyOptions) => Promise<GetContentPropertyResult>;
|
|
59
|
+
export declare const updateContentProperty: ({ pageId, key, value, cloudId, }: UpdateContentPropertyOptions) => Promise<UpdateContentPropertyResult>;
|
|
60
|
+
export declare const createContentProperty: ({ pageId, key, value, cloudId, }: CreateContentPropertyOptions) => Promise<CreateContentPropertyResult>;
|
|
61
|
+
export {};
|
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@atlaskit/css": "^0.14.0",
|
|
30
30
|
"@atlaskit/editor-json-transformer": "^8.30.0",
|
|
31
31
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
32
|
-
"@atlaskit/node-data-provider": "^7.
|
|
32
|
+
"@atlaskit/node-data-provider": "^7.1.0",
|
|
33
33
|
"@atlaskit/primitives": "^14.15.0",
|
|
34
34
|
"@atlaskit/tokens": "^6.4.0",
|
|
35
35
|
"@babel/runtime": "^7.0.0",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
84
|
"name": "@atlaskit/editor-synced-block-provider",
|
|
85
|
-
"version": "0.
|
|
85
|
+
"version": "0.4.0",
|
|
86
86
|
"description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
|
|
87
87
|
"author": "Atlassian Pty Ltd",
|
|
88
88
|
"license": "Apache-2.0",
|