@parallelogram-js/dashboard 0.0.0-stage → 0.1.1
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 +113 -0
- package/LICENSE +21 -0
- package/README.md +1390 -2
- package/dist/parallelogram-dashboard.css +9401 -0
- package/dist/parallelogram-dashboard.css.map +1 -0
- package/dist/parallelogram-dashboard.min.css +1 -0
- package/package.json +72 -4
- package/scss/_base.scss +403 -0
- package/scss/_datetime.scss +50 -0
- package/scss/_icon.scss +40 -0
- package/scss/_index.scss +60 -0
- package/scss/_mixins.scss +396 -0
- package/scss/_tokens.scss +340 -0
- package/scss/_utilities.scss +464 -0
- package/scss/_variables.scss +219 -0
- package/scss/components/_accordion.scss +297 -0
- package/scss/components/_actionbar.scss +333 -0
- package/scss/components/_alert.scss +183 -0
- package/scss/components/_avatar.scss +203 -0
- package/scss/components/_badge.scss +176 -0
- package/scss/components/_banner.scss +344 -0
- package/scss/components/_breadcrumb.scss +220 -0
- package/scss/components/_button.scss +264 -0
- package/scss/components/_card.scss +256 -0
- package/scss/components/_chart.scss +246 -0
- package/scss/components/_command.scss +267 -0
- package/scss/components/_dashboard.scss +681 -0
- package/scss/components/_data-list.scss +280 -0
- package/scss/components/_dropdown.scss +318 -0
- package/scss/components/_empty.scss +226 -0
- package/scss/components/_filebrowser.scss +906 -0
- package/scss/components/_form-layout.scss +332 -0
- package/scss/components/_input.scss +310 -0
- package/scss/components/_list.scss +130 -0
- package/scss/components/_media.scss +239 -0
- package/scss/components/_modal.scss +298 -0
- package/scss/components/_navbar.scss +312 -0
- package/scss/components/_notification.scss +59 -0
- package/scss/components/_pageheader.scss +99 -0
- package/scss/components/_pagination.scss +165 -0
- package/scss/components/_progress.scss +333 -0
- package/scss/components/_separator.scss +129 -0
- package/scss/components/_sheet.scss +286 -0
- package/scss/components/_sidebar.scss +324 -0
- package/scss/components/_skeleton.scss +246 -0
- package/scss/components/_stat.scss +218 -0
- package/scss/components/_table.scss +589 -0
- package/scss/components/_tabs.scss +266 -0
- package/scss/components/_timeline.scss +339 -0
- package/scss/components/_toast.scss +259 -0
- package/scss/components/_toolbar.scss +301 -0
- package/scss/components/_tooltip.scss +250 -0
- package/scss/main.scss +6 -0
- package/src/js/behaviours/accordion.js +58 -0
- package/src/js/behaviours/action-bar-list.js +406 -0
- package/src/js/behaviours/action-bar.js +29 -0
- package/src/js/behaviours/chart.js +339 -0
- package/src/js/behaviours/collapsible.js +34 -0
- package/src/js/behaviours/editable-table.js +91 -0
- package/src/js/behaviours/expandable.js +80 -0
- package/src/js/behaviours/overflow-actions.js +137 -0
- package/src/js/behaviours/publish-schedule.js +91 -0
- package/src/js/behaviours/search-clear.js +19 -0
- package/src/js/behaviours/segmented-control.js +43 -0
- package/src/js/behaviours/submenu.js +73 -0
- package/src/js/behaviours/table-columns.js +77 -0
- package/src/js/behaviours/table-paste.js +305 -0
- package/src/js/behaviours/table-reorder.js +252 -0
- package/src/js/behaviours/table-sort.js +101 -0
- package/src/js/behaviours/tabs.js +148 -0
- package/src/js/behaviours/toast-manager.js +106 -0
- package/src/js/behaviours/toggle.js +186 -0
- package/src/js/behaviours/unsaved-guard.js +88 -0
- package/src/js/core-loader.js +26 -0
- package/src/js/index.js +85 -0
- package/src/js/polyfills/dialog-commands.js +20 -0
- package/src/js/util/dom.js +39 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { leadingEdge } from '../util/dom.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Behaviour for an .actionbar__list: expand and collapse, and optional reordering.
|
|
5
|
+
*
|
|
6
|
+
* An .actionbar__toggle with aria-controls shows or hides the child list it names.
|
|
7
|
+
*
|
|
8
|
+
* data-actionbar-sortable reorders items within the list; data-actionbar-sortable="tree" makes the
|
|
9
|
+
* list and every .actionbar__list nested inside it one tree, so items can also move between
|
|
10
|
+
* parents. Drag an .actionbar__handle: the bar under the pointer shows a line before or after it,
|
|
11
|
+
* or (in a tree, over the middle of a bar) an outline for "drop inside as a child". With the
|
|
12
|
+
* keyboard, focus a handle and press Space to pick the item up, the up and down arrows to move
|
|
13
|
+
* it, and in a tree the right arrow to make it a child of the item above and the left arrow to
|
|
14
|
+
* move it out a level; Space drops and Escape cancels. Moves are announced to screen readers and
|
|
15
|
+
* the root list dispatches a bubbling "actionbar:reorder" event with
|
|
16
|
+
* { item, from, to, fromParent, toParent }, where the parents are the owning <li> or null.
|
|
17
|
+
*/
|
|
18
|
+
export class ActionBarList {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.elements = new WeakMap();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
mount(list) {
|
|
24
|
+
if (this.elements.has(list)) return;
|
|
25
|
+
list.addEventListener('click', (e) => this._toggle(e, list));
|
|
26
|
+
|
|
27
|
+
// Lists inside a tree are driven by the tree's root
|
|
28
|
+
const insideTree = list.parentElement?.closest('[data-actionbar-sortable="tree"]');
|
|
29
|
+
if (!list.hasAttribute('data-actionbar-sortable') || insideTree) {
|
|
30
|
+
this.elements.set(list, {});
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const status = document.createElement('div');
|
|
35
|
+
status.className = 'sr-only';
|
|
36
|
+
status.setAttribute('aria-live', 'assertive');
|
|
37
|
+
list.after(status);
|
|
38
|
+
|
|
39
|
+
const state = { root: list, tree: list.dataset.actionbarSortable === 'tree', status, grabbed: null, origin: null };
|
|
40
|
+
list.addEventListener('pointerdown', (e) => this._pointerDown(e, state));
|
|
41
|
+
list.addEventListener('keydown', (e) => this._keyDown(e, state));
|
|
42
|
+
this.elements.set(list, state);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_toggle(event, list) {
|
|
46
|
+
const toggle = event.target.closest('.actionbar__toggle[aria-controls]');
|
|
47
|
+
if (!toggle || toggle.closest('.actionbar__list') !== list) return;
|
|
48
|
+
const open = toggle.getAttribute('aria-expanded') !== 'true';
|
|
49
|
+
toggle.setAttribute('aria-expanded', String(open));
|
|
50
|
+
const children = document.getElementById(toggle.getAttribute('aria-controls'));
|
|
51
|
+
if (children) children.hidden = !open;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
// Structure helpers
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
/** The list item a handle belongs to, if the handle is part of this root. */
|
|
59
|
+
_itemFor(handle, state) {
|
|
60
|
+
if (!handle) return null;
|
|
61
|
+
const item = handle.closest('li');
|
|
62
|
+
const owner = item?.parentElement;
|
|
63
|
+
if (!owner?.matches('.actionbar__list')) return null;
|
|
64
|
+
if (state.tree ? !state.root.contains(owner) : owner !== state.root) return null;
|
|
65
|
+
// A nested sortable root handles its own items
|
|
66
|
+
const nearestRoot = owner.closest('[data-actionbar-sortable]');
|
|
67
|
+
return nearestRoot === state.root || (state.tree && state.root.contains(nearestRoot)) ? item : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
_bar(item) {
|
|
71
|
+
return item.querySelector(':scope > .actionbar');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_name(item) {
|
|
75
|
+
return this._bar(item)?.querySelector('.actionbar__label')?.textContent.trim() || 'Item';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
_parentItem(item) {
|
|
79
|
+
const owner = item.parentElement;
|
|
80
|
+
return owner === this._rootOf(item) ? null : owner.closest('li');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
_rootOf(item) {
|
|
84
|
+
return item.closest('[data-actionbar-sortable="tree"]') || item.parentElement;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
_childList(item) {
|
|
88
|
+
return item.querySelector(':scope > .actionbar__list');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
_position(item) {
|
|
92
|
+
return { list: item.parentElement, index: [...item.parentElement.children].indexOf(item), parent: this._parentItem(item) };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Items a dragged item could land next to: visible, and not the item or its descendants. */
|
|
96
|
+
_candidates(state, item) {
|
|
97
|
+
const all = state.tree ? [...state.root.querySelectorAll('li')] : [...state.root.children];
|
|
98
|
+
return all.filter(li => li !== item && !item.contains(li) && this._bar(li) && li.offsetParent !== null);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Give an item a child list (and a live toggle) so something can be dropped inside it. */
|
|
102
|
+
_ensureChildList(parent) {
|
|
103
|
+
let list = this._childList(parent);
|
|
104
|
+
if (!list) {
|
|
105
|
+
list = document.createElement('ul');
|
|
106
|
+
list.className = 'actionbar__list';
|
|
107
|
+
list.id = `${parent.id || 'actionbar-item'}-${Math.random().toString(36).slice(2, 8)}-children`;
|
|
108
|
+
list.setAttribute('aria-label', `Under ${this._name(parent)}`);
|
|
109
|
+
parent.append(list);
|
|
110
|
+
}
|
|
111
|
+
const toggle = this._bar(parent).querySelector('.actionbar__toggle');
|
|
112
|
+
if (toggle && toggle.tagName !== 'BUTTON') {
|
|
113
|
+
const button = document.createElement('button');
|
|
114
|
+
button.type = 'button';
|
|
115
|
+
button.className = toggle.className;
|
|
116
|
+
button.setAttribute('aria-label', `Show items under ${this._name(parent)}`);
|
|
117
|
+
button.innerHTML = '<svg class="icon" viewBox="0 0 24 24"><path d="M6 9l6 6l6 -6"/></svg>';
|
|
118
|
+
toggle.replaceWith(button);
|
|
119
|
+
}
|
|
120
|
+
const button = this._bar(parent).querySelector('button.actionbar__toggle');
|
|
121
|
+
if (button) {
|
|
122
|
+
button.setAttribute('aria-controls', list.id);
|
|
123
|
+
button.setAttribute('aria-expanded', 'true');
|
|
124
|
+
}
|
|
125
|
+
list.hidden = false;
|
|
126
|
+
return list;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Remove a nested list left empty by a move, and turn its toggle back into a spacer. */
|
|
130
|
+
_pruneEmpty(list, state) {
|
|
131
|
+
if (!list || list === state.root || list.children.length) return;
|
|
132
|
+
const parent = list.closest('li');
|
|
133
|
+
list.remove();
|
|
134
|
+
const toggle = parent && this._bar(parent).querySelector('button.actionbar__toggle');
|
|
135
|
+
if (toggle) {
|
|
136
|
+
const spacer = document.createElement('span');
|
|
137
|
+
spacer.className = toggle.className;
|
|
138
|
+
spacer.setAttribute('aria-hidden', 'true');
|
|
139
|
+
toggle.replaceWith(spacer);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_place(item, target, where, state) {
|
|
144
|
+
const oldList = item.parentElement;
|
|
145
|
+
if (where === 'inside') {
|
|
146
|
+
this._ensureChildList(target).append(item);
|
|
147
|
+
} else if (where === 'first-inside') {
|
|
148
|
+
this._ensureChildList(target).prepend(item);
|
|
149
|
+
} else {
|
|
150
|
+
target.parentElement.insertBefore(item, where === 'before' ? target : target.nextElementSibling);
|
|
151
|
+
}
|
|
152
|
+
this._pruneEmpty(oldList, state);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_dispatch(state, item) {
|
|
156
|
+
const from = state.origin;
|
|
157
|
+
const to = this._position(item);
|
|
158
|
+
if (from.list === to.list && from.index === to.index) return;
|
|
159
|
+
state.root.dispatchEvent(new CustomEvent('actionbar:reorder', {
|
|
160
|
+
bubbles: true,
|
|
161
|
+
detail: { item, from: from.index, to: to.index, fromParent: from.parent, toParent: to.parent },
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
_announce(state, message) {
|
|
166
|
+
state.status.textContent = message;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
_describe(item) {
|
|
170
|
+
const { index, list, parent } = this._position(item);
|
|
171
|
+
const where = parent ? `under ${this._name(parent)}` : 'at the top level';
|
|
172
|
+
return `position ${index + 1} of ${list.children.length} ${where}`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ---------------------------------------------------------------------------
|
|
176
|
+
// Pointer dragging
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The item moves to its landing place as the pointer moves, so a gap opens where it will drop
|
|
181
|
+
* while the item itself (with any children) follows the pointer. Other rows slide out of the
|
|
182
|
+
* way. Releasing settles the item into the gap; Escape or a cancelled pointer puts it back.
|
|
183
|
+
*/
|
|
184
|
+
_pointerDown(event, state) {
|
|
185
|
+
const handle = event.target.closest('.actionbar__handle');
|
|
186
|
+
const item = this._itemFor(handle, state);
|
|
187
|
+
if (!item || event.button !== 0) return;
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
|
|
190
|
+
const bar = this._bar(item);
|
|
191
|
+
const grabOffset = event.clientY - item.getBoundingClientRect().top;
|
|
192
|
+
let pointerY = event.clientY;
|
|
193
|
+
state.origin = this._position(item);
|
|
194
|
+
bar.setAttribute('data-dragging', '');
|
|
195
|
+
item.style.position = 'relative';
|
|
196
|
+
item.style.zIndex = '2';
|
|
197
|
+
|
|
198
|
+
const follow = () => {
|
|
199
|
+
item.style.transform = '';
|
|
200
|
+
const slotTop = item.getBoundingClientRect().top;
|
|
201
|
+
item.style.transform = `translateY(${pointerY - grabOffset - slotTop}px)`;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const move = (e) => {
|
|
205
|
+
pointerY = e.clientY;
|
|
206
|
+
// The item (not the bar inside it) carries the drag transform, so its box gives the slot
|
|
207
|
+
const edge = leadingEdge(this._layoutRect(item).top, pointerY - grabOffset, bar.offsetHeight);
|
|
208
|
+
const next = this._dropTarget(state, item, pointerY, edge);
|
|
209
|
+
if (next && !this._isAt(item, next)) {
|
|
210
|
+
this._animate(state, item, () => this._place(item, next.target, next.where, state));
|
|
211
|
+
}
|
|
212
|
+
follow();
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const finish = (commit) => {
|
|
216
|
+
document.removeEventListener('pointermove', move);
|
|
217
|
+
document.removeEventListener('pointerup', release);
|
|
218
|
+
document.removeEventListener('pointercancel', cancel);
|
|
219
|
+
document.removeEventListener('keydown', escape);
|
|
220
|
+
if (!commit) this._restore(item, state);
|
|
221
|
+
this._settle(item, () => {
|
|
222
|
+
bar.removeAttribute('data-dragging');
|
|
223
|
+
item.style.position = '';
|
|
224
|
+
item.style.zIndex = '';
|
|
225
|
+
});
|
|
226
|
+
if (commit) this._dispatch(state, item);
|
|
227
|
+
};
|
|
228
|
+
const release = () => finish(true);
|
|
229
|
+
const cancel = () => finish(false);
|
|
230
|
+
const escape = (e) => {
|
|
231
|
+
if (e.key !== 'Escape') return;
|
|
232
|
+
e.preventDefault();
|
|
233
|
+
finish(false);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
document.addEventListener('pointermove', move);
|
|
237
|
+
document.addEventListener('pointerup', release);
|
|
238
|
+
document.addEventListener('pointercancel', cancel);
|
|
239
|
+
document.addEventListener('keydown', escape);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Whether the item already sits where a drop target would put it. */
|
|
243
|
+
_isAt(item, { target, where }) {
|
|
244
|
+
if (where === 'before') return item.nextElementSibling === target;
|
|
245
|
+
if (where === 'after') return target.nextElementSibling === item;
|
|
246
|
+
const list = this._childList(target);
|
|
247
|
+
if (!list || item.parentElement !== list) return false;
|
|
248
|
+
return where === 'inside' ? !item.nextElementSibling : !item.previousElementSibling;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
_reducedMotion() {
|
|
252
|
+
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** Run a DOM move, then slide the other bars from where they were to where they now are. */
|
|
256
|
+
_animate(state, item, mutate) {
|
|
257
|
+
const bars = this._candidates(state, item).map(li => this._bar(li));
|
|
258
|
+
const before = new Map(bars.map(bar => [bar, bar.getBoundingClientRect().top]));
|
|
259
|
+
mutate();
|
|
260
|
+
if (this._reducedMotion()) return;
|
|
261
|
+
for (const [bar, top] of before) {
|
|
262
|
+
const delta = top - bar.getBoundingClientRect().top;
|
|
263
|
+
if (delta) {
|
|
264
|
+
bar.animate([{ transform: `translateY(${delta}px)` }, { transform: 'none' }], { duration: 150, easing: 'ease-out' });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Drop the pointer offset and glide the item into its slot, then run done. */
|
|
270
|
+
_settle(item, done) {
|
|
271
|
+
const from = item.getBoundingClientRect().top;
|
|
272
|
+
item.style.transform = '';
|
|
273
|
+
const delta = from - item.getBoundingClientRect().top;
|
|
274
|
+
if (!delta || this._reducedMotion()) {
|
|
275
|
+
done();
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
item.animate([{ transform: `translateY(${delta}px)` }, { transform: 'none' }], { duration: 150, easing: 'ease-out' })
|
|
279
|
+
.finished.then(done, done);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Put an item back where the current move started. */
|
|
283
|
+
_restore(item, state) {
|
|
284
|
+
const { list, index, parent } = state.origin;
|
|
285
|
+
const oldList = item.parentElement;
|
|
286
|
+
// The original list may have been removed when the move emptied it
|
|
287
|
+
const home = list.isConnected ? list : this._ensureChildList(parent);
|
|
288
|
+
home.insertBefore(item, [...home.children].filter(el => el !== item)[index] || null);
|
|
289
|
+
if (home !== oldList) this._pruneEmpty(oldList, state);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** A bar's box without any slide animation still running on it, so targets don't flicker. */
|
|
293
|
+
_layoutRect(bar) {
|
|
294
|
+
const rect = bar.getBoundingClientRect();
|
|
295
|
+
const shift = new DOMMatrixReadOnly(getComputedStyle(bar).transform).m42;
|
|
296
|
+
return { top: rect.top - shift, bottom: rect.bottom - shift, height: rect.height };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Where the dragged item would land. Before and after follow its leading edge, so a
|
|
301
|
+
* neighbour gives way once half covered; in a tree, the pointer (y) over the middle of a bar
|
|
302
|
+
* still means "drop inside as a child".
|
|
303
|
+
*/
|
|
304
|
+
_dropTarget(state, item, y, edge = y) {
|
|
305
|
+
const nearest = (at) => {
|
|
306
|
+
let best = null;
|
|
307
|
+
for (const candidate of this._candidates(state, item)) {
|
|
308
|
+
const rect = this._layoutRect(this._bar(candidate));
|
|
309
|
+
const distance = at < rect.top ? rect.top - at : at > rect.bottom ? at - rect.bottom : 0;
|
|
310
|
+
if (!best || distance < best.distance) best = { target: candidate, rect, distance };
|
|
311
|
+
}
|
|
312
|
+
return best;
|
|
313
|
+
};
|
|
314
|
+
const ratio = (at, { rect }) => (at - rect.top) / rect.height;
|
|
315
|
+
|
|
316
|
+
if (state.tree) {
|
|
317
|
+
const under = nearest(y);
|
|
318
|
+
if (!under) return null;
|
|
319
|
+
const middle = ratio(y, under);
|
|
320
|
+
if (middle >= 0.25 && middle <= 0.75 && under.distance === 0) return { target: under.target, where: 'inside' };
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const best = nearest(edge);
|
|
324
|
+
if (!best) return null;
|
|
325
|
+
const { target } = best;
|
|
326
|
+
if (ratio(edge, best) < 0.5) return { target, where: 'before' };
|
|
327
|
+
// Below an open parent, the next visible slot is its first child
|
|
328
|
+
const children = state.tree && this._childList(target);
|
|
329
|
+
return children && !children.hidden && children.children.length
|
|
330
|
+
? { target, where: 'first-inside' }
|
|
331
|
+
: { target, where: 'after' };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// ---------------------------------------------------------------------------
|
|
335
|
+
// Keyboard
|
|
336
|
+
// ---------------------------------------------------------------------------
|
|
337
|
+
|
|
338
|
+
_keyDown(event, state) {
|
|
339
|
+
const handle = event.target.closest('.actionbar__handle');
|
|
340
|
+
const item = this._itemFor(handle, state);
|
|
341
|
+
if (!item) return;
|
|
342
|
+
const bar = this._bar(item);
|
|
343
|
+
const name = this._name(item);
|
|
344
|
+
|
|
345
|
+
if (event.key === ' ' || event.key === 'Enter') {
|
|
346
|
+
event.preventDefault();
|
|
347
|
+
if (state.grabbed === item) {
|
|
348
|
+
state.grabbed = null;
|
|
349
|
+
handle.setAttribute('aria-pressed', 'false');
|
|
350
|
+
bar.removeAttribute('data-dragging');
|
|
351
|
+
this._announce(state, `${name} dropped at ${this._describe(item)}.`);
|
|
352
|
+
this._dispatch(state, item);
|
|
353
|
+
} else {
|
|
354
|
+
state.grabbed = item;
|
|
355
|
+
state.origin = this._position(item);
|
|
356
|
+
handle.setAttribute('aria-pressed', 'true');
|
|
357
|
+
bar.setAttribute('data-dragging', '');
|
|
358
|
+
const levels = state.tree ? ', right arrow to nest it under the item above, left arrow to move it out a level' : '';
|
|
359
|
+
this._announce(state, `${name} grabbed. Use the up and down arrow keys to move it${levels}. Space drops, Escape cancels.`);
|
|
360
|
+
}
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (state.grabbed !== item) return;
|
|
365
|
+
|
|
366
|
+
if (event.key === 'Escape') {
|
|
367
|
+
event.preventDefault();
|
|
368
|
+
this._restore(item, state);
|
|
369
|
+
state.grabbed = null;
|
|
370
|
+
handle.setAttribute('aria-pressed', 'false');
|
|
371
|
+
bar.removeAttribute('data-dragging');
|
|
372
|
+
handle.focus();
|
|
373
|
+
this._announce(state, `Move cancelled. ${name} is back at ${this._describe(item)}.`);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const siblings = [...item.parentElement.children];
|
|
378
|
+
const index = siblings.indexOf(item);
|
|
379
|
+
let moved = false;
|
|
380
|
+
|
|
381
|
+
if (event.key === 'ArrowUp' && index > 0) {
|
|
382
|
+
item.parentElement.insertBefore(item, siblings[index - 1]);
|
|
383
|
+
moved = true;
|
|
384
|
+
} else if (event.key === 'ArrowDown' && index < siblings.length - 1) {
|
|
385
|
+
item.parentElement.insertBefore(item, siblings[index + 1].nextElementSibling);
|
|
386
|
+
moved = true;
|
|
387
|
+
} else if (state.tree && event.key === 'ArrowRight' && index > 0) {
|
|
388
|
+
this._place(item, siblings[index - 1], 'inside', state);
|
|
389
|
+
moved = true;
|
|
390
|
+
} else if (state.tree && event.key === 'ArrowLeft' && this._parentItem(item)) {
|
|
391
|
+
this._place(item, this._parentItem(item), 'after', state);
|
|
392
|
+
moved = true;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (!moved) return;
|
|
396
|
+
event.preventDefault();
|
|
397
|
+
handle.focus();
|
|
398
|
+
this._announce(state, `${name} moved to ${this._describe(item)}.`);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
static enhanceAll(selector = '.actionbar__list', root = document) {
|
|
402
|
+
const instance = new ActionBarList();
|
|
403
|
+
root.querySelectorAll(selector).forEach(el => instance.mount(el));
|
|
404
|
+
return instance;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { OverflowActions } from './overflow-actions.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Folds an action bar's lower-priority segments into a "more" menu before its label is cut off,
|
|
5
|
+
* using OverflowActions with action bar styling for the menu. Bars in a list (and its nested
|
|
6
|
+
* lists) fold together, so a tree's columns stay aligned.
|
|
7
|
+
*/
|
|
8
|
+
export class ActionBar {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.overflow = new OverflowActions();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
mount(bar) {
|
|
14
|
+
let list = bar.closest('.actionbar__list');
|
|
15
|
+
while (list?.parentElement?.closest('.actionbar__list')) list = list.parentElement.closest('.actionbar__list');
|
|
16
|
+
this.overflow.mount(bar, {
|
|
17
|
+
boundary: list || bar,
|
|
18
|
+
protect: '.actionbar__label',
|
|
19
|
+
moreClass: 'actionbar__segment actionbar__more dropdown',
|
|
20
|
+
triggerClass: 'actionbar__trigger dropdown__trigger',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static enhanceAll(selector = '.actionbar', root = document) {
|
|
25
|
+
const instance = new ActionBar();
|
|
26
|
+
root.querySelectorAll(selector).forEach(el => instance.mount(el));
|
|
27
|
+
return instance;
|
|
28
|
+
}
|
|
29
|
+
}
|