Skip to content

Commit e581766

Browse files
authored
v0.3.0 (#44)
1 parent 0b3be0f commit e581766

17 files changed

+131
-33
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ Quickly add new pages or content to your vault.
99
You can also do a [manual installation](docs/ManualInstallation.md).
1010

1111
## What's new?
12+
### 0.3.0
13+
- Link suggestion in the input prompt now uses your Obsidian link settings by default.
14+
- Add error handling for using ``{{MACRO}}`` to execute a macro that does not exist.
15+
- Input prompt can now also suggest unresolved links.
16+
- Capped input prompt at 50 suggestions for performance in larger vaults.
17+
- You can now offset dates with ``{{DATE+3}}`` or ``{{DATE:<format>+3}}``. `+3` gives you the date in three days, while `+-3` gives you the date three days ago.
18+
- Added a new API feature which allows you to execute choices from within user scripts. These keep the current variables for the execution, so you can 'transfer' variables.
19+
1220
### 0.2.14 - 0.2.16
1321
- Add 'Insert at the end of section' feature to Captures.
1422
- Revamped the Capture & Template format suggesters. They're now more like smart-autocompleters.

docs/FormatSyntax.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## `format` syntax
22
| Template | Description |
33
| ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
4-
| `{{DATE}}` | Outputs the current date in `YYYY-MM-DD` format. |
5-
| `{{DATE:<DATEFORMAT>}}` | Replace `<DATEFORMAT>` with a [Moment.js date format](https://momentjs.com/docs/#/displaying/format/). |
4+
| `{{DATE}}` | Outputs the current date in `YYYY-MM-DD` format. You could write `{{DATE+3}}` to offset the date with 3 days. You can use `+-3` to offset with `-3` days. |
5+
| `{{DATE:<DATEFORMAT>}}` | Replace `<DATEFORMAT>` with a [Moment.js date format](https://momentjs.com/docs/#/displaying/format/). You could write `{{DATE<DATEFORMAT>+3}}` to offset the date with 3 days. |
66
| `{{VDATE:<variable name>, <date format>}}` | You'll get prompted to enter a date and it'll be parsed to the given date format. You could write 'today' or 'in two weeks' and it'll give you the date for that. Works like variables, so you can use the date in multiple places. **REQUIRES THE NATURAL LANGUAGE DATES PLUGIN!** |
77
| `{{VALUE}}` or `{{NAME}}` | Interchangeable. Represents the value given in an input prompt. If text is selected in the current editor, it will be used as the value. |
88
| `{{VALUE:<variable name>` | You can now use variable names in values. They'll get saved and inserted just like values, but the difference is that you can have as many of them as you want. Use comma separation to get a suggester rather than a prompt. |

docs/QuickAddAPI.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ Returns an array of the selected items.
3333

3434
This function is asynchronous. You should ``await`` it.
3535

36+
### ``executeChoice(choiceName: string)``
37+
Executes choice with the given name.
38+
39+
This function is asynchronous. You should ``await`` it.
40+
3641
## Utility module
3742
### ``getClipboard()``
3843
Returns the contents of your clipboard.

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"id": "quickadd",
33
"name": "QuickAdd",
4-
"version": "0.2.16",
5-
"minAppVersion": "0.12.00",
4+
"version": "0.3.0",
5+
"minAppVersion": "0.12.5",
66
"description": "Quickly add new pages or content to your vault.",
77
"author": "Christian B. B. Houmann",
88
"authorUrl": "https://bagerbach.com",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quickadd",
3-
"version": "0.2.16",
3+
"version": "0.3.0",
44
"description": "Quickly add new pages or content to your vault.",
55
"main": "main.js",
66
"scripts": {
@@ -29,7 +29,7 @@
2929
"babel-jest": "27.0.1",
3030
"jest": "27.0.1",
3131
"jest-environment-node": "27.0.1",
32-
"obsidian": "^0.12.0",
32+
"obsidian": "0.12.5",
3333
"rollup": "^2.32.1",
3434
"rollup-plugin-strip-code": "0.2.7",
3535
"rollup-plugin-svelte": "^7.1.0",

src/IChoiceExecutor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import type IChoice from "./types/choices/IChoice";
22

33
export interface IChoiceExecutor {
44
execute(choice: IChoice): Promise<void>;
5+
variables: Map<string, string>;
56
}

src/choiceExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type IMultiChoice from "./types/choices/IMultiChoice";
1414
import ChoiceSuggester from "./gui/choiceSuggester";
1515

1616
export class ChoiceExecutor implements IChoiceExecutor {
17-
private variables: Map<string, string> = new Map<string, string>();
17+
public variables: Map<string, string> = new Map<string, string>();
1818

1919
constructor(private app: App, private plugin: QuickAdd) { }
2020

src/constants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ export const FILE_NAME_FORMAT_SYNTAX: string[] = [
1616
]
1717

1818
export const FILE_NUMBER_REGEX: RegExp = new RegExp(/([0-9]*)\.md$/);
19-
export const DATE_REGEX: RegExp = new RegExp(/{{DATE(\+[0-9]*)?}}/);
20-
export const DATE_REGEX_FORMATTED: RegExp = new RegExp(/{{DATE:([^}\n\r+]*)(\+[0-9]*)?}}/);
19+
export const NUMBER_REGEX: RegExp = new RegExp(/^-?[0-9]*$/);
20+
21+
export const DATE_REGEX: RegExp = new RegExp(/{{DATE(\+-?[0-9]+)?}}/);
22+
export const DATE_REGEX_FORMATTED: RegExp = new RegExp(/{{DATE:([^}\n\r+]*)(\+-?[0-9]+)?}}/);
2123
export const NAME_VALUE_REGEX: RegExp = new RegExp(/{{NAME}}|{{VALUE}}/);
2224
export const VARIABLE_REGEX: RegExp = new RegExp(/{{VALUE:([^\n\r}]*)}}/);
2325
export const DATE_VARIABLE_REGEX: RegExp = new RegExp(/{{VDATE:([^\n\r},]*),\s*([^\n\r},]*)}}/);

src/engine/MacroChoiceEngine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {IWaitCommand} from "../types/macros/QuickCommands/IWaitCommand";
2121

2222
export class MacroChoiceEngine extends QuickAddChoiceEngine {
2323
public choice: IMacroChoice;
24-
public params = {app: this.app, quickAddApi: QuickAddApi.GetApi(this.app), variables: {}};
24+
public params;
2525
protected output: string;
2626
protected macros: IMacro[];
2727
protected choiceExecutor: IChoiceExecutor;
@@ -33,6 +33,7 @@ export class MacroChoiceEngine extends QuickAddChoiceEngine {
3333
this.plugin = plugin;
3434
this.macros = macros;
3535
this.choiceExecutor = choiceExecutor;
36+
this.params = {app: this.app, quickAddApi: QuickAddApi.GetApi(app, plugin, choiceExecutor), variables: {}};
3637

3738
variables?.forEach(((value, key) => {
3839
this.params.variables[key] = value;

src/engine/SingleMacroEngine.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {MacroChoiceEngine} from "./MacroChoiceEngine";
44
import type QuickAdd from "../main";
55
import type {IChoiceExecutor} from "../IChoiceExecutor";
66
import {getUserScriptMemberAccess} from "../utility";
7+
import {log} from "../logger/logManager";
78

89
export class SingleMacroEngine extends MacroChoiceEngine {
910
private memberAccess: string[];
@@ -15,7 +16,10 @@ export class SingleMacroEngine extends MacroChoiceEngine {
1516
public async runAndGetOutput(macroName: string): Promise<string> {
1617
const {basename, memberAccess} = getUserScriptMemberAccess(macroName);
1718
const macro = this.macros.find(macro => macro.name === basename);
18-
if (!macro) return;
19+
if (!macro) {
20+
log.logError(`macro '${macroName}' does not exist.`)
21+
return;
22+
}
1923

2024
if (memberAccess && memberAccess.length > 0) {
2125
this.memberAccess = memberAccess;

0 commit comments

Comments
 (0)