- stores/collective.ts (état local-first, gabarits, import/export, seeds) + stores/decisions.ts (cycle de vie complet : capture→chemin→fenêtres→ sessions→cristallisation→épreuve du réel→révocation) - data/templates.ts : 7 gabarits (Page blanche observatoire-d'abord, 5 points de départ, Institution symétrique) - composables useFeed (13 sections du Fil en sélecteurs purs) + useSearch (index unique Cmd+K/Q0) - shell : layouts default/bare, app.vue mince, useMood v2 (Source/Margelle/ Nappe/Minuit), sceau 井 = logo, LdWorkspaceSelector avec finalité A1, LdAvatarStack (premier/second lieu), LdCountdown (suspension striée) - 338 tests vitest verts, npm run build zéro erreur Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
/**
|
|
* The ONE search index — Cmd+K AND Q0 « déjà décidé ? » (same index, by
|
|
* doctrine): clauses (code + title), decisions (title), mandates (title).
|
|
* Case- and accent-insensitive. Pure selector over the collective store.
|
|
*
|
|
* EXPLICIT imports (no Nuxt auto-imports) — testable under plain vitest.
|
|
*/
|
|
|
|
import type { Id } from '../types/domain'
|
|
import { STATUS_LABELS } from '../lexicon'
|
|
import { useCollectiveStore } from '../stores/collective'
|
|
|
|
export interface SearchHit {
|
|
kind: 'clause' | 'decision' | 'mandate'
|
|
id: Id
|
|
label: string
|
|
sublabel: string
|
|
}
|
|
|
|
const MAX_HITS = 20
|
|
|
|
/** Case/accent-insensitive folding (same folding as the stores). */
|
|
function fold(text: string): string {
|
|
return text.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase()
|
|
}
|
|
|
|
export function useSearch() {
|
|
const col = useCollectiveStore()
|
|
|
|
/** Search the unique index. Empty (or blank) query ⇒ no hit. */
|
|
const search = (query: string): SearchHit[] => {
|
|
const needle = fold(query.trim())
|
|
if (needle.length === 0) return []
|
|
const hits: SearchHit[] = []
|
|
|
|
for (const clause of col.clauses) {
|
|
if (hits.length >= MAX_HITS) break
|
|
if (fold(clause.code).includes(needle) || fold(clause.title).includes(needle)) {
|
|
const doc = col.docs.find(d => d.id === clause.docId)
|
|
hits.push({
|
|
kind: 'clause',
|
|
id: clause.id,
|
|
label: `${clause.code} — ${clause.title}`,
|
|
sublabel: doc?.title ?? '',
|
|
})
|
|
}
|
|
}
|
|
|
|
for (const decision of col.decisions) {
|
|
if (hits.length >= MAX_HITS) break
|
|
if (fold(decision.title).includes(needle)) {
|
|
hits.push({
|
|
kind: 'decision',
|
|
id: decision.id,
|
|
label: decision.title,
|
|
sublabel: STATUS_LABELS[decision.status],
|
|
})
|
|
}
|
|
}
|
|
|
|
for (const mandate of col.mandates) {
|
|
if (hits.length >= MAX_HITS) break
|
|
if (fold(mandate.title).includes(needle)) {
|
|
const holder = col.people.find(p => p.id === mandate.holderId)
|
|
hits.push({
|
|
kind: 'mandate',
|
|
id: mandate.id,
|
|
label: mandate.title,
|
|
sublabel: holder?.displayName ?? '',
|
|
})
|
|
}
|
|
}
|
|
|
|
return hits
|
|
}
|
|
|
|
return { search }
|
|
}
|