toiljs 0.0.11 → 0.0.12
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 +2 -0
- package/build/cli/.tsbuildinfo +1 -1
- package/build/cli/configure.js +10 -4
- package/build/cli/create.js +58 -30
- package/build/cli/diagnostics.d.ts +55 -0
- package/build/cli/diagnostics.js +333 -0
- package/build/cli/doctor.d.ts +6 -0
- package/build/cli/doctor.js +249 -0
- package/build/cli/index.js +26 -0
- package/build/cli/proc.d.ts +5 -0
- package/build/cli/proc.js +20 -0
- package/build/cli/ui.d.ts +1 -0
- package/build/cli/ui.js +1 -0
- package/build/cli/update.d.ts +7 -0
- package/build/cli/update.js +117 -0
- package/build/cli/updates.d.ts +10 -0
- package/build/cli/updates.js +45 -0
- package/build/client/.tsbuildinfo +1 -1
- package/build/client/dev/error-overlay.js +1 -1
- package/build/client/head/metadata.js +3 -1
- package/build/client/index.d.ts +5 -1
- package/build/client/index.js +2 -0
- package/build/client/navigation/navigation.js +1 -1
- package/build/client/routing/Router.js +2 -2
- package/build/client/search/search.d.ts +26 -0
- package/build/client/search/search.js +101 -0
- package/build/client/search/use-page-search.d.ts +8 -0
- package/build/client/search/use-page-search.js +21 -0
- package/build/compiler/.tsbuildinfo +1 -1
- package/build/compiler/generate.js +26 -23
- package/build/compiler/index.d.ts +2 -0
- package/build/compiler/index.js +1 -0
- package/build/compiler/pages.d.ts +8 -0
- package/build/compiler/pages.js +37 -0
- package/build/compiler/plugin.js +3 -1
- package/build/compiler/prerender.d.ts +1 -0
- package/build/compiler/prerender.js +11 -5
- package/build/compiler/seo.js +10 -3
- package/build/io/.tsbuildinfo +1 -1
- package/examples/basic/client/components/Header.tsx +43 -41
- package/examples/basic/client/components/HoneycombBackground.tsx +223 -230
- package/examples/basic/client/public/index.html +18 -16
- package/examples/basic/client/routes/(legal)/privacy.tsx +18 -19
- package/examples/basic/client/routes/(legal)/terms.tsx +15 -16
- package/examples/basic/client/routes/about.tsx +21 -22
- package/examples/basic/client/routes/blog/[id].tsx +26 -18
- package/examples/basic/client/routes/features/actions.tsx +67 -67
- package/examples/basic/client/routes/features/error/index.tsx +27 -27
- package/examples/basic/client/routes/features/head.tsx +38 -38
- package/examples/basic/client/routes/features/index.tsx +83 -75
- package/examples/basic/client/routes/features/realtime.tsx +34 -32
- package/examples/basic/client/routes/features/script.tsx +31 -31
- package/examples/basic/client/routes/features/seo.tsx +39 -39
- package/examples/basic/client/routes/features/template/index.tsx +20 -20
- package/examples/basic/client/routes/features/template/template.tsx +16 -18
- package/examples/basic/client/routes/gallery/@modal/(.)photo/[id].tsx +23 -23
- package/examples/basic/client/routes/gallery/index.tsx +42 -42
- package/examples/basic/client/routes/gallery/photo/[id].tsx +18 -18
- package/examples/basic/client/routes/get-started.tsx +157 -84
- package/examples/basic/client/routes/index.tsx +137 -96
- package/examples/basic/client/routes/loader-demo/index.tsx +59 -52
- package/examples/basic/client/routes/search.tsx +61 -0
- package/examples/basic/client/routes/test.tsx +7 -8
- package/examples/basic/client/styles/main.css +624 -552
- package/package.json +2 -2
- package/presets/eslint.js +10 -3
- package/src/cli/configure.ts +363 -353
- package/src/cli/create.ts +563 -530
- package/src/cli/diagnostics.ts +421 -0
- package/src/cli/doctor.ts +318 -0
- package/src/cli/features.ts +166 -160
- package/src/cli/index.ts +242 -211
- package/src/cli/proc.ts +30 -0
- package/src/cli/ui.ts +111 -103
- package/src/cli/update.ts +150 -0
- package/src/cli/updates.ts +69 -0
- package/src/client/components/Image.tsx +91 -89
- package/src/client/dev/error-overlay.tsx +193 -197
- package/src/client/head/metadata.ts +94 -92
- package/src/client/index.ts +79 -64
- package/src/client/navigation/Link.tsx +94 -100
- package/src/client/navigation/navigation.ts +215 -218
- package/src/client/routing/Router.tsx +210 -193
- package/src/client/routing/hooks.ts +110 -114
- package/src/client/routing/lazy.ts +77 -81
- package/src/client/search/search.ts +189 -0
- package/src/client/search/use-page-search.ts +73 -0
- package/src/compiler/config.ts +173 -171
- package/src/compiler/fonts.ts +89 -87
- package/src/compiler/generate.ts +378 -373
- package/src/compiler/image-report.ts +88 -85
- package/src/compiler/index.ts +2 -0
- package/src/compiler/pages.ts +70 -0
- package/src/compiler/plugin.ts +51 -47
- package/src/compiler/prerender.ts +152 -130
- package/src/compiler/routes.ts +132 -131
- package/src/compiler/seo.ts +381 -356
- package/src/compiler/vite.ts +155 -145
- package/src/io/FastSet.ts +99 -96
- package/test/configure.test.ts +94 -90
- package/test/doctor.test.ts +140 -0
- package/test/dom/Image.test.tsx +73 -46
- package/test/dom/Script.test.tsx +48 -45
- package/test/dom/action.test.tsx +146 -129
- package/test/dom/error-overlay.test.tsx +44 -44
- package/test/dom/loader.test.tsx +2 -2
- package/test/dom/revalidate.test.tsx +1 -1
- package/test/dom/route-head.test.tsx +1 -2
- package/test/dom/slot.test.tsx +131 -109
- package/test/dom/view-transitions.test.tsx +53 -51
- package/test/features.test.ts +149 -142
- package/test/fonts.test.ts +28 -26
- package/test/head.test.ts +45 -35
- package/test/metadata.test.ts +42 -41
- package/test/pages.test.ts +105 -0
- package/test/prerender.test.ts +54 -46
- package/test/search.test.ts +114 -0
- package/test/seo.test.ts +164 -142
- package/test/update.test.ts +44 -0
package/src/client/index.ts
CHANGED
|
@@ -1,64 +1,79 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* toiljs client runtime, published as `toiljs/client`. Re-exports the router (mount/Router/Link),
|
|
3
|
-
* navigation hooks, prefetching, and the route types consumed by the compiler-generated entry.
|
|
4
|
-
* Zero imports needed in user route files beyond this package.
|
|
5
|
-
*
|
|
6
|
-
* Internals are split by concern: route `types`, history-based `navigation`, the params
|
|
7
|
-
* `params-context` + `hooks`, `lazy` component resolution, the `Link`/`Router` components,
|
|
8
|
-
* `mount`, `match` (pure matcher), `prefetch` (link prefetcher), and `channel` (WebSocket helper).
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export { mount } from './routing/mount.js';
|
|
12
|
-
export { Router } from './routing/Router.js';
|
|
13
|
-
export { Link } from './navigation/Link.js';
|
|
14
|
-
export type { LinkProps } from './navigation/Link.js';
|
|
15
|
-
export { NavLink, matchActive } from './navigation/NavLink.js';
|
|
16
|
-
export type { NavLinkProps, NavLinkState } from './navigation/NavLink.js';
|
|
17
|
-
export { navigate, back, forward, refresh, setViewTransitions } from './navigation/navigation.js';
|
|
18
|
-
export type { NavigateOptions } from './navigation/navigation.js';
|
|
19
|
-
export {
|
|
20
|
-
useParams,
|
|
21
|
-
useNavigate,
|
|
22
|
-
useLocation,
|
|
23
|
-
usePathname,
|
|
24
|
-
useSearchParams,
|
|
25
|
-
useRouter,
|
|
26
|
-
useNavigationPending,
|
|
27
|
-
} from './routing/hooks.js';
|
|
28
|
-
export type { RouterInstance } from './routing/hooks.js';
|
|
29
|
-
export { useLoaderData, revalidate, invalidateLoaderData } from './routing/loader.js';
|
|
30
|
-
export type { LoaderArgs, LoaderFunction, LoaderData, Revalidate } from './routing/loader.js';
|
|
31
|
-
export { useAction } from './routing/action.js';
|
|
32
|
-
export type {
|
|
33
|
-
UseActionOptions,
|
|
34
|
-
ActionState,
|
|
35
|
-
ActionHandle,
|
|
36
|
-
RevalidateTarget,
|
|
37
|
-
} from './routing/action.js';
|
|
38
|
-
export { prefetch } from './navigation/prefetch.js';
|
|
39
|
-
export type {
|
|
40
|
-
RouteDef,
|
|
41
|
-
LayoutLoader,
|
|
42
|
-
LayoutComponentLoader,
|
|
43
|
-
NotFoundLoader,
|
|
44
|
-
RouteErrorProps,
|
|
45
|
-
Register,
|
|
46
|
-
RoutePath,
|
|
47
|
-
Href,
|
|
48
|
-
} from './types.js';
|
|
49
|
-
export { matchRoute } from './routing/match.js';
|
|
50
|
-
export type { RouteParams } from './routing/match.js';
|
|
51
|
-
export { connectChannel, useChannel, resolveChannelUrl } from './channel/channel.js';
|
|
52
|
-
export type { Channel, ChannelOptions, ChannelHook, ChannelData } from './channel/channel.js';
|
|
53
|
-
export { useHead, useTitle, Head, mergeHead } from './head/head.js';
|
|
54
|
-
export type { HeadSpec, MetaTag, LinkTag, ResolvedHead } from './head/head.js';
|
|
55
|
-
export { resolveMetadata } from './head/metadata.js';
|
|
56
|
-
export type {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
export
|
|
63
|
-
export {
|
|
64
|
-
|
|
1
|
+
/**
|
|
2
|
+
* toiljs client runtime, published as `toiljs/client`. Re-exports the router (mount/Router/Link),
|
|
3
|
+
* navigation hooks, prefetching, and the route types consumed by the compiler-generated entry.
|
|
4
|
+
* Zero imports needed in user route files beyond this package.
|
|
5
|
+
*
|
|
6
|
+
* Internals are split by concern: route `types`, history-based `navigation`, the params
|
|
7
|
+
* `params-context` + `hooks`, `lazy` component resolution, the `Link`/`Router` components,
|
|
8
|
+
* `mount`, `match` (pure matcher), `prefetch` (link prefetcher), and `channel` (WebSocket helper).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export { mount } from './routing/mount.js';
|
|
12
|
+
export { Router } from './routing/Router.js';
|
|
13
|
+
export { Link } from './navigation/Link.js';
|
|
14
|
+
export type { LinkProps } from './navigation/Link.js';
|
|
15
|
+
export { NavLink, matchActive } from './navigation/NavLink.js';
|
|
16
|
+
export type { NavLinkProps, NavLinkState } from './navigation/NavLink.js';
|
|
17
|
+
export { navigate, back, forward, refresh, setViewTransitions } from './navigation/navigation.js';
|
|
18
|
+
export type { NavigateOptions } from './navigation/navigation.js';
|
|
19
|
+
export {
|
|
20
|
+
useParams,
|
|
21
|
+
useNavigate,
|
|
22
|
+
useLocation,
|
|
23
|
+
usePathname,
|
|
24
|
+
useSearchParams,
|
|
25
|
+
useRouter,
|
|
26
|
+
useNavigationPending,
|
|
27
|
+
} from './routing/hooks.js';
|
|
28
|
+
export type { RouterInstance } from './routing/hooks.js';
|
|
29
|
+
export { useLoaderData, revalidate, invalidateLoaderData } from './routing/loader.js';
|
|
30
|
+
export type { LoaderArgs, LoaderFunction, LoaderData, Revalidate } from './routing/loader.js';
|
|
31
|
+
export { useAction } from './routing/action.js';
|
|
32
|
+
export type {
|
|
33
|
+
UseActionOptions,
|
|
34
|
+
ActionState,
|
|
35
|
+
ActionHandle,
|
|
36
|
+
RevalidateTarget,
|
|
37
|
+
} from './routing/action.js';
|
|
38
|
+
export { prefetch } from './navigation/prefetch.js';
|
|
39
|
+
export type {
|
|
40
|
+
RouteDef,
|
|
41
|
+
LayoutLoader,
|
|
42
|
+
LayoutComponentLoader,
|
|
43
|
+
NotFoundLoader,
|
|
44
|
+
RouteErrorProps,
|
|
45
|
+
Register,
|
|
46
|
+
RoutePath,
|
|
47
|
+
Href,
|
|
48
|
+
} from './types.js';
|
|
49
|
+
export { matchRoute } from './routing/match.js';
|
|
50
|
+
export type { RouteParams } from './routing/match.js';
|
|
51
|
+
export { connectChannel, useChannel, resolveChannelUrl } from './channel/channel.js';
|
|
52
|
+
export type { Channel, ChannelOptions, ChannelHook, ChannelData } from './channel/channel.js';
|
|
53
|
+
export { useHead, useTitle, Head, mergeHead } from './head/head.js';
|
|
54
|
+
export type { HeadSpec, MetaTag, LinkTag, ResolvedHead } from './head/head.js';
|
|
55
|
+
export { resolveMetadata } from './head/metadata.js';
|
|
56
|
+
export type {
|
|
57
|
+
Metadata,
|
|
58
|
+
GenerateMetadata,
|
|
59
|
+
GenerateMetadataArgs,
|
|
60
|
+
OpenGraph,
|
|
61
|
+
} from './head/metadata.js';
|
|
62
|
+
export { searchPages, registerPages, getPages, pagePath } from './search/search.js';
|
|
63
|
+
export type {
|
|
64
|
+
PageMeta,
|
|
65
|
+
PageSearchResult,
|
|
66
|
+
PageSearchOptions,
|
|
67
|
+
SearchField,
|
|
68
|
+
SearchHints,
|
|
69
|
+
} from './search/search.js';
|
|
70
|
+
export { usePageSearch } from './search/use-page-search.js';
|
|
71
|
+
export type { PageSearch } from './search/use-page-search.js';
|
|
72
|
+
export { Image } from './components/Image.js';
|
|
73
|
+
export type { ImageProps } from './components/Image.js';
|
|
74
|
+
export { Script } from './components/Script.js';
|
|
75
|
+
export type { ScriptProps, ScriptStrategy } from './components/Script.js';
|
|
76
|
+
export { Form } from './components/Form.js';
|
|
77
|
+
export type { FormProps } from './components/Form.js';
|
|
78
|
+
export { Slot } from './components/Slot.js';
|
|
79
|
+
export type { SlotProps } from './components/Slot.js';
|
|
@@ -1,100 +1,94 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
onPointerEnter={handlePointerEnter}
|
|
96
|
-
onFocus={handleFocus}>
|
|
97
|
-
{children}
|
|
98
|
-
</a>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
1
|
+
import type { ComponentPropsWithRef, FocusEvent, MouseEvent, PointerEvent, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { navigate } from './navigation.js';
|
|
4
|
+
import { prefetch } from './prefetch.js';
|
|
5
|
+
import type { Href } from '../types.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for {@link Link}: every standard `<a>` attribute (`rel`, `target`, `download`,
|
|
9
|
+
* `referrerPolicy`, `hrefLang`, `className`, `style`, `ref`, `data-*`, `aria-*`, event handlers …)
|
|
10
|
+
* plus toil's `replace` and `prefetch` controls. `href` is required and typed to the project's routes.
|
|
11
|
+
*/
|
|
12
|
+
export interface LinkProps extends Omit<ComponentPropsWithRef<'a'>, 'href'> {
|
|
13
|
+
/** Destination. Same-origin hrefs navigate client-side; external / `target` / `download` / `#hash` use the browser. */
|
|
14
|
+
href: Href;
|
|
15
|
+
/** Replace the current history entry instead of pushing a new one. Default `false`. */
|
|
16
|
+
replace?: boolean;
|
|
17
|
+
/** Scroll to top after navigating. Default `true`. */
|
|
18
|
+
scroll?: boolean;
|
|
19
|
+
/** Prefetch the route chunk on hover/focus. Default `true`; `false` opts this link out. */
|
|
20
|
+
prefetch?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** True for cross-origin, opaque (`mailto:` / `tel:`), or otherwise non-same-origin hrefs. */
|
|
24
|
+
function isExternalHref(href: string): boolean {
|
|
25
|
+
try {
|
|
26
|
+
return new URL(href, window.location.href).origin !== window.location.origin;
|
|
27
|
+
} catch {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Client-side navigation link. Forwards all anchor attributes to the underlying `<a>`, and
|
|
34
|
+
* prefetches the target route's chunk on hover/focus. Intercepts only plain same-origin clicks ,
|
|
35
|
+
* modified clicks, `target=_blank`, `download`, in-page `#hash`, and external URLs fall through to
|
|
36
|
+
* native browser behavior.
|
|
37
|
+
*/
|
|
38
|
+
export function Link(props: LinkProps): ReactNode {
|
|
39
|
+
const {
|
|
40
|
+
href,
|
|
41
|
+
replace = false,
|
|
42
|
+
scroll = true,
|
|
43
|
+
prefetch: prefetchProp = true,
|
|
44
|
+
onClick,
|
|
45
|
+
onPointerEnter,
|
|
46
|
+
onFocus,
|
|
47
|
+
children,
|
|
48
|
+
...rest
|
|
49
|
+
} = props;
|
|
50
|
+
|
|
51
|
+
const handleClick = (event: MouseEvent<HTMLAnchorElement>): void => {
|
|
52
|
+
onClick?.(event);
|
|
53
|
+
if (
|
|
54
|
+
event.defaultPrevented ||
|
|
55
|
+
event.button !== 0 ||
|
|
56
|
+
event.metaKey ||
|
|
57
|
+
event.ctrlKey ||
|
|
58
|
+
event.shiftKey ||
|
|
59
|
+
event.altKey ||
|
|
60
|
+
(rest.target !== undefined && rest.target !== '_self') ||
|
|
61
|
+
rest.download !== undefined ||
|
|
62
|
+
href.startsWith('#') ||
|
|
63
|
+
isExternalHref(href)
|
|
64
|
+
) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
navigate(href, { replace, scroll });
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const warm = (): void => {
|
|
72
|
+
if (prefetchProp) prefetch(href);
|
|
73
|
+
};
|
|
74
|
+
const handlePointerEnter = (event: PointerEvent<HTMLAnchorElement>): void => {
|
|
75
|
+
onPointerEnter?.(event);
|
|
76
|
+
warm();
|
|
77
|
+
};
|
|
78
|
+
const handleFocus = (event: FocusEvent<HTMLAnchorElement>): void => {
|
|
79
|
+
onFocus?.(event);
|
|
80
|
+
warm();
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<a
|
|
85
|
+
{...rest}
|
|
86
|
+
{...(prefetchProp ? {} : { 'data-no-prefetch': '' })}
|
|
87
|
+
href={href}
|
|
88
|
+
onClick={handleClick}
|
|
89
|
+
onPointerEnter={handlePointerEnter}
|
|
90
|
+
onFocus={handleFocus}>
|
|
91
|
+
{children}
|
|
92
|
+
</a>
|
|
93
|
+
);
|
|
94
|
+
}
|