mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 18:13:29 +00:00
feat: add scalar api client (#180)
* wip * feat: add scalar api client * fix: pr feedback * feat: add scalar react client package, remove vueary * feat: add scalar proxy * Move dependencies to package * Format once * Rename prop * Use react context and simplify lazy loading * Add loading state * Format * Move styles * bun install * bun * fix: remove extraneous api-reference package * feat: make operation functional with spec in client * fix: column bug and http request type wrapping * fix: add scalar api reference package * Format * bun install * fix: scrolling in scalar modal * Lazy load operations data in component * fix: change dependency from api-reference to oas-utils to reduce size * bun install * Log error in the worker proxy * Cleanup * Comment "mode" * Without credentials and referrerPolicy --------- Co-authored-by: Samy Pessé <samypesse@gmail.com> Co-authored-by: Amrit <amrit@hockey-community.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import { BlockProps } from '../Block';
|
||||
import { PlainCodeBlock } from '../CodeBlock';
|
||||
|
||||
import './style.css';
|
||||
import './scalar.css';
|
||||
|
||||
/**
|
||||
* Render an OpenAPI block.
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
.light .scalar-modal-layout,
|
||||
.light .scalar {
|
||||
--theme-color-1: color-mix(
|
||||
in srgb,
|
||||
rgb(var(--primary-base-300, 180 180 180)),
|
||||
rgb(var(--dark-base, 23 23 23)) 96%
|
||||
);
|
||||
--theme-color-2: color-mix(in srgb, var(--theme-color-1), transparent calc(100% - 100% * 0.72));
|
||||
--theme-color-3: color-mix(in srgb, var(--theme-color-1), transparent calc(100% - 100% * 0.4));
|
||||
--theme-color-accent: #007d9c;
|
||||
|
||||
--theme-background-1: rgb(var(--light-base, 255 255 255));
|
||||
--theme-background-2: color-mix(
|
||||
in srgb,
|
||||
rgb(var(--primary-base-800, 30 30 30)),
|
||||
var(--theme-background-1) 96%
|
||||
);
|
||||
--theme-background-3: color-mix(
|
||||
in srgb,
|
||||
rgb(var(--primary-base-800, 30 30 30)),
|
||||
var(--theme-background-1) 90%
|
||||
);
|
||||
--theme-background-accent: #007d9c1f;
|
||||
--theme-code-language-color-supersede: var(--theme-color-1);
|
||||
--theme-code-languages-background-supersede: var(--theme-background-1);
|
||||
--theme-border-color: color-mix(
|
||||
in srgb,
|
||||
var(--theme-color-1),
|
||||
transparent calc(100% - 100% * 0.08)
|
||||
);
|
||||
|
||||
--theme-color-green: #0a6355;
|
||||
--theme-color-red: #dc1b19;
|
||||
--theme-color-yellow: #ffc90d;
|
||||
--theme-color-blue: rgb(var(--primary-color-500, 52 109 219));
|
||||
--theme-color-orange: #ff8d4d;
|
||||
--theme-color-purple: #8250df;
|
||||
|
||||
--theme-scrollbar-color: rgba(255, 255, 255, 0.24);
|
||||
--theme-scrollbar-color-active: rgba(255, 255, 255, 0.48);
|
||||
}
|
||||
.dark .scalar-modal-layout,
|
||||
.dark .scalar {
|
||||
--theme-color-1: color-mix(
|
||||
in srgb,
|
||||
rgb(var(--primary-base-700, 70 70 70)),
|
||||
rgb(var(--light-base, 255 255 255)) 100%
|
||||
);
|
||||
--theme-color-2: color-mix(in srgb, var(--theme-color-1), transparent calc(100% - 100% * 0.64));
|
||||
--theme-color-3: color-mix(in srgb, var(--theme-color-1), transparent calc(100% - 100% * 0.4));
|
||||
--theme-color-accent: #50b7e0;
|
||||
|
||||
--theme-background-1: rgb(var(--dark-base, 22 22 22));
|
||||
--theme-background-2: color-mix(
|
||||
in srgb,
|
||||
rgb(var(--primary-base-200, 200 200 200)),
|
||||
var(--theme-background-1) 92%
|
||||
);
|
||||
--theme-background-3: color-mix(
|
||||
in srgb,
|
||||
rgb(var(--primary-base-200, 200 200 200)),
|
||||
var(--theme-background-1) 88%
|
||||
);
|
||||
--theme-background-accent: #8ab4f81f;
|
||||
--theme-code-languages-background-supersede: var(--theme-background-1);
|
||||
--theme-border-color: color-mix(
|
||||
in srgb,
|
||||
var(--theme-color-1),
|
||||
transparent calc(100% - 100% * 0.08)
|
||||
);
|
||||
|
||||
--theme-color-green: #56b6c2;
|
||||
--theme-color-red: rgb(245 124 97);
|
||||
--theme-color-yellow: #edbe20;
|
||||
--theme-color-blue: rgb(var(--primary-color-400, 93 138 226));
|
||||
--theme-color-orange: #d19a66;
|
||||
--theme-color-purple: #5203d1;
|
||||
|
||||
--theme-scrollbar-color: rgba(0, 0, 0, 0.18);
|
||||
--theme-scrollbar-color-active: rgba(0, 0, 0, 0.36);
|
||||
}
|
||||
.scalar-modal-layout,
|
||||
.scalar {
|
||||
--theme-font: initial;
|
||||
--theme-font-code: var(--font-mono);
|
||||
|
||||
--theme-paragraph: 16px;
|
||||
--theme-small: 14px;
|
||||
--theme-mini: 13px;
|
||||
--theme-micro: 12px;
|
||||
|
||||
--theme-bold: 600;
|
||||
--theme-semibold: 500;
|
||||
--theme-regular: 400;
|
||||
|
||||
/* Font sizes for interactive applications (not rendered text content) */
|
||||
--theme-font-size-1: 24px;
|
||||
--theme-font-size-2: 16px;
|
||||
--theme-font-size-3: 14px;
|
||||
--theme-font-size-4: 13px;
|
||||
--theme-font-size-5: 12px;
|
||||
|
||||
--theme-line-height-1: 32px;
|
||||
--theme-line-height-2: 24px;
|
||||
--theme-line-height-3: 20px;
|
||||
--theme-line-height-4: 18px;
|
||||
--theme-line-height-5: 16px;
|
||||
|
||||
--scalar-app-header-height: 35px;
|
||||
}
|
||||
.scalar input::placeholder {
|
||||
color: var(--theme-color-3);
|
||||
}
|
||||
.scalar .scalar-app-header {
|
||||
width: 100%;
|
||||
z-index: 1000;
|
||||
padding: 6px 12px 6px 12px;
|
||||
border-radius: 0.25rem 0.25rem 0 0;
|
||||
font-size: 14px;
|
||||
height: var(--scalar-app-header-height);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
gap: 6px;
|
||||
}
|
||||
.scalar .scalar-api-client {
|
||||
max-height: calc(100dvh - (100px + var(--scalar-app-header-height))) !important;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.scalar-api-client__close {
|
||||
appearance: none;
|
||||
border: none;
|
||||
outline: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: transparent;
|
||||
color: var(--theme-color-1);
|
||||
font-size: var(--theme-small);
|
||||
font-weight: var(--theme-semibold);
|
||||
}
|
||||
.scalar-api-client__close:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
.scalar .scalar-app {
|
||||
background: var(--theme-background-3);
|
||||
height: calc(100dvh - 100px);
|
||||
max-width: 1280px;
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
opacity: 0;
|
||||
animation: scalarapiclientfadein 0.35s forwards;
|
||||
z-index: 1002;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
@keyframes scalarapiclientfadein {
|
||||
from {
|
||||
transform: translate3d(0, 20px, 0) scale(0.985);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translate3d(0, 0, 0) scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.scalar .scalar-app-exit {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background: rgba(0, 0, 0, 0.62);
|
||||
transition: all 0.3s ease-in-out;
|
||||
z-index: 1000;
|
||||
cursor: pointer;
|
||||
animation: scalardrawerexitfadein 0.35s forwards;
|
||||
}
|
||||
.scalar .scalar-app-exit:before {
|
||||
content: '\00d7';
|
||||
font-family: sans-serif;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
font-size: 30px;
|
||||
font-weight: 100;
|
||||
line-height: 50px;
|
||||
right: 12px;
|
||||
text-align: center;
|
||||
color: white;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.scalar .scalar-app-exit:hover:before {
|
||||
opacity: 1;
|
||||
}
|
||||
@keyframes scalardrawerexitfadein {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.scalar-container {
|
||||
overflow: hidden;
|
||||
visibility: visible;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 1001;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.scalar .url-form-input {
|
||||
min-height: auto !important;
|
||||
}
|
||||
|
||||
.scalar .scalar-container {
|
||||
line-height: normal;
|
||||
}
|
||||
.scalar .scalar-app-header span {
|
||||
color: var(--theme-color-3);
|
||||
}
|
||||
.scalar .scalar-app-header a {
|
||||
color: var(--theme-color-1);
|
||||
}
|
||||
.scalar .scalar-app-header a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.scalar-activate {
|
||||
width: fit-content;
|
||||
margin: 0px 0.75rem 0.75rem auto;
|
||||
line-height: 24px;
|
||||
font-size: 0.75rem;
|
||||
cursor: pointer;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.scalar-activate-button {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
color: var(--theme-color-blue);
|
||||
appearance: none;
|
||||
outline: none;
|
||||
border: none;
|
||||
background: transparent;
|
||||
}
|
||||
.scalar-activate-button {
|
||||
padding: 0 0.5rem;
|
||||
}
|
||||
.scalar-activate:hover .scalar-activate-button {
|
||||
background: var(--theme-background-3);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.scalar-app-loading {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.scalar .request-method {
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* Use :where to lower specificity to 0 */
|
||||
.scalar .custom-scroll {
|
||||
overflow-y: auto;
|
||||
scrollbar-color: transparent transparent;
|
||||
scrollbar-width: thin;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
@supports (-moz-appearance: none) {
|
||||
.scalar .custom-scroll {
|
||||
padding-right: 12px;
|
||||
}
|
||||
}
|
||||
.scalar .custom-scroll:hover {
|
||||
scrollbar-color: rgba(0, 0, 0, 0.24) transparent;
|
||||
}
|
||||
.dark .scalar .custom-scroll:hover {
|
||||
scrollbar-color: rgba(255, 255, 255, 0.24) transparent;
|
||||
}
|
||||
.scalar .custom-scroll:hover::-webkit-scrollbar-thumb {
|
||||
background: var(--theme-scrollbar-color, var(--default-theme-scrollbar-color));
|
||||
background-clip: content-box;
|
||||
border: 3px solid transparent;
|
||||
}
|
||||
.scalar .custom-scroll::-webkit-scrollbar-thumb:active {
|
||||
background: var(--theme-scrollbar-color-active, var(--default-theme-scrollbar-color-active));
|
||||
background-clip: content-box;
|
||||
border: 3px solid transparent;
|
||||
}
|
||||
.scalar .custom-scroll::-webkit-scrollbar-corner {
|
||||
background: transparent;
|
||||
}
|
||||
.scalar .custom-scroll::-webkit-scrollbar {
|
||||
height: 12px;
|
||||
width: 12px;
|
||||
}
|
||||
.scalar .custom-scroll::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
.scalar .custom-scroll::-webkit-scrollbar-thumb {
|
||||
border-radius: 20px;
|
||||
background: transparent;
|
||||
background-clip: content-box;
|
||||
border: 3px solid transparent;
|
||||
}
|
||||
@media (pointer: coarse) {
|
||||
.scalar .custom-scroll {
|
||||
padding-right: 12px;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user