Skip to content

Commit a27d75b

Browse files
committed
renaming things, update table API
1 parent be0a8a7 commit a27d75b

File tree

63 files changed

+484
-472
lines changed

Some content is hidden

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

63 files changed

+484
-472
lines changed

.prettierrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"printWidth": 120,
55
"useTabs": true,
6+
"tabWidth": 4,
67
"semi": true,
78
"singleQuote": true,
89
"arrowParens": "avoid",

bun.lockb

16.1 KB
Binary file not shown.

exampleVault/Meta Bind API.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,28 @@ const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
1212

1313
const options = ['a', 'b', 'c'];
1414

15-
// first, create an empty declaration
16-
let declaration = mb.inputField.createInputFieldDeclaration();
17-
// set the input field type
18-
declaration = mb.inputField.setType(declaration, 'select');
19-
// bind the input field to 'select'
20-
declaration = mb.inputField.setBindTargetMetadataField(declaration, 'select');
21-
22-
for (const option of options) {
23-
// add all the options
24-
declaration = mb.inputField.addArgument(declaration, {name: 'option', value: [option]});
25-
}
26-
27-
// create the input field in the container and pass in the component for life cycle management (container and component are globals exposed by js engine)
28-
mb.createInputField(declaration, 'block', context.file.path, container, component);
15+
const arguments = options.map(x => ({
16+
name: 'option',
17+
value: [x],
18+
}));
19+
20+
arguments.push({
21+
name: 'title',
22+
value: ['I was created using JS Engine and the Meta Bind API'],
23+
});
24+
25+
const bindTarget = mb.parseBindTarget('select', context.file.path);
26+
27+
const mountable = mb.createInputFieldMountable(context.file.path, {
28+
renderChildType: 'block',
29+
declaration: {
30+
inputFieldType: 'select',
31+
bindTarget: bindTarget,
32+
arguments: arguments,
33+
},
34+
});
35+
36+
mb.wrapInMDRC(mountable, container, component);
2937
```
3038

3139
**Resulting Input Field**
@@ -46,7 +54,7 @@ arguments.push({
4654
4755
const bindTarget = mb.parseBindTarget('select', context.file.path);
4856
49-
const base = mb.createInputFieldBase(context.file.path, {
57+
const mountable = mb.createInputFieldMountable(context.file.path, {
5058
renderChildType: 'block',
5159
declaration: {
5260
inputFieldType: 'select',
@@ -55,5 +63,5 @@ const base = mb.createInputFieldBase(context.file.path, {
5563
},
5664
});
5765
58-
mb.wrapInMDRC(base, container, component);
59-
```
66+
mb.wrapInMDRC(mountable, container, component);
67+
```

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@
2828
"author": "Moritz Jung",
2929
"license": "GPL-3.0",
3030
"devDependencies": {
31-
"@happy-dom/global-registrator": "^13.3.8",
32-
"@tsconfig/svelte": "^5.0.2",
33-
"@types/bun": "^1.0.5",
34-
"@typescript-eslint/eslint-plugin": "^7.0.1",
35-
"@typescript-eslint/parser": "^7.0.1",
31+
"@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",
3636
"builtin-modules": "^3.3.0",
3737
"elysia": "^0.8.17",
38-
"esbuild": "^0.20.0",
38+
"esbuild": "^0.20.2",
3939
"esbuild-plugin-copy-watch": "^2.1.0",
4040
"esbuild-svelte": "^0.8.0",
41-
"eslint": "^8.56.0",
41+
"eslint": "^8.57.0",
4242
"eslint-plugin-import": "^2.29.1",
4343
"eslint-plugin-isaacscript": "^3.12.2",
4444
"eslint-plugin-no-relative-import-paths": "^1.5.3",
4545
"eslint-plugin-only-warn": "^1.1.0",
4646
"prettier": "^3.2.5",
47-
"prettier-plugin-svelte": "^3.2.1",
47+
"prettier-plugin-svelte": "^3.2.2",
4848
"string-argv": "^0.3.2",
49-
"svelte-check": "^3.6.4",
49+
"svelte-check": "^3.6.8",
5050
"svelte-preprocess": "^5.1.3",
5151
"tslib": "2.6.2",
52-
"typescript": "^5.3.3",
52+
"typescript": "^5.4.3",
5353
"yaml": "^2.4.1"
5454
},
5555
"dependencies": {

packages/core/src/api/API.ts

Lines changed: 73 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,27 @@ import {
1212
type JsViewFieldOptions,
1313
type NotePosition,
1414
RenderChildType,
15+
type TableFieldOptions,
1516
type ViewFieldOptions,
1617
} from 'packages/core/src/config/FieldConfigs';
17-
import { type FieldBase } from 'packages/core/src/fields/FieldBase';
18+
import { type FieldMountable } from 'packages/core/src/fields/FieldMountable';
1819
import { ButtonActionRunner } from 'packages/core/src/fields/button/ButtonActionRunner';
19-
import { ButtonBase } from 'packages/core/src/fields/button/ButtonBase';
20+
import { ButtonMountable } from 'packages/core/src/fields/button/ButtonMountable';
2021
import { ButtonManager } from 'packages/core/src/fields/button/ButtonManager';
21-
import { ButtonGroupBase } from 'packages/core/src/fields/button/ButtonGroupBase';
22-
import { InputFieldBase } from 'packages/core/src/fields/inputFields/InputFieldBase';
22+
import { ButtonGroupMountable } from 'packages/core/src/fields/button/ButtonGroupMountable';
23+
import { InputFieldMountable } from 'packages/core/src/fields/inputFields/InputFieldMountable';
2324
import { InputFieldFactory } from 'packages/core/src/fields/inputFields/InputFieldFactory';
24-
import { JsViewField } from 'packages/core/src/fields/viewFields/JsViewField';
25-
import { ViewFieldBase } from 'packages/core/src/fields/viewFields/ViewFieldBase';
25+
import { JsViewFieldMountable } from 'packages/core/src/fields/viewFields/JsViewFieldMountable';
26+
import { ViewFieldMountable } from 'packages/core/src/fields/viewFields/ViewFieldMountable';
2627
import { ViewFieldFactory } from 'packages/core/src/fields/viewFields/ViewFieldFactory';
2728
import type { BindTargetScope } from 'packages/core/src/metadata/BindTargetScope';
2829
import { BindTargetParser } from 'packages/core/src/parsers/bindTargetParser/BindTargetParser';
2930
import { InputFieldParser } from 'packages/core/src/parsers/inputFieldParser/InputFieldParser';
3031
import { ViewFieldParser } from 'packages/core/src/parsers/viewFieldParser/ViewFieldParser';
3132
import { expectType, getUUID } from 'packages/core/src/utils/Utils';
3233
import { ErrorLevel, MetaBindInternalError } from 'packages/core/src/utils/errors/MetaBindErrors';
33-
import { EmbedBase } from 'packages/core/src/fields/embed/EmbedBase';
34-
import { ExcludedBase } from 'packages/core/src/fields/excluded/ExcludedBase';
34+
import { EmbedMountable } from 'packages/core/src/fields/embed/EmbedMountable';
35+
import { ExcludedMountable } from 'packages/core/src/fields/excluded/ExcludedMountable';
3536
import { type InputFieldDeclaration } from 'packages/core/src/parsers/inputFieldParser/InputFieldDeclaration';
3637
import {
3738
type JsViewFieldDeclaration,
@@ -57,10 +58,12 @@ import {
5758
V_InputFieldOptions,
5859
V_JsViewFieldOptions,
5960
V_RenderChildType,
61+
V_TableFieldOptions,
6062
V_ViewFieldOptions,
6163
} from 'packages/core/src/api/Validators';
6264
import { validate } from 'packages/core/src/utils/ZodUtils';
6365
import { z } from 'zod';
66+
import { TableMountable } from 'packages/core/src/fields/metaBindTable/TableMountable';
6467

6568
export interface LifecycleHook {
6669
register(cb: () => void): void;
@@ -127,7 +130,7 @@ export abstract class API<Plugin extends IPlugin> {
127130
filePath: string,
128131
options: FieldOptionMap[Type],
129132
honorExcludedSetting: boolean = true,
130-
): FieldBase {
133+
): FieldMountable {
131134
validate(
132135
z.object({
133136
type: V_FieldType,
@@ -144,23 +147,25 @@ export abstract class API<Plugin extends IPlugin> {
144147
);
145148

146149
if (this.plugin.internal.isFilePathExcluded(filePath) && honorExcludedSetting) {
147-
return this.createExcludedBase(filePath);
150+
return this.createExcludedMountable(filePath);
148151
}
149152

150-
if (type === FieldType.INPUT_FIELD) {
151-
return this.createInputFieldBase(filePath, options as FieldOptionMap[FieldType.INPUT_FIELD]);
152-
} else if (type === FieldType.VIEW_FIELD) {
153-
return this.createViewFieldBase(filePath, options as FieldOptionMap[FieldType.VIEW_FIELD]);
154-
} else if (type === FieldType.JS_VIEW_FIELD) {
155-
return this.createJsViewFieldBase(filePath, options as FieldOptionMap[FieldType.JS_VIEW_FIELD]);
153+
if (type === FieldType.INPUT) {
154+
return this.createInputFieldMountable(filePath, options as FieldOptionMap[FieldType.INPUT]);
155+
} else if (type === FieldType.VIEW) {
156+
return this.createViewFieldMountable(filePath, options as FieldOptionMap[FieldType.VIEW]);
157+
} else if (type === FieldType.JS_VIEW) {
158+
return this.createJsViewFieldMountable(filePath, options as FieldOptionMap[FieldType.JS_VIEW]);
159+
} else if (type === FieldType.TABLE) {
160+
return this.createTableFieldMountable(filePath, options as FieldOptionMap[FieldType.TABLE]);
156161
} else if (type === FieldType.BUTTON_GROUP) {
157-
return this.createButtonGroupBase(filePath, options as FieldOptionMap[FieldType.BUTTON_GROUP]);
162+
return this.createButtonGroupMountable(filePath, options as FieldOptionMap[FieldType.BUTTON_GROUP]);
158163
} else if (type === FieldType.BUTTON) {
159-
return this.createButtonBase(filePath, options as FieldOptionMap[FieldType.BUTTON]);
164+
return this.createButtonMountable(filePath, options as FieldOptionMap[FieldType.BUTTON]);
160165
} else if (type === FieldType.EMBED) {
161-
return this.createEmbedBase(filePath, options as FieldOptionMap[FieldType.EMBED]);
166+
return this.createEmbedMountable(filePath, options as FieldOptionMap[FieldType.EMBED]);
162167
} else if (type === FieldType.EXCLUDED) {
163-
return this.createExcludedBase(filePath);
168+
return this.createExcludedMountable(filePath);
164169
}
165170

166171
expectType<never>(type);
@@ -187,7 +192,7 @@ export abstract class API<Plugin extends IPlugin> {
187192
renderChildType: RenderChildType = RenderChildType.INLINE,
188193
position?: NotePosition | undefined,
189194
honorExcludedSetting: boolean = true,
190-
): FieldBase {
195+
): FieldMountable {
191196
validate(
192197
z.object({
193198
fieldString: z.string(),
@@ -245,7 +250,7 @@ export abstract class API<Plugin extends IPlugin> {
245250
renderChildType: RenderChildType = RenderChildType.INLINE,
246251
position?: NotePosition | undefined,
247252
honorExcludedSetting: boolean = true,
248-
): FieldBase {
253+
): FieldMountable {
249254
validate(
250255
z.object({
251256
type: V_FieldType,
@@ -266,27 +271,27 @@ export abstract class API<Plugin extends IPlugin> {
266271
);
267272

268273
if (this.plugin.internal.isFilePathExcluded(filePath) && honorExcludedSetting) {
269-
return this.createExcludedBase(filePath);
274+
return this.createExcludedMountable(filePath);
270275
}
271276

272-
if (type === FieldType.INPUT_FIELD) {
273-
return this.createInputFieldBase(filePath, {
277+
if (type === FieldType.INPUT) {
278+
return this.createInputFieldMountable(filePath, {
274279
renderChildType: renderChildType,
275280
declaration: declaration,
276281
scope: scope,
277282
});
278283
}
279284

280-
if (type === FieldType.VIEW_FIELD) {
281-
return this.createViewFieldBase(filePath, {
285+
if (type === FieldType.VIEW) {
286+
return this.createViewFieldMountable(filePath, {
282287
renderChildType: renderChildType,
283288
declaration: declaration,
284289
scope: scope,
285290
});
286291
}
287292

288293
if (type === FieldType.BUTTON_GROUP) {
289-
return this.createButtonGroupBase(filePath, {
294+
return this.createButtonGroupMountable(filePath, {
290295
renderChildType: renderChildType,
291296
declaration: declaration,
292297
position: position,
@@ -302,7 +307,7 @@ export abstract class API<Plugin extends IPlugin> {
302307
});
303308
}
304309

305-
public createInputFieldBase(filePath: string, options: InputFieldOptions): InputFieldBase {
310+
public createInputFieldMountable(filePath: string, options: InputFieldOptions): InputFieldMountable {
306311
validate(
307312
z.object({
308313
filePath: V_FilePath,
@@ -327,10 +332,10 @@ export abstract class API<Plugin extends IPlugin> {
327332
);
328333
}
329334

330-
return new InputFieldBase(this.plugin, uuid, filePath, options.renderChildType, declaration);
335+
return new InputFieldMountable(this.plugin, uuid, filePath, options.renderChildType, declaration);
331336
}
332337

333-
public createViewFieldBase(filePath: string, options: ViewFieldOptions): ViewFieldBase {
338+
public createViewFieldMountable(filePath: string, options: ViewFieldOptions): ViewFieldMountable {
334339
validate(
335340
z.object({
336341
filePath: V_FilePath,
@@ -355,10 +360,10 @@ export abstract class API<Plugin extends IPlugin> {
355360
);
356361
}
357362

358-
return new ViewFieldBase(this.plugin, uuid, filePath, options.renderChildType, declaration);
363+
return new ViewFieldMountable(this.plugin, uuid, filePath, options.renderChildType, declaration);
359364
}
360365

361-
public createJsViewFieldBase(filePath: string, options: JsViewFieldOptions): JsViewField {
366+
public createJsViewFieldMountable(filePath: string, options: JsViewFieldOptions): JsViewFieldMountable {
362367
validate(
363368
z.object({
364369
filePath: V_FilePath,
@@ -379,10 +384,27 @@ export abstract class API<Plugin extends IPlugin> {
379384
declaration = this.jsViewFieldParser.fromSimpleDeclarationAndValidate(options.declaration, filePath);
380385
}
381386

382-
return new JsViewField(this.plugin, uuid, filePath, declaration);
387+
return new JsViewFieldMountable(this.plugin, uuid, filePath, declaration);
383388
}
384389

385-
public createButtonGroupBase(filePath: string, options: ButtonGroupOptions): ButtonGroupBase {
390+
public createTableFieldMountable(filePath: string, options: TableFieldOptions): TableMountable {
391+
validate(
392+
z.object({
393+
filePath: V_FilePath,
394+
options: V_TableFieldOptions,
395+
}),
396+
{
397+
filePath: filePath,
398+
options: options,
399+
},
400+
);
401+
402+
const uuid = getUUID();
403+
404+
return new TableMountable(this.plugin, uuid, filePath, options.bindTarget, options.tableHead, options.columns);
405+
}
406+
407+
public createButtonGroupMountable(filePath: string, options: ButtonGroupOptions): ButtonGroupMountable {
386408
validate(
387409
z.object({
388410
filePath: V_FilePath,
@@ -403,10 +425,17 @@ export abstract class API<Plugin extends IPlugin> {
403425
declaration = this.buttonParser.validateGroup(options.declaration);
404426
}
405427

406-
return new ButtonGroupBase(this.plugin, uuid, filePath, declaration, options.renderChildType, options.position);
428+
return new ButtonGroupMountable(
429+
this.plugin,
430+
uuid,
431+
filePath,
432+
declaration,
433+
options.renderChildType,
434+
options.position,
435+
);
407436
}
408437

409-
public createButtonBase(filePath: string, options: ButtonOptions): ButtonBase {
438+
public createButtonMountable(filePath: string, options: ButtonOptions): ButtonMountable {
410439
validate(
411440
z.object({
412441
filePath: V_FilePath,
@@ -427,10 +456,10 @@ export abstract class API<Plugin extends IPlugin> {
427456
declaration = this.buttonParser.validate(options.declaration);
428457
}
429458

430-
return new ButtonBase(this.plugin, uuid, filePath, declaration, options.position, options.isPreview);
459+
return new ButtonMountable(this.plugin, uuid, filePath, declaration, options.position, options.isPreview);
431460
}
432461

433-
public createEmbedBase(filePath: string, options: EmbedOptions): EmbedBase {
462+
public createEmbedMountable(filePath: string, options: EmbedOptions): EmbedMountable {
434463
validate(
435464
z.object({
436465
filePath: V_FilePath,
@@ -443,10 +472,10 @@ export abstract class API<Plugin extends IPlugin> {
443472
);
444473

445474
const uuid = getUUID();
446-
return new EmbedBase(this.plugin, uuid, filePath, options.depth, options.content);
475+
return new EmbedMountable(this.plugin, uuid, filePath, options.depth, options.content);
447476
}
448477

449-
public createExcludedBase(filePath: string): ExcludedBase {
478+
public createExcludedMountable(filePath: string): ExcludedMountable {
450479
validate(
451480
z.object({
452481
filePath: V_FilePath,
@@ -457,7 +486,7 @@ export abstract class API<Plugin extends IPlugin> {
457486
);
458487

459488
const uuid = getUUID();
460-
return new ExcludedBase(this.plugin, uuid, filePath);
489+
return new ExcludedMountable(this.plugin, uuid, filePath);
461490
}
462491

463492
/**
@@ -475,9 +504,9 @@ export abstract class API<Plugin extends IPlugin> {
475504
},
476505
);
477506

478-
if (fieldType === FieldType.INPUT_FIELD) {
507+
if (fieldType === FieldType.INPUT) {
479508
return 'INPUT';
480-
} else if (fieldType === FieldType.VIEW_FIELD) {
509+
} else if (fieldType === FieldType.VIEW) {
481510
return 'VIEW';
482511
} else if (fieldType === FieldType.BUTTON_GROUP) {
483512
return 'BUTTON';

0 commit comments

Comments
 (0)