FFLOW 0.3.1: settings redesigned as collapsible flow cards
This commit is contained in:
1 parent
8553b7c75a
commit
157e5e018a
6 files changed
+450
-219
No files matched your search
+211
-195
@@ -1,8 +1,22 @@
|
||||
import { App, PluginSettingTab, SearchComponent, Setting, SettingGroup } from "obsidian";
|
||||
import {
|
||||
App,
|
||||
DropdownComponent,
|
||||
ExtraButtonComponent,
|
||||
PluginSettingTab,
|
||||
SearchComponent,
|
||||
setIcon,
|
||||
Setting,
|
||||
setTooltip,
|
||||
TextComponent,
|
||||
ToggleComponent,
|
||||
} from "obsidian";
|
||||
import type FflowPlugin from "./main";
|
||||
import { BLOCKED_SYMBOLS, Flow, FlowKind, FlowStep, newFlow, symbolError, ValueMode } from "./settings";
|
||||
|
||||
export class FflowSettingTab extends PluginSettingTab {
|
||||
/** Flows shown open. Kept across redraws, not saved: every visit starts with compact cards. */
|
||||
private expanded = new Set<string>();
|
||||
|
||||
constructor(app: App, private plugin: FflowPlugin) {
|
||||
super(app, plugin);
|
||||
}
|
||||
@@ -23,222 +37,216 @@ export class FflowSettingTab extends PluginSettingTab {
|
||||
new Setting(containerEl)
|
||||
.setHeading()
|
||||
.setName("Flows")
|
||||
.setDesc(
|
||||
`Type a flow's symbol at the start of a word and pick a value: the text disappears, the property is set, and the step's other properties are applied. Ordered flows get “next step” and “previous step” commands for hotkeys. Reserved symbols: ${BLOCKED_SYMBOLS.join(" ")}`,
|
||||
)
|
||||
.setDesc("Type a flow's symbol at the start of a word to pick a value. Ordered flows also get next/previous step commands.")
|
||||
.addButton((b) => b.setButtonText("Hotkeys").onClick(() => this.openHotkeys()))
|
||||
.addButton((b) =>
|
||||
b.setButtonText("Add flow").onClick(async () => {
|
||||
flows.push(newFlow({ steps: [{ value: "", effects: [] }] }));
|
||||
await this.saveAndRedraw();
|
||||
}),
|
||||
b
|
||||
.setButtonText("Add flow")
|
||||
.setCta()
|
||||
.onClick(async () => {
|
||||
const flow = newFlow({ steps: [{ value: "", effects: [] }] });
|
||||
flows.push(flow);
|
||||
this.expanded.add(flow.id);
|
||||
await this.saveAndRedraw();
|
||||
}),
|
||||
);
|
||||
|
||||
flows.forEach((flow, index) => this.renderFlow(flow, index));
|
||||
const list = containerEl.createDiv({ cls: "fflow-list" });
|
||||
flows.forEach((flow, index) => this.renderFlow(list, flow, index));
|
||||
if (flows.length === 0) list.createDiv({ cls: "fflow-empty", text: "No flows yet." });
|
||||
}
|
||||
|
||||
private renderFlow(flow: Flow, index: number): void {
|
||||
private renderFlow(parent: HTMLElement, flow: Flow, index: number): void {
|
||||
const flows = this.plugin.settings.flows;
|
||||
const card = parent.createDiv({ cls: "fflow-card" });
|
||||
card.toggleClass("is-collapsed", !this.expanded.has(flow.id));
|
||||
|
||||
const title = createFragment();
|
||||
const badge = title.createSpan({ cls: "fflow-badge" });
|
||||
const name = title.createSpan();
|
||||
const updateTitle = () => {
|
||||
// Header: always visible, toggles the body.
|
||||
const header = card.createDiv({ cls: "fflow-card-header" });
|
||||
setIcon(header.createSpan({ cls: "fflow-chevron" }), "chevron-right");
|
||||
const badge = header.createSpan({ cls: "fflow-badge" });
|
||||
const title = header.createSpan({ cls: "fflow-title" });
|
||||
const summary = header.createSpan({ cls: "fflow-summary" });
|
||||
const updateHeader = () => {
|
||||
badge.setText(flow.symbol);
|
||||
badge.toggle(flow.symbol !== "");
|
||||
name.setText(flow.name || flow.property || "New flow");
|
||||
title.setText(flow.name || flow.property || "New flow");
|
||||
const values = flow.steps.map((s) => s.value).filter(Boolean);
|
||||
summary.setText(
|
||||
[flow.property, flow.kind === "open" ? "open list" : values.join(" → ") || "no steps"].filter(Boolean).join(" · "),
|
||||
);
|
||||
};
|
||||
updateTitle();
|
||||
updateHeader();
|
||||
header.addEventListener("click", () => {
|
||||
const open = !this.expanded.has(flow.id);
|
||||
if (open) this.expanded.add(flow.id);
|
||||
else this.expanded.delete(flow.id);
|
||||
card.toggleClass("is-collapsed", !open);
|
||||
});
|
||||
const remove = new ExtraButtonComponent(header.createDiv({ cls: "fflow-header-actions" }))
|
||||
.setIcon("trash-2")
|
||||
.setTooltip("Delete flow")
|
||||
.onClick(async () => {
|
||||
flows.splice(index, 1);
|
||||
this.expanded.delete(flow.id);
|
||||
await this.saveAndRedraw();
|
||||
});
|
||||
remove.extraSettingsEl.addEventListener("click", (e) => e.stopPropagation());
|
||||
|
||||
const group = new SettingGroup(this.containerEl).setHeading(title).addClass("fflow-group");
|
||||
group.addExtraButton((b) =>
|
||||
b
|
||||
.setIcon("trash")
|
||||
.setTooltip("Delete flow")
|
||||
.onClick(async () => {
|
||||
flows.splice(index, 1);
|
||||
await this.saveAndRedraw();
|
||||
}),
|
||||
);
|
||||
const body = card.createDiv({ cls: "fflow-card-body" });
|
||||
|
||||
group.addSetting((s) =>
|
||||
s
|
||||
.setName("Name")
|
||||
.setDesc(flow.kind === "ordered" ? "Labels the hotkey commands." : "For your reference.")
|
||||
.addText((t) =>
|
||||
t
|
||||
.setPlaceholder("Status")
|
||||
.setValue(flow.name)
|
||||
.onChange(async (value) => {
|
||||
flow.name = value;
|
||||
updateTitle();
|
||||
await this.save();
|
||||
}),
|
||||
),
|
||||
);
|
||||
// Identity: one compact row of labelled fields.
|
||||
const fields = body.createDiv({ cls: "fflow-fields" });
|
||||
const field = (label: string, cls = "") => {
|
||||
const el = fields.createDiv({ cls: `fflow-field ${cls}` });
|
||||
el.createDiv({ cls: "fflow-label", text: label });
|
||||
return el;
|
||||
};
|
||||
|
||||
group.addSetting((s) => {
|
||||
s.setName("Symbol").setDesc("Optional. One character, not a letter or digit.");
|
||||
const error = s.descEl.createDiv({ cls: "fflow-error" });
|
||||
error.setText(symbolError(flow.symbol, flows, index) ?? "");
|
||||
s.addText((t) => {
|
||||
t.setPlaceholder("@").setValue(flow.symbol);
|
||||
t.inputEl.addClass("fflow-symbol");
|
||||
t.onChange(async (value) => {
|
||||
const problem = symbolError(value, flows, index);
|
||||
error.setText(problem ?? "");
|
||||
// Invalid input stays in the field but is never saved.
|
||||
if (problem) return;
|
||||
flow.symbol = value;
|
||||
updateTitle();
|
||||
new TextComponent(field("Name", "is-wide"))
|
||||
.setPlaceholder("Status")
|
||||
.setValue(flow.name)
|
||||
.onChange(async (value) => {
|
||||
flow.name = value;
|
||||
updateHeader();
|
||||
await this.save();
|
||||
});
|
||||
|
||||
const symbolField = field("Symbol", "is-narrow");
|
||||
const symbol = new TextComponent(symbolField).setPlaceholder("—").setValue(flow.symbol);
|
||||
symbol.inputEl.addClass("fflow-symbol");
|
||||
setTooltip(symbol.inputEl, `Optional. One character, not a letter or digit. Reserved: ${BLOCKED_SYMBOLS.join(" ")}`);
|
||||
const error = body.createDiv({ cls: "fflow-error", text: symbolError(flow.symbol, flows, index) ?? "" });
|
||||
symbol.onChange(async (value) => {
|
||||
const problem = symbolError(value, flows, index);
|
||||
error.setText(problem ?? "");
|
||||
symbol.inputEl.toggleClass("is-invalid", problem !== null);
|
||||
// Invalid input stays in the field but is never saved.
|
||||
if (problem) return;
|
||||
flow.symbol = value;
|
||||
updateHeader();
|
||||
await this.save();
|
||||
});
|
||||
|
||||
new TextComponent(field("Property", "is-wide"))
|
||||
.setPlaceholder("status")
|
||||
.setValue(flow.property)
|
||||
.onChange(async (value) => {
|
||||
flow.property = value.trim();
|
||||
updateHeader();
|
||||
await this.save();
|
||||
});
|
||||
|
||||
new DropdownComponent(field("Kind"))
|
||||
.addOptions({ ordered: "Ordered list", open: "Open (vault)" })
|
||||
.setValue(flow.kind)
|
||||
.onChange(async (value) => {
|
||||
flow.kind = value as FlowKind;
|
||||
await this.saveAndRedraw();
|
||||
});
|
||||
|
||||
if (flow.kind === "open") {
|
||||
new DropdownComponent(field("Values"))
|
||||
.addOptions({ single: "Single value", list: "List" })
|
||||
.setValue(flow.valueMode)
|
||||
.onChange(async (value) => {
|
||||
flow.valueMode = value as ValueMode;
|
||||
await this.save();
|
||||
});
|
||||
body.createDiv({
|
||||
cls: "fflow-hint",
|
||||
text: "Suggests every value already used for this property in the vault. New values are allowed. No steps or hotkeys.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
new ToggleComponent(field("Loop", "is-toggle"))
|
||||
.setValue(flow.loop)
|
||||
.setTooltip("After the last step, “next” goes back to the first")
|
||||
.onChange(async (value) => {
|
||||
flow.loop = value;
|
||||
await this.save();
|
||||
});
|
||||
|
||||
const steps = body.createDiv({ cls: "fflow-steps" });
|
||||
const head = steps.createDiv({ cls: "fflow-step-row fflow-steps-head" });
|
||||
head.createSpan();
|
||||
head.createSpan({ text: "Value" });
|
||||
head.createSpan({ text: "Also sets" });
|
||||
flow.steps.forEach((step, i) => this.renderStep(steps, flow, step, i, updateHeader));
|
||||
|
||||
addLink(body.createDiv({ cls: "fflow-add-step" }), "Add step", async () => {
|
||||
flow.steps.push({ value: "", effects: [] });
|
||||
await this.saveAndRedraw();
|
||||
});
|
||||
|
||||
group.addSetting((s) => {
|
||||
s.setName("Property")
|
||||
.setDesc(
|
||||
flow.kind === "ordered"
|
||||
? "Ordered: the steps below, in order. Each step can set other properties."
|
||||
: "Open: every value already used in the vault; new values allowed. No steps or hotkeys.",
|
||||
)
|
||||
.addText((t) =>
|
||||
t
|
||||
.setPlaceholder("status")
|
||||
.setValue(flow.property)
|
||||
.onChange(async (value) => {
|
||||
flow.property = value.trim();
|
||||
updateTitle();
|
||||
await this.save();
|
||||
}),
|
||||
)
|
||||
.addDropdown((d) =>
|
||||
d
|
||||
.addOptions({ ordered: "Ordered list", open: "Open (vault)" })
|
||||
.setValue(flow.kind)
|
||||
.onChange(async (value) => {
|
||||
flow.kind = value as FlowKind;
|
||||
await this.saveAndRedraw();
|
||||
}),
|
||||
);
|
||||
if (flow.kind === "open") {
|
||||
s.addDropdown((d) =>
|
||||
d
|
||||
.addOptions({ single: "Single value", list: "List" })
|
||||
.setValue(flow.valueMode)
|
||||
.onChange(async (value) => {
|
||||
flow.valueMode = value as ValueMode;
|
||||
await this.save();
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (flow.kind === "open") return;
|
||||
|
||||
group.addSetting((s) =>
|
||||
s
|
||||
.setName("Loop")
|
||||
.setDesc("After the last step, “next” goes back to the first.")
|
||||
.addToggle((t) =>
|
||||
t.setValue(flow.loop).onChange(async (value) => {
|
||||
flow.loop = value;
|
||||
await this.save();
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
flow.steps.forEach((step, i) => this.renderStep(group, flow, step, i));
|
||||
|
||||
group.addSetting((s) =>
|
||||
s.addButton((b) =>
|
||||
b.setButtonText("Add step").onClick(async () => {
|
||||
flow.steps.push({ value: "", effects: [] });
|
||||
await this.saveAndRedraw();
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
private renderStep(group: SettingGroup, flow: Flow, step: FlowStep, i: number): void {
|
||||
group.addSetting((s) => {
|
||||
s.setName(`Step ${i + 1}`).setClass("fflow-step");
|
||||
s.addText((t) =>
|
||||
t
|
||||
.setPlaceholder("value")
|
||||
.setValue(step.value)
|
||||
.onChange(async (value) => {
|
||||
step.value = value.trim();
|
||||
await this.save();
|
||||
}),
|
||||
);
|
||||
s.addExtraButton((b) =>
|
||||
b
|
||||
.setIcon("list-plus")
|
||||
.setTooltip("Also set a property")
|
||||
.onClick(async () => {
|
||||
step.effects.push({ property: "", value: "" });
|
||||
await this.saveAndRedraw();
|
||||
}),
|
||||
);
|
||||
const move = async (to: number) => {
|
||||
flow.steps.splice(to, 0, ...flow.steps.splice(i, 1));
|
||||
await this.saveAndRedraw();
|
||||
};
|
||||
s.addExtraButton((b) => b.setIcon("arrow-up").setTooltip("Move up").setDisabled(i === 0).onClick(() => move(i - 1)));
|
||||
s.addExtraButton((b) =>
|
||||
b
|
||||
.setIcon("arrow-down")
|
||||
.setTooltip("Move down")
|
||||
.setDisabled(i === flow.steps.length - 1)
|
||||
.onClick(() => move(i + 1)),
|
||||
);
|
||||
s.addExtraButton((b) =>
|
||||
b
|
||||
.setIcon("x")
|
||||
.setTooltip("Remove step")
|
||||
.onClick(async () => {
|
||||
flow.steps.splice(i, 1);
|
||||
await this.saveAndRedraw();
|
||||
}),
|
||||
);
|
||||
private renderStep(parent: HTMLElement, flow: Flow, step: FlowStep, i: number, updateHeader: () => void): void {
|
||||
const row = parent.createDiv({ cls: "fflow-step-row" });
|
||||
row.createSpan({ cls: "fflow-step-num", text: String(i + 1) });
|
||||
|
||||
new TextComponent(row.createDiv({ cls: "fflow-step-value" }))
|
||||
.setPlaceholder("value")
|
||||
.setValue(step.value)
|
||||
.onChange(async (value) => {
|
||||
step.value = value.trim();
|
||||
updateHeader();
|
||||
await this.save();
|
||||
});
|
||||
|
||||
const effects = row.createDiv({ cls: "fflow-effects" });
|
||||
step.effects.forEach((effect, j) => {
|
||||
const line = effects.createDiv({ cls: "fflow-effect" });
|
||||
new TextComponent(line)
|
||||
.setPlaceholder("property")
|
||||
.setValue(effect.property)
|
||||
.onChange(async (value) => {
|
||||
effect.property = value.trim();
|
||||
await this.save();
|
||||
});
|
||||
line.createSpan({ cls: "fflow-equals", text: "=" });
|
||||
new TextComponent(line)
|
||||
.setPlaceholder("value (lists: a, b)")
|
||||
.setValue(effect.value)
|
||||
.onChange(async (value) => {
|
||||
effect.value = value;
|
||||
await this.save();
|
||||
});
|
||||
new ExtraButtonComponent(line)
|
||||
.setIcon("minus")
|
||||
.setTooltip("Remove this property")
|
||||
.onClick(async () => {
|
||||
step.effects.splice(j, 1);
|
||||
await this.saveAndRedraw();
|
||||
});
|
||||
});
|
||||
addLink(effects, "property", async () => {
|
||||
step.effects.push({ property: "", value: "" });
|
||||
await this.saveAndRedraw();
|
||||
});
|
||||
|
||||
step.effects.forEach((effect, j) =>
|
||||
group.addSetting((s) =>
|
||||
s
|
||||
.setClass("fflow-effect")
|
||||
.setDesc(j === 0 ? "Also sets" : "")
|
||||
.addText((t) =>
|
||||
t
|
||||
.setPlaceholder("property")
|
||||
.setValue(effect.property)
|
||||
.onChange(async (value) => {
|
||||
effect.property = value.trim();
|
||||
await this.save();
|
||||
}),
|
||||
)
|
||||
.addText((t) =>
|
||||
t
|
||||
.setPlaceholder("value (lists: a, b)")
|
||||
.setValue(effect.value)
|
||||
.onChange(async (value) => {
|
||||
effect.value = value;
|
||||
await this.save();
|
||||
}),
|
||||
)
|
||||
.addExtraButton((b) =>
|
||||
b
|
||||
.setIcon("x")
|
||||
.setTooltip("Remove property")
|
||||
.onClick(async () => {
|
||||
step.effects.splice(j, 1);
|
||||
await this.saveAndRedraw();
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
const actions = row.createDiv({ cls: "fflow-step-actions" });
|
||||
const move = async (to: number) => {
|
||||
flow.steps.splice(to, 0, ...flow.steps.splice(i, 1));
|
||||
await this.saveAndRedraw();
|
||||
};
|
||||
new ExtraButtonComponent(actions)
|
||||
.setIcon("arrow-up")
|
||||
.setTooltip("Move up")
|
||||
.setDisabled(i === 0)
|
||||
.onClick(() => move(i - 1));
|
||||
new ExtraButtonComponent(actions)
|
||||
.setIcon("arrow-down")
|
||||
.setTooltip("Move down")
|
||||
.setDisabled(i === flow.steps.length - 1)
|
||||
.onClick(() => move(i + 1));
|
||||
new ExtraButtonComponent(actions)
|
||||
.setIcon("trash-2")
|
||||
.setTooltip("Delete step")
|
||||
.onClick(async () => {
|
||||
flow.steps.splice(i, 1);
|
||||
await this.saveAndRedraw();
|
||||
});
|
||||
}
|
||||
|
||||
/** Opens Settings → Hotkeys filtered on this plugin. `app.setting` and the tab's search box are internal API: probe before use. */
|
||||
@@ -252,3 +260,11 @@ export class FflowSettingTab extends PluginSettingTab {
|
||||
search.inputEl.dispatchEvent(new Event("input"));
|
||||
}
|
||||
}
|
||||
|
||||
/** A quiet "+ label" button, used for adding steps and properties. */
|
||||
function addLink(parent: HTMLElement, label: string, onClick: () => Promise<void>): void {
|
||||
const button = parent.createEl("button", { cls: "fflow-add clickable-icon" });
|
||||
setIcon(button.createSpan(), "plus");
|
||||
button.createSpan({ text: label });
|
||||
button.addEventListener("click", () => void onClick());
|
||||
}
|
||||
Reference in new issue
Block a user