@kapiuara/ui 0.6.0 → 0.7.0
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.
- package/README.md +69 -4
- package/dist/components/chat/KapiComposer.d.ts +2 -2
- package/dist/components/chat/KapiComposer.js +47 -45
- package/dist/components/data/KapiTable.d.ts +25 -1
- package/dist/components/data/KapiTable.js +408 -390
- package/dist/components/data/index.d.ts +1 -1
- package/dist/components/data/tableLogic.d.ts +7 -0
- package/dist/components/data/tableLogic.js +21 -16
- package/dist/components/inputs/KapiButton.d.ts +9 -2
- package/dist/components/inputs/KapiButton.js +25 -15
- package/dist/components/inputs/KapiFacetedSearch.d.ts +29 -5
- package/dist/components/inputs/KapiFacetedSearch.js +161 -119
- package/dist/components/inputs/KapiSegmented.d.ts +2 -1
- package/dist/components/inputs/KapiSegmented.js +45 -44
- package/dist/components/inputs/facetedSearchLogic.d.ts +40 -9
- package/dist/components/inputs/facetedSearchLogic.js +38 -20
- package/dist/components/inputs/index.d.ts +2 -2
- package/dist/components/layout/KapiRail.d.ts +1 -1
- package/dist/components/layout/KapiRail.js +57 -50
- package/dist/components/layout/KapiShell.d.ts +9 -2
- package/dist/components/layout/KapiShell.js +22 -22
- package/dist/components/navigation/KapiTabs.d.ts +3 -1
- package/dist/components/navigation/KapiTabs.js +47 -46
- package/dist/components/overlays/KapiCanvasForm.js +2 -6
- package/dist/components/overlays/KapiConfirm.js +1 -6
- package/dist/hooks/colorLogic.d.ts +26 -0
- package/dist/hooks/colorLogic.js +53 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/numberFormatLogic.d.ts +6 -0
- package/dist/hooks/numberFormatLogic.js +7 -0
- package/dist/hooks/rightClick.d.ts +10 -0
- package/dist/hooks/rightClick.js +10 -4
- package/dist/hooks/themeColorsLogic.d.ts +11 -0
- package/dist/hooks/themeColorsLogic.js +37 -0
- package/dist/hooks/themeContrastLogic.d.ts +23 -0
- package/dist/hooks/themeContrastLogic.js +46 -0
- package/dist/hooks/themeDeriveLogic.d.ts +52 -0
- package/dist/hooks/themeDeriveLogic.js +103 -0
- package/dist/hooks/useDragScroll.js +26 -23
- package/dist/hooks/useGlobalRightClick.js +28 -25
- package/dist/hooks/useKapiTheme.d.ts +28 -4
- package/dist/hooks/useKapiTheme.js +82 -50
- package/dist/index.js +129 -126
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/package.json +3 -3
|
@@ -3,250 +3,292 @@ import { useLabels as e } from "../locale/KapiLocaleProvider.js";
|
|
|
3
3
|
import { createLoadSequencer as t } from "./asyncSelectLogic.js";
|
|
4
4
|
import { joinClasses as n } from "../rootProps.js";
|
|
5
5
|
import { KapiDatePicker as r } from "./KapiDatePicker.js";
|
|
6
|
-
import { KapiDateRangePicker as
|
|
7
|
-
import { KapiTag as
|
|
8
|
-
import { KapiPopover as
|
|
9
|
-
import { facetKeyAction as
|
|
6
|
+
import { KapiDateRangePicker as ee } from "./KapiDateRangePicker.js";
|
|
7
|
+
import { KapiTag as i } from "../display/KapiTag.js";
|
|
8
|
+
import { KapiPopover as te } from "../overlays/KapiPopover.js";
|
|
9
|
+
import { facetChipText as ne, facetKeyAction as re, facetMenuItems as ie, facetOperators as a, facetOptionName as ae, isDateFacet as o, moveActive as oe, toDateRangeValue as se, toDateValue as ce } from "./facetedSearchLogic.js";
|
|
10
10
|
/* empty css */
|
|
11
|
-
import { Fragment as
|
|
12
|
-
import { useEffect as
|
|
13
|
-
import { Search as
|
|
11
|
+
import { Fragment as le, jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
12
|
+
import { useEffect as l, useId as ue, useRef as u, useState as d } from "react";
|
|
13
|
+
import { Search as de } from "lucide-react";
|
|
14
14
|
//#region src/components/inputs/KapiFacetedSearch.tsx
|
|
15
|
-
var
|
|
15
|
+
var f = {
|
|
16
16
|
input: "Buscar o filtrar",
|
|
17
17
|
region: "Búsqueda",
|
|
18
18
|
placeholder: "Buscar o filtrar…",
|
|
19
19
|
searchFor: "Buscar",
|
|
20
20
|
pickValue: "elegir valor…",
|
|
21
|
+
typeValue: "escribir texto…",
|
|
21
22
|
empty: "Sin opciones",
|
|
22
23
|
remove: "Quitar",
|
|
23
24
|
valueOf: "Valor de",
|
|
24
25
|
clearAll: "Limpiar todo",
|
|
25
26
|
loading: "Buscando…",
|
|
26
|
-
loadError: "No se pudieron cargar los valores"
|
|
27
|
+
loadError: "No se pudieron cargar los valores",
|
|
28
|
+
pickOperator: "Cómo comparar",
|
|
29
|
+
operatorEq: "es",
|
|
30
|
+
operatorNe: "no es",
|
|
31
|
+
operatorContains: "contiene",
|
|
32
|
+
operatorStartsWith: "empieza con",
|
|
33
|
+
operatorEndsWith: "termina con",
|
|
34
|
+
operatorGt: "mayor que",
|
|
35
|
+
operatorGte: "mayor o igual que",
|
|
36
|
+
operatorLt: "menor que",
|
|
37
|
+
operatorLte: "menor o igual que"
|
|
27
38
|
};
|
|
28
|
-
function
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
Object.is(
|
|
32
|
-
}, [
|
|
33
|
-
let
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
function p({ facets: p, chips: m, onText: fe, onClearAll: h, loadDelay: g = 300, reloadKey: _, labels: pe, className: me, onMouseDown: he, "aria-label": ge, ..._e }) {
|
|
40
|
+
let v = e("facetedSearch", f, pe), y = ue(), b = `${y}-list`, x = u(null), S = u(null), C = u(null), [w, T] = d(""), [E, D] = d(null), [O, k] = d(null), [ve, A] = d(!1), [j, M] = d(-1), [N, P] = d(null), [F] = d(t), I = u(_);
|
|
41
|
+
l(() => {
|
|
42
|
+
Object.is(I.current, _) || (I.current = _, F.cancel(), P(null));
|
|
43
|
+
}, [_, F]);
|
|
44
|
+
let L = w.trim(), R = !!E && a(E).length >= 2 && O === null, z = E?.kind === "text" && !R, B = typeof E?.loadOptions == "function" && E.kind !== "text" && !R, V = {
|
|
45
|
+
eq: v.operatorEq,
|
|
46
|
+
ne: v.operatorNe,
|
|
47
|
+
contains: v.operatorContains,
|
|
48
|
+
startsWith: v.operatorStartsWith,
|
|
49
|
+
endsWith: v.operatorEndsWith,
|
|
50
|
+
gt: v.operatorGt,
|
|
51
|
+
gte: v.operatorGte,
|
|
52
|
+
lt: v.operatorLt,
|
|
53
|
+
lte: v.operatorLte
|
|
54
|
+
}, H = (e) => ne(e, e.operator ? V[e.operator] : void 0), U = B && N?.key === E?.key && N?.query === L ? N : null, W = B && !U, G = ie(p, E, w, U && !U.error ? U.options : void 0, O), K = o(E) && !R, q = ve && !K && !(z && G.length === 0), J = u(E?.loadOptions);
|
|
55
|
+
l(() => {
|
|
56
|
+
J.current = E?.loadOptions;
|
|
57
|
+
}), l(() => {
|
|
58
|
+
if (!B || !q || U) return;
|
|
59
|
+
let e = E?.key ?? "", t = setTimeout(() => {
|
|
39
60
|
let t = J.current;
|
|
40
61
|
if (!t) return;
|
|
41
|
-
let n =
|
|
62
|
+
let n = F.start(), r;
|
|
42
63
|
try {
|
|
43
|
-
r = t(
|
|
64
|
+
r = t(L, { signal: n.signal });
|
|
44
65
|
} catch (e) {
|
|
45
66
|
r = Promise.reject(e);
|
|
46
67
|
}
|
|
47
68
|
r.then((t) => {
|
|
48
|
-
n.isCurrent() && (
|
|
69
|
+
n.isCurrent() && (P({
|
|
49
70
|
key: e,
|
|
50
|
-
query:
|
|
71
|
+
query: L,
|
|
51
72
|
options: t,
|
|
52
73
|
error: !1
|
|
53
|
-
}),
|
|
74
|
+
}), M(-1));
|
|
54
75
|
}, () => {
|
|
55
|
-
n.isCurrent() &&
|
|
76
|
+
n.isCurrent() && P({
|
|
56
77
|
key: e,
|
|
57
|
-
query:
|
|
78
|
+
query: L,
|
|
58
79
|
options: [],
|
|
59
80
|
error: !0
|
|
60
81
|
});
|
|
61
82
|
});
|
|
62
|
-
},
|
|
83
|
+
}, g);
|
|
63
84
|
return () => clearTimeout(t);
|
|
64
85
|
}, [
|
|
65
|
-
|
|
86
|
+
B,
|
|
66
87
|
q,
|
|
67
88
|
U,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
]),
|
|
89
|
+
L,
|
|
90
|
+
g,
|
|
91
|
+
E?.key,
|
|
92
|
+
F
|
|
93
|
+
]), l(() => ((!q || !E) && (F.cancel(), P((e) => e?.error ? null : e)), () => F.cancel()), [
|
|
73
94
|
q,
|
|
74
|
-
|
|
75
|
-
|
|
95
|
+
E,
|
|
96
|
+
F
|
|
76
97
|
]);
|
|
77
|
-
let Y = () => requestAnimationFrame(() =>
|
|
78
|
-
|
|
98
|
+
let Y = () => requestAnimationFrame(() => S.current?.focus()), X = () => {
|
|
99
|
+
T(""), D(null), k(null), M(-1);
|
|
79
100
|
}, Z = () => {
|
|
80
|
-
X(),
|
|
81
|
-
}, Q = (e) => {
|
|
82
|
-
e.
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
101
|
+
X(), A(!1), Y();
|
|
102
|
+
}, Q = (e, t) => {
|
|
103
|
+
e.kind === "flag" ? (e.apply("true", t), Z()) : (D(e), k(t), T(""), M(-1), A(!0), o(e) ? requestAnimationFrame(() => C.current?.focus()) : Y());
|
|
104
|
+
}, ye = () => {
|
|
105
|
+
O !== null && E && a(E).length >= 2 || D(null), k(null), M(-1), Y();
|
|
106
|
+
}, be = (e) => {
|
|
107
|
+
E?.kind === "text" ? E.apply(e, O ?? "eq") : fe(e), Z();
|
|
108
|
+
}, xe = (e) => {
|
|
109
|
+
if (e.type === "text") be(e.text);
|
|
110
|
+
else if (e.type === "option") E?.apply(e.option.value, O ?? "eq"), Z();
|
|
111
|
+
else if (e.type === "operator") Q(e.facet, e.operator);
|
|
112
|
+
else {
|
|
113
|
+
let t = a(e.facet);
|
|
114
|
+
t.length >= 2 ? (D(e.facet), k(null), T(""), M(-1), A(!0), Y()) : Q(e.facet, t[0] ?? "eq");
|
|
115
|
+
}
|
|
116
|
+
}, Se = (e) => {
|
|
117
|
+
let t = re(e.key, {
|
|
118
|
+
input: w,
|
|
119
|
+
pending: !!E,
|
|
120
|
+
pendingText: z,
|
|
121
|
+
active: j,
|
|
88
122
|
open: q,
|
|
89
|
-
chips:
|
|
123
|
+
chips: m.length
|
|
90
124
|
});
|
|
91
125
|
if (t) switch (e.preventDefault(), t) {
|
|
92
126
|
case "next":
|
|
93
127
|
case "prev":
|
|
94
|
-
|
|
128
|
+
A(!0), M((e) => oe(q ? e : -1, G.length, t === "next" ? 1 : -1));
|
|
95
129
|
break;
|
|
96
130
|
case "select": {
|
|
97
|
-
let e = G[
|
|
98
|
-
e &&
|
|
131
|
+
let e = G[j];
|
|
132
|
+
e && xe(e);
|
|
99
133
|
break;
|
|
100
134
|
}
|
|
101
135
|
case "text":
|
|
102
|
-
|
|
136
|
+
be(w.trim());
|
|
103
137
|
break;
|
|
104
138
|
case "cancel":
|
|
105
139
|
X();
|
|
106
140
|
break;
|
|
107
141
|
case "close":
|
|
108
|
-
|
|
142
|
+
A(!1), M(-1);
|
|
109
143
|
break;
|
|
110
144
|
case "dropPending":
|
|
111
|
-
|
|
145
|
+
ye();
|
|
112
146
|
break;
|
|
113
|
-
case "removeLast":
|
|
147
|
+
case "removeLast": m[m.length - 1]?.onRemove();
|
|
114
148
|
}
|
|
115
|
-
},
|
|
149
|
+
}, Ce = (e) => {
|
|
116
150
|
let t = e.target.value === "";
|
|
117
|
-
|
|
118
|
-
}, $ = (e) => `${
|
|
119
|
-
return /* @__PURE__ */
|
|
120
|
-
...
|
|
121
|
-
ref:
|
|
122
|
-
className: n("kapi-facets",
|
|
151
|
+
e.key === "Escape" ? (e.preventDefault(), X(), Y()) : e.key === "Backspace" && t && (e.preventDefault(), ye());
|
|
152
|
+
}, $ = (e) => `${y}-opt-${e}`;
|
|
153
|
+
return /* @__PURE__ */ c("div", {
|
|
154
|
+
..._e,
|
|
155
|
+
ref: x,
|
|
156
|
+
className: n("kapi-facets", me),
|
|
123
157
|
role: "search",
|
|
124
|
-
"aria-label":
|
|
158
|
+
"aria-label": ge ?? v.region,
|
|
125
159
|
onMouseDown: (e) => {
|
|
126
|
-
|
|
160
|
+
he?.(e), !e.defaultPrevented && e.target === e.currentTarget && (e.preventDefault(), S.current?.focus(), A(!0));
|
|
127
161
|
},
|
|
128
162
|
children: [
|
|
129
|
-
/* @__PURE__ */
|
|
163
|
+
/* @__PURE__ */ s(de, {
|
|
130
164
|
className: "kapi-facets__icon",
|
|
131
165
|
size: 15,
|
|
132
166
|
"aria-hidden": !0
|
|
133
167
|
}),
|
|
134
|
-
|
|
168
|
+
m.map((e) => /* @__PURE__ */ s(i, {
|
|
135
169
|
size: "sm",
|
|
136
170
|
onRemove: () => {
|
|
137
171
|
e.onRemove(), Y();
|
|
138
172
|
},
|
|
139
|
-
removeLabel: `${
|
|
140
|
-
children: e
|
|
173
|
+
removeLabel: `${v.remove} ${H(e)}`,
|
|
174
|
+
children: H(e)
|
|
141
175
|
}, e.key)),
|
|
142
|
-
|
|
176
|
+
E && /* @__PURE__ */ c(i, {
|
|
143
177
|
size: "sm",
|
|
144
178
|
tone: "primary",
|
|
145
179
|
className: "kapi-facets__pending",
|
|
146
|
-
children: [
|
|
180
|
+
children: [
|
|
181
|
+
E.label,
|
|
182
|
+
O && O !== "eq" ? ` ${V[O]}` : "",
|
|
183
|
+
":"
|
|
184
|
+
]
|
|
147
185
|
}),
|
|
148
|
-
K &&
|
|
186
|
+
K && E ? /* @__PURE__ */ s("span", {
|
|
149
187
|
className: "kapi-facets__date",
|
|
150
|
-
onKeyDown:
|
|
151
|
-
children:
|
|
152
|
-
ref:
|
|
153
|
-
"aria-label": `${
|
|
188
|
+
onKeyDown: Ce,
|
|
189
|
+
children: E.kind === "dateRange" ? /* @__PURE__ */ s(ee, {
|
|
190
|
+
ref: C,
|
|
191
|
+
"aria-label": `${v.valueOf} ${E.label}`,
|
|
154
192
|
onChange: ({ from: e, to: t }) => {
|
|
155
|
-
e && t && (
|
|
193
|
+
e && t && (E.apply(se(e, t), O ?? "eq"), Z());
|
|
156
194
|
}
|
|
157
|
-
}) : /* @__PURE__ */
|
|
158
|
-
ref:
|
|
159
|
-
"aria-label": `${
|
|
195
|
+
}) : /* @__PURE__ */ s(r, {
|
|
196
|
+
ref: C,
|
|
197
|
+
"aria-label": `${v.valueOf} ${E.label}`,
|
|
160
198
|
onChange: (e) => {
|
|
161
|
-
e && (
|
|
199
|
+
e && (E.apply(ce(e), O ?? "eq"), Z());
|
|
162
200
|
}
|
|
163
201
|
})
|
|
164
|
-
}) : /* @__PURE__ */
|
|
165
|
-
ref:
|
|
202
|
+
}) : /* @__PURE__ */ s("input", {
|
|
203
|
+
ref: S,
|
|
166
204
|
className: "kapi-facets__input",
|
|
167
205
|
type: "text",
|
|
168
206
|
role: "combobox",
|
|
169
207
|
autoComplete: "off",
|
|
170
|
-
"aria-label":
|
|
208
|
+
"aria-label": v.input,
|
|
171
209
|
"aria-expanded": q,
|
|
172
|
-
"aria-controls":
|
|
210
|
+
"aria-controls": b,
|
|
173
211
|
"aria-autocomplete": "list",
|
|
174
|
-
"aria-activedescendant": q &&
|
|
175
|
-
placeholder:
|
|
176
|
-
value:
|
|
177
|
-
onFocus: () =>
|
|
178
|
-
onClick: () =>
|
|
212
|
+
"aria-activedescendant": q && j >= 0 ? $(j) : void 0,
|
|
213
|
+
placeholder: z ? v.typeValue : m.length === 0 && !E ? v.placeholder : void 0,
|
|
214
|
+
value: w,
|
|
215
|
+
onFocus: () => A(!0),
|
|
216
|
+
onClick: () => A(!0),
|
|
179
217
|
onBlur: (e) => {
|
|
180
218
|
let t = e.relatedTarget;
|
|
181
|
-
(!t || !
|
|
219
|
+
(!t || !x.current?.contains(t)) && A(!1);
|
|
182
220
|
},
|
|
183
221
|
onChange: (e) => {
|
|
184
|
-
|
|
222
|
+
T(e.target.value), A(!0), M(-1);
|
|
185
223
|
},
|
|
186
|
-
onKeyDown:
|
|
224
|
+
onKeyDown: Se
|
|
187
225
|
}),
|
|
188
|
-
|
|
226
|
+
h && m.length > 0 && /* @__PURE__ */ s("button", {
|
|
189
227
|
type: "button",
|
|
190
228
|
className: "kapi-facets__clear",
|
|
191
229
|
onClick: () => {
|
|
192
|
-
|
|
230
|
+
h(), X(), Y();
|
|
193
231
|
},
|
|
194
|
-
children:
|
|
232
|
+
children: v.clearAll
|
|
195
233
|
}),
|
|
196
|
-
/* @__PURE__ */
|
|
234
|
+
/* @__PURE__ */ c(te, {
|
|
197
235
|
open: q,
|
|
198
|
-
anchorRef:
|
|
199
|
-
onClose: () =>
|
|
236
|
+
anchorRef: x,
|
|
237
|
+
onClose: () => A(!1),
|
|
200
238
|
matchAnchorWidth: !0,
|
|
201
239
|
role: "listbox",
|
|
202
|
-
id:
|
|
203
|
-
"aria-label":
|
|
240
|
+
id: b,
|
|
241
|
+
"aria-label": E ? R ? `${E.label}: ${v.pickOperator}` : E.label : v.input,
|
|
204
242
|
closeOnEscape: !1,
|
|
205
243
|
restoreFocus: !1,
|
|
206
244
|
className: "kapi-facets__menu",
|
|
207
245
|
children: [
|
|
208
|
-
W && /* @__PURE__ */
|
|
246
|
+
W && /* @__PURE__ */ s("div", {
|
|
209
247
|
className: "kapi-facets__empty",
|
|
210
|
-
children:
|
|
248
|
+
children: v.loading
|
|
211
249
|
}),
|
|
212
|
-
!W && U?.error && /* @__PURE__ */
|
|
250
|
+
!W && U?.error && /* @__PURE__ */ s("div", {
|
|
213
251
|
className: "kapi-facets__empty kapi-facets__empty--err",
|
|
214
|
-
children:
|
|
252
|
+
children: v.loadError
|
|
215
253
|
}),
|
|
216
|
-
!W && !U?.error && G.length === 0 && /* @__PURE__ */
|
|
254
|
+
!W && !U?.error && G.length === 0 && /* @__PURE__ */ s("div", {
|
|
217
255
|
className: "kapi-facets__empty",
|
|
218
|
-
children:
|
|
256
|
+
children: v.empty
|
|
219
257
|
}),
|
|
220
|
-
!W && !U?.error && G.map((e, t) => /* @__PURE__ */
|
|
258
|
+
!W && !U?.error && G.map((e, t) => /* @__PURE__ */ s("div", {
|
|
221
259
|
id: $(t),
|
|
222
260
|
role: "option",
|
|
223
|
-
"aria-selected": t ===
|
|
224
|
-
"aria-label": e.type === "option" ?
|
|
225
|
-
className: `kapi-facets__opt${t ===
|
|
261
|
+
"aria-selected": t === j,
|
|
262
|
+
"aria-label": e.type === "option" ? ae(e.option) : void 0,
|
|
263
|
+
className: `kapi-facets__opt${t === j ? " kapi-facets__opt--active" : ""}`,
|
|
226
264
|
onMouseDown: (e) => e.preventDefault(),
|
|
227
|
-
onMouseEnter: () =>
|
|
228
|
-
onClick: () =>
|
|
229
|
-
children: e.type === "text" ? /* @__PURE__ */
|
|
230
|
-
|
|
265
|
+
onMouseEnter: () => M(t),
|
|
266
|
+
onClick: () => xe(e),
|
|
267
|
+
children: e.type === "text" ? /* @__PURE__ */ c("span", { children: [
|
|
268
|
+
v.searchFor,
|
|
231
269
|
" “",
|
|
232
270
|
e.text,
|
|
233
271
|
"”"
|
|
234
|
-
] }) : e.type === "option" ? /* @__PURE__ */
|
|
272
|
+
] }) : e.type === "operator" ? /* @__PURE__ */ s("span", { children: V[e.operator] }) : e.type === "option" ? /* @__PURE__ */ c(le, { children: [/* @__PURE__ */ s("span", { children: e.option.label }), e.option.count !== void 0 && /* @__PURE__ */ s("span", {
|
|
235
273
|
className: "kapi-facets__count",
|
|
236
274
|
"aria-hidden": "true",
|
|
237
275
|
children: e.option.count
|
|
238
|
-
})] }) : /* @__PURE__ */
|
|
276
|
+
})] }) : /* @__PURE__ */ c("span", { children: [/* @__PURE__ */ s("span", {
|
|
239
277
|
className: "kapi-facets__facet",
|
|
240
278
|
children: e.facet.label
|
|
241
|
-
}), e.facet.kind !== "flag" && /* @__PURE__ */
|
|
279
|
+
}), e.facet.kind !== "flag" && /* @__PURE__ */ c("span", {
|
|
242
280
|
className: "kapi-facets__hint",
|
|
243
|
-
children: [
|
|
281
|
+
children: [
|
|
282
|
+
" ",
|
|
283
|
+
"· ",
|
|
284
|
+
e.facet.kind === "text" ? v.typeValue : v.pickValue
|
|
285
|
+
]
|
|
244
286
|
})] })
|
|
245
|
-
}, e.type === "facet" ? `f-${e.facet.key}` : e.type === "option" ? `o-${e.option.value}` : "t"))
|
|
287
|
+
}, e.type === "facet" ? `f-${e.facet.key}` : e.type === "option" ? `o-${e.option.value}` : e.type === "operator" ? `op-${e.operator}` : "t"))
|
|
246
288
|
]
|
|
247
289
|
})
|
|
248
290
|
]
|
|
249
291
|
});
|
|
250
292
|
}
|
|
251
293
|
//#endregion
|
|
252
|
-
export {
|
|
294
|
+
export { f as DEFAULT_FACETED_SEARCH_LABELS, p as KapiFacetedSearch };
|
|
@@ -6,7 +6,8 @@ export type KapiSegmentedItem<Id extends string | number = string> = {
|
|
|
6
6
|
label: string;
|
|
7
7
|
/** Ícono (lucide-react). Se muestra en las variantes `icon` y `both`. */
|
|
8
8
|
icon?: ReactNode;
|
|
9
|
-
/** Contador en píldora a la derecha
|
|
9
|
+
/** Contador en píldora a la derecha, con separadores de miles del español, que agrupa desde
|
|
10
|
+
* cinco cifras (`14760` → «14.760»; `4760` queda «4760»). */
|
|
10
11
|
count?: number;
|
|
11
12
|
/** Color del ítem cuando está activo (en vez del primario). */
|
|
12
13
|
color?: KapiSegmentedColor;
|
|
@@ -3,81 +3,82 @@ import { assignRef as e, fieldControlProps as t } from "./fieldLogic.js";
|
|
|
3
3
|
import { useKapiField as n } from "./KapiField.js";
|
|
4
4
|
import { joinClasses as r } from "../rootProps.js";
|
|
5
5
|
import { useSlidingIndicator as i } from "../../hooks/useSlidingIndicator.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { formatCount as a } from "../../hooks/numberFormatLogic.js";
|
|
7
|
+
import { KapiTooltip as o } from "../overlays/KapiTooltip.js";
|
|
8
|
+
import { nextRadioIndex as s } from "./segmentedLogic.js";
|
|
9
|
+
import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
9
10
|
//#region src/components/inputs/KapiSegmented.tsx
|
|
10
|
-
var
|
|
11
|
-
let
|
|
12
|
-
id:
|
|
13
|
-
describedBy:
|
|
14
|
-
invalid:
|
|
15
|
-
required:
|
|
11
|
+
var d = ({ items: d, value: f, onChange: p, variant: m = "text", "aria-label": h, className: g, name: _, onBlur: v, invalid: y, required: b, id: x, "aria-describedby": S, ref: C, ...w }) => {
|
|
12
|
+
let T = t(n(), {
|
|
13
|
+
id: x,
|
|
14
|
+
describedBy: S,
|
|
15
|
+
invalid: y,
|
|
16
|
+
required: b,
|
|
16
17
|
labelable: !1,
|
|
17
|
-
ariaLabel:
|
|
18
|
-
}),
|
|
19
|
-
active:
|
|
20
|
-
deps: [
|
|
18
|
+
ariaLabel: h
|
|
19
|
+
}), E = d.find((e) => e.id === f), { containerRef: D, indicatorRef: O } = i({
|
|
20
|
+
active: f,
|
|
21
|
+
deps: [d, m],
|
|
21
22
|
findActive: (e) => e.querySelector("[role=\"radio\"][aria-checked=\"true\"]")
|
|
22
|
-
}),
|
|
23
|
-
let t =
|
|
24
|
-
t !== void 0 && n && (e.preventDefault(),
|
|
25
|
-
},
|
|
26
|
-
e.currentTarget.contains(e.relatedTarget) ||
|
|
23
|
+
}), k = d.findIndex((e) => e.id === f), A = (e) => {
|
|
24
|
+
let t = s(d.length, k, e.key), n = t === void 0 ? void 0 : d[t];
|
|
25
|
+
t !== void 0 && n && (e.preventDefault(), p(n.id), D.current?.querySelectorAll("[role=\"radio\"]")[t]?.focus());
|
|
26
|
+
}, j = (e) => {
|
|
27
|
+
e.currentTarget.contains(e.relatedTarget) || v?.(e);
|
|
27
28
|
};
|
|
28
|
-
return /* @__PURE__ */
|
|
29
|
-
...
|
|
30
|
-
...
|
|
29
|
+
return /* @__PURE__ */ u("div", {
|
|
30
|
+
...w,
|
|
31
|
+
...T,
|
|
31
32
|
ref: (t) => {
|
|
32
|
-
|
|
33
|
+
D.current = t, e(C, t);
|
|
33
34
|
},
|
|
34
|
-
className: r("kapi-seg",
|
|
35
|
+
className: r("kapi-seg", g),
|
|
35
36
|
role: "radiogroup",
|
|
36
|
-
"aria-label":
|
|
37
|
-
onKeyDown:
|
|
38
|
-
onBlur:
|
|
37
|
+
"aria-label": h,
|
|
38
|
+
onKeyDown: A,
|
|
39
|
+
onBlur: j,
|
|
39
40
|
children: [
|
|
40
|
-
/* @__PURE__ */
|
|
41
|
-
ref:
|
|
41
|
+
/* @__PURE__ */ l("span", {
|
|
42
|
+
ref: O,
|
|
42
43
|
className: "kapi-seg__indicator",
|
|
43
|
-
"data-color":
|
|
44
|
+
"data-color": E?.color,
|
|
44
45
|
"aria-hidden": "true"
|
|
45
46
|
}),
|
|
46
|
-
|
|
47
|
-
let n =
|
|
47
|
+
d.map((e, t) => {
|
|
48
|
+
let n = f === e.id, r = /* @__PURE__ */ u("button", {
|
|
48
49
|
type: "button",
|
|
49
50
|
role: "radio",
|
|
50
51
|
"aria-checked": n,
|
|
51
|
-
tabIndex: n ||
|
|
52
|
-
"aria-label":
|
|
52
|
+
tabIndex: n || k === -1 && t === 0 ? 0 : -1,
|
|
53
|
+
"aria-label": m === "icon" ? e.label : void 0,
|
|
53
54
|
className: `kapi-seg__btn${n ? " is-on" : ""}`,
|
|
54
55
|
"data-color": n && e.color ? e.color : void 0,
|
|
55
|
-
onClick: () =>
|
|
56
|
+
onClick: () => p(e.id),
|
|
56
57
|
children: [
|
|
57
|
-
(
|
|
58
|
+
(m === "icon" || m === "both") && e.icon && /* @__PURE__ */ l("span", {
|
|
58
59
|
className: "kapi-seg__ico",
|
|
59
60
|
children: e.icon
|
|
60
61
|
}),
|
|
61
|
-
|
|
62
|
-
e.count != null && /* @__PURE__ */
|
|
62
|
+
m !== "icon" && /* @__PURE__ */ l("span", { children: e.label }),
|
|
63
|
+
e.count != null && /* @__PURE__ */ u(c, { children: [" ", /* @__PURE__ */ l("span", {
|
|
63
64
|
className: "kapi-seg__n",
|
|
64
|
-
children: e.count
|
|
65
|
-
})
|
|
65
|
+
children: a(e.count)
|
|
66
|
+
})] })
|
|
66
67
|
]
|
|
67
68
|
}, e.id);
|
|
68
|
-
return
|
|
69
|
+
return m === "icon" && e.label ? /* @__PURE__ */ l(o, {
|
|
69
70
|
label: e.label,
|
|
70
71
|
prefer: "top",
|
|
71
72
|
children: r
|
|
72
73
|
}, e.id) : r;
|
|
73
74
|
}),
|
|
74
|
-
|
|
75
|
+
_ && /* @__PURE__ */ l("input", {
|
|
75
76
|
type: "hidden",
|
|
76
|
-
name:
|
|
77
|
-
value: String(
|
|
77
|
+
name: _,
|
|
78
|
+
value: String(f)
|
|
78
79
|
})
|
|
79
80
|
]
|
|
80
81
|
});
|
|
81
82
|
};
|
|
82
83
|
//#endregion
|
|
83
|
-
export {
|
|
84
|
+
export { d as KapiSegmented };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `list` abre sus opciones; `date` pide una fecha; `dateRange`
|
|
3
|
-
* calendario; `flag` se aplica directo.
|
|
2
|
+
* `list` abre sus opciones; `text` recibe texto libre sobre ese campo; `date` pide una fecha; `dateRange`
|
|
3
|
+
* pide un rango (desde/hasta) en un solo calendario; `flag` se aplica directo.
|
|
4
4
|
*/
|
|
5
|
-
export type KapiFacetKind = "list" | "date" | "dateRange" | "flag";
|
|
5
|
+
export type KapiFacetKind = "list" | "text" | "date" | "dateRange" | "flag";
|
|
6
|
+
/** Comparación que se aplica al valor de una faceta. `eq` es la de siempre. */
|
|
7
|
+
export type KapiFacetOperator = "eq" | "ne" | "contains" | "startsWith" | "endsWith" | "gt" | "gte" | "lt" | "lte";
|
|
6
8
|
export type KapiFacetOption = {
|
|
7
9
|
value: string;
|
|
8
10
|
label: string;
|
|
@@ -24,17 +26,37 @@ export type KapiFacet = {
|
|
|
24
26
|
signal: AbortSignal;
|
|
25
27
|
}) => Promise<ReadonlyArray<KapiFacetOption>>) | undefined;
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
+
* Comparaciones que el usuario puede elegir antes del valor. Ausente o vacío equivale a `["eq"]`:
|
|
30
|
+
* no hay paso extra. Con una sola no se pregunta; con dos o más, el menú ofrece el paso.
|
|
29
31
|
*/
|
|
30
|
-
|
|
32
|
+
operators?: ReadonlyArray<KapiFacetOperator> | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Recibe el valor elegido (el `value` de la opción, el texto tipeado en una faceta `text`, la fecha como `yyyy-mm-dd`, el rango como
|
|
35
|
+
* `yyyy-mm-dd/yyyy-mm-dd` (ver `parseDateRangeValue`) o `"true"` (flag)) y la comparación elegida
|
|
36
|
+
* (`"eq"` si la faceta no declara `operators`).
|
|
37
|
+
*/
|
|
38
|
+
apply: (value: string, operator: KapiFacetOperator) => void;
|
|
31
39
|
};
|
|
40
|
+
/** Operadores de la faceta: los declarados si hay al menos uno, si no `["eq"]`. */
|
|
41
|
+
export declare const facetOperators: (facet: Pick<KapiFacet, "operators">) => ReadonlyArray<KapiFacetOperator>;
|
|
32
42
|
/** Filtro activo que la barra muestra como chip removible. */
|
|
33
43
|
export type KapiFacetChip = {
|
|
34
44
|
key: string;
|
|
35
45
|
label: string;
|
|
46
|
+
/** Valor elegido de la faceta: el chip dice `label: value`. Sin valor (o vacío) dice sólo `label`. */
|
|
47
|
+
value?: string | undefined;
|
|
48
|
+
/** Comparación del filtro: el chip la dice ("Fecha mayor que: …"). Sin ella, o con `eq`, no dice nada. */
|
|
49
|
+
operator?: KapiFacetOperator | undefined;
|
|
36
50
|
onRemove: () => void;
|
|
37
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Texto del chip: `label: value` cuando hay valor, `label` solo cuando no. Un valor vacío o de puros
|
|
54
|
+
* espacios cuenta como ausente, para no dibujar un "Carrera: " colgado. Con un operador que no es `eq`
|
|
55
|
+
* suma su texto: `label operatorText: value`. La función es pura: recibe el texto del operador ya
|
|
56
|
+
* resuelto (traducido), no lo traduce. Lo usan el texto visible y el nombre accesible del botón de
|
|
57
|
+
* quitar, así dos chips de la misma faceta no suenan idénticos.
|
|
58
|
+
*/
|
|
59
|
+
export declare const facetChipText: (chip: Pick<KapiFacetChip, "label" | "value" | "operator">, operatorText?: string | undefined) => string;
|
|
38
60
|
export type KapiFacetMenuItem = {
|
|
39
61
|
type: "text";
|
|
40
62
|
text: string;
|
|
@@ -44,15 +66,22 @@ export type KapiFacetMenuItem = {
|
|
|
44
66
|
} | {
|
|
45
67
|
type: "option";
|
|
46
68
|
option: KapiFacetOption;
|
|
69
|
+
} | {
|
|
70
|
+
type: "operator";
|
|
71
|
+
operator: KapiFacetOperator;
|
|
72
|
+
facet: KapiFacet;
|
|
47
73
|
};
|
|
48
74
|
/**
|
|
49
75
|
* Ítems del desplegable. Sin faceta pendiente: "buscar el texto" (si hay) y las facetas que coinciden.
|
|
50
|
-
* Con una faceta `list` pendiente: sus opciones que coinciden. Con una `
|
|
51
|
-
* el calendario).
|
|
76
|
+
* Con una faceta `list` pendiente: sus opciones que coinciden. Con una `text`: "buscar el texto" (si hay),
|
|
77
|
+
* que se aplica a esa faceta. Con una `date` o `dateRange`: nada (decide el calendario). Con una faceta pendiente de dos o más operadores y ninguno elegido (`operator` ausente o
|
|
78
|
+
* `null`): los operadores a elegir, antes que cualquier valor.
|
|
52
79
|
*/
|
|
53
80
|
export declare function facetMenuItems(facets: ReadonlyArray<KapiFacet>, pending: KapiFacet | null, input: string,
|
|
54
81
|
/** Opciones ya cargadas para la faceta pendiente. Si vienen, NO se filtran de nuevo: filtró el servidor. */
|
|
55
|
-
loaded?: ReadonlyArray<KapiFacetOption> | undefined
|
|
82
|
+
loaded?: ReadonlyArray<KapiFacetOption> | undefined,
|
|
83
|
+
/** Operador ya elegido para la faceta pendiente; sin él, y con 2 o más, el menú pide elegirlo. */
|
|
84
|
+
operator?: KapiFacetOperator | null | undefined): KapiFacetMenuItem[];
|
|
56
85
|
/** Mueve el ítem activo con vuelta; desde `-1` entra por el extremo según la dirección. */
|
|
57
86
|
export declare const moveActive: (index: number, count: number, delta: 1 | -1) => number;
|
|
58
87
|
export type KapiFacetKeyAction = "next" | "prev" | "select" | "text" | "cancel" | "close" | "dropPending" | "removeLast";
|
|
@@ -60,6 +89,8 @@ export type KapiFacetKeyAction = "next" | "prev" | "select" | "text" | "cancel"
|
|
|
60
89
|
export declare function facetKeyAction(key: string, s: {
|
|
61
90
|
input: string;
|
|
62
91
|
pending: boolean;
|
|
92
|
+
/** La faceta pendiente es de texto y ya tiene su operador: Enter aplica el texto en vez de ignorarlo. */
|
|
93
|
+
pendingText?: boolean | undefined;
|
|
63
94
|
active: number;
|
|
64
95
|
open: boolean;
|
|
65
96
|
chips: number;
|