voc-lib-js 1.0.8 → 1.0.10
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/README.md +93 -5
- package/dist/main.d.mts +14 -3
- package/dist/main.d.ts +14 -3
- package/dist/main.global.js +1 -1
- package/dist/main.js +1 -1
- package/dist/main.mjs +1 -1
- package/package.json +5 -5
- package/src/css/portal.scss +0 -0
package/README.md
CHANGED
|
@@ -1,19 +1,107 @@
|
|
|
1
1
|
# Vocphone JavaScript Library
|
|
2
|
+
|
|
2
3
|
This is a JavaScript library for [VocPhone](https://vocphone.com).
|
|
3
4
|
|
|
4
5
|
## Setup
|
|
6
|
+
|
|
5
7
|
```bash
|
|
6
8
|
npm install
|
|
7
9
|
```
|
|
8
10
|
|
|
9
11
|
## Usage
|
|
12
|
+
|
|
13
|
+
## CDN
|
|
14
|
+
|
|
15
|
+
This is how to use the package from the CDN.
|
|
16
|
+
|
|
17
|
+
### CommonJS
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<div id="render-form"></div>
|
|
21
|
+
|
|
22
|
+
<script src="https://cdn.jsdelivr.net/npm/voc-lib-js@latest/dist/main.global.js"></script>
|
|
23
|
+
<script>
|
|
24
|
+
VocLibJs.FormsLib.renderForm("#render-form", object);
|
|
25
|
+
</script>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Module
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<div id="the-form"></div>
|
|
32
|
+
<script type="module">
|
|
33
|
+
import { FormsLib } from "https://cdn.jsdelivr.net/npm/voc-lib-js@latest/dist/main.mjs";
|
|
34
|
+
|
|
35
|
+
const form = FormsLib.renderForm("#the-form", jsonObject);
|
|
36
|
+
</script>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Node
|
|
40
|
+
|
|
41
|
+
We can also use the package on any frontend framework like React, Angular, Vue, or vanilla.
|
|
42
|
+
|
|
10
43
|
### Installation
|
|
44
|
+
|
|
11
45
|
```bash
|
|
46
|
+
|
|
12
47
|
npm install voc-lib-js
|
|
13
48
|
```
|
|
14
49
|
|
|
15
|
-
###
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```
|
|
50
|
+
### Usage
|
|
51
|
+
|
|
52
|
+
Example using Vue, this will work with any frontend framework
|
|
53
|
+
|
|
54
|
+
```vue
|
|
55
|
+
<script setup>
|
|
56
|
+
import { onMounted, ref } from "vue";
|
|
57
|
+
import { FormsLib } from "voc-lib-js";
|
|
58
|
+
|
|
59
|
+
const form = ref(null);
|
|
60
|
+
|
|
61
|
+
onMounted(() => {
|
|
62
|
+
// the jsonObject we fetch the schema from the database
|
|
63
|
+
form.value = FormsLib.renderForm("#render-form", jsonObject);
|
|
64
|
+
|
|
65
|
+
const values = form.value.getValues();
|
|
66
|
+
console.log("Initial form values:", values);
|
|
67
|
+
});
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<template>
|
|
71
|
+
<main>
|
|
72
|
+
<div id="render-form"></div>
|
|
73
|
+
</main>
|
|
74
|
+
</template>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## EVENTS
|
|
78
|
+
|
|
79
|
+
We have a onSubmit event that when user clicked on the submit button it will return the data from the form.
|
|
80
|
+
|
|
81
|
+
```html
|
|
82
|
+
<script src="./../../dist/main.global.js"></script>
|
|
83
|
+
<script>
|
|
84
|
+
const formRendered = VocLibJs.FormsLib.renderForm("#render-form");
|
|
85
|
+
|
|
86
|
+
// Listen for the submit event
|
|
87
|
+
// the onSubmit will return the form data in object
|
|
88
|
+
formRendered.onSubmit((data) => {
|
|
89
|
+
console.log(data);
|
|
90
|
+
/**
|
|
91
|
+
* example output
|
|
92
|
+
* {
|
|
93
|
+
* "first_name": "John",
|
|
94
|
+
* "last_name": "Doe",
|
|
95
|
+
* "username": "johndoe",
|
|
96
|
+
* "password": "password123",
|
|
97
|
+
* "text_area": "This is a text area",
|
|
98
|
+
* "email": "3ZJ3f@example.com",
|
|
99
|
+
* "gender": "male",
|
|
100
|
+
* "country": "usa"
|
|
101
|
+
* }
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
// Do something with the data
|
|
105
|
+
});
|
|
106
|
+
</script>
|
|
107
|
+
```
|
package/dist/main.d.mts
CHANGED
|
@@ -17,11 +17,14 @@ type BaseField = {
|
|
|
17
17
|
direction?: "horizontal" | "vertical";
|
|
18
18
|
options?: Option[];
|
|
19
19
|
default?: string;
|
|
20
|
+
description?: string;
|
|
20
21
|
};
|
|
21
22
|
type RowField = {
|
|
22
23
|
label?: string;
|
|
23
24
|
type: "row";
|
|
24
25
|
items: BaseField[];
|
|
26
|
+
description?: string;
|
|
27
|
+
direction?: "horizontal" | "vertical";
|
|
25
28
|
};
|
|
26
29
|
type Field = BaseField | RowField;
|
|
27
30
|
type FormData = {
|
|
@@ -36,15 +39,23 @@ interface RenderedForm {
|
|
|
36
39
|
element: HTMLElement;
|
|
37
40
|
message: string;
|
|
38
41
|
}>;
|
|
39
|
-
submitForm: () => void;
|
|
40
42
|
getValues: () => {
|
|
41
43
|
[key: string]: FormDataEntryValue | FormDataEntryValue[];
|
|
42
44
|
};
|
|
45
|
+
onSubmit: (callback: (data: any, event: Event) => void) => void;
|
|
43
46
|
}
|
|
44
|
-
declare function renderForm(element: string | HTMLElement, data: FormData
|
|
47
|
+
declare function renderForm(element: string | HTMLElement, data: FormData, options?: {
|
|
48
|
+
onSubmit?: (result: any, error?: any) => void;
|
|
49
|
+
enableAutoSubmit?: boolean;
|
|
50
|
+
}): RenderedForm | null;
|
|
45
51
|
|
|
46
52
|
declare const FormsLib: {
|
|
47
53
|
renderForm: typeof renderForm;
|
|
48
54
|
};
|
|
55
|
+
declare const _default: {
|
|
56
|
+
FormsLib: {
|
|
57
|
+
renderForm: typeof renderForm;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
49
60
|
|
|
50
|
-
export { FormsLib };
|
|
61
|
+
export { FormsLib, _default as default };
|
package/dist/main.d.ts
CHANGED
|
@@ -17,11 +17,14 @@ type BaseField = {
|
|
|
17
17
|
direction?: "horizontal" | "vertical";
|
|
18
18
|
options?: Option[];
|
|
19
19
|
default?: string;
|
|
20
|
+
description?: string;
|
|
20
21
|
};
|
|
21
22
|
type RowField = {
|
|
22
23
|
label?: string;
|
|
23
24
|
type: "row";
|
|
24
25
|
items: BaseField[];
|
|
26
|
+
description?: string;
|
|
27
|
+
direction?: "horizontal" | "vertical";
|
|
25
28
|
};
|
|
26
29
|
type Field = BaseField | RowField;
|
|
27
30
|
type FormData = {
|
|
@@ -36,15 +39,23 @@ interface RenderedForm {
|
|
|
36
39
|
element: HTMLElement;
|
|
37
40
|
message: string;
|
|
38
41
|
}>;
|
|
39
|
-
submitForm: () => void;
|
|
40
42
|
getValues: () => {
|
|
41
43
|
[key: string]: FormDataEntryValue | FormDataEntryValue[];
|
|
42
44
|
};
|
|
45
|
+
onSubmit: (callback: (data: any, event: Event) => void) => void;
|
|
43
46
|
}
|
|
44
|
-
declare function renderForm(element: string | HTMLElement, data: FormData
|
|
47
|
+
declare function renderForm(element: string | HTMLElement, data: FormData, options?: {
|
|
48
|
+
onSubmit?: (result: any, error?: any) => void;
|
|
49
|
+
enableAutoSubmit?: boolean;
|
|
50
|
+
}): RenderedForm | null;
|
|
45
51
|
|
|
46
52
|
declare const FormsLib: {
|
|
47
53
|
renderForm: typeof renderForm;
|
|
48
54
|
};
|
|
55
|
+
declare const _default: {
|
|
56
|
+
FormsLib: {
|
|
57
|
+
renderForm: typeof renderForm;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
49
60
|
|
|
50
|
-
export { FormsLib };
|
|
61
|
+
export { FormsLib, _default as default };
|
package/dist/main.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var VocLibJs=(()=>{var k=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var T=(i,a)=>{for(var p in a)k(i,p,{get:a[p],enumerable:!0})},M=(i,a,p,d)=>{if(a&&typeof a=="object"||typeof a=="function")for(let u of F(a))!C.call(i,u)&&u!==p&&k(i,u,{get:()=>a[u],enumerable:!(d=L(a,u))||d.enumerable});return i};var H=i=>M(k({},"__esModule",{value:!0}),i);var N={};T(N,{FormsLib:()=>w,default:()=>q});function x(i){let a=new FormData(i),p={};return a.forEach((d,u)=>{p[u]=d}),p}function f(i,a,p){let d=[];if(typeof i=="string"?d=Array.from(document.querySelectorAll(i)):d=[i],d.length===0)return null;function u(){let s=document.createElement("form");s.classList.add("voc-form"),s.id=a.id;let y=document.createElement("h2");y.textContent=a.form_name,s.appendChild(y);function h(e,n){n&&(n.min_length!==void 0&&(e.minLength=n.min_length),n.max_length!==void 0&&(e.maxLength=n.max_length),n.regex&&(e instanceof HTMLInputElement?e.pattern=n.regex:e.dataset.pattern=n.regex))}function v(e){if(!e.key&&!e.label)return null;let n=document.createElement("div");if(n.className="voc-form-group",e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),n.appendChild(t)}let l=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.options)e.options.forEach((r,o)=>{let m=document.createElement("label");m.classList.add("voc-form-checkbox-label"),m.style.display=e.direction==="horizontal"?"inline-block":"block";let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),c.name=e.key||"",c.value=r.value,e.key&&(c.id=`voc-form-${e.key}-${o}`),e.required&&(c.required=!0),e.default===r.value&&(c.checked=!0),m.appendChild(c),m.appendChild(document.createTextNode(r.label)),t.appendChild(m)});else{let r=document.createElement("label");r.classList.add("voc-form-checkbox-label");let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),e.key&&(o.name=e.key,o.id=`voc-form-${e.key}`),e.required&&(o.required=!0),e.default&&(o.checked=!!e.default),r.appendChild(o),r.appendChild(document.createTextNode(e.label||"")),t.appendChild(r)}l=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),e.key&&(t.name=e.key,t.id=`voc-form-${e.key}`),e.required&&(t.required=!0),h(t,e.validation),l=t;break}case"select":{let t=document.createElement("select");t.classList.add("voc-form-select"),e.key&&(t.name=e.key,t.id=`voc-form-${e.key}`),e.required&&(t.required=!0),e.options&&e.options.forEach(r=>{let o=document.createElement("option");o.value=r.value,o.textContent=r.label,e.default===r.value&&(o.selected=!0),t.appendChild(o)}),l=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.options&&e.options.forEach((r,o)=>{let m=document.createElement("label");m.classList.add("voc-form-radio-label"),m.style.display=e.direction==="horizontal"?"inline-block":"block";let c=document.createElement("input");c.type="radio",c.classList.add("voc-form-radio"),c.name=e.key||"",c.value=r.value,e.key&&(c.id=`voc-form-${e.key}-${o}`),m.appendChild(c),m.appendChild(document.createTextNode(r.label)),t.appendChild(m)}),l=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),e.key&&(t.name=e.key,t.id=`voc-form-${e.key}`),e.required&&(t.required=!0),h(t,e.validation),l=t;break}}if(l&&n.appendChild(l),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,n.appendChild(t)}return n}a.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let n=document.createElement("div");if(n.className="voc-form-row",e.label){let t=document.createElement("h3");t.className="voc-form-row-label",t.textContent=e.label,n.appendChild(t)}if(e.description){let t=document.createElement("p");t.className="voc-form-row-description",t.textContent=e.description,n.appendChild(t)}let l=document.createElement("div");l.className="voc-form-row-items "+(e.direction||"vertical"),n.appendChild(l),e.items.forEach(t=>{let r=v(t);r&&l.appendChild(r)}),s.appendChild(n)}else{let n=v(e);n&&s.appendChild(n)}});let E=document.createElement("button");return E.type="submit",E.className="voc-form-submit",E.textContent="Submit",s.appendChild(E),s}let b=u();return d[0].appendChild(b),{element:b,validate:()=>{let s=[];return b.querySelectorAll(":invalid").forEach(h=>{let v=h.validationMessage;s.push({element:h,message:v})}),s},getValues:()=>x(b),onSubmit:s=>{b.addEventListener("submit",y=>{y.preventDefault();let h=x(b);s(h,y)})}}}var g={renderForm:f};var w=g,q={FormsLib:g};return H(N);})();
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var k=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var T=(i,a)=>{for(var p in a)k(i,p,{get:a[p],enumerable:!0})},M=(i,a,p,d)=>{if(a&&typeof a=="object"||typeof a=="function")for(let u of F(a))!C.call(i,u)&&u!==p&&k(i,u,{get:()=>a[u],enumerable:!(d=L(a,u))||d.enumerable});return i};var H=i=>M(k({},"__esModule",{value:!0}),i);var N={};T(N,{FormsLib:()=>w,default:()=>q});module.exports=H(N);function x(i){let a=new FormData(i),p={};return a.forEach((d,u)=>{p[u]=d}),p}function f(i,a,p){let d=[];if(typeof i=="string"?d=Array.from(document.querySelectorAll(i)):d=[i],d.length===0)return null;function u(){let s=document.createElement("form");s.classList.add("voc-form"),s.id=a.id;let y=document.createElement("h2");y.textContent=a.form_name,s.appendChild(y);function h(e,n){n&&(n.min_length!==void 0&&(e.minLength=n.min_length),n.max_length!==void 0&&(e.maxLength=n.max_length),n.regex&&(e instanceof HTMLInputElement?e.pattern=n.regex:e.dataset.pattern=n.regex))}function v(e){if(!e.key&&!e.label)return null;let n=document.createElement("div");if(n.className="voc-form-group",e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),n.appendChild(t)}let l=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.options)e.options.forEach((r,o)=>{let m=document.createElement("label");m.classList.add("voc-form-checkbox-label"),m.style.display=e.direction==="horizontal"?"inline-block":"block";let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),c.name=e.key||"",c.value=r.value,e.key&&(c.id=`voc-form-${e.key}-${o}`),e.required&&(c.required=!0),e.default===r.value&&(c.checked=!0),m.appendChild(c),m.appendChild(document.createTextNode(r.label)),t.appendChild(m)});else{let r=document.createElement("label");r.classList.add("voc-form-checkbox-label");let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),e.key&&(o.name=e.key,o.id=`voc-form-${e.key}`),e.required&&(o.required=!0),e.default&&(o.checked=!!e.default),r.appendChild(o),r.appendChild(document.createTextNode(e.label||"")),t.appendChild(r)}l=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),e.key&&(t.name=e.key,t.id=`voc-form-${e.key}`),e.required&&(t.required=!0),h(t,e.validation),l=t;break}case"select":{let t=document.createElement("select");t.classList.add("voc-form-select"),e.key&&(t.name=e.key,t.id=`voc-form-${e.key}`),e.required&&(t.required=!0),e.options&&e.options.forEach(r=>{let o=document.createElement("option");o.value=r.value,o.textContent=r.label,e.default===r.value&&(o.selected=!0),t.appendChild(o)}),l=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.options&&e.options.forEach((r,o)=>{let m=document.createElement("label");m.classList.add("voc-form-radio-label"),m.style.display=e.direction==="horizontal"?"inline-block":"block";let c=document.createElement("input");c.type="radio",c.classList.add("voc-form-radio"),c.name=e.key||"",c.value=r.value,e.key&&(c.id=`voc-form-${e.key}-${o}`),m.appendChild(c),m.appendChild(document.createTextNode(r.label)),t.appendChild(m)}),l=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),e.key&&(t.name=e.key,t.id=`voc-form-${e.key}`),e.required&&(t.required=!0),h(t,e.validation),l=t;break}}if(l&&n.appendChild(l),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,n.appendChild(t)}return n}a.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let n=document.createElement("div");if(n.className="voc-form-row",e.label){let t=document.createElement("h3");t.className="voc-form-row-label",t.textContent=e.label,n.appendChild(t)}if(e.description){let t=document.createElement("p");t.className="voc-form-row-description",t.textContent=e.description,n.appendChild(t)}let l=document.createElement("div");l.className="voc-form-row-items "+(e.direction||"vertical"),n.appendChild(l),e.items.forEach(t=>{let r=v(t);r&&l.appendChild(r)}),s.appendChild(n)}else{let n=v(e);n&&s.appendChild(n)}});let E=document.createElement("button");return E.type="submit",E.className="voc-form-submit",E.textContent="Submit",s.appendChild(E),s}let b=u();return d[0].appendChild(b),{element:b,validate:()=>{let s=[];return b.querySelectorAll(":invalid").forEach(h=>{let v=h.validationMessage;s.push({element:h,message:v})}),s},getValues:()=>x(b),onSubmit:s=>{b.addEventListener("submit",y=>{y.preventDefault();let h=x(b);s(h,y)})}}}var g={renderForm:f};var w=g,q={FormsLib:g};0&&(module.exports={FormsLib});
|
package/dist/main.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function k(p){let h=new FormData(p),v={};return h.forEach((m,E)=>{v[E]=m}),v}function g(p,h,v){let m=[];if(typeof p=="string"?m=Array.from(document.querySelectorAll(p)):m=[p],m.length===0)return null;function E(){let c=document.createElement("form");c.classList.add("voc-form"),c.id=h.id;let u=document.createElement("h2");u.textContent=h.form_name,c.appendChild(u);function l(e,n){n&&(n.min_length!==void 0&&(e.minLength=n.min_length),n.max_length!==void 0&&(e.maxLength=n.max_length),n.regex&&(e instanceof HTMLInputElement?e.pattern=n.regex:e.dataset.pattern=n.regex))}function b(e){if(!e.key&&!e.label)return null;let n=document.createElement("div");if(n.className="voc-form-group",e.label){let t=document.createElement("label");t.classList.add("voc-form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label+(e.required?" *":""),n.appendChild(t)}let i=null;switch(e.type){case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.options)e.options.forEach((r,o)=>{let s=document.createElement("label");s.classList.add("voc-form-checkbox-label"),s.style.display=e.direction==="horizontal"?"inline-block":"block";let a=document.createElement("input");a.type="checkbox",a.classList.add("voc-form-checkbox"),a.name=e.key||"",a.value=r.value,e.key&&(a.id=`voc-form-${e.key}-${o}`),e.required&&(a.required=!0),e.default===r.value&&(a.checked=!0),s.appendChild(a),s.appendChild(document.createTextNode(r.label)),t.appendChild(s)});else{let r=document.createElement("label");r.classList.add("voc-form-checkbox-label");let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),e.key&&(o.name=e.key,o.id=`voc-form-${e.key}`),e.required&&(o.required=!0),e.default&&(o.checked=!!e.default),r.appendChild(o),r.appendChild(document.createTextNode(e.label||"")),t.appendChild(r)}i=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),e.key&&(t.name=e.key,t.id=`voc-form-${e.key}`),e.required&&(t.required=!0),l(t,e.validation),i=t;break}case"select":{let t=document.createElement("select");t.classList.add("voc-form-select"),e.key&&(t.name=e.key,t.id=`voc-form-${e.key}`),e.required&&(t.required=!0),e.options&&e.options.forEach(r=>{let o=document.createElement("option");o.value=r.value,o.textContent=r.label,e.default===r.value&&(o.selected=!0),t.appendChild(o)}),i=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.options&&e.options.forEach((r,o)=>{let s=document.createElement("label");s.classList.add("voc-form-radio-label"),s.style.display=e.direction==="horizontal"?"inline-block":"block";let a=document.createElement("input");a.type="radio",a.classList.add("voc-form-radio"),a.name=e.key||"",a.value=r.value,e.key&&(a.id=`voc-form-${e.key}-${o}`),s.appendChild(a),s.appendChild(document.createTextNode(r.label)),t.appendChild(s)}),i=t;break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),e.key&&(t.name=e.key,t.id=`voc-form-${e.key}`),e.required&&(t.required=!0),l(t,e.validation),i=t;break}}if(i&&n.appendChild(i),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,n.appendChild(t)}return n}h.fields.forEach(e=>{if(e.type==="row"&&"items"in e){let n=document.createElement("div");if(n.className="voc-form-row",e.label){let t=document.createElement("h3");t.className="voc-form-row-label",t.textContent=e.label,n.appendChild(t)}if(e.description){let t=document.createElement("p");t.className="voc-form-row-description",t.textContent=e.description,n.appendChild(t)}let i=document.createElement("div");i.className="voc-form-row-items "+(e.direction||"vertical"),n.appendChild(i),e.items.forEach(t=>{let r=b(t);r&&i.appendChild(r)}),c.appendChild(n)}else{let n=b(e);n&&c.appendChild(n)}});let y=document.createElement("button");return y.type="submit",y.className="voc-form-submit",y.textContent="Submit",c.appendChild(y),c}let d=E();return m[0].appendChild(d),{element:d,validate:()=>{let c=[];return d.querySelectorAll(":invalid").forEach(l=>{let b=l.validationMessage;c.push({element:l,message:b})}),c},getValues:()=>k(d),onSubmit:c=>{d.addEventListener("submit",u=>{u.preventDefault();let l=k(d);c(l,u)})}}}var x={renderForm:g};var H=x,w={FormsLib:x};export{H as FormsLib,w as default};
|
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "voc-lib-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "A JavaScript library for VocPhone",
|
|
5
5
|
"main": "./dist/main.cjs",
|
|
6
6
|
"module": "./dist/main.mjs",
|
|
7
|
-
"unpkg": "./dist/main.iife.js",
|
|
8
|
-
"jsdelivr": "./dist/main.iife.js",
|
|
9
7
|
"types": "./dist/main.d.ts",
|
|
10
8
|
"scripts": {
|
|
11
9
|
"build": "tsup",
|
|
12
|
-
"up": "npm version patch && rimraf dist && npm run build && npm publish"
|
|
10
|
+
"up": "npm version patch && rimraf dist && npm run build && npm publish",
|
|
11
|
+
"del-dist": "rimraf dist"
|
|
13
12
|
},
|
|
14
13
|
"repository": {
|
|
15
14
|
"type": "git",
|
|
@@ -31,6 +30,7 @@
|
|
|
31
30
|
},
|
|
32
31
|
"files": [
|
|
33
32
|
"dist",
|
|
34
|
-
"README.md"
|
|
33
|
+
"README.md",
|
|
34
|
+
"src/css"
|
|
35
35
|
]
|
|
36
36
|
}
|
|
File without changes
|