FFLOW 0.6.0: duplicate flows with independent settings and commands
This commit is contained in:
1 parent
60582bcb03
commit
80dc13cfe8
7 files changed
+38
-7
No files matched your search
+23
-3
@@ -11,7 +11,17 @@ import {
|
||||
ToggleComponent,
|
||||
} from "obsidian";
|
||||
import type FflowPlugin from "./main";
|
||||
import { BLOCKED_SYMBOLS, Flow, FlowKind, FlowStep, newFlow, shadowingFlow, symbolError, ValueMode } from "./settings";
|
||||
import {
|
||||
BLOCKED_SYMBOLS,
|
||||
duplicateFlow,
|
||||
Flow,
|
||||
FlowKind,
|
||||
FlowStep,
|
||||
newFlow,
|
||||
shadowingFlow,
|
||||
symbolError,
|
||||
ValueMode,
|
||||
} from "./settings";
|
||||
|
||||
export class FflowSettingTab extends PluginSettingTab {
|
||||
/** Flows shown open. Kept across redraws, not saved: every visit starts with compact cards. */
|
||||
@@ -93,7 +103,18 @@ export class FflowSettingTab extends PluginSettingTab {
|
||||
else this.expanded.delete(flow.id);
|
||||
card.toggleClass("is-collapsed", !open);
|
||||
});
|
||||
const remove = new ExtraButtonComponent(header.createDiv({ cls: "fflow-header-actions" }))
|
||||
const actions = header.createDiv({ cls: "fflow-header-actions" });
|
||||
actions.addEventListener("click", (e) => e.stopPropagation());
|
||||
new ExtraButtonComponent(actions)
|
||||
.setIcon("copy")
|
||||
.setTooltip("Duplicate flow")
|
||||
.onClick(async () => {
|
||||
const copy = duplicateFlow(flow, flows);
|
||||
flows.splice(index + 1, 0, copy);
|
||||
this.expanded.add(copy.id);
|
||||
await this.saveAndRedraw();
|
||||
});
|
||||
new ExtraButtonComponent(actions)
|
||||
.setIcon("trash-2")
|
||||
.setTooltip("Delete flow")
|
||||
.onClick(async () => {
|
||||
@@ -101,7 +122,6 @@ export class FflowSettingTab extends PluginSettingTab {
|
||||
this.expanded.delete(flow.id);
|
||||
await this.saveAndRedraw();
|
||||
});
|
||||
remove.extraSettingsEl.addEventListener("click", (e) => e.stopPropagation());
|
||||
|
||||
const body = card.createDiv({ cls: "fflow-card-body" });
|
||||
|
||||
|
||||
@@ -59,6 +59,16 @@ export function newFlow(fields: Partial<Flow>): Flow {
|
||||
};
|
||||
}
|
||||
|
||||
/** A deep copy of `flow` with a fresh id (so its own commands) and a name no other flow uses: "Status (copy)", "Status (copy 2)"… */
|
||||
export function duplicateFlow(flow: Flow, flows: Flow[]): Flow {
|
||||
const base = flow.name || flow.property || "New flow";
|
||||
const taken = new Set(flows.map((f) => f.name));
|
||||
let name = `${base} (copy)`;
|
||||
for (let n = 2; taken.has(name); n++) name = `${base} (copy ${n})`;
|
||||
const { id: _id, ...fields } = structuredClone(flow);
|
||||
return newFlow({ ...fields, name });
|
||||
}
|
||||
|
||||
export function defaultSettings(): FflowSettings {
|
||||
return { flows: [newFlow({ name: "Type", symbol: "&", property: "type", kind: "open" })] };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user