voc-lib-js 1.0.18 → 1.0.20

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.
@@ -1 +1 @@
1
- "use strict";var VocLibJs=(()=>{var w=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var M=(p,a)=>{for(var l in a)w(p,l,{get:a[l],enumerable:!0})},R=(p,a,l,d)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of _(a))!H.call(p,f)&&f!==l&&w(p,f,{get:()=>a[f],enumerable:!(d=A(a,f))||d.enumerable});return p};var q=p=>R(w({},"__esModule",{value:!0}),p);var $={};M($,{FormsLib:()=>N,default:()=>D});function L(p,a=!0){let l=new FormData(p);if(a)return l;let d={};return l.forEach((f,m)=>{let v=(f instanceof File,f);Object.prototype.hasOwnProperty.call(d,m)?Array.isArray(d[m])?d[m].push(v):d[m]=[d[m],v]:d[m]=v}),d}async function T(p,a,l){let d=a.url,f=a.method,m={"Content-Type":"application/json"};a?.api_token&&(m.Authorization=`Bearer ${a.api_token}`);let v=JSON.stringify(L(p,!1));try{fetch(d,{method:f,headers:m,...f!=="GET"?{body:v}:{}}).then(async r=>r.ok?r.json():r.json().then(u=>{throw new Error(u.message||"Failed to delete AI Route")})).then(r=>{l&&l(r,null)}).catch(r=>{l&&l(null,r)})}catch(r){l&&l(null,r)}}function S(p,a,l){let d=[];if(typeof p=="string"?d=Array.from(document.querySelectorAll(p)):d=[p],d.length===0)return null;function f(){let r=l?.style==="bootstrap",u=document.createElement("form");u.classList.add("voc-form"),r&&u.classList.add("needs-validation"),u.id=a.id;let y=document.createElement("h2");y.textContent=a.form_name,u.appendChild(y);function x(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 C(e){if(!e.key&&!e.label)return null;let s=a.default_values||{},E=e.name||e.key,o=E?s[E]:void 0,b=document.createElement("div");if(b.className="voc-form-group",r&&b.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),r&&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,c)=>{let h=document.createElement("label");h.classList.add("voc-form-checkbox-label"),r&&h.classList.add("form-check"),h.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(h.style.width=e.width);let i=document.createElement("input");i.type="checkbox",i.classList.add("voc-form-checkbox"),r&&i.classList.add("form-check-input"),i.name=e.name||e.key||"",i.value=n.value,e.key&&(i.id=`voc-form-${e.key}-${c}`),e.required&&(i.required=!0),Array.isArray(o)?o.includes(n.value)&&(i.checked=!0):o!==void 0?o===n.value&&(i.checked=!0):e.default===n.value&&(i.checked=!0),h.appendChild(i),h.appendChild(document.createTextNode(n.label)),t.appendChild(h)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),r&&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}`)),r&&c.classList.add("form-check-input"),e.required&&(c.required=!0),o!==void 0?c.checked=!!o:e.default&&(c.checked=!!e.default),n.appendChild(c),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"),r&&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),o!=null?t.value=String(o):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),x(t,e.validation),g=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),r&&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(o)?o.includes(n.value)&&(c.selected=!0):o!==void 0?o===n.value&&(c.selected=!0):e.default===n.value&&(c.selected=!0),t.appendChild(c)}),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,c)=>{let h=document.createElement("label");h.classList.add("voc-form-radio-label"),r&&h.classList.add("form-check"),h.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(h.style.width=e.width);let i=document.createElement("input");i.type="radio",i.classList.add("voc-form-radio"),r&&i.classList.add("form-check-input"),i.name=e.name||e.key||"",i.value=n.value,e.key&&(i.id=`voc-form-${e.key}-${c}`),Array.isArray(o)?o.includes(n.value)&&(i.checked=!0):o!==void 0?o===n.value&&(i.checked=!0):e.default===n.value&&(i.checked=!0),h.appendChild(i),h.appendChild(document.createTextNode(n.label)),t.appendChild(h)}),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"),r&&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"),r&&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),o!=null?t.value=String(o):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),x(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}a.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let s=document.createElement("div");if(s.className="voc-form-group voc-form-row",r&&s.classList.add("mb-3"),e.label){let o=document.createElement("h3");o.className="voc-form-row-label",o.textContent=e.label,s.appendChild(o)}if(e.description){let o=document.createElement("p");o.className="voc-form-row-description",o.textContent=e.description,s.appendChild(o)}let E=document.createElement("div");E.className="voc-form-row-items "+(e.direction||"horizontal"),s.appendChild(E),e.items.forEach(o=>{let b=C(o);b&&E.appendChild(b)}),u.appendChild(s)}else{let s=C(e);s&&u.appendChild(s)}});let k=document.createElement("button");return k.type="submit",k.className="voc-form-submit",k.textContent="Submit",r&&k.classList.add("btn","btn-primary"),u.appendChild(k),u}let m=f();d[0].appendChild(m);let v=a?.submit_config??l?.submitConfig??null;return v&&m.addEventListener("submit",r=>{r.preventDefault(),T(m,v,(u,y)=>{l?.onSubmitResult&&l.onSubmitResult(u,y)})}),{element:m,validate:()=>{let r=[];return m.querySelectorAll(":invalid").forEach(y=>{let x=y.validationMessage;r.push({element:y,message:x})}),r},getValues:()=>L(m),onSubmit:r=>{m.addEventListener("submit",u=>{u.preventDefault();let y=L(m);r(y,u)})}}}var F={renderForm:S};var N=F,D={FormsLib:F};return q($);})();
1
+ "use strict";var VocLibJs=(()=>{var w=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var M=(p,a)=>{for(var m in a)w(p,m,{get:a[m],enumerable:!0})},q=(p,a,m,d)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of A(a))!H.call(p,f)&&f!==m&&w(p,f,{get:()=>a[f],enumerable:!(d=_(a,f))||d.enumerable});return p};var R=p=>q(w({},"__esModule",{value:!0}),p);var $={};M($,{FormsLib:()=>D,default:()=>N});function L(p,a=!0){let m=new FormData(p);if(a)return m;let d={};return m.forEach((f,u)=>{let v=(f instanceof File,f);Object.prototype.hasOwnProperty.call(d,u)?Array.isArray(d[u])?d[u].push(v):d[u]=[d[u],v]:d[u]=v}),d}async function C(p,a,m){let d=a.url,f={"Content-Type":"application/json"};a?.api_token&&(f.Authorization=`Bearer ${a.api_token}`);let u={...L(p,!1),...a.additional_data},v=JSON.stringify(u),i={method:a.method,headers:{Authorization:`Bearer ${a.api_token}`,"Content-Type":"application/json",Accept:"application/json"},...a.method==="GET"?{}:{body:v}};try{fetch(d,i).then(o=>{let y=o.headers.get("content-type");if(!o.ok){let E=o.text();throw new Error(`HTTP ${o.status}: ${E}`)}return y&&y.includes("application/json")?o.json():o.text()}).then(o=>{m&&m(o,null)}).catch(o=>{m&&m(null,o)})}catch(o){m&&m(null,o)}}function S(p,a,m){let d=[];if(typeof p=="string"?d=Array.from(document.querySelectorAll(p)):d=[p],d.length===0)return null;function f(){let i=m?.style==="bootstrap",o=document.createElement("form");o.classList.add("voc-form"),i&&o.classList.add("needs-validation"),o.id=a.id;let y=document.createElement("h2");y.textContent=a.form_name,o.appendChild(y);function E(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 T(e){if(!e.key&&!e.label)return null;let c=a.default_values||{},k=e.name||e.key,r=k?c[k]:void 0,b=document.createElement("div");if(b.className="voc-form-group",i&&b.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),i&&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 h=document.createElement("label");h.classList.add("voc-form-checkbox-label"),i&&h.classList.add("form-check"),h.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(h.style.width=e.width);let s=document.createElement("input");s.type="checkbox",s.classList.add("voc-form-checkbox"),i&&s.classList.add("form-check-input"),s.name=e.name||e.key||"",s.value=n.value,e.key&&(s.id=`voc-form-${e.key}-${l}`),e.required&&(s.required=!0),Array.isArray(r)?r.includes(n.value)&&(s.checked=!0):r!==void 0?r===n.value&&(s.checked=!0):e.default===n.value&&(s.checked=!0),h.appendChild(s),h.appendChild(document.createTextNode(n.label)),t.appendChild(h)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),i&&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}`)),i&&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"),i&&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),E(t,e.validation),g=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),i&&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 h=document.createElement("label");h.classList.add("voc-form-radio-label"),i&&h.classList.add("form-check"),h.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(h.style.width=e.width);let s=document.createElement("input");s.type="radio",s.classList.add("voc-form-radio"),i&&s.classList.add("form-check-input"),s.name=e.name||e.key||"",s.value=n.value,e.key&&(s.id=`voc-form-${e.key}-${l}`),Array.isArray(r)?r.includes(n.value)&&(s.checked=!0):r!==void 0?r===n.value&&(s.checked=!0):e.default===n.value&&(s.checked=!0),h.appendChild(s),h.appendChild(document.createTextNode(n.label)),t.appendChild(h)}),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"),i&&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"),i&&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),E(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}a.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let c=document.createElement("div");if(c.className="voc-form-group voc-form-row",i&&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 k=document.createElement("div");k.className="voc-form-row-items "+(e.direction||"horizontal"),c.appendChild(k),e.items.forEach(r=>{let b=T(r);b&&k.appendChild(b)}),o.appendChild(c)}else{let c=T(e);c&&o.appendChild(c)}});let x=document.createElement("button");return x.type="submit",x.className="voc-form-submit",x.textContent="Submit",i&&x.classList.add("btn","btn-primary"),o.appendChild(x),o}let u=f();d[0].appendChild(u);let v=a?.submit_config??m?.submitConfig??null;return v&&u.addEventListener("submit",i=>{i.preventDefault(),C(u,v,(o,y)=>{m?.onSubmitResult&&m.onSubmitResult(o,y)})}),{element:u,validate:()=>{let i=[];return u.querySelectorAll(":invalid").forEach(y=>{let E=y.validationMessage;i.push({element:y,message:E})}),i},getValues:()=>L(u),onSubmit:i=>{u.addEventListener("submit",o=>{o.preventDefault();let y=L(u);i(y,o)})}}}var F={renderForm:S};var D=F,N={FormsLib:F};return R($);})();
package/dist/main.js CHANGED
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var M=(p,a)=>{for(var l in a)w(p,l,{get:a[l],enumerable:!0})},R=(p,a,l,d)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of _(a))!H.call(p,f)&&f!==l&&w(p,f,{get:()=>a[f],enumerable:!(d=A(a,f))||d.enumerable});return p};var q=p=>R(w({},"__esModule",{value:!0}),p);var $={};M($,{FormsLib:()=>N,default:()=>D});module.exports=q($);function L(p,a=!0){let l=new FormData(p);if(a)return l;let d={};return l.forEach((f,m)=>{let v=(f instanceof File,f);Object.prototype.hasOwnProperty.call(d,m)?Array.isArray(d[m])?d[m].push(v):d[m]=[d[m],v]:d[m]=v}),d}async function T(p,a,l){let d=a.url,f=a.method,m={"Content-Type":"application/json"};a?.api_token&&(m.Authorization=`Bearer ${a.api_token}`);let v=JSON.stringify(L(p,!1));try{fetch(d,{method:f,headers:m,...f!=="GET"?{body:v}:{}}).then(async r=>r.ok?r.json():r.json().then(u=>{throw new Error(u.message||"Failed to delete AI Route")})).then(r=>{l&&l(r,null)}).catch(r=>{l&&l(null,r)})}catch(r){l&&l(null,r)}}function S(p,a,l){let d=[];if(typeof p=="string"?d=Array.from(document.querySelectorAll(p)):d=[p],d.length===0)return null;function f(){let r=l?.style==="bootstrap",u=document.createElement("form");u.classList.add("voc-form"),r&&u.classList.add("needs-validation"),u.id=a.id;let y=document.createElement("h2");y.textContent=a.form_name,u.appendChild(y);function x(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 C(e){if(!e.key&&!e.label)return null;let s=a.default_values||{},E=e.name||e.key,o=E?s[E]:void 0,b=document.createElement("div");if(b.className="voc-form-group",r&&b.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),r&&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,c)=>{let h=document.createElement("label");h.classList.add("voc-form-checkbox-label"),r&&h.classList.add("form-check"),h.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(h.style.width=e.width);let i=document.createElement("input");i.type="checkbox",i.classList.add("voc-form-checkbox"),r&&i.classList.add("form-check-input"),i.name=e.name||e.key||"",i.value=n.value,e.key&&(i.id=`voc-form-${e.key}-${c}`),e.required&&(i.required=!0),Array.isArray(o)?o.includes(n.value)&&(i.checked=!0):o!==void 0?o===n.value&&(i.checked=!0):e.default===n.value&&(i.checked=!0),h.appendChild(i),h.appendChild(document.createTextNode(n.label)),t.appendChild(h)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),r&&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}`)),r&&c.classList.add("form-check-input"),e.required&&(c.required=!0),o!==void 0?c.checked=!!o:e.default&&(c.checked=!!e.default),n.appendChild(c),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"),r&&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),o!=null?t.value=String(o):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),x(t,e.validation),g=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),r&&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(o)?o.includes(n.value)&&(c.selected=!0):o!==void 0?o===n.value&&(c.selected=!0):e.default===n.value&&(c.selected=!0),t.appendChild(c)}),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,c)=>{let h=document.createElement("label");h.classList.add("voc-form-radio-label"),r&&h.classList.add("form-check"),h.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(h.style.width=e.width);let i=document.createElement("input");i.type="radio",i.classList.add("voc-form-radio"),r&&i.classList.add("form-check-input"),i.name=e.name||e.key||"",i.value=n.value,e.key&&(i.id=`voc-form-${e.key}-${c}`),Array.isArray(o)?o.includes(n.value)&&(i.checked=!0):o!==void 0?o===n.value&&(i.checked=!0):e.default===n.value&&(i.checked=!0),h.appendChild(i),h.appendChild(document.createTextNode(n.label)),t.appendChild(h)}),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"),r&&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"),r&&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),o!=null?t.value=String(o):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),x(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}a.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let s=document.createElement("div");if(s.className="voc-form-group voc-form-row",r&&s.classList.add("mb-3"),e.label){let o=document.createElement("h3");o.className="voc-form-row-label",o.textContent=e.label,s.appendChild(o)}if(e.description){let o=document.createElement("p");o.className="voc-form-row-description",o.textContent=e.description,s.appendChild(o)}let E=document.createElement("div");E.className="voc-form-row-items "+(e.direction||"horizontal"),s.appendChild(E),e.items.forEach(o=>{let b=C(o);b&&E.appendChild(b)}),u.appendChild(s)}else{let s=C(e);s&&u.appendChild(s)}});let k=document.createElement("button");return k.type="submit",k.className="voc-form-submit",k.textContent="Submit",r&&k.classList.add("btn","btn-primary"),u.appendChild(k),u}let m=f();d[0].appendChild(m);let v=a?.submit_config??l?.submitConfig??null;return v&&m.addEventListener("submit",r=>{r.preventDefault(),T(m,v,(u,y)=>{l?.onSubmitResult&&l.onSubmitResult(u,y)})}),{element:m,validate:()=>{let r=[];return m.querySelectorAll(":invalid").forEach(y=>{let x=y.validationMessage;r.push({element:y,message:x})}),r},getValues:()=>L(m),onSubmit:r=>{m.addEventListener("submit",u=>{u.preventDefault();let y=L(m);r(y,u)})}}}var F={renderForm:S};var N=F,D={FormsLib:F};0&&(module.exports={FormsLib});
1
+ "use strict";var w=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var M=(p,a)=>{for(var m in a)w(p,m,{get:a[m],enumerable:!0})},q=(p,a,m,d)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of A(a))!H.call(p,f)&&f!==m&&w(p,f,{get:()=>a[f],enumerable:!(d=_(a,f))||d.enumerable});return p};var R=p=>q(w({},"__esModule",{value:!0}),p);var $={};M($,{FormsLib:()=>D,default:()=>N});module.exports=R($);function L(p,a=!0){let m=new FormData(p);if(a)return m;let d={};return m.forEach((f,u)=>{let v=(f instanceof File,f);Object.prototype.hasOwnProperty.call(d,u)?Array.isArray(d[u])?d[u].push(v):d[u]=[d[u],v]:d[u]=v}),d}async function C(p,a,m){let d=a.url,f={"Content-Type":"application/json"};a?.api_token&&(f.Authorization=`Bearer ${a.api_token}`);let u={...L(p,!1),...a.additional_data},v=JSON.stringify(u),i={method:a.method,headers:{Authorization:`Bearer ${a.api_token}`,"Content-Type":"application/json",Accept:"application/json"},...a.method==="GET"?{}:{body:v}};try{fetch(d,i).then(o=>{let y=o.headers.get("content-type");if(!o.ok){let E=o.text();throw new Error(`HTTP ${o.status}: ${E}`)}return y&&y.includes("application/json")?o.json():o.text()}).then(o=>{m&&m(o,null)}).catch(o=>{m&&m(null,o)})}catch(o){m&&m(null,o)}}function S(p,a,m){let d=[];if(typeof p=="string"?d=Array.from(document.querySelectorAll(p)):d=[p],d.length===0)return null;function f(){let i=m?.style==="bootstrap",o=document.createElement("form");o.classList.add("voc-form"),i&&o.classList.add("needs-validation"),o.id=a.id;let y=document.createElement("h2");y.textContent=a.form_name,o.appendChild(y);function E(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 T(e){if(!e.key&&!e.label)return null;let c=a.default_values||{},k=e.name||e.key,r=k?c[k]:void 0,b=document.createElement("div");if(b.className="voc-form-group",i&&b.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),i&&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 h=document.createElement("label");h.classList.add("voc-form-checkbox-label"),i&&h.classList.add("form-check"),h.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(h.style.width=e.width);let s=document.createElement("input");s.type="checkbox",s.classList.add("voc-form-checkbox"),i&&s.classList.add("form-check-input"),s.name=e.name||e.key||"",s.value=n.value,e.key&&(s.id=`voc-form-${e.key}-${l}`),e.required&&(s.required=!0),Array.isArray(r)?r.includes(n.value)&&(s.checked=!0):r!==void 0?r===n.value&&(s.checked=!0):e.default===n.value&&(s.checked=!0),h.appendChild(s),h.appendChild(document.createTextNode(n.label)),t.appendChild(h)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),i&&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}`)),i&&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"),i&&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),E(t,e.validation),g=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),i&&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 h=document.createElement("label");h.classList.add("voc-form-radio-label"),i&&h.classList.add("form-check"),h.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(h.style.width=e.width);let s=document.createElement("input");s.type="radio",s.classList.add("voc-form-radio"),i&&s.classList.add("form-check-input"),s.name=e.name||e.key||"",s.value=n.value,e.key&&(s.id=`voc-form-${e.key}-${l}`),Array.isArray(r)?r.includes(n.value)&&(s.checked=!0):r!==void 0?r===n.value&&(s.checked=!0):e.default===n.value&&(s.checked=!0),h.appendChild(s),h.appendChild(document.createTextNode(n.label)),t.appendChild(h)}),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"),i&&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"),i&&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),E(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}a.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let c=document.createElement("div");if(c.className="voc-form-group voc-form-row",i&&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 k=document.createElement("div");k.className="voc-form-row-items "+(e.direction||"horizontal"),c.appendChild(k),e.items.forEach(r=>{let b=T(r);b&&k.appendChild(b)}),o.appendChild(c)}else{let c=T(e);c&&o.appendChild(c)}});let x=document.createElement("button");return x.type="submit",x.className="voc-form-submit",x.textContent="Submit",i&&x.classList.add("btn","btn-primary"),o.appendChild(x),o}let u=f();d[0].appendChild(u);let v=a?.submit_config??m?.submitConfig??null;return v&&u.addEventListener("submit",i=>{i.preventDefault(),C(u,v,(o,y)=>{m?.onSubmitResult&&m.onSubmitResult(o,y)})}),{element:u,validate:()=>{let i=[];return u.querySelectorAll(":invalid").forEach(y=>{let E=y.validationMessage;i.push({element:y,message:E})}),i},getValues:()=>L(u),onSubmit:i=>{u.addEventListener("submit",o=>{o.preventDefault();let y=L(u);i(y,o)})}}}var F={renderForm:S};var D=F,N={FormsLib:F};0&&(module.exports={FormsLib});
package/dist/main.mjs CHANGED
@@ -1 +1 @@
1
- function L(g,p=!0){let d=new FormData(g);if(p)return d;let u={};return d.forEach((y,c)=>{let b=(y instanceof File,y);Object.prototype.hasOwnProperty.call(u,c)?Array.isArray(u[c])?u[c].push(b):u[c]=[u[c],b]:u[c]=b}),u}async function C(g,p,d){let u=p.url,y=p.method,c={"Content-Type":"application/json"};p?.api_token&&(c.Authorization=`Bearer ${p.api_token}`);let b=JSON.stringify(L(g,!1));try{fetch(u,{method:y,headers:c,...y!=="GET"?{body:b}:{}}).then(async r=>r.ok?r.json():r.json().then(l=>{throw new Error(l.message||"Failed to delete AI Route")})).then(r=>{d&&d(r,null)}).catch(r=>{d&&d(null,r)})}catch(r){d&&d(null,r)}}function T(g,p,d){let u=[];if(typeof g=="string"?u=Array.from(document.querySelectorAll(g)):u=[g],u.length===0)return null;function y(){let r=d?.style==="bootstrap",l=document.createElement("form");l.classList.add("voc-form"),r&&l.classList.add("needs-validation"),l.id=p.id;let h=document.createElement("h2");h.textContent=p.form_name,l.appendChild(h);function x(e,i){i&&(i.min_length!==void 0&&(e.minLength=i.min_length),i.max_length!==void 0&&(e.maxLength=i.max_length),i.regex&&(e instanceof HTMLInputElement?e.pattern=i.regex:e.dataset.pattern=i.regex))}function F(e){if(!e.key&&!e.label)return null;let i=p.default_values||{},E=e.name||e.key,o=E?i[E]:void 0,f=document.createElement("div");if(f.className="voc-form-group",r&&f.classList.add("mb-3"),e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),r&&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?" *":""),f.appendChild(t)}let v=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,s)=>{let m=document.createElement("label");m.classList.add("voc-form-checkbox-label"),r&&m.classList.add("form-check"),m.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(m.style.width=e.width);let a=document.createElement("input");a.type="checkbox",a.classList.add("voc-form-checkbox"),r&&a.classList.add("form-check-input"),a.name=e.name||e.key||"",a.value=n.value,e.key&&(a.id=`voc-form-${e.key}-${s}`),e.required&&(a.required=!0),Array.isArray(o)?o.includes(n.value)&&(a.checked=!0):o!==void 0?o===n.value&&(a.checked=!0):e.default===n.value&&(a.checked=!0),m.appendChild(a),m.appendChild(document.createTextNode(n.label)),t.appendChild(m)});else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),r&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let s=document.createElement("input");s.type="checkbox",s.classList.add("voc-form-checkbox"),(e.key||e.name)&&(s.name=e.name||e.key,e.key&&(s.id=`voc-form-${e.key}`)),r&&s.classList.add("form-check-input"),e.required&&(s.required=!0),o!==void 0?s.checked=!!o:e.default&&(s.checked=!!e.default),n.appendChild(s),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}v=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),r&&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),o!=null?t.value=String(o):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),x(t,e.validation),v=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),r&&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 s=document.createElement("option");s.value=n.value,s.textContent=n.label,Array.isArray(o)?o.includes(n.value)&&(s.selected=!0):o!==void 0?o===n.value&&(s.selected=!0):e.default===n.value&&(s.selected=!0),t.appendChild(s)}),e.width&&(t.style.width=e.width),v=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,s)=>{let m=document.createElement("label");m.classList.add("voc-form-radio-label"),r&&m.classList.add("form-check"),m.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(m.style.width=e.width);let a=document.createElement("input");a.type="radio",a.classList.add("voc-form-radio"),r&&a.classList.add("form-check-input"),a.name=e.name||e.key||"",a.value=n.value,e.key&&(a.id=`voc-form-${e.key}-${s}`),Array.isArray(o)?o.includes(n.value)&&(a.checked=!0):o!==void 0?o===n.value&&(a.checked=!0):e.default===n.value&&(a.checked=!0),m.appendChild(a),m.appendChild(document.createTextNode(n.label)),t.appendChild(m)}),v=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"),r&&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),v=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),r&&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),o!=null?t.value=String(o):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),x(t,e.validation),v=t;break}}if(v&&f.appendChild(v),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,f.appendChild(t)}return f}p.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let i=document.createElement("div");if(i.className="voc-form-group voc-form-row",r&&i.classList.add("mb-3"),e.label){let o=document.createElement("h3");o.className="voc-form-row-label",o.textContent=e.label,i.appendChild(o)}if(e.description){let o=document.createElement("p");o.className="voc-form-row-description",o.textContent=e.description,i.appendChild(o)}let E=document.createElement("div");E.className="voc-form-row-items "+(e.direction||"horizontal"),i.appendChild(E),e.items.forEach(o=>{let f=F(o);f&&E.appendChild(f)}),l.appendChild(i)}else{let i=F(e);i&&l.appendChild(i)}});let k=document.createElement("button");return k.type="submit",k.className="voc-form-submit",k.textContent="Submit",r&&k.classList.add("btn","btn-primary"),l.appendChild(k),l}let c=y();u[0].appendChild(c);let b=p?.submit_config??d?.submitConfig??null;return b&&c.addEventListener("submit",r=>{r.preventDefault(),C(c,b,(l,h)=>{d?.onSubmitResult&&d.onSubmitResult(l,h)})}),{element:c,validate:()=>{let r=[];return c.querySelectorAll(":invalid").forEach(h=>{let x=h.validationMessage;r.push({element:h,message:x})}),r},getValues:()=>L(c),onSubmit:r=>{c.addEventListener("submit",l=>{l.preventDefault();let h=L(c);r(h,l)})}}}var w={renderForm:T};var $=w,B={FormsLib:w};export{$ as FormsLib,B as default};
1
+ function L(v,m=!0){let u=new FormData(v);if(m)return u;let p={};return u.forEach((g,l)=>{let y=(g instanceof File,g);Object.prototype.hasOwnProperty.call(p,l)?Array.isArray(p[l])?p[l].push(y):p[l]=[p[l],y]:p[l]=y}),p}async function T(v,m,u){let p=m.url,g={"Content-Type":"application/json"};m?.api_token&&(g.Authorization=`Bearer ${m.api_token}`);let l={...L(v,!1),...m.additional_data},y=JSON.stringify(l),a={method:m.method,headers:{Authorization:`Bearer ${m.api_token}`,"Content-Type":"application/json",Accept:"application/json"},...m.method==="GET"?{}:{body:y}};try{fetch(p,a).then(o=>{let h=o.headers.get("content-type");if(!o.ok){let E=o.text();throw new Error(`HTTP ${o.status}: ${E}`)}return h&&h.includes("application/json")?o.json():o.text()}).then(o=>{u&&u(o,null)}).catch(o=>{u&&u(null,o)})}catch(o){u&&u(null,o)}}function C(v,m,u){let p=[];if(typeof v=="string"?p=Array.from(document.querySelectorAll(v)):p=[v],p.length===0)return null;function g(){let a=u?.style==="bootstrap",o=document.createElement("form");o.classList.add("voc-form"),a&&o.classList.add("needs-validation"),o.id=m.id;let h=document.createElement("h2");h.textContent=m.form_name,o.appendChild(h);function E(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 F(e){if(!e.key&&!e.label)return null;let s=m.default_values||{},k=e.name||e.key,r=k?s[k]:void 0,f=document.createElement("div");if(f.className="voc-form-group",a&&f.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?" *":""),f.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 d=document.createElement("label");d.classList.add("voc-form-checkbox-label"),a&&d.classList.add("form-check"),d.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(d.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}-${c}`),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),d.appendChild(i),d.appendChild(document.createTextNode(n.label)),t.appendChild(d)});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),E(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 d=document.createElement("label");d.classList.add("voc-form-radio-label"),a&&d.classList.add("form-check"),d.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(d.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}-${c}`),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),d.appendChild(i),d.appendChild(document.createTextNode(n.label)),t.appendChild(d)}),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),E(t,e.validation),b=t;break}}if(b&&f.appendChild(b),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,f.appendChild(t)}return f}m.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 k=document.createElement("div");k.className="voc-form-row-items "+(e.direction||"horizontal"),s.appendChild(k),e.items.forEach(r=>{let f=F(r);f&&k.appendChild(f)}),o.appendChild(s)}else{let s=F(e);s&&o.appendChild(s)}});let x=document.createElement("button");return x.type="submit",x.className="voc-form-submit",x.textContent="Submit",a&&x.classList.add("btn","btn-primary"),o.appendChild(x),o}let l=g();p[0].appendChild(l);let y=m?.submit_config??u?.submitConfig??null;return y&&l.addEventListener("submit",a=>{a.preventDefault(),T(l,y,(o,h)=>{u?.onSubmitResult&&u.onSubmitResult(o,h)})}),{element:l,validate:()=>{let a=[];return l.querySelectorAll(":invalid").forEach(h=>{let E=h.validationMessage;a.push({element:h,message:E})}),a},getValues:()=>L(l),onSubmit:a=>{l.addEventListener("submit",o=>{o.preventDefault();let h=L(l);a(h,o)})}}}var w={renderForm:C};var $=w,B={FormsLib:w};export{$ as FormsLib,B as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "voc-lib-js",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "A JavaScript library for VocPhone",
5
5
  "main": "./dist/main.cjs",
6
6
  "module": "./dist/main.mjs",