unxok / dataedit

Dataview tables but editable!
MIT License
70 stars 1 forks source link
beta dataview obsidian obsidian-md obsidian-plugin

Obsidian Dataedit📝

Transform Your Dataview queries into editable tables ✨

This is an Obsidian plugin that turns your static Dataview queries into dynamic, editable tables. Edit data right where you see it, without needing to leave your current view.

💌 Support the Project: I humbly appreciate any support you would like to give me to keep updates brewing! However, please consider supporting blacksmithgu first and foremost for all their hardwork which makes this plugin possible.

Buy Me A Coffee

TOC

Dependencies

This plugin leans heavily on the mighty Dataview plugin to make querying note metadata possible. Huge shoutout to blacksmithgu (and other contributers) for their outstanding work. This would not be possible without them!

What about Datacore?

The development of Datacore, another brilliant creation by blacksmithgu, will fulfill most needs to use this plugin. Datacore promises similar features along with an enhanced query engine. However, it's not ready for the public yet—created 2 years ago and with no recent roadmap updates (last checked 9 months ago).

So, why wait? This plugin is here to fill that gap, bringing you the editing capabilities today!

Join the Beta 🚀

We're Officially Beta Testing! Before this plugin hits the Obsidian community page, I’m hoping for some brave souls to dive in, test it out, and help me spot bugs and share your ideas for new features.

How to Get Involved

  1. Direct Install: Grab the plugin straight from the release
  2. BRAT Plugin: Or install it using the BRAT plugin by TfTHacker for a quick and easy install.

Found a Bug? Got a Feature Idea?

Don’t be shy! Open an issue on GitHub for any bugs 🐞, feature suggestions 💡, or questions ❓ you might have. Your feedback is valuable!

Thank you!!

Demo🎥

Key features🌟

demo gif

Usage

[!IMPORTANT] The Dataview plugin must installed and enabled separately!

Set your codeblock language to dataedit

```dataedit
TABLE foo
FROM #bar

The codeblock will accept a **_dataview query_** or a **_Javascript expression_** that returns an object with `headers` and `values` keys with arrays respectively.

## Dataview Query

Most _(exceptions below)_ valid Dataview queries _should_ work (let me know if not!)

> [!CAUTION]
> Inline metadata may show in the table, but editing it will cause it to be added as a frontmatter property (support coming soon).

````sql
```dataedit
TABLE progress, category
FROM #tasks
SORT file.name

> [!WARNING]
> The exceptions to the statement above are:
>
> -   You <u>must</u> include the note link as one of the columns.
>     -   the 'File' column is included by default, but if you use `TABLE WITHOUT ID`, then you <u>must</u> include `file.link`.
> -   You <u>cannot</u> specify column aliases in the query (you can set up aliases in this plugin or block settings though)
> -   I haven't tried it yet, but I am pretty sure `GROUP BY` will <u>not</u> work (on roadmap)

## Javascript expression

-   You will have access to the dataview api through `dv` just like in a dataview js expression
    -   Dataview [render methods](https://blacksmithgu.github.io/obsidian-dataview/api/code-reference/#render) will not work properly, so don't use them.
-   You must return `{headers: string[], values: string[][]}`
-   Note that you still just use the `dataedit` code block language. The plugin will automatically detect if you have entered a dataview query or js expression
-   _Technically_ you don't have to use dataview here, but currently I rely on some data types produced by it so it won't work properly

````js
// surround with ```dataedit <newline> ``` like normal
const data = dv
    .pages("#tasks")
    .map((p) => [p.file.link, p.progress, p.category]);
return { headers: ["Name", "Progress", "Category"], values: data };

Customization

You can customize the way tables look and behave through either the plugin settings and or an individual code blocks config.

Plugin settings

These settings will apply to all Dataedit tables unless that code block has its own config that conflicts with them.

plugin settings demo

Block config

This configuration will apply only to the table produced from that codeblock.

block config demo

Implementation details

The following is a typescript definition of the expected shape of the provided config after being parsed to YAML. This is validated by zod and will revert to the plugin settings if an invalid config is provided.

Zod schema

Show code ```ts const StartCenterEnd = z.union([ z.literal("start"), z.literal("center"), z.literal("end"), ]); const TopMiddleBottom = z.union([ z.literal("top"), z.literal("middle"), z.literal("bottom"), ]); const Alignment = z.object({ vertical: TopMiddleBottom, horizontal: StartCenterEnd, enabled: z.boolean(), }); export const SettingsSchema = z.object({ autoSuggest: z.boolean(), renderMarkdown: z.boolean(), showNumberButtons: z.boolean(), showTypeIcons: z.boolean(), emptyValueDisplay: z.string(), queryLinksPropertyName: z.string(), cssClassName: z.string(), columnAliases: z.array(z.array(z.string(), z.string())), verticalAlignment: TopMiddleBottom, horizontalAlignment: StartCenterEnd, alignmentByType: z.object({ text: Alignment, list: Alignment, number: Alignment, checkbox: Alignment, date: Alignment, datetime: Alignment, }), }); ```

Default settings

Below are what the default plugin settings are when you first install the plugin.

Show code ```ts { autoSuggest: true, renderMarkdown: true, showNumberButtons: true, showTypeIcons: true, emptyValueDisplay: "-", queryLinksPropertyName: "dataedit-links", cssClassName: "", columnAliases: [["thisColumn", "showThisAlias"]], verticalAlignment: "top", horizontalAlignment: "start", alignmentByType: { text: { vertical: "top", horizontal: "start", enabled: false, }, list: { vertical: "top", horizontal: "start", enabled: false, }, number: { vertical: "top", horizontal: "start", enabled: false, }, checkbox: { vertical: "top", horizontal: "start", enabled: false, }, date: { vertical: "top", horizontal: "start", enabled: false, }, datetime: { vertical: "top", horizontal: "start", enabled: false, }, }, }; ```

Roadmap

Items will be moved to the appropriate release once I start working on them or have them planned out

Releases

0.0.3 (TBD upcoming)

0.0.2 (TBD upcoming)

0.0.1 (2024-05-30)

Initial beta release!

Contributing

Feel free to open an issue for improvements, bugs, questions, etc.

If you would like to contribute to the project, please fork the repo and make a pull request! Setting it up on your local machine is as simple as cloning the repo and running npm install. It comes with a test vault (/test-vault) which is where the code gets built to on npm run build.