@anyknown/ui 0.1.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.
- package/LICENSE +21 -0
- package/README.md +121 -0
- package/dist/components/action-bar/ActionBar.d.ts +28 -0
- package/dist/components/action-bar/ActionBar.js +73 -0
- package/dist/components/badge/Badge.d.ts +28 -0
- package/dist/components/badge/Badge.js +79 -0
- package/dist/components/button/Button.d.ts +7 -0
- package/dist/components/button/Button.js +86 -0
- package/dist/components/card/Card.d.ts +2 -0
- package/dist/components/card/Card.js +17 -0
- package/dist/components/checkbox/Checkbox.d.ts +8 -0
- package/dist/components/checkbox/Checkbox.js +102 -0
- package/dist/components/code-block/CodeBlock.d.ts +10 -0
- package/dist/components/code-block/CodeBlock.js +103 -0
- package/dist/components/composer/Composer.d.ts +27 -0
- package/dist/components/composer/Composer.js +278 -0
- package/dist/components/data-table/DataTable.d.ts +38 -0
- package/dist/components/data-table/DataTable.js +256 -0
- package/dist/components/dialog/Dialog.d.ts +36 -0
- package/dist/components/dialog/Dialog.js +77 -0
- package/dist/components/diff-viewer/DiffViewer.d.ts +13 -0
- package/dist/components/diff-viewer/DiffViewer.js +133 -0
- package/dist/components/dropdown/DropdownMenu.d.ts +43 -0
- package/dist/components/dropdown/DropdownMenu.js +86 -0
- package/dist/components/dropzone/Dropzone.d.ts +32 -0
- package/dist/components/dropzone/Dropzone.js +242 -0
- package/dist/components/empty-state/EmptyState.d.ts +9 -0
- package/dist/components/empty-state/EmptyState.js +41 -0
- package/dist/components/file-row/FileRow.d.ts +32 -0
- package/dist/components/file-row/FileRow.js +153 -0
- package/dist/components/handoff-receipt/HandoffReceipt.d.ts +15 -0
- package/dist/components/handoff-receipt/HandoffReceipt.js +147 -0
- package/dist/components/input/Input.d.ts +48 -0
- package/dist/components/input/Input.js +64 -0
- package/dist/components/interaction-card/InteractionCard.d.ts +59 -0
- package/dist/components/interaction-card/InteractionCard.js +238 -0
- package/dist/components/kbd/Kbd.d.ts +9 -0
- package/dist/components/kbd/Kbd.js +43 -0
- package/dist/components/label/Field.d.ts +11 -0
- package/dist/components/label/Field.js +28 -0
- package/dist/components/label/Label.d.ts +7 -0
- package/dist/components/label/Label.js +21 -0
- package/dist/components/label/fieldContext.d.ts +26 -0
- package/dist/components/label/fieldContext.js +16 -0
- package/dist/components/message/Message.d.ts +29 -0
- package/dist/components/message/Message.js +94 -0
- package/dist/components/password-input/PasswordInput.d.ts +20 -0
- package/dist/components/password-input/PasswordInput.js +141 -0
- package/dist/components/popover/Popover.d.ts +38 -0
- package/dist/components/popover/Popover.js +37 -0
- package/dist/components/progress/Progress.d.ts +36 -0
- package/dist/components/progress/Progress.js +200 -0
- package/dist/components/radio/Radio.d.ts +7 -0
- package/dist/components/radio/Radio.js +89 -0
- package/dist/components/radio/RadioGroup.d.ts +21 -0
- package/dist/components/radio/RadioGroup.js +34 -0
- package/dist/components/reasoning-fold/ReasoningFold.d.ts +10 -0
- package/dist/components/reasoning-fold/ReasoningFold.js +92 -0
- package/dist/components/recovery-key/RecoveryKey.d.ts +17 -0
- package/dist/components/recovery-key/RecoveryKey.js +132 -0
- package/dist/components/select/Select.d.ts +31 -0
- package/dist/components/select/Select.js +209 -0
- package/dist/components/skeleton/Skeleton.d.ts +20 -0
- package/dist/components/skeleton/Skeleton.js +57 -0
- package/dist/components/switch/Switch.d.ts +7 -0
- package/dist/components/switch/Switch.js +108 -0
- package/dist/components/tabs/Tabs.d.ts +28 -0
- package/dist/components/tabs/Tabs.js +133 -0
- package/dist/components/text/Text.d.ts +7 -0
- package/dist/components/text/Text.js +31 -0
- package/dist/components/textarea/Textarea.d.ts +7 -0
- package/dist/components/textarea/Textarea.js +25 -0
- package/dist/components/toast/Toast.d.ts +56 -0
- package/dist/components/toast/Toast.js +175 -0
- package/dist/components/tool-card/ToolCard.d.ts +55 -0
- package/dist/components/tool-card/ToolCard.js +281 -0
- package/dist/components/tooltip/Tooltip.d.ts +12 -0
- package/dist/components/tooltip/Tooltip.js +38 -0
- package/dist/components/voice-indicator/VoiceIndicator.d.ts +7 -0
- package/dist/components/voice-indicator/VoiceIndicator.js +51 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +38 -0
- package/dist/lib/diff.d.ts +28 -0
- package/dist/lib/diff.js +133 -0
- package/dist/lib/format.d.ts +2 -0
- package/dist/lib/format.js +24 -0
- package/dist/lib/format.test.d.ts +1 -0
- package/dist/lib/format.test.js +37 -0
- package/dist/lib/mergeRefs.d.ts +2 -0
- package/dist/lib/mergeRefs.js +8 -0
- package/dist/lib/motion.d.ts +1 -0
- package/dist/lib/motion.js +10 -0
- package/dist/lib/paths.d.ts +3 -0
- package/dist/lib/paths.js +11 -0
- package/dist/lib/popup.d.ts +29 -0
- package/dist/lib/popup.js +27 -0
- package/dist/lib/progress.d.ts +2 -0
- package/dist/lib/progress.js +28 -0
- package/dist/lib/silk.d.ts +66 -0
- package/dist/lib/silk.js +337 -0
- package/dist/lib/styled.d.ts +29 -0
- package/dist/lib/styled.js +30 -0
- package/dist/lib/svgId.d.ts +1 -0
- package/dist/lib/svgId.js +4 -0
- package/dist/lib/useAnimationFrame.d.ts +1 -0
- package/dist/lib/useAnimationFrame.js +21 -0
- package/dist/lib/useControllableState.d.ts +1 -0
- package/dist/lib/useControllableState.js +14 -0
- package/dist/lib/useCopy.d.ts +4 -0
- package/dist/lib/useCopy.js +19 -0
- package/dist/lib/voice.d.ts +2 -0
- package/dist/lib/voice.js +30 -0
- package/dist/lib/weave.d.ts +28 -0
- package/dist/lib/weave.js +83 -0
- package/dist/scrollbar.css +29 -0
- package/dist/themes.stylex.d.ts +49 -0
- package/dist/themes.stylex.js +52 -0
- package/dist/tokens.css +109 -0
- package/dist/tokens.stylex.d.ts +126 -0
- package/dist/tokens.stylex.js +149 -0
- package/package.json +81 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as stylex from "@stylexjs/stylex";
|
|
3
|
+
import { reset, styled } from "../../lib/styled.js";
|
|
4
|
+
import { useCopy } from "../../lib/useCopy.js";
|
|
5
|
+
import { color, font, motion, radius, space, text } from "../../tokens.stylex.js";
|
|
6
|
+
const REDUCED = "@media (prefers-reduced-motion: reduce)";
|
|
7
|
+
const blink = stylex.keyframes({ "50%": { opacity: 0 } });
|
|
8
|
+
const styles = stylex.create({
|
|
9
|
+
block: {
|
|
10
|
+
borderWidth: 1,
|
|
11
|
+
borderStyle: "solid",
|
|
12
|
+
borderColor: color.border,
|
|
13
|
+
borderRadius: radius.lg,
|
|
14
|
+
backgroundColor: color.surface,
|
|
15
|
+
overflow: "hidden",
|
|
16
|
+
},
|
|
17
|
+
head: {
|
|
18
|
+
display: "flex",
|
|
19
|
+
alignItems: "center",
|
|
20
|
+
justifyContent: "space-between",
|
|
21
|
+
gap: space.xs,
|
|
22
|
+
paddingBlock: space.xxs,
|
|
23
|
+
paddingInlineStart: space.sm,
|
|
24
|
+
paddingInlineEnd: space.xxs,
|
|
25
|
+
borderBottomWidth: 1,
|
|
26
|
+
borderBottomStyle: "solid",
|
|
27
|
+
borderBottomColor: color.border,
|
|
28
|
+
},
|
|
29
|
+
lang: {
|
|
30
|
+
fontFamily: font.mono,
|
|
31
|
+
fontSize: "0.68rem",
|
|
32
|
+
lineHeight: text.leadingSnug,
|
|
33
|
+
letterSpacing: "0.04em",
|
|
34
|
+
color: color.textFaint,
|
|
35
|
+
},
|
|
36
|
+
copy: {
|
|
37
|
+
display: "inline-flex",
|
|
38
|
+
alignItems: "center",
|
|
39
|
+
gap: space.xxs,
|
|
40
|
+
fontFamily: font.body,
|
|
41
|
+
fontSize: text.xs,
|
|
42
|
+
color: { default: color.textMuted, ":hover": color.text },
|
|
43
|
+
backgroundColor: {
|
|
44
|
+
default: "transparent",
|
|
45
|
+
":hover": `color-mix(in srgb, ${color.border} 40%, ${color.surface})`,
|
|
46
|
+
},
|
|
47
|
+
paddingBlock: space.xxs,
|
|
48
|
+
paddingInline: space.xxs,
|
|
49
|
+
borderRadius: radius.sm,
|
|
50
|
+
cursor: "pointer",
|
|
51
|
+
transitionProperty: "background-color, color",
|
|
52
|
+
transitionDuration: { default: motion.fast, [REDUCED]: "0s" },
|
|
53
|
+
outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` },
|
|
54
|
+
outlineOffset: -1,
|
|
55
|
+
},
|
|
56
|
+
copied: { color: color.accent },
|
|
57
|
+
pre: {
|
|
58
|
+
margin: 0,
|
|
59
|
+
paddingBlock: space.xs,
|
|
60
|
+
paddingInline: space.sm,
|
|
61
|
+
overflowX: "auto",
|
|
62
|
+
fontFamily: font.mono,
|
|
63
|
+
fontSize: text.code,
|
|
64
|
+
lineHeight: text.leadingNormal,
|
|
65
|
+
color: color.text,
|
|
66
|
+
outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` },
|
|
67
|
+
outlineOffset: -2,
|
|
68
|
+
},
|
|
69
|
+
code: { font: "inherit" },
|
|
70
|
+
cursor: {
|
|
71
|
+
display: "inline-block",
|
|
72
|
+
width: 1,
|
|
73
|
+
height: "1.05em",
|
|
74
|
+
backgroundColor: color.text,
|
|
75
|
+
verticalAlign: "text-bottom",
|
|
76
|
+
marginInlineStart: 1,
|
|
77
|
+
animationName: { default: blink, [REDUCED]: "none" },
|
|
78
|
+
animationDuration: "1s",
|
|
79
|
+
animationTimingFunction: "steps(2, start)",
|
|
80
|
+
animationIterationCount: "infinite",
|
|
81
|
+
},
|
|
82
|
+
inline: {
|
|
83
|
+
fontFamily: font.mono,
|
|
84
|
+
fontSize: text.code,
|
|
85
|
+
lineHeight: text.leadingNormal,
|
|
86
|
+
backgroundColor: `color-mix(in srgb, ${color.border} 40%, ${color.surface})`,
|
|
87
|
+
borderWidth: 1,
|
|
88
|
+
borderStyle: "solid",
|
|
89
|
+
borderColor: color.border,
|
|
90
|
+
borderRadius: radius.sm,
|
|
91
|
+
paddingInline: "0.3em",
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
function CopyIcon() {
|
|
95
|
+
return (_jsxs("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", "aria-hidden": "true", children: [_jsx("rect", { x: "9", y: "9", width: "11", height: "11", rx: "2" }), _jsx("path", { d: "M5 15V5a2 2 0 0 1 2-2h10" })] }));
|
|
96
|
+
}
|
|
97
|
+
export function CodeBlock({ lang, code, streaming = false, copyLabel = "複製", copiedLabel = "已複製 ✓", }) {
|
|
98
|
+
const { copied, copy } = useCopy();
|
|
99
|
+
return (_jsxs("div", { ...stylex.props(styles.block), children: [_jsxs("div", { ...stylex.props(styles.head), children: [_jsx("span", { ...stylex.props(styles.lang), children: lang ?? "" }), _jsxs("button", { type: "button", onClick: () => copy(code), ...stylex.props(reset.control, styles.copy, copied && styles.copied), children: [!copied && _jsx(CopyIcon, {}), copied ? copiedLabel : copyLabel] })] }), _jsx("pre", { tabIndex: 0, role: "region", "aria-label": lang ? `${lang} 程式碼` : "程式碼", ...stylex.props(styles.pre), children: _jsxs("code", { ...stylex.props(styles.code), children: [code, streaming && _jsx("span", { "aria-hidden": "true", ...stylex.props(styles.cursor) })] }) })] }));
|
|
100
|
+
}
|
|
101
|
+
export function InlineCode(props) {
|
|
102
|
+
return _jsx("code", { ...props, ...styled(props, styles.inline) });
|
|
103
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type SourceRef = {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
kind: string;
|
|
6
|
+
};
|
|
7
|
+
export type SlashCommand = {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
kind?: string;
|
|
11
|
+
};
|
|
12
|
+
export type ComposerProps = {
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
hint?: ReactNode;
|
|
15
|
+
models?: string[];
|
|
16
|
+
model?: string;
|
|
17
|
+
onModelChange?: (model: string) => void;
|
|
18
|
+
sources?: (query: string) => Promise<SourceRef[]>;
|
|
19
|
+
commands?: SlashCommand[];
|
|
20
|
+
micActive?: boolean;
|
|
21
|
+
onMicToggle?: () => void;
|
|
22
|
+
onSubmit: (text: string, refs: SourceRef[]) => void;
|
|
23
|
+
label?: string;
|
|
24
|
+
sourcesLabel?: string;
|
|
25
|
+
commandsLabel?: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function Composer({ placeholder, hint, models, model, onModelChange, sources, commands, micActive, onMicToggle, onSubmit, label, sourcesLabel, commandsLabel, }: ComposerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as stylex from "@stylexjs/stylex";
|
|
3
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState, } from "react";
|
|
4
|
+
import { reset } from "../../lib/styled.js";
|
|
5
|
+
import { popupStyles } from "../../lib/popup.js";
|
|
6
|
+
import { color, font, motion, radius, space, text } from "../../tokens.stylex.js";
|
|
7
|
+
const REDUCED = "@media (prefers-reduced-motion: reduce)";
|
|
8
|
+
const styles = stylex.create({
|
|
9
|
+
composer: {
|
|
10
|
+
position: "relative",
|
|
11
|
+
backgroundColor: color.surface,
|
|
12
|
+
borderWidth: 1,
|
|
13
|
+
borderStyle: "solid",
|
|
14
|
+
borderColor: { default: color.border, ":focus-within": color.accent },
|
|
15
|
+
borderRadius: radius.lg,
|
|
16
|
+
paddingBlock: space.xs,
|
|
17
|
+
paddingInline: space.xs,
|
|
18
|
+
display: "grid",
|
|
19
|
+
gap: space.xxs,
|
|
20
|
+
transitionProperty: "border-color",
|
|
21
|
+
transitionDuration: { default: "140ms", [REDUCED]: "0s" },
|
|
22
|
+
outline: { default: "none", ":focus-within": `1px solid ${color.accent}` },
|
|
23
|
+
outlineOffset: -1,
|
|
24
|
+
},
|
|
25
|
+
textarea: {
|
|
26
|
+
width: "100%",
|
|
27
|
+
boxSizing: "border-box",
|
|
28
|
+
fontFamily: font.body,
|
|
29
|
+
fontSize: text.sm,
|
|
30
|
+
lineHeight: text.leadingNormal,
|
|
31
|
+
color: color.text,
|
|
32
|
+
paddingBlock: space.xxs,
|
|
33
|
+
paddingInline: space.xxs,
|
|
34
|
+
resize: "none",
|
|
35
|
+
fieldSizing: "content",
|
|
36
|
+
maxHeight: "11rem",
|
|
37
|
+
overflowY: "auto",
|
|
38
|
+
whiteSpace: "pre-wrap",
|
|
39
|
+
overflowWrap: "anywhere",
|
|
40
|
+
"::placeholder": { color: color.textFaint },
|
|
41
|
+
},
|
|
42
|
+
bar: { display: "flex", alignItems: "center", gap: space.xxs },
|
|
43
|
+
iconButton: {
|
|
44
|
+
display: "grid",
|
|
45
|
+
placeItems: "center",
|
|
46
|
+
width: "1.9rem",
|
|
47
|
+
height: "1.9rem",
|
|
48
|
+
borderRadius: radius.sm,
|
|
49
|
+
color: { default: color.textMuted, ":hover": color.text },
|
|
50
|
+
backgroundColor: { default: "transparent", ":hover": color.accentSubtle },
|
|
51
|
+
cursor: "pointer",
|
|
52
|
+
transitionProperty: "background-color, color",
|
|
53
|
+
transitionDuration: { default: motion.fast, [REDUCED]: "0s" },
|
|
54
|
+
outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` },
|
|
55
|
+
outlineOffset: -1,
|
|
56
|
+
},
|
|
57
|
+
iconButtonOn: { backgroundColor: color.accentSubtle, color: color.accent },
|
|
58
|
+
spacer: { flex: 1 },
|
|
59
|
+
model: {
|
|
60
|
+
fontFamily: font.body,
|
|
61
|
+
fontSize: "0.78rem",
|
|
62
|
+
fontWeight: 500,
|
|
63
|
+
lineHeight: 1,
|
|
64
|
+
color: color.textMuted,
|
|
65
|
+
backgroundColor: "transparent",
|
|
66
|
+
borderWidth: 1,
|
|
67
|
+
borderStyle: "solid",
|
|
68
|
+
borderColor: { default: "transparent", ":hover": color.border },
|
|
69
|
+
borderRadius: radius.sm,
|
|
70
|
+
paddingBlock: space.xxs,
|
|
71
|
+
paddingInline: space.xxs,
|
|
72
|
+
cursor: "pointer",
|
|
73
|
+
transitionProperty: "border-color",
|
|
74
|
+
transitionDuration: { default: motion.fast, [REDUCED]: "0s" },
|
|
75
|
+
outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` },
|
|
76
|
+
outlineOffset: -1,
|
|
77
|
+
},
|
|
78
|
+
send: {
|
|
79
|
+
display: "grid",
|
|
80
|
+
placeItems: "center",
|
|
81
|
+
width: "1.9rem",
|
|
82
|
+
height: "1.9rem",
|
|
83
|
+
borderRadius: radius.sm,
|
|
84
|
+
backgroundColor: { default: color.accent, ":disabled": color.border },
|
|
85
|
+
color: { default: color.accentText, ":disabled": color.textFaint },
|
|
86
|
+
cursor: { default: "pointer", ":disabled": "not-allowed" },
|
|
87
|
+
outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` },
|
|
88
|
+
outlineOffset: 1,
|
|
89
|
+
},
|
|
90
|
+
popup: {
|
|
91
|
+
position: "absolute",
|
|
92
|
+
zIndex: 10,
|
|
93
|
+
bottom: `calc(100% + ${space.xxs})`,
|
|
94
|
+
insetInlineStart: space.xs,
|
|
95
|
+
width: `min(20rem, calc(100% - ${space.md}))`,
|
|
96
|
+
transformOrigin: "bottom",
|
|
97
|
+
},
|
|
98
|
+
groupLabel: {
|
|
99
|
+
fontFamily: font.mono,
|
|
100
|
+
fontSize: "0.65rem",
|
|
101
|
+
fontWeight: 600,
|
|
102
|
+
lineHeight: 1,
|
|
103
|
+
letterSpacing: "0.08em",
|
|
104
|
+
textTransform: "uppercase",
|
|
105
|
+
color: color.textFaint,
|
|
106
|
+
paddingBlock: space.xxs,
|
|
107
|
+
paddingInline: space.xs,
|
|
108
|
+
},
|
|
109
|
+
list: { listStyle: "none", margin: 0, padding: space.xxs },
|
|
110
|
+
option: {
|
|
111
|
+
display: "flex",
|
|
112
|
+
alignItems: "center",
|
|
113
|
+
gap: space.xs,
|
|
114
|
+
borderRadius: radius.sm,
|
|
115
|
+
paddingBlock: "0.42rem",
|
|
116
|
+
paddingInline: space.xs,
|
|
117
|
+
fontFamily: font.body,
|
|
118
|
+
fontSize: text.sm,
|
|
119
|
+
color: color.text,
|
|
120
|
+
cursor: "pointer",
|
|
121
|
+
},
|
|
122
|
+
optionActive: {
|
|
123
|
+
backgroundColor: color.accentSubtle,
|
|
124
|
+
outline: `2px solid ${color.focusRing}`,
|
|
125
|
+
outlineOffset: -2,
|
|
126
|
+
"@media (forced-colors: active)": { outline: "2px solid Highlight" },
|
|
127
|
+
},
|
|
128
|
+
kind: { color: color.textFaint, fontSize: "0.72rem", marginInlineStart: "auto" },
|
|
129
|
+
hint: {
|
|
130
|
+
fontFamily: font.body,
|
|
131
|
+
fontSize: "0.72rem",
|
|
132
|
+
color: color.textFaint,
|
|
133
|
+
margin: 0,
|
|
134
|
+
marginInline: space.xxs,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
const AT_PATTERN = /(^|\s)@(\S*)$/;
|
|
138
|
+
const SLASH_PATTERN = /^\/(\S*)$/;
|
|
139
|
+
function AtIcon() {
|
|
140
|
+
return (_jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "4" }), _jsx("path", { d: "M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8" })] }));
|
|
141
|
+
}
|
|
142
|
+
function SlashIcon() {
|
|
143
|
+
return (_jsx("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", "aria-hidden": "true", children: _jsx("path", { d: "m16 4-8 16" }) }));
|
|
144
|
+
}
|
|
145
|
+
function MicIcon() {
|
|
146
|
+
return (_jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", "aria-hidden": "true", children: [_jsx("rect", { x: "9", y: "2", width: "6", height: "12", rx: "3" }), _jsx("path", { d: "M5 10a7 7 0 0 0 14 0" }), _jsx("path", { d: "M12 17v4" })] }));
|
|
147
|
+
}
|
|
148
|
+
function SendIcon() {
|
|
149
|
+
return (_jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", "aria-hidden": "true", children: [_jsx("path", { d: "M12 19V5" }), _jsx("path", { d: "m5 12 7-7 7 7" })] }));
|
|
150
|
+
}
|
|
151
|
+
export function Composer({ placeholder = "跟 agent 說話", hint, models, model, onModelChange, sources, commands, micActive = false, onMicToggle, onSubmit, label = "訊息", sourcesLabel = "@ 來源", commandsLabel = "/ 指令", }) {
|
|
152
|
+
const listId = useId();
|
|
153
|
+
const suggestible = sources != null || commands != null;
|
|
154
|
+
const textarea = useRef(null);
|
|
155
|
+
const [value, setValue] = useState("");
|
|
156
|
+
const [caret, setCaret] = useState(0);
|
|
157
|
+
const [items, setItems] = useState([]);
|
|
158
|
+
const [rawActive, setActive] = useState(0);
|
|
159
|
+
const [picked, setPicked] = useState([]);
|
|
160
|
+
const [dismissed, setDismissed] = useState(false);
|
|
161
|
+
const pendingCaret = useRef(null);
|
|
162
|
+
const latestSources = useRef(sources);
|
|
163
|
+
// Held in a ref so an inline `sources` prop doesn't refetch on every parent
|
|
164
|
+
// render; assigned in an effect that is declared before the fetch below, so
|
|
165
|
+
// it is already current when that one runs.
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
latestSources.current = sources;
|
|
168
|
+
});
|
|
169
|
+
// The caret lives in state so the @/-slash mode can be derived from it, but
|
|
170
|
+
// the DOM caret has to be moved explicitly or the browser parks it at the end.
|
|
171
|
+
useLayoutEffect(() => {
|
|
172
|
+
if (pendingCaret.current == null)
|
|
173
|
+
return;
|
|
174
|
+
textarea.current?.setSelectionRange(pendingCaret.current, pendingCaret.current);
|
|
175
|
+
pendingCaret.current = null;
|
|
176
|
+
});
|
|
177
|
+
const before = value.slice(0, caret);
|
|
178
|
+
const atMatch = AT_PATTERN.exec(before);
|
|
179
|
+
const slashMatch = SLASH_PATTERN.exec(before);
|
|
180
|
+
const mode = atMatch ? "sources" : slashMatch ? "commands" : null;
|
|
181
|
+
const query = atMatch?.[2] ?? slashMatch?.[1] ?? "";
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
if (mode !== "sources" || latestSources.current == null)
|
|
184
|
+
return;
|
|
185
|
+
let cancelled = false;
|
|
186
|
+
latestSources
|
|
187
|
+
.current(query)
|
|
188
|
+
.then((result) => {
|
|
189
|
+
if (!cancelled) {
|
|
190
|
+
setItems(result);
|
|
191
|
+
setActive(0);
|
|
192
|
+
}
|
|
193
|
+
})
|
|
194
|
+
.catch(() => {
|
|
195
|
+
if (!cancelled)
|
|
196
|
+
setItems([]);
|
|
197
|
+
});
|
|
198
|
+
return () => {
|
|
199
|
+
cancelled = true;
|
|
200
|
+
};
|
|
201
|
+
}, [mode, query]);
|
|
202
|
+
const options = mode === "commands"
|
|
203
|
+
? (commands ?? [])
|
|
204
|
+
.filter((command) => command.label.toLowerCase().includes(query.toLowerCase()))
|
|
205
|
+
.map((command) => ({ id: command.id, label: command.label, kind: command.kind ?? "指令" }))
|
|
206
|
+
: mode === "sources"
|
|
207
|
+
? items
|
|
208
|
+
: [];
|
|
209
|
+
const open = mode != null && options.length > 0 && !dismissed;
|
|
210
|
+
const active = options.length === 0 ? 0 : Math.min(rawActive, options.length - 1);
|
|
211
|
+
const canSend = value.trim().length > 0;
|
|
212
|
+
function moveCaret(next, position) {
|
|
213
|
+
setValue(next);
|
|
214
|
+
setCaret(position);
|
|
215
|
+
pendingCaret.current = position;
|
|
216
|
+
}
|
|
217
|
+
function complete(option) {
|
|
218
|
+
const tail = value.slice(caret);
|
|
219
|
+
// Function replacers: a label containing $&, $1 … must go in literally.
|
|
220
|
+
const head = mode === "commands"
|
|
221
|
+
? before.replace(SLASH_PATTERN, () => `/${option.label} `)
|
|
222
|
+
: before.replace(AT_PATTERN, (_, lead) => `${lead}@${option.label} `);
|
|
223
|
+
moveCaret(head + tail, head.length);
|
|
224
|
+
if (mode === "sources")
|
|
225
|
+
setPicked((refs) => [...refs, option]);
|
|
226
|
+
textarea.current?.focus();
|
|
227
|
+
}
|
|
228
|
+
function submit() {
|
|
229
|
+
if (!canSend)
|
|
230
|
+
return;
|
|
231
|
+
// A ref the user deleted again is not a ref any more.
|
|
232
|
+
onSubmit(value, picked.filter((ref) => value.includes(`@${ref.label}`)));
|
|
233
|
+
setValue("");
|
|
234
|
+
setPicked([]);
|
|
235
|
+
setCaret(0);
|
|
236
|
+
setDismissed(false);
|
|
237
|
+
}
|
|
238
|
+
function onKeyDown(event) {
|
|
239
|
+
// Enter while an IME candidate is open commits the candidate, not the message.
|
|
240
|
+
if (event.nativeEvent.isComposing)
|
|
241
|
+
return;
|
|
242
|
+
if (open && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
|
|
243
|
+
event.preventDefault();
|
|
244
|
+
setActive((index) => (index + (event.key === "ArrowDown" ? 1 : options.length - 1)) % options.length);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (open && event.key === "Enter" && !event.shiftKey) {
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
complete(options[active]);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
253
|
+
event.preventDefault();
|
|
254
|
+
submit();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (event.key === "Escape" && open) {
|
|
258
|
+
event.preventDefault();
|
|
259
|
+
setDismissed(true);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function insertMarker(marker) {
|
|
263
|
+
const position = textarea.current?.selectionStart ?? value.length;
|
|
264
|
+
const lead = position > 0 && !/\s$/.test(value.slice(0, position)) ? " " : "";
|
|
265
|
+
const next = `${value.slice(0, position)}${lead}${marker}${value.slice(position)}`;
|
|
266
|
+
setDismissed(false);
|
|
267
|
+
moveCaret(next, position + lead.length + marker.length);
|
|
268
|
+
textarea.current?.focus();
|
|
269
|
+
}
|
|
270
|
+
return (_jsxs("div", { ...stylex.props(styles.composer), children: [open && (_jsxs("div", { ...stylex.props(popupStyles.surface, styles.popup), children: [_jsx("div", { ...stylex.props(styles.groupLabel), children: mode === "commands" ? commandsLabel : sourcesLabel }), _jsx("ul", { id: listId, role: "listbox", "aria-label": mode === "commands" ? commandsLabel : sourcesLabel, ...stylex.props(styles.list), children: options.map((option, index) => (_jsxs("li", { id: `${listId}-${index}`, role: "option", "aria-selected": index === active, onMouseDown: (event) => {
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
complete(option);
|
|
273
|
+
}, ...stylex.props(styles.option, index === active && styles.optionActive), children: [option.label, _jsx("small", { ...stylex.props(styles.kind), children: option.kind })] }, option.id))) })] })), _jsx("textarea", { ref: textarea, rows: 1, "aria-label": label, role: suggestible ? "combobox" : undefined, "aria-expanded": suggestible ? open : undefined, "aria-autocomplete": suggestible ? "list" : undefined, "aria-haspopup": suggestible ? "listbox" : undefined, "aria-controls": open ? listId : undefined, "aria-activedescendant": open ? `${listId}-${active}` : undefined, placeholder: placeholder, value: value, onChange: (event) => {
|
|
274
|
+
setValue(event.currentTarget.value);
|
|
275
|
+
setCaret(event.currentTarget.selectionStart ?? event.currentTarget.value.length);
|
|
276
|
+
setDismissed(false);
|
|
277
|
+
}, onKeyUp: (event) => setCaret(event.currentTarget.selectionStart ?? 0), onClick: (event) => setCaret(event.currentTarget.selectionStart ?? 0), onKeyDown: onKeyDown, ...stylex.props(reset.control, styles.textarea) }), _jsxs("div", { ...stylex.props(styles.bar), children: [_jsx("button", { type: "button", "aria-label": `加入來源(@)`, "aria-expanded": mode === "sources" && open, onClick: () => insertMarker("@"), ...stylex.props(reset.control, styles.iconButton), children: _jsx(AtIcon, {}) }), _jsx("button", { type: "button", "aria-label": "\u6307\u4EE4(/)", "aria-expanded": mode === "commands" && open, onClick: () => insertMarker("/"), ...stylex.props(reset.control, styles.iconButton), children: _jsx(SlashIcon, {}) }), _jsx("span", { ...stylex.props(styles.spacer) }), models != null && models.length > 0 && (_jsx("select", { "aria-label": "\u6A21\u578B", value: model, onChange: (event) => onModelChange?.(event.currentTarget.value), ...stylex.props(styles.model), children: models.map((option) => (_jsx("option", { value: option, children: option }, option))) })), onMicToggle != null && (_jsx("button", { type: "button", "aria-label": "\u8A9E\u97F3\u8F38\u5165", "aria-pressed": micActive, onClick: onMicToggle, ...stylex.props(reset.control, styles.iconButton, micActive && styles.iconButtonOn), children: _jsx(MicIcon, {}) })), _jsx("button", { type: "button", "aria-label": "\u9001\u51FA", disabled: !canSend, onClick: submit, ...stylex.props(reset.control, styles.send), children: _jsx(SendIcon, {}) })] }), hint != null && _jsx("p", { ...stylex.props(styles.hint), children: hint })] }));
|
|
278
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type SortState = {
|
|
3
|
+
col: string;
|
|
4
|
+
dir: "asc" | "desc";
|
|
5
|
+
} | null;
|
|
6
|
+
export type DataTableColumn<Row> = {
|
|
7
|
+
id: string;
|
|
8
|
+
header: string;
|
|
9
|
+
mono?: boolean;
|
|
10
|
+
sortable?: boolean;
|
|
11
|
+
editable?: boolean;
|
|
12
|
+
value?: (row: Row) => string;
|
|
13
|
+
cell?: (row: Row) => ReactNode;
|
|
14
|
+
onCommit?: (row: Row, next: string) => void;
|
|
15
|
+
};
|
|
16
|
+
export type DataTableProps<Row> = {
|
|
17
|
+
rows: Row[];
|
|
18
|
+
/** Total before filtering, for the "N / M" readout. Defaults to `rows.length`. */
|
|
19
|
+
total?: number;
|
|
20
|
+
rowKey: (row: Row) => string;
|
|
21
|
+
columns: DataTableColumn<Row>[];
|
|
22
|
+
label: string;
|
|
23
|
+
filter?: string;
|
|
24
|
+
onFilterChange?: (filter: string) => void;
|
|
25
|
+
filterPlaceholder?: string;
|
|
26
|
+
sort?: SortState;
|
|
27
|
+
onSortChange?: (sort: SortState) => void;
|
|
28
|
+
selected?: Set<string>;
|
|
29
|
+
onSelectedChange?: (selected: Set<string>) => void;
|
|
30
|
+
emptyState?: (query: string) => ReactNode;
|
|
31
|
+
onClearFilter?: () => void;
|
|
32
|
+
countLabel?: (shown: number, total: number) => string;
|
|
33
|
+
selectLabel?: (key: string) => string;
|
|
34
|
+
selectAllLabel?: string;
|
|
35
|
+
editLabel?: (column: string, key: string) => string;
|
|
36
|
+
clearLabel?: string;
|
|
37
|
+
};
|
|
38
|
+
export declare function DataTable<Row>({ rows, total, rowKey, columns, label, filter, onFilterChange, filterPlaceholder, sort, onSortChange, selected, onSelectedChange, emptyState, onClearFilter, countLabel, selectLabel, selectAllLabel, editLabel, clearLabel, }: DataTableProps<Row>): import("react").JSX.Element;
|