@lastbrain/ai-ui-react 1.0.67 → 1.0.69

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.
Files changed (60) hide show
  1. package/dist/components/AiChipLabel.d.ts +8 -3
  2. package/dist/components/AiChipLabel.d.ts.map +1 -1
  3. package/dist/components/AiChipLabel.js +21 -70
  4. package/dist/components/AiContextButton.d.ts +5 -1
  5. package/dist/components/AiContextButton.d.ts.map +1 -1
  6. package/dist/components/AiContextButton.js +67 -291
  7. package/dist/components/AiImageButton.d.ts +5 -1
  8. package/dist/components/AiImageButton.d.ts.map +1 -1
  9. package/dist/components/AiImageButton.js +6 -142
  10. package/dist/components/AiInput.d.ts +5 -3
  11. package/dist/components/AiInput.d.ts.map +1 -1
  12. package/dist/components/AiInput.js +13 -25
  13. package/dist/components/AiPromptPanel.d.ts.map +1 -1
  14. package/dist/components/AiPromptPanel.js +58 -212
  15. package/dist/components/AiSelect.d.ts +5 -3
  16. package/dist/components/AiSelect.d.ts.map +1 -1
  17. package/dist/components/AiSelect.js +21 -30
  18. package/dist/components/AiStatusButton.d.ts +4 -1
  19. package/dist/components/AiStatusButton.d.ts.map +1 -1
  20. package/dist/components/AiStatusButton.js +198 -626
  21. package/dist/components/AiTextarea.d.ts +4 -2
  22. package/dist/components/AiTextarea.d.ts.map +1 -1
  23. package/dist/components/AiTextarea.js +14 -26
  24. package/dist/components/LBApiKeySelector.d.ts.map +1 -1
  25. package/dist/components/LBApiKeySelector.js +5 -166
  26. package/dist/components/LBConnectButton.d.ts +4 -7
  27. package/dist/components/LBConnectButton.d.ts.map +1 -1
  28. package/dist/components/LBConnectButton.js +17 -86
  29. package/dist/components/LBSigninModal.d.ts +1 -1
  30. package/dist/components/LBSigninModal.d.ts.map +1 -1
  31. package/dist/components/LBSigninModal.js +42 -320
  32. package/dist/examples/AiUiPremiumShowcase.d.ts +2 -0
  33. package/dist/examples/AiUiPremiumShowcase.d.ts.map +1 -0
  34. package/dist/examples/AiUiPremiumShowcase.js +15 -0
  35. package/dist/index.d.ts +2 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +2 -0
  38. package/dist/styles/inline.d.ts +1 -0
  39. package/dist/styles/inline.d.ts.map +1 -1
  40. package/dist/styles/inline.js +25 -129
  41. package/dist/styles.css +1268 -369
  42. package/dist/types.d.ts +3 -0
  43. package/dist/types.d.ts.map +1 -1
  44. package/package.json +2 -2
  45. package/src/components/AiChipLabel.tsx +64 -101
  46. package/src/components/AiContextButton.tsx +138 -430
  47. package/src/components/AiImageButton.tsx +29 -190
  48. package/src/components/AiInput.tsx +49 -74
  49. package/src/components/AiPromptPanel.tsx +71 -254
  50. package/src/components/AiSelect.tsx +61 -69
  51. package/src/components/AiStatusButton.tsx +477 -1219
  52. package/src/components/AiTextarea.tsx +49 -64
  53. package/src/components/LBApiKeySelector.tsx +86 -274
  54. package/src/components/LBConnectButton.tsx +46 -334
  55. package/src/components/LBSigninModal.tsx +140 -481
  56. package/src/examples/AiUiPremiumShowcase.tsx +91 -0
  57. package/src/index.ts +3 -0
  58. package/src/styles/inline.ts +27 -148
  59. package/src/styles.css +1268 -369
  60. package/src/types.ts +3 -0
@@ -1,29 +1,33 @@
1
1
  "use client";
2
2
 
3
3
  import React, { useState, type SelectHTMLAttributes } from "react";
4
- import { Sparkles, Lock } from "lucide-react";
5
- import type { BaseAiProps } from "../types";
4
+ import { ChevronDown, Loader2, Lock, Sparkles } from "lucide-react";
5
+ import type { AiRadius, AiSize, BaseAiProps } from "../types";
6
6
  import { useAiCallText } from "../hooks/useAiCallText";
7
7
  import { useAiModels } from "../hooks/useAiModels";
8
8
  import { AiPromptPanel } from "./AiPromptPanel";
9
9
  import { UsageToast, useUsageToast } from "./UsageToast";
10
10
  import { LBSigninModal } from "./LBSigninModal";
11
- import { aiStyles } from "../styles/inline";
12
11
  import { handleAIError } from "../utils/errorHandler";
13
12
  import { useLB } from "../context/LBAuthProvider";
13
+ import { useAiContext } from "../context/AiProvider";
14
14
 
15
15
  export interface AiSelectProps
16
16
  extends
17
17
  Omit<BaseAiProps, "type">,
