@norges-domstoler/dds-components 10.3.0 → 10.3.1
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/dist/cjs/components/FileUploader/fileUploaderReducer.d.ts +3 -0
- package/dist/cjs/index.js +18 -6
- package/dist/components/FileUploader/fileUploaderReducer.d.ts +3 -0
- package/dist/components/FileUploader/fileUploaderReducer.js +4 -0
- package/dist/components/FileUploader/useFileUploader.js +15 -7
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -11040,6 +11040,10 @@ var fileUploaderReducer = function fileUploaderReducer(state, action) {
|
|
|
11040
11040
|
rootErrors: action.payload.rootErrors,
|
|
11041
11041
|
files: action.payload.files
|
|
11042
11042
|
});
|
|
11043
|
+
case 'setRootErrors':
|
|
11044
|
+
return Object.assign(Object.assign({}, state), {
|
|
11045
|
+
rootErrors: action.payload
|
|
11046
|
+
});
|
|
11043
11047
|
default:
|
|
11044
11048
|
return state;
|
|
11045
11049
|
}
|
|
@@ -11094,12 +11098,14 @@ var useFileUploader = function useFileUploader(props) {
|
|
|
11094
11098
|
var rootRef = React.useRef(null);
|
|
11095
11099
|
var inputRef = React.useRef(null);
|
|
11096
11100
|
var buttonRef = React.useRef(null);
|
|
11097
|
-
var initialFileUploaderFiles =
|
|
11098
|
-
return {
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
|
|
11102
|
-
|
|
11101
|
+
var initialFileUploaderFiles = React.useMemo(function () {
|
|
11102
|
+
return initialFiles.map(function (f) {
|
|
11103
|
+
return {
|
|
11104
|
+
file: f,
|
|
11105
|
+
errors: []
|
|
11106
|
+
};
|
|
11107
|
+
});
|
|
11108
|
+
}, [initialFiles]);
|
|
11103
11109
|
var _useReducer = React.useReducer(fileUploaderReducer, {
|
|
11104
11110
|
files: initialFileUploaderFiles,
|
|
11105
11111
|
isFocused: false,
|
|
@@ -11110,6 +11116,12 @@ var useFileUploader = function useFileUploader(props) {
|
|
|
11110
11116
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
11111
11117
|
state = _useReducer2[0],
|
|
11112
11118
|
dispatch = _useReducer2[1];
|
|
11119
|
+
React.useEffect(function () {
|
|
11120
|
+
dispatch({
|
|
11121
|
+
type: 'setRootErrors',
|
|
11122
|
+
payload: calcRootErrors(initialFileUploaderFiles, maxFiles, errorMessage)
|
|
11123
|
+
});
|
|
11124
|
+
}, [dispatch, initialFileUploaderFiles, maxFiles, errorMessage]);
|
|
11113
11125
|
var stateFiles = state.files;
|
|
11114
11126
|
var onRootFocus = React.useCallback(function () {
|
|
11115
11127
|
return dispatch({
|
|
@@ -27,6 +27,10 @@ var fileUploaderReducer = function fileUploaderReducer(state, action) {
|
|
|
27
27
|
rootErrors: action.payload.rootErrors,
|
|
28
28
|
files: action.payload.files
|
|
29
29
|
});
|
|
30
|
+
case 'setRootErrors':
|
|
31
|
+
return Object.assign(Object.assign({}, state), {
|
|
32
|
+
rootErrors: action.payload
|
|
33
|
+
});
|
|
30
34
|
default:
|
|
31
35
|
return state;
|
|
32
36
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { slicedToArray as _slicedToArray, regeneratorRuntime as _regeneratorRuntime, toConsumableArray as _toConsumableArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
2
|
import { __awaiter } from 'tslib';
|
|
3
|
-
import { useRef, useReducer, useCallback } from 'react';
|
|
3
|
+
import { useRef, useMemo, useReducer, useEffect, useCallback } from 'react';
|
|
4
4
|
import { fileUploaderReducer } from './fileUploaderReducer.js';
|
|
5
5
|
import { fromEvent } from 'file-selector';
|
|
6
6
|
import { preventDefaults, isEventWithFiles, isFileAccepted, getInvalidFileTypeErrorMessage, getTooManyFilesErrorMessage } from './utils.js';
|
|
@@ -25,12 +25,14 @@ var useFileUploader = function useFileUploader(props) {
|
|
|
25
25
|
var rootRef = useRef(null);
|
|
26
26
|
var inputRef = useRef(null);
|
|
27
27
|
var buttonRef = useRef(null);
|
|
28
|
-
var initialFileUploaderFiles =
|
|
29
|
-
return {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
var initialFileUploaderFiles = useMemo(function () {
|
|
29
|
+
return initialFiles.map(function (f) {
|
|
30
|
+
return {
|
|
31
|
+
file: f,
|
|
32
|
+
errors: []
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}, [initialFiles]);
|
|
34
36
|
var _useReducer = useReducer(fileUploaderReducer, {
|
|
35
37
|
files: initialFileUploaderFiles,
|
|
36
38
|
isFocused: false,
|
|
@@ -41,6 +43,12 @@ var useFileUploader = function useFileUploader(props) {
|
|
|
41
43
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
42
44
|
state = _useReducer2[0],
|
|
43
45
|
dispatch = _useReducer2[1];
|
|
46
|
+
useEffect(function () {
|
|
47
|
+
dispatch({
|
|
48
|
+
type: 'setRootErrors',
|
|
49
|
+
payload: calcRootErrors(initialFileUploaderFiles, maxFiles, errorMessage)
|
|
50
|
+
});
|
|
51
|
+
}, [dispatch, initialFileUploaderFiles, maxFiles, errorMessage]);
|
|
44
52
|
var stateFiles = state.files;
|
|
45
53
|
var onRootFocus = useCallback(function () {
|
|
46
54
|
return dispatch({
|