@clarify-labs/renderer 0.9.1 → 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-291_IXxJ.js → ClarifyShell-C38EkErX.js} +199 -159
  2. package/output/ClarifyShell-C38EkErX.js.map +1 -0
  3. package/output/{ClarifyShell-DJ4fOVOd.cjs → ClarifyShell-DdYRgrfY.cjs} +199 -159
  4. package/output/ClarifyShell-DdYRgrfY.cjs.map +1 -0
  5. package/output/{OpenApiOperation-3DUVruIO.cjs → OpenApiOperation-CP_fxT_F.cjs} +343 -218
  6. package/output/OpenApiOperation-CP_fxT_F.cjs.map +1 -0
  7. package/output/{OpenApiOperation-E8lSLsSK.js → OpenApiOperation-DIFaYAe5.js} +343 -218
  8. package/output/OpenApiOperation-DIFaYAe5.js.map +1 -0
  9. package/output/{PageActions-GI1t-JrR.cjs → PageActions-B08cDCzq.cjs} +276 -173
  10. package/output/PageActions-B08cDCzq.cjs.map +1 -0
  11. package/output/{PageActions-DaXQgMYP.js → PageActions-tmnpzi23.js} +277 -174
  12. package/output/PageActions-tmnpzi23.js.map +1 -0
  13. package/output/app/SectionProvider.d.ts +1 -1
  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-yBo2SUlA.js → render-6gHfrR9h.js} +2 -2
  30. package/output/{render-yBo2SUlA.js.map → render-6gHfrR9h.js.map} +1 -1
  31. package/output/{render-r9DclX3Y.cjs → render-Bvf5ZMZb.cjs} +2 -2
  32. package/output/{render-r9DclX3Y.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-291_IXxJ.js.map +0 -1
  39. package/output/ClarifyShell-DJ4fOVOd.cjs.map +0 -1
  40. package/output/OpenApiOperation-3DUVruIO.cjs.map +0 -1
  41. package/output/OpenApiOperation-E8lSLsSK.js.map +0 -1
  42. package/output/PageActions-DaXQgMYP.js.map +0 -1
  43. package/output/PageActions-GI1t-JrR.cjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { D as copyTextToClipboard, M as useConfig, N as useLocale, O as useBuiltInText, T as localizeHref, c as remToPx, g as useTheme, l as lucideIconRegistry, n as PageTitleActions, s as useSectionStore, u as resolveLucideIconName, w as isExternalHref } from "./PageActions-DaXQgMYP.js";
1
+ import { D as copyTextToClipboard, M as useConfig, N as useLocale, O as useBuiltInText, T as localizeHref, c as remToPx, g as useTheme, l as lucideIconRegistry, n as PageTitleActions, s as useSectionStore, u as resolveLucideIconName, w as isExternalHref } from "./PageActions-tmnpzi23.js";
2
2
  import { t as markdownRemarkPlugins } from "./remark-Dd2WU50s.js";
3
3
  import clsx from "clsx";
4
4
  import { Children, createContext, createElement, forwardRef, isValidElement, useContext, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
@@ -1734,7 +1734,7 @@ function buildRequestCodeExamples(input) {
1734
1734
  }));
1735
1735
  }
1736
1736
  //#endregion
1737
- //#region source/openapi/components/ExamplePanels.tsx
1737
+ //#region source/openapi/components/SelectControl.tsx
1738
1738
  function SelectControl(arg0) {
1739
1739
  const { label, value, options, onChange, icon, compact = false } = arg0;
1740
1740
  const normalizedOptions = options.map((option) => typeof option === "string" ? {
@@ -1781,69 +1781,8 @@ function SelectControl(arg0) {
1781
1781
  })
1782
1782
  });
1783
1783
  }
