zy-react-library 2.2.1 → 2.2.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.
@@ -1,4 +1,4 @@
1
- import type { FC } from "react";
1
+ import type { CSSProperties, FC, ReactNode } from "react";
2
2
 
3
3
  export interface ExcelProps {
4
4
  /** 是否显示弹窗 */
@@ -13,8 +13,10 @@ export interface ExcelProps {
13
13
  inline?: boolean;
14
14
  /** 弹窗标题 */
15
15
  title?: string;
16
- /** 内容样式 */
17
- style?: Record<string, any>;
16
+ /** 内联模式下的样式 */
17
+ style?: CSSProperties;
18
+ /** 弹窗底部额外的按钮 */
19
+ extraButtons?: ReactNode;
18
20
  }
19
21
 
20
22
  declare const Excel: FC<ExcelProps>;
@@ -1 +1 @@
1
- import{Modal as e,Button as t,message as r,Spin as n}from"antd";import i from"exceljs";import{useRef as o,useState as l,useEffect as c}from"react";import a from"x-data-spreadsheet";import u from"../../hooks/useDownloadFile/index.js";import{getFileUrl as s}from"../../utils/index.js";import"x-data-spreadsheet/dist/xspreadsheet.css";import{jsx as d}from"react/jsx-runtime";function h(h){const{visible:x=!1,onCancel:w,file:p,name:v,inline:g=!1,title:y="Excel预览",style:C={}}=h,E=o(null),k=o(null),I=o(!1),T=s(),[b,j]=l(!1),{downloadFile:S}=u();c(()=>{if(!x&&!g||!p)return;I.current=!1;const e=setTimeout(()=>{(async()=>{j(!0),E.current.innerHTML="";try{const e=await fetch(p.includes(T)?p:T+p);if(!e.ok)throw new Error("加载 Excel 文件失败");const t=await e.arrayBuffer(),r=new i.Workbook;if(await r.xlsx.load(t),I.current)return;new a(E.current,{mode:"read",showToolbar:!1,showContextmenu:!1,view:{height:()=>E.current?.clientHeight||520,width:()=>E.current?.clientWidth||800}}).loadData(function(e){const t=[];return e.worksheets.forEach(e=>{t.push(function(e){const t={name:e.name,rows:{},cols:{len:e.columnCount||26},merges:e.model?.merges||[]};return e.columns.forEach((e,r)=>{e.width&&(t.cols[r]={width:Math.round(8*e.width)})}),e.eachRow({includeEmpty:!0},(e,r)=>{const n={cells:{}};e.height&&(n.height=Math.round(1.4*e.height)),e.eachCell({includeEmpty:!0},(e,t)=>{n.cells[t-1]={text:m(e)}}),t.rows[r-1]=n}),(t.merges||[]).forEach(e=>{const r=function(e){const[t,r=t]=e.split(":"),n=f(t),i=f(r);return{sri:n.rowIndex,sci:n.colIndex,eri:i.rowIndex,eci:i.colIndex}}(e),n=t.rows[r.sri]?.cells?.[r.sci];n&&(n.merge=[r.eri-r.sri,r.eci-r.sci])}),t}(e))}),t.length>0?t:[{name:"Sheet1",rows:{}}]}(r))}catch{r.error("加载 Excel 文件失败"),!g&&w&&w()}finally{I.current||j(!1)}})()},100);return()=>{I.current=!0,E.current&&(E.current.innerHTML=""),e&&clearTimeout(e)}},[x,g,p]);const D=()=>d(n,{spinning:b,children:d("div",{style:{height:"72vh",overflow:"hidden",...C},children:d("div",{ref:E,style:{width:"100%",height:"100%"}})})});return g?D():d("div",{ref:k,children:d(e,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:x,mask:{closable:!1},width:1e3,title:y,onCancel:()=>{w()},getContainer:!1,footer:[d(t,{onClick:()=>{w()},children:"关闭"},"cancel"),d(t,{type:"primary",onClick:()=>{S({url:p,name:v})},children:"下载"},"download")],children:D()})})}function m(e){if(null===e.value||void 0===e.value)return"";if(e.formula)return null===e.result||void 0===e.result?`=${e.formula}`:String(e.result);if(e.text)return e.text;if(e.value instanceof Date)return e.value.toLocaleDateString();if("object"==typeof e.value){if(e.value.text)return e.value.text;if(e.value.richText)return e.value.richText.map(e=>e.text).join("");if(void 0!==e.value.result)return String(e.value.result)}return String(e.value)}function f(e){const t=/^([A-Z]+)(\d+)$/i.exec(e);return t?{rowIndex:Number(t[2])-1,colIndex:(r=t[1],r.toUpperCase().split("").reduce((e,t)=>26*e+t.charCodeAt(0)-64,0)-1)}:{rowIndex:0,colIndex:0};var r}h.displayName="Excel";export{h as default};
1
+ import{Modal as e,Button as t,message as r,Spin as n}from"antd";import o from"exceljs";import{useRef as i,useState as l,useEffect as c}from"react";import a from"x-data-spreadsheet";import u from"../../hooks/useDownloadFile/index.js";import{getFileUrl as s}from"../../utils/index.js";import"x-data-spreadsheet/dist/xspreadsheet.css";import{jsx as d}from"react/jsx-runtime";function h(h){const{visible:x=!1,onCancel:w,file:p,name:v,inline:g=!1,title:y="Excel预览",style:C={},extraButtons:E}=h,k=i(null),I=i(null),T=i(!1),b=s(),[j,S]=l(!1),{downloadFile:D}=u();c(()=>{if(!x&&!g||!p)return;T.current=!1;const e=setTimeout(()=>{(async()=>{S(!0),k.current.innerHTML="";try{const e=await fetch(p.includes(b)?p:b+p);if(!e.ok)throw new Error("加载 Excel 文件失败");const t=await e.arrayBuffer(),r=new o.Workbook;if(await r.xlsx.load(t),T.current)return;new a(k.current,{mode:"read",showToolbar:!1,showContextmenu:!1,view:{height:()=>k.current?.clientHeight||520,width:()=>k.current?.clientWidth||800}}).loadData(function(e){const t=[];return e.worksheets.forEach(e=>{t.push(function(e){const t={name:e.name,rows:{},cols:{len:e.columnCount||26},merges:e.model?.merges||[]};return e.columns.forEach((e,r)=>{e.width&&(t.cols[r]={width:Math.round(8*e.width)})}),e.eachRow({includeEmpty:!0},(e,r)=>{const n={cells:{}};e.height&&(n.height=Math.round(1.4*e.height)),e.eachCell({includeEmpty:!0},(e,t)=>{n.cells[t-1]={text:m(e)}}),t.rows[r-1]=n}),(t.merges||[]).forEach(e=>{const r=function(e){const[t,r=t]=e.split(":"),n=f(t),o=f(r);return{sri:n.rowIndex,sci:n.colIndex,eri:o.rowIndex,eci:o.colIndex}}(e),n=t.rows[r.sri]?.cells?.[r.sci];n&&(n.merge=[r.eri-r.sri,r.eci-r.sci])}),t}(e))}),t.length>0?t:[{name:"Sheet1",rows:{}}]}(r))}catch{r.error("加载 Excel 文件失败"),!g&&w&&w()}finally{T.current||S(!1)}})()},100);return()=>{T.current=!0,k.current&&(k.current.innerHTML=""),e&&clearTimeout(e)}},[x,g,p]);const M=()=>d(n,{spinning:j,children:d("div",{style:{height:"72vh",overflow:"hidden",...C},children:d("div",{ref:k,style:{width:"100%",height:"100%"}})})});return g?M():d("div",{ref:I,children:d(e,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:x,mask:{closable:!1},width:1e3,title:y,onCancel:()=>{w()},getContainer:!1,footer:[d(t,{onClick:()=>{w()},children:"关闭"},"cancel"),d(t,{type:"primary",onClick:()=>{D({url:p,name:v})},children:"下载"},"download"),...E||[]],children:M()})})}function m(e){if(null===e.value||void 0===e.value)return"";if(e.formula)return null===e.result||void 0===e.result?`=${e.formula}`:String(e.result);if(e.text)return e.text;if(e.value instanceof Date)return e.value.toLocaleDateString();if("object"==typeof e.value){if(e.value.text)return e.value.text;if(e.value.richText)return e.value.richText.map(e=>e.text).join("");if(void 0!==e.value.result)return String(e.value.result)}return String(e.value)}function f(e){const t=/^([A-Z]+)(\d+)$/i.exec(e);return t?{rowIndex:Number(t[2])-1,colIndex:(r=t[1],r.toUpperCase().split("").reduce((e,t)=>26*e+t.charCodeAt(0)-64,0)-1)}:{rowIndex:0,colIndex:0};var r}h.displayName="Excel";export{h as default};
@@ -1,4 +1,4 @@
1
- import type { CSSProperties, FC } from "react";
1
+ import type { CSSProperties, FC, ReactNode } from "react";
2
2
 
3
3
  export interface PdfProps {
4
4
  /** pdf 文件地址 */
@@ -15,6 +15,8 @@ export interface PdfProps {
15
15
  inline?: boolean;
16
16
  /** 内联模式下的样式 */
17
17
  style?: CSSProperties;
18
+ /** 弹窗底部额外的按钮 */
19
+ extraButtons?: ReactNode;
18
20
  }
19
21
 
20
22
  declare const Pdf: FC<PdfProps>;
@@ -1 +1 @@
1
- import{useFullscreen as e}from"ahooks";import{Modal as r,Button as o,Spin as i,message as n}from"antd";import{useState as t,useRef as l}from"react";import{pdfjs as a,Document as d,Page as c}from"react-pdf";import s from"../../hooks/useDownloadFile/index.js";import{getFileUrl as p}from"../../utils/index.js";import"react-pdf/dist/Page/AnnotationLayer.css";import"react-pdf/dist/Page/TextLayer.css";import"./index.less";import{jsx as m,Fragment as f}from"react/jsx-runtime";function h(h){const{visible:u=!1,onCancel:x,file:g,name:v,inline:y=!1,title:w="PDF预览",style:k={}}=h,C=p(),[j,F]=t(0),[P,b]=t(600),L=l(null),[S,{enterFullscreen:D,exitFullscreen:A}]=e(L),{downloadFile:N}=s();a.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${a.version}/build/pdf.worker.min.mjs`;const W=({numPages:e})=>{F(e)},$=()=>{n.error("加载 PDF 文件失败"),x&&x()},z=({width:e})=>{b(e)},B=()=>m(f,{children:m("div",{style:{height:S?"calc(100vh - 40px - 24px - 8px - 32px - 12px)":"72vh",overflowY:"auto",padding:"24px",...k},children:m(d,{file:g.includes(C)?g:C+g,onLoadSuccess:W,onLoadError:$,loading:m("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"65vh"},children:m(i,{size:"large"})}),children:Array.from({length:j}).map((e,r)=>m(c,{pageNumber:r+1,onLoadSuccess:z},`page_${r+1}`))})})});return y?B():m("div",{ref:L,children:m(r,{style:{top:S?0:100,maxWidth:S?"100vw":"calc(100vw - 32px)",paddingBottom:S?0:24},open:u,mask:{closable:!1},width:S?"100vw":P+100,title:w,onCancel:()=>{S&&A(),x()},getContainer:!1,footer:[m(o,{onClick:()=>{S&&A(),x()},children:"关闭"},"cancel"),m(o,{onClick:()=>{S?A():D()},children:S?"退出全屏":"全屏"},"fullScreen"),m(o,{type:"primary",onClick:()=>{S&&A(),N({url:g,name:v})},children:"下载"},"download")],children:B()})})}h.displayName="Pdf";export{h as default};
1
+ import{useFullscreen as e}from"ahooks";import{Modal as r,Button as o,Spin as i,message as n}from"antd";import{useState as t,useRef as l}from"react";import{pdfjs as a,Document as d,Page as s}from"react-pdf";import c from"../../hooks/useDownloadFile/index.js";import{getFileUrl as p}from"../../utils/index.js";import"react-pdf/dist/Page/AnnotationLayer.css";import"react-pdf/dist/Page/TextLayer.css";import"./index.less";import{jsx as m,Fragment as f}from"react/jsx-runtime";function h(h){const{visible:u=!1,onCancel:x,file:g,name:v,inline:y=!1,title:w="PDF预览",style:k={},extraButtons:C}=h,j=p(),[F,P]=t(0),[b,L]=t(600),S=l(null),[D,{enterFullscreen:A,exitFullscreen:B}]=e(S),{downloadFile:N}=c();a.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${a.version}/build/pdf.worker.min.mjs`;const W=({numPages:e})=>{P(e)},$=()=>{n.error("加载 PDF 文件失败"),x&&x()},z=({width:e})=>{L(e)},E=()=>m(f,{children:m("div",{style:{height:D?"calc(100vh - 40px - 24px - 8px - 32px - 12px)":"72vh",overflowY:"auto",padding:"24px",...k},children:m(d,{file:g.includes(j)?g:j+g,onLoadSuccess:W,onLoadError:$,loading:m("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"65vh"},children:m(i,{size:"large"})}),children:Array.from({length:F}).map((e,r)=>m(s,{pageNumber:r+1,onLoadSuccess:z},`page_${r+1}`))})})});return y?E():m("div",{ref:S,children:m(r,{style:{top:D?0:100,maxWidth:D?"100vw":"calc(100vw - 32px)",paddingBottom:D?0:24},open:u,mask:{closable:!1},width:D?"100vw":b+100,title:w,onCancel:()=>{D&&B(),x()},getContainer:!1,footer:[m(o,{onClick:()=>{D&&B(),x()},children:"关闭"},"cancel"),m(o,{onClick:()=>{D?B():A()},children:D?"退出全屏":"全屏"},"fullScreen"),m(o,{type:"primary",onClick:()=>{D&&B(),N({url:g,name:v})},children:"下载"},"download"),...C||[]],children:E()})})}h.displayName="Pdf";export{h as default};
@@ -1,4 +1,4 @@
1
- import type { FC } from "react";
1
+ import type { CSSProperties, FC, ReactNode } from "react";
2
2
 
3
3
  export interface WordProps {
4
4
  /** 是否显示弹窗 */
@@ -13,8 +13,10 @@ export interface WordProps {
13
13
  inline?: boolean;
14
14
  /** 弹窗标题 */
15
15
  title?: string;
16
- /** 内容样式 */
17
- style?: Record<string, any>;
16
+ /** 内联模式下的样式 */
17
+ style?: CSSProperties;
18
+ /** 弹窗底部额外的按钮 */
19
+ extraButtons?: ReactNode;
18
20
  }
19
21
 
20
22
  declare const Word: FC<WordProps>;
@@ -1 +1 @@
1
- import{Modal as r,Button as e,message as n,Spin as t}from"antd";import{renderAsync as i}from"docx-preview";import{useRef as o,useState as l,useEffect as a}from"react";import c from"../../hooks/useDownloadFile/index.js";import{getFileUrl as d}from"../../utils/index.js";import{jsx as u}from"react/jsx-runtime";function s(s){const{visible:f=!1,onCancel:m,file:p,name:h,inline:w=!1,title:g="Word预览",style:y={}}=s,v=o(null),x=o(null),k=o(!1),W=d(),[C,b]=l(!1),{downloadFile:T}=c();a(()=>{if(!f&&!w||!p)return;k.current=!1;const r=setTimeout(()=>{(async()=>{b(!0),v.current.innerHTML="";try{const r=await fetch(p.includes(W)?p:W+p);if(!r.ok)throw new Error("加载 Word 文件失败");const e=await r.arrayBuffer();if(k.current)return;await i(e,v.current,null,{className:"docx-preview",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,breakPages:!0})}catch{n.error("加载 Word 文件失败"),!w&&m&&m()}finally{k.current||b(!1)}})()},100);return()=>{k.current=!0,v.current&&(v.current.innerHTML=""),r&&clearTimeout(r)}},[f,w,p]);const j=()=>u(t,{spinning:C,children:u("div",{style:{height:"72vh",overflowY:"auto",padding:"24px",background:"#f5f5f5",...y},children:u("div",{ref:v})})});return w?j():u("div",{ref:x,children:u(r,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:f,mask:{closable:!1},width:900,title:g,onCancel:()=>{m()},getContainer:!1,footer:[u(e,{onClick:()=>{m()},children:"关闭"},"cancel"),u(e,{type:"primary",onClick:()=>{T({url:p,name:h})},children:"下载"},"download")],children:j()})})}s.displayName="Word";export{s as default};
1
+ import{Modal as r,Button as e,message as n,Spin as t}from"antd";import{renderAsync as i}from"docx-preview";import{useRef as o,useState as a,useEffect as l}from"react";import c from"../../hooks/useDownloadFile/index.js";import{getFileUrl as d}from"../../utils/index.js";import{jsx as u}from"react/jsx-runtime";function s(s){const{visible:f=!1,onCancel:m,file:p,name:h,inline:w=!1,title:g="Word预览",style:x={},extraButtons:y}=s,v=o(null),k=o(null),W=o(!1),C=d(),[b,T]=a(!1),{downloadFile:j}=c();l(()=>{if(!f&&!w||!p)return;W.current=!1;const r=setTimeout(()=>{(async()=>{T(!0),v.current.innerHTML="";try{const r=await fetch(p.includes(C)?p:C+p);if(!r.ok)throw new Error("加载 Word 文件失败");const e=await r.arrayBuffer();if(W.current)return;await i(e,v.current,null,{className:"docx-preview",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,breakPages:!0})}catch{n.error("加载 Word 文件失败"),!w&&m&&m()}finally{W.current||T(!1)}})()},100);return()=>{W.current=!0,v.current&&(v.current.innerHTML=""),r&&clearTimeout(r)}},[f,w,p]);const B=()=>u(t,{spinning:b,children:u("div",{style:{height:"72vh",overflowY:"auto",padding:"24px",background:"#f5f5f5",...x},children:u("div",{ref:v})})});return w?B():u("div",{ref:k,children:u(r,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:f,mask:{closable:!1},width:900,title:g,onCancel:()=>{m()},getContainer:!1,footer:[u(e,{onClick:()=>{m()},children:"关闭"},"cancel"),u(e,{type:"primary",onClick:()=>{j({url:p,name:h})},children:"下载"},"download"),...y||[]],children:B()})})}s.displayName="Word";export{s as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "2.2.1",
4
+ "version": "2.2.2",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",
@@ -75,5 +75,9 @@
75
75
  "antd": ">=6.4.4 <7",
76
76
  "react": ">=18.3.1 <19",
77
77
  "zy-react-data": ">=1.0.0"
78
+ },
79
+ "publishConfig": {
80
+ "access": "public",
81
+ "registry": "https://registry.npmjs.org/"
78
82
  }
79
83
  }