@stll/chat 0.4.2 → 0.4.3
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/dist/link.d.ts +5 -1
- package/dist/link.js +10 -3
- package/package.json +1 -1
package/dist/link.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ type ChatLinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href" | "tar
|
|
|
17
17
|
/** A tray chip whose label is the whole point (a decision's case number and
|
|
18
18
|
* date) keeps it up to the row's width instead of the compact 20ch cap. */
|
|
19
19
|
fullLabel?: boolean | undefined;
|
|
20
|
+
/** What a link whose text is itself a URL shows: the bare host (a chip for
|
|
21
|
+
* a model's cited URL) or the text as written (a URL a person typed, whose
|
|
22
|
+
* path and query are what they meant). */
|
|
23
|
+
urlLabel?: "host" | "written" | undefined;
|
|
20
24
|
};
|
|
21
25
|
/**
|
|
22
26
|
* Gives the link rendered inside it fixed ids, so a surface that renders the
|
|
@@ -28,5 +32,5 @@ export declare const ChatLinkIdScope: ({ children, id }: {
|
|
|
28
32
|
children: ReactNode;
|
|
29
33
|
id: string;
|
|
30
34
|
}) => import("react").JSX.Element;
|
|
31
|
-
export declare const ChatLink: ({ appearance, children, fullLabel, href, iconSource, id, newTabLabel, title, ...anchorProps }: ChatLinkProps) => import("react").JSX.Element;
|
|
35
|
+
export declare const ChatLink: ({ appearance, children, fullLabel, href, iconSource, id, newTabLabel, title, urlLabel, ...anchorProps }: ChatLinkProps) => import("react").JSX.Element;
|
|
32
36
|
export {};
|
package/dist/link.js
CHANGED
|
@@ -47,6 +47,14 @@ const BUNDLED_ICONS = /* @__PURE__ */ new Map([
|
|
|
47
47
|
["www.twitter.com", X_LINK_ICON]
|
|
48
48
|
]);
|
|
49
49
|
const hasBundledChatLinkIcon = (hostname) => BUNDLED_ICONS.has(hostname);
|
|
50
|
+
/**
|
|
51
|
+
* A link's visible label: its own text, unless that text is just a URL a
|
|
52
|
+
* model cited, which shows as the bare host.
|
|
53
|
+
*/
|
|
54
|
+
const linkLabel = (children, hostname, urlLabel) => {
|
|
55
|
+
const text = linkText(children).trim();
|
|
56
|
+
return text && (urlLabel === "written" || normalizeChatLink(text) === null) ? children : hostname.replace(/^www\./u, "");
|
|
57
|
+
};
|
|
50
58
|
const ChatLinkIdContext = createContext(void 0);
|
|
51
59
|
/**
|
|
52
60
|
* Gives the link rendered inside it fixed ids, so a surface that renders the
|
|
@@ -74,7 +82,7 @@ const LinkHint = ({ children, hint, hintId, id }) => hint ? /* @__PURE__ */ jsxs
|
|
|
74
82
|
id: hintId,
|
|
75
83
|
children: hint
|
|
76
84
|
})] }) : children;
|
|
77
|
-
const ChatLink = ({ appearance = "inline", children, fullLabel = false, href, iconSource, id, newTabLabel, title, ...anchorProps }) => {
|
|
85
|
+
const ChatLink = ({ appearance = "inline", children, fullLabel = false, href, iconSource, id, newTabLabel, title, urlLabel = "host", ...anchorProps }) => {
|
|
78
86
|
const hint = newTabLabel ?? title;
|
|
79
87
|
const generatedId = useId();
|
|
80
88
|
const baseId = use(ChatLinkIdContext) ?? generatedId;
|
|
@@ -114,8 +122,7 @@ const ChatLink = ({ appearance = "inline", children, fullLabel = false, href, ic
|
|
|
114
122
|
})
|
|
115
123
|
});
|
|
116
124
|
}
|
|
117
|
-
const
|
|
118
|
-
const label = text && normalizeChatLink(text) === null ? children : target.hostname.replace(/^www\./u, "");
|
|
125
|
+
const label = linkLabel(children, target.hostname, urlLabel);
|
|
119
126
|
let icon = /* @__PURE__ */ jsx(GlobeIcon, {
|
|
120
127
|
"aria-hidden": "true",
|
|
121
128
|
className: "size-[1em]"
|