@raketa-builder/file-input 0.4.0 → 0.6.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.6.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 69.91 KB
11
+ CJS ⚡️ Build success in 49ms
@@ -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
@@ -910,9 +910,8 @@ function toFileCategory(mimeType, format = "robot") {
910
910
  }
911
911
  if (format === "human") {
912
912
  return FILE_CATEGORIES[fileCategory] || fileCategory;
913
- } else {
914
- return fileCategory;
915
913
  }
914
+ return fileCategory;
916
915
  }
917
916
  function fileCategoriesOptions() {
918
917
  return Object.keys(FILE_CATEGORIES).map((key) => [key, FILE_CATEGORIES[key]]);
@@ -996,16 +995,14 @@ function uploadFiles(fileManager, files, allowedFileCategory, setState) {
996
995
  ]
997
996
  })
998
997
  });
999
- } else {
1000
- const newUploads = currentState.uploads.map((upload) => {
1001
- if (upload.id === tmpId) {
1002
- return __spreadProps(__spreadValues({}, upload), { state: newState });
1003
- } else {
1004
- return upload;
1005
- }
1006
- });
1007
- return __spreadProps(__spreadValues({}, currentState), { uploads: newUploads });
1008
998
  }
999
+ const newUploads = currentState.uploads.map((upload) => {
1000
+ if (upload.id === tmpId) {
1001
+ return __spreadProps(__spreadValues({}, upload), { state: newState });
1002
+ }
1003
+ return upload;
1004
+ });
1005
+ return __spreadProps(__spreadValues({}, currentState), { uploads: newUploads });
1009
1006
  })
1010
1007
  )
1011
1008
  );
@@ -1263,6 +1260,7 @@ var FileSearch = ({ fetching, value, allowedFileCategory, onChange }) => {
1263
1260
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1264
1261
  "button",
1265
1262
  {
1263
+ type: "button",
1266
1264
  disabled: fetching,
1267
1265
  className: `r-reset-button r-tab-button ${(value == null ? void 0 : value.category) === "" ? "r-tab-button-active" : ""}`,
1268
1266
  onClick: () => onCategoryPick(""),
@@ -1274,6 +1272,7 @@ var FileSearch = ({ fetching, value, allowedFileCategory, onChange }) => {
1274
1272
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1275
1273
  "button",
1276
1274
  {
1275
+ type: "button",
1277
1276
  disabled: fetching,
1278
1277
  className: `r-reset-button r-tab-button ${(value == null ? void 0 : value.category) === key ? "r-tab-button-active" : ""}`,
1279
1278
  onClick: () => onCategoryPick(key),
@@ -1319,6 +1318,7 @@ var DeleteIcon = (props) => {
1319
1318
  className: "r-file-input-delete-icon"
1320
1319
  }, props), {
1321
1320
  children: [
1321
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("title", { children: "Delete" }),
1322
1322
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1323
1323
  "path",
1324
1324
  {
@@ -1363,6 +1363,41 @@ var DeleteIcon = (props) => {
1363
1363
  })
1364
1364
  );
1365
1365
  };
1366
+ var CopyIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1367
+ "svg",
1368
+ __spreadProps(__spreadValues({
1369
+ xmlns: "http://www.w3.org/2000/svg",
1370
+ width: "24",
1371
+ height: "25",
1372
+ viewBox: "0 0 24 25",
1373
+ fill: "none",
1374
+ className: "r-file-input-copy-icon"
1375
+ }, props), {
1376
+ children: [
1377
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("title", { children: "Copy file URL" }),
1378
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1379
+ "path",
1380
+ {
1381
+ d: "M10 13.5C10.4295 14.0741 10.9774 14.5491 11.6066 14.8929C12.2357 15.2367 12.9315 15.4411 13.6467 15.4923C14.3618 15.5435 15.0796 15.4403 15.7513 15.1897C16.4231 14.9392 17.0331 14.547 17.54 14.04L20.54 11.04C21.4508 10.097 21.9548 8.83394 21.9434 7.52296C21.932 6.21198 21.4061 4.95791 20.4791 4.03087C19.5521 3.10383 18.298 2.57799 16.987 2.5666C15.676 2.5552 14.413 3.05918 13.47 3.96997L11.75 5.67997",
1382
+ stroke: "black",
1383
+ strokeWidth: "2",
1384
+ strokeLinecap: "round",
1385
+ strokeLinejoin: "round"
1386
+ }
1387
+ ),
1388
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1389
+ "path",
1390
+ {
1391
+ d: "M14 11.5C13.5705 10.9259 13.0226 10.4508 12.3934 10.107C11.7642 9.76328 11.0684 9.55886 10.3533 9.50765C9.63816 9.45643 8.92037 9.55961 8.24861 9.8102C7.57685 10.0608 6.96684 10.4529 6.45996 10.96L3.45996 13.96C2.54917 14.903 2.04519 16.166 2.05659 17.477C2.06798 18.788 2.59382 20.042 3.52086 20.9691C4.4479 21.8961 5.70197 22.422 7.01295 22.4334C8.32393 22.4447 9.58694 21.9408 10.53 21.03L12.24 19.32",
1392
+ stroke: "black",
1393
+ strokeWidth: "2",
1394
+ strokeLinecap: "round",
1395
+ strokeLinejoin: "round"
1396
+ }
1397
+ )
1398
+ ]
1399
+ })
1400
+ );
1366
1401
  var formatDate = (dateStr) => new Date(dateStr).toLocaleDateString(void 0, {
1367
1402
  year: "numeric",
1368
1403
  month: "long",
@@ -1419,6 +1454,15 @@ var FileList = ({
1419
1454
  }
1420
1455
  ),
1421
1456
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: decodeURI(file.filename) }),
1457
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1458
+ CopyIcon,
1459
+ {
1460
+ onClick: (e) => {
1461
+ e.stopPropagation();
1462
+ navigator.clipboard.writeText(file.url);
1463
+ }
1464
+ }
1465
+ ),
1422
1466
  allowDelete && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1423
