-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rename satisfies to filter, add docs (#1249)
- Loading branch information
1 parent
f2697df
commit 10f6e58
Showing
70 changed files
with
1,553 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import type { JSX } from "react" | ||
import type { ApiGroup, ParsedJsDocPart } from "../../repo/jsdocGen.ts" | ||
import { apiDocsByGroup } from "./apiData.ts" | ||
import { CodeBlock } from "./CodeBlock.tsx" | ||
import { LocalFriendlyUrl } from "./LocalFriendlyUrl.tsx" | ||
|
||
export type ApiTableProps = { | ||
group: ApiGroup | ||
rows: JSX.Element[] | ||
} | ||
|
||
export const ApiTable = ({ group }: ApiTableProps) => ( | ||
<> | ||
<h2>{group}</h2> | ||
<div className="w-full overflow-x-auto"> | ||
<table className="w-full table-fixed border-collapse"> | ||
<colgroup> | ||
<col className="w-28" /> | ||
<col className="w-1/4" /> | ||
<col className="w-full" /> | ||
</colgroup> | ||
<ApiTableHeader /> | ||
<tbody> | ||
{apiDocsByGroup[group].map(props => ( | ||
<ApiTableRow key={props.name} {...props} /> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
</> | ||
) | ||
|
||
const ApiTableHeader = () => ( | ||
<thead> | ||
<tr> | ||
<th className="p-2 text-left align-top whitespace-nowrap w-auto min-w-[100px]"> | ||
Name | ||
</th> | ||
<th className="p-2 text-left align-top min-w-[200px]">Summary</th> | ||
<th className="p-2 text-left align-top">Example</th> | ||
</tr> | ||
</thead> | ||
) | ||
|
||
interface ApiTableRowProps { | ||
name: string | ||
summary: ParsedJsDocPart[] | ||
example?: string | ||
notes: ParsedJsDocPart[][] | ||
} | ||
|
||
const ApiTableRow = ({ name, summary, example, notes }: ApiTableRowProps) => ( | ||
<tr key={name}> | ||
<td className="p-2 align-top whitespace-nowrap w-auto">{name}</td> | ||
<td className="p-2 align-top">{JsDocParts(summary)}</td> | ||
<td className="p-2 align-top"> | ||
{notes.map((note, i) => ( | ||
<div key={i}>{JsDocParts(note)} </div> | ||
))} | ||
<ApiExample>{example}</ApiExample> | ||
</td> | ||
</tr> | ||
) | ||
|
||
const JsDocParts = (parts: readonly ParsedJsDocPart[]) => | ||
parts.map((part, i) => ( | ||
<span key={i} style={{ marginRight: "0.25em" }}> | ||
{part.kind === "link" ? | ||
<LocalFriendlyUrl url={part.url} key={i}> | ||
{part.value} | ||
</LocalFriendlyUrl> | ||
: part.kind === "reference" ? | ||
<a href={`#${part.value}`} key={i}> | ||
{part.value} | ||
</a> | ||
: part.kind === "tag" ? | ||
<p key={i}> | ||
{part.name} {JsDocParts(part.value)} | ||
</p> | ||
: <p | ||
style={{ display: "inline" }} | ||
key={i} | ||
dangerouslySetInnerHTML={{ | ||
__html: part.value | ||
.replace(/(\*\*|__)([^*_]+)\1/g, "<strong>$2</strong>") | ||
.replace(/(\*|_)([^*_]+)\1/g, "<em>$2</em>") | ||
}} | ||
/> | ||
} | ||
</span> | ||
)) | ||
|
||
interface ApiExampleProps { | ||
children: string | undefined | ||
} | ||
|
||
const ApiExample = ({ children }: ApiExampleProps) => | ||
children && ( | ||
<CodeBlock style={{ margin: 0 }} decorators={["@noErrors"]}> | ||
{children} | ||
</CodeBlock> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use client" | ||
import { useEffect, useState } from "react" | ||
|
||
export interface LocalFriendlyUrlProps { | ||
children: string | ||
url: string | ||
key?: string | number | undefined | ||
} | ||
|
||
export const LocalFriendlyUrl = (props: LocalFriendlyUrlProps) => { | ||
const [locallyAccessibleUrl, setLocallyAccessibleUrl] = useState(props.url) | ||
|
||
if (process.env.NODE_ENV === "development") { | ||
useEffect(() => { | ||
const devFriendlyUrl = new URL(props.url) | ||
devFriendlyUrl.protocol = "http:" | ||
devFriendlyUrl.host = window.location.host | ||
setLocallyAccessibleUrl(devFriendlyUrl.toString()) | ||
}, [props.url]) | ||
} | ||
|
||
return ( | ||
<a href={locallyAccessibleUrl} key={props.key}> | ||
{props.children} | ||
</a> | ||
) | ||
} |
Oops, something went wrong.