@solidxai/core-ui 0.1.2 → 0.1.3

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.
Files changed (40) hide show
  1. package/dist/components/core/common/SolidGlobalSearchElement.d.ts.map +1 -1
  2. package/dist/components/core/common/SolidGlobalSearchElement.js +51 -27
  3. package/dist/components/core/common/SolidGlobalSearchElement.js.map +1 -1
  4. package/dist/components/core/common/SolidGlobalSearchElement.tsx +85 -22
  5. package/dist/components/core/common/SolidImageViewer.d.ts +10 -0
  6. package/dist/components/core/common/SolidImageViewer.d.ts.map +1 -0
  7. package/dist/components/core/common/SolidImageViewer.js +59 -0
  8. package/dist/components/core/common/SolidImageViewer.js.map +1 -0
  9. package/dist/components/core/common/SolidImageViewer.tsx +84 -0
  10. package/dist/components/core/form/fields/widgets/SolidS3FileViewerWidget.d.ts.map +1 -1
  11. package/dist/components/core/form/fields/widgets/SolidS3FileViewerWidget.js +80 -79
  12. package/dist/components/core/form/fields/widgets/SolidS3FileViewerWidget.js.map +1 -1
  13. package/dist/components/core/form/fields/widgets/SolidS3FileViewerWidget.tsx +92 -85
  14. package/dist/components/core/list/SolidListView.d.ts.map +1 -1
  15. package/dist/components/core/list/SolidListView.js +6 -4
  16. package/dist/components/core/list/SolidListView.js.map +1 -1
  17. package/dist/components/core/list/SolidListView.tsx +6 -4
  18. package/dist/components/core/list/columns/SolidMediaMultipleColumn.d.ts.map +1 -1
  19. package/dist/components/core/list/columns/SolidMediaMultipleColumn.js +16 -17
  20. package/dist/components/core/list/columns/SolidMediaMultipleColumn.js.map +1 -1
  21. package/dist/components/core/list/columns/SolidMediaMultipleColumn.tsx +46 -44
  22. package/dist/components/core/list/columns/SolidMediaSingleColumn.d.ts.map +1 -1
  23. package/dist/components/core/list/columns/SolidMediaSingleColumn.js +6 -4
  24. package/dist/components/core/list/columns/SolidMediaSingleColumn.js.map +1 -1
  25. package/dist/components/core/list/columns/SolidMediaSingleColumn.tsx +7 -5
  26. package/dist/helpers/fetchS3Url.d.ts +19 -0
  27. package/dist/helpers/fetchS3Url.d.ts.map +1 -0
  28. package/dist/helpers/fetchS3Url.js +60 -0
  29. package/dist/helpers/fetchS3Url.js.map +1 -0
  30. package/dist/helpers/fetchS3Url.ts +33 -0
  31. package/dist/index.d.ts +6 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/index.ts +8 -1
  36. package/dist/routes/pages/admin/core/ListPage.d.ts.map +1 -1
  37. package/dist/routes/pages/admin/core/ListPage.js +8 -3
  38. package/dist/routes/pages/admin/core/ListPage.js.map +1 -1
  39. package/dist/routes/pages/admin/core/ListPage.tsx +10 -3
  40. package/package.json +1 -1
