| 1 |
--- |
| 2 |
title: "Reference" |
| 3 |
description: "Attributes, headers, events, and configuration." |
| 4 |
--- |
| 5 |
|
| 6 |
import { getFolder } from '../../lib/content'; |
| 7 |
|
| 8 |
export const folder = await getFolder('reference'); |
| 9 |
|
| 10 |
export const ATTRIBUTE_GROUPS = [ |
| 11 |
{ label: 'Requests', titles: ['hx-get', 'hx-post', 'hx-put', 'hx-patch', 'hx-delete'] }, |
| 12 |
{ label: 'Request Control', titles: ['hx-trigger', 'hx-swap', 'hx-target', 'hx-select', 'hx-swap-oob', 'hx-select-oob', 'hx-confirm'] }, |
| 13 |
{ label: 'Scripting', titles: ['hx-on'] }, |
| 14 |
{ label: 'Data', titles: ['hx-vals', 'hx-include', 'hx-headers', 'hx-encoding'] }, |
| 15 |
{ label: 'History', titles: ['hx-push-url', 'hx-replace-url', 'hx-history-elt'] }, |
| 16 |
{ label: 'Enhancements', titles: ['hx-boost', 'hx-preload', 'hx-optimistic'] }, |
| 17 |
{ label: 'Advanced', titles: ['hx-indicator', 'hx-status', 'hx-sync', 'hx-validate', 'hx-disable', 'hx-ignore', 'hx-preserve', 'hx-action', 'hx-method', 'hx-config'] }, |
| 18 |
]; |
| 19 |
export const REQUEST_HEADERS = ['HX-Request', 'HX-Request-Type', 'HX-Current-URL', 'HX-Source', 'HX-Target', 'HX-Boosted', 'HX-History-Restore-Request', 'Accept', 'Last-Event-ID']; |
| 20 |
|
| 21 |
export const groups = folder.folders.map(sub => { |
| 22 |
const items = sub.files.map(f => ({ |
| 23 |
title: f.frontmatter.title, |
| 24 |
url: f.url, |
| 25 |
description: f.frontmatter.description, |
| 26 |
})); |
| 27 |
|
| 28 |
if (sub.slug === 'attributes') { |
| 29 |
const subgroups = ATTRIBUTE_GROUPS.map(g => ({ |
| 30 |
label: g.label, |
| 31 |
items: g.titles.map(t => items.find(i => i.title === t)).filter(Boolean), |
| 32 |
})); |
| 33 |
return { slug: sub.slug, label: sub.frontmatter.title, subgroups }; |
| 34 |
} |
| 35 |
if (sub.slug === 'headers') { |
| 36 |
const request = items.filter(i => REQUEST_HEADERS.includes(i.title)); |
| 37 |
const response = items.filter(i => !REQUEST_HEADERS.includes(i.title)); |
| 38 |
return { slug: sub.slug, label: sub.frontmatter.title, subgroups: [ |
| 39 |
{ label: 'Request', items: request }, |
| 40 |
{ label: 'Response', items: response }, |
| 41 |
]}; |
| 42 |
} |
| 43 |
return { slug: sub.slug, label: sub.frontmatter.title, subgroups: [{ label: null, items }] }; |
| 44 |
}); |
| 45 |
|
| 46 |
<div class="not-prose mb-6"> |
| 47 |
<input |
| 48 |
id="filter-input" |
| 49 |
type="text" |
| 50 |
placeholder="Search reference..." |
| 51 |
autocomplete="off" |
| 52 |
class="w-full px-3 py-2 text-sm border border-neutral-200 dark:border-neutral-800 rounded-md bg-white dark:bg-neutral-900 text-neutral-800 dark:text-neutral-200 placeholder:text-neutral-400 dark:placeholder:text-neutral-500 focus:outline-none focus:ring-2 focus:ring-neutral-300/50 dark:focus:ring-neutral-600/50 focus:border-neutral-300 dark:focus:border-neutral-600" |
| 53 |
_="on input |
| 54 |
set q to my.value.toLowerCase() |
| 55 |
if q is '' |
| 56 |
for s in <.filter-group/> remove @hidden from s end |
| 57 |
for sg in <.filter-subgroup/> remove @hidden from sg end |
| 58 |
for i in <.filter-item/> remove @hidden from i end |
| 59 |
for ct in <.filter-count/> |
| 60 |
set parts to ct.dataset.total |
| 61 |
put parts into ct |
| 62 |
end |
| 63 |
else |
| 64 |
for section in <.filter-group/> |
| 65 |
set sectionTotal to 0 |
| 66 |
for subgroup in <.filter-subgroup/> in section |
| 67 |
set subgroupTotal to 0 |
| 68 |
for item in <.filter-item/> in subgroup |
| 69 |
if item.dataset.filter contains q |
| 70 |
remove @hidden from item |
| 71 |
increment subgroupTotal |
| 72 |
else |
| 73 |
add @hidden to item |
| 74 |
end |
| 75 |
end |
| 76 |
set sectionTotal to sectionTotal + subgroupTotal |
| 77 |
if subgroupTotal is 0 then add @hidden to subgroup else remove @hidden from subgroup |
| 78 |
end |
| 79 |
put sectionTotal into first <.filter-count/> in section |
| 80 |
if sectionTotal is 0 then add @hidden to section else remove @hidden from section |
| 81 |
end |
| 82 |
end" |
| 83 |
/> |
| 84 |
</div> |
| 85 |
|
| 86 |
{groups.map(group => { |
| 87 |
const totalItems = group.subgroups.reduce((n, sg) => n + sg.items.length, 0); |
| 88 |
return ( |
| 89 |
<section class="filter-group"> |
| 90 |
<h2 id={group.slug}> |
| 91 |
<a href={`#${group.slug}`} class="no-underline interact:underline"> |
| 92 |
{group.label} |
| 93 |
</a> |
| 94 |
{' '}<span class="filter-count text-xs font-normal text-neutral-400 dark:text-neutral-500 tabular-nums inline-block -translate-y-px" data-total={totalItems}>{totalItems}</span> |
| 95 |
</h2> |
| 96 |
{group.subgroups.map(sg => ( |
| 97 |
<div class="filter-subgroup"> |
| 98 |
{sg.label && <h4 id={`${group.slug}-${sg.label.toLowerCase()}`} class="font-sans text-[0.625rem] font-normal uppercase tracking-widest text-neutral-600 dark:text-neutral-400">{sg.label}</h4>} |
| 99 |
<table> |
| 100 |
<tbody> |
| 101 |
{sg.items.map(item => ( |
| 102 |
<tr class="filter-item stretch-link" data-filter={`${item.title} ${item.description || ''}`.toLowerCase()}> |
| 103 |
<td> |
| 104 |
<a href={item.url}><code>{item.title}</code></a> |
| 105 |
{item.description && <span class="block sm:hidden text-[0.8125em] text-neutral-650 dark:text-neutral-350 mt-0.5 pl-[6px]">{item.description}</span>} |
| 106 |
</td> |
| 107 |
<td class="hidden sm:table-cell">{item.description || ''}</td> |
| 108 |
</tr> |
| 109 |
))} |
| 110 |
</tbody> |
| 111 |
</table> |
| 112 |
</div> |
| 113 |
))} |
| 114 |
</section> |
| 115 |
); |
| 116 |
})} |