1784
- function getExampleLabel(example, t) {
1785
- return example.generated && example.title === "schema" ? t("openapi.schemaExample") : example.title;
1786
- }
1787
- function getLanguageOptions(codeOptions) {
1788
- const languages = /* @__PURE__ */ new Map();
1789
- for (const option of codeOptions ?? []) languages.set(option.languageKey, option.title);
1790
- return Array.from(languages, ([value, label]) => ({
1791
- value,
1792
- label
1793
- }));
1794
- }
1795
- function getClientOptions(codeOptions, languageKey) {
1796
- return (codeOptions ?? []).filter((option) => option.languageKey === languageKey).map((option) => ({
1797
- value: option.clientKey,
1798
- label: option.clientTitle
1799
- }));
1800
- }
1801
- function getServers(spec, operation, path) {
1802
- const operationServers = operation.servers;
1803
- const pathServers = path ? getPathItem(spec, path)?.servers : void 0;
1804
- const servers = Array.isArray(operationServers) ? operationServers : Array.isArray(pathServers) ? pathServers : spec.servers;
1805
- if (!Array.isArray(servers)) return [{ url: "https://api.example.com" }];
1806
- const validServers = servers.filter((server) => isRecord(server) && typeof server.url === "string");
1807
- return validServers.length > 0 ? validServers : [{ url: "https://api.example.com" }];
1808
- }
1809
- function getServerKey(server, index) {
1810
- return `${index}:${server.url ?? ""}`;
1811
- }
1812
- function getServerLabel(server, index) {
1813
- return server.url ?? `Server ${index + 1}`;
1814
- }
1815
- function defaultServerVariables(server) {
1816
- return Object.fromEntries(Object.entries(server?.variables ?? {}).map(([name, variable]) => [name, variable.default ?? variable.enum?.[0] ?? ""]));
1817
- }
1818
- function getSecuritySchemes(spec) {
1819
- const schemes = spec.components;
1820
- if (!isRecord(schemes) || !isRecord(schemes.securitySchemes)) return {};
1821
- return Object.fromEntries(Object.entries(schemes.securitySchemes).filter((entry) => isRecord(entry[1])));
1822
- }
1823
- function getSecurityRequirements(spec, operation) {
1824
- const operationSecurity = operation.security;
1825
- if (Array.isArray(operationSecurity)) return operationSecurity.filter(isRecord);
1826
- const specSecurity = spec.security;
1827
- return Array.isArray(specSecurity) ? specSecurity.filter(isRecord) : [];
1828
- }
1829
- function getAuthOptions(spec, operation) {
1830
- const schemes = getSecuritySchemes(spec);
1831
- const requirements = getSecurityRequirements(spec, operation);
1832
- const names = new Set(requirements.flatMap((requirement) => Object.keys(requirement)));
1833
- return Array.from(names).map((name) => ({
1834
- name,
1835
- scheme: schemes[name]
1836
- })).filter((option) => Boolean(option.scheme));
1837
- }
1838
- function authPlaceholder(auth) {
1839
- if (!auth) return "";
1840
- if (auth.scheme.type === "apiKey") return "{api_key}";
1841
- if (auth.scheme.type === "http" && auth.scheme.scheme?.toLowerCase() === "basic") return "{base64_credentials}";
1842
- return "{token}";
1843
- }
1844
- function authLabel(name, scheme) {
1845
- return `${name}${scheme.type === "apiKey" && scheme.in && scheme.name ? ` · ${scheme.in}: ${scheme.name}` : ""}`;
1846
- }
1784
+ //#endregion
1785
+ //#region source/openapi/components/CodeDisplay.tsx
1847
1786
  function CopyCodeButton(arg0) {
1848
1787
  const { code } = arg0;
1849
1788
  const t = useBuiltInText();
@@ -1909,6 +1848,73 @@ function CodeToolbar(arg0) {
1909
1848
  }), /* @__PURE__ */ jsx(CopyCodeButton, { code })]
1910
1849
  });
1911
1850
  }
1851
+ //#endregion
1852
+ //#region source/openapi/components/helpers.ts
1853
+ function getServers(spec, operation, path) {
1854
+ const operationServers = operation.servers;
1855
+ const pathServers = path ? getPathItem(spec, path)?.servers : void 0;
1856
+ const servers = Array.isArray(operationServers) ? operationServers : Array.isArray(pathServers) ? pathServers : spec.servers;
1857
+ if (!Array.isArray(servers)) return [{ url: "https://api.example.com" }];
1858
+ const validServers = servers.filter((server) => isRecord(server) && typeof server.url === "string");
1859
+ return validServers.length > 0 ? validServers : [{ url: "https://api.example.com" }];
1860
+ }
1861
+ function getServerKey(server, index) {
1862
+ return `${index}:${server.url ?? ""}`;
1863
+ }
1864
+ function getServerLabel(server, index) {
1865
+ return server.url ?? `Server ${index + 1}`;
1866
+ }
1867
+ function defaultServerVariables(server) {
1868
+ return Object.fromEntries(Object.entries(server?.variables ?? {}).map(([name, variable]) => [name, variable.default ?? variable.enum?.[0] ?? ""]));
1869
+ }
1870
+ function getSecuritySchemes(spec) {
1871
+ const schemes = spec.components;
1872
+ if (!isRecord(schemes) || !isRecord(schemes.securitySchemes)) return {};
1873
+ return Object.fromEntries(Object.entries(schemes.securitySchemes).filter((entry) => isRecord(entry[1])));
1874
+ }
1875
+ function getSecurityRequirements(spec, operation) {
1876
+ const operationSecurity = operation.security;
1877
+ if (Array.isArray(operationSecurity)) return operationSecurity.filter(isRecord);
1878
+ const specSecurity = spec.security;
1879
+ return Array.isArray(specSecurity) ? specSecurity.filter(isRecord) : [];
1880
+ }
1881
+ function getAuthOptions(spec, operation) {
1882
+ const schemes = getSecuritySchemes(spec);
1883
+ const requirements = getSecurityRequirements(spec, operation);
1884
+ const names = new Set(requirements.flatMap((requirement) => Object.keys(requirement)));
1885
+ return Array.from(names).map((name) => ({
1886
+ name,
1887
+ scheme: schemes[name]
1888
+ })).filter((option) => Boolean(option.scheme));
1889
+ }
1890
+ function authPlaceholder(auth) {
1891
+ if (!auth) return "";
1892
+ if (auth.scheme.type === "apiKey") return "{api_key}";
1893
+ if (auth.scheme.type === "http" && auth.scheme.scheme?.toLowerCase() === "basic") return "{base64_credentials}";
1894
+ return "{token}";
1895
+ }
1896
+ function authLabel(name, scheme) {
1897
+ return `${name}${scheme.type === "apiKey" && scheme.in && scheme.name ? ` · ${scheme.in}: ${scheme.name}` : ""}`;
1898
+ }
1899
+ function getExampleLabel(example, t) {
1900
+ return example.generated && example.title === "schema" ? t("openapi.schemaExample") : example.title;
1901
+ }
1902
+ function getLanguageOptions(codeOptions) {
1903
+ const languages = /* @__PURE__ */ new Map();
1904
+ for (const option of codeOptions ?? []) languages.set(option.languageKey, option.title);
1905
+ return Array.from(languages, ([value, label]) => ({
1906
+ value,
1907
+ label
1908
+ }));
1909
+ }
1910
+ function getClientOptions(codeOptions, languageKey) {
1911
+ return (codeOptions ?? []).filter((option) => option.languageKey === languageKey).map((option) => ({
1912
+ value: option.clientKey,
1913
+ label: option.clientTitle
1914
+ }));
1915
+ }
1916
+ //#endregion
1917
+ //#region source/openapi/components/ExamplePanels.tsx
1912
1918
  function ApiExampleCodeGroup(arg0) {
1913
1919
  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;
1914
1920
  const t = useBuiltInText();
@@ -1985,15 +1991,18 @@ function ApiExampleCodeGroup(arg0) {
1985
1991
  })