1467
  DeleteIcon,
1424
1468
  {
@@ -1642,7 +1686,7 @@ var FilePicker = ({
1642
1686
  state.open && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1643
1687
  Dialog_default,
1644
1688
  {
1645
- disablePrimary: !Boolean(state.selected),
1689
+ disablePrimary: !state.selected,
1646
1690
  onPrimary: onSelectFile,
1647
1691
  onClose,
1648
1692
  onDrop: onFilesUpload,
@@ -1807,8 +1851,8 @@ function uploadFile(file, document2, progressCallback) {
1807
1851
  xhr.withCredentials = false;
1808
1852
  xhr.open("PUT", document2.uploadUrl, true);
1809
1853
  xhr.setRequestHeader("content-type", file.type);
1810
- var reader = new FileReader();
1811
- reader.onload = function(event) {
1854
+ const reader = new FileReader();
1855
+ reader.onload = (event) => {
1812
1856
  xhr.send(event.target.result);
1813
1857
  };
1814
1858
  reader.readAsArrayBuffer(file);
@@ -1837,7 +1881,7 @@ var FileManager = class {
1837
1881
  }
1838
1882
  buildFilters(params) {
1839
1883
  var _a, _b;
1840
- let filters = {
1884
+ const filters = {
1841
1885
  uploadStatus: "COMPLETED"
1842
1886
  };
1843
1887
  if (((_a = params == null ? void 0 : params.mimeTypes) == null ? void 0 : _a.length) > 0) {
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@raketa-builder/file-input",
3
- "version": "0.4.0",
3
+ "version": "0.6.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",
@@ -130,8 +130,8 @@ async function uploadFile(file, document, progressCallback) {
130
130
  xhr.setRequestHeader("content-type", file.type);
131
131
 
132
132
  // Read the file as ArrayBuffer and send it!
133
- var reader = new FileReader();
134
- reader.onload = function (event) {
133
+ const reader = new FileReader();
134
+ reader.onload = (event) => {
135
135
  xhr.send(event.target.result);
136
136
  };
137
137
 
@@ -160,7 +160,7 @@ export default class FileManager {
160
160
  }
161
161
 
162
162
  buildFilters(params) {
163
- let filters = {
163
+ const filters = {
164
164
  uploadStatus: "COMPLETED",
165
165
  };
166
166
 
@@ -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
  >
@@ -108,9 +108,9 @@ export function toFileCategory(mimeType, format = "robot") {
108
108
 
109
109
  if (format === "human") {
110
110
  return FILE_CATEGORIES[fileCategory] || fileCategory;
111
- } else {
112
- return fileCategory;
113
111
  }
112
+
113
+ return fileCategory;
114
114
  }
115
115
 
116
116
  export function fileCategoriesOptions() {
@@ -14,6 +14,7 @@ const DeleteIcon = (props) => {
14
14
  className="r-file-input-delete-icon"
15
15
  {...props}
16
16
  >
17
+ <title>Delete</title>
17
18
  <path
18
19
  d="M3 6.5H5H21"
19
20
  stroke="currentColor"
@@ -46,6 +47,34 @@ const DeleteIcon = (props) => {
46
47
  );
47
48
  };
48
49
 
50
+ const CopyIcon = (props) => (
51
+ <svg
52
+ xmlns="http://www.w3.org/2000/svg"
53
+ width="24"
54
+ height="25"
55
+ viewBox="0 0 24 25"
56
+ fill="none"
57
+ className="r-file-input-copy-icon"
58
+ {...props}
59
+ >
60
+ <title>Copy file URL</title>
61
+ <path
62
+ d="M10 13.5C10.4295 14.0741 10.9774 14.5491 11.6066 14.8929C12.2357 15.2367 12.9315 15.4411 13.6467 15.4923C14.3618 15.5435 15.0796 15.4403 15.7513 15.1897C16.4231 14.9392 17.0331 14.547 17.54 14.04L20.54 11.04C21.4508 10.097 21.9548 8.83394 21.9434 7.52296C21.932 6.21198 21.4061 4.95791 20.4791 4.03087C19.5521 3.10383 18.298 2.57799 16.987 2.5666C15.676 2.5552 14.413 3.05918 13.47 3.96997L11.75 5.67997"
63
+ stroke="black"
64
+ strokeWidth="2"
65
+ strokeLinecap="round"
66
+ strokeLinejoin="round"
67
+ />
68
+ <path
69
+ d="M14 11.5C13.5705 10.9259 13.0226 10.4508 12.3934 10.107C11.7642 9.76328 11.0684 9.55886 10.3533 9.50765C9.63816 9.45643 8.92037 9.55961 8.24861 9.8102C7.57685 10.0608 6.96684 10.4529 6.45996 10.96L3.45996 13.96C2.54917 14.903 2.04519 16.166 2.05659 17.477C2.06798 18.788 2.59382 20.042 3.52086 20.9691C4.4479 21.8961 5.70197 22.422 7.01295 22.4334C8.32393 22.4447 9.58694 21.9408 10.53 21.03L12.24 19.32"
70
+ stroke="black"
71
+ strokeWidth="2"
72
+ strokeLinecap="round"
73
+ strokeLinejoin="round"
74
+ />
75
+ </svg>
76
+ );
77
+
49
78
  const formatDate = (dateStr) =>
50
79
  new Date(dateStr).toLocaleDateString(undefined, {
51
80
  year: "numeric",
@@ -105,6 +134,14 @@ const FileList = ({
105
134
  />
106
135
 
107
136
  <div>{decodeURI(file.filename)}</div>
137
+
138
+ <CopyIcon
139
+ onClick={(e) => {
140
+ e.stopPropagation();
141
+ navigator.clipboard.writeText(file.url);
142
+ }}
143
+ />
144
+
108
145
  {allowDelete && (
109
146
  <DeleteIcon
110
147
  onClick={(event) => {
@@ -62,6 +62,7 @@ const FileSearch = ({ fetching, value, allowedFileCategory, onChange }) => {
62
62
  <Stack className="r-spacing-both-sm">
63
63
  <div className={cn("r-reset", "r-tab-wrapper")}>
64
64
  <button
65
+ type="button"
65
66
  disabled={fetching}
66
67
  className={`r-reset-button r-tab-button ${
67
68
  value?.category === "" ? "r-tab-button-active" : ""
@@ -76,6 +77,7 @@ const FileSearch = ({ fetching, value, allowedFileCategory, onChange }) => {
76
77
 
77
78
  return (
78
79
  <button
80
+ type="button"
79
81
  key={key}
80
82
  disabled={fetching}
81
83
  className={`r-reset-button r-tab-button ${
@@ -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} />
@@ -86,7 +86,7 @@ const FilePicker = ({
86
86
 
87
87
  {state.open && (
88
88
  <Dialog
89
- disablePrimary={!Boolean(state.selected)}
89
+ disablePrimary={!state.selected}
90
90
  onPrimary={onSelectFile}
91
91
  onClose={onClose}
92
92
  onDrop={onFilesUpload}
@@ -86,17 +86,17 @@ export function uploadFiles(fileManager, files, allowedFileCategory, setState) {
86
86
  ],
87
87
  },
88
88
  };
89
- } else {
90
- const newUploads = currentState.uploads.map((upload) => {
91
- if (upload.id === tmpId) {
92
- return { ...upload, state: newState };
93
- } else {
94
- return upload;
95
- }
96
- });
97
-
98
- return { ...currentState, uploads: newUploads };
99
89
  }
90
+
91
+ const newUploads = currentState.uploads.map((upload) => {
92
+ if (upload.id === tmpId) {
93
+ return { ...upload, state: newState };
94
+ }
95
+
96
+ return upload;
97
+ });
98
+
99
+ return { ...currentState, uploads: newUploads };
100
100
  })
101
101
  )
102
102
  );
package/src/styles.css CHANGED
@@ -43,12 +43,16 @@
43
43
  .r-file-input-file-row {
44
44
  cursor: pointer;
45
45
  }
46
-
46
+ .r-file-input-copy-icon {
47
+ display: none;
48
+ width: auto;
49
+ height: 0.9rem;
50
+ }
47
51
  .r-file-input-delete-icon {
48
52
  display: none;
49
53
  color: var(--r-gray);
50
54
  width: auto;
51
- height: 0.8rem;
55
+ height: 0.9rem;
52
56
  }
53
57
 
54
58
  .r-file-input-delete-icon:hover {
@@ -59,7 +63,8 @@
59
63
  border-bottom: 1px solid var(--r-gray);
60
64
  }
61
65
 
62
- .r-file-input-file-row:hover .r-file-input-delete-icon {
66
+ .r-file-input-file-row:hover .r-file-input-delete-icon,
67
+ .r-file-input-file-row:hover .r-file-input-copy-icon {
63
68
  display: block;
64
69
  }
65
70
 
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
  }