vgapp 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -73,11 +73,11 @@ class VGSelect extends BaseModule {
73
73
  route: '',
74
74
  remote: false,
75
75
  delay: 300,
76
- minTerm: 1,
76
+ minterm: 1,
77
77
  pagination: false,
78
78
  pageParam: 'page',
79
79
  termParam: 'q',
80
- perPage: 20,
80
+ perpage: 20,
81
81
  loadMoreText: 'Загрузить ещё',
82
82
  },
83
83
  close: true,
@@ -198,8 +198,10 @@ class VGSelect extends BaseModule {
198
198
  li.classList.add(CLASS_NAME_OPTION);
199
199
  Manipulator.set(li, 'data-vg-toggle', 'select-option');
200
200
 
201
- // Если нет явно выбранных option ничего не подсвечиваем при открытии списка
202
- if (hasExplicitSelected && option.index === selectedIndex) {
201
+ // Раньше подсветка зависела от "явно выбранных" option (атрибут selected),
202
+ // из-за этого UI мог показывать placeholder, но DOM считал, что выбрана 1-я опция.
203
+ // Подсвечиваем по фактическому состоянию option.selected.
204
+ if (option.selected) {
203
205
  li.classList.add('selected');
204
206
  }
205
207
 
@@ -316,8 +318,9 @@ class VGSelect extends BaseModule {
316
318
  const index = selector.selectedIndex;
317
319
  const option = index >= 0 ? selector.options[index] : null;
318
320
  const text = option?.textContent.trim() || '';
319
- const hasExplicitSelected = this.hasExplicitSelectedOption(selector);
320
- const showPlaceholder = placeholder && (!hasExplicitSelected || !this.hasSelectedValidOption(selector));
321
+
322
+ // Placeholder показываем только если реально нет валидно выбранной опции
323
+ const showPlaceholder = placeholder && !this.hasSelectedValidOption(selector);
321
324
 
322
325
  current.innerHTML = showPlaceholder
323
326
  ? `<span class="${CLASS_NAME_PLACEHOLDER}">${placeholder}</span>`
@@ -363,7 +366,7 @@ class VGSelect extends BaseModule {
363
366
  instance._callCallback('onSearch', { term });
364
367
 
365
368
  if (params.search.remote && params.search.route) {
366
- if (term.length < (params.search.minTerm || 1)) return;
369
+ if (term.length < (params.search.minterm || 1)) return;
367
370
 
368
371
  clearTimeout(searchTimeout);
369
372
  searchTimeout = setTimeout(() => {
@@ -596,10 +599,9 @@ class VGSelect extends BaseModule {
596
599
  const index = select.selectedIndex;
597
600
  const option = index >= 0 ? select.options[index] : null;
598
601
  const text = option?.textContent.trim() || '';
599
- const value = option?.value;
600
602
 
601
- const hasExplicitSelected = this.hasExplicitSelectedOption(select);
602
- const showPlaceholder = placeholder && (!hasExplicitSelected || !value || this.isPlaceholderValue(select, value) || !text);
603
+ // Placeholder показываем только если реально нет валидно выбранной опции
604
+ const showPlaceholder = placeholder && !this.hasSelectedValidOption(select);
603
605
 
604
606
  const oldText = current.textContent;
605
607
  const newText = showPlaceholder ? placeholder : text || '-';
@@ -780,13 +782,13 @@ class VGSelect extends BaseModule {
780
782
  * @private
781
783
  */
782
784
  async _loadNextPage() {
783
- const { route, pageParam = 'page', termParam = 'q', perPage = 20 } = this._params.search;
785
+ const { route, pageParam = 'page', termParam = 'q', perpage = 20 } = this._params.search;
784
786
  const nextPage = this._currentPage + 1;
785
787
 
786
788
  const url = new URL(route, window.location.origin);
787
789
  url.searchParams.set(termParam, this._searchTerm);
788
790
  url.searchParams.set(pageParam, nextPage);
789
- url.searchParams.set('per_page', perPage);
791
+ url.searchParams.set('per_page', perpage);
790
792
 
791
793
  this._loading = true;
792
794
  this._showLoading(true);
@@ -825,11 +827,11 @@ class VGSelect extends BaseModule {
825
827
  * @private
826
828
  */
827
829
  _fetchRemoteData(term) {
828
- const { route, method = 'GET', pageParam = 'page', termParam = 'q', perPage = 20 } = this._params.search;
830
+ const { route, method = 'GET', pageParam = 'page', termParam = 'q', perpage = 20 } = this._params.search;
829
831
  const url = new URL(route, window.location.origin);
830
832
  url.searchParams.set(termParam, term);
831
833
  url.searchParams.set(pageParam, 1);
832
- url.searchParams.set('per_page', perPage);
834
+ url.searchParams.set('per_page', perpage);
833
835
 
834
836
  const searchInput = this._element.querySelector(SELECTOR_SEARCH_INPUT);
835
837
  const wasOpen = this._isShown();
@@ -871,6 +873,18 @@ class VGSelect extends BaseModule {
871
873
 
872
874
  // Очистка старых опций
873
875
  [...select.querySelectorAll('option')].forEach(opt => {
876
+ // Оставляем первый пустой скрытый placeholder:
877
+ // <option value="" selected hidden></option>
878
+ const isFirst = opt === select.options[0];
879
+ const isEmptyValue = (opt.getAttribute('value') ?? '') === '';
880
+ const isEmptyText = (opt.textContent || '').trim() === '';
881
+ const isHidden = opt.hidden === true || opt.hasAttribute('hidden');
882
+ const isSelectedAttr = opt.hasAttribute('selected');
883
+
884
+ if (isFirst && isEmptyValue && isEmptyText && isHidden && isSelectedAttr) {
885
+ return;
886
+ }
887
+
874
888
  if (!opt.hasAttribute('data-preserve') && !opt.closest('optgroup[data-preserve]')) {
875
889
  opt.remove();
876
890
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vgapp",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "",
5
5
  "author": {
6
6
  "name": "Vegas Studio",