Skip to content

Commit 054210a

Browse files
committed
added more functionality
1 parent c7b6552 commit 054210a

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/main.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { CachedMetadata, MarkdownPostProcessorContext, Plugin, TFile } from 'obsidian';
22
import { DEFAULT_SETTINGS, MetaBindPluginSettings, MetaBindSettingTab } from './settings/Settings';
33
import { InputFieldMarkdownRenderChild, InputFieldMarkdownRenderChildType } from './InputFieldMarkdownRenderChild';
4-
import { getFileName, isPath, removeFileEnding } from './utils/Utils';
4+
import { getFileName, isPath, isTruthy, removeFileEnding } from './utils/Utils';
55
import { Logger } from './utils/Logger';
66
import { DateParser } from './parsers/DateParser';
7-
import { InputFieldArgumentType, InputFieldDeclaration, InputFieldDeclarationParser } from './parsers/InputFieldDeclarationParser';
7+
import { InputFieldArgumentType, InputFieldDeclaration, InputFieldDeclarationParser, InputFieldType } from './parsers/InputFieldDeclarationParser';
88
import { getFrontmatterOfTFile } from '@opd-libs/opd-metadata-lib/lib/API';
99
import { traverseObject } from '@opd-libs/opd-metadata-lib/lib/Utils';
1010

@@ -107,20 +107,34 @@ export default class MetaBindPlugin extends Plugin {
107107
/**
108108
* Helper method to build a declaration from some initial data or a string.
109109
*
110-
* @param {string | InputFieldDeclaration} base The base declaration data or a string to parse for it
111-
* @param {Record<InputFieldArgumentType, string> | {} | undefined | null} args The arguments, indexed by name.
112-
* @param { string | undefined | null} templateName (optional) A template to use.
113-
* @returns
110+
* @param {string | InputFieldDeclaration | {}} base The base declaration data or a string to parse for it. Can also be an empty object with the other arguments provided to fill it.
111+
* @param {Record<InputFieldArgumentType, string> | {} | undefined } args (Optional) The arguments, indexed by name.
112+
* @param {InputFieldType | undefined} inputFieldType (Optional) The input field type if not provided in the base object.
113+
* @param {boolean | undefined} isBound (Optional) If the field should try to be bound to a bindTarget.
114+
* @param {Record<InputFieldArgumentType, string> | {} | undefined} args (Optional) The bind target of the field.
115+
* @param { string | undefined} templateName (Optional) A template to use.
116+
*
117+
* @returns A constructed InputFieldDeclaration.
114118
*/
115119
buildDeclaration(
116-
base: string | InputFieldDeclaration,
117-
args?: Record<InputFieldArgumentType, string> | {} | undefined | null,
118-
templateName?: string | undefined | null
119-
) {
120+
base: string | InputFieldDeclaration | {},
121+
args?: Record<InputFieldArgumentType, string> | {} ,
122+
inputFieldType?: InputFieldType,
123+
isBound?: boolean,
124+
bindTarget?: string,
125+
templateName?: string
126+
) : InputFieldDeclaration {
120127
if (typeof base === "string") {
121128
return InputFieldDeclarationParser.parseString(base);
122129
} else {
123-
return InputFieldDeclarationParser.parseDeclaration(base, args, templateName);
130+
var fullBase = base as InputFieldDeclaration;
131+
fullBase = {
132+
...fullBase,
133+
inputFieldType: inputFieldType ?? fullBase.inputFieldType ?? InputFieldType.INVALID,
134+
isBound: isBound ?? fullBase.isBound ?? false ?? isTruthy(bindTarget),
135+
bindTarget: bindTarget ?? fullBase.bindTarget ?? undefined
136+
}
137+
return InputFieldDeclarationParser.parseDeclaration(fullBase, args, templateName);
124138
}
125139
}
126140

0 commit comments

Comments
 (0)