jamespot-react-components 1.3.164 → 1.3.165

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.
@@ -3281,7 +3281,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
3281
3281
  background-color: ${e=>e.theme.color.primary};
3282
3282
  color: ${e=>e.theme.color.white};
3283
3283
  }
3284
- `,$E=function(e,t){const[r,n]=h.useState(t);return h.useEffect(()=>{const i=({key:a})=>{a===e&&!r&&n(!0)},o=({key:a})=>{a===e&&r&&n(!1)};return window.addEventListener("keydown",i),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",o)}},[e,r]),{keyPressed:r,setKeyPressed:n}},CL=25,O0e=({index:e,total:t,onRelease:r})=>{const n=$E("ArrowLeft",void 0),i=$E("ArrowRight",void 0);return h.useEffect(()=>{!n.keyPressed&&n.keyPressed!==void 0&&r("prev")},[n.keyPressed]),h.useEffect(()=>{!i.keyPressed&&i.keyPressed!==void 0&&r("next")},[i.keyPressed]),l.jsxs(T0e,{children:[l.jsx(wL,{onMouseDown:()=>n.setKeyPressed(!0),onMouseUp:()=>n.setKeyPressed(!1),children:l.jsx("div",{className:n.keyPressed?"left down":"left",children:l.jsx(ie,{name:"icon-angle-left",size:CL,color:"#fff"})})}),l.jsxs(I0e,{children:[e+1,"/",t]}),l.jsx(wL,{onMouseDown:()=>i.setKeyPressed(!0),onMouseUp:()=>i.setKeyPressed(!1),children:l.jsx("div",{className:i.keyPressed?"right down":"right",children:l.jsx(ie,{name:"icon-angle-right",size:CL,color:"#fff"})})})]})},j0e=({item:e,options:t})=>{const r=F.useIntl();return l.jsx(_a,{options:t.map(n=>({label:r.formatMessage({id:n.label}),onClick:()=>n.onClick(e)})),small:!0,label:r.formatMessage({id:"FILE_Viewer_Open_With"}),color:"primary"})},Xd=({item:e,options:t,children:r})=>{const n=F.useIntl(),i=e?.downloadHref;return l.jsxs(C0e,{children:[l.jsx(E0e,{children:r}),e!==void 0&&(i!==void 0||t!==void 0)&&l.jsxs(B0e,{children:[i!==void 0&&l.jsx(pe,{label:n.formatMessage({id:"GLOBAL_Download"}),onClick:()=>{const o=document.createElement("a");o.href=i,o.click(),o.remove()}}),t!==void 0&&l.jsx(j0e,{item:e,options:t})]})]})},P0e=({children:e})=>l.jsx(w0e,{children:e}),k0e=({children:e})=>l.jsx(S0e,{"data-cy":"file-viewer-image",children:e}),L0e=({children:e})=>l.jsx(D0e,{children:e}),M0e=({item:e,openWithOptions:t})=>{const r=N.getFileFamily(e.mimetype),n=e.mimetype,i=e.url,o=t.find(a=>a.condition(e))?.options;switch(r){default:return l.jsx(Xd,{item:e,options:o,children:l.jsx(ku,{mimetype:n})});case"application":return l.jsx(Xd,{item:e,options:o,children:l.jsx(ku,{mimetype:n})});case"audio":return i!==void 0?l.jsx(P0e,{children:l.jsx(EE,{uri:i,mimetype:n})}):l.jsx(Xd,{item:e,options:o,children:l.jsx(EE,{mimetype:n})});case"video":return i!==void 0?l.jsx(L0e,{children:l.jsx(Im,{uri:i,mimetype:n})}):l.jsx(Xd,{item:e,options:o,children:l.jsx(Im,{mimetype:n})});case"gif":case"image":return i!==void 0?l.jsx(k0e,{children:l.jsx(Iy,{uri:i,mimetype:n,size:1900})}):l.jsx(Xd,{item:e,options:o,children:l.jsx(ku,{mimetype:n})})}},U5=({files:e,children:t,openWithOptions:r,onReadFile:n})=>{const i=F.useIntl(),[o,a]=h.useState(-1),s=e[o];h.useEffect(()=>{if(n&&o>-1){const c=e[o];c&&n(c)}},[o,e,n]);const A={open:o!==-1,portalId:"react-modal",variant:"full-screen",maxHeight:"100%",closeHandler:()=>{a(-1)}};return l.jsxs(l.Fragment,{children:[t(c=>{const d=e.find(f=>f.key===c);if(!d)return;const u=r.find(f=>f.condition(d));u&&u.options.length>0?u.options[0].onClick(d):a(e.findIndex(f=>f.key===c))}),l.jsx(Br,{...A,children:l.jsx(zr,{onClickIconClose:A.closeHandler,title:i.formatMessage({id:"FILE_Viewer_Preview"}),isFull:!0,children:l.jsxs(p0e,{"data-testid":"file-viewer",children:[l.jsx(m0e,{children:l.jsx(v0e,{children:s&&l.jsxs(l.Fragment,{children:[s.title,s.downloadHref!==void 0&&l.jsxs(y0e,{href:s.downloadHref,children:[l.jsx(Ae,{color:"grey4",children:i.formatMessage({id:"GLOBAL_Download"})}),l.jsx(ie,{name:"icon-download",color:"grey4",size:16})]})]})})}),l.jsx(b0e,{children:s&&l.jsx(M0e,{item:s,openWithOptions:r})}),l.jsx(x0e,{children:l.jsx(O0e,{total:e.length,index:o,onRelease:c=>{switch(c){case"next":a(o<e.length-1?o+1:0);break;case"prev":a(o===0?e.length-1:o-1);break}}})})]})})})]})},Zf=({files:e,size:t=Q5,children:r,openWithOptions:n,allowDownload:i=!0,onReadFile:o})=>{const a=h.useMemo(()=>e.map(A=>g0e(A,t,i)),[e,t,i]),s=n.map(({condition:A,options:c})=>({condition:d=>A(d.file),options:c.map(d=>({label:d.label,onClick:u=>d.onClick(u.file)}))}));return l.jsx(U5,{files:a,openWithOptions:s,onReadFile:o&&(A=>o(A.file)),children:r})};function z5(e,t=!0){const[r,n]=h.useState({left:!1,right:!1});return h.useEffect(()=>{if(!t)return;const i=e.current;if(!i)return;let o=0;const a=()=>{cancelAnimationFrame(o),o=requestAnimationFrame(()=>{const{scrollLeft:A,scrollWidth:c,clientWidth:d}=i;n({left:A>0,right:A+d<c-1})})};a(),i.addEventListener("scroll",a,{passive:!0});const s=new ResizeObserver(a);return s.observe(i),()=>{i.removeEventListener("scroll",a),s.disconnect(),cancelAnimationFrame(o)}},[e,t]),r}const zm={medium:{avatar:40,radius:"sm",space:"sm"},large:{avatar:80,radius:"md",space:"md"}},W5=v.div`
3284
+ `,$E=function(e,t){const[r,n]=h.useState(t);return h.useEffect(()=>{const i=({key:a})=>{a===e&&!r&&n(!0)},o=({key:a})=>{a===e&&r&&n(!1)};return window.addEventListener("keydown",i),window.addEventListener("keyup",o),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",o)}},[e,r]),{keyPressed:r,setKeyPressed:n}},CL=25,O0e=({index:e,total:t,onRelease:r})=>{const n=$E("ArrowLeft",void 0),i=$E("ArrowRight",void 0);return h.useEffect(()=>{!n.keyPressed&&n.keyPressed!==void 0&&r("prev")},[n.keyPressed]),h.useEffect(()=>{!i.keyPressed&&i.keyPressed!==void 0&&r("next")},[i.keyPressed]),l.jsxs(T0e,{children:[l.jsx(wL,{onMouseDown:()=>n.setKeyPressed(!0),onMouseUp:()=>n.setKeyPressed(!1),children:l.jsx("div",{className:n.keyPressed?"left down":"left",children:l.jsx(ie,{name:"icon-angle-left",size:CL,color:"#fff"})})}),l.jsxs(I0e,{children:[e+1,"/",t]}),l.jsx(wL,{onMouseDown:()=>i.setKeyPressed(!0),onMouseUp:()=>i.setKeyPressed(!1),children:l.jsx("div",{className:i.keyPressed?"right down":"right",children:l.jsx(ie,{name:"icon-angle-right",size:CL,color:"#fff"})})})]})},j0e=({item:e,options:t})=>{const r=F.useIntl();return l.jsx(_a,{options:t.map(n=>({label:r.formatMessage({id:n.label}),onClick:()=>n.onClick(e)})),small:!0,label:r.formatMessage({id:"FILE_Viewer_Open_With"}),color:"primary"})},Xd=({item:e,options:t,children:r})=>{const n=F.useIntl(),i=e?.downloadHref;return l.jsxs(C0e,{children:[l.jsx(E0e,{children:r}),e!==void 0&&(i!==void 0||t!==void 0)&&l.jsxs(B0e,{children:[i!==void 0&&l.jsx(pe,{label:n.formatMessage({id:"GLOBAL_Download"}),onClick:()=>{const o=document.createElement("a");o.href=i,o.click(),o.remove()}}),t!==void 0&&l.jsx(j0e,{item:e,options:t})]})]})},P0e=({children:e})=>l.jsx(w0e,{children:e}),k0e=({children:e})=>l.jsx(S0e,{"data-cy":"file-viewer-image",children:e}),L0e=({children:e})=>l.jsx(D0e,{children:e}),M0e=({item:e,openWithOptions:t})=>{const r=N.getFileFamily(e.mimetype),n=e.mimetype,i=e.url,o=t.find(a=>a.condition(e))?.options;switch(r){default:return l.jsx(Xd,{item:e,options:o,children:l.jsx(ku,{mimetype:n})});case"application":return l.jsx(Xd,{item:e,options:o,children:l.jsx(ku,{mimetype:n})});case"audio":return i!==void 0?l.jsx(P0e,{children:l.jsx(EE,{uri:i,mimetype:n})}):l.jsx(Xd,{item:e,options:o,children:l.jsx(EE,{mimetype:n})});case"video":return i!==void 0?l.jsx(L0e,{children:l.jsx(Im,{uri:i,mimetype:n})}):l.jsx(Xd,{item:e,options:o,children:l.jsx(Im,{mimetype:n})});case"gif":case"image":return i!==void 0?l.jsx(k0e,{children:l.jsx(Iy,{uri:i,mimetype:n,size:1900})}):l.jsx(Xd,{item:e,options:o,children:l.jsx(ku,{mimetype:n})})}},U5=({files:e,children:t,openWithOptions:r,onReadFile:n,onOpen:i})=>{const o=F.useIntl(),[a,s]=h.useState(-1),A=e[a];h.useEffect(()=>{if(n&&a>-1){const d=e[a];d&&n(d)}},[a,e,n]);const c={open:a!==-1,portalId:"react-modal",variant:"full-screen",maxHeight:"100%",closeHandler:()=>{s(-1)}};return l.jsxs(l.Fragment,{children:[t(d=>{const u=e.find(g=>g.key===d);if(!u)return;const f=r.find(g=>g.condition(u));f&&f.options.length>0?f.options[0].onClick(u):(i?.(u),s(e.findIndex(g=>g.key===d)))}),l.jsx(Br,{...c,children:l.jsx(zr,{onClickIconClose:c.closeHandler,title:o.formatMessage({id:"FILE_Viewer_Preview"}),isFull:!0,children:l.jsxs(p0e,{"data-testid":"file-viewer",children:[l.jsx(m0e,{children:l.jsx(v0e,{children:A&&l.jsxs(l.Fragment,{children:[A.title,A.downloadHref!==void 0&&l.jsxs(y0e,{href:A.downloadHref,children:[l.jsx(Ae,{color:"grey4",children:o.formatMessage({id:"GLOBAL_Download"})}),l.jsx(ie,{name:"icon-download",color:"grey4",size:16})]})]})})}),l.jsx(b0e,{children:A&&l.jsx(M0e,{item:A,openWithOptions:r})}),l.jsx(x0e,{children:l.jsx(O0e,{total:e.length,index:a,onRelease:d=>{switch(d){case"next":s(a<e.length-1?a+1:0);break;case"prev":s(a===0?e.length-1:a-1);break}}})})]})})})]})},Zf=({files:e,size:t=Q5,children:r,openWithOptions:n,allowDownload:i=!0,onReadFile:o,onOpen:a})=>{const s=h.useMemo(()=>e.map(c=>g0e(c,t,i)),[e,t,i]),A=n.map(({condition:c,options:d})=>({condition:u=>c(u.file),options:d.map(u=>({label:u.label,onClick:f=>u.onClick(f.file)}))}));return l.jsx(U5,{files:s,openWithOptions:A,onReadFile:o&&(c=>o(c.file)),onOpen:a&&(c=>a(c.file)),children:r})};function z5(e,t=!0){const[r,n]=h.useState({left:!1,right:!1});return h.useEffect(()=>{if(!t)return;const i=e.current;if(!i)return;let o=0;const a=()=>{cancelAnimationFrame(o),o=requestAnimationFrame(()=>{const{scrollLeft:A,scrollWidth:c,clientWidth:d}=i;n({left:A>0,right:A+d<c-1})})};a(),i.addEventListener("scroll",a,{passive:!0});const s=new ResizeObserver(a);return s.observe(i),()=>{i.removeEventListener("scroll",a),s.disconnect(),cancelAnimationFrame(o)}},[e,t]),r}const zm={medium:{avatar:40,radius:"sm",space:"sm"},large:{avatar:80,radius:"md",space:"md"}},W5=v.div`
3285
3285
  display: flex;
