FFLOW 0.6.0: duplicate flows with independent settings and commands

This commit is contained in:
olivier committed 2026-11-11 21:58:52 -05:00
1 parent 60582bcb03
commit 80dc13cfe8
7 files changed
+38 -7

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ The top of the popup says what the pick will do: **Set** a property that is empt
## Flows
Everything is a flow (Settings → FFLOW). A flow has:
Everything is a flow (Settings → FFLOW). Each card's header has **Duplicate** (copies the flow right below it, named "… (copy)", with its own hotkey commands) and **Delete**. A flow has:
- **Name**: labels its hotkey commands.
- **Symbol** (optional): one character that is not a letter, digit or space. `# [ / :` are reserved (tags, links, slash commands, emoji). It fires only at the start of a word (line start or after a space), never inside frontmatter or code.
+1
View File
@@ -10,6 +10,7 @@ Nothing planned.
## Done
- 0.6.0 — Duplicate a flow from its card header: an independent deep copy inserted right below, with a unique name and id and its own next/previous commands. Keeps the original symbol and conditions.
- 0.5.0 — Conditional flows: "only on notes where property = values". Several flows can share a symbol; the note's frontmatter picks the flow. Per-flow next/previous commands only run on matching notes; flows sharing a symbol also get a shared pair. The popup header shows the property and whether the pick sets, replaces or adds. Default symbol for Type is now `&`.
- 0.4.0 — Date/time values in "also sets": `{{date}}`, `{{time}}`, `{{date:FORMAT}}`, `{{time:FORMAT}}` (moment.js). Leaving the step removes a date the flow wrote.
- 0.3.1 — Settings redesigned: collapsible flow cards with a step summary, one row of labelled fields, steps as a table with their "also sets" properties.
+1 -1
View File
@@ -2,4 +2,4 @@
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
*/
var I=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var ue=Object.prototype.hasOwnProperty;var de=(s,o)=>{for(var t in o)I(s,t,{get:o[t],enumerable:!0})},fe=(s,o,t,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of pe(o))!ue.call(s,n)&&n!==t&&I(s,n,{get:()=>o[n],enumerable:!(e=ce(o,n))||e.enumerable});return s};var ge=s=>fe(I({},"__esModule",{value:!0}),s);var xe={};de(xe,{default:()=>R});module.exports=ge(xe);var re=require("obsidian");var Y=require("obsidian");var X=require("obsidian");var N=require("obsidian"),U=String.raw`\{\{(date|time)(?::([^}]*))?\}\}`,we={date:"YYYY-MM-DD",time:"HH:mm"},z=(s,o)=>(o==null?void 0:o.trim())||we[s];function B(s){let o=(0,N.moment)();return s.replace(new RegExp(U,"g"),(t,e,n)=>o.format(z(e,n)))}function G(s,o){let t=new RegExp(U,"g"),e=[],n="^",r=0;for(let i=t.exec(s);i;i=t.exec(s))n+=W(s.slice(r,i.index))+"(.+?)",e.push(z(i[1],i[2])),r=i.index+i[0].length;if(e.length===0)return s===o;let a=new RegExp(n+W(s.slice(r))+"$").exec(o);return a!==null&&e.every((i,l)=>(0,N.moment)(a[l+1],i,!0).isValid())}function W(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}async function T(s,o,t){let e=s.workspace.getActiveViewOfType(X.MarkdownView);(e==null?void 0:e.file)===o&&await e.save(),await s.fileManager.processFrontMatter(o,t)}function Z(s,o,t,e){if(!e){s[o]=t;return}let n=H(s[o],o);n.includes(t)||n.push(t),s[o]=n}function M(s,o,t,e){var l;o[t.property]=e;let n=t.steps.find(c=>c.value===e),r=new Map,a=c=>{let u=r.get(c);return u===void 0&&r.set(c,u=he(s,o,c)),u},i=c=>c.property!==""&&c.property!==t.property;for(let c of t.steps)if(c!==n)for(let u of c.effects.filter(i)){let p=u.property;if(a(p)){let h=J(u.value),g=H(o[p],p).filter(v=>!h.some(y=>Q(y,v)));g.length?o[p]=g:delete o[p]}else p in o&&Q(u.value,o[p])&&delete o[p]}for(let c of(l=n==null?void 0:n.effects.filter(i))!=null?l:[]){let u=c.property;if(a(u)){let p=H(o[u],u);for(let h of J(c.value).map(B))p.includes(h)||p.push(h);p.length&&(o[u]=p)}else o[u]=ee(B(c.value))}}function he(s,o,t){if(["cssclasses","tags","aliases"].includes(t)||Array.isArray(o[t]))return!0;let e=Reflect.get(s,"metadataTypeManager");if(!e||typeof e!="object"||!("getPropertyInfo"in e)||typeof e.getPropertyInfo!="function")return!1;let n=e.getPropertyInfo(t),r=n&&typeof n=="object"&&"widget"in n?n.widget:null;return r==="multitext"||r==="tags"||r==="aliases"}function H(s,o){return Array.isArray(s)?s.map(String):s==null||s===""?[]:o==="cssclasses"?String(s).split(/[\s,]+/).filter(Boolean):[String(s)]}function J(s){return s.split(/,(?![^{]*\}\})/).map(o=>o.trim()).filter(Boolean)}function Q(s,o){let t=s.trim();return String(ee(t))===String(o)||G(t,String(o))}function ee(s){let o=s.trim();return o===""?null:o==="true"||o==="false"?o==="true":/^-?\d+(\.\d+)?$/.test(o)?Number(o):o}function F(s){return{id:Date.now().toString(36)+Math.random().toString(36).slice(2,6),name:"",symbol:"",property:"",kind:"ordered",valueMode:"single",loop:!1,steps:[],condition:{property:"",values:""},...s}}function me(){return{flows:[F({name:"Type",symbol:"&",property:"type",kind:"open"})]}}var j=s=>s.values.split(",").map(o=>o.trim().toLowerCase()).filter(Boolean),C=s=>s.condition.property!=="";function ye(s,o){if(!C(s))return!0;let t=o==null?void 0:o[s.condition.property],e=(Array.isArray(t)?t:[t]).filter(r=>r!=null&&String(r).trim()!=="").map(r=>String(r).trim().toLowerCase()),n=j(s.condition);return n.length===0?e.length>0:e.some(r=>n.includes(r))}function k(s,o){var t,e;return(e=(t=s.find(n=>C(n)&&ye(n,o)))!=null?t:s.find(n=>!C(n)))!=null?e:null}function te(s,o){var n;let t=s[o];if(!t.symbol)return null;let e=j(t.condition);return(n=s.slice(0,o).find(r=>{if(r.symbol!==t.symbol)return!1;if(!C(t))return!C(r);if(r.condition.property!==t.condition.property)return!1;let a=j(r.condition);return a.length===0||e.length>0&&e.every(i=>a.includes(i))}))!=null?n:null}var L=["#","[","/",":"];function E(s){return s===""?null:[...s].length!==1?"Use exactly one character.":/[\p{L}\p{N}\s]/u.test(s)?"Letters, digits and spaces are not allowed.":L.includes(s)?`"${s}" is reserved (${L.join(" ")}).`:null}function ne(s){var n,r;if(!s||typeof s!="object")return me();if("flows"in s&&!("rules"in s)&&Array.isArray(s.flows))return{flows:s.flows.map(a=>F({...a,condition:{property:"",values:"",...a.condition}}))};let o=s,t=(n=o.rules)!=null?n:[],e=((r=o.flows)!=null?r:[]).map(a=>{var i,l;return F({id:a.id,name:a.name,property:a.property,loop:a.loop,symbol:(l=(i=t.find(c=>c.source==="flow"&&c.flowId===a.id))==null?void 0:i.symbol)!=null?l:"",steps:a.steps.map(c=>({value:c.value,effects:c.cssclass.trim()?[{property:"cssclasses",value:c.cssclass.trim().split(/\s+/).join(", ")}]:[]}))})});for(let a of t)a.source==="open"&&e.push(F({name:a.property,symbol:a.symbol,property:a.property,kind:"open",valueMode:a.valueMode})),a.source==="finite"&&e.push(F({name:a.property,symbol:a.symbol,property:a.property,steps:a.values.map(i=>({value:i,effects:[]}Line truncated
var I=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var de=Object.prototype.hasOwnProperty;var fe=(o,s)=>{for(var t in s)I(o,t,{get:s[t],enumerable:!0})},ge=(o,s,t,e)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of ue(s))!de.call(o,n)&&n!==t&&I(o,n,{get:()=>s[n],enumerable:!(e=pe(s,n))||e.enumerable});return o};var we=o=>ge(I({},"__esModule",{value:!0}),o);var Ce={};fe(Ce,{default:()=>R});module.exports=we(Ce);var ie=require("obsidian");var Y=require("obsidian");var X=require("obsidian");var N=require("obsidian"),U=String.raw`\{\{(date|time)(?::([^}]*))?\}\}`,he={date:"YYYY-MM-DD",time:"HH:mm"},z=(o,s)=>(s==null?void 0:s.trim())||he[o];function B(o){let s=(0,N.moment)();return o.replace(new RegExp(U,"g"),(t,e,n)=>s.format(z(e,n)))}function G(o,s){let t=new RegExp(U,"g"),e=[],n="^",r=0;for(let i=t.exec(o);i;i=t.exec(o))n+=W(o.slice(r,i.index))+"(.+?)",e.push(z(i[1],i[2])),r=i.index+i[0].length;if(e.length===0)return o===s;let a=new RegExp(n+W(o.slice(r))+"$").exec(s);return a!==null&&e.every((i,l)=>(0,N.moment)(a[l+1],i,!0).isValid())}function W(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}async function T(o,s,t){let e=o.workspace.getActiveViewOfType(X.MarkdownView);(e==null?void 0:e.file)===s&&await e.save(),await o.fileManager.processFrontMatter(s,t)}function Z(o,s,t,e){if(!e){o[s]=t;return}let n=H(o[s],s);n.includes(t)||n.push(t),o[s]=n}function M(o,s,t,e){var l;s[t.property]=e;let n=t.steps.find(c=>c.value===e),r=new Map,a=c=>{let d=r.get(c);return d===void 0&&r.set(c,d=me(o,s,c)),d},i=c=>c.property!==""&&c.property!==t.property;for(let c of t.steps)if(c!==n)for(let d of c.effects.filter(i)){let p=d.property;if(a(p)){let w=J(d.value),g=H(s[p],p).filter(F=>!w.some(y=>Q(y,F)));g.length?s[p]=g:delete s[p]}else p in s&&Q(d.value,s[p])&&delete s[p]}for(let c of(l=n==null?void 0:n.effects.filter(i))!=null?l:[]){let d=c.property;if(a(d)){let p=H(s[d],d);for(let w of J(c.value).map(B))p.includes(w)||p.push(w);p.length&&(s[d]=p)}else s[d]=ee(B(c.value))}}function me(o,s,t){if(["cssclasses","tags","aliases"].includes(t)||Array.isArray(s[t]))return!0;let e=Reflect.get(o,"metadataTypeManager");if(!e||typeof e!="object"||!("getPropertyInfo"in e)||typeof e.getPropertyInfo!="function")return!1;let n=e.getPropertyInfo(t),r=n&&typeof n=="object"&&"widget"in n?n.widget:null;return r==="multitext"||r==="tags"||r==="aliases"}function H(o,s){return Array.isArray(o)?o.map(String):o==null||o===""?[]:s==="cssclasses"?String(o).split(/[\s,]+/).filter(Boolean):[String(o)]}function J(o){return o.split(/,(?![^{]*\}\})/).map(s=>s.trim()).filter(Boolean)}function Q(o,s){let t=o.trim();return String(ee(t))===String(s)||G(t,String(s))}function ee(o){let s=o.trim();return s===""?null:s==="true"||s==="false"?s==="true":/^-?\d+(\.\d+)?$/.test(s)?Number(s):s}function v(o){return{id:Date.now().toString(36)+Math.random().toString(36).slice(2,6),name:"",symbol:"",property:"",kind:"ordered",valueMode:"single",loop:!1,steps:[],condition:{property:"",values:""},...o}}function te(o,s){let t=o.name||o.property||"New flow",e=new Set(s.map(i=>i.name)),n=`${t} (copy)`;for(let i=2;e.has(n);i++)n=`${t} (copy ${i})`;let{id:r,...a}=structuredClone(o);return v({...a,name:n})}function ye(){return{flows:[v({name:"Type",symbol:"&",property:"type",kind:"open"})]}}var j=o=>o.values.split(",").map(s=>s.trim().toLowerCase()).filter(Boolean),C=o=>o.condition.property!=="";function ve(o,s){if(!C(o))return!0;let t=s==null?void 0:s[o.condition.property],e=(Array.isArray(t)?t:[t]).filter(r=>r!=null&&String(r).trim()!=="").map(r=>String(r).trim().toLowerCase()),n=j(o.condition);return n.length===0?e.length>0:e.some(r=>n.includes(r))}function k(o,s){var t,e;return(e=(t=o.find(n=>C(n)&&ve(n,s)))!=null?t:o.find(n=>!C(n)))!=null?e:null}function ne(o,s){var n;let t=o[s];if(!t.symbol)return null;let e=j(t.condition);return(n=o.slice(0,s).find(r=>{if(r.symbol!==t.symbol)return!1;if(!C(t))return!C(r);if(r.condition.property!==t.condition.property)return!1;let a=j(r.condition);return a.length===0||e.length>0&&e.every(i=>a.includes(i))}))!=null?n:null}var D=["#","[","/",":"];function E(o){return o===""?null:[...o].length!==1?"Use exactly one character.":/[\p{L}\p{N}\s]/u.test(o)?"Letters, digits and spaces are not allowed.":D.includes(o)?`"${o}" is reserved (${D.join(" ")}).`:null}function oe(o){var n,r;if(!o||typeof o!="object")return ye();if("flows"in o&&!("rules"in o)&&Array.isArray(o.flows))return{flows:o.flows.map(a=>v({...a,condition:{property:"",values:"",...a.condition}}))};let s=o,t=(n=s.rules)!=null?n:[],e=((r=s.flows)!=null?r:[]).map(a=>{var i,l;return v({id:a.id,name:a.name,property:a.property,loop:a.loop,symbol:(l=(i=t.find(c=>c.source==="flow"&&c.flowId===a.id))==null?void 0:i.symbol)!=null?l:"",steps:a.steps.map(c=>({value:c.value,effects:c.cssclass.trim()?[{property:"cssclasses",value:c.cssclass.trim().split(/\s+/).join(", ")}]:[]}))})});for(let a of t)a.source==="open"&&e.push(v({name:a.properLine truncated
+1 -1
View File
@@ -1,7 +1,7 @@
{
"id": "fflow",
"name": "FFLOW",
"version": "0.5.0",
"version": "0.6.0",
"minAppVersion": "1.11.0",
"description": "Frontmatter Flow: type a trigger symbol (like @) to autocomplete and set a frontmatter property.",
"author": "Olivier Legendre",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "fflow",
"version": "0.5.0",
"version": "0.6.0",
"description": "Frontmatter Flow: set properties from the editor with trigger symbols.",
"main": "main.js",
"scripts": {
+23 -3
View File
@@ -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" });
+10
View File
@@ -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" })] };
}