react-carousel-query
Version:
A infinite carousel component made with react that handles the pagination for you.
87 lines (68 loc) • 1.85 kB
JavaScript
module.exports = listItem
var u = require('unist-builder')
var all = require('../all')
function listItem(h, node, parent) {
var result = all(h, node)
var head = result[0]
var loose = parent ? listLoose(parent) : listItemLoose(node)
var props = {}
var wrapped = []
var length
var index
var child
if (typeof node.checked === 'boolean') {
if (!head || head.tagName !== 'p') {
head = h(null, 'p', [])
result.unshift(head)
}
if (head.children.length > 0) {
head.children.unshift(u('text', ' '))
}
head.children.unshift(
h(null, 'input', {
type: 'checkbox',
checked: node.checked,
disabled: true
})
)
// According to github-markdown-css, this class hides bullet.
// See: <https://github.com/sindresorhus/github-markdown-css>.
props.className = ['task-list-item']
}
length = result.length
index = -1
while (++index < length) {
child = result[index]
// Add eols before nodes, except if this is a loose, first paragraph.
if (loose || index !== 0 || child.tagName !== 'p') {
wrapped.push(u('text', '\n'))
}
if (child.tagName === 'p' && !loose) {
wrapped = wrapped.concat(child.children)
} else {
wrapped.push(child)
}
}
// Add a final eol.
if (length && (loose || child.tagName !== 'p')) {
wrapped.push(u('text', '\n'))
}
return h(node, 'li', props, wrapped)
}
function listLoose(node) {
var loose = node.spread
var children = node.children
var length = children.length
var index = -1
while (!loose && ++index < length) {
loose = listItemLoose(children[index])
}
return loose
}
function listItemLoose(node) {
var spread = node.spread
return spread === undefined || spread === null
? node.children.length > 1
: spread
}