@quilted/quilt 0.9.0 → 0.9.2
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 +258 -0
- package/build/esm/context/QuiltFrameworkContext.mjs +109 -0
- package/build/esm/context/testing.mjs +40 -0
- package/build/esm/context.mjs +2 -1
- package/build/esnext/context/QuiltFrameworkContext.esnext +92 -0
- package/build/esnext/context/testing.esnext +33 -0
- package/build/esnext/context.esnext +2 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/context/QuiltFrameworkContext.d.ts +66 -0
- package/build/typescript/context/QuiltFrameworkContext.d.ts.map +1 -0
- package/build/typescript/context/testing.d.ts +41 -0
- package/build/typescript/context/testing.d.ts.map +1 -0
- package/build/typescript/context.d.ts +2 -1
- package/build/typescript/context.d.ts.map +1 -1
- package/package.json +29 -20
- package/source/context/QuiltFrameworkContext.tsx +176 -0
- package/source/context/testing.tsx +77 -0
- package/source/context.ts +14 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,263 @@
|
|
|
1
1
|
# @quilted/quilt
|
|
2
2
|
|
|
3
|
+
## 0.9.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#894](https://github.com/lemonmade/quilt/pull/894) [`fb998d1`](https://github.com/lemonmade/quilt/commit/fb998d1d0a7fb7981184daa5307320477355ace8) Thanks [@lemonmade](https://github.com/lemonmade)! - Consolidate all framework context into a unified `QuiltContext` architecture.
|
|
8
|
+
|
|
9
|
+
Previously, Quilt's context was fragmented across many standalone provider components (`AsyncContext`, `GraphQLContext`, `EmailContext`, etc.), each backed by its own Preact context object. This release consolidates everything into a single `QuiltContext` interface, augmented by each package via TypeScript module declaration merging, and provided by a single `<QuiltFrameworkContext>` component.
|
|
10
|
+
|
|
11
|
+
## Breaking changes
|
|
12
|
+
|
|
13
|
+
### All packages: unified `QuiltContext` interface
|
|
14
|
+
|
|
15
|
+
Each `@quilted/*` package now augments a single `QuiltContext` interface from `@quilted/preact-context` rather than maintaining its own standalone context. If you were accessing any Quilt context values directly via `useContext(SomeSpecificContext)`, switch to the appropriate `use*` hook instead.
|
|
16
|
+
|
|
17
|
+
### `@quilted/preact-router`: `useRouter` renamed to `useNavigation`
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// Before
|
|
21
|
+
import {useRouter} from '@quilted/quilt/navigation';
|
|
22
|
+
const router = useRouter();
|
|
23
|
+
|
|
24
|
+
// After
|
|
25
|
+
import {useNavigation} from '@quilted/quilt/navigation';
|
|
26
|
+
const navigation = useNavigation();
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### `@quilted/preact-router`: `router` QuiltContext field renamed to `navigation`
|
|
30
|
+
|
|
31
|
+
The `QuiltContext` field that holds the navigation instance is now `navigation` instead of `router`. This affects any code that reads the field directly, and the prop name on `<QuiltFrameworkContext>`.
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
// Before
|
|
35
|
+
<QuiltFrameworkContext router={myNavigation} />
|
|
36
|
+
|
|
37
|
+
// After
|
|
38
|
+
<QuiltFrameworkContext navigation={myNavigation} />
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### `@quilted/preact-router`: `TestRouter` renamed to `TestNavigation`
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
// Before
|
|
45
|
+
import {TestRouter} from '@quilted/quilt/navigation/testing';
|
|
46
|
+
|
|
47
|
+
// After
|
|
48
|
+
import {TestNavigation} from '@quilted/quilt/navigation/testing';
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### `@quilted/preact-browser`: `browserDetails` and `browserAssets` QuiltContext fields renamed
|
|
52
|
+
|
|
53
|
+
The `QuiltContext` fields for browser environment details and the asset manifest have shorter, cleaner names:
|
|
54
|
+
|
|
55
|
+
- `browserDetails` → `browser`
|
|
56
|
+
- `browserAssets` → `assets`
|
|
57
|
+
|
|
58
|
+
These affect the props on `<QuiltFrameworkContext>` and any direct reads of the context.
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
// Before
|
|
62
|
+
<QuiltFrameworkContext browserDetails={browser} browserAssets={assets} />
|
|
63
|
+
|
|
64
|
+
// After
|
|
65
|
+
<QuiltFrameworkContext browser={browser} assets={assets} />
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### `@quilted/preact-localize`: `localize` QuiltContext field renamed to `localization`
|
|
69
|
+
|
|
70
|
+
The QuiltContext field and the corresponding `<QuiltFrameworkContext>` prop are now `localization`:
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
// Before
|
|
74
|
+
<QuiltFrameworkContext localize={localization} />
|
|
75
|
+
|
|
76
|
+
// After
|
|
77
|
+
<QuiltFrameworkContext localization={localization} />
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### `@quilted/preact-localize`: `createLocalizedFormatting` and `createLocalization` removed
|
|
81
|
+
|
|
82
|
+
These factory functions have been removed. Use the `Localization` class directly:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
// Before
|
|
86
|
+
import {createLocalization} from '@quilted/preact-localize';
|
|
87
|
+
const localization = createLocalization('en');
|
|
88
|
+
|
|
89
|
+
// After
|
|
90
|
+
import {Localization} from '@quilted/preact-localize';
|
|
91
|
+
const localization = new Localization('en');
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### `@quilted/preact-async`: `AsyncContext` component removed
|
|
95
|
+
|
|
96
|
+
The standalone `<AsyncContext>` provider component has been removed. Pass async context directly to `<QuiltFrameworkContext>` instead:
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
// Before
|
|
100
|
+
import {AsyncContext, AsyncActionCache} from '@quilted/quilt/async';
|
|
101
|
+
|
|
102
|
+
<AsyncContext cache={cache}>
|
|
103
|
+
<App />
|
|
104
|
+
</AsyncContext>;
|
|
105
|
+
|
|
106
|
+
// After
|
|
107
|
+
import {QuiltFrameworkContext} from '@quilted/quilt/context';
|
|
108
|
+
import {AsyncActionCache} from '@quilted/quilt/async';
|
|
109
|
+
|
|
110
|
+
<QuiltFrameworkContext async={{cache}}>
|
|
111
|
+
<App />
|
|
112
|
+
</QuiltFrameworkContext>;
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`QuiltFrameworkContext` handles cache serialization for server-side rendering automatically, so no other changes are required.
|
|
116
|
+
|
|
117
|
+
### `@quilted/preact-graphql`: `GraphQLContext` component removed
|
|
118
|
+
|
|
119
|
+
The standalone `<GraphQLContext>` provider component has been removed. The two separate `graphqlRun` and `graphqlCache` props on `<QuiltFrameworkContext>` have been replaced with a single `graphql` prop that accepts a `GraphQLClient` instance (or any object with `fetch` and `cache` properties):
|
|
120
|
+
|
|
121
|
+
```tsx
|
|
122
|
+
// Before
|
|
123
|
+
import {GraphQLContext} from '@quilted/quilt/graphql';
|
|
124
|
+
|
|
125
|
+
<QuiltFrameworkContext navigation={navigation}>
|
|
126
|
+
<GraphQLContext fetch={myFetch} cache={myCache}>
|
|
127
|
+
<App />
|
|
128
|
+
</GraphQLContext>
|
|
129
|
+
</QuiltFrameworkContext>;
|
|
130
|
+
|
|
131
|
+
// After — using the new GraphQLClient class
|
|
132
|
+
import {GraphQLClient} from '@quilted/quilt/graphql';
|
|
133
|
+
|
|
134
|
+
const graphql = new GraphQLClient(myFetch);
|
|
135
|
+
|
|
136
|
+
<QuiltFrameworkContext navigation={navigation} graphql={graphql}>
|
|
137
|
+
<App />
|
|
138
|
+
</QuiltFrameworkContext>;
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### `@quilted/preact-email`: `EmailContext` removed
|
|
142
|
+
|
|
143
|
+
The standalone `EmailContext` Preact context object has been removed. Email components should use the new `useEmailManager()` hook to access the email manager, which reads from the unified `QuiltContext`:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
// Before
|
|
147
|
+
import {useContext} from 'preact/hooks';
|
|
148
|
+
import {EmailContext} from '@quilted/preact-email';
|
|
149
|
+
const email = useContext(EmailContext);
|
|
150
|
+
|
|
151
|
+
// After
|
|
152
|
+
import {useEmailManager} from '@quilted/preact-email';
|
|
153
|
+
const email = useEmailManager();
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### `@quilted/quilt`: `QuiltContext` component renamed to `QuiltFrameworkContext`
|
|
157
|
+
|
|
158
|
+
The provider component is now named `QuiltFrameworkContext` to avoid a name clash with the `QuiltContext` TypeScript interface:
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
// Before
|
|
162
|
+
import {QuiltContext} from '@quilted/quilt/context';
|
|
163
|
+
<QuiltContext navigation={navigation}>...</QuiltContext>;
|
|
164
|
+
|
|
165
|
+
// After
|
|
166
|
+
import {QuiltFrameworkContext} from '@quilted/quilt/context';
|
|
167
|
+
<QuiltFrameworkContext navigation={navigation}>...</QuiltFrameworkContext>;
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### `@quilted/quilt`: `QuiltTestContext` renamed to `QuiltFrameworkTestContext`, takes `localization` instead of `locale`
|
|
171
|
+
|
|
172
|
+
The test context helper component is now `QuiltFrameworkTestContext` and accepts a `Localization` instance directly instead of a locale string:
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
// Before
|
|
176
|
+
import {QuiltTestContext} from '@quilted/quilt/context/testing';
|
|
177
|
+
<QuiltTestContext locale="fr">...</QuiltTestContext>;
|
|
178
|
+
|
|
179
|
+
// After
|
|
180
|
+
import {QuiltFrameworkTestContext} from '@quilted/quilt/context/testing';
|
|
181
|
+
import {Localization} from '@quilted/quilt/localize';
|
|
182
|
+
<QuiltFrameworkTestContext localization={new Localization('fr')}>
|
|
183
|
+
...
|
|
184
|
+
</QuiltFrameworkTestContext>;
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## New features
|
|
188
|
+
|
|
189
|
+
### `@quilted/graphql`: `GraphQLClient` class
|
|
190
|
+
|
|
191
|
+
A new `GraphQLClient` class bundles a GraphQL fetch function and an optional result cache into a single object. A cache is created automatically by default, configured to use the same fetch function:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import {createGraphQLFetch, GraphQLClient} from '@quilted/quilt/graphql';
|
|
195
|
+
|
|
196
|
+
// Cache created automatically from the fetch function
|
|
197
|
+
const client = new GraphQLClient(createGraphQLFetch({url: '/graphql'}));
|
|
198
|
+
|
|
199
|
+
// Disable caching
|
|
200
|
+
const client = new GraphQLClient(myFetch, {cache: false});
|
|
201
|
+
|
|
202
|
+
// Share an existing cache
|
|
203
|
+
const cache = new GraphQLCache();
|
|
204
|
+
const client = new GraphQLClient(myFetch, {cache});
|
|
205
|
+
|
|
206
|
+
// Use the client
|
|
207
|
+
client.fetch(MyQuery, {variables: {id: '1'}});
|
|
208
|
+
client.cache?.query(MyQuery, {variables: {id: '1'}});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### `@quilted/preact-router`: `useNavigation()` hook
|
|
212
|
+
|
|
213
|
+
The renamed `useNavigation()` hook returns the active `Navigation` instance from context, providing access to the current URL, navigation history, and programmatic navigation.
|
|
214
|
+
|
|
215
|
+
### `@quilted/preact-email`: `useEmailManager()` hook
|
|
216
|
+
|
|
217
|
+
A new `useEmailManager()` hook provides access to the `EmailManager` instance from the unified `QuiltContext`. Returns `undefined` outside of an email rendering context.
|
|
218
|
+
|
|
219
|
+
### `@quilted/preact-async`: signal-backed `async.isHydrated`
|
|
220
|
+
|
|
221
|
+
The `AsyncContext` interface (accessed via `useQuiltContext('async')`) now includes an `isHydrated` boolean getter backed by a Preact signal. Any component that reads `async.isHydrated` will automatically re-render when the client hydration completes, without requiring a manual signal subscription.
|
|
222
|
+
|
|
223
|
+
### `@quilted/localize`: `Localization` class documentation
|
|
224
|
+
|
|
225
|
+
The `Localization` class now has full JSDoc documentation on the class, constructor, all properties (`locale`, `direction`, `numberFormatter`, `dateTimeFormatter`), and all methods (`formatNumber`, `formatCurrency`, `formatDate`).
|
|
226
|
+
|
|
227
|
+
- Updated dependencies [[`fb998d1`](https://github.com/lemonmade/quilt/commit/fb998d1d0a7fb7981184daa5307320477355ace8)]:
|
|
228
|
+
- @quilted/graphql@3.4.0
|
|
229
|
+
- @quilted/preact-performance@0.1.3
|
|
230
|
+
- @quilted/preact-localize@0.4.2
|
|
231
|
+
- @quilted/preact-browser@0.2.7
|
|
232
|
+
- @quilted/preact-context@0.1.5
|
|
233
|
+
- @quilted/preact-graphql@0.1.10
|
|
234
|
+
- @quilted/preact-router@0.2.16
|
|
235
|
+
- @quilted/preact-async@0.1.23
|
|
236
|
+
|
|
237
|
+
## 0.9.1
|
|
238
|
+
|
|
239
|
+
### Patch Changes
|
|
240
|
+
|
|
241
|
+
- [`e6fa47e`](https://github.com/lemonmade/quilt/commit/e6fa47e93981ce0eaebbe1546659aaa08cc22689) Thanks [@lemonmade](https://github.com/lemonmade)! - Update Preact and Signal dependencies
|
|
242
|
+
|
|
243
|
+
- Updated dependencies [[`b1df5da`](https://github.com/lemonmade/quilt/commit/b1df5daff8441f8435a62b02b4ad3676d3ddcc3b), [`06b43bc`](https://github.com/lemonmade/quilt/commit/06b43bc44d271ce30798dc0b582870208bae1572), [`e6fa47e`](https://github.com/lemonmade/quilt/commit/e6fa47e93981ce0eaebbe1546659aaa08cc22689)]:
|
|
244
|
+
- @quilted/preact-browser@0.2.6
|
|
245
|
+
- @quilted/assets@0.1.11
|
|
246
|
+
- @quilted/preact-router@0.2.15
|
|
247
|
+
- @quilted/preact-performance@0.1.2
|
|
248
|
+
- @quilted/preact-localize@0.4.1
|
|
249
|
+
- @quilted/preact-context@0.1.4
|
|
250
|
+
- @quilted/preact-graphql@0.1.9
|
|
251
|
+
- @quilted/preact-signals@0.1.3
|
|
252
|
+
- @quilted/preact-testing@0.1.9
|
|
253
|
+
- @quilted/preact-workers@0.2.2
|
|
254
|
+
- @quilted/preact-async@0.1.22
|
|
255
|
+
- @quilted/react-dom@19.0.2
|
|
256
|
+
- @quilted/graphql@3.3.10
|
|
257
|
+
- @quilted/signals@0.2.4
|
|
258
|
+
- @quilted/threads@4.0.2
|
|
259
|
+
- @quilted/events@2.1.4
|
|
260
|
+
|
|
3
261
|
## 0.9.0
|
|
4
262
|
|
|
5
263
|
### Minor Changes
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useContext, useMemo, useLayoutEffect } from 'preact/hooks';
|
|
2
|
+
import { QuiltFrameworkContextPreact } from '@quilted/preact-context';
|
|
3
|
+
import { HTMLAttributes } from '@quilted/preact-browser';
|
|
4
|
+
import { signal } from '@quilted/preact-signals';
|
|
5
|
+
import { useAsyncActionCacheSerialization } from '@quilted/preact-async';
|
|
6
|
+
import { jsxs, Fragment, jsx } from 'preact/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Provides a `QuiltContext` value to the component tree. Accepts any declared
|
|
10
|
+
* `QuiltContext` fields as props and memoizes the context object so that
|
|
11
|
+
* consumers only re-render when a field they use actually changes.
|
|
12
|
+
*
|
|
13
|
+
* Also manages async hydration tracking and optional async action cache
|
|
14
|
+
* serialization — no separate `<AsyncContext>` needed.
|
|
15
|
+
*
|
|
16
|
+
* Use this component at the root of your application to provide navigation,
|
|
17
|
+
* localization, browser details, and other app-wide context.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* <QuiltFrameworkContext navigation={context.navigation} localization={context.localization}>
|
|
21
|
+
* <App />
|
|
22
|
+
* </QuiltFrameworkContext>
|
|
23
|
+
*/
|
|
24
|
+
function QuiltFrameworkContext({
|
|
25
|
+
navigation,
|
|
26
|
+
navigationEntry,
|
|
27
|
+
localization,
|
|
28
|
+
browser,
|
|
29
|
+
assets,
|
|
30
|
+
performance,
|
|
31
|
+
async: asyncProp,
|
|
32
|
+
graphql,
|
|
33
|
+
children
|
|
34
|
+
}) {
|
|
35
|
+
const parentContext = useContext(QuiltFrameworkContextPreact);
|
|
36
|
+
const asyncValue = useAsyncContext(asyncProp);
|
|
37
|
+
const memoizedValue = useMemo(() => ({
|
|
38
|
+
...parentContext,
|
|
39
|
+
...(navigation == null ? undefined : {
|
|
40
|
+
navigation
|
|
41
|
+
}),
|
|
42
|
+
...(navigationEntry == null ? undefined : {
|
|
43
|
+
navigationEntry
|
|
44
|
+
}),
|
|
45
|
+
...(localization == null ? undefined : {
|
|
46
|
+
localization
|
|
47
|
+
}),
|
|
48
|
+
...(browser == null ? undefined : {
|
|
49
|
+
browser
|
|
50
|
+
}),
|
|
51
|
+
...(assets == null ? undefined : {
|
|
52
|
+
assets
|
|
53
|
+
}),
|
|
54
|
+
...(performance == null ? undefined : {
|
|
55
|
+
performance
|
|
56
|
+
}),
|
|
57
|
+
async: asyncValue,
|
|
58
|
+
...(graphql == null ? undefined : {
|
|
59
|
+
graphql
|
|
60
|
+
})
|
|
61
|
+
}), [parentContext, navigation, navigationEntry, localization, browser, assets, performance, asyncValue, graphql]);
|
|
62
|
+
if (typeof document !== 'object') {
|
|
63
|
+
if (navigation?.cache) {
|
|
64
|
+
// Serialize the navigation cache for server-side rendering.
|
|
65
|
+
useAsyncActionCacheSerialization(navigation.cache, {
|
|
66
|
+
name: 'quilt:router'
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return jsxs(Fragment, {
|
|
71
|
+
children: [localization && jsx(HTMLAttributes, {
|
|
72
|
+
lang: localization.locale,
|
|
73
|
+
dir: localization.direction
|
|
74
|
+
}), jsx(QuiltFrameworkContextPreact.Provider, {
|
|
75
|
+
value: memoizedValue,
|
|
76
|
+
children: children
|
|
77
|
+
})]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function useAsyncContext({
|
|
81
|
+
cache: asyncCache,
|
|
82
|
+
components: asyncComponents,
|
|
83
|
+
serialize: asyncSerialize = true
|
|
84
|
+
} = {}) {
|
|
85
|
+
// Hydration signal: starts false on the server, flips to true after
|
|
86
|
+
// the first client-side render. Stable across re-renders via useRef.
|
|
87
|
+
const hydratedSignal = useMemo(() => signal(false), []);
|
|
88
|
+
if (typeof document === 'object') {
|
|
89
|
+
useLayoutEffect(() => {
|
|
90
|
+
hydratedSignal.value = true;
|
|
91
|
+
}, []);
|
|
92
|
+
}
|
|
93
|
+
if (typeof document !== 'object') {
|
|
94
|
+
// Serialize the async action cache for server-side rendering.
|
|
95
|
+
useAsyncActionCacheSerialization(asyncSerialize ? asyncCache : undefined, {
|
|
96
|
+
name: 'quilt:async',
|
|
97
|
+
optional: true
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return useMemo(() => ({
|
|
101
|
+
cache: asyncCache,
|
|
102
|
+
components: asyncComponents,
|
|
103
|
+
get isHydrated() {
|
|
104
|
+
return hydratedSignal.value;
|
|
105
|
+
}
|
|
106
|
+
}), [asyncCache, asyncComponents, hydratedSignal]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { QuiltFrameworkContext };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useMemo } from 'preact/hooks';
|
|
2
|
+
import { QuiltFrameworkContextPreact } from '@quilted/preact-context';
|
|
3
|
+
import { TestNavigation } from '@quilted/preact-router/testing';
|
|
4
|
+
import { TestBrowser } from '@quilted/preact-browser/testing';
|
|
5
|
+
import { Localization } from '@quilted/preact-localize';
|
|
6
|
+
import { jsx } from 'preact/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Provides a `QuiltContext` configured with test-friendly instances of
|
|
10
|
+
* navigation, localization, and browser details. Use this in unit tests
|
|
11
|
+
* to wrap components that need Quilt context.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const navigation = new TestNavigation('/my-page');
|
|
15
|
+
* render(
|
|
16
|
+
* <QuiltFrameworkTestContext navigation={navigation} localization={new Localization('fr')}>
|
|
17
|
+
* <MyComponent />
|
|
18
|
+
* </QuiltFrameworkTestContext>
|
|
19
|
+
* );
|
|
20
|
+
*/
|
|
21
|
+
function QuiltFrameworkTestContext({
|
|
22
|
+
navigation,
|
|
23
|
+
localization = new Localization('en'),
|
|
24
|
+
browser,
|
|
25
|
+
children
|
|
26
|
+
}) {
|
|
27
|
+
const resolvedNavigation = useMemo(() => navigation ?? new TestNavigation(), [navigation]);
|
|
28
|
+
const resolvedBrowser = useMemo(() => browser ?? new TestBrowser(), [browser]);
|
|
29
|
+
const value = useMemo(() => ({
|
|
30
|
+
navigation: resolvedNavigation,
|
|
31
|
+
localization,
|
|
32
|
+
browser: resolvedBrowser
|
|
33
|
+
}), [resolvedNavigation, localization, resolvedBrowser]);
|
|
34
|
+
return jsx(QuiltFrameworkContextPreact.Provider, {
|
|
35
|
+
value: value,
|
|
36
|
+
children: children
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { QuiltFrameworkTestContext };
|
package/build/esm/context.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { QuiltFrameworkContextPreact, createOptionalContext, useQuiltContext } from '@quilted/preact-context';
|
|
2
|
+
export { QuiltFrameworkContext } from './context/QuiltFrameworkContext.mjs';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'preact/jsx-runtime';
|
|
2
|
+
import { useContext, useMemo, useLayoutEffect } from 'preact/hooks';
|
|
3
|
+
import { QuiltFrameworkContextPreact } from '@quilted/preact-context';
|
|
4
|
+
import { HTMLAttributes } from '@quilted/preact-browser';
|
|
5
|
+
import { signal } from '@quilted/preact-signals';
|
|
6
|
+
import { useAsyncActionCacheSerialization } from '@quilted/preact-async';
|
|
7
|
+
|
|
8
|
+
function QuiltFrameworkContext({
|
|
9
|
+
navigation,
|
|
10
|
+
navigationEntry,
|
|
11
|
+
localization,
|
|
12
|
+
browser,
|
|
13
|
+
assets,
|
|
14
|
+
performance,
|
|
15
|
+
async: asyncProp,
|
|
16
|
+
graphql,
|
|
17
|
+
children
|
|
18
|
+
}) {
|
|
19
|
+
const parentContext = useContext(QuiltFrameworkContextPreact);
|
|
20
|
+
const asyncValue = useAsyncContext(asyncProp);
|
|
21
|
+
const memoizedValue = useMemo(
|
|
22
|
+
() => ({
|
|
23
|
+
...parentContext,
|
|
24
|
+
...navigation == null ? void 0 : { navigation },
|
|
25
|
+
...navigationEntry == null ? void 0 : { navigationEntry },
|
|
26
|
+
...localization == null ? void 0 : { localization },
|
|
27
|
+
...browser == null ? void 0 : { browser },
|
|
28
|
+
...assets == null ? void 0 : { assets },
|
|
29
|
+
...performance == null ? void 0 : { performance },
|
|
30
|
+
async: asyncValue,
|
|
31
|
+
...graphql == null ? void 0 : { graphql }
|
|
32
|
+
}),
|
|
33
|
+
[
|
|
34
|
+
parentContext,
|
|
35
|
+
navigation,
|
|
36
|
+
navigationEntry,
|
|
37
|
+
localization,
|
|
38
|
+
browser,
|
|
39
|
+
assets,
|
|
40
|
+
performance,
|
|
41
|
+
asyncValue,
|
|
42
|
+
graphql
|
|
43
|
+
]
|
|
44
|
+
);
|
|
45
|
+
if (typeof document !== "object") {
|
|
46
|
+
if (navigation?.cache) {
|
|
47
|
+
useAsyncActionCacheSerialization(navigation.cache, {
|
|
48
|
+
name: "quilt:router"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
53
|
+
localization && /* @__PURE__ */ jsx(
|
|
54
|
+
HTMLAttributes,
|
|
55
|
+
{
|
|
56
|
+
lang: localization.locale,
|
|
57
|
+
dir: localization.direction
|
|
58
|
+
}
|
|
59
|
+
),
|
|
60
|
+
/* @__PURE__ */ jsx(QuiltFrameworkContextPreact.Provider, { value: memoizedValue, children })
|
|
61
|
+
] });
|
|
62
|
+
}
|
|
63
|
+
function useAsyncContext({
|
|
64
|
+
cache: asyncCache,
|
|
65
|
+
components: asyncComponents,
|
|
66
|
+
serialize: asyncSerialize = true
|
|
67
|
+
} = {}) {
|
|
68
|
+
const hydratedSignal = useMemo(() => signal(false), []);
|
|
69
|
+
if (typeof document === "object") {
|
|
70
|
+
useLayoutEffect(() => {
|
|
71
|
+
hydratedSignal.value = true;
|
|
72
|
+
}, []);
|
|
73
|
+
}
|
|
74
|
+
if (typeof document !== "object") {
|
|
75
|
+
useAsyncActionCacheSerialization(asyncSerialize ? asyncCache : void 0, {
|
|
76
|
+
name: "quilt:async",
|
|
77
|
+
optional: true
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return useMemo(
|
|
81
|
+
() => ({
|
|
82
|
+
cache: asyncCache,
|
|
83
|
+
components: asyncComponents,
|
|
84
|
+
get isHydrated() {
|
|
85
|
+
return hydratedSignal.value;
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
[asyncCache, asyncComponents, hydratedSignal]
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { QuiltFrameworkContext };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx } from 'preact/jsx-runtime';
|
|
2
|
+
import { useMemo } from 'preact/hooks';
|
|
3
|
+
import { QuiltFrameworkContextPreact } from '@quilted/preact-context';
|
|
4
|
+
import { TestNavigation } from '@quilted/preact-router/testing';
|
|
5
|
+
import { TestBrowser } from '@quilted/preact-browser/testing';
|
|
6
|
+
import { Localization } from '@quilted/preact-localize';
|
|
7
|
+
|
|
8
|
+
function QuiltFrameworkTestContext({
|
|
9
|
+
navigation,
|
|
10
|
+
localization = new Localization("en"),
|
|
11
|
+
browser,
|
|
12
|
+
children
|
|
13
|
+
}) {
|
|
14
|
+
const resolvedNavigation = useMemo(
|
|
15
|
+
() => navigation ?? new TestNavigation(),
|
|
16
|
+
[navigation]
|
|
17
|
+
);
|
|
18
|
+
const resolvedBrowser = useMemo(
|
|
19
|
+
() => browser ?? new TestBrowser(),
|
|
20
|
+
[browser]
|
|
21
|
+
);
|
|
22
|
+
const value = useMemo(
|
|
23
|
+
() => ({
|
|
24
|
+
navigation: resolvedNavigation,
|
|
25
|
+
localization,
|
|
26
|
+
browser: resolvedBrowser
|
|
27
|
+
}),
|
|
28
|
+
[resolvedNavigation, localization, resolvedBrowser]
|
|
29
|
+
);
|
|
30
|
+
return /* @__PURE__ */ jsx(QuiltFrameworkContextPreact.Provider, { value, children });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { QuiltFrameworkTestContext };
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { QuiltFrameworkContextPreact, createOptionalContext, useQuiltContext } from '@quilted/preact-context';
|
|
2
|
+
export { QuiltFrameworkContext } from './context/QuiltFrameworkContext.esnext';
|