inertia-bootstrap-forms 1.0.33 → 1.0.35

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.d.ts CHANGED
@@ -1,4 +1,100 @@
1
- // index.d.ts
1
+ import { defineComponent } from 'vue';
2
+
3
+ // Import کامپوننت‌ها
4
+ import AmountInput from './src/AmountInput.vue';
5
+ import CaptchaInput from './src/CaptchaInput.vue';
6
+ import CheckboxButtonInput from './src/CheckboxButtonInput.vue';
7
+ import CheckboxInput from './src/CheckboxInput.vue';
8
+ import CheckboxToggle from './src/CheckboxToggle.vue';
9
+ import EditorInput from './src/EditorInput.vue';
10
+ import EmailInput from './src/EmailInput.vue';
11
+ import FileInput from './src/FileInput.vue';
12
+ import SimpleUploader from './src/SimpleUploader.vue';
13
+ import FormContainer from './src/FormContainer.vue';
14
+ import FormLabel from './src/FormLabel.vue';
15
+ import GroupControl from './src/GroupControl.vue';
16
+ import LocationInput from './src/LocationInput.vue';
17
+ import MobileInput from './src/MobileInput.vue';
18
+ import MultiQuantityInput from './src/MultiQuantityInput.vue';
19
+ import PasswordInput from './src/PasswordInput.vue';
20
+ import PersianDatePickerInput from './src/PersianDatePickerInput.vue';
21
+ import QuantityInput from './src/QuantityInput.vue';
22
+ import SecondarySubmitButton from './src/SecondarySubmitButton.vue';
23
+ import Select2Input from './src/Select2Input.vue';
24
+ import StarRatingInput from './src/StarRatingInput.vue';
25
+ import SubmitButton from './src/SubmitButton.vue';
26
+ import TelInput from './src/TelInput.vue';
27
+ import TextAreaInput from './src/TextAreaInput.vue';
28
+ import TextInput from './src/TextInput.vue';
29
+ import DropzoneInput from './src/DropzoneInput.vue';
30
+ import { countryCodes } from './src/countryCodes';
31
+
32
+ // Export تکی
33
+ export {
34
+ AmountInput,
35
+ CaptchaInput,
36
+ CheckboxButtonInput,
37
+ CheckboxInput,
38
+ CheckboxToggle,
39
+ countryCodes,
40
+ EditorInput,
41
+ EmailInput,
42
+ DropzoneInput,
43
+ FileInput,
44
+ SimpleUploader,
45
+ FormContainer,
46
+ FormLabel,
47
+ GroupControl,
48
+ LocationInput,
49
+ MobileInput,
50
+ MultiQuantityInput,
51
+ PasswordInput,
52
+ PersianDatePickerInput,
53
+ QuantityInput,
54
+ SecondarySubmitButton,
55
+ Select2Input,
56
+ StarRatingInput,
57
+ SubmitButton,
58
+ TelInput,
59
+ TextAreaInput,
60
+ TextInput,
61
+ Quantity,
62
+ File,
63
+ };
64
+
65
+ // Export پیش‌فرض برای import * as
66
+ const Vue3FormComponents = {
67
+ AmountInput,
68
+ CaptchaInput,
69
+ CheckboxButtonInput,
70
+ CheckboxInput,
71
+ CheckboxToggle,
72
+ countryCodes,
73
+ EditorInput,
74
+ DropzoneInput,
75
+ EmailInput,
76
+ FileInput,
77
+ SimpleUploader,
78
+ FormContainer,
79
+ FormLabel,
80
+ GroupControl,
81
+ LocationInput,
82
+ MobileInput,
83
+ MultiQuantityInput,
84
+ PasswordInput,
85
+ PersianDatePickerInput,
86
+ QuantityInput,
87
+ SecondarySubmitButton,
88
+ Select2Input,
89
+ StarRatingInput,
90
+ SubmitButton,
91
+ TelInput,
92
+ TextAreaInput,
93
+ TextInput,
94
+ };
95
+
96
+ export default Vue3FormComponents;
97
+
2
98
  import { DefineComponent } from 'vue';
