@owlmeans/client-panel 0.1.18-rc.6 → 0.1.18-rc.9

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  # @owlmeans/client-panel
2
2
 
3
- Schema-driven React form components with react-hook-form integration, i18n, and action buttons.
3
+ Schema-driven React form components with react-hook-form integration, i18n, action buttons, and the
4
+ headless navigation model.
4
5
 
5
6
  ## Overview
6
7
 
@@ -9,6 +10,7 @@ Schema-driven React form components with react-hook-form integration, i18n, and
9
10
  - `InputCtrl` — labeled input field component backed by react-hook-form
10
11
  - `useFormRef()` — hook to get a ref for programmatic form operations
11
12
  - `FormOnSubmit` — type for form submission handler functions
13
+ - `usePanelNav()` — the model behind a two-layer navigation menu (no JSX)
12
14
  - Platform-agnostic: used by React web and React Native frontends
13
15
 
14
16
  ## Installation
@@ -81,6 +83,62 @@ type FormOnSubmit<T> = (data: T) => void | Promise<void>
81
83
 
82
84
  Derives default form values from an AJV schema's `default` fields.
83
85
 
86
+ ## Navigation model
87
+
88
+ Navigation is declared as data and rendered by the platform package
89
+ (`@owlmeans/web-panel` ships `NavLayout` / `TopNav` / `SideNav` / `Footer`). This package holds only
90
+ the model, so both levels of the menu agree on what is active.
91
+
92
+ ```typescript
93
+ import { usePanelNav } from '@owlmeans/client-panel'
94
+ import type { PanelNavConfig } from '@owlmeans/client-panel'
95
+
96
+ const config: PanelNavConfig = {
97
+ sections: [
98
+ { name: 'home', label: 'Home', items: [{ alias: HOME, label: 'Overview' }] },
99
+ { name: 'demo', items: [{ alias: web.session }, { alias: web.about }] },
100
+ ],
101
+ }
102
+
103
+ const model = usePanelNav(config)
104
+ ```
105
+
106
+ ### Types
107
+
108
+ - `PanelNavItem` — `{ alias, label?, Icon?, hidden? }`; one screen, addressed by entrypoint alias,
109
+ never by URL.
110
+ - `PanelNavSection` — `{ name, label?, items, hidden? }`; the first menu level. Pressing it goes to
111
+ the first visible item.
112
+ - `PanelNavConfig` — `{ sections }`.
113
+ - `PanelNavLink` — `{ alias? | href?, label?, open? }`; a footer link.
114
+ - `NavTranslate` — `(key, defaultValue) => string`.
115
+
116
+ ### `usePanelNav(config): PanelNavModel`
117
+
118
+ Returns `sections` (with `hidden` filtered out), `current` (the active screen's alias or null),
119
+ `active` (its section), `showSide`, `isSectionActive` / `isItemActive`, `goSection` / `goItem`
120
+ (each returning a handler), and `hrefOf(target)`.
121
+
122
+ - `showSide` is false when the active section holds a single screen — that is where the "one screen,
123
+ no second level" rule lives; a renderer asks the model rather than counting items.
124
+ - The current screen resolves from the router's `location.state.alias` when present, and otherwise
125
+ from the pathname matched against resolved entrypoint paths — exact first, then longest prefix.
126
+ Both are needed: `state` is `window.history.state`, so it is empty on a hard load or deep link. A
127
+ screen listed in no section resolves its section by walking `getParentAlias()` upward.
128
+ - `hrefOf` resolves a real URL synchronously so a menu entry can be a proper link (focusable,
129
+ keyboard-operable, openable in a new tab). It returns `undefined` for a path carrying route
130
+ parameters.
131
+
132
+ ### `resolveNavLabel(translate, label, key, alias)`
133
+
134
+ Resolves a label as literal `label` → `translate(key, defaultNavLabel(alias))` → the humanized
135
+ alias. `translate` always reaches a component as a **prop**, defaulting to `defaultNavTranslate`
136
+ (which returns the fallback) — a menu must never read an i18n context implicitly, because an app
137
+ mounted without an i18n provider throws inside render and blanks the page. `defaultNavLabel`
138
+ humanizes the last alias segment
139
+ (`my-app:web:user-list` → `User list`). Default key families are `nav.<section>` and
140
+ `modules.<alias>`.
141
+
84
142
  ## Related Packages
85
143
 
86
144
  - [`@owlmeans/client`](../client) — `useContext`, `useNavigate` used within form components
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/client-panel",
4
- "version": "0.1.18-rc.6",
5
- "generatedAt": "2026-08-18T14:48:00.543Z",
4
+ "version": "0.1.18-rc.9",
5
+ "generatedAt": "2026-08-24T21:14:00.134Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: client-panel
3
- description: How to use @owlmeans/client-panel — reusable cross-platform UI panel + form components (auth screens, layouts) shared by web-panel and native-panel. Auto-invoked when importing panel components.
3
+ description: How to use @owlmeans/client-panel — reusable cross-platform UI panel + form components (auth screens, layouts) and the headless navigation model (usePanelNav) shared by web-panel and native-panel. Auto-invoked when importing panel components or building a navigation menu.
4
4
  user-invocable: false
5
5
  ---
6
6
  <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
@@ -8,13 +8,16 @@ user-invocable: false
8
8
  # @owlmeans/client-panel
9
9
 
10
10
  **Layer:** Client
11
- **Install:** `"@owlmeans/client-panel": "^0.1.18-rc.6"` in `dependencies`
11
+ **Install:** `"@owlmeans/client-panel": "^0.1.18-rc.9"` in `dependencies`
12
12
 
13
13
  ## Key Exports
14
14
 
15
15
  | Export | Description |
16
16
  |--------|-------------|
17
17
  | `components` submodule | Cross-platform panel/form components |
18
+ | `usePanelNav(config)` | Headless navigation model behind a two-layer menu |
19
+ | `resolveNavLabel`, `defaultNavLabel`, `defaultNavTranslate` | Label resolution helpers |
20
+ | `PanelNavConfig`, `PanelNavSection`, `PanelNavItem`, `PanelNavLink`, `PanelNavModel`, `NavTranslate` | Navigation types |
18
21
  | `helpers` submodule | Layout / form helpers |
19
22
 
20
23
  ## Subpath Exports
@@ -29,9 +32,63 @@ import { Panel } from '@owlmeans/client-panel'
29
32
  import { LoginPanel } from '@owlmeans/client-panel/auth'
30
33
  ```
31
34
 
32
- `@owlmeans/web-panel` re-exports these and provides the Material-UI implementations.
35
+ `@owlmeans/web-panel` re-exports these and provides the rendered implementations.
36
+
37
+ ## Navigation model — `usePanelNav`
38
+
39
+ The **model lives here, the JSX lives in the platform package** — the same split the form and panel
40
+ components already use. `usePanelNav` is headless and cross-platform; `@owlmeans/web-panel` renders
41
+ it as `TopNav`/`SideNav`/`NavLayout`. Never put a rendered menu in this package, and never
42
+ re-derive active state in a renderer.
43
+
44
+ Navigation is declared as data. A **section** is the first menu level; its **items** are the screens
45
+ the second level offers while that section is active. An item addresses a frontend entrypoint by
46
+ `alias` and never carries a URL — the router resolves it, so a path that changes shape stays correct
47
+ everywhere it is rendered.
48
+
49
+ ```ts
50
+ import { usePanelNav } from '@owlmeans/client-panel'
51
+ import type { PanelNavConfig } from '@owlmeans/client-panel'
52
+
53
+ const config: PanelNavConfig = {
54
+ sections: [
55
+ { name: 'home', label: 'Home', items: [{ alias: HOME, label: 'Overview' }] },
56
+ { name: 'demo', items: [{ alias: web.session }, { alias: web.about }] },
57
+ ],
58
+ }
59
+
60
+ const model = usePanelNav(config)
61
+ ```
62
+
63
+ `PanelNavModel` carries `sections` (with `hidden` filtered out), `current` (the active screen's
64
+ alias, or null), `active` (its section), `showSide`, `isSectionActive` / `isItemActive`,
65
+ `goSection` / `goItem` (each returning a handler), and `hrefOf`.
66
+
67
+ - **`showSide` owns the one-screen rule.** It is false when the active section holds a single
68
+ screen — a second level offering the page you are already on is noise. A renderer asks the model;
69
+ it does not count items itself.
70
+ - **Label resolution never touches i18n implicitly.** `NavTranslate` is a `(key, defaultValue) =>
71
+ string` **prop**, defaulting to `defaultNavTranslate`, which returns the fallback. An app mounted
72
+ without an i18n provider (`renderApp` from `@owlmeans/web-client` mounts none) crashes if a menu
73
+ reaches for the panel i18n context: the hook dereferences `i18n.options` on the empty object
74
+ `react-i18next` returns without an instance, and a throw inside render blanks the whole app.
75
+ `resolveNavLabel(translate, label, key, alias)` applies the order — literal `label` →
76
+ `translate(key, humanized)` → `defaultNavLabel(alias)`, which humanizes the last alias segment
77
+ (`my-app:web:user-list` → `User list`). Default key families: `nav.<name>` for sections,
78
+ `modules.<alias>` for items and footer links.
79
+ - **Resolving the current screen needs two sources.** The router's `location.state.alias` is
80
+ authoritative but is `window.history.state`, so it is null until the first in-app navigation — on
81
+ a hard page load or a deep link a menu keyed on it alone highlights nothing, on exactly the entry
82
+ that matters most. The pathname is the fallback: resolved entrypoint paths are matched exactly
83
+ first, then by longest prefix, so a detail screen under a listed one still belongs to its section.
84
+ A screen listed in no section resolves its section by walking `getParentAlias()` upward.
85
+ - **`hrefOf` gives a menu entry a real URL**, resolved synchronously from
86
+ `context.entrypoint(alias).getPath()`. It returns undefined for a path carrying route parameters
87
+ (`:id`) — there is no honest URL for a screen whose address is not known yet. An alias the app
88
+ never elevated resolves to null and is skipped rather than taking the menu down.
33
89
 
34
90
  ## Depends On
35
91
 
36
- - `@owlmeans/client`, `@owlmeans/client-auth`, `@owlmeans/client-i18n`
92
+ - `@owlmeans/client`, `@owlmeans/client-i18n`, `@owlmeans/client-entrypoint`, `@owlmeans/client-route`,
93
+ `@owlmeans/entrypoint`, `@owlmeans/error`
37
94
  - `react` (peer)
@@ -1,6 +1,7 @@
1
1
  export type * from './types.js';
2
2
  export * from './form/index.js';
3
3
  export * from './layout/index.js';
4
+ export * from './nav/index.js';
4
5
  export * from './context.js';
5
6
  export * from './consts.js';
6
7
  export * from './status.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAE/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAE/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
@@ -1,5 +1,6 @@
1
1
  export * from './form/index.js';
2
2
  export * from './layout/index.js';
3
+ export * from './nav/index.js';
3
4
  export * from './context.js';
4
5
  export * from './consts.js';
5
6
  export * from './status.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,21 @@
1
+ import type { NavTranslate, PanelNavConfig, PanelNavModel } from './types.js';
2
+ /** Default resolver: no i18n, the caller's fallback wins. See {@link NavTranslate}. */
3
+ export declare const defaultNavTranslate: NavTranslate;
4
+ /**
5
+ * Turn an alias into something readable — `my-app:web:user-list` becomes `User list`.
6
+ * The last segment is the meaningful one; the prefixes address the app, not the screen.
7
+ */
8
+ export declare const defaultNavLabel: (alias: string) => string;
9
+ export declare const resolveNavLabel: (translate: NavTranslate, label: string | undefined, key: string, alias?: string) => string;
10
+ /**
11
+ * The navigation model behind both menus.
12
+ *
13
+ * Resolving the CURRENT screen has two sources, and both are needed. The router carries the
14
+ * alias in `location.state`, which is authoritative — but `state` is `window.history.state`,
15
+ * so it is null until the first in-app navigation: on a hard page load or a deep link there
16
+ * is nothing there, and a menu keyed on it alone highlights nothing on exactly the entry that
17
+ * matters most. The pathname is the fallback: entrypoint paths are resolved by the time the
18
+ * router renders, so matching them is a lookup, not a guess.
19
+ */
20
+ export declare const usePanelNav: (config: PanelNavConfig) => PanelNavModel;
21
+ //# sourceMappingURL=helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/components/nav/helper.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAgB,aAAa,EAAmB,MAAM,YAAY,CAAA;AAE5G,uFAAuF;AACvF,eAAO,MAAM,mBAAmB,EAAE,YAAmD,CAAA;AAErF;;;GAGG;AACH,eAAO,MAAM,eAAe,UAAW,MAAM,KAAG,MAK/C,CAAA;AAED,eAAO,MAAM,eAAe,cACf,YAAY,SAAS,MAAM,GAAG,SAAS,OAAO,MAAM,UAAU,MAAM,KAC9E,MAAgE,CAAA;AAQnE;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,WAAY,cAAc,KAAG,aA6FpD,CAAA"}
@@ -0,0 +1,111 @@
1
+ import { useMemo } from 'react';
2
+ import { useContext, useNavigate } from '@owlmeans/client';
3
+ /** Default resolver: no i18n, the caller's fallback wins. See {@link NavTranslate}. */
4
+ export const defaultNavTranslate = (_key, defaultValue) => defaultValue;
5
+ /**
6
+ * Turn an alias into something readable — `my-app:web:user-list` becomes `User list`.
7
+ * The last segment is the meaningful one; the prefixes address the app, not the screen.
8
+ */
9
+ export const defaultNavLabel = (alias) => {
10
+ const segment = alias.split(/[:.]/).filter(part => part !== '').pop() ?? alias;
11
+ const words = segment.replace(/[-_]+/g, ' ').trim();
12
+ return words.charAt(0).toUpperCase() + words.slice(1);
13
+ };
14
+ export const resolveNavLabel = (translate, label, key, alias) => label ?? translate(key, defaultNavLabel(alias ?? key));
15
+ const visibleItems = (section) => section.items.filter(item => item.hidden !== true);
16
+ const normalizePath = (path) => path.length > 1 && path.endsWith('/') ? path.slice(0, -1) : path;
17
+ /**
18
+ * The navigation model behind both menus.
19
+ *
20
+ * Resolving the CURRENT screen has two sources, and both are needed. The router carries the
21
+ * alias in `location.state`, which is authoritative — but `state` is `window.history.state`,
22
+ * so it is null until the first in-app navigation: on a hard page load or a deep link there
23
+ * is nothing there, and a menu keyed on it alone highlights nothing on exactly the entry that
24
+ * matters most. The pathname is the fallback: entrypoint paths are resolved by the time the
25
+ * router renders, so matching them is a lookup, not a guess.
26
+ */
27
+ export const usePanelNav = (config) => {
28
+ const context = useContext();
29
+ const nav = useNavigate();
30
+ const location = context.router().useLocation();
31
+ const state = location.state;
32
+ const pathname = location.pathname;
33
+ return useMemo(() => {
34
+ const sections = config.sections
35
+ .filter(section => section.hidden !== true)
36
+ .map(section => ({ ...section, items: visibleItems(section) }));
37
+ const pathOf = (alias) => {
38
+ try {
39
+ return normalizePath(context.entrypoint(alias).getPath());
40
+ }
41
+ catch {
42
+ // An alias the app never elevated addresses nothing — it cannot be the current screen,
43
+ // and it must not take the menu down with it.
44
+ return null;
45
+ }
46
+ };
47
+ const all = sections.flatMap(section => section.items);
48
+ let current = state?.alias ?? null;
49
+ if (current == null) {
50
+ const here = normalizePath(pathname);
51
+ const exact = all.find(item => pathOf(item.alias) === here);
52
+ if (exact != null) {
53
+ current = exact.alias;
54
+ }
55
+ else {
56
+ // Longest prefix: a detail screen under a listed one still belongs to its section.
57
+ const prefixed = all
58
+ .map(item => ({ item, path: pathOf(item.alias) }))
59
+ .filter((entry) => entry.path != null && entry.path !== '/' && here.startsWith(`${entry.path}/`))
60
+ .sort((a, b) => b.path.length - a.path.length)[0];
61
+ current = prefixed?.item.alias ?? null;
62
+ }
63
+ }
64
+ const sectionOf = (alias) => alias == null ? null : sections.find(section => section.items.some(item => item.alias === alias)) ?? null;
65
+ let active = sectionOf(current);
66
+ if (active == null && current != null) {
67
+ // The current screen is not listed anywhere — walk up to the ancestor that is, so a
68
+ // nested screen keeps its section (and its side menu) rather than clearing the chrome.
69
+ let alias = current;
70
+ const seen = new Set();
71
+ while (alias != null && !seen.has(alias)) {
72
+ seen.add(alias);
73
+ try {
74
+ alias = context.entrypoint(alias).getParentAlias() ?? null;
75
+ }
76
+ catch {
77
+ alias = null;
78
+ }
79
+ const found = sectionOf(alias);
80
+ if (found != null) {
81
+ active = found;
82
+ break;
83
+ }
84
+ }
85
+ }
86
+ const isItemActive = (item) => item.alias === current;
87
+ const isSectionActive = (section) => active != null && section.name === active.name;
88
+ return {
89
+ sections,
90
+ current,
91
+ active,
92
+ showSide: active != null && active.items.length > 1,
93
+ isSectionActive,
94
+ isItemActive,
95
+ goSection: section => {
96
+ const first = section.items[0];
97
+ return first != null ? nav.press(first.alias) : () => { };
98
+ },
99
+ goItem: item => nav.press(item.alias),
100
+ hrefOf: target => {
101
+ const alias = 'alias' in target ? target.alias : target.items[0]?.alias;
102
+ if (alias == null) {
103
+ return undefined;
104
+ }
105
+ const path = pathOf(alias);
106
+ return path == null || path.includes(':') ? undefined : path;
107
+ },
108
+ };
109
+ }, [config, pathname, state?.alias, context, nav]);
110
+ };
111
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/components/nav/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAI/B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAI1D,uFAAuF;AACvF,MAAM,CAAC,MAAM,mBAAmB,GAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC,YAAY,CAAA;AAErF;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAa,EAAU,EAAE;IACvD,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,CAAA;IAC9E,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IAEnD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACvD,CAAC,CAAA;AAED,MAAM,C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AAC,CAAC,CAAA;AACpD,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export type * from './types.js';
2
+ export * from './helper.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/nav/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAE/B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './helper.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/nav/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA"}
@@ -0,0 +1,76 @@
1
+ import type { ComponentType } from 'react';
2
+ /**
3
+ * One screen in the navigation — the second menu level.
4
+ *
5
+ * `alias` addresses a frontend entrypoint, so an item never carries a URL: the router
6
+ * resolves it, and a path that changes shape stays correct everywhere it is rendered.
7
+ */
8
+ export interface PanelNavItem {
9
+ alias: string;
10
+ /** Literal label. Absent, the label is resolved through `translate` and falls back to a humanized alias. */
11
+ label?: string;
12
+ Icon?: ComponentType<{
13
+ className?: string;
14
+ }>;
15
+ hidden?: boolean;
16
+ }
17
+ /**
18
+ * One section — the first menu level. Its items are the screens the side menu offers
19
+ * while the section is active.
20
+ */
21
+ export interface PanelNavSection {
22
+ /** Stable key. Also the default translation key (`nav.<name>`). */
23
+ name: string;
24
+ label?: string;
25
+ /** Ordered. The first visible item is where pressing the section navigates. */
26
+ items: PanelNavItem[];
27
+ hidden?: boolean;
28
+ }
29
+ export interface PanelNavConfig {
30
+ sections: PanelNavSection[];
31
+ }
32
+ /** A footer link: exactly one of `alias` (an entrypoint) or `href` (anything else). */
33
+ export interface PanelNavLink {
34
+ alias?: string;
35
+ href?: string;
36
+ label?: string;
37
+ /** Open in a new tab. */
38
+ open?: boolean;
39
+ }
40
+ /**
41
+ * Resolves a label from a translation key.
42
+ *
43
+ * It is a PROP, never an implicit context read: an app that mounts without an i18n provider
44
+ * (`renderApp` from `@owlmeans/web-client` does) must still render a menu, and reaching for
45
+ * the panel i18n context there throws inside the render tree and blanks the whole app.
46
+ * The default returns the fallback, so literal labels work with no i18n at all.
47
+ */
48
+ export interface NavTranslate {
49
+ (key: string, defaultValue: string): string;
50
+ }
51
+ export interface PanelNavModel {
52
+ /** Sections and items with `hidden` filtered out. */
53
+ sections: PanelNavSection[];
54
+ /** Alias of the screen currently rendered, when it could be resolved. */
55
+ current: string | null;
56
+ active: PanelNavSection | null;
57
+ /**
58
+ * Whether the side menu carries anything worth showing — false when the active section
59
+ * holds a single screen, which is the whole point: one screen needs no second level.
60
+ */
61
+ showSide: boolean;
62
+ isSectionActive: (section: PanelNavSection) => boolean;
63
+ isItemActive: (item: PanelNavItem) => boolean;
64
+ goSection: (section: PanelNavSection) => () => void;
65
+ goItem: (item: PanelNavItem) => () => void;
66
+ /**
67
+ * The resolved URL of a section's landing screen, when it has one.
68
+ *
69
+ * A menu entry navigates through `nav.press`, but it still has to BE a link: an `<a>`
70
+ * without `href` is not focusable, does not answer the keyboard, and cannot be opened in a
71
+ * new tab. Undefined for a path carrying route parameters — there is no honest URL to show
72
+ * for a screen whose address is not known yet.
73
+ */
74
+ hrefOf: (target: PanelNavItem | PanelNavSection) => string | undefined;
75
+ }
76
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/nav/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1C;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,4GAA4G;IAC5G,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,aAAa,CAAC;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC5C,MAAM,CAAC,EAAE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};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/nav/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/client-panel",
3
- "version": "0.1.18-rc.6",
3
+ "version": "0.1.18-rc.9",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -36,16 +36,16 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@hookform/resolvers": "^5.2.2",
39
- "@owlmeans/client": "^0.1.18-rc.6",
40
- "@owlmeans/client-i18n": "^0.1.18-rc.6",
41
- "@owlmeans/client-entrypoint": "^0.1.18-rc.6",
42
- "@owlmeans/client-route": "^0.1.18-rc.6",
39
+ "@owlmeans/client": "^0.1.18-rc.8",
40
+ "@owlmeans/client-i18n": "^0.1.18-rc.7",
41
+ "@owlmeans/client-entrypoint": "^0.1.18-rc.7",
42
+ "@owlmeans/client-route": "^0.1.18-rc.7",
43
43
  "@owlmeans/error": "^0.1.18-rc.6",
44
- "@owlmeans/entrypoint": "^0.1.18-rc.6"
44
+ "@owlmeans/entrypoint": "^0.1.18-rc.7"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@owlmeans/auth": "^0.1.18-rc.6",
48
- "@owlmeans/client-auth": "^0.1.18-rc.6",
48
+ "@owlmeans/client-auth": "^0.1.18-rc.9",
49
49
  "@owlmeans/i18n": "^0.1.18-rc.6",
50
50
  "@owlmeans/router": "^0.1.18-rc.6",
51
51
  "ajv": "*",
@@ -63,7 +63,7 @@
63
63
  "devDependencies": {
64
64
  "@owlmeans/dep-config": "workspace:*",
65
65
  "@owlmeans/auth": "^0.1.18-rc.6",
66
- "@owlmeans/client-auth": "^0.1.18-rc.6",
66
+ "@owlmeans/client-auth": "^0.1.18-rc.9",
67
67
  "@types/react": "^19.2.17",
68
68
  "nodemon": "^3.1.14",
69
69
  "react-hook-form": "^7.53.0",
@@ -2,6 +2,7 @@ export type * from './types.js'
2
2
 
3
3
  export * from './form/index.js'
4
4
  export * from './layout/index.js'
5
+ export * from './nav/index.js'
5
6
  export * from './context.js'
6
7
  export * from './consts.js'
7
8
  export * from './status.js'
@@ -0,0 +1,136 @@
1
+ import { useMemo } from 'react'
2
+ import type { ClientRoute } from '@owlmeans/client-route'
3
+ import type { ClientEntrypoint } from '@owlmeans/client-entrypoint'
4
+ import type { Location } from '@owlmeans/router'
5
+ import { useContext, useNavigate } from '@owlmeans/client'
6
+
7
+ import type { NavTranslate, PanelNavConfig, PanelNavItem, PanelNavModel, PanelNavSection } from './types.js'
8
+
9
+ /** Default resolver: no i18n, the caller's fallback wins. See {@link NavTranslate}. */
10
+ export const defaultNavTranslate: NavTranslate = (_key, defaultValue) => defaultValue
11
+
12
+ /**
13
+ * Turn an alias into something readable — `my-app:web:user-list` becomes `User list`.
14
+ * The last segment is the meaningful one; the prefixes address the app, not the screen.
15
+ */
16
+ export const defaultNavLabel = (alias: string): string => {
17
+ const segment = alias.split(/[:.]/).filter(part => part !== '').pop() ?? alias
18
+ const words = segment.replace(/[-_]+/g, ' ').trim()
19
+
20
+ return words.charAt(0).toUpperCase() + words.slice(1)
21
+ }
22
+
23
+ export const resolveNavLabel = (
24
+ translate: NavTranslate, label: string | undefined, key: string, alias?: string
25
+ ): string => label ?? translate(key, defaultNavLabel(alias ?? key))
26
+
27
+ const visibleItems = (section: PanelNavSection): PanelNavItem[] =>
28
+ section.items.filter(item => item.hidden !== true)
29
+
30
+ const normalizePath = (path: string): string =>
31
+ path.length > 1 && path.endsWith('/') ? path.slice(0, -1) : path
32
+
33
+ /**
34
+ * The navigation model behind both menus.
35
+ *
36
+ * Resolving the CURRENT screen has two sources, and both are needed. The router carries the
37
+ * alias in `location.state`, which is authoritative — but `state` is `window.history.state`,
38
+ * so it is null until the first in-app navigation: on a hard page load or a deep link there
39
+ * is nothing there, and a menu keyed on it alone highlights nothing on exactly the entry that
40
+ * matters most. The pathname is the fallback: entrypoint paths are resolved by the time the
41
+ * router renders, so matching them is a lookup, not a guess.
42
+ */
43
+ export const usePanelNav = (config: PanelNavConfig): PanelNavModel => {
44
+ const context = useContext()
45
+ const nav = useNavigate()
46
+ const location: Location<ClientRoute> = context.router().useLocation()
47
+
48
+ const state = location.state as ClientRoute | null
49
+ const pathname = location.pathname
50
+
51
+ return useMemo(() => {
52
+ const sections = config.sections
53
+ .filter(section => section.hidden !== true)
54
+ .map(section => ({ ...section, items: visibleItems(section) }))
55
+
56
+ const pathOf = (alias: string): string | null => {
57
+ try {
58
+ return normalizePath(context.entrypoint<ClientEntrypoint<string>>(alias).getPath())
59
+ } catch {
60
+ // An alias the app never elevated addresses nothing — it cannot be the current screen,
61
+ // and it must not take the menu down with it.
62
+ return null
63
+ }
64
+ }
65
+
66
+ const all = sections.flatMap(section => section.items)
67
+
68
+ let current: string | null = state?.alias ?? null
69
+ if (current == null) {
70
+ const here = normalizePath(pathname)
71
+ const exact = all.find(item => pathOf(item.alias) === here)
72
+ if (exact != null) {
73
+ current = exact.alias
74
+ } else {
75
+ // Longest prefix: a detail screen under a listed one still belongs to its section.
76
+ const prefixed = all
77
+ .map(item => ({ item, path: pathOf(item.alias) }))
78
+ .filter((entry): entry is { item: PanelNavItem, path: string } =>
79
+ entry.path != null && entry.path !== '/' && here.startsWith(`${entry.path}/`))
80
+ .sort((a, b) => b.path.length - a.path.length)[0]
81
+ current = prefixed?.item.alias ?? null
82
+ }
83
+ }
84
+
85
+ const sectionOf = (alias: string | null): PanelNavSection | null =>
86
+ alias == null ? null : sections.find(section => section.items.some(item => item.alias === alias)) ?? null
87
+
88
+ let active = sectionOf(current)
89
+ if (active == null && current != null) {
90
+ // The current screen is not listed anywhere — walk up to the ancestor that is, so a
91
+ // nested screen keeps its section (and its side menu) rather than clearing the chrome.
92
+ let alias: string | null = current
93
+ const seen = new Set<string>()
94
+ while (alias != null && !seen.has(alias)) {
95
+ seen.add(alias)
96
+ try {
97
+ alias = context.entrypoint<ClientEntrypoint<string>>(alias).getParentAlias() ?? null
98
+ } catch {
99
+ alias = null
100
+ }
101
+ const found = sectionOf(alias)
102
+ if (found != null) {
103
+ active = found
104
+ break
105
+ }
106
+ }
107
+ }
108
+
109
+ const isItemActive = (item: PanelNavItem): boolean => item.alias === current
110
+ const isSectionActive = (section: PanelNavSection): boolean =>
111
+ active != null && section.name === active.name
112
+
113
+ return {
114
+ sections,
115
+ current,
116
+ active,
117
+ showSide: active != null && active.items.length > 1,
118
+ isSectionActive,
119
+ isItemActive,
120
+ goSection: section => {
121
+ const first = section.items[0]
122
+ return first != null ? nav.press(first.alias) : () => {}
123
+ },
124
+ goItem: item => nav.press(item.alias),
125
+ hrefOf: target => {
126
+ const alias = 'alias' in target ? target.alias : target.items[0]?.alias
127
+ if (alias == null) {
128
+ return undefined
129
+ }
130
+ const path = pathOf(alias)
131
+
132
+ return path == null || path.includes(':') ? undefined : path
133
+ },
134
+ }
135
+ }, [config, pathname, state?.alias, context, nav])
136
+ }
@@ -0,0 +1,3 @@
1
+ export type * from './types.js'
2
+
3
+ export * from './helper.js'
@@ -0,0 +1,79 @@
1
+ import type { ComponentType } from 'react'
2
+
3
+ /**
4
+ * One screen in the navigation — the second menu level.
5
+ *
6
+ * `alias` addresses a frontend entrypoint, so an item never carries a URL: the router
7
+ * resolves it, and a path that changes shape stays correct everywhere it is rendered.
8
+ */
9
+ export interface PanelNavItem {
10
+ alias: string
11
+ /** Literal label. Absent, the label is resolved through `translate` and falls back to a humanized alias. */
12
+ label?: string
13
+ Icon?: ComponentType<{ className?: string }>
14
+ hidden?: boolean
15
+ }
16
+
17
+ /**
18
+ * One section — the first menu level. Its items are the screens the side menu offers
19
+ * while the section is active.
20
+ */
21
+ export interface PanelNavSection {
22
+ /** Stable key. Also the default translation key (`nav.<name>`). */
23
+ name: string
24
+ label?: string
25
+ /** Ordered. The first visible item is where pressing the section navigates. */
26
+ items: PanelNavItem[]
27
+ hidden?: boolean
28
+ }
29
+
30
+ export interface PanelNavConfig {
31
+ sections: PanelNavSection[]
32
+ }
33
+
34
+ /** A footer link: exactly one of `alias` (an entrypoint) or `href` (anything else). */
35
+ export interface PanelNavLink {
36
+ alias?: string
37
+ href?: string
38
+ label?: string
39
+ /** Open in a new tab. */
40
+ open?: boolean
41
+ }
42
+
43
+ /**
44
+ * Resolves a label from a translation key.
45
+ *
46
+ * It is a PROP, never an implicit context read: an app that mounts without an i18n provider
47
+ * (`renderApp` from `@owlmeans/web-client` does) must still render a menu, and reaching for
48
+ * the panel i18n context there throws inside the render tree and blanks the whole app.
49
+ * The default returns the fallback, so literal labels work with no i18n at all.
50
+ */
51
+ export interface NavTranslate {
52
+ (key: string, defaultValue: string): string
53
+ }
54
+
55
+ export interface PanelNavModel {
56
+ /** Sections and items with `hidden` filtered out. */
57
+ sections: PanelNavSection[]
58
+ /** Alias of the screen currently rendered, when it could be resolved. */
59
+ current: string | null
60
+ active: PanelNavSection | null
61
+ /**
62
+ * Whether the side menu carries anything worth showing — false when the active section
63
+ * holds a single screen, which is the whole point: one screen needs no second level.
64
+ */
65
+ showSide: boolean
66
+ isSectionActive: (section: PanelNavSection) => boolean
67
+ isItemActive: (item: PanelNavItem) => boolean
68
+ goSection: (section: PanelNavSection) => () => void
69
+ goItem: (item: PanelNavItem) => () => void
70
+ /**
71
+ * The resolved URL of a section's landing screen, when it has one.
72
+ *
73
+ * A menu entry navigates through `nav.press`, but it still has to BE a link: an `<a>`
74
+ * without `href` is not focusable, does not answer the keyboard, and cannot be opened in a
75
+ * new tab. Undefined for a path carrying route parameters — there is no honest URL to show
76
+ * for a screen whose address is not known yet.
77
+ */
78
+ hrefOf: (target: PanelNavItem | PanelNavSection) => string | undefined
79
+ }