@quilted/quilt 0.5.107 → 0.5.108

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.
@@ -2,10 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
6
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
7
- var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
8
- var _regeneratorRuntime = require('@babel/runtime/regenerator');
9
5
  var server$3 = require('@quilted/react-server-render/server');
10
6
  var server = require('@quilted/react-html/server');
11
7
  var server$2 = require('@quilted/react-http/server');
@@ -13,77 +9,38 @@ var server$1 = require('@quilted/react-async/server');
13
9
  var StaticContext = require('./StaticContext.cjs');
14
10
  var jsxRuntime = require('react/jsx-runtime');
15
11
 
16
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
-
18
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
19
- var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
20
- var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
21
- var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
22
-
23
- var _excluded = ["decorate", "url", "headers"];
24
-
25
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
26
-
27
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
28
- function renderApp(_x) {
29
- return _renderApp.apply(this, arguments);
30
- }
31
-
32
- function _renderApp() {
33
- _renderApp = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(app) {
34
- var _ref,
35
- _decorate,
36
- url,
37
- headers,
38
- rest,
39
- html,
40
- asyncAssets,
41
- http,
42
- markup,
43
- _args = arguments;
44
-
45
- return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
46
- while (1) {
47
- switch (_context.prev = _context.next) {
48
- case 0:
49
- _ref = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, _decorate = _ref.decorate, url = _ref.url, headers = _ref.headers, rest = _objectWithoutProperties__default["default"](_ref, _excluded);
50
- html = new server.HtmlManager();
51
- asyncAssets = new server$1.AsyncAssetManager();
52
- http = new server$2.HttpManager({
53
- headers: headers
54
- });
55
- _context.next = 6;
56
- return server$3.extract(app, _objectSpread({
57
- decorate: function decorate(app) {
58
- var _decorate2;
59
-
60
- return /*#__PURE__*/jsxRuntime.jsx(StaticContext.StaticContext, {
61
- asyncAssets: asyncAssets,
62
- html: html,
63
- http: http,
64
- url: url,
65
- children: (_decorate2 = _decorate === null || _decorate === void 0 ? void 0 : _decorate(app)) !== null && _decorate2 !== void 0 ? _decorate2 : app
66
- });
67
- }
68
- }, rest));
69
-
70
- case 6:
71
- markup = _context.sent;
72
- return _context.abrupt("return", {
73
- markup: markup,
74
- http: http,
75
- html: html,
76
- asyncAssets: asyncAssets
77
- });
78
-
79
- case 8:
80
- case "end":
81
- return _context.stop();
82
- }
83
- }
84
- }, _callee);
85
- }));
86
- return _renderApp.apply(this, arguments);
12
+ async function renderApp(app, {
13
+ decorate,
14
+ url,
15
+ headers,
16
+ ...rest
17
+ }) {
18
+ const html = new server.HtmlManager();
19
+ const asyncAssets = new server$1.AsyncAssetManager();
20
+ const http = new server$2.HttpManager({
21
+ headers
22
+ });
23
+ const markup = await server$3.extract(app, {
24
+ decorate(app) {
25
+ var _decorate;
26
+
27
+ return /*#__PURE__*/jsxRuntime.jsx(StaticContext.StaticContext, {
28
+ asyncAssets: asyncAssets,
29
+ html: html,
30
+ http: http,
31
+ url: url,
32
+ children: (_decorate = decorate === null || decorate === void 0 ? void 0 : decorate(app)) !== null && _decorate !== void 0 ? _decorate : app
33
+ });
34
+ },
35
+
36
+ ...rest
37
+ });
38
+ return {
39
+ markup,
40
+ http,
41
+ html,
42
+ asyncAssets
43
+ };
87
44
  }
88
45
 
89
46
  exports.renderApp = renderApp;
@@ -4,8 +4,9 @@ import { jsx } from 'react/jsx-runtime';
4
4
 
5
5
  // TODO: have craft options to remove the bundle impact of parts of this that are
6
6
  // unused.
