@sybilion/uilib 1.3.104 → 1.3.105
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/esm/components/ui/Chat/ChatMessage/AgentMessageContent.helpers.js +34 -0
- package/dist/esm/components/ui/InteractiveContent/InteractiveContent.styl.js +1 -1
- package/package.json +1 -1
- package/src/components/ui/Chat/ChatMessage/AgentMessageContent.helpers.test.tsx +22 -1
- package/src/components/ui/Chat/ChatMessage/AgentMessageContent.helpers.tsx +40 -0
- package/src/components/ui/InteractiveContent/InteractiveContent.styl +9 -0
- package/src/docs/pages/InteractiveContentPage.tsx +94 -6
|
@@ -26,6 +26,34 @@ const injectHTMLTags = (content) => {
|
|
|
26
26
|
length: matches[0].length,
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
+
const injectHTMLCodeTags = (content) => {
|
|
30
|
+
const regex = /<(code)\s*>([\s\S]*?)<\/\1\s*>/i;
|
|
31
|
+
const matches = content.match(regex);
|
|
32
|
+
if (!matches)
|
|
33
|
+
return null;
|
|
34
|
+
if (isInsideHtmlListOrTable(content, matches.index)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
elem: jsx("code", { children: matches[2] }),
|
|
39
|
+
index: matches.index,
|
|
40
|
+
length: matches[0].length,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const injectBacktickCode = (content) => {
|
|
44
|
+
const regex = /`([^`\n]+?)`/;
|
|
45
|
+
const matches = content.match(regex);
|
|
46
|
+
if (!matches)
|
|
47
|
+
return null;
|
|
48
|
+
if (isInsideHtmlListOrTable(content, matches.index)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
elem: jsx("code", { children: matches[1] }),
|
|
53
|
+
index: matches.index,
|
|
54
|
+
length: matches[0].length,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
29
57
|
const injectBold = (content) => {
|
|
30
58
|
const regex = /\*\*([^*]+?)\*\*/;
|
|
31
59
|
const matches = content.match(regex);
|
|
@@ -296,6 +324,8 @@ const runFormattingPipeline = (text, injectors) => {
|
|
|
296
324
|
};
|
|
297
325
|
const linkLabelInjectors = [
|
|
298
326
|
injectHTMLTags,
|
|
327
|
+
injectHTMLCodeTags,
|
|
328
|
+
injectBacktickCode,
|
|
299
329
|
injectBold,
|
|
300
330
|
injectItalic,
|
|
301
331
|
injectNewlines,
|
|
@@ -427,6 +457,8 @@ const applyFormatting = (text) => runFormattingPipeline(text, [
|
|
|
427
457
|
injectAnchor,
|
|
428
458
|
injectMarkdownLink,
|
|
429
459
|
injectHTMLTags,
|
|
460
|
+
injectHTMLCodeTags,
|
|
461
|
+
injectBacktickCode,
|
|
430
462
|
injectBullet,
|
|
431
463
|
injectBold,
|
|
432
464
|
injectItalic,
|
|
@@ -437,6 +469,8 @@ const applyFormattingInline = (text) => runFormattingPipeline(text, [
|
|
|
437
469
|
injectAnchor,
|
|
438
470
|
injectMarkdownLink,
|
|
439
471
|
injectHTMLTags,
|
|
472
|
+
injectHTMLCodeTags,
|
|
473
|
+
injectBacktickCode,
|
|
440
474
|
injectBold,
|
|
441
475
|
injectItalic,
|
|
442
476
|
injectAutolinkUrl,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import styleInject from 'style-inject';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".InteractiveContent_root__FHnlY{box-sizing:border-box;display:inline-block;max-width:100%;min-width:0;overflow-wrap:anywhere;word-break:break-word}.InteractiveContent_root__FHnlY strong{font-weight:600}.InteractiveContent_root__FHnlY em{font-style:italic}.InteractiveContent_textLink__Ubh4i{color:var(--sb-green-600);text-decoration:underline;text-underline-offset:2px}.InteractiveContent_textLink__Ubh4i:hover{color:var(--sb-green-700)}.dark .InteractiveContent_textLink__Ubh4i{color:var(--sb-green-400)}.dark .InteractiveContent_textLink__Ubh4i:hover{color:var(--sb-green-300)}.InteractiveContent_autolinkUrl__W0tQH{align-items:center;border-radius:var(--p-2);box-sizing:border-box;color:var(--link-color);display:inline-flex;font-size:var(--text-xs);gap:6px;line-height:1.4;margin:0 1px;max-width:100%;padding:2px 8px 2px 6px;position:relative;text-decoration:none;vertical-align:middle}.InteractiveContent_autolinkUrl__W0tQH:before{background-color:var(--link-color);border-radius:inherit;content:\"\";display:inline-block;height:100%;left:0;opacity:.1;position:absolute;top:0;width:100%}.InteractiveContent_autolinkUrl__W0tQH:hover:before{opacity:.2}.InteractiveContent_autolinkUrlIcon__QoqlQ{flex-shrink:0}.InteractiveContent_autolinkUrlLabel__CcJOG{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}";
|
|
3
|
+
var css_248z = ".InteractiveContent_root__FHnlY{box-sizing:border-box;display:inline-block;max-width:100%;min-width:0;overflow-wrap:anywhere;word-break:break-word}.InteractiveContent_root__FHnlY strong{font-weight:600}.InteractiveContent_root__FHnlY em{font-style:italic}.InteractiveContent_root__FHnlY code{background-color:var(--background);border-radius:var(--p-1);box-shadow:0 0 1px var(--foreground);color:var(--foreground);font-family:ui-monospace,SF Mono,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:.875em;padding:.2em .35em}.InteractiveContent_textLink__Ubh4i{color:var(--sb-green-600);text-decoration:underline;text-underline-offset:2px}.InteractiveContent_textLink__Ubh4i:hover{color:var(--sb-green-700)}.dark .InteractiveContent_textLink__Ubh4i{color:var(--sb-green-400)}.dark .InteractiveContent_textLink__Ubh4i:hover{color:var(--sb-green-300)}.InteractiveContent_autolinkUrl__W0tQH{align-items:center;border-radius:var(--p-2);box-sizing:border-box;color:var(--link-color);display:inline-flex;font-size:var(--text-xs);gap:6px;line-height:1.4;margin:0 1px;max-width:100%;padding:2px 8px 2px 6px;position:relative;text-decoration:none;vertical-align:middle}.InteractiveContent_autolinkUrl__W0tQH:before{background-color:var(--link-color);border-radius:inherit;content:\"\";display:inline-block;height:100%;left:0;opacity:.1;position:absolute;top:0;width:100%}.InteractiveContent_autolinkUrl__W0tQH:hover:before{opacity:.2}.InteractiveContent_autolinkUrlIcon__QoqlQ{flex-shrink:0}.InteractiveContent_autolinkUrlLabel__CcJOG{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}";
|
|
4
4
|
var S = {"root":"InteractiveContent_root__FHnlY","textLink":"InteractiveContent_textLink__Ubh4i","autolinkUrl":"InteractiveContent_autolinkUrl__W0tQH","autolinkUrlIcon":"InteractiveContent_autolinkUrlIcon__QoqlQ","autolinkUrlLabel":"InteractiveContent_autolinkUrlLabel__CcJOG"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { render } from '@testing-library/react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
applyFormatting,
|
|
5
|
+
applyFormattingInline,
|
|
6
|
+
} from './AgentMessageContent.helpers';
|
|
4
7
|
|
|
5
8
|
function renderFormatting(text: string) {
|
|
6
9
|
const parts = applyFormatting(text);
|
|
@@ -24,6 +27,24 @@ describe('applyFormatting emphasis', () => {
|
|
|
24
27
|
});
|
|
25
28
|
});
|
|
26
29
|
|
|
30
|
+
describe('applyFormattingInline code', () => {
|
|
31
|
+
it('renders HTML code tags', () => {
|
|
32
|
+
const parts = applyFormattingInline(
|
|
33
|
+
'Restored <code>?prompt=</code> URLs for deep links.',
|
|
34
|
+
);
|
|
35
|
+
const { container } = render(<>{parts}</>);
|
|
36
|
+
|
|
37
|
+
expect(container.querySelector('code')?.textContent).toBe('?prompt=');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('renders backtick inline code', () => {
|
|
41
|
+
const parts = applyFormattingInline('Use `?prompt=` in the query string.');
|
|
42
|
+
const { container } = render(<>{parts}</>);
|
|
43
|
+
|
|
44
|
+
expect(container.querySelector('code')?.textContent).toBe('?prompt=');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
27
48
|
describe('applyFormatting headers', () => {
|
|
28
49
|
it('renders bold inside markdown headers', () => {
|
|
29
50
|
const { container } = renderFormatting(
|
|
@@ -43,6 +43,40 @@ const injectHTMLTags = (content: string) => {
|
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
const injectHTMLCodeTags = (content: string) => {
|
|
47
|
+
const regex = /<(code)\s*>([\s\S]*?)<\/\1\s*>/i;
|
|
48
|
+
const matches = content.match(regex);
|
|
49
|
+
|
|
50
|
+
if (!matches) return null;
|
|
51
|
+
|
|
52
|
+
if (isInsideHtmlListOrTable(content, matches.index!)) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
elem: <code>{matches[2]}</code>,
|
|
58
|
+
index: matches.index!,
|
|
59
|
+
length: matches[0].length,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const injectBacktickCode = (content: string) => {
|
|
64
|
+
const regex = /`([^`\n]+?)`/;
|
|
65
|
+
const matches = content.match(regex);
|
|
66
|
+
|
|
67
|
+
if (!matches) return null;
|
|
68
|
+
|
|
69
|
+
if (isInsideHtmlListOrTable(content, matches.index!)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
elem: <code>{matches[1]}</code>,
|
|
75
|
+
index: matches.index!,
|
|
76
|
+
length: matches[0].length,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
46
80
|
const injectBold = (content: string) => {
|
|
47
81
|
const regex = /\*\*([^*]+?)\*\*/;
|
|
48
82
|
const matches = content.match(regex);
|
|
@@ -371,6 +405,8 @@ const runFormattingPipeline = (
|
|
|
371
405
|
|
|
372
406
|
const linkLabelInjectors: Injector[] = [
|
|
373
407
|
injectHTMLTags,
|
|
408
|
+
injectHTMLCodeTags,
|
|
409
|
+
injectBacktickCode,
|
|
374
410
|
injectBold,
|
|
375
411
|
injectItalic,
|
|
376
412
|
injectNewlines,
|
|
@@ -571,6 +607,8 @@ const applyFormatting = (text: string): React.ReactNode[] =>
|
|
|
571
607
|
injectAnchor,
|
|
572
608
|
injectMarkdownLink,
|
|
573
609
|
injectHTMLTags,
|
|
610
|
+
injectHTMLCodeTags,
|
|
611
|
+
injectBacktickCode,
|
|
574
612
|
injectBullet,
|
|
575
613
|
injectBold,
|
|
576
614
|
injectItalic,
|
|
@@ -583,6 +621,8 @@ const applyFormattingInline = (text: string): React.ReactNode[] =>
|
|
|
583
621
|
injectAnchor,
|
|
584
622
|
injectMarkdownLink,
|
|
585
623
|
injectHTMLTags,
|
|
624
|
+
injectHTMLCodeTags,
|
|
625
|
+
injectBacktickCode,
|
|
586
626
|
injectBold,
|
|
587
627
|
injectItalic,
|
|
588
628
|
injectAutolinkUrl,
|
|
@@ -12,6 +12,15 @@
|
|
|
12
12
|
em
|
|
13
13
|
font-style italic
|
|
14
14
|
|
|
15
|
+
code
|
|
16
|
+
font-family ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Monaco, Consolas, monospace
|
|
17
|
+
font-size 0.875em
|
|
18
|
+
padding 0.2em 0.35em
|
|
19
|
+
border-radius var(--p-1)
|
|
20
|
+
background-color var(--background)
|
|
21
|
+
color var(--foreground)
|
|
22
|
+
box-shadow 0 0 1px var(--foreground)
|
|
23
|
+
|
|
15
24
|
.textLink
|
|
16
25
|
color var(--sb-green-600)
|
|
17
26
|
text-decoration underline
|
|
@@ -5,8 +5,59 @@ import { AppPageHeader } from '../components/AppPageHeader/AppPageHeader';
|
|
|
5
5
|
import { DocsGuidance } from '../components/DocsGuidance/DocsGuidance';
|
|
6
6
|
import { DocsHeaderActions } from '../docsHeaderActions';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
type ShowcaseRow = {
|
|
9
|
+
label: string;
|
|
10
|
+
source: string;
|
|
11
|
+
variant?: 'full' | 'inline';
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const SHOWCASE_ROWS: ShowcaseRow[] = [
|
|
15
|
+
{
|
|
16
|
+
label: 'Bold (markdown)',
|
|
17
|
+
source: 'Use **bold** for emphasis.',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: 'Bold (HTML)',
|
|
21
|
+
source: 'Use <strong>bold</strong> for emphasis.',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: 'Italic (markdown)',
|
|
25
|
+
source: 'Use *italic* or _italic_ for emphasis.',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: 'Code (HTML)',
|
|
29
|
+
source: 'Restored <code>?prompt=</code> URLs for chat deep links.',
|
|
30
|
+
variant: 'inline',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
label: 'Code (backticks)',
|
|
34
|
+
source: 'Pass `?prompt=` in the query string.',
|
|
35
|
+
variant: 'inline',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: 'Markdown link',
|
|
39
|
+
source: 'Read the [release notes](/releases) for details.',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
label: 'HTML link',
|
|
43
|
+
source: 'Read the <a href="/releases">release notes</a> for details.',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
label: 'Autolink URL',
|
|
47
|
+
source: 'See https://example.com/docs for more context.',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
label: 'Combined inline',
|
|
51
|
+
source:
|
|
52
|
+
'<strong>Chat deep links.</strong> Restored <code>?prompt=</code> URLs. See https://example.com/help.',
|
|
53
|
+
variant: 'inline',
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const FULL_VARIANT_SAMPLE = `# Section title
|
|
58
|
+
|
|
59
|
+
- **First item.** With *italic* detail.
|
|
60
|
+
- Second item with \`inline code\` and a [link](/settings).`;
|
|
10
61
|
|
|
11
62
|
export default function InteractiveContentPage() {
|
|
12
63
|
return (
|
|
@@ -18,9 +69,10 @@ export default function InteractiveContentPage() {
|
|
|
18
69
|
actions={<DocsHeaderActions />}
|
|
19
70
|
/>
|
|
20
71
|
<DocsGuidance
|
|
21
|
-
overview="InteractiveContent renders assistant-style plain text with inline formatting
|
|
72
|
+
overview="InteractiveContent renders assistant-style plain text with inline formatting: bold and italic emphasis, inline code via <code> tags or backticks, markdown and HTML links, and bare URLs converted into clickable links. The inline variant omits block-level features such as headings and markdown bullets."
|
|
22
73
|
whenToUse={[
|
|
23
74
|
'To display assistant or model-generated text that may contain markdown emphasis and raw URLs.',
|
|
75
|
+
'For release note bullets and other compact labels that need lightweight inline formatting.',
|
|
24
76
|
'When plain text needs lightweight formatting without a full markdown renderer.',
|
|
25
77
|
]}
|
|
26
78
|
whenNotToUse={[
|
|
@@ -28,11 +80,47 @@ export default function InteractiveContentPage() {
|
|
|
28
80
|
'For static UI copy that needs no formatting; render the text directly.',
|
|
29
81
|
]}
|
|
30
82
|
doNotes={[
|
|
31
|
-
'Use the inline variant when the text sits inside a sentence or compact label.',
|
|
83
|
+
'Use the inline variant when the text sits inside a sentence, list item, or compact label.',
|
|
84
|
+
'In release notes markdown, write list bullets as "- item text" in the source file; the parser strips the leading "- " and renders each item inside a list — do not repeat "- " inside the item string.',
|
|
85
|
+
'Wrap inline code with <code>…</code> or backticks (`…`); both render as monospace code.',
|
|
32
86
|
]}
|
|
33
87
|
/>
|
|
34
|
-
<PageContentSection
|
|
35
|
-
|
|
88
|
+
<PageContentSection
|
|
89
|
+
style={{ display: 'flex', flexDirection: 'column', gap: '1.5rem' }}
|
|
90
|
+
>
|
|
91
|
+
{SHOWCASE_ROWS.map(row => (
|
|
92
|
+
<section key={row.label}>
|
|
93
|
+
<h3 style={{ marginBottom: '0.5rem', fontSize: '0.875rem' }}>
|
|
94
|
+
{row.label}
|
|
95
|
+
</h3>
|
|
96
|
+
<p
|
|
97
|
+
style={{
|
|
98
|
+
margin: '0 0 0.5rem',
|
|
99
|
+
fontSize: '0.75rem',
|
|
100
|
+
color: 'var(--muted-foreground)',
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
<code>{row.source}</code>
|
|
104
|
+
</p>
|
|
105
|
+
<InteractiveContent text={row.source} variant={row.variant} />
|
|
106
|
+
</section>
|
|
107
|
+
))}
|
|
108
|
+
</PageContentSection>
|
|
109
|
+
<PageContentSection
|
|
110
|
+
style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem' }}
|
|
111
|
+
>
|
|
112
|
+
<h3 style={{ fontSize: '0.875rem' }}>Full variant (default)</h3>
|
|
113
|
+
<p
|
|
114
|
+
style={{
|
|
115
|
+
margin: 0,
|
|
116
|
+
fontSize: '0.75rem',
|
|
117
|
+
color: 'var(--muted-foreground)',
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
Supports headings, markdown bullets (<code>- item</code>), and the
|
|
121
|
+
same inline formats.
|
|
122
|
+
</p>
|
|
123
|
+
<InteractiveContent text={FULL_VARIANT_SAMPLE} />
|
|
36
124
|
</PageContentSection>
|
|
37
125
|
</>
|
|
38
126
|
);
|