@cybertale/form 2.0.3 → 2.0.5
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/copy-package.mjs
CHANGED
|
@@ -9,8 +9,8 @@ const prompt = promptSync();
|
|
|
9
9
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
10
|
|
|
11
11
|
// Correct the source and destination directory paths
|
|
12
|
-
const sourceDir = path.
|
|
13
|
-
const destDir = path.
|
|
12
|
+
const sourceDir = path.join(__dirname, 'src');
|
|
13
|
+
const destDir = path.join(process.cwd(), 'src', '@cybertale', 'form');
|
|
14
14
|
|
|
15
15
|
// Create the destination directory if it doesn't exist
|
|
16
16
|
const ensureDir = async (dir) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cybertale/form",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "ECS interface for Web Development, CyberTale edition.",
|
|
5
5
|
"author": "Joso Marich <jspmari@proton.me>",
|
|
6
6
|
"license": "GPL-3.0-only",
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
"vite": "^5.3.4"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
|
-
"copy-package": "node copy-package.mjs"
|
|
44
|
-
"postinstall": "npm run copy-package"
|
|
43
|
+
"copy-package": "node copy-package.mjs"
|
|
45
44
|
}
|
|
46
45
|
}
|
|
@@ -1,73 +1,125 @@
|
|
|
1
1
|
<template v-if="renderComponent">
|
|
2
|
-
<button
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
<button
|
|
3
|
+
data-bs-toggle="tooltip"
|
|
4
|
+
data-bs-placement="top"
|
|
5
|
+
:data-bs-title="tooltipText"
|
|
6
|
+
:hidden="isHidden"
|
|
7
|
+
:disabled="isDisabled"
|
|
8
|
+
:class="buttonClass"
|
|
9
|
+
@click.prevent="handleClick"
|
|
10
|
+
>
|
|
11
|
+
<span class="order-2">{{ buttonLabel }}</span>
|
|
12
|
+
<i v-if="showIcon" :class="iconClass"></i>
|
|
9
13
|
</button>
|
|
10
14
|
<slot></slot>
|
|
11
15
|
</template>
|
|
12
16
|
|
|
17
|
+
|
|
13
18
|
<script lang="ts">
|
|
14
19
|
import { Component, Prop, Vue } from 'vue-facing-decorator'
|
|
15
|
-
import { ObjectTemplate,
|
|
20
|
+
import { ObjectTemplate, ObjectTypeEnum, RegionEnum, RegionType, StatTypeEnum } from '@cybertale/interface'
|
|
21
|
+
|
|
22
|
+
interface LabelData {
|
|
23
|
+
iconClass: string;
|
|
24
|
+
title: string;
|
|
25
|
+
}
|
|
16
26
|
@Component
|
|
17
27
|
export default class ButtonComponent extends Vue {
|
|
18
28
|
@Prop() object!: ObjectTemplate
|
|
19
29
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
// Enums
|
|
31
|
+
StatTypeEnum = StatTypeEnum
|
|
32
|
+
ObjectTypeEnum = ObjectTypeEnum
|
|
33
|
+
RegionEnum = RegionEnum
|
|
34
|
+
btnClass = ''
|
|
35
|
+
|
|
36
|
+
renderComponent = false
|
|
37
|
+
|
|
38
|
+
// Computed properties
|
|
39
|
+
get tooltipText(): string | undefined {
|
|
40
|
+
return this.getStatData(StatTypeEnum.Tooltip)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get isHidden(): boolean {
|
|
44
|
+
return this.getStatData(StatTypeEnum.ElementType) === 'hidden'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get isDisabled(): boolean {
|
|
48
|
+
return !!this.getStatData(StatTypeEnum.Disabled, 'boolean')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get buttonClass(): string {
|
|
52
|
+
const temp = this.getValue(StatTypeEnum.Design) as string
|
|
53
|
+
return temp
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get buttonLabel(): string {
|
|
57
|
+
if(this.showIcon){
|
|
58
|
+
const value = this.getValue(StatTypeEnum.Label) as LabelData
|
|
59
|
+
return value.title
|
|
35
60
|
}
|
|
36
|
-
return
|
|
61
|
+
return this.getValue(StatTypeEnum.Label) as string
|
|
37
62
|
}
|
|
38
63
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
64
|
+
get showIcon(): boolean {
|
|
65
|
+
return this.getStatData(StatTypeEnum.ElementType) === 'icon'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get iconClass(): string {
|
|
69
|
+
if(this.showIcon){
|
|
70
|
+
const value = this.getValue(StatTypeEnum.Label) as LabelData
|
|
71
|
+
return value.iconClass
|
|
45
72
|
}
|
|
46
|
-
return
|
|
73
|
+
return this.getValue(StatTypeEnum.Label)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Methods
|
|
77
|
+
handleClick(): void {
|
|
78
|
+
const { Region, ObjectEnum } = this.object
|
|
79
|
+
RegionType.RegionTypes[Region].ObjectTypes[ObjectEnum].ChooseSubType(this.object)
|
|
47
80
|
}
|
|
48
81
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
82
|
+
getValue( statEnum: StatTypeEnum, indexStatTypeEnum = StatTypeEnum.Option): string | LabelData {
|
|
83
|
+
const tempData:string = this.getStatData(statEnum) as string
|
|
84
|
+
if (!tempData) return '';
|
|
85
|
+
|
|
86
|
+
if (this.statIsDefined(indexStatTypeEnum) && this.isJSON(tempData)) {
|
|
87
|
+
const data = JSON.parse(tempData);
|
|
88
|
+
const optionData = this.getStatData(indexStatTypeEnum) as string
|
|
89
|
+
if(this.isJSON(optionData)){
|
|
90
|
+
const parsedOptionData = JSON.parse(optionData)[Number(this.object.Stats[StatTypeEnum.OptionIndices].Data)]
|
|
91
|
+
return data[Number(parsedOptionData)] || '';
|
|
53
92
|
}
|
|
93
|
+
return data[Number(this.getStatData(indexStatTypeEnum))] || '';
|
|
54
94
|
}
|
|
95
|
+
|
|
96
|
+
return tempData;
|
|
55
97
|
}
|
|
56
98
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return this.object.Stats[this.statTypeEnum.ElementType].Data === 'hidden'
|
|
99
|
+
statIsDefined (statType: StatTypeEnum): boolean {
|
|
100
|
+
return !!this.object.Stats[statType]
|
|
60
101
|
}
|
|
61
102
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
103
|
+
getStatData(statType: StatTypeEnum, returnType: 'boolean' | 'string' = 'string'): boolean | string {
|
|
104
|
+
try {
|
|
105
|
+
const data = this.object.Stats[statType]?.Data ?? ''
|
|
106
|
+
return returnType === 'boolean' ? !!data : data
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error(`Error accessing data for statType ${statType}:`, error)
|
|
109
|
+
return returnType === 'boolean' ? false : ''
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
isJSON(str: string): boolean {
|
|
114
|
+
try {
|
|
115
|
+
return Array.isArray(JSON.parse(str))
|
|
116
|
+
} catch {
|
|
117
|
+
return false
|
|
118
|
+
}
|
|
66
119
|
}
|
|
67
120
|
}
|
|
68
121
|
</script>
|
|
69
122
|
|
|
70
|
-
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
71
123
|
<style scoped>
|
|
72
|
-
|
|
124
|
+
/* Add your scoped styles here */
|
|
73
125
|
</style>
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<input
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
<input
|
|
3
|
+
class="form-control"
|
|
4
|
+
:id="getStatData(StatTypeEnum.Tag)"
|
|
5
|
+
:required="getStatData(StatTypeEnum.Required, 'boolean')"
|
|
6
|
+
:disabled="getStatData(StatTypeEnum.Disabled, 'boolean')"
|
|
7
|
+
:autocomplete="getStatData(StatTypeEnum.AutoComplete)"
|
|
8
|
+
:class="[getStatData(StatTypeEnum.Design), validationClass]"
|
|
9
|
+
:type="getInputType()"
|
|
10
|
+
:value="computedValue"
|
|
11
|
+
:placeholder="getStatData(StatTypeEnum.Placeholder)"
|
|
12
|
+
@input="handleInput"
|
|
13
|
+
/>
|
|
14
|
+
<div v-if="showErrorMessage" class="invalid-feedback">
|
|
15
|
+
{{ getStatData(StatTypeEnum.ErrorMessage) }}
|
|
16
|
+
</div>
|
|
13
17
|
</template>
|
|
14
18
|
|
|
15
19
|
<script lang="ts">
|
|
@@ -20,74 +24,85 @@ import { ObjectTemplate, ObjectType, ObjectTypeEnum, RegionEnum, RegionType, Sta
|
|
|
20
24
|
export default class FieldComponent extends Vue {
|
|
21
25
|
@Prop() object!: ObjectTemplate
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
regionEnum = RegionEnum
|
|
27
|
+
// Enums
|
|
28
|
+
StatTypeEnum = StatTypeEnum
|
|
29
|
+
ObjectTypeEnum = ObjectTypeEnum
|
|
30
|
+
RegionEnum = RegionEnum
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
// Computed properties
|
|
33
|
+
get computedValue(): string {
|
|
34
|
+
if (this.isLabelDisabled) {
|
|
35
|
+
return this.getStatData(StatTypeEnum.Label)
|
|
32
36
|
}
|
|
33
37
|
return this.getValue(StatTypeEnum.Value, StatTypeEnum.ValueIndices)
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
get isLabelDisabled(): boolean {
|
|
41
|
+
return this.getStatData(StatTypeEnum.Tag).includes('label') &&
|
|
42
|
+
this.getStatData(StatTypeEnum.Disabled, 'boolean')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get validationClass(): string {
|
|
46
|
+
const isValid = this.getStatData(StatTypeEnum.IsValid, 'boolean')
|
|
47
|
+
const errorMessage = this.getStatData(StatTypeEnum.ErrorMessage)
|
|
48
|
+
|
|
49
|
+
if (isValid === undefined || isValid === '') return ''
|
|
50
|
+
if (isValid) return 'is-valid'
|
|
51
|
+
if (errorMessage) return 'is-invalid'
|
|
45
52
|
return ''
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
get showErrorMessage(): boolean {
|
|
56
|
+
return this.validationClass === 'is-invalid'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Methods
|
|
60
|
+
getInputType(): string {
|
|
61
|
+
return this.getValue(StatTypeEnum.ElementType)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
handleInput(event: Event): void {
|
|
65
|
+
const target = event.target as HTMLInputElement
|
|
66
|
+
const { Region, ObjectEnum } = this.object
|
|
67
|
+
console.log(target.value)
|
|
68
|
+
RegionType.RegionTypes[Region].ObjectTypes[ObjectEnum].ChooseSubType(this.object, target.value)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getValue( statEnum: StatTypeEnum, indexStatTypeEnum = StatTypeEnum.Option): string {
|
|
72
|
+
const tempData:string = this.getStatData(statEnum)
|
|
73
|
+
if (!tempData) return '';
|
|
74
|
+
|
|
75
|
+
if (this.statIsDefined(indexStatTypeEnum) && this.isJSON(tempData)) {
|
|
76
|
+
const data = JSON.parse(tempData);
|
|
77
|
+
return data[Number(this.getStatData(indexStatTypeEnum))] || '';
|
|
54
78
|
}
|
|
79
|
+
|
|
80
|
+
return tempData;
|
|
55
81
|
}
|
|
56
82
|
|
|
57
|
-
|
|
58
|
-
return this.object.Stats[
|
|
83
|
+
statIsDefined (statType: StatTypeEnum): boolean {
|
|
84
|
+
return !!this.object.Stats[statType]
|
|
59
85
|
}
|
|
60
86
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
87
|
+
getStatData(statType: StatTypeEnum, returnType: 'boolean' | 'string' = 'string'): boolean | string {
|
|
88
|
+
try {
|
|
89
|
+
const data = this.object.Stats[statType]?.Data ?? ''
|
|
90
|
+
return returnType === 'boolean' ? !!data : data
|
|
91
|
+
} catch (error) {
|
|
92
|
+
return returnType === 'boolean' ? false : ''
|
|
93
|
+
}
|
|
68
94
|
}
|
|
69
95
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
96
|
+
isJSON(str: string): boolean {
|
|
97
|
+
try {
|
|
98
|
+
return Array.isArray(JSON.parse(str))
|
|
99
|
+
} catch {
|
|
100
|
+
return false
|
|
101
|
+
}
|
|
74
102
|
}
|
|
75
103
|
|
|
76
104
|
tooltipCase(): string | undefined {
|
|
77
|
-
return this.object?.Stats[
|
|
105
|
+
return this.object?.Stats[StatTypeEnum.Tooltip]?.Data
|
|
78
106
|
}
|
|
79
107
|
}
|
|
80
108
|
</script>
|
|
81
|
-
|
|
82
|
-
<style scoped>
|
|
83
|
-
.form-check .form-check-input {
|
|
84
|
-
float: none;
|
|
85
|
-
}
|
|
86
|
-
.form-check-input {
|
|
87
|
-
margin-right: 1%;
|
|
88
|
-
}
|
|
89
|
-
.form-check-input:checked {
|
|
90
|
-
background-color: #606467;
|
|
91
|
-
border-color: #606467;
|
|
92
|
-
}
|
|
93
|
-
</style>
|