@cossackframework/cms 0.9.1 → 0.9.2

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.
@@ -2,6 +2,7 @@
2
2
  // states them in src/dashboard.config.ts. The CMS always has email and password (with passkeys
3
3
  // and sign-in links, which its auth.ts adds) and every account screen; the OAuth providers are
4
4
  // the site's `oauth` option in src/cms.config.ts.
5
+ import type { DashboardNavigationItem } from './dashboard/types';
5
6
  import { currentCms } from './cms/index';
6
7
 
7
8
  function providers(): string[] {
@@ -15,4 +16,6 @@ export const authOptions = {
15
16
  modules: ['users', 'sessions', 'settings', 'roles'],
16
17
  dashboard: true,
17
18
  redirectAfterLogin: '/dashboard',
19
+ /** The CMS's screens come from its own navigation and its plugins, not from this list. */
20
+ navigation: [] as DashboardNavigationItem[],
18
21
  };
@@ -634,7 +634,8 @@ html:lang(ar), html:lang(he), html:lang(fa), html:lang(ur), html:lang(ps), html:
634
634
  /* The lightbox (cms/lightbox.client.ts): one dialog over the page for a gallery's image or a video. */
635
635
  .cms-lightbox { position: fixed; inset: 0; width: 100vw; max-width: none; height: 100vh; height: 100dvh; max-height: none; margin: 0; padding: 0; border: 0; background: rgb(0 0 0 / 0.92); color: white; }
636
636
  .cms-lightbox[open] { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: minmax(0, 1fr) auto; align-items: center; }
637
- .cms-lightbox::backdrop { background: rgb(0 0 0 / 0.6); }
637
+ .cms-lightbox:modal { overscroll-behavior: contain; }
638
+ .cms-lightbox::backdrop { background: rgb(0 0 0 / 0.6); overflow: hidden; overscroll-behavior: contain; }
638
639
  .cms-lightbox-stage { grid-column: 2; display: flex; align-items: center; justify-content: center; height: 100%; min-height: 0; padding: 3.5rem 0 1rem; }
639
640
  .cms-lightbox-media { max-width: 100%; max-height: 100%; border-radius: 0.5rem; object-fit: contain; background: black; }
640
641
  video.cms-lightbox-media { width: min(100%, 160vh); aspect-ratio: 16 / 9; }
@@ -664,7 +665,7 @@ video.cms-lightbox-media { width: min(100%, 160vh); aspect-ratio: 16 / 9; }
664
665
  .cms-carousel[data-per-view] .cms-carousel-slide { flex-basis: calc((100% - (var(--cms-per-view) - 1) * 1.5rem) / var(--cms-per-view)); overflow: hidden; border-radius: 0.75rem; }
665
666
  @container (width < 1024px) { .cms-carousel[data-per-view] .cms-carousel-slide { flex-basis: calc((100% - 1.5rem) / 2); } }
666
667
  @container (width < 640px) { .cms-carousel[data-per-view] .cms-carousel-slide { flex-basis: 100%; } }
667
- .cms-carousel-thumbs, .cms-compare-thumbs { display: flex; gap: 0.75rem; margin-top: 0.75rem; padding-bottom: 0.25rem; overflow-x: auto; scrollbar-width: thin; }
668
+ .cms-carousel-thumbs, .cms-compare-thumbs { display: flex; gap: 0.75rem; margin-top: 0.75rem; padding-bottom: 0.25rem; overflow-x: auto; }
668
669
  .cms-carousel-thumbs { display: none; }
669
670
  .cms-carousel[data-enhanced] .cms-carousel-thumbs { display: flex; }
670
671
  :is(.cms-carousel-thumb, .cms-compare-thumb) { flex: 0 0 auto; width: 8rem; padding: 0; overflow: hidden; border: 2px solid transparent; border-radius: 0.5rem; background: none; opacity: 0.65; cursor: pointer; transition: opacity 0.2s ease, border-color 0.2s ease; }
@@ -34,6 +34,7 @@ function shared(labels: { close: string; previous: string; next: string }): Ligh
34
34
  if (lightbox?.dialog.isConnected) return lightbox;
35
35
  const dialog = document.createElement('dialog');
36
36
  dialog.className = 'cms-lightbox';
37
+ dialog.id = 'cms-lightbox';
37
38
  const stage = document.createElement('div');
38
39
  stage.className = 'cms-lightbox-stage';
39
40
  const caption = document.createElement('p');
@@ -45,17 +46,21 @@ function shared(labels: { close: string; previous: string; next: string }): Ligh
45
46
  for (const part of [close, previous, stage, next, caption]) dialog.appendChild(part);
46
47
  document.body.appendChild(dialog);
47
48
  const created: Lightbox = { dialog, stage, caption, previous, next, items: [], index: 0 };
48
- close.addEventListener('click', () => dialog.close());
49
+ // The close button closes the dialog by itself where the browser has invoker commands; elsewhere a click does it.
50
+ close.setAttribute('commandfor', dialog.id);
51
+ close.setAttribute('command', 'close');
52
+ if (!('commandForElement' in HTMLButtonElement.prototype)) close.addEventListener('click', () => dialog.close());
49
53
  previous.addEventListener('click', () => show(created, created.index - 1));
50
54
  next.addEventListener('click', () => show(created, created.index + 1));
51
- // A click on the dark ground, not on the file or a button, closes.
55
+ // A click on the dark ground, not on the file or a button, closes. The dialog fills the screen,
56
+ // so there is no backdrop to click and `closedby="any"` would never fire: this stays a script.
52
57
  dialog.addEventListener('click', event => { if (event.target === dialog || event.target === stage) dialog.close(); });
53
58
  dialog.addEventListener('keydown', event => {
54
59
  if (event.key === 'ArrowRight') show(created, created.index + 1);
55
60
  if (event.key === 'ArrowLeft') show(created, created.index - 1);
56
61
  });
57
- // Closing stops a playing video and lets the page scroll again.
58
- dialog.addEventListener('close', () => { stage.replaceChildren(); document.documentElement.style.removeProperty('overflow'); });
62
+ // Closing stops a playing video.
63
+ dialog.addEventListener('close', () => stage.replaceChildren());
59
64
  lightbox = created;
60
65
  return created;
61
66
  }
@@ -103,7 +108,7 @@ export function enhanceLightbox(root: HTMLElement): void {
103
108
  alt: entry.querySelector('img')?.alt ?? '', caption: entry.dataset.caption ?? '',
104
109
  }));
105
110
  show(box, Math.max(links.indexOf(link), 0));
106
- document.documentElement.style.overflow = 'hidden';
111
+ // The page behind stays still through overscroll-behavior on the dialog (blocks.css), not by hiding its scrollbar.
107
112
  if (!box.dialog.open) box.dialog.showModal();
108
113
  });
109
114
  }
@@ -4,7 +4,7 @@
4
4
  * Security and the user screen; the page owns the list and the new password, shown once.
5
5
  */
6
6
  import { Client, ClientState, Component, Cossack } from '@cossackframework/core';
7
- import { Badge, Button, Field, Input, NativeSelect } from '@cossackframework/ui';
7
+ import { Badge, Button, Field, Input, NativeSelect, SecretNotice } from '@cossackframework/ui';
8
8
  import { html, component } from '@cossackframework/renderer';
9
9
  import type { ApiToken } from '../auth';
10
10
 
