Jake Vanderwerf
2026-01-04 d38d825e3484d822ea3c1f0fb1df37ecf386b18a
assets/js/concise/TaxonomySelector.js
@@ -16,7 +16,7 @@
      this.subscribers = new Set();
      this.store = window.jvbStore.register(
      const store = window.jvbStore.register(
         'taxonomies',
         {
            storeName: `terms`,
@@ -39,6 +39,7 @@
            required: 'taxonomy',
            delayFetch: true,
         });
      this.store = store.terms;
      // Central field management
      this.fields = new Map();
@@ -479,7 +480,13 @@
   initAutocomplete()
   {
      this.autocompleteHandler = window.debounce((e) => this.handleAutocomplete(e), 300);
      this.autocompleteHandler = (e) => {
         window.debouncer.schedule(
            'taxonomy-autocomplete',
            () => this.handleAutocomplete(e),
            300
         );
      };
      document.addEventListener('input', this.autocompleteHandler);
      document.addEventListener('blur', this.cleanupAutocomplete.bind(this));
      // Preload taxonomy data on focus
@@ -1125,11 +1132,17 @@
         });
      }
      // Use stored current query instead of debounced one
      // Only show create button if exact match doesn't exist
      const currentQuery = field.currentAutocompleteQuery || query;
      if (field.canCreate && currentQuery && window.jvbTaxCreator) {
         const createOption = this.createNewTermOption(currentQuery);
         dropdown.appendChild(createOption);
         const exactMatch = terms.find(term =>
            term.name.toLowerCase() === currentQuery.toLowerCase()
         );
         if (!exactMatch) {
            const createOption = this.createNewTermOption(currentQuery);
            dropdown.appendChild(createOption);
         }
      }
      dropdown.hidden = false;
@@ -1544,5 +1557,10 @@
 * Initialize singleton
 */
document.addEventListener('DOMContentLoaded', function() {
   window.jvbSelector = new TaxonomySelector();
   window.auth.subscribe((event) => {
      if (event === 'auth-loaded') {
         window.jvbSelector = new TaxonomySelector();
      }
   });
});