@raketa-builder/file-input 0.5.0 → 0.7.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @raketa-builder/file-input@0.5.0 build
2
+ > @raketa-builder/file-input@0.7.0 build
3
3
  > tsup src/index.js --format cjs --loader ".js=jsx"
4
4
 
5
5
  CLI Building entry: src/index.js
@@ -7,5 +7,5 @@ CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v6.5.0
8
8
  CLI Target: es6
9
9
  CJS Build start
10
- CJS dist/index.js 67.83 KB
11
- CJS ⚡️ Build success in 150ms
10
+ CJS dist/index.js 72.99 KB
11
+ CJS ⚡️ Build success in 109ms
package/dist/index.js CHANGED
@@ -122,6 +122,7 @@ var require_dist = __commonJS({
122
122
  var src_exports2 = {};
123
123
  __export2(src_exports2, {
124
124
  Button: () => Button_default,
125
+ CategoriesMenu: () => CategoriesMenu_default,
125
126
  Col: () => Col,
126
127
  Container: () => Container_default,
127
128
  DataGrid: () => DataGrid_default,
@@ -227,11 +228,24 @@ var require_dist = __commonJS({
227
228
  var import_react32 = __toESM2(require("react"));
228
229
  var import_jsx_runtime32 = require("react/jsx-runtime");
229
230
  var Button4 = (_a) => {
230
- var _b = _a, { as = "button", size, variant, className } = _b, rest = __objRest(_b, ["as", "size", "variant", "className"]);
231
+ var _b = _a, {
232
+ as = "button",
233
+ size = "md",
234
+ variant = "primary",
235
+ className,
236
+ type = "button"
237
+ } = _b, rest = __objRest(_b, [
238
+ "as",
239
+ "size",
240
+ "variant",
241
+ "className",
242
+ "type"
243
+ ]);
231
244
  const Component = as;
232
245
  return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
233
246
  Component,
234
247
  __spreadValues2({
248
+ type,
235
249
  className: cn6(
236
250
  "r-reset",
237
251
  "r-reset-button",
@@ -243,11 +257,6 @@ var require_dist = __commonJS({
243
257
  }, rest)
244
258
  );
245
259
  };
246
- Button4.defaultProps = {
247
- type: "button",
248
- size: "md",
249
- variant: "primary"
250
- };
251
260
  Button4.variants = ["primary", "secondary", "success", "danger"];
252
261
  Button4.sizes = {
253
262
  sm: "sm",
@@ -461,6 +470,7 @@ var require_dist = __commonJS({
461
470
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
462
471
  "button",
463
472
  __spreadValues2({
473
+ type: "button",
464
474
  className: cn6("r-reset-button r-modal-close-btn", className)
465
475
  }, props)
466
476
  );
@@ -473,37 +483,47 @@ var require_dist = __commonJS({
473
483
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
474
484
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", __spreadValues2({ className: cn6("r-reset", "r-modal-content", className) }, props));
475
485
  };
486
+ function checkForChanges(hasChanges, onClose) {
487
+ if (!hasChanges) {
488
+ onClose();
489
+ return;
490
+ }
491
+ if (!confirm(
492
+ "You\u2019ve made changes to the widget. Are you sure you want to cancel?"
493
+ ))
494
+ return;
495
+ onClose();
496
+ }
476
497
  var Modal2 = (_a) => {
477
498
  var _b = _a, {
478
499
  title,
479
500
  children,
480
501
  customWrapper,
481
502
  FooterContent,
482
- onClose
503
+ onClose,
504
+ areChanges
483
505
  } = _b, rest = __objRest(_b, [
484
506
  "title",
485
507
  "children",
486
508
  "customWrapper",
487
509
  "FooterContent",
488
- "onClose"
510
+ "onClose",
511
+ "areChanges"
489
512
  ]);
490
- const handleKeyUp = ({ key }) => {
491
- if (key === "Escape")
492
- onClose();
493
- };
494
- import_react17.default.useEffect(() => {
495
- document.addEventListener("keyup", handleKeyUp);
496
- return () => {
497
- document.removeEventListener("keyup", handleKeyUp);
498
- };
499
- });
500
513
  const ModalWrapper = customWrapper ? customWrapper : Wrapper;
501
514
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_react17.default.Fragment, { children: [
502
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Overlay, { onClick: onClose }),
515
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Overlay, {}),
503
516
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ModalWrapper, __spreadProps2(__spreadValues2({}, rest), { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Inner, { children: [
504
517
  /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(TitleBar, { children: [
505
518
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Title, { children: title }),
506
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(CloseButton, { type: "button", onClick: onClose, children: "\xD7" })
519
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
520
+ CloseButton,
521
+ {
522
+ type: "button",
523
+ onClick: () => checkForChanges(areChanges, onClose),
524
+ children: "\xD7"
525
+ }
526
+ )
507
527
  ] }),
508
528
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Content, { children }),
509
529
  FooterContent && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FooterBar, { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FooterContent, {}) })
@@ -738,7 +758,7 @@ var require_dist = __commonJS({
738
758
  var import_react24 = __toESM2(require("react"));
739
759
  var import_jsx_runtime24 = require("react/jsx-runtime");
740
760
  var ImageAvatar = (_a) => {
741
- var _b = _a, { size, className } = _b, props = __objRest(_b, ["size", "className"]);
761
+ var _b = _a, { size = "24px", className } = _b, props = __objRest(_b, ["size", "className"]);
742
762
  return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
743
763
  "img",
744
764
  __spreadValues2({
@@ -751,9 +771,6 @@ var require_dist = __commonJS({
751
771
  }, props)
752
772
  );
753
773
  };
754
- ImageAvatar.defaultProps = {
755
- size: "24px"
756
- };
757
774
  var ImageAvatar_default = ImageAvatar;
758
775
  var import_react25 = __toESM2(require("react"));
759
776
  var import_jsx_runtime25 = require("react/jsx-runtime");
@@ -794,14 +811,53 @@ var require_dist = __commonJS({
794
811
  );
795
812
  };
796
813
  var DefaultAvatar = (_a) => {
797
- var _b = _a, { initials } = _b, props = __objRest(_b, ["initials"]);
798
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(DefaultAvatarStyles, __spreadProps2(__spreadValues2({ initials }, props), { children: initials }));
799
- };
800
- DefaultAvatar.defaultProps = {
801
- size: "24px",
802
- initials: "AA"
814
+ var _b = _a, { initials = "AA", size = "24px" } = _b, props = __objRest(_b, ["initials", "size"]);
815
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(DefaultAvatarStyles, __spreadProps2(__spreadValues2({ initials, size }, props), { children: initials }));
803
816
  };
804
817
  var DefaultAvatar_default = DefaultAvatar;
818
+ var import_react26 = __toESM2(require("react"));
819
+ var import_jsx_runtime26 = require("react/jsx-runtime");
820
+ var IconsWrapper = () => /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "r-reset r-categories-icons-wrapper", children: [
821
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
822
+ "img",
823
+ {
824
+ style: {
825
+ color: "#fff",
826
+ width: "24px",
827
+ height: "24px",
828
+ filter: "invert(1)"
829
+ },
830
+ alt: "directions",
831
+ src: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItZ3JpZCI+PHJlY3QgeD0iMyIgeT0iMyIgd2lkdGg9IjciIGhlaWdodD0iNyI+PC9yZWN0PjxyZWN0IHg9IjE0IiB5PSIzIiB3aWR0aD0iNyIgaGVpZ2h0PSI3Ij48L3JlY3Q+PHJlY3QgeD0iMTQiIHk9IjE0IiB3aWR0aD0iNyIgaGVpZ2h0PSI3Ij48L3JlY3Q+PHJlY3QgeD0iMyIgeT0iMTQiIHdpZHRoPSI3IiBoZWlnaHQ9IjciPjwvcmVjdD48L3N2Zz4="
832
+ }
833
+ ),
834
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
835
+ "img",
836
+ {
837
+ className: "r-reset r-category-chevron",
838
+ alt: "directions",
839
+ src: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjIiIGhlaWdodD0iMTMiIHZpZXdCb3g9IjAgMCAyMiAxMyIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTIxIDExLjVMMTEgMS41TDEgMTEuNSIgc3Ryb2tlPSIjMEMwQTA5IiBzdHJva2Utd2lkdGg9IjIiLz4KPC9zdmc+Cg=="
840
+ }
841
+ )
842
+ ] });
843
+ var Title2 = () => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "r-categories-title", children: "Categories" });
844
+ var CategoriesInner = (_a) => {
845
+ var props = __objRest(_a, []);
846
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", __spreadProps2(__spreadValues2({}, props), { className: "r-reset r-categories-inner" }));
847
+ };
848
+ var CategoriesHiddenMenu = ({ paths }) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "r-reset r-categories-hidden-menu", children: paths.map(({ title, link }, idx) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("a", { href: link, className: "r-reset r-category-link", children: title }, `${idx}-${link}`)) });
849
+ var CategoriesMenuWrapper = (_a) => {
850
+ var props = __objRest(_a, []);
851
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", __spreadValues2({ className: "r-reset r-categories-menu" }, props));
852
+ };
853
+ var CategoriesMenu = ({ paths }) => /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(CategoriesMenuWrapper, { children: [
854
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(CategoriesInner, { children: [
855
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(IconsWrapper, {}),
856
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Title2, {})
857
+ ] }),
858
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(CategoriesHiddenMenu, { paths })
859
+ ] });
860
+ var CategoriesMenu_default = CategoriesMenu;
805
861
  }
806
862
  });
807
863
 
@@ -910,9 +966,8 @@ function toFileCategory(mimeType, format = "robot") {
910
966
  }
911
967
  if (format === "human") {
912
968
  return FILE_CATEGORIES[fileCategory] || fileCategory;
913
- } else {
914
- return fileCategory;
915
969
  }
970
+ return fileCategory;
916
971
  }
917
972
  function fileCategoriesOptions() {
918
973
  return Object.keys(FILE_CATEGORIES).map((key) => [key, FILE_CATEGORIES[key]]);
@@ -996,16 +1051,14 @@ function uploadFiles(fileManager, files, allowedFileCategory, setState) {
996
1051
  ]
997
1052
  })
