- Introduced a new command to build semantic mapping blocks by section, including user prompts for overwriting existing mappings. - Enhanced settings interface with options for mapping wrapper type, title, folded state, default edge type, unassigned handling, and overwrite permissions. - Implemented virtualization in the EntityPickerModal for improved performance when displaying large sets of entries, including scroll handling and item rendering optimizations. - Updated UI components to reflect new settings and functionalities, ensuring a cohesive user experience.
89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
/**
|
|
* Build worklist of links for prompt mode.
|
|
*/
|
|
|
|
import { App, TFile } from "obsidian";
|
|
import type { EdgeVocabulary } from "../vocab/types";
|
|
import { extractWikilinks } from "./sectionParser";
|
|
import { extractExistingMappings } from "./mappingExtractor";
|
|
|
|
export interface LinkWorkItem {
|
|
link: string; // Wikilink basename
|
|
targetType: string | null; // Note type from metadataCache/frontmatter
|
|
currentType: string | null; // Existing edge type mapping, if any
|
|
}
|
|
|
|
export interface SectionWorklist {
|
|
sectionHeading: string | null;
|
|
items: LinkWorkItem[];
|
|
}
|
|
|
|
/**
|
|
* Build worklist for a section.
|
|
*/
|
|
export async function buildSectionWorklist(
|
|
app: App,
|
|
sectionContent: string,
|
|
sectionHeading: string | null,
|
|
wrapperCalloutType: string,
|
|
wrapperTitle: string
|
|
): Promise<SectionWorklist> {
|
|
// Extract all wikilinks (deduplicated)
|
|
const links = extractWikilinks(sectionContent);
|
|
|
|
// Extract existing mappings
|
|
const mappingState = extractExistingMappings(
|
|
sectionContent,
|
|
wrapperCalloutType,
|
|
wrapperTitle
|
|
);
|
|
|
|
// Build worklist items
|
|
const items: LinkWorkItem[] = [];
|
|
|
|
for (const link of links) {
|
|
// Get target file
|
|
const targetFile = app.metadataCache.getFirstLinkpathDest(link, "");
|
|
|
|
// Get target type from frontmatter
|
|
let targetType: string | null = null;
|
|
if (targetFile) {
|
|
const cache = app.metadataCache.getFileCache(targetFile);
|
|
if (cache?.frontmatter) {
|
|
targetType = cache.frontmatter.type || cache.frontmatter.noteType || null;
|
|
if (targetType && typeof targetType !== "string") {
|
|
targetType = String(targetType);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Get current mapping
|
|
const currentType = mappingState.existingMappings.get(link) || null;
|
|
|
|
items.push({
|
|
link,
|
|
targetType,
|
|
currentType,
|
|
});
|
|
}
|
|
|
|
return {
|
|
sectionHeading,
|
|
items,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get source type from current file.
|
|
*/
|
|
export function getSourceType(app: App, file: TFile): string | null {
|
|
const cache = app.metadataCache.getFileCache(file);
|
|
if (cache?.frontmatter) {
|
|
const type = cache.frontmatter.type || cache.frontmatter.noteType || null;
|
|
if (type && typeof type === "string") {
|
|
return type;
|
|
}
|
|
}
|
|
return null;
|
|
}
|