@quilted/create 0.3.3 → 0.3.4

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 (54) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/esm/_virtual/index7.mjs +2 -2
  3. package/build/esm/_virtual/index8.mjs +2 -2
  4. package/build/esm/node_modules/.pnpm/dir-glob@3.0.1/node_modules/dir-glob/index.mjs +1 -1
  5. package/build/esm/node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/utils/index.mjs +1 -1
  6. package/build/esnext/_virtual/index7.esnext +2 -2
  7. package/build/esnext/_virtual/index8.esnext +2 -2
  8. package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/index.esnext +1 -1
  9. package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/providers/async.esnext +1 -1
  10. package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/providers/sync.esnext +1 -1
  11. package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/settings.esnext +1 -1
  12. package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/index.esnext +1 -1
  13. package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/async.esnext +1 -1
  14. package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/sync.esnext +1 -1
  15. package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/settings.esnext +1 -1
  16. package/build/esnext/node_modules/.pnpm/dir-glob@3.0.1/node_modules/dir-glob/index.esnext +1 -1
  17. package/build/esnext/node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/utils/index.esnext +1 -1
  18. package/build/esnext/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/dist/prompts.esnext +1 -1
  19. package/build/esnext/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/lib/prompts.esnext +1 -1
  20. package/package.json +1 -1
  21. package/templates/app-basic/App.tsx +8 -13
  22. package/templates/app-basic/browser.tsx +1 -1
  23. package/templates/app-basic/context/browser.ts +7 -3
  24. package/templates/app-basic/context/navigation.ts +6 -13
  25. package/templates/app-basic/context/preact.ts +9 -0
  26. package/templates/app-basic/context/server.ts +10 -3
  27. package/templates/app-basic/context/types.ts +20 -1
  28. package/templates/app-basic/package.json +1 -1
  29. package/templates/app-basic/tests/render/render.tsx +17 -22
  30. package/templates/app-basic/tests/render/types.ts +17 -13
  31. package/templates/app-basic/tests/render.ts +1 -1
  32. package/templates/app-empty/package.json +1 -1
  33. package/templates/app-graphql/App.tsx +10 -16
  34. package/templates/app-graphql/browser.tsx +1 -1
  35. package/templates/app-graphql/context/browser.ts +9 -13
  36. package/templates/app-graphql/context/navigation.ts +6 -13
  37. package/templates/app-graphql/context/preact.ts +9 -0
  38. package/templates/app-graphql/context/server.ts +13 -12
  39. package/templates/app-graphql/context/types.ts +23 -6
  40. package/templates/app-graphql/package.json +1 -1
  41. package/templates/app-graphql/tests/render/render.tsx +17 -37
  42. package/templates/app-graphql/tests/render/types.ts +20 -45
  43. package/templates/app-graphql/tests/render.ts +1 -1
  44. package/templates/app-trpc/App.tsx +15 -17
  45. package/templates/app-trpc/browser.tsx +1 -1
  46. package/templates/app-trpc/context/browser.ts +8 -4
  47. package/templates/app-trpc/context/navigation.ts +6 -13
  48. package/templates/app-trpc/context/preact.ts +9 -0
  49. package/templates/app-trpc/context/server.ts +11 -4
  50. package/templates/app-trpc/context/types.ts +27 -3
  51. package/templates/app-trpc/package.json +1 -1
  52. package/templates/app-trpc/tests/render/render.tsx +25 -29
  53. package/templates/app-trpc/tests/render/types.ts +17 -16
  54. package/templates/app-trpc/tests/render.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @quilted/create
2
2
 
3
+ ## 0.3.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`e6fa47e`](https://github.com/lemonmade/quilt/commit/e6fa47e93981ce0eaebbe1546659aaa08cc22689) Thanks [@lemonmade](https://github.com/lemonmade)! - Update Preact and Signal dependencies
8
+
3
9
  ## 0.3.3
4
10
 
5
11
  ### Patch Changes
@@ -1,3 +1,3 @@
1
- var utils = {};
1
+ var dirGlob = {exports: {}};
2
2
 
