@stack-spot/ai-chat-widget 0.9.0 → 0.10.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Code.d.ts","sourceRoot":"","sources":["../../src/components/Code.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAI3C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC,MAAM,MAAM,UAAU,GAAG,CACvB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,KACb,IAAI,CAAA;AAET,KAAK,SAAS,GAAG,KAAK,CAAC,eAAe,CAAC,WAAW,CAAC,GAC/C,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,GACjC,UAAU,GACV;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE1B,MAAM,WAAW,KAAM,SAAQ,YAAY;IACzC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA6DD,eAAO,MAAM,IAAI,oGASd,IAAI,CAAC,SAAS,EAAE,WAAW,GAAG,WAAW,CAAC,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"Code.d.ts","sourceRoot":"","sources":["../../src/components/Code.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAI3C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC,MAAM,MAAM,UAAU,GAAG,CACvB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,KACb,IAAI,CAAA;AAET,KAAK,SAAS,GAAG,KAAK,CAAC,eAAe,CAAC,WAAW,CAAC,GAC/C,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,GACjC,UAAU,GACV;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE1B,MAAM,WAAW,KAAM,SAAQ,YAAY;IACzC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA6DD,eAAO,MAAM,IAAI,oGASd,IAAI,CAAC,SAAS,EAAE,WAAW,GAAG,WAAW,CAAC,GAAG,KAAK,4CA+FpD,CAAA"}
|
package/dist/components/Code.js
CHANGED
|
@@ -2,10 +2,11 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
/**
|
|
3
3
|
* Copied from the extension's webview.
|
|
4
4
|
*/
|
|
5
|
-
import { AddCode, ChevronDoubleDown, Copy } from '@citric/icons';
|
|
5
|
+
import { AddCode, ChevronDoubleDown, Collapse, Copy } from '@citric/icons';
|
|
6
6
|
import { IconButton } from '@citric/ui';
|
|
7
7
|
import { theme, useThemeKind } from '@stack-spot/portal-theme';
|
|
8
8
|
import { useTranslate } from '@stack-spot/portal-translate';
|
|
9
|
+
import { useState } from 'react';
|
|
9
10
|
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
10
11
|
import { materialDark, vs } from 'react-syntax-highlighter/dist/esm/styles/prism/index.js';
|
|
11
12
|
import styled from 'styled-components';
|
|
@@ -69,6 +70,7 @@ const lineNumbersStyle = {
|
|
|
69
70
|
export const Code = ({ className, onInsertCode, onNewFile, onCopyCode, language, children, showActionBar, ...props }) => {
|
|
70
71
|
const t = useTranslate(dictionary);
|
|
71
72
|
const themeKind = useThemeKind();
|
|
73
|
+
const [showLines, setShowLines] = useState(true);
|
|
72
74
|
const match = /language-(\w+)/.exec(className || '');
|
|
73
75
|
const computedLanguage = language ?? (match ?? [])[1]?.toLowerCase() ?? 'txt';
|
|
74
76
|
const content = String(children ?? '').replaceAll(/\n\t/g, '\n').trim();
|
|
@@ -91,22 +93,26 @@ export const Code = ({ className, onInsertCode, onNewFile, onCopyCode, language,
|
|
|
91
93
|
if (!(/language-(\w+)/.exec(className || ''))) {
|
|
92
94
|
return (_jsx("code", { ...props, className: className, children: children }));
|
|
93
95
|
}
|
|
94
|
-
return (_jsxs(CodeBox, { className: ['code-box', themeKind].join(' '), children: [showActionBar && (_jsxs("div", { className: "action-bar", role: "toolbar", children: [_jsx(IconButton, { "aria-label": t.copy, title: t.copy, onClick: onClickCopy, style: { position: 'relative' }, children: _jsx(Copy, {}) }), onInsertCode
|
|
96
|
+
return (_jsxs(CodeBox, { className: ['code-box', themeKind].join(' '), children: [showActionBar && (_jsxs("div", { className: "action-bar", role: "toolbar", children: [_jsx(IconButton, { "aria-label": showLines ? t.hideLines : t.showLines, title: showLines ? t.hideLines : t.showLines, onClick: () => setShowLines(v => !v), style: { position: 'relative', transform: showLines ? undefined : 'rotate(180deg)', transition: 'transform 0.2s' }, children: _jsx(Collapse, {}) }), _jsx(IconButton, { "aria-label": t.copy, title: t.copy, onClick: onClickCopy, style: { position: 'relative' }, children: _jsx(Copy, {}) }), onInsertCode
|
|
95
97
|
? (_jsx(IconButton, { "aria-label": t.insert, title: t.insert, onClick: onClickInsert, style: { position: 'relative' }, children: _jsx(ChevronDoubleDown, { style: { transform: 'rotate(90deg)' } }) }))
|
|
96
98
|
: null, onNewFile
|
|
97
99
|
? (_jsx(IconButton, { "aria-label": t.newFile, title: t.newFile, onClick: onClickNewFile, style: { position: 'relative' }, children: _jsx(AddCode, {}) }))
|
|
98
|
-
: null] })), _jsx("div", { children: _jsx(SyntaxHighlighter, { ...props, className: "highlighter", style: themeKind === 'dark' ? materialDark : vs, language: computedLanguage, PreTag: "div", showLineNumbers:
|
|
100
|
+
: null] })), _jsx("div", { children: _jsx(SyntaxHighlighter, { ...props, className: "highlighter", style: themeKind === 'dark' ? materialDark : vs, language: computedLanguage, PreTag: "div", showLineNumbers: showLines, lineNumberContainerStyle: lineNumbersStyle, lineNumberStyle: lineNumbersStyle, children: content }) })] }));
|
|
99
101
|
};
|
|
100
102
|
const dictionary = {
|
|
101
103
|
en: {
|
|
102
104
|
copy: 'Copy code to the clipboard',
|
|
103
105
|
insert: 'Inject code into editor',
|
|
104
106
|
newFile: 'Creates a new file with this code as its content',
|
|
107
|
+
hideLines: 'Hide line numbers',
|
|
108
|
+
showLines: 'Show line numbers',
|
|
105
109
|
},
|
|
106
110
|
pt: {
|
|
107
111
|
copy: 'Copiar código para a área de transferência',
|
|
108
112
|
insert: 'Inserir código no editor',
|
|
109
113
|
newFile: 'Criar um novo arquivo com este código como conteúdo',
|
|
114
|
+
hideLines: 'Esconder números das linhas',
|
|
115
|
+
showLines: 'Mostrar números das linhas',
|
|
110
116
|
},
|
|
111
117
|
};
|
|
112
118
|
//# sourceMappingURL=Code.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Code.js","sourceRoot":"","sources":["../../src/components/Code.tsx"],"names":[],"mappings":";AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"Code.js","sourceRoot":"","sources":["../../src/components/Code.tsx"],"names":[],"mappings":";AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAc,YAAY,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAiB,QAAQ,EAAE,MAAM,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9B,SAAS,EAAE,mBAAmB;KAC/B;IACD,EAAE,EAAE;QACF,IAAI,EAAE,4CAA4C;QAClD,MAAM,EAAE,0BAA0B;QAClC,OAAO,EAAE,qDAAqD;QAC9D,SAAS,EAAE,6BAA6B;QACxC,SAAS,EAAE,4BAA4B;KACxC;CACmB,CAAA"}
|
package/package.json
CHANGED
package/src/components/Code.tsx
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Copied from the extension's webview.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { AddCode, ChevronDoubleDown, Copy } from '@citric/icons'
|
|
5
|
+
import { AddCode, ChevronDoubleDown, Collapse, Copy } from '@citric/icons'
|
|
6
6
|
import { IconButton } from '@citric/ui'
|
|
7
7
|
import { theme, useThemeKind } from '@stack-spot/portal-theme'
|
|
8
8
|
import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
|
|
9
|
-
import { CSSProperties } from 'react'
|
|
9
|
+
import { CSSProperties, useState } from 'react'
|
|
10
10
|
import { ExtraProps } from 'react-markdown'
|
|
11
11
|
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
|
|
12
12
|
import { materialDark, vs } from 'react-syntax-highlighter/dist/esm/styles/prism'
|
|
@@ -102,6 +102,7 @@ export const Code = ({
|
|
|
102
102
|
}: Pick<CodeProps, 'className' | 'messageId'> & Props) => {
|
|
103
103
|
const t = useTranslate(dictionary)
|
|
104
104
|
const themeKind = useThemeKind()
|
|
105
|
+
const [showLines, setShowLines] = useState(true)
|
|
105
106
|
const match = /language-(\w+)/.exec(className || '')
|
|
106
107
|
const computedLanguage = language ?? (match ?? [])[1]?.toLowerCase() ?? 'txt'
|
|
107
108
|
const content = String(children ?? '').replaceAll(/\n\t/g, '\n').trim()
|
|
@@ -135,6 +136,14 @@ export const Code = ({
|
|
|
135
136
|
<CodeBox className={['code-box', themeKind].join(' ')}>
|
|
136
137
|
{showActionBar && (
|
|
137
138
|
<div className="action-bar" role="toolbar">
|
|
139
|
+
<IconButton
|
|
140
|
+
aria-label={showLines ? t.hideLines : t.showLines}
|
|
141
|
+
title={showLines ? t.hideLines : t.showLines}
|
|
142
|
+
onClick={() => setShowLines(v => !v)}
|
|
143
|
+
style={{ position: 'relative', transform: showLines ? undefined : 'rotate(180deg)', transition: 'transform 0.2s' }}
|
|
144
|
+
>
|
|
145
|
+
<Collapse />
|
|
146
|
+
</IconButton>
|
|
138
147
|
<IconButton
|
|
139
148
|
aria-label={t.copy}
|
|
140
149
|
title={t.copy}
|
|
@@ -176,7 +185,7 @@ export const Code = ({
|
|
|
176
185
|
style={themeKind === 'dark' ? materialDark : vs}
|
|
177
186
|
language={computedLanguage}
|
|
178
187
|
PreTag="div"
|
|
179
|
-
showLineNumbers={
|
|
188
|
+
showLineNumbers={showLines}
|
|
180
189
|
lineNumberContainerStyle={lineNumbersStyle}
|
|
181
190
|
lineNumberStyle={lineNumbersStyle}
|
|
182
191
|
>
|
|
@@ -192,10 +201,14 @@ const dictionary = {
|
|
|
192
201
|
copy: 'Copy code to the clipboard',
|
|
193
202
|
insert: 'Inject code into editor',
|
|
194
203
|
newFile: 'Creates a new file with this code as its content',
|
|
204
|
+
hideLines: 'Hide line numbers',
|
|
205
|
+
showLines: 'Show line numbers',
|
|
195
206
|
},
|
|
196
207
|
pt: {
|
|
197
208
|
copy: 'Copiar código para a área de transferência',
|
|
198
209
|
insert: 'Inserir código no editor',
|
|
199
210
|
newFile: 'Criar um novo arquivo com este código como conteúdo',
|
|
211
|
+
hideLines: 'Esconder números das linhas',
|
|
212
|
+
showLines: 'Mostrar números das linhas',
|
|
200
213
|
},
|
|
201
214
|
} satisfies Dictionary
|