@@ -27,8 +27,6 @@ export class AppPasswords extends Cossack {
27
27
  @ClientState() private scope: 'read' | 'write' = 'write';
28
28
  /** Days until the password expires, as the select's value; '0' is never. */
29
29
  @ClientState() private expires = '0';
30
- /** Whether Copy worked: the button says so, or the box asks to copy by hand. */
31
- @ClientState() private copied: 'yes' | 'no' | '' = '';
32
30
 
33
31
  @Client()
34
32
  private async submit(event: Event) {
@@ -41,20 +39,10 @@ export class AppPasswords extends Cossack {
41
39
  this.expires = '0';
42
40
  }
43
41
 
44
- @Client()
45
- private async copy() {
46
- try { await navigator.clipboard.writeText(this.props.newToken); this.copied = 'yes'; }
47
- catch { this.copied = 'no'; }
48
- }
49
-
50
42
  render() {
51
43
  return html`<div class="space-y-4">
52
- ${this.props.newToken ? html`<div class="space-y-2 rounded-md border border-emerald-500/40 bg-emerald-500/5 p-3">
53
- <p class="text-sm font-medium text-foreground">${__('Copy the new application password now. You will not see it again.')}</p>
54
- <div class="flex gap-2"><input readonly class="w-full rounded-md border border-input bg-background px-3 py-1.5 font-mono text-xs" aria-label=${__('New application password')} .value=${this.props.newToken} data-new-token>
55
- ${component(Button, { type: 'button', size: 'sm', variant: 'outline', '@click': () => this.copy() }, this.copied === 'yes' ? __('Copied.') : __('Copy'))}</div>
56
- ${this.copied === 'no' ? html`<p role="alert" class="text-xs text-destructive">${__('Copy it from the box.')}</p>` : null}
57
- </div>` : null}
44
+ ${this.props.newToken ? component(SecretNotice, { label: __('New application password'), value: this.props.newToken, 'data-new-token': '',
45
+ message: __('Copy the new application password now. You will not see it again.'), copyLabel: __('Copy'), copiedLabel: __('Copied.'), copyFailedLabel: __('Copy it from the box.') }) : null}
58
46
  <form class="flex flex-wrap items-end gap-2" @submit=${(event: Event) => this.submit(event)}>
59
47
  ${component(Field, { label: __('Name'), for: 'token-name', control: attributes => component(Input, { ...attributes, required: true, maxlength: 80, placeholder: __('Such as Mobile app'),
60
48
  '.value': this.name, '@input': (event: Event) => { this.name = (event.target as HTMLInputElement).value; } }) })}
@@ -1,53 +1,22 @@
1
- /**
2
- * Selection and bulk actions shared by the dashboard's lists (entries, users, forms): row and
3
- * "select all" checkboxes, and the Bulk actions select with its Apply button.
4
- */
5
- import { component, html, type TemplateResult } from '@cossackframework/renderer';
6
- import { Button, Checkbox, NativeSelect } from '@cossackframework/ui';
1
+ /** Selection and bulk actions of the dashboard's lists, from `@cossackframework/ui/blocks` with the dashboard's translations. */
2
+ import type { TemplateResult } from '@cossackframework/renderer';
3
+ import * as blocks from '@cossackframework/ui/blocks';
4
+ import type { BulkBarOptions } from '@cossackframework/ui/blocks';
7
5
 
8
- /** A bulk action of a list; `confirm` asks first with that text. */
9
- export interface BulkChoice {
10
- key: string;
11
- label: string;
12
- confirm?: string;
13
- }
14
-
15
- /** The selection after a row's checkbox changes. */
16
- export function toggleSelected(selected: readonly string[], id: string, checked: boolean): string[] {
17
- return checked ? [...new Set([...selected, id])] : selected.filter(entry => entry !== id);
18
- }
6
+ export type { BulkChoice } from '@cossackframework/ui/blocks';
7
+ export { toggleSelected } from '@cossackframework/ui/blocks';
19
8
 
20
- /** The "select all" checkbox of a table's header, over the rows that can be selected. */
9
+ /** The "select all" checkbox of a table's header. */
21
10
  export function selectAllBox(ids: readonly string[], selected: readonly string[], change: (ids: string[]) => void): TemplateResult {
22
- const all = ids.length > 0 && ids.every(id => selected.includes(id));
23
- return component(Checkbox, { checked: all, indeterminate: !all && ids.some(id => selected.includes(id)), disabled: ids.length === 0, 'aria-label': __('Select all'),
24
- '@change': (event: Event) => change((event.target as HTMLInputElement).checked ? [...ids] : []) });
11
+ return blocks.selectAllBox(ids, selected, change, __('Select all'));
25
12
  }
26
13
 
27
- /** A row's checkbox; `label` names the row for assistive technology. */
14
+ /** A row's checkbox; `label` names the row. */
28
15
  export function selectBox(id: string, label: string, selected: readonly string[], change: (ids: string[]) => void): TemplateResult {
29
- return component(Checkbox, { checked: selected.includes(id), 'aria-label': `${__('Select')} ${label}`,
30
- '@change': (event: Event) => change(toggleSelected(selected, id, (event.target as HTMLInputElement).checked)) });
31
- }
32
-
33
- export interface BulkBarOptions {
34
- /** Distinct per bar, such as `bulk-top` and `bulk-bottom`. */
35
- id: string;
36
- choices: readonly BulkChoice[];
37
- /** The chosen action's key; empty for none. */
38
- value: string;
39
- count: number;
40
- choose(key: string): void;
41
- apply(): void;
16
+ return blocks.selectBox(id, `${__('Select')} ${label}`, selected, change);
42
17
  }
43
18
 
44
19
  /** The Bulk actions select, its Apply button and how many rows are selected. */
45
- export function bulkBar(options: BulkBarOptions): TemplateResult {
46
- return html`<div class="flex flex-wrap items-center gap-2" data-bulk-bar>
47
- <div class="w-44">${component(NativeSelect, { id: options.id, size: 'sm', 'aria-label': __('Bulk actions'), '@change': (event: Event) => options.choose((event.target as HTMLSelectElement).value) }, html`
48
- <option value="" ?selected=${!options.value}>${__('Bulk actions')}</option>
49
- ${options.choices.map(choice => html`<option value=${choice.key} ?selected=${options.value === choice.key}>${choice.label}</option>`)}`)}</div>
50
- ${component(Button, { type: 'button', size: 'sm', variant: 'outline', disabled: !options.value || !options.count, '@click': () => options.apply() }, __('Apply'))}
51
- ${options.count ? html`<span class="text-xs text-muted-foreground">${options.count} ${__('selected')}</span>` : null}
52
- </div>`;
20
+ export function bulkBar(options: Omit<BulkBarOptions, 'labels'>): TemplateResult {
21
+ return blocks.bulkBar({ ...options, labels: { bulkActions: __('Bulk actions'), apply: __('Apply'), selected: __('selected') } });
53
22
  }
@@ -1,120 +1,28 @@
1
1
  /**
2
- * The dashboard's lists (entries, users, roles, forms): one table, one filter bar and one footer,
3
- * so every list reads the same. Filters are a GET form, so the address holds them; selection
4
- * goes with `bulkBar` from `./bulk`, above and below the table.
2
+ * The dashboard's lists (entries, users, roles, forms), from `@cossackframework/ui/blocks` with
3
+ * the dashboard's translations and icon style. Selection goes with `bulkBar` from `./bulk`.
5
4
  */
6
- import { component, html, ifDefined, type TemplateResult } from '@cossackframework/renderer';
7
- import { Button, Card, CardBody, Icon, Input, Pagination } from '@cossackframework/ui';
5
+ import type { TemplateResult } from '@cossackframework/renderer';
6
+ import * as blocks from '@cossackframework/ui/blocks';
7
+ import type { ListFiltersOptions, ListFooterOptions, ListTableOptions } from '@cossackframework/ui/blocks';
8
8
  import { shellIcons } from './icons';
9
- import { selectAllBox, selectBox } from './bulk';
10
9
 
11
- export interface ListColumn<T> {
12
- /** The header; empty for a column of controls. */
13
- label: string | TemplateResult;
14
- cell(row: T): unknown;
15
- /** Classes for the header and the cells, such as `w-14` or `text-muted-foreground`. */
16
- class?: string;
17
- /** How the list is sorted by this column, for `aria-sort`; a sortable header passes a link as its label. */
18
- sort?: 'ascending' | 'descending' | 'none';
19
- }
20
-
21
- export interface ListTableOptions<T> {
22
- rows: readonly T[];
23
- key(row: T): string;
24
- /** Columns in order; a falsy entry is left out, so optional columns read inline. */
25
- columns: readonly (ListColumn<T> | false | null | undefined)[];
26
- /** Row checkboxes and the "select all" box. `selectable` limits which rows have one; all by default. */
27
- selection?: { selected: readonly string[]; selectable?: readonly string[]; label(row: T): string; change(ids: string[]): void };
28
- /** What an empty list says. */
29
- empty?: string;
30
- /** The rows' data attribute, such as `data-user`, holding the key: tests and scripts find rows by it. */
31
- rowAttribute?: string;
32
- }
10
+ export type { ListColumn, RowAction } from '@cossackframework/ui/blocks';
11
+ export { rowActions } from '@cossackframework/ui/blocks';
33
12
 
34
- const TH = 'px-3 py-2 font-medium';
35
- const TD = 'px-3 py-2';
36
-
37
- /** The list as a table in a card: a header row, a row per item, and the empty text when there are none. */
13
+ /** The list as a table in a card; a row's checkbox reads "Select <label>". */
38
14
  export function listTable<T>(options: ListTableOptions<T>): TemplateResult {
39
- const columns = options.columns.filter((column): column is ListColumn<T> => !!column);
40
- const selection = options.selection;
41
- const selectable = selection ? selection.selectable ?? options.rows.map(options.key) : [];
42
- const attribute = options.rowAttribute ?? 'data-row';
43
- return component(Card, {}, component(CardBody, { class: 'p-0' }, html`
44
- <div class="overflow-x-auto">
45
- <table class="w-full text-sm">
46
- <thead><tr class="border-b border-border text-left text-xs uppercase tracking-wide text-muted-foreground">
47
- ${selection ? html`<th class="w-10 px-3 py-2">${selectAllBox(selectable, selection.selected, ids => selection.change(ids))}</th>` : null}
48
- ${columns.map(column => html`<th class=${`${TH} ${column.class ?? ''}`} aria-sort=${column.sort ?? 'none'}>${column.label}</th>`)}
49
- </tr></thead>
50
- <tbody>${options.rows.map(row => {
51
- const key = options.key(row);
52
- const chosen = selection?.selected.includes(key) === true;
53
- return html`<tr class=${`group border-b border-border last:border-0 align-top ${chosen ? 'bg-primary/5' : ''}`} ...=${{ [attribute]: key }}>
54
- ${selection ? html`<td class=${TD}>${selectable.includes(key) ? selectBox(key, selection.label(row), selection.selected, ids => selection.change(ids)) : null}</td>` : null}
55
- ${columns.map(column => html`<td class=${`${TD} ${column.class ?? ''}`}>${column.cell(row)}</td>`)}
56
- </tr>`;
57
- })}</tbody>
58
- </table>
59
- ${options.rows.length ? null : html`<p class="px-3 py-8 text-center text-sm text-muted-foreground">${options.empty ?? __('Nothing found.')}</p>`}
60
- </div>`));
61
- }
62
-
63
- export interface ListFiltersOptions {
64
- /** The list's address; the form submits to it with GET. */
65
- action: string;
66
- /** Values the form keeps, such as the sort, as hidden inputs. */
67
- hidden?: Readonly<Record<string, string>>;
68
- /** The search box: its query name, value and placeholder. */
69
- search: { name: string; value: string; placeholder: string };
70
- /** More filters before the search box, such as a role or a language select. */
71
- filters?: TemplateResult | null;
72
- id?: string;
15
+ const selection = options.selection && { ...options.selection, selectAllLabel: __('Select all'), label: (row: T) => `${__('Select')} ${options.selection!.label(row)}` };
16
+ return blocks.listTable({ ...options, selection, empty: options.empty ?? __('Nothing found.') });
73
17
  }
74
18
 
75
- /** The filter bar above a list: its filters, a search box with its icon, and the Filter button. */
19
+ /** The filter bar above a list. */
76
20
  export function listFilters(options: ListFiltersOptions): TemplateResult {
77
- return html`<form method="get" action=${options.action} class="flex flex-wrap items-center gap-2" role="search" id=${ifDefined(options.id)}>
78
- ${Object.entries(options.hidden ?? {}).filter(([, value]) => value !== '').map(([name, value]) => html`<input type="hidden" name=${name} value=${value}>`)}
79
- ${options.filters ?? null}
80
- <div class="relative w-64 max-w-full">
81
- <span aria-hidden="true" class="pointer-events-none absolute left-2.5 top-1/2 inline-flex -translate-y-1/2 text-muted-foreground [&_svg]:size-4">${component(Icon, { entry: shellIcons().search, size: 16 })}</span>
82
- ${component(Input, { type: 'search', name: options.search.name, value: options.search.value, size: 'sm', class: 'pl-8', placeholder: options.search.placeholder, 'aria-label': options.search.placeholder })}
83
- </div>
84
- ${component(Button, { type: 'submit', size: 'sm', variant: 'outline' }, __('Filter'))}
85
- </form>`;
86
- }
87
-
88
- /** Below a list: how many items there are and, past one page, the pages. */
89
- /** The count and pages under a list. `more`: the count is what was found so far, and more follow (search). */
90
- export function listFooter(options: { total: number; page: number; totalPages: number; more?: boolean; href(page: number): string }): TemplateResult {
91
- return html`<div class="flex flex-col items-center justify-between gap-3 sm:flex-row">
92
- <p class="text-xs text-muted-foreground">${options.total}${options.more ? '+' : ''} ${options.total === 1 && !options.more ? __('item') : __('items')}</p>
93
- ${options.totalPages > 1 ? component(Pagination, {
94
- page: options.page, totalPages: options.totalPages, label: __('Pagination'), previousLabel: __('Previous page'), nextLabel: __('Next page'),
95
- pageLabel: (page: number) => `${__('Page')} ${page}`, href: (page: number) => options.href(page),
96
- }) : null}
97
- </div>`;
98
- }
99
-
100
- /** A row's quick action: a link, or a button that runs `run`. */
101
- export interface RowAction {
102
- /** Unique on the page, such as `user-<id>-delete`. */
103
- id: string;
104
- label: string;
105
- href?: string;
106
- run?(): void;
107
- danger?: boolean;
21
+ return blocks.listFilters({ filterLabel: __('Filter'), searchIcon: shellIcons().search, ...options });
108
22
  }
109
23
 
110
- /** A row's quick actions under its title, as words between bars; clearer when the row is hovered or focused. */
111
- export function rowActions(actions: readonly RowAction[]): TemplateResult {
112
- const separator = html`<span aria-hidden="true" class="text-muted-foreground">|</span>`;
113
- return html`<div class="mt-1 flex flex-wrap items-center gap-2 text-xs opacity-80 group-hover:opacity-100 focus-within:opacity-100" data-quick-actions>${actions.flatMap((action, index) => {
114
- const tone = action.danger ? 'text-destructive' : 'text-primary';
115
- const control = action.href
116
- ? html`<a href=${action.href} id=${action.id} class=${`${tone} no-underline hover:underline`}>${action.label}</a>`
117
- : html`<button type="button" id=${action.id} class=${`${tone} cursor-pointer border-none bg-transparent p-0 text-xs hover:underline`} @click=${() => action.run?.()}>${action.label}</button>`;
118
- return index ? [separator, control] : [control];
119
- })}</div>`;
24
+ /** The count and pages under a list. */
25
+ export function listFooter(options: Omit<ListFooterOptions, 'labels'>): TemplateResult {
26
+ return blocks.listFooter({ ...options, labels: { item: __('item'), items: __('items'), pagination: __('Pagination'), previous: __('Previous page'), next: __('Next page'),
27
+ page: (page: number) => `${__('Page')} ${page}` } });
120
28
  }
@@ -4,10 +4,15 @@ import users from './modules/users';
4
4
  import sessions from './modules/sessions';
5
5
  import settings from './modules/settings';
6
6
  import roles from './modules/roles';
7
+ import { Widget4Icon } from '@cossackframework/solar-icons/widget-4/line';
7
8
 
8
9
  const modules: Record<string, DashboardModule> = { users, sessions, settings, roles };
9
10
 
10
- /** The modules the project chose (src/dashboard.config.ts: `modules`), in this order. */
11
- export const dashboardModules: DashboardModule[] = Object.entries(modules)
12
- .filter(([id]) => (authOptions.modules as readonly string[]).includes(id))
13
- .map(([, module]) => module);
11
+ /**
12
+ * The modules the project chose (src/dashboard.config.ts: `modules`), in this order, then the
13
+ * project's own screens (`navigation`).
14
+ */
15
+ export const dashboardModules: DashboardModule[] = [
16
+ ...Object.entries(modules).filter(([id]) => (authOptions.modules as readonly string[]).includes(id)).map(([, module]) => module),
17
+ ...authOptions.navigation.map((item): DashboardModule => ({ ...item, icon: item.icon ?? { line: Widget4Icon }, authorization: item.authorization ?? 'authenticated' })),
18
+ ];
@@ -1,26 +1,2 @@
1
- /** Tab helpers shared by the dashboard's screens: a count beside a label, and the open tab kept in the address. */
2
- import { component, html, type TemplateResult } from '@cossackframework/renderer';
3
- import { Badge } from '@cossackframework/ui';
4
-
5
- /** A count beside a label, such as a tab's items; nothing when there are none, so an empty tab stays quiet. */
6
- export function countBadge(count: number): TemplateResult {
7
- if (!count) return html``;
8
- return html`<span class="ml-1.5 inline-flex align-middle">${component(Badge, { variant: 'default' }, String(count))}</span>`;
9
- }
10
-
11
- /** The tab the address names (`?tab=`), when it is one of `values`; the first value otherwise. */
12
- export function tabFromQuery<T extends string>(query: string | undefined, values: readonly T[]): T {
13
- return values.find(value => value === query) ?? values[0]!;
14
- }
15
-
16
- /**
17
- * Keep the open tab in the address so a reload or a shared link opens it; the first (default)
18
- * tab drops the parameter. Client only: replaces the history entry.
19
- */
20
- export function rememberTab(value: string, values: readonly string[], name = 'tab'): void {
21
- if (typeof window === 'undefined') return;
22
- const url = new URL(window.location.href);
23
- if (value === values[0]) url.searchParams.delete(name);
24
- else url.searchParams.set(name, value);
25
- window.history.replaceState(window.history.state, '', url);
26
- }
1
+ /** Tab helpers of the dashboard's screens, from `@cossackframework/ui/blocks`. */
2
+ export { countBadge, tabFromQuery, rememberTab } from '@cossackframework/ui/blocks';
@@ -20,6 +20,9 @@ export interface DashboardModule {
20
20
  activeFor?: string;
21
21
  }
22
22
 
23
+ /** A screen of the project in the navigation (src/dashboard.config.ts: `navigation`): a module whose icon and authorization have defaults. */
24
+ export type DashboardNavigationItem = Omit<DashboardModule, 'icon' | 'authorization'> & Partial<Pick<DashboardModule, 'icon' | 'authorization'>>;
25
+
23
26
  /** A status the dashboard's taskbar shows: what waits for the user, and where to go. */
24
27
  export interface DashboardStatus {
25
28
  id: string;
@@ -40,6 +40,13 @@ export default class ForgotPasswordPage extends Cossack {
40
40
  }
41
41
  }
42
42
 
43
+ /** A field marked wrong is checked again as it is edited, so its message goes once the value is fixed. A submit checks it too. */
44
+ @Client()
45
+ async recheck(value: string) {
46
+ this.form.email = value;
47
+ if (this.hasError('form.email')) await this.validateProperty('form.email', 'input');
48
+ }
49
+
43
50
  @Server({ input: resetRequestInput })
44
51
  async requestReset(submitted: ResetRequestInput) {
45
52
  const { email, turnstile } = await resetRequestInput.parse(submitted);
@@ -63,7 +70,7 @@ export default class ForgotPasswordPage extends Cossack {
63
70
  __('If an account exists for that email, a reset link has been sent.'))
64
71
  : html`<form @submit="${(e: Event) => this.handleSubmit(e)}" class="space-y-4">
65
72
  ${component(Field, { label: __('Email'), for: 'email', error: this.getError('form.email'),
66
- control: attributes => component(Input, { ...attributes, type: 'email', placeholder: 'user@example.com', variant: this.hasError('form.email') ? 'error' : 'default', '.value': bind(this.form, 'email') }) })}
73
+ control: attributes => component(Input, { ...attributes, type: 'email', autocomplete: 'username', spellcheck: 'false', required: true, placeholder: 'user@example.com', variant: this.hasError('form.email') ? 'error' : 'default', '.value': bind(this.form, 'email'), '@input': (e: Event) => this.recheck((e.target as HTMLInputElement).value) }) })}
67
74
  ${this.botKey ? component(Turnstile, { id: 'reset-verify', siteKey: this.botKey, action: 'reset', label: __('Bot protection') }) : null}
