Skip to content

Commit

Permalink
fix: #439 修复sidebar设置为false失效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Apr 24, 2023
1 parent 3e5b3b8 commit 4474e47
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/Cherry.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,12 @@ export default class Cherry extends CherryStatic {
$expectTarget(this.options.toolbars.toolbar, Array);
// 创建顶部工具栏
this.toolbar = this.createToolbar();
// 创建预览区域的侧边工具栏
this.sidebar = this.createSidebar();

const wrapperFragment = document.createDocumentFragment();
wrapperFragment.appendChild(this.toolbar.options.dom);
wrapperFragment.appendChild(editor.options.editorDom);
wrapperFragment.appendChild(this.sidebar.options.dom);
// 创建预览区域的侧边工具栏
this.createSidebar(wrapperFragment);
if (!this.options.previewer.dom) {
wrapperFragment.appendChild(previewer.options.previewerDom);
}
Expand Down Expand Up @@ -403,25 +402,28 @@ export default class Cherry extends CherryStatic {
* @private
* @returns
*/
createSidebar() {
const externalClass = this.options.toolbars.theme === 'dark' ? 'dark' : '';
const dom = createElement('div', `cherry-sidebar ${externalClass}`);
this.sidebar = new Sidebar({
dom,
$cherry: this,
buttonConfig: this.options.toolbars.sidebar,
customMenu: this.options.toolbars.customMenu,
});
return this.sidebar;
createSidebar(wrapperFragment) {
if (this.options.toolbars.sidebar) {
$expectTarget(this.options.toolbars.sidebar, Array);
const externalClass = this.options.toolbars.theme === 'dark' ? 'dark' : '';
const dom = createElement('div', `cherry-sidebar ${externalClass}`);
this.sidebar = new Sidebar({
dom,
$cherry: this,
buttonConfig: this.options.toolbars.sidebar,
customMenu: this.options.toolbars.customMenu,
});
wrapperFragment.appendChild(this.sidebar.options.dom);
}
}

/**
* @private
* @returns
*/
createFloatMenu() {
const dom = createElement('div', 'cherry-floatmenu');
if (this.options.toolbars.float) {
const dom = createElement('div', 'cherry-floatmenu');
$expectTarget(this.options.toolbars.float, Array);
this.floatMenu = new FloatMenu({
dom,
Expand All @@ -436,8 +438,8 @@ export default class Cherry extends CherryStatic {
* @returns
*/
createBubble() {
const dom = createElement('div', 'cherry-bubble');
if (this.options.toolbars.bubble) {
const dom = createElement('div', 'cherry-bubble');
$expectTarget(this.options.toolbars.bubble, Array);
this.bubble = new Bubble({
dom,
Expand Down

0 comments on commit 4474e47

Please sign in to comment.