@jungherz-de/notionkit-elements 1.6.0 → 1.8.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.
Files changed (36) hide show
  1. package/README.md +15 -15
  2. package/dist/components/nk-bookmark.js +69 -0
  3. package/dist/components/nk-btn.js +29 -3
  4. package/dist/components/nk-cmdk.js +1 -1
  5. package/dist/components/nk-copy-field.js +88 -0
  6. package/dist/components/nk-database.js +14 -5
  7. package/dist/components/nk-filter-bar.js +57 -36
  8. package/dist/components/nk-image-picker.js +130 -0
  9. package/dist/components/nk-menu-item.js +10 -6
  10. package/dist/components/nk-menu.js +86 -1
  11. package/dist/components/nk-modal.js +1 -1
  12. package/dist/components/nk-peek.js +122 -0
  13. package/dist/components/nk-segmented.js +19 -0
  14. package/dist/components/nk-sheet.js +97 -0
  15. package/dist/components/nk-sidebar.js +15 -36
  16. package/dist/components/nk-steps.js +61 -0
  17. package/dist/components/shared/{focus-DXrK9oLe.js → focus-BNAChOXO.js} +12 -4
  18. package/dist/notionkit-elements.esm.js +786 -95
  19. package/dist/notionkit-elements.js +791 -94
  20. package/dist/notionkit-elements.min.js +1 -1
  21. package/package.json +6 -6
  22. package/src/components/content/nk-bookmark.js +67 -0
  23. package/src/components/data/nk-database.js +14 -5
  24. package/src/components/data/nk-filter-bar.js +57 -36
  25. package/src/components/forms/nk-btn.js +29 -3
  26. package/src/components/forms/nk-copy-field.js +86 -0
  27. package/src/components/forms/nk-image-picker.js +128 -0
  28. package/src/components/overlays/nk-menu-item.js +10 -6
  29. package/src/components/overlays/nk-menu.js +86 -1
  30. package/src/components/overlays/nk-peek.js +120 -0
  31. package/src/components/overlays/nk-sheet.js +95 -0
  32. package/src/components/page/nk-segmented.js +19 -0
  33. package/src/components/page/nk-steps.js +59 -0
  34. package/src/components/shell/nk-sidebar.js +15 -36
  35. package/src/index.js +10 -0
  36. package/src/util/focus.js +11 -3
@@ -4,10 +4,12 @@ import { NkElement } from '../../base.js';
4
4
  // <nk-menu-item type="separator"></nk-menu-item> <nk-menu-item type="label">Danger</nk-menu-item>
5
5
  // <nk-menu-item icon="🗑️" danger value="delete">Delete</nk-menu-item>
6
6
  // <nk-menu-item type="switch" icon="🔡" value="small" checked>Small text</nk-menu-item>
7
+ // <nk-menu-item type="check" icon="◉" value="open" checked>Status: Open</nk-menu-item>
7
8
  // → <div class="nk-menu-item danger"><span class="m-icon">🗑️</span>Delete<span class="m-shortcut">…</span></div>
8
9
  // A switch item carries a .nk-switch on the right, as "Small text" does in
9
- // Notion's page menu: a click flips `checked` and fires nk-change { value,
10
- // checked } instead of nk-select, so the menu around it stays open.
10
+ // Notion's page menu; a check item a ✓ where the shortcut stands, as in a
11
+ // filter menu. A click on either flips `checked` and fires nk-change
12
+ // { value, checked } instead of nk-select, so the menu around it stays open.
11
13
  class NkMenuItem extends NkElement {
12
14
  static get observedAttributes() { return ['icon', 'shortcut', 'danger', 'value', 'type', 'disabled', 'checked']; }
13
15
 
@@ -23,7 +25,8 @@ class NkMenuItem extends NkElement {
23
25
  el.appendChild(document.createElement('slot'));
24
26
  } else {
25
27
  const isSwitch = type === 'switch';
26
- el = this.createElement('div', ['nk-menu-item'], { role: isSwitch ? 'menuitemcheckbox' : 'menuitem', tabindex: '-1' });
28
+ this._check = type === 'check';
29
+ el = this.createElement('div', ['nk-menu-item'], { role: isSwitch || this._check ? 'menuitemcheckbox' : 'menuitem', tabindex: '-1' });
27
30
  this._icon = this.createElement('span', ['m-icon']);
28
31
  const iconSlot = this.createElement('slot', [], { name: 'icon' });
29
32
  iconSlot.appendChild(this._icon);
@@ -48,10 +51,11 @@ class NkMenuItem extends NkElement {
48
51
  this._shortcut.style.display = sc ? '' : 'none';
49
52
  this._el.classList.toggle('danger', this.getBoolAttr('danger'));
50
53
  this._el.setAttribute('aria-disabled', this.getBoolAttr('disabled') ? 'true' : 'false');
51
- if (this._switch) {
54
+ if (this._switch || this._check) {
52
55
  const on = this.getBoolAttr('checked') ? 'true' : 'false';
53
56
  this._el.setAttribute('aria-checked', on);
54
- this._switch.setAttribute('aria-checked', on);
57
+ if (this._switch) this._switch.setAttribute('aria-checked', on);
58
+ if (this._check) { this._shortcut.textContent = on === 'true' ? '✓' : ''; this._shortcut.style.display = ''; }
55
59
  }
56
60
  }
57
61
 
@@ -64,7 +68,7 @@ class NkMenuItem extends NkElement {
64
68
 
65
69
  select() {
66
70
  if (!this._el.classList.contains('nk-menu-item') || this.getBoolAttr('disabled')) return;
67
- if (this._switch) {
71
+ if (this._switch || this._check) {
68
72
  this.checked = !this.checked;
69
73
  this.emit('nk-change', { value: this.value, checked: this.checked, item: this });
70
74
  return;
@@ -1,4 +1,5 @@
1
1
  import { NkElement } from '../../base.js';
2
+ import { deepActiveElement } from '../../util/focus.js';
2
3
 
3
4
  // <nk-menu>
4
5
  // <nk-menu-item type="label">Page</nk-menu-item>
@@ -8,13 +9,79 @@ import { NkElement } from '../../base.js';
8
9
  // </nk-menu>
9
10
  // → <div class="nk-pop nk-menu" role="menu">…</div>
10
11
  // ↑↓ move between items, Enter selects, nk-select bubbles from the item.
12
+ //
13
+ // <nk-menu floating sheet> is a menu over the page (NotionKit 1.7.0): it
14
+ // fades in like the palette when `open` is set and is a bottom sheet on a
15
+ // phone. The host becomes the fixed box you position – show(anchor) puts it
16
+ // under the anchor, right edges aligned (align="start": left edges). A tap
17
+ // outside closes it and reaches nothing else; Escape and a chosen item
18
+ // close it too, a switch row does not. Opened from the keyboard, focus moves
19
+ // to the first item; closing returns it to where it was.
20
+ const floatSheet = new CSSStyleSheet();
21
+ floatSheet.replaceSync(`:host([floating]) { display: block; position: fixed; z-index: 60; pointer-events: none; }`);
22
+
23
+ /** The border box of an element, or of the first descendant with one (display: contents hosts). */
24
+ function boxOf(el) {
25
+ if (el.getClientRects().length) return el.getBoundingClientRect();
26
+ for (const child of [...(el.shadowRoot?.children ?? []), ...el.children]) {
27
+ const r = boxOf(child);
28
+ if (r.width || r.height) return r;
29
+ }
30
+ return el.getBoundingClientRect();
31
+ }
32
+
11
33
  class NkMenu extends NkElement {
34
+ static get hostStyles() { return floatSheet; }
35
+ static get observedAttributes() { return ['floating', 'sheet', 'open', 'align']; }
36
+
12
37
  render() {
13
38
  this._box = this.createElement('div', ['nk-pop', 'nk-menu'], { role: 'menu' });
14
39
  this._box.appendChild(document.createElement('slot'));
15
40
  this._wrapper.appendChild(this._box);
41
+ this._syncMode();
42
+ }
43
+
44
+ _syncMode() {
45
+ this._box.classList.toggle('floating', this.getBoolAttr('floating'));
46
+ this._box.classList.toggle('sheet', this.getBoolAttr('sheet'));
47
+ this._box.classList.toggle('open', this.getBoolAttr('open'));
16
48
  }
17
49
 
50
+ onAttributeChanged(name) {
51
+ this._syncMode();
52
+ if (name !== 'open') return;
53
+ const open = this.getBoolAttr('open');
54
+ // aria-expanded belongs on the control itself, inside a host such as <nk-btn>.
55
+ if (this._anchor) (this._anchor.shadowRoot?.querySelector('button, a[href]') ?? this._anchor).setAttribute('aria-expanded', String(open));
56
+ if (open) {
57
+ this._returnFocus = deepActiveElement();
58
+ if (this._returnFocus?.matches(':focus-visible')) requestAnimationFrame(() => this.focusFirst());
59
+ document.addEventListener('click', this._onOutside, true);
60
+ } else {
61
+ document.removeEventListener('click', this._onOutside, true);
62
+ const back = this._returnFocus;
63
+ this._returnFocus = null;
64
+ if (back?.isConnected && this.contains(document.activeElement)) back.focus({ preventScroll: true });
65
+ }
66
+ this.emit('nk-toggle', { open });
67
+ }
68
+
69
+ /** Opens under `anchor` (any element, display: contents hosts included). */
70
+ show(anchor) {
71
+ if (anchor) {
72
+ this._anchor = anchor;
73
+ const r = boxOf(anchor);
74
+ this.style.top = `${r.bottom + 6}px`;
75
+ if (this.getAttribute('align') === 'start') { this.style.left = `${r.left}px`; this.style.right = ''; }
76
+ else { this.style.right = `${Math.max(8, innerWidth - r.right)}px`; this.style.left = ''; }
77
+ }
78
+ this.setBoolAttr('open', true);
79
+ }
80
+ close() { this.setBoolAttr('open', false); }
81
+ toggle(anchor) { this.getBoolAttr('open') ? this.close() : this.show(anchor); }
82
+ get open() { return this.getBoolAttr('open'); }
83
+ set open(v) { this.setBoolAttr('open', v); }
84
+
18
85
  get items() { return [...this.querySelectorAll(':scope > nk-menu-item')].filter(i => i.selectable); }
19
86
 
20
87
  setupEvents() {
@@ -32,9 +99,27 @@ class NkMenu extends NkElement {
32
99
  }
33
100
  };
34
101
  this.addEventListener('keydown', this._onKey);
102
+ // Floating: outside taps close and go nowhere else; Escape and a chosen item close.
103
+ this._onOutside = (e) => {
104
+ const path = e.composedPath();
105
+ if (path.includes(this) || (this._anchor && path.includes(this._anchor))) return;
106
+ e.preventDefault(); e.stopPropagation();
107
+ this.close();
108
+ };
109
+ // Captured, so a menu inside a modal or sheet closes before they do.
110
+ this._onEscape = (e) => { if (e.key === 'Escape' && this.getBoolAttr('floating') && this.getBoolAttr('open')) { e.stopPropagation(); this.close(); } };
111
+ this._onSelect = () => { if (this.getBoolAttr('floating')) this.close(); };
112
+ document.addEventListener('keydown', this._onEscape, true);
113
+ this.addEventListener('nk-select', this._onSelect);
114
+ if (this.getBoolAttr('open')) document.addEventListener('click', this._onOutside, true);
35
115
  }
36
116
 
37
- teardownEvents() { this.removeEventListener('keydown', this._onKey); }
117
+ teardownEvents() {
118
+ this.removeEventListener('keydown', this._onKey);
119
+ document.removeEventListener('keydown', this._onEscape, true);
120
+ this.removeEventListener('nk-select', this._onSelect);
121
+ document.removeEventListener('click', this._onOutside, true);
122
+ }
38
123
 
39
124
  /** Focuses the first item (called by a popover when it opens). */
40
125
  focusFirst() { this.items[0]?.focus(); }
@@ -0,0 +1,120 @@
1
+ import { NkElement } from '../../base.js';
2
+ import { lockScroll, unlockScroll, inertOutside, deepActiveElement } from '../../util/focus.js';
3
+
4
+ // <nk-peek id="peek" label="Database Table-View">
5
+ // <nk-btn slot="actions" variant="topbar" aria-label="Open as page"><svg …></svg></nk-btn>
6
+ // <nk-page-title>🗃️ Database Table-View</nk-page-title>
7
+ // <nk-props>…</nk-props>
8
+ // <div class="nk-prose">…</div>
9
+ // <nk-comments>…</nk-comments>
10
+ // </nk-peek>
11
+ // → <div class="nk-peek-backdrop open"><aside class="nk-peek" role="dialog">
12
+ // <div class="pk-bar"><button class="nk-topbar-btn">»</button>…actions…</div>
13
+ // <div class="pk-body">…</div></aside></div>
14
+ //
15
+ // Notion's side peek (NotionKit 1.8.0): a row beside the table, which stays
16
+ // usable – no scrim, nothing inert. show() slides it in and moves focus to
17
+ // it; », Escape and a click elsewhere on the page close it, and Escape and »
18
+ // hand focus back. A click that calls show() again – on another row – only
19
+ // swaps the content, and clicks inside other overlays (a menu opened from
20
+ // the peek) leave it open. Below 860px it is a bottom sheet over a dimmed
21
+ // page; there it is modal: the page is inert and scroll-locked, the dimmed
22
+ // page takes the tap that closes it. Put it directly under <body>.
23
+ const CLOSE_ICON = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="m6 17 5-5-5-5M13 17l5-5-5-5"/></svg>';
24
+ const OVERLAYS = new Set(['nk-menu', 'nk-pop', 'nk-modal', 'nk-sheet', 'nk-cmdk', 'nk-toast']);
25
+ const OVERLAY_CLASSES = ['nk-pop', 'nk-modal-backdrop', 'nk-sheet-backdrop', 'nk-cmdk-backdrop'];
26
+ const phone = () => matchMedia('(max-width: 860px)').matches;
27
+
28
+ class NkPeek extends NkElement {
29
+ static get observedAttributes() { return ['open', 'label', 'close-label']; }
30
+
31
+ render() {
32
+ this._backdrop = this.createElement('div', ['nk-peek-backdrop']);
33
+ this._box = this.createElement('aside', ['nk-peek'], { role: 'dialog', tabindex: '-1' });
34
+ const bar = this.createElement('div', ['pk-bar']);
35
+ this._close = this.createElement('button', ['nk-topbar-btn'], { type: 'button' });
36
+ this._close.innerHTML = CLOSE_ICON;
37
+ bar.append(this._close, this.createElement('slot', [], { name: 'actions' }));
38
+ const body = this.createElement('div', ['pk-body']);
39
+ body.appendChild(document.createElement('slot'));
40
+ this._box.append(bar, body);
41
+ this._backdrop.appendChild(this._box);
42
+ this._wrapper.appendChild(this._backdrop);
43
+ this._syncLabels();
44
+ this._syncOpen();
45
+ }
46
+
47
+ _syncLabels() {
48
+ const label = this.getAttribute('label');
49
+ if (label) this._box.setAttribute('aria-label', label); else this._box.removeAttribute('aria-label');
50
+ this._close.setAttribute('aria-label', this.getAttribute('close-label') || 'Close');
51
+ }
52
+
53
+ _syncOpen() {
54
+ const open = this.getBoolAttr('open');
55
+ this._backdrop.classList.toggle('open', open);
56
+ if (open === this._wasOpen) return;
57
+ this._wasOpen = open;
58
+ if (open) {
59
+ this._returnFocus = deepActiveElement();
60
+ if (phone()) {
61
+ this._modal = true;
62
+ this._box.setAttribute('aria-modal', 'true');
63
+ lockScroll();
64
+ this._undoInert = inertOutside(this);
65
+ }
66
+ requestAnimationFrame(() => this._box.focus({ preventScroll: true }));
67
+ } else {
68
+ if (this._modal) { this._modal = false; this._box.removeAttribute('aria-modal'); unlockScroll(); this._undoInert?.(); this._undoInert = null; }
69
+ const active = deepActiveElement();
70
+ const inside = active && (this.contains(active) || this._shadow.contains(active) || active === document.body);
71
+ const back = this._returnFocus;
72
+ this._returnFocus = null;
73
+ if (inside && back?.isConnected && typeof back.focus === 'function') back.focus({ preventScroll: true });
74
+ }
75
+ }
76
+
77
+ setupEvents() {
78
+ this._onClose = () => this.close();
79
+ this._onBackdrop = (e) => { if (e.target === this._backdrop) this.close(); };
80
+ this._onKey = (e) => { if (e.key === 'Escape' && this.getBoolAttr('open')) this.close(); };
81
+ // Bubble phase, after the page's own handlers: a click that showed the
82
+ // peek again (another row) must not close it.
83
+ this._onOutside = (e) => {
84
+ if (!this.getBoolAttr('open') || this._shownAt >= e.timeStamp) return;
85
+ const path = e.composedPath();
86
+ if (path.includes(this)) return;
87
+ if (path.some(n => n.nodeType === 1 && (OVERLAYS.has(n.localName) || OVERLAY_CLASSES.some(c => n.classList.contains(c))))) return;
88
+ this.close();
89
+ };
90
+ this._close.addEventListener('click', this._onClose);
91
+ this._backdrop.addEventListener('click', this._onBackdrop);
92
+ document.addEventListener('keydown', this._onKey);
93
+ document.addEventListener('click', this._onOutside);
94
+ }
95
+
96
+ teardownEvents() {
97
+ this._close?.removeEventListener('click', this._onClose);
98
+ this._backdrop?.removeEventListener('click', this._onBackdrop);
99
+ document.removeEventListener('keydown', this._onKey);
100
+ document.removeEventListener('click', this._onOutside);
101
+ if (this._modal) { this._modal = false; unlockScroll(); this._undoInert?.(); this._undoInert = null; }
102
+ this._wasOpen = false;
103
+ }
104
+
105
+ onAttributeChanged(name) {
106
+ if (name !== 'open') { this._syncLabels(); return; }
107
+ this._syncOpen();
108
+ this.emit('nk-toggle', { open: this.getBoolAttr('open') });
109
+ }
110
+
111
+ show() { this._shownAt = performance.now(); this.setBoolAttr('open', true); }
112
+ close() { this.setBoolAttr('open', false); }
113
+ toggle() { this.getBoolAttr('open') ? this.close() : this.show(); }
114
+
115
+ get open() { return this.getBoolAttr('open'); }
116
+ set open(v) { v ? this.show() : this.close(); }
117
+ }
118
+
119
+ customElements.define('nk-peek', NkPeek);
120
+ export { NkPeek };
@@ -0,0 +1,95 @@
1
+ import { NkElement } from '../../base.js';
2
+ import { lockScroll, unlockScroll, inertOutside, firstFocusable, deepActiveElement } from '../../util/focus.js';
3
+
4
+ // <nk-sheet id="more" title="More">
5
+ // <nk-tree manual>
6
+ // <nk-section-label>Favourites</nk-section-label>
7
+ // <nk-tree-item icon="🚀">NotionKit MVP</nk-tree-item>
8
+ // </nk-tree>
9
+ // </nk-sheet>
10
+ // → <div class="nk-sheet-backdrop open"><div class="nk-sheet" role="dialog">
11
+ // <div class="sh-grabber"></div><div class="sh-title">More</div>…</div></div>
12
+ //
13
+ // A bottom sheet (NotionKit 1.7.0) with nk-modal's contract: show(), close()
14
+ // and toggle(), Escape and the backdrop close it, focus moves in and back
15
+ // out, the page behind is scroll-locked and inert. It lies above the tab
16
+ // bar; rows inside are 40px high. `title` is the heading shown under the
17
+ // grabber and the dialog's name, never a tooltip – see NkElement.takeTitle().
18
+ // Choosing a row does not close the sheet – the app decides (nk-select
19
+ // bubbles out). Put the element directly under <body>: a transformed
20
+ // ancestor would trap the fixed backdrop.
21
+ class NkSheet extends NkElement {
22
+ static get observedAttributes() { return ['open', 'title']; }
23
+
24
+ render() {
25
+ this.takeTitle();
26
+ this._backdrop = this.createElement('div', ['nk-sheet-backdrop']);
27
+ this._backdrop.inert = true;
28
+ this._box = this.createElement('div', ['nk-sheet'], { role: 'dialog', 'aria-modal': 'true', tabindex: '-1' });
29
+ this._heading = this.createElement('div', ['sh-title'], { id: 'title' });
30
+ this._box.append(this.createElement('div', ['sh-grabber']), this._heading, document.createElement('slot'));
31
+ this._backdrop.appendChild(this._box);
32
+ this._wrapper.appendChild(this._backdrop);
33
+ this._syncTitle();
34
+ this._syncOpen();
35
+ }
36
+
37
+ _syncTitle() {
38
+ const text = this._titleText || '';
39
+ this._heading.textContent = text;
40
+ this._heading.hidden = !text;
41
+ if (text) this._box.setAttribute('aria-labelledby', 'title');
42
+ else this._box.removeAttribute('aria-labelledby');
43
+ }
44
+
45
+ _syncOpen() {
46
+ const open = this.getBoolAttr('open');
47
+ this._backdrop.classList.toggle('open', open);
48
+ this._backdrop.inert = !open;
49
+ if (open === this._wasOpen) return;
50
+ this._wasOpen = open;
51
+ if (open) {
52
+ this._returnFocus = deepActiveElement();
53
+ lockScroll();
54
+ this._undoInert = inertOutside(this);
55
+ requestAnimationFrame(() => (firstFocusable(this) || this._box).focus({ preventScroll: true }));
56
+ } else {
57
+ unlockScroll();
58
+ this._undoInert?.(); this._undoInert = null;
59
+ const back = this._returnFocus;
60
+ if (back && typeof back.focus === 'function' && back.isConnected) back.focus({ preventScroll: true });
61
+ this._returnFocus = null;
62
+ }
63
+ }
64
+
65
+ setupEvents() {
66
+ this._onBackdrop = (e) => { if (e.target === this._backdrop) this.close(); };
67
+ this._onKey = (e) => { if (e.key === 'Escape' && this.getBoolAttr('open')) { e.stopPropagation(); this.close(); } };
68
+ this._backdrop.addEventListener('click', this._onBackdrop);
69
+ document.addEventListener('keydown', this._onKey);
70
+ }
71
+
72
+ teardownEvents() {
73
+ this._backdrop?.removeEventListener('click', this._onBackdrop);
74
+ document.removeEventListener('keydown', this._onKey);
75
+ if (this._wasOpen) { unlockScroll(); this._undoInert?.(); this._undoInert = null; this._wasOpen = false; }
76
+ }
77
+
78
+ onAttributeChanged(name, oldValue, value) {
79
+ if (name === 'title') { if (this.takeTitle(value)) this._syncTitle(); return; }
80
+ this._syncOpen();
81
+ this.emit('nk-toggle', { open: this.getBoolAttr('open') });
82
+ }
83
+
84
+ show() { this.setBoolAttr('open', true); }
85
+ close() { this.setBoolAttr('open', false); }
86
+ toggle() { this.setBoolAttr('open', !this.getBoolAttr('open')); }
87
+
88
+ get open() { return this.getBoolAttr('open'); }
89
+ set open(v) { this.setBoolAttr('open', v); }
90
+ get title() { return this._titleText ?? ''; }
91
+ set title(v) { this._titleText = v == null ? '' : String(v); if (this._initialized) this._syncTitle(); }
92
+ }
93
+
94
+ customElements.define('nk-sheet', NkSheet);
95
+ export { NkSheet };
@@ -6,6 +6,9 @@ import { NkFormElement } from '../../base.js';
6
6
  // → <div class="nk-segmented">…</div> with .active on the chosen button.
7
7
  // The buttons stay in the light DOM (their look comes from the ::slotted
8
8
  // twins); the element sets type/role, moves .active and submits the value.
9
+ // With `scroll` the chosen option is kept in view – after the first layout,
10
+ // on every change and when the row's width changes – by scrolling the row
11
+ // alone, never the page, by a relative distance, so right-to-left works too.
9
12
  const KEYS = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 };
10
13
 
11
14
  class NkSegmented extends NkFormElement {
@@ -49,6 +52,19 @@ class NkSegmented extends NkFormElement {
49
52
  }
50
53
  this._value = value;
51
54
  this.setFormValue(value);
55
+ this._reveal(this._revealed ? 'smooth' : 'instant');
56
+ }
57
+
58
+ /** Scrolls the row the least distance that shows the chosen button whole. */
59
+ _reveal(behavior) {
60
+ if (!this.getBoolAttr('scroll') || !this._box?.clientWidth) return;
61
+ const btn = this.buttons.find(b => b.classList.contains('active'));
62
+ if (!btn) return;
63
+ const row = this._box.getBoundingClientRect(), r = btn.getBoundingClientRect(), pad = 8;
64
+ const delta = r.left < row.left ? r.left - row.left - pad : r.right > row.right ? r.right - row.right + pad : 0;
65
+ const smooth = behavior === 'smooth' && !matchMedia('(prefers-reduced-motion: reduce)').matches;
66
+ if (delta) this._box.scrollBy({ left: delta, behavior: smooth ? 'smooth' : 'instant' });
67
+ this._revealed = true;
52
68
  }
53
69
 
54
70
  setupEvents() {
@@ -72,6 +88,8 @@ class NkSegmented extends NkFormElement {
72
88
  this._slot.addEventListener('slotchange', this._onSlot);
73
89
  this.addEventListener('click', this._onClick);
74
90
  this.addEventListener('keydown', this._onKey);
91
+ this._resize = new ResizeObserver(() => this._reveal('instant'));
92
+ this._resize.observe(this._box);
75
93
  this._sync();
76
94
  }
77
95
 
@@ -79,6 +97,7 @@ class NkSegmented extends NkFormElement {
79
97
  this._slot?.removeEventListener('slotchange', this._onSlot);
80
98
  this.removeEventListener('click', this._onClick);
81
99
  this.removeEventListener('keydown', this._onKey);
100
+ this._resize?.disconnect();
82
101
  }
83
102
 
84
103
  _choose(value) {
@@ -0,0 +1,59 @@
1
+ import { NkElement } from '../../base.js';
2
+
3
+ // <nk-steps label="Connect your own model" current="2"
4
+ // steps="Choose a provider, Enter the API key, Test the connection"></nk-steps>
5
+ // steps.steps = [{ label: 'Choose a provider', desc: 'Anthropic' }, 'Enter the API key', …];
6
+ // → <ol class="nk-steps" aria-label="…">
7
+ // <li class="nk-step done"><span class="st-mark">✓</span><span>Choose a provider<span class="st-desc">Anthropic</span></span></li>
8
+ // <li class="nk-step current" aria-current="step"><span class="st-mark">2</span><span>Enter the API key</span></li>
9
+ // <li class="nk-step"><span class="st-mark">3</span><span>Test the connection</span></li></ol>
10
+ // A setup in a few steps (NotionKit 1.7.0). `current` counts from 1; the
11
+ // steps before it are done, one past the last marks all of them done. The
12
+ // `steps` attribute is a comma-separated list; the property also takes
13
+ // { label, desc } objects for a line under the label.
14
+ class NkSteps extends NkElement {
15
+ static get observedAttributes() { return ['steps', 'current', 'label']; }
16
+
17
+ render() {
18
+ this._list = this.createElement('ol', ['nk-steps']);
19
+ this._wrapper.appendChild(this._list);
20
+ this._sync();
21
+ }
22
+
23
+ _items() {
24
+ if (this._steps) return this._steps;
25
+ return (this.getAttribute('steps') || '').split(',').map(s => s.trim()).filter(Boolean);
26
+ }
27
+
28
+ _sync() {
29
+ const label = this.getAttribute('label');
30
+ if (label) this._list.setAttribute('aria-label', label); else this._list.removeAttribute('aria-label');
31
+ const current = this.current;
32
+ this._list.replaceChildren(...this._items().map((step, i) => {
33
+ const n = i + 1, { label: text, desc } = typeof step === 'object' && step ? step : { label: String(step) };
34
+ const li = this.createElement('li', ['nk-step']);
35
+ li.classList.toggle('done', n < current);
36
+ li.classList.toggle('current', n === current);
37
+ if (n === current) li.setAttribute('aria-current', 'step');
38
+ const mark = this.createElement('span', ['st-mark'], { 'aria-hidden': 'true' });
39
+ mark.textContent = n < current ? '✓' : String(n);
40
+ const body = document.createElement('span');
41
+ body.textContent = text ?? '';
42
+ if (desc) { const d = this.createElement('span', ['st-desc']); d.textContent = desc; body.appendChild(d); }
43
+ li.append(mark, body);
44
+ return li;
45
+ }));
46
+ }
47
+
48
+ onAttributeChanged() { this._sync(); }
49
+
50
+ get steps() { return this._items(); }
51
+ set steps(v) { this._steps = Array.isArray(v) ? v : null; if (this._list) this._sync(); }
52
+ get current() { const n = parseInt(this.getAttribute('current'), 10); return Number.isFinite(n) ? n : 1; }
53
+ set current(v) { this.setAttribute('current', String(v)); }
54
+ /** Moves on to the next step; returns the new current step. */
55
+ next() { this.current = Math.min(this.current + 1, this._items().length + 1); return this.current; }
56
+ }
57
+
58
+ customElements.define('nk-steps', NkSteps);
59
+ export { NkSteps };
@@ -10,42 +10,12 @@ import { NkElement } from '../../base.js';
10
10
  //
11
11
  // The host is display:contents so the <aside> is a direct flex child of
12
12
  // .nk-app, exactly like the class markup. Below 860px notionkit.css hides the
13
- // aside; `open` brings it back as an off-canvas drawer (position only – the
14
- // look is still the stylesheet's).
15
- //
16
- // The drawer slides and the scrim fades without a line of JavaScript:
17
- // `display` transitions with transition-behavior: allow-discrete (the old
18
- // value is held for the whole duration, so closing animates too) and
19
- // @starting-style gives the first frame after display: none its start
20
- // values. `position: fixed` lives on the plain .nk-sidebar, not on the open
21
- // state – while closing, the aside is still displayed and must not fall
22
- // back into the flow. Browsers without either feature switch hard, as
23
- // before; prefers-reduced-motion switches hard on purpose.
24
- const drawerSheet = new CSSStyleSheet();
25
- drawerSheet.replaceSync(`
26
- .nk-sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 59; background: var(--nk-scrim-soft); }
27
- @media (max-width: 860px) {
28
- .nk-sidebar {
29
- position: fixed; inset: 0 auto 0 0; z-index: 60;
30
- transform: translateX(-100%);
31
- transition: background .25s ease, transform .24s cubic-bezier(.2, .8, .25, 1), display .24s;
32
- transition-behavior: allow-discrete;
33
- }
34
- :host([open]) .nk-sidebar { display: flex; transform: none; }
35
- @starting-style { :host([open]) .nk-sidebar { transform: translateX(-100%); } }
36
- .nk-sidebar-backdrop {
37
- opacity: 0;
38
- transition: opacity .24s ease, display .24s;
39
- transition-behavior: allow-discrete;
40
- }
41
- :host([open]) .nk-sidebar-backdrop { display: block; opacity: 1; }
42
- @starting-style { :host([open]) .nk-sidebar-backdrop { opacity: 0; } }
43
- }
44
- @media (prefers-reduced-motion: reduce) { .nk-sidebar, .nk-sidebar-backdrop { transition: none; } }
45
- `);
46
-
13
+ // aside; `open` brings it back as a drawer over the page. The drawer is the
14
+ // stylesheet's since NotionKit 1.7.0 (.nk-sidebar.open, .nk-sidebar-backdrop
15
+ // .open) – the sidebar slides and the scrim fades by the same rules as the
16
+ // class markup; the element toggles the two classes. <nk-btn variant="sidebar">
17
+ // in the topbar is the ☰ that opens it.
47
18
  class NkSidebar extends NkElement {
48
- static get hostStyles() { return drawerSheet; }
49
19
  static get observedAttributes() { return ['open']; }
50
20
 
51
21
  render() {
@@ -62,6 +32,13 @@ class NkSidebar extends NkElement {
62
32
  this._wrapper.appendChild(this._backdrop);
63
33
  this._wrapper.appendChild(this._aside);
64
34
  this._syncFooter();
35
+ this._syncOpen();
36
+ }
37
+
38
+ _syncOpen() {
39
+ const open = this.getBoolAttr('open');
40
+ this._aside.classList.toggle('open', open);
41
+ this._backdrop.classList.toggle('open', open);
65
42
  }
66
43
 
67
44
  _syncFooter() {
@@ -88,7 +65,9 @@ class NkSidebar extends NkElement {
88
65
  }
89
66
 
90
67
  onAttributeChanged(name) {
91
- if (name === 'open') this.emit('nk-toggle', { open: this.getBoolAttr('open') });
68
+ if (name !== 'open') return;
69
+ this._syncOpen();
70
+ this.emit('nk-toggle', { open: this.getBoolAttr('open') });
92
71
  }
93
72
 
94
73
  show() { this.setBoolAttr('open', true); }
package/src/index.js CHANGED
@@ -80,6 +80,16 @@ export { NkProp } from './components/page/nk-prop.js';
80
80
  export { NkPanels } from './components/page/nk-panels.js';
81
81
  export { NkPanel } from './components/page/nk-panel.js';
82
82
 
83
+ // 1.7.0 – mobile and filter
84
+ export { NkSheet } from './components/overlays/nk-sheet.js';
85
+ export { NkSteps } from './components/page/nk-steps.js';
86
+
87
+ // 1.8.0 – links and peeks
88
+ export { NkBookmark } from './components/content/nk-bookmark.js';
89
+ export { NkCopyField } from './components/forms/nk-copy-field.js';
90
+ export { NkImagePicker } from './components/forms/nk-image-picker.js';
91
+ export { NkPeek } from './components/overlays/nk-peek.js';
92
+
83
93
  // Wave 4 – overlays
84
94
  export { NkModal } from './components/overlays/nk-modal.js';
85
95
  export { NkSettingsPane } from './components/overlays/nk-settings-pane.js';
package/src/util/focus.js CHANGED
@@ -1,6 +1,7 @@
1
- // Overlay plumbing shared by nk-modal and nk-cmdk: body scroll lock with a
2
- // refcount, and `inert` on everything outside the overlay so focus and
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
  export function lockScroll() {
@@ -31,6 +32,13 @@ export 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
+ export 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
  export 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"]';