@tristan2828/ui-foundation 4.70.0 → 4.72.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.
@@ -32,3 +32,43 @@ export function linkHref(typed) {
32
32
  export function linkRefusal(typed) {
33
33
  return /\s/.test(typed.trim()) ? 'whitespace' : 'scheme';
34
34
  }
35
+ /**
36
+ * The rule for a link field, shaped as a schema (`safeParse`): what was
37
+ * typed becomes the address to save (`linkHref`: `example.com` gains
38
+ * https://), or `null` for a blank box; another scheme (`javascript:`) or
39
+ * a space inside the address is refused with the words to show. LinkCell
40
+ * and the `inPlace.link` preset check with it.
41
+ */
42
+ export const linkRule = {
43
+ safeParse(value) {
44
+ const typed = String(value ?? '');
45
+ const href = linkHref(typed);
46
+ if (href === '')
47
+ return { success: true, data: null };
48
+ if (href === null) {
49
+ const message = linkRefusal(typed) === 'whitespace' ? 'An address has no spaces' : 'Use a web or email address';
50
+ return { success: false, error: { issues: [{ message }] } };
51
+ }
52
+ return { success: true, data: href };
53
+ },
54
+ };
55
+ /**
56
+ * A link's text when it has no label of its own: the host of a web
57
+ * address (`docs.example.com`), the address of an email link, the path
58
+ * of a link on this site. `href` is one `linkHref` returned.
59
+ */
60
+ export function linkHost(href) {
61
+ if (/^mailto:/i.test(href))
62
+ return href.slice('mailto:'.length);
63
+ if (/^tel:/i.test(href))
64
+ return href.slice('tel:'.length);
65
+ if (/^https?:\/\//i.test(href)) {
66
+ try {
67
+ return new URL(href).host;
68
+ }
69
+ catch {
70
+ return href.replace(/^https?:\/\//i, '');
71
+ }
72
+ }
73
+ return href;
74
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.70.0",
3
+ "version": "4.72.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {