@webority/ui-react 0.83.0 → 0.83.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 +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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{devWarn as e}from"../lib/devWarn.js";import t from"./warnInvalidValue.js";import n from"./warnUnknownProps.js";import r from"./AppIcon.js";import i from"./AppButton.js";import a from"./AppSegmented.js";import
|
|
1
|
+
import{devWarn as e}from"../lib/devWarn.js";import t from"./warnInvalidValue.js";import n from"./warnUnknownProps.js";import r from"./AppIcon.js";import i from"./AppButton.js";import a from"./AppSegmented.js";import ee from"./AppChip.js";import o from"./AppDateRangePicker.js";import{emptyFacetValue as s,isFacetActive as c}from"../lib/listQuery.js";import l from"./AppMultiSelect.js";import u from"./AppSearch.js";import d from"./AppSelect.js";import f from"./AppSwitch.js";import{Fragment as te,useEffect as p,useId as m,useRef as h,useState as ne,useSyncExternalStore as re}from"react";import{Fragment as g,jsx as _,jsxs as v}from"react/jsx-runtime";import"@webority/ui-elements/elements/filter-popover";var y=`(max-width: 575.98px)`,b=3,x=2,ie=e=>{let t=window.matchMedia?.(y);return t?.addEventListener(`change`,e),()=>t?.removeEventListener(`change`,e)},ae=()=>window.matchMedia?.(y).matches??!1,S=[`enum`,`multiEnum`,`dateRange`,`text`],C=4,w=e=>(e.type===`enum`||e.type===`multiEnum`)&&!e.options?.length,T=(e,t)=>e.options?.find(e=>e.value===t)?.label??t,oe=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function se(e,t){if(!c(e,t))return[];if(e.type===`enum`)return[{id:e.key,text:T(e,t),clear:()=>s(e)}];if(e.type===`multiEnum`)return t.map(n=>({id:`${e.key}:${n}`,text:T(e,n),clear:()=>t.filter(e=>e!==n)}));if(e.type===`dateRange`){let n=t.from&&t.to?`${t.from} to ${t.to}`:t.from?`From ${t.from}`:`Until ${t.to}`;return[{id:e.key,text:n,clear:()=>s(e)}]}return[]}var E=new Set;function D(t){let n=!0;try{n=process.env.NODE_ENV!==`production`}catch{n=!0}!n||E.has(t)||(E.add(t),e(`[@webority/ui-react] <AppFilterBar> facet "${t}" sets allLabel, which only an enum facet uses.`))}var O=new Set;function k(t){let n=!0;try{n=process.env.NODE_ENV!==`production`}catch{n=!0}!n||O.has(t)||(O.add(t),e(`[@webority/ui-react] <AppFilterBar> facet "${t}" sets presets, which only a dateRange facet uses.`))}function A({facets:e,value:a,onChange:o,inline:l=b,floating:u=!1,apply:d=!1,className:y=``,...C}){n(`AppFilterBar`,C);let T=re(ie,ae,()=>!1),E=h(null),O=m(),[A,M]=ne({}),N=h(a);for(let n of e)t(`AppFilterBar`,`facets[].type`,n.type,S);for(let t of e)t.allLabel!=null&&t.type!==`enum`&&D(t.key),t.presets!=null&&t.type!==`dateRange`&&k(t.key);let P=e.filter(e=>!w(e)),F=P.flatMap(e=>se(e,a[e.key]).map(t=>({...t,facet:e}))),I=P.filter(e=>c(e,a[e.key])),L=u||T?0:Math.max(0,l),R=P.slice(L),z=R.filter(e=>I.includes(e)).length,B=!u&&R.length>0;p(()=>{if(!B)return;let e=e=>{let t=E.current;t?.open&&(e.type===`keydown`?e.key===`Escape`:!e.composedPath().includes(t))&&(t.open=!1)};return document.addEventListener(`click`,e),document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`click`,e),document.removeEventListener(`keydown`,e)}},[B]),p(()=>{let e=N.current;N.current=a,M(t=>{let n=Object.entries(t).filter(([t])=>oe(e[t],a[t]));return n.length===Object.keys(t).length?t:Object.fromEntries(n)})},[a]);let V=e=>d&&!u&&(e.type===`text`||e.type===`dateRange`),H=e=>V(e)&&Object.hasOwn(A,e.key)?A[e.key]:a[e.key],U=e=>t=>V(e)?M(n=>({...n,[e.key]:t})):o(e.key,t),W=()=>{for(let[e,t]of Object.entries(A))o(e,t);M({})},G=e=>{e.key===`Enter`&&W()},ce=e=>{e.preventDefault(),W()},K=(e,t)=>e.type===`text`&&V(e)?_(`span`,{onKeyDownCapture:G,children:t}):t,le=e=>_(te,{children:K(e,_(j,{facet:e,value:H(e),onChange:U(e)}))},e.key),q=e=>v(`div`,{className:`wui-filter-popover-field`,children:[_(`span`,{className:`label`,"aria-hidden":`true`,children:e.label}),K(e,_(j,{facet:e,value:H(e),onChange:U(e),floating:!0}))]},e.key),J=(e,t)=>t>0&&_(`span`,{className:e,children:` (${t})`}),Y=e=>_(ee,{size:`sm`,label:`${e.facet.label}: ${e.text}`,removeLabel:`Remove ${e.facet.label} filter ${e.text}`,onRemove:()=>o(e.facet.key,e.clear()),className:!u&&P.indexOf(e.facet)<L?`wui-filter-chip-inline`:void 0},e.id),X=_(i,{variant:`ghost`,size:`sm`,onClick:()=>{for(let e of I)o(e.key,s(e));M({})},children:`Clear all`});if(u){let e=F.slice(x),t=I.length;return v(`div`,{className:`wui-filter-bar d-flex flex-wrap align-items-center gap-2${y?` ${y}`:``}`,...C,children:[v(`wui-filter-popover`,{class:`wui-filter-popover`,children:[v(`button`,{type:`button`,className:`btn ${t>0?`btn-outline-primary`:`btn-ghost`} btn-sm wui-filter-popover-trigger`,"aria-expanded":`false`,"aria-controls":O,"aria-label":t>0?`Filters, ${t} active`:void 0,children:[_(r,{name:`filter`,size:14,className:`me-2`}),`Filters`,t>0&&_(`span`,{className:`badge rounded-pill text-bg-primary ms-1`,children:t})]}),v(`div`,{id:O,className:`wui-filter-popover-panel`,role:`dialog`,"aria-label":`Filters`,hidden:!0,children:[v(`div`,{className:`wui-filter-popover-head`,children:[_(`span`,{className:`wui-filter-popover-title`,children:`Filters`}),_(f,{label:`Keep open`,id:`${O}-pin`})]}),_(`div`,{className:`wui-filter-popover-grid`,children:P.map(q)}),v(`div`,{className:`wui-filter-popover-foot`,children:[_(`span`,{className:`wui-filter-popover-note`,children:`Changes apply at once.`}),t>0&&X]})]})]}),F.slice(0,x).map(Y),e.length>0&&v(`span`,{className:`chip chip-sm wui-filter-popover-more`,title:e.map(e=>`${e.facet.label}: ${e.text}`).join(`, `),children:[`+`,e.length]})]})}let Z=`wui-filter-bar d-flex flex-wrap align-items-center gap-2${T&&B?` wui-filter-bar--folded`:``}`,Q=e=>`${e}${y?` ${y}`:``}`,$=v(g,{children:[P.slice(0,L).map(le),B&&v(`details`,{ref:E,className:`wui-filter-more`,children:[v(`summary`,{className:`btn btn-outline-primary btn-sm wui-filter-more-trigger`,children:[_(r,{name:`filter`,size:14,className:`me-2`}),`Filters`,J(`wui-filter-count-desktop`,z),J(`wui-filter-count-phone`,I.length)]}),v(`div`,{className:`wui-filter-more-panel`,children:[_(`div`,{className:`wui-filter-more-head`,children:`Filters`}),R.map(q)]})]}),F.map(Y),I.length>0&&X]});return!d||!P.some(e=>e.type===`text`||e.type===`dateRange`)?_(`div`,{className:Q(Z),...C,children:$}):v(`div`,{className:Q(`wui-filter-form d-flex flex-wrap align-items-center gap-2`),...C,children:[_(`div`,{className:Z,children:$}),_(i,{type:`submit`,size:`sm`,onClick:ce,children:`Apply`})]})}function j({facet:e,value:t,onChange:n,floating:r=!1}){if(e.type===`enum`){let i=e.options??[];return i.length<C?_(a,{label:e.label,name:e.key,size:`sm`,value:t??``,onChange:n,options:[{value:``,label:e.allLabel||`All`},...i]}):_(d,{"aria-label":e.label,name:e.key,placeholder:r?`Any`:e.label,size:`sm`,clearable:!0,value:t??``,onChange:n,options:i})}return e.type===`multiEnum`?_(l,{"aria-label":e.label,name:e.key,placeholder:r?`Any`:e.label,size:`sm`,collapseChips:!0,values:t??[],onChange:n,options:e.options??[]}):e.type===`dateRange`?_(o,{ariaLabel:e.label,startName:`${e.key}From`,endName:`${e.key}To`,placeholder:r?`Any`:e.label,size:`sm`,presets:e.presets,start:t?.from??``,end:t?.to??``,onChange:e=>n({from:e.start??``,to:e.end??``})}):_(u,{ariaLabel:e.label,name:e.key,placeholder:e.label,size:`sm`,value:t??``,onChange:n})}export{A 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};
|
|
@@ -18,6 +18,8 @@ import "@webority/ui-elements/elements/filter-popover";
|
|
|
18
18
|
* into that one button and the panel becomes a sheet from the bottom edge. The button and Clear all
|
|
19
19
|
* never wrap.
|
|
20
20
|
*
|
|
21
|
+
* With `apply`, a search box or date range waits for Apply, or Enter in a search box, before it calls `onChange`; other choices still apply as they change.
|
|
22
|
+
*
|
|
21
23
|
* @param {object} props
|
|
22
24
|
* @param {{ key: string, label: string, type: 'enum'|'multiEnum'|'dateRange'|'text',
|
|
23
25
|
* options?: { value: string, label: string }[], allLabel?: string, presets?: string[] }[]} props.facets `options` fills an `enum` or `multiEnum`;
|
|
@@ -29,9 +31,10 @@ import "@webority/ui-elements/elements/filter-popover";
|
|
|
29
31
|
* Called with the facet key and its new value. Clear all calls it once per active facet, with the empty value.
|
|
30
32
|
* @param {number} [props.inline=3] How many facets stay in the row; the rest fold into the Filters button.
|
|
31
33
|
* @param {boolean} [props.floating=false] A floating panel: hover, click or F opens the facets in a non-modal panel under the Filters button, with a chip summary in the row.
|
|
34
|
+
* @param {boolean} [props.apply=false] Hold search and date range edits until Apply (or Enter in a search box), as the Razor app-filter-bar does; other choices still apply when they change. Apply shows only when a text or dateRange facet is present, and never with floating.
|
|
32
35
|
* @param {string} [props.className]
|
|
33
36
|
*/
|
|
34
|
-
export default function AppFilterBar({ facets: allFacets, value, onChange, inline, floating, className, ...rest }: {
|
|
37
|
+
export default function AppFilterBar({ facets: allFacets, value, onChange, inline, floating, apply, className, ...rest }: {
|
|
35
38
|
facets: {
|
|
36
39
|
key: string;
|
|
37
40
|
label: string;
|
|
@@ -53,5 +56,6 @@ export default function AppFilterBar({ facets: allFacets, value, onChange, inlin
|
|
|
53
56
|
}) => void;
|
|
54
57
|
inline?: number;
|
|
55
58
|
floating?: boolean;
|
|
59
|
+
apply?: boolean;
|
|
56
60
|
className?: string;
|
|
57
61
|
}): import("react").JSX.Element;
|
|
@@ -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.2",
|
|
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.2",
|
|
31
|
+
"@webority/ui-elements": "0.83.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@webority/analytics": "^0.25.0",
|