@alanizcreative/formation-static 1.3.0-beta.46 → 1.3.0-beta.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/config/config.js +1 -1
- package/cjs/config/configTypes.d.ts +2 -2
- package/cjs/objects/Form/FormTypes.d.ts +1 -1
- package/cjs/serverless/Contact/Contact.js +1 -1
- package/cjs/serverless/serverlessTypes.d.ts +2 -1
- package/cjs/utils/file/file.d.ts +3 -0
- package/cjs/utils/file/file.js +1 -0
- package/cjs/wordpress/wordpressDataNormal.js +1 -1
- package/lib/config/config.js +1 -1
- package/lib/config/configTypes.d.ts +2 -2
- package/lib/objects/Form/FormTypes.d.ts +1 -1
- package/lib/serverless/Contact/Contact.js +1 -1
- package/lib/serverless/serverlessTypes.d.ts +2 -1
- package/lib/utils/file/file.d.ts +3 -0
- package/lib/utils/file/file.js +1 -0
- package/lib/wordpress/wordpressDataNormal.js +1 -1
- package/package.json +1 -1
package/cjs/config/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setConfigFilter=exports.setConfig=exports.config=void 0;let config={namespace:"frm",source:"cms",title:"",meta:{description:"",image:""},partialTypes:[],wholeTypes:[],hierarchicalTypes:[],localeInSlug:{},typeInSlug:{},taxonomyInSlug:{},normalTypes:{},renderTypes:{},env:{dev:!0,prod:!1,build:!1,cache:!1,dir:"",devUrl:"",prodUrl:""},cms:{name:"",space:"",prodUser:"",prodCredential:"",prodHost:"",devUser:"",devCredential:"",devHost:""},local:{dir:"json"},scripts:{inputDir:"lib",outputDir:"js"},styles:{inputDir:"src",outputDir:"css"},image:{inputDir:"src/assets/img",outputDir:"site/assets/img",localUrl:"/assets/img",remoteUrl:"",quality:75,sizes:[200,400,600,800,1e3,1200,1600,2e3]},filter:config=>config};exports.config=config;const setConfig=args=>(exports.config=config={...config,...args},config);exports.setConfig=setConfig;const setConfigFilter=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setConfigFilter=exports.setConfig=exports.config=void 0;let config={namespace:"frm",source:"cms",title:"",meta:{description:"",image:""},partialTypes:[],wholeTypes:[],hierarchicalTypes:[],localeInSlug:{},typeInSlug:{},taxonomyInSlug:{},normalTypes:{},renderTypes:{},env:{dev:!0,prod:!1,build:!1,cache:!1,dir:"",devUrl:"",prodUrl:""},cms:{name:"",space:"",prodUser:"",prodCredential:"",prodHost:"",devUser:"",devCredential:"",devHost:""},local:{dir:"json"},scripts:{inputDir:"lib",outputDir:"js"},styles:{inputDir:"src",outputDir:"css"},image:{inputDir:"src/assets/img",outputDir:"site/assets/img",localUrl:"/assets/img",remoteUrl:"",quality:75,sizes:[200,400,600,800,1e3,1200,1600,2e3]},filter:config=>config};exports.config=config;const setConfig=args=>(exports.config=config={...config,...args},config);exports.setConfig=setConfig;const setConfigFilter=env=>(exports.config=config=config.filter(config,env),config);exports.setConfigFilter=setConfigFilter;
|
|
@@ -40,7 +40,7 @@ export interface ConfigImage {
|
|
|
40
40
|
sizes: number[];
|
|
41
41
|
quality: number;
|
|
42
42
|
}
|
|
43
|
-
export type ConfigFilter = (config: Config, env: Generic) => Config
|
|
43
|
+
export type ConfigFilter = (config: Config, env: Generic) => Config;
|
|
44
44
|
export interface Config {
|
|
45
45
|
namespace: string;
|
|
46
46
|
source: Source;
|
|
@@ -63,4 +63,4 @@ export interface Config {
|
|
|
63
63
|
filter: ConfigFilter;
|
|
64
64
|
}
|
|
65
65
|
export type ConfigSet = (args: Partial<Config>) => Config;
|
|
66
|
-
export type ConfigSetFilter = (env: Generic) => Config
|
|
66
|
+
export type ConfigSetFilter = (env: Generic) => Config;
|
|
@@ -30,7 +30,7 @@ export interface FormMeta {
|
|
|
30
30
|
senderEmail?: string;
|
|
31
31
|
}
|
|
32
32
|
export type FormPropsFilter<A = FormArgs, R = RenderItem> = (props: FormProps<A, R>) => FormProps<A, R>;
|
|
33
|
-
export type FormFieldType = 'text' | 'email' | 'checkbox' | 'radio' | 'number' | 'password' | 'tel' | 'url' | 'textarea' | 'select' | 'radio-group' | 'checkbox-group' | 'fieldset' | 'hidden';
|
|
33
|
+
export type FormFieldType = 'text' | 'email' | 'checkbox' | 'radio' | 'number' | 'password' | 'tel' | 'url' | 'textarea' | 'select' | 'radio-group' | 'checkbox-group' | 'fieldset' | 'hidden' | 'file';
|
|
34
34
|
export interface FormFieldArgs extends Generic {
|
|
35
35
|
type?: FormFieldType;
|
|
36
36
|
name?: string;
|
|
@@ -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"),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,html,plain,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&&(html.ref+='\n <tr>\n <td style="padding: 16px 0; border-bottom: 2px solid #ccc;">\n '),label&&!isArr&&(html.ref+=`\n <h${h} style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.3em">\n ${l}\n </h${h}>\n `,plain.ref+=`${l}\n`),recurseEmailHtml(value,html,plain,depth+1),(0,string_js_1.isString)(value)&&(html.ref+=`\n <p style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.5em;">\n ${value}\n </p>\n `,plain.ref+=value.replace(/<br\s*\/?>/gi,"\n").replace(/(<([^>]+)>)/gi,"")+"\n"),1===depth&&(html.ref+="\n </td>\n </tr>\n ",plain.ref+="\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={},html={ref:""},plain={ref:""};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,html,plain);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 ${html.ref}\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${plain.ref}${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"),file_js_1=require("../../utils/file/file.js"),recurseEmailHtml=(data,html,plain,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&&(html.ref+='\n <tr>\n <td style="padding: 16px 0; border-bottom: 2px solid #ccc;">\n '),label&&!isArr&&(html.ref+=`\n <h${h} style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.3em">\n ${l}\n </h${h}>\n `,plain.ref+=`${l}\n`),recurseEmailHtml(value,html,plain,depth+1),(0,string_js_1.isString)(value)&&(html.ref+=`\n <p style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.5em;">\n ${value}\n </p>\n `,plain.ref+=value.replace(/<br\s*\/?>/gi,"\n").replace(/(<([^>]+)>)/gi,"")+"\n"),1===depth&&(html.ref+="\n </td>\n </tr>\n ",plain.ref+="\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={},html={ref:""},plain={ref:""};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,file_js_1.isFile)(v)?v.name:(0,escape_js_1.escape)(v.toString().trim())).join("<br>"):(0,file_js_1.isFile)(inputValue)?inputValue.name:(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,html,plain);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 ${html.ref}\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${plain.ref}${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;
|
|
@@ -3,9 +3,10 @@ export interface ServerlessRoute {
|
|
|
3
3
|
path: string;
|
|
4
4
|
content?: string;
|
|
5
5
|
}
|
|
6
|
+
export type ServerlessActionPrimitive = string | number | boolean | File;
|
|
6
7
|
export interface ServerlessActionInput extends Generic {
|
|
8
|
+
value: ServerlessActionPrimitive | ServerlessActionPrimitive[];
|
|
7
9
|
type: string | string[];
|
|
8
|
-
value: string | boolean | number | string[] | number[];
|
|
9
10
|
label?: string;
|
|
10
11
|
legend?: string;
|
|
11
12
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isBlob=exports.isFile=void 0;const isFile=value=>value instanceof File;exports.isFile=isFile;const isBlob=value=>value instanceof Blob;exports.isBlob=isBlob;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.normalMetaKeys=exports.normalRoutes=exports.normalizeWordPressMenus=exports.normalizeWordPressMenuItems=exports.normalizeWordPressData=void 0;const block_serialization_default_parser_1=require("@wordpress/block-serialization-default-parser"),contentType_js_1=require("../utils/contentType/contentType.js"),objectUtils_js_1=require("../utils/object/objectUtils.js"),store_js_1=require("../store/store.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"),config_js_1=require("../config/config.js"),normalRoutes=new Map([["page","pages"],["post","posts"],["taxonomy","taxonomies"],["category","categories"],["tag","tags"],["attachment","media"],["nav_menu","menus"],["nav_menu_item","menu-items"]]);exports.normalRoutes=normalRoutes;const normalMetaKeys=new Map;exports.normalMetaKeys=normalMetaKeys;const menusById=new Map,excludeProps=["_links","auto_add"],getTaxonomy=id=>{const taxonomy=(0,store_js_1.getStoreItem)("taxonomies")[id],{title:title="",slug:slug="",contentTypes:contentTypes=[]}=(0,object_js_1.isObjectStrict)(taxonomy)?taxonomy:{};return{id:id,title:title,slug:slug,contentTypes:contentTypes}},normalizeFile=file=>{const{url:url,filename:filename,alt:alt,width:width,height:height,filesizeInBytes:filesizeInBytes,subtype:subtype,mime:mime,sizes:sizes}=file;let s;if((0,object_js_1.isObjectStrict)(sizes)){s={};for(const[,value]of Object.entries(sizes)){const{width:width,source_url:src}=value;let{url:url}=value;(0,string_js_1.isStringStrict)(src)&&(url=src),(0,number_js_1.isNumber)(width)&&(0,string_js_1.isStringStrict)(url)&&(s[width]=url)}}return{url:(0,string_js_1.isString)(url)?url:"",name:(0,string_js_1.isString)(filename)?filename:"",alt:(0,string_js_1.isString)(alt)?alt:"",width:(0,number_js_1.isNumber)(width)?width:0,height:(0,number_js_1.isNumber)(height)?height:0,size:(0,number_js_1.isNumber)(filesizeInBytes)?filesizeInBytes:0,format:"jpeg"===subtype?"jpg":subtype,type:mime,sizes:s}},normalizeEmbedded=(value,item,newItem)=>{(0,objectUtils_js_1.getObjectKeys)(value).forEach(k=>{const embeds=value[k];if((0,array_js_1.isArrayStrict)(embeds)){if("author"===k){const exclude=[...excludeProps,"id","avatar_urls"];embeds.forEach(embed=>{if(!(0,object_js_1.isObjectStrict)(embed))return;const{id:id}=embed;if(item.author!==id)return;const newAuthor={id:id.toString()};Object.entries(embed).forEach(([key,val])=>{exclude.includes(key)||(newAuthor[key]=val)}),newItem.author=newAuthor})}if("up"===k&&embeds.forEach(embed=>{if(!(0,object_js_1.isObjectStrict)(embed))return;const{id:id,title:parentTitle,name:name,type:type,taxonomy:taxonomy,slug:slug}=embed;if(item.parent!==id)return;let title="";(0,string_js_1.isString)(parentTitle?.rendered)&&(title=parentTitle.rendered),(0,string_js_1.isString)(name)&&(title=name),newItem.parent={id:id.toString(),contentType:(0,string_js_1.isString)(taxonomy)?"term":type,title:title,slug:slug}}),"wp:featuredmedia"===k&&embeds.forEach(embed=>{if(!(0,object_js_1.isObjectStrict)(embed))return;const{id:id,source_url:url,media_details:details,mime_type:mimeType,alt_text:alt}=embed;if(!(0,object_js_1.isObjectStrict)(details))return;const{file:file,filesize:filesize,width:width,height:height,sizes:sizes}=details;item.featured_media===id&&(newItem.featured_media=normalizeFile({url:url,filename:file?.split("/").pop(),alt:alt,width:width,height:height,filesizeInBytes:filesize,subtype:mimeType?.split("/").pop(),mime:mimeType,sizes:sizes}))}),"wp:term"===k){const exclude=[...excludeProps,"id","name","taxonomy"];embeds.forEach(embed=>{(0,array_js_1.isArrayStrict)(embed)&&embed.forEach(e=>{if(!(0,object_js_1.isObjectStrict)(e))return;const{id:id,name:name,taxonomy:taxonomy=""}=e;let taxonomyLookup=taxonomy;"category"===taxonomy&&(taxonomyLookup="categories"),"post_tag"===taxonomy&&(taxonomyLookup="tags");const itemTaxonomy=newItem[taxonomyLookup]??item[taxonomyLookup];(0,array_js_1.isArrayStrict)(itemTaxonomy)&&(newItem[taxonomyLookup]=itemTaxonomy.map(taxonomyId=>{if(taxonomyId!==id)return taxonomyId;const newTerm={id:id.toString(),title:name,contentType:"term",taxonomy:getTaxonomy(taxonomy)};return Object.entries(e).forEach(([key,val])=>{exclude.includes(key)||(newTerm[key]=val)}),newTerm}))})})}}})},normalizeBlocks=blocks=>{const newItems=[];return blocks.forEach(block=>{const{blockName:blockName,attrs:attrs,innerBlocks:innerBlocks}=block,contentType=blockName;if(!(0,string_js_1.isStringStrict)(contentType))return;const{
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.normalMetaKeys=exports.normalRoutes=exports.normalizeWordPressMenus=exports.normalizeWordPressMenuItems=exports.normalizeWordPressData=void 0;const block_serialization_default_parser_1=require("@wordpress/block-serialization-default-parser"),contentType_js_1=require("../utils/contentType/contentType.js"),objectUtils_js_1=require("../utils/object/objectUtils.js"),store_js_1=require("../store/store.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"),config_js_1=require("../config/config.js"),normalRoutes=new Map([["page","pages"],["post","posts"],["taxonomy","taxonomies"],["category","categories"],["tag","tags"],["attachment","media"],["nav_menu","menus"],["nav_menu_item","menu-items"]]);exports.normalRoutes=normalRoutes;const normalMetaKeys=new Map;exports.normalMetaKeys=normalMetaKeys;const menusById=new Map,excludeProps=["_links","auto_add"],getTaxonomy=id=>{const taxonomy=(0,store_js_1.getStoreItem)("taxonomies")[id],{title:title="",slug:slug="",contentTypes:contentTypes=[]}=(0,object_js_1.isObjectStrict)(taxonomy)?taxonomy:{};return{id:id,title:title,slug:slug,contentTypes:contentTypes}},normalizeFile=file=>{const{url:url,filename:filename,alt:alt,width:width,height:height,filesizeInBytes:filesizeInBytes,subtype:subtype,mime:mime,sizes:sizes}=file;let s;if((0,object_js_1.isObjectStrict)(sizes)){s={};for(const[,value]of Object.entries(sizes)){const{width:width,source_url:src}=value;let{url:url}=value;(0,string_js_1.isStringStrict)(src)&&(url=src),(0,number_js_1.isNumber)(width)&&(0,string_js_1.isStringStrict)(url)&&(s[width]=url)}}return{url:(0,string_js_1.isString)(url)?url:"",name:(0,string_js_1.isString)(filename)?filename:"",alt:(0,string_js_1.isString)(alt)?alt:"",width:(0,number_js_1.isNumber)(width)?width:0,height:(0,number_js_1.isNumber)(height)?height:0,size:(0,number_js_1.isNumber)(filesizeInBytes)?filesizeInBytes:0,format:"jpeg"===subtype?"jpg":subtype,type:mime,sizes:s}},normalizeEmbedded=(value,item,newItem)=>{(0,objectUtils_js_1.getObjectKeys)(value).forEach(k=>{const embeds=value[k];if((0,array_js_1.isArrayStrict)(embeds)){if("author"===k){const exclude=[...excludeProps,"id","avatar_urls"];embeds.forEach(embed=>{if(!(0,object_js_1.isObjectStrict)(embed))return;const{id:id}=embed;if(item.author!==id)return;const newAuthor={id:id.toString()};Object.entries(embed).forEach(([key,val])=>{exclude.includes(key)||(newAuthor[key]=val)}),newItem.author=newAuthor})}if("up"===k&&embeds.forEach(embed=>{if(!(0,object_js_1.isObjectStrict)(embed))return;const{id:id,title:parentTitle,name:name,type:type,taxonomy:taxonomy,slug:slug}=embed;if(item.parent!==id)return;let title="";(0,string_js_1.isString)(parentTitle?.rendered)&&(title=parentTitle.rendered),(0,string_js_1.isString)(name)&&(title=name),newItem.parent={id:id.toString(),contentType:(0,string_js_1.isString)(taxonomy)?"term":type,title:title,slug:slug}}),"wp:featuredmedia"===k&&embeds.forEach(embed=>{if(!(0,object_js_1.isObjectStrict)(embed))return;const{id:id,source_url:url,media_details:details,mime_type:mimeType,alt_text:alt}=embed;if(!(0,object_js_1.isObjectStrict)(details))return;const{file:file,filesize:filesize,width:width,height:height,sizes:sizes}=details;item.featured_media===id&&(newItem.featured_media=normalizeFile({url:url,filename:file?.split("/").pop(),alt:alt,width:width,height:height,filesizeInBytes:filesize,subtype:mimeType?.split("/").pop(),mime:mimeType,sizes:sizes}))}),"wp:term"===k){const exclude=[...excludeProps,"id","name","taxonomy"];embeds.forEach(embed=>{(0,array_js_1.isArrayStrict)(embed)&&embed.forEach(e=>{if(!(0,object_js_1.isObjectStrict)(e))return;const{id:id,name:name,taxonomy:taxonomy=""}=e;let taxonomyLookup=taxonomy;"category"===taxonomy&&(taxonomyLookup="categories"),"post_tag"===taxonomy&&(taxonomyLookup="tags");const itemTaxonomy=newItem[taxonomyLookup]??item[taxonomyLookup];(0,array_js_1.isArrayStrict)(itemTaxonomy)&&(newItem[taxonomyLookup]=itemTaxonomy.map(taxonomyId=>{if(taxonomyId!==id)return taxonomyId;const newTerm={id:id.toString(),title:name,contentType:"term",taxonomy:getTaxonomy(taxonomy)};return Object.entries(e).forEach(([key,val])=>{exclude.includes(key)||(newTerm[key]=val)}),newTerm}))})})}}})},normalizeBlocks=blocks=>{const newItems=[];return blocks.forEach(block=>{const{blockName:blockName,attrs:attrs,innerBlocks:innerBlocks}=block,contentType=blockName;if(!(0,string_js_1.isStringStrict)(contentType))return;const{isItem:isItem}=attrs,attrItemArr=((0,string_js_1.isStringStrict)(isItem)?isItem:"").split(","),attrItemExists=attrItemArr.length;for(const[key,value]of Object.entries(attrs))if((0,object_js_1.isObjectStrict)(value)){if(attrItemExists&&attrItemArr.includes(key)){const itemValue=normalizeItem(value);itemValue.content=void 0,attrs[key]=itemValue}(0,string_js_1.isStringStrict)(value.mime)&&(attrs[key]=normalizeFile(value))}const newItem={contentType:contentType,...attrs},renderType=config_js_1.config.renderTypes[contentType];return(0,string_js_1.isString)(renderType)&&(newItem.renderType=renderType),(0,array_js_1.isArrayStrict)(innerBlocks)&&(newItem.content=normalizeBlocks(innerBlocks)),newItems.push(newItem)}),newItems},normalizeItem=item=>{const newItem={};for(const[key,value]of Object.entries(item)){if(excludeProps.includes(key))continue;let val=value,k=key;const isObj=(0,object_js_1.isObjectStrict)(value),isStr=(0,string_js_1.isStringStrict)(value);if("id"!==key&&"object_id"!==k||(val=value?.toString()),"type"===key&&isStr)newItem.contentType=(0,contentType_js_1.normalizeContentType)(value),(0,string_js_1.isString)(config_js_1.config.renderTypes[value])&&(newItem.renderType=config_js_1.config.renderTypes[value]);else{if("types"===key&&(k="contentTypes"),isObj){const{rendered:rendered}=value;(0,string_js_1.isString)(rendered)&&(val=rendered)}if("name"===key&&(k="title"),"_embedded"===key&&isObj)normalizeEmbedded(value,item,newItem);else{if((0,string_js_1.isStringStrict)(val)){if("excerpt"===key&&(val=val.replace(/<[^>]*>|\[.*?\]/g,"").trim()),"content"===key){const normalVal=normalizeBlocks((0,block_serialization_default_parser_1.parse)(val));val=normalVal.length?normalVal:val}"taxonomy"===key&&(newItem.contentType="term",val=getTaxonomy(val))}if("meta"===key&&isObj)for(const[metaKey,metaValue]of Object.entries(val)){newItem[normalMetaKeys.get(metaKey)??metaKey]=metaValue}else{if("media_details"===k&&isObj){const valObj=val,valFull=valObj.sizes?.full,sourceUrl=item.source_url,mimeType=item.mime_type;val=normalizeFile({url:sourceUrl,filename:sourceUrl?.split("/").pop(),alt:item.alt_text,width:valFull?.width,height:valFull?.height,filesizeInBytes:valObj.filesize,subtype:mimeType?.split("/")[1],mime:mimeType,sizes:valObj.sizes})}newItem[k]=val}}}}return newItem},normalizeWordPressMenuItems=items=>{const itemsObj=Object.fromEntries(items.map(item=>[item.id,item]));menusById.clear(),items.forEach(item=>{const{id:id="",title:title="",menu_order:menu_order=0,menus:menus=0,parent:parent}=item,hasMenuOrder=(0,number_js_1.isNumber)(menu_order);if(hasMenuOrder&&(0,object_js_1.isObjectStrict)(itemsObj[parent])&&(null==itemsObj[parent].children&&(itemsObj[parent].children=[]),itemsObj[parent].children.push({id:id,menu_order:menu_order,title:title})),hasMenuOrder&&(0,number_js_1.isNumber)(menus)&&0===parent){const menuId=menus.toString();null==menusById.get(menuId)&&menusById.set(menuId,[]),menusById.get(menuId)?.push({id:id,menu_order:menu_order,title:title})}});const newItems=[];for(const[id,obj]of Object.entries(itemsObj)){const{url:url="",title:title="",contentType:contentType="",children:children=[],object:object="",object_id:object_id="",locale:locale=""}=obj;if(!(0,string_js_1.isString)(url)||!(0,string_js_1.isStringStrict)(title))continue;const newItem={id:id,title:title},isCustom="custom"===contentType;if(!isCustom&&(0,string_js_1.isStringStrict)(object)&&(0,string_js_1.isStringStrict)(object_id)){const isTerm="taxonomy"===contentType,internalLink={contentType:isTerm?"term":object,id:object_id,slug:url.split("/").filter(Boolean).pop()};isTerm&&(internalLink.taxonomy=getTaxonomy(object)),(0,string_js_1.isStringStrict)(locale)&&(internalLink.locale=locale),newItem.link=url,newItem.internalLink=internalLink}if(isCustom){url.startsWith("http")&&!url.startsWith(config_js_1.config.env.prodUrl)?newItem.externalLink=url:newItem.link=url}(0,array_js_1.isArrayStrict)(children)&&(newItem.children=children.sort((a,b)=>a.menu_order-b.menu_order));const exclude=[...excludeProps,"url","type","type_label","object","object_id","invalid","meta","menu_order","menus","parent","contentType","status"];Object.entries(obj).forEach(([key,val])=>{exclude.includes(key)||(newItem[key]=val)}),newItems.push(newItem)}return newItems};exports.normalizeWordPressMenuItems=normalizeWordPressMenuItems;const normalizeWordPressMenus=menus=>{const newMenus=[];return menus.forEach(menu=>{const{id:id="",title:title="",description:description="",locations:locations=[],meta:meta=[]}=menu,newMenu={id:id,title:title,description:description,meta:meta,location:locations,items:menusById.get(id)?.sort((a,b)=>a.menu_order-b.menu_order)??[]};newMenus.push(newMenu)}),newMenus};exports.normalizeWordPressMenus=normalizeWordPressMenus;const normalizeWordPressData=(data,route,_newData=[])=>(0,array_js_1.isArrayStrict)(data)?("taxonomies"===route&&(data=Object.entries(data[0]).map(([key,value])=>({id:key,type:"taxonomy",...value}))),data.forEach(item=>{(0,object_js_1.isObjectStrict)(item)&&_newData.push(normalizeItem(item))}),"taxonomies"===route&&_newData.forEach(item=>{(0,store_js_1.setStoreItem)("taxonomies",item,item.id)}),_newData):[];exports.normalizeWordPressData=normalizeWordPressData;
|
package/lib/config/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let config={namespace:"frm",source:"cms",title:"",meta:{description:"",image:""},partialTypes:[],wholeTypes:[],hierarchicalTypes:[],localeInSlug:{},typeInSlug:{},taxonomyInSlug:{},normalTypes:{},renderTypes:{},env:{dev:!0,prod:!1,build:!1,cache:!1,dir:"",devUrl:"",prodUrl:""},cms:{name:"",space:"",prodUser:"",prodCredential:"",prodHost:"",devUser:"",devCredential:"",devHost:""},local:{dir:"json"},scripts:{inputDir:"lib",outputDir:"js"},styles:{inputDir:"src",outputDir:"css"},image:{inputDir:"src/assets/img",outputDir:"site/assets/img",localUrl:"/assets/img",remoteUrl:"",quality:75,sizes:[200,400,600,800,1e3,1200,1600,2e3]},filter:config=>config};const setConfig=args=>(config={...config,...args},config),setConfigFilter=
|
|
1
|
+
let config={namespace:"frm",source:"cms",title:"",meta:{description:"",image:""},partialTypes:[],wholeTypes:[],hierarchicalTypes:[],localeInSlug:{},typeInSlug:{},taxonomyInSlug:{},normalTypes:{},renderTypes:{},env:{dev:!0,prod:!1,build:!1,cache:!1,dir:"",devUrl:"",prodUrl:""},cms:{name:"",space:"",prodUser:"",prodCredential:"",prodHost:"",devUser:"",devCredential:"",devHost:""},local:{dir:"json"},scripts:{inputDir:"lib",outputDir:"js"},styles:{inputDir:"src",outputDir:"css"},image:{inputDir:"src/assets/img",outputDir:"site/assets/img",localUrl:"/assets/img",remoteUrl:"",quality:75,sizes:[200,400,600,800,1e3,1200,1600,2e3]},filter:config=>config};const setConfig=args=>(config={...config,...args},config),setConfigFilter=env=>(config=config.filter(config,env),config);export{config,setConfig,setConfigFilter};
|
|
@@ -40,7 +40,7 @@ export interface ConfigImage {
|
|
|
40
40
|
sizes: number[];
|
|
41
41
|
quality: number;
|
|
42
42
|
}
|
|
43
|
-
export type ConfigFilter = (config: Config, env: Generic) => Config
|
|
43
|
+
export type ConfigFilter = (config: Config, env: Generic) => Config;
|
|
44
44
|
export interface Config {
|
|
45
45
|
namespace: string;
|
|
46
46
|
source: Source;
|
|
@@ -63,4 +63,4 @@ export interface Config {
|
|
|
63
63
|
filter: ConfigFilter;
|
|
64
64
|
}
|
|
65
65
|
export type ConfigSet = (args: Partial<Config>) => Config;
|
|
66
|
-
export type ConfigSetFilter = (env: Generic) => Config
|
|
66
|
+
export type ConfigSetFilter = (env: Generic) => Config;
|
|
@@ -30,7 +30,7 @@ export interface FormMeta {
|
|
|
30
30
|
senderEmail?: string;
|
|
31
31
|
}
|
|
32
32
|
export type FormPropsFilter<A = FormArgs, R = RenderItem> = (props: FormProps<A, R>) => FormProps<A, R>;
|
|
33
|
-
export type FormFieldType = 'text' | 'email' | 'checkbox' | 'radio' | 'number' | 'password' | 'tel' | 'url' | 'textarea' | 'select' | 'radio-group' | 'checkbox-group' | 'fieldset' | 'hidden';
|
|
33
|
+
export type FormFieldType = 'text' | 'email' | 'checkbox' | 'radio' | 'number' | 'password' | 'tel' | 'url' | 'textarea' | 'select' | 'radio-group' | 'checkbox-group' | 'fieldset' | 'hidden' | 'file';
|
|
34
34
|
export interface FormFieldArgs extends Generic {
|
|
35
35
|
type?: FormFieldType;
|
|
36
36
|
name?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{config}from"../../config/config.js";import{escape}from"../../utils/escape/escape.js";import{isArray}from"../../utils/array/array.js";import{isString,isStringStrict}from"../../utils/string/string.js";import{isObject,isObjectStrict}from"../../utils/object/object.js";import{getObjectKeys}from"../../utils/object/objectUtils.js";import{applyFilters}from"../../utils/filter/filter.js";import{getPermalink}from"../../utils/link/link.js";import{getStoreItem}from"../../store/store.js";import{minify}from"../../utils/minify/minify.js";const recurseEmailHtml=(data,html,plain,depth=1)=>{if(!isObject(data))return;const isArr=isArray(data);getObjectKeys(data).forEach(label=>{const value=data[label],l=label.toString(),h=depth+1;1===depth&&(html.ref+='\n <tr>\n <td style="padding: 16px 0; border-bottom: 2px solid #ccc;">\n '),label&&!isArr&&(html.ref+=`\n <h${h} style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.3em">\n ${l}\n </h${h}>\n `,plain.ref+=`${l}\n`),recurseEmailHtml(value,html,plain,depth+1),isString(value)&&(html.ref+=`\n <p style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.5em;">\n ${value}\n </p>\n `,plain.ref+=value.replace(/<br\s*\/?>/gi,"\n").replace(/(<([^>]+)>)/gi,"")+"\n"),1===depth&&(html.ref+="\n </td>\n </tr>\n ",plain.ref+="\n")})},Contact=async args=>{const{id:id,action:action,inputs:inputs}=args;if(!isStringStrict(id))return{error:{message:"No id"}};if(!isObjectStrict(inputs)||!Object.keys(inputs).length)return{error:{message:"No inputs"}};const formMetaData=getStoreItem("formMeta");if(!isObjectStrict(formMetaData))return{error:{message:"No meta"}};const meta=formMetaData[id];if(!isObjectStrict(meta))return{error:{message:"No meta object"}};const toEmail=meta.toEmail;if(!isStringStrict(toEmail))return{error:{message:"No to email"}};const toEmails=toEmail.split(","),senderEmail=meta.senderEmail;if(!isStringStrict(senderEmail))return{error:{message:"No sender email"}};let subject=isStringStrict(meta.subject)?meta.subject:"",replyToEmail="";const header=`${config.title} contact form submission`,footer=`This email was sent from a contact form on ${config.title} (${getPermalink()})`,outputData={},html={ref:""},plain={ref:""};for(const[name,input]of Object.entries(inputs)){const inputType=input.type,inputLabel=input.label?.trim()||`[${name}]`,inputValue=input.value;let inputValueStr="";if(inputValueStr=isArray(inputValue)?inputValue.map(v=>escape(v.toString().trim())).join("<br>"):escape(inputValue.toString().trim()),"subject"===name){subject=inputValueStr?`${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(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,html,plain);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 ${html.ref}\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${plain.ref}${footer}`;subject||(subject=`${config.title} Contact Form`);const body={id:id,action:action,inputs:inputs,to:toEmails,sender:senderEmail,subject:subject,text:minify(outputPlain),html:minify(outputHtml)};return replyToEmail&&(body.replyTo=replyToEmail),await applyFilters("contactResult",{},body,!0)};export{Contact};
|
|
1
|
+
import{config}from"../../config/config.js";import{escape}from"../../utils/escape/escape.js";import{isArray}from"../../utils/array/array.js";import{isString,isStringStrict}from"../../utils/string/string.js";import{isObject,isObjectStrict}from"../../utils/object/object.js";import{getObjectKeys}from"../../utils/object/objectUtils.js";import{applyFilters}from"../../utils/filter/filter.js";import{getPermalink}from"../../utils/link/link.js";import{getStoreItem}from"../../store/store.js";import{minify}from"../../utils/minify/minify.js";import{isFile}from"../../utils/file/file.js";const recurseEmailHtml=(data,html,plain,depth=1)=>{if(!isObject(data))return;const isArr=isArray(data);getObjectKeys(data).forEach(label=>{const value=data[label],l=label.toString(),h=depth+1;1===depth&&(html.ref+='\n <tr>\n <td style="padding: 16px 0; border-bottom: 2px solid #ccc;">\n '),label&&!isArr&&(html.ref+=`\n <h${h} style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.3em">\n ${l}\n </h${h}>\n `,plain.ref+=`${l}\n`),recurseEmailHtml(value,html,plain,depth+1),isString(value)&&(html.ref+=`\n <p style="font-family: sans-serif; color: #222; margin: 16px 0; line-height: 1.5em;">\n ${value}\n </p>\n `,plain.ref+=value.replace(/<br\s*\/?>/gi,"\n").replace(/(<([^>]+)>)/gi,"")+"\n"),1===depth&&(html.ref+="\n </td>\n </tr>\n ",plain.ref+="\n")})},Contact=async args=>{const{id:id,action:action,inputs:inputs}=args;if(!isStringStrict(id))return{error:{message:"No id"}};if(!isObjectStrict(inputs)||!Object.keys(inputs).length)return{error:{message:"No inputs"}};const formMetaData=getStoreItem("formMeta");if(!isObjectStrict(formMetaData))return{error:{message:"No meta"}};const meta=formMetaData[id];if(!isObjectStrict(meta))return{error:{message:"No meta object"}};const toEmail=meta.toEmail;if(!isStringStrict(toEmail))return{error:{message:"No to email"}};const toEmails=toEmail.split(","),senderEmail=meta.senderEmail;if(!isStringStrict(senderEmail))return{error:{message:"No sender email"}};let subject=isStringStrict(meta.subject)?meta.subject:"",replyToEmail="";const header=`${config.title} contact form submission`,footer=`This email was sent from a contact form on ${config.title} (${getPermalink()})`,outputData={},html={ref:""},plain={ref:""};for(const[name,input]of Object.entries(inputs)){const inputType=input.type,inputLabel=input.label?.trim()||`[${name}]`,inputValue=input.value;let inputValueStr="";if(inputValueStr=isArray(inputValue)?inputValue.map(v=>isFile(v)?v.name:escape(v.toString().trim())).join("<br>"):isFile(inputValue)?inputValue.name:escape(inputValue.toString().trim()),"subject"===name){subject=inputValueStr?`${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(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,html,plain);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 ${html.ref}\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${plain.ref}${footer}`;subject||(subject=`${config.title} Contact Form`);const body={id:id,action:action,inputs:inputs,to:toEmails,sender:senderEmail,subject:subject,text:minify(outputPlain),html:minify(outputHtml)};return replyToEmail&&(body.replyTo=replyToEmail),await applyFilters("contactResult",{},body,!0)};export{Contact};
|
|
@@ -3,9 +3,10 @@ export interface ServerlessRoute {
|
|
|
3
3
|
path: string;
|
|
4
4
|
content?: string;
|
|
5
5
|
}
|
|
6
|
+
export type ServerlessActionPrimitive = string | number | boolean | File;
|
|
6
7
|
export interface ServerlessActionInput extends Generic {
|
|
8
|
+
value: ServerlessActionPrimitive | ServerlessActionPrimitive[];
|
|
7
9
|
type: string | string[];
|
|
8
|
-
value: string | boolean | number | string[] | number[];
|
|
9
10
|
label?: string;
|
|
10
11
|
legend?: string;
|
|
11
12
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const isFile=value=>value instanceof File,isBlob=value=>value instanceof Blob;export{isFile,isBlob};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parse}from"@wordpress/block-serialization-default-parser";import{normalizeContentType}from"../utils/contentType/contentType.js";import{getObjectKeys}from"../utils/object/objectUtils.js";import{getStoreItem,setStoreItem}from"../store/store.js";import{isString,isStringStrict}from"../utils/string/string.js";import{isArrayStrict}from"../utils/array/array.js";import{isObjectStrict}from"../utils/object/object.js";import{isNumber}from"../utils/number/number.js";import{config}from"../config/config.js";const normalRoutes=new Map([["page","pages"],["post","posts"],["taxonomy","taxonomies"],["category","categories"],["tag","tags"],["attachment","media"],["nav_menu","menus"],["nav_menu_item","menu-items"]]),normalMetaKeys=new Map,menusById=new Map,excludeProps=["_links","auto_add"],getTaxonomy=id=>{const taxonomy=getStoreItem("taxonomies")[id],{title:title="",slug:slug="",contentTypes:contentTypes=[]}=isObjectStrict(taxonomy)?taxonomy:{};return{id:id,title:title,slug:slug,contentTypes:contentTypes}},normalizeFile=file=>{const{url:url,filename:filename,alt:alt,width:width,height:height,filesizeInBytes:filesizeInBytes,subtype:subtype,mime:mime,sizes:sizes}=file;let s;if(isObjectStrict(sizes)){s={};for(const[,value]of Object.entries(sizes)){const{width:width,source_url:src}=value;let{url:url}=value;isStringStrict(src)&&(url=src),isNumber(width)&&isStringStrict(url)&&(s[width]=url)}}return{url:isString(url)?url:"",name:isString(filename)?filename:"",alt:isString(alt)?alt:"",width:isNumber(width)?width:0,height:isNumber(height)?height:0,size:isNumber(filesizeInBytes)?filesizeInBytes:0,format:"jpeg"===subtype?"jpg":subtype,type:mime,sizes:s}},normalizeEmbedded=(value,item,newItem)=>{getObjectKeys(value).forEach(k=>{const embeds=value[k];if(isArrayStrict(embeds)){if("author"===k){const exclude=[...excludeProps,"id","avatar_urls"];embeds.forEach(embed=>{if(!isObjectStrict(embed))return;const{id:id}=embed;if(item.author!==id)return;const newAuthor={id:id.toString()};Object.entries(embed).forEach(([key,val])=>{exclude.includes(key)||(newAuthor[key]=val)}),newItem.author=newAuthor})}if("up"===k&&embeds.forEach(embed=>{if(!isObjectStrict(embed))return;const{id:id,title:parentTitle,name:name,type:type,taxonomy:taxonomy,slug:slug}=embed;if(item.parent!==id)return;let title="";isString(parentTitle?.rendered)&&(title=parentTitle.rendered),isString(name)&&(title=name),newItem.parent={id:id.toString(),contentType:isString(taxonomy)?"term":type,title:title,slug:slug}}),"wp:featuredmedia"===k&&embeds.forEach(embed=>{if(!isObjectStrict(embed))return;const{id:id,source_url:url,media_details:details,mime_type:mimeType,alt_text:alt}=embed;if(!isObjectStrict(details))return;const{file:file,filesize:filesize,width:width,height:height,sizes:sizes}=details;item.featured_media===id&&(newItem.featured_media=normalizeFile({url:url,filename:file?.split("/").pop(),alt:alt,width:width,height:height,filesizeInBytes:filesize,subtype:mimeType?.split("/").pop(),mime:mimeType,sizes:sizes}))}),"wp:term"===k){const exclude=[...excludeProps,"id","name","taxonomy"];embeds.forEach(embed=>{isArrayStrict(embed)&&embed.forEach(e=>{if(!isObjectStrict(e))return;const{id:id,name:name,taxonomy:taxonomy=""}=e;let taxonomyLookup=taxonomy;"category"===taxonomy&&(taxonomyLookup="categories"),"post_tag"===taxonomy&&(taxonomyLookup="tags");const itemTaxonomy=newItem[taxonomyLookup]??item[taxonomyLookup];isArrayStrict(itemTaxonomy)&&(newItem[taxonomyLookup]=itemTaxonomy.map(taxonomyId=>{if(taxonomyId!==id)return taxonomyId;const newTerm={id:id.toString(),title:name,contentType:"term",taxonomy:getTaxonomy(taxonomy)};return Object.entries(e).forEach(([key,val])=>{exclude.includes(key)||(newTerm[key]=val)}),newTerm}))})})}}})},normalizeBlocks=blocks=>{const newItems=[];return blocks.forEach(block=>{const{blockName:blockName,attrs:attrs,innerBlocks:innerBlocks}=block,contentType=blockName;if(!isStringStrict(contentType))return;const{
|
|
1
|
+
import{parse}from"@wordpress/block-serialization-default-parser";import{normalizeContentType}from"../utils/contentType/contentType.js";import{getObjectKeys}from"../utils/object/objectUtils.js";import{getStoreItem,setStoreItem}from"../store/store.js";import{isString,isStringStrict}from"../utils/string/string.js";import{isArrayStrict}from"../utils/array/array.js";import{isObjectStrict}from"../utils/object/object.js";import{isNumber}from"../utils/number/number.js";import{config}from"../config/config.js";const normalRoutes=new Map([["page","pages"],["post","posts"],["taxonomy","taxonomies"],["category","categories"],["tag","tags"],["attachment","media"],["nav_menu","menus"],["nav_menu_item","menu-items"]]),normalMetaKeys=new Map,menusById=new Map,excludeProps=["_links","auto_add"],getTaxonomy=id=>{const taxonomy=getStoreItem("taxonomies")[id],{title:title="",slug:slug="",contentTypes:contentTypes=[]}=isObjectStrict(taxonomy)?taxonomy:{};return{id:id,title:title,slug:slug,contentTypes:contentTypes}},normalizeFile=file=>{const{url:url,filename:filename,alt:alt,width:width,height:height,filesizeInBytes:filesizeInBytes,subtype:subtype,mime:mime,sizes:sizes}=file;let s;if(isObjectStrict(sizes)){s={};for(const[,value]of Object.entries(sizes)){const{width:width,source_url:src}=value;let{url:url}=value;isStringStrict(src)&&(url=src),isNumber(width)&&isStringStrict(url)&&(s[width]=url)}}return{url:isString(url)?url:"",name:isString(filename)?filename:"",alt:isString(alt)?alt:"",width:isNumber(width)?width:0,height:isNumber(height)?height:0,size:isNumber(filesizeInBytes)?filesizeInBytes:0,format:"jpeg"===subtype?"jpg":subtype,type:mime,sizes:s}},normalizeEmbedded=(value,item,newItem)=>{getObjectKeys(value).forEach(k=>{const embeds=value[k];if(isArrayStrict(embeds)){if("author"===k){const exclude=[...excludeProps,"id","avatar_urls"];embeds.forEach(embed=>{if(!isObjectStrict(embed))return;const{id:id}=embed;if(item.author!==id)return;const newAuthor={id:id.toString()};Object.entries(embed).forEach(([key,val])=>{exclude.includes(key)||(newAuthor[key]=val)}),newItem.author=newAuthor})}if("up"===k&&embeds.forEach(embed=>{if(!isObjectStrict(embed))return;const{id:id,title:parentTitle,name:name,type:type,taxonomy:taxonomy,slug:slug}=embed;if(item.parent!==id)return;let title="";isString(parentTitle?.rendered)&&(title=parentTitle.rendered),isString(name)&&(title=name),newItem.parent={id:id.toString(),contentType:isString(taxonomy)?"term":type,title:title,slug:slug}}),"wp:featuredmedia"===k&&embeds.forEach(embed=>{if(!isObjectStrict(embed))return;const{id:id,source_url:url,media_details:details,mime_type:mimeType,alt_text:alt}=embed;if(!isObjectStrict(details))return;const{file:file,filesize:filesize,width:width,height:height,sizes:sizes}=details;item.featured_media===id&&(newItem.featured_media=normalizeFile({url:url,filename:file?.split("/").pop(),alt:alt,width:width,height:height,filesizeInBytes:filesize,subtype:mimeType?.split("/").pop(),mime:mimeType,sizes:sizes}))}),"wp:term"===k){const exclude=[...excludeProps,"id","name","taxonomy"];embeds.forEach(embed=>{isArrayStrict(embed)&&embed.forEach(e=>{if(!isObjectStrict(e))return;const{id:id,name:name,taxonomy:taxonomy=""}=e;let taxonomyLookup=taxonomy;"category"===taxonomy&&(taxonomyLookup="categories"),"post_tag"===taxonomy&&(taxonomyLookup="tags");const itemTaxonomy=newItem[taxonomyLookup]??item[taxonomyLookup];isArrayStrict(itemTaxonomy)&&(newItem[taxonomyLookup]=itemTaxonomy.map(taxonomyId=>{if(taxonomyId!==id)return taxonomyId;const newTerm={id:id.toString(),title:name,contentType:"term",taxonomy:getTaxonomy(taxonomy)};return Object.entries(e).forEach(([key,val])=>{exclude.includes(key)||(newTerm[key]=val)}),newTerm}))})})}}})},normalizeBlocks=blocks=>{const newItems=[];return blocks.forEach(block=>{const{blockName:blockName,attrs:attrs,innerBlocks:innerBlocks}=block,contentType=blockName;if(!isStringStrict(contentType))return;const{isItem:isItem}=attrs,attrItemArr=(isStringStrict(isItem)?isItem:"").split(","),attrItemExists=attrItemArr.length;for(const[key,value]of Object.entries(attrs))if(isObjectStrict(value)){if(attrItemExists&&attrItemArr.includes(key)){const itemValue=normalizeItem(value);itemValue.content=void 0,attrs[key]=itemValue}isStringStrict(value.mime)&&(attrs[key]=normalizeFile(value))}const newItem={contentType:contentType,...attrs},renderType=config.renderTypes[contentType];return isString(renderType)&&(newItem.renderType=renderType),isArrayStrict(innerBlocks)&&(newItem.content=normalizeBlocks(innerBlocks)),newItems.push(newItem)}),newItems},normalizeItem=item=>{const newItem={};for(const[key,value]of Object.entries(item)){if(excludeProps.includes(key))continue;let val=value,k=key;const isObj=isObjectStrict(value),isStr=isStringStrict(value);if("id"!==key&&"object_id"!==k||(val=value?.toString()),"type"===key&&isStr)newItem.contentType=normalizeContentType(value),isString(config.renderTypes[value])&&(newItem.renderType=config.renderTypes[value]);else{if("types"===key&&(k="contentTypes"),isObj){const{rendered:rendered}=value;isString(rendered)&&(val=rendered)}if("name"===key&&(k="title"),"_embedded"===key&&isObj)normalizeEmbedded(value,item,newItem);else{if(isStringStrict(val)){if("excerpt"===key&&(val=val.replace(/<[^>]*>|\[.*?\]/g,"").trim()),"content"===key){const normalVal=normalizeBlocks(parse(val));val=normalVal.length?normalVal:val}"taxonomy"===key&&(newItem.contentType="term",val=getTaxonomy(val))}if("meta"===key&&isObj)for(const[metaKey,metaValue]of Object.entries(val)){newItem[normalMetaKeys.get(metaKey)??metaKey]=metaValue}else{if("media_details"===k&&isObj){const valObj=val,valFull=valObj.sizes?.full,sourceUrl=item.source_url,mimeType=item.mime_type;val=normalizeFile({url:sourceUrl,filename:sourceUrl?.split("/").pop(),alt:item.alt_text,width:valFull?.width,height:valFull?.height,filesizeInBytes:valObj.filesize,subtype:mimeType?.split("/")[1],mime:mimeType,sizes:valObj.sizes})}newItem[k]=val}}}}return newItem},normalizeWordPressMenuItems=items=>{const itemsObj=Object.fromEntries(items.map(item=>[item.id,item]));menusById.clear(),items.forEach(item=>{const{id:id="",title:title="",menu_order:menu_order=0,menus:menus=0,parent:parent}=item,hasMenuOrder=isNumber(menu_order);if(hasMenuOrder&&isObjectStrict(itemsObj[parent])&&(null==itemsObj[parent].children&&(itemsObj[parent].children=[]),itemsObj[parent].children.push({id:id,menu_order:menu_order,title:title})),hasMenuOrder&&isNumber(menus)&&0===parent){const menuId=menus.toString();null==menusById.get(menuId)&&menusById.set(menuId,[]),menusById.get(menuId)?.push({id:id,menu_order:menu_order,title:title})}});const newItems=[];for(const[id,obj]of Object.entries(itemsObj)){const{url:url="",title:title="",contentType:contentType="",children:children=[],object:object="",object_id:object_id="",locale:locale=""}=obj;if(!isString(url)||!isStringStrict(title))continue;const newItem={id:id,title:title},isCustom="custom"===contentType;if(!isCustom&&isStringStrict(object)&&isStringStrict(object_id)){const isTerm="taxonomy"===contentType,internalLink={contentType:isTerm?"term":object,id:object_id,slug:url.split("/").filter(Boolean).pop()};isTerm&&(internalLink.taxonomy=getTaxonomy(object)),isStringStrict(locale)&&(internalLink.locale=locale),newItem.link=url,newItem.internalLink=internalLink}if(isCustom){url.startsWith("http")&&!url.startsWith(config.env.prodUrl)?newItem.externalLink=url:newItem.link=url}isArrayStrict(children)&&(newItem.children=children.sort((a,b)=>a.menu_order-b.menu_order));const exclude=[...excludeProps,"url","type","type_label","object","object_id","invalid","meta","menu_order","menus","parent","contentType","status"];Object.entries(obj).forEach(([key,val])=>{exclude.includes(key)||(newItem[key]=val)}),newItems.push(newItem)}return newItems},normalizeWordPressMenus=menus=>{const newMenus=[];return menus.forEach(menu=>{const{id:id="",title:title="",description:description="",locations:locations=[],meta:meta=[]}=menu,newMenu={id:id,title:title,description:description,meta:meta,location:locations,items:menusById.get(id)?.sort((a,b)=>a.menu_order-b.menu_order)??[]};newMenus.push(newMenu)}),newMenus},normalizeWordPressData=(data,route,_newData=[])=>isArrayStrict(data)?("taxonomies"===route&&(data=Object.entries(data[0]).map(([key,value])=>({id:key,type:"taxonomy",...value}))),data.forEach(item=>{isObjectStrict(item)&&_newData.push(normalizeItem(item))}),"taxonomies"===route&&_newData.forEach(item=>{setStoreItem("taxonomies",item,item.id)}),_newData):[];export{normalizeWordPressData,normalizeWordPressMenuItems,normalizeWordPressMenus,normalRoutes,normalMetaKeys};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanizcreative/formation-static",
|
|
3
|
-
"version": "1.3.0-beta.
|
|
3
|
+
"version": "1.3.0-beta.48",
|
|
4
4
|
"description": "Foundation and utilities to build static sites using local JSON files, Contentful, or WordPress",
|
|
5
5
|
"main": "./lib/config/config.js",
|
|
6
6
|
"packageManager": "pnpm@10.15.1",
|