Skip to content

Commit

Permalink
fix(editorOptions): 修复自定义控件影响渲染结果问题
Browse files Browse the repository at this point in the history
  • Loading branch information
nineya committed Dec 20, 2023
1 parent 0d2d8b8 commit 4123463
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 19 deletions.
22 changes: 21 additions & 1 deletion source/js/editor-options.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 30 additions & 18 deletions src/js/editor-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,36 @@
}

function handleCustomElement() {
let customs = new Set(customElement
.map(item => item.html)
.map(html => html.substring(0, html.indexOf(' '))))
customs.forEach(item => {
if (customElements.get(item)) {
return
}
customElements.define(item,
class extends HTMLElement {
constructor() {
super()
if (this.hasAttribute('draw')) return
this.innerText = this.outerHTML
this.style = 'display: block;background: #eee;padding: 9px;border-radius: 5px;color: #999;font-family: monospace;'
this.setAttribute('draw', true)
}
})
})
let cssText = Array.from(
new Set(customElement
.map(item => item.html)
.map(html => html.substring(0, html.indexOf(' ')))
)
).map(item => `${item} {
position: relative;
display: block;
width: 100%;
height: 48px;
overflow: hidden;
}
${item}:before {
content: '${item} 自定义元素';
position: absolute;
display: block;
background: #eee;
border-radius: 8px;
height: 48px;
padding: 10px;
width: 100%;
text-align: center;
font-family: monospace;
color: #999;
}`)
.join('\n')
const style = document.createElement('style')
style.appendChild(document.createTextNode(cssText))
document.getElementById('vditor').before(style)
}

function handleEmojiImg() {
Expand Down

0 comments on commit 4123463

Please sign in to comment.