Skip to content

Commit 2455d19

Browse files
committed
more comments; preview in FAQ; fix #142
1 parent aaccbc6 commit 2455d19

File tree

83 files changed

+1210
-382
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1210
-382
lines changed

.eslintrc.cjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ const config = {
2222
rules: {
2323
'@typescript-eslint/no-explicit-any': ['warn'],
2424

25-
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_' }],
26-
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports', fixStyle: 'inline-type-imports' }],
25+
'@typescript-eslint/no-unused-vars': [
26+
'error',
27+
{ argsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_' },
28+
],
29+
'@typescript-eslint/consistent-type-imports': [
30+
'error',
31+
{ prefer: 'type-imports', fixStyle: 'inline-type-imports' },
32+
],
2733

2834
'@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: true }],
2935
'@typescript-eslint/restrict-template-expressions': 'off',

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"plugins": ["prettier-plugin-svelte"],
33

4-
"printWidth": 160,
4+
"printWidth": 120,
55
"useTabs": true,
66
"semi": true,
77
"singleQuote": true,

automation/shellUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ function exec(c: string): Subprocess<'ignore', 'pipe', 'inherit'> {
1111
return Bun.spawn(stringArgv(c));
1212
}
1313

14-
export async function $(cmd: string, verboseness: Verboseness = Verboseness.NORMAL): Promise<{ stdout: string; stderr: string; exit: number }> {
14+
export async function $(
15+
cmd: string,
16+
verboseness: Verboseness = Verboseness.NORMAL,
17+
): Promise<{ stdout: string; stderr: string; exit: number }> {
1518
if (verboseness === Verboseness.NORMAL || verboseness === Verboseness.VERBOSE) {
1619
console.log(`\n${CMD_FMT.Bright}running${CMD_FMT.Reset} - ${cmd}\n`);
1720
}

exampleVault/View Fields/View Field.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
number1: 12
2+
number1: 13
33
number2: 200
44
unit: km
55
distance: 12

extraTypes/JsEngine.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// js engine 0.0.7 types
2+
13
declare module 'jsEngine/ArgumentManager' {
24
import { type CachedMetadata, type TFile } from 'obsidian';
35
export interface ExecutionContext {
@@ -570,7 +572,12 @@ declare module 'jsEngine/JsMDRC' {
570572
content: string;
571573
ctx: MarkdownPostProcessorContext;
572574
jsExecution: JsExecution | undefined;
573-
constructor(containerEl: HTMLElement, plugin: JsEnginePlugin, content: string, ctx: MarkdownPostProcessorContext);
575+
constructor(
576+
containerEl: HTMLElement,
577+
plugin: JsEnginePlugin,
578+
content: string,
579+
ctx: MarkdownPostProcessorContext,
580+
);
574581
getExecutionFile(): TFile | undefined;
575582
buildExecutionContext(): ExecutionContext;
576583
tryRun(context: ExecutionContext): Promise<JsExecution>;

src/api/API.ts

Lines changed: 107 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ import { Signal } from '../utils/Signal';
1818
import { type BindTargetScope } from '../metadata/BindTargetScope';
1919
import { MetaBindTable } from '../metaBindTable/MetaBindTable';
2020
import { InputFieldFactory } from '../inputFields/InputFieldFactory';
21-
import { type JsViewFieldDeclaration, type UnvalidatedViewFieldDeclaration, type ViewFieldDeclaration } from '../parsers/viewFieldParser/ViewFieldDeclaration';
21+
import {
22+
type JsViewFieldDeclaration,
23+
type UnvalidatedViewFieldDeclaration,
24+
type ViewFieldDeclaration,
25+
} from '../parsers/viewFieldParser/ViewFieldDeclaration';
2226
import { ViewFieldFactory } from '../viewFields/ViewFieldFactory';
2327
import { getUUID } from '../utils/Utils';
2428

2529
export class API implements IAPI {
2630
public plugin: MetaBindPlugin;
2731
public readonly inputField: InputFieldAPI;
2832

29-
// public inputFieldParser: InputFieldDeclarationParser;
3033
public readonly inputFieldParser: InputFieldDeclarationParser;
3134
public readonly viewFieldParser: ViewFieldDeclarationParser;
3235
public readonly bindTargetParser: BindTargetParser;
@@ -47,32 +50,54 @@ export class API implements IAPI {
4750
this.viewFieldFactory = new ViewFieldFactory(this.plugin);
4851
}
4952

53+
/**
54+
* Creates an input field from an unvalidated declaration.
55+
*
56+
* @param unvalidatedDeclaration the unvalidated declaration
57+
* @param renderType whether to render the input field inline or as a block
58+
* @param filePath the file path that the input field is in or an empty string if it is not in a file
59+
* @param containerEl the container to mount the input field to
60+
* @param component component for lifecycle management
61+
* @param scope optional bind target scope
62+
*/
5063
public createInputField(
5164
unvalidatedDeclaration: UnvalidatedInputFieldDeclaration,
5265
renderType: RenderChildType,
5366
filePath: string,
5467
containerEl: HTMLElement,
5568
component: Component | MarkdownPostProcessorContext,
69+
scope?: BindTargetScope | undefined,
5670
): InputFieldMDRC | ExcludedMDRC {
5771
if (this.plugin.isFilePathExcluded(filePath)) {
5872
return this.createExcludedField(containerEl, filePath, component);
5973
}
6074

61-
const declaration = this.inputFieldParser.validateDeclaration(unvalidatedDeclaration);
75+
const declaration = this.inputFieldParser.validateDeclaration(unvalidatedDeclaration, scope);
6276

6377
const inputField = new InputFieldMDRC(containerEl, renderType, declaration, this.plugin, filePath, getUUID());
6478
component.addChild(inputField);
6579

6680
return inputField;
6781
}
6882

83+
/**
84+
* Creates an input field from a string.
85+
* This will parse the string and create the input field.
86+
*
87+
* @param fullDeclaration the string
88+
* @param renderType whether to render the input field inline or as a block
89+
* @param filePath the file path that the input field is in or an empty string if it is not in a file
90+
* @param containerEl the container to mount the input field to
91+
* @param component component for lifecycle management
92+
* @param scope optional bind target scope
93+
*/
6994
public createInputFieldFromString(
7095
fullDeclaration: string,
7196
renderType: RenderChildType,
7297
filePath: string,
7398
containerEl: HTMLElement,
7499
component: Component | MarkdownPostProcessorContext,
75-
scope: BindTargetScope | undefined,
100+
scope?: BindTargetScope | undefined,
76101
): InputFieldMDRC | ExcludedMDRC {
77102
if (this.plugin.isFilePathExcluded(filePath)) {
78103
return this.createExcludedField(containerEl, filePath, component);
@@ -86,25 +111,47 @@ export class API implements IAPI {
86111
return inputField;
87112
}
88113

114+
/**
115+
* Creates a view field from a string.
116+
* This will parse the string and create the view field.
117+
*
118+
* @param fullDeclaration the string
119+
* @param renderType whether to render the view field inline or as a block
120+
* @param filePath the file path that the view field is in or an empty string if it is not in a file
121+
* @param containerEl the container to mount the view field to
122+
* @param component component for lifecycle management
123+
* @param scope optional bind target scope
124+
*/
89125
public createViewFieldFromString(
90126
fullDeclaration: string,
91127
renderType: RenderChildType,
92128
filePath: string,
93129
containerEl: HTMLElement,
94130
component: Component | MarkdownPostProcessorContext,
131+
scope?: BindTargetScope | undefined,
95132
): ViewFieldMDRC | ExcludedMDRC {
96133
if (this.plugin.isFilePathExcluded(filePath)) {
97134
return this.createExcludedField(containerEl, filePath, component);
98135
}
99136

100-
const declaration: ViewFieldDeclaration = this.viewFieldParser.parseString(fullDeclaration);
137+
const declaration: ViewFieldDeclaration = this.viewFieldParser.parseString(fullDeclaration, scope);
101138

102139
const viewField = new ViewFieldMDRC(containerEl, renderType, declaration, this.plugin, filePath, getUUID());
103140
component.addChild(viewField);
104141

105142
return viewField;
106143
}
107144

145+
/**
146+
* Creates a js view field from a string.
147+
* This will parse the string and create the js view field.
148+
*
149+
* @param fullDeclaration the string containing the header and the code
150+
* @param renderType whether to render the js view field inline or as a block
151+
* @param filePath the file path that the js view field is in or an empty string if it is not in a file
152+
* @param containerEl the container to mount the js view field to
153+
* @param component component for lifecycle management
154+
*/
108155
public createJsViewFieldFromString(
109156
fullDeclaration: string,
110157
renderType: RenderChildType,
@@ -124,7 +171,18 @@ export class API implements IAPI {
124171
return viewField;
125172
}
126173

127-
public createExcludedField(containerEl: HTMLElement, filePath: string, component: Component | MarkdownPostProcessorContext): ExcludedMDRC {
174+
/**
175+
* An excluded field will render a message that the file was excluded in the plugin settings.
176+
*
177+
* @param containerEl the container to mount the field to
178+
* @param filePath the file path that the field should be in or an empty string if it is not in a file
179+
* @param component component for lifecycle management
180+
*/
181+
public createExcludedField(
182+
containerEl: HTMLElement,
183+
filePath: string,
184+
component: Component | MarkdownPostProcessorContext,
185+
): ExcludedMDRC {
128186
const excludedField = new ExcludedMDRC(containerEl, RenderChildType.INLINE, this.plugin, filePath, getUUID());
129187
component.addChild(excludedField);
130188

@@ -138,26 +196,48 @@ export class API implements IAPI {
138196
/**
139197
* Registers a signal to a metadata property and returns a callback to unregister.
140198
*
141-
* @param signal
142-
* @param filePath
143-
* @param metadataPath
144-
* @param listenToChildren
199+
* @param signal a signal that will be updated with new metadata
200+
* @param filePath the file path of the metadata to listen to
201+
* @param metadataPath the object path of the metadata to listen to (e.g. ['task', '0', 'completed'])
202+
* @param listenToChildren whether to listen to updates of the children of the metadata path, useful when listening to arrays or objects
203+
* @param onDelete callback that will be called when the metadata becomes unavailable
145204
*/
146-
public listenToMetadata(signal: Signal<unknown>, filePath: string, metadataPath: string[], listenToChildren: boolean = false): () => void {
205+
public listenToMetadata(
206+
signal: Signal<unknown>,
207+
filePath: string,
208+
metadataPath: string[],
209+
listenToChildren: boolean = false,
210+
onDelete?: () => void,
211+
): () => void {
147212
const uuid = getUUID();
148213

149-
const subscription = this.plugin.metadataManager.subscribe(uuid, signal, {
150-
filePath: filePath,
151-
metadataPath: metadataPath,
152-
listenToChildren: listenToChildren,
153-
boundToLocalScope: false,
154-
});
214+
const subscription = this.plugin.metadataManager.subscribe(
215+
uuid,
216+
signal,
217+
{
218+
filePath: filePath,
219+
metadataPath: metadataPath,
220+
listenToChildren: listenToChildren,
221+
boundToLocalScope: false,
222+
},
223+
onDelete ?? ((): void => {}),
224+
);
155225

156226
return () => {
157227
subscription.unsubscribe();
158228
};
159229
}
160230

231+
/**
232+
* Creates an editable table.
233+
*
234+
* @param containerEl the container to mount the table to
235+
* @param filePath the file path that the table is in or an empty string if it is not in a file
236+
* @param component component for lifecycle management
237+
* @param bindTarget the bind target of the table, it will be available to all input fields in the columns of the table as local scope
238+
* @param tableHead the head of the table
239+
* @param columns the columns of the table
240+
*/
161241
public createTable(
162242
containerEl: HTMLElement,
163243
filePath: string,
@@ -166,7 +246,16 @@ export class API implements IAPI {
166246
tableHead: string[],
167247
columns: (UnvalidatedInputFieldDeclaration | UnvalidatedViewFieldDeclaration)[],
168248
): MetaBindTable {
169-
const table = new MetaBindTable(containerEl, RenderChildType.INLINE, this.plugin, filePath, getUUID(), bindTarget, tableHead, columns);
249+
const table = new MetaBindTable(
250+
containerEl,
251+
RenderChildType.INLINE,
252+
this.plugin,
253+
filePath,
254+
getUUID(),
255+
bindTarget,
256+
tableHead,
257+
columns,
258+
);
170259
component.addChild(table);
171260

172261
return table;

src/api/IAPI.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@ import { type InputFieldAPI } from './InputFieldAPI';
66

77
export interface IAPI {
88
readonly plugin: IPlugin;
9+
/*
10+
* The API for creating and modifying input field declarations.
11+
*/
912
readonly inputField: InputFieldAPI;
1013

14+
/**
15+
* Parser for input field declarations.
16+
*/
1117
readonly inputFieldParser: InputFieldDeclarationParser;
18+
/**
19+
* Parser for view field declarations.
20+
*/
1221
readonly viewFieldParser: ViewFieldDeclarationParser;
22+
/**
23+
* Parser for bind target declarations.
24+
*/
1325
readonly bindTargetParser: BindTargetParser;
1426
}

0 commit comments

Comments
 (0)