@reykjavik/hanna-react 0.10.158 → 0.10.159
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 +7 -6
- package/FileInput/_FileInput.utils.d.ts +0 -2
- package/FileInput/_FileInput.utils.js +0 -2
- package/FileInput.d.ts +8 -1
- package/FileInput.js +18 -3
- package/esm/FileInput/_FileInput.utils.d.ts +0 -2
- package/esm/FileInput/_FileInput.utils.js +0 -2
- package/esm/FileInput.d.ts +8 -1
- package/esm/FileInput.js +18 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,20 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
-
## 0.10.
|
|
7
|
+
## 0.10.159
|
|
8
8
|
|
|
9
|
-
_2025-
|
|
9
|
+
_2025-10-09_
|
|
10
10
|
|
|
11
|
-
- `
|
|
12
|
-
- feat: Add prop `
|
|
13
|
-
- fix: Scope "global" keyboard event listener to the component's element
|
|
11
|
+
- `FileUpload`:
|
|
12
|
+
- feat: Add prop `unstable_confirmReplace` for multi-upload name-conflicts
|
|
14
13
|
|
|
15
|
-
## 0.10.157
|
|
14
|
+
## 0.10.157 – 0.10.158
|
|
16
15
|
|
|
17
16
|
_2025-09-16_
|
|
18
17
|
|
|
19
18
|
- `Multiselect`
|
|
19
|
+
- feat: Add prop `onDropdown` prop
|
|
20
20
|
- fix: Sync `.checked` prop of keyboard-toggled `input`s with visual state
|
|
21
|
+
- fix: Scope "global" keyboard event listener to the component's element
|
|
21
22
|
- `Selectbox`:
|
|
22
23
|
- fix: Remove stray `modifier` prop from `SelectboxProps`
|
|
23
24
|
- 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
|
-
/**
|
|
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(
|
|
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(
|
|
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 },
|
|
@@ -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
|
/**
|
package/esm/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
|
-
/**
|
|
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(
|
|
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(
|
|
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 },
|