@clarify-labs/renderer 0.9.0 → 0.9.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.
Files changed (43) hide show
  1. package/output/{ClarifyShell-BPv2bxI4.js → ClarifyShell-C38EkErX.js} +397 -250
  2. package/output/ClarifyShell-C38EkErX.js.map +1 -0
  3. package/output/{ClarifyShell-B74Fq4UU.cjs → ClarifyShell-DdYRgrfY.cjs} +396 -249
  4. package/output/ClarifyShell-DdYRgrfY.cjs.map +1 -0
  5. package/output/{OpenApiOperation-BMXfV15v.cjs → OpenApiOperation-CP_fxT_F.cjs} +344 -219
  6. package/output/OpenApiOperation-CP_fxT_F.cjs.map +1 -0
  7. package/output/{OpenApiOperation-fJ3QQOJX.js → OpenApiOperation-DIFaYAe5.js} +344 -219
  8. package/output/OpenApiOperation-DIFaYAe5.js.map +1 -0
  9. package/output/{PageActions-DOKkt2zo.cjs → PageActions-B08cDCzq.cjs} +278 -167
  10. package/output/PageActions-B08cDCzq.cjs.map +1 -0
  11. package/output/{PageActions-BwY7ierv.js → PageActions-tmnpzi23.js} +279 -168
  12. package/output/PageActions-tmnpzi23.js.map +1 -0
  13. package/output/app/SectionProvider.d.ts +1 -0
  14. package/output/client.cjs +3 -3
  15. package/output/client.js +3 -3
  16. package/output/core/types.d.ts +1 -0
  17. package/output/index.cjs +4 -4
  18. package/output/index.js +4 -4
  19. package/output/openapi/components/CodeDisplay.d.ts +25 -0
  20. package/output/openapi/components/EndpointSections.d.ts +4 -0
  21. package/output/openapi/components/ExamplePanels.d.ts +8 -17
  22. package/output/openapi/components/OpenApiOperation.state.d.ts +43 -0
  23. package/output/openapi/components/SelectControl.d.ts +15 -0
  24. package/output/openapi/components/helpers.d.ts +22 -0
  25. package/output/preview.cjs +114 -67
  26. package/output/preview.cjs.map +1 -1
  27. package/output/preview.js +114 -67
  28. package/output/preview.js.map +1 -1
  29. package/output/{render-Cghgq1AQ.js → render-6gHfrR9h.js} +2 -2
  30. package/output/{render-Cghgq1AQ.js.map → render-6gHfrR9h.js.map} +1 -1
  31. package/output/{render-ZSckbg74.cjs → render-Bvf5ZMZb.cjs} +2 -2
  32. package/output/{render-ZSckbg74.cjs.map → render-Bvf5ZMZb.cjs.map} +1 -1
  33. package/output/renderer.css +168 -107
  34. package/output/server.cjs +2 -2
  35. package/output/server.js +2 -2
  36. package/output/shell/Header.d.ts +2 -0
  37. package/package.json +1 -1
  38. package/output/ClarifyShell-B74Fq4UU.cjs.map +0 -1
  39. package/output/ClarifyShell-BPv2bxI4.js.map +0 -1
  40. package/output/OpenApiOperation-BMXfV15v.cjs.map +0 -1
  41. package/output/OpenApiOperation-fJ3QQOJX.js.map +0 -1
  42. package/output/PageActions-BwY7ierv.js.map +0 -1
  43. package/output/PageActions-DOKkt2zo.cjs.map +0 -1
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require("./chunk-DakpK96I.cjs");
2
- const require_PageActions = require("./PageActions-DOKkt2zo.cjs");
2
+ const require_PageActions = require("./PageActions-B08cDCzq.cjs");
3
3
  const require_remark = require("./remark-Dv3owbSH.cjs");
4
4
  let clsx = require("clsx");
5
5
  clsx = require_chunk.__toESM(clsx, 1);
@@ -782,7 +782,7 @@ function Heading(arg0) {
782
782
  amount: "all"
783
783
  });
