@jungherz-de/notionkit-elements 1.0.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/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/components/nk-ai-input-row.js +57 -0
- package/dist/components/nk-ai-msg.js +67 -0
- package/dist/components/nk-ai-thread.js +14 -0
- package/dist/components/nk-app.js +23 -0
- package/dist/components/nk-avatar-group.js +35 -0
- package/dist/components/nk-banner.js +30 -0
- package/dist/components/nk-block-host.js +35 -0
- package/dist/components/nk-board-view.js +129 -0
- package/dist/components/nk-breadcrumb.js +78 -0
- package/dist/components/nk-btn.js +107 -0
- package/dist/components/nk-callout.js +36 -0
- package/dist/components/nk-check.js +77 -0
- package/dist/components/nk-cmdk.js +221 -0
- package/dist/components/nk-code.js +66 -0
- package/dist/components/nk-comment.js +41 -0
- package/dist/components/nk-comments.js +57 -0
- package/dist/components/nk-danger-zone.js +27 -0
- package/dist/components/nk-database.js +100 -0
- package/dist/components/nk-divider.js +12 -0
- package/dist/components/nk-emoji-picker.js +112 -0
- package/dist/components/nk-empty.js +36 -0
- package/dist/components/nk-field.js +50 -0
- package/dist/components/nk-filter-bar.js +78 -0
- package/dist/components/nk-heading.js +29 -0
- package/dist/components/nk-input.js +108 -0
- package/dist/components/nk-kbd.js +15 -0
- package/dist/components/nk-member-list.js +30 -0
- package/dist/components/nk-member-row.js +46 -0
- package/dist/components/nk-mention.js +31 -0
- package/dist/components/nk-menu-item.js +68 -0
- package/dist/components/nk-menu.js +45 -0
- package/dist/components/nk-modal.js +166 -0
- package/dist/components/nk-model-card.js +89 -0
- package/dist/components/nk-page-actions.js +15 -0
- package/dist/components/nk-page-cover.js +35 -0
- package/dist/components/nk-page-title.js +71 -0
- package/dist/components/nk-page.js +71 -0
- package/dist/components/nk-pop.js +90 -0
- package/dist/components/nk-profile-row.js +25 -0
- package/dist/components/nk-progress.js +43 -0
- package/dist/components/nk-quote.js +32 -0
- package/dist/components/nk-radio.js +160 -0
- package/dist/components/nk-section-label.js +42 -0
- package/dist/components/nk-segmented.js +99 -0
- package/dist/components/nk-select.js +127 -0
- package/dist/components/nk-settings-pane.js +40 -0
- package/dist/components/nk-settings-user.js +36 -0
- package/dist/components/nk-sidebar.js +81 -0
- package/dist/components/nk-skeleton.js +31 -0
- package/dist/components/nk-slider.js +85 -0
- package/dist/components/nk-stat.js +40 -0
- package/dist/components/nk-stats.js +14 -0
- package/dist/components/nk-switch.js +69 -0
- package/dist/components/nk-synced.js +26 -0
- package/dist/components/nk-tab.js +54 -0
- package/dist/components/nk-table-view.js +109 -0
- package/dist/components/nk-tabs.js +82 -0
- package/dist/components/nk-tag.js +32 -0
- package/dist/components/nk-template-btn.js +43 -0
- package/dist/components/nk-textarea.js +95 -0
- package/dist/components/nk-theme-toggle.js +67 -0
- package/dist/components/nk-toast.js +51 -0
- package/dist/components/nk-todo.js +73 -0
- package/dist/components/nk-toggle.js +56 -0
- package/dist/components/nk-topbar.js +24 -0
- package/dist/components/nk-tree-item.js +155 -0
- package/dist/components/nk-tree.js +123 -0
- package/dist/components/nk-workspace-switcher.js +82 -0
- package/dist/components/shared/base-6gEcoatG.js +317 -0
- package/dist/components/shared/focus-DXrK9oLe.js +47 -0
- package/dist/components/shared/property-cell-Dn91uFkf.js +92 -0
- package/dist/notionkit-elements.esm.js +4639 -0
- package/dist/notionkit-elements.js +4718 -0
- package/dist/notionkit-elements.min.js +1 -0
- package/package.json +72 -0
- package/src/base.js +296 -0
- package/src/components/content/nk-callout.js +35 -0
- package/src/components/content/nk-code.js +51 -0
- package/src/components/content/nk-divider.js +11 -0
- package/src/components/content/nk-heading.js +28 -0
- package/src/components/content/nk-kbd.js +14 -0
- package/src/components/content/nk-progress.js +42 -0
- package/src/components/content/nk-quote.js +31 -0
- package/src/components/content/nk-tag.js +31 -0
- package/src/components/content/nk-todo.js +72 -0
- package/src/components/content/nk-toggle.js +55 -0
- package/src/components/data/nk-ai-input-row.js +56 -0
- package/src/components/data/nk-ai-msg.js +66 -0
- package/src/components/data/nk-ai-thread.js +13 -0
- package/src/components/data/nk-board-view.js +128 -0
- package/src/components/data/nk-comment.js +40 -0
- package/src/components/data/nk-comments.js +56 -0
- package/src/components/data/nk-database.js +99 -0
- package/src/components/data/nk-filter-bar.js +77 -0
- package/src/components/data/nk-table-view.js +108 -0
- package/src/components/forms/nk-btn.js +106 -0
- package/src/components/forms/nk-check.js +76 -0
- package/src/components/forms/nk-field.js +49 -0
- package/src/components/forms/nk-input.js +107 -0
- package/src/components/forms/nk-radio.js +159 -0
- package/src/components/forms/nk-select.js +126 -0
- package/src/components/forms/nk-slider.js +84 -0
- package/src/components/forms/nk-switch.js +68 -0
- package/src/components/forms/nk-textarea.js +94 -0
- package/src/components/overlays/nk-cmdk.js +201 -0
- package/src/components/overlays/nk-emoji-picker.js +94 -0
- package/src/components/overlays/nk-menu-item.js +67 -0
- package/src/components/overlays/nk-menu.js +44 -0
- package/src/components/overlays/nk-modal.js +165 -0
- package/src/components/overlays/nk-pop.js +89 -0
- package/src/components/overlays/nk-settings-pane.js +39 -0
- package/src/components/overlays/nk-settings-user.js +35 -0
- package/src/components/overlays/nk-toast.js +50 -0
- package/src/components/page/nk-avatar-group.js +34 -0
- package/src/components/page/nk-banner.js +29 -0
- package/src/components/page/nk-block-host.js +34 -0
- package/src/components/page/nk-danger-zone.js +26 -0
- package/src/components/page/nk-empty.js +35 -0
- package/src/components/page/nk-member-list.js +29 -0
- package/src/components/page/nk-member-row.js +45 -0
- package/src/components/page/nk-mention.js +30 -0
- package/src/components/page/nk-model-card.js +88 -0
- package/src/components/page/nk-page-actions.js +14 -0
- package/src/components/page/nk-page-cover.js +34 -0
- package/src/components/page/nk-page-title.js +70 -0
- package/src/components/page/nk-page.js +70 -0
- package/src/components/page/nk-profile-row.js +24 -0
- package/src/components/page/nk-segmented.js +98 -0
- package/src/components/page/nk-skeleton.js +30 -0
- package/src/components/page/nk-stat.js +39 -0
- package/src/components/page/nk-stats.js +13 -0
- package/src/components/page/nk-synced.js +25 -0
- package/src/components/page/nk-tab.js +53 -0
- package/src/components/page/nk-tabs.js +81 -0
- package/src/components/page/nk-template-btn.js +42 -0
- package/src/components/shell/nk-app.js +22 -0
- package/src/components/shell/nk-breadcrumb.js +77 -0
- package/src/components/shell/nk-section-label.js +41 -0
- package/src/components/shell/nk-sidebar.js +80 -0
- package/src/components/shell/nk-theme-toggle.js +66 -0
- package/src/components/shell/nk-topbar.js +23 -0
- package/src/components/shell/nk-tree-item.js +154 -0
- package/src/components/shell/nk-tree.js +122 -0
- package/src/components/shell/nk-workspace-switcher.js +81 -0
- package/src/index.js +88 -0
- package/src/util/emoji.js +17 -0
- package/src/util/focus.js +45 -0
- package/src/util/fuzzy.js +19 -0
- package/src/util/highlight.js +14 -0
- package/src/util/property-cell.js +90 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Polymorphic property renderer for database views. Returns plain DOM built
|
|
2
|
+
// from NotionKit classes – deliberately not a custom element: every cell rule
|
|
3
|
+
// starts with `.nk-table`, so a cell inside its own shadow root would never
|
|
4
|
+
// be styled. Exported for consumers who render tables themselves.
|
|
5
|
+
//
|
|
6
|
+
// column: { key, label, type, icon, options: [{ value, label, color }], title }
|
|
7
|
+
// types: text | select | multi-select | date | person | checkbox | url | number | progress
|
|
8
|
+
const el = (tag, cls, text) => { const n = document.createElement(tag); if (cls) n.className = cls; if (text != null) n.textContent = text; return n; };
|
|
9
|
+
const COLORS = ['blue', 'green', 'orange', 'purple'];
|
|
10
|
+
|
|
11
|
+
function optionFor(column, value) {
|
|
12
|
+
const opts = column.options || [];
|
|
13
|
+
return opts.find(o => o.value === value) || opts.find(o => o.label === value) || null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function tagFor(column, value) {
|
|
17
|
+
const opt = optionFor(column, value);
|
|
18
|
+
const color = opt?.color && COLORS.includes(opt.color) ? opt.color : 'blue';
|
|
19
|
+
return el('span', `nk-tag ${color}`, opt?.label ?? String(value));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function renderPropertyCell(column, value, row = {}) {
|
|
23
|
+
const type = column.type || 'text';
|
|
24
|
+
if (value === undefined || value === null || value === '') {
|
|
25
|
+
if (type === 'checkbox') return checkbox(column, false, row);
|
|
26
|
+
if (type === 'progress') return progress(0);
|
|
27
|
+
return el('span', type === 'person' ? 'person-cell' : null, type === 'text' && column.title ? '' : '—');
|
|
28
|
+
}
|
|
29
|
+
switch (type) {
|
|
30
|
+
case 'select': return tagFor(column, value);
|
|
31
|
+
case 'multi-select': {
|
|
32
|
+
const wrap = el('span');
|
|
33
|
+
wrap.style.display = 'inline-flex'; wrap.style.gap = '4px'; wrap.style.flexWrap = 'wrap';
|
|
34
|
+
for (const v of Array.isArray(value) ? value : String(value).split(',').map(s => s.trim()).filter(Boolean)) wrap.appendChild(tagFor(column, v));
|
|
35
|
+
return wrap;
|
|
36
|
+
}
|
|
37
|
+
case 'date': return el('span', 'date-cell', String(value));
|
|
38
|
+
case 'person': {
|
|
39
|
+
const cell = el('span', 'person-cell');
|
|
40
|
+
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
|
+
cell.append(avatar, document.createTextNode(' ' + (p.name || '')));
|
|
44
|
+
return cell;
|
|
45
|
+
}
|
|
46
|
+
case 'checkbox': return checkbox(column, !!value, row);
|
|
47
|
+
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));
|
|
49
|
+
case 'progress': return progress(Number(value) || 0);
|
|
50
|
+
default: {
|
|
51
|
+
if (column.title) {
|
|
52
|
+
const t = el('span', 'row-title');
|
|
53
|
+
if (row.icon) t.append(document.createTextNode(row.icon + ' '));
|
|
54
|
+
t.append(document.createTextNode(String(value)));
|
|
55
|
+
return t;
|
|
56
|
+
}
|
|
57
|
+
return el('span', null, String(value));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function checkbox(column, checked, row) {
|
|
63
|
+
const label = el('label', 'nk-check');
|
|
64
|
+
const input = el('input');
|
|
65
|
+
input.type = 'checkbox'; input.checked = checked;
|
|
66
|
+
input.dataset.key = column.key;
|
|
67
|
+
if (row.id != null) input.dataset.rowId = row.id;
|
|
68
|
+
label.appendChild(input);
|
|
69
|
+
return label;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function progress(value) {
|
|
73
|
+
const frag = document.createDocumentFragment();
|
|
74
|
+
const bar = el('span', 'nk-progress');
|
|
75
|
+
const fill = el('i'); fill.style.width = `${Math.max(0, Math.min(100, value))}%`;
|
|
76
|
+
bar.appendChild(fill);
|
|
77
|
+
frag.append(bar, el('span', 'nk-progress-label', `${Math.round(value)}%`));
|
|
78
|
+
return frag;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Sort comparator for a column type. */
|
|
82
|
+
function compareBy(column, dir = 1) {
|
|
83
|
+
const type = column.type || 'text';
|
|
84
|
+
return (a, b) => {
|
|
85
|
+
let x = a[column.key], y = b[column.key];
|
|
86
|
+
if (type === 'person') { x = x?.name ?? x ?? ''; y = y?.name ?? y ?? ''; }
|
|
87
|
+
if (type === 'number' || type === 'progress' || type === 'checkbox') return ((Number(x) || 0) - (Number(y) || 0)) * dir;
|
|
88
|
+
return String(x ?? '').localeCompare(String(y ?? ''), undefined, { numeric: true }) * dir;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { compareBy as c, renderPropertyCell as r, tagFor as t };
|