@tensorpass/aiconnect-react 0.1.6 → 0.1.8
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/index.d.ts +2 -1
- package/dist/index.js.map +1 -1
- package/dist/moduleMessages.d.ts +22 -0
- package/dist/moduleMessages.js +110 -0
- package/dist/moduleMessages.js.map +1 -1
- package/dist/modules/AiSearch.js +16 -5
- package/dist/modules/AiSearch.js.map +1 -1
- package/dist/modules/parts/ChatFrame.d.ts +1 -1
- package/dist/modules/parts/ChatFrame.js +11 -2
- package/dist/modules/parts/ChatFrame.js.map +1 -1
- package/dist/modules/parts/Composer.d.ts +9 -2
- package/dist/modules/parts/Composer.js +49 -12
- package/dist/modules/parts/Composer.js.map +1 -1
- package/dist/modules/parts/Conversation.js +14 -11
- package/dist/modules/parts/Conversation.js.map +1 -1
- package/dist/modules/parts/attachments/AttachButton.d.ts +5 -0
- package/dist/modules/parts/attachments/AttachButton.js +29 -0
- package/dist/modules/parts/attachments/AttachButton.js.map +1 -0
- package/dist/modules/parts/attachments/AttachmentChip.d.ts +12 -0
- package/dist/modules/parts/attachments/AttachmentChip.js +17 -0
- package/dist/modules/parts/attachments/AttachmentChip.js.map +1 -0
- package/dist/modules/parts/attachments/AttachmentRows.d.ts +11 -0
- package/dist/modules/parts/attachments/AttachmentRows.js +29 -0
- package/dist/modules/parts/attachments/AttachmentRows.js.map +1 -0
- package/dist/modules/parts/attachments/DropZone.d.ts +8 -0
- package/dist/modules/parts/attachments/DropZone.js +57 -0
- package/dist/modules/parts/attachments/DropZone.js.map +1 -0
- package/dist/modules/parts/attachments/Lightbox.d.ts +10 -0
- package/dist/modules/parts/attachments/Lightbox.js +43 -0
- package/dist/modules/parts/attachments/Lightbox.js.map +1 -0
- package/dist/modules/parts/attachments/attachmentList.d.ts +25 -0
- package/dist/modules/parts/attachments/attachmentList.js +26 -0
- package/dist/modules/parts/attachments/attachmentList.js.map +1 -0
- package/dist/modules/parts/attachments/fileSize.d.ts +1 -0
- package/dist/modules/parts/attachments/fileSize.js +14 -0
- package/dist/modules/parts/attachments/fileSize.js.map +1 -0
- package/dist/modules/parts/attachments/useAttachments.d.ts +13 -0
- package/dist/modules/parts/attachments/useAttachments.js +77 -0
- package/dist/modules/parts/attachments/useAttachments.js.map +1 -0
- package/dist/modules/parts/dictation/DictationBar.d.ts +4 -0
- package/dist/modules/parts/dictation/DictationBar.js +26 -0
- package/dist/modules/parts/dictation/DictationBar.js.map +1 -0
- package/dist/modules/parts/dictation/MicButton.d.ts +5 -0
- package/dist/modules/parts/dictation/MicButton.js +20 -0
- package/dist/modules/parts/dictation/MicButton.js.map +1 -0
- package/dist/modules/parts/dictation/audioCapture.d.ts +7 -0
- package/dist/modules/parts/dictation/audioCapture.js +44 -0
- package/dist/modules/parts/dictation/audioCapture.js.map +1 -0
- package/dist/modules/parts/dictation/browserSpeech.d.ts +37 -0
- package/dist/modules/parts/dictation/browserSpeech.js +32 -0
- package/dist/modules/parts/dictation/browserSpeech.js.map +1 -0
- package/dist/modules/parts/dictation/dictationLanguage.d.ts +2 -0
- package/dist/modules/parts/dictation/dictationLanguage.js +15 -0
- package/dist/modules/parts/dictation/dictationLanguage.js.map +1 -0
- package/dist/modules/parts/dictation/pcmWorklet.d.ts +1 -0
- package/dist/modules/parts/dictation/pcmWorklet.js +48 -0
- package/dist/modules/parts/dictation/pcmWorklet.js.map +1 -0
- package/dist/modules/parts/dictation/pcmWorkletUrl.d.ts +1 -0
- package/dist/modules/parts/dictation/pcmWorkletUrl.js +5 -0
- package/dist/modules/parts/dictation/pcmWorkletUrl.js.map +1 -0
- package/dist/modules/parts/dictation/recording.d.ts +19 -0
- package/dist/modules/parts/dictation/recording.js +45 -0
- package/dist/modules/parts/dictation/recording.js.map +1 -0
- package/dist/modules/parts/dictation/useDictation.d.ts +22 -0
- package/dist/modules/parts/dictation/useDictation.js +164 -0
- package/dist/modules/parts/dictation/useDictation.js.map +1 -0
- package/dist/modules/parts/icons.d.ts +5 -0
- package/dist/modules/parts/icons.js +6 -0
- package/dist/modules/parts/icons.js.map +1 -1
- package/dist/modules/parts/moduleAnalytics.d.ts +1 -1
- package/dist/modules/parts/moduleAnalytics.js.map +1 -1
- package/dist/modules/parts/useModuleChat.d.ts +6 -3
- package/dist/modules/parts/useModuleChat.js +20 -16
- package/dist/modules/parts/useModuleChat.js.map +1 -1
- package/dist/modules/types.d.ts +2 -0
- package/dist/modules/types.js +3 -2
- package/dist/modules/types.js.map +1 -1
- package/dist/modules/useOverlay.js +2 -1
- package/dist/modules/useOverlay.js.map +1 -1
- package/dist/styles.css +394 -0
- package/dist/transcriptBudget.d.ts +3 -0
- package/dist/transcriptBudget.js +34 -0
- package/dist/transcriptBudget.js.map +1 -0
- package/dist/useAiChat.d.ts +10 -1
- package/dist/useAiChat.js +30 -9
- package/dist/useAiChat.js.map +1 -1
- package/package.json +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Composer.js","sourceRoot":"","sources":["../../../src/modules/parts/Composer.tsx"],"names":[],"mappings":";AAAA,oGAAoG;AACpG,gEAAgE;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA6B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAa,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAU1D,0DAA0D;AAC1D,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B,sGAAsG;AACtG,gEAAgE;AAChE,MAAM,UAAU,SAAS,CAAC,KAAiC;IACzD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO;IACT,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAC7C,KAAK,CAAC,K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AAC,QAAQ,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,gBAAc,cAAc,CAAC,IAAI,KAC5F,QAAQ,YACZ,KAAC,QAAQ,KAAG,GACL,CACV,IACG,GACD,CACR,CAAC;AACJ,CAAC","sourcesContent":["// The visitor's question box: it grows with the text, sends with Enter (Shift and Enter add a line)\n// and turns its send button into Stop while the answer streams.\n\nimport { useState } from 'react';\nimport type { ChangeEvent, FormEvent, KeyboardEvent, RefObject } from 'react';\nimport { useAiConnect } from '../../AiConnectProvider.tsx';\nimport { SendIcon } from './icons.tsx';\nimport { useActionAttribute } from './moduleAnalytics.ts';\n\nexport interface ComposerProps {\n busy: boolean;\n placeholder: string;\n onSend: (question: string) => void;\n onStop: () => void;\n fieldRef: RefObject<HTMLTextAreaElement | null>;\n}\n\n// The tallest the box grows before it scrolls, in pixels.\nconst MAX_FIELD_HEIGHT = 168;\n\n// Fits the box to its text, rounded up to a whole pixel so a single line never shows a scrollbar, and\n// lets it scroll once the text is taller than the box may grow.\nexport function fitHeight(field: HTMLTextAreaElement | null): void {\n if (!field) {\n return;\n }\n field.style.height = 'auto';\n const needed = Math.ceil(field.scrollHeight);\n field.style.height = `${Math.min(needed, MAX_FIELD_HEIGHT)}px`;\n field.style.overflowY = needed > MAX_FIELD_HEIGHT ? 'auto' : 'hidden';\n}\n\nexport function StopButton({ onStop }: { onStop: () => void }) {\n const { moduleMessages } = useAiConnect();\n return (\n <button type=\"button\" className=\"aic-stop\" onClick={onStop}>\n <i aria-hidden=\"true\" />{moduleMessages.stop}\n </button>\n );\n}\n\n// The text of the question box and its keys: Enter sends unless an answer is streaming, and the box\n// shrinks back once the question is sent.\nfunction useQuestionText({ busy, onSend, fieldRef }: Pick<ComposerProps, 'busy' | 'onSend' | 'fieldRef'>) {\n const [text, setText] = useState('');\n const submit = () => {\n if (busy || !text.trim()) {\n return;\n }\n onSend(text);\n setText('');\n if (fieldRef.current) {\n fieldRef.current.style.height = '';\n fieldRef.current.style.overflowY = '';\n }\n };\n return {\n text,\n onChange: (event: ChangeEvent<HTMLTextAreaElement>) => {\n setText(event.target.value);\n fitHeight(event.target);\n },\n onSubmit: (event: FormEvent) => {\n event.preventDefault();\n submit();\n },\n onKeyDown: (event: KeyboardEvent<HTMLTextAreaElement>) => {\n if (event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing) {\n event.preventDefault();\n submit();\n }\n },\n };\n}\n\nexport function Composer({ busy, placeholder, onSend, onStop, fieldRef }: ComposerProps) {\n const { moduleMessages } = useAiConnect();\n const { text, onChange, onSubmit, onKeyDown } = useQuestionText({ busy, onSend, fieldRef });\n const tracking = useActionAttribute('send');\n return (\n <form className=\"aic-composer\" onSubmit={onSubmit}>\n <div className=\"aic-field\">\n <textarea ref={fieldRef} className=\"aic-field-input\" rows={1} value={text} placeholder={placeholder}\n aria-label={placeholder} onKeyDown={onKeyDown} onChange={onChange} />\n {busy ? <StopButton onStop={onStop} /> : (\n <button type=\"submit\" className=\"aic-send\" disabled={!text.trim()} aria-label={moduleMessages.send}\n {...tracking}>\n <SendIcon />\n </button>\n )}\n </div>\n </form>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Composer.js","sourceRoot":"","sources":["../../../src/modules/parts/Composer.tsx"],"names":[],"mappings":";AAAA,wGAAwG;AACxG,0GAA0G;AAC1G,2GAA2G;AAC3G,+GAA+G;AAE/G,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAI5C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA6B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAAgC,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAkC,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA8B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,0BAA2B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;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AAQ,EAAE,OAAO,EAAE,YAAY,CAAC,WAAW,CAAC,GAAI,EACpE,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAC,SAAS,IAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,KAAK,CAAC,KAAK,EAAE,GAAI,CAAC,CAAC,CAAC,IAAI,EAC1E,IAAI,CAAC,CAAC,CAAC,KAAC,UAAU,IAAC,MAAM,EAAE,MAAM,GAAI,CAAC,CAAC,CAAC,CACvC,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,UAAU,EAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,OAAO,gBAAc,cAAc,CAAC,IAAI,KACjG,QAAQ,YACZ,KAAC,QAAQ,KAAG,GACL,CACV,IACA,CACJ,IACG,IACD,CACR,CAAC;AACJ,CAAC","sourcesContent":["// The visitor's question box: it grows with the text, sends with Enter (Shift and Enter add a line) and\n// turns its send button into Stop while the answer streams. When the site takes attachments, it shows the\n// question's files above the text, takes files pasted into it, and offers the attach button; when the site\n// takes voice, its microphone button turns the box into the dictation bar, whose transcript lands in the text.\n\nimport { useEffect, useState } from 'react';\nimport type { ChangeEvent, ClipboardEvent, FormEvent, KeyboardEvent, RefObject } from 'react';\nimport type { Dictation, ReadableParts } from '@tensorpass/aiconnect';\nimport type { PreparedAttachment } from '@tensorpass/aiconnect/attachments';\nimport { useAiConnect } from '../../AiConnectProvider.tsx';\nimport { AttachButton } from './attachments/AttachButton.tsx';\nimport { ComposerAttachments } from './attachments/AttachmentRows.tsx';\nimport type { Attachments } from './attachments/useAttachments.ts';\nimport { DictationBar } from './dictation/DictationBar.tsx';\nimport { MicButton, useVoiceAvailable } from './dictation/MicButton.tsx';\nimport { useDictation } from './dictation/useDictation.ts';\nimport { SendIcon } from './icons.tsx';\nimport { useActionAttribute } from './moduleAnalytics.ts';\n\nexport interface ComposerProps {\n busy: boolean;\n placeholder: string;\n onSend: (question: string, attachments: PreparedAttachment[]) => void;\n onStop: () => void;\n fieldRef: RefObject<HTMLTextAreaElement | null>;\n // The question's files, when the site takes attachments.\n attachments?: Attachments;\n reads?: ReadableParts;\n // The account's dictation, and whether the site takes voice.\n dictation?: Dictation | null;\n voice?: boolean;\n}\n\n// The tallest the box grows before it scrolls, in pixels.\nconst MAX_FIELD_HEIGHT = 168;\n\n// Fits the box to its text, rounded up to a whole pixel so a single line never shows a scrollbar, and\n// lets it scroll once the text is taller than the box may grow.\nexport function fitHeight(field: HTMLTextAreaElement | null): void {\n if (!field) {\n return;\n }\n field.style.height = 'auto';\n const needed = Math.ceil(field.scrollHeight);\n field.style.height = `${Math.min(needed, MAX_FIELD_HEIGHT)}px`;\n field.style.overflowY = needed > MAX_FIELD_HEIGHT ? 'auto' : 'hidden';\n}\n\nexport function StopButton({ onStop }: { onStop: () => void }) {\n const { moduleMessages } = useAiConnect();\n return (\n <button type=\"button\" className=\"aic-stop\" onClick={onStop}>\n <i aria-hidden=\"true\" />{moduleMessages.stop}\n </button>\n );\n}\n\ntype QuestionTextOptions = Pick<ComposerProps, 'busy' | 'onSend' | 'fieldRef' | 'attachments'>;\n\n// The text of the question box and its keys: Enter sends unless an answer is streaming or a file is still\n// read, and the box shrinks back once the question is sent. A dictation's transcript joins the text.\nfunction useQuestionText({ busy, onSend, fieldRef, attachments }: QuestionTextOptions) {\n const [text, setText] = useState('');\n const ready = attachments?.ready ?? [];\n const canSend = !busy && !attachments?.reading && (Boolean(text.trim()) || ready.length > 0);\n const submit = () => {\n if (!canSend) {\n return;\n }\n onSend(text, ready);\n setText('');\n attachments?.clear();\n if (fieldRef.current) {\n fieldRef.current.style.height = '';\n fieldRef.current.style.overflowY = '';\n }\n };\n return {\n text,\n canSend,\n insert: (words: string) => setText((current) => [current.trimEnd(), words].filter(Boolean).join(' ')),\n onChange: (event: ChangeEvent<HTMLTextAreaElement>) => {\n setText(event.target.value);\n fitHeight(event.target);\n },\n onSubmit: (event: FormEvent) => {\n event.preventDefault();\n submit();\n },\n onKeyDown: (event: KeyboardEvent<HTMLTextAreaElement>) => {\n if (event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing) {\n event.preventDefault();\n submit();\n }\n },\n };\n}\n\n// Files pasted into the box join the question; the pasted text, if any, goes in the box as usual.\nfunction pasteHandler(attachments: Attachments | undefined) {\n return (event: ClipboardEvent<HTMLTextAreaElement>) => {\n const files = [...event.clipboardData.files];\n if (!attachments || files.length === 0) {\n return;\n }\n attachments.add(files);\n if (!event.clipboardData.types.includes('text/plain')) {\n event.preventDefault();\n }\n };\n}\n\nexport function Composer(props: ComposerProps) {\n const { busy, placeholder, onStop, fieldRef, attachments, reads, dictation } = props;\n const { moduleMessages } = useAiConnect();\n const question = useQuestionText(props);\n const voice = useDictation(dictation ?? null, question.insert);\n const voiceOn = useVoiceAvailable(dictation, props.voice);\n const tracking = useActionAttribute('send');\n const dictating = voice.status !== 'idle';\n // Back from the dictation bar, the box takes the focus and the height of its text.\n useEffect(() => {\n if (!dictating && fieldRef.current && fieldRef.current.value) {\n fitHeight(fieldRef.current);\n fieldRef.current.focus();\n }\n }, [dictating, fieldRef]);\n const note = attachments?.note ?? voice.error;\n return (\n <form className=\"aic-composer\" onSubmit={question.onSubmit}>\n {note ? <p className=\"aic-composer-note\" role=\"alert\">{note}</p> : null}\n <div className=\"aic-field\" data-dictating={dictating || undefined}>\n {attachments && reads ? <ComposerAttachments attachments={attachments} reads={reads} /> : null}\n {dictating ? <DictationBar dictation={voice} /> : (\n <>\n {attachments?.policy ? <AttachButton policy={attachments.policy} onFiles={attachments.add} /> : null}\n <textarea ref={fieldRef} className=\"aic-field-input\" name=\"question\" rows={1} dir=\"auto\"\n value={question.text} placeholder={placeholder} aria-label={placeholder} onKeyDown={question.onKeyDown}\n onChange={question.onChange} onPaste={pasteHandler(attachments)} />\n {voiceOn && !busy ? <MicButton onClick={() => void voice.start()} /> : null}\n {busy ? <StopButton onStop={onStop} /> : (\n <button type=\"submit\" className=\"aic-send\" disabled={!question.canSend} aria-label={moduleMessages.send}\n {...tracking}>\n <SendIcon />\n </button>\n )}\n </>\n )}\n </div>\n </form>\n );\n}\n"]}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// The conversation of a chat module. Empty, it shows its heading, the
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// The conversation of a chat module. Empty, it shows its heading, the suggested questions, then the
|
|
3
|
+
// connection step, under the wallet's ring in the full page mode. The step appears once the first wallet
|
|
4
|
+
// check ends, so it comes last and the heading and the questions the page rendered stay in place. Then
|
|
5
|
+
// each turn shows the visitor's question with its files, the site's tools as they run, the answer as it
|
|
6
|
+
// streams and the site's own result cards, and the last answer's error comes with a way to ask again,
|
|
7
|
+
// or, for a TensorPass account without a plan, the offer to subscribe. The view follows the answer down
|
|
8
|
+
// while the visitor stays at the bottom.
|
|
8
9
|
import { useEffect, useRef } from 'react';
|
|
9
10
|
import { useAiConnect } from "../../AiConnectProvider.js";
|
|
10
11
|
import { ConnectRing } from "../../ConnectRing.js";
|
|
11
12
|
import { AnswerText } from "./AnswerText.js";
|
|
13
|
+
import { QuestionAttachments } from "./attachments/AttachmentRows.js";
|
|
12
14
|
import { ConnectStep } from "./ConnectStep.js";
|
|
13
15
|
import { PlanOffer } from "./PlanOffer.js";
|
|
14
16
|
import { useActionAttribute } from "./moduleAnalytics.js";
|
|
@@ -18,9 +20,10 @@ import { ToolActivityList } from "./ToolActivity.js";
|
|
|
18
20
|
const PLAN_INACTIVE = 'plan_inactive';
|
|
19
21
|
// How close to the bottom, in pixels, the visitor counts as following the answer.
|
|
20
22
|
const FOLLOW_DISTANCE = 56;
|
|
21
|
-
function Question({ text }) {
|
|
22
|
-
const { moduleMessages } = useAiConnect();
|
|
23
|
-
|
|
23
|
+
function Question({ text, attachments, unread }) {
|
|
24
|
+
const { moduleMessages, state } = useAiConnect();
|
|
25
|
+
const account = state.status === 'connected' ? state.providerName : '';
|
|
26
|
+
return (_jsxs(_Fragment, { children: [attachments?.length ? _jsx(QuestionAttachments, { attachments: attachments }) : null, text ? (_jsxs("p", { className: "aic-question", dir: "auto", children: [_jsxs("span", { className: "aic-visually-hidden", children: [moduleMessages.question, ": "] }), text] })) : null, unread ? (_jsx("p", { className: "aic-unread", children: moduleMessages.unreadPages.replaceAll('{count}', String(unread)).replaceAll('{account}', account) })) : null] }));
|
|
24
27
|
}
|
|
25
28
|
// What a turn shows under its question: the tools as they run, a thinking line until the first
|
|
26
29
|
// words arrive, the answer, whether the visitor stopped it, and the site's own result cards.
|
|
@@ -64,6 +67,6 @@ export function Conversation({ chat, intro, suggestions, ...view }) {
|
|
|
64
67
|
const logRef = useRef(null);
|
|
65
68
|
const onScroll = useFollowAnswer(logRef, chat);
|
|
66
69
|
const empty = chat.turns.length === 0 && !chat.pendingQuestion;
|
|
67
|
-
return (_jsxs("div", { ref: logRef, className: "aic-log", role: "log", "aria-busy": chat.busy, onScroll: onScroll, children: [empty ? (_jsxs("div", { className: "aic-empty", children: [_jsx("div", { className: "aic-empty-ring", children: _jsx(ConnectRing, { live: false }) }), _jsx("h3", { className: "aic-intro", children: intro }), _jsx(
|
|
70
|
+
return (_jsxs("div", { ref: logRef, className: "aic-log", role: "log", "aria-busy": chat.busy, onScroll: onScroll, children: [empty ? (_jsxs("div", { className: "aic-empty", children: [_jsx("div", { className: "aic-empty-ring", children: _jsx(ConnectRing, { live: false }) }), _jsx("h3", { className: "aic-intro", children: intro }), _jsx(Suggestions, { items: suggestions, onPick: chat.ask }), _jsx(ConnectStep, { pending: false })] })) : null, _jsxs("ol", { className: "aic-turns", children: [chat.turns.map((turn, index) => (_jsxs("li", { className: "aic-turn", children: [_jsx(Question, { text: turn.question, attachments: turn.attachments, unread: turn.unread }), _jsx(TurnBody, { turn: turn, view: view, stopped: chat.stopped.includes(index), linkAllowed: chat.linkAllowed, live: chat.busy && index === chat.turns.length - 1 })] }, index))), chat.pendingQuestion ? (_jsxs("li", { className: "aic-turn", children: [_jsx(Question, { text: chat.pendingQuestion.text, attachments: chat.pendingQuestion.attachments }), _jsx(ConnectStep, { pending: true })] })) : null] }), chat.refusal === PLAN_INACTIVE ? _jsx(PlanOffer, { onActive: chat.retry }) : null, chat.error && chat.refusal !== PLAN_INACTIVE ? (_jsxs("div", { className: "aic-error", role: "alert", children: [_jsx("p", { children: chat.error }), _jsx("button", { type: "button", className: "aic-text-button", onClick: chat.retry, children: moduleMessages.retry })] })) : null] }));
|
|
68
71
|
}
|
|
69
72
|
//# sourceMappingURL=Conversation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Conversation.js","sourceRoot":"","sources":["../../../src/modules/parts/Conversation.tsx"],"names":[],"mappings":";AAAA,8FAA8F;AAC9F,+FAA+F;AAC/F,gGAAgG;AAChG,wGAAwG;AACxG,0GAA0G;AAC1G,UAAU;AAEV,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA6B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAuB,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAiB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAa,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAoB,CAAC;AAatD,6EAA6E;AAC7E,MAAM,aAAa,GAAG,eAAe,CAAC;AAEtC,kFAAkF;AAClF,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,SAAS,QAAQ,CAAC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EAAC,SAAS,EAAC,iBAAiB,EAAC,OAAO,EAAE,IAAI,CAAC,KAAK,YAAG,cAAc,CAAC,KAAK,GAAU,IAClG,CACP,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC;AACJ,CAAC","sourcesContent":["// The conversation of a chat module. Empty, it shows its heading, the connection step and the\n// suggested questions, under the wallet's ring in the full page mode. Then each turn shows the\n// visitor's question, the site's tools as they run, the answer as it streams and the site's own\n// result cards, and the last answer's error comes with a way to ask again, or, for a TensorPass account\n// without a plan, the offer to subscribe. The view follows the answer down while the visitor stays at the\n// bottom.\n\nimport { useEffect, useRef } from 'react';\nimport type { RefObject } from 'react';\nimport { useAiConnect } from '../../AiConnectProvider.tsx';\nimport { ConnectRing } from '../../ConnectRing.tsx';\nimport type { ChatTurn } from '../../useAiChat.ts';\nimport type { AiModuleProps } from '../types.ts';\nimport { AnswerText } from './AnswerText.tsx';\nimport { ConnectStep } from './ConnectStep.tsx';\nimport { PlanOffer } from './PlanOffer.tsx';\nimport { useActionAttribute } from './moduleAnalytics.ts';\nimport { ArrowIcon, WaveIcon } from './icons.tsx';\nimport { ToolActivityList } from './ToolActivity.tsx';\nimport type { ModuleChat } from './useModuleChat.ts';\n\nexport type TurnView = Pick<AiModuleProps, 'toolLabels' | 'renderToolResults'>;\n\nexport interface TurnBodyProps {\n turn: ChatTurn;\n live: boolean;\n stopped: boolean;\n view: TurnView;\n linkAllowed: (href: string) => boolean;\n}\n\n// The plan gateway's refusal of a TensorPass account without a subscription.\nconst PLAN_INACTIVE = 'plan_inactive';\n\n// How close to the bottom, in pixels, the visitor counts as following the answer.\nconst FOLLOW_DISTANCE = 56;\n\nfunction Question({ text }: { text: string }) {\n const { moduleMessages } = useAiConnect();\n return (\n <p className=\"aic-question\">\n <span className=\"aic-visually-hidden\">{moduleMessages.question}: </span>{text}\n </p>\n );\n}\n\n// What a turn shows under its question: the tools as they run, a thinking line until the first\n// words arrive, the answer, whether the visitor stopped it, and the site's own result cards.\nexport function TurnBody({ turn, live, stopped, view, linkAllowed }: TurnBodyProps) {\n const { moduleMessages } = useAiConnect();\n const toolRunning = turn.tools.some((activity) => activity.result === null);\n const results = view.renderToolResults?.(turn);\n return (\n <>\n <ToolActivityList tools={turn.tools} labels={view.toolLabels} />\n {live && !turn.answer && !toolRunning ? (\n <p className=\"aic-thinking\"><WaveIcon size={16} className=\"aic-live-arcs\" />{moduleMessages.thinking}</p>\n ) : null}\n <AnswerText text={turn.answer} streaming={live && Boolean(turn.answer)} linkAllowed={linkAllowed}\n blocked={Boolean(turn.blocked)} />\n {stopped ? <p className=\"aic-stopped\"><i aria-hidden=\"true\" />{moduleMessages.stopped}</p> : null}\n {results ? <div className=\"aic-results\">{results}</div> : null}\n </>\n );\n}\n\nexport function Suggestions({ items, onPick }: { items?: string[]; onPick: (question: string) => void }) {\n const { moduleMessages } = useAiConnect();\n const tracking = useActionAttribute('suggestion');\n if (!items?.length) {\n return null;\n }\n return (\n <ul className=\"aic-suggestions\" aria-label={moduleMessages.suggestionsLabel}>\n {items.map((question) => (\n <li key={question}>\n <button type=\"button\" className=\"aic-suggestion\" onClick={() => onPick(question)} {...tracking}>\n <span>{question}</span><ArrowIcon />\n </button>\n </li>\n ))}\n </ul>\n );\n}\n\n// Keeps the log scrolled to its end while the visitor reads at the bottom, and lets them scroll up.\n// An empty conversation stays at its top, where its heading is.\nfunction useFollowAnswer(logRef: RefObject<HTMLDivElement | null>, chat: ModuleChat) {\n const following = useRef(true);\n const asked = chat.turns.length + (chat.pendingQuestion ? 1 : 0);\n useEffect(() => {\n following.current = true;\n }, [asked]);\n useEffect(() => {\n const log = logRef.current;\n if (log && asked > 0 && following.current) {\n log.scrollTop = log.scrollHeight;\n }\n });\n return () => {\n const log = logRef.current;\n if (log) {\n following.current = log.scrollHeight - log.scrollTop - log.clientHeight < FOLLOW_DISTANCE;\n }\n };\n}\n\nexport interface ConversationProps extends TurnView {\n chat: ModuleChat;\n intro: string;\n suggestions?: string[];\n}\n\nexport function Conversation({ chat, intro, suggestions, ...view }: ConversationProps) {\n const { moduleMessages } = useAiConnect();\n const logRef = useRef<HTMLDivElement>(null);\n const onScroll = useFollowAnswer(logRef, chat);\n const empty = chat.turns.length === 0 && !chat.pendingQuestion;\n return (\n <div ref={logRef} className=\"aic-log\" role=\"log\" aria-busy={chat.busy} onScroll={onScroll}>\n {empty ? (\n <div className=\"aic-empty\">\n <div className=\"aic-empty-ring\"><ConnectRing live={false} /></div>\n <h3 className=\"aic-intro\">{intro}</h3>\n <ConnectStep pending={false} />\n <Suggestions items={suggestions} onPick={chat.ask} />\n </div>\n ) : null}\n <ol className=\"aic-turns\">\n {chat.turns.map((turn, index) => (\n <li key={index} className=\"aic-turn\">\n <Question text={turn.question} />\n <TurnBody turn={turn} view={view} stopped={chat.stopped.includes(index)} linkAllowed={chat.linkAllowed}\n live={chat.busy && index === chat.turns.length - 1} />\n </li>\n ))}\n {chat.pendingQuestion ? (\n <li className=\"aic-turn\"><Question text={chat.pendingQuestion} /><ConnectStep pending /></li>\n ) : null}\n </ol>\n {chat.refusal === PLAN_INACTIVE ? <PlanOffer onActive={chat.retry} /> : null}\n {chat.error && chat.refusal !== PLAN_INACTIVE ? (\n <div className=\"aic-error\" role=\"alert\">\n <p>{chat.error}</p>\n <button type=\"button\" className=\"aic-text-button\" onClick={chat.retry}>{moduleMessages.retry}</button>\n </div>\n ) : null}\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Conversation.js","sourceRoot":"","sources":["../../../src/modules/parts/Conversation.tsx"],"names":[],"mappings":";AAAA,oGAAoG;AACpG,yGAAyG;AACzG,uGAAuG;AACvG,wGAAwG;AACxG,sGAAsG;AACtG,wGAAwG;AACxG,yCAAyC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA6B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAuB,CAAC;AAIp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AAiB,EAAC,OAAO,EAAE,IAAI,CAAC,KAAK,YAAG,cAAc,CAAC,KAAK,GAAU,IAClG,CACP,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC;AACJ,CAAC","sourcesContent":["// The conversation of a chat module. Empty, it shows its heading, the suggested questions, then the\n// connection step, under the wallet's ring in the full page mode. The step appears once the first wallet\n// check ends, so it comes last and the heading and the questions the page rendered stay in place. Then\n// each turn shows the visitor's question with its files, the site's tools as they run, the answer as it\n// streams and the site's own result cards, and the last answer's error comes with a way to ask again,\n// or, for a TensorPass account without a plan, the offer to subscribe. The view follows the answer down\n// while the visitor stays at the bottom.\n\nimport { useEffect, useRef } from 'react';\nimport type { RefObject } from 'react';\nimport { useAiConnect } from '../../AiConnectProvider.tsx';\nimport { ConnectRing } from '../../ConnectRing.tsx';\nimport type { PreparedAttachment } from '@tensorpass/aiconnect/attachments';\nimport type { ChatTurn } from '../../useAiChat.ts';\nimport type { AiModuleProps } from '../types.ts';\nimport { AnswerText } from './AnswerText.tsx';\nimport { QuestionAttachments } from './attachments/AttachmentRows.tsx';\nimport { ConnectStep } from './ConnectStep.tsx';\nimport { PlanOffer } from './PlanOffer.tsx';\nimport { useActionAttribute } from './moduleAnalytics.ts';\nimport { ArrowIcon, WaveIcon } from './icons.tsx';\nimport { ToolActivityList } from './ToolActivity.tsx';\nimport type { ModuleChat } from './useModuleChat.ts';\n\nexport type TurnView = Pick<AiModuleProps, 'toolLabels' | 'renderToolResults'>;\n\nexport interface TurnBodyProps {\n turn: ChatTurn;\n live: boolean;\n stopped: boolean;\n view: TurnView;\n linkAllowed: (href: string) => boolean;\n}\n\n// The plan gateway's refusal of a TensorPass account without a subscription.\nconst PLAN_INACTIVE = 'plan_inactive';\n\n// How close to the bottom, in pixels, the visitor counts as following the answer.\nconst FOLLOW_DISTANCE = 56;\n\ninterface QuestionProps {\n text: string;\n attachments?: PreparedAttachment[];\n // The images and pages the answering model did not read.\n unread?: number;\n}\n\nfunction Question({ text, attachments, unread }: QuestionProps) {\n const { moduleMessages, state } = useAiConnect();\n const account = state.status === 'connected' ? state.providerName : '';\n return (\n <>\n {attachments?.length ? <QuestionAttachments attachments={attachments} /> : null}\n {text ? (\n <p className=\"aic-question\" dir=\"auto\">\n <span className=\"aic-visually-hidden\">{moduleMessages.question}: </span>{text}\n </p>\n ) : null}\n {unread ? (\n <p className=\"aic-unread\">\n {moduleMessages.unreadPages.replaceAll('{count}', String(unread)).replaceAll('{account}', account)}\n </p>\n ) : null}\n </>\n );\n}\n\n// What a turn shows under its question: the tools as they run, a thinking line until the first\n// words arrive, the answer, whether the visitor stopped it, and the site's own result cards.\nexport function TurnBody({ turn, live, stopped, view, linkAllowed }: TurnBodyProps) {\n const { moduleMessages } = useAiConnect();\n const toolRunning = turn.tools.some((activity) => activity.result === null);\n const results = view.renderToolResults?.(turn);\n return (\n <>\n <ToolActivityList tools={turn.tools} labels={view.toolLabels} />\n {live && !turn.answer && !toolRunning ? (\n <p className=\"aic-thinking\"><WaveIcon size={16} className=\"aic-live-arcs\" />{moduleMessages.thinking}</p>\n ) : null}\n <AnswerText text={turn.answer} streaming={live && Boolean(turn.answer)} linkAllowed={linkAllowed}\n blocked={Boolean(turn.blocked)} />\n {stopped ? <p className=\"aic-stopped\"><i aria-hidden=\"true\" />{moduleMessages.stopped}</p> : null}\n {results ? <div className=\"aic-results\">{results}</div> : null}\n </>\n );\n}\n\nexport function Suggestions({ items, onPick }: { items?: string[]; onPick: (question: string) => void }) {\n const { moduleMessages } = useAiConnect();\n const tracking = useActionAttribute('suggestion');\n if (!items?.length) {\n return null;\n }\n return (\n <ul className=\"aic-suggestions\" aria-label={moduleMessages.suggestionsLabel}>\n {items.map((question) => (\n <li key={question}>\n <button type=\"button\" className=\"aic-suggestion\" onClick={() => onPick(question)} {...tracking}>\n <span>{question}</span><ArrowIcon />\n </button>\n </li>\n ))}\n </ul>\n );\n}\n\n// Keeps the log scrolled to its end while the visitor reads at the bottom, and lets them scroll up.\n// An empty conversation stays at its top, where its heading is.\nfunction useFollowAnswer(logRef: RefObject<HTMLDivElement | null>, chat: ModuleChat) {\n const following = useRef(true);\n const asked = chat.turns.length + (chat.pendingQuestion ? 1 : 0);\n useEffect(() => {\n following.current = true;\n }, [asked]);\n useEffect(() => {\n const log = logRef.current;\n if (log && asked > 0 && following.current) {\n log.scrollTop = log.scrollHeight;\n }\n });\n return () => {\n const log = logRef.current;\n if (log) {\n following.current = log.scrollHeight - log.scrollTop - log.clientHeight < FOLLOW_DISTANCE;\n }\n };\n}\n\nexport interface ConversationProps extends TurnView {\n chat: ModuleChat;\n intro: string;\n suggestions?: string[];\n}\n\nexport function Conversation({ chat, intro, suggestions, ...view }: ConversationProps) {\n const { moduleMessages } = useAiConnect();\n const logRef = useRef<HTMLDivElement>(null);\n const onScroll = useFollowAnswer(logRef, chat);\n const empty = chat.turns.length === 0 && !chat.pendingQuestion;\n return (\n <div ref={logRef} className=\"aic-log\" role=\"log\" aria-busy={chat.busy} onScroll={onScroll}>\n {empty ? (\n <div className=\"aic-empty\">\n <div className=\"aic-empty-ring\"><ConnectRing live={false} /></div>\n <h3 className=\"aic-intro\">{intro}</h3>\n <Suggestions items={suggestions} onPick={chat.ask} />\n <ConnectStep pending={false} />\n </div>\n ) : null}\n <ol className=\"aic-turns\">\n {chat.turns.map((turn, index) => (\n <li key={index} className=\"aic-turn\">\n <Question text={turn.question} attachments={turn.attachments} unread={turn.unread} />\n <TurnBody turn={turn} view={view} stopped={chat.stopped.includes(index)} linkAllowed={chat.linkAllowed}\n live={chat.busy && index === chat.turns.length - 1} />\n </li>\n ))}\n {chat.pendingQuestion ? (\n <li className=\"aic-turn\">\n <Question text={chat.pendingQuestion.text} attachments={chat.pendingQuestion.attachments} />\n <ConnectStep pending />\n </li>\n ) : null}\n </ol>\n {chat.refusal === PLAN_INACTIVE ? <PlanOffer onActive={chat.retry} /> : null}\n {chat.error && chat.refusal !== PLAN_INACTIVE ? (\n <div className=\"aic-error\" role=\"alert\">\n <p>{chat.error}</p>\n <button type=\"button\" className=\"aic-text-button\" onClick={chat.retry}>{moduleMessages.retry}</button>\n </div>\n ) : null}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The module's attach button: its own round button over a file input kept out of sight and out of the tab
|
|
3
|
+
// order, so the system's file picker opens from a control in the module's style. The input takes the types
|
|
4
|
+
// the site's policy accepts, several at once.
|
|
5
|
+
import { useRef } from 'react';
|
|
6
|
+
import { useAiConnect } from "../../../AiConnectProvider.js";
|
|
7
|
+
import { PaperclipIcon } from "../icons.js";
|
|
8
|
+
import { useActionAttribute } from "../moduleAnalytics.js";
|
|
9
|
+
const IMAGE_TYPES = ['image/*'];
|
|
10
|
+
const FILE_TYPES = ['application/pdf', 'text/plain', 'text/markdown', 'text/csv', 'application/json',
|
|
11
|
+
'.md', '.markdown', '.csv', '.txt', '.json'];
|
|
12
|
+
// The picker's `accept`: the site's own types, or the kinds its policy leaves on.
|
|
13
|
+
function acceptOf(policy) {
|
|
14
|
+
if (policy.accept?.length) {
|
|
15
|
+
return policy.accept.join(',');
|
|
16
|
+
}
|
|
17
|
+
return [...(policy.images !== false ? IMAGE_TYPES : []), ...(policy.files !== false ? FILE_TYPES : [])].join(',');
|
|
18
|
+
}
|
|
19
|
+
export function AttachButton({ policy, onFiles }) {
|
|
20
|
+
const { moduleMessages } = useAiConnect();
|
|
21
|
+
const input = useRef(null);
|
|
22
|
+
const tracking = useActionAttribute('attach');
|
|
23
|
+
const onChange = (event) => {
|
|
24
|
+
onFiles([...event.target.files ?? []]);
|
|
25
|
+
event.target.value = '';
|
|
26
|
+
};
|
|
27
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "aic-tool-button aic-attach", "aria-label": moduleMessages.attach, title: moduleMessages.attach, onClick: () => input.current?.click(), ...tracking, children: _jsx(PaperclipIcon, {}) }), _jsx("input", { ref: input, className: "aic-visually-hidden", type: "file", multiple: true, accept: acceptOf(policy), tabIndex: -1, "aria-hidden": "true", onChange: onChange })] }));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=AttachButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttachButton.js","sourceRoot":"","sources":["../../../../src/modules/parts/attachments/AttachButton.tsx"],"names":[],"mappings":";AAAA,0GAA0G;AAC1G,2GAA2G;AAC3G,8CAA8C;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,MAAM,+BAAgC,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAc,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,WAAW,GAAG,CAAC,SAAS,CAAC,CAAC;AAChC,MAAM,UAAU,GAAG,CAAC,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,kBAAkB;IAClG,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C,kFAAkF;AAClF,SAAS,QAAQ,CAAC,MAAwB;IACxC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,EAAkE;IAC9G,MAAM,EAAE,cAAc,EAAE,GAAG,YAAY,EAAE,CAAC;IAC1C,MAAM,KAAK,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,CAAC,KAAoC,EAAE,EAAE;QACxD,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC;QACvC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;IAC1B,CAAC,CAAC;IACF,OAAO,CACL,8BACE,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,4BAA4B,gBAAa,cAAc,CAAC,MAAM,EAC5F,KAAK,EAAE,cAAc,CAAC,MAAM,EAC5B,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAM,QAAQ,YACnD,KAAC,aAAa,KAAG,GACV,EACT,gBAAO,GAAG,EAAE,KAAK,EAAE,SAAS,EAAC,qBAAqB,EAAC,IAAI,EAAC,MAAM,EAAC,QAAQ,QAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC9F,QAAQ,EAAE,CAAC,CAAC,iBAAc,MAAM,EAAC,QAAQ,EAAE,QAAQ,GAAI,IACxD,CACJ,CAAC;AACJ,CAAC","sourcesContent":["// The module's attach button: its own round button over a file input kept out of sight and out of the tab\n// order, so the system's file picker opens from a control in the module's style. The input takes the types\n// the site's policy accepts, several at once.\n\nimport { useRef } from 'react';\nimport type { ChangeEvent } from 'react';\nimport type { AttachmentPolicy } from '@tensorpass/aiconnect/attachments';\nimport { useAiConnect } from '../../../AiConnectProvider.tsx';\nimport { PaperclipIcon } from '../icons.tsx';\nimport { useActionAttribute } from '../moduleAnalytics.ts';\n\nconst IMAGE_TYPES = ['image/*'];\nconst FILE_TYPES = ['application/pdf', 'text/plain', 'text/markdown', 'text/csv', 'application/json',\n '.md', '.markdown', '.csv', '.txt', '.json'];\n\n// The picker's `accept`: the site's own types, or the kinds its policy leaves on.\nfunction acceptOf(policy: AttachmentPolicy): string {\n if (policy.accept?.length) {\n return policy.accept.join(',');\n }\n return [...(policy.images !== false ? IMAGE_TYPES : []), ...(policy.files !== false ? FILE_TYPES : [])].join(',');\n}\n\nexport function AttachButton({ policy, onFiles }: { policy: AttachmentPolicy; onFiles: (files: File[]) => void }) {\n const { moduleMessages } = useAiConnect();\n const input = useRef<HTMLInputElement>(null);\n const tracking = useActionAttribute('attach');\n const onChange = (event: ChangeEvent<HTMLInputElement>) => {\n onFiles([...event.target.files ?? []]);\n event.target.value = '';\n };\n return (\n <>\n <button type=\"button\" className=\"aic-tool-button aic-attach\" aria-label={moduleMessages.attach}\n title={moduleMessages.attach}\n onClick={() => input.current?.click()} {...tracking}>\n <PaperclipIcon />\n </button>\n <input ref={input} className=\"aic-visually-hidden\" type=\"file\" multiple accept={acceptOf(policy)}\n tabIndex={-1} aria-hidden=\"true\" onChange={onChange} />\n </>\n );\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AttachmentKind } from '@tensorpass/aiconnect/attachments';
|
|
2
|
+
export interface AttachmentChipProps {
|
|
3
|
+
name: string;
|
|
4
|
+
size: number;
|
|
5
|
+
kind: AttachmentKind;
|
|
6
|
+
preview?: string;
|
|
7
|
+
reading?: boolean;
|
|
8
|
+
note?: string;
|
|
9
|
+
onRemove?: () => void;
|
|
10
|
+
onOpen?: () => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function AttachmentChip({ reading, note, onRemove, onOpen, ...face }: AttachmentChipProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useAiConnect } from "../../../AiConnectProvider.js";
|
|
3
|
+
import { CloseIcon, FileIcon } from "../icons.js";
|
|
4
|
+
import { fileSize } from "./fileSize.js";
|
|
5
|
+
function ChipFace({ name, size, kind, preview }) {
|
|
6
|
+
const { locale } = useAiConnect();
|
|
7
|
+
if (kind === 'image') {
|
|
8
|
+
return preview ? _jsx("img", { className: "aic-chip-thumb", src: preview, alt: "" }) : _jsx("span", { className: "aic-chip-thumb" });
|
|
9
|
+
}
|
|
10
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { className: "aic-chip-icon", children: _jsx(FileIcon, {}) }), _jsxs("span", { className: "aic-chip-text", children: [_jsx("span", { className: "aic-chip-name", dir: "auto", children: name }), _jsx("span", { className: "aic-chip-size", children: fileSize(size, locale) })] })] }));
|
|
11
|
+
}
|
|
12
|
+
export function AttachmentChip({ reading, note, onRemove, onOpen, ...face }) {
|
|
13
|
+
const { moduleMessages } = useAiConnect();
|
|
14
|
+
const label = face.kind === 'image' ? `${moduleMessages.openImage}: ${face.name}` : face.name;
|
|
15
|
+
return (_jsxs("li", { className: "aic-chip", "data-kind": face.kind, "data-reading": reading || undefined, "data-unread": note ? true : undefined, title: note ?? face.name, children: [onOpen ? (_jsx("button", { type: "button", className: "aic-chip-open", "aria-label": label, onClick: onOpen, children: _jsx(ChipFace, { ...face }) })) : _jsx(ChipFace, { ...face }), reading ? _jsx("span", { className: "aic-chip-ring", role: "status", "aria-label": moduleMessages.attachmentReading }) : null, note ? _jsx("span", { className: "aic-visually-hidden", children: note }) : null, onRemove ? (_jsx("button", { type: "button", className: "aic-chip-remove", onClick: onRemove, "aria-label": moduleMessages.attachmentRemove.replaceAll('{name}', face.name), children: _jsx(CloseIcon, {}) })) : null] }));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=AttachmentChip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttachmentChip.js","sourceRoot":"","sources":["../../../../src/modules/parts/attachments/AttachmentChip.tsx"],"names":[],"mappings":";AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAAgC,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,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,IAAI,IAAI,CAAC,IAAI,aAC7D,MAAM,CAAC,CAAC,CAAC,CACR,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,eAAe,gBAAa,KAAK,EAAE,OAAO,EAAE,MAAM,YAChF,KAAC,QAAQ,OAAK,IAAI,GAAI,GACf,CACV,CAAC,CAAC,CAAC,KAAC,QAAQ,OAAK,IAAI,GAAI,EACzB,OAAO,CAAC,CAAC,CAAC,eAAM,SAAS,EAAC,eAAe,EAAC,IAAI,EAAC,QAAQ,gBAAa,cAAc,CAAC,iBAAiB,GAAI,CAAC,CAAC,CAAC,IAAI,EAC/G,IAAI,CAAC,CAAC,CAAC,eAAM,SAAS,EAAC,qBAAqB,YAAE,IAAI,GAAQ,CAAC,CAAC,CAAC,IAAI,EACjE,QAAQ,CAAC,CAAC,CAAC,CACV,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,iBAAiB,EAAC,OAAO,EAAE,QAAQ,gBACrD,cAAc,CAAC,gBAAgB,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,YAC3E,KAAC,SAAS,KAAG,GACN,CACV,CAAC,CAAC,CAAC,IAAI,IACL,CACN,CAAC;AACJ,CAAC","sourcesContent":["// A file of a question as a chip: a thumbnail for an image, an icon with the name and the size for a\n// document, a ring while the page reads it, and a note when the account that answers does not read it. In\n// the question box the chip has a remove button; in the conversation an image's chip opens the lightbox.\n\nimport type { AttachmentKind } from '@tensorpass/aiconnect/attachments';\nimport { useAiConnect } from '../../../AiConnectProvider.tsx';\nimport { CloseIcon, FileIcon } from '../icons.tsx';\nimport { fileSize } from './fileSize.ts';\n\nexport interface AttachmentChipProps {\n name: string;\n size: number;\n kind: AttachmentKind;\n // The image as the model receives it, for the thumbnail; absent while the page reads it.\n preview?: string;\n reading?: boolean;\n // Why the account that answers will not read the file.\n note?: string;\n onRemove?: () => void;\n onOpen?: () => void;\n}\n\nfunction ChipFace({ name, size, kind, preview }: Pick<AttachmentChipProps, 'name' | 'size' | 'kind' | 'preview'>) {\n const { locale } = useAiConnect();\n if (kind === 'image') {\n return preview ? <img className=\"aic-chip-thumb\" src={preview} alt=\"\" /> : <span className=\"aic-chip-thumb\" />;\n }\n return (\n <>\n <span className=\"aic-chip-icon\"><FileIcon /></span>\n <span className=\"aic-chip-text\">\n <span className=\"aic-chip-name\" dir=\"auto\">{name}</span>\n <span className=\"aic-chip-size\">{fileSize(size, locale)}</span>\n </span>\n </>\n );\n}\n\nexport function AttachmentChip({ reading, note, onRemove, onOpen, ...face }: AttachmentChipProps) {\n const { moduleMessages } = useAiConnect();\n const label = face.kind === 'image' ? `${moduleMessages.openImage}: ${face.name}` : face.name;\n return (\n <li className=\"aic-chip\" data-kind={face.kind} data-reading={reading || undefined}\n data-unread={note ? true : undefined} title={note ?? face.name}>\n {onOpen ? (\n <button type=\"button\" className=\"aic-chip-open\" aria-label={label} onClick={onOpen}>\n <ChipFace {...face} />\n </button>\n ) : <ChipFace {...face} />}\n {reading ? <span className=\"aic-chip-ring\" role=\"status\" aria-label={moduleMessages.attachmentReading} /> : null}\n {note ? <span className=\"aic-visually-hidden\">{note}</span> : null}\n {onRemove ? (\n <button type=\"button\" className=\"aic-chip-remove\" onClick={onRemove}\n aria-label={moduleMessages.attachmentRemove.replaceAll('{name}', face.name)}>\n <CloseIcon />\n </button>\n ) : null}\n </li>\n );\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PreparedAttachment } from '@tensorpass/aiconnect/attachments';
|
|
2
|
+
import type { ReadableParts } from '@tensorpass/aiconnect';
|
|
3
|
+
import type { Attachments } from './useAttachments.ts';
|
|
4
|
+
export interface ComposerAttachmentsProps {
|
|
5
|
+
attachments: Attachments;
|
|
6
|
+
reads: ReadableParts;
|
|
7
|
+
}
|
|
8
|
+
export declare function ComposerAttachments({ attachments, reads }: ComposerAttachmentsProps): import("react").JSX.Element | null;
|
|
9
|
+
export declare function QuestionAttachments({ attachments }: {
|
|
10
|
+
attachments: PreparedAttachment[];
|
|
11
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The rows of chips a chat shows: the files of the question being written, above the field, each with its
|
|
3
|
+
// remove button and, on a model that does not read it, a note; and the files of a question sent, beside it,
|
|
4
|
+
// whose images open in the lightbox.
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
import { readsAttachment } from '@tensorpass/aiconnect/attachments';
|
|
7
|
+
import { useAiConnect } from "../../../AiConnectProvider.js";
|
|
8
|
+
import { AttachmentChip } from "./AttachmentChip.js";
|
|
9
|
+
import { Lightbox } from "./Lightbox.js";
|
|
10
|
+
export function ComposerAttachments({ attachments, reads }) {
|
|
11
|
+
const { moduleMessages, state } = useAiConnect();
|
|
12
|
+
if (attachments.items.length === 0) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const account = state.status === 'connected' ? state.providerName : '';
|
|
16
|
+
const unread = moduleMessages.imageUnread.replaceAll('{account}', account);
|
|
17
|
+
const unreadNote = (kind) => (account && !readsAttachment(kind, reads) ? unread : undefined);
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx("ul", { className: "aic-chips", "aria-label": moduleMessages.attach, children: attachments.items.map((item) => (_jsx(AttachmentChip, { name: item.name, size: item.size, kind: item.kind, preview: item.kind === 'image' ? item.prepared?.part.url : undefined, reading: !item.prepared, note: unreadNote(item.kind), onRemove: () => attachments.remove(item.id) }, item.id))) }), attachments.items.some((item) => unreadNote(item.kind)) ? (_jsx("p", { className: "aic-chips-note", "aria-hidden": "true", children: unread })) : null] }));
|
|
19
|
+
}
|
|
20
|
+
export function QuestionAttachments({ attachments }) {
|
|
21
|
+
const [open, setOpen] = useState(null);
|
|
22
|
+
const images = attachments.filter((item) => item.kind === 'image')
|
|
23
|
+
.map((item) => ({ url: item.part.url, name: item.name }));
|
|
24
|
+
return (_jsxs(_Fragment, { children: [_jsx("ul", { className: "aic-chips aic-question-chips", children: attachments.map((item, index) => {
|
|
25
|
+
const image = images.findIndex((entry) => entry.url === item.part.url);
|
|
26
|
+
return (_jsx(AttachmentChip, { name: item.name, size: item.size, kind: item.kind, preview: item.kind === 'image' ? item.part.url : undefined, onOpen: item.kind === 'image' ? () => setOpen(image) : undefined }, `${item.name}-${index}`));
|
|
27
|
+
}) }), open === null ? null : _jsx(Lightbox, { images: images, start: open, onClose: () => setOpen(null) })] }));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=AttachmentRows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttachmentRows.js","sourceRoot":"","sources":["../../../../src/modules/parts/attachments/AttachmentRows.tsx"],"names":[],"mappings":";AAAA,0GAA0G;AAC1G,4GAA4G;AAC5G,qCAAqC;AAErC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAGpE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAAgC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAsB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAgB,CAAC;AAQ1C,MAAM,UAAU,mBAAmB,CAAC,EAAE,WAAW,EAAE,KAAK,EAA4B;IAClF,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,YAAY,EAAE,CAAC;IACjD,IAAI,WAAW,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IACvE,MAAM,MAAM,GAA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C,OAAO,CAAC,IAAI,CAAC,GAAI,IAC9F,CACJ,CAAC;AACJ,CAAC","sourcesContent":["// The rows of chips a chat shows: the files of the question being written, above the field, each with its\n// remove button and, on a model that does not read it, a note; and the files of a question sent, beside it,\n// whose images open in the lightbox.\n\nimport { useState } from 'react';\nimport { readsAttachment } from '@tensorpass/aiconnect/attachments';\nimport type { PreparedAttachment } from '@tensorpass/aiconnect/attachments';\nimport type { ReadableParts } from '@tensorpass/aiconnect';\nimport { useAiConnect } from '../../../AiConnectProvider.tsx';\nimport { AttachmentChip } from './AttachmentChip.tsx';\nimport { Lightbox } from './Lightbox.tsx';\nimport type { Attachments } from './useAttachments.ts';\n\nexport interface ComposerAttachmentsProps {\n attachments: Attachments;\n reads: ReadableParts;\n}\n\nexport function ComposerAttachments({ attachments, reads }: ComposerAttachmentsProps) {\n const { moduleMessages, state } = useAiConnect();\n if (attachments.items.length === 0) {\n return null;\n }\n const account = state.status === 'connected' ? state.providerName : '';\n const unread = moduleMessages.imageUnread.replaceAll('{account}', account);\n const unreadNote = (kind: (typeof attachments.items)[number]['kind']) => (\n account && !readsAttachment(kind, reads) ? unread : undefined\n );\n return (\n <>\n <ul className=\"aic-chips\" aria-label={moduleMessages.attach}>\n {attachments.items.map((item) => (\n <AttachmentChip key={item.id} name={item.name} size={item.size} kind={item.kind}\n preview={item.kind === 'image' ? item.prepared?.part.url : undefined} reading={!item.prepared}\n note={unreadNote(item.kind)} onRemove={() => attachments.remove(item.id)} />\n ))}\n </ul>\n {attachments.items.some((item) => unreadNote(item.kind)) ? (\n <p className=\"aic-chips-note\" aria-hidden=\"true\">{unread}</p>\n ) : null}\n </>\n );\n}\n\nexport function QuestionAttachments({ attachments }: { attachments: PreparedAttachment[] }) {\n const [open, setOpen] = useState<number | null>(null);\n const images = attachments.filter((item) => item.kind === 'image')\n .map((item) => ({ url: item.part.url, name: item.name }));\n return (\n <>\n <ul className=\"aic-chips aic-question-chips\">\n {attachments.map((item, index) => {\n const image = images.findIndex((entry) => entry.url === item.part.url);\n return (\n <AttachmentChip key={`${item.name}-${index}`} name={item.name} size={item.size} kind={item.kind}\n preview={item.kind === 'image' ? item.part.url : undefined}\n onOpen={item.kind === 'image' ? () => setOpen(image) : undefined} />\n );\n })}\n </ul>\n {open === null ? null : <Lightbox images={images} start={open} onClose={() => setOpen(null)} />}\n </>\n );\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { AttachmentPolicy } from '@tensorpass/aiconnect/attachments';
|
|
3
|
+
export interface DropZoneProps {
|
|
4
|
+
policy?: AttachmentPolicy;
|
|
5
|
+
onFiles: (files: File[]) => void;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export declare function DropZone({ policy, onFiles, children }: DropZoneProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Files dragged over a chat module: the module shows a drop zone as soon as files enter it, saying whether
|
|
3
|
+
// it takes them before the visitor lets go, read from the types the drag carries. Text or links dragged
|
|
4
|
+
// from the page leave the module as it is.
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
import { acceptsType, mediaTypeOf } from '@tensorpass/aiconnect/attachments';
|
|
7
|
+
import { useAiConnect } from "../../../AiConnectProvider.js";
|
|
8
|
+
import { PaperclipIcon } from "../icons.js";
|
|
9
|
+
function carriesFiles(event) {
|
|
10
|
+
return event.dataTransfer.types.includes('Files');
|
|
11
|
+
}
|
|
12
|
+
// Whether every dragged file is one the policy takes. A browser that hides the types during the drag gives
|
|
13
|
+
// empty types, which the drop then checks file by file.
|
|
14
|
+
function dragState(event, policy) {
|
|
15
|
+
const types = [...event.dataTransfer.items].filter((item) => item.kind === 'file').map((item) => item.type);
|
|
16
|
+
const known = types.filter(Boolean);
|
|
17
|
+
const accepted = known.every((type) => acceptsType(mediaTypeOf({ name: '', type }), policy));
|
|
18
|
+
return accepted ? 'accepted' : 'refused';
|
|
19
|
+
}
|
|
20
|
+
const NO_DRAG = { state: 'none', depth: 0 };
|
|
21
|
+
// The drag's state over the module and the handlers that follow it, when the module takes files.
|
|
22
|
+
function useFileDrag(policy, onFiles) {
|
|
23
|
+
const [drag, setDrag] = useState(NO_DRAG);
|
|
24
|
+
const handlers = policy && {
|
|
25
|
+
onDragEnter: (event) => {
|
|
26
|
+
if (carriesFiles(event)) {
|
|
27
|
+
const state = dragState(event, policy);
|
|
28
|
+
setDrag((current) => ({ state, depth: current.depth + 1 }));
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
onDragOver: (event) => {
|
|
32
|
+
if (carriesFiles(event)) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
event.dataTransfer.dropEffect = drag.state === 'refused' ? 'none' : 'copy';
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
onDragLeave: (event) => {
|
|
38
|
+
if (carriesFiles(event)) {
|
|
39
|
+
setDrag((current) => (current.depth <= 1 ? NO_DRAG : { ...current, depth: current.depth - 1 }));
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
onDrop: (event) => {
|
|
43
|
+
if (carriesFiles(event)) {
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
setDrag(NO_DRAG);
|
|
46
|
+
onFiles([...event.dataTransfer.files]);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
return { state: drag.state, handlers: handlers || {} };
|
|
51
|
+
}
|
|
52
|
+
export function DropZone({ policy, onFiles, children }) {
|
|
53
|
+
const { moduleMessages } = useAiConnect();
|
|
54
|
+
const { state, handlers } = useFileDrag(policy, onFiles);
|
|
55
|
+
return (_jsxs("div", { className: "aic-drop-area", ...handlers, children: [children, state === 'none' ? null : (_jsxs("div", { className: "aic-drop", "data-state": state, "aria-hidden": "true", children: [_jsx("span", { className: "aic-drop-icon", children: _jsx(PaperclipIcon, {}) }), _jsx("span", { children: state === 'accepted' ? moduleMessages.attachDrop : moduleMessages.attachRefusedType })] }))] }));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=DropZone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DropZone.js","sourceRoot":"","sources":["../../../../src/modules/parts/attachments/DropZone.tsx"],"names":[],"mappings":";AAAA,2GAA2G;AAC3G,wGAAwG;AACxG,2CAA2C;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,MAAM,+BAAgC,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAc,CAAC;AAI7C,SAAS,YAAY,CAAC,KAAgB;IACpC,OAAO,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,2GAA2G;AAC3G,wDAAwD;AACxD,SAAS,SAAS,CAAC,KAAgB,EAAE,MAAwB;IAC3D,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5G,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7F,OAAO,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS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CAAC,KAAgB,EAAE,EAAE;YAC3B,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxB,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,OAAO,CAAC,OAAO,CAAC,CAAC;gBACjB,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;KACF,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,IAAI,EAAE,EAAE,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAiB;IACnE,MAAM,EAAE,cAAc,EAAE,GAAG,YAAY,EAAE,CAAC;IAC1C,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzD,OAAO,CACL,eAAK,SAAS,EAAC,eAAe,KAAK,QAAQ,aACxC,QAAQ,EACR,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACzB,eAAK,SAAS,EAAC,UAAU,gBAAa,KAAK,iBAAc,MAAM,aAC7D,eAAM,SAAS,EAAC,eAAe,YAAC,KAAC,aAAa,KAAG,GAAO,EACxD,yBAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,cAAc,CAAC,iBAAiB,GAAQ,IAC9F,CACP,IACG,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Files dragged over a chat module: the module shows a drop zone as soon as files enter it, saying whether\n// it takes them before the visitor lets go, read from the types the drag carries. Text or links dragged\n// from the page leave the module as it is.\n\nimport { useState } from 'react';\nimport type { DragEvent, ReactNode } from 'react';\nimport { acceptsType, mediaTypeOf } from '@tensorpass/aiconnect/attachments';\nimport type { AttachmentPolicy } from '@tensorpass/aiconnect/attachments';\nimport { useAiConnect } from '../../../AiConnectProvider.tsx';\nimport { PaperclipIcon } from '../icons.tsx';\n\ntype DragState = 'none' | 'accepted' | 'refused';\n\nfunction carriesFiles(event: DragEvent): boolean {\n return event.dataTransfer.types.includes('Files');\n}\n\n// Whether every dragged file is one the policy takes. A browser that hides the types during the drag gives\n// empty types, which the drop then checks file by file.\nfunction dragState(event: DragEvent, policy: AttachmentPolicy): DragState {\n const types = [...event.dataTransfer.items].filter((item) => item.kind === 'file').map((item) => item.type);\n const known = types.filter(Boolean);\n const accepted = known.every((type) => acceptsType(mediaTypeOf({ name: '', type }), policy));\n return accepted ? 'accepted' : 'refused';\n}\n\nexport interface DropZoneProps {\n // Without a policy the module takes no files, and a drop goes to the page as before.\n policy?: AttachmentPolicy;\n onFiles: (files: File[]) => void;\n children: ReactNode;\n}\n\n// The drag over the module: its state, and the depth of the elements it entered, since entering a child\n// fires the child's enter before the parent's leave.\ninterface Drag {\n state: DragState;\n depth: number;\n}\n\nconst NO_DRAG: Drag = { state: 'none', depth: 0 };\n\n// The drag's state over the module and the handlers that follow it, when the module takes files.\nfunction useFileDrag(policy: AttachmentPolicy | undefined, onFiles: (files: File[]) => void) {\n const [drag, setDrag] = useState<Drag>(NO_DRAG);\n const handlers = policy && {\n onDragEnter: (event: DragEvent) => {\n if (carriesFiles(event)) {\n const state = dragState(event, policy);\n setDrag((current) => ({ state, depth: current.depth + 1 }));\n }\n },\n onDragOver: (event: DragEvent) => {\n if (carriesFiles(event)) {\n event.preventDefault();\n event.dataTransfer.dropEffect = drag.state === 'refused' ? 'none' : 'copy';\n }\n },\n onDragLeave: (event: DragEvent) => {\n if (carriesFiles(event)) {\n setDrag((current) => (current.depth <= 1 ? NO_DRAG : { ...current, depth: current.depth - 1 }));\n }\n },\n onDrop: (event: DragEvent) => {\n if (carriesFiles(event)) {\n event.preventDefault();\n setDrag(NO_DRAG);\n onFiles([...event.dataTransfer.files]);\n }\n },\n };\n return { state: drag.state, handlers: handlers || {} };\n}\n\nexport function DropZone({ policy, onFiles, children }: DropZoneProps) {\n const { moduleMessages } = useAiConnect();\n const { state, handlers } = useFileDrag(policy, onFiles);\n return (\n <div className=\"aic-drop-area\" {...handlers}>\n {children}\n {state === 'none' ? null : (\n <div className=\"aic-drop\" data-state={state} aria-hidden=\"true\">\n <span className=\"aic-drop-icon\"><PaperclipIcon /></span>\n <span>{state === 'accepted' ? moduleMessages.attachDrop : moduleMessages.attachRefusedType}</span>\n </div>\n )}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface LightboxImage {
|
|
2
|
+
url: string;
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
export interface LightboxProps {
|
|
6
|
+
images: LightboxImage[];
|
|
7
|
+
start: number;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function Lightbox({ images, start, onClose }: LightboxProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The images of a question at full size, over the module: Escape or the close button closes it and hands the
|
|
3
|
+
// focus back to the chip that opened it, the arrow keys and buttons move between the question's images in
|
|
4
|
+
// the reading direction, and the focus stays inside while it is open.
|
|
5
|
+
import { useEffect, useRef, useState } from 'react';
|
|
6
|
+
import { useAiConnect } from "../../../AiConnectProvider.js";
|
|
7
|
+
import { useFocusTrap } from "../../useOverlay.js";
|
|
8
|
+
import { BackIcon, CloseIcon, ForwardIcon } from "../icons.js";
|
|
9
|
+
// The arrow key that moves forward along the reading direction.
|
|
10
|
+
function forwardKey(dir) {
|
|
11
|
+
return dir === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
|
|
12
|
+
}
|
|
13
|
+
export function Lightbox({ images, start, onClose }) {
|
|
14
|
+
const { moduleMessages } = useAiConnect();
|
|
15
|
+
const [index, setIndex] = useState(start);
|
|
16
|
+
const layer = useRef(null);
|
|
17
|
+
const closeButton = useRef(null);
|
|
18
|
+
useFocusTrap(layer, true);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const root = layer.current?.getRootNode();
|
|
21
|
+
const opener = root?.activeElement instanceof HTMLElement ? root.activeElement : null;
|
|
22
|
+
closeButton.current?.focus();
|
|
23
|
+
return () => opener?.focus();
|
|
24
|
+
}, []);
|
|
25
|
+
const move = (step) => setIndex((current) => (current + step + images.length) % images.length);
|
|
26
|
+
const onKeyDown = (event) => {
|
|
27
|
+
const forward = forwardKey(moduleMessages.dir);
|
|
28
|
+
if (event.key === 'Escape') {
|
|
29
|
+
// The lightbox closes alone, and the module stays open under it.
|
|
30
|
+
event.stopPropagation();
|
|
31
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
32
|
+
onClose();
|
|
33
|
+
}
|
|
34
|
+
else if (images.length > 1 && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) {
|
|
35
|
+
move(event.key === forward ? 1 : -1);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const image = images[index];
|
|
39
|
+
const position = moduleMessages.imageOf.replaceAll('{index}', String(index + 1))
|
|
40
|
+
.replaceAll('{count}', String(images.length));
|
|
41
|
+
return (_jsxs("div", { ref: layer, className: "aic-lightbox", role: "dialog", "aria-modal": "true", "aria-label": image.name, onKeyDown: onKeyDown, children: [_jsx("button", { type: "button", className: "aic-lightbox-backdrop", tabIndex: -1, "aria-hidden": "true", onClick: onClose }), _jsxs("figure", { className: "aic-lightbox-figure", children: [_jsx("img", { src: image.url, alt: image.name }), _jsxs("figcaption", { dir: "auto", children: [image.name, images.length > 1 ? ` · ${position}` : ''] })] }), _jsx("button", { ref: closeButton, type: "button", className: "aic-round aic-lightbox-close", "aria-label": moduleMessages.close, onClick: onClose, children: _jsx(CloseIcon, {}) }), images.length > 1 ? (_jsxs("div", { className: "aic-lightbox-steps", children: [_jsx("button", { type: "button", className: "aic-round", "aria-label": moduleMessages.previousImage, onClick: () => move(-1), children: _jsx(BackIcon, {}) }), _jsx("button", { type: "button", className: "aic-round", "aria-label": moduleMessages.nextImage, onClick: () => move(1), children: _jsx(ForwardIcon, {}) })] })) : null] }));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=Lightbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Lightbox.js","sourceRoot":"","sources":["../../../../src/modules/parts/attachments/Lightbox.tsx"],"names":[],"mappings":";AAAA,6GAA6G;AAC7G,0GAA0G;AAC1G,sEAAsE;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAAgC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAc,CAAC;AAahE,gEAAgE;AAChE,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAiB;IAChE,MAAM,EAAE,cAAc,EAAE,GAAG,YAAY,EAAE,CAAC;IAC1C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC3C,MAAM,WAAW,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IACpD,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,EAAE,WAAW,EAAuC,CAAC;QAC/E,MAAM,MAAM,GAAG,IAAI,EAAE,aAAa,YAAY,W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CAAC;AACJ,CAAC","sourcesContent":["// The images of a question at full size, over the module: Escape or the close button closes it and hands the\n// focus back to the chip that opened it, the arrow keys and buttons move between the question's images in\n// the reading direction, and the focus stays inside while it is open.\n\nimport { useEffect, useRef, useState } from 'react';\nimport type { KeyboardEvent } from 'react';\nimport { useAiConnect } from '../../../AiConnectProvider.tsx';\nimport { useFocusTrap } from '../../useOverlay.ts';\nimport { BackIcon, CloseIcon, ForwardIcon } from '../icons.tsx';\n\nexport interface LightboxImage {\n url: string;\n name: string;\n}\n\nexport interface LightboxProps {\n images: LightboxImage[];\n start: number;\n onClose: () => void;\n}\n\n// The arrow key that moves forward along the reading direction.\nfunction forwardKey(dir: string): string {\n return dir === 'rtl' ? 'ArrowLeft' : 'ArrowRight';\n}\n\nexport function Lightbox({ images, start, onClose }: LightboxProps) {\n const { moduleMessages } = useAiConnect();\n const [index, setIndex] = useState(start);\n const layer = useRef<HTMLDivElement>(null);\n const closeButton = useRef<HTMLButtonElement>(null);\n useFocusTrap(layer, true);\n useEffect(() => {\n const root = layer.current?.getRootNode() as Document | ShadowRoot | undefined;\n const opener = root?.activeElement instanceof HTMLElement ? root.activeElement : null;\n closeButton.current?.focus();\n return () => opener?.focus();\n }, []);\n const move = (step: number) => setIndex((current) => (current + step + images.length) % images.length);\n const onKeyDown = (event: KeyboardEvent) => {\n const forward = forwardKey(moduleMessages.dir);\n if (event.key === 'Escape') {\n // The lightbox closes alone, and the module stays open under it.\n event.stopPropagation();\n event.nativeEvent.stopImmediatePropagation();\n onClose();\n } else if (images.length > 1 && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) {\n move(event.key === forward ? 1 : -1);\n }\n };\n const image = images[index];\n const position = moduleMessages.imageOf.replaceAll('{index}', String(index + 1))\n .replaceAll('{count}', String(images.length));\n return (\n <div ref={layer} className=\"aic-lightbox\" role=\"dialog\" aria-modal=\"true\" aria-label={image.name}\n onKeyDown={onKeyDown}>\n <button type=\"button\" className=\"aic-lightbox-backdrop\" tabIndex={-1} aria-hidden=\"true\" onClick={onClose} />\n <figure className=\"aic-lightbox-figure\">\n <img src={image.url} alt={image.name} />\n <figcaption dir=\"auto\">{image.name}{images.length > 1 ? ` · ${position}` : ''}</figcaption>\n </figure>\n <button ref={closeButton} type=\"button\" className=\"aic-round aic-lightbox-close\" aria-label={moduleMessages.close}\n onClick={onClose}>\n <CloseIcon />\n </button>\n {images.length > 1 ? (\n <div className=\"aic-lightbox-steps\">\n <button type=\"button\" className=\"aic-round\" aria-label={moduleMessages.previousImage}\n onClick={() => move(-1)}>\n <BackIcon />\n </button>\n <button type=\"button\" className=\"aic-round\" aria-label={moduleMessages.nextImage} onClick={() => move(1)}>\n <ForwardIcon />\n </button>\n </div>\n ) : null}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AttachmentKind, PreparedAttachment } from '@tensorpass/aiconnect/attachments';
|
|
2
|
+
export interface AttachmentItem {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
size: number;
|
|
6
|
+
kind: AttachmentKind;
|
|
7
|
+
prepared: PreparedAttachment | null;
|
|
8
|
+
}
|
|
9
|
+
export type AttachmentAction = {
|
|
10
|
+
type: 'add';
|
|
11
|
+
item: AttachmentItem;
|
|
12
|
+
} | {
|
|
13
|
+
type: 'ready';
|
|
14
|
+
id: string;
|
|
15
|
+
prepared: PreparedAttachment;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'remove';
|
|
18
|
+
id: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'clear';
|
|
21
|
+
};
|
|
22
|
+
export declare function attachmentList(items: AttachmentItem[], action: AttachmentAction): AttachmentItem[];
|
|
23
|
+
export declare function heldBytes(items: AttachmentItem[], except?: string): number;
|
|
24
|
+
export declare function readyAttachments(items: AttachmentItem[]): PreparedAttachment[];
|
|
25
|
+
export declare function stillReading(items: AttachmentItem[]): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// The files of the question being written, as a list the composer keeps: each file is added while the page
|
|
2
|
+
// reads it, then holds what the page prepared for the model, or leaves the list when it is removed or
|
|
3
|
+
// refused once read.
|
|
4
|
+
export function attachmentList(items, action) {
|
|
5
|
+
switch (action.type) {
|
|
6
|
+
case 'add':
|
|
7
|
+
return [...items, action.item];
|
|
8
|
+
case 'ready':
|
|
9
|
+
return items.map((item) => (item.id === action.id ? { ...item, prepared: action.prepared } : item));
|
|
10
|
+
case 'remove':
|
|
11
|
+
return items.filter((item) => item.id !== action.id);
|
|
12
|
+
case 'clear':
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// The bytes the files read so far take on the way to the model, the file being checked left out.
|
|
17
|
+
export function heldBytes(items, except) {
|
|
18
|
+
return items.reduce((total, item) => total + (item.id === except ? 0 : item.prepared?.bytes ?? 0), 0);
|
|
19
|
+
}
|
|
20
|
+
export function readyAttachments(items) {
|
|
21
|
+
return items.flatMap((item) => (item.prepared ? [item.prepared] : []));
|
|
22
|
+
}
|
|
23
|
+
export function stillReading(items) {
|
|
24
|
+
return items.some((item) => item.prepared === null);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=attachmentList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachmentList.js","sourceRoot":"","sources":["../../../../src/modules/parts/attachments/attachmentList.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,sGAAsG;AACtG,qBAAqB;AAmBrB,MAAM,UAAU,cAAc,CAAC,KAAuB,EAAE,MAAwB;IAC9E,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,KAAK;YACR,OAAO,CAAC,GAAG,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACjC,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACtG,KAAK,QAAQ;YACX,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;QACvD,KAAK,OAAO;YACV,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,SAAS,CAAC,KAAuB,EAAE,MAAe;IAChE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACxG,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAuB;IACtD,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAuB;IAClD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC;AACtD,CAAC","sourcesContent":["// The files of the question being written, as a list the composer keeps: each file is added while the page\n// reads it, then holds what the page prepared for the model, or leaves the list when it is removed or\n// refused once read.\n\nimport type { AttachmentKind, PreparedAttachment } from '@tensorpass/aiconnect/attachments';\n\nexport interface AttachmentItem {\n id: string;\n name: string;\n size: number;\n kind: AttachmentKind;\n // Null while the page reads the file.\n prepared: PreparedAttachment | null;\n}\n\nexport type AttachmentAction =\n | { type: 'add'; item: AttachmentItem }\n | { type: 'ready'; id: string; prepared: PreparedAttachment }\n | { type: 'remove'; id: string }\n | { type: 'clear' };\n\nexport function attachmentList(items: AttachmentItem[], action: AttachmentAction): AttachmentItem[] {\n switch (action.type) {\n case 'add':\n return [...items, action.item];\n case 'ready':\n return items.map((item) => (item.id === action.id ? { ...item, prepared: action.prepared } : item));\n case 'remove':\n return items.filter((item) => item.id !== action.id);\n case 'clear':\n return [];\n }\n}\n\n// The bytes the files read so far take on the way to the model, the file being checked left out.\nexport function heldBytes(items: AttachmentItem[], except?: string): number {\n return items.reduce((total, item) => total + (item.id === except ? 0 : item.prepared?.bytes ?? 0), 0);\n}\n\nexport function readyAttachments(items: AttachmentItem[]): PreparedAttachment[] {\n return items.flatMap((item) => (item.prepared ? [item.prepared] : []));\n}\n\nexport function stillReading(items: AttachmentItem[]): boolean {\n return items.some((item) => item.prepared === null);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fileSize(bytes: number, locale: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// A file's size as the visitor reads it, in kilobytes or megabytes, in the module's language.
|
|
2
|
+
const KILOBYTE = 1024;
|
|
3
|
+
const MEGABYTE = KILOBYTE * 1024;
|
|
4
|
+
export function fileSize(bytes, locale) {
|
|
5
|
+
const megabytes = bytes >= MEGABYTE;
|
|
6
|
+
const value = megabytes ? bytes / MEGABYTE : Math.max(1, Math.round(bytes / KILOBYTE));
|
|
7
|
+
return new Intl.NumberFormat(locale, {
|
|
8
|
+
style: 'unit',
|
|
9
|
+
unit: megabytes ? 'megabyte' : 'kilobyte',
|
|
10
|
+
unitDisplay: 'short',
|
|
11
|
+
maximumFractionDigits: megabytes ? 1 : 0,
|
|
12
|
+
}).format(value);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=fileSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileSize.js","sourceRoot":"","sources":["../../../../src/modules/parts/attachments/fileSize.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAAC;AAEjC,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,MAAc;IACpD,MAAM,SAAS,GAAG,KAAK,IAAI,QAAQ,CAAC;IACpC,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC;IACvF,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;QACnC,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU;QACzC,WAAW,EAAE,OAAO;QACpB,qBAAqB,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACzC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC","sourcesContent":["// A file's size as the visitor reads it, in kilobytes or megabytes, in the module's language.\n\nconst KILOBYTE = 1024;\nconst MEGABYTE = KILOBYTE * 1024;\n\nexport function fileSize(bytes: number, locale: string): string {\n const megabytes = bytes >= MEGABYTE;\n const value = megabytes ? bytes / MEGABYTE : Math.max(1, Math.round(bytes / KILOBYTE));\n return new Intl.NumberFormat(locale, {\n style: 'unit',\n unit: megabytes ? 'megabyte' : 'kilobyte',\n unitDisplay: 'short',\n maximumFractionDigits: megabytes ? 1 : 0,\n }).format(value);\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AttachmentPolicy } from '@tensorpass/aiconnect/attachments';
|
|
2
|
+
import type { AttachmentItem } from './attachmentList.ts';
|
|
3
|
+
export declare function useAttachments(policy: AttachmentPolicy | undefined): {
|
|
4
|
+
policy: AttachmentPolicy | undefined;
|
|
5
|
+
items: AttachmentItem[];
|
|
6
|
+
note: string | null;
|
|
7
|
+
add: (files: File[]) => void;
|
|
8
|
+
remove: (id: string) => void;
|
|
9
|
+
clear: () => void;
|
|
10
|
+
ready: import("@tensorpass/aiconnect/attachments").PreparedAttachment[];
|
|
11
|
+
reading: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type Attachments = ReturnType<typeof useAttachments>;
|