@backstage/plugin-techdocs-react 0.1.1-next.0 → 1.0.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 +62 -0
- package/alpha/package.json +1 -1
- package/dist/index.alpha.d.ts +47 -13
- package/dist/index.beta.d.ts +122 -11
- package/dist/index.d.ts +122 -11
- package/dist/index.esm.js +5 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
# @backstage/plugin-techdocs-react
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 0ad901569f: The TechDocs Addon framework is now generally available.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 52419be116: Create a new addon location called "Settings", it is designed for addons that allow users to customize the reading experience in documentation pages.
|
|
12
|
+
|
|
13
|
+
Usage example:
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
const TextSize = techdocsModuleAddonsContribPlugin.provide(
|
|
17
|
+
createTechDocsAddonExtension({
|
|
18
|
+
name: 'TextSize',
|
|
19
|
+
location: TechDocsAddonLocations.Settings,
|
|
20
|
+
component: TextSizeAddon,
|
|
21
|
+
}),
|
|
22
|
+
);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- c25e880e36: Added overload signatures for `createTechDocsAddonExtension` to handle TechDocs addons without props.
|
|
26
|
+
- 52fddad92d: The `TechDocsStorageApi` and its associated ref are now exported by `@backstage/plugin-techdocs-react`. The API interface, ref, and types are now deprecated in `@backstage/plugin-techdocs` and will be removed in a future release.
|
|
27
|
+
- 075a9a067b: Updated the return type of `createTechDocsAddonExtension` to better reflect the fact that passing children to Addon components is not a valid use-case.
|
|
28
|
+
- Updated dependencies
|
|
29
|
+
- @backstage/core-components@0.9.4
|
|
30
|
+
- @backstage/core-plugin-api@1.0.2
|
|
31
|
+
- @backstage/catalog-model@1.0.2
|
|
32
|
+
|
|
33
|
+
## 0.1.1-next.2
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- 52419be116: Create a new addon location called "Settings", it is designed for addons that allow users to customize the reading experience in documentation pages.
|
|
38
|
+
|
|
39
|
+
Usage example:
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
const TextSize = techdocsModuleAddonsContribPlugin.provide(
|
|
43
|
+
createTechDocsAddonExtension({
|
|
44
|
+
name: 'TextSize',
|
|
45
|
+
location: TechDocsAddonLocations.Settings,
|
|
46
|
+
component: TextSizeAddon,
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- Updated dependencies
|
|
52
|
+
- @backstage/core-components@0.9.4-next.1
|
|
53
|
+
- @backstage/catalog-model@1.0.2-next.0
|
|
54
|
+
- @backstage/core-plugin-api@1.0.2-next.1
|
|
55
|
+
|
|
56
|
+
## 0.1.1-next.1
|
|
57
|
+
|
|
58
|
+
### Patch Changes
|
|
59
|
+
|
|
60
|
+
- 52fddad92d: The `TechDocsStorageApi` and its associated ref are now exported by `@backstage/plugin-techdocs-react`. The API interface, ref, and types are now deprecated in `@backstage/plugin-techdocs` and will be removed in a future release.
|
|
61
|
+
- Updated dependencies
|
|
62
|
+
- @backstage/core-components@0.9.4-next.0
|
|
63
|
+
- @backstage/core-plugin-api@1.0.2-next.0
|
|
64
|
+
|
|
3
65
|
## 0.1.1-next.0
|
|
4
66
|
|
|
5
67
|
### Patch Changes
|
package/alpha/package.json
CHANGED
package/dist/index.alpha.d.ts
CHANGED
|
@@ -16,25 +16,33 @@ import { ReactNode } from 'react';
|
|
|
16
16
|
import { SetStateAction } from 'react';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Create a TechDocs addon.
|
|
20
|
-
* @
|
|
19
|
+
* Create a TechDocs addon overload signature without props.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTechDocsAddonExtension(options: TechDocsAddonOptions): Extension<() => JSX.Element | null>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a TechDocs addon overload signature with props.
|
|
26
|
+
* @public
|
|
21
27
|
*/
|
|
22
28
|
export declare function createTechDocsAddonExtension<TComponentProps>(options: TechDocsAddonOptions<TComponentProps>): Extension<(props: TComponentProps) => JSX.Element | null>;
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
|
-
*
|
|
31
|
+
* The outcome of a docs sync operation.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
26
34
|
*/
|
|
27
|
-
export declare
|
|
35
|
+
export declare type SyncResult = 'cached' | 'updated';
|
|
28
36
|
|
|
29
37
|
/**
|
|
30
38
|
* Marks the <TechDocsAddons> registry component.
|
|
31
|
-
* @
|
|
39
|
+
* @public
|
|
32
40
|
*/
|
|
33
41
|
export declare const TECHDOCS_ADDONS_WRAPPER_KEY = "techdocs.addons.wrapper.v1";
|
|
34
42
|
|
|
35
43
|
/**
|
|
36
44
|
* Locations for which TechDocs addons may be declared and rendered.
|
|
37
|
-
* @
|
|
45
|
+
* @public
|
|
38
46
|
*/
|
|
39
47
|
export declare const TechDocsAddonLocations: Readonly<{
|
|
40
48
|
/**
|
|
@@ -47,6 +55,11 @@ export declare const TechDocsAddonLocations: Readonly<{
|
|
|
47
55
|
* can be inserted for convenience.
|
|
48
56
|
*/
|
|
49
57
|
readonly Subheader: "Subheader";
|
|
58
|
+
/**
|
|
59
|
+
* These addons are items added to the settings menu list and are designed to make
|
|
60
|
+
* the reader experience customizable, for example accessibility options
|
|
61
|
+
*/
|
|
62
|
+
readonly Settings: "Settings";
|
|
50
63
|
/**
|
|
51
64
|
* These addons appear left of the content and above the navigation.
|
|
52
65
|
*/
|
|
@@ -64,7 +77,7 @@ export declare const TechDocsAddonLocations: Readonly<{
|
|
|
64
77
|
|
|
65
78
|
/**
|
|
66
79
|
* Options for creating a TechDocs addon.
|
|
67
|
-
* @
|
|
80
|
+
* @public
|
|
68
81
|
*/
|
|
69
82
|
export declare type TechDocsAddonOptions<TAddonProps = {}> = {
|
|
70
83
|
name: string;
|
|
@@ -74,7 +87,7 @@ export declare type TechDocsAddonOptions<TAddonProps = {}> = {
|
|
|
74
87
|
|
|
75
88
|
/**
|
|
76
89
|
* TechDocs Addon registry.
|
|
77
|
-
* @
|
|
90
|
+
* @public
|
|
78
91
|
*/
|
|
79
92
|
export declare const TechDocsAddons: React_2.ComponentType;
|
|
80
93
|
|
|
@@ -160,10 +173,31 @@ export declare type TechDocsReaderPageValue = {
|
|
|
160
173
|
onReady?: () => void;
|
|
161
174
|
};
|
|
162
175
|
|
|
176
|
+
/**
|
|
177
|
+
* API which talks to TechDocs storage to fetch files to render.
|
|
178
|
+
*
|
|
179
|
+
* @public
|
|
180
|
+
*/
|
|
181
|
+
export declare interface TechDocsStorageApi {
|
|
182
|
+
getApiOrigin(): Promise<string>;
|
|
183
|
+
getStorageUrl(): Promise<string>;
|
|
184
|
+
getBuilder(): Promise<string>;
|
|
185
|
+
getEntityDocs(entityId: CompoundEntityRef, path: string): Promise<string>;
|
|
186
|
+
syncEntityDocs(entityId: CompoundEntityRef, logHandler?: (line: string) => void): Promise<SyncResult>;
|
|
187
|
+
getBaseUrl(oldBaseUrl: string, entityId: CompoundEntityRef, path: string): Promise<string>;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Utility API reference for the {@link TechDocsStorageApi}.
|
|
192
|
+
*
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
export declare const techdocsStorageApiRef: ApiRef<TechDocsStorageApi>;
|
|
196
|
+
|
|
163
197
|
/**
|
|
164
198
|
* Hook for use within TechDocs addons that provides access to the underlying
|
|
165
199
|
* shadow root of the current page, allowing the DOM within to be mutated.
|
|
166
|
-
* @
|
|
200
|
+
* @public
|
|
167
201
|
*/
|
|
168
202
|
export declare const useShadowRoot: () => ShadowRoot | undefined;
|
|
169
203
|
|
|
@@ -171,19 +205,19 @@ export declare const useShadowRoot: () => ShadowRoot | undefined;
|
|
|
171
205
|
* Convenience hook for use within TechDocs addons that provides access to
|
|
172
206
|
* elements that match a given selector within the shadow root.
|
|
173
207
|
*
|
|
174
|
-
* @
|
|
208
|
+
* @public
|
|
175
209
|
*/
|
|
176
210
|
export declare const useShadowRootElements: <TReturnedElement extends HTMLElement = HTMLElement>(selectors: string[]) => TReturnedElement[];
|
|
177
211
|
|
|
178
212
|
/**
|
|
179
213
|
* Hook for retreiving a selection within the ShadowRoot.
|
|
180
|
-
* @
|
|
214
|
+
* @public
|
|
181
215
|
*/
|
|
182
216
|
export declare const useShadowRootSelection: (wait?: number) => Selection | null;
|
|
183
217
|
|
|
184
218
|
/**
|
|
185
219
|
* hook to use addons in components
|
|
186
|
-
* @
|
|
220
|
+
* @public
|
|
187
221
|
*/
|
|
188
222
|
export declare const useTechDocsAddons: () => {
|
|
189
223
|
renderComponentByName: (name: string) => JSX.Element | null;
|
|
@@ -192,7 +226,7 @@ export declare const useTechDocsAddons: () => {
|
|
|
192
226
|
|
|
193
227
|
/**
|
|
194
228
|
* Hook used to get access to shared state between reader page components.
|
|
195
|
-
* @
|
|
229
|
+
* @public
|
|
196
230
|
*/
|
|
197
231
|
export declare const useTechDocsReaderPage: () => TechDocsReaderPageValue;
|
|
198
232
|
|
package/dist/index.beta.d.ts
CHANGED
|
@@ -15,17 +15,81 @@ import { default as React_2 } from 'react';
|
|
|
15
15
|
import { ReactNode } from 'react';
|
|
16
16
|
import { SetStateAction } from 'react';
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Create a TechDocs addon overload signature without props.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTechDocsAddonExtension(options: TechDocsAddonOptions): Extension<() => JSX.Element | null>;
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Create a TechDocs addon overload signature with props.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare function createTechDocsAddonExtension<TComponentProps>(options: TechDocsAddonOptions<TComponentProps>): Extension<(props: TComponentProps) => JSX.Element | null>;
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The outcome of a docs sync operation.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare type SyncResult = 'cached' | 'updated';
|
|
23
36
|
|
|
24
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Marks the <TechDocsAddons> registry component.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export declare const TECHDOCS_ADDONS_WRAPPER_KEY = "techdocs.addons.wrapper.v1";
|
|
25
42
|
|
|
26
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Locations for which TechDocs addons may be declared and rendered.
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export declare const TechDocsAddonLocations: Readonly<{
|
|
48
|
+
/**
|
|
49
|
+
* These addons fill up the header from the right, on the same line as the
|
|
50
|
+
* title.
|
|
51
|
+
*/
|
|
52
|
+
readonly Header: "Header";
|
|
53
|
+
/**
|
|
54
|
+
* These addons appear below the header and above all content; tooling addons
|
|
55
|
+
* can be inserted for convenience.
|
|
56
|
+
*/
|
|
57
|
+
readonly Subheader: "Subheader";
|
|
58
|
+
/**
|
|
59
|
+
* These addons are items added to the settings menu list and are designed to make
|
|
60
|
+
* the reader experience customizable, for example accessibility options
|
|
61
|
+
*/
|
|
62
|
+
readonly Settings: "Settings";
|
|
63
|
+
/**
|
|
64
|
+
* These addons appear left of the content and above the navigation.
|
|
65
|
+
*/
|
|
66
|
+
readonly PrimarySidebar: "PrimarySidebar";
|
|
67
|
+
/**
|
|
68
|
+
* These addons appear right of the content and above the table of contents.
|
|
69
|
+
*/
|
|
70
|
+
readonly SecondarySidebar: "SecondarySidebar";
|
|
71
|
+
/**
|
|
72
|
+
* A virtual location which allows mutation of all content within the shadow
|
|
73
|
+
* root by transforming DOM nodes. These addons should return null on render.
|
|
74
|
+
*/
|
|
75
|
+
readonly Content: "Content";
|
|
76
|
+
}>;
|
|
27
77
|
|
|
28
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Options for creating a TechDocs addon.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export declare type TechDocsAddonOptions<TAddonProps = {}> = {
|
|
83
|
+
name: string;
|
|
84
|
+
location: keyof typeof TechDocsAddonLocations;
|
|
85
|
+
component: ComponentType<TAddonProps>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* TechDocs Addon registry.
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
export declare const TechDocsAddons: React_2.ComponentType;
|
|
29
93
|
|
|
30
94
|
/**
|
|
31
95
|
* API to talk to techdocs-backend.
|
|
@@ -109,14 +173,61 @@ export declare type TechDocsReaderPageValue = {
|
|
|
109
173
|
onReady?: () => void;
|
|
110
174
|
};
|
|
111
175
|
|
|
112
|
-
|
|
176
|
+
/**
|
|
177
|
+
* API which talks to TechDocs storage to fetch files to render.
|
|
178
|
+
*
|
|
179
|
+
* @public
|
|
180
|
+
*/
|
|
181
|
+
export declare interface TechDocsStorageApi {
|
|
182
|
+
getApiOrigin(): Promise<string>;
|
|
183
|
+
getStorageUrl(): Promise<string>;
|
|
184
|
+
getBuilder(): Promise<string>;
|
|
185
|
+
getEntityDocs(entityId: CompoundEntityRef, path: string): Promise<string>;
|
|
186
|
+
syncEntityDocs(entityId: CompoundEntityRef, logHandler?: (line: string) => void): Promise<SyncResult>;
|
|
187
|
+
getBaseUrl(oldBaseUrl: string, entityId: CompoundEntityRef, path: string): Promise<string>;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Utility API reference for the {@link TechDocsStorageApi}.
|
|
192
|
+
*
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
export declare const techdocsStorageApiRef: ApiRef<TechDocsStorageApi>;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Hook for use within TechDocs addons that provides access to the underlying
|
|
199
|
+
* shadow root of the current page, allowing the DOM within to be mutated.
|
|
200
|
+
* @public
|
|
201
|
+
*/
|
|
202
|
+
export declare const useShadowRoot: () => ShadowRoot | undefined;
|
|
113
203
|
|
|
114
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Convenience hook for use within TechDocs addons that provides access to
|
|
206
|
+
* elements that match a given selector within the shadow root.
|
|
207
|
+
*
|
|
208
|
+
* @public
|
|
209
|
+
*/
|
|
210
|
+
export declare const useShadowRootElements: <TReturnedElement extends HTMLElement = HTMLElement>(selectors: string[]) => TReturnedElement[];
|
|
115
211
|
|
|
116
|
-
|
|
212
|
+
/**
|
|
213
|
+
* Hook for retreiving a selection within the ShadowRoot.
|
|
214
|
+
* @public
|
|
215
|
+
*/
|
|
216
|
+
export declare const useShadowRootSelection: (wait?: number) => Selection | null;
|
|
117
217
|
|
|
118
|
-
|
|
218
|
+
/**
|
|
219
|
+
* hook to use addons in components
|
|
220
|
+
* @public
|
|
221
|
+
*/
|
|
222
|
+
export declare const useTechDocsAddons: () => {
|
|
223
|
+
renderComponentByName: (name: string) => JSX.Element | null;
|
|
224
|
+
renderComponentsByLocation: (location: keyof typeof TechDocsAddonLocations) => (JSX.Element | null)[] | null;
|
|
225
|
+
};
|
|
119
226
|
|
|
120
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Hook used to get access to shared state between reader page components.
|
|
229
|
+
* @public
|
|
230
|
+
*/
|
|
231
|
+
export declare const useTechDocsReaderPage: () => TechDocsReaderPageValue;
|
|
121
232
|
|
|
122
233
|
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -15,17 +15,81 @@ import { default as React_2 } from 'react';
|
|
|
15
15
|
import { ReactNode } from 'react';
|
|
16
16
|
import { SetStateAction } from 'react';
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Create a TechDocs addon overload signature without props.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTechDocsAddonExtension(options: TechDocsAddonOptions): Extension<() => JSX.Element | null>;
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Create a TechDocs addon overload signature with props.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare function createTechDocsAddonExtension<TComponentProps>(options: TechDocsAddonOptions<TComponentProps>): Extension<(props: TComponentProps) => JSX.Element | null>;
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The outcome of a docs sync operation.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare type SyncResult = 'cached' | 'updated';
|
|
23
36
|
|
|
24
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Marks the <TechDocsAddons> registry component.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export declare const TECHDOCS_ADDONS_WRAPPER_KEY = "techdocs.addons.wrapper.v1";
|
|
25
42
|
|
|
26
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Locations for which TechDocs addons may be declared and rendered.
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export declare const TechDocsAddonLocations: Readonly<{
|
|
48
|
+
/**
|
|
49
|
+
* These addons fill up the header from the right, on the same line as the
|
|
50
|
+
* title.
|
|
51
|
+
*/
|
|
52
|
+
readonly Header: "Header";
|
|
53
|
+
/**
|
|
54
|
+
* These addons appear below the header and above all content; tooling addons
|
|
55
|
+
* can be inserted for convenience.
|
|
56
|
+
*/
|
|
57
|
+
readonly Subheader: "Subheader";
|
|
58
|
+
/**
|
|
59
|
+
* These addons are items added to the settings menu list and are designed to make
|
|
60
|
+
* the reader experience customizable, for example accessibility options
|
|
61
|
+
*/
|
|
62
|
+
readonly Settings: "Settings";
|
|
63
|
+
/**
|
|
64
|
+
* These addons appear left of the content and above the navigation.
|
|
65
|
+
*/
|
|
66
|
+
readonly PrimarySidebar: "PrimarySidebar";
|
|
67
|
+
/**
|
|
68
|
+
* These addons appear right of the content and above the table of contents.
|
|
69
|
+
*/
|
|
70
|
+
readonly SecondarySidebar: "SecondarySidebar";
|
|
71
|
+
/**
|
|
72
|
+
* A virtual location which allows mutation of all content within the shadow
|
|
73
|
+
* root by transforming DOM nodes. These addons should return null on render.
|
|
74
|
+
*/
|
|
75
|
+
readonly Content: "Content";
|
|
76
|
+
}>;
|
|
27
77
|
|
|
28
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Options for creating a TechDocs addon.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export declare type TechDocsAddonOptions<TAddonProps = {}> = {
|
|
83
|
+
name: string;
|
|
84
|
+
location: keyof typeof TechDocsAddonLocations;
|
|
85
|
+
component: ComponentType<TAddonProps>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* TechDocs Addon registry.
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
export declare const TechDocsAddons: React_2.ComponentType;
|
|
29
93
|
|
|
30
94
|
/**
|
|
31
95
|
* API to talk to techdocs-backend.
|
|
@@ -109,14 +173,61 @@ export declare type TechDocsReaderPageValue = {
|
|
|
109
173
|
onReady?: () => void;
|
|
110
174
|
};
|
|
111
175
|
|
|
112
|
-
|
|
176
|
+
/**
|
|
177
|
+
* API which talks to TechDocs storage to fetch files to render.
|
|
178
|
+
*
|
|
179
|
+
* @public
|
|
180
|
+
*/
|
|
181
|
+
export declare interface TechDocsStorageApi {
|
|
182
|
+
getApiOrigin(): Promise<string>;
|
|
183
|
+
getStorageUrl(): Promise<string>;
|
|
184
|
+
getBuilder(): Promise<string>;
|
|
185
|
+
getEntityDocs(entityId: CompoundEntityRef, path: string): Promise<string>;
|
|
186
|
+
syncEntityDocs(entityId: CompoundEntityRef, logHandler?: (line: string) => void): Promise<SyncResult>;
|
|
187
|
+
getBaseUrl(oldBaseUrl: string, entityId: CompoundEntityRef, path: string): Promise<string>;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Utility API reference for the {@link TechDocsStorageApi}.
|
|
192
|
+
*
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
export declare const techdocsStorageApiRef: ApiRef<TechDocsStorageApi>;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Hook for use within TechDocs addons that provides access to the underlying
|
|
199
|
+
* shadow root of the current page, allowing the DOM within to be mutated.
|
|
200
|
+
* @public
|
|
201
|
+
*/
|
|
202
|
+
export declare const useShadowRoot: () => ShadowRoot | undefined;
|
|
113
203
|
|
|
114
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Convenience hook for use within TechDocs addons that provides access to
|
|
206
|
+
* elements that match a given selector within the shadow root.
|
|
207
|
+
*
|
|
208
|
+
* @public
|
|
209
|
+
*/
|
|
210
|
+
export declare const useShadowRootElements: <TReturnedElement extends HTMLElement = HTMLElement>(selectors: string[]) => TReturnedElement[];
|
|
115
211
|
|
|
116
|
-
|
|
212
|
+
/**
|
|
213
|
+
* Hook for retreiving a selection within the ShadowRoot.
|
|
214
|
+
* @public
|
|
215
|
+
*/
|
|
216
|
+
export declare const useShadowRootSelection: (wait?: number) => Selection | null;
|
|
117
217
|
|
|
118
|
-
|
|
218
|
+
/**
|
|
219
|
+
* hook to use addons in components
|
|
220
|
+
* @public
|
|
221
|
+
*/
|
|
222
|
+
export declare const useTechDocsAddons: () => {
|
|
223
|
+
renderComponentByName: (name: string) => JSX.Element | null;
|
|
224
|
+
renderComponentsByLocation: (location: keyof typeof TechDocsAddonLocations) => (JSX.Element | null)[] | null;
|
|
225
|
+
};
|
|
119
226
|
|
|
120
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Hook used to get access to shared state between reader page components.
|
|
229
|
+
* @public
|
|
230
|
+
*/
|
|
231
|
+
export declare const useTechDocsReaderPage: () => TechDocsReaderPageValue;
|
|
121
232
|
|
|
122
233
|
export { }
|
package/dist/index.esm.js
CHANGED
|
@@ -70,6 +70,9 @@ const useTechDocsAddons = () => {
|
|
|
70
70
|
const techdocsApiRef = createApiRef({
|
|
71
71
|
id: "plugin.techdocs.service"
|
|
72
72
|
});
|
|
73
|
+
const techdocsStorageApiRef = createApiRef({
|
|
74
|
+
id: "plugin.techdocs.storageservice"
|
|
75
|
+
});
|
|
73
76
|
|
|
74
77
|
const areEntityRefsEqual = (prevEntityRef, nextEntityRef) => {
|
|
75
78
|
return stringifyEntityRef(prevEntityRef) === stringifyEntityRef(nextEntityRef);
|
|
@@ -164,10 +167,11 @@ const useShadowRootSelection = (wait = 0) => {
|
|
|
164
167
|
const TechDocsAddonLocations = Object.freeze({
|
|
165
168
|
Header: "Header",
|
|
166
169
|
Subheader: "Subheader",
|
|
170
|
+
Settings: "Settings",
|
|
167
171
|
PrimarySidebar: "PrimarySidebar",
|
|
168
172
|
SecondarySidebar: "SecondarySidebar",
|
|
169
173
|
Content: "Content"
|
|
170
174
|
});
|
|
171
175
|
|
|
172
|
-
export { TECHDOCS_ADDONS_WRAPPER_KEY, TechDocsAddonLocations, TechDocsAddons, TechDocsReaderPageProvider, createTechDocsAddonExtension,
|
|
176
|
+
export { TECHDOCS_ADDONS_WRAPPER_KEY, TechDocsAddonLocations, TechDocsAddons, TechDocsReaderPageProvider, createTechDocsAddonExtension, techdocsApiRef, techdocsStorageApiRef, useShadowRoot, useShadowRootElements, useShadowRootSelection, useTechDocsAddons, useTechDocsReaderPage };
|
|
173
177
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/addons.tsx","../src/api.ts","../src/context.tsx","../src/hooks.ts","../src/types.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useCallback } from 'react';\nimport { useOutlet } from 'react-router-dom';\n\nimport {\n attachComponentData,\n createReactExtension,\n ElementCollection,\n Extension,\n useElementFilter,\n} from '@backstage/core-plugin-api';\n\nimport { TechDocsAddonLocations, TechDocsAddonOptions } from './types';\n\nexport const TECHDOCS_ADDONS_KEY = 'techdocs.addons.addon.v1';\n\n/**\n * Marks the <TechDocsAddons> registry component.\n * @alpha\n */\nexport const TECHDOCS_ADDONS_WRAPPER_KEY = 'techdocs.addons.wrapper.v1';\n\n/**\n * TechDocs Addon registry.\n * @alpha\n */\nexport const TechDocsAddons: React.ComponentType = () => null;\n\nattachComponentData(TechDocsAddons, TECHDOCS_ADDONS_WRAPPER_KEY, true);\n\nconst getDataKeyByName = (name: string) => {\n return `${TECHDOCS_ADDONS_KEY}.${name.toLocaleLowerCase('en-US')}`;\n};\n\n/**\n * Create a TechDocs addon.\n * @alpha\n */\nexport function createTechDocsAddonExtension<TComponentProps>(\n options: TechDocsAddonOptions<TComponentProps>,\n): Extension<(props: TComponentProps) => JSX.Element | null> {\n const { name, component: TechDocsAddon } = options;\n return createReactExtension({\n name,\n component: {\n sync: (props: TComponentProps) => <TechDocsAddon {...props} />,\n },\n data: {\n [TECHDOCS_ADDONS_KEY]: options,\n [getDataKeyByName(name)]: true,\n },\n });\n}\n\nconst getTechDocsAddonByName = (\n collection: ElementCollection,\n key: string,\n): JSX.Element | undefined => {\n return collection.selectByComponentData({ key }).getElements()[0];\n};\n\nconst getAllTechDocsAddons = (collection: ElementCollection) => {\n return collection\n .selectByComponentData({\n key: TECHDOCS_ADDONS_WRAPPER_KEY,\n })\n .selectByComponentData({\n key: TECHDOCS_ADDONS_KEY,\n });\n};\n\nconst getAllTechDocsAddonsData = (collection: ElementCollection) => {\n return collection\n .selectByComponentData({\n key: TECHDOCS_ADDONS_WRAPPER_KEY,\n })\n .findComponentData<TechDocsAddonOptions>({\n key: TECHDOCS_ADDONS_KEY,\n });\n};\n\n/**\n * hook to use addons in components\n * @alpha\n */\nexport const useTechDocsAddons = () => {\n const node = useOutlet();\n const collection = useElementFilter(node, getAllTechDocsAddons);\n const options = useElementFilter(node, getAllTechDocsAddonsData);\n\n const findAddonByData = useCallback(\n (data: TechDocsAddonOptions | undefined) => {\n if (!collection || !data) return null;\n const nameKey = getDataKeyByName(data.name);\n return getTechDocsAddonByName(collection, nameKey) ?? null;\n },\n [collection],\n );\n\n const renderComponentByName = useCallback(\n (name: string) => {\n const data = options.find(option => option.name === name);\n return data ? findAddonByData(data) : null;\n },\n [options, findAddonByData],\n );\n\n const renderComponentsByLocation = useCallback(\n (location: keyof typeof TechDocsAddonLocations) => {\n const data = options.filter(option => option.location === location);\n return data.length ? data.map(findAddonByData) : null;\n },\n [options, findAddonByData],\n );\n\n return { renderComponentByName, renderComponentsByLocation };\n};\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CompoundEntityRef } from '@backstage/catalog-model';\nimport { createApiRef } from '@backstage/core-plugin-api';\nimport { TechDocsEntityMetadata, TechDocsMetadata } from './types';\n\n/**\n * API to talk to techdocs-backend.\n *\n * @public\n */\nexport interface TechDocsApi {\n getApiOrigin(): Promise<string>;\n getTechDocsMetadata(entityId: CompoundEntityRef): Promise<TechDocsMetadata>;\n getEntityMetadata(\n entityId: CompoundEntityRef,\n ): Promise<TechDocsEntityMetadata>;\n}\n\n/**\n * Utility API reference for the {@link TechDocsApi}.\n *\n * @public\n */\nexport const techdocsApiRef = createApiRef<TechDocsApi>({\n id: 'plugin.techdocs.service',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, {\n Dispatch,\n SetStateAction,\n useContext,\n useState,\n memo,\n ReactNode,\n} from 'react';\nimport useAsync, { AsyncState } from 'react-use/lib/useAsync';\n\nimport {\n CompoundEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport {\n createVersionedContext,\n createVersionedValueMap,\n} from '@backstage/version-bridge';\n\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { techdocsApiRef } from './api';\nimport { TechDocsEntityMetadata, TechDocsMetadata } from './types';\n\nconst areEntityRefsEqual = (\n prevEntityRef: CompoundEntityRef,\n nextEntityRef: CompoundEntityRef,\n) => {\n return (\n stringifyEntityRef(prevEntityRef) === stringifyEntityRef(nextEntityRef)\n );\n};\n\n/**\n * @public type for the value of the TechDocsReaderPageContext\n */\nexport type TechDocsReaderPageValue = {\n metadata: AsyncState<TechDocsMetadata>;\n entityRef: CompoundEntityRef;\n entityMetadata: AsyncState<TechDocsEntityMetadata>;\n shadowRoot?: ShadowRoot;\n setShadowRoot: Dispatch<SetStateAction<ShadowRoot | undefined>>;\n title: string;\n setTitle: Dispatch<SetStateAction<string>>;\n subtitle: string;\n setSubtitle: Dispatch<SetStateAction<string>>;\n /**\n * @deprecated property can be passed down directly to the `TechDocsReaderPageContent` instead.\n */\n onReady?: () => void;\n};\n\n/**\n * @alpha\n */\nexport const defaultTechDocsReaderPageValue: TechDocsReaderPageValue = {\n title: '',\n subtitle: '',\n setTitle: () => {},\n setSubtitle: () => {},\n setShadowRoot: () => {},\n metadata: { loading: true },\n entityMetadata: { loading: true },\n entityRef: { kind: '', name: '', namespace: '' },\n};\n\nconst TechDocsReaderPageContext = createVersionedContext<{\n 1: TechDocsReaderPageValue;\n}>('techdocs-reader-page-context');\n\n/**\n * render function for {@link TechDocsReaderPageProvider}\n *\n * @public\n */\nexport type TechDocsReaderPageProviderRenderFunction = (\n value: TechDocsReaderPageValue,\n) => JSX.Element;\n\n/**\n * Props for {@link TechDocsReaderPageProvider}\n *\n * @public\n */\nexport type TechDocsReaderPageProviderProps = {\n entityRef: CompoundEntityRef;\n children: TechDocsReaderPageProviderRenderFunction | ReactNode;\n};\n\n/**\n * A context to store the reader page state\n * @public\n */\nexport const TechDocsReaderPageProvider = memo(\n ({ entityRef, children }: TechDocsReaderPageProviderProps) => {\n const techdocsApi = useApi(techdocsApiRef);\n\n const metadata = useAsync(async () => {\n return techdocsApi.getTechDocsMetadata(entityRef);\n }, [entityRef]);\n\n const entityMetadata = useAsync(async () => {\n return techdocsApi.getEntityMetadata(entityRef);\n }, [entityRef]);\n\n const [title, setTitle] = useState(defaultTechDocsReaderPageValue.title);\n const [subtitle, setSubtitle] = useState(\n defaultTechDocsReaderPageValue.subtitle,\n );\n const [shadowRoot, setShadowRoot] = useState<ShadowRoot | undefined>(\n defaultTechDocsReaderPageValue.shadowRoot,\n );\n\n const value = {\n metadata,\n entityRef,\n entityMetadata,\n shadowRoot,\n setShadowRoot,\n title,\n setTitle,\n subtitle,\n setSubtitle,\n };\n const versionedValue = createVersionedValueMap({ 1: value });\n\n return (\n <TechDocsReaderPageContext.Provider value={versionedValue}>\n {children instanceof Function ? children(value) : children}\n </TechDocsReaderPageContext.Provider>\n );\n },\n (prevProps, nextProps) => {\n return areEntityRefsEqual(prevProps.entityRef, nextProps.entityRef);\n },\n);\n\n/**\n * Hook used to get access to shared state between reader page components.\n * @alpha\n */\nexport const useTechDocsReaderPage = () => {\n const versionedContext = useContext(TechDocsReaderPageContext);\n\n if (versionedContext === undefined) {\n return defaultTechDocsReaderPageValue;\n }\n\n const context = versionedContext.atVersion(1);\n if (context === undefined) {\n throw new Error('No context found for version 1.');\n }\n\n return context;\n};\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useState, useEffect, useMemo } from 'react';\nimport debounce from 'lodash/debounce';\nimport { useTechDocsReaderPage } from './context';\n\n/**\n * Hook for use within TechDocs addons that provides access to the underlying\n * shadow root of the current page, allowing the DOM within to be mutated.\n * @alpha\n */\nexport const useShadowRoot = () => {\n const { shadowRoot } = useTechDocsReaderPage();\n return shadowRoot;\n};\n\n/**\n * Convenience hook for use within TechDocs addons that provides access to\n * elements that match a given selector within the shadow root.\n *\n * @alpha\n */\nexport const useShadowRootElements = <\n TReturnedElement extends HTMLElement = HTMLElement,\n>(\n selectors: string[],\n): TReturnedElement[] => {\n const shadowRoot = useShadowRoot();\n if (!shadowRoot) return [];\n return selectors\n .map(selector => shadowRoot?.querySelectorAll<TReturnedElement>(selector))\n .filter(nodeList => nodeList.length)\n .map(nodeList => Array.from(nodeList))\n .flat();\n};\n\nconst isValidSelection = (newSelection: Selection) => {\n // Safari sets the selection rect to top zero\n return (\n newSelection.toString() &&\n newSelection.rangeCount &&\n newSelection.getRangeAt(0).getBoundingClientRect().top\n );\n};\n\n/**\n * Hook for retreiving a selection within the ShadowRoot.\n * @alpha\n */\nexport const useShadowRootSelection = (wait: number = 0) => {\n const shadowRoot = useShadowRoot();\n const [selection, setSelection] = useState<Selection | null>(null);\n const handleSelectionChange = useMemo(\n () =>\n debounce(() => {\n const shadowDocument = shadowRoot as ShadowRoot &\n Pick<Document, 'getSelection'>;\n // Firefox and Safari don't implement getSelection for Shadow DOM\n const newSelection = shadowDocument.getSelection\n ? shadowDocument.getSelection()\n : document.getSelection();\n\n if (newSelection && isValidSelection(newSelection)) {\n setSelection(newSelection);\n } else {\n setSelection(null);\n }\n }, wait),\n [shadowRoot, setSelection, wait],\n );\n\n useEffect(() => {\n window.document.addEventListener('selectionchange', handleSelectionChange);\n return () =>\n window.document.removeEventListener(\n 'selectionchange',\n handleSelectionChange,\n );\n }, [handleSelectionChange]);\n\n return selection;\n};\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ComponentType } from 'react';\nimport { Entity } from '@backstage/catalog-model';\n\n/**\n * Metadata for TechDocs page\n *\n * @public\n */\nexport type TechDocsMetadata = {\n site_name: string;\n site_description: string;\n};\n\n/**\n * Metadata for TechDocs Entity\n *\n * @public\n */\nexport type TechDocsEntityMetadata = Entity & {\n locationMetadata?: { type: string; target: string };\n};\n\n/**\n * Locations for which TechDocs addons may be declared and rendered.\n * @alpha\n */\nexport const TechDocsAddonLocations = Object.freeze({\n /**\n * These addons fill up the header from the right, on the same line as the\n * title.\n */\n Header: 'Header',\n\n /**\n * These addons appear below the header and above all content; tooling addons\n * can be inserted for convenience.\n */\n Subheader: 'Subheader',\n\n /**\n * These addons appear left of the content and above the navigation.\n */\n PrimarySidebar: 'PrimarySidebar',\n\n /**\n * These addons appear right of the content and above the table of contents.\n */\n SecondarySidebar: 'SecondarySidebar',\n\n /**\n * A virtual location which allows mutation of all content within the shadow\n * root by transforming DOM nodes. These addons should return null on render.\n */\n Content: 'Content',\n\n /**\n * todo(backstage/community): This is a proposed virtual location which would\n * help implement a common addon pattern in which many instances of a given\n * element in markdown would be dynamically replaced at render-time based on\n * attributes provided on that element, for example:\n *\n * ```md\n * ## For Fun\n * <TechDocsAddon>CatGif</TechDocsAddon>\n *\n * ## Component Metadata\n * <TechDocsAddon entityRef=\"default:component/some-component-name\">CatalogEntityCard</TechDocsAddon>\n *\n * ## System Metadata\n * <TechDocsAddon entityRef=\"default:system/some-system-name\">CatalogEntityCard</TechDocsAddon>\n * ```\n *\n * Could correspond to a TechDocs addon named `CatalogEntityCard` with\n * location `TechDocsAddonLocations.COMPONENT`, whose `component` would be\n * the react component that would be rendered in place of all instances of\n * the markdown illustrated above.\n *\n * The `@backstage/plugin-techdocs-react` package would need to be updated to, in\n * cases where such addons had been registered, find all instances of the\n * the `<TechDocsAddon>` tag whose `textContent` corresponded with the name of the\n * addon, then replace them with component instances of the addon component,\n * passing any attributes from the tag as props to the component.\n */\n // Component: 'Component',\n} as const);\n\n/**\n * Options for creating a TechDocs addon.\n * @alpha\n */\nexport type TechDocsAddonOptions<TAddonProps = {}> = {\n name: string;\n location: keyof typeof TechDocsAddonLocations;\n component: ComponentType<TAddonProps>;\n};\n"],"names":[],"mappings":";;;;;;;;AAOO,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AAClD,MAAC,2BAA2B,GAAG,6BAA6B;AAC5D,MAAC,cAAc,GAAG,MAAM,KAAK;AACzC,mBAAmB,CAAC,cAAc,EAAE,2BAA2B,EAAE,IAAI,CAAC,CAAC;AACvE,MAAM,gBAAgB,GAAG,CAAC,IAAI,KAAK;AACnC,EAAE,OAAO,CAAC,EAAE,mBAAmB,CAAC,CAAC,EAAE,IAAI,CAAC,iBAAi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nD,EAAE,MAAM,qBAAqB,GAAG,OAAO,CAAC,MAAM,QAAQ,CAAC,MAAM;AAC7D,IAAI,MAAM,cAAc,GAAG,UAAU,CAAC;AACtC,IAAI,MAAM,YAAY,GAAG,cAAc,CAAC,YAAY,GAAG,cAAc,CAAC,YAAY,EAAE,GAAG,QAAQ,CAAC,YAAY,EAAE,CAAC;AAC/G,IAAI,IAAI,YAAY,IAAI,gBAAgB,CAAC,YAAY,CAAC,EAAE;AACxD,MAAM,YAAY,CAAC,YAAY,CAAC,CAAC;AACjC,KAAK,MAAM;AACX,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;AACzB,KAAK;AACL,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,UAAU,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;AAC9C,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;AAC/E,IAAI,OAAO,MAAM,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;AAC/F,GAAG,EAAE,CAAC,qBAAqB,CAAC,CAAC,CAAC;AAC9B,EAAE,OAAO,SAAS,CAAC;AACnB;;ACjCY,MAAC,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC;AACpD,EAAE,MAAM,EAAE,QAAQ;AAClB,EAAE,SAAS,EAAE,WAAW;AACxB,EAAE,cAAc,EAAE,gBAAgB;AAClC,EAAE,gBAAgB,EAAE,kBAAkB;AACtC,EAAE,OAAO,EAAE,SAAS;AACpB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/addons.tsx","../src/api.ts","../src/context.tsx","../src/hooks.ts","../src/types.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useCallback } from 'react';\nimport { useOutlet } from 'react-router-dom';\n\nimport {\n attachComponentData,\n createReactExtension,\n ElementCollection,\n Extension,\n useElementFilter,\n} from '@backstage/core-plugin-api';\n\nimport { TechDocsAddonLocations, TechDocsAddonOptions } from './types';\n\nexport const TECHDOCS_ADDONS_KEY = 'techdocs.addons.addon.v1';\n\n/**\n * Marks the <TechDocsAddons> registry component.\n * @public\n */\nexport const TECHDOCS_ADDONS_WRAPPER_KEY = 'techdocs.addons.wrapper.v1';\n\n/**\n * TechDocs Addon registry.\n * @public\n */\nexport const TechDocsAddons: React.ComponentType = () => null;\n\nattachComponentData(TechDocsAddons, TECHDOCS_ADDONS_WRAPPER_KEY, true);\n\nconst getDataKeyByName = (name: string) => {\n return `${TECHDOCS_ADDONS_KEY}.${name.toLocaleLowerCase('en-US')}`;\n};\n\n/**\n * Create a TechDocs addon overload signature without props.\n * @public\n */\nexport function createTechDocsAddonExtension(\n options: TechDocsAddonOptions,\n): Extension<() => JSX.Element | null>;\n\n/**\n * Create a TechDocs addon overload signature with props.\n * @public\n */\nexport function createTechDocsAddonExtension<TComponentProps>(\n options: TechDocsAddonOptions<TComponentProps>,\n): Extension<(props: TComponentProps) => JSX.Element | null>;\n\n/**\n * Create a TechDocs addon implementation.\n * @public\n */\nexport function createTechDocsAddonExtension<TComponentProps>(\n options: TechDocsAddonOptions<TComponentProps>,\n): Extension<(props: TComponentProps) => JSX.Element | null> {\n const { name, component: TechDocsAddon } = options;\n return createReactExtension({\n name,\n component: {\n sync: (props: TComponentProps) => <TechDocsAddon {...props} />,\n },\n data: {\n [TECHDOCS_ADDONS_KEY]: options,\n [getDataKeyByName(name)]: true,\n },\n });\n}\n\nconst getTechDocsAddonByName = (\n collection: ElementCollection,\n key: string,\n): JSX.Element | undefined => {\n return collection.selectByComponentData({ key }).getElements()[0];\n};\n\nconst getAllTechDocsAddons = (collection: ElementCollection) => {\n return collection\n .selectByComponentData({\n key: TECHDOCS_ADDONS_WRAPPER_KEY,\n })\n .selectByComponentData({\n key: TECHDOCS_ADDONS_KEY,\n });\n};\n\nconst getAllTechDocsAddonsData = (collection: ElementCollection) => {\n return collection\n .selectByComponentData({\n key: TECHDOCS_ADDONS_WRAPPER_KEY,\n })\n .findComponentData<TechDocsAddonOptions>({\n key: TECHDOCS_ADDONS_KEY,\n });\n};\n\n/**\n * hook to use addons in components\n * @public\n */\nexport const useTechDocsAddons = () => {\n const node = useOutlet();\n const collection = useElementFilter(node, getAllTechDocsAddons);\n const options = useElementFilter(node, getAllTechDocsAddonsData);\n\n const findAddonByData = useCallback(\n (data: TechDocsAddonOptions | undefined) => {\n if (!collection || !data) return null;\n const nameKey = getDataKeyByName(data.name);\n return getTechDocsAddonByName(collection, nameKey) ?? null;\n },\n [collection],\n );\n\n const renderComponentByName = useCallback(\n (name: string) => {\n const data = options.find(option => option.name === name);\n return data ? findAddonByData(data) : null;\n },\n [options, findAddonByData],\n );\n\n const renderComponentsByLocation = useCallback(\n (location: keyof typeof TechDocsAddonLocations) => {\n const data = options.filter(option => option.location === location);\n return data.length ? data.map(findAddonByData) : null;\n },\n [options, findAddonByData],\n );\n\n return { renderComponentByName, renderComponentsByLocation };\n};\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CompoundEntityRef } from '@backstage/catalog-model';\nimport { createApiRef } from '@backstage/core-plugin-api';\nimport { TechDocsEntityMetadata, TechDocsMetadata } from './types';\n\n/**\n * API to talk to techdocs-backend.\n *\n * @public\n */\nexport interface TechDocsApi {\n getApiOrigin(): Promise<string>;\n getTechDocsMetadata(entityId: CompoundEntityRef): Promise<TechDocsMetadata>;\n getEntityMetadata(\n entityId: CompoundEntityRef,\n ): Promise<TechDocsEntityMetadata>;\n}\n\n/**\n * Utility API reference for the {@link TechDocsApi}.\n *\n * @public\n */\nexport const techdocsApiRef = createApiRef<TechDocsApi>({\n id: 'plugin.techdocs.service',\n});\n\n/**\n * The outcome of a docs sync operation.\n *\n * @public\n */\nexport type SyncResult = 'cached' | 'updated';\n\n/**\n * API which talks to TechDocs storage to fetch files to render.\n *\n * @public\n */\nexport interface TechDocsStorageApi {\n getApiOrigin(): Promise<string>;\n getStorageUrl(): Promise<string>;\n getBuilder(): Promise<string>;\n getEntityDocs(entityId: CompoundEntityRef, path: string): Promise<string>;\n syncEntityDocs(\n entityId: CompoundEntityRef,\n logHandler?: (line: string) => void,\n ): Promise<SyncResult>;\n getBaseUrl(\n oldBaseUrl: string,\n entityId: CompoundEntityRef,\n path: string,\n ): Promise<string>;\n}\n\n/**\n * Utility API reference for the {@link TechDocsStorageApi}.\n *\n * @public\n */\nexport const techdocsStorageApiRef = createApiRef<TechDocsStorageApi>({\n id: 'plugin.techdocs.storageservice',\n});\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, {\n Dispatch,\n SetStateAction,\n useContext,\n useState,\n memo,\n ReactNode,\n} from 'react';\nimport useAsync, { AsyncState } from 'react-use/lib/useAsync';\n\nimport {\n CompoundEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport {\n createVersionedContext,\n createVersionedValueMap,\n} from '@backstage/version-bridge';\n\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { techdocsApiRef } from './api';\nimport { TechDocsEntityMetadata, TechDocsMetadata } from './types';\n\nconst areEntityRefsEqual = (\n prevEntityRef: CompoundEntityRef,\n nextEntityRef: CompoundEntityRef,\n) => {\n return (\n stringifyEntityRef(prevEntityRef) === stringifyEntityRef(nextEntityRef)\n );\n};\n\n/**\n * @public type for the value of the TechDocsReaderPageContext\n */\nexport type TechDocsReaderPageValue = {\n metadata: AsyncState<TechDocsMetadata>;\n entityRef: CompoundEntityRef;\n entityMetadata: AsyncState<TechDocsEntityMetadata>;\n shadowRoot?: ShadowRoot;\n setShadowRoot: Dispatch<SetStateAction<ShadowRoot | undefined>>;\n title: string;\n setTitle: Dispatch<SetStateAction<string>>;\n subtitle: string;\n setSubtitle: Dispatch<SetStateAction<string>>;\n /**\n * @deprecated property can be passed down directly to the `TechDocsReaderPageContent` instead.\n */\n onReady?: () => void;\n};\n\nconst defaultTechDocsReaderPageValue: TechDocsReaderPageValue = {\n title: '',\n subtitle: '',\n setTitle: () => {},\n setSubtitle: () => {},\n setShadowRoot: () => {},\n metadata: { loading: true },\n entityMetadata: { loading: true },\n entityRef: { kind: '', name: '', namespace: '' },\n};\n\nconst TechDocsReaderPageContext = createVersionedContext<{\n 1: TechDocsReaderPageValue;\n}>('techdocs-reader-page-context');\n\n/**\n * render function for {@link TechDocsReaderPageProvider}\n *\n * @public\n */\nexport type TechDocsReaderPageProviderRenderFunction = (\n value: TechDocsReaderPageValue,\n) => JSX.Element;\n\n/**\n * Props for {@link TechDocsReaderPageProvider}\n *\n * @public\n */\nexport type TechDocsReaderPageProviderProps = {\n entityRef: CompoundEntityRef;\n children: TechDocsReaderPageProviderRenderFunction | ReactNode;\n};\n\n/**\n * A context to store the reader page state\n * @public\n */\nexport const TechDocsReaderPageProvider = memo(\n ({ entityRef, children }: TechDocsReaderPageProviderProps) => {\n const techdocsApi = useApi(techdocsApiRef);\n\n const metadata = useAsync(async () => {\n return techdocsApi.getTechDocsMetadata(entityRef);\n }, [entityRef]);\n\n const entityMetadata = useAsync(async () => {\n return techdocsApi.getEntityMetadata(entityRef);\n }, [entityRef]);\n\n const [title, setTitle] = useState(defaultTechDocsReaderPageValue.title);\n const [subtitle, setSubtitle] = useState(\n defaultTechDocsReaderPageValue.subtitle,\n );\n const [shadowRoot, setShadowRoot] = useState<ShadowRoot | undefined>(\n defaultTechDocsReaderPageValue.shadowRoot,\n );\n\n const value = {\n metadata,\n entityRef,\n entityMetadata,\n shadowRoot,\n setShadowRoot,\n title,\n setTitle,\n subtitle,\n setSubtitle,\n };\n const versionedValue = createVersionedValueMap({ 1: value });\n\n return (\n <TechDocsReaderPageContext.Provider value={versionedValue}>\n {children instanceof Function ? children(value) : children}\n </TechDocsReaderPageContext.Provider>\n );\n },\n (prevProps, nextProps) => {\n return areEntityRefsEqual(prevProps.entityRef, nextProps.entityRef);\n },\n);\n\n/**\n * Hook used to get access to shared state between reader page components.\n * @public\n */\nexport const useTechDocsReaderPage = () => {\n const versionedContext = useContext(TechDocsReaderPageContext);\n\n if (versionedContext === undefined) {\n return defaultTechDocsReaderPageValue;\n }\n\n const context = versionedContext.atVersion(1);\n if (context === undefined) {\n throw new Error('No context found for version 1.');\n }\n\n return context;\n};\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useState, useEffect, useMemo } from 'react';\nimport debounce from 'lodash/debounce';\nimport { useTechDocsReaderPage } from './context';\n\n/**\n * Hook for use within TechDocs addons that provides access to the underlying\n * shadow root of the current page, allowing the DOM within to be mutated.\n * @public\n */\nexport const useShadowRoot = () => {\n const { shadowRoot } = useTechDocsReaderPage();\n return shadowRoot;\n};\n\n/**\n * Convenience hook for use within TechDocs addons that provides access to\n * elements that match a given selector within the shadow root.\n *\n * @public\n */\nexport const useShadowRootElements = <\n TReturnedElement extends HTMLElement = HTMLElement,\n>(\n selectors: string[],\n): TReturnedElement[] => {\n const shadowRoot = useShadowRoot();\n if (!shadowRoot) return [];\n return selectors\n .map(selector => shadowRoot?.querySelectorAll<TReturnedElement>(selector))\n .filter(nodeList => nodeList.length)\n .map(nodeList => Array.from(nodeList))\n .flat();\n};\n\nconst isValidSelection = (newSelection: Selection) => {\n // Safari sets the selection rect to top zero\n return (\n newSelection.toString() &&\n newSelection.rangeCount &&\n newSelection.getRangeAt(0).getBoundingClientRect().top\n );\n};\n\n/**\n * Hook for retreiving a selection within the ShadowRoot.\n * @public\n */\nexport const useShadowRootSelection = (wait: number = 0) => {\n const shadowRoot = useShadowRoot();\n const [selection, setSelection] = useState<Selection | null>(null);\n const handleSelectionChange = useMemo(\n () =>\n debounce(() => {\n const shadowDocument = shadowRoot as ShadowRoot &\n Pick<Document, 'getSelection'>;\n // Firefox and Safari don't implement getSelection for Shadow DOM\n const newSelection = shadowDocument.getSelection\n ? shadowDocument.getSelection()\n : document.getSelection();\n\n if (newSelection && isValidSelection(newSelection)) {\n setSelection(newSelection);\n } else {\n setSelection(null);\n }\n }, wait),\n [shadowRoot, setSelection, wait],\n );\n\n useEffect(() => {\n window.document.addEventListener('selectionchange', handleSelectionChange);\n return () =>\n window.document.removeEventListener(\n 'selectionchange',\n handleSelectionChange,\n );\n }, [handleSelectionChange]);\n\n return selection;\n};\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ComponentType } from 'react';\nimport { Entity } from '@backstage/catalog-model';\n\n/**\n * Metadata for TechDocs page\n *\n * @public\n */\nexport type TechDocsMetadata = {\n site_name: string;\n site_description: string;\n};\n\n/**\n * Metadata for TechDocs Entity\n *\n * @public\n */\nexport type TechDocsEntityMetadata = Entity & {\n locationMetadata?: { type: string; target: string };\n};\n\n/**\n * Locations for which TechDocs addons may be declared and rendered.\n * @public\n */\nexport const TechDocsAddonLocations = Object.freeze({\n /**\n * These addons fill up the header from the right, on the same line as the\n * title.\n */\n Header: 'Header',\n\n /**\n * These addons appear below the header and above all content; tooling addons\n * can be inserted for convenience.\n */\n Subheader: 'Subheader',\n\n /**\n * These addons are items added to the settings menu list and are designed to make\n * the reader experience customizable, for example accessibility options\n */\n Settings: 'Settings',\n\n /**\n * These addons appear left of the content and above the navigation.\n */\n PrimarySidebar: 'PrimarySidebar',\n\n /**\n * These addons appear right of the content and above the table of contents.\n */\n SecondarySidebar: 'SecondarySidebar',\n\n /**\n * A virtual location which allows mutation of all content within the shadow\n * root by transforming DOM nodes. These addons should return null on render.\n */\n Content: 'Content',\n\n /**\n * todo(backstage/community): This is a proposed virtual location which would\n * help implement a common addon pattern in which many instances of a given\n * element in markdown would be dynamically replaced at render-time based on\n * attributes provided on that element, for example:\n *\n * ```md\n * ## For Fun\n * <TechDocsAddon>CatGif</TechDocsAddon>\n *\n * ## Component Metadata\n * <TechDocsAddon entityRef=\"default:component/some-component-name\">CatalogEntityCard</TechDocsAddon>\n *\n * ## System Metadata\n * <TechDocsAddon entityRef=\"default:system/some-system-name\">CatalogEntityCard</TechDocsAddon>\n * ```\n *\n * Could correspond to a TechDocs addon named `CatalogEntityCard` with\n * location `TechDocsAddonLocations.COMPONENT`, whose `component` would be\n * the react component that would be rendered in place of all instances of\n * the markdown illustrated above.\n *\n * The `@backstage/plugin-techdocs-react` package would need to be updated to, in\n * cases where such addons had been registered, find all instances of the\n * the `<TechDocsAddon>` tag whose `textContent` corresponded with the name of the\n * addon, then replace them with component instances of the addon component,\n * passing any attributes from the tag as props to the component.\n */\n // Component: 'Component',\n} as const);\n\n/**\n * Options for creating a TechDocs addon.\n * @public\n */\nexport type TechDocsAddonOptions<TAddonProps = {}> = {\n name: string;\n location: keyof typeof TechDocsAddonLocations;\n component: ComponentType<TAddonProps>;\n};\n"],"names":[],"mappings":";;;;;;;;AAOO,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AAClD,MAAC,2BAA2B,GAAG,6BAA6B;AAC5D,MAAC,cAAc,GAAG,MAAM,KAAK;AACzC,mBAAmB,CAAC,cAAc,EAAE,2BAA2B,EAAE,IAAI,CAAC,CAAC;AACvE,MAAM,gBAAgB,GAAG,CAAC,IAAI,KAAK;AACnC,EAAE,OAAO,CAAC,EAAE,mBAAmB,CAAC,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC,CAAC;AACK,SAAS,4BAA4B,CAAC,OAAO,EAAE;AACtD,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;AACrD,EAAE,OAAO,oBAAoB,CAAC;AAC9B,IAAI,IAAI;AACR,IAAI,SAAS,EAAE;AACf,MAAM,IAAI,EAAE,CAAC,KAAK,qBAAqB,KAAK,CAAC,aAAa,CAAC,aAAa,EAAE;AAC1E,QAAQ,GAAG,KAAK;AAChB,OAAO,CAAC;AACR,KAAK;AACL,IAAI,IAAI,EAAE;AACV,MAAM,CAAC,mBAAmB,GAAG,OAAO;AACpC,MAAM,CAAC,gBAAgB,CAAC,IAAI,CA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;AACzB,KAAK;AACL,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,UAAU,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;AAC9C,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;AAC/E,IAAI,OAAO,MAAM,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;AAC/F,GAAG,EAAE,CAAC,qBAAqB,CAAC,CAAC,CAAC;AAC9B,EAAE,OAAO,SAAS,CAAC;AACnB;;ACjCY,MAAC,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC;AACpD,EAAE,MAAM,EAAE,QAAQ;AAClB,EAAE,SAAS,EAAE,WAAW;AACxB,EAAE,QAAQ,EAAE,UAAU;AACtB,EAAE,cAAc,EAAE,gBAAgB;AAClC,EAAE,gBAAgB,EAAE,kBAAkB;AACtC,EAAE,OAAO,EAAE,SAAS;AACpB,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-techdocs-react",
|
|
3
3
|
"description": "Shared frontend utilities for TechDocs and Addons",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"start": "backstage-cli package start"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@backstage/catalog-model": "^1.0.
|
|
39
|
-
"@backstage/core-components": "^0.9.
|
|
40
|
-
"@backstage/core-plugin-api": "^1.0.
|
|
38
|
+
"@backstage/catalog-model": "^1.0.2",
|
|
39
|
+
"@backstage/core-components": "^0.9.4",
|
|
40
|
+
"@backstage/core-plugin-api": "^1.0.2",
|
|
41
41
|
"@backstage/version-bridge": "^1.0.1",
|
|
42
42
|
"@material-ui/core": "^4.12.2",
|
|
43
43
|
"@material-ui/lab": "4.0.0-alpha.57",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"react": "^16.13.1 || ^17.0.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@backstage/test-utils": "^1.
|
|
56
|
+
"@backstage/test-utils": "^1.1.0",
|
|
57
57
|
"@backstage/theme": "^0.2.15",
|
|
58
58
|
"@testing-library/react": "^12.1.3",
|
|
59
59
|
"@testing-library/react-hooks": "^8.0.0"
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"alpha",
|
|
63
63
|
"dist"
|
|
64
64
|
],
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "96323f280ba32ee526c5b151cda42260aee927c9"
|
|
66
66
|
}
|