voc-lib-js 1.0.16 → 1.0.17
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/main.d.mts +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.global.js +1 -1
- package/dist/main.js +1 -1
- package/dist/main.mjs +1 -1
- package/package.json +1 -1
package/dist/main.d.mts
CHANGED
|
@@ -41,7 +41,7 @@ type FormData = {
|
|
|
41
41
|
};
|
|
42
42
|
type SubmitConfig = {
|
|
43
43
|
api_endpoint: string;
|
|
44
|
-
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
44
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "get" | "post" | "put" | "patch" | "delete";
|
|
45
45
|
api_key?: string;
|
|
46
46
|
headers?: Record<string, string>;
|
|
47
47
|
additional_data?: Record<string, any> | FormData;
|
package/dist/main.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ type FormData = {
|
|
|
41
41
|
};
|
|
42
42
|
type SubmitConfig = {
|
|
43
43
|
api_endpoint: string;
|
|
44
|
-
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
44
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "get" | "post" | "put" | "patch" | "delete";
|
|
45
45
|
api_key?: string;
|
|
46
46
|
headers?: Record<string, string>;
|
|
47
47
|
additional_data?: Record<string, any> | FormData;
|
package/dist/main.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var VocLibJs=(()=>{var x=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var H=(p,
|
|
1
|
+
"use strict";var VocLibJs=(()=>{var x=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var H=(p,o)=>{for(var m in o)x(p,m,{get:o[m],enumerable:!0})},_=(p,o,m,d)=>{if(o&&typeof o=="object"||typeof o=="function")for(let h of M(o))!A.call(p,h)&&h!==m&&x(p,h,{get:()=>o[h],enumerable:!(d=S(o,h))||d.enumerable});return p};var R=p=>_(x({},"__esModule",{value:!0}),p);var D={};H(D,{FormsLib:()=>q,default:()=>N});function k(p,o=!0){let m=new FormData(p);if(o)return m;let d={};return m.forEach((h,u)=>{let a=(h instanceof File,h);Object.prototype.hasOwnProperty.call(d,u)?Array.isArray(d[u])?d[u].push(a):d[u]=[d[u],a]:d[u]=a}),d}async function C(p,o,m){console.log("Submitting form to endpoint:",o.api_endpoint);let d=o.api_endpoint,h=(o.method||"post").toLowerCase(),u={"Content-Type":"application/json",...o?.headers||{}};console.log("Form method:",h);let a=JSON.stringify(k(p,!1));fetch(d,{method:h,headers:u,...h!=="get"?{body:a}:{},credentials:o.credentials||"same-origin"}).then(async s=>await s.json().catch(()=>null)).then(s=>{console.log("asdfasdf"),m&&m(s,null)}).catch(s=>{console.log("asfdasdf"),m&&m(null,s)})}function T(p,o,m){let d=[];if(typeof p=="string"?d=Array.from(document.querySelectorAll(p)):d=[p],d.length===0)return null;function h(){let a=m?.style==="bootstrap",s=document.createElement("form");s.classList.add("voc-form"),a&&s.classList.add("needs-validation"),s.id=o.id;let y=document.createElement("h2");y.textContent=o.form_name,s.appendChild(y);function L(e,c){c&&(c.min_length!==void 0&&(e.minLength=c.min_length),c.max_length!==void 0&&(e.maxLength=c.max_length),c.regex&&(e instanceof HTMLInputElement?e.pattern=c.regex:e.dataset.pattern=c.regex))}function F(e){if(!e.key&&!e.label)return null;let c=o.default_values||{},v=e.name||e.key,r=v?c[v]:void 0,b=document.createElement("div");if(b.className="voc-form-group",a&&b.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),a&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),b.appendChild(t)}let g=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options)e.options.forEach((n,l)=>{let f=document.createElement("label");f.classList.add("voc-form-checkbox-label"),a&&f.classList.add("form-check"),f.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(f.style.width=e.width);let i=document.createElement("input");i.type="checkbox",i.classList.add("voc-form-checkbox"),a&&i.classList.add("form-check-input"),i.name=e.name||e.key||"",i.value=n.value,e.key&&(i.id=`voc-form-${e.key}-${l}`),e.required&&(i.required=!0),Array.isArray(r)?r.includes(n.value)&&(i.checked=!0):r!==void 0?r===n.value&&(i.checked=!0):e.default===n.value&&(i.checked=!0),f.appendChild(i),f.appendChild(document.createTextNode(n.label)),t.appendChild(f)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),a&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let l=document.createElement("input");l.type="checkbox",l.classList.add("voc-form-checkbox"),(e.key||e.name)&&(l.name=e.name||e.key,e.key&&(l.id=`voc-form-${e.key}`)),a&&l.classList.add("form-check-input"),e.required&&(l.required=!0),r!==void 0?l.checked=!!r:e.default&&(l.checked=!!e.default),n.appendChild(l),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}g=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),L(t,e.validation),g=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),a&&t.classList.add("form-select"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let l=document.createElement("option");l.value=n.value,l.textContent=n.label,Array.isArray(r)?r.includes(n.value)&&(l.selected=!0):r!==void 0?r===n.value&&(l.selected=!0):e.default===n.value&&(l.selected=!0),t.appendChild(l)}),e.width&&(t.style.width=e.width),g=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,l)=>{let f=document.createElement("label");f.classList.add("voc-form-radio-label"),a&&f.classList.add("form-check"),f.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(f.style.width=e.width);let i=document.createElement("input");i.type="radio",i.classList.add("voc-form-radio"),a&&i.classList.add("form-check-input"),i.name=e.name||e.key||"",i.value=n.value,e.key&&(i.id=`voc-form-${e.key}-${l}`),Array.isArray(r)?r.includes(n.value)&&(i.checked=!0):r!==void 0?r===n.value&&(i.checked=!0):e.default===n.value&&(i.checked=!0),f.appendChild(i),f.appendChild(document.createTextNode(n.label)),t.appendChild(f)}),g=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),a&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),g=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),L(t,e.validation),g=t;break}}if(g&&b.appendChild(g),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,b.appendChild(t)}return b}o.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let c=document.createElement("div");if(c.className="voc-form-group voc-form-row",a&&c.classList.add("mb-3"),e.label){let r=document.createElement("h3");r.className="voc-form-row-label",r.textContent=e.label,c.appendChild(r)}if(e.description){let r=document.createElement("p");r.className="voc-form-row-description",r.textContent=e.description,c.appendChild(r)}let v=document.createElement("div");v.className="voc-form-row-items "+(e.direction||"horizontal"),c.appendChild(v),e.items.forEach(r=>{let b=F(r);b&&v.appendChild(b)}),s.appendChild(c)}else{let c=F(e);c&&s.appendChild(c)}});let E=document.createElement("button");return E.type="submit",E.className="voc-form-submit",E.textContent="Submit",a&&E.classList.add("btn","btn-primary"),s.appendChild(E),s}let u=h();return d[0].appendChild(u),m&&m.submitConfig&&u.addEventListener("submit",a=>{a.preventDefault(),C(u,m.submitConfig,(s,y)=>{m?.onSubmitResult&&m.onSubmitResult(s,y)})}),{element:u,validate:()=>{let a=[];return u.querySelectorAll(":invalid").forEach(y=>{let L=y.validationMessage;a.push({element:y,message:L})}),a},getValues:()=>k(u),onSubmit:a=>{u.addEventListener("submit",s=>{s.preventDefault();let y=k(u);a(y,s)})}}}var w={renderForm:T};var q=w,N={FormsLib:w};return R(D);})();
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var x=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var H=(p,
|
|
1
|
+
"use strict";var x=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var H=(p,o)=>{for(var m in o)x(p,m,{get:o[m],enumerable:!0})},_=(p,o,m,d)=>{if(o&&typeof o=="object"||typeof o=="function")for(let h of M(o))!A.call(p,h)&&h!==m&&x(p,h,{get:()=>o[h],enumerable:!(d=S(o,h))||d.enumerable});return p};var R=p=>_(x({},"__esModule",{value:!0}),p);var D={};H(D,{FormsLib:()=>q,default:()=>N});module.exports=R(D);function k(p,o=!0){let m=new FormData(p);if(o)return m;let d={};return m.forEach((h,u)=>{let a=(h instanceof File,h);Object.prototype.hasOwnProperty.call(d,u)?Array.isArray(d[u])?d[u].push(a):d[u]=[d[u],a]:d[u]=a}),d}async function C(p,o,m){console.log("Submitting form to endpoint:",o.api_endpoint);let d=o.api_endpoint,h=(o.method||"post").toLowerCase(),u={"Content-Type":"application/json",...o?.headers||{}};console.log("Form method:",h);let a=JSON.stringify(k(p,!1));fetch(d,{method:h,headers:u,...h!=="get"?{body:a}:{},credentials:o.credentials||"same-origin"}).then(async s=>await s.json().catch(()=>null)).then(s=>{console.log("asdfasdf"),m&&m(s,null)}).catch(s=>{console.log("asfdasdf"),m&&m(null,s)})}function T(p,o,m){let d=[];if(typeof p=="string"?d=Array.from(document.querySelectorAll(p)):d=[p],d.length===0)return null;function h(){let a=m?.style==="bootstrap",s=document.createElement("form");s.classList.add("voc-form"),a&&s.classList.add("needs-validation"),s.id=o.id;let y=document.createElement("h2");y.textContent=o.form_name,s.appendChild(y);function L(e,c){c&&(c.min_length!==void 0&&(e.minLength=c.min_length),c.max_length!==void 0&&(e.maxLength=c.max_length),c.regex&&(e instanceof HTMLInputElement?e.pattern=c.regex:e.dataset.pattern=c.regex))}function F(e){if(!e.key&&!e.label)return null;let c=o.default_values||{},v=e.name||e.key,r=v?c[v]:void 0,b=document.createElement("div");if(b.className="voc-form-group",a&&b.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),a&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),b.appendChild(t)}let g=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options)e.options.forEach((n,l)=>{let f=document.createElement("label");f.classList.add("voc-form-checkbox-label"),a&&f.classList.add("form-check"),f.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(f.style.width=e.width);let i=document.createElement("input");i.type="checkbox",i.classList.add("voc-form-checkbox"),a&&i.classList.add("form-check-input"),i.name=e.name||e.key||"",i.value=n.value,e.key&&(i.id=`voc-form-${e.key}-${l}`),e.required&&(i.required=!0),Array.isArray(r)?r.includes(n.value)&&(i.checked=!0):r!==void 0?r===n.value&&(i.checked=!0):e.default===n.value&&(i.checked=!0),f.appendChild(i),f.appendChild(document.createTextNode(n.label)),t.appendChild(f)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),a&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let l=document.createElement("input");l.type="checkbox",l.classList.add("voc-form-checkbox"),(e.key||e.name)&&(l.name=e.name||e.key,e.key&&(l.id=`voc-form-${e.key}`)),a&&l.classList.add("form-check-input"),e.required&&(l.required=!0),r!==void 0?l.checked=!!r:e.default&&(l.checked=!!e.default),n.appendChild(l),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}g=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),L(t,e.validation),g=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),a&&t.classList.add("form-select"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let l=document.createElement("option");l.value=n.value,l.textContent=n.label,Array.isArray(r)?r.includes(n.value)&&(l.selected=!0):r!==void 0?r===n.value&&(l.selected=!0):e.default===n.value&&(l.selected=!0),t.appendChild(l)}),e.width&&(t.style.width=e.width),g=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,l)=>{let f=document.createElement("label");f.classList.add("voc-form-radio-label"),a&&f.classList.add("form-check"),f.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(f.style.width=e.width);let i=document.createElement("input");i.type="radio",i.classList.add("voc-form-radio"),a&&i.classList.add("form-check-input"),i.name=e.name||e.key||"",i.value=n.value,e.key&&(i.id=`voc-form-${e.key}-${l}`),Array.isArray(r)?r.includes(n.value)&&(i.checked=!0):r!==void 0?r===n.value&&(i.checked=!0):e.default===n.value&&(i.checked=!0),f.appendChild(i),f.appendChild(document.createTextNode(n.label)),t.appendChild(f)}),g=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),a&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),g=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),L(t,e.validation),g=t;break}}if(g&&b.appendChild(g),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,b.appendChild(t)}return b}o.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let c=document.createElement("div");if(c.className="voc-form-group voc-form-row",a&&c.classList.add("mb-3"),e.label){let r=document.createElement("h3");r.className="voc-form-row-label",r.textContent=e.label,c.appendChild(r)}if(e.description){let r=document.createElement("p");r.className="voc-form-row-description",r.textContent=e.description,c.appendChild(r)}let v=document.createElement("div");v.className="voc-form-row-items "+(e.direction||"horizontal"),c.appendChild(v),e.items.forEach(r=>{let b=F(r);b&&v.appendChild(b)}),s.appendChild(c)}else{let c=F(e);c&&s.appendChild(c)}});let E=document.createElement("button");return E.type="submit",E.className="voc-form-submit",E.textContent="Submit",a&&E.classList.add("btn","btn-primary"),s.appendChild(E),s}let u=h();return d[0].appendChild(u),m&&m.submitConfig&&u.addEventListener("submit",a=>{a.preventDefault(),C(u,m.submitConfig,(s,y)=>{m?.onSubmitResult&&m.onSubmitResult(s,y)})}),{element:u,validate:()=>{let a=[];return u.querySelectorAll(":invalid").forEach(y=>{let L=y.validationMessage;a.push({element:y,message:L})}),a},getValues:()=>k(u),onSubmit:a=>{u.addEventListener("submit",s=>{s.preventDefault();let y=k(u);a(y,s)})}}}var w={renderForm:T};var q=w,N={FormsLib:w};0&&(module.exports={FormsLib});
|
package/dist/main.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function k(
|
|
1
|
+
function k(g,p=!0){let d=new FormData(g);if(p)return d;let u={};return d.forEach((f,l)=>{let a=(f instanceof File,f);Object.prototype.hasOwnProperty.call(u,l)?Array.isArray(u[l])?u[l].push(a):u[l]=[u[l],a]:u[l]=a}),u}async function F(g,p,d){console.log("Submitting form to endpoint:",p.api_endpoint);let u=p.api_endpoint,f=(p.method||"post").toLowerCase(),l={"Content-Type":"application/json",...p?.headers||{}};console.log("Form method:",f);let a=JSON.stringify(k(g,!1));fetch(u,{method:f,headers:l,...f!=="get"?{body:a}:{},credentials:p.credentials||"same-origin"}).then(async i=>await i.json().catch(()=>null)).then(i=>{console.log("asdfasdf"),d&&d(i,null)}).catch(i=>{console.log("asfdasdf"),d&&d(null,i)})}function C(g,p,d){let u=[];if(typeof g=="string"?u=Array.from(document.querySelectorAll(g)):u=[g],u.length===0)return null;function f(){let a=d?.style==="bootstrap",i=document.createElement("form");i.classList.add("voc-form"),a&&i.classList.add("needs-validation"),i.id=p.id;let h=document.createElement("h2");h.textContent=p.form_name,i.appendChild(h);function L(e,s){s&&(s.min_length!==void 0&&(e.minLength=s.min_length),s.max_length!==void 0&&(e.maxLength=s.max_length),s.regex&&(e instanceof HTMLInputElement?e.pattern=s.regex:e.dataset.pattern=s.regex))}function w(e){if(!e.key&&!e.label)return null;let s=p.default_values||{},v=e.name||e.key,r=v?s[v]:void 0,y=document.createElement("div");if(y.className="voc-form-group",a&&y.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),a&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),y.appendChild(t)}let b=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options)e.options.forEach((n,c)=>{let m=document.createElement("label");m.classList.add("voc-form-checkbox-label"),a&&m.classList.add("form-check"),m.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(m.style.width=e.width);let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),a&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${c}`),e.required&&(o.required=!0),Array.isArray(r)?r.includes(n.value)&&(o.checked=!0):r!==void 0?r===n.value&&(o.checked=!0):e.default===n.value&&(o.checked=!0),m.appendChild(o),m.appendChild(document.createTextNode(n.label)),t.appendChild(m)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),a&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),(e.key||e.name)&&(c.name=e.name||e.key,e.key&&(c.id=`voc-form-${e.key}`)),a&&c.classList.add("form-check-input"),e.required&&(c.required=!0),r!==void 0?c.checked=!!r:e.default&&(c.checked=!!e.default),n.appendChild(c),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}b=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),L(t,e.validation),b=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),a&&t.classList.add("form-select"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let c=document.createElement("option");c.value=n.value,c.textContent=n.label,Array.isArray(r)?r.includes(n.value)&&(c.selected=!0):r!==void 0?r===n.value&&(c.selected=!0):e.default===n.value&&(c.selected=!0),t.appendChild(c)}),e.width&&(t.style.width=e.width),b=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,c)=>{let m=document.createElement("label");m.classList.add("voc-form-radio-label"),a&&m.classList.add("form-check"),m.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(m.style.width=e.width);let o=document.createElement("input");o.type="radio",o.classList.add("voc-form-radio"),a&&o.classList.add("form-check-input"),o.name=e.name||e.key||"",o.value=n.value,e.key&&(o.id=`voc-form-${e.key}-${c}`),Array.isArray(r)?r.includes(n.value)&&(o.checked=!0):r!==void 0?r===n.value&&(o.checked=!0):e.default===n.value&&(o.checked=!0),m.appendChild(o),m.appendChild(document.createTextNode(n.label)),t.appendChild(m)}),b=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),a&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),b=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),a&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),r!=null?t.value=String(r):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),L(t,e.validation),b=t;break}}if(b&&y.appendChild(b),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,y.appendChild(t)}return y}p.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let s=document.createElement("div");if(s.className="voc-form-group voc-form-row",a&&s.classList.add("mb-3"),e.label){let r=document.createElement("h3");r.className="voc-form-row-label",r.textContent=e.label,s.appendChild(r)}if(e.description){let r=document.createElement("p");r.className="voc-form-row-description",r.textContent=e.description,s.appendChild(r)}let v=document.createElement("div");v.className="voc-form-row-items "+(e.direction||"horizontal"),s.appendChild(v),e.items.forEach(r=>{let y=w(r);y&&v.appendChild(y)}),i.appendChild(s)}else{let s=w(e);s&&i.appendChild(s)}});let E=document.createElement("button");return E.type="submit",E.className="voc-form-submit",E.textContent="Submit",a&&E.classList.add("btn","btn-primary"),i.appendChild(E),i}let l=f();return u[0].appendChild(l),d&&d.submitConfig&&l.addEventListener("submit",a=>{a.preventDefault(),F(l,d.submitConfig,(i,h)=>{d?.onSubmitResult&&d.onSubmitResult(i,h)})}),{element:l,validate:()=>{let a=[];return l.querySelectorAll(":invalid").forEach(h=>{let L=h.validationMessage;a.push({element:h,message:L})}),a},getValues:()=>k(l),onSubmit:a=>{l.addEventListener("submit",i=>{i.preventDefault();let h=k(l);a(h,i)})}}}var x={renderForm:C};var D=x,B={FormsLib:x};export{D as FormsLib,B as default};
|