@iankibetsh/shframework 0.4.5 → 0.5.1

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.
@@ -51,3 +51,18 @@
51
51
  width: 100% !important;
52
52
  }
53
53
  }
54
+
55
+ .sh-selected-item{
56
+ line-height: unset!important;
57
+ }
58
+ .sh-suggestion-input{
59
+ padding: 0.375rem 0.75rem;
60
+ }
61
+ .sh-suggest{
62
+ margin-bottom: 1rem;
63
+ }
64
+ .sh-suggest-control::after{
65
+ margin-top: auto;
66
+ margin-bottom: auto;
67
+ margin-right: 0.255em;
68
+ }
package/dist/library.js CHANGED
@@ -1544,7 +1544,7 @@ const countries = [
1544
1544
  }
1545
1545
  ];
1546
1546
 
1547
- var script$7 = {
1547
+ var script$8 = {
1548
1548
  name: 'ShPhone',
1549
1549
  props: ['modelValue', 'country_code'],
1550
1550
  data () {
@@ -1606,19 +1606,19 @@ var script$7 = {
1606
1606
  }
1607
1607
  };
1608
1608
 
1609
- const _hoisted_1$7 = { class: "sh-phone mb-3" };
1610
- const _hoisted_2$6 = {
1609
+ const _hoisted_1$8 = { class: "sh-phone mb-3" };
1610
+ const _hoisted_2$7 = {
1611
1611
  key: 0,
1612
1612
  style: {"display":"contents"}
1613
1613
  };
1614
- const _hoisted_3$6 = ["src"];
1615
- const _hoisted_4$6 = ["value"];
1614
+ const _hoisted_3$7 = ["src"];
1615
+ const _hoisted_4$7 = ["value"];
1616
1616
 
1617
1617
  function render$7(_ctx, _cache, $props, $setup, $data, $options) {
1618
- return (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$7, [
1618
+ return (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$8, [
1619
1619
  ($data.selectedCountry)
1620
- ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$6, [
1621
- vue.createElementVNode("img", { src: $data.flag }, null, 8 /* PROPS */, _hoisted_3$6),
1620
+ ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$7, [
1621
+ vue.createElementVNode("img", { src: $data.flag }, null, 8 /* PROPS */, _hoisted_3$7),
1622
1622
  vue.createTextVNode(" " + vue.toDisplayString($data.selectedCountry.dialCode), 1 /* TEXT */)
1623
1623
  ]))
1624
1624
  : vue.createCommentVNode("v-if", true),
@@ -1631,7 +1631,7 @@ function render$7(_ctx, _cache, $props, $setup, $data, $options) {
1631
1631
  return (vue.openBlock(), vue.createElementBlock("option", {
1632
1632
  value: country,
1633
1633
  key: country.dialCode
1634
- }, vue.toDisplayString(country.name + '(' + country.dialCode + ')'), 9 /* TEXT, PROPS */, _hoisted_4$6))
1634
+ }, vue.toDisplayString(country.name + '(' + country.dialCode + ')'), 9 /* TEXT, PROPS */, _hoisted_4$7))
1635
1635
  }), 128 /* KEYED_FRAGMENT */))
1636
1636
  ], 544 /* HYDRATE_EVENTS, NEED_PATCH */), [
1637
1637
  [vue.vModelSelect, $data.selectedCountry]
@@ -1649,10 +1649,10 @@ function render$7(_ctx, _cache, $props, $setup, $data, $options) {
1649
1649
  ]))
1650
1650
  }
1651
1651
 
1652
- script$7.render = render$7;
1653
- script$7.__file = "src/views/ShPhone.vue";
1652
+ script$8.render = render$7;
1653
+ script$8.__file = "src/views/ShPhone.vue";
1654
1654
 
