@tak-ps/vue-tabler 3.2.0 → 3.4.0
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/CHANGELOG.md +8 -0
- package/components/Epoch.vue +35 -1
- package/components/EpochRange.vue +66 -8
- package/components/Help.vue +50 -0
- package/components/Input.vue +42 -21
- package/components/Schema.vue +128 -0
- package/lib.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,14 @@
|
|
|
10
10
|
|
|
11
11
|
## Version History
|
|
12
12
|
|
|
13
|
+
### v3.4.0
|
|
14
|
+
|
|
15
|
+
- :rocket: Add `TablerSchema` component for creating forms from basic JSON Schemas
|
|
16
|
+
|
|
17
|
+
### v3.3.0
|
|
18
|
+
|
|
19
|
+
- :rocket: Add `Human` mode (and make it the default) to `Epoch` and `EpochRange`
|
|
20
|
+
|
|
13
21
|
### v3.2.0
|
|
14
22
|
|
|
15
23
|
- :rocket: Add `required` Property to labelled components
|
package/components/Epoch.vue
CHANGED
|
@@ -12,16 +12,50 @@ export default {
|
|
|
12
12
|
},
|
|
13
13
|
format: {
|
|
14
14
|
type: String,
|
|
15
|
-
default: '
|
|
15
|
+
default: 'Human'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
data: function() {
|
|
19
|
+
return {
|
|
20
|
+
suffix: {
|
|
21
|
+
1: 'st',
|
|
22
|
+
2: 'nd',
|
|
23
|
+
3: 'rd'
|
|
24
|
+
},
|
|
25
|
+
months: [
|
|
26
|
+
'January',
|
|
27
|
+
'February',
|
|
28
|
+
'March',
|
|
29
|
+
'April',
|
|
30
|
+
'May',
|
|
31
|
+
'June',
|
|
32
|
+
'July',
|
|
33
|
+
'August',
|
|
34
|
+
'September',
|
|
35
|
+
'October',
|
|
36
|
+
'November',
|
|
37
|
+
'December'
|
|
38
|
+
]
|
|
16
39
|
}
|
|
17
40
|
},
|
|
18
41
|
computed: {
|
|
19
42
|
display: function() {
|
|
20
43
|
const date = new Date(this.date)
|
|
44
|
+
|
|
21
45
|
if (this.format === 'ISO') {
|
|
22
46
|
return date.toISOString()
|
|
23
47
|
.replace('T', ' ')
|
|
24
48
|
.replace(/:[0-9]+\.[0-9]+[A-Z]/, '');
|
|
49
|
+
} else if (this.format === 'Human') {
|
|
50
|
+
const day = String(date.getUTCDate());
|
|
51
|
+
const suffix = this.suffix[day.slice(day.length - 1)] || 'th';
|
|
52
|
+
|
|
53
|
+
const res = `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padEnd(2, '0')}, ${this.months[date.getUTCMonth()]} ${date.getUTCDate()}${suffix}`;
|
|
54
|
+
if (date.getFullYear() === new Date().getFullYear()) {
|
|
55
|
+
return res;
|
|
56
|
+
} else {
|
|
57
|
+
return res + `, ${date.getFullYear()}`;
|
|
58
|
+
}
|
|
25
59
|
} else {
|
|
26
60
|
return date.toString();
|
|
27
61
|
}
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
export default {
|
|
7
7
|
name: 'EpochRange',
|
|
8
8
|
props: {
|
|
9
|
+
format: {
|
|
10
|
+
type: String,
|
|
11
|
+
default: 'Human'
|
|
12
|
+
},
|
|
9
13
|
start: {
|
|
10
14
|
type: Number,
|
|
11
15
|
required: true
|
|
@@ -15,17 +19,71 @@ export default {
|
|
|
15
19
|
required: true
|
|
16
20
|
},
|
|
17
21
|
},
|
|
22
|
+
data: function() {
|
|
23
|
+
return {
|
|
24
|
+
suffix: {
|
|
25
|
+
1: 'st',
|
|
26
|
+
2: 'nd',
|
|
27
|
+
3: 'rd'
|
|
28
|
+
},
|
|
29
|
+
months: [
|
|
30
|
+
'January',
|
|
31
|
+
'February',
|
|
32
|
+
'March',
|
|
33
|
+
'April',
|
|
34
|
+
'May',
|
|
35
|
+
'June',
|
|
36
|
+
'July',
|
|
37
|
+
'August',
|
|
38
|
+
'September',
|
|
39
|
+
'October',
|
|
40
|
+
'November',
|
|
41
|
+
'December'
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
18
45
|
computed: {
|
|
19
46
|
display: function() {
|
|
20
|
-
|
|
21
|
-
|
|
47
|
+
if (this.format === 'ISO') {
|
|
48
|
+
const start = new Date(this.start)
|
|
49
|
+
const end = new Date(this.end)
|
|
50
|
+
|
|
51
|
+
const start_dt = start.toISOString().replace(/[A-Z].*/, '');
|
|
52
|
+
const end_dt = end.toISOString().replace(/[A-Z].*/, '');
|
|
53
|
+
if (start_dt === end_dt) {
|
|
54
|
+
return `${start.toISOString().replace(/[A-Z]/, ' ').replace(/:[0-9]+\.[0-9]+[A-Z]/, '')} - ${end.toISOString().replace(/^.*?[A-Z]/, '').replace(/:[0-9]+\.[0-9]+[A-Z]/, '')}`;
|
|
55
|
+
} else {
|
|
56
|
+
return `${start.toISOString().replace(/[A-Z]/, ' ').replace(/:[0-9]+\.[0-9]+[A-Z]/, '')} - ${end.toISOString().replace(/[A-Z]/, ' ').replace(/:[0-9]+\.[0-9]+[A-Z]/, '')}`;
|
|
57
|
+
}
|
|
58
|
+
} else if (this.format === 'Human') {
|
|
59
|
+
const start = new Date(this.start)
|
|
60
|
+
const end = new Date(this.end)
|
|
61
|
+
|
|
62
|
+
const start_day = String(start.getUTCDate());
|
|
63
|
+
const start_day_suffix = this.suffix[start_day.slice(start_day.length - 1)] || 'th';
|
|
64
|
+
const end_day = String(end.getUTCDate());
|
|
65
|
+
const end_day_suffix = this.suffix[end_day.slice(end_day.length - 1)] || 'th';
|
|
66
|
+
|
|
67
|
+
const start_month = `${this.months[start.getUTCMonth()]} ${start.getUTCDate()}${start_day_suffix}`;
|
|
68
|
+
const end_month = `${this.months[end.getUTCMonth()]} ${end.getUTCDate()}${end_day_suffix}`;
|
|
69
|
+
const start_time = `${String(start.getHours()).padStart(2, '0')}:${String(start.getMinutes()).padEnd(2, '0')}`;
|
|
70
|
+
const end_time = `${String(end.getHours()).padStart(2, '0')}:${String(end.getMinutes()).padEnd(2, '0')}`;
|
|
22
71
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
72
|
+
if (start.getFullYear() === end.getFullYear() && start.getFullYear() === new Date().getFullYear()) {
|
|
73
|
+
if (start.getUTCMonth() === end.getUTCMonth() && start.getUTCDate() === end.getUTCDate()) {
|
|
74
|
+
return `${start_month} ${start_time} - ${end_time}`;
|
|
75
|
+
} else {
|
|
76
|
+
return `${start_month} ${start_time} - ${end_month} ${end_time}`;
|
|
77
|
+
}
|
|
78
|
+
} else if (start.getFullYear() === end.getFullYear()) {
|
|
79
|
+
if (start.getUTCMonth() === end.getUTCMonth() && start.getUTCDate() === end.getUTCDate()) {
|
|
80
|
+
return `${start_month}, ${start.getFullYear()} ${start_time} - ${end_time}`;
|
|
81
|
+
} else {
|
|
82
|
+
return `${start_month}, ${start.getFullYear()} ${start_time} - ${end_month} ${end_time}`;
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
return `${start_month} ${start.getFullYear()}, ${start_time} - ${end_month} ${end.getFullYear()}, ${end_time}`;
|
|
86
|
+
}
|
|
29
87
|
}
|
|
30
88
|
}
|
|
31
89
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Modal>
|
|
3
|
+
<button type="button" class="btn-close" @click='close' aria-label="Close"></button>
|
|
4
|
+
<div class="modal-status bg-yellow"></div>
|
|
5
|
+
<div class="modal-header d-flex">
|
|
6
|
+
<span class='modal-title' v-text='label'></span>
|
|
7
|
+
</div>
|
|
8
|
+
<div class="modal-body text-center py-4">
|
|
9
|
+
<div class="text-muted" v-text='description'></div>
|
|
10
|
+
</div>
|
|
11
|
+
<div class="modal-footer">
|
|
12
|
+
<div class="w-100">
|
|
13
|
+
<div class="row">
|
|
14
|
+
<div class="col"><a @click='close' class="cursor-pointer btn w-100">OK</a></div>
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
</Modal>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script>
|
|
22
|
+
import Modal from './Modal.vue';
|
|
23
|
+
import {
|
|
24
|
+
InfoSquareIcon
|
|
25
|
+
} from 'vue-tabler-icons'
|
|
26
|
+
|
|
27
|
+
export default {
|
|
28
|
+
name: 'TablerHelp',
|
|
29
|
+
props: {
|
|
30
|
+
label: {
|
|
31
|
+
type: String,
|
|
32
|
+
require: false,
|
|
33
|
+
default: 'Help'
|
|
34
|
+
},
|
|
35
|
+
description: {
|
|
36
|
+
type: String,
|
|
37
|
+
require: true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
methods: {
|
|
41
|
+
close: function() {
|
|
42
|
+
this.$emit('close');
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
components: {
|
|
46
|
+
Modal,
|
|
47
|
+
InfoSquareIcon
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
</script>
|
package/components/Input.vue
CHANGED
|
@@ -1,29 +1,41 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<
|
|
4
|
-
v-if='
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
</
|
|
17
|
-
<
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
<div class='row'>
|
|
3
|
+
<div class='col-12 d-flex'>
|
|
4
|
+
<span v-if='description' style='margin-right: 4px;'>
|
|
5
|
+
<InfoSquareIcon @click='help = true' size='20' class='cursor-pointer'/>
|
|
6
|
+
<Help v-if='help' @click='help = false' :label='label || placeholder' :description='description'/>
|
|
7
|
+
</span>
|
|
8
|
+
<label
|
|
9
|
+
v-if='label'
|
|
10
|
+
class="form-label"
|
|
11
|
+
v-text='label'
|
|
12
|
+
:class='{
|
|
13
|
+
"required": required
|
|
14
|
+
}'
|
|
15
|
+
></label>
|
|
16
|
+
</div>
|
|
17
|
+
<div class='col-12'>
|
|
18
|
+
<template v-if='!rows || rows <= 1'>
|
|
19
|
+
<input :disabled='disabled' :value='modelValue' @input='event => current = event.target.value' :type='type' :class='{
|
|
20
|
+
"is-invalid": error
|
|
21
|
+
}' class="form-control" :placeholder='label||placeholder||""'/>
|
|
22
|
+
</template>
|
|
23
|
+
<template v-else>
|
|
24
|
+
<textarea style='white-space: pre;' :disabled='disabled' :rows='rows' :value='modelValue' @input='event => current = event.target.value' :type='type' :class='{
|
|
25
|
+
"is-invalid": error
|
|
26
|
+
}' class="form-control" :placeholder='label||placeholder||""'/>
|
|
27
|
+
</template>
|
|
28
|
+
<div v-if='error' v-text='error' class="invalid-feedback"></div>
|
|
29
|
+
</div>
|
|
23
30
|
</div>
|
|
24
31
|
</template>
|
|
25
32
|
|
|
26
33
|
<script>
|
|
34
|
+
import {
|
|
35
|
+
InfoSquareIcon
|
|
36
|
+
} from 'vue-tabler-icons';
|
|
37
|
+
import Help from './Help.vue';
|
|
38
|
+
|
|
27
39
|
export default {
|
|
28
40
|
name: 'TablerInput',
|
|
29
41
|
props: {
|
|
@@ -39,6 +51,10 @@ export default {
|
|
|
39
51
|
type: Boolean,
|
|
40
52
|
default: false,
|
|
41
53
|
},
|
|
54
|
+
description: {
|
|
55
|
+
type: String,
|
|
56
|
+
default: '',
|
|
57
|
+
},
|
|
42
58
|
rows: {
|
|
43
59
|
type: Number,
|
|
44
60
|
default: 1
|
|
@@ -53,6 +69,7 @@ export default {
|
|
|
53
69
|
},
|
|
54
70
|
data: function() {
|
|
55
71
|
return {
|
|
72
|
+
help: false,
|
|
56
73
|
current: ''
|
|
57
74
|
}
|
|
58
75
|
},
|
|
@@ -73,6 +90,10 @@ export default {
|
|
|
73
90
|
this.$emit('update:modelValue', this.current);
|
|
74
91
|
}
|
|
75
92
|
}
|
|
93
|
+
},
|
|
94
|
+
components: {
|
|
95
|
+
Help,
|
|
96
|
+
InfoSquareIcon
|
|
76
97
|
}
|
|
77
98
|
}
|
|
78
99
|
</script>
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class='px-2 py-2'>
|
|
3
|
+
<div :key='key' v-for='key in Object.keys(schema.properties)' class='py-2 floating-input'>
|
|
4
|
+
<template v-if='schema.properties[key].enum'>
|
|
5
|
+
<TablerEnum
|
|
6
|
+
:label='key'
|
|
7
|
+
:disabled='disabled'
|
|
8
|
+
v-model='data[key]'
|
|
9
|
+
:options='schema.properties[key].enum'
|
|
10
|
+
:default='schema.properties[key].default'
|
|
11
|
+
/>
|
|
12
|
+
</template>
|
|
13
|
+
<template v-else-if='schema.properties[key].type === "string"'>
|
|
14
|
+
<TablerInput :label='key' :disabled='disabled' v-model='data[key]'/>
|
|
15
|
+
</template>
|
|
16
|
+
<template v-else-if='schema.properties[key].type === "boolean"'>
|
|
17
|
+
<TablerToggle :label='key' :disabled='disabled' v-model='data[key]'/>
|
|
18
|
+
</template>
|
|
19
|
+
<template v-else-if='schema.properties[key].type === "array"'>
|
|
20
|
+
<div class='d-flex'>
|
|
21
|
+
<label class='form-label' v-text='key'/>
|
|
22
|
+
<div class='ms-auto'>
|
|
23
|
+
<PlusIcon v-if='!disabled' @click='push(key)' class='cursor-pointer'/>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
<div :key='i' v-for='(arr, i) of data[key]' class='border rounded my-2 py-2 mx-2 px-2'>
|
|
28
|
+
<div class='d-flex'>
|
|
29
|
+
<div class='mx-2 my-2'>Entry <span v-text='i + 1'/></div>
|
|
30
|
+
<div class='ms-auto mx-2 my-2'>
|
|
31
|
+
<TrashIcon v-if='!disabled' @click='data[key].splice(i, 1)' class='cursor-pointer'/>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<GenericSchema :schema='schema.properties[key].items' :disabled='disabled' v-model='data[key][i]' />
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|
|
38
|
+
<template v-else>
|
|
39
|
+
<div class='row'>
|
|
40
|
+
<TablerInput :label='key' :rows='3' :disabled='disabled' v-model='data[key]'/>
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<script>
|
|
48
|
+
import TablerInput from './Input.vue';
|
|
49
|
+
import TablerToggle from './Toggle.vue';
|
|
50
|
+
import TablerEnum from './Enum.vue';
|
|
51
|
+
import {
|
|
52
|
+
PlusIcon,
|
|
53
|
+
TrashIcon,
|
|
54
|
+
} from 'vue-tabler-icons'
|
|
55
|
+
|
|
56
|
+
export default {
|
|
57
|
+
name: 'TablerSchema',
|
|
58
|
+
props: {
|
|
59
|
+
modelValue: {
|
|
60
|
+
type: Object,
|
|
61
|
+
required: true
|
|
62
|
+
},
|
|
63
|
+
schema: {
|
|
64
|
+
type: Object,
|
|
65
|
+
required: true
|
|
66
|
+
},
|
|
67
|
+
disabled: {
|
|
68
|
+
type: Boolean,
|
|
69
|
+
default: false
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
data: function() {
|
|
73
|
+
return {
|
|
74
|
+
data: {},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
watch: {
|
|
78
|
+
data: {
|
|
79
|
+
deep: true,
|
|
80
|
+
handler: function() {
|
|
81
|
+
this.$emit('update:modelValue', this.data);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
mounted: async function() {
|
|
86
|
+
this.data = JSON.parse(JSON.stringify(this.modelValue));
|
|
87
|
+
|
|
88
|
+
for (const key of Object.keys(this.schema.properties)) {
|
|
89
|
+
if (this.schema.properties[key].display === 'table') {
|
|
90
|
+
this.edit[key] = new Map();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (this.schema.type === 'object' && this.schema.properties) {
|
|
95
|
+
for (const key in this.schema.properties) {
|
|
96
|
+
if (!this.data[key] && this.schema.properties[key].type === 'array') {
|
|
97
|
+
this.data[key] = [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
methods: {
|
|
103
|
+
remove: function(key, arr, i) {
|
|
104
|
+
this.edit[key].delete(arr);
|
|
105
|
+
this.data[key].splice(i, 1)
|
|
106
|
+
},
|
|
107
|
+
push: function(key) {
|
|
108
|
+
if (!this.schema.properties[key].items) this.data[key].push('');
|
|
109
|
+
if (this.schema.properties[key].items.type === 'object') {
|
|
110
|
+
this.data[key].push({});
|
|
111
|
+
} else if (this.schema.properties[key].items.type === 'array') {
|
|
112
|
+
this.data[key].push([]);
|
|
113
|
+
} else if (this.schema.properties[key].items.type === 'boolean') {
|
|
114
|
+
this.data[key].push(false);
|
|
115
|
+
} else {
|
|
116
|
+
this.data[key].push('');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
components: {
|
|
121
|
+
PlusIcon,
|
|
122
|
+
TrashIcon,
|
|
123
|
+
TablerInput,
|
|
124
|
+
TablerToggle,
|
|
125
|
+
TablerEnum
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
</script>
|
package/lib.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as TablerError } from './components/Err.vue'
|
|
2
2
|
export { default as TablerList } from './components/List.vue'
|
|
3
|
+
export { default as TablerHelp } from './components/Help.vue'
|
|
3
4
|
export { default as TablerSelect } from './components/Select.vue'
|
|
4
5
|
export { default as TablerModal } from './components/Modal.vue'
|
|
5
6
|
export { default as TablerProgress } from './components/Progress.vue'
|
|
@@ -13,3 +14,4 @@ export { default as TablerEpoch } from './components/Epoch.vue';
|
|
|
13
14
|
export { default as TablerEpochRange } from './components/EpochRange.vue';
|
|
14
15
|
export { default as TablerMarkdown } from './components/Markdown.vue';
|
|
15
16
|
export { default as TablerDelete } from './components/Delete.vue';
|
|
17
|
+
export { default as TablerSchema } from './components/Schema.vue';
|