@modelforms/fontawesome-vuetify 1.0.4 → 2.1.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/components/form/Form.vue +3 -3
- package/components/form/complete/Complete.vue +78 -37
- package/components/form/date/Date.vue +1 -1
- package/components/form/functions/methods.ts +25 -0
- package/components/form/functions/rules.ts +6 -1
- package/components/form/helpers/parsers.ts +37 -0
- package/components/form/models/completeModels.ts +4 -6
- package/components/form/models/formModels.ts +14 -12
- package/components/form/models/resources.ts +2 -1
- package/components/index.d.ts +2 -1
- package/dist/index.amd.ts +15 -15
- package/dist/index.cjs.ts +15 -15
- package/package.json +1 -1
- package/components/form/functions/complete.ts +0 -45
- package/components/form/functions/helper.ts +0 -11
package/components/form/Form.vue
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
:model="form.model"
|
|
44
44
|
:itemValue="col.complete.itemValue"
|
|
45
45
|
:items="col.complete.items"
|
|
46
|
-
:
|
|
46
|
+
:filterKeys="col.complete.filterOptions"
|
|
47
47
|
:multiple="col.complete.multiple"
|
|
48
48
|
:label="col.label"
|
|
49
49
|
:rules="col.rules"
|
|
@@ -89,7 +89,7 @@ export default{
|
|
|
89
89
|
},
|
|
90
90
|
props: {
|
|
91
91
|
form: {
|
|
92
|
-
type: Object as () => GridModel
|
|
92
|
+
type: Object as () => GridModel<any>,
|
|
93
93
|
required: true
|
|
94
94
|
}
|
|
95
95
|
},
|
|
@@ -107,7 +107,7 @@ export default{
|
|
|
107
107
|
value(event: any, name: string) {
|
|
108
108
|
this.model[name] = event;
|
|
109
109
|
},
|
|
110
|
-
init(form: GridModel) {
|
|
110
|
+
init(form: GridModel<any>) {
|
|
111
111
|
for(let row of form.rows){
|
|
112
112
|
for(let col of row.cols){
|
|
113
113
|
this.model[col.name] = col.value;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<template> <v-container fluid>
|
|
2
2
|
<v-autocomplete
|
|
3
|
-
ref="template"
|
|
4
3
|
:v-model="model"
|
|
5
4
|
:items="items"
|
|
6
5
|
:item-title="title"
|
|
@@ -8,7 +7,7 @@
|
|
|
8
7
|
:rules="rule"
|
|
9
8
|
:search="value"
|
|
10
9
|
:multiple="multiple"
|
|
11
|
-
:filter-keys="
|
|
10
|
+
:filter-keys="controlKeys"
|
|
12
11
|
:menu-icon="defaultIcon"
|
|
13
12
|
v-bind:model-value="value"
|
|
14
13
|
@update:search="select($event)"
|
|
@@ -24,7 +23,7 @@
|
|
|
24
23
|
<FontAwesomeIcon v-if="square" v-bind:icon="item.props.icon" />
|
|
25
24
|
</v-col>
|
|
26
25
|
<v-col cols="10">
|
|
27
|
-
<span>{{ item.data
|
|
26
|
+
<span>{{ item.data![filterKeys.title] }}</span>
|
|
28
27
|
</v-col>
|
|
29
28
|
</v-row>
|
|
30
29
|
</v-container>
|
|
@@ -38,14 +37,12 @@
|
|
|
38
37
|
import { faArrowAltCircleDown, faSquare } from '@fortawesome/free-regular-svg-icons';
|
|
39
38
|
import { faCheck } from '@fortawesome/free-solid-svg-icons';
|
|
40
39
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
|
41
|
-
import { setRule } from '../functions/rules';
|
|
40
|
+
import { getFilterKeys, setRule } from '../functions/rules';
|
|
42
41
|
import { RowItem, RowProps } from '../models/completeModels';
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
import { empty, defaultIcon, valueEvent, filterKeys, template } from '../models/resources';
|
|
46
|
-
import { CompleteItems } from '../models/formModels';
|
|
42
|
+
import { empty, defaultIcon, valueEvent, template, searchError } from '../models/resources';
|
|
43
|
+
import { FilterOptions } from '../models/formModels';
|
|
47
44
|
import { initComponent } from '../functions/init';
|
|
48
|
-
import {
|
|
45
|
+
import {isEqual, onMethod } from '../functions/methods';
|
|
49
46
|
|
|
50
47
|
export default{
|
|
51
48
|
name: "CompleteControl",
|
|
@@ -58,11 +55,11 @@
|
|
|
58
55
|
type: Object
|
|
59
56
|
},
|
|
60
57
|
items: {
|
|
61
|
-
type: Array<
|
|
58
|
+
type: Array<Object>,
|
|
62
59
|
default: () => []
|
|
63
60
|
},
|
|
64
61
|
itemValue: {
|
|
65
|
-
type: Array<
|
|
62
|
+
type: Array<Object>,
|
|
66
63
|
default: () => []
|
|
67
64
|
},
|
|
68
65
|
title: {
|
|
@@ -77,6 +74,10 @@
|
|
|
77
74
|
rules: {
|
|
78
75
|
type: Array<String>,
|
|
79
76
|
default: () => []
|
|
77
|
+
},
|
|
78
|
+
filterKeys: {
|
|
79
|
+
type: FilterOptions,
|
|
80
|
+
default: () => new FilterOptions()
|
|
80
81
|
}
|
|
81
82
|
},
|
|
82
83
|
components: {
|
|
@@ -93,18 +94,17 @@
|
|
|
93
94
|
},
|
|
94
95
|
data() {
|
|
95
96
|
return {
|
|
96
|
-
selected: [] as
|
|
97
|
-
unSelected: [] as
|
|
97
|
+
selected: [] as Object[],
|
|
98
|
+
unSelected: [] as Object[],
|
|
98
99
|
rows: [] as RowItem[],
|
|
99
100
|
rule: setRule(this.rules),
|
|
100
101
|
value: this.value,
|
|
101
|
-
ref: useTemplateRef('template'),
|
|
102
102
|
arrowDown: faArrowAltCircleDown,
|
|
103
103
|
square: faSquare,
|
|
104
104
|
check: faCheck,
|
|
105
105
|
search: empty,
|
|
106
106
|
defaultIcon: defaultIcon,
|
|
107
|
-
|
|
107
|
+
controlKeys: getFilterKeys(this.filterKeys),
|
|
108
108
|
template: template
|
|
109
109
|
}
|
|
110
110
|
},
|
|
@@ -118,68 +118,109 @@
|
|
|
118
118
|
blur(event) {
|
|
119
119
|
this.$emit(valueEvent, this.selected);
|
|
120
120
|
},
|
|
121
|
-
multiSelect(value:
|
|
121
|
+
multiSelect(value: Object) {
|
|
122
122
|
this.unSelected = [];
|
|
123
123
|
|
|
124
124
|
if(!this.selected.length){
|
|
125
125
|
this.unSelected = [value!];
|
|
126
|
-
this.search = addItem(this.search, value)!;
|
|
126
|
+
this.search = this.addItem(this.search, value)!;
|
|
127
127
|
}
|
|
128
|
-
else if(this.selected.some(element => element
|
|
129
|
-
this.unSelected = this.selected.filter(element => element
|
|
130
|
-
this.search = removeItem(this.search, value)!;
|
|
128
|
+
else if(this.selected.some(element => isEqual(value, element))){
|
|
129
|
+
this.unSelected = this.selected.filter(element => !isEqual(value, element));
|
|
130
|
+
this.search = this.removeItem(this.search, value)!;
|
|
131
131
|
}else{
|
|
132
132
|
this.unSelected = [...this.selected, value!];
|
|
133
|
-
this.search += addItem(this.search, value, false)!;
|
|
133
|
+
this.search += this.addItem(this.search, value, false)!;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
this.value = this.search;
|
|
137
137
|
this.selected = this.unSelected;
|
|
138
|
-
this.
|
|
138
|
+
this.updateState(value);
|
|
139
139
|
},
|
|
140
140
|
initAriaRows(){
|
|
141
141
|
this.value = "";
|
|
142
142
|
this.ariaRows(this.items);
|
|
143
143
|
|
|
144
144
|
if(this.itemValue.length){
|
|
145
|
+
console.log(this.itemValue);
|
|
145
146
|
for(let item of this.itemValue){
|
|
146
147
|
this.multiSelect(item);
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
},
|
|
150
|
-
|
|
151
|
+
updateState(value: Object) {
|
|
151
152
|
for(let item of this.rows){
|
|
152
|
-
if(item.
|
|
153
|
-
|
|
154
|
-
findFirst(item.icon)(value);
|
|
155
|
-
findFirst(item.active)(value);
|
|
153
|
+
if(isEqual(item.data!, value)){
|
|
154
|
+
onMethod(item.active, value);
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
},
|
|
159
|
-
ariaRows(selected:
|
|
158
|
+
ariaRows(selected: Object[]) {
|
|
160
159
|
for(let i = 0; i < selected.length; i++){
|
|
161
160
|
this.ariarows(selected[i], i);
|
|
162
161
|
}
|
|
163
162
|
},
|
|
164
|
-
|
|
165
|
-
for(let i = 0; i < selected.length; i++){
|
|
166
|
-
this.changeRow(selected[i], i);
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
ariarows(value: CompleteItems, index) {
|
|
163
|
+
ariarows(value: Object, index) {
|
|
170
164
|
const row: RowItem = {
|
|
171
165
|
id: index,
|
|
172
166
|
data: value,
|
|
173
167
|
props: new RowProps(),
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
168
|
+
active: [(item: Object) => {
|
|
169
|
+
if(this.selected.some(element => item == element)){
|
|
170
|
+
row.props.icon = this.check;
|
|
171
|
+
row.props.row = 'active';
|
|
172
|
+
}else{
|
|
173
|
+
row.props.icon = this.square
|
|
174
|
+
row.props.row = '';
|
|
175
|
+
}
|
|
176
|
+
}],
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
this.rows = [...this.rows, row];
|
|
180
180
|
|
|
181
181
|
return index;
|
|
182
182
|
},
|
|
183
|
+
removeItem(search: string, value: Object) {
|
|
184
|
+
if(search == null || search == undefined){
|
|
185
|
+
search = empty;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let lastIndex = search.indexOf(', ' + value[this.filterKeys.title]);
|
|
189
|
+
|
|
190
|
+
if(lastIndex >= 0){
|
|
191
|
+
let title = ', ' + value[this.filterKeys.title];
|
|
192
|
+
let s = search.indexOf(title);
|
|
193
|
+
return search.substring(0, s) + search.substring(s + title.length, search.length);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let firstIndex = search.indexOf(value[this.filterKeys.title]!);
|
|
197
|
+
|
|
198
|
+
if(firstIndex >= 0){
|
|
199
|
+
let title = value[this.filterKeys.title]!;
|
|
200
|
+
let s = search.indexOf(title);
|
|
201
|
+
let result = search.substring(0, s) + search.substring(s + title.length, search.length);
|
|
202
|
+
|
|
203
|
+
if(result.substring(0, 2) == ', '){
|
|
204
|
+
return result.substring(2, result.length);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
new Error(`${searchError} CompleteControl`);
|
|
211
|
+
},
|
|
212
|
+
addItem(compare: string, value: Object, first = true) {
|
|
213
|
+
if(value[this.filterKeys.title] == undefined){
|
|
214
|
+
return empty;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if(!first){
|
|
218
|
+
return ', ' + value[this.filterKeys.title];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return value[this.filterKeys.title];
|
|
222
|
+
}
|
|
223
|
+
|
|
183
224
|
}
|
|
184
225
|
}
|
|
185
226
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { firstIndex, index } from "../models/resources";
|
|
2
|
+
|
|
3
|
+
export const findLast = (entries: string[]) => {
|
|
4
|
+
return entries[entries.length - index];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const findFirst = (entires: any[]) => {
|
|
8
|
+
for(let entry of entires){
|
|
9
|
+
return entry;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const onMethod = (method: any, value: Object) => {
|
|
14
|
+
method[firstIndex](value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const isEqual = (object1: Object, object2: Object) => {
|
|
18
|
+
for(let prop1 of Object.keys(object1)){
|
|
19
|
+
if(object1[prop1] != object2[prop1]){
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { FilterOptions } from "../models/formModels";
|
|
1
2
|
import { index, ruleError } from "../models/resources";
|
|
2
3
|
import { componentType } from "./init";
|
|
3
|
-
import { findFirst, findLast } from './
|
|
4
|
+
import { findFirst, findLast } from './methods';
|
|
4
5
|
|
|
5
6
|
export const setRule = (rules: any) => {
|
|
6
7
|
if(rules.length > 0){
|
|
@@ -34,6 +35,10 @@ const parseRules = (rules: string[]) => {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
export const getFilterKeys = (models: FilterOptions): string[] => {
|
|
39
|
+
return [models.title, models.name];
|
|
40
|
+
}
|
|
41
|
+
|
|
37
42
|
const getRules = (value: any, error = '') => {
|
|
38
43
|
return [
|
|
39
44
|
{'maxLen': [(v: any) => v?.length <= value || `Not grater than ${value} characters!`]},
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CompleteModels, GridModel } from "../models/formModels";
|
|
2
|
+
|
|
3
|
+
export class GridModelHelper<T> {
|
|
4
|
+
populateGridModel(gridModel: GridModel<T>, model: T) {
|
|
5
|
+
|
|
6
|
+
for(let row of gridModel.rows){
|
|
7
|
+
for(let col of row.cols){
|
|
8
|
+
let name = model[col.name];
|
|
9
|
+
|
|
10
|
+
if(name != undefined){
|
|
11
|
+
if(col.type == 'complete'){
|
|
12
|
+
col.complete.itemValue = model[name];
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
col.value = model[name];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return gridModel;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
populateCompletes(gridModel: GridModel<T>, completeModels: CompleteModels[]) {
|
|
25
|
+
for(let row of gridModel.rows){
|
|
26
|
+
for(let col of row.cols.filter(x=> x.type == 'complete')){
|
|
27
|
+
let model = completeModels.find(model => model.name == col.name);
|
|
28
|
+
|
|
29
|
+
if(model != undefined){
|
|
30
|
+
col.complete.items = model.items;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return gridModel;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { faSquare } from "@fortawesome/free-regular-svg-icons";
|
|
2
|
-
import type { CompleteItems } from "./formModels";
|
|
3
2
|
|
|
4
3
|
export class RowItem{
|
|
5
4
|
id: number = 0;
|
|
6
|
-
data?:
|
|
7
|
-
|
|
8
|
-
icon: ((v: CompleteItems) => void)[] = [];
|
|
9
|
-
active: ((v: CompleteItems) => void)[] = [];
|
|
5
|
+
data?: Object;
|
|
6
|
+
active: ((v: Object) => void)[] = [];
|
|
10
7
|
props: RowProps = new RowProps();
|
|
11
8
|
}
|
|
12
9
|
|
|
@@ -14,4 +11,5 @@ export class RowProps{
|
|
|
14
11
|
row: string = '';
|
|
15
12
|
icon: any = faSquare;
|
|
16
13
|
active: boolean = false;
|
|
17
|
-
}
|
|
14
|
+
}
|
|
15
|
+
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export class GridModel {
|
|
1
|
+
export class GridModel<T> {
|
|
4
2
|
name: string = "";
|
|
5
|
-
model:
|
|
3
|
+
model: T = Object.assign({});
|
|
6
4
|
rows: Row[] = [];
|
|
7
5
|
}
|
|
8
6
|
|
|
@@ -11,11 +9,15 @@ export class Row{
|
|
|
11
9
|
cols: Col[] = [];
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
export class
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
export class CompleteModels{
|
|
13
|
+
name: string = '';
|
|
14
|
+
items: any[] = [];
|
|
17
15
|
}
|
|
18
16
|
|
|
17
|
+
export class FilterOptions {
|
|
18
|
+
title: string = '';
|
|
19
|
+
name: string = '';
|
|
20
|
+
}
|
|
19
21
|
|
|
20
22
|
class Col{
|
|
21
23
|
name: string = "";
|
|
@@ -24,12 +26,12 @@ class Col{
|
|
|
24
26
|
label: string = "";
|
|
25
27
|
rules: string[] = [];
|
|
26
28
|
size: number = 4;
|
|
27
|
-
complete: Complete = new Complete();
|
|
29
|
+
complete: Complete<any> = new Complete<any>();
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
class Complete{
|
|
31
|
-
items:
|
|
32
|
-
itemValue:
|
|
32
|
+
class Complete<T>{
|
|
33
|
+
items: T[] = [];
|
|
34
|
+
itemValue: T[] = [];
|
|
33
35
|
multiple?: boolean = false;
|
|
34
|
-
|
|
36
|
+
filterOptions: FilterOptions = new FilterOptions();
|
|
35
37
|
}
|
package/components/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
export { default as FormPlate } from "./form/Form.vue";
|
|
4
4
|
export { GridModel } from './form/models/formModels';
|
|
5
|
+
export { GridModelHelper } from './form/helpers/parsers';
|
|
5
6
|
|
|
6
7
|
/*!
|
|
7
8
|
* Vuetify Labs v3.4.0 by vuetify - https://vuetifyjs.com
|
|
@@ -11,4 +12,4 @@ export { GridModel } from './form/models/formModels';
|
|
|
11
12
|
* Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com
|
|
12
13
|
* License - https://fontawesome.com/license/free - MIT License
|
|
13
14
|
* Copyright 2025 Fonticons, Inc.
|
|
14
|
-
*/
|
|
15
|
+
*/
|