@sampleapp.ai/sdk 1.0.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/dist/components/ChatButton.d.ts +12 -0
- package/dist/components/ModalSearchAndChat.d.ts +14 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +1 -0
- package/dist/types.d.ts +19 -0
- package/package.json +37 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SDKSettings, ComponentOptions } from "../types";
|
|
2
|
+
export declare class ChatButton {
|
|
3
|
+
private settings;
|
|
4
|
+
private element;
|
|
5
|
+
constructor(settings: SDKSettings, options?: ComponentOptions);
|
|
6
|
+
private init;
|
|
7
|
+
private validateSettings;
|
|
8
|
+
private createElement;
|
|
9
|
+
private bindEvents;
|
|
10
|
+
private handleClick;
|
|
11
|
+
destroy(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SDKSettings, ComponentOptions } from "../types";
|
|
2
|
+
export declare class ModalSearchAndChat {
|
|
3
|
+
private settings;
|
|
4
|
+
private element;
|
|
5
|
+
constructor(settings: SDKSettings, options?: ComponentOptions);
|
|
6
|
+
private init;
|
|
7
|
+
private validateSettings;
|
|
8
|
+
private createElement;
|
|
9
|
+
private renderExampleQuestions;
|
|
10
|
+
private bindEvents;
|
|
11
|
+
show(): void;
|
|
12
|
+
hide(): void;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModalSearchAndChat } from "./components/ModalSearchAndChat";
|
|
2
|
+
import { ChatButton } from "./components/ChatButton";
|
|
3
|
+
import { SDKSettings, ComponentOptions } from "./types";
|
|
4
|
+
declare class YourSDK {
|
|
5
|
+
ModalSearchAndChat: (settings: SDKSettings, options?: ComponentOptions) => ModalSearchAndChat;
|
|
6
|
+
ChatButton: (settings: SDKSettings, options?: ComponentOptions) => ChatButton;
|
|
7
|
+
version: string;
|
|
8
|
+
}
|
|
9
|
+
declare const sdk: YourSDK;
|
|
10
|
+
export default sdk;
|
|
11
|
+
export { ModalSearchAndChat, ChatButton };
|
|
12
|
+
export type { SDKSettings, ComponentOptions, BaseSettings, AiChatSettings, } from "./types";
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
YourSDK: YourSDK;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SampleApp=t():e.SampleApp=t()}(this,()=>(()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{ChatButton:()=>i,ModalSearchAndChat:()=>n,default:()=>o});class n{constructor(e,t){this.element=null,this.settings=e,this.init(t)}init(e){this.validateSettings(),this.createElement(e),this.bindEvents()}validateSettings(){if(!this.settings.baseSettings.apiKey)throw new Error("API Key is required");if(!this.settings.baseSettings.primaryBrandColor)throw new Error("Primary brand color is required")}createElement(e){this.element=document.createElement("div"),this.element.className=`modal-search-chat ${(null==e?void 0:e.className)||""}`,this.element.style.cssText="\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n background: white;\n border-radius: 8px;\n box-shadow: 0 4px 20px rgba(0,0,0,0.15);\n z-index: 1000;\n display: none;\n ",this.element.innerHTML=`\n <div style="padding: 20px; border-bottom: 1px solid #eee;">\n <h3 style="margin: 0; color: ${this.settings.baseSettings.primaryBrandColor};">\n ${this.settings.baseSettings.organizationDisplayName}\n </h3>\n </div>\n <div style="padding: 20px;">\n <input type="text" placeholder="Ask a question..." style="width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px;" />\n ${this.renderExampleQuestions()}\n </div>\n `,document.body.appendChild(this.element)}renderExampleQuestions(){var e;return(null===(e=this.settings.aiChatSettings)||void 0===e?void 0:e.exampleQuestions)?`\n <div style="margin-top: 15px;">\n <p style="margin: 0 0 10px 0; font-weight: bold;">Example questions:</p>\n ${this.settings.aiChatSettings.exampleQuestions.map(e=>`<button style="display: block; margin: 5px 0; padding: 8px; border: 1px solid #ddd; background: white; border-radius: 4px; cursor: pointer;">${e}</button>`).join("")}\n </div>\n `:""}bindEvents(){if(this.element){const e=this.element.querySelector("input");this.element.querySelectorAll("button").forEach(t=>{t.addEventListener("click",t=>{const n=t.target;e&&(e.value=n.textContent||"")})})}}show(){this.element&&(this.element.style.display="block")}hide(){this.element&&(this.element.style.display="none")}destroy(){this.element&&(this.element.remove(),this.element=null)}}class i{constructor(e,t){this.element=null,this.settings=e,this.init(t)}init(e){this.validateSettings(),this.createElement(e),this.bindEvents()}validateSettings(){if(!this.settings.baseSettings.apiKey)throw new Error("API Key is required")}createElement(e){var t;if(this.element=document.createElement("button"),this.element.className=`chat-button ${(null==e?void 0:e.className)||""}`,this.element.textContent="Ask AI",this.element.style.cssText=`\n position: fixed;\n bottom: 20px;\n right: 20px;\n background: ${this.settings.baseSettings.primaryBrandColor};\n color: white;\n border: none;\n border-radius: 50px;\n padding: 15px 20px;\n font-size: 14px;\n font-weight: bold;\n cursor: pointer;\n box-shadow: 0 4px 12px rgba(0,0,0,0.15);\n z-index: 1000;\n transition: transform 0.2s, box-shadow 0.2s;\n `,null===(t=this.settings.aiChatSettings)||void 0===t?void 0:t.aiAssistantAvatar){const e=document.createElement("img");e.src=this.settings.aiChatSettings.aiAssistantAvatar,e.style.cssText="width: 20px; height: 20px; border-radius: 50%; margin-right: 8px; vertical-align: middle;",this.element.insertBefore(e,this.element.firstChild)}document.body.appendChild(this.element)}bindEvents(){this.element&&(this.element.addEventListener("mouseenter",()=>{this.element&&(this.element.style.transform="scale(1.05)",this.element.style.boxShadow="0 6px 20px rgba(0,0,0,0.2)")}),this.element.addEventListener("mouseleave",()=>{this.element&&(this.element.style.transform="scale(1)",this.element.style.boxShadow="0 4px 12px rgba(0,0,0,0.15)")}),this.element.addEventListener("click",()=>{this.handleClick()}))}handleClick(){const e=new CustomEvent("chatButtonClick",{detail:{settings:this.settings}});document.dispatchEvent(e),console.log("Chat button clicked!",this.settings)}destroy(){this.element&&(this.element.remove(),this.element=null)}}const s=new class{constructor(){this.ModalSearchAndChat=(e,t)=>new n(e,t),this.ChatButton=(e,t)=>new i(e,t),this.version="1.0.0"}},o=s;return"undefined"!=typeof window&&(window.SampleApp=s),t})());
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface BaseSettings {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
primaryBrandColor: string;
|
|
4
|
+
organizationDisplayName: string;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
export interface AiChatSettings {
|
|
8
|
+
aiAssistantAvatar?: string;
|
|
9
|
+
exampleQuestions?: string[];
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
export interface SDKSettings {
|
|
13
|
+
baseSettings: BaseSettings;
|
|
14
|
+
aiChatSettings?: AiChatSettings;
|
|
15
|
+
}
|
|
16
|
+
export interface ComponentOptions {
|
|
17
|
+
containerId?: string;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sampleapp.ai/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK for your components",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "webpack --mode=production",
|
|
15
|
+
"dev": "webpack --mode=development --watch",
|
|
16
|
+
"type-check": "tsc --noEmit",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^20.0.0",
|
|
21
|
+
"ts-loader": "^9.4.0",
|
|
22
|
+
"typescript": "^5.0.0",
|
|
23
|
+
"webpack": "^5.88.0",
|
|
24
|
+
"webpack-cli": "^5.1.0"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"sdk",
|
|
28
|
+
"typescript",
|
|
29
|
+
"components"
|
|
30
|
+
],
|
|
31
|
+
"author": "Your Name",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/sampleapp/sdk.git"
|
|
36
|
+
}
|
|
37
|
+
}
|