998
1053
  });
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
1054
  }
1055
+ const newUploads = currentState.uploads.map((upload) => {
1056
+ if (upload.id === tmpId) {
1057
+ return __spreadProps(__spreadValues({}, upload), { state: newState });
1058
+ }
1059
+ return upload;
1060
+ });
1061
+ return __spreadProps(__spreadValues({}, currentState), { uploads: newUploads });
1009
1062
  })
1010
1063
  )
1011
1064
  );
@@ -1263,6 +1316,7 @@ var FileSearch = ({ fetching, value, allowedFileCategory, onChange }) => {
1263
1316
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1264
1317
  "button",
1265
1318
  {
1319
+ type: "button",
1266
1320
  disabled: fetching,
1267
1321
  className: `r-reset-button r-tab-button ${(value == null ? void 0 : value.category) === "" ? "r-tab-button-active" : ""}`,
1268
1322
  onClick: () => onCategoryPick(""),
@@ -1274,6 +1328,7 @@ var FileSearch = ({ fetching, value, allowedFileCategory, onChange }) => {
1274
1328
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1275
1329
  "button",
1276
1330
  {
1331
+ type: "button",
1277
1332
  disabled: fetching,
1278
1333
  className: `r-reset-button r-tab-button ${(value == null ? void 0 : value.category) === key ? "r-tab-button-active" : ""}`,
1279
1334
  onClick: () => onCategoryPick(key),
@@ -1319,6 +1374,7 @@ var DeleteIcon = (props) => {
1319
1374
  className: "r-file-input-delete-icon"
1320
1375
  }, props), {
1321
1376
  children: [
1377
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("title", { children: "Delete" }),
1322
1378
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1323
1379
  "path",
1324
1380
  {
@@ -1363,6 +1419,41 @@ var DeleteIcon = (props) => {
1363
1419
  })
1364
1420
  );
1365
1421
  };
1422
+ var CopyIcon = (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1423
+ "svg",
1424
+ __spreadProps(__spreadValues({
1425
+ xmlns: "http://www.w3.org/2000/svg",
1426
+ width: "24",
1427
+ height: "25",
1428
+ viewBox: "0 0 24 25",
1429
+ fill: "none",
1430
+ className: "r-file-input-copy-icon"
1431
+ }, props), {
1432
+ children: [
1433
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("title", { children: "Copy file URL" }),
1434
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1435
+ "path",
1436
+ {
1437
+ 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",
1438
+ stroke: "black",
1439
+ strokeWidth: "2",
1440
+ strokeLinecap: "round",
1441
+ strokeLinejoin: "round"
1442
+ }
1443
+ ),
1444
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1445
+ "path",
1446
+ {
1447
+ 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",
1448
+ stroke: "black",
1449
+ strokeWidth: "2",
1450
+ strokeLinecap: "round",
1451
+ strokeLinejoin: "round"
1452
+ }
1453
+ )
1454
+ ]
1455
+ })
1456
+ );
1366
1457
  var formatDate = (dateStr) => new Date(dateStr).toLocaleDateString(void 0, {
1367
1458
  year: "numeric",
1368
1459
  month: "long",
@@ -1419,6 +1510,15 @@ var FileList = ({
1419
1510
  }
1420
1511
  ),
1421
1512
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: decodeURI(file.filename) }),
1513
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1514
+ CopyIcon,
1515
+ {
1516
+ onClick: (e) => {
1517
+ e.stopPropagation();
1518
+ navigator.clipboard.writeText(file.url);
1519
+ }
1520
+ }
1521
+ ),
1422
1522
  allowDelete && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1423
