@jungherz-de/notionkit-elements 1.6.0 → 1.7.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/README.md +13 -13
- package/dist/components/nk-btn.js +29 -3
- package/dist/components/nk-cmdk.js +1 -1
- package/dist/components/nk-database.js +14 -5
- package/dist/components/nk-filter-bar.js +57 -36
- package/dist/components/nk-menu-item.js +10 -6
- package/dist/components/nk-menu.js +86 -1
- package/dist/components/nk-modal.js +1 -1
- package/dist/components/nk-segmented.js +19 -0
- package/dist/components/nk-sheet.js +97 -0
- package/dist/components/nk-sidebar.js +15 -36
- package/dist/components/nk-steps.js +61 -0
- package/dist/components/shared/{focus-DXrK9oLe.js → focus-BNAChOXO.js} +12 -4
- package/dist/notionkit-elements.esm.js +394 -95
- package/dist/notionkit-elements.js +395 -94
- package/dist/notionkit-elements.min.js +1 -1
- package/package.json +6 -6
- package/src/components/data/nk-database.js +14 -5
- package/src/components/data/nk-filter-bar.js +57 -36
- package/src/components/forms/nk-btn.js +29 -3
- package/src/components/overlays/nk-menu-item.js +10 -6
- package/src/components/overlays/nk-menu.js +86 -1
- package/src/components/overlays/nk-sheet.js +95 -0
- package/src/components/page/nk-segmented.js +19 -0
- package/src/components/page/nk-steps.js +59 -0
- package/src/components/shell/nk-sidebar.js +15 -36
- package/src/index.js +4 -0
- package/src/util/focus.js +11 -3
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { NkElement } from './base.js';
|
|
2
|
+
import { d as deepActiveElement, l as lockScroll, i as inertOutside, f as firstFocusable, u as unlockScroll } from './shared/focus-BNAChOXO.js';
|
|
3
|
+
import '@jungherz-de/notionkit/notionkit-styles.js';
|
|
4
|
+
|
|
5
|
+
// <nk-sheet id="more" title="More">
|
|
6
|
+
// <nk-tree manual>
|
|
7
|
+
// <nk-section-label>Favourites</nk-section-label>
|
|
8
|
+
// <nk-tree-item icon="🚀">NotionKit MVP</nk-tree-item>
|
|
9
|
+
// </nk-tree>
|
|
10
|
+
// </nk-sheet>
|
|
11
|
+
// → <div class="nk-sheet-backdrop open"><div class="nk-sheet" role="dialog">
|
|
12
|
+
// <div class="sh-grabber"></div><div class="sh-title">More</div>…</div></div>
|
|
13
|
+
//
|
|
14
|
+
// A bottom sheet (NotionKit 1.7.0) with nk-modal's contract: show(), close()
|
|
15
|
+
// and toggle(), Escape and the backdrop close it, focus moves in and back
|
|
16
|
+
// out, the page behind is scroll-locked and inert. It lies above the tab
|
|
17
|
+
// bar; rows inside are 40px high. `title` is the heading shown under the
|
|
18
|
+
// grabber and the dialog's name, never a tooltip – see NkElement.takeTitle().
|
|
19
|
+
// Choosing a row does not close the sheet – the app decides (nk-select
|
|
20
|
+
// bubbles out). Put the element directly under <body>: a transformed
|
|
21
|
+
// ancestor would trap the fixed backdrop.
|
|
22
|
+
class NkSheet extends NkElement {
|
|
23
|
+
static get observedAttributes() { return ['open', 'title']; }
|
|
24
|
+
|
|
25
|
+
render() {
|
|
26
|
+
this.takeTitle();
|
|
27
|
+
this._backdrop = this.createElement('div', ['nk-sheet-backdrop']);
|
|
28
|
+
this._backdrop.inert = true;
|
|
29
|
+
this._box = this.createElement('div', ['nk-sheet'], { role: 'dialog', 'aria-modal': 'true', tabindex: '-1' });
|
|
30
|
+
this._heading = this.createElement('div', ['sh-title'], { id: 'title' });
|
|
31
|
+
this._box.append(this.createElement('div', ['sh-grabber']), this._heading, document.createElement('slot'));
|
|
32
|
+
this._backdrop.appendChild(this._box);
|
|
33
|
+
this._wrapper.appendChild(this._backdrop);
|
|
34
|
+
this._syncTitle();
|
|
35
|
+
this._syncOpen();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
_syncTitle() {
|
|
39
|
+
const text = this._titleText || '';
|
|
40
|
+
this._heading.textContent = text;
|
|
41
|
+
this._heading.hidden = !text;
|
|
42
|
+
if (text) this._box.setAttribute('aria-labelledby', 'title');
|
|
43
|
+
else this._box.removeAttribute('aria-labelledby');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_syncOpen() {
|
|
47
|
+
const open = this.getBoolAttr('open');
|
|
48
|
+
this._backdrop.classList.toggle('open', open);
|
|
49
|
+
this._backdrop.inert = !open;
|
|
50
|
+
if (open === this._wasOpen) return;
|
|
51
|
+
this._wasOpen = open;
|
|
52
|
+
if (open) {
|
|
53
|
+
this._returnFocus = deepActiveElement();
|
|
54
|
+
lockScroll();
|
|
55
|
+
this._undoInert = inertOutside(this);
|
|
56
|
+
requestAnimationFrame(() => (firstFocusable(this) || this._box).focus({ preventScroll: true }));
|
|
57
|
+
} else {
|
|
58
|
+
unlockScroll();
|
|
59
|
+
this._undoInert?.(); this._undoInert = null;
|
|
60
|
+
const back = this._returnFocus;
|
|
61
|
+
if (back && typeof back.focus === 'function' && back.isConnected) back.focus({ preventScroll: true });
|
|
62
|
+
this._returnFocus = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
setupEvents() {
|
|
67
|
+
this._onBackdrop = (e) => { if (e.target === this._backdrop) this.close(); };
|
|
68
|
+
this._onKey = (e) => { if (e.key === 'Escape' && this.getBoolAttr('open')) { e.stopPropagation(); this.close(); } };
|
|
69
|
+
this._backdrop.addEventListener('click', this._onBackdrop);
|
|
70
|
+
document.addEventListener('keydown', this._onKey);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
teardownEvents() {
|
|
74
|
+
this._backdrop?.removeEventListener('click', this._onBackdrop);
|
|
75
|
+
document.removeEventListener('keydown', this._onKey);
|
|
76
|
+
if (this._wasOpen) { unlockScroll(); this._undoInert?.(); this._undoInert = null; this._wasOpen = false; }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
onAttributeChanged(name, oldValue, value) {
|
|
80
|
+
if (name === 'title') { if (this.takeTitle(value)) this._syncTitle(); return; }
|
|
81
|
+
this._syncOpen();
|
|
82
|
+
this.emit('nk-toggle', { open: this.getBoolAttr('open') });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
show() { this.setBoolAttr('open', true); }
|
|
86
|
+
close() { this.setBoolAttr('open', false); }
|
|
87
|
+
toggle() { this.setBoolAttr('open', !this.getBoolAttr('open')); }
|
|
88
|
+
|
|
89
|
+
get open() { return this.getBoolAttr('open'); }
|
|
90
|
+
set open(v) { this.setBoolAttr('open', v); }
|
|
91
|
+
get title() { return this._titleText ?? ''; }
|
|
92
|
+
set title(v) { this._titleText = v == null ? '' : String(v); if (this._initialized) this._syncTitle(); }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
customElements.define('nk-sheet', NkSheet);
|
|
96
|
+
|
|
97
|
+
export { NkSheet };
|
|
@@ -11,42 +11,12 @@ import '@jungherz-de/notionkit/notionkit-styles.js';
|
|
|
11
11
|
//
|
|
12
12
|
// The host is display:contents so the <aside> is a direct flex child of
|
|
13
13
|
// .nk-app, exactly like the class markup. Below 860px notionkit.css hides the
|
|
14
|
-
// aside; `open` brings it back as
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
// value is held for the whole duration, so closing animates too) and
|
|
20
|
-
// @starting-style gives the first frame after display: none its start
|
|
21
|
-
// values. `position: fixed` lives on the plain .nk-sidebar, not on the open
|
|
22
|
-
// state – while closing, the aside is still displayed and must not fall
|
|
23
|
-
// back into the flow. Browsers without either feature switch hard, as
|
|
24
|
-
// before; prefers-reduced-motion switches hard on purpose.
|
|
25
|
-
const drawerSheet = new CSSStyleSheet();
|
|
26
|
-
drawerSheet.replaceSync(`
|
|
27
|
-
.nk-sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 59; background: var(--nk-scrim-soft); }
|
|
28
|
-
@media (max-width: 860px) {
|
|
29
|
-
.nk-sidebar {
|
|
30
|
-
position: fixed; inset: 0 auto 0 0; z-index: 60;
|
|
31
|
-
transform: translateX(-100%);
|
|
32
|
-
transition: background .25s ease, transform .24s cubic-bezier(.2, .8, .25, 1), display .24s;
|
|
33
|
-
transition-behavior: allow-discrete;
|
|
34
|
-
}
|
|
35
|
-
:host([open]) .nk-sidebar { display: flex; transform: none; }
|
|
36
|
-
@starting-style { :host([open]) .nk-sidebar { transform: translateX(-100%); } }
|
|
37
|
-
.nk-sidebar-backdrop {
|
|
38
|
-
opacity: 0;
|
|
39
|
-
transition: opacity .24s ease, display .24s;
|
|
40
|
-
transition-behavior: allow-discrete;
|
|
41
|
-
}
|
|
42
|
-
:host([open]) .nk-sidebar-backdrop { display: block; opacity: 1; }
|
|
43
|
-
@starting-style { :host([open]) .nk-sidebar-backdrop { opacity: 0; } }
|
|
44
|
-
}
|
|
45
|
-
@media (prefers-reduced-motion: reduce) { .nk-sidebar, .nk-sidebar-backdrop { transition: none; } }
|
|
46
|
-
`);
|
|
47
|
-
|
|
14
|
+
// aside; `open` brings it back as a drawer over the page. The drawer is the
|
|
15
|
+
// stylesheet's since NotionKit 1.7.0 (.nk-sidebar.open, .nk-sidebar-backdrop
|
|
16
|
+
// .open) – the sidebar slides and the scrim fades by the same rules as the
|
|
17
|
+
// class markup; the element toggles the two classes. <nk-btn variant="sidebar">
|
|
18
|
+
// in the topbar is the ☰ that opens it.
|
|
48
19
|
class NkSidebar extends NkElement {
|
|
49
|
-
static get hostStyles() { return drawerSheet; }
|
|
50
20
|
static get observedAttributes() { return ['open']; }
|
|
51
21
|
|
|
52
22
|
render() {
|
|
@@ -63,6 +33,13 @@ class NkSidebar extends NkElement {
|
|
|
63
33
|
this._wrapper.appendChild(this._backdrop);
|
|
64
34
|
this._wrapper.appendChild(this._aside);
|
|
65
35
|
this._syncFooter();
|
|
36
|
+
this._syncOpen();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_syncOpen() {
|
|
40
|
+
const open = this.getBoolAttr('open');
|
|
41
|
+
this._aside.classList.toggle('open', open);
|
|
42
|
+
this._backdrop.classList.toggle('open', open);
|
|
66
43
|
}
|
|
67
44
|
|
|
68
45
|
_syncFooter() {
|
|
@@ -89,7 +66,9 @@ class NkSidebar extends NkElement {
|
|
|
89
66
|
}
|
|
90
67
|
|
|
91
68
|
onAttributeChanged(name) {
|
|
92
|
-
if (name
|
|
69
|
+
if (name !== 'open') return;
|
|
70
|
+
this._syncOpen();
|
|
71
|
+
this.emit('nk-toggle', { open: this.getBoolAttr('open') });
|
|
93
72
|
}
|
|
94
73
|
|
|
95
74
|
show() { this.setBoolAttr('open', true); }
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { NkElement } from './base.js';
|
|
2
|
+
import '@jungherz-de/notionkit/notionkit-styles.js';
|
|
3
|
+
|
|
4
|
+
// <nk-steps label="Connect your own model" current="2"
|
|
5
|
+
// steps="Choose a provider, Enter the API key, Test the connection"></nk-steps>
|
|
6
|
+
// steps.steps = [{ label: 'Choose a provider', desc: 'Anthropic' }, 'Enter the API key', …];
|
|
7
|
+
// → <ol class="nk-steps" aria-label="…">
|
|
8
|
+
// <li class="nk-step done"><span class="st-mark">✓</span><span>Choose a provider<span class="st-desc">Anthropic</span></span></li>
|
|
9
|
+
// <li class="nk-step current" aria-current="step"><span class="st-mark">2</span><span>Enter the API key</span></li>
|
|
10
|
+
// <li class="nk-step"><span class="st-mark">3</span><span>Test the connection</span></li></ol>
|
|
11
|
+
// A setup in a few steps (NotionKit 1.7.0). `current` counts from 1; the
|
|
12
|
+
// steps before it are done, one past the last marks all of them done. The
|
|
13
|
+
// `steps` attribute is a comma-separated list; the property also takes
|
|
14
|
+
// { label, desc } objects for a line under the label.
|
|
15
|
+
class NkSteps extends NkElement {
|
|
16
|
+
static get observedAttributes() { return ['steps', 'current', 'label']; }
|
|
17
|
+
|
|
18
|
+
render() {
|
|
19
|
+
this._list = this.createElement('ol', ['nk-steps']);
|
|
20
|
+
this._wrapper.appendChild(this._list);
|
|
21
|
+
this._sync();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
_items() {
|
|
25
|
+
if (this._steps) return this._steps;
|
|
26
|
+
return (this.getAttribute('steps') || '').split(',').map(s => s.trim()).filter(Boolean);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
_sync() {
|
|
30
|
+
const label = this.getAttribute('label');
|
|
31
|
+
if (label) this._list.setAttribute('aria-label', label); else this._list.removeAttribute('aria-label');
|
|
32
|
+
const current = this.current;
|
|
33
|
+
this._list.replaceChildren(...this._items().map((step, i) => {
|
|
34
|
+
const n = i + 1, { label: text, desc } = typeof step === 'object' && step ? step : { label: String(step) };
|
|
35
|
+
const li = this.createElement('li', ['nk-step']);
|
|
36
|
+
li.classList.toggle('done', n < current);
|
|
37
|
+
li.classList.toggle('current', n === current);
|
|
38
|
+
if (n === current) li.setAttribute('aria-current', 'step');
|
|
39
|
+
const mark = this.createElement('span', ['st-mark'], { 'aria-hidden': 'true' });
|
|
40
|
+
mark.textContent = n < current ? '✓' : String(n);
|
|
41
|
+
const body = document.createElement('span');
|
|
42
|
+
body.textContent = text ?? '';
|
|
43
|
+
if (desc) { const d = this.createElement('span', ['st-desc']); d.textContent = desc; body.appendChild(d); }
|
|
44
|
+
li.append(mark, body);
|
|
45
|
+
return li;
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
onAttributeChanged() { this._sync(); }
|
|
50
|
+
|
|
51
|
+
get steps() { return this._items(); }
|
|
52
|
+
set steps(v) { this._steps = Array.isArray(v) ? v : null; if (this._list) this._sync(); }
|
|
53
|
+
get current() { const n = parseInt(this.getAttribute('current'), 10); return Number.isFinite(n) ? n : 1; }
|
|
54
|
+
set current(v) { this.setAttribute('current', String(v)); }
|
|
55
|
+
/** Moves on to the next step; returns the new current step. */
|
|
56
|
+
next() { this.current = Math.min(this.current + 1, this._items().length + 1); return this.current; }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
customElements.define('nk-steps', NkSteps);
|
|
60
|
+
|
|
61
|
+
export { NkSteps };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// Overlay plumbing shared by nk-modal and nk-
|
|
2
|
-
// refcount,
|
|
3
|
-
// assistive technology stay inside – nested shadow roots included
|
|
1
|
+
// Overlay plumbing shared by nk-modal, nk-sheet, nk-cmdk and nk-menu: body
|
|
2
|
+
// scroll lock with a refcount, `inert` on everything outside the overlay so
|
|
3
|
+
// focus and assistive technology stay inside – nested shadow roots included –
|
|
4
|
+
// and the focused element behind shadow hosts, to return focus to.
|
|
4
5
|
let locks = 0, previousOverflow = '';
|
|
5
6
|
|
|
6
7
|
function lockScroll() {
|
|
@@ -31,6 +32,13 @@ function inertOutside(el) {
|
|
|
31
32
|
return () => { for (const c of made) c.inert = false; };
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
/** The focused element itself, looking into shadow roots (document.activeElement stops at the host). */
|
|
36
|
+
function deepActiveElement() {
|
|
37
|
+
let el = document.activeElement;
|
|
38
|
+
while (el?.shadowRoot?.activeElement) el = el.shadowRoot.activeElement;
|
|
39
|
+
return el;
|
|
40
|
+
}
|
|
41
|
+
|
|
34
42
|
/** The first tabbable element inside a light-DOM subtree, looking into shadow roots. */
|
|
35
43
|
function firstFocusable(root) {
|
|
36
44
|
const SEL = 'a[href], button:not([disabled]), input:not([disabled]):not([type=hidden]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"], [contenteditable="plaintext-only"]';
|
|
@@ -44,4 +52,4 @@ function firstFocusable(root) {
|
|
|
44
52
|
return walk(root);
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
export { firstFocusable as f, inertOutside as i, lockScroll as l, unlockScroll as u };
|
|
55
|
+
export { deepActiveElement as d, firstFocusable as f, inertOutside as i, lockScroll as l, unlockScroll as u };
|