@iankibetsh/shframework 4.3.6 → 4.3.8

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.
@@ -63,21 +63,6 @@
63
63
  opacity: 0.5;
64
64
  }
65
65
 
66
- .sh-selected-item{
67
- line-height: unset!important;
68
- }
69
- .sh-suggestion-input{
70
- padding: 0.375rem 0.75rem;
71
- }
72
- .sh-suggest{
73
- margin-bottom: 1rem;
74
- }
75
- .sh-suggest-control::after{
76
- margin-top: auto;
77
- margin-bottom: auto;
78
- margin-right: 0.255em;
79
- }
80
-
81
66
  .permissions-main {
82
67
  background: #edeff2;
83
68
  }
@@ -110,6 +95,22 @@
110
95
  flex-grow: 1;
111
96
  }
112
97
 
98
+ .sh-selected-item{
99
+ line-height: unset!important;
100
+ }
101
+ .sh-suggestion-input{
102
+ padding: 0.375rem 0.75rem;
103
+ }
104
+ .sh-suggest{
105
+ margin-bottom: 1rem;
106
+ padding: 0rem 0rem;
107
+ }
108
+ .sh-suggest-control::after{
109
+ margin-top: auto;
110
+ margin-bottom: auto;
111
+ margin-right: 0.255em;
112
+ }
113
+
113
114
  .callout{
114
115
  --bs-link-color-rgb: 110,168,254;
115
116
  --bs-code-color: #e685b5;
package/dist/library.js CHANGED
@@ -197,7 +197,7 @@ function showToast(message, toastType, config){
197
197
  mixinConfig[newKey] = config[key];
198
198
  });
199
199
  }
200
- console.log(mixinConfig);
200
+ // console.log(mixinConfig)
201
201
  const Toast = Swal__default["default"].mixin(mixinConfig);
202
202
  // Toast.mixin({
203
203
  // position: 'top'
@@ -2049,11 +2049,11 @@ const _hoisted_1$n = {
2049
2049
  class: "dropdown sh-suggest"
2050
2050
  };
2051
2051
  const _hoisted_2$d = ["id"];
2052
- const _hoisted_3$c = { class: "badge bg-secondary m-1 sh-selected-item" };
2053
- const _hoisted_4$c = ["onClick"];
2054
- const _hoisted_5$a = ["id"];
2055
- const _hoisted_6$9 = ["id", "aria-labelledby"];
2056
- const _hoisted_7$8 = { key: 0 };
2052
+ const _hoisted_3$c = { class: "sh-suggestions-holder" };
2053
+ const _hoisted_4$c = { class: "badge bg-secondary m-1 sh-selected-item" };
2054
+ const _hoisted_5$a = ["onClick"];
2055
+ const _hoisted_6$9 = ["id"];
2056
+ const _hoisted_7$8 = ["id", "aria-labelledby"];
2057
2057
  const _hoisted_8$7 = ["onClick"];
2058
2058
  const _hoisted_9$7 = {
2059
2059
  key: 1,
@@ -2067,7 +2067,7 @@ const _hoisted_10$6 = {
2067
2067
 
2068
2068
  var script$u = {
2069
2069
  __name: 'ShSuggest',
2070
- props: ['data','allowMultiple','url','modelValue'],
2070
+ props: ['data','allowMultiple','url','modelValue','optionTemplate'],
2071
2071
  emits: ['update:modelValue'],
2072
2072
  setup(__props, { emit: __emit }) {
2073
2073
 
@@ -2080,6 +2080,11 @@ let selectedSuggestions = vue.ref([]);
2080
2080
  vue.onMounted(() => {
2081
2081
  id.value = 'sid' + (Math.random() + 1).toString(36).substring(7);
2082
2082
  resetData();
2083
+ if(props.url){
2084
+ fetchRemoteData();
2085
+ } else {
2086
+ initializeExisting();
2087
+ }
2083
2088
  });
2084
2089
  function resetData(){
2085
2090
  const data = props.data;
@@ -2143,10 +2148,10 @@ const fetchRemoteData = ()=>{
2143
2148
  const data = {
2144
2149
  all: 1,
2145
2150
  filter_value: searchText.value,
2146
- here: 'three'
2147
2151
  };
2148
2152
  shApis.doGet(props.url, data).then(res => {
2149
2153
  suggestions.value = res.data.data ?? res.data;
2154
+ initializeExisting();
2150
2155
  }).catch(res => {
2151
2156
  console.log(res);
2152
2157
  });
@@ -2165,36 +2170,60 @@ const hideDropDown = ()=>{
2165
2170
  }
2166
2171
  };
2167
2172
 
2173
+ const initializeExisting = ()=>{
2174
+ console.log(props);
2175
+ if(props.modelValue && suggestions.value){
2176
+ if(props.allowMultiple){
2177
+ let selected = [];
2178
+ props.modelValue.forEach(id=>{
2179
+ let found = suggestions.value.find(sgt=>{
2180
+ return sgt.id === id
2181
+ });
2182
+ if(found){
2183
+ selected.push(found);
2184
+ }
2185
+ });
2186
+ selectedSuggestions.value = selected;
2187
+ } else {
2188
+ let found = suggestions.value.find(sgt=>{
2189
+ return sgt.id === props.modelValue
2190
+ });
2191
+ if(found){
2192
+ selectedSuggestions.value = [found];
2193
+ }
2194
+ }
2195
+ }
2196
+ };
2197
+
2168
2198
  return (_ctx, _cache) => {
2169
2199
  return (vue.unref(id))
2170
2200
  ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$n, [
2171
2201
  vue.createElementVNode("div", {
2172
2202
  id: vue.unref(id),
2173
2203
  "data-bs-toggle": "dropdown",
2174
- class: "form-control p-0 d-flex sh-suggest-control dropdown-toggle",
2204
+ class: "p-0 d-flex sh-suggest-control dropdown-toggle",
2175
2205
  "aria-expanded": "false"
2176
2206
  }, [
2177
- vue.createElementVNode("div", null, [
2207
+ vue.createElementVNode("div", _hoisted_3$c, [
2178
2208
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(selectedSuggestions), (sgt) => {
2179
- return (vue.openBlock(), vue.createElementBlock("h5", _hoisted_3$c, [
2209
+ return (vue.openBlock(), vue.createElementBlock("h5", _hoisted_4$c, [
2180
2210
  vue.createTextVNode(vue.toDisplayString(sgt.name) + " ", 1 /* TEXT */),
2181
2211
  vue.createElementVNode("button", {
2182
2212
  onClick: $event => (removeSuggestion(sgt.id)),
2183
2213
  type: "button",
2184
2214
  class: "btn-close border-start border-1 ms-1",
2185
2215
  "aria-label": "Close"
2186
- }, null, 8 /* PROPS */, _hoisted_4$c)
2216
+ }, null, 8 /* PROPS */, _hoisted_5$a)
2187
2217
  ]))
2188
2218
  }), 256 /* UNKEYED_FRAGMENT */))
2189
2219
  ]),
2190
2220
  vue.createElementVNode("div", {
2191
2221
  id: 'input_' + vue.unref(id),
2192
2222
  contenteditable: "true",
2193
- onClick: filterData,
2194
2223
  onInput: filterData,
2195
2224
  onChange: filterData,
2196
2225
  class: "flex-fill h-100 sh-suggestion-input"
2197
- }, null, 40 /* PROPS, NEED_HYDRATION */, _hoisted_5$a)
2226
+ }, null, 40 /* PROPS, NEED_HYDRATION */, _hoisted_6$9)
2198
2227
  ], 8 /* PROPS */, _hoisted_2$d),
2199
2228
  vue.createElementVNode("ul", {
2200
2229
  class: "dropdown-menu w-100",
@@ -2207,21 +2236,29 @@ return (_ctx, _cache) => {
2207
2236
  key: suggestion.id
2208
2237
  }, [
2209
2238
  (suggestion.name)
2210
- ? (vue.openBlock(), vue.createElementBlock("li", _hoisted_7$8, [
2211
- vue.createElementVNode("span", {
2212
- style: {"cursor":"pointer"},
2213
- onClick: $event => (addSuggestion(suggestion)),
2214
- class: vue.normalizeClass(["dropdown-item", vue.unref(selectedSuggestions).includes(suggestion) ? 'active':'']),
2215
- href: "#"
2216
- }, vue.toDisplayString(suggestion.name ?? suggestion.text), 11 /* TEXT, CLASS, PROPS */, _hoisted_8$7)
2217
- ]))
2239
+ ? (vue.openBlock(), vue.createElementBlock("li", {
2240
+ key: 0,
2241
+ onClick: $event => (addSuggestion(suggestion))
2242
+ }, [
2243
+ (__props.optionTemplate)
2244
+ ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.optionTemplate), {
2245
+ key: 0,
2246
+ option: suggestion
2247
+ }, null, 8 /* PROPS */, ["option"]))
2248
+ : (vue.openBlock(), vue.createElementBlock("span", {
2249
+ key: 1,
2250
+ style: {"cursor":"pointer"},
2251
+ class: vue.normalizeClass(["dropdown-item", vue.unref(selectedSuggestions).includes(suggestion) ? 'active':'']),
2252
+ href: "#"
2253
+ }, vue.toDisplayString(suggestion.name ?? suggestion.text), 3 /* TEXT, CLASS */))
2254
+ ], 8 /* PROPS */, _hoisted_8$7))
2218
2255
  : vue.createCommentVNode("v-if", true)
2219
2256
  ], 64 /* STABLE_FRAGMENT */))
2220
2257
  }), 128 /* KEYED_FRAGMENT */))
