@quilted/quilt 0.0.0-Simpler-Quilt-app-context-component-20220421223224

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 (191) hide show
  1. package/CHANGELOG.md +189 -0
  2. package/build/cjs/AppContext.cjs +22 -0
  3. package/build/cjs/email.cjs +32 -0
  4. package/build/cjs/env.cjs +7 -0
  5. package/build/cjs/global.cjs +5 -0
  6. package/build/cjs/html.cjs +112 -0
  7. package/build/cjs/http-handlers/index.cjs +14 -0
  8. package/build/cjs/http-handlers/node.cjs +14 -0
  9. package/build/cjs/http.cjs +108 -0
  10. package/build/cjs/index.cjs +187 -0
  11. package/build/cjs/matchers.cjs +5 -0
  12. package/build/cjs/polyfills/base.cjs +4 -0
  13. package/build/cjs/polyfills/crypto.cjs +4 -0
  14. package/build/cjs/polyfills/fetch.cjs +4 -0
  15. package/build/cjs/polyfills/noop.cjs +4 -0
  16. package/build/cjs/react/index.cjs +22 -0
  17. package/build/cjs/react/jsx-runtime.cjs +14 -0
  18. package/build/cjs/react/server.cjs +14 -0
  19. package/build/cjs/react/test-utils.cjs +14 -0
  20. package/build/cjs/server/ServerContext.cjs +22 -0
  21. package/build/cjs/server/http-handler.cjs +87 -0
  22. package/build/cjs/server/index.cjs +89 -0
  23. package/build/cjs/server/render.cjs +46 -0
  24. package/build/cjs/static/StaticContext.cjs +22 -0
  25. package/build/cjs/static/index.cjs +306 -0
  26. package/build/cjs/static/render.cjs +46 -0
  27. package/build/cjs/testing.cjs +42 -0
  28. package/build/cjs/utilities/react.cjs +14 -0
  29. package/build/cjs/workers/index.cjs +14 -0
  30. package/build/cjs/workers/worker.cjs +14 -0
  31. package/build/esm/AppContext.mjs +18 -0
  32. package/build/esm/email.mjs +1 -0
  33. package/build/esm/env.mjs +3 -0
  34. package/build/esm/global.mjs +3 -0
  35. package/build/esm/html.mjs +1 -0
  36. package/build/esm/http-handlers/index.mjs +1 -0
  37. package/build/esm/http-handlers/node.mjs +1 -0
  38. package/build/esm/http.mjs +1 -0
  39. package/build/esm/index.mjs +11 -0
  40. package/build/esm/matchers.mjs +2 -0
  41. package/build/esm/polyfills/base.mjs +1 -0
  42. package/build/esm/polyfills/crypto.mjs +1 -0
  43. package/build/esm/polyfills/fetch.mjs +1 -0
  44. package/build/esm/polyfills/noop.mjs +1 -0
  45. package/build/esm/react/index.mjs +2 -0
  46. package/build/esm/react/jsx-runtime.mjs +1 -0
  47. package/build/esm/react/server.mjs +1 -0
  48. package/build/esm/react/test-utils.mjs +1 -0
  49. package/build/esm/server/ServerContext.mjs +18 -0
  50. package/build/esm/server/http-handler.mjs +81 -0
  51. package/build/esm/server/index.mjs +9 -0
  52. package/build/esm/server/render.mjs +42 -0
  53. package/build/esm/static/StaticContext.mjs +18 -0
  54. package/build/esm/static/index.mjs +284 -0
  55. package/build/esm/static/render.mjs +42 -0
  56. package/build/esm/testing.mjs +3 -0
  57. package/build/esm/utilities/react.mjs +10 -0
  58. package/build/esm/workers/index.mjs +1 -0
  59. package/build/esm/workers/worker.mjs +1 -0
  60. package/build/esnext/AppContext.esnext +18 -0
  61. package/build/esnext/email.esnext +1 -0
  62. package/build/esnext/env.esnext +3 -0
  63. package/build/esnext/global.esnext +3 -0
  64. package/build/esnext/html.esnext +1 -0
  65. package/build/esnext/http-handlers/index.esnext +1 -0
  66. package/build/esnext/http-handlers/node.esnext +1 -0
  67. package/build/esnext/http.esnext +1 -0
  68. package/build/esnext/index.esnext +11 -0
  69. package/build/esnext/matchers.esnext +2 -0
  70. package/build/esnext/polyfills/base.esnext +1 -0
  71. package/build/esnext/polyfills/crypto.esnext +1 -0
  72. package/build/esnext/polyfills/fetch.esnext +1 -0
  73. package/build/esnext/polyfills/noop.esnext +1 -0
  74. package/build/esnext/react/index.esnext +2 -0
  75. package/build/esnext/react/jsx-runtime.esnext +1 -0
  76. package/build/esnext/react/server.esnext +1 -0
  77. package/build/esnext/react/test-utils.esnext +1 -0
  78. package/build/esnext/server/ServerContext.esnext +18 -0
  79. package/build/esnext/server/http-handler.esnext +81 -0
  80. package/build/esnext/server/index.esnext +9 -0
  81. package/build/esnext/server/render.esnext +40 -0
  82. package/build/esnext/static/StaticContext.esnext +18 -0
  83. package/build/esnext/static/index.esnext +280 -0
  84. package/build/esnext/static/render.esnext +40 -0
  85. package/build/esnext/testing.esnext +3 -0
  86. package/build/esnext/utilities/react.esnext +10 -0
  87. package/build/esnext/workers/index.esnext +1 -0
  88. package/build/esnext/workers/worker.esnext +1 -0
  89. package/build/tsconfig.tsbuildinfo +1 -0
  90. package/build/typescript/App.d.ts +15 -0
  91. package/build/typescript/App.d.ts.map +1 -0
  92. package/build/typescript/AppContext.d.ts +8 -0
  93. package/build/typescript/AppContext.d.ts.map +1 -0
  94. package/build/typescript/email.d.ts +3 -0
  95. package/build/typescript/email.d.ts.map +1 -0
  96. package/build/typescript/env.d.ts +5 -0
  97. package/build/typescript/env.d.ts.map +1 -0
  98. package/build/typescript/global.d.ts +2 -0
  99. package/build/typescript/global.d.ts.map +1 -0
  100. package/build/typescript/html.d.ts +3 -0
  101. package/build/typescript/html.d.ts.map +1 -0
  102. package/build/typescript/http-handlers/index.d.ts +2 -0
  103. package/build/typescript/http-handlers/index.d.ts.map +1 -0
  104. package/build/typescript/http-handlers/node.d.ts +2 -0
  105. package/build/typescript/http-handlers/node.d.ts.map +1 -0
  106. package/build/typescript/http.d.ts +2 -0
  107. package/build/typescript/http.d.ts.map +1 -0
  108. package/build/typescript/index.d.ts +21 -0
  109. package/build/typescript/index.d.ts.map +1 -0
  110. package/build/typescript/magic/app.d.ts +4 -0
  111. package/build/typescript/magic/app.d.ts.map +1 -0
  112. package/build/typescript/magic/asset-loader.d.ts +6 -0
  113. package/build/typescript/magic/asset-loader.d.ts.map +1 -0
  114. package/build/typescript/magic/http-handler.d.ts +4 -0
  115. package/build/typescript/magic/http-handler.d.ts.map +1 -0
  116. package/build/typescript/matchers.d.ts +3 -0
  117. package/build/typescript/matchers.d.ts.map +1 -0
  118. package/build/typescript/polyfills/base.d.ts +2 -0
  119. package/build/typescript/polyfills/base.d.ts.map +1 -0
  120. package/build/typescript/polyfills/crypto.d.ts +2 -0
  121. package/build/typescript/polyfills/crypto.d.ts.map +1 -0
  122. package/build/typescript/polyfills/fetch.d.ts +2 -0
  123. package/build/typescript/polyfills/fetch.d.ts.map +1 -0
  124. package/build/typescript/polyfills/noop.d.ts +2 -0
  125. package/build/typescript/polyfills/noop.d.ts.map +1 -0
  126. package/build/typescript/react/index.d.ts +3 -0
  127. package/build/typescript/react/index.d.ts.map +1 -0
  128. package/build/typescript/react/jsx-runtime.d.ts +2 -0
  129. package/build/typescript/react/jsx-runtime.d.ts.map +1 -0
  130. package/build/typescript/react/server.d.ts +2 -0
  131. package/build/typescript/react/server.d.ts.map +1 -0
  132. package/build/typescript/react/test-utils.d.ts +2 -0
  133. package/build/typescript/react/test-utils.d.ts.map +1 -0
  134. package/build/typescript/server/ServerContext.d.ts +13 -0
  135. package/build/typescript/server/ServerContext.d.ts.map +1 -0
  136. package/build/typescript/server/http-handler.d.ts +15 -0
  137. package/build/typescript/server/http-handler.d.ts.map +1 -0
  138. package/build/typescript/server/index.d.ts +13 -0
  139. package/build/typescript/server/index.d.ts.map +1 -0
  140. package/build/typescript/server/render.d.ts +17 -0
  141. package/build/typescript/server/render.d.ts.map +1 -0
  142. package/build/typescript/static/StaticContext.d.ts +13 -0
  143. package/build/typescript/static/StaticContext.d.ts.map +1 -0
  144. package/build/typescript/static/index.d.ts +22 -0
  145. package/build/typescript/static/index.d.ts.map +1 -0
  146. package/build/typescript/static/render.d.ts +17 -0
  147. package/build/typescript/static/render.d.ts.map +1 -0
  148. package/build/typescript/testing.d.ts +4 -0
  149. package/build/typescript/testing.d.ts.map +1 -0
  150. package/build/typescript/utilities/react.d.ts +3 -0
  151. package/build/typescript/utilities/react.d.ts.map +1 -0
  152. package/build/typescript/workers/index.d.ts +2 -0
  153. package/build/typescript/workers/index.d.ts.map +1 -0
  154. package/build/typescript/workers/worker.d.ts +2 -0
  155. package/build/typescript/workers/worker.d.ts.map +1 -0
  156. package/package.json +282 -0
  157. package/quilt.project.ts +48 -0
  158. package/source/AppContext.tsx +21 -0
  159. package/source/email.ts +9 -0
  160. package/source/env.ts +5 -0
  161. package/source/global.ts +3 -0
  162. package/source/html.ts +29 -0
  163. package/source/http-handlers/index.ts +1 -0
  164. package/source/http-handlers/node.ts +1 -0
  165. package/source/http.ts +27 -0
  166. package/source/index.ts +103 -0
  167. package/source/magic/app.ts +5 -0
  168. package/source/magic/asset-loader.ts +5 -0
  169. package/source/magic/http-handler.ts +5 -0
  170. package/source/matchers.ts +2 -0
  171. package/source/polyfills/README.md +3 -0
  172. package/source/polyfills/base.ts +1 -0
  173. package/source/polyfills/crypto.ts +1 -0
  174. package/source/polyfills/fetch.ts +1 -0
  175. package/source/polyfills/noop.ts +1 -0
  176. package/source/react/index.ts +4 -0
  177. package/source/react/jsx-runtime.ts +2 -0
  178. package/source/react/server.ts +2 -0
  179. package/source/react/test-utils.ts +2 -0
  180. package/source/server/ServerContext.tsx +42 -0
  181. package/source/server/http-handler.tsx +101 -0
  182. package/source/server/index.ts +45 -0
  183. package/source/server/render.tsx +43 -0
  184. package/source/static/StaticContext.tsx +42 -0
  185. package/source/static/index.tsx +307 -0
  186. package/source/static/render.tsx +43 -0
  187. package/source/testing.ts +7 -0
  188. package/source/utilities/react.tsx +13 -0
  189. package/source/workers/index.ts +1 -0
  190. package/source/workers/worker.ts +1 -0
  191. package/tsconfig.json +30 -0
