Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve types, close #970 #974

Closed
wants to merge 5 commits into from
Closed

Conversation

midgleyc
Copy link
Contributor

@midgleyc midgleyc commented May 8, 2020

Please check if the PR fulfills these requirements

  • It's the right issue type on the title
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)
  • It does not introduce a breaking change or has a description of the breaking change

Description

As discussed in #970, I've found some types that I'd like to change. I've left each separate change in its own commit for easier discussion / reversion if necessary. I've tried to mark whether it was a fix (type was wrong) or feat (new public type).

setValue was present under the functions of Viewer, but calling it crashed the application as it doesn't exist any more.

When using custom events, you can pass additional arguments through emit. The first arg is always the name of the event, so I left it in.

eventManager wasn't available under Editor: I added a method to call-through for the method you need to call when adding a custom button, and updated the example to use it. I also noted that addCommand should be public: there is the same issue with commandManager.

CommandManagerExecFunc incorrectly said the first argument was a string -- I think it's actually one of Editor (for global commands), MarkdownEditor (for markdown commands) or WysiwygEditor (for wysiwyg commands).

Finally, there are some methods in MarkdownEditor that are accessible through CodeMirrorExt (that MarkdownEditor extends) that are useful when writing custom commands. I added the two I used.

Closes #970


Thank you for your contribution to TOAST UI product. 🎉 😘 ✨

interface MarkdownRange {
from: CodeMirror.Position;
to: CodeMirror.Position;
ollapsed: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of this property is wrong, collapsed is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I will fix this

Comment on lines +743 to +745
public addCommand(type: Command): void;

public addCommand(type: string, props: CommandPropsOptions): void;
Copy link
Member

@seonim-ryu seonim-ryu May 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you declare addCommand twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first type is different: the first one takes a single Command, the second one takes two parameters: a string and a CommandPropsOptions

https://github.com/nhn/tui.editor/blob/master/apps/editor/src/js/editor.js#L359-L365

I could declare it

public addCommand(type: string | Command, props?: CommandPropsOptions): void;

but I thought declaring the two options separately was more precise.

@@ -835,8 +852,6 @@ declare namespace toastui {

public setMarkdown(markdown: string): void;

public setValue(markdown: string): void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
It remains in the Editor class, can you remove it too?

public setValue(value: string, cursorToEnd?: boolean): void;

// @TODO: change toastMark type definition to @toast-ui/toastmark type file through importing
class MarkdownEditor {
class MarkdownEditor extends CodeMirrorExt {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add the CodeMirrorExt type to handle the event issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is actually a type bug fix. MarkdownEditor extends a CodeMirrorExt class:

https://github.com/nhn/tui.editor/blob/master/apps/editor/src/js/markdownEditor.js#L113

but this isn't represented in the types. I added two methods from CodeMirrorExt I found useful when developing custom commands: ideally I think they would all be added but this is quite a lot more work!

Copy link
Member

@seonim-ryu seonim-ryu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@midgleyc I completed the review. Thank you for contributing! :)

But this PR will be difficult to merge. First, there are two issues in this PR. In this case, issues and PRs must be managed individually.

  • Bug Fix : Remove setValue from index.d.ts
  • Feature : Add new API (addEventType)

And in case of the API that you want to add newly, it is better to handle it after the specification is decided as I answered in the previous issue.

#970 (comment)

So, it would be better to close this PR and remove setValue from index.d.ts to create the PR again. Removing setValue is simple and I can handle it, but it seems meaningful that you contribute. Then please check the comments with the above issue!

@midgleyc
Copy link
Contributor Author

I have split this out into:

#986 which contains only the setValue function removal
#987 which includes some other type fixes and features I found essential while developing custom commands
#988 which contains the addEventType feature. As discussed in #970 and above this will wait until the specification is decided and may change.

Thanks for the review!

@midgleyc midgleyc closed this May 15, 2020
js87zz pushed a commit that referenced this pull request Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues with typings in 2.1.0
2 participants