@duskmoon-dev/components 0.3.1 → 0.3.3
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/README.md +2 -2
- package/dist/{chunk-r9wkv7xd.js → chunk-fwjzvsrx.js} +3 -3
- package/dist/classes/chat.d.ts +35 -0
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.js +1271 -1184
- package/dist/components/anchor/index.js +2 -2
- package/dist/components/app/index.js +85 -85
- package/dist/components/cascader/index.js +2 -2
- package/dist/components/chat/Chat.d.ts +14 -0
- package/dist/components/chat/Chat.types.d.ts +47 -0
- package/dist/components/chat/index.d.ts +2 -0
- package/dist/components/chat/index.js +220 -0
- package/dist/components/color-picker/index.js +4 -4
- package/dist/components/config-provider/index.js +2 -2
- package/dist/components/dm-breadcrumb/index.js +18 -18
- package/dist/components/dm-date-picker/index.js +94 -94
- package/dist/components/dm-drawer/index.js +16 -16
- package/dist/components/dm-layout/index.js +189 -189
- package/dist/components/dm-menu/index.js +24 -24
- package/dist/components/dm-message/index.js +18 -18
- package/dist/components/dm-page-header/index.js +158 -158
- package/dist/components/dm-pagination/index.js +39 -39
- package/dist/components/dm-pro-table/index.js +1558 -1558
- package/dist/components/dm-provider/index.js +94 -94
- package/dist/components/dm-query/index.js +33 -31
- package/dist/components/dm-search/index.js +25 -25
- package/dist/components/dm-splitter/index.js +32 -32
- package/dist/components/dm-status/index.js +25 -25
- package/dist/components/dm-table/index.js +595 -595
- package/dist/components/dm-tabs/index.js +34 -34
- package/dist/components/dm-toolbar/index.js +23 -23
- package/dist/components/dm-tree/index.js +92 -92
- package/dist/components/dm-truncate/index.js +33 -33
- package/dist/components/dropdown/index.js +83 -83
- package/dist/components/form/index.js +2 -2
- package/dist/components/grid/index.js +2 -2
- package/dist/components/input/index.js +4 -4
- package/dist/components/markdown/index.js +1 -1
- package/dist/components/message/index.js +5 -5
- package/dist/components/notification/index.js +2 -2
- package/dist/components/popconfirm/index.js +42 -42
- package/dist/components/skeleton/index.js +5 -5
- package/dist/components/spin/index.js +2 -2
- package/dist/components/steps/index.js +2 -2
- package/dist/components/table/index.js +2 -2
- package/dist/components/tabs/index.js +2 -2
- package/dist/components/tag/index.js +2 -2
- package/dist/components/tour/index.js +62 -62
- package/dist/components/typography/index.js +4 -4
- package/dist/components/upload/index.js +5 -5
- package/dist/generated/version.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1716 -1525
- package/dist/infrastructure.js +11 -11
- package/dist/styles.css +13430 -9848
- package/dist/theme/index.js +3 -3
- package/dist/utils/index.js +5 -5
- package/package.json +10 -6
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
// src/components/
|
|
4
|
-
import
|
|
3
|
+
// src/components/app/App.tsx
|
|
4
|
+
import {
|
|
5
|
+
createContext,
|
|
6
|
+
forwardRef as forwardRef2,
|
|
7
|
+
useContext,
|
|
8
|
+
useEffect as useEffect3,
|
|
9
|
+
useMemo as useMemo2
|
|
10
|
+
} from "react";
|
|
5
11
|
|
|
6
12
|
// ../../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
7
13
|
function r(e) {
|
|
@@ -28,6 +34,20 @@ function clsx() {
|
|
|
28
34
|
function cn(...inputs) {
|
|
29
35
|
return clsx(inputs);
|
|
30
36
|
}
|
|
37
|
+
// src/classes/app.ts
|
|
38
|
+
var appClass = "app";
|
|
39
|
+
var appRootClass = "app-root";
|
|
40
|
+
var appHolderClass = "app-holder";
|
|
41
|
+
function getAppClasses({ className }) {
|
|
42
|
+
return cn(appClass, className);
|
|
43
|
+
}
|
|
44
|
+
function getAppRootClasses({ className }) {
|
|
45
|
+
return cn(appRootClass, className);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/components/message/Message.tsx
|
|
49
|
+
import React, { useSyncExternalStore } from "react";
|
|
50
|
+
|
|
31
51
|
// src/classes/message.ts
|
|
32
52
|
var messageHolderClass = "message-holder";
|
|
33
53
|
var messageBaseClass = "message";
|
|
@@ -154,13 +174,13 @@ function config(nextConfig) {
|
|
|
154
174
|
emit();
|
|
155
175
|
}
|
|
156
176
|
function MessageHolder({ className }) {
|
|
157
|
-
const
|
|
177
|
+
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
158
178
|
return /* @__PURE__ */ jsx("div", {
|
|
159
179
|
className: getMessageHolderClasses({
|
|
160
|
-
placement:
|
|
180
|
+
placement: snapshot.config.placement,
|
|
161
181
|
className
|
|
162
182
|
}),
|
|
163
|
-
children:
|
|
183
|
+
children: snapshot.messages.map((item) => /* @__PURE__ */ jsxs("div", {
|
|
164
184
|
className: getMessageClasses({
|
|
165
185
|
type: item.type,
|
|
166
186
|
className: item.className
|
|
@@ -219,11 +239,11 @@ var modalCloseClass = "modal-close";
|
|
|
219
239
|
var modalBodyClass = "modal-body";
|
|
220
240
|
var modalFooterClass = "modal-footer";
|
|
221
241
|
function getModalBackdropClasses({
|
|
222
|
-
open
|
|
242
|
+
open,
|
|
223
243
|
centered,
|
|
224
244
|
className
|
|
225
245
|
}) {
|
|
226
|
-
return cn(modalBackdropClass,
|
|
246
|
+
return cn(modalBackdropClass, open && modalOpenClass, centered && modalBackdropCenterClass, className);
|
|
227
247
|
}
|
|
228
248
|
function getModalClasses({ className }) {
|
|
229
249
|
return cn(modalClass, className);
|
|
@@ -233,8 +253,8 @@ function getModalClasses({ className }) {
|
|
|
233
253
|
import { jsx as jsx2, jsxs as jsxs2, Fragment } from "react/jsx-runtime";
|
|
234
254
|
var defaultCloseIcon = "x";
|
|
235
255
|
var serviceHandles = new Set;
|
|
236
|
-
function createServiceHandle(
|
|
237
|
-
let currentConfig =
|
|
256
|
+
function createServiceHandle(config) {
|
|
257
|
+
let currentConfig = config;
|
|
238
258
|
const handle = {
|
|
239
259
|
destroy: () => {
|
|
240
260
|
serviceHandles.delete(handle);
|
|
@@ -256,7 +276,7 @@ function getModalStyle({
|
|
|
256
276
|
};
|
|
257
277
|
}
|
|
258
278
|
var ModalBase = forwardRef(({
|
|
259
|
-
open
|
|
279
|
+
open,
|
|
260
280
|
defaultOpen = false,
|
|
261
281
|
title,
|
|
262
282
|
children,
|
|
@@ -280,9 +300,9 @@ var ModalBase = forwardRef(({
|
|
|
280
300
|
role = "dialog",
|
|
281
301
|
...props
|
|
282
302
|
}, ref) => {
|
|
283
|
-
const controlled =
|
|
303
|
+
const controlled = open !== undefined;
|
|
284
304
|
const [innerOpen, setInnerOpen] = useState(defaultOpen);
|
|
285
|
-
const mergedOpen = controlled ? Boolean(
|
|
305
|
+
const mergedOpen = controlled ? Boolean(open) : innerOpen;
|
|
286
306
|
const previousOpen = useRef(mergedOpen);
|
|
287
307
|
const showClose = closable && closeIcon !== null && closeIcon !== false;
|
|
288
308
|
const body = children ?? content;
|
|
@@ -425,10 +445,10 @@ function getNotificationHolderClasses({
|
|
|
425
445
|
}
|
|
426
446
|
function getNotificationNoticeClasses({
|
|
427
447
|
type = "info",
|
|
428
|
-
open
|
|
448
|
+
open = true,
|
|
429
449
|
className
|
|
430
450
|
}) {
|
|
431
|
-
return cn("toast", "alert", notificationNoticeClass, notificationTypeClasses[type],
|
|
451
|
+
return cn("toast", "alert", notificationNoticeClass, notificationTypeClasses[type], open && "toast-show", open && notificationNoticeOpenClass, className);
|
|
432
452
|
}
|
|
433
453
|
|
|
434
454
|
// src/components/notification/Notification.tsx
|
|
@@ -457,11 +477,11 @@ function getKey(key) {
|
|
|
457
477
|
globalCounter += 1;
|
|
458
478
|
return `notification-${globalCounter}`;
|
|
459
479
|
}
|
|
460
|
-
function getDuration(
|
|
461
|
-
return
|
|
480
|
+
function getDuration(config, holderConfig) {
|
|
481
|
+
return config.duration ?? holderConfig.duration ?? defaultConfig.duration;
|
|
462
482
|
}
|
|
463
|
-
function getPlacement(
|
|
464
|
-
return
|
|
483
|
+
function getPlacement(config, holderConfig) {
|
|
484
|
+
return config.placement ?? holderConfig.placement ?? defaultConfig.placement;
|
|
465
485
|
}
|
|
466
486
|
function applyMaxCount(notices, maxCount) {
|
|
467
487
|
if (!maxCount || notices.length <= maxCount) {
|
|
@@ -539,42 +559,42 @@ function destroyGlobal(key) {
|
|
|
539
559
|
globalNotices = [];
|
|
540
560
|
emitGlobal();
|
|
541
561
|
}
|
|
542
|
-
function openGlobal(
|
|
543
|
-
const key = getKey(
|
|
562
|
+
function openGlobal(config) {
|
|
563
|
+
const key = getKey(config.key);
|
|
544
564
|
const notice = {
|
|
545
|
-
...
|
|
565
|
+
...config,
|
|
546
566
|
key,
|
|
547
|
-
placement: getPlacement(
|
|
548
|
-
type:
|
|
567
|
+
placement: getPlacement(config, globalConfig2),
|
|
568
|
+
type: config.type ?? "info"
|
|
549
569
|
};
|
|
550
570
|
clearTimer2(key);
|
|
551
571
|
globalNotices = applyMaxCount([...globalNotices.filter((item) => item.key !== key), notice], globalConfig2.maxCount);
|
|
552
|
-
const duration = getDuration(
|
|
572
|
+
const duration = getDuration(config, globalConfig2);
|
|
553
573
|
if (duration && duration > 0) {
|
|
554
574
|
globalTimers.set(key, setTimeout(() => closeGlobal(key), duration * 1000));
|
|
555
575
|
}
|
|
556
576
|
emitGlobal();
|
|
557
577
|
}
|
|
558
|
-
function withType(type,
|
|
559
|
-
openGlobal({ ...
|
|
578
|
+
function withType(type, config) {
|
|
579
|
+
openGlobal({ ...config, type });
|
|
560
580
|
}
|
|
561
581
|
var globalApi = {
|
|
562
582
|
open: openGlobal,
|
|
563
|
-
success: (
|
|
564
|
-
info: (
|
|
565
|
-
warning: (
|
|
566
|
-
error: (
|
|
583
|
+
success: (config) => withType("success", config),
|
|
584
|
+
info: (config) => withType("info", config),
|
|
585
|
+
warning: (config) => withType("warning", config),
|
|
586
|
+
error: (config) => withType("error", config),
|
|
567
587
|
close: closeGlobal,
|
|
568
588
|
destroy: destroyGlobal,
|
|
569
|
-
config: (
|
|
570
|
-
globalConfig2 = { ...globalConfig2, ...
|
|
589
|
+
config: (config) => {
|
|
590
|
+
globalConfig2 = { ...globalConfig2, ...config };
|
|
571
591
|
emitGlobal();
|
|
572
592
|
},
|
|
573
593
|
useNotification
|
|
574
594
|
};
|
|
575
595
|
function NotificationHolder({
|
|
576
596
|
notices,
|
|
577
|
-
config
|
|
597
|
+
config,
|
|
578
598
|
onClose
|
|
579
599
|
}) {
|
|
580
600
|
const groups = groupByPlacement(notices);
|
|
@@ -583,7 +603,7 @@ function NotificationHolder({
|
|
|
583
603
|
if (group.length === 0) {
|
|
584
604
|
return null;
|
|
585
605
|
}
|
|
586
|
-
const offsetStyle = placement.startsWith("bottom") &&
|
|
606
|
+
const offsetStyle = placement.startsWith("bottom") && config.bottom !== undefined ? { bottom: config.bottom } : config.top !== undefined ? { top: config.top } : undefined;
|
|
587
607
|
return /* @__PURE__ */ jsx3("div", {
|
|
588
608
|
className: getNotificationHolderClasses({
|
|
589
609
|
placement
|
|
@@ -591,7 +611,7 @@ function NotificationHolder({
|
|
|
591
611
|
style: offsetStyle,
|
|
592
612
|
children: group.map((notice) => /* @__PURE__ */ jsx3(NotificationNotice, {
|
|
593
613
|
notice,
|
|
594
|
-
fallbackCloseIcon:
|
|
614
|
+
fallbackCloseIcon: config.closeIcon,
|
|
595
615
|
onClose
|
|
596
616
|
}, notice.key))
|
|
597
617
|
}, placement);
|
|
@@ -678,30 +698,30 @@ function createScopedApi({
|
|
|
678
698
|
return current.filter((item) => item.key !== key);
|
|
679
699
|
});
|
|
680
700
|
}
|
|
681
|
-
function
|
|
682
|
-
const key = getKey(
|
|
701
|
+
function open(config) {
|
|
702
|
+
const key = getKey(config.key);
|
|
683
703
|
const notice = {
|
|
684
|
-
...
|
|
704
|
+
...config,
|
|
685
705
|
key,
|
|
686
|
-
placement: getPlacement(
|
|
687
|
-
type:
|
|
706
|
+
placement: getPlacement(config, holderConfig),
|
|
707
|
+
type: config.type ?? "info"
|
|
688
708
|
};
|
|
689
709
|
clearScopedTimer(key);
|
|
690
710
|
setNotices((current) => applyMaxCount([...current.filter((item) => item.key !== key), notice], holderConfig.maxCount));
|
|
691
|
-
const duration = getDuration(
|
|
711
|
+
const duration = getDuration(config, holderConfig);
|
|
692
712
|
if (duration && duration > 0) {
|
|
693
713
|
timerMap.set(key, setTimeout(() => close(key), duration * 1000));
|
|
694
714
|
}
|
|
695
715
|
}
|
|
696
|
-
function typed(type,
|
|
697
|
-
|
|
716
|
+
function typed(type, config) {
|
|
717
|
+
open({ ...config, type });
|
|
698
718
|
}
|
|
699
719
|
return {
|
|
700
|
-
open
|
|
701
|
-
success: (
|
|
702
|
-
info: (
|
|
703
|
-
warning: (
|
|
704
|
-
error: (
|
|
720
|
+
open,
|
|
721
|
+
success: (config) => typed("success", config),
|
|
722
|
+
info: (config) => typed("info", config),
|
|
723
|
+
warning: (config) => typed("warning", config),
|
|
724
|
+
error: (config) => typed("error", config),
|
|
705
725
|
close,
|
|
706
726
|
destroy: (key) => {
|
|
707
727
|
if (key !== undefined) {
|
|
@@ -720,24 +740,24 @@ function createScopedApi({
|
|
|
720
740
|
}
|
|
721
741
|
};
|
|
722
742
|
}
|
|
723
|
-
function useNotification(
|
|
743
|
+
function useNotification(config = {}) {
|
|
724
744
|
const holderConfig = useMemo(() => ({
|
|
725
745
|
...defaultConfig,
|
|
726
|
-
bottom:
|
|
727
|
-
closeIcon:
|
|
728
|
-
duration:
|
|
729
|
-
getContainer:
|
|
730
|
-
maxCount:
|
|
731
|
-
placement:
|
|
732
|
-
top:
|
|
746
|
+
bottom: config.bottom,
|
|
747
|
+
closeIcon: config.closeIcon,
|
|
748
|
+
duration: config.duration ?? defaultConfig.duration,
|
|
749
|
+
getContainer: config.getContainer,
|
|
750
|
+
maxCount: config.maxCount,
|
|
751
|
+
placement: config.placement ?? defaultConfig.placement,
|
|
752
|
+
top: config.top
|
|
733
753
|
}), [
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
754
|
+
config.bottom,
|
|
755
|
+
config.closeIcon,
|
|
756
|
+
config.duration,
|
|
757
|
+
config.getContainer,
|
|
758
|
+
config.maxCount,
|
|
759
|
+
config.placement,
|
|
760
|
+
config.top
|
|
741
761
|
]);
|
|
742
762
|
const [notices, setNotices] = useState2([]);
|
|
743
763
|
const [timerMap] = useState2(() => new Map);
|
|
@@ -772,26 +792,6 @@ function useNotification(config2 = {}) {
|
|
|
772
792
|
];
|
|
773
793
|
}
|
|
774
794
|
var notification = globalApi;
|
|
775
|
-
// src/components/app/App.tsx
|
|
776
|
-
import {
|
|
777
|
-
createContext,
|
|
778
|
-
forwardRef as forwardRef2,
|
|
779
|
-
useContext,
|
|
780
|
-
useEffect as useEffect3,
|
|
781
|
-
useMemo as useMemo2
|
|
782
|
-
} from "react";
|
|
783
|
-
|
|
784
|
-
// src/classes/app.ts
|
|
785
|
-
var appClass = "app";
|
|
786
|
-
var appRootClass = "app-root";
|
|
787
|
-
var appHolderClass = "app-holder";
|
|
788
|
-
function getAppClasses({ className }) {
|
|
789
|
-
return cn(appClass, className);
|
|
790
|
-
}
|
|
791
|
-
function getAppRootClasses({ className }) {
|
|
792
|
-
return cn(appRootClass, className);
|
|
793
|
-
}
|
|
794
|
-
|
|
795
795
|
// src/components/app/App.tsx
|
|
796
796
|
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
797
797
|
var fallbackContext = {
|
|
@@ -877,7 +877,7 @@ function AppRoot({ className, ...props }) {
|
|
|
877
877
|
});
|
|
878
878
|
}
|
|
879
879
|
export {
|
|
880
|
-
|
|
880
|
+
App,
|
|
881
881
|
AppContext,
|
|
882
|
-
|
|
882
|
+
AppRoot
|
|
883
883
|
};
|
|
@@ -402,9 +402,9 @@ var CascaderRoot = forwardRef(({
|
|
|
402
402
|
});
|
|
403
403
|
}
|
|
404
404
|
if (multiple) {
|
|
405
|
-
return selectedPaths.map((
|
|
405
|
+
return selectedPaths.map((path, index) => /* @__PURE__ */ jsx("span", {
|
|
406
406
|
className: cascaderTagClass,
|
|
407
|
-
children: displayRender ? displayRender(labelsForPath(
|
|
407
|
+
children: displayRender ? displayRender(labelsForPath(path, names), path) : defaultDisplay(labelsForPath(path, names))
|
|
408
408
|
}, valueKey(selectedValues[index] ?? [])));
|
|
409
409
|
}
|
|
410
410
|
const path = selectedPaths[0] ?? [];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ChatBubbleProps, ChatComponent, ChatToolProps, ChatTypingProps } from "./Chat.types";
|
|
3
|
+
export declare const ChatAvatar: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
4
|
+
export declare const ChatHeader: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
5
|
+
export declare const ChatBubble: React.ForwardRefExoticComponent<Omit<ChatBubbleProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
6
|
+
export declare const ChatFooter: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
7
|
+
export declare const ChatReasoning: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.DetailsHTMLAttributes<HTMLDetailsElement>, HTMLDetailsElement>, "ref"> & React.RefAttributes<HTMLDetailsElement>>;
|
|
8
|
+
export declare const ChatTool: React.ForwardRefExoticComponent<Omit<ChatToolProps, "ref"> & React.RefAttributes<HTMLDetailsElement>>;
|
|
9
|
+
export declare const ChatToolHeader: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & React.RefAttributes<HTMLElement>>;
|
|
10
|
+
export declare const ChatToolStatus: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & React.RefAttributes<HTMLSpanElement>>;
|
|
11
|
+
export declare const ChatToolCall: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
12
|
+
export declare const ChatToolResult: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
13
|
+
export declare const ChatTyping: React.ForwardRefExoticComponent<Omit<ChatTypingProps, "ref"> & React.RefAttributes<HTMLSpanElement>>;
|
|
14
|
+
export declare const Chat: ChatComponent;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ComponentProps, ForwardRefExoticComponent, RefAttributes } from "react";
|
|
2
|
+
export type ChatPlacement = "start" | "end";
|
|
3
|
+
export type ChatBubbleColor = "primary" | "secondary" | "tertiary" | "accent" | "neutral" | "base" | "info" | "success" | "warning" | "error";
|
|
4
|
+
export type ChatBubbleSize = "xs" | "sm" | "md" | "lg";
|
|
5
|
+
export type ChatToolState = "pending" | "running" | "success" | "error";
|
|
6
|
+
export interface ChatProps extends ComponentProps<"div"> {
|
|
7
|
+
/** Position the turn at the start or end of the conversation row. */
|
|
8
|
+
placement?: ChatPlacement;
|
|
9
|
+
}
|
|
10
|
+
export type ChatAvatarProps = ComponentProps<"div">;
|
|
11
|
+
export type ChatHeaderProps = ComponentProps<"div">;
|
|
12
|
+
export type ChatFooterProps = ComponentProps<"div">;
|
|
13
|
+
export interface ChatBubbleProps extends ComponentProps<"div"> {
|
|
14
|
+
/** Apply a semantic DuskMoon color to the bubble. */
|
|
15
|
+
color?: ChatBubbleColor;
|
|
16
|
+
/** Control the bubble padding and font size. @default "md" */
|
|
17
|
+
size?: ChatBubbleSize;
|
|
18
|
+
/** Use the saturated form of the selected color. */
|
|
19
|
+
filled?: boolean;
|
|
20
|
+
/** Show the live streaming caret after the bubble content. */
|
|
21
|
+
streaming?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export type ChatReasoningProps = ComponentProps<"details">;
|
|
24
|
+
export interface ChatToolProps extends ComponentProps<"details"> {
|
|
25
|
+
/** Reflect the current tool-call state. */
|
|
26
|
+
status?: ChatToolState;
|
|
27
|
+
}
|
|
28
|
+
export type ChatToolHeaderProps = ComponentProps<"summary">;
|
|
29
|
+
export type ChatToolStatusProps = ComponentProps<"span">;
|
|
30
|
+
export type ChatToolCallProps = ComponentProps<"div">;
|
|
31
|
+
export type ChatToolResultProps = ComponentProps<"div">;
|
|
32
|
+
export type ChatTypingProps = Omit<ComponentProps<"span">, "children">;
|
|
33
|
+
type ChatPartComponent<T extends HTMLElement, P> = ForwardRefExoticComponent<P & RefAttributes<T>>;
|
|
34
|
+
export type ChatComponent = ChatPartComponent<HTMLDivElement, ChatProps> & {
|
|
35
|
+
Avatar: ChatPartComponent<HTMLDivElement, ChatAvatarProps>;
|
|
36
|
+
Header: ChatPartComponent<HTMLDivElement, ChatHeaderProps>;
|
|
37
|
+
Bubble: ChatPartComponent<HTMLDivElement, ChatBubbleProps>;
|
|
38
|
+
Footer: ChatPartComponent<HTMLDivElement, ChatFooterProps>;
|
|
39
|
+
Reasoning: ChatPartComponent<HTMLDetailsElement, ChatReasoningProps>;
|
|
40
|
+
Tool: ChatPartComponent<HTMLDetailsElement, ChatToolProps>;
|
|
41
|
+
ToolHeader: ChatPartComponent<HTMLElement, ChatToolHeaderProps>;
|
|
42
|
+
ToolStatus: ChatPartComponent<HTMLSpanElement, ChatToolStatusProps>;
|
|
43
|
+
ToolCall: ChatPartComponent<HTMLDivElement, ChatToolCallProps>;
|
|
44
|
+
ToolResult: ChatPartComponent<HTMLDivElement, ChatToolResultProps>;
|
|
45
|
+
Typing: ChatPartComponent<HTMLSpanElement, ChatTypingProps>;
|
|
46
|
+
};
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/chat/Chat.tsx
|
|
4
|
+
import { forwardRef } from "react";
|
|
5
|
+
|
|
6
|
+
// ../../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
7
|
+
function r(e) {
|
|
8
|
+
var t, f, n = "";
|
|
9
|
+
if (typeof e == "string" || typeof e == "number")
|
|
10
|
+
n += e;
|
|
11
|
+
else if (typeof e == "object")
|
|
12
|
+
if (Array.isArray(e)) {
|
|
13
|
+
var o = e.length;
|
|
14
|
+
for (t = 0;t < o; t++)
|
|
15
|
+
e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
16
|
+
} else
|
|
17
|
+
for (f in e)
|
|
18
|
+
e[f] && (n && (n += " "), n += f);
|
|
19
|
+
return n;
|
|
20
|
+
}
|
|
21
|
+
function clsx() {
|
|
22
|
+
for (var e, t, f = 0, n = "", o = arguments.length;f < o; f++)
|
|
23
|
+
(e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
24
|
+
return n;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/utils/cn.ts
|
|
28
|
+
function cn(...inputs) {
|
|
29
|
+
return clsx(inputs);
|
|
30
|
+
}
|
|
31
|
+
// src/classes/chat.ts
|
|
32
|
+
var chatBaseClass = "chat";
|
|
33
|
+
var chatAvatarClass = "chat-avatar";
|
|
34
|
+
var chatHeaderClass = "chat-header";
|
|
35
|
+
var chatBubbleBaseClass = "chat-bubble";
|
|
36
|
+
var chatFooterClass = "chat-footer";
|
|
37
|
+
var chatReasoningClass = "chat-reasoning";
|
|
38
|
+
var chatToolBaseClass = "chat-tool";
|
|
39
|
+
var chatToolHeaderClass = "chat-tool-header";
|
|
40
|
+
var chatToolStatusClass = "chat-tool-status";
|
|
41
|
+
var chatToolCallClass = "chat-tool-call";
|
|
42
|
+
var chatToolResultClass = "chat-tool-result";
|
|
43
|
+
var chatTypingClass = "chat-typing";
|
|
44
|
+
var chatStreamingCaretClass = "chat-streaming-caret";
|
|
45
|
+
var chatBubbleFilledClass = "chat-bubble-filled";
|
|
46
|
+
var chatBubbleStreamingClass = "chat-bubble-streaming";
|
|
47
|
+
var chatPlacementClasses = {
|
|
48
|
+
start: "chat-start",
|
|
49
|
+
end: "chat-end"
|
|
50
|
+
};
|
|
51
|
+
var chatBubbleColorClasses = {
|
|
52
|
+
primary: "chat-bubble-primary",
|
|
53
|
+
secondary: "chat-bubble-secondary",
|
|
54
|
+
tertiary: "chat-bubble-tertiary",
|
|
55
|
+
accent: "chat-bubble-accent",
|
|
56
|
+
neutral: "chat-bubble-neutral",
|
|
57
|
+
base: "chat-bubble-base",
|
|
58
|
+
info: "chat-bubble-info",
|
|
59
|
+
success: "chat-bubble-success",
|
|
60
|
+
warning: "chat-bubble-warning",
|
|
61
|
+
error: "chat-bubble-error"
|
|
62
|
+
};
|
|
63
|
+
var chatBubbleSizeClasses = {
|
|
64
|
+
xs: "chat-bubble-xs",
|
|
65
|
+
sm: "chat-bubble-sm",
|
|
66
|
+
md: "chat-bubble-md",
|
|
67
|
+
lg: "chat-bubble-lg"
|
|
68
|
+
};
|
|
69
|
+
var chatToolStateClasses = {
|
|
70
|
+
pending: "chat-tool-pending",
|
|
71
|
+
running: "chat-tool-running",
|
|
72
|
+
success: "chat-tool-success",
|
|
73
|
+
error: "chat-tool-error"
|
|
74
|
+
};
|
|
75
|
+
function getChatClasses({
|
|
76
|
+
placement = "start",
|
|
77
|
+
className
|
|
78
|
+
}) {
|
|
79
|
+
return cn(chatBaseClass, chatPlacementClasses[placement], className);
|
|
80
|
+
}
|
|
81
|
+
function getChatBubbleClasses({
|
|
82
|
+
color,
|
|
83
|
+
size = "md",
|
|
84
|
+
filled,
|
|
85
|
+
streaming,
|
|
86
|
+
className
|
|
87
|
+
}) {
|
|
88
|
+
return cn(chatBubbleBaseClass, color && chatBubbleColorClasses[color], chatBubbleSizeClasses[size], filled && chatBubbleFilledClass, streaming && chatBubbleStreamingClass, className);
|
|
89
|
+
}
|
|
90
|
+
function getChatToolClasses({
|
|
91
|
+
status,
|
|
92
|
+
className
|
|
93
|
+
}) {
|
|
94
|
+
return cn(chatToolBaseClass, status && chatToolStateClasses[status], className);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/components/chat/Chat.tsx
|
|
98
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
99
|
+
var ChatAvatar = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", {
|
|
100
|
+
...props,
|
|
101
|
+
ref,
|
|
102
|
+
className: cn(chatAvatarClass, className)
|
|
103
|
+
}));
|
|
104
|
+
ChatAvatar.displayName = "Chat.Avatar";
|
|
105
|
+
var ChatHeader = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", {
|
|
106
|
+
...props,
|
|
107
|
+
ref,
|
|
108
|
+
className: cn(chatHeaderClass, className)
|
|
109
|
+
}));
|
|
110
|
+
ChatHeader.displayName = "Chat.Header";
|
|
111
|
+
var ChatBubble = forwardRef(({ color, size = "md", filled, streaming, className, children, ...props }, ref) => /* @__PURE__ */ jsxs("div", {
|
|
112
|
+
...props,
|
|
113
|
+
ref,
|
|
114
|
+
className: getChatBubbleClasses({
|
|
115
|
+
color,
|
|
116
|
+
size,
|
|
117
|
+
filled,
|
|
118
|
+
streaming,
|
|
119
|
+
className
|
|
120
|
+
}),
|
|
121
|
+
children: [
|
|
122
|
+
children,
|
|
123
|
+
streaming ? /* @__PURE__ */ jsx("span", {
|
|
124
|
+
className: chatStreamingCaretClass,
|
|
125
|
+
"aria-hidden": "true"
|
|
126
|
+
}) : null
|
|
127
|
+
]
|
|
128
|
+
}));
|
|
129
|
+
ChatBubble.displayName = "Chat.Bubble";
|
|
130
|
+
var ChatFooter = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", {
|
|
131
|
+
...props,
|
|
132
|
+
ref,
|
|
133
|
+
className: cn(chatFooterClass, className)
|
|
134
|
+
}));
|
|
135
|
+
ChatFooter.displayName = "Chat.Footer";
|
|
136
|
+
var ChatReasoning = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("details", {
|
|
137
|
+
...props,
|
|
138
|
+
ref,
|
|
139
|
+
className: cn(chatReasoningClass, className)
|
|
140
|
+
}));
|
|
141
|
+
ChatReasoning.displayName = "Chat.Reasoning";
|
|
142
|
+
var ChatTool = forwardRef(({ status, className, ...props }, ref) => /* @__PURE__ */ jsx("details", {
|
|
143
|
+
...props,
|
|
144
|
+
ref,
|
|
145
|
+
className: getChatToolClasses({ status, className })
|
|
146
|
+
}));
|
|
147
|
+
ChatTool.displayName = "Chat.Tool";
|
|
148
|
+
var ChatToolHeader = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("summary", {
|
|
149
|
+
...props,
|
|
150
|
+
ref,
|
|
151
|
+
className: cn(chatToolHeaderClass, className)
|
|
152
|
+
}));
|
|
153
|
+
ChatToolHeader.displayName = "Chat.ToolHeader";
|
|
154
|
+
var ChatToolStatus = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("span", {
|
|
155
|
+
...props,
|
|
156
|
+
ref,
|
|
157
|
+
className: cn(chatToolStatusClass, className)
|
|
158
|
+
}));
|
|
159
|
+
ChatToolStatus.displayName = "Chat.ToolStatus";
|
|
160
|
+
var ChatToolCall = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", {
|
|
161
|
+
...props,
|
|
162
|
+
ref,
|
|
163
|
+
className: cn(chatToolCallClass, className)
|
|
164
|
+
}));
|
|
165
|
+
ChatToolCall.displayName = "Chat.ToolCall";
|
|
166
|
+
var ChatToolResult = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", {
|
|
167
|
+
...props,
|
|
168
|
+
ref,
|
|
169
|
+
className: cn(chatToolResultClass, className)
|
|
170
|
+
}));
|
|
171
|
+
ChatToolResult.displayName = "Chat.ToolResult";
|
|
172
|
+
var ChatTyping = forwardRef(({
|
|
173
|
+
className,
|
|
174
|
+
role = "status",
|
|
175
|
+
"aria-label": ariaLabel = "Assistant is typing",
|
|
176
|
+
...props
|
|
177
|
+
}, ref) => /* @__PURE__ */ jsx("span", {
|
|
178
|
+
...props,
|
|
179
|
+
ref,
|
|
180
|
+
role,
|
|
181
|
+
"aria-label": ariaLabel,
|
|
182
|
+
className: cn(chatTypingClass, className),
|
|
183
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
184
|
+
"aria-hidden": "true"
|
|
185
|
+
})
|
|
186
|
+
}));
|
|
187
|
+
ChatTyping.displayName = "Chat.Typing";
|
|
188
|
+
var ChatRoot = forwardRef(({ placement = "start", className, ...props }, ref) => /* @__PURE__ */ jsx("div", {
|
|
189
|
+
...props,
|
|
190
|
+
ref,
|
|
191
|
+
className: getChatClasses({ placement, className })
|
|
192
|
+
}));
|
|
193
|
+
ChatRoot.displayName = "Chat";
|
|
194
|
+
var Chat = Object.assign(ChatRoot, {
|
|
195
|
+
Avatar: ChatAvatar,
|
|
196
|
+
Header: ChatHeader,
|
|
197
|
+
Bubble: ChatBubble,
|
|
198
|
+
Footer: ChatFooter,
|
|
199
|
+
Reasoning: ChatReasoning,
|
|
200
|
+
Tool: ChatTool,
|
|
201
|
+
ToolHeader: ChatToolHeader,
|
|
202
|
+
ToolStatus: ChatToolStatus,
|
|
203
|
+
ToolCall: ChatToolCall,
|
|
204
|
+
ToolResult: ChatToolResult,
|
|
205
|
+
Typing: ChatTyping
|
|
206
|
+
});
|
|
207
|
+
export {
|
|
208
|
+
Chat,
|
|
209
|
+
ChatAvatar,
|
|
210
|
+
ChatBubble,
|
|
211
|
+
ChatFooter,
|
|
212
|
+
ChatHeader,
|
|
213
|
+
ChatReasoning,
|
|
214
|
+
ChatTool,
|
|
215
|
+
ChatToolCall,
|
|
216
|
+
ChatToolHeader,
|
|
217
|
+
ChatToolResult,
|
|
218
|
+
ChatToolStatus,
|
|
219
|
+
ChatTyping
|
|
220
|
+
};
|
|
@@ -88,9 +88,9 @@ function hsbToRgb(value) {
|
|
|
88
88
|
const c = brightness * s;
|
|
89
89
|
const x = c * (1 - Math.abs(h / 60 % 2 - 1));
|
|
90
90
|
const m = brightness - c;
|
|
91
|
-
const [
|
|
91
|
+
const [r, g, b] = h < 60 ? [c, x, 0] : h < 120 ? [x, c, 0] : h < 180 ? [0, c, x] : h < 240 ? [0, x, c] : h < 300 ? [x, 0, c] : [c, 0, x];
|
|
92
92
|
return {
|
|
93
|
-
r: (
|
|
93
|
+
r: (r + m) * 255,
|
|
94
94
|
g: (g + m) * 255,
|
|
95
95
|
b: (b + m) * 255,
|
|
96
96
|
a: value.a
|
|
@@ -113,8 +113,8 @@ function colorToRgb(value) {
|
|
|
113
113
|
}
|
|
114
114
|
const match = normalized.match(/rgba?\(([^)]+)\)/i);
|
|
115
115
|
if (match) {
|
|
116
|
-
const [
|
|
117
|
-
return { r
|
|
116
|
+
const [r, g, b, a] = match[1].split(",").map((part) => Number(part.trim()));
|
|
117
|
+
return { r, g, b, a };
|
|
118
118
|
}
|
|
119
119
|
return { r: 0, g: 0, b: 0 };
|
|
120
120
|
}
|