@@ -0,0 +1,18 @@
1
+ import { InitialUrlContext } from '@quilted/react-router';
2
+ import { HtmlContext } from '@quilted/react-html/server';
3
+ import { AsyncAssetContext } from '@quilted/react-async/server';
4
+ import { HttpServerContext } from '@quilted/react-http/server';
5
+ import { maybeWrapContext } from '../utilities/react.mjs';
6
+
7
+ function StaticContext({
8
+ url,
9
+ html,
10
+ http,
11
+ asyncAssets,
12
+ children
13
+ }) {
14
+ const normalizedUrl = typeof url === 'string' ? new URL(url) : url;
15
+ return maybeWrapContext(AsyncAssetContext, asyncAssets, maybeWrapContext(HttpServerContext, http, maybeWrapContext(HtmlContext, html, maybeWrapContext(InitialUrlContext, normalizedUrl, children))));
16
+ }
17
+
18
+ export { StaticContext };
@@ -0,0 +1,284 @@
1
+ import { render, Html } from '@quilted/react-html/server';
2
+ import { StaticRenderer, StaticRendererContext } from '@quilted/react-router/static';
3
+ import { renderApp } from './render.mjs';
4
+ import { jsx } from 'react/jsx-runtime';
5
+
6
+ const BASE_URL = 'http://localhost:3000';
7
+ async function renderStatic(App, {
8
+ assets,
9
+ routes: startingRoutes,
10
+ onRender,
11
+ crawl = true,
12
+ baseUrl = BASE_URL,
13
+ prettify = true
14
+ }) {
15
+ const routesToHandle = startingRoutes.map(route => ({
16
+ route: removePostfixSlash(new URL(route, baseUrl).pathname),
17
+ fallback: false
18
+ }));
19
+ const seenRoutes = [...routesToHandle];
20
+ const seenRouteIds = new Set(seenRoutes.map(({
21
+ route
22
+ }) => route));
23
+ let renderableRoute;
24
+
25
+ while (renderableRoute = routesToHandle.shift()) {
26
+ const {
27
+ route,
28
+ fallback
29
+ } = renderableRoute;
30
+ const url = new URL(route, baseUrl);
31
+ const {
32
+ html,
33
+ http,
34
+ routes
35
+ } = await renderUrl(url, {
36
+ fallback
37
+ });
38
+
39
+ if (crawl) {
40
+ for (const {
41
+ routes: routeDefinitions,
42
+ fallback = false,
43
+ consumedPath,
44
+ prefix
45
+ } of routes) {
46
+ var _routeDefinitions;
47
+
48
+ const basePathname = joinPath(prefix, consumedPath);
49
+ const baseId = basePathname === '/' ? basePathname : `__QUILT_BASE_${basePathname}__`;
50
+
51
+ for (const routeDefinition of routeDefinitions) {
52
+ await recordRouteDefinition(routeDefinition, {
53
+ baseId,
54
+ basePathname,
55
+ addFallbacks: fallback
56
+ });
57
+ }
58
+
59
+ if (fallback && ((_routeDefinitions = routeDefinitions[routeDefinitions.length - 1]) === null || _routeDefinitions === void 0 ? void 0 : _routeDefinitions.match) != null) {
60
+ await recordRouteDefinition({}, {
61
+ baseId,
62
+ basePathname,
63
+ addFallbacks: fallback
64
+ });
65
+ }
66
+ }
67
+ }
68
+
69
+ await onRender({
70
+ route,
71
+ content: html,
72
+ http,
73
+ fallback,
74
+ hasChildren: !fallback && seenRoutes.some(otherRoute => otherRoute.route.startsWith(`${route}/`))
75
+ });
76
+ }
77
+
78
+ async function recordRouteDefinition({
79
+ match,
80
+ children,
81
+ renderStatic
82
+ }, {
83
+ basePathname,
84
+ baseId,
85
+ addFallbacks
86
+ }) {
87
+ if (renderStatic === false) return;
88
+ let routeId;
89
+ const hasChildren = children && children.length > 0;
90
+ const hasManualMatches = typeof renderStatic === 'function' && typeof match !== 'string';
91
+ const matchedRoutes = [];
92
+
93
+ if (typeof match === 'string') {
94
+ routeId = joinPath(baseId, match);
95
+ matchedRoutes.push({
96
+ id: routeId,
97
+ route: joinPath(basePathname, match),
98
+ fallback: false
99
+ });
100
+ } else if (typeof match === 'function') {
101
+ routeId = joinPath(baseId, `__QUILT_FUNCTION_ROUTE_${match.toString()}__`);
102
+ } else if (match instanceof RegExp) {
103
+ routeId = joinPath(`__QUILT_REGEX_ROUTE_${match.source}__`);
104
+ } else {
105
+ routeId = joinPath(baseId, '__QUILT_FALLBACK_ROUTE__');
106
+
107
+ if (!hasManualMatches) {
108
+ matchedRoutes.push({
109
+ id: routeId,
110
+ route: basePathname,
111
+ fallback: true
112
+ });
113
+ }
114
+ }
115
+
116
+ if (seenRouteIds.has(routeId)) return;
117
+ seenRouteIds.add(routeId);
118
+
119
+ if (typeof renderStatic === 'function' && typeof match !== 'string') {
120
+ const matchedRouteParts = await renderStatic();
121
+
122
+ for (const routePart of matchedRouteParts) {
123
+ const id = joinPath(baseId, `__QUILT_MATCH_${routePart}__`);
124
+ seenRouteIds.add(id);
125
+ matchedRoutes.push({
126
+ id,
127
+ route: joinPath(basePathname, routePart),
128
+ fallback: false
129
+ });
130
+ }
131
+ }
132
+
133
+ if (hasChildren) {
134
+ for (const {
135
+ id,
136
+ route
137
+ } of matchedRoutes) {
138
+ var _ref;
139
+
140
+ for (const child of children) {
141
+ await recordRouteDefinition(child, {
142
+ addFallbacks,
143
+ basePathname: route,
144
+ baseId: id
145
+ });
146
+ }
147
+
148
+ if (addFallbacks && ((_ref = children[children.length - 1]) === null || _ref === void 0 ? void 0 : _ref.match) != null) {
149
+ await recordRouteDefinition({}, {
150
+ addFallbacks,
151
+ basePathname: route,
152
+ baseId: id
153
+ });
154
+ }
155
+ }
156
+
157
+ return;
158
+ }
159
+
160
+ for (const {
161
+ route,
162
+ fallback
163
+ } of matchedRoutes) {
164
+ const renderableRoute = {
165
+ route,
166
+ fallback
167
+ };
168
+ seenRoutes.push(renderableRoute);
169
+ routesToHandle.push(renderableRoute);
170
+ }
171
+ }
172
+
173
+ async function renderUrl(url, {
174
+ fallback = false
175
+ } = {}) {
176
+ const routeRecorder = new StaticRenderer({
177
+ forceFallback: fallback ? url.pathname : undefined
178
+ });
179
+ const {
180
+ http,
181
+ html: htmlManager,
182
+ markup,
183
+ asyncAssets
184
+ } = await renderApp( /*#__PURE__*/jsx(App, {}), {
185
+ url,
186
+
187
+ decorate(app) {
188
+ return /*#__PURE__*/jsx(StaticRendererContext.Provider, {
189
+ value: routeRecorder,
190
+ children: app
191
+ });
192
+ }
193
+
194
+ });
195
+ const usedAssets = asyncAssets.used({
196
+ timing: 'load'
197
+ });
198
+ const [moduleStyles, moduleScripts, modulePreload, nomoduleStyles, nomoduleScripts] = await Promise.all([assets.styles({
199
+ async: usedAssets,
200
+ options: {
201
+ modules: true
202
+ }
203
+ }), assets.scripts({
204
+ async: usedAssets,
205
+ options: {
206
+ modules: true
207
+ }
208
+ }), assets.asyncAssets(asyncAssets.used({
209
+ timing: 'preload'
210
+ }), {
211
+ options: {
212
+ modules: true
213
+ }
214
+ }), assets.styles({
215
+ async: usedAssets,
216
+ options: {
217
+ modules: false
218
+ }
219
+ }), assets.scripts({
220
+ async: usedAssets,
221
+ options: {
222
+ modules: false
223
+ }
224
+ })]); // We don’t want to load styles from both bundles, so we only use module styles,
225
+ // since modules are intended to be the default and CSS (usually) doesn’t
226
+ // have features that meaningfully break older user agents.
227
+
228
+ const styles = moduleStyles.length > 0 ? moduleStyles : nomoduleStyles; // If there are nomodule scripts, we can’t really do preloading, because we can’t
229
+ // prevent the nomodule scripts from being preloaded in module browsers. If there
230
+ // are only module scripts, we can preload those.
231
+
232
+ const preload = nomoduleScripts.length > 0 ? [] : modulePreload;
233
+ const scripts = [...moduleScripts, ...nomoduleScripts.map(script => ({ ...script,
234
+ nomodule: true
235
+ }))];
236
+ const minifiedHtml = render( /*#__PURE__*/jsx(Html, {
237
+ manager: htmlManager,
238
+ styles: styles,
239
+ scripts: scripts,
240
+ preloadAssets: preload,
241
+ children: markup
242
+ }));
243
+ const html = prettify ? await prettifyHtml(minifiedHtml) : minifiedHtml;
244
+ return {
245
+ html,
246
+ http: http.state,
247
+ routes: routeRecorder.state
248
+ };
249
+ }
250
+ }
251
+
252
+ async function prettifyHtml(html) {
253
+ try {
254
+ const {
255
+ default: prettier
256
+ } = await import('prettier');
257
+ return prettier.format(html, {
258
+ parser: 'html'
259
+ });
260
+ } catch (error) {
261
+ return html;
262
+ }
263
+ }
264
+
265
+ function joinPath(...parts) {
266
+ let path = '/';
267
+
268
+ for (const part of parts) {
269
+ if (typeof part !== 'string') continue;
270
+ const normalizedPart = part.startsWith('/') ? part.slice(1) : part;
271
+ if (normalizedPart.length === 0) continue;
272
+ if (path !== '/') path += '/';
273
+ path += normalizedPart;
274
+ path = removePostfixSlash(path);
275
+ }
276
+
277
+ return path;
278
+ }
279
+
280
+ function removePostfixSlash(value) {
281
+ return value.endsWith('/') && value !== '/' ? value.slice(0, value.length - 1) : value;
282
+ }
283
+
284
+ export { renderStatic };
@@ -0,0 +1,42 @@
1
+ import { extract } from '@quilted/react-server-render/server';
2
+ import { HtmlManager } from '@quilted/react-html/server';
3
+ import { HttpManager } from '@quilted/react-http/server';
4
+ import { AsyncAssetManager } from '@quilted/react-async/server';
5
+ import { StaticContext } from './StaticContext.mjs';
6
+ import { jsx } from 'react/jsx-runtime';
7
+
8
+ async function renderApp(app, {
9
+ decorate,
10
+ url,
11
+ headers,
12
+ ...rest
13
+ } = {}) {
14
+ const html = new HtmlManager();
15
+ const asyncAssets = new AsyncAssetManager();
16
+ const http = new HttpManager({
17
+ headers
18
+ });
19
+ const markup = await extract(app, {
20
+ decorate(app) {
21
+ var _decorate;
22
+
23
+ return /*#__PURE__*/jsx(StaticContext, {
24
+ asyncAssets: asyncAssets,
25
+ html: html,
26
+ http: http,
27
+ url: url,
28
+ children: (_decorate = decorate === null || decorate === void 0 ? void 0 : decorate(app)) !== null && _decorate !== void 0 ? _decorate : app
29
+ });
30
+ },
31
+
32
+ ...rest
33
+ });
34
+ return {
35
+ markup,
36
+ http,
37
+ html,
38
+ asyncAssets
39
+ };
40
+ }
41
+
42
+ export { renderApp };
@@ -0,0 +1,3 @@
1
+ export { createMount, mount, unmountAll } from '@quilted/react-testing';
2
+ export { TestRouter, createTestRouter } from '@quilted/react-router/testing';
3
+ export { TestGraphQL, createFiller, createTestGraphQL } from '@quilted/react-graphql/testing';
@@ -0,0 +1,10 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ function maybeWrapContext(Context, value, children) {
4
+ return value ? /*#__PURE__*/jsx(Context.Provider, {
5
+ value: value,
6
+ children: children
7
+ }) : children;
8
+ }
9
+
10
+ export { maybeWrapContext };
@@ -0,0 +1 @@
1
+ export * from '@quilted/react-workers';
@@ -0,0 +1 @@
1
+ export * from '@quilted/react-workers/worker';
@@ -0,0 +1,18 @@
1
+ import { HttpContext, CookieContext } from '@quilted/react-http';
2
+ import { useHtmlUpdater } from '@quilted/react-html';
3
+ import { jsx } from 'react/jsx-runtime';
4
+
5
+ // TODO: have craft options to remove the bundle impact of parts of this that are
6
+ // unused.
7
+ function AppContext({
8
+ children
9
+ }) {
10
+ useHtmlUpdater();
11
+ return /*#__PURE__*/jsx(HttpContext, {
12
+ children: /*#__PURE__*/jsx(CookieContext, {
13
+ children: children
14
+ })
15
+ });
16
+ }
17
+
18
+ export { AppContext };
@@ -0,0 +1 @@
1
+ export { usePlainTextContent, useSendBcc, useSendCc, useSendTo, useSender, useSubject } from '@quilted/react-email';
@@ -0,0 +1,3 @@
1
+ const Env = {};
2
+
3
+ export { Env as default };
@@ -0,0 +1,3 @@
1
+ import { installAsyncAssetsGlobal } from '@quilted/async';
2
+
3
+ installAsyncAssetsGlobal();
@@ -0,0 +1 @@
1
+ export { Alternate, BodyAttributes, Favicon, HtmlAttributes, Hydrator, Link, Meta, SearchRobots, Serialize, ThemeColor, Title, Viewport, getSerialized, useAlternateUrl, useBodyAttributes, useFavicon, useHtmlAttributes, useHtmlUpdater, useLink, useLocale, useMeta, useSearchRobots, useSerialized, useThemeColor, useTitle, useViewport } from '@quilted/react-html';
@@ -0,0 +1 @@
1
+ export * from '@quilted/http-handlers';
@@ -0,0 +1 @@
1
+ export * from '@quilted/http-handlers/node';
@@ -0,0 +1 @@
1
+ export { CacheControl, ContentSecurityPolicy, ContentSecurityPolicyDirective, ContentSecurityPolicySandboxAllow, ContentSecurityPolicySpecialSource, HttpContext, HttpMethod, NotFound, PermissionsPolicy, ResponseCookie, ResponseHeader, ResponseStatus, ResponseType, StatusCode, StrictTransportSecurity, useCacheControl, useContentSecurityPolicy, useDeleteResponseCookie, usePermissionsPolicy, useRequestHeader, useResponseCookie, useResponseHeader, useResponseRedirect, useResponseStatus, useStrictTransportSecurity } from '@quilted/react-http';
@@ -0,0 +1,11 @@
1
+ export { createAsyncLoader } from '@quilted/async';
2
+ export { createAsyncComponent, useAsync, useAsyncAsset, usePreload } from '@quilted/react-async';
3
+ export { GraphQLContext, createGraphQL, createGraphQLHttpFetch, useGraphQL, useMutation, useQuery } from '@quilted/react-graphql';
4
+ export { useIdleCallback } from '@quilted/react-idle';
5
+ export { ServerAction, useServerAction } from '@quilted/react-server-render';
6
+ export { Localization, useLocale, useLocaleFromEnvironment, useLocalizedFormatting } from '@quilted/react-localize';
7
+ export { PerformanceContext, usePerformance, usePerformanceNavigation } from '@quilted/react-performance';
8
+ export { Link, NavigationBlock, Preloader, Redirect, Router, useCurrentUrl, useInitialUrl, useMatch, useNavigate, useNavigationBlock, useRedirect, useRouteChangeFocusRef, useRouter, useRoutes, useScrollRestoration } from '@quilted/react-router';
9
+ export { createCallableWorker, createWorker, useWorker } from '@quilted/react-workers';
10
+ export { CookieContext, useCookie, useCookies } from '@quilted/react-http';
11
+ export { AppContext } from './AppContext.esnext';
@@ -0,0 +1,2 @@
1
+ import '@quilted/react-testing/matchers';
2
+ import '@quilted/graphql/matchers';
@@ -0,0 +1 @@
1
+ import '@quilted/polyfills/base';
@@ -0,0 +1 @@
1
+ import '@quilted/polyfills/crypto';
@@ -0,0 +1 @@
1
+ import '@quilted/polyfills/fetch';
@@ -0,0 +1 @@
1
+ import '@quilted/polyfills/noop';
@@ -0,0 +1,2 @@
1
+ export * from '@quilted/react';
2
+ export { default } from '@quilted/react';
@@ -0,0 +1 @@
1
+ export * from '@quilted/react/jsx-runtime';
@@ -0,0 +1 @@
1
+ export * from '@quilted/react/server';
@@ -0,0 +1 @@
1
+ export * from '@quilted/react/test-utils';
@@ -0,0 +1,18 @@
1
+ import { InitialUrlContext } from '@quilted/react-router';
2
+ import { HtmlContext } from '@quilted/react-html/server';
3
+ import { AsyncAssetContext } from '@quilted/react-async/server';
4
+ import { HttpServerContext } from '@quilted/react-http/server';
5
+ import { maybeWrapContext } from '../utilities/react.esnext';
6
+
7
+ function ServerContext({
8
+ url,
9
+ html,
10
+ http,
11
+ asyncAssets,
12
+ children
13
+ }) {
14
+ const normalizedUrl = typeof url === 'string' ? new URL(url) : url;
15
+ return maybeWrapContext(AsyncAssetContext, asyncAssets, maybeWrapContext(HttpServerContext, http, maybeWrapContext(HtmlContext, html, maybeWrapContext(InitialUrlContext, normalizedUrl, children))));
16
+ }
17
+
18
+ export { ServerContext };
@@ -0,0 +1,81 @@
1
+ import { render, Html } from '@quilted/react-html/server';
2
+ import { createHttpHandler, redirect, html } from '@quilted/http-handlers';
3
+ import { renderApp } from './render.esnext';
4
+ import { jsx } from 'react/jsx-runtime';
5
+
6
+ function createServerRenderingHttpHandler(App, {
7
+ handler = createHttpHandler(),
8
+ ...options
9
+ }) {
10
+ handler.get(createServerRenderingRequestHandler(App, options));
11
+ return handler;
12
+ }
13
+ function createServerRenderingRequestHandler(App, {
14
+ renderProps,
15
+ ...options
16
+ } = {}) {
17
+ return request => {
18
+ return renderToResponse( /*#__PURE__*/jsx(App, { ...renderProps?.({
19
+ request
20
+ })
21
+ }), request, options);
22
+ };
23
+ }
24
+ async function renderToResponse(element, request, {
25
+ assets,
26
+ ...options
27
+ } = {}) {
28
+ const accepts = request.headers.get('Accept');
29
+ if (accepts != null && !accepts.includes('text/html')) return;
30
+ const {
31
+ html: htmlManager,
32
+ http,
33
+ markup,
34
+ asyncAssets
35
+ } = await renderApp(element, { ...options,
36
+ url: request.url,
37
+ headers: request.headers
38
+ });
39
+ const {
40
+ headers,
41
+ statusCode = 200,
42
+ redirectUrl
43
+ } = http.state;
44
+
45
+ if (redirectUrl) {
46
+ return redirect(redirectUrl, {
47
+ status: statusCode,
48
+ headers
49
+ });
50
+ }
51
+
52
+ const usedAssets = asyncAssets.used({
53
+ timing: 'load'
54
+ });
55
+ const assetOptions = {
56
+ userAgent: request.headers.get('User-Agent')
57
+ };
58
+ const [styles, scripts, preload] = assets ? await Promise.all([assets.styles({
59
+ async: usedAssets,
60
+ options: assetOptions
61
+ }), assets.scripts({
62
+ async: usedAssets,
63
+ options: assetOptions
64
+ }), assets.asyncAssets(asyncAssets.used({
65
+ timing: 'preload'
66
+ }), {
67
+ options: assetOptions
68
+ })]) : [];
69
+ return html(render( /*#__PURE__*/jsx(Html, {
70
+ manager: htmlManager,
71
+ styles: styles,
72
+ scripts: scripts,
73
+ preloadAssets: preload,
74
+ children: markup
75
+ })), {
76
+ headers,
77
+ status: statusCode
78
+ });
79
+ }
80
+
81
+ export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse };
@@ -0,0 +1,9 @@
1
+ export { SERVER_ACTION_ID as HTML_SERVER_ACTION_ID, Html, HtmlContext, HtmlManager, Serialize, render } from '@quilted/react-html/server';
2
+ export { ServerAction, ServerRenderContext, ServerRenderManager, extract, useServerAction } from '@quilted/react-server-render/server';
3
+ export { createAssetLoader } from '@quilted/async/server';
4
+ export { SERVER_ACTION_ID as ASYNC_ASSETS_SERVER_ACTION_ID, AsyncAssetContext, AsyncAssetManager } from '@quilted/react-async/server';
5
+ export { renderEmail } from '@quilted/react-email/server';
6
+ export { createHttpHandler } from '@quilted/http-handlers';
7
+ export { renderApp } from './render.esnext';
8
+ export { ServerContext } from './ServerContext.esnext';
9
+ export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse } from './http-handler.esnext';
@@ -0,0 +1,40 @@
1
+ import { extract } from '@quilted/react-server-render/server';
2
+ import { HtmlManager } from '@quilted/react-html/server';
3
+ import { HttpManager } from '@quilted/react-http/server';
4
+ import { AsyncAssetManager } from '@quilted/react-async/server';
5
+ import { ServerContext } from './ServerContext.esnext';
6
+ import { jsx } from 'react/jsx-runtime';
7
+
8
+ async function renderApp(app, {
9
+ decorate,
10
+ url,
11
+ headers,
12
+ ...rest
13
+ } = {}) {
14
+ const html = new HtmlManager();
15
+ const asyncAssets = new AsyncAssetManager();
16
+ const http = new HttpManager({
17
+ headers
18
+ });
19
+ const markup = await extract(app, {
20
+ decorate(app) {
21
+ return /*#__PURE__*/jsx(ServerContext, {
22
+ asyncAssets: asyncAssets,
23
+ http: http,
24
+ html: html,
25
+ url: url,
26
+ children: decorate?.(app) ?? app
27
+ });
28
+ },
29
+
30
+ ...rest
31
+ });
32
+ return {
33
+ markup,
34
+ http,
35
+ html,
36
+ asyncAssets
37
+ };
38
+ }
39
+
40
+ export { renderApp };
@@ -0,0 +1,18 @@
1
+ import { InitialUrlContext } from '@quilted/react-router';
2
+ import { HtmlContext } from '@quilted/react-html/server';
3
+ import { AsyncAssetContext } from '@quilted/react-async/server';
4
+ import { HttpServerContext } from '@quilted/react-http/server';
5
+ import { maybeWrapContext } from '../utilities/react.esnext';
6
+
7
+ function StaticContext({
8
+ url,
9
+ html,
10
+ http,
11
+ asyncAssets,
12
+ children
13
+ }) {
14
+ const normalizedUrl = typeof url === 'string' ? new URL(url) : url;
15
+ return maybeWrapContext(AsyncAssetContext, asyncAssets, maybeWrapContext(HttpServerContext, http, maybeWrapContext(HtmlContext, html, maybeWrapContext(InitialUrlContext, normalizedUrl, children))));
16
+ }
17
+
18
+ export { StaticContext };