@paroicms/contact-form-plugin 0.27.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/backend/dist/plugin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
1
|
import { escapeHtml, loadSimpleTranslatorFromDirectory, makeStylesheetLinkAsyncTag, resolveModuleDirectory, } from "@paroicms/public-server-lib";
|
|
4
2
|
import { type } from "arktype";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
5
|
import { sendContactFormMail } from "./contact-form-mail.js";
|
|
6
6
|
import { SendMailInputBody } from "./data-format.js";
|
|
7
7
|
const SLUG = "contact-form";
|
|
@@ -14,7 +14,6 @@ const plugin = {
|
|
|
14
14
|
async siteInit(service) {
|
|
15
15
|
const simpleI18n = await loadSimpleTranslatorFromDirectory({
|
|
16
16
|
l10nDir: join(projectDir, "locales"),
|
|
17
|
-
languages: ["en", "fr"],
|
|
18
17
|
logger: service.logger,
|
|
19
18
|
});
|
|
20
19
|
service.setPublicAssetsDirectory(join(packageDir, "frontend", "dist"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{template as $,insert as
|
|
1
|
+
import{template as $,insert as c,setAttribute as h,createComponent as C,effect as P,render as ae}from"https://esm.sh/solid-js@1.9.7/web";import{createMemo as re,createSignal as i,Show as B,onMount as oe,onCleanup as ce}from"https://esm.sh/solid-js@1.9.7";const le={en:{en:"English",fr:"French"},fr:{en:"Anglais",fr:"Français"}},J=Object.keys(le);function ie(e,{pluginLanguages:t,siteLanguages:n=[]}){if(t.includes(e)||J.includes(e)&&t.includes(e))return e;const a=n.find((r=>J.includes(r)&&t.includes(r)));return a||(t.includes("en")?"en":t[0]??"en")}const V=e=>e!=null&&(e=Object.getPrototypeOf(e),e===Array.prototype||e===Object.prototype);function Y(e,t,n){for(const[a,r]of Object.entries(t)){const d=`${n}.${a}`;e[d]=r,V(r)&&Y(e,r,d)}}function de(e){const t={...e};for(const[n,a]of Object.entries(e))V(a)&&Y(t,a,n);return t}const ue=(e,t)=>{if(t)for(const[n,a]of Object.entries(t))e=e.replace(new RegExp(`{{\\s*${n}\\s*}}`,"g"),a);return e},me=e=>e;function pe(e,t=me){return(n,...a)=>{n[0]==="."&&(n=n.slice(1));const r=e()?.[n];switch(typeof r){case"function":return r(...a);case"string":return t(r,a[0]);default:return r}}}const fe="Name",he="Email",ge="Subject",be="Message",ve="Send",Pe="johndoe@gmail.com",$e="John Doe",ye="The subject of your message",Ee="Enter your message here…",we="Unexpected error, the message could not be sent.",Fe="Return Home",Se="Your message has been sent. If there is a response, it will be sent to the address:",xe={name:fe,email:he,subject:ge,message:be,send:ve,emailPlaceholder:Pe,namePlaceholder:$e,subjectPlaceholder:ye,messagePlaceholder:Ee,unexpectedErrorMessage:we,returnHome:Fe,successMessage:Se},je="Nom",_e="Courriel",Ce="Sujet",Me="Message",Re="Envoyer",ke="johndoe@gmail.com",Oe="John Doe",Le="Le sujet de votre message",He="Saisissez votre message…",Te="Erreur inattendue, le message n'a pas pu être envoyé.",Ae="Retourner à l'accueil",De="Votre message a été envoyé. S'il y a une réponse, elle sera envoyée à l'adresse :",Ie={name:je,email:_e,subject:Ce,message:Me,send:Re,emailPlaceholder:ke,namePlaceholder:Oe,subjectPlaceholder:Le,messagePlaceholder:He,unexpectedErrorMessage:Te,returnHome:Ae,successMessage:De},z={en:xe,fr:Ie};function Ne(e,t){const n=re((()=>{const r=Object.keys(z),y=ie(e,{pluginLanguages:r,siteLanguages:t});return de(z[y])}));return{t:pe(n,ue)}}async function Ue(e,t,n){n(!0);try{const a=await Be(e);return t.reset(),a}finally{n(!1)}}async function Be(e){const t=await fetch("/api/plugin/contact-form",{headers:{"Content-Type":"application/json"},body:JSON.stringify(e),method:"POST"});if(t.status!==200){const a=await t.text();throw new Error(`Unexpected error: ${a}`)}return await t.json()}var Je=$("<div class=PaForm-error>"),ze=$('<div class=PaForm-ended><div class=PaForm-message><p> <i></i></p></div><div class=PaForm-action><a class="PaForm-button PaButton">'),Ge=$('<form class=PaForm><div class=PaForm-fields><label class=PaField><span class=PaField-label></span><input class=PaField-input type=text name=name required></label><label class=PaField><span class=PaField-label></span><input class=PaField-input type=email name=email required></label><label class=PaField><span class=PaField-label></span><textarea class=PaField-input rows=5 name=message required></textarea></label></div><div class=PaForm-action><button class="PaForm-button PaButton"type=submit>'),Ve=$("<div class=PaForm-captcha><div class=g-recaptcha data-callback=onRecaptchaSubmitted data-expired-callback=onRecaptchaExpired>");function Ye({googleRecaptchaSiteKey:e,language:t,homeUrl:n}){const[a,r]=i(""),[d,y]=i(""),[R,q]=i(""),[Q,W]=i(),[k,O]=i(!e),[L,E]=i(),[X,H]=i(""),[Z,K]=i(!1),{t:o}=Ne(t),ee=async l=>{try{if(l.preventDefault(),!k()||!g)throw new Error("Recaptcha error");const u=await Ue({language:t,name:a(),message:R(),email:d(),gRecaptchaResponse:Q()},g,K);u.success?E(!0):(E(!1),H(u.message??o("unexpectedErrorMessage")))}catch{E(!1),H(o("unexpectedErrorMessage"))}},g=(()=>{var l=Ge(),u=l.firstChild,T=u.firstChild,A=T.firstChild,w=A.nextSibling,D=T.nextSibling,I=D.firstChild,F=I.nextSibling,ne=D.nextSibling,N=ne.firstChild,S=N.nextSibling,x=u.nextSibling,j=x.firstChild;return l.addEventListener("submit",ee),c(A,(()=>o("name"))),w.addEventListener("change",(s=>r(s.currentTarget.value))),c(I,(()=>o("email"))),F.addEventListener("change",(s=>{y(s.currentTarget.value)})),c(N,(()=>o("message"))),S.addEventListener("change",(s=>q(s.currentTarget.value))),c(l,e&&(()=>{var s=Ve(),m=s.firstChild;return h(m,"data-sitekey",e),s})(),x),c(l,C(B,{get when(){return L()===!1},get children(){var s=Je();return c(s,X),s}}),x),c(j,(()=>o("send"))),c(l,C(B,{get when(){return L()===!0},get children(){var s=ze(),m=s.firstChild,p=m.firstChild,f=p.firstChild,b=f.nextSibling,v=m.nextSibling,U=v.firstChild;return c(p,(()=>o("successMessage")),f),c(b,d),h(U,"href",n),c(U,(()=>o("returnHome"))),s}}),null),P((s=>{var m=o("namePlaceholder"),p=o("emailPlaceholder"),f=o("messagePlaceholder"),b=!!Z(),v=!k();return m!==s.e&&h(w,"placeholder",s.e=m),p!==s.t&&h(F,"placeholder",s.t=p),f!==s.a&&h(S,"placeholder",s.a=f),b!==s.o&&j.classList.toggle("inProgress",s.o=b),v!==s.i&&(j.disabled=s.i=v),s}),{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),P((()=>w.value=a())),P((()=>F.value=d())),P((()=>S.value=R())),l})();return oe((()=>{e&&(window.onRecaptchaSubmitted=te,window.onRecaptchaExpired=se)})),ce((()=>{e&&(window.onRecaptchaSubmitted=void 0,window.onRecaptchaExpired=void 0)})),g;function te(l){if(!l)return;O(!0);const u=g?.elements.namedItem("g-recaptcha-response");W(u.value)}function se(){O(!1)}}let M;const[_]=document.getElementsByClassName("js-script-contact-form");_&&_ instanceof HTMLScriptElement&&(M=_.dataset.googleRecaptchaSiteKey);if(!M)throw new Error('Missing "data-google-recaptcha-site-key" or the script element "js-script-contact-form"');function qe(e,{language:t}){if(!t)throw new Error("Missing language");e.dataset.recaptchaKey&&console.warn('Remove "data-recaptcha-key" attribute, it is not needed anymore.');const n=e.dataset.homeUrl;if(!n)throw new Error('Missing "data-home-url"');const a=document.createElement("script");a.setAttribute("src","https://www.google.com/recaptcha/api.js"),document.head.appendChild(a),ae((()=>C(Ye,{googleRecaptchaSiteKey:M,language:t,homeUrl:n})),e)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",G):G();function G(){const e=document.documentElement.lang,t=document.querySelector("[data-effect='paContactForm']");t&&qe(t,{language:e})}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paroicms/contact-form-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Contact form plugin for ParoiCMS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"paroicms",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@paroicms/public-server-lib": "0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@paroicms/public-anywhere-lib": "0.
|
|
38
|
-
"@paroicms/public-server-lib": "0.
|
|
37
|
+
"@paroicms/public-anywhere-lib": "0.27.0",
|
|
38
|
+
"@paroicms/public-server-lib": "0.38.0",
|
|
39
39
|
"@solid-primitives/i18n": "~2.2.1",
|
|
40
40
|
"@types/node": "~24.0.1",
|
|
41
41
|
"rimraf": "~6.0.1",
|