@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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/index.js +19 -1
- 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 +4 -0
- 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 +4 -0
- 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 -0
- 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 -0
- 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 +5 -4
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { JSONDocNode, JSONNode } from '@atlaskit/editor-json-transformer';
|
|
2
|
+
import type { NodeDataProvider } from '../node-data-provider';
|
|
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
|
+
type SsrData = {
|
|
14
|
+
[dataKey: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Represents the aggregated SSR data for all node data providers.
|
|
18
|
+
* It's a map where each key is a provider's name and the value is the {@link SsrData} for that provider.
|
|
19
|
+
* This structure is used to hydrate the client-side caches.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* {
|
|
23
|
+
* 'mentionProvider': { 'mention-1': { id: '1', name: 'John Doe' } },
|
|
24
|
+
* 'emojiProvider': { 'emoji-123': { shortName: ':smile:', representation: '😊' } }
|
|
25
|
+
* }
|
|
26
|
+
*/
|
|
27
|
+
type NodeDataProvidersSsrData = {
|
|
28
|
+
[providerName: string]: SsrData;
|
|
29
|
+
};
|
|
30
|
+
interface Props {
|
|
31
|
+
/**
|
|
32
|
+
* The document for which to prefetch data.
|
|
33
|
+
*/
|
|
34
|
+
doc: JSONDocNode;
|
|
35
|
+
/**
|
|
36
|
+
* A global timeout in milliseconds for all fetch requests.
|
|
37
|
+
*
|
|
38
|
+
* Each provider will use the minimum of this value and its own specific timeout.
|
|
39
|
+
*/
|
|
40
|
+
timeout: number;
|
|
41
|
+
/**
|
|
42
|
+
* The maximum number of nodes to visit when searching for nodes to prefetch.
|
|
43
|
+
* This is a performance safeguard for very large documents.
|
|
44
|
+
*
|
|
45
|
+
* @default If not specified, the entire document will be traversed.
|
|
46
|
+
*/
|
|
47
|
+
maxNodesToVisit?: number;
|
|
48
|
+
/**
|
|
49
|
+
* A list of node data providers to use for prefetching, along with their
|
|
50
|
+
* individual configurations.
|
|
51
|
+
*/
|
|
52
|
+
providers: {
|
|
53
|
+
/**
|
|
54
|
+
* The provider instance to use for prefetching.
|
|
55
|
+
*/
|
|
56
|
+
provider: NodeDataProvider<JSONNode, unknown>;
|
|
57
|
+
/**
|
|
58
|
+
* The maximum number of nodes to prefetch for this specific provider.
|
|
59
|
+
* This helps prevent performance issues with documents containing many
|
|
60
|
+
* nodes of the same type.
|
|
61
|
+
*
|
|
62
|
+
* @default If not specified, all nodes supported by the provider will be prefetched.
|
|
63
|
+
*/
|
|
64
|
+
maxNodesToPrefetch?: number;
|
|
65
|
+
/**
|
|
66
|
+
* The timeout in milliseconds for the fetch request for this specific provider.
|
|
67
|
+
* If the request takes longer than this, it will be aborted and return no data.
|
|
68
|
+
*
|
|
69
|
+
* @default If not specified, the global timeout will be used.
|
|
70
|
+
*/
|
|
71
|
+
timeout?: number;
|
|
72
|
+
}[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Fetches data for nodes in the document that are supported by the given providers.
|
|
76
|
+
* This function will traverse the document and call the `fetchData` method for each node that is supported by the providers.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```
|
|
80
|
+
* const doc = JSON.parse('{"type": "doc", "content": [...] }');
|
|
81
|
+
* const providers = [
|
|
82
|
+
* {
|
|
83
|
+
* provider: new EditorCardProvider(),
|
|
84
|
+
* maxNodesToPrefetch: 10,
|
|
85
|
+
* timeout: 500,
|
|
86
|
+
* },
|
|
87
|
+
* {
|
|
88
|
+
* provider: new EditorMentionsProvider(),
|
|
89
|
+
* maxNodesToPrefetch: 50,
|
|
90
|
+
* timeout: 500,
|
|
91
|
+
* },
|
|
92
|
+
* ];
|
|
93
|
+
*
|
|
94
|
+
* window['__SSR_EDITOR_NODE_DATA_PROVIDERS_DATA__'] = await prefetchNodeDataProvidersData({
|
|
95
|
+
* providers,
|
|
96
|
+
* doc,
|
|
97
|
+
* timeout: 1_000,
|
|
98
|
+
* maxNodesToVisit: 2_000
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @param props The properties for prefetching node data.
|
|
103
|
+
* @returns Record of provider names to their respective SSR data,
|
|
104
|
+
* where each SSR data is a record of node data keys to the fetched data.
|
|
105
|
+
*/
|
|
106
|
+
export declare function prefetchNodeDataProvidersData({ providers, doc, timeout, maxNodesToVisit, }: Props): Promise<NodeDataProvidersSsrData>;
|
|
107
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/node-data-provider",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.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",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"registry": "https://registry.npmjs.org/"
|
|
9
9
|
},
|
|
10
10
|
"atlassian": {
|
|
11
|
-
"team": "Editor:
|
|
11
|
+
"team": "Editor: Lego",
|
|
12
12
|
"singleton": true
|
|
13
13
|
},
|
|
14
14
|
"repository": "https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo",
|
|
@@ -24,13 +24,14 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@atlaskit/adf-schema": "^49.0.6",
|
|
26
26
|
"@atlaskit/adf-utils": "^19.20.0",
|
|
27
|
+
"@atlaskit/editor-json-transformer": "^8.24.0",
|
|
28
|
+
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
27
29
|
"@babel/runtime": "^7.0.0"
|
|
28
30
|
},
|
|
29
31
|
"peerDependencies": {
|
|
30
|
-
"
|
|
32
|
+
"@atlaskit/editor-common": "^107.12.0"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
|
-
"@atlaskit/editor-test-helpers": "workspace:^",
|
|
34
35
|
"typescript": "~5.4.2"
|
|
35
36
|
},
|
|
36
37
|
"techstack": {
|