0.0.6 • Published 3 years ago

surround-contents v0.0.6

Weekly downloads
13
License
MIT
Repository
github
Last release
3 years ago

Range.surroundContents()的加强版

用来解决原生surroundContents,无法跨边界用新节点包裹指定Range的问题。

用法:

import surroundContents from 'surround-contents'

surroundContents(getSelection().getRangeAt(0), () => {
    const span = document.createElement('span')
    span.style.background = 'red'
    return span
})

参数

参数名是否必填类型默认值描述
rangeAttrueRangenull需要处理的 Range 对象
newDomMethodfalseFunction() => document.createElement('span')创建新节点的函数,由于有跨边界的情况,每次需要创建新的节点,不能复用同一个节点
0.0.5

3 years ago

0.0.6

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago