FFLOW 0.2.0: flows with next/previous commands and per-step cssclasses; grouped settings page
This commit is contained in:
1 parent
021777203b
commit
68e390fb37
12 files changed
+486
-165
No files matched your search
+41
-8
@@ -1,24 +1,45 @@
|
||||
export type ValueMode = "single" | "list";
|
||||
export type SourceMode = "open" | "finite";
|
||||
export type SourceMode = "open" | "finite" | "flow";
|
||||
|
||||
export interface TriggerRule {
|
||||
/** One non-alphanumeric character that opens the suggestions. */
|
||||
symbol: string;
|
||||
/** Frontmatter property written on selection. */
|
||||
/** Frontmatter property written on selection. Ignored for flow sources: the flow owns it. */
|
||||
property: string;
|
||||
/** single: replace the value. list: append to a list, no duplicates. */
|
||||
/** single: replace the value. list: append to a list, no duplicates. Flows are always single. */
|
||||
valueMode: ValueMode;
|
||||
/** open: values already used in the vault. finite: `values` below. */
|
||||
/** open: values already used in the vault. finite: `values`. flow: the steps of `flowId`. */
|
||||
source: SourceMode;
|
||||
values: string[];
|
||||
flowId: string;
|
||||
}
|
||||
|
||||
export interface FlowStep {
|
||||
value: string;
|
||||
/** Space-separated classes added to `cssclasses` while the note is on this step. */
|
||||
cssclass: string;
|
||||
}
|
||||
|
||||
export interface Flow {
|
||||
/** Stable id: command ids derive from it, so hotkeys survive renames. */
|
||||
id: string;
|
||||
name: string;
|
||||
property: string;
|
||||
/** After the last step, "next" goes back to the first (and "previous" the other way). */
|
||||
loop: boolean;
|
||||
steps: FlowStep[];
|
||||
}
|
||||
|
||||
export interface FflowSettings {
|
||||
rules: TriggerRule[];
|
||||
flows: Flow[];
|
||||
}
|
||||
|
||||
export const NEW_RULE: TriggerRule = { symbol: "", property: "", valueMode: "single", source: "open", values: [], flowId: "" };
|
||||
|
||||
export const DEFAULT_SETTINGS: FflowSettings = {
|
||||
rules: [{ symbol: "@", property: "type", valueMode: "single", source: "open", values: [] }],
|
||||
rules: [{ ...NEW_RULE, symbol: "@", property: "type" }],
|
||||
flows: [],
|
||||
};
|
||||
|
||||
/** Reserved by Obsidian or common plugins: tags, links, slash commands, emoji shortcodes. */
|
||||
@@ -29,10 +50,22 @@ export function symbolError(symbol: string, rules: TriggerRule[], index: number)
|
||||
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.`;
|
||||
if (rules.some((r, i) => i !== index && r.symbol === symbol)) return `"${symbol}" is already used by another trigger.`;
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isRuleActive(rule: TriggerRule, rules: TriggerRule[], index: number): boolean {
|
||||
return rule.property.trim() !== "" && symbolError(rule.symbol, rules, index) === null;
|
||||
/** What a usable trigger writes to; null when the rule is incomplete or points to a missing flow. */
|
||||
export function resolveRule(settings: FflowSettings, index: number): { property: string; flow: Flow | null } | null {
|
||||
const rule = settings.rules[index];
|
||||
if (symbolError(rule.symbol, settings.rules, index)) return null;
|
||||
if (rule.source === "flow") {
|
||||
const flow = settings.flows.find((f) => f.id === rule.flowId);
|
||||
return flow && flow.property ? { property: flow.property, flow } : null;
|
||||
}
|
||||
return rule.property ? { property: rule.property, flow: null } : null;
|
||||
}
|
||||
|
||||
/** Steps usable at runtime: blank values are skipped. */
|
||||
export function flowSteps(flow: Flow): FlowStep[] {
|
||||
return flow.steps.filter((s) => s.value.trim() !== "");
|
||||
}
|
||||
Reference in new issue
Block a user