3
99
 
4
100
  export const AmountInput: DefineComponent<{}, {}, any>;
@@ -9,10 +105,9 @@ export const CheckboxToggle: DefineComponent<{}, {}, any>;
9
105
  export const countryCodes: any;
10
106
  export const EditorInput: DefineComponent<{}, {}, any>;
11
107
  export const EmailInput: DefineComponent<{}, {}, any>;
12
- export const FileInput: DefineComponent<{
13
-
14
- }, {}, any>;
15
- export const FileUploader: DefineComponent<{}, {}, any>;
108
+ export const DropzoneInput: DefineComponent<{}, {}, any>;
109
+ export const FileInput: DefineComponent<{}, {}, any>;
110
+ export const SimpleUploader: DefineComponent<{}, {}, any>;
16
111
  export const FormContainer: DefineComponent<{}, {}, any>;
17
112
  export const FormLabel: DefineComponent<{}, {}, any>;
18
113
  export const GroupControl: DefineComponent<{}, {}, any>;
@@ -30,18 +125,19 @@ export const TelInput: DefineComponent<{}, {}, any>;
30
125
  export const TextAreaInput: DefineComponent<{}, {}, any>;
31
126
  export const TextInput: DefineComponent<{}, {}, any>;
32
127
 
33
- // این قسمت برای اینکه import * as ... هم ساپورت بشه
128
+ // Export پیش‌فرض
34
129
  declare const Vue3FormComponents: {
35
130
  AmountInput: typeof AmountInput;
36
131
  CaptchaInput: typeof CaptchaInput;
37
132
  CheckboxButtonInput: typeof CheckboxButtonInput;
38
133
  CheckboxInput: typeof CheckboxInput;
39
134
  CheckboxToggle: typeof CheckboxToggle;
135
+ DropzoneInput: typeof DropzoneInput;
40
136
  countryCodes: typeof countryCodes;
41
137
  EditorInput: typeof EditorInput;
42
138
  EmailInput: typeof EmailInput;
43
139
  FileInput: typeof FileInput;
44
- FileUploader: typeof FileUploader;
140
+ SimpleUploader: typeof SimpleUploader;
45
141
  FormContainer: typeof FormContainer;
46
142
  FormLabel: typeof FormLabel;
47
143
  GroupControl: typeof GroupControl;
@@ -58,6 +154,7 @@ declare const Vue3FormComponents: {
58
154
  TelInput: typeof TelInput;
59
155
  TextAreaInput: typeof TextAreaInput;
60
156
  TextInput: typeof TextInput;
157
+ Quantity: typeof QuantityInput;
61
158
  };
62
159
 
63
160
  export default Vue3FormComponents;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-bootstrap-forms",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "Create bootstrap forms with inertia and twitter bootstrap",
5
5
  "main": "dist/inertia-bootstrap-forms.cjs.js",
6
6
  "module": "dist/inertia-bootstrap-forms.es.js",
@@ -46,10 +46,12 @@
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@inertiajs/vue3": ">2.0",
49
+ "dropzone": "^6.0.0-beta.2",
49
50
  "vue": "^3.0"
50
51
  },
51
52
  "devDependencies": {
52
53
  "sass-embedded": "^1.89.2",
54
+ "dropzone": "^6.0.0-beta.2",
53
55
  "vite": "^5"
54
56
  },