1986
1992
  });
1987
1993
  }
1988
- function RequestExamplesPanel(arg0) {
1989
- const { spec, path, method, parameters, requestContents, selectedMediaType, onSelectMediaType, selectedServer, serverVariables, auth } = arg0;
1990
- const t = useBuiltInText();
1994
+ function firstExampleKeyForMediaType(requestContents, mediaType) {
1995
+ return getExampleEntries(requestContents.find((content) => content.mediaType === mediaType)?.value)[0]?.key ?? "";
1996
+ }
1997
+ function useRequestExamplesState(arg0) {
1998
+ const { spec, path, method, parameters, requestContents, selectedMediaType, onSelectMediaType, selectedServer, serverVariables, auth, sharedExampleKey, onSelectExampleKey } = arg0;
1991
1999
  const selectedContent = requestContents.find((content) => content.mediaType === selectedMediaType) ?? requestContents[0];
1992
2000
  const examples = getExampleEntries(selectedContent?.value);
1993
2001
  const [selectedExampleKey, setSelectedExampleKey] = useState(examples[0]?.key ?? "");
1994
2002
  const [selectedLanguageKey, setSelectedLanguageKey] = useState("shell");
1995
2003
  const [selectedClientKey, setSelectedClientKey] = useState("curl");
1996
- const selectedExample = examples.find((example) => example.key === selectedExampleKey) ?? examples[0];
2004
+ const currentExampleKey = (sharedExampleKey && examples.some((example) => example.key === sharedExampleKey) ? sharedExampleKey : void 0) ?? selectedExampleKey;
2005
+ const selectedExample = examples.find((example) => example.key === currentExampleKey) ?? examples[0];
1997
2006
  const codeOptions = buildRequestCodeExamples({
1998
2007
  spec,
1999
2008
  path,
@@ -2013,38 +2022,71 @@ function RequestExamplesPanel(arg0) {
2013
2022
  });
2014
2023
  const selectedLanguage = codeOptions.find((option) => option.languageKey === selectedLanguageKey) ?? codeOptions[0];
2015
2024
  const selectedCode = codeOptions.find((option) => option.languageKey === selectedLanguage.languageKey && option.clientKey === selectedClientKey) ?? selectedLanguage;
2016
- const languageOptions = getLanguageOptions(codeOptions);
2017
- const clientOptions = getClientOptions(codeOptions, selectedCode.languageKey);
2018
- return /* @__PURE__ */ jsx(ApiExampleCodeGroup, {
2019
- title: t("openapi.request"),
2020
- tag: method,
2021
- label: path,
2022
- code: selectedCode.code,
2023
- language: selectedCode.language,
2024
- mediaTypes: requestContents.map((content) => content.mediaType),
2025
- selectedMediaType: selectedContent?.mediaType,
2025
+ return {
2026
+ selectedContent,
2027
+ selectedExample,
2028
+ selectedCode,
2029
+ languageOptions: getLanguageOptions(codeOptions),
2030
+ clientOptions: getClientOptions(codeOptions, selectedCode.languageKey),
2031
+ examples,
2026
2032
  onSelectMediaType: (value) => {
2027
2033
  onSelectMediaType(value);
2028
- setSelectedExampleKey(getExampleEntries(requestContents.find((content) => content.mediaType === value)?.value)[0]?.key ?? "");
2034
+ setSelectedExampleKey(firstExampleKeyForMediaType(requestContents, value));
2035
+ },
2036
+ onSelectExample: (value) => {
2037
+ setSelectedExampleKey(value);
2038
+ onSelectExampleKey?.(value);
2029
2039
  },
2030
- examples,
2031
- selectedExampleKey: selectedExample?.key,
2032
- onSelectExample: setSelectedExampleKey,
2033
- languageOptions,
2034
- selectedLanguageKey: selectedCode.languageKey,
2035
2040
  onSelectLanguage: (value) => {
2036
2041
  const nextCode = codeOptions.find((option) => option.languageKey === value);
2037
2042
  setSelectedLanguageKey(nextCode?.languageKey ?? value);
2038
2043
  setSelectedClientKey(nextCode?.clientKey ?? "");
2039
2044
  },
2040
- clientOptions,
2041
- selectedClientKey: selectedCode.clientKey,
2042
2045
  onSelectClient: setSelectedClientKey
2043
- });
2046
+ };
2044
2047
  }
2045
- function ResponseExamplesPanel(arg0) {
2046
- const { operation, spec } = arg0;
2048
+ function RequestExamplesPanel(arg0) {
2049
+ const { spec, path, method, parameters, requestContents, selectedMediaType, onSelectMediaType, selectedServer, serverVariables, auth, sharedExampleKey, onSelectExampleKey } = arg0;
2047
2050
  const t = useBuiltInText();
2051
+ const state = useRequestExamplesState({
2052
+ spec,
2053
+ path,
2054
+ method,
2055
+ parameters,
2056
+ requestContents,
2057
+ selectedMediaType,
2058
+ onSelectMediaType,
2059
+ selectedServer,
2060
+ serverVariables,
2061
+ auth,
2062
+ sharedExampleKey,
2063
+ onSelectExampleKey
2064
+ });
2065
+ return /* @__PURE__ */ jsx(ApiExampleCodeGroup, {
2066
+ title: t("openapi.request"),
2067
+ tag: method,
2068
+ label: path,
2069
+ code: state.selectedCode.code,
2070
+ language: state.selectedCode.language,
2071
+ mediaTypes: requestContents.map((content) => content.mediaType),
2072
+ selectedMediaType: state.selectedContent?.mediaType,
2073
+ onSelectMediaType: state.onSelectMediaType,
2074
+ examples: state.examples,
2075
+ selectedExampleKey: state.selectedExample?.key,
2076
+ onSelectExample: state.onSelectExample,
2077
+ languageOptions: state.languageOptions,
2078
+ selectedLanguageKey: state.selectedCode.languageKey,
2079
+ onSelectLanguage: state.onSelectLanguage,
2080
+ clientOptions: state.clientOptions,
2081
+ selectedClientKey: state.selectedCode.clientKey,
2082
+ onSelectClient: state.onSelectClient
2083
+ });
2084
+ }
2085
+ function firstExampleKeyForResponseContent(content) {
2086
+ return getExampleEntries(content?.value)[0]?.key ?? "";
2087
+ }
2088
+ function useResponseExamplesState(arg0) {
2089
+ const { operation, spec, sharedExampleKey, onSelectExampleKey } = arg0;
2048
2090
  const responses = getResponseEntries(operation, spec).filter(({ response }) => getMediaTypeEntries(response.content, spec).length > 0);
2049
2091
  const [selectedStatus, setSelectedStatus] = useState(responses.find(({ status }) => status.startsWith("2"))?.status ?? responses[0]?.status ?? "");
2050
2092
  const selectedResponse = responses.find(({ status }) => status === selectedStatus) ?? responses[0];
@@ -2053,31 +2095,56 @@ function ResponseExamplesPanel(arg0) {
2053
2095
  const selectedContent = responseContents.find((content) => content.mediaType === selectedMediaType) ?? responseContents[0];
2054
2096
  const examples = getExampleEntries(selectedContent?.value);
2055
2097
  const [selectedExampleKey, setSelectedExampleKey] = useState(examples[0]?.key ?? "");
2056
- const selectedExample = examples.find((example) => example.key === selectedExampleKey) ?? examples[0];
2057
- const responseCode = stringifyExample(selectedExample?.value);
2058
- if (!selectedResponse || !selectedContent || !responseCode) return null;
2059
- return /* @__PURE__ */ jsx(ApiExampleCodeGroup, {
2060
- title: t("openapi.response"),
2061
- tag: selectedResponse.status,
2062
- tagOptions: responses.map(({ status }) => status),
2063
- onSelectTag: (value) => {
2098
+ const currentExampleKey = (sharedExampleKey && examples.some((example) => example.key === sharedExampleKey) ? sharedExampleKey : void 0) ?? selectedExampleKey;
2099
+ const selectedExample = examples.find((example) => example.key === currentExampleKey) ?? examples[0];
2100
+ return {
2101
+ responses,
2102
+ selectedResponse,
2103
+ responseContents,
2104
+ selectedContent,
2105
+ examples,
2106
+ selectedExample,
2107
+ responseCode: stringifyExample(selectedExample?.value),
2108
+ onSelectStatus: (value) => {
2064
2109
  const nextContents = getMediaTypeEntries(responses.find(({ status }) => status === value)?.response.content, spec);
2065
2110
  setSelectedStatus(value);
2066
2111
  setSelectedMediaType(nextContents[0]?.mediaType ?? "");
2067
- setSelectedExampleKey(getExampleEntries(nextContents[0]?.value)[0]?.key ?? "");
2112
+ setSelectedExampleKey(firstExampleKeyForResponseContent(nextContents[0]));
2068
2113
  },
2069
- label: selectedContent.mediaType,
2070
- labelOptions: responseContents.map((content) => content.mediaType),
2071
- onSelectLabel: (value) => {
2114
+ onSelectMediaType: (value) => {
2072
2115
  setSelectedMediaType(value);
2073
- setSelectedExampleKey(getExampleEntries(responseContents.find((content) => content.mediaType === value)?.value)[0]?.key ?? "");
2116
+ setSelectedExampleKey(firstExampleKeyForResponseContent(responseContents.find((content) => content.mediaType === value)));
2074
2117
  },
2118
+ onSelectExample: (value) => {
2119
+ setSelectedExampleKey(value);
2120
+ onSelectExampleKey?.(value);
2121
+ }
2122
+ };
2123
+ }
2124
+ function ResponseExamplesPanel(arg0) {
2125
+ const { operation, spec, sharedExampleKey, onSelectExampleKey } = arg0;
2126
+ const t = useBuiltInText();
2127
+ const state = useResponseExamplesState({
2128
+ operation,
2129
+ spec,
2130
+ sharedExampleKey,
2131
+ onSelectExampleKey
2132
+ });
2133
+ if (!state.selectedResponse || !state.selectedContent || !state.responseCode) return null;
2134
+ return /* @__PURE__ */ jsx(ApiExampleCodeGroup, {
2135
+ title: t("openapi.response"),
2136
+ tag: state.selectedResponse.status,
2137
+ tagOptions: state.responses.map(({ status }) => status),
2138
+ onSelectTag: state.onSelectStatus,
2139
+ label: state.selectedContent.mediaType,
2140
+ labelOptions: state.responseContents.map((content) => content.mediaType),
2141
+ onSelectLabel: state.onSelectMediaType,
2075
2142
  comfortableMeta: true,
2076
- code: responseCode,
2077
- language: codeLanguageForMediaType(selectedContent.mediaType),
2078
- examples,
2079
- selectedExampleKey: selectedExample?.key,
2080
- onSelectExample: setSelectedExampleKey
2143
+ code: state.responseCode,
2144
+ language: codeLanguageForMediaType(state.selectedContent.mediaType),
2145
+ examples: state.examples,
2146
+ selectedExampleKey: state.selectedExample?.key,
2147
+ onSelectExample: state.onSelectExample
2081
2148
  });
2082
2149
  }
2083
2150
  //#endregion
@@ -2340,7 +2407,7 @@ function ResponseList(arg0) {
2340
2407
  //#endregion
2341
2408
  //#region source/openapi/components/EndpointSections.tsx
2342
2409
  function EndpointRequest(arg0) {
2343
- const { spec, path, method, description, groupedParameters, parameters, requestBody, requestContents, requestSchema, selectedRequestMediaType, onSelectRequestMediaType, selectedServer, serverVariables, auth } = arg0;
2410
+ const { spec, path, method, description, groupedParameters, parameters, requestBody, requestContents, requestSchema, selectedRequestMediaType, onSelectRequestMediaType, selectedServer, serverVariables, auth, sharedExampleKey, onSelectExampleKey } = arg0;
2344
2411
  const t = useBuiltInText();
2345
2412
  return /* @__PURE__ */ jsxs(Row, {
2346
2413
  className: "relative mt-6",
@@ -2379,13 +2446,15 @@ function EndpointRequest(arg0) {
2379
2446
  onSelectMediaType: onSelectRequestMediaType,
2380
2447
  selectedServer,
2381
2448
  serverVariables,
2382
- auth
2449
+ auth,
2450
+ sharedExampleKey,
2451
+ onSelectExampleKey
2383
2452
  })
2384
2453
  })]
2385
2454
  });
2386
2455
  }
2387
2456
  function EndpointResponse(arg0) {
2388
- const { spec, operation } = arg0;
2457
+ const { spec, operation, sharedExampleKey, onSelectExampleKey } = arg0;
2389
2458
  return /* @__PURE__ */ jsxs(Row, {
2390
2459
  className: "relative mt-6",
2391
2460
  children: [/* @__PURE__ */ jsx(Col, { children: /* @__PURE__ */ jsx(ResponseList, {
@@ -2395,27 +2464,127 @@ function EndpointResponse(arg0) {
2395
2464
  sticky: true,
2396
2465
  children: /* @__PURE__ */ jsx(ResponseExamplesPanel, {
2397
2466
  operation,
2398
- spec
2467
+ spec,
2468
+ sharedExampleKey,
2469
+ onSelectExampleKey
2399
2470
  })
2400
2471
  })]
2401
2472
  });
2402
2473
  }
2403
2474
  //#endregion
2475
+ //#region source/openapi/components/OpenApiOperation.state.ts
2476
+ function useOperationRequestState(spec, path, operation) {
2477
+ const parameters = getOperationParameters(spec, path, operation);
2478
+ const requestBody = getRequestBody$1(spec, operation);
2479
+ const requestContents = getMediaTypeEntries(requestBody?.content, spec);
2480
+ const [selectedRequestMediaType, setSelectedRequestMediaType] = useState(requestContents[0]?.mediaType ?? "");
2481
+ const selectedRequestContent = requestContents.find((content) => content.mediaType === selectedRequestMediaType) ?? requestContents[0];
2482
+ const requestSchema = selectedRequestContent?.value.schema;
2483
+ const groupedParameters = {
2484
+ path: parameters.filter((parameter) => parameter.in === "path"),
2485
+ query: parameters.filter((parameter) => parameter.in === "query"),
2486
+ header: parameters.filter((parameter) => parameter.in === "header")
2487
+ };
2488
+ return {
2489
+ parameters,
2490
+ requestBody,
2491
+ requestContents,
2492
+ selectedRequestMediaType: selectedRequestContent?.mediaType ?? "",
2493
+ setSelectedRequestMediaType,
2494
+ requestSchema,
2495
+ groupedParameters
2496
+ };
2497
+ }
2498
+ function useOperationServerState(spec, operation, path) {
2499
+ const servers = getServers(spec, operation, path);
2500
+ const [selectedServerKey, setSelectedServerKey] = useState(getServerKey(servers[0], 0));
2501
+ const selectedServer = servers.find((server, index) => getServerKey(server, index) === selectedServerKey) ?? servers[0];
2502
+ const [serverVariables, setServerVariables] = useState(defaultServerVariables(selectedServer));
2503
+ const [serverOpen, setServerOpen] = useState(false);
2504
+ return {
2505
+ servers,
2506
+ selectedServerKey,
2507
+ selectedServer,
2508
+ serverVariables,
2509
+ serverOpen,
2510
+ onSelectServer: (value) => {
2511
+ const nextServer = servers.find((server, index) => getServerKey(server, index) === value) ?? servers[0];
2512
+ setSelectedServerKey(value);
2513
+ setServerVariables(defaultServerVariables(nextServer));
2514
+ },
2515
+ onChangeServerVariable: (name, value) => setServerVariables((current) => ({
2516
+ ...current,
2517
+ [name]: value
2518
+ })),
2519
+ onToggleServer: () => setServerOpen((current) => !current),
2520
+ closeServer: () => setServerOpen(false)
2521
+ };
2522
+ }
2523
+ function useOperationAuthState(spec, operation) {
2524
+ const authOptions = getAuthOptions(spec, operation);
2525
+ const [selectedAuthName, setSelectedAuthName] = useState(authOptions[0]?.name ?? "");
2526
+ const selectedAuth = authOptions.find((option) => option.name === selectedAuthName);
2527
+ const [authValues, setAuthValues] = useState({});
2528
+ const [authOpen, setAuthOpen] = useState(false);
2529
+ return {
2530
+ authOptions,
2531
+ selectedAuthName,
2532
+ selectedAuth,
2533
+ authValues,
2534
+ authOpen,
2535
+ authInput: selectedAuth ? {
2536
+ name: selectedAuth.name,
2537
+ scheme: selectedAuth.scheme,
2538
+ value: authValues[selectedAuth.name] ?? authPlaceholder(selectedAuth)
2539
+ } : void 0,
2540
+ onSelectAuth: setSelectedAuthName,
2541
+ onChangeAuthValue: (name, value) => setAuthValues((current) => ({
2542
+ ...current,
2543
+ [name]: value
2544
+ })),
2545
+ onToggleAuth: () => setAuthOpen((current) => !current),
2546
+ closeAuth: () => setAuthOpen(false)
2547
+ };
2548
+ }
2549
+ //#endregion
2404
2550
  //#region source/openapi/components/OpenApiOperation.tsx
2405
- var endpointMethodStyles = {
2406
- GET: "bg-emerald-400/15 text-emerald-600 dark:bg-emerald-400/20 dark:text-emerald-300",
2407
- POST: "bg-sky-400/15 text-sky-600 dark:bg-sky-400/20 dark:text-sky-300",
2408
- PUT: "bg-amber-400/15 text-amber-600 dark:bg-amber-400/20 dark:text-amber-300",
2409
- PATCH: "bg-amber-400/15 text-amber-600 dark:bg-amber-400/20 dark:text-amber-300",
2410
- DELETE: "bg-rose-400/15 text-rose-600 dark:bg-rose-400/20 dark:text-rose-300"
2551
+ var endpointMethodStyleVars = {
2552
+ GET: "bg-(--clarify-http-method-get-background) text-(--clarify-http-method-get-text)",
2553
+ POST: "bg-(--clarify-http-method-post-background) text-(--clarify-http-method-post-text)",
2554
+ PUT: "bg-(--clarify-http-method-put-background) text-(--clarify-http-method-put-text)",
2555
+ PATCH: "bg-(--clarify-http-method-patch-background) text-(--clarify-http-method-patch-text)",
2556
+ DELETE: "bg-(--clarify-http-method-delete-background) text-(--clarify-http-method-delete-text)"
2411
2557
  };
2412
2558
  function EndpointMethodBadge(arg0) {
2413
2559
  const { method } = arg0;
2414
2560
  return /* @__PURE__ */ jsx("span", {
2415
- className: clsx("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"),
2561
+ className: clsx("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)"),
2416
2562
  children: method
2417
2563
  });
2418
2564
  }
2565
+ function EndpointPath(arg0) {
2566
+ const { path } = arg0;
2567
+ const segments = path.split("/").filter(Boolean);
2568
+ return /* @__PURE__ */ jsx("div", {
2569
+ className: "flex min-w-0 flex-1 items-center overflow-x-auto text-sm font-bold leading-6 whitespace-nowrap",
2570
+ children: segments.length > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
2571
+ className: "text-(--clarify-ui-text-faint)",
2572
+ children: "/"
2573
+ }), segments.map((segment, index) => /* @__PURE__ */ jsxs("span", {
2574
+ className: "flex items-center",
2575
+ children: [index > 0 ? /* @__PURE__ */ jsx("span", {
2576
+ className: "text-(--clarify-ui-text-faint)",
2577
+ children: "/"
2578
+ }) : null, /* @__PURE__ */ jsx("span", {
2579
+ className: "font-bold text-(--clarify-theme-tokens-colors-foreground)",
2580
+ children: segment
2581
+ })]
2582
+ }, `${segment}-${index}`))] }) : /* @__PURE__ */ jsx("span", {
2583
+ className: "font-bold text-(--clarify-theme-tokens-colors-foreground)",
2584
+ children: "/"
2585
+ })
2586
+ });
2587
+ }
2419
2588
  function InlineListbox(arg0) {
2420
2589
  const { label, value, options, onChange, compact = false } = arg0;
2421
2590
  const selected = options.find((option) => option.value === value) ?? options[0];
@@ -2531,7 +2700,7 @@ function ServerPanel(arg0) {
2531
2700
  return /* @__PURE__ */ jsx("div", {
2532
2701
  className: "border-t border-(--clarify-theme-tokens-colors-border) bg-(--clarify-ui-subtle-background) p-3",
2533
2702
  children: /* @__PURE__ */ jsxs("div", {
2534
- className: "grid gap-3 sm:grid-cols-(--clarify-openapi-control-grid)",
2703
+ className: "flex flex-col gap-3",
2535
2704
  children: [servers.length > 1 ? /* @__PURE__ */ jsxs("label", {
2536
2705
  className: "flex min-w-0 flex-col gap-1.5",
2537
2706
  children: [/* @__PURE__ */ jsx("span", {
@@ -2547,18 +2716,21 @@ function ServerPanel(arg0) {
2547
2716
  })),
2548
2717
  onChange: onSelectServer
2549
2718
  })]
2550
- }) : null, variableEntries.map(([name, variable]) => /* @__PURE__ */ jsxs("label", {
2551
- className: "flex min-w-0 flex-col gap-1.5",
2552
- children: [/* @__PURE__ */ jsx("span", {
2553
- className: "text-2xs font-semibold text-(--clarify-ui-text-soft)",
2554
- children: name
2555
- }), /* @__PURE__ */ jsx(ServerVariableControl, {
2556
- name,
2557
- variable,
2558
- value: variables[name] ?? variable.default ?? "",
2559
- onChange: (value) => onChangeVariable(name, value)
2560
- })]
2561
- }, name))]
2719
+ }) : null, variableEntries.length > 0 ? /* @__PURE__ */ jsx("div", {
2720
+ className: "grid gap-3 sm:grid-cols-(--clarify-openapi-variable-grid)",
2721
+ children: variableEntries.map(([name, variable]) => /* @__PURE__ */ jsxs("label", {
2722
+ className: "flex min-w-0 flex-col gap-1.5",
2723
+ children: [/* @__PURE__ */ jsx("span", {
2724
+ className: "text-2xs font-semibold text-(--clarify-ui-text-soft)",
2725
+ children: name
2726
+ }), /* @__PURE__ */ jsx(ServerVariableControl, {
2727
+ name,
2728
+ variable,
2729
+ value: variables[name] ?? variable.default ?? "",
2730
+ onChange: (value) => onChangeVariable(name, value)
2731
+ })]
2732
+ }, name))
2733
+ }) : null]
2562
2734
  })
2563
2735
  });
2564
2736
  }
@@ -2606,7 +2778,6 @@ function AuthPanel(arg0) {
2606
2778
  }
2607
2779
  function EndpointIdentity(arg0) {
2608
2780
  const { method, path, servers, selectedServerKey, selectedServer, serverVariables, serverOpen, authOptions, selectedAuthName, selectedAuth, authValues, authOpen, onSelectServer, onChangeServerVariable, onToggleServer, onToggleAuth, onSelectAuth, onChangeAuthValue } = arg0;
2609
- const segments = path.split("/").filter(Boolean);
2610
2781
  const serverInteractive = servers.length > 1 || Object.keys(selectedServer.variables ?? {}).length > 0;
2611
2782
  return /* @__PURE__ */ jsxs("div", {
2612
2783
  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",
@@ -2622,25 +2793,7 @@ function EndpointIdentity(arg0) {
2622
2793
  interactive: serverInteractive,
2623
2794
  onToggle: onToggleServer
2624
2795
  }),
2625
- /* @__PURE__ */ jsx("div", {
2626
- className: "flex min-w-0 flex-1 items-center overflow-x-auto text-sm font-bold leading-6 whitespace-nowrap",
2627
- children: segments.length > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
2628
- className: "text-(--clarify-ui-text-faint)",
2629
- children: "/"
2630
- }), segments.map((segment, index) => /* @__PURE__ */ jsxs("span", {
2631
- className: "flex items-center",
2632
- children: [index > 0 ? /* @__PURE__ */ jsx("span", {
2633
- className: "text-(--clarify-ui-text-faint)",
2634
- children: "/"
2635
- }) : null, /* @__PURE__ */ jsx("span", {
2636
- className: "font-bold text-(--clarify-theme-tokens-colors-foreground)",
2637
- children: segment
2638
- })]
2639
- }, `${segment}-${index}`))] }) : /* @__PURE__ */ jsx("span", {
2640
- className: "font-bold text-(--clarify-theme-tokens-colors-foreground)",
2641
- children: "/"
2642
- })
2643
- }),
2796
+ /* @__PURE__ */ jsx(EndpointPath, { path }),
2644
2797
  authOptions.length > 0 ? /* @__PURE__ */ jsx("button", {
2645
2798
  type: "button",
2646
2799
  "aria-expanded": authOpen,
@@ -2681,32 +2834,10 @@ function OpenApiOperation(arg0) {
2681
2834
  const id = slug(`${method.toLowerCase()} ${path}`);
2682
2835
  const summary = operation.summary ?? `${method} ${path}`;
2683
2836
  const description = operation.description;
2684
- const parameters = getOperationParameters(spec, path, operation);
2685
- const requestBody = getRequestBody$1(spec, operation);
2686
- const requestContents = getMediaTypeEntries(requestBody?.content, spec);
2687
- const [selectedRequestMediaType, setSelectedRequestMediaType] = useState(requestContents[0]?.mediaType ?? "");
2688
- const selectedRequestContent = requestContents.find((content) => content.mediaType === selectedRequestMediaType) ?? requestContents[0];
2689
- const requestSchema = selectedRequestContent?.value.schema;
2690
- const servers = getServers(spec, operation, path);
2691
- const [selectedServerKey, setSelectedServerKey] = useState(getServerKey(servers[0], 0));
2692
- const selectedServer = servers.find((server, index) => getServerKey(server, index) === selectedServerKey) ?? servers[0];
2693
- const [serverVariables, setServerVariables] = useState(defaultServerVariables(selectedServer));
2694
- const [serverOpen, setServerOpen] = useState(false);
2695
- const authOptions = getAuthOptions(spec, operation);
2696
- const [selectedAuthName, setSelectedAuthName] = useState(authOptions[0]?.name ?? "");
2697
- const selectedAuth = authOptions.find((option) => option.name === selectedAuthName);
2698
- const [authValues, setAuthValues] = useState({});
2699
- const [authOpen, setAuthOpen] = useState(false);
2700
- const authInput = selectedAuth ? {
2701
- name: selectedAuth.name,
2702
- scheme: selectedAuth.scheme,
2703
- value: authValues[selectedAuth.name] ?? authPlaceholder(selectedAuth)
2704
- } : void 0;
2705
- const groupedParameters = {
2706
- path: parameters.filter((parameter) => parameter.in === "path"),
2707
- query: parameters.filter((parameter) => parameter.in === "query"),
2708
- header: parameters.filter((parameter) => parameter.in === "header")
2709
- };
2837
+ const requestState = useOperationRequestState(spec, path, operation);
2838
+ const serverState = useOperationServerState(spec, operation, path);
2839
+ const authState = useOperationAuthState(spec, operation);
2840
+ const [linkedExampleKey, setLinkedExampleKey] = useState("");
2710
2841
  return /* @__PURE__ */ jsxs("section", {
2711
2842
  className: "clarify-api-endpoint scroll-mt-24 pb-16 first:pt-0 last:pb-0",
2712
2843
  "aria-labelledby": id,
@@ -2718,58 +2849,52 @@ function OpenApiOperation(arg0) {
2718
2849
  /* @__PURE__ */ jsx(EndpointIdentity, {
2719
2850
  method,
2720
2851
  path,
2721
- servers,
2722
- selectedServerKey,
2723
- selectedServer,
2724
- serverVariables,
2725
- serverOpen,
2726
- authOptions,
2727
- selectedAuthName,
2728
- selectedAuth,
2729
- authValues,
2730
- authOpen,
2731
- onSelectServer: (value) => {
2732
- const nextServer = servers.find((server, index) => getServerKey(server, index) === value) ?? servers[0];
2733
- setSelectedServerKey(value);
2734
- setServerVariables(defaultServerVariables(nextServer));
2735
- },
2736
- onChangeServerVariable: (name, value) => setServerVariables((current) => ({
2737
- ...current,
2738
- [name]: value
2739
- })),
2852
+ servers: serverState.servers,
2853
+ selectedServerKey: serverState.selectedServerKey,
2854
+ selectedServer: serverState.selectedServer,
2855
+ serverVariables: serverState.serverVariables,
2856
+ serverOpen: serverState.serverOpen,
2857
+ authOptions: authState.authOptions,
2858
+ selectedAuthName: authState.selectedAuthName,
2859
+ selectedAuth: authState.selectedAuth,
2860
+ authValues: authState.authValues,
2861
+ authOpen: authState.authOpen,
2862
+ onSelectServer: serverState.onSelectServer,
2863
+ onChangeServerVariable: serverState.onChangeServerVariable,
2740
2864
  onToggleServer: () => {
2741
- setServerOpen((current) => !current);
2742
- setAuthOpen(false);
2865
+ serverState.onToggleServer();
2866
+ authState.closeAuth();
2743
2867
  },
2744
2868
  onToggleAuth: () => {
2745
- setAuthOpen((current) => !current);
2746
- setServerOpen(false);
2869
+ authState.onToggleAuth();
2870
+ serverState.closeServer();
2747
2871
  },
2748
- onSelectAuth: setSelectedAuthName,
2749
- onChangeAuthValue: (name, value) => setAuthValues((current) => ({
2750
- ...current,
2751
- [name]: value
2752
- }))
2872
+ onSelectAuth: authState.onSelectAuth,
2873
+ onChangeAuthValue: authState.onChangeAuthValue
2753
2874
  }),
2754
2875
  /* @__PURE__ */ jsx(EndpointRequest, {
2755
2876
  spec,
2756
2877
  path,
2757
2878
  method,
2758
2879
  description,
2759
- groupedParameters,
2760
- parameters,
2761
- requestBody,
2762
- requestContents,
2763
- requestSchema,
2764
- selectedRequestMediaType: selectedRequestContent?.mediaType ?? "",
2765
- onSelectRequestMediaType: setSelectedRequestMediaType,
2766
- selectedServer,
2767
- serverVariables,
2768
- auth: authInput
2880
+ groupedParameters: requestState.groupedParameters,
2881
+ parameters: requestState.parameters,
2882
+ requestBody: requestState.requestBody,
2883
+ requestContents: requestState.requestContents,
2884
+ requestSchema: requestState.requestSchema,
2885
+ selectedRequestMediaType: requestState.selectedRequestMediaType,
2886
+ onSelectRequestMediaType: requestState.setSelectedRequestMediaType,
2887
+ selectedServer: serverState.selectedServer,
2888
+ serverVariables: serverState.serverVariables,
2889
+ auth: authState.authInput,
2890
+ sharedExampleKey: linkedExampleKey,
2891
+ onSelectExampleKey: setLinkedExampleKey
2769
2892
  }),
2770
2893
  /* @__PURE__ */ jsx(EndpointResponse, {
2771
2894
  spec,
2772
- operation
2895
+ operation,
2896
+ sharedExampleKey: linkedExampleKey,
2897
+ onSelectExampleKey: setLinkedExampleKey
2773
2898
  })
2774
2899
  ]
2775
2900
  });
@@ -2777,4 +2902,4 @@ function OpenApiOperation(arg0) {
2777
2902
  //#endregion
2778
2903
  export { Button as A, Code as C, Card as D, Mermaid as E, CardGroup as O, Collapse as S, Pre as T, HeroPattern as _, authPlaceholder as a, Tag as b, getServerKey as c, getRequestBody$1 as d, Markdown as f, GridPattern as g, Prose as h, ResponseExamplesPanel as i, Callout as k, getServers as l, WebFrame as m, OpenApiOperation as n, defaultServerVariables as o, primitives_exports as p, RequestExamplesPanel as r, getAuthOptions as s, EndpointIdentity as t, getMediaTypeEntries as u, Logo as v, CodeGroup as w, Feedback as x, Heading as y };
2779
2904
 
2780
- //# sourceMappingURL=OpenApiOperation-E8lSLsSK.js.map
2905
+ //# sourceMappingURL=OpenApiOperation-DIFaYAe5.js.map