Skip to content

Commit 9fd934c

Browse files
committed
1.0 release prep
1 parent c37b846 commit 9fd934c

File tree

20 files changed

+181
-19
lines changed

20 files changed

+181
-19
lines changed

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
# Obsidian Meta Bind Changelog
22

3+
# 1.0.0
4+
5+
New Features
6+
7+
- Added new input field `imageListSuggester`, a list variant of the `imageSuggester` input field [#193](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/193)
8+
- Added new input field `dateTime`, a combined date and time input field, using the native obsidian data time input [#193](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/193)
9+
- Added new input field argument `multiLine` to add multi line support to the `list` input field [#232](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/242)
10+
- Added new input field argument `allowOther` to allow non suggester values to the `suggester`, `listSuggester` and `inlineListSuggester` input fields [#234](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/234)
11+
- Added new view field `ìmage` to display images in the note, it functions similar to the link view field [#246](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/246)
12+
- Added new view field argument `class` to all view fields to add custom classes to the view field, similar to the `class` input field argument [#260](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/260)
13+
- Added new button action `createNote` to create a new note [#206](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/206)
14+
- Added new button action `replaceInNote` to replace lines in the note of the button [#206](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/206)
15+
- Added new button action `regexpReplaceInNote` to replace run a regular expression replace in the note of the button [#206](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/206)
16+
- Added new button action `insertIntoNote` to insert text at a specified line in the note of the button [#206](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/206)
17+
- Added new button action `replaceSelf` to replace the button with a string or templater template [#206](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/206)
18+
- Added new button action `inlineJS` to run a JavaScript snippet
19+
- Added the option to add icons to buttons [#273](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/273)
20+
- Added a command to easily copy command IDs to the clipboard [#247](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/247)
21+
- Added support for reordering in all list type input fields
22+
- Added support for editing in some list type input fields
23+
24+
Changes
25+
26+
- **BREAKING** Completely reworked the plugins JavaScript API
27+
- Restyled the following input fields: `list`, `listSuggester`, `inlineList`, `inlineListSuggester`, `imageSuggester`, `imageListSuggester`, `select` and `multiSelect` to be more in line with Obsidian's design
28+
- Changed the date and time input fields to use the native obsidian date and time inputs
29+
- Added the ability for the `open` button action to open the link in a new tab
30+
- Added the button config and args as available variables in the JS button action [#242](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/242)
31+
- Added view field examples into the FAQ [#186](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/186)
32+
- Major restructuring of the plugin codebase to allow for easier development on the publish version of the plugin
33+
34+
Bug Fixes
35+
36+
- Fixed FAQ not opening [#230](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/230)
37+
- Fixed an issue with settings reverting when using a sync service [#235](https://github.com/mProjectsCode/obsidian-meta-bind-plugin/issues/235)
38+
- Fixed in issue where the plugin would sometimes incorrectly complain about duplicate button ids
39+
340
# 0.12.5
441

542
Bug Fixes

bun.lockb

0 Bytes
Binary file not shown.

exampleVault/Buttons/Button Example.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,20 @@ actions:
185185
186186
```
187187

188+
```meta-bind-button
189+
label: Inline Js
190+
icon: "file-code"
191+
hidden: false
192+
class: ""
193+
tooltip: ""
194+
id: ""
195+
style: default
196+
actions:
197+
- type: inlineJS
198+
code: console.log("Hello world")
199+
200+
```
201+
188202
### Modifying Front-matter
189203

190204
```meta-bind-button

exampleVault/Input Fields/Suggester.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ showcase
2929
### Suggester with Dataview
3030

3131
Note, that this will error, if dataview is not enabled.
32+
33+
`INPUT[suggester(optionQuery(#example-note)):fileSuggest]`
34+
3235
```meta-bind
3336
INPUT[suggester(optionQuery(#example-note), showcase):fileSuggest]
3437
```

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
"license": "GPL-3.0",
3030
"devDependencies": {
3131
"@happy-dom/global-registrator": "^13.10.1",
32-
"@tsconfig/svelte": "^5.0.3",
33-
"@types/bun": "^1.0.10",
34-
"@typescript-eslint/eslint-plugin": "^7.3.1",
35-
"@typescript-eslint/parser": "^7.3.1",
32+
"@tsconfig/svelte": "^5.0.4",
33+
"@types/bun": "^1.0.11",
34+
"@typescript-eslint/eslint-plugin": "^7.4.0",
35+
"@typescript-eslint/parser": "^7.4.0",
3636
"builtin-modules": "^3.3.0",
3737
"elysia": "^0.8.17",
3838
"esbuild": "^0.20.2",

packages/core/src/api/InternalAPI.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,17 @@ export abstract class InternalAPI<Plugin extends IPlugin> {
126126
*
127127
* @param code
128128
* @param callingFilePath
129+
* @param contextOverrides
129130
* @param container
130131
*
131132
* @returns Cleanup callback.
132133
*/
133-
abstract jsEngineRunCode(code: string, callingFilePath: string, container?: HTMLElement): Promise<() => void>;
134+
abstract jsEngineRunCode(
135+
code: string,
136+
callingFilePath: string,
137+
contextOverrides: Record<string, unknown>,
138+
container?: HTMLElement,
139+
): Promise<() => void>;
134140

135141
/**
136142
* Creates a js renderer, used for the js view field.

packages/core/src/config/ButtonConfig.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export enum ButtonActionType {
1818
REGEXP_REPLACE_IN_NOTE = 'regexpReplaceInNote',
1919
REPLACE_SELF = 'replaceSelf',
2020
INSERT_INTO_NOTE = 'insertIntoNote',
21+
INLINE_JS = 'inlineJS',
2122
}
2223

2324
export interface CommandButtonAction {
@@ -96,6 +97,11 @@ export interface InsertIntoNoteButtonAction {
9697
templater?: boolean;
9798
}
9899

100+
export interface InlineJsButtonAction {
101+
type: ButtonActionType.INLINE_JS;
102+
code: string;
103+
}
104+
99105
export type ButtonAction =
100106
| CommandButtonAction
101107
| JSButtonAction
@@ -108,10 +114,12 @@ export type ButtonAction =
108114
| ReplaceInNoteButtonAction
109115
| ReplaceSelfButtonAction
110116
| RegexpReplaceInNoteButtonAction
111-
| InsertIntoNoteButtonAction;
117+
| InsertIntoNoteButtonAction
118+
| InlineJsButtonAction;
112119

113120
export interface ButtonConfig {
114121
label: string;
122+
icon?: string;
115123
style: ButtonStyleType;
116124
class?: string;
117125
tooltip?: string;

packages/core/src/config/ButtonConfigValidators.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ButtonStyleType,
66
type CommandButtonAction,
77
type CreateNoteButtonAction,
8+
type InlineJsButtonAction,
89
type InputButtonAction,
910
type InsertIntoNoteButtonAction,
1011
type JSButtonAction,
@@ -118,6 +119,13 @@ export const V_InsertIntoNoteButtonAction = schemaForType<InsertIntoNoteButtonAc
118119
}),
119120
);
120121

122+
export const V_InlineJsButtonAction = schemaForType<InlineJsButtonAction>()(
123+
z.object({
124+
type: z.literal(ButtonActionType.INLINE_JS),
125+
code: z.string(),
126+
}),
127+
);
128+
121129
export const V_ButtonAction = schemaForType<ButtonAction>()(
122130
z.union([
123131
V_CommandButtonAction,
@@ -132,6 +140,7 @@ export const V_ButtonAction = schemaForType<ButtonAction>()(
132140
V_ReplaceSelfButtonAction,
133141
V_RegexpReplaceInNoteButtonAction,
134142
V_InsertIntoNoteButtonAction,
143+
V_InlineJsButtonAction,
135144
]),
136145
);
137146

@@ -141,6 +150,7 @@ export const V_ButtonConfig = schemaForType<ButtonConfig>()(
141150
z
142151
.object({
143152
label: z.string(),
153+
icon: z.string().optional(),
144154
style: V_ButtonStyleType,
145155
class: z.string().optional(),
146156
tooltip: z.string().optional(),

packages/core/src/fields/button/ButtonActionRunner.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ButtonStyleType,
77
type CommandButtonAction,
88
type CreateNoteButtonAction,
9+
type InlineJsButtonAction,
910
type InputButtonAction,
1011
type InsertIntoNoteButtonAction,
1112
type JSButtonAction,
@@ -33,6 +34,7 @@ export class ButtonActionRunner {
3334
createDefaultButtonConfig(): ButtonConfig {
3435
return {
3536
label: 'This is a button',
37+
icon: '',
3638
hidden: false,
3739
class: '',
3840
tooltip: '',
@@ -137,6 +139,11 @@ export class ButtonActionRunner {
137139
line: 0,
138140
value: 'Some text',
139141
} satisfies InsertIntoNoteButtonAction;
142+
} else if (type === ButtonActionType.INLINE_JS) {
143+
return {
144+
type: ButtonActionType.INLINE_JS,
145+
code: 'console.log("Hello world")',
146+
} satisfies InlineJsButtonAction;
140147
}
141148

142149
expectType<never>(type);
@@ -197,6 +204,9 @@ export class ButtonActionRunner {
197204
} else if (action.type === ButtonActionType.INSERT_INTO_NOTE) {
198205
await this.runInsertIntoNoteAction(action, filePath);
199206
return;
207+
} else if (action.type === ButtonActionType.INLINE_JS) {
208+
await this.runInlineJsAction(config, action, filePath);
209+
return;
200210
}
201211

202212
expectType<never>(action);
@@ -210,8 +220,8 @@ export class ButtonActionRunner {
210220

211221
async runJSAction(config: ButtonConfig | undefined, action: JSButtonAction, filePath: string): Promise<void> {
212222
const configOverrides: Record<string, unknown> = {
213-
buttonConfig: config,
214-
args: action.args,
223+
buttonConfig: structuredClone(config),
224+
args: structuredClone(action.args),
215225
};
216226
const unloadCallback = await this.plugin.internal.jsEngineRunFile(action.file, filePath, configOverrides);
217227
unloadCallback();
@@ -333,4 +343,16 @@ export class ButtonActionRunner {
333343

334344
await this.plugin.internal.writeFilePath(filePath, splitContent.join('\n'));
335345
}
346+
347+
async runInlineJsAction(
348+
config: ButtonConfig | undefined,
349+
action: InlineJsButtonAction,
350+
filePath: string,
351+
): Promise<void> {
352+
const configOverrides: Record<string, unknown> = {
353+
buttonConfig: structuredClone(config),
354+
};
355+
const unloadCallback = await this.plugin.internal.jsEngineRunCode(action.code, filePath, configOverrides);
356+
unloadCallback();
357+
}
336358
}

packages/core/src/fields/button/ButtonField.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export class ButtonField extends Mountable {
5656
this.buttonComponent = new ButtonComponent({
5757
target: targetEl,
5858
props: {
59+
plugin: this.plugin,
60+
icon: this.config.icon,
5961
variant: this.config.style,
6062
label: this.config.label,
6163
tooltip: isTruthy(this.config.tooltip) ? this.config.tooltip : this.config.label,

0 commit comments

Comments
 (0)