@jungherz-de/notionkit-elements 1.5.3 → 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.
Files changed (115) hide show
  1. package/README.md +27 -18
  2. package/dist/components/base.js +346 -0
  3. package/dist/components/nk-ai-input-row.js +2 -1
  4. package/dist/components/nk-ai-msg.js +10 -3
  5. package/dist/components/nk-ai-thread.js +2 -1
  6. package/dist/components/nk-app.js +2 -1
  7. package/dist/components/nk-avatar-group.js +2 -1
  8. package/dist/components/nk-avatar.js +57 -0
  9. package/dist/components/nk-banner.js +2 -1
  10. package/dist/components/nk-block-host.js +2 -1
  11. package/dist/components/nk-board-view.js +4 -2
  12. package/dist/components/nk-breadcrumb.js +2 -1
  13. package/dist/components/nk-btn.js +31 -4
  14. package/dist/components/nk-callout.js +2 -1
  15. package/dist/components/nk-check.js +2 -1
  16. package/dist/components/nk-cmdk.js +3 -2
  17. package/dist/components/nk-code.js +2 -1
  18. package/dist/components/nk-comment.js +9 -6
  19. package/dist/components/nk-comments.js +2 -1
  20. package/dist/components/nk-danger-zone.js +2 -1
  21. package/dist/components/nk-database.js +16 -6
  22. package/dist/components/nk-divider.js +2 -1
  23. package/dist/components/nk-emoji-picker.js +2 -1
  24. package/dist/components/nk-empty.js +2 -1
  25. package/dist/components/nk-field.js +2 -1
  26. package/dist/components/nk-fields.js +2 -1
  27. package/dist/components/nk-filter-bar.js +59 -37
  28. package/dist/components/nk-heading.js +2 -1
  29. package/dist/components/nk-input.js +2 -1
  30. package/dist/components/nk-kbd.js +2 -1
  31. package/dist/components/nk-list-view.js +96 -0
  32. package/dist/components/nk-member-list.js +2 -1
  33. package/dist/components/nk-member-row.js +10 -6
  34. package/dist/components/nk-mention.js +2 -1
  35. package/dist/components/nk-menu-item.js +27 -3
  36. package/dist/components/nk-menu.js +88 -2
  37. package/dist/components/nk-modal.js +3 -2
  38. package/dist/components/nk-model-card.js +2 -1
  39. package/dist/components/nk-page-actions.js +2 -1
  40. package/dist/components/nk-page-cover.js +12 -11
  41. package/dist/components/nk-page-title.js +2 -1
  42. package/dist/components/nk-page.js +12 -4
  43. package/dist/components/nk-panel.js +61 -0
  44. package/dist/components/nk-panels.js +18 -0
  45. package/dist/components/nk-pop.js +2 -1
  46. package/dist/components/nk-profile-row.js +2 -1
  47. package/dist/components/nk-progress.js +5 -2
  48. package/dist/components/nk-prop.js +54 -0
  49. package/dist/components/nk-props.js +21 -0
  50. package/dist/components/nk-quote.js +2 -1
  51. package/dist/components/nk-radio.js +2 -1
  52. package/dist/components/nk-section-label.js +2 -1
  53. package/dist/components/nk-segmented.js +21 -1
  54. package/dist/components/nk-select.js +2 -1
  55. package/dist/components/nk-settings-pane.js +2 -1
  56. package/dist/components/nk-settings-user.js +2 -1
  57. package/dist/components/nk-sheet.js +97 -0
  58. package/dist/components/nk-sidebar.js +17 -37
  59. package/dist/components/nk-skeleton.js +2 -1
  60. package/dist/components/nk-slider.js +2 -1
  61. package/dist/components/nk-stat.js +2 -1
  62. package/dist/components/nk-stats.js +2 -1
  63. package/dist/components/nk-steps.js +61 -0
  64. package/dist/components/nk-switch.js +2 -1
  65. package/dist/components/nk-synced.js +2 -1
  66. package/dist/components/nk-tab-bar-item.js +2 -1
  67. package/dist/components/nk-tab-bar.js +2 -1
  68. package/dist/components/nk-tab.js +2 -1
  69. package/dist/components/nk-table-view.js +6 -2
  70. package/dist/components/nk-tabs.js +2 -1
  71. package/dist/components/nk-tag.js +2 -1
  72. package/dist/components/nk-template-btn.js +2 -1
  73. package/dist/components/nk-textarea.js +2 -1
  74. package/dist/components/nk-theme-toggle.js +2 -1
  75. package/dist/components/nk-toast.js +2 -1
  76. package/dist/components/nk-todo.js +2 -1
  77. package/dist/components/nk-toggle.js +2 -1
  78. package/dist/components/nk-topbar.js +2 -1
  79. package/dist/components/nk-tree-item.js +2 -1
  80. package/dist/components/nk-tree.js +2 -1
  81. package/dist/components/nk-workspace-switcher.js +2 -1
  82. package/dist/components/shared/avatar-BiqCaHOt.js +19 -0
  83. package/dist/components/shared/{focus-DXrK9oLe.js → focus-BNAChOXO.js} +12 -4
  84. package/dist/components/shared/{property-cell-CtXQpUjQ.js → property-cell-o7N30kAQ.js} +8 -3
  85. package/dist/notionkit-elements.esm.js +759 -120
  86. package/dist/notionkit-elements.js +767 -119
  87. package/dist/notionkit-elements.min.js +1 -1
  88. package/package.json +7 -6
  89. package/src/components/content/nk-progress.js +3 -1
  90. package/src/components/data/nk-ai-msg.js +8 -2
  91. package/src/components/data/nk-comment.js +7 -5
  92. package/src/components/data/nk-database.js +14 -5
  93. package/src/components/data/nk-filter-bar.js +57 -36
  94. package/src/components/data/nk-list-view.js +93 -0
  95. package/src/components/data/nk-table-view.js +2 -0
  96. package/src/components/forms/nk-btn.js +29 -3
  97. package/src/components/overlays/nk-menu-item.js +25 -2
  98. package/src/components/overlays/nk-menu.js +86 -1
  99. package/src/components/overlays/nk-sheet.js +95 -0
  100. package/src/components/page/nk-avatar.js +55 -0
  101. package/src/components/page/nk-member-row.js +8 -5
  102. package/src/components/page/nk-page-cover.js +10 -10
  103. package/src/components/page/nk-page.js +10 -3
  104. package/src/components/page/nk-panel.js +59 -0
  105. package/src/components/page/nk-panels.js +16 -0
  106. package/src/components/page/nk-prop.js +52 -0
  107. package/src/components/page/nk-props.js +19 -0
  108. package/src/components/page/nk-segmented.js +19 -0
  109. package/src/components/page/nk-steps.js +59 -0
  110. package/src/components/shell/nk-sidebar.js +15 -36
  111. package/src/index.js +18 -0
  112. package/src/util/avatar.js +17 -0
  113. package/src/util/focus.js +11 -3
  114. package/src/util/property-cell.js +7 -3
  115. package/dist/components/shared/base-C3eJwHKA.js +0 -366
