[ci] format
This commit is contained in:
parent
6bc2cbe5e9
commit
f8c2d828bd
11 changed files with 41 additions and 48 deletions
|
@ -1,9 +1,4 @@
|
||||||
|
import type { APIContext, EndpointHandler, Params } from '../../@types/astro';
|
||||||
import type {
|
|
||||||
APIContext,
|
|
||||||
EndpointHandler,
|
|
||||||
Params
|
|
||||||
} from '../../@types/astro';
|
|
||||||
|
|
||||||
function getHandlerFromModule(mod: EndpointHandler, method: string) {
|
function getHandlerFromModule(mod: EndpointHandler, method: string) {
|
||||||
// If there was an exact match on `method`, return that function.
|
// If there was an exact match on `method`, return that function.
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { serializeListValue } from './util.js';
|
||||||
|
|
||||||
const HydrationDirectivesRaw = ['load', 'idle', 'media', 'visible', 'only'];
|
const HydrationDirectivesRaw = ['load', 'idle', 'media', 'visible', 'only'];
|
||||||
const HydrationDirectives = new Set(HydrationDirectivesRaw);
|
const HydrationDirectives = new Set(HydrationDirectivesRaw);
|
||||||
export const HydrationDirectiveProps = new Set(HydrationDirectivesRaw.map(n => `client:${n}`));
|
export const HydrationDirectiveProps = new Set(HydrationDirectivesRaw.map((n) => `client:${n}`));
|
||||||
|
|
||||||
export interface HydrationMetadata {
|
export interface HydrationMetadata {
|
||||||
directive: string;
|
directive: string;
|
||||||
|
@ -72,7 +72,9 @@ export function extractDirectives(inputProps: Record<string | number, any>): Ext
|
||||||
// throw an error if an invalid hydration directive was provided
|
// throw an error if an invalid hydration directive was provided
|
||||||
if (!HydrationDirectives.has(extracted.hydration.directive)) {
|
if (!HydrationDirectives.has(extracted.hydration.directive)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Error: invalid hydration directive "${key}". Supported hydration methods: ${Array.from(HydrationDirectiveProps).join(', ')}`
|
`Error: invalid hydration directive "${key}". Supported hydration methods: ${Array.from(
|
||||||
|
HydrationDirectiveProps
|
||||||
|
).join(', ')}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
export { createAstro } from './astro-global.js';
|
||||||
|
export { renderEndpoint } from './endpoint.js';
|
||||||
export {
|
export {
|
||||||
escapeHTML,
|
escapeHTML,
|
||||||
HTMLString,
|
HTMLString,
|
||||||
|
@ -6,32 +8,29 @@ export {
|
||||||
} from './escape.js';
|
} from './escape.js';
|
||||||
export type { Metadata } from './metadata';
|
export type { Metadata } from './metadata';
|
||||||
export { createMetadata } from './metadata.js';
|
export { createMetadata } from './metadata.js';
|
||||||
export type { AstroComponentFactory, RenderInstruction } from './render/index.js';
|
|
||||||
import type { AstroComponentFactory } from './render/index.js';
|
|
||||||
|
|
||||||
import { Renderer } from './render/index.js';
|
|
||||||
import { markHTMLString } from './escape.js';
|
|
||||||
|
|
||||||
export { createAstro } from './astro-global.js';
|
|
||||||
export {
|
export {
|
||||||
addAttribute,
|
addAttribute,
|
||||||
voidElementNames,
|
|
||||||
defineScriptVars,
|
defineScriptVars,
|
||||||
|
Fragment,
|
||||||
maybeRenderHead,
|
maybeRenderHead,
|
||||||
renderAstroComponent,
|
renderAstroComponent,
|
||||||
renderComponent,
|
renderComponent,
|
||||||
|
Renderer as Renderer,
|
||||||
renderHead,
|
renderHead,
|
||||||
renderHTMLElement,
|
renderHTMLElement,
|
||||||
renderPage,
|
renderPage,
|
||||||
renderSlot,
|
renderSlot,
|
||||||
renderTemplate,
|
|
||||||
renderTemplate as render,
|
renderTemplate as render,
|
||||||
|
renderTemplate,
|
||||||
renderToString,
|
renderToString,
|
||||||
stringifyChunk,
|
stringifyChunk,
|
||||||
Fragment,
|
voidElementNames,
|
||||||
Renderer as Renderer
|
|
||||||
} from './render/index.js';
|
} from './render/index.js';
|
||||||
export { renderEndpoint } from './endpoint.js';
|
export type { AstroComponentFactory, RenderInstruction } from './render/index.js';
|
||||||
|
import type { AstroComponentFactory } from './render/index.js';
|
||||||
|
|
||||||
|
import { markHTMLString } from './escape.js';
|
||||||
|
import { Renderer } from './render/index.js';
|
||||||
|
|
||||||
import { addAttribute } from './render/index.js';
|
import { addAttribute } from './render/index.js';
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
import { escapeHTML, HTMLString, markHTMLString } from '../escape.js';
|
||||||
import { AstroComponent, renderAstroComponent } from './astro.js';
|
import { AstroComponent, renderAstroComponent } from './astro.js';
|
||||||
import { markHTMLString, HTMLString, escapeHTML } from '../escape.js';
|
|
||||||
import { stringifyChunk } from './common.js';
|
import { stringifyChunk } from './common.js';
|
||||||
|
|
||||||
export async function* renderChild(child: any): AsyncIterable<any> {
|
export async function* renderChild(child: any): AsyncIterable<any> {
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
import type { SSRResult } from '../../../@types/astro';
|
import type { SSRResult } from '../../../@types/astro';
|
||||||
import type { RenderInstruction } from './types';
|
|
||||||
import type { AstroComponentFactory } from './index';
|
import type { AstroComponentFactory } from './index';
|
||||||
|
import type { RenderInstruction } from './types';
|
||||||
|
|
||||||
import { HydrationDirectiveProps } from '../hydration.js';
|
|
||||||
import { stringifyChunk } from './common.js';
|
|
||||||
import { markHTMLString } from '../escape.js';
|
import { markHTMLString } from '../escape.js';
|
||||||
|
import { HydrationDirectiveProps } from '../hydration.js';
|
||||||
import { renderChild } from './any.js';
|
import { renderChild } from './any.js';
|
||||||
|
import { stringifyChunk } from './common.js';
|
||||||
|
|
||||||
// In dev mode, check props and make sure they are valid for an Astro component
|
// In dev mode, check props and make sure they are valid for an Astro component
|
||||||
function validateComponentProps(props: any, displayName: string) {
|
function validateComponentProps(props: any, displayName: string) {
|
||||||
if(import.meta.env?.DEV && props != null) {
|
if (import.meta.env?.DEV && props != null) {
|
||||||
for(const prop of Object.keys(props)) {
|
for (const prop of Object.keys(props)) {
|
||||||
if(HydrationDirectiveProps.has(prop)) {
|
if (HydrationDirectiveProps.has(prop)) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.warn(`You are attempting to render <${displayName} ${prop} />, but ${displayName} is an Astro component. Astro components do not render in the client and should not have a hydration directive. Please use a framework component for client rendering.`);
|
console.warn(
|
||||||
|
`You are attempting to render <${displayName} ${prop} />, but ${displayName} is an Astro component. Astro components do not render in the client and should not have a hydration directive. Please use a framework component for client rendering.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,12 @@ import {
|
||||||
determineIfNeedsHydrationScript,
|
determineIfNeedsHydrationScript,
|
||||||
determinesIfNeedsDirectiveScript,
|
determinesIfNeedsDirectiveScript,
|
||||||
getPrescripts,
|
getPrescripts,
|
||||||
PrescriptType,
|
PrescriptType,
|
||||||
} from '../scripts.js';
|
} from '../scripts.js';
|
||||||
|
|
||||||
export const Fragment = Symbol.for('astro:fragment');
|
export const Fragment = Symbol.for('astro:fragment');
|
||||||
export const Renderer = Symbol.for('astro:renderer');
|
export const Renderer = Symbol.for('astro:renderer');
|
||||||
|
|
||||||
|
|
||||||
// Rendering produces either marked strings of HTML or instructions for hydration.
|
// Rendering produces either marked strings of HTML or instructions for hydration.
|
||||||
// These directive instructions bubble all the way up to renderPage so that we
|
// These directive instructions bubble all the way up to renderPage so that we
|
||||||
// can ensure they are added only once, and as soon as possible.
|
// can ensure they are added only once, and as soon as possible.
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
import type {
|
import type { AstroComponentMetadata, SSRLoadedRenderer, SSRResult } from '../../../@types/astro';
|
||||||
AstroComponentMetadata,
|
|
||||||
SSRLoadedRenderer,
|
|
||||||
SSRResult,
|
|
||||||
} from '../../../@types/astro';
|
|
||||||
import type { RenderInstruction } from './types.js';
|
import type { RenderInstruction } from './types.js';
|
||||||
|
|
||||||
|
import { markHTMLString } from '../escape.js';
|
||||||
import { extractDirectives, generateHydrateScript } from '../hydration.js';
|
import { extractDirectives, generateHydrateScript } from '../hydration.js';
|
||||||
import { serializeProps } from '../serialize.js';
|
import { serializeProps } from '../serialize.js';
|
||||||
import { shorthash } from '../shorthash.js';
|
import { shorthash } from '../shorthash.js';
|
||||||
import { Fragment, Renderer } from './common.js';
|
|
||||||
import { markHTMLString } from '../escape.js';
|
|
||||||
import { renderSlot } from './any.js';
|
import { renderSlot } from './any.js';
|
||||||
import { renderToIterable, renderAstroComponent, renderTemplate } from './astro.js';
|
import { renderAstroComponent, renderTemplate, renderToIterable } from './astro.js';
|
||||||
|
import { Fragment, Renderer } from './common.js';
|
||||||
import { componentIsHTMLElement, renderHTMLElement } from './dom.js';
|
import { componentIsHTMLElement, renderHTMLElement } from './dom.js';
|
||||||
import { formatList, internalSpreadAttributes, renderElement, voidElementNames } from './util.js';
|
import { formatList, internalSpreadAttributes, renderElement, voidElementNames } from './util.js';
|
||||||
|
|
||||||
|
@ -38,10 +34,10 @@ function getComponentType(Component: unknown): ComponentType {
|
||||||
if (Component === Fragment) {
|
if (Component === Fragment) {
|
||||||
return 'fragment';
|
return 'fragment';
|
||||||
}
|
}
|
||||||
if(Component && typeof Component === 'object' && (Component as any)['astro:html']) {
|
if (Component && typeof Component === 'object' && (Component as any)['astro:html']) {
|
||||||
return 'html';
|
return 'html';
|
||||||
}
|
}
|
||||||
if(Component && (Component as any).isAstroComponentFactory) {
|
if (Component && (Component as any).isAstroComponentFactory) {
|
||||||
return 'astro-factory';
|
return 'astro-factory';
|
||||||
}
|
}
|
||||||
return 'unknown';
|
return 'unknown';
|
||||||
|
@ -56,7 +52,7 @@ export async function renderComponent(
|
||||||
): Promise<string | AsyncIterable<string | RenderInstruction>> {
|
): Promise<string | AsyncIterable<string | RenderInstruction>> {
|
||||||
Component = await Component;
|
Component = await Component;
|
||||||
|
|
||||||
switch(getComponentType(Component)) {
|
switch (getComponentType(Component)) {
|
||||||
case 'fragment': {
|
case 'fragment': {
|
||||||
const children = await renderSlot(result, slots?.default);
|
const children = await renderSlot(result, slots?.default);
|
||||||
if (children == null) {
|
if (children == null) {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import { renderTemplate } from './astro.js';
|
import { renderTemplate } from './astro.js';
|
||||||
|
|
||||||
export type { RenderInstruction } from './types';
|
|
||||||
export { renderSlot } from './any.js';
|
export { renderSlot } from './any.js';
|
||||||
export { renderTemplate, renderAstroComponent, renderToString } from './astro.js';
|
export { renderAstroComponent, renderTemplate, renderToString } from './astro.js';
|
||||||
export { stringifyChunk, Fragment, Renderer } from './common.js';
|
export { Fragment, Renderer, stringifyChunk } from './common.js';
|
||||||
export { renderComponent } from './component.js';
|
export { renderComponent } from './component.js';
|
||||||
export { renderHTMLElement } from './dom.js';
|
export { renderHTMLElement } from './dom.js';
|
||||||
export { renderHead, maybeRenderHead } from './head.js';
|
export { maybeRenderHead, renderHead } from './head.js';
|
||||||
export { renderPage } from './page.js';
|
export { renderPage } from './page.js';
|
||||||
|
export type { RenderInstruction } from './types';
|
||||||
export { addAttribute, defineScriptVars, voidElementNames } from './util.js';
|
export { addAttribute, defineScriptVars, voidElementNames } from './util.js';
|
||||||
|
|
||||||
// The callback passed to to $$createComponent
|
// The callback passed to to $$createComponent
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import type { SSRResult } from '../../../@types/astro';
|
import type { SSRResult } from '../../../@types/astro';
|
||||||
import type { AstroComponentFactory } from './index';
|
import type { AstroComponentFactory } from './index';
|
||||||
|
|
||||||
|
import { createResponse } from '../response.js';
|
||||||
import { isAstroComponent, renderAstroComponent } from './astro.js';
|
import { isAstroComponent, renderAstroComponent } from './astro.js';
|
||||||
import { stringifyChunk } from './common.js';
|
import { stringifyChunk } from './common.js';
|
||||||
import { renderComponent } from './component.js';
|
import { renderComponent } from './component.js';
|
||||||
import { maybeRenderHead } from './head.js';
|
import { maybeRenderHead } from './head.js';
|
||||||
import { createResponse } from '../response.js';
|
|
||||||
|
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { SSRResult } from '../../../@types/astro';
|
import type { SSRResult } from '../../../@types/astro';
|
||||||
import type { HydrationMetadata } from '../hydration.js';
|
import type { HydrationMetadata } from '../hydration.js';
|
||||||
|
|
||||||
export interface RenderInstruction {
|
export interface RenderInstruction {
|
||||||
type: 'directive';
|
type: 'directive';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import type { SSRElement } from '../../../@types/astro';
|
import type { SSRElement } from '../../../@types/astro';
|
||||||
|
|
||||||
import { markHTMLString, HTMLString } from '../escape.js';
|
import { HTMLString, markHTMLString } from '../escape.js';
|
||||||
import { serializeListValue } from '../util.js';
|
import { serializeListValue } from '../util.js';
|
||||||
|
|
||||||
export const voidElementNames =
|
export const voidElementNames =
|
||||||
|
|
Loading…
Reference in a new issue