@reykjavik/hanna-react 0.10.158 → 0.10.160

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,20 +4,28 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
- ## 0.10.158
7
+ ## 0.10.160
8
8
 
9
- _2025-09-16_
9
+ _2025-10-13_
10
10
 
11
- - `Multiselect`
12
- - feat: Add prop `onDropdown` prop
13
- - fix: Scope "global" keyboard event listener to the component's element
11
+ - `ReadSpeakerPlayer`:
12
+ - fix: Default `lang` to Hanna's `DEFAULT_LANG` value, like other components
13
+
14
+ ## 0.10.159
14
15
 
15
- ## 0.10.157
16
+ _2025-10-09_
17
+
18
+ - `FileUpload`:
19
+ - feat: Add prop `unstable_confirmReplace` for multi-upload name-conflicts
20
+
21
+ ## 0.10.157 – 0.10.158
16
22
 
17
23
  _2025-09-16_
18
24
 
19
25
  - `Multiselect`
26
+ - feat: Add prop `onDropdown` prop
20
27
  - fix: Sync `.checked` prop of keyboard-toggled `input`s with visual state
28
+ - fix: Scope "global" keyboard event listener to the component's element
21
29
  - `Selectbox`:
22
30
  - fix: Remove stray `modifier` prop from `SelectboxProps`
23
31
  - docs: Add JSDoc comments for `FormfieldProps.renderInput` parameters
