MCPcopy Create free account
hub / github.com/chhoumann/quickadd / buildTemplatePickerItems

Function buildTemplatePickerItems

src/engine/applyTemplateToActiveNote.ts:72–101  ·  view source on GitHub ↗
(
	choices: IChoice[],
	templateFilePaths: string[],
)

Source from the content-addressed store, hash-verified

70 * Multis), then raw template files not already covered by a choice.
71 */
72export function buildTemplatePickerItems(
73 choices: IChoice[],
74 templateFilePaths: string[],
75): TemplatePickerItem[] {
76 const templateChoices = flattenChoices(choices).filter(
77 (choice): choice is ITemplateChoice =>
78 choice.type === "Template" &&
79 Boolean((choice as ITemplateChoice).templatePath) &&
80 isMarkdownTemplatePath((choice as ITemplateChoice).templatePath),
81 );
82
83 const coveredPaths = new Set(
84 templateChoices.map((choice) =>
85 normalizeTemplatePathForComparison(choice.templatePath),
86 ),
87 );
88
89 const items: TemplatePickerItem[] = templateChoices.map((choice) => ({
90 kind: "choice",
91 choice,
92 }));
93
94 for (const path of templateFilePaths) {
95 if (!isMarkdownTemplatePath(path)) continue;
96 if (coveredPaths.has(normalizeTemplatePathForComparison(path))) continue;
97 items.push({ kind: "file", path });
98 }
99
100 return items;
101}
102
103/**
104 * Applies a template to an existing note (issue #526).

Callers 2

pickTemplateFunction · 0.85

Calls 4

flattenChoicesFunction · 0.90
isMarkdownTemplatePathFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected