@stoplight/elements-core 7.7.0 → 7.7.2

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.
@@ -1,9 +1,13 @@
1
- import { Meta, Story } from '@storybook/react';
1
+ import type { ErrorBoundaryProps } from '@stoplight/react-error-boundary';
2
+ import type { Meta, Story } from '@storybook/react';
2
3
  import * as React from 'react';
3
- interface HelperReturn<P> {
4
+ declare type DocsProps = {
5
+ data: unknown;
6
+ } & ErrorBoundaryProps;
7
+ interface HelperReturn<P extends Partial<DocsProps>> {
4
8
  meta: Meta<P>;
5
9
  createStory(name: string, input: Partial<P>): Story<P>;
6
10
  createHoistedStory(input: Partial<P>): Story<P>;
7
11
  }
8
- export declare const createStoriesForDocsComponent: <P>(Component: React.ComponentType<P>, title?: string | undefined) => HelperReturn<P>;
12
+ export declare const createStoriesForDocsComponent: <P extends Partial<DocsProps> = DocsProps>(Component: React.ComponentType<P>, title?: string | undefined) => HelperReturn<P>;
9
13
  export {};
@@ -1,3 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import type { RouterType } from '../types';
3
- export declare const RouterTypeContext: React.Context<RouterType>;
3
+ export declare const RouterTypeContext: React.Context<RouterType | null>;
4
+ export declare const useRouterType: () => RouterType | null;
package/index.esm.js CHANGED
@@ -2088,9 +2088,17 @@ ${scopes.map(([key, value]) => `- \`${key}\` - ${value}`).join('\n')}`;
2088
2088
  return description;
2089
2089
  }
2090
2090
 
2091
- const RouterTypeContext = React.createContext('history');
2091
+ const RouterTypeContext = React.createContext(null);
2092
+ const useRouterType = () => {
2093
+ return React.useContext(RouterTypeContext);
2094
+ };
2092
2095
 
2093
- const LinkHeading = React.memo(function LinkHeading(_a) {
2096
+ const LinkHeading = React.memo(function LinkHeading(props) {
2097
+ const isUsingRouter = !!useRouterType();
2098
+ const Comp = isUsingRouter ? CustomLinkHeading : LinkHeading$1;
2099
+ return React.createElement(Comp, Object.assign({}, props));
2100
+ });
2101
+ const CustomLinkHeading = React.memo(function LinkHeading(_a) {
2094
2102
  var { id: _id } = _a, props = __rest(_a, ["id"]);
2095
2103
  const { pathname } = useLocation();
2096
2104
  const routerKind = React.useContext(RouterTypeContext);
@@ -2172,7 +2180,6 @@ const Parameters = ({ parameters, parameterType }) => {
2172
2180
  };
2173
2181
  Parameters.displayName = 'HttpOperation.Parameters';
2174
2182
  const httpOperationParamsToSchema = ({ parameters, parameterType }) => {
2175
- var _a, _b, _c;
2176
2183
  if (!parameters || !parameters.length)
2177
2184
  return null;
2178
2185
  const schema = {
@@ -2182,19 +2189,22 @@ const httpOperationParamsToSchema = ({ parameters, parameterType }) => {
2182
2189
  const sortedParams = sortBy(parameters, ['required', 'name']);
2183
2190
  for (const p of sortedParams) {
2184
2191
  const { name, description, required, deprecated, examples, style } = p;
2192
+ const paramSchema = isPlainObject$1(p.schema) ? p.schema : {};
2185
2193
  const paramExamples = (examples === null || examples === void 0 ? void 0 : examples.map(example => {
2186
2194
  if (isNodeExample(example)) {
2187
2195
  return example.value;
2188
2196
  }
2189
2197
  return example.externalValue;
2190
2198
  })) || [];
2191
- const schemaExamples = (_a = p.schema) === null || _a === void 0 ? void 0 : _a.examples;
2199
+ const schemaExamples = paramSchema.examples;
2192
2200
  const schemaExamplesArray = Array.isArray(schemaExamples) ? schemaExamples : [];
2193
- const paramDescription = description || ((_b = p.schema) === null || _b === void 0 ? void 0 : _b.description);
2194
- const paramDeprecated = deprecated || p.schema.deprecated;
2201
+ const paramDescription = description || paramSchema.description;
2202
+ const paramDeprecated = !!(deprecated || paramSchema.deprecated);
2195
2203
  const paramStyle = style && defaultStyle[parameterType] !== style ? readableStyles[style] || style : undefined;
2196
- schema.properties[p.name] = Object.assign(Object.assign({}, (p.schema || {})), { description: paramDescription, examples: [...paramExamples, ...schemaExamplesArray], deprecated: paramDeprecated, style: paramStyle, 'x-stoplight': Object.assign(Object.assign({}, (((_c = p.schema) === null || _c === void 0 ? void 0 : _c['x-stoplight']) || {})), { id: p.id }) });
2197
- if (required) {
2204
+ if (isPlainObject$1(schema.properties)) {
2205
+ schema.properties[p.name] = Object.assign(Object.assign({}, paramSchema), { description: paramDescription, examples: [...paramExamples, ...schemaExamplesArray], deprecated: paramDeprecated, style: paramStyle, 'x-stoplight': Object.assign(Object.assign({}, (isPlainObject$1(paramSchema['x-stoplight']) ? paramSchema['x-stoplight'] : {})), { id: p.id }) });
2206
+ }
2207
+ if (required && Array.isArray(schema.required)) {
2198
2208
  schema.required.push(name);
2199
2209
  }
2200
2210
  }
package/index.js CHANGED
@@ -2142,9 +2142,17 @@ ${scopes.map(([key, value]) => `- \`${key}\` - ${value}`).join('\n')}`;
2142
2142
  return description;
2143
2143
  }
2144
2144
 
2145
- const RouterTypeContext = React__namespace.createContext('history');
2145
+ const RouterTypeContext = React__namespace.createContext(null);
2146
+ const useRouterType = () => {
2147
+ return React__namespace.useContext(RouterTypeContext);
2148
+ };
2146
2149
 
2147
- const LinkHeading = React__namespace.memo(function LinkHeading(_a) {
2150
+ const LinkHeading = React__namespace.memo(function LinkHeading(props) {
2151
+ const isUsingRouter = !!useRouterType();
2152
+ const Comp = isUsingRouter ? CustomLinkHeading : mosaic.LinkHeading;
2153
+ return React__namespace.createElement(Comp, Object.assign({}, props));
2154
+ });
2155
+ const CustomLinkHeading = React__namespace.memo(function LinkHeading(_a) {
2148
2156
  var { id: _id } = _a, props = tslib.__rest(_a, ["id"]);
2149
2157
  const { pathname } = reactRouterDom.useLocation();
2150
2158
  const routerKind = React__namespace.useContext(RouterTypeContext);
@@ -2226,7 +2234,6 @@ const Parameters = ({ parameters, parameterType }) => {
2226
2234
  };
2227
2235
  Parameters.displayName = 'HttpOperation.Parameters';
2228
2236
  const httpOperationParamsToSchema = ({ parameters, parameterType }) => {
2229
- var _a, _b, _c;
2230
2237
  if (!parameters || !parameters.length)
2231
2238
  return null;
2232
2239
  const schema = {
@@ -2236,19 +2243,22 @@ const httpOperationParamsToSchema = ({ parameters, parameterType }) => {
2236
2243
  const sortedParams = sortBy__default["default"](parameters, ['required', 'name']);
2237
2244
  for (const p of sortedParams) {
2238
2245
  const { name, description, required, deprecated, examples, style } = p;
2246
+ const paramSchema = json.isPlainObject(p.schema) ? p.schema : {};
2239
2247
  const paramExamples = (examples === null || examples === void 0 ? void 0 : examples.map(example => {
2240
2248
  if (isNodeExample(example)) {
2241
2249
  return example.value;
2242
2250
  }
2243
2251
  return example.externalValue;
2244
2252
  })) || [];
2245
- const schemaExamples = (_a = p.schema) === null || _a === void 0 ? void 0 : _a.examples;
2253
+ const schemaExamples = paramSchema.examples;
2246
2254
  const schemaExamplesArray = Array.isArray(schemaExamples) ? schemaExamples : [];
2247
- const paramDescription = description || ((_b = p.schema) === null || _b === void 0 ? void 0 : _b.description);
2248
- const paramDeprecated = deprecated || p.schema.deprecated;
2255
+ const paramDescription = description || paramSchema.description;
2256
+ const paramDeprecated = !!(deprecated || paramSchema.deprecated);
2249
2257
  const paramStyle = style && defaultStyle[parameterType] !== style ? readableStyles[style] || style : undefined;
2250
- schema.properties[p.name] = Object.assign(Object.assign({}, (p.schema || {})), { description: paramDescription, examples: [...paramExamples, ...schemaExamplesArray], deprecated: paramDeprecated, style: paramStyle, 'x-stoplight': Object.assign(Object.assign({}, (((_c = p.schema) === null || _c === void 0 ? void 0 : _c['x-stoplight']) || {})), { id: p.id }) });
2251
- if (required) {
2258
+ if (json.isPlainObject(schema.properties)) {
2259
+ schema.properties[p.name] = Object.assign(Object.assign({}, paramSchema), { description: paramDescription, examples: [...paramExamples, ...schemaExamplesArray], deprecated: paramDeprecated, style: paramStyle, 'x-stoplight': Object.assign(Object.assign({}, (json.isPlainObject(paramSchema['x-stoplight']) ? paramSchema['x-stoplight'] : {})), { id: p.id }) });
2260
+ }
2261
+ if (required && Array.isArray(schema.required)) {
2252
2262
  schema.required.push(name);
2253
2263
  }
2254
2264
  }
package/index.mjs CHANGED
@@ -2088,9 +2088,17 @@ ${scopes.map(([key, value]) => `- \`${key}\` - ${value}`).join('\n')}`;
2088
2088
  return description;
2089
2089
  }
2090
2090
 
2091
- const RouterTypeContext = React.createContext('history');
2091
+ const RouterTypeContext = React.createContext(null);
2092
+ const useRouterType = () => {
2093
+ return React.useContext(RouterTypeContext);
2094
+ };
2092
2095
 
2093
- const LinkHeading = React.memo(function LinkHeading(_a) {
2096
+ const LinkHeading = React.memo(function LinkHeading(props) {
2097
+ const isUsingRouter = !!useRouterType();
2098
+ const Comp = isUsingRouter ? CustomLinkHeading : LinkHeading$1;
2099
+ return React.createElement(Comp, Object.assign({}, props));
2100
+ });
2101
+ const CustomLinkHeading = React.memo(function LinkHeading(_a) {
2094
2102
  var { id: _id } = _a, props = __rest(_a, ["id"]);
2095
2103
  const { pathname } = useLocation();
2096
2104
  const routerKind = React.useContext(RouterTypeContext);
@@ -2172,7 +2180,6 @@ const Parameters = ({ parameters, parameterType }) => {
2172
2180
  };
2173
2181
  Parameters.displayName = 'HttpOperation.Parameters';
2174
2182
  const httpOperationParamsToSchema = ({ parameters, parameterType }) => {
2175
- var _a, _b, _c;
2176
2183
  if (!parameters || !parameters.length)
2177
2184
  return null;
2178
2185
  const schema = {
@@ -2182,19 +2189,22 @@ const httpOperationParamsToSchema = ({ parameters, parameterType }) => {
2182
2189
  const sortedParams = sortBy(parameters, ['required', 'name']);
2183
2190
  for (const p of sortedParams) {
2184
2191
  const { name, description, required, deprecated, examples, style } = p;
2192
+ const paramSchema = isPlainObject$1(p.schema) ? p.schema : {};
2185
2193
  const paramExamples = (examples === null || examples === void 0 ? void 0 : examples.map(example => {
2186
2194
  if (isNodeExample(example)) {
2187
2195
  return example.value;
2188
2196
  }
2189
2197
  return example.externalValue;
2190
2198
  })) || [];
2191
- const schemaExamples = (_a = p.schema) === null || _a === void 0 ? void 0 : _a.examples;
2199
+ const schemaExamples = paramSchema.examples;
2192
2200
  const schemaExamplesArray = Array.isArray(schemaExamples) ? schemaExamples : [];
2193
- const paramDescription = description || ((_b = p.schema) === null || _b === void 0 ? void 0 : _b.description);
2194
- const paramDeprecated = deprecated || p.schema.deprecated;
2201
+ const paramDescription = description || paramSchema.description;
2202
+ const paramDeprecated = !!(deprecated || paramSchema.deprecated);
2195
2203
  const paramStyle = style && defaultStyle[parameterType] !== style ? readableStyles[style] || style : undefined;
2196
- schema.properties[p.name] = Object.assign(Object.assign({}, (p.schema || {})), { description: paramDescription, examples: [...paramExamples, ...schemaExamplesArray], deprecated: paramDeprecated, style: paramStyle, 'x-stoplight': Object.assign(Object.assign({}, (((_c = p.schema) === null || _c === void 0 ? void 0 : _c['x-stoplight']) || {})), { id: p.id }) });
2197
- if (required) {
2204
+ if (isPlainObject$1(schema.properties)) {
2205
+ schema.properties[p.name] = Object.assign(Object.assign({}, paramSchema), { description: paramDescription, examples: [...paramExamples, ...schemaExamplesArray], deprecated: paramDeprecated, style: paramStyle, 'x-stoplight': Object.assign(Object.assign({}, (isPlainObject$1(paramSchema['x-stoplight']) ? paramSchema['x-stoplight'] : {})), { id: p.id }) });
2206
+ }
2207
+ if (required && Array.isArray(schema.required)) {
2198
2208
  schema.required.push(name);
2199
2209
  }
2200
2210
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements-core",
3
- "version": "7.7.0",
3
+ "version": "7.7.2",
4
4
  "main": "./index.js",
5
5
  "sideEffects": [
6
6
  "web-components.min.js",