784
784
  (0, react.useEffect)(() => {
785
- if (resolvedLevel === 2) registerHeading({
785
+ registerHeading({
786
786
  id: props.id,
787
787
  ref,
788
788
  offsetRem: tag || label ? 8 : 6
@@ -1725,7 +1725,7 @@ function buildRequestCodeExamples(input) {
1725
1725
  }));
1726
1726
  }
1727
1727
  //#endregion
1728
- //#region source/openapi/components/ExamplePanels.tsx
1728
+ //#region source/openapi/components/SelectControl.tsx
1729
1729
  function SelectControl(arg0) {
1730
1730
  const { label, value, options, onChange, icon, compact = false } = arg0;
1731
1731
  const normalizedOptions = options.map((option) => typeof option === "string" ? {
@@ -1772,69 +1772,8 @@ function SelectControl(arg0) {
1772
1772
  })
1773
1773
  });
1774
1774
  }
1775
- function getExampleLabel(example, t) {
1776
- return example.generated && example.title === "schema" ? t("openapi.schemaExample") : example.title;
1777
- }
1778
- function getLanguageOptions(codeOptions) {
1779
- const languages = /* @__PURE__ */ new Map();
1780
- for (const option of codeOptions ?? []) languages.set(option.languageKey, option.title);
1781
- return Array.from(languages, ([value, label]) => ({
1782
- value,
1783
- label
1784
- }));
1785
- }
1786
- function getClientOptions(codeOptions, languageKey) {
1787
- return (codeOptions ?? []).filter((option) => option.languageKey === languageKey).map((option) => ({
1788
- value: option.clientKey,
1789
- label: option.clientTitle
1790
- }));
1791
- }
1792
- function getServers(spec, operation, path) {
1793
- const operationServers = operation.servers;
1794
- const pathServers = path ? getPathItem(spec, path)?.servers : void 0;
1795
- const servers = Array.isArray(operationServers) ? operationServers : Array.isArray(pathServers) ? pathServers : spec.servers;
1796
- if (!Array.isArray(servers)) return [{ url: "https://api.example.com" }];
1797
- const validServers = servers.filter((server) => isRecord(server) && typeof server.url === "string");
1798
- return validServers.length > 0 ? validServers : [{ url: "https://api.example.com" }];
1799
- }
1800
- function getServerKey(server, index) {
1801
- return `${index}:${server.url ?? ""}`;
1802
- }
1803
- function getServerLabel(server, index) {
1804
- return server.description ? `${server.description} (${server.url})` : server.url ?? `Server ${index + 1}`;
1805
- }
1806
- function defaultServerVariables(server) {
1807
- return Object.fromEntries(Object.entries(server?.variables ?? {}).map(([name, variable]) => [name, variable.default ?? variable.enum?.[0] ?? ""]));
1808
- }
1809
- function getSecuritySchemes(spec) {
1810
- const schemes = spec.components;
1811
- if (!isRecord(schemes) || !isRecord(schemes.securitySchemes)) return {};
1812
- return Object.fromEntries(Object.entries(schemes.securitySchemes).filter((entry) => isRecord(entry[1])));
1813
- }
1814
- function getSecurityRequirements(spec, operation) {
1815
- const operationSecurity = operation.security;
1816
- if (Array.isArray(operationSecurity)) return operationSecurity.filter(isRecord);
1817
- const specSecurity = spec.security;
1818
- return Array.isArray(specSecurity) ? specSecurity.filter(isRecord) : [];
1819
- }
1820
- function getAuthOptions(spec, operation) {
1821
- const schemes = getSecuritySchemes(spec);
1822
- const requirements = getSecurityRequirements(spec, operation);
1823
- const names = new Set(requirements.flatMap((requirement) => Object.keys(requirement)));
1824
- return Array.from(names).map((name) => ({
1825
- name,
1826
- scheme: schemes[name]
1827
- })).filter((option) => Boolean(option.scheme));
1828
- }
1829
- function authPlaceholder(auth) {
1830
- if (!auth) return "";
1831
- if (auth.scheme.type === "apiKey") return "{api_key}";
1832
- if (auth.scheme.type === "http" && auth.scheme.scheme?.toLowerCase() === "basic") return "{base64_credentials}";
1833
- return "{token}";
1834
- }
1835
- function authLabel(name, scheme) {
1836
- return `${name}${scheme.type === "apiKey" && scheme.in && scheme.name ? ` · ${scheme.in}: ${scheme.name}` : ""}`;
1837
- }
1775
+ //#endregion
1776
+ //#region source/openapi/components/CodeDisplay.tsx
1838
1777
  function CopyCodeButton(arg0) {
1839
1778
  const { code } = arg0;
1840
1779
  const t = require_PageActions.useBuiltInText();
@@ -1900,6 +1839,73 @@ function CodeToolbar(arg0) {
1900
1839
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyCodeButton, { code })]
1901
1840
  });
1902
1841
  }
1842
+ //#endregion
1843
+ //#region source/openapi/components/helpers.ts
1844
+ function getServers(spec, operation, path) {
1845
+ const operationServers = operation.servers;
1846
+ const pathServers = path ? getPathItem(spec, path)?.servers : void 0;
1847
+ const servers = Array.isArray(operationServers) ? operationServers : Array.isArray(pathServers) ? pathServers : spec.servers;
1848
+ if (!Array.isArray(servers)) return [{ url: "https://api.example.com" }];
1849
+ const validServers = servers.filter((server) => isRecord(server) && typeof server.url === "string");
1850
+ return validServers.length > 0 ? validServers : [{ url: "https://api.example.com" }];
1851
+ }
1852
+ function getServerKey(server, index) {
1853
+ return `${index}:${server.url ?? ""}`;
1854
+ }
1855
+ function getServerLabel(server, index) {
1856
+ return server.url ?? `Server ${index + 1}`;
1857
+ }
1858
+ function defaultServerVariables(server) {
1859
+ return Object.fromEntries(Object.entries(server?.variables ?? {}).map(([name, variable]) => [name, variable.default ?? variable.enum?.[0] ?? ""]));
1860
+ }
1861
+ function getSecuritySchemes(spec) {
1862
+ const schemes = spec.components;
1863
+ if (!isRecord(schemes) || !isRecord(schemes.securitySchemes)) return {};
1864
+ return Object.fromEntries(Object.entries(schemes.securitySchemes).filter((entry) => isRecord(entry[1])));
1865
+ }
1866
+ function getSecurityRequirements(spec, operation) {
1867
+ const operationSecurity = operation.security;
1868
+ if (Array.isArray(operationSecurity)) return operationSecurity.filter(isRecord);
1869
+ const specSecurity = spec.security;
1870
+ return Array.isArray(specSecurity) ? specSecurity.filter(isRecord) : [];
1871
+ }
1872
+ function getAuthOptions(spec, operation) {
1873
+ const schemes = getSecuritySchemes(spec);
1874
+ const requirements = getSecurityRequirements(spec, operation);
1875
+ const names = new Set(requirements.flatMap((requirement) => Object.keys(requirement)));
1876
+ return Array.from(names).map((name) => ({
1877
+ name,
1878
+ scheme: schemes[name]
1879
+ })).filter((option) => Boolean(option.scheme));
1880
+ }
1881
+ function authPlaceholder(auth) {
1882
+ if (!auth) return "";
1883
+ if (auth.scheme.type === "apiKey") return "{api_key}";
1884
+ if (auth.scheme.type === "http" && auth.scheme.scheme?.toLowerCase() === "basic") return "{base64_credentials}";
1885
+ return "{token}";
1886
+ }
1887
+ function authLabel(name, scheme) {
1888
+ return `${name}${scheme.type === "apiKey" && scheme.in && scheme.name ? ` · ${scheme.in}: ${scheme.name}` : ""}`;
1889
+ }
1890
+ function getExampleLabel(example, t) {
1891
+ return example.generated && example.title === "schema" ? t("openapi.schemaExample") : example.title;
1892
+ }
1893
+ function getLanguageOptions(codeOptions) {
1894
+ const languages = /* @__PURE__ */ new Map();
1895
+ for (const option of codeOptions ?? []) languages.set(option.languageKey, option.title);
1896
+ return Array.from(languages, ([value, label]) => ({
1897
+ value,
1898
+ label
1899
+ }));
1900
+ }
1901
+ function getClientOptions(codeOptions, languageKey) {
1902
+ return (codeOptions ?? []).filter((option) => option.languageKey === languageKey).map((option) => ({
1903
+ value: option.clientKey,
1904
+ label: option.clientTitle
1905
+ }));
1906
+ }
1907
+ //#endregion
1908
+ //#region source/openapi/components/ExamplePanels.tsx
1903
1909
  function ApiExampleCodeGroup(arg0) {
1904
1910
  const { title, tag, tagOptions, onSelectTag, label, labelOptions, onSelectLabel, comfortableMeta = false, code, language, mediaTypes, selectedMediaType, onSelectMediaType, examples, selectedExampleKey, onSelectExample, languageOptions, selectedLanguageKey, onSelectLanguage, clientOptions, selectedClientKey, onSelectClient } = arg0;
1905
1911
  const t = require_PageActions.useBuiltInText();
@@ -1976,15 +1982,18 @@ function ApiExampleCodeGroup(arg0) {
1976
1982
  })
