Skip to content

Commit

Permalink
🎨 fix #343
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Apr 28, 2020
1 parent e4ae1ef commit 79d9754
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@

### v3.1.20 / 2020-04-2x

* [343](https://github.com/Vanessa219/vditor/issues/343) 添加初始化大纲展现参数 `改进功能`

### v3.1.19 / 2020-04-26

* [341](https://github.com/Vanessa219/vditor/issues/341) Can not delete the image at IR mode `修复缺陷`
Expand Down Expand Up @@ -106,7 +108,7 @@
* [283](https://github.com/Vanessa219/vditor/issues/283) 添加 SetSetext 配置 `引入特性`
* [278](https://github.com/Vanessa219/vditor/issues/278) IR 细节修改 `修复缺陷`
* 文档更新
* 添加 `options.minHeight`
* 添加 `options.minHeight`, `options.outline`
* `options.counter` 修改为 `counter?: { enable: boolean; max?: number; type: "markdown" | "text"; }`
* counter 位置移动到 toolbar 上
* `options.hideToolbar` 修改为 `toolbarConfig: { hide?: boolean, pin?: boolean }`
Expand Down
1 change: 1 addition & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ if (window.innerWidth < 768) {

window.vditor = new Vditor('vditor', {
toolbar,
outline: true,
debugger: true,
typewriterMode: true,
placeholder: 'placeholder',
Expand Down
33 changes: 18 additions & 15 deletions src/ts/toolbar/Outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ import {getEventName} from "../util/compatibility";
import {renderOutline} from "../util/fixBrowserBehavior";
import {MenuItem} from "./MenuItem";

export const toggleOutline = (vditor: IVditor, btnElement: Element) => {
if (btnElement.classList.contains(Constants.CLASS_MENU_DISABLED)) {
return;
}

const outlineElement = vditor.element.querySelector(".vditor-outline") as HTMLElement;
if (btnElement.classList.contains("vditor-menu--current")) {
outlineElement.style.display = "none";
btnElement.classList.remove("vditor-menu--current");
} else {
outlineElement.style.display = "block";
renderOutline(vditor);
btnElement.classList.add("vditor-menu--current");
}
setPadding(vditor);
};

export class Outline extends MenuItem {
constructor(vditor: IVditor, menuItem: IMenuItem) {
super(vditor, menuItem);
this.element.children[0].addEventListener(getEventName(), (event) => {
event.preventDefault();
const btnElement = this.element.firstElementChild;
if (btnElement.classList.contains(Constants.CLASS_MENU_DISABLED)) {
return;
}

const outlineElement = vditor.element.querySelector(".vditor-outline") as HTMLElement;
if (btnElement.classList.contains("vditor-menu--current")) {
outlineElement.style.display = "none";
btnElement.classList.remove("vditor-menu--current");
} else {
outlineElement.style.display = "block";
renderOutline(vditor);
btnElement.classList.add("vditor-menu--current");
}
setPadding(vditor);
toggleOutline(vditor, this.element.firstElementChild);
});
}
}
4 changes: 4 additions & 0 deletions src/ts/ui/initUI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {i18n} from "../i18n";
import {html2md} from "../sv/html2md";
import {setEditMode} from "../toolbar/EditMode";
import {toggleOutline} from "../toolbar/Outline";
import {setContentTheme} from "./setContentTheme";
import {setTheme} from "./setTheme";

Expand Down Expand Up @@ -75,6 +76,9 @@ export const initUI = (vditor: IVditor) => {
}

setEditMode(vditor, vditor.options.mode, afterRender(vditor, contentElement));
if (vditor.options.outline && vditor.toolbar.elements.outline) {
toggleOutline(vditor, vditor.toolbar.elements.outline.firstElementChild);
}
};

export const setPadding = (vditor: IVditor) => {
Expand Down
1 change: 1 addition & 0 deletions src/ts/util/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class Options {
},
lang: "zh_CN",
mode: "wysiwyg",
outline: false,
placeholder: "",
preview: {
delay: 1000,
Expand Down
9 changes: 7 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,9 @@ interface IOptions {
value?: string;
/** 是否显示日志。默认值: false */
debugger?: boolean;
/** 编辑器异步渲染完成后的回调方法 */
after?: () => void;
/** 是否启用打字机模式。默认值: false */
typewriterMode?: boolean;
/** @link https://hacpai.com/article/1549638745630#options-keymap */
keymap?: { [key: string]: string };
/** 编辑器总高度。默认值: 'auto' */
height?: number | string;
Expand All @@ -327,6 +326,7 @@ interface IOptions {
lang?: (keyof II18nLang);
/** @link https://hacpai.com/article/1549638745630#options-toolbar */
toolbar?: Array<string | IMenuItem>;
/** @link https://hacpai.com/article/1549638745630#options-resize */
resize?: IResize;
/** @link https://hacpai.com/article/1549638745630#options-counter */
counter?: {
Expand Down Expand Up @@ -354,11 +354,16 @@ interface IOptions {
theme?: "classic" | "dark";
/** @link https://hacpai.com/article/1549638745630#options-upload */
upload?: IUpload;
/** @link https://hacpai.com/article/1549638745630#options-classes */
classes?: IClasses;
/** 配置自建 CDN 地址。默认值: 'https://cdn.jsdelivr.net/npm/vditor@${VDITOR_VERSION}' */
cdn?: string;
/** tab 键操作字符串,支持 \t 及任意字符串 */
tab?: string;
/** 是否展现大纲。默认值:'false' */
outline?: boolean;
/** 编辑器异步渲染完成后的回调方法 */
after?(): void;

/** 输入后触发 */
input?(value: string, previewElement?: HTMLElement): void;
Expand Down

0 comments on commit 79d9754

Please sign in to comment.