2221
2258
  : (vue.unref(searchText))
2222
2259
  ? (vue.openBlock(), vue.createElementBlock("li", _hoisted_9$7, " No results found "))
2223
2260
  : (vue.openBlock(), vue.createElementBlock("li", _hoisted_10$6, " Type to search... "))
2224
- ], 8 /* PROPS */, _hoisted_6$9)
2261
+ ], 8 /* PROPS */, _hoisted_7$8)
2225
2262
  ]))
2226
2263
  : vue.createCommentVNode("v-if", true)
2227
2264
  }
@@ -2581,7 +2618,7 @@ const _hoisted_10$5 = ["data-cy", "placeholder", "name", "onFocus", "onChange"];
2581
2618
  const _hoisted_11$5 = ["data-cy", "placeholder", "name", "onFocus", "onUpdate:modelValue"];
2582
2619
  const _hoisted_12$4 = ["data-cy", "placeholder", "name", "onFocus", "onUpdate:modelValue"];
2583
2620
  const _hoisted_13$4 = ["data-cy", "placeholder", "name", "onFocus", "onUpdate:modelValue"];
2584
- const _hoisted_14$3 = ["data-cy", "name", "onFocus", "onUpdate:modelValue"];
2621
+ const _hoisted_14$4 = ["data-cy", "name", "onFocus", "onUpdate:modelValue"];
2585
2622
  const _hoisted_15$3 = ["disabled", "placeholder", "name", "onFocus", "onUpdate:modelValue"];
2586
2623
  const _hoisted_16$3 = ["name", "onFocus", "onUpdate:modelValue"];
2587
2624
  const _hoisted_17$3 = ["name", "onFocus", "onUpdate:modelValue"];
@@ -2727,7 +2764,7 @@ function render$2(_ctx, _cache, $props, $setup, $data, $options) {
2727
2764
  onFocus: $event => ($options.removeErrors(field)),
2728
2765
  class: vue.normalizeClass([_ctx.form_errors[field] == null ? ' field_' + field:'is-invalid ' + field, "form-control active"]),
2729
2766
  "onUpdate:modelValue": $event => ((_ctx.form_elements[field]) = $event)
2730
- }, null, 42 /* CLASS, PROPS, NEED_HYDRATION */, _hoisted_14$3)), [
2767
+ }, null, 42 /* CLASS, PROPS, NEED_HYDRATION */, _hoisted_14$4)), [
2731
2768
  [vue.vModelText, _ctx.form_elements[field]]
2732
2769
  ])
2733
2770
  : vue.createCommentVNode("v-if", true),
@@ -3005,7 +3042,7 @@ const _hoisted_1$k = ["value"];
3005
3042
 