@@ -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
@@ -6,6 +6,12 @@
6
6
 
7
7
  export { NkElement, NkFormElement } from './base.js';
8
8
 
9
+ // The component sheet the elements adopt, for a project's own views: a view
10
+ // that adopts this instance shares it with every element instead of loading
11
+ // NotionKit's stylesheet a second time next to the bundle
12
+ // (NotionKitElements.componentsSheet from the <script> bundle).
13
+ export { componentsSheet } from '@jungherz-de/notionkit/notionkit-styles.js';
14
+
9
15
  // Wave 1 – forms
10
16
  export { NkBtn } from './components/forms/nk-btn.js';
11
17
  export { NkInput } from './components/forms/nk-input.js';
@@ -59,6 +65,7 @@ export { NkSegmented } from './components/page/nk-segmented.js';
59
65
  export { NkStats } from './components/page/nk-stats.js';
60
66
  export { NkStat } from './components/page/nk-stat.js';
61
67
  export { NkAvatarGroup } from './components/page/nk-avatar-group.js';
68
+ export { NkAvatar } from './components/page/nk-avatar.js';
62
69
  export { NkMention } from './components/page/nk-mention.js';
63
70
  export { NkTemplateBtn } from './components/page/nk-template-btn.js';
64
71
  export { NkModelCard } from './components/page/nk-model-card.js';
@@ -67,6 +74,16 @@ export { NkDangerZone } from './components/page/nk-danger-zone.js';
67
74
  export { NkMemberList } from './components/page/nk-member-list.js';
68
75
  export { NkMemberRow } from './components/page/nk-member-row.js';
69
76
 
