Skip to content

Commit 48ab3fb

Browse files
committed
udpate comments; fix naming
1 parent 3ca70a1 commit 48ab3fb

File tree

4 files changed

+109
-40
lines changed

4 files changed

+109
-40
lines changed

packages/core/src/api/API.ts

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import {
5656
type FieldOptionMap,
5757
FieldType,
5858
type InlineFieldType,
59-
type APIConfigs,
59+
type InputFieldOptions,
6060
isFieldTypeAllowedInline,
6161
type JsViewFieldOptions,
6262
NotePosition,
@@ -120,10 +120,10 @@ export abstract class API<Plugin extends IPlugin> {
120120
/**
121121
* Creates a field of a given type.
122122
*
123-
* @param type
124-
* @param filePath
123+
* @param type the type of the field
124+
* @param filePath the file path that the field is located in, or an empty string if it is not in a file
125125
* @param options
126-
* @param honorExcludedSetting
126+
* @param honorExcludedSetting whether to honor the excluded folders settings for this field
127127
*/
128128
public createField<Type extends FieldType>(
129129
type: Type,
@@ -178,12 +178,12 @@ export abstract class API<Plugin extends IPlugin> {
178178
* Creates an inline field from a string.
179179
* Will throw an error if the string is not a valid declaration.
180180
*
181-
* @param fieldString
182-
* @param filePath
183-
* @param scope
184-
* @param renderChildType
185-
* @param position
186-
* @param honorExcludedSetting
181+
* @param fieldString the declaration string of the field
182+
* @param filePath the file path that the field is located in
183+
* @param scope optional bind target scope
184+
* @param renderChildType the render child type, default INLINE
185+
* @param position an optional note position
186+
* @param honorExcludedSetting whether to honor the excluded folders settings for this field
187187
*/
188188
public createInlineFieldFromString(
189189
fieldString: string,
@@ -234,13 +234,13 @@ export abstract class API<Plugin extends IPlugin> {
234234
* Creates an inline field of a given type and string.
235235
* Will throw an error if the string is not a valid inline field type.
236236
*
237-
* @param type
238-
* @param filePath
239-
* @param declaration
240-
* @param scope
241-
* @param renderChildType
242-
* @param position
243-
* @param honorExcludedSetting
237+
* @param type the field type
238+
* @param declaration the declaration string of the field
239+
* @param filePath the file path that the field is located in
240+
* @param scope optional bind target scope
241+
* @param renderChildType the render child type, default INLINE
242+
* @param position an optional note position
243+
* @param honorExcludedSetting whether to honor the excluded folders settings for this field
244244
*/
245245
public createInlineFieldOfTypeFromString(
246246
type: InlineFieldType,
@@ -307,7 +307,13 @@ export abstract class API<Plugin extends IPlugin> {
307307
});
308308
}
309309

310-
public createInputFieldMountable(filePath: string, options: APIConfigs): InputFieldMountable {
310+
/**
311+
* Creates an input field from an options object.
312+
*
313+
* @param filePath the file path that the field is located in or an empty string
314+
* @param options
315+
*/
316+
public createInputFieldMountable(filePath: string, options: InputFieldOptions): InputFieldMountable {
311317
validate(
312318
z.object({
313319
filePath: V_FilePath,
@@ -335,6 +341,12 @@ export abstract class API<Plugin extends IPlugin> {
335341
return new InputFieldMountable(this.plugin, uuid, filePath, options.renderChildType, declaration);
336342
}
337343

344+
/**
345+
* Creates a view field from an options object.
346+
*
347+
* @param filePath the file path that the field is located in or an empty string
348+
* @param options
349+
*/
338350
public createViewFieldMountable(filePath: string, options: ViewFieldOptions): ViewFieldMountable {
339351
validate(
340352
z.object({
@@ -363,6 +375,12 @@ export abstract class API<Plugin extends IPlugin> {
363375
return new ViewFieldMountable(this.plugin, uuid, filePath, options.renderChildType, declaration);
364376
}
365377

378+
/**
379+
* Creates a JS view field from an options object.
380+
*
381+
* @param filePath the file path that the field is located in or an empty string
382+
* @param options
383+
*/
366384
public createJsViewFieldMountable(filePath: string, options: JsViewFieldOptions): JsViewFieldMountable {
367385
validate(
368386
z.object({
@@ -387,6 +405,12 @@ export abstract class API<Plugin extends IPlugin> {
387405
return new JsViewFieldMountable(this.plugin, uuid, filePath, declaration);
388406
}
389407

408+
/**
409+
* Creates a table from an options object.
410+
*
411+
* @param filePath the file path that the field is located in or an empty string
412+
* @param options
413+
*/
390414
public createTableMountable(filePath: string, options: TableOptions): TableMountable {
391415
validate(
392416
z.object({
@@ -404,6 +428,12 @@ export abstract class API<Plugin extends IPlugin> {
404428
return new TableMountable(this.plugin, uuid, filePath, options.bindTarget, options.tableHead, options.columns);
405429
}
406430

431+
/**
432+
* Creates a button group from an options object.
433+
*
434+
* @param filePath the file path that the field is located in or an empty string
435+
* @param options
436+
*/
407437
public createButtonGroupMountable(filePath: string, options: ButtonGroupOptions): ButtonGroupMountable {
408438
validate(
409439
z.object({
@@ -435,6 +465,12 @@ export abstract class API<Plugin extends IPlugin> {
435465
);
436466
}
437467

468+
/**
469+
* Creates a button from an options object.
470+
*
471+
* @param filePath the file path that the field is located in or an empty string
472+
* @param options
473+
*/
438474
public createButtonMountable(filePath: string, options: ButtonOptions): ButtonMountable {
439475
validate(
440476
z.object({
@@ -459,6 +495,12 @@ export abstract class API<Plugin extends IPlugin> {
459495
return new ButtonMountable(this.plugin, uuid, filePath, declaration, options.position, options.isPreview);
460496
}
461497

498+
/**
499+
* Creates a meta bind embed fields from an options object.
500+
*
501+
* @param filePath the file path that the field is located in or an empty string
502+
* @param options
503+
*/
462504
public createEmbedMountable(filePath: string, options: EmbedOptions): EmbedMountable {
463505
validate(
464506
z.object({
@@ -475,6 +517,11 @@ export abstract class API<Plugin extends IPlugin> {
475517
return new EmbedMountable(this.plugin, uuid, filePath, options.depth, options.content);
476518
}
477519

520+
/**
521+
* Creates an excluded notification mountable for the excluded folders setting.
522+
*
523+
* @param filePath the file path that the field is located in or an empty string
524+
*/
478525
public createExcludedMountable(filePath: string): ExcludedMountable {
479526
validate(
480527
z.object({
@@ -490,7 +537,7 @@ export abstract class API<Plugin extends IPlugin> {
490537
}
491538

492539
/**
493-
* Gets the prefix of a given widget type. (e.g. INPUT or VIEW)
540+
* Gets the prefix of a given widget type. (e.g. INPUT or VIEW).
494541
*
495542
* @param fieldType
496543
*/
@@ -523,7 +570,7 @@ export abstract class API<Plugin extends IPlugin> {
523570
* Checks if a string is a declaration of a given widget type.
524571
*
525572
* @param fieldType
526-
* @param str
573+
* @param str the declaration string
527574
*/
528575
public isInlineFieldDeclaration(fieldType: FieldType, str: string): boolean {
529576
validate(
@@ -545,9 +592,8 @@ export abstract class API<Plugin extends IPlugin> {
545592

546593
/**
547594
* Checks if a string is any declaration and if yes returns the widget type.
548-
* This does not use {@link isInlineFieldDeclaration} because of performance reasons.
549595
*
550-
* @param str
596+
* @param str the declaration string
551597
*/
552598
public isInlineFieldDeclarationAndGetType(str: string): InlineFieldType | undefined {
553599
validate(
@@ -576,6 +622,11 @@ export abstract class API<Plugin extends IPlugin> {
576622
return undefined;
577623
}
578624

625+
/**
626+
* Creates a signal.
627+
*
628+
* @param value
629+
*/
579630
public createSignal<T>(value: T): Signal<T> {
580631
return new Signal<T>(value);
581632
}
@@ -749,6 +800,12 @@ export abstract class API<Plugin extends IPlugin> {
749800
});
750801
}
751802

803+
/**
804+
* Creates a note position from a line start and line end number.
805+
*
806+
* @param lineStart
807+
* @param lineEnd
808+
*/
752809
public createNotePosition(lineStart: number, lineEnd: number): NotePosition {
753810
validate(
754811
z.object({

packages/core/src/api/Validators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
type ButtonOptions,
3838
type EmbedOptions,
3939
FieldType,
40-
type APIConfigs,
40+
type InputFieldOptions,
4141
type JsViewFieldOptions,
4242
NotePosition,
4343
RenderChildType,
@@ -195,7 +195,7 @@ export const V_SimpleInlineButtonDeclaration = schemaForType<SimpleButtonGroupDe
195195
}),
196196
);
197197

198-
export const V_InputFieldOptions = schemaForType<APIConfigs>()(
198+
export const V_InputFieldOptions = schemaForType<InputFieldOptions>()(
199199
z.object({
200200
renderChildType: V_RenderChildType,
201201
declaration: z.union([z.string(), V_SimpleInputFieldDeclaration]),

packages/core/src/config/APIConfigs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export enum FieldType {
2525
EXCLUDED = 'EXCLUDED',
2626
}
2727

28-
export interface APIConfigs {
28+
export interface InputFieldOptions {
2929
renderChildType: RenderChildType;
3030
declaration: SimpleInputFieldDeclaration | string;
3131
scope?: BindTargetScope | undefined;
@@ -82,7 +82,7 @@ export interface EmbedOptions {
8282
}
8383

8484
export interface FieldOptionMap {
85-
[FieldType.INPUT]: APIConfigs;
85+
[FieldType.INPUT]: InputFieldOptions;
8686
[FieldType.VIEW]: ViewFieldOptions;
8787
[FieldType.JS_VIEW]: JsViewFieldOptions;
8888
[FieldType.TABLE]: TableOptions;

packages/obsidian/src/ObsidianAPI.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import { Signal } from 'packages/core/src/utils/Signal';
1313
import { getJsEnginePluginAPI } from 'packages/obsidian/src/ObsUtils';
1414
import { type ReactiveComponent } from 'jsEngine/api/reactive/ReactiveComponent';
1515
import { type Mountable } from 'packages/core/src/utils/Mountable';
16-
import { type FieldType, isFieldTypeAllowedInline } from 'packages/core/src/config/APIConfigs';
16+
import { type InlineFieldType, isFieldTypeAllowedInline } from 'packages/core/src/config/APIConfigs';
1717

1818
/**
19-
* Either {@link MarkdownPostProcessorContext} or {@link Component}.
19+
* Either a [Component](https://docs.obsidian.md/Reference/TypeScript+API/Component) or a [MarkdownPostProcessorContext](https://docs.obsidian.md/Reference/TypeScript+API/MarkdownPostProcessorContext).
2020
*/
2121
export interface ComponentLike {
2222
addChild(child: Component): void;
@@ -38,48 +38,60 @@ export class ObsidianAPI extends API<MetaBindPlugin> {
3838
super(plugin);
3939
}
4040

41-
public wrapInMDRC(field: Mountable, containerEl: HTMLElement, component: ComponentLike): MountableMDRC {
41+
/**
42+
* Wraps any mountable in a [MarkdownRenderChild](https://docs.obsidian.md/Reference/TypeScript+API/MarkdownRenderChild)
43+
* and adds it as a child to the passed in {@link ComponentLike}.
44+
*
45+
* A {@link ComponentLike} is either a [Component](https://docs.obsidian.md/Reference/TypeScript+API/Component) or a [MarkdownPostProcessorContext](https://docs.obsidian.md/Reference/TypeScript+API/MarkdownPostProcessorContext)
46+
*
47+
* @param mountable the mountable to wrap in a [MarkdownRenderChild](https://docs.obsidian.md/Reference/TypeScript+API/MarkdownRenderChild)
48+
* @param containerEl the element to mount the [MarkdownRenderChild](https://docs.obsidian.md/Reference/TypeScript+API/MarkdownRenderChild) to
49+
* @param component the {@link ComponentLike} to register the [MarkdownRenderChild](https://docs.obsidian.md/Reference/TypeScript+API/MarkdownRenderChild) to
50+
*/
51+
public wrapInMDRC(mountable: Mountable, containerEl: HTMLElement, component: ComponentLike): MountableMDRC {
4252
validate(
4353
z.object({
4454
field: V_Mountable,
4555
containerEl: V_HTMLElement,
4656
component: V_ComponentLike,
4757
}),
4858
{
49-
field: field,
59+
field: mountable,
5060
containerEl: containerEl,
5161
component: component,
5262
},
5363
);
5464

55-
const mdrc = new MountableMDRC(this.plugin, field, containerEl);
65+
const mdrc = new MountableMDRC(this.plugin, mountable, containerEl);
5666
component.addChild(mdrc);
5767

5868
return mdrc;
5969
}
6070

6171
/**
62-
* Creates a MDRC widget from a given widget type.
72+
* Creates a CM6 widget from a given widget type.
73+
*
74+
* This is only useful fur use in a CodeMirror plugin.
6375
*
64-
* @param mdrcType
76+
* @param inlineFieldType
6577
* @param content
6678
* @param filePath
6779
* @param component
6880
*/
6981
public constructMDRCWidget(
70-
mdrcType: FieldType,
82+
inlineFieldType: InlineFieldType,
7183
content: string,
7284
filePath: string,
7385
component: Component,
7486
): MarkdownRenderChildWidget {
75-
if (isFieldTypeAllowedInline(mdrcType)) {
76-
return new MarkdownRenderChildWidget(mdrcType, content, filePath, component, this.plugin);
87+
if (isFieldTypeAllowedInline(inlineFieldType)) {
88+
return new MarkdownRenderChildWidget(inlineFieldType, content, filePath, component, this.plugin);
7789
}
7890

7991
throw new MetaBindInternalError({
8092
errorLevel: ErrorLevel.CRITICAL,
8193
effect: 'failed to construct mdrc',
82-
cause: `Invalid inline mdrc type "${mdrcType}"`,
94+
cause: `Invalid inline field type "${inlineFieldType}"`,
8395
});
8496
}
8597

@@ -88,9 +100,9 @@ export class ObsidianAPI extends API<MetaBindPlugin> {
88100
*
89101
* This requires JS Engine to be installed and enabled!
90102
*
91-
* @param bindTargets
92-
* @param lifecycleHook
93-
* @param callback
103+
* @param bindTargets the bind targets to listen to
104+
* @param lifecycleHook a [Component](https://docs.obsidian.md/Reference/TypeScript+API/Component)
105+
* @param callback the callback to call with all the values of the bind targets when one of them changes. What ever this callback returns will be rendered by the reactive component.
94106
*/
95107
public reactiveMetadata(
96108
bindTargets: BindTargetDeclaration[],

0 commit comments

Comments
 (0)