@seip/bluebird-js 0.1.1 → 0.1.4
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.
- package/.vscode/extensions.json +7 -0
- package/.vscode/settings.json +10 -0
- package/AGENTS.md +124 -64
- package/README.md +236 -103
- package/app/routes/web.js +47 -55
- package/app/views/about.jsx +98 -0
- package/app/views/components/Header.jsx +42 -0
- package/app/views/components/LiveCounter.jsx +67 -0
- package/app/views/dashboard.jsx +300 -0
- package/app/views/index.jsx +123 -0
- package/app/views/layouts/main/view.jsx +201 -0
- package/app/views/legal/terms.html +29 -19
- package/app/views/login.jsx +141 -0
- package/core/actions.d.ts +4 -0
- package/core/actions.js +329 -0
- package/core/app.js +129 -22
- package/core/auth.js +1 -1
- package/core/cli/doctor.js +3 -4
- package/core/cli/init.js +153 -6
- package/core/cli/migrate.js +418 -145
- package/core/cli/view.js +76 -11
- package/core/config.js +35 -5
- package/core/csrf.js +1 -1
- package/core/database.js +52 -17
- package/core/debug.js +1 -1
- package/core/html.d.ts +54 -42
- package/core/html.js +473 -217
- package/core/index.d.ts +187 -85
- package/core/jsx.d.ts +38 -0
- package/core/jsx.js +1180 -0
- package/core/model.js +282 -61
- package/core/queue.js +7 -4
- package/core/render-cache.js +212 -212
- package/core/render.d.ts +20 -2
- package/core/render.js +320 -43
- package/core/upload.js +7 -1
- package/core/validate.js +1 -1
- package/core/view-loader.js +341 -19
- package/core/vite.js +1 -1
- package/package.json +9 -3
- package/public/js/bluebird-client.js +2313 -1049
- package/public/js/tailwind.js +8 -0
- package/app/views/about.js +0 -63
- package/app/views/dashboard.js +0 -147
- package/app/views/index.js +0 -80
- package/app/views/layouts/main/view.js +0 -81
- package/app/views/login.js +0 -80
- package/public/css/bluebird.min.css +0 -2
- package/public/js/bluebird.min.js +0 -1073
|
@@ -1,1073 +0,0 @@
|
|
|
1
|
-
/* Blue Bird JS v0.2.2 | MIT License | @seip/blue-bird-css */
|
|
2
|
-
function bluebird(component, options) {
|
|
3
|
-
if (typeof component === 'object') {
|
|
4
|
-
options = component;
|
|
5
|
-
component = 'snackbar';
|
|
6
|
-
}
|
|
7
|
-
if (component === 'snackbar') {
|
|
8
|
-
let snackbarEl = document.getElementById('snackbar');
|
|
9
|
-
if (!snackbarEl) {
|
|
10
|
-
snackbarEl = document.createElement('div');
|
|
11
|
-
snackbarEl.id = 'snackbar';
|
|
12
|
-
document.body.appendChild(snackbarEl);
|
|
13
|
-
}
|
|
14
|
-
snackbarEl.className = 'show';
|
|
15
|
-
if (options && options.type) {
|
|
16
|
-
snackbarEl.classList.add(options.type);
|
|
17
|
-
} else {
|
|
18
|
-
snackbarEl.classList.add('info');
|
|
19
|
-
}
|
|
20
|
-
snackbarEl.textContent = (options && options.message) || '';
|
|
21
|
-
setTimeout(() => {
|
|
22
|
-
snackbarEl.classList.add('show');
|
|
23
|
-
}, 10);
|
|
24
|
-
const duration = (options && options.duration) || 3000;
|
|
25
|
-
if (snackbarEl.timeoutId) {
|
|
26
|
-
clearTimeout(snackbarEl.timeoutId);
|
|
27
|
-
}
|
|
28
|
-
snackbarEl.timeoutId = setTimeout(function () {
|
|
29
|
-
snackbarEl.className = '';
|
|
30
|
-
}, duration);
|
|
31
|
-
}
|
|
32
|
-
if (component === 'toast') {
|
|
33
|
-
const position = (options && options.position) || 'bottom-right';
|
|
34
|
-
let container = document.querySelector(`.toast-container.${position}`);
|
|
35
|
-
if (!container) {
|
|
36
|
-
container = document.createElement('div');
|
|
37
|
-
container.className = `toast-container ${position}`;
|
|
38
|
-
document.body.appendChild(container);
|
|
39
|
-
}
|
|
40
|
-
const toastEl = document.createElement('div');
|
|
41
|
-
const typeClass = (options && options.type) ? `toast-${options.type}` : 'toast-info';
|
|
42
|
-
toastEl.className = `toast ${typeClass}`;
|
|
43
|
-
const title = (options && options.title) ? `<div class="toast-title">${options.title}</div>` : '';
|
|
44
|
-
const desc = (options && options.description) ? `<div class="toast-description">${options.description}</div>` : '';
|
|
45
|
-
toastEl.innerHTML = `
|
|
46
|
-
<div class="toast-content">
|
|
47
|
-
${title}
|
|
48
|
-
${desc}
|
|
49
|
-
</div>
|
|
50
|
-
<button class="toast-close" aria-label="Dismiss">×</button>
|
|
51
|
-
`;
|
|
52
|
-
const closeBtn = toastEl.querySelector('.toast-close');
|
|
53
|
-
closeBtn.addEventListener('click', () => dismissToast(toastEl));
|
|
54
|
-
container.appendChild(toastEl);
|
|
55
|
-
const duration = (options && options.duration) !== undefined ? options.duration : 4000;
|
|
56
|
-
if (duration > 0) {
|
|
57
|
-
setTimeout(() => dismissToast(toastEl), duration);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (component === 'tab') {
|
|
61
|
-
const targetId = options && options.id;
|
|
62
|
-
if (!targetId) return;
|
|
63
|
-
const targetContent = document.getElementById(targetId);
|
|
64
|
-
if (!targetContent) return;
|
|
65
|
-
const tabsContainer = targetContent.closest('.tabs');
|
|
66
|
-
if (!tabsContainer) return;
|
|
67
|
-
const allTriggers = tabsContainer.querySelectorAll('.tab-trigger');
|
|
68
|
-
const allContents = tabsContainer.querySelectorAll('.tab-content');
|
|
69
|
-
allContents.forEach(c => c.classList.remove('active'));
|
|
70
|
-
allTriggers.forEach(t => t.classList.remove('active'));
|
|
71
|
-
targetContent.classList.add('active');
|
|
72
|
-
const matchingTrigger = Array.from(allTriggers).find(t =>
|
|
73
|
-
t.getAttribute('data-tab-target') === targetId || t.getAttribute('href') === `#${targetId}`
|
|
74
|
-
);
|
|
75
|
-
if (matchingTrigger) {
|
|
76
|
-
matchingTrigger.classList.add('active');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (component === 'command') {
|
|
80
|
-
const action = (options && options.action) || 'toggle';
|
|
81
|
-
let backdrop = document.querySelector('.command-backdrop');
|
|
82
|
-
if (!backdrop) {
|
|
83
|
-
backdrop = createCommandPaletteModal();
|
|
84
|
-
}
|
|
85
|
-
const isOpen = backdrop.classList.contains('open');
|
|
86
|
-
if (action === 'open' || (action === 'toggle' && !isOpen)) {
|
|
87
|
-
backdrop.classList.add('open');
|
|
88
|
-
const input = backdrop.querySelector('.command-input');
|
|
89
|
-
if (input) {
|
|
90
|
-
input.value = '';
|
|
91
|
-
setTimeout(() => input.focus(), 50);
|
|
92
|
-
}
|
|
93
|
-
} else if (action === 'close' || (action === 'toggle' && isOpen)) {
|
|
94
|
-
backdrop.classList.remove('open');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (component === 'popover') {
|
|
98
|
-
const id = options && options.id;
|
|
99
|
-
const action = (options && options.action) || 'toggle';
|
|
100
|
-
if (!id) return;
|
|
101
|
-
const popoverEl = document.getElementById(id) || document.querySelector(`[data-popover-id="${id}"]`);
|
|
102
|
-
if (!popoverEl) return;
|
|
103
|
-
const isOpen = popoverEl.classList.contains('open');
|
|
104
|
-
if (action === 'open' || (action === 'toggle' && !isOpen)) {
|
|
105
|
-
popoverEl.classList.add('open');
|
|
106
|
-
} else {
|
|
107
|
-
popoverEl.classList.remove('open');
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (component === 'drawer') {
|
|
111
|
-
cleanupOrphanedBackdrops();
|
|
112
|
-
const id = options && options.id;
|
|
113
|
-
const action = (options && options.action) || 'toggle';
|
|
114
|
-
if (!id) return;
|
|
115
|
-
const drawerEl = document.getElementById(id);
|
|
116
|
-
if (!drawerEl) return;
|
|
117
|
-
let overlay = document.querySelector(`.drawer-backdrop[data-for="${id}"]`);
|
|
118
|
-
if (!overlay) {
|
|
119
|
-
overlay = document.createElement('div');
|
|
120
|
-
overlay.className = 'drawer-backdrop';
|
|
121
|
-
overlay.setAttribute('data-for', id);
|
|
122
|
-
document.body.appendChild(overlay);
|
|
123
|
-
overlay.addEventListener('click', () => {
|
|
124
|
-
bluebird('drawer', { id, action: 'close' });
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
const isOpen = drawerEl.classList.contains('open') || drawerEl.classList.contains('active');
|
|
128
|
-
if (action === 'open' || (action === 'toggle' && !isOpen)) {
|
|
129
|
-
drawerEl.classList.add('open');
|
|
130
|
-
overlay.classList.add('open');
|
|
131
|
-
document.body.style.overflow = 'hidden';
|
|
132
|
-
} else if (action === 'close' || (action === 'toggle' && isOpen)) {
|
|
133
|
-
drawerEl.classList.remove('open');
|
|
134
|
-
overlay.classList.remove('open');
|
|
135
|
-
document.body.style.overflow = '';
|
|
136
|
-
setTimeout(() => {
|
|
137
|
-
if (overlay && overlay.parentNode && !drawerEl.classList.contains('open')) {
|
|
138
|
-
overlay.remove();
|
|
139
|
-
}
|
|
140
|
-
}, 300);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (component === 'carousel') {
|
|
144
|
-
const selector = (options && options.selector) || '.carousel';
|
|
145
|
-
const carousels = document.querySelectorAll(selector);
|
|
146
|
-
carousels.forEach(carousel => initSingleCarousel(carousel, options));
|
|
147
|
-
}
|
|
148
|
-
if (component === 'datatable' || component === 'table') {
|
|
149
|
-
const containerId = (options && (options.container || options.id)) || 'datatable';
|
|
150
|
-
return new ResponsiveDataTable(containerId, options);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
function snackbar(options) {
|
|
154
|
-
bluebird('snackbar', options);
|
|
155
|
-
}
|
|
156
|
-
function toast(options) {
|
|
157
|
-
bluebird('toast', options);
|
|
158
|
-
}
|
|
159
|
-
function dismissToast(toastEl) {
|
|
160
|
-
if (!toastEl || toastEl.isDismissing) return;
|
|
161
|
-
toastEl.isDismissing = true;
|
|
162
|
-
toastEl.style.opacity = '0';
|
|
163
|
-
toastEl.style.transform = 'translateY(-10px) scale(0.95)';
|
|
164
|
-
setTimeout(() => {
|
|
165
|
-
if (toastEl.parentNode) {
|
|
166
|
-
toastEl.remove();
|
|
167
|
-
}
|
|
168
|
-
}, 200);
|
|
169
|
-
}
|
|
170
|
-
function createCommandPaletteModal() {
|
|
171
|
-
const backdrop = document.createElement('div');
|
|
172
|
-
backdrop.className = 'command-backdrop';
|
|
173
|
-
backdrop.innerHTML = `
|
|
174
|
-
<div class="command-dialog">
|
|
175
|
-
<div class="command-input-wrapper">
|
|
176
|
-
<span>🔍</span>
|
|
177
|
-
<input type="text" class="command-input" placeholder="Type a command or search documentation..." />
|
|
178
|
-
<kbd>ESC</kbd>
|
|
179
|
-
</div>
|
|
180
|
-
<div class="command-list">
|
|
181
|
-
<div class="command-group">
|
|
182
|
-
<div class="command-group-title">Navigation</div>
|
|
183
|
-
<div class="command-item" data-navigate="#/"><span>Documentation Home</span><kbd>↵</kbd></div>
|
|
184
|
-
<div class="command-item" data-navigate="#/buttons"><span>Buttons & Badges</span><kbd>↵</kbd></div>
|
|
185
|
-
<div class="command-item" data-navigate="#/forms"><span>Forms & Inputs</span><kbd>↵</kbd></div>
|
|
186
|
-
</div>
|
|
187
|
-
<div class="command-group">
|
|
188
|
-
<div class="command-group-title">Components</div>
|
|
189
|
-
<div class="command-item" data-navigate="#/carousel"><span>Touch Carousel</span><kbd>↵</kbd></div>
|
|
190
|
-
<div class="command-item" data-navigate="#/aside-drawer"><span>Aside & Drawers</span><kbd>↵</kbd></div>
|
|
191
|
-
<div class="command-item" data-navigate="#/animations"><span>CSS Animations</span><kbd>↵</kbd></div>
|
|
192
|
-
</div>
|
|
193
|
-
</div>
|
|
194
|
-
</div>
|
|
195
|
-
`;
|
|
196
|
-
document.body.appendChild(backdrop);
|
|
197
|
-
backdrop.addEventListener('click', (e) => {
|
|
198
|
-
if (e.target === backdrop) {
|
|
199
|
-
bluebird('command', { action: 'close' });
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
const input = backdrop.querySelector('.command-input');
|
|
203
|
-
input.addEventListener('input', (e) => {
|
|
204
|
-
const query = e.target.value.toLowerCase().trim();
|
|
205
|
-
const items = backdrop.querySelectorAll('.command-item');
|
|
206
|
-
items.forEach(item => {
|
|
207
|
-
const text = item.textContent.toLowerCase();
|
|
208
|
-
item.style.display = text.includes(query) ? 'flex' : 'none';
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
backdrop.addEventListener('click', (e) => {
|
|
212
|
-
const item = e.target.closest('.command-item');
|
|
213
|
-
if (item && item.getAttribute('data-navigate')) {
|
|
214
|
-
window.location.hash = item.getAttribute('data-navigate');
|
|
215
|
-
bluebird('command', { action: 'close' });
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
return backdrop;
|
|
219
|
-
}
|
|
220
|
-
function cleanupOrphanedBackdrops() {
|
|
221
|
-
document.querySelectorAll('.drawer-backdrop[data-for]').forEach(backdrop => {
|
|
222
|
-
const targetId = backdrop.getAttribute('data-for');
|
|
223
|
-
if (!document.getElementById(targetId)) {
|
|
224
|
-
backdrop.remove();
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
function initMobileDrawer() {
|
|
229
|
-
const mainEl = document.querySelector('main');
|
|
230
|
-
const aside = mainEl ? mainEl.querySelector(':scope > aside') : null;
|
|
231
|
-
if (!aside) return;
|
|
232
|
-
let overlay = document.querySelector('.bluebird-drawer-overlay');
|
|
233
|
-
if (!overlay) {
|
|
234
|
-
overlay = document.createElement('div');
|
|
235
|
-
overlay.className = 'bluebird-drawer-overlay';
|
|
236
|
-
document.body.appendChild(overlay);
|
|
237
|
-
}
|
|
238
|
-
let drawer = document.querySelector('.bluebird-drawer');
|
|
239
|
-
if (!drawer) {
|
|
240
|
-
drawer = document.createElement('div');
|
|
241
|
-
drawer.className = 'bluebird-drawer';
|
|
242
|
-
document.body.appendChild(drawer);
|
|
243
|
-
}
|
|
244
|
-
drawer.innerHTML = aside.innerHTML;
|
|
245
|
-
let toggle = document.querySelector('.bluebird-drawer-toggle');
|
|
246
|
-
if (!toggle) {
|
|
247
|
-
toggle = document.createElement('button');
|
|
248
|
-
toggle.className = 'bluebird-drawer-toggle';
|
|
249
|
-
toggle.innerHTML = '☰';
|
|
250
|
-
toggle.setAttribute('aria-label', 'Toggle navigation menu');
|
|
251
|
-
const header = document.querySelector('header');
|
|
252
|
-
if (header) {
|
|
253
|
-
const nav = header.querySelector('nav');
|
|
254
|
-
if (nav) {
|
|
255
|
-
nav.insertBefore(toggle, nav.firstChild);
|
|
256
|
-
} else {
|
|
257
|
-
header.prepend(toggle);
|
|
258
|
-
}
|
|
259
|
-
} else {
|
|
260
|
-
document.body.prepend(toggle);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
document.addEventListener('keydown', function (e) {
|
|
265
|
-
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
|
|
266
|
-
e.preventDefault();
|
|
267
|
-
bluebird('command', { action: 'toggle' });
|
|
268
|
-
}
|
|
269
|
-
if (e.key === 'Escape') {
|
|
270
|
-
const commandBackdrop = document.querySelector('.command-backdrop.open');
|
|
271
|
-
if (commandBackdrop) {
|
|
272
|
-
bluebird('command', { action: 'close' });
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
document.addEventListener('click', function (e) {
|
|
277
|
-
const tabTrigger = e.target.closest('[data-tab-target], .tab-trigger');
|
|
278
|
-
if (tabTrigger) {
|
|
279
|
-
const targetId = tabTrigger.getAttribute('data-tab-target') || (tabTrigger.getAttribute('href') || '').replace('#', '');
|
|
280
|
-
if (targetId) {
|
|
281
|
-
e.preventDefault();
|
|
282
|
-
bluebird('tab', { id: targetId });
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
const popoverTrigger = e.target.closest('[data-popover-target]');
|
|
286
|
-
if (popoverTrigger) {
|
|
287
|
-
const popoverId = popoverTrigger.getAttribute('data-popover-target');
|
|
288
|
-
bluebird('popover', { id: popoverId, action: 'toggle' });
|
|
289
|
-
}
|
|
290
|
-
if (!e.target.closest('.popover') && !e.target.closest('[data-popover-target]')) {
|
|
291
|
-
document.querySelectorAll('.popover.open').forEach(p => p.classList.remove('open'));
|
|
292
|
-
}
|
|
293
|
-
const mobileToggle = e.target.closest('.bluebird-drawer-toggle');
|
|
294
|
-
if (mobileToggle) {
|
|
295
|
-
e.preventDefault();
|
|
296
|
-
e.stopPropagation();
|
|
297
|
-
initMobileDrawer();
|
|
298
|
-
const drawer = document.querySelector('.bluebird-drawer');
|
|
299
|
-
const overlay = document.querySelector('.bluebird-drawer-overlay');
|
|
300
|
-
if (drawer && overlay) {
|
|
301
|
-
const isOpen = drawer.classList.contains('open');
|
|
302
|
-
if (isOpen) {
|
|
303
|
-
drawer.classList.remove('open');
|
|
304
|
-
overlay.classList.remove('open');
|
|
305
|
-
document.body.style.overflow = '';
|
|
306
|
-
} else {
|
|
307
|
-
drawer.classList.add('open');
|
|
308
|
-
overlay.classList.add('open');
|
|
309
|
-
document.body.style.overflow = 'hidden';
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
if (e.target.closest('.bluebird-drawer-overlay')) {
|
|
315
|
-
const drawer = document.querySelector('.bluebird-drawer');
|
|
316
|
-
const overlay = document.querySelector('.bluebird-drawer-overlay');
|
|
317
|
-
if (drawer) drawer.classList.remove('open');
|
|
318
|
-
if (overlay) overlay.classList.remove('open');
|
|
319
|
-
document.body.style.overflow = '';
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
if (e.target.closest('.bluebird-drawer a')) {
|
|
323
|
-
const drawer = document.querySelector('.bluebird-drawer');
|
|
324
|
-
const overlay = document.querySelector('.bluebird-drawer-overlay');
|
|
325
|
-
if (drawer) drawer.classList.remove('open');
|
|
326
|
-
if (overlay) overlay.classList.remove('open');
|
|
327
|
-
document.body.style.overflow = '';
|
|
328
|
-
}
|
|
329
|
-
const btn = e.target.closest("button, a[role='button']");
|
|
330
|
-
if (btn && !btn.classList.contains('fab') && !btn.classList.contains('carousel-nav') && !btn.classList.contains('bluebird-drawer-toggle')) {
|
|
331
|
-
const rect = btn.getBoundingClientRect();
|
|
332
|
-
const size = Math.max(rect.width, rect.height);
|
|
333
|
-
const x = e.clientX - rect.left - size / 2;
|
|
334
|
-
const y = e.clientY - rect.top - size / 2;
|
|
335
|
-
const ripple = document.createElement('span');
|
|
336
|
-
ripple.className = 'ripple';
|
|
337
|
-
ripple.style.width = ripple.style.height = size + 'px';
|
|
338
|
-
ripple.style.left = x + 'px';
|
|
339
|
-
ripple.style.top = y + 'px';
|
|
340
|
-
btn.appendChild(ripple);
|
|
341
|
-
ripple.addEventListener('animationend', () => ripple.remove());
|
|
342
|
-
}
|
|
343
|
-
const drawerTrigger = e.target.closest('[data-drawer-target]');
|
|
344
|
-
if (drawerTrigger) {
|
|
345
|
-
const id = drawerTrigger.getAttribute('data-drawer-target');
|
|
346
|
-
bluebird('drawer', { id, action: 'toggle' });
|
|
347
|
-
}
|
|
348
|
-
const drawerClose = e.target.closest('[data-drawer-close]');
|
|
349
|
-
if (drawerClose) {
|
|
350
|
-
const drawerEl = drawerClose.closest('.drawer');
|
|
351
|
-
if (drawerEl && drawerEl.id) {
|
|
352
|
-
bluebird('drawer', { id: drawerEl.id, action: 'close' });
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
function initSingleCarousel(carousel, opts = {}) {
|
|
357
|
-
if (carousel._bb_initialized) return;
|
|
358
|
-
carousel._bb_initialized = true;
|
|
359
|
-
const track = carousel.querySelector('.carousel-track');
|
|
360
|
-
if (!track) return;
|
|
361
|
-
const items = Array.from(track.querySelectorAll('.carousel-item, .carousel-card'));
|
|
362
|
-
if (items.length === 0) return;
|
|
363
|
-
const prevBtn = carousel.querySelector('.carousel-prev');
|
|
364
|
-
const nextBtn = carousel.querySelector('.carousel-next');
|
|
365
|
-
let indicatorsContainer = carousel.querySelector('.carousel-indicators');
|
|
366
|
-
let currentSlideIndex = 0;
|
|
367
|
-
if (indicatorsContainer && indicatorsContainer.children.length === 0) {
|
|
368
|
-
items.forEach((_, idx) => {
|
|
369
|
-
const dot = document.createElement('button');
|
|
370
|
-
dot.className = `carousel-dot ${idx === 0 ? 'active' : ''}`;
|
|
371
|
-
dot.setAttribute('aria-label', `Go to slide ${idx + 1}`);
|
|
372
|
-
dot.addEventListener('click', (e) => {
|
|
373
|
-
e.preventDefault();
|
|
374
|
-
scrollToSlide(idx);
|
|
375
|
-
});
|
|
376
|
-
indicatorsContainer.appendChild(dot);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
function scrollToSlide(index) {
|
|
380
|
-
if (index < 0) index = 0;
|
|
381
|
-
if (index >= items.length) index = items.length - 1;
|
|
382
|
-
currentSlideIndex = index;
|
|
383
|
-
const targetItem = items[index];
|
|
384
|
-
if (targetItem) {
|
|
385
|
-
track.scrollTo({
|
|
386
|
-
left: targetItem.offsetLeft - track.offsetLeft,
|
|
387
|
-
behavior: 'smooth'
|
|
388
|
-
});
|
|
389
|
-
updateIndicators(index);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
function updateIndicators(activeIndex) {
|
|
393
|
-
if (!indicatorsContainer) return;
|
|
394
|
-
const dots = Array.from(indicatorsContainer.children);
|
|
395
|
-
dots.forEach((dot, idx) => {
|
|
396
|
-
dot.classList.toggle('active', idx === activeIndex);
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
let scrollTimeout;
|
|
400
|
-
track.addEventListener('scroll', () => {
|
|
401
|
-
clearTimeout(scrollTimeout);
|
|
402
|
-
scrollTimeout = setTimeout(() => {
|
|
403
|
-
const trackLeft = track.scrollLeft;
|
|
404
|
-
let closestIndex = 0;
|
|
405
|
-
let minDistance = Infinity;
|
|
406
|
-
items.forEach((item, idx) => {
|
|
407
|
-
const distance = Math.abs(item.offsetLeft - track.offsetLeft - trackLeft);
|
|
408
|
-
if (distance < minDistance) {
|
|
409
|
-
minDistance = distance;
|
|
410
|
-
closestIndex = idx;
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
currentSlideIndex = closestIndex;
|
|
414
|
-
updateIndicators(closestIndex);
|
|
415
|
-
}, 40);
|
|
416
|
-
});
|
|
417
|
-
if (prevBtn) {
|
|
418
|
-
prevBtn.addEventListener('click', (e) => {
|
|
419
|
-
e.preventDefault();
|
|
420
|
-
e.stopPropagation();
|
|
421
|
-
scrollToSlide(currentSlideIndex - 1);
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
if (nextBtn) {
|
|
425
|
-
nextBtn.addEventListener('click', (e) => {
|
|
426
|
-
e.preventDefault();
|
|
427
|
-
e.stopPropagation();
|
|
428
|
-
scrollToSlide(currentSlideIndex + 1);
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
let startX = 0;
|
|
432
|
-
let isDragging = false;
|
|
433
|
-
track.addEventListener('touchstart', (e) => {
|
|
434
|
-
startX = e.touches[0].clientX;
|
|
435
|
-
isDragging = true;
|
|
436
|
-
}, { passive: true });
|
|
437
|
-
track.addEventListener('touchend', (e) => {
|
|
438
|
-
if (!isDragging) return;
|
|
439
|
-
isDragging = false;
|
|
440
|
-
const endX = e.changedTouches[0].clientX;
|
|
441
|
-
const diffX = startX - endX;
|
|
442
|
-
if (Math.abs(diffX) > 35) {
|
|
443
|
-
if (diffX > 0) {
|
|
444
|
-
scrollToSlide(currentSlideIndex + 1);
|
|
445
|
-
} else {
|
|
446
|
-
scrollToSlide(currentSlideIndex - 1);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
track.addEventListener('mousedown', (e) => {
|
|
451
|
-
startX = e.clientX;
|
|
452
|
-
isDragging = true;
|
|
453
|
-
track.style.cursor = 'grabbing';
|
|
454
|
-
});
|
|
455
|
-
track.addEventListener('mouseleave', () => {
|
|
456
|
-
isDragging = false;
|
|
457
|
-
track.style.cursor = 'grab';
|
|
458
|
-
});
|
|
459
|
-
track.addEventListener('mouseup', (e) => {
|
|
460
|
-
if (!isDragging) return;
|
|
461
|
-
isDragging = false;
|
|
462
|
-
track.style.cursor = 'grab';
|
|
463
|
-
const endX = e.clientX;
|
|
464
|
-
const diffX = startX - endX;
|
|
465
|
-
if (Math.abs(diffX) > 35) {
|
|
466
|
-
if (diffX > 0) {
|
|
467
|
-
scrollToSlide(currentSlideIndex + 1);
|
|
468
|
-
} else {
|
|
469
|
-
scrollToSlide(currentSlideIndex - 1);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
const isAutoplay = (opts && opts.autoplay) || carousel.getAttribute('data-autoplay') === 'true';
|
|
474
|
-
const intervalTime = parseInt((opts && opts.interval) || carousel.getAttribute('data-interval') || 3500, 10);
|
|
475
|
-
if (isAutoplay) {
|
|
476
|
-
let autoInterval = setInterval(() => {
|
|
477
|
-
const nextIdx = (currentSlideIndex + 1) % items.length;
|
|
478
|
-
scrollToSlide(nextIdx);
|
|
479
|
-
}, intervalTime);
|
|
480
|
-
carousel.addEventListener('mouseenter', () => clearInterval(autoInterval));
|
|
481
|
-
carousel.addEventListener('mouseleave', () => {
|
|
482
|
-
autoInterval = setInterval(() => {
|
|
483
|
-
const nextIdx = (currentSlideIndex + 1) % items.length;
|
|
484
|
-
scrollToSlide(nextIdx);
|
|
485
|
-
}, intervalTime);
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
(function setupDeclarativeListeners() {
|
|
490
|
-
document.addEventListener('click', (e) => {
|
|
491
|
-
const copyTrigger = e.target.closest('[data-copy]');
|
|
492
|
-
if (copyTrigger) {
|
|
493
|
-
e.preventDefault();
|
|
494
|
-
const targetAttr = copyTrigger.getAttribute('data-copy');
|
|
495
|
-
let textToCopy = targetAttr;
|
|
496
|
-
if (targetAttr && (targetAttr.startsWith('#') || targetAttr.startsWith('.'))) {
|
|
497
|
-
const targetEl = document.querySelector(targetAttr);
|
|
498
|
-
if (targetEl) {
|
|
499
|
-
textToCopy = targetEl.value !== undefined ? targetEl.value : (targetEl.innerText || targetEl.textContent);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
if (textToCopy) {
|
|
503
|
-
navigator.clipboard.writeText(textToCopy.trim()).then(() => {
|
|
504
|
-
copyTrigger.classList.add('copied');
|
|
505
|
-
if (typeof bluebird === 'function') {
|
|
506
|
-
bluebird('toast', {
|
|
507
|
-
title: 'Copied to clipboard',
|
|
508
|
-
description: textToCopy.length > 50 ? textToCopy.substring(0, 50) + '...' : textToCopy,
|
|
509
|
-
type: 'success',
|
|
510
|
-
duration: 2500
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
setTimeout(() => copyTrigger.classList.remove('copied'), 2000);
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
const confirmTrigger = e.target.closest('[data-confirm]');
|
|
519
|
-
if (confirmTrigger) {
|
|
520
|
-
const msg = confirmTrigger.getAttribute('data-confirm') || 'Are you sure?';
|
|
521
|
-
if (!window.confirm(msg)) {
|
|
522
|
-
e.preventDefault();
|
|
523
|
-
e.stopImmediatePropagation();
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
const scrollTrigger = e.target.closest('[data-scroll-to]');
|
|
528
|
-
if (scrollTrigger) {
|
|
529
|
-
e.preventDefault();
|
|
530
|
-
const targetId = scrollTrigger.getAttribute('data-scroll-to');
|
|
531
|
-
const targetEl = document.querySelector(targetId);
|
|
532
|
-
if (targetEl) {
|
|
533
|
-
targetEl.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
534
|
-
}
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
const passToggle = e.target.closest('[data-password-toggle]');
|
|
538
|
-
if (passToggle) {
|
|
539
|
-
e.preventDefault();
|
|
540
|
-
const targetSelector = passToggle.getAttribute('data-password-toggle');
|
|
541
|
-
const input = targetSelector
|
|
542
|
-
? document.querySelector(targetSelector)
|
|
543
|
-
: (passToggle.closest('.input-group, .form-input-group, div')?.querySelector('input') || passToggle.previousElementSibling);
|
|
544
|
-
if (input && (input.type === 'password' || input.type === 'text')) {
|
|
545
|
-
const isPassword = input.type === 'password';
|
|
546
|
-
input.type = isPassword ? 'text' : 'password';
|
|
547
|
-
passToggle.classList.toggle('showing', isPassword);
|
|
548
|
-
passToggle.setAttribute('aria-pressed', isPassword ? 'true' : 'false');
|
|
549
|
-
}
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
|
-
const stepUp = e.target.closest('[data-step-up]');
|
|
553
|
-
if (stepUp) {
|
|
554
|
-
e.preventDefault();
|
|
555
|
-
const targetInput = document.querySelector(stepUp.getAttribute('data-step-up')) ||
|
|
556
|
-
stepUp.closest('.stepper')?.querySelector('input[type="number"]');
|
|
557
|
-
if (targetInput && typeof targetInput.stepUp === 'function') {
|
|
558
|
-
targetInput.stepUp();
|
|
559
|
-
targetInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
560
|
-
targetInput.dispatchEvent(new Event('change', { bubbles: true }));
|
|
561
|
-
}
|
|
562
|
-
return;
|
|
563
|
-
}
|
|
564
|
-
const stepDown = e.target.closest('[data-step-down]');
|
|
565
|
-
if (stepDown) {
|
|
566
|
-
e.preventDefault();
|
|
567
|
-
const targetInput = document.querySelector(stepDown.getAttribute('data-step-down')) ||
|
|
568
|
-
stepDown.closest('.stepper')?.querySelector('input[type="number"]');
|
|
569
|
-
if (targetInput && typeof targetInput.stepDown === 'function') {
|
|
570
|
-
targetInput.stepDown();
|
|
571
|
-
targetInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
572
|
-
targetInput.dispatchEvent(new Event('change', { bubbles: true }));
|
|
573
|
-
}
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
576
|
-
const selectItem = e.target.closest('[data-select-value]');
|
|
577
|
-
if (selectItem) {
|
|
578
|
-
const val = selectItem.getAttribute('data-select-value');
|
|
579
|
-
const targetSelector = selectItem.getAttribute('data-select-target') ||
|
|
580
|
-
selectItem.closest('[data-select-container]')?.getAttribute('data-select-target');
|
|
581
|
-
if (targetSelector) {
|
|
582
|
-
const targetEl = document.querySelector(targetSelector);
|
|
583
|
-
if (targetEl) {
|
|
584
|
-
if (targetEl.tagName === 'INPUT' || targetEl.tagName === 'SELECT') {
|
|
585
|
-
targetEl.value = val;
|
|
586
|
-
targetEl.dispatchEvent(new Event('input', { bubbles: true }));
|
|
587
|
-
targetEl.dispatchEvent(new Event('change', { bubbles: true }));
|
|
588
|
-
} else {
|
|
589
|
-
targetEl.textContent = selectItem.textContent.trim();
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
const parentDropdown = selectItem.closest('.dropdown-content, .popover-content');
|
|
594
|
-
if (parentDropdown) {
|
|
595
|
-
parentDropdown.classList.remove('open');
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
const modalTrigger = e.target.closest('[data-toggle="modal"], [data-modal-target], [data-dialog-target]');
|
|
599
|
-
if (modalTrigger) {
|
|
600
|
-
e.preventDefault();
|
|
601
|
-
const targetSelector = modalTrigger.getAttribute('data-modal-target') ||
|
|
602
|
-
modalTrigger.getAttribute('data-dialog-target') ||
|
|
603
|
-
modalTrigger.getAttribute('data-target') ||
|
|
604
|
-
modalTrigger.getAttribute('href');
|
|
605
|
-
if (targetSelector) {
|
|
606
|
-
const dialog = document.querySelector(targetSelector);
|
|
607
|
-
if (dialog && typeof dialog.showModal === 'function') {
|
|
608
|
-
dialog.showModal();
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
return;
|
|
612
|
-
}
|
|
613
|
-
const dismissTrigger = e.target.closest('[data-dismiss="modal"], [data-close-dialog], [data-close-modal]');
|
|
614
|
-
if (dismissTrigger) {
|
|
615
|
-
e.preventDefault();
|
|
616
|
-
const dialog = dismissTrigger.closest('dialog') ||
|
|
617
|
-
document.querySelector(dismissTrigger.getAttribute('data-target') || '');
|
|
618
|
-
if (dialog && typeof dialog.close === 'function') {
|
|
619
|
-
dialog.close();
|
|
620
|
-
}
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
|
-
const themeTrigger = e.target.closest('[data-toggle="theme"]');
|
|
624
|
-
if (themeTrigger) {
|
|
625
|
-
e.preventDefault();
|
|
626
|
-
const html = document.documentElement;
|
|
627
|
-
const current = html.getAttribute('data-theme') || 'light';
|
|
628
|
-
const next = current === 'dark' ? 'light' : 'dark';
|
|
629
|
-
html.setAttribute('data-theme', next);
|
|
630
|
-
try {
|
|
631
|
-
localStorage.setItem('bluebird-theme', next);
|
|
632
|
-
} catch (err) { }
|
|
633
|
-
return;
|
|
634
|
-
}
|
|
635
|
-
const toastTrigger = e.target.closest('[data-toast]');
|
|
636
|
-
if (toastTrigger) {
|
|
637
|
-
e.preventDefault();
|
|
638
|
-
const desc = toastTrigger.getAttribute('data-toast') || '';
|
|
639
|
-
const title = toastTrigger.getAttribute('data-toast-title') || '';
|
|
640
|
-
const type = toastTrigger.getAttribute('data-toast-type') || 'info';
|
|
641
|
-
if (typeof bluebird === 'function') {
|
|
642
|
-
bluebird('toast', { title, description: desc, type });
|
|
643
|
-
}
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
const snackbarTrigger = e.target.closest('[data-snackbar]');
|
|
647
|
-
if (snackbarTrigger) {
|
|
648
|
-
e.preventDefault();
|
|
649
|
-
const message = snackbarTrigger.getAttribute('data-snackbar') || '';
|
|
650
|
-
const type = snackbarTrigger.getAttribute('data-snackbar-type') || 'info';
|
|
651
|
-
if (typeof bluebird === 'function') {
|
|
652
|
-
bluebird('snackbar', { message, type });
|
|
653
|
-
}
|
|
654
|
-
return;
|
|
655
|
-
}
|
|
656
|
-
if (!e.target.closest('.dropdown') && !e.target.closest('.popover')) {
|
|
657
|
-
document.querySelectorAll('.dropdown-content.open, .popover-content.open').forEach(el => {
|
|
658
|
-
el.classList.remove('open');
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
});
|
|
662
|
-
document.addEventListener('input', (e) => {
|
|
663
|
-
const filterInput = e.target.closest('[data-filter-target]');
|
|
664
|
-
if (filterInput) {
|
|
665
|
-
const targetSelector = filterInput.getAttribute('data-filter-target');
|
|
666
|
-
const targetContainer = document.querySelector(targetSelector);
|
|
667
|
-
if (targetContainer) {
|
|
668
|
-
const query = filterInput.value.toLowerCase().trim();
|
|
669
|
-
const items = targetContainer.querySelectorAll('[data-filter-item], li, tr, .card, .dropdown-item, .item');
|
|
670
|
-
let visibleCount = 0;
|
|
671
|
-
items.forEach(item => {
|
|
672
|
-
const text = item.textContent.toLowerCase();
|
|
673
|
-
const matches = text.includes(query);
|
|
674
|
-
item.style.display = matches ? '' : 'none';
|
|
675
|
-
if (matches) visibleCount++;
|
|
676
|
-
});
|
|
677
|
-
const emptyMsg = targetContainer.querySelector('.no-filter-results');
|
|
678
|
-
if (emptyMsg) {
|
|
679
|
-
emptyMsg.style.display = visibleCount === 0 ? 'block' : 'none';
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
if (e.target.matches('textarea[data-auto-resize]')) {
|
|
684
|
-
const textarea = e.target;
|
|
685
|
-
textarea.style.height = 'auto';
|
|
686
|
-
textarea.style.height = (textarea.scrollHeight + 2) + 'px';
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
document.addEventListener('keydown', (e) => {
|
|
690
|
-
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
|
|
691
|
-
e.preventDefault();
|
|
692
|
-
if (typeof bluebird === 'function') {
|
|
693
|
-
bluebird('command', { action: 'toggle' });
|
|
694
|
-
}
|
|
695
|
-
} else if (e.key === 'Escape') {
|
|
696
|
-
const openCommand = document.querySelector('.command-backdrop.open');
|
|
697
|
-
if (openCommand && typeof bluebird === 'function') {
|
|
698
|
-
bluebird('command', { action: 'close' });
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
})();
|
|
703
|
-
(function () {
|
|
704
|
-
function init() {
|
|
705
|
-
cleanupOrphanedBackdrops();
|
|
706
|
-
initMobileDrawer();
|
|
707
|
-
document.querySelectorAll('.carousel').forEach(c => initSingleCarousel(c));
|
|
708
|
-
document.querySelectorAll('textarea[data-auto-resize]').forEach(t => {
|
|
709
|
-
t.style.height = 'auto';
|
|
710
|
-
t.style.height = (t.scrollHeight + 2) + 'px';
|
|
711
|
-
});
|
|
712
|
-
try {
|
|
713
|
-
const savedTheme = localStorage.getItem('bluebird-theme');
|
|
714
|
-
if (savedTheme) {
|
|
715
|
-
document.documentElement.setAttribute('data-theme', savedTheme);
|
|
716
|
-
}
|
|
717
|
-
} catch (e) { }
|
|
718
|
-
}
|
|
719
|
-
if (document.readyState === 'loading') {
|
|
720
|
-
document.addEventListener('DOMContentLoaded', () => setTimeout(init, 100));
|
|
721
|
-
} else {
|
|
722
|
-
setTimeout(init, 100);
|
|
723
|
-
}
|
|
724
|
-
})();
|
|
725
|
-
async function Http(
|
|
726
|
-
url = "/",
|
|
727
|
-
method = "GET",
|
|
728
|
-
body = false,
|
|
729
|
-
bodyForm = false,
|
|
730
|
-
headers = {},
|
|
731
|
-
) {
|
|
732
|
-
const csrfEl = document.getElementById("csrf");
|
|
733
|
-
const csrfToken = csrfEl ? csrfEl.value : null;
|
|
734
|
-
const mergedHeaders = { ...headers };
|
|
735
|
-
if (csrfToken) {
|
|
736
|
-
mergedHeaders["X-CSRF-Token"] = csrfToken;
|
|
737
|
-
}
|
|
738
|
-
const options = { method: method, headers: mergedHeaders, credentials: "include" };
|
|
739
|
-
if (body) {
|
|
740
|
-
const payload = csrfToken ? { ...body, csrf: csrfToken } : body;
|
|
741
|
-
options["body"] = JSON.stringify(payload);
|
|
742
|
-
if (!mergedHeaders["Content-Type"]) {
|
|
743
|
-
mergedHeaders["Content-Type"] = "application/json";
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
if (bodyForm) {
|
|
747
|
-
if (csrfToken && bodyForm instanceof FormData) {
|
|
748
|
-
bodyForm.append("csrf", csrfToken);
|
|
749
|
-
}
|
|
750
|
-
options["body"] = bodyForm;
|
|
751
|
-
}
|
|
752
|
-
const response = await fetch(url, options);
|
|
753
|
-
if (!response.ok) {
|
|
754
|
-
let errorData;
|
|
755
|
-
try {
|
|
756
|
-
errorData = await response.json();
|
|
757
|
-
} catch {
|
|
758
|
-
errorData = { message: `HTTP Error ${response.status}: ${response.statusText}` };
|
|
759
|
-
}
|
|
760
|
-
throw new Error(errorData.message || errorData.msg || errorData.mensaje || "Fetch request failed");
|
|
761
|
-
}
|
|
762
|
-
return await response.json();
|
|
763
|
-
}
|
|
764
|
-
function getUrlParameter(name) {
|
|
765
|
-
return new URLSearchParams(window.location.search).get(name);
|
|
766
|
-
}
|
|
767
|
-
function lang(l = "es") {
|
|
768
|
-
const docLang = document.documentElement.lang || "es";
|
|
769
|
-
return docLang === l || docLang.startsWith(l);
|
|
770
|
-
}
|
|
771
|
-
class ResponsiveDataTable {
|
|
772
|
-
constructor(containerId, options = {}) {
|
|
773
|
-
this.container = typeof containerId === "string" ? document.getElementById(containerId) : containerId;
|
|
774
|
-
if (!this.container) return;
|
|
775
|
-
this.defaults = {
|
|
776
|
-
data: [],
|
|
777
|
-
columns: [],
|
|
778
|
-
rowsPerPage: 10,
|
|
779
|
-
search: true,
|
|
780
|
-
pagination: true,
|
|
781
|
-
headerTitles: {},
|
|
782
|
-
summaryFields: ["id"],
|
|
783
|
-
edit: false,
|
|
784
|
-
delete: false,
|
|
785
|
-
breakpoint: 768,
|
|
786
|
-
};
|
|
787
|
-
this.options = { ...this.defaults, ...options };
|
|
788
|
-
this.currentPage = 1;
|
|
789
|
-
this.filteredData = [...this.options.data];
|
|
790
|
-
this.isMobile = window.innerWidth < this.options.breakpoint;
|
|
791
|
-
this.init();
|
|
792
|
-
window.addEventListener("resize", () => this.handleResize());
|
|
793
|
-
}
|
|
794
|
-
init() {
|
|
795
|
-
this.renderContainer();
|
|
796
|
-
this.updateTable();
|
|
797
|
-
if (this.options.search) this.setupSearch();
|
|
798
|
-
}
|
|
799
|
-
handleResize() {
|
|
800
|
-
const wasMobile = this.isMobile;
|
|
801
|
-
this.isMobile = window.innerWidth < this.options.breakpoint;
|
|
802
|
-
if (wasMobile !== this.isMobile) this.updateTable();
|
|
803
|
-
}
|
|
804
|
-
renderContainer() {
|
|
805
|
-
this.container.innerHTML = `
|
|
806
|
-
<section class="w-full">
|
|
807
|
-
${this.options.search
|
|
808
|
-
? `<div class="mb-4 flex items-center justify-between"><input type="search" class="datatable-search-input outline" placeholder="${lang() ? "Buscar..." : "Search..."}" aria-label="Search"/></div>`
|
|
809
|
-
: ""
|
|
810
|
-
}
|
|
811
|
-
<div class="overflow-x-auto">
|
|
812
|
-
<table class="datatable-table hidden"></table>
|
|
813
|
-
<div class="datatable-mobile"></div>
|
|
814
|
-
</div>
|
|
815
|
-
${this.options.pagination ? `<nav class="datatable-pagination mt-4 flex items-center justify-center gap-1" aria-label="Pagination"></nav>` : ""}
|
|
816
|
-
</section>`;
|
|
817
|
-
}
|
|
818
|
-
renderTable() {
|
|
819
|
-
const table = this.container.querySelector(".datatable-table");
|
|
820
|
-
const mobileView = this.container.querySelector(".datatable-mobile");
|
|
821
|
-
if (!table || !mobileView) return;
|
|
822
|
-
if (this.isMobile) {
|
|
823
|
-
table.classList.add("hidden");
|
|
824
|
-
mobileView.classList.remove("hidden");
|
|
825
|
-
this.renderMobileView();
|
|
826
|
-
} else {
|
|
827
|
-
table.classList.remove("hidden");
|
|
828
|
-
mobileView.classList.add("hidden");
|
|
829
|
-
this.renderDesktopTable();
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
renderDesktopTable() {
|
|
833
|
-
const table = this.container.querySelector(".datatable-table");
|
|
834
|
-
table.innerHTML = `
|
|
835
|
-
<thead>
|
|
836
|
-
<tr class="datatable-header"></tr>
|
|
837
|
-
</thead>
|
|
838
|
-
<tbody class="datatable-body"></tbody>`;
|
|
839
|
-
const headerRow = table.querySelector("thead tr");
|
|
840
|
-
this.options.columns.forEach((column) => {
|
|
841
|
-
const th = document.createElement("th");
|
|
842
|
-
th.scope = "col";
|
|
843
|
-
th.textContent =
|
|
844
|
-
this.options.headerTitles[column.key] || column.title || column.key;
|
|
845
|
-
headerRow.appendChild(th);
|
|
846
|
-
});
|
|
847
|
-
if (this.options.edit || this.options.delete) {
|
|
848
|
-
const th = document.createElement("th");
|
|
849
|
-
th.scope = "col";
|
|
850
|
-
th.textContent = lang() ? "Acciones" : "Actions";
|
|
851
|
-
headerRow.appendChild(th);
|
|
852
|
-
}
|
|
853
|
-
const startIndex = (this.currentPage - 1) * this.options.rowsPerPage;
|
|
854
|
-
const endIndex = startIndex + this.options.rowsPerPage;
|
|
855
|
-
const paginatedData = this.filteredData.slice(startIndex, endIndex);
|
|
856
|
-
const tbody = table.querySelector("tbody");
|
|
857
|
-
paginatedData.forEach((item) => {
|
|
858
|
-
const row = document.createElement("tr");
|
|
859
|
-
this.options.columns.forEach((column) => {
|
|
860
|
-
const td = document.createElement("td");
|
|
861
|
-
const value = item[column.key];
|
|
862
|
-
if (
|
|
863
|
-
value &&
|
|
864
|
-
typeof value === "string" &&
|
|
865
|
-
/<[a-z][\s\S]*>/i.test(value)
|
|
866
|
-
) {
|
|
867
|
-
td.innerHTML = value;
|
|
868
|
-
} else {
|
|
869
|
-
td.textContent = value !== undefined && value !== null ? value : "-";
|
|
870
|
-
}
|
|
871
|
-
row.appendChild(td);
|
|
872
|
-
});
|
|
873
|
-
if (this.options.edit || this.options.delete) {
|
|
874
|
-
const td = document.createElement("td");
|
|
875
|
-
const actionsDiv = document.createElement("div");
|
|
876
|
-
actionsDiv.className = "flex items-center gap-2";
|
|
877
|
-
if (this.options.edit) {
|
|
878
|
-
const btn = document.createElement("button");
|
|
879
|
-
btn.className = "outline";
|
|
880
|
-
btn.textContent = lang() ? "Editar" : "Edit";
|
|
881
|
-
btn.onclick = (e) => this.handleAction("edit", e, item);
|
|
882
|
-
actionsDiv.appendChild(btn);
|
|
883
|
-
}
|
|
884
|
-
if (this.options.delete) {
|
|
885
|
-
const btn = document.createElement("button");
|
|
886
|
-
btn.className = "destructive";
|
|
887
|
-
btn.textContent = lang() ? "Eliminar" : "Delete";
|
|
888
|
-
btn.onclick = (e) => this.handleAction("delete", e, item);
|
|
889
|
-
actionsDiv.appendChild(btn);
|
|
890
|
-
}
|
|
891
|
-
td.appendChild(actionsDiv);
|
|
892
|
-
row.appendChild(td);
|
|
893
|
-
}
|
|
894
|
-
tbody.appendChild(row);
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
renderMobileView() {
|
|
898
|
-
const mobileView = this.container.querySelector(".datatable-mobile");
|
|
899
|
-
mobileView.innerHTML = "";
|
|
900
|
-
const startIndex = (this.currentPage - 1) * this.options.rowsPerPage;
|
|
901
|
-
const endIndex = startIndex + this.options.rowsPerPage;
|
|
902
|
-
const paginatedData = this.filteredData.slice(startIndex, endIndex);
|
|
903
|
-
paginatedData.forEach((item) => {
|
|
904
|
-
const card = document.createElement("article");
|
|
905
|
-
card.className = "card mb-4";
|
|
906
|
-
const summary = document.createElement("h3");
|
|
907
|
-
summary.className =
|
|
908
|
-
"flex items-center justify-between font-bold mb-2 pb-2";
|
|
909
|
-
this.options.summaryFields.forEach((fieldKey) => {
|
|
910
|
-
const value = item[fieldKey];
|
|
911
|
-
summary.innerHTML += `<span>${value !== undefined && value !== null ? value : "-"}</span>`;
|
|
912
|
-
});
|
|
913
|
-
card.appendChild(summary);
|
|
914
|
-
const details = document.createElement("dl");
|
|
915
|
-
details.className =
|
|
916
|
-
"grid cols-1 gap-2 mb-2 pb-2";
|
|
917
|
-
this.options.columns.forEach((column) => {
|
|
918
|
-
if (this.options.summaryFields.includes(column.key)) return;
|
|
919
|
-
const dt = document.createElement("dt");
|
|
920
|
-
dt.className =
|
|
921
|
-
"font-bold text-muted";
|
|
922
|
-
dt.textContent =
|
|
923
|
-
this.options.headerTitles[column.key] || column.title || column.key;
|
|
924
|
-
const dd = document.createElement("dd");
|
|
925
|
-
dd.className =
|
|
926
|
-
"text-left";
|
|
927
|
-
const cellValue = item[column.key];
|
|
928
|
-
if (
|
|
929
|
-
cellValue &&
|
|
930
|
-
typeof cellValue === "string" &&
|
|
931
|
-
/<[a-z][\s\S]*>/i.test(cellValue)
|
|
932
|
-
) {
|
|
933
|
-
dd.innerHTML = cellValue;
|
|
934
|
-
} else {
|
|
935
|
-
dd.textContent = cellValue !== undefined && cellValue !== null ? cellValue : "-";
|
|
936
|
-
}
|
|
937
|
-
details.appendChild(dt);
|
|
938
|
-
details.appendChild(dd);
|
|
939
|
-
});
|
|
940
|
-
card.appendChild(details);
|
|
941
|
-
if (this.options.edit || this.options.delete) {
|
|
942
|
-
const actions = document.createElement("div");
|
|
943
|
-
actions.className = "flex items-center gap-2 justify-end";
|
|
944
|
-
if (this.options.edit) {
|
|
945
|
-
const btn = document.createElement("button");
|
|
946
|
-
btn.className = "outline";
|
|
947
|
-
btn.textContent = lang() ? "Editar" : "Edit";
|
|
948
|
-
btn.onclick = (e) => this.handleAction("edit", e, item);
|
|
949
|
-
actions.appendChild(btn);
|
|
950
|
-
}
|
|
951
|
-
if (this.options.delete) {
|
|
952
|
-
const btn = document.createElement("button");
|
|
953
|
-
btn.className = "destructive";
|
|
954
|
-
btn.textContent = lang() ? "Eliminar" : "Delete";
|
|
955
|
-
btn.onclick = (e) => this.handleAction("delete", e, item);
|
|
956
|
-
actions.appendChild(btn);
|
|
957
|
-
}
|
|
958
|
-
card.appendChild(actions);
|
|
959
|
-
}
|
|
960
|
-
mobileView.appendChild(card);
|
|
961
|
-
});
|
|
962
|
-
}
|
|
963
|
-
renderPagination() {
|
|
964
|
-
const pagination = this.container.querySelector(".datatable-pagination");
|
|
965
|
-
if (!pagination || !this.options.pagination) return;
|
|
966
|
-
pagination.innerHTML = "";
|
|
967
|
-
const pageCount = Math.ceil(
|
|
968
|
-
this.filteredData.length / this.options.rowsPerPage,
|
|
969
|
-
);
|
|
970
|
-
if (pageCount <= 1) return;
|
|
971
|
-
const baseClass = "px-3 py-2 outline";
|
|
972
|
-
const activeClass = "px-3 py-2";
|
|
973
|
-
const prevButton = document.createElement("button");
|
|
974
|
-
prevButton.textContent = "«";
|
|
975
|
-
prevButton.className = baseClass;
|
|
976
|
-
prevButton.disabled = this.currentPage === 1;
|
|
977
|
-
prevButton.onclick = () => this.changePage(this.currentPage - 1);
|
|
978
|
-
pagination.appendChild(prevButton);
|
|
979
|
-
const maxVisible = 5;
|
|
980
|
-
let start = Math.max(1, this.currentPage - Math.floor(maxVisible / 2));
|
|
981
|
-
let end = start + maxVisible - 1;
|
|
982
|
-
if (end > pageCount) {
|
|
983
|
-
end = pageCount;
|
|
984
|
-
start = Math.max(1, end - maxVisible + 1);
|
|
985
|
-
}
|
|
986
|
-
if (start > 1) {
|
|
987
|
-
const firstButton = document.createElement("button");
|
|
988
|
-
firstButton.className = baseClass;
|
|
989
|
-
firstButton.textContent = "1";
|
|
990
|
-
firstButton.onclick = () => this.changePage(1);
|
|
991
|
-
pagination.appendChild(firstButton);
|
|
992
|
-
if (start > 2) pagination.appendChild(this.createEllipsis());
|
|
993
|
-
}
|
|
994
|
-
for (let i = start; i <= end; i++) {
|
|
995
|
-
const button = document.createElement("button");
|
|
996
|
-
button.className =
|
|
997
|
-
i === this.currentPage ? activeClass : baseClass;
|
|
998
|
-
button.textContent = i;
|
|
999
|
-
button.onclick = () => this.changePage(i);
|
|
1000
|
-
pagination.appendChild(button);
|
|
1001
|
-
}
|
|
1002
|
-
if (end < pageCount) {
|
|
1003
|
-
if (end < pageCount - 1) pagination.appendChild(this.createEllipsis());
|
|
1004
|
-
const lastButton = document.createElement("button");
|
|
1005
|
-
lastButton.className = baseClass;
|
|
1006
|
-
lastButton.textContent = pageCount;
|
|
1007
|
-
lastButton.onclick = () => this.changePage(pageCount);
|
|
1008
|
-
pagination.appendChild(lastButton);
|
|
1009
|
-
}
|
|
1010
|
-
const nextButton = document.createElement("button");
|
|
1011
|
-
nextButton.className = baseClass;
|
|
1012
|
-
nextButton.textContent = "»";
|
|
1013
|
-
nextButton.disabled = this.currentPage === pageCount;
|
|
1014
|
-
nextButton.onclick = () => this.changePage(this.currentPage + 1);
|
|
1015
|
-
pagination.appendChild(nextButton);
|
|
1016
|
-
}
|
|
1017
|
-
createEllipsis() {
|
|
1018
|
-
const span = document.createElement("span");
|
|
1019
|
-
span.className = "px-2 text-muted";
|
|
1020
|
-
span.textContent = "...";
|
|
1021
|
-
return span;
|
|
1022
|
-
}
|
|
1023
|
-
changePage(page) {
|
|
1024
|
-
this.currentPage = page;
|
|
1025
|
-
this.updateTable();
|
|
1026
|
-
}
|
|
1027
|
-
handleAction(type, event, item) {
|
|
1028
|
-
if (!this.options[type]) return;
|
|
1029
|
-
const callback =
|
|
1030
|
-
typeof this.options[type] === "function"
|
|
1031
|
-
? this.options[type]
|
|
1032
|
-
: window[this.options[type]];
|
|
1033
|
-
if (typeof callback === "function") callback(event, item.id || item);
|
|
1034
|
-
}
|
|
1035
|
-
setupSearch() {
|
|
1036
|
-
const searchInput = this.container.querySelector(".datatable-search-input");
|
|
1037
|
-
if (!searchInput) return;
|
|
1038
|
-
searchInput.addEventListener("input", (e) => {
|
|
1039
|
-
const term = e.target.value.toLowerCase().trim();
|
|
1040
|
-
this.filteredData = this.options.data.filter((item) =>
|
|
1041
|
-
this.options.columns.some((column) =>
|
|
1042
|
-
String(item[column.key] || "")
|
|
1043
|
-
.toLowerCase()
|
|
1044
|
-
.includes(term),
|
|
1045
|
-
),
|
|
1046
|
-
);
|
|
1047
|
-
this.currentPage = 1;
|
|
1048
|
-
this.updateTable();
|
|
1049
|
-
});
|
|
1050
|
-
}
|
|
1051
|
-
updateTable() {
|
|
1052
|
-
this.renderTable();
|
|
1053
|
-
if (this.options.pagination) this.renderPagination();
|
|
1054
|
-
}
|
|
1055
|
-
updateData(newData) {
|
|
1056
|
-
this.options.data = newData;
|
|
1057
|
-
this.filteredData = [...newData];
|
|
1058
|
-
this.currentPage = 1;
|
|
1059
|
-
this.updateTable();
|
|
1060
|
-
}
|
|
1061
|
-
updateColumns(newColumns) {
|
|
1062
|
-
this.options.columns = newColumns;
|
|
1063
|
-
this.updateTable();
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
if (typeof window !== "undefined") {
|
|
1067
|
-
window.ResponsiveDataTable = ResponsiveDataTable;
|
|
1068
|
-
window.Http = Http;
|
|
1069
|
-
window.getUrlParameter = getUrlParameter;
|
|
1070
|
-
window.snackbar = snackbar;
|
|
1071
|
-
window.toast = toast;
|
|
1072
|
-
window.bluebird = bluebird; window.dismissToast = dismissToast; window.initMobileDrawer = initMobileDrawer; window.initSingleCarousel = initSingleCarousel; window.lang = lang;
|
|
1073
|
-
}
|