@stoplight/elements-core 8.0.0 → 8.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/Docs/Article/Article.stories.d.ts +4 -4
- package/components/Docs/Docs.stories.d.ts +1 -1
- package/components/Docs/HttpOperation/HttpOperation.stories.d.ts +2 -2
- package/components/Docs/HttpService/HttpService.stories.d.ts +2 -2
- package/components/Docs/Model/Model.stories.d.ts +2 -2
- package/components/Layout/MobileTopNav.d.ts +9 -0
- package/components/Layout/ResponsiveSidebarLayout.d.ts +22 -0
- package/components/Logo.d.ts +4 -10
- package/components/RequestSamples/RequestSamples.stories.d.ts +2 -2
- package/components/ResponseExamples/ResponseExamples.stories.d.ts +2 -2
- package/components/TableOfContents/index.d.ts +1 -0
- package/components/TryIt/TryIt.stories.d.ts +11 -11
- package/components/TryIt/TryItWithRequestSamples.stories.d.ts +3 -3
- package/hooks/useResponsiveLayout.d.ts +13 -0
- package/index.d.ts +3 -0
- package/index.esm.js +317 -184
- package/index.js +317 -181
- package/index.mjs +317 -184
- package/package.json +1 -1
- package/styles.min.css +1 -1
- package/types.d.ts +6 -0
package/index.esm.js
CHANGED
|
@@ -7,10 +7,10 @@ import isArray from 'lodash/isArray.js';
|
|
|
7
7
|
import isPlainObject from 'lodash/isPlainObject.js';
|
|
8
8
|
import { NodeType, HttpParamStyles } from '@stoplight/types';
|
|
9
9
|
import { parse } from '@stoplight/yaml';
|
|
10
|
-
import { isArray as isArray$1, Box, useBreakpoints, Panel, CopyButton, Menu, Button, Text, Flex, Input, Icon, Select, FieldButton, Image, Link, useThemeIsDark, HStack, VStack, InvertTheme, Tooltip, Badge, LinkHeading as LinkHeading$1, NodeAnnotation, Callout, useModalState, Modal, ListBox, ListBoxItem, TabList, Tab, Tabs, TabPanels, TabPanel, Heading, useClipboard, useMosaicContext, Provider as Provider$1 } from '@stoplight/mosaic';
|
|
10
|
+
import { isArray as isArray$1, Box, useBreakpoints, Panel, CopyButton, Menu, Button, Text, Flex, Input, Icon, Select, FieldButton, Image, Link, useThemeIsDark, HStack, VStack, InvertTheme, Tooltip, Badge, LinkHeading as LinkHeading$1, NodeAnnotation, Callout, useModalState, Modal, ListBox, ListBoxItem, TabList, Tab, Tabs, TabPanels, TabPanel, Heading, useClipboard, Drawer, useMosaicContext, Provider as Provider$1 } from '@stoplight/mosaic';
|
|
11
11
|
import isObject from 'lodash/isObject.js';
|
|
12
12
|
import { withErrorBoundary } from '@stoplight/react-error-boundary';
|
|
13
|
-
import { useLocation, BrowserRouter, MemoryRouter, HashRouter, StaticRouter, Route } from 'react-router-dom';
|
|
13
|
+
import { useLocation, Link as Link$1, BrowserRouter, MemoryRouter, HashRouter, StaticRouter, Route } from 'react-router-dom';
|
|
14
14
|
import { MarkdownViewer as MarkdownViewer$1, DefaultSMDComponents, MarkdownViewerProvider } from '@stoplight/markdown-viewer';
|
|
15
15
|
export { DefaultSMDComponents } from '@stoplight/markdown-viewer';
|
|
16
16
|
import cn from 'classnames';
|
|
@@ -308,6 +308,11 @@ const Article = withErrorBoundary(ArticleComponent, { recoverableProps: ['data']
|
|
|
308
308
|
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
|
309
309
|
* Copyright 2022 Fonticons, Inc.
|
|
310
310
|
*/
|
|
311
|
+
var faBars = {
|
|
312
|
+
prefix: 'fas',
|
|
313
|
+
iconName: 'bars',
|
|
314
|
+
icon: [448, 512, ["navicon"], "f0c9", "M0 96C0 78.33 14.33 64 32 64H416C433.7 64 448 78.33 448 96C448 113.7 433.7 128 416 128H32C14.33 128 0 113.7 0 96zM0 256C0 238.3 14.33 224 32 224H416C433.7 224 448 238.3 448 256C448 273.7 433.7 288 416 288H32C14.33 288 0 273.7 0 256zM416 448H32C14.33 448 0 433.7 0 416C0 398.3 14.33 384 32 384H416C433.7 384 448 398.3 448 416C448 433.7 433.7 448 416 448z"]
|
|
315
|
+
};
|
|
311
316
|
var faBolt = {
|
|
312
317
|
prefix: 'fas',
|
|
313
318
|
iconName: 'bolt',
|
|
@@ -379,6 +384,11 @@ var faServer = {
|
|
|
379
384
|
iconName: 'server',
|
|
380
385
|
icon: [512, 512, [], "f233", "M480 288H32c-17.62 0-32 14.38-32 32v128c0 17.62 14.38 32 32 32h448c17.62 0 32-14.38 32-32v-128C512 302.4 497.6 288 480 288zM352 408c-13.25 0-24-10.75-24-24s10.75-24 24-24s24 10.75 24 24S365.3 408 352 408zM416 408c-13.25 0-24-10.75-24-24s10.75-24 24-24s24 10.75 24 24S429.3 408 416 408zM480 32H32C14.38 32 0 46.38 0 64v128c0 17.62 14.38 32 32 32h448c17.62 0 32-14.38 32-32V64C512 46.38 497.6 32 480 32zM352 152c-13.25 0-24-10.75-24-24S338.8 104 352 104S376 114.8 376 128S365.3 152 352 152zM416 152c-13.25 0-24-10.75-24-24S402.8 104 416 104S440 114.8 440 128S429.3 152 416 152z"]
|
|
381
386
|
};
|
|
387
|
+
var faX = {
|
|
388
|
+
prefix: 'fas',
|
|
389
|
+
iconName: 'x',
|
|
390
|
+
icon: [384, 512, [120], "58", "M376.6 427.5c11.31 13.58 9.484 33.75-4.094 45.06c-5.984 4.984-13.25 7.422-20.47 7.422c-9.172 0-18.27-3.922-24.59-11.52L192 305.1l-135.4 162.5c-6.328 7.594-15.42 11.52-24.59 11.52c-7.219 0-14.48-2.438-20.47-7.422c-13.58-11.31-15.41-31.48-4.094-45.06l142.9-171.5L7.422 84.5C-3.891 70.92-2.063 50.75 11.52 39.44c13.56-11.34 33.73-9.516 45.06 4.094L192 206l135.4-162.5c11.3-13.58 31.48-15.42 45.06-4.094c13.58 11.31 15.41 31.48 4.094 45.06l-142.9 171.5L376.6 427.5z"]
|
|
391
|
+
};
|
|
382
392
|
|
|
383
393
|
const NodeTypeColors = {
|
|
384
394
|
http_operation: '#6a6acb',
|
|
@@ -3096,195 +3106,53 @@ const ParsedDocs = (_a) => {
|
|
|
3096
3106
|
}
|
|
3097
3107
|
};
|
|
3098
3108
|
|
|
3099
|
-
const
|
|
3100
|
-
|
|
3101
|
-
const SIDEBAR_MAX_WIDTH = 1.5 * SIDEBAR_MIN_WIDTH;
|
|
3102
|
-
const SidebarLayout = React.forwardRef(({ sidebar, children, maxContentWidth = MAX_CONTENT_WIDTH, sidebarWidth = SIDEBAR_MIN_WIDTH }, ref) => {
|
|
3103
|
-
const scrollRef = React.useRef(null);
|
|
3104
|
-
const [sidebarRef, currentSidebarWidth, startResizing] = useResizer(sidebarWidth);
|
|
3105
|
-
const { pathname } = useLocation();
|
|
3106
|
-
React.useEffect(() => {
|
|
3107
|
-
var _a;
|
|
3108
|
-
(_a = scrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo(0, 0);
|
|
3109
|
-
}, [pathname]);
|
|
3110
|
-
return (React.createElement(Flex, { ref: ref, className: "sl-elements-api", pin: true, h: "full" },
|
|
3111
|
-
React.createElement(Flex, { ref: sidebarRef, onMouseDown: (e) => e.preventDefault(), style: { maxWidth: `${SIDEBAR_MAX_WIDTH}px` } },
|
|
3112
|
-
React.createElement(Flex, { direction: "col", bg: "canvas-100", borderR: true, pt: 8, pos: "sticky", pinY: true, overflowY: "auto", style: {
|
|
3113
|
-
paddingLeft: `calc((100% - ${maxContentWidth}px) / 2)`,
|
|
3114
|
-
width: `${currentSidebarWidth}px`,
|
|
3115
|
-
minWidth: `${SIDEBAR_MIN_WIDTH}px`,
|
|
3116
|
-
} }, sidebar),
|
|
3117
|
-
React.createElement(Flex, { justifySelf: "end", flexGrow: 0, flexShrink: 0, resize: "x", onMouseDown: startResizing, style: { width: '1em', flexBasis: '6px', cursor: 'ew-resize' } })),
|
|
3118
|
-
React.createElement(Box, { ref: scrollRef, bg: "canvas", px: 24, flex: 1, w: "full", overflowY: "auto" },
|
|
3119
|
-
React.createElement(Box, { style: { maxWidth: `${maxContentWidth - currentSidebarWidth}px` }, py: 16 }, children))));
|
|
3120
|
-
});
|
|
3121
|
-
function useResizer(sidebarWidth) {
|
|
3122
|
-
const sidebarRef = React.useRef(null);
|
|
3123
|
-
const [isResizing, setIsResizing] = React.useState(false);
|
|
3124
|
-
const [currentSidebarWidth, setCurrentSidebarWidth] = React.useState(sidebarWidth);
|
|
3125
|
-
const startResizing = React.useCallback(() => {
|
|
3126
|
-
setIsResizing(true);
|
|
3127
|
-
}, []);
|
|
3128
|
-
const stopResizing = React.useCallback(() => {
|
|
3129
|
-
setIsResizing(false);
|
|
3130
|
-
}, []);
|
|
3131
|
-
const resize = React.useCallback(mouseMoveEvent => {
|
|
3132
|
-
if (isResizing) {
|
|
3133
|
-
const value = mouseMoveEvent.clientX - sidebarRef.current.getBoundingClientRect().left;
|
|
3134
|
-
setCurrentSidebarWidth(Math.min(Math.max(SIDEBAR_MIN_WIDTH, value), SIDEBAR_MAX_WIDTH));
|
|
3135
|
-
}
|
|
3136
|
-
}, [isResizing]);
|
|
3137
|
-
React.useEffect(() => {
|
|
3138
|
-
window.addEventListener('mousemove', resize);
|
|
3139
|
-
window.addEventListener('mouseup', stopResizing, { passive: true });
|
|
3140
|
-
return () => {
|
|
3141
|
-
window.removeEventListener('mousemove', resize);
|
|
3142
|
-
window.removeEventListener('mouseup', stopResizing);
|
|
3143
|
-
};
|
|
3144
|
-
}, [resize, stopResizing]);
|
|
3145
|
-
return [sidebarRef, currentSidebarWidth, startResizing];
|
|
3146
|
-
}
|
|
3147
|
-
|
|
3148
|
-
const Logo = ({ logo }) => {
|
|
3149
|
-
var _a;
|
|
3150
|
-
return (React.createElement(Box, { display: "inline", mr: 3, rounded: "lg", overflowY: "hidden", overflowX: "hidden", style: { backgroundColor: (_a = logo.backgroundColor) !== null && _a !== void 0 ? _a : 'transparent' } }, logo.href ? (React.createElement("a", { href: logo.href, target: "_blank", rel: "noopener noreferrer" },
|
|
3151
|
-
React.createElement("img", { src: logo.url, height: "30px", width: "30px", alt: logo.altText }))) : (React.createElement("img", { src: logo.url, height: "30px", width: "30px", alt: logo.altText }))));
|
|
3152
|
-
};
|
|
3153
|
-
|
|
3154
|
-
function getDisplayName(WrappedComponent) {
|
|
3155
|
-
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
3156
|
-
}
|
|
3157
|
-
|
|
3158
|
-
const PersistenceContextProvider = Provider;
|
|
3159
|
-
function withPersistenceBoundary(WrappedComponent) {
|
|
3160
|
-
const WithPersistenceBoundary = props => {
|
|
3161
|
-
return (React.createElement(PersistenceContextProvider, null,
|
|
3162
|
-
React.createElement(WrappedComponent, Object.assign({}, props))));
|
|
3163
|
-
};
|
|
3164
|
-
WithPersistenceBoundary.displayName = `withPersistenceBoundary(${getDisplayName(WrappedComponent)})`;
|
|
3165
|
-
return WithPersistenceBoundary;
|
|
3166
|
-
}
|
|
3167
|
-
|
|
3168
|
-
function useParsedValue(value) {
|
|
3169
|
-
return React.useMemo(() => {
|
|
3170
|
-
let parsedValue = value;
|
|
3171
|
-
if (typeof value === 'string') {
|
|
3172
|
-
try {
|
|
3173
|
-
parsedValue = parse(value);
|
|
3174
|
-
}
|
|
3175
|
-
catch (error) {
|
|
3176
|
-
}
|
|
3177
|
-
}
|
|
3178
|
-
return parsedValue;
|
|
3179
|
-
}, [value]);
|
|
3180
|
-
}
|
|
3181
|
-
|
|
3182
|
-
function isPartialHttpRequest(maybeHttpRequest) {
|
|
3183
|
-
return (isObject(maybeHttpRequest) &&
|
|
3184
|
-
'method' in maybeHttpRequest &&
|
|
3185
|
-
typeof maybeHttpRequest['method'] === 'string' &&
|
|
3186
|
-
'url' in maybeHttpRequest &&
|
|
3187
|
-
typeof maybeHttpRequest['url'] === 'string');
|
|
3188
|
-
}
|
|
3189
|
-
const SchemaAndDescription = ({ title: titleProp, schema }) => {
|
|
3190
|
-
const [resolveRef, maxRefDepth] = useSchemaInlineRefResolver();
|
|
3191
|
-
const title = titleProp !== null && titleProp !== void 0 ? titleProp : schema.title;
|
|
3192
|
-
return (React__default.createElement(Box, { py: 2 },
|
|
3193
|
-
title && (React__default.createElement(Flex, { alignItems: "center", p: 2 },
|
|
3194
|
-
React__default.createElement(Icon, { icon: NodeTypeIconDefs[NodeType.Model], color: NodeTypeColors[NodeType.Model] }),
|
|
3195
|
-
React__default.createElement(Box, { color: "muted", px: 2 }, title))),
|
|
3196
|
-
React__default.createElement(JsonSchemaViewer, { resolveRef: resolveRef, maxRefDepth: maxRefDepth, schema: getOriginalObject(schema) })));
|
|
3109
|
+
const ElementsBreakpoints = {
|
|
3110
|
+
docs: 700,
|
|
3197
3111
|
};
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
return
|
|
3208
|
-
React__default.createElement(SchemaAndDescription, { title: title, schema: parsedValue })));
|
|
3112
|
+
var ScreenType;
|
|
3113
|
+
(function (ScreenType) {
|
|
3114
|
+
ScreenType[ScreenType["Phone"] = 415] = "Phone";
|
|
3115
|
+
ScreenType[ScreenType["Tablet"] = 750] = "Tablet";
|
|
3116
|
+
ScreenType[ScreenType["Resized_Browser"] = 980] = "Resized_Browser";
|
|
3117
|
+
ScreenType[ScreenType["Normal_Browser"] = 1000000] = "Normal_Browser";
|
|
3118
|
+
})(ScreenType || (ScreenType = {}));
|
|
3119
|
+
const getScreenType = () => {
|
|
3120
|
+
if ((window === null || window === void 0 ? void 0 : window.innerWidth) <= ScreenType.Phone) {
|
|
3121
|
+
return ScreenType.Phone;
|
|
3209
3122
|
}
|
|
3210
|
-
if (
|
|
3211
|
-
|
|
3212
|
-
return null;
|
|
3213
|
-
}
|
|
3214
|
-
return (React__default.createElement(PersistenceContextProvider, null,
|
|
3215
|
-
React__default.createElement(TryIt, { httpOperation: isHttpOperation(parsedValue) ? parsedValue : parseHttpRequest(parsedValue), embeddedInMd: true })));
|
|
3123
|
+
else if ((window === null || window === void 0 ? void 0 : window.innerWidth) <= ScreenType.Tablet) {
|
|
3124
|
+
return ScreenType.Tablet;
|
|
3216
3125
|
}
|
|
3217
|
-
|
|
3218
|
-
|
|
3126
|
+
else if ((window === null || window === void 0 ? void 0 : window.innerWidth) <= ScreenType.Resized_Browser) {
|
|
3127
|
+
return ScreenType.Resized_Browser;
|
|
3128
|
+
}
|
|
3129
|
+
return ScreenType.Normal_Browser;
|
|
3219
3130
|
};
|
|
3220
|
-
|
|
3221
|
-
const
|
|
3222
|
-
const
|
|
3131
|
+
const useResponsiveLayout = () => {
|
|
3132
|
+
const [screenType, setScreenType] = React.useState();
|
|
3133
|
+
const getElementsBreakpoint = (node) => {
|
|
3134
|
+
return ElementsBreakpoints[node];
|
|
3135
|
+
};
|
|
3136
|
+
React.useLayoutEffect(() => {
|
|
3137
|
+
function handleResize() {
|
|
3138
|
+
setScreenType(getScreenType());
|
|
3139
|
+
}
|
|
3140
|
+
window === null || window === void 0 ? void 0 : window.addEventListener('resize', handleResize);
|
|
3141
|
+
handleResize();
|
|
3142
|
+
return () => window === null || window === void 0 ? void 0 : window.removeEventListener('resize', handleResize);
|
|
3143
|
+
}, []);
|
|
3144
|
+
const isResponsiveLayoutEnabled = screenType !== ScreenType.Normal_Browser;
|
|
3223
3145
|
return {
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
servers: [{ id: `?http-server-${uri.href()}?`, url: uri.is('absolute') ? uri.origin() : data.baseUrl || '' }],
|
|
3228
|
-
request: Object.assign({ query: Object.entries(data.query || {}).map(([key, value]) => {
|
|
3229
|
-
const defaultVal = Array.isArray(value) ? value[0] : value;
|
|
3230
|
-
return {
|
|
3231
|
-
id: `?http-query-${key}-id?`,
|
|
3232
|
-
name: key,
|
|
3233
|
-
style: HttpParamStyles.Form,
|
|
3234
|
-
schema: { default: defaultVal },
|
|
3235
|
-
required: isHttpRequestParamRequired(defaultVal),
|
|
3236
|
-
};
|
|
3237
|
-
}), headers: Object.entries(data.headers || {}).map(([key, value]) => ({
|
|
3238
|
-
id: `?http-header-${key}-id?`,
|
|
3239
|
-
name: key,
|
|
3240
|
-
style: HttpParamStyles.Simple,
|
|
3241
|
-
schema: { default: value },
|
|
3242
|
-
required: isHttpRequestParamRequired(value),
|
|
3243
|
-
})), path: pathParam === null || pathParam === void 0 ? void 0 : pathParam.map(name => ({
|
|
3244
|
-
id: `?http-param-${name}-id?`,
|
|
3245
|
-
name,
|
|
3246
|
-
style: HttpParamStyles.Simple,
|
|
3247
|
-
required: true,
|
|
3248
|
-
})) }, (data.body
|
|
3249
|
-
? {
|
|
3250
|
-
body: {
|
|
3251
|
-
id: '?http-request-body?',
|
|
3252
|
-
contents: [
|
|
3253
|
-
{
|
|
3254
|
-
id: '?http-request-body-media?',
|
|
3255
|
-
mediaType: 'application/json',
|
|
3256
|
-
schema: { default: data.body },
|
|
3257
|
-
},
|
|
3258
|
-
],
|
|
3259
|
-
},
|
|
3260
|
-
}
|
|
3261
|
-
: null)),
|
|
3262
|
-
responses: [],
|
|
3146
|
+
isResponsiveLayoutEnabled,
|
|
3147
|
+
screenType,
|
|
3148
|
+
getElementsBreakpoint,
|
|
3263
3149
|
};
|
|
3264
|
-
}
|
|
3265
|
-
function isHttpRequestParamRequired(value) {
|
|
3266
|
-
return typeof value !== 'undefined';
|
|
3267
|
-
}
|
|
3268
|
-
|
|
3269
|
-
const MarkdownComponentsProvider = ({ value, children }) => {
|
|
3270
|
-
return React.createElement(MarkdownViewerProvider, { components: Object.assign({ code: CodeComponent }, value) }, children);
|
|
3271
3150
|
};
|
|
3272
3151
|
|
|
3273
|
-
const
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
if (isExternal) {
|
|
3278
|
-
return (React__default.createElement("a", { target: "_blank", rel: "noreferrer noopener", href: href, title: title }, children));
|
|
3279
|
-
}
|
|
3280
|
-
return (React__default.createElement(HashLink, { to: href, title: title }, children));
|
|
3281
|
-
};
|
|
3282
|
-
|
|
3283
|
-
const NonIdealState = ({ description, icon, title }) => {
|
|
3284
|
-
return (React.createElement(Flex, { flexDirection: "col", alignItems: "center", justifyContent: "center", textAlign: "center", w: "full", h: "full" },
|
|
3285
|
-
React.createElement(Box, { as: Icon, icon: icon || ['fas', 'exclamation-triangle'], color: "light", fontSize: "6xl", mb: 4 }),
|
|
3286
|
-
React.createElement(Heading, { size: 4, mb: 4 }, title),
|
|
3287
|
-
React.createElement(Text, null, description)));
|
|
3152
|
+
const Logo = ({ logo }) => {
|
|
3153
|
+
var _a;
|
|
3154
|
+
return (React.createElement(Box, { display: "inline", mr: 3, rounded: "lg", overflowY: "hidden", overflowX: "hidden", style: { backgroundColor: (_a = logo.backgroundColor) !== null && _a !== void 0 ? _a : 'transparent' } }, logo.href ? (React.createElement("a", { href: logo.href, target: "_blank", rel: "noopener noreferrer" },
|
|
3155
|
+
React.createElement("img", { src: logo.url, height: "30px", width: "30px", alt: logo.altText }))) : (React.createElement("img", { src: logo.url, height: "30px", width: "30px", alt: logo.altText }))));
|
|
3288
3156
|
};
|
|
3289
3157
|
|
|
3290
3158
|
function useFirstRender() {
|
|
@@ -3510,6 +3378,271 @@ const Version = ({ value }) => {
|
|
|
3510
3378
|
React.createElement(VersionBadge, { value: value, backgroundColor: "#909DAB" })));
|
|
3511
3379
|
};
|
|
3512
3380
|
|
|
3381
|
+
const MobileTopNav = ({ name, logo, tree, pathname, onTocClick, }) => {
|
|
3382
|
+
const [isSidebarOpen, setIsSidebarOpen] = React.useState(false);
|
|
3383
|
+
const handleTocClick = () => {
|
|
3384
|
+
onTocClick();
|
|
3385
|
+
setIsSidebarOpen(false);
|
|
3386
|
+
};
|
|
3387
|
+
return (React.createElement(Flex, { className: "TopNav--mosaic", alignItems: "center", h: "3xl", pl: 4, pr: 4, bg: "canvas", borderB: true, pos: "fixed", w: "full", zIndex: 20 },
|
|
3388
|
+
React.createElement(Flex, { "data-test": "mobile-top-nav", w: "full", alignItems: "center", justifyContent: "between" },
|
|
3389
|
+
React.createElement(Button, { "data-test": "show-left-sidebar-btn", onPress: () => setIsSidebarOpen(true), appearance: "minimal" },
|
|
3390
|
+
React.createElement(Icon, { size: "lg", icon: faBars })),
|
|
3391
|
+
React.createElement(NavHeading, { heading: name })),
|
|
3392
|
+
React.createElement(Drawer, { isOpen: isSidebarOpen, position: "left" },
|
|
3393
|
+
React.createElement(Flex, { justifyContent: "end" },
|
|
3394
|
+
React.createElement(Button, { className: "sl-mr-4 sl-mt-2", onPress: () => setIsSidebarOpen(false), appearance: "minimal", justifySelf: "end" },
|
|
3395
|
+
React.createElement(Icon, { size: "lg", icon: faX }))),
|
|
3396
|
+
React.createElement(Sidebar, { name: name, logo: logo, tree: tree, pathname: pathname, onTocClick: () => handleTocClick(), isInResponsiveMode: true }))));
|
|
3397
|
+
};
|
|
3398
|
+
const NavHeading = ({ heading }) => (React.createElement(Flex, { flex: 1, "data-test": "mobile-project-top-nav", style: { minWidth: 0 } },
|
|
3399
|
+
React.createElement(Box, { fontSize: "xl", fontWeight: "semibold", whitespace: "nowrap", textOverflow: "overflow-ellipsis", overflowX: "hidden", overflowY: "hidden", w: "full", textAlign: "center" }, heading)));
|
|
3400
|
+
|
|
3401
|
+
const MAX_CONTENT_WIDTH$1 = 1800;
|
|
3402
|
+
const SIDEBAR_MIN_WIDTH$1 = 300;
|
|
3403
|
+
const SIDEBAR_MAX_WIDTH$1 = 1.5 * SIDEBAR_MIN_WIDTH$1;
|
|
3404
|
+
const ResponsiveSidebarLayout = React.forwardRef(({ children, name, logo, tree, onTocClick, maxContentWidth = MAX_CONTENT_WIDTH$1, sidebarWidth = SIDEBAR_MIN_WIDTH$1 }, ref) => {
|
|
3405
|
+
const scrollRef = React.useRef(null);
|
|
3406
|
+
const [sidebarRef, currentSidebarWidth, startResizing] = useResizer$1(sidebarWidth);
|
|
3407
|
+
const { pathname } = useLocation();
|
|
3408
|
+
React.useEffect(() => {
|
|
3409
|
+
var _a;
|
|
3410
|
+
(_a = scrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo(0, 0);
|
|
3411
|
+
}, [pathname]);
|
|
3412
|
+
const { isResponsiveLayoutEnabled } = useResponsiveLayout();
|
|
3413
|
+
return (React.createElement(Flex, { ref: ref, className: "sl-elements-api", pin: true, h: "full" },
|
|
3414
|
+
!isResponsiveLayoutEnabled ? (React.createElement(Flex, { ref: sidebarRef, onMouseDown: (e) => e.preventDefault(), style: { maxWidth: `${SIDEBAR_MAX_WIDTH$1}px` } },
|
|
3415
|
+
React.createElement(Flex, { direction: "col", bg: "canvas-100", borderR: true, pt: 8, pos: "sticky", pinY: true, overflowY: "auto", style: {
|
|
3416
|
+
paddingLeft: `calc((100% - ${maxContentWidth}px) / 2)`,
|
|
3417
|
+
width: `${currentSidebarWidth}px`,
|
|
3418
|
+
minWidth: `${SIDEBAR_MIN_WIDTH$1}px`,
|
|
3419
|
+
} },
|
|
3420
|
+
React.createElement(Sidebar, { name: name, logo: logo, tree: tree, pathname: pathname, onTocClick: onTocClick, isInResponsiveMode: false })),
|
|
3421
|
+
React.createElement(Flex, { justifySelf: "end", flexGrow: 0, flexShrink: 0, resize: "x", onMouseDown: startResizing, style: { width: '1em', flexBasis: '6px', cursor: 'ew-resize' } }))) : (React.createElement(MobileTopNav, { onTocClick: onTocClick, name: name, logo: logo, tree: tree, pathname: pathname })),
|
|
3422
|
+
React.createElement(Box, { ref: scrollRef, bg: "canvas", px: !isResponsiveLayoutEnabled ? 24 : 6, flex: 1, w: "full", overflowY: "auto" },
|
|
3423
|
+
React.createElement(Box, { style: { maxWidth: `${maxContentWidth - currentSidebarWidth}px` }, py: 16 }, children))));
|
|
3424
|
+
});
|
|
3425
|
+
const Sidebar = ({ name, logo, tree, pathname, onTocClick, isInResponsiveMode, }) => {
|
|
3426
|
+
return (React.createElement(React.Fragment, null,
|
|
3427
|
+
React.createElement(Flex, { ml: 4, mb: 5, alignItems: "center" },
|
|
3428
|
+
typeof logo === 'string' ? (React.createElement(Logo, { logo: { url: logo, altText: 'logo' } })) : (typeof logo === 'object' && React.createElement(Logo, { logo: logo })),
|
|
3429
|
+
React.createElement(Heading, { size: 4 }, name)),
|
|
3430
|
+
React.createElement(Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
|
|
3431
|
+
React.createElement(TableOfContents, { tree: tree, activeId: pathname, Link: Link$1, onLinkClick: onTocClick, isInResponsiveMode: isInResponsiveMode })),
|
|
3432
|
+
React.createElement(PoweredByLink, { source: name, pathname: pathname, packageType: "elements" })));
|
|
3433
|
+
};
|
|
3434
|
+
function useResizer$1(sidebarWidth) {
|
|
3435
|
+
const sidebarRef = React.useRef(null);
|
|
3436
|
+
const [isResizing, setIsResizing] = React.useState(false);
|
|
3437
|
+
const [currentSidebarWidth, setCurrentSidebarWidth] = React.useState(sidebarWidth);
|
|
3438
|
+
const startResizing = React.useCallback(() => {
|
|
3439
|
+
setIsResizing(true);
|
|
3440
|
+
}, []);
|
|
3441
|
+
const stopResizing = React.useCallback(() => {
|
|
3442
|
+
setIsResizing(false);
|
|
3443
|
+
}, []);
|
|
3444
|
+
const resize = React.useCallback(mouseMoveEvent => {
|
|
3445
|
+
if (isResizing) {
|
|
3446
|
+
const value = mouseMoveEvent.clientX - sidebarRef.current.getBoundingClientRect().left;
|
|
3447
|
+
setCurrentSidebarWidth(Math.min(Math.max(SIDEBAR_MIN_WIDTH$1, value), SIDEBAR_MAX_WIDTH$1));
|
|
3448
|
+
}
|
|
3449
|
+
}, [isResizing]);
|
|
3450
|
+
React.useEffect(() => {
|
|
3451
|
+
window === null || window === void 0 ? void 0 : window.addEventListener('mousemove', resize);
|
|
3452
|
+
window === null || window === void 0 ? void 0 : window.addEventListener('mouseup', stopResizing, { passive: true });
|
|
3453
|
+
return () => {
|
|
3454
|
+
window === null || window === void 0 ? void 0 : window.removeEventListener('mousemove', resize);
|
|
3455
|
+
window === null || window === void 0 ? void 0 : window.removeEventListener('mouseup', stopResizing);
|
|
3456
|
+
};
|
|
3457
|
+
}, [resize, stopResizing]);
|
|
3458
|
+
return [sidebarRef, currentSidebarWidth, startResizing];
|
|
3459
|
+
}
|
|
3460
|
+
|
|
3461
|
+
const MAX_CONTENT_WIDTH = 1800;
|
|
3462
|
+
const SIDEBAR_MIN_WIDTH = 300;
|
|
3463
|
+
const SIDEBAR_MAX_WIDTH = 1.5 * SIDEBAR_MIN_WIDTH;
|
|
3464
|
+
const SidebarLayout = React.forwardRef(({ sidebar, children, maxContentWidth = MAX_CONTENT_WIDTH, sidebarWidth = SIDEBAR_MIN_WIDTH }, ref) => {
|
|
3465
|
+
const scrollRef = React.useRef(null);
|
|
3466
|
+
const [sidebarRef, currentSidebarWidth, startResizing] = useResizer(sidebarWidth);
|
|
3467
|
+
const { pathname } = useLocation();
|
|
3468
|
+
React.useEffect(() => {
|
|
3469
|
+
var _a;
|
|
3470
|
+
(_a = scrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo(0, 0);
|
|
3471
|
+
}, [pathname]);
|
|
3472
|
+
return (React.createElement(Flex, { ref: ref, className: "sl-elements-api", pin: true, h: "full" },
|
|
3473
|
+
React.createElement(Flex, { ref: sidebarRef, onMouseDown: (e) => e.preventDefault(), style: { maxWidth: `${SIDEBAR_MAX_WIDTH}px` } },
|
|
3474
|
+
React.createElement(Flex, { direction: "col", bg: "canvas-100", borderR: true, pt: 8, pos: "sticky", pinY: true, overflowY: "auto", style: {
|
|
3475
|
+
paddingLeft: `calc((100% - ${maxContentWidth}px) / 2)`,
|
|
3476
|
+
width: `${currentSidebarWidth}px`,
|
|
3477
|
+
minWidth: `${SIDEBAR_MIN_WIDTH}px`,
|
|
3478
|
+
} }, sidebar),
|
|
3479
|
+
React.createElement(Flex, { justifySelf: "end", flexGrow: 0, flexShrink: 0, resize: "x", onMouseDown: startResizing, style: { width: '1em', flexBasis: '6px', cursor: 'ew-resize' } })),
|
|
3480
|
+
React.createElement(Box, { ref: scrollRef, bg: "canvas", px: 24, flex: 1, w: "full", overflowY: "auto" },
|
|
3481
|
+
React.createElement(Box, { style: { maxWidth: `${maxContentWidth - currentSidebarWidth}px` }, py: 16 }, children))));
|
|
3482
|
+
});
|
|
3483
|
+
function useResizer(sidebarWidth) {
|
|
3484
|
+
const sidebarRef = React.useRef(null);
|
|
3485
|
+
const [isResizing, setIsResizing] = React.useState(false);
|
|
3486
|
+
const [currentSidebarWidth, setCurrentSidebarWidth] = React.useState(sidebarWidth);
|
|
3487
|
+
const startResizing = React.useCallback(() => {
|
|
3488
|
+
setIsResizing(true);
|
|
3489
|
+
}, []);
|
|
3490
|
+
const stopResizing = React.useCallback(() => {
|
|
3491
|
+
setIsResizing(false);
|
|
3492
|
+
}, []);
|
|
3493
|
+
const resize = React.useCallback(mouseMoveEvent => {
|
|
3494
|
+
if (isResizing) {
|
|
3495
|
+
const value = mouseMoveEvent.clientX - sidebarRef.current.getBoundingClientRect().left;
|
|
3496
|
+
setCurrentSidebarWidth(Math.min(Math.max(SIDEBAR_MIN_WIDTH, value), SIDEBAR_MAX_WIDTH));
|
|
3497
|
+
}
|
|
3498
|
+
}, [isResizing]);
|
|
3499
|
+
React.useEffect(() => {
|
|
3500
|
+
window.addEventListener('mousemove', resize);
|
|
3501
|
+
window.addEventListener('mouseup', stopResizing, { passive: true });
|
|
3502
|
+
return () => {
|
|
3503
|
+
window.removeEventListener('mousemove', resize);
|
|
3504
|
+
window.removeEventListener('mouseup', stopResizing);
|
|
3505
|
+
};
|
|
3506
|
+
}, [resize, stopResizing]);
|
|
3507
|
+
return [sidebarRef, currentSidebarWidth, startResizing];
|
|
3508
|
+
}
|
|
3509
|
+
|
|
3510
|
+
function getDisplayName(WrappedComponent) {
|
|
3511
|
+
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
3512
|
+
}
|
|
3513
|
+
|
|
3514
|
+
const PersistenceContextProvider = Provider;
|
|
3515
|
+
function withPersistenceBoundary(WrappedComponent) {
|
|
3516
|
+
const WithPersistenceBoundary = props => {
|
|
3517
|
+
return (React.createElement(PersistenceContextProvider, null,
|
|
3518
|
+
React.createElement(WrappedComponent, Object.assign({}, props))));
|
|
3519
|
+
};
|
|
3520
|
+
WithPersistenceBoundary.displayName = `withPersistenceBoundary(${getDisplayName(WrappedComponent)})`;
|
|
3521
|
+
return WithPersistenceBoundary;
|
|
3522
|
+
}
|
|
3523
|
+
|
|
3524
|
+
function useParsedValue(value) {
|
|
3525
|
+
return React.useMemo(() => {
|
|
3526
|
+
let parsedValue = value;
|
|
3527
|
+
if (typeof value === 'string') {
|
|
3528
|
+
try {
|
|
3529
|
+
parsedValue = parse(value);
|
|
3530
|
+
}
|
|
3531
|
+
catch (error) {
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3534
|
+
return parsedValue;
|
|
3535
|
+
}, [value]);
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
function isPartialHttpRequest(maybeHttpRequest) {
|
|
3539
|
+
return (isObject(maybeHttpRequest) &&
|
|
3540
|
+
'method' in maybeHttpRequest &&
|
|
3541
|
+
typeof maybeHttpRequest['method'] === 'string' &&
|
|
3542
|
+
'url' in maybeHttpRequest &&
|
|
3543
|
+
typeof maybeHttpRequest['url'] === 'string');
|
|
3544
|
+
}
|
|
3545
|
+
const SchemaAndDescription = ({ title: titleProp, schema }) => {
|
|
3546
|
+
const [resolveRef, maxRefDepth] = useSchemaInlineRefResolver();
|
|
3547
|
+
const title = titleProp !== null && titleProp !== void 0 ? titleProp : schema.title;
|
|
3548
|
+
return (React__default.createElement(Box, { py: 2 },
|
|
3549
|
+
title && (React__default.createElement(Flex, { alignItems: "center", p: 2 },
|
|
3550
|
+
React__default.createElement(Icon, { icon: NodeTypeIconDefs[NodeType.Model], color: NodeTypeColors[NodeType.Model] }),
|
|
3551
|
+
React__default.createElement(Box, { color: "muted", px: 2 }, title))),
|
|
3552
|
+
React__default.createElement(JsonSchemaViewer, { resolveRef: resolveRef, maxRefDepth: maxRefDepth, schema: getOriginalObject(schema) })));
|
|
3553
|
+
};
|
|
3554
|
+
const CodeComponent = props => {
|
|
3555
|
+
const { title, jsonSchema, http, resolved, children } = props;
|
|
3556
|
+
const resolver = useInlineRefResolver();
|
|
3557
|
+
const value = resolved || String(Array.isArray(children) ? children[0] : children);
|
|
3558
|
+
const parsedValue = useParsedValue(value);
|
|
3559
|
+
if (jsonSchema) {
|
|
3560
|
+
if (!isJSONSchema(parsedValue)) {
|
|
3561
|
+
return null;
|
|
3562
|
+
}
|
|
3563
|
+
return (React__default.createElement(InlineRefResolverProvider, { document: parsedValue, resolver: resolver === null || resolver === void 0 ? void 0 : resolver.resolver, maxRefDepth: resolver === null || resolver === void 0 ? void 0 : resolver.maxRefDepth },
|
|
3564
|
+
React__default.createElement(SchemaAndDescription, { title: title, schema: parsedValue })));
|
|
3565
|
+
}
|
|
3566
|
+
if (http) {
|
|
3567
|
+
if (!isObject(parsedValue) || (!isPartialHttpRequest(parsedValue) && !isHttpOperation(parsedValue))) {
|
|
3568
|
+
return null;
|
|
3569
|
+
}
|
|
3570
|
+
return (React__default.createElement(PersistenceContextProvider, null,
|
|
3571
|
+
React__default.createElement(TryIt, { httpOperation: isHttpOperation(parsedValue) ? parsedValue : parseHttpRequest(parsedValue), embeddedInMd: true })));
|
|
3572
|
+
}
|
|
3573
|
+
const DefaultCode = DefaultSMDComponents.code;
|
|
3574
|
+
return React__default.createElement(DefaultCode, Object.assign({}, props));
|
|
3575
|
+
};
|
|
3576
|
+
function parseHttpRequest(data) {
|
|
3577
|
+
const uri = URI(data.url);
|
|
3578
|
+
const pathParam = data.url.match(/[^{\}]+(?=})/g);
|
|
3579
|
+
return {
|
|
3580
|
+
id: '?http-operation-id?',
|
|
3581
|
+
method: data.method,
|
|
3582
|
+
path: uri.is('absolute') ? uri.path() : data.url,
|
|
3583
|
+
servers: [{ id: `?http-server-${uri.href()}?`, url: uri.is('absolute') ? uri.origin() : data.baseUrl || '' }],
|
|
3584
|
+
request: Object.assign({ query: Object.entries(data.query || {}).map(([key, value]) => {
|
|
3585
|
+
const defaultVal = Array.isArray(value) ? value[0] : value;
|
|
3586
|
+
return {
|
|
3587
|
+
id: `?http-query-${key}-id?`,
|
|
3588
|
+
name: key,
|
|
3589
|
+
style: HttpParamStyles.Form,
|
|
3590
|
+
schema: { default: defaultVal },
|
|
3591
|
+
required: isHttpRequestParamRequired(defaultVal),
|
|
3592
|
+
};
|
|
3593
|
+
}), headers: Object.entries(data.headers || {}).map(([key, value]) => ({
|
|
3594
|
+
id: `?http-header-${key}-id?`,
|
|
3595
|
+
name: key,
|
|
3596
|
+
style: HttpParamStyles.Simple,
|
|
3597
|
+
schema: { default: value },
|
|
3598
|
+
required: isHttpRequestParamRequired(value),
|
|
3599
|
+
})), path: pathParam === null || pathParam === void 0 ? void 0 : pathParam.map(name => ({
|
|
3600
|
+
id: `?http-param-${name}-id?`,
|
|
3601
|
+
name,
|
|
3602
|
+
style: HttpParamStyles.Simple,
|
|
3603
|
+
required: true,
|
|
3604
|
+
})) }, (data.body
|
|
3605
|
+
? {
|
|
3606
|
+
body: {
|
|
3607
|
+
id: '?http-request-body?',
|
|
3608
|
+
contents: [
|
|
3609
|
+
{
|
|
3610
|
+
id: '?http-request-body-media?',
|
|
3611
|
+
mediaType: 'application/json',
|
|
3612
|
+
schema: { default: data.body },
|
|
3613
|
+
},
|
|
3614
|
+
],
|
|
3615
|
+
},
|
|
3616
|
+
}
|
|
3617
|
+
: null)),
|
|
3618
|
+
responses: [],
|
|
3619
|
+
};
|
|
3620
|
+
}
|
|
3621
|
+
function isHttpRequestParamRequired(value) {
|
|
3622
|
+
return typeof value !== 'undefined';
|
|
3623
|
+
}
|
|
3624
|
+
|
|
3625
|
+
const MarkdownComponentsProvider = ({ value, children }) => {
|
|
3626
|
+
return React.createElement(MarkdownViewerProvider, { components: Object.assign({ code: CodeComponent }, value) }, children);
|
|
3627
|
+
};
|
|
3628
|
+
|
|
3629
|
+
const externalRegex = new RegExp('^(?:[a-z]+:)?//', 'i');
|
|
3630
|
+
const ReactRouterMarkdownLink = ({ title, to, href: _href, children, }) => {
|
|
3631
|
+
const href = to || _href;
|
|
3632
|
+
const isExternal = href !== undefined && externalRegex.test(href);
|
|
3633
|
+
if (isExternal) {
|
|
3634
|
+
return (React__default.createElement("a", { target: "_blank", rel: "noreferrer noopener", href: href, title: title }, children));
|
|
3635
|
+
}
|
|
3636
|
+
return (React__default.createElement(HashLink, { to: href, title: title }, children));
|
|
3637
|
+
};
|
|
3638
|
+
|
|
3639
|
+
const NonIdealState = ({ description, icon, title }) => {
|
|
3640
|
+
return (React.createElement(Flex, { flexDirection: "col", alignItems: "center", justifyContent: "center", textAlign: "center", w: "full", h: "full" },
|
|
3641
|
+
React.createElement(Box, { as: Icon, icon: icon || ['fas', 'exclamation-triangle'], color: "light", fontSize: "6xl", mb: 4 }),
|
|
3642
|
+
React.createElement(Heading, { size: 4, mb: 4 }, title),
|
|
3643
|
+
React.createElement(Text, null, description)));
|
|
3644
|
+
};
|
|
3645
|
+
|
|
3513
3646
|
function withMosaicProvider(WrappedComponent) {
|
|
3514
3647
|
const WithMosaicProvider = (props) => {
|
|
3515
3648
|
try {
|
|
@@ -3761,4 +3894,4 @@ const createElementClass = (Component, propDescriptors) => {
|
|
|
3761
3894
|
};
|
|
3762
3895
|
};
|
|
3763
3896
|
|
|
3764
|
-
export { DeprecatedBadge, Docs, ExportButton, HttpMethodColors, InlineRefResolverProvider, Logo, MarkdownComponentsProvider, MockingProvider, NodeTypeColors, NodeTypeIconDefs, NodeTypePrettyName, NonIdealState, ParsedDocs, PersistenceContextProvider, PoweredByLink, ReactRouterMarkdownLink, RouterTypeContext, SidebarLayout, Styled, TableOfContents, TryIt, TryItWithRequestSamples, createElementClass, createResolvedObject, findFirstNode, isHttpOperation, isHttpService, isHttpWebhookOperation, slugify, useBundleRefsIntoDocument, useParsedData, useParsedValue, useRouter, withMosaicProvider, withPersistenceBoundary, withQueryClientProvider, withRouter, withStyles };
|
|
3897
|
+
export { DeprecatedBadge, Docs, ExportButton, HttpMethodColors, InlineRefResolverProvider, LinkHeading, Logo, MarkdownComponentsProvider, MockingProvider, NodeTypeColors, NodeTypeIconDefs, NodeTypePrettyName, NonIdealState, ParsedDocs, PersistenceContextProvider, PoweredByLink, ReactRouterMarkdownLink, ResponsiveSidebarLayout, RouterTypeContext, SidebarLayout, Styled, TableOfContents, TryIt, TryItWithRequestSamples, createElementClass, createResolvedObject, findFirstNode, isHttpOperation, isHttpService, isHttpWebhookOperation, slugify, useBundleRefsIntoDocument, useParsedData, useParsedValue, useResponsiveLayout, useRouter, withMosaicProvider, withPersistenceBoundary, withQueryClientProvider, withRouter, withStyles };
|