eddev 2.0.0-beta.9 → 2.0.0-beta.91

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.
Files changed (210) hide show
  1. package/dist/app/entry/HydrationOverlay.d.ts +1 -0
  2. package/dist/app/entry/HydrationOverlay.js +2 -0
  3. package/dist/app/entry/MetaTags.d.ts +7 -0
  4. package/dist/app/entry/MetaTags.js +17 -0
  5. package/dist/app/entry/boot-admin.js +11 -6
  6. package/dist/app/entry/hydration-script.d.ts +1 -0
  7. package/dist/app/entry/hydration-script.js +18 -0
  8. package/dist/app/entry/spa-root.js +4 -5
  9. package/dist/app/entry/ssr-root-client.d.ts +3 -1
  10. package/dist/app/entry/ssr-root-client.js +24 -8
  11. package/dist/app/entry/ssr-root.d.ts +5 -4
  12. package/dist/app/entry/ssr-root.js +21 -20
  13. package/dist/app/lib/admin/index.d.ts +2 -2
  14. package/dist/app/lib/admin/index.js +2 -2
  15. package/dist/app/lib/admin/installFieldTypes.js +1 -1
  16. package/dist/app/lib/admin/runWidgets.js +1 -1
  17. package/dist/app/lib/blocks/ContentBlocks.d.ts +1 -1
  18. package/dist/app/lib/blocks/ContentBlocks.js +5 -5
  19. package/dist/app/lib/blocks/EditableText.d.ts +1 -1
  20. package/dist/app/lib/blocks/EditableText.js +3 -3
  21. package/dist/app/lib/blocks/InnerBlocks.d.ts +13 -3
  22. package/dist/app/lib/blocks/InnerBlocks.js +13 -5
  23. package/dist/app/lib/blocks/block-utils.d.ts +2 -2
  24. package/dist/app/lib/blocks/block-utils.js +2 -2
  25. package/dist/app/lib/blocks/editor/EditorHighlights.d.ts +7 -0
  26. package/dist/app/lib/blocks/editor/EditorHighlights.js +130 -0
  27. package/dist/app/lib/blocks/editor/EditorSupport.js +4 -5
  28. package/dist/app/lib/blocks/editor/ErrorBoundaryEditor.d.ts +1 -1
  29. package/dist/app/lib/blocks/editor/editor-config.d.ts +17 -4
  30. package/dist/app/lib/blocks/editor/editor-config.js +21 -9
  31. package/dist/app/lib/blocks/editor/installGutenbergHooks.js +20 -14
  32. package/dist/app/lib/blocks/editor/root-blocks.d.ts +6 -0
  33. package/dist/app/lib/blocks/editor/root-blocks.js +30 -0
  34. package/dist/app/lib/blocks/editor/usePostEditor.d.ts +1 -1
  35. package/dist/app/lib/blocks/index.d.ts +9 -9
  36. package/dist/app/lib/blocks/index.js +9 -9
  37. package/dist/app/lib/blocks/inline-editing.d.ts +1 -1
  38. package/dist/app/lib/blocks/inline-editing.js +7 -5
  39. package/dist/app/lib/devtools/components/BreakpointIndicator.js +1 -1
  40. package/dist/app/lib/devtools/components/DevUI.js +4 -3
  41. package/dist/app/lib/devtools/components/GridIndicator.d.ts +1 -0
  42. package/dist/app/lib/devtools/components/GridIndicator.js +29 -0
  43. package/dist/app/lib/devtools/hooks/usePersistState.d.ts +1 -1
  44. package/dist/app/lib/devtools/hooks/usePersistState.js +11 -2
  45. package/dist/app/lib/devtools/hooks/useTailwind.d.ts +1014 -1014
  46. package/dist/app/lib/devtools/hooks/useTailwind.js +1 -1
  47. package/dist/app/lib/devtools/index.d.ts +1 -1
  48. package/dist/app/lib/devtools/index.js +1 -1
  49. package/dist/app/lib/devtools/loader.js +8 -7
  50. package/dist/app/lib/devtools/useQueryDebug.d.ts +7 -1
  51. package/dist/app/lib/devtools/useQueryDebug.js +5 -8
  52. package/dist/app/lib/dynamic/dynamic.d.ts +1 -1
  53. package/dist/app/lib/dynamic/dynamic.js +5 -1
  54. package/dist/app/lib/dynamic/index.d.ts +1 -1
  55. package/dist/app/lib/dynamic/index.js +1 -1
  56. package/dist/app/lib/hooks/index.d.ts +4 -5
  57. package/dist/app/lib/hooks/index.js +4 -5
  58. package/dist/app/lib/hooks/queryUtils.d.ts +37 -3
  59. package/dist/app/lib/hooks/queryUtils.js +66 -26
  60. package/dist/app/lib/hooks/useAppData.js +1 -1
  61. package/dist/app/lib/hooks/useRPC.d.ts +0 -4
  62. package/dist/app/lib/hooks/useRPC.js +1 -8
  63. package/dist/app/lib/internal/finalize-rpc.d.ts +17 -0
  64. package/dist/app/lib/internal/finalize-rpc.js +3 -0
  65. package/dist/app/lib/internal/index.d.ts +5 -4
  66. package/dist/app/lib/internal/index.js +5 -4
  67. package/dist/app/lib/internal/read-admin-manifest.d.ts +1 -1
  68. package/dist/app/lib/legacy-stitches/createStitches.d.ts +21 -21
  69. package/dist/app/lib/legacy-stitches/createStitches.js +1 -1
  70. package/dist/app/lib/legacy-stitches/index.d.ts +1 -1
  71. package/dist/app/lib/legacy-stitches/index.js +1 -1
  72. package/dist/app/lib/routing/components/BackButton.d.ts +49 -0
  73. package/dist/app/lib/routing/components/BackButton.js +47 -0
  74. package/dist/app/lib/routing/components/BrowserRouter.d.ts +4 -1
  75. package/dist/app/lib/routing/components/BrowserRouter.js +95 -19
  76. package/dist/app/lib/routing/components/ClientOnly.d.ts +1 -1
  77. package/dist/app/lib/routing/components/ClientOnly.js +1 -1
  78. package/dist/app/lib/routing/components/Link.d.ts +1 -0
  79. package/dist/app/lib/routing/components/Link.js +11 -12
  80. package/dist/app/lib/routing/components/RouteRenderer.d.ts +1 -1
  81. package/dist/app/lib/routing/components/RouteRenderer.js +7 -6
  82. package/dist/app/lib/routing/components/SSRRouter.d.ts +2 -2
  83. package/dist/app/lib/routing/components/SSRRouter.js +5 -6
  84. package/dist/app/lib/routing/components/ScrollRestoration.js +5 -2
  85. package/dist/app/lib/routing/context.d.ts +8 -5
  86. package/dist/app/lib/routing/context.js +13 -96
  87. package/dist/app/lib/routing/hooks/useRestorableState.d.ts +2 -1
  88. package/dist/app/lib/routing/hooks/useRestorableState.js +2 -1
  89. package/dist/app/lib/routing/hooks/useRoute.d.ts +16 -1
  90. package/dist/app/lib/routing/hooks/useRoute.js +22 -1
  91. package/dist/app/lib/routing/hooks/useRouteMeta.d.ts +5 -0
  92. package/dist/app/lib/routing/hooks/useRouteMeta.js +9 -0
  93. package/dist/app/lib/routing/hooks/useRouteTransition.d.ts +1 -1
  94. package/dist/app/lib/routing/hooks/useRouteTransition.js +1 -1
  95. package/dist/app/lib/routing/hooks/useRouter.d.ts +1 -1
  96. package/dist/app/lib/routing/hooks/useRouter.js +1 -1
  97. package/dist/app/lib/routing/hooks/useRouterEvents.d.ts +1 -1
  98. package/dist/app/lib/routing/hooks/useRouterEvents.js +1 -1
  99. package/dist/app/lib/routing/hooks/useRouterState.d.ts +1 -1
  100. package/dist/app/lib/routing/hooks/useRouterState.js +1 -1
  101. package/dist/app/lib/routing/hooks/useSearchParams.js +2 -2
  102. package/dist/app/lib/routing/index.d.ts +14 -13
  103. package/dist/app/lib/routing/index.js +14 -13
  104. package/dist/app/lib/routing/loader.d.ts +2 -2
  105. package/dist/app/lib/routing/loader.js +20 -11
  106. package/dist/app/lib/routing/types.d.ts +36 -10
  107. package/dist/app/lib/routing/utils.d.ts +5 -2
  108. package/dist/app/lib/routing/utils.js +37 -4
  109. package/dist/app/lib/{hooks → runtime}/apiConfig.d.ts +6 -2
  110. package/dist/app/lib/runtime/apiConfig.js +6 -0
  111. package/dist/app/lib/runtime/errorHandling.d.ts +39 -0
  112. package/dist/app/lib/runtime/errorHandling.js +6 -0
  113. package/dist/app/lib/runtime/index.d.ts +2 -0
  114. package/dist/app/lib/runtime/index.js +2 -0
  115. package/dist/app/lib/views/index.d.ts +1 -1
  116. package/dist/app/lib/views/index.js +1 -1
  117. package/dist/app/server/defineRouter.d.ts +2 -0
  118. package/dist/app/server/defineRouter.js +4 -0
  119. package/dist/app/server/index.d.ts +5 -3
  120. package/dist/app/server/index.js +5 -3
  121. package/dist/app/server/proxy-wp-admin.d.ts +1 -2
  122. package/dist/app/server/proxy-wp-admin.js +32 -14
  123. package/dist/app/server/render-ssr-page.d.ts +21 -2
  124. package/dist/app/server/render-ssr-page.js +143 -11
  125. package/dist/app/server/rpc.d.ts +56 -0
  126. package/dist/app/server/rpc.js +18 -0
  127. package/dist/app/server/server-context.d.ts +42 -4
  128. package/dist/app/server/server-context.js +196 -30
  129. package/dist/app/server/utils/replace-host.d.ts +1 -1
  130. package/dist/app/server/utils/replace-host.js +10 -2
  131. package/dist/app/server/utils/swr-cache.d.ts +4 -0
  132. package/dist/app/server/utils/swr-cache.js +31 -0
  133. package/dist/app/utils/APIProvider.d.ts +2 -0
  134. package/dist/app/utils/APIProvider.js +5 -0
  135. package/dist/app/utils/BlockErrorBoundary.d.ts +19 -0
  136. package/dist/app/utils/BlockErrorBoundary.js +38 -0
  137. package/dist/app/utils/ErrorMessage.d.ts +5 -0
  138. package/dist/app/utils/ErrorMessage.js +14 -0
  139. package/dist/app/utils/RouteErrorBoundary.d.ts +18 -0
  140. package/dist/app/utils/RouteErrorBoundary.js +38 -0
  141. package/dist/app/utils/asset-capture.d.ts +2 -0
  142. package/dist/app/utils/asset-capture.js +5 -0
  143. package/dist/app/utils/hydration-debugger.d.ts +13 -0
  144. package/dist/app/utils/hydration-debugger.js +11 -0
  145. package/dist/app/utils/query-client.d.ts +2 -0
  146. package/dist/app/utils/query-client.js +5 -1
  147. package/dist/app/utils/trpc-client.d.ts +2 -0
  148. package/dist/app/utils/trpc-client.js +39 -0
  149. package/dist/node/cli/cli-worker.js +10 -5
  150. package/dist/node/cli/cli.js +79 -11
  151. package/dist/node/cli/display/CLIApp.js +3 -6
  152. package/dist/node/cli/display/boot-cli-app.js +1 -1
  153. package/dist/node/cli/display/tools/CreateBlock.d.ts +1 -1
  154. package/dist/node/cli/display/tools/cli-tools.d.ts +1 -11
  155. package/dist/node/cli/display/tools/cli-tools.js +9 -9
  156. package/dist/node/cli/version.d.ts +1 -1
  157. package/dist/node/cli/version.js +1 -1
  158. package/dist/node/compiler/build-vinxi.js +3 -1
  159. package/dist/node/compiler/bundler.admin.d.ts +1 -1
  160. package/dist/node/compiler/bundler.admin.js +1 -1
  161. package/dist/node/compiler/bundler.frontend.js +1 -1
  162. package/dist/node/compiler/dev-server.js +10 -0
  163. package/dist/node/compiler/get-vite-config.d.ts +1 -0
  164. package/dist/node/compiler/get-vite-config.js +34 -11
  165. package/dist/node/compiler/vinxi-app.d.ts +12 -0
  166. package/dist/node/compiler/vinxi-app.js +139 -32
  167. package/dist/node/compiler/vinxi-codegen.js +321 -108
  168. package/dist/node/graphql/graphql-codegen.d.ts +11 -1
  169. package/dist/node/graphql/graphql-codegen.js +210 -33
  170. package/dist/node/graphql/graphql-schema-loader.d.ts +2 -1
  171. package/dist/node/graphql/graphql-schema-loader.js +5 -16
  172. package/dist/node/graphql/plugins/gql-plugin-queries.js +1 -1
  173. package/dist/node/graphql/query-files-loader.d.ts +3 -0
  174. package/dist/node/graphql/query-files-loader.js +5 -0
  175. package/dist/node/project/config.d.ts +159 -73
  176. package/dist/node/project/config.js +69 -20
  177. package/dist/node/project/env.d.ts +4 -0
  178. package/dist/node/project/env.js +1 -0
  179. package/dist/node/project/manifest/block-manifest.js +1 -0
  180. package/dist/node/project/manifest/manifest.d.ts +1 -0
  181. package/dist/node/project/manifest/manifest.js +14 -10
  182. package/dist/node/project/manifest/routes-manifest.d.ts +20 -0
  183. package/dist/node/project/manifest/routes-manifest.js +74 -0
  184. package/dist/node/project/manifest/view-manifest.js +1 -1
  185. package/dist/node/project/project.d.ts +9 -1
  186. package/dist/node/project/project.js +37 -6
  187. package/dist/node/project/wp-info.d.ts +1 -0
  188. package/dist/node/project/wp-info.js +13 -1
  189. package/dist/node/types/block-type.d.ts +25 -20
  190. package/dist/node/types/block-type.js +1 -0
  191. package/dist/node/types/view-type.d.ts +7 -7
  192. package/dist/node/utils/fetch-wp.d.ts +1 -0
  193. package/dist/node/utils/fetch-wp.js +27 -0
  194. package/dist/node/utils/fs-codegen.d.ts +2 -0
  195. package/dist/node/utils/fs-codegen.js +2 -1
  196. package/dist/node/utils/is-deploying.js +1 -1
  197. package/dist/node/utils/stateful-log.js +2 -0
  198. package/dist/node/utils/watch-file-tree.d.ts +17 -3
  199. package/dist/node/utils/watch-file-tree.js +12 -5
  200. package/package.json +17 -13
  201. package/types.app.d.ts +4 -2
  202. package/types.app.internal.d.ts +2 -2
  203. package/types.node.d.ts +3 -3
  204. package/dist/app/lib/blocks/ErrorBoundaryFrontend.d.ts +0 -15
  205. package/dist/app/lib/blocks/ErrorBoundaryFrontend.js +0 -35
  206. package/dist/app/lib/hooks/apiConfig.js +0 -4
  207. package/dist/app/lib/hooks/usePageLoad.d.ts +0 -6
  208. package/dist/app/lib/hooks/usePageLoad.js +0 -5
  209. package/dist/app/server/utils/index.html.d.ts +0 -2
  210. package/dist/app/server/utils/index.html.js +0 -14
