voc-lib-js 1.0.21 → 1.0.22

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,2 +1,2 @@
1
- "use strict";var VocLibJs=(()=>{var w=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var $=(h,a)=>{for(var m in a)w(h,m,{get:a[m],enumerable:!0})},B=(h,a,m,d)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of D(a))!N.call(h,f)&&f!==m&&w(h,f,{get:()=>a[f],enumerable:!(d=q(a,f))||d.enumerable});return h};var V=h=>B(w({},"__esModule",{value:!0}),h);var O={};$(O,{FormsLib:()=>z,default:()=>P});function L(h,a=!0){let m=new FormData(h);if(a)return m;let d={};return m.forEach((f,u)=>{let g=(f instanceof File,f);Object.prototype.hasOwnProperty.call(d,u)?Array.isArray(d[u])?d[u].push(g):d[u]=[d[u],g]:d[u]=g}),d}async function M(h,a,m){let d=a.url,f={"Content-Type":"application/json"};a?.api_token&&(f.Authorization=`Bearer ${a.api_token}`);let u={...L(h,!1),...a.additional_data},g=JSON.stringify(u),i={method:a.method,headers:{Authorization:`Bearer ${a.api_token}`,"Content-Type":"application/json",Accept:"application/json"},...a.method==="GET"?{}:{body:g}};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(h,a,m){let d=[];if(typeof h=="string"?d=Array.from(document.querySelectorAll(h)):d=[h],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,l){l&&(l.min_length!==void 0&&(e.minLength=l.min_length),l.max_length!==void 0&&(e.maxLength=l.max_length),l.regex&&(e instanceof HTMLInputElement?e.pattern=l.regex:e.dataset.pattern=l.regex))}function C(e){if(!e.key&&!e.label)return null;let l=a.default_values||{},k=e.name||e.key,r=k?l[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 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,c)=>{let p=document.createElement("label");p.classList.add("voc-form-checkbox-label"),i&&p.classList.add("form-check"),p.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(p.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}-${c}`),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),p.appendChild(s),p.appendChild(document.createTextNode(n.label)),t.appendChild(p)});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 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}`)),i&&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)}v=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));let n=t.value||"";if(n){let c=(n.match(/\n/g)||[]).length,p=80,s=n.split(`
1
+ "use strict";var VocLibJs=(()=>{var w=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var $=(h,a)=>{for(var m in a)w(h,m,{get:a[m],enumerable:!0})},B=(h,a,m,d)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of D(a))!N.call(h,f)&&f!==m&&w(h,f,{get:()=>a[f],enumerable:!(d=q(a,f))||d.enumerable});return h};var V=h=>B(w({},"__esModule",{value:!0}),h);var O={};$(O,{FormsLib:()=>z,default:()=>P});function L(h,a=!0){let m=new FormData(h);if(a)return m;let d={};return m.forEach((f,u)=>{let g=(f instanceof File,f);Object.prototype.hasOwnProperty.call(d,u)?Array.isArray(d[u])?d[u].push(g):d[u]=[d[u],g]:d[u]=g}),d}async function M(h,a,m){let d=a.url,f={"Content-Type":"application/json"};a?.api_token&&(f.Authorization=`Bearer ${a.api_token}`);let u={...L(h,!1),...a.additional_data},g=JSON.stringify(u),i={method:a.method,headers:{Authorization:`Bearer ${a.api_token}`,"Content-Type":"application/json",Accept:"application/json"},...a.method==="GET"?{}:{body:g}};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(h,a,m){let d=[];if(typeof h=="string"?d=Array.from(document.querySelectorAll(h)):d=[h],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,l){l&&(l.min_length!==void 0&&(e.minLength=l.min_length),l.max_length!==void 0&&(e.maxLength=l.max_length),l.regex&&(e instanceof HTMLInputElement?e.pattern=l.regex:e.dataset.pattern=l.regex))}function C(e){if(!e.key&&!e.label)return null;let l=a.default_values||{},k=e.name||e.key,r=k?l[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 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,c)=>{let p=document.createElement("label");p.classList.add("voc-form-checkbox-label"),i&&p.classList.add("form-check"),p.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(p.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}-${c}`),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),p.appendChild(s),p.appendChild(document.createTextNode(n.label)),t.appendChild(p)});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 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}`)),i&&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)}v=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));let n=t.value||"";if(n&&(e.default||r)){let c=(n.match(/\n/g)||[]).length,p=80,s=n.split(`
2
2
  `).reduce((H,R)=>Math.max(H,R.length),0),_=Math.ceil(s/p)||1,A=Math.max(2,c+_),T=20;t.rows=Math.min(A,T),t.style.height=`${T*1.2}em`,t.style.resize="vertical"}e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),v=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 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),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,c)=>{let p=document.createElement("label");p.classList.add("voc-form-radio-label"),i&&p.classList.add("form-check"),p.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(p.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}-${c}`),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),p.appendChild(s),p.appendChild(document.createTextNode(n.label)),t.appendChild(p)}),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"),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),v=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),v=t;break}}if(v&&b.appendChild(v),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 l=document.createElement("div");if(l.className="voc-form-group voc-form-row",i&&l.classList.add("mb-3"),e.label){let r=document.createElement("h3");r.className="voc-form-row-label",r.textContent=e.label,l.appendChild(r)}if(e.description){let r=document.createElement("p");r.className="voc-form-row-description",r.textContent=e.description,l.appendChild(r)}let k=document.createElement("div");k.className="voc-form-row-items "+(e.direction||"horizontal"),l.appendChild(k),e.items.forEach(r=>{let b=C(r);b&&k.appendChild(b)}),o.appendChild(l)}else{let l=C(e);l&&o.appendChild(l)}});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 g=a?.submit_config??m?.submitConfig??null;return g&&u.addEventListener("submit",i=>{i.preventDefault(),M(u,g,(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 z=F,P={FormsLib:F};return V(O);})();
