vuetable-next 1.0.8 → 1.0.10

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.
Files changed (33) hide show
  1. package/README.md +2 -52
  2. package/auto-imports.d.ts +9 -0
  3. package/dist/vuetable-next.js +475 -491
  4. package/dist/vuetable-next.js.map +1 -1
  5. package/dist/vuetable-next.umd.cjs +6 -6
  6. package/dist/vuetable-next.umd.cjs.map +1 -1
  7. package/package.json +87 -87
  8. package/src/assets/vue.svg +1 -0
  9. package/src/components/Demo.vue +17 -0
  10. package/src/components/Vuetable.vue +1216 -0
  11. package/src/components/VuetableColGroup.vue +66 -0
  12. package/src/components/VuetableColGutter.vue +25 -0
  13. package/src/components/VuetableCssSemanticUI.ts +36 -0
  14. package/src/components/VuetableFieldCheckbox.vue +87 -0
  15. package/src/components/VuetableFieldCheckboxMixin.vue +46 -0
  16. package/src/components/VuetableFieldHandle.vue +41 -0
  17. package/src/components/VuetableFieldMixin.vue +30 -0
  18. package/src/components/VuetableFieldSequence.vue +43 -0
  19. package/src/components/VuetablePagination.vue +119 -0
  20. package/src/components/VuetablePaginationDropdown.vue +88 -0
  21. package/src/components/VuetablePaginationInfo.vue +51 -0
  22. package/src/components/VuetablePaginationInfoMixin.vue +64 -0
  23. package/src/components/VuetablePaginationMixin.vue +107 -0
  24. package/src/components/VuetableRowHeader.vue +195 -0
  25. package/src/components/useVuetablePagination.ts +57 -0
  26. package/src/components/useVuetablePaginationInfo.ts +41 -0
  27. package/src/data/fields.ts +102 -0
  28. package/src/data/lang.ts +4 -0
  29. package/src/helpers/toValue.ts +9 -0
  30. package/src/index.ts +57 -0
  31. package/src/main.ts +398 -0
  32. package/src/style.css +79 -0
  33. package/src/vite-env.d.ts +1 -0
