@jpmorganchase/elemental 6.0.2 → 7.0.1
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/components/API/APIWithResponsiveSidebarLayout.d.ts +19 -0
- package/components/API/APIWithSidebarLayout.d.ts +11 -1
- package/components/API/APIWithStackedLayout.d.ts +11 -0
- package/components/API/utils.d.ts +7 -6
- package/containers/API.d.ts +4 -1
- package/containers/API.stories.d.ts +2 -0
- package/containers/story-helper.d.ts +2 -0
- package/index.d.ts +2 -0
- package/index.esm.js +222 -115
- package/index.js +222 -114
- package/index.mjs +222 -115
- package/package.json +7 -7
- package/styles.min.css +1 -1
- package/utils/oas/types.d.ts +5 -2
- package/web-components.min.js +1 -1
package/index.js
CHANGED
@@ -4,15 +4,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
5
5
|
var elementalCore = require('@jpmorganchase/elemental-core');
|
6
6
|
var mosaic = require('@stoplight/mosaic');
|
7
|
-
var
|
7
|
+
var types = require('@stoplight/types');
|
8
|
+
var cn = require('classnames');
|
8
9
|
var React = require('react');
|
10
|
+
var defaults = require('lodash/defaults.js');
|
11
|
+
var flow = require('lodash/flow.js');
|
9
12
|
var reactQuery = require('react-query');
|
10
|
-
var types = require('@stoplight/types');
|
11
13
|
var reactRouterDom = require('react-router-dom');
|
12
|
-
var defaults = require('lodash/defaults.js');
|
13
|
-
var cn = require('classnames');
|
14
14
|
var yaml = require('@stoplight/yaml');
|
15
15
|
var saver = require('file-saver');
|
16
|
+
var oas = require('@stoplight/http-spec/oas');
|
16
17
|
var oas2 = require('@stoplight/http-spec/oas2');
|
17
18
|
var oas3 = require('@stoplight/http-spec/oas3');
|
18
19
|
var json = require('@stoplight/json');
|
@@ -40,22 +41,21 @@ function _interopNamespace(e) {
|
|
40
41
|
return Object.freeze(n);
|
41
42
|
}
|
42
43
|
|
43
|
-
var
|
44
|
+
var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
|
44
45
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
45
46
|
var defaults__default = /*#__PURE__*/_interopDefaultLegacy(defaults);
|
46
|
-
var
|
47
|
+
var flow__default = /*#__PURE__*/_interopDefaultLegacy(flow);
|
47
48
|
var saver__default = /*#__PURE__*/_interopDefaultLegacy(saver);
|
48
49
|
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
|
49
50
|
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
50
51
|
var last__default = /*#__PURE__*/_interopDefaultLegacy(last);
|
51
52
|
|
52
|
-
|
53
|
+
function computeTagGroups(serviceNode, nodeType) {
|
53
54
|
const groupsByTagId = {};
|
54
55
|
const ungrouped = [];
|
55
56
|
const lowerCaseServiceTags = serviceNode.tags.map(tn => tn.toLowerCase());
|
56
|
-
|
57
|
-
|
58
|
-
continue;
|
57
|
+
const groupableNodes = serviceNode.children.filter(n => n.type === nodeType);
|
58
|
+
for (const node of groupableNodes) {
|
59
59
|
const tagName = node.tags[0];
|
60
60
|
if (tagName) {
|
61
61
|
const tagId = tagName.toLowerCase();
|
@@ -91,7 +91,7 @@ const computeTagGroups = (serviceNode) => {
|
|
91
91
|
})
|
92
92
|
.map(([, tagGroup]) => tagGroup);
|
93
93
|
return { groups: orderedTagGroups, ungrouped };
|
94
|
-
}
|
94
|
+
}
|
95
95
|
const defaultComputerAPITreeConfig = {
|
96
96
|
hideSchemas: false,
|
97
97
|
hideInternal: false,
|
@@ -106,62 +106,32 @@ const computeAPITree = (serviceNode, config = {}) => {
|
|
106
106
|
type: 'overview',
|
107
107
|
meta: '',
|
108
108
|
});
|
109
|
-
const
|
110
|
-
if (
|
109
|
+
const hasOperationNodes = serviceNode.children.some(node => node.type === types.NodeType.HttpOperation);
|
110
|
+
if (hasOperationNodes) {
|
111
111
|
tree.push({
|
112
112
|
title: 'Endpoints',
|
113
113
|
});
|
114
|
-
const { groups, ungrouped } = computeTagGroups(serviceNode);
|
115
|
-
ungrouped.
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
slug: operationNode.uri,
|
122
|
-
title: operationNode.name,
|
123
|
-
type: operationNode.type,
|
124
|
-
meta: operationNode.data.method,
|
125
|
-
});
|
126
|
-
});
|
127
|
-
groups.forEach(group => {
|
128
|
-
const items = group.items.flatMap(operationNode => {
|
129
|
-
if (mergedConfig.hideInternal && operationNode.data.internal) {
|
130
|
-
return [];
|
131
|
-
}
|
132
|
-
return {
|
133
|
-
id: operationNode.uri,
|
134
|
-
slug: operationNode.uri,
|
135
|
-
title: operationNode.name,
|
136
|
-
type: operationNode.type,
|
137
|
-
meta: operationNode.data.method,
|
138
|
-
};
|
139
|
-
});
|
140
|
-
if (items.length > 0) {
|
141
|
-
tree.push({
|
142
|
-
title: group.title,
|
143
|
-
items,
|
144
|
-
});
|
145
|
-
}
|
114
|
+
const { groups, ungrouped } = computeTagGroups(serviceNode, types.NodeType.HttpOperation);
|
115
|
+
addTagGroupsToTree(groups, ungrouped, tree, types.NodeType.HttpOperation, mergedConfig.hideInternal);
|
116
|
+
}
|
117
|
+
const hasWebhookNodes = serviceNode.children.some(node => node.type === types.NodeType.HttpWebhook);
|
118
|
+
if (hasWebhookNodes) {
|
119
|
+
tree.push({
|
120
|
+
title: 'Webhooks',
|
146
121
|
});
|
122
|
+
const { groups, ungrouped } = computeTagGroups(serviceNode, types.NodeType.HttpWebhook);
|
123
|
+
addTagGroupsToTree(groups, ungrouped, tree, types.NodeType.HttpWebhook, mergedConfig.hideInternal);
|
147
124
|
}
|
148
125
|
let schemaNodes = serviceNode.children.filter(node => node.type === types.NodeType.Model);
|
149
126
|
if (mergedConfig.hideInternal) {
|
150
|
-
schemaNodes = schemaNodes.filter(
|
127
|
+
schemaNodes = schemaNodes.filter(n => !isInternal(n));
|
151
128
|
}
|
152
129
|
if (!mergedConfig.hideSchemas && schemaNodes.length) {
|
153
130
|
tree.push({
|
154
131
|
title: 'Schemas',
|
155
132
|
});
|
156
|
-
|
157
|
-
|
158
|
-
id: node.uri,
|
159
|
-
slug: node.uri,
|
160
|
-
title: node.name,
|
161
|
-
type: node.type,
|
162
|
-
meta: '',
|
163
|
-
});
|
164
|
-
});
|
133
|
+
const { groups, ungrouped } = computeTagGroups(serviceNode, types.NodeType.Model);
|
134
|
+
addTagGroupsToTree(groups, ungrouped, tree, types.NodeType.Model, mergedConfig.hideInternal);
|
165
135
|
}
|
166
136
|
return tree;
|
167
137
|
};
|
@@ -181,52 +151,48 @@ const findFirstNodeSlug = (tree) => {
|
|
181
151
|
};
|
182
152
|
const isInternal = (node) => {
|
183
153
|
const data = node.data;
|
184
|
-
if (elementalCore.isHttpOperation(data)) {
|
154
|
+
if (elementalCore.isHttpOperation(data) || elementalCore.isHttpWebhookOperation(data)) {
|
185
155
|
return !!data.internal;
|
186
156
|
}
|
187
157
|
if (elementalCore.isHttpService(data)) {
|
188
158
|
return false;
|
189
159
|
}
|
190
160
|
return !!data['x-internal'];
|
191
|
-
};
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
if (!useCustomNav)
|
197
|
-
return computeAPITree(serviceNode, { hideSchemas, hideInternal });
|
198
|
-
else
|
199
|
-
return [];
|
200
|
-
}, [serviceNode, hideSchemas, hideInternal, useCustomNav]);
|
201
|
-
const location = reactRouterDom.useLocation();
|
202
|
-
const { pathname } = location;
|
203
|
-
const isRootPath = !pathname || pathname === '/';
|
204
|
-
const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
|
205
|
-
React__namespace.useEffect(() => {
|
206
|
-
}, [pathname]);
|
207
|
-
const layoutOptions = React__namespace.useMemo(() => ({ hideTryIt: hideTryIt, hideInlineExamples, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== types.NodeType.HttpService }), [hideTryIt, hideExport, node, hideInlineExamples]);
|
208
|
-
if (!node) {
|
209
|
-
const firstSlug = findFirstNodeSlug(tree);
|
210
|
-
if (firstSlug) {
|
211
|
-
return React__namespace.createElement(reactRouterDom.Redirect, { to: firstSlug });
|
161
|
+
};
|
162
|
+
const addTagGroupsToTree = (groups, ungrouped, tree, itemsType, hideInternal) => {
|
163
|
+
ungrouped.forEach(node => {
|
164
|
+
if (hideInternal && isInternal(node)) {
|
165
|
+
return;
|
212
166
|
}
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
167
|
+
tree.push({
|
168
|
+
id: node.uri,
|
169
|
+
slug: node.uri,
|
170
|
+
title: node.name,
|
171
|
+
type: node.type,
|
172
|
+
meta: elementalCore.isHttpOperation(node.data) || elementalCore.isHttpWebhookOperation(node.data) ? node.data.method : '',
|
173
|
+
});
|
174
|
+
});
|
175
|
+
groups.forEach(group => {
|
176
|
+
const items = group.items.flatMap(node => {
|
177
|
+
if (hideInternal && isInternal(node)) {
|
178
|
+
return [];
|
179
|
+
}
|
180
|
+
return {
|
181
|
+
id: node.uri,
|
182
|
+
slug: node.uri,
|
183
|
+
title: node.name,
|
184
|
+
type: node.type,
|
185
|
+
meta: elementalCore.isHttpOperation(node.data) || elementalCore.isHttpWebhookOperation(node.data) ? node.data.method : '',
|
186
|
+
};
|
187
|
+
});
|
188
|
+
if (items.length > 0) {
|
189
|
+
tree.push({
|
190
|
+
title: group.title,
|
191
|
+
items,
|
192
|
+
itemsType,
|
193
|
+
});
|
220
194
|
}
|
221
|
-
};
|
222
|
-
const sidebar = (React__namespace.createElement(React__namespace.Fragment, null,
|
223
|
-
React__namespace.createElement(mosaic.Flex, { ml: 4, mb: 5, alignItems: "center" },
|
224
|
-
logo ? (React__namespace.createElement(elementalCore.Logo, { logo: { url: logo, altText: 'logo' } })) : (serviceNode.data.logo && React__namespace.createElement(elementalCore.Logo, { logo: serviceNode.data.logo })),
|
225
|
-
React__namespace.createElement(mosaic.Heading, { size: 4 }, serviceNode.name)),
|
226
|
-
React__namespace.createElement(mosaic.Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
|
227
|
-
React__namespace.createElement(elementalCore.TableOfContents, { tree: tree, activeId: pathname, Link: reactRouterDom.Link, onLinkClick: handleTocClick })),
|
228
|
-
React__namespace.createElement(elementalCore.PoweredByLink, { source: serviceNode.name, pathname: pathname, packageType: "elements" })));
|
229
|
-
return (React__namespace.createElement(elementalCore.SidebarLayout, { ref: container, sidebar: sidebar, renderSideBar: !useCustomNav, layout: layout }, node && (React__namespace.createElement(elementalCore.ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, tryItOutDefaultServer: tryItOutDefaultServer }))));
|
195
|
+
});
|
230
196
|
};
|
231
197
|
|
232
198
|
const itemUriMatchesPathname = (itemUri, pathname) => itemUri === pathname;
|
@@ -235,24 +201,39 @@ const TryItContext = React__namespace.createContext({
|
|
235
201
|
tryItCredentialsPolicy: 'omit',
|
236
202
|
});
|
237
203
|
TryItContext.displayName = 'TryItContext';
|
238
|
-
const
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
204
|
+
const LocationContext = React__namespace.createContext({
|
205
|
+
location: {
|
206
|
+
hash: '',
|
207
|
+
key: '',
|
208
|
+
pathname: '',
|
209
|
+
search: '',
|
210
|
+
state: '',
|
211
|
+
},
|
212
|
+
});
|
213
|
+
LocationContext.displayName = 'LocationContext';
|
214
|
+
const APIWithStackedLayout = ({ serviceNode, hideTryIt, hideExport, hideInlineExamples, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, showPoweredByLink = true, location, tryItOutDefaultServer, }) => {
|
215
|
+
const { groups: operationGroups } = computeTagGroups(serviceNode, types.NodeType.HttpOperation);
|
216
|
+
const { groups: webhookGroups } = computeTagGroups(serviceNode, types.NodeType.HttpWebhook);
|
217
|
+
return (React__namespace.createElement(LocationContext.Provider, { value: { location } },
|
218
|
+
React__namespace.createElement(TryItContext.Provider, { value: {
|
219
|
+
hideTryIt,
|
220
|
+
tryItCredentialsPolicy,
|
221
|
+
corsProxy: tryItCorsProxy,
|
222
|
+
hideInlineExamples,
|
223
|
+
tryItOutDefaultServer,
|
224
|
+
} },
|
225
|
+
React__namespace.createElement(mosaic.Flex, { w: "full", flexDirection: "col", m: "auto", className: "sl-max-w-4xl" },
|
226
|
+
React__namespace.createElement(mosaic.Box, { w: "full", borderB: true },
|
227
|
+
React__namespace.createElement(elementalCore.Docs, { className: "sl-mx-auto", nodeData: serviceNode.data, nodeTitle: serviceNode.name, nodeType: types.NodeType.HttpService, location: location, layoutOptions: { showPoweredByLink, hideExport }, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, renderExtensionAddon: renderExtensionAddon, tryItOutDefaultServer: tryItOutDefaultServer })),
|
228
|
+
operationGroups.length > 0 && webhookGroups.length > 0 ? React__namespace.createElement(mosaic.Heading, { size: 2 }, "Endpoints") : null,
|
229
|
+
operationGroups.map(group => (React__namespace.createElement(Group, { key: group.title, group: group }))),
|
230
|
+
webhookGroups.length > 0 ? React__namespace.createElement(mosaic.Heading, { size: 2 }, "Webhooks") : null,
|
231
|
+
webhookGroups.map(group => (React__namespace.createElement(Group, { key: group.title, group: group })))))));
|
252
232
|
};
|
233
|
+
APIWithStackedLayout.displayName = 'APIWithStackedLayout';
|
253
234
|
const Group = React__namespace.memo(({ group }) => {
|
254
235
|
const [isExpanded, setIsExpanded] = React__namespace.useState(false);
|
255
|
-
const { pathname } =
|
236
|
+
const { location: { pathname }, } = React__namespace.useContext(LocationContext);
|
256
237
|
const onClick = React__namespace.useCallback(() => setIsExpanded(!isExpanded), [isExpanded]);
|
257
238
|
const shouldExpand = React__namespace.useMemo(() => {
|
258
239
|
return group.items.some(item => itemUriMatchesPathname(item.uri, pathname));
|
@@ -270,8 +251,9 @@ const Group = React__namespace.memo(({ group }) => {
|
|
270
251
|
return React__namespace.createElement(Item, { key: item.uri, item: item });
|
271
252
|
}))));
|
272
253
|
});
|
254
|
+
Group.displayName = 'Group';
|
273
255
|
const Item = React__namespace.memo(({ item }) => {
|
274
|
-
const location =
|
256
|
+
const { location } = React__namespace.useContext(LocationContext);
|
275
257
|
const { pathname } = location;
|
276
258
|
const [isExpanded, setIsExpanded] = React__namespace.useState(false);
|
277
259
|
const scrollRef = React__namespace.useRef(null);
|
@@ -295,7 +277,7 @@ const Item = React__namespace.memo(({ item }) => {
|
|
295
277
|
return (React__namespace.createElement(mosaic.Box, { ref: scrollRef, w: "full", my: 2, border: true, borderColor: { default: isExpanded ? 'light' : 'transparent', hover: 'light' }, bg: { default: isExpanded ? 'code' : 'transparent', hover: 'code' } },
|
296
278
|
React__namespace.createElement(mosaic.Flex, { mx: "auto", alignItems: "center", cursor: "pointer", fontSize: "lg", p: 2, onClick: onClick, color: "current" },
|
297
279
|
React__namespace.createElement(mosaic.Box, { w: 24, textTransform: "uppercase", textAlign: "center", fontWeight: "semibold", border: true, rounded: true, px: 2, bg: "canvas", className: cn__default["default"](`sl-mr-5 sl-text-base`, `sl-text-${color}`, `sl-border-${color}`) }, item.data.method || 'UNKNOWN'),
|
298
|
-
React__namespace.createElement(mosaic.Box, { flex: 1, fontWeight: "medium", wordBreak: "all" }, item.data.path),
|
280
|
+
React__namespace.createElement(mosaic.Box, { flex: 1, fontWeight: "medium", wordBreak: "all" }, item.type === types.NodeType.HttpOperation ? item.data.path : item.name),
|
299
281
|
isDeprecated && React__namespace.createElement(elementalCore.DeprecatedBadge, null)),
|
300
282
|
React__namespace.createElement(Collapse, { isOpen: isExpanded },
|
301
283
|
React__namespace.createElement(mosaic.Box, { flex: 1, p: 2, fontWeight: "medium", mx: "auto", fontSize: "xl" }, item.name),
|
@@ -309,17 +291,91 @@ const Item = React__namespace.memo(({ item }) => {
|
|
309
291
|
React__namespace.createElement(mosaic.TabPanel, null,
|
310
292
|
React__namespace.createElement(elementalCore.TryItWithRequestSamples, { httpOperation: item.data, hideInlineExamples: hideInlineExamples, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItOutDefaultServer: tryItOutDefaultServer, corsProxy: corsProxy }))))))));
|
311
293
|
});
|
294
|
+
Item.displayName = 'Item';
|
312
295
|
const Collapse = ({ isOpen, children }) => {
|
313
296
|
if (!isOpen)
|
314
297
|
return null;
|
315
298
|
return React__namespace.createElement(mosaic.Box, null, children);
|
299
|
+
};
|
300
|
+
Collapse.displayName = 'Collapse';
|
301
|
+
|
302
|
+
const APIWithResponsiveSidebarLayout = ({ serviceNode, logo, hideTryIt, compact, hideSchemas, hideInternal, hideExport, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, }) => {
|
303
|
+
const container = React__namespace.useRef(null);
|
304
|
+
const tree = React__namespace.useMemo(() => computeAPITree(serviceNode, { hideSchemas, hideInternal }), [serviceNode, hideSchemas, hideInternal]);
|
305
|
+
const location = reactRouterDom.useLocation();
|
306
|
+
const { pathname } = location;
|
307
|
+
const isRootPath = !pathname || pathname === '/';
|
308
|
+
const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
|
309
|
+
const layoutOptions = React__namespace.useMemo(() => ({ hideTryIt: hideTryIt, compact: compact, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== types.NodeType.HttpService }), [hideTryIt, hideExport, node, compact]);
|
310
|
+
if (!node) {
|
311
|
+
const firstSlug = findFirstNodeSlug(tree);
|
312
|
+
if (firstSlug) {
|
313
|
+
return React__namespace.createElement(reactRouterDom.Redirect, { to: firstSlug });
|
314
|
+
}
|
315
|
+
}
|
316
|
+
if (hideInternal && node && isInternal(node)) {
|
317
|
+
return React__namespace.createElement(reactRouterDom.Redirect, { to: "/" });
|
318
|
+
}
|
319
|
+
const handleTocClick = () => {
|
320
|
+
if (container.current) {
|
321
|
+
container.current.scrollIntoView();
|
322
|
+
}
|
323
|
+
};
|
324
|
+
return (React__namespace.createElement(elementalCore.ResponsiveSidebarLayout, { onTocClick: handleTocClick, tree: tree, logo: logo !== null && logo !== void 0 ? logo : serviceNode.data.logo, ref: container, name: serviceNode.name }, node && (React__namespace.createElement(elementalCore.ElementsOptionsProvider, { renderExtensionAddon: renderExtensionAddon },
|
325
|
+
React__namespace.createElement(elementalCore.ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon })))));
|
316
326
|
};
|
317
327
|
|
328
|
+
const APIWithSidebarLayout = ({ serviceNode, logo, hideTryIt, hideSchemas, hideInternal, hideExport, hideInlineExamples = false, exportProps, tryItCredentialsPolicy, tryItCorsProxy, renderExtensionAddon, tryItOutDefaultServer, useCustomNav, layout, }) => {
|
329
|
+
const container = React__namespace.useRef(null);
|
330
|
+
const tree = React__namespace.useMemo(() => {
|
331
|
+
if (!useCustomNav)
|
332
|
+
return computeAPITree(serviceNode, { hideSchemas, hideInternal });
|
333
|
+
else
|
334
|
+
return [];
|
335
|
+
}, [serviceNode, hideSchemas, hideInternal, useCustomNav]);
|
336
|
+
const location = reactRouterDom.useLocation();
|
337
|
+
const { pathname } = location;
|
338
|
+
const isRootPath = !pathname || pathname === '/';
|
339
|
+
const node = isRootPath ? serviceNode : serviceNode.children.find(child => child.uri === pathname);
|
340
|
+
React__namespace.useEffect(() => {
|
341
|
+
}, [pathname]);
|
342
|
+
const layoutOptions = React__namespace.useMemo(() => ({ hideTryIt: hideTryIt, hideInlineExamples, hideExport: hideExport || (node === null || node === void 0 ? void 0 : node.type) !== types.NodeType.HttpService }), [hideTryIt, hideExport, node, hideInlineExamples]);
|
343
|
+
if (!node) {
|
344
|
+
const firstSlug = findFirstNodeSlug(tree);
|
345
|
+
if (firstSlug) {
|
346
|
+
return React__namespace.createElement(reactRouterDom.Redirect, { to: firstSlug });
|
347
|
+
}
|
348
|
+
}
|
349
|
+
if (hideInternal && node && isInternal(node)) {
|
350
|
+
return React__namespace.createElement(reactRouterDom.Redirect, { to: "/" });
|
351
|
+
}
|
352
|
+
const sidebar = (React__namespace.createElement(Sidebar, { serviceNode: serviceNode, logo: logo, container: container, pathname: pathname, tree: tree }));
|
353
|
+
return (React__namespace.createElement(elementalCore.SidebarLayout, { ref: container, sidebar: sidebar, renderSideBar: !useCustomNav, layout: layout }, node && (React__namespace.createElement(elementalCore.ElementsOptionsProvider, { renderExtensionAddon: renderExtensionAddon },
|
354
|
+
React__namespace.createElement(elementalCore.ParsedDocs, { key: pathname, uri: pathname, node: node, nodeTitle: node.name, layoutOptions: layoutOptions, location: location, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon, tryItOutDefaultServer: tryItOutDefaultServer })))));
|
355
|
+
};
|
356
|
+
const Sidebar = ({ serviceNode, logo, container, pathname, tree }) => {
|
357
|
+
const handleTocClick = () => {
|
358
|
+
if (container.current) {
|
359
|
+
container.current.scrollIntoView();
|
360
|
+
}
|
361
|
+
};
|
362
|
+
return (React__namespace.createElement(React__namespace.Fragment, null,
|
363
|
+
React__namespace.createElement(mosaic.Flex, { ml: 4, mb: 5, alignItems: "center" },
|
364
|
+
logo ? (React__namespace.createElement(elementalCore.Logo, { logo: { url: logo, altText: 'logo' } })) : (serviceNode.data.logo && React__namespace.createElement(elementalCore.Logo, { logo: serviceNode.data.logo })),
|
365
|
+
React__namespace.createElement(mosaic.Heading, { size: 4 }, serviceNode.name)),
|
366
|
+
React__namespace.createElement(mosaic.Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
|
367
|
+
React__namespace.createElement(elementalCore.TableOfContents, { tree: tree, activeId: pathname, Link: reactRouterDom.Link, onLinkClick: handleTocClick })),
|
368
|
+
React__namespace.createElement(elementalCore.PoweredByLink, { source: serviceNode.name, pathname: pathname, packageType: "elements" })));
|
369
|
+
};
|
370
|
+
Sidebar.displayName = 'Sidebar';
|
371
|
+
|
318
372
|
var NodeTypes;
|
319
373
|
(function (NodeTypes) {
|
320
374
|
NodeTypes["Paths"] = "paths";
|
321
375
|
NodeTypes["Path"] = "path";
|
322
376
|
NodeTypes["Operation"] = "operation";
|
377
|
+
NodeTypes["Webhooks"] = "webhooks";
|
378
|
+
NodeTypes["Webhook"] = "webhook";
|
323
379
|
NodeTypes["Components"] = "components";
|
324
380
|
NodeTypes["Models"] = "models";
|
325
381
|
NodeTypes["Model"] = "model";
|
@@ -371,6 +427,22 @@ const oas3SourceMap = [
|
|
371
427
|
},
|
372
428
|
],
|
373
429
|
},
|
430
|
+
{
|
431
|
+
match: 'webhooks',
|
432
|
+
type: NodeTypes.Webhooks,
|
433
|
+
children: [
|
434
|
+
{
|
435
|
+
notMatch: '^x-',
|
436
|
+
type: NodeTypes.Webhook,
|
437
|
+
children: [
|
438
|
+
{
|
439
|
+
match: 'get|post|put|delete|options|head|patch|trace',
|
440
|
+
type: NodeTypes.Webhook,
|
441
|
+
},
|
442
|
+
],
|
443
|
+
},
|
444
|
+
],
|
445
|
+
},
|
374
446
|
{
|
375
447
|
match: 'components',
|
376
448
|
type: NodeTypes.Components,
|
@@ -425,7 +497,7 @@ function computeServiceNode(document, map, transformService, transformOperation)
|
|
425
497
|
return serviceNode;
|
426
498
|
}
|
427
499
|
function computeChildNodes(document, data, map, transformer, parentUri = '') {
|
428
|
-
var _a;
|
500
|
+
var _a, _b;
|
429
501
|
const nodes = [];
|
430
502
|
if (!isObject__default["default"](data))
|
431
503
|
return nodes;
|
@@ -438,7 +510,12 @@ function computeChildNodes(document, data, map, transformer, parentUri = '') {
|
|
438
510
|
if (match.type === NodeTypes.Operation && jsonPath.length === 3) {
|
439
511
|
const path = String(jsonPath[1]);
|
440
512
|
const method = String(jsonPath[2]);
|
441
|
-
const operationDocument = transformer({
|
513
|
+
const operationDocument = transformer({
|
514
|
+
document,
|
515
|
+
name: path,
|
516
|
+
method,
|
517
|
+
config: oas.OPERATION_CONFIG,
|
518
|
+
});
|
442
519
|
let parsedUri;
|
443
520
|
const encodedPath = String(json.encodePointerFragment(path));
|
444
521
|
if (operationDocument.iid) {
|
@@ -455,6 +532,31 @@ function computeChildNodes(document, data, map, transformer, parentUri = '') {
|
|
455
532
|
tags: ((_a = operationDocument.tags) === null || _a === void 0 ? void 0 : _a.map(tag => tag.name)) || [],
|
456
533
|
});
|
457
534
|
}
|
535
|
+
else if (match.type === NodeTypes.Webhook && jsonPath.length === 3) {
|
536
|
+
const name = String(jsonPath[1]);
|
537
|
+
const method = String(jsonPath[2]);
|
538
|
+
const webhookDocument = transformer({
|
539
|
+
document,
|
540
|
+
name,
|
541
|
+
method,
|
542
|
+
config: oas.WEBHOOK_CONFIG,
|
543
|
+
});
|
544
|
+
let parsedUri;
|
545
|
+
const encodedPath = String(json.encodePointerFragment(name));
|
546
|
+
if (webhookDocument.iid) {
|
547
|
+
parsedUri = `/webhooks/${webhookDocument.iid}`;
|
548
|
+
}
|
549
|
+
else {
|
550
|
+
parsedUri = uri.replace(encodedPath, elementalCore.slugify(name));
|
551
|
+
}
|
552
|
+
nodes.push({
|
553
|
+
type: types.NodeType.HttpWebhook,
|
554
|
+
uri: parsedUri,
|
555
|
+
data: webhookDocument,
|
556
|
+
name: webhookDocument.summary || webhookDocument.name,
|
557
|
+
tags: ((_b = webhookDocument.tags) === null || _b === void 0 ? void 0 : _b.map(tag => tag.name)) || [],
|
558
|
+
});
|
559
|
+
}
|
458
560
|
else if (match.type === NodeTypes.Model) {
|
459
561
|
const schemaDocument = get__default["default"](document, jsonPath);
|
460
562
|
const parsedUri = uri.replace(OAS_MODEL_REGEXP, 'schemas/');
|
@@ -527,8 +629,10 @@ const propsAreWithDocument = (props) => {
|
|
527
629
|
return props.hasOwnProperty('apiDescriptionDocument');
|
528
630
|
};
|
529
631
|
const APIImpl = props => {
|
530
|
-
const { layout, apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, hideInlineExamples, tryItCredentialsPolicy, tryItCorsProxy, tryItOutDefaultServer, useCustomNav, } = props;
|
632
|
+
const { layout = 'sidebar', apiDescriptionUrl = '', logo, hideTryIt, hideSchemas, hideInternal, hideExport, hideInlineExamples, tryItCredentialsPolicy, tryItCorsProxy, maxRefDepth, renderExtensionAddon, tryItOutDefaultServer, useCustomNav, } = props;
|
633
|
+
const location = reactRouterDom.useLocation();
|
531
634
|
const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
|
635
|
+
const { isResponsiveLayoutEnabled } = elementalCore.useResponsiveLayout();
|
532
636
|
const { data: fetchedDocument, error } = reactQuery.useQuery([apiDescriptionUrl], () => fetch(apiDescriptionUrl).then(res => {
|
533
637
|
if (res.ok) {
|
534
638
|
return res.text();
|
@@ -554,7 +658,10 @@ const APIImpl = props => {
|
|
554
658
|
return (React__namespace.createElement(mosaic.Flex, { justify: "center", alignItems: "center", w: "full", minH: "screen" },
|
555
659
|
React__namespace.createElement(elementalCore.NonIdealState, { title: "Failed to parse OpenAPI file", description: "Please make sure your OpenAPI file is valid and try again" })));
|
556
660
|
}
|
557
|
-
return (React__namespace.createElement(elementalCore.InlineRefResolverProvider, { document: parsedDocument
|
661
|
+
return (React__namespace.createElement(elementalCore.InlineRefResolverProvider, { document: parsedDocument, maxRefDepth: maxRefDepth },
|
662
|
+
layout === 'stacked' && (React__namespace.createElement(APIWithStackedLayout, { serviceNode: serviceNode, hideTryIt: hideTryIt, hideExport: hideExport, hideInlineExamples: hideInlineExamples, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon, location: location, tryItOutDefaultServer: tryItOutDefaultServer })),
|
663
|
+
layout === 'sidebar' && (React__namespace.createElement(APIWithSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, hideInlineExamples: hideInlineExamples, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon, tryItOutDefaultServer: tryItOutDefaultServer, useCustomNav: useCustomNav, layout: layout })),
|
664
|
+
layout === 'responsive' && (React__namespace.createElement(APIWithResponsiveSidebarLayout, { logo: logo, serviceNode: serviceNode, hideTryIt: hideTryIt, hideSchemas: hideSchemas, hideInternal: hideInternal, hideExport: hideExport, exportProps: exportProps, tryItCredentialsPolicy: tryItCredentialsPolicy, tryItCorsProxy: tryItCorsProxy, renderExtensionAddon: renderExtensionAddon, compact: isResponsiveLayoutEnabled }))));
|
558
665
|
};
|
559
666
|
const API = flow__default["default"](elementalCore.withRouter, elementalCore.withStyles, elementalCore.withPersistenceBoundary, elementalCore.withMosaicProvider, elementalCore.withQueryClientProvider)(APIImpl);
|
560
667
|
|
@@ -588,6 +695,7 @@ const useGetOasNavTree = (apiDescriptionDocument) => {
|
|
588
695
|
};
|
589
696
|
|
590
697
|
exports.API = API;
|
698
|
+
exports.APIWithStackedLayout = APIWithStackedLayout;
|
591
699
|
exports.transformOasToServiceNode = transformOasToServiceNode;
|
592
700
|
exports.useExportDocumentProps = useExportDocumentProps;
|
593
701
|
exports.useGetOasNavTree = useGetOasNavTree;
|