Skip to content

Commit

Permalink
🎨 fix #875
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jan 1, 2021
1 parent 778aad2 commit 35cb610
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@

### v3.7.5 / 2020-12-xx

* [875](https://github.com/Vanessa219/vditor/issues/875) 增加大纲位置配置 `引入特性`
* [873](https://github.com/Vanessa219/vditor/issues/873) graphviz,mermaid 在为空时不应出现错误提示 `改进功能`
* [872](https://github.com/Vanessa219/vditor/issues/872) vditor.options.upload.file 支持 await `改进功能`

* 文档修改
* 3.7.5
* `options.outline` 修改为 `{ enable: boolean, position: "left" | "right" }`

### v3.7.4 / 2020-12-26

* [871](https://github.com/Vanessa219/vditor/issues/871) 大纲标题过长需显示省略号 `改进功能`
Expand Down
5 changes: 4 additions & 1 deletion demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ window.vditor = new Vditor('vditor', {
toolbar,
mode: 'wysiwyg',
height: window.innerHeight + 100,
outline: true,
outline: {
enable: true,
position: "right"
},
debugger: true,
typewriterMode: true,
placeholder: 'Hello, Vditor!',
Expand Down
5 changes: 5 additions & 0 deletions src/assets/scss/_reset.scss
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@
display: none;
overflow: auto;

&--right {
border-right: 0;
border-left: 1px solid var(--border-color);
}

&::-webkit-scrollbar {
display: none;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ts/toolbar/EditMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const setEditMode = (vditor: IVditor, type: string, event: Event | string
vditor.toolbar.elements["edit-mode"].querySelector(`button[data-mode="${vditor.currentMode}"]`).classList.add("vditor-menu--current");
}

vditor.outline.toggle(vditor, vditor.currentMode !== "sv" && vditor.options.outline);
vditor.outline.toggle(vditor, vditor.currentMode !== "sv" && vditor.options.outline.enable);
};

export class EditMode extends MenuItem {
Expand Down
4 changes: 2 additions & 2 deletions src/ts/toolbar/Outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class Outline extends MenuItem {
if (btnElement.classList.contains(Constants.CLASS_MENU_DISABLED)) {
return;
}
vditor.options.outline = !this.element.firstElementChild.classList.contains("vditor-menu--current");
vditor.outline.toggle(vditor, vditor.options.outline);
vditor.options.outline.enable = !this.element.firstElementChild.classList.contains("vditor-menu--current");
vditor.outline.toggle(vditor, vditor.options.outline.enable);
});
}
}
11 changes: 9 additions & 2 deletions src/ts/ui/initUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export const initUI = (vditor: IVditor) => {
const contentElement = document.createElement("div");
contentElement.className = "vditor-content";

contentElement.appendChild(vditor.outline.element);
if (vditor.options.outline.position === "left") {
contentElement.appendChild(vditor.outline.element);
}

contentElement.appendChild(vditor.wysiwyg.element.parentElement);

Expand All @@ -46,6 +48,11 @@ export const initUI = (vditor: IVditor) => {
contentElement.appendChild(vditor.devtools.element);
}

if (vditor.options.outline.position === "right") {
vditor.outline.element.classList.add("vditor-outline--right");
contentElement.appendChild(vditor.outline.element);
}

if (vditor.upload) {
contentElement.appendChild(vditor.upload.element);
}
Expand Down Expand Up @@ -110,7 +117,7 @@ export const setPadding = (vditor: IVditor) => {
if (vditor.preview.element.style.display !== "block" || vditor.currentMode === "sv") {
vditor.toolbar.element.style.paddingLeft = Math.max(5,
parseInt(vditor[vditor.currentMode].element.style.paddingLeft || "0", 10) +
vditor.outline.element.offsetWidth) + "px";
(vditor.options.outline.position === "left" ? vditor.outline.element.offsetWidth : 0)) + "px";
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/ts/util/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export class Options {
icon: "ant",
lang: "zh_CN",
mode: "ir",
outline: false,
outline: {
enable: false,
position: "left",
},
placeholder: "",
preview: {
actions: ["desktop", "tablet", "mobile", "mp-wechat", "zhihu"],
Expand Down
8 changes: 5 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,11 @@ interface IOptions {
cdn?: string;
/** tab 键操作字符串,支持 \t 及任意字符串 */
tab?: string;
/** 是否展现大纲。默认值:'false' */
outline?: boolean;

/** @link https://ld246.com/article/1549638745630#options-outline */
outline?: {
enable: boolean,
position: "left" | "right",
};
/** 编辑器异步渲染完成后的回调方法 */
after?(): void;

Expand Down

0 comments on commit 35cb610

Please sign in to comment.