1977
1983
  });
1978
1984
  }
1979
- function RequestExamplesPanel(arg0) {
1980
- const { spec, path, method, parameters, requestContents, selectedMediaType, onSelectMediaType, selectedServer, serverVariables, auth } = arg0;
1981
- const t = require_PageActions.useBuiltInText();
1985
+ function firstExampleKeyForMediaType(requestContents, mediaType) {
1986
+ return getExampleEntries(requestContents.find((content) => content.mediaType === mediaType)?.value)[0]?.key ?? "";
1987
+ }
1988
+ function useRequestExamplesState(arg0) {
1989
+ const { spec, path, method, parameters, requestContents, selectedMediaType, onSelectMediaType, selectedServer, serverVariables, auth, sharedExampleKey, onSelectExampleKey } = arg0;
1982
1990
  const selectedContent = requestContents.find((content) => content.mediaType === selectedMediaType) ?? requestContents[0];
1983
1991
  const examples = getExampleEntries(selectedContent?.value);
1984
1992
  const [selectedExampleKey, setSelectedExampleKey] = (0, react.useState)(examples[0]?.key ?? "");
1985
1993
  const [selectedLanguageKey, setSelectedLanguageKey] = (0, react.useState)("shell");
1986
1994
  const [selectedClientKey, setSelectedClientKey] = (0, react.useState)("curl");
1987
- const selectedExample = examples.find((example) => example.key === selectedExampleKey) ?? examples[0];
1995
+ const currentExampleKey = (sharedExampleKey && examples.some((example) => example.key === sharedExampleKey) ? sharedExampleKey : void 0) ?? selectedExampleKey;
1996
+ const selectedExample = examples.find((example) => example.key === currentExampleKey) ?? examples[0];
1988
1997
  const codeOptions = buildRequestCodeExamples({
1989
1998
  spec,
1990
1999
  path,
@@ -2004,38 +2013,71 @@ function RequestExamplesPanel(arg0) {
2004
2013
  });
2005
2014
  const selectedLanguage = codeOptions.find((option) => option.languageKey === selectedLanguageKey) ?? codeOptions[0];
2006
2015
  const selectedCode = codeOptions.find((option) => option.languageKey === selectedLanguage.languageKey && option.clientKey === selectedClientKey) ?? selectedLanguage;
2007
- const languageOptions = getLanguageOptions(codeOptions);
2008
- const clientOptions = getClientOptions(codeOptions, selectedCode.languageKey);
2009
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ApiExampleCodeGroup, {
2010
- title: t("openapi.request"),
2011
- tag: method,
2012
- label: path,
2013
- code: selectedCode.code,
2014
- language: selectedCode.language,
2015
- mediaTypes: requestContents.map((content) => content.mediaType),
2016
- selectedMediaType: selectedContent?.mediaType,
2016
+ return {
2017
+ selectedContent,
2018
+ selectedExample,
2019
+ selectedCode,
2020
+ languageOptions: getLanguageOptions(codeOptions),
2021
+ clientOptions: getClientOptions(codeOptions, selectedCode.languageKey),
2022
+ examples,
2017
2023
  onSelectMediaType: (value) => {
2018
2024
  onSelectMediaType(value);
2019
- setSelectedExampleKey(getExampleEntries(requestContents.find((content) => content.mediaType === value)?.value)[0]?.key ?? "");
2025
+ setSelectedExampleKey(firstExampleKeyForMediaType(requestContents, value));
2026
+ },
2027
+ onSelectExample: (value) => {
2028
+ setSelectedExampleKey(value);
2029
+ onSelectExampleKey?.(value);
2020
2030
  },
2021
- examples,
2022
- selectedExampleKey: selectedExample?.key,
2023
- onSelectExample: setSelectedExampleKey,
2024
- languageOptions,
2025
- selectedLanguageKey: selectedCode.languageKey,
2026
2031
  onSelectLanguage: (value) => {
2027
2032
  const nextCode = codeOptions.find((option) => option.languageKey === value);
2028
2033
  setSelectedLanguageKey(nextCode?.languageKey ?? value);
2029
2034
  setSelectedClientKey(nextCode?.clientKey ?? "");
2030
2035
  },
2031
- clientOptions,
2032
- selectedClientKey: selectedCode.clientKey,
2033
2036
  onSelectClient: setSelectedClientKey
2034
- });
2037
+ };
2035
2038
  }
2036
- function ResponseExamplesPanel(arg0) {
2037
- const { operation, spec } = arg0;
2039
+ function RequestExamplesPanel(arg0) {
2040
+ const { spec, path, method, parameters, requestContents, selectedMediaType, onSelectMediaType, selectedServer, serverVariables, auth, sharedExampleKey, onSelectExampleKey } = arg0;
2038
2041
  const t = require_PageActions.useBuiltInText();
2042
+ const state = useRequestExamplesState({
2043
+ spec,
2044
+ path,
2045
+ method,
2046
+ parameters,
2047
+ requestContents,
2048
+ selectedMediaType,
2049
+ onSelectMediaType,
2050
+ selectedServer,
2051
+ serverVariables,
2052
+ auth,
2053
+ sharedExampleKey,
2054
+ onSelectExampleKey
2055
+ });
2056
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ApiExampleCodeGroup, {
2057
+ title: t("openapi.request"),
2058
+ tag: method,
2059
+ label: path,
2060
+ code: state.selectedCode.code,
2061
+ language: state.selectedCode.language,
2062
+ mediaTypes: requestContents.map((content) => content.mediaType),
2063
+ selectedMediaType: state.selectedContent?.mediaType,
2064
+ onSelectMediaType: state.onSelectMediaType,
2065
+ examples: state.examples,
2066
+ selectedExampleKey: state.selectedExample?.key,
2067
+ onSelectExample: state.onSelectExample,
2068
+ languageOptions: state.languageOptions,
2069
+ selectedLanguageKey: state.selectedCode.languageKey,
2070
+ onSelectLanguage: state.onSelectLanguage,
2071
+ clientOptions: state.clientOptions,
2072
+ selectedClientKey: state.selectedCode.clientKey,
2073
+ onSelectClient: state.onSelectClient
2074
+ });
2075
+ }
2076
+ function firstExampleKeyForResponseContent(content) {
2077
+ return getExampleEntries(content?.value)[0]?.key ?? "";
2078
+ }
2079
+ function useResponseExamplesState(arg0) {
2080
+ const { operation, spec, sharedExampleKey, onSelectExampleKey } = arg0;
2039
2081
  const responses = getResponseEntries(operation, spec).filter(({ response }) => getMediaTypeEntries(response.content, spec).length > 0);
2040
2082
  const [selectedStatus, setSelectedStatus] = (0, react.useState)(responses.find(({ status }) => status.startsWith("2"))?.status ?? responses[0]?.status ?? "");
2041
2083
  const selectedResponse = responses.find(({ status }) => status === selectedStatus) ?? responses[0];
@@ -2044,31 +2086,56 @@ function ResponseExamplesPanel(arg0) {
2044
2086
  const selectedContent = responseContents.find((content) => content.mediaType === selectedMediaType) ?? responseContents[0];
2045
2087
  const examples = getExampleEntries(selectedContent?.value);
2046
2088
  const [selectedExampleKey, setSelectedExampleKey] = (0, react.useState)(examples[0]?.key ?? "");
2047
- const selectedExample = examples.find((example) => example.key === selectedExampleKey) ?? examples[0];
2048
- const responseCode = stringifyExample(selectedExample?.value);
2049
- if (!selectedResponse || !selectedContent || !responseCode) return null;
2050
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ApiExampleCodeGroup, {
2051
- title: t("openapi.response"),
2052
- tag: selectedResponse.status,
2053
- tagOptions: responses.map(({ status }) => status),
2054
- onSelectTag: (value) => {
2089
+ const currentExampleKey = (sharedExampleKey && examples.some((example) => example.key === sharedExampleKey) ? sharedExampleKey : void 0) ?? selectedExampleKey;
2090
+ const selectedExample = examples.find((example) => example.key === currentExampleKey) ?? examples[0];
2091
+ return {
2092
+ responses,
2093
+ selectedResponse,
2094
+ responseContents,
2095
+ selectedContent,
2096
+ examples,
2097
+ selectedExample,
2098
+ responseCode: stringifyExample(selectedExample?.value),
2099
+ onSelectStatus: (value) => {
2055
2100
  const nextContents = getMediaTypeEntries(responses.find(({ status }) => status === value)?.response.content, spec);
2056
2101
  setSelectedStatus(value);
2057
2102
  setSelectedMediaType(nextContents[0]?.mediaType ?? "");
2058
- setSelectedExampleKey(getExampleEntries(nextContents[0]?.value)[0]?.key ?? "");
2103
+ setSelectedExampleKey(firstExampleKeyForResponseContent(nextContents[0]));
2059
2104
  },
2060
- label: selectedContent.mediaType,
2061
- labelOptions: responseContents.map((content) => content.mediaType),
2062
- onSelectLabel: (value) => {
2105
+ onSelectMediaType: (value) => {
2063
2106
  setSelectedMediaType(value);
2064
- setSelectedExampleKey(getExampleEntries(responseContents.find((content) => content.mediaType === value)?.value)[0]?.key ?? "");
2107
+ setSelectedExampleKey(firstExampleKeyForResponseContent(responseContents.find((content) => content.mediaType === value)));
2065
2108
  },
2109
+ onSelectExample: (value) => {
2110
+ setSelectedExampleKey(value);
2111
+ onSelectExampleKey?.(value);
2112
+ }
2113
+ };
2114
+ }
2115
+ function ResponseExamplesPanel(arg0) {
2116
+ const { operation, spec, sharedExampleKey, onSelectExampleKey } = arg0;
2117
+ const t = require_PageActions.useBuiltInText();
2118
+ const state = useResponseExamplesState({
2119
+ operation,
2120
+ spec,
2121
+ sharedExampleKey,
2122
+ onSelectExampleKey
2123
+ });
2124
+ if (!state.selectedResponse || !state.selectedContent || !state.responseCode) return null;
2125
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ApiExampleCodeGroup, {
2126
+ title: t("openapi.response"),
2127
+ tag: state.selectedResponse.status,
2128
+ tagOptions: state.responses.map(({ status }) => status),
2129
+ onSelectTag: state.onSelectStatus,
2130
+ label: state.selectedContent.mediaType,
2131
+ labelOptions: state.responseContents.map((content) => content.mediaType),
2132
+ onSelectLabel: state.onSelectMediaType,
2066
2133
  comfortableMeta: true,
2067
- code: responseCode,
2068
- language: codeLanguageForMediaType(selectedContent.mediaType),
2069
- examples,
2070
- selectedExampleKey: selectedExample?.key,
2071
- onSelectExample: setSelectedExampleKey
2134
+ code: state.responseCode,
2135
+ language: codeLanguageForMediaType(state.selectedContent.mediaType),
2136
+ examples: state.examples,
2137
+ selectedExampleKey: state.selectedExample?.key,
2138
+ onSelectExample: state.onSelectExample
2072
2139
  });
2073
2140
  }
2074
2141
  //#endregion
@@ -2331,7 +2398,7 @@ function ResponseList(arg0) {
2331
2398
  //#endregion
2332
2399
  //#region source/openapi/components/EndpointSections.tsx
2333
2400
  function EndpointRequest(arg0) {
2334
- const { spec, path, method, description, groupedParameters, parameters, requestBody, requestContents, requestSchema, selectedRequestMediaType, onSelectRequestMediaType, selectedServer, serverVariables, auth } = arg0;
2401
+ const { spec, path, method, description, groupedParameters, parameters, requestBody, requestContents, requestSchema, selectedRequestMediaType, onSelectRequestMediaType, selectedServer, serverVariables, auth, sharedExampleKey, onSelectExampleKey } = arg0;
2335
2402
  const t = require_PageActions.useBuiltInText();
2336
2403
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Row, {
2337
2404
  className: "relative mt-6",
@@ -2370,13 +2437,15 @@ function EndpointRequest(arg0) {
2370
2437
  onSelectMediaType: onSelectRequestMediaType,
2371
2438
  selectedServer,
2372
2439
  serverVariables,
2373
- auth
2440
+ auth,
2441
+ sharedExampleKey,
2442
+ onSelectExampleKey
2374
2443
  })
2375
2444
  })]
2376
2445
  });
2377
2446
  }
