@instincthub/react-ui 0.3.0 → 0.3.2

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 (31) hide show
  1. package/dist/src/assets/css/navbar/sidenav.css +293 -0
  2. package/dist/src/components/forms/uploads/FileUploader.cjs +1 -1
  3. package/dist/src/components/forms/uploads/FileUploader.js +1 -1
  4. package/dist/src/components/forms/uploads/IhubFileUploader.cjs +1 -1
  5. package/dist/src/components/forms/uploads/IhubFileUploader.js +1 -1
  6. package/dist/src/components/forms/uploads/uploadedFileUrl.cjs +2 -0
  7. package/dist/src/components/forms/uploads/uploadedFileUrl.cjs.map +1 -0
  8. package/dist/src/components/forms/uploads/uploadedFileUrl.js +2 -0
  9. package/dist/src/components/forms/uploads/uploadedFileUrl.js.map +1 -0
  10. package/dist/src/components/navbar/SideNavSearch.cjs +2 -0
  11. package/dist/src/components/navbar/SideNavSearch.cjs.map +1 -0
  12. package/dist/src/components/navbar/SideNavSearch.js +2 -0
  13. package/dist/src/components/navbar/SideNavSearch.js.map +1 -0
  14. package/dist/src/components/navbar/SideNavbar.cjs +1 -1
  15. package/dist/src/components/navbar/SideNavbar.js +1 -1
  16. package/dist/src/components/navbar/sideNavMatch.cjs +2 -0
  17. package/dist/src/components/navbar/sideNavMatch.cjs.map +1 -0
  18. package/dist/src/components/navbar/sideNavMatch.js +2 -0
  19. package/dist/src/components/navbar/sideNavMatch.js.map +1 -0
  20. package/dist/src/components/navbar/useRevealActiveRow.cjs +2 -0
  21. package/dist/src/components/navbar/useRevealActiveRow.cjs.map +1 -0
  22. package/dist/src/components/navbar/useRevealActiveRow.js +2 -0
  23. package/dist/src/components/navbar/useRevealActiveRow.js.map +1 -0
  24. package/dist/src/types/components/forms/uploads/uploadedFileUrl.d.ts +17 -0
  25. package/dist/src/types/components/navbar/SideNavSearch.d.ts +27 -0
  26. package/dist/src/types/components/navbar/SideNavbar.d.ts +1 -1
  27. package/dist/src/types/components/navbar/sideNavMatch.d.ts +65 -0
  28. package/dist/src/types/components/navbar/useRevealActiveRow.d.ts +12 -0
  29. package/dist/src/types/types/navbar.d.ts +44 -1
  30. package/dist/tsconfig.build.tsbuildinfo +1 -1
  31. package/package.json +2 -1
@@ -305,6 +305,16 @@
305
305
  background-color: rgba(0, 0, 0, 0.05);
306
306
  }
307
307
 
308
+ /* main.css colours every bare span and svg (`span, i, li` and `time, svg`
309
+ get var(--Gunmetal)), which beat the row's own colour: labels, icons and
310
+ section headings stayed Gunmetal on the dark sidebar's Gunmetal
311
+ background, and active rows never turned DarkCyan. Inside the sidebar they
312
+ follow their parent instead. One class of specificity, and early in the
313
+ file, so every sidebar rule below that sets a colour still wins. */
314
+ .ihub-sidenav :where(span, svg) {
315
+ color: inherit;
316
+ }
317
+
308
318
  .ihub-sidenav-active {
309
319
  background-color: rgba(0, 131, 143, 0.1);
310
320
  color: var(--DarkCyan, #00838f);
@@ -681,3 +691,286 @@
681
691
  opacity: 1;
682
692
  }
683
693
  }
