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