@jungherz-de/notionkit-elements 1.16.0 → 1.17.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 (61) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +64 -6
  3. package/SKILL.md +59 -53
  4. package/dist/components/base.js +102 -3
  5. package/dist/components/nk-ai-input-row.js +6 -3
  6. package/dist/components/nk-board-view.js +2 -2
  7. package/dist/components/nk-breadcrumb.js +2 -1
  8. package/dist/components/nk-calendar-view.js +8 -5
  9. package/dist/components/nk-calendar.js +10 -7
  10. package/dist/components/nk-cmdk.js +6 -2
  11. package/dist/components/nk-comments.js +5 -3
  12. package/dist/components/nk-copy-field.js +6 -3
  13. package/dist/components/nk-emoji-picker.js +6 -2
  14. package/dist/components/nk-filter-bar.js +10 -8
  15. package/dist/components/nk-gallery-view.js +29 -7
  16. package/dist/components/nk-image-picker.js +7 -3
  17. package/dist/components/nk-list-view.js +3 -2
  18. package/dist/components/nk-modal.js +3 -1
  19. package/dist/components/nk-page-title.js +2 -1
  20. package/dist/components/nk-page.js +3 -1
  21. package/dist/components/nk-peek.js +6 -3
  22. package/dist/components/nk-sidebar.js +5 -2
  23. package/dist/components/nk-steps.js +20 -4
  24. package/dist/components/nk-synced.js +2 -1
  25. package/dist/components/nk-table-view.js +3 -2
  26. package/dist/components/nk-theme-toggle.js +5 -2
  27. package/dist/components/nk-tree-item.js +3 -1
  28. package/dist/components/shared/{property-cell-BSVcETss.js → property-cell-DcsfnUNF.js} +15 -5
  29. package/dist/notionkit-elements.esm.js +265 -70
  30. package/dist/notionkit-elements.esm.min.js +1 -1
  31. package/dist/notionkit-elements.esm.min.js.map +1 -1
  32. package/dist/notionkit-elements.js +267 -69
  33. package/dist/notionkit-elements.min.js +1 -1
  34. package/package.json +3 -3
  35. package/src/base.js +32 -2
  36. package/src/components/data/nk-ai-input-row.js +6 -3
  37. package/src/components/data/nk-board-view.js +2 -2
  38. package/src/components/data/nk-calendar-view.js +7 -4
  39. package/src/components/data/nk-comments.js +5 -3
  40. package/src/components/data/nk-filter-bar.js +10 -8
  41. package/src/components/data/nk-gallery-view.js +29 -7
  42. package/src/components/data/nk-list-view.js +2 -1
  43. package/src/components/data/nk-table-view.js +2 -1
  44. package/src/components/forms/nk-calendar.js +10 -7
  45. package/src/components/forms/nk-copy-field.js +6 -3
  46. package/src/components/forms/nk-image-picker.js +7 -3
  47. package/src/components/overlays/nk-cmdk.js +6 -2
  48. package/src/components/overlays/nk-emoji-picker.js +6 -2
  49. package/src/components/overlays/nk-modal.js +3 -1
  50. package/src/components/overlays/nk-peek.js +6 -3
  51. package/src/components/page/nk-page-title.js +2 -1
  52. package/src/components/page/nk-page.js +3 -1
  53. package/src/components/page/nk-steps.js +20 -4
  54. package/src/components/page/nk-synced.js +2 -1
  55. package/src/components/shell/nk-breadcrumb.js +2 -1
  56. package/src/components/shell/nk-sidebar.js +5 -2
  57. package/src/components/shell/nk-theme-toggle.js +5 -2
  58. package/src/components/shell/nk-tree-item.js +3 -1
  59. package/src/index.js +5 -1
  60. package/src/util/property-cell.js +14 -4
  61. package/src/util/strings.js +73 -0
@@ -18,6 +18,12 @@ import '@jungherz-de/notionkit/notionkit-styles.js';
18
18
  // nk-select { index, value, step } – index counts from 1, like `current` –
19
19
  // and, unless cancelled, makes that step current. `horizontal` sets the
20
20
  // steps in one row above a wizard.