2378
2447
  function EndpointResponse(arg0) {
2379
- const { spec, operation } = arg0;
2448
+ const { spec, operation, sharedExampleKey, onSelectExampleKey } = arg0;
2380
2449
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Row, {
2381
2450
  className: "relative mt-6",
2382
2451
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Col, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResponseList, {
@@ -2386,27 +2455,127 @@ function EndpointResponse(arg0) {
2386
2455
  sticky: true,
2387
2456
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResponseExamplesPanel, {
2388
2457
  operation,
2389
- spec
2458
+ spec,
2459
+ sharedExampleKey,
2460
+ onSelectExampleKey
2390
2461
  })
2391
2462
  })]
2392
2463
  });
2393
2464
  }
2394
2465
  //#endregion
2466
+ //#region source/openapi/components/OpenApiOperation.state.ts
2467
+ function useOperationRequestState(spec, path, operation) {
2468
+ const parameters = getOperationParameters(spec, path, operation);
2469
+ const requestBody = getRequestBody$1(spec, operation);
2470
+ const requestContents = getMediaTypeEntries(requestBody?.content, spec);
2471
+ const [selectedRequestMediaType, setSelectedRequestMediaType] = (0, react.useState)(requestContents[0]?.mediaType ?? "");
2472
+ const selectedRequestContent = requestContents.find((content) => content.mediaType === selectedRequestMediaType) ?? requestContents[0];
2473
+ const requestSchema = selectedRequestContent?.value.schema;
2474
+ const groupedParameters = {
2475
+ path: parameters.filter((parameter) => parameter.in === "path"),
2476
+ query: parameters.filter((parameter) => parameter.in === "query"),
2477
+ header: parameters.filter((parameter) => parameter.in === "header")
2478
+ };
2479
+ return {
2480
+ parameters,
2481
+ requestBody,
2482
+ requestContents,
2483
+ selectedRequestMediaType: selectedRequestContent?.mediaType ?? "",
2484
+ setSelectedRequestMediaType,
2485
+ requestSchema,
2486
+ groupedParameters
2487
+ };
2488
+ }
2489
+ function useOperationServerState(spec, operation, path) {
2490
+ const servers = getServers(spec, operation, path);
2491
+ const [selectedServerKey, setSelectedServerKey] = (0, react.useState)(getServerKey(servers[0], 0));
2492
+ const selectedServer = servers.find((server, index) => getServerKey(server, index) === selectedServerKey) ?? servers[0];
2493
+ const [serverVariables, setServerVariables] = (0, react.useState)(defaultServerVariables(selectedServer));
2494
+ const [serverOpen, setServerOpen] = (0, react.useState)(false);
2495
+ return {
2496
+ servers,
2497
+ selectedServerKey,
2498
+ selectedServer,
2499
+ serverVariables,
2500
+ serverOpen,
2501
+ onSelectServer: (value) => {
2502
+ const nextServer = servers.find((server, index) => getServerKey(server, index) === value) ?? servers[0];
2503
+ setSelectedServerKey(value);
2504
+ setServerVariables(defaultServerVariables(nextServer));
2505
+ },
2506
+ onChangeServerVariable: (name, value) => setServerVariables((current) => ({
2507
+ ...current,
2508
+ [name]: value
2509
+ })),
2510
+ onToggleServer: () => setServerOpen((current) => !current),
2511
+ closeServer: () => setServerOpen(false)
2512
+ };
2513
+ }
2514
+ function useOperationAuthState(spec, operation) {
2515
+ const authOptions = getAuthOptions(spec, operation);
2516
+ const [selectedAuthName, setSelectedAuthName] = (0, react.useState)(authOptions[0]?.name ?? "");
2517
+ const selectedAuth = authOptions.find((option) => option.name === selectedAuthName);
2518
+ const [authValues, setAuthValues] = (0, react.useState)({});
2519
+ const [authOpen, setAuthOpen] = (0, react.useState)(false);
2520
+ return {
2521
+ authOptions,
2522
+ selectedAuthName,
2523
+ selectedAuth,
2524
+ authValues,
2525
+ authOpen,
2526
+ authInput: selectedAuth ? {
2527
+ name: selectedAuth.name,
2528
+ scheme: selectedAuth.scheme,
2529
+ value: authValues[selectedAuth.name] ?? authPlaceholder(selectedAuth)
2530
+ } : void 0,
2531
+ onSelectAuth: setSelectedAuthName,
2532
+ onChangeAuthValue: (name, value) => setAuthValues((current) => ({
2533
+ ...current,
2534
+ [name]: value
2535
+ })),
2536
+ onToggleAuth: () => setAuthOpen((current) => !current),
2537
+ closeAuth: () => setAuthOpen(false)
2538
+ };
2539
+ }
2540
+ //#endregion
2395
2541
  //#region source/openapi/components/OpenApiOperation.tsx
