tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

library-browser.ts (974B)


      1 import { fetchBytes } from './bundle.js';
      2 import { libraryIndex, type Library } from './library-index.js';
      3 let pending: Promise<Library[]> | undefined;
      4 export function loadLibraries(): Promise<Library[]> {
      5   return pending ??= fetchBytes(new URL('../reference/libraries.json', import.meta.url), 2_097_152)
      6     .then(bytes => libraryIndex(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)) as unknown))
      7     .catch(error => { pending = undefined; throw error; });
      8 }
      9 export function renderLibraryExports(list: HTMLElement, names: string[], query: string, choose: (name: string) => void): void {
     10   list.replaceChildren();
     11   for (const name of names.filter(name => name.toLowerCase().includes(query.toLowerCase()))) {
     12     const button = document.createElement('button'); button.type = 'button'; button.textContent = name;
     13     button.onclick = () => choose(name); list.append(button);
     14   }
     15   if (!list.children.length) list.textContent = 'No matching exports.';
     16 }