Skip to content

Commit

Permalink
🎨 #217
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Mar 11, 2020
1 parent 4046c63 commit 38539b2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

### v2.3.0 / 未发布

* [217](https://github.com/Vanessa219/vditor/issues/217) ToC 添加悬浮菜单及 bug 修复 `修复缺陷`
* [216](https://github.com/Vanessa219/vditor/issues/216) subtoolbar 向下溢出 `修复缺陷`

### v2.2.19 / 2020-03-10
Expand Down
13 changes: 6 additions & 7 deletions src/assets/scss/_wysiwyg.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,30 @@
float: left;
padding-right: 4px;
margin-left: -29px;
content: 'h1';
content: 'H1';
font-size: 0.85rem;
font-weight: normal;
text-transform: uppercase;
color: var(--second-color);
}

h2:before {
content: 'h2';
content: 'H2';
}

h3:before {
content: 'h3';
content: 'H3';
}

h4:before {
content: 'h4';
content: 'H4';
}

h5:before {
content: 'h5';
content: 'H5';
}

h6:before {
content: 'h6';
content: 'H6';
}

div[data-type="link-ref-defs-block"]:before {
Expand Down
2 changes: 1 addition & 1 deletion src/ts/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ILuteRender {
Type: number,
},
}
}, entering: boolean) => [string, number];
}, entering: boolean) => [string, number];
}

interface ILute {
Expand Down
36 changes: 30 additions & 6 deletions src/ts/wysiwyg/highlightToolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ export const highlightToolbar = (vditor: IVditor) => {
disableToolbar(vditor.toolbar.elements, ["table"]);
}

// toc popover
let tocElement = hasClosestByClassName(typeElement, "vditor-toc") as HTMLElement;
if (!tocElement) {
const blockElement = hasClosestByAttribute(typeElement, "data-block", "0");
if (blockElement) {
if (blockElement.nextElementSibling?.classList.contains("vditor-toc")) {
tocElement = blockElement.nextElementSibling as HTMLElement
}
if (blockElement.previousElementSibling?.classList.contains("vditor-toc")) {
tocElement = blockElement.previousElementSibling as HTMLElement
}
}
}
if (tocElement) {
vditor.wysiwyg.popover.innerHTML = "";
const insertBefore = genInsertBefore(range, tocElement, vditor);
const insertAfter = genInsertAfter(range, tocElement, vditor);
const close = genClose(vditor.wysiwyg.popover, tocElement, vditor);
vditor.wysiwyg.popover.insertAdjacentElement("beforeend", close);
vditor.wysiwyg.popover.insertAdjacentElement("beforeend", insertBefore);
vditor.wysiwyg.popover.insertAdjacentElement("beforeend", insertAfter);
setPopoverPosition(vditor, tocElement);
}

// quote popover
const blockquoteElement = hasClosestByTag(typeElement, "BLOCKQUOTE") as HTMLTableElement;
if (blockquoteElement) {
Expand Down Expand Up @@ -414,11 +438,6 @@ export const highlightToolbar = (vditor: IVditor) => {
setPopoverPosition(vditor, tableElement);
}

// a popover
if (aElement) {
genAPopover(vditor, aElement);
}

// link ref popover
const linkRefElement = hasClosestByAttribute(typeElement, "data-type", "link-ref");
if (linkRefElement) {
Expand Down Expand Up @@ -693,8 +712,13 @@ export const highlightToolbar = (vditor: IVditor) => {
headingElement = undefined;
}

// a popover
if (aElement) {
genAPopover(vditor, aElement);
}

if (!blockquoteElement && !imgElement && !topListElement && !tableElement && !blockRenderElement && !aElement
&& !linkRefElement && !footnotesRefElement && !headingElement) {
&& !linkRefElement && !footnotesRefElement && !headingElement && !tocElement) {
vditor.wysiwyg.popover.style.display = "none";
}

Expand Down

0 comments on commit 38539b2

Please sign in to comment.