obsidian-releases icon indicating copy to clipboard operation
obsidian-releases copied to clipboard

Add table generator

Open Quorafind opened this issue 1 year ago • 7 comments

I am submitting a new Community Plugin

Repo URL

Link to my plugin: https://github.com/Quorafind/Obsidian-Table-Generator

Release Checklist

  • [ ] I have tested the plugin on
    • [x] Windows
    • [ ] macOS
    • [ ] Linux
    • [ ] Android (if applicable)
    • [ ] iOS (if applicable)
  • [x] My GitHub release contains all required files
    • [x] main.js
    • [x] manifest.json
    • [x] styles.css (optional)
  • [x] GitHub release name matches the exact version number specified in my manifest.json (Note: Use the exact version number, don't include a prefix v)
  • [x] The id in my manifest.json matches the id in the community-plugins.json file.
  • [x] My README.md describes the plugin's purpose and provides clear usage instructions.
  • [x] I have read the tips in https://github.com/obsidianmd/obsidian-releases/blob/master/plugin-review.md and have self-reviewed my plugin to avoid these common pitfalls.
  • [x] I have added a license in the LICENSE file.
  • [x] My project respects and is compatible with the original license of any code from other plugins that I'm using. I have given proper attribution to these other projects in my README.md.

Quorafind avatar Jul 12 '22 06:07 Quorafind

this.tableGeneratorEl.style.position = "absolute"; you should move these into the CSS file to make it easier to style, if possible.

SampleSettingTab Rename this to avoid conflicts.

this.applyDebounceTimer = window.setTimeout(() => { You can use the .registerInterval from the API instead, it will be automatically unloaded.

this.registerInterval(window.setTimeout(() => {
            plugin.saveSettings();
        }, 100)
);

The following are just style nitpicks, you don't have fix these.

(evt.target as HTMLElement) You are doing this multiple times, at multiple places, you could just save this in a variable.

joethei avatar Jul 15 '22 07:07 joethei

@joethei Fixed in https://github.com/Quorafind/Obsidian-Table-Generator/commit/26476699f14e90a1d4ef4e01b4e577d46ea45dbd

Quorafind avatar Jul 17 '22 15:07 Quorafind

liamcain avatar Aug 04 '22 21:08 liamcain

I'm sorry not to see this added. I've found it useful via BRAT.

claremacrae avatar Sep 19 '22 08:09 claremacrae

Sorry that I didn't update this. And it closed automatically because I pulled a new request. I will reopen this soon. @claremacrae

Quorafind avatar Sep 19 '22 08:09 Quorafind

Oh that's great news. Thanks!

claremacrae avatar Sep 19 '22 08:09 claremacrae

@liamcain hi, I fixed all these issues.

Quorafind avatar Sep 20 '22 16:09 Quorafind

  • if (!this.tableGeneratorEl) return; Unnecessary check, createElement won't fail, so this will never run
  • if (this.tableGeneratorEl) this.tableGeneratorEl.detach(); No need to detach if you're just going to reattach. appendChild will automatically detach if the element is attached elsewhere. I feel like the logic you have here is a bit backwards. I think what you want to do is check if tableGeneratorEl doesn't exist, if so, create the element. Then unconditionally attach the element to the body.
  • registerTableGeneratorMenu afaict, this function doesn't do anything. I think you can just remove it.
  • style You can use svelte's style directive instead. Another cool option would be passing in the row and column as css vars. That way you can keep the css inside your style tag.
  • hideTable You already have a reference to your table instance in the plugin. I think it's better to just pass around the reference to the table rather than querying the DOM for it. Or just have hideTable be a function on the plugin instance, then call plugin.hideTable if you want to avoid passing the htmlelement instance around.

liamcain avatar Oct 06 '22 03:10 liamcain

@liamcain

if (!this.tableGeneratorEl) return; Unnecessary check, createElement won't fail, so this will never run

Remove. And use createEl from Obsidian now.

if (this.tableGeneratorEl) this.tableGeneratorEl.detach(); No need to detach if you're just going to reattach. appendChild will automatically detach if the element is attached elsewhere. I feel like the logic you have here is a bit backwards. I think what you want to do is check if tableGeneratorEl doesn't exist, if so, create the element. Then unconditionally attach the element to the body.

But appendChild didn't work with popout windows, for example when I create a new table generator in the popout window, the old one would not auto detach. So if you know how to make this work well with popout windows , I need some help 😂 Or I have to leave the code here.

registerTableGeneratorMenu afaict, this function doesn't do anything. I think you can just remove it.

This does same thing like above.

style You can use svelte's style directive instead. Another cool option would be passing in the row and column as css vars. That way you can keep the css inside your style tag.

Used style directive.

hideTable You already have a reference to your table instance in the plugin. I think it's better to just pass around the reference to the table rather than querying the DOM for it. Or just have hideTable be a function on the plugin instance, then call plugin.hideTable if you want to avoid passing the htmlelement instance around.

Move hidetable to plugin class.

Quorafind avatar Oct 07 '22 02:10 Quorafind

LGTM, do you mind rebasing this PR? Github has decided that I can't resolve the conflicts via the web UI for some reason.

liamcain avatar Oct 10 '22 20:10 liamcain

@liamcain https://github.com/obsidianmd/obsidian-releases/pull/1212

Quorafind avatar Oct 11 '22 01:10 Quorafind