@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/index.js CHANGED
@@ -365,6 +365,11 @@ const Article = reactErrorBoundary.withErrorBoundary(ArticleComponent, { recover
365
365
  * License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
366
366
  * Copyright 2022 Fonticons, Inc.
367
367
  */
368
+ var faBars = {
369
+ prefix: 'fas',
370
+ iconName: 'bars',
371
+ 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"]
372
+ };
368
373
  var faBolt = {
369
374
  prefix: 'fas',
370
375
  iconName: 'bolt',
@@ -436,6 +441,11 @@ var faServer = {
436
441
  iconName: 'server',
437
442
  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"]
438
443
  };
444
+ var faX = {
445
+ prefix: 'fas',
446
+ iconName: 'x',
447
+ 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"]
448
+ };
439
449
 
440
450
  const NodeTypeColors = {
441
451
  http_operation: '#6a6acb',
@@ -3153,195 +3163,53 @@ const ParsedDocs = (_a) => {
3153
3163
  }
3154
3164
  };
3155
3165
 
3156
- const MAX_CONTENT_WIDTH = 1800;
3157
- const SIDEBAR_MIN_WIDTH = 300;
3158
- const SIDEBAR_MAX_WIDTH = 1.5 * SIDEBAR_MIN_WIDTH;
3159
- const SidebarLayout = React__namespace.forwardRef(({ sidebar, children, maxContentWidth = MAX_CONTENT_WIDTH, sidebarWidth = SIDEBAR_MIN_WIDTH }, ref) => {
3160
- const scrollRef = React__namespace.useRef(null);
3161
- const [sidebarRef, currentSidebarWidth, startResizing] = useResizer(sidebarWidth);
3162
- const { pathname } = reactRouterDom.useLocation();
3163
- React__namespace.useEffect(() => {
3164
- var _a;
3165
- (_a = scrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo(0, 0);
3166
- }, [pathname]);
3167
- return (React__namespace.createElement(mosaic.Flex, { ref: ref, className: "sl-elements-api", pin: true, h: "full" },
3168
- React__namespace.createElement(mosaic.Flex, { ref: sidebarRef, onMouseDown: (e) => e.preventDefault(), style: { maxWidth: `${SIDEBAR_MAX_WIDTH}px` } },
3169
- React__namespace.createElement(mosaic.Flex, { direction: "col", bg: "canvas-100", borderR: true, pt: 8, pos: "sticky", pinY: true, overflowY: "auto", style: {
3170
- paddingLeft: `calc((100% - ${maxContentWidth}px) / 2)`,
3171
- width: `${currentSidebarWidth}px`,
3172
- minWidth: `${SIDEBAR_MIN_WIDTH}px`,
3173
- } }, sidebar),
3174
- React__namespace.createElement(mosaic.Flex, { justifySelf: "end", flexGrow: 0, flexShrink: 0, resize: "x", onMouseDown: startResizing, style: { width: '1em', flexBasis: '6px', cursor: 'ew-resize' } })),
3175
- React__namespace.createElement(mosaic.Box, { ref: scrollRef, bg: "canvas", px: 24, flex: 1, w: "full", overflowY: "auto" },
3176
- React__namespace.createElement(mosaic.Box, { style: { maxWidth: `${maxContentWidth - currentSidebarWidth}px` }, py: 16 }, children))));
3177
- });
3178
- function useResizer(sidebarWidth) {
3179
- const sidebarRef = React__namespace.useRef(null);
3180
- const [isResizing, setIsResizing] = React__namespace.useState(false);
3181
- const [currentSidebarWidth, setCurrentSidebarWidth] = React__namespace.useState(sidebarWidth);
3182
- const startResizing = React__namespace.useCallback(() => {
3183
- setIsResizing(true);
3184
- }, []);
3185
- const stopResizing = React__namespace.useCallback(() => {
3186
- setIsResizing(false);
3187
- }, []);
3188
- const resize = React__namespace.useCallback(mouseMoveEvent => {
3189
- if (isResizing) {
3190
- const value = mouseMoveEvent.clientX - sidebarRef.current.getBoundingClientRect().left;
3191
- setCurrentSidebarWidth(Math.min(Math.max(SIDEBAR_MIN_WIDTH, value), SIDEBAR_MAX_WIDTH));
3192
- }
3193
- }, [isResizing]);
3194
- React__namespace.useEffect(() => {
3195
- window.addEventListener('mousemove', resize);
3196
- window.addEventListener('mouseup', stopResizing, { passive: true });
3197
- return () => {
3198
- window.removeEventListener('mousemove', resize);
3199
- window.removeEventListener('mouseup', stopResizing);
3200
- };
3201
- }, [resize, stopResizing]);
3202
- return [sidebarRef, currentSidebarWidth, startResizing];
3203
- }
3204
-
3205
- const Logo = ({ logo }) => {
3206
- var _a;
3207
- return (React__namespace.createElement(mosaic.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__namespace.createElement("a", { href: logo.href, target: "_blank", rel: "noopener noreferrer" },
3208
- React__namespace.createElement("img", { src: logo.url, height: "30px", width: "30px", alt: logo.altText }))) : (React__namespace.createElement("img", { src: logo.url, height: "30px", width: "30px", alt: logo.altText }))));
3209
- };
3210
-
3211
- function getDisplayName(WrappedComponent) {
3212
- return WrappedComponent.displayName || WrappedComponent.name || 'Component';
3213
- }
3214
-
3215
- const PersistenceContextProvider = jotai.Provider;
3216
- function withPersistenceBoundary(WrappedComponent) {
3217
- const WithPersistenceBoundary = props => {
3218
- return (React__namespace.createElement(PersistenceContextProvider, null,
3219
- React__namespace.createElement(WrappedComponent, Object.assign({}, props))));
3220
- };
3221
- WithPersistenceBoundary.displayName = `withPersistenceBoundary(${getDisplayName(WrappedComponent)})`;
3222
- return WithPersistenceBoundary;
3223
- }
3224
-
3225
- function useParsedValue(value) {
3226
- return React__namespace.useMemo(() => {
3227
- let parsedValue = value;
3228
- if (typeof value === 'string') {
3229
- try {
3230
- parsedValue = yaml.parse(value);
3231
- }
3232
- catch (error) {
3233
- }
3234
- }
3235
- return parsedValue;
3236
- }, [value]);
3237
- }
3238
-
3239
- function isPartialHttpRequest(maybeHttpRequest) {
3240
- return (isObject__default["default"](maybeHttpRequest) &&
3241
- 'method' in maybeHttpRequest &&
3242
- typeof maybeHttpRequest['method'] === 'string' &&
3243
- 'url' in maybeHttpRequest &&
3244
- typeof maybeHttpRequest['url'] === 'string');
3245
- }
3246
- const SchemaAndDescription = ({ title: titleProp, schema }) => {
3247
- const [resolveRef, maxRefDepth] = useSchemaInlineRefResolver();
3248
- const title = titleProp !== null && titleProp !== void 0 ? titleProp : schema.title;
3249
- return (React__default["default"].createElement(mosaic.Box, { py: 2 },
3250
- title && (React__default["default"].createElement(mosaic.Flex, { alignItems: "center", p: 2 },
3251
- React__default["default"].createElement(mosaic.Icon, { icon: NodeTypeIconDefs[types.NodeType.Model], color: NodeTypeColors[types.NodeType.Model] }),
3252
- React__default["default"].createElement(mosaic.Box, { color: "muted", px: 2 }, title))),
3253
- React__default["default"].createElement(jsonSchemaViewer.JsonSchemaViewer, { resolveRef: resolveRef, maxRefDepth: maxRefDepth, schema: getOriginalObject(schema) })));
3166
+ const ElementsBreakpoints = {
3167
+ docs: 700,
3254
3168
  };
3255
- const CodeComponent = props => {
3256
- const { title, jsonSchema, http, resolved, children } = props;
3257
- const resolver = useInlineRefResolver();
3258
- const value = resolved || String(Array.isArray(children) ? children[0] : children);
3259
- const parsedValue = useParsedValue(value);
3260
- if (jsonSchema) {
3261
- if (!isJSONSchema(parsedValue)) {
3262
- return null;
3263
- }
3264
- return (React__default["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 },
3265
- React__default["default"].createElement(SchemaAndDescription, { title: title, schema: parsedValue })));
3169
+ var ScreenType;
3170
+ (function (ScreenType) {
3171
+ ScreenType[ScreenType["Phone"] = 415] = "Phone";
3172
+ ScreenType[ScreenType["Tablet"] = 750] = "Tablet";
3173
+ ScreenType[ScreenType["Resized_Browser"] = 980] = "Resized_Browser";
3174
+ ScreenType[ScreenType["Normal_Browser"] = 1000000] = "Normal_Browser";
3175
+ })(ScreenType || (ScreenType = {}));
3176
+ const getScreenType = () => {
3177
+ if ((window === null || window === void 0 ? void 0 : window.innerWidth) <= ScreenType.Phone) {
3178
+ return ScreenType.Phone;
3266
3179
  }
3267
- if (http) {
3268
- if (!isObject__default["default"](parsedValue) || (!isPartialHttpRequest(parsedValue) && !isHttpOperation(parsedValue))) {
3269
- return null;
3270
- }
3271
- return (React__default["default"].createElement(PersistenceContextProvider, null,
3272
- React__default["default"].createElement(TryIt, { httpOperation: isHttpOperation(parsedValue) ? parsedValue : parseHttpRequest(parsedValue), embeddedInMd: true })));
3180
+ else if ((window === null || window === void 0 ? void 0 : window.innerWidth) <= ScreenType.Tablet) {
3181
+ return ScreenType.Tablet;
3273
3182
  }
3274
- const DefaultCode = markdownViewer.DefaultSMDComponents.code;
3275
- return React__default["default"].createElement(DefaultCode, Object.assign({}, props));
3183
+ else if ((window === null || window === void 0 ? void 0 : window.innerWidth) <= ScreenType.Resized_Browser) {
3184
+ return ScreenType.Resized_Browser;
3185
+ }
3186
+ return ScreenType.Normal_Browser;
3276
3187
  };
3277
- function parseHttpRequest(data) {
3278
- const uri = URI__default["default"](data.url);
3279
- const pathParam = data.url.match(/[^{\}]+(?=})/g);
3188
+ const useResponsiveLayout = () => {
3189
+ const [screenType, setScreenType] = React__namespace.useState();
3190
+ const getElementsBreakpoint = (node) => {
3191
+ return ElementsBreakpoints[node];
3192
+ };
3193
+ React__namespace.useLayoutEffect(() => {
3194
+ function handleResize() {
3195
+ setScreenType(getScreenType());
3196
+ }
3197
+ window === null || window === void 0 ? void 0 : window.addEventListener('resize', handleResize);
3198
+ handleResize();
3199
+ return () => window === null || window === void 0 ? void 0 : window.removeEventListener('resize', handleResize);
3200
+ }, []);
3201
+ const isResponsiveLayoutEnabled = screenType !== ScreenType.Normal_Browser;
3280
3202
  return {
3281
- id: '?http-operation-id?',
3282
- method: data.method,
3283
- path: uri.is('absolute') ? uri.path() : data.url,
3284
- servers: [{ id: `?http-server-${uri.href()}?`, url: uri.is('absolute') ? uri.origin() : data.baseUrl || '' }],
3285
- request: Object.assign({ query: Object.entries(data.query || {}).map(([key, value]) => {
3286
- const defaultVal = Array.isArray(value) ? value[0] : value;
3287
- return {
3288
- id: `?http-query-${key}-id?`,
3289
- name: key,
3290
- style: types.HttpParamStyles.Form,
3291
- schema: { default: defaultVal },
3292
- required: isHttpRequestParamRequired(defaultVal),
3293
- };
3294
- }), headers: Object.entries(data.headers || {}).map(([key, value]) => ({
3295
- id: `?http-header-${key}-id?`,
3296
- name: key,
3297
- style: types.HttpParamStyles.Simple,
3298
- schema: { default: value },
3299
- required: isHttpRequestParamRequired(value),
3300
- })), path: pathParam === null || pathParam === void 0 ? void 0 : pathParam.map(name => ({
3301
- id: `?http-param-${name}-id?`,
3302
- name,
3303
- style: types.HttpParamStyles.Simple,
3304
- required: true,
3305
- })) }, (data.body
3306
- ? {
3307
- body: {
3308
- id: '?http-request-body?',
3309
- contents: [
3310
- {
3311
- id: '?http-request-body-media?',
3312
- mediaType: 'application/json',
3313
- schema: { default: data.body },
3314
- },
3315
- ],
3316
- },
3317
- }
3318
- : null)),
3319
- responses: [],
3203
+ isResponsiveLayoutEnabled,
3204
+ screenType,
3205
+ getElementsBreakpoint,
3320
3206
  };
3321
- }
3322
- function isHttpRequestParamRequired(value) {
3323
- return typeof value !== 'undefined';
3324
- }
3325
-
3326
- const MarkdownComponentsProvider = ({ value, children }) => {
3327
- return React__namespace.createElement(markdownViewer.MarkdownViewerProvider, { components: Object.assign({ code: CodeComponent }, value) }, children);
3328
3207
  };
3329
3208
 
3330
- const externalRegex = new RegExp('^(?:[a-z]+:)?//', 'i');
3331
- const ReactRouterMarkdownLink = ({ title, to, href: _href, children, }) => {
3332
- const href = to || _href;
3333
- const isExternal = href !== undefined && externalRegex.test(href);
3334
- if (isExternal) {
3335
- return (React__default["default"].createElement("a", { target: "_blank", rel: "noreferrer noopener", href: href, title: title }, children));
3336
- }
3337
- return (React__default["default"].createElement(reactRouterHashLink.HashLink, { to: href, title: title }, children));
3338
- };
3339
-
3340
- const NonIdealState = ({ description, icon, title }) => {
3341
- return (React__namespace.createElement(mosaic.Flex, { flexDirection: "col", alignItems: "center", justifyContent: "center", textAlign: "center", w: "full", h: "full" },
3342
- React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, icon: icon || ['fas', 'exclamation-triangle'], color: "light", fontSize: "6xl", mb: 4 }),
3343
- React__namespace.createElement(mosaic.Heading, { size: 4, mb: 4 }, title),
3344
- React__namespace.createElement(mosaic.Text, null, description)));
3209
+ const Logo = ({ logo }) => {
3210
+ var _a;
3211
+ return (React__namespace.createElement(mosaic.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__namespace.createElement("a", { href: logo.href, target: "_blank", rel: "noopener noreferrer" },
3212
+ React__namespace.createElement("img", { src: logo.url, height: "30px", width: "30px", alt: logo.altText }))) : (React__namespace.createElement("img", { src: logo.url, height: "30px", width: "30px", alt: logo.altText }))));
3345
3213
  };
3346
3214
 
3347
3215
  function useFirstRender() {
@@ -3567,6 +3435,271 @@ const Version = ({ value }) => {
3567
3435
  React__namespace.createElement(VersionBadge, { value: value, backgroundColor: "#909DAB" })));
3568
3436
  };
3569
3437
 
3438
+ const MobileTopNav = ({ name, logo, tree, pathname, onTocClick, }) => {
3439
+ const [isSidebarOpen, setIsSidebarOpen] = React__namespace.useState(false);
3440
+ const handleTocClick = () => {
3441
+ onTocClick();
3442
+ setIsSidebarOpen(false);
3443
+ };
3444
+ return (React__namespace.createElement(mosaic.Flex, { className: "TopNav--mosaic", alignItems: "center", h: "3xl", pl: 4, pr: 4, bg: "canvas", borderB: true, pos: "fixed", w: "full", zIndex: 20 },
3445
+ React__namespace.createElement(mosaic.Flex, { "data-test": "mobile-top-nav", w: "full", alignItems: "center", justifyContent: "between" },
3446
+ React__namespace.createElement(mosaic.Button, { "data-test": "show-left-sidebar-btn", onPress: () => setIsSidebarOpen(true), appearance: "minimal" },
3447
+ React__namespace.createElement(mosaic.Icon, { size: "lg", icon: faBars })),
3448
+ React__namespace.createElement(NavHeading, { heading: name })),
3449
+ React__namespace.createElement(mosaic.Drawer, { isOpen: isSidebarOpen, position: "left" },
3450
+ React__namespace.createElement(mosaic.Flex, { justifyContent: "end" },
3451
+ React__namespace.createElement(mosaic.Button, { className: "sl-mr-4 sl-mt-2", onPress: () => setIsSidebarOpen(false), appearance: "minimal", justifySelf: "end" },
3452
+ React__namespace.createElement(mosaic.Icon, { size: "lg", icon: faX }))),
3453
+ React__namespace.createElement(Sidebar, { name: name, logo: logo, tree: tree, pathname: pathname, onTocClick: () => handleTocClick(), isInResponsiveMode: true }))));
3454
+ };
3455
+ const NavHeading = ({ heading }) => (React__namespace.createElement(mosaic.Flex, { flex: 1, "data-test": "mobile-project-top-nav", style: { minWidth: 0 } },
3456
+ React__namespace.createElement(mosaic.Box, { fontSize: "xl", fontWeight: "semibold", whitespace: "nowrap", textOverflow: "overflow-ellipsis", overflowX: "hidden", overflowY: "hidden", w: "full", textAlign: "center" }, heading)));
3457
+
3458
+ const MAX_CONTENT_WIDTH$1 = 1800;
3459
+ const SIDEBAR_MIN_WIDTH$1 = 300;
3460
+ const SIDEBAR_MAX_WIDTH$1 = 1.5 * SIDEBAR_MIN_WIDTH$1;
3461
+ const ResponsiveSidebarLayout = React__namespace.forwardRef(({ children, name, logo, tree, onTocClick, maxContentWidth = MAX_CONTENT_WIDTH$1, sidebarWidth = SIDEBAR_MIN_WIDTH$1 }, ref) => {
3462
+ const scrollRef = React__namespace.useRef(null);
3463
+ const [sidebarRef, currentSidebarWidth, startResizing] = useResizer$1(sidebarWidth);
3464
+ const { pathname } = reactRouterDom.useLocation();
3465
+ React__namespace.useEffect(() => {
3466
+ var _a;
3467
+ (_a = scrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo(0, 0);
3468
+ }, [pathname]);
3469
+ const { isResponsiveLayoutEnabled } = useResponsiveLayout();
3470
+ return (React__namespace.createElement(mosaic.Flex, { ref: ref, className: "sl-elements-api", pin: true, h: "full" },
3471
+ !isResponsiveLayoutEnabled ? (React__namespace.createElement(mosaic.Flex, { ref: sidebarRef, onMouseDown: (e) => e.preventDefault(), style: { maxWidth: `${SIDEBAR_MAX_WIDTH$1}px` } },
3472
+ React__namespace.createElement(mosaic.Flex, { direction: "col", bg: "canvas-100", borderR: true, pt: 8, pos: "sticky", pinY: true, overflowY: "auto", style: {
3473
+ paddingLeft: `calc((100% - ${maxContentWidth}px) / 2)`,
3474
+ width: `${currentSidebarWidth}px`,
3475
+ minWidth: `${SIDEBAR_MIN_WIDTH$1}px`,
3476
+ } },
3477
+ React__namespace.createElement(Sidebar, { name: name, logo: logo, tree: tree, pathname: pathname, onTocClick: onTocClick, isInResponsiveMode: false })),
3478
+ React__namespace.createElement(mosaic.Flex, { justifySelf: "end", flexGrow: 0, flexShrink: 0, resize: "x", onMouseDown: startResizing, style: { width: '1em', flexBasis: '6px', cursor: 'ew-resize' } }))) : (React__namespace.createElement(MobileTopNav, { onTocClick: onTocClick, name: name, logo: logo, tree: tree, pathname: pathname })),
3479
+ React__namespace.createElement(mosaic.Box, { ref: scrollRef, bg: "canvas", px: !isResponsiveLayoutEnabled ? 24 : 6, flex: 1, w: "full", overflowY: "auto" },
3480
+ React__namespace.createElement(mosaic.Box, { style: { maxWidth: `${maxContentWidth - currentSidebarWidth}px` }, py: 16 }, children))));
3481
+ });
3482
+ const Sidebar = ({ name, logo, tree, pathname, onTocClick, isInResponsiveMode, }) => {
3483
+ return (React__namespace.createElement(React__namespace.Fragment, null,
3484
+ React__namespace.createElement(mosaic.Flex, { ml: 4, mb: 5, alignItems: "center" },
3485
+ typeof logo === 'string' ? (React__namespace.createElement(Logo, { logo: { url: logo, altText: 'logo' } })) : (typeof logo === 'object' && React__namespace.createElement(Logo, { logo: logo })),
3486
+ React__namespace.createElement(mosaic.Heading, { size: 4 }, name)),
3487
+ React__namespace.createElement(mosaic.Flex, { flexGrow: true, flexShrink: true, overflowY: "auto", direction: "col" },
3488
+ React__namespace.createElement(TableOfContents, { tree: tree, activeId: pathname, Link: reactRouterDom.Link, onLinkClick: onTocClick, isInResponsiveMode: isInResponsiveMode })),
3489
+ React__namespace.createElement(PoweredByLink, { source: name, pathname: pathname, packageType: "elements" })));
3490
+ };
3491
+ function useResizer$1(sidebarWidth) {
3492
+ const sidebarRef = React__namespace.useRef(null);
3493
+ const [isResizing, setIsResizing] = React__namespace.useState(false);
3494
+ const [currentSidebarWidth, setCurrentSidebarWidth] = React__namespace.useState(sidebarWidth);
3495
+ const startResizing = React__namespace.useCallback(() => {
3496
+ setIsResizing(true);
3497
+ }, []);
3498
+ const stopResizing = React__namespace.useCallback(() => {
3499
+ setIsResizing(false);
3500
+ }, []);
3501
+ const resize = React__namespace.useCallback(mouseMoveEvent => {
3502
+ if (isResizing) {
3503
+ const value = mouseMoveEvent.clientX - sidebarRef.current.getBoundingClientRect().left;
3504
+ setCurrentSidebarWidth(Math.min(Math.max(SIDEBAR_MIN_WIDTH$1, value), SIDEBAR_MAX_WIDTH$1));
3505
+ }
3506
+ }, [isResizing]);
3507
+ React__namespace.useEffect(() => {
3508
+ window === null || window === void 0 ? void 0 : window.addEventListener('mousemove', resize);
3509
+ window === null || window === void 0 ? void 0 : window.addEventListener('mouseup', stopResizing, { passive: true });
3510
+ return () => {
3511
+ window === null || window === void 0 ? void 0 : window.removeEventListener('mousemove', resize);
3512
+ window === null || window === void 0 ? void 0 : window.removeEventListener('mouseup', stopResizing);
3513
+ };
3514
+ }, [resize, stopResizing]);
3515
+ return [sidebarRef, currentSidebarWidth, startResizing];
3516
+ }
3517
+
3518
+ const MAX_CONTENT_WIDTH = 1800;
3519
+ const SIDEBAR_MIN_WIDTH = 300;
3520
+ const SIDEBAR_MAX_WIDTH = 1.5 * SIDEBAR_MIN_WIDTH;
3521
+ const SidebarLayout = React__namespace.forwardRef(({ sidebar, children, maxContentWidth = MAX_CONTENT_WIDTH, sidebarWidth = SIDEBAR_MIN_WIDTH }, ref) => {
3522
+ const scrollRef = React__namespace.useRef(null);
3523
+ const [sidebarRef, currentSidebarWidth, startResizing] = useResizer(sidebarWidth);
3524
+ const { pathname } = reactRouterDom.useLocation();
3525
+ React__namespace.useEffect(() => {
3526
+ var _a;
3527
+ (_a = scrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo(0, 0);
3528
+ }, [pathname]);
3529
+ return (React__namespace.createElement(mosaic.Flex, { ref: ref, className: "sl-elements-api", pin: true, h: "full" },
3530
+ React__namespace.createElement(mosaic.Flex, { ref: sidebarRef, onMouseDown: (e) => e.preventDefault(), style: { maxWidth: `${SIDEBAR_MAX_WIDTH}px` } },
3531
+ React__namespace.createElement(mosaic.Flex, { direction: "col", bg: "canvas-100", borderR: true, pt: 8, pos: "sticky", pinY: true, overflowY: "auto", style: {
3532
+ paddingLeft: `calc((100% - ${maxContentWidth}px) / 2)`,
3533
+ width: `${currentSidebarWidth}px`,
3534
+ minWidth: `${SIDEBAR_MIN_WIDTH}px`,
3535
+ } }, sidebar),
3536
+ React__namespace.createElement(mosaic.Flex, { justifySelf: "end", flexGrow: 0, flexShrink: 0, resize: "x", onMouseDown: startResizing, style: { width: '1em', flexBasis: '6px', cursor: 'ew-resize' } })),
3537
+ React__namespace.createElement(mosaic.Box, { ref: scrollRef, bg: "canvas", px: 24, flex: 1, w: "full", overflowY: "auto" },
3538
+ React__namespace.createElement(mosaic.Box, { style: { maxWidth: `${maxContentWidth - currentSidebarWidth}px` }, py: 16 }, children))));
3539
+ });
3540
+ function useResizer(sidebarWidth) {
3541
+ const sidebarRef = React__namespace.useRef(null);
3542
+ const [isResizing, setIsResizing] = React__namespace.useState(false);
3543
+ const [currentSidebarWidth, setCurrentSidebarWidth] = React__namespace.useState(sidebarWidth);
3544
+ const startResizing = React__namespace.useCallback(() => {
3545
+ setIsResizing(true);
3546
+ }, []);
3547
+ const stopResizing = React__namespace.useCallback(() => {
3548
+ setIsResizing(false);
3549
+ }, []);
3550
+ const resize = React__namespace.useCallback(mouseMoveEvent => {
3551
+ if (isResizing) {
3552
+ const value = mouseMoveEvent.clientX - sidebarRef.current.getBoundingClientRect().left;
3553
+ setCurrentSidebarWidth(Math.min(Math.max(SIDEBAR_MIN_WIDTH, value), SIDEBAR_MAX_WIDTH));
3554
+ }
3555
+ }, [isResizing]);
3556
+ React__namespace.useEffect(() => {
3557
+ window.addEventListener('mousemove', resize);
3558
+ window.addEventListener('mouseup', stopResizing, { passive: true });
3559
+ return () => {
3560
+ window.removeEventListener('mousemove', resize);
3561
+ window.removeEventListener('mouseup', stopResizing);
3562
+ };
3563
+ }, [resize, stopResizing]);
3564
+ return [sidebarRef, currentSidebarWidth, startResizing];
3565
+ }
3566
+
3567
+ function getDisplayName(WrappedComponent) {
3568
+ return WrappedComponent.displayName || WrappedComponent.name || 'Component';
3569
+ }
3570
+
3571
+ const PersistenceContextProvider = jotai.Provider;
3572
+ function withPersistenceBoundary(WrappedComponent) {
3573
+ const WithPersistenceBoundary = props => {
3574
+ return (React__namespace.createElement(PersistenceContextProvider, null,
3575
+ React__namespace.createElement(WrappedComponent, Object.assign({}, props))));
3576
+ };
3577
+ WithPersistenceBoundary.displayName = `withPersistenceBoundary(${getDisplayName(WrappedComponent)})`;
3578
+ return WithPersistenceBoundary;
3579
+ }
3580
+
3581
+ function useParsedValue(value) {
3582
+ return React__namespace.useMemo(() => {
3583
+ let parsedValue = value;
3584
+ if (typeof value === 'string') {
3585
+ try {
3586
+ parsedValue = yaml.parse(value);
3587
+ }
3588
+ catch (error) {
3589
+ }
3590
+ }
3591
+ return parsedValue;
3592
+ }, [value]);
3593
+ }
3594
+
3595
+ function isPartialHttpRequest(maybeHttpRequest) {
3596
+ return (isObject__default["default"](maybeHttpRequest) &&
3597
+ 'method' in maybeHttpRequest &&
3598
+ typeof maybeHttpRequest['method'] === 'string' &&
3599
+ 'url' in maybeHttpRequest &&
3600
+ typeof maybeHttpRequest['url'] === 'string');
3601
+ }
3602
+ const SchemaAndDescription = ({ title: titleProp, schema }) => {
3603
+ const [resolveRef, maxRefDepth] = useSchemaInlineRefResolver();
3604
+ const title = titleProp !== null && titleProp !== void 0 ? titleProp : schema.title;
3605
+ return (React__default["default"].createElement(mosaic.Box, { py: 2 },
3606
+ title && (React__default["default"].createElement(mosaic.Flex, { alignItems: "center", p: 2 },
3607
+ React__default["default"].createElement(mosaic.Icon, { icon: NodeTypeIconDefs[types.NodeType.Model], color: NodeTypeColors[types.NodeType.Model] }),
3608
+ React__default["default"].createElement(mosaic.Box, { color: "muted", px: 2 }, title))),
3609
+ React__default["default"].createElement(jsonSchemaViewer.JsonSchemaViewer, { resolveRef: resolveRef, maxRefDepth: maxRefDepth, schema: getOriginalObject(schema) })));
3610
+ };
3611
+ const CodeComponent = props => {
3612
+ const { title, jsonSchema, http, resolved, children } = props;
3613
+ const resolver = useInlineRefResolver();
3614
+ const value = resolved || String(Array.isArray(children) ? children[0] : children);
3615
+ const parsedValue = useParsedValue(value);
3616
+ if (jsonSchema) {
3617
+ if (!isJSONSchema(parsedValue)) {
3618
+ return null;
3619
+ }
3620
+ return (React__default["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 },
3621
+ React__default["default"].createElement(SchemaAndDescription, { title: title, schema: parsedValue })));
3622
+ }
3623
+ if (http) {
3624
+ if (!isObject__default["default"](parsedValue) || (!isPartialHttpRequest(parsedValue) && !isHttpOperation(parsedValue))) {
3625
+ return null;
3626
+ }
3627
+ return (React__default["default"].createElement(PersistenceContextProvider, null,
3628
+ React__default["default"].createElement(TryIt, { httpOperation: isHttpOperation(parsedValue) ? parsedValue : parseHttpRequest(parsedValue), embeddedInMd: true })));
3629
+ }
3630
+ const DefaultCode = markdownViewer.DefaultSMDComponents.code;
3631
+ return React__default["default"].createElement(DefaultCode, Object.assign({}, props));
3632
+ };
3633
+ function parseHttpRequest(data) {
3634
+ const uri = URI__default["default"](data.url);
3635
+ const pathParam = data.url.match(/[^{\}]+(?=})/g);
3636
+ return {
3637
+ id: '?http-operation-id?',
3638
+ method: data.method,
3639
+ path: uri.is('absolute') ? uri.path() : data.url,
3640
+ servers: [{ id: `?http-server-${uri.href()}?`, url: uri.is('absolute') ? uri.origin() : data.baseUrl || '' }],
3641
+ request: Object.assign({ query: Object.entries(data.query || {}).map(([key, value]) => {
3642
+ const defaultVal = Array.isArray(value) ? value[0] : value;
3643
+ return {
3644
+ id: `?http-query-${key}-id?`,
3645
+ name: key,
3646
+ style: types.HttpParamStyles.Form,
3647
+ schema: { default: defaultVal },
3648
+ required: isHttpRequestParamRequired(defaultVal),
3649
+ };
3650
+ }), headers: Object.entries(data.headers || {}).map(([key, value]) => ({
3651
+ id: `?http-header-${key}-id?`,
3652
+ name: key,
3653
+ style: types.HttpParamStyles.Simple,
3654
+ schema: { default: value },
3655
+ required: isHttpRequestParamRequired(value),
3656
+ })), path: pathParam === null || pathParam === void 0 ? void 0 : pathParam.map(name => ({
3657
+ id: `?http-param-${name}-id?`,
3658
+ name,
3659
+ style: types.HttpParamStyles.Simple,
3660
+ required: true,
3661
+ })) }, (data.body
3662
+ ? {
3663
+ body: {
3664
+ id: '?http-request-body?',
3665
+ contents: [
3666
+ {
3667
+ id: '?http-request-body-media?',
3668
+ mediaType: 'application/json',
3669
+ schema: { default: data.body },
3670
+ },
3671
+ ],
3672
+ },
3673
+ }
3674
+ : null)),
3675
+ responses: [],
3676
+ };
3677
+ }
3678
+ function isHttpRequestParamRequired(value) {
3679
+ return typeof value !== 'undefined';
3680
+ }
3681
+
3682
+ const MarkdownComponentsProvider = ({ value, children }) => {
3683
+ return React__namespace.createElement(markdownViewer.MarkdownViewerProvider, { components: Object.assign({ code: CodeComponent }, value) }, children);
3684
+ };
3685
+
3686
+ const externalRegex = new RegExp('^(?:[a-z]+:)?//', 'i');
3687
+ const ReactRouterMarkdownLink = ({ title, to, href: _href, children, }) => {
3688
+ const href = to || _href;
3689
+ const isExternal = href !== undefined && externalRegex.test(href);
3690
+ if (isExternal) {
3691
+ return (React__default["default"].createElement("a", { target: "_blank", rel: "noreferrer noopener", href: href, title: title }, children));
3692
+ }
3693
+ return (React__default["default"].createElement(reactRouterHashLink.HashLink, { to: href, title: title }, children));
3694
+ };
3695
+
3696
+ const NonIdealState = ({ description, icon, title }) => {
3697
+ return (React__namespace.createElement(mosaic.Flex, { flexDirection: "col", alignItems: "center", justifyContent: "center", textAlign: "center", w: "full", h: "full" },
3698
+ React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, icon: icon || ['fas', 'exclamation-triangle'], color: "light", fontSize: "6xl", mb: 4 }),
3699
+ React__namespace.createElement(mosaic.Heading, { size: 4, mb: 4 }, title),
3700
+ React__namespace.createElement(mosaic.Text, null, description)));
3701
+ };
3702
+
3570
3703
  function withMosaicProvider(WrappedComponent) {
3571
3704
  const WithMosaicProvider = (props) => {
3572
3705
  try {
@@ -3827,6 +3960,7 @@ exports.Docs = Docs;
3827
3960
  exports.ExportButton = ExportButton;
3828
3961
  exports.HttpMethodColors = HttpMethodColors;
3829
3962
  exports.InlineRefResolverProvider = InlineRefResolverProvider;
3963
+ exports.LinkHeading = LinkHeading;
3830
3964
  exports.Logo = Logo;
3831
3965
  exports.MarkdownComponentsProvider = MarkdownComponentsProvider;
3832
3966
  exports.MockingProvider = MockingProvider;
@@ -3838,6 +3972,7 @@ exports.ParsedDocs = ParsedDocs;
3838
3972
  exports.PersistenceContextProvider = PersistenceContextProvider;
3839
3973
  exports.PoweredByLink = PoweredByLink;
3840
3974
  exports.ReactRouterMarkdownLink = ReactRouterMarkdownLink;
3975
+ exports.ResponsiveSidebarLayout = ResponsiveSidebarLayout;
3841
3976
  exports.RouterTypeContext = RouterTypeContext;
3842
3977
  exports.SidebarLayout = SidebarLayout;
3843
3978
  exports.Styled = Styled;
@@ -3854,6 +3989,7 @@ exports.slugify = slugify;
3854
3989
  exports.useBundleRefsIntoDocument = useBundleRefsIntoDocument;
3855
3990
  exports.useParsedData = useParsedData;
3856
3991
  exports.useParsedValue = useParsedValue;
3992
+ exports.useResponsiveLayout = useResponsiveLayout;
3857
3993
  exports.useRouter = useRouter;
3858
3994
  exports.withMosaicProvider = withMosaicProvider;
3859
3995
  exports.withPersistenceBoundary = withPersistenceBoundary;