@raketa-builder/file-input 0.3.0 → 0.5.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.
@@ -0,0 +1,11 @@
1
+
2
+ > @raketa-builder/file-input@0.5.0 build
3
+ > tsup src/index.js --format cjs --loader ".js=jsx"
4
+
5
+ CLI Building entry: src/index.js
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v6.5.0
8
+ CLI Target: es6
9
+ CJS Build start
10
+ CJS dist/index.js 67.83 KB
11
+ CJS ⚡️ Build success in 150ms
@@ -0,0 +1,21 @@
1
+
2
+ > @raketa-builder/file-input@0.4.0 format
3
+ > prettier --write .
4
+
5
+ biome.json 573ms (unchanged)
6
+ dist/index.js 5084ms (unchanged)
7
+ package.json 43ms (unchanged)
8
+ src/FileManager.js 258ms (unchanged)
9
+ src/FilePicker/Dialog.js 147ms (unchanged)
10
+ src/FilePicker/FileCategory.js 85ms (unchanged)
11
+ src/FilePicker/FileInput.js 20ms (unchanged)
12
+ src/FilePicker/FileList.js 60ms (unchanged)
13
+ src/FilePicker/FileSearch.js 141ms (unchanged)
14
+ src/FilePicker/index.js 154ms (unchanged)
15
+ src/FilePicker/stateManagement.js 126ms (unchanged)
16
+ src/FilePicker/UploadFilesButton.js 30ms (unchanged)
17
+ src/FilePicker/UploadProgress.js 69ms (unchanged)
18
+ src/FilePicker/utils.js 20ms (unchanged)
19
+ src/index.js 2ms (unchanged)
20
+ src/styles.css 300ms (unchanged)
21
+ tsconfig.json 3ms (unchanged)
@@ -0,0 +1,4 @@
1
+
2
+ > @raketa-builder/file-input@0.4.0 lint
3
+ > biome lint --max-diagnostics=5000 .
4
+
package/biome.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": ["../../biome.json"]
3
+ }
package/dist/index.js CHANGED
@@ -1366,12 +1366,16 @@ var DeleteIcon = (props) => {
1366
1366
  var formatDate = (dateStr) => new Date(dateStr).toLocaleDateString(void 0, {
1367
1367
  year: "numeric",
1368
1368
  month: "long",
1369
- day: "numeric"
1369
+ day: "numeric",
1370
+ hour: "numeric",
1371
+ minute: "numeric",
1372
+ second: "numeric"
1370
1373
  });
1371
1374
  var FileList = ({
1372
1375
  files,
1373
1376
  fetching,
1374
1377
  selected,
1378
+ allowDelete,
1375
1379
  onMore,
1376
1380
  onSelect,
1377
1381
  onDelete
@@ -1415,7 +1419,7 @@ var FileList = ({
1415
1419
  }
1416
1420
  ),
1417
1421
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: decodeURI(file.filename) }),
1418
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1422
+ allowDelete && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1419
1423
  DeleteIcon,
1420
1424
  {
1421
1425
  onClick: (event) => {
@@ -1584,6 +1588,7 @@ var FilePicker = ({
1584
1588
  label,
1585
1589
  hint,
1586
1590
  fileCategory = null,
1591
+ allowFilesDelete = true,
1587
1592
  onChange
1588
1593
  }) => {
1589
1594
  var _a;
@@ -1666,6 +1671,7 @@ var FilePicker = ({
1666
1671
  fetching: state.fetching,
1667
1672
  files: state.files.list,
1668
1673
  onMore: loadMoreFiles(fileManager, state, setState),
1674
+ allowDelete: allowFilesDelete,
1669
1675
  onDelete: onDeleteFile,
1670
1676
  selected: (_a = state.selected) == null ? void 0 : _a.document,
1671
1677
  onSelect: (fileId) => selectFile(fileId, setState)
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@raketa-builder/file-input",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
7
7
  "scripts": {
8
- "lint": "TIMING=1 eslint \"**/*.js\"",
9
8
  "build": "tsup src/index.js --format cjs --loader \".js=jsx\"",
10
- "dev": "tsup src/index.js --format cjs --loader \".js=jsx\" --watch"
9
+ "dev": "tsup src/index.js --format cjs --loader \".js=jsx\" --watch",
10
+ "format": "prettier --write .",
11
+ "lint": "biome lint --max-diagnostics=5000 ."
11
12
  },
12
13
  "peerDependencies": {
13
14
  "react": "18.2.0",
@@ -18,10 +19,10 @@
18
19
  "ui": "*"
19
20
  },
20
21
  "devDependencies": {
22
+ "@biomejs/biome": "1.5.2",
21
23
  "@types/react": "17.0.37",
22
24
  "@types/react-dom": "17.0.11",
23
- "eslint": "7.32.0",
24
- "eslint-config-custom": "*",
25
+ "prettier": "3.2.4",
25
26
  "react": "18.2.0",
26
27
  "tsconfig": "*",
27
28
  "tsup": "6.5.0",
@@ -150,7 +150,7 @@ export default class FileManager {
150
150
  method: "POST",
151
151
  headers: Object.assign(
152
152
  { "Content-Type": "application/json" },
153
- this.headers
153
+ this.headers,
154
154
  ),
155
155
  body: JSON.stringify({
156
156
  query: query,
@@ -196,7 +196,7 @@ export default class FileManager {
196
196
  async all(params = {}) {
197
197
  return this.graphQLRequest(
198
198
  DOCUMENTS_QUERY,
199
- this.buildVariables(params)
199
+ this.buildVariables(params),
200
200
  ).then((d) => {
201
201
  return d?.data.documents || {};
202
202
  });
@@ -222,7 +222,7 @@ export default class FileManager {
222
222
  }
223
223
 
224
224
  const result = await uploadFile(file, document, (state) =>
225
- progressCallback(id, state)
225
+ progressCallback(id, state),
226
226
  );
227
227
 
228
228
  if (result) {
@@ -7,7 +7,7 @@ const DropZone = ({ children, onDrop }) => {
7
7
  (acceptedFiles) => {
8
8
  onDrop(acceptedFiles);
9
9
  },
10
- [onDrop]
10
+ [onDrop],
11
11
  );
12
12
 
13
13
  const { getRootProps, getInputProps, isDragActive } = useDropzone({
@@ -20,7 +20,7 @@ const DropZone = ({ children, onDrop }) => {
20
20
  className={cn(
21
21
  "r-reset",
22
22
  "r-dropzone-modal",
23
- isDragActive ? "r-dropzone-modal-active" : ""
23
+ isDragActive ? "r-dropzone-modal-active" : "",
24
24
  )}
25
25
  {...getRootProps()}
26
26
  >
@@ -51,12 +51,16 @@ const formatDate = (dateStr) =>
51
51
  year: "numeric",
52
52
  month: "long",
53
53
  day: "numeric",
54
+ hour: "numeric",
55
+ minute: "numeric",
56
+ second: "numeric",
54
57
  });
55
58
 
56
59
  const FileList = ({
57
60
  files,
58
61
  fetching,
59
62
  selected,
63
+ allowDelete,
60
64
  onMore,
61
65
  onSelect,
62
66
  onDelete,
@@ -81,7 +85,7 @@ const FileList = ({
81
85
  key={file.id}
82
86
  className={cn(
83
87
  "r-file-input-file-row",
84
- selected?.id === file.id ? "r-file-input-file-row-active" : ""
88
+ selected?.id === file.id ? "r-file-input-file-row-active" : "",
85
89
  )}
86
90
  onClick={() => onSelect(file.id)}
87
91
  >
@@ -101,15 +105,17 @@ const FileList = ({
101
105
  />
102
106
 
103
107
  <div>{decodeURI(file.filename)}</div>
104
- <DeleteIcon
105
- onClick={(event) => {
106
- event.stopPropagation();
108
+ {allowDelete && (
109
+ <DeleteIcon
110
+ onClick={(event) => {
111
+ event.stopPropagation();
107
112
 
108
- if (confirm("Are you sure?")) {
109
- onDelete(file.id);
110
- }
111
- }}
112
- />
113
+ if (confirm("Are you sure?")) {
114
+ onDelete(file.id);
115
+ }
116
+ }}
117
+ />
118
+ )}
113
119
  </Stack>
114
120
  </td>
115
121
  <td>{toFileCategory(file.mimeType, "human")}</td>
@@ -17,7 +17,7 @@ const UploadState = ({ upload }) => {
17
17
  "r-reset",
18
18
  "r-stack",
19
19
  "r-stack-justify-beteen",
20
- "r-stack-align-center"
20
+ "r-stack-align-center",
21
21
  )}
22
22
  >
23
23
  {fileSizeFormatter(upload.state?.payload?.loaded || 0)} /{" "}
@@ -70,7 +70,7 @@ const UploadProgress = ({ uploads }) => {
70
70
  "r-reset",
71
71
  "r-stack-justify-beteen",
72
72
  "r-stack-align-center",
73
- "r-file-progress"
73
+ "r-file-progress",
74
74
  )}
75
75
  >
76
76
  <UploadName upload={upload} />
@@ -23,15 +23,16 @@ const FilePicker = ({
23
23
  label,
24
24
  hint,
25
25
  fileCategory = null,
26
+ allowFilesDelete = true,
26
27
  onChange,
27
28
  }) => {
28
29
  const allowedFileCategory = React.useMemo(
29
30
  () => sanitizeFileCategory(fileCategory),
30
- [fileCategory]
31
+ [fileCategory],
31
32
  );
32
33
 
33
34
  const [state, setState] = React.useState(
34
- initialState(initialValue, allowedFileCategory)
35
+ initialState(initialValue, allowedFileCategory),
35
36
  );
36
37
 
37
38
  const onFilesUpload = (files) => {
@@ -110,6 +111,7 @@ const FilePicker = ({
110
111
  fetching={state.fetching}
111
112
  files={state.files.list}
112
113
  onMore={loadMoreFiles(fileManager, state, setState)}
114
+ allowDelete={allowFilesDelete}
113
115
  onDelete={onDeleteFile}
114
116
  selected={state.selected?.document}
115
117
  onSelect={(fileId) => selectFile(fileId, setState)}
@@ -67,7 +67,7 @@ export function uploadFiles(fileManager, files, allowedFileCategory, setState) {
67
67
  if (newState.type === "completed") {
68
68
  if (
69
69
  currentState.files.list.find(
70
- (file) => file.id === newState.payload.document.id
70
+ (file) => file.id === newState.payload.document.id,
71
71
  )
72
72
  ) {
73
73
  return currentState;
@@ -76,7 +76,7 @@ export function uploadFiles(fileManager, files, allowedFileCategory, setState) {
76
76
  return {
77
77
  ...currentState,
78
78
  uploads: currentState.uploads.filter(
79
- (upload) => upload.id !== tmpId
79
+ (upload) => upload.id !== tmpId,
80
80
  ),
81
81
  files: {
82
82
  ...currentState.files,
@@ -97,8 +97,8 @@ export function uploadFiles(fileManager, files, allowedFileCategory, setState) {
97
97
 
98
98
  return { ...currentState, uploads: newUploads };
99
99
  }
100
- })
101
- )
100
+ }),
101
+ ),
102
102
  );
103
103
  }
104
104
 
@@ -186,7 +186,7 @@ export async function deleteFile(
186
186
  fileId,
187
187
  state,
188
188
  setState,
189
- onChange
189
+ onChange,
190
190
  ) {
191
191
  setState((currentState) => ({
192
192
  ...currentState,
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "tsconfig/react-library.json",
3
3
  "include": ["src"],
4
- "exclude": ["dist", "build", "node_modules"]
4
+ "exclude": ["dist", "build", "node_modules"],
5
5
  }