@k34a/blog 0.0.3 → 0.0.4

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.
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod';
2
+ import { articleQuerySchema } from '../services/search-params';
3
+ type FilterProps = z.infer<typeof articleQuerySchema>;
4
+ interface Props extends FilterProps {
5
+ availableTags: string[];
6
+ navigate: (query: string) => void;
7
+ }
8
+ export default function FilterSearchSortArticles(props: Props): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,200 @@
1
+ "use client";
2
+ import { jsx as t, jsxs as w } from "react/jsx-runtime";
3
+ import { Group as A, TextInput as z, Popover as h, Indicator as T, ActionIcon as F, Stack as k, MultiSelect as I, Button as R } from "@mantine/core";
4
+ import { IconSearch as B, IconFilter as j, IconSelector as x, IconCheck as L } from "@tabler/icons-react";
5
+ import { useRef as y, useEffect as C, useMemo as O, useState as b, useCallback as _ } from "react";
6
+ import "../services/search-params.js";
7
+ function Z(r) {
8
+ const s = y(r);
9
+ return C(() => {
10
+ s.current = r;
11
+ }), O(() => ((...o) => s.current?.(...o)), []);
12
+ }
13
+ function D(r, s) {
14
+ const { delay: o, flushOnUnmount: i, leading: f } = { delay: s, flushOnUnmount: !1, leading: !1 }, n = Z(r), c = y(0), u = O(() => {
15
+ const l = Object.assign(
16
+ (...d) => {
17
+ window.clearTimeout(c.current);
18
+ const g = l._isFirstCall;
19
+ l._isFirstCall = !1;
20
+ function a() {
21
+ window.clearTimeout(c.current), c.current = 0, l._isFirstCall = !0;
22
+ }
23
+ if (f && g) {
24
+ n(...d);
25
+ const m = () => {
26
+ a();
27
+ }, e = () => {
28
+ c.current !== 0 && (a(), n(...d));
29
+ }, v = () => {
30
+ a();
31
+ };
32
+ l.flush = e, l.cancel = v, c.current = window.setTimeout(m, o);
33
+ return;
34
+ }
35
+ if (f && !g) {
36
+ const m = () => {
37
+ c.current !== 0 && (a(), n(...d));
38
+ }, e = () => {
39
+ a();
40
+ };
41
+ l.flush = m, l.cancel = e;
42
+ const v = () => {
43
+ a();
44
+ };
45
+ c.current = window.setTimeout(v, o);
46
+ return;
47
+ }
48
+ const p = () => {
49
+ c.current !== 0 && (a(), n(...d));
50
+ }, S = () => {
51
+ a();
52
+ };
53
+ l.flush = p, l.cancel = S, c.current = window.setTimeout(p, o);
54
+ },
55
+ {
56
+ flush: () => {
57
+ },
58
+ cancel: () => {
59
+ },
60
+ _isFirstCall: !0
61
+ }
62
+ );
63
+ return l;
64
+ }, [n, o, f]);
65
+ return C(
66
+ () => () => {
67
+ i ? u.flush() : u.cancel();
68
+ },
69
+ [u, i]
70
+ ), u;
71
+ }
72
+ const P = [
73
+ { value: "latest", label: "Latest" },
74
+ { value: "oldest", label: "Oldest" },
75
+ { value: "A-Z", label: "Title A-Z" },
76
+ { value: "Z-A", label: "Title Z-A" }
77
+ ];
78
+ function N(r) {
79
+ const [s, o] = b(r.search ?? ""), [i, f] = b(
80
+ r.sortBy ?? "latest"
81
+ ), [n, c] = b(
82
+ r.tags ?? []
83
+ ), [u, l] = b(!1), [d, g] = b(!1), a = D(() => {
84
+ const e = p();
85
+ r.navigate(e);
86
+ }, 300), p = _(() => {
87
+ const e = new URLSearchParams();
88
+ return s && e.set("search", s), n.length > 0 && e.set("tags", n.join(",")), i && e.set("sortBy", i), e.set("page", "0"), e.toString();
89
+ }, [s, n, i]);
90
+ C(() => {
91
+ a();
92
+ }, [n, s, i]);
93
+ const S = n.length > 0, m = i !== "latest";
94
+ return /* @__PURE__ */ t("form", { style: { paddingBottom: "20px" }, children: /* @__PURE__ */ w(A, { justify: "space-between", wrap: "nowrap", children: [
95
+ /* @__PURE__ */ t(
96
+ z,
97
+ {
98
+ placeholder: "Search articles...",
99
+ value: s,
100
+ onChange: (e) => o(e.currentTarget.value),
101
+ leftSection: /* @__PURE__ */ t(B, { size: 16 }),
102
+ rightSectionWidth: 40,
103
+ w: "100%",
104
+ size: "lg"
105
+ }
106
+ ),
107
+ /* @__PURE__ */ w(
108
+ h,
109
+ {
110
+ opened: u,
111
+ onChange: l,
112
+ position: "bottom-end",
113
+ width: 300,
114
+ trapFocus: !0,
115
+ children: [
116
+ /* @__PURE__ */ t(h.Target, { children: /* @__PURE__ */ t(
117
+ T,
118
+ {
119
+ color: "blue",
120
+ size: 8,
121
+ offset: 4,
122
+ disabled: !S,
123
+ inline: !0,
124
+ children: /* @__PURE__ */ t(
125
+ F,
126
+ {
127
+ variant: "light",
128
+ onClick: () => l((e) => !e),
129
+ size: "lg",
130
+ children: /* @__PURE__ */ t(j, { size: 18 })
131
+ }
132
+ )
133
+ }
134
+ ) }),
135
+ /* @__PURE__ */ t(h.Dropdown, { children: /* @__PURE__ */ t(k, { gap: "sm", children: /* @__PURE__ */ t(
136
+ I,
137
+ {
138
+ label: "Tags",
139
+ data: r.availableTags.map((e) => ({
140
+ value: e,
141
+ label: e
142
+ })),
143
+ value: n,
144
+ onChange: c,
145
+ searchable: !0,
146
+ placeholder: "Select tags"
147
+ }
148
+ ) }) })
149
+ ]
150
+ }
151
+ ),
152
+ /* @__PURE__ */ w(
153
+ h,
154
+ {
155
+ opened: d,
156
+ onChange: g,
157
+ position: "bottom-end",
158
+ width: 200,
159
+ trapFocus: !0,
160
+ children: [
161
+ /* @__PURE__ */ t(h.Target, { children: /* @__PURE__ */ t(
162
+ T,
163
+ {
164
+ color: "blue",
165
+ size: 8,
166
+ offset: 4,
167
+ disabled: !m,
168
+ inline: !0,
169
+ children: /* @__PURE__ */ t(
170
+ F,
171
+ {
172
+ size: "lg",
173
+ variant: "light",
174
+ onClick: () => g((e) => !e),
175
+ children: /* @__PURE__ */ t(x, { size: 18 })
176
+ }
177
+ )
178
+ }
179
+ ) }),
180
+ /* @__PURE__ */ t(h.Dropdown, { children: /* @__PURE__ */ t(k, { children: P.map((e) => /* @__PURE__ */ t(
181
+ R,
182
+ {
183
+ onClick: () => f(
184
+ e.value
185
+ ),
186
+ size: "sm",
187
+ variant: "subtle",
188
+ leftSection: i === e.value ? /* @__PURE__ */ t(L, {}) : void 0,
189
+ children: e.label
190
+ },
191
+ e.value
192
+ )) }) })
193
+ ]
194
+ }
195
+ )
196
+ ] }) });
197
+ }
198
+ export {
199
+ N as default
200
+ };
package/dist/main.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ArticleService, ArticleDetailsForListing } from './services/articles';
2
2
  import { articleQuerySchema } from './services/search-params';
3
- export { ArticleService, articleQuerySchema };
3
+ import { default as FilterSearchSortArticles } from './components/filter-search-sort';
4
+ export { ArticleService, articleQuerySchema, FilterSearchSortArticles };
4
5
  export type { ArticleDetailsForListing };
package/dist/main.js CHANGED
@@ -1,6 +1,8 @@
1
- import { ArticleService as c } from "./services/articles.js";
2
- import { articleQuerySchema as t } from "./services/search-params.js";
1
+ import { ArticleService as t } from "./services/articles.js";
2
+ import { articleQuerySchema as c } from "./services/search-params.js";
3
+ import { default as i } from "./components/filter-search-sort.js";
3
4
  export {
4
- c as ArticleService,
5
- t as articleQuerySchema
5
+ t as ArticleService,
6
+ i as FilterSearchSortArticles,
7
+ c as articleQuerySchema
6
8
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@k34a/blog",
3
3
  "description": "Create and share articles with your audience.",
4
4
  "private": false,
5
- "version": "0.0.3",
5
+ "version": "0.0.4",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {