@rubenlangeweg/mero-ui 0.7.0 → 0.9.0
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 +25 -0
- package/README.md +25 -4
- package/agent-docs/components/accordion.md +1 -1
- package/agent-docs/components/action-bar.md +1 -1
- package/agent-docs/components/action-button.md +32 -1
- package/agent-docs/components/agenda.md +1 -1
- package/agent-docs/components/alert-dialog.md +1 -1
- package/agent-docs/components/alert.md +1 -1
- package/agent-docs/components/app-layout.md +1 -1
- package/agent-docs/components/area-chart.md +1 -1
- package/agent-docs/components/aura.md +1 -1
- package/agent-docs/components/autocomplete.md +1 -1
- package/agent-docs/components/avatar-group.md +1 -1
- package/agent-docs/components/avatar.md +1 -1
- package/agent-docs/components/badge.md +1 -1
- package/agent-docs/components/bar-chart.md +1 -1
- package/agent-docs/components/breadcrumbs.md +1 -1
- package/agent-docs/components/browser-mockup.md +1 -1
- package/agent-docs/components/button-group.md +1 -1
- package/agent-docs/components/button.md +32 -1
- package/agent-docs/components/calendar.md +3 -3
- package/agent-docs/components/card.md +56 -1
- package/agent-docs/components/carousel.md +1 -1
- package/agent-docs/components/cell-color-picker.md +1 -1
- package/agent-docs/components/cell-select.md +1 -1
- package/agent-docs/components/cell-slider.md +1 -1
- package/agent-docs/components/cell-switch.md +1 -1
- package/agent-docs/components/chain-of-thought.md +1 -1
- package/agent-docs/components/chart-tooltip.md +1 -1
- package/agent-docs/components/chat-attachment.md +1 -1
- package/agent-docs/components/chat-conversation.md +1 -1
- package/agent-docs/components/chat-list-view.md +1 -1
- package/agent-docs/components/chat-loader.md +1 -1
- package/agent-docs/components/chat-message-actions.md +1 -1
- package/agent-docs/components/chat-message.md +1 -1
- package/agent-docs/components/chat-source.md +1 -1
- package/agent-docs/components/chat-tool.md +1 -1
- package/agent-docs/components/checkbox-button-group.md +1 -1
- package/agent-docs/components/checkbox-group.md +1 -1
- package/agent-docs/components/checkbox.md +1 -1
- package/agent-docs/components/chip.md +1 -1
- package/agent-docs/components/close-button.md +1 -1
- package/agent-docs/components/code-block.md +1 -1
- package/agent-docs/components/code-mockup.md +1 -1
- package/agent-docs/components/color-area.md +1 -1
- package/agent-docs/components/color-field.md +1 -1
- package/agent-docs/components/color-picker.md +1 -1
- package/agent-docs/components/color-slider.md +1 -1
- package/agent-docs/components/color-swatch.md +1 -1
- package/agent-docs/components/combo-box.md +1 -1
- package/agent-docs/components/command-menu.md +1 -1
- package/agent-docs/components/command.md +1 -1
- package/agent-docs/components/composed-chart.md +1 -1
- package/agent-docs/components/context-menu.md +1 -1
- package/agent-docs/components/countdown.md +1 -1
- package/agent-docs/components/data-grid.md +1 -1
- package/agent-docs/components/date-field.md +1 -1
- package/agent-docs/components/date-picker.md +1 -1
- package/agent-docs/components/date-range-picker.md +1 -1
- package/agent-docs/components/description-list.md +30 -0
- package/agent-docs/components/description.md +1 -1
- package/agent-docs/components/diff.md +1 -1
- package/agent-docs/components/disclosure-group.md +1 -1
- package/agent-docs/components/disclosure.md +1 -1
- package/agent-docs/components/dock.md +1 -1
- package/agent-docs/components/drawer.md +83 -1
- package/agent-docs/components/drop-zone.md +1 -1
- package/agent-docs/components/dropdown.md +1 -1
- package/agent-docs/components/emoji-picker.md +1 -1
- package/agent-docs/components/emoji-reaction-button.md +1 -1
- package/agent-docs/components/empty-state.md +36 -4
- package/agent-docs/components/error-message.md +1 -1
- package/agent-docs/components/fab.md +1 -1
- package/agent-docs/components/field-error.md +1 -1
- package/agent-docs/components/fieldset.md +45 -1
- package/agent-docs/components/file-input.md +1 -1
- package/agent-docs/components/file-tree.md +1 -1
- package/agent-docs/components/filter-chips.md +1 -1
- package/agent-docs/components/floating-toc.md +1 -1
- package/agent-docs/components/footer.md +1 -1
- package/agent-docs/components/form.md +155 -1
- package/agent-docs/components/hero.md +1 -1
- package/agent-docs/components/holo-card.md +1 -1
- package/agent-docs/components/hover-card.md +1 -1
- package/agent-docs/components/hover-gallery.md +1 -1
- package/agent-docs/components/indicator.md +1 -1
- package/agent-docs/components/inline-select.md +1 -1
- package/agent-docs/components/input-group.md +1 -1
- package/agent-docs/components/input-otp.md +1 -1
- package/agent-docs/components/input.md +1 -1
- package/agent-docs/components/item-card-group.md +1 -1
- package/agent-docs/components/item-card.md +1 -1
- package/agent-docs/components/join.md +1 -1
- package/agent-docs/components/joined-filter.md +1 -1
- package/agent-docs/components/kanban.md +1 -1
- package/agent-docs/components/kbd.md +32 -1
- package/agent-docs/components/kpi-group.md +1 -1
- package/agent-docs/components/kpi.md +1 -1
- package/agent-docs/components/label.md +1 -1
- package/agent-docs/components/line-chart.md +1 -1
- package/agent-docs/components/link.md +1 -1
- package/agent-docs/components/list-box.md +1 -1
- package/agent-docs/components/list-view.md +1 -1
- package/agent-docs/components/live-progress.md +34 -1
- package/agent-docs/components/map.md +1 -1
- package/agent-docs/components/markdown.md +1 -1
- package/agent-docs/components/mask.md +1 -1
- package/agent-docs/components/megamenu.md +1 -1
- package/agent-docs/components/menu-button.md +35 -1
- package/agent-docs/components/menu.md +1 -1
- package/agent-docs/components/meter.md +1 -1
- package/agent-docs/components/modal.md +1 -1
- package/agent-docs/components/native-select.md +1 -1
- package/agent-docs/components/navbar.md +1 -1
- package/agent-docs/components/number-field.md +1 -1
- package/agent-docs/components/number-stepper.md +1 -1
- package/agent-docs/components/number-value.md +1 -1
- package/agent-docs/components/page-header.md +69 -0
- package/agent-docs/components/pagination.md +1 -1
- package/agent-docs/components/phone-mockup.md +1 -1
- package/agent-docs/components/pie-chart.md +1 -1
- package/agent-docs/components/popover.md +1 -1
- package/agent-docs/components/pressable-feedback.md +1 -1
- package/agent-docs/components/progress-bar.md +1 -1
- package/agent-docs/components/progress-circle.md +1 -1
- package/agent-docs/components/prompt-input.md +1 -1
- package/agent-docs/components/prompt-suggestion.md +1 -1
- package/agent-docs/components/radar-chart.md +1 -1
- package/agent-docs/components/radial-chart.md +1 -1
- package/agent-docs/components/radio-button-group.md +1 -1
- package/agent-docs/components/radio-group.md +1 -1
- package/agent-docs/components/range-calendar.md +1 -1
- package/agent-docs/components/rating.md +1 -1
- package/agent-docs/components/resizable.md +1 -1
- package/agent-docs/components/rich-text-editor.md +1 -1
- package/agent-docs/components/scroll-shadow.md +1 -1
- package/agent-docs/components/search-field.md +43 -1
- package/agent-docs/components/segment.md +1 -1
- package/agent-docs/components/select.md +1 -1
- package/agent-docs/components/separator.md +1 -1
- package/agent-docs/components/sheet.md +1 -1
- package/agent-docs/components/sidebar.md +1 -1
- package/agent-docs/components/skeleton.md +1 -1
- package/agent-docs/components/slider.md +1 -1
- package/agent-docs/components/sortable-table.md +1 -1
- package/agent-docs/components/spinner.md +1 -1
- package/agent-docs/components/stack.md +1 -1
- package/agent-docs/components/status.md +1 -1
- package/agent-docs/components/stepper.md +1 -1
- package/agent-docs/components/surface.md +1 -1
- package/agent-docs/components/swap.md +1 -1
- package/agent-docs/components/switch.md +1 -1
- package/agent-docs/components/table.md +58 -1
- package/agent-docs/components/tabs.md +24 -1
- package/agent-docs/components/tag-group.md +1 -1
- package/agent-docs/components/text-area.md +1 -1
- package/agent-docs/components/text-field.md +1 -1
- package/agent-docs/components/text-rotate.md +1 -1
- package/agent-docs/components/text-shimmer.md +1 -1
- package/agent-docs/components/theme-controller.md +1 -1
- package/agent-docs/components/time-field.md +1 -1
- package/agent-docs/components/timeline.md +1 -1
- package/agent-docs/components/toast.md +1 -1
- package/agent-docs/components/toggle-button-group.md +1 -1
- package/agent-docs/components/toggle-button.md +1 -1
- package/agent-docs/components/toolbar.md +1 -1
- package/agent-docs/components/tooltip.md +1 -1
- package/agent-docs/components/trend-chip.md +1 -1
- package/agent-docs/components/typed-confirmation.md +1 -1
- package/agent-docs/components/typography.md +24 -1
- package/agent-docs/components/validator.md +1 -1
- package/agent-docs/components/visually-hidden.md +27 -0
- package/agent-docs/components/widget.md +1 -1
- package/agent-docs/components/window-mockup.md +1 -1
- package/agent-docs/llms-components.txt +989 -194
- package/agent-docs/llms-full.txt +1079 -206
- package/agent-docs/llms-patterns.txt +91 -13
- package/agent-docs/llms.txt +5 -2
- package/package.json +4 -1
- package/ui/insight-charts.mjs +1 -1
- package/ui/insight-markdown.mjs +1 -1
- package/ui/mero-collections.css +1 -7
- package/ui/mero-collections.js +1 -1
- package/ui/mero-composition.css +1 -1
- package/ui/mero-composition.js +1 -1
- package/ui/mero-forms.js +415 -27
- package/ui/mero-gallery.css +1 -1
- package/ui/mero-gallery.js +1 -1
- package/ui/mero-insights.css +1 -1
- package/ui/mero-insights.js +1 -1
- package/ui/mero-inventory.css +1 -1
- package/ui/mero-inventory.js +1 -1
- package/ui/mero-layouts.css +1 -4
- package/ui/mero-live.js +25 -4
- package/ui/mero-workspace.css +1 -1
- package/ui/mero-workspace.js +1 -1
- package/ui/mero.css +104 -5
- package/ui/mero.js +220 -8
package/ui/mero.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @rubenlangeweg/mero-ui 0.
|
|
1
|
+
/*! @rubenlangeweg/mero-ui 0.9.0 | MIT */
|
|
2
2
|
:root {
|
|
3
3
|
--mero-control-height: 2.5rem;
|
|
4
4
|
--mero-control-padding-inline: .75rem;
|
|
@@ -69,6 +69,12 @@
|
|
|
69
69
|
|
|
70
70
|
:where(.mero-scope) { display: contents; }
|
|
71
71
|
|
|
72
|
+
/* Text for screen readers only, such as the object of a short button label or what a count counts. */
|
|
73
|
+
:where(.mero-sr-only) {
|
|
74
|
+
position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0; border: 0;
|
|
75
|
+
overflow: hidden; clip-path: inset(50%); white-space: nowrap;
|
|
76
|
+
}
|
|
77
|
+
|
|
72
78
|
:where([data-mero-combo-status]:not([data-mero-error])) {
|
|
73
79
|
position: absolute;
|
|
74
80
|
inline-size: 1px;
|
|
@@ -212,6 +218,12 @@
|
|
|
212
218
|
:where(.mero-field-error, .mero-error-message) { color: var(--mero-danger); }
|
|
213
219
|
:where(.mero-fieldset) { min-inline-size: 0; margin: 0; padding: .85rem; border: 1px solid var(--mero-line); border-radius: var(--mero-radius); }
|
|
214
220
|
:where(.mero-fieldset legend) { padding-inline: .3rem; }
|
|
221
|
+
/* Form grid: two field columns that stack below 768 px or in a container narrower than two fields. mero-field-wide spans the row. */
|
|
222
|
+
:where(.mero-form-grid) { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, max(14rem, calc(50% - .5rem))), 1fr)); align-items: start; gap: .9rem 1rem; }
|
|
223
|
+
:where(.mero-form-grid > .mero-field-wide) { grid-column: 1 / -1; }
|
|
224
|
+
@media (width < 48rem) {
|
|
225
|
+
:where(.mero-form-grid) { grid-template-columns: minmax(0, 1fr); }
|
|
226
|
+
}
|
|
215
227
|
:where(.mero-date-range) { box-sizing: border-box; inline-size: min(100%, 22rem); }
|
|
216
228
|
:where(.mero-date-range-fields) {
|
|
217
229
|
display: grid;
|
|
@@ -344,7 +356,7 @@
|
|
|
344
356
|
:where(.mero-card, .mero-section, .mero-surface) {
|
|
345
357
|
--mero-panel-bg: var(--mero-surface);
|
|
346
358
|
box-sizing: border-box;
|
|
347
|
-
padding: 1.06rem;
|
|
359
|
+
padding: var(--mero-panel-padding, 1.06rem);
|
|
348
360
|
border: 1px solid var(--mero-line);
|
|
349
361
|
border-radius: var(--mero-radius-panel);
|
|
350
362
|
background: var(--mero-panel-bg);
|
|
@@ -354,7 +366,21 @@
|
|
|
354
366
|
:where(.mero-card-title) { margin: 0; font-size: 1.05rem; font-weight: 650; }
|
|
355
367
|
:where(.mero-card-description) { margin: .35rem 0 0; color: var(--mero-muted); }
|
|
356
368
|
:where(.mero-card-header, .mero-card-footer) { display: flex; align-items: center; gap: .65rem; }
|
|
357
|
-
:where(.mero-card-header) { margin-block-end: .7rem; }
|
|
369
|
+
:where(.mero-card-header) { flex-wrap: wrap; margin-block-end: .7rem; }
|
|
370
|
+
/* Header actions sit at the end of the header row and wrap under the title when it runs out of room. */
|
|
371
|
+
:where(.mero-card-actions) { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-inline-start: auto; }
|
|
372
|
+
/* A flush body reaches the card's edges, for a table that brings its own cell padding. */
|
|
373
|
+
:where(.mero-card-flush) { margin-inline: calc(-1 * var(--mero-panel-padding, 1.06rem)); }
|
|
374
|
+
:where(.mero-card-flush:last-child) {
|
|
375
|
+
margin-block-end: calc(-1 * var(--mero-panel-padding, 1.06rem));
|
|
376
|
+
border-end-start-radius: inherit; border-end-end-radius: inherit; overflow: clip;
|
|
377
|
+
}
|
|
378
|
+
@media (width < 48rem) {
|
|
379
|
+
:where(.mero-card-flush:has(> .mero-table-cards)) { margin: 0; overflow: visible; }
|
|
380
|
+
}
|
|
381
|
+
@media (width < 64rem) {
|
|
382
|
+
:where(.mero-card-flush:has(> .mero-table-cards-wide)) { margin: 0; overflow: visible; }
|
|
383
|
+
}
|
|
358
384
|
:where(.mero-card-footer) { margin-block-start: .8rem; }
|
|
359
385
|
:where(.mero-separator) { align-self: stretch; margin: .75rem 0; border: 0; border-block-start: 1px solid var(--mero-line); }
|
|
360
386
|
:where(.mero-stack > .mero-separator) { margin: 0; }
|
|
@@ -399,6 +425,20 @@
|
|
|
399
425
|
:where(.mero-alert-title) { font-weight: 650; }
|
|
400
426
|
:where(.mero-alert p) { margin: 0; }
|
|
401
427
|
|
|
428
|
+
/* Description list: one div per term and value. Below 768 px each label sits above its value. */
|
|
429
|
+
:where(.mero-description-list) { display: grid; margin: 0; color: var(--mero-text); font: 400 .875rem/1.5 var(--mero-font); }
|
|
430
|
+
:where(.mero-description-list > div) {
|
|
431
|
+
display: grid; grid-template-columns: minmax(7rem, 1fr) minmax(0, 2fr); align-items: baseline; gap: .15rem 1rem;
|
|
432
|
+
padding-block: .55rem; border-block-end: 1px solid var(--mero-line);
|
|
433
|
+
}
|
|
434
|
+
:where(.mero-description-list > div:last-child) { border-block-end: 0; }
|
|
435
|
+
:where(.mero-description-list dt) { color: var(--mero-muted); }
|
|
436
|
+
:where(.mero-description-list dd) { min-inline-size: 0; margin: 0; overflow-wrap: anywhere; }
|
|
437
|
+
:where(.mero-description-list dd code) { font: 500 .8rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
438
|
+
@media (width < 48rem) {
|
|
439
|
+
:where(.mero-description-list > div) { grid-template-columns: minmax(0, 1fr); }
|
|
440
|
+
}
|
|
441
|
+
|
|
402
442
|
:where(.mero-live) { inline-size: min(100%, 22rem); }
|
|
403
443
|
:where(.mero-live-status) { margin-block-start: .75rem; }
|
|
404
444
|
:where(.mero-live [data-mero-live-retry][hidden]) { display: none; }
|
|
@@ -451,6 +491,21 @@
|
|
|
451
491
|
background: linear-gradient(105deg, var(--mero-line) 30%, var(--mero-hover) 50%, var(--mero-line) 70%) 100% 0 / 250% 100%;
|
|
452
492
|
animation: mero-shimmer 2.2s ease-in-out infinite;
|
|
453
493
|
}
|
|
494
|
+
/* Empty state: an optional glyph, a heading or strong title, a description and an optional action. */
|
|
495
|
+
:where(.mero-empty-state) { padding: 1.1rem; text-align: center; color: var(--mero-text); }
|
|
496
|
+
:where(.mero-empty-state) :where(h2, h3, h4, strong, p) { display: block; margin: .3rem 0 0; }
|
|
497
|
+
:where(.mero-empty-state) :where(h2, h3, h4) { font-size: 1rem; font-weight: 650; line-height: 1.35; }
|
|
498
|
+
:where(.mero-empty-state p) { color: var(--mero-muted); font-size: .79rem; }
|
|
499
|
+
:where(.mero-empty-state > :is(.mero-button, .mero-row)) { margin-block-start: .85rem; }
|
|
500
|
+
:where(.mero-empty-state > .mero-row) { justify-content: center; }
|
|
501
|
+
:where(.mero-empty-glyph) { position: relative; display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: var(--mero-radius); background: var(--mero-raised); font: 1.6rem/1 system-ui; }
|
|
502
|
+
:where(.mero-empty-glyph)::before { content: ""; box-sizing: border-box; width: .85rem; height: .85rem; border: 1.5px solid currentColor; border-radius: 50%; transform: translate(-.09rem, -.09rem); }
|
|
503
|
+
:where(.mero-empty-glyph)::after { content: ""; position: absolute; width: .45rem; height: 1.5px; border-radius: 1px; background: currentColor; transform: translate(.35rem, .35rem) rotate(45deg); }
|
|
504
|
+
@media (forced-colors: active) {
|
|
505
|
+
:where(.mero-empty-glyph) { border: 1px solid CanvasText; }
|
|
506
|
+
:where(.mero-empty-glyph)::after { forced-color-adjust: none; background: CanvasText; }
|
|
507
|
+
}
|
|
508
|
+
|
|
454
509
|
@keyframes mero-spin { to { transform: rotate(360deg); } }
|
|
455
510
|
@keyframes mero-shimmer { 50%, 100% { background-position: 0 0; } }
|
|
456
511
|
|
|
@@ -462,7 +517,8 @@
|
|
|
462
517
|
text-align: start;
|
|
463
518
|
font: 400 .84rem/1.45 var(--mero-font);
|
|
464
519
|
}
|
|
465
|
-
:
|
|
520
|
+
/* position: relative keeps absolutely positioned content, such as visually hidden text in a cell, inside the scroller instead of widening the page. */
|
|
521
|
+
:where(.mero-table-wrap) { position: relative; max-inline-size: 100%; overflow-x: auto; }
|
|
466
522
|
:where(.mero-table caption) { padding-block-end: .6rem; color: var(--mero-muted); text-align: start; }
|
|
467
523
|
:where(.mero-table th, .mero-table td) { padding: .6rem .75rem; border-block-end: 1px solid var(--mero-line); text-align: start; white-space: nowrap; }
|
|
468
524
|
:where(.mero-table th) { background: var(--mero-raised); color: var(--mero-muted); font-size: .76rem; font-weight: 600; }
|
|
@@ -475,6 +531,10 @@
|
|
|
475
531
|
:where(.mero-table th a) { display: inline-flex; gap: .25rem; color: inherit; text-decoration: none; }
|
|
476
532
|
:where(.mero-table th a):hover { color: var(--mero-text); }
|
|
477
533
|
:where(.mero-table-compact) :where(th, td) { padding: .35rem .6rem; }
|
|
534
|
+
:where(.mero-table .mero-table-num) { text-align: end; font-variant-numeric: tabular-nums; }
|
|
535
|
+
:where(.mero-card-flush .mero-table :is(th, td):first-child, .mero-card-flush .mero-table caption) { padding-inline-start: var(--mero-panel-padding, 1.06rem); }
|
|
536
|
+
:where(.mero-card-flush .mero-table :is(th, td):last-child) { padding-inline-end: var(--mero-panel-padding, 1.06rem); }
|
|
537
|
+
:where(.mero-card-flush .mero-table th) { border-radius: 0; }
|
|
478
538
|
/* One real link per row; its ::after covers the row while other controls sit above it. */
|
|
479
539
|
:where(.mero-table tr:has(.mero-row-link)) { position: relative; cursor: pointer; }
|
|
480
540
|
:where(.mero-row-link) { color: inherit; text-decoration: none; }
|
|
@@ -518,6 +578,8 @@
|
|
|
518
578
|
:where(.mero-table td[colspan]) { display: block; }
|
|
519
579
|
:where(.mero-table [data-mero-cell-label]) { display: inline; color: var(--mero-muted); font-size: .76rem; }
|
|
520
580
|
:where(.mero-table .mero-row-link) { font-weight: 600; }
|
|
581
|
+
:where(.mero-table [data-mero-card-hidden]) { display: none; }
|
|
582
|
+
:where(.mero-table .mero-table-num) { text-align: start; }
|
|
521
583
|
}
|
|
522
584
|
|
|
523
585
|
/* Row peek. mero.js adds .mero-peek as the last child of [data-mero-peek] while a preview is open. */
|
|
@@ -584,6 +646,18 @@
|
|
|
584
646
|
:where(.mero-breadcrumbs li + li)::before { content: "/"; margin-inline-end: .52rem; color: var(--mero-muted); }
|
|
585
647
|
:where(.mero-pagination [aria-current="page"]) { background: var(--mero-accent); color: var(--mero-accent-ink); }
|
|
586
648
|
|
|
649
|
+
/* Page header: optional breadcrumbs, the heading block, then actions at the end. Below 768 px the actions wrap under the heading. */
|
|
650
|
+
:where(.mero-page-head) { display: flex; align-items: start; justify-content: space-between; flex-wrap: wrap; gap: .75rem; margin-block-end: 1.5rem; }
|
|
651
|
+
:where(.mero-page-head) :where(h1, h2) { margin: 0; font-size: clamp(1.55rem, 3vw, 2.15rem); line-height: 1.12; letter-spacing: -.05em; overflow-wrap: anywhere; }
|
|
652
|
+
:where(.mero-page-head) :where(p) { margin: .35rem 0 0; color: var(--mero-muted); font-size: .9rem; }
|
|
653
|
+
:where(.mero-page-head > .mero-breadcrumbs) { flex-basis: 100%; margin-block-end: -.25rem; font-size: .84rem; }
|
|
654
|
+
:where(.mero-page-head > :not(.mero-breadcrumbs, .mero-page-head-actions)) { flex: 1 1 16rem; min-inline-size: 0; }
|
|
655
|
+
:where(.mero-page-head-title) { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .65rem; }
|
|
656
|
+
:where(.mero-page-head-actions) { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
|
|
657
|
+
@media (width < 48rem) {
|
|
658
|
+
:where(.mero-page-head-actions) { flex-basis: 100%; }
|
|
659
|
+
}
|
|
660
|
+
|
|
587
661
|
:where(.mero-tabs-list, .mero-tabs > [role="tablist"]) {
|
|
588
662
|
display: inline-flex;
|
|
589
663
|
max-inline-size: 100%;
|
|
@@ -621,6 +695,18 @@
|
|
|
621
695
|
:where(.mero-tabs-vertical > [role="tablist"]) { flex-direction: column; align-items: stretch; }
|
|
622
696
|
:where(.mero-tabs-vertical .mero-tab) { text-align: start; }
|
|
623
697
|
:where(.mero-tabs-vertical > [role="tabpanel"]:not([hidden])) { margin-block-start: 0; padding-block-start: .55rem; }
|
|
698
|
+
/* Link tabs: nav.mero-tabs-list > a.mero-tab, with aria-current=page on the current view. */
|
|
699
|
+
:where(nav.mero-tabs-list) { flex-wrap: wrap; }
|
|
700
|
+
:where(a.mero-tab) { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; box-sizing: border-box; text-decoration: none; }
|
|
701
|
+
:where(.mero-tab)[aria-current="page"] { background: var(--mero-surface); color: var(--mero-text); box-shadow: inset 0 0 0 1px var(--mero-line), 0 1px 3px #14192324; }
|
|
702
|
+
:where(.mero-tab-count) {
|
|
703
|
+
min-inline-size: 1.25rem; box-sizing: border-box; padding: 0 .35rem; border-radius: 99rem;
|
|
704
|
+
background: var(--mero-hover); color: var(--mero-muted); font: 600 .7rem/1.45 var(--mero-font); font-variant-numeric: tabular-nums; text-align: center;
|
|
705
|
+
}
|
|
706
|
+
:where(.mero-tab[aria-current="page"] .mero-tab-count) { color: var(--mero-text); }
|
|
707
|
+
@media (forced-colors: active) {
|
|
708
|
+
:where(.mero-tab)[aria-current="page"], :where(.mero-tab)[aria-selected="true"] { outline: 2px solid Highlight; outline-offset: -2px; }
|
|
709
|
+
}
|
|
624
710
|
|
|
625
711
|
:where(.mero-setting-switch) {
|
|
626
712
|
display: flex;
|
|
@@ -707,6 +793,14 @@
|
|
|
707
793
|
border-end-start-radius: var(--mero-radius-panel);
|
|
708
794
|
}
|
|
709
795
|
:where(.mero-drawer:dir(rtl)) { --mero-offset-x: -100%; }
|
|
796
|
+
/* Start-edge drawer, such as app navigation on small screens. It opens from the left, or the right in RTL. */
|
|
797
|
+
:where(.mero-dialog.mero-drawer.mero-drawer-start) {
|
|
798
|
+
--mero-offset-x: -100%;
|
|
799
|
+
inset-inline-start: 0; inset-inline-end: auto;
|
|
800
|
+
border-start-start-radius: 0; border-end-start-radius: 0;
|
|
801
|
+
border-start-end-radius: var(--mero-radius-panel); border-end-end-radius: var(--mero-radius-panel);
|
|
802
|
+
}
|
|
803
|
+
:where(.mero-drawer-start:dir(rtl)) { --mero-offset-x: 100%; }
|
|
710
804
|
:where(.mero-drawer .mero-dialog-body) { padding: 1.5rem; }
|
|
711
805
|
:where(.mero-dialog.mero-sheet) {
|
|
712
806
|
--mero-offset-y: 100%;
|
|
@@ -815,6 +909,11 @@
|
|
|
815
909
|
:where([data-mero-listbox] > [role="option"]) { flex-wrap: nowrap; }
|
|
816
910
|
:where([data-mero-listbox] > [aria-selected="true"]) { background: color-mix(in srgb, var(--mero-accent) 9%, var(--mero-surface)); }
|
|
817
911
|
:where([data-mero-listbox] > [aria-selected="true"], .mero-menu-item[aria-checked="true"])::after { content: ""; flex: none; inline-size: .6rem; block-size: .32rem; margin-inline-start: auto; margin-inline-end: .16rem; border-left: 1.5px solid; border-bottom: 1.5px solid; transform: translateY(-.08rem) rotate(-45deg); }
|
|
912
|
+
/* A menu group named by its visible heading: role=group aria-labelledby the heading, which is aria-hidden so it is not read twice. */
|
|
913
|
+
:where(.mero-menu [role="group"]:first-child > .mero-menu-heading) { padding-block-start: .2rem; }
|
|
914
|
+
:where(.mero-menu > .mero-separator) { margin: .3rem .1rem; }
|
|
915
|
+
:where(.mero-menu-item-danger) { color: var(--mero-danger); }
|
|
916
|
+
:where(.mero-menu-item-danger:hover, .mero-menu-item-danger:focus) { background: color-mix(in srgb, var(--mero-danger) 12%, var(--mero-surface)); }
|
|
818
917
|
:where(.mero-combo) { position: relative; inline-size: 100%; }
|
|
819
918
|
:where(.mero-combo-list:not([hidden])) {
|
|
820
919
|
position: absolute;
|
|
@@ -826,7 +925,7 @@
|
|
|
826
925
|
/* Command results accept keyboard input immediately, including during entry. */
|
|
827
926
|
:where(.mero-command) { --mero-enter-opacity: 1; inline-size: min(36rem, calc(100% - 2rem)); margin-block-start: 12vh; padding: .5rem; }
|
|
828
927
|
:where(.mero-command .mero-combo-list:not([hidden])) { position: static; max-block-size: min(50vh, 24rem); margin-block-start: .35rem; box-shadow: none; }
|
|
829
|
-
:where(.mero-command-heading) { margin: 0; padding: .55rem .56rem .15rem; color: var(--mero-muted); font-size: .78rem; font-weight: 600; }
|
|
928
|
+
:where(.mero-command-heading, .mero-menu-heading) { margin: 0; padding: .55rem .56rem .15rem; color: var(--mero-muted); font-size: .78rem; font-weight: 600; }
|
|
830
929
|
:where(.mero-command [role="group"] + [role="group"]) { margin-block-start: .3rem; border-block-start: 1px solid var(--mero-line); }
|
|
831
930
|
:where(.mero-option small) { margin-inline-start: auto; color: var(--mero-muted); }
|
|
832
931
|
:where(.mero-scroll-shadow) {
|
package/ui/mero.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @rubenlangeweg/mero-ui 0.
|
|
1
|
+
/*! @rubenlangeweg/mero-ui 0.9.0 | MIT */
|
|
2
2
|
(() => {
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
}
|
|
116
116
|
if (!aliases.size) continue;
|
|
117
117
|
scopeAliases.set(scope, aliases);
|
|
118
|
-
const selectors = ["hx-target", "data-mero-return-focus", "data-mero-fallback-focus"];
|
|
118
|
+
const selectors = ["hx-target", "data-mero-return-focus", "data-mero-fallback-focus", "data-mero-ephemeral-dismiss", "data-mero-action-unknown", "data-mero-action-reread"];
|
|
119
119
|
const attributes = ["for", "aria-controls", "aria-labelledby", "aria-describedby", "aria-activedescendant", "popovertarget", "data-mero-open", ...selectors];
|
|
120
120
|
for (const node of scope.querySelectorAll(attributes.map(attr => "[" + attr + "]").join(","))) {
|
|
121
121
|
if (node.closest(selector) !== scope) continue;
|
|
@@ -164,9 +164,10 @@
|
|
|
164
164
|
return [...list.querySelectorAll(tabSelector)].filter(tab => tab.closest('[role="tablist"]') === list);
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
function selectTab(tab
|
|
167
|
+
function selectTab(tab) {
|
|
168
168
|
const list = tab.closest('[role="tablist"]');
|
|
169
|
-
if (!list || disabled(tab)) return;
|
|
169
|
+
if (!list || disabled(tab)) return false;
|
|
170
|
+
const changed = tab.getAttribute("aria-selected") !== "true";
|
|
170
171
|
for (const item of tabsFor(list)) {
|
|
171
172
|
const selected = item === tab;
|
|
172
173
|
item.tabIndex = selected ? 0 : -1;
|
|
@@ -174,7 +175,14 @@
|
|
|
174
175
|
const panel = element(item.getAttribute("aria-controls"));
|
|
175
176
|
if (panel) panel.hidden = !selected;
|
|
176
177
|
}
|
|
177
|
-
|
|
178
|
+
return changed;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// A person chose the tab. initTabs calls selectTab directly, so nothing fires at init.
|
|
182
|
+
function chooseTab(tab, focus) {
|
|
183
|
+
if (selectTab(tab)) tab.dispatchEvent(new CustomEvent("mero:tab", { bubbles: true, detail: { tab, panel: element(tab.getAttribute("aria-controls")) } }));
|
|
184
|
+
// Focus last, and only if a listener left this tab selected: a focus handler can select another tab.
|
|
185
|
+
if (focus && tab.getAttribute("aria-selected") === "true") tab.focus();
|
|
178
186
|
}
|
|
179
187
|
|
|
180
188
|
function initTabs(root) {
|
|
@@ -390,6 +398,24 @@
|
|
|
390
398
|
return item;
|
|
391
399
|
}
|
|
392
400
|
|
|
401
|
+
// Copy a literal value (data-mero-copy="…") or a target's value or text (data-mero-copy-target="#id").
|
|
402
|
+
// An empty data-mero-copy without a target belongs to the code block and chat copy in mero-insights.js.
|
|
403
|
+
async function copy(button) {
|
|
404
|
+
const target = button.hasAttribute("data-mero-copy-target") ? document.querySelector(button.getAttribute("data-mero-copy-target")) : null;
|
|
405
|
+
const text = target ? ("value" in target && target.matches("input, textarea, select, output") ? target.value : target.innerText)
|
|
406
|
+
: button.getAttribute("data-mero-copy");
|
|
407
|
+
if (!text) return;
|
|
408
|
+
try {
|
|
409
|
+
await navigator.clipboard.writeText(text);
|
|
410
|
+
toast(button.dataset.meroCopyMessage || "Copied", { tone: "success", duration: 2400, trigger: button });
|
|
411
|
+
} catch {
|
|
412
|
+
// Without clipboard access, select the text so the person can copy it themselves.
|
|
413
|
+
if (target?.select) target.select();
|
|
414
|
+
else if (target) getSelection().selectAllChildren(target);
|
|
415
|
+
toast(target ? "Press Ctrl+C or ⌘C to copy the selected text." : "Couldn't copy. Your browser blocked clipboard access.", { tone: target ? "accent" : "warning", trigger: button });
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
393
419
|
// Row peek: one preview at a time, keyed by the row's id (or the link's href) so it can follow the row through swaps.
|
|
394
420
|
let peek = null;
|
|
395
421
|
const peekRegion = node => node?.closest?.("[data-mero-peek]");
|
|
@@ -455,12 +481,54 @@
|
|
|
455
481
|
if (document.activeElement === document.body) region?.querySelector(".mero-row-link")?.focus({ preventScroll: true });
|
|
456
482
|
}
|
|
457
483
|
|
|
484
|
+
// time[data-mero-time]: show the datetime attribute in the reader's locale and time zone.
|
|
485
|
+
// relative: "3 minutes ago", refreshed every minute, with the full date in title. absolute, date, time: formatted.
|
|
486
|
+
const timeUnits = [["year", 31536e6], ["month", 2592e6], ["week", 6048e5], ["day", 864e5], ["hour", 36e5], ["minute", 6e4], ["second", 1e3]];
|
|
487
|
+
function localizeTimes(root = document) {
|
|
488
|
+
for (const node of matching(root, "time[data-mero-time]")) {
|
|
489
|
+
const date = new Date(node.getAttribute("datetime"));
|
|
490
|
+
if (Number.isNaN(date.getTime())) continue;
|
|
491
|
+
const style = node.dataset.meroTime;
|
|
492
|
+
const full = date.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });
|
|
493
|
+
let text = full;
|
|
494
|
+
if (style === "date") text = date.toLocaleDateString(undefined, { dateStyle: "medium" });
|
|
495
|
+
else if (style === "time") text = date.toLocaleTimeString(undefined, { timeStyle: "short" });
|
|
496
|
+
else if (style === "relative") {
|
|
497
|
+
const delta = date.getTime() - Date.now();
|
|
498
|
+
const [unit, size] = timeUnits.find(([, size]) => Math.abs(delta) >= size) ?? ["second", 1e3];
|
|
499
|
+
text = new Intl.RelativeTimeFormat(undefined, { numeric: "auto" }).format(Math.round(delta / size), unit);
|
|
500
|
+
if (node.title !== full) node.title = full;
|
|
501
|
+
}
|
|
502
|
+
if (node.textContent !== text) node.textContent = text;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
setInterval(() => document.querySelector('time[data-mero-time="relative"]') && localizeTimes(), 60000);
|
|
506
|
+
|
|
507
|
+
// Single-key shortcuts. WCAG 2.1.4: a [data-mero-shortcuts-toggle] control turns them off, remembered per browser.
|
|
508
|
+
const shortcutStore = "mero-shortcuts";
|
|
509
|
+
const shortcutsOn = () => { try { return localStorage.getItem(shortcutStore) !== "off"; } catch { return true; } };
|
|
510
|
+
function syncShortcuts(root = document) {
|
|
511
|
+
const on = shortcutsOn();
|
|
512
|
+
for (const node of matching(root, "[data-mero-shortcut]")) {
|
|
513
|
+
const keys = node.dataset.meroShortcut.trim();
|
|
514
|
+
// aria-keyshortcuts has no notation for sequences, so only single keys are announced.
|
|
515
|
+
if (on && !/\s/.test(keys)) node.setAttribute("aria-keyshortcuts", keys);
|
|
516
|
+
else if (node.getAttribute("aria-keyshortcuts") === keys) node.removeAttribute("aria-keyshortcuts");
|
|
517
|
+
}
|
|
518
|
+
for (const toggle of matching(root, "[data-mero-shortcuts-toggle]")) {
|
|
519
|
+
if (toggle.matches("input[type=checkbox]")) toggle.checked = on;
|
|
520
|
+
else toggle.setAttribute(toggle.matches('[role="menuitemcheckbox"], [role="switch"], [role="checkbox"]') ? "aria-checked" : "aria-pressed", String(on));
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
458
524
|
function init(root = document, trigger, request) {
|
|
459
525
|
scopeIds(root);
|
|
460
526
|
initNativeGroups(root);
|
|
461
527
|
initTabs(root);
|
|
462
528
|
initListboxes(root);
|
|
463
529
|
reconcileCombos(root, request);
|
|
530
|
+
localizeTimes(root);
|
|
531
|
+
syncShortcuts(root);
|
|
464
532
|
for (const dialog of matching(root, "dialog[data-mero-autoopen]")) {
|
|
465
533
|
if (autoOpened.has(dialog)) continue;
|
|
466
534
|
autoOpened.add(dialog);
|
|
@@ -523,6 +591,8 @@
|
|
|
523
591
|
const toggle = target.closest("[data-mero-toggle]");
|
|
524
592
|
const notifier = target.closest("[data-mero-toast]");
|
|
525
593
|
const removable = target.closest("[data-mero-remove]");
|
|
594
|
+
const copier = target.closest("[data-mero-copy-target], [data-mero-copy]:not([data-mero-copy=''])");
|
|
595
|
+
const shortcutToggle = target.closest("[data-mero-shortcuts-toggle]");
|
|
526
596
|
if (trigger && !disabled(trigger)) {
|
|
527
597
|
open(trigger.dataset.meroOpen, { trigger });
|
|
528
598
|
}
|
|
@@ -535,13 +605,25 @@
|
|
|
535
605
|
pointerStarts.delete(target);
|
|
536
606
|
if (beganOutside && outsideDialog(event, target)) close(target);
|
|
537
607
|
}
|
|
538
|
-
if (tab?.closest("[data-mero-tabs]"))
|
|
608
|
+
if (tab?.closest("[data-mero-tabs]")) chooseTab(tab);
|
|
539
609
|
const combo = option?.closest("[data-mero-combo]");
|
|
540
610
|
const list = !combo && option?.closest("[data-mero-listbox]");
|
|
541
611
|
if (combo) selectCombo(combo.querySelector('[role="combobox"]'), option);
|
|
542
612
|
if (list && !disabled(option)) chooseOption(list, option);
|
|
543
|
-
if (toggle && !disabled(toggle))
|
|
613
|
+
if (toggle && !disabled(toggle)) {
|
|
614
|
+
const pressed = toggle.getAttribute("aria-pressed") !== "true";
|
|
615
|
+
toggle.setAttribute("aria-pressed", String(pressed));
|
|
616
|
+
toggle.dispatchEvent(new CustomEvent("mero:toggle", { bubbles: true, detail: { pressed } }));
|
|
617
|
+
}
|
|
544
618
|
if (notifier && !disabled(notifier)) toast(notifier.dataset.meroToast, { tone: notifier.dataset.meroTone, trigger: notifier });
|
|
619
|
+
if (copier && !disabled(copier)) copy(copier);
|
|
620
|
+
if (shortcutToggle && !disabled(shortcutToggle)) {
|
|
621
|
+
// A checkbox has already changed; other controls flip the stored state.
|
|
622
|
+
const on = shortcutToggle.matches("input[type=checkbox]") ? shortcutToggle.checked : !shortcutsOn();
|
|
623
|
+
try { localStorage.setItem(shortcutStore, on ? "on" : "off"); } catch {}
|
|
624
|
+
syncShortcuts();
|
|
625
|
+
toast(on ? "Keyboard shortcuts on" : "Keyboard shortcuts off", { trigger: shortcutToggle, duration: 2400 });
|
|
626
|
+
}
|
|
545
627
|
if (removable && !disabled(removable)) {
|
|
546
628
|
const chip = removable.closest(".mero-chip");
|
|
547
629
|
const next = chip?.nextElementSibling?.querySelector(focusable) ?? chip?.previousElementSibling?.querySelector(focusable);
|
|
@@ -550,6 +632,35 @@
|
|
|
550
632
|
}
|
|
551
633
|
});
|
|
552
634
|
|
|
635
|
+
let shortcutPrefix = null;
|
|
636
|
+
function runShortcut(event) {
|
|
637
|
+
const target = event.target;
|
|
638
|
+
if (event.defaultPrevented || event.key.length !== 1 || !shortcutsOn()) return false;
|
|
639
|
+
// Typing, menus, lists and grids own their letter keys.
|
|
640
|
+
if (target.isContentEditable || target.matches("input, textarea, select") ||
|
|
641
|
+
target.closest('[role="menu"], [role="listbox"], [role="tablist"], [role="grid"], [role="combobox"]')) return false;
|
|
642
|
+
const key = event.key.toLowerCase();
|
|
643
|
+
const sequence = shortcutPrefix && Date.now() - shortcutPrefix.at < 1500 ? shortcutPrefix.key + " " + key : null;
|
|
644
|
+
shortcutPrefix = null;
|
|
645
|
+
const modal = document.querySelector("dialog:modal");
|
|
646
|
+
const candidates = [...document.querySelectorAll("[data-mero-shortcut]")]
|
|
647
|
+
.filter(node => !node.closest("[inert]") && (!modal || modal.contains(node)) && node.getClientRects().length && !disabled(node));
|
|
648
|
+
const match = keys => candidates.find(node => node.dataset.meroShortcut.trim().toLowerCase().split(/\s+/).join(" ") === keys);
|
|
649
|
+
const found = (sequence && match(sequence)) || match(key);
|
|
650
|
+
if (!found) {
|
|
651
|
+
if (candidates.some(node => node.dataset.meroShortcut.trim().toLowerCase().startsWith(key + " "))) {
|
|
652
|
+
shortcutPrefix = { key, at: Date.now() };
|
|
653
|
+
event.preventDefault();
|
|
654
|
+
return true;
|
|
655
|
+
}
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
event.preventDefault();
|
|
659
|
+
if (found.matches("input, textarea, select")) found.focus();
|
|
660
|
+
else found.click();
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
|
|
553
664
|
document.addEventListener("keydown", event => {
|
|
554
665
|
const target = event.target;
|
|
555
666
|
if ((event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey && event.key.toLowerCase() === "k" &&
|
|
@@ -565,6 +676,7 @@
|
|
|
565
676
|
}
|
|
566
677
|
}
|
|
567
678
|
if (!(target instanceof Element) || event.altKey || event.ctrlKey || event.metaKey || event.isComposing) return;
|
|
679
|
+
if (runShortcut(event)) return;
|
|
568
680
|
if (event.key === "Escape") {
|
|
569
681
|
const tooltip = target.closest(".mero-tooltip") ?? document.querySelector(".mero-tooltip:hover");
|
|
570
682
|
if (tooltip && !tooltip.hasAttribute("data-mero-tooltip-dismissed")) {
|
|
@@ -584,7 +696,7 @@
|
|
|
584
696
|
const candidate = step(tab, tabsFor(list).filter(item => !disabled(item)), event.key, previous, next);
|
|
585
697
|
if (candidate) {
|
|
586
698
|
event.preventDefault();
|
|
587
|
-
|
|
699
|
+
chooseTab(candidate, true);
|
|
588
700
|
}
|
|
589
701
|
return;
|
|
590
702
|
}
|
|
@@ -834,6 +946,106 @@
|
|
|
834
946
|
}
|
|
835
947
|
});
|
|
836
948
|
|
|
949
|
+
// data-mero-boost="#main" on a boosted container: the newest boosted GET wins, a response without the
|
|
950
|
+
// region (and without an htmx redirect header) or a failed GET becomes a full page load, open
|
|
951
|
+
// non-static dialogs such as a navigation drawer close, and focus moves to the new region.
|
|
952
|
+
const boostRequests = new Set();
|
|
953
|
+
const supersededBoosts = new WeakSet();
|
|
954
|
+
const boostFocus = new WeakMap();
|
|
955
|
+
const unswappedBoosts = new WeakSet();
|
|
956
|
+
const boostRegion = ctx => ctx.request?.headers?.["HX-Boosted"] && ctx.sourceElement?.closest?.("[data-mero-boost]")?.getAttribute("data-mero-boost");
|
|
957
|
+
const isGet = ctx => ctx.request.method.toUpperCase() === "GET";
|
|
958
|
+
|
|
959
|
+
document.addEventListener("htmx:before:request", event => {
|
|
960
|
+
const { ctx } = event.detail;
|
|
961
|
+
if (event.defaultPrevented || !boostRegion(ctx)) return;
|
|
962
|
+
boostFocus.set(ctx, document.activeElement);
|
|
963
|
+
if (!isGet(ctx)) return;
|
|
964
|
+
// Only navigations are aborted, never a boosted form that changes data.
|
|
965
|
+
for (const older of boostRequests) {
|
|
966
|
+
supersededBoosts.add(older);
|
|
967
|
+
older.request.abort();
|
|
968
|
+
}
|
|
969
|
+
boostRequests.clear();
|
|
970
|
+
boostRequests.add(ctx);
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
document.addEventListener("htmx:before:swap", event => {
|
|
974
|
+
const { ctx } = event.detail;
|
|
975
|
+
const selector = boostRegion(ctx);
|
|
976
|
+
if (!selector || event.defaultPrevented) return;
|
|
977
|
+
if (supersededBoosts.has(ctx)) {
|
|
978
|
+
unswappedBoosts.add(ctx);
|
|
979
|
+
return event.preventDefault();
|
|
980
|
+
}
|
|
981
|
+
const page = document.createElement("template");
|
|
982
|
+
page.innerHTML = ctx.text ?? "";
|
|
983
|
+
let found;
|
|
984
|
+
try { found = page.content.querySelector(selector); } catch {}
|
|
985
|
+
if (!found) {
|
|
986
|
+
// A login page, an error page from a proxy or any other document: let the browser show it.
|
|
987
|
+
event.preventDefault();
|
|
988
|
+
unswappedBoosts.add(ctx);
|
|
989
|
+
location.assign(ctx.response?.raw?.url || ctx.request.action);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
const open = [...document.querySelectorAll("dialog[open]:not([data-mero-static], [role='alertdialog'])")];
|
|
993
|
+
// Closing a dialog moves focus to its opener; that move is Mero's, not the person's.
|
|
994
|
+
if (open.some(dialog => dialog.contains(boostFocus.get(ctx)))) boostFocus.set(ctx, null);
|
|
995
|
+
for (const dialog of open) close(dialog);
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
document.addEventListener("htmx:finally:request", event => {
|
|
999
|
+
const { ctx } = event.detail;
|
|
1000
|
+
if (!boostRequests.delete(ctx) || supersededBoosts.has(ctx)) return;
|
|
1001
|
+
// No response and not cancelled before sending: the network failed or timed out.
|
|
1002
|
+
if (!ctx.response && String(ctx.status).startsWith("error") && isGet(ctx)) location.assign(ctx.request.action);
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
// After htmx's [autofocus]. Focus that the person moved during the load stays where they put it.
|
|
1006
|
+
document.addEventListener("htmx:finally:swap", event => {
|
|
1007
|
+
const { ctx } = event.detail;
|
|
1008
|
+
const selector = boostRegion(ctx);
|
|
1009
|
+
const before = boostFocus.get(ctx);
|
|
1010
|
+
boostFocus.delete(ctx);
|
|
1011
|
+
if (!selector || unswappedBoosts.has(ctx)) return;
|
|
1012
|
+
const region = document.querySelector(selector);
|
|
1013
|
+
const active = document.activeElement;
|
|
1014
|
+
// null: focus was in a dialog Mero closed, so wherever the browser put it is not the person's choice.
|
|
1015
|
+
if (!region || region.contains(active) || (before !== null && active && active !== document.body && active !== before && active.isConnected)) return;
|
|
1016
|
+
if (!region.hasAttribute("tabindex")) region.tabIndex = -1;
|
|
1017
|
+
region.focus({ preventScroll: true });
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
// Focus continuity: when a swap or morph removes the focused element, focus would fall to <body>.
|
|
1021
|
+
// Mero puts it back on the same element, else the element with its ID, else the swapped region's
|
|
1022
|
+
// [data-mero-focus-fallback]. It only acts when focus was inside a swap target as the swap began and
|
|
1023
|
+
// is on <body> once every task has settled, so it never moves focus the person put somewhere else.
|
|
1024
|
+
const lostFocus = new WeakMap();
|
|
1025
|
+
const focusLost = () => !document.activeElement || document.activeElement === document.body;
|
|
1026
|
+
document.addEventListener("htmx:before:swap", event => {
|
|
1027
|
+
const { ctx, tasks } = event.detail;
|
|
1028
|
+
const active = document.activeElement;
|
|
1029
|
+
if (focusLost() || event.defaultPrevented) return;
|
|
1030
|
+
const targets = tasks.map(task => typeof task.target === "string" ? document.querySelector(task.target) : task.target)
|
|
1031
|
+
.filter(target => target?.contains(active) && !target.closest("[data-mero-focus-manual]"));
|
|
1032
|
+
if (targets.length) lostFocus.set(ctx, { element: active, id: active.id, targets });
|
|
1033
|
+
});
|
|
1034
|
+
// finally:swap follows every task's settle and htmx's own [autofocus], so both keep precedence.
|
|
1035
|
+
document.addEventListener("htmx:finally:swap", event => {
|
|
1036
|
+
const saved = lostFocus.get(event.detail.ctx);
|
|
1037
|
+
lostFocus.delete(event.detail.ctx);
|
|
1038
|
+
if (!saved || !focusLost()) return;
|
|
1039
|
+
const regions = saved.targets.map(target => target.isConnected ? target : target.id && document.getElementById(target.id)).filter(Boolean);
|
|
1040
|
+
const candidates = [saved.element, saved.id && document.getElementById(saved.id),
|
|
1041
|
+
...regions.map(region => region.querySelector("[data-mero-focus-fallback]"))];
|
|
1042
|
+
for (const candidate of candidates) {
|
|
1043
|
+
if (!candidate?.isConnected || !candidate.getClientRects().length) continue;
|
|
1044
|
+
candidate.focus({ preventScroll: true });
|
|
1045
|
+
if (document.activeElement === candidate) return;
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
|
|
837
1049
|
const focusStore = () => "mero-focus:" + location.pathname + location.search;
|
|
838
1050
|
// The key is per URL, not per history entry, so every visit consumes it and only a traversal applies it.
|
|
839
1051
|
function restoreFocus(apply = true) {
|