3
- export { utils as __exports };
3
+ export { dirGlob as __module };
@@ -1,3 +1,3 @@
1
- var dirGlob = {exports: {}};
1
+ var utils = {};
2
2
 
3
- export { dirGlob as __module };
3
+ export { utils as __exports };
@@ -1,4 +1,4 @@
1
- import { __module as dirGlob } from '../../../../../_virtual/index8.mjs';
1
+ import { __module as dirGlob } from '../../../../../_virtual/index7.mjs';
2
2
  import path__default from 'node:path';
3
3
  import { __require as requirePathType } from '../../../path-type@4.0.0/node_modules/path-type/index.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __exports as utils } from '../../../../../../../_virtual/index7.mjs';
1
+ import { __exports as utils } from '../../../../../../../_virtual/index8.mjs';
2
2
  import { __require as requireArray } from './array.mjs';
3
3
  import { __require as requireErrno } from './errno.mjs';
4
4
  import { __require as requireFs } from './fs.mjs';
@@ -1,3 +1,3 @@
1
- var utils = {};
1
+ var dirGlob = {exports: {}};
2
2
 
3
- export { utils as __exports };
3
+ export { dirGlob as __module };
@@ -1,3 +1,3 @@
1
- var dirGlob = {exports: {}};
1
+ var utils = {};
2
2
 
3
- export { dirGlob as __module };
3
+ export { utils as __exports };
@@ -1,4 +1,4 @@
1
- import { __exports as out } from '../../../../../../../_virtual/index11.esnext';
1
+ import { __exports as out } from '../../../../../../../_virtual/index10.esnext';
2
2
  import { __require as requireAsync } from './providers/async.esnext';
3
3
  import { __require as requireSync } from './providers/sync.esnext';
4
4
  import { __require as requireSettings } from './settings.esnext';
@@ -1,4 +1,4 @@
1
- import { __exports as async } from '../../../../../../../../_virtual/async4.esnext';
1
+ import { __exports as async } from '../../../../../../../../_virtual/async3.esnext';
2
2
 
3
3
  var hasRequiredAsync;
4
4
  function requireAsync() {
@@ -1,4 +1,4 @@
1
- import { __exports as sync } from '../../../../../../../../_virtual/sync4.esnext';
1
+ import { __exports as sync } from '../../../../../../../../_virtual/sync3.esnext';
2
2
 
3
3
  var hasRequiredSync;
4
4
  function requireSync() {
@@ -1,4 +1,4 @@
1
- import { __exports as settings } from '../../../../../../../_virtual/settings3.esnext';
1
+ import { __exports as settings } from '../../../../../../../_virtual/settings2.esnext';
2
2
  import { __require as requireFs } from './adapters/fs.esnext';
3
3
 
4
4
  var hasRequiredSettings;
@@ -1,4 +1,4 @@
1
- import { __exports as out } from '../../../../../../../_virtual/index10.esnext';
1
+ import { __exports as out } from '../../../../../../../_virtual/index11.esnext';
2
2
  import { __require as requireAsync } from './providers/async.esnext';
3
3
  import { __require as requireStream } from './providers/stream.esnext';
4
4
  import { __require as requireSync } from './providers/sync.esnext';
@@ -1,4 +1,4 @@
1
- import { __exports as async } from '../../../../../../../../_virtual/async3.esnext';
1
+ import { __exports as async } from '../../../../../../../../_virtual/async4.esnext';
2
2
  import { __require as requireAsync$1 } from '../readers/async.esnext';
3
3
 
4
4
  var hasRequiredAsync;
@@ -1,4 +1,4 @@
1
- import { __exports as sync } from '../../../../../../../../_virtual/sync3.esnext';
1
+ import { __exports as sync } from '../../../../../../../../_virtual/sync4.esnext';
2
2
  import { __require as requireSync$1 } from '../readers/sync.esnext';
3
3
 
4
4
  var hasRequiredSync;
@@ -1,4 +1,4 @@
1
- import { __exports as settings } from '../../../../../../../_virtual/settings2.esnext';
1
+ import { __exports as settings } from '../../../../../../../_virtual/settings3.esnext';
2
2
  import path__default from 'node:path';
3
3
  import { __require as requireOut } from '../../../../../@nodelib_fs.scandir@2.1.5/node_modules/@nodelib/fs.scandir/out/index.esnext';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __module as dirGlob } from '../../../../../_virtual/index8.esnext';
1
+ import { __module as dirGlob } from '../../../../../_virtual/index7.esnext';
2
2
  import path__default from 'node:path';
3
3
  import { __require as requirePathType } from '../../../path-type@4.0.0/node_modules/path-type/index.esnext';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __exports as utils } from '../../../../../../../_virtual/index7.esnext';
