@alanizcreative/formation-static 1.3.0-beta.29 → 1.3.0-beta.31

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.
Files changed (59) hide show
  1. package/cjs/components/Navigation/Navigation.js +1 -1
  2. package/cjs/config/configTypes.d.ts +3 -1
  3. package/cjs/contentful/contentfulData.d.ts +2 -2
  4. package/cjs/contentful/contentfulData.js +1 -1
  5. package/cjs/contentful/contentfulDataNormal.js +1 -1
  6. package/cjs/contentful/contentfulDataTypes.d.ts +15 -10
  7. package/cjs/global/globalTypes.d.ts +5 -3
  8. package/cjs/local/localData.js +1 -1
  9. package/cjs/render/render.js +1 -1
  10. package/cjs/render/renderInline.js +1 -1
  11. package/cjs/render/renderTypes.d.ts +16 -15
  12. package/cjs/serverless/Ajax/Ajax.js +1 -1
  13. package/cjs/serverless/Contact/Contact.js +1 -1
  14. package/cjs/serverless/Preview/Preview.js +1 -1
  15. package/cjs/serverless/serverlessTypes.d.ts +3 -4
  16. package/cjs/store/store.js +1 -1
  17. package/cjs/store/storeTypes.d.ts +13 -22
  18. package/cjs/utils/archive/archive.d.ts +9 -6
  19. package/cjs/utils/archive/archive.js +1 -1
  20. package/cjs/utils/archive/archiveTypes.d.ts +11 -0
  21. package/cjs/utils/link/link.js +1 -1
  22. package/cjs/utils/link/linkTypes.d.ts +3 -6
  23. package/cjs/utils/shortcode/shortcode.d.ts +1 -1
  24. package/cjs/utils/shortcode/shortcode.js +1 -1
  25. package/cjs/utils/shortcode/shortcodeTypes.d.ts +1 -1
  26. package/cjs/utils/tag/tag.js +1 -1
  27. package/cjs/utils/tag/tagTypes.d.ts +0 -1
  28. package/cjs/wordpress/wordpressData.js +1 -1
  29. package/cjs/wordpress/wordpressDataNormal.js +1 -1
  30. package/lib/components/Navigation/Navigation.js +1 -1
  31. package/lib/config/configTypes.d.ts +3 -1
  32. package/lib/contentful/contentfulData.d.ts +2 -2
  33. package/lib/contentful/contentfulData.js +1 -1
  34. package/lib/contentful/contentfulDataNormal.js +1 -1
  35. package/lib/contentful/contentfulDataTypes.d.ts +15 -10
  36. package/lib/global/globalTypes.d.ts +5 -3
  37. package/lib/local/localData.js +1 -1
  38. package/lib/render/render.js +1 -1
  39. package/lib/render/renderInline.js +1 -1
  40. package/lib/render/renderTypes.d.ts +16 -15
  41. package/lib/serverless/Ajax/Ajax.js +1 -1
  42. package/lib/serverless/Contact/Contact.js +1 -1
  43. package/lib/serverless/Preview/Preview.js +1 -1
  44. package/lib/serverless/serverlessTypes.d.ts +3 -4
  45. package/lib/store/store.js +1 -1
  46. package/lib/store/storeTypes.d.ts +13 -22
  47. package/lib/utils/archive/archive.d.ts +9 -6
  48. package/lib/utils/archive/archive.js +1 -1
  49. package/lib/utils/archive/archiveTypes.d.ts +11 -0
  50. package/lib/utils/link/link.js +1 -1
  51. package/lib/utils/link/linkTypes.d.ts +3 -6
  52. package/lib/utils/shortcode/shortcode.d.ts +1 -1
  53. package/lib/utils/shortcode/shortcode.js +1 -1
  54. package/lib/utils/shortcode/shortcodeTypes.d.ts +1 -1
  55. package/lib/utils/tag/tag.js +1 -1
  56. package/lib/utils/tag/tagTypes.d.ts +0 -1
  57. package/lib/wordpress/wordpressData.js +1 -1
  58. package/lib/wordpress/wordpressDataNormal.js +1 -1
  59. package/package.json +1 -1
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Navigation=void 0;const link_js_1=require("../../utils/link/link.js"),array_js_1=require("../../utils/array/array.js"),object_js_1=require("../../utils/object/object.js"),string_js_1=require("../../utils/string/string.js"),function_js_1=require("../../utils/function/function.js"),number_js_1=require("../../utils/number/number.js"),contentType_js_1=require("../../utils/contentType/contentType.js"),store_js_1=require("../../store/store.js");class Navigation{navigations=[];items=[];currentLink="";currentType=[];init=!1;#itemsById=new Map;#navigationsByLocation=new Map;constructor(props){this.init=this.#initialize(props)}#initialize(props){if(!(0,object_js_1.isObjectStrict)(props))return!1;const{navigations:navigations,items:items,currentLink:currentLink,currentType:currentType}=props;if(!(0,array_js_1.isArrayStrict)(navigations)||!(0,array_js_1.isArrayStrict)(items))return!1;this.navigations=navigations,this.items=items,this.currentLink=(0,string_js_1.isStringStrict)(currentLink)?currentLink:"";const typesArr=(0,array_js_1.isArrayStrict)(currentType)?currentType:[currentType];return this.currentType=typesArr.map((type=>(0,contentType_js_1.normalizeContentType)(type))),this.items.forEach((item=>{item&&this.#itemsById.set(item.id,item)})),this.items.forEach((item=>{const info=this.#getItemInfo(item);info&&this.#itemsById.set(info.id,info)})),this.navigations.forEach((nav=>{if(!(0,object_js_1.isObjectStrict)(nav))return;const{title:title,location:location,items:items=[]}=nav,locations=(0,array_js_1.isArrayStrict)(location)?location:[location];(0,string_js_1.isStringStrict)(title)&&(0,array_js_1.isArrayStrict)(items)&&locations.forEach((loc=>{this.#navigationsByLocation.set(loc,{title:title,items:items})}))})),!0}#getItemInfo(item){if(!(0,object_js_1.isObjectStrict)(item))return;const{id:id,title:title,link:link,internalLink:internalLink,externalLink:externalLink,children:children}=item;let external=!1;(0,string_js_1.isStringStrict)(externalLink)&&(external=!0);const props={id:id,title:title,link:(0,string_js_1.isStringStrict)(link)?link:(0,link_js_1.getLink)(internalLink,externalLink),external:external};(0,string_js_1.isStringStrict)(props.link)&&!external&&(props.current=props.link===this.currentLink);const internalId=internalLink?.id;if((0,string_js_1.isStringStrict)(internalId)){let isArchiveCurrent=!1;for(const type of this.currentType){if(internalId===(0,store_js_1.getStoreItem)("archiveMeta")[type]?.id){isArchiveCurrent=!0;break}}props.archiveCurrent=isArchiveCurrent}let descendentCurrent=!1;if((0,array_js_1.isArrayStrict)(children)){const storeChildren=[];descendentCurrent=this.#recurseItemChildren(children,storeChildren),props.children=storeChildren}return descendentCurrent&&(props.descendentCurrent=descendentCurrent),{...item,...props}}#recurseItemChildren(children,output){let childCurrent=!1;return children.forEach((child=>{const info=this.#getItemInfo(this.#itemsById.get(child?.id));if(!info)return;const{current:current=!1,archiveCurrent:archiveCurrent=!1}=info;(current||archiveCurrent)&&(childCurrent=!0),output.push(info)})),childCurrent}#getItems(items=[]){const resItems=[];return items.forEach((item=>{if(!(0,object_js_1.isObjectStrict)(item))return;const{id:id}=item,storedItem=this.#itemsById.get(id);storedItem&&resItems.push(storedItem)})),resItems}#recurseOutput=(items,output,args,depth=0,maxDepth)=>{if((0,number_js_1.isNumber)(maxDepth)&&depth>maxDepth)return;const dataAttr=(0,string_js_1.isStringStrict)(args.dataAttr)?args.dataAttr:"data-nav",depthAttr=args.depthAttr?` ${dataAttr}-depth="${depth}"`:"",listFilterArgs={args:args,output:output,items:items,depth:depth};(0,function_js_1.isFunction)(args.filterBeforeList)&&args.filterBeforeList(listFilterArgs);const listClasses=(0,string_js_1.isStringStrict)(args.listClass)?` class="${args.listClass}"`:"",listAttrs=(0,string_js_1.isStringStrict)(args.listAttr)?` ${args.listAttr}`:"",listTag=(0,string_js_1.isStringStrict)(args.listTag)?args.listTag:"ul";output.html+=`<${listTag}${depthAttr}${listClasses}${listAttrs}>`,items.forEach(((item,index)=>{const{title:title,link:link,external:external=!1,children:children,current:current=!1,descendentCurrent:descendentCurrent=!1,archiveCurrent:archiveCurrent=!1}=item,filterArgs={args:args,item:item,output:output,index:index,items:items,depth:depth};(0,function_js_1.isFunction)(args.filterBeforeItem)&&args.filterBeforeItem(filterArgs);const itemClasses=(0,string_js_1.isStringStrict)(args.itemClass)?` class="${args.itemClass}"`:"",itemTag=(0,string_js_1.isStringStrict)(args.itemTag)?args.itemTag:"li";let itemAttrs=(0,string_js_1.isStringStrict)(args.itemAttr)?` ${args.itemAttr}`:"";current&&(itemAttrs+=` ${dataAttr}-current`),descendentCurrent&&(itemAttrs+=` ${dataAttr}-descendent-current`),archiveCurrent&&(itemAttrs+=` ${dataAttr}-archive-current`),output.html+=`<${itemTag}${depthAttr}${itemClasses}${itemAttrs}>`,(0,function_js_1.isFunction)(args.filterBeforeLink)&&args.filterBeforeLink(filterArgs);const linkClassesArr=[];(0,string_js_1.isStringStrict)(args.linkClass)&&linkClassesArr.push(args.linkClass),!external&&(0,string_js_1.isStringStrict)(args.internalLinkClass)&&linkClassesArr.push(args.internalLinkClass);const hasLink=(0,string_js_1.isStringStrict)(link),linkClasses=linkClassesArr.length>0?` class="${linkClassesArr.join(" ")}"`:"",linkAttrsArr=[hasLink?`href="${link}"`:'type="button"'];(0,string_js_1.isStringStrict)(args.linkAttr)&&linkAttrsArr.push(args.linkAttr),current&&(linkAttrsArr.push(`${dataAttr}-current`),hasLink&&linkAttrsArr.push('aria-current="page"')),descendentCurrent&&linkAttrsArr.push(`${dataAttr}-descendent-current`),archiveCurrent&&linkAttrsArr.push(`${dataAttr}-archive-current`);const linkAttrs=` ${linkAttrsArr.join(" ")}`,linkTag=hasLink?"a":"button";output.html+=`<${linkTag}${depthAttr}${linkClasses}${linkAttrs}>`,(0,function_js_1.isFunction)(args.filterBeforeLinkText)&&args.filterBeforeLinkText(filterArgs),output.html+=title,(0,function_js_1.isFunction)(args.filterAfterLinkText)&&args.filterAfterLinkText(filterArgs),output.html+=`</${linkTag}>`,(0,function_js_1.isFunction)(args.filterAfterLink)&&args.filterAfterLink(filterArgs),(0,array_js_1.isArrayStrict)(children)&&this.#recurseOutput(children,output,args,depth+1,maxDepth),output.html+=`</${itemTag}>`,(0,function_js_1.isFunction)(args.filterAfterItem)&&args.filterAfterItem(filterArgs)})),output.html+=`</${listTag}>`,(0,function_js_1.isFunction)(args.filterAfterList)&&args.filterAfterList(listFilterArgs)};getOutput(location,args,maxDepth){const nav=this.#navigationsByLocation.get(location);if(!nav)return"";const items=nav.items,normalizedItems=this.#getItems(items);if(!normalizedItems.length)return"";args=Object.assign({listTag:"",listClass:"",listAttr:"",itemTag:"",itemClass:"",itemAttr:"",linkClass:"",internalLinkClass:"",linkAttr:"",dataAttr:"",depthAttr:!1,filterBeforeList:()=>{},filterAfterList:()=>{},filterBeforeItem:()=>{},filterAfterItem:()=>{},filterBeforeLink:()=>{},filterAfterLink:()=>{},filterBeforeLinkText:()=>{},filterAfterLinkText:()=>{}},(0,object_js_1.isObjectStrict)(args)?args:{});const output={html:""};return this.#recurseOutput(normalizedItems,output,args,0,maxDepth),output.html}getBreadcrumbs(items,current,args){if(!(0,array_js_1.isArrayStrict)(items))return"";args=Object.assign({listClass:"",listAttr:"",itemClass:"",itemAttr:"",linkClass:"",internalLinkClass:"",linkAttr:"",currentClass:"",currentLabel:"",a11yClass:"a-hide-vis",dataAttr:"",filterBeforeLink:()=>{},filterAfterLink:()=>{}},(0,object_js_1.isObjectStrict)(args)?args:{});const dataAttr=(0,string_js_1.isStringStrict)(args.dataAttr)?args.dataAttr:"data-nav",listClasses=(0,string_js_1.isStringStrict)(args.listClass)?` class="${args.listClass}"`:"",listAttrs=(0,string_js_1.isStringStrict)(args.listAttr)?` ${args.listAttr}`:"",filteredItems=items.filter((item=>!!(0,string_js_1.isStringStrict)(item.title)&&(!!(0,string_js_1.isString)(item.slug)&&(item.slug=(0,link_js_1.getSlug)({id:item.id,slug:item.slug,contentType:item.contentType,pageData:item.internalLink}),!0)))),itemClasses=(0,string_js_1.isStringStrict)(args.itemClass)?` class="${args.itemClass}"`:"",itemAttrs=(0,string_js_1.isStringStrict)(args.itemAttr)?` ${args.itemAttr}`:"",lastItemIndex=filteredItems.length-1,itemsArr=filteredItems.map(((item,index)=>{const{title:title,slug:slug}=item,link=(0,link_js_1.getPermalink)(slug),output={html:""},lastLevel=lastItemIndex===index,filterArgs={output:output,lastLevel:lastLevel};output.html+=`<li${itemClasses}${itemAttrs}${lastLevel?` ${dataAttr}-last`:""}>`,(0,function_js_1.isFunction)(args.filterBeforeLink)&&args.filterBeforeLink(filterArgs);const linkClassesArr=[];(0,string_js_1.isStringStrict)(args.linkClass)&&linkClassesArr.push(args.linkClass),(0,string_js_1.isStringStrict)(args.internalLinkClass)&&linkClassesArr.push(args.internalLinkClass);const linkClasses=linkClassesArr.length>0?` class="${linkClassesArr.join(" ")}"`:"",linkAttrs=(0,string_js_1.isStringStrict)(args.linkAttr)?` ${args.linkAttr}`:"";return output.html+=`<a${linkClasses} href="${link}"${linkAttrs}>${title}</a>`,(0,function_js_1.isFunction)(args.filterAfterLink)&&args.filterAfterLink(filterArgs),output.html+="</li>",output.html})),currentLabel=(0,string_js_1.isStringStrict)(args.currentLabel)?args.currentLabel:"(current page)",currentClasses=(0,string_js_1.isStringStrict)(args.currentClass)?` class="${args.currentClass}"`:"",a11yClasses=(0,string_js_1.isStringStrict)(args.a11yClass)?` class="${args.a11yClass}"`:"",currentItem=(0,string_js_1.isStringStrict)(current)?`\n <li${itemClasses}${itemAttrs} ${dataAttr}-current>\n <span${currentClasses}>${current}<span${a11yClasses}> ${currentLabel}</span></span>\n </li>\n `:"";return`\n <ol${listClasses}${listAttrs}>\n ${itemsArr.join("")}\n ${currentItem}\n </ol>\n `}getItemsById(){return this.#itemsById}getNavigationsByLocation(){return this.#navigationsByLocation}getNavigationByLocation(location){return this.#navigationsByLocation.get(location)}}exports.Navigation=Navigation;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Navigation=void 0;const link_js_1=require("../../utils/link/link.js"),array_js_1=require("../../utils/array/array.js"),object_js_1=require("../../utils/object/object.js"),string_js_1=require("../../utils/string/string.js"),function_js_1=require("../../utils/function/function.js"),number_js_1=require("../../utils/number/number.js"),contentType_js_1=require("../../utils/contentType/contentType.js"),archive_js_1=require("../../utils/archive/archive.js");class Navigation{navigations=[];items=[];currentLink="";currentType=[];init=!1;#itemsById=new Map;#navigationsByLocation=new Map;constructor(props){this.init=this.#initialize(props)}#initialize(props){if(!(0,object_js_1.isObjectStrict)(props))return!1;const{navigations:navigations,items:items,currentLink:currentLink,currentType:currentType}=props;return!(!(0,array_js_1.isArrayStrict)(navigations)||!(0,array_js_1.isArrayStrict)(items))&&(this.navigations=navigations,this.items=items,this.currentLink=(0,string_js_1.isStringStrict)(currentLink)?currentLink:"",this.currentType=((0,array_js_1.isArrayStrict)(currentType)?currentType:[currentType]).map((type=>(0,contentType_js_1.normalizeContentType)(type))),this.items.forEach((item=>{item&&this.#itemsById.set(item.id,item)})),this.items.forEach((item=>{const info=this.#getItemInfo(item);info&&this.#itemsById.set(info.id,info)})),this.navigations.forEach((nav=>{if(!(0,object_js_1.isObjectStrict)(nav))return;const{title:title,location:location,items:items=[]}=nav,locations=(0,array_js_1.isArrayStrict)(location)?location:[location];(0,string_js_1.isStringStrict)(title)&&(0,array_js_1.isArrayStrict)(items)&&locations.forEach((loc=>{this.#navigationsByLocation.set(loc,{title:title,items:items})}))})),!0)}#getItemInfo(item){if(!(0,object_js_1.isObjectStrict)(item))return;const{id:id,title:title,link:link,internalLink:internalLink,externalLink:externalLink,children:children}=item;let external=!1;(0,string_js_1.isStringStrict)(externalLink)&&(external=!0);const props={id:id,title:title,link:(0,string_js_1.isStringStrict)(link)?link:(0,link_js_1.getLink)(internalLink,externalLink),external:external};(0,string_js_1.isStringStrict)(props.link)&&!external&&(props.current=props.link===this.currentLink);const internalId=internalLink?.id;if((0,string_js_1.isStringStrict)(internalId)){let isArchiveCurrent=!1;for(const type of this.currentType){if(internalId===(0,archive_js_1.getArchiveMeta)(type,internalLink?.locale).id){isArchiveCurrent=!0;break}}props.archiveCurrent=isArchiveCurrent}let descendentCurrent=!1;if((0,array_js_1.isArrayStrict)(children)){const storeChildren=[];descendentCurrent=this.#recurseItemChildren(children,storeChildren),props.children=storeChildren}return descendentCurrent&&(props.descendentCurrent=descendentCurrent),{...item,...props}}#recurseItemChildren(children,output){let childCurrent=!1;return children.forEach((child=>{const info=this.#getItemInfo(this.#itemsById.get(child?.id));if(!info)return;const{current:current=!1,archiveCurrent:archiveCurrent=!1}=info;(current||archiveCurrent)&&(childCurrent=!0),output.push(info)})),childCurrent}#getItems(items=[]){const resItems=[];return items.forEach((item=>{if(!(0,object_js_1.isObjectStrict)(item))return;const{id:id}=item,storedItem=this.#itemsById.get(id);storedItem&&resItems.push(storedItem)})),resItems}#recurseOutput=(items,output,args,depth=0,maxDepth)=>{if((0,number_js_1.isNumber)(maxDepth)&&depth>maxDepth)return;const dataAttr=(0,string_js_1.isStringStrict)(args.dataAttr)?args.dataAttr:"data-nav",depthAttr=args.depthAttr?` ${dataAttr}-depth="${depth}"`:"",listFilterArgs={args:args,output:output,items:items,depth:depth};(0,function_js_1.isFunction)(args.filterBeforeList)&&args.filterBeforeList(listFilterArgs);const listClasses=(0,string_js_1.isStringStrict)(args.listClass)?` class="${args.listClass}"`:"",listAttrs=(0,string_js_1.isStringStrict)(args.listAttr)?` ${args.listAttr}`:"",listTag=(0,string_js_1.isStringStrict)(args.listTag)?args.listTag:"ul";output.html+=`<${listTag}${depthAttr}${listClasses}${listAttrs}>`,items.forEach(((item,index)=>{const{title:title,link:link,external:external=!1,children:children,current:current=!1,descendentCurrent:descendentCurrent=!1,archiveCurrent:archiveCurrent=!1}=item,filterArgs={args:args,item:item,output:output,index:index,items:items,depth:depth};(0,function_js_1.isFunction)(args.filterBeforeItem)&&args.filterBeforeItem(filterArgs);const itemClasses=(0,string_js_1.isStringStrict)(args.itemClass)?` class="${args.itemClass}"`:"",itemTag=(0,string_js_1.isStringStrict)(args.itemTag)?args.itemTag:"li";let itemAttrs=(0,string_js_1.isStringStrict)(args.itemAttr)?` ${args.itemAttr}`:"";current&&(itemAttrs+=` ${dataAttr}-current`),descendentCurrent&&(itemAttrs+=` ${dataAttr}-descendent-current`),archiveCurrent&&(itemAttrs+=` ${dataAttr}-archive-current`),output.html+=`<${itemTag}${depthAttr}${itemClasses}${itemAttrs}>`,(0,function_js_1.isFunction)(args.filterBeforeLink)&&args.filterBeforeLink(filterArgs);const linkClassesArr=[];(0,string_js_1.isStringStrict)(args.linkClass)&&linkClassesArr.push(args.linkClass),!external&&(0,string_js_1.isStringStrict)(args.internalLinkClass)&&linkClassesArr.push(args.internalLinkClass);const hasLink=(0,string_js_1.isStringStrict)(link),linkClasses=linkClassesArr.length>0?` class="${linkClassesArr.join(" ")}"`:"",linkAttrsArr=[hasLink?`href="${link}"`:'type="button"'];(0,string_js_1.isStringStrict)(args.linkAttr)&&linkAttrsArr.push(args.linkAttr),current&&(linkAttrsArr.push(`${dataAttr}-current`),hasLink&&linkAttrsArr.push('aria-current="page"')),descendentCurrent&&linkAttrsArr.push(`${dataAttr}-descendent-current`),archiveCurrent&&linkAttrsArr.push(`${dataAttr}-archive-current`);const linkAttrs=` ${linkAttrsArr.join(" ")}`,linkTag=hasLink?"a":"button";output.html+=`<${linkTag}${depthAttr}${linkClasses}${linkAttrs}>`,(0,function_js_1.isFunction)(args.filterBeforeLinkText)&&args.filterBeforeLinkText(filterArgs),output.html+=title,(0,function_js_1.isFunction)(args.filterAfterLinkText)&&args.filterAfterLinkText(filterArgs),output.html+=`</${linkTag}>`,(0,function_js_1.isFunction)(args.filterAfterLink)&&args.filterAfterLink(filterArgs),(0,array_js_1.isArrayStrict)(children)&&this.#recurseOutput(children,output,args,depth+1,maxDepth),output.html+=`</${itemTag}>`,(0,function_js_1.isFunction)(args.filterAfterItem)&&args.filterAfterItem(filterArgs)})),output.html+=`</${listTag}>`,(0,function_js_1.isFunction)(args.filterAfterList)&&args.filterAfterList(listFilterArgs)};getOutput(location,args,maxDepth){const nav=this.#navigationsByLocation.get(location);if(!nav)return"";const items=nav.items,normalizedItems=this.#getItems(items);if(!normalizedItems.length)return"";args=Object.assign({listTag:"",listClass:"",listAttr:"",itemTag:"",itemClass:"",itemAttr:"",linkClass:"",internalLinkClass:"",linkAttr:"",dataAttr:"",depthAttr:!1,filterBeforeList:()=>{},filterAfterList:()=>{},filterBeforeItem:()=>{},filterAfterItem:()=>{},filterBeforeLink:()=>{},filterAfterLink:()=>{},filterBeforeLinkText:()=>{},filterAfterLinkText:()=>{}},(0,object_js_1.isObjectStrict)(args)?args:{});const output={html:""};return this.#recurseOutput(normalizedItems,output,args,0,maxDepth),output.html}getBreadcrumbs(items,current,args){if(!(0,array_js_1.isArrayStrict)(items))return"";args=Object.assign({listClass:"",listAttr:"",itemClass:"",itemAttr:"",linkClass:"",internalLinkClass:"",linkAttr:"",currentClass:"",currentLabel:"",a11yClass:"a-hide-vis",dataAttr:"",filterBeforeLink:()=>{},filterAfterLink:()=>{}},(0,object_js_1.isObjectStrict)(args)?args:{});const dataAttr=(0,string_js_1.isStringStrict)(args.dataAttr)?args.dataAttr:"data-nav",listClasses=(0,string_js_1.isStringStrict)(args.listClass)?` class="${args.listClass}"`:"",listAttrs=(0,string_js_1.isStringStrict)(args.listAttr)?` ${args.listAttr}`:"",filteredItems=items.filter((item=>!!(0,string_js_1.isStringStrict)(item.title)&&(!!(0,string_js_1.isString)(item.slug)&&(item.slug=(0,link_js_1.getSlug)({id:item.id,slug:item.slug,contentType:item.contentType,itemData:item.internalLink}),!0)))),itemClasses=(0,string_js_1.isStringStrict)(args.itemClass)?` class="${args.itemClass}"`:"",itemAttrs=(0,string_js_1.isStringStrict)(args.itemAttr)?` ${args.itemAttr}`:"",lastItemIndex=filteredItems.length-1,itemsArr=filteredItems.map(((item,index)=>{const{title:title,slug:slug}=item,link=(0,link_js_1.getPermalink)(slug),output={html:""},lastLevel=lastItemIndex===index,filterArgs={output:output,lastLevel:lastLevel};output.html+=`<li${itemClasses}${itemAttrs}${lastLevel?` ${dataAttr}-last`:""}>`,(0,function_js_1.isFunction)(args.filterBeforeLink)&&args.filterBeforeLink(filterArgs);const linkClassesArr=[];(0,string_js_1.isStringStrict)(args.linkClass)&&linkClassesArr.push(args.linkClass),(0,string_js_1.isStringStrict)(args.internalLinkClass)&&linkClassesArr.push(args.internalLinkClass);const linkClasses=linkClassesArr.length>0?` class="${linkClassesArr.join(" ")}"`:"",linkAttrs=(0,string_js_1.isStringStrict)(args.linkAttr)?` ${args.linkAttr}`:"";return output.html+=`<a${linkClasses} href="${link}"${linkAttrs}>${title}</a>`,(0,function_js_1.isFunction)(args.filterAfterLink)&&args.filterAfterLink(filterArgs),output.html+="</li>",output.html})),currentLabel=(0,string_js_1.isStringStrict)(args.currentLabel)?args.currentLabel:"(current page)",currentClasses=(0,string_js_1.isStringStrict)(args.currentClass)?` class="${args.currentClass}"`:"",a11yClasses=(0,string_js_1.isStringStrict)(args.a11yClass)?` class="${args.a11yClass}"`:"",currentItem=(0,string_js_1.isStringStrict)(current)?`\n <li${itemClasses}${itemAttrs} ${dataAttr}-current>\n <span${currentClasses}>${current}<span${a11yClasses}> ${currentLabel}</span></span>\n </li>\n `:"";return`\n <ol${listClasses}${listAttrs}>\n ${itemsArr.join("")}\n ${currentItem}\n </ol>\n `}getItemsById(){return this.#itemsById}getNavigationsByLocation(){return this.#navigationsByLocation}getNavigationByLocation(location){return this.#navigationsByLocation.get(location)}}exports.Navigation=Navigation;
@@ -15,13 +15,15 @@ export interface ConfigEnv {
15
15
  export interface ConfigCms {
16
16
  name: string;
17
17
  space: string;
18
- ssl?: boolean;
19
18
  prodUser: string;
20
19
  prodCredential: string;
21
20
  prodHost: string;
22
21
  devUser: string;
23
22
  devCredential: string;
24
23
  devHost: string;
24
+ ssl?: boolean;
25
+ env?: string;
26
+ locales?: string[];
25
27
  }
26
28
  export interface ConfigLocal {
27
29
  dir: string;
@@ -1,5 +1,5 @@
1
1
  import type { ContentfulDataParams, AllContentfulDataArgs } from './contentfulDataTypes.js';
2
- import type { RenderAllData, RenderItem } from '../render/renderTypes.js';
3
- declare const getContentfulData: (key: string, params?: ContentfulDataParams) => Promise<RenderItem[]>;
2
+ import type { RenderAllData, RenderDataMeta, RenderItem } from '../render/renderTypes.js';
3
+ declare const getContentfulData: (key: string, params?: ContentfulDataParams, meta?: RenderDataMeta) => Promise<RenderItem[]>;
4
4
  declare const getAllContentfulData: (args?: AllContentfulDataArgs) => Promise<RenderAllData | undefined>;
5
5
  export { getContentfulData, getAllContentfulData };
@@ -1 +1 @@
1
- "use strict";var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getAllContentfulData=exports.getContentfulData=void 0;const contentful_resolve_response_1=__importDefault(require("contentful-resolve-response")),ResponseError_js_1=require("../utils/ResponseError/ResponseError.js"),filter_js_1=require("../utils/filter/filter.js"),object_js_1=require("../utils/object/object.js"),string_js_1=require("../utils/string/string.js"),array_js_1=require("../utils/array/array.js"),config_js_1=require("../config/config.js"),store_js_1=require("../store/store.js"),contentfulDataNormal_js_1=require("./contentfulDataNormal.js"),getContentfulData=async(key,params={})=>{if(!(0,string_js_1.isStringStrict)(key))throw new Error("No key");if(config_js_1.config.env.cache){const cacheDataFilterArgs={key:key,type:"get"},cacheData=await(0,filter_js_1.applyFilters)("cacheData",void 0,cacheDataFilterArgs,!0);if((0,object_js_1.isObject)(cacheData))return structuredClone(cacheData)}const{space:space,devCredential:devCredential,prodCredential:prodCredential,devHost:devHost,prodHost:prodHost}=config_js_1.config.cms;let accessToken=devCredential,host=devHost;if(config_js_1.config.env.prod&&(accessToken=prodCredential,host=prodHost),!(0,string_js_1.isStringStrict)(space)||!(0,string_js_1.isStringStrict)(accessToken)||!(0,string_js_1.isStringStrict)(host))throw new Error("No credentials");let url=`https://${host}/spaces/${space}/environments/master/entries?access_token=${accessToken}`;for(const[key,value]of Object.entries(params))url+=`&${key}=${value.toString()}`;const resp=await fetch(url),data=await resp.json();if(!resp.ok)throw new ResponseError_js_1.ResponseError("Bad fetch response",resp);const resolvedData=(0,contentful_resolve_response_1.default)(data),newData=(0,contentfulDataNormal_js_1.normalizeContentfulData)(resolvedData.items);if(config_js_1.config.env.cache){const cacheDataFilterArgs={key:key,type:"set",data:data};await(0,filter_js_1.applyFilters)("cacheData",newData,cacheDataFilterArgs,!0)}return newData};exports.getContentfulData=getContentfulData;const getAllContentfulData=async(args={})=>{const{serverlessData:serverlessData,previewData:previewData}=args;let allData={navigationItem:[],navigation:[],redirect:[],content:{page:[]}};const isServerless=null!=serverlessData,isPreview=null!=previewData,contentfulDataFilterArgs={serverlessData:serverlessData,previewData:previewData};if(isServerless||isPreview){let contentType="",id="";if(isServerless){const item=(0,store_js_1.getStoreItem)("slugs")[serverlessData.path];(0,object_js_1.isObjectStrict)(item)&&(id=(0,string_js_1.isStringStrict)(item.id)?item.id:"",contentType=(0,string_js_1.isStringStrict)(item.contentType)?item.contentType:"")}if(isPreview&&(id=previewData.id,contentType=previewData.contentType),id){const key=`serverless_${id}_${contentType}`,params={"sys.id":id,include:10},data=await getContentfulData(key,params);(0,array_js_1.isArray)(data)&&(allData.content[contentType]=data)}}if(!isServerless){const partial=config_js_1.config.partialTypes;for(const contentType of partial){allData[contentType]=[];const key=`all_${contentType}`,params={content_type:contentType};let data=await getContentfulData(key,params);data=(0,filter_js_1.applyFilters)("contentfulData",data,contentfulDataFilterArgs),(0,array_js_1.isArray)(data)&&(allData[contentType]=data)}}if(!isServerless&&!isPreview){const whole=config_js_1.config.wholeTypes;for(const contentType of whole){allData.content[contentType]=[];const key=`all_${contentType}`,params={content_type:contentType,include:10};let data=await getContentfulData(key,params);data=(0,filter_js_1.applyFilters)("contentfulData",data,contentfulDataFilterArgs),(0,array_js_1.isArray)(data)&&(allData.content[contentType]=data)}}return allData=(0,filter_js_1.applyFilters)("allData",allData,{type:"contentful",serverlessData:serverlessData,previewData:previewData}),allData};exports.getAllContentfulData=getAllContentfulData;
1
+ "use strict";var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getAllContentfulData=exports.getContentfulData=void 0;const contentful_resolve_response_1=__importDefault(require("contentful-resolve-response")),filter_js_1=require("../utils/filter/filter.js"),object_js_1=require("../utils/object/object.js"),string_js_1=require("../utils/string/string.js"),array_js_1=require("../utils/array/array.js"),config_js_1=require("../config/config.js"),store_js_1=require("../store/store.js"),contentfulDataNormal_js_1=require("./contentfulDataNormal.js"),getContentfulData=async(key,params,meta)=>{if(!(0,string_js_1.isStringStrict)(key))throw new Error("No key");const hasMeta=(0,object_js_1.isObjectStrict)(meta);if(config_js_1.config.env.cache){const cacheDataFilterArgs={key:key,type:"get"},cacheData=await(0,filter_js_1.applyFilters)("cacheData",void 0,cacheDataFilterArgs,!0),cacheItems=cacheData?.items,cacheMeta=cacheData?.meta;if((0,object_js_1.isObjectStrict)(cacheMeta)&&hasMeta){const{total:total,limit:limit,skip:skip}=cacheMeta;meta.total=total,meta.limit=limit,meta.skip=skip}if((0,array_js_1.isArray)(cacheItems))return structuredClone(cacheItems)}const{space:space,devCredential:devCredential,prodCredential:prodCredential,devHost:devHost,prodHost:prodHost,env:env="master"}=config_js_1.config.cms;let accessToken=devCredential,host=devHost;if(config_js_1.config.env.prod&&(accessToken=prodCredential,host=prodHost),!(0,string_js_1.isStringStrict)(space)||!(0,string_js_1.isStringStrict)(accessToken)||!(0,string_js_1.isStringStrict)(host))throw new Error("No credentials");let url=`https://${host}/spaces/${space}/environments/${env}/entries?access_token=${accessToken}`;if((0,object_js_1.isObjectStrict)(params))for(const[key,value]of Object.entries(params))url+=`&${key}=${value.toString()}`;const resp=await fetch(url),data=await resp.json();if(!resp.ok){const message=(0,string_js_1.isStringStrict)(data.message)?data.message:"Bad fetch response";throw new Error(message,{cause:data})}if(hasMeta){const{total:total,limit:limit,skip:skip}=data;meta.total=total,meta.limit=limit,meta.skip=skip}const resolvedData=(0,contentful_resolve_response_1.default)(data),newData=(0,contentfulDataNormal_js_1.normalizeContentfulData)(resolvedData);if(config_js_1.config.env.cache){const cacheDataFilterArgs={key:key,type:"set",data:data};await(0,filter_js_1.applyFilters)("cacheData",{items:newData,meta:meta},cacheDataFilterArgs,!0)}return newData};exports.getContentfulData=getContentfulData;const getAllContentfulData=async args=>{const{serverlessData:serverlessData,previewData:previewData}=(0,object_js_1.isObjectStrict)(args)?args:{};let allData={navigationItem:[],navigation:[],content:{page:[]}};const isServerless=null!=serverlessData,isPreview=null!=previewData,contentfulDataFilterArgs={serverlessData:serverlessData,previewData:previewData},cmsLocales=config_js_1.config.cms.locales||[],defaultLocale=cmsLocales[0],paramLocales=isPreview?[]:[...cmsLocales];if(0===paramLocales.length&&paramLocales.push(""),isServerless||isPreview){let locale,contentType="",id="";if(isServerless){const item=(0,store_js_1.getStoreItem)("slugs")[serverlessData.path];(0,object_js_1.isObjectStrict)(item)&&(id=(0,string_js_1.isStringStrict)(item.id)?item.id:"",contentType=(0,string_js_1.isStringStrict)(item.contentType)?item.contentType:"",locale=(0,string_js_1.isStringStrict)(item.locale)?item.locale:"")}if(isPreview&&(id=previewData.id,contentType=previewData.contentType,locale=previewData.locale),id){const key=`serverless_${id}_${contentType}`,params={content_type:contentType,"sys.id":id,include:10};locale&&locale!==defaultLocale&&(params.locale=locale,paramLocales[0]=locale);const data=await getContentfulData(key,params);(0,array_js_1.isArray)(data)&&(allData.content[contentType]=data)}}if(!isServerless){const partial=config_js_1.config.partialTypes;for(const contentType of partial){const key=`all_${contentType}`;let data=[];for(const locale of paramLocales){const params={content_type:contentType};locale&&locale!==defaultLocale&&(params.locale=locale);let newData=await getContentfulData(key,params);newData=(0,filter_js_1.applyFilters)("contentfulData",newData,contentfulDataFilterArgs),(0,array_js_1.isArray)(newData)&&(data=[...data,...newData])}allData[contentType]=data}}if(!isServerless&&!isPreview){const whole=config_js_1.config.wholeTypes;for(const contentType of whole){const key=`all_${contentType}`;let data=[];for(const locale of paramLocales){const params={content_type:contentType,include:10};locale&&locale!==defaultLocale&&(params.locale=locale);let newData=await getContentfulData(key,params);newData=(0,filter_js_1.applyFilters)("contentfulData",newData,contentfulDataFilterArgs),(0,array_js_1.isArray)(newData)&&(data=[...data,...newData])}allData.content[contentType]=data}}return allData=(0,filter_js_1.applyFilters)("allData",allData,{type:"contentful",serverlessData:serverlessData,previewData:previewData}),allData};exports.getAllContentfulData=getAllContentfulData;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.normalizeContentfulData=void 0;const contentType_js_1=require("../utils/contentType/contentType.js"),array_js_1=require("../utils/array/array.js"),object_js_1=require("../utils/object/object.js"),string_js_1=require("../utils/string/string.js"),objectUtils_js_1=require("../utils/object/objectUtils.js"),number_js_1=require("../utils/number/number.js"),config_js_1=require("../config/config.js"),getTag=(type="text")=>{const tag={br:"br",hr:"hr",paragraph:"p",blockquote:"blockquote",bold:"b",italic:"i",underline:"u",superscript:"sup",subscript:"sub",code:"code",hyperlink:"a","entry-hyperlink":"a","asset-hyperlink":"a","heading-1":"h1","heading-2":"h2","heading-3":"h3","heading-4":"h4","heading-5":"h5","heading-6":"h6","list-item":"li","unordered-list":"ul","ordered-list":"ol",table:"table","table-row":"tr","table-cell":"td","table-header-cell":"th",text:""}[type];return(0,string_js_1.isString)(tag)?tag:""},normalizeRichText=items=>{const newItems=[];return items.forEach((item=>{if(!(0,object_js_1.isObjectStrict)(item))return;const{nodeType:nodeType,data:data,value:value,marks:marks,content:content}=item,tag=getTag(nodeType);let contentValue,link,internalLink;if((0,string_js_1.isStringStrict)(value)&&(contentValue=value,contentValue=contentValue.replace(/\n/g,"<br>"),(0,array_js_1.isArrayStrict)(marks))){const markTags=marks.map((m=>getTag(m.type)));contentValue=`${markTags.map((m=>`<${m}>`)).join("")}${value}${markTags.map((m=>`</${m}>`)).join("")}`}if((0,string_js_1.isStringStrict)(content)&&(contentValue=content),(0,array_js_1.isArrayStrict)(content)){const contentArr=normalizeRichText(content);contentArr.length>0&&(contentValue=contentArr)}if((0,object_js_1.isObjectStrict)(data)&&(link=(0,string_js_1.isString)(data.uri)?data.uri:"",(0,object_js_1.isObjectStrict)(data.target))){const target=data.target;"entry-hyperlink"===nodeType&&(internalLink=target);const url=target.fields?.file?.url;"asset-hyperlink"===nodeType&&(0,string_js_1.isString)(url)&&(link=url)}if(!contentValue)return;const newItem={content:contentValue};return(0,string_js_1.isStringStrict)(tag)&&(newItem.tag=tag),(0,string_js_1.isStringStrict)(link)&&(newItem.link=link),(0,object_js_1.isObjectStrict)(internalLink)&&(newItem.internalLink=normalizeItem(internalLink,[],!0)),newItems.push(newItem)})),newItems},normalizeFile=(file,fields)=>{const type=(0,string_js_1.isString)(file.contentType)?file.contentType:"",format=type?type.split("/")[1]:"";return{url:(0,string_js_1.isString)(file.url)?`https:${file.url}`:"",name:(0,string_js_1.isString)(file.fileName)?file.fileName:"",alt:(0,string_js_1.isString)(fields.description)?fields.description:"",width:(0,number_js_1.isNumber)(file.details?.image?.width)?file.details.image.width:0,height:(0,number_js_1.isNumber)(file.details?.image?.height)?file.details.image.height:0,size:(0,number_js_1.isNumber)(file.details?.size)?file.details.size:0,format:"jpeg"===format?"jpg":format,type:type}},normalizeItem=(item,data,isInternalLink=!1)=>{let newItem={};const itemCopy={...item};(0,string_js_1.isString)(itemCopy.sys?.id)&&(newItem.id=itemCopy.sys.id);let type="";if((0,string_js_1.isString)(itemCopy.sys?.type)&&(type=itemCopy.sys.type),(0,string_js_1.isString)(itemCopy.sys?.contentType?.sys?.id)&&(type=itemCopy.sys.contentType.sys.id),type&&"Link"!==type&&(newItem.contentType=(0,contentType_js_1.normalizeContentType)(type),(0,string_js_1.isString)(config_js_1.config.renderTypes[type])&&(newItem.renderType=config_js_1.config.renderTypes[type])),(0,array_js_1.isArrayStrict)(itemCopy.metadata?.tags)&&(newItem.metadata={tags:itemCopy.metadata.tags.map((t=>({id:(0,string_js_1.isString)(t.sys?.id)?t.sys.id:"",name:(0,string_js_1.isString)(t.sys?.name)?t.sys.name:""})))}),(0,object_js_1.isObjectStrict)(itemCopy.fields)){const fields=itemCopy.fields,file=fields.file;if((0,object_js_1.isObjectStrict)(file))return Object.assign(normalizeFile(file,fields),newItem);(0,objectUtils_js_1.getObjectKeys)(fields).forEach((prop=>{const field=fields[prop];if("content"!==prop||!isInternalLink)if((0,object_js_1.isObjectStrict)(field))if("document"===field.nodeType){const{content:content}=field;(0,array_js_1.isArrayStrict)(content)&&(newItem[prop]=content.map((c=>(0,object_js_1.isObjectStrict)(c)?normalizeItem(c,data,isInternalLink):c)))}else newItem[prop]=normalizeItem(field,data,"internalLink"===prop);else(0,array_js_1.isArrayStrict)(field)?newItem[prop]=field.map((f=>(0,object_js_1.isObjectStrict)(f)?normalizeItem(f,data,isInternalLink):f)):newItem[prop]=field}))}if((0,string_js_1.isString)(itemCopy.nodeType)){const nodeType=itemCopy.nodeType;if("embedded-entry-block"===nodeType||"embedded-asset-block"===nodeType){const content=(0,object_js_1.isObjectStrict)(itemCopy.data?.target)?itemCopy.data.target:item;newItem=normalizeItem(content,data,isInternalLink)}else newItem.renderType="richText",newItem.tag=getTag(itemCopy.nodeType),(0,string_js_1.isString)(itemCopy.content)&&(newItem.content=itemCopy.content),(0,array_js_1.isArrayStrict)(itemCopy.content)&&(newItem.content=normalizeRichText(itemCopy.content))}return newItem},normalizeContentfulData=(data,_newData=[])=>(0,array_js_1.isArrayStrict)(data)?(data.forEach((item=>{(0,object_js_1.isObjectStrict)(item)&&_newData.push(normalizeItem(item,_newData))})),_newData):[];exports.normalizeContentfulData=normalizeContentfulData;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.normalizeContentfulData=void 0;const contentType_js_1=require("../utils/contentType/contentType.js"),array_js_1=require("../utils/array/array.js"),object_js_1=require("../utils/object/object.js"),string_js_1=require("../utils/string/string.js"),objectUtils_js_1=require("../utils/object/objectUtils.js"),number_js_1=require("../utils/number/number.js"),config_js_1=require("../config/config.js"),getTag=(type="text")=>({br:"br",hr:"hr",paragraph:"p",blockquote:"blockquote",bold:"b",italic:"i",underline:"u",superscript:"sup",subscript:"sub",code:"code",hyperlink:"a","entry-hyperlink":"a","asset-hyperlink":"a","heading-1":"h1","heading-2":"h2","heading-3":"h3","heading-4":"h4","heading-5":"h5","heading-6":"h6","list-item":"li","unordered-list":"ul","ordered-list":"ol",table:"table","table-row":"tr","table-cell":"td","table-header-cell":"th"}[type]||""),normalizeRichText=items=>{const newItems=[];return items.forEach((item=>{if(!(0,object_js_1.isObjectStrict)(item))return;const{nodeType:nodeType,data:data,value:value,marks:marks,content:content}=item,tag=getTag(nodeType);let contentValue,link,internalLink;if((0,string_js_1.isStringStrict)(value)&&(contentValue=value,contentValue=contentValue.replace(/\n/g,"<br>"),(0,array_js_1.isArrayStrict)(marks))){const markTags=marks.map((m=>getTag(m.type)));contentValue=`${markTags.map((m=>`<${m}>`)).join("")}${value}${markTags.map((m=>`</${m}>`)).join("")}`}if((0,string_js_1.isStringStrict)(content)&&(contentValue=content),(0,array_js_1.isArrayStrict)(content)){const contentArr=normalizeRichText(content);contentArr.length>0&&(contentValue=contentArr)}if((0,object_js_1.isObjectStrict)(data)&&(link=(0,string_js_1.isString)(data.uri)?data.uri:"",(0,object_js_1.isObjectStrict)(data.target))){const target=data.target;"entry-hyperlink"===nodeType&&(internalLink=target);const url=target.fields?.file?.url;"asset-hyperlink"===nodeType&&(0,string_js_1.isString)(url)&&(link=`https:${url}`)}if(!contentValue)return;const newItem={content:contentValue};return(0,string_js_1.isStringStrict)(tag)&&(newItem.tag=tag),(0,string_js_1.isStringStrict)(link)&&(newItem.link=link),(0,object_js_1.isObjectStrict)(internalLink)&&(newItem.internalLink=normalizeItem(internalLink,[],!0)),newItems.push(newItem)})),newItems},normalizeFile=(file,fields)=>{const type=(0,string_js_1.isString)(file.contentType)?file.contentType:"",format=type?type.split("/")[1]:"";return{url:(0,string_js_1.isString)(file.url)?`https:${file.url}`:"",name:(0,string_js_1.isString)(file.fileName)?file.fileName:"",alt:(0,string_js_1.isString)(fields.description)?fields.description:"",width:(0,number_js_1.isNumber)(file.details?.image?.width)?file.details.image.width:0,height:(0,number_js_1.isNumber)(file.details?.image?.height)?file.details.image.height:0,size:(0,number_js_1.isNumber)(file.details?.size)?file.details.size:0,format:"jpeg"===format?"jpg":format,type:type}},normalizeItem=(item,data,isInternalLink=!1)=>{let newItem={};const itemCopy={...item};(0,string_js_1.isString)(itemCopy.sys?.id)&&(newItem.id=itemCopy.sys.id),(0,string_js_1.isStringStrict)(itemCopy.sys?.locale)&&(newItem.locale=itemCopy.sys.locale);let type="";if((0,string_js_1.isString)(itemCopy.sys?.type)&&(type=itemCopy.sys.type),(0,string_js_1.isString)(itemCopy.sys?.contentType?.sys?.id)&&(type=itemCopy.sys.contentType.sys.id),type&&"Link"!==type&&(newItem.contentType=(0,contentType_js_1.normalizeContentType)(type),(0,string_js_1.isString)(config_js_1.config.renderTypes[type])&&(newItem.renderType=config_js_1.config.renderTypes[type])),(0,array_js_1.isArrayStrict)(itemCopy.metadata?.tags)&&(newItem.metadata={tags:itemCopy.metadata.tags.map((t=>({id:(0,string_js_1.isString)(t.sys?.id)?t.sys.id:""})))}),(0,object_js_1.isObjectStrict)(itemCopy.fields)){const fields=itemCopy.fields,file=fields.file;if((0,object_js_1.isObjectStrict)(file))return Object.assign(normalizeFile(file,fields),newItem);(0,objectUtils_js_1.getObjectKeys)(fields).forEach((prop=>{const field=fields[prop];if("content"!==prop||!isInternalLink)if((0,object_js_1.isObjectStrict)(field))if("document"===field.nodeType){const{content:content}=field;(0,array_js_1.isArrayStrict)(content)&&(newItem[prop]=content.map((c=>(0,object_js_1.isObjectStrict)(c)?normalizeItem(c,data,isInternalLink):c)))}else newItem[prop]=normalizeItem(field,data,"internalLink"===prop);else(0,array_js_1.isArrayStrict)(field)?newItem[prop]=field.map((f=>(0,object_js_1.isObjectStrict)(f)?normalizeItem(f,data,isInternalLink):f)):newItem[prop]=field}))}if((0,string_js_1.isString)(itemCopy.nodeType)){const nodeType=itemCopy.nodeType;if("embedded-entry-block"===nodeType||"embedded-asset-block"===nodeType){const content=(0,object_js_1.isObjectStrict)(itemCopy.data?.target)?itemCopy.data.target:{};newItem=normalizeItem(content,data,isInternalLink)}else newItem.renderType="richText",newItem.tag=getTag(itemCopy.nodeType),(0,string_js_1.isString)(itemCopy.content)&&(newItem.content=itemCopy.content),(0,array_js_1.isArrayStrict)(itemCopy.content)&&(newItem.content=normalizeRichText(itemCopy.content))}return newItem},normalizeContentfulData=(data,_newData=[])=>(0,array_js_1.isArrayStrict)(data)?(data.forEach((item=>{(0,object_js_1.isObjectStrict)(item)&&_newData.push(normalizeItem(item,_newData))})),_newData):[];exports.normalizeContentfulData=normalizeContentfulData;
@@ -1,10 +1,22 @@
1
1
  import type { Generic } from '../global/globalTypes.js';
2
- import type { RenderServerlessData, RenderPreviewData, RenderItem } from '../render/renderTypes.js';
2
+ import type { RenderServerlessData, RenderPreviewData } from '../render/renderTypes.js';
3
3
  export type ContentfulDataParams = Record<string, string | number | boolean>;
4
+ export interface ContentfulDataError {
5
+ message: string;
6
+ sys: {
7
+ type: string;
8
+ id: string;
9
+ };
10
+ }
11
+ export interface ContentfulData {
12
+ items: ContentfulDataItem[];
13
+ total: number;
14
+ limit: number;
15
+ skip: number;
16
+ }
4
17
  export interface ContentfulDataTag {
5
18
  sys?: {
6
19
  id?: string;
7
- name?: string;
8
20
  };
9
21
  }
10
22
  export interface ContentfulDataMark {
@@ -32,6 +44,7 @@ export interface ContentfulDataFields extends Generic {
32
44
  export interface ContentfulDataSys {
33
45
  id?: string;
34
46
  type?: string;
47
+ locale?: string;
35
48
  contentType?: {
36
49
  sys?: {
37
50
  id?: string;
@@ -53,14 +66,6 @@ export interface ContentfulDataItem {
53
66
  sys?: ContentfulDataSys;
54
67
  fields?: ContentfulDataFields;
55
68
  }
56
- export interface ContentfulData extends Generic {
57
- items?: ContentfulDataItem[];
58
- errors?: Generic[];
59
- }
60
- export interface ContentfulDataReturn extends Generic {
61
- items?: RenderItem[];
62
- errors?: Generic[];
63
- }
64
69
  export interface AllContentfulDataArgs {
65
70
  serverlessData?: RenderServerlessData;
66
71
  previewData?: RenderPreviewData;
@@ -7,7 +7,7 @@ export interface Taxonomy {
7
7
  isPage?: boolean;
8
8
  usePrimaryContentTypeSlug?: boolean;
9
9
  }
10
- export interface InternalLinkBase {
10
+ export interface InternalLink extends Generic {
11
11
  id?: string;
12
12
  contentType?: string;
13
13
  slug?: string;
@@ -15,8 +15,10 @@ export interface InternalLinkBase {
15
15
  title?: string;
16
16
  taxonomy?: Taxonomy;
17
17
  }
18
- export interface InternalLink extends InternalLinkBase, Partial<Taxonomy> {
19
- [key: string]: unknown;
18
+ export interface Parent extends InternalLink {
19
+ id: string;
20
+ slug: string;
21
+ title: string;
20
22
  }
21
23
  export interface ParentArgs<T = Generic> {
22
24
  renderType: string;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getAllLocalData=exports.getLocalData=void 0;const promises_1=require("node:fs/promises"),node_path_1=require("node:path"),object_js_1=require("../utils/object/object.js"),string_js_1=require("../utils/string/string.js"),filter_js_1=require("../utils/filter/filter.js"),json_js_1=require("../utils/json/json.js"),config_js_1=require("../config/config.js"),localDataNormal_js_1=require("./localDataNormal.js"),getLocalData=async args=>{if(!(0,object_js_1.isObjectStrict)(args))throw new Error("No args");const{key:key,refProps:refProps,imageProps:imageProps,unsetProps:unsetProps}=args;if(!(0,string_js_1.isStringStrict)(key))throw new Error("No key");if(config_js_1.config.env.cache){const cacheDataFilterArgs={key:key,type:"get"},cacheData=await(0,filter_js_1.applyFilters)("cacheData",void 0,cacheDataFilterArgs,!0),cacheObj=cacheData?.data;if((0,object_js_1.isObject)(cacheObj))return structuredClone(cacheObj)}const dir=config_js_1.config.local.dir,data={};let hasData=!1;const files=await(0,promises_1.readdir)((0,node_path_1.resolve)(dir));for(const file of files){const fileExt=(0,node_path_1.extname)(file),fileName=(0,node_path_1.basename)(file,fileExt);if(".json"!==fileExt)continue;const fileContents=await(0,promises_1.readFile)((0,node_path_1.resolve)(dir,file),{encoding:"utf8"}),fileJson=(0,json_js_1.getJson)(fileContents);fileJson&&(data[fileName]=fileJson,hasData=!0)}if(!hasData)throw new Error("No data");const newData=(0,localDataNormal_js_1.normalizeLocalData)(data,refProps,imageProps,unsetProps);if(config_js_1.config.env.cache){const cacheDataFilterArgs={key:key,type:"set",data:data};await(0,filter_js_1.applyFilters)("cacheData",{data:newData},cacheDataFilterArgs,!0)}return newData};exports.getLocalData=getLocalData;const getAllLocalData=async args=>{const data=await getLocalData({key:"all_file_data",refProps:args?.refProps,imageProps:args?.imageProps,unsetProps:args?.unsetProps});let allData={navigationItem:[],navigation:[],content:{page:[]}};for(const[,value]of Object.entries(data)){const{contentType:contentType}=value;if(!(0,string_js_1.isStringStrict)(contentType))continue;const isPartial=config_js_1.config.partialTypes.includes(contentType),isWhole=config_js_1.config.wholeTypes.includes(contentType);if(!isPartial&&!isWhole)continue;const val=(0,filter_js_1.applyFilters)("localData",value);isPartial&&(null==allData[contentType]&&(allData[contentType]=[]),allData[contentType].push(val)),isWhole&&(null==allData.content[contentType]&&(allData.content[contentType]=[]),allData.content[contentType].push(val))}return allData=(0,filter_js_1.applyFilters)("allData",allData,{type:"local"}),allData};exports.getAllLocalData=getAllLocalData;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getAllLocalData=exports.getLocalData=void 0;const promises_1=require("node:fs/promises"),node_path_1=require("node:path"),object_js_1=require("../utils/object/object.js"),string_js_1=require("../utils/string/string.js"),filter_js_1=require("../utils/filter/filter.js"),json_js_1=require("../utils/json/json.js"),config_js_1=require("../config/config.js"),localDataNormal_js_1=require("./localDataNormal.js"),getLocalData=async args=>{if(!(0,object_js_1.isObjectStrict)(args))throw new Error("No args");const{key:key,refProps:refProps,imageProps:imageProps,unsetProps:unsetProps}=args;if(!(0,string_js_1.isStringStrict)(key))throw new Error("No key");if(config_js_1.config.env.cache){const cacheDataFilterArgs={key:key,type:"get"},cacheData=await(0,filter_js_1.applyFilters)("cacheData",void 0,cacheDataFilterArgs,!0),cacheItems=cacheData?.data;if((0,object_js_1.isObject)(cacheItems))return structuredClone(cacheItems)}const dir=config_js_1.config.local.dir,data={};let hasData=!1;const files=await(0,promises_1.readdir)((0,node_path_1.resolve)(dir));for(const file of files){const fileExt=(0,node_path_1.extname)(file),fileName=(0,node_path_1.basename)(file,fileExt);if(".json"!==fileExt)continue;const fileContents=await(0,promises_1.readFile)((0,node_path_1.resolve)(dir,file),{encoding:"utf8"}),fileJson=(0,json_js_1.getJson)(fileContents);fileJson&&(data[fileName]=fileJson,hasData=!0)}if(!hasData)throw new Error("No data");const newData=(0,localDataNormal_js_1.normalizeLocalData)(data,refProps,imageProps,unsetProps);if(config_js_1.config.env.cache){const cacheDataFilterArgs={key:key,type:"set",data:data};await(0,filter_js_1.applyFilters)("cacheData",{data:newData},cacheDataFilterArgs,!0)}return newData};exports.getLocalData=getLocalData;const getAllLocalData=async args=>{const data=await getLocalData({key:"all_file_data",refProps:args?.refProps,imageProps:args?.imageProps,unsetProps:args?.unsetProps});let allData={navigationItem:[],navigation:[],content:{page:[]}};for(const[,value]of Object.entries(data)){const{contentType:contentType}=value;if(!(0,string_js_1.isStringStrict)(contentType))continue;const isPartial=config_js_1.config.partialTypes.includes(contentType),isWhole=config_js_1.config.wholeTypes.includes(contentType);if(!isPartial&&!isWhole)continue;const val=(0,filter_js_1.applyFilters)("localData",value);isPartial&&(null==allData[contentType]&&(allData[contentType]=[]),allData[contentType].push(val)),isWhole&&(null==allData.content[contentType]&&(allData.content[contentType]=[]),allData.content[contentType].push(val))}return allData=(0,filter_js_1.applyFilters)("allData",allData,{type:"local"}),allData};exports.getAllLocalData=getAllLocalData;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setRenderFunctions=exports.renderHttpError=exports.renderNavigations=exports.renderLayout=exports.renderFunctions=exports.renderContent=exports.renderItem=exports.render=void 0;const action_js_1=require("../utils/action/action.js"),filter_js_1=require("../utils/filter/filter.js"),link_js_1=require("../utils/link/link.js"),string_js_1=require("../utils/string/string.js"),array_js_1=require("../utils/array/array.js"),object_js_1=require("../utils/object/object.js"),number_js_1=require("../utils/number/number.js"),function_js_1=require("../utils/function/function.js"),shortcode_js_1=require("../utils/shortcode/shortcode.js"),tag_js_1=require("../utils/tag/tag.js"),store_js_1=require("../store/store.js"),redirects_js_1=require("../redirects/redirects.js"),serverless_js_1=require("../serverless/serverless.js"),scriptStyle_js_1=require("../utils/scriptStyle/scriptStyle.js"),Container_js_1=require("../layouts/Container/Container.js"),Column_js_1=require("../layouts/Column/Column.js"),Form_js_1=require("../objects/Form/Form.js"),FormField_js_1=require("../objects/Form/FormField.js"),FormOption_js_1=require("../objects/Form/FormOption.js"),RichText_js_1=require("../text/RichText/RichText.js"),defaultRenderFunctions={container:Container_js_1.Container,column:Column_js_1.Column,form:Form_js_1.Form,formField:FormField_js_1.FormField,formOption:FormOption_js_1.FormOption,richText:RichText_js_1.RichText};let renderFunctions={...defaultRenderFunctions};exports.renderFunctions=renderFunctions;let renderLayout=()=>"";exports.renderLayout=renderLayout;let renderHttpError=()=>"";exports.renderHttpError=renderHttpError;let renderNavigations=()=>{};exports.renderNavigations=renderNavigations;const setRenderFunctions=args=>{if(!(0,object_js_1.isObjectStrict)(args))return!1;const{functions:functions,layout:layout,navigations:navigations,httpError:httpError}=args;return!(!(0,object_js_1.isObjectStrict)(functions)||!(0,function_js_1.isFunction)(layout))&&(exports.renderFunctions=renderFunctions={...defaultRenderFunctions,...functions},exports.renderLayout=renderLayout=layout,(0,function_js_1.isFunction)(navigations)&&(exports.renderNavigations=renderNavigations=navigations),(0,function_js_1.isFunction)(httpError)&&(exports.renderHttpError=renderHttpError=httpError),!0)};exports.setRenderFunctions=setRenderFunctions;const getContentTemplate=(content,templates=[],named=!1)=>{if(!(0,array_js_1.isArrayStrict)(content))return{content:[],namedContent:{},templates:templates};const namedContent={};return{content:content.map((c=>(named&&(0,string_js_1.isString)(c.name)&&(namedContent[c.name]={...c}),(0,tag_js_1.tagExists)(c,"template")?(templates.push({...c}),{metadata:{tags:[{id:"templateBreak",name:""}]}}):c))),namedContent:namedContent,templates:templates}},mapContentTemplate=(templates,content=[],namedContent={},named=!1)=>{if(!(0,array_js_1.isArrayStrict)(templates))return templates;const lastTemplateIndex=templates.length-1;return templates.forEach(((t,i)=>{content[0]&&(0,tag_js_1.tagExists)(content[0],"templateBreak")&&content.length>=1&&content.shift();if((0,tag_js_1.tagExists)(t,"templateOptional")&&i===lastTemplateIndex&&!content.length)return void templates.pop();const isSlot=(0,tag_js_1.tagExists)(t,"templateSlot");let children=t.content;if((0,array_js_1.isArrayStrict)(children)&&!isSlot){let repeat;const newChildren=[...children],repeatIndex=children.findIndex((c=>{const isRepeat=(0,tag_js_1.tagExists)(c,"templateRepeat");return isRepeat&&(repeat=c),isRepeat}));if(-1!==repeatIndex&&repeat){let breakIndex=content.findIndex((c=>(0,tag_js_1.tagExists)(c,"templateBreak")));breakIndex=-1===breakIndex?content.length:breakIndex;let insertIndex=repeatIndex;for(let j=insertIndex;j<breakIndex-1;j+=1)newChildren.splice(insertIndex,0,{...repeat}),insertIndex=j}children=newChildren}if(isSlot&&content.length>=1){let fill=null;return fill=named?namedContent[t.name]:content.shift(),void(fill&&(templates[i]=fill))}(0,array_js_1.isArray)(children)&&templates[i]&&(templates[i].content=mapContentTemplate(children,content,namedContent,named))})),templates},renderContent=async(args,_output={html:""})=>{if(!(0,object_js_1.isObjectStrict)(args))return _output.html;const{content:content=[],serverlessData:serverlessData,previewData:previewData,pageData:pageData,pageContains:pageContains=[],pageHeadings:pageHeadings=[],navigations:navigations,parents:parents=[],depth:depth=0}=args;let{headingsIndex:headingsIndex=-1}=args;if(!(0,array_js_1.isArrayStrict)(content))return _output.html;for(const item of content){if(!(0,object_js_1.isObjectStrict)(item))continue;const props={...item},renderType=(0,string_js_1.isString)(props.renderType)?props.renderType:"",contentAttr=props.contentIsAttribute,isRichText="richText"===renderType;let childrenArr,children=props.content;if("contentTemplate"===renderType){const isNamed=(0,tag_js_1.tagExists)(item,"templateNamed"),template=getContentTemplate((0,array_js_1.isArray)(props.content)?props.content:[],[],isNamed);children=mapContentTemplate(template.templates,template.content,template.namedContent,isNamed)}let childrenStr="";(0,array_js_1.isArrayStrict)(children)&&!isRichText&&(childrenArr=children),(0,string_js_1.isStringStrict)(children)&&!isRichText&&(childrenStr=children),"content"===renderType&&0===depth&&(headingsIndex=pageHeadings.push([])-1),(0,string_js_1.isStringStrict)(contentAttr)&&(props[contentAttr]=children,props.content=void 0,childrenArr=void 0);let renderStart="",renderEnd="",filterType="",filterArgs={};const renderFunction=renderFunctions[renderType];if((0,function_js_1.isFunction)(renderFunction)){const renderArgs={args:props,parents:parents,pageData:pageData,pageContains:pageContains,navigations:navigations,serverlessData:serverlessData,previewData:previewData};childrenArr&&(renderArgs.children=childrenArr),"richText"===renderType&&(renderArgs.headings=pageHeadings[headingsIndex]);let renderOutput=await renderFunction(renderArgs);if((0,array_js_1.isArrayStrict)(renderOutput)){1===renderOutput.length&&(renderOutput=renderOutput[0]?.split("%content")??["",""]);const[start,end]=renderOutput;(0,string_js_1.isString)(start)&&(renderStart=start),(0,string_js_1.isString)(end)&&(renderEnd=end)}(0,string_js_1.isString)(renderOutput)&&(renderStart=renderOutput),pageContains.push(renderType),filterType=renderType,filterArgs={...props,content:void 0}}const renderContentFilterArgs={renderType:filterType,args:filterArgs},[filterRenderStart,filterRenderEnd]=await(0,filter_js_1.applyFilters)("renderContent",[renderStart,renderEnd],renderContentFilterArgs,!0);if((0,string_js_1.isString)(filterRenderStart)&&(renderStart=filterRenderStart),(0,string_js_1.isString)(filterRenderEnd)&&(renderEnd=filterRenderEnd),_output.html+=renderStart+childrenStr,childrenArr){const parentsCopy=[...parents];renderType&&parentsCopy.unshift({renderType:renderType,args:{...props,content:void 0,parents:void 0}}),await renderContent({content:childrenArr,serverlessData:serverlessData,previewData:previewData,parents:parentsCopy,pageData:pageData,pageContains:pageContains,pageHeadings:pageHeadings,navigations:navigations,headingsIndex:headingsIndex,depth:depth+1},_output)}_output.html+=renderEnd}return _output.html};exports.renderContent=renderContent;const renderItem=async(args,_contentType)=>{if(!(0,object_js_1.isObjectStrict)(args))return null;const{item:item,serverlessData:serverlessData,previewData:previewData}=args;if(!(0,object_js_1.isObjectStrict)(item))return null;const contentType=item.contentType;if(!(0,string_js_1.isStringStrict)(contentType))return null;if("taxonomy"===contentType&&!0!==item.isPage)return null;const id=item.id;if(!(0,string_js_1.isStringStrict)(id))return null;if(!(0,string_js_1.isStringStrict)(item.slug))return null;let serverlessRender=!1;const pageContains=[],pageHeadings=[];scriptStyle_js_1.scripts.deps.clear(),scriptStyle_js_1.scripts.item.clear(),scriptStyle_js_1.scripts.meta={},scriptStyle_js_1.styles.deps.clear(),scriptStyle_js_1.styles.item.clear();const renderItemStartArgs={id:id,pageData:{...item},contentType:contentType,pageContains:[],pageHeadings:[],serverlessData:serverlessData,previewData:previewData};await(0,action_js_1.doActions)("renderItemStart",renderItemStartArgs,!0);const title=item.title,meta={title:"",description:"",url:"",image:"",canonical:"",prev:"",next:"",noIndex:!1,isIndex:!1,...item.meta};(0,string_js_1.isStringStrict)(item.metaTitle)&&(meta.title=item.metaTitle),(0,string_js_1.isStringStrict)(item.metaDescription)&&(meta.description=item.metaDescription),(0,string_js_1.isStringStrict)(item.metaImage?.url)&&(meta.image=item.metaImage.url),!(0,string_js_1.isStringStrict)(meta.title)&&(0,string_js_1.isStringStrict)(title)&&(meta.title=title);const taxonomy="term"===contentType?item.taxonomy:"taxonomy"===contentType?item:{},slugArgs={id:id,contentType:contentType,slug:item.slug,returnParents:!0,pageData:item,page:0},s=(0,link_js_1.getSlug)(slugArgs,!0),slug=s.slug,slugIsHtml=slug.includes(".html"),permalink=(0,link_js_1.getPermalink)(slug,!slugIsHtml),parents=s.parents;item.baseUrl=permalink,meta.url=permalink,meta.canonical=permalink;let formattedSlug="index"!==slug&&""!==slug?`/${slug}/`:"/";slugIsHtml&&(formattedSlug=slug),(0,store_js_1.setStoreItem)("slugs",{id:id,contentType:(0,string_js_1.isStringStrict)(_contentType)?_contentType:contentType},slugIsHtml?`/${slug}`:formattedSlug);const index="index"===item.slug;let navigations,itemServerlessData;if(meta.isIndex=index,(0,function_js_1.isFunction)(renderNavigations)){let currentType=contentType;(0,object_js_1.isObjectStrict)(taxonomy)&&(0,array_js_1.isArrayStrict)(taxonomy.contentTypes)&&(currentType=taxonomy.contentTypes),navigations=await renderNavigations({navigations:(0,store_js_1.getStoreItem)("navigations"),items:(0,store_js_1.getStoreItem)("navigationItems"),currentLink:permalink,currentType:currentType,title:title,parents:parents})}if((0,object_js_1.isObjectStrict)(serverlessData)){if(!(serverlessData.path===formattedSlug&&null!=serverlessData.query))return{serverlessRender:!1};itemServerlessData=serverlessData}const pageData={...item};pageData.id=id,pageData.parents=parents,pageData.content=void 0;let contentOutput="";const contentData=item.content;(0,string_js_1.isStringStrict)(contentData)&&(contentOutput=contentData),(0,array_js_1.isArrayStrict)(contentData)&&(contentOutput=await renderContent({content:contentData,serverlessData:itemServerlessData,parents:[],pageData:pageData,pageContains:pageContains,pageHeadings:pageHeadings,navigations:navigations,previewData:previewData})),contentOutput=await(0,shortcode_js_1.doShortcodes)(contentOutput,pageData);const pag=pageData.pagination;if((0,object_js_1.isObjectStrict)(pag)){const{current:current=0,total:total=1,currentFilters:currentFilters,prevFilters:prevFilters,nextFilters:nextFilters}=pag;if(meta.canonicalParams=`${current>1?`?page=${current}`:""}${(0,string_js_1.isString)(currentFilters)?currentFilters:""}`,(0,string_js_1.isStringStrict)(pag.title)&&(meta.paginationTitle=pag.title),(0,number_js_1.isNumber)(pag.prev)&&pag.prev>=1){slugArgs.page=pag.prev;const p=(0,link_js_1.getSlug)(slugArgs,!0);meta.prev=`${(0,link_js_1.getPermalink)(p.slug,1===pag.prev)}${(0,string_js_1.isString)(prevFilters)?prevFilters:""}`}if((0,number_js_1.isNumber)(pag.next)&&pag.next>1&&pag.next<total){slugArgs.page=pag.next;const n=(0,link_js_1.getSlug)(slugArgs,!0);meta.next=`${(0,link_js_1.getPermalink)(n.slug,!1)}${(0,string_js_1.isString)(nextFilters)?nextFilters:""}`}serverlessRender=!0}let layoutOutput="";if((0,function_js_1.isFunction)(renderLayout)){const layoutArgs={id:id,meta:meta,navigations:navigations,contentType:contentType,content:contentOutput,slug:formattedSlug,pageContains:pageContains,pageHeadings:pageHeadings,pageData:pageData,serverlessData:serverlessData,previewData:previewData};layoutOutput=await renderLayout(layoutArgs)}const renderItemFilterArgs={id:id,contentType:contentType,slug:formattedSlug,output:layoutOutput,pageData:pageData,pageContains:pageContains,pageHeadings:pageHeadings,serverlessData:serverlessData,previewData:previewData};layoutOutput=await(0,filter_js_1.applyFilters)("renderItem",layoutOutput,renderItemFilterArgs,!0);const renderItemEndArgs={id:id,contentType:contentType,slug:formattedSlug,output:layoutOutput,pageData:pageData,pageContains:pageContains,pageHeadings:pageHeadings,serverlessData:serverlessData,previewData:previewData};return await(0,action_js_1.doActions)("renderItemEnd",renderItemEndArgs,!0),{serverlessRender:serverlessRender,pageData:pageData,data:{slug:formattedSlug,output:layoutOutput}}};exports.renderItem=renderItem;const render=async args=>{if(!(0,object_js_1.isObjectStrict)(args))return[];const{allData:allData,serverlessData:serverlessData,previewData:previewData}=args,isServerless=null!=serverlessData,isPreview=null!=previewData;if(scriptStyle_js_1.scripts.deps.clear(),scriptStyle_js_1.scripts.item.clear(),scriptStyle_js_1.scripts.meta={},scriptStyle_js_1.styles.deps.clear(),scriptStyle_js_1.styles.item.clear(),!(0,object_js_1.isObjectStrict)(allData))return[];const{redirect:redirect,content:content}=allData;await(0,action_js_1.doActions)("renderStart",args,!0);const data=[];isServerless||(0,store_js_1.setStoreData)(allData),(0,redirects_js_1.setRedirects)(redirect),serverless_js_1.serverlessRoutes.reload=[];for(const[contentType,contentItems]of Object.entries(content))if((0,array_js_1.isArrayStrict)(contentItems))for(const contentItem of contentItems){const item=await renderItem({item:await(0,filter_js_1.applyFilters)("renderItemData",contentItem,{contentType:contentType},!0),serverlessData:serverlessData},contentType);if(!item)continue;const{serverlessRender:serverlessRender=!1,data:itemData}=item;itemData&&(data.push(itemData),serverlessRender&&!isServerless&&serverless_js_1.serverlessRoutes.reload.push({path:itemData.slug.replace(/^\/|\/$/gm,"")}))}const[outputItem]=data,output=(isServerless||isPreview)&&outputItem?outputItem:data;return await(0,action_js_1.doActions)("renderEnd",{...args,data:output},!0),output};exports.render=render;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setRenderFunctions=exports.renderHttpError=exports.renderNavigations=exports.renderLayout=exports.renderFunctions=exports.renderContent=exports.renderItem=exports.render=void 0;const action_js_1=require("../utils/action/action.js"),filter_js_1=require("../utils/filter/filter.js"),link_js_1=require("../utils/link/link.js"),string_js_1=require("../utils/string/string.js"),array_js_1=require("../utils/array/array.js"),object_js_1=require("../utils/object/object.js"),number_js_1=require("../utils/number/number.js"),function_js_1=require("../utils/function/function.js"),shortcode_js_1=require("../utils/shortcode/shortcode.js"),tag_js_1=require("../utils/tag/tag.js"),store_js_1=require("../store/store.js"),redirects_js_1=require("../redirects/redirects.js"),serverless_js_1=require("../serverless/serverless.js"),scriptStyle_js_1=require("../utils/scriptStyle/scriptStyle.js"),Container_js_1=require("../layouts/Container/Container.js"),Column_js_1=require("../layouts/Column/Column.js"),Form_js_1=require("../objects/Form/Form.js"),FormField_js_1=require("../objects/Form/FormField.js"),FormOption_js_1=require("../objects/Form/FormOption.js"),RichText_js_1=require("../text/RichText/RichText.js"),config_js_1=require("../config/config.js"),defaultRenderFunctions={container:Container_js_1.Container,column:Column_js_1.Column,form:Form_js_1.Form,formField:FormField_js_1.FormField,formOption:FormOption_js_1.FormOption,richText:RichText_js_1.RichText};let renderFunctions={...defaultRenderFunctions};exports.renderFunctions=renderFunctions;let renderLayout=()=>"";exports.renderLayout=renderLayout;let renderHttpError=()=>"";exports.renderHttpError=renderHttpError;let renderNavigations=()=>{};exports.renderNavigations=renderNavigations;const setRenderFunctions=args=>{if(!(0,object_js_1.isObjectStrict)(args))return!1;const{functions:functions,layout:layout,navigations:navigations,httpError:httpError}=args;return!(!(0,object_js_1.isObjectStrict)(functions)||!(0,function_js_1.isFunction)(layout))&&(exports.renderFunctions=renderFunctions={...defaultRenderFunctions,...functions},exports.renderLayout=renderLayout=layout,(0,function_js_1.isFunction)(navigations)&&(exports.renderNavigations=renderNavigations=navigations),(0,function_js_1.isFunction)(httpError)&&(exports.renderHttpError=renderHttpError=httpError),!0)};exports.setRenderFunctions=setRenderFunctions;const getContentTemplate=(content,templates=[],named=!1)=>{if(!(0,array_js_1.isArrayStrict)(content))return{content:[],namedContent:{},templates:[]};const namedContent={},newContent=content.map((c=>(named&&(0,string_js_1.isString)(c.name)&&(namedContent[c.name]={...c}),(0,tag_js_1.tagExists)(c,"template")?(templates.push({...c}),{metadata:{tags:[{id:"templateBreak"}]}}):c)));return{namedContent:namedContent,content:newContent,templates:structuredClone(templates)}},mapContentTemplate=(templates,content=[],namedContent={},named=!1)=>{if(!(0,array_js_1.isArrayStrict)(templates))return templates;const lastTemplateIndex=templates.length-1;return templates.forEach(((t,i)=>{content[0]&&(0,tag_js_1.tagExists)(content[0],"templateBreak")&&content.length>=1&&content.shift();if((0,tag_js_1.tagExists)(t,"templateOptional")&&i===lastTemplateIndex&&!content.length)return void templates.pop();const isSlot=(0,tag_js_1.tagExists)(t,"templateSlot");let children=t.content;if((0,array_js_1.isArrayStrict)(children)&&!isSlot&&!named){let repeat;const newChildren=[...children],repeatIndex=children.findIndex((c=>{const isRepeat=(0,tag_js_1.tagExists)(c,"templateRepeat");return isRepeat&&(repeat=c),isRepeat}));if(-1!==repeatIndex&&repeat){let breakIndex=content.findIndex((c=>(0,tag_js_1.tagExists)(c,"templateBreak")));breakIndex=-1===breakIndex?content.length:breakIndex;let insertIndex=repeatIndex;for(let j=insertIndex;j<breakIndex-1;j+=1)newChildren.splice(insertIndex,0,structuredClone(repeat)),insertIndex=j}children=newChildren}if(isSlot&&content.length>=1){let fill=null;return fill=named?namedContent[t.name]:content.shift(),void(fill&&(templates[i]=fill))}(0,array_js_1.isArray)(children)&&templates[i]&&(templates[i].content=mapContentTemplate(children,content,namedContent,named))})),templates},renderContent=async(args,_output={html:""})=>{if(!(0,object_js_1.isObjectStrict)(args))return _output.html;const{content:content=[],serverlessData:serverlessData,previewData:previewData,itemData:itemData,itemContains:itemContains=[],itemHeadings:itemHeadings=[],navigations:navigations,parents:parents=[],depth:depth=0}=args;let{headingsIndex:headingsIndex=-1}=args;if(!(0,array_js_1.isArrayStrict)(content))return _output.html;for(const item of content){if(!(0,object_js_1.isObjectStrict)(item))continue;const props={...item},renderType=(0,string_js_1.isString)(props.renderType)?props.renderType:"",contentAttr=props.contentIsAttribute,isRichText="richText"===renderType;let childrenArr,children=props.content;if("contentTemplate"===renderType){const isNamed=(0,tag_js_1.tagExists)(item,"templateNamed"),template=getContentTemplate((0,array_js_1.isArray)(props.content)?props.content:[],[],isNamed);children=mapContentTemplate(template.templates,template.content,template.namedContent,isNamed)}let childrenStr="";(0,array_js_1.isArrayStrict)(children)&&!isRichText&&(childrenArr=children),(0,string_js_1.isStringStrict)(children)&&!isRichText&&(childrenStr=children),"content"===renderType&&0===depth&&(headingsIndex=itemHeadings.push([])-1),(0,string_js_1.isStringStrict)(contentAttr)&&(props[contentAttr]=children,props.content=void 0,childrenArr=void 0);let renderStart="",renderEnd="",filterType="",filterArgs={};const renderFunction=renderFunctions[renderType];if((0,function_js_1.isFunction)(renderFunction)){const renderArgs={args:props,parents:parents,itemData:itemData,itemContains:itemContains,navigations:navigations,serverlessData:serverlessData,previewData:previewData};childrenArr&&(renderArgs.children=childrenArr),"richText"===renderType&&(renderArgs.headings=itemHeadings[headingsIndex]);let renderOutput=await renderFunction(renderArgs);if((0,array_js_1.isArrayStrict)(renderOutput)){1===renderOutput.length&&(renderOutput=renderOutput[0]?.split("%content")??["",""]);const[start,end]=renderOutput;(0,string_js_1.isString)(start)&&(renderStart=start),(0,string_js_1.isString)(end)&&(renderEnd=end)}(0,string_js_1.isString)(renderOutput)&&(renderStart=renderOutput),itemContains.push(renderType),filterType=renderType,filterArgs={...props,content:void 0}}const renderContentFilterArgs={renderType:filterType,args:filterArgs},[filterRenderStart,filterRenderEnd]=await(0,filter_js_1.applyFilters)("renderContent",[renderStart,renderEnd],renderContentFilterArgs,!0);if((0,string_js_1.isString)(filterRenderStart)&&(renderStart=filterRenderStart),(0,string_js_1.isString)(filterRenderEnd)&&(renderEnd=filterRenderEnd),_output.html+=renderStart+childrenStr,childrenArr){const parentsCopy=[...parents];renderType&&parentsCopy.unshift({renderType:renderType,args:{...props,content:void 0,parents:void 0}}),await renderContent({content:childrenArr,serverlessData:serverlessData,previewData:previewData,parents:parentsCopy,itemData:itemData,itemContains:itemContains,itemHeadings:itemHeadings,navigations:navigations,headingsIndex:headingsIndex,depth:depth+1},_output)}_output.html+=renderEnd}return _output.html};exports.renderContent=renderContent;const renderItem=async(args,_contentType)=>{if(!(0,object_js_1.isObjectStrict)(args))return null;const{item:item,serverlessData:serverlessData,previewData:previewData}=args;if(!(0,object_js_1.isObjectStrict)(item))return null;const contentType=item.contentType;if(!(0,string_js_1.isStringStrict)(contentType))return null;if("taxonomy"===contentType&&!0!==item.isPage)return null;const id=item.id;if(!(0,string_js_1.isStringStrict)(id))return null;if(!(0,string_js_1.isStringStrict)(item.slug))return null;let serverlessRender=!1;const itemContains=[],itemHeadings=[];scriptStyle_js_1.scripts.deps.clear(),scriptStyle_js_1.scripts.item.clear(),scriptStyle_js_1.scripts.meta={},scriptStyle_js_1.styles.deps.clear(),scriptStyle_js_1.styles.item.clear();const renderItemStartArgs={id:id,itemData:{...item},contentType:contentType,itemContains:[],itemHeadings:[],serverlessData:serverlessData,previewData:previewData};await(0,action_js_1.doActions)("renderItemStart",renderItemStartArgs,!0);const title=item.title,meta={title:"",description:"",url:"",image:"",canonical:"",prev:"",next:"",noIndex:!1,isIndex:!1,...item.meta};(0,string_js_1.isStringStrict)(item.metaTitle)&&(meta.title=item.metaTitle),(0,string_js_1.isStringStrict)(item.metaDescription)&&(meta.description=item.metaDescription),(0,string_js_1.isStringStrict)(item.metaImage?.url)&&(meta.image=item.metaImage.url),!(0,string_js_1.isStringStrict)(meta.title)&&(0,string_js_1.isStringStrict)(title)&&(meta.title=title);const taxonomy="term"===contentType?item.taxonomy:"taxonomy"===contentType?item:{},slugArgs={id:id,contentType:contentType,slug:item.slug,returnParents:!0,itemData:item,page:0},s=(0,link_js_1.getSlug)(slugArgs,!0),slug=s.slug,slugIsHtml=slug.includes(".html"),permalink=(0,link_js_1.getPermalink)(slug,!slugIsHtml),parents=s.parents;item.baseUrl=permalink,meta.url=permalink,meta.canonical=permalink;let formattedSlug="index"!==slug&&""!==slug?`/${slug}/`:"/";slugIsHtml&&(formattedSlug=slug);const cmsLocales=config_js_1.config.cms.locales,slugData={id:id,contentType:(0,string_js_1.isStringStrict)(_contentType)?_contentType:contentType};if((0,string_js_1.isStringStrict)(item.locale)&&cmsLocales){const locale=item.locale;cmsLocales.includes(locale)&&locale!==cmsLocales[0]&&(slugData.locale=locale)}(0,store_js_1.setStoreItem)("slugs",slugData,slugIsHtml?`/${slug}`:formattedSlug);const index="index"===item.slug;let navigations,itemServerlessData;if(meta.isIndex=index,(0,function_js_1.isFunction)(renderNavigations)){let currentType=contentType;(0,object_js_1.isObjectStrict)(taxonomy)&&(0,array_js_1.isArrayStrict)(taxonomy.contentTypes)&&(currentType=taxonomy.contentTypes),navigations=await renderNavigations({navigations:(0,store_js_1.getStoreItem)("navigations"),items:(0,store_js_1.getStoreItem)("navigationItems"),currentLink:permalink,currentType:currentType,title:title,parents:parents})}if((0,object_js_1.isObjectStrict)(serverlessData)){if(!(serverlessData.path===formattedSlug&&null!=serverlessData.query))return{serverlessRender:!1};itemServerlessData=serverlessData}const itemData={...item};itemData.id=id,itemData.parents=parents,itemData.content=void 0;let contentOutput="";const contentData=item.content;(0,string_js_1.isStringStrict)(contentData)&&(contentOutput=contentData),(0,array_js_1.isArrayStrict)(contentData)&&(contentOutput=await renderContent({content:contentData,serverlessData:itemServerlessData,parents:[],itemData:itemData,itemContains:itemContains,itemHeadings:itemHeadings,navigations:navigations,previewData:previewData})),contentOutput=await(0,shortcode_js_1.doShortcodes)(contentOutput,itemData);const pag=itemData.pagination;if((0,object_js_1.isObjectStrict)(pag)){const{current:current=0,total:total=1,currentFilters:currentFilters,prevFilters:prevFilters,nextFilters:nextFilters}=pag;if(meta.canonicalParams=`${current>1?`?page=${current}`:""}${(0,string_js_1.isString)(currentFilters)?currentFilters:""}`,(0,string_js_1.isStringStrict)(pag.title)&&(meta.paginationTitle=pag.title),(0,number_js_1.isNumber)(pag.prev)&&pag.prev>=1){slugArgs.page=pag.prev;const p=(0,link_js_1.getSlug)(slugArgs,!0);meta.prev=`${(0,link_js_1.getPermalink)(p.slug,1===pag.prev)}${(0,string_js_1.isString)(prevFilters)?prevFilters:""}`}if((0,number_js_1.isNumber)(pag.next)&&pag.next>1&&pag.next<total){slugArgs.page=pag.next;const n=(0,link_js_1.getSlug)(slugArgs,!0);meta.next=`${(0,link_js_1.getPermalink)(n.slug,!1)}${(0,string_js_1.isString)(nextFilters)?nextFilters:""}`}serverlessRender=!0}let layoutOutput="";if((0,function_js_1.isFunction)(renderLayout)){const layoutArgs={id:id,meta:meta,navigations:navigations,contentType:contentType,content:contentOutput,slug:formattedSlug,itemContains:itemContains,itemHeadings:itemHeadings,itemData:itemData,serverlessData:serverlessData,previewData:previewData};layoutOutput=await renderLayout(layoutArgs)}const renderItemFilterArgs={id:id,contentType:contentType,slug:formattedSlug,output:layoutOutput,itemData:itemData,itemContains:itemContains,itemHeadings:itemHeadings,serverlessData:serverlessData,previewData:previewData};layoutOutput=await(0,filter_js_1.applyFilters)("renderItem",layoutOutput,renderItemFilterArgs,!0);const renderItemEndArgs={id:id,contentType:contentType,slug:formattedSlug,output:layoutOutput,itemData:itemData,itemContains:itemContains,itemHeadings:itemHeadings,serverlessData:serverlessData,previewData:previewData};return await(0,action_js_1.doActions)("renderItemEnd",renderItemEndArgs,!0),{serverlessRender:serverlessRender,itemData:itemData,data:{slug:formattedSlug,output:layoutOutput}}};exports.renderItem=renderItem;const render=async args=>{if(!(0,object_js_1.isObjectStrict)(args))return[];const{allData:allData,serverlessData:serverlessData,previewData:previewData}=args,isServerless=null!=serverlessData,isPreview=null!=previewData;if(scriptStyle_js_1.scripts.deps.clear(),scriptStyle_js_1.scripts.item.clear(),scriptStyle_js_1.scripts.meta={},scriptStyle_js_1.styles.deps.clear(),scriptStyle_js_1.styles.item.clear(),!(0,object_js_1.isObjectStrict)(allData))return[];const{redirect:redirect,content:content}=allData;await(0,action_js_1.doActions)("renderStart",args,!0);const data=[];isServerless||(0,store_js_1.setStoreData)(allData),(0,redirects_js_1.setRedirects)(redirect),serverless_js_1.serverlessRoutes.reload=[];for(const[contentType,contentItems]of Object.entries(content))if((0,array_js_1.isArrayStrict)(contentItems))for(const contentItem of contentItems){const item=await renderItem({item:await(0,filter_js_1.applyFilters)("renderItemData",contentItem,{contentType:contentType},!0),serverlessData:serverlessData,previewData:previewData},contentType);if(!item)continue;const{serverlessRender:serverlessRender=!1,data:itemData}=item;itemData&&(data.push(itemData),serverlessRender&&!isServerless&&serverless_js_1.serverlessRoutes.reload.push({path:itemData.slug.replace(/^\/|\/$/gm,"")}))}const[outputItem]=data,output=(isServerless||isPreview)&&outputItem?outputItem:data;return await(0,action_js_1.doActions)("renderEnd",{...args,data:output},!0),output};exports.render=render;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.renderInlineItem=exports.renderInlineContent=void 0;const render_js_1=require("./render.js"),object_js_1=require("../utils/object/object.js"),string_js_1=require("../utils/string/string.js"),renderInlineContent=async(content,args)=>await(0,render_js_1.renderContent)({content:content,parents:[],pageData:{},pageContains:[],pageHeadings:[],navigations:void 0,...args});exports.renderInlineContent=renderInlineContent;const renderInlineItem=async item=>{if(!(0,object_js_1.isObjectStrict)(item))return"";const res=await(0,render_js_1.renderItem)({item:item});return(0,string_js_1.isString)(res?.data?.output)?res.data.output:""};exports.renderInlineItem=renderInlineItem;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.renderInlineItem=exports.renderInlineContent=void 0;const render_js_1=require("./render.js"),object_js_1=require("../utils/object/object.js"),string_js_1=require("../utils/string/string.js"),renderInlineContent=async(content,args)=>await(0,render_js_1.renderContent)({content:content,parents:[],itemData:{},itemContains:[],itemHeadings:[],navigations:void 0,...args});exports.renderInlineContent=renderInlineContent;const renderInlineItem=async item=>{if(!(0,object_js_1.isObjectStrict)(item))return"";const res=await(0,render_js_1.renderItem)({item:item});return(0,string_js_1.isString)(res?.data?.output)?res.data.output:""};exports.renderInlineItem=renderInlineItem;
@@ -1,9 +1,8 @@
1
- import type { Generic, GenericStrings, InternalLink, Taxonomy, ParentArgs } from '../global/globalTypes.js';
1
+ import type { Generic, GenericStrings, InternalLink, Taxonomy, Parent, ParentArgs } from '../global/globalTypes.js';
2
2
  import type { NavigationList, NavigationItem, NavigationProps } from '../components/Navigation/NavigationTypes.js';
3
3
  import type { Navigation } from '../components/Navigation/Navigation.js';
4
4
  import type { RichTextHeading } from '../text/RichText/RichTextTypes.js';
5
- import type { StoreParent } from '../store/storeTypes.js';
6
- import { PaginationData } from '../components/Pagination/PaginationTypes.js';
5
+ import type { PaginationData } from '../components/Pagination/PaginationTypes.js';
7
6
  export interface RenderMeta {
8
7
  title?: string;
9
8
  paginationTitle?: string;
@@ -18,9 +17,9 @@ export interface RenderMeta {
18
17
  isIndex?: boolean;
19
18
  }
20
19
  export interface RenderBase {
21
- pageData: RenderItem;
22
- pageHeadings: RichTextHeading[][];
23
- pageContains: string[];
20
+ itemData: RenderItem;
21
+ itemHeadings: RichTextHeading[][];
22
+ itemContains: string[];
24
23
  serverlessData?: RenderServerlessData;
25
24
  previewData?: RenderPreviewData;
26
25
  }
@@ -31,13 +30,13 @@ export interface RenderServerlessData {
31
30
  export interface RenderPreviewData {
32
31
  id: string;
33
32
  contentType: string;
33
+ locale?: string;
34
34
  }
35
35
  export interface RenderRedirect {
36
36
  redirect: string[];
37
37
  }
38
38
  export interface RenderTag {
39
39
  id: string;
40
- name: string;
41
40
  }
42
41
  export interface RenderMetaTags {
43
42
  tags?: RenderTag[];
@@ -68,7 +67,7 @@ export interface RenderTemplate {
68
67
  }
69
68
  export interface RenderNavigationsArgs extends NavigationProps {
70
69
  title?: string;
71
- parents: StoreParent[];
70
+ parents: Parent[];
72
71
  }
73
72
  export type RenderNavigations = (args: RenderNavigationsArgs) => Navigation | undefined | Promise<Navigation | undefined>;
74
73
  export interface RenderHttpErrorArgs extends Generic {
@@ -78,8 +77,8 @@ export type RenderHttpError = (args: RenderHttpErrorArgs) => string | Promise<st
78
77
  export interface RenderFunctionArgs<T = any, R = RenderItem, P = ParentArgs> {
79
78
  args: 0 extends (1 & T) ? any : T;
80
79
  parents?: P[];
81
- pageData?: R;
82
- pageContains?: string[];
80
+ itemData?: R;
81
+ itemContains?: string[];
83
82
  navigations?: Navigation;
84
83
  serverlessData?: RenderServerlessData;
85
84
  previewData?: RenderPreviewData;
@@ -126,7 +125,7 @@ export interface RenderItemArgs {
126
125
  }
127
126
  export interface RenderItemReturn {
128
127
  serverlessRender?: boolean;
129
- pageData?: RenderItem;
128
+ itemData?: RenderItem;
130
129
  data?: {
131
130
  slug: string;
132
131
  output: string;
@@ -155,9 +154,9 @@ export interface RenderLayoutArgs {
155
154
  contentType: string;
156
155
  content: string;
157
156
  slug: string;
158
- pageData: RenderItem;
159
- pageHeadings?: RichTextHeading[][];
160
- pageContains?: string[];
157
+ itemData: RenderItem;
158
+ itemHeadings?: RichTextHeading[][];
159
+ itemContains?: string[];
161
160
  serverlessData?: RenderServerlessData;
162
161
  previewData?: RenderPreviewData;
163
162
  }
@@ -194,5 +193,7 @@ export type RenderItemStartAction = (args: RenderItemStartActionArgs) => Promise
194
193
  export type RenderItemEndAction = (args: RenderItemActionArgs) => Promise<void> | void;
195
194
  export interface RenderDataMeta {
196
195
  total?: number;
197
- totalPages?: number;
196
+ pages?: number;
197
+ skip?: number;
198
+ limit?: number;
198
199
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Ajax=void 0;const ResponseError_js_1=require("../../utils/ResponseError/ResponseError.js"),filter_js_1=require("../../utils/filter/filter.js"),object_js_1=require("../../utils/object/object.js"),string_js_1=require("../../utils/string/string.js"),number_js_1=require("../../utils/number/number.js"),function_js_1=require("../../utils/function/function.js"),print_js_1=require("../../utils/print/print.js"),config_js_1=require("../../config/config.js"),serverless_js_1=require("../serverless.js"),Ajax=async(context,setupServerless)=>{try{await setupServerless(context,"ajax");const request=context.request,data=await request.json();if(!(0,object_js_1.isObjectStrict)(data))throw new Error("Data not an object");const honeypotName=`${config_js_1.config.namespace}_asi`;if((0,object_js_1.isObjectStrict)(data.inputs?.[honeypotName])){const honeypotValue=data.inputs[honeypotName].value;if((0,string_js_1.isStringStrict)(honeypotValue)){const options={status:200,headers:{"Content-Type":"application/json"}};return new Response(JSON.stringify({success:"Form successully sent"}),options)}data.inputs[honeypotName].exclude=!0}const action=data.action;if(!(0,string_js_1.isStringStrict)(action))throw new Error("No action");let res=null;const ajaxFn=serverless_js_1.serverlessActions[action];(0,function_js_1.isFunction)(ajaxFn)&&(res=await ajaxFn(data,context));const ajaxResultFilterArgs={data:data,context:context};if(res=await(0,filter_js_1.applyFilters)("ajaxResult",res,ajaxResultFilterArgs,!0),!res)throw new Error("No result");if(res.error)throw new ResponseError_js_1.ResponseError(res.error.message,res.error.response);const options={status:200,headers:{"Content-Type":"application/json"}};let message="";if(res.success){const{message:successMessage,headers:headers}=res.success;(0,string_js_1.isStringStrict)(successMessage)&&(message=successMessage),(0,object_js_1.isObjectStrict)(headers)&&(options.headers={...options.headers,...headers})}return new Response(JSON.stringify({success:message}),options)}catch(error){(0,print_js_1.print)("[FRM] Error with ajax function",error);let statusCode=500,message=error instanceof Error?error.message:"Unknown error";error instanceof ResponseError_js_1.ResponseError&&((0,number_js_1.isNumber)(error.response?.status)&&(statusCode=error.response.status),(0,string_js_1.isStringStrict)(error.message)&&(message=error.message));const options={status:statusCode,headers:{"Content-Type":"application/json"}};return new Response(JSON.stringify({error:message}),options)}};exports.Ajax=Ajax;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Ajax=void 0;const ResponseError_js_1=require("../../utils/ResponseError/ResponseError.js"),filter_js_1=require("../../utils/filter/filter.js"),object_js_1=require("../../utils/object/object.js"),string_js_1=require("../../utils/string/string.js"),number_js_1=require("../../utils/number/number.js"),function_js_1=require("../../utils/function/function.js"),print_js_1=require("../../utils/print/print.js"),config_js_1=require("../../config/config.js"),serverless_js_1=require("../serverless.js"),Ajax=async(context,setupServerless)=>{try{await setupServerless(context,"ajax");const request=context.request,data=await request.json();if(!(0,object_js_1.isObjectStrict)(data))throw new Error("Data not an object");const honeypotName=`${config_js_1.config.namespace}_asi`;if((0,object_js_1.isObjectStrict)(data.inputs?.[honeypotName])){const honeypotValue=data.inputs[honeypotName].value;if((0,string_js_1.isStringStrict)(honeypotValue)){const options={status:200,headers:{"Content-Type":"application/json"}};return new Response(JSON.stringify({success:"Form successully sent"}),options)}delete data.inputs[honeypotName]}const action=data.action;if(!(0,string_js_1.isStringStrict)(action))throw new Error("No action");let res=null;const ajaxFn=serverless_js_1.serverlessActions[action];(0,function_js_1.isFunction)(ajaxFn)&&(res=await ajaxFn(data,context));const ajaxResultFilterArgs={data:data,context:context};if(res=await(0,filter_js_1.applyFilters)("ajaxResult",res,ajaxResultFilterArgs,!0),!res)throw new Error("No result");if(res.error)throw new ResponseError_js_1.ResponseError(res.error.message,res.error.response);const options={status:200,headers:{"Content-Type":"application/json"}};let message="";if(res.success){const{message:successMessage,headers:headers}=res.success;(0,string_js_1.isStringStrict)(successMessage)&&(message=successMessage),(0,object_js_1.isObjectStrict)(headers)&&(options.headers={...options.headers,...headers})}return new Response(JSON.stringify({success:message}),options)}catch(error){(0,print_js_1.print)("[FRM] Error with ajax function",error);let statusCode=500,message=error instanceof Error?error.message:"Unknown error";error instanceof ResponseError_js_1.ResponseError&&((0,number_js_1.isNumber)(error.response?.status)&&(statusCode=error.response.status),(0,string_js_1.isStringStrict)(error.message)&&(message=error.message));const options={status:statusCode,headers:{"Content-Type":"application/json"}};return new Response(JSON.stringify({error:message}),options)}};exports.Ajax=Ajax;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Contact=void 0;const config_js_1=require("../../config/config.js"),escape_js_1=require("../../utils/escape/escape.js"),array_js_1=require("../../utils/array/array.js"),string_js_1=require("../../utils/string/string.js"),object_js_1=require("../../utils/object/object.js"),boolean_js_1=require("../../utils/boolean/boolean.js"),objectUtils_js_1=require("../../utils/object/objectUtils.js"),filter_js_1=require("../../utils/filter/filter.js"),link_js_1=require("../../utils/link/link.js"),store_js_1=require("../../store/store.js"),minify_js_1=require("../../utils/minify/minify.js"),recurseEmailHtml=(data,output,depth=1)=>{if(!(0,object_js_1.isObject)(data))return;const isArr=(0,array_js_1.isArray)(data);(0,objectUtils_js_1.getObjectKeys)(data).forEach((label=>{const value=data[label],l=label.toString(),h=depth+1;1===depth&&(output.html+='\n <tr>\n <td style="padding: 16px 0; border-bottom: 2px solid #ccc;">\n '),label&&!isArr&&(output.html+=`\n <h${h} style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.3em">\n ${l}\n </h${h}>\n `,output.plain+=`${l}\n`),recurseEmailHtml(value,output,depth+1),(0,string_js_1.isString)(value)&&(output.html+=`\n <p style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.5em;">\n ${value}\n </p>\n `,output.plain+=value.replace(/<br\s*\/?>/gi,"\n").replace(/(<([^>]+)>)/gi,"")+"\n"),1===depth&&(output.html+="\n </td>\n </tr>\n ",output.plain+="\n")}))},Contact=async args=>{const{id:id,action:action,inputs:inputs}=args;if(!(0,string_js_1.isStringStrict)(id))return{error:{message:"No id"}};if(!(0,object_js_1.isObjectStrict)(inputs)||!Object.keys(inputs).length)return{error:{message:"No inputs"}};const formMetaData=(0,store_js_1.getStoreItem)("formMeta");if(!(0,object_js_1.isObjectStrict)(formMetaData))return{error:{message:"No meta"}};const meta=formMetaData[id];if(!(0,object_js_1.isObjectStrict)(meta))return{error:{message:"No meta object"}};const toEmail=meta.toEmail;if(!(0,string_js_1.isStringStrict)(toEmail))return{error:{message:"No to email"}};const toEmails=toEmail.split(","),senderEmail=meta.senderEmail;if(!(0,string_js_1.isStringStrict)(senderEmail))return{error:{message:"No sender email"}};let subject=(0,string_js_1.isStringStrict)(meta.subject)?meta.subject:"",replyToEmail="";const header=`${config_js_1.config.title} contact form submission`,footer=`This email was sent from a contact form on ${config_js_1.config.title} (${(0,link_js_1.getPermalink)()})`,outputData={},output={html:"",plain:""};for(const[name,input]of Object.entries(inputs)){const inputExclude=input.exclude;if(!!(0,boolean_js_1.isBoolean)(inputExclude)&&inputExclude)continue;const inputType=input.type,inputLabel=input.label.trim(),inputValue=input.value;let inputValueStr="";if((0,array_js_1.isArray)(inputValue)&&(inputValueStr=inputValue.map((v=>(0,escape_js_1.escape)(v.trim()+""))).join("<br>")),(0,string_js_1.isString)(inputValue)&&(inputValueStr=(0,escape_js_1.escape)(inputValue.trim()+"")),"subject"===name){subject=inputValueStr?`${(0,string_js_1.isStringStrict)(subject)?`${subject} - `:""}${inputValueStr}`:subject;continue}"email"===inputType&&inputValueStr&&(replyToEmail=inputValueStr,inputValueStr=`<a href="mailto:${inputValueStr}">${inputValueStr}</a>`);const outputValue=""===inputValueStr?"--":inputValueStr;let hasLegend=!1,legend="";if((0,string_js_1.isStringStrict)(input.legend)&&(hasLegend=!0,legend=input.legend),hasLegend){null==outputData[legend]&&(outputData[legend]={});null==outputData[legend][inputLabel]&&(outputData[legend][inputLabel]=[]),outputData[legend][inputLabel].push(outputValue)}if(!hasLegend){null==outputData[inputLabel]&&(outputData[inputLabel]=[]),outputData[inputLabel].push(outputValue)}}recurseEmailHtml(outputData,output);const outputHtml=`\n <table width="100%" cellpadding="0" cellspacing="0" border="0">\n <tr>\n <td align="center" width="100%" style="padding: 0 16px 16px 16px;">\n <table align="center" cellpadding="0" cellspacing="0" border="0" style="margin-right: auto; margin-left: auto; border-spacing: 0; max-width: 37.5em;">\n <tr>\n <td style="padding: 32px 0 0 0;">\n <h1 style="font-family: sans-serif; color: #222; margin: 0; line-height: 1.3em;">\n ${header}\n </h1>\n </td>\n </tr>\n <tr>\n <td>\n <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;">\n ${output.html}\n <tr>\n <td style="padding: 32px 0;">\n <p style="font-family: sans-serif; color: #222; margin: 0; line-height: 1.5em;">\n ${footer}\n </p>\n </td>\n </tr>\n </table>\n </td>\n </tr>\n </table>\n </td>\n </tr>\n </table>\n `,outputPlain=`${header}\n\n${output.plain}${footer}`;subject||(subject=`${config_js_1.config.title} Contact Form`);const body={id:id,action:action,inputs:inputs,to:toEmails,sender:senderEmail,subject:subject,text:(0,minify_js_1.minify)(outputPlain),html:(0,minify_js_1.minify)(outputHtml)};return replyToEmail&&(body.replyTo=replyToEmail),await(0,filter_js_1.applyFilters)("contactResult",{},body,!0)};exports.Contact=Contact;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Contact=void 0;const config_js_1=require("../../config/config.js"),escape_js_1=require("../../utils/escape/escape.js"),array_js_1=require("../../utils/array/array.js"),string_js_1=require("../../utils/string/string.js"),object_js_1=require("../../utils/object/object.js"),objectUtils_js_1=require("../../utils/object/objectUtils.js"),filter_js_1=require("../../utils/filter/filter.js"),link_js_1=require("../../utils/link/link.js"),store_js_1=require("../../store/store.js"),minify_js_1=require("../../utils/minify/minify.js"),recurseEmailHtml=(data,output,depth=1)=>{if(!(0,object_js_1.isObject)(data))return;const isArr=(0,array_js_1.isArray)(data);(0,objectUtils_js_1.getObjectKeys)(data).forEach((label=>{const value=data[label],l=label.toString(),h=depth+1;1===depth&&(output.html+='\n <tr>\n <td style="padding: 16px 0; border-bottom: 2px solid #ccc;">\n '),label&&!isArr&&(output.html+=`\n <h${h} style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.3em">\n ${l}\n </h${h}>\n `,output.plain+=`${l}\n`),recurseEmailHtml(value,output,depth+1),(0,string_js_1.isString)(value)&&(output.html+=`\n <p style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.5em;">\n ${value}\n </p>\n `,output.plain+=value.replace(/<br\s*\/?>/gi,"\n").replace(/(<([^>]+)>)/gi,"")+"\n"),1===depth&&(output.html+="\n </td>\n </tr>\n ",output.plain+="\n")}))},Contact=async args=>{const{id:id,action:action,inputs:inputs}=args;if(!(0,string_js_1.isStringStrict)(id))return{error:{message:"No id"}};if(!(0,object_js_1.isObjectStrict)(inputs)||!Object.keys(inputs).length)return{error:{message:"No inputs"}};const formMetaData=(0,store_js_1.getStoreItem)("formMeta");if(!(0,object_js_1.isObjectStrict)(formMetaData))return{error:{message:"No meta"}};const meta=formMetaData[id];if(!(0,object_js_1.isObjectStrict)(meta))return{error:{message:"No meta object"}};const toEmail=meta.toEmail;if(!(0,string_js_1.isStringStrict)(toEmail))return{error:{message:"No to email"}};const toEmails=toEmail.split(","),senderEmail=meta.senderEmail;if(!(0,string_js_1.isStringStrict)(senderEmail))return{error:{message:"No sender email"}};let subject=(0,string_js_1.isStringStrict)(meta.subject)?meta.subject:"",replyToEmail="";const header=`${config_js_1.config.title} contact form submission`,footer=`This email was sent from a contact form on ${config_js_1.config.title} (${(0,link_js_1.getPermalink)()})`,outputData={},output={html:"",plain:""};for(const[name,input]of Object.entries(inputs)){const inputType=input.type,inputLabel=input.label?.trim()||`[${name}]`,inputValue=input.value;let inputValueStr="";if(inputValueStr=(0,array_js_1.isArray)(inputValue)?inputValue.map((v=>(0,escape_js_1.escape)(v.toString().trim()))).join("<br>"):(0,escape_js_1.escape)(inputValue.toString().trim()),"subject"===name){subject=inputValueStr?`${(0,string_js_1.isStringStrict)(subject)?`${subject} - `:""}${inputValueStr}`:subject;continue}"email"===inputType&&inputValueStr&&(replyToEmail=inputValueStr,inputValueStr=`<a href="mailto:${inputValueStr}">${inputValueStr}</a>`);const outputValue=""===inputValueStr?"--":inputValueStr;let hasLegend=!1,legend="";if((0,string_js_1.isStringStrict)(input.legend)&&(hasLegend=!0,legend=input.legend),hasLegend){null==outputData[legend]&&(outputData[legend]={});null==outputData[legend][inputLabel]&&(outputData[legend][inputLabel]=[]),outputData[legend][inputLabel].push(outputValue)}if(!hasLegend){null==outputData[inputLabel]&&(outputData[inputLabel]=[]),outputData[inputLabel].push(outputValue)}}recurseEmailHtml(outputData,output);const outputHtml=`\n <table width="100%" cellpadding="0" cellspacing="0" border="0">\n <tr>\n <td align="center" width="100%" style="padding: 0 16px 16px 16px;">\n <table align="center" cellpadding="0" cellspacing="0" border="0" style="margin-right: auto; margin-left: auto; border-spacing: 0; max-width: 37.5em;">\n <tr>\n <td style="padding: 32px 0 0 0;">\n <h1 style="font-family: sans-serif; color: #222; margin: 0; line-height: 1.3em;">\n ${header}\n </h1>\n </td>\n </tr>\n <tr>\n <td>\n <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;">\n ${output.html}\n <tr>\n <td style="padding: 32px 0;">\n <p style="font-family: sans-serif; color: #222; margin: 0; line-height: 1.5em;">\n ${footer}\n </p>\n </td>\n </tr>\n </table>\n </td>\n </tr>\n </table>\n </td>\n </tr>\n </table>\n `,outputPlain=`${header}\n\n${output.plain}${footer}`;subject||(subject=`${config_js_1.config.title} Contact Form`);const body={id:id,action:action,inputs:inputs,to:toEmails,sender:senderEmail,subject:subject,text:(0,minify_js_1.minify)(outputPlain),html:(0,minify_js_1.minify)(outputHtml)};return replyToEmail&&(body.replyTo=replyToEmail),await(0,filter_js_1.applyFilters)("contactResult",{},body,!0)};exports.Contact=Contact;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Preview=void 0;const string_js_1=require("../../utils/string/string.js"),object_js_1=require("../../utils/object/object.js"),function_js_1=require("../../utils/function/function.js"),render_js_1=require("../../render/render.js"),minify_js_1=require("../../utils/minify/minify.js"),Preview=async(context,setupServerless,getData)=>{const{request:request,next:next}=context,{searchParams:searchParams}=new URL(request.url),contentType=searchParams.get("content_type"),id=searchParams.get("preview");if(!(0,string_js_1.isStringStrict)(id)||!(0,string_js_1.isStringStrict)(contentType))return next();await setupServerless(context,"preview");const previewData={id:id,contentType:contentType},data=await(0,render_js_1.render)({previewData:previewData,allData:await getData({previewData:previewData})});let html="",status=200;(0,object_js_1.isObjectStrict)(data)&&(html=data.output);const isEmpty=""===html;return isEmpty&&(status=404),isEmpty&&(0,function_js_1.isFunction)(render_js_1.renderHttpError)&&(html=await(0,render_js_1.renderHttpError)({code:status})),new Response((0,minify_js_1.minify)(html),{status:status,headers:{"Content-Type":"text/html;charset=UTF-8"}})};exports.Preview=Preview;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Preview=void 0;const string_js_1=require("../../utils/string/string.js"),object_js_1=require("../../utils/object/object.js"),function_js_1=require("../../utils/function/function.js"),render_js_1=require("../../render/render.js"),minify_js_1=require("../../utils/minify/minify.js"),Preview=async(context,setupServerless,getData)=>{const{request:request,next:next}=context,{searchParams:searchParams}=new URL(request.url),contentType=searchParams.get("content_type"),locale=searchParams.get("locale"),id=searchParams.get("preview");if(!(0,string_js_1.isStringStrict)(id)||!(0,string_js_1.isStringStrict)(contentType))return next();await setupServerless(context,"preview");const previewData={id:id,contentType:contentType};(0,string_js_1.isStringStrict)(locale)&&(previewData.locale=locale);const data=await(0,render_js_1.render)({previewData:previewData,allData:await getData({previewData:previewData})});let html="",status=200;(0,object_js_1.isObjectStrict)(data)&&(html=data.output);const isEmpty=""===html;return isEmpty&&(status=404),isEmpty&&(0,function_js_1.isFunction)(render_js_1.renderHttpError)&&(html=await(0,render_js_1.renderHttpError)({code:status})),new Response((0,minify_js_1.minify)(html),{status:status,headers:{"Content-Type":"text/html;charset=UTF-8"}})};exports.Preview=Preview;
@@ -8,11 +8,10 @@ export type ServerlessRoutes = Record<string, ServerlessRoute[]>;
8
8
  export type ServerlessContext = EventContext<GenericStrings, string, unknown>;
9
9
  export type ServerlessSetup = (context: ServerlessContext, type?: string) => Promise<void> | void;
10
10
  export interface ServerlessActionInput extends Generic {
11
- type: string;
12
- label: string;
13
- value: string | string[];
11
+ type: string | string[];
12
+ value: string | boolean | number | string[] | number[];
13
+ label?: string;
14
14
  legend?: string;
15
- exclude?: boolean;
16
15
  }
17
16
  export interface ServerlessActionData {
18
17
  id: string;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getStoreItem=exports.setStoreItem=exports.setStoreData=exports.setStore=exports.storeDir=exports.store=void 0;const contentType_js_1=require("../utils/contentType/contentType.js"),object_js_1=require("../utils/object/object.js"),string_js_1=require("../utils/string/string.js"),array_js_1=require("../utils/array/array.js"),config_js_1=require("../config/config.js");let storeDir="lib/store";exports.storeDir=storeDir;const defaultStore={slugs:{},parents:{},navigations:[],navigationItems:[],formMeta:{},archiveMeta:{},imageMeta:{},taxonomies:{}};let store={...defaultStore};exports.store=store;const setStore=(args,dir="lib/store")=>(0,object_js_1.isObjectStrict)(args)?(exports.store=store={...defaultStore,...args},(0,string_js_1.isStringStrict)(dir)&&(exports.storeDir=storeDir=dir),store):store;exports.setStore=setStore;const setStoreItem=(prop,value,subProp)=>!(!(0,string_js_1.isStringStrict)(prop)||!(0,object_js_1.isObject)(value)||null==store[prop])&&((0,string_js_1.isStringStrict)(subProp)?store[prop][subProp]=value:store[prop]=value,!0);exports.setStoreItem=setStoreItem;const setStoreData=allData=>{if(!(0,object_js_1.isObjectStrict)(allData))return!1;const{navigation:navigation,navigationItem:navigationItem,content:content}=allData;store.navigations=(0,array_js_1.isArrayStrict)(navigation)?navigation:[],store.navigationItems=(0,array_js_1.isArrayStrict)(navigationItem)?navigationItem:[];const data={...allData,...content};return config_js_1.config.hierarchicalTypes.forEach((type=>{const items=data[type];(0,array_js_1.isArrayStrict)(items)&&items.forEach((item=>{if(!(0,object_js_1.isObjectStrict)(item))return;const{id:id,parent:parent,archive:archive,slug:slug,title:title}=item;if(!(0,string_js_1.isStringStrict)(id))return;const archiveType=(0,contentType_js_1.normalizeContentType)(archive);if((0,string_js_1.isStringStrict)(archiveType)){const archiveObj=(0,object_js_1.isObjectStrict)(store.archiveMeta[archiveType])?store.archiveMeta[archiveType]:{};store.archiveMeta[archiveType]={id:id,slug:slug,title:title,contentType:type,...archiveObj}}if((0,object_js_1.isObjectStrict)(parent)){const parentSlug=parent.slug,parentTitle=parent.title,parentId=parent.id;(0,string_js_1.isStringStrict)(parentSlug)&&(0,string_js_1.isStringStrict)(parentTitle)&&(0,string_js_1.isStringStrict)(parentId)&&(null==store.parents[type]&&(store.parents[type]={}),store.parents[type][id]={id:parentId,slug:parentSlug,title:parentTitle})}}))})),!0};exports.setStoreData=setStoreData;const getStoreItem=prop=>store[prop];exports.getStoreItem=getStoreItem;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getStoreItem=exports.setStoreItem=exports.setStoreData=exports.setStore=exports.storeDir=exports.store=void 0;const contentType_js_1=require("../utils/contentType/contentType.js"),object_js_1=require("../utils/object/object.js"),string_js_1=require("../utils/string/string.js"),array_js_1=require("../utils/array/array.js"),archive_js_1=require("../utils/archive/archive.js"),config_js_1=require("../config/config.js");let storeDir="lib/store";exports.storeDir=storeDir;const defaultStore={slugs:{},parents:{},navigations:[],navigationItems:[],formMeta:{},archiveMeta:{},imageMeta:{},taxonomies:{}};let store={...defaultStore};exports.store=store;const setStore=(args,dir="lib/store")=>(0,object_js_1.isObjectStrict)(args)?(exports.store=store={...defaultStore,...args},(0,string_js_1.isStringStrict)(dir)&&(exports.storeDir=storeDir=dir),store):store;exports.setStore=setStore;const setStoreItem=(prop,value,subProp)=>!(!(0,string_js_1.isStringStrict)(prop)||!(0,object_js_1.isObject)(value)||null==store[prop])&&((0,string_js_1.isStringStrict)(subProp)?store[prop][subProp]=value:store[prop]=value,!0);exports.setStoreItem=setStoreItem;const setStoreData=allData=>{if(!(0,object_js_1.isObjectStrict)(allData))return!1;const{navigation:navigation,navigationItem:navigationItem,content:content}=allData;store.navigations=(0,array_js_1.isArrayStrict)(navigation)?navigation:[],store.navigationItems=(0,array_js_1.isArrayStrict)(navigationItem)?navigationItem:[];const data={...allData,...content};return config_js_1.config.hierarchicalTypes.forEach((type=>{const items=data[type];(0,array_js_1.isArrayStrict)(items)&&items.forEach((item=>{if(!(0,object_js_1.isObjectStrict)(item))return;const{id:id,parent:parent,archive:archive,slug:slug,title:title,locale:locale}=item;if(!(0,string_js_1.isStringStrict)(id))return;const archiveType=(0,contentType_js_1.normalizeContentType)(archive);if((0,string_js_1.isStringStrict)(archiveType)){const hasLocale=(0,string_js_1.isStringStrict)(locale),archiveMeta=(0,archive_js_1.getArchiveMeta)(archiveType,locale),newArchive={id:id,slug:slug,title:title,contentType:type,...archiveMeta};hasLocale?(store.archiveMeta[archiveType]||(store.archiveMeta[archiveType]={}),store.archiveMeta[archiveType][locale]=newArchive):store.archiveMeta[archiveType]=newArchive}if((0,object_js_1.isObjectStrict)(parent)){const parentSlug=parent.slug,parentTitle=parent.title,parentId=parent.id;(0,string_js_1.isStringStrict)(parentSlug)&&(0,string_js_1.isStringStrict)(parentTitle)&&(0,string_js_1.isStringStrict)(parentId)&&(null==store.parents[type]&&(store.parents[type]={}),store.parents[type][id]={id:parentId,slug:parentSlug,title:parentTitle})}}))})),!0};exports.setStoreData=setStoreData;const getStoreItem=prop=>store[prop];exports.getStoreItem=getStoreItem;
@@ -1,35 +1,26 @@
1
+ import type { Generic, Parent, Taxonomy } from '../global/globalTypes.js';
1
2
  import type { NavigationList, NavigationItem } from '../components/Navigation/NavigationTypes.js';
3
+ import type { ArchiveMeta } from '../utils/archive/archiveTypes.js';
2
4
  import type { ImageProps } from '../utils/image/imageTypes.js';
3
5
  import type { FormMeta } from '../objects/Form/FormTypes.js';
4
- import type { Generic, Taxonomy } from '../global/globalTypes.js';
5
6
  export interface StoreSlug {
6
7
  contentType: string;
7
8
  id: string;
9
+ locale?: string;
8
10
  }
9
- export interface StoreParent {
10
- id: string;
11
- slug: string;
12
- title: string;
13
- }
14
- export interface StoreArchiveMeta {
15
- id?: string;
16
- slug?: string;
17
- title?: string;
18
- contentType?: string;
19
- singular?: string;
20
- plural?: string;
21
- layout?: string;
22
- order?: string;
23
- display?: number;
24
- }
11
+ export type StoreSlugs = Record<string, StoreSlug>;
12
+ export type StoreParents = Record<string, Record<string, Parent>>;
13
+ export type StoreArchiveMeta = Record<string, ArchiveMeta | Record<string, ArchiveMeta>>;
14
+ export type StoreFormMeta = Record<string, FormMeta>;
25
15
  export type StoreImageMeta = Record<string, ImageProps>;
16
+ export type StoreTaxonomies = Record<string, Taxonomy>;
26
17
  export interface Store extends Generic {
27
- slugs: Record<string, StoreSlug>;
28
- parents: Record<string, Record<string, StoreParent>>;
29
- archiveMeta: Record<string, StoreArchiveMeta>;
30
- formMeta: Record<string, FormMeta>;
18
+ slugs: StoreSlugs;
19
+ parents: StoreParents;
20
+ archiveMeta: StoreArchiveMeta;
21
+ formMeta: StoreFormMeta;
31
22
  imageMeta: StoreImageMeta;
32
23
  navigations: NavigationList[];
33
24
  navigationItems: NavigationItem[];
34
- taxonomies: Record<string, Taxonomy>;
25
+ taxonomies: StoreTaxonomies;
35
26
  }
@@ -1,7 +1,10 @@
1
- import type { ArchiveInfo, ArchiveTaxonomy, ArchiveLink, ArchiveLabels } from './archiveTypes.js';
1
+ import type { ArchiveInfo, ArchiveTaxonomy, ArchiveLink, ArchiveLabels, ArchiveMeta } from './archiveTypes.js';
2
2
  import type { RenderItem } from '../../render/renderTypes.js';
3
- declare const getArchiveInfo: (contentType: string) => ArchiveInfo;
4
- declare const getTaxonomyInfo: (contentType: string, pageData?: RenderItem) => ArchiveTaxonomy;
5
- declare const getArchiveLink: (contentType: string, pageData?: RenderItem) => ArchiveLink;
6
- declare const getArchiveLabels: (contentType: string, pageData?: RenderItem) => ArchiveLabels;
7
- export { getArchiveInfo, getTaxonomyInfo, getArchiveLink, getArchiveLabels };
3
+ declare const isTerm: (contentType: string, itemData: RenderItem) => boolean;
4
+ declare const isArchive: (contentType: string, itemData: RenderItem) => boolean;
5
+ declare const getArchiveMeta: (contentType: string, locale?: string) => ArchiveMeta;
6
+ declare const getArchiveInfo: (contentType: string, locale?: string) => ArchiveInfo;
7
+ declare const getTaxonomyInfo: (contentType: string, itemData?: RenderItem) => ArchiveTaxonomy;
8
+ declare const getArchiveLink: (contentType: string, itemData?: RenderItem) => ArchiveLink;
9
+ declare const getArchiveLabels: (contentType: string, itemData?: RenderItem) => ArchiveLabels;
10
+ export { isTerm, isArchive, getArchiveMeta, getArchiveInfo, getTaxonomyInfo, getArchiveLink, getArchiveLabels };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getArchiveLabels=exports.getArchiveLink=exports.getTaxonomyInfo=exports.getArchiveInfo=void 0;const store_js_1=require("../../store/store.js"),object_js_1=require("../object/object.js"),array_js_1=require("../array/array.js"),string_js_1=require("../string/string.js"),boolean_js_1=require("../boolean/boolean.js"),contentType_js_1=require("../contentType/contentType.js"),link_js_1=require("../link/link.js"),getArchiveInfo=contentType=>{const value={id:"",slug:"",title:"",contentType:""};if("page"===(contentType=(0,contentType_js_1.normalizeContentType)(contentType)))return value;const info=(0,store_js_1.getStoreItem)("archiveMeta")[contentType];if(!(0,object_js_1.isObjectStrict)(info))return value;const{id:id,slug:slug,title:title,contentType:type}=info;return value.id=(0,string_js_1.isStringStrict)(id)?id:"",value.slug=(0,string_js_1.isStringStrict)(slug)?slug:"",value.title=(0,string_js_1.isStringStrict)(title)?title:"",value.contentType=(0,string_js_1.isStringStrict)(type)?type:"",value};exports.getArchiveInfo=getArchiveInfo;const getTaxonomyInfo=(contentType,pageData)=>{const value={id:"",slug:"",title:"",contentTypes:[],primaryContentType:"",usePrimaryContentTypeSlug:!0,isPage:!1},taxObj="taxonomy"===contentType?pageData:pageData?.taxonomy;if(!(0,object_js_1.isObjectStrict)(taxObj))return value;const{id:id,slug:slug,link:link,title:title,contentTypes:contentTypes,usePrimaryContentTypeSlug:usePrimaryContentTypeSlug,isPage:isPage}=taxObj,taxonomyTypes=(0,array_js_1.isArrayStrict)(contentTypes)?contentTypes.map((type=>(0,contentType_js_1.normalizeContentType)(type))):[],primaryTaxonomyType=taxonomyTypes[0];return value.id=(0,string_js_1.isStringStrict)(id)?id:"",value.slug=(0,string_js_1.isStringStrict)(slug)?slug:"",value.title=(0,string_js_1.isStringStrict)(title)?title:"",value.contentTypes=taxonomyTypes,value.primaryContentType=(0,string_js_1.isStringStrict)(primaryTaxonomyType)?primaryTaxonomyType:"",value.usePrimaryContentTypeSlug=!(0,boolean_js_1.isBoolean)(usePrimaryContentTypeSlug)||usePrimaryContentTypeSlug,value.isPage=!!(0,boolean_js_1.isBoolean)(isPage)&&isPage,(0,string_js_1.isStringStrict)(link)&&(value.link=link),value};exports.getTaxonomyInfo=getTaxonomyInfo;const getArchiveLink=(contentType,pageData)=>{let slug,title="";const taxonomyInfo=getTaxonomyInfo(contentType,pageData),{title:taxonomyTitle,isPage:taxonomyIsPage,contentTypes:taxonomyTypes,usePrimaryContentTypeSlug:taxonomyUseTypeSlug}=taxonomyInfo;"term"===contentType&&taxonomyIsPage&&(slug=(0,link_js_1.getSlug)({slug:"",contentType:contentType,pageData:pageData}),title=taxonomyTitle);const taxonomyType=taxonomyTypes[0],useArchiveType=taxonomyUseTypeSlug&&(0,string_js_1.isStringStrict)(taxonomyType);"taxonomy"===contentType&&useArchiveType&&(contentType=taxonomyType),"term"===contentType&&!taxonomyIsPage&&useArchiveType&&(contentType=taxonomyType);const archiveInfo=getArchiveInfo(contentType),{id:archiveId,slug:archiveSlug,title:archiveTitle,contentType:archiveType}=archiveInfo;if(archiveSlug&&archiveId){slug=(0,link_js_1.getSlug)({id:archiveId,slug:archiveSlug,contentType:archiveType});const plural=(0,store_js_1.getStoreItem)("archiveMeta")[contentType]?.plural;title=(0,string_js_1.isStringStrict)(plural)?plural:archiveTitle}return{title:title,link:(0,string_js_1.isStringStrict)(slug)?(0,link_js_1.getPermalink)(slug):""}};exports.getArchiveLink=getArchiveLink;const getArchiveLabels=(contentType,pageData)=>{let singular="Post",plural="Posts";const taxonomyInfo=getTaxonomyInfo(contentType,pageData),{title:taxonomyTitle,isPage:taxonomyIsPage,primaryContentType:taxonomyType,usePrimaryContentTypeSlug:taxonomyUseTypeSlug}=taxonomyInfo;if("term"===contentType&&taxonomyIsPage&&(0,string_js_1.isStringStrict)(taxonomyTitle))return{singular:taxonomyTitle,plural:taxonomyTitle};const useArchiveType=taxonomyUseTypeSlug&&(0,string_js_1.isStringStrict)(taxonomyType);if("taxonomy"===contentType&&useArchiveType&&(contentType=taxonomyType),"term"===contentType&&!taxonomyIsPage&&useArchiveType&&(contentType=taxonomyType),(0,string_js_1.isStringStrict)(contentType)){contentType=(0,contentType_js_1.normalizeContentType)(contentType);const archiveType=(0,store_js_1.getStoreItem)("archiveMeta")[contentType],s=archiveType?.singular,p=archiveType?.plural;singular=(0,string_js_1.isStringStrict)(s)?s:"Post",plural=(0,string_js_1.isStringStrict)(p)?p:"Posts"}return{singular:singular,plural:plural}};exports.getArchiveLabels=getArchiveLabels;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getArchiveLabels=exports.getArchiveLink=exports.getTaxonomyInfo=exports.getArchiveInfo=exports.getArchiveMeta=exports.isArchive=exports.isTerm=void 0;const store_js_1=require("../../store/store.js"),object_js_1=require("../object/object.js"),array_js_1=require("../array/array.js"),string_js_1=require("../string/string.js"),boolean_js_1=require("../boolean/boolean.js"),contentType_js_1=require("../contentType/contentType.js"),link_js_1=require("../link/link.js"),isTerm=(contentType,itemData)=>{if(!(0,object_js_1.isObjectStrict)(itemData))return!1;const{contentType:type,taxonomy:taxonomy}=itemData;return!("term"!==type||!(0,object_js_1.isObjectStrict)(taxonomy))&&taxonomy.contentTypes.includes(contentType)};exports.isTerm=isTerm;const isArchive=(contentType,itemData)=>{if(!(0,object_js_1.isObjectStrict)(itemData))return!1;const{archive:archive}=itemData;return archive===contentType||isTerm(contentType,itemData)};exports.isArchive=isArchive;const getArchiveMeta=(contentType,locale)=>{const archiveMeta=(0,store_js_1.getStoreItem)("archiveMeta")[contentType];return(0,object_js_1.isObjectStrict)(archiveMeta)?(0,string_js_1.isStringStrict)(locale)&&(0,object_js_1.isObjectStrict)(archiveMeta[locale])?archiveMeta[locale]:archiveMeta:{}};exports.getArchiveMeta=getArchiveMeta;const getArchiveInfo=(contentType,locale)=>{const value={id:"",slug:"",title:"",contentType:""};if("page"===(contentType=(0,contentType_js_1.normalizeContentType)(contentType)))return value;const{id:id,slug:slug,title:title,contentType:type}=getArchiveMeta(contentType,locale);return value.id=(0,string_js_1.isStringStrict)(id)?id:"",value.slug=(0,string_js_1.isStringStrict)(slug)?slug:"",value.title=(0,string_js_1.isStringStrict)(title)?title:"",value.contentType=(0,string_js_1.isStringStrict)(type)?type:"",value};exports.getArchiveInfo=getArchiveInfo;const getTaxonomyInfo=(contentType,itemData)=>{const value={id:"",slug:"",title:"",contentTypes:[],primaryContentType:"",usePrimaryContentTypeSlug:!0,isPage:!1},taxObj="taxonomy"===contentType?itemData:itemData?.taxonomy;if(!(0,object_js_1.isObjectStrict)(taxObj))return value;const{id:id,slug:slug,link:link,title:title,contentTypes:contentTypes,usePrimaryContentTypeSlug:usePrimaryContentTypeSlug,isPage:isPage}=taxObj,taxonomyTypes=(0,array_js_1.isArrayStrict)(contentTypes)?contentTypes.map((type=>(0,contentType_js_1.normalizeContentType)(type))):[],primaryTaxonomyType=taxonomyTypes[0];return value.id=(0,string_js_1.isStringStrict)(id)?id:"",value.slug=(0,string_js_1.isStringStrict)(slug)?slug:"",value.title=(0,string_js_1.isStringStrict)(title)?title:"",value.contentTypes=taxonomyTypes,value.primaryContentType=(0,string_js_1.isStringStrict)(primaryTaxonomyType)?primaryTaxonomyType:"",value.usePrimaryContentTypeSlug=!(0,boolean_js_1.isBoolean)(usePrimaryContentTypeSlug)||usePrimaryContentTypeSlug,value.isPage=!!(0,boolean_js_1.isBoolean)(isPage)&&isPage,(0,string_js_1.isStringStrict)(link)&&(value.link=link),value};exports.getTaxonomyInfo=getTaxonomyInfo;const getArchiveLink=(contentType,itemData)=>{let slug,title="";const taxonomyInfo=getTaxonomyInfo(contentType,itemData),{title:taxonomyTitle,isPage:taxonomyIsPage,contentTypes:taxonomyTypes,usePrimaryContentTypeSlug:taxonomyUseTypeSlug}=taxonomyInfo;"term"===contentType&&taxonomyIsPage&&(slug=(0,link_js_1.getSlug)({slug:"",contentType:contentType,itemData:itemData}),title=taxonomyTitle);const taxonomyType=taxonomyTypes[0],useArchiveType=taxonomyUseTypeSlug&&(0,string_js_1.isStringStrict)(taxonomyType);"taxonomy"===contentType&&useArchiveType&&(contentType=taxonomyType),"term"===contentType&&!taxonomyIsPage&&useArchiveType&&(contentType=taxonomyType);const archiveInfo=getArchiveInfo(contentType),{id:archiveId,slug:archiveSlug,title:archiveTitle,contentType:archiveType}=archiveInfo;return archiveSlug&&archiveId&&(slug=(0,link_js_1.getSlug)({id:archiveId,slug:archiveSlug,contentType:archiveType}),title=getArchiveLabel(contentType,itemData,"plural",archiveTitle)),{title:title,link:(0,string_js_1.isStringStrict)(slug)?(0,link_js_1.getPermalink)(slug):""}};exports.getArchiveLink=getArchiveLink;const getArchiveLabel=(contentType,itemData,labelType="singular",fallback)=>{fallback=(0,string_js_1.isStringStrict)(fallback)?fallback:"singular"===labelType?"Post":"Posts";const label=getArchiveMeta(contentType,itemData?.locale)[labelType];return(0,string_js_1.isStringStrict)(label)?label:fallback},getArchiveLabels=(contentType,itemData)=>{let singular="Post",plural="Posts";const taxonomyInfo=getTaxonomyInfo(contentType,itemData),{title:taxonomyTitle,isPage:taxonomyIsPage,primaryContentType:taxonomyType,usePrimaryContentTypeSlug:taxonomyUseTypeSlug}=taxonomyInfo;if("term"===contentType&&taxonomyIsPage&&(0,string_js_1.isStringStrict)(taxonomyTitle))return{singular:taxonomyTitle,plural:taxonomyTitle};const useArchiveType=taxonomyUseTypeSlug&&(0,string_js_1.isStringStrict)(taxonomyType);return"taxonomy"===contentType&&useArchiveType&&(contentType=taxonomyType),"term"===contentType&&!taxonomyIsPage&&useArchiveType&&(contentType=taxonomyType),(0,string_js_1.isStringStrict)(contentType)&&(contentType=(0,contentType_js_1.normalizeContentType)(contentType),singular=getArchiveLabel(contentType,itemData),plural=getArchiveLabel(contentType,itemData,"plural")),{singular:singular,plural:plural}};exports.getArchiveLabels=getArchiveLabels;