quirk-ui 0.0.477 → 0.0.478
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"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),B=require("../../ui/PortableTextRenderer/index.cjs"),G=require("../../hooks/useStyleClasses.cjs"),X=require("../../contexts/LocaleBridge.cjs"),b=require("../../../index-DpYgzTme.cjs"),J=require("../../../core/components/Input/index.cjs"),K=require("../../../core/components/Select/index.cjs"),Q=require("../../cards/BlogArticleCard/index.cjs"),s=require("../../../CategoryFilters-CJsgwMGz.cjs"),V=require("../../../x-Dft9NVe_.cjs"),Y=[{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 F({heading:l,layout:P="grid",includeFilters:y,excludeFilters:x,limit:C=3,categoryFilters:d,documentType:_,styleOptions:$}){const[N,r]=o.useState([]),[M,z]=o.useState(null),[g,D]=o.useState("date-desc"),[f,L]=o.useState(()=>typeof window>"u"?[]:Array.from(new URLSearchParams(window.location.search).getAll("categories"))),[S]=o.useState(()=>typeof window>"u"?null:new URLSearchParams(window.location.search).get("type")),[T,c]=o.useState(0),[i,A]=o.useState(!1),[m,h]=o.useState(!1),[k,n]=o.useState(!0),[u,w]=o.useState(""),[v,I]=o.useState(""),{locale:H}=X.useLocaleBridge(),O=G.useStyleClasses($),U={list:s.styles.list}[P??"grid"],W=t=>{D(t.target.value),r([]),c(0),n(!0)},q=()=>{h(!m)},Z=()=>{r([]),c(0),n(!0),L([]),w(""),h(!1)},R=async()=>{if(i||!k)return;A(!0);const t=new URLSearchParams({start:String(T),limit:String(C),sort:g,documentType:_,locale:H});S&&t.append("type",S),v&&t.append("search",v),f.forEach(a=>t.append("categories",a)),y==null||y.forEach(a=>t.append("include",a._id)),x==null||x.forEach(a=>t.append("exclude",a._id));try{const p=await(await fetch(`/api/articles?${t.toString()}`,{method:"GET"})).json();r(j=>[...j,...p.articles]),c(j=>j+C),z(p.totalCount),T+p.articles.length>=p.totalCount&&n(!1)}catch(a){console.error("Failed to load articles:",a),n(!1)}finally{A(!1)}},E=o.useCallback(()=>{typeof window<"u"&&window.innerWidth>768&&(h(!1),typeof document<"u"&&(document.body.style.overflow=""))},[]);return o.useEffect(()=>{const t=typeof window<"u";return t&&window.addEventListener("resize",E),()=>{t&&window.removeEventListener("resize",E)}},[]),o.useEffect(()=>{if(typeof document<"u")return document.body.style.overflow=m?"hidden":"",()=>{document.body.style.overflow=""}},[m]),o.useEffect(()=>{const t=setTimeout(()=>{I(u)},1e3);return()=>clearTimeout(t)},[u]),o.useEffect(()=>{r([]),c(0),n(!0),R()},[v,g,f.join(","),S]),e.jsx("section",{className:`${s.styles.documentList} ${O}`,children:e.jsxs("article",{className:s.styles.container,children:[e.jsxs("div",{className:s.styles.heading,children:[(l==null?void 0:l.title)&&e.jsx(B.RichText,{blocks:l==null?void 0:l.title}),(l==null?void 0:l.description)&&e.jsx(B.RichText,{blocks:l==null?void 0:l.description})]}),e.jsxs("div",{className:s.styles.listContainer,children:[(d==null?void 0:d.length)&&e.jsxs("div",{className:s.styles.filterToggle,children:[e.jsx(b.CallToAction,{as:"button",variant:"secondary",onClick:q,disabled:i,icon:"settings",iconAlignment:"left",children:"Filters"}),e.jsx(b.CallToAction,{as:"button",variant:"link",onClick:Z,disabled:i||f.length===0&&u.length===0,children:"Reset"})]}),d&&e.jsx(s.CategoryFilters,{categoryFilters:d,selectedCategories:f,setSelectedCategories:L,setArticles:r,setStart:c,setHasMore:n,showFilters:m,toggleFilters:q,isLoading:i}),e.jsxs("div",{className:s.styles.listWrapper,children:[e.jsxs("div",{className:s.styles.listHeader,children:[e.jsxs("div",{className:s.styles.listResults,children:["Results: ",e.jsx("span",{children:M})]}),e.jsxs("div",{className:s.styles.listHeaderFilters,children:[e.jsxs("div",{className:s.styles.listSearch,children:[e.jsx(J.Input,{type:"text",name:"list-search",placeholder:"Search articles",value:u,onChange:t=>{w(t.target.value),r([]),c(0),n(!0)}}),u&&e.jsx("button",{className:s.styles.clearSearch,onClick:()=>{w(""),r([]),c(0),n(!0)},children:e.jsx(V.X,{size:21})})]}),e.jsx("div",{className:s.styles.listSort,children:e.jsx(K.Select,{id:"list-sort",name:"list-sort",options:Y,onChange:W})})]})]}),e.jsx("div",{className:`${s.styles.list} ${U}`,children:N&&N.map(t=>_=="blog"&&e.jsx(Q.BlogArticleCard,{article:t},t._id))}),k&&e.jsx("div",{className:s.styles.loadMore,children:e.jsx(b.CallToAction,{as:"button",variant:"primary",onClick:R,disabled:i,icon:"refresh",iconAlignment:"left",className:i?s.styles.buttonIsLoading:"",children:i?"Loading...":"Load more"})})]})]})]})})}exports.DocumentListBlock=F;
|
|
@@ -1,109 +1,103 @@
|
|
|
1
|
-
import { jsx as t, jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { RichText as
|
|
4
|
-
import { useStyleClasses as
|
|
5
|
-
import { useLocaleBridge as
|
|
6
|
-
import { C as
|
|
7
|
-
import { Input as
|
|
8
|
-
import { Select as
|
|
9
|
-
import { BlogArticleCard as
|
|
10
|
-
import { s, C as
|
|
11
|
-
import { X as
|
|
12
|
-
const
|
|
1
|
+
import { jsx as t, jsxs as a } from "react/jsx-runtime";
|
|
2
|
+
import { useState as r, useCallback as J, useEffect as v } from "react";
|
|
3
|
+
import { RichText as H } from "../../ui/PortableTextRenderer/index.mjs";
|
|
4
|
+
import { useStyleClasses as K } from "../../hooks/useStyleClasses.mjs";
|
|
5
|
+
import { useLocaleBridge as Q } from "../../contexts/LocaleBridge.mjs";
|
|
6
|
+
import { C as g } from "../../../index-CIb65n0z.js";
|
|
7
|
+
import { Input as V } from "../../../core/components/Input/index.mjs";
|
|
8
|
+
import { Select as Y } from "../../../core/components/Select/index.mjs";
|
|
9
|
+
import { BlogArticleCard as F } from "../../cards/BlogArticleCard/index.mjs";
|
|
10
|
+
import { s, C as ee } from "../../../CategoryFilters-BrPk0efZ.js";
|
|
11
|
+
import { X as te } from "../../../x-CnsEH4Ox.js";
|
|
12
|
+
const se = [
|
|
13
13
|
{ label: "Newest", value: "date-desc" },
|
|
14
14
|
{ label: "Oldest", value: "date-asc" },
|
|
15
15
|
{ label: "Title A-Z", value: "title-asc" },
|
|
16
16
|
{ label: "Title Z-A", value: "title-desc" },
|
|
17
17
|
{ label: "Most Popular", value: "popular-desc" }
|
|
18
18
|
];
|
|
19
|
-
function
|
|
19
|
+
function pe({
|
|
20
20
|
heading: o,
|
|
21
|
-
layout:
|
|
21
|
+
layout: I = "grid",
|
|
22
22
|
includeFilters: b,
|
|
23
23
|
excludeFilters: C,
|
|
24
|
-
limit:
|
|
24
|
+
limit: A = 3,
|
|
25
25
|
categoryFilters: f,
|
|
26
|
-
documentType:
|
|
26
|
+
documentType: k,
|
|
27
27
|
// filterMode,
|
|
28
|
-
styleOptions:
|
|
28
|
+
styleOptions: U
|
|
29
29
|
}) {
|
|
30
|
-
const [
|
|
30
|
+
const [T, i] = r([]), [W, _] = r(null), [R, x] = r("date-desc"), [u, E] = r(() => typeof window > "u" ? [] : Array.from(
|
|
31
|
+
new URLSearchParams(window.location.search).getAll("categories")
|
|
32
|
+
)), [S] = r(() => typeof window > "u" ? null : new URLSearchParams(window.location.search).get("type")), [P, c] = r(0), [d, $] = r(!1), [p, h] = r(!1), [j, l] = r(!0), [m, y] = r(""), [N, D] = r(""), { locale: O } = Q(), Z = K(U), q = {
|
|
31
33
|
//grid: styles.grid,
|
|
32
34
|
list: s.list
|
|
33
|
-
}[
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
x(e.target.value), i([]), c(0), n(!0);
|
|
43
|
-
}, M = () => {
|
|
44
|
-
w(!v);
|
|
45
|
-
}, J = () => {
|
|
46
|
-
i([]), c(0), n(!0), S([]), N(""), w(!1);
|
|
47
|
-
}, P = async () => {
|
|
48
|
-
if (d || !z) return;
|
|
49
|
-
j(!0);
|
|
35
|
+
}[I ?? "grid"], G = (e) => {
|
|
36
|
+
x(e.target.value), i([]), c(0), l(!0);
|
|
37
|
+
}, z = () => {
|
|
38
|
+
h(!p);
|
|
39
|
+
}, X = () => {
|
|
40
|
+
i([]), c(0), l(!0), E([]), y(""), h(!1);
|
|
41
|
+
}, M = async () => {
|
|
42
|
+
if (d || !j) return;
|
|
43
|
+
$(!0);
|
|
50
44
|
const e = new URLSearchParams({
|
|
51
|
-
start: String(
|
|
52
|
-
limit: String(
|
|
45
|
+
start: String(P),
|
|
46
|
+
limit: String(A),
|
|
53
47
|
sort: R,
|
|
54
|
-
documentType:
|
|
55
|
-
locale:
|
|
48
|
+
documentType: k,
|
|
49
|
+
locale: O
|
|
56
50
|
});
|
|
57
|
-
|
|
58
|
-
(
|
|
51
|
+
S && e.append("type", S), N && e.append("search", N), u.forEach(
|
|
52
|
+
(n) => e.append("categories", n)
|
|
59
53
|
), b == null || b.forEach(
|
|
60
|
-
(
|
|
54
|
+
(n) => e.append("include", n._id)
|
|
61
55
|
), C == null || C.forEach(
|
|
62
|
-
(
|
|
56
|
+
(n) => e.append("exclude", n._id)
|
|
63
57
|
);
|
|
64
58
|
try {
|
|
65
|
-
const
|
|
59
|
+
const w = await (await fetch(`/api/articles?${e.toString()}`, {
|
|
66
60
|
method: "GET"
|
|
67
61
|
})).json();
|
|
68
|
-
i((L) => [...L, ...
|
|
69
|
-
} catch (
|
|
70
|
-
console.error("Failed to load articles:",
|
|
62
|
+
i((L) => [...L, ...w.articles]), c((L) => L + A), _(w.totalCount), P + w.articles.length >= w.totalCount && l(!1);
|
|
63
|
+
} catch (n) {
|
|
64
|
+
console.error("Failed to load articles:", n), l(!1);
|
|
71
65
|
} finally {
|
|
72
|
-
|
|
66
|
+
$(!1);
|
|
73
67
|
}
|
|
74
|
-
},
|
|
75
|
-
typeof window < "u" && window.innerWidth > 768 && (
|
|
68
|
+
}, B = J(() => {
|
|
69
|
+
typeof window < "u" && window.innerWidth > 768 && (h(!1), typeof document < "u" && (document.body.style.overflow = ""));
|
|
76
70
|
}, []);
|
|
77
|
-
return
|
|
71
|
+
return v(() => {
|
|
78
72
|
const e = typeof window < "u";
|
|
79
|
-
return e && window.addEventListener("resize",
|
|
80
|
-
e && window.removeEventListener("resize",
|
|
73
|
+
return e && window.addEventListener("resize", B), () => {
|
|
74
|
+
e && window.removeEventListener("resize", B);
|
|
81
75
|
};
|
|
82
|
-
}, []),
|
|
76
|
+
}, []), v(() => {
|
|
83
77
|
if (typeof document < "u")
|
|
84
|
-
return document.body.style.overflow =
|
|
78
|
+
return document.body.style.overflow = p ? "hidden" : "", () => {
|
|
85
79
|
document.body.style.overflow = "";
|
|
86
80
|
};
|
|
87
|
-
}, [
|
|
81
|
+
}, [p]), v(() => {
|
|
88
82
|
const e = setTimeout(() => {
|
|
89
|
-
|
|
83
|
+
D(m);
|
|
90
84
|
}, 1e3);
|
|
91
85
|
return () => clearTimeout(e);
|
|
92
|
-
}, [
|
|
93
|
-
|
|
94
|
-
}, [
|
|
95
|
-
/* @__PURE__ */
|
|
96
|
-
(o == null ? void 0 : o.title) && /* @__PURE__ */ t(
|
|
97
|
-
(o == null ? void 0 : o.description) && /* @__PURE__ */ t(
|
|
86
|
+
}, [m]), v(() => {
|
|
87
|
+
i([]), c(0), l(!0), M();
|
|
88
|
+
}, [N, R, u.join(","), S]), /* @__PURE__ */ t("section", { className: `${s.documentList} ${Z}`, children: /* @__PURE__ */ a("article", { className: s.container, children: [
|
|
89
|
+
/* @__PURE__ */ a("div", { className: s.heading, children: [
|
|
90
|
+
(o == null ? void 0 : o.title) && /* @__PURE__ */ t(H, { blocks: o == null ? void 0 : o.title }),
|
|
91
|
+
(o == null ? void 0 : o.description) && /* @__PURE__ */ t(H, { blocks: o == null ? void 0 : o.description })
|
|
98
92
|
] }),
|
|
99
|
-
/* @__PURE__ */
|
|
100
|
-
(f == null ? void 0 : f.length) && /* @__PURE__ */
|
|
93
|
+
/* @__PURE__ */ a("div", { className: s.listContainer, children: [
|
|
94
|
+
(f == null ? void 0 : f.length) && /* @__PURE__ */ a("div", { className: s.filterToggle, children: [
|
|
101
95
|
/* @__PURE__ */ t(
|
|
102
|
-
|
|
96
|
+
g,
|
|
103
97
|
{
|
|
104
98
|
as: "button",
|
|
105
99
|
variant: "secondary",
|
|
106
|
-
onClick:
|
|
100
|
+
onClick: z,
|
|
107
101
|
disabled: d,
|
|
108
102
|
icon: "settings",
|
|
109
103
|
iconAlignment: "left",
|
|
@@ -111,81 +105,81 @@ function he({
|
|
|
111
105
|
}
|
|
112
106
|
),
|
|
113
107
|
/* @__PURE__ */ t(
|
|
114
|
-
|
|
108
|
+
g,
|
|
115
109
|
{
|
|
116
110
|
as: "button",
|
|
117
111
|
variant: "link",
|
|
118
|
-
onClick:
|
|
119
|
-
disabled: d ||
|
|
112
|
+
onClick: X,
|
|
113
|
+
disabled: d || u.length === 0 && m.length === 0,
|
|
120
114
|
children: "Reset"
|
|
121
115
|
}
|
|
122
116
|
)
|
|
123
117
|
] }),
|
|
124
118
|
f && /* @__PURE__ */ t(
|
|
125
|
-
|
|
119
|
+
ee,
|
|
126
120
|
{
|
|
127
121
|
categoryFilters: f,
|
|
128
|
-
selectedCategories:
|
|
129
|
-
setSelectedCategories:
|
|
122
|
+
selectedCategories: u,
|
|
123
|
+
setSelectedCategories: E,
|
|
130
124
|
setArticles: i,
|
|
131
125
|
setStart: c,
|
|
132
|
-
setHasMore:
|
|
133
|
-
showFilters:
|
|
134
|
-
toggleFilters:
|
|
126
|
+
setHasMore: l,
|
|
127
|
+
showFilters: p,
|
|
128
|
+
toggleFilters: z,
|
|
135
129
|
isLoading: d
|
|
136
130
|
}
|
|
137
131
|
),
|
|
138
|
-
/* @__PURE__ */
|
|
139
|
-
/* @__PURE__ */
|
|
140
|
-
/* @__PURE__ */
|
|
132
|
+
/* @__PURE__ */ a("div", { className: s.listWrapper, children: [
|
|
133
|
+
/* @__PURE__ */ a("div", { className: s.listHeader, children: [
|
|
134
|
+
/* @__PURE__ */ a("div", { className: s.listResults, children: [
|
|
141
135
|
"Results: ",
|
|
142
136
|
/* @__PURE__ */ t("span", { children: W })
|
|
143
137
|
] }),
|
|
144
|
-
/* @__PURE__ */
|
|
145
|
-
/* @__PURE__ */
|
|
138
|
+
/* @__PURE__ */ a("div", { className: s.listHeaderFilters, children: [
|
|
139
|
+
/* @__PURE__ */ a("div", { className: s.listSearch, children: [
|
|
146
140
|
/* @__PURE__ */ t(
|
|
147
|
-
|
|
141
|
+
V,
|
|
148
142
|
{
|
|
149
143
|
type: "text",
|
|
150
144
|
name: "list-search",
|
|
151
145
|
placeholder: "Search articles",
|
|
152
|
-
value:
|
|
146
|
+
value: m,
|
|
153
147
|
onChange: (e) => {
|
|
154
|
-
|
|
148
|
+
y(e.target.value), i([]), c(0), l(!0);
|
|
155
149
|
}
|
|
156
150
|
}
|
|
157
151
|
),
|
|
158
|
-
|
|
152
|
+
m && /* @__PURE__ */ t(
|
|
159
153
|
"button",
|
|
160
154
|
{
|
|
161
155
|
className: s.clearSearch,
|
|
162
156
|
onClick: () => {
|
|
163
|
-
|
|
157
|
+
y(""), i([]), c(0), l(!0);
|
|
164
158
|
},
|
|
165
|
-
children: /* @__PURE__ */ t(
|
|
159
|
+
children: /* @__PURE__ */ t(te, { size: 21 })
|
|
166
160
|
}
|
|
167
161
|
)
|
|
168
162
|
] }),
|
|
169
163
|
/* @__PURE__ */ t("div", { className: s.listSort, children: /* @__PURE__ */ t(
|
|
170
|
-
|
|
164
|
+
Y,
|
|
171
165
|
{
|
|
172
166
|
id: "list-sort",
|
|
173
167
|
name: "list-sort",
|
|
174
|
-
options:
|
|
175
|
-
onChange:
|
|
168
|
+
options: se,
|
|
169
|
+
onChange: G
|
|
176
170
|
}
|
|
177
171
|
) })
|
|
178
172
|
] })
|
|
179
173
|
] }),
|
|
180
|
-
/* @__PURE__ */ t("div", { className: `${s.list} ${
|
|
181
|
-
(e) =>
|
|
174
|
+
/* @__PURE__ */ t("div", { className: `${s.list} ${q}`, children: T && T.map(
|
|
175
|
+
(e) => k == "blog" && /* @__PURE__ */ t(F, { article: e }, e._id)
|
|
182
176
|
) }),
|
|
183
|
-
|
|
184
|
-
|
|
177
|
+
j && /* @__PURE__ */ t("div", { className: s.loadMore, children: /* @__PURE__ */ t(
|
|
178
|
+
g,
|
|
185
179
|
{
|
|
186
180
|
as: "button",
|
|
187
181
|
variant: "primary",
|
|
188
|
-
onClick:
|
|
182
|
+
onClick: M,
|
|
189
183
|
disabled: d,
|
|
190
184
|
icon: "refresh",
|
|
191
185
|
iconAlignment: "left",
|
|
@@ -198,5 +192,5 @@ function he({
|
|
|
198
192
|
] }) });
|
|
199
193
|
}
|
|
200
194
|
export {
|
|
201
|
-
|
|
195
|
+
pe as DocumentListBlock
|
|
202
196
|
};
|