@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.
- package/README.md +15 -15
- package/dist/components/nk-bookmark.js +69 -0
- package/dist/components/nk-btn.js +29 -3
- package/dist/components/nk-cmdk.js +1 -1
- package/dist/components/nk-copy-field.js +88 -0
- package/dist/components/nk-database.js +14 -5
- package/dist/components/nk-filter-bar.js +57 -36
- package/dist/components/nk-image-picker.js +130 -0
- 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-peek.js +122 -0
- 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 +786 -95
- package/dist/notionkit-elements.js +791 -94
- package/dist/notionkit-elements.min.js +1 -1
- package/package.json +6 -6
- package/src/components/content/nk-bookmark.js +67 -0
- 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/forms/nk-copy-field.js +86 -0
- package/src/components/forms/nk-image-picker.js +128 -0
- package/src/components/overlays/nk-menu-item.js +10 -6
- package/src/components/overlays/nk-menu.js +86 -1
- package/src/components/overlays/nk-peek.js +120 -0
- 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 +10 -0
- package/src/util/focus.js +11 -3
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
<h1 align="center">π§© NotionKit Elements</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<a href="https://www.npmjs.com/package/@jungherz-de/notionkit-elements"><img src="https://img.shields.io/badge/version-1.
|
|
4
|
+
<a href="https://www.npmjs.com/package/@jungherz-de/notionkit-elements"><img src="https://img.shields.io/badge/version-1.8.0-2383e2?style=flat-square" alt="Version"></a>
|
|
5
5
|
<a href="#"><img src="https://img.shields.io/badge/vanilla_JS-no_dependencies-448361?style=flat-square" alt="Vanilla JS"></a>
|
|
6
|
-
<a href="#"><img src="https://img.shields.io/badge/elements-
|
|
6
|
+
<a href="#"><img src="https://img.shields.io/badge/elements-83-529cca?style=flat-square" alt="83 Elements"></a>
|
|
7
7
|
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-9065b0?style=flat-square" alt="MIT License"></a>
|
|
8
|
-
<a href="CHANGELOG.md"><img src="https://img.shields.io/badge/changelog-v1.
|
|
8
|
+
<a href="CHANGELOG.md"><img src="https://img.shields.io/badge/changelog-v1.8.0-lightgrey?style=flat-square" alt="Changelog"></a>
|
|
9
9
|
<a href="https://www.npmjs.com/package/@jungherz-de/notionkit-elements"><img src="https://img.shields.io/badge/npm-%40jungherz--de%2Fnotionkit--elements-cb3837?style=flat-square&logo=npm" alt="npm"></a>
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
12
|
<p align="center">
|
|
13
13
|
<strong>Drop-in Web Components for <a href="https://github.com/JUNGHERZ/NotionKit">NotionKit CSS</a></strong><br>
|
|
14
|
-
|
|
14
|
+
83 vanilla JavaScript custom elements wrapping NotionKit's calm, document-centric workspace look.<br>
|
|
15
15
|
Shadow DOM · Native form participation · Pixel parity with the class markup · Zero dependencies.
|
|
16
16
|
</p>
|
|
17
17
|
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
## β¨ What is NotionKit Elements?
|
|
30
30
|
|
|
31
|
-
NotionKit Elements is the companion library to [NotionKit CSS](https://github.com/JUNGHERZ/NotionKit). It provides **
|
|
31
|
+
NotionKit Elements is the companion library to [NotionKit CSS](https://github.com/JUNGHERZ/NotionKit). It provides **83 Web Components** β from buttons and form controls over the sidebar, page tree and page shell with its properties to the settings modal, the bottom sheet, the side peek, βK palette, database views with Notionβs toolbar and AI thread β that encapsulate the class markup of the foundation into simple, declarative custom elements.
|
|
32
32
|
|
|
33
33
|
It is the **app layer** of the NotionKit family β three layers, one design language: [NotionKit](https://notionkit.jungherz.com) is the pure-CSS foundation, NotionKit Elements wraps it into web components for application UIs, and [NotionKit Web](https://notionkit-web.jungherz.com) is the Astro template for complete websites on top of the same foundation. The word stem stays the same across the layers: `.nk-callout` becomes `<nk-callout>`, a modifier class becomes an attribute, a state class becomes a boolean attribute.
|
|
34
34
|
|
|
@@ -56,10 +56,10 @@ It is the **app layer** of the NotionKit family β three layers, one design lan
|
|
|
56
56
|
|---|---|
|
|
57
57
|
| π― **Pixel parity** | Every element renders identically to its class markup β verified by a Playwright pixel test in light and dark; the reference app differs by 0.00 % from the class version |
|
|
58
58
|
| π **Shadow DOM** | Each root adopts the NotionKit *components* sheet via `adoptedStyleSheets`; tokens are inherited from the document, so one `:root { --nk-accent: β¦ }` re-brands everything |
|
|
59
|
-
| π§© **
|
|
59
|
+
| π§© **83 Elements** | Forms with copy field and image picker, content blocks with bookmarks, app shell & tree with the β° drawer, page shell with properties, panels, avatars and steps, overlays (modal, sheet, side peek, βK palette, menus that float in and become sheets on a phone, popover, emoji picker, toast), database table, board & list with toolbar and filter pills, comments, AI thread |
|
|
60
60
|
| ποΈ **Form participation** | Input, textarea, select, switch, check, radio, slider, segmented and model card work natively with `<form>` via `ElementInternals`; radios group across shadow roots |
|
|
61
61
|
| π **Theme sync** | One observer mirrors `data-theme` on `<html>` into every element |
|
|
62
|
-
| πͺΆ **Lightweight** |
|
|
62
|
+
| πͺΆ **Lightweight** | 225 KB minified / 44 KB gzipped (IIFE, foundation sheet included), no external dependencies |
|
|
63
63
|
| π¦ **Four bundle shapes** | IIFE, minified IIFE, ESM, and per-component ESM entries on a stable `base.js`, which import NotionKit's sheet instead of carrying a copy |
|
|
64
64
|
| π€ **AI-ready** | `SKILL.md` with copy-paste markup, six app skeletons and the rules β an agent given only that file built a working app in the release test |
|
|
65
65
|
|
|
@@ -71,8 +71,8 @@ It is the **app layer** of the NotionKit family β three layers, one design lan
|
|
|
71
71
|
<!DOCTYPE html>
|
|
72
72
|
<html lang="en" data-theme="light">
|
|
73
73
|
<head>
|
|
74
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@jungherz-de/notionkit@1.
|
|
75
|
-
<script src="https://cdn.jsdelivr.net/npm/@jungherz-de/notionkit-elements@1.
|
|
74
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@jungherz-de/notionkit@1.8.0/notionkit.min.css">
|
|
75
|
+
<script src="https://cdn.jsdelivr.net/npm/@jungherz-de/notionkit-elements@1.8.0/dist/notionkit-elements.min.js"></script>
|
|
76
76
|
</head>
|
|
77
77
|
<body class="nk-body">
|
|
78
78
|
<nk-field label="Display name" desc="Shown next to your comments">
|
|
@@ -102,17 +102,17 @@ The per-component files import NotionKit's sheet as `@jungherz-de/notionkit/noti
|
|
|
102
102
|
|
|
103
103
|
Do not mix the full bundle with the per-component files: each brings its own `NkElement`. With the bundle, take `componentsSheet` and `NkElement` from the bundle (`NotionKitElements.componentsSheet` from the `<script>` build).
|
|
104
104
|
|
|
105
|
-
Two prerequisites, always: `notionkit.css` on the document (the peer dependency, `>= 1.
|
|
105
|
+
Two prerequisites, always: `notionkit.css` on the document (the peer dependency, `>= 1.8.0`; 1.8.0 brings the side peek, the bookmark, the copy field and pictures on the profile row, 1.7.0 the sheet, menus that float in and become sheets on a phone, the sidebar drawer, the database toolbar with filter pills and the steps, 1.7.1 minified files that carry all of it, 1.6.0 page properties, page options, list view, panels, prose and the avatar, 1.5.1 the safe areas, 1.5.0 the Notion-2025 tokens, the nine tag colours and the filled inputs; from 1.5.0 on, Elements and the foundation share one version number β the elements are built and tested against the same release) and `class="nk-body"` on `<body>`. The elements ship no visual CSS of their own β every rule comes from the foundation. The bundle injects the design tokens once as `@layer notionkit-defaults`, so any plain `:root { --nk-accent: β¦ }` of yours re-brands every element in both themes.
|
|
106
106
|
|
|
107
107
|
## Elements
|
|
108
108
|
|
|
109
109
|
| Group | Elements |
|
|
110
110
|
|---|---|
|
|
111
|
-
| Forms & controls | `nk-btn` `nk-input` `nk-textarea` `nk-select` `nk-switch` `nk-check` `nk-radio` `nk-slider` `nk-field` `nk-fields` |
|
|
112
|
-
| Content | `nk-tag` `nk-progress` `nk-callout` `nk-divider` `nk-heading` `nk-toggle` `nk-todo` `nk-kbd` `nk-code` `nk-quote` |
|
|
111
|
+
| Forms & controls | `nk-btn` `nk-input` `nk-textarea` `nk-select` `nk-switch` `nk-check` `nk-radio` `nk-slider` `nk-field` `nk-fields` `nk-copy-field` `nk-image-picker` |
|
|
112
|
+
| Content | `nk-tag` `nk-progress` `nk-callout` `nk-bookmark` `nk-divider` `nk-heading` `nk-toggle` `nk-todo` `nk-kbd` `nk-code` `nk-quote` |
|
|
113
113
|
| App shell & navigation | `nk-app` `nk-sidebar` `nk-workspace-switcher` `nk-section-label` `nk-tree` `nk-tree-item` `nk-topbar` `nk-breadcrumb` `nk-theme-toggle` `nk-tab-bar` `nk-tab-bar-item` |
|
|
114
|
-
| Page shell & blocks | `nk-page` `nk-page-cover` `nk-page-title` `nk-page-actions` `nk-props` `nk-prop` `nk-panels` `nk-panel` `nk-avatar` `nk-block-host` `nk-banner` `nk-empty` `nk-skeleton` `nk-synced` `nk-tabs` `nk-tab` `nk-segmented` `nk-stats` `nk-stat` `nk-avatar-group` `nk-mention` `nk-template-btn` `nk-model-card` `nk-profile-row` `nk-danger-zone` `nk-member-list` `nk-member-row` |
|
|
115
|
-
| Overlays | `nk-modal` `nk-settings-pane` `nk-settings-user` `nk-cmdk` `nk-menu` `nk-menu-item` `nk-pop` `nk-emoji-picker` `nk-toast` |
|
|
114
|
+
| Page shell & blocks | `nk-page` `nk-page-cover` `nk-page-title` `nk-page-actions` `nk-props` `nk-prop` `nk-panels` `nk-panel` `nk-avatar` `nk-block-host` `nk-banner` `nk-empty` `nk-skeleton` `nk-synced` `nk-tabs` `nk-tab` `nk-segmented` `nk-steps` `nk-stats` `nk-stat` `nk-avatar-group` `nk-mention` `nk-template-btn` `nk-model-card` `nk-profile-row` `nk-danger-zone` `nk-member-list` `nk-member-row` |
|
|
115
|
+
| Overlays | `nk-modal` `nk-sheet` `nk-peek` `nk-settings-pane` `nk-settings-user` `nk-cmdk` `nk-menu` `nk-menu-item` `nk-pop` `nk-emoji-picker` `nk-toast` |
|
|
116
116
|
| Data & collaboration | `nk-database` `nk-table-view` `nk-board-view` `nk-list-view` `nk-filter-bar` `nk-comments` `nk-comment` `nk-ai-thread` `nk-ai-msg` `nk-ai-input-row` (+ the exported `renderPropertyCell()`) |
|
|
117
117
|
|
|
118
118
|
Static content goes in through attributes and slots, dynamic data through properties (`tree.data`, `database.rows`, `palette.commands`). Interactions fire custom events with fixed names: `nk-select`, `nk-change`, `nk-view-change`, `nk-command`, `nk-toggle`, `nk-submit`, `nk-action`. No fetching, no two-way binding β the elements render what they get.
|
|
@@ -124,7 +124,7 @@ Static content goes in through attributes and slots, dynamic data through proper
|
|
|
124
124
|
- Form controls are form-associated custom elements: `FormData`, `reset`, `required` and `<fieldset disabled>` just work. `<nk-radio>`s with the same `name` form a real group across shadow roots, with one tab stop and arrow keys.
|
|
125
125
|
- Elements that copy light-DOM children (`nk-select` options, breadcrumb crumbs) watch them; `element.refresh()` is the escape hatch. Listeners are re-armed on every connect, so a moved element keeps working.
|
|
126
126
|
- `::slotted()` matches only the assigned node: pass icons directly (`<span slot="icon">π</span>`), never wrapped. For the same reason there is no `<nk-prose>`: rendered Markdown goes into a light-DOM `<div class="nk-prose">`, which reads the same rules as the editor adapter.
|
|
127
|
-
- Overlays (`nk-modal`, `nk-cmdk`, `nk-toast`) go directly under `<body
|
|
127
|
+
- Overlays (`nk-modal`, `nk-sheet`, `nk-peek`, `nk-cmdk`, `nk-toast`, a floating `nk-menu`) go directly under `<body>`. The modal, the sheet and the palette lock scroll and make the rest of the page `inert` β the side peek only as a sheet on a phone, beside the page it leaves it usable; all of them return focus to the control that had it.
|
|
128
128
|
- The editor stays an adapter: `nk-block-host` is the shell, `docs-editor.js` the TipTap recipe (used in the demo app). `<nk-editor>` follows in v1.1 as an optional import, never in the core bundle.
|
|
129
129
|
|
|
130
130
|
## Development
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { NkElement } from './base.js';
|
|
2
|
+
import '@jungherz-de/notionkit/notionkit-styles.js';
|
|
3
|
+
|
|
4
|
+
// <nk-bookmark href="https://notionkit.jungherz.com" title="NotionKit" desc="β¦"
|
|
5
|
+
// favicon="favicon.svg" cover="og.jpg"></nk-bookmark>
|
|
6
|
+
// β <a class="nk-bookmark" href="β¦" target="_blank" rel="noopener">
|
|
7
|
+
// <span class="bm-text"><span class="bm-title">β¦</span><span class="bm-desc">β¦</span>
|
|
8
|
+
// <span class="bm-url"><img class="bm-favicon"><span>β¦</span></span></span>
|
|
9
|
+
// <span class="bm-cover"><img></span></a>
|
|
10
|
+
// Notion's link block (NotionKit 1.8.0), filled from what you know of the
|
|
11
|
+
// page: og:title, og:description, og:image. `title` is the heading, never a
|
|
12
|
+
// tooltip β see NkElement.takeTitle(); without it the host name stands in.
|
|
13
|
+
// The address shown is `href`, or `url` where it should read differently. A
|
|
14
|
+
// part without a value is left out, not hidden β the stylesheet gives the
|
|
15
|
+
// description its own display. Opens in a new tab unless `target` says so.
|
|
16
|
+
class NkBookmark extends NkElement {
|
|
17
|
+
static get observedAttributes() { return ['href', 'title', 'desc', 'favicon', 'cover', 'target', 'url']; }
|
|
18
|
+
|
|
19
|
+
render() {
|
|
20
|
+
this.takeTitle();
|
|
21
|
+
this._a = this.createElement('a', ['nk-bookmark']);
|
|
22
|
+
this._wrapper.appendChild(this._a);
|
|
23
|
+
this._sync();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
_sync() {
|
|
27
|
+
if (!this._a) return;
|
|
28
|
+
const href = this.getAttribute('href') || '';
|
|
29
|
+
this._a.setAttribute('href', href);
|
|
30
|
+
const target = this.getAttribute('target') || '_blank';
|
|
31
|
+
this._a.setAttribute('target', target);
|
|
32
|
+
if (target === '_blank') this._a.setAttribute('rel', 'noopener'); else this._a.removeAttribute('rel');
|
|
33
|
+
let host = href;
|
|
34
|
+
try { host = new URL(href, location.href).host; } catch { /* keep the text */ }
|
|
35
|
+
|
|
36
|
+
const text = this.createElement('span', ['bm-text']);
|
|
37
|
+
const title = this.createElement('span', ['bm-title']);
|
|
38
|
+
title.textContent = this._titleText || host;
|
|
39
|
+
text.appendChild(title);
|
|
40
|
+
const desc = this.getAttribute('desc');
|
|
41
|
+
if (desc) { const d = this.createElement('span', ['bm-desc']); d.textContent = desc; text.appendChild(d); }
|
|
42
|
+
const url = this.createElement('span', ['bm-url']);
|
|
43
|
+
const favicon = this.getAttribute('favicon');
|
|
44
|
+
if (favicon) url.appendChild(this.createElement('img', ['bm-favicon'], { src: favicon, alt: '' }));
|
|
45
|
+
const address = document.createElement('span');
|
|
46
|
+
address.textContent = this.getAttribute('url') || href;
|
|
47
|
+
url.appendChild(address);
|
|
48
|
+
text.appendChild(url);
|
|
49
|
+
const parts = [text];
|
|
50
|
+
const cover = this.getAttribute('cover');
|
|
51
|
+
if (cover) { const c = this.createElement('span', ['bm-cover']); c.appendChild(this.createElement('img', [], { src: cover, alt: '' })); parts.push(c); }
|
|
52
|
+
this._a.replaceChildren(...parts);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onAttributeChanged(name, _old, value) {
|
|
56
|
+
if (name === 'title' && !this.takeTitle(value)) return;
|
|
57
|
+
this._sync();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
focus(o) { this._a?.focus(o); }
|
|
61
|
+
get title() { return this._titleText ?? ''; }
|
|
62
|
+
set title(v) { this._titleText = v == null ? '' : String(v); this._sync(); }
|
|
63
|
+
get href() { return this.getAttribute('href') || ''; }
|
|
64
|
+
set href(v) { this.setAttribute('href', v); }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
customElements.define('nk-bookmark', NkBookmark);
|
|
68
|
+
|
|
69
|
+
export { NkBookmark };
|
|
@@ -4,13 +4,16 @@ import '@jungherz-de/notionkit/notionkit-styles.js';
|
|
|
4
4
|
// <nk-btn variant="primary" small>Save</nk-btn> β <button class="nk-btn primary small">
|
|
5
5
|
// <nk-btn href="/docs" variant="secondary">Docs</nk-btn> β <a class="nk-btn secondary">
|
|
6
6
|
// <nk-btn variant="topbar">β</nk-btn> β <button class="nk-topbar-btn">
|
|
7
|
+
// <nk-btn variant="tool" active>Filter</nk-btn> β <button class="nk-db-tool active"> (slot="tools" of nk-database)
|
|
8
|
+
// <nk-btn variant="sidebar" aria-label="Menu">β°</nk-btn> β <button class="nk-topbar-btn nk-sidebar-toggle">:
|
|
9
|
+
// shown on phones only, it opens the page's <nk-sidebar> as a drawer.
|
|
7
10
|
//
|
|
8
11
|
// Modifier classes become attributes. A slotted <svg> is sized by the
|
|
9
12
|
// `.nk-btn ::slotted(svg)` twin; pass the icon itself, never wrapped.
|
|
10
13
|
const VARIANTS = ['primary', 'secondary', 'danger', 'danger-solid', 'topbar', 'share'];
|
|
11
14
|
|
|
12
15
|
class NkBtn extends NkElement {
|
|
13
|
-
static get observedAttributes() { return ['variant', 'small', 'disabled', 'type', 'href', 'title', 'aria-label']; }
|
|
16
|
+
static get observedAttributes() { return ['variant', 'small', 'disabled', 'type', 'href', 'title', 'aria-label', 'aria-haspopup', 'active']; }
|
|
14
17
|
|
|
15
18
|
render() {
|
|
16
19
|
this._build();
|
|
@@ -38,13 +41,22 @@ class NkBtn extends NkElement {
|
|
|
38
41
|
else el.setAttribute('aria-disabled', disabled ? 'true' : 'false');
|
|
39
42
|
const title = this.getAttribute('title');
|
|
40
43
|
title ? el.setAttribute('title', title) : el.removeAttribute('title');
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
// The accessible name and the popup hint belong on the button itself.
|
|
45
|
+
for (const name of ['aria-label', 'aria-haspopup']) {
|
|
46
|
+
const v = this.getAttribute(name);
|
|
47
|
+
v ? el.setAttribute(name, v) : el.removeAttribute(name);
|
|
48
|
+
}
|
|
49
|
+
if (this.getAttribute('variant') === 'sidebar') el.setAttribute('aria-expanded', this._sidebar()?.open ? 'true' : 'false');
|
|
50
|
+
else el.removeAttribute('aria-expanded');
|
|
43
51
|
}
|
|
44
52
|
|
|
53
|
+
/** The sidebar the β° opens: the one in its own app, else the page's. */
|
|
54
|
+
_sidebar() { return this.closest('nk-app')?.querySelector('nk-sidebar') ?? document.querySelector('nk-sidebar'); }
|
|
55
|
+
|
|
45
56
|
setupEvents() {
|
|
46
57
|
this._onClick = (e) => {
|
|
47
58
|
if (this.getBoolAttr('disabled')) { e.preventDefault(); e.stopPropagation(); return; }
|
|
59
|
+
if (this.getAttribute('variant') === 'sidebar') { this._sidebar()?.toggle?.(); return; }
|
|
48
60
|
// A button inside a shadow root is not a submit button of the outer
|
|
49
61
|
// form; forward the intent to the form the host sits in.
|
|
50
62
|
const type = this.getAttribute('type');
|
|
@@ -53,11 +65,17 @@ class NkBtn extends NkElement {
|
|
|
53
65
|
if (form) type === 'submit' ? form.requestSubmit() : form.reset();
|
|
54
66
|
}
|
|
55
67
|
};
|
|
68
|
+
// The β° says whether its drawer is open, however the drawer closed.
|
|
69
|
+
this._onToggle = (e) => {
|
|
70
|
+
if (this.getAttribute('variant') === 'sidebar' && e.target === this._sidebar()) this._btn.setAttribute('aria-expanded', e.detail.open ? 'true' : 'false');
|
|
71
|
+
};
|
|
56
72
|
this._btn.addEventListener('click', this._onClick);
|
|
73
|
+
document.addEventListener('nk-toggle', this._onToggle);
|
|
57
74
|
}
|
|
58
75
|
|
|
59
76
|
teardownEvents() {
|
|
60
77
|
this._btn?.removeEventListener('click', this._onClick);
|
|
78
|
+
document.removeEventListener('nk-toggle', this._onToggle);
|
|
61
79
|
}
|
|
62
80
|
|
|
63
81
|
onAttributeChanged(name) {
|
|
@@ -67,7 +85,11 @@ class NkBtn extends NkElement {
|
|
|
67
85
|
this._build();
|
|
68
86
|
break;
|
|
69
87
|
case 'variant':
|
|
88
|
+
this._btn.className = this._computeClasses().join(' ');
|
|
89
|
+
this._applyState(this._btn);
|
|
90
|
+
break;
|
|
70
91
|
case 'small':
|
|
92
|
+
case 'active':
|
|
71
93
|
this._btn.className = this._computeClasses().join(' ');
|
|
72
94
|
break;
|
|
73
95
|
case 'type':
|
|
@@ -82,6 +104,8 @@ class NkBtn extends NkElement {
|
|
|
82
104
|
const variant = this.getAttribute('variant');
|
|
83
105
|
if (variant === 'topbar') return ['nk-topbar-btn'];
|
|
84
106
|
if (variant === 'share') return ['nk-topbar-btn', 'nk-share-btn'];
|
|
107
|
+
if (variant === 'sidebar') return ['nk-topbar-btn', 'nk-sidebar-toggle'];
|
|
108
|
+
if (variant === 'tool') return this.getBoolAttr('active') ? ['nk-db-tool', 'active'] : ['nk-db-tool'];
|
|
85
109
|
const classes = ['nk-btn'];
|
|
86
110
|
if (VARIANTS.includes(variant)) classes.push(variant);
|
|
87
111
|
if (this.getBoolAttr('small')) classes.push('small');
|
|
@@ -93,6 +117,8 @@ class NkBtn extends NkElement {
|
|
|
93
117
|
|
|
94
118
|
get variant() { return this.getAttribute('variant'); }
|
|
95
119
|
set variant(v) { v ? this.setAttribute('variant', v) : this.removeAttribute('variant'); }
|
|
120
|
+
get active() { return this.getBoolAttr('active'); }
|
|
121
|
+
set active(v) { this.setBoolAttr('active', v); }
|
|
96
122
|
get small() { return this.getBoolAttr('small'); }
|
|
97
123
|
set small(v) { this.setBoolAttr('small', v); }
|
|
98
124
|
get disabled() { return this.getBoolAttr('disabled'); }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NkElement } from './base.js';
|
|
2
|
-
import { l as lockScroll, i as inertOutside, u as unlockScroll } from './shared/focus-
|
|
2
|
+
import { l as lockScroll, i as inertOutside, u as unlockScroll } from './shared/focus-BNAChOXO.js';
|
|
3
3
|
import '@jungherz-de/notionkit/notionkit-styles.js';
|
|
4
4
|
|
|
5
5
|
// Subsequence scoring for the command palette: every query character must
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { NkElement } from './base.js';
|
|
2
|
+
import '@jungherz-de/notionkit/notionkit-styles.js';
|
|
3
|
+
|
|
4
|
+
// <nk-copy-field value="https://monahilft.notionkit.app"></nk-copy-field>
|
|
5
|
+
// <nk-copy-field value="ntn_4f2β¦" secret mono></nk-copy-field>
|
|
6
|
+
// β <div class="nk-copy-field mono"><span class="cf-value">β¦</span>
|
|
7
|
+
// <button class="cf-btn">Show</button><button class="cf-btn">Copy</button></div>
|
|
8
|
+
// A value to take along β a link, an address, a key (NotionKit 1.8.0). Copy
|
|
9
|
+
// writes it to the clipboard and says "Copied" in green for a moment; where
|
|
10
|
+
// the clipboard is not allowed, the value is shown and selected instead, for
|
|
11
|
+
// βC. `secret` masks it behind a Show/Hide toggle; Copy still copies the
|
|
12
|
+
// real value. `value` set as a property is not reflected, so a key never
|
|
13
|
+
// lands in the markup. Fires nk-action { action: 'copy', value, ok }. The
|
|
14
|
+
// texts are attributes: copy-label, copied-label, show-label, hide-label.
|
|
15
|
+
class NkCopyField extends NkElement {
|
|
16
|
+
static get observedAttributes() { return ['value', 'mono', 'wrap', 'wide', 'secret', 'copy-label', 'copied-label', 'show-label', 'hide-label']; }
|
|
17
|
+
|
|
18
|
+
render() {
|
|
19
|
+
this._val ??= this.getAttribute('value') ?? '';
|
|
20
|
+
this._box = this.createElement('div', ['nk-copy-field']);
|
|
21
|
+
this._text = this.createElement('span', ['cf-value']);
|
|
22
|
+
this._show = this.createElement('button', ['cf-btn'], { type: 'button' });
|
|
23
|
+
this._copy = this.createElement('button', ['cf-btn'], { type: 'button' });
|
|
24
|
+
this._box.append(this._text, this._copy);
|
|
25
|
+
this._wrapper.appendChild(this._box);
|
|
26
|
+
this._sync();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
_sync() {
|
|
30
|
+
if (!this._box) return;
|
|
31
|
+
for (const m of ['mono', 'wrap', 'wide']) this._box.classList.toggle(m, this.getBoolAttr(m));
|
|
32
|
+
const secret = this.getBoolAttr('secret');
|
|
33
|
+
this._text.textContent = secret && !this._revealed ? 'β’'.repeat(Math.min(this._val.length, 24)) : this._val;
|
|
34
|
+
// Not `hidden`: .cf-btn sets no display of its own that could lose to it,
|
|
35
|
+
// but a button that is not there cannot be tabbed to either.
|
|
36
|
+
if (secret && !this._show.isConnected) this._copy.before(this._show);
|
|
37
|
+
if (!secret) this._show.remove();
|
|
38
|
+
this._show.textContent = this._revealed ? (this.getAttribute('hide-label') || 'Hide') : (this.getAttribute('show-label') || 'Show');
|
|
39
|
+
this._show.setAttribute('aria-pressed', String(!!this._revealed));
|
|
40
|
+
this._copy.textContent = this._copied ? (this.getAttribute('copied-label') || 'Copied') : (this.getAttribute('copy-label') || 'Copy');
|
|
41
|
+
this._copy.classList.toggle('copied', !!this._copied);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setupEvents() {
|
|
45
|
+
this._onCopy = () => this.copy();
|
|
46
|
+
this._onShow = () => { this._revealed = !this._revealed; this._sync(); };
|
|
47
|
+
this._copy.addEventListener('click', this._onCopy);
|
|
48
|
+
this._show.addEventListener('click', this._onShow);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
teardownEvents() {
|
|
52
|
+
this._copy?.removeEventListener('click', this._onCopy);
|
|
53
|
+
this._show?.removeEventListener('click', this._onShow);
|
|
54
|
+
clearTimeout(this._timer);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
onAttributeChanged(name, _old, value) {
|
|
58
|
+
if (name === 'value') this._val = value ?? '';
|
|
59
|
+
this._sync();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Copies the value; resolves to whether the clipboard took it. */
|
|
63
|
+
async copy() {
|
|
64
|
+
const value = this._val;
|
|
65
|
+
let ok = true;
|
|
66
|
+
try { await navigator.clipboard.writeText(value); } catch { ok = false; }
|
|
67
|
+
if (ok) {
|
|
68
|
+
this._copied = true;
|
|
69
|
+
clearTimeout(this._timer);
|
|
70
|
+
this._timer = setTimeout(() => { this._copied = false; this._sync(); }, 1500);
|
|
71
|
+
} else {
|
|
72
|
+
this._revealed = true;
|
|
73
|
+
}
|
|
74
|
+
this._sync();
|
|
75
|
+
if (!ok) getSelection()?.selectAllChildren(this._text);
|
|
76
|
+
this.emit('nk-action', { action: 'copy', value, ok });
|
|
77
|
+
return ok;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get value() { return this._val ?? this.getAttribute('value') ?? ''; }
|
|
81
|
+
set value(v) { this._val = v == null ? '' : String(v); this._sync(); }
|
|
82
|
+
get secret() { return this.getBoolAttr('secret'); }
|
|
83
|
+
set secret(v) { this.setBoolAttr('secret', v); }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
customElements.define('nk-copy-field', NkCopyField);
|
|
87
|
+
|
|
88
|
+
export { NkCopyField };
|
|
@@ -7,16 +7,24 @@ import '@jungherz-de/notionkit/notionkit-styles.js';
|
|
|
7
7
|
// </nk-database>
|
|
8
8
|
// db.columns = [{ key: 'name', label: 'Name', type: 'text', icon: 'π', title: true }, { key: 'status', type: 'select', options: [...] }, β¦];
|
|
9
9
|
// db.rows = [{ id: 1, icon: 'π§', name: 'β¦', status: 'done', β¦ }];
|
|
10
|
-
//
|
|
10
|
+
// <nk-btn slot="tools" variant="tool">Filter</nk-btn> β¦ sit right of the tabs,
|
|
11
|
+
// <nk-filter-bar slot="filters"> under them (NotionKit 1.7.0's toolbar).
|
|
12
|
+
// β <div class="nk-database"><div class="nk-db-toolbar"><div class="nk-db-tabs">β¦</div>
|
|
13
|
+
// <div class="tools">β¦</div></div>β¦filtersβ¦active viewβ¦</div>
|
|
11
14
|
// The tabs come from the child views; data is pushed into every view.
|
|
12
15
|
class NkDatabase extends NkElement {
|
|
13
16
|
static get observedAttributes() { return ['view', 'add-view']; }
|
|
14
17
|
|
|
15
18
|
render() {
|
|
16
19
|
this._box = this.createElement('div', ['nk-database']);
|
|
20
|
+
this._toolbar = this.createElement('div', ['nk-db-toolbar']);
|
|
17
21
|
this._tabs = this.createElement('div', ['nk-db-tabs'], { role: 'tablist' });
|
|
22
|
+
const tools = this.createElement('div', ['tools']);
|
|
23
|
+
this._toolsSlot = this.createElement('slot', [], { name: 'tools' });
|
|
24
|
+
tools.appendChild(this._toolsSlot);
|
|
25
|
+
this._toolbar.append(this._tabs, tools);
|
|
18
26
|
this._slot = document.createElement('slot');
|
|
19
|
-
this._box.append(this.
|
|
27
|
+
this._box.append(this._toolbar, this.createElement('slot', [], { name: 'filters' }), this._slot);
|
|
20
28
|
this._wrapper.appendChild(this._box);
|
|
21
29
|
this._columns = []; this._rows = [];
|
|
22
30
|
this._sync();
|
|
@@ -44,12 +52,11 @@ class NkDatabase extends NkElement {
|
|
|
44
52
|
v.setData?.(this._columns, this._rows);
|
|
45
53
|
}
|
|
46
54
|
if (this.getBoolAttr('add-view')) {
|
|
47
|
-
const add = this.createElement('span', ['nk-db-tab'], { role: 'button', 'data-add': '', tabindex: '0' });
|
|
48
|
-
add.style.color = 'var(--nk-text-tertiary)';
|
|
55
|
+
const add = this.createElement('span', ['nk-db-tab', 'add'], { role: 'button', 'data-add': '', tabindex: '0' });
|
|
49
56
|
add.textContent = 'οΌ';
|
|
50
57
|
this._tabs.appendChild(add);
|
|
51
58
|
}
|
|
52
|
-
this.
|
|
59
|
+
this._toolbar.hidden = !views.length && !this._toolsSlot.assignedElements().length;
|
|
53
60
|
this._current = current;
|
|
54
61
|
}
|
|
55
62
|
|
|
@@ -71,6 +78,7 @@ class NkDatabase extends NkElement {
|
|
|
71
78
|
this._tabs.addEventListener('click', this._onClick);
|
|
72
79
|
this._tabs.addEventListener('keydown', this._onKey);
|
|
73
80
|
this._slot.addEventListener('slotchange', this._onSlot);
|
|
81
|
+
this._toolsSlot.addEventListener('slotchange', this._onSlot);
|
|
74
82
|
this._sync();
|
|
75
83
|
}
|
|
76
84
|
|
|
@@ -78,6 +86,7 @@ class NkDatabase extends NkElement {
|
|
|
78
86
|
this._tabs?.removeEventListener('click', this._onClick);
|
|
79
87
|
this._tabs?.removeEventListener('keydown', this._onKey);
|
|
80
88
|
this._slot?.removeEventListener('slotchange', this._onSlot);
|
|
89
|
+
this._toolsSlot?.removeEventListener('slotchange', this._onSlot);
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
onAttributeChanged(name) {
|
|
@@ -1,61 +1,77 @@
|
|
|
1
1
|
import { NkElement } from './base.js';
|
|
2
2
|
import '@jungherz-de/notionkit/notionkit-styles.js';
|
|
3
3
|
|
|
4
|
-
// <nk-filter-bar
|
|
5
|
-
// bar.filters = [{ key: 'status',
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
4
|
+
// <nk-filter-bar add no-filter no-sort></nk-filter-bar>
|
|
5
|
+
// bar.filters = [{ key: 'status', value: 'done', op: 'is-not', label: 'Status: Open' }];
|
|
6
|
+
// The filters in effect as NotionKit's filter pills (1.7.0), no inline style:
|
|
7
|
+
// β <div class="nk-filter-row">[Filter][Sort]
|
|
8
|
+
// <span class="nk-filter-pill active"><button>Status: Open</button><button class="fp-remove">Γ</button></span>β¦
|
|
9
|
+
// <button class="nk-filter-pill add">οΌ Filter</button> β¦slotβ¦ [search]</div>
|
|
10
|
+
// Filter and Sort are .nk-db-tool buttons (hide them with no-filter / no-sort
|
|
11
|
+
// when the database toolbar carries its own); they fire nk-action. A pill's
|
|
12
|
+
// label fires nk-action { action: 'edit', index, filter }, the add pill
|
|
13
|
+
// nk-action { action: 'add' } β each with the clicked button as `anchor`, to
|
|
14
|
+
// open a menu under it. Γ removes the filter; every change to filters or
|
|
15
|
+
// search fires nk-change { filters, search }. In slot="filters" of
|
|
16
|
+
// <nk-database> the row sits right under the view tabs. The texts are
|
|
17
|
+
// attributes, for other languages: filter-label, sort-label, add-label,
|
|
18
|
+
// remove-label (the Γ reads "<remove-label>: <pill>") and placeholder.
|
|
9
19
|
class NkFilterBar extends NkElement {
|
|
10
|
-
static get observedAttributes() { return ['search', 'placeholder', 'no-filter', 'no-sort', 'value']; }
|
|
20
|
+
static get observedAttributes() { return ['search', 'placeholder', 'no-filter', 'no-sort', 'value', 'add', 'add-label', 'filter-label', 'sort-label', 'remove-label']; }
|
|
11
21
|
|
|
12
22
|
render() {
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this._sortBtn.textContent = 'β Sort';
|
|
19
|
-
this._chips = document.createElement('span');
|
|
20
|
-
this._chips.style.cssText = 'display:inline-flex;gap:4px;flex-wrap:wrap';
|
|
23
|
+
this._row = this.createElement('div', ['nk-filter-row']);
|
|
24
|
+
this._filterBtn = this.createElement('button', ['nk-db-tool'], { type: 'button', 'data-action': 'filter' });
|
|
25
|
+
this._sortBtn = this.createElement('button', ['nk-db-tool'], { type: 'button', 'data-action': 'sort' });
|
|
26
|
+
this._pillStart = document.createComment('pills');
|
|
27
|
+
this._addBtn = this.createElement('button', ['nk-filter-pill', 'add'], { type: 'button', 'data-action': 'add' });
|
|
21
28
|
this._input = this.createElement('input', ['nk-input'], { type: 'search', autocomplete: 'off' });
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
this._wrapper.appendChild(this._bar);
|
|
29
|
+
this._row.append(this._filterBtn, this._sortBtn, this._pillStart, this._addBtn, document.createElement('slot'), this._input);
|
|
30
|
+
this._wrapper.appendChild(this._row);
|
|
25
31
|
this._filters = [];
|
|
26
32
|
this._sync();
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
_sync() {
|
|
30
|
-
this._filterBtn.
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
36
|
+
this._filterBtn.textContent = this.getAttribute('filter-label') || 'Filter';
|
|
37
|
+
this._filterBtn.hidden = this.getBoolAttr('no-filter');
|
|
38
|
+
this._filterBtn.classList.toggle('active', this._filters.length > 0);
|
|
39
|
+
this._sortBtn.textContent = this.getAttribute('sort-label') || 'Sort';
|
|
40
|
+
this._sortBtn.hidden = this.getBoolAttr('no-sort');
|
|
41
|
+
this._addBtn.textContent = this.getAttribute('add-label') || 'οΌ Filter';
|
|
42
|
+
this._addBtn.hidden = !this.getBoolAttr('add');
|
|
43
|
+
this._input.hidden = !this.getBoolAttr('search');
|
|
33
44
|
this._input.placeholder = this.getAttribute('placeholder') || 'Search β¦';
|
|
34
45
|
if (this.hasAttribute('value') && this._input.value !== this.getAttribute('value')) this._input.value = this.getAttribute('value');
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
|
|
46
|
+
for (const old of this._row.querySelectorAll('[data-pill]')) old.remove();
|
|
47
|
+
const removeLabel = this.getAttribute('remove-label') || 'Remove filter';
|
|
48
|
+
this._pillStart.after(...this._filters.map((f, i) => {
|
|
49
|
+
const pill = this.createElement('span', ['nk-filter-pill', 'active'], { 'data-pill': i });
|
|
50
|
+
const label = this.createElement('button', [], { type: 'button', 'data-edit': i });
|
|
51
|
+
label.textContent = f.label ?? `${f.key}: ${f.value}`;
|
|
52
|
+
const remove = this.createElement('button', ['fp-remove'], { type: 'button', 'data-remove': i, 'aria-label': `${removeLabel}: ${label.textContent}` });
|
|
53
|
+
remove.textContent = 'Γ';
|
|
54
|
+
pill.append(label, remove);
|
|
55
|
+
return pill;
|
|
56
|
+
}));
|
|
43
57
|
}
|
|
44
58
|
|
|
45
59
|
setupEvents() {
|
|
46
60
|
this._onClick = (e) => {
|
|
61
|
+
const remove = e.target.closest('[data-remove]');
|
|
62
|
+
if (remove) { this._filters.splice(Number(remove.dataset.remove), 1); this._sync(); this._emitChange(); return; }
|
|
63
|
+
const edit = e.target.closest('[data-edit]');
|
|
64
|
+
if (edit) { const index = Number(edit.dataset.edit); this.emit('nk-action', { action: 'edit', index, filter: this._filters[index], anchor: edit }); return; }
|
|
47
65
|
const btn = e.target.closest('[data-action]');
|
|
48
|
-
if (btn)
|
|
49
|
-
const chip = e.target.closest('[data-index]');
|
|
50
|
-
if (chip) { this._filters.splice(Number(chip.dataset.index), 1); this._sync(); this._emitChange(); }
|
|
66
|
+
if (btn) this.emit('nk-action', { action: btn.dataset.action, anchor: btn });
|
|
51
67
|
};
|
|
52
68
|
this._onInput = () => { clearTimeout(this._debounce); this._debounce = setTimeout(() => this._emitChange(), 150); };
|
|
53
|
-
this.
|
|
69
|
+
this._row.addEventListener('click', this._onClick);
|
|
54
70
|
this._input.addEventListener('input', this._onInput);
|
|
55
71
|
}
|
|
56
72
|
|
|
57
73
|
teardownEvents() {
|
|
58
|
-
this.
|
|
74
|
+
this._row?.removeEventListener('click', this._onClick);
|
|
59
75
|
this._input?.removeEventListener('input', this._onInput);
|
|
60
76
|
clearTimeout(this._debounce);
|
|
61
77
|
}
|
|
@@ -64,13 +80,18 @@ class NkFilterBar extends NkElement {
|
|
|
64
80
|
onAttributeChanged() { this._sync(); }
|
|
65
81
|
|
|
66
82
|
get filters() { return this._filters; }
|
|
67
|
-
set filters(v) { this._filters = Array.isArray(v) ? v : []; this._sync(); }
|
|
83
|
+
set filters(v) { this._filters = Array.isArray(v) ? v : []; if (this._row) this._sync(); }
|
|
68
84
|
get value() { return this._input?.value ?? ''; }
|
|
69
85
|
set value(v) { if (this._input) this._input.value = v ?? ''; }
|
|
70
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Applies filters and search to rows: a filter keeps rows where row[key]
|
|
88
|
+
* equals value β or differs from it with op: 'is-not'; the search looks
|
|
89
|
+
* for the text in every string field (a person's name).
|
|
90
|
+
*/
|
|
71
91
|
apply(rows) {
|
|
72
92
|
const q = this.value.trim().toLowerCase();
|
|
73
|
-
return rows.filter(r => this._filters.every(f => r[f.key]
|
|
93
|
+
return rows.filter(r => this._filters.every(f => (f.op === 'is-not' ? r[f.key] !== f.value : r[f.key] === f.value))
|
|
94
|
+
&& (!q || Object.values(r).some(v => String(typeof v === 'object' && v ? v.name ?? '' : v ?? '').toLowerCase().includes(q))));
|
|
74
95
|
}
|
|
75
96
|
}
|
|
76
97
|
|