mProjectsCode / obsidian-meta-bind-plugin

A plugin for Obsidian to make your notes interactive with inline input fields, metadata displays, and buttons.
https://www.moritzjung.dev/obsidian-meta-bind-plugin-docs/
GNU General Public License v3.0
490 stars 40 forks source link

[regression] Dynamically generating tables with `mb.createBindTarget` doesn't work anymore #285

Closed seomwan closed 6 months ago

seomwan commented 6 months ago

Please fill out these Check-boxes

This Issue Occurs on

Plugin Version

1.0.3

Describe the Issue

Here's the example I used as reference:

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/831c052dbbe6ebe572fbe627f2bb5b1cd3cd0b83/exampleVault/Advanced%20Examples/Activity%20Tracker.md?plain=1#L12

Gives the error:

plugin:js-engine:45 failed to execute JS Error: [MB_INTERNAL] "invalid arguments supplied to function" caused by error "[
  {
    "code": "invalid_type",
    "expected": "array",
    "received": "undefined",
    "path": [
      "property"
    ],
    "message": "Required"
  }
]"
    at jr (plugin:obsidian-meta-bind-plugin:110:56155)
    at Ah.createBindTarget (plugin:obsidian-meta-bind-plugin:111:17437)
    at Bo.eval [as func] (eval at buildFunction (plugin:js-engine:1:1), <anonymous>:7:23)
    at Bo.runFunction (plugin:js-engine:45:61422)
[...]

Steps to Reproduce

Reproducible in a new test vault with Metabind and JSengine installed:

```js-engine
const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;

const bindTarget = mb.createBindTarget('activities', context.file.path);


### Expected Behavior

Shouldn't error as it worked in previous (<1.0) versions.

Or example needs to be updated for new behavior?
seomwan commented 6 months ago

I see the api changed and there's a new required argument:

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/831c052dbbe6ebe572fbe627f2bb5b1cd3cd0b83/packages/core/src/api/API.ts#L594

This does silence that error and give a new one, although I'm not sure what needs to be passed in:

mb.createBindTarget('activities', context.file.path, ['activities'])

And the corresponding test doesn't seemed to be updated yet:

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/831c052dbbe6ebe572fbe627f2bb5b1cd3cd0b83/tests/metadataManagerTests/MetadataManager.test.ts#L30

But that api looks even more outdated (different?) than the current code I'm using..

seomwan commented 6 months ago

Okay, just missed the doc comments right above that:

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/831c052dbbe6ebe572fbe627f2bb5b1cd3cd0b83/packages/core/src/api/API.ts#L583-L590

Updated my code to:

const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;

const bindTarget = mb.createBindTarget('activities', context.file.path);

And it still gives an error, but I'm pretty sure it's due to another problem:createInputFieldDeclarationFromString no longer exists

Tried to trace it until:

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/831c052dbbe6ebe572fbe627f2bb5b1cd3cd0b83/packages/core/src/api/API.ts#L570

I don't know why it gives undefined here, and I'm out of time, so I'll check it later..

mProjectsCode commented 6 months ago

Oh yeah, it seems like I forgot to finish the new API for creating the tables.

mProjectsCode commented 6 months ago

Released a new canary release that with the new API and updated the pf2e example.

seomwan commented 6 months ago

I'm getting an Error: mb.createTableMountable is not a function

Edit: restarting fixed it