7
- function AppContext(_ref) {
8
- var children = _ref.children;
7
+ function AppContext({
8
+ children
9
+ }) {
9
10
  useHtmlUpdater();
10
11
  return /*#__PURE__*/jsx(HttpContext, {
11
12
  children: /*#__PURE__*/jsx(CookieContext, {
package/build/esm/env.mjs CHANGED
@@ -1,3 +1,3 @@
1
- var Env = {};
1
+ const Env = {};
2
2
 
3
3
  export { Env as default };
@@ -4,13 +4,14 @@ import { AsyncAssetContext } from '@quilted/react-async/server';
4
4
  import { HttpServerContext } from '@quilted/react-http/server';
5
5
  import { maybeWrapContext } from '../utilities/react.mjs';
6
6
 
7
- function ServerContext(_ref) {
8
- var url = _ref.url,
9
- html = _ref.html,
10
- http = _ref.http,
11
- asyncAssets = _ref.asyncAssets,
12
- children = _ref.children;
13
- var normalizedUrl = typeof url === 'string' ? new URL(url) : url;
7
+ function ServerContext({
8
+ url,
9
+ html,
10
+ http,
11
+ asyncAssets,
12
+ children
13
+ }) {
14
+ const normalizedUrl = typeof url === 'string' ? new URL(url) : url;
14
15
  return maybeWrapContext(AsyncAssetContext, asyncAssets, maybeWrapContext(HttpServerContext, http, maybeWrapContext(HtmlContext, html, maybeWrapContext(InitialUrlContext, normalizedUrl, children))));
15
16
  }
16
17
 
@@ -1,192 +1,84 @@
1
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
- import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
4
- import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
- import _regeneratorRuntime from '@babel/runtime/regenerator';
6
1
  import { render, Html } from '@quilted/react-html/server';
7
- import { createHttpHandler, html, redirect } from '@quilted/http-handlers';
2
+ import { createHttpHandler, redirect, html } from '@quilted/http-handlers';
8
3
  import { renderApp } from './render.mjs';
9
4
  import { jsx } from 'react/jsx-runtime';
10
5
 
11
- var _excluded = ["handler"],
12
- _excluded2 = ["context"],
13
- _excluded3 = ["assets"];
14
-
15
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
-
17
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
- function createServerRenderingHttpHandler(render, _ref) {
19
- var _ref$handler = _ref.handler,
20
- handler = _ref$handler === void 0 ? createHttpHandler() : _ref$handler,
21
- options = _objectWithoutProperties(_ref, _excluded);
22
-
6
+ function createServerRenderingHttpHandler(render, {
7
+ handler = createHttpHandler(),
8
+ ...options
9
+ }) {
23
10
  handler.get(createServerRenderingRequestHandler(render, options));
24
11
  return handler;
25
12
  }
26
- function createServerRenderingRequestHandler(render) {
27
- var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
28
- context = _ref2.context,
29
- options = _objectWithoutProperties(_ref2, _excluded2);
30
-
31
- return /*#__PURE__*/function () {
32
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(request, requestContext) {
33
- var _context;
34
-
35
- var app;
36
- return _regeneratorRuntime.wrap(function _callee$(_context2) {
37
- while (1) {
38
- switch (_context2.prev = _context2.next) {
39
- case 0:
40
- _context2.next = 2;
41
- return render(request, requestContext);
42
-
43
- case 2:
44
- app = _context2.sent;
45
- return _context2.abrupt("return", renderToResponse(app, request, _objectSpread(_objectSpread({}, options), {}, {
46
- context: (_context = context === null || context === void 0 ? void 0 : context(request, requestContext)) !== null && _context !== void 0 ? _context : requestContext
47
- })));
48
-
49
- case 4:
50
- case "end":
51
- return _context2.stop();
52
- }
53
- }
54
- }, _callee);
55
- }));
56
-
57
- return function (_x, _x2) {
58
- return _ref3.apply(this, arguments);
59
- };
60
- }();
61
- }
62
- function renderToResponse(_x3, _x4) {
63
- return _renderToResponse.apply(this, arguments);
13
+ function createServerRenderingRequestHandler(render, {
14
+ context,
15
+ ...options
16
+ } = {}) {
17
+ return async (request, requestContext) => {
18
+ var _context;
19
+
20
+ const app = await render(request, requestContext);
21
+ return renderToResponse(app, request, { ...options,
22
+ context: (_context = context === null || context === void 0 ? void 0 : context(request, requestContext)) !== null && _context !== void 0 ? _context : requestContext
23
+ });
24
+ };
64
25
  }
65
-
66
- function _renderToResponse() {
67
- _renderToResponse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(app, request) {
68
- var _ref4,
69
- assets,
70
- options,
71
- accepts,
72
- _yield$renderApp,
73
- htmlManager,
74
- http,
75
- markup,
76
- asyncAssets,
77
- _http$state,
78
- headers,
79
- _http$state$statusCod,
80
- statusCode,
81
- redirectUrl,
82
- usedAssets,
83
- assetOptions,
84
- _ref5,
85
- _ref6,
86
- styles,
87
- scripts,
88
- preload,
89
- _args2 = arguments;
90
-
91
- return _regeneratorRuntime.wrap(function _callee2$(_context3) {
92
- while (1) {
93
- switch (_context3.prev = _context3.next) {
94
- case 0:
95
- _ref4 = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {}, assets = _ref4.assets, options = _objectWithoutProperties(_ref4, _excluded3);
96
- accepts = request.headers.get('Accept');
97
-
98
- if (!(accepts != null && !accepts.includes('text/html'))) {
99
- _context3.next = 4;
100
- break;
101
- }
102
-
103
- return _context3.abrupt("return");
104
-
105
- case 4:
106
- _context3.next = 6;
107
- return renderApp(app, _objectSpread(_objectSpread({}, options), {}, {
108
- url: request.url,
109
- headers: request.headers
110
- }));
111
-
112
- case 6:
113
- _yield$renderApp = _context3.sent;
114
- htmlManager = _yield$renderApp.html;
115
- http = _yield$renderApp.http;
116
- markup = _yield$renderApp.markup;
117
- asyncAssets = _yield$renderApp.asyncAssets;
118
- _http$state = http.state, headers = _http$state.headers, _http$state$statusCod = _http$state.statusCode, statusCode = _http$state$statusCod === void 0 ? 200 : _http$state$statusCod, redirectUrl = _http$state.redirectUrl;
119
-
120
- if (!redirectUrl) {
121
- _context3.next = 14;
122
- break;
123
- }
124
-
125
- return _context3.abrupt("return", redirect(redirectUrl, {
126
- status: statusCode,
127
- headers: headers
128
- }));
129
-
130
- case 14:
131
- usedAssets = asyncAssets.used({
132
- timing: 'load'
133
- });
134
- assetOptions = {
135
- userAgent: request.headers.get('User-Agent')
136
- };
137
-
138
- if (!assets) {
139
- _context3.next = 22;
140
- break;
141
- }
142
-
143
- _context3.next = 19;
144
- return Promise.all([assets.styles({
145
- async: usedAssets,
146
- options: assetOptions
147
- }), assets.scripts({
148
- async: usedAssets,
149
- options: assetOptions
150
- }), assets.asyncAssets(asyncAssets.used({
151
- timing: 'preload'
152
- }), {
153
- options: assetOptions
154
- })]);
155
-
156
- case 19:
157
- _context3.t0 = _context3.sent;
158
- _context3.next = 23;
159
- break;
160
-
161
- case 22:
162
- _context3.t0 = [];
163
-
164
- case 23:
165
- _ref5 = _context3.t0;
166
- _ref6 = _slicedToArray(_ref5, 3);
167
- styles = _ref6[0];
168
- scripts = _ref6[1];
169
- preload = _ref6[2];
170
- return _context3.abrupt("return", html(render( /*#__PURE__*/jsx(Html, {
171
- url: new URL(request.url),
172
- manager: htmlManager,
173
- styles: styles,
174
- scripts: scripts,
175
- preloadAssets: preload,
176
- children: markup
177
- })), {
178
- headers: headers,
179
- status: statusCode
180
- }));
181
-
182
- case 29:
183
- case "end":
184
- return _context3.stop();
185
- }
186
- }
187
- }, _callee2);
188
- }));
189
- return _renderToResponse.apply(this, arguments);
26
+ async function renderToResponse(app, request, {
27
+ assets,
28
+ ...options
29
+ } = {}) {
30
+ const accepts = request.headers.get('Accept');
31
+ if (accepts != null && !accepts.includes('text/html')) return;
32
+ const {
33
+ html: htmlManager,
34
+ http,
35
+ markup,
36
+ asyncAssets
37
+ } = await renderApp(app, { ...options,
38
+ url: request.url,
39
+ headers: request.headers
40
+ });
41
+ const {
42
+ headers,
43
+ statusCode = 200,
44
+ redirectUrl
45
+ } = http.state;
46
+
47
+ if (redirectUrl) {
48
+ return redirect(redirectUrl, {
49
+ status: statusCode,
50
+ headers
51
+ });
52
+ }
53
+
54
+ const usedAssets = asyncAssets.used({
55
+ timing: 'load'
56
+ });
57
+ const assetOptions = {
58
+ userAgent: request.headers.get('User-Agent')
59
+ };
60
+ const [styles, scripts, preload] = assets ? await Promise.all([assets.styles({
61
+ async: usedAssets,
62
+ options: assetOptions
63
+ }), assets.scripts({
64
+ async: usedAssets,
65
+ options: assetOptions
66
+ }), assets.asyncAssets(asyncAssets.used({
67
+ timing: 'preload'
68
+ }), {
69
+ options: assetOptions
70
+ })]) : [];
71
+ return html(render( /*#__PURE__*/jsx(Html, {
72
+ url: new URL(request.url),
73
+ manager: htmlManager,
74
+ styles: styles,
75
+ scripts: scripts,
76
+ preloadAssets: preload,
77
+ children: markup
78
+ })), {
79
+ headers,
80
+ status: statusCode
81
+ });
190
82
  }
191
83
 
192
84
  export { createServerRenderingHttpHandler, createServerRenderingRequestHandler, renderToResponse };
@@ -1,7 +1,3 @@
1
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
- import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
3
- import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
4
- import _regeneratorRuntime from '@babel/runtime/regenerator';
5
1
  import { extract } from '@quilted/react-server-render/server';
6
2
  import { HtmlManager } from '@quilted/react-html/server';
7
3
  import { HttpManager } from '@quilted/react-http/server';
@@ -9,70 +5,38 @@ import { AsyncAssetManager } from '@quilted/react-async/server';
9
5
  import { ServerContext } from './ServerContext.mjs';
10
6
  import { jsx } from 'react/jsx-runtime';
11
7
 
12
- var _excluded = ["decorate", "url", "headers"];
13
-
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
-
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
- function renderApp(_x) {
18
- return _renderApp.apply(this, arguments);
19
- }
20
-
21
- function _renderApp() {
22
- _renderApp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(app) {
23
- var _ref,
24
- _decorate,
25
- url,
26
- headers,
27
- rest,
28
- html,
29
- asyncAssets,
30
- http,
31
- markup,
32
- _args = arguments;
33
-
34
- return _regeneratorRuntime.wrap(function _callee$(_context) {
35
- while (1) {
36
- switch (_context.prev = _context.next) {
37
- case 0:
38
- _ref = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, _decorate = _ref.decorate, url = _ref.url, headers = _ref.headers, rest = _objectWithoutProperties(_ref, _excluded);
39
- html = new HtmlManager();
40
- asyncAssets = new AsyncAssetManager();
41
- http = new HttpManager({
42
- headers: headers
43
- });
44
- _context.next = 6;
45
- return extract(app, _objectSpread({
46
- decorate: function decorate(app) {
47
- var _decorate2;
48
-
49
- return /*#__PURE__*/jsx(ServerContext, {
50
- asyncAssets: asyncAssets,
51
- http: http,
52
- html: html,
53
- url: url,
54
- children: (_decorate2 = _decorate === null || _decorate === void 0 ? void 0 : _decorate(app)) !== null && _decorate2 !== void 0 ? _decorate2 : app
55
- });
56
- }
57
- }, rest));
58
-
59
- case 6:
60
- markup = _context.sent;
61
- return _context.abrupt("return", {
62
- markup: markup,
63
- http: http,
64
- html: html,
65
- asyncAssets: asyncAssets
66
- });
67
-
68
- case 8:
69
- case "end":
70
- return _context.stop();
71
- }
72
- }
73
- }, _callee);
74
- }));
75
- return _renderApp.apply(this, arguments);
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(ServerContext, {
24
+ asyncAssets: asyncAssets,
25
+ http: http,
26
+ html: html,
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
+ };
76
40
  }
77
41
 
78
42
  export { renderApp };
@@ -4,13 +4,14 @@ import { AsyncAssetContext } from '@quilted/react-async/server';
4
4
  import { HttpServerContext } from '@quilted/react-http/server';
5
5
  import { maybeWrapContext } from '../utilities/react.mjs';
6
6
 
7
- function StaticContext(_ref) {
8
- var url = _ref.url,
9
- html = _ref.html,
10
- http = _ref.http,
11
- asyncAssets = _ref.asyncAssets,
12
- children = _ref.children;
13
- var normalizedUrl = typeof url === 'string' ? new URL(url) : url;
7
+ function StaticContext({
8
+ url,
9
+ html,
10
+ http,
11
+ asyncAssets,
12
+ children
13
+ }) {
14
+ const normalizedUrl = typeof url === 'string' ? new URL(url) : url;
14
15
  return maybeWrapContext(AsyncAssetContext, asyncAssets, maybeWrapContext(HttpServerContext, http, maybeWrapContext(HtmlContext, html, maybeWrapContext(InitialUrlContext, normalizedUrl, children))));
15
16
  }
16
17