@@ -1,4 +1,4 @@
1
- import type { RouteState } from "../types";
1
+ import type { RouteState } from "../types.js";
2
2
  type TransitionFunction = (currentRoute: RouteState, nextRoute: RouteState) => void | Promise<any | void>;
3
3
  export declare function useRouteTransition(func: TransitionFunction): void;
4
4
  export {};
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useRef } from "react";
2
- import { useRouter } from "./useRouter";
2
+ import { useRouter } from "./useRouter.js";
3
3
  export function useRouteTransition(func) {
4
4
  const subscribe = useRouter((r) => r.subscribe);
5
5
  const handler = useRef(func);
@@ -1,2 +1,2 @@
1
- import { RouterAPI } from "../types";
1
+ import { RouterAPI } from "../types.js";
2
2
  export declare function useRouter<T = RouterAPI>(selector?: (r: RouterAPI) => T): T;
@@ -1,5 +1,5 @@
1
1
  import { useContext } from "react";
2
- import { RouterContext } from "../context";
2
+ import { RouterContext } from "../context.js";
3
3
  export function useRouter(selector) {
4
4
  const router = useContext(RouterContext);
5
5
  if (selector) {
@@ -1,2 +1,2 @@
1
- import type { RouterEvent } from "../types";
1
+ import type { RouterEvent } from "../types.js";
2
2
  export declare function useRouterEvents(handler: (event: RouterEvent) => void): void;
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useRef } from "react";
2
- import { useRouter } from "./useRouter";
2
+ import { useRouter } from "./useRouter.js";
3
3
  export function useRouterEvents(handler) {
4
4
  const subscribe = useRouter((r) => r.subscribe);
5
5
  const ref = useRef(handler);
@@ -1,2 +1,2 @@
1
- import { RouterAPIState } from "../types";
1
+ import { RouterAPIState } from "../types.js";
2
2
  export declare function useRouterState<T = RouterAPIState>(selector?: (state: RouterAPIState) => T): T;
@@ -1,5 +1,5 @@
1
1
  import { useContext } from "react";
2
- import { RouterStateContext } from "../context";
2
+ import { RouterStateContext } from "../context.js";
3
3
  export function useRouterState(selector) {
4
4
  const ctx = useContext(RouterStateContext);
5
5
  if (selector)
@@ -1,6 +1,6 @@
1
1
  import { useMemo } from "react";
2
- import { useRoute } from "./useRoute";
3
- import { useRouter } from "./useRouter";
2
+ import { useRoute } from "./useRoute.js";
3
+ import { useRouter } from "./useRouter.js";
4
4
  export function useSearchParams(defaultValue) {
5
5
  const route = useRoute();
6
6
  const replaceQuery = useRouter((r) => r.replaceQuery);
@@ -1,13 +1,14 @@
1
- export * from "./types";
2
- export * from "./components/Link";
3
- export * from "./components/ScrollRestoration";
4
- export * from "./components/RouteRenderer";
5
- export * from "./components/ClientOnly";
6
- export * from "./hooks/useRoute";
7
- export * from "./hooks/useRouteTransition";
8
- export * from "./hooks/useRouter";
9
- export * from "./hooks/useRouterEvents";
10
- export * from "./hooks/useRouterState";
11
- export * from "./hooks/useRestorableState";
12
- export * from "./hooks/useIsSSR";
13
- export * from "./hooks/useSearchParams";
1
+ export * from "./types.js";
2
+ export * from "./components/Link.js";
3
+ export * from "./components/ScrollRestoration.js";
4
+ export * from "./components/RouteRenderer.js";
5
+ export * from "./components/ClientOnly.js";
6
+ export * from "./components/BackButton.js";
7
+ export * from "./hooks/useRoute.js";
8
+ export * from "./hooks/useRouteTransition.js";
9
+ export * from "./hooks/useRouter.js";
10
+ export * from "./hooks/useRouterEvents.js";
11
+ export * from "./hooks/useRouterState.js";
12
+ export * from "./hooks/useRestorableState.js";
13
+ export * from "./hooks/useIsSSR.js";
14
+ export * from "./hooks/useSearchParams.js";
@@ -1,13 +1,14 @@
1
- export * from "./types";
2
- export * from "./components/Link";
3
- export * from "./components/ScrollRestoration";
4
- export * from "./components/RouteRenderer";
5
- export * from "./components/ClientOnly";
6
- export * from "./hooks/useRoute";
7
- export * from "./hooks/useRouteTransition";
8
- export * from "./hooks/useRouter";
9
- export * from "./hooks/useRouterEvents";
10
- export * from "./hooks/useRouterState";
11
- export * from "./hooks/useRestorableState";
12
- export * from "./hooks/useIsSSR";
13
- export * from "./hooks/useSearchParams";
1
+ export * from "./types.js";
2
+ export * from "./components/Link.js";
3
+ export * from "./components/ScrollRestoration.js";
4
+ export * from "./components/RouteRenderer.js";
5
+ export * from "./components/ClientOnly.js";
6
+ export * from "./components/BackButton.js";
7
+ export * from "./hooks/useRoute.js";
8
+ export * from "./hooks/useRouteTransition.js";
9
+ export * from "./hooks/useRouter.js";
10
+ export * from "./hooks/useRouterEvents.js";
11
+ export * from "./hooks/useRouterState.js";
12
+ export * from "./hooks/useRestorableState.js";
13
+ export * from "./hooks/useIsSSR.js";
14
+ export * from "./hooks/useSearchParams.js";
@@ -1,6 +1,6 @@
1
1
  import { FunctionComponent, PropsWithChildren } from "react";
2
- import { DynamicComponent } from "../dynamic/dynamic";
3
- import { RouteData } from "./types";
2
+ import { DynamicComponent } from "../dynamic/dynamic.js";
3
+ import { RouteData } from "./types.js";
4
4
  export type RouteCacheEntry = {
5
5
  data: RouteData;
6
6
  component: FunctionComponent;
@@ -1,5 +1,5 @@
1
1
  import { parseURL, stringifyParsedURL, stringifyQuery, withTrailingSlash } from "ufo";
2
- import { viewManifestReader } from "../internal";
2
+ import { viewManifestReader } from "../internal/read-view-manifest.js";
3
3
  export class RouteError extends Error {
4
4
  message;
5
5
  statusCode;
@@ -56,6 +56,7 @@ export class RouteLoader {
56
56
  return this.entries.has(cacheKey);
57
57
  }
58
58
  async loadRouteData(pathname, withAppData = false) {
59
+ pathname = withTrailingSlash(pathname);
59
60
  const cacheKey = this.getKey(pathname);
60
61
  // Cached value?
61
62
  if (this.entries.has(cacheKey))
@@ -65,27 +66,35 @@ export class RouteLoader {
65
66
  serverless: env.serverless,
66
67
  debug: env.dev,
67
68
  });
68
- const promise = this.fetchImpl(requestUrl, {})
69
- .then((response) => response.text())
70
- .then((text) => {
69
+ const promise = this.fetchImpl(requestUrl)
70
+ .then(async (response) => {
71
+ if (response.redirected) {
72
+ return { redirect: response.url };
73
+ }
74
+ let text = await response.text();
71
75
  if (this.processProps) {
72
76
  text = this.processProps(text);
73
77
  }
74
78
  try {
75
- return JSON.parse(text);
79
+ const payload = JSON.parse(text);
80
+ if (!payload.view) {
81
+ throw new RouteError(`Invalid route data for '${pathname}'`, 500);
82
+ }
83
+ return payload;
76
84
  }
77
85
  catch (err) {
78
86
  throw new RouteError(`JSON parse error for route '${pathname}':\n${err?.message}`, 500);
79
87
  }
80
88
  })
81
- .then((data) => {
89
+ .then(async (data) => {
82
90
  if (data.redirect) {
83
- const redirect = data.redirect;
84
- data = this.loadRouteData(redirect).then((data) => {
85
- data.canonical = redirect;
86
- return data;
87
- });
91
+ const redirect = parseURL(data.redirect).pathname;
92
+ data = await this.loadRouteData(redirect);
93
+ data.canonical = redirect;
88
94
  }
95
+ return data;
96
+ })
97
+ .then((data) => {
89
98
  this.entries.set(cacheKey, new Promise((resolve) => resolve(data)));
90
99
  return data;
91
100
  });
@@ -1,9 +1,16 @@
1
1
  import { FunctionComponent } from "react";
2
- import type { RouteLoader } from "./loader";
3
- import { LinkHandlerMode, PointerOrMouseEvent } from "./utils";
4
- export type ParsedRouteTags = Record<"title" | "meta" | "script" | "style" | "link", {
5
- [key: string]: string;
6
- }[]>;
2
+ import type { RouteLoader } from "./loader.js";
3
+ import { LinkHandlerMode, PointerOrMouseEvent } from "./utils.js";
4
+ export type RouteMetaTag = {
5
+ tagName: string;
6
+ attributes: Record<string, string>;
7
+ inner?: string;
8
+ };
9
+ export type TrackerTags = {
10
+ head?: RouteMetaTag[];
11
+ body?: RouteMetaTag[];
12
+ footer?: RouteMetaTag[];
13
+ };
7
14
  export interface RouteData {
8
15
  view: string;
9
16
  editLink?: string;
@@ -13,10 +20,13 @@ export interface RouteData {
13
20
  redirect?: string;
14
21
  canonical?: string;
15
22
  meta?: {
16
- head: ParsedRouteTags;
17
- footer: ParsedRouteTags;
23
+ head: RouteMetaTag[];
24
+ footer: RouteMetaTag[];
18
25
  };
19
26
  }
27
+ export interface RouteDataWithTrackers extends RouteData {
28
+ trackers?: TrackerTags;
29
+ }
20
30
  export type RouteReturnState<T = {}> = {
21
31
  scrollTop: number;
22
32
  scrollLeft: number;
@@ -73,7 +83,7 @@ export type RouterEvent = {
73
83
  data: RouteData;
74
84
  } | {
75
85
  type: "error";
76
- critical: false;
86
+ critical: boolean;
77
87
  error: Error;
78
88
  };
79
89
  export type RouterSubscriber = (event: RouterEvent) => void;
@@ -99,14 +109,24 @@ export type RouterAPI = {
99
109
  replaceQuery: (search: Record<string, string | string[]>) => void;
100
110
  /** Replace the hash */
101
111
  replaceHash: (hash: string) => void;
102
- /** Handle link clicking events */
103
- handleClickEvent(e: PointerOrMouseEvent, href?: string): void;
112
+ /**
113
+ * Handle a click event, potentially triggering a route change.
114
+ *
115
+ * @param e A pointer or mouse event.
116
+ * @param href An optional URL. This must be provided if no `href` property exists on the clicked element
117
+ * @param preferBack If set, clicking this link will send the user 'back', when clicking a link to the previous history item.
118
+ */
119
+ handleClickEvent(e: PointerOrMouseEvent, href?: string, preferBack?: boolean | "exact"): void;
104
120
  /** A reference to the route loader (mostly for internal use) */
105
121
  loader: RouteLoader;
106
122
  /** Subscribe to events */
107
123
  subscribe: (subscribe: RouterSubscriber) => () => void;
108
124
  /** This function is used by the routing system automatically */
109
125
  emitEvent: (event: RouterEvent) => void;
126
+ /** Returns the current RouterAPIState */
127
+ getState: () => RouterAPIState | null;
128
+ /** Go back to a previous route in the history stack, or push it onto the stack if it isn't currently on the stack. */
129
+ restoreRoute: (route: RouteState) => void;
110
130
  };
111
131
  export type TypedRouteState<T, TProps> = {
112
132
  /** A unique ID, representing this history item. */
@@ -131,6 +151,12 @@ export type TypedRouteState<T, TProps> = {
131
151
  component: FunctionComponent<TProps>;
132
152
  /** The props for this route, to be passed to the component. */
133
153
  props: TProps;
154
+ /** Loaded metadata for this route */
155
+ meta: RouteMeta;
156
+ };
157
+ export type RouteMeta = {
158
+ title?: string;
159
+ tags?: RouteMetaTag[];
134
160
  };
135
161
  export type RouteState = {
136
162
  [K in keyof ViewProps]: TypedRouteState<K, ViewProps[K]>;
@@ -1,15 +1,18 @@
1
1
  import { MouseEvent as ReactMouseEvent, PointerEvent as ReactPointerEvent } from "react";
2
- import { RouteLink, RouteState } from "./types";
2
+ import { RouteData, RouteLink, RouteMeta, RouteState } from "./types.js";
3
3
  export declare function isSameOrigin(url: string): boolean;
4
+ export declare function isSamePathname(a: string, b: string): boolean;
4
5
  export type PointerOrMouseEvent = MouseEvent | PointerEvent | ReactMouseEvent | ReactPointerEvent;
5
6
  export type LinkHandlerMode = {
6
7
  mode: "ignore" | "navigate" | "native";
7
8
  href?: string;
8
9
  };
9
- export declare function getLinkHandlerMode(e?: PointerOrMouseEvent, href?: string): LinkHandlerMode;
10
+ export declare function getLinkHandlerMode(e?: PointerOrMouseEvent, href?: string, currentRoute?: RouteState): LinkHandlerMode;
10
11
  type Partialize<T, TKeys extends keyof T> = Partial<Pick<T, TKeys>> & Omit<T, TKeys>;
11
12
  export declare function normalizeRoute(route: Partialize<RouteState, "uri" | "returnState" | "key">): RouteState;
12
13
  export declare function stringifyRouteLink(route: RouteLink): string;
13
14
  export declare function parseQuery(query: string): Record<string, string | string[]>;
14
15
  export declare function stringifyQuery(query: any): string;
16
+ export declare function getRouteMeta(data: RouteData): RouteMeta;
17
+ export declare function addTrailingSlash(path?: string | null): string;
15
18
  export {};
@@ -1,5 +1,5 @@
1
- import { parseURL, resolveURL, stringifyParsedURL, withoutTrailingSlash } from "ufo";
2
- import { stringify as qsStringify, parse as qsParse } from "qs";
1
+ import { parse as qsParse, stringify as qsStringify } from "qs";
2
+ import { parseURL, resolveURL, stringifyParsedURL, withoutTrailingSlash, withTrailingSlash } from "ufo";
3
3
  export function isSameOrigin(url) {
4
4
  if (typeof document === "undefined") {
5
5
  return url.startsWith("/");
@@ -10,7 +10,12 @@ export function isSameOrigin(url) {
10
10
  return parsed.protocol === document.location.protocol && parsed.host === document.location.host;
11
11
  }
12
12
  }
13
- export function getLinkHandlerMode(e, href) {
13
+ export function isSamePathname(a, b) {
14
+ const left = parseURL(a).pathname.replace(/\/$/, "").toLocaleLowerCase();
15
+ const right = parseURL(b).pathname.replace(/\/$/, "").toLocaleLowerCase();
16
+ return left === right;
17
+ }
18
+ export function getLinkHandlerMode(e, href, currentRoute) {
14
19
  try {
15
20
  // Attempt to get the link element, if there is one
16
21
  let eventTarget = null;
@@ -31,7 +36,11 @@ export function getLinkHandlerMode(e, href) {
31
36
  if (!href)
32
37
  return { mode: "native", href };
33
38
  // Resolve the URL and check if it's the same origin
34
- const resolved = href.startsWith("http") ? href : resolveURL(document.location.href, href);
39
+ const resolved = href.startsWith("http")
40
+ ? href
41
+ : href.startsWith("/")
42
+ ? resolveURL(document.location.origin, href)
43
+ : resolveURL(document.location.href, href);
35
44
  const parsed = parseURL(resolved);
36
45
  const isSameOrigin = parsed.host?.replace(/:.+/, "") === document.location.host.replace(/:.+/, "");
37
46
  // External links should be handled natively
@@ -52,6 +61,17 @@ export function getLinkHandlerMode(e, href) {
52
61
  // Starts with /wp-, use native (wp-content, wp-admin etc)
53
62
  if (parsed.pathname.startsWith("/wp-"))
54
63
  return { mode: "native", href };
64
+ // If pathname+query are identical, but the hash is different, then allow the browser to handle it
65
+ if (currentRoute &&
66
+ isSamePathname(currentRoute.pathname, parsed.pathname) &&
67
+ currentRoute.search === parsed.search) {
68
+ if (currentRoute.hash !== parsed.hash) {
69
+ return { mode: "native", href };
70
+ }
71
+ else {
72
+ return { mode: "ignore", href };
73
+ }
74
+ }
55
75
  return { mode: "navigate", href };
56
76
  }
57
77
  catch (err) {
@@ -76,6 +96,7 @@ export function normalizeRoute(route) {
76
96
  export function stringifyRouteLink(route) {
77
97
  return stringifyParsedURL({
78
98
  ...route,
99
+ pathname: withTrailingSlash(route.pathname),
79
100
  search: stringifyQuery(route.query),
80
101
  });
81
102
  }
@@ -92,3 +113,15 @@ export function stringifyQuery(query) {
92
113
  arrayFormat: "brackets",
93
114
  });
94
115
  }
116
+ export function getRouteMeta(data) {
117
+ return {
118
+ title: data.meta?.head.find((tag) => tag.tagName === "title")?.inner,
119
+ tags: data.meta?.head ?? [],
120
+ };
121
+ }
122
+ export function addTrailingSlash(path) {
123
+ if (path?.match(/\./)) {
124
+ return path;
125
+ }
126
+ return withTrailingSlash(path ?? undefined, true);
127
+ }
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Configuration options for manipulating how the client interacts with the GraphQL API
3
+ */
1
4
  export type APIConfigStore = {
2
5
  /**
3
6
  * Any value, which will be used as part of the cache key for each query.
@@ -11,8 +14,9 @@ export type APIConfigStore = {
11
14
  */
12
15
  customQueryFetchOptions?: (type: "query" | "mutation", queryName: string, queryArgs: any, url: string, opts: RequestInit) => RequestInit | Promise<RequestInit>;
13
16
  /**
14
- * Update aspects of the API client
17
+ * Allows you to hook into the response of a query or mutation.
15
18
  */
19
+ onResponse?: (response: Response, type: "query" | "mutation", queryName: string, queryArgs: any, url: string, opts: RequestInit) => void;
16
20
  set: (config: Partial<APIConfigStore>) => void;
17
21
  };
18
- export declare const useAPIConfig: import("zustand").UseBoundStore<import("zustand").StoreApi<APIConfigStore>>;
22
+ export declare const apiConfig: APIConfigStore;
@@ -0,0 +1,6 @@
1
+ import { proxy } from "valtio";
2
+ export const apiConfig = proxy({
3
+ set: (config) => {
4
+ Object.assign(apiConfig, config);
5
+ },
6
+ });
@@ -0,0 +1,39 @@
1
+ import { ContentBlock } from "../blocks";
2
+ import { ReactNode } from "react";
3
+ import { RouteState } from "../routing";
4
+ export type ErrorEvent = {
5
+ /** The runtime error that occurred */
6
+ error: Error;
7
+ /** The Component stack (not available in renderBlockError) */
8
+ componentStack?: string;
9
+ } & ({
10
+ type: "block";
11
+ /** The block which had an error, including it's type information, props, content and children */
12
+ block: ContentBlock;
13
+ } | {
14
+ type: "route";
15
+ /** The route which had an error */
16
+ route: RouteState;
17
+ });
18
+ /**
19
+ * Configuration options for manipulating how the client interacts with the GraphQL API
20
+ */
21
+ export type ErrorHandlingConfig = {
22
+ /**
23
+ * Triggered when a runtime error occurs in a block
24
+ * @param event The error event, containing the error and block information
25
+ **/
26
+ onReactError?(event: ErrorEvent): void;
27
+ /**
28
+ * Triggered when a React rendering error occurs, and allows you to return some JSX to render as a fallback.
29
+ * If not provided, the block will be hidden from the user.
30
+ * @param error The error event, containing the error and contextual information
31
+ * @param defaultDisplay The default display for the block — in development, this will display the error message. In production, this will be `null`.
32
+ */
33
+ renderFallback?(event: ErrorEvent, defaultDisplay: ReactNode): ReactNode;
34
+ /**
35
+ * Update the error handling configuration all at once
36
+ */
37
+ set: (config: Partial<ErrorHandlingConfig>) => void;
38
+ };
39
+ export declare const errorHandling: ErrorHandlingConfig;
@@ -0,0 +1,6 @@
1
+ import { proxy } from "valtio";
2
+ export const errorHandling = proxy({
3
+ set: (config) => {
4
+ Object.assign(errorHandling, config);
5
+ },
6
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./apiConfig";
2
+ export * from "./errorHandling";
@@ -0,0 +1,2 @@
1
+ export * from "./apiConfig";
2
+ export * from "./errorHandling";
@@ -1 +1 @@
1
- export * from "./defineView";
1
+ export * from "./defineView.js";
@@ -1 +1 @@
1
- export * from "./defineView";
1
+ export * from "./defineView.js";
@@ -0,0 +1,2 @@
1
+ import { Hono } from "hono";
2
+ export declare function defineRouter(): Hono;
@@ -0,0 +1,4 @@
1
+ import { Hono } from "hono";
2
+ export function defineRouter() {
3
+ return new Hono();
4
+ }
@@ -1,3 +1,5 @@
1
- export * from "./render-ssr-page";
2
- export * from "./server-context";
3
- export * from "./proxy-wp-admin";
1
+ export * from "./render-ssr-page.js";
2
+ export * from "./server-context.js";
3
+ export * from "./proxy-wp-admin.js";
4
+ export * from "./defineRouter.js";
5
+ export * from "./rpc.js";
@@ -1,3 +1,5 @@
1
- export * from "./render-ssr-page";
2
- export * from "./server-context";
3
- export * from "./proxy-wp-admin";
1
+ export * from "./render-ssr-page.js";
2
+ export * from "./server-context.js";
3
+ export * from "./proxy-wp-admin.js";
4
+ export * from "./defineRouter.js";
5
+ export * from "./rpc.js";
@@ -1,3 +1,2 @@
1
1
  import { EventHandlerRequest, H3Event } from "vinxi/http";
2
- import { ServerContext } from "./server-context";
3
- export declare function proxyWpAdmin(event: H3Event<EventHandlerRequest>, serverContext: ServerContext): Promise<Response>;
2
+ export declare function proxyWpAdmin(event: H3Event<EventHandlerRequest>): Promise<Response>;
@@ -1,14 +1,29 @@
1
1
  /// <reference types="vinxi/types/server" />
2
2
  import { splitSetCookieString } from "cookie-es";
3
3
  import { getProxyRequestHeaders, getRequestURL, getWebRequest } from "vinxi/http";
4
- import { getManifest } from "vinxi/manifest";
5
- export async function proxyWpAdmin(event, serverContext) {
6
- const replaceUrls = serverContext.replaceUrls;
4
+ import { ServerContext } from "./server-context.js";
5
+ import { renderErrorPage } from "./render-ssr-page.js";
6
+ export async function proxyWpAdmin(event) {
7
+ const serverContext = ServerContext.main;
7
8
  const req = getWebRequest(event);
8
- const proxyUrl = serverContext.getOriginUrl(getRequestURL(event).href);
9
+ const reqUrl = getRequestURL(event);
10
+ const serverlessConfig = serverContext.config.serverless;
11
+ if (!serverContext.dev) {
12
+ if (reqUrl.pathname.toLowerCase().match(/\/+(graphql|xmlrpc|index\.php|wp\-(admin|login|json))/)) {
13
+ if (serverlessConfig.admin === "hide") {
14
+ return renderErrorPage({
15
+ code: 404,
16
+ pathname: reqUrl.pathname,
17
+ title: "Not Found",
18
+ });
19
+ }
20
+ }
21
+ }
22
+ const proxyUrl = serverContext.getOriginUrl(reqUrl.href);
9
23
  // Prepare request headers to be sent to the origin server
10
24
  const proxyHeaders = getProxyRequestHeaders(event);
11
25
  proxyHeaders["X-ED-Dev-Proxy"] = "true";
26
+ const followRedirects = !reqUrl.pathname.match(/\.[a-z0-9]$/);
12
27
  // Forward the request to the origin server
13
28
  const response = await fetch(proxyUrl, {
14
29
  method: req.method,
@@ -16,7 +31,7 @@ export async function proxyWpAdmin(event, serverContext) {
16
31
  referrerPolicy: req.referrerPolicy,
17
32
  headers: proxyHeaders,
18
33
  body: req.method.match(/get|head|options/i) ? undefined : await req.blob(),
19
- redirect: "manual",
34
+ redirect: followRedirects ? "follow" : "manual",
20
35
  cache: "no-cache",
21
36
  });
22
37
  const contentType = response.headers.get("content-type");
@@ -31,8 +46,8 @@ export async function proxyWpAdmin(event, serverContext) {
31
46
  cookies.push(...splitSetCookieString(value));
32
47
  return;
33
48
  }
34
- if (key === "location" && replaceUrls) {
35
- value = replaceUrls(value);
49
+ if (key === "location") {
50
+ value = serverContext.replaceUrls(value);
36
51
  }
37
52
  res.headers.set(key, value);
38
53
  });
@@ -46,22 +61,25 @@ export async function proxyWpAdmin(event, serverContext) {
46
61
  // Replace URLs pointing to the origin server from the response itself
47
62
  // This is only done for text-based content types, like application/json, text/plain, text/html etc
48
63
  if (contentType?.match(/(application|text)\//)) {
49
- if (replaceUrls) {
50
- body = replaceUrls((await response.text()) ?? "");
51
- }
64
+ body = serverContext.replaceUrls((await response.text()) ?? "", reqUrl.origin);
52
65
  // If the content type is text/html, inject the Vite assets into the response — assuming the placeholder comments are found
53
66
  if (contentType.startsWith("text/html")) {
54
- const clientManifest = getManifest("admin");
67
+ const clientManifest = serverContext.runtime.getManifest("admin");
55
68
  const assets = await clientManifest.inputs[clientManifest.handler].assets();
56
- body = body.replace("<!---VITE_HEADER--->", () => assets.map((asset) => renderAsset(asset)).join("\n"));
57
- body = body.replace("<!---VITE_FOOTER--->", () => renderAsset({
69
+ const getViteHeader = () => assets.map((asset) => renderAsset(asset)).join("\n");
70
+ const getViteFooter = () => renderAsset({
58
71
  tag: "script",
59
72
  attrs: {
60
73
  type: "module",
61
74
  src: clientManifest.inputs[clientManifest.handler].output.path,
62
75
  },
63
76
  children: "",
64
- }));
77
+ });
78
+ const encodeForJSON = (str) => JSON.stringify(str).slice(1, -1).replace(/\"/g, "'");
79
+ body = body.replace(/<!---VITE_HEADER--->/g, getViteHeader);
80
+ body = body.replace(/<!---VITE_FOOTER--->/g, getViteFooter);
81
+ body = body.replace(/<!---VITE_HEADER_ENCODED--->/g, encodeForJSON(getViteHeader()));
82
+ body = body.replace(/<!---VITE_FOOTER_ENCODED--->/g, encodeForJSON(getViteFooter()));
65
83
  }
66
84
  }
67
85
  else {
@@ -1,2 +1,21 @@
1
- import type { RouteData } from "../lib/routing/types";
2
- export declare function renderPageToSSRStream(pathname: string, initialData: RouteData): Promise<unknown>;
1
+ import type { RouteDataWithTrackers } from "../lib/routing/types.js";
2
+ type SSRArgs = {
3
+ pathname: string;
4
+ initialData: RouteDataWithTrackers;
5
+ };
6
+ export declare function getSsrStream(args: SSRArgs): Promise<ReadableStream<Uint8Array>>;
7
+ type RenderArgs = {
8
+ pathname: string;
9
+ statusCode?: number;
10
+ newOrigin?: string;
11
+ };
12
+ export declare function renderPage(args: RenderArgs): Promise<Response>;
13
+ type RenderErrorPageArgs = {
14
+ pathname: string;
15
+ code: number;
16
+ title: string;
17
+ newOrigin?: string;
18
+ realError?: Error;
19
+ };
20
+ export declare function renderErrorPage(args: RenderErrorPageArgs): Promise<Response>;
21
+ export {};