@quilted/create 0.2.34 → 0.2.36

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @quilted/create
2
2
 
3
+ ## 0.2.36
4
+
5
+ ### Patch Changes
6
+
7
+ - [#788](https://github.com/lemonmade/quilt/pull/788) [`85a4b7e`](https://github.com/lemonmade/quilt/commit/85a4b7ed8e6ad58662ebf969d8fabbe8e21510a3) Thanks [@lemonmade](https://github.com/lemonmade)! - Add `Browser.locale` and use it in place of `useLocaleFromEnvironment()`
8
+
9
+ ## 0.2.35
10
+
11
+ ### Patch Changes
12
+
13
+ - [`5c418c3`](https://github.com/lemonmade/quilt/commit/5c418c3a9a7de7c5ee4337cbd02b68e4bcd2d581) Thanks [@lemonmade](https://github.com/lemonmade)! - Add `createContextRouteFunction()` helper for creating routes with a known context, and use it for app context
14
+
15
+ - [`7dae2be`](https://github.com/lemonmade/quilt/commit/7dae2bebab01a4a4e2baf6c1799ce0adb59a5bb7) Thanks [@lemonmade](https://github.com/lemonmade)! - Rename `@quilted/quilt/navigate` to `@quilted/quilt/navigation`
16
+
3
17
  ## 0.2.34
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quilted/create",
3
3
  "type": "module",
4
- "version": "0.2.34",
4
+ "version": "0.2.36",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,8 +1,8 @@
1
1
  import type {RenderableProps} from 'preact';
2
2
 
3
3
  import {NotFound} from '@quilted/quilt/server';
4
- import {Navigation, route} from '@quilted/quilt/navigate';
5
- import {Localization, useLocaleFromEnvironment} from '@quilted/quilt/localize';
4
+ import {Navigation} from '@quilted/quilt/navigation';
5
+ import {Localization} from '@quilted/quilt/localize';
6
6
 
7
7
  import {HTML} from './foundation/html.ts';
8
8
  import {Frame} from './foundation/frame.ts';
@@ -13,6 +13,7 @@ import {
13
13
  AppContextReact,
14
14
  type AppContext as AppContextType,
15
15
  } from './shared/context.ts';
16
+ import {routeWithAppContext} from './shared/navigation.ts';
16
17
 
17
18
  export interface AppProps {
18
19
  context: AppContextType;
@@ -21,16 +22,16 @@ export interface AppProps {
21
22
  // Define the routes for your application. If you have a lot of routes, you
22
23
  // might want to split this into a separate file.
23
24
  const routes = [
24
- route('*', {
25
+ routeWithAppContext('*', {
25
26
  render: (children) => <Frame>{children}</Frame>,
26
27
  children: [
27
- route('/', {
28
+ routeWithAppContext('/', {
28
29
  async load() {
29
30
  await Promise.all([Home.load()]);
30
31
  },
31
32
  render: <Home />,
32
33
  }),
33
- route('*', {render: <NotFound />}),
34
+ routeWithAppContext('*', {render: <NotFound />}),
34
35
  ],
35
36
  }),
36
37
  ];
@@ -51,11 +52,9 @@ export default App;
51
52
 
52
53
  // This component renders any app-wide context.
53
54
  function AppContext({children, context}: RenderableProps<AppProps>) {
54
- const locale = useLocaleFromEnvironment() ?? 'en';
55
-
56
55
  return (
57
56
  <AppContextReact.Provider value={context}>
58
- <Localization locale={locale}>{children}</Localization>
57
+ <Localization>{children}</Localization>
59
58
  </AppContextReact.Provider>
60
59
  );
61
60
  }
@@ -1,7 +1,7 @@
1
1
  import '@quilted/quilt/globals';
2
2
  import {hydrate} from 'preact';
3
3
  import {Browser, BrowserContext} from '@quilted/quilt/browser';
4
- import {Router} from '@quilted/quilt/navigate';
4
+ import {Router} from '@quilted/quilt/navigation';
5
5
 
6
6
  import type {AppContext} from '~/shared/context.ts';
7
7
  import {App} from './App.tsx';
@@ -1,7 +1,7 @@
1
1
  import '@quilted/quilt/globals';
2
2
  import {RequestRouter} from '@quilted/quilt/request-router';
3
3
  import {renderToResponse} from '@quilted/quilt/server';
4
- import {Router} from '@quilted/quilt/navigate';
4
+ import {Router} from '@quilted/quilt/navigation';
5
5
  import {BrowserAssets} from 'quilt:module/assets';
6
6
 
7
7
  import type {AppContext} from '~/shared/context.ts';
@@ -1,12 +1,6 @@
1
1
  import {createOptionalContext} from '@quilted/quilt/context';
2
- import type {Router} from '@quilted/quilt/navigate';
3
2
 
4
- export interface AppContext {
5
- /**
6
- * The router used to control navigation throughout the application.
7
- */
8
- readonly router: Router;
9
- }
3
+ export interface AppContext {}
10
4
 
11
5
  export const AppContextReact = createOptionalContext<AppContext>();
12
6
  export const useAppContext = AppContextReact.use;
@@ -0,0 +1,15 @@
1
+ import type {Router} from '@quilted/quilt/navigation';
2
+ import {createContextRouteFunction} from '@quilted/quilt/navigation';
3
+
4
+ import type {AppContext} from '~/shared/context.ts';
5
+
6
+ declare module '~/shared/context.ts' {
7
+ interface AppContext {
8
+ /**
9
+ * The router used to control navigation throughout the application.
10
+ */
11
+ readonly router: Router;
12
+ }
13
+ }
14
+
15
+ export const routeWithAppContext = createContextRouteFunction<AppContext>();
@@ -1,6 +1,6 @@
1
1
  import {createRender} from '@quilted/quilt/testing';
2
2
  import {BrowserContext, BrowserTestMock} from '@quilted/quilt/browser/testing';
3
- import {TestRouting, TestRouter} from '@quilted/quilt/navigate/testing';
3
+ import {TestRouting, TestRouter} from '@quilted/quilt/navigation/testing';
4
4
  import {Localization} from '@quilted/quilt/localize';
5
5
 
6
6
  import {AppContextReact} from '~/shared/context.ts';
@@ -1,4 +1,4 @@
1
- import type {TestRouter} from '@quilted/quilt/navigate/testing';
1
+ import type {TestRouter} from '@quilted/quilt/navigation/testing';
2
2
  import type {BrowserTestMock} from '@quilted/quilt/browser/testing';
3
3
 
4
4
  import type {AppContext} from '~/shared/context.ts';
@@ -1,6 +1,6 @@
1
1
  import '@quilted/quilt/testing';
2
2
 
3
- export {TestRouter} from '@quilted/quilt/navigate/testing';
3
+ export {TestRouter} from '@quilted/quilt/navigation/testing';
4
4
 
5
5
  export * from './render/types.ts';
6
6
  export {renderApp} from './render/render.tsx';
@@ -2,8 +2,8 @@ import type {RenderableProps} from 'preact';
2
2
 
3
3
  import {NotFound} from '@quilted/quilt/server';
4
4
  import {GraphQLContext} from '@quilted/quilt/graphql';
5
- import {Navigation, route} from '@quilted/quilt/navigate';
6
- import {Localization, useLocaleFromEnvironment} from '@quilted/quilt/localize';
5
+ import {Navigation} from '@quilted/quilt/navigation';
6
+ import {Localization} from '@quilted/quilt/localize';
7
7
 
8
8
  import {HTML} from './foundation/html.ts';
9
9
  import {Frame} from './foundation/frame.ts';
@@ -14,6 +14,7 @@ import {
14
14
  AppContextReact,
15
15
  type AppContext as AppContextType,
16
16
  } from './shared/context.ts';
17
+ import {routeWithAppContext} from './shared/navigation.ts';
17
18
 
18
19
  export interface AppProps {
19
20
  context: AppContextType;
@@ -22,16 +23,16 @@ export interface AppProps {
22
23
  // Define the routes for your application. If you have a lot of routes, you
23
24
  // might want to split this into a separate file.
24
25
  const routes = [
25
- route('*', {
26
+ routeWithAppContext('*', {
26
27
  render: (children) => <Frame>{children}</Frame>,
27
28
  children: [
28
- route('/', {
29
- async load(_navigation, {graphql}: AppContextType) {
29
+ routeWithAppContext('/', {
30
+ async load({context: {graphql}}) {
30
31
  await Promise.all([Home.load(), graphql.cache.query(homeQuery)]);
31
32
  },
32
33
  render: <Home />,
33
34
  }),
34
- route('*', {render: <NotFound />}),
35
+ routeWithAppContext('*', {render: <NotFound />}),
35
36
  ],
36
37
  }),
37
38
  ];
@@ -52,15 +53,13 @@ export default App;
52
53
 
53
54
  // This component renders any app-wide context.
54
55
  function AppContext({children, context}: RenderableProps<AppProps>) {
55
- const locale = useLocaleFromEnvironment() ?? 'en';
56
-
57
56
  return (
58
57
  <AppContextReact.Provider value={context}>
59
58
  <GraphQLContext
60
59
  fetch={context.graphql.fetch}
61
60
  cache={context.graphql.cache}
62
61
  >
63
- <Localization locale={locale}>{children}</Localization>
62
+ <Localization>{children}</Localization>
64
63
  </GraphQLContext>
65
64
  </AppContextReact.Provider>
66
65
  );
@@ -3,7 +3,7 @@ import '@quilted/quilt/globals';
3
3
  import {hydrate} from 'preact';
4
4
  import {createGraphQLFetch, GraphQLCache} from '@quilted/quilt/graphql';
5
5
  import {Browser, BrowserContext} from '@quilted/quilt/browser';
6
- import {Router} from '@quilted/quilt/navigate';
6
+ import {Router} from '@quilted/quilt/navigation';
7
7
 
8
8
  import type {AppContext} from '~/shared/context.ts';
9
9
 
@@ -1,7 +1,7 @@
1
1
  import '@quilted/quilt/globals';
2
2
 
3
3
  import {RequestRouter, JSONResponse} from '@quilted/quilt/request-router';
4
- import {Router} from '@quilted/quilt/navigate';
4
+ import {Router} from '@quilted/quilt/navigation';
5
5
  import {BrowserAssets} from 'quilt:module/assets';
6
6
 
7
7
  import type {AppContext} from '~/shared/context.ts';
@@ -1,12 +1,6 @@
1
1
  import {createOptionalContext} from '@quilted/quilt/context';
2
- import type {Router} from '@quilted/quilt/navigate';
3
2
 
4
- export interface AppContext {
5
- /**
6
- * The router used to control navigation throughout the application.
7
- */
8
- readonly router: Router;
9
- }
3
+ export interface AppContext {}
10
4
 
11
5
  export const AppContextReact = createOptionalContext<AppContext>();
12
6
  export const useAppContext = AppContextReact.use;
@@ -0,0 +1,15 @@
1
+ import type {Router} from '@quilted/quilt/navigation';
2
+ import {createContextRouteFunction} from '@quilted/quilt/navigation';
3
+
4
+ import type {AppContext} from '~/shared/context.ts';
5
+
6
+ declare module '~/shared/context.ts' {
7
+ interface AppContext {
8
+ /**
9
+ * The router used to control navigation throughout the application.
10
+ */
11
+ readonly router: Router;
12
+ }
13
+ }
14
+
15
+ export const routeWithAppContext = createContextRouteFunction<AppContext>();
@@ -2,7 +2,7 @@ import {Suspense} from 'preact/compat';
2
2
 
3
3
  import {createRender} from '@quilted/quilt/testing';
4
4
  import {BrowserContext, BrowserTestMock} from '@quilted/quilt/browser/testing';
5
- import {TestRouting, TestRouter} from '@quilted/quilt/navigate/testing';
5
+ import {Navigation, TestRouter} from '@quilted/quilt/navigation/testing';
6
6
  import {Localization} from '@quilted/quilt/localize';
7
7
  import {GraphQLCache} from '@quilted/quilt/graphql';
8
8
 
@@ -34,24 +34,26 @@ export const renderApp = createRender<
34
34
  return {
35
35
  router,
36
36
  browser,
37
- graphql,
38
- fetchGraphQL: graphql.fetch,
39
- graphQLCache,
37
+ graphql: {fetch: graphql.fetch, cache: graphQLCache},
38
+ graphQLController: graphql,
40
39
  };
41
40
  },
42
41
  // Render all of our app-wide context providers around each component under test.
43
42
  render(element, context, {locale = 'en'}) {
44
- const {router, browser, graphql, graphQLCache} = context;
43
+ const {router, browser, graphql, graphQLController} = context;
45
44
 
46
45
  return (
47
46
  <AppContextReact.Provider value={context}>
48
47
  <BrowserContext browser={browser}>
49
48
  <Localization locale={locale}>
50
- <TestRouting router={router}>
51
- <GraphQLTesting controller={graphql} cache={graphQLCache}>
49
+ <Navigation router={router}>
50
+ <GraphQLTesting
51
+ controller={graphQLController}
52
+ cache={graphql.cache}
53
+ >
52
54
  <Suspense fallback={null}>{element}</Suspense>
53
55
  </GraphQLTesting>
54
- </TestRouting>
56
+ </Navigation>
55
57
  </Localization>
56
58
  </BrowserContext>
57
59
  </AppContextReact.Provider>
@@ -64,7 +66,7 @@ export const renderApp = createRender<
64
66
  // once the data is ready.
65
67
 
66
68
  await wrapper.act(async () => {
67
- await wrapper.context.graphql.resolveAll();
69
+ await wrapper.context.graphQLController.resolveAll();
68
70
  });
69
71
  },
70
72
  });
@@ -1,4 +1,4 @@
1
- import type {TestRouter} from '@quilted/quilt/navigate/testing';
1
+ import type {TestRouter} from '@quilted/quilt/navigation/testing';
2
2
  import type {BrowserTestMock} from '@quilted/quilt/browser/testing';
3
3
  import type {GraphQLCache} from '@quilted/quilt/graphql';
4
4
 
@@ -68,12 +68,7 @@ export interface RenderContext extends AppContext {
68
68
  /**
69
69
  * The GraphQL controller used for this component test.
70
70
  */
71
- readonly graphql: GraphQLController;
72
-
73
- /**
74
- * The cache of GraphQL query results.
75
- */
76
- readonly graphQLCache: GraphQLCache;
71
+ readonly graphQLController: GraphQLController;
77
72
  }
78
73
 
79
74
  export interface RenderActions extends Record<string, never> {}
@@ -1,6 +1,6 @@
1
1
  import '@quilted/quilt/testing';
2
2
 
3
- export {TestRouter} from '@quilted/quilt/navigate/testing';
3
+ export {TestRouter} from '@quilted/quilt/navigation/testing';
4
4
 
5
5
  export * from './render/types.ts';
6
6
  export {renderApp} from './render/render.tsx';
@@ -1,8 +1,8 @@
1
1
  import type {RenderableProps} from 'preact';
2
2
 
3
3
  import {NotFound} from '@quilted/quilt/server';
4
- import {Navigation, route} from '@quilted/quilt/navigate';
5
- import {Localization, useLocaleFromEnvironment} from '@quilted/quilt/localize';
4
+ import {Navigation} from '@quilted/quilt/navigation';
5
+ import {Localization} from '@quilted/quilt/localize';
6
6
 
7
7
  import {ReactQueryContext} from '@quilted/react-query';
8
8
 
@@ -16,6 +16,7 @@ import {
16
16
  AppContextReact,
17
17
  type AppContext as AppContextType,
18
18
  } from './shared/context.ts';
19
+ import {routeWithAppContext} from './shared/navigation.ts';
19
20
 
20
21
  export interface AppProps {
21
22
  context: AppContextType;
@@ -24,16 +25,16 @@ export interface AppProps {
24
25
  // Define the routes for your application. If you have a lot of routes, you
25
26
  // might want to split this into a separate file.
26
27
  const routes = [
27
- route('*', {
28
+ routeWithAppContext('*', {
28
29
  render: (children) => <Frame>{children}</Frame>,
29
30
  children: [
30
- route('/', {
31
+ routeWithAppContext('/', {
31
32
  async load() {
32
33
  await Promise.all([Home.load()]);
33
34
  },
34
35
  render: <Home />,
35
36
  }),
36
- route('*', {render: <NotFound />}),
37
+ routeWithAppContext('*', {render: <NotFound />}),
37
38
  ],
38
39
  }),
39
40
  ];
@@ -44,7 +45,7 @@ export function App({context}: AppProps) {
44
45
  return (
45
46
  <AppContext context={context}>
46
47
  <HTML>
47
- <Navigation routes={routes} context={context} />
48
+ <Navigation router={context.router} routes={routes} context={context} />
48
49
  </HTML>
49
50
  </AppContext>
50
51
  );
@@ -54,11 +55,9 @@ export default App;
54
55
 
55
56
  // This component renders any app-wide context.
56
57
  function AppContext({children, context}: RenderableProps<AppProps>) {
57
- const locale = useLocaleFromEnvironment() ?? 'en';
58
-
59
58
  return (
60
59
  <AppContextReact.Provider value={context}>
61
- <Localization locale={locale}>
60
+ <Localization>
62
61
  <trpc.Provider client={context.trpc} queryClient={context.queryClient}>
63
62
  <ReactQueryContext client={context.queryClient}>
64
63
  {children}
@@ -4,7 +4,7 @@ import {hydrate} from 'preact';
4
4
  import {httpBatchLink} from '@trpc/client';
5
5
  import {QueryClient} from '@tanstack/react-query';
6
6
  import {Browser, BrowserContext} from '@quilted/quilt/browser';
7
- import {Router} from '@quilted/quilt/navigate';
7
+ import {Router} from '@quilted/quilt/navigation';
8
8
 
9
9
  import type {AppContext} from '~/shared/context.ts';
10
10
  import {trpc} from '~/shared/trpc.ts';
@@ -31,7 +31,7 @@ router.get(async (request) => {
31
31
  await Promise.all([
32
32
  import('./App.tsx'),
33
33
  import('@quilted/quilt/server'),
34
- import('@quilted/quilt/navigate'),
34
+ import('@quilted/quilt/navigation'),
35
35
  import('@tanstack/react-query'),
36
36
  ]);
37
37
 
@@ -1,12 +1,6 @@
1
1
  import {createOptionalContext} from '@quilted/quilt/context';
2
- import type {Router} from '@quilted/quilt/navigate';
3
2
 
4
- export interface AppContext {
5
- /**
6
- * The router used to control navigation throughout the application.
7
- */
8
- readonly router: Router;
9
- }
3
+ export interface AppContext {}
10
4
 
11
5
  export const AppContextReact = createOptionalContext<AppContext>();
12
6
  export const useAppContext = AppContextReact.use;
@@ -0,0 +1,15 @@
1
+ import type {Router} from '@quilted/quilt/navigation';
2
+ import {createContextRouteFunction} from '@quilted/quilt/navigation';
3
+
4
+ import type {AppContext} from '~/shared/context.ts';
5
+
6
+ declare module '~/shared/context.ts' {
7
+ interface AppContext {
8
+ /**
9
+ * The router used to control navigation throughout the application.
10
+ */
11
+ readonly router: Router;
12
+ }
13
+ }
14
+
15
+ export const routeWithAppContext = createContextRouteFunction<AppContext>();
@@ -1,6 +1,6 @@
1
1
  import {createRender} from '@quilted/quilt/testing';
2
2
  import {BrowserContext, BrowserTestMock} from '@quilted/quilt/browser/testing';
3
- import {TestRouting, TestRouter} from '@quilted/quilt/navigate/testing';
3
+ import {Navigation, TestRouter} from '@quilted/quilt/navigation/testing';
4
4
  import {Localization} from '@quilted/quilt/localize';
5
5
 
6
6
  import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
@@ -39,13 +39,13 @@ export const renderApp = createRender<
39
39
  <AppContextReact.Provider value={context}>
40
40
  <BrowserContext browser={browser}>
41
41
  <Localization locale={locale}>
42
- <TestRouting router={router}>
42
+ <Navigation router={router}>
43
43
  <trpc.Provider client={trpcClient} queryClient={queryClient}>
44
44
  <QueryClientProvider client={queryClient}>
45
45
  {element}
46
46
  </QueryClientProvider>
47
47
  </trpc.Provider>
48
- </TestRouting>
48
+ </Navigation>
49
49
  </Localization>
50
50
  </BrowserContext>
51
51
  </AppContextReact.Provider>
@@ -1,4 +1,4 @@
1
- import type {TestRouter} from '@quilted/quilt/navigate/testing';
1
+ import type {TestRouter} from '@quilted/quilt/navigation/testing';
2
2
  import type {BrowserTestMock} from '@quilted/quilt/browser/testing';
3
3
  import type {QueryClient} from '@tanstack/react-query';
4
4
 
@@ -1,6 +1,6 @@
1
1
  import '@quilted/quilt/testing';
2
2
 
3
- export {TestRouter} from '@quilted/quilt/navigate/testing';
3
+ export {TestRouter} from '@quilted/quilt/navigation/testing';
4
4
 
5
5
  export * from './render/types.ts';
6
6
  export {renderApp} from './render/render.tsx';