@doyosi/laraisy 1.0.1 → 1.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.
Files changed (51) hide show
  1. package/LICENSE +1 -1
  2. package/package.json +1 -1
  3. package/src/CodeInput.js +48 -48
  4. package/src/DSAlert.js +352 -352
  5. package/src/DSAvatar.js +207 -207
  6. package/src/DSDelete.js +274 -274
  7. package/src/DSForm.js +568 -568
  8. package/src/DSGridOrTable.js +453 -453
  9. package/src/DSLocaleSwitcher.js +239 -239
  10. package/src/DSLogout.js +293 -293
  11. package/src/DSNotifications.js +365 -365
  12. package/src/DSRestore.js +181 -181
  13. package/src/DSSelect.js +1071 -1071
  14. package/src/DSSelectBox.js +563 -563
  15. package/src/DSSimpleSlider.js +517 -517
  16. package/src/DSSvgFetch.js +69 -69
  17. package/src/DSTable/DSTableExport.js +68 -68
  18. package/src/DSTable/DSTableFilter.js +224 -224
  19. package/src/DSTable/DSTablePagination.js +136 -136
  20. package/src/DSTable/DSTableSearch.js +40 -40
  21. package/src/DSTable/DSTableSelection.js +192 -192
  22. package/src/DSTable/DSTableSort.js +58 -58
  23. package/src/DSTable.js +353 -353
  24. package/src/DSTabs.js +488 -488
  25. package/src/DSUpload.js +887 -887
  26. package/dist/CodeInput.d.ts +0 -10
  27. package/dist/DSAlert.d.ts +0 -112
  28. package/dist/DSAvatar.d.ts +0 -45
  29. package/dist/DSDelete.d.ts +0 -61
  30. package/dist/DSForm.d.ts +0 -151
  31. package/dist/DSGridOrTable/DSGOTRenderer.d.ts +0 -60
  32. package/dist/DSGridOrTable/DSGOTViewToggle.d.ts +0 -26
  33. package/dist/DSGridOrTable.d.ts +0 -296
  34. package/dist/DSLocaleSwitcher.d.ts +0 -71
  35. package/dist/DSLogout.d.ts +0 -76
  36. package/dist/DSNotifications.d.ts +0 -54
  37. package/dist/DSRestore.d.ts +0 -56
  38. package/dist/DSSelect.d.ts +0 -221
  39. package/dist/DSSelectBox.d.ts +0 -123
  40. package/dist/DSSimpleSlider.d.ts +0 -136
  41. package/dist/DSSvgFetch.d.ts +0 -17
  42. package/dist/DSTable/DSTableExport.d.ts +0 -11
  43. package/dist/DSTable/DSTableFilter.d.ts +0 -40
  44. package/dist/DSTable/DSTablePagination.d.ts +0 -12
  45. package/dist/DSTable/DSTableSearch.d.ts +0 -8
  46. package/dist/DSTable/DSTableSelection.d.ts +0 -46
  47. package/dist/DSTable/DSTableSort.d.ts +0 -8
  48. package/dist/DSTable.d.ts +0 -116
  49. package/dist/DSTabs.d.ts +0 -156
  50. package/dist/DSUpload.d.ts +0 -220
  51. package/dist/index.d.ts +0 -17
