@stoplight/elements-core 7.14.0 → 7.15.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 +12 -4
- package/components/Docs/Docs.d.ts +1 -0
- package/components/Docs/Docs.stories.d.ts +2 -2
- package/components/Docs/HttpOperation/HttpOperation.stories.d.ts +6 -2
- package/components/Docs/HttpService/HttpService.stories.d.ts +6 -2
- package/components/Docs/Model/Model.stories.d.ts +6 -2
- package/components/Docs/story-helper.d.ts +10 -7
- package/components/RequestSamples/RequestSamples.stories.d.ts +2 -3
- package/components/ResponseExamples/ResponseExamples.stories.d.ts +2 -3
- package/components/TryIt/TryIt.stories.d.ts +11 -12
- package/components/TryIt/TryItWithRequestSamples.stories.d.ts +3 -4
- package/context/InlineRefResolver.d.ts +8 -2
- package/index.esm.js +21 -18
- package/index.js +21 -18
- package/index.mjs +21 -18
- package/package.json +6 -6
- package/styles.min.css +1 -1
package/index.mjs
CHANGED
|
@@ -119,23 +119,25 @@ const InlineRefResolverContext = React.createContext(undefined);
|
|
|
119
119
|
InlineRefResolverContext.displayName = 'InlineRefResolverContext';
|
|
120
120
|
const DocumentContext = React.createContext(undefined);
|
|
121
121
|
DocumentContext.displayName = 'DocumentContext';
|
|
122
|
-
const InlineRefResolverProvider = ({ children, document: maybeDocument, resolver, }) => {
|
|
122
|
+
const InlineRefResolverProvider = ({ children, document: maybeDocument, resolver, maxRefDepth, }) => {
|
|
123
123
|
const document = isPlainObject$1(maybeDocument) ? maybeDocument : undefined;
|
|
124
124
|
const computedResolver = React.useMemo(() => resolver || (document !== undefined ? defaultResolver(document) : undefined), [document, resolver]);
|
|
125
|
-
return (React.createElement(InlineRefResolverContext.Provider, { value: computedResolver },
|
|
125
|
+
return (React.createElement(InlineRefResolverContext.Provider, { value: { resolver: computedResolver, maxRefDepth } },
|
|
126
126
|
React.createElement(DocumentContext.Provider, { value: document }, children)));
|
|
127
127
|
};
|
|
128
128
|
const useInlineRefResolver = () => useContext(InlineRefResolverContext);
|
|
129
129
|
const useDocument = () => useContext(DocumentContext);
|
|
130
130
|
const useResolvedObject = (currentObject) => {
|
|
131
|
+
var _a;
|
|
131
132
|
const document = useDocument();
|
|
132
|
-
const resolver = useInlineRefResolver();
|
|
133
|
+
const { resolver } = (_a = useInlineRefResolver()) !== null && _a !== void 0 ? _a : {};
|
|
133
134
|
return React.useMemo(() => createResolvedObject(currentObject, { contextObject: document, resolver }), [currentObject, document, resolver]);
|
|
134
135
|
};
|
|
135
136
|
const useSchemaInlineRefResolver = () => {
|
|
137
|
+
var _a;
|
|
136
138
|
const document = useDocument();
|
|
137
|
-
const resolver = useInlineRefResolver();
|
|
138
|
-
|
|
139
|
+
const { resolver, maxRefDepth } = (_a = useInlineRefResolver()) !== null && _a !== void 0 ? _a : {};
|
|
140
|
+
const referenceResolver = React.useCallback((...args) => {
|
|
139
141
|
const resolved = resolver === null || resolver === void 0 ? void 0 : resolver(...args);
|
|
140
142
|
if (!isPlainObject$1(resolved)) {
|
|
141
143
|
return resolved;
|
|
@@ -151,6 +153,7 @@ const useSchemaInlineRefResolver = () => {
|
|
|
151
153
|
delete converted.$schema;
|
|
152
154
|
return converted;
|
|
153
155
|
}, [document, resolver]);
|
|
156
|
+
return [referenceResolver, maxRefDepth];
|
|
154
157
|
};
|
|
155
158
|
|
|
156
159
|
const DEFAULT_CONTEXT = {};
|
|
@@ -2446,7 +2449,7 @@ const isBodyEmpty = (body) => {
|
|
|
2446
2449
|
};
|
|
2447
2450
|
const Body = ({ body, onChange }) => {
|
|
2448
2451
|
var _a;
|
|
2449
|
-
const refResolver = useSchemaInlineRefResolver();
|
|
2452
|
+
const [refResolver, maxRefDepth] = useSchemaInlineRefResolver();
|
|
2450
2453
|
const [chosenContent, setChosenContent] = React.useState(0);
|
|
2451
2454
|
const { nodeHasChanged } = useOptionsCtx();
|
|
2452
2455
|
React.useEffect(() => {
|
|
@@ -2463,7 +2466,7 @@ const Body = ({ body, onChange }) => {
|
|
|
2463
2466
|
description && (React.createElement(Box, { pos: "relative" },
|
|
2464
2467
|
React.createElement(MarkdownViewer, { markdown: description }),
|
|
2465
2468
|
React.createElement(NodeAnnotation, { change: descriptionChanged }))),
|
|
2466
|
-
isJSONSchema(schema) && (React.createElement(JsonSchemaViewer, { resolveRef: refResolver, schema: getOriginalObject(schema), viewMode: "write", renderRootTreeLines: true, nodeHasChanged: nodeHasChanged }))));
|
|
2469
|
+
isJSONSchema(schema) && (React.createElement(JsonSchemaViewer, { resolveRef: refResolver, maxRefDepth: maxRefDepth, schema: getOriginalObject(schema), viewMode: "write", renderRootTreeLines: true, nodeHasChanged: nodeHasChanged }))));
|
|
2467
2470
|
};
|
|
2468
2471
|
Body.displayName = 'HttpOperation.Body';
|
|
2469
2472
|
|
|
@@ -2488,11 +2491,11 @@ const defaultStyle = {
|
|
|
2488
2491
|
};
|
|
2489
2492
|
const Parameters = ({ parameters, parameterType }) => {
|
|
2490
2493
|
const { nodeHasChanged } = useOptionsCtx();
|
|
2491
|
-
const refResolver = useSchemaInlineRefResolver();
|
|
2494
|
+
const [refResolver, maxRefDepth] = useSchemaInlineRefResolver();
|
|
2492
2495
|
const schema = React.useMemo(() => httpOperationParamsToSchema({ parameters, parameterType }), [parameters, parameterType]);
|
|
2493
2496
|
if (!schema)
|
|
2494
2497
|
return null;
|
|
2495
|
-
return React.createElement(JsonSchemaViewer, { resolveRef: refResolver, schema: schema, disableCrumbs: true, nodeHasChanged: nodeHasChanged });
|
|
2498
|
+
return (React.createElement(JsonSchemaViewer, { resolveRef: refResolver, maxRefDepth: maxRefDepth, schema: schema, disableCrumbs: true, nodeHasChanged: nodeHasChanged }));
|
|
2496
2499
|
};
|
|
2497
2500
|
Parameters.displayName = 'HttpOperation.Parameters';
|
|
2498
2501
|
const httpOperationParamsToSchema = ({ parameters, parameterType }) => {
|
|
@@ -2626,7 +2629,7 @@ Responses.displayName = 'HttpOperation.Responses';
|
|
|
2626
2629
|
const Response = ({ response, onMediaTypeChange }) => {
|
|
2627
2630
|
const { contents = [], headers = [], description } = response;
|
|
2628
2631
|
const [chosenContent, setChosenContent] = React.useState(0);
|
|
2629
|
-
const refResolver = useSchemaInlineRefResolver();
|
|
2632
|
+
const [refResolver, maxRefDepth] = useSchemaInlineRefResolver();
|
|
2630
2633
|
const { nodeHasChanged } = useOptionsCtx();
|
|
2631
2634
|
const responseContent = contents[chosenContent];
|
|
2632
2635
|
const schema = responseContent === null || responseContent === void 0 ? void 0 : responseContent.schema;
|
|
@@ -2645,7 +2648,7 @@ const Response = ({ response, onMediaTypeChange }) => {
|
|
|
2645
2648
|
React.createElement(SectionSubtitle, { title: "Body", id: "response-body" },
|
|
2646
2649
|
React.createElement(Flex, { flex: 1, justify: "end" },
|
|
2647
2650
|
React.createElement(Select, { "aria-label": "Response Body Content Type", value: String(chosenContent), onChange: value => setChosenContent(parseInt(String(value), 10)), options: contents.map((content, index) => ({ label: content.mediaType, value: index })), size: "sm" }))),
|
|
2648
|
-
schema && (React.createElement(JsonSchemaViewer, { schema: getOriginalObject(schema), resolveRef: refResolver, viewMode: "read", parentCrumbs: ['responses', response.code], renderRootTreeLines: true, nodeHasChanged: nodeHasChanged }))))));
|
|
2651
|
+
schema && (React.createElement(JsonSchemaViewer, { schema: getOriginalObject(schema), resolveRef: refResolver, maxRefDepth: maxRefDepth, viewMode: "read", parentCrumbs: ['responses', response.code], renderRootTreeLines: true, nodeHasChanged: nodeHasChanged }))))));
|
|
2649
2652
|
};
|
|
2650
2653
|
Response.displayName = 'HttpOperation.Response';
|
|
2651
2654
|
const codeToIntentVal = (code) => {
|
|
@@ -2929,7 +2932,7 @@ const HttpService = withErrorBoundary(HttpServiceComponent, { recoverableProps:
|
|
|
2929
2932
|
|
|
2930
2933
|
const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOptions, exportProps, }) => {
|
|
2931
2934
|
var _a, _b;
|
|
2932
|
-
const resolveRef = useSchemaInlineRefResolver();
|
|
2935
|
+
const [resolveRef, maxRefDepth] = useSchemaInlineRefResolver();
|
|
2933
2936
|
const data = useResolvedObject(unresolvedData);
|
|
2934
2937
|
const { nodeHasChanged } = useOptionsCtx();
|
|
2935
2938
|
const { ref: layoutRef, isCompact } = useIsCompact(layoutOptions);
|
|
@@ -2955,7 +2958,7 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
|
|
|
2955
2958
|
React.createElement(MarkdownViewer, { role: "textbox", markdown: data.description }),
|
|
2956
2959
|
React.createElement(NodeAnnotation, { change: descriptionChanged }))),
|
|
2957
2960
|
isCompact && modelExamples,
|
|
2958
|
-
React.createElement(JsonSchemaViewer, { resolveRef: resolveRef, schema: getOriginalObject(data), nodeHasChanged: nodeHasChanged, skipTopLevelDescription: true })));
|
|
2961
|
+
React.createElement(JsonSchemaViewer, { resolveRef: resolveRef, maxRefDepth: maxRefDepth, schema: getOriginalObject(data), nodeHasChanged: nodeHasChanged, skipTopLevelDescription: true })));
|
|
2959
2962
|
return (React.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('Model', className), header: header, left: description, right: !isCompact && modelExamples }));
|
|
2960
2963
|
};
|
|
2961
2964
|
const ModelExamples = React.memo(({ data, isCollapsible = false }) => {
|
|
@@ -2978,7 +2981,7 @@ const Model = withErrorBoundary(ModelComponent, { recoverableProps: ['data'] });
|
|
|
2978
2981
|
|
|
2979
2982
|
const Docs = React.memo((_a) => {
|
|
2980
2983
|
var _b;
|
|
2981
|
-
var { nodeType, nodeData, useNodeForRefResolving = false, refResolver, nodeHasChanged } = _a, commonProps = __rest(_a, ["nodeType", "nodeData", "useNodeForRefResolving", "refResolver", "nodeHasChanged"]);
|
|
2984
|
+
var { nodeType, nodeData, useNodeForRefResolving = false, refResolver, maxRefDepth, nodeHasChanged } = _a, commonProps = __rest(_a, ["nodeType", "nodeData", "useNodeForRefResolving", "refResolver", "maxRefDepth", "nodeHasChanged"]);
|
|
2982
2985
|
const parsedNode = useParsedData(nodeType, nodeData);
|
|
2983
2986
|
if (!parsedNode) {
|
|
2984
2987
|
(_b = commonProps.nodeUnsupported) === null || _b === void 0 ? void 0 : _b.call(commonProps, 'dataEmpty');
|
|
@@ -2986,7 +2989,7 @@ const Docs = React.memo((_a) => {
|
|
|
2986
2989
|
}
|
|
2987
2990
|
let elem = React.createElement(ParsedDocs, Object.assign({ node: parsedNode }, commonProps));
|
|
2988
2991
|
if (useNodeForRefResolving) {
|
|
2989
|
-
elem = (React.createElement(InlineRefResolverProvider, { document: parsedNode.data, resolver: refResolver }, elem));
|
|
2992
|
+
elem = (React.createElement(InlineRefResolverProvider, { document: parsedNode.data, resolver: refResolver, maxRefDepth: maxRefDepth }, elem));
|
|
2990
2993
|
}
|
|
2991
2994
|
return React.createElement(ElementsOptionsProvider, { nodeHasChanged: nodeHasChanged }, elem);
|
|
2992
2995
|
});
|
|
@@ -3098,13 +3101,13 @@ function isPartialHttpRequest(maybeHttpRequest) {
|
|
|
3098
3101
|
typeof maybeHttpRequest['url'] === 'string');
|
|
3099
3102
|
}
|
|
3100
3103
|
const SchemaAndDescription = ({ title: titleProp, schema }) => {
|
|
3101
|
-
const resolveRef = useSchemaInlineRefResolver();
|
|
3104
|
+
const [resolveRef, maxRefDepth] = useSchemaInlineRefResolver();
|
|
3102
3105
|
const title = titleProp !== null && titleProp !== void 0 ? titleProp : schema.title;
|
|
3103
3106
|
return (React__default.createElement(Box, { py: 2 },
|
|
3104
3107
|
title && (React__default.createElement(Flex, { alignItems: "center", p: 2 },
|
|
3105
3108
|
React__default.createElement(Icon, { icon: NodeTypeIconDefs[NodeType.Model], color: NodeTypeColors[NodeType.Model] }),
|
|
3106
3109
|
React__default.createElement(Box, { color: "muted", px: 2 }, title))),
|
|
3107
|
-
React__default.createElement(JsonSchemaViewer, { resolveRef: resolveRef, schema: getOriginalObject(schema) })));
|
|
3110
|
+
React__default.createElement(JsonSchemaViewer, { resolveRef: resolveRef, maxRefDepth: maxRefDepth, schema: getOriginalObject(schema) })));
|
|
3108
3111
|
};
|
|
3109
3112
|
const CodeComponent = props => {
|
|
3110
3113
|
const { title, jsonSchema, http, resolved, children } = props;
|
|
@@ -3115,7 +3118,7 @@ const CodeComponent = props => {
|
|
|
3115
3118
|
if (!isJSONSchema(parsedValue)) {
|
|
3116
3119
|
return null;
|
|
3117
3120
|
}
|
|
3118
|
-
return (React__default.createElement(InlineRefResolverProvider, { document: parsedValue, resolver: resolver },
|
|
3121
|
+
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 },
|
|
3119
3122
|
React__default.createElement(SchemaAndDescription, { title: title, schema: parsedValue })));
|
|
3120
3123
|
}
|
|
3121
3124
|
if (http) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stoplight/elements-core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.15.1",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"web-components.min.js",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"@stoplight/json": "^3.18.1",
|
|
29
29
|
"@stoplight/json-schema-ref-parser": "^9.0.5",
|
|
30
30
|
"@stoplight/json-schema-sampler": "0.2.3",
|
|
31
|
-
"@stoplight/json-schema-tree": "^2.
|
|
32
|
-
"@stoplight/json-schema-viewer": "^4.
|
|
31
|
+
"@stoplight/json-schema-tree": "^2.3.0",
|
|
32
|
+
"@stoplight/json-schema-viewer": "^4.14.0",
|
|
33
33
|
"@stoplight/markdown-viewer": "^5.6.0",
|
|
34
|
-
"@stoplight/mosaic": "^1.
|
|
35
|
-
"@stoplight/mosaic-code-editor": "^1.
|
|
36
|
-
"@stoplight/mosaic-code-viewer": "^1.
|
|
34
|
+
"@stoplight/mosaic": "^1.46.1",
|
|
35
|
+
"@stoplight/mosaic-code-editor": "^1.46.1",
|
|
36
|
+
"@stoplight/mosaic-code-viewer": "^1.46.1",
|
|
37
37
|
"@stoplight/path": "^1.3.2",
|
|
38
38
|
"@stoplight/react-error-boundary": "^2.0.0",
|
|
39
39
|
"@stoplight/types": "^14.0.0",
|