imbajin commented on code in PR #496:
URL: https://github.com/apache/hugegraph-doc/pull/496#discussion_r4096192395


##########
assets/js/kapa-adapter.js:
##########
@@ -306,119 +344,32 @@
     var config = readConfig(documentObject);
     if (!config) return null;
     var controller = createController(windowObject, documentObject, config);
-    var root = documentObject.getElementById('td-shell-search');
-    var input = root && root.querySelector('.td-shell-search__input');
-    var list = root && root.querySelector('.td-shell-search__list');
-    var syncing = false;
-
-    function bind(button) {
+    documentObject.querySelectorAll('[data-hg-ask-ai]').forEach(function 
(button) {
       if (button.dataset.hgAiBound !== undefined) return;
       button.dataset.hgAiBound = '';
       button.addEventListener('click', function () {
-        controller.activate(
-          button.dataset.hgAiQuery || '',
-          button.dataset.hgAiSubmit === 'true',
-          button,
-        );
+        controller.activate('', false, button);
       });
-    }
-    documentObject.querySelectorAll('[data-hg-ask-ai]').forEach(bind);
-
-    if (!input || !list) return controller;
+    });
 
-    // Keep the OINK palette untouched: only intercept Enter when local search
-    // is empty and the site-owned Ask AI tail is the available follow-up.
-    input.addEventListener('keydown', function (event) {
-      if (event.isComposing || event.keyCode === 229 || event.key !== 'Enter') 
return;
-      var empty = list.querySelector('.td-shell-search__empty');
-      var localRow = 
list.querySelector('.td-shell-search__item:not(.hg-ai-search-tail__button)');
-      var tailButton = list.querySelector('[data-hg-ai-search-tail] 
[data-hg-ask-ai]');
-      if (!empty || localRow || !tailButton) return;
-      event.preventDefault();
-      event.stopImmediatePropagation();
-      controller.activate(input.value, true, tailButton);
-    }, true);
-
-    function syncTail() {
-      syncing = false;
-      if (!root || !input || !list || root.hidden) return;
-      var old = list.querySelector('[data-hg-ai-search-tail]');
-      var query = trimmedQuery(input.value);
-      if (!query || query.charAt(0) === '>') {
-        if (old) old.remove();
-        return;
-      }
-      var choiceLabel = root.dataset.tdTChoice || '';
-      if (
-        choiceLabel &&
-        Array.prototype.some.call(
-          list.querySelectorAll('.td-shell-search__group-label'),
-          function (label) { return label.textContent.trim() === choiceLabel; 
},
-        )
-      ) {
-        if (old) old.remove();
-        return;
-      }
-      var loading = root.dataset.tdTLoading || '';
-      if (
-        loading &&
-        Array.prototype.some.call(
-          list.querySelectorAll('.td-shell-search__empty'),
-          function (node) { return node.textContent.trim() === loading; },
-        )
-      ) {
-        if (old) old.remove();
-        return;
-      }
-      var empty = list.querySelector('.td-shell-search__empty');
-      if (empty && config.labels.noResults) empty.textContent = 
config.labels.noResults;
-      var oldButton = old && old.querySelector('[data-hg-ask-ai]');
-      if (oldButton && oldButton.dataset.hgAiQuery === query) return;
-      if (old) old.remove();
-
-      var group = documentObject.createElement('div');
-      group.className = 'td-shell-search__group hg-ai-search-tail';
-      group.dataset.hgAiSearchTail = '';
-      group.setAttribute('role', 'group');
-      var label = documentObject.createElement('div');
-      label.className = 'td-shell-search__group-label';
-      label.textContent = config.labels.ask;
-      var row = documentObject.createElement('button');
-      row.type = 'button';
-      row.className = 'td-shell-search__item hg-ai-search-tail__button';
-      row.dataset.hgAskAi = '';
-      row.dataset.hgAiQuery = query;
-      row.dataset.hgAiSubmit = 'true';
-      var icon = documentObject.createElement('i');
-      icon.className =
-        'fa-solid fa-wand-magic-sparkles td-shell-search__item-icon';
-      icon.setAttribute('aria-hidden', 'true');
-      var meta = documentObject.createElement('span');
-      meta.className = 'td-shell-search__item-meta';
-      var title = documentObject.createElement('span');
-      title.className = 'td-shell-search__item-title';
-      title.textContent = config.labels.ask + ': “' + query + '”';
-      var detail = documentObject.createElement('span');
-      detail.className = 'td-shell-search__item-ref';
-      detail.textContent = config.historical ? config.labels.latest + '.' : '';
-      meta.appendChild(title);
-      meta.appendChild(detail);
-      row.appendChild(icon);
-      row.appendChild(meta);
-      group.appendChild(label);
-      group.appendChild(row);
-      list.appendChild(group);
-      bind(row);
-    }
-
-    if (list) {
-      new MutationObserver(function () {
-        if (syncing) return;
-        syncing = true;
-        windowObject.requestAnimationFrame(syncTail);
-      }).observe(list, { childList: true, subtree: true });
-      input.addEventListener('input', syncTail);
-      syncTail();
+    var palette = windowObject.OinkCommandPalette;
+    if (palette && typeof palette.registerSearchTail === 'function') {
+      palette.registerSearchTail({
+        id: 'hugegraph-ai',
+        rows: function (context) {
+          return [{
+            id: 'ask',
+            title: config.labels.ask + ': “' + context.query + '”',
+            description: config.historical ? config.labels.latest + '.' : '',
+            icon: 'fa-solid fa-wand-magic-sparkles',
+          }];
+        },

Review Comment:
   Verified that pinned OINK v1.1.0 calls the extension only for a nonempty 
query outside command/choice mode. Keeping that eligibility rule in the theme 
avoids duplicating its public search-tail contract. 
https://github.com/pgsty/oink/blob/v1.1.0/assets/js/command-palette.js#L553



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to