@skiddph/prui 0.13.0 → 0.13.1

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.
@@ -3,10 +3,12 @@ import { PropsMeta } from './props-meta';
3
3
  import * as React from "react";
4
4
  /**
5
5
  * TagInput: comma-separated entry as removable chips (tags, email
6
- * recipients, keywords). Text commits on a separator, Enter, paste of
7
- * multi-value text, or blur; Backspace on an empty field removes the last
8
- * tag. The chip and the value are separate concerns: labelFor decides what
9
- * the chip displays while onChange keeps emitting the original strings, and
6
+ * recipients, keywords). Text commits the moment a separator arrives by
7
+ * keydown, or through the input value itself (IME, virtual keyboards,
8
+ * autofill, multi-char separators like " and ") plus Enter, multi-value
9
+ * paste, or blur; Backspace on an empty field removes the last tag. The
10
+ * chip and the value are separate concerns: labelFor decides what the chip
11
+ * displays while onChange keeps emitting the original strings, and
10
12
  * renderTag takes over the chip entirely.
11
13
  */
12
14
  export type TagInputSize = "sm" | "md" | "lg";
@@ -1,81 +1,88 @@
1
- import { jsxs as I, jsx as u } from "react/jsx-runtime";
2
- import * as c from "react";
3
- import { X as L } from "lucide-react";
4
- import { resolveSurface as Q, withSurface as W } from "./surface.js";
5
- import { cn as Y } from "./cn.js";
6
- import { usePruiI18n as Z } from "../i18n.js";
7
- const ee = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), te = {
1
+ import { jsxs as D, jsx as u } from "react/jsx-runtime";
2
+ import * as d from "react";
3
+ import { X as Q } from "lucide-react";
4
+ import { resolveSurface as W, withSurface as Y } from "./surface.js";
5
+ import { cn as Z } from "./cn.js";
6
+ import { usePruiI18n as ee } from "../i18n.js";
7
+ const te = (h) => h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), ne = {
8
8
  sm: "min-h-8 text-sm",
9
9
  md: "min-h-9 text-sm",
10
10
  lg: "min-h-11 text-base"
11
- }, ne = c.forwardRef(function({
11
+ }, re = d.forwardRef(function({
12
12
  className: j,
13
13
  style: k,
14
14
  size: R = "md",
15
15
  variant: T = "default",
16
- value: b,
16
+ value: v,
17
17
  defaultValue: B,
18
- onChange: d,
19
- separators: l = [","],
20
- commitOnBlur: P = !0,
21
- parseInput: S,
22
- validate: h,
18
+ onChange: m,
19
+ separators: a = [","],
20
+ commitOnBlur: C = !0,
21
+ parseInput: P,
22
+ validate: b,
23
23
  maxTags: y,
24
- allowDuplicates: C = !1,
24
+ allowDuplicates: S = !1,
25
25
  labelFor: x,
26
26
  renderTag: w,
27
- disabled: m,
27
+ disabled: f,
28
28
  bg: z,
29
29
  fg: E,
30
30
  radius: F,
31
31
  texture: K,
32
32
  textureColor: A,
33
33
  elevation: M,
34
- ...n
34
+ ...r
35
35
  }, O) {
36
- const { t: U } = Z(), N = b !== void 0, [V, X] = c.useState(B ?? []), r = N ? b : V, [o, f] = c.useState(""), _ = S ?? ((e) => e.split(new RegExp(l.map(ee).join("|"))).map((t) => t.trim()).filter(Boolean)), $ = (e) => {
37
- N || X(e), d == null || d(e);
38
- }, p = (e) => {
36
+ const { t: U } = ee(), N = v !== void 0, [V, X] = d.useState(B ?? []), o = N ? v : V, [l, p] = d.useState(""), _ = P ?? ((e) => e.split(new RegExp(a.map(te).join("|"))).map((t) => t.trim()).filter(Boolean)), I = (e) => {
37
+ N || X(e), m == null || m(e);
38
+ }, c = (e) => {
39
39
  const t = _(e);
40
40
  if (!t.length) {
41
- f("");
41
+ p("");
42
42
  return;
43
43
  }
44
- const a = [...r], i = [];
44
+ const n = [...o], i = [];
45
45
  for (const s of t)
46
- y !== void 0 && a.length >= y ? i.push(s) : !C && a.includes(s) || (h && !h(s) ? i.push(s) : a.push(s));
47
- f(i.join(l[0] ?? ", ")), a.length !== r.length && $(a);
48
- }, g = (e) => $(r.filter((t, a) => a !== e)), q = (e) => {
46
+ y !== void 0 && n.length >= y ? i.push(s) : !S && n.includes(s) || (b && !b(s) ? i.push(s) : n.push(s));
47
+ p(i.join(a[0] ?? ", ")), n.length !== o.length && I(n);
48
+ }, g = (e) => I(o.filter((t, n) => n !== e)), q = (e) => {
49
49
  var t;
50
- e.key === "Enter" || l.includes(e.key) ? (e.preventDefault(), p(o)) : e.key === "Backspace" && !o && r.length && (e.preventDefault(), g(r.length - 1)), (t = n.onKeyDown) == null || t.call(n, e);
50
+ e.key === "Enter" || a.includes(e.key) ? (e.preventDefault(), c(l)) : e.key === "Backspace" && !l && o.length && (e.preventDefault(), g(o.length - 1)), (t = r.onKeyDown) == null || t.call(r, e);
51
51
  }, G = (e) => {
52
- var a;
52
+ var n;
53
53
  const t = e.clipboardData.getData("text");
54
- if (t && l.some((i) => t.includes(i))) {
55
- e.preventDefault(), p(o ? `${o}${l[0] ?? ","}${t}` : t);
54
+ if (t && a.some((i) => t.includes(i))) {
55
+ e.preventDefault(), c(l ? `${l}${a[0] ?? ","}${t}` : t);
56
56
  return;
57
57
  }
58
- (a = n.onPaste) == null || a.call(n, e);
58
+ (n = r.onPaste) == null || n.call(r, e);
59
59
  }, H = (e) => {
60
60
  var t;
61
- P && p(o), (t = n.onBlur) == null || t.call(n, e);
62
- }, J = Q({ bg: z, fg: E, radius: F, texture: K, textureColor: A, elevation: M }), D = W(
63
- Y(
61
+ C && c(l), (t = r.onBlur) == null || t.call(r, e);
62
+ }, J = (e) => {
63
+ const t = e.target.value;
64
+ if (a.some((n) => t.includes(n))) {
65
+ c(t);
66
+ return;
67
+ }
68
+ p(t);
69
+ }, L = W({ bg: z, fg: E, radius: F, texture: K, textureColor: A, elevation: M }), $ = Y(
70
+ Z(
64
71
  "prui-f-control prui-taginput flex w-full flex-wrap items-center gap-1 px-1.5 py-1",
65
72
  "border border-[var(--prui-line)] rounded-[var(--prui-s-radius,var(--prui-radius))]",
66
73
  "bg-[var(--prui-s-bg,var(--prui-background))] text-[var(--prui-s-fg,var(--prui-fg))] placeholder:text-[var(--prui-dim)]",
67
74
  "outline-none transition-colors focus-within:border-[var(--prui-brand)] focus-within:ring-2 focus-within:ring-[var(--prui-brand)]/30",
68
- te[R],
75
+ ne[R],
69
76
  T === "filled" && "bg-[var(--prui-s-bg,var(--prui-raise))] border-transparent",
70
- m && "opacity-50 cursor-not-allowed",
77
+ f && "opacity-50 cursor-not-allowed",
71
78
  j
72
79
  ),
73
80
  k,
74
- J
81
+ L
75
82
  );
76
- return /* @__PURE__ */ I("div", { className: D.className, style: D.style, children: [
77
- r.map(
78
- (e, t) => w ? /* @__PURE__ */ u(c.Fragment, { children: w(e, { remove: () => g(t) }) }, `${e}-${t}`) : /* @__PURE__ */ I(
83
+ return /* @__PURE__ */ D("div", { className: $.className, style: $.style, children: [
84
+ o.map(
85
+ (e, t) => w ? /* @__PURE__ */ u(d.Fragment, { children: w(e, { remove: () => g(t) }) }, `${e}-${t}`) : /* @__PURE__ */ D(
79
86
  "span",
80
87
  {
81
88
  className: "inline-flex max-w-full items-center gap-1 rounded-[var(--prui-radius-full)] border border-[var(--prui-line)] bg-[var(--prui-raise)] py-0.5 pl-2 pr-1 text-xs text-[var(--prui-fg)]",
@@ -86,10 +93,10 @@ const ee = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), te = {
86
93
  {
87
94
  type: "button",
88
95
  "aria-label": U.removeTag.replace("{label}", e),
89
- disabled: m,
96
+ disabled: f,
90
97
  onClick: () => g(t),
91
98
  className: "flex h-4 w-4 cursor-pointer items-center justify-center rounded-full text-[var(--prui-dim)] hover:bg-[var(--prui-line)] hover:text-[var(--prui-fg)] disabled:cursor-not-allowed",
92
- children: /* @__PURE__ */ u(L, { className: "h-3 w-3", "aria-hidden": !0 })
99
+ children: /* @__PURE__ */ u(Q, { className: "h-3 w-3", "aria-hidden": !0 })
93
100
  }
94
101
  )
95
102
  ]
@@ -101,20 +108,20 @@ const ee = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), te = {
101
108
  "input",
102
109
  {
103
110
  ref: O,
104
- value: o,
105
- onChange: (e) => f(e.target.value),
111
+ value: l,
112
+ onChange: J,
106
113
  onKeyDown: q,
107
114
  onPaste: G,
108
115
  onBlur: H,
109
- disabled: m,
110
- ...n,
116
+ disabled: f,
117
+ ...r,
111
118
  className: "h-7 min-w-16 flex-1 bg-transparent text-sm outline-none placeholder:text-[var(--prui-dim)] disabled:cursor-not-allowed"
112
119
  }
113
120
  )
114
121
  ] });
115
122
  });
116
- ne.displayName = "TagInput";
117
- const se = {
123
+ re.displayName = "TagInput";
124
+ const ue = {
118
125
  name: "TagInput",
119
126
  props: [
120
127
  { name: "value", type: "string[]", default: "uncontrolled", control: "none" },
@@ -135,6 +142,6 @@ const se = {
135
142
  ]
136
143
  };
137
144
  export {
138
- ne as TagInput,
139
- se as tagInputPropsMeta
145
+ re as TagInput,
146
+ ue as tagInputPropsMeta
140
147
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skiddph/prui",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "PRUI component system: primitives, app-layer super-components, pages, and themes",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",