@lightspeed/crane-api 2.3.0 → 2.3.1
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 +13 -0
- package/dist/index.d.mts +952 -4193
- package/dist/index.d.ts +952 -4193
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/types.d.ts +55 -56
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createSSRApp as Te,getCurrentInstance as fe,ref as y,computed as a,reactive as O}from"vue";import{renderToString as pe}from"vue/server-renderer";import{z as m}from"zod";function M(e){return{app:Te(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=fe()?.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 me(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 Ie(){return globalThis.window.instantsite}function Le(e){const t={appName:"",blockName:"",version:"",scriptUrl:"",imageBuckets:{},globalDesign:{}};return{component:e,initState(n,o,r,i){E().init(n,t,o,r,i,{},{},void 0)},updateState(n,o,r,i){E().update(n,o,r,i,{},{},void 0)}}}function _e(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 pe(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 Ce=U,k={COLOR:"COLOR",GRADIENT:"GRADIENT",NONE:"NONE"};m.enum(Object.values(k));const Re=k,x={SOLID:"SOLID",OUTLINE:"OUTLINE",TEXT:"TEXT"};m.enum(Object.values(x));const be=x,P={SMALL:"SMALL",MEDIUM:"MEDIUM",LARGE:"LARGE"};m.enum(Object.values(P));const ye=P,K={ROUND_CORNER:"ROUND_CORNER",RECTANGLE:"RECTANGLE",PILL:"PILL"};m.enum(Object.values(K));const Se=K,$={COLOR:"COLOR",GRADIENT:"GRADIENT"};m.enum(Object.values($));const Ae=$,X={SECTION:"SECTION",HEADER:"HEADER",FOOTER:"FOOTER"};m.enum(Object.values(X));const Ne=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 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"};m.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",INFO:"INFO",ACCORDION:"ACCORDION"};m.enum(Object.values(V));const Ge=V,j={CONTENT:"Content",DESIGN:"Design"};m.enum(Object.values(j));const De=j,W={TEXT:"TEXT",IMAGE:"IMAGE"};m.enum(Object.values(W));const he=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 we={PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},Be={CATEGORY_TITLE:"MAIN_TITLE",PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},Me={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 Ue=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 ke(e){if("tileId"in e)return e.tileId;if("tileIdForScroll"in e)return e.tileIdForScroll}function xe(e){if("pageId"in e)return e.pageId;if("pageIdForNavigate"in e)return e.pageIdForNavigate}function Pe(e,t){if("pageUrl"in e)return e.pageUrl;const n=xe(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 Ke(e){if("categoryId"in e)return e.categoryId}function $e(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=$e(c),u=Pe(e,v),g=Ke(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 A=n?.find(f=>f.id===g)?.url;return A===void 0?()=>window.open(`${s}/404`,"_self"):()=>window.open(A,"_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=ke(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 Xe(e){return"title"in e&&"type"in e}function ze(e,t,n,o){const r=a(()=>{const b=e.value[t];if(b!==void 0){if(Xe(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),g=a(()=>r.value?.pageUrl),A=a(()=>!!i.value),f=a(()=>!!d.value),N=Z(r.value,n,o);return O({title:i,type:l,link:d,email:v,phone:c,tileDivId:s,pageId:u,pageUrl:g,hasTitle:A,hasLink:f,performAction:N})}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 ze(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 Fe(e){return typeof e=="object"&&e!==null&&"categories"in e}function Ye(e){return a(()=>e.value.reduce((t,n)=>(t[n.id]=n,t),{}))}function Ve(e){return e!==void 0}function je(e){return!!e?.trim()}function We({name:e,customName:t,selectionType:n}){return n==="ROOT"?e:je(t)?t:e}function He(e,t){return Ve(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:g}){return{itemId:e||t.toString(),id:t,alt:n,name:We({name:o,customName:i,selectionType:g}),nameTranslated:r,label:o,enabled:l,url:v,productsCount:d,imageUrl:c,thumbnailImageUrl:s,imageBorderInfo:u,showCategory:He(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:Fe}),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 A=Ye(v);return d.value==="MANUAL"?i.value?.categories?.items?.map(f=>{const N=A.value[f.id];return ne({...f,...N,selectionType:d.value})})??[]:l?.value?.categories.map(f=>ne({...f,selectionType:d.value}))??[]}),u=a(()=>i.value!==void 0),g=a(()=>s.value!==void 0&&s.value.length>0);return O({categories:s,categoryIds:c,hasContent:u,hasCategories:g})}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 N=c.value?[c.value]:v.value??[];return l?.value?.products?.filter(b=>N.includes(b.id))??[]}),g=a(()=>l?.value?.categories.filter(N=>N.id===s?.value)??[]),A=a(()=>i.value!==void 0&&u.value.length>0),f=a(()=>u.value!==void 0&&u.value.length>0);return O({products:u,categories:g,categoryId:s,hasContent:A,hasProducts:f})}function qe(e){return"bucket"in e&&"borderInfo"in e&&"set"in e}function G(e,t){const n=new RegExp(/^https?:\/\//);return e!=null&&n.test(e)?e:`${t}/${e}`}function Qe(e,t){const n=a(()=>{const c=e.value[t];if(c!==void 0){if(qe(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(()=>G(n.value?.set?.["cropped-webp-100x200"]?.url,o.value)),l=a(()=>G(n.value?.set?.["cropped-webp-1000x2000"]?.url,o.value)),d=a(()=>G(n.value?.set?.["webp-200x200"]?.url,o.value)),v=a(()=>G(n.value?.set?.["webp-2000x2000"]?.url,o.value));return O({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 Qe(o,e)}function Ze(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 Ze(o,e)}function et(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 et(o,e)}function tt(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 tt(o,e)}function nt(e){return"enabled"in e}function ot(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(nt(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 ot(o,e)}function ce(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 de(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);case I.DECK:return at(e,n,o);default:return}}function at(e,t,n){const o=a(()=>{const l=e.settings[t];if(l!==void 0){if(ce(l))return l;throw new Error(`Element ${t} 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:(l,d,v)=>de(l,d,v,n)})}function rt(e){const t=E(),n=a(()=>t.storeData?.value),o=a(()=>{const l=t.content.value[e];if(l!==void 0){if(ce(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 O({hasContent:r,cards:i,getReactiveRef:(l,d,v)=>de(l,d,v,n.value)})}function it(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 lt(){const e=E(),t=a(()=>{const l=e.content.value.logo;if(l!==void 0){if(it(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 O({type:n,text:o,image:i})}function ut(e){return e!==null&&"items"in e}function ve(e){const t=E(),n=a(()=>{const u=t.content.value[e];if(u!==void 0){if(ut(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(g=>({...g,url:l(g.url)??g.url}))}const v=a(()=>d(r.value));function c(u){const g=Z(u,o.value,v.value);return{...u,performAction:g,nestedItems:u.nestedItems?.map(c)}}const s=a(()=>n.value?.items?n.value.items.map(c):[]);return O({hasContent:i,items:s})}const st="menu";function ct(){return ve(st)}function dt(){return globalThis.craneSharedTranslation??{}}function vt(){const e=E(),t=a(()=>e.site?.value),n=a(()=>dt()),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 Et(e){const t=E(),n=a(()=>t.design.value[e]),o=a(()=>{const l=n.value?.items;return l!==void 0&&Object.keys(l).length>0}),r=a(()=>n.value?.items),i=a(()=>n.value?.sortable??!1);return O({hasItems:o,items:r,sortable:i})}function Ee(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?Ee(e,t):Ee(e,n)}function Oe(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?Oe(e,t):Oe(e,n)}function ge(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 L(e,t,n){return t?ge(e,t):ge(e,n)}function Ot(e,t,n){return{visible:t?.visible??n?.visible??!1,width:t?.width??n?.width??1,color:L(e,t?.color,n?.color)}}function gt(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:L(l,r?.background?.solid?.color,i?.background?.solid?.color)},gradient:{fromColor:L(l,r?.background?.gradient?.fromColor,i?.background?.gradient?.fromColor),toColor:L(l,r?.background?.gradient?.toColor,i?.background?.gradient?.toColor)}}}}),o=a(()=>n.value?.background);return O({background:o})}function Tt(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:L(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 O({appearance:o,font:r,size:i,style:l,color:d,visible:v})}function ft(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:L(d,i?.overlay?.solid?.color,l?.overlay?.solid?.color)},gradient:{fromColor:L(d,i?.overlay?.gradient?.fromColor,l?.overlay?.gradient?.fromColor),toColor:L(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 O({overlay:o,visible:r})}function pt(){const e=E(),t=a(()=>e.design.value.layout),n=a(()=>t.value);return O({layout:n})}function mt(){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:L(o,t?.color,n?.color),visible:t?.visible??n?.visible??!1,spacing:t?.spacing??n?.spacing??0,capitalization:t?.capitalization??n?.capitalization??"none",frame:Ot(o,t?.frame,n?.frame)}})}function It(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 Lt(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:L(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 O({font:o,size:r,bold:i,italic:l,color:d,visible:v})}function _t(e){const t=E(),n=a(()=>{const s=t.design.value[e],u=t.defaults.value[e],g=t.globalDesign.value;return{font:h(g,s?.font,u?.font),size:B(g,s?.size,u?.size),bold:s?.bold??u?.bold,italic:s?.italic??u?.italic,color:L(g,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 O({font:o,size:r,bold:i,italic:l,color:d,visible:v,whiteSpace:c})}function Ct(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})}const Rt={configuration:e=>({metadata:{...e.metadata},sections:[...e.sections]})};function T(e){return t=>{const{type:n}=t;return"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 bt={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=>{const{type:n}=t;return"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 yt={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"),accordion:C("ACCORDION"),default:{text:_("TEXT"),button:_("BUTTON"),image:_("IMAGE"),toggle:_("TOGGLE"),selectbox:_("SELECTBOX"),background:_("BACKGROUND"),colorPicker:_("COLOR_PICKER"),logo:_("LOGO"),accordion:_("ACCORDION"),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 St={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"),accordion:R("ACCORDION")}},At={init:e=>e},Nt={configuration:e=>({...e}),page:e=>({...e})},Gt={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}}},Dt={init:e=>({...e})};export{Y as ActionLinkTypeEnum,Ae as BackgroundStyleEnum,be as ButtonAppearanceEnum,Se as ButtonShapeEnum,ye as ButtonSizeEnum,Ce as ButtonTypeEnum,we as CatalogLayoutSlot,Be as CategoryLayoutSlot,F as ConfigTypeEnum,Ge as DesignEditorType,I as EditorTypes,H as ImageSet,J as InstantsiteJsEvent,he as LogoTypeEnum,Re as OverlayTypeEnum,z as PluginTypeEnum,Me as ProductLayoutSlot,Ne as SectionTypeEnum,Ue as TemplateCategoriesList,De as ValidationTypeEnum,Rt as collection,bt as content,Le as createLayoutApp,me as createVueClientApp,_e as createVueServerApp,yt as design,St as layout,Gt as section,At as showcase,Nt as template,Dt as translation,Et as useAccordionElementDesign,gt as useBackgroundElementDesign,ee as useButtonElementContent,Tt as useButtonElementDesign,oe as useCategorySelectorElementContent,rt as useDeckElementContent,re as useImageElementContent,ft as useImageElementDesign,ie as useInputboxElementContent,Ie as useInstantsiteJsApi,pt as useLayoutElementDesign,lt as useLogoElementContent,mt as useLogoElementDesign,ve as useMenuElementContent,ct as useNavigationMenuElementContent,ae as useProductSelectorElementContent,le as useSelectboxElementContent,It as useSelectboxElementDesign,Lt as useTextElementDesign,ue as useTextareaElementContent,_t as useTextareaElementDesign,se as useToggleElementContent,Ct as useToggleElementDesign,vt as useTranslation,E as useVueBaseProps};
|
|
1
|
+
import{createSSRApp as Te,getCurrentInstance as fe,ref as y,computed as a,reactive as E}from"vue";import{renderToString as pe}from"vue/server-renderer";import{z as m}from"zod";function B(e){return{app:Te(e)}}const w=new Map;function O(){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=fe()?.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 me(e,t){return{init:()=>{const{app:n}=B(e);return t?.init?.(n),{mount:(o,r)=>{O().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=>{O().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 Ie(){return globalThis.window.instantsite}function Le(e){const t={appName:"",blockName:"",version:"",scriptUrl:"",imageBuckets:{},globalDesign:{}};return{component:e,initState(n,o,r,i){O().init(n,t,o,r,i,{},{},void 0)},updateState(n,o,r,i){O().update(n,o,r,i,{},{},void 0)}}}function _e(e,t){return{init:()=>{const{app:n}=B(e);return t?.init?.(n),{render:async(o,r)=>(O().init(n,o,r.content,r.design,r.defaults,r.externalContent,o.globalDesign,r.tileId),t?.render?.(n,o,r),{html:await pe(n,{context:o}),state:{context:o,data:r}})}}}}const Ce={SOLID:"solid",GRADIENT:"gradient",NONE:"none"},M={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(M));const Re=M,x={COLOR:"COLOR",GRADIENT:"GRADIENT",NONE:"NONE"};m.enum(Object.values(x));const be=x,k={SOLID:"SOLID",OUTLINE:"OUTLINE",TEXT:"TEXT"};m.enum(Object.values(k));const ye=k,P={SMALL:"SMALL",MEDIUM:"MEDIUM",LARGE:"LARGE"};m.enum(Object.values(P));const Se=P,$={ROUND_CORNER:"ROUND_CORNER",RECTANGLE:"RECTANGLE",PILL:"PILL"};m.enum(Object.values($));const Ae=$,K={COLOR:"COLOR",GRADIENT:"GRADIENT"};m.enum(Object.values(K));const Ne=K,X={SECTION:"SECTION",HEADER:"HEADER",FOOTER:"FOOTER"};m.enum(Object.values(X));const Ge=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 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"};m.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",INFO:"INFO",ACCORDION:"ACCORDION"};m.enum(Object.values(V));const De=V,j={CONTENT:"Content",DESIGN:"Design"};m.enum(Object.values(j));const he=j,W={TEXT:"TEXT",IMAGE:"IMAGE"};m.enum(Object.values(W));const we=W;class Ue{type="STRUCTURED_COLOR";raw;hex;hsl;rgba;auto;constructor({raw:t,hex:n,hsl:o,rgba:r,auto:i}){this.raw=t,this.hex=n,this.hsl=o,this.rgba=r,this.auto=i}}function Be(e){if(e!==void 0)return{...e,type:"STRUCTURED_COLOR"}}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 Me={PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},xe={CATEGORY_TITLE:"MAIN_TITLE",PRODUCT_LIST:"CONTROLS",BOTTOM_BAR:"FOOTER",CUSTOM_SLOT:"CUSTOM_SLOT"},ke={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 Pe=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 $e(e){if("tileId"in e)return e.tileId;if("tileIdForScroll"in e)return e.tileIdForScroll}function Ke(e){if("pageId"in e)return e.pageId;if("pageIdForNavigate"in e)return e.pageIdForNavigate}function Xe(e,t){if("pageUrl"in e)return e.pageUrl;const n=Ke(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 ze(e){if("categoryId"in e)return e.categoryId}function Fe(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=O(),v=d.site?.value?.pages,c=d.site?.value?.languages,s=Fe(c),u=Xe(e,v),g=ze(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 A=n?.find(f=>f.id===g)?.url;return A===void 0?()=>window.open(`${s}/404`,"_self"):()=>window.open(A,"_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=$e(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 Ye(e){return"title"in e&&"type"in e}function Ve(e,t,n,o){const r=a(()=>{const b=e.value[t];if(b!==void 0){if(Ye(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),g=a(()=>r.value?.pageUrl),A=a(()=>!!i.value),f=a(()=>!!d.value),N=Z(r.value,n,o);return E({title:i,type:l,link:d,email:v,phone:c,tileDivId:s,pageId:u,pageUrl:g,hasTitle:A,hasLink:f,performAction:N})}function ee(e,t){const n=O(),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 Ve(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 je(e){return typeof e=="object"&&e!==null&&"categories"in e}function We(e){return a(()=>e.value.reduce((t,n)=>(t[n.id]=n,t),{}))}function He(e){return e!==void 0}function Je(e){return!!e?.trim()}function qe({name:e,customName:t,selectionType:n}){return n==="ROOT"?e:Je(t)?t:e}function Qe(e,t){return He(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:g}){return{itemId:e||t.toString(),id:t,alt:n,name:qe({name:o,customName:i,selectionType:g}),nameTranslated:r,label:o,enabled:l,url:v,productsCount:d,imageUrl:c,thumbnailImageUrl:s,imageBorderInfo:u,showCategory:Qe(t,l)}}function oe(e,t,n){const o=O(),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:je}),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 A=We(v);return d.value==="MANUAL"?i.value?.categories?.items?.map(f=>{const N=A.value[f.id];return ne({...f,...N,selectionType:d.value})})??[]:l?.value?.categories.map(f=>ne({...f,selectionType:d.value}))??[]}),u=a(()=>i.value!==void 0),g=a(()=>s.value!==void 0&&s.value.length>0);return E({categories:s,categoryIds:c,hasContent:u,hasCategories:g})}function Ze(e){return typeof e=="object"&&e!==null&&("products"in e||"product"in e)}function ae(e,t,n){const o=O(),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:Ze}),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 N=c.value?[c.value]:v.value??[];return l?.value?.products?.filter(b=>N.includes(b.id))??[]}),g=a(()=>l?.value?.categories.filter(N=>N.id===s?.value)??[]),A=a(()=>i.value!==void 0&&u.value.length>0),f=a(()=>u.value!==void 0&&u.value.length>0);return E({products:u,categories:g,categoryId:s,hasContent:A,hasProducts:f})}function et(e){return"bucket"in e&&"set"in e}function G(e,t){const n=new RegExp(/^https?:\/\//);return e!=null&&n.test(e)?e:`${t}/${e}`}function tt(e,t){const n=a(()=>{const c=e.value[t];if(c!==void 0){if(et(c))return c;throw new Error(`Element ${t} is not image`)}}),o=a(()=>n.value===void 0?"":O().context.value.imageBuckets?.[n.value?.bucket]),r=a(()=>n.value!==void 0),i=a(()=>G(n.value?.set?.["cropped-webp-100x200"]?.url,o.value)),l=a(()=>G(n.value?.set?.["cropped-webp-1000x2000"]?.url,o.value)),d=a(()=>G(n.value?.set?.["webp-200x200"]?.url,o.value)),v=a(()=>G(n.value?.set?.["webp-2000x2000"]?.url,o.value));return E({hasContent:r,lowResolutionMobileImage:i,highResolutionMobileImage:l,lowResolutionDesktopImage:d,highResolutionDesktopImage:v})}function re(e,t){const n=O(),o=a(()=>t!==void 0?t:n.content.value);return tt(o,e)}function nt(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 E({hasContent:o,value:r})}function ie(e,t){const n=O(),o=a(()=>t!==void 0?t:n.content.value);return nt(o,e)}function ot(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 E({hasContent:o,value:r})}function le(e,t){const n=O(),o=a(()=>t!==void 0?t:n.content.value);return ot(o,e)}function at(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&&n.value.length>0),r=a(()=>n.value);return E({hasContent:o,value:r})}function ue(e,t){const n=O(),o=a(()=>t!==void 0?t:n.content.value);return at(o,e)}function rt(e){return"enabled"in e}function it(e,t){const n=a(()=>{const i=e.value[t];if(i!==void 0){if(rt(i))return i;throw new Error(`Element ${t} is not toggle`)}}),o=a(()=>n.value!==void 0),r=a(()=>n.value?.enabled);return E({hasContent:o,value:r})}function se(e,t){const n=O(),o=a(()=>t!==void 0?t:n.content.value);return it(o,e)}function ce(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 de(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);case I.DECK:return lt(e,n,o);default:return}}function lt(e,t,n){const o=a(()=>{const l=e.settings[t];if(l!==void 0){if(ce(l))return l;throw new Error(`Element ${t} is not of DECK type`)}}),r=a(()=>o.value!==void 0&&o.value.cards.length>0),i=a(()=>o.value?.cards);return E({hasContent:r,cards:i,getReactiveRef:(l,d,v)=>de(l,d,v,n)})}function ut(e){const t=O(),n=a(()=>t.storeData?.value),o=a(()=>{const l=t.content.value[e];if(l!==void 0){if(ce(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 E({hasContent:r,cards:i,getReactiveRef:(l,d,v)=>de(l,d,v,n.value)})}function st(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 ct(){const e=O(),t=a(()=>{const l=e.content.value.logo;if(l!==void 0){if(st(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 E({type:n,text:o,image:i})}function dt(e){return e!==null&&"items"in e}function ve(e){const t=O(),n=a(()=>{const u=t.content.value[e];if(u!==void 0){if(dt(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(g=>({...g,url:l(g.url)??g.url}))}const v=a(()=>d(r.value));function c(u){const g=Z(u,o.value,v.value);return{...u,performAction:g,nestedItems:u.nestedItems?.map(c)}}const s=a(()=>n.value?.items?n.value.items.map(c):[]);return E({hasContent:i,items:s})}const vt="menu";function Ot(){return ve(vt)}function Et(){return globalThis.craneSharedTranslation??{}}function gt(){const e=O(),t=a(()=>e.site?.value),n=a(()=>Et()),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 Tt(e){const t=O(),n=a(()=>t.design.value[e]),o=a(()=>{const l=n.value?.items;return l!==void 0&&Object.keys(l).length>0}),r=a(()=>n.value?.items),i=a(()=>n.value?.sortable??!1);return E({hasItems:o,items:r,sortable:i})}function Oe(e,t){if(t===void 0)return;if(!t.startsWith("global."))return t.replaceAll("_"," ");const n=t.split(".").at(2);return n===void 0?void 0:e.fontFamily?.[n]?.replaceAll("_"," ")}function h(e,t,n){return t?Oe(e,t):Oe(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.textSize?e.textSize[n]:void 0}function U(e,t,n){return t?Ee(e,t):Ee(e,n)}function ge(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 L(e,t,n){return t?ge(e,t):ge(e,n)}function ft(e,t,n){return{visible:t?.visible??n?.visible??!1,width:t?.width??n?.width??1,color:L(e,t?.color,n?.color)}}function pt(e){const t=O(),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:L(l,r?.background?.solid?.color,i?.background?.solid?.color)},gradient:{fromColor:L(l,r?.background?.gradient?.fromColor,i?.background?.gradient?.fromColor),toColor:L(l,r?.background?.gradient?.toColor,i?.background?.gradient?.toColor)}}}}),o=a(()=>n.value?.background);return E({background:o})}function mt(e){const t=O(),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:L(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 E({appearance:o,font:r,size:i,style:l,color:d,visible:v.value??!1})}function It(e){const t=O(),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:L(d,i?.overlay?.solid?.color,l?.overlay?.solid?.color)},gradient:{fromColor:L(d,i?.overlay?.gradient?.fromColor,l?.overlay?.gradient?.fromColor),toColor:L(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 E({overlay:o,visible:r})}function Lt(){const e=O(),t=a(()=>e.design.value.layout),n=a(()=>t.value);return E({layout:n})}function _t(){const e=O();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:U(o,t?.size,n?.size),bold:t?.bold??n?.bold,italic:t?.italic??n?.italic,color:L(o,t?.color,n?.color),visible:t?.visible??n?.visible??!1,spacing:t?.spacing??n?.spacing??0,capitalization:t?.capitalization??n?.capitalization??"none",frame:ft(o,t?.frame,n?.frame)}})}function Ct(e){const t=O(),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 E({value:o})}function Rt(e){const t=O(),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:U(u,c?.size,s?.size),bold:c?.bold??s?.bold,italic:c?.italic??s?.italic,color:L(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 E({font:o,size:r,bold:i,italic:l,color:d,visible:v})}function bt(e){const t=O(),n=a(()=>{const s=t.design.value[e],u=t.defaults.value[e],g=t.globalDesign.value;return{font:h(g,s?.font,u?.font),size:U(g,s?.size,u?.size),bold:s?.bold??u?.bold,italic:s?.italic??u?.italic,color:L(g,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 E({font:o,size:r,bold:i,italic:l,color:d,visible:v,whiteSpace:c})}function yt(e){const t=O(),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 E({enabled:o})}const St={configuration:e=>({metadata:{...e.metadata},sections:[...e.sections]})};function T(e){return t=>{const{type:n}=t;return"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 At={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=>{const{type:n}=t;return"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 Nt={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"),accordion:C("ACCORDION"),default:{text:_("TEXT"),button:_("BUTTON"),image:_("IMAGE"),toggle:_("TOGGLE"),selectbox:_("SELECTBOX"),background:_("BACKGROUND"),colorPicker:_("COLOR_PICKER"),logo:_("LOGO"),accordion:_("ACCORDION"),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 Gt={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"),accordion:R("ACCORDION")}},Dt={init:e=>e},ht={configuration:e=>({...e}),page:e=>({...e})},wt={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}}},Ut={init:e=>({...e})};export{Y as ActionLinkTypeEnum,Ne as BackgroundStyleEnum,ye as ButtonAppearanceEnum,Ae as ButtonShapeEnum,Se as ButtonSizeEnum,Re as ButtonTypeEnum,Me as CatalogLayoutSlot,xe as CategoryLayoutSlot,Ue as Color,F as ConfigTypeEnum,De as DesignEditorType,I as EditorTypes,H as ImageSet,J as InstantsiteJsEvent,we as LogoTypeEnum,Ce as OverlayType,be as OverlayTypeEnum,z as PluginTypeEnum,ke as ProductLayoutSlot,Ge as SectionTypeEnum,Pe as TemplateCategoriesList,he as ValidationTypeEnum,Be as asStructuredColor,St as collection,At as content,Le as createLayoutApp,me as createVueClientApp,_e as createVueServerApp,Nt as design,Gt as layout,wt as section,Dt as showcase,ht as template,Ut as translation,Tt as useAccordionElementDesign,pt as useBackgroundElementDesign,ee as useButtonElementContent,mt as useButtonElementDesign,oe as useCategorySelectorElementContent,ut as useDeckElementContent,re as useImageElementContent,It as useImageElementDesign,ie as useInputboxElementContent,Ie as useInstantsiteJsApi,Lt as useLayoutElementDesign,ct as useLogoElementContent,_t as useLogoElementDesign,ve as useMenuElementContent,Ot as useNavigationMenuElementContent,ae as useProductSelectorElementContent,le as useSelectboxElementContent,Ct as useSelectboxElementDesign,Rt as useTextElementDesign,ue as useTextareaElementContent,bt as useTextareaElementDesign,se as useToggleElementContent,yt as useToggleElementDesign,gt as useTranslation,O as useVueBaseProps};
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -115,35 +115,35 @@ interface LogoContentData {
|
|
|
115
115
|
readonly image: ImageContentData;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
type
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
118
|
+
/**
|
|
119
|
+
* This type is added for backward compatibility and will be removed in the future.
|
|
120
|
+
* Import the same type from '@lightspeed/crane-api' directly.
|
|
121
|
+
*/
|
|
122
|
+
type GlobalColorsString = import('./dist').GlobalColorsString;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* This type is added for backward compatibility and will be removed in the future.
|
|
126
|
+
* Import the same type from '@lightspeed/crane-api' directly.
|
|
127
|
+
*/
|
|
128
|
+
type GlobalFontsString = import('./dist').GlobalFontsString;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* This type is added for backward compatibility and will be removed in the future.
|
|
132
|
+
* Import the same type from '@lightspeed/crane-api' directly.
|
|
133
|
+
*/
|
|
134
|
+
type GlobalTextSizeString = import('./dist').GlobalTextSizeString;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* This type is added for backward compatibility and will be removed in the future.
|
|
138
|
+
* Import the same type from '@lightspeed/crane-api' directly.
|
|
139
|
+
*/
|
|
140
|
+
type HSLColor = import('./dist').HSLColor;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* This type is added for backward compatibility and will be removed in the future.
|
|
144
|
+
* Import the same type from '@lightspeed/crane-api' directly.
|
|
145
|
+
*/
|
|
146
|
+
type RGBAColor = import('./dist').RGBAColor;
|
|
147
147
|
|
|
148
148
|
// Note: We should check if RGBAColor has abbreviations or full names
|
|
149
149
|
interface RGBAColorNamed {
|
|
@@ -153,29 +153,30 @@ interface RGBAColorNamed {
|
|
|
153
153
|
alpha: number;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
auto?: boolean;
|
|
162
|
-
}
|
|
156
|
+
/**
|
|
157
|
+
* This type is added for backward compatibility and will be removed in the future.
|
|
158
|
+
* Import the same type from '@lightspeed/crane-api' directly.
|
|
159
|
+
*/
|
|
160
|
+
type Color = import('./dist').Color;
|
|
163
161
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
/**
|
|
163
|
+
* This type is added for backward compatibility and will be removed in the future.
|
|
164
|
+
* Import the same type from '@lightspeed/crane-api' directly.
|
|
165
|
+
*/
|
|
166
|
+
type SolidColor = import('./dist').SolidColor;
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
168
|
+
/**
|
|
169
|
+
* This type is added for backward compatibility and will be removed in the future.
|
|
170
|
+
* Import the same type from '@lightspeed/crane-api' directly.
|
|
171
|
+
*/
|
|
172
|
+
type GradientColor = import('./dist').GradientColor;
|
|
172
173
|
|
|
173
174
|
interface TextDesignData {
|
|
174
|
-
font: string |
|
|
175
|
-
size: number |
|
|
175
|
+
font: string | undefined;
|
|
176
|
+
size: number | undefined;
|
|
176
177
|
bold: boolean | undefined;
|
|
177
178
|
italic: boolean | undefined;
|
|
178
|
-
color: Color |
|
|
179
|
+
color: Color | undefined;
|
|
179
180
|
visible: boolean;
|
|
180
181
|
}
|
|
181
182
|
|
|
@@ -191,15 +192,15 @@ type CapitalizationType
|
|
|
191
192
|
interface Frame {
|
|
192
193
|
visible: boolean;
|
|
193
194
|
width: number | undefined;
|
|
194
|
-
color: Color |
|
|
195
|
+
color: Color | undefined;
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
interface LogoDesignData {
|
|
198
|
-
font: string |
|
|
199
|
-
size: number |
|
|
199
|
+
font: string | undefined;
|
|
200
|
+
size: number | undefined;
|
|
200
201
|
bold: boolean | undefined;
|
|
201
202
|
italic: boolean | undefined;
|
|
202
|
-
color: Color |
|
|
203
|
+
color: Color | undefined;
|
|
203
204
|
visible: boolean;
|
|
204
205
|
spacing: number | undefined;
|
|
205
206
|
capitalization: CapitalizationType | undefined;
|
|
@@ -223,17 +224,15 @@ type ButtonStyle
|
|
|
223
224
|
|
|
224
225
|
interface ButtonDesignData {
|
|
225
226
|
appearance: ButtonAppearance | undefined;
|
|
226
|
-
font: string |
|
|
227
|
+
font: string | undefined;
|
|
227
228
|
size: ButtonSize | undefined;
|
|
228
229
|
style: ButtonStyle | undefined;
|
|
229
|
-
color: Color |
|
|
230
|
+
color: Color | undefined;
|
|
230
231
|
visible: boolean;
|
|
231
232
|
}
|
|
232
233
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
| 'gradient'
|
|
236
|
-
| 'none';
|
|
234
|
+
declare const OverlayType: typeof import('./dist')['OverlayType'];
|
|
235
|
+
type OverlayType = import('./dist')['OverlayType'];
|
|
237
236
|
|
|
238
237
|
interface Overlay {
|
|
239
238
|
type: OverlayType | undefined;
|