@iankibetsh/shframework 5.6.8 → 5.6.9

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.js CHANGED
@@ -2073,125 +2073,137 @@ const countries = [
2073
2073
  }
2074
2074
  ];
2075
2075
 
2076
- var script$A = {
2077
- name: 'PhoneInput',
2078
- props: ['modelValue', 'country_code','disabled'],
2079
- data () {
2080
- return {
2081
- input: this.modelValue,
2082
- countries: countries,
2083
- selectedCountry: {
2084
- name: 'Kenya',
2085
- dialCode: '+254',
2086
- isoCode: 'KE',
2087
- flag: 'https://www.countryflags.io/KE/flat/64.png'
2088
- },
2089
- flag: undefined.VITE_APP_HOME_URL + 'flags/ke.svg',
2090
- appUrl: undefined.VITE_APP_HOME_URL
2091
- }
2092
- },
2093
- updated () {
2094
- if (!this.selectedCountry || !this.input) ;
2095
- },
2096
- mounted () {
2097
- this.setSelectedCountry();
2098
- },
2099
- watch: {
2100
- modelValue: function(newVal){
2101
- if(!this.input){
2102
- let phone = newVal.replace('+254','');
2103
- this.input = phone.replace('+1','');
2104
- }
2105
- }
2106
- },
2107
- methods: {
2108
- updateValue: function () {
2109
- let phone = this.input;
2110
- phone = '-' + phone;
2111
- phone = phone.replace('-0', '');
2112
- phone = phone.replace('-', '');
2113
- // this.input = phone
2114
- if (this.selectedCountry) {
2115
- phone = this.selectedCountry.dialCode + '' + phone;
2116
- }
2117
- this.$emit('update:modelValue', phone);
2118
- this.flag = this.appUrl + 'flags/' + this.selectedCountry.isoCode.toLowerCase() + '.svg';
2119
- },
2120
- setSelectedCountry: function () {
2121
- let countryCode = 'KE';
2122
- if (this.country_code) {
2123
- countryCode = this.country_code;
2124
- }
2125
- this.input = this.modelValue;
2126
- const country = this.countries.find(function (country) {
2127
- if (countryCode.toUpperCase() === country.isoCode) {
2128
- return country
2129
- }
2130
- }, this);
2131
- if (this.input) {
2132
- if (!this.input.includes('+')) {
2133
- this.input = '+' + this.input;
2134
- }
2135
- this.flag = this.appUrl + 'flags/' + country.isoCode.toLowerCase() + '.svg';
2136
- this.input = this.input.replace(country.dialCode, '');
2137
- this.input = this.input.replace(':', '');
2138
- this.input = this.input.replace(':', '');
2139
- this.input = this.input.replace(':', '');
2140
- this.selectedCountry = country;
2141
- }
2142
- }
2143
- }
2144
- };
2145
-
2146
2076
  const _hoisted_1$q = {
2147
- class: "sh-phone mb-3",
2077
+ class: "sh-phone mb-3 form-control",
2148
2078
  style: {"display":"flex"}
2149
2079
  };
2150
2080
  const _hoisted_2$i = {
2151
2081
  key: 0,
2152
2082
  style: {"display":"contents"}
2153
2083
  };
2154
- const _hoisted_3$f = ["src"];
2084
+ const _hoisted_3$f = ["src", "alt"];
2155
2085
  const _hoisted_4$f = ["value"];
2156
2086
  const _hoisted_5$d = ["disabled"];
2157
2087
 