3286
3286
  flex-direction: row;
3287
3287
  align-items: center;
@@ -29892,59 +29892,60 @@ const I5 = "fitx1200", Sbe = (e, t = I5, r = !0) => ({
29892
29892
  files: e,
29893
29893
  children: t,
29894
29894
  openWithOptions: r,
29895
- onReadFile: n
29895
+ onReadFile: n,
29896
+ onOpen: i
29896
29897
  }) => {
29897
- const i = Y(), [o, a] = j(-1), s = e[o];
29898
+ const o = Y(), [a, s] = j(-1), A = e[a];
29898
29899
  _(() => {
29899
- if (n && o > -1) {
29900
- const c = e[o];
29901
- c && n(c);
29900
+ if (n && a > -1) {
29901
+ const d = e[a];
29902
+ d && n(d);
29902
29903
  }
29903
- }, [o, e, n]);
29904
- const A = {
29905
- open: o !== -1,
29904
+ }, [a, e, n]);
29905
+ const c = {
29906
+ open: a !== -1,
29906
29907
  portalId: "react-modal",
29907
29908
  variant: "full-screen",
29908
29909
  maxHeight: "100%",
29909
29910
  closeHandler: () => {
29910
- a(-1);
29911
+ s(-1);
29911
29912
  }
29912
29913
  };
29913
29914
  return /* @__PURE__ */ l.jsxs(l.Fragment, { children: [
29914
- t((c) => {
29915
- const d = e.find((f) => f.key === c);
29916
- if (!d)
29915
+ t((d) => {
29916
+ const u = e.find((g) => g.key === d);
29917
+ if (!u)
29917
29918
  return;
29918
- const u = r.find((f) => f.condition(d));
29919
- u && u.options.length > 0 ? u.options[0].onClick(d) : a(e.findIndex((f) => f.key === c));
29919
+ const f = r.find((g) => g.condition(u));
29920
+ f && f.options.length > 0 ? f.options[0].onClick(u) : (i?.(u), s(e.findIndex((g) => g.key === d)));
29920
29921
  }),
29921
- /* @__PURE__ */ l.jsx(qr, { ...A, children: /* @__PURE__ */ l.jsx(
29922
+ /* @__PURE__ */ l.jsx(qr, { ...c, children: /* @__PURE__ */ l.jsx(
29922
29923
  gn,
29923
29924
  {
29924
- onClickIconClose: A.closeHandler,
29925
- title: i.formatMessage({ id: "FILE_Viewer_Preview" }),
29925
+ onClickIconClose: c.closeHandler,
29926
+ title: o.formatMessage({ id: "FILE_Viewer_Preview" }),
29926
29927
  isFull: !0,
29927
29928
  children: /* @__PURE__ */ l.jsxs(Ibe, { "data-testid": "file-viewer", children: [
29928
- /* @__PURE__ */ l.jsx(Tbe, { children: /* @__PURE__ */ l.jsx(Obe, { children: s && /* @__PURE__ */ l.jsxs(l.Fragment, { children: [
29929
- s.title,
29930
- s.downloadHref !== void 0 && /* @__PURE__ */ l.jsxs(jbe, { href: s.downloadHref, children: [
29931
- /* @__PURE__ */ l.jsx(ge, { color: "grey4", children: i.formatMessage({ id: "GLOBAL_Download" }) }),
29929
+ /* @__PURE__ */ l.jsx(Tbe, { children: /* @__PURE__ */ l.jsx(Obe, { children: A && /* @__PURE__ */ l.jsxs(l.Fragment, { children: [
29930
+ A.title,
29931
+ A.downloadHref !== void 0 && /* @__PURE__ */ l.jsxs(jbe, { href: A.downloadHref, children: [
29932
+ /* @__PURE__ */ l.jsx(ge, { color: "grey4", children: o.formatMessage({ id: "GLOBAL_Download" }) }),
29932
29933
  /* @__PURE__ */ l.jsx(le, { name: "icon-download", color: "grey4", size: 16 })
29933
29934
  ] })
29934
29935
  ] }) }) }),
29935
- /* @__PURE__ */ l.jsx(Lbe, { children: s && /* @__PURE__ */ l.jsx(Xbe, { item: s, openWithOptions: r }) }),
29936
+ /* @__PURE__ */ l.jsx(Lbe, { children: A && /* @__PURE__ */ l.jsx(Xbe, { item: A, openWithOptions: r }) }),
29936
29937
  /* @__PURE__ */ l.jsx(Pbe, { children: /* @__PURE__ */ l.jsx(
29937
29938
  zbe,
29938
29939
  {
29939
29940
  total: e.length,
29940
- index: o,
29941
- onRelease: (c) => {
29942
- switch (c) {
29941
+ index: a,
29942
+ onRelease: (d) => {
29943
+ switch (d) {
29943
29944
  case "next":
29944
- a(o < e.length - 1 ? o + 1 : 0);
29945
+ s(a < e.length - 1 ? a + 1 : 0);
29945
29946
  break;
29946
29947
  case "prev":
29947
- a(o === 0 ? e.length - 1 : o - 1);
29948
+ s(a === 0 ? e.length - 1 : a - 1);
29948
29949
  break;
29949
29950
  }
29950
29951
  }
@@ -29960,24 +29961,26 @@ const I5 = "fitx1200", Sbe = (e, t = I5, r = !0) => ({
29960
29961
  children: r,
29961
29962
  openWithOptions: n,
29962
29963
  allowDownload: i = !0,
29963
- onReadFile: o
29964
+ onReadFile: o,
29965
+ onOpen: a
29964
29966
  }) => {
29965
- const a = Z(
29966
- () => e.map((A) => Sbe(A, t, i)),
29967
+ const s = Z(
29968
+ () => e.map((c) => Sbe(c, t, i)),
29967
29969
  [e, t, i]
29968
- ), s = n.map(({ condition: A, options: c }) => ({
29969
- condition: (d) => A(d.file),
29970
- options: c.map((d) => ({
29971
- label: d.label,
29972
- onClick: (u) => d.onClick(u.file)
29970
+ ), A = n.map(({ condition: c, options: d }) => ({
29971
+ condition: (u) => c(u.file),
29972
+ options: d.map((u) => ({
29973
+ label: u.label,
29974
+ onClick: (f) => u.onClick(f.file)
29973
29975
  }))
29974
29976
  }));
29975
29977
  return /* @__PURE__ */ l.jsx(
29976
29978
  T5,
29977
29979
  {
29978
- files: a,
29979
- openWithOptions: s,
29980
- onReadFile: o && ((A) => o(A.file)),
29980
+ files: s,
29981
+ openWithOptions: A,
29982
+ onReadFile: o && ((c) => o(c.file)),
29983
+ onOpen: a && ((c) => a(c.file)),
29981
29984
  children: r
29982
29985
  }
29983
29986
  );
@@ -7,6 +7,7 @@ export type JRCFileViewerProps<T extends jFileLittle> = {
7
7
  allowDownload?: boolean;
8
8
  children(open: (idFile: number) => void): ReactElement<HTMLElement>;
9
9
  onReadFile?(file: T): void;
10
+ onOpen?(file: T): void;
10
11
  };
11
12
  export type JRCFileViewerOpenWithOptionsType = Array<{
12
13
  condition: (file: jFileLittle) => boolean;
@@ -16,4 +17,4 @@ export type JRCFileViewerOpenWithOptionType = {
16
17
  label: string;
17
18
  onClick: (file: jFileLittle | undefined) => void;
18
19
  };
19
- export declare const JRCFileViewer: <T extends jFileLittle>({ files, size, children, openWithOptions, allowDownload, onReadFile, }: JRCFileViewerProps<T>) => import("react").JSX.Element;
20
+ export declare const JRCFileViewer: <T extends jFileLittle>({ files, size, children, openWithOptions, allowDownload, onReadFile, onOpen, }: JRCFileViewerProps<T>) => import("react").JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import { JRCFileViewerItem, JRCFileViewerRawProps } from './types';
2
- export declare const JRCFileViewerRaw: <TItem extends JRCFileViewerItem>({ files, children, openWithOptions, onReadFile, }: JRCFileViewerRawProps<TItem>) => import("react").JSX.Element;
2
+ export declare const JRCFileViewerRaw: <TItem extends JRCFileViewerItem>({ files, children, openWithOptions, onReadFile, onOpen, }: JRCFileViewerRawProps<TItem>) => import("react").JSX.Element;
@@ -15,6 +15,7 @@ export type JRCFileViewerRawProps<TItem extends JRCFileViewerItem> = {
15
15
  openWithOptions: JRCFileViewerRawOptionsType<TItem>;
16
16
  children(open: (key: number) => void): ReactElement<HTMLElement>;
17
17
  onReadFile?(item: TItem): void;
18
+ onOpen?(item: TItem): void;
18
19
  };
19
20
  export type JRCFileViewerRawOptionsType<TItem extends JRCFileViewerItem> = Array<{
20
21
  condition: (item: TItem) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jamespot-react-components",
3
- "version": "1.3.164",
3
+ "version": "1.3.165",
4
4
  "description": "",
5
5
  "main": "dist/jamespot-react-components.cjs",
6
6
  "module": "dist/jamespot-react-components.js",
@@ -89,8 +89,8 @@
89
89
  "vite-plugin-css-injected-by-js": "^3.5.2",
90
90
  "vite-plugin-dts": "^4.5.4",
91
91
  "vitest": "^4.1.10",
92
- "jamespot-front-business": "1.3.164",
93
- "jamespot-user-api": "1.3.164"
92
+ "jamespot-front-business": "1.3.165",
93
+ "jamespot-user-api": "1.3.165"
94
94
  },
95
95
  "lint-staged": {
96
96
  "*.{js,jsx,ts,tsx}": [