1523
  DeleteIcon,
1424
1524
  {
@@ -1642,7 +1742,7 @@ var FilePicker = ({
1642
1742
  state.open && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1643
1743
  Dialog_default,
1644
1744
  {
1645
- disablePrimary: !Boolean(state.selected),
1745
+ disablePrimary: !state.selected,
1646
1746
  onPrimary: onSelectFile,
1647
1747
  onClose,
1648
1748
  onDrop: onFilesUpload,
@@ -1773,7 +1873,7 @@ var DELETE_DOCUMENT_MUTATION = `
1773
1873
  }
1774
1874
  }
1775
1875
  `;
1776
- function uploadFile(file, document2, progressCallback) {
1876
+ function uploadFile(file, document, progressCallback) {
1777
1877
  return __async(this, null, function* () {
1778
1878
  const xhr = new XMLHttpRequest();
1779
1879
  return new Promise((resolve) => {
@@ -1805,10 +1905,10 @@ function uploadFile(file, document2, progressCallback) {
1805
1905
  resolve(xhr.readyState === 4 && xhr.status === 200);
1806
1906
  });
1807
1907
  xhr.withCredentials = false;
1808
- xhr.open("PUT", document2.uploadUrl, true);
1908
+ xhr.open("PUT", document.uploadUrl, true);
1809
1909
  xhr.setRequestHeader("content-type", file.type);
1810
- var reader = new FileReader();
1811
- reader.onload = function(event) {
1910
+ const reader = new FileReader();
1911
+ reader.onload = (event) => {
1812
1912
  xhr.send(event.target.result);
1813
1913
  };
1814
1914
  reader.readAsArrayBuffer(file);
@@ -1837,7 +1937,7 @@ var FileManager = class {
1837
1937
  }
1838
1938
  buildFilters(params) {
1839
1939
  var _a, _b;
1840
- let filters = {
1940
+ const filters = {
1841
1941
  uploadStatus: "COMPLETED"
1842
1942
  };
1843
1943
  if (((_a = params == null ? void 0 : params.mimeTypes) == null ? void 0 : _a.length) > 0) {
@@ -1875,7 +1975,7 @@ var FileManager = class {
1875
1975
  createAndUpload(fileInfo, progressCallback) {
1876
1976
  return __async(this, null, function* () {
1877
1977
  const { file, id } = fileInfo;
1878
- const { document: document2, errors } = yield this.create({
1978
+ const { document, errors } = yield this.create({
1879
1979
  filename: file.name,
1880
1980
  mime_type: file.type,
1881
1981
  size: file.size
@@ -1891,11 +1991,11 @@ var FileManager = class {
1891
1991
  }
1892
1992
  const result = yield uploadFile(
1893
1993
  file,
1894
- document2,
1994
+ document,
1895
1995
  (state) => progressCallback(id, state)
1896
1996
  );
1897
1997
  if (result) {
1898
- const notify = yield this.notifyUploaded(document2.id);
1998
+ const notify = yield this.notifyUploaded(document.id);
1899
1999
  if (notify.errors) {
1900
2000
  progressCallback(id, {
1901
2001
  type: "errored",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-builder/file-input",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
@@ -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
 
@@ -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,
@@ -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
 
@@ -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) {
@@ -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",
@@ -85,7 +114,7 @@ const FileList = ({
85
114
  key={file.id}
86
115
  className={cn(
87
116
  "r-file-input-file-row",
88
- selected?.id === file.id ? "r-file-input-file-row-active" : "",
117
+ selected?.id === file.id ? "r-file-input-file-row-active" : ""
89
118
  )}
90
119
  onClick={() => onSelect(file.id)}
91
120
  >
@@ -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 ${
@@ -28,11 +28,11 @@ const FilePicker = ({
28
28
  }) => {
29
29
  const allowedFileCategory = React.useMemo(
30
30
  () => sanitizeFileCategory(fileCategory),
31
- [fileCategory],
31
+ [fileCategory]
32
32
  );
33
33
 
34
34
  const [state, setState] = React.useState(
35
- initialState(initialValue, allowedFileCategory),
35
+ initialState(initialValue, allowedFileCategory)
36
36
  );
37
37
 
38
38
  const onFilesUpload = (files) => {
@@ -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}
@@ -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,
@@ -86,19 +86,19 @@ 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
  }
100
- }),
101
- ),
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
+ })
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/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
 
@@ -1,21 +0,0 @@
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)
@@ -1,4 +0,0 @@
1
-
2
- > @raketa-builder/file-input@0.4.0 lint
3
- > biome lint --max-diagnostics=5000 .
4
-