@nucel/ui 0.10.0 → 0.11.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.
@@ -0,0 +1,144 @@
1
+ import tippy, { type Instance, type Props as TippyProps } from 'tippy.js';
2
+
3
+ export type MentionItem = {
4
+ id: string;
5
+ label: string;
6
+ type?: 'user' | 'team';
7
+ slug?: string;
8
+ avatar_url?: string;
9
+ sublabel?: string;
10
+ };
11
+
12
+ function escapeHtml(text: string): string {
13
+ const div = document.createElement('div');
14
+ div.textContent = text;
15
+ return div.innerHTML;
16
+ }
17
+
18
+ function getInitials(name: string): string {
19
+ return name.split(' ').map(p => p.charAt(0)).join('').toUpperCase().slice(0, 2);
20
+ }
21
+
22
+ function createDropdown(props: { items: MentionItem[]; command: (item: MentionItem) => void }) {
23
+ const el = document.createElement('div');
24
+ el.className = 'mention-list';
25
+ let selectedIndex = 0;
26
+ let items = props.items;
27
+ let command = props.command;
28
+
29
+ function render() {
30
+ if (items.length === 0) {
31
+ el.innerHTML = `<div class="mention-list-empty">No results</div>`;
32
+ return;
33
+ }
34
+ if (items.length === 1 && (items[0] as any).type === 'hint') {
35
+ el.innerHTML = `<div class="mention-list-empty">${escapeHtml(items[0].label)}</div>`;
36
+ return;
37
+ }
38
+ el.innerHTML = items.map((item, i) => `
39
+ <button type="button" class="mention-list-item ${i === selectedIndex ? 'is-selected' : ''}" data-index="${i}">
40
+ ${item.avatar_url
41
+ ? `<img src="${escapeHtml(item.avatar_url)}" alt="" class="mention-avatar" />`
42
+ : `<span class="mention-avatar-fallback">${getInitials(item.label)}</span>`
43
+ }
44
+ <span class="mention-info">
45
+ <span class="mention-label">${escapeHtml(item.label)}</span>
46
+ ${item.sublabel ? `<span class="mention-sublabel">${escapeHtml(item.sublabel)}</span>` : ''}
47
+ </span>
48
+ ${item.type === 'team' ? `<span class="mention-badge">Team</span>` : ''}
49
+ </button>
50
+ `).join('');
51
+
52
+ el.querySelectorAll('.mention-list-item').forEach(btn => {
53
+ btn.addEventListener('click', () => {
54
+ const idx = parseInt((btn as HTMLElement).dataset.index ?? '0');
55
+ select(idx);
56
+ });
57
+ });
58
+ }
59
+
60
+ function select(idx: number) {
61
+ const item = items[idx];
62
+ if (item) command(item);
63
+ }
64
+
65
+ function updateSelection(idx: number) {
66
+ selectedIndex = ((idx % items.length) + items.length) % items.length;
67
+ render();
68
+ }
69
+
70
+ render();
71
+
72
+ return {
73
+ el,
74
+ update(newItems: MentionItem[], newCommand: (item: MentionItem) => void) {
75
+ items = newItems;
76
+ command = newCommand;
77
+ selectedIndex = 0;
78
+ render();
79
+ },
80
+ onKeyDown(key: string): boolean {
81
+ if (key === 'ArrowUp') { updateSelection(selectedIndex - 1); return true; }
82
+ if (key === 'ArrowDown') { updateSelection(selectedIndex + 1); return true; }
83
+ if (key === 'Enter') { select(selectedIndex); return true; }
84
+ return false;
85
+ },
86
+ };
87
+ }
88
+
89
+ export function createMentionSuggestion(mentionsUrl: string) {
90
+ return {
91
+ char: '@',
92
+ allowSpaces: false,
93
+ items: async ({ query }: { query: string }): Promise<MentionItem[]> => {
94
+ if (!query || query.length < 1) {
95
+ return [{ id: 'hint', label: 'Type to search users…', type: 'user' } as any];
96
+ }
97
+ try {
98
+ const sep = mentionsUrl.includes('?') ? '&' : '?';
99
+ const res = await fetch(`${mentionsUrl}${sep}query=${encodeURIComponent(query)}`, {
100
+ headers: { Accept: 'application/json' },
101
+ });
102
+ if (!res.ok) return [];
103
+ const data = await res.json();
104
+ return Array.isArray(data.suggestions) ? data.suggestions : [];
105
+ } catch {
106
+ return [];
107
+ }
108
+ },
109
+ render: () => {
110
+ let dropdown: ReturnType<typeof createDropdown>;
111
+ let popup: Instance<TippyProps>[];
112
+
113
+ return {
114
+ onStart(props: any) {
115
+ dropdown = createDropdown({ items: props.items, command: (item) => props.command({ id: item.id, label: item.label, type: item.type, slug: item.slug }) });
116
+ if (!props.clientRect) return;
117
+ popup = tippy('body', {
118
+ getReferenceClientRect: props.clientRect,
119
+ appendTo: () => document.body,
120
+ content: dropdown.el,
121
+ showOnCreate: true,
122
+ interactive: true,
123
+ trigger: 'manual',
124
+ placement: 'bottom-start',
125
+ }) as Instance<TippyProps>[];
126
+ },
127
+ onUpdate(props: any) {
128
+ dropdown.update(props.items, (item) => props.command({ id: item.id, label: item.label, type: item.type, slug: item.slug }));
129
+ if (props.clientRect && popup?.[0]) {
130
+ popup[0].setProps({ getReferenceClientRect: props.clientRect });
131
+ }
132
+ },
133
+ onKeyDown(props: any) {
134
+ if (props.event.key === 'Escape') { popup?.[0]?.hide(); return true; }
135
+ return dropdown.onKeyDown(props.event.key);
136
+ },
137
+ onExit() {
138
+ popup?.[0]?.destroy();
139
+ dropdown.el.remove();
140
+ },
141
+ };
142
+ },
143
+ };
144
+ }
@@ -0,0 +1,12 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import { cn } from '../../../utils/cn.js';
4
+
5
+ let { children, class: className }: { children: Snippet; class?: string } = $props();
6
+ </script>
7
+
8
+ <div class={cn("w-full overflow-auto", className)}>
9
+ <table class="w-full caption-bottom text-sm">
10
+ {@render children()}
11
+ </table>
12
+ </div>
@@ -0,0 +1,10 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import { cn } from '../../../utils/cn.js';
4
+
5
+ let { children, class: className }: { children: Snippet; class?: string } = $props();
6
+ </script>
7
+
8
+ <tbody class={cn("[&_tr:last-child]:border-0", className)}>
9
+ {@render children()}
10
+ </tbody>
@@ -0,0 +1,10 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import { cn } from '../../../utils/cn.js';
4
+
5
+ let { children, class: className }: { children: Snippet; class?: string } = $props();
6
+ </script>
7
+
8
+ <caption class={cn("mt-4 text-xs text-muted-foreground", className)}>
9
+ {@render children()}
10
+ </caption>
@@ -0,0 +1,10 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import { cn } from '../../../utils/cn.js';
4
+
5
+ let { children, class: className, ...rest }: { children?: Snippet; class?: string; [key: string]: unknown } = $props();
6
+ </script>
7
+
8
+ <td class={cn("px-4 py-2.5 align-middle [&:has([role=checkbox])]:pr-0", className)} {...rest}>
9
+ {@render children?.()}
10
+ </td>
@@ -0,0 +1,10 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import { cn } from '../../../utils/cn.js';
4
+
5
+ let { children, class: className, ...rest }: { children?: Snippet; class?: string; [key: string]: unknown } = $props();
6
+ </script>
7
+
8
+ <th class={cn("h-9 px-4 text-left align-middle text-[10px] font-semibold uppercase tracking-wide text-muted-foreground [&:has([role=checkbox])]:pr-0", className)} {...rest}>
9
+ {@render children?.()}
10
+ </th>
@@ -0,0 +1,10 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import { cn } from '../../../utils/cn.js';
4
+
5
+ let { children, class: className }: { children: Snippet; class?: string } = $props();
6
+ </script>
7
+
8
+ <thead class={cn("[&_tr]:border-b [&_tr]:border-border", className)}>
9
+ {@render children()}
10
+ </thead>
@@ -0,0 +1,10 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import { cn } from '../../../utils/cn.js';
4
+
5
+ let { children, class: className }: { children: Snippet; class?: string } = $props();
6
+ </script>
7
+
8
+ <tr class={cn("border-b border-border transition-colors hover:bg-accent/50 data-[state=selected]:bg-accent", className)}>
9
+ {@render children()}
10
+ </tr>
@@ -0,0 +1,7 @@
1
+ export { default as Table } from './Table.svelte';
2
+ export { default as TableHeader } from './TableHeader.svelte';
3
+ export { default as TableBody } from './TableBody.svelte';
4
+ export { default as TableRow } from './TableRow.svelte';
5
+ export { default as TableHead } from './TableHead.svelte';
6
+ export { default as TableCell } from './TableCell.svelte';
7
+ export { default as TableCaption } from './TableCaption.svelte';
package/src/lib/index.ts CHANGED
@@ -376,3 +376,53 @@ export {
376
376
  // ColorInput — styled native <input type="color"> wrapper matching the
377
377
  // form-control border/ring/focus tokens. Optional `showValue` hex readout.
378
378
  export { default as ColorInput } from './components/ColorInput.svelte';
379
+
380
+ // ---- 0.11.0 additions (restored components) ----
381
+ //
382
+ // These components were part of the export surface in earlier releases but
383
+ // were dropped from the 0.10.0 barrel. The nucel app still imports them, so a
384
+ // clean `bun install --frozen-lockfile` against 0.10.0 broke the build. They
385
+ // are restored here against the package's shared-component conventions.
386
+
387
+ // Alert — inline notice banner (info/success/warning/error variants).
388
+ export { default as Alert } from './components/ui/Alert.svelte';
389
+
390
+ // Section + SectionTitle — page section wrapper + heading.
391
+ export { default as Section } from './components/ui/Section.svelte';
392
+ export { default as SectionTitle } from './components/ui/SectionTitle.svelte';
393
+
394
+ // PageHeader — page title + actions header row.
395
+ export { default as PageHeader } from './components/ui/PageHeader.svelte';
396
+
397
+ // ListCard — bordered list-item card row.
398
+ export { default as ListCard } from './components/ui/ListCard.svelte';
399
+
400
+ // Pills — compact status/branch/comment chips.
401
+ export { default as StatusPill } from './components/ui/StatusPill.svelte';
402
+ export { default as BranchPill } from './components/ui/BranchPill.svelte';
403
+ export { default as CommentPill } from './components/ui/CommentPill.svelte';
404
+
405
+ // PermissionChips — permission/scope chip group.
406
+ export { default as PermissionChips } from './components/ui/PermissionChips.svelte';
407
+
408
+ // AppCard — app/repo summary card.
409
+ export { default as AppCard } from './components/ui/AppCard.svelte';
410
+
411
+ // Kanban — board / column / card composites.
412
+ export { default as KanbanBoard } from './components/ui/KanbanBoard.svelte';
413
+ export { default as KanbanColumn } from './components/ui/KanbanColumn.svelte';
414
+ export { default as KanbanCard } from './components/ui/KanbanCard.svelte';
415
+
416
+ // RichEditor — Tiptap-powered rich text editor (wiki/issues/PR comments).
417
+ export { default as RichEditor } from './components/ui/editor/RichEditor.svelte';
418
+
419
+ // Table — shadcn-styled table primitives.
420
+ export {
421
+ Table,
422
+ TableHeader,
423
+ TableBody,
424
+ TableRow,
425
+ TableHead,
426
+ TableCell,
427
+ TableCaption,
428
+ } from './components/ui/table/index.js';