68
75
  ${component(Button, { type: 'submit', block: true }, __('Send Reset Link'))}
69
76
  </form>`}
@@ -82,6 +82,13 @@ export default class LoginPage extends Cossack {
82
82
  }
83
83
  }
84
84
 
85
+ /** A field marked wrong is checked again as it is edited, so its message goes once the value is fixed. A submit checks every field. */
86
+ @Client()
87
+ async recheck(field: keyof LoginForm, value: string) {
88
+ this.form[field] = value;
89
+ if (this.hasError(`form.${field}`)) await this.validateProperty(`form.${field}`, 'input');
90
+ }
91
+
85
92
  @Server({ input: loginInput })
86
93
  async login(submitted: LoginInput) {
87
94
  // Native server calls bypass decorator gates, so validate here too.
@@ -168,9 +175,9 @@ export default class LoginPage extends Cossack {
168
175
  <h3 class="mb-6 text-xl font-semibold text-foreground">${__('Login')}</h3>
169
176
  <form @submit="${(e: Event) => this.handleSubmit(e)}" class="space-y-4">
170
177
  ${component(Field, { label: __('Email'), for: 'email', error: this.getError('form.email'),
171
- control: attributes => component(Input, { ...attributes, type: 'email', placeholder: 'user@example.com', variant: this.hasError('form.email') ? 'error' : 'default', '.value': bind(this.form, 'email') }) })}
178
+ control: attributes => component(Input, { ...attributes, type: 'email', autocomplete: 'username', spellcheck: 'false', required: true, placeholder: 'user@example.com', variant: this.hasError('form.email') ? 'error' : 'default', '.value': bind(this.form, 'email'), '@input': (e: Event) => this.recheck('email', (e.target as HTMLInputElement).value) }) })}
172
179
  ${component(Field, { label: __('Password'), for: 'password', error: this.getError('form.password'),
173
- control: attributes => component(PasswordInput, { ...attributes, value: this.form.password, onValueChange: (v: string) => this.form.password = v }) })}
180
+ control: attributes => component(PasswordInput, { ...attributes, autocomplete: 'current-password', required: true, value: this.form.password, onValueChange: (v: string) => this.recheck('password', v) }) })}
174
181
  <div class="flex items-center justify-between gap-3 text-sm">
175
182
  <button type="button" class="text-primary hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${(e: Event) => this.emailLink(e)}>${__('Email me a sign-in link')}</button>
176
183
  <a href="/auth/forgot-password" class="text-primary hover:underline">${__('Forgot password?')}</a>
@@ -56,6 +56,13 @@ export default class RegisterPage extends Cossack {
56
56
  }
57
57
  }
58
58
 
59
+ /** A field marked wrong is checked again as it is edited, so its message goes once the value is fixed. A submit checks every field. */
60
+ @Client()
61
+ async recheck(field: 'email' | 'password', value: string) {
62
+ this.form[field] = value;
63
+ if (this.hasError(`form.${field}`)) await this.validateProperty(`form.${field}`, 'input');
64
+ }
65
+
59
66
  @Server({ input: registerInput })
60
67
  async register(submitted: RegisterInput) {
61
68
  const { name, email, password, turnstile } = await registerInput.parse(submitted);
@@ -99,11 +106,11 @@ export default class RegisterPage extends Cossack {
99
106
  <h3 class="mb-6 text-xl font-semibold text-foreground">${__('Register')}</h3>
100
107
  <form @submit="${(e: Event) => this.handleSubmit(e)}" class="space-y-4">
101
108
  ${component(Field, { label: __('Name'), for: 'name',
102
- control: attributes => component(Input, { ...attributes, type: 'text', '.value': bind(this.form, 'name') }) })}
109
+ control: attributes => component(Input, { ...attributes, type: 'text', autocomplete: 'name', '.value': bind(this.form, 'name') }) })}
103
110
  ${component(Field, { label: __('Email'), for: 'email', error: this.getError('form.email'),
104
- control: attributes => component(Input, { ...attributes, type: 'email', placeholder: 'user@example.com', variant: this.hasError('form.email') ? 'error' : 'default', '.value': bind(this.form, 'email') }) })}
111
+ control: attributes => component(Input, { ...attributes, type: 'email', autocomplete: 'username', spellcheck: 'false', required: true, placeholder: 'user@example.com', variant: this.hasError('form.email') ? 'error' : 'default', '.value': bind(this.form, 'email'), '@input': (e: Event) => this.recheck('email', (e.target as HTMLInputElement).value) }) })}
105
112
  ${component(Field, { label: __('Password'), for: 'password', error: this.getError('form.password'),
106
- control: attributes => component(PasswordInput, { ...attributes, value: this.form.password, onValueChange: (v: string) => this.form.password = v }) })}
113
+ control: attributes => component(PasswordInput, { ...attributes, autocomplete: 'new-password', required: true, minlength: 8, value: this.form.password, onValueChange: (v: string) => this.recheck('password', v) }) })}
107
114
  ${this.botKey ? component(Turnstile, { id: 'register-verify', siteKey: this.botKey, action: 'register', label: __('Bot protection') }) : null}
108
115
  ${this.error ? component(Alert, { variant: 'destructive' }, this.error) : null}
109
116
  ${component(Button, { type: 'submit', block: true }, __('Create Account'))}
@@ -35,6 +35,15 @@ export default class ResetPasswordPage extends Cossack {
35
35
  }
36
36
  }
37
37
 
38
+ /** A field marked wrong is checked again as it is edited, so its message goes once the value is fixed. A submit checks every field. */
39
+ @Client()
40
+ async recheck(field: 'password' | 'confirm', value: string) {
41
+ this.form[field] = value;
42
+ if (this.hasError(`form.${field}`)) await this.validateProperty(`form.${field}`, 'input');
43
+ // The confirmation is checked against the password, so a changed password checks it again too.
44
+ if (field === 'password' && this.hasError('form.confirm')) await this.validateProperty('form.confirm', 'input');
45
+ }
46
+
38
47
  @Server({ input: resetPasswordInput })
39
48
  async doReset(submitted: ResetPasswordInput) {
40
49
  const { token, password, confirm } = await resetPasswordInput.parse(submitted);
@@ -54,9 +63,9 @@ export default class ResetPasswordPage extends Cossack {
54
63
  <h3 class="mb-6 text-xl font-semibold text-foreground">${__('Reset Password')}</h3>
55
64
  <form @submit="${(e: Event) => this.handleSubmit(e)}" class="space-y-4">
56
65
  ${component(Field, { label: __('New Password'), for: 'password', error: this.getError('form.password'),
57
- control: attributes => component(PasswordInput, { ...attributes, value: this.form.password, placeholder: '••••••••', autocomplete: 'new-password', onValueChange: (v: string) => this.form.password = v }) })}
66
+ control: attributes => component(PasswordInput, { ...attributes, value: this.form.password, placeholder: '••••••••', autocomplete: 'new-password', required: true, minlength: 8, onValueChange: (v: string) => this.recheck('password', v) }) })}
58
67
  ${component(Field, { label: __('Confirm New Password'), for: 'confirm', error: this.getError('form.confirm'),
59
- control: attributes => component(PasswordInput, { ...attributes, value: this.form.confirm, placeholder: '••••••••', autocomplete: 'new-password', onValueChange: (v: string) => this.form.confirm = v }) })}
68
+ control: attributes => component(PasswordInput, { ...attributes, value: this.form.confirm, placeholder: '••••••••', autocomplete: 'new-password', required: true, onValueChange: (v: string) => this.recheck('confirm', v) }) })}
60
69
  ${this.error ? component(Alert, { variant: 'destructive' }, this.error) : null}
61
70
  ${component(Button, { type: 'submit', block: true }, __('Reset Password'))}
62
71
  </form>
@@ -25,6 +25,8 @@ export default class TwoFactorPage extends Cossack {
25
25
  @Client()
26
26
  async submit(event: Event) {
27
27
  event.preventDefault();
28
+ // The button stays enabled; `required` stops an empty submit, and blank space costs no try.
29
+ if (!this.code.trim()) return;
28
30
  await this.verify(this.code);
29
31
  }
30
32
 
@@ -49,13 +51,13 @@ export default class TwoFactorPage extends Cossack {
49
51
  render() {
50
52
  return html`
51
53
  <h3 class="mb-2 text-xl font-semibold text-foreground">${__('Two-step sign-in')}</h3>
52
- <p class="mb-6 text-sm text-muted-foreground">${this.recovery ? __('Enter one of your recovery codes. Each works once.') : __('Enter the 6-digit code from your authenticator app.')}</p>
54
+ <p id="two-factor-hint" class="mb-6 text-sm text-muted-foreground">${this.recovery ? __('Enter one of your recovery codes. Each works once.') : __('Enter the 6-digit code from your authenticator app.')}</p>
53
55
  <form class="space-y-4" @submit=${(event: Event) => this.submit(event)}>
54
56
  ${component(Field, { label: this.recovery ? __('Recovery code') : __('Code'), for: 'two-factor-code',
55
- control: attributes => component(Input, { ...attributes, autocomplete: 'one-time-code', inputmode: this.recovery ? 'text' : 'numeric', required: true, autofocus: true,
57
+ control: attributes => component(Input, { ...attributes, 'aria-describedby': 'two-factor-hint', type: 'text', autocomplete: 'one-time-code', inputmode: this.recovery ? 'text' : 'numeric', required: true, autofocus: true,
56
58
  maxlength: this.recovery ? 20 : 6, '.value': this.code, '@input': (event: Event) => { this.code = (event.target as HTMLInputElement).value; } }) })}
57
59
  ${this.error ? component(Alert, { variant: 'destructive' }, this.error) : null}
58
- ${component(Button, { type: 'submit', block: true, disabled: !this.code.trim() }, __('Verify'))}
60
+ ${component(Button, { type: 'submit', block: true }, __('Verify'))}
59
61
  </form>
60
62
  <div class="mt-6 flex justify-between text-sm">
61
63
  <button type="button" class="text-primary hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => { this.recovery = !this.recovery; this.code = ''; }}>
@@ -1,6 +1,6 @@
1
1
  import { Cossack, Page, State, Server, Client, type HeadValue } from '@cossackframework/core';
2
2
  import { input } from '@cossackframework/core/input';
3
- import { AlertDialog, Badge, Button, Card, CardBody, CardHeader, Checkbox, Field, Input } from '@cossackframework/ui';
3
+ import { AlertDialog, Badge, Button, Card, CardBody, CardHeader, Checkbox, CopyField, Field, Input } from '@cossackframework/ui';
4
4
  import { html, component } from '@cossackframework/renderer';
5
5
  import { isCmsError, PERMISSIONS, WEBHOOK_EVENTS, type Webhook, type WebhookDelivery, type WebhookEvent } from '@cossackframework/cms';
6
6
  import { requireAny } from '#app/cms/guards';
@@ -166,7 +166,8 @@ export default class WebhooksPage extends Cossack {
166
166
  ${component(Badge, { variant: entry.active ? 'success' : 'secondary' }, entry.active ? __('Active') : __('Off'))}</span>
167
167
  <span class="block truncate text-xs text-muted-foreground">${entry.url}</span></a></li>`)}</ul>` : html`<p class="text-sm text-muted-foreground">${__('No webhooks yet.')}</p>`}`))}
168
168
  ${hook ? component(Card, {}, component(CardBody, { class: 'space-y-2' }, html`<h2 class="text-base font-semibold text-foreground">${__('Signing secret')}</h2>
169
- <code class="block break-all rounded bg-muted px-2 py-1 text-xs">${this.revealed || `${hook.secretHint}${'•'.repeat(16)}`}</code>
169
+ ${this.revealed ? component(CopyField, { label: __('Signing secret'), value: this.revealed, 'data-webhook-secret': '', copyLabel: __('Copy'), copiedLabel: __('Copied.'), copyFailedLabel: __('Copy it from the box.') })
170
+ : html`<code class="block break-all rounded bg-muted px-2 py-1 text-xs">${`${hook.secretHint}${'•'.repeat(16)}`}</code>`}
170
171
  ${this.revealed ? null : html`<button type="button" class="text-xs text-primary hover:underline bg-transparent border-none p-0 cursor-pointer" @click=${() => this.reveal()}>${__('Show')}</button>`}
171
172
  <p class="text-xs text-muted-foreground">${__('Each delivery has X-Cossack-Signature: sha256= the HMAC-SHA256 of “timestamp.body” with this secret, and the timestamp in X-Cossack-Timestamp.')}</p>`)) : null}
172
173
  </aside>
@@ -1,12 +1,11 @@
1
- import { Cossack, Page, Server, State, Client, Image, server$, type HeadValue } from '@cossackframework/core';
2
- import { Sidebar, DropdownMenu, Avatar, Icon, type SidebarItem } from '@cossackframework/ui';
3
- import { CommandPalette, type CommandItem } from '@cossackframework/ui/blocks';
1
+ import { Cossack, Page, Server, State, Client, server$, type HeadValue } from '@cossackframework/core';
2
+ import type { SidebarItem } from '@cossackframework/ui';
3
+ import { DashboardShell, type CommandItem } from '@cossackframework/ui/blocks';
4
4
  import { html, component, type TemplateResult } from '@cossackframework/renderer';
5
5
  import { getCookie } from 'hono/cookie';
6
6
  import { dashboardFind, dashboardNotices, dashboardSearch, dashboardStatus, navigation } from '#app/dashboard/access';
7
7
  import { shellIcons } from '#app/dashboard/icons';
8
8
  import { dashboardHead } from '#app/dashboard/head';
9
- import { notice } from '@cossackframework/ui/blocks';
10
9
  import { siteHasLogo, siteLogo, siteName } from '#app/brand';
11
10
  import type { DashboardModule, DashboardNotice, DashboardStatus } from '#app/dashboard/types';
12
11
  import { logout } from '#app/auth';
@@ -14,14 +13,11 @@ import { requireDashboardUser } from '#app/middlewares/auth';
14
13
  import { themeStore } from '@/stores.client';
15
14
 
16
15
  /**
17
- * Dashboard layout: sidebar nav + user menu + theme toggle, shared by every
18
- * /dashboard/* page. src/dashboard/access.ts decides which modules the user
19
- * sees; each describes its icon, destination, submenu links, and whether it
20
- * belongs in navigation or the account menu.
21
- *
22
- * A page with navigation of its own (a secondary sidebar) marks its root
23
- * `data-subnav`: the main area then drops its padding, so the page's
24
- * navigation sits against the sidebar and runs to the footer.
16
+ * Dashboard layout, shared by every /dashboard/* page: it decides what the signed-in user sees
17
+ * and renders it in `DashboardShell` from `@cossackframework/ui/blocks` (sidebar, account menu,
18
+ * theme toggle, palette, notices, taskbar). src/dashboard/access.ts decides which modules the
19
+ * user sees; each describes its icon, destination, submenu links, and whether it belongs in
20
+ * navigation or the account menu.
25
21
  *
26
22
  * The theme toggle writes the same `cs-theme` cookie and themeStore the App
27
23
  * component applies to `<html>.dark`, and draws itself from that class.
@@ -64,8 +60,11 @@ export default class DashboardLayout extends Cossack {
64
60
 
65
61
  @Client()
66
62
  toggleTheme() {
63
+ // The opposite of what shows. Back to the system's scheme forgets the choice, so the
64
+ // page follows the system again; a choice that differs from it is kept until undone.
67
65
  const theme = themeStore.get() === 'dark' ? 'light' : 'dark';
68
- document.cookie = `cs-theme=${theme}; Path=/; Max-Age=31536000; SameSite=Lax`;
66
+ const system = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
67
+ document.cookie = theme === system ? 'cs-theme=; Path=/; Max-Age=0; SameSite=Lax' : `cs-theme=${theme}; Path=/; Max-Age=31536000; SameSite=Lax`;
69
68
  themeStore.set(theme);
70
69
  }
71
70
 
@@ -159,9 +158,6 @@ export default class DashboardLayout extends Cossack {
159
158
 
160
159
  render(): TemplateResult {
161
160
  const icons = shellIcons();
162
- const iconClass = 'inline-flex items-center justify-center [&_svg]:size-4';
163
- // The theme icons: only one shows, so `hidden` must not share the element with `inline-flex`.
164
- const themeIcon = 'items-center justify-center [&_svg]:size-4';
165
161
  const availableModules = this.modules;
166
162
  // A module with a parent the user also sees is listed inside the parent's menu.
167
163
  const nested = (module: DashboardModule) => !!module.parent && availableModules.some((other) => other.id === module.parent);
@@ -204,117 +200,28 @@ export default class DashboardLayout extends Cossack {
204
200
  }),
205
201
  ];
206
202
 
207
- const statusTone = (tone: DashboardStatus['tone']) => tone === 'error' ? 'text-destructive' : tone === 'warning' ? 'text-warning-text' : 'text-muted-foreground';
208
- const taskbarButton = 'hidden h-7 cursor-pointer items-center gap-1 rounded-md border-none bg-transparent px-2 text-xs text-muted-foreground hover:bg-muted hover:text-foreground';
209
- return html`
210
- <div class="group/dashboard flex min-h-screen bg-background">
211
- ${component(Sidebar, {
212
- id: 'dashboard-navigation', label: __('Dashboard navigation'),
213
- expandLabel: __('Expand navigation'), collapseLabel: __('Collapse navigation'),
214
- title: this.appName,
215
- // The brand opens the site itself, as WordPress's admin bar does; Dashboard is the first navigation item.
216
- brand: html`<a href="/" class="flex items-center gap-2 no-underline group-[.is-collapsed]:hidden" aria-label=${__('View site')} title=${__('View site')}>
217
- ${this.appLogoOnly
218
- ? Image({ src: this.appLogo, alt: this.appName, width: 32, height: 32, loading: 'eager', class: 'h-8 w-auto max-w-40 shrink-0 object-contain' })
219
- : html`${Image({ src: this.appLogo, alt: '', width: 24, height: 24, loading: 'eager', class: 'h-6 w-auto max-w-24 shrink-0 object-contain' })}
220
- <span class="text-sm font-semibold text-foreground truncate">${this.appName}</span>`}
221
- </a>
222
- <a href="/" class="hidden group-[.is-collapsed]:flex items-center justify-center" aria-label=${__('View site')} title=${__('View site')}>
223
- ${Image({ src: this.appLogo, alt: '', width: 24, height: 24, loading: 'eager', class: 'size-6 object-contain' })}
224
- </a>`,
225
- width: '248px',
226
- collapsible: 'icon',
227
- collapsed: this.sidebarCollapsed,
228
- onCollapsedChange: () => this.onToggleSidebar(),
229
- items: items,
230
- // The toggle renders both modes and the .dark class on <html> shows the current
231
- // one (sun in light mode, moon in dark mode), so the server's markup matches
232
- // before the cookie or system theme is known. A click switches to the other.
233
- footer: html`
234
- <div class="flex items-center gap-1">
235
- <button
236
- type="button"
237
- @click=${() => this.toggleTheme()}
238
- class="flex-1 flex items-center justify-center gap-2 px-2 py-1.5 rounded-md text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground cursor-pointer border-none bg-transparent group-[.is-collapsed]:px-0"
239
- title=${__('Switch between light and dark mode')}
240
- aria-label=${__('Switch between light and dark mode')}
241
- >
242
- <span class=${`${themeIcon} inline-flex dark:hidden`}>${component(Icon, { entry: icons.light, size: 16 })}</span>
243
- <span class=${`${themeIcon} hidden dark:inline-flex`}>${component(Icon, { entry: icons.dark, size: 16 })}</span>
244
- <span class="group-[.is-collapsed]:hidden dark:hidden">${__('Light mode')}</span>
245
- <span class="hidden group-[.is-collapsed]:hidden dark:inline">${__('Dark mode')}</span>
246
- </button>
247
- </div>
248
- <div class="h-px bg-border my-1 group-[.is-collapsed]:hidden"></div>
249
- ${component(DropdownMenu, {
250
- id: 'dashboard-account-menu',
251
- block: true,
252
- side: 'right',
253
- align: 'end',
254
- trigger: html`
255
- <span class="flex items-center gap-2.5 w-full px-1.5 py-1 rounded-md text-left group-[.is-collapsed]:justify-center">
256
- ${component(Avatar, { src: this.account.avatar ?? '', alt: this.account.name, size: 32 })}
257
- <span class="flex-1 min-w-0 group-[.is-collapsed]:hidden">
258
- <span class="block text-sm font-medium text-foreground truncate">${this.account.name}</span>
259
- <span class="block text-xs text-muted-foreground truncate">${this.account.email}</span>
260
- </span>
261
- <span class="text-muted-foreground group-[.is-collapsed]:hidden ${iconClass}">
262
- ${component(Icon, { entry: icons.expand, size: 16 })}
263
- </span>
264
- </span>
265
- `,
266
- }, html`
267
- <div class="px-3 py-2">
268
- <div class="text-sm font-medium">${this.account.name}</div>
269
- <div class="text-xs text-muted-foreground">${this.account.email}</div>
270
- </div>
271
- ${accountModules.length ? html`<div class="h-px bg-border my-1"></div>` : null}
272
- ${accountModules.map((module) => html`
273
- <a role="menuitem" tabindex="-1" href=${module.href} class="w-full flex items-center gap-2 px-3 py-2 text-sm rounded-sm hover:bg-muted text-foreground no-underline">
274
- <span class=${iconClass}>${component(Icon, { entry: module.icon, size: 16 })}</span>
275
- ${__(module.label)}
276
- </a>
277
- `)}
278
- <div class="h-px bg-border my-1"></div>
279
- <button
280
- type="button" role="menuitem" tabindex="-1"
281
- @click=${() => this.doLogout()}
282
- class="w-full flex items-center gap-2 px-3 py-2 text-sm rounded-sm hover:bg-muted cursor-pointer border-none bg-transparent text-left text-destructive">
283
- <span class=${iconClass}>${component(Icon, { entry: icons.logout, size: 16 })}</span>
284
- ${__('Log out')}
285
- </button>
286
- `)}
287
- `,
288
- })}
289
- <div class="flex-1 min-w-0 flex flex-col">
290
- ${component(CommandPalette, { id: 'dashboard-commands', label: __('Go to'), placeholder: __('Type a screen name or search…'), shortcut: true,
291
- commands: [...this.commands.map((entry): CommandItem => ({ id: entry.id, label: entry.label, group: entry.group })),
292
- ...this.found.map((entry): CommandItem => ({ id: entry.id, label: entry.label, group: entry.group, matched: true }))],
293
- onSelect: (id: string) => this.go(id), onSearchChange: (text: string) => this.onPaletteSearch(text) })}
294
- <main class="flex-1 p-6 sm:p-8 overflow-x-hidden has-[[data-settings-toolbar]]:overflow-visible has-[[data-subnav]]:grid has-[[data-subnav]]:grid-cols-1 has-[[data-subnav]]:p-0">
295
- ${this.logoutError ? html`<p role="alert" class="mb-4 text-sm text-destructive">${this.logoutError}</p>` : null}
296
- ${this.notices.length ? html`<div data-dashboard-notices class="mb-6 space-y-2 group-has-[[data-subnav]]/dashboard:m-4">${this.notices.map((item) => item.href
297
- ? html`<a href=${item.href} data-notice-id=${item.id} class="block no-underline">${notice(item.message, item.tone)}</a>`
298
- : html`<div data-notice-id=${item.id}>${notice(item.message, item.tone)}</div>`)}</div>` : null}
299
- ${this.children}
300
- </main>
301
- <footer data-dashboard-taskbar aria-label=${__('Dashboard taskbar')} class="sticky bottom-0 z-30 hidden h-10 items-center gap-1 border-t border-border bg-background/95 px-3 text-xs text-muted-foreground backdrop-blur md:flex">
302
- <a href="/" class="inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-xs font-medium text-foreground no-underline hover:bg-muted" title=${__('View site')}>
303
- ${this.appLogoOnly
304
- ? Image({ src: this.appLogo, alt: this.appName, width: 24, height: 24, loading: 'eager', class: 'h-6 w-auto max-w-28 shrink-0 object-contain' })
305
- : html`${Image({ src: this.appLogo, alt: '', width: 16, height: 16, loading: 'eager', class: 'h-4 w-auto max-w-16 shrink-0 object-contain' })}
306
- <span class="max-w-40 truncate">${this.appName}</span>`}
307
- </a>
308
- <span aria-hidden="true" class="mx-1 h-4 w-px bg-border"></span>
309
- ${this.statuses.map((item) => html`<a href=${item.href} data-status=${item.id} class=${`inline-flex h-7 items-center gap-1.5 rounded-md px-2 no-underline hover:bg-muted hover:text-foreground ${statusTone(item.tone)}`}>
310
- ${__(item.label)}${item.count !== undefined ? html`<span class="rounded-full bg-muted px-1.5 py-px text-[0.7rem] font-semibold tabular-nums text-foreground">${item.count}</span>` : null}</a>`)}
311
- <span class="flex-1"></span>
312
- <button type="button" popovertarget="screen-options" class=${`${taskbarButton} group-has-[#screen-options]/dashboard:inline-flex`}>${__('Screen options')}</button>
313
- <button type="button" popovertarget="screen-help" class=${`${taskbarButton} group-has-[#screen-help]/dashboard:inline-flex`}>${__('Help')}</button>
314
- <span class="px-2">&copy; ${new Date().getFullYear()} ${this.appName}</span>
315
- </footer>
316
- </div>
317
- </div>
318
- `;
203
+ return html`${component(DashboardShell, {
204
+ brand: { name: this.appName, logo: this.appLogo, logoOnly: this.appLogoOnly },
205
+ account: this.account,
206
+ navigation: items,
207
+ accountLinks: accountModules.map((module) => ({ label: __(module.label), href: module.href, icon: module.icon })),
208
+ collapsed: this.sidebarCollapsed,
209
+ onCollapsedChange: () => this.onToggleSidebar(),
210
+ onLogout: () => this.doLogout(),
211
+ onThemeToggle: () => this.toggleTheme(),
212
+ commands: [...this.commands.map((entry): CommandItem => ({ id: entry.id, label: entry.label, group: entry.group })),
213
+ ...this.found.map((entry): CommandItem => ({ id: entry.id, label: entry.label, group: entry.group, matched: true }))],
214
+ onCommand: (id: string) => this.go(id),
215
+ onCommandSearch: (text: string) => this.onPaletteSearch(text),
216
+ notices: this.notices,
217
+ statuses: this.statuses.map((item) => ({ ...item, label: __(item.label) })),
218
+ error: this.logoutError,
219
+ icons: { light: icons.light, dark: icons.dark, expand: icons.expand, logout: icons.logout },
220
+ labels: {
221
+ navigation: __('Dashboard navigation'), expand: __('Expand navigation'), collapse: __('Collapse navigation'), viewSite: __('View site'),
222
+ toggleTheme: __('Switch between light and dark mode'), lightMode: __('Light mode'), darkMode: __('Dark mode'), logOut: __('Log out'),
223
+ palette: __('Go to'), palettePlaceholder: __('Type a screen name or search…'), taskbar: __('Dashboard taskbar'), screenOptions: __('Screen options'), help: __('Help'),
224
+ },
225
+ }, this.children)}`;
319
226
  }
320
227
  }
@@ -1,6 +1,6 @@
1
1
  import { Cossack, Page, State, Server, Client, type HeadValue } from '@cossackframework/core';
2
2
  import { input } from '@cossackframework/core/input';
3
- import { Alert, Badge, Button, Card, CardBody, CardHeader, Field, Input } from '@cossackframework/ui';
3
+ import { Alert, Badge, Button, Card, CardBody, CardHeader, CopyField, Field, Input } from '@cossackframework/ui';
4
4
  import { notice, pageHeader } from '@cossackframework/ui/blocks';
5
5
  import { html, component, unsafeHTML, type TemplateResult } from '@cossackframework/renderer';
6
6
  import {
@@ -94,12 +94,6 @@ export default class SecurityPage extends Cossack {
94
94
  } catch (error) { this.error = (error as Error).message; }
95
95
  }
96
96
 
97
- @Client()
98
- async copyCodes() {
99
- this.error = '';
100
- try { await navigator.clipboard.writeText(this.recoveryCodes.join('\n')); this.message = __('Recovery codes copied.'); }
101
- catch { this.message = ''; this.error = __('Copy the codes from the list.'); }
102
- }
103
97
 
104
98
  // --- Passkeys ------------------------------------------------------------------
105
99
 
@@ -231,8 +225,8 @@ export default class SecurityPage extends Cossack {
231
225
  ${this.error ? notice(this.error, 'error') : null}
232
226
  ${this.recoveryCodes.length ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Your recovery codes')}</h2>`)}
