staffa 0.23.1 → 0.23.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/field.js +3 -0
- package/dist/components/textarea.js +34 -16
- package/dist/components/tooltip.js +20 -26
- package/dist/staffa.esm.js +1 -1
- package/package.json +7 -4
- package/src/components/field.ts +3 -0
- package/src/components/textarea.ts +34 -14
- package/src/components/tooltip.ts +18 -20
- package/dist/components/layers.d.ts +0 -330
- package/dist/components/layers.js +0 -888
- package/dist/components/pages.d.ts +0 -638
- package/dist/components/pages.js +0 -1510
- package/dist/glyphs.d.ts +0 -24
- package/dist/glyphs.js +0 -25
package/dist/components/field.js
CHANGED
|
@@ -33,6 +33,9 @@ A.insertGlobalCss({
|
|
|
33
33
|
// On a textarea the insets ride the bottom edge, so a growing box keeps its
|
|
34
34
|
// send button where the caret is rather than floating it mid-paragraph.
|
|
35
35
|
"&.s-inset-bottom > .s-inset_start, &.s-inset-bottom > .s-inset_end": "top:auto padding-bottom:0.35em",
|
|
36
|
+
// A column rather than a grid, so the textarea flexes within the box as it
|
|
37
|
+
// would directly in the field.
|
|
38
|
+
"&.s-inset-bottom:has(> .s-inset_start), &.s-inset-bottom:has(> .s-inset_end)": "display:flex flex-direction:column",
|
|
36
39
|
"> .s-inset_start > svg, > .s-inset_end > svg": "width:1.15em height:1.15em",
|
|
37
40
|
// A number input's spinner wants the very corner a trailing inset is in, and
|
|
38
41
|
// it is the inset that was asked for. (Firefox's is `appearance`-controlled.)
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import A from "aberdeen";
|
|
2
2
|
import { applyControlAttrs, drawField, drawInsets } from "./field.js";
|
|
3
3
|
A.insertGlobalCss({
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// how tall to be (`attrs: "h:8rem"`) hands
|
|
7
|
-
// field left to size itself
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
"textarea.s-input, .s-inset.s-inset-bottom": "flex: 0 1 100%; min-height:0",
|
|
4
|
+
// Start from the height the textarea asks for (its rows, or its text when
|
|
5
|
+
// growing), then grow or shrink to whatever room the field has left: a field
|
|
6
|
+
// told how tall to be (`attrs: "h:8rem"`) hands its height to the textarea,
|
|
7
|
+
// while a field left to size itself has no room to share out, so the textarea
|
|
8
|
+
// keeps its own height. The same rule rides the inset box below, which stands
|
|
9
|
+
// in for the control once a prefix/suffix gives it one.
|
|
10
|
+
"textarea.s-input, .s-inset.s-inset-bottom": "flex: 1 1 auto; min-height:0",
|
|
12
11
|
"textarea.s-input": "resize:vertical min-height:3em line-height:1.45",
|
|
13
12
|
// Sized to its text there is nothing to scroll; `fitToContent` turns scrolling
|
|
14
13
|
// on once a caller caps the height (`inputAttrs: "max-height:12em"`).
|
|
@@ -71,22 +70,41 @@ export function textarea(opts = {}) {
|
|
|
71
70
|
A("change=", opts.change);
|
|
72
71
|
applyControlAttrs(opts, id, isInvalid, opts.bind);
|
|
73
72
|
});
|
|
74
|
-
if (grow)
|
|
75
|
-
|
|
73
|
+
if (grow) {
|
|
74
|
+
// Typing aside, refit when the text is set from code (a value loaded
|
|
75
|
+
// after drawing, a box cleared after sending), and when the box is
|
|
76
|
+
// shown or changes width, which rewraps the text.
|
|
77
|
+
A(() => {
|
|
78
|
+
opts.bind?.value;
|
|
79
|
+
requestAnimationFrame(() => fitToContent(el));
|
|
80
|
+
});
|
|
81
|
+
new ResizeObserver(() => fitToContent(el)).observe(el);
|
|
82
|
+
}
|
|
76
83
|
});
|
|
77
84
|
});
|
|
78
85
|
}
|
|
79
86
|
function fitToContent(el) {
|
|
80
|
-
|
|
81
|
-
//
|
|
82
|
-
|
|
87
|
+
// Measure a copy taken out of the flow: collapsing the textarea itself would
|
|
88
|
+
// scroll its caret into view of the collapsed box and shrink the page under
|
|
89
|
+
// it, so a capped textarea, or the page, would jump on every keystroke.
|
|
90
|
+
const probe = el.cloneNode();
|
|
91
|
+
probe.value = el.value;
|
|
92
|
+
Object.assign(probe.style, {
|
|
93
|
+
position: "absolute",
|
|
94
|
+
visibility: "hidden",
|
|
95
|
+
width: `${el.offsetWidth}px`,
|
|
96
|
+
height: "auto",
|
|
97
|
+
// Measure without a scrollbar: one would narrow the text and wrap it early.
|
|
98
|
+
overflowY: "",
|
|
99
|
+
});
|
|
100
|
+
el.after(probe);
|
|
83
101
|
// `scrollHeight` measures the padding box, while the height we set sizes the
|
|
84
102
|
// border box: add the borders back, or the text ends up two pixels too tall
|
|
85
103
|
// for its box and the textarea scrolls by that much.
|
|
86
|
-
const height =
|
|
104
|
+
const height = probe.scrollHeight + probe.offsetHeight - probe.clientHeight;
|
|
105
|
+
probe.remove();
|
|
87
106
|
el.style.height = `${height}px`;
|
|
88
107
|
// Scroll only once a `max-height` caps the box: `scrollHeight` is rounded, so
|
|
89
108
|
// an uncapped box can fall a fraction of a pixel short and show a bar.
|
|
90
|
-
|
|
91
|
-
el.style.overflowY = "auto";
|
|
109
|
+
el.style.overflowY = el.offsetHeight < height ? "auto" : "";
|
|
92
110
|
}
|
|
@@ -13,7 +13,6 @@ A.insertGlobalCss({
|
|
|
13
13
|
// ─── Global portal state ────────────────────────────────────────────────────
|
|
14
14
|
// At most one tooltip at a time; the anchor is the element whose rect positions it.
|
|
15
15
|
const $ttActive = A.proxy(undefined);
|
|
16
|
-
let hideTimer = null;
|
|
17
16
|
function computePos(rect, tipW, tipH, placement) {
|
|
18
17
|
const gap = 7;
|
|
19
18
|
const vw = window.innerWidth;
|
|
@@ -53,14 +52,6 @@ function computePos(rect, tipW, tipH, placement) {
|
|
|
53
52
|
y: Math.max(8, Math.min(y, vh - tipH - 8)),
|
|
54
53
|
};
|
|
55
54
|
}
|
|
56
|
-
function scheduleHide() {
|
|
57
|
-
if (hideTimer)
|
|
58
|
-
clearTimeout(hideTimer);
|
|
59
|
-
hideTimer = setTimeout(() => {
|
|
60
|
-
$ttActive.value = undefined;
|
|
61
|
-
hideTimer = null;
|
|
62
|
-
}, 100);
|
|
63
|
-
}
|
|
64
55
|
// ─── Portal ──────────────────────────────────────────────────────────────────
|
|
65
56
|
mountPortal(() => {
|
|
66
57
|
const active = $ttActive.value;
|
|
@@ -68,16 +59,7 @@ mountPortal(() => {
|
|
|
68
59
|
return;
|
|
69
60
|
const { opts, anchor } = active;
|
|
70
61
|
const placement = opts.placement ?? "top";
|
|
71
|
-
const tipEl = A("div.s-tt-tip.s-s.neutral.shadow role=tooltip", opts.attrs, () =>
|
|
72
|
-
A("mouseenter=", () => {
|
|
73
|
-
if (hideTimer) {
|
|
74
|
-
clearTimeout(hideTimer);
|
|
75
|
-
hideTimer = null;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
A("mouseleave=", scheduleHide);
|
|
79
|
-
drawSlot(opts.tip);
|
|
80
|
-
});
|
|
62
|
+
const tipEl = A("div.s-tt-tip.s-s.neutral.shadow role=tooltip", opts.attrs, () => drawSlot(opts.tip));
|
|
81
63
|
followAnchor(anchor, (rect) => {
|
|
82
64
|
// Out of the viewport, or on a panel that slid off and went inert: nothing
|
|
83
65
|
// left to explain, and no `mouseleave` is coming to say so.
|
|
@@ -113,22 +95,34 @@ mountPortal(() => {
|
|
|
113
95
|
* ```
|
|
114
96
|
*/
|
|
115
97
|
export function addTooltip(opts) {
|
|
98
|
+
// Pressing the anchor dismisses its tip until the pointer leaves, as a native
|
|
99
|
+
// `title` does: whatever the press opens shouldn't sit under the tip.
|
|
100
|
+
let pressed = false;
|
|
116
101
|
const show = (e) => {
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
102
|
+
if (!pressed)
|
|
103
|
+
$ttActive.value = { opts, anchor: e.currentTarget };
|
|
104
|
+
};
|
|
105
|
+
// Only this anchor's own tip: another one may have taken over since.
|
|
106
|
+
const hide = (e) => {
|
|
107
|
+
if (A.unproxy($ttActive).value?.anchor === e.currentTarget)
|
|
108
|
+
$ttActive.value = undefined;
|
|
122
109
|
};
|
|
123
110
|
A("mouseenter=", show);
|
|
124
|
-
A("mouseleave=",
|
|
111
|
+
A("mouseleave=", (e) => {
|
|
112
|
+
pressed = false;
|
|
113
|
+
hide(e);
|
|
114
|
+
});
|
|
115
|
+
A("pointerdown=", (e) => {
|
|
116
|
+
pressed = true;
|
|
117
|
+
hide(e);
|
|
118
|
+
});
|
|
125
119
|
// Keyboard focus only: programmatic focus (a nav opening on its current row,
|
|
126
120
|
// say) would pop a tip over the very thing it describes.
|
|
127
121
|
A("focusin=", (e) => {
|
|
128
122
|
if (e.target.matches?.(":focus-visible"))
|
|
129
123
|
show(e);
|
|
130
124
|
});
|
|
131
|
-
A("focusout=",
|
|
125
|
+
A("focusout=", hide);
|
|
132
126
|
A.clean(() => {
|
|
133
127
|
// Compare raw: the proxy's getter wraps stored objects, so `$ttActive.value.opts`
|
|
134
128
|
// would be a Proxy that never equals our raw `opts`.
|