FFLOW 0.1.0: trigger symbols set frontmatter properties

This commit is contained in:
olivier committed 2026-10-25 16:02:10 -04:00
commit 021777203b
15 files changed
+1189

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
export type ValueMode = "single" | "list";
export type SourceMode = "open" | "finite";
export interface TriggerRule {
/** One non-alphanumeric character that opens the suggestions. */
symbol: string;
/** Frontmatter property written on selection. */
property: string;
/** single: replace the value. list: append to a list, no duplicates. */
valueMode: ValueMode;
/** open: values already used in the vault. finite: `values` below. */
source: SourceMode;
values: string[];
}
export interface FflowSettings {
rules: TriggerRule[];
}
export const DEFAULT_SETTINGS: FflowSettings = {
rules: [{ symbol: "@", property: "type", valueMode: "single", source: "open", values: [] }],
};
/** Reserved by Obsidian or common plugins: tags, links, slash commands, emoji shortcodes. */
export const BLOCKED_SYMBOLS = ["#", "[", "/", ":"];
/** Returns an error message, or null when `symbol` is usable by rule `index`. */
export function symbolError(symbol: string, rules: TriggerRule[], index: number): string | null {
if ([...symbol].length !== 1) return "Use exactly one character.";
if (/[\p{L}\p{N}\s]/u.test(symbol)) return "Letters, digits and spaces are not allowed.";
if (BLOCKED_SYMBOLS.includes(symbol)) return `"${symbol}" is reserved (${BLOCKED_SYMBOLS.join(" ")}).`;
if (rules.some((r, i) => i !== index && r.symbol === symbol)) return `"${symbol}" is already used by another rule.`;
return null;
}
export function isRuleActive(rule: TriggerRule, rules: TriggerRule[], index: number): boolean {
return rule.property.trim() !== "" && symbolError(rule.symbol, rules, index) === null;
}