Skip to content

Commit

Permalink
Merge pull request #105 from XiongAmao/bug-fix
Browse files Browse the repository at this point in the history
v1.8.1
  • Loading branch information
XiongAmao authored Aug 29, 2022
2 parents 3bcd561 + b5be0d5 commit 33cf5f5
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.8.1] (29 August 2022)

- Fix(composables): `show()` accept wrong param when use in vue template. #104

## [1.8.0] (12 August 2022)

- Feat: Add `maxZoom` `zoomScale` to specify the zoom level.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ export declare const useEasyLightbox: (options: UseEasyLightboxOptions) => {
imgsRef: Ref<Img | string | (Img | string)[]>;
indexRef: Ref<number | undefined>;
visibleRef: Ref<boolean>;
show: (index?: number | undefined) => void;
show: (index?: Ref<number> | number | Event) => void;
onHide: () => void;
changeIndex: (index?: number | undefined) => void;
changeIndex: (index?: number) => void;
};
```

Expand Down
2 changes: 1 addition & 1 deletion dist/external-css/vue-easy-lightbox.common.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/external-css/vue-easy-lightbox.esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/external-css/vue-easy-lightbox.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-easy-lightbox.common.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-easy-lightbox.esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-easy-lightbox.umd.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/docs/guide/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ export declare const useEasyLightbox: (options: UseEasyLightboxOptions) => {
imgsRef: Ref<Img | string | (Img | string)[]>;
indexRef: Ref<number | undefined>;
visibleRef: Ref<boolean>;
show: (index?: number | undefined) => void;
show: (index?: Ref<number> | number | Event) => void;
onHide: () => void;
changeIndex: (index?: number | undefined) => void;
changeIndex: (index?: number) => void;
};
```

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/pt-BR/guide/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ export declare const useEasyLightbox: (options: UseEasyLightboxOptions) => {
imgsRef: Ref<Img | string | (Img | string)[]>;
indexRef: Ref<number | undefined>;
visibleRef: Ref<boolean>;
show: (index?: number | undefined) => void;
show: (index?: Ref<number> | number | Event) => void;
onHide: () => void;
changeIndex: (index?: number | undefined) => void;
changeIndex: (index?: number) => void;
};
```

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/zh/guide/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ export declare const useEasyLightbox: (options: UseEasyLightboxOptions) => {
imgsRef: Ref<Img | string | (Img | string)[]>;
indexRef: Ref<number | undefined>;
visibleRef: Ref<boolean>;
show: (index?: number | undefined) => void;
show: (index?: Ref<number> | number | Event) => void;
onHide: () => void;
changeIndex: (index?: number | undefined) => void;
changeIndex: (index?: number) => void;
};
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-easy-lightbox",
"version": "1.8.0",
"version": "1.8.1",
"description": "A Vue.js 3.0 image lightbox component with Zoom / Drag / Rotate / Switch",
"keywords": [
"vue",
Expand Down
14 changes: 11 additions & 3 deletions src/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref } from 'vue'
import { isRef, Ref, ref } from 'vue'
import type { PropsImgs } from '../types'

export interface UseEasyLightboxOptions {
Expand All @@ -24,8 +24,16 @@ export const useEasyLightbox = (
const indexRef = ref(initIndex)
const visibleRef = ref(false)

const show = (index = indexRef.value) => {
changeIndex(index)
const show = (index: Ref<number> | number | Event = indexRef.value) => {
if (typeof index === 'number') {
changeIndex(index)
} else if (isRef(index) && typeof index.value === 'number') {
changeIndex(index.value)
} else if (index instanceof Event) {
// when pass `show()` directly to `@click` in vue template
// e.g. @click="show"
changeIndex(indexRef.value)
}
visibleRef.value = true
}
const changeIndex = (index = indexRef.value) => {
Expand Down
62 changes: 62 additions & 0 deletions src/dev-entry/AppScriptSetup.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<template>
<div>
<button @click="showSingle">Show single picture.</button>
<button @click="showMultiple">Show a group of pictures.</button>
<br />
<button @click="test">test1</button>
<button @click="test2">test2</button>
<button @click="show">test show</button>

<vue-easy-lightbox
:visible="visibleRef"
:imgs="imgsRef"
:index="indexRef"
@hide="onHide"
@on-index-change="onIndexChange"
></vue-easy-lightbox>
</div>
</template>

<script lang="ts" setup>
import { isReactive, ref } from 'vue'
import { useEasyLightbox } from '../composables'
const imgList = ref([
'http://via.placeholder.com/350x150',
'http://via.placeholder.com/250x150'
])
const { visibleRef, indexRef, imgsRef, show, changeIndex, onHide } =
useEasyLightbox({
imgs: imgList.value,
initIndex: 0
})
const test = () => {
console.log(isReactive(imgList.value))
console.log(imgList.value)
show()
}
const test2 = () => {
imgList.value.push('http://via.placeholder.com/250x150')
show()
}
const showSingle = () => {
imgsRef.value = 'http://it-does-not-matter.png/'
show()
}
const showMultiple = () => {
imgsRef.value = [
'http://via.placeholder.com/350x150',
'http://via.placeholder.com/350x150'
]
changeIndex()
show()
}
const showImg = () => show()
const onIndexChange = (old: number, newN: number) => {
console.log(old, newN)
}
</script>
4 changes: 3 additions & 1 deletion src/dev-entry/AppSetup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<br />
<button @click="test">test1</button>
<button @click="test2">test2</button>
<button @click="show">test show</button>

<vue-easy-lightbox
:visible="visibleRef"
Expand Down Expand Up @@ -73,7 +74,8 @@ export default defineComponent({
onHide,
test,
test2,
onIndexChange
onIndexChange,
show
}
}
})
Expand Down

0 comments on commit 33cf5f5

Please sign in to comment.