@scalar/api-client-react 0.5.15 → 1.0.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.
- package/CHANGELOG.md +285 -0
- package/README.md +25 -69
- package/dist/ApiClientModalProvider.js +33 -0
- package/dist/index.d.ts +27 -17
- package/dist/index.js +3 -11770
- package/dist/style.css +1 -1
- package/package.json +21 -6
- package/dist/index.cjs +0 -90
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,290 @@
|
|
|
1
1
|
# @scalar/api-client-react
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5d19345: feat(api-client-react): adds use client directive at the top of file for next.js
|
|
8
|
+
- Updated dependencies [d5408e8]
|
|
9
|
+
- @scalar/api-client@2.0.29
|
|
10
|
+
|
|
11
|
+
## 1.0.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 2945efe: chore: make api client react public
|
|
16
|
+
|
|
17
|
+
## 1.0.0
|
|
18
|
+
|
|
19
|
+
### Major Changes
|
|
20
|
+
|
|
21
|
+
- e41c15e: fix: SSR issue with api-client-react
|
|
22
|
+
|
|
23
|
+
## 0.5.45
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 33f5a09: fix: revived the api-client-react package
|
|
28
|
+
- Updated dependencies [23d498b]
|
|
29
|
+
- Updated dependencies [624696e]
|
|
30
|
+
- Updated dependencies [41341e9]
|
|
31
|
+
- Updated dependencies [5402338]
|
|
32
|
+
- Updated dependencies [33f5a09]
|
|
33
|
+
- Updated dependencies [9f4db12]
|
|
34
|
+
- Updated dependencies [aee3783]
|
|
35
|
+
- Updated dependencies [9ca5d7d]
|
|
36
|
+
- Updated dependencies [d97bffd]
|
|
37
|
+
- @scalar/api-client@2.0.28
|
|
38
|
+
|
|
39
|
+
## 0.5.44
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- Updated dependencies [19d8b6a]
|
|
44
|
+
- Updated dependencies [c112f24]
|
|
45
|
+
- Updated dependencies [83fc241]
|
|
46
|
+
- Updated dependencies [2e1ef12]
|
|
47
|
+
- @scalar/api-client@2.0.27
|
|
48
|
+
|
|
49
|
+
## 0.5.43
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- Updated dependencies [54f7654]
|
|
54
|
+
- Updated dependencies [b0b3290]
|
|
55
|
+
- Updated dependencies [7e01b12]
|
|
56
|
+
- Updated dependencies [b7211fb]
|
|
57
|
+
- @scalar/api-client@2.0.26
|
|
58
|
+
|
|
59
|
+
## 0.5.42
|
|
60
|
+
|
|
61
|
+
### Patch Changes
|
|
62
|
+
|
|
63
|
+
- Updated dependencies [591fe24]
|
|
64
|
+
- Updated dependencies [7f17fe4]
|
|
65
|
+
- Updated dependencies [1dab515]
|
|
66
|
+
- Updated dependencies [4d76ff5]
|
|
67
|
+
- Updated dependencies [e8cd161]
|
|
68
|
+
- Updated dependencies [a431eb0]
|
|
69
|
+
- Updated dependencies [ff59399]
|
|
70
|
+
- Updated dependencies [ec47287]
|
|
71
|
+
- Updated dependencies [747e80e]
|
|
72
|
+
- Updated dependencies [9d561b7]
|
|
73
|
+
- @scalar/api-client@2.0.25
|
|
74
|
+
|
|
75
|
+
## 0.5.41
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- Updated dependencies [7076725]
|
|
80
|
+
- Updated dependencies [1e72b03]
|
|
81
|
+
- Updated dependencies [cbe984b]
|
|
82
|
+
- @scalar/api-client@2.0.24
|
|
83
|
+
|
|
84
|
+
## 0.5.40
|
|
85
|
+
|
|
86
|
+
### Patch Changes
|
|
87
|
+
|
|
88
|
+
- Updated dependencies [3928ac3]
|
|
89
|
+
- @scalar/api-client@2.0.23
|
|
90
|
+
|
|
91
|
+
## 0.5.39
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- Updated dependencies [45b956f]
|
|
96
|
+
- @scalar/api-client@2.0.22
|
|
97
|
+
|
|
98
|
+
## 0.5.38
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- Updated dependencies [d48e4ac]
|
|
103
|
+
- @scalar/api-client@2.0.21
|
|
104
|
+
|
|
105
|
+
## 0.5.37
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- @scalar/api-client@2.0.20
|
|
110
|
+
|
|
111
|
+
## 0.5.36
|
|
112
|
+
|
|
113
|
+
### Patch Changes
|
|
114
|
+
|
|
115
|
+
- Updated dependencies [a0bb23a]
|
|
116
|
+
- @scalar/api-client@2.0.19
|
|
117
|
+
|
|
118
|
+
## 0.5.35
|
|
119
|
+
|
|
120
|
+
### Patch Changes
|
|
121
|
+
|
|
122
|
+
- Updated dependencies [8654323]
|
|
123
|
+
- @scalar/api-client@2.0.18
|
|
124
|
+
|
|
125
|
+
## 0.5.34
|
|
126
|
+
|
|
127
|
+
### Patch Changes
|
|
128
|
+
|
|
129
|
+
- Updated dependencies [91b97fa]
|
|
130
|
+
- Updated dependencies [05bc858]
|
|
131
|
+
- Updated dependencies [05bc858]
|
|
132
|
+
- @scalar/api-client@2.0.17
|
|
133
|
+
|
|
134
|
+
## 0.5.33
|
|
135
|
+
|
|
136
|
+
### Patch Changes
|
|
137
|
+
|
|
138
|
+
- fc096b6: refactor!: rename `createScalarApiClient` to `createApiClientModal`
|
|
139
|
+
- Updated dependencies [a5b295c]
|
|
140
|
+
- Updated dependencies [bff602a]
|
|
141
|
+
- Updated dependencies [6f4d20d]
|
|
142
|
+
- Updated dependencies [1ba4267]
|
|
143
|
+
- Updated dependencies [58da2c6]
|
|
144
|
+
- Updated dependencies [9e3348a]
|
|
145
|
+
- Updated dependencies [fe16789]
|
|
146
|
+
- Updated dependencies [fc096b6]
|
|
147
|
+
- Updated dependencies [ebdc9cf]
|
|
148
|
+
- @scalar/api-client@2.0.16
|
|
149
|
+
|
|
150
|
+
## 0.5.32
|
|
151
|
+
|
|
152
|
+
### Patch Changes
|
|
153
|
+
|
|
154
|
+
- Updated dependencies [f86a242]
|
|
155
|
+
- @scalar/api-client@2.0.15
|
|
156
|
+
|
|
157
|
+
## 0.5.31
|
|
158
|
+
|
|
159
|
+
### Patch Changes
|
|
160
|
+
|
|
161
|
+
- Updated dependencies [6b32eee]
|
|
162
|
+
- Updated dependencies [1a675be]
|
|
163
|
+
- Updated dependencies [a1d59de]
|
|
164
|
+
- @scalar/api-client@2.0.14
|
|
165
|
+
|
|
166
|
+
## 0.5.30
|
|
167
|
+
|
|
168
|
+
### Patch Changes
|
|
169
|
+
|
|
170
|
+
- Updated dependencies [618285e]
|
|
171
|
+
- @scalar/api-client@2.0.13
|
|
172
|
+
|
|
173
|
+
## 0.5.29
|
|
174
|
+
|
|
175
|
+
### Patch Changes
|
|
176
|
+
|
|
177
|
+
- Updated dependencies [0a33194]
|
|
178
|
+
- @scalar/api-client@2.0.12
|
|
179
|
+
|
|
180
|
+
## 0.5.28
|
|
181
|
+
|
|
182
|
+
### Patch Changes
|
|
183
|
+
|
|
184
|
+
- Updated dependencies [e8a7f82]
|
|
185
|
+
- Updated dependencies [c16413d]
|
|
186
|
+
- Updated dependencies [b9a7a4e]
|
|
187
|
+
- @scalar/api-client@2.0.11
|
|
188
|
+
|
|
189
|
+
## 0.5.27
|
|
190
|
+
|
|
191
|
+
### Patch Changes
|
|
192
|
+
|
|
193
|
+
- Updated dependencies [b65d1fa]
|
|
194
|
+
- Updated dependencies [b655c7a]
|
|
195
|
+
- @scalar/api-client@2.0.10
|
|
196
|
+
|
|
197
|
+
## 0.5.26
|
|
198
|
+
|
|
199
|
+
### Patch Changes
|
|
200
|
+
|
|
201
|
+
- Updated dependencies [1bb94c7]
|
|
202
|
+
- Updated dependencies [f1b5390]
|
|
203
|
+
- Updated dependencies [ad7fd7e]
|
|
204
|
+
- @scalar/api-client@2.0.9
|
|
205
|
+
|
|
206
|
+
## 0.5.25
|
|
207
|
+
|
|
208
|
+
### Patch Changes
|
|
209
|
+
|
|
210
|
+
- Updated dependencies [ba3f5cb]
|
|
211
|
+
- Updated dependencies [0b6e3aa]
|
|
212
|
+
- Updated dependencies [d58841b]
|
|
213
|
+
- @scalar/api-client@2.0.8
|
|
214
|
+
|
|
215
|
+
## 0.5.24
|
|
216
|
+
|
|
217
|
+
### Patch Changes
|
|
218
|
+
|
|
219
|
+
- Updated dependencies [f2e3b0e]
|
|
220
|
+
- @scalar/api-client@2.0.7
|
|
221
|
+
|
|
222
|
+
## 0.5.23
|
|
223
|
+
|
|
224
|
+
### Patch Changes
|
|
225
|
+
|
|
226
|
+
- Updated dependencies [4385ae2]
|
|
227
|
+
- Updated dependencies [632d6f7]
|
|
228
|
+
- Updated dependencies [a5aedf5]
|
|
229
|
+
- Updated dependencies [a5aedf5]
|
|
230
|
+
- Updated dependencies [d6a2a4d]
|
|
231
|
+
- Updated dependencies [cd5d1a4]
|
|
232
|
+
- @scalar/api-client@2.0.6
|
|
233
|
+
|
|
234
|
+
## 0.5.22
|
|
235
|
+
|
|
236
|
+
### Patch Changes
|
|
237
|
+
|
|
238
|
+
- Updated dependencies [6709507]
|
|
239
|
+
- Updated dependencies [8f06fcd]
|
|
240
|
+
- Updated dependencies [8f06fcd]
|
|
241
|
+
- Updated dependencies [cdfb8c5]
|
|
242
|
+
- @scalar/api-client@2.0.5
|
|
243
|
+
|
|
244
|
+
## 0.5.21
|
|
245
|
+
|
|
246
|
+
### Patch Changes
|
|
247
|
+
|
|
248
|
+
- @scalar/api-client@2.0.4
|
|
249
|
+
|
|
250
|
+
## 0.5.20
|
|
251
|
+
|
|
252
|
+
### Patch Changes
|
|
253
|
+
|
|
254
|
+
- Updated dependencies [9f208d5]
|
|
255
|
+
- @scalar/api-client@2.0.3
|
|
256
|
+
|
|
257
|
+
## 0.5.19
|
|
258
|
+
|
|
259
|
+
### Patch Changes
|
|
260
|
+
|
|
261
|
+
- Updated dependencies [209a7e1]
|
|
262
|
+
- Updated dependencies [429e928]
|
|
263
|
+
- Updated dependencies [3ba80b9]
|
|
264
|
+
- @scalar/api-client@2.0.2
|
|
265
|
+
|
|
266
|
+
## 0.5.18
|
|
267
|
+
|
|
268
|
+
### Patch Changes
|
|
269
|
+
|
|
270
|
+
- Updated dependencies [ec52346]
|
|
271
|
+
- Updated dependencies [ded1303]
|
|
272
|
+
- Updated dependencies [6aae9fe]
|
|
273
|
+
- @scalar/api-client@2.0.1
|
|
274
|
+
|
|
275
|
+
## 0.5.17
|
|
276
|
+
|
|
277
|
+
### Patch Changes
|
|
278
|
+
|
|
279
|
+
- Updated dependencies [bd67d8f]
|
|
280
|
+
- @scalar/api-client@2.0.0
|
|
281
|
+
|
|
282
|
+
## 0.5.16
|
|
283
|
+
|
|
284
|
+
### Patch Changes
|
|
285
|
+
|
|
286
|
+
- @scalar/api-client@1.3.21
|
|
287
|
+
|
|
3
288
|
## 0.5.15
|
|
4
289
|
|
|
5
290
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -13,79 +13,35 @@ npm install @scalar/api-client-react
|
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
close={() => setIsOpen(false)}
|
|
31
|
-
isOpen={isOpen}
|
|
32
|
-
request={{
|
|
33
|
-
url: 'https://api.sampleapis.com',
|
|
34
|
-
type: 'GET',
|
|
35
|
-
path: '/simpsons/products',
|
|
36
|
-
}}
|
|
37
|
-
/>
|
|
38
|
-
</>
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
You will also need one of the following classes on a parent element:
|
|
44
|
-
|
|
45
|
-
```css
|
|
46
|
-
.dark-mode
|
|
47
|
-
.light-mode
|
|
16
|
+
First we need to add the provider, you should add it in the highest place you have a unique spec.
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { ApiClientModalProvider } from '@scalar/api-client-react'
|
|
20
|
+
import '@scalar/api-client-react/style.css'
|
|
21
|
+
|
|
22
|
+
;<ApiClientModalProvider
|
|
23
|
+
configuration={{
|
|
24
|
+
spec: {
|
|
25
|
+
url: 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.json',
|
|
26
|
+
},
|
|
27
|
+
}}>
|
|
28
|
+
{children}
|
|
29
|
+
</ApiClientModalProvider>
|
|
48
30
|
```
|
|
49
31
|
|
|
50
|
-
|
|
32
|
+
Then you can trigger it from anywhere inside of that provider by calling the `useApiClientModal()`
|
|
51
33
|
|
|
52
|
-
|
|
34
|
+
```tsx
|
|
35
|
+
import { useApiClientModal } from '@scalar/api-client-react'
|
|
53
36
|
|
|
54
|
-
|
|
37
|
+
const client = useApiClientModal()
|
|
55
38
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
export type ClientRequestConfig = {
|
|
64
|
-
id?: string
|
|
65
|
-
name?: string
|
|
66
|
-
url: string
|
|
67
|
-
/** HTTP Request Method */
|
|
68
|
-
type: string
|
|
69
|
-
/** Request path */
|
|
70
|
-
path: string
|
|
71
|
-
/** Variables */
|
|
72
|
-
variables?: BaseParameter[]
|
|
73
|
-
/** Query parameters */
|
|
74
|
-
query?: Query[]
|
|
75
|
-
/** Cookies */
|
|
76
|
-
cookies?: Cookie[]
|
|
77
|
-
/** Request headers */
|
|
78
|
-
headers?: Header[]
|
|
79
|
-
/** Content type matched body */
|
|
80
|
-
body?: string
|
|
81
|
-
/** Optional form data body */
|
|
82
|
-
formData?: FormDataItem[]
|
|
83
|
-
}
|
|
39
|
+
return (
|
|
40
|
+
<button
|
|
41
|
+
onClick={() => client?.open({ path: '/auth/token', method: 'get' })}>
|
|
42
|
+
Click me to open the Api Client
|
|
43
|
+
</button>
|
|
44
|
+
)
|
|
84
45
|
```
|
|
85
46
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
We also export the base component if you do not want the modal.
|
|
89
|
-
`ApiClientReactBase`
|
|
90
|
-
|
|
91
|
-
Details on how to use it can be found in the source code for `ApiClientReact`
|
|
47
|
+
Check out the playground for a working example.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs as p, jsx as C } from "react/jsx-runtime";
|
|
3
|
+
import { createContext as d, useRef as A, useState as s, useEffect as i, useContext as T } from "react";
|
|
4
|
+
/* empty css */
|
|
5
|
+
const o = d(null);
|
|
6
|
+
globalThis.__VUE_OPTIONS_API__ = !0;
|
|
7
|
+
globalThis.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__ = !0;
|
|
8
|
+
globalThis.__VUE_PROD_DEVTOOLS__ = !1;
|
|
9
|
+
const S = ({
|
|
10
|
+
children: c,
|
|
11
|
+
configuration: l = {}
|
|
12
|
+
}) => {
|
|
13
|
+
const e = A(null), [n, u] = s(null), [_, r] = s(null);
|
|
14
|
+
return i(() => {
|
|
15
|
+
(async () => {
|
|
16
|
+
const { createApiClientModalSync: a } = await import("@scalar/api-client");
|
|
17
|
+
u(() => a);
|
|
18
|
+
})();
|
|
19
|
+
}, []), i(() => {
|
|
20
|
+
if (!(e != null && e.current) || !n) return;
|
|
21
|
+
const t = n(e.current, l, !0, !0);
|
|
22
|
+
return r(t), l.spec && t.updateSpec(l.spec), () => {
|
|
23
|
+
t.app.unmount(), r(null);
|
|
24
|
+
};
|
|
25
|
+
}, [e, n]), /* @__PURE__ */ p(o.Provider, { value: _, children: [
|
|
26
|
+
/* @__PURE__ */ C("div", { ref: e }),
|
|
27
|
+
c
|
|
28
|
+
] });
|
|
29
|
+
}, x = () => T(o);
|
|
30
|
+
export {
|
|
31
|
+
S as ApiClientModalProvider,
|
|
32
|
+
x as useApiClientModal
|
|
33
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { App } from 'vue';
|
|
2
|
+
import { AuthenticationState } from '@scalar/oas-utils';
|
|
3
|
+
import { ClientConfiguration } from '@scalar/api-client';
|
|
2
4
|
import { default as default_2 } from 'react';
|
|
5
|
+
import { OpenClientPayload } from '@scalar/api-client';
|
|
6
|
+
import { PropsWithChildren } from 'react';
|
|
7
|
+
import { SpecConfiguration } from '@scalar/oas-utils';
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
|
-
* Api Client React
|
|
10
|
+
* Api Client Modal React
|
|
11
|
+
*
|
|
12
|
+
* Provider which mounts the Scalar Api Client Modal vue app
|
|
6
13
|
*/
|
|
7
|
-
export declare const
|
|
14
|
+
export declare const ApiClientModalProvider: ({ children, configuration, }: Props) => default_2.JSX.Element;
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* only use this if you know what you are doing
|
|
13
|
-
*/
|
|
14
|
-
export declare const ApiClientReactBase: (props: {
|
|
15
|
-
proxy: string;
|
|
16
|
-
}) => default_2.JSX.Element;
|
|
16
|
+
declare type Props = PropsWithChildren<{
|
|
17
|
+
configuration?: ClientConfiguration;
|
|
18
|
+
}>;
|
|
17
19
|
|
|
18
|
-
declare
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
export declare const useApiClientModal: () => {
|
|
21
|
+
app: App<Element>;
|
|
22
|
+
updateConfig(newConfig: ClientConfiguration, mergeConfigs?: boolean): void;
|
|
23
|
+
updateServerUrl: (serverUrl: string) => void;
|
|
24
|
+
updateAuth: (auth: AuthenticationState) => void;
|
|
25
|
+
updateSpec: (spec: SpecConfiguration) => void;
|
|
26
|
+
open: (payload?: OpenClientPayload) => void;
|
|
27
|
+
mount: (mountingEl?: HTMLElement | null) => void;
|
|
28
|
+
modalState: {
|
|
29
|
+
open: boolean;
|
|
30
|
+
show: () => void;
|
|
31
|
+
hide: () => void;
|
|
32
|
+
};
|
|
33
|
+
} | null;
|
|
24
34
|
|
|
25
35
|
export { }
|