@webority/ui-react 0.83.0 → 0.83.1
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 +1 @@
|
|
|
1
|
-
import e from"./warnUnknownProps.js";import t from"./AppIcon.js";import n from"../lib/FieldMessage.js";import{keyOf as
|
|
1
|
+
import e from"./warnUnknownProps.js";import t from"./AppIcon.js";import n from"../lib/FieldMessage.js";import r from"./AppProgress.js";import{keyOf as i,linkOf as a,nameOf as o,sizeLabelOf as s,uploadErrorOf as c,uploadProgressOf as l,useItemUrl as u}from"../lib/fileItem.js";import d from"../lib/FileItemRow.js";import{DEFAULT_IMAGE_ACCEPT as f,DEFAULT_MAX_SIZE_MB as p,acceptLabel as m,isImageFile as h,isImageOnlyAccept as g,validateFile as _}from"@webority/ui-elements/helpers";import{useId as v,useState as y}from"react";import{Fragment as b,jsx as x,jsxs as S}from"react/jsx-runtime";function C({label:r=`Attachment`,value:o,name:s,onChange:c,multiple:l=!1,accept:u=f,maxSizeMb:m=p,optional:C=!1,validate:E=!0,error:D,id:O,...k}){e(`AppFileAttachment`,k);let A=v(),j=O||A,[M,N]=y(``),[P,F]=y(!1),I=l&&Array.isArray(o)?o:o?[o]:[],L=g(u),R=e=>e instanceof File?h(e):L||h(e),z=!l&&I.length===1&&R(I[0])&&(I[0]instanceof File||a(I[0])!==null),B=w(u,m);function V(e){if(!e.length)return;let t=[],n=``;for(let r of e){let e=E?_(r,{accept:u,maxSizeMb:m}):null;if(e){n||=e;continue}t.push(r)}if(N(n),t.length)if(l){let e=Array.isArray(o)?o:o?[o]:[],n=new Set(e.map(i));c(e.concat(t.filter(e=>!n.has(i(e)))))}else c(t[0])}function H(e){let t=Array.from(e.target.files||[]);e.target.value=``,V(t)}function U(e){N(``),c(l?I.filter((t,n)=>n!==e):null)}let W=D||M,G=W?`${j}-error`:void 0,K=l||I.length===0,q=L?`image`:`file`,J=l?`Add ${q}s`:`Add ${L?`an`:`a`} ${q}`;return S(`div`,{className:`field`,children:[S(`label`,{className:`label`,htmlFor:j,children:[r,C&&x(`span`,{className:`label-optional`,children:` (optional)`})]}),K&&S(b,{children:[S(`label`,{className:`attach-drop${P?` dragging`:``}`,htmlFor:j,onDragEnter:e=>{e.preventDefault(),k.disabled||F(!0)},onDragOver:e=>{e.preventDefault(),k.disabled||F(!0)},onDragLeave:e=>{e.preventDefault(),F(!1)},onDrop:e=>{e.preventDefault(),F(!1),!k.disabled&&V(Array.from(e.dataTransfer?.files||[]))},children:[x(`span`,{className:`attach-drop-icon`,children:x(t,{name:L?`image`:`file-text`,size:18})}),S(`span`,{className:`attach-drop-copy`,children:[x(`span`,{className:`attach-drop-title`,children:J}),B&&x(`span`,{className:`attach-drop-hint`,children:B})]}),x(`span`,{className:`attach-drop-cta`,children:`Browse`})]}),x(`input`,{id:j,type:`file`,className:`visually-hidden`,name:s,accept:u||void 0,multiple:l||void 0,"aria-describedby":G,onChange:H,...k})]}),z?x(T,{item:I[0],isImage:!0,onRemove:()=>U(0)}):I.length>0&&x(`div`,{className:`attach-list`,children:I.map((e,t)=>x(d,{item:e,isImage:R(e),onRemove:()=>U(t)},i(e)))}),x(n,{error:W,errorId:`${j}-error`})]})}function w(e,t){let n=e?.trim()?m(e):``,r=t>0?`up to ${t} MB`:``;return n&&r?`${n}, ${r}`:r?`Up to ${t} MB`:n}function T({item:e,isImage:n,onRemove:i}){let d=u(e,n),f=o(e),p=s(e),m=l(e),h=c(e),g=a(e);return S(`div`,{className:h?`attach-preview wui-attach-failed`:`attach-preview`,children:[S(`div`,{className:`attach-figure`,children:[x(`img`,{src:d,alt:f}),x(`button`,{type:`button`,className:`attach-remove`,"aria-label":`Remove attachment`,onClick:i,children:x(t,{name:`x`,size:18})})]}),S(`div`,{className:`attach-meta`,children:[x(`div`,{className:`attach-name`,children:g?x(`a`,{href:g,children:f}):f}),p&&x(`div`,{className:`attach-size`,children:p})]}),m!==null&&x(r,{value:m,size:`sm`,label:`Uploading ${f}`,className:`wui-attach-progress`}),h&&x(`div`,{className:`wui-attach-error`,children:h})]})}export{C as default};
|
package/dist/lib/FileItemRow.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../components/AppIcon.js";import t from"../components/AppProgress.js";import{
|
|
1
|
+
import e from"../components/AppIcon.js";import t from"../components/AppProgress.js";import{linkOf as n,nameOf as r,sizeLabelOf as i,uploadErrorOf as a,uploadProgressOf as o,useItemUrl as s}from"./fileItem.js";import{jsx as c,jsxs as l}from"react/jsx-runtime";function u({item:u,isImage:d,onRemove:f,noun:p=`attachment`}){let m=s(u,d),h=r(u),g=i(u),_=o(u),v=a(u),y=n(u);return l(`div`,{className:v?`attach-item wui-attach-failed`:`attach-item`,children:[c(`span`,{className:`attach-item-media`,children:m?c(`img`,{src:m,alt:h}):c(e,{name:`file-text`,size:18})}),l(`span`,{className:`attach-item-info`,children:[c(`span`,{className:`attach-name`,children:y?c(`a`,{href:y,children:h}):h}),g&&c(`span`,{className:`attach-size`,children:g}),_!==null&&c(t,{value:_,size:`sm`,label:`Uploading ${h}`,className:`wui-attach-progress`}),v&&c(`div`,{className:`wui-attach-error`,children:v})]}),c(`button`,{type:`button`,className:`attach-item-remove`,"aria-label":`Remove ${h||p}`,onClick:f,children:c(e,{name:`x`,size:16})})]})}export{u as default};
|
package/dist/lib/fileItem.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffect as
|
|
1
|
+
import{formatFileSize as e}from"@webority/ui-elements/helpers";import{useEffect as t,useState as n}from"react";function r(e){return e instanceof File?`${e.name}:${e.size}`:e?.url||e?.name||`item`}function i(e){return e instanceof File?e.name:e?.name}function a(t){if(t instanceof File)return e(t.size);let n=t?.sizeBytes;return Number.isFinite(n)&&n>=0?e(n):null}function o(e){return typeof e?.url==`string`&&e.url.length>0?e.url:null}function s(e){let t=e?.progress;return typeof t==`number`&&t>=0&&t<=99?t:null}function c(e){return typeof e?.error==`string`&&e.error.length>0?e.error:null}function l(e,r){let[i,a]=n(null);return t(()=>{if(!r){a(null);return}if(e instanceof File){let t=URL.createObjectURL(e);return a(t),()=>URL.revokeObjectURL(t)}a(e?.url||null)},[e,r]),i}export{r as keyOf,o as linkOf,i as nameOf,a as sizeLabelOf,c as uploadErrorOf,s as uploadProgressOf,l as useItemUrl};
|
|
@@ -11,6 +11,12 @@ export declare function nameOf(item: any): any;
|
|
|
11
11
|
* `sizeBytes` of 0 or more. Null when the size is unknown.
|
|
12
12
|
*/
|
|
13
13
|
export declare function sizeLabelOf(item: any): string;
|
|
14
|
+
/** The link a stored file opens; a freshly picked File has none. */
|
|
15
|
+
export declare function linkOf(item: any): any;
|
|
16
|
+
/** Upload progress while it is under 100, else null: a finished upload draws no bar. */
|
|
17
|
+
export declare function uploadProgressOf(item: any): number;
|
|
18
|
+
/** Why the upload failed, or null. */
|
|
19
|
+
export declare function uploadErrorOf(item: any): any;
|
|
14
20
|
/**
|
|
15
21
|
* A freshly-picked File has no URL of its own; mint one (for images) and revoke it on
|
|
16
22
|
* change/unmount. An existing attachment already carries `url`. Non-images get no URL — the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/ui-react",
|
|
3
|
-
"version": "0.83.
|
|
3
|
+
"version": "0.83.1",
|
|
4
4
|
"description": "Webority shared React component library — App* primitives on react-bootstrap + the @webority/theme design system.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@webority/
|
|
31
|
-
"@webority/
|
|
30
|
+
"@webority/theme": "0.83.1",
|
|
31
|
+
"@webority/ui-elements": "0.83.1"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@webority/analytics": "^0.25.0",
|