hanbiro-react16-sdk 1.0.11 → 1.0.12
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
CHANGED
|
@@ -166,8 +166,67 @@ angular.module('myApp').directive('chatAiDraft', function() {
|
|
|
166
166
|
|
|
167
167
|
---
|
|
168
168
|
|
|
169
|
+
## ChatAIDraft — Imperative API (Ref)
|
|
170
|
+
|
|
171
|
+
`ChatAIDraft` exposes `setAIContext` via ref, allowing you to programmatically set the HTML content of the **AI Context** editor inside the Settings panel.
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
interface ChatAIDraftRef {
|
|
175
|
+
setAIContext: (html: string) => void;
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### React 18 / React 16.8+ (useRef)
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import React, { useRef } from 'react';
|
|
183
|
+
import { ChatAIDraft } from 'hanbiro-react16-sdk/components';
|
|
184
|
+
|
|
185
|
+
function MailComposer() {
|
|
186
|
+
const chatRef = useRef<ChatAIDraft>(null);
|
|
187
|
+
|
|
188
|
+
const handleOpenAI = () => {
|
|
189
|
+
chatRef.current?.setAIContext('<p>Original email content...</p>');
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<>
|
|
194
|
+
<button onClick={handleOpenAI}>Open AI</button>
|
|
195
|
+
<ChatAIDraft
|
|
196
|
+
ref={chatRef}
|
|
197
|
+
onApply={(params) => console.log(params.html)}
|
|
198
|
+
/>
|
|
199
|
+
</>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### AngularJS / UMD (callback ref)
|
|
205
|
+
|
|
206
|
+
```js
|
|
207
|
+
let chatAIInstance = null;
|
|
208
|
+
|
|
209
|
+
ReactDOM.render(
|
|
210
|
+
React.createElement(HanbiroReact16SDK.ChatAIDraft, {
|
|
211
|
+
ref: function(instance) { chatAIInstance = instance; },
|
|
212
|
+
onApply: function(result) { /* ... */ },
|
|
213
|
+
}),
|
|
214
|
+
document.getElementById('chat-ai-container')
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
// Call anytime — e.g. when opening the AI panel
|
|
218
|
+
function setEmailContext(html) {
|
|
219
|
+
if (chatAIInstance) {
|
|
220
|
+
chatAIInstance.setAIContext(html);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
169
227
|
## Development Commands
|
|
170
228
|
|
|
229
|
+
|
|
171
230
|
- Run playground locally: `npm run dev`
|
|
172
231
|
- Build library for production: `npm run build`
|
|
173
232
|
- Build playground for production: `npm run build:playground`
|
|
@@ -6,6 +6,10 @@ export interface AIPaneProps {
|
|
|
6
6
|
html: string;
|
|
7
7
|
}) => void;
|
|
8
8
|
}
|
|
9
|
+
/** Public imperative API exposed via ref */
|
|
10
|
+
export interface ChatAIDraftRef {
|
|
11
|
+
setAIContext: (html: string) => void;
|
|
12
|
+
}
|
|
9
13
|
export interface AIMessage {
|
|
10
14
|
id: string;
|
|
11
15
|
question: string;
|
|
@@ -22,10 +26,10 @@ interface AIPaneState {
|
|
|
22
26
|
conversationId: string;
|
|
23
27
|
originalEmail: string;
|
|
24
28
|
}
|
|
25
|
-
declare class ChatAIDraft extends React.Component<AIPaneProps, AIPaneState> {
|
|
29
|
+
declare class ChatAIDraft extends React.Component<AIPaneProps, AIPaneState> implements ChatAIDraftRef {
|
|
26
30
|
private rootRef;
|
|
27
31
|
constructor(props: AIPaneProps);
|
|
28
|
-
|
|
32
|
+
setAIContext: (html: string) => void;
|
|
29
33
|
handleMessageChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
30
34
|
handleSubmit: () => Promise<void>;
|
|
31
35
|
handleKeyDown: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;
|
|
@@ -3128,8 +3128,7 @@ class On extends d.Component {
|
|
|
3128
3128
|
constructor(n) {
|
|
3129
3129
|
super(n);
|
|
3130
3130
|
b(this, "rootRef");
|
|
3131
|
-
|
|
3132
|
-
b(this, "setAiContext", (n) => {
|
|
3131
|
+
b(this, "setAIContext", (n) => {
|
|
3133
3132
|
this.setState({ originalEmail: n });
|
|
3134
3133
|
});
|
|
3135
3134
|
b(this, "handleMessageChange", (n) => {
|
|
@@ -109,4 +109,4 @@ Please report this to https://github.com/markedjs/marked.`,t){const r="<p>An err
|
|
|
109
109
|
line-height: unset;
|
|
110
110
|
background: var(--background-softGrey);
|
|
111
111
|
color: var(--text-primary);
|
|
112
|
-
}`,setup:z,relative_urls:!1,remove_script_host:!1,document_base_url:"/"}}))}}class In extends d.Component{constructor(n){super(n);b(this,"containerRef");b(this,"popperRef");b(this,"handleClickOutside",n=>{const r=n.target;this.containerRef.current&&!this.containerRef.current.contains(r)&&(!this.popperRef.current||!this.popperRef.current.contains(r))&&this.setState({open:!1})});b(this,"togglePopper",()=>{this.setState(n=>({open:!n.open}))});b(this,"handleLangChange",n=>{const r=ce.find(i=>i.value===n.target.value);this.props.setLang(r||null)});this.state={open:!1},this.containerRef=d.createRef(),this.popperRef=d.createRef()}componentDidMount(){document.addEventListener("mousedown",this.handleClickOutside)}componentWillUnmount(){document.removeEventListener("mousedown",this.handleClickOutside)}render(){const{lang:n,originalEmail:r,setOriginalEmail:i,getEditorContent:o,parentRef:s}=this.props,{open:a}=this.state;let c=0,l=0,u=320;if(a&&this.containerRef.current){const f=this.containerRef.current.getBoundingClientRect();if(c=f.top+(window.scrollY||document.documentElement.scrollTop)-8,l=f.left+(window.scrollX||document.documentElement.scrollLeft),s&&s.current){const h=s.current.getBoundingClientRect();u=h.width-16,l=h.left+8}}return d.createElement("div",{ref:this.containerRef,style:{position:"relative",display:"inline-block"}},d.createElement("button",{type:"button",onClick:this.togglePopper,className:"icon-button small"},d.createElement(le,{size:16})),a&&this.containerRef.current&&Ie.createPortal(d.createElement("div",{ref:this.popperRef,style:{position:"absolute",top:c,left:l,transform:"translateY(-100%)",zIndex:1051,background:"#fff",border:"1px solid #ddd",boxShadow:"0px 4px 12px rgba(0, 0, 0, 0.1)",borderRadius:8,padding:16,width:u,boxSizing:"border-box"}},d.createElement("div",{style:{display:"flex",flexDirection:"column",gap:12}},d.createElement("div",{style:{display:"flex",flexDirection:"column",gap:4}},d.createElement("span",{style:{fontSize:12,fontWeight:500}},"Language"),d.createElement("select",{value:n?n.value:"",onChange:this.handleLangChange,style:{padding:"7px 8px",borderRadius:4,border:"1px solid #ccc",fontSize:14}},d.createElement("option",{value:"",disabled:!0},"Select Language"),ce.map(f=>d.createElement("option",{key:f.value,value:f.value},f.label)))),d.createElement("div",{style:{display:"flex",flexDirection:"column",gap:4}},d.createElement("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"}},d.createElement("span",{style:{fontSize:12,fontWeight:500}},"AI Context"),o&&d.createElement(ne,{title:"Copy from origin email"},d.createElement("button",{type:"button",onClick:()=>{const f=o();i(f)},className:"icon-button small"},d.createElement(V,null)))),d.createElement(_n,{value:r,onChange:f=>i(f),height:350,isSimple:!0})))),document.body))}}class Pn extends d.Component{constructor(n){super(n);b(this,"rootRef");b(this,"
|
|
112
|
+
}`,setup:z,relative_urls:!1,remove_script_host:!1,document_base_url:"/"}}))}}class In extends d.Component{constructor(n){super(n);b(this,"containerRef");b(this,"popperRef");b(this,"handleClickOutside",n=>{const r=n.target;this.containerRef.current&&!this.containerRef.current.contains(r)&&(!this.popperRef.current||!this.popperRef.current.contains(r))&&this.setState({open:!1})});b(this,"togglePopper",()=>{this.setState(n=>({open:!n.open}))});b(this,"handleLangChange",n=>{const r=ce.find(i=>i.value===n.target.value);this.props.setLang(r||null)});this.state={open:!1},this.containerRef=d.createRef(),this.popperRef=d.createRef()}componentDidMount(){document.addEventListener("mousedown",this.handleClickOutside)}componentWillUnmount(){document.removeEventListener("mousedown",this.handleClickOutside)}render(){const{lang:n,originalEmail:r,setOriginalEmail:i,getEditorContent:o,parentRef:s}=this.props,{open:a}=this.state;let c=0,l=0,u=320;if(a&&this.containerRef.current){const f=this.containerRef.current.getBoundingClientRect();if(c=f.top+(window.scrollY||document.documentElement.scrollTop)-8,l=f.left+(window.scrollX||document.documentElement.scrollLeft),s&&s.current){const h=s.current.getBoundingClientRect();u=h.width-16,l=h.left+8}}return d.createElement("div",{ref:this.containerRef,style:{position:"relative",display:"inline-block"}},d.createElement("button",{type:"button",onClick:this.togglePopper,className:"icon-button small"},d.createElement(le,{size:16})),a&&this.containerRef.current&&Ie.createPortal(d.createElement("div",{ref:this.popperRef,style:{position:"absolute",top:c,left:l,transform:"translateY(-100%)",zIndex:1051,background:"#fff",border:"1px solid #ddd",boxShadow:"0px 4px 12px rgba(0, 0, 0, 0.1)",borderRadius:8,padding:16,width:u,boxSizing:"border-box"}},d.createElement("div",{style:{display:"flex",flexDirection:"column",gap:12}},d.createElement("div",{style:{display:"flex",flexDirection:"column",gap:4}},d.createElement("span",{style:{fontSize:12,fontWeight:500}},"Language"),d.createElement("select",{value:n?n.value:"",onChange:this.handleLangChange,style:{padding:"7px 8px",borderRadius:4,border:"1px solid #ccc",fontSize:14}},d.createElement("option",{value:"",disabled:!0},"Select Language"),ce.map(f=>d.createElement("option",{key:f.value,value:f.value},f.label)))),d.createElement("div",{style:{display:"flex",flexDirection:"column",gap:4}},d.createElement("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"}},d.createElement("span",{style:{fontSize:12,fontWeight:500}},"AI Context"),o&&d.createElement(ne,{title:"Copy from origin email"},d.createElement("button",{type:"button",onClick:()=>{const f=o();i(f)},className:"icon-button small"},d.createElement(V,null)))),d.createElement(_n,{value:r,onChange:f=>i(f),height:350,isSimple:!0})))),document.body))}}class Pn extends d.Component{constructor(n){super(n);b(this,"rootRef");b(this,"setAIContext",n=>{this.setState({originalEmail:n})});b(this,"handleMessageChange",n=>{this.setState({message:n.target.value})});b(this,"handleSubmit",async()=>{const{message:n,messages:r,lang:i,originalEmail:o,conversationId:s}=this.state;if(!n.trim())return;const a=pt();let c={id:a,question:n,subject:"",body:"",created_at:new Date().getTime(),isLoading:!0};const l=[...r,c];this.setState({messages:l,message:"",isSending:!0});const u={query:n,default_language:i?i.value:"KR",original_email:o,debug_grpc:!0};s&&(u.conversation_id=s),await Rt(u,{setContent:g=>{this.setState(m=>({messages:m.messages.map(w=>w.id===a?{...w,subject:"Some thing not used",body:g,isLoading:!1,created_at:new Date().getTime()}:w)}))},setIsLoading:g=>{this.setState(m=>({messages:m.messages.map(w=>w.id===a?{...w,isLoading:g}:w)}))},setConversationId:g=>{this.setState({conversationId:g})}}),this.setState({isSending:!1})});b(this,"handleKeyDown",n=>{!n.shiftKey&&n.key==="Enter"&&!this.state.isSending&&(n.preventDefault(),this.handleSubmit())});b(this,"setLang",n=>{this.setState({lang:n})});b(this,"setOriginalEmail",n=>{this.setState({originalEmail:n})});this.rootRef=d.createRef(),this.state={message:"",messages:[],isSending:!1,lang:ce[0],conversationId:"",originalEmail:""}}render(){const{onApply:n,getEditorContent:r}=this.props,{message:i,messages:o,isSending:s,lang:a,originalEmail:c}=this.state;return d.createElement("div",{ref:this.rootRef,style:{display:"flex",height:"100%",padding:16,flexDirection:"column",background:"#fff",fontFamily:"inherit",boxSizing:"border-box"}},o.length>0?d.createElement(hn,{items:o,onApply:n,getEditorContent:r}):d.createElement("div",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"var(--grey-light)"}},d.createElement(St,{size:46}),d.createElement("h2",{style:{marginTop:16,fontWeight:600,color:"inherit",fontSize:18}},"Build with Agent")),d.createElement("div",{style:{width:"100%",border:"1px solid var(--border-main)",borderRadius:4,overflow:"hidden",background:"#fff",display:"flex",flexDirection:"column"}},d.createElement("textarea",{value:i,onChange:this.handleMessageChange,placeholder:"Describe your email",name:"ai-content",onKeyDown:this.handleKeyDown,disabled:s,style:{flex:1,minWidth:0,borderRadius:4,padding:12,fontSize:13,border:"none",resize:"none",outline:"none",minHeight:60,fontFamily:"inherit"}}),d.createElement("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"8px",boxSizing:"border-box"}},d.createElement(In,{lang:a,setLang:this.setLang,originalEmail:c,setOriginalEmail:this.setOriginalEmail,getEditorContent:r,parentRef:this.rootRef}),d.createElement("button",{disabled:!i.trim()||s,onClick:this.handleSubmit,className:"icon-button",color:"primary"},d.createElement(se,null)))))}}E.ChatAIDraft=Pn,E.LoadingCircular=ye,E.LoadingContainer=Ye,E.Tooltip=ne,E.getBaseUrl=Z,E.getGroupwareUrl=Ct,E.initHanbiroReactSDK=Et,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|