( app: App, plugin: QuickAdd, choiceExecutor: IChoiceExecutor, sharedVariables: Map<string, unknown> )
| 174 | private readonly preloadedUserScripts: Map<string, unknown>; |
| 175 | private readonly promptLabel?: string; |
| 176 | private buildParams( |
| 177 | app: App, |
| 178 | plugin: QuickAdd, |
| 179 | choiceExecutor: IChoiceExecutor, |
| 180 | sharedVariables: Map<string, unknown> |
| 181 | ) { |
| 182 | const variablesProxy = createVariablesProxy(sharedVariables); |
| 183 | |
| 184 | const params = { |
| 185 | app, |
| 186 | quickAddApi: QuickAddApi.GetApi(app, plugin, choiceExecutor), |
| 187 | obsidian, |
| 188 | abort: (message?: string) => { |
| 189 | throw new MacroAbortError(message); |
| 190 | }, |
| 191 | } as unknown as typeof this.params; |
| 192 | |
| 193 | // Backward compatibility: some scripts assign `QuickAdd.variables = {...}` |
| 194 | // or `params.variables = {...}`. |
| 195 | // Treat that as replacing the backing Map so templates can consume them. |
| 196 | Object.defineProperty(params, "variables", { |
| 197 | get: () => variablesProxy, |
| 198 | set: (next: unknown) => { |
| 199 | if (next === sharedVariables || next === variablesProxy) return; |
| 200 | |
| 201 | const entries = |
| 202 | next instanceof Map |
| 203 | ? Array.from(next.entries()).filter(([key]) => typeof key === "string") |
| 204 | : next && typeof next === "object" |
| 205 | ? Object.entries(next as Record<string, unknown>) |
| 206 | : null; |
| 207 | |
| 208 | // Invalid assignments are ignored to avoid wiping the backing store. |
| 209 | if (!entries) return; |
| 210 | |
| 211 | sharedVariables.clear(); |
| 212 | |
| 213 | entries?.forEach(([key, value]) => sharedVariables.set(key, value)); |
| 214 | }, |
| 215 | enumerable: true, |
| 216 | configurable: false, |
| 217 | }); |
| 218 | |
| 219 | return params; |
| 220 | } |
| 221 | |
| 222 | private initSharedVariables( |
| 223 | choiceExecutor: IChoiceExecutor, |
no test coverage detected