55
57
  "bugs": {
@@ -1,8 +1,8 @@
1
1
  <script>
2
2
  import {InputGroup, InputGroupText} from 'vue3-bootstrap-components';
3
- import {inject} from "vue";
3
+ import {defineComponent, inject} from "vue";
4
4
 
5
- export default {
5
+ export default defineComponent({
6
6
  components: {InputGroup, InputGroupText},
7
7
  props: {
8
8
  name: {
@@ -40,7 +40,7 @@ export default {
40
40
  this.$emit('update:modelValue', parseFloat(this.$number.toEnglish(event.detail?.unmasked)));
41
41
  }
42
42
  }
43
- }
43
+ })
44
44
  </script>
45
45
  <template>
46
46
  <InputGroup>
@@ -1,7 +1,8 @@
1
1
  <script>
2
2
  import TextInput from "./TextInput.vue";
3
+ import {defineComponent} from "vue";
3
4
 
4
- export default {
5
+ export default defineComponent({
5
6
  components: {TextInput},
6
7
  props: {
7
8
  name: {
@@ -56,7 +57,7 @@ export default {
56
57
  src: this.url + Math.random(),
57
58
  };
58
59
  }
59
- };
60
+ });
60
61
 
61
62
  </script>
62
63
  <template>
@@ -1,7 +1,7 @@
1
1
  <script>
2
- import {inject} from "vue";
2
+ import {defineComponent, inject} from "vue";
3
3
 
4
- export default {
4
+ export default defineComponent({
5
5
  emits: ['change'],
6
6
  props: {
7
7
  name: {
@@ -43,7 +43,7 @@ export default {
43
43
 
44
44
  return {form};
45
45
  },
46
- }
46
+ })
47
47
  </script>
48
48
  <template>
49
49
  <label class="btn-label" :for="form.getID(name)+(id || value)" :class="{'active': (form[name] === value || form[name] === true)}">
@@ -1,7 +1,7 @@
1
1
  <script>
2
- import {computed, inject} from "vue";
2
+ import {computed, defineComponent, inject} from "vue";
3
3
 
4
- export default {
4
+ export default defineComponent({
5
5
  props: {
6
6
  name: {
7
7
  type: String,
@@ -52,7 +52,7 @@ export default {
52
52
 
53
53
  return {modelValue, form, group};
54
54
  },
55
- }
55
+ })
56
56
  </script>
57
57
  <template>
58
58
  <div class="form-check">
@@ -1,7 +1,7 @@
1
1
  <script>
2
- import {computed, inject} from "vue";
2
+ import {computed, defineComponent, inject} from "vue";
3
3
 
4
- export default {
4
+ export default defineComponent({
5
5
  props: {
6
6
  name: {
7
7
  type: String,
@@ -30,6 +30,9 @@ export default {
30
30
  computed: {
31
31
  inputID() {
32
32
  return this.form.getID(this) + (this.value || '');
33
+ },
34
+ selectedValue(){
35
+ return (typeof this.modelValue == 'object') ? Object.values(this.modelValue) : (this.modelValue ? [this.modelValue] : null)
33
36
  }
34
37
  },
35
38
  setup(props) {
@@ -56,10 +59,10 @@ export default {
56
59
 
57
60
  return {modelValue, form, group};
58
61
  },
59
- }
62
+ })
60
63
  </script>
61
64
  <template>
62
- <label class="form-check-toggle" :class="{'form-check-toggle--active': (Array.isArray(modelValue) ? modelValue : [modelValue]).include(value)}" :for="inputID">
65
+ <label class="form-check-toggle" :class="{'form-check-toggle--active': (selectedValue || []).includes(value)}" :for="inputID">
63
66
  <input
64
67
  :name="name + (group ? '_' + group?.name + '-'+group?.groupID : '')"
65
68
  :id="inputID"
@@ -0,0 +1,108 @@
1
+ <script setup>
2
+ import { computed, inject, ref, onMounted } from "vue";
3
+ import Dropzone from "dropzone";
4
+ import "dropzone/dist/basic.css";
5
+ import "dropzone/dist/dropzone.css";
6
+
7
+ const props = defineProps({
8
+ name: {
9
+ type: String,
10
+ required: true,
11
+ },
12
+ multiple: {
13
+ type: Boolean,
14
+ default: false,
15
+ },
16
+ modelValue: String,
17
+ url: { type: String, default: "/upload" },
18
+ options: { type: Object, default: () => ({}) },
19
+ });
20
+ const emit = defineEmits(["update:modelValue"]);
21
+
22
+ const form = inject("form", {
23
+ value: {},
24
+ errors: {},
25
+ getID: n => n,
26
+ });
27
+
28
+ const group = inject("group", null);
29
+
30
+ const dz = ref(null);
31
+ const dropzone = ref(null);
32
+
33
+ const modelValue = computed({
34
+ get() {
35
+ return group?.value?.name
36
+ ? group.value.getData(props.name)
37
+ : form.value[props.name];
38
+ },
39
+ set(val) {
40
+ if (group?.value?.name) {
41
+ group.value.setData(props.name, val);
42
+ } else {
43
+ form.value[props.name] = val;
44
+ }
45
+ emit("update:modelValue", val);
46
+ }
47
+ });
48
+
49
+ onMounted(() => {
50
+ dropzone.value = new Dropzone(dz.value, {
51
+ url: props.url,
52
+ addRemoveLinks: true,
53
+ maxFiles: props.multiple ? null : 1,
54
+ ...props.options,
55
+ });
56
+
57
+ dropzone.value.on("error", (file, response) => {
58
+ let message = "خطا در آپلود";
59
+
60
+ if (typeof response === "string") {
61
+ message = response;
62
+ }
63
+
64
+ if (response?.message) {
65
+ message = response.message;
66
+ }
67
+
68
+ file.previewElement.classList.add("dz-error");
69
+ const err = file.previewElement.querySelector("[data-dz-errormessage]");
70
+ if (err) err.textContent = message;
71
+ });
72
+
73
+ dropzone.value.on("success", (file, response) => {
74
+ const result = response.data ?? response;
75
+
76
+ if(props.multiple){
77
+ modelValue.value = [...(modelValue.value || []), result];
78
+ }else{
79
+ modelValue.value = result;
80
+ }
81
+ });
82
+
83
+ dropzone.value.on("removedfile", async (file) => {
84
+ let data = file.xhr.response;
85
+ if (!data) return;
86
+
87
+ try {
88
+ data = JSON.parse(data);
89
+ modelValue.value = (modelValue.value || []).filter(f => f.path !== data.path);
90
+
91
+ await fetch(props.url, {
92
+ method: "DELETE",
93
+ headers: {
94
+ "Content-Type": "application/json",
95
+ 'Accept': 'application/json',
96
+ },
97
+ body: data.path
98
+ });
99
+ } catch (e) {
100
+ console.error("حذف فایل در سرور با خطا مواجه شد", e);
101
+ }
102
+ });
103
+ });
104
+ </script>
105
+
106
+ <template>
107
+ <div class="inertia-dropzone-input dropzone" ref="dz"></div>
108
+ </template>
@@ -1,8 +1,8 @@
1
1
  <script>
2
2
  import Editor from '@tinymce/tinymce-vue';
3
- import {inject} from "vue";
3
+ import {computed, defineComponent, inject} from "vue";
4
4
 
5
- export default {
5
+ export default defineComponent({
6
6
  components: {Editor},
7
7
  props: {
8
8
  name: {
@@ -27,27 +27,38 @@ export default {
27
27
  },
28
28
  },
29
29
  setup(props) {
30
- let form = inject('form');
30
+ let form = inject('form', {
31
+ errors: {},
32
+ getID(name) {
33
+ return name;
34
+ }
35
+ });
36
+ let group = inject('group', {});
31
37
 
32
- if (form === undefined) {
33
- form = {
34
- errors: {},
35
- getID(name) {
36
- }
37
- };
38
+ const modelValue = computed({
39
+ get() {
40
+ return (group.value && form.value[group.value.name]) ? group.value?.getData(props.name) : form.value[props.name];
41
+ },
42
+ set(value) {
43
+ if (group?.value?.name) {
44
+ group.value.setData(props.name, value);
45
+ } else {
46
+ form.value[props.name] = value;
47
+ }
38
48
  }
49
+ });
39
50
 
40
- return {form};
51
+ return {modelValue, form, group};
41
52
  },
42
53
  emits: ['update:modelValue'],
43
- }
54
+ })
44
55
  </script>
45
56
 
46
57
  <template>
47
58
  <Editor
48
59
  api-key="tbws10u99swxhai03qolxykukvqw99jd4nw9q8z34aocvc4r"
49
60
  tinymce-script-src="/js/tinymce/tinymce.min.js"
50
- v-model="form[name]"
61
+ v-model="modelValue"
51
62
  :init="{
52
63
  base_url: '/js/tinymce/',
53
64
  disabled: false,
@@ -1,7 +1,8 @@
1
1
  <script>
2
2
  import TextInput from "./TextInput.vue";
3
+ import {defineComponent} from "vue";
3
4
 
4
- export default {
5
+ export default defineComponent({
5
6
  components: {
6
7
  TextInput
7
8
  },
@@ -12,7 +13,7 @@ export default {
12
13
  required: true,
13
14
  },
14
15
  },
15
- }
16
+ })
16
17
  </script>
17
18
  <template>
18
19
  <TextInput
package/src/FileInput.vue CHANGED
@@ -1,7 +1,7 @@
1
1
  <script>
2
- import {inject} from "vue";
2
+ import {defineComponent, inject} from "vue";
3
3
 
4
- export default {
4
+ export default defineComponent({
5
5
  props: {
6
6
  modelValue: '',
7
7
  name: {
@@ -99,7 +99,7 @@ export default {
99
99
  files: [],
100
100
  }
101
101
  }
102
- }
102
+ })
103
103
  </script>
104
104
  <template>
105
105
  <div class="file-input-uploader">
@@ -1,9 +1,9 @@
1
1
  <script>
2
2
  import {useForm} from "@inertiajs/vue3";
3
- import {computed, reactive, toRef} from "vue";
3
+ import {computed, defineComponent, reactive, toRef} from "vue";
4
4
  import {Alert} from "vue3-bootstrap-components";
5
5
 
6
- export default {
6
+ export default defineComponent({
7
7
  components: {Alert},
8
8
  emits: ['submit', 'reset', 'onStart', 'onFinish', 'onSuccess', 'change'],
9
9
  props: {
@@ -34,7 +34,11 @@ export default {
34
34
  setup(props) {
35
35
  const formEl = toRef('formEl');
36
36
  const formData = reactive(props.modelValue);
37
- const form = useForm(formData);
37
+ const form = useForm({
38
+ hasMessage: false,
39
+ successMessage: null,
40
+ ...formData
41
+ });
38
42
 
39
43
  form.getID = function (el) {
40
44
  if (typeof el === String) {
@@ -58,6 +62,8 @@ export default {
58
62
  isDirty,
59
63
  errors,
60
64
  hasErrors,
65
+ hasMessage,
66
+ successMessage,
61
67
  processing,
62
68
  progress,
63
69
  wasSuccessful,
@@ -101,7 +107,10 @@ export default {
101
107
  }).submit(this.method.toString(), this.url, {
102
108
  only: this.only,
103
109
  onStart: () => {
104
- this.$emit('onStart');
110
+ this.form.hasMessage = false;
111
+ this.form.successMessage = null;
112
+
113
+ this.$emit('onStart');
105
114
  this.form.clearErrors();
106
115
  },
107
116
  onFinish: (data) => {
@@ -111,6 +120,12 @@ export default {
111
120
  },
112
121
  onSuccess: (data) => {
113
122
  this.reset();
123
+
124
+ if(data?.props?.message){
125
+ this.form.hasMessage = true;
126
+ this.form.successMessage = data?.props?.message;
127
+ }
128
+
114
129
  this.$emit('onSuccess', data);
115
130
  }
116
131
  });
@@ -118,7 +133,7 @@ export default {
118
133
  }
119
134
  },
120
135
  expose: ['submit', 'reset'],
121
- }
136
+ })
122
137
 
123
138
  </script>
124
139
 
@@ -137,6 +152,9 @@ export default {
137
152
  </ul>
138
153
  </Alert>
139
154
  </slot>
155
+ <slot name="message" v-if="form.hasMessage" :form="form">
156
+ <Alert type="success" v-html="form.successMessage"></Alert>
157
+ </slot>
140
158
  <slot :form="form" :submit="submit"/>
141
159
  </form>
142
160
  </template>
package/src/FormLabel.vue CHANGED
@@ -1,11 +1,13 @@
1
1
  <script>
2
- export default {
2
+ import {defineComponent} from "vue";
3
+
4
+ export default defineComponent({
3
5
  props: {
4
6
  default: false,
5
7
  required: false,
6
8
  },
7
9
  emits: ['update:modelValue'],
8
- }
10
+ })
9
11
  </script>
10
12
 
11
13
  <template>
@@ -1,7 +1,7 @@
1
1
  <script>
2
- import {computed, inject} from "vue";
2
+ import {computed, defineComponent, inject} from "vue";
3
3
 
4
- export default {
4
+ export default defineComponent({
5
5
  props: {
6
6
  name: {
7
7
  type: String,
@@ -58,7 +58,7 @@ export default {
58
58
  groupID: '0',
59
59
  };
60
60
  }
61
- }
61
+ })
62
62
  </script>
63
63
  <template>
64
64
  <div class="form-control-group" :data-group-id="groupID" ref="groupEl">
@@ -1,9 +1,10 @@
1
1
  <script>
2
2
  import "leaflet/dist/leaflet.css";
3
+ import "./css/location.scss";
3
4
  import {LMap, LTileLayer, LMarker} from "@vue-leaflet/vue-leaflet";
4
- import {inject} from "vue";
5
+ import {defineComponent, inject} from "vue";
5
6
 
6
- export default {
7
+ export default defineComponent({
7
8
  name: 'LocationInput',
8
9
  components: {
9
10
  LMap, LTileLayer, LMarker
@@ -60,7 +61,7 @@ export default {
60
61
  };
61
62
  },
62
63
 
63
- }
64
+ })
64
65
  </script>
65
66
  <template>
66
67
  <div class="location-map-container"
@@ -75,50 +76,3 @@ export default {
75
76
  </l-map>
76
77
  </div>
77
78
  </template>
78
- <style>
79
- .location-map-container {
80
- position: relative;
81
- width: 100%;
82
- height: 300px;
83
- overflow: hidden;
84
- border-radius: var(--bs-border-radius);
85
- }
86
-
87
- .location-map-container.is-invalid {
88
- border: 1px solid var(--bs-form-invalid-border-color);
89
- }
90
-
91
- .location-map-container[disabled],
92
- .location-map-container.disabled:before {
93
- content: "";
94
- background-color: rgba(var(--bs-light-rgb), 0.4);
95
- display: block;
96
- position: absolute;
97
- top: 0;
98
- right: 0;
99
- left: 0;
100
- bottom: 0;
101
- z-index: 9999;
102
- }
103
-
104
- .location-map-container {
105
- .leaflet-pane,
106
- .leaflet-tile,
107
- .leaflet-marker-icon,
108
- .leaflet-marker-shadow,
109
- .leaflet-tile-container,
110
- .leaflet-pane > svg,
111
- .leaflet-pane > canvas,
112
- .leaflet-zoom-box,
113
- .leaflet-image-layer,
114
- .leaflet-layer {
115
- left: auto;
116
- right: 0;
117
- }
118
-
119
- .leaflet-control-attribution.leaflet-control {
120
- display: none;
121
- }
122
- }
123
-
124
- </style>
@@ -1,7 +1,8 @@
1
1
  <script>
2
2
  import TextInput from "./TextInput.vue";
3
+ import {defineComponent} from "vue";
3
4
 
4
- export default {
5
+ export default defineComponent({
5
6
  components: {
6
7
  TextInput
7
8
  },
@@ -12,7 +13,7 @@ export default {
12
13
  required: true,
13
14
  },
14
15
  },
15
- }
16
+ })
16
17
  </script>
17
18
  <template>
18
19
  <TextInput