|
1 | 1 | import { CachedMetadata, MarkdownPostProcessorContext, Plugin, TFile } from 'obsidian'; |
2 | 2 | import { DEFAULT_SETTINGS, MetaBindPluginSettings, MetaBindSettingTab } from './settings/Settings'; |
3 | 3 | import { InputFieldMarkdownRenderChild, InputFieldMarkdownRenderChildType } from './InputFieldMarkdownRenderChild'; |
4 | | -import { getFileName, isPath, removeFileEnding } from './utils/Utils'; |
| 4 | +import { getFileName, isPath, isTruthy, removeFileEnding } from './utils/Utils'; |
5 | 5 | import { Logger } from './utils/Logger'; |
6 | 6 | import { DateParser } from './parsers/DateParser'; |
7 | | -import { InputFieldArgumentType, InputFieldDeclaration, InputFieldDeclarationParser } from './parsers/InputFieldDeclarationParser'; |
| 7 | +import { InputFieldArgumentType, InputFieldDeclaration, InputFieldDeclarationParser, InputFieldType } from './parsers/InputFieldDeclarationParser'; |
8 | 8 | import { getFrontmatterOfTFile } from '@opd-libs/opd-metadata-lib/lib/API'; |
9 | 9 | import { traverseObject } from '@opd-libs/opd-metadata-lib/lib/Utils'; |
10 | 10 |
|
@@ -107,20 +107,34 @@ export default class MetaBindPlugin extends Plugin { |
107 | 107 | /** |
108 | 108 | * Helper method to build a declaration from some initial data or a string. |
109 | 109 | * |
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. |
114 | 118 | */ |
115 | 119 | 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 { |
120 | 127 | if (typeof base === "string") { |
121 | 128 | return InputFieldDeclarationParser.parseString(base); |
122 | 129 | } 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); |
124 | 138 | } |
125 | 139 | } |
126 | 140 |
|
|
0 commit comments