21
+ // A step with `href` (1.17.0) shows its label as a link, <a class="st-label">,
22
+ // with or without `selectable` – to open a chapter in a new tab or copy its
23
+ // address. A plain click, or Enter, fires the same nk-select; cancelling it
24
+ // keeps the browser from following the link, for a router of your own. A
25
+ // middle click or one with Cmd, Ctrl, Shift or Alt fires nothing and does
26
+ // what a link does.
21
27
  class NkSteps extends NkElement {
22
28
  static get observedAttributes() { return ['steps', 'current', 'label', 'selectable', 'horizontal']; }
23
29
 
@@ -45,7 +51,7 @@ class NkSteps extends NkElement {
45
51
  // Rebuilding drops the focused label; the new one at that place takes it back.
46
52
  const focused = this.shadowRoot?.activeElement?.closest?.('li')?.dataset.index;
47
53
  this._list.replaceChildren(...this._items().map((_, i) => {
48
- const n = i + 1, { label: text, desc, state } = this._step(i);
54
+ const n = i + 1, { label: text, desc, state, href } = this._step(i);
49
55
  // A state of its own wins; without one, the steps before `current` are done.
50
56
  const done = state ? state === 'done' : n < current, skipped = state === 'skipped';
51
57
  const li = this.createElement('li', ['nk-step'], { 'data-index': String(n) });
@@ -55,7 +61,8 @@ class NkSteps extends NkElement {
55
61
  if (n === current) li.setAttribute('aria-current', 'step');
56
62
  const mark = this.createElement('span', ['st-mark'], { 'aria-hidden': 'true' });
57
63
  mark.textContent = done ? '✓' : skipped ? '–' : String(n);
58
- const body = selectable ? this.createElement('button', ['st-label'], { type: 'button' }) : document.createElement('span');
64
+ const body = href != null && href !== '' ? this.createElement('a', ['st-label'], { href: String(href) })
65
+ : selectable ? this.createElement('button', ['st-label'], { type: 'button' }) : document.createElement('span');
59
66
  body.textContent = text ?? '';
60
67
  if (desc) { const d = this.createElement('span', ['st-desc']); d.textContent = desc; body.appendChild(d); }
61
68
  li.append(mark, body);
@@ -66,9 +73,18 @@ class NkSteps extends NkElement {
66
73
 
67
74
  setupEvents() {
68
75
  this._onClick = (e) => {
69
- if (!this.getBoolAttr('selectable')) return;
70
76
  const li = e.target.closest?.('li.nk-step');
71
- if (li && this._list.contains(li)) this.select(Number(li.dataset.index));
77
+ if (!li || !this._list.contains(li)) return;
78
+ const link = li.querySelector('a.st-label');
79
+ if (link) {
80
+ // The link contract: a plain left click is a selection, any other
81
+ // one the browser's. The mark beside the link counts as the link.
82
+ if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
83
+ if (!link.contains(e.target)) { link.click(); return; }
84
+ if (!this.select(Number(li.dataset.index))) e.preventDefault();
85
+ return;
86
+ }
87
+ if (this.getBoolAttr('selectable')) this.select(Number(li.dataset.index));
72
88
  };
73
89
  this._list.addEventListener('click', this._onClick);
74
90
  }
@@ -15,8 +15,9 @@ class NkSynced extends NkElement {
15
15
  this._sync();
16
16
  }
17
17
 
18
- _sync() { this._badge.textContent = this.getAttribute('badge') ?? '⟳ synced'; }
18
+ _sync() { this._badge.textContent = this.getAttribute('badge') ?? this.str('synced'); }
19
19
  onAttributeChanged() { this._sync(); }
20
+ onStringsChanged() { this._sync(); }
20
21
 
21
22
  get badge() { return this.getAttribute('badge'); }
22
23
  set badge(v) { this.setAttribute('badge', v); }
@@ -1,5 +1,5 @@
1
1
  import { NkElement } from './base.js';
2
- import { c as compareBy, r as renderPropertyCell } from './shared/property-cell-BSVcETss.js';
2
+ import { c as compareBy, r as renderPropertyCell } from './shared/property-cell-DcsfnUNF.js';
3
3
  import '@jungherz-de/notionkit/notionkit-styles.js';
4
4
  import './shared/avatar-CzPZN3uP.js';
5
5
  import './shared/dates-a32DcW1l.js';
@@ -66,7 +66,7 @@ class NkTableView extends NkElement {
66
66
  }
67
67
  this._tbody.appendChild(r);
68
68
  }
69
- this._newRow.textContent = this.getAttribute('new-row-label') || '+ New page';
69
+ this._newRow.textContent = this.getAttribute('new-row-label') || this.str('newPage');
70
70
  this._newRow.style.display = this.getBoolAttr('new-row') ? '' : 'none';
71
71
  }
72
72
 
@@ -116,6 +116,7 @@ class NkTableView extends NkElement {
116
116
 
117
117
  _rowById(id) { return this._rows.find(r => String(r.id) === String(id)); }
118
118
  onAttributeChanged() { this._render(); }
119
+ onStringsChanged() { this._render(); }
119
120
 
120
121
  get name() { return this.getAttribute('name') || 'table'; }
121
122
  get columns() { return this._columns; }
@@ -15,7 +15,7 @@ class NkThemeToggle extends NkElement {
15
15
 
16
16
  render() {
17
17
  this._btn = this.createElement('button', ['nk-topbar-btn', 'nk-theme-toggle'], { type: 'button' });
18
- this._btn.title = this.getAttribute('title') || 'Toggle light / dark';
18
+ this._syncTitle();
19
19
  this._wrapper.appendChild(this._btn);
20
20
  const root = document.documentElement;
21
21
  let stored = null;
@@ -46,8 +46,11 @@ class NkThemeToggle extends NkElement {
46
46
  window.removeEventListener('message', this._onMessage);
47
47
  }
48
48
 
49
+ _syncTitle() { this._btn.title = this.getAttribute('title') || this.str('toggleTheme'); }
50
+ onStringsChanged() { this._syncTitle(); }
51
+
49
52
  onAttributeChanged(name) {
50
- if (name === 'title' && this._btn) this._btn.title = this.getAttribute('title') || 'Toggle light / dark';
53
+ if (name === 'title' && this._btn) this._syncTitle();
51
54
  }
52
55
 
53
56
  /** Sets the theme on <html>, persists it and reports it. */
@@ -34,7 +34,7 @@ class NkTreeItem extends NkElement {
34
34
  this._labelSlot.appendChild(this._labelText);
35
35
  this._label.appendChild(this._labelSlot);
36
36
  this._actions = this.createElement('span', ['actions']);
37
- for (const [action, glyph, title] of [['add', '+', 'Add'], ['more', '⋯', 'More']]) {
37
+ for (const [action, glyph, title] of [['add', '+', this.str('add')], ['more', '⋯', this.str('more')]]) {
38
38
  const b = this.createElement('span', [], { 'data-action': action, role: 'button', title });
39
39
  b.textContent = glyph;
40
40
  this._actions.appendChild(b);
@@ -120,6 +120,8 @@ class NkTreeItem extends NkElement {
120
120
  this._row?.removeEventListener('keydown', this._onKey);
121
121
  }
122
122
 
123
+ onStringsChanged() { for (const b of this._actions.children) b.title = this.str(b.dataset.action); }
124
+
123
125
  onAttributeChanged(name) {
124
126
  if (name === 'label') this.assignSlots();
125
127
  else this._sync();
@@ -16,6 +16,8 @@ import { r as resolveLocale } from './dates-a32DcW1l.js';
16
16
  // text: a string, or { text, desc, color, tooltip, sort } – one of Notion's
17
17
  // nine text colours for a tone, a quiet second line under it, the whole
18
18
  // text in a tooltip (served by <nk-tooltip>), a value to sort by.
19
+ // progress: 0–100, the bar and its percentage as Intl writes it in
20
+ // column.locale, else the page's language ("45 %" in German).
19
21
  // date: the value as given, or with column.format ('short', 'relative' or
20
22
  // Intl.DateTimeFormat options) and column.locale formatted from an ISO date
21
23
  // or date-time, D.M.YYYY, a Date or a timestamp; { start, end } is a range.
@@ -81,7 +83,7 @@ function renderPropertyCell(column, value, row = {}) {
81
83
  if (type === 'actions') return actions(column, value);
82
84
  if (value === undefined || value === null || value === '') {
83
85
  if (type === 'checkbox') return checkbox(column, false, row);
84
- if (type === 'progress') return progress(0);
86
+ if (type === 'progress') return progress(column, 0);
85
87
  return el('span', type === 'person' ? 'person-cell' : null, type === 'text' && column.title ? '' : '—');
86
88
  }
87
89
  switch (type) {
@@ -113,7 +115,7 @@ function renderPropertyCell(column, value, row = {}) {
113
115
  }
114
116
  // column.locale / column.format: Intl.NumberFormat locale and options, e.g. { minimumFractionDigits: 1 }.
115
117
  case 'number': return el('span', null, typeof value === 'number' ? value.toLocaleString(column.locale, column.format) : String(value));
116
- case 'progress': return progress(Number(value) || 0);
118
+ case 'progress': return progress(column, Number(value) || 0);
117
119
  default: {
118
120
  const o = typeof value === 'object' ? value : { text: value };
119
121
  let t;
@@ -159,15 +161,23 @@ function checkbox(column, checked, row) {
159
161
  return label;
160
162
  }
161
163
 
162
- function progress(value) {
164
+ function progress(column, value) {
163
165
  const frag = document.createDocumentFragment();
164
166
  const bar = el('span', 'nk-progress');
165
167
  const fill = el('i'); fill.style.width = `${Math.max(0, Math.min(100, value))}%`;
166
168
  bar.appendChild(fill);
167
- frag.append(bar, el('span', 'nk-progress-label', `${Math.round(value)}%`));
169
+ frag.append(bar, el('span', 'nk-progress-label', formatPercent(column, value)));
168
170
  return frag;
169
171
  }
170
172
 
173
+ /** A progress value of 0–100 as Intl writes a percentage in column.locale, else the page's language: 45 → "45%", in German "45 %". */
174
+ function formatPercent(column, value) {
175
+ const n = Number(value) || 0;
176
+ try {
177
+ return new Intl.NumberFormat(column.locale || resolveLocale(), { style: 'percent', maximumFractionDigits: 0 }).format(n / 100);
178
+ } catch { return `${Math.round(n)}%`; } // a lang Intl does not take
179
+ }
180
+
171
181
  /** A select's place among its options: the order Notion sorts by. */
172
182
  function rankOf(column, value) {
173
183
  const i = (column.options || []).findIndex(o => o.value === value || o.label === value);
@@ -201,4 +211,4 @@ function compareBy(column, dir = 1) {
201
211
  };
202
212
  }
203
213
 
204
- export { textOf as a, compareBy as c, formatDate as f, renderPropertyCell as r, tagFor as t };
214
+ export { textOf as a, formatDate as b, compareBy as c, formatPercent as f, renderPropertyCell as r, tagFor as t };