2396
- var endpointMethodStyles = {
2397
- GET: "bg-emerald-400/15 text-emerald-600 dark:bg-emerald-400/20 dark:text-emerald-300",
2398
- POST: "bg-sky-400/15 text-sky-600 dark:bg-sky-400/20 dark:text-sky-300",
2399
- PUT: "bg-amber-400/15 text-amber-600 dark:bg-amber-400/20 dark:text-amber-300",
2400
- PATCH: "bg-amber-400/15 text-amber-600 dark:bg-amber-400/20 dark:text-amber-300",
2401
- DELETE: "bg-rose-400/15 text-rose-600 dark:bg-rose-400/20 dark:text-rose-300"
2542
+ var endpointMethodStyleVars = {
2543
+ GET: "bg-(--clarify-http-method-get-background) text-(--clarify-http-method-get-text)",
2544
+ POST: "bg-(--clarify-http-method-post-background) text-(--clarify-http-method-post-text)",
2545
+ PUT: "bg-(--clarify-http-method-put-background) text-(--clarify-http-method-put-text)",
2546
+ PATCH: "bg-(--clarify-http-method-patch-background) text-(--clarify-http-method-patch-text)",
2547
+ DELETE: "bg-(--clarify-http-method-delete-background) text-(--clarify-http-method-delete-text)"
2402
2548
  };
2403
2549
  function EndpointMethodBadge(arg0) {
2404
2550
  const { method } = arg0;
2405
2551
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2406
- className: (0, clsx.default)("rounded-(--clarify-theme-tokens-radius-md) px-2.5 py-0.5 text-xs/6 font-black tracking-wide", endpointMethodStyles[method] ?? "bg-zinc-400/15 text-zinc-700 dark:bg-zinc-400/20 dark:text-zinc-200"),
2552
+ className: (0, clsx.default)("rounded-(--clarify-theme-tokens-radius-md) px-2.5 py-0.5 text-xs/6 font-black tracking-wide", endpointMethodStyleVars[method] ?? "bg-(--clarify-http-method-default-background) text-(--clarify-http-method-default-text)"),
2407
2553
  children: method
2408
2554
  });
