git ssb

16+

Dominic / patchbay



Tree: 814717ae9da45083790dbf4847fb7a674daeac0c

Files: 814717ae9da45083790dbf4847fb7a674daeac0c / modules_core / suggest-box.js

1033 bytesRaw
1const fs = require('fs')
2const h = require('../h')
3const onload = require('on-load')
4const { para } = require('cont')
5const Suggest = require('suggest-box')
6
7exports.gives = {
8 build_suggest_box: true,
9 css: true
10}
11
12exports.create = function (api) {
13 return {
14 build_suggest_box,
15 css: () => fs.readFileSync(__filename.replace(/js$/, 'css'), 'utf8') // NOTE css
16 }
17
18 function build_suggest_box (inputNode, asyncSuggesters, opts = {}) {
19 function suggester (inputText, cb) {
20 para(asyncSuggesters(inputText))
21 ((err, ary) => {
22 if(err) return cb(err)
23
24 var suggestions = ary.filter(Boolean).reduce((a, b) => a.concat(b), [])
25 cb(null, suggestions)
26 })
27 }
28
29 var suggestBox
30 onload(inputNode, (el) => {
31 suggestBox = Suggest(el, suggester, opts)
32 })
33
34 // HACK (mix) : onload is needed because Suggest demands a parent node.
35 // I've chosen this over forcing users to pass a callback
36 return {
37 complete: () => suggestBox.complete()
38 }
39 }
40}
41
42

Built with git-ssb-web