@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
@@ -1,224 +1,224 @@
1
- export class DSTableFilter {
2
- constructor(tableInstance) {
3
- this.table = tableInstance;
4
- this.table.registerModule('filter', this);
5
- this.wrapper = this.table.wrapper;
6
-
7
- // Config might be passed in options or we look for standard filter areas
8
- // The instruction suggests passing "filter_selectors" in config.
9
-
10
- this.filters = this.table.config.filter_selectors || {};
11
-
12
- // Optional: filter reset button selector
13
- this.resetButtonSelector = this.table.config.filter_reset_button || null;
14
- this.resetButton = null;
15
-
16
- this._init();
17
- this._initResetButton();
18
- }
19
-
20
- _init() {
21
- if (Object.keys(this.filters).length === 0) return;
22
-
23
- Object.entries(this.filters).forEach(([key, config]) => {
24
- const selector = config.input_selector;
25
- const el = document.querySelector(selector);
26
-
27
- if (!el) return;
28
-
29
- // Save default
30
- if (config.default_value !== undefined && config.default_value !== null) {
31
- this.table.setParam(key, config.default_value);
32
- }
33
-
34
- // Check if this is a DSSelect component (custom searchable select)
35
- const isDSSelect = el.hasAttribute('data-ds-select');
36
-
37
- if (isDSSelect) {
38
- // Listen for DSSelect's custom change event
39
- el.addEventListener('dsselect:change', (e) => {
40
- this._handleDSSelectChange(key, el, e.detail);
41
- this._updateResetButtonState();
42
- });
43
- } else {
44
- // Standard input/select handling
45
- const eventName = ['checkbox', 'radio', 'select-one'].includes(el.type) ? 'change' : 'input';
46
-
47
- // For Bulk actions, we might handle differently
48
- if (config.is_bulk) {
49
- el.addEventListener(eventName, (e) => {
50
- this._handleFilterChange(key, e.target);
51
- this._updateResetButtonState();
52
- });
53
- } else {
54
- el.addEventListener(eventName, (e) => {
55
- this._handleFilterChange(key, e.target);
56
- this._updateResetButtonState();
57
- });
58
- }
59
- }
60
- });
61
- }
62
-
63
- /**
64
- * Initialize the reset button if configured
65
- */
66
- _initResetButton() {
67
- if (!this.resetButtonSelector) return;
68
-
69
- this.resetButton = document.querySelector(this.resetButtonSelector);
70
- if (!this.resetButton) return;
71
-
72
- // Attach click handler
73
- this.resetButton.addEventListener('click', (e) => {
74
- e.preventDefault();
75
- this.clearFilters(true);
76
- });
77
-
78
- // Set initial state
79
- this._updateResetButtonState();
80
- }
81
-
82
- /**
83
- * Check if any filter has an active value
84
- * @returns {boolean}
85
- */
86
- hasActiveFilters() {
87
- return Object.entries(this.filters).some(([key, config]) => {
88
- const el = document.querySelector(config.input_selector);
89
- if (!el) return false;
90
-
91
- const defaultValue = config.default_value;
92
-
93
- // Handle checkboxes
94
- if (el.type === 'checkbox') {
95
- return el.checked === true;
96
- }
97
-
98
- const value = el.value;
99
-
100
- // Check if value is different from default/empty
101
- if (Array.isArray(value)) {
102
- return value.length > 0;
103
- }
104
-
105
- // If there's a default value and current value equals default, not "active"
106
- if (defaultValue !== undefined && defaultValue !== null) {
107
- if (value === String(defaultValue) || value === defaultValue) {
108
- return false;
109
- }
110
- }
111
-
112
- return value && value !== '' && value !== 'null';
113
- });
114
- }
115
-
116
- /**
117
- * Update the reset button's disabled state
118
- */
119
- _updateResetButtonState() {
120
- if (!this.resetButton) return;
121
- this.resetButton.disabled = !this.hasActiveFilters();
122
- }
123
-
124
- _handleFilterChange(key, element) {
125
- let val;
126
- if (element.type === 'checkbox') {
127
- val = element.checked ? (element.value || true) : null;
128
- // If unchecked and default is null, send null.
129
- } else {
130
- val = element.value;
131
- }
132
-
133
- // Debounce text inputs
134
- if (element.type === 'text') {
135
- clearTimeout(this._debounce);
136
- this._debounce = setTimeout(() => {
137
- this.table.setParam(key, val);
138
- this.table.setParam('page', 1);
139
- this.table.loadData();
140
- }, 500);
141
- } else {
142
- this.table.setParam(key, val);
143
- this.table.setParam('page', 1);
144
- this.table.loadData();
145
- }
146
- }
147
-
148
- /**
149
- * Handle DSSelect (searchable-select) custom component changes
150
- */
151
- _handleDSSelectChange(key, wrapper, detail) {
152
- let val = detail?.value;
153
-
154
- // Handle array values for multiple selects
155
- if (Array.isArray(val)) {
156
- // If empty array, set to null (no filter)
157
- val = val.length > 0 ? val : null;
158
- } else if (val === '' || val === undefined) {
159
- val = null;
160
- }
161
-
162
- this.table.setParam(key, val);
163
- this.table.setParam('page', 1);
164
- this.table.loadData();
165
- }
166
-
167
- /**
168
- * Reset a single filter by key
169
- * @param {string} key - The filter key to reset
170
- * @param {boolean} reload - Whether to reload data after reset (default: false)
171
- */
172
- resetFilter(key, reload = false) {
173
- const config = this.filters[key];
174
- if (!config) return;
175
-
176
- const el = document.querySelector(config.input_selector);
177
- if (el) {
178
- const isDSSelect = el.hasAttribute('data-ds-select');
179
- if (isDSSelect) {
180
- // Reset DSSelect visual state
181
- el.value = '';
182
- // Clear tags container if multiple
183
- const tagsContainer = el.querySelector('.ds-select-tags');
184
- if (tagsContainer) tagsContainer.innerHTML = '';
185
- // Reset display text
186
- const displayText = el.querySelector('.ds-select-text, .ds-select-placeholder');
187
- if (displayText) displayText.textContent = displayText.dataset.placeholder || '';
188
- } else {
189
- el.value = '';
190
- }
191
- }
192
-
193
- // Reset the param
194
- this.table.setParam(key, config.default_value !== undefined ? config.default_value : null);
195
-
196
- if (reload) {
197
- this.table.setParam('page', 1);
198
- this.table.loadData();
199
- }
200
- }
201
-
202
- /**
203
- * Clear all filters and reload data
204
- * @param {boolean} reload - Whether to reload data after clearing (default: true)
205
- */
206
- clearFilters(reload = true) {
207
- Object.keys(this.filters).forEach(key => {
208
- this.resetFilter(key, false);
209
- });
210
-
211
- if (reload) {
212
- this.table.setParam('page', 1);
213
- this.table.loadData();
214
- }
215
-
216
- // Update reset button state
217
- this._updateResetButtonState();
218
-
219
- // Emit custom event for external listeners
220
- this.wrapper.dispatchEvent(new CustomEvent('dstable:filters-cleared', { bubbles: true }));
221
- }
222
- }
223
- export default DSTableFilter;
224
-
1
+ export class DSTableFilter {
2
+ constructor(tableInstance) {
3
+ this.table = tableInstance;
4
+ this.table.registerModule('filter', this);
5
+ this.wrapper = this.table.wrapper;
6
+
7
+ // Config might be passed in options or we look for standard filter areas
8
+ // The instruction suggests passing "filter_selectors" in config.
9
+
10
+ this.filters = this.table.config.filter_selectors || {};
11
+
12
+ // Optional: filter reset button selector
13
+ this.resetButtonSelector = this.table.config.filter_reset_button || null;
14
+ this.resetButton = null;
15
+
16
+ this._init();
17
+ this._initResetButton();
18
+ }
19
+
20
+ _init() {
21
+ if (Object.keys(this.filters).length === 0) return;
22
+
23
+ Object.entries(this.filters).forEach(([key, config]) => {
24
+ const selector = config.input_selector;
25
+ const el = document.querySelector(selector);
26
+
27
+ if (!el) return;
28
+
29
+ // Save default
30
+ if (config.default_value !== undefined && config.default_value !== null) {
31
+ this.table.setParam(key, config.default_value);
32
+ }
33
+
34
+ // Check if this is a DSSelect component (custom searchable select)
35
+ const isDSSelect = el.hasAttribute('data-ds-select');
36
+
37
+ if (isDSSelect) {
38
+ // Listen for DSSelect's custom change event
39
+ el.addEventListener('dsselect:change', (e) => {
40
+ this._handleDSSelectChange(key, el, e.detail);
41
+ this._updateResetButtonState();
42
+ });
43
+ } else {
44
+ // Standard input/select handling
45
+ const eventName = ['checkbox', 'radio', 'select-one'].includes(el.type) ? 'change' : 'input';
46
+
47
+ // For Bulk actions, we might handle differently
48
+ if (config.is_bulk) {
49
+ el.addEventListener(eventName, (e) => {
50
+ this._handleFilterChange(key, e.target);
51
+ this._updateResetButtonState();
52
+ });
53
+ } else {
54
+ el.addEventListener(eventName, (e) => {
55
+ this._handleFilterChange(key, e.target);
56
+ this._updateResetButtonState();
57
+ });
58
+ }
59
+ }
60
+ });
61
+ }
62
+
63
+ /**
64
+ * Initialize the reset button if configured
65
+ */
66
+ _initResetButton() {
67
+ if (!this.resetButtonSelector) return;
68
+
69
+ this.resetButton = document.querySelector(this.resetButtonSelector);
70
+ if (!this.resetButton) return;
71
+
72
+ // Attach click handler
73
+ this.resetButton.addEventListener('click', (e) => {
74
+ e.preventDefault();
75
+ this.clearFilters(true);
76
+ });
77
+
78
+ // Set initial state
79
+ this._updateResetButtonState();
80
+ }
81
+
82
+ /**
83
+ * Check if any filter has an active value
84
+ * @returns {boolean}
85
+ */
86
+ hasActiveFilters() {
87
+ return Object.entries(this.filters).some(([key, config]) => {
88
+ const el = document.querySelector(config.input_selector);
89
+ if (!el) return false;
90
+
91
+ const defaultValue = config.default_value;
92
+
93
+ // Handle checkboxes
94
+ if (el.type === 'checkbox') {
95
+ return el.checked === true;
96
+ }
97
+
98
+ const value = el.value;
99
+
100
+ // Check if value is different from default/empty
101
+ if (Array.isArray(value)) {
102
+ return value.length > 0;
103
+ }
104
+
105
+ // If there's a default value and current value equals default, not "active"
106
+ if (defaultValue !== undefined && defaultValue !== null) {
107
+ if (value === String(defaultValue) || value === defaultValue) {
108
+ return false;
109
+ }
110
+ }
111
+
112
+ return value && value !== '' && value !== 'null';
113
+ });
114
+ }
115
+
116
+ /**
117
+ * Update the reset button's disabled state
118
+ */
119
+ _updateResetButtonState() {
120
+ if (!this.resetButton) return;
121
+ this.resetButton.disabled = !this.hasActiveFilters();
122
+ }
123
+
124
+ _handleFilterChange(key, element) {
125
+ let val;
126
+ if (element.type === 'checkbox') {
127
+ val = element.checked ? (element.value || true) : null;
128
+ // If unchecked and default is null, send null.
129
+ } else {
130
+ val = element.value;
131
+ }
132
+
133
+ // Debounce text inputs
134
+ if (element.type === 'text') {
135
+ clearTimeout(this._debounce);
136
+ this._debounce = setTimeout(() => {
137
+ this.table.setParam(key, val);
138
+ this.table.setParam('page', 1);
139
+ this.table.loadData();
140
+ }, 500);
141
+ } else {
142
+ this.table.setParam(key, val);
143
+ this.table.setParam('page', 1);
144
+ this.table.loadData();
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Handle DSSelect (searchable-select) custom component changes
150
+ */
151
+ _handleDSSelectChange(key, wrapper, detail) {
152
+ let val = detail?.value;
153
+
154
+ // Handle array values for multiple selects
155
+ if (Array.isArray(val)) {
156
+ // If empty array, set to null (no filter)
157
+ val = val.length > 0 ? val : null;
158
+ } else if (val === '' || val === undefined) {
159
+ val = null;
160
+ }
161
+
162
+ this.table.setParam(key, val);
163
+ this.table.setParam('page', 1);
164
+ this.table.loadData();
165
+ }
166
+
167
+ /**
168
+ * Reset a single filter by key
169
+ * @param {string} key - The filter key to reset
170
+ * @param {boolean} reload - Whether to reload data after reset (default: false)
171
+ */
172
+ resetFilter(key, reload = false) {
173
+ const config = this.filters[key];
174
+ if (!config) return;
175
+
176
+ const el = document.querySelector(config.input_selector);
177
+ if (el) {
178
+ const isDSSelect = el.hasAttribute('data-ds-select');
179
+ if (isDSSelect) {
180
+ // Reset DSSelect visual state
181
+ el.value = '';
182
+ // Clear tags container if multiple
183
+ const tagsContainer = el.querySelector('.ds-select-tags');
184
+ if (tagsContainer) tagsContainer.innerHTML = '';
185
+ // Reset display text
186
+ const displayText = el.querySelector('.ds-select-text, .ds-select-placeholder');
187
+ if (displayText) displayText.textContent = displayText.dataset.placeholder || '';
188
+ } else {
189
+ el.value = '';
190
+ }
191
+ }
192
+
193
+ // Reset the param
194
+ this.table.setParam(key, config.default_value !== undefined ? config.default_value : null);
195
+
196
+ if (reload) {
197
+ this.table.setParam('page', 1);
198
+ this.table.loadData();
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Clear all filters and reload data
204
+ * @param {boolean} reload - Whether to reload data after clearing (default: true)
205
+ */
206
+ clearFilters(reload = true) {
207
+ Object.keys(this.filters).forEach(key => {
208
+ this.resetFilter(key, false);
209
+ });
210
+
211
+ if (reload) {
212
+ this.table.setParam('page', 1);
213
+ this.table.loadData();
214
+ }
215
+
216
+ // Update reset button state
217
+ this._updateResetButtonState();
218
+
219
+ // Emit custom event for external listeners
220
+ this.wrapper.dispatchEvent(new CustomEvent('dstable:filters-cleared', { bubbles: true }));
221
+ }
222
+ }
223
+ export default DSTableFilter;
224
+