1655
- var script$6 = {
1655
+ var script$7 = {
1656
1656
  name: 'ShEditor',
1657
1657
  props: ['modelValue'],
1658
1658
  components: {
@@ -1691,7 +1691,7 @@ var script$6 = {
1691
1691
  }
1692
1692
  };
1693
1693
 
1694
- const _hoisted_1$6 = /*#__PURE__*/vue.createElementVNode("textarea", {
1694
+ const _hoisted_1$7 = /*#__PURE__*/vue.createElementVNode("textarea", {
1695
1695
  id: "tiny",
1696
1696
  style: {"display":"none"},
1697
1697
  "data-cy": "tinymce_editor"
@@ -1701,7 +1701,7 @@ function render$6(_ctx, _cache, $props, $setup, $data, $options) {
1701
1701
  const _component_editor = vue.resolveComponent("editor");
1702
1702
 
1703
1703
  return (vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
1704
- _hoisted_1$6,
1704
+ _hoisted_1$7,
1705
1705
  vue.createElementVNode("div", {
1706
1706
  onFocusin: _cache[1] || (_cache[1] = vue.withModifiers(() => {}, ["stop"])),
1707
1707
  class: "sh-editor w-100"
@@ -1726,14 +1726,174 @@ function render$6(_ctx, _cache, $props, $setup, $data, $options) {
1726
1726
  ], 64 /* STABLE_FRAGMENT */))
1727
1727
  }
1728
1728
 
1729
- script$6.render = render$6;
1730
- script$6.__file = "src/views/FormComponent/ShEditor.vue";
1729
+ script$7.render = render$6;
1730
+ script$7.__file = "src/views/FormComponent/ShEditor.vue";
1731
+
1732
+ const _hoisted_1$6 = {
1733
+ key: 0,
1734
+ class: "dropdown sh-suggest"
1735
+ };
1736
+ const _hoisted_2$6 = ["id"];
1737
+ const _hoisted_3$6 = { class: "badge bg-secondary m-1 sh-selected-item" };
1738
+ const _hoisted_4$6 = ["onClick"];
1739
+ const _hoisted_5$5 = ["id"];
1740
+ const _hoisted_6$3 = ["aria-labelledby"];
1741
+ const _hoisted_7$3 = { key: 0 };
1742
+ const _hoisted_8$2 = ["onClick"];
1743
+ const _hoisted_9$2 = {
1744
+ key: 1,
1745
+ class: "dropdown-item sh-suggest-no-results"
1746
+ };
1747
+ const _hoisted_10$3 = {
1748
+ key: 2,
1749
+ class: "dropdown-item sh-suggest-no-input"
1750
+ };
1751
+
1752
+
1753
+ var script$6 = {
1754
+ __name: 'ShSuggest',
1755
+ props: ['fillSelects','modelValue'],
1756
+ emits: ['update:modelValue'],
1757
+ setup(__props, { emit }) {
1758
+
1759
+ const props = __props;
1760
+
1761
+
1762
+
1763
+ let id = vue.ref(null);
1764
+ vue.ref(null);
1765
+ let suggestions = vue.ref(null);
1766
+ let selectedSuggestions = vue.ref([]);
1767
+ vue.onMounted(() => {
1768
+ id.value = 'sid' + (Math.random() + 1).toString(36).substring(7);
1769
+ resetData();
1770
+ });
1771
+ function resetData(){
1772
+ if(props.fillSelects.data) {
1773
+ suggestions.value = props.fillSelects.data;
1774
+ }
1775
+ }
1776
+ function addSuggestion(sgn){
1777
+ let selected = selectedSuggestions.value;
1778
+ if(selected.length > 0 && !props.fillSelects.allow_multiple){
1779
+ selected = [];
1780
+ }
1781
+ if(!selected.includes(sgn)){
1782
+ selected.push(sgn);
1783
+ selectedSuggestions.value = selected;
1784
+ }
1785
+ updateModelValue();
1786
+ document.getElementById('input_' + id.value).innerHTML = '';
1787
+ }
1788
+ function updateModelValue(){
1789
+ let selectedItems = selectedSuggestions.value;
1790
+ if(selectedItems.length === 0) {
1791
+ emit('update:modelValue', null);
1792
+ } else if (!props.fillSelects.allow_multiple) {
1793
+ emit('update:modelValue', selectedItems[0].id);
1794
+ } else {
1795
+ const ids = selectedItems.map(item => {
1796
+ return item.id
1797
+ });
1798
+ emit('update:modelValue', ids);
1799
+ }
1800
+ }
1801
+ function removeSuggestion(sgt){
1802
+ selectedSuggestions.value = selectedSuggestions.value.filter(selectedSgt=>{
1803
+ if(selectedSgt.id !== sgt) {
1804
+ return selectedSgt
1805
+ }
1806
+ });
1807
+ updateModelValue();
1808
+ }
1809
+ let searchText = vue.ref(null);
1810
+ function filterData(e){
1811
+ let filterValue = e.target.innerText;
1812
+ searchText.value = filterValue;
1813
+ if(props.fillSelects.data) {
1814
+ suggestions.value = props.fillSelects.data.filter(item=>{
1815
+ if(item.name.toLowerCase().includes(filterValue.toLowerCase())){
1816
+ return item
1817
+ }
1818
+ });
1819
+ } else {
1820
+ apis.doGet(props.fillSelects.url, { all: 1,filter_value: filterValue }).then(res => {
1821
+ suggestions.value = res.data.data;
1822
+ }).catch(res => {
1823
+ console.log(res);
1824
+ });
1825
+ }
1826
+ }
1827
+
1828
+ return (_ctx, _cache) => {
1829
+ return (vue.unref(id))
1830
+ ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$6, [
1831
+ vue.createElementVNode("div", {
1832
+ id: vue.unref(id),
1833
+ "data-bs-toggle": "dropdown",
1834
+ class: "form-control p-0 d-flex sh-suggest-control dropdown-toggle",
1835
+ "aria-expanded": "false"
1836
+ }, [
1837
+ vue.createElementVNode("div", null, [
1838
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(selectedSuggestions), (sgt) => {
1839
+ return (vue.openBlock(), vue.createElementBlock("h5", _hoisted_3$6, [
1840
+ vue.createTextVNode(vue.toDisplayString(sgt.name) + " ", 1 /* TEXT */),
1841
+ vue.createElementVNode("button", {
1842
+ onClick: $event => (removeSuggestion(sgt.id)),
1843
+ type: "button",
1844
+ class: "btn-close border-start border-1 ms-1",
1845
+ "aria-label": "Close"
1846
+ }, null, 8 /* PROPS */, _hoisted_4$6)
1847
+ ]))
1848
+ }), 256 /* UNKEYED_FRAGMENT */))
1849
+ ]),
1850
+ vue.createElementVNode("div", {
1851
+ id: 'input_' + vue.unref(id),
1852
+ contenteditable: "true",
1853
+ onInput: filterData,
1854
+ class: "flex-fill h-100 sh-suggestion-input"
1855
+ }, null, 40 /* PROPS, HYDRATE_EVENTS */, _hoisted_5$5)
1856
+ ], 8 /* PROPS */, _hoisted_2$6),
1857
+ vue.createElementVNode("ul", {
1858
+ class: "dropdown-menu w-100",
1859
+ "aria-labelledby": vue.unref(id)
1860
+ }, [
1861
+ (vue.unref(suggestions) && vue.unref(suggestions).length > 0)
1862
+ ? (vue.openBlock(true), vue.createElementBlock(vue.Fragment, { key: 0 }, vue.renderList(vue.unref(suggestions), (suggestion) => {
1863
+ return (vue.openBlock(), vue.createElementBlock(vue.Fragment, {
1864
+ key: suggestion.id
1865
+ }, [
1866
+ (suggestion.name)
1867
+ ? (vue.openBlock(), vue.createElementBlock("li", _hoisted_7$3, [
1868
+ vue.createElementVNode("a", {
1869
+ onClick: $event => (addSuggestion(suggestion)),
1870
+ class: vue.normalizeClass(["dropdown-item", vue.unref(selectedSuggestions).includes(suggestion) ? 'active':'']),
1871
+ href: "#"
1872
+ }, vue.toDisplayString(suggestion.name ?? suggestion.text), 11 /* TEXT, CLASS, PROPS */, _hoisted_8$2)
1873
+ ]))
1874
+ : vue.createCommentVNode("v-if", true)
1875
+ ], 64 /* STABLE_FRAGMENT */))
1876
+ }), 128 /* KEYED_FRAGMENT */))
1877
+ : (vue.unref(searchText))
1878
+ ? (vue.openBlock(), vue.createElementBlock("li", _hoisted_9$2, " No results found "))
1879
+ : (vue.openBlock(), vue.createElementBlock("li", _hoisted_10$3, " Type to search... "))
1880
+ ], 8 /* PROPS */, _hoisted_6$3)
1881
+ ]))
1882
+ : vue.createCommentVNode("v-if", true)
1883
+ }
1884
+ }
1885
+
1886
+ };
1887
+
1888
+ script$6.__scopeId = "data-v-043a2b8f";
1889
+ script$6.__file = "src/views/FormComponent/ShSuggest.vue";
1731
1890
 
1732
1891
  var script$5 = {
1733
1892
  name: 'ShForm',
1734
1893
  components: {
1735
- ShEditor: script$6,
1736
- ShPhone: script$7
1894
+ ShSuggest: script$6,
1895
+ ShEditor: script$7,
1896
+ ShPhone: script$8
1737
1897
  },
1738
1898
  props: [
1739
1899
  'action',
@@ -1763,7 +1923,8 @@ var script$5 = {
1763
1923
  users: [],
1764
1924
  allPlaceHolders: {},
1765
1925
  user: null,
1766
- allLabels: {}
1926
+ allLabels: {},
1927
+ suggests: []
1767
1928
  }
1768
1929
  },
1769
1930
  methods: {
@@ -1788,6 +1949,9 @@ var script$5 = {
1788
1949
  }
1789
1950
  },
1790
1951
  getFieldType: function (field) {
1952
+ if(this.suggests && this.suggests.includes(field)){
1953
+ return 'suggest'
1954
+ }
1791
1955
  if(this.editors && this.editors.includes(field)){
1792
1956
  return 'editor'
1793
1957
  }
@@ -1811,7 +1975,7 @@ var script$5 = {
1811
1975
  const mapLocations = ['building_location'];
1812
1976
  const files = ['file', 'logo'];
1813
1977
  const phones = ['phone'];
1814
- if (field.includes('_id') || this.selectData[field]) {
1978
+ if (this.selectData[field]) {
1815
1979
  return 'select'
1816
1980
  }
1817
1981
  if (field === 'email') {
@@ -1993,7 +2157,12 @@ var script$5 = {
1993
2157
  const selectData = {};
1994
2158
  if (this.fillSelects) {
1995
2159
  Object.keys(this.fillSelects).forEach(key => {
1996
- if (this.fillSelects[key].data) {
2160
+ if(this.fillSelects[key].suggest || this.fillSelects[key].suggests) {
2161
+ if (!this.suggests) {
2162
+ this.suggests = [];
2163
+ }
2164
+ this.suggests.push(key);
2165
+ } else if (this.fillSelects[key].data) {
1997
2166
  selectData[key] = this.fillSelects[key].data;
1998
2167
  this.selectData = selectData;
1999
2168
  console.log(this.selectData);
@@ -2051,7 +2220,7 @@ const _hoisted_15$2 = ["name", "onFocus", "onUpdate:modelValue"];
2051
2220
  const _hoisted_16$2 = ["name", "onFocus", "onUpdate:modelValue"];
2052
2221
  const _hoisted_17$2 = ["value"];
2053
2222
  const _hoisted_18$2 = {
2054
- key: 10,
2223
+ key: 11,
2055
2224
  class: "invalid-feedback"
2056
2225
  };
2057
2226
  const _hoisted_19$2 = {
@@ -2084,6 +2253,7 @@ const _hoisted_23$2 = {
2084
2253
 
2085
2254
  function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2086
2255
  const _component_ShPhone = vue.resolveComponent("ShPhone");
2256
+ const _component_ShSuggest = vue.resolveComponent("ShSuggest");
2087
2257
  const _component_ShEditor = vue.resolveComponent("ShEditor");
2088
2258
 
2089
2259
  return (vue.openBlock(), vue.createElementBlock("form", _hoisted_1$5, [
@@ -2189,9 +2359,19 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2189
2359
  required: ""
2190
2360
  }, null, 8 /* PROPS */, ["country_code", "placeholder", "name", "onFocus", "class", "modelValue", "onUpdate:modelValue"]))
2191
2361
  : vue.createCommentVNode("v-if", true),
2362
+ ($options.getFieldType(field) === 'suggest')
2363
+ ? (vue.openBlock(), vue.createBlock(_component_ShSuggest, {
2364
+ key: 6,
2365
+ "select-data": _ctx.selectData[field],
2366
+ "fill-selects": $props.fillSelects[field],
2367
+ class: vue.normalizeClass(_ctx.form_errors[field] == null ? ' field_' + field:'is-invalid ' + field),
2368
+ modelValue: _ctx.form_elements[field],
2369
+ "onUpdate:modelValue": $event => ((_ctx.form_elements[field]) = $event)
2370
+ }, null, 8 /* PROPS */, ["select-data", "fill-selects", "class", "modelValue", "onUpdate:modelValue"]))
2371
+ : vue.createCommentVNode("v-if", true),
2192
2372
  ($options.getFieldType(field) === 'editor')
2193
2373
  ? (vue.openBlock(), vue.createBlock(_component_ShEditor, {
2194
- key: 6,
2374
+ key: 7,
2195
2375
  placeholder: _ctx.allPlaceHolders[field] ? _ctx.allPlaceHolders[field] : '',
2196
2376
  name: field,
2197
2377
  onFocus: $event => ($options.removeErrors(field)),
@@ -2202,7 +2382,7 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2202
2382
  : vue.createCommentVNode("v-if", true),
2203
2383
  ($options.getFieldType(field) === 'text')
2204
2384
  ? vue.withDirectives((vue.openBlock(), vue.createElementBlock("input", {
2205
- key: 7,
2385
+ key: 8,
2206
2386
  disabled: $options.isDisabled(field),
2207
2387
  placeholder: field === 'phone_number' ? 'e.g 0712 345 678':'',
2208
2388
  name: field,
@@ -2216,7 +2396,7 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2216
2396
  : vue.createCommentVNode("v-if", true),
2217
2397
  ($options.getFieldType(field) === 'textarea')
2218
2398
  ? vue.withDirectives((vue.openBlock(), vue.createElementBlock("textarea", {
2219
- key: 8,
2399
+ key: 9,
2220
2400
  name: field,
2221
2401
  onFocus: $event => ($options.removeErrors(field)),
2222
2402
  class: vue.normalizeClass([_ctx.form_errors[field] == null ? ' field_' + field:'is-invalid ' + field, "form-control"]),
@@ -2227,7 +2407,7 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2227
2407
  : vue.createCommentVNode("v-if", true),
2228
2408
  ($options.getFieldType(field) === 'select' && _ctx.selectData[field] != null)
2229
2409
  ? vue.withDirectives((vue.openBlock(), vue.createElementBlock("select", {
2230
- key: 9,
2410
+ key: 10,
2231
2411
  name: field,
2232
2412
  onFocus: $event => ($options.removeErrors(field)),
2233
2413
  class: vue.normalizeClass([_ctx.form_errors[field] == null ? ' field_' + field:'is-invalid ' + field, "form-control"]),
@@ -2953,7 +3133,7 @@ var script$1 = {
2953
3133
  }
2954
3134
  };
2955
3135
 
2956
- const _hoisted_1$1 = { class: "auto-table mt-2" };
3136
+ const _hoisted_1$1 = { class: "auto-table" };
2957
3137
  const _hoisted_2$1 = {
2958
3138
  key: 0,
2959
3139
  class: "col-md-4 mb-2"
@@ -3681,7 +3861,7 @@ const useUserStore = pinia.defineStore('user-store', {
3681
3861
  exports.ShCanvas = script$4;
3682
3862
  exports.ShForm = script$5;
3683
3863
  exports.ShModal = script$3;
3684
- exports.ShPhone = script$7;
3864
+ exports.ShPhone = script$8;
3685
3865
  exports.ShTable = script$1;
3686
3866
  exports.ShTabs = script;
3687
3867
  exports.shApis = apis;
package/dist/library.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import Axios from 'axios';
2
2
  import NProgress from 'nprogress';
3
- import { openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, resolveComponent, withModifiers, createVNode, normalizeClass, createBlock, renderSlot, createStaticVNode, withCtx } from 'vue';
3
+ import { openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, resolveComponent, withModifiers, createVNode, ref, onMounted, unref, normalizeClass, createBlock, renderSlot, createStaticVNode, withCtx } from 'vue';
4
4
  import Editor from '@tinymce/tinymce-vue';
5
5
  import moment from 'moment';
6
6
  import Swal from 'sweetalert2';
@@ -1532,7 +1532,7 @@ const countries = [
1532
1532
  }
1533
1533
  ];
1534
1534
 
1535
- var script$7 = {
1535
+ var script$8 = {
1536
1536
  name: 'ShPhone',
1537
1537
  props: ['modelValue', 'country_code'],
1538
1538
  data () {
@@ -1594,19 +1594,19 @@ var script$7 = {
1594
1594
  }
1595
1595
  };
1596
1596
 
1597
- const _hoisted_1$7 = { class: "sh-phone mb-3" };
1598
- const _hoisted_2$6 = {
1597
+ const _hoisted_1$8 = { class: "sh-phone mb-3" };
1598
+ const _hoisted_2$7 = {
1599
1599
  key: 0,
1600
1600
  style: {"display":"contents"}
1601
1601
  };
1602
- const _hoisted_3$6 = ["src"];
1603
- const _hoisted_4$6 = ["value"];
1602
+ const _hoisted_3$7 = ["src"];
1603
+ const _hoisted_4$7 = ["value"];
1604
1604
 
1605
1605
  function render$7(_ctx, _cache, $props, $setup, $data, $options) {
1606
- return (openBlock(), createElementBlock("div", _hoisted_1$7, [
1606
+ return (openBlock(), createElementBlock("div", _hoisted_1$8, [
1607
1607
  ($data.selectedCountry)
1608
- ? (openBlock(), createElementBlock("div", _hoisted_2$6, [
1609
- createElementVNode("img", { src: $data.flag }, null, 8 /* PROPS */, _hoisted_3$6),
1608
+ ? (openBlock(), createElementBlock("div", _hoisted_2$7, [
1609
+ createElementVNode("img", { src: $data.flag }, null, 8 /* PROPS */, _hoisted_3$7),
1610
1610
  createTextVNode(" " + toDisplayString($data.selectedCountry.dialCode), 1 /* TEXT */)
1611
1611
  ]))
1612
1612
  : createCommentVNode("v-if", true),
@@ -1619,7 +1619,7 @@ function render$7(_ctx, _cache, $props, $setup, $data, $options) {
1619
1619
  return (openBlock(), createElementBlock("option", {
1620
1620
  value: country,
1621
1621
  key: country.dialCode
1622
- }, toDisplayString(country.name + '(' + country.dialCode + ')'), 9 /* TEXT, PROPS */, _hoisted_4$6))
1622
+ }, toDisplayString(country.name + '(' + country.dialCode + ')'), 9 /* TEXT, PROPS */, _hoisted_4$7))
1623
1623
  }), 128 /* KEYED_FRAGMENT */))
1624
1624
  ], 544 /* HYDRATE_EVENTS, NEED_PATCH */), [
1625
1625
  [vModelSelect, $data.selectedCountry]
@@ -1637,10 +1637,10 @@ function render$7(_ctx, _cache, $props, $setup, $data, $options) {
1637
1637
  ]))
1638
1638
  }
1639
1639
 
1640
- script$7.render = render$7;
1641
- script$7.__file = "src/views/ShPhone.vue";
1640
+ script$8.render = render$7;
1641
+ script$8.__file = "src/views/ShPhone.vue";
1642
1642
 
1643
- var script$6 = {
1643
+ var script$7 = {
1644
1644
  name: 'ShEditor',
1645
1645
  props: ['modelValue'],
1646
1646
  components: {
@@ -1679,7 +1679,7 @@ var script$6 = {
1679
1679
  }
1680
1680
  };
1681
1681
 
1682
- const _hoisted_1$6 = /*#__PURE__*/createElementVNode("textarea", {
1682
+ const _hoisted_1$7 = /*#__PURE__*/createElementVNode("textarea", {
1683
1683
  id: "tiny",
1684
1684
  style: {"display":"none"},
1685
1685
  "data-cy": "tinymce_editor"
@@ -1689,7 +1689,7 @@ function render$6(_ctx, _cache, $props, $setup, $data, $options) {
1689
1689
  const _component_editor = resolveComponent("editor");
1690
1690
 
1691
1691
  return (openBlock(), createElementBlock(Fragment, null, [
1692
- _hoisted_1$6,
1692
+ _hoisted_1$7,
1693
1693
  createElementVNode("div", {
1694
1694
  onFocusin: _cache[1] || (_cache[1] = withModifiers(() => {}, ["stop"])),
1695
1695
  class: "sh-editor w-100"
@@ -1714,14 +1714,174 @@ function render$6(_ctx, _cache, $props, $setup, $data, $options) {
1714
1714
  ], 64 /* STABLE_FRAGMENT */))
1715
1715
  }
1716
1716
 
1717
- script$6.render = render$6;
1718
- script$6.__file = "src/views/FormComponent/ShEditor.vue";
1717
+ script$7.render = render$6;
1718
+ script$7.__file = "src/views/FormComponent/ShEditor.vue";
1719
+
1720
+ const _hoisted_1$6 = {
1721
+ key: 0,
1722
+ class: "dropdown sh-suggest"
1723
+ };
1724
+ const _hoisted_2$6 = ["id"];
1725
+ const _hoisted_3$6 = { class: "badge bg-secondary m-1 sh-selected-item" };
1726
+ const _hoisted_4$6 = ["onClick"];
1727
+ const _hoisted_5$5 = ["id"];
1728
+ const _hoisted_6$3 = ["aria-labelledby"];
1729
+ const _hoisted_7$3 = { key: 0 };
1730
+ const _hoisted_8$2 = ["onClick"];
1731
+ const _hoisted_9$2 = {
1732
+ key: 1,
1733
+ class: "dropdown-item sh-suggest-no-results"
1734
+ };
1735
+ const _hoisted_10$3 = {
1736
+ key: 2,
1737
+ class: "dropdown-item sh-suggest-no-input"
1738
+ };
1739
+
1740
+
1741
+ var script$6 = {
1742
+ __name: 'ShSuggest',
1743
+ props: ['fillSelects','modelValue'],
1744
+ emits: ['update:modelValue'],
1745
+ setup(__props, { emit }) {
1746
+
1747
+ const props = __props;
1748
+
1749
+
1750
+
1751
+ let id = ref(null);
1752
+ ref(null);
1753
+ let suggestions = ref(null);
1754
+ let selectedSuggestions = ref([]);
1755
+ onMounted(() => {
1756
+ id.value = 'sid' + (Math.random() + 1).toString(36).substring(7);
1757
+ resetData();
1758
+ });
1759
+ function resetData(){
1760
+ if(props.fillSelects.data) {
1761
+ suggestions.value = props.fillSelects.data;
1762
+ }
1763
+ }
1764
+ function addSuggestion(sgn){
1765
+ let selected = selectedSuggestions.value;
1766
+ if(selected.length > 0 && !props.fillSelects.allow_multiple){
1767
+ selected = [];
1768
+ }
1769
+ if(!selected.includes(sgn)){
1770
+ selected.push(sgn);
1771
+ selectedSuggestions.value = selected;
1772
+ }
1773
+ updateModelValue();
1774
+ document.getElementById('input_' + id.value).innerHTML = '';
1775
+ }
1776
+ function updateModelValue(){
1777
+ let selectedItems = selectedSuggestions.value;
1778
+ if(selectedItems.length === 0) {
1779
+ emit('update:modelValue', null);
1780
+ } else if (!props.fillSelects.allow_multiple) {
1781
+ emit('update:modelValue', selectedItems[0].id);
1782
+ } else {
1783
+ const ids = selectedItems.map(item => {
1784
+ return item.id
1785
+ });
1786
+ emit('update:modelValue', ids);
1787
+ }
1788
+ }
1789
+ function removeSuggestion(sgt){
1790
+ selectedSuggestions.value = selectedSuggestions.value.filter(selectedSgt=>{
1791
+ if(selectedSgt.id !== sgt) {
1792
+ return selectedSgt
1793
+ }
1794
+ });
1795
+ updateModelValue();
1796
+ }
1797
+ let searchText = ref(null);
1798
+ function filterData(e){
1799
+ let filterValue = e.target.innerText;
1800
+ searchText.value = filterValue;
1801
+ if(props.fillSelects.data) {
1802
+ suggestions.value = props.fillSelects.data.filter(item=>{
1803
+ if(item.name.toLowerCase().includes(filterValue.toLowerCase())){
1804
+ return item
1805
+ }
1806
+ });
1807
+ } else {
1808
+ apis.doGet(props.fillSelects.url, { all: 1,filter_value: filterValue }).then(res => {
1809
+ suggestions.value = res.data.data;
1810
+ }).catch(res => {
1811
+ console.log(res);
1812
+ });
1813
+ }
1814
+ }
1815
+
1816
+ return (_ctx, _cache) => {
1817
+ return (unref(id))
1818
+ ? (openBlock(), createElementBlock("div", _hoisted_1$6, [
1819
+ createElementVNode("div", {
1820
+ id: unref(id),
1821
+ "data-bs-toggle": "dropdown",
1822
+ class: "form-control p-0 d-flex sh-suggest-control dropdown-toggle",
1823
+ "aria-expanded": "false"
1824
+ }, [
1825
+ createElementVNode("div", null, [
1826
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(selectedSuggestions), (sgt) => {
1827
+ return (openBlock(), createElementBlock("h5", _hoisted_3$6, [
1828
+ createTextVNode(toDisplayString(sgt.name) + " ", 1 /* TEXT */),
1829
+ createElementVNode("button", {
1830
+ onClick: $event => (removeSuggestion(sgt.id)),
1831
+ type: "button",
1832
+ class: "btn-close border-start border-1 ms-1",
1833
+ "aria-label": "Close"
1834
+ }, null, 8 /* PROPS */, _hoisted_4$6)
1835
+ ]))
1836
+ }), 256 /* UNKEYED_FRAGMENT */))
1837
+ ]),
1838
+ createElementVNode("div", {
1839
+ id: 'input_' + unref(id),
1840
+ contenteditable: "true",
1841
+ onInput: filterData,
1842
+ class: "flex-fill h-100 sh-suggestion-input"
1843
+ }, null, 40 /* PROPS, HYDRATE_EVENTS */, _hoisted_5$5)
1844
+ ], 8 /* PROPS */, _hoisted_2$6),
1845
+ createElementVNode("ul", {
1846
+ class: "dropdown-menu w-100",
1847
+ "aria-labelledby": unref(id)
1848
+ }, [
1849
+ (unref(suggestions) && unref(suggestions).length > 0)
1850
+ ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(unref(suggestions), (suggestion) => {
1851
+ return (openBlock(), createElementBlock(Fragment, {
1852
+ key: suggestion.id
1853
+ }, [
1854
+ (suggestion.name)
1855
+ ? (openBlock(), createElementBlock("li", _hoisted_7$3, [
1856
+ createElementVNode("a", {
1857
+ onClick: $event => (addSuggestion(suggestion)),
1858
+ class: normalizeClass(["dropdown-item", unref(selectedSuggestions).includes(suggestion) ? 'active':'']),
1859
+ href: "#"
1860
+ }, toDisplayString(suggestion.name ?? suggestion.text), 11 /* TEXT, CLASS, PROPS */, _hoisted_8$2)
1861
+ ]))
1862
+ : createCommentVNode("v-if", true)
1863
+ ], 64 /* STABLE_FRAGMENT */))
1864
+ }), 128 /* KEYED_FRAGMENT */))
1865
+ : (unref(searchText))
1866
+ ? (openBlock(), createElementBlock("li", _hoisted_9$2, " No results found "))
1867
+ : (openBlock(), createElementBlock("li", _hoisted_10$3, " Type to search... "))
1868
+ ], 8 /* PROPS */, _hoisted_6$3)
1869
+ ]))
1870
+ : createCommentVNode("v-if", true)
1871
+ }
1872
+ }
1873
+
1874
+ };
1875
+
1876
+ script$6.__scopeId = "data-v-043a2b8f";
1877
+ script$6.__file = "src/views/FormComponent/ShSuggest.vue";
1719
1878
 
1720
1879
  var script$5 = {
1721
1880
  name: 'ShForm',
1722
1881
  components: {
1723
- ShEditor: script$6,
1724
- ShPhone: script$7
1882
+ ShSuggest: script$6,
1883
+ ShEditor: script$7,
1884
+ ShPhone: script$8
1725
1885
  },
1726
1886
  props: [
1727
1887
  'action',
@@ -1751,7 +1911,8 @@ var script$5 = {
1751
1911
  users: [],
1752
1912
  allPlaceHolders: {},
1753
1913
  user: null,
1754
- allLabels: {}
1914
+ allLabels: {},
1915
+ suggests: []
1755
1916
  }
1756
1917
  },
1757
1918
  methods: {
@@ -1776,6 +1937,9 @@ var script$5 = {
1776
1937
  }
1777
1938
  },
1778
1939
  getFieldType: function (field) {
1940
+ if(this.suggests && this.suggests.includes(field)){
1941
+ return 'suggest'
1942
+ }
1779
1943
  if(this.editors && this.editors.includes(field)){
1780
1944
  return 'editor'
1781
1945
  }
@@ -1799,7 +1963,7 @@ var script$5 = {
1799
1963
  const mapLocations = ['building_location'];
1800
1964
  const files = ['file', 'logo'];
1801
1965
  const phones = ['phone'];
1802
- if (field.includes('_id') || this.selectData[field]) {
1966
+ if (this.selectData[field]) {
1803
1967
  return 'select'
1804
1968
  }
1805
1969
  if (field === 'email') {
@@ -1981,7 +2145,12 @@ var script$5 = {
1981
2145
  const selectData = {};
1982
2146
  if (this.fillSelects) {
1983
2147
  Object.keys(this.fillSelects).forEach(key => {
1984
- if (this.fillSelects[key].data) {
2148
+ if(this.fillSelects[key].suggest || this.fillSelects[key].suggests) {
2149
+ if (!this.suggests) {
2150
+ this.suggests = [];
2151
+ }
2152
+ this.suggests.push(key);
2153
+ } else if (this.fillSelects[key].data) {
1985
2154
  selectData[key] = this.fillSelects[key].data;
1986
2155
  this.selectData = selectData;
1987
2156
  console.log(this.selectData);
@@ -2039,7 +2208,7 @@ const _hoisted_15$2 = ["name", "onFocus", "onUpdate:modelValue"];
2039
2208
  const _hoisted_16$2 = ["name", "onFocus", "onUpdate:modelValue"];
2040
2209
  const _hoisted_17$2 = ["value"];
2041
2210
  const _hoisted_18$2 = {
2042
- key: 10,
2211
+ key: 11,
2043
2212
  class: "invalid-feedback"
2044
2213
  };
2045
2214
  const _hoisted_19$2 = {
@@ -2072,6 +2241,7 @@ const _hoisted_23$2 = {
2072
2241
 
2073
2242
  function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2074
2243
  const _component_ShPhone = resolveComponent("ShPhone");
2244
+ const _component_ShSuggest = resolveComponent("ShSuggest");
2075
2245
  const _component_ShEditor = resolveComponent("ShEditor");
2076
2246
 
2077
2247
  return (openBlock(), createElementBlock("form", _hoisted_1$5, [
@@ -2177,9 +2347,19 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2177
2347
  required: ""
2178
2348
  }, null, 8 /* PROPS */, ["country_code", "placeholder", "name", "onFocus", "class", "modelValue", "onUpdate:modelValue"]))
2179
2349
  : createCommentVNode("v-if", true),
2350
+ ($options.getFieldType(field) === 'suggest')
2351
+ ? (openBlock(), createBlock(_component_ShSuggest, {
2352
+ key: 6,
2353
+ "select-data": _ctx.selectData[field],
2354
+ "fill-selects": $props.fillSelects[field],
2355
+ class: normalizeClass(_ctx.form_errors[field] == null ? ' field_' + field:'is-invalid ' + field),
2356
+ modelValue: _ctx.form_elements[field],
2357
+ "onUpdate:modelValue": $event => ((_ctx.form_elements[field]) = $event)
2358
+ }, null, 8 /* PROPS */, ["select-data", "fill-selects", "class", "modelValue", "onUpdate:modelValue"]))
2359
+ : createCommentVNode("v-if", true),
2180
2360
  ($options.getFieldType(field) === 'editor')
2181
2361
  ? (openBlock(), createBlock(_component_ShEditor, {
2182
- key: 6,
2362
+ key: 7,
2183
2363
  placeholder: _ctx.allPlaceHolders[field] ? _ctx.allPlaceHolders[field] : '',
2184
2364
  name: field,
2185
2365
  onFocus: $event => ($options.removeErrors(field)),
@@ -2190,7 +2370,7 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2190
2370
  : createCommentVNode("v-if", true),
2191
2371
  ($options.getFieldType(field) === 'text')
2192
2372
  ? withDirectives((openBlock(), createElementBlock("input", {
2193
- key: 7,
2373
+ key: 8,
2194
2374
  disabled: $options.isDisabled(field),
2195
2375
  placeholder: field === 'phone_number' ? 'e.g 0712 345 678':'',
2196
2376
  name: field,
@@ -2204,7 +2384,7 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2204
2384
  : createCommentVNode("v-if", true),
2205
2385
  ($options.getFieldType(field) === 'textarea')
2206
2386
  ? withDirectives((openBlock(), createElementBlock("textarea", {
2207
- key: 8,
2387
+ key: 9,
2208
2388
  name: field,
2209
2389
  onFocus: $event => ($options.removeErrors(field)),
2210
2390
  class: normalizeClass([_ctx.form_errors[field] == null ? ' field_' + field:'is-invalid ' + field, "form-control"]),
@@ -2215,7 +2395,7 @@ function render$5(_ctx, _cache, $props, $setup, $data, $options) {
2215
2395
  : createCommentVNode("v-if", true),
2216
2396
  ($options.getFieldType(field) === 'select' && _ctx.selectData[field] != null)
2217
2397
  ? withDirectives((openBlock(), createElementBlock("select", {
2218
- key: 9,
2398
+ key: 10,
2219
2399
  name: field,
2220
2400
  onFocus: $event => ($options.removeErrors(field)),
2221
2401
  class: normalizeClass([_ctx.form_errors[field] == null ? ' field_' + field:'is-invalid ' + field, "form-control"]),
@@ -2941,7 +3121,7 @@ var script$1 = {
2941
3121
  }
2942
3122
  };
2943
3123
 
2944
- const _hoisted_1$1 = { class: "auto-table mt-2" };
3124
+ const _hoisted_1$1 = { class: "auto-table" };
2945
3125
  const _hoisted_2$1 = {
2946
3126
  key: 0,
2947
3127
  class: "col-md-4 mb-2"
@@ -3666,4 +3846,4 @@ const useUserStore = defineStore('user-store', {
3666
3846
  }
3667
3847
  });
3668
3848
 
3669
- export { script$4 as ShCanvas, script$5 as ShForm, script$3 as ShModal, script$7 as ShPhone, script$1 as ShTable, script as ShTabs, apis as shApis, helpers as shRepo, shstorage as shStorage, useUserStore };
3849
+ export { script$4 as ShCanvas, script$5 as ShForm, script$3 as ShModal, script$8 as ShPhone, script$1 as ShTable, script as ShTabs, apis as shApis, helpers as shRepo, shstorage as shStorage, useUserStore };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/shframework",
3
- "version": "0.4.5",
3
+ "version": "0.5.1",
4
4
  "description": "Vue library for handling laravel backend",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.mjs",
@@ -11,25 +11,34 @@
11
11
  "test": "echo \"Error: no test specifieds\" && exit 1",
12
12
  "build": "rollup -c",
13
13
  "docs:dev": "vuepress dev docs",
14
- "docs:build": "vuepress build docs"
14
+ "docs:build": "vuepress build docs",
15
+ "dev": "vite",
16
+ "serve": "vite"
15
17
  },
16
18
  "keywords": [],
17
19
  "author": "",
18
20
  "license": "ISC",
19
21
  "peerDependencies": {
22
+ "@tinymce/tinymce-vue": "^4.0.7",
20
23
  "axios": "^0.27.2",
21
24
  "moment": "^2.29.3",
22
25
  "nprogress": "^0.2.0",
23
26
  "pinia": "^2.0.13",
24
27
  "sweetalert2": "^11.4.14",
25
- "vue": "^3.2.37",
26
- "@tinymce/tinymce-vue": "^4.0.7"
28
+ "vue": "^3.2.37"
27
29
  },
28
30
  "devDependencies": {
31
+ "@vitejs/plugin-vue": "^3.0.3",
32
+ "bootstrap": "^5.2.0",
33
+ "bootstrap-icons": "^1.9.1",
29
34
  "rollup": "^2.75.7",
30
35
  "rollup-plugin-css-only": "^3.1.0",
31
36
  "rollup-plugin-peer-deps-external": "^2.2.4",
32
37
  "rollup-plugin-vue": "^6.0.0",
38
+ "vite": "^3.0.7",
33
39
  "vuepress": "^2.0.0-beta.48"
40
+ },
41
+ "dependencies": {
42
+ "vue-router": "^4.1.4"
34
43
  }
35
44
  }