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: customize toolbar (ref #85) #124

Merged
merged 6 commits into from
Apr 3, 2018
Merged

Conversation

kyuwoo-choi
Copy link
Member

@kyuwoo-choi kyuwoo-choi commented Apr 2, 2018

image

refactoring

  • remove DefaultToolbar
  • add ToolbarItemFactory

feature

  • create ToolbarItems from options
  • create default ToolbarItems from default options

example

var editor = new tui.Editor({
        el: document.querySelector('#editSection'),
        previewStyle: 'vertical',
        height: '400px',
        initialEditType: 'markdown',
        useCommandShortcut: true,
        initialValue: content,
        exts: ['scrollSync', 'uml', 'chart', 'mark', 'table', 'taskCounter'],
        toolbarItems: [
          'heading',
          'bold',
          'divider',
          'indent',
          'outdent',
          {
            type: 'button',
            options: {
              name: 'test',
              className: 'custom-button-1',
              event: 'lol',
              tooltip: 'custom button 1'
            }
          },
          {
            type: 'button',
            options: {
              $el: $('<div style="float:left;width:100px;font-size: 10px;text-align:center;line-height: 30px">custom element</div>'),
              name: 'test2',
              className: 'custom-button-2',
              command: 'CustomCommand',
              tooltip: 'custom button 2'
            }
          }
        ]
      });

no deprecated entities in the diagram

*/
/* eslint-disable complexity */
static create(name, options) {
let toolbarItem;

Choose a reason for hiding this comment

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

static 맴버 하나뿐인 클래스인데 그냥 class로 선언하는것보다 object 리터럴로 선언하는게 직관적이지 않을까요?

Copy link
Member Author

Choose a reason for hiding this comment

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

맞아요. 필요한건 사실 함수 하나뿐이긴 한데.
이것이 팩토리 패턴으로 사용된다는 것을 명확하게 하니라 통상적인 구조 그대로 유지했어요.

@jinwoo-kim-nhn
Copy link

완료했습니다. 수고하셨습니다.

Copy link
Member

@shiren shiren left a comment

Choose a reason for hiding this comment

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

작업 깔끔하게 잘했네요~ 수고하셨습니다.

eventManager.listen('stateChange', ev => {
this._items.forEach(item => {
if (item._state) {
if (ev[item._state]) {
Copy link
Member

Choose a reason for hiding this comment

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

구조 괜찮네요..
음 조금 아이디어를 더하면 state를 키로 item을 매핑하는 객체 하나를 더 하거나 toolbar에 해당 기능을 구현해서 item을 쉽게 꺼낼 수 있게 하면 더 좋을것 같아요(getItemByState()?) 아무래도 매번 루프를 도는것 보다는 나을것 같아요. 꽤 호출되는 이벤트니까요..

Copy link
Member Author

Choose a reason for hiding this comment

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

좋습니다. 리팩토링은 하면 할수록 하고싶은게 계속 있네요. ㅋㅋ

_toolbar;

/**
* @memberof DefaultUI
Copy link
Member

Choose a reason for hiding this comment

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

요건 설명이 누락되었네요ㅎㅎ

Copy link
Member Author

Choose a reason for hiding this comment

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

헷 😉


return $el;
}

/**
* _setButton
* @param {Button} button - button instance
Copy link
Member

Choose a reason for hiding this comment

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

if (!(button instanceof Button)) 조건문 체크를 봐서는 인스턴스가 아닌 경우도 있는 것 같네요~
{Button|object} 이렇게 명시해야될 것 같습니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

ㅎㅎㅎ 정신없이 리팩토링하다가 넘어간게 몇개 어렴풋이 있는데.
역시 잡아주시는군요. 감사합니다.

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.

[4/3] 리뷰 완료하였습니다~ 코드 깔끔하네요 👍

@kyuwoo-choi kyuwoo-choi merged commit cae38ea into master Apr 3, 2018
@kyuwoo-choi kyuwoo-choi added this to the 1.1.0 milestone Apr 3, 2018
@kyuwoo-choi
Copy link
Member Author

아 별생각없이 머지 눌러버렸네요. 리뷰 내용은 별도 커밋으로 올립니다.

@kyuwoo-choi kyuwoo-choi deleted the feature/customize-toolbar branch April 3, 2018 12:05
seonim-ryu pushed a commit that referenced this pull request Jan 2, 2020
seonim-ryu pushed a commit that referenced this pull request Jan 2, 2020
seonim-ryu pushed a commit that referenced this pull request Jan 2, 2020
* feat: add getToolbar api to defaultUI
* feat: toolbar customization
* refactor: apply code review
* feat: add toolbar item factory
* feat: toolbar add/insert item by name/options
* feature: set toolbar items from editor options
seonim-ryu pushed a commit that referenced this pull request Jan 6, 2020
* feat: add getToolbar api to defaultUI
* feat: toolbar customization
* refactor: apply code review
* feat: add toolbar item factory
* feat: toolbar add/insert item by name/options
* feature: set toolbar items from editor options
js87zz pushed a commit that referenced this pull request Jun 17, 2021
js87zz pushed a commit that referenced this pull request Jun 17, 2021
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.

4 participants