docthub-core-components 3.2.8 → 3.2.9

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.
@@ -2,7 +2,7 @@
2
2
  import { jsx as a, jsxs as q, Fragment as Ie } from "react/jsx-runtime";
3
3
  import { c as fe } from "react-compiler-runtime";
4
4
  import { X as Re, ChevronDown as Ce, Check as er } from "lucide-react";
5
- import { useState as Z, useEffect as p, useDeferredValue as rr, useRef as O, useId as tr, useMemo as J, useCallback as P, memo as sr } from "react";
5
+ import { useState as Z, useEffect as K, useDeferredValue as rr, useRef as O, useId as tr, useMemo as J, useCallback as P, memo as sr } from "react";
6
6
  import { createPortal as cr } from "react-dom";
7
7
  import { Input as or } from "../../ui/input.js";
8
8
  import { useExclusiveDropdown as ir } from "../../../hooks/use-exclusive-dropdown.js";
@@ -68,8 +68,8 @@ const Te = (l) => {
68
68
  }, e[0] = S, e[1] = t, e[2] = y) : y = e[2];
69
69
  const f = y;
70
70
  let u;
71
- e[3] !== f ? (u = (H) => {
72
- (H.key === "Enter" || H.key === " ") && (H.preventDefault(), f());
71
+ e[3] !== f ? (u = (p) => {
72
+ (p.key === "Enter" || p.key === " ") && (p.preventDefault(), f());
73
73
  }, e[3] = f, e[4] = u) : u = e[4];
74
74
  const T = u, V = `
75
75
  px-3 py-2 cursor-pointer flex items-center justify-between
@@ -111,11 +111,11 @@ const Fe = (l) => {
111
111
  e[11] === Symbol.for("react.memo_cache_sentinel") ? (N = /* @__PURE__ */ a(Re, { className: "h-3 w-3" }), e[11] = N) : N = e[11];
112
112
  let b;
113
113
  e[12] !== x || e[13] !== V ? (b = /* @__PURE__ */ a("button", { type: "button", onClick: x, className: "ml-1 hover:bg-secondary-foreground/20 rounded-full p-0.5", "data-testid": "tag-remove", "aria-label": V, children: N }), e[12] = x, e[13] = V, e[14] = b) : b = e[14];
114
- let H;
115
- return e[15] !== d || e[16] !== f || e[17] !== u || e[18] !== b ? (H = /* @__PURE__ */ q(Se, { variant: "secondary", className: f, children: [
114
+ let p;
115
+ return e[15] !== d || e[16] !== f || e[17] !== u || e[18] !== b ? (p = /* @__PURE__ */ q(Se, { variant: "secondary", className: f, children: [
116
116
  u,
117
117
  b
118
- ] }, d), e[15] = d, e[16] = f, e[17] = u, e[18] = b, e[19] = H) : H = e[19], H;
118
+ ] }, d), e[15] = d, e[16] = f, e[17] = u, e[18] = b, e[19] = p) : p = e[19], p;
119
119
  };
120
120
  Fe.displayName = "AutocompleteTag";
121
121
  const Sr = ({
@@ -137,7 +137,7 @@ const Sr = ({
137
137
  label: V = "",
138
138
  helperText: N = "",
139
139
  error: b,
140
- required: H = !1,
140
+ required: p = !1,
141
141
  fullWidth: te = !0,
142
142
  clearable: ue = !0,
143
143
  disableCloseOnSelect: se = !1,
@@ -150,20 +150,20 @@ const Sr = ({
150
150
  fields: L,
151
151
  // New prop for field mapping
152
152
  noOptionsText: Ve = "No options",
153
- emptyMessage: He,
154
- className: Ke = "",
153
+ emptyMessage: pe,
154
+ className: He = "",
155
155
  inputClassName: ye = "",
156
156
  chipClassName: be,
157
157
  debounceMs: ie = 0,
158
158
  // New: Debounce filtering
159
159
  minSearchLength: xe = 0,
160
160
  // New prop: Min chars before search
161
- ntt: pe = !1,
161
+ ntt: Ke = !1,
162
162
  clearInputOnSelect: xr = !0,
163
163
  onPointerDown: _,
164
164
  ...ze
165
165
  }) => {
166
- const [n, w] = Z(!1), [k, A] = Z(""), [je, we] = Z(""), [z, g] = Z(-1), [I, R] = Z(!1), [M, Be] = Z({
166
+ const [n, w] = Z(!1), [k, A] = Z(""), [je, we] = Z(""), [z, g] = Z(-1), [I, R] = Z(!1), [G, Be] = Z({
167
167
  top: 0,
168
168
  left: 0,
169
169
  width: 0,
@@ -173,7 +173,7 @@ const Sr = ({
173
173
  containerProps: Ue,
174
174
  onOpenChange: ve
175
175
  } = ir();
176
- p(() => {
176
+ K(() => {
177
177
  if (ie <= 0) {
178
178
  we(k);
179
179
  return;
@@ -181,27 +181,27 @@ const Sr = ({
181
181
  const r = setTimeout(() => we(k), ie);
182
182
  return () => clearTimeout(r);
183
183
  }, [k, ie]);
184
- const G = rr(je), v = O(null), Ne = O(null), Q = O(null), W = O(null), Y = O(!1), Ee = tr(), X = e.length > 0 ? e : l, F = J(() => me || ((r, o) => yr(r, o, j, L)), [me, j, L]), C = P((r) => {
184
+ const X = rr(je), v = O(null), Ne = O(null), M = O(null), Q = O(null), W = O(!1), Ee = tr(), Y = e.length > 0 ? e : l, F = J(() => me || ((r, o) => yr(r, o, j, L)), [me, j, L]), C = P((r) => {
185
185
  if (r == null) return "";
186
186
  if (typeof r == "object") return E(r);
187
- const o = X.find((m) => F(m, r));
187
+ const o = Y.find((m) => F(m, r));
188
188
  if (o) return E(o);
189
189
  try {
190
190
  return String(r);
191
191
  } catch {
192
192
  return "";
193
193
  }
194
- }, [X, E, F]), B = J(() => {
195
- if (G.length < xe)
196
- return X;
197
- let r = X;
198
- return c && Array.isArray(t) && (r = X.filter((o) => !t.some((m) => F(o, m)))), !c && !I && t && G === E(t) ? r : ce ? ce(r, {
199
- inputValue: G
200
- }) : br(r, G, E, L);
194
+ }, [Y, E, F]), B = J(() => {
195
+ if (X.length < xe)
196
+ return Y;
197
+ let r = Y;
198
+ return c && Array.isArray(t) && (r = Y.filter((o) => !t.some((m) => F(o, m)))), !c && !I && t && X === E(t) ? r : ce ? ce(r, {
199
+ inputValue: X
200
+ }) : br(r, X, E, L);
201
201
  }, [
202
- X,
202
+ Y,
203
203
  t,
204
- G,
204
+ X,
205
205
  // Use deferred value
206
206
  ce,
207
207
  E,
@@ -214,11 +214,11 @@ const Sr = ({
214
214
  const o = r.target.value;
215
215
  R(!0), A(o), s == null || s(r, o), !n && o && w(!0);
216
216
  }, [n, s]);
217
- p(() => {
217
+ K(() => {
218
218
  if (c || I) return;
219
219
  const r = C(t);
220
220
  A(r);
221
- }, [t, c, I, C]), p(() => {
221
+ }, [t, c, I, C]), K(() => {
222
222
  i && process.env.NODE_ENV !== "production" && console.warn('[DoctAutocomplete] The "change" prop is deprecated. Please use "onChange" instead. "change" will be removed in v3.0.');
223
223
  }, [i]);
224
224
  const ee = P((r) => {
@@ -290,8 +290,8 @@ const Sr = ({
290
290
  }, ""));
291
291
  break;
292
292
  }
293
- }, [n, B, z, ee, x, k, c, s]), K = P(() => {
294
- const r = Ne.current ?? W.current;
293
+ }, [n, B, z, ee, x, k, c, s]), H = P(() => {
294
+ const r = Ne.current ?? Q.current;
295
295
  if (!r) return;
296
296
  const o = r.getBoundingClientRect(), m = dr(r);
297
297
  Be(lr({
@@ -300,34 +300,34 @@ const Sr = ({
300
300
  strategy: "absolute",
301
301
  clipRects: m
302
302
  }));
303
- }, []), Ze = P(() => {
304
- n || (K(), k === "" && (s == null || s({
303
+ }, []), Ye = P(() => {
304
+ n || (H(), k === "" && (s == null || s({
305
305
  target: {
306
306
  value: ""
307
307
  }
308
308
  }, ""))), w(!n);
309
- }, [n, K, k, s]), Je = P(() => {
310
- if (Y.current) {
311
- Y.current = !1, K(), R(!1), !c && !t && (A(""), s == null || s({
309
+ }, [n, H, k, s]), Ze = P(() => {
310
+ if (W.current) {
311
+ W.current = !1, H(), R(!1), !c && !t && (A(""), s == null || s({
312
312
  target: {
313
313
  value: ""
314
314
  }
315
315
  }, ""));
316
316
  return;
317
317
  }
318
- K(), R(!1), w(!0), !c && !t && (A(""), s == null || s({
318
+ H(), R(!1), w(!0), !c && !t && (A(""), s == null || s({
319
319
  target: {
320
320
  value: ""
321
321
  }
322
322
  }, ""));
323
- }, [K, c, t, s]), Me = P((r) => {
323
+ }, [H, c, t, s]), Je = P((r) => {
324
324
  document.activeElement === v.current && w((o) => !o), _ == null || _(r);
325
325
  }, [_]);
326
- p(() => {
326
+ K(() => {
327
327
  const r = (o) => {
328
328
  const m = o.target;
329
329
  if (!(n || c && k !== "")) return;
330
- const D = W.current ? !W.current.contains(m) : !0, de = Q.current ? !Q.current.contains(m) : !0;
330
+ const D = Q.current ? !Q.current.contains(m) : !0, de = M.current ? !M.current.contains(m) : !0;
331
331
  if (D && de) {
332
332
  if (w(!1), R(!1), c) {
333
333
  A(""), s == null || s({
@@ -348,12 +348,12 @@ const Sr = ({
348
348
  return document.addEventListener("pointerdown", r, !0), () => {
349
349
  document.removeEventListener("pointerdown", r, !0);
350
350
  };
351
- }, [c, s, C, t, n, k]), p(() => {
351
+ }, [c, s, C, t, n, k]), K(() => {
352
352
  if (!n || typeof window > "u") return;
353
353
  const r = () => {
354
- K();
355
- }, o = W.current, m = ar(o), $ = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
356
- K();
354
+ H();
355
+ }, o = Q.current, m = ar(o), $ = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
356
+ H();
357
357
  });
358
358
  return $ == null || $.observe(o ?? document.body), m.forEach((D) => {
359
359
  D.addEventListener("scroll", r, {
@@ -364,86 +364,87 @@ const Sr = ({
364
364
  D.removeEventListener("scroll", r);
365
365
  }), window.removeEventListener("resize", r);
366
366
  };
367
- }, [n, K]), p(() => {
368
- if (n && z >= 0 && Q.current) {
369
- const r = Q.current.children[z];
367
+ }, [n, H]), K(() => {
368
+ if (n && z >= 0 && M.current) {
369
+ const r = M.current.children[z];
370
370
  r && r.scrollIntoView({
371
371
  block: "nearest"
372
372
  });
373
373
  }
374
- }, [z, n]), p(() => {
374
+ }, [z, n]), K(() => {
375
375
  if (!n || !c) return;
376
376
  const r = requestAnimationFrame(() => {
377
- K();
377
+ H();
378
378
  });
379
379
  return () => cancelAnimationFrame(r);
380
- }, [n, c, t, K]), p(() => {
380
+ }, [n, c, t, H]), K(() => {
381
381
  w(!1);
382
- }, []), p(() => {
382
+ }, []), K(() => {
383
383
  ve(n);
384
384
  }, [n, ve]);
385
385
  const $e = P(() => {
386
386
  var r;
387
- document.activeElement !== v.current && (Y.current = !0), w(!1), c && (A(""), R(!1), s == null || s({
387
+ document.activeElement !== v.current && (W.current = !0), w(!1), c && (A(""), R(!1), s == null || s({
388
388
  target: {
389
389
  value: ""
390
390
  }
391
391
  }, "")), (r = v.current) == null || r.focus();
392
- }, [c, s]), Qe = J(() => !c || !Array.isArray(t) || t.length === 0 ? null : oe ? oe(t, le) : (
392
+ }, [c, s]), Me = J(() => !c || !Array.isArray(t) || t.length === 0 ? null : oe ? oe(t, le) : (
393
393
  // biome-ignore lint/a11y/noStaticElementInteractions: chips container wraps nested buttons (tag remove)
394
394
  // biome-ignore lint/a11y/useKeyWithClickEvents: Escape/click-outside already close; click is convenience
395
395
  /* @__PURE__ */ a("div", { className: "flex flex-wrap gap-1 mb-1 min-h-0", onClick: $e, children: t.map((r, o) => {
396
396
  const m = j ? String(j(r)) : `${E(r)}-${o}`;
397
397
  return /* @__PURE__ */ a(Fe, { tag: r, index: o, getOptionLabel: E, onRemove: le, chipClassName: be }, m);
398
398
  }) })
399
- ), [c, t, oe, le, $e, E, j, be]), We = J(() => `
399
+ ), [c, t, oe, le, $e, E, j, be]), Qe = J(() => `
400
400
  relative flex items-center rounded-md
401
401
  ${b ? "border border-destructive" : fr[T]}
402
402
  ${nr[u]}
403
403
  ${y ? "opacity-50 cursor-not-allowed" : "cursor-text"}
404
404
  transition-colors ${ye}
405
- `, [T, u, b, y, ye]), Ye = He ?? Ve;
406
- return /* @__PURE__ */ q("div", { className: `relative ${te ? "w-full" : "w-auto"} ${Ke}`, ref: W, children: [
405
+ `, [T, u, b, y, ye]), We = pe ?? Ve;
406
+ return /* @__PURE__ */ q("div", { className: `relative ${te ? "w-full" : "w-auto"} ${He}`, ref: Q, children: [
407
407
  V && /* @__PURE__ */ q("label", { htmlFor: Ee, className: "block text-sm font-medium mb-1 w-full", onClick: (r) => {
408
408
  var o;
409
- r.preventDefault(), document.activeElement !== v.current && (Y.current = !0), w(!1), c && (A(""), R(!1), s == null || s({
409
+ r.preventDefault(), document.activeElement !== v.current && (W.current = !0), w(!1), c && (A(""), R(!1), s == null || s({
410
410
  target: {
411
411
  value: ""
412
412
  }
413
413
  }, "")), (o = v.current) == null || o.focus();
414
414
  }, onKeyDown: (r) => {
415
415
  var o;
416
- (r.key === "Enter" || r.key === " ") && (r.preventDefault(), document.activeElement !== v.current && (Y.current = !0), w(!1), c && (A(""), R(!1), s == null || s({
416
+ (r.key === "Enter" || r.key === " ") && (r.preventDefault(), document.activeElement !== v.current && (W.current = !0), w(!1), c && (A(""), R(!1), s == null || s({
417
417
  target: {
418
418
  value: ""
419
419
  }
420
420
  }, "")), (o = v.current) == null || o.focus());
421
421
  }, children: [
422
422
  V,
423
- H && /* @__PURE__ */ a("span", { className: "text-destructive ml-1", children: "*" })
423
+ p && /* @__PURE__ */ a("span", { className: "text-destructive ml-1", children: "*" })
424
424
  ] }),
425
425
  /* @__PURE__ */ a("div", { ...Ue, children: /* @__PURE__ */ q("div", { className: "relative overflow-visible", children: [
426
- Qe,
427
- /* @__PURE__ */ q("div", { ref: Ne, className: We, children: [
428
- /* @__PURE__ */ a(or, { id: Ee, ref: v, value: k, onChange: qe, onKeyDown: Xe, onFocus: Je, onPointerDown: Me, placeholder: S, disabled: y, className: "px-0 border-0 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0 bg-transparent rounded-md", ...ze }),
426
+ Me,
427
+ /* @__PURE__ */ q("div", { ref: Ne, className: Qe, children: [
428
+ /* @__PURE__ */ a(or, { id: Ee, ref: v, value: k, onChange: qe, onKeyDown: Xe, onFocus: Ze, onPointerDown: Je, placeholder: S, disabled: y, className: "px-0 border-0 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0 bg-transparent rounded-md", ...ze }),
429
429
  /* @__PURE__ */ q("div", { className: "flex items-center gap-1 ml-auto", children: [
430
430
  f && /* @__PURE__ */ a("div", { className: "animate-spin rounded-full h-4 w-4 border-2 border-muted-foreground border-t-transparent" }),
431
431
  Ge && /* @__PURE__ */ a("button", { type: "button", onClick: Le, className: "p-1 hover:bg-accent rounded-sm transition-colors", tabIndex: -1, "data-testid": "autocomplete-clear", children: /* @__PURE__ */ a(Re, { className: "h-4 w-4 text-muted-foreground" }) }),
432
- /* @__PURE__ */ a("button", { type: "button", disabled: y, onClick: Ze, className: `p-1 hover:bg-accent rounded-sm transition-colors ${y ? "opacity-50 cursor-not-allowed" : "cursor-pointer"}`, tabIndex: -1, "data-testid": "autocomplete-toggle", children: /* @__PURE__ */ a(Ce, { className: `h-4 w-4 text-muted-foreground transition-transform ${n ? "rotate-180" : ""}` }) })
432
+ /* @__PURE__ */ a("button", { type: "button", disabled: y, onClick: Ye, className: `p-1 hover:bg-accent rounded-sm transition-colors ${y ? "opacity-50 cursor-not-allowed" : "cursor-pointer"}`, tabIndex: -1, "data-testid": "autocomplete-toggle", children: /* @__PURE__ */ a(Ce, { className: `h-4 w-4 text-muted-foreground transition-transform ${n ? "rotate-180" : ""}` }) })
433
433
  ] })
434
434
  ] }),
435
- n && M.maxHeight > 0 && cr(/* @__PURE__ */ a("div", { className: `
435
+ n && G.maxHeight > 0 && cr(/* @__PURE__ */ a("div", { className: `
436
436
  absolute bg-popover border border-border rounded-md shadow-lg
437
437
  max-h-60 overflow-auto z-[9999]
438
438
 
439
439
  `, style: {
440
- top: M.top,
441
- left: M.left,
442
- width: M.width,
443
- maxHeight: M.maxHeight
444
- }, ref: Q, children: B.length === 0 ? /* @__PURE__ */ a("div", { className: "p-3 text-sm text-muted-foreground text-center", children: Ye }) : B.map((r, o) => {
440
+ top: G.top,
441
+ left: G.left,
442
+ width: G.width,
443
+ maxHeight: G.maxHeight,
444
+ transform: G.placement === "top" ? "translateY(-100%)" : void 0
445
+ }, ref: M, children: B.length === 0 ? /* @__PURE__ */ a("div", { className: "p-3 text-sm text-muted-foreground text-center", children: We }) : B.map((r, o) => {
445
446
  const m = c ? Array.isArray(t) && t.some((U) => F(r, U)) : F(r, t), $ = o === z, D = j ? String(j(r)) : `${E(r)}-${o}`, de = (U) => U.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), h = (U) => {
446
- const ae = E(U), ne = pe ? String(G || "").trim() : "";
447
+ const ae = E(U), ne = Ke ? String(X || "").trim() : "";
447
448
  if (!ne) return /* @__PURE__ */ a("span", { children: ae });
448
449
  try {
449
450
  const he = new RegExp(`(${de(ne)})`, "ig"), Oe = ae.split(he);
@@ -8,7 +8,7 @@ const I = ({
8
8
  viewportPadding: l = 8,
9
9
  clipRects: e = []
10
10
  }) => {
11
- const w = window.innerHeight, H = window.innerWidth, S = M === "absolute" ? window.scrollX : 0, p = M === "absolute" ? window.scrollY : 0, u = e.reduce((i, o) => Math.max(i, o.top), 0), d = e.reduce((i, o) => Math.min(i, o.bottom), w), s = e.reduce((i, o) => Math.max(i, o.left), 0), n = e.reduce((i, o) => Math.min(i, o.right), H), c = t.bottom < u || t.top > d || t.left + t.width < s || t.left > n, A = Math.max(0, d - t.bottom - l - m), B = Math.max(0, t.top - u - l - m), C = Math.max(0, w - t.bottom - l - m), L = Math.max(0, t.top - l - m), W = Math.min(f, 160), a = x === "auto" ? A >= W || A >= B ? "bottom" : "top" : x, F = Math.max(0, Math.min(f, a === "bottom" ? C : L)), v = c ? 0 : F, X = t.left >= s && t.left + t.width <= n;
11
+ const w = window.innerHeight, v = window.innerWidth, H = M === "absolute" ? window.scrollX : 0, p = M === "absolute" ? window.scrollY : 0, u = e.reduce((i, o) => Math.max(i, o.top), 0), d = e.reduce((i, o) => Math.min(i, o.bottom), w), s = e.reduce((i, o) => Math.max(i, o.left), 0), n = e.reduce((i, o) => Math.min(i, o.right), v), c = t.bottom < u || t.top > d || t.left + t.width < s || t.left > n, A = Math.max(0, d - t.bottom - l - m), S = Math.max(0, t.top - u - l - m), B = Math.max(0, w - t.bottom - l - m), C = Math.max(0, t.top - l - m), L = Math.min(f, 160), a = x === "auto" ? A >= L || A >= S ? "bottom" : "top" : x, W = Math.max(0, Math.min(f, a === "bottom" ? B : C)), F = c ? 0 : W, X = t.left >= s && t.left + t.width <= n;
12
12
  let h, b;
13
13
  if (X)
14
14
  h = t.width, b = t.left;
@@ -19,10 +19,10 @@ const I = ({
19
19
  b = Math.min(Math.max(t.left, o), Y);
20
20
  }
21
21
  return {
22
- top: a === "bottom" ? t.bottom + m + p : t.top - m - v + p,
23
- left: b + S,
22
+ top: a === "bottom" ? t.bottom + m + p : t.top - m + p,
23
+ left: b + H,
24
24
  width: h,
25
- maxHeight: v,
25
+ maxHeight: F,
26
26
  placement: a,
27
27
  isAnchorClipped: c
28
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docthub-core-components",
3
- "version": "3.2.8",
3
+ "version": "3.2.9",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",