@josercl/form-maker 1.1.0-beta01 → 1.1.0-beta02

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/index.js CHANGED
@@ -8,7 +8,7 @@ import FormMakerInputLabel from './lib/components/inputs/FormMakerInputLabel.vue
8
8
  import RadioInput from './lib/components/inputs/RadioInput.vue';
9
9
  import SelectInput from './lib/components/inputs/SelectInput.vue';
10
10
  import TextAreaInput from './lib/components/inputs/TextAreaInput.vue';
11
- import TextInput from './lib/components/inputs/TextInput.vue';
11
+ import BasicInput from './lib/components/inputs/BasicInput.vue';
12
12
 
13
13
  const defaultOptions = {
14
14
  classes: {
@@ -26,19 +26,19 @@ const defaultOptions = {
26
26
  'submit-button': 'form-maker-submit',
27
27
  },
28
28
  components: {
29
- 'form-maker-input-color': TextInput,
30
- 'form-maker-input-date': TextInput,
31
- 'form-maker-input-email': TextInput,
32
- 'form-maker-input-month': TextInput,
33
- 'form-maker-input-number': TextInput,
34
- 'form-maker-input-password': TextInput,
35
- 'form-maker-input-search': TextInput,
36
- 'form-maker-input-tel': TextInput,
37
- 'form-maker-input-time': TextInput,
38
- 'form-maker-input-text': TextInput,
39
- 'form-maker-input-url': TextInput,
40
- 'form-maker-input-week': TextInput,
41
- 'form-maker-input-range': TextInput,
29
+ 'form-maker-input-color': BasicInput,
30
+ 'form-maker-input-date': BasicInput,
31
+ 'form-maker-input-email': BasicInput,
32
+ 'form-maker-input-month': BasicInput,
33
+ 'form-maker-input-number': BasicInput,
34
+ 'form-maker-input-password': BasicInput,
35
+ 'form-maker-input-search': BasicInput,
36
+ 'form-maker-input-tel': BasicInput,
37
+ 'form-maker-input-time': BasicInput,
38
+ 'form-maker-input-text': BasicInput,
39
+ 'form-maker-input-url': BasicInput,
40
+ 'form-maker-input-week': BasicInput,
41
+ 'form-maker-input-range': BasicInput,
42
42
  'form-maker-input-file': FileInput,
43
43
  'form-maker-input-textarea': TextAreaInput,
44
44
  'form-maker-input-select': SelectInput,
@@ -63,13 +63,15 @@ const FormMaker = {
63
63
  app.component('FormMaker', FormMakerComponent);
64
64
  app.component('FormMakerInput', FormMakerInput);
65
65
 
66
- Object.keys(options.classes).forEach(key => {
67
- app.provide(key, options.classes[key]);
68
- });
66
+ Object.keys(options.classes)
67
+ .forEach(key => {
68
+ app.provide(key, options.classes[key]);
69
+ });
69
70
 
70
- Object.keys(options.components).forEach(key => {
71
- app.component(key, options.components[key]);
72
- });
71
+ Object.keys(options.components)
72
+ .forEach(key => {
73
+ app.component(key, options.components[key]);
74
+ });
73
75
  },
74
76
  };
75
77
  export default FormMaker;
@@ -1,3 +1,135 @@
1
+ <script setup>
2
+ import {
3
+ computed, inject, provide, toRefs
4
+ } from 'vue';
5
+
6
+ const props = defineProps({
7
+ loading: {
8
+ type: Boolean,
9
+ default: false,
10
+ },
11
+ hasActions: {
12
+ type: Boolean,
13
+ default: true,
14
+ },
15
+ modelValue: {
16
+ type: Object,
17
+ default: () => ({}),
18
+ },
19
+ fields: {
20
+ type: Array,
21
+ default: () => [],
22
+ },
23
+ hideDivider: {
24
+ type: Boolean,
25
+ default: false,
26
+ },
27
+ rowClass: {
28
+ type: String,
29
+ default: null,
30
+ },
31
+ columnClass: {
32
+ type: String,
33
+ default: null,
34
+ },
35
+ labelClass: {
36
+ type: String,
37
+ default: null,
38
+ },
39
+ inputGroupClass: {
40
+ type: String,
41
+ default: null,
42
+ },
43
+ inputWrapperClass: {
44
+ type: String,
45
+ default: null,
46
+ },
47
+ inputErrorClass: {
48
+ type: String,
49
+ default: null,
50
+ },
51
+ inputClass: {
52
+ type: String,
53
+ default: null,
54
+ },
55
+ errorClass: {
56
+ type: String,
57
+ default: null,
58
+ },
59
+ helpTextClass: {
60
+ type: String,
61
+ default: null,
62
+ },
63
+ submitButtonClass: {
64
+ type: String,
65
+ default: null,
66
+ },
67
+ submitButtonText: {
68
+ type: String,
69
+ default: 'Submit',
70
+ },
71
+ });
72
+
73
+ const emit = defineEmits([ 'submit', 'update:modelValue' ]);
74
+
75
+ const handleSubmit = () => emit('submit');
76
+
77
+ const formFields = computed(() => {
78
+ if (props.fields.length > 0) {
79
+ return props.fields.map(row => {
80
+ let newRow = row;
81
+ if (!Array.isArray(row)) {
82
+ newRow = [ row ];
83
+ }
84
+ return newRow.map(fieldSpec => {
85
+ if (!fieldSpec.id) {
86
+ return {
87
+ ...fieldSpec,
88
+ id: `formMaker_${new Date().getTime()}_${fieldSpec.name}`,
89
+ };
90
+ }
91
+ return fieldSpec;
92
+ });
93
+ });
94
+ }
95
+
96
+ return Object.keys(props.modelValue)
97
+ .map(key => [
98
+ {
99
+ name: key,
100
+ label: key,
101
+ id: `formMaker_${key}`,
102
+ },
103
+ ]);
104
+ });
105
+
106
+ const {
107
+ rowClass,
108
+ columnClass,
109
+ labelClass,
110
+ inputGroupClass,
111
+ inputWrapperClass,
112
+ inputErrorClass,
113
+ inputClass,
114
+ errorClass,
115
+ helpTextClass,
116
+ submitButtonClass,
117
+ modelValue,
118
+ } = toRefs(props);
119
+
120
+ provide('labelClass', labelClass.value || inject('form-label'));
121
+ provide('inputGroupClass', inputGroupClass.value || inject('input-group'));
122
+ provide('inputWrapperClass', inputWrapperClass.value || inject('input-wrapper'));
123
+ provide('inputErrorClass', inputErrorClass.value || inject('input-error'));
124
+ provide('inputClass', inputClass.value || inject('input'));
125
+ provide('errorClass', errorClass.value || inject('error'));
126
+ provide('helpTextClass', helpTextClass.value || inject('help-text'));
127
+
128
+ const realRowClass = rowClass.value || inject('form-row');
129
+ const realColumnClass = columnClass.value || inject('form-column');
130
+ const realSubmitButtonClass = submitButtonClass.value || inject('submit-button');
131
+ </script>
132
+
1
133
  <template>
2
134
  <form
3
135
  class="form-maker"
@@ -25,14 +157,13 @@
25
157
  :name="`${field.name}`"
26
158
  >
27
159
  <form-maker-input
28
- v-model="value[field.name]"
160
+ v-model="modelValue[field.name]"
29
161
  v-bind="field"
30
162
  />
31
163
  </slot>
32
164
  </div>
33
165
  </div>
34
166
  </slot>
35
-
36
167
  <slot name="extra" />
37
168
  <slot name="divider">
38
169
  <hr v-if="hasActions && !hideDivider">
@@ -54,148 +185,3 @@
54
185
  </slot>
55
186
  </form>
56
187
  </template>
57
-
58
- <script>
59
- import {
60
- computed, inject, provide, toRefs
61
- } from 'vue';
62
- // import setupVModel from '../utils';
63
-
64
- export default {
65
- name: 'FormMaker',
66
- emits: [ 'submit', 'update:modelValue' ],
67
- props: {
68
- loading: {
69
- type: Boolean,
70
- default: false,
71
- },
72
- hasActions: {
73
- type: Boolean,
74
- default: true,
75
- },
76
- modelValue: {
77
- type: Object,
78
- default: () => ({}),
79
- },
80
- fields: {
81
- type: Array,
82
- default: () => [],
83
- },
84
- hideDivider: {
85
- type: Boolean,
86
- default: false,
87
- },
88
- rowClass: {
89
- type: String,
90
- default: null,
91
- },
92
- columnClass: {
93
- type: String,
94
- default: null,
95
- },
96
- labelClass: {
97
- type: String,
98
- default: null,
99
- },
100
- inputGroupClass: {
101
- type: String,
102
- default: null,
103
- },
104
- inputWrapperClass: {
105
- type: String,
106
- default: null,
107
- },
108
- inputErrorClass: {
109
- type: String,
110
- default: null,
111
- },
112
- inputClass: {
113
- type: String,
114
- default: null,
115
- },
116
- errorClass: {
117
- type: String,
118
- default: null,
119
- },
120
- helpTextClass: {
121
- type: String,
122
- default: null,
123
- },
124
- submitButtonClass: {
125
- type: String,
126
- default: null,
127
- },
128
- submitButtonText: {
129
- type: String,
130
- default: 'Submit',
131
- },
132
- },
133
- setup(props, { emit }) {
134
- const handleSubmit = () => emit('submit');
135
-
136
- const formFields = computed(() => {
137
- if (props.fields.length > 0) {
138
- return props.fields.map(row => {
139
- let newRow = row;
140
- if (!Array.isArray(row)) {
141
- newRow = [ row ];
142
- }
143
- return newRow.map(fieldSpec => {
144
- if (!fieldSpec.id) {
145
- return {
146
- ...fieldSpec,
147
- id: `formMaker_${new Date().getTime()}_${fieldSpec.name}`,
148
- };
149
- }
150
- return fieldSpec;
151
- });
152
- });
153
- }
154
-
155
- return Object.keys(props.modelValue)
156
- .map(key => [
157
- {
158
- name: key,
159
- label: key,
160
- id: `formMaker_${key}`,
161
- },
162
- ]);
163
- });
164
-
165
- const {
166
- rowClass,
167
- columnClass,
168
- labelClass,
169
- inputGroupClass,
170
- inputWrapperClass,
171
- inputErrorClass,
172
- inputClass,
173
- errorClass,
174
- helpTextClass,
175
- submitButtonClass,
176
- modelValue,
177
- } = toRefs(props);
178
-
179
- provide('labelClass', labelClass.value || inject('form-label'));
180
- provide('inputGroupClass', inputGroupClass.value || inject('input-group'));
181
- provide('inputWrapperClass', inputWrapperClass.value || inject('input-wrapper'));
182
- provide('inputErrorClass', inputErrorClass.value || inject('input-error'));
183
- provide('inputClass', inputClass.value || inject('input'));
184
- provide('errorClass', errorClass.value || inject('error'));
185
- provide('helpTextClass', helpTextClass.value || inject('help-text'));
186
-
187
- const realRowClass = rowClass.value || inject('form-row');
188
- const realColumnClass = columnClass.value || inject('form-column');
189
- const realSubmitButtonClass = submitButtonClass.value || inject('submit-button');
190
-
191
- return {
192
- value: modelValue,
193
- formFields,
194
- realColumnClass,
195
- realRowClass,
196
- realSubmitButtonClass,
197
- handleSubmit,
198
- };
199
- },
200
- };
201
- </script>
@@ -1,5 +1,40 @@
1
+ <script setup>
2
+ import setupVModel from '../utils';
3
+ import {
4
+ FormInputMixin,
5
+ injectFormClasses,
6
+ getFormInputComputeds
7
+ } from './inputs/FormInputMixin';
8
+
9
+ const props = defineProps(FormInputMixin.props);
10
+ const emit = defineEmits(FormInputMixin.emits);
11
+
12
+ const value = setupVModel(props, emit);
13
+
14
+ const {
15
+ labelClass,
16
+ inputClass,
17
+ inputWrapperClass,
18
+ inputGroupClass,
19
+ inputErrorClass,
20
+ errorClass,
21
+ helpTextClass,
22
+ } = injectFormClasses();
23
+
24
+ const {
25
+ hasErrors,
26
+ hasLabel,
27
+ hasHelpText,
28
+ } = getFormInputComputeds(props);
29
+ </script>
30
+ <script>
31
+ export default {
32
+ inheritAttrs: false,
33
+ };
34
+ </script>
35
+
1
36
  <template>
2
- <div :class="[ hasErrors && inputErrorClass ]">
37
+ <div :class="[ hasErrors && inputErrorClass, inputWrapperClass ]">
3
38
  <slot
4
39
  v-if="type !== 'checkbox'"
5
40
  name="label"
@@ -40,43 +75,3 @@
40
75
  </slot>
41
76
  </div>
42
77
  </template>
43
-
44
- <script>
45
- import setupVModel from '../utils';
46
- import { FormInputMixin, injectFormClasses, getFormInputComputeds } from './inputs/FormInputMixin';
47
-
48
- export default {
49
- name: 'FormMakerInput',
50
- mixins: [ FormInputMixin ],
51
- inheritAttrs: false,
52
- setup(props, { emit }) {
53
- const value = setupVModel(props, emit);
54
-
55
- const {
56
- labelClass,
57
- inputClass,
58
- inputWrapperClass,
59
- inputGroupClass,
60
- inputErrorClass,
61
- errorClass,
62
- helpTextClass,
63
- } = injectFormClasses();
64
-
65
- const { hasErrors, hasLabel, hasHelpText } = getFormInputComputeds(props);
66
-
67
- return {
68
- value,
69
- labelClass,
70
- inputClass,
71
- inputErrorClass,
72
- inputGroupClass,
73
- inputWrapperClass,
74
- errorClass,
75
- helpTextClass,
76
- hasErrors,
77
- hasLabel,
78
- hasHelpText,
79
- };
80
- },
81
- };
82
- </script>
@@ -1,3 +1,13 @@
1
+ <script setup>
2
+ import setupVModel from '../../utils';
3
+ import { FormInputMixin } from './FormInputMixin';
4
+
5
+ const props = defineProps(FormInputMixin.props);
6
+ const emit = defineEmits(FormInputMixin.emits);
7
+
8
+ const value = setupVModel(props, emit);
9
+ </script>
10
+
1
11
  <template>
2
12
  <input
3
13
  v-model="value"
@@ -5,20 +15,3 @@
5
15
  v-bind="$props"
6
16
  >
7
17
  </template>
8
-
9
- <script>
10
- import setupVModel from '../../utils';
11
- import { FormInputMixin } from './FormInputMixin';
12
-
13
- export default {
14
- name: 'TextInput',
15
- mixins: [ FormInputMixin ],
16
- setup(props, { emit }) {
17
- const value = setupVModel(props, emit);
18
-
19
- return {
20
- value,
21
- };
22
- },
23
- };
24
- </script>
@@ -1,3 +1,52 @@
1
+ <script setup>
2
+ import { computed, toRefs } from 'vue';
3
+ import { FormInputMixin } from './FormInputMixin';
4
+
5
+ const props = defineProps({
6
+ ...FormInputMixin.props,
7
+ options: { type: Array, default: () => [] },
8
+ });
9
+ const emit = defineEmits(FormInputMixin.emits);
10
+
11
+ const { options, label } = toRefs(props);
12
+
13
+ const isBinary = computed(() => options.value.length === 0);
14
+
15
+ const val = computed(() => props.modelValue);
16
+
17
+ const selectedOptions = computed(() => {
18
+ const arr = Array.isArray(val.value) ? val.value : [ val.value ];
19
+ return arr.filter(x => !!x);
20
+ });
21
+
22
+ const fieldOptions = computed(() => {
23
+ if (!isBinary.value) {
24
+ return options.value;
25
+ }
26
+ return [
27
+ {
28
+ label: label.value,
29
+ value: true,
30
+ },
31
+ ];
32
+ });
33
+
34
+ const handleClick = clickVal => {
35
+ let selOptions = [ ...selectedOptions.value ];
36
+ if (selOptions.indexOf(clickVal) === -1) {
37
+ selOptions.push(clickVal);
38
+ } else {
39
+ selOptions = selOptions.filter(x => x !== clickVal);
40
+ }
41
+
42
+ if (isBinary.value) {
43
+ emit('update:modelValue', selOptions.length > 0);
44
+ } else {
45
+ emit('update:modelValue', selOptions);
46
+ }
47
+ };
48
+ </script>
49
+
1
50
  <template>
2
51
  <div
3
52
  v-for="(option,i) in fieldOptions"
@@ -15,66 +64,3 @@
15
64
  </label>
16
65
  </div>
17
66
  </template>
18
-
19
- <script>
20
- import { computed, toRefs } from 'vue';
21
- import { FormInputMixin } from './FormInputMixin';
22
-
23
- export default {
24
- name: 'CheckInput',
25
- mixins: [ FormInputMixin ],
26
- emits: [ 'update:modelValue' ],
27
- props: {
28
- label: {
29
- type: String,
30
- default: null,
31
- },
32
- },
33
- setup(props, { emit }) {
34
- const { options, label } = toRefs(props);
35
-
36
- const isBinary = computed(() => options.value.length === 0);
37
-
38
- const val = computed(() => props.modelValue);
39
-
40
- const selectedOptions = computed(() => {
41
- const arr = Array.isArray(val.value) ? val.value : [ val.value ];
42
- return arr.filter(x => !!x);
43
- });
44
-
45
- const fieldOptions = computed(() => {
46
- if (!isBinary.value) {
47
- return options.value;
48
- }
49
- return [
50
- {
51
- label: label.value,
52
- value: true,
53
- },
54
- ];
55
- });
56
-
57
- const handleClick = clickVal => {
58
- let selOptions = [ ...selectedOptions.value ];
59
- if (selOptions.indexOf(clickVal) === -1) {
60
- selOptions.push(clickVal);
61
- } else {
62
- selOptions = selOptions.filter(x => x !== clickVal);
63
- }
64
-
65
- if (isBinary.value) {
66
- emit('update:modelValue', selOptions.length > 0);
67
- } else {
68
- emit('update:modelValue', selOptions);
69
- }
70
- };
71
-
72
- return {
73
- fieldOptions,
74
- isBinary,
75
- selectedOptions,
76
- handleClick,
77
- };
78
- },
79
- };
80
- </script>
@@ -1,3 +1,17 @@
1
+ <script setup>
2
+ import { FormInputMixin } from './FormInputMixin';
3
+
4
+ defineProps(FormInputMixin.props);
5
+ const emit = defineEmits(FormInputMixin.emits);
6
+
7
+ const handleFileSelect = event => {
8
+ if (event.target.files.length) {
9
+ const file = event.target.files[0];
10
+ emit('update:modelValue', file);
11
+ }
12
+ };
13
+ </script>
14
+
1
15
  <template>
2
16
  <input
3
17
  v-bind="$props"
@@ -5,25 +19,3 @@
5
19
  @change="handleFileSelect"
6
20
  >
7
21
  </template>
8
-
9
- <script>
10
- import { FormInputMixin } from './FormInputMixin';
11
-
12
- export default {
13
- name: 'FileInput',
14
- mixins: [ FormInputMixin ],
15
- emits: [ 'update:modelValue' ],
16
- setup(props, { emit }) {
17
- const handleFileSelect = event => {
18
- if (event.target.files.length) {
19
- const file = event.target.files[0];
20
- emit('update:modelValue', file);
21
- }
22
- };
23
-
24
- return {
25
- handleFileSelect,
26
- };
27
- },
28
- };
29
- </script>
@@ -23,9 +23,9 @@ export const injectFormClasses = () => {
23
23
  export const getFormInputComputeds = props => {
24
24
  const { label, error, helpText } = toRefs(props);
25
25
 
26
- const hasErrors = computed(() => !!error.value);
27
- const hasLabel = computed(() => !!label.value);
28
- const hasHelpText = computed(() => !!helpText.value);
26
+ const hasErrors = computed(() => Boolean(error.value));
27
+ const hasLabel = computed(() => Boolean(label.value));
28
+ const hasHelpText = computed(() => Boolean(helpText.value));
29
29
 
30
30
  return {
31
31
  hasErrors,
@@ -47,7 +47,5 @@ export const FormInputMixin = {
47
47
  name: { type: String, default: null },
48
48
  placeholder: { type: String, default: null },
49
49
  type: { type: String, default: 'text' },
50
- options: { type: Array, default: () => [] },
51
- optionGroups: { type: Object, default: () => ({}) },
52
50
  },
53
51
  };
@@ -1,15 +1,12 @@
1
+ <script setup>
2
+ defineProps({
3
+ text: {
4
+ type: String,
5
+ default: null,
6
+ },
7
+ });
8
+ </script>
9
+
1
10
  <template>
2
11
  <div>{{ text }}</div>
3
12
  </template>
4
-
5
- <script>
6
- export default {
7
- name: 'FormMakerInputError',
8
- props: {
9
- text: {
10
- type: String,
11
- default: null,
12
- },
13
- },
14
- };
15
- </script>
@@ -1,15 +1,12 @@
1
+ <script setup>
2
+ defineProps({
3
+ text: {
4
+ type: String,
5
+ default: null,
6
+ },
7
+ });
8
+ </script>
9
+
1
10
  <template>
2
11
  <div>{{ text }}</div>
3
12
  </template>
4
-
5
- <script>
6
- export default {
7
- name: 'FormMakerInputHelp',
8
- props: {
9
- text: {
10
- type: String,
11
- default: null,
12
- },
13
- },
14
- };
15
- </script>
@@ -1,19 +1,16 @@
1
+ <script setup>
2
+ defineProps({
3
+ text: {
4
+ type: String,
5
+ default: null,
6
+ },
7
+ id: {
8
+ type: String,
9
+ default: null,
10
+ },
11
+ });
12
+ </script>
13
+
1
14
  <template>
2
15
  <label :for="id">{{ text }}</label>
3
16
  </template>
4
-
5
- <script>
6
- export default {
7
- name: 'FormMakerInputLabel',
8
- props: {
9
- text: {
10
- type: String,
11
- default: null,
12
- },
13
- id: {
14
- type: String,
15
- default: null,
16
- },
17
- },
18
- };
19
- </script>
@@ -1,3 +1,19 @@
1
+ <script setup>
2
+ import { FormInputMixin } from './FormInputMixin';
3
+
4
+ defineProps({
5
+ ...FormInputMixin.props,
6
+ options: {
7
+ type: Array,
8
+ default: () => [],
9
+ },
10
+ });
11
+
12
+ const emit = defineEmits(FormInputMixin.emits);
13
+
14
+ const handleClick = e => emit('update:modelValue', e.target.value);
15
+ </script>
16
+
1
17
  <template>
2
18
  <div
3
19
  v-for="(option, i) in options"
@@ -15,26 +31,3 @@
15
31
  </label>
16
32
  </div>
17
33
  </template>
18
-
19
- <script>
20
- import { FormInputMixin } from './FormInputMixin';
21
-
22
- export default {
23
- name: 'RadioInput',
24
- emits: [ 'update:modelValue' ],
25
- mixins: [ FormInputMixin ],
26
- props: {
27
- label: {
28
- type: String,
29
- default: null,
30
- },
31
- },
32
- setup(props, { emit }) {
33
- const handleClick = e => emit('update:modelValue', e.target.value);
34
-
35
- return {
36
- handleClick,
37
- };
38
- },
39
- };
40
- </script>
@@ -1,3 +1,39 @@
1
+ <script setup>
2
+ import { computed } from 'vue';
3
+ import { FormInputMixin } from './FormInputMixin';
4
+ import setupVModel from '../../utils';
5
+
6
+ const props = defineProps({
7
+ ...FormInputMixin.props,
8
+ options: {
9
+ type: Array,
10
+ default: () => [],
11
+ },
12
+ optionGroups: {
13
+ type: Object,
14
+ default: () => ({}),
15
+ },
16
+ });
17
+
18
+ const emit = defineEmits(FormInputMixin.emits);
19
+
20
+ const value = setupVModel(props, emit);
21
+
22
+ const hasGroups = Object.keys(props.optionGroups).length > 0;
23
+
24
+ const fixedOptions = computed(() => props.options.map(o => {
25
+ if (typeof o === 'object') {
26
+ return o;
27
+ }
28
+ return {
29
+ label: o,
30
+ value: o,
31
+ };
32
+ }));
33
+
34
+ console.log(fixedOptions.value);
35
+ </script>
36
+
1
37
  <template>
2
38
  <select
3
39
  :id="id"
@@ -22,7 +58,7 @@
22
58
  </optgroup>
23
59
  </template>
24
60
  <option
25
- v-for="(option,i) in options"
61
+ v-for="(option,i) in fixedOptions"
26
62
  v-else
27
63
  :key="`option_${i}`"
28
64
  :value="option.value"
@@ -31,23 +67,3 @@
31
67
  </option>
32
68
  </select>
33
69
  </template>
34
-
35
- <script>
36
- import setupVModel from '../../utils';
37
- import { FormInputMixin } from './FormInputMixin';
38
-
39
- export default {
40
- name: 'SelectInput',
41
- mixins: [ FormInputMixin ],
42
- setup(props, { emit }) {
43
- const value = setupVModel(props, emit);
44
-
45
- const hasGroups = Object.keys(props.optionGroups).length > 0;
46
-
47
- return {
48
- value,
49
- hasGroups,
50
- };
51
- },
52
- };
53
- </script>
@@ -1,3 +1,13 @@
1
+ <script setup>
2
+ import setupVModel from '../../utils';
3
+ import { FormInputMixin } from './FormInputMixin';
4
+
5
+ const props = defineProps(FormInputMixin.props);
6
+ const emit = defineEmits(FormInputMixin.emits);
7
+
8
+ const value = setupVModel(props, emit);
9
+ </script>
10
+
1
11
  <template>
2
12
  <textarea
3
13
  :id="id"
@@ -7,20 +17,3 @@
7
17
  :placeholder="placeholder"
8
18
  />
9
19
  </template>
10
-
11
- <script>
12
- import setupVModel from '../../utils';
13
- import { FormInputMixin } from './FormInputMixin';
14
-
15
- export default {
16
- name: 'TextAreaInput',
17
- mixins: [ FormInputMixin ],
18
- setup(props, { emit }) {
19
- const value = setupVModel(props, emit);
20
-
21
- return {
22
- value,
23
- };
24
- },
25
- };
26
- </script>
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@josercl/form-maker",
3
- "version": "1.1.0-beta01",
3
+ "version": "1.1.0-beta02",
4
4
  "description": "Form generator using vue 3",
5
5
  "author": "Jose Carrero <josercl@gmail.com>",
6
6
  "scripts": {
7
- "dev": "vite -c docs.config.js dev",
7
+ "docs": "vite -c docs.config.js dev --port 9090",
8
+ "dev": "vite -c dev.config.js dev",
8
9
  "build": "vite build",
9
10
  "build-docs": "vite -c docs.config.js build",
10
11
  "preview": "vite -c docs.config.js preview --port 5050",
11
- "lint": "eslint --ext .vue,.js lib/ docs/ index.js"
12
+ "lint": "eslint --ext .vue,.js lib/ docs/ dev/ index.js"
12
13
  },
13
14
  "files": [
14
15
  "index.js",
@@ -26,13 +27,16 @@
26
27
  "@fortawesome/free-brands-svg-icons": "^5.15.1",
27
28
  "@fortawesome/free-regular-svg-icons": "^5.15.1",
28
29
  "@fortawesome/vue-fontawesome": "^3.0.0-2",
29
- "@tailwindcss/typography": "^0.2.0",
30
+ "@tailwindcss/forms": "^0.4.0",
31
+ "@tailwindcss/typography": "^0.5.2",
30
32
  "@vitejs/plugin-vue": "^2.2.2",
31
33
  "@vue/eslint-config-airbnb": "^6.0.0",
34
+ "autoprefixer": "^10.4.2",
32
35
  "eslint": "^8.10.0",
33
36
  "eslint-plugin-vue": "^8.5.0",
34
37
  "highlight.js": "^10.2.1",
35
- "tailwindcss": "^1.9.6",
38
+ "postcss": "^8.4.7",
39
+ "tailwindcss": "^3.0.23",
36
40
  "vite": "^2.8.4",
37
41
  "vue-router": "^4.0.12"
38
42
  },
package/umd/index.umd.js CHANGED
@@ -1 +1 @@
1
- var $e=Object.defineProperty,Se=Object.defineProperties;var Ee=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var Ve=Object.prototype.hasOwnProperty,Fe=Object.prototype.propertyIsEnumerable;var E=(e,a,f)=>a in e?$e(e,a,{enumerable:!0,configurable:!0,writable:!0,value:f}):e[a]=f,k=(e,a)=>{for(var f in a||(a={}))Ve.call(a,f)&&E(e,f,a[f]);if(S)for(var f of S(a))Fe.call(a,f)&&E(e,f,a[f]);return e},V=(e,a)=>Se(e,Ee(a));(function(e,a){typeof exports=="object"&&typeof module!="undefined"?module.exports=a(require("vue")):typeof define=="function"&&define.amd?define(["vue"],a):(e=typeof globalThis!="undefined"?globalThis:e||self,e.FormMaker=a(e.Vue))})(this,function(e){"use strict";var a=(t,r)=>{const n=t.__vccOpts||t;for(const[l,s]of r)n[l]=s;return n};const f={name:"FormMaker",emits:["submit","update:modelValue"],props:{loading:{type:Boolean,default:!1},hasActions:{type:Boolean,default:!0},modelValue:{type:Object,default:()=>({})},fields:{type:Array,default:()=>[]},hideDivider:{type:Boolean,default:!1},rowClass:{type:String,default:null},columnClass:{type:String,default:null},labelClass:{type:String,default:null},inputGroupClass:{type:String,default:null},inputWrapperClass:{type:String,default:null},inputErrorClass:{type:String,default:null},inputClass:{type:String,default:null},errorClass:{type:String,default:null},helpTextClass:{type:String,default:null},submitButtonClass:{type:String,default:null},submitButtonText:{type:String,default:"Submit"}},setup(t,{emit:r}){const n=()=>r("submit"),l=e.computed(()=>t.fields.length>0?t.fields.map(b=>{let $=b;return Array.isArray(b)||($=[b]),$.map(g=>g.id?g:V(k({},g),{id:`formMaker_${new Date().getTime()}_${g.name}`}))}):Object.keys(t.modelValue).map(b=>[{name:b,label:b,id:`formMaker_${b}`}])),{rowClass:s,columnClass:i,labelClass:o,inputGroupClass:m,inputWrapperClass:u,inputErrorClass:p,inputClass:c,errorClass:h,helpTextClass:B,submitButtonClass:be,modelValue:ye}=e.toRefs(t);e.provide("labelClass",o.value||e.inject("form-label")),e.provide("inputGroupClass",m.value||e.inject("input-group")),e.provide("inputWrapperClass",u.value||e.inject("input-wrapper")),e.provide("inputErrorClass",p.value||e.inject("input-error")),e.provide("inputClass",c.value||e.inject("input")),e.provide("errorClass",h.value||e.inject("error")),e.provide("helpTextClass",B.value||e.inject("help-text"));const ge=s.value||e.inject("form-row"),Be=i.value||e.inject("form-column"),_e=be.value||e.inject("submit-button");return{value:ye,formFields:l,realColumnClass:Be,realRowClass:ge,realSubmitButtonClass:_e,handleSubmit:n}}},F=e.createTextVNode(" Loading... "),x={key:0},T=["disabled"];function j(t,r,n,l,s,i){const o=e.resolveComponent("form-maker-input");return e.openBlock(),e.createElementBlock("form",{class:"form-maker",onSubmit:r[0]||(r[0]=e.withModifiers((...m)=>l.handleSubmit&&l.handleSubmit(...m),["prevent"]))},[n.loading?e.renderSlot(t.$slots,"loading",{key:0},()=>[F]):e.createCommentVNode("",!0),e.renderSlot(t.$slots,"default",{},()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.formFields,(m,u)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(l.realRowClass),key:`fieldRow_${u}`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(m,(p,c)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([l.realColumnClass,p.columnClass]),key:`field_${u}_${c}`},[e.renderSlot(t.$slots,`${p.name}`,{field:p},()=>[e.createVNode(o,e.mergeProps({modelValue:l.value[p.name],"onUpdate:modelValue":h=>l.value[p.name]=h},p),null,16,["modelValue","onUpdate:modelValue"])])],2))),128))],2))),128))]),e.renderSlot(t.$slots,"extra"),e.renderSlot(t.$slots,"divider",{},()=>[n.hasActions&&!n.hideDivider?(e.openBlock(),e.createElementBlock("hr",x)):e.createCommentVNode("",!0)]),n.hasActions?e.renderSlot(t.$slots,"actions",{key:1},()=>[e.renderSlot(t.$slots,"submit-button",{},()=>[e.createElementVNode("button",{class:e.normalizeClass(l.realSubmitButtonClass),disabled:n.loading,type:"submit"},e.toDisplayString(n.submitButtonText),11,T)]),e.renderSlot(t.$slots,"extra-buttons")]):e.createCommentVNode("",!0)],32)}var I=a(f,[["render",j]]);const y=(t,r,n="modelValue")=>e.computed({get:()=>t[n],set:l=>r(`update:${n}`,l)}),M=()=>{const t=e.inject("labelClass",null),r=e.inject("inputClass",null),n=e.inject("inputWrapperClass",null),l=e.inject("inputGroupClass",null),s=e.inject("inputErrorClass",null),i=e.inject("errorClass",null),o=e.inject("helpTextClass",null);return{labelClass:t,inputClass:r,inputWrapperClass:n,inputGroupClass:l,inputErrorClass:s,errorClass:i,helpTextClass:o}},w=t=>{const{label:r,error:n,helpText:l}=e.toRefs(t),s=e.computed(()=>!!n.value),i=e.computed(()=>!!r.value),o=e.computed(()=>!!l.value);return{hasErrors:s,hasLabel:i,hasHelpText:o}},C={emits:["update:modelValue"],props:{loading:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},modelValue:{default:null},error:{type:String,default:null},helpText:{type:String,default:null},id:{type:String,default:null},label:{type:String,default:null},name:{type:String,default:null},placeholder:{type:String,default:null},type:{type:String,default:"text"},options:{type:Array,default:()=>[]},optionGroups:{type:Object,default:()=>({})}}},D={name:"FormMakerInput",mixins:[C],inheritAttrs:!1,setup(t,{emit:r}){const n=y(t,r),{labelClass:l,inputClass:s,inputWrapperClass:i,inputGroupClass:o,inputErrorClass:m,errorClass:u,helpTextClass:p}=M(),{hasErrors:c,hasLabel:h,hasHelpText:B}=w(t);return{value:n,labelClass:l,inputClass:s,inputErrorClass:m,inputGroupClass:o,inputWrapperClass:i,errorClass:u,helpTextClass:p,hasErrors:c,hasLabel:h,hasHelpText:B}}};function N(t,r,n,l,s,i){const o=e.resolveComponent("form-maker-label"),m=e.resolveComponent("form-maker-help"),u=e.resolveComponent("form-maker-error");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([l.hasErrors&&l.inputErrorClass])},[t.type!=="checkbox"?e.renderSlot(t.$slots,"label",{key:0},()=>[l.hasLabel?(e.openBlock(),e.createBlock(o,{key:0,id:t.id,class:e.normalizeClass(l.labelClass),text:t.label},null,8,["id","class","text"])):e.createCommentVNode("",!0)]):e.createCommentVNode("",!0),e.renderSlot(t.$slots,"default",{},()=>[e.createElementVNode("div",{class:e.normalizeClass([l.inputGroupClass,l.hasErrors&&l.inputErrorClass])},[e.renderSlot(t.$slots,"before"),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(`form-maker-input-${t.type}`),e.mergeProps({modelValue:l.value,"onUpdate:modelValue":r[0]||(r[0]=p=>l.value=p)},k(k({},t.$props),t.$attrs),{class:[t.type!=="checkbox"&&l.inputClass,l.hasErrors&&l.inputErrorClass],label:t.label}),null,16,["modelValue","class","label"])),e.renderSlot(t.$slots,"after")],2)]),e.renderSlot(t.$slots,"help",{},()=>[l.hasHelpText?(e.openBlock(),e.createBlock(m,{key:0,class:e.normalizeClass(l.helpTextClass),text:t.helpText},null,8,["class","text"])):e.createCommentVNode("",!0)]),e.renderSlot(t.$slots,"errors",{},()=>[l.hasErrors?(e.openBlock(),e.createBlock(u,{key:0,class:e.normalizeClass(l.errorClass),text:t.error},null,8,["class","text"])):e.createCommentVNode("",!0)])],2)}var O=a(D,[["render",N]]);const G={name:"CheckInput",mixins:[C],emits:["update:modelValue"],props:{label:{type:String,default:null}},setup(t,{emit:r}){const{options:n,label:l}=e.toRefs(t),s=e.computed(()=>n.value.length===0),i=e.computed(()=>t.modelValue),o=e.computed(()=>(Array.isArray(i.value)?i.value:[i.value]).filter(c=>!!c));return{fieldOptions:e.computed(()=>s.value?[{label:l.value,value:!0}]:n.value),isBinary:s,selectedOptions:o,handleClick:p=>{let c=[...o.value];c.indexOf(p)===-1?c.push(p):c=c.filter(h=>h!==p),s.value?r("update:modelValue",c.length>0):r("update:modelValue",c)}}}},L=["checked","value","onClick"];function A(t,r,n,l,s,i){return e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.fieldOptions,(o,m)=>(e.openBlock(),e.createElementBlock("div",{key:`option_${m}`},[e.createElementVNode("label",null,[e.createElementVNode("input",e.mergeProps(t.$props,{checked:l.selectedOptions.indexOf(o.value)!==-1,value:o.value,type:"checkbox",onClick:()=>l.handleClick(o.value)}),null,16,L),e.createTextVNode(" "+e.toDisplayString(o.label),1)])]))),128)}var R=a(G,[["render",A]]);const z={name:"FileInput",mixins:[C],emits:["update:modelValue"],setup(t,{emit:r}){return{handleFileSelect:l=>{if(l.target.files.length){const s=l.target.files[0];r("update:modelValue",s)}}}}};function P(t,r,n,l,s,i){return e.openBlock(),e.createElementBlock("input",e.mergeProps(t.$props,{type:"file",onChange:r[0]||(r[0]=(...o)=>l.handleFileSelect&&l.handleFileSelect(...o))}),null,16)}var U=a(z,[["render",P]]);const W={name:"FormMakerInputError",props:{text:{type:String,default:null}}};function H(t,r,n,l,s,i){return e.openBlock(),e.createElementBlock("div",null,e.toDisplayString(n.text),1)}var q=a(W,[["render",H]]);const J={name:"FormMakerInputHelp",props:{text:{type:String,default:null}}};function K(t,r,n,l,s,i){return e.openBlock(),e.createElementBlock("div",null,e.toDisplayString(n.text),1)}var Q=a(J,[["render",K]]);const X={name:"FormMakerInputLabel",props:{text:{type:String,default:null},id:{type:String,default:null}}},Y=["for"];function Z(t,r,n,l,s,i){return e.openBlock(),e.createElementBlock("label",{for:n.id},e.toDisplayString(n.text),9,Y)}var v=a(X,[["render",Z]]);const ee={name:"RadioInput",emits:["update:modelValue"],mixins:[C],props:{label:{type:String,default:null}},setup(t,{emit:r}){return{handleClick:l=>r("update:modelValue",l.target.value)}}},te=["checked","value"];function le(t,r,n,l,s,i){return e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.options,(o,m)=>(e.openBlock(),e.createElementBlock("div",{key:`option_${m}`},[e.createElementVNode("label",null,[e.createElementVNode("input",e.mergeProps(t.$props,{checked:o.value===t.modelValue,value:o.value,type:"radio",onChange:r[0]||(r[0]=(...u)=>l.handleClick&&l.handleClick(...u))}),null,16,te),e.createTextVNode(" "+e.toDisplayString(o.label),1)])]))),128)}var re=a(ee,[["render",le]]);const ne={name:"SelectInput",mixins:[C],setup(t,{emit:r}){const n=y(t,r),l=Object.keys(t.optionGroups).length>0;return{value:n,hasGroups:l}}},oe=["id","disabled","name","placeholder"],ae=["label"],se=["value"],ie=["value"];function pe(t,r,n,l,s,i){return e.withDirectives((e.openBlock(),e.createElementBlock("select",{id:t.id,"onUpdate:modelValue":r[0]||(r[0]=o=>l.value=o),disabled:t.disabled,name:t.name,placeholder:t.placeholder},[l.hasGroups?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(t.optionGroups,(o,m)=>(e.openBlock(),e.createElementBlock("optgroup",{key:`optGroup_${m}`,label:m},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o,(u,p)=>(e.openBlock(),e.createElementBlock("option",{key:`option_${p}`,value:p},e.toDisplayString(u),9,se))),128))],8,ae))),128)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(t.options,(o,m)=>(e.openBlock(),e.createElementBlock("option",{key:`option_${m}`,value:o.value},e.toDisplayString(o.label),9,ie))),128))],8,oe)),[[e.vModelSelect,l.value]])}var me=a(ne,[["render",pe]]);const ce={name:"TextAreaInput",mixins:[C],setup(t,{emit:r}){return{value:y(t,r)}}},de=["id","disabled","name","placeholder"];function ue(t,r,n,l,s,i){return e.withDirectives((e.openBlock(),e.createElementBlock("textarea",{id:t.id,"onUpdate:modelValue":r[0]||(r[0]=o=>l.value=o),disabled:t.disabled,name:t.name,placeholder:t.placeholder},null,8,de)),[[e.vModelText,l.value]])}var fe=a(ce,[["render",ue]]);const ke={name:"TextInput",mixins:[C],setup(t,{emit:r}){return{value:y(t,r)}}},Ce=["type"];function he(t,r,n,l,s,i){return e.withDirectives((e.openBlock(),e.createElementBlock("input",e.mergeProps({"onUpdate:modelValue":r[0]||(r[0]=o=>l.value=o),type:t.type},t.$props),null,16,Ce)),[[e.vModelDynamic,l.value]])}var d=a(ke,[["render",he]]);const _={classes:{"form-row":"form-maker-row","form-column":"form-maker-column","form-label":"form-maker-label","input-group":"form-maker-input-group","input-wrapper":"form-maker-input-wrapper","input-error":"form-maker-input-error",input:"form-maker-input",error:"form-maker-error","help-text":"form-maker-help-text","submit-button":"form-maker-submit"},components:{"form-maker-input-color":d,"form-maker-input-date":d,"form-maker-input-email":d,"form-maker-input-month":d,"form-maker-input-number":d,"form-maker-input-password":d,"form-maker-input-search":d,"form-maker-input-tel":d,"form-maker-input-time":d,"form-maker-input-text":d,"form-maker-input-url":d,"form-maker-input-week":d,"form-maker-input-range":d,"form-maker-input-file":U,"form-maker-input-textarea":fe,"form-maker-input-select":me,"form-maker-input-checkbox":R,"form-maker-input-radio":re,"form-maker-label":v,"form-maker-help":Q,"form-maker-error":q}};return{install:(t,r={})=>{const n={classes:k(k({},_.classes),r.classes),components:k(k({},_.components),r.components)};t.component("FormMaker",I),t.component("FormMakerInput",O),Object.keys(n.classes).forEach(l=>{t.provide(l,n.classes[l])}),Object.keys(n.components).forEach(l=>{t.component(l,n.components[l])})}}});
1
+ var ae=Object.defineProperty,pe=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var me=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var M=(e,i,k)=>i in e?ae(e,i,{enumerable:!0,configurable:!0,writable:!0,value:k}):e[i]=k,y=(e,i)=>{for(var k in i||(i={}))me.call(i,k)&&M(e,k,i[k]);if(N)for(var k of N(i))ce.call(i,k)&&M(e,k,i[k]);return e},E=(e,i)=>pe(e,ie(i));(function(e,i){typeof exports=="object"&&typeof module!="undefined"?module.exports=i(require("vue")):typeof define=="function"&&define.amd?define(["vue"],i):(e=typeof globalThis!="undefined"?globalThis:e||self,e.FormMaker=i(e.Vue))})(this,function(e){"use strict";const i=["onSubmit"],k=e.createTextVNode(" Loading... "),O={key:0},A=["disabled"],G={props:{loading:{type:Boolean,default:!1},hasActions:{type:Boolean,default:!0},modelValue:{type:Object,default:()=>({})},fields:{type:Array,default:()=>[]},hideDivider:{type:Boolean,default:!1},rowClass:{type:String,default:null},columnClass:{type:String,default:null},labelClass:{type:String,default:null},inputGroupClass:{type:String,default:null},inputWrapperClass:{type:String,default:null},inputErrorClass:{type:String,default:null},inputClass:{type:String,default:null},errorClass:{type:String,default:null},helpTextClass:{type:String,default:null},submitButtonClass:{type:String,default:null},submitButtonText:{type:String,default:"Submit"}},emits:["submit","update:modelValue"],setup(l,{emit:o}){const r=l,t=()=>o("submit"),s=e.computed(()=>r.fields.length>0?r.fields.map(c=>{let w=c;return Array.isArray(c)||(w=[c]),w.map(g=>g.id?g:E(y({},g),{id:`formMaker_${new Date().getTime()}_${g.name}`}))}):Object.keys(r.modelValue).map(c=>[{name:c,label:c,id:`formMaker_${c}`}])),{rowClass:a,columnClass:n,labelClass:B,inputGroupClass:u,inputWrapperClass:C,inputErrorClass:h,inputClass:p,errorClass:b,helpTextClass:S,submitButtonClass:m,modelValue:_}=e.toRefs(r);e.provide("labelClass",B.value||e.inject("form-label")),e.provide("inputGroupClass",u.value||e.inject("input-group")),e.provide("inputWrapperClass",C.value||e.inject("input-wrapper")),e.provide("inputErrorClass",h.value||e.inject("input-error")),e.provide("inputClass",p.value||e.inject("input")),e.provide("errorClass",b.value||e.inject("error")),e.provide("helpTextClass",S.value||e.inject("help-text"));const j=a.value||e.inject("form-row"),x=n.value||e.inject("form-column"),T=m.value||e.inject("submit-button");return(c,w)=>{const g=e.resolveComponent("form-maker-input");return e.openBlock(),e.createElementBlock("form",{class:"form-maker",onSubmit:e.withModifiers(t,["prevent"])},[l.loading?e.renderSlot(c.$slots,"loading",{key:0},()=>[k]):e.createCommentVNode("",!0),e.renderSlot(c.$slots,"default",{},()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(s),(oe,D)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(e.unref(j)),key:`fieldRow_${D}`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(oe,($,ne)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([e.unref(x),$.columnClass]),key:`field_${D}_${ne}`},[e.renderSlot(c.$slots,`${$.name}`,{field:$},()=>[e.createVNode(g,e.mergeProps({modelValue:e.unref(_)[$.name],"onUpdate:modelValue":se=>e.unref(_)[$.name]=se},$),null,16,["modelValue","onUpdate:modelValue"])])],2))),128))],2))),128))]),e.renderSlot(c.$slots,"extra"),e.renderSlot(c.$slots,"divider",{},()=>[l.hasActions&&!l.hideDivider?(e.openBlock(),e.createElementBlock("hr",O)):e.createCommentVNode("",!0)]),l.hasActions?e.renderSlot(c.$slots,"actions",{key:1},()=>[e.renderSlot(c.$slots,"submit-button",{},()=>[e.createElementVNode("button",{class:e.normalizeClass(e.unref(T)),disabled:l.loading,type:"submit"},e.toDisplayString(l.submitButtonText),11,A)]),e.renderSlot(c.$slots,"extra-buttons")]):e.createCommentVNode("",!0)],40,i)}}},V=(l,o,r="modelValue")=>e.computed({get:()=>l[r],set:t=>o(`update:${r}`,t)}),L=()=>{const l=e.inject("labelClass",null),o=e.inject("inputClass",null),r=e.inject("inputWrapperClass",null),t=e.inject("inputGroupClass",null),s=e.inject("inputErrorClass",null),a=e.inject("errorClass",null),n=e.inject("helpTextClass",null);return{labelClass:l,inputClass:o,inputWrapperClass:r,inputGroupClass:t,inputErrorClass:s,errorClass:a,helpTextClass:n}},R=l=>{const{label:o,error:r,helpText:t}=e.toRefs(l),s=e.computed(()=>Boolean(r.value)),a=e.computed(()=>Boolean(o.value)),n=e.computed(()=>Boolean(t.value));return{hasErrors:s,hasLabel:a,hasHelpText:n}},d={emits:["update:modelValue"],props:{loading:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},modelValue:{default:null},error:{type:String,default:null},helpText:{type:String,default:null},id:{type:String,default:null},label:{type:String,default:null},name:{type:String,default:null},placeholder:{type:String,default:null},type:{type:String,default:"text"}}},z=Object.assign({inheritAttrs:!1},{props:d.props,emits:d.emits,setup(l,{emit:o}){const r=l,t=V(r,o),{labelClass:s,inputClass:a,inputWrapperClass:n,inputGroupClass:B,inputErrorClass:u,errorClass:C,helpTextClass:h}=L(),{hasErrors:p,hasLabel:b,hasHelpText:S}=R(r);return(m,_)=>{const j=e.resolveComponent("form-maker-label"),x=e.resolveComponent("form-maker-help"),T=e.resolveComponent("form-maker-error");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([e.unref(p)&&e.unref(u),e.unref(n)])},[m.type!=="checkbox"?e.renderSlot(m.$slots,"label",{key:0},()=>[e.unref(b)?(e.openBlock(),e.createBlock(j,{key:0,id:m.id,class:e.normalizeClass(e.unref(s)),text:m.label},null,8,["id","class","text"])):e.createCommentVNode("",!0)]):e.createCommentVNode("",!0),e.renderSlot(m.$slots,"default",{},()=>[e.createElementVNode("div",{class:e.normalizeClass([e.unref(B),e.unref(p)&&e.unref(u)])},[e.renderSlot(m.$slots,"before"),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(`form-maker-input-${m.type}`),e.mergeProps({modelValue:e.unref(t),"onUpdate:modelValue":_[0]||(_[0]=c=>e.isRef(t)?t.value=c:null)},y(y({},m.$props),m.$attrs),{class:[m.type!=="checkbox"&&e.unref(a),e.unref(p)&&e.unref(u)],label:m.label}),null,16,["modelValue","class","label"])),e.renderSlot(m.$slots,"after")],2)]),e.renderSlot(m.$slots,"help",{},()=>[e.unref(S)?(e.openBlock(),e.createBlock(x,{key:0,class:e.normalizeClass(e.unref(h)),text:m.helpText},null,8,["class","text"])):e.createCommentVNode("",!0)]),e.renderSlot(m.$slots,"errors",{},()=>[e.unref(p)?(e.openBlock(),e.createBlock(T,{key:0,class:e.normalizeClass(e.unref(C)),text:m.error},null,8,["class","text"])):e.createCommentVNode("",!0)])],2)}}}),P=["checked","value","onClick"],U={props:E(y({},d.props),{options:{type:Array,default:()=>[]}}),emits:d.emits,setup(l,{emit:o}){const r=l,{options:t,label:s}=e.toRefs(r),a=e.computed(()=>t.value.length===0),n=e.computed(()=>r.modelValue),B=e.computed(()=>(Array.isArray(n.value)?n.value:[n.value]).filter(p=>!!p)),u=e.computed(()=>a.value?[{label:s.value,value:!0}]:t.value),C=h=>{let p=[...B.value];p.indexOf(h)===-1?p.push(h):p=p.filter(b=>b!==h),a.value?o("update:modelValue",p.length>0):o("update:modelValue",p)};return(h,p)=>(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(u),(b,S)=>(e.openBlock(),e.createElementBlock("div",{key:`option_${S}`},[e.createElementVNode("label",null,[e.createElementVNode("input",e.mergeProps(h.$props,{checked:e.unref(B).indexOf(b.value)!==-1,value:b.value,type:"checkbox",onClick:()=>C(b.value)}),null,16,P),e.createTextVNode(" "+e.toDisplayString(b.label),1)])]))),128))}},W={props:d.props,emits:d.emits,setup(l,{emit:o}){const r=t=>{if(t.target.files.length){const s=t.target.files[0];o("update:modelValue",s)}};return(t,s)=>(e.openBlock(),e.createElementBlock("input",e.mergeProps(t.$props,{type:"file",onChange:r}),null,16))}},I={props:{text:{type:String,default:null}},setup(l){return(o,r)=>(e.openBlock(),e.createElementBlock("div",null,e.toDisplayString(l.text),1))}},H={props:{text:{type:String,default:null}},setup(l){return(o,r)=>(e.openBlock(),e.createElementBlock("div",null,e.toDisplayString(l.text),1))}},q=["for"],J={props:{text:{type:String,default:null},id:{type:String,default:null}},setup(l){return(o,r)=>(e.openBlock(),e.createElementBlock("label",{for:l.id},e.toDisplayString(l.text),9,q))}},K=["checked","value"],Q={props:E(y({},d.props),{options:{type:Array,default:()=>[]}}),emits:d.emits,setup(l,{emit:o}){const r=t=>o("update:modelValue",t.target.value);return(t,s)=>(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.options,(a,n)=>(e.openBlock(),e.createElementBlock("div",{key:`option_${n}`},[e.createElementVNode("label",null,[e.createElementVNode("input",e.mergeProps(t.$props,{checked:a.value===t.modelValue,value:a.value,type:"radio",onChange:r}),null,16,K),e.createTextVNode(" "+e.toDisplayString(a.label),1)])]))),128))}},X=["id","disabled","name","placeholder"],Y=["label"],Z=["value"],v=["value"],ee={props:E(y({},d.props),{options:{type:Array,default:()=>[]},optionGroups:{type:Object,default:()=>({})}}),emits:d.emits,setup(l,{emit:o}){const r=l,t=V(r,o),s=Object.keys(r.optionGroups).length>0,a=e.computed(()=>r.options.map(n=>typeof n=="object"?n:{label:n,value:n}));return console.log(a.value),(n,B)=>e.withDirectives((e.openBlock(),e.createElementBlock("select",{id:n.id,"onUpdate:modelValue":B[0]||(B[0]=u=>e.isRef(t)?t.value=u:null),disabled:n.disabled,name:n.name,placeholder:n.placeholder},[s?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(l.optionGroups,(u,C)=>(e.openBlock(),e.createElementBlock("optgroup",{key:`optGroup_${C}`,label:C},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(u,(h,p)=>(e.openBlock(),e.createElementBlock("option",{key:`option_${p}`,value:p},e.toDisplayString(h),9,Z))),128))],8,Y))),128)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(e.unref(a),(u,C)=>(e.openBlock(),e.createElementBlock("option",{key:`option_${C}`,value:u.value},e.toDisplayString(u.label),9,v))),128))],8,X)),[[e.vModelSelect,e.unref(t)]])}},te=["id","disabled","name","placeholder"],le={props:d.props,emits:d.emits,setup(l,{emit:o}){const t=V(l,o);return(s,a)=>e.withDirectives((e.openBlock(),e.createElementBlock("textarea",{id:s.id,"onUpdate:modelValue":a[0]||(a[0]=n=>e.isRef(t)?t.value=n:null),disabled:s.disabled,name:s.name,placeholder:s.placeholder},null,8,te)),[[e.vModelText,e.unref(t)]])}},re=["type"],f={props:d.props,emits:d.emits,setup(l,{emit:o}){const t=V(l,o);return(s,a)=>e.withDirectives((e.openBlock(),e.createElementBlock("input",e.mergeProps({"onUpdate:modelValue":a[0]||(a[0]=n=>e.isRef(t)?t.value=n:null),type:s.type},s.$props),null,16,re)),[[e.vModelDynamic,e.unref(t)]])}},F={classes:{"form-row":"form-maker-row","form-column":"form-maker-column","form-label":"form-maker-label","input-group":"form-maker-input-group","input-wrapper":"form-maker-input-wrapper","input-error":"form-maker-input-error",input:"form-maker-input",error:"form-maker-error","help-text":"form-maker-help-text","submit-button":"form-maker-submit"},components:{"form-maker-input-color":f,"form-maker-input-date":f,"form-maker-input-email":f,"form-maker-input-month":f,"form-maker-input-number":f,"form-maker-input-password":f,"form-maker-input-search":f,"form-maker-input-tel":f,"form-maker-input-time":f,"form-maker-input-text":f,"form-maker-input-url":f,"form-maker-input-week":f,"form-maker-input-range":f,"form-maker-input-file":W,"form-maker-input-textarea":le,"form-maker-input-select":ee,"form-maker-input-checkbox":U,"form-maker-input-radio":Q,"form-maker-label":J,"form-maker-help":H,"form-maker-error":I}};return{install:(l,o={})=>{const r={classes:y(y({},F.classes),o.classes),components:y(y({},F.components),o.components)};l.component("FormMaker",G),l.component("FormMakerInput",z),Object.keys(r.classes).forEach(t=>{l.provide(t,r.classes[t])}),Object.keys(r.components).forEach(t=>{l.component(t,r.components[t])})}}});