Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Commit 802ca0f

Browse files
committed
Fix dynamic slot not interactable
- Fixes #2 by internally listening on @drawfinish
1 parent 6508ddd commit 802ca0f

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-annotator",
3-
"version": "0.12.0",
3+
"version": "0.12.1",
44
"description": "Vue Component for drawing annotation (box, etc)",
55
"homepage": "http://vue-annotator.surge.sh",
66
"repository": "github:DrSensor/vue-annotator",
@@ -50,10 +50,10 @@
5050
"surge": "^0.19.0"
5151
},
5252
"peerDependencies": {
53-
"svg.js": "^2.6.3"
53+
"svg.js": "^2.6.4"
5454
},
5555
"dependencies": {
56-
"interactjs": "^1.3.2",
56+
"interactjs": "^1.3.3",
5757
"svg.draw.js": "^2.0.3",
5858
"svg.select.js": "^2.1.2"
5959
}

src/components/Annotator.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ export default {
7373
7474
updated () {
7575
this.w = parseInt(this.width) || this.$refs.bg.scrollWidth
76-
this.h = parseInt(this.width) || this.$refs.bg.scrollHeight
76+
this.h = parseInt(this.height) || this.$refs.bg.scrollHeight
7777
},
7878
7979
beforeMount () {
8080
if (this.$slots.default) {
8181
const media = this.$slots.default.filter(el => ['img', 'video', 'audio', 'picture'].includes(el.tag))
8282
const interval = setInterval(() => {
8383
const loadComplete = media.every(el => el.elm.complete)
84-
if (loadComplete) {
84+
if (loadComplete && this.$refs.annotations) {
8585
clearInterval(interval)
8686
this.$forceUpdate()
8787
}
@@ -92,7 +92,6 @@ export default {
9292
mounted () {
9393
this.background = SVG.adopt(this.$refs.bgSvg)
9494
this.annotations = SVG.adopt(this.$refs.annotations)
95-
9695
this.enableInteraction(!this.noInteract)
9796
this.enableSelection(!this.noSelect)
9897
this.enableDrawing(this.drawing)

src/mixins/manipulate.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,23 @@ export default {
118118
} else this.interactables[id] = this.makeInteractable(node)
119119
})
120120
}
121+
},
122+
123+
$_onUpdate (isDrawing) {
124+
if ((this.$refs.annotations.hasChildNodes() ? this.$refs.annotations.childNodes.length : 0) > this.interactables.length) {
125+
const element = this.$refs.annotations.childNodes[this.$refs.annotations.childNodes.length - 1]
126+
const interaction = this.makeInteractable(element, isDrawing)
127+
this.interactables.push(interaction)
128+
}
121129
}
122130
},
123131

132+
mounted () {
133+
this.$on('drawfinish', () => this.$_onUpdate(false))
134+
},
135+
124136
updated () {
125-
if ((this.$refs.annotations.hasChildNodes() ? this.$refs.annotations.childNodes.length : 0) > this.interactables.length) {
126-
const element = this.$refs.annotations.childNodes[this.$refs.annotations.childNodes.length - 1]
127-
const interaction = this.makeInteractable(element, true)
128-
this.interactables.push(interaction)
129-
}
137+
this.$_onUpdate(this.drawing)
130138
},
131139

132140
computed: {

src/stories/Interact and Manipulate/Select.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
<div id="annotation">
33
<pre>Try to open <b>Action Logger</b> panel</pre>
44
<pre>and also Vue-devtools > Events</pre>
5+
<button @click="onAdd">Add rectangle</button>
56
<annotations :minSize="minSize" width="600" height="600" :grid="grid" :inertia="inertia" :multipleSelect="multipleSelect"
67
@select="selected" @unselect="unselect">
8+
<img draggable="false" src="https://cdn.css-tricks.com/wp-content/uploads/2017/01/vue-2-1.jpg" />
79
<polygon ref="myAnnotation" class="stroke" slot="annotation" points="200,10 250,190 160,210" />
8-
<rect class="stroke" slot="annotation" x="300" y="150" width="170" height="100" />
10+
<template slot="annotation" v-for="(offset, key) in offsetList">
11+
<rect class="stroke" :x="300+offset" :y="150+offset" width="170" height="100" :key="key" />
12+
</template>
913
</annotations>
1014
</div>
1115
</template>
@@ -22,7 +26,8 @@ export default {
2226
minSize: number('minimum diameter', 50),
2327
grid: [number('gird width', 0), number('gird height', 0)],
2428
inertia: boolean('enable inertia', true),
25-
multipleSelect: boolean('enable multiple select', false)
29+
multipleSelect: boolean('enable multiple select', false),
30+
offsetList: [10,20,30]
2631
}
2732
},
2833
components: {
@@ -44,6 +49,11 @@ export default {
4449
4550
unselect (element) {
4651
this.$action('unselect', `<${element.type}>`)
52+
},
53+
54+
onAdd () {
55+
const lastOffset = this.offsetList[this.offsetList.length - 1]
56+
this.offsetList.push(lastOffset+10)
4757
}
4858
}
4959
}

0 commit comments

Comments
 (0)