package/src/DSRestore.js CHANGED
@@ -1,181 +1,181 @@
1
- import { DSAlert } from './DSAlert.js';
2
-
3
- /**
4
- * DSRestore
5
- *
6
- * A plugin to handle restore actions with confirmation dialogs and AJAX requests.
7
- * Integrates with DSAlert for UI.
8
- */
9
- export class DSRestore {
10
- static defaults = {
11
- selector: '[data-restore]',
12
- method: 'PATCH',
13
- ajaxFunction: 'axios', // axios | fetch
14
-
15
- // Confirmation Dialog
16
- title: 'Are you sure?',
17
- text: "You are about to restore this item.",
18
- icon: 'question',
19
- confirmButtonText: 'Yes, restore it!',
20
- cancelButtonText: 'Cancel',
21
- confirmButtonColor: 'btn btn-sm btn-success', // Positive action for restore
22
-
23
- // Success Dialog
24
- successTitle: 'Restored!',
25
- successText: 'Item has been restored successfully.',
26
- successIcon: 'success',
27
-
28
- // Error Dialog
29
- errorTitle: 'Error!',
30
- errorText: 'Something went wrong.',
31
- errorIcon: 'error',
32
-
33
- // Callbacks
34
- onSuccess: null, // function(response, element)
35
- onError: null, // function(error, element)
36
- onRestore: null, // function(element) - before restore, return false to cancel
37
- };
38
-
39
- constructor(options = {}) {
40
- this.config = { ...DSRestore.defaults, ...options };
41
- this._init();
42
- }
43
-
44
- _init() {
45
- // Event Delegation
46
- document.addEventListener('click', (e) => {
47
- const trigger = e.target.closest(this.config.selector);
48
- if (trigger) {
49
- e.preventDefault();
50
- this._handleRestore(trigger);
51
- }
52
- });
53
- }
54
-
55
- async _handleRestore(element) {
56
- // Allow cancellation via hook
57
- if (this.config.onRestore && this.config.onRestore(element) === false) {
58
- return;
59
- }
60
-
61
- const url = element.dataset.restore || element.getAttribute('href');
62
- const id = element.dataset.restoreId;
63
-
64
- if (!url) {
65
- console.error('DSRestore: No restore URL found on element', element);
66
- return;
67
- }
68
-
69
- const contentTitle = element.dataset.restoreTitle ? `"${element.dataset.restoreTitle}"` : '';
70
- const confirmText = contentTitle ? `${this.config.text} ${contentTitle}` : this.config.text;
71
-
72
- const confirmed = await DSAlert.fire({
73
- title: this.config.title,
74
- text: confirmText,
75
- icon: this.config.icon,
76
- showCancelButton: true,
77
- confirmButtonText: this.config.confirmButtonText,
78
- cancelButtonText: this.config.cancelButtonText,
79
- confirmButtonColor: this.config.confirmButtonColor
80
- });
81
-
82
- if (confirmed.isConfirmed) {
83
- this._performRestore(url, id, element);
84
- }
85
- }
86
-
87
- async _performRestore(url, id, element) {
88
- try {
89
- this._emit('restore:start', { element, url, id });
90
-
91
- let response;
92
- const data = id ? { id } : {};
93
-
94
- if (this.config.ajaxFunction === 'axios' && window.axios) {
95
- response = await window.axios({
96
- method: this.config.method,
97
- url: url,
98
- data: data
99
- });
100
- // Axios returns data in response.data
101
- await this._handleSuccess(response.data, element);
102
- } else if (this.config.ajaxFunction === 'fetch' || window.fetch) {
103
- const options = {
104
- method: this.config.method,
105
- headers: {
106
- 'Content-Type': 'application/json',
107
- 'Accept': 'application/json',
108
- 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.content
109
- },
110
- body: JSON.stringify(data)
111
- };
112
- const res = await fetch(url, options);
113
- const json = await res.json();
114
-
115
- if (!res.ok) throw { response: res, data: json };
116
-
117
- await this._handleSuccess(json, element);
118
- } else {
119
- throw new Error('DSRestore: No valid ajax function found');
120
- }
121
-
122
- } catch (error) {
123
- this._handleError(error, element);
124
- }
125
- }
126
-
127
- async _handleSuccess(response, element) {
128
- // Standard Laravel response: { success: true, message: '...' }
129
- const message = response.message || this.config.successText;
130
-
131
- // Fire Success Alert
132
- await DSAlert.fire({
133
- title: this.config.successTitle,
134
- text: message,
135
- icon: this.config.successIcon,
136
- timer: 2000,
137
- timerProgressBar: true
138
- });
139
-
140
- if (this.config.onSuccess) {
141
- this.config.onSuccess(response, element);
142
- }
143
-
144
- this._emit('restore:success', { response, element });
145
-
146
- // Optional: Remove row from table if inside one (assuming we are in trash view)
147
- const row = element.closest('tr');
148
- if (row) {
149
- row.remove();
150
- }
151
- }
152
-
153
- _handleError(error, element) {
154
- console.error('DSRestore Error:', error);
155
-
156
- let message = this.config.errorText;
157
- if (error.response && error.response.data && error.response.data.message) {
158
- message = error.response.data.message;
159
- } else if (error.data && error.data.message) {
160
- message = error.data.message;
161
- }
162
-
163
- DSAlert.fire({
164
- title: this.config.errorTitle,
165
- text: message,
166
- icon: this.config.errorIcon
167
- });
168
-
169
- if (this.config.onError) {
170
- this.config.onError(error, element);
171
- }
172
-
173
- this._emit('restore:error', { error, element });
174
- }
175
-
176
- _emit(event, detail = {}) {
177
- document.dispatchEvent(new CustomEvent(`ds:${event}`, { bubbles: true, detail }));
178
- }
179
- }
180
-
181
- export default DSRestore;
1
+ import { DSAlert } from './DSAlert.js';
2
+
3
+ /**
4
+ * DSRestore
5
+ *
6
+ * A plugin to handle restore actions with confirmation dialogs and AJAX requests.
7
+ * Integrates with DSAlert for UI.
8
+ */
9
+ export class DSRestore {
10
+ static defaults = {
11
+ selector: '[data-restore]',
12
+ method: 'PATCH',
13
+ ajaxFunction: 'axios', // axios | fetch
14
+
15
+ // Confirmation Dialog
16
+ title: 'Are you sure?',
17
+ text: "You are about to restore this item.",
18
+ icon: 'question',
19
+ confirmButtonText: 'Yes, restore it!',
20
+ cancelButtonText: 'Cancel',
21
+ confirmButtonColor: 'btn btn-sm btn-success', // Positive action for restore
22
+
23
+ // Success Dialog
24
+ successTitle: 'Restored!',
25
+ successText: 'Item has been restored successfully.',
26
+ successIcon: 'success',
27
+
28
+ // Error Dialog
29
+ errorTitle: 'Error!',
30
+ errorText: 'Something went wrong.',
31
+ errorIcon: 'error',
32
+
33
+ // Callbacks
34
+ onSuccess: null, // function(response, element)
35
+ onError: null, // function(error, element)
36
+ onRestore: null, // function(element) - before restore, return false to cancel
37
+ };
38
+
39
+ constructor(options = {}) {
40
+ this.config = { ...DSRestore.defaults, ...options };
41
+ this._init();
42
+ }
43
+
44
+ _init() {
45
+ // Event Delegation
46
+ document.addEventListener('click', (e) => {
47
+ const trigger = e.target.closest(this.config.selector);
48
+ if (trigger) {
49
+ e.preventDefault();
50
+ this._handleRestore(trigger);
51
+ }
52
+ });
53
+ }
54
+
55
+ async _handleRestore(element) {
56
+ // Allow cancellation via hook
57
+ if (this.config.onRestore && this.config.onRestore(element) === false) {
58
+ return;
59
+ }
60
+
61
+ const url = element.dataset.restore || element.getAttribute('href');
62
+ const id = element.dataset.restoreId;
63
+
64
+ if (!url) {
65
+ console.error('DSRestore: No restore URL found on element', element);
66
+ return;
67
+ }
68
+
69
+ const contentTitle = element.dataset.restoreTitle ? `"${element.dataset.restoreTitle}"` : '';
70
+ const confirmText = contentTitle ? `${this.config.text} ${contentTitle}` : this.config.text;
71
+
72
+ const confirmed = await DSAlert.fire({
73
+ title: this.config.title,
74
+ text: confirmText,
75
+ icon: this.config.icon,
76
+ showCancelButton: true,
77
+ confirmButtonText: this.config.confirmButtonText,
78
+ cancelButtonText: this.config.cancelButtonText,
79
+ confirmButtonColor: this.config.confirmButtonColor
80
+ });
81
+
82
+ if (confirmed.isConfirmed) {
83
+ this._performRestore(url, id, element);
84
+ }
85
+ }
86
+
87
+ async _performRestore(url, id, element) {
88
+ try {
89
+ this._emit('restore:start', { element, url, id });
90
+
91
+ let response;
92
+ const data = id ? { id } : {};
93
+
94
+ if (this.config.ajaxFunction === 'axios' && window.axios) {
95
+ response = await window.axios({
96
+ method: this.config.method,
97
+ url: url,
98
+ data: data
99
+ });
100
+ // Axios returns data in response.data
101
+ await this._handleSuccess(response.data, element);
102
+ } else if (this.config.ajaxFunction === 'fetch' || window.fetch) {
103
+ const options = {
104
+ method: this.config.method,
105
+ headers: {
106
+ 'Content-Type': 'application/json',
107
+ 'Accept': 'application/json',
108
+ 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.content
109
+ },
110
+ body: JSON.stringify(data)
111
+ };
112
+ const res = await fetch(url, options);
113
+ const json = await res.json();
114
+
115
+ if (!res.ok) throw { response: res, data: json };
116
+
117
+ await this._handleSuccess(json, element);
118
+ } else {
119
+ throw new Error('DSRestore: No valid ajax function found');
120
+ }
121
+
122
+ } catch (error) {
123
+ this._handleError(error, element);
124
+ }
125
+ }
126
+
127
+ async _handleSuccess(response, element) {
128
+ // Standard Laravel response: { success: true, message: '...' }
129
+ const message = response.message || this.config.successText;
130
+
131
+ // Fire Success Alert
132
+ await DSAlert.fire({
133
+ title: this.config.successTitle,
134
+ text: message,
135
+ icon: this.config.successIcon,
136
+ timer: 2000,
137
+ timerProgressBar: true
138
+ });
139
+
140
+ if (this.config.onSuccess) {
141
+ this.config.onSuccess(response, element);
142
+ }
143
+
144
+ this._emit('restore:success', { response, element });
145
+
146
+ // Optional: Remove row from table if inside one (assuming we are in trash view)
147
+ const row = element.closest('tr');
148
+ if (row) {
149
+ row.remove();
150
+ }
151
+ }
152
+
153
+ _handleError(error, element) {
154
+ console.error('DSRestore Error:', error);
155
+
156
+ let message = this.config.errorText;
157
+ if (error.response && error.response.data && error.response.data.message) {
158
+ message = error.response.data.message;
159
+ } else if (error.data && error.data.message) {
160
+ message = error.data.message;
161
+ }
162
+
163
+ DSAlert.fire({
164
+ title: this.config.errorTitle,
165
+ text: message,
166
+ icon: this.config.errorIcon
167
+ });
168
+
169
+ if (this.config.onError) {
170
+ this.config.onError(error, element);
171
+ }
172
+
173
+ this._emit('restore:error', { error, element });
174
+ }
175
+
176
+ _emit(event, detail = {}) {
177
+ document.dispatchEvent(new CustomEvent(`ds:${event}`, { bubbles: true, detail }));
178
+ }
179
+ }
180
+
181
+ export default DSRestore;