@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.
- package/CHANGELOG.md +6 -0
- package/build/esm/_virtual/index7.mjs +2 -2
- package/build/esm/_virtual/index8.mjs +2 -2
- package/build/esm/node_modules/.pnpm/dir-glob@3.0.1/node_modules/dir-glob/index.mjs +1 -1
- package/build/esm/node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/utils/index.mjs +1 -1
- package/build/esnext/_virtual/index7.esnext +2 -2
- package/build/esnext/_virtual/index8.esnext +2 -2
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/index.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/providers/async.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/providers/sync.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/settings.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/index.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/async.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/sync.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/settings.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/dir-glob@3.0.1/node_modules/dir-glob/index.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/utils/index.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/dist/prompts.esnext +1 -1
- package/build/esnext/node_modules/.pnpm/prompts@2.4.2/node_modules/prompts/lib/prompts.esnext +1 -1
- package/package.json +1 -1
- package/templates/app-basic/App.tsx +8 -13
- package/templates/app-basic/browser.tsx +1 -1
- package/templates/app-basic/context/browser.ts +7 -3
- package/templates/app-basic/context/navigation.ts +6 -13
- package/templates/app-basic/context/preact.ts +9 -0
- package/templates/app-basic/context/server.ts +10 -3
- package/templates/app-basic/context/types.ts +20 -1
- package/templates/app-basic/package.json +1 -1
- package/templates/app-basic/tests/render/render.tsx +17 -22
- package/templates/app-basic/tests/render/types.ts +17 -13
- package/templates/app-basic/tests/render.ts +1 -1
- package/templates/app-empty/package.json +1 -1
- package/templates/app-graphql/App.tsx +10 -16
- package/templates/app-graphql/browser.tsx +1 -1
- package/templates/app-graphql/context/browser.ts +9 -13
- package/templates/app-graphql/context/navigation.ts +6 -13
- package/templates/app-graphql/context/preact.ts +9 -0
- package/templates/app-graphql/context/server.ts +13 -12
- package/templates/app-graphql/context/types.ts +23 -6
- package/templates/app-graphql/package.json +1 -1
- package/templates/app-graphql/tests/render/render.tsx +17 -37
- package/templates/app-graphql/tests/render/types.ts +20 -45
- package/templates/app-graphql/tests/render.ts +1 -1
- package/templates/app-trpc/App.tsx +15 -17
- package/templates/app-trpc/browser.tsx +1 -1
- package/templates/app-trpc/context/browser.ts +8 -4
- package/templates/app-trpc/context/navigation.ts +6 -13
- package/templates/app-trpc/context/preact.ts +9 -0
- package/templates/app-trpc/context/server.ts +11 -4
- package/templates/app-trpc/context/types.ts +27 -3
- package/templates/app-trpc/package.json +1 -1
- package/templates/app-trpc/tests/render/render.tsx +25 -29
- package/templates/app-trpc/tests/render/types.ts +17 -16
- 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
|
|
1
|
+
var dirGlob = {exports: {}};
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { dirGlob as __module };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var utils = {};
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { utils as __exports };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __module as dirGlob } from '../../../../../_virtual/
|
|
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
|
|
package/build/esm/node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/utils/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __exports as utils } from '../../../../../../../_virtual/
|
|
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
|
|
1
|
+
var dirGlob = {exports: {}};
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { dirGlob as __module };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var utils = {};
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { utils as __exports };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __exports as out } from '../../../../../../../_virtual/
|
|
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 out } from '../../../../../../../_virtual/
|
|
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 settings } from '../../../../../../../_virtual/
|
|
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/
|
|
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/
|
|
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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {NotFound} from '@quilted/quilt/server';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
<
|
|
36
|
+
<QuiltFrameworkContext
|
|
37
|
+
navigation={context.navigation}
|
|
38
|
+
localization={context.localization}
|
|
39
|
+
>
|
|
41
40
|
<Head />
|
|
42
|
-
<
|
|
43
|
-
|
|
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.
|
|
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:
|
|
7
|
+
readonly navigation: Navigation;
|
|
8
|
+
readonly localization: Localization;
|
|
6
9
|
|
|
7
10
|
constructor() {
|
|
8
|
-
this.navigation = new
|
|
11
|
+
this.navigation = new Navigation();
|
|
12
|
+
this.localization = new Localization(navigator.language);
|
|
9
13
|
}
|
|
10
14
|
}
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import {
|
|
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:
|
|
7
|
+
readonly navigation: Navigation;
|
|
8
|
+
readonly localization: Localization;
|
|
6
9
|
|
|
7
10
|
constructor(request: Request) {
|
|
8
|
-
this.navigation = new
|
|
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 '
|
|
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
|
}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import {createRender} from '@quilted/quilt/testing';
|
|
2
|
-
import {
|
|
3
|
-
|
|
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({
|
|
27
|
-
|
|
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,
|
|
31
|
-
const {
|
|
32
|
-
navigation: {router},
|
|
33
|
-
browser,
|
|
34
|
-
} = context;
|
|
35
|
-
|
|
30
|
+
render(element, {navigation, browser, localization}) {
|
|
36
31
|
return (
|
|
37
|
-
<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
</
|
|
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 {
|
|
2
|
-
import type {
|
|
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
|
|
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
|
|
12
|
+
readonly navigation?: TestNavigation;
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* A custom environment for this component test.
|
|
17
16
|
*/
|
|
18
|
-
readonly browser?:
|
|
17
|
+
readonly browser?: TestBrowser;
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
|
-
* A custom
|
|
20
|
+
* A custom localization instance to use for this component test.
|
|
22
21
|
*/
|
|
23
|
-
readonly
|
|
22
|
+
readonly localization?: Localization;
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
export interface RenderContext
|
|
25
|
+
export interface RenderContext {
|
|
27
26
|
/**
|
|
28
|
-
* The
|
|
27
|
+
* The navigation used for this component test.
|
|
29
28
|
*/
|
|
30
|
-
readonly navigation:
|
|
29
|
+
readonly navigation: TestNavigation;
|
|
31
30
|
|
|
32
31
|
/**
|
|
33
32
|
* The browser environment for this component test.
|
|
34
33
|
*/
|
|
35
|
-
readonly browser:
|
|
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,7 +1,6 @@
|
|
|
1
1
|
import {NotFound} from '@quilted/quilt/server';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
|
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
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
<QuiltFrameworkContext
|
|
41
|
+
navigation={context.navigation}
|
|
42
|
+
localization={context.localization}
|
|
43
|
+
graphql={context.graphql}
|
|
44
44
|
>
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
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.
|
|
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 {
|
|
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:
|
|
8
|
-
readonly
|
|
8
|
+
readonly navigation: Navigation;
|
|
9
|
+
readonly localization: Localization;
|
|
10
|
+
readonly graphql: GraphQLClient;
|
|
9
11
|
|
|
10
12
|
constructor() {
|
|
11
|
-
this.navigation = new
|
|
12
|
-
|
|
13
|
-
|
|
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 {
|
|
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 {
|
|
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:
|
|
8
|
-
readonly
|
|
8
|
+
readonly navigation: Navigation;
|
|
9
|
+
readonly localization: Localization;
|
|
10
|
+
readonly graphql: GraphQLClient;
|
|
9
11
|
|
|
10
12
|
constructor(request: Request) {
|
|
11
|
-
this.navigation = new
|
|
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
|
-
|
|
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
|
}
|