@easy-cms/plugin-form-builder 0.26.0 → 0.27.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/dist/admin.js +86 -8
- package/dist/index.js +97 -2
- package/package.json +5 -5
package/dist/admin.js
CHANGED
|
@@ -1,4 +1,82 @@
|
|
|
1
|
-
var
|
|
1
|
+
var x={en:{range:"Period",days7:"Last 7 days",days30:"Last 30 days",total:"{n} submissions",totalOne:"1 submission",chart:"Submissions per day: {n} in total",day:"{date}: {n}",form:"Form",count:"Submissions",view:"View submissions",trend:"Per day",actions:"Actions",noForms:"No forms yet.",loading:"Loading\u2026",failed:"Couldn't load the numbers.",widgetTitle:"Form submissions",widgetNone:"None in the last 7 days.",overview:"Form overview"},th:{range:"\u0E0A\u0E48\u0E27\u0E07\u0E40\u0E27\u0E25\u0E32",days7:"7 \u0E27\u0E31\u0E19\u0E25\u0E48\u0E32\u0E2A\u0E38\u0E14",days30:"30 \u0E27\u0E31\u0E19\u0E25\u0E48\u0E32\u0E2A\u0E38\u0E14",total:"{n} \u0E23\u0E32\u0E22\u0E01\u0E32\u0E23",totalOne:"1 \u0E23\u0E32\u0E22\u0E01\u0E32\u0E23",chart:"\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E2A\u0E48\u0E07\u0E21\u0E32\u0E23\u0E32\u0E22\u0E27\u0E31\u0E19 \u0E23\u0E27\u0E21 {n} \u0E23\u0E32\u0E22\u0E01\u0E32\u0E23",day:"{date}: {n}",form:"\u0E1F\u0E2D\u0E23\u0E4C\u0E21",count:"\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E2A\u0E48\u0E07\u0E21\u0E32",view:"\u0E14\u0E39\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E2A\u0E48\u0E07\u0E21\u0E32",trend:"\u0E23\u0E32\u0E22\u0E27\u0E31\u0E19",actions:"\u0E01\u0E32\u0E23\u0E17\u0E33\u0E07\u0E32\u0E19",noForms:"\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35\u0E1F\u0E2D\u0E23\u0E4C\u0E21",loading:"\u0E01\u0E33\u0E25\u0E31\u0E07\u0E42\u0E2B\u0E25\u0E14\u2026",failed:"\u0E42\u0E2B\u0E25\u0E14\u0E15\u0E31\u0E27\u0E40\u0E25\u0E02\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08",widgetTitle:"\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E17\u0E35\u0E48\u0E2A\u0E48\u0E07\u0E08\u0E32\u0E01\u0E1F\u0E2D\u0E23\u0E4C\u0E21",widgetNone:"\u0E44\u0E21\u0E48\u0E21\u0E35\u0E43\u0E19 7 \u0E27\u0E31\u0E19\u0E25\u0E48\u0E32\u0E2A\u0E38\u0E14",overview:"\u0E20\u0E32\u0E1E\u0E23\u0E27\u0E21\u0E1F\u0E2D\u0E23\u0E4C\u0E21"}},o=i=>i.replace(/[&<>"']/g,t=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[t]),y=`
|
|
2
|
+
:host { display: block; font: inherit; color: var(--text); }
|
|
3
|
+
[hidden] { display: none !important; }
|
|
4
|
+
a { color: var(--accent-strong, var(--accent)); text-decoration: none; }
|
|
5
|
+
a:hover { text-decoration: underline; }
|
|
6
|
+
a:focus-visible, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
|
|
7
|
+
.muted { color: var(--text-muted); }
|
|
8
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
9
|
+
.bars { display: flex; align-items: flex-end; justify-content: space-between; gap: 3px; }
|
|
10
|
+
.bar { flex: 1; max-width: 3rem; min-height: 2px; border-radius: 3px 3px 0 0; background: var(--accent); }
|
|
11
|
+
.bar.zero { background: var(--border); }
|
|
12
|
+
.bars.big { height: 9rem; gap: 6px; }
|
|
13
|
+
.bars.big .bar { border-radius: 4px 4px 0 0; }
|
|
14
|
+
.bars.spark { width: 7rem; height: 1.5rem; gap: 2px; }
|
|
15
|
+
.bars.small { height: 2.5rem; margin-bottom: 0.6rem; gap: 4px; }
|
|
16
|
+
`,k=`
|
|
17
|
+
${y}
|
|
18
|
+
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }
|
|
19
|
+
.total { margin: 0; font-size: 1.5rem; font-weight: 600; }
|
|
20
|
+
.range { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm, 8px); overflow: hidden; }
|
|
21
|
+
.range button {
|
|
22
|
+
min-height: 2.1rem; padding: 0 0.8rem; border: 0; background: var(--surface); color: var(--text-muted);
|
|
23
|
+
font: inherit; font-size: 0.85rem; cursor: pointer;
|
|
24
|
+
}
|
|
25
|
+
.range button + button { border-left: 1px solid var(--border-strong); }
|
|
26
|
+
.range button[aria-pressed='true'] { background: var(--surface-2); color: var(--text); font-weight: 600; }
|
|
27
|
+
.card { padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius, 12px); background: var(--surface); }
|
|
28
|
+
.chart { margin-bottom: 1rem; }
|
|
29
|
+
.axis { display: flex; justify-content: space-between; margin-top: 0.35rem; font-size: 0.75rem; }
|
|
30
|
+
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
|
|
31
|
+
th { text-align: left; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em; }
|
|
32
|
+
th, td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
|
|
33
|
+
tr:last-child td { border-bottom: 0; }
|
|
34
|
+
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
|
|
35
|
+
.table { padding: 0; overflow-x: auto; }
|
|
36
|
+
`,E=`
|
|
37
|
+
${y}
|
|
38
|
+
h2 { margin: 0; font-size: 1rem; font-weight: 600; }
|
|
39
|
+
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.75rem; }
|
|
40
|
+
.total { margin: 0 0 0.6rem; font-size: 1.75rem; font-weight: 600; font-variant-numeric: tabular-nums; }
|
|
41
|
+
ol { list-style: none; margin: 0; padding: 0; }
|
|
42
|
+
li { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.4rem 0; border-top: 1px solid var(--border); font-size: 0.875rem; }
|
|
43
|
+
li span:last-child { font-variant-numeric: tabular-nums; color: var(--text-muted); }
|
|
44
|
+
p { margin: 0; font-size: 0.875rem; }
|
|
45
|
+
`,S=()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}};function g(i,t,e,s){let n=Math.max(1,...i),c=i.map((d,r)=>{let m=d===0?0:Math.max(4,Math.round(d/n*100)),p=t[r]?` title="${o(t[r]??"")}"`:"";return`<span class="bar${d===0?" zero":""}" style="height:${m}%"${p}></span>`}).join(""),a=s?`role="img" aria-label="${o(s)}"`:'aria-hidden="true"';return`<div class="bars ${e}" ${a}>${c}</div>`}var u=class extends HTMLElement{props={};stats=null;failed=!1;#t="";constructor(){super(),this.attachShadow({mode:"open"})}connectedCallback(){this.update()}get settings(){return this.props.options??{}}get uiLang(){return this.props.uiLocale==="th"?"th":"en"}t(t,e={}){return x[this.uiLang][t].replace(/\{(\w+)\}/g,(s,n)=>String(e[n]??""))}number(t){return new Intl.NumberFormat(this.uiLang==="th"?"th-TH":"en-GB").format(t)}date(t){return new Intl.DateTimeFormat(this.uiLang==="th"?"th-TH":"en-GB",{day:"numeric",month:"short",timeZone:"UTC"}).format(new Date(`${t}T00:00:00Z`))}totalText(t){return t===1?this.t("totalOne"):this.t("total",{n:this.number(t)})}link(t,e,s=""){let n=`${this.settings.adminPath??"/admin"}${t}`;return`<a href="${o(n)}" data-to="${o(t)}" ${s}>${o(e)}</a>`}wireLinks(t){for(let e of t.querySelectorAll("a[data-to]"))e.addEventListener("click",s=>{s.metaKey||s.ctrlKey||s.shiftKey||s.altKey||s.button!==0||(s.preventDefault(),this.navigate(e.dataset.to??"/"))})}navigate(t){this.dispatchEvent(new CustomEvent("navigate",{detail:t}))}async load(t){let e=this.props.api,s=`${t}`;if(!(!e||s===this.#t)){this.#t=s;try{let n=await e("GET",`/form/stats.json?days=${t}&tz=${encodeURIComponent(S())}`);if(s!==this.#t)return;this.stats=n,this.failed=!1}catch{this.failed=!0}this.update()}}};for(let i of["options","uiLocale","api","route","user","apiVersion"])Object.defineProperty(u.prototype,i,{get(){return this.props[i]},set(t){this.props[i]=t,this.update()}});var f=class extends u{get#t(){return this.props.route?.query?.range==="30"?30:7}update(){let t=this.shadowRoot;if(!t)return;let e=this.#t,s=t.activeElement?.dataset?.days;this.load(e);let n=this.stats?.days===e?this.stats:null,{submissions:c}=this.settings,a=`
|
|
46
|
+
<div class="range" role="group" aria-label="${o(this.t("range"))}">
|
|
47
|
+
${[7,30].map(r=>`<button type="button" data-days="${r}" aria-pressed="${r===e}">${o(this.t(r===7?"days7":"days30"))}</button>`).join("")}
|
|
48
|
+
</div>`,d;if(this.failed)d=`<p class="muted">${o(this.t("failed"))}</p>`;else if(!n)d=`<p class="muted">${o(this.t("loading"))}</p>`;else if(n.forms.length===0)d=`<p class="muted">${o(this.t("noForms"))}</p>`;else{let r=n.dates.map((p,h)=>this.t("day",{date:this.date(p),n:this.number(n.perDay[h]??0)})),m=n.forms.map(p=>{let h=g(p.perDay,[],"spark");return`<tr>
|
|
49
|
+
<td>${o(p.title)}</td>
|
|
50
|
+
<td class="spark">${h}</td>
|
|
51
|
+
<td class="num">${o(this.number(p.total))}</td>
|
|
52
|
+
<td>${this.link(`/collections/${c}?f_form=${encodeURIComponent(String(p.id))}`,this.t("view"),`aria-label="${o(`${this.t("view")}: ${p.title}`)}"`)}</td>
|
|
53
|
+
</tr>`}).join("");d=`
|
|
54
|
+
<div class="card chart">
|
|
55
|
+
${g(n.perDay,r,"big",this.t("chart",{n:this.number(n.total)}))}
|
|
56
|
+
<div class="axis muted" aria-hidden="true"><span>${o(this.date(n.dates[0]??""))}</span><span>${o(this.date(n.dates.at(-1)??""))}</span></div>
|
|
57
|
+
</div>
|
|
58
|
+
<div class="card table">
|
|
59
|
+
<table>
|
|
60
|
+
<thead><tr><th scope="col">${o(this.t("form"))}</th><th scope="col"><span class="sr">${o(this.t("trend"))}</span></th><th scope="col" class="num">${o(this.t("count"))}</th><th scope="col"><span class="sr">${o(this.t("actions"))}</span></th></tr></thead>
|
|
61
|
+
<tbody>${m}</tbody>
|
|
62
|
+
</table>
|
|
63
|
+
</div>`}t.innerHTML=`<style>${k}</style>
|
|
64
|
+
<div class="toolbar">
|
|
65
|
+
<p class="total" aria-live="polite">${n?.forms.length?o(this.totalText(n.total)):""}</p>
|
|
66
|
+
${a}
|
|
67
|
+
</div>
|
|
68
|
+
${d}`;for(let r of t.querySelectorAll("button[data-days]"))r.addEventListener("click",()=>{let m=r.dataset.days==="30"?"30":"7";this.navigate(m==="30"?"/p/forms-overview?range=30":"/p/forms-overview")}),s&&r.dataset.days===s&&r.focus();this.wireLinks(t)}},b=class extends u{update(){let t=this.shadowRoot;if(!t)return;this.load(7);let e=this.stats,s;if(this.failed)s=`<p class="muted">${o(this.t("failed"))}</p>`;else if(!e)s=`<p class="muted">${o(this.t("loading"))}</p>`;else{let n=e.forms.filter(a=>a.total>0).slice(0,3),c=e.dates.map((a,d)=>this.t("day",{date:this.date(a),n:this.number(e.perDay[d]??0)}));s=`
|
|
69
|
+
<p class="total">${o(this.totalText(e.total))}</p>
|
|
70
|
+
${g(e.perDay,c,"small",this.t("chart",{n:this.number(e.total)}))}
|
|
71
|
+
${n.length?`<ol>${n.map(a=>`<li><span>${o(a.title)}</span><span>${o(this.number(a.total))}</span></li>`).join("")}</ol>`:`<p class="muted">${o(this.t("widgetNone"))}</p>`}`}t.innerHTML=`<style>${E}</style>
|
|
72
|
+
<section aria-labelledby="title">
|
|
73
|
+
<div class="head">
|
|
74
|
+
<h2 id="title">${o(this.t("widgetTitle"))}</h2>
|
|
75
|
+
<span class="muted">${o(this.t("days7"))}</span>
|
|
76
|
+
</div>
|
|
77
|
+
${s}
|
|
78
|
+
<p style="margin-top:0.75rem">${this.link("/p/forms-overview",`${this.t("overview")} \u2192`)}</p>
|
|
79
|
+
</section>`,this.wireLinks(t)}};function $(){customElements.get("ecms-forms-overview")||customElements.define("ecms-forms-overview",f),customElements.get("ecms-forms-widget")||customElements.define("ecms-forms-widget",b)}var w={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"}},l=i=>i.replace(/[&<>"']/g,t=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[t]),T=`
|
|
2
80
|
:host { display: block; font: inherit; color: var(--text); }
|
|
3
81
|
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
82
|
p { margin: 0 0 0.6rem; font-size: 0.875rem; }
|
|
@@ -12,12 +90,12 @@ var l={en:{title:"Submissions",count:"{n} received",none:"None yet",view:"View s
|
|
|
12
90
|
a.btn:hover { background: var(--surface-2); }
|
|
13
91
|
a.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
|
|
14
92
|
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
|
-
`,
|
|
16
|
-
<p>${
|
|
93
|
+
`,v=class i 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(i.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"?w.th:w.en)[t].replace("{n}",String(e??""))}async count(t,e){let s=this.props.api;if(!(!s||t===this.loadedFor)){this.loadedFor=t;try{let n=await s("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??{},s=this.props.id,n=this.props.doc??{},c=typeof n.slug=="string"?n.slug:"",a;if(s==null)a=`<p class="hint">${l(this.t("unsaved"))}</p>`;else{this.count(s,e);let d=`${e.adminPath}/collections/${e.submissions}?f_form=${encodeURIComponent(String(s))}`,r=`${e.apiPath}/form/${encodeURIComponent(c)}/submissions.csv`;a=`
|
|
94
|
+
<p>${l(this.total===null?"\u2026":this.total===0?this.t("none"):this.t("count",this.total))}</p>
|
|
17
95
|
<div class="actions">
|
|
18
|
-
<a class="btn" href="${
|
|
19
|
-
${
|
|
96
|
+
<a class="btn" href="${l(d)}">${l(this.t("view"))}</a>
|
|
97
|
+
${c?`<a class="btn" href="${l(r)}" download>${l(this.t("csv"))}</a>`:""}
|
|
20
98
|
</div>
|
|
21
|
-
${n.status==="draft"?`<p class="hint">${
|
|
22
|
-
${
|
|
23
|
-
`}t.innerHTML=`<style>${
|
|
99
|
+
${n.status==="draft"?`<p class="hint">${l(this.t("draft"))}</p>`:""}
|
|
100
|
+
${c?`<h3>${l(this.t("embed"))}</h3><code>${l(`<easy-form form="${c}"></easy-form>`)}</code>`:""}
|
|
101
|
+
`}t.innerHTML=`<style>${T}</style><section aria-label="${l(this.t("title"))}"><h3>${l(this.t("title"))}</h3>${a}</section>`}};customElements.get("ecms-form-submissions")||customElements.define("ecms-form-submissions",v);$();
|
package/dist/index.js
CHANGED
|
@@ -428,6 +428,7 @@ function formBuilderPlugin(options = {}) {
|
|
|
428
428
|
]
|
|
429
429
|
}
|
|
430
430
|
];
|
|
431
|
+
const adminPath = `/${(config.admin?.path ?? "/admin").replace(/^\/+|\/+$/g, "")}`;
|
|
431
432
|
const formsCollection = {
|
|
432
433
|
slug: forms,
|
|
433
434
|
labels: { singular: { en: "Form", th: "\u0E1F\u0E2D\u0E23\u0E4C\u0E21" }, plural: { en: "Forms", th: "\u0E1F\u0E2D\u0E23\u0E4C\u0E21" } },
|
|
@@ -441,7 +442,7 @@ function formBuilderPlugin(options = {}) {
|
|
|
441
442
|
tag: "ecms-form-submissions",
|
|
442
443
|
props: {
|
|
443
444
|
submissions,
|
|
444
|
-
adminPath
|
|
445
|
+
adminPath,
|
|
445
446
|
apiPath: (config.routes?.api ?? "/api/cms").replace(/\/+$/, "")
|
|
446
447
|
}
|
|
447
448
|
}
|
|
@@ -688,6 +689,77 @@ function formBuilderPlugin(options = {}) {
|
|
|
688
689
|
});
|
|
689
690
|
}
|
|
690
691
|
};
|
|
692
|
+
const statsEndpoint = {
|
|
693
|
+
path: "/form/stats.json",
|
|
694
|
+
method: "get",
|
|
695
|
+
handler: async ({ url, user, cms }) => {
|
|
696
|
+
if (!user) return fail(401, [{ message: "Log in to see form statistics" }]);
|
|
697
|
+
const days = url.searchParams.get("days") === "30" ? 30 : 7;
|
|
698
|
+
const timeZone = validTimeZone(url.searchParams.get("tz"));
|
|
699
|
+
const dayOf = new Intl.DateTimeFormat("en-CA", {
|
|
700
|
+
timeZone,
|
|
701
|
+
year: "numeric",
|
|
702
|
+
month: "2-digit",
|
|
703
|
+
day: "2-digit"
|
|
704
|
+
});
|
|
705
|
+
const now = Date.now();
|
|
706
|
+
const dates = Array.from(
|
|
707
|
+
{ length: days },
|
|
708
|
+
(_, i) => dayOf.format(new Date(now - (days - 1 - i) * 864e5))
|
|
709
|
+
);
|
|
710
|
+
const index = new Map(dates.map((d, i) => [d, i]));
|
|
711
|
+
const formRows = [];
|
|
712
|
+
for (let page = 1; ; page++) {
|
|
713
|
+
const result = await cms.find(forms, {
|
|
714
|
+
sort: "title",
|
|
715
|
+
limit: 100,
|
|
716
|
+
page,
|
|
717
|
+
depth: 0,
|
|
718
|
+
draft: true,
|
|
719
|
+
overrideAccess: false,
|
|
720
|
+
user
|
|
721
|
+
});
|
|
722
|
+
formRows.push(...result.docs);
|
|
723
|
+
if (!result.hasNextPage) break;
|
|
724
|
+
}
|
|
725
|
+
const counts = new Map(formRows.map((f) => [String(f.id), new Array(days).fill(0)]));
|
|
726
|
+
const since = new Date(now - (days + 1) * 864e5).toISOString();
|
|
727
|
+
for (let page = 1; ; page++) {
|
|
728
|
+
const result = await cms.find(submissions, {
|
|
729
|
+
where: { createdAt: { gte: since } },
|
|
730
|
+
limit: 500,
|
|
731
|
+
page,
|
|
732
|
+
depth: 0,
|
|
733
|
+
overrideAccess: false,
|
|
734
|
+
user
|
|
735
|
+
});
|
|
736
|
+
for (const row of result.docs) {
|
|
737
|
+
const perDay = counts.get(String(row.form));
|
|
738
|
+
const i = index.get(dayOf.format(new Date(String(row.createdAt))));
|
|
739
|
+
if (perDay && i !== void 0) perDay[i] = (perDay[i] ?? 0) + 1;
|
|
740
|
+
}
|
|
741
|
+
if (!result.hasNextPage) break;
|
|
742
|
+
}
|
|
743
|
+
const list = formRows.map((f) => {
|
|
744
|
+
const perDay = counts.get(String(f.id)) ?? [];
|
|
745
|
+
return {
|
|
746
|
+
id: f.id,
|
|
747
|
+
slug: String(f.slug ?? ""),
|
|
748
|
+
title: String(f.title ?? f.slug ?? f.id),
|
|
749
|
+
total: perDay.reduce((a, b) => a + b, 0),
|
|
750
|
+
perDay
|
|
751
|
+
};
|
|
752
|
+
}).sort((a, b) => b.total - a.total);
|
|
753
|
+
return {
|
|
754
|
+
days,
|
|
755
|
+
timeZone,
|
|
756
|
+
dates,
|
|
757
|
+
total: list.reduce((a, f) => a + f.total, 0),
|
|
758
|
+
perDay: dates.map((_, i) => list.reduce((a, f) => a + (f.perDay[i] ?? 0), 0)),
|
|
759
|
+
forms: list
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
};
|
|
691
763
|
let element;
|
|
692
764
|
const elementEndpoint = {
|
|
693
765
|
path: "/form/element.js",
|
|
@@ -712,13 +784,28 @@ function formBuilderPlugin(options = {}) {
|
|
|
712
784
|
collections: [...config.collections ?? [], formsCollection, submissionsCollection],
|
|
713
785
|
admin: {
|
|
714
786
|
...config.admin,
|
|
715
|
-
modules: [.../* @__PURE__ */ new Set([...config.admin?.modules ?? [], ADMIN_MODULE])]
|
|
787
|
+
modules: [.../* @__PURE__ */ new Set([...config.admin?.modules ?? [], ADMIN_MODULE])],
|
|
788
|
+
// Submissions at a glance: a page under Content and a dashboard panel.
|
|
789
|
+
pages: [
|
|
790
|
+
...config.admin?.pages ?? [],
|
|
791
|
+
{
|
|
792
|
+
path: "forms-overview",
|
|
793
|
+
label: { en: "Form overview", th: "\u0E20\u0E32\u0E1E\u0E23\u0E27\u0E21\u0E1F\u0E2D\u0E23\u0E4C\u0E21" },
|
|
794
|
+
icon: "chart-column",
|
|
795
|
+
component: { tag: "ecms-forms-overview", props: { forms, submissions, adminPath } }
|
|
796
|
+
}
|
|
797
|
+
],
|
|
798
|
+
dashboard: [
|
|
799
|
+
...config.admin?.dashboard ?? [],
|
|
800
|
+
{ component: { tag: "ecms-forms-widget", props: { forms, submissions, adminPath } } }
|
|
801
|
+
]
|
|
716
802
|
},
|
|
717
803
|
endpoints: [
|
|
718
804
|
...config.endpoints ?? [],
|
|
719
805
|
getEndpoint,
|
|
720
806
|
submitEndpoint,
|
|
721
807
|
csvEndpoint,
|
|
808
|
+
statsEndpoint,
|
|
722
809
|
elementEndpoint
|
|
723
810
|
]
|
|
724
811
|
};
|
|
@@ -729,6 +816,14 @@ function summarize(rows, values) {
|
|
|
729
816
|
const text = parts.slice(0, 3).join(" \xB7 ");
|
|
730
817
|
return text.length > 120 ? `${text.slice(0, 119)}\u2026` : text;
|
|
731
818
|
}
|
|
819
|
+
function validTimeZone(value) {
|
|
820
|
+
if (!value) return "UTC";
|
|
821
|
+
try {
|
|
822
|
+
return new Intl.DateTimeFormat("en-US", { timeZone: value }).resolvedOptions().timeZone;
|
|
823
|
+
} catch {
|
|
824
|
+
return "UTC";
|
|
825
|
+
}
|
|
826
|
+
}
|
|
732
827
|
var BOM = String.fromCharCode(65279);
|
|
733
828
|
function cell(value) {
|
|
734
829
|
if (value === null || value === void 0) return "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/plugin-form-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Forms for Easy CMS: build forms in the admin, collect submissions, email notifications, spam protection and an <easy-form> element",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@easy-cms/richtext": "^0.
|
|
26
|
+
"@easy-cms/richtext": "^0.27.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@easy-cms/core": "^0.
|
|
29
|
+
"@easy-cms/core": "^0.27.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"happy-dom": "^20.14.5",
|
|
33
|
-
"@easy-cms/core": "^0.
|
|
34
|
-
"@easy-cms/db-sqlite": "^0.
|
|
33
|
+
"@easy-cms/core": "^0.27.0",
|
|
34
|
+
"@easy-cms/db-sqlite": "^0.27.0"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=22.12"
|