@olenbetong/synergi-react 5.0.0 → 5.1.0
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/Checkbox/index.js +1 -9
- package/es/components/CodeEditor/CodeEditor.css +6 -6
- package/es/components/FilePond.js +3 -12
- package/es/components/ImageEditor/plugins/redactPlugin/useRedactTool.js +18 -14
- package/es/components/ImageEditor/useImageHistory.js +13 -1
- package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +1 -1
- package/es/components/MergeProgressDialog/useMergeJob.js +5 -4
- package/es/components/Portal/index.js +20 -20
- package/es/components/SplitContainer/index.js +3 -1
- package/es/components/Toolbar/Toolbar.css +137 -137
- package/es/components/Toolbar/index.js +6 -1
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +8 -0
- package/es/elements/ElementLookupDialog/HIDScanner/useHIDScanner.js +3 -1
- package/es/elements-ds/DescriptionInput.d.ts +16 -0
- package/es/elements-ds/DescriptionInput.js +41 -0
- package/es/elements-ds/DuplicateElementDamage.d.ts +40 -0
- package/es/elements-ds/DuplicateElementDamage.js +57 -0
- package/es/elements-ds/ElementLookup.d.ts +23 -0
- package/es/elements-ds/ElementLookup.js +35 -0
- package/es/elements-ds/ElementLookupDialog.d.ts +7 -0
- package/es/elements-ds/ElementLookupDialog.js +84 -0
- package/es/elements-ds/FormFields.d.ts +43 -0
- package/es/elements-ds/FormFields.js +67 -0
- package/es/elements-ds/HIDScanner.d.ts +7 -0
- package/es/elements-ds/HIDScanner.js +36 -0
- package/es/elements-ds/ManualForm.d.ts +7 -0
- package/es/elements-ds/ManualForm.js +70 -0
- package/es/elements-ds/ProjectSelect.d.ts +28 -0
- package/es/elements-ds/ProjectSelect.js +45 -0
- package/es/elements-ds/elements-ds.css +157 -0
- package/es/elements-ds/index.d.ts +12 -0
- package/es/elements-ds/index.js +14 -0
- package/es/useTranslation/index.js +5 -3
- package/package.json +15 -3
- package/src/chrome/AppShell/AppShell.test.tsx +48 -0
- package/src/chrome/AppShell/index.tsx +29 -29
- package/src/chrome/openReport.test.ts +50 -0
- package/src/chrome/openReport.ts +34 -34
- package/src/colorScheme.test.ts +188 -0
- package/src/colorScheme.ts +125 -125
- package/src/components/Checkbox/Checkbox.browser.test.tsx +116 -0
- package/src/components/Checkbox/index.tsx +1 -10
- package/src/components/CodeEditor/CodeEditor.css +6 -6
- package/src/components/CodeEditor/CodeEditor.tsx +173 -173
- package/src/components/CodeEditor/index.ts +1 -1
- package/src/components/ColorCard/ColorCard.test.tsx +34 -0
- package/src/components/DateNavigator/DateNavigator.test.tsx +175 -0
- package/src/components/DateNavigator/index.tsx +186 -186
- package/src/components/FilePond.browser.test.tsx +389 -0
- package/src/components/FilePond.tsx +303 -312
- package/src/components/ImageEditor/ImageEditor.browser.test.tsx +286 -0
- package/src/components/ImageEditor/ImageEditor.test.tsx +299 -0
- package/src/components/ImageEditor/ImageEditor.tsx +348 -348
- 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.test.ts +225 -0
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
- package/src/components/ImageEditor/plugins/plugins.browser.test.ts +252 -0
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
- package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.test.ts +89 -0
- package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.ts +16 -13
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
- package/src/components/ImageEditor/plugins/zoomPlugin/useZoomPan.test.ts +154 -0
- package/src/components/ImageEditor/useActiveTool.ts +21 -21
- package/src/components/ImageEditor/useEdgeDetection.test.ts +96 -0
- package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
- package/src/components/ImageEditor/useImageHistory.test.ts +409 -0
- package/src/components/ImageEditor/useImageHistory.ts +206 -197
- package/src/components/ImageEditor/useOpenCV.test.ts +208 -0
- package/src/components/ImageEditor/useOpenCV.ts +184 -184
- package/src/components/LinkedCardList/index.scss +95 -95
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.browser.test.tsx +156 -0
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +1 -0
- package/src/components/MergeProgressDialog/useMergeJob.test.ts +326 -0
- package/src/components/MergeProgressDialog/useMergeJob.ts +4 -3
- package/src/components/PageBanner/index.tsx +80 -80
- package/src/components/PdfViewer/PdfViewer.browser.test.tsx +78 -0
- package/src/components/PdfViewer/PdfViewer.tsx +158 -158
- package/src/components/Portal/Portal.test.tsx +106 -0
- package/src/components/Portal/index.tsx +22 -25
- package/src/components/Sidebar/Sidebar.browser.test.tsx +57 -0
- package/src/components/Sidebar/Sidebar.test.tsx +123 -0
- package/src/components/SplitContainer/SplitContainer.browser.test.tsx +304 -0
- package/src/components/SplitContainer/index.tsx +335 -333
- package/src/components/Toolbar/Toolbar.css +137 -137
- package/src/components/Toolbar/Toolbar.test.tsx +216 -0
- package/src/components/Toolbar/ToolbarBreadcrumbs.browser.test.tsx +137 -0
- package/src/components/Toolbar/index.tsx +270 -265
- package/src/components/ValueToggleGroup/ValueToggleGroup.test.tsx +112 -0
- 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/BarcodeScanner.browser.test.tsx +175 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +8 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/engines.browser.test.ts +225 -0
- package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
- package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.test.ts +124 -0
- package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.ts +2 -1
- package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
- package/src/elements/ElementLookupDialog/getElement.test.ts +133 -0
- package/src/elements/ElementLookupDialog/index.tsx +226 -226
- package/src/elements/ElementLookupDialog/utils/Giai.test.ts +53 -0
- 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/elements-ds/DamageForm.browser.test.tsx +530 -0
- package/src/elements-ds/DescriptionInput.tsx +114 -0
- package/src/elements-ds/DuplicateElementDamage.tsx +185 -0
- package/src/elements-ds/ElementLookup.tsx +114 -0
- package/src/elements-ds/ElementLookupDialog.browser.test.tsx +207 -0
- package/src/elements-ds/ElementLookupDialog.tsx +196 -0
- package/src/elements-ds/FormFields.tsx +176 -0
- package/src/elements-ds/HIDScanner.tsx +53 -0
- package/src/elements-ds/ManualForm.tsx +129 -0
- package/src/elements-ds/ProjectSelect.tsx +120 -0
- package/src/elements-ds/elements-ds.css +157 -0
- package/src/elements-ds/index.ts +16 -0
- package/src/filter/index.ts +34 -34
- package/src/i18n.test.ts +31 -0
- package/src/i18n.ts +13 -13
- package/src/mui/MuiThemeProvider.tsx +135 -135
- package/src/test/fakeCamera.ts +98 -0
- package/src/test/fakeDataApi.ts +90 -0
- package/src/test/setup.browser.ts +21 -0
- package/src/test/setup.ts +23 -23
- package/src/useTranslation/index.ts +5 -3
- package/src/useTranslation/useTranslation.test.ts +128 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts +0 -1
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +0 -103
- package/es/test/setup.d.ts +0 -6
- package/es/test/setup.js +0 -6
|
@@ -1,312 +1,303 @@
|
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
pondRef.current
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
+
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
return () => {
|
|
167
|
+
pondRef.current?.destroy();
|
|
168
|
+
pondRef.current = null;
|
|
169
|
+
};
|
|
170
|
+
}, []);
|
|
171
|
+
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
async function removeUploadedFile(source: string, load: () => void, error: (error: string) => void) {
|
|
174
|
+
let { dataHandler } = dataObject;
|
|
175
|
+
try {
|
|
176
|
+
let result = await dataHandler.destroy({
|
|
177
|
+
PrimKey: source,
|
|
178
|
+
} as Partial<T>);
|
|
179
|
+
|
|
180
|
+
if (result) {
|
|
181
|
+
onFileRemoved?.(source);
|
|
182
|
+
load();
|
|
183
|
+
} else {
|
|
184
|
+
error("Failed to delete file on server. Delete request returned false");
|
|
185
|
+
}
|
|
186
|
+
} catch (err: any) {
|
|
187
|
+
error(
|
|
188
|
+
err.responseText ??
|
|
189
|
+
err.statusText ??
|
|
190
|
+
err.message ??
|
|
191
|
+
"Failed to delete file on server but no error was returned.",
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let options: FilePondOptions = {
|
|
197
|
+
allowMultiple: Boolean(props.multiple),
|
|
198
|
+
allowImageResize: true,
|
|
199
|
+
imageResizeMode: "contain",
|
|
200
|
+
imageResizeTargetWidth: 2400,
|
|
201
|
+
imageResizeTargetHeight: 2400,
|
|
202
|
+
imageResizeUpscale: false,
|
|
203
|
+
...labels,
|
|
204
|
+
onaddfilestart: (file) => {
|
|
205
|
+
if (file.status !== 5 && file.status !== 6 && file.status !== 10) {
|
|
206
|
+
onUploadStart();
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
onprocessfile: (error, file) => {
|
|
210
|
+
onFileUploaded(error, file);
|
|
211
|
+
|
|
212
|
+
let refFiles = pondRef.current?.getFiles();
|
|
213
|
+
let found = refFiles?.find(
|
|
214
|
+
(file) => file.status !== 2 && file.status !== 5 && file.status !== 6 && file.status !== 10,
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
if (found === undefined) {
|
|
218
|
+
onFinishedUploads();
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
onprocessfiles: () => onFinishedUploads(),
|
|
222
|
+
onerror: (error) => onError(error.body),
|
|
223
|
+
beforeRemoveFile: () => {
|
|
224
|
+
if (confirm(getLocalizedString("Are you sure you want to remove this file?"))) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return false;
|
|
229
|
+
},
|
|
230
|
+
server: {
|
|
231
|
+
load: getFileUrl(dataObject, fieldName, primKey, "view"),
|
|
232
|
+
restore: getFileUrl(dataObject, fieldName, primKey, "view"),
|
|
233
|
+
|
|
234
|
+
revert: removeUploadedFile,
|
|
235
|
+
remove: removeUploadedFile,
|
|
236
|
+
|
|
237
|
+
process: {
|
|
238
|
+
url: getFileUrl(dataObject, fieldName),
|
|
239
|
+
ondata: (formData) => {
|
|
240
|
+
let masterChildCriteria = dataObject.getParameter("masterChildCriteria");
|
|
241
|
+
let allFields = { ...masterChildCriteria, ...fields };
|
|
242
|
+
|
|
243
|
+
for (let [field, value] of Object.entries(allFields)) {
|
|
244
|
+
if (value !== undefined) {
|
|
245
|
+
formData.append(field, String(value));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return formData;
|
|
250
|
+
},
|
|
251
|
+
onload: (response) => JSON.parse(response),
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
...filePondOptions,
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
if (pondRef.current) {
|
|
258
|
+
pondRef.current.setOptions(options);
|
|
259
|
+
} else {
|
|
260
|
+
pondRef.current = create(inputRefProp?.current ?? inputRef.current ?? undefined, options);
|
|
261
|
+
}
|
|
262
|
+
}, [
|
|
263
|
+
dataObject,
|
|
264
|
+
props.multiple,
|
|
265
|
+
fields,
|
|
266
|
+
fieldName,
|
|
267
|
+
primKey,
|
|
268
|
+
inputRefProp,
|
|
269
|
+
filePondOptions,
|
|
270
|
+
onError,
|
|
271
|
+
onFileUploaded,
|
|
272
|
+
onUploadStart,
|
|
273
|
+
onFinishedUploads,
|
|
274
|
+
onFileRemoved,
|
|
275
|
+
]);
|
|
276
|
+
|
|
277
|
+
useEffect(() => {
|
|
278
|
+
if (pondRef.current) {
|
|
279
|
+
files.forEach((file, index) => {
|
|
280
|
+
let options: { index: number } & Partial<FilePondInitialFile["options"]> = {
|
|
281
|
+
index,
|
|
282
|
+
type: "local",
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
pondRef.current?.addFile(file.PrimKey, options);
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return () => {
|
|
290
|
+
// The data has changed: clear the list without deleting the files on the server
|
|
291
|
+
// (`remove: false` keeps FilePond from calling `server.remove` for them).
|
|
292
|
+
pondRef.current?.removeFiles({ remove: false });
|
|
293
|
+
};
|
|
294
|
+
}, [files]);
|
|
295
|
+
|
|
296
|
+
return (
|
|
297
|
+
<div className="filepond--wrapper">
|
|
298
|
+
{attachmentPrimKeys && <input type="hidden" name="AttachmentPrimkeys" value={attachmentPrimKeys} />}
|
|
299
|
+
|
|
300
|
+
<input type="file" {...props} name="File" ref={inputRefProp ?? inputRef} />
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
}
|