@atlaskit/node-data-provider 4.1.2 → 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.
- package/CHANGELOG.md +22 -0
- package/dist/cjs/index.js +13 -226
- package/dist/cjs/node-data-provider.js +252 -0
- package/dist/cjs/utils/find-nodes-to-prefetch.js +68 -0
- package/dist/cjs/utils/prefetch-node-data-providers-data.js +165 -0
- package/dist/es2019/index.js +3 -190
- package/dist/es2019/node-data-provider.js +216 -0
- package/dist/es2019/utils/find-nodes-to-prefetch.js +57 -0
- package/dist/es2019/utils/prefetch-node-data-providers-data.js +128 -0
- package/dist/esm/index.js +3 -226
- package/dist/esm/node-data-provider.js +248 -0
- package/dist/esm/utils/find-nodes-to-prefetch.js +61 -0
- package/dist/esm/utils/prefetch-node-data-providers-data.js +161 -0
- package/dist/types/index.d.ts +2 -134
- package/dist/types/node-data-provider.d.ts +125 -0
- package/dist/types/utils/find-nodes-to-prefetch.d.ts +21 -0
- package/dist/types/utils/prefetch-node-data-providers-data.d.ts +107 -0
- package/dist/types-ts4.5/index.d.ts +2 -134
- package/dist/types-ts4.5/node-data-provider.d.ts +125 -0
- package/dist/types-ts4.5/utils/find-nodes-to-prefetch.d.ts +21 -0
- package/dist/types-ts4.5/utils/prefetch-node-data-providers-data.d.ts +107 -0
- package/package.json +6 -13
- package/cache/package.json +0 -15
- package/content/package.json +0 -15
- package/dist/cjs/cache.js +0 -145
- package/dist/cjs/consumption/_global-ndp-caches.js +0 -21
- package/dist/cjs/consumption/_internal-context.js +0 -77
- package/dist/cjs/consumption/_lru-cache.js +0 -45
- package/dist/cjs/consumption/content.js +0 -56
- package/dist/cjs/get-providers/confluence-page.js +0 -15
- package/dist/cjs/internal-types.js +0 -5
- package/dist/cjs/plugin-hooks.js +0 -100
- package/dist/cjs/providers/emoji.js +0 -54
- package/dist/es2019/cache.js +0 -96
- package/dist/es2019/consumption/_global-ndp-caches.js +0 -13
- package/dist/es2019/consumption/_internal-context.js +0 -71
- package/dist/es2019/consumption/_lru-cache.js +0 -30
- package/dist/es2019/consumption/content.js +0 -49
- package/dist/es2019/get-providers/confluence-page.js +0 -10
- package/dist/es2019/internal-types.js +0 -1
- package/dist/es2019/plugin-hooks.js +0 -69
- package/dist/es2019/providers/emoji.js +0 -26
- package/dist/esm/cache.js +0 -141
- package/dist/esm/consumption/_global-ndp-caches.js +0 -13
- package/dist/esm/consumption/_internal-context.js +0 -71
- package/dist/esm/consumption/_lru-cache.js +0 -38
- package/dist/esm/consumption/content.js +0 -49
- package/dist/esm/get-providers/confluence-page.js +0 -9
- package/dist/esm/internal-types.js +0 -1
- package/dist/esm/plugin-hooks.js +0 -93
- package/dist/esm/providers/emoji.js +0 -47
- package/dist/types/cache.d.ts +0 -61
- package/dist/types/consumption/_global-ndp-caches.d.ts +0 -8
- package/dist/types/consumption/_internal-context.d.ts +0 -32
- package/dist/types/consumption/_lru-cache.d.ts +0 -7
- package/dist/types/consumption/content.d.ts +0 -65
- package/dist/types/get-providers/confluence-page.d.ts +0 -6
- package/dist/types/internal-types.d.ts +0 -2
- package/dist/types/plugin-hooks.d.ts +0 -32
- package/dist/types/providers/emoji.d.ts +0 -10
- package/dist/types-ts4.5/cache.d.ts +0 -61
- package/dist/types-ts4.5/consumption/_global-ndp-caches.d.ts +0 -8
- package/dist/types-ts4.5/consumption/_internal-context.d.ts +0 -32
- package/dist/types-ts4.5/consumption/_lru-cache.d.ts +0 -7
- package/dist/types-ts4.5/consumption/content.d.ts +0 -65
- package/dist/types-ts4.5/get-providers/confluence-page.d.ts +0 -6
- package/dist/types-ts4.5/internal-types.d.ts +0 -2
- package/dist/types-ts4.5/plugin-hooks.d.ts +0 -32
- package/dist/types-ts4.5/providers/emoji.d.ts +0 -10
- package/emoji-provider/package.json +0 -15
- package/get-confluence-page-providers/package.json +0 -15
- package/plugin-hooks/package.json +0 -15
package/dist/esm/cache.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
-
import { traverse } from '@atlaskit/adf-utils/traverse';
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Builds {@link NodeDataProvider}s caches for a document.
|
|
12
|
-
*
|
|
13
|
-
* It will traverse the document and call the resolve method for each node.
|
|
14
|
-
* When all promises are resolved, NodeDataProviders will have their caches populated.
|
|
15
|
-
*
|
|
16
|
-
* The providers will then be ready for use with an Editor.
|
|
17
|
-
*
|
|
18
|
-
* To limit the time spent building the cache, a signal can be provided to abort the request.
|
|
19
|
-
*
|
|
20
|
-
* ## Usage
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* buildCaches({
|
|
25
|
-
* adf: doc,
|
|
26
|
-
* nodeDataProviders: { emoji: emojiNodeDataProvider, ... },
|
|
27
|
-
* signal: AbortSignal.timeout(5000),
|
|
28
|
-
* });
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* ### Using caches
|
|
32
|
-
*
|
|
33
|
-
* To make use of a cache in another provider (ie. for a cache created on the server), you can retrieve the cache
|
|
34
|
-
* from the provider and pass it to the new provider.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```tsx
|
|
38
|
-
* // SSR env
|
|
39
|
-
* const ssrProvidersCaches = await buildCaches({adf, nodeDataProviders: { emoji }})
|
|
40
|
-
*
|
|
41
|
-
* // Client env (providersCaches is the cache from the server)
|
|
42
|
-
* <ContentNodeDataProviders ... existingProvidersCache={ssrProvidersCaches} />
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* *Note:* On the client - buildCache is not expected to be used directly.
|
|
46
|
-
*
|
|
47
|
-
* @see {@link ContentNodeDataProviders} for expected client usage.
|
|
48
|
-
*/
|
|
49
|
-
export function buildCaches(_x) {
|
|
50
|
-
return _buildCaches.apply(this, arguments);
|
|
51
|
-
}
|
|
52
|
-
function _buildCaches() {
|
|
53
|
-
_buildCaches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
54
|
-
var adf, nodeDataProviders, _ref$signal, signal, existingProvidersCache, visitors, promises, _loop, _i, _Object$values, caches, _i2, _Object$values2, nodeDataProvider;
|
|
55
|
-
return _regeneratorRuntime.wrap(function _callee$(_context2) {
|
|
56
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
57
|
-
case 0:
|
|
58
|
-
adf = _ref.adf, nodeDataProviders = _ref.nodeDataProviders, _ref$signal = _ref.signal, signal = _ref$signal === void 0 ? new AbortController().signal : _ref$signal, existingProvidersCache = _ref.existingProvidersCache;
|
|
59
|
-
visitors = {};
|
|
60
|
-
promises = [];
|
|
61
|
-
_loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
|
|
62
|
-
var _nodeDataProvider, nodeDataProvider;
|
|
63
|
-
return _regeneratorRuntime.wrap(function _loop$(_context) {
|
|
64
|
-
while (1) switch (_context.prev = _context.next) {
|
|
65
|
-
case 0:
|
|
66
|
-
_nodeDataProvider = _Object$values[_i];
|
|
67
|
-
// widen type to avoid typescript errors with the specific node data provider types
|
|
68
|
-
nodeDataProvider = _nodeDataProvider;
|
|
69
|
-
if (existingProvidersCache && existingProvidersCache[nodeDataProvider.nodeName]) {
|
|
70
|
-
nodeDataProvider.updateCache(existingProvidersCache[nodeDataProvider.nodeName], {
|
|
71
|
-
strategy: 'merge-override'
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
visitors[nodeDataProvider.nodeName] = function (node) {
|
|
75
|
-
var result = nodeDataProvider.get(node, {
|
|
76
|
-
signal: signal
|
|
77
|
-
});
|
|
78
|
-
if (!isPromise(result)) {
|
|
79
|
-
nodeDataProvider.cache[nodeDataProvider.nodeToKey(node)] = result;
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
promises.push(result);
|
|
83
|
-
result.then(function (resolvedValue) {
|
|
84
|
-
var signalAborted = signal ? signal.aborted : false;
|
|
85
|
-
if (!signalAborted && resolvedValue !== undefined) {
|
|
86
|
-
nodeDataProvider.cache[nodeDataProvider.nodeToKey(node)] = resolvedValue;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
return undefined;
|
|
90
|
-
};
|
|
91
|
-
case 4:
|
|
92
|
-
case "end":
|
|
93
|
-
return _context.stop();
|
|
94
|
-
}
|
|
95
|
-
}, _loop);
|
|
96
|
-
});
|
|
97
|
-
_i = 0, _Object$values = Object.values(nodeDataProviders);
|
|
98
|
-
case 5:
|
|
99
|
-
if (!(_i < _Object$values.length)) {
|
|
100
|
-
_context2.next = 10;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
return _context2.delegateYield(_loop(), "t0", 7);
|
|
104
|
-
case 7:
|
|
105
|
-
_i++;
|
|
106
|
-
_context2.next = 5;
|
|
107
|
-
break;
|
|
108
|
-
case 10:
|
|
109
|
-
if (!adf) {
|
|
110
|
-
_context2.next = 16;
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
traverse(adf, visitors);
|
|
114
|
-
_context2.next = 14;
|
|
115
|
-
return Promise.all(promises);
|
|
116
|
-
case 14:
|
|
117
|
-
_context2.next = 18;
|
|
118
|
-
break;
|
|
119
|
-
case 16:
|
|
120
|
-
_context2.next = 18;
|
|
121
|
-
return Promise.resolve();
|
|
122
|
-
case 18:
|
|
123
|
-
caches = {};
|
|
124
|
-
for (_i2 = 0, _Object$values2 = Object.values(nodeDataProviders); _i2 < _Object$values2.length; _i2++) {
|
|
125
|
-
nodeDataProvider = _Object$values2[_i2];
|
|
126
|
-
caches[nodeDataProvider.nodeName] = nodeDataProvider.cache;
|
|
127
|
-
}
|
|
128
|
-
return _context2.abrupt("return", caches);
|
|
129
|
-
case 21:
|
|
130
|
-
case "end":
|
|
131
|
-
return _context2.stop();
|
|
132
|
-
}
|
|
133
|
-
}, _callee);
|
|
134
|
-
}));
|
|
135
|
-
return _buildCaches.apply(this, arguments);
|
|
136
|
-
}
|
|
137
|
-
function isPromise(obj) {
|
|
138
|
-
return !!obj && (_typeof(obj) === 'object' || typeof obj === 'function') &&
|
|
139
|
-
// @ts-ignore
|
|
140
|
-
typeof obj.then === 'function';
|
|
141
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
var GlobalNdpCachesContext = /*#__PURE__*/React.createContext({});
|
|
3
|
-
export function useGlobalNdpCachesContext() {
|
|
4
|
-
var globalNdpCachesContextValue = React.useContext(GlobalNdpCachesContext);
|
|
5
|
-
return globalNdpCachesContextValue;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// The ndp caches currently use module scope to store the caches. This is not ideal, and a global provider
|
|
9
|
-
// will avoid the need for this.
|
|
10
|
-
// This function is used to reset the global ndp caches context in tests.
|
|
11
|
-
export function _resetGlobalNdpCachesContext() {
|
|
12
|
-
GlobalNdpCachesContext = /*#__PURE__*/React.createContext({});
|
|
13
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { buildCaches } from '../cache';
|
|
3
|
-
import { useGlobalNdpCachesContext } from './_global-ndp-caches';
|
|
4
|
-
import { LRUCache } from './_lru-cache';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The settings for the data providers lru cache,
|
|
8
|
-
* increasing the value will increase the number of data providers that can be stored in the cache.
|
|
9
|
-
*/
|
|
10
|
-
var lruCacheSettings = {
|
|
11
|
-
page: 5,
|
|
12
|
-
default: 1
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Sets up nodeview data providers for a content node.
|
|
17
|
-
*
|
|
18
|
-
* This will return the cached node data providers if they exist, otherwise it will call the provided getNodeDataProviders function.
|
|
19
|
-
*
|
|
20
|
-
* Note: Calling this has side effects where caches for the nodeview data providers will continue to be built
|
|
21
|
-
* in the background after this resolves to a set of nodeview data providers that can be used.
|
|
22
|
-
*/
|
|
23
|
-
export function useContentNodeDataProvidersSetup(content,
|
|
24
|
-
/**
|
|
25
|
-
* Note: changes to this object will not be reflected in the cache.
|
|
26
|
-
*/
|
|
27
|
-
setupOptions) {
|
|
28
|
-
var _globalNdpCachesContextValue = useGlobalNdpCachesContext();
|
|
29
|
-
// Create a cache for the content type if it doesn't exist
|
|
30
|
-
// While this will not result in any existing context consumers getting the updated value.
|
|
31
|
-
// It will ensure that the cache is available for future consumers.
|
|
32
|
-
if (_globalNdpCachesContextValue[content.contentType] === undefined) {
|
|
33
|
-
var _lruCacheSettings$con;
|
|
34
|
-
_globalNdpCachesContextValue[content.contentType] = new LRUCache((_lruCacheSettings$con = lruCacheSettings[content.contentType]) !== null && _lruCacheSettings$con !== void 0 ? _lruCacheSettings$con : lruCacheSettings.default);
|
|
35
|
-
}
|
|
36
|
-
var contentTypeNdpCaches = _globalNdpCachesContextValue[content.contentType];
|
|
37
|
-
|
|
38
|
-
// The node data providers should only be rebuilt if the content changes
|
|
39
|
-
// to avoid unnecessary rebuilding of the cache.
|
|
40
|
-
// useRef is used over useMemo as use memo is not a guarantee that the value will be reused
|
|
41
|
-
// - in development it can be called twice
|
|
42
|
-
// - react have made clear that in future versions useMemo may add features that throw away the cache, and [recommend refs](https://react.dev/reference/react/useMemo#caveats) for this use case.
|
|
43
|
-
var currentContentKey = "".concat(content.contentType, "-").concat(content.contentId);
|
|
44
|
-
var contentKeyRef = React.useRef();
|
|
45
|
-
var nodeDataProvidersRef = React.useRef();
|
|
46
|
-
if (contentKeyRef.current !== currentContentKey) {
|
|
47
|
-
contentKeyRef.current = currentContentKey;
|
|
48
|
-
var cachedContentNdps = contentTypeNdpCaches === null || contentTypeNdpCaches === void 0 ? void 0 : contentTypeNdpCaches.get(content.contentId);
|
|
49
|
-
var nodeDataProviders = cachedContentNdps || setupOptions.getNodeDataProviders();
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Note: while this will remove old NodeDataProviders from the cache -- these are passed directly to consumers,
|
|
53
|
-
* so removing from the cache will not result in actively used NodeDataProviders being deleted in some way.
|
|
54
|
-
*
|
|
55
|
-
*/
|
|
56
|
-
contentTypeNdpCaches.set(content.contentId, nodeDataProviders);
|
|
57
|
-
buildCaches({
|
|
58
|
-
adf: setupOptions.adfToUpdateWith,
|
|
59
|
-
nodeDataProviders: nodeDataProviders,
|
|
60
|
-
existingProvidersCache: setupOptions.existingProvidersCache
|
|
61
|
-
}).then(function (warmedNodeDataProvidersCache) {
|
|
62
|
-
var _setupOptions$onCache;
|
|
63
|
-
(_setupOptions$onCache = setupOptions.onCacheWarmed) === null || _setupOptions$onCache === void 0 || _setupOptions$onCache.call(setupOptions, {
|
|
64
|
-
warmedNodeDataProvidersCache: warmedNodeDataProvidersCache,
|
|
65
|
-
nodeDataProviders: nodeDataProviders
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
nodeDataProvidersRef.current = nodeDataProviders;
|
|
69
|
-
}
|
|
70
|
-
return nodeDataProvidersRef.current;
|
|
71
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
export var LRUCache = /*#__PURE__*/function () {
|
|
4
|
-
function LRUCache(capacity) {
|
|
5
|
-
_classCallCheck(this, LRUCache);
|
|
6
|
-
this.capacity = capacity;
|
|
7
|
-
this.cache = new Map();
|
|
8
|
-
}
|
|
9
|
-
return _createClass(LRUCache, [{
|
|
10
|
-
key: "get",
|
|
11
|
-
value: function get(key) {
|
|
12
|
-
if (!this.cache.has(key)) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Move the used key to the end to mark it as most recently used
|
|
17
|
-
// Ignored via go/ees005
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
19
|
-
var value = this.cache.get(key);
|
|
20
|
-
this.cache.delete(key);
|
|
21
|
-
this.cache.set(key, value);
|
|
22
|
-
return value;
|
|
23
|
-
}
|
|
24
|
-
}, {
|
|
25
|
-
key: "set",
|
|
26
|
-
value: function set(key, value) {
|
|
27
|
-
// Check if the key already exists and delete it to update its position
|
|
28
|
-
if (this.cache.has(key)) {
|
|
29
|
-
this.cache.delete(key);
|
|
30
|
-
} else if (this.cache.size >= this.capacity) {
|
|
31
|
-
// Remove the first (least recently used) cache item if we're at capacity
|
|
32
|
-
var firstKey = this.cache.keys().next().value;
|
|
33
|
-
this.cache.delete(firstKey);
|
|
34
|
-
}
|
|
35
|
-
this.cache.set(key, value);
|
|
36
|
-
}
|
|
37
|
-
}]);
|
|
38
|
-
}();
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @atlaskit/editor/no-re-export */
|
|
2
|
-
// Entry file
|
|
3
|
-
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import { _resetGlobalNdpCachesContext } from './_global-ndp-caches';
|
|
6
|
-
import { useContentNodeDataProvidersSetup } from './_internal-context';
|
|
7
|
-
var ContentNodeDataProvidersContext = /*#__PURE__*/React.createContext(undefined);
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```tsx
|
|
13
|
-
* <ContentNodeDataProviders
|
|
14
|
-
* contentType="page" contentId="9001"
|
|
15
|
-
* adf={doc}
|
|
16
|
-
* placeholder={<Spinner />}
|
|
17
|
-
* existingProvidersCache={ssrProvidersCache}
|
|
18
|
-
* getNodeDataProviders={getPageNodeDataProviders}
|
|
19
|
-
* onCacheWarmed={trackCacheWarmed}
|
|
20
|
-
* >
|
|
21
|
-
* <Editor />
|
|
22
|
-
* </ContentNodeDataProviders>
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export function ContentNodeDataProviders(props) {
|
|
26
|
-
var contentNodeDataProviders = useContentNodeDataProvidersSetup({
|
|
27
|
-
contentType: props.contentType,
|
|
28
|
-
contentId: props.contentId
|
|
29
|
-
}, {
|
|
30
|
-
adfToUpdateWith: props.adf,
|
|
31
|
-
existingProvidersCache: props.existingProvidersCache,
|
|
32
|
-
getNodeDataProviders: props.getNodeDataProviders,
|
|
33
|
-
onCacheWarmed: props.onCacheWarmed
|
|
34
|
-
});
|
|
35
|
-
return /*#__PURE__*/React.createElement(ContentNodeDataProvidersContext.Provider, {
|
|
36
|
-
value: contentNodeDataProviders
|
|
37
|
-
}, props.children);
|
|
38
|
-
}
|
|
39
|
-
export function useContentNodeDataProviders() {
|
|
40
|
-
var contentNodeDataProvidersContext = React.useContext(ContentNodeDataProvidersContext);
|
|
41
|
-
return contentNodeDataProvidersContext;
|
|
42
|
-
}
|
|
43
|
-
export {
|
|
44
|
-
/**
|
|
45
|
-
* Exported for testing purposes only.
|
|
46
|
-
*
|
|
47
|
-
* This API will change.
|
|
48
|
-
*/
|
|
49
|
-
_resetGlobalNdpCachesContext as __testOnly_resetGlobalNdpCachesContext };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/plugin-hooks.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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 _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* This hook is intended to simplify accessing data via the one tick providers.
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* const value = useNodeDataProviderGet(emojiProvider, emojiNode);
|
|
13
|
-
*
|
|
14
|
-
* if (value.state === 'loading') {
|
|
15
|
-
* return <Loading />;
|
|
16
|
-
* }
|
|
17
|
-
* if (value.state === 'failed') {
|
|
18
|
-
* return <Fallback />;
|
|
19
|
-
* }
|
|
20
|
-
* return <Emoji properties=(value.result) />
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function useNodeDataProviderGet(options) {
|
|
24
|
-
var getResult = useMemo(
|
|
25
|
-
// Ignored via go/ees005
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
27
|
-
function () {
|
|
28
|
-
return options.provider.get(options.node);
|
|
29
|
-
}, [options.provider, options.node]);
|
|
30
|
-
var _useState = useState(getResult !== undefined && !isPromise(getResult) ? getResult : undefined),
|
|
31
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
32
|
-
resolved = _useState2[0],
|
|
33
|
-
setResolved = _useState2[1];
|
|
34
|
-
useEffect(function () {
|
|
35
|
-
if (!isPromise(getResult)) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
var cancelled = false;
|
|
39
|
-
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
40
|
-
var _resolved;
|
|
41
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
42
|
-
while (1) switch (_context.prev = _context.next) {
|
|
43
|
-
case 0:
|
|
44
|
-
_context.prev = 0;
|
|
45
|
-
_context.next = 3;
|
|
46
|
-
return getResult;
|
|
47
|
-
case 3:
|
|
48
|
-
_resolved = _context.sent;
|
|
49
|
-
if (!cancelled) {
|
|
50
|
-
if (_resolved === undefined) {
|
|
51
|
-
setResolved('error');
|
|
52
|
-
} else {
|
|
53
|
-
setResolved(_resolved);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
_context.next = 10;
|
|
57
|
-
break;
|
|
58
|
-
case 7:
|
|
59
|
-
_context.prev = 7;
|
|
60
|
-
_context.t0 = _context["catch"](0);
|
|
61
|
-
setResolved('error');
|
|
62
|
-
case 10:
|
|
63
|
-
case "end":
|
|
64
|
-
return _context.stop();
|
|
65
|
-
}
|
|
66
|
-
}, _callee, null, [[0, 7]]);
|
|
67
|
-
}))();
|
|
68
|
-
return function () {
|
|
69
|
-
cancelled = true;
|
|
70
|
-
};
|
|
71
|
-
}, [getResult]);
|
|
72
|
-
if (resolved === undefined) {
|
|
73
|
-
return {
|
|
74
|
-
state: 'loading',
|
|
75
|
-
result: undefined
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
if (resolved === 'error') {
|
|
79
|
-
return {
|
|
80
|
-
state: 'failed',
|
|
81
|
-
result: undefined
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
state: 'resolved',
|
|
86
|
-
result: resolved
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function isPromise(obj) {
|
|
90
|
-
return !!obj && (_typeof(obj) === 'object' || typeof obj === 'function') &&
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
typeof obj.then === 'function';
|
|
93
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
-
import { NodeDataProvider } from '../index';
|
|
4
|
-
export function createEmojiNodeDataProvider(_ref) {
|
|
5
|
-
var emojiProvider = _ref.emojiProvider,
|
|
6
|
-
existingCache = _ref.existingCache;
|
|
7
|
-
var emojiNodeDataProvider = new NodeDataProvider({
|
|
8
|
-
existingCache: existingCache,
|
|
9
|
-
nodeName: 'emoji',
|
|
10
|
-
nodeToKey: function nodeToKey(node) {
|
|
11
|
-
var key = "".concat(node.attrs.id, "-").concat(node.attrs.shortName, "-").concat(node.attrs.text);
|
|
12
|
-
return key;
|
|
13
|
-
},
|
|
14
|
-
resolve: function resolve(node, _resolveOptions) {
|
|
15
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
16
|
-
var emojiDescriptionWithVariations;
|
|
17
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
18
|
-
while (1) switch (_context.prev = _context.next) {
|
|
19
|
-
case 0:
|
|
20
|
-
_context.next = 2;
|
|
21
|
-
return emojiProvider;
|
|
22
|
-
case 2:
|
|
23
|
-
_context.next = 4;
|
|
24
|
-
return _context.sent.fetchByEmojiId({
|
|
25
|
-
id: node.attrs.id,
|
|
26
|
-
shortName: node.attrs.shortName,
|
|
27
|
-
fallback: node.attrs.text
|
|
28
|
-
}, true);
|
|
29
|
-
case 4:
|
|
30
|
-
emojiDescriptionWithVariations = _context.sent;
|
|
31
|
-
if (emojiDescriptionWithVariations) {
|
|
32
|
-
_context.next = 7;
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
throw new Error('Could not resolve emoji');
|
|
36
|
-
case 7:
|
|
37
|
-
return _context.abrupt("return", emojiDescriptionWithVariations);
|
|
38
|
-
case 8:
|
|
39
|
-
case "end":
|
|
40
|
-
return _context.stop();
|
|
41
|
-
}
|
|
42
|
-
}, _callee);
|
|
43
|
-
}))();
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
return emojiNodeDataProvider;
|
|
47
|
-
}
|
package/dist/types/cache.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { DocNode } from '@atlaskit/adf-schema';
|
|
2
|
-
import { type AnyNodeDataProvider } from './internal-types';
|
|
3
|
-
import { type EmojiNodeDataProvider } from './providers/emoji';
|
|
4
|
-
export type NodeDataProvidersCache = {
|
|
5
|
-
[nodeName: string]: Record<string, any>;
|
|
6
|
-
};
|
|
7
|
-
export type NodeDataProviders = {
|
|
8
|
-
emoji: EmojiNodeDataProvider;
|
|
9
|
-
[nodeName: string]: AnyNodeDataProvider;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Builds {@link NodeDataProvider}s caches for a document.
|
|
13
|
-
*
|
|
14
|
-
* It will traverse the document and call the resolve method for each node.
|
|
15
|
-
* When all promises are resolved, NodeDataProviders will have their caches populated.
|
|
16
|
-
*
|
|
17
|
-
* The providers will then be ready for use with an Editor.
|
|
18
|
-
*
|
|
19
|
-
* To limit the time spent building the cache, a signal can be provided to abort the request.
|
|
20
|
-
*
|
|
21
|
-
* ## Usage
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* buildCaches({
|
|
26
|
-
* adf: doc,
|
|
27
|
-
* nodeDataProviders: { emoji: emojiNodeDataProvider, ... },
|
|
28
|
-
* signal: AbortSignal.timeout(5000),
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* ### Using caches
|
|
33
|
-
*
|
|
34
|
-
* To make use of a cache in another provider (ie. for a cache created on the server), you can retrieve the cache
|
|
35
|
-
* from the provider and pass it to the new provider.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```tsx
|
|
39
|
-
* // SSR env
|
|
40
|
-
* const ssrProvidersCaches = await buildCaches({adf, nodeDataProviders: { emoji }})
|
|
41
|
-
*
|
|
42
|
-
* // Client env (providersCaches is the cache from the server)
|
|
43
|
-
* <ContentNodeDataProviders ... existingProvidersCache={ssrProvidersCaches} />
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* *Note:* On the client - buildCache is not expected to be used directly.
|
|
47
|
-
*
|
|
48
|
-
* @see {@link ContentNodeDataProviders} for expected client usage.
|
|
49
|
-
*/
|
|
50
|
-
export declare function buildCaches({ adf, nodeDataProviders, signal, existingProvidersCache, }: {
|
|
51
|
-
adf?: DocNode;
|
|
52
|
-
/**
|
|
53
|
-
* Providers to build caches for
|
|
54
|
-
*/
|
|
55
|
-
nodeDataProviders: NodeDataProviders;
|
|
56
|
-
/**
|
|
57
|
-
* Signal to abort cache building -- the caches will be built up to the point of abort.
|
|
58
|
-
*/
|
|
59
|
-
signal?: AbortSignal;
|
|
60
|
-
existingProvidersCache?: NodeDataProvidersCache;
|
|
61
|
-
}): Promise<NodeDataProvidersCache>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type NodeDataProviders } from '../cache';
|
|
2
|
-
import { type LRUCache } from './_lru-cache';
|
|
3
|
-
type GlobalNdpCachesContextValue = {
|
|
4
|
-
[contentType: string]: LRUCache<NodeDataProviders>;
|
|
5
|
-
};
|
|
6
|
-
export declare function useGlobalNdpCachesContext(): GlobalNdpCachesContextValue;
|
|
7
|
-
export declare function _resetGlobalNdpCachesContext(): void;
|
|
8
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { type DocNode } from '@atlaskit/adf-schema';
|
|
2
|
-
import { type NodeDataProviders, type NodeDataProvidersCache } from '../cache';
|
|
3
|
-
/**
|
|
4
|
-
* Sets up nodeview data providers for a content node.
|
|
5
|
-
*
|
|
6
|
-
* This will return the cached node data providers if they exist, otherwise it will call the provided getNodeDataProviders function.
|
|
7
|
-
*
|
|
8
|
-
* Note: Calling this has side effects where caches for the nodeview data providers will continue to be built
|
|
9
|
-
* in the background after this resolves to a set of nodeview data providers that can be used.
|
|
10
|
-
*/
|
|
11
|
-
export declare function useContentNodeDataProvidersSetup(content: {
|
|
12
|
-
/**
|
|
13
|
-
* The type of content.
|
|
14
|
-
*/
|
|
15
|
-
contentType: 'page';
|
|
16
|
-
contentId: string;
|
|
17
|
-
},
|
|
18
|
-
/**
|
|
19
|
-
* Note: changes to this object will not be reflected in the cache.
|
|
20
|
-
*/
|
|
21
|
-
setupOptions: {
|
|
22
|
-
/**
|
|
23
|
-
* Note: this will only be used if no existing NodeDataProviders are found for the content.
|
|
24
|
-
*/
|
|
25
|
-
adfToUpdateWith?: DocNode;
|
|
26
|
-
existingProvidersCache?: NodeDataProvidersCache;
|
|
27
|
-
getNodeDataProviders: () => NodeDataProviders;
|
|
28
|
-
onCacheWarmed?: (_: {
|
|
29
|
-
warmedNodeDataProvidersCache: NodeDataProvidersCache;
|
|
30
|
-
nodeDataProviders: NodeDataProviders;
|
|
31
|
-
}) => void;
|
|
32
|
-
}): NodeDataProviders | undefined;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { type DocNode } from '@atlaskit/adf-schema';
|
|
3
|
-
import { type NodeDataProviders, type NodeDataProvidersCache } from '../cache';
|
|
4
|
-
import { _resetGlobalNdpCachesContext } from './_global-ndp-caches';
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```tsx
|
|
9
|
-
* <ContentNodeDataProviders
|
|
10
|
-
* contentType="page" contentId="9001"
|
|
11
|
-
* adf={doc}
|
|
12
|
-
* placeholder={<Spinner />}
|
|
13
|
-
* existingProvidersCache={ssrProvidersCache}
|
|
14
|
-
* getNodeDataProviders={getPageNodeDataProviders}
|
|
15
|
-
* onCacheWarmed={trackCacheWarmed}
|
|
16
|
-
* >
|
|
17
|
-
* <Editor />
|
|
18
|
-
* </ContentNodeDataProviders>
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare function ContentNodeDataProviders(props: {
|
|
22
|
-
/**
|
|
23
|
-
* The type of content, this is used to group the resulting providers cache
|
|
24
|
-
*
|
|
25
|
-
* Note: Providers Caches are stored in an internal LRU cache, are grouped by content type.
|
|
26
|
-
*/
|
|
27
|
-
contentType: 'page';
|
|
28
|
-
/**
|
|
29
|
-
* The type of content, this is used to group the resulting providers cache
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
contentId: string;
|
|
33
|
-
/**
|
|
34
|
-
* This is optional - when passed the caches in the data providers will be warmed
|
|
35
|
-
* based on this document.
|
|
36
|
-
*/
|
|
37
|
-
adf?: DocNode;
|
|
38
|
-
/**
|
|
39
|
-
* This is optional, and supports passing in an existing providers cache.
|
|
40
|
-
*
|
|
41
|
-
* An example of this is when you have a server-side rendered providers cache that you want to use on the client.
|
|
42
|
-
*/
|
|
43
|
-
existingProvidersCache?: NodeDataProvidersCache;
|
|
44
|
-
/**
|
|
45
|
-
* Returns a set of `NodeDataProviders` which are put in context for use when creating an editor or renderer.
|
|
46
|
-
* These will be pre-warmed if adf is passed in.
|
|
47
|
-
*/
|
|
48
|
-
getNodeDataProviders: () => NodeDataProviders;
|
|
49
|
-
/**
|
|
50
|
-
* Called when the cache is warmed.
|
|
51
|
-
*/
|
|
52
|
-
onCacheWarmed?: (_: {
|
|
53
|
-
warmedNodeDataProvidersCache: NodeDataProvidersCache;
|
|
54
|
-
nodeDataProviders: NodeDataProviders;
|
|
55
|
-
}) => void;
|
|
56
|
-
children: React.ReactNode;
|
|
57
|
-
}): React.JSX.Element;
|
|
58
|
-
export declare function useContentNodeDataProviders(): NodeDataProviders | undefined;
|
|
59
|
-
export {
|
|
60
|
-
/**
|
|
61
|
-
* Exported for testing purposes only.
|
|
62
|
-
*
|
|
63
|
-
* This API will change.
|
|
64
|
-
*/
|
|
65
|
-
_resetGlobalNdpCachesContext as __testOnly_resetGlobalNdpCachesContext, };
|