@@ -378,8 +378,14 @@ const SavedFilterList = ({ savedfilter, activeSavedFilter, applySavedFilter, ope
378
378
  return (
379
379
  <div className="flex align-items-center justify-content-between gap-2">
380
380
  <div>
381
- <Button text size="small" className="text-base py-1 w-full" severity={Number(activeSavedFilter) == savedfilter.id ? "secondary" : "contrast"} onClick={() => applySavedFilter(savedfilter)}>{savedfilter.name}</Button>
382
- {savedfilter?.description && <p className="text-xs pl-3">{savedfilter?.description}</p>}
381
+ <Button text
382
+ size="small"
383
+ className="text-base py-1 w-full"
384
+ severity={Number(activeSavedFilter) == savedfilter.id ? "secondary" : "contrast"}
385
+ onClick={() => applySavedFilter(savedfilter)}
386
+ tooltip={savedfilter?.description}>{savedfilter.name}
387
+ </Button>
388
+ {/* {savedfilter?.description && <p className="text-xs pl-3">{savedfilter?.description}</p>} */}
383
389
  </div>
384
390
  <div className="flex align-items-center gap-2">
385
391
  <Button
@@ -422,6 +428,57 @@ const replacePlaceholders = (obj: any, searchValue: string): any => {
422
428
  return obj;
423
429
  };
424
430
 
431
+
432
+ const extractChips = (node: any): any[] => {
433
+ if (!node) return [];
434
+
435
+ // If node has $and
436
+ if (node.$and && Array.isArray(node.$and)) {
437
+ return node.$and.flatMap(extractChips);
438
+ }
439
+
440
+ // If node has $or
441
+ if (node.$or && Array.isArray(node.$or)) {
442
+ return node.$or.flatMap(extractChips);
443
+ }
444
+
445
+ // Leaf condition
446
+ const field = Object.keys(node)[0];
447
+ const operatorObj = node[field];
448
+
449
+ // ✅ Normal case
450
+ if (operatorObj?.$containsi) {
451
+ return [{
452
+ columnName: field,
453
+ value: operatorObj.$containsi,
454
+ columnDisplayName: field.charAt(0).toUpperCase() + field.slice(1),
455
+ searchField: field,
456
+ matchMode: "$containsi"
457
+ }];
458
+ }
459
+ // ✅ Nested case (like city.name)
460
+ else if (typeof operatorObj === "object") {
461
+ const nestedField = Object.keys(operatorObj)[0];
462
+ const nestedOperatorObj = operatorObj[nestedField];
463
+
464
+ const operatorKey = nestedOperatorObj
465
+ ? Object.keys(nestedOperatorObj).find(k => k.startsWith("$"))
466
+ : null;
467
+
468
+ if (operatorKey) {
469
+ return [{
470
+ columnName: field,
471
+ value: nestedOperatorObj[operatorKey],
472
+ columnDisplayName: field.charAt(0).toUpperCase() + field.slice(1),
473
+ searchField: `${field}.${nestedField}`,
474
+ matchMode: operatorKey
475
+ }];
476
+ }
477
+ }
478
+
479
+ return [];
480
+ };
481
+
425
482
  type RelationCache = Map<string, { label: string; value: number }>;
426
483
 
427
484
 
@@ -638,16 +695,19 @@ export const SolidGlobalSearchElement = forwardRef(({ viewData, handleApplyCusto
638
695
  }
639
696
  if (searchChips) {
640
697
  setSearchFilter(searchChips);
641
- const formattedChips = searchChips?.$and.map((chip: any, key: any) => {
642
- const chipKey = Object.keys(chip)[0]; // Get the key, e.g., "displayName"
643
- const chipValue = chip[chipKey]?.$containsi; // Get the value of "$containsi"
644
- const chipdata = {
645
- columnName: chipKey,
646
- value: chipValue
647
- };
648
- return chipdata
649
- }
650
- );
698
+ // const formattedChips = searchChips?.$and.map((chip: any, key: any) => {
699
+ // const chipKey = Object.keys(chip)[0]; // Get the key, e.g., "displayName"
700
+ // const chipValue = chip[chipKey]?.$containsi; // Get the value of "$containsi"
701
+ // const chipdata = {
702
+ // columnName: chipKey,
703
+ // value: chipValue
704
+ // };
705
+ // return chipdata
706
+ // }
707
+ // );
708
+ // setSearchChips(formattedChips);
709
+
710
+ const formattedChips = extractChips(searchChips);
651
711
  setSearchChips(formattedChips);
652
712
 
653
713
  }
@@ -680,17 +740,20 @@ export const SolidGlobalSearchElement = forwardRef(({ viewData, handleApplyCusto
680
740
  }
681
741
  if (filterPredicates?.search_predicate && filterPredicates?.search_predicate !== searchFilter) {
682
742
  setSearchFilter(filterPredicates?.search_predicate);
683
- const formattedChips = filterPredicates.search_predicate?.$and.map((chip: any, key: any) => {
684
- const chipKey = Object.keys(chip)[0]; // Get the key, e.g., "displayName"
685
- const chipValue = chip[chipKey]?.$containsi; // Get the value of "$containsi"
686
- const chipdata = {
687
- columnName: chipKey,
688
- value: chipValue
689
- };
690
- return chipdata
691
- }
692
- );
743
+ // const formattedChips = filterPredicates.search_predicate?.$and.map((chip: any, key: any) => {
744
+ // const chipKey = Object.keys(chip)[0]; // Get the key, e.g., "displayName"
745
+ // const chipValue = chip[chipKey]?.$containsi; // Get the value of "$containsi"
746
+ // const chipdata = {
747
+ // columnName: chipKey,
748
+ // value: chipValue
749
+ // };
750
+ // return chipdata
751
+ // }
752
+ // );
753
+ // setSearchChips(formattedChips);
754
+ const formattedChips = extractChips(filterPredicates.search_predicate);
693
755
  setSearchChips(formattedChips);
756
+
694
757
  }
695
758
  }
696
759
  }
@@ -0,0 +1,10 @@
1
+ import Viewer from "viewerjs";
2
+ import "viewerjs/dist/viewer.css";
3
+ export interface SolidImageViewerProps {
4
+ images: string[];
5
+ open: boolean;
6
+ onClose: () => void;
7
+ viewerOptions?: Viewer.Options;
8
+ }
9
+ export declare const SolidImageViewer: ({ images, open, onClose, viewerOptions, }: SolidImageViewerProps) => import("react/jsx-runtime").JSX.Element;
10
+ //# sourceMappingURL=SolidImageViewer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SolidImageViewer.d.ts","sourceRoot":"","sources":["../../../../src/components/core/common/SolidImageViewer.tsx"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,0BAA0B,CAAC;AAElC,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;CAClC;AAED,eAAO,MAAM,gBAAgB,8CAK1B,qBAAqB,4CAmEvB,CAAC"}
@@ -0,0 +1,59 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { useEffect, useRef } from "react";
14
+ import Viewer from "viewerjs";
15
+ import "viewerjs/dist/viewer.css";
16
+ export var SolidImageViewer = function (_a) {
17
+ var images = _a.images, open = _a.open, onClose = _a.onClose, viewerOptions = _a.viewerOptions;
18
+ var containerRef = useRef(null);
19
+ var viewerRef = useRef(null);
20
+ // Initialize viewer
21
+ useEffect(function () {
22
+ if (!containerRef.current || images.length === 0)
23
+ return;
24
+ if (viewerRef.current) {
25
+ viewerRef.current.destroy();
26
+ }
27
+ viewerRef.current = new Viewer(containerRef.current, __assign({ navbar: images.length > 1, title: false, transition: true, movable: true, scalable: true, rotatable: true, zoomable: true, zIndex: 9999, hidden: function () {
28
+ onClose();
29
+ }, toolbar: {
30
+ prev: 1,
31
+ next: 1,
32
+ zoomIn: 1,
33
+ zoomOut: 1,
34
+ rotateLeft: 1,
35
+ rotateRight: 1,
36
+ reset: 1,
37
+ } }, viewerOptions));
38
+ return function () {
39
+ if (viewerRef.current) {
40
+ viewerRef.current.destroy();
41
+ viewerRef.current = null;
42
+ }
43
+ };
44
+ }, [images, open]);
45
+ // Show viewer when open becomes true
46
+ useEffect(function () {
47
+ if (open && viewerRef.current) {
48
+ viewerRef.current.show();
49
+ }
50
+ }, [open]);
51
+ return (_jsx("div", { ref: containerRef, style: {
52
+ position: "absolute",
53
+ visibility: "hidden",
54
+ width: 0,
55
+ height: 0,
56
+ overflow: "hidden",
57
+ }, children: images.map(function (src, index) { return (_jsx("img", { src: src, alt: "preview-".concat(index) }, index)); }) }));
58
+ };
59
+ //# sourceMappingURL=SolidImageViewer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SolidImageViewer.js","sourceRoot":"","sources":["../../../../src/components/core/common/SolidImageViewer.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,0BAA0B,CAAC;AASlC,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAAC,EAKT;QAJpB,MAAM,YAAA,EACN,IAAI,UAAA,EACJ,OAAO,aAAA,EACP,aAAa,mBAAA;IAEb,IAAM,YAAY,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IACzD,IAAM,SAAS,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;IAE9C,oBAAoB;IACpB,SAAS,CAAC;QACN,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAEzD,IAAI,SAAS,CAAC,OAAO,EAAE;YACnB,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;SAC/B;QAED,SAAS,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,OAAO,aAC/C,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,EACzB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,IAAI,EA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"viewerjs\";\nimport \"viewerjs/dist/viewer.css\";\n\nexport interface SolidImageViewerProps {\n images: string[];\n open: boolean;\n onClose: () => void;\n viewerOptions?: Viewer.Options;\n}\n\nexport const SolidImageViewer = ({\n images,\n open,\n onClose,\n viewerOptions,\n}: SolidImageViewerProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null);\n const viewerRef = useRef<Viewer | null>(null);\n\n // Initialize viewer\n useEffect(() => {\n if (!containerRef.current || images.length === 0) return;\n\n if (viewerRef.current) {\n viewerRef.current.destroy();\n }\n\n viewerRef.current = new Viewer(containerRef.current, {\n navbar: images.length > 1, // show navbar only if multiple\n title: false,\n transition: true,\n movable: true,\n scalable: true,\n rotatable: true,\n zoomable: true,\n zIndex: 9999,\n hidden: () => {\n onClose();\n },\n toolbar: {\n prev: 1,\n next: 1,\n zoomIn: 1,\n zoomOut: 1,\n rotateLeft: 1,\n rotateRight: 1,\n reset: 1,\n },\n ...viewerOptions,\n });\n\n return () => {\n if (viewerRef.current) {\n viewerRef.current.destroy();\n viewerRef.current = null;\n }\n };\n }, [images, open]);\n\n // Show viewer when open becomes true\n useEffect(() => {\n if (open && viewerRef.current) {\n viewerRef.current.show();\n }\n }, [open]);\n\n return (\n <div\n ref={containerRef}\n style={{\n position: \"absolute\",\n visibility: \"hidden\",\n width: 0,\n height: 0,\n overflow: \"hidden\",\n }}\n >\n {images.map((src, index) => (\n <img key={index} src={src} alt={`preview-${index}`} />\n ))}\n </div>\n );\n};\n"]}
@@ -0,0 +1,84 @@
1
+ import { useEffect, useRef } from "react";
2
+ import Viewer from "viewerjs";
3
+ import "viewerjs/dist/viewer.css";
4
+
5
+ export interface SolidImageViewerProps {
6
+ images: string[];
7
+ open: boolean;
8
+ onClose: () => void;
9
+ viewerOptions?: Viewer.Options;
10
+ }
11
+
12
+ export const SolidImageViewer = ({
13
+ images,
14
+ open,
15
+ onClose,
16
+ viewerOptions,
17
+ }: SolidImageViewerProps) => {
18
+ const containerRef = useRef<HTMLDivElement | null>(null);
19
+ const viewerRef = useRef<Viewer | null>(null);
20
+
21
+ // Initialize viewer
22
+ useEffect(() => {
23
+ if (!containerRef.current || images.length === 0) return;
24
+
25
+ if (viewerRef.current) {
26
+ viewerRef.current.destroy();
27
+ }
28
+
29
+ viewerRef.current = new Viewer(containerRef.current, {
30
+ navbar: images.length > 1, // show navbar only if multiple
31
+ title: false,
32
+ transition: true,
33
+ movable: true,
34
+ scalable: true,
35
+ rotatable: true,
36
+ zoomable: true,
37
+ zIndex: 9999,
38
+ hidden: () => {
39
+ onClose();
40
+ },
41
+ toolbar: {
42
+ prev: 1,
43
+ next: 1,
44
+ zoomIn: 1,
45
+ zoomOut: 1,
46
+ rotateLeft: 1,
47
+ rotateRight: 1,
48
+ reset: 1,
49
+ },
50
+ ...viewerOptions,
51
+ });
52
+
53
+ return () => {
54
+ if (viewerRef.current) {
55
+ viewerRef.current.destroy();
56
+ viewerRef.current = null;
57
+ }
58
+ };
59
+ }, [images, open]);
60
+
61
+ // Show viewer when open becomes true
62
+ useEffect(() => {
63
+ if (open && viewerRef.current) {
64
+ viewerRef.current.show();
65
+ }
66
+ }, [open]);
67
+
68
+ return (
69
+ <div
70
+ ref={containerRef}
71
+ style={{
72
+ position: "absolute",
73
+ visibility: "hidden",
74
+ width: 0,
75
+ height: 0,
76
+ overflow: "hidden",
77
+ }}
78
+ >
79
+ {images.map((src, index) => (
80
+ <img key={index} src={src} alt={`preview-${index}`} />
81
+ ))}
82
+ </div>
83
+ );
84
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"SolidS3FileViewerWidget.d.ts","sourceRoot":"","sources":["../../../../../../src/components/core/form/fields/widgets/SolidS3FileViewerWidget.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAK5E,OAAO,0BAA0B,CAAC;AAElC;;GAEG;AACH,eAAO,MAAM,uBAAuB,6BAA8B,yBAAyB,4CAiN1F,CAAC"}
1
+ {"version":3,"file":"SolidS3FileViewerWidget.d.ts","sourceRoot":"","sources":["../../../../../../src/components/core/form/fields/widgets/SolidS3FileViewerWidget.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAK5E,OAAO,0BAA0B,CAAC;AAIlC;;GAEG;AACH,eAAO,MAAM,uBAAuB,6BAA8B,yBAAyB,4CAsN1F,CAAC"}
@@ -35,12 +35,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
38
- import { useEffect, useRef, useState } from "react";
38
+ import { useRef, useState } from "react";
39
39
  import { Button } from "primereact/button";
40
40
  import { Dialog } from "primereact/dialog";
41
41
  import { useResolveS3UrlMutation } from "../../../../../redux/api/fieldApi";
42
- import Viewer from "viewerjs";
43
42
  import "viewerjs/dist/viewer.css";
43
+ import { SolidImageViewer } from "../../../../../components/core/common/SolidImageViewer";
44
+ import { fetchS3Url } from "../../../../..//helpers/fetchS3Url";
44
45
  /**
45
46
  * SolidS3FileViewerWidget (PrimeReact version)
46
47
  */
@@ -63,39 +64,24 @@ export var SolidS3FileViewerWidget = function (_a) {
63
64
  var _f = useState(false), open = _f[0], setOpen = _f[1];
64
65
  var _g = useState(false), shouldShowViewer = _g[0], setShouldShowViewer = _g[1];
65
66
  var resolveS3Url = useResolveS3UrlMutation()[0];
66
- var fetchS3Url = function () { return __awaiter(void 0, void 0, void 0, function () {
67
- var result, e_1;
67
+ var resolveFileUrl = function () { return __awaiter(void 0, void 0, void 0, function () {
68
+ var options, url;
68
69
  return __generator(this, function (_a) {
69
70
  switch (_a.label) {
70
71
  case 0:
71
- console.log("fetch url called");
72
72
  setIsLoading(true);
73
- _a.label = 1;
73
+ options = {
74
+ s3Key: value,
75
+ fileType: fileType,
76
+ bucketName: bucketName,
77
+ mediaStorageProviderUserKey: mediaStorageProviderUserKey,
78
+ isPrivate: isPrivate
79
+ };
80
+ return [4 /*yield*/, fetchS3Url(resolveS3Url, options)];
74
81
  case 1:
75
- _a.trys.push([1, 3, , 4]);
76
- return [4 /*yield*/, resolveS3Url({
77
- modelName: fieldContext.modelName,
78
- fieldName: fieldContext.fieldMetadata.name,
79
- s3Key: value,
80
- fileType: fileType,
81
- bucketName: bucketName,
82
- mediaStorageProviderUserKey: mediaStorageProviderUserKey,
83
- isPrivate: isPrivate
84
- }).unwrap()];
85
- case 2:
86
- result = _a.sent();
87
- setIsLoading(false);
88
- if (result.statusCode == "200") {
89
- console.log("fetch url success", result.data.url);
90
- return [2 /*return*/, result.data.url];
91
- }
92
- return [3 /*break*/, 4];
93
- case 3:
94
- e_1 = _a.sent();
95
- console.error("Failed to resolve S3 URL:", e_1);
82
+ url = _a.sent();
96
83
  setIsLoading(false);
97
- return [2 /*return*/, null];
98
- case 4: return [2 /*return*/];
84
+ return [2 /*return*/, url];
99
85
  }
100
86
  });
101
87
  }); };
@@ -106,7 +92,7 @@ export var SolidS3FileViewerWidget = function (_a) {
106
92
  case 0:
107
93
  if (isLoading)
108
94
  return [2 /*return*/];
109
- return [4 /*yield*/, fetchS3Url()];
95
+ return [4 /*yield*/, resolveFileUrl()];
110
96
  case 1:
111
97
  url = _a.sent();
112
98
  if (!url)
@@ -129,7 +115,7 @@ export var SolidS3FileViewerWidget = function (_a) {
129
115
  console.log("isLoading in view", isLoading);
130
116
  if (isLoading)
131
117
  return [2 /*return*/];
132
- return [4 /*yield*/, fetchS3Url()];
118
+ return [4 /*yield*/, resolveFileUrl()];
133
119
  case 1:
134
120
  url = _a.sent();
135
121
  console.log("url after fetch success", url);
@@ -151,55 +137,70 @@ export var SolidS3FileViewerWidget = function (_a) {
151
137
  var isPDF = fileType === "pdf";
152
138
  var isDownloadOnly = ["xlsx", "xls", "csv", "doc", "docx"].includes(fileType);
153
139
  // 🔹 Initialize Viewer.js once image exists
154
- useEffect(function () {
155
- if (imageRef.current && previewUrl && isImage) {
156
- // Destroy existing viewer if any
157
- if (viewerRef.current) {
158
- viewerRef.current.destroy();
159
- }
160
- // Create new viewer instance
161
- viewerRef.current = new Viewer(imageRef.current, {
162
- toolbar: {
163
- zoomIn: 1,
164
- zoomOut: 1,
165
- rotateLeft: 1,
166
- rotateRight: 1,
167
- reset: 1,
168
- },
169
- navbar: false,
170
- title: false,
171
- transition: true,
172
- movable: true,
173
- scalable: true,
174
- rotatable: true,
175
- zoomable: true,
176
- zIndex: 9999,
177
- // Add hidden event to reset state
178
- hidden: function () {
179
- setShouldShowViewer(false);
180
- }
181
- });
182
- console.log("Viewer initialized");
183
- }
184
- return function () {
185
- if (viewerRef.current) {
186
- viewerRef.current.destroy();
187
- viewerRef.current = null;
188
- }
189
- };
190
- }, [previewUrl, isImage]);
140
+ // useEffect(() => {
141
+ // if (imageRef.current && previewUrl && isImage) {
142
+ // // Destroy existing viewer if any
143
+ // if (viewerRef.current) {
144
+ // viewerRef.current.destroy();
145
+ // }
146
+ // // Create new viewer instance
147
+ // viewerRef.current = new Viewer(imageRef.current, {
148
+ // toolbar: {
149
+ // zoomIn: 1,
150
+ // zoomOut: 1,
151
+ // rotateLeft: 1,
152
+ // rotateRight: 1,
153
+ // reset: 1,
154
+ // },
155
+ // navbar: false,
156
+ // title: false,
157
+ // transition: true,
158
+ // movable: true,
159
+ // scalable: true,
160
+ // rotatable: true,
161
+ // zoomable: true,
162
+ // zIndex: 9999,
163
+ // // Add hidden event to reset state
164
+ // hidden: () => {
165
+ // setShouldShowViewer(false);
166
+ // }
167
+ // });
168
+ // console.log("Viewer initialized");
169
+ // }
170
+ // return () => {
171
+ // if (viewerRef.current) {
172
+ // viewerRef.current.destroy();
173
+ // viewerRef.current = null;
174
+ // }
175
+ // };
176
+ // }, [previewUrl, isImage]);
191
177
  // 🔹 Show viewer when shouldShowViewer becomes true
192
- useEffect(function () {
193
- if (shouldShowViewer && viewerRef.current) {
194
- console.log("Showing viewer");
195
- viewerRef.current.show();
196
- }
197
- }, [shouldShowViewer]);
198
- return (_jsxs("div", { className: "mt-2 flex flex-col gap-2", children: [_jsx("p", { className: "m-0 form-field-label font-medium", children: fieldLabel }), value ? (_jsxs("div", { className: "flex gap-3 items-center", children: [(isImage || isPDF) && (_jsx(Button, { icon: "pi pi-eye", type: "button", style: { minWidth: 66 }, loading: isLoading, tooltip: value, disabled: isLoading, label: "View ".concat(fileType), size: "small", iconPos: "left", onClick: handleView })), downloadAllowed && (_jsx(Button, { size: "small", type: "button", icon: "pi pi-download", tooltip: "Download ".concat(value === null || value === void 0 ? void 0 : value.split("/").pop()), loading: isLoading, onClick: handleDownload, disabled: isLoading, className: 'solid-icon-button' }))] })) : (_jsx("p", { className: "text-sm text-muted-foreground", children: "No file uploaded" })), isImage && previewUrl && (_jsx("img", { ref: imageRef, src: previewUrl, alt: value, style: {
199
- position: "absolute",
200
- visibility: "hidden",
201
- width: "1px",
202
- height: "1px"
178
+ // useEffect(() => {
179
+ // if (shouldShowViewer && viewerRef.current) {
180
+ // console.log("Showing viewer");
181
+ // viewerRef.current.show();
182
+ // }
183
+ // }, [shouldShowViewer]);
184
+ return (_jsxs("div", { className: "mt-2 flex flex-col gap-2", children: [_jsx("p", { className: "m-0 form-field-label font-medium", children: fieldLabel }), value ? (_jsxs("div", { className: "flex gap-3 items-center", children: [(isImage || isPDF) && (_jsx(Button, { icon: "pi pi-eye", type: "button", style: { minWidth: 66 }, loading: isLoading, tooltip: value, disabled: isLoading, label: "View ".concat(fileType), size: "small", iconPos: "left", onClick: handleView })), downloadAllowed && (_jsx(Button, { size: "small", type: "button", icon: "pi pi-download", tooltip: "Download ".concat(value === null || value === void 0 ? void 0 : value.split("/").pop()), loading: isLoading, onClick: handleDownload, disabled: isLoading, className: 'solid-icon-button' }))] })) : (_jsx("p", { className: "text-sm text-muted-foreground", children: "No file uploaded" })), isImage && previewUrl && (
185
+ // <img
186
+ // ref={imageRef}
187
+ // src={previewUrl}
188
+ // alt={value}
189
+ // style={{
190
+ // position: "absolute",
191
+ // visibility: "hidden",
192
+ // width: "1px",
193
+ // height: "1px"
194
+ // }}
195
+ // />
196
+ _jsx(SolidImageViewer, { images: [previewUrl], open: shouldShowViewer, onClose: function () { return setShouldShowViewer(false); }, viewerOptions: {
197
+ toolbar: {
198
+ zoomIn: 1,
199
+ zoomOut: 1,
200
+ rotateLeft: 1,
201
+ rotateRight: 1,
202
+ reset: 1,
203
+ },
203
204
  } })), _jsx(Dialog, { header: value, visible: open, modal: true, style: { width: "80vw", maxHeight: "90vh" }, onHide: function () { return setOpen(false); }, headerClassName: 'p-1 form-wrapper-title', contentClassName: 'p-0', contentStyle: { borderRadius: 6 }, children: previewUrl && isPDF && (_jsx("div", { style: {
204
205
  width: "100%",
205
206
  height: "75vh",
@@ -1 +1 @@
1
- {"version":3,"file":"SolidS3FileViewerWidget.js","sourceRoot":"","sources":["../../../../../../src/components/core/form/fields/widgets/SolidS3FileViewerWidget.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,0BAA0B,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,IAAM,uBAAuB,GAAG,UAAC,EAAmD;;QAAjD,MAAM,YAAA,EAAE,YAAY,kBAAA;IAC1D,IAAM,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC;IACjD,IAAM,eAAe,GAAG,YAAY,CAAC,KAAK,CAAC;IAC3C,IAAM,UAAU,GAAG,MAAA,eAAe,CAAC,KAAK,CAAC,KAAK,mCAAI,aAAa,CAAC,WAAW,CAAC;IAC5E,IAAM,KAAK,GAAG,MAAM,CAAC,MAAM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ACT,CAAC;AACN,CAAC,CAAC","sourcesContent":["\nimport { useEffect, useRef, useState } from \"react\";\nimport { SolidFormFieldWidgetProps } from \"../../../../../types/solid-core\";\nimport { Button } from \"primereact/button\";\nimport { Dialog } from \"primereact/dialog\";\nimport { useResolveS3UrlMutation } from \"../../../../../redux/api/fieldApi\";\nimport Viewer from \"viewerjs\";\nimport \"viewerjs/dist/viewer.css\";\n\n/**\n * SolidS3FileViewerWidget (PrimeReact version)\n */\nexport const SolidS3FileViewerWidget = ({ formik, fieldContext }: SolidFormFieldWidgetProps) => {\n const fieldMetadata = fieldContext.fieldMetadata;\n const fieldLayoutInfo = fieldContext.field;\n const fieldLabel = fieldLayoutInfo.attrs.label ?? fieldMetadata.displayName;\n const value = formik.values[fieldLayoutInfo.attrs.name];\n const fileType = fieldLayoutInfo.attrs.fileType?.toLowerCase();\n const downloadAllowed = fieldLayoutInfo.attrs.downloadAllowed !== false;\n const bucketName = fieldLayoutInfo.attrs.bucketName;\n const mediaStorageProviderUserKey = fieldLayoutInfo.attrs.mediaStorageProviderUserKey;\n const isPrivate = fieldLayoutInfo.attrs.isPrivate ? fieldLayoutInfo.attrs.isPrivate : \"false\";\n\n const imageRef = useRef<HTMLImageElement | null>(null);\n const viewerRef = useRef<Viewer | null>(null);\n\n const [previewUrl, setPreviewUrl] = useState<string>(\"\");\n const [isLoading, setIsLoading] = useState(false);\n const [open, setOpen] = useState(false);\n const [shouldShowViewer, setShouldShowViewer] = useState(false);\n\n const [resolveS3Url] = useResolveS3UrlMutation();\n\n const fetchS3Url = async () => {\n console.log(\"fetch url called\");\n setIsLoading(true);\n try {\n const result = await resolveS3Url({\n modelName: fieldContext.modelName,\n fieldName: fieldContext.fieldMetadata.name,\n s3Key: value,\n fileType: fileType,\n bucketName: bucketName,\n mediaStorageProviderUserKey: mediaStorageProviderUserKey,\n isPrivate: isPrivate\n }).unwrap();\n\n setIsLoading(false);\n if (result.statusCode == \"200\") {\n console.log(\"fetch url success\", result.data.url);\n return result.data.url;\n }\n } catch (e) {\n console.error(\"Failed to resolve S3 URL:\", e);\n setIsLoading(false);\n return null;\n }\n };\n\n const handleDownload = async () => {\n if (isLoading) return;\n const url = await fetchS3Url();\n if (!url) return;\n const a = document.createElement(\"a\");\n a.href = url;\n a.download = value?.split(\"/\").pop() || \"file\";\n a.target = \"_blank\";\n a.rel = \"noopener noreferrer\";\n a.click();\n };\n\n const handleView = async () => {\n console.log(\"isLoading in view\", isLoading);\n if (isLoading) return;\n \n const url = await fetchS3Url();\n console.log(\"url after fetch success\", url);\n if (!url) return;\n \n setPreviewUrl(url);\n \n if (isImage) {\n // Trigger viewer to show after state update\n setShouldShowViewer(true);\n } else {\n setOpen(true);\n }\n };\n\n const isImage = [\"jpeg\", \"jpg\", \"png\", \"gif\", \"webp\"].includes(fileType);\n const isPDF = fileType === \"pdf\";\n const isDownloadOnly = [\"xlsx\", \"xls\", \"csv\", \"doc\", \"docx\"].includes(fileType);\n\n // 🔹 Initialize Viewer.js once image exists\n useEffect(() => {\n if (imageRef.current && previewUrl && isImage) {\n // Destroy existing viewer if any\n if (viewerRef.current) {\n viewerRef.current.destroy();\n }\n\n // Create new viewer instance\n viewerRef.current = new Viewer(imageRef.current, {\n toolbar: {\n zoomIn: 1,\n zoomOut: 1,\n rotateLeft: 1,\n rotateRight: 1,\n reset: 1,\n },\n navbar: false,\n title: false,\n transition: true,\n movable: true,\n scalable: true,\n rotatable: true,\n zoomable: true,\n zIndex:9999,\n // Add hidden event to reset state\n hidden: () => {\n setShouldShowViewer(false);\n }\n });\n\n console.log(\"Viewer initialized\");\n }\n\n return () => {\n if (viewerRef.current) {\n viewerRef.current.destroy();\n viewerRef.current = null;\n }\n };\n }, [previewUrl, isImage]);\n\n // 🔹 Show viewer when shouldShowViewer becomes true\n useEffect(() => {\n if (shouldShowViewer && viewerRef.current) {\n console.log(\"Showing viewer\");\n viewerRef.current.show();\n }\n }, [shouldShowViewer]);\n\n return (\n <div className=\"mt-2 flex flex-col gap-2\">\n <p className=\"m-0 form-field-label font-medium\">{fieldLabel}</p>\n\n {value ? (\n <div className=\"flex gap-3 items-center\">\n {(isImage || isPDF) && (\n <Button\n icon=\"pi pi-eye\"\n type=\"button\"\n style={{ minWidth: 66 }}\n loading={isLoading}\n tooltip={value}\n disabled={isLoading}\n label={`View ${fileType}`}\n size=\"small\"\n iconPos=\"left\"\n onClick={handleView}\n />\n )}\n {downloadAllowed && (\n <Button\n size=\"small\"\n type=\"button\"\n icon=\"pi pi-download\"\n tooltip={`Download ${value?.split(\"/\").pop()}`}\n loading={isLoading}\n onClick={handleDownload}\n disabled={isLoading}\n className='solid-icon-button' />\n )}\n </div>\n ) : (\n <p className=\"text-sm text-muted-foreground\">No file uploaded</p>\n )}\n\n {/* Hidden image for Viewer.js - keep visibility hidden instead of display none */}\n {isImage && previewUrl && (\n <img\n ref={imageRef}\n src={previewUrl}\n alt={value}\n style={{ \n position: \"absolute\",\n visibility: \"hidden\",\n width: \"1px\",\n height: \"1px\"\n }}\n />\n )}\n\n <Dialog\n header={value}\n visible={open}\n modal\n style={{ width: \"80vw\", maxHeight: \"90vh\" }}\n onHide={() => setOpen(false)}\n headerClassName='p-1 form-wrapper-title'\n contentClassName='p-0'\n contentStyle={{ borderRadius: 6 }}\n >\n {previewUrl && isPDF && (\n <div\n style={{\n width: \"100%\",\n height: \"75vh\",\n overflow: \"hidden\",\n }}\n >\n <iframe\n src={previewUrl}\n style={{ width: \"100%\", height: \"100%\", border: \"none\" }}\n />\n </div>\n )}\n </Dialog>\n </div>\n );\n};"]}
1
+ {"version":3,"file":"SolidS3FileViewerWidget.js","sourceRoot":"","sources":["../../../../../../src/components/core/form/fields/widgets/SolidS3FileViewerWidget.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C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AAuB;YACvB,kBAAkB;YAClB,eAAe;YACf,gCAAgC;YAChC,gCAAgC;YAChC,wBAAwB;YACxB,wBAAwB;YACxB,SAAS;YACT,KAAK;YACL,KAAC,gBAAgB,IACb,MAAM,EAAE,CAAC,UAAU,CAAC,EACpB,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,cAAM,OAAA,mBAAmB,CAAC,KAAK,CAAC,EAA1B,CAA0B,EACzC,aAAa,EAAE;oBACX,OAAO,EAAE;wBACL,MAAM,EAAE,CAAC;wBACT,OAAO,EAAE,CAAC;wBACV,UAAU,EAAE,CAAC;wBACb,WAAW,EAAE,CAAC;wBACd,KAAK,EAAE,CAAC;qBACX;iBACJ,GACH,CAEL,EAED,KAAC,MAAM,IACH,MAAM,EAAE,KAAK,EACb,OAAO,EAAE,IAAI,EACb,KAAK,QACL,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAC3C,MAAM,EAAE,cAAM,OAAA,OAAO,CAAC,KAAK,CAAC,EAAd,CAAc,EAC5B,eAAe,EAAC,wBAAwB,EACxC,gBAAgB,EAAC,KAAK,EACtB,YAAY,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,YAEhC,UAAU,IAAI,KAAK,IAAI,CACpB,cACI,KAAK,EAAE;wBACH,KAAK,EAAE,MAAM;wBACb,MAAM,EAAE,MAAM;wBACd,QAAQ,EAAE,QAAQ;qBACrB,YAED,iBACI,GAAG,EAAE,UAAU,EACf,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAC1D,GACA,CACT,GACI,IACP,CACT,CAAC;AACN,CAAC,CAAC","sourcesContent":["\nimport { useRef, useState } from \"react\";\nimport { SolidFormFieldWidgetProps } from \"../../../../../types/solid-core\";\nimport { Button } from \"primereact/button\";\nimport { Dialog } from \"primereact/dialog\";\nimport { useResolveS3UrlMutation } from \"../../../../../redux/api/fieldApi\";\nimport Viewer from \"viewerjs\";\nimport \"viewerjs/dist/viewer.css\";\nimport { SolidImageViewer } from \"../../../../../components/core/common/SolidImageViewer\";\nimport { fetchS3Url, type FetchS3UrlOptions } from \"../../../../..//helpers/fetchS3Url\";\n\n/**\n * SolidS3FileViewerWidget (PrimeReact version)\n */\nexport const SolidS3FileViewerWidget = ({ formik, fieldContext }: SolidFormFieldWidgetProps) => {\n const fieldMetadata = fieldContext.fieldMetadata;\n const fieldLayoutInfo = fieldContext.field;\n const fieldLabel = fieldLayoutInfo.attrs.label ?? fieldMetadata.displayName;\n const value = formik.values[fieldLayoutInfo.attrs.name];\n const fileType = fieldLayoutInfo.attrs.fileType?.toLowerCase();\n const downloadAllowed = fieldLayoutInfo.attrs.downloadAllowed !== false;\n const bucketName = fieldLayoutInfo.attrs.bucketName;\n const mediaStorageProviderUserKey = fieldLayoutInfo.attrs.mediaStorageProviderUserKey;\n const isPrivate = fieldLayoutInfo.attrs.isPrivate ? fieldLayoutInfo.attrs.isPrivate : \"false\";\n\n const imageRef = useRef<HTMLImageElement | null>(null);\n const viewerRef = useRef<Viewer | null>(null);\n\n const [previewUrl, setPreviewUrl] = useState<string>(\"\");\n const [isLoading, setIsLoading] = useState(false);\n const [open, setOpen] = useState(false);\n const [shouldShowViewer, setShouldShowViewer] = useState(false);\n\n const [resolveS3Url] = useResolveS3UrlMutation();\n\n const resolveFileUrl = async () => {\n setIsLoading(true);\n\n const options: FetchS3UrlOptions = {\n s3Key: value,\n fileType: fileType,\n bucketName: bucketName,\n mediaStorageProviderUserKey: mediaStorageProviderUserKey,\n isPrivate: isPrivate\n };\n\n const url = await fetchS3Url(resolveS3Url, options);\n setIsLoading(false);\n return url;\n };\n\n const handleDownload = async () => {\n if (isLoading) return;\n const url = await resolveFileUrl();\n if (!url) return;\n const a = document.createElement(\"a\");\n a.href = url;\n a.download = value?.split(\"/\").pop() || \"file\";\n a.target = \"_blank\";\n a.rel = \"noopener noreferrer\";\n a.click();\n };\n\n const handleView = async () => {\n console.log(\"isLoading in view\", isLoading);\n if (isLoading) return;\n\n const url = await resolveFileUrl();\n console.log(\"url after fetch success\", url);\n if (!url) return;\n\n setPreviewUrl(url);\n\n if (isImage) {\n // Trigger viewer to show after state update\n setShouldShowViewer(true);\n } else {\n setOpen(true);\n }\n };\n\n const isImage = [\"jpeg\", \"jpg\", \"png\", \"gif\", \"webp\"].includes(fileType);\n const isPDF = fileType === \"pdf\";\n const isDownloadOnly = [\"xlsx\", \"xls\", \"csv\", \"doc\", \"docx\"].includes(fileType);\n\n // 🔹 Initialize Viewer.js once image exists\n // useEffect(() => {\n // if (imageRef.current && previewUrl && isImage) {\n // // Destroy existing viewer if any\n // if (viewerRef.current) {\n // viewerRef.current.destroy();\n // }\n\n // // Create new viewer instance\n // viewerRef.current = new Viewer(imageRef.current, {\n // toolbar: {\n // zoomIn: 1,\n // zoomOut: 1,\n // rotateLeft: 1,\n // rotateRight: 1,\n // reset: 1,\n // },\n // navbar: false,\n // title: false,\n // transition: true,\n // movable: true,\n // scalable: true,\n // rotatable: true,\n // zoomable: true,\n // zIndex: 9999,\n // // Add hidden event to reset state\n // hidden: () => {\n // setShouldShowViewer(false);\n // }\n // });\n\n // console.log(\"Viewer initialized\");\n // }\n\n // return () => {\n // if (viewerRef.current) {\n // viewerRef.current.destroy();\n // viewerRef.current = null;\n // }\n // };\n // }, [previewUrl, isImage]);\n\n // 🔹 Show viewer when shouldShowViewer becomes true\n // useEffect(() => {\n // if (shouldShowViewer && viewerRef.current) {\n // console.log(\"Showing viewer\");\n // viewerRef.current.show();\n // }\n // }, [shouldShowViewer]);\n\n return (\n <div className=\"mt-2 flex flex-col gap-2\">\n <p className=\"m-0 form-field-label font-medium\">{fieldLabel}</p>\n\n {value ? (\n <div className=\"flex gap-3 items-center\">\n {(isImage || isPDF) && (\n <Button\n icon=\"pi pi-eye\"\n type=\"button\"\n style={{ minWidth: 66 }}\n loading={isLoading}\n tooltip={value}\n disabled={isLoading}\n label={`View ${fileType}`}\n size=\"small\"\n iconPos=\"left\"\n onClick={handleView}\n />\n )}\n {downloadAllowed && (\n <Button\n size=\"small\"\n type=\"button\"\n icon=\"pi pi-download\"\n tooltip={`Download ${value?.split(\"/\").pop()}`}\n loading={isLoading}\n onClick={handleDownload}\n disabled={isLoading}\n className='solid-icon-button' />\n )}\n </div>\n ) : (\n <p className=\"text-sm text-muted-foreground\">No file uploaded</p>\n )}\n\n {/* Hidden image for Viewer.js - keep visibility hidden instead of display none */}\n {isImage && previewUrl && (\n // <img\n // ref={imageRef}\n // src={previewUrl}\n // alt={value}\n // style={{\n // position: \"absolute\",\n // visibility: \"hidden\",\n // width: \"1px\",\n // height: \"1px\"\n // }}\n // />\n <SolidImageViewer\n images={[previewUrl]}\n open={shouldShowViewer}\n onClose={() => setShouldShowViewer(false)}\n viewerOptions={{\n toolbar: {\n zoomIn: 1,\n zoomOut: 1,\n rotateLeft: 1,\n rotateRight: 1,\n reset: 1,\n },\n }}\n />\n\n )}\n\n <Dialog\n header={value}\n visible={open}\n modal\n style={{ width: \"80vw\", maxHeight: \"90vh\" }}\n onHide={() => setOpen(false)}\n headerClassName='p-1 form-wrapper-title'\n contentClassName='p-0'\n contentStyle={{ borderRadius: 6 }}\n >\n {previewUrl && isPDF && (\n <div\n style={{\n width: \"100%\",\n height: \"75vh\",\n overflow: \"hidden\",\n }}\n >\n <iframe\n src={previewUrl}\n style={{ width: \"100%\", height: \"100%\", border: \"none\" }}\n />\n </div>\n )}\n </Dialog>\n </div>\n );\n};\n"]}