2158
- function render$4(_ctx, _cache, $props, $setup, $data, $options) {
2088
+ var script$A = {
2089
+ __name: 'PhoneInput',
2090
+ props: {
2091
+ modelValue: String,
2092
+ country_code: String,
2093
+ disabled: Boolean
2094
+ },
2095
+ emits: ['update:modelValue'],
2096
+ setup(__props, { emit: __emit }) {
2097
+
2098
+ const props = __props;
2099
+ const countryCode = vue.ref(props.country_code || 'KE');
2100
+ const emit = __emit;
2101
+ const input = vue.ref(props.modelValue);
2102
+ const countriesList = vue.ref(countries);
2103
+ const selectedCountry = vue.ref({
2104
+ name: 'Kenya',
2105
+ dialCode: '+254',
2106
+ isoCode: 'KE',
2107
+ flag: 'https://www.countryflags.io/KE/flat/64.png'
2108
+ });
2109
+ const flag = vue.computed(()=> {
2110
+ const homeUrl = undefined.VITE_APP_HOME_URL;
2111
+ if (selectedCountry.value) {
2112
+ return homeUrl + 'flags/' + selectedCountry.value.isoCode.toLowerCase() + '.svg';
2113
+ }
2114
+ }
2115
+ );
2116
+ undefined.VITE_APP_HOME_URL;
2117
+
2118
+ const updateValue = () => {
2119
+ let phone = input.value || '';
2120
+ phone = phone.replace(/^0/, '');
2121
+ if (selectedCountry.value) {
2122
+ phone = selectedCountry.value.dialCode + phone;
2123
+ }
2124
+ emit('update:modelValue', phone);
2125
+ // flag.value = appUrl + 'flags/' + selectedCountry.value.isoCode.toLowerCase() + '.svg';
2126
+ };
2127
+
2128
+ const setSelectedCountry = () => {
2129
+ input.value = props.modelValue;
2130
+ const country = countriesList.value.find(country => country.isoCode === countryCode.value.toUpperCase());
2131
+ if (country) {
2132
+ selectedCountry.value = country;
2133
+ if (input.value) {
2134
+ if (!input.value.includes('+')) {
2135
+ input.value = '+' + input.value;
2136
+ }
2137
+ // flag.value = appUrl + 'flags/' + country.isoCode.toLowerCase() + '.svg';
2138
+ input.value = input.value.replace(country.dialCode, '').replace(/:/g, '');
2139
+ }
2140
+ }
2141
+ };
2142
+
2143
+ vue.watch(() => props.modelValue, (newVal) => {
2144
+ if (!input.value) {
2145
+ input.value = newVal.replace('+254', '').replace('+1', '');
2146
+ }
2147
+ });
2148
+
2149
+ vue.onMounted(() => {
2150
+ getCountryCodeFromBackend();
2151
+ });
2152
+
2153
+ const getCountryCodeFromBackend = ()=>{
2154
+ if(!props.modelValue){
2155
+ shApis.doGet('sh-country-code').then(response=>{
2156
+ if(response.data && response.data.countryCode){
2157
+ countryCode.value = response.data.countryCode;
2158
+ }
2159
+ }).finally(()=>{
2160
+ setSelectedCountry();
2161
+ });
2162
+ }
2163
+ };
2164
+
2165
+ return (_ctx, _cache) => {
2159
2166
  return (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$q, [
2160
- ($data.selectedCountry)
2167
+ (selectedCountry.value)
2161
2168
  ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$i, [
2162
- vue.createElementVNode("img", { src: $data.flag }, null, 8 /* PROPS */, _hoisted_3$f),
2163
- vue.createTextVNode(" " + vue.toDisplayString($data.selectedCountry.dialCode), 1 /* TEXT */)
2169
+ vue.createElementVNode("img", {
2170
+ src: flag.value,
2171
+ alt: selectedCountry.value.name + ' flag'
2172
+ }, null, 8 /* PROPS */, _hoisted_3$f),
2173
+ vue.createTextVNode(" " + vue.toDisplayString(selectedCountry.value.dialCode), 1 /* TEXT */)
2164
2174
  ]))
2165
2175
  : vue.createCommentVNode("v-if", true),
2166
2176
  vue.withDirectives(vue.createElementVNode("select", {
2167
- onChange: _cache[0] || (_cache[0] = (...args) => ($options.updateValue && $options.updateValue(...args))),
2168
- "onUpdate:modelValue": _cache[1] || (_cache[1] = $event => (($data.selectedCountry) = $event)),
2177
+ onChange: updateValue,
2178
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => ((selectedCountry).value = $event)),
2169
2179
  class: "phone-country"
2170
2180
  }, [
2171
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList($data.countries, (country) => {
2181
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(countries), (country) => {
2172
2182
  return (vue.openBlock(), vue.createElementBlock("option", {
2173
2183
  value: country,
2174
2184
  key: country.dialCode
2175
2185
  }, vue.toDisplayString(country.name + '(' + country.dialCode + ')'), 9 /* TEXT, PROPS */, _hoisted_4$f))
2176
2186
  }), 128 /* KEYED_FRAGMENT */))
2177
2187
  ], 544 /* NEED_HYDRATION, NEED_PATCH */), [
2178
- [vue.vModelSelect, $data.selectedCountry]
2188
+ [vue.vModelSelect, selectedCountry.value]
2179
2189
  ]),
2180
2190
  vue.withDirectives(vue.createElementVNode("input", {
2181
- type: "number",
2191
+ type: "text",
2182
2192
  class: "phone-number",
2183
- disabled: $props.disabled,
2193
+ disabled: __props.disabled,
2184
2194
  "data-cy": "phone_input",
2185
- onInput: _cache[2] || (_cache[2] = (...args) => ($options.updateValue && $options.updateValue(...args))),
2195
+ onInput: updateValue,
2186
2196
  placeholder: "712345678",
2187
- "onUpdate:modelValue": _cache[3] || (_cache[3] = $event => (($data.input) = $event))
2197
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = $event => ((input).value = $event))
2188
2198
  }, null, 40 /* PROPS, NEED_HYDRATION */, _hoisted_5$d), [
2189
- [vue.vModelText, $data.input]
2199
+ [vue.vModelText, input.value]
2190
2200
  ])
2191
2201
  ]))
