Files
MindSift/frontend/src/lib/wikiLink.ts
T
sandrodachandClaude Opus 5.5 68bc4d279c
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 2m20s
fix(workspace): hidden bullet actions on phones, no second extract, notice layout
- The floating bullet actions only react to hover on devices with a real
  pointer; a tap on a phone made the invisible buttons clickable.
- A bullet that is only a note link (plus hashtags) can no longer be
  extracted: button and /extract are hidden, the server answers 400.
- Extract notice on phones sits above the bottom navigation, text on
  top (two lines max) with the actions below.
- Release v0.26.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 19:56:32 +01:00

39 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Wiki links: [[Titel]], [[Titel|Anzeigetext]] and links to a single bullet [[Titel#^blockId|Anzeigetext]].
// A missing bullet just opens the note (links are not updated when a bullet moves to another note).
export interface WikiLink {
title: string;
blockId?: string;
label?: string;
}
/** Parses the inside of [[…]]. */
export function parseWikiLink(inner: string): WikiLink {
const [target, ...rest] = inner.split('|');
const label = rest.join('|').trim() || undefined;
const hash = target.indexOf('#');
const title = (hash === -1 ? target : target.slice(0, hash)).trim();
const anchor = hash === -1 ? '' : target.slice(hash + 1).trim();
return { title, blockId: anchor.startsWith('^') ? anchor.slice(1) || undefined : undefined, label };
}
/** Text shown for a link: its label, else the note title (with » for a bullet). */
export function wikiLinkText(link: WikiLink): string {
if (link.label) return link.label;
return link.blockId ? `${link.title} »` : link.title;
}
/** Link to one bullet; the label is a short excerpt of the bullet so the reader knows what it points to. */
export function buildBlockLink(title: string, blockId: string, blockContent: string): string {
const clean = (s: string) => s.replace(/[[\]|]/g, '').replace(/\s+/g, ' ').trim();
let excerpt = clean(blockContent);
if (excerpt.length > 40) excerpt = `${excerpt.slice(0, 39).trimEnd()}…`;
const label = excerpt ? `${clean(title)} › ${excerpt}` : clean(title);
return `[[${clean(title)}#^${blockId}|${label}]]`;
}
/** A bullet that is only a link to a note (plus hashtags), as left behind when a branch became a note. */
export function isNoteLinkOnly(content: string): boolean {
return /^\s*\[\[[^\]]+\]\](\s+#[\p{L}\p{N}_-]+)*\s*$/u.test(content);
}