@bison-lab/ui 3.28.0 → 3.35.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.
@@ -65,7 +65,14 @@ declare function usPhoneField({
65
65
  }?: UsPhoneFieldOptions): z.ZodEffects<z.ZodString, string, string>;
66
66
  //#endregion
67
67
  //#region src/lib/us-phone.d.ts
68
- /** Strips non-digits and caps at 10 (US NANP). */
68
+ /**
69
+ * Strips non-digits, drops a `+1` country code, and caps at 10 (US NANP).
70
+ *
71
+ * No NANP area code starts with 1, so a leading 1 on an eleven-digit or longer
72
+ * value can only be the country code (`+1 816 555 1234`, `+18165551234`). A
73
+ * shorter value keeps its 1: someone typing `+1 …` sees it until the eleventh
74
+ * digit arrives, when the display corrects itself.
75
+ */
69
76
  declare function parseUsPhoneDigits(value: string): string;
70
77
  /** Formats a phone value (digits, E.164, or any mixed string) as `(XXX) XXX-XXXX`. */
71
78
  declare function formatUsPhone(value: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.mts","names":[],"sources":["../src/form/validators.ts","../src/lib/us-phone.ts"],"mappings":";;;;;AAsBA;;;;;AAWA;;;;;;;;;;;UAXiB,gBAAA;EAaO;EAXtB,eAAA;AAAA;AAeF;;;;;;AAAA,iBANgB,YAAA,CAAA;EACd;AAAA,IACC,gBAAA,GAAqB,CAAA,CAAA,SAAA;AAAA,UAIP,iBAAA,SAA0B,gBAAA;EAIjC;EAFR,OAAA;EAMwB;EAJxB,QAAA;AAAA;;iBAIc,UAAA,CAAA;EACd,eAAA;EACA,OAAA;EACA;AAAA,IACC,iBAAA,GAAsB,CAAA,CAAA,SAAA,GAAA,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,SAAA;AAAA,UAYR,mBAAA,SAA4B,gBAAA;EAZpB;EAcvB,OAAA;EAduB;EAgBvB,QAAA;AAAA;;;;;;;;;iBAWc,YAAA,CAAA;EACd,eAAA;EACA,OAAA;EACA;AAAA,IACC,mBAAA,GAAwB,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,SAAA;;;;iBC/EX,kBAAA,CAAmB,KAAA;;iBAKnB,aAAA,CAAc,KAAA"}
1
+ {"version":3,"file":"validators.d.mts","names":[],"sources":["../src/form/validators.ts","../src/lib/us-phone.ts"],"mappings":";;;;;AAsBA;;;;;AAWA;;;;;;;;;;;UAXiB,gBAAA;EAaO;EAXtB,eAAA;AAAA;AAeF;;;;;;AAAA,iBANgB,YAAA,CAAA;EACd;AAAA,IACC,gBAAA,GAAqB,CAAA,CAAA,SAAA;AAAA,UAIP,iBAAA,SAA0B,gBAAA;EAIjC;EAFR,OAAA;EAMwB;EAJxB,QAAA;AAAA;;iBAIc,UAAA,CAAA;EACd,eAAA;EACA,OAAA;EACA;AAAA,IACC,iBAAA,GAAsB,CAAA,CAAA,SAAA,GAAA,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,SAAA;AAAA,UAYR,mBAAA,SAA4B,gBAAA;EAZpB;EAcvB,OAAA;EAduB;EAgBvB,QAAA;AAAA;;;;;;;;;iBAWc,YAAA,CAAA;EACd,eAAA;EACA,OAAA;EACA;AAAA,IACC,mBAAA,GAAwB,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,SAAA;;;;;;AA5D3B;;;;;iBCZgB,kBAAA,CAAmB,KAAA;;iBAOnB,aAAA,CAAc,KAAA"}
@@ -1,9 +1,17 @@
1
1
  import { z } from "zod";
2
2
  //#region src/lib/us-phone.ts
3
3
  const PHONE_MAX_DIGITS = 10;
4
- /** Strips non-digits and caps at 10 (US NANP). */
4
+ /**
5
+ * Strips non-digits, drops a `+1` country code, and caps at 10 (US NANP).
6
+ *
7
+ * No NANP area code starts with 1, so a leading 1 on an eleven-digit or longer
8
+ * value can only be the country code (`+1 816 555 1234`, `+18165551234`). A
9
+ * shorter value keeps its 1: someone typing `+1 …` sees it until the eleventh
10
+ * digit arrives, when the display corrects itself.
11
+ */
5
12
  function parseUsPhoneDigits(value) {
6
- return value.replace(/\D/g, "").slice(0, PHONE_MAX_DIGITS);
13
+ const digits = value.replace(/\D/g, "");
14
+ return (digits.length > PHONE_MAX_DIGITS && digits.startsWith("1") ? digits.slice(1) : digits).slice(0, PHONE_MAX_DIGITS);
7
15
  }
8
16
  /** Formats a phone value (digits, E.164, or any mixed string) as `(XXX) XXX-XXXX`. */
9
17
  function formatUsPhone(value) {
@@ -1 +1 @@
1
- {"version":3,"file":"validators.mjs","names":[],"sources":["../src/lib/us-phone.ts","../src/form/validators.ts"],"sourcesContent":["const PHONE_MAX_DIGITS = 10;\n\n/** Strips non-digits and caps at 10 (US NANP). */\nexport function parseUsPhoneDigits(value: string): string {\n return value.replace(/\\D/g, '').slice(0, PHONE_MAX_DIGITS);\n}\n\n/** Formats a phone value (digits, E.164, or any mixed string) as `(XXX) XXX-XXXX`. */\nexport function formatUsPhone(value: string): string {\n const d = parseUsPhoneDigits(value);\n if (d.length <= 3) return d;\n if (d.length <= 6) return `(${d.slice(0, 3)}) ${d.slice(3)}`;\n return `(${d.slice(0, 3)}) ${d.slice(3, 6)}-${d.slice(6)}`;\n}\n\n/**\n * Deliberately NOT a `'use client'` module, and deliberately not living in\n * `phone-input.tsx` any more.\n *\n * `validators.ts` needs `parseUsPhoneDigits`, and it is consumed from Server\n * Actions. Importing it from the component file dragged the whole client\n * component in behind it, and every output of the main entry carries a\n * `\"use client\"` banner — so calling the validator on the server failed with\n * \"Attempted to call … from the server but … is on the client\".\n *\n * Keep this file free of React, and free of imports from anything holding a\n * `'use client'` directive.\n */\n","import { z } from 'zod';\nimport { parseUsPhoneDigits } from '../lib/us-phone';\n\n/**\n * Shared field schemas for `<Form schema={...}>`.\n *\n * Published from `@bison-lab/ui/validators`, NOT the package root. Every output\n * of the main entry carries a `\"use client\"` banner, and these are meant to run\n * in Server Actions and route handlers as well as the browser — importing them\n * from the root fails at runtime with \"Attempted to call … from the server but\n * … is on the client\". Keep this file free of React and of anything holding a\n * `'use client'` directive.\n *\n * These exist so the rules that go with the library's own controls ship with\n * the library. The phone case is the reason they had to: `PhoneInput` submits\n * its FORMATTED display value — `(555) 123-4567`, not `5551234567` — because\n * the visible input is the one carrying the `name`. Every consumer writing\n * their own `z.string().length(10)` against that field gets a schema that can\n * never pass, and the failure looks like a validation bug rather than a\n * formatting mismatch. {@link usPhoneField} counts digits instead.\n */\n\nexport interface TextFieldOptions {\n /** Message shown when the field is empty. */\n requiredMessage?: string;\n}\n\n/**\n * A trimmed, non-empty string.\n *\n * Trimming happens before the emptiness check, so a field holding only spaces\n * fails rather than passing as \"filled\".\n */\nexport function requiredText({\n requiredMessage = 'This field is required.',\n}: TextFieldOptions = {}) {\n return z.string().trim().min(1, { message: requiredMessage });\n}\n\nexport interface EmailFieldOptions extends TextFieldOptions {\n /** Message shown when the value is present but not an email address. */\n message?: string;\n /** Allow an empty value. @default false */\n optional?: boolean;\n}\n\n/** An email address. Trimmed, and empty-tolerant when `optional`. */\nexport function emailField({\n requiredMessage = 'Email address is required.',\n message = 'Enter a valid email address.',\n optional = false,\n}: EmailFieldOptions = {}) {\n const base = z.string().trim();\n\n if (optional) {\n return base.refine((value) => value === '' || z.string().email().safeParse(value).success, {\n message,\n });\n }\n\n return base.min(1, { message: requiredMessage }).email({ message });\n}\n\nexport interface UsPhoneFieldOptions extends TextFieldOptions {\n /** Message shown when the value is present but not ten digits. */\n message?: string;\n /** Require a value. @default false — phone is usually a secondary channel. */\n required?: boolean;\n}\n\n/**\n * A US (NANP) phone number, counted in digits rather than matched by shape.\n *\n * Accepts anything `PhoneInput` can produce or a human can paste:\n * `(555) 123-4567`, `555-123-4567`, `5551234567`, `+1 555 123 4567`. What it\n * checks is that exactly ten digits are present, which is the only part that\n * carries meaning — `PhoneInput` already owns the presentation.\n */\nexport function usPhoneField({\n requiredMessage = 'Phone number is required.',\n message = 'Enter a 10-digit US phone number.',\n required = false,\n}: UsPhoneFieldOptions = {}) {\n const base = z.string().trim();\n const hasTenDigits = (value: string) => parseUsPhoneDigits(value).length === 10;\n\n if (required) {\n return base.min(1, { message: requiredMessage }).refine(hasTenDigits, { message });\n }\n\n return base.refine((value) => value === '' || hasTenDigits(value), { message });\n}\n"],"mappings":";;AAAA,MAAM,mBAAmB;;AAGzB,SAAgB,mBAAmB,OAAuB;AACxD,QAAO,MAAM,QAAQ,OAAO,GAAG,CAAC,MAAM,GAAG,iBAAiB;;;AAI5D,SAAgB,cAAc,OAAuB;CACnD,MAAM,IAAI,mBAAmB,MAAM;AACnC,KAAI,EAAE,UAAU,EAAG,QAAO;AAC1B,KAAI,EAAE,UAAU,EAAG,QAAO,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE;AAC1D,QAAO,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;ACqB1D,SAAgB,aAAa,EAC3B,kBAAkB,8BACE,EAAE,EAAE;AACxB,QAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,SAAS,iBAAiB,CAAC;;;AAW/D,SAAgB,WAAW,EACzB,kBAAkB,8BAClB,UAAU,gCACV,WAAW,UACU,EAAE,EAAE;CACzB,MAAM,OAAO,EAAE,QAAQ,CAAC,MAAM;AAE9B,KAAI,SACF,QAAO,KAAK,QAAQ,UAAU,UAAU,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,MAAM,CAAC,SAAS,EACzF,SACD,CAAC;AAGJ,QAAO,KAAK,IAAI,GAAG,EAAE,SAAS,iBAAiB,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC;;;;;;;;;;AAkBrE,SAAgB,aAAa,EAC3B,kBAAkB,6BAClB,UAAU,qCACV,WAAW,UACY,EAAE,EAAE;CAC3B,MAAM,OAAO,EAAE,QAAQ,CAAC,MAAM;CAC9B,MAAM,gBAAgB,UAAkB,mBAAmB,MAAM,CAAC,WAAW;AAE7E,KAAI,SACF,QAAO,KAAK,IAAI,GAAG,EAAE,SAAS,iBAAiB,CAAC,CAAC,OAAO,cAAc,EAAE,SAAS,CAAC;AAGpF,QAAO,KAAK,QAAQ,UAAU,UAAU,MAAM,aAAa,MAAM,EAAE,EAAE,SAAS,CAAC"}
1
+ {"version":3,"file":"validators.mjs","names":[],"sources":["../src/lib/us-phone.ts","../src/form/validators.ts"],"sourcesContent":["const PHONE_MAX_DIGITS = 10;\n\n/**\n * Strips non-digits, drops a `+1` country code, and caps at 10 (US NANP).\n *\n * No NANP area code starts with 1, so a leading 1 on an eleven-digit or longer\n * value can only be the country code (`+1 816 555 1234`, `+18165551234`). A\n * shorter value keeps its 1: someone typing `+1 …` sees it until the eleventh\n * digit arrives, when the display corrects itself.\n */\nexport function parseUsPhoneDigits(value: string): string {\n const digits = value.replace(/\\D/g, '');\n const national = digits.length > PHONE_MAX_DIGITS && digits.startsWith('1') ? digits.slice(1) : digits;\n return national.slice(0, PHONE_MAX_DIGITS);\n}\n\n/** Formats a phone value (digits, E.164, or any mixed string) as `(XXX) XXX-XXXX`. */\nexport function formatUsPhone(value: string): string {\n const d = parseUsPhoneDigits(value);\n if (d.length <= 3) return d;\n if (d.length <= 6) return `(${d.slice(0, 3)}) ${d.slice(3)}`;\n return `(${d.slice(0, 3)}) ${d.slice(3, 6)}-${d.slice(6)}`;\n}\n\n/**\n * Deliberately NOT a `'use client'` module, and deliberately not living in\n * `phone-input.tsx` any more.\n *\n * `validators.ts` needs `parseUsPhoneDigits`, and it is consumed from Server\n * Actions. Importing it from the component file dragged the whole client\n * component in behind it, and every output of the main entry carries a\n * `\"use client\"` banner — so calling the validator on the server failed with\n * \"Attempted to call … from the server but … is on the client\".\n *\n * Keep this file free of React, and free of imports from anything holding a\n * `'use client'` directive.\n */\n","import { z } from 'zod';\nimport { parseUsPhoneDigits } from '../lib/us-phone';\n\n/**\n * Shared field schemas for `<Form schema={...}>`.\n *\n * Published from `@bison-lab/ui/validators`, NOT the package root. Every output\n * of the main entry carries a `\"use client\"` banner, and these are meant to run\n * in Server Actions and route handlers as well as the browser — importing them\n * from the root fails at runtime with \"Attempted to call … from the server but\n * … is on the client\". Keep this file free of React and of anything holding a\n * `'use client'` directive.\n *\n * These exist so the rules that go with the library's own controls ship with\n * the library. The phone case is the reason they had to: `PhoneInput` submits\n * its FORMATTED display value — `(555) 123-4567`, not `5551234567` — because\n * the visible input is the one carrying the `name`. Every consumer writing\n * their own `z.string().length(10)` against that field gets a schema that can\n * never pass, and the failure looks like a validation bug rather than a\n * formatting mismatch. {@link usPhoneField} counts digits instead.\n */\n\nexport interface TextFieldOptions {\n /** Message shown when the field is empty. */\n requiredMessage?: string;\n}\n\n/**\n * A trimmed, non-empty string.\n *\n * Trimming happens before the emptiness check, so a field holding only spaces\n * fails rather than passing as \"filled\".\n */\nexport function requiredText({\n requiredMessage = 'This field is required.',\n}: TextFieldOptions = {}) {\n return z.string().trim().min(1, { message: requiredMessage });\n}\n\nexport interface EmailFieldOptions extends TextFieldOptions {\n /** Message shown when the value is present but not an email address. */\n message?: string;\n /** Allow an empty value. @default false */\n optional?: boolean;\n}\n\n/** An email address. Trimmed, and empty-tolerant when `optional`. */\nexport function emailField({\n requiredMessage = 'Email address is required.',\n message = 'Enter a valid email address.',\n optional = false,\n}: EmailFieldOptions = {}) {\n const base = z.string().trim();\n\n if (optional) {\n return base.refine((value) => value === '' || z.string().email().safeParse(value).success, {\n message,\n });\n }\n\n return base.min(1, { message: requiredMessage }).email({ message });\n}\n\nexport interface UsPhoneFieldOptions extends TextFieldOptions {\n /** Message shown when the value is present but not ten digits. */\n message?: string;\n /** Require a value. @default false — phone is usually a secondary channel. */\n required?: boolean;\n}\n\n/**\n * A US (NANP) phone number, counted in digits rather than matched by shape.\n *\n * Accepts anything `PhoneInput` can produce or a human can paste:\n * `(555) 123-4567`, `555-123-4567`, `5551234567`, `+1 555 123 4567`. What it\n * checks is that exactly ten digits are present, which is the only part that\n * carries meaning — `PhoneInput` already owns the presentation.\n */\nexport function usPhoneField({\n requiredMessage = 'Phone number is required.',\n message = 'Enter a 10-digit US phone number.',\n required = false,\n}: UsPhoneFieldOptions = {}) {\n const base = z.string().trim();\n const hasTenDigits = (value: string) => parseUsPhoneDigits(value).length === 10;\n\n if (required) {\n return base.min(1, { message: requiredMessage }).refine(hasTenDigits, { message });\n }\n\n return base.refine((value) => value === '' || hasTenDigits(value), { message });\n}\n"],"mappings":";;AAAA,MAAM,mBAAmB;;;;;;;;;AAUzB,SAAgB,mBAAmB,OAAuB;CACxD,MAAM,SAAS,MAAM,QAAQ,OAAO,GAAG;AAEvC,SADiB,OAAO,SAAS,oBAAoB,OAAO,WAAW,IAAI,GAAG,OAAO,MAAM,EAAE,GAAG,QAChF,MAAM,GAAG,iBAAiB;;;AAI5C,SAAgB,cAAc,OAAuB;CACnD,MAAM,IAAI,mBAAmB,MAAM;AACnC,KAAI,EAAE,UAAU,EAAG,QAAO;AAC1B,KAAI,EAAE,UAAU,EAAG,QAAO,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE;AAC1D,QAAO,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;ACY1D,SAAgB,aAAa,EAC3B,kBAAkB,8BACE,EAAE,EAAE;AACxB,QAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,SAAS,iBAAiB,CAAC;;;AAW/D,SAAgB,WAAW,EACzB,kBAAkB,8BAClB,UAAU,gCACV,WAAW,UACU,EAAE,EAAE;CACzB,MAAM,OAAO,EAAE,QAAQ,CAAC,MAAM;AAE9B,KAAI,SACF,QAAO,KAAK,QAAQ,UAAU,UAAU,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,MAAM,CAAC,SAAS,EACzF,SACD,CAAC;AAGJ,QAAO,KAAK,IAAI,GAAG,EAAE,SAAS,iBAAiB,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC;;;;;;;;;;AAkBrE,SAAgB,aAAa,EAC3B,kBAAkB,6BAClB,UAAU,qCACV,WAAW,UACY,EAAE,EAAE;CAC3B,MAAM,OAAO,EAAE,QAAQ,CAAC,MAAM;CAC9B,MAAM,gBAAgB,UAAkB,mBAAmB,MAAM,CAAC,WAAW;AAE7E,KAAI,SACF,QAAO,KAAK,IAAI,GAAG,EAAE,SAAS,iBAAiB,CAAC,CAAC,OAAO,cAAc,EAAE,SAAS,CAAC;AAGpF,QAAO,KAAK,QAAQ,UAAU,UAAU,MAAM,aAAa,MAAM,EAAE,EAAE,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bison-lab/ui",
3
- "version": "3.28.0",
3
+ "version": "3.35.0",
4
4
  "description": "React components, form system, and blocks for Bison Lab component library",
5
5
  "keywords": [
6
6
  "bison-lab",
@@ -67,8 +67,8 @@
67
67
  "sonner": "^2.0.7",
68
68
  "tailwind-merge": "^3.5.0",
69
69
  "zod": "^3.24.0",
70
- "@bison-lab/tokens": "3.27.1",
71
- "@bison-lab/fonts": "3.27.1"
70
+ "@bison-lab/fonts": "3.27.1",
71
+ "@bison-lab/tokens": "3.27.1"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "react": "^18.0.0 || ^19.0.0",