quirk-ui 0.1.134 → 0.1.135

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
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("react"),oe=require("../../hooks/useStyleClasses.cjs"),ce=require("../../context/LocaleBridge.cjs"),w=require("../../../index-CAS0iFfs.cjs"),ne=require("../../../core/components/Input/index.cjs"),re=require("../../../core/components/Select/index.cjs"),t=require("../../../CategoryFilters-oA43LCO6.cjs"),ie=require("../../../x-Dft9NVe_.cjs"),ue=[{label:"Newest",value:"date-desc"},{label:"Oldest",value:"date-asc"},{label:"Title A-Z",value:"title-asc"},{label:"Title Z-A",value:"title-desc"},{label:"Most Popular",value:"popular-desc"}];function de({heading:r,layout:X="grid",includeFilters:L,excludeFilters:q,limit:B=3,categoryFilters:h,documentType:E,styleOptions:G,initialDocuments:v=[],initialTotalCount:M=0,initialIncludeCategories:J=[],parentPage:$,id:K,renderRichText:o,renderCard:g}){const[Q,u]=s.useState(v),[V,Y]=s.useState(M),[b,R]=s.useState("date-desc"),[d,A]=s.useState(J),[P,f]=s.useState(v.length),[c,z]=s.useState(!1),[j,C]=s.useState(!1),[_,i]=s.useState(v.length<M),[y,x]=s.useState(""),[p,T]=s.useState(""),{locale:I}=ce.useLocaleBridge(),ee=oe.useStyleClasses(G),F=s.useRef(!1),H=s.useRef({sort:b,debouncedSearch:p,selectedCategories:d,start:P,isLoading:c,hasMore:_,limit:B,documentType:E,locale:I,includeFilters:L,excludeFilters:q,parentPage:$});H.current={sort:b,debouncedSearch:p,selectedCategories:d,start:P,isLoading:c,hasMore:_,limit:B,documentType:E,locale:I,includeFilters:L,excludeFilters:q,parentPage:$};const se=X==="list"?t.styles.list:void 0,O=s.useCallback(()=>{C(l=>!l)},[]),te=s.useCallback(l=>{R(l.target.value),u([]),f(0),i(!0)},[]),le=s.useCallback(()=>{u([]),f(0),i(!0),A([]),x(""),C(!1)},[]),ae=s.useCallback(l=>{u([]),f(0),i(!0),A(l)},[]),D=s.useRef(async(l=!1)=>{var W,Z,U;const a=H.current;if(!l&&(a.isLoading||!a.hasMore))return;z(!0);const m=new URLSearchParams({start:l?"0":String(a.start),limit:String(a.limit),sort:a.sort,documentType:a.documentType,locale:a.locale});a.debouncedSearch&&m.append("search",a.debouncedSearch),a.selectedCategories.forEach(n=>m.append("categories",n)),(W=a.includeFilters)==null||W.forEach(n=>m.append("include",n._id)),(Z=a.excludeFilters)==null||Z.forEach(n=>m.append("exclude",n._id)),(U=a.parentPage)!=null&&U._ref&&m.append("parentRef",a.parentPage._ref);try{const S=await(await fetch(`/api/articles?${m.toString()}`)).json();u(k=>l?S.documents:[...k,...S.documents]),f(k=>l?a.limit:k+a.limit),Y(S.totalCount),i((l?0:a.start)+S.articles.length<S.totalCount)}catch(n){console.error("Failed to load articles:",n),i(!1)}finally{z(!1)}}).current,N=s.useCallback(()=>{window.innerWidth>768&&(C(!1),document.body.style.overflow="")},[]);return s.useEffect(()=>(window.addEventListener("resize",N),()=>window.removeEventListener("resize",N)),[N]),s.useEffect(()=>(document.body.style.overflow=j?"hidden":"",()=>{document.body.style.overflow=""}),[j]),s.useEffect(()=>{const l=setTimeout(()=>T(y),500);return()=>clearTimeout(l)},[y]),s.useEffect(()=>{if(!F.current){F.current=!0;return}(p||b!=="date-desc"||d.length>0)&&D(!0)},[p,b,d.join(",")]),e.jsx("section",{id:K,className:`${t.styles.documentList} ${ee}`,children:e.jsxs("article",{className:t.styles.container,children:[e.jsxs("div",{className:t.styles.heading,children:[e.jsxs("div",{children:[r.eyebrow&&(o==null?void 0:o({blocks:r.eyebrow,className:t.styles.eyebrow})),o==null?void 0:o({blocks:r.title,className:t.styles.title})]})," ",(r==null?void 0:r.description)&&(o==null?void 0:o({blocks:r.description}))]}),e.jsxs("div",{className:t.styles.listContainer,children:[h!=null&&h.length?e.jsxs("div",{className:t.styles.filterToggle,children:[e.jsx(w.Button,{as:"button",variant:"secondary",onClick:O,disabled:c,icon:"settings",iconAlignment:"left",children:"Filters"}),e.jsx(w.Button,{as:"button",variant:"link",onClick:le,disabled:c||d.length===0&&y.length===0,children:"Reset"})]}):null,h&&e.jsx(t.CategoryFilters,{categoryFilters:h,selectedCategories:d,onSelectionChange:ae,showFilters:j,toggleFilters:O,isLoading:c}),e.jsxs("div",{className:t.styles.listWrapper,children:[e.jsxs("div",{className:t.styles.listHeader,children:[e.jsxs("div",{className:t.styles.listResults,children:["Results: ",e.jsx("span",{children:V})]}),e.jsxs("div",{className:t.styles.listHeaderFilters,children:[e.jsxs("div",{className:t.styles.listSearch,children:[e.jsx(ne.Input,{type:"text",name:"list-search",placeholder:"Search articles",value:y,onChange:l=>{x(l.target.value),u([]),f(0),i(!0)}}),y&&e.jsx("button",{className:t.styles.clearSearch,onClick:()=>{x(""),u([]),f(0),i(!0)},children:e.jsx(ie.X,{size:21})})]}),e.jsx("div",{className:t.styles.listSort,children:e.jsx(re.Select,{id:"list-sort",name:"list-sort","aria-label":"Sort by",options:ue,onChange:te})})]})]}),e.jsx("div",{className:`${t.styles.list} ${se??""}`,children:Q.map(l=>g==null?void 0:g(l))}),_&&e.jsx("div",{className:t.styles.loadMore,children:e.jsx(w.Button,{as:"button",variant:"primary",onClick:()=>D(!1),disabled:c,icon:"refresh",iconAlignment:"left",className:c?t.styles.buttonIsLoading:"",children:c?"Loading...":"Load more"})})]})]})]})})}exports.DocumentListBlock=de;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("react"),oe=require("../../hooks/useStyleClasses.cjs"),ce=require("../../context/LocaleBridge.cjs"),w=require("../../../index-CAS0iFfs.cjs"),ne=require("../../../core/components/Input/index.cjs"),re=require("../../../core/components/Select/index.cjs"),t=require("../../../CategoryFilters-oA43LCO6.cjs"),ie=require("../../../x-Dft9NVe_.cjs"),ue=[{label:"Newest",value:"date-desc"},{label:"Oldest",value:"date-asc"},{label:"Title A-Z",value:"title-asc"},{label:"Title Z-A",value:"title-desc"},{label:"Most Popular",value:"popular-desc"}];function de({heading:r,layout:X="grid",includeFilters:L,excludeFilters:q,limit:B=3,categoryFilters:h,documentType:E,styleOptions:G,initialDocuments:v=[],initialTotalCount:M=0,initialIncludeCategories:J=[],parentPage:$,id:K,renderRichText:o,renderCard:g}){const[Q,u]=s.useState(v),[V,Y]=s.useState(M),[b,R]=s.useState("date-desc"),[d,A]=s.useState(J),[P,f]=s.useState(v.length),[c,z]=s.useState(!1),[j,C]=s.useState(!1),[_,i]=s.useState(v.length<M),[y,x]=s.useState(""),[p,T]=s.useState(""),{locale:I}=ce.useLocaleBridge(),ee=oe.useStyleClasses(G),F=s.useRef(!1),H=s.useRef({sort:b,debouncedSearch:p,selectedCategories:d,start:P,isLoading:c,hasMore:_,limit:B,documentType:E,locale:I,includeFilters:L,excludeFilters:q,parentPage:$});H.current={sort:b,debouncedSearch:p,selectedCategories:d,start:P,isLoading:c,hasMore:_,limit:B,documentType:E,locale:I,includeFilters:L,excludeFilters:q,parentPage:$};const se=X==="list"?t.styles.list:void 0,O=s.useCallback(()=>{C(l=>!l)},[]),te=s.useCallback(l=>{R(l.target.value),u([]),f(0),i(!0)},[]),le=s.useCallback(()=>{u([]),f(0),i(!0),A([]),x(""),C(!1)},[]),ae=s.useCallback(l=>{u([]),f(0),i(!0),A(l)},[]),D=s.useRef(async(l=!1)=>{var W,Z,U;const a=H.current;if(!l&&(a.isLoading||!a.hasMore))return;z(!0);const m=new URLSearchParams({start:l?"0":String(a.start),limit:String(a.limit),sort:a.sort,documentType:a.documentType,locale:a.locale});a.debouncedSearch&&m.append("search",a.debouncedSearch),a.selectedCategories.forEach(n=>m.append("categories",n)),(W=a.includeFilters)==null||W.forEach(n=>m.append("include",n._id)),(Z=a.excludeFilters)==null||Z.forEach(n=>m.append("exclude",n._id)),(U=a.parentPage)!=null&&U._ref&&m.append("parentRef",a.parentPage._ref);try{const S=await(await fetch(`/api/documents?${m.toString()}`)).json();u(k=>l?S.documents:[...k,...S.documents]),f(k=>l?a.limit:k+a.limit),Y(S.totalCount),i((l?0:a.start)+S.articles.length<S.totalCount)}catch(n){console.error("Failed to load articles:",n),i(!1)}finally{z(!1)}}).current,N=s.useCallback(()=>{window.innerWidth>768&&(C(!1),document.body.style.overflow="")},[]);return s.useEffect(()=>(window.addEventListener("resize",N),()=>window.removeEventListener("resize",N)),[N]),s.useEffect(()=>(document.body.style.overflow=j?"hidden":"",()=>{document.body.style.overflow=""}),[j]),s.useEffect(()=>{const l=setTimeout(()=>T(y),500);return()=>clearTimeout(l)},[y]),s.useEffect(()=>{if(!F.current){F.current=!0;return}(p||b!=="date-desc"||d.length>0)&&D(!0)},[p,b,d.join(",")]),e.jsx("section",{id:K,className:`${t.styles.documentList} ${ee}`,children:e.jsxs("article",{className:t.styles.container,children:[e.jsxs("div",{className:t.styles.heading,children:[e.jsxs("div",{children:[r.eyebrow&&(o==null?void 0:o({blocks:r.eyebrow,className:t.styles.eyebrow})),o==null?void 0:o({blocks:r.title,className:t.styles.title})]})," ",(r==null?void 0:r.description)&&(o==null?void 0:o({blocks:r.description}))]}),e.jsxs("div",{className:t.styles.listContainer,children:[h!=null&&h.length?e.jsxs("div",{className:t.styles.filterToggle,children:[e.jsx(w.Button,{as:"button",variant:"secondary",onClick:O,disabled:c,icon:"settings",iconAlignment:"left",children:"Filters"}),e.jsx(w.Button,{as:"button",variant:"link",onClick:le,disabled:c||d.length===0&&y.length===0,children:"Reset"})]}):null,h&&e.jsx(t.CategoryFilters,{categoryFilters:h,selectedCategories:d,onSelectionChange:ae,showFilters:j,toggleFilters:O,isLoading:c}),e.jsxs("div",{className:t.styles.listWrapper,children:[e.jsxs("div",{className:t.styles.listHeader,children:[e.jsxs("div",{className:t.styles.listResults,children:["Results: ",e.jsx("span",{children:V})]}),e.jsxs("div",{className:t.styles.listHeaderFilters,children:[e.jsxs("div",{className:t.styles.listSearch,children:[e.jsx(ne.Input,{type:"text",name:"list-search",placeholder:"Search articles",value:y,onChange:l=>{x(l.target.value),u([]),f(0),i(!0)}}),y&&e.jsx("button",{className:t.styles.clearSearch,onClick:()=>{x(""),u([]),f(0),i(!0)},children:e.jsx(ie.X,{size:21})})]}),e.jsx("div",{className:t.styles.listSort,children:e.jsx(re.Select,{id:"list-sort",name:"list-sort","aria-label":"Sort by",options:ue,onChange:te})})]})]}),e.jsx("div",{className:`${t.styles.list} ${se??""}`,children:Q.map(l=>g==null?void 0:g(l))}),_&&e.jsx("div",{className:t.styles.loadMore,children:e.jsx(w.Button,{as:"button",variant:"primary",onClick:()=>D(!1),disabled:c,icon:"refresh",iconAlignment:"left",className:c?t.styles.buttonIsLoading:"",children:c?"Loading...":"Load more"})})]})]})]})})}exports.DocumentListBlock=de;
@@ -92,7 +92,7 @@ function Ae({
92
92
  (r) => h.append("categories", r)
93
93
  ), (J = s.includeFilters) == null || J.forEach((r) => h.append("include", r._id)), (K = s.excludeFilters) == null || K.forEach((r) => h.append("exclude", r._id)), (Q = s.parentPage) != null && Q._ref && h.append("parentRef", s.parentPage._ref);
94
94
  try {
95
- const b = await (await fetch(`/api/articles?${h.toString()}`)).json();
95
+ const b = await (await fetch(`/api/documents?${h.toString()}`)).json();
96
96
  u(
97
97
  (P) => t ? b.documents : [...P, ...b.documents]
98
98
  ), f((P) => t ? s.limit : P + s.limit), te(b.totalCount), d(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "quirk-ui",
3
3
  "private": false,
4
- "version": "0.1.134",
4
+ "version": "0.1.135",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {