@travetto/doc 8.0.0-alpha.2 → 8.0.0-alpha.21
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/README.md +41 -31
- package/__index__.ts +3 -3
- package/package.json +5 -3
- package/src/jsx.ts +53 -19
- package/src/mapping/library.ts +7 -4
- package/src/mapping/module.ts +177 -61
- package/src/render/code-highlight.ts +3 -5
- package/src/render/context.ts +28 -13
- package/src/render/html.ts +63 -22
- package/src/render/markdown.ts +37 -11
- package/src/render/renderer.ts +26 -24
- package/src/types.ts +7 -8
- package/src/util/file.ts +37 -37
- package/src/util/package.ts +19 -13
- package/src/util/resolve.ts +11 -12
- package/src/util/run.ts +14 -10
- package/src/util/types.ts +1 -1
- package/support/cli.doc.ts +12 -11
- package/support/jsx-runtime.ts +26 -15
package/support/jsx-runtime.ts
CHANGED
|
@@ -1,33 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Class, castTo } from '@travetto/runtime';
|
|
2
2
|
|
|
3
3
|
type JSXChild = JSXElement | number | bigint | boolean | object | string;
|
|
4
4
|
type JSXProps = { children?: JSXChild | JSXChild[] | null };
|
|
5
5
|
|
|
6
|
-
export type JSXComponentFunction<P extends {} = {}> = (props: P & JSXProps, ...args: unknown[]) =>
|
|
6
|
+
export type JSXComponentFunction<P extends {} = {}> = (props: P & JSXProps, ...args: unknown[]) => JSXElement | null;
|
|
7
7
|
|
|
8
8
|
export const JSXRuntimeTag = Symbol.for('@travetto/doc:jsx-runtime');
|
|
9
|
-
export class JSXFragmentType {
|
|
9
|
+
export class JSXFragmentType {}
|
|
10
10
|
|
|
11
11
|
let id = 0;
|
|
12
12
|
|
|
13
13
|
/** Simple JSX Element */
|
|
14
|
-
export interface JSXElement<
|
|
15
|
-
T extends string | Class | JSXComponentFunction<P> = string | Class | JSXComponentFunction,
|
|
16
|
-
P extends {} = {},
|
|
17
|
-
> {
|
|
14
|
+
export interface JSXElement<T extends string | Class | JSXComponentFunction<P> = string | Class | JSXComponentFunction, P extends {} = {}> {
|
|
18
15
|
[JSXRuntimeTag]?: { id: number };
|
|
19
16
|
type: T;
|
|
20
17
|
key: string;
|
|
21
18
|
props: P & JSXProps;
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
export type ValidHtmlTags =
|
|
25
|
-
|
|
21
|
+
export type ValidHtmlTags =
|
|
22
|
+
| 'strong'
|
|
23
|
+
| 'em'
|
|
24
|
+
| 'br'
|
|
25
|
+
| 'hr'
|
|
26
|
+
| 'li'
|
|
27
|
+
| 'ul'
|
|
28
|
+
| 'ol'
|
|
29
|
+
| 'h2'
|
|
30
|
+
| 'h3'
|
|
31
|
+
| 'h4'
|
|
32
|
+
| 'td'
|
|
33
|
+
| 'tr'
|
|
34
|
+
| 'table'
|
|
35
|
+
| 'thead'
|
|
36
|
+
| 'tbody';
|
|
26
37
|
|
|
27
|
-
let createFrag: Function | undefined
|
|
38
|
+
let createFrag: Function | undefined;
|
|
28
39
|
|
|
29
40
|
export function createElement<T extends string | Class | JSXComponentFunction<P>, P extends {}>(
|
|
30
|
-
type: T,
|
|
41
|
+
type: T,
|
|
42
|
+
props: P & JSXProps
|
|
31
43
|
): JSXElement<T, P> {
|
|
32
44
|
type = castTo(type === createFrag ? JSXFragmentType : type);
|
|
33
45
|
return { [JSXRuntimeTag]: { id: (id += 1) }, type, key: '', props };
|
|
@@ -46,10 +58,9 @@ export function isJSXElement(value: unknown): value is JSXElement {
|
|
|
46
58
|
return value !== undefined && value !== null && typeof value === 'object' && JSXRuntimeTag in value;
|
|
47
59
|
}
|
|
48
60
|
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
50
61
|
export namespace JSX {
|
|
51
|
-
export interface Element extends JSXElement {
|
|
52
|
-
export interface IntrinsicAttributes extends JSXProps {
|
|
62
|
+
export interface Element extends JSXElement {}
|
|
63
|
+
export interface IntrinsicAttributes extends JSXProps {}
|
|
53
64
|
type BasicElements = { [K in ValidHtmlTags]: IntrinsicAttributes };
|
|
54
|
-
export interface IntrinsicElements extends BasicElements {
|
|
65
|
+
export interface IntrinsicElements extends BasicElements {}
|
|
55
66
|
}
|