@olenbetong/synergi-react 4.1.1 → 4.1.2
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/es/components/ImageEditor/plugins/cropPlugin/useCropTool.js +3 -1
- package/es/components/ImageEditor/useEdgeDetection.d.ts +17 -2
- package/es/components/ImageEditor/useEdgeDetection.js +238 -61
- package/es/components/Toolbar/index.js +20 -1
- package/package.json +3 -3
- package/src/chrome/AppShell/index.tsx +29 -29
- package/src/chrome/openReport.ts +34 -34
- package/src/colorScheme.ts +81 -81
- package/src/components/DateNavigator/index.tsx +186 -186
- package/src/components/FilePond.tsx +312 -312
- package/src/components/ImageEditor/ImageEditor.tsx +343 -343
- package/src/components/ImageEditor/index.ts +9 -9
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -403
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
- package/src/components/ImageEditor/useEdgeDetection.ts +316 -127
- package/src/components/ImageEditor/useImageHistory.ts +197 -197
- package/src/components/ImageEditor/useOpenCV.ts +184 -184
- package/src/components/LinkedCardList/index.scss +95 -95
- package/src/components/MergeProgressDialog/index.tsx +249 -249
- package/src/components/PageBanner/index.tsx +80 -80
- package/src/components/PdfViewer/PdfViewer.tsx +158 -158
- package/src/components/ProgressBar/index.scss +96 -96
- package/src/components/SplitContainer/index.tsx +333 -333
- package/src/components/Toolbar/index.tsx +232 -212
- package/src/designsystemet-web-types.d.ts +24 -24
- package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
- package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
- package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
- package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
- package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
- package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
- package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
- package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
- package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
- package/src/elements/ElementLookup.tsx +123 -123
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -32
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -118
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -103
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -95
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -118
- package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -21
- package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +90 -90
- package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +280 -280
- package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
- package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
- package/src/elements/ElementLookupDialog/index.tsx +226 -226
- package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
- package/src/elements/ProjectSelect.tsx +130 -130
- package/src/elements/index.ts +15 -15
- package/src/filter/index.ts +34 -34
- package/src/i18n.ts +13 -13
- package/src/index.ts +77 -77
- package/src/mui/MuiThemeProvider.tsx +174 -174
- package/src/mui/index.ts +1 -1
- package/src/test/setup.ts +8 -8
|
@@ -1,312 +1,312 @@
|
|
|
1
|
-
import "filepond-plugin-file-poster/dist/filepond-plugin-file-poster.css";
|
|
2
|
-
import "filepond-plugin-image-preview/dist/filepond-plugin-image-preview.css";
|
|
3
|
-
import "filepond/dist/filepond.css";
|
|
4
|
-
|
|
5
|
-
import type { DataObject } from "@olenbetong/appframe-data";
|
|
6
|
-
import { useData, useFetchData } from "@olenbetong/appframe-react";
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
create,
|
|
10
|
-
type FilePondErrorDescription,
|
|
11
|
-
type FilePondFile,
|
|
12
|
-
type FilePondInitialFile,
|
|
13
|
-
type FilePond as FilePondInstance,
|
|
14
|
-
type FilePondOptions,
|
|
15
|
-
FileStatus,
|
|
16
|
-
registerPlugin,
|
|
17
|
-
} from "filepond";
|
|
18
|
-
import FilePondPluginImageExifOrientation from "filepond-plugin-image-exif-orientation";
|
|
19
|
-
import FilePondPluginImagePreview from "filepond-plugin-image-preview";
|
|
20
|
-
import FilePondPluginImageResize from "filepond-plugin-image-resize";
|
|
21
|
-
import FilePondPluginImageTransform from "filepond-plugin-image-transform";
|
|
22
|
-
import { type RefObject, useEffect, useMemo, useRef } from "react";
|
|
23
|
-
import { getLocalizedString } from "../i18n.js";
|
|
24
|
-
|
|
25
|
-
export { FileStatus, registerPlugin };
|
|
26
|
-
|
|
27
|
-
registerPlugin(
|
|
28
|
-
FilePondPluginImageExifOrientation,
|
|
29
|
-
FilePondPluginImageResize,
|
|
30
|
-
FilePondPluginImagePreview,
|
|
31
|
-
FilePondPluginImageTransform,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
let isMostLikelyMobile =
|
|
35
|
-
navigator.userAgent.match(/Android/i) ||
|
|
36
|
-
navigator.userAgent.match(/iPhone/i) ||
|
|
37
|
-
navigator.userAgent.match(/iPad/i) ||
|
|
38
|
-
navigator.userAgent.match(/iPod/i);
|
|
39
|
-
|
|
40
|
-
const labels = {
|
|
41
|
-
labelIdle: isMostLikelyMobile
|
|
42
|
-
? getLocalizedString("Take a photo, or upload an existing image/file")
|
|
43
|
-
: getLocalizedString('Drag & Drop your files or <span class="filepond--label-action"> Browse </span>'),
|
|
44
|
-
labelInvalidField: getLocalizedString("Field contains invalid files"),
|
|
45
|
-
labelFileWaitingForSize: getLocalizedString("Waiting for size"),
|
|
46
|
-
labelFileSizeNotAvailable: getLocalizedString("Size not available"),
|
|
47
|
-
labelFileLoading: getLocalizedString("Loading"),
|
|
48
|
-
labelFileLoadError: getLocalizedString("Error during load"),
|
|
49
|
-
labelFileProcessing: getLocalizedString("Uploading"),
|
|
50
|
-
labelFileProcessingComplete: getLocalizedString("Upload complete"),
|
|
51
|
-
labelFileProcessingAborted: getLocalizedString("Upload cancelled"),
|
|
52
|
-
labelFileProcessingError: getLocalizedString("Error during upload"),
|
|
53
|
-
labelFileProcessingRevertError: getLocalizedString("Error during revert"),
|
|
54
|
-
labelFileRemoveError: getLocalizedString("Error during remove"),
|
|
55
|
-
labelTapToCancel: getLocalizedString("tap to cancel"),
|
|
56
|
-
labelTapToRetry: getLocalizedString("tap to retry"),
|
|
57
|
-
labelTapToUndo: getLocalizedString("tap to undo"),
|
|
58
|
-
labelButtonRemoveItem: getLocalizedString("Remove"),
|
|
59
|
-
labelButtonAbortItemLoad: getLocalizedString("Abort"),
|
|
60
|
-
labelButtonRetryItemLoad: getLocalizedString("Retry"),
|
|
61
|
-
labelButtonAbortItemProcessing: getLocalizedString("Cancel"),
|
|
62
|
-
labelButtonUndoItemProcessing: getLocalizedString("Undo"),
|
|
63
|
-
labelButtonRetryItemProcessing: getLocalizedString("Retry"),
|
|
64
|
-
labelButtonProcessItem: getLocalizedString("Upload"),
|
|
65
|
-
labelMaxFileSizeExceeded: getLocalizedString("File is too large"),
|
|
66
|
-
labelMaxFileSize: getLocalizedString("Maximum file size is {filesize}"),
|
|
67
|
-
labelMaxTotalFileSizeExceeded: getLocalizedString("Maximum total size exceeded"),
|
|
68
|
-
labelMaxTotalFileSize: getLocalizedString("Maximum total file size is {filesize}"),
|
|
69
|
-
labelFileTypeNotAllowed: getLocalizedString("File of invalid type"),
|
|
70
|
-
fileValidateTypeLabelExpectedTypes: getLocalizedString("Expects {allButLastType} or {lastType}"),
|
|
71
|
-
imageValidateSizeLabelFormatError: getLocalizedString("Image type not supported"),
|
|
72
|
-
imageValidateSizeLabelImageSizeTooSmall: getLocalizedString("Image is too small"),
|
|
73
|
-
imageValidateSizeLabelImageSizeTooBig: getLocalizedString("Image is too big"),
|
|
74
|
-
imageValidateSizeLabelExpectedMinSize: getLocalizedString("Minimum size is {minWidth} × {minHeight}"),
|
|
75
|
-
imageValidateSizeLabelExpectedMaxSize: getLocalizedString("Maximum size is {maxWidth} × {maxHeight}"),
|
|
76
|
-
imageValidateSizeLabelImageResolutionTooLow: getLocalizedString("Resolution is too low"),
|
|
77
|
-
imageValidateSizeLabelImageResolutionTooHigh: getLocalizedString("Resolution is too high"),
|
|
78
|
-
imageValidateSizeLabelExpectedMinResolution: getLocalizedString("Minimum resolution is {minResolution}"),
|
|
79
|
-
imageValidateSizeLabelExpectedMaxResolution: getLocalizedString("Maximum resolution is {maxResolution}"),
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
type FilePondProps<T extends Record<string, unknown>> = React.HTMLProps<HTMLInputElement> & {
|
|
83
|
-
dataObject: DataObject<T>;
|
|
84
|
-
fields: Partial<T>;
|
|
85
|
-
onUploadStart: () => void;
|
|
86
|
-
onFileUploaded: (error: FilePondErrorDescription | null, file: FilePondFile) => void;
|
|
87
|
-
onFinishedUploads: () => void;
|
|
88
|
-
onError: (error: string) => void;
|
|
89
|
-
onFileRemoved?: (primKey: string) => void;
|
|
90
|
-
/**
|
|
91
|
-
* If the file should be uploaded to a blob field, set the field name here
|
|
92
|
-
*/
|
|
93
|
-
fieldName?: string;
|
|
94
|
-
/**
|
|
95
|
-
* If the file should be added to an existing record, set the prim key here
|
|
96
|
-
*/
|
|
97
|
-
primKey?: string;
|
|
98
|
-
/**
|
|
99
|
-
* If a reference to the file input element is needed, pass a ref here.
|
|
100
|
-
*/
|
|
101
|
-
inputRef?: RefObject<HTMLInputElement>;
|
|
102
|
-
/**
|
|
103
|
-
* Options to pass to FilePond
|
|
104
|
-
*/
|
|
105
|
-
filePondOptions?: Partial<FilePondOptions>;
|
|
106
|
-
attachmentPrimKeys?: string[];
|
|
107
|
-
whereClause?: string;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
function getFileUrl<T extends Record<string, unknown>>(
|
|
111
|
-
dataObject: DataObject<T>,
|
|
112
|
-
fieldName?: string,
|
|
113
|
-
primKey?: string,
|
|
114
|
-
action = "upload",
|
|
115
|
-
) {
|
|
116
|
-
let url =
|
|
117
|
-
action === "upload"
|
|
118
|
-
? dataObject.dataHandler.getUploadUrl()
|
|
119
|
-
: dataObject.dataHandler.getFileStoreURL(primKey ?? "", fieldName ?? "");
|
|
120
|
-
|
|
121
|
-
if (action === "upload") {
|
|
122
|
-
url += "/";
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return url?.replaceAll("//", "/") ?? "";
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
type FileStoreDataObjectRecord = {
|
|
129
|
-
PrimKey: string;
|
|
130
|
-
FileName: string | null;
|
|
131
|
-
FileSize: number | null;
|
|
132
|
-
FileRef: string | null;
|
|
133
|
-
ElementRef: string | null;
|
|
134
|
-
Damage: boolean;
|
|
135
|
-
DamageID: number | null;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export function FilePond<T extends FileStoreDataObjectRecord>({
|
|
139
|
-
dataObject,
|
|
140
|
-
fields,
|
|
141
|
-
onUploadStart,
|
|
142
|
-
onFileUploaded,
|
|
143
|
-
onFinishedUploads,
|
|
144
|
-
onFileRemoved,
|
|
145
|
-
onError,
|
|
146
|
-
fieldName,
|
|
147
|
-
filePondOptions,
|
|
148
|
-
primKey,
|
|
149
|
-
attachmentPrimKeys,
|
|
150
|
-
whereClause,
|
|
151
|
-
inputRef: inputRefProp,
|
|
152
|
-
...props
|
|
153
|
-
}: FilePondProps<T>) {
|
|
154
|
-
let inputRef = useRef<HTMLInputElement>(null);
|
|
155
|
-
let pondRef = useRef<FilePondInstance | null>(null);
|
|
156
|
-
let filesData = useData(dataObject);
|
|
157
|
-
let { data: filesFetched } = useFetchData(dataObject, whereClause ?? "1=2");
|
|
158
|
-
let files = useMemo(() => {
|
|
159
|
-
if (whereClause) {
|
|
160
|
-
return filesFetched;
|
|
161
|
-
}
|
|
162
|
-
return filesData;
|
|
163
|
-
}, [whereClause, filesFetched, filesData]);
|
|
164
|
-
let clearFilesRef = useRef(false);
|
|
165
|
-
|
|
166
|
-
useEffect(() => {
|
|
167
|
-
return () => {
|
|
168
|
-
pondRef.current?.destroy();
|
|
169
|
-
pondRef.current = null;
|
|
170
|
-
};
|
|
171
|
-
}, []);
|
|
172
|
-
|
|
173
|
-
useEffect(() => {
|
|
174
|
-
async function removeUploadedFile(source: string, load: () => void, error: (error: string) => void) {
|
|
175
|
-
// this method is also called when we clear the files on data object
|
|
176
|
-
// refresh. Haven't found any elegant way to work around that, so instead
|
|
177
|
-
// we set this ref to true when we remove the files to have a way
|
|
178
|
-
// to discover why the files are being removed
|
|
179
|
-
if (clearFilesRef.current) return;
|
|
180
|
-
|
|
181
|
-
let { dataHandler } = dataObject;
|
|
182
|
-
try {
|
|
183
|
-
let result = await dataHandler.destroy({
|
|
184
|
-
PrimKey: source,
|
|
185
|
-
} as Partial<T>);
|
|
186
|
-
|
|
187
|
-
if (result) {
|
|
188
|
-
onFileRemoved?.(source);
|
|
189
|
-
load();
|
|
190
|
-
} else {
|
|
191
|
-
error("Failed to delete file on server. Delete request returned false");
|
|
192
|
-
}
|
|
193
|
-
} catch (err: any) {
|
|
194
|
-
error(
|
|
195
|
-
err.responseText ??
|
|
196
|
-
err.statusText ??
|
|
197
|
-
err.message ??
|
|
198
|
-
"Failed to delete file on server but no error was returned.",
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
let options: FilePondOptions = {
|
|
204
|
-
allowMultiple: Boolean(props.multiple),
|
|
205
|
-
allowImageResize: true,
|
|
206
|
-
imageResizeMode: "contain",
|
|
207
|
-
imageResizeTargetWidth: 2400,
|
|
208
|
-
imageResizeTargetHeight: 2400,
|
|
209
|
-
imageResizeUpscale: false,
|
|
210
|
-
...labels,
|
|
211
|
-
onaddfilestart: (file) => {
|
|
212
|
-
if (file.status !== 5 && file.status !== 6 && file.status !== 10) {
|
|
213
|
-
onUploadStart();
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
onprocessfile: (error, file) => {
|
|
217
|
-
onFileUploaded(error, file);
|
|
218
|
-
|
|
219
|
-
let refFiles = pondRef.current?.getFiles();
|
|
220
|
-
let found = refFiles?.find(
|
|
221
|
-
(file) => file.status !== 2 && file.status !== 5 && file.status !== 6 && file.status !== 10,
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
if (found === undefined) {
|
|
225
|
-
onFinishedUploads();
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
onprocessfiles: () => onFinishedUploads(),
|
|
229
|
-
onerror: (error) => onError(error.body),
|
|
230
|
-
beforeRemoveFile: () => {
|
|
231
|
-
if (confirm(getLocalizedString("Are you sure you want to remove this file?"))) {
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return false;
|
|
236
|
-
},
|
|
237
|
-
server: {
|
|
238
|
-
load: getFileUrl(dataObject, fieldName, primKey, "view"),
|
|
239
|
-
restore: getFileUrl(dataObject, fieldName, primKey, "view"),
|
|
240
|
-
|
|
241
|
-
revert: removeUploadedFile,
|
|
242
|
-
remove: removeUploadedFile,
|
|
243
|
-
|
|
244
|
-
process: {
|
|
245
|
-
url: getFileUrl(dataObject, fieldName),
|
|
246
|
-
ondata: (formData) => {
|
|
247
|
-
let masterChildCriteria = dataObject.getParameter("masterChildCriteria");
|
|
248
|
-
let allFields = { ...masterChildCriteria, ...fields };
|
|
249
|
-
|
|
250
|
-
for (let [field, value] of Object.entries(allFields)) {
|
|
251
|
-
if (value !== undefined) {
|
|
252
|
-
formData.append(field, String(value));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return formData;
|
|
257
|
-
},
|
|
258
|
-
onload: (response) => JSON.parse(response),
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
...filePondOptions,
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
if (pondRef.current) {
|
|
265
|
-
pondRef.current.setOptions(options);
|
|
266
|
-
} else {
|
|
267
|
-
pondRef.current = create(inputRefProp?.current ?? inputRef.current ?? undefined, options);
|
|
268
|
-
}
|
|
269
|
-
}, [
|
|
270
|
-
dataObject,
|
|
271
|
-
props.multiple,
|
|
272
|
-
fields,
|
|
273
|
-
fieldName,
|
|
274
|
-
primKey,
|
|
275
|
-
inputRefProp,
|
|
276
|
-
filePondOptions,
|
|
277
|
-
onError,
|
|
278
|
-
onFileUploaded,
|
|
279
|
-
onUploadStart,
|
|
280
|
-
onFinishedUploads,
|
|
281
|
-
onFileRemoved,
|
|
282
|
-
]);
|
|
283
|
-
|
|
284
|
-
useEffect(() => {
|
|
285
|
-
if (pondRef.current) {
|
|
286
|
-
files.forEach((file, index) => {
|
|
287
|
-
let options: { index: number } & Partial<FilePondInitialFile["options"]> = {
|
|
288
|
-
index,
|
|
289
|
-
type: "local",
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
pondRef.current?.addFile(file.PrimKey, options);
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return () => {
|
|
297
|
-
// Indicate that we are clearing the files because data has changed,
|
|
298
|
-
// to prevent the remove callback from deleting the files
|
|
299
|
-
clearFilesRef.current = true;
|
|
300
|
-
pondRef.current?.removeFiles();
|
|
301
|
-
clearFilesRef.current = false;
|
|
302
|
-
};
|
|
303
|
-
}, [files]);
|
|
304
|
-
|
|
305
|
-
return (
|
|
306
|
-
<div className="filepond--wrapper">
|
|
307
|
-
{attachmentPrimKeys && <input type="hidden" name="AttachmentPrimkeys" value={attachmentPrimKeys} />}
|
|
308
|
-
|
|
309
|
-
<input type="file" {...props} name="File" ref={inputRefProp ?? inputRef} />
|
|
310
|
-
</div>
|
|
311
|
-
);
|
|
312
|
-
}
|
|
1
|
+
import "filepond-plugin-file-poster/dist/filepond-plugin-file-poster.css";
|
|
2
|
+
import "filepond-plugin-image-preview/dist/filepond-plugin-image-preview.css";
|
|
3
|
+
import "filepond/dist/filepond.css";
|
|
4
|
+
|
|
5
|
+
import type { DataObject } from "@olenbetong/appframe-data";
|
|
6
|
+
import { useData, useFetchData } from "@olenbetong/appframe-react";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
create,
|
|
10
|
+
type FilePondErrorDescription,
|
|
11
|
+
type FilePondFile,
|
|
12
|
+
type FilePondInitialFile,
|
|
13
|
+
type FilePond as FilePondInstance,
|
|
14
|
+
type FilePondOptions,
|
|
15
|
+
FileStatus,
|
|
16
|
+
registerPlugin,
|
|
17
|
+
} from "filepond";
|
|
18
|
+
import FilePondPluginImageExifOrientation from "filepond-plugin-image-exif-orientation";
|
|
19
|
+
import FilePondPluginImagePreview from "filepond-plugin-image-preview";
|
|
20
|
+
import FilePondPluginImageResize from "filepond-plugin-image-resize";
|
|
21
|
+
import FilePondPluginImageTransform from "filepond-plugin-image-transform";
|
|
22
|
+
import { type RefObject, useEffect, useMemo, useRef } from "react";
|
|
23
|
+
import { getLocalizedString } from "../i18n.js";
|
|
24
|
+
|
|
25
|
+
export { FileStatus, registerPlugin };
|
|
26
|
+
|
|
27
|
+
registerPlugin(
|
|
28
|
+
FilePondPluginImageExifOrientation,
|
|
29
|
+
FilePondPluginImageResize,
|
|
30
|
+
FilePondPluginImagePreview,
|
|
31
|
+
FilePondPluginImageTransform,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
let isMostLikelyMobile =
|
|
35
|
+
navigator.userAgent.match(/Android/i) ||
|
|
36
|
+
navigator.userAgent.match(/iPhone/i) ||
|
|
37
|
+
navigator.userAgent.match(/iPad/i) ||
|
|
38
|
+
navigator.userAgent.match(/iPod/i);
|
|
39
|
+
|
|
40
|
+
const labels = {
|
|
41
|
+
labelIdle: isMostLikelyMobile
|
|
42
|
+
? getLocalizedString("Take a photo, or upload an existing image/file")
|
|
43
|
+
: getLocalizedString('Drag & Drop your files or <span class="filepond--label-action"> Browse </span>'),
|
|
44
|
+
labelInvalidField: getLocalizedString("Field contains invalid files"),
|
|
45
|
+
labelFileWaitingForSize: getLocalizedString("Waiting for size"),
|
|
46
|
+
labelFileSizeNotAvailable: getLocalizedString("Size not available"),
|
|
47
|
+
labelFileLoading: getLocalizedString("Loading"),
|
|
48
|
+
labelFileLoadError: getLocalizedString("Error during load"),
|
|
49
|
+
labelFileProcessing: getLocalizedString("Uploading"),
|
|
50
|
+
labelFileProcessingComplete: getLocalizedString("Upload complete"),
|
|
51
|
+
labelFileProcessingAborted: getLocalizedString("Upload cancelled"),
|
|
52
|
+
labelFileProcessingError: getLocalizedString("Error during upload"),
|
|
53
|
+
labelFileProcessingRevertError: getLocalizedString("Error during revert"),
|
|
54
|
+
labelFileRemoveError: getLocalizedString("Error during remove"),
|
|
55
|
+
labelTapToCancel: getLocalizedString("tap to cancel"),
|
|
56
|
+
labelTapToRetry: getLocalizedString("tap to retry"),
|
|
57
|
+
labelTapToUndo: getLocalizedString("tap to undo"),
|
|
58
|
+
labelButtonRemoveItem: getLocalizedString("Remove"),
|
|
59
|
+
labelButtonAbortItemLoad: getLocalizedString("Abort"),
|
|
60
|
+
labelButtonRetryItemLoad: getLocalizedString("Retry"),
|
|
61
|
+
labelButtonAbortItemProcessing: getLocalizedString("Cancel"),
|
|
62
|
+
labelButtonUndoItemProcessing: getLocalizedString("Undo"),
|
|
63
|
+
labelButtonRetryItemProcessing: getLocalizedString("Retry"),
|
|
64
|
+
labelButtonProcessItem: getLocalizedString("Upload"),
|
|
65
|
+
labelMaxFileSizeExceeded: getLocalizedString("File is too large"),
|
|
66
|
+
labelMaxFileSize: getLocalizedString("Maximum file size is {filesize}"),
|
|
67
|
+
labelMaxTotalFileSizeExceeded: getLocalizedString("Maximum total size exceeded"),
|
|
68
|
+
labelMaxTotalFileSize: getLocalizedString("Maximum total file size is {filesize}"),
|
|
69
|
+
labelFileTypeNotAllowed: getLocalizedString("File of invalid type"),
|
|
70
|
+
fileValidateTypeLabelExpectedTypes: getLocalizedString("Expects {allButLastType} or {lastType}"),
|
|
71
|
+
imageValidateSizeLabelFormatError: getLocalizedString("Image type not supported"),
|
|
72
|
+
imageValidateSizeLabelImageSizeTooSmall: getLocalizedString("Image is too small"),
|
|
73
|
+
imageValidateSizeLabelImageSizeTooBig: getLocalizedString("Image is too big"),
|
|
74
|
+
imageValidateSizeLabelExpectedMinSize: getLocalizedString("Minimum size is {minWidth} × {minHeight}"),
|
|
75
|
+
imageValidateSizeLabelExpectedMaxSize: getLocalizedString("Maximum size is {maxWidth} × {maxHeight}"),
|
|
76
|
+
imageValidateSizeLabelImageResolutionTooLow: getLocalizedString("Resolution is too low"),
|
|
77
|
+
imageValidateSizeLabelImageResolutionTooHigh: getLocalizedString("Resolution is too high"),
|
|
78
|
+
imageValidateSizeLabelExpectedMinResolution: getLocalizedString("Minimum resolution is {minResolution}"),
|
|
79
|
+
imageValidateSizeLabelExpectedMaxResolution: getLocalizedString("Maximum resolution is {maxResolution}"),
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
type FilePondProps<T extends Record<string, unknown>> = React.HTMLProps<HTMLInputElement> & {
|
|
83
|
+
dataObject: DataObject<T>;
|
|
84
|
+
fields: Partial<T>;
|
|
85
|
+
onUploadStart: () => void;
|
|
86
|
+
onFileUploaded: (error: FilePondErrorDescription | null, file: FilePondFile) => void;
|
|
87
|
+
onFinishedUploads: () => void;
|
|
88
|
+
onError: (error: string) => void;
|
|
89
|
+
onFileRemoved?: (primKey: string) => void;
|
|
90
|
+
/**
|
|
91
|
+
* If the file should be uploaded to a blob field, set the field name here
|
|
92
|
+
*/
|
|
93
|
+
fieldName?: string;
|
|
94
|
+
/**
|
|
95
|
+
* If the file should be added to an existing record, set the prim key here
|
|
96
|
+
*/
|
|
97
|
+
primKey?: string;
|
|
98
|
+
/**
|
|
99
|
+
* If a reference to the file input element is needed, pass a ref here.
|
|
100
|
+
*/
|
|
101
|
+
inputRef?: RefObject<HTMLInputElement>;
|
|
102
|
+
/**
|
|
103
|
+
* Options to pass to FilePond
|
|
104
|
+
*/
|
|
105
|
+
filePondOptions?: Partial<FilePondOptions>;
|
|
106
|
+
attachmentPrimKeys?: string[];
|
|
107
|
+
whereClause?: string;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
function getFileUrl<T extends Record<string, unknown>>(
|
|
111
|
+
dataObject: DataObject<T>,
|
|
112
|
+
fieldName?: string,
|
|
113
|
+
primKey?: string,
|
|
114
|
+
action = "upload",
|
|
115
|
+
) {
|
|
116
|
+
let url =
|
|
117
|
+
action === "upload"
|
|
118
|
+
? dataObject.dataHandler.getUploadUrl()
|
|
119
|
+
: dataObject.dataHandler.getFileStoreURL(primKey ?? "", fieldName ?? "");
|
|
120
|
+
|
|
121
|
+
if (action === "upload") {
|
|
122
|
+
url += "/";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return url?.replaceAll("//", "/") ?? "";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
type FileStoreDataObjectRecord = {
|
|
129
|
+
PrimKey: string;
|
|
130
|
+
FileName: string | null;
|
|
131
|
+
FileSize: number | null;
|
|
132
|
+
FileRef: string | null;
|
|
133
|
+
ElementRef: string | null;
|
|
134
|
+
Damage: boolean;
|
|
135
|
+
DamageID: number | null;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export function FilePond<T extends FileStoreDataObjectRecord>({
|
|
139
|
+
dataObject,
|
|
140
|
+
fields,
|
|
141
|
+
onUploadStart,
|
|
142
|
+
onFileUploaded,
|
|
143
|
+
onFinishedUploads,
|
|
144
|
+
onFileRemoved,
|
|
145
|
+
onError,
|
|
146
|
+
fieldName,
|
|
147
|
+
filePondOptions,
|
|
148
|
+
primKey,
|
|
149
|
+
attachmentPrimKeys,
|
|
150
|
+
whereClause,
|
|
151
|
+
inputRef: inputRefProp,
|
|
152
|
+
...props
|
|
153
|
+
}: FilePondProps<T>) {
|
|
154
|
+
let inputRef = useRef<HTMLInputElement>(null);
|
|
155
|
+
let pondRef = useRef<FilePondInstance | null>(null);
|
|
156
|
+
let filesData = useData(dataObject);
|
|
157
|
+
let { data: filesFetched } = useFetchData(dataObject, whereClause ?? "1=2");
|
|
158
|
+
let files = useMemo(() => {
|
|
159
|
+
if (whereClause) {
|
|
160
|
+
return filesFetched;
|
|
161
|
+
}
|
|
162
|
+
return filesData;
|
|
163
|
+
}, [whereClause, filesFetched, filesData]);
|
|
164
|
+
let clearFilesRef = useRef(false);
|
|
165
|
+
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
return () => {
|
|
168
|
+
pondRef.current?.destroy();
|
|
169
|
+
pondRef.current = null;
|
|
170
|
+
};
|
|
171
|
+
}, []);
|
|
172
|
+
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
async function removeUploadedFile(source: string, load: () => void, error: (error: string) => void) {
|
|
175
|
+
// this method is also called when we clear the files on data object
|
|
176
|
+
// refresh. Haven't found any elegant way to work around that, so instead
|
|
177
|
+
// we set this ref to true when we remove the files to have a way
|
|
178
|
+
// to discover why the files are being removed
|
|
179
|
+
if (clearFilesRef.current) return;
|
|
180
|
+
|
|
181
|
+
let { dataHandler } = dataObject;
|
|
182
|
+
try {
|
|
183
|
+
let result = await dataHandler.destroy({
|
|
184
|
+
PrimKey: source,
|
|
185
|
+
} as Partial<T>);
|
|
186
|
+
|
|
187
|
+
if (result) {
|
|
188
|
+
onFileRemoved?.(source);
|
|
189
|
+
load();
|
|
190
|
+
} else {
|
|
191
|
+
error("Failed to delete file on server. Delete request returned false");
|
|
192
|
+
}
|
|
193
|
+
} catch (err: any) {
|
|
194
|
+
error(
|
|
195
|
+
err.responseText ??
|
|
196
|
+
err.statusText ??
|
|
197
|
+
err.message ??
|
|
198
|
+
"Failed to delete file on server but no error was returned.",
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
let options: FilePondOptions = {
|
|
204
|
+
allowMultiple: Boolean(props.multiple),
|
|
205
|
+
allowImageResize: true,
|
|
206
|
+
imageResizeMode: "contain",
|
|
207
|
+
imageResizeTargetWidth: 2400,
|
|
208
|
+
imageResizeTargetHeight: 2400,
|
|
209
|
+
imageResizeUpscale: false,
|
|
210
|
+
...labels,
|
|
211
|
+
onaddfilestart: (file) => {
|
|
212
|
+
if (file.status !== 5 && file.status !== 6 && file.status !== 10) {
|
|
213
|
+
onUploadStart();
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
onprocessfile: (error, file) => {
|
|
217
|
+
onFileUploaded(error, file);
|
|
218
|
+
|
|
219
|
+
let refFiles = pondRef.current?.getFiles();
|
|
220
|
+
let found = refFiles?.find(
|
|
221
|
+
(file) => file.status !== 2 && file.status !== 5 && file.status !== 6 && file.status !== 10,
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
if (found === undefined) {
|
|
225
|
+
onFinishedUploads();
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
onprocessfiles: () => onFinishedUploads(),
|
|
229
|
+
onerror: (error) => onError(error.body),
|
|
230
|
+
beforeRemoveFile: () => {
|
|
231
|
+
if (confirm(getLocalizedString("Are you sure you want to remove this file?"))) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return false;
|
|
236
|
+
},
|
|
237
|
+
server: {
|
|
238
|
+
load: getFileUrl(dataObject, fieldName, primKey, "view"),
|
|
239
|
+
restore: getFileUrl(dataObject, fieldName, primKey, "view"),
|
|
240
|
+
|
|
241
|
+
revert: removeUploadedFile,
|
|
242
|
+
remove: removeUploadedFile,
|
|
243
|
+
|
|
244
|
+
process: {
|
|
245
|
+
url: getFileUrl(dataObject, fieldName),
|
|
246
|
+
ondata: (formData) => {
|
|
247
|
+
let masterChildCriteria = dataObject.getParameter("masterChildCriteria");
|
|
248
|
+
let allFields = { ...masterChildCriteria, ...fields };
|
|
249
|
+
|
|
250
|
+
for (let [field, value] of Object.entries(allFields)) {
|
|
251
|
+
if (value !== undefined) {
|
|
252
|
+
formData.append(field, String(value));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return formData;
|
|
257
|
+
},
|
|
258
|
+
onload: (response) => JSON.parse(response),
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
...filePondOptions,
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
if (pondRef.current) {
|
|
265
|
+
pondRef.current.setOptions(options);
|
|
266
|
+
} else {
|
|
267
|
+
pondRef.current = create(inputRefProp?.current ?? inputRef.current ?? undefined, options);
|
|
268
|
+
}
|
|
269
|
+
}, [
|
|
270
|
+
dataObject,
|
|
271
|
+
props.multiple,
|
|
272
|
+
fields,
|
|
273
|
+
fieldName,
|
|
274
|
+
primKey,
|
|
275
|
+
inputRefProp,
|
|
276
|
+
filePondOptions,
|
|
277
|
+
onError,
|
|
278
|
+
onFileUploaded,
|
|
279
|
+
onUploadStart,
|
|
280
|
+
onFinishedUploads,
|
|
281
|
+
onFileRemoved,
|
|
282
|
+
]);
|
|
283
|
+
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
if (pondRef.current) {
|
|
286
|
+
files.forEach((file, index) => {
|
|
287
|
+
let options: { index: number } & Partial<FilePondInitialFile["options"]> = {
|
|
288
|
+
index,
|
|
289
|
+
type: "local",
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
pondRef.current?.addFile(file.PrimKey, options);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return () => {
|
|
297
|
+
// Indicate that we are clearing the files because data has changed,
|
|
298
|
+
// to prevent the remove callback from deleting the files
|
|
299
|
+
clearFilesRef.current = true;
|
|
300
|
+
pondRef.current?.removeFiles();
|
|
301
|
+
clearFilesRef.current = false;
|
|
302
|
+
};
|
|
303
|
+
}, [files]);
|
|
304
|
+
|
|
305
|
+
return (
|
|
306
|
+
<div className="filepond--wrapper">
|
|
307
|
+
{attachmentPrimKeys && <input type="hidden" name="AttachmentPrimkeys" value={attachmentPrimKeys} />}
|
|
308
|
+
|
|
309
|
+
<input type="file" {...props} name="File" ref={inputRefProp ?? inputRef} />
|
|
310
|
+
</div>
|
|
311
|
+
);
|
|
312
|
+
}
|