Files: c6808ebda95764b1cdd2b287584c051d8901fb42 / book / html / images.js
710 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Set, map, forEach, when } = require('mutant') |
3 | |
4 | exports.needs = nest({ |
5 | 'blob.sync.url': 'first', |
6 | 'blob.html.input': 'first' |
7 | }) |
8 | |
9 | exports.gives = nest('book.html.images') |
10 | |
11 | exports.create = (api) => { |
12 | return nest('book.html.images', images) |
13 | function images ({images, isEditing, onUpdate}) { |
14 | const allImages = Set([]) |
15 | images(images => forEach(images, image => allImages.add(image))) |
16 | |
17 | const fileInput = api.blob.html.input(file => { |
18 | onUpdate(file) |
19 | }) |
20 | |
21 | return h('section.images', {}, [ |
22 | map(allImages, image => h('img', {src: api.blob.sync.url(image.link)})), |
23 | when(isEditing, [h('div', 'Add an image:'), fileInput]) |
24 | ]) |
25 | } |
26 | } |
27 |
Built with git-ssb-web