vi-grid-builder 0.0.1 → 0.0.3

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.
@@ -1,5 +1,7 @@
1
1
  import ViGridBuilder from "./src/ViGridBuilder.vue"
2
2
  import ViPaginationPlugin from 'vi-pagination'
3
+ import fieldMixin from "./src/mixins/field-mixin.js"
4
+ import {useGridActions} from "./src/composables/useGridActions.js"
3
5
  export default {
4
6
  install(app, options ={pagination:{}, fieldComponents:{}, defaultSlots:{}}) {
5
7
 
@@ -19,8 +21,22 @@ export default {
19
21
 
20
22
  return options?.defaultSlots ?? {}
21
23
  }
24
+ },
25
+ noDataLabel:{
26
+ type: String,
27
+ default: options.noDataLabel ?? 'No data found'
28
+ },
29
+ noCellDataLabel:{
30
+ type: String,
31
+ default: options.noCellDataLabel ?? '/'
22
32
  }
23
33
  }
24
34
  });
25
35
  }
26
- };
36
+ };
37
+ const mixins = {fieldMixin};
38
+ const composables = {useGridActions};
39
+ export {
40
+ mixins,
41
+ composables
42
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vi-grid-builder",
3
3
  "main": "ViGridBuilderPlugin",
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -9,7 +9,7 @@
9
9
  "preview": "vite preview"
10
10
  },
11
11
  "dependencies": {
12
- "vi-pagination": "^0.0.2",
12
+ "vi-pagination": "^0.0.4",
13
13
  "vue": "^3.3.4"
14
14
  },
15
15
  "devDependencies": {
@@ -25,9 +25,17 @@
25
25
  </td>
26
26
  </tr>
27
27
  </tbody>
28
- <tbody v-else class="table-body">
29
28
 
30
- <tr v-for="row in currentVisibleRows" :key="row[rowKey]">
29
+ <tbody v-else-if="!currentVisibleRows.length" class="table-body">
30
+ <tr>
31
+ <slot name="empty-data">
32
+ <component v-if="defaultSlots.noRows" :is="defaultSlots.noRows"/>
33
+ <td v-else :colspan="columns.length" align="center">{{noDataLabel}}</td>
34
+ </slot>
35
+ </tr>
36
+ </tbody>
37
+ <tbody v-else class="table-body">
38
+ <tr v-for="row in currentVisibleRows" :key="row[rowKey]">
31
39
 
32
40
  <td v-for="column in columns" :key="column.name">
33
41
  <vi-grid-field
@@ -116,6 +124,13 @@
116
124
  },
117
125
  defaultSlots: {
118
126
  type: Object
127
+ },
128
+ noDataLabel: {
129
+ type: String,
130
+ },
131
+ noCellDataLabel: {
132
+ type: String,
133
+ default:'/'
119
134
  }
120
135
  },
121
136
  data: () => ({search: null, isFetchingData: false}),
@@ -1,28 +1,31 @@
1
1
  <template>
2
- <div class="vi-grid-field">
3
- <component
4
- v-if="fieldComponent"
5
- v-bind:is="fieldComponent"
6
- :field="field"
7
- :value="fieldValue"
8
- :row="rowValue"
9
- />
10
- <slot v-else name="custom-field" :field="field"
11
- :value="fieldValue"
12
- :row="rowValue">
13
- </slot>
2
+ <div class="vi-grid-field">
3
+ <component
4
+ v-if="fieldComponent"
5
+ v-bind:is="fieldComponent"
6
+ :field="field"
7
+ :value="filedValueFormatted"
8
+ :original-value="fieldValue"
9
+ :row="rowValue"
10
+ />
11
+ <slot v-else name="custom-field"
12
+ :field="field"
13
+ :value="fieldValue"
14
+ :original-value="fieldValue"
15
+ :row="rowValue">
16
+ </slot>
14
17
 
15
- </div>
18
+ </div>
16
19
  </template>
17
20
 
18
21
  <script>
19
22
  const snakeToCamel = str =>
20
- str.toLowerCase().replace(/([-_][a-z])/g, group =>
21
- group
22
- .toUpperCase()
23
- .replace('-', '')
24
- .replace('_', '')
25
- );
23
+ str.toLowerCase().replace(/([-_][a-z])/g, group =>
24
+ group
25
+ .toUpperCase()
26
+ .replace('-', '')
27
+ .replace('_', '')
28
+ );
26
29
  const uppercaseFirstLetter = str => str.charAt(0).toUpperCase() + str.slice(1);
27
30
 
28
31
  import ViGridBadge from "./fields/ViGridBadge.vue";
@@ -31,9 +34,10 @@
31
34
  import ViGridDate from "./fields/ViGridDate.vue";
32
35
  import ViGridActions from "./fields/ViGridActions.vue";
33
36
  import ViGridLink from "./fields/ViGridLink.vue";