77
+ // 1.6.0 – app views
78
+ export { NkProps } from './components/page/nk-props.js';
79
+ export { NkProp } from './components/page/nk-prop.js';
80
+ export { NkPanels } from './components/page/nk-panels.js';
81
+ export { NkPanel } from './components/page/nk-panel.js';
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
+
70
87
  // Wave 4 – overlays
71
88
  export { NkModal } from './components/overlays/nk-modal.js';
72
89
  export { NkSettingsPane } from './components/overlays/nk-settings-pane.js';
@@ -82,6 +99,7 @@ export { NkToast } from './components/overlays/nk-toast.js';
82
99
  export { NkDatabase } from './components/data/nk-database.js';
83
100
  export { NkTableView } from './components/data/nk-table-view.js';
84
101
  export { NkBoardView } from './components/data/nk-board-view.js';
102
+ export { NkListView } from './components/data/nk-list-view.js';
85
103
  export { NkFilterBar } from './components/data/nk-filter-bar.js';
86
104
  export { NkComments } from './components/data/nk-comments.js';
87
105
  export { NkComment } from './components/data/nk-comment.js';
@@ -0,0 +1,17 @@
1
+ // Shared by every element that draws an avatar: nk-avatar itself, member
2
+ // rows, comments and the person cells of a database view.
3
+ export const AVATAR_COLORS = ['gray', 'brown', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink', 'red'];
4
+
5
+ /**
6
+ * Paints an .nk-avatar. One of Notion's nine colour names becomes its class,
7
+ * so the tokens decide the shade in each theme; any other value – a hex, a
8
+ * gradient, a var() – is taken as an inline background, as before 1.6.0.
9
+ * Without a colour the avatar keeps the stylesheet's gradient.
10
+ */
11
+ export function paintAvatar(el, color) {
12
+ for (const c of AVATAR_COLORS) el.classList.toggle(c, c === color);
13
+ el.style.background = color && !AVATAR_COLORS.includes(color) ? color : '';
14
+ }
15
+
16
+ /** "Sara Lindt" → "SL". */
17
+ export const initialsOf = name => String(name || '').split(/\s+/).map(w => w[0]).filter(Boolean).join('').slice(0, 2).toUpperCase();
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"]';
@@ -5,6 +5,8 @@
5
5
  //
6
6
  // column: { key, label, type, icon, options: [{ value, label, color }], title }
7
7
  // types: text | select | multi-select | date | person | checkbox | url | number | progress
8
+ import { paintAvatar, initialsOf } from './avatar.js';
9
+
8
10
  const el = (tag, cls, text) => { const n = document.createElement(tag); if (cls) n.className = cls; if (text != null) n.textContent = text; return n; };
9
11
  const COLORS = ['gray', 'brown', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink', 'red'];
10
12
 
@@ -38,14 +40,16 @@ export function renderPropertyCell(column, value, row = {}) {
38
40
  case 'person': {
39
41
  const cell = el('span', 'person-cell');
40
42
  const p = typeof value === 'string' ? { name: value } : value;
41
- const avatar = el('span', 'mini-avatar', p.initials || p.avatar || (p.name || '').split(/\s+/).map(w => w[0]).join('').slice(0, 2).toUpperCase());
42
- avatar.style.background = p.color || 'var(--nk-text-tertiary)';
43
+ // color: one of Notion's nine names, or any CSS background; none – the avatar gradient.
44
+ const avatar = el('span', 'nk-avatar small', p.initials || p.avatar || initialsOf(p.name));
45
+ paintAvatar(avatar, p.color);
43
46
  cell.append(avatar, document.createTextNode(' ' + (p.name || '')));
44
47
  return cell;
45
48
  }
46
49
  case 'checkbox': return checkbox(column, !!value, row);
47
50
  case 'url': { const a = el('a', null, String(value).replace(/^https?:\/\//, '')); a.href = String(value); a.target = '_blank'; a.rel = 'noopener'; return a; }
48
- case 'number': return el('span', null, typeof value === 'number' ? value.toLocaleString() : String(value));
51
+ // column.locale / column.format: Intl.NumberFormat locale and options, e.g. { minimumFractionDigits: 1 }.
52
+ case 'number': return el('span', null, typeof value === 'number' ? value.toLocaleString(column.locale, column.format) : String(value));
49
53
  case 'progress': return progress(Number(value) || 0);
50
54
  default: {
51
55
  if (column.title) {