@weaverse/core 0.7.45 → 0.7.48

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/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var b=Object.create;var p=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var S=(e,t)=>{for(var i in t)p(e,i,{get:t[i],enumerable:!0})},m=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of w(t))!D.call(e,n)&&n!==i&&p(e,n,{get:()=>t[n],enumerable:!(s=x(t,n))||s.enumerable});return e};var E=(e,t,i)=>(i=e!=null?b(j(e)):{},m(t||!e||!e.__esModule?p(i,"default",{value:e,enumerable:!0}):i,e)),I=e=>m(p({},"__esModule",{value:!0}),e);var v={};S(v,{Weaverse:()=>c,WeaverseItemStore:()=>o,createGlobalStyles:()=>h,isBrowser:()=>f,isIframe:()=>g,isReactNative:()=>u,merge:()=>d,stichesUtils:()=>l});module.exports=I(v);var y=E(require("@stitches/core"));var l={m:e=>({margin:e}),mt:e=>({marginTop:e}),mr:e=>({marginRight:e}),mb:e=>({marginBottom:e}),ml:e=>({marginLeft:e}),mx:e=>({marginLeft:e,marginRight:e}),my:e=>({marginTop:e,marginBottom:e}),size:e=>({width:e,height:e}),px:e=>({paddingLeft:e,paddingRight:e}),py:e=>({paddingTop:e,paddingBottom:e})};function h(e){e.globalCss({"@keyframes spin":{from:{transform:"rotate(0deg)"},to:{transform:"rotate(360deg)"}},"@keyframes pulse":{"0%, 100%":{opacity:1},"50%":{opacity:.5}},".wv-spinner-wrapper":{position:"absolute",inset:"0px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"inherit",".wv-spinner":{width:"20px",height:"20px",animation:"spin .75s linear infinite"}},"[data-wv-placeholder]":{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(236, 236, 236, 0.5)",backgroundClip:"content-box",padding:"10px"},"[data-blink-src]":{visibility:"hidden"},body:{"&.wv-modal-open":{".weaverse-content-root":{zIndex:9999,'[data-wv-type="product-details"]':{zIndex:999}}}},".weaverse-content-root":{position:"relative",zIndex:0,"*":{WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"auto",textRendering:"optimizeLegibility",boxSizing:"border-box"},input:{"&::-webkit-outer-spin-button, &::-webkit-inner-spin-button":{"-webkit-appearance":"none",margin:0},"&[type=number]":{"-moz-appearance":"textfield"}},select:{WebkitAppearance:"none",MozAppearance:"none",appearance:"none",outline:"none",boxShadow:"none",color:"currentColor",verticalAlign:"middle",backgroundColor:"transparent",backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundImage:"url(https://ucarecdn.com/4bb6a6e7-1ce8-4201-8f2d-da00a50105f3/)",backgroundSize:"10px",backgroundPositionX:"calc(100% - 12px)",paddingLeft:"12px",paddingRight:"35px !important",cursor:"pointer"},button:{outline:"none",boxShadow:"none",cursor:"pointer",border:"none","&:focus":{outline:"none",boxShadow:"none"}},".animate-pulse":{animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"}},".wv-error-boundary":{textAlign:"center",padding:"32px 0",button:{cursor:"pointer",fontSize:"14px",padding:"4px 10px"}}})()}var u=typeof navigator=="object"&&navigator.product==="ReactNative",f=typeof window<"u"&&!u,g=f&&window.top!==window.self;function d(e,t){let i={...e||{}};for(let s of Object.keys(t))t[s]instanceof Object&&!Array.isArray(t[s])&&Object.assign(t[s],d(i[s],t[s]));return Object.assign(i||{},t),i}var o=class{constructor(t,i){this.listeners=new Set;this.ref={current:null};this.stitchesClass="";this._data={id:"",type:""};this._flags={};this.setData=t=>(this.data=Object.assign(this.data,t),this.triggerUpdate(),this.data);this.subscribe=t=>{this.listeners.add(t)};this.unsubscribe=t=>{this.listeners.delete(t)};this.triggerUpdate=()=>{this.listeners.forEach(t=>t(this.data))};let{type:s,id:n}=t;this.weaverse=i,n&&s&&(i.itemInstances.set(n,this),this.data={...t})}get _id(){return this._data.id}get _element(){return this.ref.current}get Element(){return this.weaverse.elementInstances.get(this._data.type)}set data(t){this._data={...this.data,...t}}get data(){let t=this.Element?.defaultCss||{},i=this._data.css||{},s=d(t,i);return{...{...this.Element?.Component?.defaultProps},...this._data,css:s}}},c=class{constructor({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:n,isDesignMode:a,ssrMode:r}={}){this.elementInstances=new Map;this.itemInstances=new Map;this.appUrl=process.env.NODE_ENV==="development"?"http://localhost:3000":"https://studio.weaverse.io";this.projectKey="";this.projectData={rootId:"",items:[],script:{css:"",js:""}};this.listeners=new Set;this.isDesignMode=!1;this.ssrMode=!1;this.mediaBreakPoints={desktop:"all",mobile:"(max-width: 767.98px)"};this.initialized=!1;this.initializeData=t=>{if(!this.initialized){let{data:i,published:s,id:n,projectKey:a,studioUrl:r}=t;this.projectKey=a||this.projectKey,this.appUrl=r||this.appUrl,this.projectData={...i,pageId:n},this.isDesignMode=!s,this.initProjectItemData(),this.isDesignMode&&(this.triggerUpdate(),this.loadStudio())}this.initialized=!0};this.initStitches=()=>{this.stitchesInstance=this.stitchesInstance||y.createStitches({prefix:"weaverse",media:this.mediaBreakPoints,utils:l}),h(this.stitchesInstance)};this.init({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:n,isDesignMode:a,ssrMode:r})}init({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:n,isDesignMode:a,ssrMode:r}={}){this.appUrl=t||this.appUrl,this.projectKey=i||this.projectKey,this.mediaBreakPoints=n||this.mediaBreakPoints,this.isDesignMode=a||this.isDesignMode,this.ssrMode=r||this.ssrMode,this.projectData=s||this.projectData,this.initStitches(),this.initProjectItemData()}loadStudio(){setTimeout(()=>{if(g&&this.isDesignMode&&!this.studioBridge){let t=()=>{this.studioBridge=new window.WeaverseStudioBridge(this),this.triggerUpdate()};if(window.WeaverseStudioBridge)t();else{let i=document.createElement("script"),s=new Date().getTime();i.src=`${this.appUrl}/assets/studio/studio-bridge.js?t=${s}`,i.type="module",i.onload=t,document.body.appendChild(i)}}},2e3)}registerElement(t){if(t?.type){if(this.elementInstances.has(t.type))throw new Error(`Weaverse: Element '${t.type}' already registered`);this.elementInstances.set(t?.type,t)}else throw new Error("Weaverse: registerElement: `type` is required")}subscribe(t){this.listeners.add(t)}unsubscribe(t){this.listeners.delete(t)}triggerUpdate(){this.listeners.forEach(t=>t())}static fetchProjectData({fetch:t=globalThis.fetch,appUrl:i,projectKey:s}){return t(i+`/api/public/project/${s}`).then(n=>n.json()).catch(n=>console.log("Error fetching project data:",n))}setProjectData(t){this.projectData=t,this.initProjectItemData(),this.triggerUpdate()}initProjectItemData(){let t=this.projectData;t?.items&&t.items.forEach(i=>{this.itemInstances.get(i.id)||new o(i,this)})}};c.WeaverseItemStore=o;0&&(module.exports={Weaverse,WeaverseItemStore,createGlobalStyles,isBrowser,isIframe,isReactNative,merge,stichesUtils});
1
+ "use strict";var y=Object.create;var p=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var i in t)p(e,i,{get:t[i],enumerable:!0})},g=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of w(t))!j.call(e,a)&&a!==i&&p(e,a,{get:()=>t[a],enumerable:!(s=x(t,a))||s.enumerable});return e};var S=(e,t,i)=>(i=e!=null?y(v(e)):{},g(t||!e||!e.__esModule?p(i,"default",{value:e,enumerable:!0}):i,e)),E=e=>g(p({},"__esModule",{value:!0}),e);var k={};D(k,{Weaverse:()=>c,WeaverseItemStore:()=>o,createGlobalStyles:()=>h,isBrowser:()=>f,isIframe:()=>m,isReactNative:()=>u,merge:()=>d,stichesUtils:()=>l});module.exports=E(k);var b=S(require("@stitches/core"));var l={m:e=>({margin:e}),mt:e=>({marginTop:e}),mr:e=>({marginRight:e}),mb:e=>({marginBottom:e}),ml:e=>({marginLeft:e}),mx:e=>({marginLeft:e,marginRight:e}),my:e=>({marginTop:e,marginBottom:e}),size:e=>({width:e,height:e}),px:e=>({paddingLeft:e,paddingRight:e}),py:e=>({paddingTop:e,paddingBottom:e})};function h(e){e.globalCss({"@keyframes spin":{from:{transform:"rotate(0deg)"},to:{transform:"rotate(360deg)"}},"@keyframes pulse":{"0%, 100%":{opacity:1},"50%":{opacity:.5}},".wv-tooltip-container":{position:"relative !important",display:"inline-flex !important",".wv-tooltip":{position:"absolute",color:"#fff !important",backgroundColor:"#000 !important",fontSize:"13px",textAlign:"center",transition:".3s all",borderRadius:"5px !important",lineHeight:"12px",bottom:"calc(100% + 5px)",left:"50%",transform:"translateX(-50%)",padding:"8px 12px",opacity:0,visibility:"hidden",textTransform:"initial",width:"max-content !important",maxWidth:"initial !important",height:"auto !important",display:"inline-block !important","&:after":{content:'""',position:"absolute",width:"10px",height:"10px",backgroundColor:"#000",bottom:"-4px",left:"50%",transform:"translateX(-50%) rotate(45deg)"}},"&:hover":{".wv-tooltip":{opacity:1,visibility:"visible",bottom:"calc(100% + 10px)"}}},".wv-spinner-wrapper":{position:"absolute",inset:"0px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"inherit",".wv-spinner":{width:"20px",height:"20px",animation:"spin .75s linear infinite"}},"[data-wv-placeholder]":{height:"100%",width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(236, 236, 236, 0.5)",backgroundClip:"content-box",padding:"10px"},".wv-pcard__quickview":{borderRadius:"0px !important",width:"950px !important"},body:{"&.wv-modal-open":{".weaverse-content-root":{zIndex:9999,'[data-wv-type="product-details"]':{zIndex:999}}}},".weaverse-content-root":{position:"relative",zIndex:0,"*":{WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"auto",textRendering:"optimizeLegibility",boxSizing:"border-box"},input:{"&::-webkit-outer-spin-button, &::-webkit-inner-spin-button":{"-webkit-appearance":"none",margin:0},"&[type=number]":{"-moz-appearance":"textfield"}},select:{WebkitAppearance:"none",MozAppearance:"none",appearance:"none",outline:"none",boxShadow:"none",color:"currentColor",verticalAlign:"middle",backgroundColor:"transparent",backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundImage:"url(https://ucarecdn.com/4bb6a6e7-1ce8-4201-8f2d-da00a50105f3/)",backgroundSize:"10px",backgroundPositionX:"calc(100% - 12px)",paddingLeft:"12px",paddingRight:"35px !important",cursor:"pointer"},button:{outline:"none",boxShadow:"none",cursor:"pointer",border:"none","&:focus":{outline:"none",boxShadow:"none"}},".animate-pulse":{animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"}},".wv-error-boundary":{textAlign:"center",padding:"32px 0",button:{cursor:"pointer",fontSize:"14px",padding:"4px 10px"}},"@media (max-width: 768px)":{".wv-tooltip-container":{".wv-tooltip":{display:"none !important"}}}})()}var u=typeof navigator=="object"&&navigator.product==="ReactNative",f=typeof window<"u"&&!u,m=f&&window.top!==window.self;function d(e,t){let i={...e||{}};for(let s of Object.keys(t))t[s]instanceof Object&&!Array.isArray(t[s])&&Object.assign(t[s],d(i[s],t[s]));return Object.assign(i||{},t),i}var o=class{constructor(t,i){this.listeners=new Set;this.ref={current:null};this.stitchesClass="";this._data={id:"",type:""};this._flags={};this.setData=t=>(this.data=Object.assign(this.data,t),this.triggerUpdate(),this.data);this.subscribe=t=>{this.listeners.add(t)};this.unsubscribe=t=>{this.listeners.delete(t)};this.triggerUpdate=()=>{this.listeners.forEach(t=>t(this.data))};let{type:s,id:a}=t;this.weaverse=i,a&&s&&(i.itemInstances.set(a,this),this.data={...t})}get _id(){return this._data.id}get _element(){return this.ref.current}get Element(){return this.weaverse.elementInstances.get(this._data.type)}set data(t){this._data={...this.data,...t}}get data(){let t=this.Element?.defaultCss||{},i=this._data.css||{},s=d(t,i);return{...{...this.Element?.Component?.defaultProps},...this._data,css:s}}},c=class{constructor({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:a,isDesignMode:n,ssrMode:r}={}){this.elementInstances=new Map;this.itemInstances=new Map;this.appUrl=process.env.NODE_ENV==="development"?"http://localhost:3000":"https://studio.weaverse.io";this.projectKey="";this.projectData={rootId:"",items:[],script:{css:"",js:""}};this.listeners=new Set;this.isDesignMode=!1;this.ssrMode=!1;this.mediaBreakPoints={desktop:"all",mobile:"(max-width: 767.98px)"};this.initialized=!1;this.initializeData=t=>{if(!this.initialized){let{data:i,published:s,id:a,projectKey:n,studioUrl:r}=t;this.projectKey=n||this.projectKey,this.appUrl=r||this.appUrl,this.projectData={...i,pageId:a},this.isDesignMode=!s,this.initProjectItemData(),this.isDesignMode&&(this.triggerUpdate(),this.loadStudio())}this.initialized=!0};this.initStitches=()=>{this.stitchesInstance=this.stitchesInstance||b.createStitches({prefix:"weaverse",media:this.mediaBreakPoints,utils:l}),h(this.stitchesInstance)};this.init({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:a,isDesignMode:n,ssrMode:r})}init({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:a,isDesignMode:n,ssrMode:r}={}){this.appUrl=t||this.appUrl,this.projectKey=i||this.projectKey,this.mediaBreakPoints=a||this.mediaBreakPoints,this.isDesignMode=n||this.isDesignMode,this.ssrMode=r||this.ssrMode,this.projectData=s||this.projectData,this.initStitches(),this.initProjectItemData()}loadStudio(){setTimeout(()=>{if(m&&this.isDesignMode&&!this.studioBridge){let t=()=>{this.studioBridge=new window.WeaverseStudioBridge(this),this.triggerUpdate()};if(window.WeaverseStudioBridge)t();else{let i=document.createElement("script"),s=new Date().getTime();i.src=`${this.appUrl}/assets/studio/studio-bridge.js?t=${s}`,i.type="module",i.onload=t,document.body.appendChild(i)}}},2e3)}registerElement(t){if(t?.type){if(this.elementInstances.has(t.type))throw new Error(`Weaverse: Element '${t.type}' already registered`);this.elementInstances.set(t?.type,t)}else throw new Error("Weaverse: registerElement: `type` is required")}subscribe(t){this.listeners.add(t)}unsubscribe(t){this.listeners.delete(t)}triggerUpdate(){this.listeners.forEach(t=>t())}static fetchProjectData({fetch:t=globalThis.fetch,appUrl:i,projectKey:s}){return t(i+`/api/public/project/${s}`).then(a=>a.json()).catch(a=>console.log("Error fetching project data:",a))}setProjectData(t){this.projectData=t,this.initProjectItemData(),this.triggerUpdate()}initProjectItemData(){let t=this.projectData;t?.items&&t.items.forEach(i=>{this.itemInstances.get(i.id)||new o(i,this)})}};c.WeaverseItemStore=o;0&&(module.exports={Weaverse,WeaverseItemStore,createGlobalStyles,isBrowser,isIframe,isReactNative,merge,stichesUtils});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import*as g from"@stitches/core";var c={m:e=>({margin:e}),mt:e=>({marginTop:e}),mr:e=>({marginRight:e}),mb:e=>({marginBottom:e}),ml:e=>({marginLeft:e}),mx:e=>({marginLeft:e,marginRight:e}),my:e=>({marginTop:e,marginBottom:e}),size:e=>({width:e,height:e}),px:e=>({paddingLeft:e,paddingRight:e}),py:e=>({paddingTop:e,paddingBottom:e})};function l(e){e.globalCss({"@keyframes spin":{from:{transform:"rotate(0deg)"},to:{transform:"rotate(360deg)"}},"@keyframes pulse":{"0%, 100%":{opacity:1},"50%":{opacity:.5}},".wv-spinner-wrapper":{position:"absolute",inset:"0px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"inherit",".wv-spinner":{width:"20px",height:"20px",animation:"spin .75s linear infinite"}},"[data-wv-placeholder]":{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(236, 236, 236, 0.5)",backgroundClip:"content-box",padding:"10px"},"[data-blink-src]":{visibility:"hidden"},body:{"&.wv-modal-open":{".weaverse-content-root":{zIndex:9999,'[data-wv-type="product-details"]':{zIndex:999}}}},".weaverse-content-root":{position:"relative",zIndex:0,"*":{WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"auto",textRendering:"optimizeLegibility",boxSizing:"border-box"},input:{"&::-webkit-outer-spin-button, &::-webkit-inner-spin-button":{"-webkit-appearance":"none",margin:0},"&[type=number]":{"-moz-appearance":"textfield"}},select:{WebkitAppearance:"none",MozAppearance:"none",appearance:"none",outline:"none",boxShadow:"none",color:"currentColor",verticalAlign:"middle",backgroundColor:"transparent",backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundImage:"url(https://ucarecdn.com/4bb6a6e7-1ce8-4201-8f2d-da00a50105f3/)",backgroundSize:"10px",backgroundPositionX:"calc(100% - 12px)",paddingLeft:"12px",paddingRight:"35px !important",cursor:"pointer"},button:{outline:"none",boxShadow:"none",cursor:"pointer",border:"none","&:focus":{outline:"none",boxShadow:"none"}},".animate-pulse":{animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"}},".wv-error-boundary":{textAlign:"center",padding:"32px 0",button:{cursor:"pointer",fontSize:"14px",padding:"4px 10px"}}})()}var m=typeof navigator=="object"&&navigator.product==="ReactNative",u=typeof window<"u"&&!m,h=u&&window.top!==window.self;function p(e,t){let i={...e||{}};for(let s of Object.keys(t))t[s]instanceof Object&&!Array.isArray(t[s])&&Object.assign(t[s],p(i[s],t[s]));return Object.assign(i||{},t),i}var o=class{constructor(t,i){this.listeners=new Set;this.ref={current:null};this.stitchesClass="";this._data={id:"",type:""};this._flags={};this.setData=t=>(this.data=Object.assign(this.data,t),this.triggerUpdate(),this.data);this.subscribe=t=>{this.listeners.add(t)};this.unsubscribe=t=>{this.listeners.delete(t)};this.triggerUpdate=()=>{this.listeners.forEach(t=>t(this.data))};let{type:s,id:n}=t;this.weaverse=i,n&&s&&(i.itemInstances.set(n,this),this.data={...t})}get _id(){return this._data.id}get _element(){return this.ref.current}get Element(){return this.weaverse.elementInstances.get(this._data.type)}set data(t){this._data={...this.data,...t}}get data(){let t=this.Element?.defaultCss||{},i=this._data.css||{},s=p(t,i);return{...{...this.Element?.Component?.defaultProps},...this._data,css:s}}},d=class{constructor({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:n,isDesignMode:a,ssrMode:r}={}){this.elementInstances=new Map;this.itemInstances=new Map;this.appUrl=process.env.NODE_ENV==="development"?"http://localhost:3000":"https://studio.weaverse.io";this.projectKey="";this.projectData={rootId:"",items:[],script:{css:"",js:""}};this.listeners=new Set;this.isDesignMode=!1;this.ssrMode=!1;this.mediaBreakPoints={desktop:"all",mobile:"(max-width: 767.98px)"};this.initialized=!1;this.initializeData=t=>{if(!this.initialized){let{data:i,published:s,id:n,projectKey:a,studioUrl:r}=t;this.projectKey=a||this.projectKey,this.appUrl=r||this.appUrl,this.projectData={...i,pageId:n},this.isDesignMode=!s,this.initProjectItemData(),this.isDesignMode&&(this.triggerUpdate(),this.loadStudio())}this.initialized=!0};this.initStitches=()=>{this.stitchesInstance=this.stitchesInstance||g.createStitches({prefix:"weaverse",media:this.mediaBreakPoints,utils:c}),l(this.stitchesInstance)};this.init({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:n,isDesignMode:a,ssrMode:r})}init({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:n,isDesignMode:a,ssrMode:r}={}){this.appUrl=t||this.appUrl,this.projectKey=i||this.projectKey,this.mediaBreakPoints=n||this.mediaBreakPoints,this.isDesignMode=a||this.isDesignMode,this.ssrMode=r||this.ssrMode,this.projectData=s||this.projectData,this.initStitches(),this.initProjectItemData()}loadStudio(){setTimeout(()=>{if(h&&this.isDesignMode&&!this.studioBridge){let t=()=>{this.studioBridge=new window.WeaverseStudioBridge(this),this.triggerUpdate()};if(window.WeaverseStudioBridge)t();else{let i=document.createElement("script"),s=new Date().getTime();i.src=`${this.appUrl}/assets/studio/studio-bridge.js?t=${s}`,i.type="module",i.onload=t,document.body.appendChild(i)}}},2e3)}registerElement(t){if(t?.type){if(this.elementInstances.has(t.type))throw new Error(`Weaverse: Element '${t.type}' already registered`);this.elementInstances.set(t?.type,t)}else throw new Error("Weaverse: registerElement: `type` is required")}subscribe(t){this.listeners.add(t)}unsubscribe(t){this.listeners.delete(t)}triggerUpdate(){this.listeners.forEach(t=>t())}static fetchProjectData({fetch:t=globalThis.fetch,appUrl:i,projectKey:s}){return t(i+`/api/public/project/${s}`).then(n=>n.json()).catch(n=>console.log("Error fetching project data:",n))}setProjectData(t){this.projectData=t,this.initProjectItemData(),this.triggerUpdate()}initProjectItemData(){let t=this.projectData;t?.items&&t.items.forEach(i=>{this.itemInstances.get(i.id)||new o(i,this)})}};d.WeaverseItemStore=o;export{d as Weaverse,o as WeaverseItemStore,l as createGlobalStyles,u as isBrowser,h as isIframe,m as isReactNative,p as merge,c as stichesUtils};
1
+ import*as m from"@stitches/core";var c={m:e=>({margin:e}),mt:e=>({marginTop:e}),mr:e=>({marginRight:e}),mb:e=>({marginBottom:e}),ml:e=>({marginLeft:e}),mx:e=>({marginLeft:e,marginRight:e}),my:e=>({marginTop:e,marginBottom:e}),size:e=>({width:e,height:e}),px:e=>({paddingLeft:e,paddingRight:e}),py:e=>({paddingTop:e,paddingBottom:e})};function l(e){e.globalCss({"@keyframes spin":{from:{transform:"rotate(0deg)"},to:{transform:"rotate(360deg)"}},"@keyframes pulse":{"0%, 100%":{opacity:1},"50%":{opacity:.5}},".wv-tooltip-container":{position:"relative !important",display:"inline-flex !important",".wv-tooltip":{position:"absolute",color:"#fff !important",backgroundColor:"#000 !important",fontSize:"13px",textAlign:"center",transition:".3s all",borderRadius:"5px !important",lineHeight:"12px",bottom:"calc(100% + 5px)",left:"50%",transform:"translateX(-50%)",padding:"8px 12px",opacity:0,visibility:"hidden",textTransform:"initial",width:"max-content !important",maxWidth:"initial !important",height:"auto !important",display:"inline-block !important","&:after":{content:'""',position:"absolute",width:"10px",height:"10px",backgroundColor:"#000",bottom:"-4px",left:"50%",transform:"translateX(-50%) rotate(45deg)"}},"&:hover":{".wv-tooltip":{opacity:1,visibility:"visible",bottom:"calc(100% + 10px)"}}},".wv-spinner-wrapper":{position:"absolute",inset:"0px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"inherit",".wv-spinner":{width:"20px",height:"20px",animation:"spin .75s linear infinite"}},"[data-wv-placeholder]":{height:"100%",width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(236, 236, 236, 0.5)",backgroundClip:"content-box",padding:"10px"},".wv-pcard__quickview":{borderRadius:"0px !important",width:"950px !important"},body:{"&.wv-modal-open":{".weaverse-content-root":{zIndex:9999,'[data-wv-type="product-details"]':{zIndex:999}}}},".weaverse-content-root":{position:"relative",zIndex:0,"*":{WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"auto",textRendering:"optimizeLegibility",boxSizing:"border-box"},input:{"&::-webkit-outer-spin-button, &::-webkit-inner-spin-button":{"-webkit-appearance":"none",margin:0},"&[type=number]":{"-moz-appearance":"textfield"}},select:{WebkitAppearance:"none",MozAppearance:"none",appearance:"none",outline:"none",boxShadow:"none",color:"currentColor",verticalAlign:"middle",backgroundColor:"transparent",backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundImage:"url(https://ucarecdn.com/4bb6a6e7-1ce8-4201-8f2d-da00a50105f3/)",backgroundSize:"10px",backgroundPositionX:"calc(100% - 12px)",paddingLeft:"12px",paddingRight:"35px !important",cursor:"pointer"},button:{outline:"none",boxShadow:"none",cursor:"pointer",border:"none","&:focus":{outline:"none",boxShadow:"none"}},".animate-pulse":{animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"}},".wv-error-boundary":{textAlign:"center",padding:"32px 0",button:{cursor:"pointer",fontSize:"14px",padding:"4px 10px"}},"@media (max-width: 768px)":{".wv-tooltip-container":{".wv-tooltip":{display:"none !important"}}}})()}var g=typeof navigator=="object"&&navigator.product==="ReactNative",u=typeof window<"u"&&!g,h=u&&window.top!==window.self;function p(e,t){let i={...e||{}};for(let s of Object.keys(t))t[s]instanceof Object&&!Array.isArray(t[s])&&Object.assign(t[s],p(i[s],t[s]));return Object.assign(i||{},t),i}var o=class{constructor(t,i){this.listeners=new Set;this.ref={current:null};this.stitchesClass="";this._data={id:"",type:""};this._flags={};this.setData=t=>(this.data=Object.assign(this.data,t),this.triggerUpdate(),this.data);this.subscribe=t=>{this.listeners.add(t)};this.unsubscribe=t=>{this.listeners.delete(t)};this.triggerUpdate=()=>{this.listeners.forEach(t=>t(this.data))};let{type:s,id:a}=t;this.weaverse=i,a&&s&&(i.itemInstances.set(a,this),this.data={...t})}get _id(){return this._data.id}get _element(){return this.ref.current}get Element(){return this.weaverse.elementInstances.get(this._data.type)}set data(t){this._data={...this.data,...t}}get data(){let t=this.Element?.defaultCss||{},i=this._data.css||{},s=p(t,i);return{...{...this.Element?.Component?.defaultProps},...this._data,css:s}}},d=class{constructor({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:a,isDesignMode:n,ssrMode:r}={}){this.elementInstances=new Map;this.itemInstances=new Map;this.appUrl=process.env.NODE_ENV==="development"?"http://localhost:3000":"https://studio.weaverse.io";this.projectKey="";this.projectData={rootId:"",items:[],script:{css:"",js:""}};this.listeners=new Set;this.isDesignMode=!1;this.ssrMode=!1;this.mediaBreakPoints={desktop:"all",mobile:"(max-width: 767.98px)"};this.initialized=!1;this.initializeData=t=>{if(!this.initialized){let{data:i,published:s,id:a,projectKey:n,studioUrl:r}=t;this.projectKey=n||this.projectKey,this.appUrl=r||this.appUrl,this.projectData={...i,pageId:a},this.isDesignMode=!s,this.initProjectItemData(),this.isDesignMode&&(this.triggerUpdate(),this.loadStudio())}this.initialized=!0};this.initStitches=()=>{this.stitchesInstance=this.stitchesInstance||m.createStitches({prefix:"weaverse",media:this.mediaBreakPoints,utils:c}),l(this.stitchesInstance)};this.init({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:a,isDesignMode:n,ssrMode:r})}init({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:a,isDesignMode:n,ssrMode:r}={}){this.appUrl=t||this.appUrl,this.projectKey=i||this.projectKey,this.mediaBreakPoints=a||this.mediaBreakPoints,this.isDesignMode=n||this.isDesignMode,this.ssrMode=r||this.ssrMode,this.projectData=s||this.projectData,this.initStitches(),this.initProjectItemData()}loadStudio(){setTimeout(()=>{if(h&&this.isDesignMode&&!this.studioBridge){let t=()=>{this.studioBridge=new window.WeaverseStudioBridge(this),this.triggerUpdate()};if(window.WeaverseStudioBridge)t();else{let i=document.createElement("script"),s=new Date().getTime();i.src=`${this.appUrl}/assets/studio/studio-bridge.js?t=${s}`,i.type="module",i.onload=t,document.body.appendChild(i)}}},2e3)}registerElement(t){if(t?.type){if(this.elementInstances.has(t.type))throw new Error(`Weaverse: Element '${t.type}' already registered`);this.elementInstances.set(t?.type,t)}else throw new Error("Weaverse: registerElement: `type` is required")}subscribe(t){this.listeners.add(t)}unsubscribe(t){this.listeners.delete(t)}triggerUpdate(){this.listeners.forEach(t=>t())}static fetchProjectData({fetch:t=globalThis.fetch,appUrl:i,projectKey:s}){return t(i+`/api/public/project/${s}`).then(a=>a.json()).catch(a=>console.log("Error fetching project data:",a))}setProjectData(t){this.projectData=t,this.initProjectItemData(),this.triggerUpdate()}initProjectItemData(){let t=this.projectData;t?.items&&t.items.forEach(i=>{this.itemInstances.get(i.id)||new o(i,this)})}};d.WeaverseItemStore=o;export{d as Weaverse,o as WeaverseItemStore,l as createGlobalStyles,u as isBrowser,h as isIframe,g as isReactNative,p as merge,c as stichesUtils};
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.45",
2
+ "version": "0.7.48",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
package/dist/index.d.ts DELETED
@@ -1,346 +0,0 @@
1
- import * as Stitches from '@stitches/core';
2
- import { ForwardRefExoticComponent, RefObject } from 'react';
3
- import Stitches$1 from '@stitches/core/types/stitches';
4
-
5
- declare let stichesUtils: {
6
- m: (value: string) => {
7
- margin: string;
8
- };
9
- mt: (value: string) => {
10
- marginTop: string;
11
- };
12
- mr: (value: string) => {
13
- marginRight: string;
14
- };
15
- mb: (value: string) => {
16
- marginBottom: string;
17
- };
18
- ml: (value: string) => {
19
- marginLeft: string;
20
- };
21
- mx: (value: string) => {
22
- marginLeft: string;
23
- marginRight: string;
24
- };
25
- my: (value: string) => {
26
- marginTop: string;
27
- marginBottom: string;
28
- };
29
- size: (value: string) => {
30
- width: string;
31
- height: string;
32
- };
33
- px: (value: string) => {
34
- paddingLeft: string;
35
- paddingRight: string;
36
- };
37
- py: (value: string) => {
38
- paddingTop: string;
39
- paddingBottom: string;
40
- };
41
- };
42
- declare function createGlobalStyles(stitches: Stitches$1): void;
43
-
44
- declare const isReactNative: boolean;
45
- declare const isBrowser: boolean;
46
- declare const isIframe: boolean;
47
- /**
48
- * Deep merge two objects.
49
- * @param target
50
- * @param source
51
- */
52
- declare function merge(target: Record<string, any>, source: Record<string, any>): {
53
- [x: string]: any;
54
- };
55
-
56
- interface ProjectDataType {
57
- items: ElementData[];
58
- rootId: string;
59
- script: {
60
- css: string;
61
- js: string;
62
- };
63
- pageId?: string;
64
- }
65
- interface InitializeData {
66
- id: string;
67
- handle: string;
68
- data: ProjectDataType;
69
- published: boolean;
70
- projectKey?: string;
71
- studioUrl?: string;
72
- }
73
- interface BreakPoints {
74
- mobile: string;
75
- desktop: string;
76
- }
77
- interface WeaverseType {
78
- mediaBreakPoints?: BreakPoints;
79
- appUrl?: string;
80
- projectKey?: string;
81
- projectData?: ProjectDataType;
82
- isDesignMode?: boolean;
83
- ssrMode?: boolean;
84
- }
85
- interface WeaverseElement {
86
- Component: ForwardRefExoticComponent<any>;
87
- type: string;
88
- schema?: ElementSchema;
89
- defaultCss?: ElementCSS;
90
- permanentCss?: ElementCSS;
91
- }
92
- type CatalogGroup = "essential" | "composition" | "shopify";
93
- interface ElementCatalog {
94
- name: string;
95
- icon?: string;
96
- group?: CatalogGroup;
97
- data?: ElementDataInCatalog[];
98
- }
99
- interface ElementDataInCatalog extends Omit<ElementData, "id"> {
100
- id: string | number;
101
- }
102
- type FlagType = "draggable" | "resizable" | "sortable" | "ignoreShortcutKeys" | "hasContextMenu" | "isSortableContext";
103
- type ElementFlags = Partial<Record<FlagType, boolean>>;
104
- type ChildElementSelector = string | string[];
105
- interface ChildElement {
106
- label: string;
107
- selector: ChildElementSelector;
108
- }
109
- type ParentType = "container" | "layout" | "root" | "product-details" | "product-info" | "collection.box" | "collection-box" | "article-box" | "article-list" | "slider" | "tab" | "accordion" | "accordion.wrapper";
110
- type GridSize = {
111
- rowSpan: number;
112
- colSpan: number;
113
- };
114
- type ToolbarAction = "general-settings" | "edit-text" | "duplicate" | "delete" | "copy-styles" | "paste-styles" | "move-up" | "move-down" | "toggle-visibility";
115
- interface ElementSchema {
116
- title: string;
117
- type: string;
118
- parentTypes: ParentType[];
119
- gridSize?: GridSize;
120
- inspector?: ElementInspector;
121
- toolbar?: (ToolbarAction | ToolbarAction[])[];
122
- childElements?: ChildElement[];
123
- catalog?: ElementCatalog;
124
- flags?: ElementFlags;
125
- }
126
- interface ElementData {
127
- id: string;
128
- type: string;
129
- childIds?: (string | number)[];
130
- css?: ElementCSS;
131
- [key: string]: any;
132
- }
133
- type WeaverseCSSProperties = Stitches.CSS & Partial<Record<keyof typeof stichesUtils, string | number>>;
134
- type ChildElementCSS = Partial<{
135
- [selector: string]: WeaverseCSSProperties & ChildElementCSS;
136
- }>;
137
- interface ElementCSS {
138
- "@desktop"?: WeaverseCSSProperties | ChildElementCSS;
139
- "@mobile"?: WeaverseCSSProperties | ChildElementCSS;
140
- }
141
- interface ElementInspector {
142
- settings?: (AdvancedGroup | BasicGroup)[];
143
- styles?: (AdvancedGroup | BasicGroup)[];
144
- }
145
- interface AdvancedGroup {
146
- groupType: AdvancedGroupType;
147
- useData?: boolean;
148
- }
149
- interface BasicGroup {
150
- groupType: "basic";
151
- groupHeader: string;
152
- inputs: BasicInput[];
153
- }
154
- type AdvancedGroupType = "border" | "alignment" | "background" | "dimensions" | "spacing" | "typography" | "visibility" | "shadows-and-effects" | "layout-background";
155
- interface BasicInput<ConfigsType = AdditionalInputConfigs> {
156
- type: InputType;
157
- label?: string;
158
- binding?: "style" | "data";
159
- /**
160
- * The key of the value of the element data or styles
161
- * @example
162
- * // Bind to `element.data.title`
163
- * name: "title"
164
- * // Bind to `element.css["@desktop"].backgroundColor`
165
- * name: "backgroundColor"
166
- */
167
- name?: string;
168
- /**
169
- * Additional options for inputs that require more configuration
170
- */
171
- configs?: ConfigsType;
172
- /**
173
- * Only display if condition matches.
174
- *
175
- * Format: `dataBindingKey.conditionalOperator.value`
176
- *
177
- * Supported operators: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`
178
- *
179
- * @example
180
- * `clickAction.eq.openLink`
181
- * `clickAction.ne.openLink`
182
- * `imagesPerRow.gt.1`
183
- */
184
- condition?: string;
185
- defaultValue?: string | number | boolean;
186
- placeholder?: string;
187
- helpText?: string;
188
- }
189
- type AdditionalInputConfigs = SelectInputConfigs | ToggleGroupConfigs | RangeInputConfigs | SortableInputConfigs;
190
- interface SelectInputConfigs {
191
- options?: {
192
- value: string;
193
- label: string;
194
- icon?: string;
195
- weight?: string;
196
- }[];
197
- }
198
- interface ToggleGroupConfigs {
199
- options?: {
200
- value: string;
201
- label: string;
202
- icon?: string;
203
- weight?: string;
204
- }[];
205
- }
206
- interface RangeInputConfigs {
207
- min?: number;
208
- max?: number;
209
- step?: number;
210
- }
211
- type SortableItemAction = "add" | "edit" | "duplicate" | "delete" | "toggle-visibility";
212
- interface SortableInputConfigs {
213
- actions: SortableItemAction[];
214
- }
215
- type InputType = "color" | "datepicker" | "image" | "range" | "select" | "sortable" | "switch" | "text" | "textarea" | "toggle-group" | "form" | "product" | "product-list" | "product-swatches" | "text-editor" | "custom.html" | "instagram" | "collection-list" | "collection" | "article-list" | "map-autocomplete";
216
- declare global {
217
- interface Window {
218
- WeaverseStudioBridge: any;
219
- Blinkloader: any;
220
- }
221
- }
222
-
223
- /**
224
- * WeaverseItemStore is a store for Weaverse item, it can be used to subscribe/update the item data
225
- * @param itemData {ElementData} Weaverse item data
226
- * @param weaverse {Weaverse} Weaverse instance
227
- * @example
228
- * useEffect(() => {
229
- * let handleUpdate = (update: any) => {
230
- * setData({...update})
231
- * }
232
- * itemInstance.subscribe(handleUpdate)
233
- * return () => {
234
- * itemInstance.unsubscribe(handleUpdate)
235
- * }
236
- * }, [])
237
- */
238
- declare class WeaverseItemStore {
239
- listeners: Set<any>;
240
- ref: RefObject<HTMLElement>;
241
- weaverse: Weaverse;
242
- stitchesClass: string;
243
- _data: ElementData;
244
- _flags: ElementFlags;
245
- constructor(itemData: ElementData, weaverse: Weaverse);
246
- get _id(): string;
247
- get _element(): HTMLElement | null;
248
- get Element(): WeaverseElement | undefined;
249
- set data(data: Omit<ElementData, "id" | "type">);
250
- get data(): ElementData;
251
- setData: (data: Omit<ElementData, "id" | "type">) => ElementData;
252
- subscribe: (fn: any) => void;
253
- unsubscribe: (fn: any) => void;
254
- triggerUpdate: () => void;
255
- }
256
- declare class Weaverse {
257
- /**
258
- * The `weaverse-content-root` element of Weaverse SDK
259
- */
260
- contentRootElement: HTMLElement | undefined;
261
- /**
262
- * For storing, registering element React component from Weaverse or created by user/developer
263
- */
264
- elementInstances: Map<string, WeaverseElement>;
265
- /**
266
- * list of element/items store to provide data, handle state update, state sharing, etc.
267
- */
268
- itemInstances: Map<string | number, WeaverseItemStore>;
269
- /**
270
- * Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
271
- * @type {string}
272
- */
273
- appUrl: string;
274
- /**
275
- * Weaverse project key to access project data via API
276
- * @type {string}
277
- */
278
- projectKey: string;
279
- /**
280
- * Weaverse project data, by default, user can provide project data via React Component:
281
- * <WeaverseRoot defaultData={projectData} /> it will be used to server-side rendering
282
- */
283
- projectData: ProjectDataType;
284
- /**
285
- * storing subscribe callback function for any component that want to listen to the change of WeaverseRoot
286
- * @type {Map<string, (data: any) => void>}
287
- */
288
- listeners: Set<any>;
289
- /**
290
- * check whether the sdk is isDesignMode or not
291
- * if isDesignMode is true, it means the sdk is isDesignMode mode, render the editor UI
292
- * else render the preview UI, plain HTML + CSS + React hydrate
293
- * @type {boolean}
294
- */
295
- isDesignMode: boolean;
296
- /**
297
- * Use in element to optionally render special HTML for hydration
298
- * @type {boolean}
299
- */
300
- ssrMode: boolean;
301
- /**
302
- * stitches instance for handling CSS stylesheet, media, theme for Weaverse project
303
- */
304
- stitchesInstance: Stitches$1 | any;
305
- studioBridge?: any;
306
- static WeaverseItemStore: typeof WeaverseItemStore;
307
- mediaBreakPoints: BreakPoints;
308
- /**
309
- * constructor
310
- * @param appUrl {string} Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
311
- * @param projectKey {string} Weaverse project key to access project data via API
312
- * @param projectData {ProjectDataType} Weaverse project data, by default, user can provide project data via React Component.
313
- * @param mediaBreakPoints {object} Pass down custom media query breakpoints or just use the default.
314
- * @param isDesignMode {boolean} check whether the sdk is isDesignMode or not
315
- * @param ssrMode {boolean} Use in element to optionally render special HTML for hydration
316
- */
317
- constructor({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode }?: WeaverseType);
318
- init({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode }?: WeaverseType): void;
319
- initialized: boolean;
320
- initializeData: (data: InitializeData) => void;
321
- loadStudio(): void;
322
- /**
323
- * register the custom React Component to Weaverse, store it into Weaverse.elementInstances
324
- * @param element {WeaverseElement} custom React Component
325
- */
326
- registerElement(element: WeaverseElement): void;
327
- initStitches: () => void;
328
- subscribe(fn: any): void;
329
- unsubscribe(fn: any): void;
330
- triggerUpdate(): void;
331
- /**
332
- * fetch data from Weaverse API (https://weaverse.io/api/v1/project/:projectKey)
333
- * @param fetch {fetch} custom fetch function, pass in custom fetch function if you want to use your own fetch function
334
- * @param appUrl
335
- * @param projectKey
336
- */
337
- static fetchProjectData({ fetch, appUrl, projectKey, }: {
338
- fetch?: any;
339
- appUrl?: string;
340
- projectKey?: string;
341
- }): any;
342
- setProjectData(projectData: ProjectDataType): void;
343
- initProjectItemData(): void;
344
- }
345
-
346
- export { AdditionalInputConfigs, AdvancedGroup, AdvancedGroupType, BasicGroup, BasicInput, BreakPoints, CatalogGroup, ChildElement, ChildElementCSS, ChildElementSelector, ElementCSS, ElementCatalog, ElementData, ElementDataInCatalog, ElementFlags, ElementInspector, ElementSchema, FlagType, GridSize, InitializeData, InputType, ParentType, ProjectDataType, RangeInputConfigs, SelectInputConfigs, SortableInputConfigs, SortableItemAction, ToggleGroupConfigs, ToolbarAction, Weaverse, WeaverseCSSProperties, WeaverseElement, WeaverseItemStore, WeaverseType, createGlobalStyles, isBrowser, isIframe, isReactNative, merge, stichesUtils };