@dice-roller/vue 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/demo.html +17 -0
- package/dist/vue.common.js +77250 -0
- package/dist/vue.common.js.map +1 -0
- package/dist/vue.umd.js +77260 -0
- package/dist/vue.umd.js.map +1 -0
- package/dist/vue.umd.min.js +20 -0
- package/dist/vue.umd.min.js.map +1 -0
- package/package.json +48 -0
- package/src/DiceRoller.vue +118 -0
- package/src/main.js +8 -0
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dice-roller/vue",
|
|
3
|
+
"version": "0.1.8",
|
|
4
|
+
"description": "Vue.js component which allows rolling dice",
|
|
5
|
+
"main": "dist/vue.umd.js",
|
|
6
|
+
"module": "src/DiceRoller.vue",
|
|
7
|
+
"unpkg": "dist/vue.umd.min.js",
|
|
8
|
+
"browser": {
|
|
9
|
+
"./sfc": "src/DiceRoller.vue"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"serve": "vue-cli-service serve",
|
|
13
|
+
"build": "vue-cli-service build --target lib src/DiceRoller.vue",
|
|
14
|
+
"lint": "vue-cli-service lint",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/dice-roller/vue.git"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"dice",
|
|
23
|
+
"roll",
|
|
24
|
+
"vue"
|
|
25
|
+
],
|
|
26
|
+
"author": "GreenImp Media <info@greenimp.co.uk> (http://greenimp.co.uk)",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/dice-roller/vue/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/dice-roller/vue",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"rpg-dice-roller": "^4.5.0",
|
|
34
|
+
"vue": "^2.6.12"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@vue/cli-plugin-babel": "~4.5.4",
|
|
38
|
+
"@vue/cli-plugin-eslint": "~4.5.4",
|
|
39
|
+
"@vue/cli-service": "~4.5.4",
|
|
40
|
+
"@vue/eslint-config-airbnb": "^5.1.0",
|
|
41
|
+
"babel-eslint": "^10.1.0",
|
|
42
|
+
"core-js": "^3.6.5",
|
|
43
|
+
"eslint": "^7.8.1",
|
|
44
|
+
"eslint-plugin-import": "^2.22.0",
|
|
45
|
+
"eslint-plugin-vue": "^6.2.2",
|
|
46
|
+
"vue-template-compiler": "^2.6.12"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<section class="dice-roller">
|
|
3
|
+
<transition name="fade">
|
|
4
|
+
<output name="output" :for="`notation-${this.uuid}`" class="output" v-if="output">
|
|
5
|
+
{{ output }}
|
|
6
|
+
</output>
|
|
7
|
+
</transition>
|
|
8
|
+
|
|
9
|
+
<input
|
|
10
|
+
type="text"
|
|
11
|
+
name="notation"
|
|
12
|
+
:id="`notation-${this.uuid}`"
|
|
13
|
+
:placeholder="`e.g. ${this.notation || '4d6'}`"
|
|
14
|
+
v-model="notationString"
|
|
15
|
+
:class="error ? 'is-invalid' : ''"
|
|
16
|
+
@change="$emit('notation:change', $event.target.value)"
|
|
17
|
+
@keyup.enter="roll"
|
|
18
|
+
/>
|
|
19
|
+
|
|
20
|
+
<transition name="fade">
|
|
21
|
+
<span class="invalid-feedback" v-if="error">{{ error }}</span>
|
|
22
|
+
</transition>
|
|
23
|
+
|
|
24
|
+
<footer>
|
|
25
|
+
<label :for="`notation-${this.uuid}`">
|
|
26
|
+
Enter the notation and press "enter" to roll the dice!
|
|
27
|
+
</label>
|
|
28
|
+
</footer>
|
|
29
|
+
</section>
|
|
30
|
+
</template>
|
|
31
|
+
|
|
32
|
+
<script>
|
|
33
|
+
const { DiceRoll } = require('rpg-dice-roller/lib/umd/bundle.js');
|
|
34
|
+
|
|
35
|
+
let uuid = 0;
|
|
36
|
+
|
|
37
|
+
module.exports = {
|
|
38
|
+
beforeCreate() {
|
|
39
|
+
this.uuid = uuid.toString();
|
|
40
|
+
uuid += 1;
|
|
41
|
+
},
|
|
42
|
+
data() {
|
|
43
|
+
return {
|
|
44
|
+
error: null,
|
|
45
|
+
notationString: this.notation,
|
|
46
|
+
output: null,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
props: {
|
|
50
|
+
notation: {
|
|
51
|
+
type: String,
|
|
52
|
+
required: false,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
methods: {
|
|
56
|
+
roll() {
|
|
57
|
+
this.error = null;
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
this.output = this.notationString ? new DiceRoll(this.notationString) : null;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
this.output = null;
|
|
63
|
+
|
|
64
|
+
if (error.name === 'SyntaxError') {
|
|
65
|
+
this.error = `Invalid notation; ${error.message}`;
|
|
66
|
+
} else {
|
|
67
|
+
this.error = `An error has occurred: ${error.message}`;
|
|
68
|
+
}
|
|
69
|
+
} finally {
|
|
70
|
+
this.$emit('roll', this.notationString);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<style scoped>
|
|
78
|
+
.fade-enter-active,
|
|
79
|
+
.fade-leave-active {
|
|
80
|
+
transition: opacity .5s;
|
|
81
|
+
}
|
|
82
|
+
.fade-enter,
|
|
83
|
+
.fade-leave-to {
|
|
84
|
+
opacity: 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
input:invalid,
|
|
88
|
+
input.is-invalid {
|
|
89
|
+
color: #ff0000;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.invalid-feedback {
|
|
93
|
+
display: block;
|
|
94
|
+
margin: .5rem 0 0;
|
|
95
|
+
color: #ff0000;
|
|
96
|
+
font-size: .8rem;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.dice-roller {
|
|
100
|
+
margin: 1rem 0;
|
|
101
|
+
padding: 1rem 1.5rem;
|
|
102
|
+
border-radius: .4rem;
|
|
103
|
+
background-color: #f0f4f8;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.output {
|
|
107
|
+
display: block;
|
|
108
|
+
margin: 0 0 1rem;
|
|
109
|
+
padding: .5rem 1.9rem;
|
|
110
|
+
font-size: 1.5rem;
|
|
111
|
+
border-radius: .4rem;
|
|
112
|
+
background: #fff;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
footer {
|
|
116
|
+
font-size: .8rem;
|
|
117
|
+
}
|
|
118
|
+
</style>
|