@modelforms/fontawesome-vuetify 1.0.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.
@@ -0,0 +1,184 @@
1
+ <template> <v-container fluid>
2
+ <v-autocomplete
3
+ ref="template"
4
+ menu-icon=""
5
+ :v-model="model"
6
+ :filter-keys="['title']"
7
+ :items="items"
8
+ :item-title="title"
9
+ :label="label"
10
+ :rules="rule"
11
+ v-bind:model-value="value"
12
+ :search="value"
13
+ :multiple="multiple"
14
+ @update:search="select($event)"
15
+ @blur="blur($event)">
16
+ <template v-if="arrowDown" #append-inner>
17
+ <FontAwesomeIcon :icon="arrowDown" />
18
+ </template>
19
+ <template v-if="multiple" #item></template>
20
+ <template v-if="multiple" #append-item>
21
+ <v-container class="mb-6">
22
+ <v-row v-for="item in rows" v-bind:key="item.id" :v-bind="item" v-bind:class="item.props.row" @click="multiSelect(item.data!)">
23
+ <v-col cols="2">
24
+ <FontAwesomeIcon v-if="square" v-bind:icon="item.props.icon" />
25
+ </v-col>
26
+ <v-col cols="10">
27
+ <span>{{ item.data?.title }}</span>
28
+ </v-col>
29
+ </v-row>
30
+ </v-container>
31
+ </template>
32
+ </v-autocomplete>
33
+ </v-container>
34
+
35
+ </template>
36
+
37
+ <script lang="ts">
38
+ import { faArrowAltCircleDown, faSquare } from '@fortawesome/free-regular-svg-icons';
39
+ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
40
+ import { setRule } from '../functions/rules';
41
+ import { CompleteItems, RowItem, RowProps } from './../models/h-model';
42
+ import { faCheck } from '@fortawesome/free-solid-svg-icons';
43
+ import { useTemplateRef } from 'vue';
44
+ import { addItem, removeItem } from '../functions/complete';
45
+ import { valueEvent } from './../models/references';
46
+
47
+ export default{
48
+ props: {
49
+ value: {
50
+ type: String,
51
+ required: true,
52
+ },
53
+ model: {
54
+ type: Object
55
+ },
56
+ items: {
57
+ type: Array<CompleteItems>,
58
+ default: () => []
59
+ },
60
+ itemValue: {
61
+ type: Array<CompleteItems>,
62
+ default: () => []
63
+ },
64
+ title: {
65
+ type: String,
66
+ },
67
+ multiple: {
68
+ type: Boolean
69
+ },
70
+ label: {
71
+ type: String
72
+ },
73
+ rules: {
74
+ type: Array<String>,
75
+ default: () => []
76
+ }
77
+ },
78
+ components: {
79
+ FontAwesomeIcon: FontAwesomeIcon,
80
+ },
81
+ emits: [valueEvent],
82
+ mounted() {
83
+ if(this.multiple){
84
+ this.initAriaRows();
85
+ }
86
+ },
87
+ data() {
88
+ return {
89
+ selected: [] as CompleteItems[],
90
+ unSelected: [] as CompleteItems[],
91
+ rows: [] as RowItem[],
92
+ rule: setRule(this.rules),
93
+ value: this.value,
94
+ ref: useTemplateRef('template'),
95
+ arrowDown: faArrowAltCircleDown,
96
+ square: faSquare,
97
+ check: faCheck,
98
+ search: "",
99
+ template: {}
100
+ }
101
+ },
102
+ methods: {
103
+ select(event) {
104
+ if(event.length!) {
105
+ console.log(event)
106
+ this.value = event;
107
+ this.$emit(valueEvent, this.items.find(item => item[this.title!] == event));
108
+ }
109
+ },
110
+ blur(event) {
111
+ this.$emit(valueEvent, this.selected);
112
+ },
113
+ multiSelect(value: CompleteItems) {
114
+ this.unSelected = [];
115
+
116
+ if(!this.selected.length){
117
+ this.unSelected = [value!];
118
+ this.search = addItem(this.search, value)!;
119
+ }
120
+ else if(this.selected.some(element => element == value)){
121
+ this.unSelected = this.selected.filter(element => element != value);
122
+ this.search = removeItem(this.search, value)!;
123
+ }else{
124
+ this.unSelected = [...this.selected, value!];
125
+ this.search += addItem(this.search, value, false)!;
126
+ }
127
+
128
+ this.value = this.search;
129
+ this.selected = this.unSelected;
130
+ this.changedRows(this.items);
131
+ },
132
+ initAriaRows(){
133
+ this.value = "";
134
+ this.ariaRows(this.items);
135
+
136
+ if(this.itemValue.length){
137
+ for(let item of this.itemValue){
138
+ this.multiSelect(item);
139
+ }
140
+ }
141
+ },
142
+ changeRow(value: CompleteItems, index) {
143
+ for(let item of this.rows){
144
+ if(item.id == index){
145
+ item.row[0](value);
146
+ item.icon[0](value);
147
+ item.active[0](value);
148
+ }
149
+ }
150
+ },
151
+ ariaRows(selected: CompleteItems[]) {
152
+ for(let i = 0; i < selected.length; i++){
153
+ this.ariarows(selected[i], i);
154
+ }
155
+ },
156
+ changedRows(selected: CompleteItems[]) {
157
+ for(let i = 0; i < selected.length; i++){
158
+ this.changeRow(selected[i], i);
159
+ }
160
+ },
161
+ ariarows(value: CompleteItems, index) {
162
+ const row: RowItem = {
163
+ id: index,
164
+ data: value,
165
+ props: new RowProps(),
166
+ row: [(item: CompleteItems) => this.selected.some(element => element == item) ? row.props.row = 'active' : row.props.row = ''],
167
+ icon: [(item: CompleteItems) => this.selected.some(element => element == item) ? row.props.icon = this.check : row.props.icon = this.square],
168
+ active: [(item: CompleteItems) => this.template = this.ref!],
169
+ }
170
+
171
+ this.rows = [...this.rows, row];
172
+
173
+ return index;
174
+ },
175
+ }
176
+ }
177
+
178
+ </script>
179
+
180
+ <style>
181
+ .active{
182
+ background-color: rgb(228, 223, 223);
183
+ }
184
+ </style>
@@ -0,0 +1,59 @@
1
+ <template>
2
+ <v-container fluid>
3
+ <v-date-input
4
+ :v-model="model"
5
+ :model-value="value"
6
+ :rules="rule"
7
+ :label="label"
8
+ @save="select($event)">
9
+ <template v-if="faCalendar" #append-inner>
10
+ <FontAwesomeIcon :icon="faCalendar" />
11
+ </template>
12
+ </v-date-input>
13
+ </v-container>
14
+ </template>
15
+
16
+ <script lang="ts">
17
+ import { faCalendar } from '@fortawesome/free-regular-svg-icons';
18
+ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
19
+ import { setRule } from '../functions/rules';
20
+ import { valueEvent } from './../models/references';
21
+
22
+ export default {
23
+ components: {
24
+ FontAwesomeIcon
25
+ },
26
+ props: {
27
+ value: {
28
+ type: [String, Date],
29
+ required: true
30
+ },
31
+ label: {
32
+ type: String,
33
+ required: true
34
+ },
35
+ model: {
36
+ type: Object,
37
+ required: true
38
+ },
39
+ rules:{
40
+ type: Array,
41
+ required: false,
42
+ default: () => []
43
+ }
44
+ },
45
+ emits: [valueEvent],
46
+ data() {
47
+ return {
48
+ rule: setRule(this.rules),
49
+ faCalendar: faCalendar
50
+ }
51
+ },
52
+ methods: {
53
+ select(event: any) {
54
+ this.$emit(valueEvent, event);
55
+ }
56
+ },
57
+ }
58
+
59
+ </script>
@@ -0,0 +1,22 @@
1
+ {
2
+ "name":"",
3
+ "model": {},
4
+ "rows": [
5
+ {
6
+ "colSize": 2,
7
+ "cols": [
8
+ {
9
+ "name": "",
10
+ "type": "",
11
+ "label": "",
12
+ "rules": [""],
13
+ "size": 2,
14
+ "complete": {
15
+ "items": [{}],
16
+ "title": ""
17
+ }
18
+ }
19
+ ]
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,43 @@
1
+ import { CompleteItems } from "../models/h-model";
2
+
3
+ export const removeItem = (search: string, value: CompleteItems) => {
4
+ if(search == null || search == undefined){
5
+ search = '';
6
+ }
7
+
8
+ let lastIndex = search.indexOf(', ' + value.title);
9
+
10
+ if(lastIndex >= 0){
11
+ let title = ', ' + value.title;
12
+ let s = search.indexOf(title);
13
+ return search.substring(0, s) + search.substring(s + title.length, search.length);
14
+ }
15
+
16
+ let firstIndex = search.indexOf(value.title!);
17
+
18
+ if(firstIndex >= 0){
19
+ let title = value.title!;
20
+ let s = search.indexOf(title);
21
+ let result = search.substring(0, s) + search.substring(s + title.length, search.length);
22
+
23
+ if(result.substring(0, 2) == ', '){
24
+ return result.substring(2, result.length);
25
+ }
26
+
27
+ return result;
28
+ }
29
+
30
+ new Error('');
31
+ }
32
+
33
+ export const addItem = (compare: string, value: CompleteItems, first = true) => {
34
+ if(value.title == undefined){
35
+ return '';
36
+ }
37
+
38
+ if(!first){
39
+ return ', ' + value.title;
40
+ }
41
+
42
+ return value.title;
43
+ }
@@ -0,0 +1,54 @@
1
+ export const setRule = (rules: any) => {
2
+ if(rules.length > 0){
3
+ let rule = parseRules(rules);
4
+ if(rule != undefined && rule != null){
5
+ return rule;
6
+ }
7
+ }
8
+ }
9
+
10
+ const index = 1;
11
+ const parseRules = (rules: string[]) => {
12
+ for(let rule of rules){
13
+ let parts = rule.split(':');
14
+
15
+ let rules = getRules(findLast(parts), parts[index]).map((value) => {
16
+ var entries = Object.keys(value);
17
+ let entry = findFirst(entries);
18
+
19
+ if(entry == findFirst(parts)){
20
+ let output = findLast(entries)!;
21
+ return value[output];
22
+ }
23
+ })
24
+
25
+ if(rules.length){
26
+ return findFirst(rules);
27
+ }
28
+
29
+ new Error('');
30
+ }
31
+ }
32
+
33
+ const findLast = (entries: string[]) => {
34
+ return entries[entries.length - index];
35
+ }
36
+
37
+ const findFirst = (entires: any[]) => {
38
+ for(let entry of entires){
39
+ return entry;
40
+ }
41
+ }
42
+
43
+ const getRules = (value: any, error = '') => {
44
+ return [
45
+ {'maxLen': [(v: any) => v?.length <= value || `Not grater than ${value} characters!`]},
46
+ {'minLen': [(v: any) => v?.length >= value || `Not less ${value} characters!`]},
47
+ {'maxValue': [(v: any) => v <= value || `Not grater than ${value}!`]},
48
+ {'minValue': [(v: any) => v >= value || `Not less than ${value}!`]},
49
+ {'maxDate': [(v: any) => v <= new Date(value) || `Not grater than ${value}!`]},
50
+ {'minDate': [(v: any) => v >= new Date(value) || `Not less than ${value}!`]},
51
+ {'required': [(v: any) => (v != '' && v != null && v != undefined) || `Field is required!`]},
52
+ {'pattern': [(v: any) => new RegExp(value, 'g').test(v) || error]}
53
+ ];
54
+ }
@@ -0,0 +1,21 @@
1
+ import { faSquare } from "@fortawesome/free-regular-svg-icons";
2
+
3
+ export class CompleteItems{
4
+ title?: '';
5
+ abbr?: 0
6
+ }
7
+
8
+ export class RowItem{
9
+ id: number = 0;
10
+ data?: CompleteItems;
11
+ row: ((v: CompleteItems) => void)[] = [];
12
+ icon: ((v: CompleteItems) => void)[] = [];
13
+ active: ((v: CompleteItems) => void)[] = [];
14
+ props: RowProps = new RowProps();
15
+ }
16
+
17
+ export class RowProps{
18
+ row: string = '';
19
+ icon: any = faSquare;
20
+ active: boolean = false;
21
+ }
@@ -0,0 +1,29 @@
1
+ import { CompleteItems } from "./h-model";
2
+
3
+ export class GridModel {
4
+ name: string = "";
5
+ model: any;
6
+ rows: Row[] = [];
7
+ }
8
+
9
+ export class Row{
10
+ colSize: number = 12;
11
+ cols: Col[] = [];
12
+ }
13
+
14
+ class Col{
15
+ name: string = "";
16
+ type: "text" | "number" | "date" | "complete" | "area" = "text";
17
+ value?: any;
18
+ label: string = "";
19
+ rules: string[] = [];
20
+ size: number = 4;
21
+ complete: Complete = new Complete();
22
+ }
23
+
24
+ class Complete{
25
+ items: CompleteItems[] = [];
26
+ itemValue: CompleteItems[] = [];
27
+ multiple?: boolean = false;
28
+ title: "title" | "abbr" = "title";
29
+ }
@@ -0,0 +1,4 @@
1
+ export const button = 'SUBMIT';
2
+ export const event = 'submit';
3
+ export const valueEvent = 'value';
4
+ export let templateRef = 'template';
@@ -0,0 +1,52 @@
1
+ <template>
2
+ <v-container fluid>
3
+ <v-number-input
4
+ :model-value="value"
5
+ :v-model="model"
6
+ :rules="rule"
7
+ :label="label"
8
+ :precision="2"
9
+ control-variant="hidden"
10
+ @blur="blur($event)">
11
+ </v-number-input>
12
+ </v-container>
13
+ </template>
14
+
15
+ <script lang="ts">
16
+ import { setRule } from '../functions/rules';
17
+ import { valueEvent } from './../models/references';
18
+
19
+ export default {
20
+ props: {
21
+ value: {
22
+ type: Number,
23
+ required: true
24
+ },
25
+ label: {
26
+ type: String,
27
+ required: true
28
+ },
29
+ model: {
30
+ type: Object,
31
+ required: true
32
+ },
33
+ rules:{
34
+ type: Array,
35
+ required: false,
36
+ default: () => []
37
+ }
38
+ },
39
+ emits: [valueEvent],
40
+ data() {
41
+ return {
42
+ rule: setRule(this.rules)
43
+ }
44
+ },
45
+ methods: {
46
+ blur(event: any) {
47
+ this.$emit(valueEvent, event.target.value);
48
+ }
49
+ },
50
+
51
+ }
52
+ </script>
@@ -0,0 +1,51 @@
1
+ <template>
2
+ <v-container fluid>
3
+ <v-text-field
4
+ :v-model="model"
5
+ :model-value="value"
6
+ :rules="rule"
7
+ :label="label"
8
+ @blur="blur($event)">
9
+ </v-text-field>
10
+ </v-container>
11
+ </template>
12
+
13
+
14
+ <script lang="ts">
15
+ import { setRule } from '../functions/rules';
16
+ import { valueEvent } from './../models/references';
17
+
18
+ export default {
19
+ props: {
20
+ value: {
21
+ type: String,
22
+ required: true
23
+ },
24
+ label: {
25
+ type: String,
26
+ required: true
27
+ },
28
+ model: {
29
+ type: Object,
30
+ required: true
31
+ },
32
+ rules:{
33
+ type: Array,
34
+ required: false,
35
+ default: () => []
36
+ }
37
+ },
38
+ emits: [valueEvent],
39
+ data() {
40
+ return {
41
+ rule: setRule(this.rules)
42
+ }
43
+ },
44
+ methods: {
45
+ blur(event: any) {
46
+ this.$emit(valueEvent, event.target.value);
47
+ }
48
+ },
49
+
50
+ }
51
+ </script>
package/src/index.html ADDED
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Document</title>
7
+ </head>
8
+ <body>
9
+
10
+ </body>
11
+ </html>
package/tsconfig.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "include": [
3
+ "src",
4
+ "types"
5
+ ],
6
+ // Visit https://aka.ms/tsconfig to read more about this file
7
+ "compilerOptions": {
8
+ // File Layout
9
+ // "rootDir": "./src",
10
+ "outDir": "./dist",
11
+ "module": "preserve",
12
+ "moduleResolution": "bundler",
13
+
14
+
15
+ // Environment Settings
16
+ // See also https://aka.ms/tsconfig/module
17
+ "target": "es2020",
18
+ "types": [],
19
+ // For nodejs:
20
+ // "lib": ["esnext"],
21
+ // "types": ["node"],
22
+ // and npm install -D @types/node
23
+
24
+ // Other Outputs
25
+ "sourceMap": true,
26
+ "declaration": true,
27
+ "declarationMap": true,
28
+
29
+ // Stricter Typechecking Options
30
+ "noUncheckedIndexedAccess": true,
31
+ "exactOptionalPropertyTypes": false,
32
+
33
+ // Style Options
34
+ // "noImplicitReturns": true,
35
+ // "noImplicitOverride": true,
36
+ // "noUnusedLocals": true,
37
+ // "noUnusedParameters": true,
38
+ // "noFallthroughCasesInSwitch": true,
39
+ // "noPropertyAccessFromIndexSignature": true,
40
+
41
+ // Recommended Options
42
+ "strict": false,
43
+ "jsx": "react-jsx",
44
+ "verbatimModuleSyntax": true,
45
+ "isolatedModules": true,
46
+ "noUncheckedSideEffectImports": true,
47
+ "moduleDetection": "force",
48
+ "skipLibCheck": true,
49
+ }
50
+ }
package/vite.config.js ADDED
@@ -0,0 +1,44 @@
1
+ import path from 'path'
2
+ import { defineConfig } from 'vite'
3
+ import vue from '@vitejs/plugin-vue'
4
+ import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify';
5
+
6
+ export default defineConfig({
7
+ plugins: [
8
+ vue(),
9
+ vuetify({
10
+ autoImport: {
11
+ labs: true
12
+ }
13
+ })
14
+ ],
15
+ build: {
16
+ transpile: ['vuetify'],
17
+ lib: {
18
+ entry: path.resolve(__dirname, 'index.d.ts'),
19
+ name: '@test',
20
+ formats: ['amd', 'cjs'],
21
+ fileName: (format) => `index.${format}.ts`
22
+ },
23
+ css: {
24
+ filename: 'styles/[name].css',
25
+ chunkFilename: 'styles/[name].css',
26
+ },
27
+ js: {
28
+ entryFileNames: 'js/[name].js',
29
+ chunkFileNames: 'js/[name].js',
30
+ },
31
+ rollupOptions: {
32
+ // make sure to externalize deps that shouldn't be bundled
33
+ // into your library
34
+ external: ['vue'],
35
+ output: {
36
+ // Provide global variables to use in the UMD build
37
+ // for externalized deps
38
+ globals: {
39
+ vue: 'Vue'
40
+ }
41
+ }
42
+ }
43
+ }
44
+ })