@atlaskit/node-data-provider 4.2.0 → 4.3.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.
@@ -0,0 +1,216 @@
1
+ import { isSSR } from '@atlaskit/editor-common/core-utils';
2
+
3
+ /**
4
+ * Represents the SSR data for a single provider.
5
+ * It's a map where each key is a unique node data key and the value is the prefetched data for that node.
6
+ *
7
+ * @example
8
+ * {
9
+ * 'node-id-1': { value: 'some data' },
10
+ * 'node-id-2': { value: 'other data' }
11
+ * }
12
+ */
13
+
14
+ /**
15
+ * Represents the cached data for a Node Data Provider.
16
+ * Each key is a unique node data key, and the value is an object containing:
17
+ * - `source`: Indicates whether the data was fetched from SSR or the network.
18
+ * - `data`: The actual data, which can be either a resolved value or a Promise.
19
+ *
20
+ * @example
21
+ * {
22
+ * 'node-id-1': { source: 'ssr', data: { value: 'some data' } },
23
+ * 'node-id-2': { source: 'network', data: Promise.resolve({ value: 'other data' }) }
24
+ * }
25
+ */
26
+
27
+ /**
28
+ * A Node Data Provider is responsible for fetching and caching data associated with specific ProseMirror nodes.
29
+ * It supports a cache-first-then-network strategy, with initial data potentially provided via SSR.
30
+ *
31
+ * @template Node The specific type of JSONNode this provider supports.
32
+ * @template Data The type of data this provider fetches and manages.
33
+ */
34
+ export class NodeDataProvider {
35
+ /**
36
+ * A unique name for the provider. Used for identification in SSR.
37
+ */
38
+
39
+ /**
40
+ * A type guard to check if a given JSONNode is supported by this provider.
41
+ * Used to ensure that the provider can handle the node type before attempting to fetch data.
42
+ *
43
+ * @param node The node to check.
44
+ * @returns `true` if the node is of the type supported by this provider, otherwise `false`.
45
+ */
46
+
47
+ /**
48
+ * Generates a unique key for a given node to be used for caching.
49
+ *
50
+ * @param node The node for which to generate a data key.
51
+ * @returns A unique string key for the node's data.
52
+ */
53
+
54
+ /**
55
+ * Fetches data for a batch of nodes from the network or another asynchronous source.
56
+ *
57
+ * @param nodes An array of nodes for which to fetch data.
58
+ * @returns A promise that resolves to an array of data corresponding to the input nodes.
59
+ */
60
+
61
+ constructor() {
62
+ this.cacheVersion = 0;
63
+ this.cache = {};
64
+ }
65
+
66
+ /**
67
+ * Sets the SSR data for the provider.
68
+ * This pre-populates the cache with data rendered on the server, preventing redundant network requests on the client.
69
+ * Calling this method will invalidate the existing cache.
70
+ *
71
+ * @example
72
+ * ```
73
+ * const ssrData = window.__SSR_NODE_DATA__ || {};
74
+ * nodeDataProvider.setSSRData(ssrData);
75
+ * ```
76
+ *
77
+ * @param ssrData A map of node data keys to their corresponding data.
78
+ */
79
+ setSSRData(ssrData = {}) {
80
+ this.cacheVersion++;
81
+ this.cache = Object.entries(ssrData).reduce((acc, [key, data]) => {
82
+ acc[key] = {
83
+ source: 'ssr',
84
+ data
85
+ };
86
+ return acc;
87
+ }, {});
88
+ }
89
+
90
+ /**
91
+ * Clears all cached data.
92
+ * This increments the internal cache version, invalidating any pending network requests.
93
+ *
94
+ * @example
95
+ * ```
96
+ * function useMyNodeDataProvider(contentId: string) {
97
+ * const nodeDataProvider = new MyNodeDataProvider();
98
+ *
99
+ * // Reset the cache when the contentId changes (e.g., when the user navigates to a different page).
100
+ * useEffect(() => {
101
+ * nodeDataProvider.resetCache();
102
+ * }, [contentId]);
103
+ *
104
+ * return nodeDataProvider;
105
+ * }
106
+ * ```
107
+ */
108
+ resetCache() {
109
+ this.cacheVersion++;
110
+ this.cache = {};
111
+ }
112
+
113
+ /**
114
+ * Fetches data for a given node using a cache-first-then-network strategy.
115
+ *
116
+ * The provided callback may be called multiple times:
117
+ * 1. Immediately with data from the SSR cache, if available.
118
+ * 2. Asynchronously with data fetched from the network.
119
+ *
120
+ * @example
121
+ * ```
122
+ * const nodeDataProvider = new MyNodeDataProvider();
123
+ *
124
+ * nodeDataProvider.getData(node, (data) => {
125
+ * console.log('Node data:', data);
126
+ * });
127
+ * ```
128
+ *
129
+ * @param node The node (or its ProseMirror representation) for which to fetch data.
130
+ * @param callback The function to call when data is available.
131
+ */
132
+ getData(node, callback) {
133
+ // Move implementation to a separate async method
134
+ // to keep this method synchronous and avoid async/await in the public API.
135
+ void this.getDataAsync(node, callback);
136
+ }
137
+ async getDataAsync(node, callback) {
138
+ const jsonNode = 'toJSON' in node ? node.toJSON() : node;
139
+ if (!this.isNodeSupported(jsonNode)) {
140
+ // eslint-disable-next-line no-console
141
+ console.error(`The ${this.constructor.name} doesn't support Node ${jsonNode.type}.`);
142
+ return;
143
+ }
144
+ const dataKey = this.nodeDataKey(jsonNode);
145
+ const dataFromCache = this.cache[dataKey];
146
+ if (dataFromCache !== undefined) {
147
+ // If we have the data in the SSR data, we can use it directly
148
+ if (isPromise(dataFromCache.data)) {
149
+ callback(await dataFromCache.data);
150
+ } else {
151
+ callback(dataFromCache.data);
152
+ }
153
+ if (isSSR()) {
154
+ // If we are in SSR, we don't want to fetch the data again, as it is already available in the SSR data
155
+ return;
156
+ }
157
+ }
158
+
159
+ // If no data is available in the cache or the data is from the network,
160
+ // we need to fetch it from the network.
161
+ if ((dataFromCache === null || dataFromCache === void 0 ? void 0 : dataFromCache.source) !== 'network') {
162
+ // Store the current cache version before making the request,
163
+ // so we can check if the cache has changed while we are waiting for the network response.
164
+ const cacheVersionBeforeRequest = this.cacheVersion;
165
+ const dataPromise = this.fetchNodesData([jsonNode]).then(([value]) => value);
166
+ // Store the promise in the cache to avoid multiple requests for the same data
167
+ this.cache[dataKey] = {
168
+ source: 'network',
169
+ data: dataPromise
170
+ };
171
+ const data = await dataPromise;
172
+ // We need to call the callback with the data with result even if the cache version has changed,
173
+ // so all promises that are waiting for the data can resolve.
174
+ callback(data);
175
+
176
+ // If the cache version has changed, we don't want to use the data from the network
177
+ // because it could be stale data.
178
+ if (cacheVersionBeforeRequest === this.cacheVersion) {
179
+ // Replace promise with the resolved data in the cache
180
+ this.cache[dataKey] = {
181
+ source: 'network',
182
+ data
183
+ };
184
+ }
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Fetches data for a given node and returns it as a Promise.
190
+ * This is a convenience wrapper around the `data` method for use with async/await.
191
+ *
192
+ * Note: This promise resolves with the *first* available data, which could be from the SSR cache or the network.
193
+ * It may not provide the most up-to-date data if a network fetch is in progress.
194
+ *
195
+ * Note: This method is only for migration purposes. Use {@link getData} in new code instead.
196
+ *
197
+ * @private
198
+ * @deprecated Don't use this method, use {@link getData} method instead.
199
+ * This method is only for migration purposes.
200
+ *
201
+ * @param node The node (or its ProseMirror representation) for which to fetch data.
202
+ * @returns A promise that resolves with the node's data.
203
+ */
204
+ getDataAsPromise_DO_NOT_USE_OUTSIDE_MIGRATIONS(node) {
205
+ return new Promise((resolve, reject) => {
206
+ try {
207
+ return this.getData(node, resolve);
208
+ } catch (error) {
209
+ reject(error);
210
+ }
211
+ });
212
+ }
213
+ }
214
+ function isPromise(value) {
215
+ return typeof value === 'object' && value !== null && 'then' in value && typeof value.then === 'function';
216
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Finds nodes in the document that are supported by the given providers, up to a maximum number of nodes.
3
+ *
4
+ * @param doc The document to search for nodes.
5
+ * @param providers An array of providers with their maximum nodes to prefetch.
6
+ * @param maxNodesToVisit The maximum number of nodes to visit in the document.
7
+ * @returns An array of objects, each containing a provider and the nodes that are supported by that provider.
8
+ */
9
+ export function findNodesToPrefetch(doc, providers, maxNodesToVisit) {
10
+ let totalVisitedNodesCount = 0;
11
+ const resultMap = providers.reduce((acc, {
12
+ provider
13
+ }) => {
14
+ acc[provider.name] = {
15
+ provider,
16
+ nodes: []
17
+ };
18
+ return acc;
19
+ }, {});
20
+
21
+ // It doesn't use `filter` function from `@atlaskit/adf-utils/traverse` because it does not support early stopping.
22
+ // We need to stop traversing when we reach the maximum number of nodes to visit to support large documents.
23
+
24
+ const providersToLookup = providers.filter(({
25
+ maxNodesToPrefetch
26
+ }) => maxNodesToPrefetch > 0).map(({
27
+ provider,
28
+ maxNodesToPrefetch
29
+ }) => ({
30
+ provider,
31
+ maxNodesToPrefetch,
32
+ foundNodes: 0
33
+ }));
34
+ const nodesToVisit = [doc];
35
+ let currentIndex = 0;
36
+ while (currentIndex < nodesToVisit.length && providersToLookup.length > 0 && totalVisitedNodesCount < maxNodesToVisit) {
37
+ totalVisitedNodesCount += 1;
38
+ const currentNode = nodesToVisit[currentIndex];
39
+ currentIndex++;
40
+
41
+ // Using reverse loop to avoid issues with array mutation
42
+ for (let i = providersToLookup.length - 1; i >= 0; i--) {
43
+ const providerToFind = providersToLookup[i];
44
+ if (providerToFind.provider.isNodeSupported(currentNode)) {
45
+ resultMap[providerToFind.provider.name].nodes.push(currentNode);
46
+ providerToFind.foundNodes += 1;
47
+ if (providerToFind.foundNodes >= providerToFind.maxNodesToPrefetch) {
48
+ providersToLookup.splice(i, 1);
49
+ }
50
+ }
51
+ }
52
+ if (currentNode.content) {
53
+ nodesToVisit.push(...currentNode.content.filter(node => node !== undefined));
54
+ }
55
+ }
56
+ return Object.values(resultMap);
57
+ }
@@ -0,0 +1,128 @@
1
+ import { findNodesToPrefetch } from './find-nodes-to-prefetch';
2
+
3
+ /**
4
+ * Represents the SSR data for a single provider.
5
+ * It's a map where each key is a unique node data key and the value is the prefetched data for that node.
6
+ *
7
+ * @example
8
+ * {
9
+ * 'node-id-1': { value: 'some data' },
10
+ * 'node-id-2': { value: 'other data' }
11
+ * }
12
+ */
13
+
14
+ /**
15
+ * Represents the aggregated SSR data for all node data providers.
16
+ * It's a map where each key is a provider's name and the value is the {@link SsrData} for that provider.
17
+ * This structure is used to hydrate the client-side caches.
18
+ *
19
+ * @example
20
+ * {
21
+ * 'mentionProvider': { 'mention-1': { id: '1', name: 'John Doe' } },
22
+ * 'emojiProvider': { 'emoji-123': { shortName: ':smile:', representation: '😊' } }
23
+ * }
24
+ */
25
+
26
+ /**
27
+ * Fetches data for nodes in the document that are supported by the given providers.
28
+ * This function will traverse the document and call the `fetchData` method for each node that is supported by the providers.
29
+ *
30
+ * @example
31
+ * ```
32
+ * const doc = JSON.parse('{"type": "doc", "content": [...] }');
33
+ * const providers = [
34
+ * {
35
+ * provider: new EditorCardProvider(),
36
+ * maxNodesToPrefetch: 10,
37
+ * timeout: 500,
38
+ * },
39
+ * {
40
+ * provider: new EditorMentionsProvider(),
41
+ * maxNodesToPrefetch: 50,
42
+ * timeout: 500,
43
+ * },
44
+ * ];
45
+ *
46
+ * window['__SSR_EDITOR_NODE_DATA_PROVIDERS_DATA__'] = await prefetchNodeDataProvidersData({
47
+ * providers,
48
+ * doc,
49
+ * timeout: 1_000,
50
+ * maxNodesToVisit: 2_000
51
+ * });
52
+ * ```
53
+ *
54
+ * @param props The properties for prefetching node data.
55
+ * @returns Record of provider names to their respective SSR data,
56
+ * where each SSR data is a record of node data keys to the fetched data.
57
+ */
58
+ export async function prefetchNodeDataProvidersData({
59
+ providers,
60
+ doc,
61
+ timeout,
62
+ maxNodesToVisit = Infinity
63
+ }) {
64
+ const providersWithDefaults = providers.map(({
65
+ provider,
66
+ maxNodesToPrefetch = Infinity,
67
+ timeout: providerTimeout = Infinity
68
+ }) => ({
69
+ provider,
70
+ maxNodesToPrefetch,
71
+ // Use the minimum of the global timeout and the provider-specific timeout
72
+ timeout: Math.min(providerTimeout, timeout)
73
+ }));
74
+ const providerTimeouts = providersWithDefaults.reduce((acc, {
75
+ provider,
76
+ timeout
77
+ }) => {
78
+ acc[provider.name] = timeout;
79
+ return acc;
80
+ }, {});
81
+ const nodesWithProviders = findNodesToPrefetch(doc, providersWithDefaults, maxNodesToVisit).map(({
82
+ provider,
83
+ nodes
84
+ }) => ({
85
+ provider,
86
+ nodes,
87
+ timeout: providerTimeouts[provider.name]
88
+ }));
89
+ const promises = nodesWithProviders.map(async ({
90
+ nodes,
91
+ provider,
92
+ timeout
93
+ }) => {
94
+ try {
95
+ const timeoutPromise = new Promise(resolve => {
96
+ setTimeout(() => {
97
+ resolve([]);
98
+ }, timeout);
99
+ });
100
+ const data = await Promise.race([provider.fetchNodesData(nodes), timeoutPromise]);
101
+ return {
102
+ provider,
103
+ nodes,
104
+ data
105
+ };
106
+ } catch {
107
+ return {
108
+ provider,
109
+ nodes,
110
+ data: []
111
+ };
112
+ }
113
+ });
114
+ const results = await Promise.all(promises);
115
+ return results.reduce((acc, {
116
+ provider,
117
+ nodes,
118
+ data
119
+ }) => {
120
+ acc[provider.name] = data.reduce((providerSsrData, nodeData, nodeIndex) => {
121
+ const node = nodes[nodeIndex];
122
+ const nodeDataKey = provider.nodeDataKey(node);
123
+ providerSsrData[nodeDataKey] = nodeData;
124
+ return providerSsrData;
125
+ }, {});
126
+ return acc;
127
+ }, {});
128
+ }
package/dist/esm/index.js CHANGED
@@ -0,0 +1,4 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+
3
+ export { NodeDataProvider } from './node-data-provider';
4
+ export { prefetchNodeDataProvidersData } from './utils/prefetch-node-data-providers-data';
@@ -0,0 +1,248 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5
+ import _createClass from "@babel/runtime/helpers/createClass";
6
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
7
+ import { isSSR } from '@atlaskit/editor-common/core-utils';
8
+
9
+ /**
10
+ * Represents the SSR data for a single provider.
11
+ * It's a map where each key is a unique node data key and the value is the prefetched data for that node.
12
+ *
13
+ * @example
14
+ * {
15
+ * 'node-id-1': { value: 'some data' },
16
+ * 'node-id-2': { value: 'other data' }
17
+ * }
18
+ */
19
+
20
+ /**
21
+ * Represents the cached data for a Node Data Provider.
22
+ * Each key is a unique node data key, and the value is an object containing:
23
+ * - `source`: Indicates whether the data was fetched from SSR or the network.
24
+ * - `data`: The actual data, which can be either a resolved value or a Promise.
25
+ *
26
+ * @example
27
+ * {
28
+ * 'node-id-1': { source: 'ssr', data: { value: 'some data' } },
29
+ * 'node-id-2': { source: 'network', data: Promise.resolve({ value: 'other data' }) }
30
+ * }
31
+ */
32
+
33
+ /**
34
+ * A Node Data Provider is responsible for fetching and caching data associated with specific ProseMirror nodes.
35
+ * It supports a cache-first-then-network strategy, with initial data potentially provided via SSR.
36
+ *
37
+ * @template Node The specific type of JSONNode this provider supports.
38
+ * @template Data The type of data this provider fetches and manages.
39
+ */
40
+ export var NodeDataProvider = /*#__PURE__*/function () {
41
+ function NodeDataProvider() {
42
+ _classCallCheck(this, NodeDataProvider);
43
+ this.cacheVersion = 0;
44
+ this.cache = {};
45
+ }
46
+
47
+ /**
48
+ * Sets the SSR data for the provider.
49
+ * This pre-populates the cache with data rendered on the server, preventing redundant network requests on the client.
50
+ * Calling this method will invalidate the existing cache.
51
+ *
52
+ * @example
53
+ * ```
54
+ * const ssrData = window.__SSR_NODE_DATA__ || {};
55
+ * nodeDataProvider.setSSRData(ssrData);
56
+ * ```
57
+ *
58
+ * @param ssrData A map of node data keys to their corresponding data.
59
+ */
60
+ return _createClass(NodeDataProvider, [{
61
+ key: "setSSRData",
62
+ value: function setSSRData() {
63
+ var ssrData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
64
+ this.cacheVersion++;
65
+ this.cache = Object.entries(ssrData).reduce(function (acc, _ref) {
66
+ var _ref2 = _slicedToArray(_ref, 2),
67
+ key = _ref2[0],
68
+ data = _ref2[1];
69
+ acc[key] = {
70
+ source: 'ssr',
71
+ data: data
72
+ };
73
+ return acc;
74
+ }, {});
75
+ }
76
+
77
+ /**
78
+ * Clears all cached data.
79
+ * This increments the internal cache version, invalidating any pending network requests.
80
+ *
81
+ * @example
82
+ * ```
83
+ * function useMyNodeDataProvider(contentId: string) {
84
+ * const nodeDataProvider = new MyNodeDataProvider();
85
+ *
86
+ * // Reset the cache when the contentId changes (e.g., when the user navigates to a different page).
87
+ * useEffect(() => {
88
+ * nodeDataProvider.resetCache();
89
+ * }, [contentId]);
90
+ *
91
+ * return nodeDataProvider;
92
+ * }
93
+ * ```
94
+ */
95
+ }, {
96
+ key: "resetCache",
97
+ value: function resetCache() {
98
+ this.cacheVersion++;
99
+ this.cache = {};
100
+ }
101
+
102
+ /**
103
+ * Fetches data for a given node using a cache-first-then-network strategy.
104
+ *
105
+ * The provided callback may be called multiple times:
106
+ * 1. Immediately with data from the SSR cache, if available.
107
+ * 2. Asynchronously with data fetched from the network.
108
+ *
109
+ * @example
110
+ * ```
111
+ * const nodeDataProvider = new MyNodeDataProvider();
112
+ *
113
+ * nodeDataProvider.getData(node, (data) => {
114
+ * console.log('Node data:', data);
115
+ * });
116
+ * ```
117
+ *
118
+ * @param node The node (or its ProseMirror representation) for which to fetch data.
119
+ * @param callback The function to call when data is available.
120
+ */
121
+ }, {
122
+ key: "getData",
123
+ value: function getData(node, callback) {
124
+ // Move implementation to a separate async method
125
+ // to keep this method synchronous and avoid async/await in the public API.
126
+ void this.getDataAsync(node, callback);
127
+ }
128
+ }, {
129
+ key: "getDataAsync",
130
+ value: function () {
131
+ var _getDataAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(node, callback) {
132
+ var jsonNode, dataKey, dataFromCache, cacheVersionBeforeRequest, dataPromise, data;
133
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
134
+ while (1) switch (_context.prev = _context.next) {
135
+ case 0:
136
+ jsonNode = 'toJSON' in node ? node.toJSON() : node;
137
+ if (this.isNodeSupported(jsonNode)) {
138
+ _context.next = 4;
139
+ break;
140
+ }
141
+ // eslint-disable-next-line no-console
142
+ console.error("The ".concat(this.constructor.name, " doesn't support Node ").concat(jsonNode.type, "."));
143
+ return _context.abrupt("return");
144
+ case 4:
145
+ dataKey = this.nodeDataKey(jsonNode);
146
+ dataFromCache = this.cache[dataKey];
147
+ if (!(dataFromCache !== undefined)) {
148
+ _context.next = 18;
149
+ break;
150
+ }
151
+ if (!isPromise(dataFromCache.data)) {
152
+ _context.next = 15;
153
+ break;
154
+ }
155
+ _context.t0 = callback;
156
+ _context.next = 11;
157
+ return dataFromCache.data;
158
+ case 11:
159
+ _context.t1 = _context.sent;
160
+ (0, _context.t0)(_context.t1);
161
+ _context.next = 16;
162
+ break;
163
+ case 15:
164
+ callback(dataFromCache.data);
165
+ case 16:
166
+ if (!isSSR()) {
167
+ _context.next = 18;
168
+ break;
169
+ }
170
+ return _context.abrupt("return");
171
+ case 18:
172
+ if (!((dataFromCache === null || dataFromCache === void 0 ? void 0 : dataFromCache.source) !== 'network')) {
173
+ _context.next = 27;
174
+ break;
175
+ }
176
+ // Store the current cache version before making the request,
177
+ // so we can check if the cache has changed while we are waiting for the network response.
178
+ cacheVersionBeforeRequest = this.cacheVersion;
179
+ dataPromise = this.fetchNodesData([jsonNode]).then(function (_ref3) {
180
+ var _ref4 = _slicedToArray(_ref3, 1),
181
+ value = _ref4[0];
182
+ return value;
183
+ }); // Store the promise in the cache to avoid multiple requests for the same data
184
+ this.cache[dataKey] = {
185
+ source: 'network',
186
+ data: dataPromise
187
+ };
188
+ _context.next = 24;
189
+ return dataPromise;
190
+ case 24:
191
+ data = _context.sent;
192
+ // We need to call the callback with the data with result even if the cache version has changed,
193
+ // so all promises that are waiting for the data can resolve.
194
+ callback(data);
195
+
196
+ // If the cache version has changed, we don't want to use the data from the network
197
+ // because it could be stale data.
198
+ if (cacheVersionBeforeRequest === this.cacheVersion) {
199
+ // Replace promise with the resolved data in the cache
200
+ this.cache[dataKey] = {
201
+ source: 'network',
202
+ data: data
203
+ };
204
+ }
205
+ case 27:
206
+ case "end":
207
+ return _context.stop();
208
+ }
209
+ }, _callee, this);
210
+ }));
211
+ function getDataAsync(_x, _x2) {
212
+ return _getDataAsync.apply(this, arguments);
213
+ }
214
+ return getDataAsync;
215
+ }()
216
+ /**
217
+ * Fetches data for a given node and returns it as a Promise.
218
+ * This is a convenience wrapper around the `data` method for use with async/await.
219
+ *
220
+ * Note: This promise resolves with the *first* available data, which could be from the SSR cache or the network.
221
+ * It may not provide the most up-to-date data if a network fetch is in progress.
222
+ *
223
+ * Note: This method is only for migration purposes. Use {@link getData} in new code instead.
224
+ *
225
+ * @private
226
+ * @deprecated Don't use this method, use {@link getData} method instead.
227
+ * This method is only for migration purposes.
228
+ *
229
+ * @param node The node (or its ProseMirror representation) for which to fetch data.
230
+ * @returns A promise that resolves with the node's data.
231
+ */
232
+ }, {
233
+ key: "getDataAsPromise_DO_NOT_USE_OUTSIDE_MIGRATIONS",
234
+ value: function getDataAsPromise_DO_NOT_USE_OUTSIDE_MIGRATIONS(node) {
235
+ var _this = this;
236
+ return new Promise(function (resolve, reject) {
237
+ try {
238
+ return _this.getData(node, resolve);
239
+ } catch (error) {
240
+ reject(error);
241
+ }
242
+ });
243
+ }
244
+ }]);
245
+ }();
246
+ function isPromise(value) {
247
+ return _typeof(value) === 'object' && value !== null && 'then' in value && typeof value.then === 'function';
248
+ }