3006
3043
  var script$o = {
3007
3044
  __name: 'SelectInput',
3008
- props: ['modelValue','label','data','dataUrl'],
3045
+ props: ['modelValue','label','url','required','options','dataUrl','data'],
3009
3046
  emits: ['update:modelValue','clearValidationErrors'],
3010
3047
  setup(__props, { emit: __emit }) {
3011
3048
 
@@ -3018,6 +3055,7 @@ const modelValueUpdated = (e) => {
3018
3055
  emit('update:modelValue',inputModel);
3019
3056
  };
3020
3057
  vue.onMounted(()=>{
3058
+ console.log(props);
3021
3059
  props.modelValue && (inputModel.value = props.modelValue);
3022
3060
  const options = props.data ?? props.options;
3023
3061
  if(options){
@@ -3027,8 +3065,8 @@ vue.onMounted(()=>{
3027
3065
  name: item.label ? item.label : item.name ? item.name : item.value ? item.value:item.id ? item.id:item.option
3028
3066
  }
3029
3067
  });
3030
- } else if (props.dataUrl){
3031
- shApis.doGet(props.dataUrl,{all:1}).then(res=>{
3068
+ } else if (props.dataUrl || props.url) {
3069
+ shApis.doGet(props.dataUrl ?? props.url,{all:1}).then(res=>{
3032
3070
  selectOptions.value = res.data.map(item=>{
3033
3071
  return {
3034
3072
  id: item.id ? item.id : item.key ? item.key : item.value ? item.value:item.name ? item.name:item.label,
@@ -3108,59 +3146,63 @@ script$n.__file = "src/lib/components/form-components/PasswordInput.vue";
3108
3146
  const _hoisted_1$j = /*#__PURE__*/vue.createElementVNode("div", null, null, -1 /* HOISTED */);
3109
3147
  const _hoisted_2$b = ["onUpdate:modelValue"];
3110
3148
  const _hoisted_3$a = ["innerHTML"];
3111
- const _hoisted_4$a = ["innerHTML"];
3112
- const _hoisted_5$8 = {
3149
+ const _hoisted_4$a = {
3150
+ key: 0,
3151
+ class: "text-danger sh-required"
3152
+ };
3153
+ const _hoisted_5$8 = ["innerHTML"];
3154
+ const _hoisted_6$7 = {
3113
3155
  key: 2,
3114
3156
  class: "form-notch"
3115
3157
  };
3116
- const _hoisted_6$7 = /*#__PURE__*/vue.createElementVNode("div", { class: "form-notch-leading" }, null, -1 /* HOISTED */);
3117
- const _hoisted_7$6 = /*#__PURE__*/vue.createElementVNode("div", { class: "form-notch-middle" }, null, -1 /* HOISTED */);
3118
- const _hoisted_8$5 = /*#__PURE__*/vue.createElementVNode("div", { class: "form-notch-trailing" }, null, -1 /* HOISTED */);
3119
- const _hoisted_9$5 = [
3120
- _hoisted_6$7,
3158
+ const _hoisted_7$6 = /*#__PURE__*/vue.createElementVNode("div", { class: "form-notch-leading" }, null, -1 /* HOISTED */);
3159
+ const _hoisted_8$5 = /*#__PURE__*/vue.createElementVNode("div", { class: "form-notch-middle" }, null, -1 /* HOISTED */);
3160
+ const _hoisted_9$5 = /*#__PURE__*/vue.createElementVNode("div", { class: "form-notch-trailing" }, null, -1 /* HOISTED */);
3161
+ const _hoisted_10$4 = [
3121
3162
  _hoisted_7$6,
3122
- _hoisted_8$5
3163
+ _hoisted_8$5,
3164
+ _hoisted_9$5
3123
3165
  ];
3124
- const _hoisted_10$4 = ["innerHTML"];
3125
- const _hoisted_11$4 = ["disabled"];
3126
- const _hoisted_12$3 = {
3166
+ const _hoisted_11$4 = ["innerHTML"];
3167
+ const _hoisted_12$3 = ["disabled"];
3168
+ const _hoisted_13$3 = {
3127
3169
  key: 0,
3128
3170
  class: "spinner-border spinner-border-sm",
3129
3171
  role: "status",
3130
3172
  "aria-hidden": "true"
3131
3173
  };
3132
- const _hoisted_13$3 = { key: 1 };
3174
+ const _hoisted_14$3 = { key: 1 };
3133
3175
 
3134
3176
 
3135
3177
  var script$m = {
3136
3178
  __name: 'ShAutoForm',
3137
3179
  props: [
3138
- 'action','successCallback','retainDataAfterSubmission',
3139
- 'successMessage','fields','customComponents','placeHolders',
3180
+ 'action', 'successCallback', 'retainDataAfterSubmission',
3181
+ 'successMessage', 'fields', 'customComponents', 'placeHolders',
3140
3182
  'formClasses',
3141
- 'helperTexts','labels','data',
3183
+ 'helperTexts', 'labels', 'data',
3142
3184
  'fillSelects',
3143
3185
  'formClass',
3144
3186
  'actionLabel',
3145
- 'textAreas',
3146
- 'currentData',
3147
- 'emails',
3148
- 'phones','numbers','selects','dates','gqlMutation'
3187
+ 'textAreas',
3188
+ 'currentData',
3189
+ 'emails',
3190
+ 'phones', 'numbers', 'selects', 'dates', 'gqlMutation'
3149
3191
  ],
3150
- emits: ['success','fieldChanged','formSubmitted','formError'],
3192
+ emits: ['success', 'fieldChanged', 'formSubmitted', 'formError'],
3151
3193
  setup(__props, { emit: __emit }) {
3152
3194
 
3153
3195
  const props = __props;
3154
3196
  const emit = __emit;
3155
3197
  const formFields = vue.ref([]);
3156
- const getFieldComponent = (fieldObj)=>{
3157
- if(fieldObj.component){
3198
+ const getFieldComponent = (fieldObj) => {
3199
+ if (fieldObj.component) {
3158
3200
  return fieldObj.component
3159
3201
  }
3160
3202
  const field = fieldObj.field ?? fieldObj.name;
3161
3203
  const defaultTextareas = ['message', 'meta_description', 'comment', 'call_response', 'comments', 'description'];
3162
3204
  const defaultNumbers = ['age'];
3163
- const passwords = ['password','password_confirmation','pin'];
3205
+ const passwords = ['password', 'password_confirmation', 'pin'];
3164
3206
  const defaultPhones = ['phone'];
3165
3207
  const defaultEmails = ['email'];
3166
3208
  const formComponents = vue.inject('formComponents');
@@ -3171,38 +3213,35 @@ const getFieldComponent = (fieldObj)=>{
3171
3213
  const NumberComponent = formComponents.number ?? script$r;
3172
3214
  const SelectComponent = formComponents.select ?? script$o;
3173
3215
  const PasswordComponent = formComponents.password ?? script$n;
3174
- if(props.customComponents && props.customComponents[field]) {
3216
+ if (props.customComponents && props.customComponents[field]) {
3175
3217
  return props.customComponents[field]
3176
3218
  }
3177
- if(props.fillSelects && props.fillSelects[field]){
3219
+ if (props.fillSelects && props.fillSelects[field]) {
3178
3220
  Object.assign(fieldObj, props.fillSelects[field]);
3179
- if(fieldObj.suggests || fieldObj.suggest){
3221
+ if (fieldObj.suggests || fieldObj.suggest) {
3180
3222
  fieldObj.type = 'suggests';
3181
3223
  } else {
3182
3224
  fieldObj.type = 'select';
3183
3225
  }
3184
3226
  }
3227
+ if(fieldObj.suggests || fieldObj.suggest){
3228
+ fieldObj.type = 'suggests';
3229
+ }
3185
3230
 
3186
- if(fieldObj.type){
3187
- if(fieldObj.type === 'suggest' || fieldObj.type === 'suggests'){
3231
+ if (fieldObj.type) {
3232
+ if (fieldObj.type === 'suggest' || fieldObj.type === 'suggests') {
3188
3233
  return script$u
3189
3234
  }
3190
- return fieldObj.type === 'number' ? NumberComponent:fieldObj.type === 'textarea' ? TextAreaComponent : fieldObj.type === 'email' ? EmailComponent : fieldObj.type === 'phone' ? PhoneComponent : fieldObj.type === 'password' ? PasswordComponent:fieldObj.type === 'select' ? SelectComponent:TextComponent
3191
- }else
3192
- if(passwords.includes(field)){
3193
- return PasswordComponent
3194
- }
3195
- else
3196
- if((props.textAreas && props.textAreas.includes(field)) || defaultTextareas.includes(field)){
3235
+ return fieldObj.type === 'number' ? NumberComponent : fieldObj.type === 'textarea' ? TextAreaComponent : fieldObj.type === 'email' ? EmailComponent : fieldObj.type === 'phone' ? PhoneComponent : fieldObj.type === 'password' ? PasswordComponent : fieldObj.type === 'select' ? SelectComponent : TextComponent
3236
+ } else if (passwords.includes(field)) {
3237
+ return PasswordComponent
3238
+ } else if ((props.textAreas && props.textAreas.includes(field)) || defaultTextareas.includes(field)) {
3197
3239
  return formComponents.textArea ?? script$p
3198
- } else
3199
- if((props.emails && props.emails.includes(field)) || defaultEmails.includes(field)){
3240
+ } else if ((props.emails && props.emails.includes(field)) || defaultEmails.includes(field)) {
3200
3241
  return formComponents.email ?? script$s
3201
- } else
3202
- if((props.phones && props.phones.includes(field)) || defaultPhones.includes(field)){
3242
+ } else if ((props.phones && props.phones.includes(field)) || defaultPhones.includes(field)) {
3203
3243
  return formComponents.phone ?? script$v
3204
- } else
3205
- if((props.numbers && props.numbers.includes(field)) || defaultNumbers.includes(field)){
3244
+ } else if ((props.numbers && props.numbers.includes(field)) || defaultNumbers.includes(field)) {
3206
3245
  return formComponents.number ?? script$r
3207
3246
  }
3208
3247
  // else
@@ -3220,20 +3259,20 @@ const shAutoForm = vue.ref(null);
3220
3259
  const closeModal = e => {
3221
3260
  setTimeout(() => {
3222
3261
  const modal = shAutoForm.value.closest('.modal-dialog');
3223
- if(modal){
3262
+ if (modal) {
3224
3263
  const closeBtn = modal.querySelector('[data-bs-dismiss="modal"]');
3225
3264
  closeBtn && closeBtn.click();
3226
3265
  }
3227
3266
  }, 1500);
3228
3267
  };
3229
- const getLabel = field => (props.labels && (props.labels[field] !== undefined)) ? props.labels[field]:___default["default"].startCase(___default["default"].camelCase(field));
3230
- const getComponentClass = field => validationErrors.value[field] ? getElementClass('formControl') + ' is-invalid':getElementClass('formControl');
3231
- const getHelperText = field => (props.helperTexts && props.helperTexts[field]) ? props.helperTexts[field]:false;
3232
- const getElementClass = section => (props.formClasses && props.formClasses[section]) ? props.formClasses[section]:shFormElementClasses.value[section] ?? ___default["default"].snakeCase(section).replace(/_/gi,'-');
3268
+ const getLabel = field => (props.labels && (props.labels[field] !== undefined)) ? props.labels[field] : ___default["default"].startCase(___default["default"].camelCase(field));
3269
+ const getComponentClass = field => validationErrors.value[field] ? getElementClass('formControl') + ' is-invalid' : getElementClass('formControl');
3270
+ const getHelperText = field => (props.helperTexts && props.helperTexts[field]) ? props.helperTexts[field] : false;
3271
+ const getElementClass = section => (props.formClasses && props.formClasses[section]) ? props.formClasses[section] : shFormElementClasses.value[section] ?? ___default["default"].snakeCase(section).replace(/_/gi, '-');
3233
3272
  const getPlaceholder = field => (props.placeHolders && props.placeHolders[field]) && props.placeHolders[field];
3234
3273
  const fieldChanged = field => {
3235
- delete validationErrors.value[field];
3236
- emit('fieldChanged', field, formFields.value.filter(f=>f.field === field)[0].value);
3274
+ delete validationErrors.value[field];
3275
+ emit('fieldChanged', field, formFields.value.filter(f => f.field === field)[0].value);
3237
3276
  };
3238
3277
  const getComponentProps = field => {
3239
3278
  const newField = {...field};
@@ -3252,57 +3291,58 @@ const submitForm = e => {
3252
3291
  e.preventDefault();
3253
3292
  loading.value = true;
3254
3293
  const data = {};
3255
- formFields.value.map(field=>{
3294
+ formFields.value.map(field => {
3256
3295
  data[field.field] = field.value;
3257
3296
  });
3258
- if(props.gqlMutation) {
3297
+ if (props.gqlMutation) {
3259
3298
  let args = `(`;
3260
3299
  let selectFields = Object.keys(data);
3261
- selectFields.forEach(key=>{
3262
- if(data[key]) {
3263
- args +=`${key}: "${data[key]}",`;
3300
+ selectFields.forEach(key => {
3301
+ if (data[key]) {
3302
+ args += `${key}: "${data[key]}",`;
3264
3303
  }
3265
3304
  });
3266
- args+=`)`;
3267
- args = args.replace(',)',')');
3268
- if(args == '()') {
3305
+ args += `)`;
3306
+ args = args.replace(',)', ')');
3307
+ if (args == '()') {
3269
3308
  args = '';
3270
3309
  }
3271
3310
  const mutation = `{\n${props.gqlMutation} ${args} {\n${selectFields.join(`\n`)}\n}\n}`;
3272
- shApis.graphQlMutate(mutation).then(res=>handleSuccessRequest(res)).catch(reason=>handlefailedRequest(reason));
3311
+ shApis.graphQlMutate(mutation).then(res => handleSuccessRequest(res)).catch(reason => handlefailedRequest(reason));
3273
3312
  } else {
3274
- shApis.doPost(props.action,data).then(res=>handleSuccessRequest(res)).catch(reason=>handlefailedRequest(reason));
3313
+ shApis.doPost(props.action, data).then(res => handleSuccessRequest(res)).catch(reason => handlefailedRequest(reason));
3275
3314
  }
3276
3315
  return false
3277
3316
  };
3278
3317
 
3279
- const handleSuccessRequest = res=>{
3318
+ const handleSuccessRequest = res => {
3280
3319
  loading.value = false;
3281
- emit('formSubmitted',res.data);
3282
- emit('success',res.data);
3320
+ emit('formSubmitted', res.data);
3321
+ emit('success', res.data);
3283
3322
  props.successMessage && shRepo.showToast(props.successMessage);
3284
3323
  props.successCallback && props.successCallback(res.data);
3285
- !props.retainDataAfterSubmission && formFields.value.map(field=>field.value = null);
3324
+ !props.retainDataAfterSubmission && formFields.value.map(field => field.value = null);
3286
3325
  closeModal();
3287
3326
  };
3288
3327
 
3289
- const handlefailedRequest = reason=>{
3328
+ const handlefailedRequest = reason => {
3290
3329
  loading.value = false;
3291
- const httpStatus = reason.response ? reason.response.status:0;
3292
- formError.value = httpStatus === 422 ? formError.value = null:reason.message ?? null;
3330
+ const httpStatus = reason.response ? reason.response.status : 0;
3331
+ formError.value = httpStatus === 422 ? formError.value = null : reason.message ?? null;
3293
3332
  let httpErrors = {};
3294
3333
  httpStatus === 422 && typeof reason.response.data.errors === 'object' && (httpErrors = reason.response.data.errors);
3295
- if(httpErrors && reason.response){
3296
- Object.keys(httpErrors).map(key=>validationErrors.value[key] = typeof httpErrors[key] === 'string' ? httpErrors[key]:httpErrors[key][0]);
3334
+ if (httpErrors && reason.response) {
3335
+ Object.keys(httpErrors).map(key => validationErrors.value[key] = typeof httpErrors[key] === 'string' ? httpErrors[key] : httpErrors[key][0]);
3297
3336
  }
3298
- (httpStatus !== 422 && formError.value) && shRepo.showToast(formError.value,'error');
3337
+ (httpStatus !== 422 && formError.value) && shRepo.showToast(formError.value, 'error');
3299
3338
  validationErrors.value;
3300
3339
  };
3301
3340
  const submitBtnWidth = vue.ref(null);
3302
- const setExistingData = (existingData)=>{
3303
- if (props.currentData) {
3304
- const newFields = formFields.value.map(fl=>{
3305
- if(existingData[fl.field]) {
3341
+ const setExistingData = (existingData) => {
3342
+ console.log(existingData,props);
3343
+ if (existingData) {
3344
+ const newFields = formFields.value.map(fl => {
3345
+ if (existingData[fl.field]) {
3306
3346
  fl.value = existingData[fl.field];
3307
3347
  }
3308
3348
  return fl
@@ -3314,13 +3354,15 @@ const setExistingData = (existingData)=>{
3314
3354
  formFields.value = newFields;
3315
3355
  }
3316
3356
  };
3317
- vue.watch(()=>props.currentData,(newData)=>{
3357
+ vue.watch(() => props.currentData, (newData) => {
3318
3358
  setExistingData(newData);
3319
3359
  });
3320
- vue.onMounted((ev)=>{
3321
- props.fields && props.fields.map(field=>{
3322
- if(typeof field === 'object') {
3323
- const fieldObj = {...field};
3360
+ vue.onMounted((ev) => {
3361
+ console.log(props);
3362
+ props.fields && props.fields.map(field => {
3363
+ let fieldObj = {};
3364
+ if (typeof field === 'object') {
3365
+ fieldObj = {...field};
3324
3366
  fieldObj.field = fieldObj.field ?? fieldObj.name;
3325
3367
  // fieldObj.label && getLabel(fieldObj.field)
3326
3368
  fieldObj.helper = fieldObj.helperText ?? fieldObj.helper;
@@ -3329,15 +3371,19 @@ vue.onMounted((ev)=>{
3329
3371
  fieldObj.label = fieldObj.label ?? getLabel(fieldObj.field ?? fieldObj.name);
3330
3372
  // fieldObj.placeholder && fieldObj.placeHolder && getPlaceholder(fieldObj.field)
3331
3373
  fieldObj.value = null;
3332
- formFields.value.push(fieldObj);
3333
3374
  } else {
3334
- formFields.value.push({
3335
- field:field,label: getLabel(field),
3375
+ fieldObj = {
3376
+ field: field, label: getLabel(field),
3336
3377
  helper: getHelperText(field),
3337
3378
  placeholder: getPlaceholder(field),
3338
3379
  value: null
3339
- });
3380
+ };
3381
+
3382
+ if(props.fillSelects && props.fillSelects[fieldObj.field]){
3383
+ Object.assign(fieldObj, props.fillSelects[fieldObj.field]);
3384
+ }
3340
3385
  }
3386
+ formFields.value.push(fieldObj);
3341
3387
  formFields.value.push({
3342
3388
  field: 'id',
3343
3389
  type: 'hidden'
@@ -3374,9 +3420,16 @@ return (_ctx, _cache) => {
3374
3420
  (!vue.unref(isFloating) && field.label)
3375
3421
  ? (vue.openBlock(), vue.createElementBlock("label", {
3376
3422
  key: 0,
3377
- class: vue.normalizeClass(getElementClass('formLabel')),
3378
- innerHTML: field.label
3379
- }, null, 10 /* CLASS, PROPS */, _hoisted_3$a))
3423
+ class: vue.normalizeClass(getElementClass('formLabel'))
3424
+ }, [
3425
+ vue.createElementVNode("span", {
3426
+ innerHTML: field.label,
3427
+ class: "sh-label"
3428
+ }, null, 8 /* PROPS */, _hoisted_3$a),
3429
+ (field.required)
3430
+ ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_4$a, "*"))
3431
+ : vue.createCommentVNode("v-if", true)
3432
+ ], 2 /* CLASS */))
3380
3433
  : vue.createCommentVNode("v-if", true),
3381
3434
  (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(getFieldComponent(field)), vue.mergeProps(getComponentProps(field), {
3382
3435
  isInvalid: typeof validationErrors.value[field.field] !== 'undefined',
@@ -3390,17 +3443,17 @@ return (_ctx, _cache) => {
3390
3443
  key: 1,
3391
3444
  class: vue.normalizeClass(getElementClass('formLabel')),
3392
3445
  innerHTML: field.label
3393
- }, null, 10 /* CLASS, PROPS */, _hoisted_4$a))
3446
+ }, null, 10 /* CLASS, PROPS */, _hoisted_5$8))
3394
3447
  : vue.createCommentVNode("v-if", true),
3395
3448
  (vue.unref(isFloating))
3396
- ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_5$8, [..._hoisted_9$5]))
3449
+ ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_6$7, [..._hoisted_10$4]))
3397
3450
  : vue.createCommentVNode("v-if", true),
3398
3451
  (field.helper)
3399
3452
  ? (vue.openBlock(), vue.createElementBlock("div", {
3400
3453
  key: 3,
3401
3454
  class: vue.normalizeClass(getElementClass('helperText')),
3402
3455
  innerHTML: field.helper
3403
- }, null, 10 /* CLASS, PROPS */, _hoisted_10$4))
3456
+ }, null, 10 /* CLASS, PROPS */, _hoisted_11$4))
3404
3457
  : vue.createCommentVNode("v-if", true),
3405
3458
  (validationErrors.value[field.field])
3406
3459
  ? (vue.openBlock(), vue.createElementBlock("div", {
@@ -3422,12 +3475,12 @@ return (_ctx, _cache) => {
3422
3475
  class: vue.normalizeClass(getElementClass('actionBtn'))
3423
3476
  }, [
3424
3477
  (loading.value)
3425
- ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_12$3))
3478
+ ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_13$3))
3426
3479
  : vue.createCommentVNode("v-if", true),
3427
3480
  (!loading.value)
3428
- ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_13$3, "Submit"))
3481
+ ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_14$3, "Submit"))
3429
3482
  : vue.createCommentVNode("v-if", true)
3430
- ], 14 /* CLASS, STYLE, PROPS */, _hoisted_11$4)
3483
+ ], 14 /* CLASS, STYLE, PROPS */, _hoisted_12$3)
3431
3484
  ], 2 /* CLASS */),
3432
3485
  vue.renderSlot(_ctx.$slots, "default")
3433
3486
  ], 34 /* CLASS, NEED_HYDRATION */)
package/dist/library.mjs CHANGED
@@ -3,7 +3,7 @@ import moment from 'moment';
3
3
  import Swal from 'sweetalert2';
4
4
  import { Modal, Offcanvas } from 'bootstrap';
5
5
  import NProgress from 'nprogress';
6
- import { openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, ref, onMounted, unref, normalizeClass, resolveComponent, createBlock, resolveDynamicComponent, watch, inject, mergeProps, normalizeStyle, renderSlot, createVNode, normalizeProps, guardReactiveProps, withCtx, vModelCheckbox, shallowRef, pushScopeId, popScopeId, markRaw, computed, isRef } from 'vue';
6
+ import { openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, ref, onMounted, unref, createBlock, resolveDynamicComponent, normalizeClass, resolveComponent, watch, inject, mergeProps, normalizeStyle, renderSlot, createVNode, normalizeProps, guardReactiveProps, withCtx, vModelCheckbox, shallowRef, pushScopeId, popScopeId, markRaw, computed, isRef } from 'vue';
7
7
  import _ from 'lodash';
8
8
  import { defineStore, storeToRefs } from 'pinia';
9
9
  import { useRoute, useRouter } from 'vue-router';
@@ -185,7 +185,7 @@ function showToast(message, toastType, config){
185
185
  mixinConfig[newKey] = config[key];
186
186
  });
187
187
  }
188
- console.log(mixinConfig);
188
+ // console.log(mixinConfig)
189
189
  const Toast = Swal.mixin(mixinConfig);
190
190
  // Toast.mixin({
191
191
  // position: 'top'
@@ -2037,11 +2037,11 @@ const _hoisted_1$n = {
2037
2037
  class: "dropdown sh-suggest"
2038
2038
  };
2039
2039
  const _hoisted_2$d = ["id"];
2040
- const _hoisted_3$c = { class: "badge bg-secondary m-1 sh-selected-item" };
2041
- const _hoisted_4$c = ["onClick"];
2042
- const _hoisted_5$a = ["id"];
2043
- const _hoisted_6$9 = ["id", "aria-labelledby"];
2044
- const _hoisted_7$8 = { key: 0 };
2040
+ const _hoisted_3$c = { class: "sh-suggestions-holder" };
2041
+ const _hoisted_4$c = { class: "badge bg-secondary m-1 sh-selected-item" };
2042
+ const _hoisted_5$a = ["onClick"];
2043
+ const _hoisted_6$9 = ["id"];
2044
+ const _hoisted_7$8 = ["id", "aria-labelledby"];
2045
2045
  const _hoisted_8$7 = ["onClick"];
2046
2046
  const _hoisted_9$7 = {
2047
2047
  key: 1,
@@ -2055,7 +2055,7 @@ const _hoisted_10$6 = {
2055
2055
 
2056
2056
  var script$u = {
2057
2057
  __name: 'ShSuggest',
2058
- props: ['data','allowMultiple','url','modelValue'],
2058
+ props: ['data','allowMultiple','url','modelValue','optionTemplate'],
2059
2059
  emits: ['update:modelValue'],
2060
2060
  setup(__props, { emit: __emit }) {
2061
2061
 
@@ -2068,6 +2068,11 @@ let selectedSuggestions = ref([]);
2068
2068
  onMounted(() => {
2069
2069
  id.value = 'sid' + (Math.random() + 1).toString(36).substring(7);
2070
2070
  resetData();
2071
+ if(props.url){
2072
+ fetchRemoteData();
2073
+ } else {
2074
+ initializeExisting();
2075
+ }
2071
2076
  });
2072
2077
  function resetData(){
2073
2078
  const data = props.data;
@@ -2131,10 +2136,10 @@ const fetchRemoteData = ()=>{
2131
2136
  const data = {
2132
2137
  all: 1,
2133
2138
  filter_value: searchText.value,
2134
- here: 'three'
2135
2139
  };
2136
2140
  shApis.doGet(props.url, data).then(res => {
2137
2141
  suggestions.value = res.data.data ?? res.data;
2142
+ initializeExisting();
2138
2143
  }).catch(res => {
2139
2144
  console.log(res);
2140
2145
  });
@@ -2153,36 +2158,60 @@ const hideDropDown = ()=>{
2153
2158
  }
2154
2159
  };
2155
2160
 
2161
+ const initializeExisting = ()=>{
2162
+ console.log(props);
2163
+ if(props.modelValue && suggestions.value){
2164
+ if(props.allowMultiple){
2165
+ let selected = [];
2166
+ props.modelValue.forEach(id=>{
2167
+ let found = suggestions.value.find(sgt=>{
2168
+ return sgt.id === id
2169
+ });
2170
+ if(found){
2171
+ selected.push(found);
2172
+ }
2173
+ });
2174
+ selectedSuggestions.value = selected;
2175
+ } else {
2176
+ let found = suggestions.value.find(sgt=>{
2177
+ return sgt.id === props.modelValue
2178
+ });
2179
+ if(found){
2180
+ selectedSuggestions.value = [found];
2181
+ }
2182
+ }
2183
+ }
2184
+ };
2185
+
2156
2186
  return (_ctx, _cache) => {
2157
2187
  return (unref(id))
2158
2188
  ? (openBlock(), createElementBlock("div", _hoisted_1$n, [
2159
2189
  createElementVNode("div", {
2160
2190
  id: unref(id),
2161
2191
  "data-bs-toggle": "dropdown",
2162
- class: "form-control p-0 d-flex sh-suggest-control dropdown-toggle",
2192
+ class: "p-0 d-flex sh-suggest-control dropdown-toggle",
2163
2193
  "aria-expanded": "false"
2164
2194
  }, [
2165
- createElementVNode("div", null, [
2195
+ createElementVNode("div", _hoisted_3$c, [
2166
2196
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(selectedSuggestions), (sgt) => {
2167
- return (openBlock(), createElementBlock("h5", _hoisted_3$c, [
2197
+ return (openBlock(), createElementBlock("h5", _hoisted_4$c, [
2168
2198
  createTextVNode(toDisplayString(sgt.name) + " ", 1 /* TEXT */),
2169
2199
  createElementVNode("button", {
2170
2200
  onClick: $event => (removeSuggestion(sgt.id)),
2171
2201
  type: "button",
2172
2202
  class: "btn-close border-start border-1 ms-1",
2173
2203
  "aria-label": "Close"
2174
- }, null, 8 /* PROPS */, _hoisted_4$c)
2204
+ }, null, 8 /* PROPS */, _hoisted_5$a)
2175
2205
  ]))
2176
2206
  }), 256 /* UNKEYED_FRAGMENT */))
2177
2207
  ]),
2178
2208
  createElementVNode("div", {
2179
2209
  id: 'input_' + unref(id),
2180
2210
  contenteditable: "true",
2181
- onClick: filterData,
2182
2211
  onInput: filterData,
2183
2212
  onChange: filterData,
2184
2213
  class: "flex-fill h-100 sh-suggestion-input"
2185
- }, null, 40 /* PROPS, NEED_HYDRATION */, _hoisted_5$a)
2214
+ }, null, 40 /* PROPS, NEED_HYDRATION */, _hoisted_6$9)
2186
2215
  ], 8 /* PROPS */, _hoisted_2$d),
2187
2216
  createElementVNode("ul", {
2188
2217
  class: "dropdown-menu w-100",
@@ -2195,21 +2224,29 @@ return (_ctx, _cache) => {
2195
2224
  key: suggestion.id
2196
2225
  }, [
2197
2226
  (suggestion.name)
2198
- ? (openBlock(), createElementBlock("li", _hoisted_7$8, [
2199
- createElementVNode("span", {
2200
- style: {"cursor":"pointer"},
2201
- onClick: $event => (addSuggestion(suggestion)),
2202
- class: normalizeClass(["dropdown-item", unref(selectedSuggestions).includes(suggestion) ? 'active':'']),
2203
- href: "#"
2204
- }, toDisplayString(suggestion.name ?? suggestion.text), 11 /* TEXT, CLASS, PROPS */, _hoisted_8$7)
2205
- ]))
2227
+ ? (openBlock(), createElementBlock("li", {
2228
+ key: 0,
2229
+ onClick: $event => (addSuggestion(suggestion))
2230
+ }, [
2231
+ (__props.optionTemplate)
2232
+ ? (openBlock(), createBlock(resolveDynamicComponent(__props.optionTemplate), {
2233
+ key: 0,
2234
+ option: suggestion
2235
+ }, null, 8 /* PROPS */, ["option"]))
2236
+ : (openBlock(), createElementBlock("span", {
2237
+ key: 1,
2238
+ style: {"cursor":"pointer"},
2239
+ class: normalizeClass(["dropdown-item", unref(selectedSuggestions).includes(suggestion) ? 'active':'']),
2240
+ href: "#"
2241
+ }, toDisplayString(suggestion.name ?? suggestion.text), 3 /* TEXT, CLASS */))
2242
+ ], 8 /* PROPS */, _hoisted_8$7))
2206
2243
  : createCommentVNode("v-if", true)
2207
2244
  ], 64 /* STABLE_FRAGMENT */))
2208
2245
  }), 128 /* KEYED_FRAGMENT */))
2209
2246
  : (unref(searchText))
2210
2247
  ? (openBlock(), createElementBlock("li", _hoisted_9$7, " No results found "))
2211
2248
  : (openBlock(), createElementBlock("li", _hoisted_10$6, " Type to search... "))
2212
- ], 8 /* PROPS */, _hoisted_6$9)
2249
+ ], 8 /* PROPS */, _hoisted_7$8)
2213
2250
  ]))
2214
2251
  : createCommentVNode("v-if", true)
2215
2252
  }
@@ -2569,7 +2606,7 @@ const _hoisted_10$5 = ["data-cy", "placeholder", "name", "onFocus", "onChange"];
2569
2606
  const _hoisted_11$5 = ["data-cy", "placeholder", "name", "onFocus", "onUpdate:modelValue"];
2570
2607
  const _hoisted_12$4 = ["data-cy", "placeholder", "name", "onFocus", "onUpdate:modelValue"];
2571
2608
  const _hoisted_13$4 = ["data-cy", "placeholder", "name", "onFocus", "onUpdate:modelValue"];
2572
- const _hoisted_14$3 = ["data-cy", "name", "onFocus", "onUpdate:modelValue"];
2609
+ const _hoisted_14$4 = ["data-cy", "name", "onFocus", "onUpdate:modelValue"];
2573
2610
  const _hoisted_15$3 = ["disabled", "placeholder", "name", "onFocus", "onUpdate:modelValue"];
2574
2611
  const _hoisted_16$3 = ["name", "onFocus", "onUpdate:modelValue"];
2575
2612
  const _hoisted_17$3 = ["name", "onFocus", "onUpdate:modelValue"];
@@ -2715,7 +2752,7 @@ function render$2(_ctx, _cache, $props, $setup, $data, $options) {
2715
2752
  onFocus: $event => ($options.removeErrors(field)),
2716
2753
  class: normalizeClass([_ctx.form_errors[field] == null ? ' field_' + field:'is-invalid ' + field, "form-control active"]),
2717
2754
  "onUpdate:modelValue": $event => ((_ctx.form_elements[field]) = $event)
2718
- }, null, 42 /* CLASS, PROPS, NEED_HYDRATION */, _hoisted_14$3)), [
2755
+ }, null, 42 /* CLASS, PROPS, NEED_HYDRATION */, _hoisted_14$4)), [
2719
2756
  [vModelText, _ctx.form_elements[field]]
2720
2757
  ])
2721
2758
  : createCommentVNode("v-if", true),
@@ -2993,7 +3030,7 @@ const _hoisted_1$k = ["value"];
2993
3030
 
2994
3031
  var script$o = {
2995
3032
  __name: 'SelectInput',
2996
- props: ['modelValue','label','data','dataUrl'],
3033
+ props: ['modelValue','label','url','required','options','dataUrl','data'],
2997
3034
  emits: ['update:modelValue','clearValidationErrors'],
2998
3035
  setup(__props, { emit: __emit }) {
2999
3036
 
@@ -3006,6 +3043,7 @@ const modelValueUpdated = (e) => {
3006
3043
  emit('update:modelValue',inputModel);
3007
3044
  };
3008
3045
  onMounted(()=>{
3046
+ console.log(props);
3009
3047
  props.modelValue && (inputModel.value = props.modelValue);
3010
3048
  const options = props.data ?? props.options;
3011
3049
  if(options){
@@ -3015,8 +3053,8 @@ onMounted(()=>{
3015
3053
  name: item.label ? item.label : item.name ? item.name : item.value ? item.value:item.id ? item.id:item.option
3016
3054
  }
3017
3055
  });
3018
- } else if (props.dataUrl){
3019
- shApis.doGet(props.dataUrl,{all:1}).then(res=>{
3056
+ } else if (props.dataUrl || props.url) {
3057
+ shApis.doGet(props.dataUrl ?? props.url,{all:1}).then(res=>{
3020
3058
  selectOptions.value = res.data.map(item=>{
3021
3059
  return {
3022
3060
  id: item.id ? item.id : item.key ? item.key : item.value ? item.value:item.name ? item.name:item.label,
@@ -3096,59 +3134,63 @@ script$n.__file = "src/lib/components/form-components/PasswordInput.vue";
3096
3134
  const _hoisted_1$j = /*#__PURE__*/createElementVNode("div", null, null, -1 /* HOISTED */);
3097
3135
  const _hoisted_2$b = ["onUpdate:modelValue"];
3098
3136
  const _hoisted_3$a = ["innerHTML"];
3099
- const _hoisted_4$a = ["innerHTML"];
3100
- const _hoisted_5$8 = {
3137
+ const _hoisted_4$a = {
3138
+ key: 0,
3139
+ class: "text-danger sh-required"
3140
+ };
3141
+ const _hoisted_5$8 = ["innerHTML"];
3142
+ const _hoisted_6$7 = {
3101
3143
  key: 2,
3102
3144
  class: "form-notch"
3103
3145
  };
3104
- const _hoisted_6$7 = /*#__PURE__*/createElementVNode("div", { class: "form-notch-leading" }, null, -1 /* HOISTED */);
3105
- const _hoisted_7$6 = /*#__PURE__*/createElementVNode("div", { class: "form-notch-middle" }, null, -1 /* HOISTED */);
3106
- const _hoisted_8$5 = /*#__PURE__*/createElementVNode("div", { class: "form-notch-trailing" }, null, -1 /* HOISTED */);
3107
- const _hoisted_9$5 = [
3108
- _hoisted_6$7,
3146
+ const _hoisted_7$6 = /*#__PURE__*/createElementVNode("div", { class: "form-notch-leading" }, null, -1 /* HOISTED */);
3147
+ const _hoisted_8$5 = /*#__PURE__*/createElementVNode("div", { class: "form-notch-middle" }, null, -1 /* HOISTED */);
3148
+ const _hoisted_9$5 = /*#__PURE__*/createElementVNode("div", { class: "form-notch-trailing" }, null, -1 /* HOISTED */);
3149
+ const _hoisted_10$4 = [
3109
3150
  _hoisted_7$6,
3110
- _hoisted_8$5
3151
+ _hoisted_8$5,
3152
+ _hoisted_9$5
3111
3153
  ];
3112
- const _hoisted_10$4 = ["innerHTML"];
3113
- const _hoisted_11$4 = ["disabled"];
3114
- const _hoisted_12$3 = {
3154
+ const _hoisted_11$4 = ["innerHTML"];
3155
+ const _hoisted_12$3 = ["disabled"];
3156
+ const _hoisted_13$3 = {
3115
3157
  key: 0,
3116
3158
  class: "spinner-border spinner-border-sm",
3117
3159
  role: "status",
3118
3160
  "aria-hidden": "true"
3119
3161
  };
3120
- const _hoisted_13$3 = { key: 1 };
3162
+ const _hoisted_14$3 = { key: 1 };
3121
3163
 
3122
3164
 
3123
3165
  var script$m = {
3124
3166
  __name: 'ShAutoForm',
3125
3167
  props: [
3126
- 'action','successCallback','retainDataAfterSubmission',
3127
- 'successMessage','fields','customComponents','placeHolders',
3168
+ 'action', 'successCallback', 'retainDataAfterSubmission',
3169
+ 'successMessage', 'fields', 'customComponents', 'placeHolders',
3128
3170
  'formClasses',
3129
- 'helperTexts','labels','data',
3171
+ 'helperTexts', 'labels', 'data',
3130
3172
  'fillSelects',
3131
3173
  'formClass',
3132
3174
  'actionLabel',
3133
- 'textAreas',
3134
- 'currentData',
3135
- 'emails',
3136
- 'phones','numbers','selects','dates','gqlMutation'
3175
+ 'textAreas',
3176
+ 'currentData',
3177
+ 'emails',
3178
+ 'phones', 'numbers', 'selects', 'dates', 'gqlMutation'
3137
3179
  ],
3138
- emits: ['success','fieldChanged','formSubmitted','formError'],
3180
+ emits: ['success', 'fieldChanged', 'formSubmitted', 'formError'],
3139
3181
  setup(__props, { emit: __emit }) {
3140
3182
 
3141
3183
  const props = __props;
3142
3184
  const emit = __emit;
3143
3185
  const formFields = ref([]);
3144
- const getFieldComponent = (fieldObj)=>{
3145
- if(fieldObj.component){
3186
+ const getFieldComponent = (fieldObj) => {
3187
+ if (fieldObj.component) {
3146
3188
  return fieldObj.component
3147
3189
  }
3148
3190
  const field = fieldObj.field ?? fieldObj.name;
3149
3191
  const defaultTextareas = ['message', 'meta_description', 'comment', 'call_response', 'comments', 'description'];
3150
3192
  const defaultNumbers = ['age'];
3151
- const passwords = ['password','password_confirmation','pin'];
3193
+ const passwords = ['password', 'password_confirmation', 'pin'];
3152
3194
  const defaultPhones = ['phone'];
3153
3195
  const defaultEmails = ['email'];
3154
3196
  const formComponents = inject('formComponents');
@@ -3159,38 +3201,35 @@ const getFieldComponent = (fieldObj)=>{
3159
3201
  const NumberComponent = formComponents.number ?? script$r;
3160
3202
  const SelectComponent = formComponents.select ?? script$o;
3161
3203
  const PasswordComponent = formComponents.password ?? script$n;
3162
- if(props.customComponents && props.customComponents[field]) {
3204
+ if (props.customComponents && props.customComponents[field]) {
3163
3205
  return props.customComponents[field]
3164
3206
  }
3165
- if(props.fillSelects && props.fillSelects[field]){
3207
+ if (props.fillSelects && props.fillSelects[field]) {
3166
3208
  Object.assign(fieldObj, props.fillSelects[field]);
3167
- if(fieldObj.suggests || fieldObj.suggest){
3209
+ if (fieldObj.suggests || fieldObj.suggest) {
3168
3210
  fieldObj.type = 'suggests';
3169
3211
  } else {
3170
3212
  fieldObj.type = 'select';
3171
3213
  }
3172
3214
  }
3215
+ if(fieldObj.suggests || fieldObj.suggest){
3216
+ fieldObj.type = 'suggests';
3217
+ }
3173
3218
 
3174
- if(fieldObj.type){
3175
- if(fieldObj.type === 'suggest' || fieldObj.type === 'suggests'){
3219
+ if (fieldObj.type) {
3220
+ if (fieldObj.type === 'suggest' || fieldObj.type === 'suggests') {
3176
3221
  return script$u
3177
3222
  }
3178
- return fieldObj.type === 'number' ? NumberComponent:fieldObj.type === 'textarea' ? TextAreaComponent : fieldObj.type === 'email' ? EmailComponent : fieldObj.type === 'phone' ? PhoneComponent : fieldObj.type === 'password' ? PasswordComponent:fieldObj.type === 'select' ? SelectComponent:TextComponent
3179
- }else
3180
- if(passwords.includes(field)){
3181
- return PasswordComponent
3182
- }
3183
- else
3184
- if((props.textAreas && props.textAreas.includes(field)) || defaultTextareas.includes(field)){
3223
+ return fieldObj.type === 'number' ? NumberComponent : fieldObj.type === 'textarea' ? TextAreaComponent : fieldObj.type === 'email' ? EmailComponent : fieldObj.type === 'phone' ? PhoneComponent : fieldObj.type === 'password' ? PasswordComponent : fieldObj.type === 'select' ? SelectComponent : TextComponent
3224
+ } else if (passwords.includes(field)) {
3225
+ return PasswordComponent
3226
+ } else if ((props.textAreas && props.textAreas.includes(field)) || defaultTextareas.includes(field)) {
3185
3227
  return formComponents.textArea ?? script$p
3186
- } else
3187
- if((props.emails && props.emails.includes(field)) || defaultEmails.includes(field)){
3228
+ } else if ((props.emails && props.emails.includes(field)) || defaultEmails.includes(field)) {
3188
3229
  return formComponents.email ?? script$s
3189
- } else
3190
- if((props.phones && props.phones.includes(field)) || defaultPhones.includes(field)){
3230
+ } else if ((props.phones && props.phones.includes(field)) || defaultPhones.includes(field)) {
3191
3231
  return formComponents.phone ?? script$v
3192
- } else
3193
- if((props.numbers && props.numbers.includes(field)) || defaultNumbers.includes(field)){
3232
+ } else if ((props.numbers && props.numbers.includes(field)) || defaultNumbers.includes(field)) {
3194
3233
  return formComponents.number ?? script$r
3195
3234
  }
3196
3235
  // else
@@ -3208,20 +3247,20 @@ const shAutoForm = ref(null);
3208
3247
  const closeModal = e => {
3209
3248
  setTimeout(() => {
3210
3249
  const modal = shAutoForm.value.closest('.modal-dialog');
3211
- if(modal){
3250
+ if (modal) {
3212
3251
  const closeBtn = modal.querySelector('[data-bs-dismiss="modal"]');
3213
3252
  closeBtn && closeBtn.click();
3214
3253
  }
3215
3254
  }, 1500);
3216
3255
  };
3217
- const getLabel = field => (props.labels && (props.labels[field] !== undefined)) ? props.labels[field]:_.startCase(_.camelCase(field));
3218
- const getComponentClass = field => validationErrors.value[field] ? getElementClass('formControl') + ' is-invalid':getElementClass('formControl');
3219
- const getHelperText = field => (props.helperTexts && props.helperTexts[field]) ? props.helperTexts[field]:false;
3220
- const getElementClass = section => (props.formClasses && props.formClasses[section]) ? props.formClasses[section]:shFormElementClasses.value[section] ?? _.snakeCase(section).replace(/_/gi,'-');
3256
+ const getLabel = field => (props.labels && (props.labels[field] !== undefined)) ? props.labels[field] : _.startCase(_.camelCase(field));
3257
+ const getComponentClass = field => validationErrors.value[field] ? getElementClass('formControl') + ' is-invalid' : getElementClass('formControl');
3258
+ const getHelperText = field => (props.helperTexts && props.helperTexts[field]) ? props.helperTexts[field] : false;
3259
+ const getElementClass = section => (props.formClasses && props.formClasses[section]) ? props.formClasses[section] : shFormElementClasses.value[section] ?? _.snakeCase(section).replace(/_/gi, '-');
3221
3260
  const getPlaceholder = field => (props.placeHolders && props.placeHolders[field]) && props.placeHolders[field];
3222
3261
  const fieldChanged = field => {
3223
- delete validationErrors.value[field];
3224
- emit('fieldChanged', field, formFields.value.filter(f=>f.field === field)[0].value);
3262
+ delete validationErrors.value[field];
3263
+ emit('fieldChanged', field, formFields.value.filter(f => f.field === field)[0].value);
3225
3264
  };
3226
3265
  const getComponentProps = field => {
3227
3266
  const newField = {...field};
@@ -3240,57 +3279,58 @@ const submitForm = e => {
3240
3279
  e.preventDefault();
3241
3280
  loading.value = true;
3242
3281
  const data = {};
3243
- formFields.value.map(field=>{
3282
+ formFields.value.map(field => {
3244
3283
  data[field.field] = field.value;
3245
3284
  });
3246
- if(props.gqlMutation) {
3285
+ if (props.gqlMutation) {
3247
3286
  let args = `(`;
3248
3287
  let selectFields = Object.keys(data);
3249
- selectFields.forEach(key=>{
3250
- if(data[key]) {
3251
- args +=`${key}: "${data[key]}",`;
3288
+ selectFields.forEach(key => {
3289
+ if (data[key]) {
3290
+ args += `${key}: "${data[key]}",`;
3252
3291
  }
3253
3292
  });
3254
- args+=`)`;
3255
- args = args.replace(',)',')');
3256
- if(args == '()') {
3293
+ args += `)`;
3294
+ args = args.replace(',)', ')');
3295
+ if (args == '()') {
3257
3296
  args = '';
3258
3297
  }
3259
3298
  const mutation = `{\n${props.gqlMutation} ${args} {\n${selectFields.join(`\n`)}\n}\n}`;
3260
- shApis.graphQlMutate(mutation).then(res=>handleSuccessRequest(res)).catch(reason=>handlefailedRequest(reason));
3299
+ shApis.graphQlMutate(mutation).then(res => handleSuccessRequest(res)).catch(reason => handlefailedRequest(reason));
3261
3300
  } else {
3262
- shApis.doPost(props.action,data).then(res=>handleSuccessRequest(res)).catch(reason=>handlefailedRequest(reason));
3301
+ shApis.doPost(props.action, data).then(res => handleSuccessRequest(res)).catch(reason => handlefailedRequest(reason));
3263
3302
  }
3264
3303
  return false
3265
3304
  };
3266
3305
 
3267
- const handleSuccessRequest = res=>{
3306
+ const handleSuccessRequest = res => {
3268
3307
  loading.value = false;
3269
- emit('formSubmitted',res.data);
3270
- emit('success',res.data);
3308
+ emit('formSubmitted', res.data);
3309
+ emit('success', res.data);
3271
3310
  props.successMessage && shRepo.showToast(props.successMessage);
3272
3311
  props.successCallback && props.successCallback(res.data);
3273
- !props.retainDataAfterSubmission && formFields.value.map(field=>field.value = null);
3312
+ !props.retainDataAfterSubmission && formFields.value.map(field => field.value = null);
3274
3313
  closeModal();
3275
3314
  };
3276
3315
 
3277
- const handlefailedRequest = reason=>{
3316
+ const handlefailedRequest = reason => {
3278
3317
  loading.value = false;
3279
- const httpStatus = reason.response ? reason.response.status:0;
3280
- formError.value = httpStatus === 422 ? formError.value = null:reason.message ?? null;
3318
+ const httpStatus = reason.response ? reason.response.status : 0;
3319
+ formError.value = httpStatus === 422 ? formError.value = null : reason.message ?? null;
3281
3320
  let httpErrors = {};
3282
3321
  httpStatus === 422 && typeof reason.response.data.errors === 'object' && (httpErrors = reason.response.data.errors);
3283
- if(httpErrors && reason.response){
3284
- Object.keys(httpErrors).map(key=>validationErrors.value[key] = typeof httpErrors[key] === 'string' ? httpErrors[key]:httpErrors[key][0]);
3322
+ if (httpErrors && reason.response) {
3323
+ Object.keys(httpErrors).map(key => validationErrors.value[key] = typeof httpErrors[key] === 'string' ? httpErrors[key] : httpErrors[key][0]);
3285
3324
  }
3286
- (httpStatus !== 422 && formError.value) && shRepo.showToast(formError.value,'error');
3325
+ (httpStatus !== 422 && formError.value) && shRepo.showToast(formError.value, 'error');
3287
3326
  validationErrors.value;
3288
3327
  };
3289
3328
  const submitBtnWidth = ref(null);
3290
- const setExistingData = (existingData)=>{
3291
- if (props.currentData) {
3292
- const newFields = formFields.value.map(fl=>{
3293
- if(existingData[fl.field]) {
3329
+ const setExistingData = (existingData) => {
3330
+ console.log(existingData,props);
3331
+ if (existingData) {
3332
+ const newFields = formFields.value.map(fl => {
3333
+ if (existingData[fl.field]) {
3294
3334
  fl.value = existingData[fl.field];
3295
3335
  }
3296
3336
  return fl
@@ -3302,13 +3342,15 @@ const setExistingData = (existingData)=>{
3302
3342
  formFields.value = newFields;
3303
3343
  }
3304
3344
  };
3305
- watch(()=>props.currentData,(newData)=>{
3345
+ watch(() => props.currentData, (newData) => {
3306
3346
  setExistingData(newData);
3307
3347
  });
3308
- onMounted((ev)=>{
3309
- props.fields && props.fields.map(field=>{
3310
- if(typeof field === 'object') {
3311
- const fieldObj = {...field};
3348
+ onMounted((ev) => {
3349
+ console.log(props);
3350
+ props.fields && props.fields.map(field => {
3351
+ let fieldObj = {};
3352
+ if (typeof field === 'object') {
3353
+ fieldObj = {...field};
3312
3354
  fieldObj.field = fieldObj.field ?? fieldObj.name;
3313
3355
  // fieldObj.label && getLabel(fieldObj.field)
3314
3356
  fieldObj.helper = fieldObj.helperText ?? fieldObj.helper;
@@ -3317,15 +3359,19 @@ onMounted((ev)=>{
3317
3359
  fieldObj.label = fieldObj.label ?? getLabel(fieldObj.field ?? fieldObj.name);
3318
3360
  // fieldObj.placeholder && fieldObj.placeHolder && getPlaceholder(fieldObj.field)
3319
3361
  fieldObj.value = null;
3320
- formFields.value.push(fieldObj);
3321
3362
  } else {
3322
- formFields.value.push({
3323
- field:field,label: getLabel(field),
3363
+ fieldObj = {
3364
+ field: field, label: getLabel(field),
3324
3365
  helper: getHelperText(field),
3325
3366
  placeholder: getPlaceholder(field),
3326
3367
  value: null
3327
- });
3368
+ };
3369
+
3370
+ if(props.fillSelects && props.fillSelects[fieldObj.field]){
3371
+ Object.assign(fieldObj, props.fillSelects[fieldObj.field]);
3372
+ }
3328
3373
  }
3374
+ formFields.value.push(fieldObj);
3329
3375
  formFields.value.push({
3330
3376
  field: 'id',
3331
3377
  type: 'hidden'
@@ -3362,9 +3408,16 @@ return (_ctx, _cache) => {
3362
3408
  (!unref(isFloating) && field.label)
3363
3409
  ? (openBlock(), createElementBlock("label", {
3364
3410
  key: 0,
3365
- class: normalizeClass(getElementClass('formLabel')),
3366
- innerHTML: field.label
3367
- }, null, 10 /* CLASS, PROPS */, _hoisted_3$a))
3411
+ class: normalizeClass(getElementClass('formLabel'))
3412
+ }, [
3413
+ createElementVNode("span", {
3414
+ innerHTML: field.label,
3415
+ class: "sh-label"
3416
+ }, null, 8 /* PROPS */, _hoisted_3$a),
3417
+ (field.required)
3418
+ ? (openBlock(), createElementBlock("span", _hoisted_4$a, "*"))
3419
+ : createCommentVNode("v-if", true)
3420
+ ], 2 /* CLASS */))
3368
3421
  : createCommentVNode("v-if", true),
3369
3422
  (openBlock(), createBlock(resolveDynamicComponent(getFieldComponent(field)), mergeProps(getComponentProps(field), {
3370
3423
  isInvalid: typeof validationErrors.value[field.field] !== 'undefined',
@@ -3378,17 +3431,17 @@ return (_ctx, _cache) => {
3378
3431
  key: 1,
3379
3432
  class: normalizeClass(getElementClass('formLabel')),
3380
3433
  innerHTML: field.label
3381
- }, null, 10 /* CLASS, PROPS */, _hoisted_4$a))
3434
+ }, null, 10 /* CLASS, PROPS */, _hoisted_5$8))
3382
3435
  : createCommentVNode("v-if", true),
3383
3436
  (unref(isFloating))
3384
- ? (openBlock(), createElementBlock("div", _hoisted_5$8, [..._hoisted_9$5]))
3437
+ ? (openBlock(), createElementBlock("div", _hoisted_6$7, [..._hoisted_10$4]))
3385
3438
  : createCommentVNode("v-if", true),
3386
3439
  (field.helper)
3387
3440
  ? (openBlock(), createElementBlock("div", {
3388
3441
  key: 3,
3389
3442
  class: normalizeClass(getElementClass('helperText')),
3390
3443
  innerHTML: field.helper
3391
- }, null, 10 /* CLASS, PROPS */, _hoisted_10$4))
3444
+ }, null, 10 /* CLASS, PROPS */, _hoisted_11$4))
3392
3445
  : createCommentVNode("v-if", true),
3393
3446
  (validationErrors.value[field.field])
3394
3447
  ? (openBlock(), createElementBlock("div", {
@@ -3410,12 +3463,12 @@ return (_ctx, _cache) => {
3410
3463
  class: normalizeClass(getElementClass('actionBtn'))
3411
3464
  }, [
3412
3465
  (loading.value)
3413
- ? (openBlock(), createElementBlock("span", _hoisted_12$3))
3466
+ ? (openBlock(), createElementBlock("span", _hoisted_13$3))
3414
3467
  : createCommentVNode("v-if", true),
3415
3468
  (!loading.value)
3416
- ? (openBlock(), createElementBlock("span", _hoisted_13$3, "Submit"))
3469
+ ? (openBlock(), createElementBlock("span", _hoisted_14$3, "Submit"))
3417
3470
  : createCommentVNode("v-if", true)
3418
- ], 14 /* CLASS, STYLE, PROPS */, _hoisted_11$4)
3471
+ ], 14 /* CLASS, STYLE, PROPS */, _hoisted_12$3)
3419
3472
  ], 2 /* CLASS */),
3420
3473
  renderSlot(_ctx.$slots, "default")
3421
3474
  ], 34 /* CLASS, NEED_HYDRATION */)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/shframework",
3
- "version": "4.3.6",
3
+ "version": "4.3.8",
4
4
  "description": "Vue library for handling laravel backend",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.mjs",