@alanizcreative/formation-static 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +145 -0
- package/cjs/actions/actions.d.ts +8 -0
- package/cjs/actions/actions.js +1 -0
- package/cjs/actions/actionsTypes.d.ts +10 -0
- package/cjs/actions/actionsTypes.js +1 -0
- package/cjs/components/Navigation/Navigation.d.ts +14 -0
- package/cjs/components/Navigation/Navigation.js +1 -0
- package/cjs/components/Navigation/NavigationTypes.d.ts +88 -0
- package/cjs/components/Navigation/NavigationTypes.js +1 -0
- package/cjs/components/Pagination/Pagination.d.ts +3 -0
- package/cjs/components/Pagination/Pagination.js +1 -0
- package/cjs/components/Pagination/PaginationTypes.d.ts +54 -0
- package/cjs/components/Pagination/PaginationTypes.js +1 -0
- package/cjs/config/config.d.ts +5 -0
- package/cjs/config/config.js +1 -0
- package/cjs/config/configTypes.d.ts +66 -0
- package/cjs/config/configTypes.js +1 -0
- package/cjs/contentful/contentfulData.d.ts +5 -0
- package/cjs/contentful/contentfulData.js +1 -0
- package/cjs/contentful/contentfulDataNormal.d.ts +4 -0
- package/cjs/contentful/contentfulDataNormal.js +1 -0
- package/cjs/contentful/contentfulDataTypes.d.ts +78 -0
- package/cjs/contentful/contentfulDataTypes.js +1 -0
- package/cjs/filters/filters.d.ts +8 -0
- package/cjs/filters/filters.js +1 -0
- package/cjs/filters/filtersTypes.d.ts +60 -0
- package/cjs/filters/filtersTypes.js +1 -0
- package/cjs/global/globalTypes.d.ts +34 -0
- package/cjs/global/globalTypes.js +1 -0
- package/cjs/layouts/Column/Column.d.ts +3 -0
- package/cjs/layouts/Column/Column.js +1 -0
- package/cjs/layouts/Column/ColumnTypes.d.ts +16 -0
- package/cjs/layouts/Column/ColumnTypes.js +1 -0
- package/cjs/layouts/Container/Container.d.ts +3 -0
- package/cjs/layouts/Container/Container.js +1 -0
- package/cjs/layouts/Container/ContainerTypes.d.ts +15 -0
- package/cjs/layouts/Container/ContainerTypes.js +1 -0
- package/cjs/local/localData.d.ts +5 -0
- package/cjs/local/localData.js +1 -0
- package/cjs/local/localDataNormal.d.ts +3 -0
- package/cjs/local/localDataNormal.js +1 -0
- package/cjs/local/localDataTypes.d.ts +14 -0
- package/cjs/local/localDataTypes.js +1 -0
- package/cjs/objects/Form/Form.d.ts +3 -0
- package/cjs/objects/Form/Form.js +1 -0
- package/cjs/objects/Form/FormField.d.ts +3 -0
- package/cjs/objects/Form/FormField.js +1 -0
- package/cjs/objects/Form/FormOption.d.ts +3 -0
- package/cjs/objects/Form/FormOption.js +1 -0
- package/cjs/objects/Form/FormTypes.d.ts +76 -0
- package/cjs/objects/Form/FormTypes.js +1 -0
- package/cjs/package.json +1 -0
- package/cjs/redirects/redirects.d.ts +4 -0
- package/cjs/redirects/redirects.js +1 -0
- package/cjs/redirects/redirectsFile.d.ts +2 -0
- package/cjs/redirects/redirectsFile.js +1 -0
- package/cjs/render/render.d.ts +11 -0
- package/cjs/render/render.js +1 -0
- package/cjs/render/renderInline.d.ts +4 -0
- package/cjs/render/renderInline.js +1 -0
- package/cjs/render/renderTypes.d.ts +197 -0
- package/cjs/render/renderTypes.js +1 -0
- package/cjs/scripts/scripts.d.ts +8 -0
- package/cjs/scripts/scripts.js +1 -0
- package/cjs/scripts/scriptsTypes.d.ts +15 -0
- package/cjs/scripts/scriptsTypes.js +1 -0
- package/cjs/serverless/Contact/Contact.d.ts +3 -0
- package/cjs/serverless/Contact/Contact.js +1 -0
- package/cjs/serverless/Contact/ContactTypes.d.ts +13 -0
- package/cjs/serverless/Contact/ContactTypes.js +1 -0
- package/cjs/serverless/serverless.d.ts +12 -0
- package/cjs/serverless/serverless.js +1 -0
- package/cjs/serverless/serverlessTypes.d.ts +41 -0
- package/cjs/serverless/serverlessTypes.js +1 -0
- package/cjs/shortcodes/shortcodes.d.ts +10 -0
- package/cjs/shortcodes/shortcodes.js +1 -0
- package/cjs/shortcodes/shortcodesTypes.d.ts +20 -0
- package/cjs/shortcodes/shortcodesTypes.js +1 -0
- package/cjs/store/store.d.ts +9 -0
- package/cjs/store/store.js +1 -0
- package/cjs/store/storeFiles.d.ts +2 -0
- package/cjs/store/storeFiles.js +1 -0
- package/cjs/store/storeTypes.d.ts +28 -0
- package/cjs/store/storeTypes.js +1 -0
- package/cjs/text/RichText/RichText.d.ts +4 -0
- package/cjs/text/RichText/RichText.js +1 -0
- package/cjs/text/RichText/RichTextTypes.d.ts +54 -0
- package/cjs/text/RichText/RichTextTypes.js +1 -0
- package/cjs/utils/ResponseError/ResponseError.d.ts +5 -0
- package/cjs/utils/ResponseError/ResponseError.js +1 -0
- package/cjs/utils/archive/archive.d.ts +10 -0
- package/cjs/utils/archive/archive.js +1 -0
- package/cjs/utils/archive/archiveTypes.d.ts +29 -0
- package/cjs/utils/archive/archiveTypes.js +1 -0
- package/cjs/utils/array/array.d.ts +3 -0
- package/cjs/utils/array/array.js +1 -0
- package/cjs/utils/boolean/boolean.d.ts +2 -0
- package/cjs/utils/boolean/boolean.js +1 -0
- package/cjs/utils/contentType/contentType.d.ts +2 -0
- package/cjs/utils/contentType/contentType.js +1 -0
- package/cjs/utils/dataSource/dataSource.d.ts +3 -0
- package/cjs/utils/dataSource/dataSource.js +1 -0
- package/cjs/utils/dataSource/dataSourceTypes.d.ts +9 -0
- package/cjs/utils/dataSource/dataSourceTypes.js +1 -0
- package/cjs/utils/escape/escape.d.ts +2 -0
- package/cjs/utils/escape/escape.js +1 -0
- package/cjs/utils/excerpt/excerpt.d.ts +3 -0
- package/cjs/utils/excerpt/excerpt.js +1 -0
- package/cjs/utils/excerpt/excerptTypes.d.ts +14 -0
- package/cjs/utils/excerpt/excerptTypes.js +1 -0
- package/cjs/utils/file/file.d.ts +3 -0
- package/cjs/utils/file/file.js +1 -0
- package/cjs/utils/file/filePath.d.ts +2 -0
- package/cjs/utils/file/filePath.js +1 -0
- package/cjs/utils/function/function.d.ts +3 -0
- package/cjs/utils/function/function.js +1 -0
- package/cjs/utils/heading/heading.d.ts +2 -0
- package/cjs/utils/heading/heading.js +1 -0
- package/cjs/utils/image/image.d.ts +5 -0
- package/cjs/utils/image/image.js +1 -0
- package/cjs/utils/image/imageLocal.d.ts +3 -0
- package/cjs/utils/image/imageLocal.js +1 -0
- package/cjs/utils/image/imageRemote.d.ts +3 -0
- package/cjs/utils/image/imageRemote.js +1 -0
- package/cjs/utils/image/imageTypes.d.ts +69 -0
- package/cjs/utils/image/imageTypes.js +1 -0
- package/cjs/utils/json/json.d.ts +3 -0
- package/cjs/utils/json/json.js +1 -0
- package/cjs/utils/link/link.d.ts +6 -0
- package/cjs/utils/link/link.js +1 -0
- package/cjs/utils/link/linkShare.d.ts +3 -0
- package/cjs/utils/link/linkShare.js +1 -0
- package/cjs/utils/link/linkTypes.d.ts +28 -0
- package/cjs/utils/link/linkTypes.js +1 -0
- package/cjs/utils/map/map.d.ts +2 -0
- package/cjs/utils/map/map.js +1 -0
- package/cjs/utils/minify/minify.d.ts +2 -0
- package/cjs/utils/minify/minify.js +1 -0
- package/cjs/utils/number/number.d.ts +2 -0
- package/cjs/utils/number/number.js +1 -0
- package/cjs/utils/object/object.d.ts +4 -0
- package/cjs/utils/object/object.js +1 -0
- package/cjs/utils/object/objectUtils.d.ts +2 -0
- package/cjs/utils/object/objectUtils.js +1 -0
- package/cjs/utils/path/path.d.ts +3 -0
- package/cjs/utils/path/path.js +1 -0
- package/cjs/utils/print/print.d.ts +2 -0
- package/cjs/utils/print/print.js +1 -0
- package/cjs/utils/set/set.d.ts +3 -0
- package/cjs/utils/set/set.js +1 -0
- package/cjs/utils/string/string.d.ts +3 -0
- package/cjs/utils/string/string.js +1 -0
- package/cjs/utils/tag/tag.d.ts +4 -0
- package/cjs/utils/tag/tag.js +1 -0
- package/cjs/utils/tag/tagTypes.d.ts +6 -0
- package/cjs/utils/tag/tagTypes.js +1 -0
- package/cjs/utils/year/year.d.ts +2 -0
- package/cjs/utils/year/year.js +1 -0
- package/cjs/wordpress/wordpressData.d.ts +6 -0
- package/cjs/wordpress/wordpressData.js +1 -0
- package/cjs/wordpress/wordpressDataNormal.d.ts +9 -0
- package/cjs/wordpress/wordpressDataNormal.js +1 -0
- package/cjs/wordpress/wordpressDataTypes.d.ts +208 -0
- package/cjs/wordpress/wordpressDataTypes.js +1 -0
- package/lib/actions/actions.d.ts +8 -0
- package/lib/actions/actions.js +1 -0
- package/lib/actions/actionsTypes.d.ts +10 -0
- package/lib/actions/actionsTypes.js +1 -0
- package/lib/components/Navigation/Navigation.d.ts +14 -0
- package/lib/components/Navigation/Navigation.js +1 -0
- package/lib/components/Navigation/NavigationTypes.d.ts +88 -0
- package/lib/components/Navigation/NavigationTypes.js +1 -0
- package/lib/components/Pagination/Pagination.d.ts +3 -0
- package/lib/components/Pagination/Pagination.js +1 -0
- package/lib/components/Pagination/PaginationTypes.d.ts +54 -0
- package/lib/components/Pagination/PaginationTypes.js +1 -0
- package/lib/config/config.d.ts +5 -0
- package/lib/config/config.js +1 -0
- package/lib/config/configTypes.d.ts +66 -0
- package/lib/config/configTypes.js +1 -0
- package/lib/contentful/contentfulData.d.ts +5 -0
- package/lib/contentful/contentfulData.js +1 -0
- package/lib/contentful/contentfulDataNormal.d.ts +4 -0
- package/lib/contentful/contentfulDataNormal.js +1 -0
- package/lib/contentful/contentfulDataTypes.d.ts +78 -0
- package/lib/contentful/contentfulDataTypes.js +1 -0
- package/lib/filters/filters.d.ts +8 -0
- package/lib/filters/filters.js +1 -0
- package/lib/filters/filtersTypes.d.ts +60 -0
- package/lib/filters/filtersTypes.js +1 -0
- package/lib/global/globalTypes.d.ts +34 -0
- package/lib/global/globalTypes.js +1 -0
- package/lib/layouts/Column/Column.d.ts +3 -0
- package/lib/layouts/Column/Column.js +1 -0
- package/lib/layouts/Column/ColumnTypes.d.ts +16 -0
- package/lib/layouts/Column/ColumnTypes.js +1 -0
- package/lib/layouts/Container/Container.d.ts +3 -0
- package/lib/layouts/Container/Container.js +1 -0
- package/lib/layouts/Container/ContainerTypes.d.ts +15 -0
- package/lib/layouts/Container/ContainerTypes.js +1 -0
- package/lib/local/localData.d.ts +5 -0
- package/lib/local/localData.js +1 -0
- package/lib/local/localDataNormal.d.ts +3 -0
- package/lib/local/localDataNormal.js +1 -0
- package/lib/local/localDataTypes.d.ts +14 -0
- package/lib/local/localDataTypes.js +1 -0
- package/lib/objects/Form/Form.d.ts +3 -0
- package/lib/objects/Form/Form.js +1 -0
- package/lib/objects/Form/FormField.d.ts +3 -0
- package/lib/objects/Form/FormField.js +1 -0
- package/lib/objects/Form/FormOption.d.ts +3 -0
- package/lib/objects/Form/FormOption.js +1 -0
- package/lib/objects/Form/FormTypes.d.ts +76 -0
- package/lib/objects/Form/FormTypes.js +1 -0
- package/lib/package.json +1 -0
- package/lib/redirects/redirects.d.ts +4 -0
- package/lib/redirects/redirects.js +1 -0
- package/lib/redirects/redirectsFile.d.ts +2 -0
- package/lib/redirects/redirectsFile.js +1 -0
- package/lib/render/render.d.ts +11 -0
- package/lib/render/render.js +1 -0
- package/lib/render/renderInline.d.ts +4 -0
- package/lib/render/renderInline.js +1 -0
- package/lib/render/renderTypes.d.ts +197 -0
- package/lib/render/renderTypes.js +1 -0
- package/lib/scripts/scripts.d.ts +8 -0
- package/lib/scripts/scripts.js +1 -0
- package/lib/scripts/scriptsTypes.d.ts +15 -0
- package/lib/scripts/scriptsTypes.js +1 -0
- package/lib/serverless/Contact/Contact.d.ts +3 -0
- package/lib/serverless/Contact/Contact.js +1 -0
- package/lib/serverless/Contact/ContactTypes.d.ts +13 -0
- package/lib/serverless/Contact/ContactTypes.js +1 -0
- package/lib/serverless/serverless.d.ts +12 -0
- package/lib/serverless/serverless.js +1 -0
- package/lib/serverless/serverlessTypes.d.ts +41 -0
- package/lib/serverless/serverlessTypes.js +1 -0
- package/lib/shortcodes/shortcodes.d.ts +10 -0
- package/lib/shortcodes/shortcodes.js +1 -0
- package/lib/shortcodes/shortcodesTypes.d.ts +20 -0
- package/lib/shortcodes/shortcodesTypes.js +1 -0
- package/lib/store/store.d.ts +9 -0
- package/lib/store/store.js +1 -0
- package/lib/store/storeFiles.d.ts +2 -0
- package/lib/store/storeFiles.js +1 -0
- package/lib/store/storeTypes.d.ts +28 -0
- package/lib/store/storeTypes.js +1 -0
- package/lib/text/RichText/RichText.d.ts +4 -0
- package/lib/text/RichText/RichText.js +1 -0
- package/lib/text/RichText/RichTextTypes.d.ts +54 -0
- package/lib/text/RichText/RichTextTypes.js +1 -0
- package/lib/utils/ResponseError/ResponseError.d.ts +5 -0
- package/lib/utils/ResponseError/ResponseError.js +1 -0
- package/lib/utils/archive/archive.d.ts +10 -0
- package/lib/utils/archive/archive.js +1 -0
- package/lib/utils/archive/archiveTypes.d.ts +29 -0
- package/lib/utils/archive/archiveTypes.js +1 -0
- package/lib/utils/array/array.d.ts +3 -0
- package/lib/utils/array/array.js +1 -0
- package/lib/utils/boolean/boolean.d.ts +2 -0
- package/lib/utils/boolean/boolean.js +1 -0
- package/lib/utils/contentType/contentType.d.ts +2 -0
- package/lib/utils/contentType/contentType.js +1 -0
- package/lib/utils/dataSource/dataSource.d.ts +3 -0
- package/lib/utils/dataSource/dataSource.js +1 -0
- package/lib/utils/dataSource/dataSourceTypes.d.ts +9 -0
- package/lib/utils/dataSource/dataSourceTypes.js +1 -0
- package/lib/utils/escape/escape.d.ts +2 -0
- package/lib/utils/escape/escape.js +1 -0
- package/lib/utils/excerpt/excerpt.d.ts +3 -0
- package/lib/utils/excerpt/excerpt.js +1 -0
- package/lib/utils/excerpt/excerptTypes.d.ts +14 -0
- package/lib/utils/excerpt/excerptTypes.js +1 -0
- package/lib/utils/file/file.d.ts +3 -0
- package/lib/utils/file/file.js +1 -0
- package/lib/utils/file/filePath.d.ts +2 -0
- package/lib/utils/file/filePath.js +1 -0
- package/lib/utils/function/function.d.ts +3 -0
- package/lib/utils/function/function.js +1 -0
- package/lib/utils/heading/heading.d.ts +2 -0
- package/lib/utils/heading/heading.js +1 -0
- package/lib/utils/image/image.d.ts +5 -0
- package/lib/utils/image/image.js +1 -0
- package/lib/utils/image/imageLocal.d.ts +3 -0
- package/lib/utils/image/imageLocal.js +1 -0
- package/lib/utils/image/imageRemote.d.ts +3 -0
- package/lib/utils/image/imageRemote.js +1 -0
- package/lib/utils/image/imageTypes.d.ts +69 -0
- package/lib/utils/image/imageTypes.js +1 -0
- package/lib/utils/json/json.d.ts +3 -0
- package/lib/utils/json/json.js +1 -0
- package/lib/utils/link/link.d.ts +6 -0
- package/lib/utils/link/link.js +1 -0
- package/lib/utils/link/linkShare.d.ts +3 -0
- package/lib/utils/link/linkShare.js +1 -0
- package/lib/utils/link/linkTypes.d.ts +28 -0
- package/lib/utils/link/linkTypes.js +1 -0
- package/lib/utils/map/map.d.ts +2 -0
- package/lib/utils/map/map.js +1 -0
- package/lib/utils/minify/minify.d.ts +2 -0
- package/lib/utils/minify/minify.js +1 -0
- package/lib/utils/number/number.d.ts +2 -0
- package/lib/utils/number/number.js +1 -0
- package/lib/utils/object/object.d.ts +4 -0
- package/lib/utils/object/object.js +1 -0
- package/lib/utils/object/objectUtils.d.ts +2 -0
- package/lib/utils/object/objectUtils.js +1 -0
- package/lib/utils/path/path.d.ts +3 -0
- package/lib/utils/path/path.js +1 -0
- package/lib/utils/print/print.d.ts +2 -0
- package/lib/utils/print/print.js +1 -0
- package/lib/utils/set/set.d.ts +3 -0
- package/lib/utils/set/set.js +1 -0
- package/lib/utils/string/string.d.ts +3 -0
- package/lib/utils/string/string.js +1 -0
- package/lib/utils/tag/tag.d.ts +4 -0
- package/lib/utils/tag/tag.js +1 -0
- package/lib/utils/tag/tagTypes.d.ts +6 -0
- package/lib/utils/tag/tagTypes.js +1 -0
- package/lib/utils/year/year.d.ts +2 -0
- package/lib/utils/year/year.js +1 -0
- package/lib/wordpress/wordpressData.d.ts +6 -0
- package/lib/wordpress/wordpressData.js +1 -0
- package/lib/wordpress/wordpressDataNormal.d.ts +9 -0
- package/lib/wordpress/wordpressDataNormal.js +1 -0
- package/lib/wordpress/wordpressDataTypes.d.ts +208 -0
- package/lib/wordpress/wordpressDataTypes.js +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{v4 as uuid}from"uuid";import{applyFilters}from"../../filters/filters.js";import{isStringStrict}from"../../utils/string/string.js";import{isObjectStrict}from"../../utils/object/object.js";const FormField=props=>{if(!isObjectStrict(props))return[];props=applyFilters("formFieldProps",props);const{args:args}=props,{type:type="text",name:name,label:label,hint:hint,value:value,required:required=!1,attr:attr,emptyError:emptyError,invalidError:invalidError,fieldTag:fieldTag="div",fieldClasses:fieldClasses,fieldAttr:fieldAttr,fieldsetClasses:fieldsetClasses,fieldsetAttr:fieldsetAttr,labelClasses:labelClasses,classes:classes,radioIcon:radioIcon,checkboxIcon:checkboxIcon}=isObjectStrict(args)?args:{},isHidden="hidden"===type;if(!isStringStrict(label)&&!isHidden)return[];let isFieldset="fieldset"===type;if(!isFieldset&&!isStringStrict(name))return[];const isOption="checkbox"===type||"radio"===type,isSelect="select"===type;("checkbox-group"===type||"radio-group"===type)&&(isFieldset=!0);const isTextarea="textarea"===type,hasValue=isStringStrict(value),id=uuid();let optionIcon="",selectIcon="";"radio"===type&&isStringStrict(radioIcon)&&(optionIcon=radioIcon),"checkbox"===type&&isStringStrict(checkboxIcon)&&(optionIcon=checkboxIcon),"select"===type&&isStringStrict(args.selectIcon)&&(selectIcon=args.selectIcon);const requiredIcon=required&&isStringStrict(args.requiredIcon)?args.requiredIcon:"",fieldAttrs=["data-form-field"],fieldsetAttrs=[],attrs=["data-form-input"];if(isStringStrict(attr)){const attrsArr=attr.split("\n");for(const attrItem of attrsArr){const[attrName,attrValue]=attrItem.split(" : ");isStringStrict(attrName)&&isStringStrict(attrValue)&&attrs.push(`${attrName}="${attrValue}"`)}}isTextarea||isSelect||!hasValue||attrs.push(`value="${value}"`),isStringStrict(classes)&&attrs.push(`class="${classes}"`),isStringStrict(fieldClasses)&&fieldAttrs.push(`class="${fieldClasses}"`),isStringStrict(fieldsetClasses)&&fieldsetAttrs.push(`class="${fieldsetClasses}"`),isStringStrict(fieldAttr)&&fieldAttrs.push(fieldAttr),isStringStrict(fieldsetAttr)&&fieldsetAttrs.push(fieldsetAttr),isStringStrict(emptyError)&&!isHidden&&(isFieldset?fieldsetAttrs:attrs).push(`data-form-empty="${emptyError}"`),isStringStrict(invalidError)&&!isHidden&&(isFieldset?fieldsetAttrs:attrs).push(`data-form-invalid="${invalidError}"`),required&&!isHidden&&(isFieldset?fieldsetAttrs:attrs).push(isFieldset?"data-form-required":"required");const fieldAtts=` ${fieldAttrs.join(" ")}`,fieldsetAtts=fieldsetAttrs.length?` ${fieldsetAttrs.join(" ")}`:"",atts=` ${attrs.join(" ")}`;let hintOutput="";isStringStrict(hint)&&(hintOutput=`<small data-form-hint>${hint}</small>`);let labelBefore="",labelAfter="";const labelClass=isStringStrict(labelClasses)?` class="${labelClasses}"`:"";isFieldset?labelBefore=`\n <legend id="${uuid()}"${labelClass}>\n <span data-form-legend>\n <span data-form-legend-text>${label}</span>\n ${requiredIcon}\n </span>\n ${hintOutput}\n </legend>\n `:isOption?labelAfter=`\n <label for="${id}"${labelClass}>\n <span data-form-option>\n ${optionIcon}\n <span data-form-label>\n <span data-form-label-text>${label}</span>\n ${requiredIcon}\n </span>\n </span>\n ${hintOutput}\n </label>\n `:labelBefore=`\n <label for="${id}"${labelClass}>\n <span data-form-label>\n <span data-form-label-text>${label}</span>\n ${requiredIcon}\n </span>\n ${hintOutput}\n </label>\n `;let beforeOutput="",afterOutput="";switch(type){case"text":case"email":case"checkbox":case"radio":case"number":case"password":case"tel":case"url":case"hidden":beforeOutput=`<input type="${type}" name="${name}" id="${id}"${atts}>`;break;case"textarea":beforeOutput=`<textarea name="${name}" id="${id}"${atts}>${hasValue?value:""}</textarea>`;break;case"select":beforeOutput=`\n <div data-form-select>\n <select name="${name}" id="${id}"${atts}>`,afterOutput=`\n </select>\n ${selectIcon}\n </div>`}return isHidden?[beforeOutput]:[`\n <${fieldTag}${fieldAtts}>\n ${isFieldset?`<fieldset${fieldsetAtts}>`:""}\n ${labelBefore}\n ${isFieldset?"<div data-form-group>":""}\n ${beforeOutput}`,`${afterOutput}\n ${labelAfter}\n ${isFieldset?"</div></fieldset>":""}\n </${fieldTag}>\n `]};export{FormField};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{v4 as uuid}from"uuid";import{applyFilters}from"../../filters/filters.js";import{isStringStrict}from"../../utils/string/string.js";import{isObjectStrict}from"../../utils/object/object.js";import{isArrayStrict}from"../../utils/array/array.js";const FormOption=props=>{if(!isObjectStrict(props))return"";props=applyFilters("formOptionProps",props);const{args:args,parents:parents}=props,{label:label,value:value="",name:name,hint:hint,selected:selected,radioIcon:radioIcon,checkboxIcon:checkboxIcon,optionClasses:optionClasses,labelClasses:labelClasses,classes:classes}=isObjectStrict(args)?args:{};if(!isStringStrict(label))return"";if(!isArrayStrict(parents))return"";const fieldParent=parents[0];if(!isObjectStrict(fieldParent))return"";const{renderType:renderType,args:fieldArgs}=fieldParent;if("formField"!==renderType)return"";const{name:fieldName,type:fieldType}=fieldArgs,isRadioGroup="radio-group"===fieldType,isCheckboxGroup="checkbox-group"===fieldType,isSelect="select"===fieldType;if(!isRadioGroup&&!isCheckboxGroup&&!isSelect)return"";if(isSelect)return`<option value="${value}"${selected?" selected":""}>${label}</option>`;const inputName=name||fieldName;if(!isStringStrict(inputName))return"";const id=uuid();let optionIcon="";isRadioGroup&&isStringStrict(radioIcon)&&(optionIcon=radioIcon),isCheckboxGroup&&isStringStrict(checkboxIcon)&&(optionIcon=checkboxIcon);let hintOutput="";return isStringStrict(hint)&&(hintOutput=`<small data-form-hint>${hint}</small>`),`\n <div${isStringStrict(optionClasses)?` class="${optionClasses}"`:""}>\n <input\n type="${isRadioGroup?"radio":"checkbox"}"\n value="${value}"\n name="${inputName}"\n id="${id}"\n ${isStringStrict(classes)?` class="${classes}"`:""}\n data-form-input\n ${selected?" checked":""}\n >\n <label for="${id}"${isStringStrict(labelClasses)?` class="${labelClasses}"`:""}>\n <span data-form-option>\n ${optionIcon}\n <span data-form-label>\n <span data-form-label-text>${label}</span>\n ${hintOutput}\n </span>\n </span>\n </label>\n </div>\n `};export{FormOption};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Generic, ParentArgs } from '../../global/globalTypes.js';
|
|
2
|
+
import type { RenderFunctionArgs, RenderItem } from '../../render/renderTypes.js';
|
|
3
|
+
export interface FormArgs extends Generic {
|
|
4
|
+
id?: string;
|
|
5
|
+
formTag?: string;
|
|
6
|
+
formClasses?: string;
|
|
7
|
+
formAttr?: string;
|
|
8
|
+
fields?: string;
|
|
9
|
+
fieldsClasses?: string;
|
|
10
|
+
fieldsAttr?: string;
|
|
11
|
+
submitFieldClasses?: string;
|
|
12
|
+
submitFieldAttr?: string;
|
|
13
|
+
submitLabel?: string;
|
|
14
|
+
submitClasses?: string;
|
|
15
|
+
submitAttr?: string;
|
|
16
|
+
honeypotName?: string;
|
|
17
|
+
honeypotFieldClasses?: string;
|
|
18
|
+
honeypotFieldAttr?: string;
|
|
19
|
+
honeypotLabelClasses?: string;
|
|
20
|
+
honeypotClasses?: string;
|
|
21
|
+
honeypotLabel?: string;
|
|
22
|
+
honeypotAttr?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface FormProps<A = FormArgs, R = RenderItem> extends RenderFunctionArgs<A, R> {
|
|
25
|
+
args: FormArgs & A;
|
|
26
|
+
}
|
|
27
|
+
export interface FormMeta {
|
|
28
|
+
subject?: string;
|
|
29
|
+
toEmail?: string;
|
|
30
|
+
senderEmail?: string;
|
|
31
|
+
}
|
|
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' | 'file';
|
|
34
|
+
export interface FormFieldArgs extends Generic {
|
|
35
|
+
type?: FormFieldType;
|
|
36
|
+
name?: string;
|
|
37
|
+
label?: string;
|
|
38
|
+
hint?: string;
|
|
39
|
+
value?: string;
|
|
40
|
+
required?: boolean;
|
|
41
|
+
attr?: string;
|
|
42
|
+
emptyError?: string;
|
|
43
|
+
invalidError?: string;
|
|
44
|
+
fieldsetClasses?: string;
|
|
45
|
+
fieldsetAttr?: string;
|
|
46
|
+
fieldTag?: string;
|
|
47
|
+
fieldClasses?: string;
|
|
48
|
+
fieldAttr?: string;
|
|
49
|
+
labelClasses?: string;
|
|
50
|
+
classes?: string;
|
|
51
|
+
radioIcon?: string;
|
|
52
|
+
checkboxIcon?: string;
|
|
53
|
+
selectIcon?: string;
|
|
54
|
+
requiredIcon?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface FormFieldProps<A = FormFieldArgs, R = RenderItem> extends RenderFunctionArgs<A, R> {
|
|
57
|
+
args: FormFieldArgs & A;
|
|
58
|
+
}
|
|
59
|
+
export type FormFieldPropsFilter<A = FormFieldArgs, R = RenderItem> = (props: FormFieldProps<A, R>) => FormFieldProps<A, R>;
|
|
60
|
+
export interface FormOptionArgs extends Generic {
|
|
61
|
+
label?: string;
|
|
62
|
+
value?: string;
|
|
63
|
+
name?: string;
|
|
64
|
+
hint?: string;
|
|
65
|
+
selected?: boolean;
|
|
66
|
+
optionClasses?: string;
|
|
67
|
+
labelClasses?: string;
|
|
68
|
+
classes?: string;
|
|
69
|
+
radioIcon?: string;
|
|
70
|
+
checkboxIcon?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface FormOptionProps<A = FormOptionArgs, R = RenderItem, P = ParentArgs & FormFieldProps> extends RenderFunctionArgs<A, R, P> {
|
|
73
|
+
args: FormOptionArgs & A;
|
|
74
|
+
parents?: P[];
|
|
75
|
+
}
|
|
76
|
+
export type FormOptionPropsFilter<A = FormOptionArgs, R = RenderItem> = (props: FormOptionProps<A, R>) => FormOptionProps<A, R>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/lib/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isArrayStrict}from"../utils/array/array.js";import{isObjectStrict}from"../utils/object/object.js";let redirects=[];const setRedirects=data=>!!isArrayStrict(data)&&(redirects=[],data.forEach(item=>{if(!isObjectStrict(item))return;const{redirect:redirect}=item;isArrayStrict(redirect)&&(redirects=redirects.concat(redirect))}),redirects.length>1);export{redirects,setRedirects};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{mkdir,writeFile}from"node:fs/promises";import{resolve,dirname}from"node:path";import{print}from"../utils/print/print.js";import{redirects}from"./redirects.js";const createRedirectsFile=async(path="site/_redirects")=>{const redirectsPath=resolve(path),redirectsDir=dirname(redirectsPath);await mkdir(redirectsDir,{recursive:!0}),await writeFile(redirectsPath,redirects.join("\n").trimEnd()),print("[FRM] Successfully wrote",redirectsPath,"success")};export{createRedirectsFile};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RenderContentArgs, RenderItemArgs, RenderItemReturn, RenderArgs, RenderReturn, RenderFunctions, RenderLayout, RenderHttpError, RenderNavigation, RenderFunctionsArgs } from './renderTypes.js';
|
|
2
|
+
import type { RefString } from '../global/globalTypes.js';
|
|
3
|
+
declare let renderFunctions: RenderFunctions;
|
|
4
|
+
declare let renderLayout: RenderLayout;
|
|
5
|
+
declare let renderHttpError: RenderHttpError;
|
|
6
|
+
declare let renderNavigation: RenderNavigation;
|
|
7
|
+
declare const setRenderFunctions: (args: RenderFunctionsArgs) => boolean;
|
|
8
|
+
declare const renderContent: (args: RenderContentArgs, _html?: RefString) => Promise<string>;
|
|
9
|
+
declare const renderItem: (args: RenderItemArgs, _contentType?: string) => Promise<RenderItemReturn | null>;
|
|
10
|
+
declare const render: (args: RenderArgs) => Promise<RenderReturn[] | RenderReturn>;
|
|
11
|
+
export { render, renderItem, renderContent, renderFunctions, renderLayout, renderNavigation, renderHttpError, setRenderFunctions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{doActions}from"../actions/actions.js";import{applyFilters}from"../filters/filters.js";import{getSlug,getPermalink}from"../utils/link/link.js";import{isString,isStringStrict}from"../utils/string/string.js";import{isArray,isArrayStrict}from"../utils/array/array.js";import{isObjectStrict}from"../utils/object/object.js";import{isFunction}from"../utils/function/function.js";import{doShortcodes}from"../shortcodes/shortcodes.js";import{tagExists}from"../utils/tag/tag.js";import{setStoreData,setStoreItem,getStoreItem}from"../store/store.js";import{setRedirects}from"../redirects/redirects.js";import{scripts,styles}from"../scripts/scripts.js";import{config}from"../config/config.js";let renderFunctions={},renderLayout=()=>"",renderHttpError=()=>"",renderNavigation=()=>{};const setRenderFunctions=args=>{if(!isObjectStrict(args))return!1;const{functions:functions,layout:layout,navigation:navigation,httpError:httpError}=args;return!(!isObjectStrict(functions)||!isFunction(layout))&&(renderFunctions={...functions},renderLayout=layout,isFunction(navigation)&&(renderNavigation=navigation),isFunction(httpError)&&(renderHttpError=httpError),!0)},getContentTemplate=(content,templates=[],named=!1)=>{if(!isArrayStrict(content))return{content:[],namedContent:{},templates:[]};const namedContent={},newContent=content.map(c=>(named&&isString(c.name)&&(namedContent[c.name]={...c}),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(!isArrayStrict(templates))return templates;const lastTemplateIndex=templates.length-1;return templates.forEach((t,i)=>{content[0]&&tagExists(content[0],"templateBreak")&&content.length>=1&&content.shift();if(tagExists(t,"templateOptional")&&i===lastTemplateIndex&&!content.length)return void templates.pop();const isSlot=tagExists(t,"templateSlot");let children=t.content;if(isArrayStrict(children)&&!isSlot&&!named){let repeat;const newChildren=[...children],repeatIndex=children.findIndex(c=>{const isRepeat=tagExists(c,"templateRepeat");return isRepeat&&(repeat=c),isRepeat});if(-1!==repeatIndex&&repeat){let breakIndex=content.findIndex(c=>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))}isArray(children)&&templates[i]&&(templates[i].content=mapContentTemplate(children,content,namedContent,named))}),templates},renderContent=async(args,_html={ref:""})=>{if(!isObjectStrict(args))return _html.ref;const{content:content=[],serverlessData:serverlessData,previewData:previewData,itemData:itemData,itemContains:itemContains=new Set,itemHeadings:itemHeadings=[],parents:parents=[],depth:depth=0}=args;let{headingsIndex:headingsIndex=-1}=args;if(!isArrayStrict(content))return _html.ref;for(const item of content){if(!isObjectStrict(item))continue;const props={...item},renderType=isString(props.renderType)?props.renderType:"",isRichText="richText"===renderType;let childrenArr,children=props.content;if("contentTemplate"===renderType){const isNamed=tagExists(item,"templateNamed"),template=getContentTemplate(isArray(props.content)?props.content:[],[],isNamed);children=mapContentTemplate(template.templates,template.content,template.namedContent,isNamed)}let childrenStr="";isArrayStrict(children)&&!isRichText&&(childrenArr=children),isStringStrict(children)&&!isRichText&&(childrenStr=children),"content"===renderType&&0===depth&&(headingsIndex=itemHeadings.push([])-1);let renderStart="",renderEnd="",filterType="",filterArgs={};const renderFunction=renderFunctions[renderType];if(isFunction(renderFunction)){childrenArr&&(props.content=void 0);const renderArgs={args:props,parents:parents,itemData:itemData,itemContains:itemContains,serverlessData:serverlessData,previewData:previewData};childrenArr&&(renderArgs.children=childrenArr),"richText"===renderType&&(renderArgs.headings=itemHeadings[headingsIndex]);const renderOutput=await renderFunction(renderArgs);if(isArrayStrict(renderOutput)){const[start,end]=renderOutput;isString(start)&&(renderStart=start),isString(end)&&(renderEnd=end)}isString(renderOutput)&&(renderStart=renderOutput,childrenArr=void 0),itemContains.add(renderType),filterType=renderType,filterArgs={...props,content:void 0}}const renderContentFilterArgs={renderType:filterType,args:filterArgs},[filterRenderStart,filterRenderEnd]=await applyFilters("renderContent",[renderStart,renderEnd],renderContentFilterArgs,!0);if(renderStart=filterRenderStart,renderEnd=filterRenderEnd,_html.ref+=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,headingsIndex:headingsIndex,depth:depth+1},_html)}_html.ref+=renderEnd}return _html.ref},renderItem=async(args,_contentType)=>{if(!isObjectStrict(args))return null;const{item:item,serverlessData:serverlessData,previewData:previewData}=args;if(!isObjectStrict(item))return null;const contentType=item.contentType;if(!isStringStrict(contentType))return null;if("taxonomy"===contentType&&!0!==item.isPage)return null;const id=item.id;if(!isStringStrict(id))return null;if(!isStringStrict(item.slug))return null;let serverlessRender=!1;const itemContains=new Set,itemHeadings=[];scripts.deps.clear(),scripts.item.clear(),scripts.meta={},styles.deps.clear(),styles.item.clear();const renderItemStartArgs={id:id,itemData:{...item},contentType:contentType,itemContains:new Set,itemHeadings:[],serverlessData:serverlessData,previewData:previewData};await doActions("renderItemStart",renderItemStartArgs,!0);const title=item.title,meta={title:"",description:"",url:"",image:"",canonical:"",prev:"",next:"",index:!0,isIndex:!1,...item.meta};isStringStrict(item.metaTitle)&&(meta.title=item.metaTitle),isStringStrict(item.metaDescription)&&(meta.description=item.metaDescription),isStringStrict(item.metaImage?.url)&&(meta.image=item.metaImage.url),!isStringStrict(meta.title)&&isStringStrict(title)&&(meta.title=title);const slugArgs={id:id,contentType:contentType,slug:item.slug,returnParents:!0,itemData:item,page:0},s=getSlug(slugArgs,!0),slug=s.slug,slugIsHtml=slug.endsWith(".html"),permalink=getPermalink(slug,!slugIsHtml),parents=s.parents;meta.url=permalink,meta.canonical=permalink;const taxonomy="term"===contentType?item.taxonomy:"taxonomy"===contentType?item:null;item.baseUrl=permalink,item.baseType=isObjectStrict(taxonomy)&&isArrayStrict(taxonomy.contentTypes)?taxonomy.contentTypes:contentType;let formattedSlug="index"!==slug&&""!==slug?`/${slug}/`:"/";slugIsHtml&&(formattedSlug=slug);const index="index"===item.slug;let itemServerlessData;if(meta.isIndex=index,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;isStringStrict(contentData)&&(contentOutput=contentData),isArrayStrict(contentData)&&(contentOutput=await renderContent({content:contentData,serverlessData:itemServerlessData,parents:[],itemData:itemData,itemContains:itemContains,itemHeadings:itemHeadings,previewData:previewData})),contentOutput=await doShortcodes(contentOutput,itemData);const pag=itemData.pagination;if(isObjectStrict(pag)){const{currentParams:currentParams,prevParams:prevParams,nextParams:nextParams}=pag,currentParamsStr=new URLSearchParams(currentParams).toString();if(currentParamsStr&&(meta.canonicalParams=`?${currentParamsStr}`),isStringStrict(pag.title)&&(meta.paginationTitle=pag.title),pag.prev){const prevSlugArgs={...slugArgs,params:prevParams},p=getSlug(prevSlugArgs,!0);meta.prev=getPermalink(p.slug,1===pag.prev&&!prevParams)}if(pag.next){const nextSlugArgs={...slugArgs,params:nextParams},n=getSlug(nextSlugArgs,!0);meta.next=getPermalink(n.slug,!1)}serverlessRender=!0}const cmsLocales=config.cms.locales,slugData=[id,isStringStrict(_contentType)?_contentType:contentType];if(isStringStrict(item.locale)&&cmsLocales){const locale=item.locale;cmsLocales.includes(locale)&&locale!==cmsLocales[0]&&slugData.push(locale)}(config.env.dev||config.env.prod&&serverlessRender)&&setStoreItem("slugs",slugData,slugIsHtml?`/${slug}`:formattedSlug);const layoutArgs={id:id,meta:meta,contentType:contentType,content:contentOutput,slug:formattedSlug,itemContains:itemContains,itemHeadings:itemHeadings,itemData:itemData,serverlessData:serverlessData,previewData:previewData};let 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 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 doActions("renderItemEnd",renderItemEndArgs,!0),{serverlessRender:serverlessRender,itemData:itemData,data:{slug:formattedSlug,output:layoutOutput}}},render=async args=>{if(!isObjectStrict(args))return[];const{allData:allData,serverlessData:serverlessData,previewData:previewData}=args,isServerless=null!=serverlessData,isPreview=null!=previewData;if(scripts.deps.clear(),scripts.item.clear(),scripts.meta={},styles.deps.clear(),styles.item.clear(),!isObjectStrict(allData))return[];const{redirect:redirect,content:content}=allData;await doActions("renderStart",args,!0);const data=[];isServerless||setStoreData(allData),await renderNavigation({navigations:getStoreItem("navigations"),items:getStoreItem("navigationItems")}),setRedirects(redirect);for(const[contentType,contentItems]of Object.entries(content))if(isArrayStrict(contentItems))for(const contentItem of contentItems){const item=await renderItem({item:await 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&&setStoreItem("serverless",["reload"],itemData.slug))}const[outputItem]=data,output=(isServerless||isPreview)&&outputItem?outputItem:data;return await doActions("renderEnd",{...args,data:output},!0),output};export{render,renderItem,renderContent,renderFunctions,renderLayout,renderNavigation,renderHttpError,setRenderFunctions};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RenderItem, RenderContentArgs, RenderInlineItem } from './renderTypes.js';
|
|
2
|
+
declare const renderInlineContent: (content: RenderItem[], args?: Partial<Omit<RenderContentArgs, "content">>) => Promise<string>;
|
|
3
|
+
declare const renderInlineItem: (item: RenderInlineItem) => Promise<string>;
|
|
4
|
+
export { renderInlineContent, renderInlineItem };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{renderContent,renderItem}from"./render.js";import{isObjectStrict}from"../utils/object/object.js";import{isString}from"../utils/string/string.js";const renderInlineContent=async(content,args)=>await renderContent({content:content,parents:[],itemData:{},itemContains:new Set,itemHeadings:[],...args}),renderInlineItem=async item=>{if(!isObjectStrict(item))return"";const res=await renderItem({item:item});return isString(res?.data?.output)?res.data.output:""};export{renderInlineContent,renderInlineItem};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { Generic, GenericStrings, InternalLink, Taxonomy, ParentArgs } from '../global/globalTypes.js';
|
|
2
|
+
import type { NavigationList, NavigationItem, NavigationProps } from '../components/Navigation/NavigationTypes.js';
|
|
3
|
+
import type { RichTextHeading } from '../text/RichText/RichTextTypes.js';
|
|
4
|
+
import type { PaginationData } from '../components/Pagination/PaginationTypes.js';
|
|
5
|
+
export interface RenderMeta {
|
|
6
|
+
title?: string;
|
|
7
|
+
paginationTitle?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
image?: string;
|
|
11
|
+
canonical?: string;
|
|
12
|
+
canonicalParams?: string;
|
|
13
|
+
prev?: string;
|
|
14
|
+
next?: string;
|
|
15
|
+
index?: boolean;
|
|
16
|
+
isIndex?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface RenderBase {
|
|
19
|
+
itemData: RenderItem;
|
|
20
|
+
itemHeadings: RichTextHeading[][];
|
|
21
|
+
itemContains: Set<string>;
|
|
22
|
+
serverlessData?: RenderServerlessData;
|
|
23
|
+
previewData?: RenderPreviewData;
|
|
24
|
+
}
|
|
25
|
+
export interface RenderServerlessData {
|
|
26
|
+
path: string;
|
|
27
|
+
query?: Generic;
|
|
28
|
+
}
|
|
29
|
+
export interface RenderPreviewData {
|
|
30
|
+
id: string;
|
|
31
|
+
contentType: string;
|
|
32
|
+
locale?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface RenderRedirect {
|
|
35
|
+
redirect: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface RenderTag {
|
|
38
|
+
id: string;
|
|
39
|
+
}
|
|
40
|
+
export interface RenderMetaTags {
|
|
41
|
+
tags?: RenderTag[];
|
|
42
|
+
}
|
|
43
|
+
export interface RenderFile {
|
|
44
|
+
path?: string;
|
|
45
|
+
url?: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
alt?: string;
|
|
48
|
+
width?: number;
|
|
49
|
+
height?: number;
|
|
50
|
+
size?: number;
|
|
51
|
+
format?: string;
|
|
52
|
+
type?: string;
|
|
53
|
+
sizes?: Record<number, string>;
|
|
54
|
+
}
|
|
55
|
+
export interface RenderRichText {
|
|
56
|
+
tag?: string;
|
|
57
|
+
link?: string;
|
|
58
|
+
internalLink?: InternalLink;
|
|
59
|
+
content?: RenderItem[] | string;
|
|
60
|
+
attr?: string | GenericStrings;
|
|
61
|
+
}
|
|
62
|
+
export interface RenderTemplate {
|
|
63
|
+
content: RenderItem[];
|
|
64
|
+
namedContent: Record<string, RenderItem>;
|
|
65
|
+
templates: RenderItem[];
|
|
66
|
+
}
|
|
67
|
+
export type RenderNavigation = (args: NavigationProps) => void | Promise<void>;
|
|
68
|
+
export interface RenderHttpErrorArgs extends Generic {
|
|
69
|
+
code: number;
|
|
70
|
+
}
|
|
71
|
+
export type RenderHttpError = (args: RenderHttpErrorArgs) => string | Promise<string>;
|
|
72
|
+
export interface RenderFunctionArgs<A = any, R = RenderItem, P = ParentArgs, C = any> {
|
|
73
|
+
args: 0 extends (1 & A) ? any : A;
|
|
74
|
+
parents?: P[];
|
|
75
|
+
itemData?: R;
|
|
76
|
+
itemContains?: Set<string>;
|
|
77
|
+
serverlessData?: RenderServerlessData;
|
|
78
|
+
previewData?: RenderPreviewData;
|
|
79
|
+
headings?: RichTextHeading[];
|
|
80
|
+
children?: C[];
|
|
81
|
+
}
|
|
82
|
+
export type RenderFunction<A = any, R = RenderItem, P = ParentArgs, C = any> = (props: RenderFunctionArgs<A, R, P, C>) => string | string[] | Promise<string | string[]>;
|
|
83
|
+
export type RenderFunctions<A = any, R = RenderItem, P = ParentArgs, C = any> = Record<string, RenderFunction<A, R, P, C>>;
|
|
84
|
+
export interface RenderFunctionsArgs {
|
|
85
|
+
functions: RenderFunctions;
|
|
86
|
+
layout: RenderLayout;
|
|
87
|
+
navigation?: RenderNavigation;
|
|
88
|
+
httpError?: RenderHttpError;
|
|
89
|
+
}
|
|
90
|
+
export interface RenderContentArgs extends RenderBase {
|
|
91
|
+
content: RenderItem[];
|
|
92
|
+
parents: ParentArgs[];
|
|
93
|
+
headingsIndex?: number;
|
|
94
|
+
depth?: number;
|
|
95
|
+
}
|
|
96
|
+
export interface RenderItem extends Generic, Partial<Taxonomy> {
|
|
97
|
+
id?: string;
|
|
98
|
+
contentType?: string;
|
|
99
|
+
renderType?: string;
|
|
100
|
+
tag?: string;
|
|
101
|
+
link?: string;
|
|
102
|
+
internalLink?: InternalLink;
|
|
103
|
+
slug?: string;
|
|
104
|
+
title?: string;
|
|
105
|
+
content?: RenderItem[] | string;
|
|
106
|
+
meta?: RenderMeta;
|
|
107
|
+
baseUrl?: string;
|
|
108
|
+
baseType?: string | string[];
|
|
109
|
+
archive?: string;
|
|
110
|
+
parent?: RenderItem;
|
|
111
|
+
taxonomy?: Taxonomy;
|
|
112
|
+
metadata?: RenderMetaTags;
|
|
113
|
+
pagination?: PaginationData;
|
|
114
|
+
}
|
|
115
|
+
export interface RenderItemArgs {
|
|
116
|
+
item: RenderItem;
|
|
117
|
+
serverlessData?: RenderServerlessData;
|
|
118
|
+
previewData?: RenderPreviewData;
|
|
119
|
+
}
|
|
120
|
+
interface RenderItemReturnData {
|
|
121
|
+
slug: string;
|
|
122
|
+
output: string;
|
|
123
|
+
}
|
|
124
|
+
export interface RenderItemReturn {
|
|
125
|
+
serverlessRender?: boolean;
|
|
126
|
+
itemData?: RenderItem;
|
|
127
|
+
data?: RenderItemReturnData;
|
|
128
|
+
}
|
|
129
|
+
export interface RenderInlineItem extends Omit<RenderItem, 'id' | 'slug' | 'contentType' | 'content'> {
|
|
130
|
+
id: string;
|
|
131
|
+
slug: string;
|
|
132
|
+
contentType: string;
|
|
133
|
+
content: RenderItem[] | string;
|
|
134
|
+
}
|
|
135
|
+
export interface RenderItemStartActionArgs extends RenderBase {
|
|
136
|
+
id: string;
|
|
137
|
+
contentType: string;
|
|
138
|
+
}
|
|
139
|
+
export interface RenderItemActionArgs extends RenderBase {
|
|
140
|
+
id: string;
|
|
141
|
+
contentType: string;
|
|
142
|
+
slug: string;
|
|
143
|
+
output: string;
|
|
144
|
+
}
|
|
145
|
+
export interface RenderLayoutArgs {
|
|
146
|
+
id: string;
|
|
147
|
+
meta: RenderMeta;
|
|
148
|
+
contentType: string;
|
|
149
|
+
content: string;
|
|
150
|
+
slug: string;
|
|
151
|
+
itemData: RenderItem;
|
|
152
|
+
itemHeadings?: RichTextHeading[][];
|
|
153
|
+
itemContains?: Set<string>;
|
|
154
|
+
serverlessData?: RenderServerlessData;
|
|
155
|
+
previewData?: RenderPreviewData;
|
|
156
|
+
}
|
|
157
|
+
export type RenderLayout = (args: RenderLayoutArgs) => string | Promise<string>;
|
|
158
|
+
interface RenderAllDataContent {
|
|
159
|
+
page: RenderItem[];
|
|
160
|
+
[key: string]: RenderItem[];
|
|
161
|
+
}
|
|
162
|
+
export interface RenderAllData extends Generic {
|
|
163
|
+
navigation?: NavigationList[];
|
|
164
|
+
navigationItem?: NavigationItem[];
|
|
165
|
+
redirect?: RenderRedirect[];
|
|
166
|
+
content: RenderAllDataContent;
|
|
167
|
+
}
|
|
168
|
+
export interface RenderArgs {
|
|
169
|
+
allData?: RenderAllData;
|
|
170
|
+
serverlessData?: RenderServerlessData;
|
|
171
|
+
previewData?: RenderPreviewData;
|
|
172
|
+
}
|
|
173
|
+
export interface RenderReturn {
|
|
174
|
+
slug: string;
|
|
175
|
+
output: string;
|
|
176
|
+
}
|
|
177
|
+
export type RenderContentFilter = <T>(content: string[], args: ParentArgs<T>) => Promise<string[]> | string[];
|
|
178
|
+
export type RenderItemFilter = (output: string, args: RenderItemActionArgs) => Promise<string> | string;
|
|
179
|
+
interface RenderItemDataFilterArgs {
|
|
180
|
+
contentType: string;
|
|
181
|
+
}
|
|
182
|
+
export type RenderItemDataFilter = (item: RenderItem, args: RenderItemDataFilterArgs) => Promise<RenderItem> | RenderItem;
|
|
183
|
+
export type RenderStartAction = (args: RenderArgs) => Promise<void> | void;
|
|
184
|
+
export interface RenderEndActionArgs extends RenderArgs {
|
|
185
|
+
data: RenderReturn[] | RenderReturn;
|
|
186
|
+
}
|
|
187
|
+
export type RenderEndAction = (args: RenderEndActionArgs) => Promise<void> | void;
|
|
188
|
+
export type RenderItemStartAction = (args: RenderItemStartActionArgs) => Promise<void> | void;
|
|
189
|
+
export type RenderItemEndAction = (args: RenderItemActionArgs) => Promise<void> | void;
|
|
190
|
+
export interface RenderData {
|
|
191
|
+
items: RenderItem[];
|
|
192
|
+
total?: number;
|
|
193
|
+
pages?: number;
|
|
194
|
+
skip?: number;
|
|
195
|
+
limit?: number;
|
|
196
|
+
}
|
|
197
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Scripts, Styles, ScriptsPriority } from './scriptsTypes.js';
|
|
2
|
+
declare const scripts: Scripts;
|
|
3
|
+
declare const styles: Styles;
|
|
4
|
+
declare const addScript: (path: string, deps?: string[], priority?: ScriptsPriority) => boolean;
|
|
5
|
+
declare const addStyle: (path: string, deps?: string[], priority?: ScriptsPriority) => boolean;
|
|
6
|
+
declare const outputScripts: (link: string) => string;
|
|
7
|
+
declare const outputStyles: (link: string) => string;
|
|
8
|
+
export { scripts, styles, addScript, addStyle, outputScripts, outputStyles };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isArrayStrict}from"../utils/array/array.js";import{isStringStrict}from"../utils/string/string.js";import{config}from"../config/config.js";const scripts={priority:new Map,deps:new Map,item:new Map,build:new Map,meta:{}},styles={priority:new Map,deps:new Map,item:new Map,build:new Map},addScriptStyle=(type,path,deps=[],priority)=>{if(!isStringStrict(path))return!1;const isScripts="scripts"===type,assets=isScripts?scripts:styles,ext=isScripts?"js":"scss",{inputDir:inputDir,outputDir:outputDir}=config[type],input=`${inputDir}/${path}.${ext}`,output=`${outputDir}/${path}`;return assets.item.set(output,input),assets.build.set(output,input),isArrayStrict(deps)&&deps.forEach(dep=>{const depInput=`${inputDir}/${dep}.${ext}`,depOutput=`${outputDir}/${dep}`;assets.deps.has(output)||assets.deps.set(output,new Set),assets.deps.get(output)?.add(depOutput),assets.item.set(depOutput,depInput),assets.build.set(depOutput,depInput)}),priority&&assets.priority.set(output,priority),!0},addScript=(path,deps=[],priority)=>addScriptStyle("scripts",path,deps,priority),addStyle=(path,deps=[],priority)=>addScriptStyle("styles",path,deps,priority),outputScriptsStyles=(type,link)=>{if(!isStringStrict(link))return"";const{item:item,deps:deps,priority:priority}="scripts"===type?scripts:styles;if(!item.size)return"";const itemOut=Array.from(item.keys());itemOut.sort((a,b)=>{const aIsDep=deps.get(b)?.has(a),bIsDep=deps.get(a)?.has(b);return!0===aIsDep?-1:!0===bIsDep?1:0});let output="";return itemOut.forEach(out=>{const fetchPriority=priority.has(out)?` fetchpriority="${priority.get(out)}"`:"";"scripts"===type&&(output+=`<script type="module" src="${link}${out}.js"${fetchPriority}><\/script>`),"styles"===type&&(output+=`<link rel="stylesheet" href="${link}${out}.css" media="all"${fetchPriority}>`)}),output},outputScripts=link=>outputScriptsStyles("scripts",link),outputStyles=link=>outputScriptsStyles("styles",link);export{scripts,styles,addScript,addStyle,outputScripts,outputStyles};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Generic } from '../global/globalTypes.js';
|
|
2
|
+
export type ScriptsPriority = 'high' | 'low';
|
|
3
|
+
export interface Scripts {
|
|
4
|
+
item: Map<string, string>;
|
|
5
|
+
build: Map<string, string>;
|
|
6
|
+
deps: Map<string, Set<string>>;
|
|
7
|
+
priority: Map<string, ScriptsPriority>;
|
|
8
|
+
meta: Generic;
|
|
9
|
+
}
|
|
10
|
+
export interface Styles {
|
|
11
|
+
item: Map<string, string>;
|
|
12
|
+
build: Map<string, string>;
|
|
13
|
+
deps: Map<string, Set<string>>;
|
|
14
|
+
priority: Map<string, ScriptsPriority>;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +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"../../filters/filters.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};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ServerlessActionData, ServerlessActionReturn } from '../serverlessTypes.js';
|
|
2
|
+
export interface ContactData {
|
|
3
|
+
[key: string]: string[] | ContactData;
|
|
4
|
+
}
|
|
5
|
+
export interface ContactBody extends ServerlessActionData {
|
|
6
|
+
to: string[];
|
|
7
|
+
sender: string;
|
|
8
|
+
subject: string;
|
|
9
|
+
text: string;
|
|
10
|
+
html: string;
|
|
11
|
+
replyTo?: string;
|
|
12
|
+
}
|
|
13
|
+
export type ContactResultFilter = (res: ServerlessActionReturn | null, args: ContactBody) => Promise<ServerlessActionReturn | null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ServerlessActions } from './serverlessTypes.js';
|
|
2
|
+
import type { RenderPreviewData, RenderServerlessData } from '../render/renderTypes.js';
|
|
3
|
+
import type { Generic, GenericStrings } from '../global/globalTypes.js';
|
|
4
|
+
import type { getAllContentfulData } from '../contentful/contentfulData.js';
|
|
5
|
+
import type { getAllWordPressData } from '../wordpress/wordpressData.js';
|
|
6
|
+
declare let serverlessActions: ServerlessActions;
|
|
7
|
+
declare const serverlessPreview: (request: Request) => RenderPreviewData | undefined;
|
|
8
|
+
declare const serverlessReload: (request: Request, allowedParams?: string[]) => RenderServerlessData | undefined;
|
|
9
|
+
declare const serverlessRender: (getData: typeof getAllContentfulData | typeof getAllWordPressData, serverlessData?: RenderServerlessData, previewData?: RenderPreviewData) => Promise<Response>;
|
|
10
|
+
declare const setServerless: (actions?: ServerlessActions) => void;
|
|
11
|
+
declare const doServerlessAction: (request: Request, env: Generic, headers?: GenericStrings, honeypotName?: string) => Promise<Response>;
|
|
12
|
+
export { serverlessActions, serverlessPreview, serverlessReload, serverlessRender, setServerless, doServerlessAction };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ResponseError}from"../utils/ResponseError/ResponseError.js";import{isStringStrict}from"../utils/string/string.js";import{isObjectStrict}from"../utils/object/object.js";import{isFunction}from"../utils/function/function.js";import{applyFilters}from"../filters/filters.js";import{render,renderHttpError}from"../render/render.js";import{minify}from"../utils/minify/minify.js";import{print}from"../utils/print/print.js";let serverlessActions={};const serverlessPreview=request=>{const{method:method,url:url}=request;if("GET"!==method)return;const{searchParams:searchParams}=new URL(url),contentType=searchParams.get("content_type"),locale=searchParams.get("locale"),id=searchParams.get("preview");if(!isStringStrict(id)||!isStringStrict(contentType))return;const previewData={id:id,contentType:contentType};return isStringStrict(locale)&&(previewData.locale=locale),previewData},serverlessReload=(request,allowedParams=["page","filters"])=>{const{method:method,url:url}=request;if("GET"!==method)return;const{searchParams:searchParams,pathname:pathname}=new URL(url),path=pathname,query={};let hasParams=!1;for(const param of allowedParams){const value=searchParams.get(param);isStringStrict(value)&&(query[param]=value,hasParams=!0)}return hasParams?{query:query,path:path}:void 0},serverlessRender=async(getData,serverlessData,previewData)=>{try{const data=await render({serverlessData:serverlessData,previewData:previewData,allData:await getData({serverlessData:serverlessData,previewData:previewData})});let html="",status=200;isObjectStrict(data)&&(html=data.output);const isEmpty=""===html;return isEmpty&&(status=404),isEmpty&&isFunction(renderHttpError)&&(html=await renderHttpError({code:status})),new Response(minify(html),{status:status,headers:{"Content-Type":"text/html;charset=UTF-8"}})}catch(error){print("[FRM] Error on serverless render",error);const status=500,html=await renderHttpError({code:status});return new Response(html,{status:status,headers:{"Content-Type":"text/html;charset=UTF-8"}})}},setServerless=actions=>{isObjectStrict(actions)&&(serverlessActions={...actions})},doServerlessAction=async(request,env,headers,honeypotName)=>{const serverlessHeaders={"Content-Type":"application/json",...headers};try{if("POST"!==request.method)return new Response(JSON.stringify({error:"Method not allowed"}),{status:405,headers:serverlessHeaders});const data=await request.json();if(!isObjectStrict(data))throw new Error("Data not an object");if(isStringStrict(honeypotName)&&isObjectStrict(data.inputs?.[honeypotName])){const honeypotValue=data.inputs[honeypotName].value;if(isStringStrict(honeypotValue))return new Response(JSON.stringify({success:""}),{status:200,headers:serverlessHeaders});delete data.inputs[honeypotName]}const action=data.action;if(!isStringStrict(action))throw new Error("No action");let res=null;const serverlessAction=serverlessActions[action];isFunction(serverlessAction)&&(res=await serverlessAction(data,request,env));const serverlessResultFilterArgs={data:data,request:request,env:env};if(res=await applyFilters("serverlessResult",res,serverlessResultFilterArgs,!0),!res)throw new Error("No result");if(res.error){const errorMessage=res.error.message;throw res.error.response?new ResponseError(errorMessage,res.error.response):new Error(errorMessage)}const options={status:200,headers:serverlessHeaders};let message="";if(res.success){const{message:successMessage,headers:successHeaders}=res.success;isStringStrict(successMessage)&&(message=successMessage),isObjectStrict(successHeaders)&&(options.headers={...options.headers,...successHeaders})}return new Response(JSON.stringify({success:message}),options)}catch(error){print("[FRM] Error with serverless action",error);let statusCode=500,message=error instanceof Error?error.message:"Unknown error";return error instanceof ResponseError&&(statusCode=error.response.status,message=error.message),new Response(JSON.stringify({error:message}),{status:statusCode,headers:serverlessHeaders})}};export{serverlessActions,serverlessPreview,serverlessReload,serverlessRender,setServerless,doServerlessAction};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Generic, GenericStrings } from '../global/globalTypes.js';
|
|
2
|
+
export interface ServerlessRoute {
|
|
3
|
+
path: string;
|
|
4
|
+
content?: string;
|
|
5
|
+
}
|
|
6
|
+
export type ServerlessActionPrimitive = string | number | boolean | File;
|
|
7
|
+
export interface ServerlessActionInput extends Generic {
|
|
8
|
+
value: ServerlessActionPrimitive | ServerlessActionPrimitive[];
|
|
9
|
+
type: string | string[];
|
|
10
|
+
label?: string;
|
|
11
|
+
legend?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ServerlessActionData {
|
|
14
|
+
id: string;
|
|
15
|
+
action: string;
|
|
16
|
+
inputs: Record<string, ServerlessActionInput>;
|
|
17
|
+
}
|
|
18
|
+
export interface ServerlessActionError {
|
|
19
|
+
message: string;
|
|
20
|
+
response?: Response;
|
|
21
|
+
}
|
|
22
|
+
export interface ServerlessActionSuccess {
|
|
23
|
+
message: string;
|
|
24
|
+
headers?: GenericStrings;
|
|
25
|
+
}
|
|
26
|
+
export interface ServerlessActionReturn {
|
|
27
|
+
error?: ServerlessActionError;
|
|
28
|
+
success?: ServerlessActionSuccess;
|
|
29
|
+
}
|
|
30
|
+
export type ServerlessAction = (args: ServerlessActionData, request: Request, env: Generic) => Promise<ServerlessActionReturn> | ServerlessActionReturn;
|
|
31
|
+
export type ServerlessActions = Record<string, ServerlessAction>;
|
|
32
|
+
export interface ServerlessResultOptions {
|
|
33
|
+
status: number;
|
|
34
|
+
headers?: GenericStrings;
|
|
35
|
+
}
|
|
36
|
+
export interface ServerlessResultFilterArgs {
|
|
37
|
+
data: ServerlessActionData;
|
|
38
|
+
request: Request;
|
|
39
|
+
env: Generic;
|
|
40
|
+
}
|
|
41
|
+
export type ServerlessResultFilter = (res: ServerlessActionReturn | null, args: ServerlessResultFilterArgs) => Promise<ServerlessActionReturn | null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Shortcode, Shortcodes, ShortcodesSet } from './shortcodesTypes.js';
|
|
2
|
+
import type { RenderItem } from '../render/renderTypes.js';
|
|
3
|
+
declare const shortcodes: Shortcodes;
|
|
4
|
+
declare const addShortcode: <T extends Shortcode>(name: string, shortcode: T) => boolean;
|
|
5
|
+
declare const removeShortcode: (name: string) => boolean;
|
|
6
|
+
declare const doShortcodes: (content: string, itemData?: RenderItem) => Promise<string>;
|
|
7
|
+
declare const resetShortcodes: () => void;
|
|
8
|
+
declare const setShortcodes: <T extends ShortcodesSet>(args: T) => boolean;
|
|
9
|
+
declare const stripShortcodes: (content: string) => string;
|
|
10
|
+
export { shortcodes, addShortcode, removeShortcode, doShortcodes, resetShortcodes, setShortcodes, stripShortcodes };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isObjectStrict}from"../utils/object/object.js";import{isArrayStrict}from"../utils/array/array.js";import{isStringStrict}from"../utils/string/string.js";import{isFunction}from"../utils/function/function.js";import{escape}from"../utils/escape/escape.js";const shortcodes=new Map,attrReg=/[\w-]+=".*?"/g,getShortcodeData=(content,tagNames,props,itemData)=>{if(!isStringStrict(content)||!isStringStrict(tagNames))return[];const reg=new RegExp(String.raw`\[(?:\/)?(?<name>${tagNames})(?:\s[^\]]*?)?\]`,"g"),matches=[...content.matchAll(reg)];if(!matches.length)return[];const data=[];return matches.forEach((opening,i)=>{const name=opening.groups?.name,tag=opening[0];if(!isStringStrict(name)||tag.startsWith("[/"))return;const info=props||shortcodes.get(name);if(!isObjectStrict(info))return;const child=info.child,hasChild=isStringStrict(child),startIndex=opening.index,startLen=tag.length;let endIndex=startIndex+tag.length,endLen=0;const closingTag=`[/${name}]`,closingMatch=hasChild?matches.find(m=>m[0]===closingTag):matches[i+1];closingMatch?.[0]===closingTag&&(endIndex=closingMatch.index,endLen=closingTag.length);const attrs={},attrTypes=isObjectStrict(info.attrTypes)?info.attrTypes:{},attr=tag.match(attrReg);isArrayStrict(attr)&&attr.forEach(a=>{const[key,value]=a.split("="),type=attrTypes[key];let val=escape(value.replace(/"/g,""));if("number"===type){const num=parseInt(val,10);val=isNaN(num)?0:num}"boolean"===type&&(val="true"===val),attrs[key]=val});const replaceContent=content.slice(startIndex,endIndex+endLen),innerContent=content.slice(startIndex+startLen,endIndex);let children=[];hasChild&&(children=getShortcodeData(innerContent,child,props,itemData)),data.push({name:name,replaceContent:replaceContent,content:innerContent,attr:attrs,children:children,itemData:itemData})}),data},addShortcode=(name,shortcode)=>!(!isStringStrict(name)||!isObjectStrict(shortcode))&&(shortcodes.set(name,shortcode),!0),removeShortcode=name=>!!isStringStrict(name)&&shortcodes.delete(name),doShortcodes=async(content,itemData)=>{if(!shortcodes.size)return content;const names=[...shortcodes.keys()].join("|"),data=getShortcodeData(content,names,void 0,itemData);if(!data.length)return content;let newContent=content;for(const datum of data){const{name:name,replaceContent:replaceContent}=datum,callback=shortcodes.get(name)?.callback;isFunction(callback)&&(newContent=newContent.replace(replaceContent,await callback({...datum,itemData:itemData})))}return newContent},resetShortcodes=()=>{shortcodes.clear()},setShortcodes=args=>{if(!isObjectStrict(args))return!1;const names=Object.entries(args);return!!names.length&&(resetShortcodes(),names.forEach(([name,shortcode])=>{addShortcode(name,shortcode)}),!0)},stripShortcodes=content=>{if(!shortcodes.size)return content;const names=[...shortcodes.keys()].join("|"),reg=new RegExp(String.raw`\[(?:\/)?(?<name>${names})(?:\s[^\]]*?)?\]`,"g");return content.replace(reg,()=>"")};export{shortcodes,addShortcode,removeShortcode,doShortcodes,resetShortcodes,setShortcodes,stripShortcodes};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RenderItem } from '../render/renderTypes.js';
|
|
2
|
+
export type ShortcodeAttrValue = string | number | boolean | undefined;
|
|
3
|
+
export type ShortcodeAttrs = Record<string, ShortcodeAttrValue>;
|
|
4
|
+
export type ShortcodeAttrTypes = Record<string, 'string' | 'number' | 'boolean'>;
|
|
5
|
+
export interface ShortcodeData {
|
|
6
|
+
name: string;
|
|
7
|
+
replaceContent: string;
|
|
8
|
+
content: string;
|
|
9
|
+
attr: ShortcodeAttrs;
|
|
10
|
+
children: ShortcodeData[];
|
|
11
|
+
itemData?: RenderItem;
|
|
12
|
+
}
|
|
13
|
+
export type ShortcodeCallback = (args: ShortcodeData) => string | Promise<string>;
|
|
14
|
+
export interface Shortcode {
|
|
15
|
+
callback: ShortcodeCallback;
|
|
16
|
+
attrTypes?: ShortcodeAttrTypes;
|
|
17
|
+
child?: string;
|
|
18
|
+
}
|
|
19
|
+
export type Shortcodes = Map<string, Shortcode>;
|
|
20
|
+
export type ShortcodesSet = Record<string, Shortcode>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Store } from './storeTypes.js';
|
|
2
|
+
import type { RenderAllData } from '../render/renderTypes.js';
|
|
3
|
+
declare let storeDir: string;
|
|
4
|
+
declare let store: Store;
|
|
5
|
+
declare const setStore: <T extends object>(args: T, dir?: string) => Store & T;
|
|
6
|
+
declare const setStoreItem: <T extends Store, K extends keyof T, V extends keyof T[K] | undefined = undefined>(prop: K, value: V extends keyof T[K] ? T[K][V] : T[K], subProp?: V) => boolean;
|
|
7
|
+
declare const setStoreData: (allData: RenderAllData) => boolean;
|
|
8
|
+
declare const getStoreItem: <T extends Store, K extends keyof T>(prop: K) => T[K];
|
|
9
|
+
export { store, storeDir, setStore, setStoreData, setStoreItem, getStoreItem };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{normalizeContentType}from"../utils/contentType/contentType.js";import{isObject,isObjectStrict}from"../utils/object/object.js";import{isStringStrict}from"../utils/string/string.js";import{isArrayStrict}from"../utils/array/array.js";import{getArchiveMeta}from"../utils/archive/archive.js";import{config}from"../config/config.js";let storeDir="lib/store";const defaultStore={slugs:{},parents:{},navigations:[],navigationItems:[],formMeta:{},archiveMeta:{},imageMeta:{},taxonomies:{},serverless:{}};let store={...defaultStore};const setStore=(args,dir="lib/store")=>isObjectStrict(args)?(store={...defaultStore,...args},isStringStrict(dir)&&(storeDir=dir),store):store,setStoreItem=(prop,value,subProp)=>!(!isStringStrict(prop)||!isObject(value)||null==store[prop])&&(isStringStrict(subProp)?store[prop][subProp]=value:store[prop]=value,!0),setStoreData=allData=>{if(!isObjectStrict(allData))return!1;const{navigation:navigation,navigationItem:navigationItem,content:content}=allData;store.navigations=isArrayStrict(navigation)?navigation:[],store.navigationItems=isArrayStrict(navigationItem)?navigationItem:[];const data={...allData,...content};return config.hierarchicalTypes.forEach(type=>{const items=data[type];isArrayStrict(items)&&items.forEach(item=>{if(!isObjectStrict(item))return;const{id:id,parent:parent,archive:archive,slug:slug,title:title,locale:locale}=item;if(!isStringStrict(id))return;const archiveType=normalizeContentType(archive);if(isStringStrict(archiveType)){const hasLocale=isStringStrict(locale),archiveMeta=getArchiveMeta(archiveType),newArchive={id:id,slug:slug,title:title,contentType:type,...hasLocale?archiveMeta[locale]:archiveMeta};hasLocale?(store.archiveMeta[archiveType]||(store.archiveMeta[archiveType]={}),store.archiveMeta[archiveType][locale]=newArchive):store.archiveMeta[archiveType]=newArchive}if(isObjectStrict(parent)){const parentSlug=parent.slug,parentTitle=parent.title,parentId=parent.id;isStringStrict(parentSlug)&&isStringStrict(parentTitle)&&isStringStrict(parentId)&&(null==store.parents[type]&&(store.parents[type]={}),store.parents[type][id]=[parentId,parentSlug,parentTitle])}})}),!0},getStoreItem=prop=>store[prop];export{store,storeDir,setStore,setStoreData,setStoreItem,getStoreItem};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{mkdir,writeFile}from"node:fs/promises";import{resolve}from"node:path";import{print}from"../utils/print/print.js";import{storeDir,store}from"./store.js";const createStoreFiles=async()=>{await mkdir(resolve(storeDir),{recursive:!0});for(const[key,data]of Object.entries(store)){const path=resolve(storeDir,`${key}.json`);await writeFile(path,JSON.stringify(data)),print("[FRM] Successfully wrote",path,"success")}};export{createStoreFiles};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Generic, Taxonomy } from '../global/globalTypes.js';
|
|
2
|
+
import type { NavigationList, NavigationItem } from '../components/Navigation/NavigationTypes.js';
|
|
3
|
+
import type { ArchiveMeta } from '../utils/archive/archiveTypes.js';
|
|
4
|
+
import type { ImageProps } from '../utils/image/imageTypes.js';
|
|
5
|
+
import type { FormMeta } from '../objects/Form/FormTypes.js';
|
|
6
|
+
export type StoreSlugs = Record<string, [string, string, string?]>;
|
|
7
|
+
export type StoreParents = Record<string, Record<string, [string, string, string]>>;
|
|
8
|
+
export type StoreArchiveMeta = Record<string, ArchiveMeta | Record<string, ArchiveMeta>>;
|
|
9
|
+
export type StoreFormMeta = Record<string, FormMeta>;
|
|
10
|
+
export type StoreImageMeta = Record<string, ImageProps>;
|
|
11
|
+
export type StoreTaxonomies = Record<string, Taxonomy>;
|
|
12
|
+
interface StorePrimitiveGeneric {
|
|
13
|
+
[key: string]: StorePrimitive;
|
|
14
|
+
}
|
|
15
|
+
export type StorePrimitive = string | number | boolean | null | undefined | StorePrimitive[] | StorePrimitiveGeneric;
|
|
16
|
+
export type StoreServerless<T extends StorePrimitive[]> = Record<string, T>;
|
|
17
|
+
export interface Store extends Generic {
|
|
18
|
+
slugs: StoreSlugs;
|
|
19
|
+
parents: StoreParents;
|
|
20
|
+
archiveMeta: StoreArchiveMeta;
|
|
21
|
+
formMeta: StoreFormMeta;
|
|
22
|
+
imageMeta: StoreImageMeta;
|
|
23
|
+
navigations: NavigationList[];
|
|
24
|
+
navigationItems: NavigationItem[];
|
|
25
|
+
taxonomies: StoreTaxonomies;
|
|
26
|
+
serverless: StoreServerless<StorePrimitive[]>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|