1
+ import { __exports as utils } from '../../../../../../../_virtual/index8.esnext';
2
2
  import { __require as requireArray } from './array.esnext';
3
3
  import { __require as requireErrno } from './errno.esnext';
4
4
  import { __require as requireFs } from './fs.esnext';
@@ -1,4 +1,4 @@
1
- import { __exports as prompts } from '../../../../../../_virtual/prompts2.esnext';
1
+ import { __exports as prompts } from '../../../../../../_virtual/prompts.esnext';
2
2
  import { __require as requireElements } from './elements/index.esnext';
3
3
 
4
4
  var hasRequiredPrompts;
@@ -1,4 +1,4 @@
1
- import { __exports as prompts } from '../../../../../../_virtual/prompts.esnext';
1
+ import { __exports as prompts } from '../../../../../../_virtual/prompts2.esnext';
2
2
  import { __require as requireElements } from './elements/index.esnext';
3
3
 
4
4
  var hasRequiredPrompts;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quilted/create",
3
3
  "type": "module",
4
- "version": "0.3.3",
4
+ "version": "0.3.4",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  import {NotFound} from '@quilted/quilt/server';
2
- import {Navigation} from '@quilted/quilt/navigation';
3
- import {Localization} from '@quilted/quilt/localize';
2
+ import {Routes} from '@quilted/quilt/navigation';
3
+ import {QuiltFrameworkContext} from '@quilted/quilt/context';
4
4
 
5
5
  import {Head} from './foundation/html.ts';
6
6
  import {Frame} from './foundation/frame.ts';
@@ -15,8 +15,6 @@ export interface AppProps {
15
15
  context: AppContext;
16
16
  }
17
17
 
