@atlaskit/node-data-provider 4.1.2 → 4.2.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 +9 -0
- package/dist/cjs/index.js +1 -232
- package/dist/es2019/index.js +0 -191
- package/dist/esm/index.js +0 -227
- package/dist/types/index.d.ts +0 -134
- package/dist/types-ts4.5/index.d.ts +0 -134
- package/package.json +2 -10
- 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/types/index.d.ts
CHANGED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is the base class for creating a node data provider for an editor plugin.
|
|
3
|
-
*
|
|
4
|
-
* ## Usage
|
|
5
|
-
*
|
|
6
|
-
* ### Create a provider
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* class EmojiNodeDataProvider extends NodeDataProvider<
|
|
11
|
-
* { attrs: EmojiAttributes },
|
|
12
|
-
* { resolvedData: string }
|
|
13
|
-
* > {
|
|
14
|
-
* constructor({ existingCache }?: { existingCache: Record<string, { resolvedData: string }> }) {
|
|
15
|
-
* super({ existingCache, nodeName: 'emoji' });
|
|
16
|
-
* }
|
|
17
|
-
* nodeToKey(node: { attrs: EmojiAttributes }): string {
|
|
18
|
-
* return `${node.attrs.shortName}-${node.attrs.text}-${node.attrs.id}`;
|
|
19
|
-
* }
|
|
20
|
-
* resolve(node: { attrs: EmojiAttributes }, _?: { signal: AbortSignal }) {
|
|
21
|
-
* return Promise.resolve({ resolvedData: 'resolved' });
|
|
22
|
-
* }
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* ### Use the provider
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const emojiNodeDataProvider = new EmojiNodeDataProvider();
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* ### Caching
|
|
34
|
-
*
|
|
35
|
-
* @see {@link buildCaches} for more information on building caches.
|
|
36
|
-
*
|
|
37
|
-
* #### Load an existing provider with a cache
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```
|
|
41
|
-
* await buildCaches({
|
|
42
|
-
* adf: docFromSomewhere,
|
|
43
|
-
* nodeDataProviders: [emojiNodeDataProvider],
|
|
44
|
-
* signal: AbortSignal.timeout(5000),
|
|
45
|
-
* });
|
|
46
|
-
* emojiNodeDataProvider // { 'key': 'value' }
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* ### Load an new provider with an existing cache
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```
|
|
53
|
-
* const provider1 = new ExampleNodeDataProvider();
|
|
54
|
-
* await buildCaches({adf, nodeDataProviders: [provider1]})
|
|
55
|
-
* provider1.cache // { 'key': 'value' }
|
|
56
|
-
*
|
|
57
|
-
* const provider2 = new ExampleNodeDataProvider({existingCache: provider1.cache});
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export declare class NodeDataProvider<INode extends ReceivableNode, Result extends unknown> {
|
|
61
|
-
/**
|
|
62
|
-
* This is added to ease building types
|
|
63
|
-
*/
|
|
64
|
-
__node: INode;
|
|
65
|
-
private __cache;
|
|
66
|
-
/**
|
|
67
|
-
* This takes a node and returns a key that can be used to cache the result of the resolve function.
|
|
68
|
-
*/
|
|
69
|
-
nodeToKey: (node: INode) => string;
|
|
70
|
-
/**
|
|
71
|
-
* This returns the information required to render a node.
|
|
72
|
-
*
|
|
73
|
-
* If unresolvable, this method will throw an error.
|
|
74
|
-
*
|
|
75
|
-
* If signal is aborted, this method will return undefined.
|
|
76
|
-
*/
|
|
77
|
-
resolve: (node: INode, _?: {
|
|
78
|
-
signal?: AbortSignal;
|
|
79
|
-
}) => Promise<Result | undefined>;
|
|
80
|
-
/**
|
|
81
|
-
* The adf node name this provider is responsible for.
|
|
82
|
-
*/
|
|
83
|
-
nodeName: string;
|
|
84
|
-
constructor({ existingCache, nodeName, nodeToKey, resolve, }: {
|
|
85
|
-
/**
|
|
86
|
-
* A cache to load the provider with.
|
|
87
|
-
*
|
|
88
|
-
* @see {@link buildCaches} for more information on building caches.
|
|
89
|
-
*/
|
|
90
|
-
existingCache?: Record<string, Result>;
|
|
91
|
-
/**
|
|
92
|
-
* The adf node name this provider is responsible for.
|
|
93
|
-
*
|
|
94
|
-
* It is used for;
|
|
95
|
-
* - determining if the traverser should use this provider to resolve a node when building caches
|
|
96
|
-
* - identifying the node when submitting analytics events via the helper react hooks
|
|
97
|
-
*/
|
|
98
|
-
nodeName: string;
|
|
99
|
-
nodeToKey: typeof NodeDataProvider.prototype.nodeToKey;
|
|
100
|
-
resolve: typeof NodeDataProvider.prototype.resolve;
|
|
101
|
-
});
|
|
102
|
-
/**
|
|
103
|
-
* Updates the providers cache.
|
|
104
|
-
*
|
|
105
|
-
* Useful in scenarios such as SSR where the cache is built on the server and then passed to the client.
|
|
106
|
-
*
|
|
107
|
-
* Avoids the need to provide the cache to the constructor (to allow decoupling creation of node data providers from cache building),
|
|
108
|
-
* and allow for caching to be managed at a group level across multiple providers.
|
|
109
|
-
*
|
|
110
|
-
* This is not expected to be used by consumers, for internal consumption examples;
|
|
111
|
-
* @see {@link buildCaches}
|
|
112
|
-
*
|
|
113
|
-
*/
|
|
114
|
-
updateCache(cache: Record<string, Result>, options: {
|
|
115
|
-
strategy: 'merge-override' | 'replace';
|
|
116
|
-
}): void;
|
|
117
|
-
/**
|
|
118
|
-
* This is the cache for the provider.
|
|
119
|
-
*/
|
|
120
|
-
get cache(): Record<string, Result>;
|
|
121
|
-
private pending;
|
|
122
|
-
get(node: INode, _?: {
|
|
123
|
-
signal: AbortSignal;
|
|
124
|
-
}): Promise<Result | undefined> | Result;
|
|
125
|
-
}
|
|
126
|
-
export type ReceivableNode = {
|
|
127
|
-
[key: string]: any;
|
|
128
|
-
attrs: {
|
|
129
|
-
[key: string]: any;
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
export type ResolveOptions = {
|
|
133
|
-
signal: AbortSignal;
|
|
134
|
-
};
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is the base class for creating a node data provider for an editor plugin.
|
|
3
|
-
*
|
|
4
|
-
* ## Usage
|
|
5
|
-
*
|
|
6
|
-
* ### Create a provider
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* class EmojiNodeDataProvider extends NodeDataProvider<
|
|
11
|
-
* { attrs: EmojiAttributes },
|
|
12
|
-
* { resolvedData: string }
|
|
13
|
-
* > {
|
|
14
|
-
* constructor({ existingCache }?: { existingCache: Record<string, { resolvedData: string }> }) {
|
|
15
|
-
* super({ existingCache, nodeName: 'emoji' });
|
|
16
|
-
* }
|
|
17
|
-
* nodeToKey(node: { attrs: EmojiAttributes }): string {
|
|
18
|
-
* return `${node.attrs.shortName}-${node.attrs.text}-${node.attrs.id}`;
|
|
19
|
-
* }
|
|
20
|
-
* resolve(node: { attrs: EmojiAttributes }, _?: { signal: AbortSignal }) {
|
|
21
|
-
* return Promise.resolve({ resolvedData: 'resolved' });
|
|
22
|
-
* }
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* ### Use the provider
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const emojiNodeDataProvider = new EmojiNodeDataProvider();
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* ### Caching
|
|
34
|
-
*
|
|
35
|
-
* @see {@link buildCaches} for more information on building caches.
|
|
36
|
-
*
|
|
37
|
-
* #### Load an existing provider with a cache
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```
|
|
41
|
-
* await buildCaches({
|
|
42
|
-
* adf: docFromSomewhere,
|
|
43
|
-
* nodeDataProviders: [emojiNodeDataProvider],
|
|
44
|
-
* signal: AbortSignal.timeout(5000),
|
|
45
|
-
* });
|
|
46
|
-
* emojiNodeDataProvider // { 'key': 'value' }
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* ### Load an new provider with an existing cache
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```
|
|
53
|
-
* const provider1 = new ExampleNodeDataProvider();
|
|
54
|
-
* await buildCaches({adf, nodeDataProviders: [provider1]})
|
|
55
|
-
* provider1.cache // { 'key': 'value' }
|
|
56
|
-
*
|
|
57
|
-
* const provider2 = new ExampleNodeDataProvider({existingCache: provider1.cache});
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export declare class NodeDataProvider<INode extends ReceivableNode, Result extends unknown> {
|
|
61
|
-
/**
|
|
62
|
-
* This is added to ease building types
|
|
63
|
-
*/
|
|
64
|
-
__node: INode;
|
|
65
|
-
private __cache;
|
|
66
|
-
/**
|
|
67
|
-
* This takes a node and returns a key that can be used to cache the result of the resolve function.
|
|
68
|
-
*/
|
|
69
|
-
nodeToKey: (node: INode) => string;
|
|
70
|
-
/**
|
|
71
|
-
* This returns the information required to render a node.
|
|
72
|
-
*
|
|
73
|
-
* If unresolvable, this method will throw an error.
|
|
74
|
-
*
|
|
75
|
-
* If signal is aborted, this method will return undefined.
|
|
76
|
-
*/
|
|
77
|
-
resolve: (node: INode, _?: {
|
|
78
|
-
signal?: AbortSignal;
|
|
79
|
-
}) => Promise<Result | undefined>;
|
|
80
|
-
/**
|
|
81
|
-
* The adf node name this provider is responsible for.
|
|
82
|
-
*/
|
|
83
|
-
nodeName: string;
|
|
84
|
-
constructor({ existingCache, nodeName, nodeToKey, resolve, }: {
|
|
85
|
-
/**
|
|
86
|
-
* A cache to load the provider with.
|
|
87
|
-
*
|
|
88
|
-
* @see {@link buildCaches} for more information on building caches.
|
|
89
|
-
*/
|
|
90
|
-
existingCache?: Record<string, Result>;
|
|
91
|
-
/**
|
|
92
|
-
* The adf node name this provider is responsible for.
|
|
93
|
-
*
|
|
94
|
-
* It is used for;
|
|
95
|
-
* - determining if the traverser should use this provider to resolve a node when building caches
|
|
96
|
-
* - identifying the node when submitting analytics events via the helper react hooks
|
|
97
|
-
*/
|
|
98
|
-
nodeName: string;
|
|
99
|
-
nodeToKey: typeof NodeDataProvider.prototype.nodeToKey;
|
|
100
|
-
resolve: typeof NodeDataProvider.prototype.resolve;
|
|
101
|
-
});
|
|
102
|
-
/**
|
|
103
|
-
* Updates the providers cache.
|
|
104
|
-
*
|
|
105
|
-
* Useful in scenarios such as SSR where the cache is built on the server and then passed to the client.
|
|
106
|
-
*
|
|
107
|
-
* Avoids the need to provide the cache to the constructor (to allow decoupling creation of node data providers from cache building),
|
|
108
|
-
* and allow for caching to be managed at a group level across multiple providers.
|
|
109
|
-
*
|
|
110
|
-
* This is not expected to be used by consumers, for internal consumption examples;
|
|
111
|
-
* @see {@link buildCaches}
|
|
112
|
-
*
|
|
113
|
-
*/
|
|
114
|
-
updateCache(cache: Record<string, Result>, options: {
|
|
115
|
-
strategy: 'merge-override' | 'replace';
|
|
116
|
-
}): void;
|
|
117
|
-
/**
|
|
118
|
-
* This is the cache for the provider.
|
|
119
|
-
*/
|
|
120
|
-
get cache(): Record<string, Result>;
|
|
121
|
-
private pending;
|
|
122
|
-
get(node: INode, _?: {
|
|
123
|
-
signal: AbortSignal;
|
|
124
|
-
}): Promise<Result | undefined> | Result;
|
|
125
|
-
}
|
|
126
|
-
export type ReceivableNode = {
|
|
127
|
-
[key: string]: any;
|
|
128
|
-
attrs: {
|
|
129
|
-
[key: string]: any;
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
export type ResolveOptions = {
|
|
133
|
-
signal: AbortSignal;
|
|
134
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/node-data-provider",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Node data provider for @atlaskit/editor-core plugins and @atlaskit/renderer",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -19,17 +19,11 @@
|
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"atlaskit:src": "src/index.ts",
|
|
21
21
|
"af:exports": {
|
|
22
|
-
".": "./src/index.ts"
|
|
23
|
-
"./plugin-hooks": "./src/plugin-hooks.ts",
|
|
24
|
-
"./content": "./src/consumption/content.tsx",
|
|
25
|
-
"./cache": "./src/cache.ts",
|
|
26
|
-
"./emoji-provider": "./src/providers/emoji.ts",
|
|
27
|
-
"./get-confluence-page-providers": "./src/get-providers/confluence-page.ts"
|
|
22
|
+
".": "./src/index.ts"
|
|
28
23
|
},
|
|
29
24
|
"dependencies": {
|
|
30
25
|
"@atlaskit/adf-schema": "^49.0.6",
|
|
31
26
|
"@atlaskit/adf-utils": "^19.20.0",
|
|
32
|
-
"@atlaskit/emoji": "^69.3.0",
|
|
33
27
|
"@babel/runtime": "^7.0.0"
|
|
34
28
|
},
|
|
35
29
|
"peerDependencies": {
|
|
@@ -37,8 +31,6 @@
|
|
|
37
31
|
},
|
|
38
32
|
"devDependencies": {
|
|
39
33
|
"@atlaskit/editor-test-helpers": "workspace:^",
|
|
40
|
-
"@testing-library/react": "^13.4.0",
|
|
41
|
-
"@testing-library/react-hooks": "^8.0.1",
|
|
42
34
|
"typescript": "~5.4.2"
|
|
43
35
|
},
|
|
44
36
|
"techstack": {
|
package/cache/package.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@atlaskit/node-data-provider/cache",
|
|
3
|
-
"main": "../dist/cjs/cache.js",
|
|
4
|
-
"module": "../dist/esm/cache.js",
|
|
5
|
-
"module:es2019": "../dist/es2019/cache.js",
|
|
6
|
-
"sideEffects": false,
|
|
7
|
-
"types": "../dist/types/cache.d.ts",
|
|
8
|
-
"typesVersions": {
|
|
9
|
-
">=4.5 <5.4": {
|
|
10
|
-
"*": [
|
|
11
|
-
"../dist/types-ts4.5/cache.d.ts"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
package/content/package.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@atlaskit/node-data-provider/content",
|
|
3
|
-
"main": "../dist/cjs/consumption/content.js",
|
|
4
|
-
"module": "../dist/esm/consumption/content.js",
|
|
5
|
-
"module:es2019": "../dist/es2019/consumption/content.js",
|
|
6
|
-
"sideEffects": false,
|
|
7
|
-
"types": "../dist/types/consumption/content.d.ts",
|
|
8
|
-
"typesVersions": {
|
|
9
|
-
">=4.5 <5.4": {
|
|
10
|
-
"*": [
|
|
11
|
-
"../dist/types-ts4.5/consumption/content.d.ts"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
package/dist/cjs/cache.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.buildCaches = buildCaches;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
-
var _traverse = require("@atlaskit/adf-utils/traverse");
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
/**
|
|
15
|
-
* Builds {@link NodeDataProvider}s caches for a document.
|
|
16
|
-
*
|
|
17
|
-
* It will traverse the document and call the resolve method for each node.
|
|
18
|
-
* When all promises are resolved, NodeDataProviders will have their caches populated.
|
|
19
|
-
*
|
|
20
|
-
* The providers will then be ready for use with an Editor.
|
|
21
|
-
*
|
|
22
|
-
* To limit the time spent building the cache, a signal can be provided to abort the request.
|
|
23
|
-
*
|
|
24
|
-
* ## Usage
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* buildCaches({
|
|
29
|
-
* adf: doc,
|
|
30
|
-
* nodeDataProviders: { emoji: emojiNodeDataProvider, ... },
|
|
31
|
-
* signal: AbortSignal.timeout(5000),
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* ### Using caches
|
|
36
|
-
*
|
|
37
|
-
* To make use of a cache in another provider (ie. for a cache created on the server), you can retrieve the cache
|
|
38
|
-
* from the provider and pass it to the new provider.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```tsx
|
|
42
|
-
* // SSR env
|
|
43
|
-
* const ssrProvidersCaches = await buildCaches({adf, nodeDataProviders: { emoji }})
|
|
44
|
-
*
|
|
45
|
-
* // Client env (providersCaches is the cache from the server)
|
|
46
|
-
* <ContentNodeDataProviders ... existingProvidersCache={ssrProvidersCaches} />
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* *Note:* On the client - buildCache is not expected to be used directly.
|
|
50
|
-
*
|
|
51
|
-
* @see {@link ContentNodeDataProviders} for expected client usage.
|
|
52
|
-
*/
|
|
53
|
-
function buildCaches(_x) {
|
|
54
|
-
return _buildCaches.apply(this, arguments);
|
|
55
|
-
}
|
|
56
|
-
function _buildCaches() {
|
|
57
|
-
_buildCaches = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
|
|
58
|
-
var adf, nodeDataProviders, _ref$signal, signal, existingProvidersCache, visitors, promises, _loop, _i, _Object$values, caches, _i2, _Object$values2, nodeDataProvider;
|
|
59
|
-
return _regenerator.default.wrap(function _callee$(_context2) {
|
|
60
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
61
|
-
case 0:
|
|
62
|
-
adf = _ref.adf, nodeDataProviders = _ref.nodeDataProviders, _ref$signal = _ref.signal, signal = _ref$signal === void 0 ? new AbortController().signal : _ref$signal, existingProvidersCache = _ref.existingProvidersCache;
|
|
63
|
-
visitors = {};
|
|
64
|
-
promises = [];
|
|
65
|
-
_loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
|
|
66
|
-
var _nodeDataProvider, nodeDataProvider;
|
|
67
|
-
return _regenerator.default.wrap(function _loop$(_context) {
|
|
68
|
-
while (1) switch (_context.prev = _context.next) {
|
|
69
|
-
case 0:
|
|
70
|
-
_nodeDataProvider = _Object$values[_i];
|
|
71
|
-
// widen type to avoid typescript errors with the specific node data provider types
|
|
72
|
-
nodeDataProvider = _nodeDataProvider;
|
|
73
|
-
if (existingProvidersCache && existingProvidersCache[nodeDataProvider.nodeName]) {
|
|
74
|
-
nodeDataProvider.updateCache(existingProvidersCache[nodeDataProvider.nodeName], {
|
|
75
|
-
strategy: 'merge-override'
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
visitors[nodeDataProvider.nodeName] = function (node) {
|
|
79
|
-
var result = nodeDataProvider.get(node, {
|
|
80
|
-
signal: signal
|
|
81
|
-
});
|
|
82
|
-
if (!isPromise(result)) {
|
|
83
|
-
nodeDataProvider.cache[nodeDataProvider.nodeToKey(node)] = result;
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
promises.push(result);
|
|
87
|
-
result.then(function (resolvedValue) {
|
|
88
|
-
var signalAborted = signal ? signal.aborted : false;
|
|
89
|
-
if (!signalAborted && resolvedValue !== undefined) {
|
|
90
|
-
nodeDataProvider.cache[nodeDataProvider.nodeToKey(node)] = resolvedValue;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
return undefined;
|
|
94
|
-
};
|
|
95
|
-
case 4:
|
|
96
|
-
case "end":
|
|
97
|
-
return _context.stop();
|
|
98
|
-
}
|
|
99
|
-
}, _loop);
|
|
100
|
-
});
|
|
101
|
-
_i = 0, _Object$values = Object.values(nodeDataProviders);
|
|
102
|
-
case 5:
|
|
103
|
-
if (!(_i < _Object$values.length)) {
|
|
104
|
-
_context2.next = 10;
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
return _context2.delegateYield(_loop(), "t0", 7);
|
|
108
|
-
case 7:
|
|
109
|
-
_i++;
|
|
110
|
-
_context2.next = 5;
|
|
111
|
-
break;
|
|
112
|
-
case 10:
|
|
113
|
-
if (!adf) {
|
|
114
|
-
_context2.next = 16;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
(0, _traverse.traverse)(adf, visitors);
|
|
118
|
-
_context2.next = 14;
|
|
119
|
-
return Promise.all(promises);
|
|
120
|
-
case 14:
|
|
121
|
-
_context2.next = 18;
|
|
122
|
-
break;
|
|
123
|
-
case 16:
|
|
124
|
-
_context2.next = 18;
|
|
125
|
-
return Promise.resolve();
|
|
126
|
-
case 18:
|
|
127
|
-
caches = {};
|
|
128
|
-
for (_i2 = 0, _Object$values2 = Object.values(nodeDataProviders); _i2 < _Object$values2.length; _i2++) {
|
|
129
|
-
nodeDataProvider = _Object$values2[_i2];
|
|
130
|
-
caches[nodeDataProvider.nodeName] = nodeDataProvider.cache;
|
|
131
|
-
}
|
|
132
|
-
return _context2.abrupt("return", caches);
|
|
133
|
-
case 21:
|
|
134
|
-
case "end":
|
|
135
|
-
return _context2.stop();
|
|
136
|
-
}
|
|
137
|
-
}, _callee);
|
|
138
|
-
}));
|
|
139
|
-
return _buildCaches.apply(this, arguments);
|
|
140
|
-
}
|
|
141
|
-
function isPromise(obj) {
|
|
142
|
-
return !!obj && ((0, _typeof2.default)(obj) === 'object' || typeof obj === 'function') &&
|
|
143
|
-
// @ts-ignore
|
|
144
|
-
typeof obj.then === 'function';
|
|
145
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports._resetGlobalNdpCachesContext = _resetGlobalNdpCachesContext;
|
|
8
|
-
exports.useGlobalNdpCachesContext = useGlobalNdpCachesContext;
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
var GlobalNdpCachesContext = /*#__PURE__*/_react.default.createContext({});
|
|
11
|
-
function useGlobalNdpCachesContext() {
|
|
12
|
-
var globalNdpCachesContextValue = _react.default.useContext(GlobalNdpCachesContext);
|
|
13
|
-
return globalNdpCachesContextValue;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// The ndp caches currently use module scope to store the caches. This is not ideal, and a global provider
|
|
17
|
-
// will avoid the need for this.
|
|
18
|
-
// This function is used to reset the global ndp caches context in tests.
|
|
19
|
-
function _resetGlobalNdpCachesContext() {
|
|
20
|
-
GlobalNdpCachesContext = /*#__PURE__*/_react.default.createContext({});
|
|
21
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.useContentNodeDataProvidersSetup = useContentNodeDataProvidersSetup;
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
var _cache = require("../cache");
|
|
10
|
-
var _globalNdpCaches = require("./_global-ndp-caches");
|
|
11
|
-
var _lruCache = require("./_lru-cache");
|
|
12
|
-
/**
|
|
13
|
-
* The settings for the data providers lru cache,
|
|
14
|
-
* increasing the value will increase the number of data providers that can be stored in the cache.
|
|
15
|
-
*/
|
|
16
|
-
var lruCacheSettings = {
|
|
17
|
-
page: 5,
|
|
18
|
-
default: 1
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Sets up nodeview data providers for a content node.
|
|
23
|
-
*
|
|
24
|
-
* This will return the cached node data providers if they exist, otherwise it will call the provided getNodeDataProviders function.
|
|
25
|
-
*
|
|
26
|
-
* Note: Calling this has side effects where caches for the nodeview data providers will continue to be built
|
|
27
|
-
* in the background after this resolves to a set of nodeview data providers that can be used.
|
|
28
|
-
*/
|
|
29
|
-
function useContentNodeDataProvidersSetup(content,
|
|
30
|
-
/**
|
|
31
|
-
* Note: changes to this object will not be reflected in the cache.
|
|
32
|
-
*/
|
|
33
|
-
setupOptions) {
|
|
34
|
-
var _globalNdpCachesContextValue = (0, _globalNdpCaches.useGlobalNdpCachesContext)();
|
|
35
|
-
// Create a cache for the content type if it doesn't exist
|
|
36
|
-
// While this will not result in any existing context consumers getting the updated value.
|
|
37
|
-
// It will ensure that the cache is available for future consumers.
|
|
38
|
-
if (_globalNdpCachesContextValue[content.contentType] === undefined) {
|
|
39
|
-
var _lruCacheSettings$con;
|
|
40
|
-
_globalNdpCachesContextValue[content.contentType] = new _lruCache.LRUCache((_lruCacheSettings$con = lruCacheSettings[content.contentType]) !== null && _lruCacheSettings$con !== void 0 ? _lruCacheSettings$con : lruCacheSettings.default);
|
|
41
|
-
}
|
|
42
|
-
var contentTypeNdpCaches = _globalNdpCachesContextValue[content.contentType];
|
|
43
|
-
|
|
44
|
-
// The node data providers should only be rebuilt if the content changes
|
|
45
|
-
// to avoid unnecessary rebuilding of the cache.
|
|
46
|
-
// useRef is used over useMemo as use memo is not a guarantee that the value will be reused
|
|
47
|
-
// - in development it can be called twice
|
|
48
|
-
// - 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.
|
|
49
|
-
var currentContentKey = "".concat(content.contentType, "-").concat(content.contentId);
|
|
50
|
-
var contentKeyRef = _react.default.useRef();
|
|
51
|
-
var nodeDataProvidersRef = _react.default.useRef();
|
|
52
|
-
if (contentKeyRef.current !== currentContentKey) {
|
|
53
|
-
contentKeyRef.current = currentContentKey;
|
|
54
|
-
var cachedContentNdps = contentTypeNdpCaches === null || contentTypeNdpCaches === void 0 ? void 0 : contentTypeNdpCaches.get(content.contentId);
|
|
55
|
-
var nodeDataProviders = cachedContentNdps || setupOptions.getNodeDataProviders();
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Note: while this will remove old NodeDataProviders from the cache -- these are passed directly to consumers,
|
|
59
|
-
* so removing from the cache will not result in actively used NodeDataProviders being deleted in some way.
|
|
60
|
-
*
|
|
61
|
-
*/
|
|
62
|
-
contentTypeNdpCaches.set(content.contentId, nodeDataProviders);
|
|
63
|
-
(0, _cache.buildCaches)({
|
|
64
|
-
adf: setupOptions.adfToUpdateWith,
|
|
65
|
-
nodeDataProviders: nodeDataProviders,
|
|
66
|
-
existingProvidersCache: setupOptions.existingProvidersCache
|
|
67
|
-
}).then(function (warmedNodeDataProvidersCache) {
|
|
68
|
-
var _setupOptions$onCache;
|
|
69
|
-
(_setupOptions$onCache = setupOptions.onCacheWarmed) === null || _setupOptions$onCache === void 0 || _setupOptions$onCache.call(setupOptions, {
|
|
70
|
-
warmedNodeDataProvidersCache: warmedNodeDataProvidersCache,
|
|
71
|
-
nodeDataProviders: nodeDataProviders
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
nodeDataProvidersRef.current = nodeDataProviders;
|
|
75
|
-
}
|
|
76
|
-
return nodeDataProvidersRef.current;
|
|
77
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.LRUCache = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var LRUCache = exports.LRUCache = /*#__PURE__*/function () {
|
|
11
|
-
function LRUCache(capacity) {
|
|
12
|
-
(0, _classCallCheck2.default)(this, LRUCache);
|
|
13
|
-
this.capacity = capacity;
|
|
14
|
-
this.cache = new Map();
|
|
15
|
-
}
|
|
16
|
-
return (0, _createClass2.default)(LRUCache, [{
|
|
17
|
-
key: "get",
|
|
18
|
-
value: function get(key) {
|
|
19
|
-
if (!this.cache.has(key)) {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Move the used key to the end to mark it as most recently used
|
|
24
|
-
// Ignored via go/ees005
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
26
|
-
var value = this.cache.get(key);
|
|
27
|
-
this.cache.delete(key);
|
|
28
|
-
this.cache.set(key, value);
|
|
29
|
-
return value;
|
|
30
|
-
}
|
|
31
|
-
}, {
|
|
32
|
-
key: "set",
|
|
33
|
-
value: function set(key, value) {
|
|
34
|
-
// Check if the key already exists and delete it to update its position
|
|
35
|
-
if (this.cache.has(key)) {
|
|
36
|
-
this.cache.delete(key);
|
|
37
|
-
} else if (this.cache.size >= this.capacity) {
|
|
38
|
-
// Remove the first (least recently used) cache item if we're at capacity
|
|
39
|
-
var firstKey = this.cache.keys().next().value;
|
|
40
|
-
this.cache.delete(firstKey);
|
|
41
|
-
}
|
|
42
|
-
this.cache.set(key, value);
|
|
43
|
-
}
|
|
44
|
-
}]);
|
|
45
|
-
}();
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.ContentNodeDataProviders = ContentNodeDataProviders;
|
|
8
|
-
Object.defineProperty(exports, "__testOnly_resetGlobalNdpCachesContext", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function get() {
|
|
11
|
-
return _globalNdpCaches._resetGlobalNdpCachesContext;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
exports.useContentNodeDataProviders = useContentNodeDataProviders;
|
|
15
|
-
var _react = _interopRequireDefault(require("react"));
|
|
16
|
-
var _globalNdpCaches = require("./_global-ndp-caches");
|
|
17
|
-
var _internalContext = require("./_internal-context");
|
|
18
|
-
/* eslint-disable @atlaskit/editor/no-re-export */
|
|
19
|
-
// Entry file
|
|
20
|
-
|
|
21
|
-
var ContentNodeDataProvidersContext = /*#__PURE__*/_react.default.createContext(undefined);
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```tsx
|
|
27
|
-
* <ContentNodeDataProviders
|
|
28
|
-
* contentType="page" contentId="9001"
|
|
29
|
-
* adf={doc}
|
|
30
|
-
* placeholder={<Spinner />}
|
|
31
|
-
* existingProvidersCache={ssrProvidersCache}
|
|
32
|
-
* getNodeDataProviders={getPageNodeDataProviders}
|
|
33
|
-
* onCacheWarmed={trackCacheWarmed}
|
|
34
|
-
* >
|
|
35
|
-
* <Editor />
|
|
36
|
-
* </ContentNodeDataProviders>
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
function ContentNodeDataProviders(props) {
|
|
40
|
-
var contentNodeDataProviders = (0, _internalContext.useContentNodeDataProvidersSetup)({
|
|
41
|
-
contentType: props.contentType,
|
|
42
|
-
contentId: props.contentId
|
|
43
|
-
}, {
|
|
44
|
-
adfToUpdateWith: props.adf,
|
|
45
|
-
existingProvidersCache: props.existingProvidersCache,
|
|
46
|
-
getNodeDataProviders: props.getNodeDataProviders,
|
|
47
|
-
onCacheWarmed: props.onCacheWarmed
|
|
48
|
-
});
|
|
49
|
-
return /*#__PURE__*/_react.default.createElement(ContentNodeDataProvidersContext.Provider, {
|
|
50
|
-
value: contentNodeDataProviders
|
|
51
|
-
}, props.children);
|
|
52
|
-
}
|
|
53
|
-
function useContentNodeDataProviders() {
|
|
54
|
-
var contentNodeDataProvidersContext = _react.default.useContext(ContentNodeDataProvidersContext);
|
|
55
|
-
return contentNodeDataProvidersContext;
|
|
56
|
-
}
|