feat: make virtualization configurable where the default is not using virtualization

This commit is contained in:
Putu Audi Pasuatmadi 2024-11-26 13:59:10 +08:00 committed by GitHub
parent 2e5c98e9fc
commit 80509a8ceb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 1 deletions

View File

@ -166,6 +166,12 @@ _Default: false_
If set to `true`, the API definition is considered untrusted and all HTML/Markdown is sanitized to prevent XSS.
### enableVirtualization
If set to `true`, the API documentation content will use virtualization. Virtualization only renders the API content when it is currently visible in user's viewport.
_Default: false_
## Theme settings
* `spacing`

View File

@ -14,6 +14,8 @@ import { ApiContentWrap, BackgroundStub, RedocWrap } from './styled.elements';
import { SearchBox } from '../SearchBox/SearchBox';
import { StoreProvider } from '../StoreBuilder';
import VirtualizedContent from '../Virtualization/VirtualizedContent';
import { ApiInfo } from '../ApiInfo/ApiInfo';
import { ContentItems } from '../ContentItems/ContentItems';
export interface RedocProps {
store: AppStore;
@ -56,7 +58,14 @@ export class Redoc extends React.Component<RedocProps> {
<SideMenu menu={menu} />
</StickyResponsiveSidebar>
<ApiContentWrap className="api-content">
{options.enableVirtualization ? (
<VirtualizedContent store={store} menu={menu} />
) : (
<>
<ApiInfo store={store} />
<ContentItems items={menu.items as any} />
</>
)}
</ApiContentWrap>
<BackgroundStub />
</RedocWrap>

View File

@ -79,6 +79,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"disableSearch": false,
"downloadDefinitionUrl": undefined,
"downloadFileName": undefined,
"enableVirtualization": false,
"enumSkipQuotes": false,
"expandDefaultServerVariables": false,
"expandResponses": {},
@ -351,6 +352,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"disableSearch": false,
"downloadDefinitionUrl": undefined,
"downloadFileName": undefined,
"enableVirtualization": false,
"enumSkipQuotes": false,
"expandDefaultServerVariables": false,
"expandResponses": {},
@ -610,6 +612,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"disableSearch": false,
"downloadDefinitionUrl": undefined,
"downloadFileName": undefined,
"enableVirtualization": false,
"enumSkipQuotes": false,
"expandDefaultServerVariables": false,
"expandResponses": {},
@ -931,6 +934,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"disableSearch": false,
"downloadDefinitionUrl": undefined,
"downloadFileName": undefined,
"enableVirtualization": false,
"enumSkipQuotes": false,
"expandDefaultServerVariables": false,
"expandResponses": {},
@ -1215,6 +1219,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"disableSearch": false,
"downloadDefinitionUrl": undefined,
"downloadFileName": undefined,
"enableVirtualization": false,
"enumSkipQuotes": false,
"expandDefaultServerVariables": false,
"expandResponses": {},
@ -1470,6 +1475,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"disableSearch": false,
"downloadDefinitionUrl": undefined,
"downloadFileName": undefined,
"enableVirtualization": false,
"enumSkipQuotes": false,
"expandDefaultServerVariables": false,
"expandResponses": {},
@ -1750,6 +1756,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"disableSearch": false,
"downloadDefinitionUrl": undefined,
"downloadFileName": undefined,
"enableVirtualization": false,
"enumSkipQuotes": false,
"expandDefaultServerVariables": false,
"expandResponses": {},
@ -2060,6 +2067,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"disableSearch": false,
"downloadDefinitionUrl": undefined,
"downloadFileName": undefined,
"enableVirtualization": false,
"enumSkipQuotes": false,
"expandDefaultServerVariables": false,
"expandResponses": {},
@ -2332,6 +2340,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"disableSearch": false,
"downloadDefinitionUrl": undefined,
"downloadFileName": undefined,
"enableVirtualization": false,
"enumSkipQuotes": false,
"expandDefaultServerVariables": false,
"expandResponses": {},
@ -2591,6 +2600,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"disableSearch": false,
"downloadDefinitionUrl": undefined,
"downloadFileName": undefined,
"enableVirtualization": false,
"enumSkipQuotes": false,
"expandDefaultServerVariables": false,
"expandResponses": {},

View File

@ -57,6 +57,8 @@ export interface RedocRawOptions {
hideFab?: boolean;
minCharacterLengthToInitSearch?: number;
showWebhookVerb?: boolean;
enableVirtualization?: boolean | string;
}
export function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean {
@ -259,6 +261,8 @@ export class RedocNormalizedOptions {
minCharacterLengthToInitSearch: number;
showWebhookVerb: boolean;
enableVirtualization: boolean;
nonce?: string;
constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) {
@ -338,5 +342,6 @@ export class RedocNormalizedOptions {
this.hideFab = argValueToBoolean(raw.hideFab);
this.minCharacterLengthToInitSearch = argValueToNumber(raw.minCharacterLengthToInitSearch) || 3;
this.showWebhookVerb = argValueToBoolean(raw.showWebhookVerb);
this.enableVirtualization = argValueToBoolean(raw.enableVirtualization);
}
}