quirk-ui 0.1.134 → 0.1.136
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"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("react"),oe=require("../../hooks/useStyleClasses.cjs"),ne=require("../../context/LocaleBridge.cjs"),w=require("../../../index-CAS0iFfs.cjs"),ce=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,P]=s.useState(J),[z,m]=s.useState(v.length),[n,A]=s.useState(!1),[j,C]=s.useState(!1),[_,i]=s.useState(v.length<M),[y,x]=s.useState(""),[p,T]=s.useState(""),{locale:D}=ne.useLocaleBridge(),ee=oe.useStyleClasses(G),I=s.useRef(!1),F=s.useRef({sort:b,debouncedSearch:p,selectedCategories:d,start:z,isLoading:n,hasMore:_,limit:B,documentType:E,locale:D,includeFilters:L,excludeFilters:q,parentPage:$});F.current={sort:b,debouncedSearch:p,selectedCategories:d,start:z,isLoading:n,hasMore:_,limit:B,documentType:E,locale:D,includeFilters:L,excludeFilters:q,parentPage:$};const se=X==="list"?t.styles.list:void 0,H=s.useCallback(()=>{C(l=>!l)},[]),te=s.useCallback(l=>{R(l.target.value),u([]),m(0),i(!0)},[]),le=s.useCallback(()=>{u([]),m(0),i(!0),P([]),x(""),C(!1)},[]),ae=s.useCallback(l=>{u([]),m(0),i(!0),P(l)},[]),O=s.useRef(async(l=!1)=>{var W,Z,U;const a=F.current;if(!l&&(a.isLoading||!a.hasMore))return;A(!0);const f=new URLSearchParams({start:l?"0":String(a.start),limit:String(a.limit),sort:a.sort,documentType:a.documentType,locale:a.locale});a.debouncedSearch&&f.append("search",a.debouncedSearch),a.selectedCategories.forEach(c=>f.append("categories",c)),(W=a.includeFilters)==null||W.forEach(c=>f.append("include",c._id)),(Z=a.excludeFilters)==null||Z.forEach(c=>f.append("exclude",c._id)),(U=a.parentPage)!=null&&U._ref&&f.append("parentRef",a.parentPage._ref);try{const S=await(await fetch(`/api/documents?${f.toString()}`)).json();u(k=>l?S.documents:[...k,...S.documents]),m(k=>l?a.limit:k+a.limit),Y(S.totalCount),i((l?0:a.start)+S.documents.length<S.totalCount)}catch(c){console.error("Failed to load documents:",c),i(!1)}finally{A(!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(!I.current){I.current=!0;return}(p||b!=="date-desc"||d.length>0)&&O(!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:H,disabled:n,icon:"settings",iconAlignment:"left",children:"Filters"}),e.jsx(w.Button,{as:"button",variant:"link",onClick:le,disabled:n||d.length===0&&y.length===0,children:"Reset"})]}):null,h&&e.jsx(t.CategoryFilters,{categoryFilters:h,selectedCategories:d,onSelectionChange:ae,showFilters:j,toggleFilters:H,isLoading:n}),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(ce.Input,{type:"text",name:"list-search",placeholder:"Search",value:y,onChange:l=>{x(l.target.value),u([]),m(0),i(!0)}}),y&&e.jsx("button",{className:t.styles.clearSearch,onClick:()=>{x(""),u([]),m(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:()=>O(!1),disabled:n,icon:"refresh",iconAlignment:"left",className:n?t.styles.buttonIsLoading:"",children:n?"Loading...":"Load more"})})]})]})]})})}exports.DocumentListBlock=de;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
1
|
+
import { jsx as o, jsxs as a } from "react/jsx-runtime";
|
|
2
|
+
import { useState as l, useRef as j, useCallback as g, useEffect as w } from "react";
|
|
3
3
|
import { useStyleClasses as ie } from "../../hooks/useStyleClasses.mjs";
|
|
4
4
|
import { useLocaleBridge as de } from "../../context/LocaleBridge.mjs";
|
|
5
|
-
import { B as
|
|
5
|
+
import { B as z } from "../../../index-Cahn_yoK.js";
|
|
6
6
|
import { Input as ue } from "../../../core/components/Input/index.mjs";
|
|
7
7
|
import { Select as me } from "../../../core/components/Select/index.mjs";
|
|
8
8
|
import { s as e, C as fe } from "../../../CategoryFilters-CR4MkgvA.js";
|
|
@@ -14,10 +14,10 @@ const pe = [
|
|
|
14
14
|
{ label: "Title Z-A", value: "title-desc" },
|
|
15
15
|
{ label: "Most Popular", value: "popular-desc" }
|
|
16
16
|
];
|
|
17
|
-
function
|
|
17
|
+
function Ee({
|
|
18
18
|
heading: i,
|
|
19
19
|
layout: V = "grid",
|
|
20
|
-
includeFilters:
|
|
20
|
+
includeFilters: A,
|
|
21
21
|
excludeFilters: B,
|
|
22
22
|
limit: _ = 3,
|
|
23
23
|
categoryFilters: p,
|
|
@@ -26,46 +26,46 @@ function Ae({
|
|
|
26
26
|
initialDocuments: C = [],
|
|
27
27
|
initialTotalCount: I = 0,
|
|
28
28
|
initialIncludeCategories: R = [],
|
|
29
|
-
parentPage:
|
|
29
|
+
parentPage: D,
|
|
30
30
|
id: T,
|
|
31
31
|
renderRichText: n,
|
|
32
32
|
renderCard: y
|
|
33
33
|
}) {
|
|
34
|
-
const [x, u] =
|
|
34
|
+
const [x, u] = l(C), [ee, te] = l(
|
|
35
35
|
I
|
|
36
|
-
), [S, se] =
|
|
36
|
+
), [S, se] = l("date-desc"), [m, F] = l(
|
|
37
37
|
R
|
|
38
|
-
), [
|
|
38
|
+
), [O, f] = l(C.length), [c, W] = l(!1), [L, k] = l(!1), [E, d] = l(
|
|
39
39
|
C.length < I
|
|
40
|
-
), [v,
|
|
40
|
+
), [v, M] = l(""), [N, oe] = l(""), { locale: Z } = de(), ae = ie(Y), q = j(!1), U = j({
|
|
41
41
|
sort: S,
|
|
42
42
|
debouncedSearch: N,
|
|
43
43
|
selectedCategories: m,
|
|
44
|
-
start:
|
|
44
|
+
start: O,
|
|
45
45
|
isLoading: c,
|
|
46
|
-
hasMore:
|
|
46
|
+
hasMore: E,
|
|
47
47
|
limit: _,
|
|
48
48
|
documentType: H,
|
|
49
|
-
locale:
|
|
50
|
-
includeFilters:
|
|
49
|
+
locale: Z,
|
|
50
|
+
includeFilters: A,
|
|
51
51
|
excludeFilters: B,
|
|
52
|
-
parentPage:
|
|
52
|
+
parentPage: D
|
|
53
53
|
});
|
|
54
|
-
|
|
54
|
+
U.current = {
|
|
55
55
|
sort: S,
|
|
56
56
|
debouncedSearch: N,
|
|
57
57
|
selectedCategories: m,
|
|
58
|
-
start:
|
|
58
|
+
start: O,
|
|
59
59
|
isLoading: c,
|
|
60
|
-
hasMore:
|
|
60
|
+
hasMore: E,
|
|
61
61
|
limit: _,
|
|
62
62
|
documentType: H,
|
|
63
|
-
locale:
|
|
64
|
-
includeFilters:
|
|
63
|
+
locale: Z,
|
|
64
|
+
includeFilters: A,
|
|
65
65
|
excludeFilters: B,
|
|
66
|
-
parentPage:
|
|
66
|
+
parentPage: D
|
|
67
67
|
};
|
|
68
|
-
const
|
|
68
|
+
const le = V === "list" ? e.list : void 0, X = g(() => {
|
|
69
69
|
k((t) => !t);
|
|
70
70
|
}, []), ne = g(
|
|
71
71
|
(t) => {
|
|
@@ -73,14 +73,14 @@ function Ae({
|
|
|
73
73
|
},
|
|
74
74
|
[]
|
|
75
75
|
), ce = g(() => {
|
|
76
|
-
u([]), f(0), d(!0),
|
|
76
|
+
u([]), f(0), d(!0), F([]), M(""), k(!1);
|
|
77
77
|
}, []), re = g((t) => {
|
|
78
|
-
u([]), f(0), d(!0),
|
|
79
|
-
}, []), G =
|
|
78
|
+
u([]), f(0), d(!0), F(t);
|
|
79
|
+
}, []), G = j(async (t = !1) => {
|
|
80
80
|
var J, K, Q;
|
|
81
|
-
const s =
|
|
81
|
+
const s = U.current;
|
|
82
82
|
if (!t && (s.isLoading || !s.hasMore)) return;
|
|
83
|
-
|
|
83
|
+
W(!0);
|
|
84
84
|
const h = new URLSearchParams({
|
|
85
85
|
start: t ? "0" : String(s.start),
|
|
86
86
|
limit: String(s.limit),
|
|
@@ -92,32 +92,32 @@ 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/
|
|
95
|
+
const b = await (await fetch(`/api/documents?${h.toString()}`)).json();
|
|
96
96
|
u(
|
|
97
|
-
(
|
|
98
|
-
), f((
|
|
99
|
-
(t ? 0 : s.start) + b.
|
|
97
|
+
($) => t ? b.documents : [...$, ...b.documents]
|
|
98
|
+
), f(($) => t ? s.limit : $ + s.limit), te(b.totalCount), d(
|
|
99
|
+
(t ? 0 : s.start) + b.documents.length < b.totalCount
|
|
100
100
|
);
|
|
101
101
|
} catch (r) {
|
|
102
|
-
console.error("Failed to load
|
|
102
|
+
console.error("Failed to load documents:", r), d(!1);
|
|
103
103
|
} finally {
|
|
104
|
-
|
|
104
|
+
W(!1);
|
|
105
105
|
}
|
|
106
|
-
}).current,
|
|
106
|
+
}).current, P = g(() => {
|
|
107
107
|
window.innerWidth > 768 && (k(!1), document.body.style.overflow = "");
|
|
108
108
|
}, []);
|
|
109
|
-
return w(() => (window.addEventListener("resize",
|
|
109
|
+
return w(() => (window.addEventListener("resize", P), () => window.removeEventListener("resize", P)), [P]), w(() => (document.body.style.overflow = L ? "hidden" : "", () => {
|
|
110
110
|
document.body.style.overflow = "";
|
|
111
111
|
}), [L]), w(() => {
|
|
112
|
-
const t = setTimeout(() =>
|
|
112
|
+
const t = setTimeout(() => oe(v), 500);
|
|
113
113
|
return () => clearTimeout(t);
|
|
114
114
|
}, [v]), w(() => {
|
|
115
|
-
if (!
|
|
116
|
-
|
|
115
|
+
if (!q.current) {
|
|
116
|
+
q.current = !0;
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
(N || S !== "date-desc" || m.length > 0) && G(!0);
|
|
120
|
-
}, [N, S, m.join(",")]), /* @__PURE__ */
|
|
120
|
+
}, [N, S, m.join(",")]), /* @__PURE__ */ o("section", { id: T, className: `${e.documentList} ${ae}`, children: /* @__PURE__ */ a("article", { className: e.container, children: [
|
|
121
121
|
/* @__PURE__ */ a("div", { className: e.heading, children: [
|
|
122
122
|
/* @__PURE__ */ a("div", { children: [
|
|
123
123
|
i.eyebrow && (n == null ? void 0 : n({
|
|
@@ -134,20 +134,20 @@ function Ae({
|
|
|
134
134
|
] }),
|
|
135
135
|
/* @__PURE__ */ a("div", { className: e.listContainer, children: [
|
|
136
136
|
p != null && p.length ? /* @__PURE__ */ a("div", { className: e.filterToggle, children: [
|
|
137
|
-
/* @__PURE__ */
|
|
138
|
-
|
|
137
|
+
/* @__PURE__ */ o(
|
|
138
|
+
z,
|
|
139
139
|
{
|
|
140
140
|
as: "button",
|
|
141
141
|
variant: "secondary",
|
|
142
|
-
onClick:
|
|
142
|
+
onClick: X,
|
|
143
143
|
disabled: c,
|
|
144
144
|
icon: "settings",
|
|
145
145
|
iconAlignment: "left",
|
|
146
146
|
children: "Filters"
|
|
147
147
|
}
|
|
148
148
|
),
|
|
149
|
-
/* @__PURE__ */
|
|
150
|
-
|
|
149
|
+
/* @__PURE__ */ o(
|
|
150
|
+
z,
|
|
151
151
|
{
|
|
152
152
|
as: "button",
|
|
153
153
|
variant: "link",
|
|
@@ -157,14 +157,14 @@ function Ae({
|
|
|
157
157
|
}
|
|
158
158
|
)
|
|
159
159
|
] }) : null,
|
|
160
|
-
p && /* @__PURE__ */
|
|
160
|
+
p && /* @__PURE__ */ o(
|
|
161
161
|
fe,
|
|
162
162
|
{
|
|
163
163
|
categoryFilters: p,
|
|
164
164
|
selectedCategories: m,
|
|
165
165
|
onSelectionChange: re,
|
|
166
166
|
showFilters: L,
|
|
167
|
-
toggleFilters:
|
|
167
|
+
toggleFilters: X,
|
|
168
168
|
isLoading: c
|
|
169
169
|
}
|
|
170
170
|
),
|
|
@@ -172,34 +172,34 @@ function Ae({
|
|
|
172
172
|
/* @__PURE__ */ a("div", { className: e.listHeader, children: [
|
|
173
173
|
/* @__PURE__ */ a("div", { className: e.listResults, children: [
|
|
174
174
|
"Results: ",
|
|
175
|
-
/* @__PURE__ */
|
|
175
|
+
/* @__PURE__ */ o("span", { children: ee })
|
|
176
176
|
] }),
|
|
177
177
|
/* @__PURE__ */ a("div", { className: e.listHeaderFilters, children: [
|
|
178
178
|
/* @__PURE__ */ a("div", { className: e.listSearch, children: [
|
|
179
|
-
/* @__PURE__ */
|
|
179
|
+
/* @__PURE__ */ o(
|
|
180
180
|
ue,
|
|
181
181
|
{
|
|
182
182
|
type: "text",
|
|
183
183
|
name: "list-search",
|
|
184
|
-
placeholder: "Search
|
|
184
|
+
placeholder: "Search",
|
|
185
185
|
value: v,
|
|
186
186
|
onChange: (t) => {
|
|
187
|
-
|
|
187
|
+
M(t.target.value), u([]), f(0), d(!0);
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
),
|
|
191
|
-
v && /* @__PURE__ */
|
|
191
|
+
v && /* @__PURE__ */ o(
|
|
192
192
|
"button",
|
|
193
193
|
{
|
|
194
194
|
className: e.clearSearch,
|
|
195
195
|
onClick: () => {
|
|
196
|
-
|
|
196
|
+
M(""), u([]), f(0), d(!0);
|
|
197
197
|
},
|
|
198
|
-
children: /* @__PURE__ */
|
|
198
|
+
children: /* @__PURE__ */ o(he, { size: 21 })
|
|
199
199
|
}
|
|
200
200
|
)
|
|
201
201
|
] }),
|
|
202
|
-
/* @__PURE__ */
|
|
202
|
+
/* @__PURE__ */ o("div", { className: e.listSort, children: /* @__PURE__ */ o(
|
|
203
203
|
me,
|
|
204
204
|
{
|
|
205
205
|
id: "list-sort",
|
|
@@ -211,9 +211,9 @@ function Ae({
|
|
|
211
211
|
) })
|
|
212
212
|
] })
|
|
213
213
|
] }),
|
|
214
|
-
/* @__PURE__ */
|
|
215
|
-
|
|
216
|
-
|
|
214
|
+
/* @__PURE__ */ o("div", { className: `${e.list} ${le ?? ""}`, children: x.map((t) => y == null ? void 0 : y(t)) }),
|
|
215
|
+
E && /* @__PURE__ */ o("div", { className: e.loadMore, children: /* @__PURE__ */ o(
|
|
216
|
+
z,
|
|
217
217
|
{
|
|
218
218
|
as: "button",
|
|
219
219
|
variant: "primary",
|
|
@@ -230,5 +230,5 @@ function Ae({
|
|
|
230
230
|
] }) });
|
|
231
231
|
}
|
|
232
232
|
export {
|
|
233
|
-
|
|
233
|
+
Ee as DocumentListBlock
|
|
234
234
|
};
|