@parallelogram-js/dashboard 0.1.7 → 0.1.8
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/CHANGELOG.md +33 -1
- package/dist/parallelogram-dashboard.css +12 -2
- package/dist/parallelogram-dashboard.css.map +1 -1
- package/dist/parallelogram-dashboard.min.css +1 -1
- package/package.json +1 -1
- package/scss/components/_badge.scss +5 -0
- package/scss/components/_dropdown.scss +3 -1
- package/scss/components/_modal.scss +12 -1
- package/src/js/behaviours/confirm-action.js +20 -0
- package/src/js/behaviours/live-filters.js +70 -0
- package/src/js/behaviours/unsaved-guard.js +7 -2
- package/src/js/index.js +5 -0
package/package.json
CHANGED
|
@@ -124,6 +124,11 @@
|
|
|
124
124
|
height: 0.5rem;
|
|
125
125
|
padding: 0;
|
|
126
126
|
border-radius: $radius-full;
|
|
127
|
+
|
|
128
|
+
// The secondary background is a faint tint meant to sit behind text; alone, a dot needs to show
|
|
129
|
+
&.badge--secondary {
|
|
130
|
+
background-color: var(--fg-subtle);
|
|
131
|
+
}
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
// --------------------------------------------------------------------------
|
|
@@ -153,7 +153,9 @@ $dropdown-open: '.dropdown:has(> .dropdown__trigger[aria-expanded="true"]), .dro
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
&__item-icon
|
|
156
|
+
&__item-icon,
|
|
157
|
+
// An icon from a project's icon helper, which draws a plain .icon
|
|
158
|
+
&__item > .icon {
|
|
157
159
|
width: $icon-size-md;
|
|
158
160
|
height: $icon-size-md;
|
|
159
161
|
flex-shrink: 0;
|
|
@@ -267,6 +267,12 @@ p-modal {
|
|
|
267
267
|
margin-bottom: $spacing-sm;
|
|
268
268
|
color: var(--fg-muted);
|
|
269
269
|
|
|
270
|
+
// An icon drawn inside the slot (an <span class="alertdialog__icon"> holding a .icon) fills it
|
|
271
|
+
> .icon {
|
|
272
|
+
width: 100%;
|
|
273
|
+
height: 100%;
|
|
274
|
+
}
|
|
275
|
+
|
|
270
276
|
&--destructive {
|
|
271
277
|
color: var(--destructive);
|
|
272
278
|
}
|
|
@@ -293,6 +299,11 @@ p-modal {
|
|
|
293
299
|
@extend .modal__footer;
|
|
294
300
|
justify-content: center;
|
|
295
301
|
border-top: none;
|
|
296
|
-
padding-top:
|
|
302
|
+
padding-top: $spacing-lg;
|
|
303
|
+
|
|
304
|
+
// Cancel at one end and the action at the other, as in a form's action bar
|
|
305
|
+
&--between {
|
|
306
|
+
justify-content: space-between;
|
|
307
|
+
}
|
|
297
308
|
}
|
|
298
309
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Points one shared confirmation at whichever of many buttons opened it.
|
|
3
|
+
*
|
|
4
|
+
* A page with a Delete on every row needs one .alertdialog, not one per row. Each button opens it
|
|
5
|
+
* as usual (commandfor and command="show-modal") and carries data-confirm-action, the address its
|
|
6
|
+
* form should post to; data-confirm-title, if given, replaces the dialog's .alertdialog__title.
|
|
7
|
+
* The click sets both before the dialog opens.
|
|
8
|
+
*/
|
|
9
|
+
export class ConfirmAction {
|
|
10
|
+
static {
|
|
11
|
+
document.addEventListener('click', (event) => {
|
|
12
|
+
const button = event.target.closest('[data-confirm-action]');
|
|
13
|
+
const dialog = button && document.getElementById(button.getAttribute('commandfor') || '');
|
|
14
|
+
if (!dialog) return;
|
|
15
|
+
dialog.querySelector('form')?.setAttribute('action', button.dataset.confirmAction);
|
|
16
|
+
const title = dialog.querySelector('.alertdialog__title');
|
|
17
|
+
if (title && button.dataset.confirmTitle) title.textContent = button.dataset.confirmTitle;
|
|
18
|
+
}, true);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies a filter form as it changes, so it needs no Apply button.
|
|
3
|
+
*
|
|
4
|
+
* A form with data-live-filters="#results" fetches its own page again with the form's query when a
|
|
5
|
+
* select or checkbox changes, a date picker closes having changed, or a search is typed in (after a
|
|
6
|
+
* pause), then swaps the element the attribute names for its fresh copy and keeps the address in
|
|
7
|
+
* step. Only the results change, so typing is not interrupted. Should the fetch fail, or the page
|
|
8
|
+
* have no such element, the form submits as usual. Keep a submit button (it can be visually hidden)
|
|
9
|
+
* so Enter still works without the script.
|
|
10
|
+
*/
|
|
11
|
+
export class LiveFilters {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.forms = new WeakSet();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
mount(form) {
|
|
17
|
+
if (this.forms.has(form)) return;
|
|
18
|
+
this.forms.add(form);
|
|
19
|
+
|
|
20
|
+
const selector = form.dataset.liveFilters;
|
|
21
|
+
let pending = null;
|
|
22
|
+
let timer = null;
|
|
23
|
+
|
|
24
|
+
const apply = async () => {
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
const url = new URL(form.action || window.location.href, window.location.href);
|
|
27
|
+
url.search = new URLSearchParams(new FormData(form)).toString();
|
|
28
|
+
const results = selector ? document.querySelector(selector) : null;
|
|
29
|
+
if (!results) {
|
|
30
|
+
window.location.assign(url);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
pending?.abort();
|
|
35
|
+
pending = new AbortController();
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch(url, { signal: pending.signal, headers: { Accept: 'text/html' } });
|
|
38
|
+
const fresh = new DOMParser().parseFromString(await response.text(), 'text/html').querySelector(selector);
|
|
39
|
+
if (!response.ok || !fresh) throw new Error(`Filtering returned ${response.status}`);
|
|
40
|
+
results.replaceWith(fresh);
|
|
41
|
+
window.history.replaceState(window.history.state, '', url);
|
|
42
|
+
form.dispatchEvent(new CustomEvent('live-filters:update', { detail: { url: url.href } }));
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (error.name !== 'AbortError') window.location.assign(url);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
form.addEventListener('submit', (event) => {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
apply();
|
|
51
|
+
});
|
|
52
|
+
form.addEventListener('change', (event) => {
|
|
53
|
+
if (event.target.localName !== 'p-datetime' && event.target.type !== 'search') apply();
|
|
54
|
+
});
|
|
55
|
+
form.addEventListener('input', (event) => {
|
|
56
|
+
if (event.target.type !== 'search') return;
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
timer = setTimeout(apply, 300);
|
|
59
|
+
});
|
|
60
|
+
form.addEventListener('p-datetime:close', (event) => {
|
|
61
|
+
if (event.detail?.changed) apply();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static enhanceAll(selector = '[data-live-filters]', root = document) {
|
|
66
|
+
const instance = new LiveFilters();
|
|
67
|
+
root.querySelectorAll(selector).forEach(form => instance.mount(form));
|
|
68
|
+
return instance;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -43,11 +43,16 @@ export class UnsavedGuard {
|
|
|
43
43
|
.filter(field => !field.closest('[data-unsaved-ignore]'));
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* A disabled field isn't submitted, so it counts as empty; a custom field not yet loaded reads its attribute. A
|
|
48
|
+
* field whose value is a list, such as a <p-select multiple>, gives a new array each time it is read, so the list
|
|
49
|
+
* is compared by what it holds.
|
|
50
|
+
*/
|
|
47
51
|
_value(field) {
|
|
48
52
|
if (field.disabled || field.hasAttribute('disabled')) return '';
|
|
49
53
|
if (field.type === 'checkbox' || field.type === 'radio') return field.checked;
|
|
50
|
-
|
|
54
|
+
const value = field.value ?? field.getAttribute('value') ?? '';
|
|
55
|
+
return Array.isArray(value) ? JSON.stringify(value) : value;
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
_record(area) {
|
package/src/js/index.js
CHANGED
|
@@ -26,6 +26,8 @@ import { ActionBar } from './behaviours/action-bar.js';
|
|
|
26
26
|
import { ActionBarList } from './behaviours/action-bar-list.js';
|
|
27
27
|
import { SearchClear } from './behaviours/search-clear.js';
|
|
28
28
|
import { ToastManager } from './behaviours/toast-manager.js';
|
|
29
|
+
import { LiveFilters } from './behaviours/live-filters.js';
|
|
30
|
+
import { ConfirmAction } from './behaviours/confirm-action.js';
|
|
29
31
|
import { loadParallelogramJs } from './core-loader.js';
|
|
30
32
|
|
|
31
33
|
export {
|
|
@@ -49,6 +51,8 @@ export {
|
|
|
49
51
|
ActionBarList,
|
|
50
52
|
SearchClear,
|
|
51
53
|
ToastManager,
|
|
54
|
+
LiveFilters,
|
|
55
|
+
ConfirmAction,
|
|
52
56
|
};
|
|
53
57
|
export { loadParallelogramJs } from './core-loader.js';
|
|
54
58
|
export { polyfillDialogCommands } from './polyfills/dialog-commands.js';
|
|
@@ -81,5 +85,6 @@ export function init(root = document) {
|
|
|
81
85
|
tableReorder: TableReorder.enhanceAll('[data-table-reorder]', root),
|
|
82
86
|
tablePaste: TablePaste.enhanceAll('[data-table-paste]', root),
|
|
83
87
|
chart: Chart.enhanceAll('[data-chart]', root),
|
|
88
|
+
liveFilters: LiveFilters.enhanceAll('[data-live-filters]', root),
|
|
84
89
|
};
|
|
85
90
|
}
|