import { createSignal, createMemo, Show, For, onMount, onCleanup } from 'solid-js'; import { Portal } from 'solid-js/web'; import { Button } from '@components'; import { useLicense } from '@util/context'; import { buildSearchIndex } from '@util/help-data'; import GettingStarted from './help/GettingStarted'; import Tutorials from './help/Tutorials'; import DevReference from './help/DevReference'; import Troubleshooting from './help/Troubleshooting'; import Changelog from './help/Changelog'; import Feedback from './help/Feedback'; // Export search state for header access export const [helpSearchOpen, setHelpSearchOpen] = createSignal(false); export default function Help() { const { isLocked } = useLicense(); const pluginVersion = window?.ajaxpress_admin_vars?.plugin?.version || '2.2.4'; let searchInputRef; // Get initial tab from URL hash (e.g., #/help/changelog) const getTabFromHash = () => { const hash = window.location.hash; const match = hash.match(/#\/help\/(\w+[-\w]*)/); return match ? match[1] : 'getting-started'; }; const [activeTab, setActiveTab] = createSignal(getTabFromHash()); const [tabTransition, setTabTransition] = createSignal(false); const [searchQuery, setSearchQuery] = createSignal(''); const [selectedIndex, setSelectedIndex] = createSignal(0); // Search index built from centralized help data const searchIndex = buildSearchIndex(); const searchResults = createMemo(() => { const query = searchQuery().toLowerCase().trim(); if (query.length < 2) return []; return searchIndex .filter(item => item.title.toLowerCase().includes(query) || item.content.toLowerCase().includes(query) ) .slice(0, 8); }); // Update URL when tab changes with animation const changeTab = (tabId) => { if (tabId === activeTab()) return; setTabTransition(true); setTimeout(() => { setActiveTab(tabId); window.history.replaceState(null, '', `#/help/${tabId}`); setTabTransition(false); }, 50); }; const handleSearchSelect = (item) => { changeTab(item.tab); setSearchQuery(''); setHelpSearchOpen(false); // Scroll to element after tab change, then highlight after scroll completes setTimeout(() => { const el = document.querySelector(`[data-search-title="${item.title}"]`); if (el) { el.scrollIntoView({ behavior: 'smooth', block: 'center' }); // Wait for scroll to complete before highlighting setTimeout(() => { el.classList.add('search-highlight'); setTimeout(() => el.classList.remove('search-highlight'), 2500); }, 400); } }, 150); }; // Listen for hash changes (browser back/forward) const handleHashChange = () => { setActiveTab(getTabFromHash()); }; const closeSearch = () => { setHelpSearchOpen(false); setSearchQuery(''); setSelectedIndex(0); }; // Keyboard navigation in search modal const handleSearchKeyDown = (e) => { const results = searchResults(); if (e.key === 'ArrowDown') { e.preventDefault(); setSelectedIndex(i => Math.min(i + 1, results.length - 1)); } else if (e.key === 'ArrowUp') { e.preventDefault(); setSelectedIndex(i => Math.max(i - 1, 0)); } else if (e.key === 'Enter' && results.length > 0) { e.preventDefault(); handleSearchSelect(results[selectedIndex()]); } else if (e.key === 'Escape') { closeSearch(); } }; // Global keyboard shortcut: Ctrl/Cmd + / const handleGlobalKeyDown = (e) => { if ((e.ctrlKey || e.metaKey) && e.key === '/') { e.preventDefault(); setHelpSearchOpen(true); } }; onMount(() => { window.addEventListener('hashchange', handleHashChange); document.addEventListener('keydown', handleGlobalKeyDown); }); onCleanup(() => { window.removeEventListener('hashchange', handleHashChange); document.removeEventListener('keydown', handleGlobalKeyDown); }); // Focus input when modal opens const focusInput = (el) => { setTimeout(() => el?.focus(), 50); }; const tabs = [ { id: 'getting-started', label: 'Getting Started', icon: '🚀' }, { id: 'tutorials', label: 'Tutorials', icon: '🎬' }, { id: 'dev-reference', label: 'Developer', icon: '🛠️' }, { id: 'troubleshooting', label: 'Troubleshooting', icon: '🔧' }, { id: 'changelog', label: 'Changelog', icon: '📋' }, { id: 'feedback', label: 'Feedback', icon: '💬' } ]; const getTabLabel = (tabId) => tabs.find(t => t.id === tabId)?.label || tabId; const supportLink = () => isLocked() ? 'https://wordpress.org/support/plugin/ajaxpress/' : atob('aHR0cHM6Ly9hcnJheXN0b3J5LmNvbS9zdXBwb3J0'); return (
{/* Tab Navigation */}
{(tab) => ( )}
{/* Search Modal */}
{/* Backdrop */}
{/* Modal */}
{/* Search Input */}
{ setSearchQuery(e.target.value); setSelectedIndex(0); }} onKeyDown={handleSearchKeyDown} class="ap-flex-1 ap-py-4 ap-text-base ap-bg-transparent ap-outline-none ap-placeholder-slate-400 ap-border-none ap-shadow-none focus:ap-outline-none focus:ap-ring-0 focus:ap-border-none" style={{ 'box-shadow': 'none' }} /> ESC
{/* Results */}

Type to search across all help topics

{(tab) => ( )}
= 2 && searchResults().length === 0}>

No results found for "{searchQuery()}"

0}>
{(item, index) => ( )}
{/* Footer */}
↑ ↓ navigate ↵ select
{navigator.platform.includes('Mac') ? '⌘' : 'Ctrl'} / to open
{/* Tab Content */}
); }