18
- Omit<SelectHTMLAttributes<HTMLSelectElement>, "onValue"> {
18
+ Omit<SelectHTMLAttributes<HTMLSelectElement>, "onValue" | "size"> {
19
19
  children: React.ReactNode;
20
20
  uiMode?: "modal" | "drawer";
21
+ size?: AiSize;
22
+ radius?: AiRadius;
21
23
  }
22
24
 
23
25
  export function AiSelect({
24
- baseUrl,
25
- apiKeyId,
26
+ baseUrl: propBaseUrl,
27
+ apiKeyId: propApiKeyId,
26
28
  uiMode = "modal",
29
+ size = "md",
30
+ radius = "full",
27
31
  context,
28
32
  model,
29
33
  prompt,
@@ -38,7 +42,6 @@ export function AiSelect({
38
42
  }: AiSelectProps) {
39
43
  const [isOpen, setIsOpen] = useState(false);
40
44
  const [showAuthModal, setShowAuthModal] = useState(false);
41
- const [isFocused, setIsFocused] = useState(false);
42
45
  const { showUsageToast, toastData, toastKey, clearToast } = useUsageToast();
43
46
 
44
47
  // Rendre l'authentification optionnelle
@@ -51,6 +54,20 @@ export function AiSelect({
51
54
  lbStatus = undefined;
52
55
  }
53
56
 
57
+ let ctxBaseUrl: string | undefined;
58
+ let ctxApiKeyId: string | undefined;
59
+ try {
60
+ const aiContext = useAiContext();
61
+ ctxBaseUrl = aiContext.baseUrl;
62
+ ctxApiKeyId = aiContext.apiKeyId;
63
+ } catch {
64
+ ctxBaseUrl = undefined;
65
+ ctxApiKeyId = undefined;
66
+ }
67
+
68
+ const baseUrl = propBaseUrl ?? ctxBaseUrl;
69
+ const apiKeyId = propApiKeyId ?? ctxApiKeyId;
70
+
54
71
  const { models } = useAiModels({
55
72
  baseUrl,
56
73
  apiKeyId,
@@ -99,69 +116,44 @@ export function AiSelect({
99
116
  }
100
117
  };
101
118
 
119
+ const sizeClass = `ai-size-${size}`;
120
+ const radiusClass = `ai-radius-${radius}`;
121
+
102
122
  return (
103
- <div style={{ width: "100%", position: "relative" }} className={className}>
104
- <select
105
- {...selectProps}
106
- style={{
107
- ...aiStyles.select,
108
- ...(isFocused && aiStyles.selectFocus),
109
- paddingRight: "40px", // Space for AI button
110
- }}
111
- onFocus={(e) => {
112
- setIsFocused(true);
113
- selectProps.onFocus?.(e);
114
- }}
115
- onBlur={(e) => {
116
- setIsFocused(false);
117
- selectProps.onBlur?.(e);
118
- }}
119
- disabled={disabled || loading}
120
- >
121
- {children}
122
- </select>
123
-
124
- {/* AI Button */}
125
- <button
126
- onClick={handleOpenPanel}
127
- style={{
128
- position: "absolute",
129
- right: "8px",
130
- top: "50%",
131
- transform: "translateY(-50%)",
132
- background: "none",
133
- border: "none",
134
- cursor: "pointer",
135
- padding: "4px",
136
- borderRadius: "4px",
137
- display: "flex",
138
- alignItems: "center",
139
- color: shouldShowSparkles ? "#6366f1" : "#ef4444",
140
- }}
141
- title={
142
- shouldShowSparkles
143
- ? "Générer avec l'IA"
144
- : "Se connecter pour utiliser l'IA"
145
- }
146
- disabled={disabled || loading}
147
- >
148
- {loading ? (
149
- <svg
150
- style={aiStyles.spinner}
151
- width="16"
152
- height="16"
153
- viewBox="0 0 24 24"
154
- fill="none"
155
- stroke="currentColor"
156
- >
157
- <path d="M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83" />
158
- </svg>
159
- ) : shouldShowSparkles ? (
160
- <Sparkles size={16} />
161
- ) : (
162
- <Lock size={16} />
163
- )}
164
- </button>
123
+ <div className={`ai-control-group ai-glow ${className || ""}`}>
124
+ <div className={`ai-shell ${sizeClass} ${radiusClass}`}>
125
+ <select
126
+ {...selectProps}
127
+ className={`ai-control ai-control-input ai-control-select ${sizeClass} ${radiusClass}`}
128
+ disabled={disabled || loading}
129
+ >
130
+ {children}
131
+ </select>
132
+
133
+ <span className="ai-control-select-chevron" aria-hidden="true">
134
+ <ChevronDown size={14} />
135
+ </span>
136
+
137
+ <button
138
+ className={`ai-control-action ai-spark ${sizeClass} ${radiusClass}`}
139
+ onClick={handleOpenPanel}
140
+ title={
141
+ shouldShowSparkles
142
+ ? "Générer avec l'IA"
143
+ : "Se connecter pour utiliser l'IA"
144
+ }
145
+ disabled={disabled || loading}
146
+ type="button"
147
+ >
148
+ {loading ? (
149
+ <Loader2 size={16} className="ai-spinner" />
150
+ ) : shouldShowSparkles ? (
151
+ <Sparkles size={16} />
152
+ ) : (
153
+ <Lock size={16} />
154
+ )}
155
+ </button>
156
+ </div>
165
157
  {isOpen && (
166
158
  <AiPromptPanel
167
159
  isOpen={isOpen}