Skip to content
Snippets Groups Projects
Commit a9960ac6 authored by syuilo's avatar syuilo
Browse files

refactor(client): use composition api

parent 2a4f2fba
No related branches found
No related tags found
No related merge requests found
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent, onMounted, PropType, ref } from 'vue'; import { onMounted, ref } from 'vue';
import * as misskey from 'misskey-js'; import * as misskey from 'misskey-js';
import PhotoSwipeLightbox from 'photoswipe/dist/photoswipe-lightbox.esm.js'; import PhotoSwipeLightbox from 'photoswipe/dist/photoswipe-lightbox.esm.js';
import PhotoSwipe from 'photoswipe/dist/photoswipe.esm.js'; import PhotoSwipe from 'photoswipe/dist/photoswipe.esm.js';
...@@ -25,98 +25,80 @@ import * as os from '@/os'; ...@@ -25,98 +25,80 @@ import * as os from '@/os';
import { FILE_TYPE_BROWSERSAFE } from '@/const'; import { FILE_TYPE_BROWSERSAFE } from '@/const';
import { defaultStore } from '@/store'; import { defaultStore } from '@/store';
export default defineComponent({ const props = defineProps<{
components: { mediaList: misskey.entities.DriveFile[];
XBanner, raw?: boolean;
XImage, }>();
XVideo,
}, const gallery = ref(null);
props: { const pswpZIndex = os.claimZIndex('middle');
mediaList: {
type: Array as PropType<misskey.entities.DriveFile[]>, onMounted(() => {
required: true, const lightbox = new PhotoSwipeLightbox({
}, dataSource: props.mediaList
raw: { .filter(media => {
default: false if (media.type === 'image/svg+xml') return true; // svgのwebpublicはpngなのでtrue
}, return media.type.startsWith('image') && FILE_TYPE_BROWSERSAFE.includes(media.type);
}, })
setup(props) { .map(media => {
const gallery = ref(null); const item = {
src: media.url,
onMounted(() => { w: media.properties.width,
const lightbox = new PhotoSwipeLightbox({ h: media.properties.height,
dataSource: props.mediaList alt: media.name,
.filter(media => { };
if (media.type === 'image/svg+xml') return true; // svgのwebpublicはpngなのでtrue if (media.properties.orientation != null && media.properties.orientation >= 5) {
return media.type.startsWith('image') && FILE_TYPE_BROWSERSAFE.includes(media.type); [item.w, item.h] = [item.h, item.w];
})
.map(media => {
const item = {
src: media.url,
w: media.properties.width,
h: media.properties.height,
alt: media.name,
};
if (media.properties.orientation != null && media.properties.orientation >= 5) {
[item.w, item.h] = [item.h, item.w];
}
return item;
}),
gallery: gallery.value,
children: '.image',
thumbSelector: '.image',
loop: false,
padding: window.innerWidth > 500 ? {
top: 32,
bottom: 32,
left: 32,
right: 32,
} : {
top: 0,
bottom: 0,
left: 0,
right: 0,
},
imageClickAction: 'close',
tapAction: 'toggle-controls',
pswpModule: PhotoSwipe,
});
lightbox.on('itemData', (e) => {
const { itemData } = e;
// element is children
const { element } = itemData;
const id = element.dataset.id;
const file = props.mediaList.find(media => media.id === id);
itemData.src = file.url;
itemData.w = Number(file.properties.width);
itemData.h = Number(file.properties.height);
if (file.properties.orientation != null && file.properties.orientation >= 5) {
[itemData.w, itemData.h] = [itemData.h, itemData.w];
} }
itemData.msrc = file.thumbnailUrl; return item;
itemData.thumbCropped = true; }),
}); gallery: gallery.value,
children: '.image',
lightbox.init(); thumbSelector: '.image',
}); loop: false,
padding: window.innerWidth > 500 ? {
const previewable = (file: misskey.entities.DriveFile): boolean => { top: 32,
if (file.type === 'image/svg+xml') return true; // svgのwebpublic/thumbnailはpngなのでtrue bottom: 32,
// FILE_TYPE_BROWSERSAFEに適合しないものはブラウザで表示するのに不適切 left: 32,
return (file.type.startsWith('video') || file.type.startsWith('image')) && FILE_TYPE_BROWSERSAFE.includes(file.type); right: 32,
}; } : {
top: 0,
return { bottom: 0,
previewable, left: 0,
gallery, right: 0,
pswpZIndex: os.claimZIndex('middle'), },
}; imageClickAction: 'close',
}, tapAction: 'toggle-controls',
pswpModule: PhotoSwipe,
});
lightbox.on('itemData', (ev) => {
const { itemData } = ev;
// element is children
const { element } = itemData;
const id = element.dataset.id;
const file = props.mediaList.find(media => media.id === id);
itemData.src = file.url;
itemData.w = Number(file.properties.width);
itemData.h = Number(file.properties.height);
if (file.properties.orientation != null && file.properties.orientation >= 5) {
[itemData.w, itemData.h] = [itemData.h, itemData.w];
}
itemData.msrc = file.thumbnailUrl;
itemData.thumbCropped = true;
});
lightbox.init();
}); });
const previewable = (file: misskey.entities.DriveFile): boolean => {
if (file.type === 'image/svg+xml') return true; // svgのwebpublic/thumbnailはpngなのでtrue
// FILE_TYPE_BROWSERSAFEに適合しないものはブラウザで表示するのに不適切
return (file.type.startsWith('video') || file.type.startsWith('image')) && FILE_TYPE_BROWSERSAFE.includes(file.type);
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment