@servicetitan/form 31.1.0 → 31.3.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/dist/color-picker/color-palette.js +8 -9
- package/dist/color-picker/color-palette.js.map +1 -1
- package/dist/color-picker/color-picker.js +46 -9
- package/dist/color-picker/color-picker.js.map +1 -1
- package/dist/color-picker/color-picker.module.css.d.ts +4 -0
- package/dist/color-picker/index.js +1 -0
- package/dist/color-picker/index.js.map +1 -1
- package/dist/date-range-picker/date-range-picker.js +205 -174
- package/dist/date-range-picker/date-range-picker.js.map +1 -1
- package/dist/date-range-picker/date-range-picker.module.css.d.ts +8 -0
- package/dist/date-range-picker/index.js +1 -0
- package/dist/date-range-picker/index.js.map +1 -1
- package/dist/demo/color-picker.js +39 -4
- package/dist/demo/color-picker.js.map +1 -1
- package/dist/demo/date-range-picker.js +18 -2
- package/dist/demo/date-range-picker.js.map +1 -1
- package/dist/demo/file-uploader.js +94 -12
- package/dist/demo/file-uploader.js.map +1 -1
- package/dist/demo/index.js +1 -0
- package/dist/demo/index.js.map +1 -1
- package/dist/demo/input-date-mask.js +18 -2
- package/dist/demo/input-date-mask.js.map +1 -1
- package/dist/demo/number-input.js +121 -3
- package/dist/demo/number-input.js.map +1 -1
- package/dist/demo/original-number-input.js +18 -2
- package/dist/demo/original-number-input.js.map +1 -1
- package/dist/demo/phone-number-input.js +5 -1
- package/dist/demo/phone-number-input.js.map +1 -1
- package/dist/file-uploader/config.js +10 -1
- package/dist/file-uploader/config.js.map +1 -1
- package/dist/file-uploader/file-uploader.js +189 -192
- package/dist/file-uploader/file-uploader.js.map +1 -1
- package/dist/file-uploader/index.js +3 -1
- package/dist/file-uploader/index.js.map +1 -1
- package/dist/file-uploader/uploader.js +57 -41
- package/dist/file-uploader/uploader.js.map +1 -1
- package/dist/form-state-error-banner/form-state-error-banner.js +15 -5
- package/dist/form-state-error-banner/form-state-error-banner.js.map +1 -1
- package/dist/form-state-error-banner/index.js +1 -0
- package/dist/form-state-error-banner/index.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/input-date-mask/index.js +1 -0
- package/dist/input-date-mask/index.js.map +1 -1
- package/dist/input-date-mask/input-date-mask.js +47 -28
- package/dist/input-date-mask/input-date-mask.js.map +1 -1
- package/dist/input-date-mask/input-date-mask.module.css.d.ts +4 -0
- package/dist/label/index.js +1 -0
- package/dist/label/index.js.map +1 -1
- package/dist/label/label.js +29 -1
- package/dist/label/label.js.map +1 -1
- package/dist/label/label.module.css.d.ts +7 -0
- package/dist/masked-input.js +17 -4
- package/dist/masked-input.js.map +1 -1
- package/dist/number-input/common-interfaces.js +2 -1
- package/dist/number-input/common-interfaces.js.map +1 -1
- package/dist/number-input/get-formatted-string.js +2 -3
- package/dist/number-input/get-formatted-string.js.map +1 -1
- package/dist/number-input/index.js +1 -0
- package/dist/number-input/index.js.map +1 -1
- package/dist/number-input/number-input.js +53 -42
- package/dist/number-input/number-input.js.map +1 -1
- package/dist/number-input/process-value.js +10 -16
- package/dist/number-input/process-value.js.map +1 -1
- package/dist/original-number-input/index.js +1 -0
- package/dist/original-number-input/index.js.map +1 -1
- package/dist/original-number-input/ordinal-number-input.js +54 -59
- package/dist/original-number-input/ordinal-number-input.js.map +1 -1
- package/dist/phone-number-input/index.js +1 -0
- package/dist/phone-number-input/index.js.map +1 -1
- package/dist/phone-number-input/phone-number-input.js +13 -1
- package/dist/phone-number-input/phone-number-input.js.map +1 -1
- package/package.json +13 -13
- package/dist/form.stories.js +0 -20
- package/dist/form.stories.js.map +0 -1
- package/dist/number-input/__tests__/get-formatted-string.test.js +0 -41
- package/dist/number-input/__tests__/get-formatted-string.test.js.map +0 -1
- package/dist/number-input/__tests__/process-value.test.js +0 -283
- package/dist/number-input/__tests__/process-value.test.js.map +0 -1
- package/dist/original-number-input/__tests__/ordinal-number-input.test.js +0 -51
- package/dist/original-number-input/__tests__/ordinal-number-input.test.js.map +0 -1
@@ -1,5 +1,9 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { observer } from 'mobx-react';
|
3
3
|
import { PhoneNumberInput } from '..';
|
4
|
-
export const PhoneNumberInputExample = observer(()
|
4
|
+
export const PhoneNumberInputExample = observer(()=>/*#__PURE__*/ _jsx(PhoneNumberInput, {
|
5
|
+
placeholder: "(123) 456-7890",
|
6
|
+
label: "Phone"
|
7
|
+
}));
|
8
|
+
|
5
9
|
//# sourceMappingURL=phone-number-input.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/demo/phone-number-input.tsx"],"sourcesContent":["import { FC } from 'react';\n\nimport { observer } from 'mobx-react';\n\nimport { PhoneNumberInput } from '..';\n\nexport const PhoneNumberInputExample: FC = observer(() => (\n <PhoneNumberInput placeholder=\"(123) 456-7890\" label=\"Phone\" />\n));\n"],"names":["observer","PhoneNumberInput","PhoneNumberInputExample","placeholder","label"],"mappings":";AAEA,SAASA,QAAQ,QAAQ,aAAa;AAEtC,SAASC,gBAAgB,QAAQ,KAAK;AAEtC,OAAO,MAAMC,0BAA8BF,SAAS,kBAChD,KAACC;QAAiBE,aAAY;QAAiBC,OAAM;QACtD"}
|
@@ -1,5 +1,14 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { Provider, symbolToken } from '@servicetitan/react-ioc';
|
3
3
|
export const FILE_UPLOADER_CONFIGURATION_TOKEN = symbolToken('FILE_UPLOADER_CONFIGURATION_TOKEN');
|
4
|
-
export const FileUploaderConfigurationProvider = ({ value, children
|
4
|
+
export const FileUploaderConfigurationProvider = ({ value, children })=>/*#__PURE__*/ _jsx(Provider, {
|
5
|
+
singletons: [
|
6
|
+
{
|
7
|
+
provide: FILE_UPLOADER_CONFIGURATION_TOKEN,
|
8
|
+
useValue: value
|
9
|
+
}
|
10
|
+
],
|
11
|
+
children: children
|
12
|
+
});
|
13
|
+
|
5
14
|
//# sourceMappingURL=config.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/file-uploader/config.tsx"],"sourcesContent":["import { FC, PropsWithChildren } from 'react';\n\nimport { Provider, symbolToken } from '@servicetitan/react-ioc';\n\nexport interface FileUploaderConfig {\n target?: string;\n downloadPath?: string;\n chunkSize?: number;\n testChunks?: boolean;\n forceChunkSize?: boolean;\n simultaneousUploads?: number;\n headers?: Record<string, string>;\n permanentErrors?: number[];\n fileType?: string[];\n errorParser?(error?: string): string;\n}\n\nexport const FILE_UPLOADER_CONFIGURATION_TOKEN = symbolToken<FileUploaderConfig>(\n 'FILE_UPLOADER_CONFIGURATION_TOKEN'\n);\n\ninterface FileUploaderConfigurationProviderProps extends PropsWithChildren<{}> {\n value: FileUploaderConfig;\n}\n\nexport const FileUploaderConfigurationProvider: FC<FileUploaderConfigurationProviderProps> = ({\n value,\n children,\n}) => (\n <Provider singletons={[{ provide: FILE_UPLOADER_CONFIGURATION_TOKEN, useValue: value }]}>\n {children}\n </Provider>\n);\n"],"names":["Provider","symbolToken","FILE_UPLOADER_CONFIGURATION_TOKEN","FileUploaderConfigurationProvider","value","children","singletons","provide","useValue"],"mappings":";AAEA,SAASA,QAAQ,EAAEC,WAAW,QAAQ,0BAA0B;AAehE,OAAO,MAAMC,oCAAoCD,YAC7C,qCACF;AAMF,OAAO,MAAME,oCAAgF,CAAC,EAC1FC,KAAK,EACLC,QAAQ,EACX,iBACG,KAACL;QAASM,YAAY;YAAC;gBAAEC,SAASL;gBAAmCM,UAAUJ;YAAM;SAAE;kBAClFC;OAEP"}
|
@@ -1,173 +1,70 @@
|
|
1
|
-
|
1
|
+
function _define_property(obj, key, value) {
|
2
|
+
if (key in obj) {
|
3
|
+
Object.defineProperty(obj, key, {
|
4
|
+
value: value,
|
5
|
+
enumerable: true,
|
6
|
+
configurable: true,
|
7
|
+
writable: true
|
8
|
+
});
|
9
|
+
} else {
|
10
|
+
obj[key] = value;
|
11
|
+
}
|
12
|
+
return obj;
|
13
|
+
}
|
14
|
+
function _ts_decorate(decorators, target, key, desc) {
|
2
15
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
16
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
-
else for
|
17
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
18
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
-
}
|
7
|
-
|
19
|
+
}
|
20
|
+
function _ts_metadata(k, v) {
|
8
21
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
-
}
|
10
|
-
import {
|
22
|
+
}
|
23
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
11
24
|
import { Component, Fragment } from 'react';
|
12
25
|
import { injectDependency, optional } from '@servicetitan/react-ioc';
|
13
26
|
import { observer } from 'mobx-react';
|
14
27
|
import { observable, action, makeObservable } from 'mobx';
|
15
28
|
import { FilePicker, Banner } from '@servicetitan/design-system';
|
16
29
|
import { Confirm } from '@servicetitan/confirm';
|
17
|
-
import { FILE_UPLOADER_CONFIGURATION_TOKEN } from './config';
|
30
|
+
import { FileUploaderConfig, FILE_UPLOADER_CONFIGURATION_TOKEN } from './config';
|
18
31
|
import { Uploader } from './uploader';
|
19
32
|
import { v4 as uuid } from 'uuid';
|
20
33
|
function immutableSplice(arr, start, deleteCount, ...items) {
|
21
|
-
return [
|
34
|
+
return [
|
35
|
+
...arr.slice(0, start),
|
36
|
+
...items,
|
37
|
+
...arr.slice(start + deleteCount)
|
38
|
+
];
|
22
39
|
}
|
23
|
-
const UploadErrors = ({ errors, className, onClose, multiple })
|
24
|
-
const title = multiple
|
25
|
-
|
26
|
-
:
|
27
|
-
|
40
|
+
const UploadErrors = ({ errors, className, onClose, multiple })=>{
|
41
|
+
const title = multiple ? 'One or more files could not be uploaded:' : 'Your file could not be uploaded';
|
42
|
+
return /*#__PURE__*/ _jsx(Banner, {
|
43
|
+
icon: true,
|
44
|
+
status: "critical",
|
45
|
+
title: title,
|
46
|
+
className: className,
|
47
|
+
onClose: onClose,
|
48
|
+
children: /*#__PURE__*/ _jsx("ul", {
|
49
|
+
className: "p-x-0-i",
|
50
|
+
children: errors.map(({ id, file, message })=>/*#__PURE__*/ _jsxs("li", {
|
51
|
+
style: !multiple ? {
|
52
|
+
listStyle: 'none'
|
53
|
+
} : {},
|
54
|
+
children: [
|
55
|
+
multiple && file.name,
|
56
|
+
message && (multiple ? ` (${message})` : message)
|
57
|
+
]
|
58
|
+
}, id))
|
59
|
+
})
|
60
|
+
});
|
28
61
|
};
|
29
|
-
|
30
|
-
constructor(props) {
|
31
|
-
super(props);
|
32
|
-
Object.defineProperty(this, "errors", {
|
33
|
-
enumerable: true,
|
34
|
-
configurable: true,
|
35
|
-
writable: true,
|
36
|
-
value: []
|
37
|
-
});
|
38
|
-
Object.defineProperty(this, "uploader", {
|
39
|
-
enumerable: true,
|
40
|
-
configurable: true,
|
41
|
-
writable: true,
|
42
|
-
value: void 0
|
43
|
-
});
|
44
|
-
Object.defineProperty(this, "handleUploadProgress", {
|
45
|
-
enumerable: true,
|
46
|
-
configurable: true,
|
47
|
-
writable: true,
|
48
|
-
value: (file, progress) => {
|
49
|
-
if (!this.props.onChange) {
|
50
|
-
return;
|
51
|
-
}
|
52
|
-
const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);
|
53
|
-
if (index !== -1) {
|
54
|
-
this.props.onChange(immutableSplice(this.props.value, index, 1, {
|
55
|
-
...this.props.value[index],
|
56
|
-
uploadProgress: progress,
|
57
|
-
}));
|
58
|
-
}
|
59
|
-
else {
|
60
|
-
this.uploader.cancel(file);
|
61
|
-
}
|
62
|
-
}
|
63
|
-
});
|
64
|
-
Object.defineProperty(this, "handleUploadSuccess", {
|
65
|
-
enumerable: true,
|
66
|
-
configurable: true,
|
67
|
-
writable: true,
|
68
|
-
value: (file, message) => {
|
69
|
-
if (!this.props.onChange) {
|
70
|
-
return;
|
71
|
-
}
|
72
|
-
const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);
|
73
|
-
if (index !== -1) {
|
74
|
-
this.props.onChange(immutableSplice(this.props.value, index, 1, {
|
75
|
-
...this.props.value[index],
|
76
|
-
...(message
|
77
|
-
? { file: message, displayName: file.name, downloadLink: message }
|
78
|
-
: { file: file.name }),
|
79
|
-
uploadProgress: undefined,
|
80
|
-
}));
|
81
|
-
}
|
82
|
-
}
|
83
|
-
});
|
84
|
-
Object.defineProperty(this, "handleUploadError", {
|
85
|
-
enumerable: true,
|
86
|
-
configurable: true,
|
87
|
-
writable: true,
|
88
|
-
value: (file, message) => {
|
89
|
-
if (!this.props.onChange) {
|
90
|
-
return;
|
91
|
-
}
|
92
|
-
this.addError(file, message);
|
93
|
-
this.props.onChange(this.props.value.filter(fileDescriptor => fileDescriptor.file !== file));
|
94
|
-
}
|
95
|
-
});
|
96
|
-
Object.defineProperty(this, "handleDownload", {
|
97
|
-
enumerable: true,
|
98
|
-
configurable: true,
|
99
|
-
writable: true,
|
100
|
-
value: (file) => {
|
101
|
-
var _a, _b, _c, _d;
|
102
|
-
if (!file.downloadLink) {
|
103
|
-
return;
|
104
|
-
}
|
105
|
-
const path = (_d = (_b = (_a = this.props.config) === null || _a === void 0 ? void 0 : _a.downloadPath) !== null && _b !== void 0 ? _b : (_c = this.config) === null || _c === void 0 ? void 0 : _c.downloadPath) !== null && _d !== void 0 ? _d : `/app/api/fileuploader/folders/${this.props.folderName}/files/`;
|
106
|
-
window.open(path + file.downloadLink);
|
107
|
-
}
|
108
|
-
});
|
109
|
-
Object.defineProperty(this, "handleSelected", {
|
110
|
-
enumerable: true,
|
111
|
-
configurable: true,
|
112
|
-
writable: true,
|
113
|
-
value: (files) => {
|
114
|
-
if (!this.props.onChange) {
|
115
|
-
return;
|
116
|
-
}
|
117
|
-
this.props.onChange([
|
118
|
-
...this.props.value,
|
119
|
-
...Array.from(files).map(file => ({
|
120
|
-
file,
|
121
|
-
uploadProgress: 0,
|
122
|
-
})),
|
123
|
-
]);
|
124
|
-
this.uploader.upload(files);
|
125
|
-
}
|
126
|
-
});
|
127
|
-
Object.defineProperty(this, "handleReplace", {
|
128
|
-
enumerable: true,
|
129
|
-
configurable: true,
|
130
|
-
writable: true,
|
131
|
-
value: ({ file: { file }, newFile }) => {
|
132
|
-
if (!this.props.onChange) {
|
133
|
-
return;
|
134
|
-
}
|
135
|
-
const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);
|
136
|
-
if (index !== -1) {
|
137
|
-
this.uploader.upload(newFile);
|
138
|
-
this.props.onChange(immutableSplice(this.props.value, index, 1, {
|
139
|
-
file: newFile,
|
140
|
-
uploadProgress: 0,
|
141
|
-
}));
|
142
|
-
}
|
143
|
-
}
|
144
|
-
});
|
145
|
-
Object.defineProperty(this, "handleDelete", {
|
146
|
-
enumerable: true,
|
147
|
-
configurable: true,
|
148
|
-
writable: true,
|
149
|
-
value: ({ file }) => {
|
150
|
-
if (!this.props.onChange) {
|
151
|
-
return;
|
152
|
-
}
|
153
|
-
this.props.onChange(this.props.value.filter(fileDescriptor => fileDescriptor.file !== file));
|
154
|
-
}
|
155
|
-
});
|
156
|
-
Object.defineProperty(this, "handleErrorsClose", {
|
157
|
-
enumerable: true,
|
158
|
-
configurable: true,
|
159
|
-
writable: true,
|
160
|
-
value: () => {
|
161
|
-
this.clearErrors();
|
162
|
-
}
|
163
|
-
});
|
164
|
-
makeObservable(this);
|
165
|
-
}
|
62
|
+
export class FileUploader extends Component {
|
166
63
|
addError(file, message) {
|
167
64
|
this.errors.push({
|
168
65
|
file,
|
169
66
|
message,
|
170
|
-
id: uuid()
|
67
|
+
id: uuid()
|
171
68
|
});
|
172
69
|
}
|
173
70
|
clearErrors() {
|
@@ -176,11 +73,11 @@ let FileUploader = class FileUploader extends Component {
|
|
176
73
|
componentDidMount() {
|
177
74
|
this.uploader = new Uploader({
|
178
75
|
...this.config,
|
179
|
-
...this.props.config
|
76
|
+
...this.props.config
|
180
77
|
}, {
|
181
78
|
progress: this.handleUploadProgress,
|
182
79
|
success: this.handleUploadSuccess,
|
183
|
-
error: this.handleUploadError
|
80
|
+
error: this.handleUploadError
|
184
81
|
}, this.props.folderName);
|
185
82
|
}
|
186
83
|
componentWillUnmount() {
|
@@ -191,60 +88,160 @@ let FileUploader = class FileUploader extends Component {
|
|
191
88
|
if (!onChange && !value.length) {
|
192
89
|
return null;
|
193
90
|
}
|
194
|
-
const readonlyProps = onChange
|
195
|
-
|
196
|
-
:
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
91
|
+
const readonlyProps = onChange ? {} : {
|
92
|
+
onReplace: undefined,
|
93
|
+
onDelete: undefined,
|
94
|
+
limitReached: true
|
95
|
+
};
|
96
|
+
return /*#__PURE__*/ _jsxs(Fragment, {
|
97
|
+
children: [
|
98
|
+
!!this.errors.length && /*#__PURE__*/ _jsx(UploadErrors, {
|
99
|
+
errors: this.errors,
|
100
|
+
onClose: this.handleErrorsClose,
|
101
|
+
className: "m-b-2",
|
102
|
+
multiple: multiple
|
103
|
+
}),
|
104
|
+
/*#__PURE__*/ _jsx(Confirm, {
|
105
|
+
onConfirm: this.handleDelete,
|
106
|
+
title: "Are you sure you want to delete this file?",
|
107
|
+
children: (onDelete)=>/*#__PURE__*/ _jsx(FilePicker, {
|
108
|
+
value: value.length ? value : undefined,
|
109
|
+
onReplace: !hideReplace ? this.handleReplace : undefined,
|
110
|
+
onSelected: this.handleSelected,
|
111
|
+
onDelete: onDelete,
|
112
|
+
onDownload: !hideDownload ? this.handleDownload : undefined,
|
113
|
+
limitReached: limitReached,
|
114
|
+
multiple: multiple,
|
115
|
+
...rest,
|
116
|
+
...readonlyProps
|
117
|
+
})
|
118
|
+
})
|
119
|
+
]
|
120
|
+
});
|
202
121
|
}
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
122
|
+
constructor(props){
|
123
|
+
super(props), _define_property(this, "errors", []), _define_property(this, "uploader", void 0), _define_property(this, "handleUploadProgress", (file, progress)=>{
|
124
|
+
if (!this.props.onChange) {
|
125
|
+
return;
|
126
|
+
}
|
127
|
+
const index = this.props.value.findIndex((fileDescriptor)=>fileDescriptor.file === file);
|
128
|
+
if (index !== -1) {
|
129
|
+
this.props.onChange(immutableSplice(this.props.value, index, 1, {
|
130
|
+
...this.props.value[index],
|
131
|
+
uploadProgress: progress
|
132
|
+
}));
|
133
|
+
} else {
|
134
|
+
this.uploader.cancel(file);
|
135
|
+
}
|
136
|
+
}), _define_property(this, "handleUploadSuccess", (file, message)=>{
|
137
|
+
if (!this.props.onChange) {
|
138
|
+
return;
|
139
|
+
}
|
140
|
+
const index = this.props.value.findIndex((fileDescriptor)=>fileDescriptor.file === file);
|
141
|
+
if (index !== -1) {
|
142
|
+
this.props.onChange(immutableSplice(this.props.value, index, 1, {
|
143
|
+
...this.props.value[index],
|
144
|
+
...message ? {
|
145
|
+
file: message,
|
146
|
+
displayName: file.name,
|
147
|
+
downloadLink: message
|
148
|
+
} : {
|
149
|
+
file: file.name
|
150
|
+
},
|
151
|
+
uploadProgress: undefined
|
152
|
+
}));
|
153
|
+
}
|
154
|
+
}), _define_property(this, "handleUploadError", (file, message)=>{
|
155
|
+
if (!this.props.onChange) {
|
156
|
+
return;
|
157
|
+
}
|
158
|
+
this.addError(file, message);
|
159
|
+
this.props.onChange(this.props.value.filter((fileDescriptor)=>fileDescriptor.file !== file));
|
160
|
+
}), _define_property(this, "handleDownload", (file)=>{
|
161
|
+
var _this_props_config, _this_config;
|
162
|
+
if (!file.downloadLink) {
|
163
|
+
return;
|
164
|
+
}
|
165
|
+
var _this_props_config_downloadPath, _ref;
|
166
|
+
const path = (_ref = (_this_props_config_downloadPath = (_this_props_config = this.props.config) === null || _this_props_config === void 0 ? void 0 : _this_props_config.downloadPath) !== null && _this_props_config_downloadPath !== void 0 ? _this_props_config_downloadPath : (_this_config = this.config) === null || _this_config === void 0 ? void 0 : _this_config.downloadPath) !== null && _ref !== void 0 ? _ref : `/app/api/fileuploader/folders/${this.props.folderName}/files/`;
|
167
|
+
window.open(path + file.downloadLink);
|
168
|
+
}), _define_property(this, "handleSelected", (files)=>{
|
169
|
+
if (!this.props.onChange) {
|
170
|
+
return;
|
171
|
+
}
|
172
|
+
this.props.onChange([
|
173
|
+
...this.props.value,
|
174
|
+
...Array.from(files).map((file)=>({
|
175
|
+
file,
|
176
|
+
uploadProgress: 0
|
177
|
+
}))
|
178
|
+
]);
|
179
|
+
this.uploader.upload(files);
|
180
|
+
}), _define_property(this, "handleReplace", ({ file: { file }, newFile })=>{
|
181
|
+
if (!this.props.onChange) {
|
182
|
+
return;
|
183
|
+
}
|
184
|
+
const index = this.props.value.findIndex((fileDescriptor)=>fileDescriptor.file === file);
|
185
|
+
if (index !== -1) {
|
186
|
+
this.uploader.upload(newFile);
|
187
|
+
this.props.onChange(immutableSplice(this.props.value, index, 1, {
|
188
|
+
file: newFile,
|
189
|
+
uploadProgress: 0
|
190
|
+
}));
|
191
|
+
}
|
192
|
+
}), _define_property(this, "handleDelete", ({ file })=>{
|
193
|
+
if (!this.props.onChange) {
|
194
|
+
return;
|
195
|
+
}
|
196
|
+
this.props.onChange(this.props.value.filter((fileDescriptor)=>fileDescriptor.file !== file));
|
197
|
+
}), _define_property(this, "handleErrorsClose", ()=>{
|
198
|
+
this.clearErrors();
|
199
|
+
});
|
200
|
+
makeObservable(this);
|
210
201
|
}
|
202
|
+
}
|
203
|
+
_define_property(FileUploader, "defaultProps", {
|
204
|
+
folderName: 'temp'
|
211
205
|
});
|
212
|
-
|
206
|
+
_ts_decorate([
|
213
207
|
injectDependency(FILE_UPLOADER_CONFIGURATION_TOKEN),
|
214
208
|
optional(),
|
215
|
-
|
209
|
+
_ts_metadata("design:type", typeof FileUploaderConfig === "undefined" ? Object : FileUploaderConfig)
|
216
210
|
], FileUploader.prototype, "config", void 0);
|
217
|
-
|
211
|
+
_ts_decorate([
|
218
212
|
observable,
|
219
|
-
|
213
|
+
_ts_metadata("design:type", Array)
|
220
214
|
], FileUploader.prototype, "errors", void 0);
|
221
|
-
|
215
|
+
_ts_decorate([
|
222
216
|
action,
|
223
|
-
|
224
|
-
|
225
|
-
|
217
|
+
_ts_metadata("design:type", Function),
|
218
|
+
_ts_metadata("design:paramtypes", [
|
219
|
+
typeof File === "undefined" ? Object : File,
|
220
|
+
String
|
221
|
+
]),
|
222
|
+
_ts_metadata("design:returntype", void 0)
|
226
223
|
], FileUploader.prototype, "addError", null);
|
227
|
-
|
224
|
+
_ts_decorate([
|
228
225
|
action,
|
229
|
-
|
230
|
-
|
231
|
-
|
226
|
+
_ts_metadata("design:type", Function),
|
227
|
+
_ts_metadata("design:paramtypes", []),
|
228
|
+
_ts_metadata("design:returntype", void 0)
|
232
229
|
], FileUploader.prototype, "clearErrors", null);
|
233
|
-
|
234
|
-
action
|
235
|
-
__metadata("design:type", Object)
|
230
|
+
_ts_decorate([
|
231
|
+
action
|
236
232
|
], FileUploader.prototype, "handleUploadProgress", void 0);
|
237
|
-
|
238
|
-
action
|
239
|
-
__metadata("design:type", Object)
|
233
|
+
_ts_decorate([
|
234
|
+
action
|
240
235
|
], FileUploader.prototype, "handleUploadSuccess", void 0);
|
241
|
-
|
242
|
-
action
|
243
|
-
__metadata("design:type", Object)
|
236
|
+
_ts_decorate([
|
237
|
+
action
|
244
238
|
], FileUploader.prototype, "handleUploadError", void 0);
|
245
|
-
FileUploader =
|
239
|
+
FileUploader = _ts_decorate([
|
246
240
|
observer,
|
247
|
-
|
241
|
+
_ts_metadata("design:type", Function),
|
242
|
+
_ts_metadata("design:paramtypes", [
|
243
|
+
typeof FileUploaderProps === "undefined" ? Object : FileUploaderProps
|
244
|
+
])
|
248
245
|
], FileUploader);
|
249
|
-
|
246
|
+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C,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,EAC3D,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,QAAQ,KACd,IAAI,KACJ,aAAa,GACnB,CACL,GACK,IACH,CACd,CAAC;IACN,CAAC;;AAzNM;;;;WAAe;QAClB,UAAU,EAAE,MAAM;KACrB;EAFkB,CAEjB;AAIM;IAFP,gBAAgB,CAAC,iCAAiC,CAAC;IACnD,QAAQ,EAAE;;4CACyB;AAExB;IAAX,UAAU;;4CAA4B;AAUvC;IADC,MAAM;;qCACQ,IAAI;;4CAMlB;AAGD;IADC,MAAM;;;;+CAGN;AAGD;IADC,MAAM;;0DAiBL;AAGF;IADC,MAAM;;yDAkBL;AAGF;IADC,MAAM;;uDAWL;AAlFO,YAAY;IADxB,QAAQ;;GACI,YAAY,CA2NxB"}
|
1
|
+
{"version":3,"sources":["../../src/file-uploader/file-uploader.tsx"],"sourcesContent":["import { Component, Fragment, FC } from 'react';\n\nimport { injectDependency, optional } from '@servicetitan/react-ioc';\n\nimport { observer } from 'mobx-react';\nimport { observable, action, makeObservable } from 'mobx';\n\nimport { FilePicker, FileDescriptor, Banner, FilePickerProps } from '@servicetitan/design-system';\nimport { Confirm } from '@servicetitan/confirm';\n\nimport { FileUploaderConfig, FILE_UPLOADER_CONFIGURATION_TOKEN } from './config';\nimport { Uploader } from './uploader';\n\nimport { v4 as uuid } from 'uuid';\n\nfunction immutableSplice<T>(arr: T[], start: number, deleteCount: number, ...items: T[]) {\n return [...arr.slice(0, start), ...items, ...arr.slice(start + deleteCount)];\n}\n\ninterface UploadError {\n id: string;\n file: File;\n message?: string;\n}\n\ninterface UploadErrorsProps {\n errors: UploadError[];\n multiple?: boolean;\n className?: string;\n onClose(): void;\n}\n\nconst UploadErrors: FC<UploadErrorsProps> = ({ errors, className, onClose, multiple }) => {\n const title = multiple\n ? 'One or more files could not be uploaded:'\n : 'Your file could not be uploaded';\n\n return (\n <Banner icon status=\"critical\" title={title} className={className} onClose={onClose}>\n <ul className=\"p-x-0-i\">\n {errors.map(({ id, file, message }) => (\n <li key={id} style={!multiple ? { listStyle: 'none' } : {}}>\n {multiple && file.name}\n {message && (multiple ? ` (${message})` : message)}\n </li>\n ))}\n </ul>\n </Banner>\n );\n};\n\ntype ExcludedFilePickerProps = 'onDelete' | 'onDownload' | 'onReplace' | 'onSelected' | 'value';\n\ninterface FileUploaderProps extends Omit<FilePickerProps, ExcludedFilePickerProps> {\n config?: FileUploaderConfig;\n value: FileDescriptor[];\n folderName?: string;\n hideReplace?: boolean;\n hideDownload?: boolean;\n onChange?(value: FileDescriptor[]): void;\n}\n\n@observer\nexport class FileUploader extends Component<FileUploaderProps> {\n static defaultProps = {\n folderName: 'temp',\n };\n\n @injectDependency(FILE_UPLOADER_CONFIGURATION_TOKEN)\n @optional()\n declare config?: FileUploaderConfig;\n\n @observable errors: UploadError[] = [];\n\n uploader!: Uploader;\n\n constructor(props: FileUploaderProps) {\n super(props);\n makeObservable(this);\n }\n\n @action\n addError(file: File, message?: string) {\n this.errors.push({\n file,\n message,\n id: uuid(),\n });\n }\n\n @action\n clearErrors() {\n this.errors = [];\n }\n\n @action\n handleUploadProgress = (file: File, progress: number) => {\n if (!this.props.onChange) {\n return;\n }\n\n const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);\n if (index !== -1) {\n this.props.onChange(\n immutableSplice(this.props.value, index, 1, {\n ...this.props.value[index],\n uploadProgress: progress,\n })\n );\n } else {\n this.uploader.cancel(file);\n }\n };\n\n @action\n handleUploadSuccess = (file: File, message?: string) => {\n if (!this.props.onChange) {\n return;\n }\n\n const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);\n if (index !== -1) {\n this.props.onChange(\n immutableSplice(this.props.value, index, 1, {\n ...this.props.value[index],\n ...(message\n ? { file: message, displayName: file.name, downloadLink: message }\n : { file: file.name }),\n uploadProgress: undefined,\n })\n );\n }\n };\n\n @action\n handleUploadError = (file: File, message?: string) => {\n if (!this.props.onChange) {\n return;\n }\n\n this.addError(file, message);\n\n this.props.onChange(\n this.props.value.filter(fileDescriptor => fileDescriptor.file !== file)\n );\n };\n\n componentDidMount() {\n this.uploader = new Uploader(\n {\n ...this.config,\n ...this.props.config,\n },\n {\n progress: this.handleUploadProgress,\n success: this.handleUploadSuccess,\n error: this.handleUploadError,\n },\n this.props.folderName\n );\n }\n\n componentWillUnmount() {\n this.uploader.cancel();\n }\n\n handleDownload = (file: FileDescriptor) => {\n if (!file.downloadLink) {\n return;\n }\n\n const path =\n this.props.config?.downloadPath ??\n this.config?.downloadPath ??\n `/app/api/fileuploader/folders/${this.props.folderName}/files/`;\n\n window.open(path + file.downloadLink);\n };\n\n handleSelected = (files: FileList) => {\n if (!this.props.onChange) {\n return;\n }\n\n this.props.onChange([\n ...this.props.value,\n ...Array.from(files).map(file => ({\n file,\n uploadProgress: 0,\n })),\n ]);\n this.uploader.upload(files);\n };\n\n handleReplace = ({ file: { file }, newFile }: { file: FileDescriptor; newFile: File }) => {\n if (!this.props.onChange) {\n return;\n }\n\n const index = this.props.value.findIndex(fileDescriptor => fileDescriptor.file === file);\n if (index !== -1) {\n this.uploader.upload(newFile);\n\n this.props.onChange(\n immutableSplice(this.props.value, index, 1, {\n file: newFile,\n uploadProgress: 0,\n })\n );\n }\n };\n\n handleDelete = ({ file }: FileDescriptor) => {\n if (!this.props.onChange) {\n return;\n }\n\n this.props.onChange(\n this.props.value.filter(fileDescriptor => fileDescriptor.file !== file)\n );\n };\n\n handleErrorsClose = () => {\n this.clearErrors();\n };\n\n render() {\n const {\n value,\n onChange,\n hideReplace,\n hideDownload,\n limitReached,\n multiple,\n config,\n folderName,\n ...rest\n } = this.props;\n\n if (!onChange && !value.length) {\n return null;\n }\n\n const readonlyProps = onChange\n ? {}\n : {\n onReplace: undefined,\n onDelete: undefined,\n limitReached: true,\n };\n\n return (\n <Fragment>\n {!!this.errors.length && (\n <UploadErrors\n errors={this.errors}\n onClose={this.handleErrorsClose}\n className=\"m-b-2\"\n multiple={multiple}\n />\n )}\n <Confirm\n onConfirm={this.handleDelete}\n title=\"Are you sure you want to delete this file?\"\n >\n {onDelete => (\n <FilePicker\n value={value.length ? value : undefined}\n onReplace={!hideReplace ? this.handleReplace : undefined}\n onSelected={this.handleSelected}\n onDelete={onDelete}\n onDownload={!hideDownload ? this.handleDownload : undefined}\n limitReached={limitReached}\n multiple={multiple}\n {...rest}\n {...readonlyProps}\n />\n )}\n </Confirm>\n </Fragment>\n );\n }\n}\n"],"names":["Component","Fragment","injectDependency","optional","observer","observable","action","makeObservable","FilePicker","Banner","Confirm","FileUploaderConfig","FILE_UPLOADER_CONFIGURATION_TOKEN","Uploader","v4","uuid","immutableSplice","arr","start","deleteCount","items","slice","UploadErrors","errors","className","onClose","multiple","title","icon","status","ul","map","id","file","message","li","style","listStyle","name","FileUploader","addError","push","clearErrors","componentDidMount","uploader","config","props","progress","handleUploadProgress","success","handleUploadSuccess","error","handleUploadError","folderName","componentWillUnmount","cancel","render","value","onChange","hideReplace","hideDownload","limitReached","rest","length","readonlyProps","onReplace","undefined","onDelete","handleErrorsClose","onConfirm","handleDelete","handleReplace","onSelected","handleSelected","onDownload","handleDownload","constructor","index","findIndex","fileDescriptor","uploadProgress","displayName","downloadLink","filter","path","downloadPath","window","open","files","Array","from","upload","newFile","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAY,QAAQ;AAEhD,SAASC,gBAAgB,EAAEC,QAAQ,QAAQ,0BAA0B;AAErE,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,UAAU,EAAEC,MAAM,EAAEC,cAAc,QAAQ,OAAO;AAE1D,SAASC,UAAU,EAAkBC,MAAM,QAAyB,8BAA8B;AAClG,SAASC,OAAO,QAAQ,wBAAwB;AAEhD,SAASC,kBAAkB,EAAEC,iCAAiC,QAAQ,WAAW;AACjF,SAASC,QAAQ,QAAQ,aAAa;AAEtC,SAASC,MAAMC,IAAI,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2D;oBACNZ,gBAAgB;gBACpB;YAER;QACJ,IAEAV,uBAAAA,gBAAe,CAAC,EAAErC,IAAI,EAAkB;YACpC,IAAI,CAAC,IAAI,CAACa,KAAK,CAACY,QAAQ,EAAE;gBACtB;YACJ;YAEA,IAAI,CAACZ,KAAK,CAACY,QAAQ,CACf,IAAI,CAACZ,KAAK,CAACW,KAAK,CAAC0B,MAAM,CAACJ,CAAAA,iBAAkBA,eAAe9C,IAAI,KAAKA;QAE1E,IAEAmC,uBAAAA,qBAAoB;YAChB,IAAI,CAAC1B,WAAW;QACpB;QAlJInC,eAAe,IAAI;IACvB;AA2MJ;AA1NI,iBADSgC,cACFsD,gBAAe;IAClBxC,YAAY;AAChB"}
|
@@ -1,3 +1,5 @@
|
|
1
1
|
export { FileUploader } from './file-uploader';
|
2
|
-
export { FileUploaderConfigurationProvider } from './config';
|
2
|
+
export { FileUploaderConfig, FileUploaderConfigurationProvider } from './config';
|
3
|
+
export { FileDescriptor } from '@servicetitan/design-system';
|
4
|
+
|
3
5
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/file-uploader/index.ts"],"sourcesContent":["export { FileUploader } from './file-uploader';\nexport { FileUploaderConfig, FileUploaderConfigurationProvider } from './config';\nexport { FileDescriptor } from '@servicetitan/design-system';\n"],"names":["FileUploader","FileUploaderConfig","FileUploaderConfigurationProvider","FileDescriptor"],"mappings":"AAAA,SAASA,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,kBAAkB,EAAEC,iCAAiC,QAAQ,WAAW;AACjF,SAASC,cAAc,QAAQ,8BAA8B"}
|