@entifix/next-shell 0.19.0 → 0.20.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/README.md +7 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/back-office/account-menu.d.ts +10 -1
- package/dist/lib/back-office/account-menu.d.ts.map +1 -1
- package/dist/lib/back-office/account-menu.js +27 -3
- package/dist/lib/back-office/account-menu.js.map +1 -1
- package/dist/lib/back-office/back-office-shell.d.ts +0 -19
- package/dist/lib/back-office/back-office-shell.d.ts.map +1 -1
- package/dist/lib/back-office/back-office-shell.js +75 -59
- package/dist/lib/back-office/back-office-shell.js.map +1 -1
- package/dist/lib/back-office/breadcrumb-labels.d.ts +20 -0
- package/dist/lib/back-office/breadcrumb-labels.d.ts.map +1 -0
- package/dist/lib/back-office/breadcrumb-labels.js +52 -0
- package/dist/lib/back-office/breadcrumb-labels.js.map +1 -0
- package/dist/lib/back-office/breadcrumbs.d.ts.map +1 -1
- package/dist/lib/back-office/breadcrumbs.js +6 -1
- package/dist/lib/back-office/breadcrumbs.js.map +1 -1
- package/dist/lib/back-office/index.d.ts +1 -0
- package/dist/lib/back-office/index.d.ts.map +1 -1
- package/dist/lib/back-office/index.js +1 -0
- package/dist/lib/back-office/index.js.map +1 -1
- package/dist/lib/back-office/sidebar-nav.d.ts.map +1 -1
- package/dist/lib/back-office/sidebar-nav.js +31 -36
- package/dist/lib/back-office/sidebar-nav.js.map +1 -1
- package/dist/lib/command-palette/command-palette-host.d.ts.map +1 -1
- package/dist/lib/command-palette/command-palette-host.js +2 -9
- package/dist/lib/command-palette/command-palette-host.js.map +1 -1
- package/dist/lib/command-palette/use-use-cases-source.d.ts.map +1 -1
- package/dist/lib/command-palette/use-use-cases-source.js +3 -1
- package/dist/lib/command-palette/use-use-cases-source.js.map +1 -1
- package/dist/lib/confirm-action/confirm-action-state.d.ts +33 -0
- package/dist/lib/confirm-action/confirm-action-state.d.ts.map +1 -0
- package/dist/lib/confirm-action/confirm-action-state.js +33 -0
- package/dist/lib/confirm-action/confirm-action-state.js.map +1 -0
- package/dist/lib/confirm-action/confirm-action.d.ts +28 -0
- package/dist/lib/confirm-action/confirm-action.d.ts.map +1 -0
- package/dist/lib/confirm-action/confirm-action.js +129 -0
- package/dist/lib/confirm-action/confirm-action.js.map +1 -0
- package/dist/lib/confirm-action/index.d.ts +3 -0
- package/dist/lib/confirm-action/index.d.ts.map +1 -0
- package/dist/lib/confirm-action/index.js +3 -0
- package/dist/lib/confirm-action/index.js.map +1 -0
- package/dist/lib/crud/entity-crud-form.d.ts +5 -1
- package/dist/lib/crud/entity-crud-form.d.ts.map +1 -1
- package/dist/lib/crud/entity-crud-form.js +5 -10
- package/dist/lib/crud/entity-crud-form.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.js +120 -20
- package/dist/lib/crud/make-entity-crud.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts +18 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.js.map +1 -1
- package/dist/lib/crud/use-link-labels.d.ts +32 -0
- package/dist/lib/crud/use-link-labels.d.ts.map +1 -0
- package/dist/lib/crud/use-link-labels.js +76 -0
- package/dist/lib/crud/use-link-labels.js.map +1 -0
- package/dist/lib/i18n/catalog/en.d.ts.map +1 -1
- package/dist/lib/i18n/catalog/en.js +4 -4
- package/dist/lib/i18n/catalog/en.js.map +1 -1
- package/dist/lib/i18n/catalog/es.d.ts +4 -2
- package/dist/lib/i18n/catalog/es.d.ts.map +1 -1
- package/dist/lib/i18n/catalog/es.js +4 -4
- package/dist/lib/i18n/catalog/es.js.map +1 -1
- package/dist/lib/i18n/catalog/index.d.ts +4 -4
- package/dist/lib/theme/theme-cookies.d.ts +27 -0
- package/dist/lib/theme/theme-cookies.d.ts.map +1 -0
- package/dist/lib/theme/theme-cookies.js +18 -0
- package/dist/lib/theme/theme-cookies.js.map +1 -0
- package/dist/lib/workspace/pending-flows.d.ts.map +1 -1
- package/dist/lib/workspace/pending-flows.js +15 -6
- package/dist/lib/workspace/pending-flows.js.map +1 -1
- package/dist/lib/workspace/workspace-shell.d.ts.map +1 -1
- package/dist/lib/workspace/workspace-shell.js +11 -2
- package/dist/lib/workspace/workspace-shell.js.map +1 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +5 -0
- package/dist/server.js.map +1 -1
- package/package.json +9 -9
- package/dist/lib/crud/validation-messages.d.ts +0 -13
- package/dist/lib/crud/validation-messages.d.ts.map +0 -1
- package/dist/lib/crud/validation-messages.js +0 -36
- package/dist/lib/crud/validation-messages.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
The Next.js application shell. `makeEntityCrud` derives the list, detail and edit screens for an entity from its metadata; `BackOfficeShell` and `WorkspaceShell` provide the chrome, sidebar navigation, breadcrumbs, workspace tabs and command palette around them. Drafts and pending writes persist in IndexedDB.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`makeEntityCrud` takes a `delete` policy (`confirm`, `undo` or `typed`) and a `facets` adapter, announces saves and deletions, names a link column's target and a record's breadcrumb rather than its id, and keeps focus on a heading after every write. `ConfirmAction` asks before a Server Action acts, with or without JavaScript; the action guards itself with `whenConfirmed`. `AccountMenu` offers theme and density.
|
|
6
|
+
|
|
7
|
+
The `server` entry holds the route handlers a Next backend needs: a same-origin proxy to your services, session refresh and cookies, health, and record search across services — and `whenConfirmed` and `readThemeCookies`.
|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
|
@@ -12,10 +14,10 @@ pnpm add @entifix/next-shell @tanstack/react-query effect next react react-dom z
|
|
|
12
14
|
|
|
13
15
|
## Entry points
|
|
14
16
|
|
|
15
|
-
| Import | What it holds
|
|
16
|
-
| ---------------------------- |
|
|
17
|
-
| `@entifix/next-shell` | Client shell: `makeEntityCrud`, `BackOfficeShell`, `WorkspaceShell`, tabs, drafts, `shellCatalogs`
|
|
18
|
-
| `@entifix/next-shell/server` | `createServiceProxyRoute`, `createRefreshRoute`, `applySessionCookies`, `createHealthRoutes`, `createRecordSearchRoute` |
|
|
17
|
+
| Import | What it holds |
|
|
18
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
19
|
+
| `@entifix/next-shell` | Client shell: `makeEntityCrud`, `BackOfficeShell`, `WorkspaceShell`, `ConfirmAction`, `AccountMenu`, `useBreadcrumbLabel`, tabs, drafts, `shellCatalogs` |
|
|
20
|
+
| `@entifix/next-shell/server` | `createServiceProxyRoute`, `createRefreshRoute`, `applySessionCookies`, `createHealthRoutes`, `createRecordSearchRoute`, `whenConfirmed`, `readThemeCookies` |
|
|
19
21
|
|
|
20
22
|
## Optional peers
|
|
21
23
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './lib/back-office/index.js';
|
|
2
2
|
export * from './lib/command-palette/index.js';
|
|
3
|
+
export * from './lib/confirm-action/index.js';
|
|
3
4
|
export * from './lib/crud/index.js';
|
|
4
5
|
export * from './lib/i18n/index.js';
|
|
5
6
|
export type * from './lib/search/record-search.types.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAE/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AAIpC,mBAAmB,qCAAqC,CAAC;AACzD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AAIvC,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,WAAW,GACZ,MAAM,gCAAgC,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AAEzC;;;;;;;GAOG;AACH,cAAc,6BAA6B,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Use this file to export React client components (e.g. those with 'use client' directive) or other non-server utilities
|
|
2
2
|
export * from './lib/back-office/index.js';
|
|
3
3
|
export * from './lib/command-palette/index.js';
|
|
4
|
+
// A Server Action form that asks first; its guard ships from `/server`.
|
|
5
|
+
export * from './lib/confirm-action/index.js';
|
|
4
6
|
export * from './lib/crud/index.js';
|
|
5
7
|
export * from './lib/i18n/index.js';
|
|
6
8
|
export * from './lib/search/search-records.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Use this file to export React client components (e.g. those with 'use client' directive) or other non-server utilities\n\nexport * from './lib/back-office/index.js';\nexport * from './lib/command-palette/index.js';\nexport * from './lib/crud/index.js';\nexport * from './lib/i18n/index.js';\n// The browser half of record search: a typed `fetch` and the shapes it returns.\n// The route handler and the source declarations stay in `/server`, since they\n// read cookies and would be stamped as client references here.\nexport type * from './lib/search/record-search.types.js';\nexport * from './lib/search/search-records.js';\nexport * from './lib/session/index.js';\n// Type-only, so it stays erased: the account-link *values* ship from `/server`\n// (see src/server.ts), but `AccountMenuProps` names these types and a consumer\n// of the client entry has to be able to name them too.\nexport type {\n AccountDestination,\n AccountLabelKey,\n AccountLink,\n} from './lib/session/account-links.js';\nexport * from './lib/wizard/index.js';\nexport * from './lib/workspace/index.js';\n\n/**\n * Re-exported, not redeclared. A workspace host holds an entity form's draft to\n * autosave it, so it has to be able to name the type — but the type is core's,\n * and a fourth structural copy of `Record<string, string>` beside\n * `EntityFormValues`/`EntityFormDraft`/`EntityLinkDraft` is exactly what\n * composition metadata collapsed. One\n * declaration, reachable from the layer its consumers already depend on.\n */\nexport * from './lib/i18n/catalog/index.js';\nexport type { EntityDraft } from '@entifix/core';\n"],"names":[],"mappings":"AAAA,yHAAyH;AAEzH,cAAc,6BAA6B;AAC3C,cAAc,iCAAiC;AAC/C,cAAc,sBAAsB;AACpC,cAAc,sBAAsB;AAKpC,cAAc,iCAAiC;AAC/C,cAAc,yBAAyB;AASvC,cAAc,wBAAwB;AACtC,cAAc,2BAA2B;AAEzC;;;;;;;CAOC,GACD,cAAc,8BAA8B"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Use this file to export React client components (e.g. those with 'use client' directive) or other non-server utilities\n\nexport * from './lib/back-office/index.js';\nexport * from './lib/command-palette/index.js';\n// A Server Action form that asks first; its guard ships from `/server`.\nexport * from './lib/confirm-action/index.js';\nexport * from './lib/crud/index.js';\nexport * from './lib/i18n/index.js';\n// The browser half of record search: a typed `fetch` and the shapes it returns.\n// The route handler and the source declarations stay in `/server`, since they\n// read cookies and would be stamped as client references here.\nexport type * from './lib/search/record-search.types.js';\nexport * from './lib/search/search-records.js';\nexport * from './lib/session/index.js';\n// Type-only, so it stays erased: the account-link *values* ship from `/server`\n// (see src/server.ts), but `AccountMenuProps` names these types and a consumer\n// of the client entry has to be able to name them too.\nexport type {\n AccountDestination,\n AccountLabelKey,\n AccountLink,\n} from './lib/session/account-links.js';\nexport * from './lib/wizard/index.js';\nexport * from './lib/workspace/index.js';\n\n/**\n * Re-exported, not redeclared. A workspace host holds an entity form's draft to\n * autosave it, so it has to be able to name the type — but the type is core's,\n * and a fourth structural copy of `Record<string, string>` beside\n * `EntityFormValues`/`EntityFormDraft`/`EntityLinkDraft` is exactly what\n * composition metadata collapsed. One\n * declaration, reachable from the layer its consumers already depend on.\n */\nexport * from './lib/i18n/catalog/index.js';\nexport type { EntityDraft } from '@entifix/core';\n"],"names":[],"mappings":"AAAA,yHAAyH;AAEzH,cAAc,6BAA6B;AAC3C,cAAc,iCAAiC;AAC/C,wEAAwE;AACxE,cAAc,gCAAgC;AAC9C,cAAc,sBAAsB;AACpC,cAAc,sBAAsB;AAKpC,cAAc,iCAAiC;AAC/C,cAAc,yBAAyB;AASvC,cAAc,wBAAwB;AACtC,cAAc,2BAA2B;AAEzC;;;;;;;CAOC,GACD,cAAc,8BAA8B"}
|
|
@@ -12,6 +12,15 @@ export interface AccountMenuProps {
|
|
|
12
12
|
readonly signOutEndpoint?: string;
|
|
13
13
|
/** Fallback destination if logout answers without one. */
|
|
14
14
|
readonly signOutRedirect?: string;
|
|
15
|
+
/** Omits Sign out — for a host with no session to end. */
|
|
16
|
+
readonly hideSignOut?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Omits the theme choice. Shown by default whenever a `ThemeProvider` is
|
|
19
|
+
* above, which is where the themes come from.
|
|
20
|
+
*/
|
|
21
|
+
readonly hideTheme?: boolean;
|
|
22
|
+
/** Omits the density choice. */
|
|
23
|
+
readonly hideDensity?: boolean;
|
|
15
24
|
}
|
|
16
25
|
/**
|
|
17
26
|
* The top-bar account menu.
|
|
@@ -25,5 +34,5 @@ export interface AccountMenuProps {
|
|
|
25
34
|
* Showing or hiding an entry here protects nothing; auth-service refuses the
|
|
26
35
|
* request. This is navigation, not authorization.
|
|
27
36
|
*/
|
|
28
|
-
export declare function AccountMenu({ label, items, signOutEndpoint, signOutRedirect, }: AccountMenuProps): import("react").JSX.Element;
|
|
37
|
+
export declare function AccountMenu({ label, items, signOutEndpoint, signOutRedirect, hideSignOut, hideTheme, hideDensity, }: AccountMenuProps): import("react").JSX.Element;
|
|
29
38
|
//# sourceMappingURL=account-menu.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-menu.d.ts","sourceRoot":"","sources":["../../../src/lib/back-office/account-menu.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"account-menu.d.ts","sourceRoot":"","sources":["../../../src/lib/back-office/account-menu.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;IACvC,gDAAgD;IAChD,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,0DAA0D;IAC1D,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,0DAA0D;IAC1D,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,gCAAgC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,eAAoC,EACpC,eAAqB,EACrB,WAAmB,EACnB,SAAiB,EACjB,WAAmB,GACpB,EAAE,gBAAgB,+BA8ElB"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { Menu, useT } from '@entifix/react-controls';
|
|
3
|
+
import { Menu, useOptionalTheme, useT } from '@entifix/react-controls';
|
|
4
4
|
import { useState } from 'react';
|
|
5
|
+
const DENSITIES = [
|
|
6
|
+
'comfortable',
|
|
7
|
+
'compact'
|
|
8
|
+
];
|
|
5
9
|
/**
|
|
6
10
|
* The top-bar account menu.
|
|
7
11
|
*
|
|
@@ -13,8 +17,12 @@ import { useState } from 'react';
|
|
|
13
17
|
*
|
|
14
18
|
* Showing or hiding an entry here protects nothing; auth-service refuses the
|
|
15
19
|
* request. This is navigation, not authorization.
|
|
16
|
-
*/ export function AccountMenu({ label, items, signOutEndpoint = '/api/auth/logout', signOutRedirect = '/' }) {
|
|
20
|
+
*/ export function AccountMenu({ label, items, signOutEndpoint = '/api/auth/logout', signOutRedirect = '/', hideSignOut = false, hideTheme = false, hideDensity = false }) {
|
|
17
21
|
const t = useT('shell');
|
|
22
|
+
const controls = useT();
|
|
23
|
+
// Theme and density are the reader's to choose, from the menu that is
|
|
24
|
+
// theirs; the provider keeps the choice where the next page is rendered.
|
|
25
|
+
const theme = useOptionalTheme();
|
|
18
26
|
const [pending, setPending] = useState(false);
|
|
19
27
|
const signOut = async ()=>{
|
|
20
28
|
setPending(true);
|
|
@@ -56,7 +64,23 @@ import { useState } from 'react';
|
|
|
56
64
|
href: item.href,
|
|
57
65
|
children: t(item.labelKey)
|
|
58
66
|
}, item.href)),
|
|
59
|
-
/*#__PURE__*/ _jsx(Menu.
|
|
67
|
+
theme !== null && !hideTheme && /*#__PURE__*/ _jsx(Menu.Group, {
|
|
68
|
+
label: controls('theme.label'),
|
|
69
|
+
children: theme.themes.map((option)=>/*#__PURE__*/ _jsx(Menu.Radio, {
|
|
70
|
+
checked: theme.theme === option.id,
|
|
71
|
+
onClick: ()=>theme.setTheme(option.id),
|
|
72
|
+
children: option.label
|
|
73
|
+
}, option.id))
|
|
74
|
+
}),
|
|
75
|
+
theme !== null && !hideDensity && /*#__PURE__*/ _jsx(Menu.Group, {
|
|
76
|
+
label: controls('density.label'),
|
|
77
|
+
children: DENSITIES.map((option)=>/*#__PURE__*/ _jsx(Menu.Radio, {
|
|
78
|
+
checked: theme.density === option,
|
|
79
|
+
onClick: ()=>theme.setDensity(option),
|
|
80
|
+
children: controls(`density.${option}`)
|
|
81
|
+
}, option))
|
|
82
|
+
}),
|
|
83
|
+
!hideSignOut && /*#__PURE__*/ _jsx(Menu.Item, {
|
|
60
84
|
onClick: signOut,
|
|
61
85
|
disabled: pending,
|
|
62
86
|
children: t('account.signOut')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/back-office/account-menu.tsx"],"sourcesContent":["'use client';\n\nimport { Menu
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/back-office/account-menu.tsx"],"sourcesContent":["'use client';\n\nimport {\n type Density,\n Menu,\n useOptionalTheme,\n useT,\n} from '@entifix/react-controls';\nimport { useState } from 'react';\n\nimport type { AccountLink } from '../session/account-links.js';\n\nexport interface AccountMenuProps {\n /** Trigger text — typically the signed-in subject. */\n readonly label: string;\n /**\n * Built by the host from `accountPaths()`, which is where the request's\n * locale is known. Only the `href` is the host's to supply; the copy is this\n * component's own.\n */\n readonly items: readonly AccountLink[];\n /** Where this app mounts its logout handler. */\n readonly signOutEndpoint?: string;\n /** Fallback destination if logout answers without one. */\n readonly signOutRedirect?: string;\n /** Omits Sign out — for a host with no session to end. */\n readonly hideSignOut?: boolean;\n /**\n * Omits the theme choice. Shown by default whenever a `ThemeProvider` is\n * above, which is where the themes come from.\n */\n readonly hideTheme?: boolean;\n /** Omits the density choice. */\n readonly hideDensity?: boolean;\n}\n\nconst DENSITIES: readonly Density[] = ['comfortable', 'compact'];\n\n/**\n * The top-bar account menu.\n *\n * Entries are plain links rather than router pushes: they are ordinary\n * navigations, and were absolute cross-origin URLs back when the account\n * surface lived in its own app. Unlike `nav`, whose labels are authored by the\n * host app, this menu's copy is authored here — so it is resolved here, out of\n * `shell:account.*`, and the host supplies only URLs.\n *\n * Showing or hiding an entry here protects nothing; auth-service refuses the\n * request. This is navigation, not authorization.\n */\nexport function AccountMenu({\n label,\n items,\n signOutEndpoint = '/api/auth/logout',\n signOutRedirect = '/',\n hideSignOut = false,\n hideTheme = false,\n hideDensity = false,\n}: AccountMenuProps) {\n const t = useT('shell');\n const controls = useT();\n // Theme and density are the reader's to choose, from the menu that is\n // theirs; the provider keeps the choice where the next page is rendered.\n const theme = useOptionalTheme();\n const [pending, setPending] = useState(false);\n\n const signOut = async () => {\n setPending(true);\n try {\n const response = await fetch(signOutEndpoint, {\n method: 'POST',\n cache: 'no-store',\n });\n const body = (await response.json()) as {\n redirect?: string;\n endSessionUrl?: string;\n };\n // The provider's end-session URL wins when the handler returns one.\n // Clearing our cookies alone leaves someone \"signed out\" who is one click\n // from being signed straight back in with no prompt, because the provider\n // still holds a session — which on a shared machine is the failure this\n // whole control exists to prevent.\n window.location.href =\n body.endSessionUrl ?? body.redirect ?? signOutRedirect;\n } catch {\n // The cookies may already be gone; get out of the protected area anyway.\n window.location.href = signOutRedirect;\n }\n };\n\n return (\n <Menu>\n <Menu.Trigger aria-label={label}>\n <span aria-hidden=\"true\">◕</span>\n <span>{label}</span>\n </Menu.Trigger>\n <Menu.Items>\n {items.map(item => (\n <Menu.Link key={item.href} href={item.href}>\n {t(item.labelKey)}\n </Menu.Link>\n ))}\n {theme !== null && !hideTheme && (\n <Menu.Group label={controls('theme.label')}>\n {theme.themes.map(option => (\n <Menu.Radio\n key={option.id}\n checked={theme.theme === option.id}\n onClick={() => theme.setTheme(option.id)}\n >\n {option.label}\n </Menu.Radio>\n ))}\n </Menu.Group>\n )}\n {theme !== null && !hideDensity && (\n <Menu.Group label={controls('density.label')}>\n {DENSITIES.map(option => (\n <Menu.Radio\n key={option}\n checked={theme.density === option}\n onClick={() => theme.setDensity(option)}\n >\n {controls(`density.${option}`)}\n </Menu.Radio>\n ))}\n </Menu.Group>\n )}\n {!hideSignOut && (\n <Menu.Item onClick={signOut} disabled={pending}>\n {t('account.signOut')}\n </Menu.Item>\n )}\n </Menu.Items>\n </Menu>\n );\n}\n"],"names":["Menu","useOptionalTheme","useT","useState","DENSITIES","AccountMenu","label","items","signOutEndpoint","signOutRedirect","hideSignOut","hideTheme","hideDensity","t","controls","theme","pending","setPending","signOut","body","response","fetch","method","cache","json","window","location","href","endSessionUrl","redirect","Trigger","aria-label","span","aria-hidden","Items","map","item","Link","labelKey","Group","themes","option","Radio","checked","id","onClick","setTheme","density","setDensity","Item","disabled"],"mappings":"AAAA;;AAEA,SAEEA,IAAI,EACJC,gBAAgB,EAChBC,IAAI,QACC,0BAA0B;AACjC,SAASC,QAAQ,QAAQ,QAAQ;AA4BjC,MAAMC,YAAgC;IAAC;IAAe;CAAU;AAEhE;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,YAAY,EAC1BC,KAAK,EACLC,KAAK,EACLC,kBAAkB,kBAAkB,EACpCC,kBAAkB,GAAG,EACrBC,cAAc,KAAK,EACnBC,YAAY,KAAK,EACjBC,cAAc,KAAK,EACF;IACjB,MAAMC,IAAIX,KAAK;IACf,MAAMY,WAAWZ;IACjB,sEAAsE;IACtE,yEAAyE;IACzE,MAAMa,QAAQd;IACd,MAAM,CAACe,SAASC,WAAW,GAAGd,SAAS;IAEvC,MAAMe,UAAU;QACdD,WAAW;QACX,IAAI;gBAeAE,MAAAA;YAdF,MAAMC,WAAW,MAAMC,MAAMb,iBAAiB;gBAC5Cc,QAAQ;gBACRC,OAAO;YACT;YACA,MAAMJ,OAAQ,MAAMC,SAASI,IAAI;YAIjC,oEAAoE;YACpE,0EAA0E;YAC1E,0EAA0E;YAC1E,wEAAwE;YACxE,mCAAmC;YACnCC,OAAOC,QAAQ,CAACC,IAAI,IAClBR,QAAAA,sBAAAA,KAAKS,aAAa,YAAlBT,sBAAsBA,KAAKU,QAAQ,YAAnCV,OAAuCV;QAC3C,EAAE,eAAM;YACN,yEAAyE;YACzEgB,OAAOC,QAAQ,CAACC,IAAI,GAAGlB;QACzB;IACF;IAEA,qBACE,MAACT;;0BACC,MAACA,KAAK8B,OAAO;gBAACC,cAAYzB;;kCACxB,KAAC0B;wBAAKC,eAAY;kCAAO;;kCACzB,KAACD;kCAAM1B;;;;0BAET,MAACN,KAAKkC,KAAK;;oBACR3B,MAAM4B,GAAG,CAACC,CAAAA,qBACT,KAACpC,KAAKqC,IAAI;4BAAiBV,MAAMS,KAAKT,IAAI;sCACvCd,EAAEuB,KAAKE,QAAQ;2BADFF,KAAKT,IAAI;oBAI1BZ,UAAU,QAAQ,CAACJ,2BAClB,KAACX,KAAKuC,KAAK;wBAACjC,OAAOQ,SAAS;kCACzBC,MAAMyB,MAAM,CAACL,GAAG,CAACM,CAAAA,uBAChB,KAACzC,KAAK0C,KAAK;gCAETC,SAAS5B,MAAMA,KAAK,KAAK0B,OAAOG,EAAE;gCAClCC,SAAS,IAAM9B,MAAM+B,QAAQ,CAACL,OAAOG,EAAE;0CAEtCH,OAAOnC,KAAK;+BAJRmC,OAAOG,EAAE;;oBASrB7B,UAAU,QAAQ,CAACH,6BAClB,KAACZ,KAAKuC,KAAK;wBAACjC,OAAOQ,SAAS;kCACzBV,UAAU+B,GAAG,CAACM,CAAAA,uBACb,KAACzC,KAAK0C,KAAK;gCAETC,SAAS5B,MAAMgC,OAAO,KAAKN;gCAC3BI,SAAS,IAAM9B,MAAMiC,UAAU,CAACP;0CAE/B3B,SAAS,CAAC,QAAQ,EAAE2B,QAAQ;+BAJxBA;;oBASZ,CAAC/B,6BACA,KAACV,KAAKiD,IAAI;wBAACJ,SAAS3B;wBAASgC,UAAUlC;kCACpCH,EAAE;;;;;;AAMf"}
|
|
@@ -27,24 +27,5 @@ export interface BackOfficeShellProps {
|
|
|
27
27
|
*/
|
|
28
28
|
commandPalette?: ReactNode;
|
|
29
29
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Back-office page shell: a collapsible sidebar + a top bar carrying
|
|
32
|
-
* breadcrumbs, wrapping the routed content. Composed from the agnostic
|
|
33
|
-
* `Sidebar` primitive — the Next coupling (routing, breadcrumbs) lives here,
|
|
34
|
-
* not in the primitive.
|
|
35
|
-
*
|
|
36
|
-
* **Collapse has two inputs, and only one of them is a preference.** The stored
|
|
37
|
-
* choice is the person's; a `rail`-width viewport forces the compact form
|
|
38
|
-
* whatever they chose. They are kept apart deliberately: writing the forced
|
|
39
|
-
* value back would mean a single visit at a narrow width silently rewrites the
|
|
40
|
-
* choice, and the sidebar comes back collapsed on the desktop the person set it
|
|
41
|
-
* expanded on.
|
|
42
|
-
*
|
|
43
|
-
* Below `rail` the sidebar is not a sidebar at all — it is a drawer, built on
|
|
44
|
-
* Headless UI's `Dialog` for the focus trap, `Escape` handling, backdrop click
|
|
45
|
-
* and focus restoration that a hand-rolled one has to get right and usually does
|
|
46
|
-
* not. There is exactly one `SidebarNav` in the tree either way; rendering a
|
|
47
|
-
* second copy for the drawer is how the two drift.
|
|
48
|
-
*/
|
|
49
30
|
export declare function BackOfficeShell({ nav, brand, children, breadcrumbLabels, accountMenu, commandPalette, }: BackOfficeShellProps): import("react").JSX.Element;
|
|
50
31
|
//# sourceMappingURL=back-office-shell.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"back-office-shell.d.ts","sourceRoot":"","sources":["../../../src/lib/back-office/back-office-shell.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,SAAS,EAAY,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"back-office-shell.d.ts","sourceRoot":"","sources":["../../../src/lib/back-office/back-office-shell.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,SAAS,EAAY,MAAM,OAAO,CAAC;AAIjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAa3C,MAAM,WAAW,oBAAoB;IACnC,kCAAkC;IAClC,GAAG,EAAE,UAAU,EAAE,CAAC;IAClB,kDAAkD;IAClD,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;IACpB,0DAA0D;IAC1D,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C;;;;;OAKG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB;;;;;;;;;OASG;IACH,cAAc,CAAC,EAAE,SAAS,CAAC;CAC5B;AAwBD,wBAAgB,eAAe,CAAC,EAC9B,GAAG,EACH,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACX,cAAc,GACf,EAAE,oBAAoB,+BAsHtB"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
3
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
4
4
|
import { Button, Drawer, Sidebar, useT, useUiPreference, useViewportMode } from '@entifix/react-controls';
|
|
5
5
|
import { usePathname } from 'next/navigation';
|
|
6
6
|
import { useState } from 'react';
|
|
7
|
+
import { BreadcrumbLabelsProvider } from './breadcrumb-labels.js';
|
|
7
8
|
import { BackOfficeBreadcrumbs } from './breadcrumbs.js';
|
|
8
9
|
import { SidebarNav } from './sidebar-nav.js';
|
|
9
10
|
/** `namespace:` is prepended by the store → `entifix-ui:back-office:sidebar-collapsed`. */ const SIDEBAR_PREF_KEY = 'back-office:sidebar-collapsed';
|
|
@@ -30,7 +31,8 @@ import { SidebarNav } from './sidebar-nav.js';
|
|
|
30
31
|
* and focus restoration that a hand-rolled one has to get right and usually does
|
|
31
32
|
* not. There is exactly one `SidebarNav` in the tree either way; rendering a
|
|
32
33
|
* second copy for the drawer is how the two drift.
|
|
33
|
-
*/
|
|
34
|
+
*/ /** The content landmark's id: where the skip link lands. */ const MAIN_ID = 'main-content';
|
|
35
|
+
export function BackOfficeShell({ nav, brand, children, breadcrumbLabels, accountMenu, commandPalette }) {
|
|
34
36
|
const t = useT('shell');
|
|
35
37
|
const mode = useViewportMode();
|
|
36
38
|
const pathname = usePathname();
|
|
@@ -60,66 +62,80 @@ import { SidebarNav } from './sidebar-nav.js';
|
|
|
60
62
|
onToggleGroup: toggleGroup
|
|
61
63
|
});
|
|
62
64
|
const isCompact = mode === 'compact';
|
|
63
|
-
return /*#__PURE__*/ _jsxs(
|
|
64
|
-
gap: "none",
|
|
65
|
-
className: "min-h-screen",
|
|
65
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
66
66
|
children: [
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
children: [
|
|
72
|
-
/*#__PURE__*/ _jsx("div", {
|
|
73
|
-
className: "flex items-center justify-center px-2xs py-3xs text-step-1 font-semibold text-content",
|
|
74
|
-
children: collapsed ? null : brand
|
|
75
|
-
}),
|
|
76
|
-
navTree
|
|
77
|
-
]
|
|
67
|
+
/*#__PURE__*/ _jsx("a", {
|
|
68
|
+
href: `#${MAIN_ID}`,
|
|
69
|
+
className: "sr-only rounded-md bg-surface-elevated px-s py-2xs text-step-sm text-content shadow-overlay focus-ring focus:not-sr-only focus:fixed focus:top-s focus:left-s focus:z-(--z-overlay)",
|
|
70
|
+
children: t('sidebar.skipToContent')
|
|
78
71
|
}),
|
|
79
|
-
/*#__PURE__*/
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
72
|
+
/*#__PURE__*/ _jsx(BreadcrumbLabelsProvider, {
|
|
73
|
+
children: /*#__PURE__*/ _jsxs(Sidebar, {
|
|
74
|
+
gap: "none",
|
|
75
|
+
className: "min-h-screen",
|
|
76
|
+
children: [
|
|
77
|
+
isCompact ? null : /*#__PURE__*/ _jsxs(Sidebar.Side, {
|
|
78
|
+
as: "aside",
|
|
79
|
+
width: collapsed ? '4.5rem' : '16rem',
|
|
80
|
+
className: "md:sticky md:top-0 md:h-screen md:overflow-y-auto flex flex-col gap-m border-r border-border bg-surface-elevated p-s",
|
|
81
|
+
children: [
|
|
82
|
+
/*#__PURE__*/ _jsx("div", {
|
|
83
|
+
className: "flex items-center justify-center px-2xs py-3xs text-step-1 font-semibold text-content",
|
|
84
|
+
children: collapsed ? null : brand
|
|
85
|
+
}),
|
|
86
|
+
navTree
|
|
87
|
+
]
|
|
88
|
+
}),
|
|
89
|
+
/*#__PURE__*/ _jsxs(Sidebar.Main, {
|
|
90
|
+
as: "main",
|
|
91
|
+
id: MAIN_ID,
|
|
92
|
+
// The skip link's target: focusable from it, never a Tab stop.
|
|
93
|
+
tabIndex: -1,
|
|
94
|
+
className: "flex flex-col outline-none",
|
|
95
|
+
children: [
|
|
96
|
+
/*#__PURE__*/ _jsxs("header", {
|
|
97
|
+
className: "flex items-center gap-s border-b border-border bg-surface-elevated px-m py-s",
|
|
98
|
+
children: [
|
|
99
|
+
/*#__PURE__*/ _jsx(Button, _extends({
|
|
100
|
+
variant: "ghost",
|
|
101
|
+
size: "sm",
|
|
102
|
+
"aria-label": isCompact ? t('sidebar.openMenu') : collapsed ? t('sidebar.expand') : t('sidebar.collapse')
|
|
103
|
+
}, isCompact ? {} : {
|
|
104
|
+
'aria-pressed': collapsed
|
|
105
|
+
}, {
|
|
106
|
+
onClick: ()=>isCompact ? setDrawerOpen(true) : setCollapsed(!preferCollapsed),
|
|
107
|
+
children: /*#__PURE__*/ _jsx("span", {
|
|
108
|
+
"aria-hidden": "true",
|
|
109
|
+
children: "☰"
|
|
110
|
+
})
|
|
111
|
+
})),
|
|
112
|
+
/*#__PURE__*/ _jsx(BackOfficeBreadcrumbs, {
|
|
113
|
+
labels: breadcrumbLabels
|
|
114
|
+
}),
|
|
115
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
116
|
+
className: "ml-auto flex items-center gap-2xs",
|
|
117
|
+
children: [
|
|
118
|
+
commandPalette,
|
|
119
|
+
accountMenu
|
|
120
|
+
]
|
|
121
|
+
})
|
|
122
|
+
]
|
|
123
|
+
}),
|
|
124
|
+
/*#__PURE__*/ _jsx("div", {
|
|
125
|
+
className: "flex-1 p-m",
|
|
126
|
+
children: children
|
|
97
127
|
})
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
]
|
|
110
|
-
}),
|
|
111
|
-
/*#__PURE__*/ _jsx("div", {
|
|
112
|
-
className: "flex-1 p-m",
|
|
113
|
-
children: children
|
|
114
|
-
})
|
|
115
|
-
]
|
|
116
|
-
}),
|
|
117
|
-
isCompact && /*#__PURE__*/ _jsx(Drawer, {
|
|
118
|
-
open: isDrawerOpen,
|
|
119
|
-
onClose: ()=>setDrawerOpen(false),
|
|
120
|
-
title: brand,
|
|
121
|
-
closeLabel: t('sidebar.closeMenu'),
|
|
122
|
-
children: navTree
|
|
128
|
+
]
|
|
129
|
+
}),
|
|
130
|
+
isCompact && /*#__PURE__*/ _jsx(Drawer, {
|
|
131
|
+
open: isDrawerOpen,
|
|
132
|
+
onClose: ()=>setDrawerOpen(false),
|
|
133
|
+
title: brand,
|
|
134
|
+
closeLabel: t('sidebar.closeMenu'),
|
|
135
|
+
children: navTree
|
|
136
|
+
})
|
|
137
|
+
]
|
|
138
|
+
})
|
|
123
139
|
})
|
|
124
140
|
]
|
|
125
141
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/back-office/back-office-shell.tsx"],"sourcesContent":["'use client';\n\nimport {\n Button,\n Drawer,\n Sidebar,\n useT,\n useUiPreference,\n useViewportMode,\n} from '@entifix/react-controls';\nimport { usePathname } from 'next/navigation';\nimport { type ReactNode, useState } from 'react';\n\nimport { BackOfficeBreadcrumbs } from './breadcrumbs.js';\nimport type { NavSection } from './nav.js';\nimport { SidebarNav } from './sidebar-nav.js';\n\n/** `namespace:` is prepended by the store → `entifix-ui:back-office:sidebar-collapsed`. */\nconst SIDEBAR_PREF_KEY = 'back-office:sidebar-collapsed';\n\n/**\n * Which domain groups are collapsed, as one keyed record rather than a key per\n * group. `useUiPreference` resolves asynchronously after mount, so N keys would\n * be N first-paint transitions; one read settles the whole sidebar at once.\n */\nconst NAV_GROUPS_PREF_KEY = 'back-office:nav-collapsed-groups';\n\nexport interface BackOfficeShellProps {\n /** Grouped primary navigation. */\n nav: NavSection[];\n /** Brand mark shown at the top of the sidebar. */\n brand: ReactNode;\n children: ReactNode;\n /** Segment → label overrides for the breadcrumb trail. */\n breadcrumbLabels?: Record<string, string>;\n /**\n * Right-aligned slot in the top bar — the account menu. A slot rather than a\n * built-in, because what belongs in it differs per host: the label is the\n * signed-in subject where a layout has resolved a principal, and a bare\n * caption where it has not.\n */\n accountMenu?: ReactNode;\n /**\n * The command palette, trigger and all.\n *\n * A slot for a reason the account menu does not share: the palette's use-case\n * sources carry entity constructors and handler functions, neither of which\n * survives the server→client boundary, so it cannot be built from serializable\n * props here. The host composes it in a client module of its own and hands it\n * over — which also keeps this framework package from naming any domain's\n * entities.\n */\n commandPalette?: ReactNode;\n}\n\n/**\n * Back-office page shell: a collapsible sidebar + a top bar carrying\n * breadcrumbs, wrapping the routed content. Composed from the agnostic\n * `Sidebar` primitive — the Next coupling (routing, breadcrumbs) lives here,\n * not in the primitive.\n *\n * **Collapse has two inputs, and only one of them is a preference.** The stored\n * choice is the person's; a `rail`-width viewport forces the compact form\n * whatever they chose. They are kept apart deliberately: writing the forced\n * value back would mean a single visit at a narrow width silently rewrites the\n * choice, and the sidebar comes back collapsed on the desktop the person set it\n * expanded on.\n *\n * Below `rail` the sidebar is not a sidebar at all — it is a drawer, built on\n * Headless UI's `Dialog` for the focus trap, `Escape` handling, backdrop click\n * and focus restoration that a hand-rolled one has to get right and usually does\n * not. There is exactly one `SidebarNav` in the tree either way; rendering a\n * second copy for the drawer is how the two drift.\n */\nexport function BackOfficeShell({\n nav,\n brand,\n children,\n breadcrumbLabels,\n accountMenu,\n commandPalette,\n}: BackOfficeShellProps) {\n const t = useT('shell');\n const mode = useViewportMode();\n const pathname = usePathname();\n const { value: preferCollapsed, setValue: setCollapsed } =\n useUiPreference<boolean>(SIDEBAR_PREF_KEY, false);\n const { value: collapsedGroups, setValue: setCollapsedGroups } =\n useUiPreference<Record<string, boolean>>(NAV_GROUPS_PREF_KEY, {});\n // The drawer remembers *where* it was opened, and is open only while the\n // visitor is still there. A drawer that survives navigation covers the page\n // they just asked for, and closing it from an effect keyed on the route would\n // set state during a passive effect — a cascading render for something that is\n // derivable, since \"still on the page I opened this from\" is a fact about the\n // current render rather than an event to react to.\n const [openedAt, setOpenedAt] = useState<string | null>(null);\n const isDrawerOpen = openedAt !== null && openedAt === pathname;\n const setDrawerOpen = (open: boolean) => setOpenedAt(open ? pathname : null);\n\n // Three modes, one answer. A drawer has the whole viewport's width, so it\n // shows labels whatever the stored preference says — that preference is about\n // how much room the sidebar should take beside the content, and in a drawer\n // there is no beside.\n const collapsed =\n mode === 'rail' ? true : mode === 'compact' ? false : preferCollapsed;\n const toggleGroup = (title: string) =>\n setCollapsedGroups({\n ...collapsedGroups,\n [title]: collapsedGroups[title] !== true,\n });\n\n const navTree = (\n <SidebarNav\n sections={nav}\n collapsed={collapsed}\n collapsedGroups={collapsedGroups}\n onToggleGroup={toggleGroup}\n />\n );\n\n const isCompact = mode === 'compact';\n\n return (\n <Sidebar gap=\"none\" className=\"min-h-screen\">\n {isCompact ? null : (\n <Sidebar.Side\n as=\"aside\"\n width={collapsed ? '4.5rem' : '16rem'}\n className=\"md:sticky md:top-0 md:h-screen md:overflow-y-auto flex flex-col gap-m border-r border-border bg-surface-elevated p-s\"\n >\n <div className=\"flex items-center justify-center px-2xs py-3xs text-step-1 font-semibold text-content\">\n {collapsed ? null : brand}\n </div>\n {navTree}\n </Sidebar.Side>\n )}\n\n <Sidebar.Main as=\"main\" className=\"flex flex-col\">\n <header className=\"flex items-center gap-s border-b border-border bg-surface-elevated px-m py-s\">\n <Button\n variant=\"ghost\"\n size=\"sm\"\n aria-label={\n isCompact\n ? t('sidebar.openMenu')\n : collapsed\n ? t('sidebar.expand')\n : t('sidebar.collapse')\n }\n // A drawer trigger is not a two-state toggle — it opens a thing that\n // closes itself — so it reports pressed state only where it is one.\n {...(isCompact ? {} : { 'aria-pressed': collapsed })}\n onClick={() =>\n isCompact ? setDrawerOpen(true) : setCollapsed(!preferCollapsed)\n }\n >\n <span aria-hidden=\"true\">☰</span>\n </Button>\n <BackOfficeBreadcrumbs labels={breadcrumbLabels} />\n <div className=\"ml-auto flex items-center gap-2xs\">\n {commandPalette}\n {accountMenu}\n </div>\n </header>\n <div className=\"flex-1 p-m\">{children}</div>\n </Sidebar.Main>\n\n {isCompact && (\n <Drawer\n open={isDrawerOpen}\n onClose={() => setDrawerOpen(false)}\n title={brand}\n closeLabel={t('sidebar.closeMenu')}\n >\n {navTree}\n </Drawer>\n )}\n </Sidebar>\n );\n}\n"],"names":["Button","Drawer","Sidebar","useT","useUiPreference","useViewportMode","usePathname","useState","BackOfficeBreadcrumbs","SidebarNav","SIDEBAR_PREF_KEY","NAV_GROUPS_PREF_KEY","BackOfficeShell","nav","brand","children","breadcrumbLabels","accountMenu","commandPalette","t","mode","pathname","value","preferCollapsed","setValue","setCollapsed","collapsedGroups","setCollapsedGroups","openedAt","setOpenedAt","isDrawerOpen","setDrawerOpen","open","collapsed","toggleGroup","title","navTree","sections","onToggleGroup","isCompact","gap","className","Side","as","width","div","Main","header","variant","size","aria-label","onClick","span","aria-hidden","labels","onClose","closeLabel"],"mappings":"AAAA;;;AAEA,SACEA,MAAM,EACNC,MAAM,EACNC,OAAO,EACPC,IAAI,EACJC,eAAe,EACfC,eAAe,QACV,0BAA0B;AACjC,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAAyBC,QAAQ,QAAQ,QAAQ;AAEjD,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,SAASC,UAAU,QAAQ,mBAAmB;AAE9C,yFAAyF,GACzF,MAAMC,mBAAmB;AAEzB;;;;CAIC,GACD,MAAMC,sBAAsB;AA8B5B;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,gBAAgB,EAC9BC,GAAG,EACHC,KAAK,EACLC,QAAQ,EACRC,gBAAgB,EAChBC,WAAW,EACXC,cAAc,EACO;IACrB,MAAMC,IAAIhB,KAAK;IACf,MAAMiB,OAAOf;IACb,MAAMgB,WAAWf;IACjB,MAAM,EAAEgB,OAAOC,eAAe,EAAEC,UAAUC,YAAY,EAAE,GACtDrB,gBAAyBM,kBAAkB;IAC7C,MAAM,EAAEY,OAAOI,eAAe,EAAEF,UAAUG,kBAAkB,EAAE,GAC5DvB,gBAAyCO,qBAAqB,CAAC;IACjE,yEAAyE;IACzE,4EAA4E;IAC5E,8EAA8E;IAC9E,+EAA+E;IAC/E,8EAA8E;IAC9E,mDAAmD;IACnD,MAAM,CAACiB,UAAUC,YAAY,GAAGtB,SAAwB;IACxD,MAAMuB,eAAeF,aAAa,QAAQA,aAAaP;IACvD,MAAMU,gBAAgB,CAACC,OAAkBH,YAAYG,OAAOX,WAAW;IAEvE,0EAA0E;IAC1E,8EAA8E;IAC9E,4EAA4E;IAC5E,sBAAsB;IACtB,MAAMY,YACJb,SAAS,SAAS,OAAOA,SAAS,YAAY,QAAQG;IACxD,MAAMW,cAAc,CAACC,QACnBR,mBAAmB,aACdD;YACH,CAACS,MAAM,EAAET,eAAe,CAACS,MAAM,KAAK;;IAGxC,MAAMC,wBACJ,KAAC3B;QACC4B,UAAUxB;QACVoB,WAAWA;QACXP,iBAAiBA;QACjBY,eAAeJ;;IAInB,MAAMK,YAAYnB,SAAS;IAE3B,qBACE,MAAClB;QAAQsC,KAAI;QAAOC,WAAU;;YAC3BF,YAAY,qBACX,MAACrC,QAAQwC,IAAI;gBACXC,IAAG;gBACHC,OAAOX,YAAY,WAAW;gBAC9BQ,WAAU;;kCAEV,KAACI;wBAAIJ,WAAU;kCACZR,YAAY,OAAOnB;;oBAErBsB;;;0BAIL,MAAClC,QAAQ4C,IAAI;gBAACH,IAAG;gBAAOF,WAAU;;kCAChC,MAACM;wBAAON,WAAU;;0CAChB,KAACzC;gCACCgD,SAAQ;gCACRC,MAAK;gCACLC,cACEX,YACIpB,EAAE,sBACFc,YACEd,EAAE,oBACFA,EAAE;+BAILoB,YAAY,CAAC,IAAI;gCAAE,gBAAgBN;4BAAU;gCAClDkB,SAAS,IACPZ,YAAYR,cAAc,QAAQN,aAAa,CAACF;0CAGlD,cAAA,KAAC6B;oCAAKC,eAAY;8CAAO;;;0CAE3B,KAAC7C;gCAAsB8C,QAAQtC;;0CAC/B,MAAC6B;gCAAIJ,WAAU;;oCACZvB;oCACAD;;;;;kCAGL,KAAC4B;wBAAIJ,WAAU;kCAAc1B;;;;YAG9BwB,2BACC,KAACtC;gBACC+B,MAAMF;gBACNyB,SAAS,IAAMxB,cAAc;gBAC7BI,OAAOrB;gBACP0C,YAAYrC,EAAE;0BAEbiB;;;;AAKX"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/back-office/back-office-shell.tsx"],"sourcesContent":["'use client';\n\nimport {\n Button,\n Drawer,\n Sidebar,\n useT,\n useUiPreference,\n useViewportMode,\n} from '@entifix/react-controls';\nimport { usePathname } from 'next/navigation';\nimport { type ReactNode, useState } from 'react';\n\nimport { BreadcrumbLabelsProvider } from './breadcrumb-labels.js';\nimport { BackOfficeBreadcrumbs } from './breadcrumbs.js';\nimport type { NavSection } from './nav.js';\nimport { SidebarNav } from './sidebar-nav.js';\n\n/** `namespace:` is prepended by the store → `entifix-ui:back-office:sidebar-collapsed`. */\nconst SIDEBAR_PREF_KEY = 'back-office:sidebar-collapsed';\n\n/**\n * Which domain groups are collapsed, as one keyed record rather than a key per\n * group. `useUiPreference` resolves asynchronously after mount, so N keys would\n * be N first-paint transitions; one read settles the whole sidebar at once.\n */\nconst NAV_GROUPS_PREF_KEY = 'back-office:nav-collapsed-groups';\n\nexport interface BackOfficeShellProps {\n /** Grouped primary navigation. */\n nav: NavSection[];\n /** Brand mark shown at the top of the sidebar. */\n brand: ReactNode;\n children: ReactNode;\n /** Segment → label overrides for the breadcrumb trail. */\n breadcrumbLabels?: Record<string, string>;\n /**\n * Right-aligned slot in the top bar — the account menu. A slot rather than a\n * built-in, because what belongs in it differs per host: the label is the\n * signed-in subject where a layout has resolved a principal, and a bare\n * caption where it has not.\n */\n accountMenu?: ReactNode;\n /**\n * The command palette, trigger and all.\n *\n * A slot for a reason the account menu does not share: the palette's use-case\n * sources carry entity constructors and handler functions, neither of which\n * survives the server→client boundary, so it cannot be built from serializable\n * props here. The host composes it in a client module of its own and hands it\n * over — which also keeps this framework package from naming any domain's\n * entities.\n */\n commandPalette?: ReactNode;\n}\n\n/**\n * Back-office page shell: a collapsible sidebar + a top bar carrying\n * breadcrumbs, wrapping the routed content. Composed from the agnostic\n * `Sidebar` primitive — the Next coupling (routing, breadcrumbs) lives here,\n * not in the primitive.\n *\n * **Collapse has two inputs, and only one of them is a preference.** The stored\n * choice is the person's; a `rail`-width viewport forces the compact form\n * whatever they chose. They are kept apart deliberately: writing the forced\n * value back would mean a single visit at a narrow width silently rewrites the\n * choice, and the sidebar comes back collapsed on the desktop the person set it\n * expanded on.\n *\n * Below `rail` the sidebar is not a sidebar at all — it is a drawer, built on\n * Headless UI's `Dialog` for the focus trap, `Escape` handling, backdrop click\n * and focus restoration that a hand-rolled one has to get right and usually does\n * not. There is exactly one `SidebarNav` in the tree either way; rendering a\n * second copy for the drawer is how the two drift.\n */\n/** The content landmark's id: where the skip link lands. */\nconst MAIN_ID = 'main-content';\n\nexport function BackOfficeShell({\n nav,\n brand,\n children,\n breadcrumbLabels,\n accountMenu,\n commandPalette,\n}: BackOfficeShellProps) {\n const t = useT('shell');\n const mode = useViewportMode();\n const pathname = usePathname();\n const { value: preferCollapsed, setValue: setCollapsed } =\n useUiPreference<boolean>(SIDEBAR_PREF_KEY, false);\n const { value: collapsedGroups, setValue: setCollapsedGroups } =\n useUiPreference<Record<string, boolean>>(NAV_GROUPS_PREF_KEY, {});\n // The drawer remembers *where* it was opened, and is open only while the\n // visitor is still there. A drawer that survives navigation covers the page\n // they just asked for, and closing it from an effect keyed on the route would\n // set state during a passive effect — a cascading render for something that is\n // derivable, since \"still on the page I opened this from\" is a fact about the\n // current render rather than an event to react to.\n const [openedAt, setOpenedAt] = useState<string | null>(null);\n const isDrawerOpen = openedAt !== null && openedAt === pathname;\n const setDrawerOpen = (open: boolean) => setOpenedAt(open ? pathname : null);\n\n // Three modes, one answer. A drawer has the whole viewport's width, so it\n // shows labels whatever the stored preference says — that preference is about\n // how much room the sidebar should take beside the content, and in a drawer\n // there is no beside.\n const collapsed =\n mode === 'rail' ? true : mode === 'compact' ? false : preferCollapsed;\n const toggleGroup = (title: string) =>\n setCollapsedGroups({\n ...collapsedGroups,\n [title]: collapsedGroups[title] !== true,\n });\n\n const navTree = (\n <SidebarNav\n sections={nav}\n collapsed={collapsed}\n collapsedGroups={collapsedGroups}\n onToggleGroup={toggleGroup}\n />\n );\n\n const isCompact = mode === 'compact';\n\n return (\n <>\n {/* The first stop on every page: past the navigation, to the content\n (WCAG 2.4.1). Hidden until it is focused. */}\n <a\n href={`#${MAIN_ID}`}\n className=\"sr-only rounded-md bg-surface-elevated px-s py-2xs text-step-sm text-content shadow-overlay focus-ring focus:not-sr-only focus:fixed focus:top-s focus:left-s focus:z-(--z-overlay)\"\n >\n {t('sidebar.skipToContent')}\n </a>\n <BreadcrumbLabelsProvider>\n <Sidebar gap=\"none\" className=\"min-h-screen\">\n {isCompact ? null : (\n <Sidebar.Side\n as=\"aside\"\n width={collapsed ? '4.5rem' : '16rem'}\n className=\"md:sticky md:top-0 md:h-screen md:overflow-y-auto flex flex-col gap-m border-r border-border bg-surface-elevated p-s\"\n >\n <div className=\"flex items-center justify-center px-2xs py-3xs text-step-1 font-semibold text-content\">\n {collapsed ? null : brand}\n </div>\n {navTree}\n </Sidebar.Side>\n )}\n\n <Sidebar.Main\n as=\"main\"\n id={MAIN_ID}\n // The skip link's target: focusable from it, never a Tab stop.\n tabIndex={-1}\n className=\"flex flex-col outline-none\"\n >\n <header className=\"flex items-center gap-s border-b border-border bg-surface-elevated px-m py-s\">\n <Button\n variant=\"ghost\"\n size=\"sm\"\n aria-label={\n isCompact\n ? t('sidebar.openMenu')\n : collapsed\n ? t('sidebar.expand')\n : t('sidebar.collapse')\n }\n // A drawer trigger is not a two-state toggle — it opens a thing that\n // closes itself — so it reports pressed state only where it is one.\n {...(isCompact ? {} : { 'aria-pressed': collapsed })}\n onClick={() =>\n isCompact\n ? setDrawerOpen(true)\n : setCollapsed(!preferCollapsed)\n }\n >\n <span aria-hidden=\"true\">☰</span>\n </Button>\n <BackOfficeBreadcrumbs labels={breadcrumbLabels} />\n <div className=\"ml-auto flex items-center gap-2xs\">\n {commandPalette}\n {accountMenu}\n </div>\n </header>\n <div className=\"flex-1 p-m\">{children}</div>\n </Sidebar.Main>\n\n {isCompact && (\n <Drawer\n open={isDrawerOpen}\n onClose={() => setDrawerOpen(false)}\n title={brand}\n closeLabel={t('sidebar.closeMenu')}\n >\n {navTree}\n </Drawer>\n )}\n </Sidebar>\n </BreadcrumbLabelsProvider>\n </>\n );\n}\n"],"names":["Button","Drawer","Sidebar","useT","useUiPreference","useViewportMode","usePathname","useState","BreadcrumbLabelsProvider","BackOfficeBreadcrumbs","SidebarNav","SIDEBAR_PREF_KEY","NAV_GROUPS_PREF_KEY","MAIN_ID","BackOfficeShell","nav","brand","children","breadcrumbLabels","accountMenu","commandPalette","t","mode","pathname","value","preferCollapsed","setValue","setCollapsed","collapsedGroups","setCollapsedGroups","openedAt","setOpenedAt","isDrawerOpen","setDrawerOpen","open","collapsed","toggleGroup","title","navTree","sections","onToggleGroup","isCompact","a","href","className","gap","Side","as","width","div","Main","id","tabIndex","header","variant","size","aria-label","onClick","span","aria-hidden","labels","onClose","closeLabel"],"mappings":"AAAA;;;AAEA,SACEA,MAAM,EACNC,MAAM,EACNC,OAAO,EACPC,IAAI,EACJC,eAAe,EACfC,eAAe,QACV,0BAA0B;AACjC,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAAyBC,QAAQ,QAAQ,QAAQ;AAEjD,SAASC,wBAAwB,QAAQ,yBAAyB;AAClE,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,SAASC,UAAU,QAAQ,mBAAmB;AAE9C,yFAAyF,GACzF,MAAMC,mBAAmB;AAEzB;;;;CAIC,GACD,MAAMC,sBAAsB;AA8B5B;;;;;;;;;;;;;;;;;;CAkBC,GACD,0DAA0D,GAC1D,MAAMC,UAAU;AAEhB,OAAO,SAASC,gBAAgB,EAC9BC,GAAG,EACHC,KAAK,EACLC,QAAQ,EACRC,gBAAgB,EAChBC,WAAW,EACXC,cAAc,EACO;IACrB,MAAMC,IAAIlB,KAAK;IACf,MAAMmB,OAAOjB;IACb,MAAMkB,WAAWjB;IACjB,MAAM,EAAEkB,OAAOC,eAAe,EAAEC,UAAUC,YAAY,EAAE,GACtDvB,gBAAyBO,kBAAkB;IAC7C,MAAM,EAAEa,OAAOI,eAAe,EAAEF,UAAUG,kBAAkB,EAAE,GAC5DzB,gBAAyCQ,qBAAqB,CAAC;IACjE,yEAAyE;IACzE,4EAA4E;IAC5E,8EAA8E;IAC9E,+EAA+E;IAC/E,8EAA8E;IAC9E,mDAAmD;IACnD,MAAM,CAACkB,UAAUC,YAAY,GAAGxB,SAAwB;IACxD,MAAMyB,eAAeF,aAAa,QAAQA,aAAaP;IACvD,MAAMU,gBAAgB,CAACC,OAAkBH,YAAYG,OAAOX,WAAW;IAEvE,0EAA0E;IAC1E,8EAA8E;IAC9E,4EAA4E;IAC5E,sBAAsB;IACtB,MAAMY,YACJb,SAAS,SAAS,OAAOA,SAAS,YAAY,QAAQG;IACxD,MAAMW,cAAc,CAACC,QACnBR,mBAAmB,aACdD;YACH,CAACS,MAAM,EAAET,eAAe,CAACS,MAAM,KAAK;;IAGxC,MAAMC,wBACJ,KAAC5B;QACC6B,UAAUxB;QACVoB,WAAWA;QACXP,iBAAiBA;QACjBY,eAAeJ;;IAInB,MAAMK,YAAYnB,SAAS;IAE3B,qBACE;;0BAGE,KAACoB;gBACCC,MAAM,CAAC,CAAC,EAAE9B,SAAS;gBACnB+B,WAAU;0BAETvB,EAAE;;0BAEL,KAACb;0BACC,cAAA,MAACN;oBAAQ2C,KAAI;oBAAOD,WAAU;;wBAC3BH,YAAY,qBACX,MAACvC,QAAQ4C,IAAI;4BACXC,IAAG;4BACHC,OAAOb,YAAY,WAAW;4BAC9BS,WAAU;;8CAEV,KAACK;oCAAIL,WAAU;8CACZT,YAAY,OAAOnB;;gCAErBsB;;;sCAIL,MAACpC,QAAQgD,IAAI;4BACXH,IAAG;4BACHI,IAAItC;4BACJ,+DAA+D;4BAC/DuC,UAAU,CAAC;4BACXR,WAAU;;8CAEV,MAACS;oCAAOT,WAAU;;sDAChB,KAAC5C;4CACCsD,SAAQ;4CACRC,MAAK;4CACLC,cACEf,YACIpB,EAAE,sBACFc,YACEd,EAAE,oBACFA,EAAE;2CAILoB,YAAY,CAAC,IAAI;4CAAE,gBAAgBN;wCAAU;4CAClDsB,SAAS,IACPhB,YACIR,cAAc,QACdN,aAAa,CAACF;sDAGpB,cAAA,KAACiC;gDAAKC,eAAY;0DAAO;;;sDAE3B,KAAClD;4CAAsBmD,QAAQ1C;;sDAC/B,MAAC+B;4CAAIL,WAAU;;gDACZxB;gDACAD;;;;;8CAGL,KAAC8B;oCAAIL,WAAU;8CAAc3B;;;;wBAG9BwB,2BACC,KAACxC;4BACCiC,MAAMF;4BACN6B,SAAS,IAAM5B,cAAc;4BAC7BI,OAAOrB;4BACP8C,YAAYzC,EAAE;sCAEbiB;;;;;;;AAOf"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
/** Shown for a record's crumb while the record is still being read. */
|
|
3
|
+
export declare const PENDING_CRUMB = "\u2026";
|
|
4
|
+
/**
|
|
5
|
+
* Holds the labels a page knows for its own path segments — a record page
|
|
6
|
+
* knows its record's name, which the shell's breadcrumbs cannot (#200).
|
|
7
|
+
*/
|
|
8
|
+
export declare function BreadcrumbLabelsProvider({ children, }: {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
11
|
+
/** The labels pages have given for their segments. */
|
|
12
|
+
export declare const useBreadcrumbLabels: () => Readonly<Record<string, string>>;
|
|
13
|
+
/**
|
|
14
|
+
* Names a path segment in the breadcrumbs for as long as the calling page is
|
|
15
|
+
* mounted: a record's id reads as the record. `undefined` while the name is
|
|
16
|
+
* still loading shows a placeholder rather than the id. Outside a shell with
|
|
17
|
+
* breadcrumbs — a workspace tab — it does nothing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useBreadcrumbLabel(segment: string | undefined, label: string | undefined): void;
|
|
20
|
+
//# sourceMappingURL=breadcrumb-labels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"breadcrumb-labels.d.ts","sourceRoot":"","sources":["../../../src/lib/back-office/breadcrumb-labels.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AAEf,uEAAuE;AACvE,eAAO,MAAM,aAAa,WAAM,CAAC;AAWjC;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,+BAeA;AAED,sDAAsD;AACtD,eAAO,MAAM,mBAAmB,QAAO,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CACnB,CAAC;AAEpD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,IAAI,CAON"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
|
5
|
+
/** Shown for a record's crumb while the record is still being read. */ export const PENDING_CRUMB = '…';
|
|
6
|
+
const BreadcrumbLabelsContext = /*#__PURE__*/ createContext(undefined);
|
|
7
|
+
/**
|
|
8
|
+
* Holds the labels a page knows for its own path segments — a record page
|
|
9
|
+
* knows its record's name, which the shell's breadcrumbs cannot (#200).
|
|
10
|
+
*/ export function BreadcrumbLabelsProvider({ children }) {
|
|
11
|
+
const [labels, setLabels] = useState({});
|
|
12
|
+
const set = useCallback((segment, label)=>{
|
|
13
|
+
setLabels((current)=>{
|
|
14
|
+
const next = _extends({}, current);
|
|
15
|
+
if (label === undefined) delete next[segment];
|
|
16
|
+
else next[segment] = label;
|
|
17
|
+
return next;
|
|
18
|
+
});
|
|
19
|
+
}, []);
|
|
20
|
+
return /*#__PURE__*/ _jsx(BreadcrumbLabelsContext.Provider, {
|
|
21
|
+
value: {
|
|
22
|
+
labels,
|
|
23
|
+
set
|
|
24
|
+
},
|
|
25
|
+
children: children
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** The labels pages have given for their segments. */ export const useBreadcrumbLabels = ()=>{
|
|
29
|
+
var _ref;
|
|
30
|
+
var _useContext;
|
|
31
|
+
return (_ref = (_useContext = useContext(BreadcrumbLabelsContext)) == null ? void 0 : _useContext.labels) != null ? _ref : {};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Names a path segment in the breadcrumbs for as long as the calling page is
|
|
35
|
+
* mounted: a record's id reads as the record. `undefined` while the name is
|
|
36
|
+
* still loading shows a placeholder rather than the id. Outside a shell with
|
|
37
|
+
* breadcrumbs — a workspace tab — it does nothing.
|
|
38
|
+
*/ export function useBreadcrumbLabel(segment, label) {
|
|
39
|
+
var _useContext;
|
|
40
|
+
const set = (_useContext = useContext(BreadcrumbLabelsContext)) == null ? void 0 : _useContext.set;
|
|
41
|
+
useEffect(()=>{
|
|
42
|
+
if (set === undefined || segment === undefined) return;
|
|
43
|
+
set(segment, label != null ? label : PENDING_CRUMB);
|
|
44
|
+
return ()=>set(segment, undefined);
|
|
45
|
+
}, [
|
|
46
|
+
set,
|
|
47
|
+
segment,
|
|
48
|
+
label
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=breadcrumb-labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/back-office/breadcrumb-labels.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useState,\n} from 'react';\n\n/** Shown for a record's crumb while the record is still being read. */\nexport const PENDING_CRUMB = '…';\n\ninterface BreadcrumbLabels {\n readonly labels: Readonly<Record<string, string>>;\n readonly set: (segment: string, label: string | undefined) => void;\n}\n\nconst BreadcrumbLabelsContext = createContext<BreadcrumbLabels | undefined>(\n undefined,\n);\n\n/**\n * Holds the labels a page knows for its own path segments — a record page\n * knows its record's name, which the shell's breadcrumbs cannot (#200).\n */\nexport function BreadcrumbLabelsProvider({\n children,\n}: {\n children: ReactNode;\n}) {\n const [labels, setLabels] = useState<Record<string, string>>({});\n const set = useCallback((segment: string, label: string | undefined) => {\n setLabels(current => {\n const next = { ...current };\n if (label === undefined) delete next[segment];\n else next[segment] = label;\n return next;\n });\n }, []);\n return (\n <BreadcrumbLabelsContext.Provider value={{ labels, set }}>\n {children}\n </BreadcrumbLabelsContext.Provider>\n );\n}\n\n/** The labels pages have given for their segments. */\nexport const useBreadcrumbLabels = (): Readonly<Record<string, string>> =>\n useContext(BreadcrumbLabelsContext)?.labels ?? {};\n\n/**\n * Names a path segment in the breadcrumbs for as long as the calling page is\n * mounted: a record's id reads as the record. `undefined` while the name is\n * still loading shows a placeholder rather than the id. Outside a shell with\n * breadcrumbs — a workspace tab — it does nothing.\n */\nexport function useBreadcrumbLabel(\n segment: string | undefined,\n label: string | undefined,\n): void {\n const set = useContext(BreadcrumbLabelsContext)?.set;\n useEffect(() => {\n if (set === undefined || segment === undefined) return;\n set(segment, label ?? PENDING_CRUMB);\n return () => set(segment, undefined);\n }, [set, segment, label]);\n}\n"],"names":["createContext","useCallback","useContext","useEffect","useState","PENDING_CRUMB","BreadcrumbLabelsContext","undefined","BreadcrumbLabelsProvider","children","labels","setLabels","set","segment","label","current","next","Provider","value","useBreadcrumbLabels","useBreadcrumbLabel"],"mappings":"AAAA;;;AAEA,SACEA,aAAa,EAEbC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,QAAQ,QACH,QAAQ;AAEf,qEAAqE,GACrE,OAAO,MAAMC,gBAAgB,IAAI;AAOjC,MAAMC,wCAA0BN,cAC9BO;AAGF;;;CAGC,GACD,OAAO,SAASC,yBAAyB,EACvCC,QAAQ,EAGT;IACC,MAAM,CAACC,QAAQC,UAAU,GAAGP,SAAiC,CAAC;IAC9D,MAAMQ,MAAMX,YAAY,CAACY,SAAiBC;QACxCH,UAAUI,CAAAA;YACR,MAAMC,OAAO,aAAKD;YAClB,IAAID,UAAUP,WAAW,OAAOS,IAAI,CAACH,QAAQ;iBACxCG,IAAI,CAACH,QAAQ,GAAGC;YACrB,OAAOE;QACT;IACF,GAAG,EAAE;IACL,qBACE,KAACV,wBAAwBW,QAAQ;QAACC,OAAO;YAAER;YAAQE;QAAI;kBACpDH;;AAGP;AAEA,oDAAoD,GACpD,OAAO,MAAMU,sBAAsB;;QACjCjB;oBAAAA,cAAAA,WAAWI,6CAAXJ,YAAqCQ,MAAM,mBAAI,CAAC;EAAE;AAEpD;;;;;CAKC,GACD,OAAO,SAASU,mBACdP,OAA2B,EAC3BC,KAAyB;QAEbZ;IAAZ,MAAMU,OAAMV,cAAAA,WAAWI,6CAAXJ,YAAqCU,GAAG;IACpDT,UAAU;QACR,IAAIS,QAAQL,aAAaM,YAAYN,WAAW;QAChDK,IAAIC,SAASC,gBAAAA,QAAST;QACtB,OAAO,IAAMO,IAAIC,SAASN;IAC5B,GAAG;QAACK;QAAKC;QAASC;KAAM;AAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breadcrumbs.d.ts","sourceRoot":"","sources":["../../../src/lib/back-office/breadcrumbs.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,cAAc,EAGpB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"breadcrumbs.d.ts","sourceRoot":"","sources":["../../../src/lib/back-office/breadcrumbs.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,cAAc,EAGpB,MAAM,yBAAyB,CAAC;AAMjC,MAAM,WAAW,0BAA0B;IACzC;;gEAE4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAMD,0EAA0E;AAC1E,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,SAAS,EAAE,MAAM,GAChB,cAAc,EAAE,CAclB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,MAAW,GACZ,EAAE,0BAA0B,+BAwB5B"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
4
|
import { splitLocalePath } from '@entifix/core';
|
|
4
5
|
import { Breadcrumbs, useT } from '@entifix/react-controls';
|
|
5
6
|
import { usePathname } from 'next/navigation';
|
|
6
7
|
import { LocaleLink } from '../i18n/index.js';
|
|
8
|
+
import { useBreadcrumbLabels } from './breadcrumb-labels.js';
|
|
7
9
|
function humanize(segment) {
|
|
8
10
|
return segment.replace(/-/g, ' ').replace(/\b\w/g, (c)=>c.toUpperCase());
|
|
9
11
|
}
|
|
@@ -40,7 +42,10 @@ function humanize(segment) {
|
|
|
40
42
|
const t = useT('shell');
|
|
41
43
|
const controls = useT();
|
|
42
44
|
const pathname = (_usePathname = usePathname()) != null ? _usePathname : '/';
|
|
43
|
-
|
|
45
|
+
// What the page knows about its own segments — a record's name — over what
|
|
46
|
+
// the host mapped; an id never reads as a crumb.
|
|
47
|
+
const pageLabels = useBreadcrumbLabels();
|
|
48
|
+
const items = buildCrumbs(pathname, _extends({}, labels, pageLabels), t('breadcrumbs.home'));
|
|
44
49
|
return /*#__PURE__*/ _jsx(Breadcrumbs, {
|
|
45
50
|
label: controls('breadcrumbs.label'),
|
|
46
51
|
items: items,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/back-office/breadcrumbs.tsx"],"sourcesContent":["'use client';\n\nimport { splitLocalePath } from '@entifix/core';\nimport {\n type BreadcrumbItem,\n Breadcrumbs,\n useT,\n} from '@entifix/react-controls';\nimport { usePathname } from 'next/navigation';\n\nimport { LocaleLink } from '../i18n/index.js';\n\nexport interface BackOfficeBreadcrumbsProps {\n /** Map a path segment to an already-translated label; unmapped segments are\n * title-cased. Hosts resolve these through `useT` — the shell has no way to\n * know which namespace an app keeps its route names in. */\n labels?: Record<string, string>;\n}\n\nfunction humanize(segment: string): string {\n return segment.replace(/-/g, ' ').replace(/\\b\\w/g, c => c.toUpperCase());\n}\n\n/** Derives the crumb trail from a pathname. Exported for unit testing. */\nexport function buildCrumbs(\n pathname: string,\n labels: Record<string, string>,\n homeLabel: string,\n): BreadcrumbItem[] {\n const crumbs: BreadcrumbItem[] = [{ label: homeLabel, href: '/' }];\n let href = '';\n // The locale prefix is routing, not a place — a crumb reading \"Es\" would be\n // both meaningless and un-navigable.\n const { rest } = splitLocalePath(pathname);\n for (const segment of rest.split('/').filter(Boolean)) {\n href += `/${segment}`;\n crumbs.push({ label: labels[segment] ?? humanize(segment), href });\n }\n // The last crumb is the current page: drop its href so it renders as such.\n const last = crumbs[crumbs.length - 1];\n last.href = undefined;\n return crumbs;\n}\n\n/**\n * The root crumb is the shell's own copy: it names the shell's `/`, not\n * anything the host app authored. Apps used to pass their brand here\n * (\"Admin\", \"Identidad\"), which duplicated what the sidebar already shows.\n */\nexport function BackOfficeBreadcrumbs({\n labels = {},\n}: BackOfficeBreadcrumbsProps) {\n const t = useT('shell');\n const controls = useT();\n const pathname = usePathname() ?? '/';\n const items = buildCrumbs(pathname
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/back-office/breadcrumbs.tsx"],"sourcesContent":["'use client';\n\nimport { splitLocalePath } from '@entifix/core';\nimport {\n type BreadcrumbItem,\n Breadcrumbs,\n useT,\n} from '@entifix/react-controls';\nimport { usePathname } from 'next/navigation';\n\nimport { LocaleLink } from '../i18n/index.js';\nimport { useBreadcrumbLabels } from './breadcrumb-labels.js';\n\nexport interface BackOfficeBreadcrumbsProps {\n /** Map a path segment to an already-translated label; unmapped segments are\n * title-cased. Hosts resolve these through `useT` — the shell has no way to\n * know which namespace an app keeps its route names in. */\n labels?: Record<string, string>;\n}\n\nfunction humanize(segment: string): string {\n return segment.replace(/-/g, ' ').replace(/\\b\\w/g, c => c.toUpperCase());\n}\n\n/** Derives the crumb trail from a pathname. Exported for unit testing. */\nexport function buildCrumbs(\n pathname: string,\n labels: Record<string, string>,\n homeLabel: string,\n): BreadcrumbItem[] {\n const crumbs: BreadcrumbItem[] = [{ label: homeLabel, href: '/' }];\n let href = '';\n // The locale prefix is routing, not a place — a crumb reading \"Es\" would be\n // both meaningless and un-navigable.\n const { rest } = splitLocalePath(pathname);\n for (const segment of rest.split('/').filter(Boolean)) {\n href += `/${segment}`;\n crumbs.push({ label: labels[segment] ?? humanize(segment), href });\n }\n // The last crumb is the current page: drop its href so it renders as such.\n const last = crumbs[crumbs.length - 1];\n last.href = undefined;\n return crumbs;\n}\n\n/**\n * The root crumb is the shell's own copy: it names the shell's `/`, not\n * anything the host app authored. Apps used to pass their brand here\n * (\"Admin\", \"Identidad\"), which duplicated what the sidebar already shows.\n */\nexport function BackOfficeBreadcrumbs({\n labels = {},\n}: BackOfficeBreadcrumbsProps) {\n const t = useT('shell');\n const controls = useT();\n const pathname = usePathname() ?? '/';\n // What the page knows about its own segments — a record's name — over what\n // the host mapped; an id never reads as a crumb.\n const pageLabels = useBreadcrumbLabels();\n const items = buildCrumbs(\n pathname,\n { ...labels, ...pageLabels },\n t('breadcrumbs.home'),\n );\n\n return (\n <Breadcrumbs\n label={controls('breadcrumbs.label')}\n items={items}\n renderLink={item => (\n <LocaleLink href={item.href} className={item.className}>\n {item.label}\n </LocaleLink>\n )}\n />\n );\n}\n"],"names":["splitLocalePath","Breadcrumbs","useT","usePathname","LocaleLink","useBreadcrumbLabels","humanize","segment","replace","c","toUpperCase","buildCrumbs","pathname","labels","homeLabel","crumbs","label","href","rest","split","filter","Boolean","push","last","length","undefined","BackOfficeBreadcrumbs","t","controls","pageLabels","items","renderLink","item","className"],"mappings":"AAAA;;;AAEA,SAASA,eAAe,QAAQ,gBAAgB;AAChD,SAEEC,WAAW,EACXC,IAAI,QACC,0BAA0B;AACjC,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,SAASC,UAAU,QAAQ,mBAAmB;AAC9C,SAASC,mBAAmB,QAAQ,yBAAyB;AAS7D,SAASC,SAASC,OAAe;IAC/B,OAAOA,QAAQC,OAAO,CAAC,MAAM,KAAKA,OAAO,CAAC,SAASC,CAAAA,IAAKA,EAAEC,WAAW;AACvE;AAEA,wEAAwE,GACxE,OAAO,SAASC,YACdC,QAAgB,EAChBC,MAA8B,EAC9BC,SAAiB;IAEjB,MAAMC,SAA2B;QAAC;YAAEC,OAAOF;YAAWG,MAAM;QAAI;KAAE;IAClE,IAAIA,OAAO;IACX,4EAA4E;IAC5E,qCAAqC;IACrC,MAAM,EAAEC,IAAI,EAAE,GAAGlB,gBAAgBY;IACjC,KAAK,MAAML,WAAWW,KAAKC,KAAK,CAAC,KAAKC,MAAM,CAACC,SAAU;YAEhCR;QADrBI,QAAQ,CAAC,CAAC,EAAEV,SAAS;QACrBQ,OAAOO,IAAI,CAAC;YAAEN,KAAK,GAAEH,kBAAAA,MAAM,CAACN,QAAQ,YAAfM,kBAAmBP,SAASC;YAAUU;QAAK;IAClE;IACA,2EAA2E;IAC3E,MAAMM,OAAOR,MAAM,CAACA,OAAOS,MAAM,GAAG,EAAE;IACtCD,KAAKN,IAAI,GAAGQ;IACZ,OAAOV;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASW,sBAAsB,EACpCb,SAAS,CAAC,CAAC,EACgB;QAGVV;IAFjB,MAAMwB,IAAIzB,KAAK;IACf,MAAM0B,WAAW1B;IACjB,MAAMU,YAAWT,eAAAA,yBAAAA,eAAiB;IAClC,2EAA2E;IAC3E,iDAAiD;IACjD,MAAM0B,aAAaxB;IACnB,MAAMyB,QAAQnB,YACZC,UACA,aAAKC,QAAWgB,aAChBF,EAAE;IAGJ,qBACE,KAAC1B;QACCe,OAAOY,SAAS;QAChBE,OAAOA;QACPC,YAAYC,CAAAA,qBACV,KAAC5B;gBAAWa,MAAMe,KAAKf,IAAI;gBAAEgB,WAAWD,KAAKC,SAAS;0BACnDD,KAAKhB,KAAK;;;AAKrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/back-office/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/back-office/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC"}
|