@molin.ai/shop-ai 0.9.8 → 0.9.9
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.
|
@@ -1852,7 +1852,7 @@ var Vp=Object.create;var Fs=Object.defineProperty;var Np=Object.getOwnPropertyDe
|
|
|
1852
1852
|
:host {
|
|
1853
1853
|
all: initial; /* reset all properties that can pierce the shadow DOM */
|
|
1854
1854
|
}
|
|
1855
|
-
`),w(jn,"properties",{cdn:{type:String},widgetId:{type:String,attribute:"widget"},showClose:{type:Boolean,attribute:"show-close"},xUserData:{type:Object,attribute:!1},xCustomInstructions:{type:String,attribute:!1}});var Lt=jn;customElements.get("molin-shop-ai-chat")||customElements.define("molin-shop-ai-chat",Lt);var Sa;Lt.CloseClickEvent=(Sa=class extends CustomEvent{constructor(e={}){super(Lt.CloseClickEvent.type,{...e})}},w(Sa,"type","mw:close-click"),Sa);var Ea=class{constructor({hidden:e=!1}){w(this,"hidden");this.hidden=e}setUserData(e){for(let r of document.querySelectorAll("molin-shop-ai"))e?r.setAttribute("user-data",JSON.stringify(e)):r.removeAttribute("user-data");for(let r of document.querySelectorAll("molin-shop-ai-chat"))e?r.setAttribute("user-data",JSON.stringify(e)):r.removeAttribute("user-data")}setCustomInstructions(e){for(let r of document.querySelectorAll("molin-shop-ai"))e?r.setAttribute("custom-instructions",e):r.removeAttribute("custom-instructions");for(let r of document.querySelectorAll("molin-shop-ai-chat"))e?r.setAttribute("custom-instructions",e):r.removeAttribute("custom-instructions")}showLauncher(){for(let e of document.querySelectorAll("molin-shop-ai"))e instanceof Te&&e.showLauncher()}hideLauncher(){for(let e of document.querySelectorAll("molin-shop-ai"))e instanceof Te&&e.hideLauncher()}openChat(e){let{message:r,autoSend:n}=e||{};for(let i of document.querySelectorAll("molin-shop-ai"))i instanceof Te&&i.openChat({message:r,autoSend:n})}closeChat(){for(let e of document.querySelectorAll("molin-shop-ai"))e instanceof Te&&e.closeChat()}reset(){ye.resetWidgetData();for(let e of document.querySelectorAll("molin-shop-ai"))e instanceof Te&&e.reset();for(let e of document.querySelectorAll("molin-shop-ai-chat"))e instanceof Lt&&e.reset()}};function up({hidden:t}){let e=new Ea({hidden:t});return window.Molin=e,e}function bs(){let t=window.Molin;if(!t)throw new Error("window.Molin global not initialized");return t}window.__INIT_MOLIN_SHOP_AI=function(e){C1(e);let r=st(),n=typeof r?.hidden=="boolean"?r.hidden:window.self!==window.top;if(up({hidden:n}),e.auto){let i=document.createElement("molin-shop-ai");i.setAttribute("cdn",e.cdn),i.setAttribute("widget",e.widgetId),document.body.appendChild(i)}};function C1(t){window.__INIT_MOLIN_SHOP_AI_OPTIONS=t}function pp(){return window.__INIT_MOLIN_SHOP_AI_OPTIONS}var Ee,Dn,$r,_r,ot=class{constructor(e,r){d(this,Ee);d(this,Dn);d(this,$r);d(this,_r);g(this,Ee,e),g(this,Dn,r),e.addController(this)}get data(){return a(this,_r)||a(this,$r)?.data}hostConnected(){if(a(this,$r)||a(this,_r))return;let e=pp();e&&e.widgetId===a(this,Ee).widgetId?g(this,_r,e.config):g(this,$r,new Ui(a(this,Ee),()=>{if(a(this,Ee).cdn&&a(this,Ee).widgetId)return`${a(this,Ee).cdn}/config?w=${a(this,Ee).widgetId}`;throw new Error("missing cdn or widgetId")},{fetchWhenConnected:!0,transform:async r=>{let n=await r.json();return n&&!e&&window.__INIT_MOLIN_SHOP_AI({cdn:a(this,Ee).cdn,widgetId:a(this,Ee).widgetId,config:n}),n},onError:a(this,Dn)?.onError}))}};Ee=new WeakMap,Dn=new WeakMap,$r=new WeakMap,_r=new WeakMap;function hp(){let t=new URL(import.meta.url).hostname;return{localhost:"http://uploads.molin.localhost:8787","molin.localhost":"http://uploads.molin.localhost:8787","widget.molin.foo":"https://
|
|
1855
|
+
`),w(jn,"properties",{cdn:{type:String},widgetId:{type:String,attribute:"widget"},showClose:{type:Boolean,attribute:"show-close"},xUserData:{type:Object,attribute:!1},xCustomInstructions:{type:String,attribute:!1}});var Lt=jn;customElements.get("molin-shop-ai-chat")||customElements.define("molin-shop-ai-chat",Lt);var Sa;Lt.CloseClickEvent=(Sa=class extends CustomEvent{constructor(e={}){super(Lt.CloseClickEvent.type,{...e})}},w(Sa,"type","mw:close-click"),Sa);var Ea=class{constructor({hidden:e=!1}){w(this,"hidden");this.hidden=e}setUserData(e){for(let r of document.querySelectorAll("molin-shop-ai"))e?r.setAttribute("user-data",JSON.stringify(e)):r.removeAttribute("user-data");for(let r of document.querySelectorAll("molin-shop-ai-chat"))e?r.setAttribute("user-data",JSON.stringify(e)):r.removeAttribute("user-data")}setCustomInstructions(e){for(let r of document.querySelectorAll("molin-shop-ai"))e?r.setAttribute("custom-instructions",e):r.removeAttribute("custom-instructions");for(let r of document.querySelectorAll("molin-shop-ai-chat"))e?r.setAttribute("custom-instructions",e):r.removeAttribute("custom-instructions")}showLauncher(){for(let e of document.querySelectorAll("molin-shop-ai"))e instanceof Te&&e.showLauncher()}hideLauncher(){for(let e of document.querySelectorAll("molin-shop-ai"))e instanceof Te&&e.hideLauncher()}openChat(e){let{message:r,autoSend:n}=e||{};for(let i of document.querySelectorAll("molin-shop-ai"))i instanceof Te&&i.openChat({message:r,autoSend:n})}closeChat(){for(let e of document.querySelectorAll("molin-shop-ai"))e instanceof Te&&e.closeChat()}reset(){ye.resetWidgetData();for(let e of document.querySelectorAll("molin-shop-ai"))e instanceof Te&&e.reset();for(let e of document.querySelectorAll("molin-shop-ai-chat"))e instanceof Lt&&e.reset()}};function up({hidden:t}){let e=new Ea({hidden:t});return window.Molin=e,e}function bs(){let t=window.Molin;if(!t)throw new Error("window.Molin global not initialized");return t}window.__INIT_MOLIN_SHOP_AI=function(e){C1(e);let r=st(),n=typeof r?.hidden=="boolean"?r.hidden:window.self!==window.top;if(up({hidden:n}),e.auto){let i=document.createElement("molin-shop-ai");i.setAttribute("cdn",e.cdn),i.setAttribute("widget",e.widgetId),document.body.appendChild(i)}};function C1(t){window.__INIT_MOLIN_SHOP_AI_OPTIONS=t}function pp(){return window.__INIT_MOLIN_SHOP_AI_OPTIONS}var Ee,Dn,$r,_r,ot=class{constructor(e,r){d(this,Ee);d(this,Dn);d(this,$r);d(this,_r);g(this,Ee,e),g(this,Dn,r),e.addController(this)}get data(){return a(this,_r)||a(this,$r)?.data}hostConnected(){if(a(this,$r)||a(this,_r))return;let e=pp();e&&e.widgetId===a(this,Ee).widgetId?g(this,_r,e.config):g(this,$r,new Ui(a(this,Ee),()=>{if(a(this,Ee).cdn&&a(this,Ee).widgetId)return`${a(this,Ee).cdn}/config?w=${a(this,Ee).widgetId}`;throw new Error("missing cdn or widgetId")},{fetchWhenConnected:!0,transform:async r=>{let n=await r.json();return n&&!e&&window.__INIT_MOLIN_SHOP_AI({cdn:a(this,Ee).cdn,widgetId:a(this,Ee).widgetId,config:n}),n},onError:a(this,Dn)?.onError}))}};Ee=new WeakMap,Dn=new WeakMap,$r=new WeakMap,_r=new WeakMap;function hp(){let t=new URL(import.meta.url).hostname;return{localhost:"http://uploads.molin.localhost:8787","molin.localhost":"http://uploads.molin.localhost:8787","widget.molin.foo":"https://widget.molin.foo","widget.molin.ai":"https://widget.molin.ai","molin.ai":"https://widget.molin.ai","molin.foo":"https://widget.molin.foo"}[t]||"https://widget.molin.ai"}var Pe=Object.freeze({PENDING:"pending",READY:"ready",ERROR:"error"}),F,W,oe,Ar,Mr,de,L,fp,$a,mp,ks,Pn,Rn,Bn,Vn,gp,xs,at,Un,_a,wp,yp,vp,gs=class{constructor(e,r={}){d(this,L);d(this,F);d(this,W);d(this,oe,null);d(this,Ar,!1);d(this,Mr,null);d(this,de,[]);d(this,ks,e=>{let r=e.target,n=Array.from(r.files||[]);m(this,L,_a).call(this,n),r.value=""});d(this,Pn,e=>{e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy")});d(this,Rn,e=>{e.preventDefault(),e.dataTransfer&&m(this,L,gp).call(this,e.dataTransfer)&&m(this,L,xs).call(this,!0)});d(this,Bn,e=>{e.preventDefault();let r=e.relatedTarget;a(this,F).contains(r)||m(this,L,xs).call(this,!1)});d(this,Vn,e=>{if(e.preventDefault(),m(this,L,xs).call(this,!1),e.dataTransfer){let r=Array.from(e.dataTransfer.files||[]);m(this,L,_a).call(this,r)}});w(this,"openImagePicker",()=>{a(this,oe)&&a(this,oe).click()});w(this,"onImageDelete",e=>{a(this,W).onImageDelete&&a(this,W).onImageDelete(e),g(this,de,a(this,de).filter(r=>r.id!==e)),m(this,L,Un).call(this),a(this,F).requestUpdate()});g(this,F,e),g(this,W,{acceptedTypes:["image/jpeg","image/png","image/gif","image/webp","image/svg+xml","image/heic"],maxFileSize:10*1024*1024,maxFiles:3,onError:()=>{},uploadUrl:new URL("/v1/uploads",hp()).href,enabled:!0,...r}),e.addController(this),m(this,L,mp).call(this)}hostConnected(){m(this,L,fp).call(this)}hostDisconnected(){m(this,L,$a).call(this),a(this,oe)&&a(this,oe).parentNode&&a(this,oe).parentNode.removeChild(a(this,oe))}get isDragging(){return a(this,Ar)}get error(){return a(this,Mr)}get selectedImages(){return a(this,de)}get hasPendingImages(){return a(this,de).some(e=>e.processingState===Pe.PENDING)}clearError(){m(this,L,Un).call(this)}updateUploadOptions(e){e.conversationId!==void 0&&(a(this,W).conversationId=e.conversationId),e.widgetId!==void 0&&(a(this,W).widgetId=e.widgetId),a(this,W).enabled=!!e.enabled,e.enabled||m(this,L,$a).call(this)}restoreImages(e){if(!Array.isArray(e)||e.length===0){g(this,de,[]),a(this,F).requestUpdate();return}let r=e.map(n=>{let i=new File([],n.name,{type:n.type});return{id:n.id,name:n.name,type:n.type,size:n.size,dataUrl:n.url,file:i,processingState:Pe.READY,imageUrl:n.url}});g(this,de,r),a(this,F).requestUpdate()}clearImages(){g(this,de,[]),this.clearError(),a(this,F).requestUpdate()}};F=new WeakMap,W=new WeakMap,oe=new WeakMap,Ar=new WeakMap,Mr=new WeakMap,de=new WeakMap,L=new WeakSet,fp=function(){a(this,W).enabled&&(a(this,F).addEventListener("dragover",a(this,Pn)),a(this,F).addEventListener("dragenter",a(this,Rn)),a(this,F).addEventListener("dragleave",a(this,Bn)),a(this,F).addEventListener("drop",a(this,Vn)))},$a=function(){a(this,F).removeEventListener("dragover",a(this,Pn)),a(this,F).removeEventListener("dragenter",a(this,Rn)),a(this,F).removeEventListener("dragleave",a(this,Bn)),a(this,F).removeEventListener("drop",a(this,Vn))},mp=function(){g(this,oe,document.createElement("input")),a(this,oe).type="file",a(this,oe).accept=a(this,W).acceptedTypes.join(","),a(this,oe).multiple=a(this,W).maxFiles>1,a(this,oe).style.display="none",a(this,oe).addEventListener("change",a(this,ks)),document.body.appendChild(a(this,oe))},ks=new WeakMap,Pn=new WeakMap,Rn=new WeakMap,Bn=new WeakMap,Vn=new WeakMap,gp=function(e){return e.types&&e.types.includes("Files")},xs=function(e){a(this,Ar)!==e&&(g(this,Ar,e),a(this,F).requestUpdate())},at=function(e){g(this,Mr,e),a(this,W).onError(e),a(this,F).requestUpdate(),setTimeout(()=>{m(this,L,Un).call(this)},6e3)},Un=function(){g(this,Mr,null),a(this,F).requestUpdate()},_a=async function(e){if(e.length===0)return;m(this,L,Un).call(this);let r=e.filter(o=>m(this,L,wp).call(this,o));if(r.length===0)return;let n=a(this,de).length,i=a(this,W).maxFiles??1/0,s=r.length;if(n+s>i){m(this,L,at).call(this,`You can upload a maximum of ${i} files`);return}try{let u=(await Promise.all(r.map(l=>m(this,L,yp).call(this,l)))).filter(l=>!a(this,de).some(c=>c.dataUrl===l.dataUrl));g(this,de,[...a(this,de),...u]),await oo(3,u,async l=>{await m(this,L,vp).call(this,l)}),a(this,F).requestUpdate()}catch(o){let u=o instanceof Error?o:new Error(String(o));m(this,L,at).call(this,"Upload failed")}},wp=function(e){return a(this,W).acceptedTypes.includes(e.type)?e.size>a(this,W).maxFileSize?(m(this,L,at).call(this,`Max file size: ${a(this,W).maxFileSize/(1024*1024)}MB`),!1):!0:(m(this,L,at).call(this,"Invalid file type"),!1)},yp=async function(e){try{let r=await(0,dp.fileToBase64)(e);return{id:crypto.randomUUID(),name:e.name,type:e.type,size:e.size,dataUrl:r,file:e,processingState:Pe.PENDING}}catch(r){let n=r instanceof Error?r:new Error(String(r));throw new Error(`Failed to read file: ${e.name} - ${n.message}`)}},vp=async function(e){if(!e){console.error("No image provided to upload"),m(this,L,at).call(this,"No image provided");return}if(!a(this,W)?.uploadUrl){console.error("Missing uploadUrl in options"),m(this,L,at).call(this,"Upload URL not configured");return}e.processingState=Pe.PENDING,a(this,F).requestUpdate();let r=new FormData;r.append("file",e.file),r.append("imageId",e.id),a(this,W).conversationId&&r.append("conversationId",a(this,W).conversationId),a(this,W).widgetId&&r.append("widgetId",a(this,W).widgetId);try{let n=await fetch(a(this,W).uploadUrl,{method:"POST",body:r});if(!n.ok)throw new Error(`Upload failed with status: ${n.status}`);let i=await n.json();if(!!!i?.success){let o=i?.error||"Upload failed";throw new Error(o)}i.imageUrl&&i.imageId?(e.imageUrl=i.imageUrl,e.id=i.imageId,e.processingState=Pe.READY):e.processingState=Pe.PENDING,a(this,F).requestUpdate()}catch(n){let i=n instanceof Error?n:new Error(String(n));console.error("Upload error:",i.message),m(this,L,at).call(this,i.message),e.processingState=Pe.ERROR,a(this,F).requestUpdate()}};var Aa={maxHeight:120,initialHeight:32,paddingY:12},Nn,Y,Ir,bp,xp,kp,Cp,Cs,Dt=class Dt extends A(E){constructor(){super();d(this,Y);d(this,Nn,new Date);this.disabled=!1,this.streaming=!1,this.loading=!1,this.placeholder="Type a message...",this.enableImageUpload=!1,this.onImageUploadClick=void 0,this.images=[],this.onImageDelete=void 0,this.color="#8B5CF6"}get value(){return a(this,Y,Ir)?.value?.trim()??""}render(){return f`
|
|
1856
1856
|
<div
|
|
1857
1857
|
class="focus-within:ring-opacity-50 ${this.enableImageUpload&&this.images.length>0?`ring-2 ring-[${this.color}] ring-opacity-50`:""} w-full overflow-hidden rounded-[18px] bg-white shadow-[0px_3px_20px_0px_rgba(0,0,0,0.2)] transition-all duration-200 focus-within:ring-2 focus-within:ring-[${this.color}]">
|
|
1858
1858
|
<!-- Image preview area -->
|