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"),B=require("../../ui/PortableTextRenderer/index.cjs"),J=require("../../hooks/useStyleClasses.cjs"),K=require("../../contexts/LocaleBridge.cjs"),_=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:$="grid",includeFilters:S,excludeFilters:v,limit:M=3,categoryFilters:u,documentType:w,styleOptions:P,initialArticles:g=[],initialTotalCount:z=0}){const[N,i]=l.useState(g),[D,I]=l.useState(z),[j,H]=l.useState("date-desc"),[f,L]=l.useState([]),[T,d]=l.useState(g.length),[a,k]=l.useState(!1),[x,y]=l.useState(!1),[q,c]=l.useState(!0),[h,b]=l.useState(""),[p,O]=l.useState(""),{locale:W}=K.useLocaleBridge(),Z=J.useStyleClasses(P),G={list:s.styles.list}[$??"grid"],U=t=>{H(t.target.value),i([]),d(0),c(!0)},A=()=>{y(!x)},X=()=>{i([]),d(0),c(!0),L([]),b(""),y(!1)},E=async(t=!1)=>{if(a||!q)return;k(!0);const m=new URLSearchParams({start:t?"0":String(T),limit:String(M),sort:j,documentType:w,locale:W});p&&m.append("search",p),f.forEach(n=>m.append("categories",n)),S==null||S.forEach(n=>m.append("include",n._id)),v==null||v.forEach(n=>m.append("exclude",n._id));try{const r=await(await fetch(`/api/articles?${m.toString()}`,{method:"GET"})).json();i(C=>t?r.articles:[...C,...r.articles]),d(C=>t?r.articles.length:C+r.articles.length),I(r.totalCount),c(T+r.articles.length<r.totalCount)}catch(n){console.error("Failed to load articles:",n),c(!1)}finally{k(!1)}},R=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",R),()=>{t&&window.removeEventListener("resize",R)}},[]),l.useEffect(()=>{if(typeof document<"u")return document.body.style.overflow=x?"hidden":"",()=>{document.body.style.overflow=""}},[x]),l.useEffect(()=>{const t=setTimeout(()=>{O(h)},500);return()=>clearTimeout(t)},[h]),l.useEffect(()=>{(p||j!=="date-desc"||f.length>0)&&E(!0)},[p,j,f.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(B.RichText,{blocks:o==null?void 0:o.title}),(o==null?void 0:o.description)&&e.jsx(B.RichText,{blocks:o==null?void 0:o.description})]}),e.jsxs("div",{className:s.styles.listContainer,children:[(u==null?void 0:u.length)&&e.jsxs("div",{className:s.styles.filterToggle,children:[e.jsx(_.CallToAction,{as:"button",variant:"secondary",onClick:A,disabled:a,icon:"settings",iconAlignment:"left",children:"Filters"}),e.jsx(_.CallToAction,{as:"button",variant:"link",onClick:X,disabled:a||f.length===0&&h.length===0,children:"Reset"})]}),u&&e.jsx(s.CategoryFilters,{categoryFilters:u,selectedCategories:f,setSelectedCategories:L,setArticles:i,setStart:d,setHasMore:c,showFilters:x,toggleFilters:A,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:h,onChange:t=>{b(t.target.value),i([]),d(0),c(!0)}}),h&&e.jsx("button",{className:s.styles.clearSearch,onClick:()=>{b(""),i([]),d(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:N&&N.map(t=>w=="blog"&&e.jsx(Y.BlogArticleCard,{article:t},t._id))}),q&&e.jsx("div",{className:s.styles.loadMore,children:e.jsx(_.CallToAction,{as:"button",variant:"primary",onClick:()=>E(),disabled:a,icon:"refresh",iconAlignment:"left",className:a?s.styles.buttonIsLoading:"",children:a?"Loading...":"Load more"})})]})]})]})})}exports.DocumentListBlock=se;
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 a } from "react/jsx-runtime";
2
- import { useState as l, useCallback as Q, useEffect as w } from "react";
3
- import { RichText as I } from "../../ui/PortableTextRenderer/index.mjs";
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 k } from "../../../index-C-E0ib2G.js";
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 le = [
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: P = "grid",
21
+ layout: _ = "grid",
22
22
  includeFilters: S,
23
23
  excludeFilters: N,
24
- limit: W = 3,
25
- categoryFilters: f,
26
- documentType: T,
24
+ limit: y = 3,
25
+ categoryFilters: m,
26
+ documentType: A,
27
27
  // filterMode,
28
- styleOptions: _,
29
- initialArticles: A = [],
30
- initialTotalCount: x = 0
28
+ styleOptions: x,
29
+ initialArticles: g = [],
30
+ initialTotalCount: R = 0
31
31
  }) {
32
- const [E, d] = l(A), [D, O] = l(
33
- x
34
- ), [y, Z] = l("date-desc"), [u, R] = l([]), [$, m] = l(A.length), [n, j] = l(!1), [v, b] = l(!1), [z, i] = l(!0), [h, g] = l(""), [C, q] = l(""), { locale: G } = Y(), U = V(_), X = {
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
- }[P ?? "grid"], J = (s) => {
38
- Z(s.target.value), d([]), m(0), i(!0);
39
- }, M = () => {
39
+ }[_ ?? "grid"], J = (s) => {
40
+ Z(s.target.value), i([]), d(0), c(!0);
41
+ }, H = () => {
40
42
  b(!v);
41
43
  }, K = () => {
42
- d([]), m(0), i(!0), R([]), g(""), b(!1);
43
- }, B = async (s = !1) => {
44
- if (n || !z) return;
45
- j(!0);
46
- const p = new URLSearchParams({
47
- start: s ? "0" : String($),
48
- limit: String(W),
49
- sort: y,
50
- documentType: T,
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 && p.append("search", C), u.forEach(
54
- (r) => p.append("categories", r)
55
+ C && h.append("search", C), f.forEach(
56
+ (r) => h.append("categories", r)
55
57
  ), S == null || S.forEach(
56
- (r) => p.append("include", r._id)
58
+ (r) => h.append("include", r._id)
57
59
  ), N == null || N.forEach(
58
- (r) => p.append("exclude", r._id)
60
+ (r) => h.append("exclude", r._id)
59
61
  );
60
62
  try {
61
- const c = await (await fetch(`/api/articles?${p.toString()}`, {
63
+ const p = await (await fetch(`/api/articles?${h.toString()}`, {
62
64
  method: "GET"
63
65
  })).json();
64
- d(
65
- (L) => s ? c.articles : [...L, ...c.articles]
66
- ), m(
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), i(!1);
70
+ console.error("Failed to load articles:", r), c(!1);
71
71
  } finally {
72
- j(!1);
72
+ M(!1);
73
73
  }
74
- }, H = Q(() => {
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", H), () => {
80
- s && window.removeEventListener("resize", H);
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(h);
89
+ q(u);
90
90
  }, 500);
91
91
  return () => clearTimeout(s);
92
- }, [h]), w(() => {
93
- (C || y !== "date-desc" || u.length > 0) && B(!0);
94
- }, [C, y, u.join(",")]), /* @__PURE__ */ e("section", { className: `${t.documentList} ${U}`, children: /* @__PURE__ */ a("article", { className: t.container, children: [
95
- /* @__PURE__ */ a("div", { className: t.heading, children: [
96
- (o == null ? void 0 : o.title) && /* @__PURE__ */ e(I, { blocks: o == null ? void 0 : o.title }),
97
- (o == null ? void 0 : o.description) && /* @__PURE__ */ e(I, { blocks: o == null ? void 0 : o.description })
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__ */ a("div", { className: t.listContainer, children: [
100
- (f == null ? void 0 : f.length) && /* @__PURE__ */ a("div", { className: t.filterToggle, children: [
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
- k,
102
+ T,
103
103
  {
104
104
  as: "button",
105
105
  variant: "secondary",
106
- onClick: M,
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
- k,
114
+ T,
115
115
  {
116
116
  as: "button",
117
117
  variant: "link",
118
118
  onClick: K,
119
- disabled: n || u.length === 0 && h.length === 0,
119
+ disabled: n || f.length === 0 && u.length === 0,
120
120
  children: "Reset"
121
121
  }
122
122
  )
123
123
  ] }),
124
- f && /* @__PURE__ */ e(
124
+ m && /* @__PURE__ */ e(
125
125
  se,
126
126
  {
127
- categoryFilters: f,
128
- selectedCategories: u,
129
- setSelectedCategories: R,
130
- setArticles: d,
131
- setStart: m,
132
- setHasMore: i,
127
+ categoryFilters: m,
128
+ selectedCategories: f,
129
+ setSelectedCategories: j,
130
+ setArticles: i,
131
+ setStart: d,
132
+ setHasMore: c,
133
133
  showFilters: v,
134
- toggleFilters: M,
134
+ toggleFilters: H,
135
135
  isLoading: n
136
136
  }
137
137
  ),
138
- /* @__PURE__ */ a("div", { className: t.listWrapper, children: [
139
- /* @__PURE__ */ a("div", { className: t.listHeader, children: [
140
- /* @__PURE__ */ a("div", { className: t.listResults, children: [
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__ */ a("div", { className: t.listHeaderFilters, children: [
145
- /* @__PURE__ */ a("div", { className: t.listSearch, children: [
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: h,
152
+ value: u,
153
153
  onChange: (s) => {
154
- g(s.target.value), d([]), m(0), i(!0);
154
+ k(s.target.value), i([]), d(0), c(!0);
155
155
  }
156
156
  }
157
157
  ),
158
- h && /* @__PURE__ */ e(
158
+ u && /* @__PURE__ */ e(
159
159
  "button",
160
160
  {
161
161
  className: t.clearSearch,
162
162
  onClick: () => {
163
- g(""), d([]), m(0), i(!0);
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: le,
174
+ options: ae,
175
175
  onChange: J
176
176
  }
177
177
  ) })
178
178
  ] })
179
179
  ] }),
180
- /* @__PURE__ */ e("div", { className: `${t.list} ${X}`, children: E && E.map(
181
- (s) => T == "blog" && /* @__PURE__ */ e(te, { article: s }, s._id)
180
+ /* @__PURE__ */ e("div", { className: `${t.list} ${X}`, children: $ && $.map(
181
+ (s) => A == "blog" && /* @__PURE__ */ e(te, { article: s }, s._id)
182
182
  ) }),
183
- z && /* @__PURE__ */ e("div", { className: t.loadMore, children: /* @__PURE__ */ e(
184
- k,
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: () => B(),
188
+ onClick: () => I(!1),
189
189
  disabled: n,
190
190
  icon: "refresh",
191
191
  iconAlignment: "left",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "quirk-ui",
3
3
  "private": false,
4
- "version": "0.0.493",
4
+ "version": "0.0.495",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {