Skip to content

Commit afc0c25

Browse files
committed
some more API changes and fixes
1 parent 6fc4e53 commit afc0c25

38 files changed

+412
-368
lines changed

esbuild.dev.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const context = await esbuild.context({
4444
sourcemap: 'inline',
4545
treeShaking: true,
4646
outdir: `exampleVault/.obsidian/plugins/${manifest.id}/`,
47-
outbase: 'src',
47+
outbase: 'packages/obsidian/src',
4848
define: {
4949
MB_GLOBAL_CONFIG_DEV_BUILD: 'true',
5050
},

exampleVault/Advanced Examples/Using JS Engine for Complex things.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ text: aasdasd
33
locked: false
44
---
55

6-
76
Locked: `INPUT[toggle:locked]`
87
```js-engine
98
const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
@@ -15,15 +14,16 @@ component.register(mb.listenToMetadata(signal, context.file.path, ['locked']));
1514
const comp = new obsidian.Component(component);
1615
1716
function render() {
18-
comp.unload()
19-
comp.load()
17+
comp.unload();
18+
comp.load();
2019
container.empty();
20+
let field;
2121
if (signal.get()) {
22-
mb.createViewFieldFromString("VIEW[{text}][text]", "inline", context.file.path, container, comp);
22+
field = mb.createInlineFieldFromString("VIEW[{text}][text]", context.file.path, undefined);
2323
} else {
24-
mb.createInputFieldFromString("INPUT[text:text]", "inline", context.file.path, container, comp);
24+
field = mb.createInlineFieldFromString("INPUT[text:text]", context.file.path, undefined);
2525
}
26-
26+
mb.wrapInMDRC(field, container, comp);
2727
}
2828
2929
const reactive = engine.reactive(render);

exampleVault/Examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
slider1: 8
2+
slider1: 5
33
suggest: test
44
toggle1: false
55
Domestic_tasks:
@@ -13,7 +13,7 @@ inlineSelect: 0
1313
nested:
1414
object: test
1515
number1: 2
16-
number2: 16
16+
number2: 10
1717
---
1818

1919
## Fields Work Everywhere

packages/core/bun.lockb

720 Bytes
Binary file not shown.

packages/core/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"name": "meta-bind-core",
33
"main": "src/index.ts",
44
"devDependencies": {
5-
"svelte": "^4.2.11"
5+
"svelte": "^4.2.11",
6+
"@lemons_dev/parsinom": "^0.0.12",
7+
"zod": "^3.22.4"
68
}
79
}

packages/core/src/api/API.ts

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,22 @@ export abstract class API<Plugin extends IPlugin> {
142142
this.syntaxHighlighting = overrides?.syntaxHighlighting ?? new SyntaxHighlightingAPI(plugin);
143143
}
144144

145+
/**
146+
* Creates a field of a given type.
147+
*
148+
* @param type
149+
* @param filePath
150+
* @param options
151+
* @param honorExcludedSetting
152+
*/
145153
public createField<Type extends FieldType>(
146154
type: Type,
147155
filePath: string,
148156
options: FieldOptionMap[Type],
149157
honorExcludedSetting: boolean = true,
150158
): FieldBase {
151159
if (this.plugin.internal.isFilePathExcluded(filePath) && honorExcludedSetting) {
152-
return this.createExcludedBase(filePath, undefined);
160+
return this.createExcludedBase(filePath);
153161
}
154162

155163
if (type === FieldType.INPUT_FIELD) {
@@ -165,7 +173,7 @@ export abstract class API<Plugin extends IPlugin> {
165173
} else if (type === FieldType.EMBED) {
166174
return this.createEmbedBase(filePath, options as FieldOptionMap[FieldType.EMBED]);
167175
} else if (type === FieldType.EXCLUDED) {
168-
return this.createExcludedBase(filePath, options as FieldOptionMap[FieldType.EXCLUDED]);
176+
return this.createExcludedBase(filePath);
169177
}
170178

171179
expectType<never>(type);
@@ -174,10 +182,21 @@ export abstract class API<Plugin extends IPlugin> {
174182
throw new Error(`Unknown field type: ${type}`);
175183
}
176184

185+
/**
186+
* Creates an inline field from a string.
187+
* Will throw an error if the string is not a valid declaration.
188+
*
189+
* @param fieldString
190+
* @param filePath
191+
* @param scope
192+
* @param renderChildType
193+
* @param honorExcludedSetting
194+
*/
177195
public createInlineFieldFromString(
178-
filePath: string,
179196
fieldString: string,
197+
filePath: string,
180198
scope: BindTargetScope | undefined,
199+
renderChildType: RenderChildType = RenderChildType.INLINE,
181200
honorExcludedSetting: boolean = true,
182201
): FieldBase {
183202
const fieldType = this.isInlineFieldDeclarationAndGetType(fieldString);
@@ -189,38 +208,57 @@ export abstract class API<Plugin extends IPlugin> {
189208
});
190209
}
191210

192-
return this.createInlineFieldOfTypeFromString(fieldType, filePath, fieldString, scope, honorExcludedSetting);
211+
return this.createInlineFieldOfTypeFromString(
212+
fieldType,
213+
fieldString,
214+
filePath,
215+
scope,
216+
renderChildType,
217+
honorExcludedSetting,
218+
);
193219
}
194220

221+
/**
222+
* Creates an inline field of a given type and string.
223+
* Will throw an error if the string is not a valid inline field type.
224+
*
225+
* @param type
226+
* @param filePath
227+
* @param declaration
228+
* @param scope
229+
* @param renderChildType
230+
* @param honorExcludedSetting
231+
*/
195232
public createInlineFieldOfTypeFromString(
196233
type: InlineFieldType,
234+
declaration: string,
197235
filePath: string,
198-
fieldString: string,
199236
scope: BindTargetScope | undefined,
237+
renderChildType: RenderChildType = RenderChildType.INLINE,
200238
honorExcludedSetting: boolean = true,
201239
): FieldBase {
202240
if (this.plugin.internal.isFilePathExcluded(filePath) && honorExcludedSetting) {
203-
return this.createExcludedBase(filePath, undefined);
241+
return this.createExcludedBase(filePath);
204242
}
205243

206244
if (type === FieldType.INPUT_FIELD) {
207245
return this.createInputFieldBase(filePath, {
208-
renderChildType: RenderChildType.INLINE,
209-
declaration: fieldString,
246+
renderChildType: renderChildType,
247+
declaration: declaration,
210248
scope: scope,
211249
});
212250
}
213251

214252
if (type === FieldType.VIEW_FIELD) {
215253
return this.createViewFieldBase(filePath, {
216-
renderChildType: RenderChildType.INLINE,
217-
declaration: fieldString,
254+
renderChildType: renderChildType,
255+
declaration: declaration,
218256
scope: scope,
219257
});
220258
}
221259

222260
if (type === FieldType.INLINE_BUTTON) {
223-
return this.createInlineButtonBase(filePath, { declaration: fieldString });
261+
return this.createInlineButtonBase(filePath, { declaration: declaration });
224262
}
225263

226264
expectType<never>(type);
@@ -232,7 +270,7 @@ export abstract class API<Plugin extends IPlugin> {
232270
});
233271
}
234272

235-
public createInputFieldBase(filePath: string, options: FieldOptionMap[FieldType.INPUT_FIELD]): InputFieldBase {
273+
public createInputFieldBase(filePath: string, options: InputFieldOptions): InputFieldBase {
236274
const uuid = getUUID();
237275

238276
let declaration: InputFieldDeclaration;
@@ -249,7 +287,7 @@ export abstract class API<Plugin extends IPlugin> {
249287
return new InputFieldBase(this.plugin, uuid, filePath, options.renderChildType, declaration);
250288
}
251289

252-
public createViewFieldBase(filePath: string, options: FieldOptionMap[FieldType.VIEW_FIELD]): ViewFieldBase {
290+
public createViewFieldBase(filePath: string, options: ViewFieldOptions): ViewFieldBase {
253291
const uuid = getUUID();
254292

255293
let declaration: ViewFieldDeclaration;
@@ -266,7 +304,7 @@ export abstract class API<Plugin extends IPlugin> {
266304
return new ViewFieldBase(this.plugin, uuid, filePath, options.renderChildType, declaration);
267305
}
268306

269-
public createJsViewFieldBase(filePath: string, options: FieldOptionMap[FieldType.JS_VIEW_FIELD]): JsViewField {
307+
public createJsViewFieldBase(filePath: string, options: JsViewFieldOptions): JsViewField {
270308
const uuid = getUUID();
271309

272310
let declaration: JsViewFieldDeclaration;
@@ -279,10 +317,7 @@ export abstract class API<Plugin extends IPlugin> {
279317
return new JsViewField(this.plugin, uuid, filePath, declaration);
280318
}
281319

282-
public createInlineButtonBase(
283-
filePath: string,
284-
options: FieldOptionMap[FieldType.INLINE_BUTTON],
285-
): InlineButtonBase {
320+
public createInlineButtonBase(filePath: string, options: InlineButtonOptions): InlineButtonBase {
286321
const uuid = getUUID();
287322

288323
let declaration: InlineButtonDeclaration;
@@ -295,7 +330,7 @@ export abstract class API<Plugin extends IPlugin> {
295330
return new InlineButtonBase(this.plugin, uuid, filePath, declaration);
296331
}
297332

298-
public createButtonBase(filePath: string, options: FieldOptionMap[FieldType.BUTTON]): ButtonBase {
333+
public createButtonBase(filePath: string, options: ButtonOptions): ButtonBase {
299334
const uuid = getUUID();
300335

301336
let declaration: ButtonDeclaration;
@@ -308,12 +343,12 @@ export abstract class API<Plugin extends IPlugin> {
308343
return new ButtonBase(this.plugin, uuid, filePath, declaration, options.isPreview);
309344
}
310345

311-
public createEmbedBase(filePath: string, options: FieldOptionMap[FieldType.EMBED]): EmbedBase {
346+
public createEmbedBase(filePath: string, options: EmbedOptions): EmbedBase {
312347
const uuid = getUUID();
313348
return new EmbedBase(this.plugin, uuid, filePath, options.depth, options.content);
314349
}
315350

316-
public createExcludedBase(filePath: string, _options: FieldOptionMap[FieldType.EXCLUDED]): ExcludedBase {
351+
public createExcludedBase(filePath: string): ExcludedBase {
317352
const uuid = getUUID();
318353
return new ExcludedBase(this.plugin, uuid, filePath);
319354
}

0 commit comments

Comments
 (0)