@easy-cms/plugin-form-builder 0.19.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kanawoot K.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # @easy-cms/plugin-form-builder
2
+
3
+ Forms for [Easy CMS](https://maritonx.github.io/easy-cms/): editors build them in the admin from
4
+ field blocks; visitors' submissions are validated, stored and emailed; honeypot, timing, rate
5
+ limits and Cloudflare Turnstile keep bots out; `<easy-form>` puts a form on any page.
6
+
7
+ ```ts
8
+ import { formBuilderPlugin } from '@easy-cms/plugin-form-builder'
9
+
10
+ export default defineConfig({
11
+ // …
12
+ email: smtp(), // from @easy-cms/email-smtp, for notifications
13
+ plugins: [formBuilderPlugin({ defaultTo: 'hello@example.com' })],
14
+ })
15
+ ```
16
+
17
+ ```html
18
+ <script type="module" src="/api/cms/form/element.js"></script>
19
+ <easy-form form="contact"></easy-form>
20
+ ```
21
+
22
+ See [Forms](https://maritonx.github.io/easy-cms/guide/forms).
package/dist/admin.js ADDED
@@ -0,0 +1,23 @@
1
+ var l={en:{title:"Submissions",count:"{n} received",none:"None yet",view:"View submissions",csv:"Export CSV",embed:"Put it on a page",unsaved:"Save the form to see its submissions.",draft:"Publish the form to accept submissions."},th:{title:"\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E2A\u0E48\u0E07\u0E21\u0E32",count:"\u0E44\u0E14\u0E49\u0E23\u0E31\u0E1A {n} \u0E23\u0E32\u0E22\u0E01\u0E32\u0E23",none:"\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35",view:"\u0E14\u0E39\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E2A\u0E48\u0E07\u0E21\u0E32",csv:"Export CSV",embed:"\u0E43\u0E2A\u0E48\u0E43\u0E19\u0E2B\u0E19\u0E49\u0E32\u0E40\u0E27\u0E47\u0E1A",unsaved:"\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01\u0E1F\u0E2D\u0E23\u0E4C\u0E21\u0E01\u0E48\u0E2D\u0E19\u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E14\u0E39\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E2A\u0E48\u0E07\u0E21\u0E32",draft:"\u0E40\u0E1C\u0E22\u0E41\u0E1E\u0E23\u0E48\u0E1F\u0E2D\u0E23\u0E4C\u0E21\u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E40\u0E23\u0E34\u0E48\u0E21\u0E23\u0E31\u0E1A\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25"}},s=r=>r.replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]),u=`
2
+ :host { display: block; font: inherit; color: var(--text); }
3
+ h3 { margin: 0 0 0.5rem; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; color: var(--text-muted); }
4
+ p { margin: 0 0 0.6rem; font-size: 0.875rem; }
5
+ .hint { color: var(--text-muted); font-size: 0.8rem; }
6
+ .actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
7
+ a.btn {
8
+ display: inline-flex; align-items: center; min-height: 1.9rem; padding: 0 0.7rem;
9
+ border: 1px solid var(--border-strong); border-radius: var(--radius-sm, 8px);
10
+ background: var(--surface); color: var(--text); font-size: 0.8rem; font-weight: 500; text-decoration: none;
11
+ }
12
+ a.btn:hover { background: var(--surface-2); }
13
+ a.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
14
+ code { display: block; padding: 0.5rem; border-radius: var(--radius-sm, 8px); background: var(--surface-2); font-size: 0.75rem; overflow-x: auto; white-space: pre; }
15
+ `,c=class r extends HTMLElement{props={};total=null;loadedFor;static{for(let t of["doc","id","uiLocale","options","api","collection","value","path","global","locale","readOnly","apiVersion","field","label"])Object.defineProperty(r.prototype,t,{get(){return this.props[t]},set(e){this.props[t]=e,this.render()}})}constructor(){super(),this.attachShadow({mode:"open"})}connectedCallback(){this.render()}t(t,e){return(this.props.uiLocale==="th"?l.th:l.en)[t].replace("{n}",String(e??""))}async count(t,e){let o=this.props.api;if(!(!o||t===this.loadedFor)){this.loadedFor=t;try{let n=await o("GET",`/${e.submissions}?where[form][equals]=${encodeURIComponent(String(t))}&limit=1`);this.total=n.totalDocs??0}catch{this.total=null}this.render()}}render(){let t=this.shadowRoot;if(!t)return;let e=this.props.options??{},o=this.props.id,n=this.props.doc??{},i=typeof n.slug=="string"?n.slug:"",a;if(o==null)a=`<p class="hint">${s(this.t("unsaved"))}</p>`;else{this.count(o,e);let p=`${e.adminPath}/collections/${e.submissions}?f_form=${encodeURIComponent(String(o))}`,d=`${e.apiPath}/form/${encodeURIComponent(i)}/submissions.csv`;a=`
16
+ <p>${s(this.total===null?"\u2026":this.total===0?this.t("none"):this.t("count",this.total))}</p>
17
+ <div class="actions">
18
+ <a class="btn" href="${s(p)}">${s(this.t("view"))}</a>
19
+ ${i?`<a class="btn" href="${s(d)}" download>${s(this.t("csv"))}</a>`:""}
20
+ </div>
21
+ ${n.status==="draft"?`<p class="hint">${s(this.t("draft"))}</p>`:""}
22
+ ${i?`<h3>${s(this.t("embed"))}</h3><code>${s(`<easy-form form="${i}"></easy-form>`)}</code>`:""}
23
+ `}t.innerHTML=`<style>${u}</style><section aria-label="${s(this.t("title"))}"><h3>${s(this.t("title"))}</h3>${a}</section>`}};customElements.get("ecms-form-submissions")||customElements.define("ecms-form-submissions",c);
@@ -0,0 +1,18 @@
1
+ // src/shared.ts
2
+ var FIELD_KINDS = [
3
+ "text",
4
+ "textarea",
5
+ "email",
6
+ "number",
7
+ "phone",
8
+ "select",
9
+ "checkbox",
10
+ "date",
11
+ "message"
12
+ ];
13
+ var formPath = (slug) => `/form/${encodeURIComponent(slug)}`;
14
+
15
+ export {
16
+ FIELD_KINDS,
17
+ formPath
18
+ };
@@ -0,0 +1,23 @@
1
+ import { P as PublicForm, S as Submission, a as SubmitResult } from './shared-BP_sUDqY.js';
2
+ export { C as Confirmation, F as FieldKind, b as PublicField } from './shared-BP_sUDqY.js';
3
+
4
+ interface ClientOptions {
5
+ /** The REST API's address, e.g. `/api/cms` or `https://cms.example.com/api/cms`. */
6
+ readonly api: string;
7
+ /** The `fetch` to use (e.g. Nuxt's `$fetch` wrapper, or a test double). */
8
+ readonly fetch?: typeof fetch;
9
+ }
10
+ /**
11
+ * A published form, ready to render: its fields in `locale`, the submit label, and the token to
12
+ * send back with the submission. `null` when there is no such published form.
13
+ */
14
+ declare function getForm(slug: string, options: ClientOptions & {
15
+ readonly locale?: string | null;
16
+ }): Promise<PublicForm | null>;
17
+ /**
18
+ * Sends a submission. Resolves to the confirmation (a message or a redirect), or to the errors:
19
+ * per field (`field`) for invalid values, or for the whole form (too many submissions…).
20
+ */
21
+ declare function submitForm(slug: string, submission: Submission, options: ClientOptions): Promise<SubmitResult>;
22
+
23
+ export { type ClientOptions, PublicForm, Submission, SubmitResult, getForm, submitForm };
package/dist/client.js ADDED
@@ -0,0 +1,35 @@
1
+ import {
2
+ formPath
3
+ } from "./chunk-7TOHDI4J.js";
4
+
5
+ // src/client.ts
6
+ var base = (api) => api.replace(/\/+$/, "");
7
+ async function getForm(slug, options) {
8
+ const query = options.locale ? `?locale=${encodeURIComponent(options.locale)}` : "";
9
+ const response = await (options.fetch ?? fetch)(`${base(options.api)}${formPath(slug)}${query}`, {
10
+ credentials: "omit"
11
+ });
12
+ if (response.status === 404) return null;
13
+ if (!response.ok) throw new Error(`Could not load form "${slug}" (${response.status})`);
14
+ return await response.json();
15
+ }
16
+ async function submitForm(slug, submission, options) {
17
+ const response = await (options.fetch ?? fetch)(`${base(options.api)}${formPath(slug)}/submit`, {
18
+ method: "POST",
19
+ // No cookies: a logged-in editor viewing the site submits like any visitor.
20
+ credentials: "omit",
21
+ headers: { "content-type": "application/json" },
22
+ body: JSON.stringify(submission)
23
+ });
24
+ const body = await response.json().catch(() => ({}));
25
+ if (response.ok && body.confirmation) return { ok: true, confirmation: body.confirmation };
26
+ return {
27
+ ok: false,
28
+ status: response.status,
29
+ errors: body.errors ?? [{ message: `Could not send the form (${response.status})` }]
30
+ };
31
+ }
32
+ export {
33
+ getForm,
34
+ submitForm
35
+ };
@@ -0,0 +1,86 @@
1
+ /* Optional defaults for <easy-form>. Override with your own CSS, or leave this file out. */
2
+ .easy-form {
3
+ --easy-form-gap: 1rem;
4
+ --easy-form-border: #d0d7de;
5
+ --easy-form-radius: 8px;
6
+ --easy-form-accent: #2f6f5e;
7
+ --easy-form-error: #cf222e;
8
+ display: grid;
9
+ gap: var(--easy-form-gap);
10
+ font: inherit;
11
+ }
12
+ .easy-form__fields {
13
+ display: grid;
14
+ grid-template-columns: repeat(2, minmax(0, 1fr));
15
+ gap: var(--easy-form-gap);
16
+ }
17
+ .easy-form__field,
18
+ .easy-form__message {
19
+ grid-column: 1 / -1;
20
+ display: grid;
21
+ gap: 0.35rem;
22
+ margin: 0;
23
+ padding: 0;
24
+ border: 0;
25
+ }
26
+ .easy-form__field--half {
27
+ grid-column: span 1;
28
+ }
29
+ @media (max-width: 480px) {
30
+ .easy-form__field--half {
31
+ grid-column: 1 / -1;
32
+ }
33
+ }
34
+ .easy-form__label {
35
+ font-weight: 600;
36
+ }
37
+ .easy-form__required {
38
+ color: var(--easy-form-error);
39
+ }
40
+ .easy-form__input {
41
+ width: 100%;
42
+ box-sizing: border-box;
43
+ padding: 0.55rem 0.7rem;
44
+ border: 1px solid var(--easy-form-border);
45
+ border-radius: var(--easy-form-radius);
46
+ font: inherit;
47
+ background: #fff;
48
+ color: inherit;
49
+ }
50
+ .easy-form__input:focus {
51
+ outline: 2px solid var(--easy-form-accent);
52
+ outline-offset: 1px;
53
+ }
54
+ .easy-form__input[aria-invalid="true"] {
55
+ border-color: var(--easy-form-error);
56
+ }
57
+ .easy-form__check,
58
+ .easy-form__choice {
59
+ display: flex;
60
+ gap: 0.5rem;
61
+ align-items: center;
62
+ }
63
+ .easy-form__error,
64
+ .easy-form__status--error {
65
+ margin: 0;
66
+ color: var(--easy-form-error);
67
+ font-size: 0.875rem;
68
+ }
69
+ .easy-form__status:empty {
70
+ display: none;
71
+ }
72
+ .easy-form__submit {
73
+ justify-self: start;
74
+ padding: 0.6rem 1.2rem;
75
+ border: 0;
76
+ border-radius: var(--easy-form-radius);
77
+ background: var(--easy-form-accent);
78
+ color: #fff;
79
+ font: inherit;
80
+ font-weight: 600;
81
+ cursor: pointer;
82
+ }
83
+ .easy-form__submit:disabled {
84
+ opacity: 0.6;
85
+ cursor: default;
86
+ }
@@ -0,0 +1,12 @@
1
+ var b=o=>`/form/${encodeURIComponent(o)}`;var v=o=>o.replace(/\/+$/,"");async function k(o,e){let r=e.locale?`?locale=${encodeURIComponent(e.locale)}`:"",t=await(e.fetch??fetch)(`${v(e.api)}${b(o)}${r}`,{credentials:"omit"});if(t.status===404)return null;if(!t.ok)throw new Error(`Could not load form "${o}" (${t.status})`);return await t.json()}async function _(o,e,r){let t=await(r.fetch??fetch)(`${v(r.api)}${b(o)}/submit`,{method:"POST",credentials:"omit",headers:{"content-type":"application/json"},body:JSON.stringify(e)}),s=await t.json().catch(()=>({}));return t.ok&&s.confirmation?{ok:!0,confirmation:s.confirmation}:{ok:!1,status:t.status,errors:s.errors??[{message:`Could not send the form (${t.status})`}]}}var x={en:{loading:"Loading the form\u2026",missing:"This form is not available.",sending:"Sending\u2026",failed:"Could not send the form. Check your connection and try again.",fix:"Please check the fields marked below.",choose:"Choose\u2026",required:"Required"},th:{loading:"\u0E01\u0E33\u0E25\u0E31\u0E07\u0E42\u0E2B\u0E25\u0E14\u0E1F\u0E2D\u0E23\u0E4C\u0E21\u2026",missing:"\u0E1F\u0E2D\u0E23\u0E4C\u0E21\u0E19\u0E35\u0E49\u0E44\u0E21\u0E48\u0E1E\u0E23\u0E49\u0E2D\u0E21\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19",sending:"\u0E01\u0E33\u0E25\u0E31\u0E07\u0E2A\u0E48\u0E07\u2026",failed:"\u0E2A\u0E48\u0E07\u0E1F\u0E2D\u0E23\u0E4C\u0E21\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08 \u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E01\u0E32\u0E23\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E41\u0E25\u0E49\u0E27\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",fix:"\u0E42\u0E1B\u0E23\u0E14\u0E15\u0E23\u0E27\u0E08\u0E0A\u0E48\u0E2D\u0E07\u0E17\u0E35\u0E48\u0E21\u0E35\u0E40\u0E04\u0E23\u0E37\u0E48\u0E2D\u0E07\u0E2B\u0E21\u0E32\u0E22\u0E14\u0E49\u0E32\u0E19\u0E25\u0E48\u0E32\u0E07",choose:"\u0E40\u0E25\u0E37\u0E2D\u0E01\u2026",required:"\u0E08\u0E33\u0E40\u0E1B\u0E47\u0E19"}},i=o=>o.replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[e]),C="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",S;function T(){return S??=new Promise((o,e)=>{let r=document.createElement("script");r.src=C,r.async=!0,r.onload=()=>o(),r.onerror=()=>e(new Error("Could not load Cloudflare Turnstile")),document.head.append(r)}),S}var q=0,g=class extends HTMLElement{static observedAttributes=["form","api","locale"];form=null;turnstileToken="";turnstileId;uid=`easy-form-${++q}`;get api(){return this.getAttribute("api")||"/api/cms"}get locale(){return this.getAttribute("locale")||document.documentElement.lang||null}t(e){return((this.form?.locale??this.locale)?.startsWith("th")?x.th:x.en)[e]}connectedCallback(){this.load()}attributeChangedCallback(e,r,t){r!==t&&this.isConnected&&this.load()}async load(){let e=this.getAttribute("form");if(e){this.innerHTML=`<p class="easy-form__status" role="status">${i(this.t("loading"))}</p>`;try{this.form=await k(e,{api:this.api,locale:this.locale})}catch{this.form=null}if(!this.form){this.innerHTML=`<p class="easy-form__status easy-form__status--error" role="alert">${i(this.t("missing"))}</p>`;return}this.render(this.form)}}render(e){let r=e.fields.map(s=>this.field(s)).join("");this.innerHTML=`
2
+ <form class="easy-form" novalidate>
3
+ <div class="easy-form__fields">${r}</div>
4
+ <div class="easy-form__hp" aria-hidden="true" style="position:absolute;left:-10000px;width:1px;height:1px;overflow:hidden">
5
+ <label>Leave this empty <input type="text" name="${i(e.honeypot)}" tabindex="-1" autocomplete="off"></label>
6
+ </div>
7
+ ${e.turnstile?'<div class="easy-form__turnstile"></div>':""}
8
+ <p class="easy-form__status" role="status" aria-live="polite"></p>
9
+ <button type="submit" class="easy-form__submit">${i(e.submitLabel)}</button>
10
+ </form>`;let t=this.querySelector("form");t.addEventListener("submit",s=>{s.preventDefault(),this.submit(t)}),e.turnstile&&this.mountTurnstile(e.turnstile)}field(e){let r=`${this.uid}-${e.name}`,t=`easy-form__field easy-form__field--${e.kind} easy-form__field--${e.width}`;if(e.kind==="message")return`<div class="easy-form__message">${e.html??""}</div>`;let s=e.required?' required aria-required="true"':"",n=e.required?` <span class="easy-form__required" aria-label="${i(this.t("required"))}">*</span>`:"",u=`<label class="easy-form__label" for="${r}">${i(e.label)}${n}</label>`,c=e.placeholder?` placeholder="${i(e.placeholder)}"`:"",a=typeof e.defaultValue=="string"?` value="${i(e.defaultValue)}"`:"",l=`<p class="easy-form__error" id="${r}-error" hidden></p>`,d=`id="${r}" name="${i(e.name)}" aria-describedby="${r}-error"${s}`,m;switch(e.kind){case"textarea":m=`<textarea class="easy-form__input" ${d}${c} rows="5">${i(typeof e.defaultValue=="string"?e.defaultValue:"")}</textarea>`;break;case"checkbox":return`<div class="${t}">
11
+ <label class="easy-form__check"><input type="checkbox" ${d}${e.defaultValue===!0?" checked":""}> ${i(e.label)}${n}</label>
12
+ ${l}</div>`;case"select":{let p=e.options??[];if(e.display==="radio"){let f=e.multiple?"checkbox":"radio",w=p.map(($,E)=>`<label class="easy-form__choice"><input type="${f}" name="${i(e.name)}" value="${i($.value)}" id="${r}-${E}"${e.required&&!e.multiple?" required":""}> ${i($.label)}</label>`).join("");return`<fieldset class="${t}" aria-describedby="${r}-error"><legend class="easy-form__label">${i(e.label)}${n}</legend>${w}${l}</fieldset>`}let y=p.map(f=>`<option value="${i(f.value)}">${i(f.label)}</option>`).join(""),h=e.multiple?"":`<option value="">${i(e.placeholder??this.t("choose"))}</option>`;m=`<select class="easy-form__input" ${d}${e.multiple?" multiple":""}>${h}${y}</select>`;break}default:{let p=e.kind==="email"?"email":e.kind==="number"?"number":e.kind==="phone"?"tel":e.kind==="date"?"date":"text",y=`${e.min!==void 0?` min="${e.min}"`:""}${e.max!==void 0?` max="${e.max}"`:""}`,h=e.kind==="email"?' autocomplete="email"':e.kind==="phone"?' autocomplete="tel"':"";m=`<input class="easy-form__input" type="${p}" ${d}${c}${a}${y}${h}>`}}return`<div class="${t}">${u}${m}${l}</div>`}async mountTurnstile(e){try{await T();let r=window.turnstile,t=this.querySelector(".easy-form__turnstile");if(!r||!t)return;this.turnstileId=r.render(t,{sitekey:e,callback:s=>{this.turnstileToken=s}})}catch{this.status(this.t("failed"),!0)}}values(e){let r={};for(let t of this.form?.fields??[]){if(t.kind==="message")continue;let s=[...e.querySelectorAll(`[name="${CSS.escape(t.name)}"]`)];t.kind==="checkbox"?r[t.name]=s[0]?.checked===!0:t.kind==="select"&&t.multiple?r[t.name]=t.display==="radio"?s.filter(n=>n.checked).map(n=>n.value):[...s[0]?.selectedOptions??[]].map(n=>n.value):t.kind==="select"&&t.display==="radio"?r[t.name]=s.find(n=>n.checked)?.value??"":r[t.name]=s[0]?.value??""}return r}async submit(e){let r=this.form;if(!r)return;let t=e.querySelector(".easy-form__submit");t&&(t.disabled=!0),this.clearErrors(),this.status(this.t("sending"),!1);let s=e.querySelector(`[name="${CSS.escape(r.honeypot)}"]`),n;try{n=await _(r.slug,{data:this.values(e),token:r.token,page:location.pathname+location.search,locale:r.locale,...r.turnstile?{turnstile:this.turnstileToken}:{},[r.honeypot]:s?.value??""},{api:this.api})}catch{n={ok:!1,status:0,errors:[{message:this.t("failed")}]}}if(t&&(t.disabled=!1),n.ok){this.dispatchEvent(new CustomEvent("easy-form:submitted",{detail:{confirmation:n.confirmation},bubbles:!0})),this.confirm(n.confirmation);return}this.dispatchEvent(new CustomEvent("easy-form:error",{detail:{errors:n.errors},bubbles:!0}));let u=0;for(let a of n.errors){if(!a.field)continue;let l=this.querySelector(`#${CSS.escape(`${this.uid}-${a.field}-error`)}`);l&&(l.textContent=a.message,l.hidden=!1,this.querySelector(`#${CSS.escape(`${this.uid}-${a.field}`)}`)?.setAttribute("aria-invalid","true"),u++)}let c=n.errors.filter(a=>!a.field).map(a=>a.message);this.status(c.join(" ")||(u?this.t("fix"):this.t("failed")),!0),n.status===400&&!u?this.load():this.turnstileId!==void 0&&window.turnstile?.reset(this.turnstileId)}confirm(e){if(e.type==="redirect"){location.assign(e.url);return}this.innerHTML=`<div class="easy-form__confirmation" role="status" tabindex="-1">${e.html}</div>`,this.querySelector(".easy-form__confirmation")?.focus()}clearErrors(){for(let e of this.querySelectorAll(".easy-form__error"))e.hidden=!0,e.textContent="";for(let e of this.querySelectorAll("[aria-invalid]"))e.removeAttribute("aria-invalid")}status(e,r){let t=this.querySelector(".easy-form__status");t&&(t.textContent=e,t.classList.toggle("easy-form__status--error",r))}};typeof customElements<"u"&&!customElements.get("easy-form")&&customElements.define("easy-form",g);export{g as EasyFormElement};
@@ -0,0 +1,43 @@
1
+ import { Plugin } from '@easy-cms/core';
2
+ import { F as FieldKind } from './shared-BP_sUDqY.js';
3
+ export { C as Confirmation, c as FIELD_KINDS, b as PublicField, P as PublicForm, S as Submission, a as SubmitResult } from './shared-BP_sUDqY.js';
4
+
5
+ interface FormBuilderOptions {
6
+ /** Field types editors can add. Default: all. */
7
+ readonly fields?: readonly FieldKind[];
8
+ /** Sender of form emails that don't set one. Default: the email adapter's `from`. */
9
+ readonly defaultFrom?: string;
10
+ /** Recipients of form emails whose "To" is empty, e.g. the site owner. */
11
+ readonly defaultTo?: string | readonly string[];
12
+ /**
13
+ * Submissions allowed per visitor (by IP address) and form in `window` seconds. Default
14
+ * 5 in 600. `false` turns it off.
15
+ */
16
+ readonly rateLimit?: {
17
+ readonly max?: number;
18
+ readonly window?: number;
19
+ } | false;
20
+ /** Submissions sent sooner than this after the form loaded are treated as bots. Default 2000 ms. */
21
+ readonly minSubmitTime?: number;
22
+ /** Cloudflare Turnstile, to check that visitors are people. Keys from the Cloudflare dashboard. */
23
+ readonly turnstile?: {
24
+ readonly siteKey: string;
25
+ readonly secretKey: string;
26
+ };
27
+ /** Delete submissions older than this many days. Default: keep them. */
28
+ readonly retentionDays?: number;
29
+ /** Slugs of the two collections. Default `forms` and `form-submissions`. */
30
+ readonly slugs?: {
31
+ readonly forms?: string;
32
+ readonly submissions?: string;
33
+ };
34
+ /** For tests: the `fetch` for Turnstile. */
35
+ readonly fetch?: typeof fetch;
36
+ }
37
+ /**
38
+ * Forms editors build in the admin from field blocks, with submissions, email notifications and
39
+ * spam protection. Pages render them with `<easy-form>` or the `getForm` / `submitForm` client.
40
+ */
41
+ declare function formBuilderPlugin(options?: FormBuilderOptions): Plugin;
42
+
43
+ export { FieldKind, type FormBuilderOptions, formBuilderPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,753 @@
1
+ import {
2
+ FIELD_KINDS
3
+ } from "./chunk-7TOHDI4J.js";
4
+
5
+ // src/plugin.ts
6
+ import { readFile } from "fs/promises";
7
+ import {
8
+ resolveAdminModule
9
+ } from "@easy-cms/core";
10
+ import { renderRichText as renderRichText2 } from "@easy-cms/richtext";
11
+
12
+ // src/emails.ts
13
+ import { escapeHtml, renderRichText, richTextToPlainText } from "@easy-cms/richtext";
14
+ var SHORT = [
15
+ "text",
16
+ "email",
17
+ "phone",
18
+ "select",
19
+ "number",
20
+ "date",
21
+ "checkbox"
22
+ ];
23
+ var SHORT_LENGTH = 100;
24
+ var PLACEHOLDER = /\{\{\s*([A-Za-z][A-Za-z0-9_]*|\*)\s*\}\}/g;
25
+ function buildEmails(context) {
26
+ const { form, fields, values, locale } = context;
27
+ const rows = Array.isArray(form.emails) ? form.emails : [];
28
+ const kindOf = new Map(fields.map((f) => [String(f.name ?? ""), f.blockType]));
29
+ const out = [];
30
+ for (const row of rows) {
31
+ let toSubmitter = false;
32
+ const recipients = [];
33
+ for (const part of splitList(row.to)) {
34
+ const field = /^\{\{\s*([A-Za-z][A-Za-z0-9_]*)\s*\}\}$/.exec(part)?.[1];
35
+ if (field) {
36
+ const value = values[field];
37
+ if (kindOf.get(field) === "email" && typeof value === "string" && value) {
38
+ recipients.push(value);
39
+ toSubmitter = true;
40
+ }
41
+ } else if (part.includes("@")) recipients.push(part);
42
+ }
43
+ if (splitList(row.to).length === 0) recipients.push(...context.defaultTo);
44
+ if (recipients.length === 0) continue;
45
+ const fill = (template, html2) => template.replace(PLACEHOLDER, (_, name) => {
46
+ if (name === "*") return toSubmitter ? "" : table(fields, values, locale, html2);
47
+ const kind = kindOf.get(name);
48
+ if (!kind || toSubmitter && !SHORT.includes(kind)) return "";
49
+ let text2 = display(values[name], locale);
50
+ if (toSubmitter) text2 = text2.slice(0, SHORT_LENGTH);
51
+ return html2 ? escapeHtml(text2) : text2;
52
+ });
53
+ const title = String(form.title ?? "");
54
+ const subjectTemplate = typeof row.subject === "string" && row.subject.trim() ? row.subject : locale === "th" ? `\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E43\u0E2B\u0E21\u0E48\u0E08\u0E32\u0E01\u0E1F\u0E2D\u0E23\u0E4C\u0E21: ${title}` : `New submission: ${title}`;
55
+ const subject = fill(subjectTemplate, false).replace(/[\r\n]+/g, " ").trim();
56
+ const message2 = row.message;
57
+ const hasMessage = richTextToPlainText(message2 ?? null).trim() !== "";
58
+ const fallback = toSubmitter ? thanks(locale) : "{{*}}";
59
+ const html = hasMessage ? fill(renderRichText(message2), true) : toSubmitter ? `<p>${escapeHtml(fallback)}</p>` : fill(fallback, true);
60
+ const text = (hasMessage ? fill(richTextToPlainText(message2), false) : fill(fallback, false)).replace(/[ \t]+$/gm, "").trim();
61
+ const replyField = /^\{\{\s*([A-Za-z][A-Za-z0-9_]*)\s*\}\}$/.exec(
62
+ String(row.replyTo ?? "").trim()
63
+ )?.[1];
64
+ const replyTo = replyField ? kindOf.get(replyField) === "email" && typeof values[replyField] === "string" ? values[replyField] : void 0 : typeof row.replyTo === "string" && row.replyTo.includes("@") ? row.replyTo.trim() : void 0;
65
+ const from = typeof row.from === "string" && row.from.trim() ? row.from.trim() : context.defaultFrom;
66
+ const cc = splitList(row.cc).filter((a) => a.includes("@") && !a.includes("{{"));
67
+ const bcc = splitList(row.bcc).filter((a) => a.includes("@") && !a.includes("{{"));
68
+ out.push({
69
+ to: recipients,
70
+ ...cc.length ? { cc } : {},
71
+ ...bcc.length ? { bcc } : {},
72
+ ...from ? { from } : {},
73
+ ...replyTo ? { replyTo } : {},
74
+ subject,
75
+ html,
76
+ text
77
+ });
78
+ }
79
+ return out;
80
+ }
81
+ function splitList(value) {
82
+ return typeof value === "string" ? value.split(/[,;]/).map((s) => s.trim()).filter(Boolean) : [];
83
+ }
84
+ function display(value, locale) {
85
+ if (value === null || value === void 0) return "";
86
+ if (typeof value === "boolean")
87
+ return locale === "th" ? value ? "\u0E43\u0E0A\u0E48" : "\u0E44\u0E21\u0E48" : value ? "Yes" : "No";
88
+ if (Array.isArray(value)) return value.map(String).join(", ");
89
+ return String(value);
90
+ }
91
+ function table(fields, values, locale, html) {
92
+ const rows = fields.filter((f) => f.blockType !== "message" && typeof f.name === "string").map((f) => {
93
+ const label = typeof f.label === "string" && f.label || String(f.name);
94
+ return [label, display(values[String(f.name)], locale)];
95
+ });
96
+ if (!html) return rows.map(([label, value]) => `${label}: ${value}`).join("\n");
97
+ const cells = rows.map(
98
+ ([label, value]) => `<tr><th align="left" style="padding:4px 12px 4px 0;vertical-align:top">${escapeHtml(label)}</th><td style="padding:4px 0;white-space:pre-wrap">${escapeHtml(value)}</td></tr>`
99
+ ).join("");
100
+ return `<table cellpadding="0" cellspacing="0">${cells}</table>`;
101
+ }
102
+ var thanks = (locale) => locale === "th" ? "\u0E02\u0E2D\u0E1A\u0E04\u0E38\u0E13 \u0E40\u0E23\u0E32\u0E44\u0E14\u0E49\u0E23\u0E31\u0E1A\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E41\u0E25\u0E49\u0E27" : "Thank you, we received your submission.";
103
+
104
+ // src/fields.ts
105
+ var FIELD_NAME = /^[A-Za-z][A-Za-z0-9_]*$/;
106
+ function fieldBlocks(localized, kinds) {
107
+ const l = localized ? { localized: true } : {};
108
+ const name = {
109
+ name: "name",
110
+ type: "text",
111
+ required: true,
112
+ label: { en: "Name (in the data)", th: "\u0E0A\u0E37\u0E48\u0E2D (\u0E43\u0E19\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25)" },
113
+ validate: (value) => value === null || value === void 0 || FIELD_NAME.test(String(value)) ? true : "use letters, digits and _, starting with a letter"
114
+ };
115
+ const label = { name: "label", type: "text", label: { en: "Label", th: "\u0E1B\u0E49\u0E32\u0E22" }, ...l };
116
+ const required = {
117
+ name: "required",
118
+ type: "boolean",
119
+ label: { en: "Required", th: "\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E23\u0E2D\u0E01" }
120
+ };
121
+ const placeholder = {
122
+ name: "placeholder",
123
+ type: "text",
124
+ label: { en: "Placeholder", th: "\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E15\u0E31\u0E27\u0E2D\u0E22\u0E48\u0E32\u0E07" },
125
+ ...l
126
+ };
127
+ const width = {
128
+ name: "width",
129
+ type: "select",
130
+ options: ["full", "half"],
131
+ defaultValue: "full",
132
+ label: { en: "Width", th: "\u0E04\u0E27\u0E32\u0E21\u0E01\u0E27\u0E49\u0E32\u0E07" }
133
+ };
134
+ const defaultValue = {
135
+ name: "defaultValue",
136
+ type: "text",
137
+ label: { en: "Default value", th: "\u0E04\u0E48\u0E32\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19" }
138
+ };
139
+ const common = [name, label, required, placeholder, defaultValue, width];
140
+ const block = (slug, en, th, fields) => ({
141
+ slug,
142
+ labels: { singular: { en, th } },
143
+ fields
144
+ });
145
+ const all = [
146
+ block("text", "Text", "\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21", common),
147
+ block("textarea", "Long text", "\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E22\u0E32\u0E27", common),
148
+ block("email", "Email", "\u0E2D\u0E35\u0E40\u0E21\u0E25", common),
149
+ block("number", "Number", "\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02", [
150
+ ...common,
151
+ { name: "min", type: "number", label: { en: "Minimum", th: "\u0E15\u0E48\u0E33\u0E2A\u0E38\u0E14" } },
152
+ { name: "max", type: "number", label: { en: "Maximum", th: "\u0E2A\u0E39\u0E07\u0E2A\u0E38\u0E14" } }
153
+ ]),
154
+ block("phone", "Phone", "\u0E40\u0E1A\u0E2D\u0E23\u0E4C\u0E42\u0E17\u0E23", common),
155
+ block("select", "Choice", "\u0E15\u0E31\u0E27\u0E40\u0E25\u0E37\u0E2D\u0E01", [
156
+ name,
157
+ label,
158
+ required,
159
+ placeholder,
160
+ width,
161
+ {
162
+ name: "options",
163
+ type: "array",
164
+ label: { en: "Choices", th: "\u0E15\u0E31\u0E27\u0E40\u0E25\u0E37\u0E2D\u0E01" },
165
+ fields: [
166
+ { name: "label", type: "text", required: true, label: { en: "Label", th: "\u0E1B\u0E49\u0E32\u0E22" }, ...l },
167
+ { name: "value", type: "text", required: true, label: { en: "Value", th: "\u0E04\u0E48\u0E32" } }
168
+ ]
169
+ },
170
+ { name: "multiple", type: "boolean", label: { en: "Allow several", th: "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E44\u0E14\u0E49\u0E2B\u0E25\u0E32\u0E22\u0E02\u0E49\u0E2D" } },
171
+ {
172
+ name: "display",
173
+ type: "select",
174
+ options: ["dropdown", "radio"],
175
+ defaultValue: "dropdown",
176
+ label: { en: "Show as", th: "\u0E41\u0E2A\u0E14\u0E07\u0E40\u0E1B\u0E47\u0E19" }
177
+ }
178
+ ]),
179
+ block("checkbox", "Checkbox", "\u0E0A\u0E48\u0E2D\u0E07\u0E15\u0E34\u0E4A\u0E01", [
180
+ name,
181
+ label,
182
+ required,
183
+ { name: "checked", type: "boolean", label: { en: "Ticked at first", th: "\u0E15\u0E34\u0E4A\u0E01\u0E44\u0E27\u0E49\u0E01\u0E48\u0E2D\u0E19" } },
184
+ width
185
+ ]),
186
+ block("date", "Date", "\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48", [name, label, required, width]),
187
+ block("message", "Message", "\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E2D\u0E18\u0E34\u0E1A\u0E32\u0E22", [
188
+ { name: "content", type: "richText", label: { en: "Text", th: "\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21" }, ...l }
189
+ ])
190
+ ];
191
+ return all.filter((b) => kinds.includes(b.slug));
192
+ }
193
+
194
+ // src/spam.ts
195
+ import { createHmac, timingSafeEqual } from "crypto";
196
+ var MAX_AGE = 24 * 36e5;
197
+ var sign = (secret, value) => createHmac("sha256", secret).update(value).digest("base64url");
198
+ function formToken(secret, slug, now = Date.now()) {
199
+ return `${now}.${sign(secret, `easy-form:${slug}:${now}`)}`;
200
+ }
201
+ function checkToken(secret, slug, token, minTime, now = Date.now()) {
202
+ if (typeof token !== "string") return "invalid";
203
+ const [time, signature] = token.split(".");
204
+ const issued = Number(time);
205
+ if (!Number.isFinite(issued) || !signature) return "invalid";
206
+ const expected = Buffer.from(sign(secret, `easy-form:${slug}:${issued}`));
207
+ const given = Buffer.from(signature);
208
+ if (expected.length !== given.length || !timingSafeEqual(expected, given)) return "invalid";
209
+ if (now - issued < minTime) return "too-fast";
210
+ if (now - issued > MAX_AGE) return "expired";
211
+ return "ok";
212
+ }
213
+ function rateKeys(secret, ip, form, window, now = Date.now()) {
214
+ const bucket = Math.floor(now / (window * 1e3));
215
+ const key = (b) => sign(secret, `easy-form-rate:${ip}:${String(form)}:${b}`).slice(0, 32);
216
+ return { current: key(bucket), previous: key(bucket - 1) };
217
+ }
218
+ function honeypotName(names) {
219
+ return ["website", "homepage", "url_address"].find((n) => !names.includes(n)) ?? "hp_field";
220
+ }
221
+ async function verifyTurnstile(secretKey, response, ip, fetcher = fetch) {
222
+ if (typeof response !== "string" || !response) return false;
223
+ const body = new URLSearchParams({ secret: secretKey, response, ...ip ? { remoteip: ip } : {} });
224
+ try {
225
+ const result = await fetcher("https://challenges.cloudflare.com/turnstile/v0/siteverify", {
226
+ method: "POST",
227
+ body,
228
+ signal: AbortSignal.timeout(1e4)
229
+ });
230
+ return (await result.json()).success === true;
231
+ } catch {
232
+ return false;
233
+ }
234
+ }
235
+
236
+ // src/validate.ts
237
+ var MESSAGES = {
238
+ en: {
239
+ required: "is required",
240
+ email: "must be an email address",
241
+ number: "must be a number",
242
+ min: "must be at least {n}",
243
+ max: "must be at most {n}",
244
+ phone: "must be a phone number",
245
+ date: "must be a date",
246
+ option: "must be one of the choices",
247
+ tooLong: "is too long",
248
+ ticked: "must be ticked"
249
+ },
250
+ th: {
251
+ required: "\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E23\u0E2D\u0E01",
252
+ email: "\u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E47\u0E19\u0E2D\u0E35\u0E40\u0E21\u0E25",
253
+ number: "\u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E47\u0E19\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02",
254
+ min: "\u0E15\u0E49\u0E2D\u0E07\u0E44\u0E21\u0E48\u0E19\u0E49\u0E2D\u0E22\u0E01\u0E27\u0E48\u0E32 {n}",
255
+ max: "\u0E15\u0E49\u0E2D\u0E07\u0E44\u0E21\u0E48\u0E40\u0E01\u0E34\u0E19 {n}",
256
+ phone: "\u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E47\u0E19\u0E40\u0E1A\u0E2D\u0E23\u0E4C\u0E42\u0E17\u0E23",
257
+ date: "\u0E15\u0E49\u0E2D\u0E07\u0E40\u0E1B\u0E47\u0E19\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48",
258
+ option: "\u0E15\u0E49\u0E2D\u0E07\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E08\u0E32\u0E01\u0E15\u0E31\u0E27\u0E40\u0E25\u0E37\u0E2D\u0E01",
259
+ tooLong: "\u0E22\u0E32\u0E27\u0E40\u0E01\u0E34\u0E19\u0E44\u0E1B",
260
+ ticked: "\u0E15\u0E49\u0E2D\u0E07\u0E15\u0E34\u0E4A\u0E01"
261
+ }
262
+ };
263
+ var message = (locale, key, n) => (locale === "th" ? MESSAGES.th : MESSAGES.en)[key].replace("{n}", String(n ?? ""));
264
+ var EMAIL = /^[^\s@<>()[\],;:"]+@[^\s@<>()[\],;:"]+\.[^\s@<>()[\],;:"]+$/;
265
+ var PHONE = /^\+?[0-9 ()-]{6,20}$/;
266
+ var DATE = /^\d{4}-\d{2}-\d{2}$/;
267
+ var MAX_TEXT = 1e3;
268
+ var MAX_TEXTAREA = 1e4;
269
+ function validateSubmission(rows, data, locale) {
270
+ const values = {};
271
+ const errors = [];
272
+ for (const row of rows) {
273
+ const kind = row.blockType;
274
+ const name = typeof row.name === "string" ? row.name : "";
275
+ if (kind === "message" || !name) continue;
276
+ const fail = (key, n) => errors.push({ field: name, message: message(locale, key, n) });
277
+ const raw = data[name];
278
+ const required = row.required === true;
279
+ if (kind === "checkbox") {
280
+ const ticked = raw === true || raw === "true" || raw === "on";
281
+ if (required && !ticked) fail("ticked");
282
+ values[name] = ticked;
283
+ continue;
284
+ }
285
+ if (kind === "select" && row.multiple === true) {
286
+ const list = (Array.isArray(raw) ? raw : raw === void 0 || raw === "" ? [] : [raw]).map(
287
+ String
288
+ );
289
+ const allowed = optionValues(row);
290
+ if (required && list.length === 0) fail("required");
291
+ else if (list.some((v) => !allowed.includes(v))) fail("option");
292
+ else values[name] = list;
293
+ continue;
294
+ }
295
+ const text = raw === void 0 || raw === null ? "" : String(raw).trim();
296
+ if (text === "") {
297
+ if (required) fail("required");
298
+ else values[name] = null;
299
+ continue;
300
+ }
301
+ switch (kind) {
302
+ case "email":
303
+ if (!EMAIL.test(text) || text.length > 254) fail("email");
304
+ else values[name] = text;
305
+ break;
306
+ case "number": {
307
+ const n = Number(text);
308
+ if (!Number.isFinite(n)) fail("number");
309
+ else if (typeof row.min === "number" && n < row.min) fail("min", row.min);
310
+ else if (typeof row.max === "number" && n > row.max) fail("max", row.max);
311
+ else values[name] = n;
312
+ break;
313
+ }
314
+ case "phone":
315
+ if (!PHONE.test(text)) fail("phone");
316
+ else values[name] = text;
317
+ break;
318
+ case "date":
319
+ if (!DATE.test(text) || Number.isNaN(Date.parse(text))) fail("date");
320
+ else values[name] = text;
321
+ break;
322
+ case "select":
323
+ if (!optionValues(row).includes(text)) fail("option");
324
+ else values[name] = text;
325
+ break;
326
+ case "textarea":
327
+ if (text.length > MAX_TEXTAREA) fail("tooLong");
328
+ else values[name] = text;
329
+ break;
330
+ default:
331
+ if (text.length > MAX_TEXT) fail("tooLong");
332
+ else values[name] = text;
333
+ }
334
+ }
335
+ return { values, errors };
336
+ }
337
+ var optionValues = (row) => (Array.isArray(row.options) ? row.options : []).map((o) => String(o.value ?? ""));
338
+
339
+ // src/plugin.ts
340
+ var ADMIN_MODULE = "@easy-cms/plugin-form-builder/admin";
341
+ function formBuilderPlugin(options = {}) {
342
+ return (config) => {
343
+ const forms = options.slugs?.forms ?? "forms";
344
+ const submissions = options.slugs?.submissions ?? "form-submissions";
345
+ for (const slug of [forms, submissions])
346
+ if (config.collections?.some((c) => c.slug === slug))
347
+ throw new Error(`formBuilderPlugin: there is already a collection "${slug}"; set \`slugs\``);
348
+ const kinds = options.fields ?? FIELD_KINDS;
349
+ const localized = !!config.localization;
350
+ const l = localized ? { localized: true } : {};
351
+ const secret = config.secret;
352
+ const locales = config.localization?.locales ?? [];
353
+ const defaultLocale = config.localization?.defaultLocale ?? locales[0] ?? null;
354
+ const rate = options.rateLimit === false ? null : { max: 5, window: 600, ...options.rateLimit };
355
+ const minTime = options.minSubmitTime ?? 2e3;
356
+ const defaultTo = options.defaultTo === void 0 ? [] : typeof options.defaultTo === "string" ? [options.defaultTo] : [...options.defaultTo];
357
+ const loggedIn = ({ user }) => !!user;
358
+ const formFields = [
359
+ { name: "title", type: "text", required: true, label: { en: "Title", th: "\u0E0A\u0E37\u0E48\u0E2D\u0E1F\u0E2D\u0E23\u0E4C\u0E21" }, ...l },
360
+ { name: "slug", type: "slug", from: "title", label: { en: "Slug", th: "Slug" } },
361
+ {
362
+ name: "fields",
363
+ type: "blocks",
364
+ label: { en: "Fields", th: "\u0E0A\u0E48\u0E2D\u0E07\u0E01\u0E23\u0E2D\u0E01" },
365
+ blocks: fieldBlocks(localized, kinds),
366
+ validate: (rows) => {
367
+ const names = (Array.isArray(rows) ? rows : []).map((r) => r.name).filter((n) => typeof n === "string" && n !== "");
368
+ const twice = names.find((n, i) => names.indexOf(n) !== i);
369
+ return twice ? `each field needs its own name: "${twice}" is used twice` : true;
370
+ }
371
+ },
372
+ {
373
+ name: "submitLabel",
374
+ type: "text",
375
+ label: { en: "Submit button", th: "\u0E1B\u0E38\u0E48\u0E21\u0E2A\u0E48\u0E07" },
376
+ ...l
377
+ },
378
+ {
379
+ name: "confirmationType",
380
+ type: "select",
381
+ options: ["message", "redirect"],
382
+ defaultValue: "message",
383
+ label: { en: "After sending", th: "\u0E2B\u0E25\u0E31\u0E07\u0E2A\u0E48\u0E07" },
384
+ position: "sidebar"
385
+ },
386
+ {
387
+ name: "confirmationMessage",
388
+ type: "richText",
389
+ label: { en: "Confirmation message", th: "\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E2B\u0E25\u0E31\u0E07\u0E2A\u0E48\u0E07" },
390
+ ...l
391
+ },
392
+ {
393
+ name: "redirectUrl",
394
+ type: "text",
395
+ label: { en: "Redirect to", th: "\u0E44\u0E1B\u0E17\u0E35\u0E48\u0E2B\u0E19\u0E49\u0E32" },
396
+ validate: (value) => !value || /^(\/|https?:\/\/)/.test(String(value)) ? true : "must start with / or http(s)://"
397
+ },
398
+ {
399
+ name: "emails",
400
+ type: "array",
401
+ label: { en: "Emails", th: "\u0E2D\u0E35\u0E40\u0E21\u0E25\u0E41\u0E08\u0E49\u0E07\u0E40\u0E15\u0E37\u0E2D\u0E19" },
402
+ // Addresses stay with editors, never in the public API.
403
+ access: { read: loggedIn },
404
+ fields: [
405
+ {
406
+ name: "to",
407
+ type: "text",
408
+ label: {
409
+ en: "To (comma separated, or {{email}})",
410
+ th: "\u0E16\u0E36\u0E07 (\u0E04\u0E31\u0E48\u0E19\u0E14\u0E49\u0E27\u0E22\u0E08\u0E38\u0E25\u0E20\u0E32\u0E04 \u0E2B\u0E23\u0E37\u0E2D {{email}})"
411
+ }
412
+ },
413
+ { name: "cc", type: "text", label: { en: "Cc", th: "Cc" } },
414
+ { name: "bcc", type: "text", label: { en: "Bcc", th: "Bcc" } },
415
+ { name: "replyTo", type: "text", label: { en: "Reply to", th: "\u0E15\u0E2D\u0E1A\u0E01\u0E25\u0E31\u0E1A\u0E16\u0E36\u0E07" } },
416
+ { name: "from", type: "text", label: { en: "From", th: "\u0E08\u0E32\u0E01" } },
417
+ { name: "subject", type: "text", label: { en: "Subject", th: "\u0E2B\u0E31\u0E27\u0E40\u0E23\u0E37\u0E48\u0E2D\u0E07" }, ...l },
418
+ {
419
+ name: "message",
420
+ type: "richText",
421
+ label: {
422
+ en: "Message ({{name}}, {{*}} for all fields)",
423
+ th: "\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21 ({{name}}, {{*}} \u0E04\u0E37\u0E2D\u0E17\u0E38\u0E01\u0E0A\u0E48\u0E2D\u0E07)"
424
+ },
425
+ ...l
426
+ }
427
+ ]
428
+ }
429
+ ];
430
+ const formsCollection = {
431
+ slug: forms,
432
+ labels: { singular: { en: "Form", th: "\u0E1F\u0E2D\u0E23\u0E4C\u0E21" }, plural: { en: "Forms", th: "\u0E1F\u0E2D\u0E23\u0E4C\u0E21" } },
433
+ icon: "mail",
434
+ useAsTitle: "title",
435
+ drafts: true,
436
+ fields: formFields,
437
+ admin: {
438
+ sidebar: [
439
+ {
440
+ tag: "ecms-form-submissions",
441
+ props: {
442
+ submissions,
443
+ adminPath: `/${(config.admin?.path ?? "/admin").replace(/^\/+|\/+$/g, "")}`,
444
+ apiPath: (config.routes?.api ?? "/api/cms").replace(/\/+$/, "")
445
+ }
446
+ }
447
+ ]
448
+ }
449
+ };
450
+ const submissionsCollection = {
451
+ slug: submissions,
452
+ labels: {
453
+ singular: { en: "Form submission", th: "\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E2A\u0E48\u0E07\u0E08\u0E32\u0E01\u0E1F\u0E2D\u0E23\u0E4C\u0E21" },
454
+ plural: { en: "Form submissions", th: "\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E2A\u0E48\u0E07\u0E08\u0E32\u0E01\u0E1F\u0E2D\u0E23\u0E4C\u0E21" }
455
+ },
456
+ icon: "message-square",
457
+ useAsTitle: "summary",
458
+ // Only the form's public endpoint creates submissions, after validation and spam checks.
459
+ access: {
460
+ read: loggedIn,
461
+ create: () => false,
462
+ update: () => false,
463
+ delete: ({ user }) => user?.role === "admin"
464
+ },
465
+ fields: [
466
+ {
467
+ name: "form",
468
+ type: "relationship",
469
+ to: forms,
470
+ required: true,
471
+ label: { en: "Form", th: "\u0E1F\u0E2D\u0E23\u0E4C\u0E21" }
472
+ },
473
+ { name: "summary", type: "text", label: { en: "Summary", th: "\u0E2A\u0E23\u0E38\u0E1B" } },
474
+ { name: "data", type: "json", label: { en: "Data", th: "\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25" } },
475
+ { name: "locale", type: "text", label: { en: "Locale", th: "\u0E20\u0E32\u0E29\u0E32" }, position: "sidebar" },
476
+ { name: "page", type: "text", label: { en: "Page", th: "\u0E2B\u0E19\u0E49\u0E32" }, position: "sidebar" },
477
+ // A hash of the IP address and the time window, for rate limits; never shown.
478
+ {
479
+ name: "rateKey",
480
+ type: "text",
481
+ index: true,
482
+ access: { read: () => false, update: () => false }
483
+ }
484
+ ]
485
+ };
486
+ const findForm = async (cms, slug, locale) => {
487
+ const { docs } = await cms.find(forms, {
488
+ where: { slug: { equals: slug } },
489
+ limit: 1,
490
+ depth: 0,
491
+ ...locale ? { locale } : {}
492
+ });
493
+ return docs[0];
494
+ };
495
+ const localeOf = (value) => typeof value === "string" && locales.includes(value) ? value : defaultLocale;
496
+ const rowsOf = (form) => Array.isArray(form.fields) ? form.fields : [];
497
+ const namesOf = (form) => rowsOf(form).map((r) => String(r.name ?? ""));
498
+ const confirmationOf = (form, locale) => form.confirmationType === "redirect" && typeof form.redirectUrl === "string" && form.redirectUrl ? { type: "redirect", url: form.redirectUrl } : {
499
+ type: "message",
500
+ html: renderRichText2(form.confirmationMessage) || `<p>${locale === "th" ? "\u0E02\u0E2D\u0E1A\u0E04\u0E38\u0E13 \u0E2A\u0E48\u0E07\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E40\u0E23\u0E35\u0E22\u0E1A\u0E23\u0E49\u0E2D\u0E22\u0E41\u0E25\u0E49\u0E27" : "Thank you, your message was sent."}</p>`
501
+ };
502
+ const fail = (status, errors) => Response.json({ errors }, { status, headers: { "cache-control": "no-store" } });
503
+ const publicForm = (form, slug, locale) => ({
504
+ slug,
505
+ title: String(form.title ?? ""),
506
+ fields: rowsOf(form).map((row) => {
507
+ const kind = row.blockType;
508
+ const text = (v) => typeof v === "string" && v ? v : void 0;
509
+ const base = {
510
+ kind,
511
+ name: String(row.name ?? ""),
512
+ label: text(row.label) ?? String(row.name ?? ""),
513
+ required: row.required === true,
514
+ width: row.width === "half" ? "half" : "full"
515
+ };
516
+ switch (kind) {
517
+ case "message":
518
+ return {
519
+ ...base,
520
+ name: "",
521
+ label: "",
522
+ html: renderRichText2(row.content)
523
+ };
524
+ case "checkbox":
525
+ return { ...base, defaultValue: row.checked === true };
526
+ case "select":
527
+ return {
528
+ ...base,
529
+ ...text(row.placeholder) ? { placeholder: text(row.placeholder) } : {},
530
+ options: (Array.isArray(row.options) ? row.options : []).map((o) => ({
531
+ label: text(o.label) ?? String(o.value ?? ""),
532
+ value: String(o.value ?? "")
533
+ })),
534
+ multiple: row.multiple === true,
535
+ display: row.display === "radio" ? "radio" : "dropdown"
536
+ };
537
+ default:
538
+ return {
539
+ ...base,
540
+ ...text(row.placeholder) ? { placeholder: text(row.placeholder) } : {},
541
+ ...text(row.defaultValue) ? { defaultValue: text(row.defaultValue) } : {},
542
+ ...typeof row.min === "number" ? { min: row.min } : {},
543
+ ...typeof row.max === "number" ? { max: row.max } : {}
544
+ };
545
+ }
546
+ }),
547
+ submitLabel: String(form.submitLabel || (locale === "th" ? "\u0E2A\u0E48\u0E07" : "Send")),
548
+ token: formToken(secret, slug),
549
+ honeypot: honeypotName(namesOf(form)),
550
+ turnstile: options.turnstile?.siteKey ?? null,
551
+ locale
552
+ });
553
+ const getEndpoint = {
554
+ path: "/form/:slug",
555
+ method: "get",
556
+ handler: async ({ params, url, cms }) => {
557
+ const slug = params.slug;
558
+ const locale = localeOf(url.searchParams.get("locale"));
559
+ const form = await findForm(cms, slug, locale);
560
+ if (!form) return fail(404, [{ message: `No published form "${slug}"` }]);
561
+ return Response.json(publicForm(form, slug, locale), {
562
+ // The token is fresh on every request.
563
+ headers: { "cache-control": "no-store" }
564
+ });
565
+ }
566
+ };
567
+ const submitEndpoint = {
568
+ path: "/form/:slug/submit",
569
+ method: "post",
570
+ handler: async ({ params, json, ip, cms }) => {
571
+ const slug = params.slug;
572
+ const body = await json();
573
+ const locale = localeOf(body.locale);
574
+ const form = await findForm(cms, slug, locale);
575
+ if (!form) return fail(404, [{ message: `No published form "${slug}"` }]);
576
+ const confirmation = confirmationOf(form, locale);
577
+ const reload = locale === "th" ? "\u0E1F\u0E2D\u0E23\u0E4C\u0E21\u0E2B\u0E21\u0E14\u0E2D\u0E32\u0E22\u0E38 \u0E42\u0E1B\u0E23\u0E14\u0E42\u0E2B\u0E25\u0E14\u0E2B\u0E19\u0E49\u0E32\u0E43\u0E2B\u0E21\u0E48\u0E41\u0E25\u0E49\u0E27\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07" : "The form expired: reload the page and try again";
578
+ const honeypot = body[honeypotName(namesOf(form))];
579
+ if (typeof honeypot === "string" && honeypot.trim() !== "") return { confirmation };
580
+ const data = typeof body.data === "object" && body.data !== null ? body.data : {};
581
+ const { values, errors } = validateSubmission(rowsOf(form), data, locale);
582
+ if (errors.length > 0) return fail(400, errors);
583
+ const token = checkToken(secret, slug, body.token, minTime);
584
+ if (token === "too-fast") return { confirmation };
585
+ if (token !== "ok") return fail(400, [{ message: reload }]);
586
+ if (options.turnstile && !await verifyTurnstile(options.turnstile.secretKey, body.turnstile, ip, options.fetch))
587
+ return fail(400, [
588
+ {
589
+ message: locale === "th" ? "\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E27\u0E48\u0E32\u0E44\u0E21\u0E48\u0E43\u0E0A\u0E48\u0E1A\u0E2D\u0E17\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08 \u0E42\u0E1B\u0E23\u0E14\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07" : "Verification failed: try again"
590
+ }
591
+ ]);
592
+ let rateKey;
593
+ if (rate && ip) {
594
+ const keys = rateKeys(secret, ip, form.id, rate.window);
595
+ const since = new Date(Date.now() - rate.window * 1e3).toISOString();
596
+ const recent = await cms.count(submissions, {
597
+ where: {
598
+ and: [
599
+ { form: { equals: form.id } },
600
+ { rateKey: { in: [keys.current, keys.previous] } },
601
+ { createdAt: { gte: since } }
602
+ ]
603
+ }
604
+ });
605
+ if (recent >= rate.max)
606
+ return fail(429, [
607
+ {
608
+ message: locale === "th" ? "\u0E2A\u0E48\u0E07\u0E1A\u0E48\u0E2D\u0E22\u0E40\u0E01\u0E34\u0E19\u0E44\u0E1B \u0E42\u0E1B\u0E23\u0E14\u0E23\u0E2D\u0E2A\u0E31\u0E01\u0E04\u0E23\u0E39\u0E48\u0E41\u0E25\u0E49\u0E27\u0E25\u0E2D\u0E07\u0E43\u0E2B\u0E21\u0E48" : "Too many submissions: wait a few minutes and try again"
609
+ }
610
+ ]);
611
+ rateKey = keys.current;
612
+ }
613
+ const page = typeof body.page === "string" ? body.page.slice(0, 500) : null;
614
+ await cms.create(submissions, {
615
+ form: form.id,
616
+ data: values,
617
+ summary: summarize(rowsOf(form), values),
618
+ locale,
619
+ page,
620
+ ...rateKey ? { rateKey } : {}
621
+ });
622
+ for (const email of buildEmails({
623
+ form,
624
+ fields: rowsOf(form),
625
+ values,
626
+ locale,
627
+ defaultFrom: options.defaultFrom,
628
+ defaultTo
629
+ }))
630
+ await cms.sendEmail(email);
631
+ if (options.retentionDays) await removeOld(cms, submissions, options.retentionDays);
632
+ return { confirmation };
633
+ }
634
+ };
635
+ const csvEndpoint = {
636
+ path: "/form/:slug/submissions.csv",
637
+ method: "get",
638
+ handler: async ({ params, user, cms }) => {
639
+ const slug = params.slug;
640
+ if (!user) return fail(401, [{ message: "Log in to export submissions" }]);
641
+ const { docs } = await cms.find(forms, {
642
+ where: { slug: { equals: slug } },
643
+ limit: 1,
644
+ depth: 0,
645
+ draft: true,
646
+ overrideAccess: false,
647
+ user
648
+ });
649
+ const form = docs[0];
650
+ if (!form) return fail(404, [{ message: `No form "${slug}"` }]);
651
+ const rows = [];
652
+ for (let page = 1; ; page++) {
653
+ const result = await cms.find(submissions, {
654
+ where: { form: { equals: form.id } },
655
+ sort: "createdAt",
656
+ limit: 500,
657
+ page,
658
+ depth: 0,
659
+ overrideAccess: false,
660
+ user
661
+ });
662
+ rows.push(...result.docs);
663
+ if (!result.hasNextPage) break;
664
+ }
665
+ const names = namesOf(form).filter(Boolean);
666
+ for (const row of rows)
667
+ for (const key of Object.keys(row.data ?? {}))
668
+ if (!names.includes(key)) names.push(key);
669
+ const header = ["createdAt", "locale", "page", ...names];
670
+ const lines = [
671
+ header,
672
+ ...rows.map((row) => [
673
+ String(row.createdAt ?? ""),
674
+ String(row.locale ?? ""),
675
+ String(row.page ?? ""),
676
+ ...names.map((n) => cell(row.data?.[n]))
677
+ ])
678
+ ];
679
+ const csv = `${BOM}${lines.map((line) => line.map(csvField).join(",")).join("\r\n")}\r
680
+ `;
681
+ return new Response(csv, {
682
+ headers: {
683
+ "content-type": "text/csv; charset=utf-8",
684
+ "content-disposition": `attachment; filename="${slug.replace(/[^\w-]/g, "_")}-submissions.csv"`,
685
+ "cache-control": "no-store"
686
+ }
687
+ });
688
+ }
689
+ };
690
+ let element;
691
+ const elementEndpoint = {
692
+ path: "/form/element.js",
693
+ method: "get",
694
+ handler: async ({ cms }) => {
695
+ element ??= (async () => {
696
+ const file = resolveAdminModule("@easy-cms/plugin-form-builder/element", cms.cwd);
697
+ return file ? readFile(file, "utf8") : void 0;
698
+ })();
699
+ const code = await element;
700
+ if (!code) return fail(404, [{ message: "The <easy-form> element was not found" }]);
701
+ return new Response(code, {
702
+ headers: {
703
+ "content-type": "text/javascript; charset=utf-8",
704
+ "cache-control": "public, max-age=3600"
705
+ }
706
+ });
707
+ }
708
+ };
709
+ return {
710
+ ...config,
711
+ collections: [...config.collections ?? [], formsCollection, submissionsCollection],
712
+ admin: {
713
+ ...config.admin,
714
+ modules: [.../* @__PURE__ */ new Set([...config.admin?.modules ?? [], ADMIN_MODULE])]
715
+ },
716
+ endpoints: [
717
+ ...config.endpoints ?? [],
718
+ getEndpoint,
719
+ submitEndpoint,
720
+ csvEndpoint,
721
+ elementEndpoint
722
+ ]
723
+ };
724
+ };
725
+ }
726
+ function summarize(rows, values) {
727
+ const parts = rows.filter((r) => r.blockType !== "message" && typeof r.name === "string").map((r) => cell(values[r.name])).filter(Boolean);
728
+ const text = parts.slice(0, 3).join(" \xB7 ");
729
+ return text.length > 120 ? `${text.slice(0, 119)}\u2026` : text;
730
+ }
731
+ var BOM = String.fromCharCode(65279);
732
+ function cell(value) {
733
+ if (value === null || value === void 0) return "";
734
+ if (Array.isArray(value)) return value.map(String).join(", ");
735
+ return String(value);
736
+ }
737
+ function csvField(value) {
738
+ const safe = /^[=+\-@\t\r]/.test(value) ? `'${value}` : value;
739
+ return /[",\r\n]/.test(safe) ? `"${safe.replace(/"/g, '""')}"` : safe;
740
+ }
741
+ async function removeOld(cms, submissions, days) {
742
+ const before = new Date(Date.now() - days * 864e5).toISOString();
743
+ const { docs } = await cms.find(submissions, {
744
+ where: { createdAt: { lt: before } },
745
+ limit: 50,
746
+ depth: 0
747
+ });
748
+ for (const doc of docs) await cms.delete(submissions, doc.id);
749
+ }
750
+ export {
751
+ FIELD_KINDS,
752
+ formBuilderPlugin
753
+ };
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Types shared by the server plugin, the browser client and the `<easy-form>` element. This
3
+ * file must not import anything: it ends up in browser bundles.
4
+ */
5
+ declare const FIELD_KINDS: readonly ["text", "textarea", "email", "number", "phone", "select", "checkbox", "date", "message"];
6
+ type FieldKind = (typeof FIELD_KINDS)[number];
7
+ /** A field of a published form, as the public API sends it (labels in the requested locale). */
8
+ interface PublicField {
9
+ readonly kind: FieldKind;
10
+ /** The key in the submitted data. Empty for `message`. */
11
+ readonly name: string;
12
+ readonly label: string;
13
+ readonly required: boolean;
14
+ readonly placeholder?: string;
15
+ readonly defaultValue?: string | boolean;
16
+ readonly width: 'full' | 'half';
17
+ /** `select`: the choices. */
18
+ readonly options?: readonly {
19
+ readonly label: string;
20
+ readonly value: string;
21
+ }[];
22
+ /** `select`: several choices. */
23
+ readonly multiple?: boolean;
24
+ /** `select`: radio buttons (or checkboxes with `multiple`) instead of a dropdown. */
25
+ readonly display?: 'dropdown' | 'radio';
26
+ /** `number`. */
27
+ readonly min?: number;
28
+ readonly max?: number;
29
+ /** `message`: the text as HTML (escaped and safe). */
30
+ readonly html?: string;
31
+ }
32
+ /** A published form, as `GET <api>/form/:slug` returns it. */
33
+ interface PublicForm {
34
+ readonly slug: string;
35
+ readonly title: string;
36
+ readonly fields: readonly PublicField[];
37
+ readonly submitLabel: string;
38
+ /** Send it back with the submission: it proves the form was loaded a moment before. */
39
+ readonly token: string;
40
+ /** The name of the hidden field bots fill in; leave it empty. */
41
+ readonly honeypot: string;
42
+ /** Cloudflare Turnstile's site key, when the form needs it. */
43
+ readonly turnstile: string | null;
44
+ readonly locale: string | null;
45
+ }
46
+ /** What happens after a submission. */
47
+ type Confirmation = {
48
+ readonly type: 'message';
49
+ readonly html: string;
50
+ } | {
51
+ readonly type: 'redirect';
52
+ readonly url: string;
53
+ };
54
+ /** The body of `POST <api>/form/:slug/submit`. */
55
+ interface Submission {
56
+ readonly data: Readonly<Record<string, unknown>>;
57
+ readonly token: string;
58
+ /** The page the form is on, kept with the submission. */
59
+ readonly page?: string;
60
+ readonly locale?: string | null;
61
+ /** Cloudflare Turnstile's response token. */
62
+ readonly turnstile?: string;
63
+ /** The honeypot's value: must be empty. */
64
+ readonly [honeypot: string]: unknown;
65
+ }
66
+ type SubmitResult = {
67
+ readonly ok: true;
68
+ readonly confirmation: Confirmation;
69
+ } | {
70
+ readonly ok: false;
71
+ readonly status: number;
72
+ readonly errors: readonly {
73
+ readonly message: string;
74
+ readonly field?: string;
75
+ }[];
76
+ };
77
+
78
+ export { type Confirmation as C, type FieldKind as F, type PublicForm as P, type Submission as S, type SubmitResult as a, type PublicField as b, FIELD_KINDS as c };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@easy-cms/plugin-form-builder",
3
+ "version": "0.19.0",
4
+ "description": "Forms for Easy CMS: build forms in the admin, collect submissions, email notifications, spam protection and an <easy-form> element",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./client": {
14
+ "types": "./dist/client.d.ts",
15
+ "default": "./dist/client.js"
16
+ },
17
+ "./element": "./dist/element.js",
18
+ "./element.css": "./dist/element.css",
19
+ "./admin": "./dist/admin.js",
20
+ "./package.json": "./package.json"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "dependencies": {
26
+ "@easy-cms/richtext": "^0.19.0"
27
+ },
28
+ "peerDependencies": {
29
+ "@easy-cms/core": "^0.19.0"
30
+ },
31
+ "devDependencies": {
32
+ "happy-dom": "^20.14.5",
33
+ "@easy-cms/db-sqlite": "^0.19.0",
34
+ "@easy-cms/core": "^0.19.0"
35
+ },
36
+ "engines": {
37
+ "node": ">=22.12"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/maritonx/easy-cms.git",
45
+ "directory": "packages/plugin-form-builder"
46
+ },
47
+ "keywords": [
48
+ "easy-cms",
49
+ "easy-cms-plugin",
50
+ "forms",
51
+ "form-builder",
52
+ "contact-form"
53
+ ],
54
+ "scripts": {
55
+ "build": "tsup",
56
+ "typecheck": "tsc --noEmit",
57
+ "test": "vitest run"
58
+ }
59
+ }