2409
2555
  }
2556
+ function EndpointPath(arg0) {
2557
+ const { path } = arg0;
2558
+ const segments = path.split("/").filter(Boolean);
2559
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2560
+ className: "flex min-w-0 flex-1 items-center overflow-x-auto text-sm font-bold leading-6 whitespace-nowrap",
2561
+ children: segments.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2562
+ className: "text-(--clarify-ui-text-faint)",
2563
+ children: "/"
2564
+ }), segments.map((segment, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2565
+ className: "flex items-center",
2566
+ children: [index > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2567
+ className: "text-(--clarify-ui-text-faint)",
2568
+ children: "/"
2569
+ }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2570
+ className: "font-bold text-(--clarify-theme-tokens-colors-foreground)",
2571
+ children: segment
2572
+ })]
2573
+ }, `${segment}-${index}`))] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2574
+ className: "font-bold text-(--clarify-theme-tokens-colors-foreground)",
2575
+ children: "/"
2576
+ })
2577
+ });
2578
+ }
2410
2579
  function InlineListbox(arg0) {
2411
2580
  const { label, value, options, onChange, compact = false } = arg0;
2412
2581
  const selected = options.find((option) => option.value === value) ?? options[0];
@@ -2522,7 +2691,7 @@ function ServerPanel(arg0) {
2522
2691
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2523
2692
  className: "border-t border-(--clarify-theme-tokens-colors-border) bg-(--clarify-ui-subtle-background) p-3",
2524
2693
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2525
- className: "grid gap-3 sm:grid-cols-(--clarify-openapi-control-grid)",
2694
+ className: "flex flex-col gap-3",
2526
2695
  children: [servers.length > 1 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
2527
2696
  className: "flex min-w-0 flex-col gap-1.5",
2528
2697
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -2538,18 +2707,21 @@ function ServerPanel(arg0) {
2538
2707
  })),
2539
2708
  onChange: onSelectServer
2540
2709
  })]
