@anvia/react-ui 0.6.3 → 0.7.1
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 +19 -3
- package/dist/index.js +41 -1
- package/dist/index.js.map +1 -1
- package/dist/styles.css +22 -0
- package/package.json +13 -13
package/dist/index.d.ts
CHANGED
|
@@ -11,13 +11,29 @@ export { T as ThreadContextValue, u as useThread } from './thread-uEm8hH0s.js';
|
|
|
11
11
|
export { T as ThreadListController, a as ThreadListItemContextValue, b as ThreadListProvider, c as ThreadListProviderProps, d as ThreadListRecord, u as useThreadList, e as useThreadListItem } from './thread-list-On8db4XL.js';
|
|
12
12
|
export { Composer, ComposerSubmitMessage, ComposerSubmitMessageArgs, Thread } from './chat/index.js';
|
|
13
13
|
export { Completion } from './completion/index.js';
|
|
14
|
+
import * as react from 'react';
|
|
15
|
+
import { ReactNode } from 'react';
|
|
16
|
+
import { UseChatResult } from '@anvia/react';
|
|
17
|
+
import { P as PrimitiveProps } from './render-CRKWam2v.js';
|
|
18
|
+
export { a as PrimitiveRef } from './render-CRKWam2v.js';
|
|
14
19
|
export { HumanInput } from './human-input/index.js';
|
|
15
20
|
export { Image } from './image/index.js';
|
|
16
21
|
export { Message, MessageAttachmentPart, MessageEntityProps, MessagePartsFilter, MessageStreamOptions, MessageToolPart, MessageToolRenderWhen } from './message/index.js';
|
|
17
22
|
export { SelectionToolbar } from './selection-toolbar/index.js';
|
|
18
|
-
export { P as PrimitiveProps, a as PrimitiveRef } from './render-CRKWam2v.js';
|
|
19
23
|
export { StreamMarkdown, StreamMarkdownProps } from './stream/index.js';
|
|
20
24
|
export { ThreadList, ThreadListItem } from './thread-list/index.js';
|
|
21
|
-
import '@anvia/react';
|
|
22
|
-
import 'react';
|
|
23
25
|
import 'react-markdown';
|
|
26
|
+
|
|
27
|
+
type ContextUsage = NonNullable<UseChatResult["contextUsage"]>;
|
|
28
|
+
type ContextMeterProps = Omit<PrimitiveProps<"div">, "children"> & {
|
|
29
|
+
usage?: ContextUsage;
|
|
30
|
+
display?: "remaining" | "used";
|
|
31
|
+
children?: ReactNode | ((usage: ContextUsage) => ReactNode);
|
|
32
|
+
};
|
|
33
|
+
declare const ContextMeter: react.ForwardRefExoticComponent<Omit<PrimitiveProps<"div">, "children"> & {
|
|
34
|
+
usage?: ContextUsage;
|
|
35
|
+
display?: "remaining" | "used";
|
|
36
|
+
children?: ReactNode | ((usage: ContextUsage) => ReactNode);
|
|
37
|
+
} & react.RefAttributes<HTMLDivElement>>;
|
|
38
|
+
|
|
39
|
+
export { ContextMeter, type ContextMeterProps, PrimitiveProps };
|
package/dist/index.js
CHANGED
|
@@ -27,7 +27,9 @@ import {
|
|
|
27
27
|
import {
|
|
28
28
|
Attachment
|
|
29
29
|
} from "./chunk-SBYUKODG.js";
|
|
30
|
-
import
|
|
30
|
+
import {
|
|
31
|
+
renderPrimitive
|
|
32
|
+
} from "./chunk-T3ZFZ3NP.js";
|
|
31
33
|
import {
|
|
32
34
|
ChatProvider,
|
|
33
35
|
CompletionProvider,
|
|
@@ -49,12 +51,50 @@ import {
|
|
|
49
51
|
useThreadList,
|
|
50
52
|
useThreadListItem
|
|
51
53
|
} from "./chunk-43U2XQP2.js";
|
|
54
|
+
|
|
55
|
+
// src/context-meter.tsx
|
|
56
|
+
import { forwardRef } from "react";
|
|
57
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
58
|
+
var ContextMeter = forwardRef(function ContextMeter2({ usage, display = "remaining", children, ...props }, ref) {
|
|
59
|
+
if (usage === void 0) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const percent = display === "remaining" ? usage.remainingPercent : usage.usedPercent;
|
|
63
|
+
const roundedPercent = Math.round(percent);
|
|
64
|
+
const label = `${roundedPercent}% context ${display === "remaining" ? "left" : "used"}`;
|
|
65
|
+
const content = typeof children === "function" ? children(usage) : children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
66
|
+
/* @__PURE__ */ jsx("span", { "data-anvia-context-meter-label": "", children: label }),
|
|
67
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", "data-anvia-context-meter-track": "", children: /* @__PURE__ */ jsx(
|
|
68
|
+
"span",
|
|
69
|
+
{
|
|
70
|
+
"data-anvia-context-meter-value": "",
|
|
71
|
+
style: { width: `${Math.min(100, Math.max(0, percent))}%` }
|
|
72
|
+
}
|
|
73
|
+
) })
|
|
74
|
+
] });
|
|
75
|
+
return renderPrimitive(
|
|
76
|
+
"div",
|
|
77
|
+
{
|
|
78
|
+
...props,
|
|
79
|
+
children: content,
|
|
80
|
+
"aria-label": props["aria-label"] ?? label,
|
|
81
|
+
"aria-valuemax": 100,
|
|
82
|
+
"aria-valuemin": 0,
|
|
83
|
+
"aria-valuenow": roundedPercent,
|
|
84
|
+
"data-anvia-context-meter": "",
|
|
85
|
+
"data-display": display,
|
|
86
|
+
role: props.role ?? "progressbar"
|
|
87
|
+
},
|
|
88
|
+
ref
|
|
89
|
+
);
|
|
90
|
+
});
|
|
52
91
|
export {
|
|
53
92
|
Attachment,
|
|
54
93
|
ChatProvider,
|
|
55
94
|
Completion,
|
|
56
95
|
CompletionProvider,
|
|
57
96
|
Composer,
|
|
97
|
+
ContextMeter,
|
|
58
98
|
HumanInput,
|
|
59
99
|
Image,
|
|
60
100
|
Message,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/context-meter.tsx"],"sourcesContent":["import type { UseChatResult } from \"@anvia/react\";\nimport { forwardRef, type ReactNode } from \"react\";\n\nimport { type PrimitiveProps, renderPrimitive } from \"./primitives\";\n\ntype ContextUsage = NonNullable<UseChatResult[\"contextUsage\"]>;\n\nexport type ContextMeterProps = Omit<PrimitiveProps<\"div\">, \"children\"> & {\n usage?: ContextUsage;\n display?: \"remaining\" | \"used\";\n children?: ReactNode | ((usage: ContextUsage) => ReactNode);\n};\n\nexport const ContextMeter = forwardRef<HTMLDivElement, ContextMeterProps>(function ContextMeter(\n { usage, display = \"remaining\", children, ...props },\n ref,\n) {\n if (usage === undefined) {\n return null;\n }\n\n const percent = display === \"remaining\" ? usage.remainingPercent : usage.usedPercent;\n const roundedPercent = Math.round(percent);\n const label = `${roundedPercent}% context ${display === \"remaining\" ? \"left\" : \"used\"}`;\n const content =\n typeof children === \"function\"\n ? children(usage)\n : (children ?? (\n <>\n <span data-anvia-context-meter-label=\"\">{label}</span>\n <span aria-hidden=\"true\" data-anvia-context-meter-track=\"\">\n <span\n data-anvia-context-meter-value=\"\"\n style={{ width: `${Math.min(100, Math.max(0, percent))}%` }}\n />\n </span>\n </>\n ));\n\n return renderPrimitive(\n \"div\",\n {\n ...props,\n children: content,\n \"aria-label\": props[\"aria-label\"] ?? label,\n \"aria-valuemax\": 100,\n \"aria-valuemin\": 0,\n \"aria-valuenow\": roundedPercent,\n \"data-anvia-context-meter\": \"\",\n \"data-display\": display,\n role: props.role ?? \"progressbar\",\n } as PrimitiveProps<\"div\">,\n ref,\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,kBAAkC;AA2BjC,mBACE,KADF;AAfH,IAAM,eAAe,WAA8C,SAASA,cACjF,EAAE,OAAO,UAAU,aAAa,UAAU,GAAG,MAAM,GACnD,KACA;AACA,MAAI,UAAU,QAAW;AACvB,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,YAAY,cAAc,MAAM,mBAAmB,MAAM;AACzE,QAAM,iBAAiB,KAAK,MAAM,OAAO;AACzC,QAAM,QAAQ,GAAG,cAAc,aAAa,YAAY,cAAc,SAAS,MAAM;AACrF,QAAM,UACJ,OAAO,aAAa,aAChB,SAAS,KAAK,IACb,YACC,iCACE;AAAA,wBAAC,UAAK,kCAA+B,IAAI,iBAAM;AAAA,IAC/C,oBAAC,UAAK,eAAY,QAAO,kCAA+B,IACtD;AAAA,MAAC;AAAA;AAAA,QACC,kCAA+B;AAAA,QAC/B,OAAO,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC,CAAC,IAAI;AAAA;AAAA,IAC5D,GACF;AAAA,KACF;AAGR,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,GAAG;AAAA,MACH,UAAU;AAAA,MACV,cAAc,MAAM,YAAY,KAAK;AAAA,MACrC,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,MACjB,4BAA4B;AAAA,MAC5B,gBAAgB;AAAA,MAChB,MAAM,MAAM,QAAQ;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AACF,CAAC;","names":["ContextMeter"]}
|
package/dist/styles.css
CHANGED
|
@@ -85,6 +85,28 @@
|
|
|
85
85
|
z-index: 60;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
[data-anvia-context-meter] {
|
|
89
|
+
display: inline-grid;
|
|
90
|
+
min-width: 8rem;
|
|
91
|
+
gap: 0.375rem;
|
|
92
|
+
font-size: 0.75rem;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
[data-anvia-context-meter-track] {
|
|
96
|
+
display: block;
|
|
97
|
+
height: 0.25rem;
|
|
98
|
+
overflow: hidden;
|
|
99
|
+
border-radius: 9999px;
|
|
100
|
+
background: color-mix(in srgb, currentcolor 20%, transparent);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
[data-anvia-context-meter-value] {
|
|
104
|
+
display: block;
|
|
105
|
+
height: 100%;
|
|
106
|
+
border-radius: inherit;
|
|
107
|
+
background: currentcolor;
|
|
108
|
+
}
|
|
109
|
+
|
|
88
110
|
[data-state="disabled"] {
|
|
89
111
|
opacity: 0.55;
|
|
90
112
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anvia/react-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Composable React UI primitives for Anvia chat and completion experiences.",
|
|
5
5
|
"author": "anvia",
|
|
6
6
|
"maintainer": "Indra Zulfi",
|
|
@@ -69,17 +69,17 @@
|
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@radix-ui/react-slot": "^1.3.3",
|
|
72
|
-
"@tiptap/core": "^3.
|
|
73
|
-
"@tiptap/extension-document": "^3.
|
|
74
|
-
"@tiptap/extension-hard-break": "^3.
|
|
75
|
-
"@tiptap/extension-mention": "^3.
|
|
76
|
-
"@tiptap/extension-paragraph": "^3.
|
|
77
|
-
"@tiptap/extension-placeholder": "^3.
|
|
78
|
-
"@tiptap/extension-text": "^3.
|
|
79
|
-
"@tiptap/pm": "^3.
|
|
80
|
-
"@tiptap/react": "^3.
|
|
81
|
-
"@tiptap/suggestion": "^3.
|
|
82
|
-
"marked": "^18.0.
|
|
72
|
+
"@tiptap/core": "^3.29.2",
|
|
73
|
+
"@tiptap/extension-document": "^3.29.2",
|
|
74
|
+
"@tiptap/extension-hard-break": "^3.29.2",
|
|
75
|
+
"@tiptap/extension-mention": "^3.29.2",
|
|
76
|
+
"@tiptap/extension-paragraph": "^3.29.2",
|
|
77
|
+
"@tiptap/extension-placeholder": "^3.29.2",
|
|
78
|
+
"@tiptap/extension-text": "^3.29.2",
|
|
79
|
+
"@tiptap/pm": "^3.29.2",
|
|
80
|
+
"@tiptap/react": "^3.29.2",
|
|
81
|
+
"@tiptap/suggestion": "^3.29.2",
|
|
82
|
+
"marked": "^18.0.9",
|
|
83
83
|
"react-markdown": "^10.1.0",
|
|
84
84
|
"remark-gfm": "^4.0.1"
|
|
85
85
|
},
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"tsup": "^8.5.0",
|
|
101
101
|
"typescript": "^5.9.3",
|
|
102
102
|
"vitest": "^4.0.8",
|
|
103
|
-
"@anvia/react": "0.
|
|
103
|
+
"@anvia/react": "0.11.4"
|
|
104
104
|
},
|
|
105
105
|
"scripts": {
|
|
106
106
|
"build": "tsup src/index.ts src/attachment/index.ts src/chat/index.ts src/completion/index.ts src/human-input/index.ts src/image/index.ts src/message/index.ts src/selection-toolbar/index.ts src/shared.ts src/stream/index.ts src/thread-list/index.ts --format esm --dts --sourcemap --clean --external react --external react-dom && cp src/styles.css dist/styles.css && cp src/stream/styles.css dist/stream/styles.css",
|