@stainless-api/docs 0.1.0-beta.94 → 0.1.0-beta.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @stainless-api/docs
2
2
 
3
+ ## 0.1.0-beta.95
4
+
5
+ ### Minor Changes
6
+
7
+ - 6b86a8b: Support multiple snippet examples
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [6b86a8b]
12
+ - @stainless-api/docs-ui@0.1.0-beta.72
13
+ - @stainless-api/docs-search@0.1.0-beta.25
14
+
3
15
  ## 0.1.0-beta.94
4
16
 
5
17
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stainless-api/docs",
3
- "version": "0.1.0-beta.94",
3
+ "version": "0.1.0-beta.95",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -56,8 +56,8 @@
56
56
  "vite-plugin-prebundle-workers": "^0.2.0",
57
57
  "web-worker": "^1.5.0",
58
58
  "yaml": "^2.8.2",
59
- "@stainless-api/docs-search": "0.1.0-beta.24",
60
- "@stainless-api/docs-ui": "0.1.0-beta.71",
59
+ "@stainless-api/docs-search": "0.1.0-beta.25",
60
+ "@stainless-api/docs-ui": "0.1.0-beta.72",
61
61
  "@stainless-api/ui-primitives": "0.1.0-beta.47"
62
62
  },
63
63
  "devDependencies": {
@@ -73,7 +73,7 @@
73
73
  "vite": "^6.4.1",
74
74
  "zod": "^4.3.5",
75
75
  "@stainless/eslint-config": "0.1.0-beta.1",
76
- "@stainless/sdk-json": "^0.1.0-beta.4"
76
+ "@stainless/sdk-json": "^0.1.0-beta.5"
77
77
  },
78
78
  "scripts": {
79
79
  "vendor-deps": "tsx scripts/vendor_deps.ts",
@@ -19,9 +19,10 @@ document.addEventListener(getPageLoadEvent(), () => {
19
19
  document
20
20
  .querySelectorAll(`[data-snippet-response-pane-id="${panelId}"]`)
21
21
  .forEach((p) => p.classList.add('stldocs-snippet-response-pane-active'));
22
- document
23
- .querySelectorAll(`[data-snippet-response-tab-id="${panelId}"]`)
24
- .forEach((p) => p.classList.add('stldocs-snippet-response-tab-item-active'));
22
+ document.querySelectorAll(`[data-snippet-response-tab-id="${panelId}"]`).forEach((p) => {
23
+ p.classList.add('stldocs-snippet-response-tab-item-active');
24
+ p.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' });
25
+ });
25
26
  });
26
27
  });
27
28
 
@@ -91,4 +92,25 @@ document.addEventListener(getPageLoadEvent(), () => {
91
92
  btn.textContent = 'Show more';
92
93
  }
93
94
  });
95
+
96
+ document.querySelectorAll('[data-stldocs-multi-snippet-container]').forEach((container) => {
97
+ const radios = container.querySelectorAll<HTMLInputElement>('input[type="radio"]');
98
+ const panes = container.querySelectorAll<HTMLDivElement>('[data-stldocs-multi-snippet-id]');
99
+
100
+ radios.forEach((radio) => {
101
+ radio.addEventListener('change', (e) => {
102
+ if (!(e.target instanceof HTMLInputElement)) return;
103
+ if (e.target.checked) {
104
+ const selectedIndex = e.target.value;
105
+ panes.forEach((pane) => {
106
+ pane.classList.toggle(
107
+ 'stldocs-snippet-multi-pane-active',
108
+ pane.dataset.stldocsMultiSnippetId === selectedIndex,
109
+ );
110
+ });
111
+ e.target.parentElement?.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' });
112
+ }
113
+ });
114
+ });
115
+ });
94
116
  });
@@ -92,7 +92,8 @@ function loadPlayground(playButton: HTMLElement) {
92
92
  doc: (language === 'python' ? 'from rich import print\n' : '') + code.trimEnd(),
93
93
  container,
94
94
  onLanguageSelect: (value) => {
95
- const originalLanguage = document.getElementById('stldocs-snippet-select')?.dataset.currentValue;
95
+ const originalLanguage = container.querySelector<HTMLElement>('[data-stldocs-snippet-select]')
96
+ ?.dataset.currentValue;
96
97
  const path: string = updateSelectedLanguage(RESOLVED_API_REFERENCE_PATH, originalLanguage, value);
97
98
  navigate(path.replace(/(\?.+)?($|#)/, (_, str, end) => (str ? str + '&play' : '?play') + end));
98
99
  },
@@ -22,15 +22,14 @@ window.addEventListener('popstate', (ev: PopStateEvent) => {
22
22
  });
23
23
 
24
24
  document.addEventListener(getPageLoadEvent(), () => {
25
- const rootElement = document.getElementById('stldocs-snippet-select');
26
- if (!rootElement) return;
27
-
28
- initDropdown({
29
- root: rootElement,
30
- onSelect: (value) => {
31
- const originalLanguage = rootElement?.dataset.currentValue;
32
- navigate(updateSelectedLanguage(RESOLVED_API_REFERENCE_PATH, originalLanguage, value));
33
- },
25
+ document.querySelectorAll<HTMLElement>('[data-stldocs-snippet-select]').forEach((rootElement) => {
26
+ initDropdown({
27
+ root: rootElement,
28
+ onSelect: (value) => {
29
+ const originalLanguage = rootElement.dataset.currentValue;
30
+ navigate(updateSelectedLanguage(RESOLVED_API_REFERENCE_PATH, originalLanguage, value));
31
+ },
32
+ });
34
33
  });
35
34
 
36
35
  const path = getStainlessPathForLocation();
@@ -192,16 +192,15 @@ async function highlight(content: string, language?: string) {
192
192
  export function SDKSelectReactComponent({
193
193
  selected,
194
194
  languages,
195
- id,
196
195
  className,
196
+ ...rest
197
197
  }: {
198
198
  selected: DocsLanguage;
199
199
  languages: DocsLanguage[];
200
- id: string;
201
200
  className?: string;
202
- }) {
201
+ } & Omit<React.ComponentProps<'div'>, 'children'>) {
203
202
  return (
204
- <Dropdown id={id} data-current-value={selected} className={className}>
203
+ <Dropdown data-current-value={selected} className={className} {...rest}>
205
204
  <Dropdown.Trigger>
206
205
  <Dropdown.TriggerSelectedItem>
207
206
  <Dropdown.Icon>
@@ -244,7 +243,7 @@ function SDKRequestTitle({ snippetLanguage }: SDKRequestTitleProps) {
244
243
  <SDKSelectReactComponent
245
244
  selected={selected || 'http'}
246
245
  languages={languages}
247
- id="stldocs-snippet-select"
246
+ data-stldocs-snippet-select
248
247
  className="stl-sdk-select stl-ui-not-prose"
249
248
  />
250
249
  );