2192
2202
  }
2203
+ }
2204
+
2205
+ };
2193
2206
 
2194
- script$A.render = render$4;
2195
2207
  script$A.__file = "src/lib/components/form-components/PhoneInput.vue";
2196
2208
 
2197
2209
  const _hoisted_1$p = {
package/dist/library.mjs CHANGED
@@ -3,7 +3,7 @@ import { DateTime } from 'luxon';
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, watch, unref, normalizeClass, createBlock, resolveDynamicComponent, resolveComponent, inject, useTemplateRef, mergeProps, renderSlot, normalizeStyle, computed, Teleport, createVNode, withCtx, useSlots, onBeforeUnmount, reactive, vModelCheckbox, resolveDirective, shallowRef, markRaw, isRef } from 'vue';
6
+ import { ref, computed, watch, onMounted, openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, unref, vModelSelect, vModelText, normalizeClass, createBlock, resolveDynamicComponent, resolveComponent, inject, useTemplateRef, mergeProps, renderSlot, normalizeStyle, Teleport, createVNode, withCtx, useSlots, onBeforeUnmount, reactive, vModelCheckbox, resolveDirective, shallowRef, markRaw, isRef } from 'vue';
7
7
  import _ from 'lodash';
8
8
  import { defineStore, storeToRefs } from 'pinia';
9
9
  import { useRoute, useRouter } from 'vue-router';
@@ -2062,125 +2062,137 @@ const countries = [
2062
2062
  }
2063
2063
  ];
2064
2064
 
2065
- var script$A = {
2066
- name: 'PhoneInput',
2067
- props: ['modelValue', 'country_code','disabled'],
2068
- data () {
2069
- return {
2070
- input: this.modelValue,
2071
- countries: countries,
2072
- selectedCountry: {
2073
- name: 'Kenya',
2074
- dialCode: '+254',
2075
- isoCode: 'KE',
2076
- flag: 'https://www.countryflags.io/KE/flat/64.png'
2077
- },
2078
- flag: import.meta.env.VITE_APP_HOME_URL + 'flags/ke.svg',
2079
- appUrl: import.meta.env.VITE_APP_HOME_URL
2080
- }
2081
- },
2082
- updated () {
2083
- if (!this.selectedCountry || !this.input) ;
2084
- },
2085
- mounted () {
2086
- this.setSelectedCountry();
2087
- },
2088
- watch: {
2089
- modelValue: function(newVal){
2090
- if(!this.input){
2091
- let phone = newVal.replace('+254','');
2092
- this.input = phone.replace('+1','');
2093
- }
2094
- }
2095
- },
2096
- methods: {
2097
- updateValue: function () {
2098
- let phone = this.input;
2099
- phone = '-' + phone;
2100
- phone = phone.replace('-0', '');
2101
- phone = phone.replace('-', '');
2102
- // this.input = phone
2103
- if (this.selectedCountry) {
2104
- phone = this.selectedCountry.dialCode + '' + phone;
2105
- }
2106
- this.$emit('update:modelValue', phone);
2107
- this.flag = this.appUrl + 'flags/' + this.selectedCountry.isoCode.toLowerCase() + '.svg';
2108
- },
2109
- setSelectedCountry: function () {
2110
- let countryCode = 'KE';
2111
- if (this.country_code) {
2112
- countryCode = this.country_code;
2113
- }
2114
- this.input = this.modelValue;
2115
- const country = this.countries.find(function (country) {
2116
- if (countryCode.toUpperCase() === country.isoCode) {
2117
- return country
2118
- }
2119
- }, this);
2120
- if (this.input) {
2121
- if (!this.input.includes('+')) {
2122
- this.input = '+' + this.input;
2123
- }
2124
- this.flag = this.appUrl + 'flags/' + country.isoCode.toLowerCase() + '.svg';
2125
- this.input = this.input.replace(country.dialCode, '');
2126
- this.input = this.input.replace(':', '');
2127
- this.input = this.input.replace(':', '');
2128
- this.input = this.input.replace(':', '');
2129
- this.selectedCountry = country;
2130
- }
2131
- }
2132
- }
2133
- };
2134
-
2135
2065
  const _hoisted_1$q = {
2136
- class: "sh-phone mb-3",
2066
+ class: "sh-phone mb-3 form-control",
2137
2067
  style: {"display":"flex"}
2138
2068
  };