233
227
  ${component(CardBody, { class: 'space-y-3' }, html`<p class="text-sm text-muted-foreground">${__('Save them somewhere safe. They are shown only now; each signs you in once without your phone.')}</p>
234
- <ul class="grid grid-cols-2 gap-1 font-mono text-sm sm:grid-cols-5" data-recovery-codes>${this.recoveryCodes.map(code => html`<li class="rounded bg-muted px-2 py-1 text-center">${code}</li>`)}</ul>
235
- ${component(Button, { type: 'button', variant: 'outline', size: 'sm', '@click': () => this.copyCodes() }, __('Copy'))}`)}`) : null}
228
+ ${component(CopyField, { label: __('Your recovery codes'), value: this.recoveryCodes.join('\n'), 'data-recovery-codes': '',
229
+ copyLabel: __('Copy'), copiedLabel: __('Copied.'), copyFailedLabel: __('Copy the codes from the list.') })}`)}`) : null}
236
230
  ${this.available ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Two-step sign-in')}</h2>`)}
237
231
  ${component(CardBody, {}, this.authenticator())}`) : null}
238
232
  ${this.available ? component(Card, {}, html`${component(CardHeader, {}, html`<h2 class="text-base font-semibold text-foreground">${__('Passkeys')}</h2>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cossackframework/cms",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "type": "module",
5
5
  "description": "Cossack CMS: resources, schema planning, repositories, auth and stores on RomeDB",
6
6
  "license": "MIT",
@@ -33,33 +33,33 @@
33
33
  "markdown-it": "15.0.3",
34
34
  "prosemirror-collab": "1.3.1",
35
35
  "uqr": "0.1.3",
36
- "@cossackframework/auth": "0.9.1",
37
- "@cossackframework/core": "0.9.1",
38
- "@cossackframework/renderer": "0.9.1",
39
- "@cossackframework/romedb": "0.9.1"
36
+ "@cossackframework/auth": "0.9.2",
37
+ "@cossackframework/romedb": "0.9.2",
38
+ "@cossackframework/core": "0.9.2",
39
+ "@cossackframework/renderer": "0.9.2"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@aws-sdk/client-s3": "^3.1156.0",
43
- "hono": "^4.13.7",
43
+ "hono": "^4.13.18",
44
44
  "sharp": "^0.35.5",
45
45
  "vite": "*",
46
- "@cossackframework/framework": "0.9.1",
47
- "@cossackframework/node-adapter": "0.9.1",
48
- "@cossackframework/ui": "0.9.1"
46
+ "@cossackframework/framework": "0.9.2",
47
+ "@cossackframework/node-adapter": "0.9.2",
48
+ "@cossackframework/ui": "0.9.2"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@aws-sdk/client-s3": "^3.1156.0",
52
52
  "@types/markdown-it": "^14.2.0",
53
53
  "@types/node": "^22.19.0",
54
- "hono": "^4.13.7",
54
+ "hono": "^4.13.18",
55
55
  "miniflare": "4.20260722.0",
56
56
  "rolldown": "~1.1.5",
57
57
  "sharp": "^0.35.5",
58
58
  "simple-icons": "16.36.0",
59
59
  "vite": "^8.1.6",
60
60
  "vitest": "^4.1.12",
61
- "@cossackframework/node-adapter": "0.9.1",
62
- "@cossackframework/framework": "0.9.1"
61
+ "@cossackframework/framework": "0.9.2",
62
+ "@cossackframework/node-adapter": "0.9.2"
63
63
  },
64
64
  "exports": {
65
65
  ".": "./src/index.ts",
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** The version of this package. A test keeps it equal to `package.json`. */
2
- export const CMS_VERSION = '0.9.1';
2
+ export const CMS_VERSION = '0.9.2';