feat: publish HoloLake model-native living system source
This commit is contained in:
parent
6ad10edde1
commit
c395dd3a99
2467 changed files with 615073 additions and 0 deletions
64
product-source/hololake-platform/src/utils/sheetWikilinks.ts
Normal file
64
product-source/hololake-platform/src/utils/sheetWikilinks.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import type { VaultEntry } from '../types'
|
||||
import { resolveNoteIcon } from './noteIcon'
|
||||
import { lookupColorForEntry } from './wikilinkColors'
|
||||
import { resolveEntry, wikilinkDisplay, wikilinkTarget } from './wikilink'
|
||||
|
||||
const SHEET_WIKILINK_PATTERN = /\[\[([^\]\n]+?)\]\]/g
|
||||
|
||||
function wikilinkRef(rawTarget: string): string {
|
||||
return `[[${rawTarget}]]`
|
||||
}
|
||||
|
||||
function displayTitleForTarget(rawTarget: string, entry: VaultEntry | undefined): string {
|
||||
const pipeIndex = rawTarget.indexOf('|')
|
||||
if (pipeIndex >= 0) return rawTarget.slice(pipeIndex + 1)
|
||||
return entry?.title ?? wikilinkDisplay(wikilinkRef(rawTarget))
|
||||
}
|
||||
|
||||
function displayIconForEntry(entry: VaultEntry | undefined): string {
|
||||
const icon = resolveNoteIcon(entry?.icon)
|
||||
return icon.kind === 'emoji' ? `${icon.value} ` : ''
|
||||
}
|
||||
|
||||
function resolveTargetEntry(
|
||||
entries: VaultEntry[],
|
||||
rawTarget: string,
|
||||
sourceEntry?: VaultEntry | null,
|
||||
): VaultEntry | undefined {
|
||||
return resolveEntry(entries, wikilinkTarget(wikilinkRef(rawTarget)), sourceEntry ?? undefined)
|
||||
}
|
||||
|
||||
export function sheetCellContainsPlainWikilink(value: string): boolean {
|
||||
SHEET_WIKILINK_PATTERN.lastIndex = 0
|
||||
return !value.trimStart().startsWith('=') && SHEET_WIKILINK_PATTERN.test(value)
|
||||
}
|
||||
|
||||
export function sheetWikilinkDisplayValue(
|
||||
value: string,
|
||||
entries: VaultEntry[],
|
||||
sourceEntry?: VaultEntry | null,
|
||||
): string {
|
||||
SHEET_WIKILINK_PATTERN.lastIndex = 0
|
||||
return value.replace(SHEET_WIKILINK_PATTERN, (_match, rawTarget: string) => {
|
||||
const entry = resolveTargetEntry(entries, rawTarget, sourceEntry)
|
||||
return `${displayIconForEntry(entry)}${displayTitleForTarget(rawTarget, entry)}`
|
||||
})
|
||||
}
|
||||
|
||||
export function firstSheetWikilinkTarget(value: string): string | null {
|
||||
SHEET_WIKILINK_PATTERN.lastIndex = 0
|
||||
return SHEET_WIKILINK_PATTERN.exec(value)?.[1] ?? null
|
||||
}
|
||||
|
||||
export function sheetWikilinkColor(
|
||||
value: string,
|
||||
entries: VaultEntry[],
|
||||
sourceEntry: VaultEntry | null | undefined,
|
||||
fallback: string,
|
||||
): string {
|
||||
const rawTarget = firstSheetWikilinkTarget(value)
|
||||
if (!rawTarget) return fallback
|
||||
|
||||
const entry = resolveTargetEntry(entries, rawTarget, sourceEntry)
|
||||
return entry ? lookupColorForEntry(entries, entry) : 'var(--text-muted)'
|
||||
}
|
||||
Loading…
Reference in a new issue