@reykjavik/webtools 0.1.37 → 0.2.0
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 +12 -0
- package/CookieHubConsent.d.ts +2 -2
- package/CookieHubConsent.js +2 -2
- package/README.md +9 -5
- package/SiteImprove.d.ts +3 -3
- package/SiteImprove.js +3 -3
- package/async.d.ts +2 -2
- package/async.js +1 -1
- package/errorhandling.d.ts +10 -10
- package/errorhandling.js +7 -7
- package/esm/CookieHubConsent.d.ts +2 -2
- package/esm/CookieHubConsent.js +2 -2
- package/esm/SiteImprove.d.ts +3 -3
- package/esm/SiteImprove.js +3 -3
- package/esm/async.d.ts +2 -2
- package/esm/async.js +1 -1
- package/esm/errorhandling.d.ts +10 -10
- package/esm/errorhandling.js +7 -7
- package/esm/http.d.ts +5 -5
- package/esm/http.js +4 -4
- package/esm/index.d.ts +2 -3
- package/esm/next/http.d.ts +2 -2
- package/esm/next/http.js +3 -3
- package/{remix → esm/react-router}/Wait.d.ts +2 -2
- package/esm/{remix → react-router}/Wait.js +2 -2
- package/esm/{remix → react-router}/http.d.ts +1 -1
- package/esm/{remix → react-router}/http.js +1 -1
- package/esm/vanillaExtract.d.ts +3 -132
- package/esm/vanillaExtract.js +2 -67
- package/http.d.ts +5 -5
- package/http.js +4 -4
- package/index.d.ts +2 -3
- package/next/http.d.ts +2 -2
- package/next/http.js +3 -3
- package/package.json +13 -17
- package/{esm/remix → react-router}/Wait.d.ts +2 -2
- package/{remix → react-router}/Wait.js +3 -3
- package/{remix → react-router}/http.d.ts +1 -1
- package/{remix → react-router}/http.js +1 -1
- package/vanillaExtract.d.ts +3 -132
- package/vanillaExtract.js +3 -70
- package/esm/next/SiteImprove.d.ts +0 -9
- package/esm/next/SiteImprove.js +0 -7
- package/next/SiteImprove.d.ts +0 -9
- package/next/SiteImprove.js +0 -10
package/esm/http.js
CHANGED
|
@@ -136,7 +136,7 @@ const unitToSeconds = {
|
|
|
136
136
|
* Converts a `TTL` (max-age) value into seconds. Returns `0` for bad and/or
|
|
137
137
|
* negative input values.
|
|
138
138
|
*
|
|
139
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
139
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#tosec-ttl-helper
|
|
140
140
|
*/
|
|
141
141
|
export const toSec = (ttl) => {
|
|
142
142
|
if (typeof ttl === 'string') {
|
|
@@ -150,7 +150,7 @@ export const toSec = (ttl) => {
|
|
|
150
150
|
* Converts a `TTL` (duration) value into milliseconds. Returns `0` for bad
|
|
151
151
|
* and/or negative input values.
|
|
152
152
|
*
|
|
153
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
153
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#toms-duration-helper
|
|
154
154
|
*/
|
|
155
155
|
export const toMs = (ttl) => toSec(ttl) * 1000;
|
|
156
156
|
const toRespnseStubHeaders = (response) => {
|
|
@@ -195,7 +195,7 @@ const setCC = (response, cc) => {
|
|
|
195
195
|
* Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
196
196
|
* on a HTTP response
|
|
197
197
|
*
|
|
198
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
198
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cachecontrol-helper
|
|
199
199
|
*/
|
|
200
200
|
// eslint-disable-next-line complexity
|
|
201
201
|
export const cacheControl = (response, ttlCfg, eTag) => {
|
|
@@ -238,7 +238,7 @@ export const cacheControl = (response, ttlCfg, eTag) => {
|
|
|
238
238
|
* situations requiring a `HeadersInit` compatible object.
|
|
239
239
|
*
|
|
240
240
|
* Accepts the same arguments as `cacheControl()`.
|
|
241
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
241
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cachecontrolheaders-helper
|
|
242
242
|
*/
|
|
243
243
|
export const cacheControlHeaders = (ttlCfg, eTag) => {
|
|
244
244
|
const headers = new Map();
|
package/esm/index.d.ts
CHANGED
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
/// <reference path="./async.d.ts" />
|
|
4
4
|
/// <reference path="./fixIcelandicLocale.d.ts" />
|
|
5
5
|
/// <reference path="./errorhandling.d.ts" />
|
|
6
|
-
/// <reference path="./
|
|
6
|
+
/// <reference path="./react-router/http.d.ts" />
|
|
7
7
|
/// <reference path="./SiteImprove.d.tsx" />
|
|
8
8
|
/// <reference path="./CookieHubConsent.d.tsx" />
|
|
9
|
-
/// <reference path="./
|
|
10
|
-
/// <reference path="./next/SiteImprove.d.tsx" />
|
|
9
|
+
/// <reference path="./react-router/Wait.d.tsx" />
|
|
11
10
|
/// <reference path="./next/http.d.tsx" />
|
|
12
11
|
|
|
13
12
|
export {};
|
package/esm/next/http.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type InferErrorPageProps<SEP extends ShowErrorPageFn<any>> = Cleanup<Retu
|
|
|
26
26
|
* cases when `getServerSideProps` returns an `__error` prop with `statusCode`
|
|
27
27
|
* and optional friendly `message`.
|
|
28
28
|
*
|
|
29
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
29
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#makeerrorizeapphoc
|
|
30
30
|
*/
|
|
31
31
|
export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorPage: React.FunctionComponent<EP>) => {
|
|
32
32
|
<P extends {
|
|
@@ -48,7 +48,7 @@ export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorP
|
|
|
48
48
|
* to return an `HTTP_304_NotModified` response with an empty props object,
|
|
49
49
|
* in a way that doesn't make TypeScript shout at you.
|
|
50
50
|
*
|
|
51
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
51
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#notmodified304-helper
|
|
52
52
|
*/
|
|
53
53
|
export declare const notModified304: (response: ServerResponse | NextContextLike) => {
|
|
54
54
|
readonly props: any;
|
package/esm/next/http.js
CHANGED
|
@@ -9,7 +9,7 @@ export * from '../http.js';
|
|
|
9
9
|
* Use this method inside a `getServerSideProps` method (or API route)
|
|
10
10
|
* to return an error page with proper HTTP status code and all the shit.
|
|
11
11
|
*
|
|
12
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
12
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#showerrorpage-helper
|
|
13
13
|
*/
|
|
14
14
|
const showErrorPage = (response, error, ttl = '2s') => {
|
|
15
15
|
error =
|
|
@@ -33,7 +33,7 @@ const showErrorPage = (response, error, ttl = '2s') => {
|
|
|
33
33
|
* cases when `getServerSideProps` returns an `__error` prop with `statusCode`
|
|
34
34
|
* and optional friendly `message`.
|
|
35
35
|
*
|
|
36
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
36
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#makeerrorizeapphoc
|
|
37
37
|
*/
|
|
38
38
|
export const makeErrorizeAppHOC = (ErrorPage) => {
|
|
39
39
|
// the HOC
|
|
@@ -62,7 +62,7 @@ export const makeErrorizeAppHOC = (ErrorPage) => {
|
|
|
62
62
|
* to return an `HTTP_304_NotModified` response with an empty props object,
|
|
63
63
|
* in a way that doesn't make TypeScript shout at you.
|
|
64
64
|
*
|
|
65
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
65
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#notmodified304-helper
|
|
66
66
|
*/
|
|
67
67
|
export const notModified304 = (response) => {
|
|
68
68
|
response = 'res' in response ? response.res : response;
|
|
@@ -31,7 +31,7 @@ export type WaitProps<T> = WaitPropsBase<T> & WaitFallbacks;
|
|
|
31
31
|
* custom properties for `meanwhile` and `error` fallbacks, and/or other
|
|
32
32
|
* behaviors.
|
|
33
33
|
*
|
|
34
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
34
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-rr.md#type-waitcomponent
|
|
35
35
|
*/
|
|
36
36
|
export type WaitComponent<CustomProps extends Record<string, unknown> = Record<never, never>> = (<T>(props: WaitPropsBase<T> & CustomProps) => ReactElement) & {
|
|
37
37
|
displayName?: string;
|
|
@@ -43,7 +43,7 @@ export type WaitComponent<CustomProps extends Record<string, unknown> = Record<n
|
|
|
43
43
|
* If the awaited promise (`props.for`) resolves to an object with a truthy
|
|
44
44
|
* `$error` property, the `$error` will be thrown.
|
|
45
45
|
*
|
|
46
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
46
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-rr.md#wait-component
|
|
47
47
|
*/
|
|
48
48
|
export declare const Wait: WaitComponent<WaitFallbacks>;
|
|
49
49
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { Suspense } from 'react';
|
|
2
|
-
import { Await } from '
|
|
2
|
+
import { Await } from 'react-router';
|
|
3
3
|
/**
|
|
4
4
|
* A thin wrapper around [Remix's `Await`](https://remix.run/docs/en/2/components/await)
|
|
5
5
|
* component, to provide a more ergonomic API.
|
|
@@ -7,7 +7,7 @@ import { Await } from '@remix-run/react';
|
|
|
7
7
|
* If the awaited promise (`props.for`) resolves to an object with a truthy
|
|
8
8
|
* `$error` property, the `$error` will be thrown.
|
|
9
9
|
*
|
|
10
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
10
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-rr.md#wait-component
|
|
11
11
|
*/
|
|
12
12
|
export const Wait = (props) => (React.createElement(Suspense, { fallback: props.meanwhile || 'Loading...' },
|
|
13
13
|
React.createElement(Await, { resolve: props.for, errorElement: props.error || 'An error occurred.' }, (value) => {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Detects if the request is a client fetch, or an initial/full-page load.
|
|
3
3
|
* Useful for deciding whether to defer data fetching or not.
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-rr.md#isclientfetch
|
|
6
6
|
*/
|
|
7
7
|
export declare const isClientFetch: (request: Request) => boolean;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Detects if the request is a client fetch, or an initial/full-page load.
|
|
3
3
|
* Useful for deciding whether to defer data fetching or not.
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-rr.md#isclientfetch
|
|
6
6
|
*/
|
|
7
7
|
export const isClientFetch = (request) =>
|
|
8
8
|
// For info about this detection method:
|
package/esm/vanillaExtract.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import { GlobalStyleRule } from '@vanilla-extract/css';
|
|
|
2
2
|
/**
|
|
3
3
|
* Adds free-form CSS as a globalStyle
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#vanillaglobal
|
|
6
6
|
*/
|
|
7
7
|
export declare const vanillaGlobal: (css: string) => void;
|
|
8
8
|
/**
|
|
9
9
|
* Spreads the return value into a style object, to inject free-form CSS
|
|
10
10
|
* properties (or nested blocks)
|
|
11
11
|
*
|
|
12
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
12
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#vanillaprops
|
|
13
13
|
*/
|
|
14
14
|
export declare const vanillaProps: (css: string) => GlobalStyleRule;
|
|
15
15
|
type ClassNameCallback = (
|
|
@@ -27,137 +27,8 @@ classNameSelector: string) => string;
|
|
|
27
27
|
*
|
|
28
28
|
* To opt out of the `&&` replacement, use the callback function signature.
|
|
29
29
|
*
|
|
30
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
30
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#vanillaclass
|
|
31
31
|
*/
|
|
32
32
|
export declare function vanillaClass(css: string | ClassNameCallback): string;
|
|
33
33
|
export declare function vanillaClass(debugId: string, css: string | ClassNameCallback): string;
|
|
34
|
-
/**
|
|
35
|
-
* @deprecated (Will be removed in v0.2)
|
|
36
|
-
*
|
|
37
|
-
* Replaces all `&` tokens with the given selector string, in a direct
|
|
38
|
-
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
39
|
-
*
|
|
40
|
-
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
41
|
-
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
42
|
-
* If you need something more sophisticated, use a custom `postcss` config.
|
|
43
|
-
*
|
|
44
|
-
* ```ts
|
|
45
|
-
* // someCssHelper.ts
|
|
46
|
-
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
47
|
-
*
|
|
48
|
-
* export const hoverGlow = (
|
|
49
|
-
* ampSelector: string,
|
|
50
|
-
* glowiness?: 'normal' | 'insane'
|
|
51
|
-
* ) =>
|
|
52
|
-
* vanillaNest(
|
|
53
|
-
* ampSelector,
|
|
54
|
-
* `
|
|
55
|
-
* &:hover {
|
|
56
|
-
* box-shadow: 0 0 20px 5px ${
|
|
57
|
-
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
58
|
-
* };
|
|
59
|
-
* }
|
|
60
|
-
* `
|
|
61
|
-
* );
|
|
62
|
-
*
|
|
63
|
-
* // ...then, somewhere else in a *.css.ts file:
|
|
64
|
-
*
|
|
65
|
-
* import { hoverGlow } from '~/someCssHelper.js';
|
|
66
|
-
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
67
|
-
*
|
|
68
|
-
* vanillaGlobal(`
|
|
69
|
-
* .MyComponent {
|
|
70
|
-
* border: 1px solid #ccc;
|
|
71
|
-
* padding: 1em;
|
|
72
|
-
* }
|
|
73
|
-
* ${hoverGlow('.MyComponent')}
|
|
74
|
-
*
|
|
75
|
-
* .MyOtherComponent {
|
|
76
|
-
* border: 1px solid #ccc;
|
|
77
|
-
* padding: 1em;
|
|
78
|
-
* }
|
|
79
|
-
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
80
|
-
* `);
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
84
|
-
*/
|
|
85
|
-
export declare const vanillaNest: (ampSelector: string, css: string) => string;
|
|
86
|
-
/**
|
|
87
|
-
* @deprecated (Will be removed in v0.2)
|
|
88
|
-
*
|
|
89
|
-
* Returns a scoped cssClassName styled with free-form CSS.
|
|
90
|
-
*
|
|
91
|
-
* It also automatically replaces all `&`-tokens with
|
|
92
|
-
* the selector for the auto-generated class-name.
|
|
93
|
-
*
|
|
94
|
-
* ```ts
|
|
95
|
-
* // someFile.css.ts
|
|
96
|
-
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
97
|
-
*
|
|
98
|
-
* export const myClass = vanillaClassNested(`
|
|
99
|
-
* background-color: #ccc;
|
|
100
|
-
* padding: .5em 1em;
|
|
101
|
-
*
|
|
102
|
-
* /* Nested blocks begin: */
|
|
103
|
-
* &:hover {
|
|
104
|
-
* background-color: #666;
|
|
105
|
-
* color: white;
|
|
106
|
-
* }
|
|
107
|
-
* & > strong {
|
|
108
|
-
* color: maroon;
|
|
109
|
-
* }
|
|
110
|
-
* html[data-color-theme="unicorn"] & {
|
|
111
|
-
* background-color: pink;
|
|
112
|
-
* }
|
|
113
|
-
* `);
|
|
114
|
-
* ```
|
|
115
|
-
*
|
|
116
|
-
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
117
|
-
* before any nested blocks.
|
|
118
|
-
*
|
|
119
|
-
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
120
|
-
* anything so fancy. It will also replace `&` characters inside values,
|
|
121
|
-
* comments, etc. If you need something more sophisticated, use a custom
|
|
122
|
-
* `postcss` config.
|
|
123
|
-
*/
|
|
124
|
-
export declare function vanillaClassNested(css: string): string;
|
|
125
|
-
/** @deprecated (Will be removed in v0.2) */
|
|
126
|
-
/**
|
|
127
|
-
* Returns a scoped cssClassName styled with free-form CSS.
|
|
128
|
-
*
|
|
129
|
-
* It also automatically replaces all `&`-tokens with
|
|
130
|
-
* the selector for the auto-generated class-name.
|
|
131
|
-
*
|
|
132
|
-
* ```ts
|
|
133
|
-
* // someFile.css.ts
|
|
134
|
-
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
135
|
-
*
|
|
136
|
-
* export const myClass = vanillaClassNested(`
|
|
137
|
-
* background-color: #ccc;
|
|
138
|
-
* padding: .5em 1em;
|
|
139
|
-
*
|
|
140
|
-
* /* Nested blocks begin: */
|
|
141
|
-
* &:hover {
|
|
142
|
-
* background-color: #666;
|
|
143
|
-
* color: white;
|
|
144
|
-
* }
|
|
145
|
-
* & > strong {
|
|
146
|
-
* color: maroon;
|
|
147
|
-
* }
|
|
148
|
-
* html[data-color-theme="unicorn"] & {
|
|
149
|
-
* background-color: pink;
|
|
150
|
-
* }
|
|
151
|
-
* `);
|
|
152
|
-
* ```
|
|
153
|
-
*
|
|
154
|
-
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
155
|
-
* before any nested blocks.
|
|
156
|
-
*
|
|
157
|
-
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
158
|
-
* anything so fancy. It will also replace `&` characters inside values,
|
|
159
|
-
* comments, etc. If you need something more sophisticated, use a custom
|
|
160
|
-
* `postcss` config.
|
|
161
|
-
*/
|
|
162
|
-
export declare function vanillaClassNested(debugId: string, css: string): string;
|
|
163
34
|
export {};
|
package/esm/vanillaExtract.js
CHANGED
|
@@ -2,7 +2,7 @@ import { globalStyle, style } from '@vanilla-extract/css';
|
|
|
2
2
|
/**
|
|
3
3
|
* Adds free-form CSS as a globalStyle
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#vanillaglobal
|
|
6
6
|
*/
|
|
7
7
|
export const vanillaGlobal = (css) => globalStyle('x', { x: `} ${css} x{x:` });
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
@@ -10,7 +10,7 @@ export const vanillaGlobal = (css) => globalStyle('x', { x: `} ${css} x{x:` });
|
|
|
10
10
|
* Spreads the return value into a style object, to inject free-form CSS
|
|
11
11
|
* properties (or nested blocks)
|
|
12
12
|
*
|
|
13
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
13
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#vanillaprops
|
|
14
14
|
*/
|
|
15
15
|
export const vanillaProps = (css) => ({ x: `; ${css}` });
|
|
16
16
|
export function vanillaClass(cssOrDebugId, css) {
|
|
@@ -25,68 +25,3 @@ export function vanillaClass(cssOrDebugId, css) {
|
|
|
25
25
|
: css.replace(/&&/g, `.${className}`));
|
|
26
26
|
return className;
|
|
27
27
|
}
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
/**
|
|
30
|
-
* @deprecated (Will be removed in v0.2)
|
|
31
|
-
*
|
|
32
|
-
* Replaces all `&` tokens with the given selector string, in a direct
|
|
33
|
-
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
34
|
-
*
|
|
35
|
-
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
36
|
-
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
37
|
-
* If you need something more sophisticated, use a custom `postcss` config.
|
|
38
|
-
*
|
|
39
|
-
* ```ts
|
|
40
|
-
* // someCssHelper.ts
|
|
41
|
-
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
42
|
-
*
|
|
43
|
-
* export const hoverGlow = (
|
|
44
|
-
* ampSelector: string,
|
|
45
|
-
* glowiness?: 'normal' | 'insane'
|
|
46
|
-
* ) =>
|
|
47
|
-
* vanillaNest(
|
|
48
|
-
* ampSelector,
|
|
49
|
-
* `
|
|
50
|
-
* &:hover {
|
|
51
|
-
* box-shadow: 0 0 20px 5px ${
|
|
52
|
-
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
53
|
-
* };
|
|
54
|
-
* }
|
|
55
|
-
* `
|
|
56
|
-
* );
|
|
57
|
-
*
|
|
58
|
-
* // ...then, somewhere else in a *.css.ts file:
|
|
59
|
-
*
|
|
60
|
-
* import { hoverGlow } from '~/someCssHelper.js';
|
|
61
|
-
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
62
|
-
*
|
|
63
|
-
* vanillaGlobal(`
|
|
64
|
-
* .MyComponent {
|
|
65
|
-
* border: 1px solid #ccc;
|
|
66
|
-
* padding: 1em;
|
|
67
|
-
* }
|
|
68
|
-
* ${hoverGlow('.MyComponent')}
|
|
69
|
-
*
|
|
70
|
-
* .MyOtherComponent {
|
|
71
|
-
* border: 1px solid #ccc;
|
|
72
|
-
* padding: 1em;
|
|
73
|
-
* }
|
|
74
|
-
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
75
|
-
* `);
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
79
|
-
*/
|
|
80
|
-
export const vanillaNest = (ampSelector, css) => css.replace(/&/g, ampSelector);
|
|
81
|
-
export function vanillaClassNested(cssOrDebugId, css) {
|
|
82
|
-
const debugId = css != null ? cssOrDebugId : undefined;
|
|
83
|
-
css = css != null ? css : cssOrDebugId;
|
|
84
|
-
const nestPoint = css.indexOf('&');
|
|
85
|
-
const bareStyles = nestPoint > -1 ? css.slice(0, nestPoint) : css;
|
|
86
|
-
const nestedStyles = nestPoint > -1 ? css.slice(nestPoint) : undefined;
|
|
87
|
-
const className = style(vanillaProps(bareStyles), debugId);
|
|
88
|
-
if (nestedStyles) {
|
|
89
|
-
vanillaGlobal(vanillaNest(`.${className}`, nestedStyles));
|
|
90
|
-
}
|
|
91
|
-
return className;
|
|
92
|
-
}
|
package/http.d.ts
CHANGED
|
@@ -154,21 +154,21 @@ type TTLObj = {
|
|
|
154
154
|
/**
|
|
155
155
|
* Configures quick TTL-related settings for a HTTP request object
|
|
156
156
|
*
|
|
157
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
157
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#type-ttlconfig
|
|
158
158
|
*/
|
|
159
159
|
export type TTLConfig = TTL | TTLKeywords | TTLObj;
|
|
160
160
|
/**
|
|
161
161
|
* Converts a `TTL` (max-age) value into seconds. Returns `0` for bad and/or
|
|
162
162
|
* negative input values.
|
|
163
163
|
*
|
|
164
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
164
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#tosec-ttl-helper
|
|
165
165
|
*/
|
|
166
166
|
export declare const toSec: (ttl: TTL) => number;
|
|
167
167
|
/**
|
|
168
168
|
* Converts a `TTL` (duration) value into milliseconds. Returns `0` for bad
|
|
169
169
|
* and/or negative input values.
|
|
170
170
|
*
|
|
171
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
171
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#toms-duration-helper
|
|
172
172
|
*/
|
|
173
173
|
export declare const toMs: (ttl: TTL) => number;
|
|
174
174
|
type ServerResponseStub = Pick<ServerResponse, 'setHeader' | 'getHeader' | 'removeHeader'> & {
|
|
@@ -181,7 +181,7 @@ type ResponseStub = {
|
|
|
181
181
|
* Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
182
182
|
* on a HTTP response
|
|
183
183
|
*
|
|
184
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
184
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cachecontrol-helper
|
|
185
185
|
*/
|
|
186
186
|
export declare const cacheControl: (response: ServerResponseStub | ResponseStub | Map<string, string> | {
|
|
187
187
|
res: ServerResponseStub | ResponseStub;
|
|
@@ -191,7 +191,7 @@ export declare const cacheControl: (response: ServerResponseStub | ResponseStub
|
|
|
191
191
|
* situations requiring a `HeadersInit` compatible object.
|
|
192
192
|
*
|
|
193
193
|
* Accepts the same arguments as `cacheControl()`.
|
|
194
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
194
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cachecontrolheaders-helper
|
|
195
195
|
*/
|
|
196
196
|
export declare const cacheControlHeaders: (ttlCfg: TTLConfig, eTag?: string | number) => Record<string, string>;
|
|
197
197
|
export {};
|
package/http.js
CHANGED
|
@@ -140,7 +140,7 @@ const unitToSeconds = {
|
|
|
140
140
|
* Converts a `TTL` (max-age) value into seconds. Returns `0` for bad and/or
|
|
141
141
|
* negative input values.
|
|
142
142
|
*
|
|
143
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
143
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#tosec-ttl-helper
|
|
144
144
|
*/
|
|
145
145
|
const toSec = (ttl) => {
|
|
146
146
|
if (typeof ttl === 'string') {
|
|
@@ -155,7 +155,7 @@ exports.toSec = toSec;
|
|
|
155
155
|
* Converts a `TTL` (duration) value into milliseconds. Returns `0` for bad
|
|
156
156
|
* and/or negative input values.
|
|
157
157
|
*
|
|
158
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
158
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#toms-duration-helper
|
|
159
159
|
*/
|
|
160
160
|
const toMs = (ttl) => (0, exports.toSec)(ttl) * 1000;
|
|
161
161
|
exports.toMs = toMs;
|
|
@@ -201,7 +201,7 @@ const setCC = (response, cc) => {
|
|
|
201
201
|
* Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
202
202
|
* on a HTTP response
|
|
203
203
|
*
|
|
204
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
204
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cachecontrol-helper
|
|
205
205
|
*/
|
|
206
206
|
// eslint-disable-next-line complexity
|
|
207
207
|
const cacheControl = (response, ttlCfg, eTag) => {
|
|
@@ -245,7 +245,7 @@ exports.cacheControl = cacheControl;
|
|
|
245
245
|
* situations requiring a `HeadersInit` compatible object.
|
|
246
246
|
*
|
|
247
247
|
* Accepts the same arguments as `cacheControl()`.
|
|
248
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
248
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#cachecontrolheaders-helper
|
|
249
249
|
*/
|
|
250
250
|
const cacheControlHeaders = (ttlCfg, eTag) => {
|
|
251
251
|
const headers = new Map();
|
package/index.d.ts
CHANGED
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
/// <reference path="./async.d.ts" />
|
|
4
4
|
/// <reference path="./fixIcelandicLocale.d.ts" />
|
|
5
5
|
/// <reference path="./errorhandling.d.ts" />
|
|
6
|
-
/// <reference path="./
|
|
6
|
+
/// <reference path="./react-router/http.d.ts" />
|
|
7
7
|
/// <reference path="./SiteImprove.d.tsx" />
|
|
8
8
|
/// <reference path="./CookieHubConsent.d.tsx" />
|
|
9
|
-
/// <reference path="./
|
|
10
|
-
/// <reference path="./next/SiteImprove.d.tsx" />
|
|
9
|
+
/// <reference path="./react-router/Wait.d.tsx" />
|
|
11
10
|
/// <reference path="./next/http.d.tsx" />
|
|
12
11
|
|
|
13
12
|
export {};
|
package/next/http.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type InferErrorPageProps<SEP extends ShowErrorPageFn<any>> = Cleanup<Retu
|
|
|
26
26
|
* cases when `getServerSideProps` returns an `__error` prop with `statusCode`
|
|
27
27
|
* and optional friendly `message`.
|
|
28
28
|
*
|
|
29
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
29
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#makeerrorizeapphoc
|
|
30
30
|
*/
|
|
31
31
|
export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorPage: React.FunctionComponent<EP>) => {
|
|
32
32
|
<P extends {
|
|
@@ -48,7 +48,7 @@ export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorP
|
|
|
48
48
|
* to return an `HTTP_304_NotModified` response with an empty props object,
|
|
49
49
|
* in a way that doesn't make TypeScript shout at you.
|
|
50
50
|
*
|
|
51
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
51
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#notmodified304-helper
|
|
52
52
|
*/
|
|
53
53
|
export declare const notModified304: (response: ServerResponse | NextContextLike) => {
|
|
54
54
|
readonly props: any;
|
package/next/http.js
CHANGED
|
@@ -29,7 +29,7 @@ __exportStar(require("../http.js"), exports);
|
|
|
29
29
|
* Use this method inside a `getServerSideProps` method (or API route)
|
|
30
30
|
* to return an error page with proper HTTP status code and all the shit.
|
|
31
31
|
*
|
|
32
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
32
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#showerrorpage-helper
|
|
33
33
|
*/
|
|
34
34
|
const showErrorPage = (response, error, ttl = '2s') => {
|
|
35
35
|
error =
|
|
@@ -53,7 +53,7 @@ const showErrorPage = (response, error, ttl = '2s') => {
|
|
|
53
53
|
* cases when `getServerSideProps` returns an `__error` prop with `statusCode`
|
|
54
54
|
* and optional friendly `message`.
|
|
55
55
|
*
|
|
56
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
56
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#makeerrorizeapphoc
|
|
57
57
|
*/
|
|
58
58
|
const makeErrorizeAppHOC = (ErrorPage) => {
|
|
59
59
|
// the HOC
|
|
@@ -83,7 +83,7 @@ exports.makeErrorizeAppHOC = makeErrorizeAppHOC;
|
|
|
83
83
|
* to return an `HTTP_304_NotModified` response with an empty props object,
|
|
84
84
|
* in a way that doesn't make TypeScript shout at you.
|
|
85
85
|
*
|
|
86
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
86
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-nextjs.md#notmodified304-helper
|
|
87
87
|
*/
|
|
88
88
|
const notModified304 = (response) => {
|
|
89
89
|
response = 'res' in response ? response.res : response;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reykjavik/webtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Misc. JS/TS helpers used by Reykjavík City's web dev teams.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "ssh://git@github.com:reykjavikcity/webtools.git",
|
|
@@ -14,16 +14,13 @@
|
|
|
14
14
|
"@reykjavik/hanna-utils": "^0.2.16"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@remix-run/react": "^2.6.0",
|
|
18
17
|
"@vanilla-extract/css": "^1.14.1",
|
|
19
18
|
"next": ">=11",
|
|
20
19
|
"react": ">=16.8.0",
|
|
21
|
-
"react-dom": ">=16.8.0"
|
|
20
|
+
"react-dom": ">=16.8.0",
|
|
21
|
+
"react-router": "^7.0.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependenciesMeta": {
|
|
24
|
-
"@remix-run/react": {
|
|
25
|
-
"optional": true
|
|
26
|
-
},
|
|
27
24
|
"@vanilla-extract/css": {
|
|
28
25
|
"optional": true
|
|
29
26
|
},
|
|
@@ -35,10 +32,13 @@
|
|
|
35
32
|
},
|
|
36
33
|
"react-dom": {
|
|
37
34
|
"optional": true
|
|
35
|
+
},
|
|
36
|
+
"react-router": {
|
|
37
|
+
"optional": true
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
41
|
+
"node": ">=20"
|
|
42
42
|
},
|
|
43
43
|
"sideEffects": [
|
|
44
44
|
"**/fixIcelandicLocale.js"
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"import": "./esm/errorhandling.js",
|
|
69
69
|
"require": "./errorhandling.js"
|
|
70
70
|
},
|
|
71
|
-
"./
|
|
72
|
-
"import": "./esm/
|
|
73
|
-
"require": "./
|
|
71
|
+
"./react-router/http": {
|
|
72
|
+
"import": "./esm/react-router/http.js",
|
|
73
|
+
"require": "./react-router/http.js"
|
|
74
74
|
},
|
|
75
75
|
"./SiteImprove": {
|
|
76
76
|
"import": "./esm/SiteImprove.js",
|
|
@@ -80,13 +80,9 @@
|
|
|
80
80
|
"import": "./esm/CookieHubConsent.js",
|
|
81
81
|
"require": "./CookieHubConsent.js"
|
|
82
82
|
},
|
|
83
|
-
"./
|
|
84
|
-
"import": "./esm/
|
|
85
|
-
"require": "./
|
|
86
|
-
},
|
|
87
|
-
"./next/SiteImprove": {
|
|
88
|
-
"import": "./esm/next/SiteImprove.js",
|
|
89
|
-
"require": "./next/SiteImprove.js"
|
|
83
|
+
"./react-router/Wait": {
|
|
84
|
+
"import": "./esm/react-router/Wait.js",
|
|
85
|
+
"require": "./react-router/Wait.js"
|
|
90
86
|
},
|
|
91
87
|
"./next/http": {
|
|
92
88
|
"import": "./esm/next/http.js",
|
|
@@ -31,7 +31,7 @@ export type WaitProps<T> = WaitPropsBase<T> & WaitFallbacks;
|
|
|
31
31
|
* custom properties for `meanwhile` and `error` fallbacks, and/or other
|
|
32
32
|
* behaviors.
|
|
33
33
|
*
|
|
34
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
34
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-rr.md#type-waitcomponent
|
|
35
35
|
*/
|
|
36
36
|
export type WaitComponent<CustomProps extends Record<string, unknown> = Record<never, never>> = (<T>(props: WaitPropsBase<T> & CustomProps) => ReactElement) & {
|
|
37
37
|
displayName?: string;
|
|
@@ -43,7 +43,7 @@ export type WaitComponent<CustomProps extends Record<string, unknown> = Record<n
|
|
|
43
43
|
* If the awaited promise (`props.for`) resolves to an object with a truthy
|
|
44
44
|
* `$error` property, the `$error` will be thrown.
|
|
45
45
|
*
|
|
46
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
46
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-rr.md#wait-component
|
|
47
47
|
*/
|
|
48
48
|
export declare const Wait: WaitComponent<WaitFallbacks>;
|
|
49
49
|
export {};
|
|
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.Wait = void 0;
|
|
27
27
|
const react_1 = __importStar(require("react"));
|
|
28
|
-
const
|
|
28
|
+
const react_router_1 = require("react-router");
|
|
29
29
|
/**
|
|
30
30
|
* A thin wrapper around [Remix's `Await`](https://remix.run/docs/en/2/components/await)
|
|
31
31
|
* component, to provide a more ergonomic API.
|
|
@@ -33,10 +33,10 @@ const react_2 = require("@remix-run/react");
|
|
|
33
33
|
* If the awaited promise (`props.for`) resolves to an object with a truthy
|
|
34
34
|
* `$error` property, the `$error` will be thrown.
|
|
35
35
|
*
|
|
36
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
36
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-rr.md#wait-component
|
|
37
37
|
*/
|
|
38
38
|
const Wait = (props) => (react_1.default.createElement(react_1.Suspense, { fallback: props.meanwhile || 'Loading...' },
|
|
39
|
-
react_1.default.createElement(
|
|
39
|
+
react_1.default.createElement(react_router_1.Await, { resolve: props.for, errorElement: props.error || 'An error occurred.' }, (value) => {
|
|
40
40
|
if (value && // eslint-disable-line @typescript-eslint/no-unnecessary-condition
|
|
41
41
|
typeof value === 'object' &&
|
|
42
42
|
'$error' in value &&
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Detects if the request is a client fetch, or an initial/full-page load.
|
|
3
3
|
* Useful for deciding whether to defer data fetching or not.
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/blob/v0.
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.2/README-rr.md#isclientfetch
|
|
6
6
|
*/
|
|
7
7
|
export declare const isClientFetch: (request: Request) => boolean;
|