@lightspeed/crane-api 2.0.0 → 2.1.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/CHANGELOG.md +11 -0
- package/dist/index.d.mts +280 -26
- package/dist/index.d.ts +281 -26
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/types.d.ts +17 -11
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createSSRApp as Oe,getCurrentInstance as Te,ref as _,computed as a,reactive as O}from"vue";import{renderToString as ge}from"vue/server-renderer";import{z as p}from"zod";function M(e){return{app:Oe(e)}}const w=new Map;function E(){const e=(r,i,u,d,v,c,s,l)=>{w.set(r._uid,{context:_(i),content:_(u),design:_(d),defaults:_(v),site:_(c?.site??{}),category:_(c?.category),storeData:_(c?.storeData),globalDesign:_(s),tileId:_(l??void 0)})},t=(r,i,u,d,v,c,s)=>{const l=w.get(r._uid);l!==void 0&&(l.content.value=i,l.design.value=u,l.defaults.value=d,l.site.value=v.site??{},l.category.value=v.category,l.globalDesign.value=c,l.storeData.value=v.storeData,l.tileId.value=s)},n=Te()?.appContext.app._uid??-1,o=w.get(n);return{init:e,update:t,context:o?.context,content:o?.content,design:o?.design,defaults:o?.defaults,site:o?.site,category:o?.category,storeData:o?.storeData,globalDesign:o?.globalDesign,tileId:o?.tileId}}function fe(e,t){return{init:()=>{const{app:n}=M(e);return t?.init?.(n),{mount:(o,r)=>{E().init(n,r.context,r.data.content,r.data.design,r.data.defaults,r.data.externalContent,r.context.globalDesign,r.data.tileId),t?.mount?.(n,o,r),n.mount(o)},update:o=>{E().update(n,o.data.content,o.data.design,o.data.defaults,o.data.externalContent,o.context.globalDesign,o.data.tileId),t?.update?.(n,o)},unmount:()=>{t?.unmount?.(n),n.unmount()}}}}}function pe(){return globalThis.window.instantsite}function me(e,t){return{init:()=>{const{app:n}=M(e);return t?.init?.(n),{render:async(o,r)=>(E().init(n,o,r.content,r.design,r.defaults,r.externalContent,o.globalDesign,r.tileId),t?.render?.(n,o,r),{html:await ge(n,{context:o}),state:{context:o,data:r}})}}}}const U={SCROLL_TO_TILE:"SCROLL_TO_TILE",HYPER_LINK:"HYPER_LINK",MAIL_LINK:"MAIL_LINK",TEL_LINK:"TEL_LINK",GO_TO_STORE:"GO_TO_STORE",GO_TO_STORE_LINK:"GO_TO_STORE_LINK",GO_TO_PAGE:"GO_TO_PAGE",GO_TO_CATEGORY:"GO_TO_CATEGORY",GO_TO_CATEGORY_LINK:"GO_TO_CATEGORY_LINK"};p.enum(Object.values(U));const Ie=U,x={COLOR:"COLOR",GRADIENT:"GRADIENT",NONE:"NONE"};p.enum(Object.values(x));const Le=x,P={SOLID:"SOLID",OUTLINE:"OUTLINE",TEXT:"TEXT"};p.enum(Object.values(P));const _e=P,k={SMALL:"SMALL",MEDIUM:"MEDIUM",LARGE:"LARGE"};p.enum(Object.values(k));const Ce=k,K={ROUND_CORNER:"ROUND_CORNER",RECTANGLE:"RECTANGLE",PILL:"PILL"};p.enum(Object.values(K));const Re=K,$={COLOR:"COLOR",GRADIENT:"GRADIENT"};p.enum(Object.values($));const be=$,X={SECTION:"SECTION",HEADER:"HEADER",FOOTER:"FOOTER"};p.enum(Object.values(X));const ye=X;var z=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.Misc=2]="Misc",e[e.Layout=3]="Layout",e[e.Asset=4]="Asset",e[e.SharedFiles=5]="SharedFiles",e))(z||{}),Y=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.SectionSetting=2]="SectionSetting",e[e.SectionShowcase=3]="SectionShowcase",e[e.SectionAsset=4]="SectionAsset",e[e.TemplateDescriptor=5]="TemplateDescriptor",e[e.PageTemplateDescriptor=6]="PageTemplateDescriptor",e[e.TemplateAsset=7]="TemplateAsset",e[e.Layout=8]="Layout",e[e.LayoutSettings=9]="LayoutSettings",e[e.LayoutAsset=10]="LayoutAsset",e[e.SlotServer=11]="SlotServer",e[e.SlotClient=12]="SlotClient",e[e.SharedTranslation=13]="SharedTranslation",e[e.CollectionDescriptor=14]="CollectionDescriptor",e[e.CollectionAsset=15]="CollectionAsset",e))(Y||{}),F=(e=>(e.SCROLL_TO_TILE="SCROLL_TO_TILE",e.HYPER_LINK="HYPER_LINK",e.MAIL_LINK="MAIL_LINK",e.TEL_LINK="TEL_LINK",e.GO_TO_STORE="GO_TO_STORE",e.GO_TO_STORE_LINK="GO_TO_STORE_LINK",e.GO_TO_PAGE="GO_TO_PAGE",e))(F||{});const I={TEXTAREA:"TEXTAREA",INPUTBOX:"INPUTBOX",SELECTBOX:"SELECTBOX",IMAGE:"IMAGE",TOGGLE:"TOGGLE",BUTTON:"BUTTON",DECK:"DECK",MENU:"MENU",NAVIGATION_MENU:"NAVIGATION_MENU",LOGO:"LOGO",INFO:"INFO",DIVIDER:"DIVIDER",PRODUCT_SELECTOR:"PRODUCT_SELECTOR",CATEGORY_SELECTOR:"CATEGORY_SELECTOR"};p.enum(Object.values(I));const V={TEXT:"TEXT",BUTTON:"BUTTON",IMAGE:"IMAGE",TOGGLE:"TOGGLE",SELECTBOX:"SELECTBOX",BACKGROUND:"BACKGROUND",COLOR_PICKER:"COLOR_PICKER",LOGO:"LOGO",DIVIDER:"DIVIDER"};p.enum(Object.values(V));const Se=V,j={CONTENT:"Content",DESIGN:"Design"};p.enum(Object.values(j));const Ae=j,W={TEXT:"TEXT",IMAGE:"IMAGE"};p.enum(Object.values(W));const Ge=W;var H=(e=>(e.ORIGINAL="original",e.WEBP_LOW_RES="webp-200x200",e.WEBP_HI_2X_RES="webp-2000x2000",e.MOBILE_WEBP_LOW_RES="cropped-webp-100x200",e.MOBILE_WEBP_HI_RES="cropped-webp-1000x2000",e))(H||{}),J=(e=>(e.TILE_LOADED="tile-loaded",e.TILE_UNLOADED="tile-unloaded",e))(J||{});const Ne={PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},De={CATEGORY_TITLE:"MAIN_TITLE",PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},he={TOP_BAR:"TOP_BAR",GALLERY:"GALLERY",SIDEBAR:"SIDEBAR",DESCRIPTION:"DESCRIPTION",REVIEW_LIST:"REVIEW_LIST",RELATED_PRODUCTS:"RELATED_PRODUCTS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},q={apparel_footwear:"apparel_footwear",vape_smoke:"vape_smoke",home_garden:"home_garden",sport_outdoor:"sport_outdoor",jewelry_accessories:"jewelry_accessories",pet_animals:"pet_animals",bikes:"bikes",health_beauty:"health_beauty",gift_shop:"gift_shop",electronics:"electronics",other:"other"};p.enum(Object.values(q));const we=q;function Q(e){if(!e||e.length===0)return[];const t=[];function n(o){if(t.push({id:o.id,name:o.name,url:o.urlPath}),o.children&&o.children.length>0)for(const r of o.children)n(r)}for(const o of e)n(o);return t}const C={HYPER_LINK:"HYPER_LINK",SCROLL_TO_TILE:"SCROLL_TO_TILE",MAIL_LINK:"MAIL_LINK",TEL_LINK:"TEL_LINK",GO_TO_STORE:"GO_TO_STORE",GO_TO_STORE_LINK:"GO_TO_STORE_LINK",GO_TO_PAGE:"GO_TO_PAGE",GO_TO_CATEGORY:"GO_TO_CATEGORY",GO_TO_CATEGORY_LINK:"GO_TO_CATEGORY_LINK"};function Be(e){if("tileId"in e)return e.tileId;if("tileIdForScroll"in e)return e.tileIdForScroll}function Me(e){if("pageId"in e)return e.pageId;if("pageIdForNavigate"in e)return e.pageIdForNavigate}function Ue(e,t){if("pageUrl"in e)return e.pageUrl;const n=Me(e);switch(n){case"products":return"/products";case"cart":return"/cart";case"account":return"/account";case"search":return"/search";case"home":return"/"}if(t){const o=t.find(r=>r.pageId===n);if(o)return o.url}return"/"}function xe(e){if("categoryId"in e)return e.categoryId}const Z=(e,t,n)=>{if(!e||t)return;const{type:o,link:r,email:i,phone:u}=e,d=E().site?.value?.pages,v=Ue(e,d),c=xe(e);switch(o){case C.HYPER_LINK:if(r){const l=e.linkTarget??"_blank";return()=>window.open(r,l)}break;case C.GO_TO_STORE:case C.GO_TO_STORE_LINK:return()=>window.open("/products","_self");case C.GO_TO_CATEGORY:case C.GO_TO_CATEGORY_LINK:const s=n?.find(l=>l.id===c)?.url;return s===void 0?()=>window.open("/404","_self"):()=>window.open(s,"_self");case C.MAIL_LINK:if(i)return()=>window.open(`mailto:${i}`,"_self");break;case C.TEL_LINK:if(u)return()=>window.open(`tel:${u}`,"_self");break;case C.SCROLL_TO_TILE:if(typeof document<"u")return()=>{const l=Be(e);document.getElementById(`tile-${l}`)?.scrollIntoView()};break;case C.GO_TO_PAGE:if(v)return()=>window.open(v,"_self");break;default:console.error(`Unknown type of ActionLink: ${o}`)}};function Pe(e){return"title"in e&&"type"in e}function ke(e,t,n,o){const r=a(()=>{const L=e.value[t];if(L!==void 0){if(Pe(L))return L;throw new Error(`Element ${t} is not action link`)}}),i=a(()=>r.value?.title),u=a(()=>r.value?.type),d=a(()=>r.value?.link),v=a(()=>r.value?.email),c=a(()=>r.value?.phone),s=a(()=>r.value?.tileId?`tile-${r.value?.tileId}`:null),l=a(()=>r.value?.type==="GO_TO_STORE_LINK"?"products":r.value?.pageId),T=a(()=>r.value?.pageUrl),G=a(()=>!!i.value),S=a(()=>!!d.value),A=Z(r.value,n,o);return O({title:i,type:u,link:d,email:v,phone:c,tileDivId:s,pageId:l,pageUrl:T,hasTitle:G,hasLink:S,performAction:A})}function ee(e,t){const n=E(),o=a(()=>!!n.site?.value?.isPreviewMode),r=a(()=>{const u=n.category?.value?.categoryTree;return Q(u)}),i=a(()=>t!==void 0?t:n.content.value!==void 0?n.content.value:{});return ke(i,e,o.value,r.value)}function te({content:e,elementName:t,errorMessage:n,validatorFn:o}){return a(()=>{const r=e.value?.[t];if(r!==void 0){if(o(r))return r;throw new Error(n)}})}function Ke(e){return typeof e=="object"&&e!==null&&"categories"in e}function $e(e){return a(()=>e.value.reduce((t,n)=>(t[n.id]=n,t),{}))}function Xe(e){return e!==void 0}function ze(e){return!!e?.trim()}function Ye({name:e,customName:t,selectionType:n}){return n==="ROOT"?e:ze(t)?t:e}function Fe(e,t){return Xe(e)&&t}function ne({itemId:e,id:t,alt:n,name:o,nameTranslated:r,customName:i,enabled:u,productsCount:d,url:v,imageUrl:c,thumbnailImageUrl:s,imageBorderInfo:l,selectionType:T}){return{itemId:e||t.toString(),id:t,alt:n,name:Ye({name:o,customName:i,selectionType:T}),nameTranslated:r,label:o,enabled:u,url:v,productsCount:d,imageUrl:c,thumbnailImageUrl:s,imageBorderInfo:l,showCategory:Fe(t,u)}}function oe(e,t,n){const o=E(),r=a(()=>t!==void 0?t:o.content.value),i=te({content:r,elementName:e,errorMessage:`Element ${e} is not a category selector type`,validatorFn:Ke}),u=a(()=>n??o.storeData?.value),d=a(()=>i.value?.categories.selectionType??"ROOT"),v=a(()=>u.value?.categories??[]),c=a(()=>i.value?.categories?.categoryIds??[]),s=a(()=>{const G=$e(v);return d.value==="MANUAL"?i.value?.categories?.items?.map(S=>{const A=G.value[S.id];return ne({...S,...A,selectionType:d.value})})??[]:u?.value?.categories.map(S=>ne({...S,selectionType:d.value}))??[]}),l=a(()=>i.value!==void 0),T=a(()=>s.value!==void 0&&s.value.length>0);return O({categories:s,categoryIds:c,hasContent:l,hasCategories:T})}function Ve(e){return typeof e=="object"&&e!==null&&("products"in e||"product"in e)}function ae(e,t,n){const o=E(),r=a(()=>t!==void 0?t:o.content.value),i=te({content:r,elementName:e,errorMessage:`Element ${e} is not a product selector type`,validatorFn:Ve}),u=a(()=>n??o.storeData?.value),d=a(()=>i.value?.products?.selectionType??"MANUAL"),v=a(()=>i.value?.products?.productIds??[]),c=a(()=>i.value?.product?.id),s=a(()=>typeof i.value?.categoryId=="number"?i.value.categoryId:void 0),l=a(()=>{if(d.value==="CATEGORY")return s.value===0?u?.value?.products.filter(L=>L?.defaultCategoryId===0)??[]:u?.value?.products.filter(L=>s.value&&L?.categoryIds?.includes(s.value))??[];const A=c.value?[c.value]:v.value??[];return u?.value?.products?.filter(L=>A.includes(L.id))??[]}),T=a(()=>u?.value?.categories.filter(A=>A.id===s?.value)??[]),G=a(()=>i.value!==void 0&&l.value.length>0),S=a(()=>l.value!==void 0&&l.value.length>0);return O({products:l,categories:T,categoryId:s,hasContent:G,hasProducts:S})}function je(e){return"bucket"in e&&"borderInfo"in e&&"set"in e}function N(e,t){const n=new RegExp(/^https?:\/\//);return e!=null&&n.test(e)?e:`${t}/${e}`}function We(e,t){const n=a(()=>{const c=e.value[t];if(c!==void 0){if(je(c))return c;throw new Error(`Element ${t} is not image`)}}),o=a(()=>n.value===void 0?"":E().context.value.imageBuckets?.[n.value?.bucket]),r=a(()=>n.value!==void 0),i=a(()=>N(n.value?.set?.["cropped-webp-100x200"]?.url,o.value)),u=a(()=>N(n.value?.set?.["cropped-webp-1000x2000"]?.url,o.value)),d=a(()=>N(n.value?.set?.["webp-200x200"]?.url,o.value)),v=a(()=>N(n.value?.set?.["webp-2000x2000"]?.url,o.value));return O({hasContent:r,lowResolutionMobileImage:i,highResolutionMobileImage:u,lowResolutionDesktopImage:d,highResolutionDesktopImage:v})}function re(e,t){const n=E(),o=a(()=>t!==void 0?t:n.content.value);return We(o,e)}function He(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not inputbox`)}}),o=a(()=>n.value!==void 0&&n.value.length>0),r=a(()=>n.value);return O({hasContent:o,value:r})}function ie(e,t){const n=E(),o=a(()=>t!==void 0?t:n.content.value);return He(o,e)}function Je(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not selectbox`)}}),o=a(()=>n.value!==void 0),r=a(()=>n.value);return O({hasContent:o,value:r})}function le(e,t){const n=E(),o=a(()=>t!==void 0?t:n.content.value);return Je(o,e)}function qe(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not textarea`)}}),o=a(()=>n.value!==void 0),r=a(()=>n.value);return O({hasContent:o,value:r})}function ue(e,t){const n=E(),o=a(()=>t!==void 0?t:n.content.value);return qe(o,e)}function Qe(e){return"enabled"in e}function Ze(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(Qe(i))return i;throw new Error(`Element ${t} is not toggle`)}}),o=a(()=>n.value!==void 0),r=a(()=>n.value?.enabled);return O({hasContent:o,value:r})}function se(e,t){const n=E(),o=a(()=>t!==void 0?t:n.content.value);return Ze(o,e)}function et(e){if(typeof e!="object"||e===null)return!1;const t=e;return Array.isArray(t.cards)&&t.cards.every(n=>typeof n.settings=="object"&&n.settings!==null)}function tt(e,t,n,o){if(e==null)throw Error("Could not get a reactive ref for undefined Card");const r=e.settings[n];if(r===void 0)return r;switch(t){case I.TEXTAREA:return ue(n,e.settings);case I.INPUTBOX:return ie(n,e.settings);case I.SELECTBOX:return le(n,e.settings);case I.IMAGE:return re(n,e.settings);case I.TOGGLE:return se(n,e.settings);case I.BUTTON:return ee(n,e.settings);case I.CATEGORY_SELECTOR:return oe(n,e.settings,o);case I.PRODUCT_SELECTOR:return ae(n,e.settings,o);default:return}}function nt(e){const t=E(),n=a(()=>t.storeData?.value),o=a(()=>{const u=t.content.value[e];if(u!==void 0){if(et(u))return u;throw new Error(`Element ${e} is not of DECK type`)}}),r=a(()=>o.value!==void 0&&o.value.cards.length>0),i=a(()=>o.value?.cards);return O({hasContent:r,cards:i,getReactiveRef:(u,d,v)=>tt(u,d,v,n.value)})}function ot(e){return"type"in e&&("text"in e||"image"in e)}function D(e,t){const n=new RegExp(/^https?:\/\//);return e!==void 0&&n.test(e)?e:`${t}/${e}`}function at(){const e=E(),t=a(()=>{const u=e.content.value.logo;if(u!==void 0){if(ot(u))return u;throw new Error("Element logo is not LOGO")}}),n=a(()=>t.value?.type),o=a(()=>t.value?.text),r=a(()=>t.value?.image===void 0?"":e.context.value.imageBuckets?.[t.value.image.bucket]),i=a(()=>({lowResolutionMobileImage:D(t.value?.image?.set?.["cropped-webp-100x200"]?.url,r.value),highResolutionMobileImage:D(t.value?.image?.set?.["cropped-webp-1000x2000"]?.url,r.value),lowResolutionDesktopImage:D(t.value?.image?.set?.["webp-200x200"]?.url,r.value),highResolutionDesktopImage:D(t.value?.image?.set?.["webp-2000x2000"]?.url,r.value)}));return O({type:n,text:o,image:i})}function rt(e){return e!==null&&"items"in e}function ce(e){const t=E(),n=a(()=>{const l=t.content.value[e];if(l!==void 0){if(rt(l))return l;throw new Error(`Element ${e} is not an menu`)}}),o=a(()=>!!t.site?.value?.isPreviewMode),r=a(()=>{const l=t.category?.value?.categoryTree;return Q(l)}),i=a(()=>n.value!==void 0);function u(l){if(l)try{return new URL(l).pathname}catch{return l}}function d(l){return l?.map(T=>({...T,url:u(T.url)??T.url}))}const v=a(()=>d(r.value));function c(l){const T=Z(l,o.value,v.value);return{...l,performAction:T,nestedItems:l.nestedItems?.map(c)}}const s=a(()=>n.value?.items?n.value.items.map(c):[]);return O({hasContent:i,items:s})}const it="menu";function lt(){return ce(it)}function ut(){return globalThis.craneSharedTranslation??{}}function st(){const e=E(),t=a(()=>e.site?.value),n=a(()=>ut()),o=a(()=>{const r=t.value?.languages;return r?r.find(i=>i.selected)?.code??r.find(i=>i.main)?.code??"en":"en"});return{t:r=>{const i=n.value;if(!i||Object.keys(i).length===0)return r;const u=o.value,d=i[u]?.[r];if(d!==void 0)return d;if(u!=="en"){const v=i.en?.[r];if(v!==void 0)return v}return r},currentLanguageCode:o}}function de(e,t){if(t===void 0)return;if(!t.startsWith("global."))return t.replaceAll("_"," ");const n=t.split(".").at(2);if(n!==void 0)return e.fontFamily?e.fontFamily[n].replaceAll("_"," "):void 0}function h(e,t,n){return t?de(e,t):de(e,n)}function ve(e,t){if(t===void 0)return;if(typeof t!="string"||!t.startsWith("global."))return t;const n=t.split(".").at(2);if(n!==void 0)return e.textSize?e.textSize[n]:void 0}function B(e,t,n){return t?ve(e,t):ve(e,n)}function Ee(e,t){if(t===void 0)return;if(typeof t!="string"||!t.startsWith("global."))return t;const n=t.split(".").at(2);if(n!==void 0)return e.color?e.color[n]:void 0}function m(e,t,n){return t?Ee(e,t):Ee(e,n)}function ct(e,t,n){return{visible:t?.visible??n?.visible??!1,width:t?.width??n?.width??1,color:m(e,t?.color,n?.color)}}function dt(e){const t=E(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e],u=t.globalDesign.value;return{background:{type:r?.background?.type??i?.background?.type,solid:{color:m(u,r?.background?.solid?.color,i?.background?.solid?.color)},gradient:{fromColor:m(u,r?.background?.gradient?.fromColor,i?.background?.gradient?.fromColor),toColor:m(u,r?.background?.gradient?.toColor,i?.background?.gradient?.toColor)}}}}),o=a(()=>n.value?.background);return O({background:o})}function vt(e){const t=E(),n=a(()=>{const c=t.design.value[e],s=t.defaults.value[e],l=t.globalDesign.value;return{appearance:c?.appearance??s?.appearance,font:h(l,c?.font,s?.font),size:c?.size??s?.size,style:c?.style??s?.style,color:m(l,c?.color,s?.color),visible:c?.visible??s?.visible??!1}}),o=a(()=>n.value?.appearance),r=a(()=>n.value?.font),i=a(()=>n.value?.size),u=a(()=>n.value?.style),d=a(()=>n.value?.color),v=a(()=>n.value?.visible);return O({appearance:o,font:r,size:i,style:u,color:d,visible:v})}function Et(e){const t=E(),n=a(()=>{const i=t.design.value[e],u=t.defaults.value[e],d=t.globalDesign.value;return{overlay:{type:i?.overlay?.type??u?.overlay?.type,solid:{color:m(d,i?.overlay?.solid?.color,u?.overlay?.solid?.color)},gradient:{fromColor:m(d,i?.overlay?.gradient?.fromColor,u?.overlay?.gradient?.fromColor),toColor:m(d,i?.overlay?.gradient?.toColor,u?.overlay?.gradient?.toColor)}},visible:i?.visible??u?.visible??!1}}),o=a(()=>n.value?.overlay),r=a(()=>n.value?.visible);return O({overlay:o,visible:r})}function Ot(){const e=E(),t=a(()=>e.design.value.layout),n=a(()=>t.value);return O({layout:n})}function Tt(){const e=E();return a(()=>{const t=e.design.value.logo,n=e.defaults.value.logo,o=e.globalDesign.value;return{font:h(o,t?.font,n?.font),size:B(o,t?.size,n?.size),bold:t?.bold??n?.bold,italic:t?.italic??n?.italic,color:m(o,t?.color,n?.color),visible:t?.visible??n?.visible??!1,spacing:t?.spacing??n?.spacing??0,capitalization:t?.capitalization??n?.capitalization??"none",frame:ct(o,t?.frame,n?.frame)}})}function gt(e){const t=E(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e];return{value:r?.value??i?.value}}),o=a(()=>n.value?.value);return O({value:o})}function ft(e){const t=E(),n=a(()=>{const c=t.design.value[e],s=t.defaults.value[e],l=t.globalDesign.value;return{font:h(l,c?.font,s?.font),size:B(l,c?.size,s?.size),bold:c?.bold??s?.bold,italic:c?.italic??s?.italic,color:m(l,c?.color,s?.color),visible:c?.visible??s?.visible??!1}}),o=a(()=>n.value?.font),r=a(()=>n.value?.size),i=a(()=>n.value?.bold),u=a(()=>n.value?.italic),d=a(()=>n.value?.color),v=a(()=>n.value?.visible);return O({font:o,size:r,bold:i,italic:u,color:d,visible:v})}function pt(e){const t=E(),n=a(()=>{const s=t.design.value[e],l=t.defaults.value[e],T=t.globalDesign.value;return{font:h(T,s?.font,l?.font),size:B(T,s?.size,l?.size),bold:s?.bold??l?.bold,italic:s?.italic??l?.italic,color:m(T,s?.color,l?.color),visible:s?.visible??l?.visible??!1,whiteSpace:"pre-wrap"}}),o=a(()=>n.value?.font),r=a(()=>n.value?.size),i=a(()=>n.value?.bold),u=a(()=>n.value?.italic),d=a(()=>n.value?.color),v=a(()=>n.value?.visible),c=a(()=>n.value?.whiteSpace);return O({font:o,size:r,bold:i,italic:u,color:d,visible:v,whiteSpace:c})}function mt(e){const t=E(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e];return{enabled:r?.enabled??i?.enabled}}),o=a(()=>n.value?.enabled);return O({enabled:o})}function g(e){return t=>"type"in t?t:{type:e,...t}}function f(e){return t=>{const{type:n,defaults:o,...r}=t,i=o?g(e)(o):void 0;return{type:e,...r,...i!==void 0?{defaults:i}:{}}}}const It={inputbox:f("INPUTBOX"),textarea:f("TEXTAREA"),button:f("BUTTON"),image:f("IMAGE"),toggle:f("TOGGLE"),selectbox:f("SELECTBOX"),deck:f("DECK"),menu:f("MENU"),navigationMenu:f("NAVIGATION_MENU"),logo:f("LOGO"),productSelector:f("PRODUCT_SELECTOR"),categorySelector:f("CATEGORY_SELECTOR"),divider:f("DIVIDER"),info:f("INFO"),default:{inputbox:g("INPUTBOX"),textarea:g("TEXTAREA"),button:g("BUTTON"),selectbox:g("SELECTBOX"),image:g("IMAGE"),toggle:g("TOGGLE"),divider:g("DIVIDER"),info:g("INFO"),deck:g("DECK"),logo:g("LOGO"),menu:g("MENU"),navigationMenu:g("NAVIGATION_MENU"),productSelector:g("PRODUCT_SELECTOR"),categorySelector:g("CATEGORY_SELECTOR")}};function R(e){return t=>"type"in t?t:{type:e,...t}}function b(e){return t=>{const{type:n,defaults:o,...r}=t,i=o?R(e)(o):void 0;return{type:e,...r,...i!==void 0?{defaults:i}:{}}}}const Lt={text:b("TEXT"),button:b("BUTTON"),image:b("IMAGE"),toggle:b("TOGGLE"),selectbox:b("SELECTBOX"),background:b("BACKGROUND"),colorPicker:b("COLOR_PICKER"),logo:b("LOGO"),divider:b("DIVIDER"),default:{text:R("TEXT"),button:R("BUTTON"),image:R("IMAGE"),toggle:R("TOGGLE"),selectbox:R("SELECTBOX"),background:R("BACKGROUND"),colorPicker:R("COLOR_PICKER"),logo:R("LOGO")}};function y(e){return t=>{const{type:n,defaults:o,...r}=t,i=o,u=i&&!("type"in i)?{...i,type:e}:o;return{type:e,...r,...u!==void 0?{defaults:u}:{}}}}const _t={init:e=>({...e}),designOverride:{text:y("TEXT"),button:y("BUTTON"),image:y("IMAGE"),toggle:y("TOGGLE"),selectbox:y("SELECTBOX"),background:y("BACKGROUND"),colorPicker:y("COLOR_PICKER"),logo:y("LOGO"),divider:y("DIVIDER")}},Ct={init:e=>e},Rt={configuration:e=>({...e}),page:e=>({...e})},bt={default:e=>{const{type:t,...n}=e;return{type:"default",...n}},custom:e=>{const{type:t,...n}=e;return{type:"custom",...n}},store:(e={})=>{const{type:t,...n}=e;return{type:"store",...n}}},yt={init:e=>({...e})};export{F as ActionLinkTypeEnum,be as BackgroundStyleEnum,_e as ButtonAppearanceEnum,Re as ButtonShapeEnum,Ce as ButtonSizeEnum,Ie as ButtonTypeEnum,Ne as CatalogLayoutSlot,De as CategoryLayoutSlot,Y as ConfigTypeEnum,Se as DesignEditorType,I as EditorTypes,H as ImageSet,J as InstantsiteJsEvent,Ge as LogoTypeEnum,Le as OverlayTypeEnum,z as PluginTypeEnum,he as ProductLayoutSlot,ye as SectionTypeEnum,we as TemplateCategoriesList,Ae as ValidationTypeEnum,It as content,fe as createVueClientApp,me as createVueServerApp,Lt as design,_t as layout,bt as section,Ct as showcase,Rt as template,yt as translation,dt as useBackgroundElementDesign,ee as useButtonElementContent,vt as useButtonElementDesign,oe as useCategorySelectorElementContent,nt as useDeckElementContent,re as useImageElementContent,Et as useImageElementDesign,ie as useInputboxElementContent,pe as useInstantsiteJsApi,Ot as useLayoutElementDesign,at as useLogoElementContent,Tt as useLogoElementDesign,ce as useMenuElementContent,lt as useNavigationMenuElementContent,ae as useProductSelectorElementContent,le as useSelectboxElementContent,gt as useSelectboxElementDesign,ft as useTextElementDesign,ue as useTextareaElementContent,pt as useTextareaElementDesign,se as useToggleElementContent,mt as useToggleElementDesign,st as useTranslation,E as useVueBaseProps};
|
|
1
|
+
import{createSSRApp as Oe,getCurrentInstance as ge,ref as y,computed as a,reactive as g}from"vue";import{renderToString as Te}from"vue/server-renderer";import{z as m}from"zod";function M(e){return{app:Oe(e)}}const w=new Map;function E(){const e=(r,i,l,d,v,c,s,u)=>{w.set(r._uid,{context:y(i),content:y(l),design:y(d),defaults:y(v),site:y(c?.site??{}),category:y(c?.category),storeData:y(c?.storeData),globalDesign:y(s),tileId:y(u??void 0)})},t=(r,i,l,d,v,c,s)=>{const u=w.get(r._uid);u!==void 0&&(u.content.value=i,u.design.value=l,u.defaults.value=d,u.site.value=v.site??{},u.category.value=v.category,u.globalDesign.value=c,u.storeData.value=v.storeData,u.tileId.value=s)},n=ge()?.appContext.app._uid??-1,o=w.get(n);return{init:e,update:t,context:o?.context,content:o?.content,design:o?.design,defaults:o?.defaults,site:o?.site,category:o?.category,storeData:o?.storeData,globalDesign:o?.globalDesign,tileId:o?.tileId}}function fe(e,t){return{init:()=>{const{app:n}=M(e);return t?.init?.(n),{mount:(o,r)=>{E().init(n,r.context,r.data.content,r.data.design,r.data.defaults,r.data.externalContent,r.context.globalDesign,r.data.tileId),t?.mount?.(n,o,r),n.mount(o)},update:o=>{E().update(n,o.data.content,o.data.design,o.data.defaults,o.data.externalContent,o.context.globalDesign,o.data.tileId),t?.update?.(n,o)},unmount:()=>{t?.unmount?.(n),n.unmount()}}}}}function pe(){return globalThis.window.instantsite}function me(e,t){return{init:()=>{const{app:n}=M(e);return t?.init?.(n),{render:async(o,r)=>(E().init(n,o,r.content,r.design,r.defaults,r.externalContent,o.globalDesign,r.tileId),t?.render?.(n,o,r),{html:await Te(n,{context:o}),state:{context:o,data:r}})}}}}const U={SCROLL_TO_TILE:"SCROLL_TO_TILE",HYPER_LINK:"HYPER_LINK",MAIL_LINK:"MAIL_LINK",TEL_LINK:"TEL_LINK",GO_TO_STORE:"GO_TO_STORE",GO_TO_STORE_LINK:"GO_TO_STORE_LINK",GO_TO_PAGE:"GO_TO_PAGE",GO_TO_CATEGORY:"GO_TO_CATEGORY",GO_TO_CATEGORY_LINK:"GO_TO_CATEGORY_LINK"};m.enum(Object.values(U));const Ie=U,x={COLOR:"COLOR",GRADIENT:"GRADIENT",NONE:"NONE"};m.enum(Object.values(x));const Le=x,P={SOLID:"SOLID",OUTLINE:"OUTLINE",TEXT:"TEXT"};m.enum(Object.values(P));const _e=P,k={SMALL:"SMALL",MEDIUM:"MEDIUM",LARGE:"LARGE"};m.enum(Object.values(k));const Ce=k,$={ROUND_CORNER:"ROUND_CORNER",RECTANGLE:"RECTANGLE",PILL:"PILL"};m.enum(Object.values($));const Re=$,K={COLOR:"COLOR",GRADIENT:"GRADIENT"};m.enum(Object.values(K));const be=K,X={SECTION:"SECTION",HEADER:"HEADER",FOOTER:"FOOTER"};m.enum(Object.values(X));const ye=X;var z=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.Misc=2]="Misc",e[e.Layout=3]="Layout",e[e.Asset=4]="Asset",e[e.SharedFiles=5]="SharedFiles",e))(z||{}),F=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.SectionSetting=2]="SectionSetting",e[e.SectionShowcase=3]="SectionShowcase",e[e.SectionAsset=4]="SectionAsset",e[e.TemplateDescriptor=5]="TemplateDescriptor",e[e.PageTemplateDescriptor=6]="PageTemplateDescriptor",e[e.TemplateAsset=7]="TemplateAsset",e[e.Layout=8]="Layout",e[e.LayoutSettings=9]="LayoutSettings",e[e.LayoutAsset=10]="LayoutAsset",e[e.SlotServer=11]="SlotServer",e[e.SlotClient=12]="SlotClient",e[e.SharedTranslation=13]="SharedTranslation",e[e.CollectionDescriptor=14]="CollectionDescriptor",e[e.CollectionAsset=15]="CollectionAsset",e))(F||{}),Y=(e=>(e.SCROLL_TO_TILE="SCROLL_TO_TILE",e.HYPER_LINK="HYPER_LINK",e.MAIL_LINK="MAIL_LINK",e.TEL_LINK="TEL_LINK",e.GO_TO_STORE="GO_TO_STORE",e.GO_TO_STORE_LINK="GO_TO_STORE_LINK",e.GO_TO_PAGE="GO_TO_PAGE",e))(Y||{});const L={TEXTAREA:"TEXTAREA",INPUTBOX:"INPUTBOX",SELECTBOX:"SELECTBOX",IMAGE:"IMAGE",TOGGLE:"TOGGLE",BUTTON:"BUTTON",DECK:"DECK",MENU:"MENU",NAVIGATION_MENU:"NAVIGATION_MENU",LOGO:"LOGO",INFO:"INFO",DIVIDER:"DIVIDER",PRODUCT_SELECTOR:"PRODUCT_SELECTOR",CATEGORY_SELECTOR:"CATEGORY_SELECTOR"};m.enum(Object.values(L));const V={TEXT:"TEXT",BUTTON:"BUTTON",IMAGE:"IMAGE",TOGGLE:"TOGGLE",SELECTBOX:"SELECTBOX",BACKGROUND:"BACKGROUND",COLOR_PICKER:"COLOR_PICKER",LOGO:"LOGO",DIVIDER:"DIVIDER",INFO:"INFO"};m.enum(Object.values(V));const Se=V,j={CONTENT:"Content",DESIGN:"Design"};m.enum(Object.values(j));const Ge=j,W={TEXT:"TEXT",IMAGE:"IMAGE"};m.enum(Object.values(W));const Ae=W;var H=(e=>(e.ORIGINAL="original",e.WEBP_LOW_RES="webp-200x200",e.WEBP_HI_2X_RES="webp-2000x2000",e.MOBILE_WEBP_LOW_RES="cropped-webp-100x200",e.MOBILE_WEBP_HI_RES="cropped-webp-1000x2000",e))(H||{}),J=(e=>(e.TILE_LOADED="tile-loaded",e.TILE_UNLOADED="tile-unloaded",e))(J||{});const Ne={PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},De={CATEGORY_TITLE:"MAIN_TITLE",PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},he={TOP_BAR:"TOP_BAR",GALLERY:"GALLERY",SIDEBAR:"SIDEBAR",DESCRIPTION:"DESCRIPTION",REVIEW_LIST:"REVIEW_LIST",RELATED_PRODUCTS:"RELATED_PRODUCTS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},q={apparel_footwear:"apparel_footwear",vape_smoke:"vape_smoke",home_garden:"home_garden",sport_outdoor:"sport_outdoor",jewelry_accessories:"jewelry_accessories",pet_animals:"pet_animals",bikes:"bikes",health_beauty:"health_beauty",gift_shop:"gift_shop",electronics:"electronics",other:"other"};m.enum(Object.values(q));const we=q;function Q(e){if(!e||e.length===0)return[];const t=[];function n(o){if(t.push({id:o.id,name:o.name,url:o.urlPath}),o.children&&o.children.length>0)for(const r of o.children)n(r)}for(const o of e)n(o);return t}const S={HYPER_LINK:"HYPER_LINK",SCROLL_TO_TILE:"SCROLL_TO_TILE",MAIL_LINK:"MAIL_LINK",TEL_LINK:"TEL_LINK",GO_TO_STORE:"GO_TO_STORE",GO_TO_STORE_LINK:"GO_TO_STORE_LINK",GO_TO_PAGE:"GO_TO_PAGE",GO_TO_CATEGORY:"GO_TO_CATEGORY",GO_TO_CATEGORY_LINK:"GO_TO_CATEGORY_LINK"};function Be(e){if("tileId"in e)return e.tileId;if("tileIdForScroll"in e)return e.tileIdForScroll}function Me(e){if("pageId"in e)return e.pageId;if("pageIdForNavigate"in e)return e.pageIdForNavigate}function Ue(e,t){if("pageUrl"in e)return e.pageUrl;const n=Me(e);switch(n){case"products":return"/products";case"cart":return"/cart";case"account":return"/account";case"search":return"/search";case"home":return"/"}if(t){const o=t.find(r=>r.pageId===n);if(o)return o.url}return"/"}function xe(e){if("categoryId"in e)return e.categoryId}function Pe(e){if(!e||e.length===0)return"";const t=e.find(n=>n.selected);return!t||t.main?"":`/${t.code}`}const Z=(e,t,n)=>{if(!e||t)return;const{type:o,link:r,email:i,phone:l}=e,d=E(),v=d.site?.value?.pages,c=d.site?.value?.languages,s=Pe(c),u=Ue(e,v),O=xe(e);switch(o){case S.HYPER_LINK:if(r){const f=e.linkTarget??"_blank";return()=>window.open(r,f)}break;case S.GO_TO_STORE:case S.GO_TO_STORE_LINK:return()=>window.open(`${s}/products`,"_self");case S.GO_TO_CATEGORY:case S.GO_TO_CATEGORY_LINK:const G=n?.find(f=>f.id===O)?.url;return G===void 0?()=>window.open(`${s}/404`,"_self"):()=>window.open(G,"_self");case S.MAIL_LINK:if(i)return()=>window.open(`mailto:${i}`,"_self");break;case S.TEL_LINK:if(l)return()=>window.open(`tel:${l}`,"_self");break;case S.SCROLL_TO_TILE:if(typeof document<"u")return()=>{const f=Be(e);document.getElementById(`tile-${f}`)?.scrollIntoView()};break;case S.GO_TO_PAGE:if(u)return()=>window.open(`${s}${u}`,"_self");break;default:console.error(`Unknown type of ActionLink: ${o}`)}};function ke(e){return"title"in e&&"type"in e}function $e(e,t,n,o){const r=a(()=>{const b=e.value[t];if(b!==void 0){if(ke(b))return b;throw new Error(`Element ${t} is not action link`)}}),i=a(()=>r.value?.title),l=a(()=>r.value?.type),d=a(()=>r.value?.link),v=a(()=>r.value?.email),c=a(()=>r.value?.phone),s=a(()=>r.value?.tileId?`tile-${r.value?.tileId}`:null),u=a(()=>r.value?.type==="GO_TO_STORE_LINK"?"products":r.value?.pageId),O=a(()=>r.value?.pageUrl),G=a(()=>!!i.value),f=a(()=>!!d.value),A=Z(r.value,n,o);return g({title:i,type:l,link:d,email:v,phone:c,tileDivId:s,pageId:u,pageUrl:O,hasTitle:G,hasLink:f,performAction:A})}function ee(e,t){const n=E(),o=a(()=>!!n.site?.value?.isPreviewMode),r=a(()=>{const l=n.category?.value?.categoryTree;return Q(l)}),i=a(()=>t!==void 0?t:n.content.value!==void 0?n.content.value:{});return $e(i,e,o.value,r.value)}function te({content:e,elementName:t,errorMessage:n,validatorFn:o}){return a(()=>{const r=e.value?.[t];if(r!==void 0){if(o(r))return r;throw new Error(n)}})}function Ke(e){return typeof e=="object"&&e!==null&&"categories"in e}function Xe(e){return a(()=>e.value.reduce((t,n)=>(t[n.id]=n,t),{}))}function ze(e){return e!==void 0}function Fe(e){return!!e?.trim()}function Ye({name:e,customName:t,selectionType:n}){return n==="ROOT"?e:Fe(t)?t:e}function Ve(e,t){return ze(e)&&t}function ne({itemId:e,id:t,alt:n,name:o,nameTranslated:r,customName:i,enabled:l,productsCount:d,url:v,imageUrl:c,thumbnailImageUrl:s,imageBorderInfo:u,selectionType:O}){return{itemId:e||t.toString(),id:t,alt:n,name:Ye({name:o,customName:i,selectionType:O}),nameTranslated:r,label:o,enabled:l,url:v,productsCount:d,imageUrl:c,thumbnailImageUrl:s,imageBorderInfo:u,showCategory:Ve(t,l)}}function oe(e,t,n){const o=E(),r=a(()=>t!==void 0?t:o.content.value),i=te({content:r,elementName:e,errorMessage:`Element ${e} is not a category selector type`,validatorFn:Ke}),l=a(()=>n??o.storeData?.value),d=a(()=>i.value?.categories.selectionType??"ROOT"),v=a(()=>l.value?.categories??[]),c=a(()=>i.value?.categories?.categoryIds??[]),s=a(()=>{const G=Xe(v);return d.value==="MANUAL"?i.value?.categories?.items?.map(f=>{const A=G.value[f.id];return ne({...f,...A,selectionType:d.value})})??[]:l?.value?.categories.map(f=>ne({...f,selectionType:d.value}))??[]}),u=a(()=>i.value!==void 0),O=a(()=>s.value!==void 0&&s.value.length>0);return g({categories:s,categoryIds:c,hasContent:u,hasCategories:O})}function je(e){return typeof e=="object"&&e!==null&&("products"in e||"product"in e)}function ae(e,t,n){const o=E(),r=a(()=>t!==void 0?t:o.content.value),i=te({content:r,elementName:e,errorMessage:`Element ${e} is not a product selector type`,validatorFn:je}),l=a(()=>n??o.storeData?.value),d=a(()=>i.value?.products?.selectionType??"MANUAL"),v=a(()=>i.value?.products?.productIds??[]),c=a(()=>i.value?.product?.id),s=a(()=>typeof i.value?.categoryId=="number"?i.value.categoryId:void 0),u=a(()=>{if(d.value==="CATEGORY")return s.value===0?l?.value?.products.filter(b=>b?.defaultCategoryId===0)??[]:l?.value?.products.filter(b=>s.value&&b?.categoryIds?.includes(s.value))??[];const A=c.value?[c.value]:v.value??[];return l?.value?.products?.filter(b=>A.includes(b.id))??[]}),O=a(()=>l?.value?.categories.filter(A=>A.id===s?.value)??[]),G=a(()=>i.value!==void 0&&u.value.length>0),f=a(()=>u.value!==void 0&&u.value.length>0);return g({products:u,categories:O,categoryId:s,hasContent:G,hasProducts:f})}function We(e){return"bucket"in e&&"borderInfo"in e&&"set"in e}function N(e,t){const n=new RegExp(/^https?:\/\//);return e!=null&&n.test(e)?e:`${t}/${e}`}function He(e,t){const n=a(()=>{const c=e.value[t];if(c!==void 0){if(We(c))return c;throw new Error(`Element ${t} is not image`)}}),o=a(()=>n.value===void 0?"":E().context.value.imageBuckets?.[n.value?.bucket]),r=a(()=>n.value!==void 0),i=a(()=>N(n.value?.set?.["cropped-webp-100x200"]?.url,o.value)),l=a(()=>N(n.value?.set?.["cropped-webp-1000x2000"]?.url,o.value)),d=a(()=>N(n.value?.set?.["webp-200x200"]?.url,o.value)),v=a(()=>N(n.value?.set?.["webp-2000x2000"]?.url,o.value));return g({hasContent:r,lowResolutionMobileImage:i,highResolutionMobileImage:l,lowResolutionDesktopImage:d,highResolutionDesktopImage:v})}function re(e,t){const n=E(),o=a(()=>t!==void 0?t:n.content.value);return He(o,e)}function Je(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not inputbox`)}}),o=a(()=>n.value!==void 0&&n.value.length>0),r=a(()=>n.value);return g({hasContent:o,value:r})}function ie(e,t){const n=E(),o=a(()=>t!==void 0?t:n.content.value);return Je(o,e)}function qe(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not selectbox`)}}),o=a(()=>n.value!==void 0),r=a(()=>n.value);return g({hasContent:o,value:r})}function le(e,t){const n=E(),o=a(()=>t!==void 0?t:n.content.value);return qe(o,e)}function Qe(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(typeof i=="string")return i;throw new Error(`Element ${t} is not textarea`)}}),o=a(()=>n.value!==void 0),r=a(()=>n.value);return g({hasContent:o,value:r})}function ue(e,t){const n=E(),o=a(()=>t!==void 0?t:n.content.value);return Qe(o,e)}function Ze(e){return"enabled"in e}function et(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(Ze(i))return i;throw new Error(`Element ${t} is not toggle`)}}),o=a(()=>n.value!==void 0),r=a(()=>n.value?.enabled);return g({hasContent:o,value:r})}function se(e,t){const n=E(),o=a(()=>t!==void 0?t:n.content.value);return et(o,e)}function tt(e){if(typeof e!="object"||e===null)return!1;const t=e;return Array.isArray(t.cards)&&t.cards.every(n=>typeof n.settings=="object"&&n.settings!==null)}function nt(e,t,n,o){if(e==null)throw Error("Could not get a reactive ref for undefined Card");const r=e.settings[n];if(r===void 0)return r;switch(t){case L.TEXTAREA:return ue(n,e.settings);case L.INPUTBOX:return ie(n,e.settings);case L.SELECTBOX:return le(n,e.settings);case L.IMAGE:return re(n,e.settings);case L.TOGGLE:return se(n,e.settings);case L.BUTTON:return ee(n,e.settings);case L.CATEGORY_SELECTOR:return oe(n,e.settings,o);case L.PRODUCT_SELECTOR:return ae(n,e.settings,o);default:return}}function ot(e){const t=E(),n=a(()=>t.storeData?.value),o=a(()=>{const l=t.content.value[e];if(l!==void 0){if(tt(l))return l;throw new Error(`Element ${e} is not of DECK type`)}}),r=a(()=>o.value!==void 0&&o.value.cards.length>0),i=a(()=>o.value?.cards);return g({hasContent:r,cards:i,getReactiveRef:(l,d,v)=>nt(l,d,v,n.value)})}function at(e){return"type"in e&&("text"in e||"image"in e)}function D(e,t){const n=new RegExp(/^https?:\/\//);return e!==void 0&&n.test(e)?e:`${t}/${e}`}function rt(){const e=E(),t=a(()=>{const l=e.content.value.logo;if(l!==void 0){if(at(l))return l;throw new Error("Element logo is not LOGO")}}),n=a(()=>t.value?.type),o=a(()=>t.value?.text),r=a(()=>t.value?.image===void 0?"":e.context.value.imageBuckets?.[t.value.image.bucket]),i=a(()=>({lowResolutionMobileImage:D(t.value?.image?.set?.["cropped-webp-100x200"]?.url,r.value),highResolutionMobileImage:D(t.value?.image?.set?.["cropped-webp-1000x2000"]?.url,r.value),lowResolutionDesktopImage:D(t.value?.image?.set?.["webp-200x200"]?.url,r.value),highResolutionDesktopImage:D(t.value?.image?.set?.["webp-2000x2000"]?.url,r.value)}));return g({type:n,text:o,image:i})}function it(e){return e!==null&&"items"in e}function ce(e){const t=E(),n=a(()=>{const u=t.content.value[e];if(u!==void 0){if(it(u))return u;throw new Error(`Element ${e} is not an menu`)}}),o=a(()=>!!t.site?.value?.isPreviewMode),r=a(()=>{const u=t.category?.value?.categoryTree;return Q(u)}),i=a(()=>n.value!==void 0);function l(u){if(u)try{return new URL(u).pathname}catch{return u}}function d(u){return u?.map(O=>({...O,url:l(O.url)??O.url}))}const v=a(()=>d(r.value));function c(u){const O=Z(u,o.value,v.value);return{...u,performAction:O,nestedItems:u.nestedItems?.map(c)}}const s=a(()=>n.value?.items?n.value.items.map(c):[]);return g({hasContent:i,items:s})}const lt="menu";function ut(){return ce(lt)}function st(){return globalThis.craneSharedTranslation??{}}function ct(){const e=E(),t=a(()=>e.site?.value),n=a(()=>st()),o=a(()=>{const r=t.value?.languages;return r?r.find(i=>i.selected)?.code??r.find(i=>i.main)?.code??"en":"en"});return{t:r=>{const i=n.value;if(!i||Object.keys(i).length===0)return r;const l=o.value,d=i[l]?.[r];if(d!==void 0)return d;if(l!=="en"){const v=i.en?.[r];if(v!==void 0)return v}return r},currentLanguageCode:o}}function de(e,t){if(t===void 0)return;if(!t.startsWith("global."))return t.replaceAll("_"," ");const n=t.split(".").at(2);if(n!==void 0)return e.fontFamily?e.fontFamily[n].replaceAll("_"," "):void 0}function h(e,t,n){return t?de(e,t):de(e,n)}function ve(e,t){if(t===void 0)return;if(typeof t!="string"||!t.startsWith("global."))return t;const n=t.split(".").at(2);if(n!==void 0)return e.textSize?e.textSize[n]:void 0}function B(e,t,n){return t?ve(e,t):ve(e,n)}function Ee(e,t){if(t===void 0)return;if(typeof t!="string"||!t.startsWith("global."))return t;const n=t.split(".").at(2);if(n!==void 0)return e.color?e.color[n]:void 0}function I(e,t,n){return t?Ee(e,t):Ee(e,n)}function dt(e,t,n){return{visible:t?.visible??n?.visible??!1,width:t?.width??n?.width??1,color:I(e,t?.color,n?.color)}}function vt(e){const t=E(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e],l=t.globalDesign.value;return{background:{type:r?.background?.type??i?.background?.type,solid:{color:I(l,r?.background?.solid?.color,i?.background?.solid?.color)},gradient:{fromColor:I(l,r?.background?.gradient?.fromColor,i?.background?.gradient?.fromColor),toColor:I(l,r?.background?.gradient?.toColor,i?.background?.gradient?.toColor)}}}}),o=a(()=>n.value?.background);return g({background:o})}function Et(e){const t=E(),n=a(()=>{const c=t.design.value[e],s=t.defaults.value[e],u=t.globalDesign.value;return{appearance:c?.appearance??s?.appearance,font:h(u,c?.font,s?.font),size:c?.size??s?.size,style:c?.style??s?.style,color:I(u,c?.color,s?.color),visible:c?.visible??s?.visible??!1}}),o=a(()=>n.value?.appearance),r=a(()=>n.value?.font),i=a(()=>n.value?.size),l=a(()=>n.value?.style),d=a(()=>n.value?.color),v=a(()=>n.value?.visible);return g({appearance:o,font:r,size:i,style:l,color:d,visible:v})}function Ot(e){const t=E(),n=a(()=>{const i=t.design.value[e],l=t.defaults.value[e],d=t.globalDesign.value;return{overlay:{type:i?.overlay?.type??l?.overlay?.type,solid:{color:I(d,i?.overlay?.solid?.color,l?.overlay?.solid?.color)},gradient:{fromColor:I(d,i?.overlay?.gradient?.fromColor,l?.overlay?.gradient?.fromColor),toColor:I(d,i?.overlay?.gradient?.toColor,l?.overlay?.gradient?.toColor)}},visible:i?.visible??l?.visible??!1}}),o=a(()=>n.value?.overlay),r=a(()=>n.value?.visible);return g({overlay:o,visible:r})}function gt(){const e=E(),t=a(()=>e.design.value.layout),n=a(()=>t.value);return g({layout:n})}function Tt(){const e=E();return a(()=>{const t=e.design.value.logo,n=e.defaults.value.logo,o=e.globalDesign.value;return{font:h(o,t?.font,n?.font),size:B(o,t?.size,n?.size),bold:t?.bold??n?.bold,italic:t?.italic??n?.italic,color:I(o,t?.color,n?.color),visible:t?.visible??n?.visible??!1,spacing:t?.spacing??n?.spacing??0,capitalization:t?.capitalization??n?.capitalization??"none",frame:dt(o,t?.frame,n?.frame)}})}function ft(e){const t=E(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e];return{value:r?.value??i?.value}}),o=a(()=>n.value?.value);return g({value:o})}function pt(e){const t=E(),n=a(()=>{const c=t.design.value[e],s=t.defaults.value[e],u=t.globalDesign.value;return{font:h(u,c?.font,s?.font),size:B(u,c?.size,s?.size),bold:c?.bold??s?.bold,italic:c?.italic??s?.italic,color:I(u,c?.color,s?.color),visible:c?.visible??s?.visible??!1}}),o=a(()=>n.value?.font),r=a(()=>n.value?.size),i=a(()=>n.value?.bold),l=a(()=>n.value?.italic),d=a(()=>n.value?.color),v=a(()=>n.value?.visible);return g({font:o,size:r,bold:i,italic:l,color:d,visible:v})}function mt(e){const t=E(),n=a(()=>{const s=t.design.value[e],u=t.defaults.value[e],O=t.globalDesign.value;return{font:h(O,s?.font,u?.font),size:B(O,s?.size,u?.size),bold:s?.bold??u?.bold,italic:s?.italic??u?.italic,color:I(O,s?.color,u?.color),visible:s?.visible??u?.visible??!1,whiteSpace:"pre-wrap"}}),o=a(()=>n.value?.font),r=a(()=>n.value?.size),i=a(()=>n.value?.bold),l=a(()=>n.value?.italic),d=a(()=>n.value?.color),v=a(()=>n.value?.visible),c=a(()=>n.value?.whiteSpace);return g({font:o,size:r,bold:i,italic:l,color:d,visible:v,whiteSpace:c})}function It(e){const t=E(),n=a(()=>{const r=t.design.value[e],i=t.defaults.value[e];return{enabled:r?.enabled??i?.enabled}}),o=a(()=>n.value?.enabled);return g({enabled:o})}function T(e){return t=>"type"in t?t:{type:e,...t}}function p(e){return t=>{const{type:n,defaults:o,...r}=t,i=o?T(e)(o):void 0;return{type:e,...r,...i!==void 0?{defaults:i}:{}}}}const Lt={inputbox:p("INPUTBOX"),textarea:p("TEXTAREA"),button:p("BUTTON"),image:p("IMAGE"),toggle:p("TOGGLE"),selectbox:p("SELECTBOX"),deck:p("DECK"),menu:p("MENU"),navigationMenu:p("NAVIGATION_MENU"),logo:p("LOGO"),productSelector:p("PRODUCT_SELECTOR"),categorySelector:p("CATEGORY_SELECTOR"),divider:p("DIVIDER"),info:p("INFO"),default:{inputbox:T("INPUTBOX"),textarea:T("TEXTAREA"),button:T("BUTTON"),selectbox:T("SELECTBOX"),image:T("IMAGE"),toggle:T("TOGGLE"),divider:T("DIVIDER"),info:T("INFO"),deck:T("DECK"),logo:T("LOGO"),menu:T("MENU"),navigationMenu:T("NAVIGATION_MENU"),productSelector:T("PRODUCT_SELECTOR"),categorySelector:T("CATEGORY_SELECTOR")}};function _(e){return t=>"type"in t?t:{type:e,...t}}function C(e){return t=>{const{type:n,defaults:o,...r}=t,i=o?_(e)(o):void 0;return{type:e,...r,...i!==void 0?{defaults:i}:{}}}}const _t={text:C("TEXT"),button:C("BUTTON"),image:C("IMAGE"),toggle:C("TOGGLE"),selectbox:C("SELECTBOX"),background:C("BACKGROUND"),colorPicker:C("COLOR_PICKER"),logo:C("LOGO"),divider:C("DIVIDER"),info:C("INFO"),default:{text:_("TEXT"),button:_("BUTTON"),image:_("IMAGE"),toggle:_("TOGGLE"),selectbox:_("SELECTBOX"),background:_("BACKGROUND"),colorPicker:_("COLOR_PICKER"),logo:_("LOGO"),info:_("INFO")}};function R(e){return t=>{const{type:n,defaults:o,...r}=t,i=o,l=i&&!("type"in i)?{...i,type:e}:o;return{type:e,...r,...l!==void 0?{defaults:l}:{}}}}const Ct={init:e=>({...e}),designOverride:{text:R("TEXT"),button:R("BUTTON"),image:R("IMAGE"),toggle:R("TOGGLE"),selectbox:R("SELECTBOX"),background:R("BACKGROUND"),colorPicker:R("COLOR_PICKER"),logo:R("LOGO"),divider:R("DIVIDER"),info:R("INFO")}},Rt={init:e=>e},bt={configuration:e=>({...e}),page:e=>({...e})},yt={default:e=>{const{type:t,...n}=e;return{type:"default",...n}},custom:e=>{const{type:t,...n}=e;return{type:"custom",...n}},store:(e={})=>{const{type:t,...n}=e;return{type:"store",...n}}},St={init:e=>({...e})};export{Y as ActionLinkTypeEnum,be as BackgroundStyleEnum,_e as ButtonAppearanceEnum,Re as ButtonShapeEnum,Ce as ButtonSizeEnum,Ie as ButtonTypeEnum,Ne as CatalogLayoutSlot,De as CategoryLayoutSlot,F as ConfigTypeEnum,Se as DesignEditorType,L as EditorTypes,H as ImageSet,J as InstantsiteJsEvent,Ae as LogoTypeEnum,Le as OverlayTypeEnum,z as PluginTypeEnum,he as ProductLayoutSlot,ye as SectionTypeEnum,we as TemplateCategoriesList,Ge as ValidationTypeEnum,Lt as content,fe as createVueClientApp,me as createVueServerApp,_t as design,Ct as layout,yt as section,Rt as showcase,bt as template,St as translation,vt as useBackgroundElementDesign,ee as useButtonElementContent,Et as useButtonElementDesign,oe as useCategorySelectorElementContent,ot as useDeckElementContent,re as useImageElementContent,Ot as useImageElementDesign,ie as useInputboxElementContent,pe as useInstantsiteJsApi,gt as useLayoutElementDesign,rt as useLogoElementContent,Tt as useLogoElementDesign,ce as useMenuElementContent,ut as useNavigationMenuElementContent,ae as useProductSelectorElementContent,le as useSelectboxElementContent,ft as useSelectboxElementDesign,pt as useTextElementDesign,ue as useTextareaElementContent,mt as useTextareaElementDesign,se as useToggleElementContent,It as useToggleElementDesign,ct as useTranslation,E as useVueBaseProps};
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/// <reference types="vite/client" />
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
declare module '*.vue' {
|
|
4
|
+
import type { DefineComponent } from 'vue';
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
const component: DefineComponent<{}, {}, any>;
|
|
7
|
+
export default component;
|
|
8
|
+
}
|
|
5
9
|
|
|
6
10
|
type ActionLinkType
|
|
7
11
|
= 'SCROLL_TO_TILE'
|
|
@@ -559,53 +563,54 @@ type MapEditorDesignTypes = {
|
|
|
559
563
|
readonly COLOR_PICKER: string;
|
|
560
564
|
readonly LOGO: string;
|
|
561
565
|
readonly DIVIDER: string;
|
|
566
|
+
readonly INFO: string;
|
|
562
567
|
};
|
|
563
568
|
|
|
564
569
|
interface TextDesignEditor {
|
|
565
570
|
readonly type: 'TEXT';
|
|
566
571
|
readonly label: string | Record<string, string>;
|
|
567
|
-
defaults
|
|
572
|
+
defaults?: Record<string, unknown>;
|
|
568
573
|
}
|
|
569
574
|
|
|
570
575
|
interface ButtonDesignEditor {
|
|
571
576
|
readonly type: 'BUTTON';
|
|
572
577
|
readonly label: string | Record<string, string>;
|
|
573
|
-
defaults
|
|
578
|
+
defaults?: Record<string, unknown>;
|
|
574
579
|
}
|
|
575
580
|
|
|
576
581
|
interface ImageDesignEditor {
|
|
577
582
|
readonly type: 'IMAGE';
|
|
578
583
|
readonly label: string | Record<string, string>;
|
|
579
|
-
defaults
|
|
584
|
+
defaults?: Record<string, unknown>;
|
|
580
585
|
}
|
|
581
586
|
|
|
582
587
|
interface ToggleDesignEditor {
|
|
583
588
|
readonly type: 'TOGGLE';
|
|
584
589
|
readonly label: string | Record<string, string>;
|
|
585
|
-
defaults
|
|
590
|
+
defaults?: Record<string, unknown>;
|
|
586
591
|
}
|
|
587
592
|
|
|
588
593
|
interface SelectboxDesignEditor {
|
|
589
594
|
readonly type: 'SELECTBOX';
|
|
590
595
|
readonly label: string | Record<string, string>;
|
|
591
|
-
defaults
|
|
596
|
+
defaults?: Record<string, unknown>;
|
|
592
597
|
}
|
|
593
598
|
|
|
594
599
|
interface BackgroundDesignEditor {
|
|
595
600
|
readonly type: 'BACKGROUND';
|
|
596
601
|
readonly label: string | Record<string, string>;
|
|
597
|
-
defaults
|
|
602
|
+
defaults?: Record<string, unknown>;
|
|
598
603
|
}
|
|
599
604
|
|
|
600
605
|
interface ColorPickerDesignEditor {
|
|
601
606
|
readonly type: 'COLOR_PICKER';
|
|
602
|
-
defaults
|
|
607
|
+
defaults?: Record<string, unknown>;
|
|
603
608
|
}
|
|
604
609
|
|
|
605
610
|
interface LogoDesignEditor {
|
|
606
611
|
readonly type: 'LOGO';
|
|
607
612
|
readonly label?: string | Record<string, string>;
|
|
608
|
-
defaults
|
|
613
|
+
defaults?: Record<string, unknown>;
|
|
609
614
|
}
|
|
610
615
|
|
|
611
616
|
interface DividerDesignEditor {
|
|
@@ -622,7 +627,8 @@ type DesignEditor
|
|
|
622
627
|
| BackgroundDesignEditor
|
|
623
628
|
| ColorPickerDesignEditor
|
|
624
629
|
| LogoDesignEditor
|
|
625
|
-
| DividerDesignEditor
|
|
630
|
+
| DividerDesignEditor
|
|
631
|
+
| InfoDesignEditor;
|
|
626
632
|
|
|
627
633
|
type InferDesignType<T extends Record<string, DesignEditor>> = {
|
|
628
634
|
readonly [P in keyof T]: MapEditorDesignTypes[T[P]['type']]
|