Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MopTym committed Oct 20, 2016
1 parent e33e920 commit bb16cf5
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 67 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

A waterfall layout component for Vue.js .

Branch [0.x (version 0.x.x)](https://github.com/MopTym/vue-waterfall/tree/0.x) is compatible with Vue 1 .

## Demo

- [Vertical line](http://app.moptym.com/vue-waterfall/demo/vertical-line.html)
Expand Down Expand Up @@ -187,7 +189,12 @@ new Vue({
<tr>
<td>order</td>
<td><code>0</code></td>
<td>The order of slot, often be set to <code>$index</code> in <code>v-for</code> .</td>
<td>The order of slot, often be set to <code>index</code> in <code>v-for</code> .</td>
</tr>
<tr>
<td>key</td>
<td><code>''</code></td>
<td>The unique identification of slot, required for transition.</td>
</tr>
<tr>
<td>move-class</td>
Expand All @@ -201,23 +208,28 @@ new Vue({

Inspired by [vue-animated-list](https://github.com/vuejs/vue-animated-list) , vue-waterfall supports moving elements with `translate` in transition, click on the [demo](http://app.moptym.com/vue-waterfall/demo/vertical-line.html) page to see it.

vue-waterfall has not supported `<transition-group>` in Vue 2 ( [#10](https://github.com/MopTym/vue-waterfall/issues/10) ) .

![preview](shuffle.gif)

## Events

```js
ON ( 'wf-reflow' ) { /* use 'wf-reflow' event to trigger reflow action */
ON ( 'reflow' ) {
reflow
}
// trigger reflow action: waterfallVm.$emit('reflow')
```

```js
AFTER ( reflow ) {
broadcast 'wf-reflowed'
dispatch 'wf-reflowed'
emit 'reflowed'
}
// waterfallVm.$on('reflowed', () => { console.log('reflowed') })
```

To

## Reactivity

```js
Expand Down
18 changes: 9 additions & 9 deletions demo/horizontal-line.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@
:min-line-gap="180"
:max-line-gap="220"
:watch="items"
@reflowed="reflowed"
ref="waterfall"
>
<!-- each component is wrapped by a waterfall slot -->
<waterfall-slot
v-for="item in items"
v-for="(item, index) in items"
:width="item.width"
:height="item.height"
:order="$index"
:order="index"
:key="item.index"
move-class="item-move"
transition="wf"
>
<div class="item" :style="item.style" :index="item.index"></div>
</waterfall-slot>
</waterfall>
</div>
<script src="https://cdn.jsdelivr.net/vue/1.0.25/vue.js"></script>
<script src="https://cdn.jsdelivr.net/vue/2.0.3/vue.min.js"></script>
<script src="http://app.moptym.com/cdn/vue-waterfall/vue-waterfall.min.js"></script>
<script src="./common/js/item-factory.js"></script>
<script>
Expand All @@ -63,18 +65,16 @@
this.items.sort(function () {
return Math.random() - 0.5
})
}
},
events: {
'wf-reflowed': function () {
},
reflowed: function () {
this.isBusy = false
}
}
})

document.body.addEventListener('click', function () {
app.shuffle()
// app.$broadcast('wf-reflow') // manually trigger reflow action
// app.$refs.waterfall.$emit('reflow') // manually trigger reflow action
}, false)

window.addEventListener('scroll', function () {
Expand Down
18 changes: 9 additions & 9 deletions demo/vertical-line.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@
:max-line-gap="220"
:single-max-width="300"
:watch="items"
@reflowed="reflowed"
ref="waterfall"
>
<!-- each component is wrapped by a waterfall slot -->
<waterfall-slot
v-for="item in items"
v-for="(item, index) in items"
:width="item.width"
:height="item.height"
:order="$index"
:order="index"
:key="item.index"
move-class="item-move"
transition="wf"
>
<div class="item" :style="item.style" :index="item.index"></div>
</waterfall-slot>
</waterfall>
</div>
<script src="https://cdn.jsdelivr.net/vue/1.0.25/vue.js"></script>
<script src="https://cdn.jsdelivr.net/vue/2.0.3/vue.min.js"></script>
<script src="http://app.moptym.com/cdn/vue-waterfall/vue-waterfall.min.js"></script>
<script src="./common/js/item-factory.js"></script>
<script>
Expand All @@ -64,18 +66,16 @@
this.items.sort(function () {
return Math.random() - 0.5
})
}
},
events: {
'wf-reflowed': function () {
},
reflowed: function () {
this.isBusy = false
}
}
})

document.body.addEventListener('click', function () {
app.shuffle()
// app.$broadcast('wf-reflow') // manually trigger reflow action
// app.$refs.waterfall.$emit('reflow') // manually trigger reflow action
}, false)

window.addEventListener('scroll', function () {
Expand Down
4 changes: 2 additions & 2 deletions lib/vue-waterfall.min.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions lib/waterfall-slot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default {
},
methods: {
notify () {
this.$dispatch('wf-reflow', [this])
this.$parent.$emit('reflow', this)
},
getMeta () {
return {
Expand All @@ -50,20 +50,22 @@ export default {
}
}
},
compiled () {
this.$watch('width, height', this.notify)
this.$once('wf-reflowed', () => this.isShow = true)
created () {
this.rect = {
top: 0,
left: 0,
width: 0,
height: 0
}
this.$watch('width, height', this.notify)
},
attached () {
mounted () {
this.$parent.$once('reflowed', () => {
this.isShow = true
})
this.notify()
},
detached () {
destroyed () {
this.notify()
}
}
Expand Down
26 changes: 13 additions & 13 deletions lib/waterfall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export default {
},
watch: {
default: {}
},
emitter: {
default: {}
}
},
data: () => ({
Expand All @@ -69,20 +72,15 @@ export default {
}
}),
methods: {
autoResizeHandler: autoResizeHandler,
reflowHandler: getReflowHandler(),
reflow: reflow
},
events: {
'wf-reflow': function () {
this.reflowHandler()
}
autoResizeHandler,
reflow
},
compiled () {
created () {
this.virtualRects = []
},
ready () {
this.autoResizeHandler()
this.$on('reflow', () => {
this.reflowHandler()
})
this.$watch('autoResize', this.autoResizeHandler)
this.$watch(() => (
this.align,
Expand All @@ -94,7 +92,10 @@ export default {
this.fixedHeight,
this.watch
), this.reflowHandler)
},
mounted () {
on(this.$el, transitionEndEvent, tidyUpAnimations, true)
this.autoResizeHandler(this.autoResize)
},
beforeDestroy () {
this.autoResizeHandler(false)
Expand Down Expand Up @@ -138,8 +139,7 @@ function reflow () {
}
this.style.overflow = 'hidden'
render(this.virtualRects, metas)
this.$broadcast('wf-reflowed', [this])
this.$dispatch('wf-reflowed', [this])
this.$emit('reflowed', this)
}, 0)
}
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-waterfall",
"version": "0.2.3",
"version": "1.0.0",
"description": "A waterfall layout component for Vue.js",
"main": "lib/vue-waterfall.min.js",
"files": [
Expand Down Expand Up @@ -32,11 +32,9 @@
"babel-plugin-transform-runtime": "^6.5.2",
"babel-preset-es2015": "^6.3.13",
"babel-runtime": "^5.8.35",
"copy-webpack-plugin": "^1.1.1",
"copy-webpack-plugin": "^3.0.1",
"css-loader": "^0.23.1",
"vue-html-loader": "^1.1.0",
"vue-loader": "^8.1.1",
"vue-style-loader": "^1.0.0",
"vue-loader": "^9.5.1",
"webpack": "^1.12.13"
}
}
14 changes: 8 additions & 6 deletions src/waterfall-slot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default {
},
methods: {
notify () {
this.$dispatch('wf-reflow', [this])
this.$parent.$emit('reflow', this)
},
getMeta () {
return {
Expand All @@ -50,20 +50,22 @@ export default {
}
}
},
compiled () {
this.$watch('width, height', this.notify)
this.$once('wf-reflowed', () => this.isShow = true)
created () {
this.rect = {
top: 0,
left: 0,
width: 0,
height: 0
}
this.$watch('width, height', this.notify)
},
attached () {
mounted () {
this.$parent.$once('reflowed', () => {
this.isShow = true
})
this.notify()
},
detached () {
destroyed () {
this.notify()
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/waterfall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export default {
},
watch: {
default: {}
},
emitter: {
default: {}
}
},
data: () => ({
Expand All @@ -69,20 +72,15 @@ export default {
}
}),
methods: {
autoResizeHandler: autoResizeHandler,
reflowHandler: getReflowHandler(),
reflow: reflow
},
events: {
'wf-reflow': function () {
this.reflowHandler()
}
autoResizeHandler,
reflow
},
compiled () {
created () {
this.virtualRects = []
},
ready () {
this.autoResizeHandler()
this.$on('reflow', () => {
this.reflowHandler()
})
this.$watch('autoResize', this.autoResizeHandler)
this.$watch(() => (
this.align,
Expand All @@ -94,7 +92,10 @@ export default {
this.fixedHeight,
this.watch
), this.reflowHandler)
},
mounted () {
on(this.$el, transitionEndEvent, tidyUpAnimations, true)
this.autoResizeHandler(this.autoResize)
},
beforeDestroy () {
this.autoResizeHandler(false)
Expand Down Expand Up @@ -138,8 +139,7 @@ function reflow () {
}
this.style.overflow = 'hidden'
render(this.virtualRects, metas)
this.$broadcast('wf-reflowed', [this])
this.$dispatch('wf-reflowed', [this])
this.$emit('reflowed', this)
}, 0)
}
Expand Down

0 comments on commit bb16cf5

Please sign in to comment.