@@ -21,8 +21,6 @@ export declare const formatBytes: (bytes: number, lang?: string, decimals?: numb
21
21
  * Figures out how to handle adding files to a FileInput
22
22
  * Which files to retaine, which too delete, and
23
23
  * what the updated fileList should look like.
24
- *
25
- *
26
24
  */
27
25
  export declare const getFileListUpdate: (oldFileList: Array<File>, added: Array<File>, replaceMode: boolean) => {
28
26
  fileList: File[];
@@ -46,8 +46,6 @@ exports.formatBytes = formatBytes;
46
46
  * Figures out how to handle adding files to a FileInput
47
47
  * Which files to retaine, which too delete, and
48
48
  * what the updated fileList should look like.
49
- *
50
- *
51
49
  */
52
50
  const getFileListUpdate = (oldFileList, added,
53
51
  /**
package/FileInput.d.ts CHANGED
@@ -23,7 +23,8 @@ export type FileInputProps = FormFieldWrappingProps & {
23
23
  onFilesUpdated?: (
24
24
  /** Updated, full list of Files. */
25
25
  files: Array<File>,
26
- /** Information about which Files were added or removed during with this update.
26
+ /**
27
+ * Information about which Files were added or removed during this update.
27
28
  *
28
29
  * NOTE: When a diff contains both added and deleted files, this indicates a
29
30
  * name-conflict occurred — i.e. one of the added files has a name that
@@ -36,6 +37,12 @@ export type FileInputProps = FormFieldWrappingProps & {
36
37
  deleted?: Array<File>;
37
38
  added?: Array<File>;
38
39
  }) => void;
40
+ /**
41
+ * Confirm replacing existing (name-conflicting) files in multi-upload mode
42
+ *
43
+ * This feature is "unstable" because its behavior might change in the future.
44
+ */
45
+ unstable_confirmReplace?: boolean;
39
46
  onFilesRejected?: (rejectedFiles: Array<File>) => void;
40
47
  name?: string;
41
48
  value?: ReadonlyArray<File>;
package/FileInput.js CHANGED
@@ -29,6 +29,11 @@ const defaultDropzoneText = {
29
29
  react_1.default.createElement("strong", null, "kliknij"),
30
30
  " by wybra\u0107.")),
31
31
  };
32
+ const replaceFileTest = {
33
+ is: 'Yfirskrifa núverandi skrá',
34
+ en: 'Replace existing file',
35
+ pl: 'Zastąp istniejący plik',
36
+ };
32
37
  const defaultOnFilesRejected = (rejectedFiles) => {
33
38
  window.alert(`Error:\n${rejectedFiles
34
39
  .map((elm) => {
@@ -49,7 +54,7 @@ const FileInput = (props) => {
49
54
  const _d = (0, FormField_js_1.groupFormFieldWrapperProps)(props), { dropzoneProps, // eslint-disable-line deprecation/deprecation
50
55
  multiple = (_b = (_a = props.dropzoneProps) === null || _a === void 0 ? void 0 : _a.multiple) !== null && _b !== void 0 ? _b : true, // eslint-disable-line deprecation/deprecation
51
56
  accept = (_c = props.dropzoneProps) === null || _c === void 0 ? void 0 : _c.accept, // eslint-disable-line deprecation/deprecation
52
- dropzoneText = defaultDropzoneText[lang](), removeFileText = defaultRemoveFileText[lang], FileList = _FileInputFileList_js_1.DefaultFileList, onFilesUpdated = () => undefined, onFilesRejected, showFileSize, showImagePreviews, value = [], fieldWrapperProps } = _d, inputElementProps = tslib_1.__rest(_d, ["dropzoneProps", "multiple", "accept", "dropzoneText", "removeFileText", "FileList", "onFilesUpdated", "onFilesRejected", "showFileSize", "showImagePreviews", "value", "fieldWrapperProps"]);
57
+ dropzoneText = defaultDropzoneText[lang](), unstable_confirmReplace, removeFileText = defaultRemoveFileText[lang], FileList = _FileInputFileList_js_1.DefaultFileList, onFilesUpdated = () => undefined, onFilesRejected, showFileSize, showImagePreviews, value = [], fieldWrapperProps } = _d, inputElementProps = tslib_1.__rest(_d, ["dropzoneProps", "multiple", "accept", "dropzoneText", "unstable_confirmReplace", "removeFileText", "FileList", "onFilesUpdated", "onFilesRejected", "showFileSize", "showImagePreviews", "value", "fieldWrapperProps"]);
53
58
  const domid = (0, useDomid_js_1.useDomid)(props.id);
54
59
  const fileInputWrapper = (0, react_1.useRef)(null);
55
60
  const fileInput = (0, react_1.useRef)(null);
@@ -113,14 +118,24 @@ const FileInput = (props) => {
113
118
  };
114
119
  const addFiles = (added) => {
115
120
  const { fileList, diff } = (0, _FileInput_utils_js_1.getFileListUpdate)(files, added, !multiple);
121
+ let updatedFileList = fileList;
122
+ if (diff.deleted && multiple && props.unstable_confirmReplace) {
123
+ diff.deleted = diff.deleted.filter((file) => window.confirm(`${replaceFileTest} "${file.name}"?`));
124
+ // When unstable_confirmReplace becomes stable, we should stop returning
125
+ // `fileList` from getFileListUpdate and just always do this thing.
126
+ // That change will require changing the tests too, so let's wait.
127
+ updatedFileList = files
128
+ .filter((file) => !diff.deleted.includes(file))
129
+ .concat(added);
130
+ }
116
131
  if (fileInput.current) {
117
- fileInput.current.files = arrayToFileList(fileList);
132
+ fileInput.current.files = arrayToFileList(updatedFileList);
118
133
  }
119
134
  if (inputRef.current) {
120
135
  // Empty on every add
121
136
  inputRef.current.files = arrayToFileList([]);
122
137
  }
123
- onFilesUpdated(fileList, diff);
138
+ onFilesUpdated(updatedFileList, diff);
124
139
  };
125
140
  return (react_1.default.createElement(FormField_js_1.default, Object.assign({ extraClassName: (0, hanna_utils_1.modifiedClass)('FileInput', [multiple && 'multi']) }, fieldWrapperProps, { id: `${domid}-fake`, LabelTag: "h4", renderInput: (className, inputProps /* , addFocusProps */) => {
126
141
  return (react_1.default.createElement("div", { className: className.control, ref: fileInputWrapper },
@@ -26,8 +26,8 @@ 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 = 'is', voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, texts, } = props;
30
- const { linkText, linkLabel } = (0, i18n_1.getTexts)({ lang: lang.slice(0, 2), texts }, exports.defaultReadSpeakerPlayerTexts);
29
+ const { align, float, customerId = '11315', lang = i18n_1.DEFAULT_LANG, voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, } = props;
30
+ const { linkText, linkLabel } = (0, i18n_1.getTexts)(props, exports.defaultReadSpeakerPlayerTexts);
31
31
  (0, react_1.useEffect)(() => {
32
32
  var _a, _b;
33
33
  if (buttons === 0) {
@@ -21,8 +21,6 @@ export declare const formatBytes: (bytes: number, lang?: string, decimals?: numb
21
21
  * Figures out how to handle adding files to a FileInput
22
22
  * Which files to retaine, which too delete, and
23
23
  * what the updated fileList should look like.
24
- *
25
- *
26
24
  */
27
25
  export declare const getFileListUpdate: (oldFileList: Array<File>, added: Array<File>, replaceMode: boolean) => {
28
26
  fileList: File[];
@@ -40,8 +40,6 @@ export const formatBytes = (bytes, lang = 'is', decimals = 2) => {
40
40
  * Figures out how to handle adding files to a FileInput
41
41
  * Which files to retaine, which too delete, and
42
42
  * what the updated fileList should look like.
43
- *
44
- *
45
43
  */
46
44
  export const getFileListUpdate = (oldFileList, added,
47
45
  /**
@@ -23,7 +23,8 @@ export type FileInputProps = FormFieldWrappingProps & {
23
23
  onFilesUpdated?: (
24
24
  /** Updated, full list of Files. */
25
25
  files: Array<File>,
26
- /** Information about which Files were added or removed during with this update.
26
+ /**
27
+ * Information about which Files were added or removed during this update.
27
28
  *
28
29
  * NOTE: When a diff contains both added and deleted files, this indicates a
29
30
  * name-conflict occurred — i.e. one of the added files has a name that
@@ -36,6 +37,12 @@ export type FileInputProps = FormFieldWrappingProps & {
36
37
  deleted?: Array<File>;
37
38
  added?: Array<File>;
38
39
  }) => void;
40
+ /**
41
+ * Confirm replacing existing (name-conflicting) files in multi-upload mode
42
+ *
43
+ * This feature is "unstable" because its behavior might change in the future.
44
+ */
45
+ unstable_confirmReplace?: boolean;
39
46
  onFilesRejected?: (rejectedFiles: Array<File>) => void;
40
47
  name?: string;
41
48
  value?: ReadonlyArray<File>;
package/esm/FileInput.js CHANGED
@@ -26,6 +26,11 @@ const defaultDropzoneText = {
26
26
  React.createElement("strong", null, "kliknij"),
27
27
  " by wybra\u0107.")),
28
28
  };
29
+ const replaceFileTest = {
30
+ is: 'Yfirskrifa núverandi skrá',
31
+ en: 'Replace existing file',
32
+ pl: 'Zastąp istniejący plik',
33
+ };
29
34
  const defaultOnFilesRejected = (rejectedFiles) => {
30
35
  window.alert(`Error:\n${rejectedFiles
31
36
  .map((elm) => {
@@ -46,7 +51,7 @@ export const FileInput = (props) => {
46
51
  const _d = groupFormFieldWrapperProps(props), { dropzoneProps, // eslint-disable-line deprecation/deprecation
47
52
  multiple = (_b = (_a = props.dropzoneProps) === null || _a === void 0 ? void 0 : _a.multiple) !== null && _b !== void 0 ? _b : true, // eslint-disable-line deprecation/deprecation
48
53
  accept = (_c = props.dropzoneProps) === null || _c === void 0 ? void 0 : _c.accept, // eslint-disable-line deprecation/deprecation
49
- dropzoneText = defaultDropzoneText[lang](), removeFileText = defaultRemoveFileText[lang], FileList = DefaultFileList, onFilesUpdated = () => undefined, onFilesRejected, showFileSize, showImagePreviews, value = [], fieldWrapperProps } = _d, inputElementProps = __rest(_d, ["dropzoneProps", "multiple", "accept", "dropzoneText", "removeFileText", "FileList", "onFilesUpdated", "onFilesRejected", "showFileSize", "showImagePreviews", "value", "fieldWrapperProps"]);
54
+ dropzoneText = defaultDropzoneText[lang](), unstable_confirmReplace, removeFileText = defaultRemoveFileText[lang], FileList = DefaultFileList, onFilesUpdated = () => undefined, onFilesRejected, showFileSize, showImagePreviews, value = [], fieldWrapperProps } = _d, inputElementProps = __rest(_d, ["dropzoneProps", "multiple", "accept", "dropzoneText", "unstable_confirmReplace", "removeFileText", "FileList", "onFilesUpdated", "onFilesRejected", "showFileSize", "showImagePreviews", "value", "fieldWrapperProps"]);
50
55
  const domid = useDomid(props.id);
51
56
  const fileInputWrapper = useRef(null);
52
57
  const fileInput = useRef(null);
@@ -110,14 +115,24 @@ export const FileInput = (props) => {
110
115
  };
111
116
  const addFiles = (added) => {
112
117
  const { fileList, diff } = getFileListUpdate(files, added, !multiple);
118
+ let updatedFileList = fileList;
119
+ if (diff.deleted && multiple && props.unstable_confirmReplace) {
120
+ diff.deleted = diff.deleted.filter((file) => window.confirm(`${replaceFileTest} "${file.name}"?`));
121
+ // When unstable_confirmReplace becomes stable, we should stop returning
122
+ // `fileList` from getFileListUpdate and just always do this thing.
123
+ // That change will require changing the tests too, so let's wait.
124
+ updatedFileList = files
125
+ .filter((file) => !diff.deleted.includes(file))
126
+ .concat(added);
127
+ }
113
128
  if (fileInput.current) {
114
- fileInput.current.files = arrayToFileList(fileList);
129
+ fileInput.current.files = arrayToFileList(updatedFileList);
115
130
  }
116
131
  if (inputRef.current) {
117
132
  // Empty on every add
118
133
  inputRef.current.files = arrayToFileList([]);
119
134
  }
120
- onFilesUpdated(fileList, diff);
135
+ onFilesUpdated(updatedFileList, diff);
121
136
  };
122
137
  return (React.createElement(FormField, Object.assign({ extraClassName: modifiedClass('FileInput', [multiple && 'multi']) }, fieldWrapperProps, { id: `${domid}-fake`, LabelTag: "h4", renderInput: (className, inputProps /* , addFocusProps */) => {
123
138
  return (React.createElement("div", { className: className.control, ref: fileInputWrapper },
@@ -1,6 +1,6 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { modifiedClass } from '@reykjavik/hanna-utils';
3
- import { getTexts } from '@reykjavik/hanna-utils/i18n';
3
+ import { DEFAULT_LANG, getTexts } from '@reykjavik/hanna-utils/i18n';
4
4
  const scriptTagId = 'rs_req_Init';
5
5
  const scriptTagSelector = `script#${scriptTagId}`;
6
6
  /**
@@ -22,8 +22,8 @@ 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 = 'is', voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, texts, } = props;
26
- const { linkText, linkLabel } = getTexts({ lang: lang.slice(0, 2), texts }, defaultReadSpeakerPlayerTexts);
25
+ const { align, float, customerId = '11315', lang = DEFAULT_LANG, voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, } = props;
26
+ const { linkText, linkLabel } = getTexts(props, defaultReadSpeakerPlayerTexts);
27
27
  useEffect(() => {
28
28
  var _a, _b;
29
29
  if (buttons === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/hanna-react",
3
- "version": "0.10.158",
3
+ "version": "0.10.160",
4
4
  "author": "Reykjavík (http://www.reykjavik.is)",
5
5
  "contributors": [
6
6
  "Hugsmiðjan ehf (http://www.hugsmidjan.is)",