@molin.ai/shop-ai 0.9.26 → 0.9.27
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.
|
@@ -1269,7 +1269,7 @@ var Yd=Object.create;var Io=Object.defineProperty;var Xd=Object.getOwnPropertyDe
|
|
|
1269
1269
|
/* bg-color gradient */
|
|
1270
1270
|
background-image: linear-gradient(to bottom, white 20%, transparent);
|
|
1271
1271
|
}
|
|
1272
|
-
`);var Tt=kr,Da;Tt.NewChatClickEvent=(Da=class extends CustomEvent{constructor(e={}){super(Tt.NewChatClickEvent.type,{...e})}},w(Da,"type","mw:new-chat-click"),Da);var Oa;Tt.CloseClickEvent=(Oa=class extends CustomEvent{constructor(e={}){super(Tt.CloseClickEvent.type,{...e})}},w(Oa,"type","mw:close-click"),Oa);customElements.get("mw-chat-header")||customElements.define("mw-chat-header",Tt);var Wu=ip(zu(),1);var Re=Object.freeze({PENDING:"pending",READY:"ready",ERROR:"error"}),N,P,le,Sr,Er,me,O,Ba,qa,Gu,ms,jn,Dn,On,Un,Zu,ps,it,Ln,Va,Ju,Ku,Yu,fs=class{constructor(e,t){p(this,O);p(this,N);p(this,P);p(this,le,null);p(this,Sr,!1);p(this,Er,null);p(this,me,[]);p(this,ms,e=>{let t=e.target,n=Array.from(t.files||[]);o(this,P).isConnected()||o(this,P).onConnect?.(),m(this,O,Va).call(this,n),t.value=""});p(this,jn,e=>{e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy")});p(this,Dn,e=>{e.preventDefault(),e.dataTransfer&&m(this,O,Zu).call(this,e.dataTransfer)&&m(this,O,ps).call(this,!0)});p(this,On,e=>{e.preventDefault();let t=e.relatedTarget;o(this,N).contains(t)||m(this,O,ps).call(this,!1)});p(this,Un,e=>{if(e.preventDefault(),m(this,O,ps).call(this,!1),e.dataTransfer){let t=Array.from(e.dataTransfer.files||[]);m(this,O,Va).call(this,t)}});w(this,"openImagePicker",()=>{if(!o(this,P).enabled||!o(this,P).widgetId){console.warn("Image uploads are disabled");return}o(this,le)&&o(this,le).click()});w(this,"onImageDelete",e=>{o(this,P).onImageDelete&&o(this,P).onImageDelete(e),g(this,me,o(this,me).filter(t=>t.id!==e)),m(this,O,Ln).call(this),o(this,N).requestUpdate()});g(this,N,e),g(this,P,{acceptedTypes:["image/jpeg","image/png","image/gif","image/webp","image/svg+xml","image/heic"],maxFileSize:10*1024*1024,maxFiles:3,onError:()=>{},enabled:!0,isConnected:()=>!1,onConnect:()=>{},...t}),e.addController(this),m(this,O,Gu).call(this)}hostConnected(){m(this,O,Ba).call(this)}hostDisconnected(){m(this,O,qa).call(this),o(this,le)&&o(this,le).parentNode&&o(this,le).parentNode.removeChild(o(this,le))}get isDragging(){return o(this,Sr)}get error(){return o(this,Er)}get selectedImages(){return o(this,me)}get hasPendingImages(){return o(this,me).some(e=>e.processingState===Re.PENDING)}clearError(){m(this,O,Ln).call(this)}updateUploadOptions(e){let t=o(this,P).isConnected();e.conversationId!==void 0&&(o(this,P).conversationId=e.conversationId),e.widgetId!==void 0&&(o(this,P).widgetId=e.widgetId),e.enabled!==void 0&&(o(this,P).enabled=!!e.enabled),e.isConnected!==void 0&&(o(this,P).isConnected=e.isConnected),e.onConnect!==void 0&&(o(this,P).onConnect=e.onConnect),!o(this,P).enabled||!o(this,P).isConnected()?m(this,O,qa).call(this):!t&&o(this,P).isConnected()&&m(this,O,Ba).call(this)}restoreImages(e){if(!Array.isArray(e)||e.length===0){g(this,me,[]),o(this,N).requestUpdate();return}let t=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:Re.READY,imageUrl:n.url}});g(this,me,t),o(this,N).requestUpdate()}clearImages(){g(this,me,[]),this.clearError(),o(this,N).requestUpdate()}};N=new WeakMap,P=new WeakMap,le=new WeakMap,Sr=new WeakMap,Er=new WeakMap,me=new WeakMap,O=new WeakSet,Ba=function(){o(this,P).enabled&&o(this,P).isConnected()&&(o(this,N).addEventListener("dragover",o(this,jn)),o(this,N).addEventListener("dragenter",o(this,Dn)),o(this,N).addEventListener("dragleave",o(this,On)),o(this,N).addEventListener("drop",o(this,Un)))},qa=function(){o(this,N).removeEventListener("dragover",o(this,jn)),o(this,N).removeEventListener("dragenter",o(this,Dn)),o(this,N).removeEventListener("dragleave",o(this,On)),o(this,N).removeEventListener("drop",o(this,Un))},Gu=function(){g(this,le,document.createElement("input")),o(this,le).type="file",o(this,le).accept=o(this,P).acceptedTypes.join(","),o(this,le).multiple=o(this,P).maxFiles>1,o(this,le).style.display="none",o(this,le).addEventListener("change",o(this,ms)),document.body.appendChild(o(this,le))},ms=new WeakMap,jn=new WeakMap,Dn=new WeakMap,On=new WeakMap,Un=new WeakMap,Zu=function(e){return e.types&&e.types.includes("Files")},ps=function(e){o(this,Sr)!==e&&(g(this,Sr,e),o(this,N).requestUpdate())},it=function(e){g(this,Er,e),o(this,P).onError(e),o(this,N).requestUpdate(),setTimeout(()=>{m(this,O,Ln).call(this)},6e3)},Ln=function(){g(this,Er,null),o(this,N).requestUpdate()},Va=async function(e){if(e.length===0)return;m(this,O,Ln).call(this);let t=e.filter(a=>m(this,O,Ju).call(this,a));if(t.length===0)return;let n=o(this,me).length,i=o(this,P).maxFiles??1/0,s=t.length;if(n+s>i){m(this,O,it).call(this,`You can upload a maximum of ${i} files`);return}try{let l=(await Promise.all(t.map(c=>m(this,O,Ku).call(this,c)))).filter(c=>!o(this,me).some(u=>u.dataUrl===c.dataUrl));g(this,me,[...o(this,me),...l]),o(this,N).requestUpdate(),await Zo({times:5,delay:2e3},async()=>{if(o(this,P).isConnected())await Go(3,l,async c=>{await m(this,O,Yu).call(this,c)});else throw new Error("Not connected yet")}),o(this,N).requestUpdate()}catch(a){console.error("Failed to process and upload images:",a),m(this,O,it).call(this,"Upload failed")}},Ju=function(e){return o(this,P).acceptedTypes.includes(e.type)?e.size>o(this,P).maxFileSize?(m(this,O,it).call(this,`Max file size: ${o(this,P).maxFileSize/(1024*1024)}MB`),!1):!0:(m(this,O,it).call(this,"Invalid file type"),!1)},Ku=async function(e){try{let t=await(0,Wu.fileToBase64)(e);return{id:crypto.randomUUID(),name:e.name,type:e.type,size:e.size,dataUrl:t,file:e,processingState:Re.PENDING}}catch(t){let n=t instanceof Error?t:new Error(String(t));throw new Error(`Failed to read file: ${e.name} - ${n.message}`)}},Yu=async function(e){if(!e){console.error("No image provided to upload"),m(this,O,it).call(this,"No image provided");return}if(!o(this,P)?.uploadUrl){console.error("Missing uploadUrl in options"),m(this,O,it).call(this,"Upload URL not configured");return}e.processingState=Re.PENDING,o(this,N).requestUpdate();let t=new FormData;t.append("file",e.file),t.append("imageId",e.id),o(this,P).conversationId&&t.append("conversationId",o(this,P).conversationId),o(this,P).widgetId&&t.append("widgetId",o(this,P).widgetId);try{let n=await fetch(o(this,P).uploadUrl,{method:"POST",body:t});if(!n.ok)throw new Error(`Upload failed with status: ${n.status}`);let i=await n.json();if(!!!i?.success){let a=i?.error||"Upload failed";throw new Error(a)}i.imageUrl&&i.imageId?(e.imageUrl=i.imageUrl,e.id=i.imageId,e.processingState=Re.READY):e.processingState=Re.PENDING,o(this,N).requestUpdate()}catch(n){let i=n instanceof Error?n:new Error(String(n));console.error("Upload error:",i.message),m(this,O,it).call(this,i.message),e.processingState=Re.ERROR,o(this,N).requestUpdate()}};var Fa={maxHeight:120,initialHeight:32,paddingY:12},Pn,Q,_r,Xu,Qu,eh,th,gs,Ot=class Ot extends I($){constructor(){super();p(this,Q);p(this,Pn,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 o(this,Q,_r)?.value?.trim()??""}render(){return h`
|
|
1272
|
+
`);var Tt=kr,Da;Tt.NewChatClickEvent=(Da=class extends CustomEvent{constructor(e={}){super(Tt.NewChatClickEvent.type,{...e})}},w(Da,"type","mw:new-chat-click"),Da);var Oa;Tt.CloseClickEvent=(Oa=class extends CustomEvent{constructor(e={}){super(Tt.CloseClickEvent.type,{...e})}},w(Oa,"type","mw:close-click"),Oa);customElements.get("mw-chat-header")||customElements.define("mw-chat-header",Tt);var Wu=ip(zu(),1);var Re=Object.freeze({PENDING:"pending",READY:"ready",ERROR:"error"}),N,P,le,Sr,Er,me,O,Ba,qa,Gu,ms,jn,Dn,On,Un,Zu,ps,it,Ln,Va,Ju,Ku,Yu,fs=class{constructor(e,t){p(this,O);p(this,N);p(this,P);p(this,le,null);p(this,Sr,!1);p(this,Er,null);p(this,me,[]);p(this,ms,e=>{let t=e.target,n=Array.from(t.files||[]);o(this,P).isConnected()||o(this,P).onConnect?.(),m(this,O,Va).call(this,n),t.value=""});p(this,jn,e=>{e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy")});p(this,Dn,e=>{e.preventDefault(),e.dataTransfer&&m(this,O,Zu).call(this,e.dataTransfer)&&m(this,O,ps).call(this,!0)});p(this,On,e=>{e.preventDefault();let t=e.relatedTarget;o(this,N).contains(t)||m(this,O,ps).call(this,!1)});p(this,Un,e=>{if(e.preventDefault(),m(this,O,ps).call(this,!1),e.dataTransfer){let t=Array.from(e.dataTransfer.files||[]);m(this,O,Va).call(this,t)}});w(this,"openImagePicker",()=>{if(!o(this,P).enabled||!o(this,P).widgetId){console.warn("Image uploads are disabled");return}o(this,le)&&o(this,le).click()});w(this,"onImageDelete",e=>{o(this,P).onImageDelete&&o(this,P).onImageDelete(e),g(this,me,o(this,me).filter(t=>t.id!==e)),m(this,O,Ln).call(this),o(this,N).requestUpdate()});g(this,N,e),g(this,P,{acceptedTypes:["image/jpeg","image/png","image/gif","image/webp","image/svg+xml","image/heic"],maxFileSize:10*1024*1024,maxFiles:3,onError:()=>{},enabled:!0,isConnected:()=>!1,onConnect:()=>{},...t}),e.addController(this),m(this,O,Gu).call(this)}hostConnected(){m(this,O,Ba).call(this)}hostDisconnected(){m(this,O,qa).call(this),o(this,le)&&o(this,le).parentNode&&o(this,le).parentNode.removeChild(o(this,le))}get isDragging(){return o(this,Sr)}get error(){return o(this,Er)}get selectedImages(){return o(this,me)}get hasPendingImages(){return o(this,me).some(e=>e.processingState===Re.PENDING)}clearError(){m(this,O,Ln).call(this)}updateUploadOptions(e){let t=o(this,P).isConnected();e.conversationId!==void 0&&(o(this,P).conversationId=e.conversationId),e.widgetId!==void 0&&(o(this,P).widgetId=e.widgetId),e.enabled!==void 0&&(o(this,P).enabled=!!e.enabled),e.isConnected!==void 0&&(o(this,P).isConnected=e.isConnected),e.onConnect!==void 0&&(o(this,P).onConnect=e.onConnect),!o(this,P).enabled||!o(this,P).isConnected()?m(this,O,qa).call(this):!t&&o(this,P).isConnected()&&m(this,O,Ba).call(this)}restoreImages(e){if(!Array.isArray(e)||e.length===0){g(this,me,[]),o(this,N).requestUpdate();return}let t=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:Re.READY,imageUrl:n.url}});g(this,me,t),o(this,N).requestUpdate()}clearImages(){g(this,me,[]),this.clearError(),o(this,N).requestUpdate()}};N=new WeakMap,P=new WeakMap,le=new WeakMap,Sr=new WeakMap,Er=new WeakMap,me=new WeakMap,O=new WeakSet,Ba=function(){o(this,P).enabled&&o(this,P).isConnected()&&(o(this,N).addEventListener("dragover",o(this,jn)),o(this,N).addEventListener("dragenter",o(this,Dn)),o(this,N).addEventListener("dragleave",o(this,On)),o(this,N).addEventListener("drop",o(this,Un)))},qa=function(){o(this,N).removeEventListener("dragover",o(this,jn)),o(this,N).removeEventListener("dragenter",o(this,Dn)),o(this,N).removeEventListener("dragleave",o(this,On)),o(this,N).removeEventListener("drop",o(this,Un))},Gu=function(){g(this,le,document.createElement("input")),o(this,le).type="file",o(this,le).accept=o(this,P).acceptedTypes.join(","),o(this,le).multiple=o(this,P).maxFiles>1,o(this,le).style.display="none",o(this,le).addEventListener("change",o(this,ms)),document.body.appendChild(o(this,le))},ms=new WeakMap,jn=new WeakMap,Dn=new WeakMap,On=new WeakMap,Un=new WeakMap,Zu=function(e){return e.types&&e.types.includes("Files")},ps=function(e){o(this,Sr)!==e&&(g(this,Sr,e),o(this,N).requestUpdate())},it=function(e){g(this,Er,e),o(this,P).onError(e),o(this,N).requestUpdate(),setTimeout(()=>{m(this,O,Ln).call(this)},6e3)},Ln=function(){g(this,Er,null),o(this,N).requestUpdate()},Va=async function(e){if(e.length===0)return;m(this,O,Ln).call(this);let t=e.filter(a=>m(this,O,Ju).call(this,a));if(t.length===0)return;let n=o(this,me).length,i=o(this,P).maxFiles??1/0,s=t.length;if(n+s>i){m(this,O,it).call(this,`You can upload a maximum of ${i} files`);return}try{let l=(await Promise.all(t.map(c=>m(this,O,Ku).call(this,c)))).filter(c=>!o(this,me).some(u=>u.dataUrl===c.dataUrl));g(this,me,[...o(this,me),...l]),o(this,N).requestUpdate(),await Zo({times:5,delay:2e3},async()=>{if(o(this,P).isConnected())await Go(3,l,async c=>{await m(this,O,Yu).call(this,c)});else throw new Error("Not connected yet")}),o(this,N).requestUpdate()}catch(a){console.error("Failed to process and upload images:",a),m(this,O,it).call(this,"Upload failed")}},Ju=function(e){return o(this,P).acceptedTypes.includes(e.type)?e.size>o(this,P).maxFileSize?(m(this,O,it).call(this,`Max file size: ${o(this,P).maxFileSize/(1024*1024)}MB`),!1):!0:(m(this,O,it).call(this,"Invalid file type"),!1)},Ku=async function(e){try{let t=await(0,Wu.fileToBase64)(e);return{id:crypto.randomUUID(),name:e.name,type:e.type,size:e.size,dataUrl:t,file:e,processingState:Re.PENDING}}catch(t){let n=t instanceof Error?t:new Error(String(t));throw new Error(`Failed to read file: ${e.name} - ${n.message}`)}},Yu=async function(e){if(!e){console.error("No image provided to upload"),m(this,O,it).call(this,"No image provided");return}if(!o(this,P)?.uploadUrl){console.error("Missing uploadUrl in options"),m(this,O,it).call(this,"Upload URL not configured");return}e.processingState=Re.PENDING,o(this,N).requestUpdate();let t=new FormData;t.append("file",e.file),t.append("imageId",e.id),t.append("role",o(this,P).role||"user"),o(this,P).conversationId&&t.append("conversationId",o(this,P).conversationId),o(this,P).widgetId&&t.append("widgetId",o(this,P).widgetId);try{let n=await fetch(o(this,P).uploadUrl,{method:"POST",body:t});if(!n.ok)throw new Error(`Upload failed with status: ${n.status}`);let i=await n.json();if(!!!i?.success){let a=i?.error||"Upload failed";throw new Error(a)}i.imageUrl&&i.imageId?(e.imageUrl=i.imageUrl,e.id=i.imageId,e.processingState=Re.READY):e.processingState=Re.PENDING,o(this,N).requestUpdate()}catch(n){let i=n instanceof Error?n:new Error(String(n));console.error("Upload error:",i.message),m(this,O,it).call(this,i.message),e.processingState=Re.ERROR,o(this,N).requestUpdate()}};var Fa={maxHeight:120,initialHeight:32,paddingY:12},Pn,Q,_r,Xu,Qu,eh,th,gs,Ot=class Ot extends I($){constructor(){super();p(this,Q);p(this,Pn,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 o(this,Q,_r)?.value?.trim()??""}render(){return h`
|
|
1273
1273
|
<div
|
|
1274
1274
|
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}]">
|
|
1275
1275
|
<!-- Image preview area -->
|
|
@@ -1428,7 +1428,7 @@ var Yd=Object.create;var Io=Object.defineProperty;var Xd=Object.getOwnPropertyDe
|
|
|
1428
1428
|
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
1429
1429
|
</svg>
|
|
1430
1430
|
</button>
|
|
1431
|
-
<div class="relative max-h-full max-w-full">
|
|
1431
|
+
<div class="relative flex max-h-full max-w-full">
|
|
1432
1432
|
<img
|
|
1433
1433
|
src="${m(this,ot,ih).call(this)}"
|
|
1434
1434
|
alt="${this.alt}"
|