@scalar/api-client-react 1.4.9 → 1.4.11

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,21 @@
1
1
  # @scalar/api-client-react
2
2
 
3
+ ## 1.4.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#8466](https://github.com/scalar/scalar/pull/8466): chore: new build pipeline
8
+
9
+ ## 1.4.10
10
+
11
+ ### Patch Changes
12
+
13
+ #### Updated Dependencies
14
+
15
+ - **@scalar/api-client@2.38.1**
16
+ - [#8468](https://github.com/scalar/scalar/pull/8468): fix: example extraction, environment navigation and general UI fixes
17
+ - [#8451](https://github.com/scalar/scalar/pull/8451): fix(api-client): default-close auth when not required
18
+
3
19
  ## 1.4.9
4
20
 
5
21
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export type { OpenClientPayload } from './ApiClientModalProvider.js';
2
- export { ApiClientModalProvider, useApiClientModal } from './ApiClientModalProvider.js';
1
+ export type { OpenClientPayload } from './ApiClientModalProvider';
2
+ export { ApiClientModalProvider, useApiClientModal } from './ApiClientModalProvider';
3
3
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,115 @@
1
- import { ApiClientModalProvider as o, useApiClientModal as l } from "./ApiClientModalProvider.js";
2
- export {
3
- o as ApiClientModalProvider,
4
- l as useApiClientModal
1
+ "use client";
2
+ import { createContext, useContext, useEffect, useRef, useSyncExternalStore } from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ //#region src/client-store.ts
5
+ globalThis.__VUE_OPTIONS_API__ = true;
6
+ globalThis.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__ = true;
7
+ globalThis.__VUE_PROD_DEVTOOLS__ = false;
8
+ /** Client state */
9
+ var state = {
10
+ createClient: null,
11
+ clientDict: {}
5
12
  };
13
+ /** Set of listener functions to be called when state changes */
14
+ var listeners = /* @__PURE__ */ new Set();
15
+ /** Subscribe to state changes */
16
+ var subscribe = (listener) => {
17
+ listeners.add(listener);
18
+ return () => listeners.delete(listener);
19
+ };
20
+ /** Get the current state at this moment in time */
21
+ var getSnapshot = () => state;
22
+ /** Trigger all listeners */
23
+ var emit = () => listeners.forEach((listener) => listener());
24
+ /** Set the create client state */
25
+ var setCreateClient = (clientFactory) => {
26
+ state = {
27
+ ...state,
28
+ createClient: clientFactory
29
+ };
30
+ emit();
31
+ };
32
+ /** Add a client to the client dict */
33
+ var addClient = (url, client) => {
34
+ state = {
35
+ ...state,
36
+ clientDict: {
37
+ ...state.clientDict,
38
+ [url]: client
39
+ }
40
+ };
41
+ emit();
42
+ };
43
+ /** Remove a client from the client dict */
44
+ var removeClient = (url) => {
45
+ const { [url]: _, ...clientDict } = state.clientDict;
46
+ state = {
47
+ ...state,
48
+ clientDict
49
+ };
50
+ emit();
51
+ };
52
+ var clientStore = {
53
+ getSnapshot,
54
+ subscribe,
55
+ setCreateClient,
56
+ addClient,
57
+ removeClient
58
+ };
59
+ //#endregion
60
+ //#region src/ApiClientModalProvider.tsx
61
+ var ApiClientModalContext = createContext(null);
62
+ /** Ensures we only load createClient once */
63
+ var isLoading = false;
64
+ /** Hack: this is strictly to prevent creation of extra clients as the store lags a bit */
65
+ var clientDict = {};
66
+ /**
67
+ * Api Client Modal React
68
+ *
69
+ * Provider which mounts the Scalar Api Client Modal vue app.
70
+ * Rebuilt to support multiple instances when using a unique spec.url
71
+ */
72
+ var ApiClientModalProvider = ({ children, initialRequest, configuration = {} }) => {
73
+ const key = configuration.spec?.url || "default";
74
+ const el = useRef(null);
75
+ const state = useSyncExternalStore(clientStore.subscribe, clientStore.getSnapshot, clientStore.getSnapshot);
76
+ useEffect(() => {
77
+ const loadApiClientJs = async () => {
78
+ isLoading = true;
79
+ const { createApiClientModal } = await import("@scalar/api-client/layouts/Modal");
80
+ clientStore.setCreateClient(createApiClientModal);
81
+ };
82
+ if (!isLoading) loadApiClientJs();
83
+ }, []);
84
+ useEffect(() => {
85
+ if (!el.current || !state.createClient || clientDict[key]) return () => null;
86
+ const { client: _client } = state.createClient({
87
+ el: el.current,
88
+ configuration
89
+ });
90
+ const updateConfig = async () => {
91
+ await _client.updateConfig(configuration);
92
+ if (initialRequest) _client.route(initialRequest);
93
+ };
94
+ clientStore.addClient(key, _client);
95
+ clientDict[key] = _client;
96
+ updateConfig();
97
+ return () => {
98
+ _client.app.unmount();
99
+ clientStore.removeClient(key);
100
+ delete clientDict[key];
101
+ };
102
+ }, [el.current, state.createClient]);
103
+ return /* @__PURE__ */ jsxs(ApiClientModalContext.Provider, {
104
+ value: state.clientDict[key] ?? null,
105
+ children: [/* @__PURE__ */ jsx("div", {
106
+ className: "scalar-app",
107
+ ref: el
108
+ }), children]
109
+ });
110
+ };
111
+ var useApiClientModal = () => useContext(ApiClientModalContext);
112
+ //#endregion
113
+ export { ApiClientModalProvider, useApiClientModal };
114
+
115
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/client-store.ts","../src/ApiClientModalProvider.tsx"],"sourcesContent":["import type { ApiClient, createApiClientModal } from '@scalar/api-client/layouts/Modal'\n\n// These are required for the vue bundler version\nglobalThis.__VUE_OPTIONS_API__ = true\nglobalThis.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__ = true\nglobalThis.__VUE_PROD_DEVTOOLS__ = false\n\n/** Client state */\nlet state = {\n createClient: null as typeof createApiClientModal | null,\n clientDict: {} as Record<string, ApiClient>,\n}\n\n/** Set of listener functions to be called when state changes */\nconst listeners = new Set<() => void>()\n\n/** Subscribe to state changes */\nconst subscribe = (listener: () => void) => {\n listeners.add(listener)\n return () => listeners.delete(listener)\n}\n\n/** Get the current state at this moment in time */\nconst getSnapshot = () => state\n\n/** Trigger all listeners */\nconst emit = () => listeners.forEach((listener) => listener())\n\n/** Set the create client state */\nconst setCreateClient = (clientFactory: typeof createApiClientModal) => {\n state = { ...state, createClient: clientFactory }\n emit()\n}\n\n/** Add a client to the client dict */\nconst addClient = (url: string, client: ApiClient) => {\n state = { ...state, clientDict: { ...state.clientDict, [url]: client } }\n emit()\n}\n\n/** Remove a client from the client dict */\nconst removeClient = (url: string) => {\n const { [url]: _, ...clientDict } = state.clientDict\n state = { ...state, clientDict }\n emit()\n}\n\nexport const clientStore = {\n getSnapshot,\n subscribe,\n setCreateClient,\n addClient,\n removeClient,\n}\n","'use client'\n\nimport type { ApiClient } from '@scalar/api-client/layouts/Modal'\nimport type { OpenClientPayload } from '@scalar/api-client/libs'\nimport type { ApiClientConfiguration } from '@scalar/types/api-reference'\nimport type { PropsWithChildren } from 'react'\nimport { createContext, useContext, useEffect, useRef, useSyncExternalStore } from 'react'\n\nexport type { OpenClientPayload }\n\nimport { clientStore } from './client-store'\n\nimport './style.css'\n\nconst ApiClientModalContext = createContext<ApiClient | null>(null)\n\ntype Props = PropsWithChildren<{\n /** Choose a request to initially route to */\n initialRequest?: OpenClientPayload\n /** Configuration for the Api Client */\n configuration?: Partial<ApiClientConfiguration>\n}>\n\n/** Ensures we only load createClient once */\nlet isLoading = false\n\n/** Hack: this is strictly to prevent creation of extra clients as the store lags a bit */\nconst clientDict: Record<string, ApiClient> = {}\n\n/**\n * Api Client Modal React\n *\n * Provider which mounts the Scalar Api Client Modal vue app.\n * Rebuilt to support multiple instances when using a unique spec.url\n */\nexport const ApiClientModalProvider = ({ children, initialRequest, configuration = {} }: Props) => {\n const key = configuration.spec?.url || 'default'\n const el = useRef<HTMLDivElement | null>(null)\n\n const state = useSyncExternalStore(clientStore.subscribe, clientStore.getSnapshot, clientStore.getSnapshot)\n\n // Lazyload the js to create the client, but we only wanna call this once\n useEffect(() => {\n const loadApiClientJs = async () => {\n isLoading = true\n const { createApiClientModal } = await import('@scalar/api-client/layouts/Modal')\n clientStore.setCreateClient(createApiClientModal)\n }\n if (!isLoading) {\n void loadApiClientJs()\n }\n }, [])\n\n useEffect(() => {\n if (!el.current || !state.createClient || clientDict[key]) {\n return () => null\n }\n\n // Check for cached client first\n const { client: _client } = state.createClient({\n el: el.current,\n configuration,\n })\n\n const updateConfig = async () => {\n await _client.updateConfig(configuration!)\n if (initialRequest) {\n _client.route(initialRequest)\n }\n }\n\n // Add the client to the store and dict\n clientStore.addClient(key, _client)\n clientDict[key] = _client\n\n // We update the config as we are using the sync version\n void updateConfig()\n\n // Ensure we unmount the vue app on unmount\n return () => {\n _client.app.unmount()\n clientStore.removeClient(key)\n delete clientDict[key]\n }\n }, [el.current, state.createClient])\n\n return (\n <ApiClientModalContext.Provider value={state.clientDict[key] ?? null}>\n <div\n className=\"scalar-app\"\n ref={el}\n />\n {children}\n </ApiClientModalContext.Provider>\n )\n}\n\nexport const useApiClientModal = (): ApiClient | null => useContext(ApiClientModalContext)\n"],"mappings":";;;;AAGA,WAAW,sBAAsB;AACjC,WAAW,0CAA0C;AACrD,WAAW,wBAAwB;;AAGnC,IAAI,QAAQ;CACV,cAAc;CACd,YAAY,EAAA;CACb;;AAGD,IAAM,4BAAY,IAAI,KAAiB;;AAGvC,IAAM,aAAa,aAAyB;AAC1C,WAAU,IAAI,SAAS;AACvB,cAAa,UAAU,OAAO,SAAS;;;AAIzC,IAAM,oBAAoB;;AAG1B,IAAM,aAAa,UAAU,SAAS,aAAa,UAAU,CAAC;;AAG9D,IAAM,mBAAmB,kBAA+C;AACtE,SAAQ;EAAE,GAAG;EAAO,cAAc;EAAe;AACjD,OAAM;;;AAIR,IAAM,aAAa,KAAa,WAAsB;AACpD,SAAQ;EAAE,GAAG;EAAO,YAAY;GAAE,GAAG,MAAM;IAAa,MAAM;;EAAU;AACxE,OAAM;;;AAIR,IAAM,gBAAgB,QAAgB;CACpC,MAAM,GAAG,MAAM,GAAG,GAAG,eAAe,MAAM;AAC1C,SAAQ;EAAE,GAAG;EAAO;EAAY;AAChC,OAAM;;AAGR,IAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACD;;;ACvCD,IAAM,wBAAwB,cAAgC,K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