@reykjavik/webtools 0.1.35 → 0.1.37
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 +10 -2
- package/README.md +8 -8
- package/SiteImprove.d.ts +3 -4
- package/SiteImprove.js +20 -34
- package/esm/SiteImprove.d.ts +3 -4
- package/esm/SiteImprove.js +20 -11
- package/esm/next/SiteImprove.d.ts +1 -2
- package/esm/vanillaExtract.d.ts +2 -2
- package/esm/vanillaExtract.js +2 -2
- package/next/SiteImprove.d.ts +1 -2
- package/package.json +1 -1
- package/vanillaExtract.d.ts +2 -2
- package/vanillaExtract.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,12 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
-
## 0.1.
|
|
7
|
+
## 0.1.37
|
|
8
|
+
|
|
9
|
+
_2024-10-23_
|
|
10
|
+
|
|
11
|
+
- `@reykjavik/webtools/SiteImprove`:
|
|
12
|
+
- fix: `onLoad` and `onError` callback arguments are now typed as `Event`
|
|
13
|
+
- fix: Script wasn't actually loading. Now it does.
|
|
14
|
+
|
|
15
|
+
## 0.1.35 – 0.1.36
|
|
8
16
|
|
|
9
17
|
_2024-10-18_
|
|
10
18
|
|
|
11
19
|
- `@reykjavik/webtools/next/vanillaExtract`:
|
|
12
|
-
- feat: `vanillaClass` auto-replaces
|
|
20
|
+
- feat: `vanillaClass` auto-replaces `&&` tokens in a plain-string input
|
|
13
21
|
- docs: Minor improvements to README and JSDoc comments
|
|
14
22
|
|
|
15
23
|
## 0.1.34
|
package/README.md
CHANGED
|
@@ -774,11 +774,11 @@ CSS.
|
|
|
774
774
|
Returns a scoped cssClassName styled with free-form CSS. This function is a
|
|
775
775
|
thin wrapper around vanilla-extract's `style` function.
|
|
776
776
|
|
|
777
|
-
When you pass it a string, all
|
|
777
|
+
When you pass it a string, all `&&` tokens are automatically replaced with the
|
|
778
778
|
selector for the auto-generated class-name. Note that in such cases EVERY
|
|
779
779
|
style property must be wrapped in a selector block.
|
|
780
780
|
|
|
781
|
-
To opt out of the
|
|
781
|
+
To opt out of the `&&` replacement, use the callback function signature.
|
|
782
782
|
|
|
783
783
|
```ts
|
|
784
784
|
// someFile.css.ts
|
|
@@ -790,13 +790,13 @@ export const myClass = vanillaClass(`
|
|
|
790
790
|
padding: .5em 1em;
|
|
791
791
|
`);
|
|
792
792
|
|
|
793
|
-
// With
|
|
793
|
+
// With && tokens that get replaced with the generated class-name
|
|
794
794
|
export const myClasWithAmp = vanillaClass(`
|
|
795
|
-
|
|
795
|
+
&& {
|
|
796
796
|
background-color: #ccc;
|
|
797
797
|
padding: .5em 1em;
|
|
798
798
|
}
|
|
799
|
-
|
|
799
|
+
&& > strong {
|
|
800
800
|
color: #c00;
|
|
801
801
|
}
|
|
802
802
|
`);
|
|
@@ -817,8 +817,8 @@ export const myOtherClass = vanillaClass(
|
|
|
817
817
|
background-color: #eee;
|
|
818
818
|
}
|
|
819
819
|
}
|
|
820
|
-
/*
|
|
821
|
-
|
|
820
|
+
/* NOTE: '&&' tokens returned from a callback function are NOT replaced */
|
|
821
|
+
&& { will-not-be: interpolated; }
|
|
822
822
|
`
|
|
823
823
|
);
|
|
824
824
|
|
|
@@ -832,7 +832,7 @@ export const humanReadableClass = vanillaClass(
|
|
|
832
832
|
);
|
|
833
833
|
```
|
|
834
834
|
|
|
835
|
-
(NOTE: The dot-prefixed
|
|
835
|
+
(NOTE: The dot-prefixed `&&` pattern is chosen to not conflict with the bare
|
|
836
836
|
`&` token in modern nested CSS.)
|
|
837
837
|
|
|
838
838
|
### `vanillaGlobal`
|
package/SiteImprove.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { EitherObj } from '@reykjavik/hanna-utils';
|
|
3
2
|
declare global {
|
|
4
3
|
interface Window {
|
|
@@ -85,11 +84,11 @@ export type SiteImproveProps = EitherObj<{
|
|
|
85
84
|
/**
|
|
86
85
|
* Custom callback for when the SiteImprove script has loaded.
|
|
87
86
|
*/
|
|
88
|
-
onLoad?: (e:
|
|
87
|
+
onLoad?: (e: Event) => void;
|
|
89
88
|
/**
|
|
90
89
|
* Error callback for if the SiteImprove script fails to load.
|
|
91
90
|
*/
|
|
92
|
-
onError?: (e:
|
|
91
|
+
onError?: (e: Event | string) => void;
|
|
93
92
|
};
|
|
94
93
|
/**
|
|
95
94
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
@@ -97,5 +96,5 @@ export type SiteImproveProps = EitherObj<{
|
|
|
97
96
|
*
|
|
98
97
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#siteimprove-component
|
|
99
98
|
*/
|
|
100
|
-
export declare const SiteImprove: (props: SiteImproveProps) =>
|
|
99
|
+
export declare const SiteImprove: (props: SiteImproveProps) => null;
|
|
101
100
|
export {};
|
package/SiteImprove.js
CHANGED
|
@@ -1,30 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.SiteImprove = exports.pingSiteImproveOutbound = exports.pingSiteImprove = void 0;
|
|
27
|
-
const react_1 =
|
|
4
|
+
const react_1 = require("react");
|
|
28
5
|
const CookieHubConsent_js_1 = require("./CookieHubConsent.js");
|
|
29
6
|
// END: Mock typing of SiteImprove's event tracking API
|
|
30
7
|
// --------------------------------------------------------------------------
|
|
@@ -117,14 +94,28 @@ const useResolvedAnalyticsConsent = (hasConsented) => {
|
|
|
117
94
|
return ((analytics && hasConsented !== false) || (analytics === undefined && hasConsented));
|
|
118
95
|
};
|
|
119
96
|
// ---------------------------------------------------------------------------
|
|
120
|
-
const
|
|
121
|
-
|
|
97
|
+
const loadSIScript = (props) => {
|
|
98
|
+
var _a;
|
|
99
|
+
if (process.env.NODE_ENV === 'production') {
|
|
100
|
+
if (window._sz || document.querySelector('script#siteimprove-analytics-script')) {
|
|
101
|
+
console.warn('SiteImprove script already loaded.');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const script = document.createElement('script');
|
|
105
|
+
script.defer = true;
|
|
106
|
+
script.id = 'siteimprove-analytics-script';
|
|
107
|
+
script.src = (_a = props.scriptUrl) !== null && _a !== void 0 ? _a : makeScriptUrl(props.accountId);
|
|
108
|
+
props.onLoad && (script.onload = props.onLoad);
|
|
109
|
+
props.onError && (script.onerror = props.onError);
|
|
110
|
+
document.body.append(script);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
122
113
|
setTimeout(() => {
|
|
123
114
|
if (!window._sz) {
|
|
124
115
|
console.info('Mock loading SiteImprove in development mode.', props.scriptUrl || props.accountId);
|
|
125
116
|
window._sz = [];
|
|
126
117
|
}
|
|
127
|
-
}, 300);
|
|
118
|
+
}, 300); // Aribtrary delay to simulate script loading
|
|
128
119
|
}
|
|
129
120
|
};
|
|
130
121
|
// ===========================================================================
|
|
@@ -137,7 +128,6 @@ const loc = typeof document !== 'undefined' ? document.location : {};
|
|
|
137
128
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#siteimprove-component
|
|
138
129
|
*/
|
|
139
130
|
const SiteImprove = (props) => {
|
|
140
|
-
var _a;
|
|
141
131
|
const consented = useResolvedAnalyticsConsent(props.hasConsented);
|
|
142
132
|
const thisUrl = `${loc.pathname}${loc.search}${loc.hash}`;
|
|
143
133
|
(0, react_1.useEffect)(() => {
|
|
@@ -162,15 +152,11 @@ const SiteImprove = (props) => {
|
|
|
162
152
|
if (!consented) {
|
|
163
153
|
return;
|
|
164
154
|
}
|
|
165
|
-
|
|
155
|
+
loadSIScript(props);
|
|
166
156
|
return logOutboundLinks();
|
|
167
157
|
},
|
|
168
158
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
169
159
|
[consented]);
|
|
170
|
-
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
const scriptUrl = (_a = props.scriptUrl) !== null && _a !== void 0 ? _a : makeScriptUrl(props.accountId);
|
|
174
|
-
return react_1.default.createElement("script", { defer: true, src: scriptUrl, onLoad: props.onLoad, onError: props.onError });
|
|
160
|
+
return null;
|
|
175
161
|
};
|
|
176
162
|
exports.SiteImprove = SiteImprove;
|
package/esm/SiteImprove.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { EitherObj } from '@reykjavik/hanna-utils';
|
|
3
2
|
declare global {
|
|
4
3
|
interface Window {
|
|
@@ -85,11 +84,11 @@ export type SiteImproveProps = EitherObj<{
|
|
|
85
84
|
/**
|
|
86
85
|
* Custom callback for when the SiteImprove script has loaded.
|
|
87
86
|
*/
|
|
88
|
-
onLoad?: (e:
|
|
87
|
+
onLoad?: (e: Event) => void;
|
|
89
88
|
/**
|
|
90
89
|
* Error callback for if the SiteImprove script fails to load.
|
|
91
90
|
*/
|
|
92
|
-
onError?: (e:
|
|
91
|
+
onError?: (e: Event | string) => void;
|
|
93
92
|
};
|
|
94
93
|
/**
|
|
95
94
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
@@ -97,5 +96,5 @@ export type SiteImproveProps = EitherObj<{
|
|
|
97
96
|
*
|
|
98
97
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#siteimprove-component
|
|
99
98
|
*/
|
|
100
|
-
export declare const SiteImprove: (props: SiteImproveProps) =>
|
|
99
|
+
export declare const SiteImprove: (props: SiteImproveProps) => null;
|
|
101
100
|
export {};
|
package/esm/SiteImprove.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
2
|
import { useCookieHubConsent } from './CookieHubConsent.js';
|
|
3
3
|
// END: Mock typing of SiteImprove's event tracking API
|
|
4
4
|
// --------------------------------------------------------------------------
|
|
@@ -89,14 +89,28 @@ const useResolvedAnalyticsConsent = (hasConsented) => {
|
|
|
89
89
|
return ((analytics && hasConsented !== false) || (analytics === undefined && hasConsented));
|
|
90
90
|
};
|
|
91
91
|
// ---------------------------------------------------------------------------
|
|
92
|
-
const
|
|
93
|
-
|
|
92
|
+
const loadSIScript = (props) => {
|
|
93
|
+
var _a;
|
|
94
|
+
if (process.env.NODE_ENV === 'production') {
|
|
95
|
+
if (window._sz || document.querySelector('script#siteimprove-analytics-script')) {
|
|
96
|
+
console.warn('SiteImprove script already loaded.');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const script = document.createElement('script');
|
|
100
|
+
script.defer = true;
|
|
101
|
+
script.id = 'siteimprove-analytics-script';
|
|
102
|
+
script.src = (_a = props.scriptUrl) !== null && _a !== void 0 ? _a : makeScriptUrl(props.accountId);
|
|
103
|
+
props.onLoad && (script.onload = props.onLoad);
|
|
104
|
+
props.onError && (script.onerror = props.onError);
|
|
105
|
+
document.body.append(script);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
94
108
|
setTimeout(() => {
|
|
95
109
|
if (!window._sz) {
|
|
96
110
|
console.info('Mock loading SiteImprove in development mode.', props.scriptUrl || props.accountId);
|
|
97
111
|
window._sz = [];
|
|
98
112
|
}
|
|
99
|
-
}, 300);
|
|
113
|
+
}, 300); // Aribtrary delay to simulate script loading
|
|
100
114
|
}
|
|
101
115
|
};
|
|
102
116
|
// ===========================================================================
|
|
@@ -109,7 +123,6 @@ const loc = typeof document !== 'undefined' ? document.location : {};
|
|
|
109
123
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#siteimprove-component
|
|
110
124
|
*/
|
|
111
125
|
export const SiteImprove = (props) => {
|
|
112
|
-
var _a;
|
|
113
126
|
const consented = useResolvedAnalyticsConsent(props.hasConsented);
|
|
114
127
|
const thisUrl = `${loc.pathname}${loc.search}${loc.hash}`;
|
|
115
128
|
useEffect(() => {
|
|
@@ -134,14 +147,10 @@ export const SiteImprove = (props) => {
|
|
|
134
147
|
if (!consented) {
|
|
135
148
|
return;
|
|
136
149
|
}
|
|
137
|
-
|
|
150
|
+
loadSIScript(props);
|
|
138
151
|
return logOutboundLinks();
|
|
139
152
|
},
|
|
140
153
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
141
154
|
[consented]);
|
|
142
|
-
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
const scriptUrl = (_a = props.scriptUrl) !== null && _a !== void 0 ? _a : makeScriptUrl(props.accountId);
|
|
146
|
-
return React.createElement("script", { defer: true, src: scriptUrl, onLoad: props.onLoad, onError: props.onError });
|
|
155
|
+
return null;
|
|
147
156
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/// <reference types="react" resolution-mode="require"/>
|
|
2
1
|
import { SiteImproveProps as _SiteImproveProps } from '../SiteImprove.js';
|
|
3
2
|
/** @deprecated Instead import from `@reykjavik/webtools/SiteImprove` (Will be removed in v0.2) */
|
|
4
3
|
export type SiteImproveProps = _SiteImproveProps;
|
|
5
4
|
/** @deprecated Instead import from `@reykjavik/webtools/SiteImprove` (Will be removed in v0.2) */
|
|
6
|
-
export declare const SiteImprove: (props: _SiteImproveProps) =>
|
|
5
|
+
export declare const SiteImprove: (props: _SiteImproveProps) => null;
|
|
7
6
|
/** @deprecated Instead import from `@reykjavik/webtools/SiteImprove` (Will be removed in v0.2) */
|
|
8
7
|
export declare const pingSiteImprove: (category: string, action: string, label?: string | undefined) => void;
|
|
9
8
|
/** @deprecated Instead import from `@reykjavik/webtools/SiteImprove` (Will be removed in v0.2) */
|
package/esm/vanillaExtract.d.ts
CHANGED
|
@@ -21,11 +21,11 @@ classNameSelector: string) => string;
|
|
|
21
21
|
* Returns a scoped cssClassName styled with free-form CSS. This function is a
|
|
22
22
|
* thin wrapper around vanilla-extract's `style` function.
|
|
23
23
|
*
|
|
24
|
-
* When you pass it a string, all
|
|
24
|
+
* When you pass it a string, all `&&` tokens are automatically replaced with the
|
|
25
25
|
* selector for the auto-generated class-name. Note that in such cases EVERY
|
|
26
26
|
* style property must be wrapped in a selector block.
|
|
27
27
|
*
|
|
28
|
-
* To opt out of the
|
|
28
|
+
* To opt out of the `&&` replacement, use the callback function signature.
|
|
29
29
|
*
|
|
30
30
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaclass
|
|
31
31
|
*/
|
package/esm/vanillaExtract.js
CHANGED
|
@@ -16,13 +16,13 @@ export const vanillaProps = (css) => ({ x: `; ${css}` });
|
|
|
16
16
|
export function vanillaClass(cssOrDebugId, css) {
|
|
17
17
|
const debugId = css != null ? cssOrDebugId : undefined;
|
|
18
18
|
css = css != null ? css : cssOrDebugId;
|
|
19
|
-
if (typeof css === 'string' &&
|
|
19
|
+
if (typeof css === 'string' && !/&&/.test(css)) {
|
|
20
20
|
return style(vanillaProps(css), debugId);
|
|
21
21
|
}
|
|
22
22
|
const className = style({}, debugId);
|
|
23
23
|
vanillaGlobal(typeof css === 'function'
|
|
24
24
|
? css('className', `.${className}`)
|
|
25
|
-
: css.replace(
|
|
25
|
+
: css.replace(/&&/g, `.${className}`));
|
|
26
26
|
return className;
|
|
27
27
|
}
|
|
28
28
|
// ---------------------------------------------------------------------------
|
package/next/SiteImprove.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { SiteImproveProps as _SiteImproveProps } from '../SiteImprove.js';
|
|
3
2
|
/** @deprecated Instead import from `@reykjavik/webtools/SiteImprove` (Will be removed in v0.2) */
|
|
4
3
|
export type SiteImproveProps = _SiteImproveProps;
|
|
5
4
|
/** @deprecated Instead import from `@reykjavik/webtools/SiteImprove` (Will be removed in v0.2) */
|
|
6
|
-
export declare const SiteImprove: (props: _SiteImproveProps) =>
|
|
5
|
+
export declare const SiteImprove: (props: _SiteImproveProps) => null;
|
|
7
6
|
/** @deprecated Instead import from `@reykjavik/webtools/SiteImprove` (Will be removed in v0.2) */
|
|
8
7
|
export declare const pingSiteImprove: (category: string, action: string, label?: string | undefined) => void;
|
|
9
8
|
/** @deprecated Instead import from `@reykjavik/webtools/SiteImprove` (Will be removed in v0.2) */
|
package/package.json
CHANGED
package/vanillaExtract.d.ts
CHANGED
|
@@ -21,11 +21,11 @@ classNameSelector: string) => string;
|
|
|
21
21
|
* Returns a scoped cssClassName styled with free-form CSS. This function is a
|
|
22
22
|
* thin wrapper around vanilla-extract's `style` function.
|
|
23
23
|
*
|
|
24
|
-
* When you pass it a string, all
|
|
24
|
+
* When you pass it a string, all `&&` tokens are automatically replaced with the
|
|
25
25
|
* selector for the auto-generated class-name. Note that in such cases EVERY
|
|
26
26
|
* style property must be wrapped in a selector block.
|
|
27
27
|
*
|
|
28
|
-
* To opt out of the
|
|
28
|
+
* To opt out of the `&&` replacement, use the callback function signature.
|
|
29
29
|
*
|
|
30
30
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaclass
|
|
31
31
|
*/
|
package/vanillaExtract.js
CHANGED
|
@@ -21,13 +21,13 @@ exports.vanillaProps = vanillaProps;
|
|
|
21
21
|
function vanillaClass(cssOrDebugId, css) {
|
|
22
22
|
const debugId = css != null ? cssOrDebugId : undefined;
|
|
23
23
|
css = css != null ? css : cssOrDebugId;
|
|
24
|
-
if (typeof css === 'string' &&
|
|
24
|
+
if (typeof css === 'string' && !/&&/.test(css)) {
|
|
25
25
|
return (0, css_1.style)((0, exports.vanillaProps)(css), debugId);
|
|
26
26
|
}
|
|
27
27
|
const className = (0, css_1.style)({}, debugId);
|
|
28
28
|
(0, exports.vanillaGlobal)(typeof css === 'function'
|
|
29
29
|
? css('className', `.${className}`)
|
|
30
|
-
: css.replace(
|
|
30
|
+
: css.replace(/&&/g, `.${className}`));
|
|
31
31
|
return className;
|
|
32
32
|
}
|
|
33
33
|
exports.vanillaClass = vanillaClass;
|