37
+
34
38
  export default {
35
39
  name: "ViGridField",
36
- components:{
40
+ components: {
37
41
  ViGridBadge,
38
42
  ViGridImage,
39
43
  ViGridText,
@@ -48,9 +52,15 @@
48
52
  },
49
53
  fieldValue: {},
50
54
  rowValue: {},
55
+ noDataLabel: {
56
+ type: String,
57
+ default: '/'
58
+ }
51
59
  },
52
60
  computed: {
53
-
61
+ filedValueFormatted() {
62
+ return this.fieldValue ?? this.noDataLabel
63
+ },
54
64
  fieldComponent() {
55
65
  let component = uppercaseFirstLetter(snakeToCamel(this.field.type))
56
66
 
@@ -65,5 +75,5 @@
65
75
  </script>
66
76
 
67
77
  <style lang="scss">
68
- @import "ViGridField";
78
+ @import "ViGridField";
69
79
  </style>
@@ -0,0 +1,18 @@
1
+ import {computed } from 'vue';
2
+
3
+ export function useGridActions(props) {
4
+
5
+ const visibleActions = computed(() => props.field.actions.filter((action ) => {
6
+ if (action.isVisible === undefined) {
7
+ return true
8
+
9
+ }
10
+ return action.isVisible(props.row)
11
+
12
+ }));
13
+
14
+ // Return the computed variable
15
+ return {
16
+ visibleActions,
17
+ };
18
+ }
@@ -1,54 +1,51 @@
1
1
  <template>
2
- <div class="vi-grid-actions">
2
+ <div class="vi-grid-actions">
3
3
 
4
- <vi-grid-kebab-menu
5
- v-if="field.kebab"
6
- :actions="visibleActions"
7
- @actionClicked="$action => $emit(`action-clicked`, {action:$action, row})"
8
- />
4
+ <vi-grid-kebab-menu
5
+ v-if="field.kebab"
6
+ :actions="visibleActions"
7
+ @actionClicked="$action => $emit(`action-clicked`, {action:$action, row})"
8
+ />
9
9
 
10
- <vi-grid-builder-actions
11
- v-else
12
- :actions="visibleActions"
10
+ <vi-grid-builder-actions
11
+ v-else
12
+ :actions="visibleActions"
13
13
 
14
- />
14
+ />
15
15
 
16
- </div>
16
+ </div>
17
17
  </template>
18
18
 
19
19
  <script>
20
20
  import ViGridKebabMenu from "./partials/ViGridKebabMenu.vue";
21
21
  import ViGridBuilderActions from "./partials/ViGridBuilderActions.vue";
22
22
 
23
+ import {useGridActions} from "../composables/useGridActions.js"
24
+ import fieldMixin from "../mixins/field-mixin.js"
25
+
23
26
  export default {
24
27
  name: "ViGridActions",
28
+ mixins: [fieldMixin],
25
29
  components: {ViGridBuilderActions, ViGridKebabMenu},
26
30
  props: {
27
31
  field: {
28
32
  type: Object,
29
33
  required: true
30
34
  },
31
- row:{
32
-
33
- }
34
-
35
+ row: {}
35
36
  },
36
- computed:{
37
- visibleActions() {
38
- return this.field.actions.filter((action ) => {
39
- if (action.isVisible === undefined) {
40
- return true
41
37
 
42
- }
43
- return action.isVisible(this.row)
38
+ setup() {
39
+ const {visibleActions} = useGridActions();
44
40
 
45
- })
46
- }
47
- },
41
+ return {
42
+ visibleActions,
43
+ };
44
+ }
48
45
 
49
46
  }
50
47
  </script>
51
48
 
52
49
  <style lang="scss">
53
- @import "ViGridActions";
50
+ @import "ViGridActions";
54
51
  </style>
@@ -0,0 +1,13 @@
1
+ export default {
2
+ props: {
3
+ value: {},
4
+ field: {
5
+ type: Object,
6
+ required: true
7
+ },
8
+ row: {
9
+ type: Object,
10
+ required: true
11
+ },
12
+ }
13
+ }
package/index.html DELETED
@@ -1,13 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Vite + Vue</title>
8
- </head>
9
- <body>
10
- <div id="app"></div>
11
- <script type="module" src="/src/examples/main.js"></script>
12
- </body>
13
- </html>
package/src/style.css DELETED
@@ -1,89 +0,0 @@
1
- :root {
2
- font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3
- line-height: 1.5;
4
- font-weight: 400;
5
-
6
- color-scheme: light dark;
7
- color: rgba(255, 255, 255, 0.87);
8
- background-color: #242424;
9
-
10
- font-synthesis: none;
11
- text-rendering: optimizeLegibility;
12
- -webkit-font-smoothing: antialiased;
13
- -moz-osx-font-smoothing: grayscale;
14
- -webkit-text-size-adjust: 100%;
15
- }
16
-
17
- a {
18
- font-weight: 500;
19
- color: #646cff;
20
- text-decoration: inherit;
21
- }
22
- a:hover {
23
- color: #535bf2;
24
- }
25
-
26
- a {
27
- font-weight: 500;
28
- color: #646cff;
29
- text-decoration: inherit;
30
- }
31
- a:hover {
32
- color: #535bf2;
33
- }
34
-
35
- body {
36
- margin: 0;
37
- display: flex;
38
- place-items: center;
39
- min-width: 320px;
40
- min-height: 100vh;
41
- }
42
-
43
- h1 {
44
- font-size: 3.2em;
45
- line-height: 1.1;
46
- }
47
-
48
- button {
49
- border-radius: 8px;
50
- border: 1px solid transparent;
51
- padding: 0.6em 1.2em;
52
- font-size: 1em;
53
- font-weight: 500;
54
- font-family: inherit;
55
- background-color: #1a1a1a;
56
- cursor: pointer;
57
- transition: border-color 0.25s;
58
- }
59
- button:hover {
60
- border-color: #646cff;
61
- }
62
- button:focus,
63
- button:focus-visible {
64
- outline: 4px auto -webkit-focus-ring-color;
65
- }
66
-
67
- .card {
68
- padding: 2em;
69
- }
70
-
71
- #app {
72
- max-width: 1280px;
73
- margin: 0 auto;
74
- padding: 2rem;
75
- text-align: center;
76
- }
77
-
78
- @media (prefers-color-scheme: light) {
79
- :root {
80
- color: #213547;
81
- background-color: #ffffff;
82
- }
83
- a:hover {
84
- color: #747bff;
85
- }
86
- button {
87
- background-color: #f9f9f9;
88
- }
89
- }