package/dist/main.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var w=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var $=(h,a)=>{for(var m in a)w(h,m,{get:a[m],enumerable:!0})},B=(h,a,m,d)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of D(a))!N.call(h,f)&&f!==m&&w(h,f,{get:()=>a[f],enumerable:!(d=q(a,f))||d.enumerable});return h};var V=h=>B(w({},"__esModule",{value:!0}),h);var O={};$(O,{FormsLib:()=>z,default:()=>P});module.exports=V(O);function L(h,a=!0){let m=new FormData(h);if(a)return m;let d={};return m.forEach((f,u)=>{let g=(f instanceof File,f);Object.prototype.hasOwnProperty.call(d,u)?Array.isArray(d[u])?d[u].push(g):d[u]=[d[u],g]:d[u]=g}),d}async function M(h,a,m){let d=a.url,f={"Content-Type":"application/json"};a?.api_token&&(f.Authorization=`Bearer ${a.api_token}`);let u={...L(h,!1),...a.additional_data},g=JSON.stringify(u),i={method:a.method,headers:{Authorization:`Bearer ${a.api_token}`,"Content-Type":"application/json",Accept:"application/json"},...a.method==="GET"?{}:{body:g}};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(h,a,m){let d=[];if(typeof h=="string"?d=Array.from(document.querySelectorAll(h)):d=[h],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,l){l&&(l.min_length!==void 0&&(e.minLength=l.min_length),l.max_length!==void 0&&(e.maxLength=l.max_length),l.regex&&(e instanceof HTMLInputElement?e.pattern=l.regex:e.dataset.pattern=l.regex))}function C(e){if(!e.key&&!e.label)return null;let l=a.default_values||{},k=e.name||e.key,r=k?l[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 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,c)=>{let p=document.createElement("label");p.classList.add("voc-form-checkbox-label"),i&&p.classList.add("form-check"),p.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(p.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}-${c}`),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),p.appendChild(s),p.appendChild(document.createTextNode(n.label)),t.appendChild(p)});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 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}`)),i&&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)}v=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));let n=t.value||"";if(n){let c=(n.match(/\n/g)||[]).length,p=80,s=n.split(`
1
+ "use strict";var w=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var $=(h,a)=>{for(var m in a)w(h,m,{get:a[m],enumerable:!0})},B=(h,a,m,d)=>{if(a&&typeof a=="object"||typeof a=="function")for(let f of D(a))!N.call(h,f)&&f!==m&&w(h,f,{get:()=>a[f],enumerable:!(d=q(a,f))||d.enumerable});return h};var V=h=>B(w({},"__esModule",{value:!0}),h);var O={};$(O,{FormsLib:()=>z,default:()=>P});module.exports=V(O);function L(h,a=!0){let m=new FormData(h);if(a)return m;let d={};return m.forEach((f,u)=>{let g=(f instanceof File,f);Object.prototype.hasOwnProperty.call(d,u)?Array.isArray(d[u])?d[u].push(g):d[u]=[d[u],g]:d[u]=g}),d}async function M(h,a,m){let d=a.url,f={"Content-Type":"application/json"};a?.api_token&&(f.Authorization=`Bearer ${a.api_token}`);let u={...L(h,!1),...a.additional_data},g=JSON.stringify(u),i={method:a.method,headers:{Authorization:`Bearer ${a.api_token}`,"Content-Type":"application/json",Accept:"application/json"},...a.method==="GET"?{}:{body:g}};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(h,a,m){let d=[];if(typeof h=="string"?d=Array.from(document.querySelectorAll(h)):d=[h],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,l){l&&(l.min_length!==void 0&&(e.minLength=l.min_length),l.max_length!==void 0&&(e.maxLength=l.max_length),l.regex&&(e instanceof HTMLInputElement?e.pattern=l.regex:e.dataset.pattern=l.regex))}function C(e){if(!e.key&&!e.label)return null;let l=a.default_values||{},k=e.name||e.key,r=k?l[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 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,c)=>{let p=document.createElement("label");p.classList.add("voc-form-checkbox-label"),i&&p.classList.add("form-check"),p.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(p.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}-${c}`),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),p.appendChild(s),p.appendChild(document.createTextNode(n.label)),t.appendChild(p)});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 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}`)),i&&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)}v=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));let n=t.value||"";if(n&&(e.default||r)){let c=(n.match(/\n/g)||[]).length,p=80,s=n.split(`
2
2
  `).reduce((H,R)=>Math.max(H,R.length),0),_=Math.ceil(s/p)||1,A=Math.max(2,c+_),T=20;t.rows=Math.min(A,T),t.style.height=`${T*1.2}em`,t.style.resize="vertical"}e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),v=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 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),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,c)=>{let p=document.createElement("label");p.classList.add("voc-form-radio-label"),i&&p.classList.add("form-check"),p.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(p.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}-${c}`),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),p.appendChild(s),p.appendChild(document.createTextNode(n.label)),t.appendChild(p)}),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"),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),v=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),v=t;break}}if(v&&b.appendChild(v),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 l=document.createElement("div");if(l.className="voc-form-group voc-form-row",i&&l.classList.add("mb-3"),e.label){let r=document.createElement("h3");r.className="voc-form-row-label",r.textContent=e.label,l.appendChild(r)}if(e.description){let r=document.createElement("p");r.className="voc-form-row-description",r.textContent=e.description,l.appendChild(r)}let k=document.createElement("div");k.className="voc-form-row-items "+(e.direction||"horizontal"),l.appendChild(k),e.items.forEach(r=>{let b=C(r);b&&k.appendChild(b)}),o.appendChild(l)}else{let l=C(e);l&&o.appendChild(l)}});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 g=a?.submit_config??m?.submitConfig??null;return g&&u.addEventListener("submit",i=>{i.preventDefault(),M(u,g,(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 z=F,P={FormsLib:F};0&&(module.exports={FormsLib});
package/dist/main.mjs CHANGED
@@ -1,2 +1,2 @@
1
- function L(g,d=!0){let u=new FormData(g);if(d)return u;let p={};return u.forEach((v,l)=>{let y=(v instanceof File,v);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(g,d,u){let p=d.url,v={"Content-Type":"application/json"};d?.api_token&&(v.Authorization=`Bearer ${d.api_token}`);let l={...L(g,!1),...d.additional_data},y=JSON.stringify(l),a={method:d.method,headers:{Authorization:`Bearer ${d.api_token}`,"Content-Type":"application/json",Accept:"application/json"},...d.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 M(g,d,u){let p=[];if(typeof g=="string"?p=Array.from(document.querySelectorAll(g)):p=[g],p.length===0)return null;function v(){let a=u?.style==="bootstrap",o=document.createElement("form");o.classList.add("voc-form"),a&&o.classList.add("needs-validation"),o.id=d.id;let h=document.createElement("h2");h.textContent=d.form_name,o.appendChild(h);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 F(e){if(!e.key&&!e.label)return null;let c=d.default_values||{},k=e.name||e.key,r=k?c[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,s)=>{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 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}-${s}`),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),m.appendChild(i),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 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}`)),a&&s.classList.add("form-check-input"),e.required&&(s.required=!0),r!==void 0?s.checked=!!r:e.default&&(s.checked=!!e.default),n.appendChild(s),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));let n=t.value||"";if(n){let s=(n.match(/\n/g)||[]).length,m=80,i=n.split(`
1
+ function L(g,d=!0){let u=new FormData(g);if(d)return u;let p={};return u.forEach((v,l)=>{let y=(v instanceof File,v);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(g,d,u){let p=d.url,v={"Content-Type":"application/json"};d?.api_token&&(v.Authorization=`Bearer ${d.api_token}`);let l={...L(g,!1),...d.additional_data},y=JSON.stringify(l),a={method:d.method,headers:{Authorization:`Bearer ${d.api_token}`,"Content-Type":"application/json",Accept:"application/json"},...d.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 M(g,d,u){let p=[];if(typeof g=="string"?p=Array.from(document.querySelectorAll(g)):p=[g],p.length===0)return null;function v(){let a=u?.style==="bootstrap",o=document.createElement("form");o.classList.add("voc-form"),a&&o.classList.add("needs-validation"),o.id=d.id;let h=document.createElement("h2");h.textContent=d.form_name,o.appendChild(h);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 F(e){if(!e.key&&!e.label)return null;let c=d.default_values||{},k=e.name||e.key,r=k?c[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,s)=>{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 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}-${s}`),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),m.appendChild(i),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 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}`)),a&&s.classList.add("form-check-input"),e.required&&(s.required=!0),r!==void 0?s.checked=!!r:e.default&&(s.checked=!!e.default),n.appendChild(s),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));let n=t.value||"";if(n&&(e.default||r)){let s=(n.match(/\n/g)||[]).length,m=80,i=n.split(`
2
2
  `).reduce((A,H)=>Math.max(A,H.length),0),S=Math.ceil(i/m)||1,_=Math.max(2,s+S),C=20;t.rows=Math.min(_,C),t.style.height=`${C*1.2}em`,t.style.resize="vertical"}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 s=document.createElement("option");s.value=n.value,s.textContent=n.label,Array.isArray(r)?r.includes(n.value)&&(s.selected=!0):r!==void 0?r===n.value&&(s.selected=!0):e.default===n.value&&(s.selected=!0),t.appendChild(s)}),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,s)=>{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 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}-${s}`),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),m.appendChild(i),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),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}d.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 k=document.createElement("div");k.className="voc-form-row-items "+(e.direction||"horizontal"),c.appendChild(k),e.items.forEach(r=>{let f=F(r);f&&k.appendChild(f)}),o.appendChild(c)}else{let c=F(e);c&&o.appendChild(c)}});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=v();p[0].appendChild(l);let y=d?.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:M};var O=w,j={FormsLib:w};export{O as FormsLib,j as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "voc-lib-js",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "A JavaScript library for VocPhone",
5
5
  "main": "./dist/main.cjs",
6
6
  "module": "./dist/main.mjs",