2541
- }) : null, variableEntries.map(([name, variable]) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
2542
- className: "flex min-w-0 flex-col gap-1.5",
2543
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2544
- className: "text-2xs font-semibold text-(--clarify-ui-text-soft)",
2545
- children: name
2546
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ServerVariableControl, {
2547
- name,
2548
- variable,
2549
- value: variables[name] ?? variable.default ?? "",
2550
- onChange: (value) => onChangeVariable(name, value)
2551
- })]
2552
- }, name))]
2710
+ }) : null, variableEntries.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2711
+ className: "grid gap-3 sm:grid-cols-(--clarify-openapi-variable-grid)",
2712
+ children: variableEntries.map(([name, variable]) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
2713
+ className: "flex min-w-0 flex-col gap-1.5",
2714
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2715
+ className: "text-2xs font-semibold text-(--clarify-ui-text-soft)",
2716
+ children: name
2717
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ServerVariableControl, {
2718
+ name,
2719
+ variable,
2720
+ value: variables[name] ?? variable.default ?? "",
2721
+ onChange: (value) => onChangeVariable(name, value)
2722
+ })]
2723
+ }, name))
2724
+ }) : null]
2553
2725
  })
2554
2726
  });
2555
2727
  }
@@ -2597,7 +2769,6 @@ function AuthPanel(arg0) {
2597
2769
  }
2598
2770
  function EndpointIdentity(arg0) {
2599
2771
  const { method, path, servers, selectedServerKey, selectedServer, serverVariables, serverOpen, authOptions, selectedAuthName, selectedAuth, authValues, authOpen, onSelectServer, onChangeServerVariable, onToggleServer, onToggleAuth, onSelectAuth, onChangeAuthValue } = arg0;
2600
- const segments = path.split("/").filter(Boolean);
2601
2772
  const serverInteractive = servers.length > 1 || Object.keys(selectedServer.variables ?? {}).length > 0;
2602
2773
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2603
2774
  className: "not-prose flex w-full flex-col overflow-hidden rounded-xl border border-(--clarify-theme-tokens-colors-border) bg-(--clarify-theme-tokens-colors-surface) shadow-xs",
@@ -2613,25 +2784,7 @@ function EndpointIdentity(arg0) {
2613
2784
  interactive: serverInteractive,
2614
2785
  onToggle: onToggleServer
2615
2786
  }),
2616
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2617
- className: "flex min-w-0 flex-1 items-center overflow-x-auto text-sm font-bold leading-6 whitespace-nowrap",
2618
- children: segments.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2619
- className: "text-(--clarify-ui-text-faint)",
2620
- children: "/"
2621
- }), segments.map((segment, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2622
- className: "flex items-center",
2623
- children: [index > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2624
- className: "text-(--clarify-ui-text-faint)",
2625
- children: "/"
2626
- }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2627
- className: "font-bold text-(--clarify-theme-tokens-colors-foreground)",
2628
- children: segment
2629
- })]
2630
- }, `${segment}-${index}`))] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2631
- className: "font-bold text-(--clarify-theme-tokens-colors-foreground)",
2632
- children: "/"
2633
- })
2634
- }),
2787
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EndpointPath, { path }),
2635
2788
  authOptions.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2636
2789
  type: "button",
2637
2790
  "aria-expanded": authOpen,
