mirror of
https://github.com/backnotprop/plannotator.git
synced 2026-09-14 14:17:26 +08:00
0b167cc478
Bundle-weight optimization of @plannotator/ui for multi-chunk hosts, requested by Workspaces: the Mermaid runtime and Graphviz engine load inside the render effect, the username dictionary sits behind a synchronous identity generator slot, and KaTeX sits behind a math renderer slot with a loader seam on configurePlannotatorUI. Plannotator's own apps import eager entries (math, identity, and Mermaid for the plan editor) so their behavior is unchanged: single-file builds within noise of main, math typeset on first paint, identities from the full dictionary, and the share portal keeps Mermaid in its entry chunk so its failure surface matches main. Built-HTML registration markers guard the eager imports. Hosts that omit the eager entries get the lazy paths, a one-shot automatic re-attempt, and a Retry affordance on the diagram error panel; the module-map limitation of in-page retries is documented. AI-assisted (Claude) under maintainer direction.
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
/**
|
|
* Eager identity registration: installs the full `unique-username-generator`
|
|
* dictionary into the generator slot in `./generateIdentity` at module
|
|
* evaluation, before any settings read can mint a name.
|
|
*
|
|
* Every Plannotator entry (`packages/editor/App.tsx`, `packages/review-editor/App.tsx`)
|
|
* imports this module for its side effect, which keeps Plannotator's tater
|
|
* names byte-identical to before: same library, same config, same call. A host
|
|
* that wants the full dictionary without its own identity provider imports it
|
|
* too:
|
|
*
|
|
* import '@plannotator/ui/utils/identity-tater';
|
|
*
|
|
* A host that provides `identityProvider` never calls the generator and should
|
|
* NOT import this, so the word lists stay out of its bundle.
|
|
*/
|
|
import { uniqueUsernameGenerator, adjectives, nouns } from 'unique-username-generator';
|
|
import { setIdentityGenerator, type IdentityGenerator } from './generateIdentity';
|
|
|
|
/** The dictionary generator Plannotator has always used. */
|
|
export const generateTaterIdentity: IdentityGenerator = () => {
|
|
// Use a unique separator to split adjective from noun, avoiding issues
|
|
// with compound words that contain hyphens (e.g., "behind-the-scenes")
|
|
const generated = uniqueUsernameGenerator({
|
|
dictionaries: [adjectives, nouns],
|
|
separator: '|||',
|
|
style: 'lowerCase',
|
|
randomDigits: 0,
|
|
length: 50, // Prevent word truncation (default is too short)
|
|
});
|
|
|
|
const [adjective, noun] = generated.split('|||');
|
|
return `${adjective}-${noun}-tater`;
|
|
};
|
|
|
|
setIdentityGenerator(generateTaterIdentity);
|