2139
2069
  const _hoisted_2$i = {
2140
2070
  key: 0,
2141
2071
  style: {"display":"contents"}
2142
2072
  };
2143
- const _hoisted_3$f = ["src"];
2073
+ const _hoisted_3$f = ["src", "alt"];
2144
2074
  const _hoisted_4$f = ["value"];
2145
2075
  const _hoisted_5$d = ["disabled"];
2146
2076
 
2147
- function render$4(_ctx, _cache, $props, $setup, $data, $options) {
2077
+ var script$A = {
2078
+ __name: 'PhoneInput',
2079
+ props: {
2080
+ modelValue: String,
2081
+ country_code: String,
2082
+ disabled: Boolean
2083
+ },
2084
+ emits: ['update:modelValue'],
2085
+ setup(__props, { emit: __emit }) {
2086
+
2087
+ const props = __props;
2088
+ const countryCode = ref(props.country_code || 'KE');
2089
+ const emit = __emit;
2090
+ const input = ref(props.modelValue);
2091
+ const countriesList = ref(countries);
2092
+ const selectedCountry = ref({
2093
+ name: 'Kenya',
2094
+ dialCode: '+254',
2095
+ isoCode: 'KE',
2096
+ flag: 'https://www.countryflags.io/KE/flat/64.png'
2097
+ });
2098
+ const flag = computed(()=> {
2099
+ const homeUrl = import.meta.env.VITE_APP_HOME_URL;
2100
+ if (selectedCountry.value) {
2101
+ return homeUrl + 'flags/' + selectedCountry.value.isoCode.toLowerCase() + '.svg';
2102
+ }
2103
+ }
2104
+ );
2105
+ import.meta.env.VITE_APP_HOME_URL;
2106
+
2107
+ const updateValue = () => {
2108
+ let phone = input.value || '';
2109
+ phone = phone.replace(/^0/, '');
2110
+ if (selectedCountry.value) {
2111
+ phone = selectedCountry.value.dialCode + phone;
2112
+ }
2113
+ emit('update:modelValue', phone);
2114
+ // flag.value = appUrl + 'flags/' + selectedCountry.value.isoCode.toLowerCase() + '.svg';
2115
+ };
2116
+
2117
+ const setSelectedCountry = () => {
2118
+ input.value = props.modelValue;
2119
+ const country = countriesList.value.find(country => country.isoCode === countryCode.value.toUpperCase());
2120
+ if (country) {
2121
+ selectedCountry.value = country;
2122
+ if (input.value) {
2123
+ if (!input.value.includes('+')) {
2124
+ input.value = '+' + input.value;
2125
+ }
2126
+ // flag.value = appUrl + 'flags/' + country.isoCode.toLowerCase() + '.svg';
2127
+ input.value = input.value.replace(country.dialCode, '').replace(/:/g, '');
2128
+ }
2129
+ }
2130
+ };
2131
+
2132
+ watch(() => props.modelValue, (newVal) => {
2133
+ if (!input.value) {
2134
+ input.value = newVal.replace('+254', '').replace('+1', '');
2135
+ }
2136
+ });
2137
+
2138
+ onMounted(() => {
2139
+ getCountryCodeFromBackend();
2140
+ });
2141
+
2142
+ const getCountryCodeFromBackend = ()=>{
2143
+ if(!props.modelValue){
2144
+ shApis.doGet('sh-country-code').then(response=>{
2145
+ if(response.data && response.data.countryCode){
2146
+ countryCode.value = response.data.countryCode;
2147
+ }
2148
+ }).finally(()=>{
2149
+ setSelectedCountry();
2150
+ });
2151
+ }
2152
+ };
2153
+
2154
+ return (_ctx, _cache) => {
2148
2155
  return (openBlock(), createElementBlock("div", _hoisted_1$q, [
2149
- ($data.selectedCountry)
2156
+ (selectedCountry.value)
2150
2157
  ? (openBlock(), createElementBlock("div", _hoisted_2$i, [
2151
- createElementVNode("img", { src: $data.flag }, null, 8 /* PROPS */, _hoisted_3$f),
2152
- createTextVNode(" " + toDisplayString($data.selectedCountry.dialCode), 1 /* TEXT */)
2158
+ createElementVNode("img", {
2159
+ src: flag.value,
2160
+ alt: selectedCountry.value.name + ' flag'
2161
+ }, null, 8 /* PROPS */, _hoisted_3$f),
2162
+ createTextVNode(" " + toDisplayString(selectedCountry.value.dialCode), 1 /* TEXT */)
2153
2163
  ]))
2154
2164
  : createCommentVNode("v-if", true),
2155
2165
  withDirectives(createElementVNode("select", {
2156
- onChange: _cache[0] || (_cache[0] = (...args) => ($options.updateValue && $options.updateValue(...args))),
2157
- "onUpdate:modelValue": _cache[1] || (_cache[1] = $event => (($data.selectedCountry) = $event)),
2166
+ onChange: updateValue,
2167
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => ((selectedCountry).value = $event)),
2158
2168
  class: "phone-country"
2159
2169
  }, [
2160
- (openBlock(true), createElementBlock(Fragment, null, renderList($data.countries, (country) => {
2170
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(countries), (country) => {
2161
2171
  return (openBlock(), createElementBlock("option", {
2162
2172
  value: country,
2163
2173
  key: country.dialCode
2164
2174
  }, toDisplayString(country.name + '(' + country.dialCode + ')'), 9 /* TEXT, PROPS */, _hoisted_4$f))
2165
2175
  }), 128 /* KEYED_FRAGMENT */))
2166
2176
  ], 544 /* NEED_HYDRATION, NEED_PATCH */), [
2167
- [vModelSelect, $data.selectedCountry]
2177
+ [vModelSelect, selectedCountry.value]
2168
2178
  ]),
2169
2179
  withDirectives(createElementVNode("input", {
2170
- type: "number",
2180
+ type: "text",
2171
2181
  class: "phone-number",
2172
- disabled: $props.disabled,
2182
+ disabled: __props.disabled,
2173
2183
  "data-cy": "phone_input",
2174
- onInput: _cache[2] || (_cache[2] = (...args) => ($options.updateValue && $options.updateValue(...args))),
2184
+ onInput: updateValue,
2175
2185
  placeholder: "712345678",
2176
- "onUpdate:modelValue": _cache[3] || (_cache[3] = $event => (($data.input) = $event))
2186
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = $event => ((input).value = $event))
2177
2187
  }, null, 40 /* PROPS, NEED_HYDRATION */, _hoisted_5$d), [
2178
- [vModelText, $data.input]
2188
+ [vModelText, input.value]
2179
2189
  ])
2180
2190
  ]))
2181
2191
  }
2192
+ }
2193
+
2194
+ };
2182
2195
 
2183
- script$A.render = render$4;
2184
2196
  script$A.__file = "src/lib/components/form-components/PhoneInput.vue";
2185
2197
 
2186
2198
  const _hoisted_1$p = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/shframework",
3
- "version": "5.6.8",
3
+ "version": "5.6.9",
4
4
  "description": "Vue library for handling laravel backend",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.mjs",