@@ -2672,32 +2825,10 @@ function OpenApiOperation(arg0) {
2672
2825
  const id = (0, github_slugger.slug)(`${method.toLowerCase()} ${path}`);
2673
2826
  const summary = operation.summary ?? `${method} ${path}`;
2674
2827
  const description = operation.description;
2675
- const parameters = getOperationParameters(spec, path, operation);
2676
- const requestBody = getRequestBody$1(spec, operation);
2677
- const requestContents = getMediaTypeEntries(requestBody?.content, spec);
2678
- const [selectedRequestMediaType, setSelectedRequestMediaType] = (0, react.useState)(requestContents[0]?.mediaType ?? "");
2679
- const selectedRequestContent = requestContents.find((content) => content.mediaType === selectedRequestMediaType) ?? requestContents[0];
2680
- const requestSchema = selectedRequestContent?.value.schema;
2681
- const servers = getServers(spec, operation, path);
2682
- const [selectedServerKey, setSelectedServerKey] = (0, react.useState)(getServerKey(servers[0], 0));
2683
- const selectedServer = servers.find((server, index) => getServerKey(server, index) === selectedServerKey) ?? servers[0];
2684
- const [serverVariables, setServerVariables] = (0, react.useState)(defaultServerVariables(selectedServer));
2685
- const [serverOpen, setServerOpen] = (0, react.useState)(false);
2686
- const authOptions = getAuthOptions(spec, operation);
2687
- const [selectedAuthName, setSelectedAuthName] = (0, react.useState)(authOptions[0]?.name ?? "");
2688
- const selectedAuth = authOptions.find((option) => option.name === selectedAuthName);
2689
- const [authValues, setAuthValues] = (0, react.useState)({});
2690
- const [authOpen, setAuthOpen] = (0, react.useState)(false);
2691
- const authInput = selectedAuth ? {
2692
- name: selectedAuth.name,
2693
- scheme: selectedAuth.scheme,
2694
- value: authValues[selectedAuth.name] ?? authPlaceholder(selectedAuth)
2695
- } : void 0;
2696
- const groupedParameters = {
2697
- path: parameters.filter((parameter) => parameter.in === "path"),
2698
- query: parameters.filter((parameter) => parameter.in === "query"),
2699
- header: parameters.filter((parameter) => parameter.in === "header")
2700
- };
2828
+ const requestState = useOperationRequestState(spec, path, operation);
2829
+ const serverState = useOperationServerState(spec, operation, path);
2830
+ const authState = useOperationAuthState(spec, operation);
2831
+ const [linkedExampleKey, setLinkedExampleKey] = (0, react.useState)("");
2701
2832
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
2702
2833
  className: "clarify-api-endpoint scroll-mt-24 pb-16 first:pt-0 last:pb-0",
2703
2834
  "aria-labelledby": id,
@@ -2709,58 +2840,52 @@ function OpenApiOperation(arg0) {
2709
2840
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EndpointIdentity, {
2710
2841
  method,
2711
2842
  path,
2712
- servers,
2713
- selectedServerKey,
2714
- selectedServer,
2715
- serverVariables,
2716
- serverOpen,
2717
- authOptions,
2718
- selectedAuthName,
2719
- selectedAuth,
2720
- authValues,
2721
- authOpen,
2722
- onSelectServer: (value) => {
2723
- const nextServer = servers.find((server, index) => getServerKey(server, index) === value) ?? servers[0];
2724
- setSelectedServerKey(value);
2725
- setServerVariables(defaultServerVariables(nextServer));
2726
- },
2727
- onChangeServerVariable: (name, value) => setServerVariables((current) => ({
2728
- ...current,
2729
- [name]: value
2730
- })),
2843
+ servers: serverState.servers,
2844
+ selectedServerKey: serverState.selectedServerKey,
2845
+ selectedServer: serverState.selectedServer,
2846
+ serverVariables: serverState.serverVariables,
2847
+ serverOpen: serverState.serverOpen,
2848
+ authOptions: authState.authOptions,
2849
+ selectedAuthName: authState.selectedAuthName,
2850
+ selectedAuth: authState.selectedAuth,
2851
+ authValues: authState.authValues,
2852
+ authOpen: authState.authOpen,
2853
+ onSelectServer: serverState.onSelectServer,
2854
+ onChangeServerVariable: serverState.onChangeServerVariable,
2731
2855
  onToggleServer: () => {
2732
- setServerOpen((current) => !current);
2733
- setAuthOpen(false);
2856
+ serverState.onToggleServer();
2857
+ authState.closeAuth();
2734
2858
  },
2735
2859
  onToggleAuth: () => {
2736
- setAuthOpen((current) => !current);
2737
- setServerOpen(false);
2860
+ authState.onToggleAuth();
2861
+ serverState.closeServer();
2738
2862
  },
2739
- onSelectAuth: setSelectedAuthName,
2740
- onChangeAuthValue: (name, value) => setAuthValues((current) => ({
2741
- ...current,
2742
- [name]: value
2743
- }))
2863
+ onSelectAuth: authState.onSelectAuth,
2864
+ onChangeAuthValue: authState.onChangeAuthValue
2744
2865
  }),
2745
2866
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EndpointRequest, {
2746
2867
  spec,
2747
2868
  path,
2748
2869
  method,
2749
2870
  description,
2750
- groupedParameters,
2751
- parameters,
2752
- requestBody,
2753
- requestContents,
2754
- requestSchema,
2755
- selectedRequestMediaType: selectedRequestContent?.mediaType ?? "",
2756
- onSelectRequestMediaType: setSelectedRequestMediaType,
2757
- selectedServer,
2758
- serverVariables,
2759
- auth: authInput
2871
+ groupedParameters: requestState.groupedParameters,
2872
+ parameters: requestState.parameters,
2873
+ requestBody: requestState.requestBody,
2874
+ requestContents: requestState.requestContents,
2875
+ requestSchema: requestState.requestSchema,
2876
+ selectedRequestMediaType: requestState.selectedRequestMediaType,
2877
+ onSelectRequestMediaType: requestState.setSelectedRequestMediaType,
2878
+ selectedServer: serverState.selectedServer,
2879
+ serverVariables: serverState.serverVariables,
2880
+ auth: authState.authInput,
2881
+ sharedExampleKey: linkedExampleKey,
2882
+ onSelectExampleKey: setLinkedExampleKey
2760
2883
  }),
2761
2884
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EndpointResponse, {
2762
2885
  spec,
2763
- operation
2886
+ operation,
2887
+ sharedExampleKey: linkedExampleKey,
2888
+ onSelectExampleKey: setLinkedExampleKey
2764
2889
  })
2765
2890
  ]
2766
2891
  });
@@ -2947,4 +3072,4 @@ Object.defineProperty(exports, "primitives_exports", {
2947
3072
  }
2948
3073
  });
2949
3074
 
2950
- //# sourceMappingURL=OpenApiOperation-BMXfV15v.cjs.map
3075
+ //# sourceMappingURL=OpenApiOperation-CP_fxT_F.cjs.map