22 **
33 */
44import * as UI from 'solid-ui'
5+ import { solidLogicSingleton } from 'solid-logic'
56
67import makeBSS from '@solid/better-simple-slideshow'
78const ns = UI . ns
9+ let slideshowId = 0
10+
11+ function isImageResource ( file , store ) {
12+ if ( UI . widgets . isImage ( file ) ) return true
13+
14+ const contentTypes = store . fetcher . getHeader ( file , 'content-type' ) || [ ]
15+ return contentTypes . some ( contentType => contentType . toLowerCase ( ) . startsWith ( 'image/' ) )
16+ }
817
918export const slideshowPane = {
1019 icon : UI . icons . iconBase + 'noun_138712.svg' ,
@@ -16,13 +25,11 @@ export const slideshowPane = {
1625 // Does the subject deserve an slideshow pane?
1726 label : function ( subject , context ) {
1827 const store = context . session . store
19- const ns = UI . ns
20- const t = store . findTypeURIs ( subject )
21- if ( t [ ns . ldp ( 'Container' ) . uri ] || t [ ns . ldp ( 'BasicContainer' ) . uri ] ) {
28+ if ( solidLogicSingleton . resource . isContainer ( subject ) ) {
2229 const contents = store . each ( subject , ns . ldp ( 'contains' ) )
2330 let count = 0
2431 contents . forEach ( function ( file ) {
25- if ( UI . widgets . isImage ( file ) ) count ++
32+ if ( isImageResource ( file , store ) ) count ++
2633 } )
2734 return count > 0 ? 'Slideshow' : null
2835 }
@@ -40,18 +47,21 @@ export const slideshowPane = {
4047 const store = context . session . store
4148 const ns = UI . ns
4249 const div = dom . createElement ( 'div' )
50+ const id = `slideshow-${ ++ slideshowId } `
51+ div . id = id
4352 div . setAttribute ( 'class' , 'bss-slides' )
4453
45- const t = store . findTypeURIs ( subject )
4654 let predicate
47- if ( t [ ns . ldp ( 'BasicContainer' ) . uri ] || t [ ns . ldp ( 'Container' ) . uri ] ) {
55+ if ( solidLogicSingleton . resource . isContainer ( subject ) ) {
4856 predicate = ns . ldp ( 'contains' )
4957 }
50- const images = store . each ( subject , predicate ) // @@ random order?
58+ const images = [ ...new Map (
59+ store . each ( subject , predicate ) . map ( image => [ image . uri , image ] )
60+ ) . values ( ) ]
5161 // @@ Ideally: sort by embedded time of image
52- images . sort ( ) // Sort for now by URI
62+ images . sort ( ( left , right ) => left . uri . localeCompare ( right . uri ) )
5363 for ( let i = 0 ; i < images . length ; i ++ ) {
54- if ( ! UI . widgets . isImage ( images [ i ] ) ) continue
64+ if ( ! isImageResource ( images [ i ] , store ) ) continue
5565 const figure = div . appendChild ( dom . createElement ( 'figure' ) )
5666 const img = figure . appendChild ( dom . createElement ( 'img' ) )
5767
@@ -69,9 +79,9 @@ export const slideshowPane = {
6979 }
7080 const options = { dom }
7181
72- setTimeout ( function ( ) {
73- makeBSS ( '.bss-slides' , options )
74- } , 1000 ) // Must run after the code which called this
82+ dom . defaultView . requestAnimationFrame ( function ( ) {
83+ makeBSS ( `# ${ id } ` , options )
84+ } )
7585
7686 return div
7787 }
0 commit comments