@jungherz-de/notionkit-elements 1.20.0 → 1.20.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 +29 -0
- package/README.md +3 -3
- package/SKILL.md +13 -13
- package/dist/components/nk-tooltip.js +61 -5
- package/dist/notionkit-elements.esm.js +61 -5
- package/dist/notionkit-elements.esm.min.js +1 -1
- package/dist/notionkit-elements.esm.min.js.map +1 -1
- package/dist/notionkit-elements.js +61 -5
- package/dist/notionkit-elements.min.js +1 -1
- package/package.json +1 -1
- package/src/components/overlays/nk-tooltip.js +61 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jungherz-de/notionkit-elements",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.1",
|
|
4
4
|
"description": "Vanilla JavaScript Web Components wrapping the NotionKit CSS foundation – <nk-*> custom elements with Shadow DOM, automatic theme sync and native form participation.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jungherz GmbH <info@jungherz.com> (https://www.jungherz.com)",
|
|
@@ -23,6 +23,17 @@ import { deepActiveElement } from '../../util/focus.js';
|
|
|
23
23
|
// [data-tooltip], a press or Escape. A line break in the text is kept.
|
|
24
24
|
// While it shows, the target's aria-describedby names it (in the same
|
|
25
25
|
// document or shadow root).
|
|
26
|
+
//
|
|
27
|
+
// Following the pointer and the focus inside a shadow root (1.20.1):
|
|
28
|
+
// pointerover, focusin and focusout carry a relatedTarget, and when target
|
|
29
|
+
// and relatedTarget share a shadow tree the DOM standard ends the event path
|
|
30
|
+
// at its host – the document never hears of a move from one [data-tooltip]
|
|
31
|
+
// to the next in the same root. So the pointer is also read from
|
|
32
|
+
// pointermove, which has no relatedTarget, and acted on only when the
|
|
33
|
+
// element under it changes; and a key that moved the focus – Tab, the arrow
|
|
34
|
+
// keys of a group – is caught on keyup, comparing the focused element with
|
|
35
|
+
// the one before the key went down. A move by script alone inside one
|
|
36
|
+
// shadow root stays unseen.
|
|
26
37
|
const hostSheet = new CSSStyleSheet();
|
|
27
38
|
hostSheet.replaceSync(`:host { display: block; position: fixed; top: 0; left: 0; z-index: 130; pointer-events: none; }`);
|
|
28
39
|
let count = 0;
|
|
@@ -100,14 +111,50 @@ class NkTooltip extends NkElement {
|
|
|
100
111
|
this.show(el, own ? null : el.getAttribute('data-tooltip'), own ? this.getAttribute('shortcut') : el.getAttribute('data-tooltip-key'));
|
|
101
112
|
}
|
|
102
113
|
|
|
114
|
+
/**
|
|
115
|
+
* The pointer is over `el` now (null: no [data-tooltip]). pointerover acts
|
|
116
|
+
* on every boundary it crosses, as it always has; pointermove – the only
|
|
117
|
+
* one that reaches the document from inside a shadow root – only when the
|
|
118
|
+
* element under the pointer changed, so a hand resting on the page leaves
|
|
119
|
+
* a tooltip the keyboard or show(rect) opened alone.
|
|
120
|
+
*/
|
|
121
|
+
_pointer(e, move) {
|
|
122
|
+
const el = e.pointerType === 'touch' ? null : this._targetOf(e);
|
|
123
|
+
if (move && el === this._hover) return;
|
|
124
|
+
this._hover = el;
|
|
125
|
+
if (el === this._target) return;
|
|
126
|
+
this.hide();
|
|
127
|
+
if (!el) return;
|
|
128
|
+
this._target = el;
|
|
129
|
+
this._timer = setTimeout(() => this._showFor(el), this._delay);
|
|
130
|
+
}
|
|
131
|
+
|
|
103
132
|
setupEvents() {
|
|
104
|
-
this._onOver = (e) =>
|
|
105
|
-
|
|
106
|
-
|
|
133
|
+
this._onOver = (e) => this._pointer(e, false);
|
|
134
|
+
this._onMove = (e) => this._pointer(e, true);
|
|
135
|
+
// The pointer left the window (no relatedTarget): a tooltip – shown or
|
|
136
|
+
// still waiting – for what it was on goes with it. One the keyboard or
|
|
137
|
+
// show(rect) opened is not the pointer's and stays.
|
|
138
|
+
this._onOut = (e) => {
|
|
139
|
+
if (e.relatedTarget || e.pointerType === 'touch') return;
|
|
140
|
+
if (this._target && this._target === this._hover) this.hide();
|
|
141
|
+
this._hover = null;
|
|
142
|
+
};
|
|
143
|
+
// Capture, before an element's own keydown moves the focus (a roving tab
|
|
144
|
+
// stop does); not for a held key's repeats, so keyup compares with where
|
|
145
|
+
// the focus was before the key went down.
|
|
146
|
+
this._onKeyDown = (e) => { if (!e.repeat) this._focusBefore = deepActiveElement(); };
|
|
147
|
+
this._onKeyUp = (e) => {
|
|
148
|
+
const active = deepActiveElement();
|
|
149
|
+
if (active === this._focusBefore) return;
|
|
150
|
+
this._focusBefore = active;
|
|
151
|
+
// keyup goes to the focused element, so its path is the focus's path.
|
|
152
|
+
const el = this._targetOf(e);
|
|
153
|
+
if (el && el === this._target) return; // focusin got there first
|
|
107
154
|
this.hide();
|
|
108
|
-
if (!el) return;
|
|
155
|
+
if (!el || !active?.matches(':focus-visible')) return;
|
|
109
156
|
this._target = el;
|
|
110
|
-
this.
|
|
157
|
+
this._showFor(el);
|
|
111
158
|
};
|
|
112
159
|
this._onFocus = (e) => {
|
|
113
160
|
const el = this._targetOf(e);
|
|
@@ -119,7 +166,11 @@ class NkTooltip extends NkElement {
|
|
|
119
166
|
this._onHide = () => this.hide();
|
|
120
167
|
this._onKey = (e) => { if (e.key === 'Escape' && this.open) this.hide(); };
|
|
121
168
|
document.addEventListener('pointerover', this._onOver);
|
|
169
|
+
document.addEventListener('pointermove', this._onMove, { capture: true, passive: true });
|
|
170
|
+
document.addEventListener('pointerout', this._onOut);
|
|
122
171
|
document.addEventListener('focusin', this._onFocus);
|
|
172
|
+
document.addEventListener('keydown', this._onKeyDown, true);
|
|
173
|
+
document.addEventListener('keyup', this._onKeyUp, true);
|
|
123
174
|
document.addEventListener('focusout', this._onHide);
|
|
124
175
|
document.addEventListener('pointerdown', this._onHide, true);
|
|
125
176
|
document.addEventListener('scroll', this._onHide, true);
|
|
@@ -130,13 +181,18 @@ class NkTooltip extends NkElement {
|
|
|
130
181
|
|
|
131
182
|
teardownEvents() {
|
|
132
183
|
document.removeEventListener('pointerover', this._onOver);
|
|
184
|
+
document.removeEventListener('pointermove', this._onMove, { capture: true });
|
|
185
|
+
document.removeEventListener('pointerout', this._onOut);
|
|
133
186
|
document.removeEventListener('focusin', this._onFocus);
|
|
187
|
+
document.removeEventListener('keydown', this._onKeyDown, true);
|
|
188
|
+
document.removeEventListener('keyup', this._onKeyUp, true);
|
|
134
189
|
document.removeEventListener('focusout', this._onHide);
|
|
135
190
|
document.removeEventListener('pointerdown', this._onHide, true);
|
|
136
191
|
document.removeEventListener('scroll', this._onHide, true);
|
|
137
192
|
document.removeEventListener('wheel', this._onHide, { capture: true });
|
|
138
193
|
document.removeEventListener('keydown', this._onKey);
|
|
139
194
|
this.hide();
|
|
195
|
+
this._hover = this._focusBefore = null;
|
|
140
196
|
}
|
|
141
197
|
|
|
142
198
|
onAttributeChanged(name) { if (name === 'shortcut' && !this._text.data) this._fill(null); if (name === 'for') this.hide(); }
|