@scalar/docusaurus 0.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 ADDED
@@ -0,0 +1,9 @@
1
+ # @scalar/docusaurus
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - f18b3f1: feat: added docusaurus plugin and example
8
+ - Updated dependencies [f18b3f1]
9
+ - @scalar/api-reference-react@0.0.4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Scalar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Scalar Docusaurus API Reference Plugin
2
+
3
+ [![Version](https://img.shields.io/npm/v/%40scalar/docusaurus)](https://www.npmjs.com/package/@scalar/docusaurus)
4
+ [![Downloads](https://img.shields.io/npm/dm/%40scalar/docusaurus)](https://www.npmjs.com/package/@scalar/docusaurus)
5
+ [![License](https://img.shields.io/npm/l/%40scalar%2Fdocusaurus)](https://www.npmjs.com/package/@scalar/docusaurus)
6
+
7
+ [![Discord](https://img.shields.io/discord/1135330207960678410?style=flat&color=5865F2)](https://discord.gg/8HeZcRGPFS)
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @scalar/docusaurus
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Simple add to the plugins section of your Docusaurus config. If you are using
18
+ typescript you can import the type options type as well
19
+
20
+ ```ts
21
+ import type { ScalarOptions } from '@scalar/docusaurus'
22
+
23
+ plugins: [
24
+ [
25
+ '@scalar/docusaurus',
26
+ {
27
+ label: 'Scalar',
28
+ route: '/scalar',
29
+ configuration: {
30
+ spec: {
31
+ url: 'https://petstore3.swagger.io/api/v3/openapi.json',
32
+ },
33
+ },
34
+ } as ScalarOptions,
35
+ ],
36
+ ],
37
+ ```
38
+
39
+ ### Example
40
+
41
+ You can find an example in this repo under [examples/docusaurus](https://github.com/scalar/scalar/tree/main/examples/docusaurus)
42
+
43
+ ## Config
44
+
45
+ These configuration options are a WIP as this plugin is still in beta
46
+
47
+ ### label: string
48
+
49
+ The label on the nav bar for this route
50
+
51
+ ### route: string
52
+
53
+ Path at which the API Reference will be shown
54
+
55
+ ### configuration: ReferenceProps
56
+
57
+ You can find the full configuration options under
58
+ [packages/api-reference](https://github.com/scalar/scalar/tree/main/packages/api-reference)
59
+ minus theme.
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ /**
8
+ * Scalar's Docusaurus plugin for Api References
9
+ */
10
+ const ScalarDocusaurus = (context, options) => {
11
+ return {
12
+ name: '@scalar/docusaurus',
13
+ async loadContent() {
14
+ // Check if we need to download a spec
15
+ if (options.configuration?.spec?.url) {
16
+ const resp = await fetch(options.configuration.spec.url);
17
+ const content = await resp.json();
18
+ return {
19
+ configuration: { ...options.configuration, spec: { content } },
20
+ };
21
+ }
22
+ return options;
23
+ },
24
+ async contentLoaded({ content, actions }) {
25
+ const { addRoute } = actions;
26
+ context.siteConfig.themeConfig.navbar.items.push({
27
+ to: options.route ?? '/scalar',
28
+ label: options.label ?? 'Scalar',
29
+ position: 'left',
30
+ });
31
+ addRoute({
32
+ path: options.route,
33
+ component: path_1.default.resolve(__dirname, './ScalarDocusaurus'),
34
+ // Provide the path to the loaded spec as a prop to your component
35
+ exact: true,
36
+ ...content,
37
+ });
38
+ },
39
+ };
40
+ };
41
+ exports.default = ScalarDocusaurus;
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@scalar/docusaurus",
3
+ "description": "Docusaurus integration for api references",
4
+ "license": "MIT",
5
+ "author": "Scalar (https://github.com/scalar)",
6
+ "homepage": "https://github.com/scalar/scalar",
7
+ "bugs": "https://github.com/scalar/scalar/issues/new/choose",
8
+ "keywords": [
9
+ "api",
10
+ "client",
11
+ "docusaurus",
12
+ "postman alternative",
13
+ "rest",
14
+ "testing",
15
+ "react"
16
+ ],
17
+ "version": "0.0.2",
18
+ "engines": {
19
+ "node": ">=20"
20
+ },
21
+ "main": "./dist/index.js",
22
+ "files": [
23
+ "src",
24
+ "CHANGELOG.md"
25
+ ],
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/scalar/scalar.git",
29
+ "directory": "packages/docusaurus"
30
+ },
31
+ "dependencies": {
32
+ "@scalar/api-reference-react": "0.0.4"
33
+ },
34
+ "devDependencies": {
35
+ "@docusaurus/types": "^3.1.1",
36
+ "@types/react": "^18.2.60",
37
+ "@types/react-dom": "^18.2.19",
38
+ "path": "^0.12.7",
39
+ "react": "^18.2.0"
40
+ },
41
+ "peerDependencies": {
42
+ "react": "^18.0.0"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc --declaration && cp ./src/theme.css ./dist/",
46
+ "lint:check": "eslint .",
47
+ "lint:fix": "eslint . --fix",
48
+ "types:check": "tsc --noEmit --skipLibCheck"
49
+ }
50
+ }
@@ -0,0 +1,25 @@
1
+ import BrowserOnly from '@docusaurus/BrowserOnly'
2
+ import { type ReferenceProps } from '@scalar/api-reference-react'
3
+ import Layout from '@theme/Layout'
4
+ import React from 'react'
5
+
6
+ import './theme.css'
7
+
8
+ type Props = {
9
+ route: ReferenceProps
10
+ }
11
+
12
+ export const ScalarDocusaurus = ({ route }: Props) => (
13
+ <Layout>
14
+ <BrowserOnly>
15
+ {() => {
16
+ const ApiReferenceReact =
17
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
18
+ require('@scalar/api-reference-react').ApiReferenceReact
19
+ return <ApiReferenceReact configuration={route.configuration} />
20
+ }}
21
+ </BrowserOnly>
22
+ </Layout>
23
+ )
24
+
25
+ export default ScalarDocusaurus
package/src/index.ts ADDED
@@ -0,0 +1,58 @@
1
+ import type { LoadContext, Plugin } from '@docusaurus/types'
2
+ import { type ReferenceProps } from '@scalar/api-reference-react'
3
+ import path from 'path'
4
+
5
+ export type ScalarOptions = {
6
+ label: string
7
+ route: string
8
+ } & ReferenceProps
9
+
10
+ /**
11
+ * Scalar's Docusaurus plugin for Api References
12
+ */
13
+ const ScalarDocusaurus = (
14
+ context: LoadContext,
15
+ options: ScalarOptions,
16
+ ): Plugin<ReferenceProps> => {
17
+ return {
18
+ name: '@scalar/docusaurus',
19
+
20
+ async loadContent() {
21
+ // Check if we need to download a spec
22
+ if (options.configuration?.spec?.url) {
23
+ const resp = await fetch(options.configuration.spec.url)
24
+ const content = await resp.json()
25
+ return {
26
+ configuration: { ...options.configuration, spec: { content } },
27
+ }
28
+ }
29
+
30
+ return options
31
+ },
32
+
33
+ async contentLoaded({ content, actions }) {
34
+ const { addRoute } = actions
35
+
36
+ // Add entry to nav
37
+ ;(
38
+ context.siteConfig.themeConfig.navbar as {
39
+ items: Record<string, string>[]
40
+ }
41
+ ).items.push({
42
+ to: options.route ?? '/scalar',
43
+ label: options.label ?? 'Scalar',
44
+ position: 'left',
45
+ })
46
+
47
+ addRoute({
48
+ path: options.route,
49
+ component: path.resolve(__dirname, './ScalarDocusaurus'),
50
+ // Provide the path to the loaded spec as a prop to your component
51
+ exact: true,
52
+ ...content,
53
+ })
54
+ },
55
+ }
56
+ }
57
+
58
+ export default ScalarDocusaurus
package/src/shims.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ declare module '@theme/Layout' {
2
+ import { Component } from 'react'
3
+ export default Component
4
+ }
5
+
6
+ declare module '@docusaurus/BrowserOnly' {
7
+ export default Component
8
+ }
package/src/theme.css ADDED
@@ -0,0 +1,324 @@
1
+ /* Scalar Theme */
2
+ :root {
3
+ --theme-font: var(--ifm-font-family-base);
4
+ --theme-font-code: var(--ifm-font-family-monospace);
5
+ }
6
+ .scalar-api-reference {
7
+ --refs-header-height: var(--ifm-navbar-height) !important;
8
+ }
9
+ /* basic theme */
10
+ html[data-theme='light'] {
11
+ --theme-color-1: var(--ifm-font-color-base, #1c1e21);
12
+ --theme-color-2: var(--ifm-color-emphasis-700, #606770);
13
+ --theme-color-3: var(--ifm-color-emphasis-600, #8d949e);
14
+ --theme-color-accent: var(--ifm-menu-color-active, #277148);
15
+
16
+ --theme-background-1: #fff;
17
+ --theme-background-2: #f6f6f6;
18
+ --theme-background-3: #e7e7e7;
19
+ --theme-background-accent: var(
20
+ --ifm-menu-color-background-active,
21
+ rgba(0, 0, 0, 0.05)
22
+ );
23
+
24
+ --theme-border-color: var(--ifm-color-emphasis-300, #ebedf0);
25
+ }
26
+ @supports (color: color-mix(in srgb, rgba(0, 0, 0, 1) 5%, white)) {
27
+ html[data-theme='light'] {
28
+ --theme-background-1: color-mix(
29
+ in srgb,
30
+ var(--ifm-background-color, #fff) 0%,
31
+ white
32
+ );
33
+ --theme-background-2: color-mix(in srgb, rgba(0, 0, 0, 1) 4%, white);
34
+ --theme-background-3: color-mix(in srgb, rgba(0, 0, 0, 1) 8%, white);
35
+ }
36
+ }
37
+
38
+ html[data-theme='dark'] {
39
+ --theme-color-1: var(--ifm-font-color-base, rgb(227, 227, 227));
40
+ --theme-color-2: var(--ifm-color-emphasis-700, #dadde1);
41
+ --theme-color-3: var(--ifm-color-emphasis-400, #8d949e);
42
+ --theme-color-accent: var(--ifm-menu-color-active, #1fa588);
43
+
44
+ --theme-background-1: var(--ifm-background-color, #1b1b1d);
45
+ --theme-background-2: var(--prism-background-color, #212121);
46
+ --theme-background-3: #323232;
47
+ --theme-background-accent: var(
48
+ --ifm-menu-color-background-active,
49
+ hsla(0, 0%, 100%, 0.05)
50
+ );
51
+
52
+ --theme-border-color: var(--ifm-color-emphasis-200, #444950);
53
+ }
54
+ .sidebar-group-item:has(.active_page) .sidebar-group-item__folder {
55
+ color: var(--theme-color-accent);
56
+ }
57
+ /* Document Sidebar */
58
+ .t-doc__sidebar {
59
+ --sidebar-background-1: var(--theme-background-1);
60
+ --sidebar-item-hover-color: currentColor;
61
+ --sidebar-item-active-background: var(--theme-background-accent);
62
+ --sidebar-border-color: var(--theme-border-color);
63
+ --sidebar-color-1: var(--theme-color-1);
64
+ --sidebar-color-2: var(--theme-color-2);
65
+ --sidebar-color-active: var(--theme-color-accent);
66
+ --sidebar-search-background: var(
67
+ --docsearch-searchbox-background,
68
+ transparent
69
+ );
70
+ --sidebar-search-border-color: var(--theme-border-color);
71
+ --sidebar-search--color: var(--theme-color-3);
72
+ }
73
+ html[data-theme='light'] .t-doc__sidebar {
74
+ --sidebar-item-hover-background: var(
75
+ --ifm-menu-color-background-hover,
76
+ rgba(0, 0, 0, 0.05)
77
+ );
78
+ }
79
+ html[data-theme='dark'] .t-doc__sidebar {
80
+ --sidebar-item-hover-background: var(
81
+ --ifm-menu-color-background-hover,
82
+ hsla(0, 0%, 100%, 0.05)
83
+ );
84
+ }
85
+ .references-sidebar {
86
+ --refs-sidebar-width: 300px !important;
87
+ }
88
+ /* advanced */
89
+ html[data-theme='light'] {
90
+ --theme-color-green: var(--ifm-color-success, #00a400);
91
+ --theme-color-red: var(--ifm-color-danger, #fa383e);
92
+ --theme-color-yellow: var(--ifm-color-warning, #ffba00);
93
+ --theme-color-blue: var(--ifm-color-info-darkest, #2554a0);
94
+ --theme-color-orange: #fb892c;
95
+ --theme-color-purple: #5203d1;
96
+ --theme-docsearch-key: var(
97
+ --docsearch-key-gradient,
98
+ linear-gradient(-225deg, #d5dbe4, #f8f8f8)
99
+ );
100
+ --theme-docsearch-boxshadow: var(
101
+ --docsearch-key-shadow,
102
+ inset 0 -2px 0 0 #cdcde6,
103
+ inset 0 0 1px 1px #fff,
104
+ 0 1px 2px 1px rgba(30, 35, 90, 0.4)
105
+ );
106
+ }
107
+ html[data-theme='dark'] {
108
+ --theme-color-green: var(--ifm-color-success, #00a400);
109
+ --theme-color-red: var(--ifm-color-danger, #fa383e);
110
+ --theme-color-yellow: var(--ifm-color-warning, #ffba00);
111
+ --theme-color-blue: var(--ifm-color-info-light, #3578e5);
112
+ --theme-color-orange: #ff8d4d;
113
+ --theme-color-purple: #b191f9;
114
+ --theme-docsearch-key: var(
115
+ --docsearch-key-gradient,
116
+ linear-gradient(-26.5deg, #444950 0%, #1c1e21 100%)
117
+ );
118
+ --theme-docsearch-boxshadow: var(
119
+ --docsearch-key-shadow,
120
+ inset 0 -2px 0 0 #282d55,
121
+ inset 0 0 1px 1px #51577d,
122
+ 0 2px 2px 0 rgba(3, 4, 9, 0.3)
123
+ );
124
+ }
125
+ .references-rendered .section-header {
126
+ color: var(--ifm-heading-color, var(--theme-color-1));
127
+ }
128
+ .sidebar-heading-type {
129
+ background: transparent !important;
130
+ color: var(--method-color) !important;
131
+ font-size: 10px !important;
132
+ line-height: 16px !important;
133
+ padding: 1px 3px !important;
134
+ }
135
+ .sidebar-heading-type:after {
136
+ content: '';
137
+ display: block;
138
+ position: absolute;
139
+ top: 0;
140
+ left: 0;
141
+ width: 100%;
142
+ height: 100%;
143
+ background: var(--method-color);
144
+ opacity: 0.15;
145
+ }
146
+ html[data-theme='light'] .sidebar-heading.active_page .sidebar-heading-type {
147
+ background: white !important;
148
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
149
+ }
150
+ html[data-theme='dark'] .sidebar-heading.active_page .sidebar-heading-type {
151
+ background: rgba(255, 255, 255, 0.14) !important;
152
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
153
+ }
154
+ .sidebar-heading.active_page .sidebar-heading-type:after {
155
+ display: none;
156
+ }
157
+ .references-rendered .section-container:nth-of-type(2) {
158
+ border-top: none !important;
159
+ }
160
+ .scalar-card-checkbox .scalar-card-checkbox-checkmark:after,
161
+ html[data-theme='light'] .api-client-drawer {
162
+ --theme-background-1: white;
163
+ }
164
+ .sidebar-heading.sidebar-group-item__folder {
165
+ flex-direction: row-reverse;
166
+ }
167
+ .sidebar-heading-chevron {
168
+ transition: all 0.3s ease-in-out;
169
+ border-radius: var(--theme-radius);
170
+ }
171
+ .sidebar-heading-chevron:before {
172
+ background: var(--ifm-menu-link-sublist-icon) 50% / 2rem 2rem;
173
+ height: 1.25rem;
174
+ transform: rotate(90deg);
175
+ transition: transform var(--ifm-transition-fast) linear;
176
+ width: 1.25rem;
177
+ content: '';
178
+ filter: var(--ifm-menu-link-sublist-icon-filter);
179
+ }
180
+ .sidebar-heading-chevron:hover {
181
+ background-color: var(--ifm-menu-color-background-hover);
182
+ }
183
+ .sidebar-heading-chevron .scalar-icon-button {
184
+ position: absolute;
185
+ top: 0;
186
+ left: 0;
187
+ width: 100%;
188
+ height: 100%;
189
+ }
190
+ .sidebar-group-item:has(ul) .sidebar-heading-chevron:before {
191
+ transform: rotate(180deg);
192
+ }
193
+ .sidebar-heading-chevron svg {
194
+ color: transparent;
195
+ }
196
+ .sidebar-heading {
197
+ margin-top: 2px;
198
+ --theme-mini: auto !important;
199
+ }
200
+ .sidebar-heading-link p {
201
+ font-family: var(--ifm-font-family-base), 'Inter', var(--system-fonts);
202
+ font-weight: 500;
203
+ }
204
+ .sidebar-indent-nested .sidebar-heading {
205
+ --default-theme-sidebar-indent-base: 6px;
206
+ }
207
+ .sidebar .darklight {
208
+ display: none !important;
209
+ }
210
+ .darklight-reference-promo {
211
+ padding-top: 12px !important;
212
+ --theme-mini: auto;
213
+ }
214
+ .sidebar-search,
215
+ .sidebar-search-input {
216
+ --theme-mini: 16px;
217
+ }
218
+ .references-header {
219
+ pointer-events: none;
220
+ }
221
+ .sidebar-search-shortcut {
222
+ display: flex;
223
+ }
224
+ .sidebar-search-shortcut .sidebar-search-key {
225
+ font-family: var(--theme-font-code);
226
+ font-size: 15px;
227
+ background: var(--theme-docsearch-key);
228
+ border: 0;
229
+ border-radius: 3px;
230
+ box-shadow: var(--theme-docsearch-boxshadow);
231
+ }
232
+ .t-doc__sidebar {
233
+ max-height: calc(100dvh - var(--ifm-navbar-height));
234
+ position: sticky;
235
+ top: var(--ifm-navbar-height);
236
+ }
237
+ #headlessui-portal-root {
238
+ position: fixed !important;
239
+ width: 100%;
240
+ }
241
+ #__docusaurus[aria-hidden='true'] ~ #headlessui-portal-root {
242
+ position: relative !important;
243
+ }
244
+ .references-layout {
245
+ height: initial !important;
246
+ max-height: initial !important;
247
+ overflow: initial !important;
248
+ grid-template-rows: 0 repeat(2, auto) !important;
249
+ }
250
+ .references-navigation-list {
251
+ height: 100% !important;
252
+ }
253
+ .section-column:nth-of-type(2) {
254
+ max-height: calc(100dvh - var(--ifm-navbar-height));
255
+ }
256
+ .scalar-card {
257
+ --full-height: calc(100dvh - var(--ifm-navbar-height));
258
+ max-height: calc(
259
+ ((var(--full-height) - var(--refs-header-height)) - 60px) / 2
260
+ );
261
+ }
262
+ .sidebar-heading-chevron {
263
+ padding: var(--ifm-menu-link-padding-vertical)
264
+ var(--ifm-menu-link-padding-horizontal);
265
+ margin: 0 !important;
266
+ margin-right: -9px !important;
267
+ }
268
+ .schema-properties-open > .schema-card-title {
269
+ backdrop-filter: blur(50px);
270
+ }
271
+ .tag-section-container .scalar-card {
272
+ border: none !important;
273
+ }
274
+ .references-narrow .section {
275
+ padding-top: calc(var(--refs-header-height) + 48px) !important;
276
+ }
277
+ @media screen and (max-width: 996px) {
278
+ .references-header {
279
+ pointer-events: all;
280
+ top: calc(var(--refs-header-height) + 12px) !important;
281
+ margin: 0 24px;
282
+ height: 36px !important;
283
+ position: fixed !important;
284
+ bottom: 24px;
285
+ top: initial !important;
286
+ width: calc(100% - 48px);
287
+ }
288
+ .references-mobile-header {
289
+ border-radius: 6px;
290
+ gap: 0 !important;
291
+ background: var(--theme-background-3) !important;
292
+ border: none !important;
293
+ }
294
+ .references-mobile-breadcrumbs:empty:before {
295
+ content: 'Menu';
296
+ }
297
+ .references-header .scalar-icon-button:before {
298
+ content: '';
299
+ position: absolute;
300
+ top: 0;
301
+ left: 0;
302
+ width: 100%;
303
+ display: block;
304
+ height: 100%;
305
+ }
306
+ .t-doc__sidebar {
307
+ position: fixed !important;
308
+ bottom: 72px;
309
+ width: calc(100dvw - 48px) !important;
310
+ height: calc(100dvh - var(--refs-header-height) - 84px) !important;
311
+ left: 24px;
312
+ top: initial !important;
313
+ }
314
+ .t-doc__sidebar .sidebar {
315
+ border-right: none !important;
316
+ }
317
+ html[data-theme='light'] .sidebar {
318
+ backdrop-filter: blur(50px);
319
+ }
320
+ .references-navigation-list {
321
+ border: 1px solid var(--theme-border-color) !important;
322
+ border-radius: 12px;
323
+ }
324
+ }