694
+
695
+ /* ---- Search ---- */
696
+ .ihub-sidenav-search {
697
+ padding: 12px 12px 6px;
698
+ }
699
+
700
+ .ihub-sidenav-search-box {
701
+ display: flex;
702
+ justify-content: flex-start;
703
+ align-items: center;
704
+ gap: 8px;
705
+ height: 38px;
706
+ padding: 0 10px;
707
+ border: 1px solid var(--crm-border, rgba(44, 51, 58, 0.15));
708
+ border-radius: 10px;
709
+ background: var(--Magnolia, #f4f3fe);
710
+ color: var(--Rhythm, #69779b);
711
+ transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
712
+ }
713
+
714
+ .ihub-sidenav-search-box:focus-within {
715
+ border-color: var(--DarkCyan, #00838f);
716
+ background: var(--White, #ffffff);
717
+ box-shadow: 0 0 0 3px rgba(0, 131, 143, 0.12);
718
+ }
719
+
720
+ .ihub-sidenav-search-box svg {
721
+ font-size: 18px;
722
+ flex-shrink: 0;
723
+ }
724
+
725
+ .ihub-sidenav-search-input {
726
+ flex: 1;
727
+ min-width: 0;
728
+ height: 100%;
729
+ padding: 0;
730
+ border: none;
731
+ outline: none;
732
+ background: transparent;
733
+ color: var(--Gunmetal, #2c333a);
734
+ font-size: 14px;
735
+ }
736
+
737
+ .ihub-sidenav-search-input::placeholder {
738
+ color: var(--Rhythm, #69779b);
739
+ }
740
+
741
+ .ihub-sidenav-search-input::-webkit-search-cancel-button {
742
+ display: none;
743
+ }
744
+
745
+ .ihub-sidenav-kbd {
746
+ display: inline-flex;
747
+ align-items: center;
748
+ justify-content: center;
749
+ min-width: 20px;
750
+ height: 20px;
751
+ padding: 0 5px;
752
+ border: 1px solid var(--crm-border, rgba(44, 51, 58, 0.2));
753
+ border-bottom-width: 2px;
754
+ border-radius: 5px;
755
+ background: var(--White, #ffffff);
756
+ color: var(--Rhythm, #69779b);
757
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
758
+ font-size: 11px;
759
+ line-height: 1;
760
+ }
761
+
762
+ .ihub-sidenav-search-clear {
763
+ display: inline-flex;
764
+ align-items: center;
765
+ justify-content: center;
766
+ width: 22px;
767
+ height: 22px;
768
+ padding: 0;
769
+ border: none;
770
+ border-radius: 999px;
771
+ background: rgba(125, 124, 124, 0.12);
772
+ color: var(--Rhythm, #69779b);
773
+ cursor: pointer;
774
+ }
775
+
776
+ .ihub-sidenav-search-clear svg {
777
+ font-size: 14px;
778
+ }
779
+
780
+ .ihub-sidenav-results {
781
+ list-style: none;
782
+ margin: 0;
783
+ padding: 0 0 8px;
784
+ }
785
+
786
+ .ihub-sidenav-results-meta {
787
+ padding: 4px 16px 6px;
788
+ font-size: 11px;
789
+ color: var(--Rhythm, #69779b);
790
+ }
791
+
792
+ .ihub-sidenav-result {
793
+ align-items: flex-start;
794
+ white-space: normal;
795
+ }
796
+
797
+ .ihub-sidenav-result[aria-selected="true"] {
798
+ background-color: rgba(0, 0, 0, 0.05);
799
+ box-shadow: inset 3px 0 0 var(--DarkCyan, #00838f);
800
+ }
801
+
802
+ .ihub-sidenav-result-text {
803
+ display: flex;
804
+ flex-direction: column;
805
+ min-width: 0;
806
+ }
807
+
808
+ .ihub-sidenav-result-title mark {
809
+ background: rgba(0, 131, 143, 0.12);
810
+ color: var(--DarkCyan, #00838f);
811
+ font-weight: 600;
812
+ border-radius: 3px;
813
+ padding: 0 1px;
814
+ }
815
+
816
+ .ihub-sidenav-result-trail {
817
+ font-size: 11.5px;
818
+ color: var(--Rhythm, #69779b);
819
+ overflow: hidden;
820
+ text-overflow: ellipsis;
821
+ white-space: nowrap;
822
+ }
823
+
824
+ .ihub-sidenav-search-empty {
825
+ display: flex;
826
+ flex-direction: column;
827
+ align-items: center;
828
+ gap: 6px;
829
+ padding: 28px 16px;
830
+ text-align: center;
831
+ font-size: 13px;
832
+ color: var(--Rhythm, #69779b);
833
+ }
834
+
835
+ .ihub-sidenav-search-empty-icon {
836
+ display: flex;
837
+ align-items: center;
838
+ justify-content: center;
839
+ width: 40px;
840
+ height: 40px;
841
+ border-radius: 12px;
842
+ background: rgba(125, 124, 124, 0.12);
843
+ }
844
+
845
+ .ihub-sidenav-search-empty strong {
846
+ color: var(--Gunmetal, #2c333a);
847
+ word-break: break-word;
848
+ }
849
+
850
+ /* ---- Sections ---- */
851
+ .ihub-sidenav-section + .ihub-sidenav-section {
852
+ margin-top: 8px;
853
+ padding-top: 8px;
854
+ border-top: 1px dashed var(--crm-border, rgba(44, 51, 58, 0.15));
855
+ }
856
+
857
+ .ihub-sidenav-section-head {
858
+ display: flex;
859
+ justify-content: flex-start;
860
+ align-items: center;
861
+ gap: 6px;
862
+ width: 100%;
863
+ padding: 6px 16px;
864
+ border: none;
865
+ background: transparent;
866
+ color: var(--Rhythm, #69779b);
867
+ font-size: 11px;
868
+ font-weight: 600;
869
+ letter-spacing: 0.08em;
870
+ text-transform: uppercase;
871
+ text-align: left;
872
+ cursor: pointer;
873
+ }
874
+
875
+ .ihub-sidenav-section-head:hover {
876
+ color: var(--Gunmetal, #2c333a);
877
+ }
878
+
879
+ .ihub-sidenav-section-head-static {
880
+ cursor: default;
881
+ }
882
+
883
+ .ihub-sidenav-section-title {
884
+ flex: 1;
885
+ }
886
+
887
+ .ihub-sidenav-section-count {
888
+ display: inline-flex;
889
+ align-items: center;
890
+ justify-content: center;
891
+ min-width: 20px;
892
+ height: 18px;
893
+ padding: 0 6px;
894
+ border-radius: 999px;
895
+ background: rgba(125, 124, 124, 0.12);
896
+ font-size: 10px;
897
+ letter-spacing: 0;
898
+ }
899
+
900
+ .ihub-sidenav-section-dot {
901
+ width: 6px;
902
+ height: 6px;
903
+ border-radius: 999px;
904
+ background: var(--DarkCyan, #00838f);
905
+ }
906
+
907
+ .ihub-sidenav-section-chevron {
908
+ display: inline-flex;
909
+ transition: transform 0.2s ease;
910
+ }
911
+
912
+ .ihub-sidenav-section-chevron svg {
913
+ font-size: 16px;
914
+ }
915
+
916
+ .ihub-sidenav-section-head[aria-expanded="false"] .ihub-sidenav-section-chevron {
917
+ transform: rotate(-90deg);
918
+ }
919
+
920
+ /* Collapsed (icon-only) sidebar: a section is a thin rule and its icons. */
921
+ .ihub-sidenav-collapsed .ihub-sidenav-section + .ihub-sidenav-section {
922
+ border-top-style: solid;
923
+ }
924
+
925
+ @media (hover: none) {
926
+ .ihub-sidenav-search-box .ihub-sidenav-kbd {
927
+ display: none;
928
+ }
929
+ }
930
+
931
+ @media (prefers-reduced-motion: reduce) {
932
+ .ihub-sidenav-section-chevron {
933
+ transition: none;
934
+ }
935
+ }
936
+
937
+ /* Dark sidebar */
938
+ .ihub-sidenav-dark .ihub-sidenav-search-box {
939
+ background: rgba(255, 255, 255, 0.06);
940
+ border-color: rgba(255, 255, 255, 0.14);
941
+ }
942
+
943
+ .ihub-sidenav-dark .ihub-sidenav-search-box:focus-within {
944
+ background: rgba(255, 255, 255, 0.1);
945
+ border-color: var(--TiffanyBlue, #0fabbc);
946
+ }
947
+
948
+ .ihub-sidenav-dark .ihub-sidenav-search-input,
949
+ .ihub-sidenav-dark .ihub-sidenav-search-empty strong {
950
+ color: var(--White, #ffffff);
951
+ }
952
+
953
+ .ihub-sidenav-dark .ihub-sidenav-kbd {
954
+ background: transparent;
955
+ border-color: rgba(255, 255, 255, 0.25);
956
+ color: rgba(255, 255, 255, 0.7);
957
+ }
958
+
959
+ .ihub-sidenav-dark .ihub-sidenav-section-head,
960
+ .ihub-sidenav-dark .ihub-sidenav-result-trail,
961
+ .ihub-sidenav-dark .ihub-sidenav-results-meta {
962
+ color: rgba(255, 255, 255, 0.6);
963
+ }
964
+
965
+ .ihub-sidenav-dark .ihub-sidenav-section-head:hover {
966
+ color: var(--White, #ffffff);
967
+ }
968
+
969
+ .ihub-sidenav-dark .ihub-sidenav-section + .ihub-sidenav-section {
970
+ border-top-color: rgba(255, 255, 255, 0.14);
971
+ }
972
+
973
+ .ihub-sidenav-dark .ihub-sidenav-result-title mark {
974
+ background: rgba(15, 171, 188, 0.2);
975
+ color: var(--TiffanyBlue, #0fabbc);
976
+ }
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_rollupPluginBabelHelpers.cjs"),r=require("react/jsx-runtime"),n=require("react"),t=require("primereact/fileupload"),a=require("../../lib/helpFunction.cjs"),s=require("@aws-sdk/client-s3"),o=require("../../lib/modals/modals.cjs");function c(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:function(){return e[n]}})}}),r.default=e,Object.freeze(r)}exports.default=function(i){var l=n.useState([]),u=e.slicedToArray(l,2),d=u[0],p=u[1],f=n.useState(null),m=e.slicedToArray(f,2),y=m[0],v=m[1],h=n.useState(i.placeholder||i.labels||"Drag and drop files here to upload."),_=e.slicedToArray(h,2),g=_[0],b=_[1],S=n.useState(0),T=e.slicedToArray(S,2),x=T[0],E=T[1],j=function(){var r=e.asyncToGenerator(e.regenerator().m(function r(n){var t;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:t=n.files,p(t),v(t[0]),E(0),i.onFilesSelected&&i.onFilesSelected(t);case 1:return e.a(2)}},r)}));return function(e){return r.apply(this,arguments)}}(),U=function(){var r=e.asyncToGenerator(e.regenerator().m(function r(){var n,t,l,u,p,f,m,v,h,_,g,b,S,T,x,j,U,C,N,k,w,A;return e.regenerator().w(function(e){for(;;)switch(e.p=e.n){case 0:if(0!==(n=d.length>0?d:y?[y]:[]).length){e.n=1;break}return e.a(2);case 1:if(!i.onUpload){e.n=5;break}return e.p=2,e.n=3,i.onUpload(n);case 3:return e.a(2);case 4:return e.p=4,w=e.v,console.error("Upload callback error:",w),o.openToast("Error uploading file!",400),e.a(2);case 5:return t=n[0],e.p=6,u=new s.S3Client({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),p=(new Date).toISOString(),f=a.slugifyFileName("".concat(i.username||"anonymous","-").concat(p,"-").concat(t.name)),m=a.IN_DEV_MODE?"test-env__".concat(f):f,v=i.accepts||null!==(l=i.acceptedFileTypes)&&void 0!==l&&l.includes("video/*")?process.env.NEXT_PUBLIC_AWS_LOCATION:process.env.NEXT_PUBLIC_AWS_LOCATION_FILES,h=process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",_="".concat(v,"/").concat(m),e.n=7,t.arrayBuffer();case 7:if(g=e.v,b=new Uint8Array(g),!(t.size<104857600)){e.n=10;break}return e.n=8,Promise.resolve().then(function(){return c(require("@aws-sdk/client-s3"))});case 8:return S=e.v,T=S.PutObjectCommand,E(10),x=new T({Bucket:h,Key:_,Body:b,ContentType:t.type,ACL:"public-read"}),j=setInterval(function(){E(function(e){return Math.min(e+5,95)})},300),e.n=9,u.send(x);case 9:clearInterval(j),E(100),e.n=12;break;case 10:return e.n=11,Promise.resolve().then(function(){return c(require("@aws-sdk/lib-storage"))});case 11:return U=e.v,C=U.Upload,(N=new C({client:u,params:{Bucket:h,Key:_,Body:b,ContentType:t.type,ACL:"public-read"}})).on("httpUploadProgress",function(e){var r=Math.round(e.loaded/e.total*100);E(r)}),e.n=12,N.done();case 12:o.openToast("File Uploaded Successfully!"),k={bucket:h,title:t.name,key:m,content_type:t.type,size:t.size,location:"".concat(a.FILE_URL,"creators/").concat(m)},i.setResponse&&i.setResponse(k),i.setValues&&i.setValues(i.names||"",k.key),i.setModules&&i.setModules(i.module||"",i.names||"",k.key),i.setSteps&&i.setSteps(i.module||"",i.step||"",i.names||"",k.key),e.n=14;break;case 13:e.p=13,A=e.v,console.error("Upload error:",A),o.openToast("Error uploading file!",400),E(0);case 14:return e.a(2)}},r,null,[[6,13],[2,4]])}));return function(){return r.apply(this,arguments)}}(),C=function(e){var n=e.percentage;return r.jsx("div",{className:"ihub-progress",style:{width:"100%",height:"8px",background:"var(--Gray, #e5e7eb)",borderRadius:"4px",overflow:"hidden",margin:"8px 0"},children:r.jsx("div",{className:"ihub-progress-bar",style:{width:"".concat(n,"%"),height:"100%",background:"var(--DarkCyan, #00838f)",borderRadius:"4px",transition:"width 0.3s ease",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",color:"#fff",fontWeight:600,minWidth:n>10?"auto":0},children:n>10?"".concat(n,"%"):""})})};return r.jsxs("div",{className:"ihub-uploader card primereact ".concat(i.className||""),children:[i.headers&&r.jsx("h3",{children:i.headers}),r.jsx(t.FileUpload,{name:"upload",customUpload:!0,accept:i.acceptedFileTypes&&i.acceptedFileTypes.length>0?i.acceptedFileTypes.join(","):i.accepts||"*",maxFileSize:i.maxFileSize||0,multiple:!i.maxFiles||i.maxFiles>1,onSelect:j,uploadHandler:U,emptyTemplate:r.jsx("p",{className:"m-0",children:g}),onError:function(){return b("Upload failed, try again!")},progressBarTemplate:!1!==i.showProgress?function(){return r.jsxs("div",{children:[r.jsx(C,{percentage:x}),r.jsxs("p",{style:{fontSize:"12px",color:"var(--Rhythm, #69779b)",margin:"4px 0 0"},children:["Uploading… ",x,"%"]})]})}:void 0,itemTemplate:x&&!1!==i.showProgress?function(e){var n,t=(null==e?void 0:e.name)||(null==e||null===(n=e.objectURL)||void 0===n?void 0:n.split("/").pop())||"File";return r.jsx("div",{style:{fontSize:"12px",color:"var(--Rhythm, #69779b)",padding:"4px 0"},children:t})}:void 0,disabled:i.isUploading,pt:{content:{className:"surface-ground"},message:{root:{className:"w-1rem"}}}})]})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_rollupPluginBabelHelpers.cjs"),r=require("react/jsx-runtime"),n=require("react"),t=require("primereact/fileupload"),a=require("../../lib/helpFunction.cjs"),s=require("./uploadedFileUrl.cjs"),o=require("@aws-sdk/client-s3"),c=require("../../lib/modals/modals.cjs");function i(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:function(){return e[n]}})}}),r.default=e,Object.freeze(r)}exports.default=function(l){var u=n.useState([]),d=e.slicedToArray(u,2),p=d[0],f=d[1],m=n.useState(null),y=e.slicedToArray(m,2),v=y[0],h=y[1],_=n.useState(l.placeholder||l.labels||"Drag and drop files here to upload."),g=e.slicedToArray(_,2),b=g[0],S=g[1],T=n.useState(0),x=e.slicedToArray(T,2),E=x[0],U=x[1],j=function(){var r=e.asyncToGenerator(e.regenerator().m(function r(n){var t;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:t=n.files,f(t),h(t[0]),U(0),l.onFilesSelected&&l.onFilesSelected(t);case 1:return e.a(2)}},r)}));return function(e){return r.apply(this,arguments)}}(),C=function(){var r=e.asyncToGenerator(e.regenerator().m(function r(){var n,t,u,d,f,m,y,h,_,g,b,S,T,x,E,j,C,N,I,A,k,w;return e.regenerator().w(function(e){for(;;)switch(e.p=e.n){case 0:if(0!==(n=p.length>0?p:v?[v]:[]).length){e.n=1;break}return e.a(2);case 1:if(!l.onUpload){e.n=5;break}return e.p=2,e.n=3,l.onUpload(n);case 3:return e.a(2);case 4:return e.p=4,k=e.v,console.error("Upload callback error:",k),c.openToast("Error uploading file!",400),e.a(2);case 5:return t=n[0],e.p=6,d=new o.S3Client({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),f=(new Date).toISOString(),m=a.slugifyFileName("".concat(l.username||"anonymous","-").concat(f,"-").concat(t.name)),y=a.IN_DEV_MODE?"test-env__".concat(m):m,h=l.accepts||null!==(u=l.acceptedFileTypes)&&void 0!==u&&u.includes("video/*")?process.env.NEXT_PUBLIC_AWS_LOCATION:process.env.NEXT_PUBLIC_AWS_LOCATION_FILES,_=process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",g="".concat(h,"/").concat(y),e.n=7,t.arrayBuffer();case 7:if(b=e.v,S=new Uint8Array(b),!(t.size<104857600)){e.n=10;break}return e.n=8,Promise.resolve().then(function(){return i(require("@aws-sdk/client-s3"))});case 8:return T=e.v,x=T.PutObjectCommand,U(10),E=new x({Bucket:_,Key:g,Body:S,ContentType:t.type,ACL:"public-read"}),j=setInterval(function(){U(function(e){return Math.min(e+5,95)})},300),e.n=9,d.send(E);case 9:clearInterval(j),U(100),e.n=12;break;case 10:return e.n=11,Promise.resolve().then(function(){return i(require("@aws-sdk/lib-storage"))});case 11:return C=e.v,N=C.Upload,(I=new N({client:d,params:{Bucket:_,Key:g,Body:S,ContentType:t.type,ACL:"public-read"}})).on("httpUploadProgress",function(e){var r=Math.round(e.loaded/e.total*100);U(r)}),e.n=12,I.done();case 12:c.openToast("File Uploaded Successfully!"),A={bucket:_,title:t.name,key:y,content_type:t.type,size:t.size,location:s.uploadedFileUrl(g,a.FILE_URL,process.env.NEXT_PUBLIC_AWS_LOCATION_FILES)},l.setResponse&&l.setResponse(A),l.setValues&&l.setValues(l.names||"",A.key),l.setModules&&l.setModules(l.module||"",l.names||"",A.key),l.setSteps&&l.setSteps(l.module||"",l.step||"",l.names||"",A.key),e.n=14;break;case 13:e.p=13,w=e.v,console.error("Upload error:",w),c.openToast("Error uploading file!",400),U(0);case 14:return e.a(2)}},r,null,[[6,13],[2,4]])}));return function(){return r.apply(this,arguments)}}(),N=function(e){var n=e.percentage;return r.jsx("div",{className:"ihub-progress",style:{width:"100%",height:"8px",background:"var(--Gray, #e5e7eb)",borderRadius:"4px",overflow:"hidden",margin:"8px 0"},children:r.jsx("div",{className:"ihub-progress-bar",style:{width:"".concat(n,"%"),height:"100%",background:"var(--DarkCyan, #00838f)",borderRadius:"4px",transition:"width 0.3s ease",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",color:"#fff",fontWeight:600,minWidth:n>10?"auto":0},children:n>10?"".concat(n,"%"):""})})};return r.jsxs("div",{className:"ihub-uploader card primereact ".concat(l.className||""),children:[l.headers&&r.jsx("h3",{children:l.headers}),r.jsx(t.FileUpload,{name:"upload",customUpload:!0,accept:l.acceptedFileTypes&&l.acceptedFileTypes.length>0?l.acceptedFileTypes.join(","):l.accepts||"*",maxFileSize:l.maxFileSize||0,multiple:!l.maxFiles||l.maxFiles>1,onSelect:j,uploadHandler:C,emptyTemplate:r.jsx("p",{className:"m-0",children:b}),onError:function(){return S("Upload failed, try again!")},progressBarTemplate:!1!==l.showProgress?function(){return r.jsxs("div",{children:[r.jsx(N,{percentage:E}),r.jsxs("p",{style:{fontSize:"12px",color:"var(--Rhythm, #69779b)",margin:"4px 0 0"},children:["Uploading… ",E,"%"]})]})}:void 0,itemTemplate:E&&!1!==l.showProgress?function(e){var n,t=(null==e?void 0:e.name)||(null==e||null===(n=e.objectURL)||void 0===n?void 0:n.split("/").pop())||"File";return r.jsx("div",{style:{fontSize:"12px",color:"var(--Rhythm, #69779b)",padding:"4px 0"},children:t})}:void 0,disabled:l.isUploading,pt:{content:{className:"surface-ground"},message:{root:{className:"w-1rem"}}}})]})};
2
2
  //# sourceMappingURL=FileUploader.cjs.map
@@ -1,2 +1,2 @@
1
- import{slicedToArray as e,asyncToGenerator as r,regenerator as n}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as a,jsx as t}from"react/jsx-runtime";import{useState as o}from"react";import{FileUpload as s}from"primereact/fileupload";import{FILE_URL as c,slugifyFileName as i,IN_DEV_MODE as l}from"../../lib/helpFunction.js";import{S3Client as p}from"@aws-sdk/client-s3";import{openToast as d}from"../../lib/modals/modals.js";var u=function(u){var m=o([]),f=e(m,2),h=f[0],v=f[1],y=o(null),_=e(y,2),g=_[0],b=_[1],S=o(u.placeholder||u.labels||"Drag and drop files here to upload."),T=e(S,2),C=T[0],U=T[1],E=o(0),N=e(E,2),k=N[0],w=N[1],I=function(){var e=r(n().m(function e(r){var a;return n().w(function(e){for(;;)switch(e.n){case 0:a=r.files,v(a),b(a[0]),w(0),u.onFilesSelected&&u.onFilesSelected(a);case 1:return e.a(2)}},e)}));return function(r){return e.apply(this,arguments)}}(),A=function(){var e=r(n().m(function e(){var r,a,t,o,s,m,f,v,y,_,b,S,T,C,U,E,N,k,I,A,x,B;return n().w(function(e){for(;;)switch(e.p=e.n){case 0:if(0!==(r=h.length>0?h:g?[g]:[]).length){e.n=1;break}return e.a(2);case 1:if(!u.onUpload){e.n=5;break}return e.p=2,e.n=3,u.onUpload(r);case 3:return e.a(2);case 4:return e.p=4,x=e.v,console.error("Upload callback error:",x),d("Error uploading file!",400),e.a(2);case 5:return a=r[0],e.p=6,o=new p({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),s=(new Date).toISOString(),m=i("".concat(u.username||"anonymous","-").concat(s,"-").concat(a.name)),f=l?"test-env__".concat(m):m,v=u.accepts||null!==(t=u.acceptedFileTypes)&&void 0!==t&&t.includes("video/*")?process.env.NEXT_PUBLIC_AWS_LOCATION:process.env.NEXT_PUBLIC_AWS_LOCATION_FILES,y=process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",_="".concat(v,"/").concat(f),e.n=7,a.arrayBuffer();case 7:if(b=e.v,S=new Uint8Array(b),!(a.size<104857600)){e.n=10;break}return e.n=8,import("@aws-sdk/client-s3");case 8:return T=e.v,C=T.PutObjectCommand,w(10),U=new C({Bucket:y,Key:_,Body:S,ContentType:a.type,ACL:"public-read"}),E=setInterval(function(){w(function(e){return Math.min(e+5,95)})},300),e.n=9,o.send(U);case 9:clearInterval(E),w(100),e.n=12;break;case 10:return e.n=11,import("@aws-sdk/lib-storage");case 11:return N=e.v,k=N.Upload,(I=new k({client:o,params:{Bucket:y,Key:_,Body:S,ContentType:a.type,ACL:"public-read"}})).on("httpUploadProgress",function(e){var r=Math.round(e.loaded/e.total*100);w(r)}),e.n=12,I.done();case 12:d("File Uploaded Successfully!"),A={bucket:y,title:a.name,key:f,content_type:a.type,size:a.size,location:"".concat(c,"creators/").concat(f)},u.setResponse&&u.setResponse(A),u.setValues&&u.setValues(u.names||"",A.key),u.setModules&&u.setModules(u.module||"",u.names||"",A.key),u.setSteps&&u.setSteps(u.module||"",u.step||"",u.names||"",A.key),e.n=14;break;case 13:e.p=13,B=e.v,console.error("Upload error:",B),d("Error uploading file!",400),w(0);case 14:return e.a(2)}},e,null,[[6,13],[2,4]])}));return function(){return e.apply(this,arguments)}}(),x=function(e){var r=e.percentage;return t("div",{className:"ihub-progress",style:{width:"100%",height:"8px",background:"var(--Gray, #e5e7eb)",borderRadius:"4px",overflow:"hidden",margin:"8px 0"},children:t("div",{className:"ihub-progress-bar",style:{width:"".concat(r,"%"),height:"100%",background:"var(--DarkCyan, #00838f)",borderRadius:"4px",transition:"width 0.3s ease",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",color:"#fff",fontWeight:600,minWidth:r>10?"auto":0},children:r>10?"".concat(r,"%"):""})})};return a("div",{className:"ihub-uploader card primereact ".concat(u.className||""),children:[u.headers&&t("h3",{children:u.headers}),t(s,{name:"upload",customUpload:!0,accept:u.acceptedFileTypes&&u.acceptedFileTypes.length>0?u.acceptedFileTypes.join(","):u.accepts||"*",maxFileSize:u.maxFileSize||0,multiple:!u.maxFiles||u.maxFiles>1,onSelect:I,uploadHandler:A,emptyTemplate:t("p",{className:"m-0",children:C}),onError:function(){return U("Upload failed, try again!")},progressBarTemplate:!1!==u.showProgress?function(){return a("div",{children:[t(x,{percentage:k}),a("p",{style:{fontSize:"12px",color:"var(--Rhythm, #69779b)",margin:"4px 0 0"},children:["Uploading… ",k,"%"]})]})}:void 0,itemTemplate:k&&!1!==u.showProgress?function(e){var r,n=(null==e?void 0:e.name)||(null==e||null===(r=e.objectURL)||void 0===r?void 0:r.split("/").pop())||"File";return t("div",{style:{fontSize:"12px",color:"var(--Rhythm, #69779b)",padding:"4px 0"},children:n})}:void 0,disabled:u.isUploading,pt:{content:{className:"surface-ground"},message:{root:{className:"w-1rem"}}}})]})};export{u as default};
1
+ import{slicedToArray as e,asyncToGenerator as r,regenerator as n}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as a,jsx as t}from"react/jsx-runtime";import{useState as o}from"react";import{FileUpload as s}from"primereact/fileupload";import{FILE_URL as c,slugifyFileName as i,IN_DEV_MODE as l}from"../../lib/helpFunction.js";import{uploadedFileUrl as p}from"./uploadedFileUrl.js";import{S3Client as d}from"@aws-sdk/client-s3";import{openToast as u}from"../../lib/modals/modals.js";var m=function(m){var f=o([]),h=e(f,2),v=h[0],y=h[1],_=o(null),g=e(_,2),S=g[0],b=g[1],T=o(m.placeholder||m.labels||"Drag and drop files here to upload."),C=e(T,2),U=C[0],E=C[1],N=o(0),I=e(N,2),k=I[0],w=I[1],A=function(){var e=r(n().m(function e(r){var a;return n().w(function(e){for(;;)switch(e.n){case 0:a=r.files,y(a),b(a[0]),w(0),m.onFilesSelected&&m.onFilesSelected(a);case 1:return e.a(2)}},e)}));return function(r){return e.apply(this,arguments)}}(),L=function(){var e=r(n().m(function e(){var r,a,t,o,s,f,h,y,_,g,b,T,C,U,E,N,I,k,A,L,x,B;return n().w(function(e){for(;;)switch(e.p=e.n){case 0:if(0!==(r=v.length>0?v:S?[S]:[]).length){e.n=1;break}return e.a(2);case 1:if(!m.onUpload){e.n=5;break}return e.p=2,e.n=3,m.onUpload(r);case 3:return e.a(2);case 4:return e.p=4,x=e.v,console.error("Upload callback error:",x),u("Error uploading file!",400),e.a(2);case 5:return a=r[0],e.p=6,o=new d({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),s=(new Date).toISOString(),f=i("".concat(m.username||"anonymous","-").concat(s,"-").concat(a.name)),h=l?"test-env__".concat(f):f,y=m.accepts||null!==(t=m.acceptedFileTypes)&&void 0!==t&&t.includes("video/*")?process.env.NEXT_PUBLIC_AWS_LOCATION:process.env.NEXT_PUBLIC_AWS_LOCATION_FILES,_=process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",g="".concat(y,"/").concat(h),e.n=7,a.arrayBuffer();case 7:if(b=e.v,T=new Uint8Array(b),!(a.size<104857600)){e.n=10;break}return e.n=8,import("@aws-sdk/client-s3");case 8:return C=e.v,U=C.PutObjectCommand,w(10),E=new U({Bucket:_,Key:g,Body:T,ContentType:a.type,ACL:"public-read"}),N=setInterval(function(){w(function(e){return Math.min(e+5,95)})},300),e.n=9,o.send(E);case 9:clearInterval(N),w(100),e.n=12;break;case 10:return e.n=11,import("@aws-sdk/lib-storage");case 11:return I=e.v,k=I.Upload,(A=new k({client:o,params:{Bucket:_,Key:g,Body:T,ContentType:a.type,ACL:"public-read"}})).on("httpUploadProgress",function(e){var r=Math.round(e.loaded/e.total*100);w(r)}),e.n=12,A.done();case 12:u("File Uploaded Successfully!"),L={bucket:_,title:a.name,key:h,content_type:a.type,size:a.size,location:p(g,c,process.env.NEXT_PUBLIC_AWS_LOCATION_FILES)},m.setResponse&&m.setResponse(L),m.setValues&&m.setValues(m.names||"",L.key),m.setModules&&m.setModules(m.module||"",m.names||"",L.key),m.setSteps&&m.setSteps(m.module||"",m.step||"",m.names||"",L.key),e.n=14;break;case 13:e.p=13,B=e.v,console.error("Upload error:",B),u("Error uploading file!",400),w(0);case 14:return e.a(2)}},e,null,[[6,13],[2,4]])}));return function(){return e.apply(this,arguments)}}(),x=function(e){var r=e.percentage;return t("div",{className:"ihub-progress",style:{width:"100%",height:"8px",background:"var(--Gray, #e5e7eb)",borderRadius:"4px",overflow:"hidden",margin:"8px 0"},children:t("div",{className:"ihub-progress-bar",style:{width:"".concat(r,"%"),height:"100%",background:"var(--DarkCyan, #00838f)",borderRadius:"4px",transition:"width 0.3s ease",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",color:"#fff",fontWeight:600,minWidth:r>10?"auto":0},children:r>10?"".concat(r,"%"):""})})};return a("div",{className:"ihub-uploader card primereact ".concat(m.className||""),children:[m.headers&&t("h3",{children:m.headers}),t(s,{name:"upload",customUpload:!0,accept:m.acceptedFileTypes&&m.acceptedFileTypes.length>0?m.acceptedFileTypes.join(","):m.accepts||"*",maxFileSize:m.maxFileSize||0,multiple:!m.maxFiles||m.maxFiles>1,onSelect:A,uploadHandler:L,emptyTemplate:t("p",{className:"m-0",children:U}),onError:function(){return E("Upload failed, try again!")},progressBarTemplate:!1!==m.showProgress?function(){return a("div",{children:[t(x,{percentage:k}),a("p",{style:{fontSize:"12px",color:"var(--Rhythm, #69779b)",margin:"4px 0 0"},children:["Uploading… ",k,"%"]})]})}:void 0,itemTemplate:k&&!1!==m.showProgress?function(e){var r,n=(null==e?void 0:e.name)||(null==e||null===(r=e.objectURL)||void 0===r?void 0:r.split("/").pop())||"File";return t("div",{style:{fontSize:"12px",color:"var(--Rhythm, #69779b)",padding:"4px 0"},children:n})}:void 0,disabled:m.isUploading,pt:{content:{className:"surface-ground"},message:{root:{className:"w-1rem"}}}})]})};export{m as default};
2
2
  //# sourceMappingURL=FileUploader.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_rollupPluginBabelHelpers.cjs"),n=require("react/jsx-runtime"),r=require("react"),t=require("../../lib/helpFunction.cjs"),o=require("@aws-sdk/client-s3"),s=require("@aws-sdk/lib-storage"),i=require("../../lib/modals/modals.cjs");exports.default=function(a){var l,c=a.header,u=a.label,d=void 0===u?"Drag and drop files here or click to browse":u,p=a.accept,h=void 0===p?"*":p,v=a.maxFileSize,x=void 0===v?0:v,m=a.name,b=void 0===m?"upload":m,f=a.module,g=void 0===f?"":f,j=a.step,y=void 0===j?"":j,w=a.username,k=void 0===w?null:w,_=a.onUploadComplete,C=a.setValues,N=a.setModules,E=a.setSteps,S=a.className,L=void 0===S?"":S,T=a.saveEndpoint,B=a.deleteEndpoint,I=a.token,A=a.enableS3Delete,U=void 0!==A&&A,W=a.onRemove,P=r.useState(null),D=e.slicedToArray(P,2),O=D[0],R=D[1],M=r.useState(!1),K=e.slicedToArray(M,2),z=K[0],F=K[1],X=r.useState(0),q=e.slicedToArray(X,2),G=q[0],H=q[1],V=r.useState("idle"),Y=e.slicedToArray(V,2),Q=Y[0],J=Y[1],Z=r.useState(""),$=e.slicedToArray(Z,2),ee=$[0],ne=$[1],re=r.useState([]),te=e.slicedToArray(re,2),oe=te[0],se=te[1],ie=r.useState(null),ae=e.slicedToArray(ie,2),le=ae[0],ce=ae[1],ue=r.useRef(null),de=function(e){if(0===e)return"0 Bytes";var n=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,n)).toFixed(2))+" "+["Bytes","KB","MB","GB"][n]},pe=function(e){ne(""),function(e){var n;if("*"===h)return!0;var r=e.type,t=".".concat(null===(n=e.name.split(".").pop())||void 0===n?void 0:n.toLowerCase());return!!h.split(",").map(function(e){return e.trim()}).some(function(e){return e.startsWith(".")?t===e.toLowerCase():e.endsWith("/*")?r.startsWith("".concat(e.replace("/*",""),"/")):r===e})||(ne("File type not accepted. Please upload: ".concat(h)),!1)}(e)&&function(e){return!(x&&e.size>x&&(ne("File size exceeds the maximum limit of ".concat(de(x))),1))}(e)&&(R(e),J("idle"),H(0))},he=function(){var n=e.asyncToGenerator(e.regenerator().m(function n(r){var o,s,i,a,l,c,u,d;return e.regenerator().w(function(e){for(;;)switch(e.p=e.n){case 0:if(T&&I){e.n=1;break}return e.a(2,null);case 1:return e.p=1,s=JSON.stringify({file_url:r.location,file_key:r.key,file_name:r.title,file_size:r.size,content_type:r.content_type,media_type:null!==(o=r.content_type)&&void 0!==o&&o.startsWith("video/")?"video":"image"}),i=t.reqOptions("POST",s,I,"json"),e.n=2,fetch(T,i);case 2:if(!(a=e.v).ok){e.n=4;break}return e.n=3,a.json();case 3:return l=e.v,e.a(2,l.id);case 4:return c=console,u=a.status,e.n=5,a.text();case 5:c.error.call(c,"Save to DB failed:",u,e.v),e.n=7;break;case 6:e.p=6,d=e.v,console.error("Save to DB error:",d);case 7:return e.a(2,null)}},n,null,[[1,6]])}));return function(e){return n.apply(this,arguments)}}(),ve=function(){var n=e.asyncToGenerator(e.regenerator().m(function n(r){var t,s,i,a;return e.regenerator().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,t=new URL(r),s=t.pathname.replace(/^\//,"")){e.n=1;break}return e.a(2);case 1:return i=new o.S3Client({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,requestChecksumCalculation:"WHEN_REQUIRED",credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),e.n=2,i.send(new o.DeleteObjectCommand({Bucket:process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",Key:s}));case 2:e.n=4;break;case 3:e.p=3,a=e.v,console.error("S3 delete error:",a);case 4:return e.a(2)}},n,null,[[0,3]])}));return function(e){return n.apply(this,arguments)}}(),xe=function(){var n=e.asyncToGenerator(e.regenerator().m(function n(r){var o,s,i;return e.regenerator().w(function(e){for(;;)switch(e.p=e.n){case 0:if(B&&I){e.n=1;break}return e.a(2,!1);case 1:return e.p=1,o=t.reqOptions("DELETE",null,I),e.n=2,fetch("".concat(B).concat(r,"/"),o);case 2:return s=e.v,e.a(2,s.ok||404===s.status);case 3:return e.p=3,i=e.v,console.error("DB delete error:",i),e.a(2,!1)}},n,null,[[1,3]])}));return function(e){return n.apply(this,arguments)}}(),me=function(){var n=e.asyncToGenerator(e.regenerator().m(function n(r){var t;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:if(t=oe[r]){e.n=1;break}return e.a(2);case 1:if(!t.dbId||!B){e.n=2;break}return e.n=2,xe(t.dbId);case 2:if(!U||!t.response.location){e.n=3;break}return e.n=3,ve(t.response.location);case 3:se(function(e){return e.filter(function(e,n){return n!==r})}),W&&W(t.response),i.openToast("File removed");case 4:return e.a(2)}},n)}));return function(e){return n.apply(this,arguments)}}(),be=function(){var n=e.asyncToGenerator(e.regenerator().m(function n(){var r,a,l,c,u,d,p,v,x,m,f,j,w,S;return e.regenerator().w(function(n){for(;;)switch(n.p=n.n){case 0:if(O){n.n=1;break}return ne("Please select a file first"),n.a(2);case 1:if(J("uploading"),ne(""),n.p=2,r=new o.S3Client({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,requestChecksumCalculation:"WHEN_REQUIRED",credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),a=(new Date).toISOString(),l=t.slugifyFileName("".concat(k||"anonymous","-").concat(a,"-").concat(O.name)),c=t.IN_DEV_MODE?"test-env__".concat(l):l,u="video/*"===h?process.env.NEXT_PUBLIC_AWS_LOCATION:process.env.NEXT_PUBLIC_AWS_LOCATION_FILES,d=process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",p="".concat(u,"/").concat(c),!(O.size<104857600)){n.n=4;break}return H(10),v=new o.PutObjectCommand({Bucket:d,Key:p,Body:O,ContentType:O.type,ACL:"public-read"}),x=setInterval(function(){H(function(e){return Math.min(e+5,95)})},300),n.n=3,r.send(v);case 3:clearInterval(x),H(100),n.n=5;break;case 4:return(m=new s.Upload({client:r,params:{Bucket:d,Key:p,Body:O,ContentType:O.type,ACL:"public-read"}})).on("httpUploadProgress",function(e){var n=Math.round(e.loaded/e.total*100);H(n)}),n.n=5,m.done();case 5:if(J("success"),i.openToast("File Uploaded Successfully!"),f={bucket:d,title:O.name,key:c,content_type:O.type,size:O.size,location:"".concat(t.FILE_URL,"creators/").concat(c)},!T||!I){n.n=7;break}return n.n=6,he(f);case 6:(w=n.v)&&(j=w);case 7:se(function(n){return[].concat(e.toConsumableArray(n),[{response:f,dbId:j,fullS3Key:p}])}),_&&_(f),C&&C(b,f.key),N&&N(g,b,f.key),E&&E(g,y,b,f.key),setTimeout(function(){R(null),J("idle"),H(0)},2e3),n.n=9;break;case 8:n.p=8,S=n.v,console.error("Upload error:",S),J("error"),ne("Error uploading file. Please try again."),i.openToast("Error uploading file!",400),H(0);case 9:return n.a(2)}},n,null,[[2,8]])}));return function(){return n.apply(this,arguments)}}(),fe=function(){R(null),J("idle"),H(0),ne("")};return n.jsxs("div",{className:"ihub-uploader ".concat(L),children:[c&&n.jsx("h3",{className:"ihub-uploader-header",children:c}),n.jsxs("div",{className:"ihub-uploader-container",children:[!O&&n.jsxs("div",{className:"ihub-uploader-dropzone ".concat(z?"ihub-uploader-dropzone-active":""),onDragOver:function(e){e.preventDefault(),e.stopPropagation(),F(!0)},onDragLeave:function(e){e.preventDefault(),e.stopPropagation(),F(!1)},onDrop:function(e){e.preventDefault(),e.stopPropagation(),F(!1);var n=e.dataTransfer.files;n&&n.length>0&&pe(n[0])},onClick:function(){var e;null===(e=ue.current)||void 0===e||e.click()},children:[n.jsx("div",{className:"ihub-uploader-icon",children:n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),n.jsx("polyline",{points:"17 8 12 3 7 8"}),n.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]})}),n.jsx("p",{className:"ihub-uploader-text",children:d}),n.jsx("p",{className:"ihub-uploader-hint",children:x>0&&"Maximum file size: ".concat(de(x))}),n.jsx("input",{ref:ue,type:"file",accept:h,onChange:function(e){var n=e.target.files;n&&n.length>0&&pe(n[0])},className:"ihub-uploader-input"})]}),O&&n.jsxs("div",{className:"ihub-uploader-preview",children:[n.jsxs("div",{className:"ihub-uploader-file-info",children:[n.jsx("div",{className:"ihub-uploader-file-icon",children:O.type.startsWith("image/")?n.jsx("img",{src:URL.createObjectURL(O),alt:O.name,className:"ihub-uploader-thumbnail"}):n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"}),n.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),n.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),n.jsx("polyline",{points:"10 9 9 9 8 9"})]})}),n.jsxs("div",{className:"ihub-uploader-file-details",children:[n.jsx("p",{className:"ihub-uploader-file-name",children:O.name}),n.jsx("p",{className:"ihub-uploader-file-size",children:de(O.size)})]})]}),"uploading"===Q&&n.jsx("div",{className:"ihub-uploader-progress",children:n.jsx("div",{className:"ihub-uploader-progress-bar",style:{width:"".concat(G,"%")},children:n.jsxs("span",{className:"ihub-uploader-progress-text",children:[G,"%"]})})}),n.jsxs("div",{className:"ihub-uploader-actions",children:["idle"===Q&&n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"ihub-uploader-upload-btn ihub-important-btn",onClick:be,children:"Upload"}),n.jsx("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:fe,children:"Cancel"})]}),"uploading"===Q&&n.jsx("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:fe,children:"Cancel"}),"success"===Q&&n.jsxs("div",{className:"ihub-uploader-success",children:[n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),n.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),n.jsx("span",{children:"Upload Complete"})]}),"error"===Q&&n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"ihub-uploader-retry-btn ihub-important-btn",onClick:be,children:"Retry"}),n.jsx("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:fe,children:"Cancel"})]})]})]}),oe.length>0&&n.jsx("div",{className:"ihub-uploader-thumbs",children:oe.map(function(e,r){var t,o=null===(t=e.response.content_type)||void 0===t?void 0:t.startsWith("video/");return n.jsxs("div",{className:"ihub-uploader-thumb",children:[n.jsxs("div",{className:"ihub-uploader-thumb-preview",onClick:function(){return ce(r)},title:"Click to preview",children:[o?n.jsx("video",{src:e.response.location,muted:!0}):n.jsx("img",{src:e.response.location,alt:e.response.title}),o&&n.jsx("span",{className:"ihub-uploader-thumb-badge",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})})})]}),n.jsx("button",{type:"button",className:"ihub-uploader-thumb-remove",onClick:function(e){e.stopPropagation(),me(r)},title:"Remove",children:n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},r)})}),null!==le&&oe[le]&&n.jsx("div",{className:"ihub-uploader-lightbox",onClick:function(){return ce(null)},children:n.jsxs("div",{className:"ihub-uploader-lightbox-content",onClick:function(e){return e.stopPropagation()},children:[n.jsx("button",{className:"ihub-uploader-lightbox-close",onClick:function(){return ce(null)},children:n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),le>0&&n.jsx("button",{className:"ihub-uploader-lightbox-nav ihub-uploader-lightbox-prev",onClick:function(){return ce(le-1)},children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsx("div",{className:"ihub-uploader-lightbox-media",children:null!==(l=oe[le].response.content_type)&&void 0!==l&&l.startsWith("video/")?n.jsx("video",{src:oe[le].response.location,controls:!0,autoPlay:!0}):n.jsx("img",{src:oe[le].response.location,alt:oe[le].response.title})}),le<oe.length-1&&n.jsx("button",{className:"ihub-uploader-lightbox-nav ihub-uploader-lightbox-next",onClick:function(){return ce(le+1)},children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"9 18 15 12 9 6"})})}),n.jsxs("div",{className:"ihub-uploader-lightbox-info",children:[n.jsx("span",{children:oe[le].response.title}),n.jsxs("span",{children:[le+1," / ",oe.length]})]})]})}),ee&&n.jsxs("div",{className:"ihub-uploader-error",children:[n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),n.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),n.jsx("span",{children:ee})]})]})]})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_rollupPluginBabelHelpers.cjs"),n=require("react/jsx-runtime"),r=require("react"),t=require("../../lib/helpFunction.cjs"),o=require("./uploadedFileUrl.cjs"),s=require("@aws-sdk/client-s3"),i=require("@aws-sdk/lib-storage"),a=require("../../lib/modals/modals.cjs");exports.default=function(l){var c,u=l.header,d=l.label,p=void 0===d?"Drag and drop files here or click to browse":d,h=l.accept,v=void 0===h?"*":h,x=l.maxFileSize,m=void 0===x?0:x,b=l.name,f=void 0===b?"upload":b,g=l.module,j=void 0===g?"":g,y=l.step,w=void 0===y?"":y,k=l.username,_=void 0===k?null:k,C=l.onUploadComplete,N=l.setValues,E=l.setModules,S=l.setSteps,L=l.className,T=void 0===L?"":L,B=l.saveEndpoint,I=l.deleteEndpoint,A=l.token,U=l.enableS3Delete,W=void 0!==U&&U,P=l.onRemove,D=r.useState(null),O=e.slicedToArray(D,2),R=O[0],F=O[1],M=r.useState(!1),K=e.slicedToArray(M,2),z=K[0],X=K[1],q=r.useState(0),G=e.slicedToArray(q,2),H=G[0],V=G[1],Y=r.useState("idle"),Q=e.slicedToArray(Y,2),J=Q[0],Z=Q[1],$=r.useState(""),ee=e.slicedToArray($,2),ne=ee[0],re=ee[1],te=r.useState([]),oe=e.slicedToArray(te,2),se=oe[0],ie=oe[1],ae=r.useState(null),le=e.slicedToArray(ae,2),ce=le[0],ue=le[1],de=r.useRef(null),pe=function(e){if(0===e)return"0 Bytes";var n=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,n)).toFixed(2))+" "+["Bytes","KB","MB","GB"][n]},he=function(e){re(""),function(e){var n;if("*"===v)return!0;var r=e.type,t=".".concat(null===(n=e.name.split(".").pop())||void 0===n?void 0:n.toLowerCase());return!!v.split(",").map(function(e){return e.trim()}).some(function(e){return e.startsWith(".")?t===e.toLowerCase():e.endsWith("/*")?r.startsWith("".concat(e.replace("/*",""),"/")):r===e})||(re("File type not accepted. Please upload: ".concat(v)),!1)}(e)&&function(e){return!(m&&e.size>m&&(re("File size exceeds the maximum limit of ".concat(pe(m))),1))}(e)&&(F(e),Z("idle"),V(0))},ve=function(){var n=e.asyncToGenerator(e.regenerator().m(function n(r){var o,s,i,a,l,c,u,d;return e.regenerator().w(function(e){for(;;)switch(e.p=e.n){case 0:if(B&&A){e.n=1;break}return e.a(2,null);case 1:return e.p=1,s=JSON.stringify({file_url:r.location,file_key:r.key,file_name:r.title,file_size:r.size,content_type:r.content_type,media_type:null!==(o=r.content_type)&&void 0!==o&&o.startsWith("video/")?"video":"image"}),i=t.reqOptions("POST",s,A,"json"),e.n=2,fetch(B,i);case 2:if(!(a=e.v).ok){e.n=4;break}return e.n=3,a.json();case 3:return l=e.v,e.a(2,l.id);case 4:return c=console,u=a.status,e.n=5,a.text();case 5:c.error.call(c,"Save to DB failed:",u,e.v),e.n=7;break;case 6:e.p=6,d=e.v,console.error("Save to DB error:",d);case 7:return e.a(2,null)}},n,null,[[1,6]])}));return function(e){return n.apply(this,arguments)}}(),xe=function(){var n=e.asyncToGenerator(e.regenerator().m(function n(r){var t,o,i,a;return e.regenerator().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,t=new URL(r),o=t.pathname.replace(/^\//,"")){e.n=1;break}return e.a(2);case 1:return i=new s.S3Client({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,requestChecksumCalculation:"WHEN_REQUIRED",credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),e.n=2,i.send(new s.DeleteObjectCommand({Bucket:process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",Key:o}));case 2:e.n=4;break;case 3:e.p=3,a=e.v,console.error("S3 delete error:",a);case 4:return e.a(2)}},n,null,[[0,3]])}));return function(e){return n.apply(this,arguments)}}(),me=function(){var n=e.asyncToGenerator(e.regenerator().m(function n(r){var o,s,i;return e.regenerator().w(function(e){for(;;)switch(e.p=e.n){case 0:if(I&&A){e.n=1;break}return e.a(2,!1);case 1:return e.p=1,o=t.reqOptions("DELETE",null,A),e.n=2,fetch("".concat(I).concat(r,"/"),o);case 2:return s=e.v,e.a(2,s.ok||404===s.status);case 3:return e.p=3,i=e.v,console.error("DB delete error:",i),e.a(2,!1)}},n,null,[[1,3]])}));return function(e){return n.apply(this,arguments)}}(),be=function(){var n=e.asyncToGenerator(e.regenerator().m(function n(r){var t;return e.regenerator().w(function(e){for(;;)switch(e.n){case 0:if(t=se[r]){e.n=1;break}return e.a(2);case 1:if(!t.dbId||!I){e.n=2;break}return e.n=2,me(t.dbId);case 2:if(!W||!t.response.location){e.n=3;break}return e.n=3,xe(t.response.location);case 3:ie(function(e){return e.filter(function(e,n){return n!==r})}),P&&P(t.response),a.openToast("File removed");case 4:return e.a(2)}},n)}));return function(e){return n.apply(this,arguments)}}(),fe=function(){var n=e.asyncToGenerator(e.regenerator().m(function n(){var r,l,c,u,d,p,h,x,m,b,g,y,k,L;return e.regenerator().w(function(n){for(;;)switch(n.p=n.n){case 0:if(R){n.n=1;break}return re("Please select a file first"),n.a(2);case 1:if(Z("uploading"),re(""),n.p=2,r=new s.S3Client({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,requestChecksumCalculation:"WHEN_REQUIRED",credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),l=(new Date).toISOString(),c=t.slugifyFileName("".concat(_||"anonymous","-").concat(l,"-").concat(R.name)),u=t.IN_DEV_MODE?"test-env__".concat(c):c,d="video/*"===v?process.env.NEXT_PUBLIC_AWS_LOCATION:process.env.NEXT_PUBLIC_AWS_LOCATION_FILES,p=process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",h="".concat(d,"/").concat(u),!(R.size<104857600)){n.n=4;break}return V(10),x=new s.PutObjectCommand({Bucket:p,Key:h,Body:R,ContentType:R.type,ACL:"public-read"}),m=setInterval(function(){V(function(e){return Math.min(e+5,95)})},300),n.n=3,r.send(x);case 3:clearInterval(m),V(100),n.n=5;break;case 4:return(b=new i.Upload({client:r,params:{Bucket:p,Key:h,Body:R,ContentType:R.type,ACL:"public-read"}})).on("httpUploadProgress",function(e){var n=Math.round(e.loaded/e.total*100);V(n)}),n.n=5,b.done();case 5:if(Z("success"),a.openToast("File Uploaded Successfully!"),g={bucket:p,title:R.name,key:u,content_type:R.type,size:R.size,location:o.uploadedFileUrl(h,t.FILE_URL,process.env.NEXT_PUBLIC_AWS_LOCATION_FILES)},!B||!A){n.n=7;break}return n.n=6,ve(g);case 6:(k=n.v)&&(y=k);case 7:ie(function(n){return[].concat(e.toConsumableArray(n),[{response:g,dbId:y,fullS3Key:h}])}),C&&C(g),N&&N(f,g.key),E&&E(j,f,g.key),S&&S(j,w,f,g.key),setTimeout(function(){F(null),Z("idle"),V(0)},2e3),n.n=9;break;case 8:n.p=8,L=n.v,console.error("Upload error:",L),Z("error"),re("Error uploading file. Please try again."),a.openToast("Error uploading file!",400),V(0);case 9:return n.a(2)}},n,null,[[2,8]])}));return function(){return n.apply(this,arguments)}}(),ge=function(){F(null),Z("idle"),V(0),re("")};return n.jsxs("div",{className:"ihub-uploader ".concat(T),children:[u&&n.jsx("h3",{className:"ihub-uploader-header",children:u}),n.jsxs("div",{className:"ihub-uploader-container",children:[!R&&n.jsxs("div",{className:"ihub-uploader-dropzone ".concat(z?"ihub-uploader-dropzone-active":""),onDragOver:function(e){e.preventDefault(),e.stopPropagation(),X(!0)},onDragLeave:function(e){e.preventDefault(),e.stopPropagation(),X(!1)},onDrop:function(e){e.preventDefault(),e.stopPropagation(),X(!1);var n=e.dataTransfer.files;n&&n.length>0&&he(n[0])},onClick:function(){var e;null===(e=de.current)||void 0===e||e.click()},children:[n.jsx("div",{className:"ihub-uploader-icon",children:n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),n.jsx("polyline",{points:"17 8 12 3 7 8"}),n.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]})}),n.jsx("p",{className:"ihub-uploader-text",children:p}),n.jsx("p",{className:"ihub-uploader-hint",children:m>0&&"Maximum file size: ".concat(pe(m))}),n.jsx("input",{ref:de,type:"file",accept:v,onChange:function(e){var n=e.target.files;n&&n.length>0&&he(n[0])},className:"ihub-uploader-input"})]}),R&&n.jsxs("div",{className:"ihub-uploader-preview",children:[n.jsxs("div",{className:"ihub-uploader-file-info",children:[n.jsx("div",{className:"ihub-uploader-file-icon",children:R.type.startsWith("image/")?n.jsx("img",{src:URL.createObjectURL(R),alt:R.name,className:"ihub-uploader-thumbnail"}):n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"}),n.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),n.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),n.jsx("polyline",{points:"10 9 9 9 8 9"})]})}),n.jsxs("div",{className:"ihub-uploader-file-details",children:[n.jsx("p",{className:"ihub-uploader-file-name",children:R.name}),n.jsx("p",{className:"ihub-uploader-file-size",children:pe(R.size)})]})]}),"uploading"===J&&n.jsx("div",{className:"ihub-uploader-progress",children:n.jsx("div",{className:"ihub-uploader-progress-bar",style:{width:"".concat(H,"%")},children:n.jsxs("span",{className:"ihub-uploader-progress-text",children:[H,"%"]})})}),n.jsxs("div",{className:"ihub-uploader-actions",children:["idle"===J&&n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"ihub-uploader-upload-btn ihub-important-btn",onClick:fe,children:"Upload"}),n.jsx("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:ge,children:"Cancel"})]}),"uploading"===J&&n.jsx("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:ge,children:"Cancel"}),"success"===J&&n.jsxs("div",{className:"ihub-uploader-success",children:[n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),n.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),n.jsx("span",{children:"Upload Complete"})]}),"error"===J&&n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"ihub-uploader-retry-btn ihub-important-btn",onClick:fe,children:"Retry"}),n.jsx("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:ge,children:"Cancel"})]})]})]}),se.length>0&&n.jsx("div",{className:"ihub-uploader-thumbs",children:se.map(function(e,r){var t,o=null===(t=e.response.content_type)||void 0===t?void 0:t.startsWith("video/");return n.jsxs("div",{className:"ihub-uploader-thumb",children:[n.jsxs("div",{className:"ihub-uploader-thumb-preview",onClick:function(){return ue(r)},title:"Click to preview",children:[o?n.jsx("video",{src:e.response.location,muted:!0}):n.jsx("img",{src:e.response.location,alt:e.response.title}),o&&n.jsx("span",{className:"ihub-uploader-thumb-badge",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:n.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})})})]}),n.jsx("button",{type:"button",className:"ihub-uploader-thumb-remove",onClick:function(e){e.stopPropagation(),be(r)},title:"Remove",children:n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},r)})}),null!==ce&&se[ce]&&n.jsx("div",{className:"ihub-uploader-lightbox",onClick:function(){return ue(null)},children:n.jsxs("div",{className:"ihub-uploader-lightbox-content",onClick:function(e){return e.stopPropagation()},children:[n.jsx("button",{className:"ihub-uploader-lightbox-close",onClick:function(){return ue(null)},children:n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),ce>0&&n.jsx("button",{className:"ihub-uploader-lightbox-nav ihub-uploader-lightbox-prev",onClick:function(){return ue(ce-1)},children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"15 18 9 12 15 6"})})}),n.jsx("div",{className:"ihub-uploader-lightbox-media",children:null!==(c=se[ce].response.content_type)&&void 0!==c&&c.startsWith("video/")?n.jsx("video",{src:se[ce].response.location,controls:!0,autoPlay:!0}):n.jsx("img",{src:se[ce].response.location,alt:se[ce].response.title})}),ce<se.length-1&&n.jsx("button",{className:"ihub-uploader-lightbox-nav ihub-uploader-lightbox-next",onClick:function(){return ue(ce+1)},children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"9 18 15 12 9 6"})})}),n.jsxs("div",{className:"ihub-uploader-lightbox-info",children:[n.jsx("span",{children:se[ce].response.title}),n.jsxs("span",{children:[ce+1," / ",se.length]})]})]})}),ne&&n.jsxs("div",{className:"ihub-uploader-error",children:[n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),n.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),n.jsx("span",{children:ne})]})]})]})};
2
2
  //# sourceMappingURL=IhubFileUploader.cjs.map
@@ -1,2 +1,2 @@
1
- import{slicedToArray as e,asyncToGenerator as n,regenerator as r,toConsumableArray as t}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as o,jsx as i,Fragment as l}from"react/jsx-runtime";import{useState as a,useRef as s}from"react";import{FILE_URL as c,slugifyFileName as u,IN_DEV_MODE as d,reqOptions as p}from"../../lib/helpFunction.js";import{S3Client as h,PutObjectCommand as v,DeleteObjectCommand as m}from"@aws-sdk/client-s3";import{Upload as f}from"@aws-sdk/lib-storage";import{openToast as b}from"../../lib/modals/modals.js";function g(g){var w,k=g.header,y=g.label,_=void 0===y?"Drag and drop files here or click to browse":y,C=g.accept,N=void 0===C?"*":C,x=g.maxFileSize,E=void 0===x?0:x,L=g.name,B=void 0===L?"upload":L,S=g.module,I=void 0===S?"":S,W=g.step,T=void 0===W?"":W,U=g.username,A=void 0===U?null:U,P=g.onUploadComplete,D=g.setValues,R=g.setModules,j=g.setSteps,K=g.className,z=void 0===K?"":K,M=g.saveEndpoint,O=g.deleteEndpoint,X=g.token,F=g.enableS3Delete,H=void 0!==F&&F,G=g.onRemove,Y=a(null),V=e(Y,2),q=V[0],Q=V[1],J=a(!1),Z=e(J,2),$=Z[0],ee=Z[1],ne=a(0),re=e(ne,2),te=re[0],oe=re[1],ie=a("idle"),le=e(ie,2),ae=le[0],se=le[1],ce=a(""),ue=e(ce,2),de=ue[0],pe=ue[1],he=a([]),ve=e(he,2),me=ve[0],fe=ve[1],be=a(null),ge=e(be,2),we=ge[0],ke=ge[1],ye=s(null),_e=function(e){if(0===e)return"0 Bytes";var n=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,n)).toFixed(2))+" "+["Bytes","KB","MB","GB"][n]},Ce=function(e){pe(""),function(e){var n;if("*"===N)return!0;var r=e.type,t=".".concat(null===(n=e.name.split(".").pop())||void 0===n?void 0:n.toLowerCase());return!!N.split(",").map(function(e){return e.trim()}).some(function(e){return e.startsWith(".")?t===e.toLowerCase():e.endsWith("/*")?r.startsWith("".concat(e.replace("/*",""),"/")):r===e})||(pe("File type not accepted. Please upload: ".concat(N)),!1)}(e)&&function(e){return!(E&&e.size>E&&(pe("File size exceeds the maximum limit of ".concat(_e(E))),1))}(e)&&(Q(e),se("idle"),oe(0))},Ne=function(){var e=n(r().m(function e(n){var t,o,i,l,a,s,c,u;return r().w(function(e){for(;;)switch(e.p=e.n){case 0:if(M&&X){e.n=1;break}return e.a(2,null);case 1:return e.p=1,o=JSON.stringify({file_url:n.location,file_key:n.key,file_name:n.title,file_size:n.size,content_type:n.content_type,media_type:null!==(t=n.content_type)&&void 0!==t&&t.startsWith("video/")?"video":"image"}),i=p("POST",o,X,"json"),e.n=2,fetch(M,i);case 2:if(!(l=e.v).ok){e.n=4;break}return e.n=3,l.json();case 3:return a=e.v,e.a(2,a.id);case 4:return s=console,c=l.status,e.n=5,l.text();case 5:s.error.call(s,"Save to DB failed:",c,e.v),e.n=7;break;case 6:e.p=6,u=e.v,console.error("Save to DB error:",u);case 7:return e.a(2,null)}},e,null,[[1,6]])}));return function(n){return e.apply(this,arguments)}}(),xe=function(){var e=n(r().m(function e(n){var t,o,i,l;return r().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,t=new URL(n),o=t.pathname.replace(/^\//,"")){e.n=1;break}return e.a(2);case 1:return i=new h({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,requestChecksumCalculation:"WHEN_REQUIRED",credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),e.n=2,i.send(new m({Bucket:process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",Key:o}));case 2:e.n=4;break;case 3:e.p=3,l=e.v,console.error("S3 delete error:",l);case 4:return e.a(2)}},e,null,[[0,3]])}));return function(n){return e.apply(this,arguments)}}(),Ee=function(){var e=n(r().m(function e(n){var t,o,i;return r().w(function(e){for(;;)switch(e.p=e.n){case 0:if(O&&X){e.n=1;break}return e.a(2,!1);case 1:return e.p=1,t=p("DELETE",null,X),e.n=2,fetch("".concat(O).concat(n,"/"),t);case 2:return o=e.v,e.a(2,o.ok||404===o.status);case 3:return e.p=3,i=e.v,console.error("DB delete error:",i),e.a(2,!1)}},e,null,[[1,3]])}));return function(n){return e.apply(this,arguments)}}(),Le=function(){var e=n(r().m(function e(n){var t;return r().w(function(e){for(;;)switch(e.n){case 0:if(t=me[n]){e.n=1;break}return e.a(2);case 1:if(!t.dbId||!O){e.n=2;break}return e.n=2,Ee(t.dbId);case 2:if(!H||!t.response.location){e.n=3;break}return e.n=3,xe(t.response.location);case 3:fe(function(e){return e.filter(function(e,r){return r!==n})}),G&&G(t.response),b("File removed");case 4:return e.a(2)}},e)}));return function(n){return e.apply(this,arguments)}}(),Be=function(){var e=n(r().m(function e(){var n,o,i,l,a,s,p,m,g,w,k,y,_,C;return r().w(function(e){for(;;)switch(e.p=e.n){case 0:if(q){e.n=1;break}return pe("Please select a file first"),e.a(2);case 1:if(se("uploading"),pe(""),e.p=2,n=new h({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,requestChecksumCalculation:"WHEN_REQUIRED",credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),o=(new Date).toISOString(),i=u("".concat(A||"anonymous","-").concat(o,"-").concat(q.name)),l=d?"test-env__".concat(i):i,a="video/*"===N?process.env.NEXT_PUBLIC_AWS_LOCATION:process.env.NEXT_PUBLIC_AWS_LOCATION_FILES,s=process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",p="".concat(a,"/").concat(l),!(q.size<104857600)){e.n=4;break}return oe(10),m=new v({Bucket:s,Key:p,Body:q,ContentType:q.type,ACL:"public-read"}),g=setInterval(function(){oe(function(e){return Math.min(e+5,95)})},300),e.n=3,n.send(m);case 3:clearInterval(g),oe(100),e.n=5;break;case 4:return(w=new f({client:n,params:{Bucket:s,Key:p,Body:q,ContentType:q.type,ACL:"public-read"}})).on("httpUploadProgress",function(e){var n=Math.round(e.loaded/e.total*100);oe(n)}),e.n=5,w.done();case 5:if(se("success"),b("File Uploaded Successfully!"),k={bucket:s,title:q.name,key:l,content_type:q.type,size:q.size,location:"".concat(c,"creators/").concat(l)},!M||!X){e.n=7;break}return e.n=6,Ne(k);case 6:(_=e.v)&&(y=_);case 7:fe(function(e){return[].concat(t(e),[{response:k,dbId:y,fullS3Key:p}])}),P&&P(k),D&&D(B,k.key),R&&R(I,B,k.key),j&&j(I,T,B,k.key),setTimeout(function(){Q(null),se("idle"),oe(0)},2e3),e.n=9;break;case 8:e.p=8,C=e.v,console.error("Upload error:",C),se("error"),pe("Error uploading file. Please try again."),b("Error uploading file!",400),oe(0);case 9:return e.a(2)}},e,null,[[2,8]])}));return function(){return e.apply(this,arguments)}}(),Se=function(){Q(null),se("idle"),oe(0),pe("")};return o("div",{className:"ihub-uploader ".concat(z),children:[k&&i("h3",{className:"ihub-uploader-header",children:k}),o("div",{className:"ihub-uploader-container",children:[!q&&o("div",{className:"ihub-uploader-dropzone ".concat($?"ihub-uploader-dropzone-active":""),onDragOver:function(e){e.preventDefault(),e.stopPropagation(),ee(!0)},onDragLeave:function(e){e.preventDefault(),e.stopPropagation(),ee(!1)},onDrop:function(e){e.preventDefault(),e.stopPropagation(),ee(!1);var n=e.dataTransfer.files;n&&n.length>0&&Ce(n[0])},onClick:function(){var e;null===(e=ye.current)||void 0===e||e.click()},children:[i("div",{className:"ihub-uploader-icon",children:o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),i("polyline",{points:"17 8 12 3 7 8"}),i("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]})}),i("p",{className:"ihub-uploader-text",children:_}),i("p",{className:"ihub-uploader-hint",children:E>0&&"Maximum file size: ".concat(_e(E))}),i("input",{ref:ye,type:"file",accept:N,onChange:function(e){var n=e.target.files;n&&n.length>0&&Ce(n[0])},className:"ihub-uploader-input"})]}),q&&o("div",{className:"ihub-uploader-preview",children:[o("div",{className:"ihub-uploader-file-info",children:[i("div",{className:"ihub-uploader-file-icon",children:q.type.startsWith("image/")?i("img",{src:URL.createObjectURL(q),alt:q.name,className:"ihub-uploader-thumbnail"}):o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),i("polyline",{points:"14 2 14 8 20 8"}),i("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),i("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),i("polyline",{points:"10 9 9 9 8 9"})]})}),o("div",{className:"ihub-uploader-file-details",children:[i("p",{className:"ihub-uploader-file-name",children:q.name}),i("p",{className:"ihub-uploader-file-size",children:_e(q.size)})]})]}),"uploading"===ae&&i("div",{className:"ihub-uploader-progress",children:i("div",{className:"ihub-uploader-progress-bar",style:{width:"".concat(te,"%")},children:o("span",{className:"ihub-uploader-progress-text",children:[te,"%"]})})}),o("div",{className:"ihub-uploader-actions",children:["idle"===ae&&o(l,{children:[i("button",{className:"ihub-uploader-upload-btn ihub-important-btn",onClick:Be,children:"Upload"}),i("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:Se,children:"Cancel"})]}),"uploading"===ae&&i("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:Se,children:"Cancel"}),"success"===ae&&o("div",{className:"ihub-uploader-success",children:[o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),i("polyline",{points:"22 4 12 14.01 9 11.01"})]}),i("span",{children:"Upload Complete"})]}),"error"===ae&&o(l,{children:[i("button",{className:"ihub-uploader-retry-btn ihub-important-btn",onClick:Be,children:"Retry"}),i("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:Se,children:"Cancel"})]})]})]}),me.length>0&&i("div",{className:"ihub-uploader-thumbs",children:me.map(function(e,n){var r,t=null===(r=e.response.content_type)||void 0===r?void 0:r.startsWith("video/");return o("div",{className:"ihub-uploader-thumb",children:[o("div",{className:"ihub-uploader-thumb-preview",onClick:function(){return ke(n)},title:"Click to preview",children:[t?i("video",{src:e.response.location,muted:!0}):i("img",{src:e.response.location,alt:e.response.title}),t&&i("span",{className:"ihub-uploader-thumb-badge",children:i("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:i("polygon",{points:"5 3 19 12 5 21 5 3"})})})]}),i("button",{type:"button",className:"ihub-uploader-thumb-remove",onClick:function(e){e.stopPropagation(),Le(n)},title:"Remove",children:o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[i("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),i("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},n)})}),null!==we&&me[we]&&i("div",{className:"ihub-uploader-lightbox",onClick:function(){return ke(null)},children:o("div",{className:"ihub-uploader-lightbox-content",onClick:function(e){return e.stopPropagation()},children:[i("button",{className:"ihub-uploader-lightbox-close",onClick:function(){return ke(null)},children:o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),i("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),we>0&&i("button",{className:"ihub-uploader-lightbox-nav ihub-uploader-lightbox-prev",onClick:function(){return ke(we-1)},children:i("svg",{xmlns:"http://www.w3.org/2000/svg",width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i("polyline",{points:"15 18 9 12 15 6"})})}),i("div",{className:"ihub-uploader-lightbox-media",children:null!==(w=me[we].response.content_type)&&void 0!==w&&w.startsWith("video/")?i("video",{src:me[we].response.location,controls:!0,autoPlay:!0}):i("img",{src:me[we].response.location,alt:me[we].response.title})}),we<me.length-1&&i("button",{className:"ihub-uploader-lightbox-nav ihub-uploader-lightbox-next",onClick:function(){return ke(we+1)},children:i("svg",{xmlns:"http://www.w3.org/2000/svg",width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i("polyline",{points:"9 18 15 12 9 6"})})}),o("div",{className:"ihub-uploader-lightbox-info",children:[i("span",{children:me[we].response.title}),o("span",{children:[we+1," / ",me.length]})]})]})}),de&&o("div",{className:"ihub-uploader-error",children:[o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i("circle",{cx:"12",cy:"12",r:"10"}),i("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),i("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),i("span",{children:de})]})]})]})}export{g as default};
1
+ import{slicedToArray as e,asyncToGenerator as n,regenerator as r,toConsumableArray as t}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as o,jsx as i,Fragment as l}from"react/jsx-runtime";import{useState as a,useRef as s}from"react";import{FILE_URL as c,slugifyFileName as u,IN_DEV_MODE as d,reqOptions as p}from"../../lib/helpFunction.js";import{uploadedFileUrl as h}from"./uploadedFileUrl.js";import{S3Client as v,PutObjectCommand as m,DeleteObjectCommand as f}from"@aws-sdk/client-s3";import{Upload as b}from"@aws-sdk/lib-storage";import{openToast as g}from"../../lib/modals/modals.js";function w(w){var k,y=w.header,_=w.label,C=void 0===_?"Drag and drop files here or click to browse":_,N=w.accept,x=void 0===N?"*":N,E=w.maxFileSize,L=void 0===E?0:E,S=w.name,B=void 0===S?"upload":S,I=w.module,T=void 0===I?"":I,W=w.step,U=void 0===W?"":W,A=w.username,P=void 0===A?null:A,D=w.onUploadComplete,j=w.setValues,R=w.setModules,K=w.setSteps,O=w.className,z=void 0===O?"":O,M=w.saveEndpoint,X=w.deleteEndpoint,F=w.token,H=w.enableS3Delete,G=void 0!==H&&H,Y=w.onRemove,V=a(null),q=e(V,2),Q=q[0],J=q[1],Z=a(!1),$=e(Z,2),ee=$[0],ne=$[1],re=a(0),te=e(re,2),oe=te[0],ie=te[1],le=a("idle"),ae=e(le,2),se=ae[0],ce=ae[1],ue=a(""),de=e(ue,2),pe=de[0],he=de[1],ve=a([]),me=e(ve,2),fe=me[0],be=me[1],ge=a(null),we=e(ge,2),ke=we[0],ye=we[1],_e=s(null),Ce=function(e){if(0===e)return"0 Bytes";var n=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,n)).toFixed(2))+" "+["Bytes","KB","MB","GB"][n]},Ne=function(e){he(""),function(e){var n;if("*"===x)return!0;var r=e.type,t=".".concat(null===(n=e.name.split(".").pop())||void 0===n?void 0:n.toLowerCase());return!!x.split(",").map(function(e){return e.trim()}).some(function(e){return e.startsWith(".")?t===e.toLowerCase():e.endsWith("/*")?r.startsWith("".concat(e.replace("/*",""),"/")):r===e})||(he("File type not accepted. Please upload: ".concat(x)),!1)}(e)&&function(e){return!(L&&e.size>L&&(he("File size exceeds the maximum limit of ".concat(Ce(L))),1))}(e)&&(J(e),ce("idle"),ie(0))},xe=function(){var e=n(r().m(function e(n){var t,o,i,l,a,s,c,u;return r().w(function(e){for(;;)switch(e.p=e.n){case 0:if(M&&F){e.n=1;break}return e.a(2,null);case 1:return e.p=1,o=JSON.stringify({file_url:n.location,file_key:n.key,file_name:n.title,file_size:n.size,content_type:n.content_type,media_type:null!==(t=n.content_type)&&void 0!==t&&t.startsWith("video/")?"video":"image"}),i=p("POST",o,F,"json"),e.n=2,fetch(M,i);case 2:if(!(l=e.v).ok){e.n=4;break}return e.n=3,l.json();case 3:return a=e.v,e.a(2,a.id);case 4:return s=console,c=l.status,e.n=5,l.text();case 5:s.error.call(s,"Save to DB failed:",c,e.v),e.n=7;break;case 6:e.p=6,u=e.v,console.error("Save to DB error:",u);case 7:return e.a(2,null)}},e,null,[[1,6]])}));return function(n){return e.apply(this,arguments)}}(),Ee=function(){var e=n(r().m(function e(n){var t,o,i,l;return r().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,t=new URL(n),o=t.pathname.replace(/^\//,"")){e.n=1;break}return e.a(2);case 1:return i=new v({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,requestChecksumCalculation:"WHEN_REQUIRED",credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),e.n=2,i.send(new f({Bucket:process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",Key:o}));case 2:e.n=4;break;case 3:e.p=3,l=e.v,console.error("S3 delete error:",l);case 4:return e.a(2)}},e,null,[[0,3]])}));return function(n){return e.apply(this,arguments)}}(),Le=function(){var e=n(r().m(function e(n){var t,o,i;return r().w(function(e){for(;;)switch(e.p=e.n){case 0:if(X&&F){e.n=1;break}return e.a(2,!1);case 1:return e.p=1,t=p("DELETE",null,F),e.n=2,fetch("".concat(X).concat(n,"/"),t);case 2:return o=e.v,e.a(2,o.ok||404===o.status);case 3:return e.p=3,i=e.v,console.error("DB delete error:",i),e.a(2,!1)}},e,null,[[1,3]])}));return function(n){return e.apply(this,arguments)}}(),Se=function(){var e=n(r().m(function e(n){var t;return r().w(function(e){for(;;)switch(e.n){case 0:if(t=fe[n]){e.n=1;break}return e.a(2);case 1:if(!t.dbId||!X){e.n=2;break}return e.n=2,Le(t.dbId);case 2:if(!G||!t.response.location){e.n=3;break}return e.n=3,Ee(t.response.location);case 3:be(function(e){return e.filter(function(e,r){return r!==n})}),Y&&Y(t.response),g("File removed");case 4:return e.a(2)}},e)}));return function(n){return e.apply(this,arguments)}}(),Be=function(){var e=n(r().m(function e(){var n,o,i,l,a,s,p,f,w,k,y,_,C,N;return r().w(function(e){for(;;)switch(e.p=e.n){case 0:if(Q){e.n=1;break}return he("Please select a file first"),e.a(2);case 1:if(ce("uploading"),he(""),e.p=2,n=new v({region:process.env.NEXT_PUBLIC_AWS_REGION,endpoint:process.env.NEXT_PUBLIC_AWS_S3_ENDPOINT_URL,requestChecksumCalculation:"WHEN_REQUIRED",credentials:{accessKeyId:process.env.NEXT_PUBLIC_AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.NEXT_PUBLIC_AWS_SECRET_ACCESS_KEY||""}}),o=(new Date).toISOString(),i=u("".concat(P||"anonymous","-").concat(o,"-").concat(Q.name)),l=d?"test-env__".concat(i):i,a="video/*"===x?process.env.NEXT_PUBLIC_AWS_LOCATION:process.env.NEXT_PUBLIC_AWS_LOCATION_FILES,s=process.env.NEXT_PUBLIC_AWS_BUCKET_NAME||"",p="".concat(a,"/").concat(l),!(Q.size<104857600)){e.n=4;break}return ie(10),f=new m({Bucket:s,Key:p,Body:Q,ContentType:Q.type,ACL:"public-read"}),w=setInterval(function(){ie(function(e){return Math.min(e+5,95)})},300),e.n=3,n.send(f);case 3:clearInterval(w),ie(100),e.n=5;break;case 4:return(k=new b({client:n,params:{Bucket:s,Key:p,Body:Q,ContentType:Q.type,ACL:"public-read"}})).on("httpUploadProgress",function(e){var n=Math.round(e.loaded/e.total*100);ie(n)}),e.n=5,k.done();case 5:if(ce("success"),g("File Uploaded Successfully!"),y={bucket:s,title:Q.name,key:l,content_type:Q.type,size:Q.size,location:h(p,c,process.env.NEXT_PUBLIC_AWS_LOCATION_FILES)},!M||!F){e.n=7;break}return e.n=6,xe(y);case 6:(C=e.v)&&(_=C);case 7:be(function(e){return[].concat(t(e),[{response:y,dbId:_,fullS3Key:p}])}),D&&D(y),j&&j(B,y.key),R&&R(T,B,y.key),K&&K(T,U,B,y.key),setTimeout(function(){J(null),ce("idle"),ie(0)},2e3),e.n=9;break;case 8:e.p=8,N=e.v,console.error("Upload error:",N),ce("error"),he("Error uploading file. Please try again."),g("Error uploading file!",400),ie(0);case 9:return e.a(2)}},e,null,[[2,8]])}));return function(){return e.apply(this,arguments)}}(),Ie=function(){J(null),ce("idle"),ie(0),he("")};return o("div",{className:"ihub-uploader ".concat(z),children:[y&&i("h3",{className:"ihub-uploader-header",children:y}),o("div",{className:"ihub-uploader-container",children:[!Q&&o("div",{className:"ihub-uploader-dropzone ".concat(ee?"ihub-uploader-dropzone-active":""),onDragOver:function(e){e.preventDefault(),e.stopPropagation(),ne(!0)},onDragLeave:function(e){e.preventDefault(),e.stopPropagation(),ne(!1)},onDrop:function(e){e.preventDefault(),e.stopPropagation(),ne(!1);var n=e.dataTransfer.files;n&&n.length>0&&Ne(n[0])},onClick:function(){var e;null===(e=_e.current)||void 0===e||e.click()},children:[i("div",{className:"ihub-uploader-icon",children:o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),i("polyline",{points:"17 8 12 3 7 8"}),i("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]})}),i("p",{className:"ihub-uploader-text",children:C}),i("p",{className:"ihub-uploader-hint",children:L>0&&"Maximum file size: ".concat(Ce(L))}),i("input",{ref:_e,type:"file",accept:x,onChange:function(e){var n=e.target.files;n&&n.length>0&&Ne(n[0])},className:"ihub-uploader-input"})]}),Q&&o("div",{className:"ihub-uploader-preview",children:[o("div",{className:"ihub-uploader-file-info",children:[i("div",{className:"ihub-uploader-file-icon",children:Q.type.startsWith("image/")?i("img",{src:URL.createObjectURL(Q),alt:Q.name,className:"ihub-uploader-thumbnail"}):o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),i("polyline",{points:"14 2 14 8 20 8"}),i("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),i("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),i("polyline",{points:"10 9 9 9 8 9"})]})}),o("div",{className:"ihub-uploader-file-details",children:[i("p",{className:"ihub-uploader-file-name",children:Q.name}),i("p",{className:"ihub-uploader-file-size",children:Ce(Q.size)})]})]}),"uploading"===se&&i("div",{className:"ihub-uploader-progress",children:i("div",{className:"ihub-uploader-progress-bar",style:{width:"".concat(oe,"%")},children:o("span",{className:"ihub-uploader-progress-text",children:[oe,"%"]})})}),o("div",{className:"ihub-uploader-actions",children:["idle"===se&&o(l,{children:[i("button",{className:"ihub-uploader-upload-btn ihub-important-btn",onClick:Be,children:"Upload"}),i("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:Ie,children:"Cancel"})]}),"uploading"===se&&i("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:Ie,children:"Cancel"}),"success"===se&&o("div",{className:"ihub-uploader-success",children:[o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),i("polyline",{points:"22 4 12 14.01 9 11.01"})]}),i("span",{children:"Upload Complete"})]}),"error"===se&&o(l,{children:[i("button",{className:"ihub-uploader-retry-btn ihub-important-btn",onClick:Be,children:"Retry"}),i("button",{className:"ihub-uploader-cancel-btn outlined-btn",onClick:Ie,children:"Cancel"})]})]})]}),fe.length>0&&i("div",{className:"ihub-uploader-thumbs",children:fe.map(function(e,n){var r,t=null===(r=e.response.content_type)||void 0===r?void 0:r.startsWith("video/");return o("div",{className:"ihub-uploader-thumb",children:[o("div",{className:"ihub-uploader-thumb-preview",onClick:function(){return ye(n)},title:"Click to preview",children:[t?i("video",{src:e.response.location,muted:!0}):i("img",{src:e.response.location,alt:e.response.title}),t&&i("span",{className:"ihub-uploader-thumb-badge",children:i("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:i("polygon",{points:"5 3 19 12 5 21 5 3"})})})]}),i("button",{type:"button",className:"ihub-uploader-thumb-remove",onClick:function(e){e.stopPropagation(),Se(n)},title:"Remove",children:o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[i("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),i("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},n)})}),null!==ke&&fe[ke]&&i("div",{className:"ihub-uploader-lightbox",onClick:function(){return ye(null)},children:o("div",{className:"ihub-uploader-lightbox-content",onClick:function(e){return e.stopPropagation()},children:[i("button",{className:"ihub-uploader-lightbox-close",onClick:function(){return ye(null)},children:o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),i("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),ke>0&&i("button",{className:"ihub-uploader-lightbox-nav ihub-uploader-lightbox-prev",onClick:function(){return ye(ke-1)},children:i("svg",{xmlns:"http://www.w3.org/2000/svg",width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i("polyline",{points:"15 18 9 12 15 6"})})}),i("div",{className:"ihub-uploader-lightbox-media",children:null!==(k=fe[ke].response.content_type)&&void 0!==k&&k.startsWith("video/")?i("video",{src:fe[ke].response.location,controls:!0,autoPlay:!0}):i("img",{src:fe[ke].response.location,alt:fe[ke].response.title})}),ke<fe.length-1&&i("button",{className:"ihub-uploader-lightbox-nav ihub-uploader-lightbox-next",onClick:function(){return ye(ke+1)},children:i("svg",{xmlns:"http://www.w3.org/2000/svg",width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i("polyline",{points:"9 18 15 12 9 6"})})}),o("div",{className:"ihub-uploader-lightbox-info",children:[i("span",{children:fe[ke].response.title}),o("span",{children:[ke+1," / ",fe.length]})]})]})}),pe&&o("div",{className:"ihub-uploader-error",children:[o("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i("circle",{cx:"12",cy:"12",r:"10"}),i("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),i("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),i("span",{children:pe})]})]})]})}export{w as default};
2
2
  //# sourceMappingURL=IhubFileUploader.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=function(n){return n.split("/").filter(Boolean)},t=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!t)return"";try{e=new URL(t)}catch(n){return t.endsWith("/")?t:"".concat(t,"/")}var o=n(e.pathname),c=function(n,t){for(var e=Math.min(n.length,t.length);e>0;e--)if(n.slice(n.length-e).every(function(n,e){return n===t[e]}))return e;return 0}(o,n(r)),i=o.slice(0,o.length-c),a=i.length?"/".concat(i.join("/"),"/"):"/";return"".concat(e.origin).concat(a)};exports.cdnBaseUrl=t,exports.uploadedFileUrl=function(e,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",c=n(e).join("/");return"".concat(t(r,o)).concat(c)};
2
+ //# sourceMappingURL=uploadedFileUrl.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadedFileUrl.cjs","sources":["../../../../../src/components/forms/uploads/uploadedFileUrl.ts"],"sourcesContent":["/**\n * Public URL of an object the uploaders wrote to S3 / Spaces.\n *\n * The uploaders write to `${keyLocation}/${key}` where keyLocation is either\n * NEXT_PUBLIC_AWS_LOCATION (videos) or NEXT_PUBLIC_AWS_LOCATION_FILES. They\n * used to report `${FILE_URL}creators/${key}`, which is only right for the\n * files location, so every video upload returned a URL that 403s.\n *\n * NEXT_PUBLIC_FILE_URL is the CDN origin plus the start of the files\n * location (e.g. `https://cdn.example.com/prod_env/social-files/` for\n * `prod_env/social-files/creators`). The CDN base is FILE_URL with that\n * shared tail removed, and the URL is that base plus the key actually written.\n */\n\nconst segments = (path: string): string[] => path.split(\"/\").filter(Boolean);\n\n/** Largest k where the last k items of `tail` equal the first k of `head`. */\nconst overlap = (tail: string[], head: string[]): number => {\n for (let k = Math.min(tail.length, head.length); k > 0; k--) {\n const end = tail.slice(tail.length - k);\n if (end.every((part, i) => part === head[i])) return k;\n }\n return 0;\n};\n\n/** CDN base (ending in \"/\") that object keys are appended to. */\nexport const cdnBaseUrl = (fileUrl: string, filesLocation = \"\"): string => {\n if (!fileUrl) return \"\";\n let url: URL;\n try {\n url = new URL(fileUrl);\n } catch {\n return fileUrl.endsWith(\"/\") ? fileUrl : `${fileUrl}/`;\n }\n const pathParts = segments(url.pathname);\n const shared = overlap(pathParts, segments(filesLocation));\n const baseParts = pathParts.slice(0, pathParts.length - shared);\n const basePath = baseParts.length ? `/${baseParts.join(\"/\")}/` : \"/\";\n return `${url.origin}${basePath}`;\n};\n\n/** Public URL for `fullKey`, the exact key passed to S3 as `Key`. */\nexport const uploadedFileUrl = (\n fullKey: string,\n fileUrl: string,\n filesLocation = \"\"\n): string => {\n const key = segments(fullKey).join(\"/\");\n return `${cdnBaseUrl(fileUrl, filesLocation)}${key}`;\n};\n"],"names":["segments","path","split","filter","Boolean","cdnBaseUrl","fileUrl","url","filesLocation","arguments","length","undefined","URL","_unused","endsWith","concat","pathParts","pathname","shared","tail","head","k","Math","min","slice","every","part","i","overlap","baseParts","basePath","join","origin","fullKey","key"],"mappings":"oEAcA,IAAMA,EAAW,SAACC,GAAY,OAAeA,EAAKC,MAAM,KAAKC,OAAOC,QAAQ,EAY/DC,EAAa,SAACC,GAA+C,IAEpEC,EAFsCC,EAAaC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,GAC1D,IAAKH,EAAS,MAAO,GAErB,IACEC,EAAM,IAAIK,IAAIN,EACf,CAAC,MAAAO,GACA,OAAOP,EAAQQ,SAAS,KAAOR,EAAOS,GAAAA,OAAMT,EAAU,IACvD,CACD,IAAMU,EAAYhB,EAASO,EAAIU,UACzBC,EAlBQ,SAACC,EAAgBC,GAC/B,IAAK,IAAIC,EAAIC,KAAKC,IAAIJ,EAAKT,OAAQU,EAAKV,QAASW,EAAI,EAAGA,IAEtD,GADYF,EAAKK,MAAML,EAAKT,OAASW,GAC7BI,MAAM,SAACC,EAAMC,GAAC,OAAKD,IAASN,EAAKO,KAAK,OAAON,EAEvD,OAAO,CACT,CAYiBO,CAAQZ,EAAWhB,EAASQ,IACrCqB,EAAYb,EAAUQ,MAAM,EAAGR,EAAUN,OAASQ,GAClDY,EAAWD,EAAUnB,OAAMK,IAAAA,OAAOc,EAAUE,KAAK,UAAU,IACjE,MAAAhB,GAAAA,OAAUR,EAAIyB,QAAMjB,OAAGe,EACzB,+CAG+B,SAC7BG,EACA3B,GAEU,IADVE,EAAaC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,GAEVyB,EAAMlC,EAASiC,GAASF,KAAK,KACnC,MAAAhB,GAAAA,OAAUV,EAAWC,EAASE,IAAcO,OAAGmB,EACjD"}
@@ -0,0 +1,2 @@
1
+ var n=function(n){return n.split("/").filter(Boolean)},t=function(t){var r,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!t)return"";try{r=new URL(t)}catch(n){return t.endsWith("/")?t:"".concat(t,"/")}var c=n(r.pathname),o=function(n,t){for(var r=Math.min(n.length,t.length);r>0;r--)if(n.slice(n.length-r).every(function(n,r){return n===t[r]}))return r;return 0}(c,n(e)),i=c.slice(0,c.length-o),a=i.length?"/".concat(i.join("/"),"/"):"/";return"".concat(r.origin).concat(a)},r=function(r,e){var c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",o=n(r).join("/");return"".concat(t(e,c)).concat(o)};export{t as cdnBaseUrl,r as uploadedFileUrl};
2
+ //# sourceMappingURL=uploadedFileUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadedFileUrl.js","sources":["../../../../../src/components/forms/uploads/uploadedFileUrl.ts"],"sourcesContent":["/**\n * Public URL of an object the uploaders wrote to S3 / Spaces.\n *\n * The uploaders write to `${keyLocation}/${key}` where keyLocation is either\n * NEXT_PUBLIC_AWS_LOCATION (videos) or NEXT_PUBLIC_AWS_LOCATION_FILES. They\n * used to report `${FILE_URL}creators/${key}`, which is only right for the\n * files location, so every video upload returned a URL that 403s.\n *\n * NEXT_PUBLIC_FILE_URL is the CDN origin plus the start of the files\n * location (e.g. `https://cdn.example.com/prod_env/social-files/` for\n * `prod_env/social-files/creators`). The CDN base is FILE_URL with that\n * shared tail removed, and the URL is that base plus the key actually written.\n */\n\nconst segments = (path: string): string[] => path.split(\"/\").filter(Boolean);\n\n/** Largest k where the last k items of `tail` equal the first k of `head`. */\nconst overlap = (tail: string[], head: string[]): number => {\n for (let k = Math.min(tail.length, head.length); k > 0; k--) {\n const end = tail.slice(tail.length - k);\n if (end.every((part, i) => part === head[i])) return k;\n }\n return 0;\n};\n\n/** CDN base (ending in \"/\") that object keys are appended to. */\nexport const cdnBaseUrl = (fileUrl: string, filesLocation = \"\"): string => {\n if (!fileUrl) return \"\";\n let url: URL;\n try {\n url = new URL(fileUrl);\n } catch {\n return fileUrl.endsWith(\"/\") ? fileUrl : `${fileUrl}/`;\n }\n const pathParts = segments(url.pathname);\n const shared = overlap(pathParts, segments(filesLocation));\n const baseParts = pathParts.slice(0, pathParts.length - shared);\n const basePath = baseParts.length ? `/${baseParts.join(\"/\")}/` : \"/\";\n return `${url.origin}${basePath}`;\n};\n\n/** Public URL for `fullKey`, the exact key passed to S3 as `Key`. */\nexport const uploadedFileUrl = (\n fullKey: string,\n fileUrl: string,\n filesLocation = \"\"\n): string => {\n const key = segments(fullKey).join(\"/\");\n return `${cdnBaseUrl(fileUrl, filesLocation)}${key}`;\n};\n"],"names":["segments","path","split","filter","Boolean","cdnBaseUrl","fileUrl","url","filesLocation","arguments","length","undefined","URL","_unused","endsWith","concat","pathParts","pathname","shared","tail","head","k","Math","min","slice","every","part","i","overlap","baseParts","basePath","join","origin","uploadedFileUrl","fullKey","key"],"mappings":"AAcA,IAAMA,EAAW,SAACC,GAAY,OAAeA,EAAKC,MAAM,KAAKC,OAAOC,QAAQ,EAY/DC,EAAa,SAACC,GAA+C,IAEpEC,EAFsCC,EAAaC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,GAC1D,IAAKH,EAAS,MAAO,GAErB,IACEC,EAAM,IAAIK,IAAIN,EACf,CAAC,MAAAO,GACA,OAAOP,EAAQQ,SAAS,KAAOR,EAAOS,GAAAA,OAAMT,EAAU,IACvD,CACD,IAAMU,EAAYhB,EAASO,EAAIU,UACzBC,EAlBQ,SAACC,EAAgBC,GAC/B,IAAK,IAAIC,EAAIC,KAAKC,IAAIJ,EAAKT,OAAQU,EAAKV,QAASW,EAAI,EAAGA,IAEtD,GADYF,EAAKK,MAAML,EAAKT,OAASW,GAC7BI,MAAM,SAACC,EAAMC,GAAC,OAAKD,IAASN,EAAKO,KAAK,OAAON,EAEvD,OAAO,CACT,CAYiBO,CAAQZ,EAAWhB,EAASQ,IACrCqB,EAAYb,EAAUQ,MAAM,EAAGR,EAAUN,OAASQ,GAClDY,EAAWD,EAAUnB,OAAMK,IAAAA,OAAOc,EAAUE,KAAK,UAAU,IACjE,MAAAhB,GAAAA,OAAUR,EAAIyB,QAAMjB,OAAGe,EACzB,EAGaG,EAAkB,SAC7BC,EACA5B,GAEU,IADVE,EAAaC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,GAEV0B,EAAMnC,EAASkC,GAASH,KAAK,KACnC,MAAAhB,GAAAA,OAAUV,EAAWC,EAASE,IAAcO,OAAGoB,EACjD"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_rollupPluginBabelHelpers.cjs"),t=require("react/jsx-runtime"),a=require("react"),r=require("@mui/icons-material/Search"),n=require("@mui/icons-material/Close"),i=require("@mui/icons-material/SearchOff"),l=require("./sideNavMatch.cjs");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=s(r),u=s(n),o=s(i);exports.default=function(r){var n,i,s=r.items,d=r.config,h=r.idPrefix,v=r.renderResult,m=r.shortcutEnabled,f=r.children,p=a.useState(""),b=e.slicedToArray(p,2),x=b[0],j=b[1],g=a.useState(0),y=e.slicedToArray(g,2),N=y[0],k=y[1],E=a.useRef(null),C=void 0===d.shortcut?"/":d.shortcut,S=l.searchSideNav(s,x),A=x.trim().length>0,q="".concat(h,"-results");a.useEffect(function(){if(C&&m){var e=function(e){if(!(e.key!==C||e.metaKey||e.ctrlKey||e.altKey||(t=e.target,a=t,a&&(a.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(a.tagName))))){var t,a,r=E.current;r&&0!==r.getClientRects().length&&(e.preventDefault(),r.focus())}};return document.addEventListener("keydown",e),function(){return document.removeEventListener("keydown",e)}}},[C,m]);var D=function(e){var t;j(e),k(0),null===(t=d.onSearch)||void 0===t||t.call(d,e)},T=A?S.length?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ihub-sidenav-results-meta","aria-live":"polite",children:[S.length," ",1===S.length?"match":"matches"]}),t.jsx("ul",{className:"ihub-sidenav-results",id:q,role:"listbox",children:S.map(function(a,r){var n=l.splitNavMatch(a.item.title,x),i=e.slicedToArray(n,3),s=i[0],c=i[1],u=i[2];return t.jsx("li",{role:"presentation",children:v(a,{id:"".concat(q,"-").concat(r),selected:r===N,label:t.jsxs("span",{className:"ihub-sidenav-result-text",children:[t.jsxs("span",{className:"ihub-sidenav-result-title",children:[s,c&&t.jsx("mark",{children:c}),u]}),a.trail.length>0&&t.jsx("span",{className:"ihub-sidenav-result-trail",children:a.trail.join(" › ")})]}),onMouseEnter:function(){return k(r)},onActivated:function(){return D("")}})},"".concat(a.item.id,"-").concat(r))})})]}):t.jsxs("div",{className:"ihub-sidenav-search-empty",role:"status",children:[t.jsx("span",{className:"ihub-sidenav-search-empty-icon","aria-hidden":"true",children:t.jsx(o.default,{})}),d.emptyMessage?d.emptyMessage(x.trim()):t.jsxs("strong",{children:["Nothing called “",x.trim(),"”"]})]}):null;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"ihub-sidenav-search",children:t.jsxs("div",{className:"ihub-sidenav-search-box",children:[t.jsx(c.default,{"aria-hidden":"true"}),t.jsx("input",{ref:E,type:"search",className:"ihub-sidenav-search-input",placeholder:null!==(n=d.placeholder)&&void 0!==n?n:"Search menu",value:x,onChange:function(e){return D(e.target.value)},onKeyDown:function(e){var t;if("Escape"===e.key)return e.preventDefault(),void(x?D(""):null===(t=E.current)||void 0===t||t.blur());if(S.length)if("ArrowDown"===e.key)e.preventDefault(),k((N+1)%S.length);else if("ArrowUp"===e.key)e.preventDefault(),k(N<=0?S.length-1:N-1);else if("Enter"===e.key){var a;e.preventDefault(),null===(a=document.getElementById("".concat(q,"-").concat(N)))||void 0===a||a.click()}},role:"combobox","aria-label":null!==(i=d.placeholder)&&void 0!==i?i:"Search menu","aria-expanded":A,"aria-controls":q,"aria-autocomplete":"list","aria-activedescendant":A&&S.length?"".concat(q,"-").concat(N):void 0,autoComplete:"off",spellCheck:!1}),x?t.jsx("button",{type:"button",className:"ihub-sidenav-search-clear","aria-label":"Clear search",onClick:function(){var e;D(""),null===(e=E.current)||void 0===e||e.focus()},children:t.jsx(u.default,{})}):C&&t.jsx("kbd",{className:"ihub-sidenav-kbd",title:"Press ".concat(C," to search"),children:C})]})}),f(T)]})};
2
+ //# sourceMappingURL=SideNavSearch.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SideNavSearch.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import{slicedToArray as e}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as t,Fragment as a,jsx as r}from"react/jsx-runtime";import{useState as n,useRef as i,useEffect as l}from"react";import c from"@mui/icons-material/Search";import o from"@mui/icons-material/Close";import s from"@mui/icons-material/SearchOff";import{searchSideNav as u,splitNavMatch as d}from"./sideNavMatch.js";var h=function(h){var m,v,f=h.items,p=h.config,b=h.idPrefix,g=h.renderResult,y=h.shortcutEnabled,N=h.children,k=n(""),E=e(k,2),C=E[0],x=E[1],D=n(0),w=e(D,2),A=w[0],S=w[1],T=i(null),j=void 0===p.shortcut?"/":p.shortcut,K=u(f,C),M=C.trim().length>0,P="".concat(b,"-results");l(function(){if(j&&y){var e=function(e){if(!(e.key!==j||e.metaKey||e.ctrlKey||e.altKey||(t=e.target,a=t,a&&(a.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(a.tagName))))){var t,a,r=T.current;r&&0!==r.getClientRects().length&&(e.preventDefault(),r.focus())}};return document.addEventListener("keydown",e),function(){return document.removeEventListener("keydown",e)}}},[j,y]);var L=function(e){var t;x(e),S(0),null===(t=p.onSearch)||void 0===t||t.call(p,e)},R=M?K.length?t(a,{children:[t("div",{className:"ihub-sidenav-results-meta","aria-live":"polite",children:[K.length," ",1===K.length?"match":"matches"]}),r("ul",{className:"ihub-sidenav-results",id:P,role:"listbox",children:K.map(function(a,n){var i=d(a.item.title,C),l=e(i,3),c=l[0],o=l[1],s=l[2];return r("li",{role:"presentation",children:g(a,{id:"".concat(P,"-").concat(n),selected:n===A,label:t("span",{className:"ihub-sidenav-result-text",children:[t("span",{className:"ihub-sidenav-result-title",children:[c,o&&r("mark",{children:o}),s]}),a.trail.length>0&&r("span",{className:"ihub-sidenav-result-trail",children:a.trail.join(" › ")})]}),onMouseEnter:function(){return S(n)},onActivated:function(){return L("")}})},"".concat(a.item.id,"-").concat(n))})})]}):t("div",{className:"ihub-sidenav-search-empty",role:"status",children:[r("span",{className:"ihub-sidenav-search-empty-icon","aria-hidden":"true",children:r(s,{})}),p.emptyMessage?p.emptyMessage(C.trim()):t("strong",{children:["Nothing called “",C.trim(),"”"]})]}):null;return t(a,{children:[r("div",{className:"ihub-sidenav-search",children:t("div",{className:"ihub-sidenav-search-box",children:[r(c,{"aria-hidden":"true"}),r("input",{ref:T,type:"search",className:"ihub-sidenav-search-input",placeholder:null!==(m=p.placeholder)&&void 0!==m?m:"Search menu",value:C,onChange:function(e){return L(e.target.value)},onKeyDown:function(e){var t;if("Escape"===e.key)return e.preventDefault(),void(C?L(""):null===(t=T.current)||void 0===t||t.blur());if(K.length)if("ArrowDown"===e.key)e.preventDefault(),S((A+1)%K.length);else if("ArrowUp"===e.key)e.preventDefault(),S(A<=0?K.length-1:A-1);else if("Enter"===e.key){var a;e.preventDefault(),null===(a=document.getElementById("".concat(P,"-").concat(A)))||void 0===a||a.click()}},role:"combobox","aria-label":null!==(v=p.placeholder)&&void 0!==v?v:"Search menu","aria-expanded":M,"aria-controls":P,"aria-autocomplete":"list","aria-activedescendant":M&&K.length?"".concat(P,"-").concat(A):void 0,autoComplete:"off",spellCheck:!1}),C?r("button",{type:"button",className:"ihub-sidenav-search-clear","aria-label":"Clear search",onClick:function(){var e;L(""),null===(e=T.current)||void 0===e||e.focus()},children:r(o,{})}):j&&r("kbd",{className:"ihub-sidenav-kbd",title:"Press ".concat(j," to search"),children:j})]})}),N(R)]})};export{h as default};
2
+ //# sourceMappingURL=SideNavSearch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SideNavSearch.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}