18
- // Define the routes for your application. If you have a lot of routes, you
19
- // might want to split this into a separate file.
20
18
  const routes = [
21
19
  routeWithAppContext('*', {
22
20
  render: (children) => <Frame>{children}</Frame>,
@@ -32,19 +30,16 @@ const routes = [
32
30
  }),
33
31
  ];
34
32
 
35
- // The root component for your application. You will typically render any
36
- // app-wide context in this component.
37
33
  export function App({context}: AppProps) {
38
34
  return (
39
35
  <AppContextPreact.Provider value={context}>
40
- <Localization>
36
+ <QuiltFrameworkContext
37
+ navigation={context.navigation}
38
+ localization={context.localization}
39
+ >
41
40
  <Head />
42
- <Navigation
43
- router={context.navigation.router}
44
- routes={routes}
45
- context={context}
46
- />
47
- </Localization>
41
+ <Routes list={routes} context={context} />
42
+ </QuiltFrameworkContext>
48
43
  </AppContextPreact.Provider>
49
44
  );
50
45
  }
@@ -14,7 +14,7 @@ const app = new BrowserApp(<App context={context} />, {context});
14
14
  // @example
15
15
  // ```js
16
16
  // // Log the current URL
17
- // console.log(globalThis.app.context.router.currentRequest.url);
17
+ // console.log(globalThis.app.context.navigation.currentRequest.url);
18
18
  // ```
19
19
  Object.defineProperty(globalThis, 'app', {
20
20
  value: app,
@@ -1,10 +1,14 @@
1
+ import {Navigation} from '@quilted/quilt/navigation';
2
+ import {Localization} from '@quilted/quilt/localize';
3
+
1
4
  import type {AppContext} from './types.ts';
2
- import {NavigationForApp} from './navigation.ts';
3
5
 
4
6
  export class BrowserAppContext implements AppContext {
5
- readonly navigation: NavigationForApp;
7
+ readonly navigation: Navigation;
8
+ readonly localization: Localization;
6
9
 
7
10
  constructor() {
8
- this.navigation = new NavigationForApp();
11
+ this.navigation = new Navigation();
12
+ this.localization = new Localization(navigator.language);
9
13
  }
10
14
  }
@@ -1,17 +1,10 @@
1
- import {createContextRouteFunction, Router} from '@quilted/quilt/navigation';
1
+ import {
2
+ createContextRouteFunction,
3
+ Navigation,
4
+ } from '@quilted/quilt/navigation';
2
5
 
3
6
  import type {AppContext} from './types.ts';
4
7
 
5
- export interface Navigation {
6
- readonly router: Router;
7
- }
8
-
9
- export class NavigationForApp implements Navigation {
10
- readonly router: Router;
11
-
12
- constructor(url?: string | URL) {
13
- this.router = new Router(url);
14
- }
15
- }
16
-
17
8
  export const routeWithAppContext = createContextRouteFunction<AppContext>();
9
+
10
+ export {Navigation};
@@ -2,5 +2,14 @@ import {createOptionalContext} from '@quilted/quilt/context';
2
2
 
3
3
  import type {AppContext} from './types.ts';
4
4
 
5
+ /**
6
+ * The Preact context object for this application's shared context.
7
+ * Provide it in `App.tsx` via `<AppContextPreact.Provider value={context}>`.
8
+ */
5
9
  export const AppContextPreact = createOptionalContext<AppContext>();
10
+
11
+ /**
12
+ * Returns the app's shared context. All fields in `AppContext` are required
13
+ * and will be available anywhere inside `<AppContextPreact.Provider>`.
14
+ */
6
15
  export const useAppContext = AppContextPreact.use;
@@ -1,10 +1,17 @@
1
+ import {Navigation} from '@quilted/quilt/navigation';
2
+ import {Localization, parseAcceptLanguageHeader} from '@quilted/quilt/localize';
3
+
1
4
  import type {AppContext} from './types.ts';
2
- import {NavigationForApp} from './navigation.ts';
3
5
 
4
6
  export class ServerAppContext implements AppContext {
5
- readonly navigation: NavigationForApp;
7
+ readonly navigation: Navigation;
8
+ readonly localization: Localization;
6
9
 
7
10
  constructor(request: Request) {
8
- this.navigation = new NavigationForApp(request.url);
11
+ this.navigation = new Navigation(request.url);
12
+ this.localization = new Localization(
13
+ parseAcceptLanguageHeader(request.headers.get('Accept-Language') ?? '') ??
14
+ 'en',
15
+ );
9
16
  }
10
17
  }
@@ -1,5 +1,24 @@
1
- import type {Navigation} from './navigation.ts';
1
+ import type {Navigation} from '@quilted/quilt/navigation';
2
+ import type {Localization} from '@quilted/quilt/localize';
2
3
 
4
+ /**
5
+ * The shared context for this application. Values in this object are
6
+ * available to all components in the app via `useQuiltContext()` hooks
7
+ * or the `useAppContext()` convenience hook.
8
+ *
9
+ * This interface extends a subset of `QuiltContext`, providing the
10
+ * navigation and localization fields as required (non-optional) values.
11
+ */
3
12
  export interface AppContext {
13
+ /**
14
+ * The navigation instance for this application. Manages the current URL,
15
+ * browser history, and programmatic navigation.
16
+ */
4
17
  readonly navigation: Navigation;
18
+
19
+ /**
20
+ * The localization instance for this application. Contains the active
21
+ * locale and formatting utilities for numbers, dates, currencies, and more.
22
+ */
23
+ readonly localization: Localization;
5
24
  }
@@ -18,7 +18,7 @@
18
18
  "@quilted/quilt": "^0.9.0",
19
19
  "hono": "^4.8.0",
20
20
  "jsdom": "^26.0.0",
21
- "preact": "^10.26.0",
21
+ "preact": "^10.29.0",
22
22
  "react": "npm:@quilted/react@^19.0.0",
23
23
  "react-dom": "npm:@quilted/react-dom@^19.0.0"
24
24
  },
@@ -1,12 +1,8 @@
1
1
  import {createRender} from '@quilted/quilt/testing';
2
- import {
3
- BrowserDetailsContext,
4
- BrowserTestMock,
5
- } from '@quilted/quilt/browser/testing';
6
- import {Navigation, TestRouter} from '@quilted/quilt/navigation/testing';
2
+ import {TestBrowser} from '@quilted/quilt/browser/testing';
3
+ import {TestNavigation} from '@quilted/quilt/navigation/testing';
7
4
  import {Localization} from '@quilted/quilt/localize';
8
-
9
- import {AppContextPreact} from '~/context/preact.ts';
5
+ import {QuiltFrameworkTestContext} from '@quilted/quilt/context/testing';
10
6
 
11
7
  import {RenderOptions, RenderContext, RenderActions} from './types.ts';
12
8
 
@@ -23,24 +19,23 @@ export const renderApp = createRender<
23
19
  // Create context that can be used by the `render` function, and referenced by test
24
20
  // authors on the `root.context` property. Context is used to share data between your
25
21
  // React tree and your test code, and is ideal for mocking out global context providers.
26
- context({router = new TestRouter(), browser = new BrowserTestMock()}) {
27
- return {navigation: {router}, browser};
22
+ context({
23
+ navigation = new TestNavigation(),
24
+ browser = new TestBrowser(),
25
+ localization = new Localization('en'),
26
+ }) {
27
+ return {navigation, browser, localization};
28
28
  },
29
29
  // Render all of our app-wide context providers around each component under test.
30
- render(element, context, {locale = 'en'}) {
31
- const {
32
- navigation: {router},
33
- browser,
34
- } = context;
35
-
30
+ render(element, {navigation, browser, localization}) {
36
31
  return (
37
- <AppContextPreact.Provider value={context}>
38
- <BrowserDetailsContext.Provider value={browser}>
39
- <Localization locale={locale}>
40
- <Navigation router={router}>{element}</Navigation>
41
- </Localization>
42
- </BrowserDetailsContext.Provider>
43
- </AppContextPreact.Provider>
32
+ <QuiltFrameworkTestContext
33
+ navigation={navigation}
34
+ browser={browser}
35
+ localization={localization}
36
+ >
37
+ {element}
38
+ </QuiltFrameworkTestContext>
44
39
  );
45
40
  },
46
41
  async afterRender() {
@@ -1,38 +1,42 @@
1
- import type {TestRouter} from '@quilted/quilt/navigation/testing';
2
- import type {BrowserTestMock} from '@quilted/quilt/browser/testing';
3
-
4
- import type {AppContext} from '~/context/types.ts';
1
+ import type {TestNavigation} from '@quilted/quilt/navigation/testing';
2
+ import type {TestBrowser} from '@quilted/quilt/browser/testing';
3
+ import type {Localization} from '@quilted/quilt/localize';
5
4
 
6
5
  export interface RenderOptions {
7
6
  /**
8
- * A custom router to use for this component test. You can use a
7
+ * A custom navigation to use for this component test. You can use a
9
8
  * custom router to simulate a particular URL, and you can spy on
10
9
  * its navigation method to check that components navigate as
11
10
  * you expect.
12
11
  */
13
- readonly router?: TestRouter;
12
+ readonly navigation?: TestNavigation;
14
13
 
15
14
  /**
16
15
  * A custom environment for this component test.
17
16
  */
18
- readonly browser?: BrowserTestMock;
17
+ readonly browser?: TestBrowser;
19
18
 
20
19
  /**
21
- * A custom locale to use for this component test.
20
+ * A custom localization instance to use for this component test.
22
21
  */
23
- readonly locale?: string;
22
+ readonly localization?: Localization;
24
23
  }
25
24
 
26
- export interface RenderContext extends AppContext {
25
+ export interface RenderContext {
27
26
  /**
28
- * The router used for this component test.
27
+ * The navigation used for this component test.
29
28
  */
30
- readonly navigation: {router: TestRouter};
29
+ readonly navigation: TestNavigation;
31
30
 
32
31
  /**
33
32
  * The browser environment for this component test.
34
33
  */
35
- readonly browser: BrowserTestMock;
34
+ readonly browser: TestBrowser;
35
+
36
+ /**
37
+ * The localization used for this component test.
38
+ */
39
+ readonly localization: Localization;
36
40
  }
37
41
 
38
42
  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/navigation/testing';
3
+ export {TestNavigation} from '@quilted/quilt/navigation/testing';
4
4
 
5
5
  export * from './render/types.ts';
6
6
  export {renderApp} from './render/render.tsx';
@@ -17,7 +17,7 @@
17
17
  "devDependencies": {
18
18
  "@quilted/quilt": "^0.9.0",
19
19
  "hono": "^4.8.0",
20
- "preact": "^10.26.0",
20
+ "preact": "^10.29.0",
21
21
  "react": "npm:@quilted/react@^19.0.0",
22
22
  "react-dom": "npm:@quilted/react-dom@^19.0.0"
23
23
  },
@@ -1,7 +1,6 @@
1
1
  import {NotFound} from '@quilted/quilt/server';
2
- import {GraphQLContext} from '@quilted/quilt/graphql';
3
- import {Navigation} from '@quilted/quilt/navigation';
4
- import {Localization} from '@quilted/quilt/localize';
2
+ import {Routes} from '@quilted/quilt/navigation';
3
+ import {QuiltFrameworkContext} from '@quilted/quilt/context';
5
4
 
6
5
  import {Head} from './foundation/html.ts';
7
6
  import {Frame} from './foundation/frame.ts';
@@ -24,7 +23,7 @@ const routes = [
24
23
  children: [
25
24
  routeWithAppContext('/', {
26
25
  async load({context: {graphql}}) {
27
- await Promise.all([Home.load(), graphql.cache.query(homeQuery)]);
26
+ await Promise.all([Home.load(), graphql.cache?.query(homeQuery)]);
28
27
  },
29
28
  render: <Home />,
30
29
  }),
@@ -38,19 +37,14 @@ const routes = [
38
37
  export function App({context}: AppProps) {
39
38
  return (
40
39
  <AppContextPreact.Provider value={context}>
41
- <GraphQLContext
42
- fetch={context.graphql.fetch}
43
- cache={context.graphql.cache}
40
+ <QuiltFrameworkContext
41
+ navigation={context.navigation}
42
+ localization={context.localization}
43
+ graphql={context.graphql}
44
44
  >
45
- <Localization>
46
- <Head />
47
- <Navigation
48
- router={context.navigation.router}
49
- routes={routes}
50
- context={context}
51
- />
52
- </Localization>
53
- </GraphQLContext>
45
+ <Head />
46
+ <Routes list={routes} context={context} />
47
+ </QuiltFrameworkContext>
54
48
  </AppContextPreact.Provider>
55
49
  );
56
50
  }
@@ -15,7 +15,7 @@ const app = new BrowserApp(<App context={context} />, {context});
15
15
  // @example
16
16
  // ```js
17
17
  // // Log the current URL
18
- // console.log(globalThis.app.context.navigation.router.currentRequest.url);
18
+ // console.log(globalThis.app.context.navigation.currentRequest.url);
19
19
  // ```
20
20
  Object.defineProperty(globalThis, 'app', {
21
21
  value: app,
@@ -1,21 +1,17 @@
1
- import {createGraphQLFetch, GraphQLCache} from '@quilted/quilt/graphql';
1
+ import {Navigation} from '@quilted/quilt/navigation';
2
+ import {Localization} from '@quilted/quilt/localize';
3
+ import {createGraphQLFetch, GraphQLClient} from '@quilted/quilt/graphql';
2
4
 
3
5
  import type {AppContext} from './types.ts';
4
- import {NavigationForApp} from './navigation.ts';
5
6
 
6
7
  export class BrowserAppContext implements AppContext {
7
- readonly navigation: NavigationForApp;
8
- readonly graphql: AppContext['graphql'];
8
+ readonly navigation: Navigation;
9
+ readonly localization: Localization;
10
+ readonly graphql: GraphQLClient;
9
11
 
10
12
  constructor() {
11
- this.navigation = new NavigationForApp();
12
-
13
- const graphQLFetch = createGraphQLFetch({url: '/api/graphql'});
14
- const graphQLCache = new GraphQLCache({fetch: graphQLFetch});
15
-
16
- this.graphql = {
17
- fetch: graphQLFetch,
18
- cache: graphQLCache,
19
- };
13
+ this.navigation = new Navigation();
14
+ this.localization = new Localization(navigator.language);
15
+ this.graphql = new GraphQLClient(createGraphQLFetch({url: '/api/graphql'}));
20
16
  }
21
17
  }
@@ -1,17 +1,10 @@
1
- import {createContextRouteFunction, Router} from '@quilted/quilt/navigation';
1
+ import {
2
+ createContextRouteFunction,
3
+ Navigation,
4
+ } from '@quilted/quilt/navigation';
2
5
 
3
6
  import type {AppContext} from './types.ts';
4
7
 
5
- export interface Navigation {
6
- readonly router: Router;
7
- }
8
-
9
- export class NavigationForApp implements Navigation {
10
- readonly router: Router;
11
-
12
- constructor(url?: string | URL) {
13
- this.router = new Router(url);
14
- }
15
- }
16
-
17
8
  export const routeWithAppContext = createContextRouteFunction<AppContext>();
9
+
10
+ export {Navigation};
@@ -2,5 +2,14 @@ import {createOptionalContext} from '@quilted/quilt/context';
2
2
 
3
3
  import type {AppContext} from './types.ts';
4
4
 
5
+ /**
6
+ * The Preact context object for this application's shared context.
7
+ * Provide it in `App.tsx` via `<AppContextPreact.Provider value={context}>`.
8
+ */
5
9
  export const AppContextPreact = createOptionalContext<AppContext>();
10
+
11
+ /**
12
+ * Returns the app's shared context. All fields in `AppContext` are required
13
+ * and will be available anywhere inside `<AppContextPreact.Provider>`.
14
+ */
6
15
  export const useAppContext = AppContextPreact.use;
@@ -1,23 +1,24 @@
1
- import {GraphQLCache} from '@quilted/quilt/graphql';
1
+ import {Navigation} from '@quilted/quilt/navigation';
2
+ import {Localization, parseAcceptLanguageHeader} from '@quilted/quilt/localize';
3
+ import {GraphQLClient} from '@quilted/quilt/graphql';
2
4
 
3
5
  import type {AppContext} from './types.ts';
4
- import {NavigationForApp} from './navigation.ts';
5
6
 
6
7
  export class ServerAppContext implements AppContext {
7
- readonly navigation: NavigationForApp;
8
- readonly graphql: AppContext['graphql'];
8
+ readonly navigation: Navigation;
9
+ readonly localization: Localization;
10
+ readonly graphql: GraphQLClient;
9
11
 
10
12
  constructor(request: Request) {
11
- this.navigation = new NavigationForApp(request.url);
13
+ this.navigation = new Navigation(request.url);
14
+ this.localization = new Localization(
15
+ parseAcceptLanguageHeader(request.headers.get('Accept-Language') ?? '') ??
16
+ 'en',
17
+ );
12
18
 
13
- const graphQLFetch: AppContext['graphql']['fetch'] = async (...args) => {
19
+ this.graphql = new GraphQLClient(async (...args) => {
14
20
  const {performGraphQLOperation} = await import('../server/graphql.ts');
15
21
  return performGraphQLOperation(...args);
16
- };
17
-
18
- this.graphql = {
19
- fetch: graphQLFetch,
20
- cache: new GraphQLCache({fetch: graphQLFetch}),
21
- };
22
+ });
22
23
  }
23
24
  }