@reykjavik/hanna-react 0.10.121 → 0.10.123

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 CHANGED
@@ -4,6 +4,19 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
+ ## 0.10.123
8
+
9
+ _2024-03-21_
10
+
11
+ - feat: Add component `HannaCssLink` for flicker-free CSS URL changes
12
+ - feat: Make `'is'` the default language for `ReadSpeakerPlayer`
13
+
14
+ ## 0.10.122
15
+
16
+ _2024-03-18_
17
+
18
+ - fix: Bad module import path in checkbox and radio inputs
19
+
7
20
  ## 0.10.121
8
21
 
9
22
  _2024-03-14_
@@ -0,0 +1,15 @@
1
+ import { CssModuleToken, getCssBundleUrl } from '@reykjavik/hanna-css';
2
+ import { EitherObj } from '@reykjavik/hanna-utils';
3
+ type HannaCssLinkProps = EitherObj<{
4
+ tokens: Array<CssModuleToken> | string;
5
+ options?: Parameters<typeof getCssBundleUrl>[1];
6
+ }, {
7
+ href: string;
8
+ }>;
9
+ /**
10
+ * A component that returns a `<link rel="stylesheet" ... />` element that
11
+ * loads the Hanna CSS bundle, in a way that prevents FOUC when the token list
12
+ * changes.
13
+ */
14
+ export declare const HannaCssLink: (props: HannaCssLinkProps) => JSX.Element;
15
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HannaCssLink = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importStar(require("react"));
6
+ const hanna_css_1 = require("@reykjavik/hanna-css");
7
+ /**
8
+ * A component that returns a `<link rel="stylesheet" ... />` element that
9
+ * loads the Hanna CSS bundle, in a way that prevents FOUC when the token list
10
+ * changes.
11
+ */
12
+ const HannaCssLink = (props) => {
13
+ var _a;
14
+ const newHref = (_a = props.href) !== null && _a !== void 0 ? _a : (0, hanna_css_1.getCssBundleUrl)(props.tokens, props.options);
15
+ const linkRef = (0, react_1.useRef)(null);
16
+ const currentHrefRef = (0, react_1.useRef)(newHref);
17
+ (0, react_1.useEffect)(() => {
18
+ const linkElm = linkRef.current;
19
+ if (!linkElm || newHref === currentHrefRef.current) {
20
+ return;
21
+ }
22
+ let newLinkElm = document.createElement('link');
23
+ newLinkElm.rel = 'stylesheet';
24
+ newLinkElm.href = newHref;
25
+ linkElm.after(newLinkElm);
26
+ newLinkElm.onload = () => {
27
+ if (!newLinkElm) {
28
+ return;
29
+ }
30
+ linkElm.href = newHref;
31
+ currentHrefRef.current = newHref;
32
+ newLinkElm.remove();
33
+ newLinkElm = undefined;
34
+ };
35
+ return () => {
36
+ if (!newLinkElm) {
37
+ return;
38
+ }
39
+ newLinkElm.remove();
40
+ newLinkElm = undefined;
41
+ };
42
+ }, [newHref]);
43
+ return react_1.default.createElement("link", { ref: linkRef, rel: "stylesheet", href: currentHrefRef.current });
44
+ };
45
+ exports.HannaCssLink = HannaCssLink;
@@ -15,8 +15,7 @@ export type ReadSpeakerPlayerProps = {
15
15
  /**
16
16
  * Reading language/locale for the ReadSpeaker player.
17
17
  *
18
- * If you don't specify a `lang`, the player will try to auto-detect
19
- * the language of the page, and pick a default `voice` for that language.
18
+ * Default: `is`
20
19
  *
21
20
  * @see https://docs.typo3.org/p/readspeaker/readspeaker-services/main/en-us/Configuration/Index.html#reading-language
22
21
  */
@@ -16,7 +16,7 @@ const scriptTagSelector = `script#${scriptTagId}`;
16
16
  */
17
17
  let buttons = 0;
18
18
  exports.defaultReadSpeakerPlayerTexts = {
19
- en: { linkText: 'Listen', linkLabel: 'Listen to this page read outloud' },
19
+ en: { linkText: 'Listen', linkLabel: 'Listen to this page read out loud' },
20
20
  is: { linkText: 'Hlusta', linkLabel: 'Hlusta á þessa síðu lesna upphátt' },
21
21
  pl: { linkText: 'Posłuchaj', linkLabel: 'Posłuchaj tej strony odczytanej na głos' },
22
22
  };
@@ -26,7 +26,7 @@ exports.defaultReadSpeakerPlayerTexts = {
26
26
  * @see https://docs.typo3.org/p/readspeaker/readspeaker-services/main/en-us/Configuration/Index.html
27
27
  */
28
28
  const ReadSpeakerPlayer = (props) => {
29
- const { align, float, customerId = '11315', lang = '', voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, texts, } = props;
29
+ const { align, float, customerId = '11315', lang = 'is', voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, texts, } = props;
30
30
  const { linkText, linkLabel } = (0, i18n_1.getTexts)({ lang: lang.slice(0, 2), texts }, exports.defaultReadSpeakerPlayerTexts);
31
31
  (0, react_1.useEffect)(() => {
32
32
  var _a, _b;
@@ -4,7 +4,7 @@ exports.TogglerInput = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const classUtils_1 = require("@hugsmidjan/qj/classUtils");
7
- const i18n_js_1 = require("@reykjavik/hanna-utils/i18n.js");
7
+ const i18n_1 = require("@reykjavik/hanna-utils/i18n");
8
8
  const useDomid_js_1 = require("../utils/useDomid.js");
9
9
  const defaultReqText = {
10
10
  is: 'Þarf að haka í',
@@ -18,7 +18,7 @@ const TogglerInput = (props) => {
18
18
  const errorId = errorMessage && `error${domid}`;
19
19
  const reqStar = required && reqText !== false && (react_1.default.createElement("abbr", { className: `${bem}__label__reqstar`,
20
20
  // FIXME: add mo-better i18n thinking
21
- title: `${reqText || defaultReqText[i18n_js_1.DEFAULT_LANG]}: ` }, "*"));
21
+ title: `${reqText || defaultReqText[i18n_1.DEFAULT_LANG]}: ` }, "*"));
22
22
  const readOnly = restInputProps.readOnly || (inputProps || {}).readOnly;
23
23
  const labelContent = (react_1.default.createElement(react_1.default.Fragment, null,
24
24
  ' ',
@@ -0,0 +1,15 @@
1
+ import { CssModuleToken, getCssBundleUrl } from '@reykjavik/hanna-css';
2
+ import { EitherObj } from '@reykjavik/hanna-utils';
3
+ type HannaCssLinkProps = EitherObj<{
4
+ tokens: Array<CssModuleToken> | string;
5
+ options?: Parameters<typeof getCssBundleUrl>[1];
6
+ }, {
7
+ href: string;
8
+ }>;
9
+ /**
10
+ * A component that returns a `<link rel="stylesheet" ... />` element that
11
+ * loads the Hanna CSS bundle, in a way that prevents FOUC when the token list
12
+ * changes.
13
+ */
14
+ export declare const HannaCssLink: (props: HannaCssLinkProps) => JSX.Element;
15
+ export {};
@@ -0,0 +1,40 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { getCssBundleUrl } from '@reykjavik/hanna-css';
3
+ /**
4
+ * A component that returns a `<link rel="stylesheet" ... />` element that
5
+ * loads the Hanna CSS bundle, in a way that prevents FOUC when the token list
6
+ * changes.
7
+ */
8
+ export const HannaCssLink = (props) => {
9
+ var _a;
10
+ const newHref = (_a = props.href) !== null && _a !== void 0 ? _a : getCssBundleUrl(props.tokens, props.options);
11
+ const linkRef = useRef(null);
12
+ const currentHrefRef = useRef(newHref);
13
+ useEffect(() => {
14
+ const linkElm = linkRef.current;
15
+ if (!linkElm || newHref === currentHrefRef.current) {
16
+ return;
17
+ }
18
+ let newLinkElm = document.createElement('link');
19
+ newLinkElm.rel = 'stylesheet';
20
+ newLinkElm.href = newHref;
21
+ linkElm.after(newLinkElm);
22
+ newLinkElm.onload = () => {
23
+ if (!newLinkElm) {
24
+ return;
25
+ }
26
+ linkElm.href = newHref;
27
+ currentHrefRef.current = newHref;
28
+ newLinkElm.remove();
29
+ newLinkElm = undefined;
30
+ };
31
+ return () => {
32
+ if (!newLinkElm) {
33
+ return;
34
+ }
35
+ newLinkElm.remove();
36
+ newLinkElm = undefined;
37
+ };
38
+ }, [newHref]);
39
+ return React.createElement("link", { ref: linkRef, rel: "stylesheet", href: currentHrefRef.current });
40
+ };
@@ -15,8 +15,7 @@ export type ReadSpeakerPlayerProps = {
15
15
  /**
16
16
  * Reading language/locale for the ReadSpeaker player.
17
17
  *
18
- * If you don't specify a `lang`, the player will try to auto-detect
19
- * the language of the page, and pick a default `voice` for that language.
18
+ * Default: `is`
20
19
  *
21
20
  * @see https://docs.typo3.org/p/readspeaker/readspeaker-services/main/en-us/Configuration/Index.html#reading-language
22
21
  */
@@ -12,7 +12,7 @@ const scriptTagSelector = `script#${scriptTagId}`;
12
12
  */
13
13
  let buttons = 0;
14
14
  export const defaultReadSpeakerPlayerTexts = {
15
- en: { linkText: 'Listen', linkLabel: 'Listen to this page read outloud' },
15
+ en: { linkText: 'Listen', linkLabel: 'Listen to this page read out loud' },
16
16
  is: { linkText: 'Hlusta', linkLabel: 'Hlusta á þessa síðu lesna upphátt' },
17
17
  pl: { linkText: 'Posłuchaj', linkLabel: 'Posłuchaj tej strony odczytanej na głos' },
18
18
  };
@@ -22,7 +22,7 @@ export const defaultReadSpeakerPlayerTexts = {
22
22
  * @see https://docs.typo3.org/p/readspeaker/readspeaker-services/main/en-us/Configuration/Index.html
23
23
  */
24
24
  export const ReadSpeakerPlayer = (props) => {
25
- const { align, float, customerId = '11315', lang = '', voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, texts, } = props;
25
+ const { align, float, customerId = '11315', lang = 'is', voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, texts, } = props;
26
26
  const { linkText, linkLabel } = getTexts({ lang: lang.slice(0, 2), texts }, defaultReadSpeakerPlayerTexts);
27
27
  useEffect(() => {
28
28
  var _a, _b;
@@ -1,7 +1,7 @@
1
1
  import { __rest } from "tslib";
2
2
  import React from 'react';
3
3
  import { modifiedClass } from '@hugsmidjan/qj/classUtils';
4
- import { DEFAULT_LANG } from '@reykjavik/hanna-utils/i18n.js';
4
+ import { DEFAULT_LANG } from '@reykjavik/hanna-utils/i18n';
5
5
  import { useDomid } from '../utils/useDomid.js';
6
6
  const defaultReqText = {
7
7
  is: 'Þarf að haka í',
package/esm/index.d.ts CHANGED
@@ -59,6 +59,7 @@
59
59
  /// <reference path="./IframeBlock.d.tsx" />
60
60
  /// <reference path="./HeroBlock.d.tsx" />
61
61
  /// <reference path="./Heading.d.tsx" />
62
+ /// <reference path="./HannaCssLink.d.tsx" />
62
63
  /// <reference path="./GridBlocks.d.tsx" />
63
64
  /// <reference path="./Gallery.d.tsx" />
64
65
  /// <reference path="./FormField.d.tsx" />
package/index.d.ts CHANGED
@@ -59,6 +59,7 @@
59
59
  /// <reference path="./IframeBlock.d.tsx" />
60
60
  /// <reference path="./HeroBlock.d.tsx" />
61
61
  /// <reference path="./Heading.d.tsx" />
62
+ /// <reference path="./HannaCssLink.d.tsx" />
62
63
  /// <reference path="./GridBlocks.d.tsx" />
63
64
  /// <reference path="./Gallery.d.tsx" />
64
65
  /// <reference path="./FormField.d.tsx" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/hanna-react",
3
- "version": "0.10.121",
3
+ "version": "0.10.123",
4
4
  "author": "Reykjavík (http://www.reykjavik.is)",
5
5
  "contributors": [
6
6
  "Hugsmiðjan ehf (http://www.hugsmidjan.is)",
@@ -289,6 +289,10 @@
289
289
  "import": "./esm/Heading.js",
290
290
  "require": "./Heading.js"
291
291
  },
292
+ "./HannaCssLink": {
293
+ "import": "./esm/HannaCssLink.js",
294
+ "require": "./HannaCssLink.js"
295
+ },
292
296
  "./GridBlocks": {
293
297
  "import": "./esm/GridBlocks.js",
294
298
  "require": "./GridBlocks.js"