package/src/main.ts ADDED
@@ -0,0 +1,398 @@
1
+ import { createApp } from "vue";
2
+ import Vuetable from "./components/Vuetable.vue";
3
+ import VuetablePagination from "./components/VuetablePagination.vue";
4
+ import VuetablePaginationDropdown from "./components/VuetablePaginationDropdown.vue";
5
+ import VuetablePaginationInfo from "./components/VuetablePaginationInfo.vue";
6
+ import type { AxiosResponse } from "axios";
7
+ import sweetAlert from "sweetalert";
8
+
9
+ import VuetableFieldCheckbox from "./components/VuetableFieldCheckbox.vue";
10
+ import VuetableFieldHandle from "./components/VuetableFieldHandle.vue";
11
+ import VuetableFieldSequence from "./components/VuetableFieldSequence.vue";
12
+ import { lang } from "./data/lang";
13
+ import { fields } from "./data/fields";
14
+
15
+ interface Field {
16
+ name: string
17
+ sortField: string | null
18
+ title: string | ((str?: any) => string)
19
+ titleClass: string
20
+ dataClass: string
21
+ formatter: (<T>(...args: any[]) => T) | null
22
+ visible: boolean
23
+ width: string | null
24
+ $_index: number
25
+ [key: string]: unknown
26
+ }
27
+
28
+ const E_SERVER_ERROR = "Error communicating with the server";
29
+
30
+ const app = createApp({
31
+ el: "#app",
32
+ components: {
33
+ Vuetable,
34
+ VuetablePagination,
35
+ VuetablePaginationDropdown,
36
+ VuetablePaginationInfo
37
+ },
38
+ data () {
39
+ return {
40
+ loading: "",
41
+ searchFor: "",
42
+ moreParams: {},
43
+ fields,
44
+ tableHeight: "600px",
45
+ vuetableFields: false,
46
+ fieldPrefix: "vuetable-",
47
+ sortOrder: [{
48
+ field: "name",
49
+ direction: "asc",
50
+ }],
51
+ multiSort: true,
52
+ paginationComponent: "vuetable-pagination",
53
+ perPage: 10,
54
+ paginationInfoTemplate: "Showing record: {from} to {to} from {total} item(s)",
55
+ lang,
56
+ };
57
+ },
58
+
59
+ watch: {
60
+ perPage () {
61
+ this.$nextTick(() => {
62
+ this.$refs.vuetable.refresh();
63
+ });
64
+ },
65
+
66
+ paginationComponent () {
67
+ this.$nextTick(() => {
68
+ this.$refs.pagination.setPaginationData(this.$refs.vuetable.tablePagination);
69
+ });
70
+ }
71
+ },
72
+
73
+ methods: {
74
+ transform (data: any) {
75
+ const transformed = {
76
+ pagination: {},
77
+ data: <any>[]
78
+ };
79
+ transformed.pagination = {
80
+ total: data.total,
81
+ per_page: data.per_page,
82
+ current_page: data.current_page,
83
+ last_page: data.last_page,
84
+ next_page_url: data.next_page_url,
85
+ prev_page_url: data.prev_page_url,
86
+ from: data.from,
87
+ to: data.to
88
+ };
89
+
90
+ transformed.data = [];
91
+ data = data.data;
92
+ for (let i = 0; i < data.length; i++) {
93
+ transformed.data.push({
94
+ id: data[i].id,
95
+ name: data[i].name,
96
+ nickname: data[i].nickname,
97
+ email: data[i].email,
98
+ age: data[i].age,
99
+ birthdate: data[i].birthdate,
100
+ gender: data[i].gender,
101
+ address: data[i].address.line1 + " " + data[i].address.line2 + " " + data[i].address.zipcode
102
+ });
103
+ }
104
+
105
+ return transformed;
106
+ },
107
+ showSettingsModal () {
108
+ // @ts-expect-error
109
+ $("#settingsModal").modal({
110
+ detachable: true,
111
+ onVisible () {
112
+ // @ts-expect-error
113
+ $(".ui.checkbox").checkbox();
114
+ }
115
+ }).modal("show");
116
+ },
117
+ showLoader () {
118
+ this.loading = "loading";
119
+ },
120
+ hideLoader () {
121
+ this.loading = "";
122
+ },
123
+ setFilter () {
124
+ this.moreParams.filter = this.searchFor;
125
+ this.$nextTick(() => {
126
+ this.$refs.vuetable.refresh();
127
+ });
128
+ },
129
+ resetFilter () {
130
+ this.searchFor = "";
131
+ this.setFilter();
132
+ },
133
+ pregQuote (str: string) {
134
+ // http://kevin.vanzonneveld.net
135
+ // + original by: booeyOH
136
+ // + improved by: Ates Goral (http://magnetiq.com)
137
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
138
+ // + bugfixed by: Onno Marsman
139
+ // * example 1: preg_quote("$40");
140
+ // * returns 1: '\$40'
141
+ // * example 2: preg_quote("*RRRING* Hello?");
142
+ // * returns 2: '\*RRRING\* Hello\?'
143
+ // * example 3: preg_quote("\\.+*?[^]$(){}=!<>|:");
144
+ // * returns 3: '\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:'
145
+ return (str+"").replace(/([\\.+*?[^\]$(){}=!<>|:])/g, "\\$1");
146
+ },
147
+ highlight (needle: string, haystack: string) {
148
+ return haystack.replace(
149
+ new RegExp("(" + this.pregQuote(needle) + ")", "ig"),
150
+ "<span class=\"highlight\">$1</span>"
151
+ );
152
+ },
153
+ rowClassCB (_: any, index: number) {
154
+ return (index % 2) === 0 ? "odd" : "even";
155
+ },
156
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
157
+ onCellClicked (data: any, field: any, _: Event) {
158
+ console.log("cellClicked", field.name);
159
+ if (field.name !== this.fieldPrefix+"actions") {
160
+ this.$refs.vuetable.toggleDetailRow(data.id);
161
+ }
162
+ },
163
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
164
+ onCellDoubleClicked (data: any, field: any, event: Event) {
165
+ console.log("cellDoubleClicked:", field.name, data, event);
166
+ },
167
+ onCellRightClicked (data: any, field: any, event: Event) {
168
+ console.log("cellRightClicked:", field.name, data, event);
169
+ },
170
+ onLoadSuccess (response: AxiosResponse) {
171
+ // set pagination data to pagination-info component
172
+ this.$refs.paginationInfo.setPaginationData(response.data);
173
+
174
+ const data = response.data.data;
175
+ if (this.searchFor !== "") {
176
+ for (const n in data) {
177
+ data[n].name = this.highlight(this.searchFor, data[n].name);
178
+ data[n].email = this.highlight(this.searchFor, data[n].email);
179
+ }
180
+ }
181
+ },
182
+ onLoadError (response: AxiosResponse) {
183
+ if (response.status == 400) {
184
+ sweetAlert("Something's Wrong!", response.data.message, "error");
185
+ } else {
186
+ sweetAlert("Oops", E_SERVER_ERROR, "error");
187
+ }
188
+ },
189
+ onPaginationData (tablePagination: any) {
190
+ this.$refs.paginationInfo.setPaginationData(tablePagination);
191
+ this.$refs.pagination.setPaginationData(tablePagination);
192
+ },
193
+ onChangePage (page: number) {
194
+ this.$refs.vuetable.changePage(page);
195
+ },
196
+ onInitialized (fields: any) {
197
+ console.log("onInitialized", fields);
198
+ this.vuetableFields = fields;
199
+ },
200
+ onDataReset () {
201
+ console.log("onDataReset");
202
+ this.$refs.paginationInfo.resetData();
203
+ this.$refs.pagination.resetData();
204
+ },
205
+ onActionClicked (action: any, data: any) {
206
+ console.log("slot actions: on-click", data.name);
207
+ sweetAlert(action, data.name);
208
+ },
209
+ onFieldEvent (type: string, payload: any, vuetable: any) {
210
+ if (type === "checkbox-toggled") {
211
+ vuetable.onCheckboxToggled(payload.isChecked, payload.field, payload.dataItem);
212
+ } else if (type === "checkbox-toggled-all") {
213
+ vuetable.onCheckboxToggledAll(payload.isChecked, payload.field);
214
+ }
215
+ },
216
+ onHeaderEvent (type: string, payload: any) {
217
+ console.log("onHeaderEvent:", type, payload);
218
+ const vuetable = this.$refs.vuetable;
219
+ switch (type) {
220
+ case "order-by":
221
+ vuetable.orderBy(payload.field, payload.event);
222
+ break;
223
+ case "refresh":
224
+ vuetable.refresh();
225
+ break;
226
+ case "add-sort-column":
227
+ vuetable.addSortColumn(payload.field, payload.direction);
228
+ break;
229
+ case "remove-sort-column":
230
+ vuetable.removeSortColumn(payload.index);
231
+ break;
232
+ case "set-sort-column":
233
+ vuetable.setSortColumnDirection(payload.index, payload.direction);
234
+ break;
235
+ case "clear-sort-column":
236
+ vuetable.clearSortOrder();
237
+ break;
238
+ case "toggle-row":
239
+ vuetable.onCheckboxToggled(payload.isChecked, payload.field, payload.dataItem);
240
+ break;
241
+ case "toggle-all-rows":
242
+ vuetable.onCheckboxToggledAll(payload.isChecked, payload.field);
243
+ break;
244
+ case "filter":
245
+ break;
246
+ default:
247
+ console.log("Unhandled event: ", type, payload);
248
+ }
249
+ }
250
+ }
251
+ });
252
+
253
+ app.component("custom-actions", {
254
+ template: [
255
+ "<div>",
256
+ "<button class=\"ui red button\" @click=\"onClick('view-item', rowData)\"><i class=\"zoom icon\"></i></button>",
257
+ "<button class=\"ui blue button\" @click=\"onClick('edit-item', rowData)\"><i class=\"edit icon\"></i></button>",
258
+ "<button class=\"ui green button\" @click=\"onClick('delete-item', rowData)\"><i class=\"delete icon\"></i></button>",
259
+ "</div>"
260
+ ].join(""),
261
+ props: {
262
+ rowData: {
263
+ type: Object,
264
+ required: true
265
+ }
266
+ },
267
+ methods: {
268
+ onClick (action: any, data: any) {
269
+ console.log("actions: on-click", data.name);
270
+ sweetAlert(action, data.name);
271
+ },
272
+ }
273
+ });
274
+
275
+ app.component("my-detail-row", {
276
+ template: [
277
+ "<div @click=\"onClick\">",
278
+ "<div class=\"inline field\">",
279
+ "<label>Name: </label>",
280
+ "<span>{{rowData.name}}</span>",
281
+ "</div>",
282
+ "<div class=\"inline field\">",
283
+ "<label>Email: </label>",
284
+ "<span>{{rowData.email}}</span>",
285
+ "</div>",
286
+ "<div class=\"inline field\">",
287
+ "<label>Nickname: </label>",
288
+ "<span>{{rowData.nickname}}</span>",
289
+ "</div>",
290
+ "<div class=\"inline field\">",
291
+ "<label>Birthdate: </label>",
292
+ "<span>{{rowData.birthdate}}</span>",
293
+ "</div>",
294
+ "<div class=\"inline field\">",
295
+ "<label>Gender: </label>",
296
+ "<span>{{rowData.gender}}</span>",
297
+ "</div>",
298
+ "</div>"
299
+ ].join(""),
300
+ props: {
301
+ rowData: {
302
+ type: Object,
303
+ required: true
304
+ }
305
+ },
306
+ methods: {
307
+ onClick (event: Event) {
308
+ console.log("my-detail-row: on-click", event.target);
309
+ }
310
+ },
311
+ });
312
+
313
+ app.component("settings-modal", {
314
+ template: `
315
+ <div class="ui small modal" id="settingsModal">
316
+ <div class="header">Settings</div>
317
+ <div class="content ui form">
318
+ <div class="field">
319
+ <div class="ui checkbox">
320
+ <input type="checkbox" v-model="$parent.multiSort">
321
+ <label>Multisort (use Alt+Click)</label>
322
+ </div>
323
+ </div>
324
+ <div class="ui divider"></div>
325
+ <div class="field">
326
+ <label>Pagination:</label>
327
+ <select class="ui simple dropdown" v-model="$parent.paginationComponent">
328
+ <option value="vuetable-pagination">vuetable-pagination</option>
329
+ <option value="vuetable-pagination-dropdown">vuetable-pagination-dropdown</option>
330
+ </select>
331
+ </div>
332
+ <div class="field">
333
+ <label>Per Page:</label>
334
+ <select class="ui simple dropdown" v-model="$parent.perPage">
335
+ <option :value="10">10</option>
336
+ <option :value="15">15</option>
337
+ <option :value="20">20</option>
338
+ <option :value="25">25</option>
339
+ </select>
340
+ </div>
341
+ <div class="ui fluid card">
342
+ <div class="content">
343
+ <div class="header">Visible fields</div>
344
+ </div>
345
+ <div v-if="vuetableFields" class="content">
346
+ <div v-for="(field, idx) in vuetableFields" class="field">
347
+ <div class="ui checkbox">
348
+ <input type="checkbox" :checked="field.visible" @change="toggleField(idx, $event)">
349
+ <label>{{ getFieldTitle(field) }}</label>
350
+ </div>
351
+ </div>
352
+ </div>
353
+ </div>
354
+ </div>
355
+ <div class="actions">
356
+ <div class="ui cancel button">Close</div>
357
+ </div>
358
+ </div>
359
+ `,
360
+ props: ["vuetableFields", "fieldPrefix"],
361
+ data () {
362
+ return {
363
+ };
364
+ },
365
+ methods: {
366
+ getFieldTitle (field: Field) {
367
+ if (typeof(field.title) === "function") return field.title(true);
368
+
369
+ let title = field.title;
370
+ if (title !== "") return this.stripHTML(title);
371
+
372
+ title = "";
373
+ // @ts-ignore
374
+ if (field.name.slice(0, 2) === this.fieldPrefix) {
375
+ title = field.name.indexOf(":") >= 0
376
+ ? field.name.split(":")[1]
377
+ // @ts-ignore
378
+ : field.name.replace(this.fieldPrefix, "");
379
+ }
380
+
381
+ return title;
382
+ },
383
+ stripHTML (str: string) {
384
+ return str ? str.replace(/(<([^>]+)>)/ig,"") : "";
385
+ },
386
+ toggleField (index: number, event: Event & { target: { checked: boolean } }) {
387
+ console.log("toggleField: ", index, event.target.checked);
388
+ // @ts-ignore
389
+ this.$parent.$refs.vuetable.toggleField(index);
390
+ }
391
+ }
392
+ });
393
+
394
+ app.component("vuetable-field-checkbox", VuetableFieldCheckbox);
395
+ app.component("vuetable-field-handle", VuetableFieldHandle);
396
+ app.component("vuetable-field-sequence", VuetableFieldSequence);
397
+
398
+ app.mount("#app");
package/src/style.css ADDED
@@ -0,0 +1,79 @@
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
+ }
15
+
16
+ a {
17
+ font-weight: 500;
18
+ color: #646cff;
19
+ text-decoration: inherit;
20
+ }
21
+ a:hover {
22
+ color: #535bf2;
23
+ }
24
+
25
+ body {
26
+ margin: 0;
27
+ display: flex;
28
+ place-items: center;
29
+ min-width: 320px;
30
+ min-height: 100vh;
31
+ }
32
+
33
+ h1 {
34
+ font-size: 3.2em;
35
+ line-height: 1.1;
36
+ }
37
+
38
+ button {
39
+ border-radius: 8px;
40
+ border: 1px solid transparent;
41
+ padding: 0.6em 1.2em;
42
+ font-size: 1em;
43
+ font-weight: 500;
44
+ font-family: inherit;
45
+ background-color: #1a1a1a;
46
+ cursor: pointer;
47
+ transition: border-color 0.25s;
48
+ }
49
+ button:hover {
50
+ border-color: #646cff;
51
+ }
52
+ button:focus,
53
+ button:focus-visible {
54
+ outline: 4px auto -webkit-focus-ring-color;
55
+ }
56
+
57
+ .card {
58
+ padding: 2em;
59
+ }
60
+
61
+ #app {
62
+ max-width: 1280px;
63
+ margin: 0 auto;
64
+ padding: 2rem;
65
+ text-align: center;
66
+ }
67
+
68
+ @media (prefers-color-scheme: light) {
69
+ :root {
70
+ color: #213547;
71
+ background-color: #ffffff;
72
+ }
73
+ a:hover {
74
+ color: #747bff;
75
+ }
76
+ button {
77
+ background-color: #f9f9f9;
78
+ }
79
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />