@iankibetsh/shframework 1.2.9 → 1.3.2

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/dist/library.mjs CHANGED
@@ -2,9 +2,9 @@ import Axios from 'axios';
2
2
  import moment from 'moment';
3
3
  import Swal from 'sweetalert2';
4
4
  import NProgress from 'nprogress';
5
- import { openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, resolveComponent, withModifiers, createVNode, ref, onMounted, unref, normalizeClass, createBlock, resolveDynamicComponent, renderSlot, normalizeProps, guardReactiveProps, withCtx, mergeProps, createStaticVNode, shallowRef, computed, isRef, vModelCheckbox, inject, watch, pushScopeId, popScopeId } from 'vue';
5
+ import { openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, resolveComponent, withModifiers, createVNode, ref, onMounted, unref, normalizeClass, createBlock, resolveDynamicComponent, inject, mergeProps, normalizeStyle, renderSlot, normalizeProps, guardReactiveProps, withCtx, createStaticVNode, shallowRef, computed, isRef, vModelCheckbox, watch, pushScopeId, popScopeId } from 'vue';
6
6
  import Editor from '@tinymce/tinymce-vue';
7
- import 'lodash';
7
+ import _ from 'lodash';
8
8
  import { defineStore, storeToRefs } from 'pinia';
9
9
  import { useRoute, useRouter } from 'vue-router';
10
10
 
@@ -1861,7 +1861,7 @@ const countries = [
1861
1861
  }
1862
1862
  ];
1863
1863
 
1864
- var script$h = {
1864
+ var script$l = {
1865
1865
  name: 'ShPhone',
1866
1866
  props: ['modelValue', 'country_code'],
1867
1867
  data () {
@@ -1923,19 +1923,19 @@ var script$h = {
1923
1923
  }
1924
1924
  };
1925
1925
 
1926
- const _hoisted_1$f = { class: "sh-phone mb-3" };
1927
- const _hoisted_2$b = {
1926
+ const _hoisted_1$g = { class: "sh-phone mb-3" };
1927
+ const _hoisted_2$c = {
1928
1928
  key: 0,
1929
1929
  style: {"display":"contents"}
1930
1930
  };
1931
- const _hoisted_3$a = ["src"];
1932
- const _hoisted_4$a = ["value"];
1931
+ const _hoisted_3$b = ["src"];
1932
+ const _hoisted_4$b = ["value"];
1933
1933
 
1934
1934
  function render$7(_ctx, _cache, $props, $setup, $data, $options) {
1935
- return (openBlock(), createElementBlock("div", _hoisted_1$f, [
1935
+ return (openBlock(), createElementBlock("div", _hoisted_1$g, [
1936
1936
  ($data.selectedCountry)
1937
- ? (openBlock(), createElementBlock("div", _hoisted_2$b, [
1938
- createElementVNode("img", { src: $data.flag }, null, 8 /* PROPS */, _hoisted_3$a),
1937
+ ? (openBlock(), createElementBlock("div", _hoisted_2$c, [
1938
+ createElementVNode("img", { src: $data.flag }, null, 8 /* PROPS */, _hoisted_3$b),
1939
1939
  createTextVNode(" " + toDisplayString($data.selectedCountry.dialCode), 1 /* TEXT */)
1940
1940
  ]))
1941
1941
  : createCommentVNode("v-if", true),
@@ -1948,7 +1948,7 @@ function render$7(_ctx, _cache, $props, $setup, $data, $options) {
1948
1948
  return (openBlock(), createElementBlock("option", {
1949
1949
  value: country,
1950
1950
  key: country.dialCode
1951
- }, toDisplayString(country.name + '(' + country.dialCode + ')'), 9 /* TEXT, PROPS */, _hoisted_4$a))
1951
+ }, toDisplayString(country.name + '(' + country.dialCode + ')'), 9 /* TEXT, PROPS */, _hoisted_4$b))
1952
1952
  }), 128 /* KEYED_FRAGMENT */))
1953
1953
  ], 544 /* HYDRATE_EVENTS, NEED_PATCH */), [
1954
1954
  [vModelSelect, $data.selectedCountry]
@@ -1966,10 +1966,10 @@ function render$7(_ctx, _cache, $props, $setup, $data, $options) {
1966
1966
  ]))
1967
1967
  }
1968
1968
 
1969
- script$h.render = render$7;
1970
- script$h.__file = "src/lib/components/form-components/ShPhone.vue";
1969
+ script$l.render = render$7;
1970
+ script$l.__file = "src/lib/components/form-components/ShPhone.vue";
1971
1971
 
1972
- var script$g = {
1972
+ var script$k = {
1973
1973
  name: 'ShEditor',
1974
1974
  props: ['modelValue'],
1975
1975
  components: {
@@ -2008,7 +2008,7 @@ var script$g = {
2008
2008
  }
2009
2009
  };
2010
2010
 
2011
- const _hoisted_1$e = /*#__PURE__*/createElementVNode("textarea", {
2011
+ const _hoisted_1$f = /*#__PURE__*/createElementVNode("textarea", {
2012
2012
  id: "tiny",
2013
2013
  style: {"display":"none"},
2014
2014
  "data-cy": "tinymce_editor"
@@ -2018,7 +2018,7 @@ function render$6(_ctx, _cache, $props, $setup, $data, $options) {
2018
2018
  const _component_editor = resolveComponent("editor");
2019
2019
 
2020
2020
  return (openBlock(), createElementBlock(Fragment, null, [
2021
- _hoisted_1$e,
2021
+ _hoisted_1$f,
2022
2022
  createElementVNode("div", {
2023
2023
  onFocusin: _cache[1] || (_cache[1] = withModifiers(() => {}, ["stop"])),
2024
2024
  class: "sh-editor w-100"
@@ -2043,19 +2043,19 @@ function render$6(_ctx, _cache, $props, $setup, $data, $options) {
2043
2043
  ], 64 /* STABLE_FRAGMENT */))
2044
2044
  }
2045
2045
 
2046
- script$g.render = render$6;
2047
- script$g.__file = "src/lib/components/form-components/ShEditor.vue";
2046
+ script$k.render = render$6;
2047
+ script$k.__file = "src/lib/components/form-components/ShEditor.vue";
2048
2048
 
2049
- const _hoisted_1$d = {
2049
+ const _hoisted_1$e = {
2050
2050
  key: 0,
2051
2051
  class: "dropdown sh-suggest"
2052
2052
  };
2053
- const _hoisted_2$a = ["id"];
2054
- const _hoisted_3$9 = { class: "badge bg-secondary m-1 sh-selected-item" };
2055
- const _hoisted_4$9 = ["onClick"];
2056
- const _hoisted_5$7 = ["id"];
2057
- const _hoisted_6$6 = ["id", "aria-labelledby"];
2058
- const _hoisted_7$4 = { key: 0 };
2053
+ const _hoisted_2$b = ["id"];
2054
+ const _hoisted_3$a = { class: "badge bg-secondary m-1 sh-selected-item" };
2055
+ const _hoisted_4$a = ["onClick"];
2056
+ const _hoisted_5$8 = ["id"];
2057
+ const _hoisted_6$7 = ["id", "aria-labelledby"];
2058
+ const _hoisted_7$5 = { key: 0 };
2059
2059
  const _hoisted_8$3 = ["onClick"];
2060
2060
  const _hoisted_9$4 = {
2061
2061
  key: 1,
@@ -2067,7 +2067,7 @@ const _hoisted_10$3 = {
2067
2067
  };
2068
2068
 
2069
2069
 
2070
- var script$f = {
2070
+ var script$j = {
2071
2071
  __name: 'ShSuggest',
2072
2072
  props: ['fillSelects','modelValue'],
2073
2073
  emits: ['update:modelValue'],
@@ -2148,7 +2148,7 @@ function filterData(e){
2148
2148
 
2149
2149
  return (_ctx, _cache) => {
2150
2150
  return (unref(id))
2151
- ? (openBlock(), createElementBlock("div", _hoisted_1$d, [
2151
+ ? (openBlock(), createElementBlock("div", _hoisted_1$e, [
2152
2152
  createElementVNode("div", {
2153
2153
  id: unref(id),
2154
2154
  "data-bs-toggle": "dropdown",
@@ -2157,14 +2157,14 @@ return (_ctx, _cache) => {
2157
2157
  }, [
2158
2158
  createElementVNode("div", null, [
2159
2159
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(selectedSuggestions), (sgt) => {
2160
- return (openBlock(), createElementBlock("h5", _hoisted_3$9, [
2160
+ return (openBlock(), createElementBlock("h5", _hoisted_3$a, [
2161
2161
  createTextVNode(toDisplayString(sgt.name) + " ", 1 /* TEXT */),
2162
2162
  createElementVNode("button", {
2163
2163
  onClick: $event => (removeSuggestion(sgt.id)),
2164
2164
  type: "button",
2165
2165
  class: "btn-close border-start border-1 ms-1",
2166
2166
  "aria-label": "Close"
2167
- }, null, 8 /* PROPS */, _hoisted_4$9)
2167
+ }, null, 8 /* PROPS */, _hoisted_4$a)
2168
2168
  ]))
2169
2169
  }), 256 /* UNKEYED_FRAGMENT */))
2170
2170
  ]),
@@ -2174,8 +2174,8 @@ return (_ctx, _cache) => {
2174
2174
  onClick: filterData,
2175
2175
  onInput: filterData,
2176
2176
  class: "flex-fill h-100 sh-suggestion-input"
2177
- }, null, 40 /* PROPS, HYDRATE_EVENTS */, _hoisted_5$7)
2178
- ], 8 /* PROPS */, _hoisted_2$a),
2177
+ }, null, 40 /* PROPS, HYDRATE_EVENTS */, _hoisted_5$8)
2178
+ ], 8 /* PROPS */, _hoisted_2$b),
2179
2179
  createElementVNode("ul", {
2180
2180
  class: "dropdown-menu w-100",
2181
2181
  id: 'dropwdown_section' + unref(id),
@@ -2187,7 +2187,7 @@ return (_ctx, _cache) => {
2187
2187
  key: suggestion.id
2188
2188
  }, [
2189
2189
  (suggestion.name)
2190
- ? (openBlock(), createElementBlock("li", _hoisted_7$4, [
2190
+ ? (openBlock(), createElementBlock("li", _hoisted_7$5, [
2191
2191
  createElementVNode("a", {
2192
2192
  onClick: $event => (addSuggestion(suggestion)),
2193
2193
  class: normalizeClass(["dropdown-item", unref(selectedSuggestions).includes(suggestion) ? 'active':'']),
@@ -2200,7 +2200,7 @@ return (_ctx, _cache) => {
2200
2200
  : (unref(searchText))
2201
2201
  ? (openBlock(), createElementBlock("li", _hoisted_9$4, " No results found "))
2202
2202
  : (openBlock(), createElementBlock("li", _hoisted_10$3, " Type to search... "))
2203
- ], 8 /* PROPS */, _hoisted_6$6)
2203
+ ], 8 /* PROPS */, _hoisted_6$7)
2204
2204
  ]))
2205
2205
  : createCommentVNode("v-if", true)
2206
2206
  }
@@ -2208,15 +2208,15 @@ return (_ctx, _cache) => {
2208
2208
 
2209
2209
  };
2210
2210
 
2211
- script$f.__scopeId = "data-v-71cc9569";
2212
- script$f.__file = "src/lib/components/form-components/ShSuggest.vue";
2211
+ script$j.__scopeId = "data-v-71cc9569";
2212
+ script$j.__file = "src/lib/components/form-components/ShSuggest.vue";
2213
2213
 
2214
- var script$e = {
2214
+ var script$i = {
2215
2215
  name: 'ShForm',
2216
2216
  components: {
2217
- ShSuggest: script$f,
2218
- ShEditor: script$g,
2219
- ShPhone: script$h
2217
+ ShSuggest: script$j,
2218
+ ShEditor: script$k,
2219
+ ShPhone: script$l
2220
2220
  },
2221
2221
  props: [
2222
2222
  'action',
@@ -2534,20 +2534,20 @@ var script$e = {
2534
2534
  }
2535
2535
  };
2536
2536
 
2537
- const _hoisted_1$c = /*#__PURE__*/createElementVNode("h5", { class: "d-none" }, null, -1 /* HOISTED */);
2538
- const _hoisted_2$9 = {
2537
+ const _hoisted_1$d = /*#__PURE__*/createElementVNode("h5", { class: "d-none" }, null, -1 /* HOISTED */);
2538
+ const _hoisted_2$a = {
2539
2539
  ref: "ShAutoForm",
2540
2540
  class: "sh-form"
2541
2541
  };
2542
- const _hoisted_3$8 = {
2542
+ const _hoisted_3$9 = {
2543
2543
  key: 0,
2544
2544
  class: "alert alert-danger alert-dismissible fade show sh-form-submission-error",
2545
2545
  role: "alert"
2546
2546
  };
2547
- const _hoisted_4$8 = /*#__PURE__*/createElementVNode("i", { class: "bi-exclamation-triangle-fill me-1" }, null, -1 /* HOISTED */);
2548
- const _hoisted_5$6 = { key: 0 };
2549
- const _hoisted_6$5 = { key: 1 };
2550
- const _hoisted_7$3 = { class: "row" };
2547
+ const _hoisted_4$9 = /*#__PURE__*/createElementVNode("i", { class: "bi-exclamation-triangle-fill me-1" }, null, -1 /* HOISTED */);
2548
+ const _hoisted_5$7 = { key: 0 };
2549
+ const _hoisted_6$6 = { key: 1 };
2550
+ const _hoisted_7$4 = { class: "row" };
2551
2551
  const _hoisted_8$2 = { class: "fg-label control-label text-capitalize control-bel col-md-12 request-form-label mb-2" };
2552
2552
  const _hoisted_9$3 = { class: "col-md-12" };
2553
2553
  const _hoisted_10$2 = ["data-cy", "placeholder", "name", "onFocus", "onChange"];
@@ -2596,16 +2596,16 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2596
2596
  const _component_ShEditor = resolveComponent("ShEditor");
2597
2597
 
2598
2598
  return (openBlock(), createElementBlock(Fragment, null, [
2599
- _hoisted_1$c,
2600
- createElementVNode("form", _hoisted_2$9, [
2599
+ _hoisted_1$d,
2600
+ createElementVNode("form", _hoisted_2$a, [
2601
2601
  createCommentVNode(" <div v-if=\"form_status == 1\" class=\"alert alert-info\">Processing...</div>"),
2602
2602
  createCommentVNode(" <div v-if=\"form_status == 2\" class=\"alert alert-success\">Success</div>"),
2603
2603
  (_ctx.form_status == 3)
2604
- ? (openBlock(), createElementBlock("div", _hoisted_3$8, [
2605
- _hoisted_4$8,
2604
+ ? (openBlock(), createElementBlock("div", _hoisted_3$9, [
2605
+ _hoisted_4$9,
2606
2606
  (_ctx.errorText)
2607
- ? (openBlock(), createElementBlock("span", _hoisted_5$6, toDisplayString(_ctx.errorText), 1 /* TEXT */))
2608
- : (openBlock(), createElementBlock("span", _hoisted_6$5, "Unexpected Error Occurred")),
2607
+ ? (openBlock(), createElementBlock("span", _hoisted_5$7, toDisplayString(_ctx.errorText), 1 /* TEXT */))
2608
+ : (openBlock(), createElementBlock("span", _hoisted_6$6, "Unexpected Error Occurred")),
2609
2609
  createCommentVNode(" <button @click=\"hideError\" type=\"button\" class=\"btn-close\" aria-label=\"Close\"></button>")
2610
2610
  ]))
2611
2611
  : createCommentVNode("v-if", true),
@@ -2615,7 +2615,7 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2615
2615
  }, null, 512 /* NEED_PATCH */), [
2616
2616
  [vModelText, _ctx.form_elements['id']]
2617
2617
  ]),
2618
- createElementVNode("div", _hoisted_7$3, [
2618
+ createElementVNode("div", _hoisted_7$4, [
2619
2619
  (openBlock(true), createElementBlock(Fragment, null, renderList($props.fields, (field) => {
2620
2620
  return (openBlock(), createElementBlock("div", {
2621
2621
  class: normalizeClass(["form-group", 'col-md-' + $options.getColumns()]),
@@ -2813,10 +2813,86 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2813
2813
  ], 64 /* STABLE_FRAGMENT */))
2814
2814
  }
2815
2815
 
2816
- script$e.render = render$5;
2817
- script$e.__file = "src/lib/components/ShForm.vue";
2816
+ script$i.render = render$5;
2817
+ script$i.__file = "src/lib/components/ShForm.vue";
2818
2818
 
2819
- var script$d = {
2819
+ var script$h = {
2820
+ __name: 'EmailInput',
2821
+ props: ['modelValue','label'],
2822
+ emits: ['update:modelValue','clearValidationErrors'],
2823
+ setup(__props, { emit }) {
2824
+
2825
+ const props = __props;
2826
+
2827
+
2828
+
2829
+ const inputModel = ref(null);
2830
+
2831
+ const modelValueUpdated = (e) => {
2832
+ emit('clearValidationErrors');
2833
+ emit('update:modelValue',inputModel);
2834
+ };
2835
+ onMounted(()=>{
2836
+ props.modelValue && (inputModel.value = props.modelValue);
2837
+ });
2838
+
2839
+
2840
+ return (_ctx, _cache) => {
2841
+ return withDirectives((openBlock(), createElementBlock("input", {
2842
+ type: "email",
2843
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => ((inputModel).value = $event)),
2844
+ onChange: modelValueUpdated,
2845
+ onKeydown: modelValueUpdated,
2846
+ onUpdated: modelValueUpdated
2847
+ }, null, 544 /* HYDRATE_EVENTS, NEED_PATCH */)), [
2848
+ [vModelText, inputModel.value]
2849
+ ])
2850
+ }
2851
+ }
2852
+
2853
+ };
2854
+
2855
+ script$h.__file = "src/lib/components/form-components/EmailInput.vue";
2856
+
2857
+ var script$g = {
2858
+ __name: 'NumberInput',
2859
+ props: ['modelValue','label'],
2860
+ emits: ['update:modelValue','clearValidationErrors'],
2861
+ setup(__props, { emit }) {
2862
+
2863
+ const props = __props;
2864
+
2865
+
2866
+
2867
+ const inputModel = ref(null);
2868
+
2869
+ const modelValueUpdated = (e) => {
2870
+ emit('clearValidationErrors');
2871
+ emit('update:modelValue',inputModel);
2872
+ };
2873
+ onMounted(()=>{
2874
+ props.modelValue && (inputModel.value = props.modelValue);
2875
+ });
2876
+
2877
+
2878
+ return (_ctx, _cache) => {
2879
+ return withDirectives((openBlock(), createElementBlock("input", {
2880
+ type: "number",
2881
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => ((inputModel).value = $event)),
2882
+ onChange: modelValueUpdated,
2883
+ onKeydown: modelValueUpdated,
2884
+ onUpdated: modelValueUpdated
2885
+ }, null, 544 /* HYDRATE_EVENTS, NEED_PATCH */)), [
2886
+ [vModelText, inputModel.value]
2887
+ ])
2888
+ }
2889
+ }
2890
+
2891
+ };
2892
+
2893
+ script$g.__file = "src/lib/components/form-components/NumberInput.vue";
2894
+
2895
+ var script$f = {
2820
2896
  __name: 'TextInput',
2821
2897
  props: ['modelValue','label'],
2822
2898
  emits: ['update:modelValue','clearValidationErrors'],
@@ -2852,7 +2928,269 @@ return (_ctx, _cache) => {
2852
2928
 
2853
2929
  };
2854
2930
 
2855
- script$d.__file = "src/lib/components/form-components/TextInput.vue";
2931
+ script$f.__file = "src/lib/components/form-components/TextInput.vue";
2932
+
2933
+ var script$e = {
2934
+ __name: 'TextAreaInput',
2935
+ props: ['modelValue','label'],
2936
+ emits: ['update:modelValue','clearValidationErrors'],
2937
+ setup(__props, { emit }) {
2938
+
2939
+ const props = __props;
2940
+
2941
+
2942
+
2943
+ const inputModel = ref(null);
2944
+
2945
+ const modelValueUpdated = (e) => {
2946
+ emit('clearValidationErrors');
2947
+ emit('update:modelValue',inputModel);
2948
+ };
2949
+ onMounted(()=>{
2950
+ props.modelValue && (inputModel.value = props.modelValue);
2951
+ });
2952
+
2953
+
2954
+ return (_ctx, _cache) => {
2955
+ return withDirectives((openBlock(), createElementBlock("textarea", {
2956
+ type: "text",
2957
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => ((inputModel).value = $event)),
2958
+ onChange: modelValueUpdated,
2959
+ onKeydown: modelValueUpdated,
2960
+ onUpdated: modelValueUpdated
2961
+ }, null, 544 /* HYDRATE_EVENTS, NEED_PATCH */)), [
2962
+ [vModelText, inputModel.value]
2963
+ ])
2964
+ }
2965
+ }
2966
+
2967
+ };
2968
+
2969
+ script$e.__file = "src/lib/components/form-components/TextAreaInput.vue";
2970
+
2971
+ const _hoisted_1$c = /*#__PURE__*/createElementVNode("div", null, null, -1 /* HOISTED */);
2972
+ const _hoisted_2$9 = ["innerHTML"];
2973
+ const _hoisted_3$8 = ["innerHTML"];
2974
+ const _hoisted_4$8 = ["innerHTML"];
2975
+ const _hoisted_5$6 = ["disabled"];
2976
+ const _hoisted_6$5 = {
2977
+ key: 0,
2978
+ class: "spinner-border spinner-border-sm",
2979
+ role: "status",
2980
+ "aria-hidden": "true"
2981
+ };
2982
+ const _hoisted_7$3 = { key: 1 };
2983
+
2984
+
2985
+ var script$d = {
2986
+ __name: 'ShAutoForm',
2987
+ props: [
2988
+ 'action','successCallback','retainDataAfterSubmission',
2989
+ 'successMessage','fields','customComponents','placeHolders',
2990
+ 'formClasses',
2991
+ 'helperTexts','labels','data',
2992
+ 'actionLabel',
2993
+ 'textAreas',
2994
+ 'emails',
2995
+ 'phones','numbers','selects','dates'
2996
+ ],
2997
+ emits: ['success'],
2998
+ setup(__props, { emit }) {
2999
+
3000
+ const props = __props;
3001
+
3002
+
3003
+
3004
+ const formFields = ref([]);
3005
+ const getFieldComponent = (field)=>{
3006
+ const defaultTextareas = ['message', 'meta_description', 'comment', 'call_response', 'comments', 'description'];
3007
+ const defaultSelects = ['gender', 'payment_method', 'allow_view_mode', 'reasons_name', 'has_free_tier', 'payment_period', 'role', 'register_as', 'account_type'];
3008
+ const defaultNumbers = ['age'];
3009
+ const defaultDates = ['free_tier_days', 'recurring_date', 'date', 'paid_at'];
3010
+ const defaultPhones = ['phone'];
3011
+ const defaultEmails = ['phone'];
3012
+ const formComponents = inject('formComponents');
3013
+ if(props.customComponents && props.customComponents[field]) {
3014
+ return props.customComponents[field]
3015
+ } else
3016
+ if((props.textAreas && props.textAreas.includes(field)) || defaultTextareas.includes(field)){
3017
+ return formComponents.textArea ?? script$e
3018
+ } else
3019
+ if((props.emails && props.emails.includes(field)) || defaultEmails.includes(field)){
3020
+ return formComponents.email ?? script$h
3021
+ } else
3022
+ if((props.phones && props.phones.includes(field)) || defaultPhones.includes(field)){
3023
+ return formComponents.phone ?? script$l
3024
+ } else
3025
+ if((props.numbers && props.numbers.includes(field)) || defaultNumbers.includes(field)){
3026
+ return formComponents.number ?? script$g
3027
+ } else
3028
+ if((props.selects && props.selects.includes(field)) || defaultSelects.includes(field)){
3029
+ return formComponents.select ?? SelectInput
3030
+ } else
3031
+ if((props.dates && props.dates.includes(field)) || defaultDates.includes(field)){
3032
+ return formComponents.date ?? DateInput
3033
+ }
3034
+ return formComponents.text ?? script$f
3035
+ };
3036
+ const shFormElementClasses = ref(null);
3037
+ shFormElementClasses.value = inject('shFormElementClasses');
3038
+ const shAutoForm = ref(null);
3039
+ const closeModal = e => {
3040
+ setTimeout(()=>{
3041
+ const closeBtn = shAutoForm.value.closest('.modal-dialog').querySelector('[data-bs-dismiss="modal"]');
3042
+ closeBtn && closeBtn.click();
3043
+ },1000);
3044
+ };
3045
+ const getLabel = field => (props.labels && (props.labels[field] !== undefined)) ? props.labels[field]:_.startCase(_.camelCase(field));
3046
+ const getComponentClass = field => validationErrors.value[field] ? getElementClass('formControl') + ' is-invalid':getElementClass('formControl');
3047
+ const getHelperText = field => (props.helperTexts && props.helperTexts[field]) ? props.helperTexts[field]:false;
3048
+ const getElementClass = section => (props.formClasses && props.formClasses[section]) ? props.formClasses[section]:shFormElementClasses.value[section] ?? _.snakeCase(section).replace(/_/gi,'-');
3049
+ const getPlaceholder = field => (props.placeHolders && props.placeHolders[field]) && props.placeHolders[field];
3050
+ const removeValidationError = field => delete validationErrors.value[field];
3051
+ const getComponentProps = field => {
3052
+ const newField = {...field};
3053
+ delete newField.component;
3054
+ delete newField.value;
3055
+ return newField
3056
+ };
3057
+ const isFloating = getElementClass('formGroup').includes('form-floating');
3058
+ const loading = ref(false);
3059
+ const submitBtn = ref(false);
3060
+ const validationErrors = ref({});
3061
+ const formError = ref(null);
3062
+ const submitForm = e => {
3063
+ console.log(formFields.value);
3064
+ submitBtnWidth.value = submitBtn.value.getBoundingClientRect().width + 'px !important';
3065
+ validationErrors.value = {};
3066
+ e.preventDefault();
3067
+ loading.value = true;
3068
+ const data = {};
3069
+ formFields.value.map(field=>data[field.field] = field.value);
3070
+ shApis.doPost(props.action,data).then(res=>{
3071
+ loading.value = false;
3072
+ emit('formSubmitted',res.data);
3073
+ emit('success',res.data);
3074
+ props.successMessage && shRepo.showToast(props.successMessage);
3075
+ props.successCallback && props.successCallback(res.data);
3076
+ !props.retainDataAfterSubmission && formFields.value.map(field=>field.value = null);
3077
+ closeModal();
3078
+ }).catch(reason=>{
3079
+ console.log(reason);
3080
+ loading.value = false;
3081
+ const httpStatus = reason.response ? reason.response.status:0;
3082
+ formError.value = httpStatus === 422 ? formError.value = null:reason.message ?? null;
3083
+ let httpErrors = {};
3084
+ httpStatus === 422 && typeof reason.response.data.errors === 'object' && (httpErrors = reason.response.data.errors);
3085
+ if(httpErrors && reason.response){
3086
+ Object.keys(httpErrors).map(key=>validationErrors.value[key] = typeof httpErrors[key] === 'string' ? httpErrors[key]:httpErrors[key][0]);
3087
+ }
3088
+ (httpStatus !== 422 && formError.value) && shRepo.showToast(formError.value,'error');
3089
+ validationErrors.value;
3090
+ });
3091
+ return false
3092
+ };
3093
+ const submitBtnWidth = ref(null);
3094
+ onMounted((ev)=>{
3095
+ props.fields && props.fields.map(field=>{
3096
+ if(typeof field === 'object') {
3097
+ const fieldObj = {...field};
3098
+ fieldObj.label && getLabel(fieldObj.field);
3099
+ !fieldObj.helper && fieldObj.helperText ? fieldObj.helper = fieldObj.helperText : fieldObj.helper = getHelperText(fieldObj.field);
3100
+ fieldObj.helperText === undefined && (fieldObj.label = getLabel(fieldObj.field));
3101
+ fieldObj.component && getfieldObjComponent(fieldObj.field);
3102
+ fieldObj.placeholder && fieldObj.placeHolder && getPlaceholder(fieldObj.field);
3103
+ fieldObj.value = null;
3104
+ formFields.value.push(fieldObj);
3105
+ } else {
3106
+ formFields.value.push({
3107
+ field:field,label: getLabel(field),
3108
+ helper: getHelperText(field),
3109
+ component: getFieldComponent(field),
3110
+ placeholder: getPlaceholder(field),
3111
+ value: null
3112
+ });
3113
+ }
3114
+ });
3115
+ });
3116
+
3117
+
3118
+ return (_ctx, _cache) => {
3119
+ return (openBlock(), createElementBlock(Fragment, null, [
3120
+ _hoisted_1$c,
3121
+ createElementVNode("form", {
3122
+ ref_key: "shAutoForm",
3123
+ ref: shAutoForm,
3124
+ class: "sh-form",
3125
+ onSubmit: _cache[0] || (_cache[0] = e => submitForm(e))
3126
+ }, [
3127
+ (openBlock(true), createElementBlock(Fragment, null, renderList(formFields.value, (field, index) => {
3128
+ return (openBlock(), createElementBlock("div", {
3129
+ key: field,
3130
+ class: normalizeClass(getElementClass('formGroup'))
3131
+ }, [
3132
+ (!unref(isFloating) && field.label)
3133
+ ? (openBlock(), createElementBlock("label", {
3134
+ key: 0,
3135
+ class: normalizeClass(getElementClass('formLabel')),
3136
+ innerHTML: field.label
3137
+ }, null, 10 /* CLASS, PROPS */, _hoisted_2$9))
3138
+ : createCommentVNode("v-if", true),
3139
+ (openBlock(), createBlock(resolveDynamicComponent(getFieldComponent(field.field)), mergeProps(getComponentProps(field), {
3140
+ onClick: $event => (removeValidationError(field.field)),
3141
+ "onUpdate:modelValue": [$event => (removeValidationError(field.field)), $event => ((formFields.value[index].value) = $event)],
3142
+ modelValue: formFields.value[index].value,
3143
+ placeholder: unref(isFloating) ? field.label:field.placeholder,
3144
+ class: getComponentClass(field.field)
3145
+ }), null, 16 /* FULL_PROPS */, ["onClick", "onUpdate:modelValue", "modelValue", "placeholder", "class"])),
3146
+ (unref(isFloating) && field.label)
3147
+ ? (openBlock(), createElementBlock("label", {
3148
+ key: 1,
3149
+ class: normalizeClass(getElementClass('formLabel')),
3150
+ innerHTML: field.label
3151
+ }, null, 10 /* CLASS, PROPS */, _hoisted_3$8))
3152
+ : createCommentVNode("v-if", true),
3153
+ (field.helper)
3154
+ ? (openBlock(), createElementBlock("div", {
3155
+ key: 2,
3156
+ class: normalizeClass(getElementClass('helperText')),
3157
+ innerHTML: field.helper
3158
+ }, null, 10 /* CLASS, PROPS */, _hoisted_4$8))
3159
+ : createCommentVNode("v-if", true),
3160
+ (validationErrors.value[field.field])
3161
+ ? (openBlock(), createElementBlock("div", {
3162
+ key: 3,
3163
+ class: normalizeClass(getElementClass('invalidFeedback'))
3164
+ }, toDisplayString(validationErrors.value[field.field]), 3 /* TEXT, CLASS */))
3165
+ : createCommentVNode("v-if", true)
3166
+ ], 2 /* CLASS */))
3167
+ }), 128 /* KEYED_FRAGMENT */)),
3168
+ createElementVNode("div", {
3169
+ class: normalizeClass(getElementClass('formGroup'))
3170
+ }, [
3171
+ createElementVNode("button", {
3172
+ style: normalizeStyle({width: submitBtnWidth.value}),
3173
+ ref_key: "submitBtn",
3174
+ ref: submitBtn,
3175
+ disabled: loading.value,
3176
+ class: normalizeClass(getElementClass('actionBtn'))
3177
+ }, [
3178
+ (loading.value)
3179
+ ? (openBlock(), createElementBlock("span", _hoisted_6$5))
3180
+ : createCommentVNode("v-if", true),
3181
+ (!loading.value)
3182
+ ? (openBlock(), createElementBlock("span", _hoisted_7$3, "Submit"))
3183
+ : createCommentVNode("v-if", true)
3184
+ ], 14 /* CLASS, STYLE, PROPS */, _hoisted_5$6)
3185
+ ], 2 /* CLASS */)
3186
+ ], 544 /* HYDRATE_EVENTS, NEED_PATCH */)
3187
+ ], 64 /* STABLE_FRAGMENT */))
3188
+ }
3189
+ }
3190
+
3191
+ };
3192
+
3193
+ script$d.__file = "src/lib/components/ShAutoForm.vue";
2856
3194
 
2857
3195
  const _hoisted_1$b = /*#__PURE__*/createElementVNode("h5", { class: "d-none" }, "To prevent default class", -1 /* HOISTED */);
2858
3196
  const _hoisted_2$8 = { class: "dropdown" };
@@ -2904,7 +3242,7 @@ return (_ctx, _cache) => {
2904
3242
  class: "dropdown-menu px-2 py-1",
2905
3243
  "aria-labelledby": dropdownId
2906
3244
  }, [
2907
- createVNode(script$e, normalizeProps(guardReactiveProps(props)), null, 16 /* FULL_PROPS */)
3245
+ createVNode(script$i, normalizeProps(guardReactiveProps(props)), null, 16 /* FULL_PROPS */)
2908
3246
  ])
2909
3247
  ])
2910
3248
  ], 64 /* STABLE_FRAGMENT */))
@@ -3008,7 +3346,7 @@ return (_ctx, _cache) => {
3008
3346
  "modal-title": __props.modalTitle
3009
3347
  }, {
3010
3348
  default: withCtx(() => [
3011
- createVNode(script$e, mergeProps({ onSuccess: success }, props), null, 16 /* FULL_PROPS */)
3349
+ createVNode(script$i, mergeProps({ onSuccess: success }, props), null, 16 /* FULL_PROPS */)
3012
3350
  ]),
3013
3351
  _: 1 /* STABLE */
3014
3352
  }, 8 /* PROPS */, ["modal-title"])
@@ -4674,7 +5012,7 @@ return (_ctx, _cache) => {
4674
5012
  "modal-title": "Department Form"
4675
5013
  }, {
4676
5014
  default: withCtx(() => [
4677
- createVNode(script$e, {
5015
+ createVNode(script$i, {
4678
5016
  "success-callback": "departmentAdded",
4679
5017
  onDepartmentAdded: departmentAdded,
4680
5018
  action: "admin/departments/store",
@@ -4833,7 +5171,7 @@ return (_ctx, _cache) => {
4833
5171
  "modal-title": "Add Module Department"
4834
5172
  }, {
4835
5173
  default: withCtx(() => [
4836
- createVNode(script$e, {
5174
+ createVNode(script$i, {
4837
5175
  "reload-select-items": unref(reload),
4838
5176
  "success-callback": moduleAdded,
4839
5177
  "fill-selects": {
@@ -4970,7 +5308,7 @@ return (_ctx, _cache) => {
4970
5308
  : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
4971
5309
  (section.value === 'login')
4972
5310
  ? (openBlock(), createElementBlock("div", _hoisted_2, [
4973
- createVNode(script$e, {
5311
+ createVNode(script$i, {
4974
5312
  class: "sh-login-form",
4975
5313
  fields: ['email','password'],
4976
5314
  "action-label": "Login",
@@ -4995,7 +5333,7 @@ return (_ctx, _cache) => {
4995
5333
  (unref(registerSubTitle))
4996
5334
  ? (openBlock(), createElementBlock("span", _hoisted_8, toDisplayString(unref(registerSubTitle)), 1 /* TEXT */))
4997
5335
  : createCommentVNode("v-if", true),
4998
- createVNode(script$e, {
5336
+ createVNode(script$i, {
4999
5337
  class: "sh-login-form",
5000
5338
  fields: unref(registrationFields),
5001
5339
  "action-label": "Sign Up",
@@ -5041,7 +5379,7 @@ const ShFrontend = {
5041
5379
  const registerTitle = options.registerTitle ?? 'Create a new account';
5042
5380
  const registerSubTitle = options.registerSubTitle ?? `It's quick and easy`;
5043
5381
  const logoutApiEndpoint = options.logoutApiEndpoint ?? `auth/logout`;
5044
- options.formTextInput ?? script$d;
5382
+ options.formTextInput ?? script$f;
5045
5383
  const loginUrl = options.loginUrl ?? `/login`;
5046
5384
  const redirectLogin = options.redirectLogin ?? `/`;
5047
5385
  const redirectRegister = options.redirectRegister ?? `/`;
@@ -5082,4 +5420,4 @@ const ShFrontend = {
5082
5420
  }
5083
5421
  };
5084
5422
 
5085
- export { script$9 as ShCanvas, script$7 as ShConfirmAction, script$c as ShDropDownForm, script$3 as ShDynamicTabs, script$e as ShForm, ShFrontend, script$b as ShModal, script$a as ShModalForm, script$h as ShPhone, script$6 as ShSilentAction, script$5 as ShTable, script$4 as ShTabs, shApis, shRepo, ShStorage as shStorage, useUserStore };
5423
+ export { script$d as ShAutoForm, script$9 as ShCanvas, script$7 as ShConfirmAction, script$c as ShDropDownForm, script$3 as ShDynamicTabs, script$i as ShForm, ShFrontend, script$b as ShModal, script$a as ShModalForm, script$l as ShPhone, script$6 as ShSilentAction, script$5 as ShTable, script$4 as ShTabs, shApis, shRepo, ShStorage as shStorage, useUserStore };