autosolutions-os 0.3.1 → 0.3.3
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/CHANGELOG.md +160 -0
- package/README.md +76 -16
- package/dist/frame.d.ts +21 -4
- package/dist/frame.js +29 -6
- package/dist/nav.d.ts +91 -8
- package/dist/nav.js +168 -28
- package/dist/search.d.ts +58 -0
- package/dist/search.js +238 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,165 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.3 - 2026-10-18
|
|
4
|
+
|
|
5
|
+
The owner's three calls of 18 October. Every app takes them with a lockfile
|
|
6
|
+
bump: no code changes.
|
|
7
|
+
|
|
8
|
+
### Marketing has an Overview
|
|
9
|
+
|
|
10
|
+
- `OS_MENU.marketing` starts with an Overview row (`marketing-home`), exactly
|
|
11
|
+
like Finance, Commercial and Operations: the same label, glyph and group
|
|
12
|
+
with no title. Cliff's map draws none for Marketing; the owner asked for it
|
|
13
|
+
("be sure it's added everywhere in all apps, exactly the same").
|
|
14
|
+
- Its page in the Hub is `/os/marketing` (`osHubPath("marketing")`), the
|
|
15
|
+
Hub's Marketing hub sample, so the row is marked " (*)" in every app.
|
|
16
|
+
|
|
17
|
+
### Operations' Overview opens Ops Hub
|
|
18
|
+
|
|
19
|
+
- `OS_TOOL_LINKS["operations-home"]` is Ops Hub's home dashboard
|
|
20
|
+
(`{ app: "ops_hub", url: "https://ops-hub.autosolutions.app", path: "/" }`),
|
|
21
|
+
in every app, instead of the Hub's Operations hub sample page. Someone who
|
|
22
|
+
holds Ops Hub goes there, with the company as `?tenant=`; for someone who
|
|
23
|
+
does not, the row is locked with the admin hint, like every Ops Hub row; a
|
|
24
|
+
frame off the core links it from `staticLinks()`. The row loses its " (*)"
|
|
25
|
+
where it opens Ops Hub.
|
|
26
|
+
- In the Hub, the page of a locked row (Operations' Overview, an Ops Hub
|
|
27
|
+
tool's page) now files under its function with no row picked: someone who
|
|
28
|
+
does not hold Ops Hub and opens `/os/operations` sees the Operations menu
|
|
29
|
+
with its Overview locked, not the Hub's landing with the menu closed.
|
|
30
|
+
Before, such a page filed under the function's Overview.
|
|
31
|
+
|
|
32
|
+
### Asset Manager's address
|
|
33
|
+
|
|
34
|
+
- Asset Manager's fixed address is `https://asset-portal.autosolutions.app`
|
|
35
|
+
(was `https://self-asset-manager.lovable.app`), the address the Hub's
|
|
36
|
+
catalogue gives Asset Portal: on autosolutions.app it shares the Hub's
|
|
37
|
+
sign-in.
|
|
38
|
+
|
|
39
|
+
### Counts
|
|
40
|
+
|
|
41
|
+
- The map has 60 rows (56 tools, four Overviews). With every live app's
|
|
42
|
+
address in the catalogue, 18 open an app (Operations' Overview among them)
|
|
43
|
+
and 42 are samples, the same in the Hub and in every app. The menu search
|
|
44
|
+
finds five rows named Overview: the Hub's, Finance's, Marketing's,
|
|
45
|
+
Commercial's and Operations'.
|
|
46
|
+
|
|
47
|
+
### What each app does after taking 0.3.3
|
|
48
|
+
|
|
49
|
+
- Every app: bump `autosolutions-os` to `^0.3.3`.
|
|
50
|
+
- The Hub: draw a page for `/os/marketing` (its Marketing hub sample), as it
|
|
51
|
+
does for the other Overviews.
|
|
52
|
+
|
|
53
|
+
## 0.3.2 - 2026-10-18
|
|
54
|
+
|
|
55
|
+
One app, as the owner asked on 18 October: the top bar, the rail, the menus
|
|
56
|
+
and their links are the Hub's in every app. Four changes an app sees, and
|
|
57
|
+
what each app does after it takes this release.
|
|
58
|
+
|
|
59
|
+
### Every row goes where the Hub's catalogue sends it
|
|
60
|
+
|
|
61
|
+
- `OS_TOOL_LINKS`: Ops Hub's fixed address is
|
|
62
|
+
`https://ops-hub.autosolutions.app` (was `https://frankhub.lovable.app`,
|
|
63
|
+
which only redirects there), for its nine tools. Every app with a live
|
|
64
|
+
address now has it as its fixed `url`: Artificial Design Studio
|
|
65
|
+
(`https://design-studio.autosolutions.app`), Live eComm sales by store
|
|
66
|
+
(`https://e-sales.autosolutions.app`), Asset Manager
|
|
67
|
+
(`https://self-asset-manager.lovable.app`) and Candidate hub
|
|
68
|
+
(`https://hire-spark-center.lovable.app`). A frame off the core sent those
|
|
69
|
+
four to their page in the Hub; it now sends them to the app, as the Hub
|
|
70
|
+
does. The five apps the catalogue has no address for yet (Paid media,
|
|
71
|
+
Marketing calendar, Influencer Manager, NPD validator, Shelf simulator)
|
|
72
|
+
still open their page in the Hub, from every app.
|
|
73
|
+
- PM Copilot opens its console, `/ops`
|
|
74
|
+
(`https://pm-copilot.autosolutions.app/ops`), from every app: the `path` is
|
|
75
|
+
joined to the catalogue's address too.
|
|
76
|
+
- `staticLinks(tenantSlug?)` takes the company's slug and puts it on every
|
|
77
|
+
address as `?tenant=`, exactly as `catalogueLinks` does, so a frame off the
|
|
78
|
+
core links to the same addresses as one on it. Pass the same slug to
|
|
79
|
+
`osFrame` as `tenantSlug`, for the rows into the Hub. Without a slug, no
|
|
80
|
+
hint, as before.
|
|
81
|
+
|
|
82
|
+
A frame on the core still links only what the catalogue says the person
|
|
83
|
+
holds, at the catalogue's address (`os_context().apps[].url`): a held app
|
|
84
|
+
with no address opens the tool's page in the Hub, and a fixed `url` is never
|
|
85
|
+
a way round the catalogue.
|
|
86
|
+
|
|
87
|
+
### Settings in the rail is the Hub's in every app
|
|
88
|
+
|
|
89
|
+
- The rail's Settings opens the Hub's settings
|
|
90
|
+
(`https://autosolutions.app/comms/settings?tenant=<slug>`) in every app, as
|
|
91
|
+
it does in the Hub (`/comms/settings`, its own route). `settingsPath` (on
|
|
92
|
+
`OsWorkspaceFrame` and `osFrame`) is deprecated and ignored: it neither
|
|
93
|
+
sends Settings to the app's page nor marks the rail's Settings there.
|
|
94
|
+
- An app's own settings page becomes a tab of its tool, the last one, with
|
|
95
|
+
the rail's settings glyph: `osSettingsTab(path, { match? })`
|
|
96
|
+
(`autosolutions-os/nav`) returns `{ id: "settings", label: "Settings",
|
|
97
|
+
icon: "settings", path }`; `OS_SETTINGS_TAB` is its id, label and glyph.
|
|
98
|
+
Put it at the end of a flat list of tabs, or in a group of its own in
|
|
99
|
+
titled tabs (`{ title: "Setup", items: [osSettingsTab("/settings")] }`).
|
|
100
|
+
The page and the pages under it are on the tab.
|
|
101
|
+
|
|
102
|
+
### Every bar has a search field
|
|
103
|
+
|
|
104
|
+
- `OsWorkspaceFrame` always draws the bar's search field, as the Hub's bar
|
|
105
|
+
has one. With `search.onChange` it is the app's own search, as before (the
|
|
106
|
+
CRM's, with its own results). Without one, or with no `search` at all, it
|
|
107
|
+
is the OS menu search: type to jump to any app or page the menu reaches,
|
|
108
|
+
every function's rows, the Hub panel's rows and this app's own tabs. The
|
|
109
|
+
matches hang under the field as the CRM's do, each with where it sits
|
|
110
|
+
("Finance · Reporting"); the arrow keys move, Enter or a click opens the
|
|
111
|
+
one marked (the first until the arrows move), Escape closes them and keeps
|
|
112
|
+
what was typed. A match goes exactly where its row or tab goes from the
|
|
113
|
+
menu. Placeholder: `search.placeholder`, else "Search", the Hub's. No ⌘K
|
|
114
|
+
hint.
|
|
115
|
+
- `autosolutions-os/search` (new entry, React only) is the same search for an
|
|
116
|
+
app that draws the design system's `WorkspaceFrame` with `osFrame()`
|
|
117
|
+
itself: `useOsMenuSearch({ frame, location, onNavigate })` returns
|
|
118
|
+
`topBar` (`searchPlaceholder`, `searchValue`, `onSearchChange`), to spread
|
|
119
|
+
on its `TopBar`, and `results`, to render after the frame. `onLeave`
|
|
120
|
+
opens another app (default: the same tab), `placeholder` names the field
|
|
121
|
+
(default "Search"), `shortcut: true` wires ⌘K / Ctrl+K and shows its hint,
|
|
122
|
+
and `field` finds the bar's input (default: the workspace bar's).
|
|
123
|
+
- `osMenuEntries(frame)` and `searchOsMenu(entries, query, limit = 8)`
|
|
124
|
+
(`autosolutions-os/nav`) are the search's data and matching: every word
|
|
125
|
+
typed must be in the name or in where it sits; names that are the words,
|
|
126
|
+
start with them, have a word starting with them or hold them come first.
|
|
127
|
+
|
|
128
|
+
### Sample pages say so: (*)
|
|
129
|
+
|
|
130
|
+
- A row whose page is one of the Hub's sample pages (`osHubPath`, the
|
|
131
|
+
design's mock dashboards) has " (*)" after its name, in every app (the
|
|
132
|
+
owner's mark for work in progress): the three Overviews and every tool with
|
|
133
|
+
no app to open. osFrame decides it where it decides the link, so a tool
|
|
134
|
+
loses the mark the day it links to an app. A row that opens an app, this
|
|
135
|
+
app's own tools, a locked row and the Hub panel (the Hub's real pages)
|
|
136
|
+
have none. With every live app's address in the catalogue that is 42 of
|
|
137
|
+
the map's 59 rows, the same in the Hub and in every app.
|
|
138
|
+
- `OS_SAMPLE_MARK` (" (*)") and `osSampleLabel(label)`, which adds it once:
|
|
139
|
+
the Hub's sample pages put it on their tabs too, since all their data is
|
|
140
|
+
mock. The menu map's own labels (`OS_MENU`) stay the design's words.
|
|
141
|
+
- The menu search finds a marked row by its name, and shows the mark.
|
|
142
|
+
|
|
143
|
+
### What each app does after taking 0.3.2
|
|
144
|
+
|
|
145
|
+
- On the core (`OsWorkspaceFrame`): drop `settingsPath` and add
|
|
146
|
+
`osSettingsTab(<the old path>)` as the tool's last tab; an app with no
|
|
147
|
+
search of its own drops any `search` handler that does nothing and gets the
|
|
148
|
+
menu search.
|
|
149
|
+
- The Hub: on its sample pages (`/os/...`), label the tabs with
|
|
150
|
+
`osSampleLabel`.
|
|
151
|
+
- Off the core (`osFrame` and `WorkspaceFrame`): pass `staticLinks(slug)` and
|
|
152
|
+
`tenantSlug: slug` (the company's slug in the core, such as `frank-body`
|
|
153
|
+
or `enxgy`), move the settings page into the tool's tabs as above, and wire
|
|
154
|
+
`useOsMenuSearch` into the TopBar.
|
|
155
|
+
|
|
156
|
+
### Known limits
|
|
157
|
+
|
|
158
|
+
- A frame off the core cannot read the core's entitlements, so it draws the
|
|
159
|
+
Hub panel's Assistants unlocked and has no Admin row in the footer; the
|
|
160
|
+
Hub locks the Assistants a company does not hold and shows Admin to people
|
|
161
|
+
who manage something.
|
|
162
|
+
|
|
3
163
|
## 0.3.1 - 2026-10-16
|
|
4
164
|
|
|
5
165
|
"Sign in with AutoSolutions" for the apps that keep their own Supabase
|
package/README.md
CHANGED
|
@@ -94,8 +94,8 @@ person signs out in the app.
|
|
|
94
94
|
|
|
95
95
|
`OsWorkspaceFrame` is the frame every app on the core renders around its pages:
|
|
96
96
|
the top bar with the company's mark and switcher, the rail, the OS menu (Cliff's
|
|
97
|
-
menu map, 0.3.0: 56 tools and an Overview first in
|
|
98
|
-
|
|
97
|
+
menu map, 0.3.0: 56 tools and an Overview first in every function, Marketing's
|
|
98
|
+
since 0.3.3, our Shelf simulator, Key accounts, PM Copilot and Candidate hub
|
|
99
99
|
among them), the Hub panel, the footer with Admin for people who manage
|
|
100
100
|
something, and the browser-tab icon. It needs `autosolutions-design-system`
|
|
101
101
|
6.5.0 or later (an optional peer: only this entry point uses it). Take this
|
|
@@ -123,13 +123,15 @@ import { OsWorkspaceFrame } from "autosolutions-os/frame";
|
|
|
123
123
|
]}
|
|
124
124
|
location={pathname + search}
|
|
125
125
|
onNavigate={(href) => navigate({ to: href })}
|
|
126
|
-
search={{ placeholder: "Search", value: query, onChange: setQuery }}
|
|
127
126
|
onSignOut={signOut}
|
|
128
127
|
>
|
|
129
128
|
<Outlet />
|
|
130
129
|
</OsWorkspaceFrame>
|
|
131
130
|
```
|
|
132
131
|
|
|
132
|
+
With no `search` the bar's field is the OS menu search. An app with a search
|
|
133
|
+
of its own passes it: `search={{ placeholder: "Search", value: query, onChange: setQuery }}`.
|
|
134
|
+
|
|
133
135
|
It works with any router: it reads `location` and calls `onNavigate(href)` for
|
|
134
136
|
paths inside the app, and opens other apps itself, in the same tab. The rows
|
|
135
137
|
for other apps are links (`<a href>` with `?tenant=`), and so are this app's
|
|
@@ -213,11 +215,18 @@ why).
|
|
|
213
215
|
- `actions` go in the top bar before the plate (What's new, a notification
|
|
214
216
|
bell). `panelFooter` renders in the tool's panel under its tabs, in the
|
|
215
217
|
panel's padding, scrolling with them (Create Studio's sessions).
|
|
216
|
-
- Settings
|
|
217
|
-
Hub
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
218
|
+
- Settings in the rail opens the Hub's settings in every app (0.3.2), as it
|
|
219
|
+
does in the Hub. `settingsPath` is deprecated and ignored. An app with a
|
|
220
|
+
settings page of its own lists it as its tool's last tab (below, "An app's
|
|
221
|
+
own settings").
|
|
222
|
+
- `search` is the top bar's field, which every bar has (0.3.2), as the
|
|
223
|
+
Hub's does. With `search.onChange` it is the app's own search (the CRM's,
|
|
224
|
+
with its own results under it). Without one, or with no `search` at all,
|
|
225
|
+
it is the OS menu search: type to jump to any app or page the menu
|
|
226
|
+
reaches (every function's rows, the Hub panel's rows, this app's own
|
|
227
|
+
tabs); the matches hang under the field, the arrow keys move, Enter or a
|
|
228
|
+
click opens the one marked, Escape closes them. `search.placeholder` names
|
|
229
|
+
the field either way; default "Search", the Hub's. There is no ⌘K hint.
|
|
221
230
|
- On a phone's screen (767px and below) the design system closes the menu on
|
|
222
231
|
every location and on every row or tab picked, so the page picked gets the
|
|
223
232
|
width, once the page is live (a server-rendered page shows it open until it
|
|
@@ -225,6 +234,15 @@ why).
|
|
|
225
234
|
for it. `initialOpen={false}` starts the menu closed on the first location,
|
|
226
235
|
which a phone no longer needs it for; after that the frame's own rule
|
|
227
236
|
applies. `data-*` and `aria-*` props land on the frame's root.
|
|
237
|
+
- A row whose page is one of the Hub's sample pages (Finance's, Marketing's
|
|
238
|
+
and Commercial's Overviews and every tool with no app to open) has " (*)"
|
|
239
|
+
after its name, in every app (0.3.2, `OS_SAMPLE_MARK`): the owner's mark
|
|
240
|
+
for work in progress. A row that opens an app has none, so a tool loses it
|
|
241
|
+
the day it gets one.
|
|
242
|
+
- Operations' Overview is Ops Hub's home dashboard (0.3.3): it opens Ops Hub
|
|
243
|
+
for someone who holds it, and is locked for someone who does not, like
|
|
244
|
+
Ops Hub's tools. In the Hub a locked row's page files under its function,
|
|
245
|
+
with no row picked.
|
|
228
246
|
- Admin appears when `my_admin_scope()` says the person manages something; pass
|
|
229
247
|
`admin` to decide it yourself.
|
|
230
248
|
- Every app shows the Hub panel (0.3.0, `OS_HUB_MENU`, the design's): Smart
|
|
@@ -241,31 +259,72 @@ why).
|
|
|
241
259
|
Hub's landing. `targetFor` still honours the design system's `back` flag
|
|
242
260
|
for a caller that passes it.
|
|
243
261
|
|
|
262
|
+
### An app's own settings
|
|
263
|
+
|
|
264
|
+
The rail's Settings is the Hub's in every app (0.3.2). An app with settings
|
|
265
|
+
of its own puts the page in its tool's panel as the last tab, with the rail's
|
|
266
|
+
settings glyph, using `osSettingsTab(path)` from `autosolutions-os/nav`
|
|
267
|
+
(`{ id: "settings", label: "Settings", icon: "settings", path }`; `match`
|
|
268
|
+
adds more paths that are the page). The page and the pages under it are on
|
|
269
|
+
the tab.
|
|
270
|
+
|
|
271
|
+
```tsx
|
|
272
|
+
import { osSettingsTab } from "autosolutions-os/nav";
|
|
273
|
+
|
|
274
|
+
const tools = [{ id: "key-accounts", path: "/", tabs: [
|
|
275
|
+
{ id: "requests", label: "Requests", icon: "hub-tasks", path: "/" },
|
|
276
|
+
{ id: "analytics", label: "Analytics", icon: "fin-ratios", path: "/analytics" },
|
|
277
|
+
osSettingsTab("/settings"),
|
|
278
|
+
] }];
|
|
279
|
+
// Titled tabs: a group of its own, last.
|
|
280
|
+
const grouped = [...groups, { title: "Setup", items: [osSettingsTab("/b2b-frank/settings")] }];
|
|
281
|
+
```
|
|
282
|
+
|
|
244
283
|
### Off the core
|
|
245
284
|
|
|
246
285
|
`autosolutions-os/nav` is plain data and functions, with no React and no
|
|
247
286
|
Supabase: the rail (`OS_FUNCTIONS`), the menu map (`OS_MENU`), the Hub panel
|
|
248
287
|
(`OS_HUB_MENU`), `OS_TOOL_LINKS`, `OS_TOOL_ALIASES` and `osToolId()`,
|
|
249
|
-
`osHubPath()`, `HUB_URL`, `HUB_PATHS`, `HINTS`, `osFooter()`, `staticLinks()
|
|
250
|
-
|
|
288
|
+
`osHubPath()`, `HUB_URL`, `HUB_PATHS`, `HINTS`, `osFooter()`, `staticLinks()`,
|
|
289
|
+
`osSettingsTab()`, `OS_SAMPLE_MARK` and `osSampleLabel()`, `osMenuEntries()`
|
|
290
|
+
and `searchOsMenu()` (the menu search's data and matching), and `osFrame()`,
|
|
291
|
+
the routing rules the frame runs on. An app on its own
|
|
251
292
|
project (Ops Hub: see "Linked, not federated" in `docs/CONTRACT.md`) pairs it
|
|
252
293
|
with the design system's `WorkspaceFrame`, a static plate and no switcher.
|
|
253
|
-
`staticLinks()` are the fixed addresses
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
294
|
+
`staticLinks(slug)` are the fixed addresses, the ones the Hub's catalogue
|
|
295
|
+
gives (0.3.2: every app with a live address, Ops Hub's tools on
|
|
296
|
+
ops-hub.autosolutions.app, PM Copilot's console at `/ops`; 0.3.3: Operations'
|
|
297
|
+
Overview on Ops Hub's home, Asset Manager on asset-portal.autosolutions.app),
|
|
298
|
+
each with the
|
|
299
|
+
company's slug as `?tenant=`, exactly as the catalogue's links carry it; pass
|
|
300
|
+
the same slug as `tenantSlug` for the rows into the Hub. With no catalogue to
|
|
301
|
+
ask, they are all live, and each app's own sign-in decides. Every other row
|
|
302
|
+
opens its page in the Hub through `HUB_URL` (`hubUrl`), where the core
|
|
303
|
+
decides. If the app's CSS is a fork of the design
|
|
257
304
|
system, import `autosolutions-design-system/frame.css` instead of `styles.css`
|
|
258
305
|
(see the design system's README).
|
|
259
306
|
|
|
307
|
+
The bar's search is the OS menu search, from `autosolutions-os/search`
|
|
308
|
+
(0.3.2, React only): `useOsMenuSearch({ frame, location, onNavigate })` gives
|
|
309
|
+
the TopBar's search props (`topBar`) and the matches under the field
|
|
310
|
+
(`results`, rendered after the frame). `onLeave(href)` opens another app
|
|
311
|
+
(default: the same tab), `placeholder` names the field (default "Search"),
|
|
312
|
+
`shortcut: true` wires ⌘K / Ctrl+K and shows its hint, and `field` finds the
|
|
313
|
+
bar's input (default: the workspace bar's). An app with a search of its own
|
|
314
|
+
passes its own props to the TopBar instead.
|
|
315
|
+
|
|
260
316
|
```tsx
|
|
261
317
|
import { WorkspaceFrame, TopBar, companyMarkUrl } from "autosolutions-design-system";
|
|
262
318
|
import { osFrame, staticLinks } from "autosolutions-os/nav";
|
|
319
|
+
import { useOsMenuSearch } from "autosolutions-os/search";
|
|
263
320
|
|
|
264
|
-
const
|
|
321
|
+
const slug = "frank-body"; // the company's slug in the core
|
|
322
|
+
const frame = osFrame({ appKey: "ops_hub", tools, links: staticLinks(slug), tenantSlug: slug });
|
|
265
323
|
const here = pathname + search;
|
|
324
|
+
const menuSearch = useOsMenuSearch({ frame, location: here, onNavigate: (href) => navigate(href) });
|
|
266
325
|
|
|
267
326
|
<WorkspaceFrame
|
|
268
|
-
topBar={<TopBar
|
|
327
|
+
topBar={<TopBar {...menuSearch.topBar} companySrc={companyMarkUrl("frankbody", "plain")} />}
|
|
269
328
|
functions={frame.functions}
|
|
270
329
|
sections={frame.sections}
|
|
271
330
|
footerItems={frame.footerItems}
|
|
@@ -282,6 +341,7 @@ const here = pathname + search;
|
|
|
282
341
|
>
|
|
283
342
|
{page}
|
|
284
343
|
</WorkspaceFrame>
|
|
344
|
+
{menuSearch.results}
|
|
285
345
|
```
|
|
286
346
|
|
|
287
347
|
## On the server
|
package/dist/frame.d.ts
CHANGED
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
* `onNavigate` when someone clicks. A click on the tab or row it already
|
|
18
18
|
* shows, from a page filed under it (a draft under Requests), goes to that
|
|
19
19
|
* tab's own page.
|
|
20
|
+
*
|
|
21
|
+
* Since 0.3.2 the bar is the Hub's in every app: Settings in the rail opens
|
|
22
|
+
* the Hub's settings (an app's own settings are a tab of its tool,
|
|
23
|
+
* `osSettingsTab`), and the bar always has a search field. An app with a
|
|
24
|
+
* search of its own passes `search.onChange` (the CRM); every other app gets
|
|
25
|
+
* the OS menu search (`autosolutions-os/search`), which jumps to any app or
|
|
26
|
+
* page the menu reaches.
|
|
20
27
|
*/
|
|
21
28
|
import { type ReactNode } from "react";
|
|
22
29
|
import type { WorkspaceState } from "autosolutions-design-system";
|
|
@@ -81,8 +88,13 @@ export type OsWorkspaceFrameProps = {
|
|
|
81
88
|
*/
|
|
82
89
|
hrefFor?: ((path: string) => string | null) | null;
|
|
83
90
|
/**
|
|
84
|
-
* The top bar's search field
|
|
85
|
-
*
|
|
91
|
+
* The top bar's search field, which every app's bar has (0.3.2), as the
|
|
92
|
+
* Hub's does. With `onChange` it is the app's own search (the CRM's: its
|
|
93
|
+
* value, its results). Without one, or with no `search` at all, it is the
|
|
94
|
+
* OS menu search: type to jump to any app or page the menu reaches (every
|
|
95
|
+
* function's rows, the Hub panel, this app's tabs), the matches under the
|
|
96
|
+
* field, arrow keys to move, Enter or a click to open, Escape to close.
|
|
97
|
+
* `placeholder` names it either way; default "Search", the Hub's.
|
|
86
98
|
*/
|
|
87
99
|
search?: {
|
|
88
100
|
placeholder?: string;
|
|
@@ -97,7 +109,12 @@ export type OsWorkspaceFrameProps = {
|
|
|
97
109
|
panelFooter?: ReactNode;
|
|
98
110
|
/** Sign out, in whatever order the app needs (clear caches first, and so on). */
|
|
99
111
|
onSignOut?: () => void;
|
|
100
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* @deprecated Ignored since 0.3.2: Settings in the rail opens the Hub's
|
|
114
|
+
* settings in every app. Put the app's own settings page in its tool's
|
|
115
|
+
* panel instead, as its last tab: `osSettingsTab("/settings")`
|
|
116
|
+
* (`autosolutions-os/nav`).
|
|
117
|
+
*/
|
|
101
118
|
settingsPath?: string;
|
|
102
119
|
/** This app's landing. In the Hub it is where the rail's Hub lands from Admin or Settings. */
|
|
103
120
|
homePath?: string;
|
|
@@ -122,4 +139,4 @@ export type OsWorkspaceFrameProps = {
|
|
|
122
139
|
} & {
|
|
123
140
|
[key: `aria-${string}`]: string | number | boolean | undefined;
|
|
124
141
|
};
|
|
125
|
-
export declare function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location, onNavigate, hrefFor, search, actions, companySwitch, panelFooter, onSignOut,
|
|
142
|
+
export declare function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location, onNavigate, hrefFor, search, actions, companySwitch, panelFooter, onSignOut, homePath, admin, favicon, initialOpen, className, children, ...rest }: OsWorkspaceFrameProps): import("react").JSX.Element;
|
package/dist/frame.js
CHANGED
|
@@ -18,13 +18,21 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
18
18
|
* `onNavigate` when someone clicks. A click on the tab or row it already
|
|
19
19
|
* shows, from a page filed under it (a draft under Requests), goes to that
|
|
20
20
|
* tab's own page.
|
|
21
|
+
*
|
|
22
|
+
* Since 0.3.2 the bar is the Hub's in every app: Settings in the rail opens
|
|
23
|
+
* the Hub's settings (an app's own settings are a tab of its tool,
|
|
24
|
+
* `osSettingsTab`), and the bar always has a search field. An app with a
|
|
25
|
+
* search of its own passes `search.onChange` (the CRM); every other app gets
|
|
26
|
+
* the OS menu search (`autosolutions-os/search`), which jumps to any app or
|
|
27
|
+
* page the menu reaches.
|
|
21
28
|
*/
|
|
22
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
29
|
+
import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
23
30
|
import { ActionList, TopBar, WorkspaceFrame } from "autosolutions-design-system";
|
|
24
31
|
import { useCompanySwitch } from "./chrome.js";
|
|
25
32
|
import { markFor, refreshOsContext, retryOsContext, watchOsAuth } from "./context.js";
|
|
26
33
|
import { myAdminScope } from "./identity.js";
|
|
27
34
|
import { catalogueLinks, osFrame } from "./nav.js";
|
|
35
|
+
import { useMenuSearch } from "./search.js";
|
|
28
36
|
/* A company's mark in the company menu. When its artwork does not load, the
|
|
29
37
|
slot stays, empty (the row already says the company's name), so the names
|
|
30
38
|
stay lined up; never a broken image. */
|
|
@@ -59,7 +67,7 @@ function linked(sections, hrefFor) {
|
|
|
59
67
|
}
|
|
60
68
|
/* Where the address bar is: a navigation the app does not make leaves it. */
|
|
61
69
|
const here = () => (typeof window === "undefined" ? "" : window.location.pathname + window.location.search + window.location.hash);
|
|
62
|
-
export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location, onNavigate, hrefFor, search, actions, companySwitch = "os", panelFooter, onSignOut,
|
|
70
|
+
export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location, onNavigate, hrefFor, search, actions, companySwitch = "os", panelFooter, onSignOut, homePath, admin, favicon = true, initialOpen, className, children, ...rest }) {
|
|
63
71
|
/* Only data-* and aria-* reach the frame's root. */
|
|
64
72
|
const attributes = Object.fromEntries(Object.entries(rest).filter(([key]) => /^(data|aria)-/.test(key)));
|
|
65
73
|
const { context, status, current: read, tenants, busy: switching, error, choose } = useCompanySwitch(os, appKey);
|
|
@@ -117,10 +125,9 @@ export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location,
|
|
|
117
125
|
appKey, links, locked, admin: admin ?? manages, tenantSlug: slug,
|
|
118
126
|
...(tools ? { tools } : {}),
|
|
119
127
|
...(hubItems ? { hubItems } : {}),
|
|
120
|
-
...(settingsPath ? { settingsPath } : {}),
|
|
121
128
|
...(homePath ? { homePath } : {}),
|
|
122
129
|
});
|
|
123
|
-
}, [appKey, apps, admin, manages, slug, tools, hubItems,
|
|
130
|
+
}, [appKey, apps, admin, manages, slug, tools, hubItems, homePath]);
|
|
124
131
|
const linkTo = hrefFor === undefined ? (path) => path : hrefFor;
|
|
125
132
|
const sections = useMemo(() => (linkTo ? linked(frame.sections, linkTo) : frame.sections), [frame, hrefFor]);
|
|
126
133
|
/* `false` tells the frame a click went nowhere (Settings on the page
|
|
@@ -142,6 +149,18 @@ export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location,
|
|
|
142
149
|
}
|
|
143
150
|
return true;
|
|
144
151
|
};
|
|
152
|
+
/* The bar's field: the app's own search when it answers it, else the OS
|
|
153
|
+
menu search, on this frame's own bar (found by its data-os-bar). */
|
|
154
|
+
const own = typeof search?.onChange === "function";
|
|
155
|
+
const barId = useId();
|
|
156
|
+
const field = useCallback(() => (typeof document === "undefined" ? null : document.querySelector(`[data-os-bar="${barId}"] .as-topbar__search input`)), [barId]);
|
|
157
|
+
const menuSearch = useMenuSearch({
|
|
158
|
+
frame,
|
|
159
|
+
location,
|
|
160
|
+
onNavigate: (href) => { void onNavigate(href); },
|
|
161
|
+
placeholder: search?.placeholder ?? "Search",
|
|
162
|
+
field,
|
|
163
|
+
}, !own);
|
|
145
164
|
const signOut = onSignOut ?? (() => {
|
|
146
165
|
void auth?.signOut().then(() => window.location.reload());
|
|
147
166
|
});
|
|
@@ -191,10 +210,14 @@ export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location,
|
|
|
191
210
|
onAction: () => pick(tenant),
|
|
192
211
|
})),
|
|
193
212
|
}] }), busy && _jsx("div", { className: "as-ws__company-note", role: "status", children: "Switching\u2026" }), error && _jsx("div", { className: "as-ws__company-note as-ws__company-note--error", role: "alert", children: error })] })) : undefined;
|
|
194
|
-
const topBar = (_jsx(TopBar, { variant: "workspace",
|
|
213
|
+
const topBar = (_jsx(TopBar, { variant: "workspace", "data-os-bar": barId, ...(own
|
|
214
|
+
? { searchPlaceholder: search?.placeholder ?? "Search", searchValue: search?.value, onSearchChange: search?.onChange }
|
|
215
|
+
: menuSearch.topBar), actions: actions, company: current?.slug ?? null, companySrc: current ? markFor(current, "plain") : undefined,
|
|
195
216
|
/* Also what the plate shows when the company has no artwork, or it fails to load. */
|
|
196
217
|
companyName: current?.name,
|
|
197
218
|
/* While the company is read, its place on the bar is kept. */
|
|
198
219
|
companyPending: !current && status === "loading" ? (companySwitch === "none" ? "plate" : true) : undefined, onSwitchCompany: switchable ? () => setMenuOpen((open) => !open) : undefined, companyMenu: companyMenu, companyMenuOpen: menuOpen, onCompanyMenuClose: () => setMenuOpen(false) }));
|
|
199
|
-
|
|
220
|
+
/* The menu search's matches hang under the bar's field, drawn after the
|
|
221
|
+
frame; nothing while they are closed. */
|
|
222
|
+
return (_jsxs(_Fragment, { children: [_jsx(WorkspaceFrame, { className: className, topBar: topBar, functions: frame.functions, sections: sections, footerItems: frame.footerItems, homeFunction: frame.homeFunction, location: { ...frame.locate(location), href: location }, onNavigate: navigate, onSignOut: signOut, favicon: favicon, panelFooter: panelFooter, ...(initialOpen === undefined ? {} : { initialOpen }), ...attributes, children: children }), menuSearch.results] }));
|
|
200
223
|
}
|
package/dist/nav.d.ts
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
* 1 the rail Hub, Finance, Marketing, Commercial, Operations
|
|
9
9
|
* 2 the menu that function's tools, grouped Reporting / Planning
|
|
10
10
|
* (Performance / Planning / Creative in Marketing),
|
|
11
|
-
* an Overview first in
|
|
12
|
-
*
|
|
13
|
-
* Assistants
|
|
11
|
+
* an Overview first in every function (Marketing's
|
|
12
|
+
* since 0.3.3, the owner's call); the Hub's is
|
|
13
|
+
* Smart Comms Hub and Assistants
|
|
14
14
|
* 3 the tool's panel an app's own tool, open: its icon and name, then its
|
|
15
15
|
* views as tabs (design system 6.5.0; no Back to hub)
|
|
16
16
|
*
|
|
@@ -66,7 +66,8 @@ export declare const OS_FUNCTIONS: OsNavItem[];
|
|
|
66
66
|
/**
|
|
67
67
|
* Cliff's menu map (the design's ui_kits/functions dashboards/nav.js and
|
|
68
68
|
* data.js, 16 October 2026): its ids, labels, groups, order, status and
|
|
69
|
-
* views, an Overview at the top of
|
|
69
|
+
* views, an Overview at the top of every function (Cliff draws one for
|
|
70
|
+
* Finance, Commercial and Operations; Marketing's is the owner's, 0.3.3), and
|
|
70
71
|
* the two rows the design keeps from before its merge (Customer scorecard,
|
|
71
72
|
* Clearance list). Then our four Live apps the map does not have, at the end
|
|
72
73
|
* of their groups, so they stay reachable: Shelf simulator (Marketing >
|
|
@@ -120,6 +121,21 @@ export type OsToolLink = {
|
|
|
120
121
|
* Pricing researcher and Brand voice copywriter have no app to open yet:
|
|
121
122
|
* like every tool with none, they open their page in the Hub. The Hub itself
|
|
122
123
|
* (smart_comms_hub) is the rail's Hub, not a row.
|
|
124
|
+
*
|
|
125
|
+
* Since 0.3.2 every app with a live address has it as its fixed `url` (Create
|
|
126
|
+
* Studio, Sales Reporting, Asset Portal and Candidate Hub had none), so a
|
|
127
|
+
* frame off the core sends each row where the Hub's catalogue does once the
|
|
128
|
+
* catalogue has that address (`launch_url`), not to the tool's page in the
|
|
129
|
+
* Hub; and PM Copilot opens its console (`/ops`), from the catalogue too.
|
|
130
|
+
* The five apps whose address the catalogue does not give yet (Paid media,
|
|
131
|
+
* Marketing calendar, Influencer Manager, NPD validator, Shelf simulator)
|
|
132
|
+
* have none: off the core they open their page in the Hub.
|
|
133
|
+
*
|
|
134
|
+
* Since 0.3.3 (the owner's calls of 18 October): Operations' Overview is Ops
|
|
135
|
+
* Hub's home dashboard, so it opens Ops Hub for someone who holds it and is
|
|
136
|
+
* locked for someone who does not, like Ops Hub's tools; and Asset Manager's
|
|
137
|
+
* fixed address is asset-portal.autosolutions.app, which shares the Hub's
|
|
138
|
+
* sign-in (self-asset-manager.lovable.app cannot read it).
|
|
123
139
|
*/
|
|
124
140
|
export declare const OS_TOOL_LINKS: Record<string, OsToolLink>;
|
|
125
141
|
/** The Hub's own pages, for the rail's Hub, Admin and Settings rows in other apps. */
|
|
@@ -141,16 +157,49 @@ export declare const HINTS: {
|
|
|
141
157
|
readonly notLinked: "Live, not linked from the Hub yet";
|
|
142
158
|
readonly checking: "Checking your access…";
|
|
143
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* The mark after the name of a row whose page is a sample (0.3.2, the
|
|
162
|
+
* owner's "(*)" for work in progress): a row that opens its page in the Hub
|
|
163
|
+
* (`osHubPath`, the design's sample dashboards, mock data) because its tool
|
|
164
|
+
* has no app to open, Finance's, Marketing's and Commercial's Overviews
|
|
165
|
+
* among them (Operations' opens Ops Hub since 0.3.3, and is a sample only
|
|
166
|
+
* where Ops Hub is held with no address yet). osFrame decides it
|
|
167
|
+
* where it decides the link, so a tool loses the mark the day it links to
|
|
168
|
+
* an app. A row that opens an app, this app's own tools, a locked row and
|
|
169
|
+
* the Hub panel (the Hub's real pages) have none. The Hub's sample pages put
|
|
170
|
+
* it on their tabs too (`osSampleLabel`), since all their data is mock.
|
|
171
|
+
*/
|
|
172
|
+
export declare const OS_SAMPLE_MARK = " (*)";
|
|
173
|
+
/** `label` with the sample mark after it, once. */
|
|
174
|
+
export declare function osSampleLabel(label: string): string;
|
|
175
|
+
/** The Settings tab's id, label and glyph (the rail's own settings glyph), 0.3.2. */
|
|
176
|
+
export declare const OS_SETTINGS_TAB: Readonly<OsNavItem>;
|
|
177
|
+
/**
|
|
178
|
+
* An app's own settings page as a tab in its tool's panel (0.3.2). The rail's
|
|
179
|
+
* Settings opens the Hub's settings in every app, so an app with settings of
|
|
180
|
+
* its own lists them with its other views, as the last tab, with the rail's
|
|
181
|
+
* settings glyph: `tabs: [...views, osSettingsTab("/settings")]`, or with
|
|
182
|
+
* titled tabs a group of its own, `{ title: "Setup", items:
|
|
183
|
+
* [osSettingsTab("/settings")] }`. Pages under `path` are on it too; `match`
|
|
184
|
+
* names more paths that are.
|
|
185
|
+
*/
|
|
186
|
+
export declare function osSettingsTab(path: string, options?: {
|
|
187
|
+
match?: string[];
|
|
188
|
+
}): OsTab;
|
|
144
189
|
/** The rail footer: Admin (for someone who manages something), Settings, then Sign out, always last. */
|
|
145
190
|
export declare function osFooter({ admin }?: {
|
|
146
191
|
admin?: boolean;
|
|
147
192
|
}): OsNavItem[];
|
|
148
193
|
/**
|
|
149
194
|
* Tool id to address, for the tools with a fixed `url`: what a frame off the
|
|
150
|
-
* core, which has no catalogue to ask, can link to.
|
|
151
|
-
*
|
|
195
|
+
* core, which has no catalogue to ask, can link to. Every other row of such
|
|
196
|
+
* a frame opens its page in the Hub, through HUB_URL. Given the company's
|
|
197
|
+
* slug (0.3.2), each address carries it as ?tenant=, exactly as
|
|
198
|
+
* catalogueLinks() writes it, so a row goes to the same address from every
|
|
199
|
+
* app; pass the same slug to osFrame as `tenantSlug` for the rows into the
|
|
200
|
+
* Hub. Without one, no hint.
|
|
152
201
|
*/
|
|
153
|
-
export declare function staticLinks(): Record<string, string>;
|
|
202
|
+
export declare function staticLinks(tenantSlug?: string | null): Record<string, string>;
|
|
154
203
|
/**
|
|
155
204
|
* Tool id to address, and tool id to the reason a row is off, for
|
|
156
205
|
* OsWorkspaceFrame to pass to osFrame. `apps` is os_context().apps: the apps
|
|
@@ -291,7 +340,11 @@ export type OsFrameOptions = {
|
|
|
291
340
|
locked?: Record<string, string>;
|
|
292
341
|
/** Show Admin in the footer. */
|
|
293
342
|
admin?: boolean;
|
|
294
|
-
/**
|
|
343
|
+
/**
|
|
344
|
+
* @deprecated Ignored since 0.3.2: the rail's Settings opens the Hub's
|
|
345
|
+
* settings in every app, as it does in the Hub. An app's own settings page
|
|
346
|
+
* is a tab in its tool's panel (`osSettingsTab`).
|
|
347
|
+
*/
|
|
295
348
|
settingsPath?: string;
|
|
296
349
|
/** This app's landing. In the Hub it is also where Back to hub lands. Default "/", or the Hub's home in the Hub. */
|
|
297
350
|
homePath?: string;
|
|
@@ -324,3 +377,33 @@ export type OsFrame = {
|
|
|
324
377
|
* company, the footer, and the only routing logic the frame needs.
|
|
325
378
|
*/
|
|
326
379
|
export declare function osFrame(options: OsFrameOptions): OsFrame;
|
|
380
|
+
/**
|
|
381
|
+
* A place the OS menu search finds (0.3.2): a row of a function's menu or of
|
|
382
|
+
* the Hub panel, or a tab of one of this app's tools. `state` is what the
|
|
383
|
+
* frame reports for a click on it, so `targetFor(state, location)` is where
|
|
384
|
+
* it goes, exactly as from the menu.
|
|
385
|
+
*/
|
|
386
|
+
export type OsMenuEntry = {
|
|
387
|
+
/** Unique among the entries: the function, the row, and the tab when it is one. */
|
|
388
|
+
key: string;
|
|
389
|
+
label: string;
|
|
390
|
+
/** Where it sits, for telling the five Overviews apart: "Finance", "Hub · Smart Comms Hub", "Key accounts". */
|
|
391
|
+
context: string;
|
|
392
|
+
icon?: string;
|
|
393
|
+
state: OsFrameState;
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Every place the menu reaches, in the menu's own order (0.3.2): the rows of
|
|
397
|
+
* each function's menu, the Hub panel's first, each followed by the tabs of
|
|
398
|
+
* this app's tool when it is one. A locked row, a disabled tab and a tab with
|
|
399
|
+
* no path (page state, nowhere to go) are left out.
|
|
400
|
+
*/
|
|
401
|
+
export declare function osMenuEntries(frame: Pick<OsFrame, "functions" | "sections">): OsMenuEntry[];
|
|
402
|
+
/**
|
|
403
|
+
* The entries that match `query`, best first, at most `limit` (0.3.2). Every
|
|
404
|
+
* word typed must be in the entry's name or where it sits ("finance overview"
|
|
405
|
+
* finds Finance's Overview). Names that are the words, start with them, have
|
|
406
|
+
* a word that starts with them, or hold them come first, in that order; then
|
|
407
|
+
* the entries found only by where they sit. Ties keep the menu's order.
|
|
408
|
+
*/
|
|
409
|
+
export declare function searchOsMenu(entries: ReadonlyArray<OsMenuEntry>, query: string, limit?: number): OsMenuEntry[];
|
package/dist/nav.js
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
* 1 the rail Hub, Finance, Marketing, Commercial, Operations
|
|
9
9
|
* 2 the menu that function's tools, grouped Reporting / Planning
|
|
10
10
|
* (Performance / Planning / Creative in Marketing),
|
|
11
|
-
* an Overview first in
|
|
12
|
-
*
|
|
13
|
-
* Assistants
|
|
11
|
+
* an Overview first in every function (Marketing's
|
|
12
|
+
* since 0.3.3, the owner's call); the Hub's is
|
|
13
|
+
* Smart Comms Hub and Assistants
|
|
14
14
|
* 3 the tool's panel an app's own tool, open: its icon and name, then its
|
|
15
15
|
* views as tabs (design system 6.5.0; no Back to hub)
|
|
16
16
|
*
|
|
@@ -42,7 +42,8 @@ const overview = (fn) => ({
|
|
|
42
42
|
/**
|
|
43
43
|
* Cliff's menu map (the design's ui_kits/functions dashboards/nav.js and
|
|
44
44
|
* data.js, 16 October 2026): its ids, labels, groups, order, status and
|
|
45
|
-
* views, an Overview at the top of
|
|
45
|
+
* views, an Overview at the top of every function (Cliff draws one for
|
|
46
|
+
* Finance, Commercial and Operations; Marketing's is the owner's, 0.3.3), and
|
|
46
47
|
* the two rows the design keeps from before its merge (Customer scorecard,
|
|
47
48
|
* Clearance list). Then our four Live apps the map does not have, at the end
|
|
48
49
|
* of their groups, so they stay reachable: Shelf simulator (Marketing >
|
|
@@ -76,6 +77,7 @@ export const OS_MENU = {
|
|
|
76
77
|
] },
|
|
77
78
|
],
|
|
78
79
|
marketing: [
|
|
80
|
+
overview("marketing"),
|
|
79
81
|
{ title: "Performance", items: [
|
|
80
82
|
tool("live-ecomm-sales", "Live eComm sales by store", "mkt-live-ecomm-sales-by-store", "Live"),
|
|
81
83
|
tool("paid-media", "Paid media", "mkt-paid-media", "No status"),
|
|
@@ -173,8 +175,10 @@ export function osHubPath(fn, toolId, tab) {
|
|
|
173
175
|
return path;
|
|
174
176
|
}
|
|
175
177
|
/* Ops Hub is linked, not federated (CONTRACT.md): its catalogue row decides
|
|
176
|
-
who sees its tools live; the fixed address serves frames off the core.
|
|
177
|
-
|
|
178
|
+
who sees its tools live; the fixed address serves frames off the core.
|
|
179
|
+
ops-hub.autosolutions.app since 0.3.2, its live address
|
|
180
|
+
(frankhub.lovable.app only redirects there). */
|
|
181
|
+
const OPS_HUB = "https://ops-hub.autosolutions.app";
|
|
178
182
|
const opsHub = (path) => ({ app: "ops_hub", url: OPS_HUB, path });
|
|
179
183
|
/**
|
|
180
184
|
* The tools that have an app of their own: every Live tool's, unchanged in
|
|
@@ -188,22 +192,39 @@ const opsHub = (path) => ({ app: "ops_hub", url: OPS_HUB, path });
|
|
|
188
192
|
* Pricing researcher and Brand voice copywriter have no app to open yet:
|
|
189
193
|
* like every tool with none, they open their page in the Hub. The Hub itself
|
|
190
194
|
* (smart_comms_hub) is the rail's Hub, not a row.
|
|
195
|
+
*
|
|
196
|
+
* Since 0.3.2 every app with a live address has it as its fixed `url` (Create
|
|
197
|
+
* Studio, Sales Reporting, Asset Portal and Candidate Hub had none), so a
|
|
198
|
+
* frame off the core sends each row where the Hub's catalogue does once the
|
|
199
|
+
* catalogue has that address (`launch_url`), not to the tool's page in the
|
|
200
|
+
* Hub; and PM Copilot opens its console (`/ops`), from the catalogue too.
|
|
201
|
+
* The five apps whose address the catalogue does not give yet (Paid media,
|
|
202
|
+
* Marketing calendar, Influencer Manager, NPD validator, Shelf simulator)
|
|
203
|
+
* have none: off the core they open their page in the Hub.
|
|
204
|
+
*
|
|
205
|
+
* Since 0.3.3 (the owner's calls of 18 October): Operations' Overview is Ops
|
|
206
|
+
* Hub's home dashboard, so it opens Ops Hub for someone who holds it and is
|
|
207
|
+
* locked for someone who does not, like Ops Hub's tools; and Asset Manager's
|
|
208
|
+
* fixed address is asset-portal.autosolutions.app, which shares the Hub's
|
|
209
|
+
* sign-in (self-asset-manager.lovable.app cannot read it).
|
|
191
210
|
*/
|
|
192
211
|
export const OS_TOOL_LINKS = {
|
|
193
|
-
"live-ecomm-sales": { app: "alive_reporting" },
|
|
212
|
+
"live-ecomm-sales": { app: "alive_reporting", url: "https://e-sales.autosolutions.app" },
|
|
194
213
|
"paid-media": { app: "ad_management" },
|
|
195
214
|
"marketing-calendar": { app: "content_calendar" },
|
|
196
215
|
"franks-kitchen": { app: "frank_kitchen" },
|
|
197
216
|
"npd-validator": { app: "product_idea_validator" },
|
|
198
217
|
"pricing-researcher": {},
|
|
199
218
|
"shelf-simulator": { app: "shelf_simulator" },
|
|
200
|
-
"image-generator": { app: "frank_create" },
|
|
201
|
-
"retail-image-library": { app: "asset_portal" },
|
|
219
|
+
"image-generator": { app: "frank_create", url: "https://design-studio.autosolutions.app" },
|
|
220
|
+
"retail-image-library": { app: "asset_portal", url: "https://asset-portal.autosolutions.app" },
|
|
202
221
|
"brand-voice-copywriter": {},
|
|
203
222
|
"sales": opsHub("/sales-dashboard"),
|
|
204
223
|
"open-orders": opsHub("/customer-orders"),
|
|
205
224
|
"crm": { app: "enxgy_crm", url: "https://e-crm.autosolutions.app" },
|
|
206
225
|
"key-accounts": { app: "key_accounts", url: "https://key-accounts.lovable.app" },
|
|
226
|
+
/* Operations' Overview is Ops Hub's home dashboard (owner, 0.3.3). */
|
|
227
|
+
"operations-home": opsHub("/"),
|
|
207
228
|
"inventory-health": opsHub("/inventory-health"),
|
|
208
229
|
"out-of-stocks": opsHub("/inventory-health?view=oos"),
|
|
209
230
|
"open-purchase-orders": opsHub("/po-pipeline"),
|
|
@@ -212,8 +233,8 @@ export const OS_TOOL_LINKS = {
|
|
|
212
233
|
"action-queue": opsHub("/action-queue"),
|
|
213
234
|
"ordering-tool": opsHub("/ordering"),
|
|
214
235
|
"carton-label-generator": { app: "label_maker", url: "https://label-maker.autosolutions.app" },
|
|
215
|
-
"pm-copilot": { app: "pm_copilot", url: "https://pm-copilot.autosolutions.app" },
|
|
216
|
-
"candidate-hub": { app: "candidate_hub" },
|
|
236
|
+
"pm-copilot": { app: "pm_copilot", url: "https://pm-copilot.autosolutions.app", path: "/ops" },
|
|
237
|
+
"candidate-hub": { app: "candidate_hub", url: "https://hire-spark-center.lovable.app" },
|
|
217
238
|
};
|
|
218
239
|
/** The Hub's own pages, for the rail's Hub, Admin and Settings rows in other apps. */
|
|
219
240
|
export const HUB_PATHS = {
|
|
@@ -234,6 +255,37 @@ export const HINTS = {
|
|
|
234
255
|
notLinked: "Live, not linked from the Hub yet",
|
|
235
256
|
checking: "Checking your access…",
|
|
236
257
|
};
|
|
258
|
+
/**
|
|
259
|
+
* The mark after the name of a row whose page is a sample (0.3.2, the
|
|
260
|
+
* owner's "(*)" for work in progress): a row that opens its page in the Hub
|
|
261
|
+
* (`osHubPath`, the design's sample dashboards, mock data) because its tool
|
|
262
|
+
* has no app to open, Finance's, Marketing's and Commercial's Overviews
|
|
263
|
+
* among them (Operations' opens Ops Hub since 0.3.3, and is a sample only
|
|
264
|
+
* where Ops Hub is held with no address yet). osFrame decides it
|
|
265
|
+
* where it decides the link, so a tool loses the mark the day it links to
|
|
266
|
+
* an app. A row that opens an app, this app's own tools, a locked row and
|
|
267
|
+
* the Hub panel (the Hub's real pages) have none. The Hub's sample pages put
|
|
268
|
+
* it on their tabs too (`osSampleLabel`), since all their data is mock.
|
|
269
|
+
*/
|
|
270
|
+
export const OS_SAMPLE_MARK = " (*)";
|
|
271
|
+
/** `label` with the sample mark after it, once. */
|
|
272
|
+
export function osSampleLabel(label) {
|
|
273
|
+
return label.endsWith(OS_SAMPLE_MARK) ? label : `${label}${OS_SAMPLE_MARK}`;
|
|
274
|
+
}
|
|
275
|
+
/** The Settings tab's id, label and glyph (the rail's own settings glyph), 0.3.2. */
|
|
276
|
+
export const OS_SETTINGS_TAB = { id: "settings", label: "Settings", icon: "settings" };
|
|
277
|
+
/**
|
|
278
|
+
* An app's own settings page as a tab in its tool's panel (0.3.2). The rail's
|
|
279
|
+
* Settings opens the Hub's settings in every app, so an app with settings of
|
|
280
|
+
* its own lists them with its other views, as the last tab, with the rail's
|
|
281
|
+
* settings glyph: `tabs: [...views, osSettingsTab("/settings")]`, or with
|
|
282
|
+
* titled tabs a group of its own, `{ title: "Setup", items:
|
|
283
|
+
* [osSettingsTab("/settings")] }`. Pages under `path` are on it too; `match`
|
|
284
|
+
* names more paths that are.
|
|
285
|
+
*/
|
|
286
|
+
export function osSettingsTab(path, options = {}) {
|
|
287
|
+
return { ...OS_SETTINGS_TAB, path, ...(options.match ? { match: options.match } : {}) };
|
|
288
|
+
}
|
|
237
289
|
/** The rail footer: Admin (for someone who manages something), Settings, then Sign out, always last. */
|
|
238
290
|
export function osFooter({ admin = false } = {}) {
|
|
239
291
|
return [
|
|
@@ -244,14 +296,18 @@ export function osFooter({ admin = false } = {}) {
|
|
|
244
296
|
}
|
|
245
297
|
/**
|
|
246
298
|
* Tool id to address, for the tools with a fixed `url`: what a frame off the
|
|
247
|
-
* core, which has no catalogue to ask, can link to.
|
|
248
|
-
*
|
|
299
|
+
* core, which has no catalogue to ask, can link to. Every other row of such
|
|
300
|
+
* a frame opens its page in the Hub, through HUB_URL. Given the company's
|
|
301
|
+
* slug (0.3.2), each address carries it as ?tenant=, exactly as
|
|
302
|
+
* catalogueLinks() writes it, so a row goes to the same address from every
|
|
303
|
+
* app; pass the same slug to osFrame as `tenantSlug` for the rows into the
|
|
304
|
+
* Hub. Without one, no hint.
|
|
249
305
|
*/
|
|
250
|
-
export function staticLinks() {
|
|
306
|
+
export function staticLinks(tenantSlug = null) {
|
|
251
307
|
const out = {};
|
|
252
308
|
for (const [id, link] of Object.entries(OS_TOOL_LINKS))
|
|
253
309
|
if (link.url)
|
|
254
|
-
out[id] = joinPath(link.url, link.path);
|
|
310
|
+
out[id] = withTenantHint(joinPath(link.url, link.path), tenantSlug);
|
|
255
311
|
return out;
|
|
256
312
|
}
|
|
257
313
|
/**
|
|
@@ -388,7 +444,7 @@ function best(routes, location, exact = false) {
|
|
|
388
444
|
* company, the footer, and the only routing logic the frame needs.
|
|
389
445
|
*/
|
|
390
446
|
export function osFrame(options) {
|
|
391
|
-
const { appKey, tools = [], hubItems, admin = false,
|
|
447
|
+
const { appKey, tools = [], hubItems, admin = false, hubUrl = HUB_URL, tenantSlug = null, } = options;
|
|
392
448
|
const links = underMenuIds(options.links ?? {});
|
|
393
449
|
const locked = underMenuIds(options.locked ?? {});
|
|
394
450
|
const isHub = appKey === "hub";
|
|
@@ -400,6 +456,8 @@ export function osFrame(options) {
|
|
|
400
456
|
? { ...base, path, ...(match ? { match } : {}) }
|
|
401
457
|
: { ...base, href: withTenantHint(`${hubUrl}${path}`, tenantSlug) });
|
|
402
458
|
const sections = {};
|
|
459
|
+
/* In the Hub, the pages of locked rows (0.3.3): see the claims below. */
|
|
460
|
+
const lockedPages = [];
|
|
403
461
|
const hubMenu = hubItems ?? OS_HUB_MENU;
|
|
404
462
|
if (hubMenu.length) {
|
|
405
463
|
sections["hub"] = hubItems
|
|
@@ -426,12 +484,15 @@ export function osFrame(options) {
|
|
|
426
484
|
if (href)
|
|
427
485
|
return { ...base, ...(isHub ? { match: [page] } : {}), href };
|
|
428
486
|
const reason = locked[entry.id];
|
|
429
|
-
if (reason)
|
|
487
|
+
if (reason) {
|
|
488
|
+
if (isHub)
|
|
489
|
+
lockedPages.push({ fn, page });
|
|
430
490
|
return { ...base, disabled: true, title: reason };
|
|
491
|
+
}
|
|
431
492
|
/* No app of its own (or one this frame cannot reach: off the core
|
|
432
493
|
with no fixed address, or held and not deployed yet): its page in
|
|
433
|
-
the Hub. */
|
|
434
|
-
return inHub(base, page);
|
|
494
|
+
the Hub, a sample, marked so (0.3.2). */
|
|
495
|
+
return inHub({ ...base, label: osSampleLabel(base.label) }, page);
|
|
435
496
|
}),
|
|
436
497
|
}));
|
|
437
498
|
}
|
|
@@ -456,8 +517,6 @@ export function osFrame(options) {
|
|
|
456
517
|
both at /), it is on the tab: the list and a draft under it are one
|
|
457
518
|
place. */
|
|
458
519
|
const claims = [];
|
|
459
|
-
if (settingsPath)
|
|
460
|
-
claims.push({ routes: [settingsPath], spot: { fn: "settings", item: null, tab: null } });
|
|
461
520
|
if (isHub)
|
|
462
521
|
claims.push({ routes: [HUB_PATHS.admin], spot: { fn: "admin", item: null, tab: null } });
|
|
463
522
|
for (const [fn, list] of Object.entries(sections)) {
|
|
@@ -472,6 +531,13 @@ export function osFrame(options) {
|
|
|
472
531
|
}
|
|
473
532
|
}
|
|
474
533
|
}
|
|
534
|
+
/* A locked row's page in the Hub files under its function, with no row
|
|
535
|
+
picked (0.3.3): someone who does not hold Ops Hub and opens
|
|
536
|
+
/os/operations (Operations' Overview, Ops Hub's since 0.3.3) sees the
|
|
537
|
+
Operations menu with that row locked, not the Hub's landing. After every
|
|
538
|
+
row's own claim, so a row that claims the same path wins. */
|
|
539
|
+
for (const { fn, page } of lockedPages)
|
|
540
|
+
claims.push({ routes: [page], spot: { fn, item: null, tab: null } });
|
|
475
541
|
const landingFn = tools.map((mine) => fnOf(sections, osToolId(mine.id))).find((fn) => fn !== undefined);
|
|
476
542
|
const locate = (location) => {
|
|
477
543
|
let url;
|
|
@@ -515,12 +581,10 @@ export function osFrame(options) {
|
|
|
515
581
|
const internal = (href, spot) => (here.fn === spot.fn && here.item === spot.item && here.tab === spot.tab ? null : { href, external: false });
|
|
516
582
|
/* A path of this app, unless the URL is exactly there already. */
|
|
517
583
|
const goTo = (href) => (at(location, href) ? null : { href, external: false });
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
return goTo(path);
|
|
523
|
-
}
|
|
584
|
+
/* Settings is the Hub's in every app (0.3.2), whatever `settingsPath`
|
|
585
|
+
says: in the Hub its own route, elsewhere a link into the Hub. */
|
|
586
|
+
if (fn === "settings")
|
|
587
|
+
return isHub ? goTo(HUB_PATHS.settings) : toHub(HUB_PATHS.settings);
|
|
524
588
|
if (fn === "admin") {
|
|
525
589
|
if (!isHub)
|
|
526
590
|
return toHub(HUB_PATHS.admin);
|
|
@@ -539,7 +603,7 @@ export function osFrame(options) {
|
|
|
539
603
|
/* The rail's Hub where the person is already in the Hub (a thread, a
|
|
540
604
|
tool, the landing) reopens its menu on that page: it is the menu's
|
|
541
605
|
control, never a navigation. Back to hub, and the rail's Hub from
|
|
542
|
-
another place (Admin
|
|
606
|
+
another place (Admin), land on the landing. */
|
|
543
607
|
if (!state.back && here.fn === fn && (sections[fn]?.length ?? 0) > 0)
|
|
544
608
|
return null;
|
|
545
609
|
/* The Hub: stay anywhere on the landing's own ground, else land on it. */
|
|
@@ -571,6 +635,82 @@ export function osFrame(options) {
|
|
|
571
635
|
};
|
|
572
636
|
return { functions: OS_FUNCTIONS, sections, footerItems, homeFunction: "hub", locate, targetFor };
|
|
573
637
|
}
|
|
638
|
+
/**
|
|
639
|
+
* Every place the menu reaches, in the menu's own order (0.3.2): the rows of
|
|
640
|
+
* each function's menu, the Hub panel's first, each followed by the tabs of
|
|
641
|
+
* this app's tool when it is one. A locked row, a disabled tab and a tab with
|
|
642
|
+
* no path (page state, nowhere to go) are left out.
|
|
643
|
+
*/
|
|
644
|
+
export function osMenuEntries(frame) {
|
|
645
|
+
const out = [];
|
|
646
|
+
const names = new Map(frame.functions.map((fn) => [fn.id, fn.label]));
|
|
647
|
+
for (const [fn, list] of Object.entries(frame.sections)) {
|
|
648
|
+
const fnLabel = names.get(fn) ?? fn;
|
|
649
|
+
for (const section of list) {
|
|
650
|
+
for (const row of section.items) {
|
|
651
|
+
if (row.disabled)
|
|
652
|
+
continue;
|
|
653
|
+
out.push({
|
|
654
|
+
key: `${fn}/${row.id}`, label: row.label, context: [fnLabel, section.title].filter(Boolean).join(" · "),
|
|
655
|
+
...(row.icon ? { icon: row.icon } : {}),
|
|
656
|
+
state: { fn: { id: fn }, item: { id: row.id }, tab: null },
|
|
657
|
+
});
|
|
658
|
+
for (const group of tabGroups(row.tabs)) {
|
|
659
|
+
for (const tab of group.items) {
|
|
660
|
+
if (tab.disabled || !tab.path)
|
|
661
|
+
continue;
|
|
662
|
+
out.push({
|
|
663
|
+
key: `${fn}/${row.id}/${tab.id}`, label: tab.label, context: [row.label, group.title].filter(Boolean).join(" · "),
|
|
664
|
+
...(tab.icon ? { icon: tab.icon } : {}),
|
|
665
|
+
state: { fn: { id: fn }, item: { id: row.id }, tab: { id: tab.id } },
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return out;
|
|
673
|
+
}
|
|
674
|
+
/* Lower case, accents off: "Cafe" finds "Café". */
|
|
675
|
+
const fold = (text) => text.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
|
|
676
|
+
/**
|
|
677
|
+
* The entries that match `query`, best first, at most `limit` (0.3.2). Every
|
|
678
|
+
* word typed must be in the entry's name or where it sits ("finance overview"
|
|
679
|
+
* finds Finance's Overview). Names that are the words, start with them, have
|
|
680
|
+
* a word that starts with them, or hold them come first, in that order; then
|
|
681
|
+
* the entries found only by where they sit. Ties keep the menu's order.
|
|
682
|
+
*/
|
|
683
|
+
export function searchOsMenu(entries, query, limit = 8) {
|
|
684
|
+
const words = fold(query).split(/\s+/).filter(Boolean);
|
|
685
|
+
if (words.length === 0)
|
|
686
|
+
return [];
|
|
687
|
+
const typed = words.join(" ");
|
|
688
|
+
const ranked = [];
|
|
689
|
+
entries.forEach((entry, at) => {
|
|
690
|
+
/* The sample mark is no part of the name. */
|
|
691
|
+
const label = fold(entry.label.endsWith(OS_SAMPLE_MARK) ? entry.label.slice(0, -OS_SAMPLE_MARK.length) : entry.label);
|
|
692
|
+
const all = `${label} ${fold(entry.context)}`;
|
|
693
|
+
if (!words.every((word) => all.includes(word)))
|
|
694
|
+
return;
|
|
695
|
+
const rank = label === typed ? 0
|
|
696
|
+
: label.startsWith(typed) ? 1
|
|
697
|
+
: label.split(/[^\p{L}\p{N}]+/u).some((part) => part.startsWith(typed)) ? 2
|
|
698
|
+
: label.includes(typed) ? 3
|
|
699
|
+
: words.every((word) => label.includes(word)) ? 4
|
|
700
|
+
: 5;
|
|
701
|
+
ranked.push({ entry, rank, at });
|
|
702
|
+
});
|
|
703
|
+
ranked.sort((a, b) => a.rank - b.rank || a.at - b.at);
|
|
704
|
+
return ranked.slice(0, Math.max(0, limit)).map(({ entry }) => entry);
|
|
705
|
+
}
|
|
706
|
+
/* Tabs as titled groups, whether given flat (one group with no title) or in groups. */
|
|
707
|
+
function tabGroups(tabs) {
|
|
708
|
+
if (!tabs || tabs.length === 0)
|
|
709
|
+
return [];
|
|
710
|
+
if ("items" in tabs[0])
|
|
711
|
+
return tabs;
|
|
712
|
+
return [{ items: tabs }];
|
|
713
|
+
}
|
|
574
714
|
function rowFor(base, mine) {
|
|
575
715
|
const row = { ...base };
|
|
576
716
|
if (mine.path)
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OS menu search (0.3.2): the top bar's field in an app with no search of
|
|
3
|
+
* its own, so every app's bar is the Hub's. Type to jump to any app or page
|
|
4
|
+
* the menu reaches: every row of every function's menu, the Hub panel's rows
|
|
5
|
+
* and this app's own tools' tabs (`osMenuEntries`). The matches hang under
|
|
6
|
+
* the field; the arrow keys move through them, Enter or a click opens the
|
|
7
|
+
* one marked (the first, until the arrows move), and Escape closes them.
|
|
8
|
+
*
|
|
9
|
+
* OsWorkspaceFrame (`autosolutions-os/frame`) runs it by itself when the app
|
|
10
|
+
* passes no `search.onChange`. An app that draws the design system's
|
|
11
|
+
* WorkspaceFrame with `osFrame()` itself (an app on its own project) calls
|
|
12
|
+
* `useOsMenuSearch`, spreads `topBar` on its TopBar and renders `results`
|
|
13
|
+
* after the frame. React only: no design system, no Supabase.
|
|
14
|
+
*/
|
|
15
|
+
import { type ReactNode } from "react";
|
|
16
|
+
import { type OsFrame } from "./nav.js";
|
|
17
|
+
export type OsMenuSearchOptions = {
|
|
18
|
+
/** The frame from `osFrame()`: its menus are what the search finds, and its `targetFor` where each goes. */
|
|
19
|
+
frame: Pick<OsFrame, "functions" | "sections" | "targetFor">;
|
|
20
|
+
/** Where the app is: pathname plus query, as the frame is given it. */
|
|
21
|
+
location: string;
|
|
22
|
+
/** Push an in-app path (a row or tab of this app). */
|
|
23
|
+
onNavigate: (href: string) => void;
|
|
24
|
+
/** Open another app or the Hub. Default: the same tab (`window.location.assign`), as the menu does. */
|
|
25
|
+
onLeave?: (href: string) => void;
|
|
26
|
+
/** The field's placeholder and name. Default "Search", the Hub's. */
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
/** ⌘K / Ctrl+K puts the cursor in the field, and the field shows the hint. Default false: no hint without the shortcut. */
|
|
29
|
+
shortcut?: boolean;
|
|
30
|
+
/** The bar's search input. Default: the workspace bar's (`.as-topbar--ws .as-topbar__search input`). */
|
|
31
|
+
field?: () => HTMLInputElement | null;
|
|
32
|
+
};
|
|
33
|
+
export type OsMenuSearch = {
|
|
34
|
+
/** Spread on the TopBar: its field is the search. */
|
|
35
|
+
topBar: {
|
|
36
|
+
searchPlaceholder: string;
|
|
37
|
+
searchValue: string;
|
|
38
|
+
onSearchChange: (value: string) => void;
|
|
39
|
+
shortcut?: boolean;
|
|
40
|
+
};
|
|
41
|
+
/** The matches under the field, or null while closed. Render it after the frame. */
|
|
42
|
+
results: ReactNode;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The OS menu search for an app that draws the frame itself:
|
|
46
|
+
*
|
|
47
|
+
* const frame = osFrame({ appKey, tools, links: staticLinks(slug), tenantSlug: slug });
|
|
48
|
+
* const search = useOsMenuSearch({ frame, location: here, onNavigate: (href) => navigate(href) });
|
|
49
|
+
* <WorkspaceFrame topBar={<TopBar {...search.topBar} companySrc={mark} />} ...>{page}</WorkspaceFrame>
|
|
50
|
+
* {search.results}
|
|
51
|
+
*/
|
|
52
|
+
export declare function useOsMenuSearch(options: OsMenuSearchOptions): OsMenuSearch;
|
|
53
|
+
/**
|
|
54
|
+
* The search itself. `on` false leaves the field alone (OsWorkspaceFrame,
|
|
55
|
+
* while the app's own search has it) and draws nothing.
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export declare function useMenuSearch(options: OsMenuSearchOptions, on: boolean): OsMenuSearch;
|
package/dist/search.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The OS menu search (0.3.2): the top bar's field in an app with no search of
|
|
4
|
+
* its own, so every app's bar is the Hub's. Type to jump to any app or page
|
|
5
|
+
* the menu reaches: every row of every function's menu, the Hub panel's rows
|
|
6
|
+
* and this app's own tools' tabs (`osMenuEntries`). The matches hang under
|
|
7
|
+
* the field; the arrow keys move through them, Enter or a click opens the
|
|
8
|
+
* one marked (the first, until the arrows move), and Escape closes them.
|
|
9
|
+
*
|
|
10
|
+
* OsWorkspaceFrame (`autosolutions-os/frame`) runs it by itself when the app
|
|
11
|
+
* passes no `search.onChange`. An app that draws the design system's
|
|
12
|
+
* WorkspaceFrame with `osFrame()` itself (an app on its own project) calls
|
|
13
|
+
* `useOsMenuSearch`, spreads `topBar` on its TopBar and renders `results`
|
|
14
|
+
* after the frame. React only: no design system, no Supabase.
|
|
15
|
+
*/
|
|
16
|
+
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
17
|
+
import { osMenuEntries, searchOsMenu } from "./nav.js";
|
|
18
|
+
const WORKSPACE_FIELD = ".as-topbar--ws .as-topbar__search input";
|
|
19
|
+
const workspaceField = () => (typeof document === "undefined" ? null : document.querySelector(WORKSPACE_FIELD));
|
|
20
|
+
const leave = (href) => { window.location.assign(href); };
|
|
21
|
+
/** The narrowest the matches get, so a name and where it sits stay readable on a phone (as the CRM's). */
|
|
22
|
+
const PANEL_MIN_WIDTH = 320;
|
|
23
|
+
/** What the matches keep clear of the screen's edges. */
|
|
24
|
+
const PANEL_GUTTER = 16;
|
|
25
|
+
/**
|
|
26
|
+
* The OS menu search for an app that draws the frame itself:
|
|
27
|
+
*
|
|
28
|
+
* const frame = osFrame({ appKey, tools, links: staticLinks(slug), tenantSlug: slug });
|
|
29
|
+
* const search = useOsMenuSearch({ frame, location: here, onNavigate: (href) => navigate(href) });
|
|
30
|
+
* <WorkspaceFrame topBar={<TopBar {...search.topBar} companySrc={mark} />} ...>{page}</WorkspaceFrame>
|
|
31
|
+
* {search.results}
|
|
32
|
+
*/
|
|
33
|
+
export function useOsMenuSearch(options) {
|
|
34
|
+
return useMenuSearch(options, true);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The search itself. `on` false leaves the field alone (OsWorkspaceFrame,
|
|
38
|
+
* while the app's own search has it) and draws nothing.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export function useMenuSearch(options, on) {
|
|
42
|
+
const { frame, location, onNavigate, onLeave, placeholder = "Search", shortcut = false, field = workspaceField } = options;
|
|
43
|
+
const [query, setQuery] = useState("");
|
|
44
|
+
const [open, setOpen] = useState(false);
|
|
45
|
+
const [active, setActive] = useState(0);
|
|
46
|
+
const [input, setInput] = useState(null);
|
|
47
|
+
const [box, setBox] = useState(null);
|
|
48
|
+
const panel = useRef(null);
|
|
49
|
+
const id = useId();
|
|
50
|
+
const listId = `os-menu-search-${id.replace(/[^\w-]/g, "")}`;
|
|
51
|
+
const entries = useMemo(() => osMenuEntries(frame), [frame.functions, frame.sections]);
|
|
52
|
+
const matches = useMemo(() => searchOsMenu(entries, query), [entries, query]);
|
|
53
|
+
const showing = on && open && query.trim() !== "";
|
|
54
|
+
const marked = Math.min(active, Math.max(matches.length - 1, 0));
|
|
55
|
+
/* Open one: where a click on its row or tab goes from here. Nowhere (it
|
|
56
|
+
is the page shown) only closes the search. */
|
|
57
|
+
const go = (entry) => {
|
|
58
|
+
const target = frame.targetFor(entry.state, location);
|
|
59
|
+
setQuery("");
|
|
60
|
+
setOpen(false);
|
|
61
|
+
setActive(0);
|
|
62
|
+
input?.blur();
|
|
63
|
+
if (!target)
|
|
64
|
+
return;
|
|
65
|
+
if (target.external)
|
|
66
|
+
(onLeave ?? leave)(target.href);
|
|
67
|
+
else
|
|
68
|
+
onNavigate(target.href);
|
|
69
|
+
};
|
|
70
|
+
/* What the field's own listeners read: always this render's. */
|
|
71
|
+
const now = useRef({ matches, marked, showing, go });
|
|
72
|
+
now.current = { matches, marked, showing, go };
|
|
73
|
+
/* The bar draws the field; find it after every render (a new bar, a new field). */
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const found = on ? field() : null;
|
|
76
|
+
if (found !== input)
|
|
77
|
+
setInput(found);
|
|
78
|
+
});
|
|
79
|
+
/* The field's keys, focus and blur, and what it says it controls. */
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!input)
|
|
82
|
+
return undefined;
|
|
83
|
+
const onKeyDown = (e) => {
|
|
84
|
+
const { matches: list, marked: at, showing: shown } = now.current;
|
|
85
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
86
|
+
if (!shown || list.length === 0)
|
|
87
|
+
return;
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
setActive(e.key === "ArrowDown" ? Math.min(at + 1, list.length - 1) : Math.max(at - 1, 0));
|
|
90
|
+
}
|
|
91
|
+
else if (e.key === "Enter") {
|
|
92
|
+
const hit = shown ? list[at] : undefined;
|
|
93
|
+
if (!hit)
|
|
94
|
+
return;
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
now.current.go(hit);
|
|
97
|
+
}
|
|
98
|
+
else if (e.key === "Escape") {
|
|
99
|
+
/* A search field empties itself on Escape: with the matches open,
|
|
100
|
+
Escape closes them and keeps what was typed, as the CRM's does. */
|
|
101
|
+
if (!shown)
|
|
102
|
+
return;
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
setOpen(false);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const onFocus = () => setOpen(true);
|
|
108
|
+
const onBlur = (e) => {
|
|
109
|
+
if (panel.current && e.relatedTarget instanceof Node && panel.current.contains(e.relatedTarget))
|
|
110
|
+
return;
|
|
111
|
+
setOpen(false);
|
|
112
|
+
};
|
|
113
|
+
input.addEventListener("keydown", onKeyDown);
|
|
114
|
+
input.addEventListener("focus", onFocus);
|
|
115
|
+
input.addEventListener("blur", onBlur);
|
|
116
|
+
input.setAttribute("role", "combobox");
|
|
117
|
+
input.setAttribute("aria-autocomplete", "list");
|
|
118
|
+
input.setAttribute("aria-controls", listId);
|
|
119
|
+
return () => {
|
|
120
|
+
input.removeEventListener("keydown", onKeyDown);
|
|
121
|
+
input.removeEventListener("focus", onFocus);
|
|
122
|
+
input.removeEventListener("blur", onBlur);
|
|
123
|
+
for (const name of ["role", "aria-autocomplete", "aria-controls", "aria-expanded", "aria-activedescendant"])
|
|
124
|
+
input.removeAttribute(name);
|
|
125
|
+
};
|
|
126
|
+
}, [input, listId]);
|
|
127
|
+
/* Open or closed, and which match is marked, as a combobox says it. */
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (!input)
|
|
130
|
+
return;
|
|
131
|
+
input.setAttribute("aria-expanded", String(showing));
|
|
132
|
+
if (showing && matches.length > 0)
|
|
133
|
+
input.setAttribute("aria-activedescendant", `${listId}-${marked}`);
|
|
134
|
+
else
|
|
135
|
+
input.removeAttribute("aria-activedescendant");
|
|
136
|
+
});
|
|
137
|
+
/* ⌘K / Ctrl+K, only when the app asks for it (the field then shows the hint). */
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
if (!on || !shortcut)
|
|
140
|
+
return undefined;
|
|
141
|
+
const onKey = (e) => {
|
|
142
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") {
|
|
143
|
+
const target = field();
|
|
144
|
+
if (!target)
|
|
145
|
+
return;
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
target.focus();
|
|
148
|
+
setOpen(true);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
window.addEventListener("keydown", onKey);
|
|
152
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
153
|
+
}, [on, shortcut, field]);
|
|
154
|
+
/* Under the field, as wide as it and never narrower than 320px, kept
|
|
155
|
+
inside the screen. The bar sticks to the top, so the place holds while
|
|
156
|
+
the page scrolls; it is measured again when the window changes. */
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (!showing || !input)
|
|
159
|
+
return undefined;
|
|
160
|
+
const place = () => {
|
|
161
|
+
const rect = (input.closest(".as-topbar__search") ?? input).getBoundingClientRect();
|
|
162
|
+
const view = document.documentElement.clientWidth || window.innerWidth;
|
|
163
|
+
const width = Math.max(0, Math.min(Math.max(rect.width, PANEL_MIN_WIDTH), view - 2 * PANEL_GUTTER));
|
|
164
|
+
const left = Math.max(PANEL_GUTTER, Math.min(rect.left, view - PANEL_GUTTER - width));
|
|
165
|
+
setBox((was) => (was && was.top === rect.bottom + 4 && was.left === left && was.width === width ? was : { top: rect.bottom + 4, left, width }));
|
|
166
|
+
};
|
|
167
|
+
place();
|
|
168
|
+
window.addEventListener("resize", place);
|
|
169
|
+
window.addEventListener("scroll", place, true);
|
|
170
|
+
return () => {
|
|
171
|
+
window.removeEventListener("resize", place);
|
|
172
|
+
window.removeEventListener("scroll", place, true);
|
|
173
|
+
};
|
|
174
|
+
}, [showing, input]);
|
|
175
|
+
const results = showing ? (_jsx("div", { ref: panel, id: listId, role: "listbox", "aria-label": "Search results", "data-os-menu-search": "", style: panelStyle(box),
|
|
176
|
+
/* The field keeps the focus: a click on a match is a pick, not a blur. */
|
|
177
|
+
onMouseDown: (e) => e.preventDefault(), children: matches.length === 0 ? (_jsx("div", { style: EMPTY, children: "No matches" })) : matches.map((entry, at) => (_jsxs("div", { id: `${listId}-${at}`, role: "option", "aria-selected": at === marked, style: at === marked ? OPTION_MARKED : OPTION, onMouseEnter: () => setActive(at), onClick: () => go(entry), children: [_jsx("span", { style: LABEL, children: entry.label }), entry.context && _jsx("span", { style: CONTEXT, children: entry.context })] }, entry.key))) })) : null;
|
|
178
|
+
return {
|
|
179
|
+
topBar: {
|
|
180
|
+
searchPlaceholder: placeholder,
|
|
181
|
+
searchValue: query,
|
|
182
|
+
onSearchChange: (value) => {
|
|
183
|
+
setQuery(value);
|
|
184
|
+
setOpen(true);
|
|
185
|
+
setActive(0);
|
|
186
|
+
},
|
|
187
|
+
...(shortcut ? { shortcut: true } : {}),
|
|
188
|
+
},
|
|
189
|
+
results,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/* The frame's popover, as the company menu wears it (the frame's private
|
|
193
|
+
tokens, with their values for a page outside the frame). */
|
|
194
|
+
const FONT = 'var(--ws-font, "AS Frame Inter", "Noto Sans Arabic", "Noto Sans Hebrew", -apple-system, BlinkMacSystemFont, "San Francisco", "Segoe UI", Roboto, "Helvetica Neue", sans-serif)';
|
|
195
|
+
const SHADOW = "var(--ws-shadow-popover, 0 8px 24px -8px rgba(0,0,0,.28), 0 8px 16px -4px rgba(0,0,0,.05), 0 3px 6px 0 rgba(0,0,0,.05), 0 2px 4px 0 rgba(0,0,0,.05), 0 1px 2px 0 rgba(0,0,0,.05), 0 0 0 1px rgba(0,0,0,.06))";
|
|
196
|
+
function panelStyle(box) {
|
|
197
|
+
return {
|
|
198
|
+
position: "fixed",
|
|
199
|
+
top: box?.top ?? 0,
|
|
200
|
+
left: box?.left ?? 0,
|
|
201
|
+
width: box?.width ?? PANEL_MIN_WIDTH,
|
|
202
|
+
visibility: box ? "visible" : "hidden",
|
|
203
|
+
zIndex: "var(--ws-z-popover, 514)",
|
|
204
|
+
boxSizing: "border-box",
|
|
205
|
+
maxHeight: 380,
|
|
206
|
+
overflowY: "auto",
|
|
207
|
+
padding: "var(--ws-space-100, .25rem)",
|
|
208
|
+
background: "var(--ws-color-surface, #FFFFFF)",
|
|
209
|
+
borderRadius: "var(--ws-radius-chip, .625rem)",
|
|
210
|
+
boxShadow: SHADOW,
|
|
211
|
+
color: "var(--ws-color-text, #303030)",
|
|
212
|
+
fontFamily: FONT,
|
|
213
|
+
fontSize: "var(--ws-size-body, .8125rem)",
|
|
214
|
+
lineHeight: "var(--ws-line-body, 1.25rem)",
|
|
215
|
+
fontWeight: "var(--ws-weight, 450)",
|
|
216
|
+
textAlign: "start",
|
|
217
|
+
overflowWrap: "anywhere",
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const OPTION = {
|
|
221
|
+
display: "flex",
|
|
222
|
+
flexDirection: "column",
|
|
223
|
+
justifyContent: "center",
|
|
224
|
+
minHeight: "var(--ws-space-800, 2rem)",
|
|
225
|
+
padding: "var(--ws-space-150, .375rem) var(--ws-space-200, .5rem)",
|
|
226
|
+
borderRadius: "var(--ws-radius-item, .5rem)",
|
|
227
|
+
background: "transparent",
|
|
228
|
+
cursor: "pointer",
|
|
229
|
+
};
|
|
230
|
+
const OPTION_MARKED = { ...OPTION, background: "var(--ws-color-fill-selected, rgba(0,0,0,.06))" };
|
|
231
|
+
const LABEL = { display: "block", overflow: "hidden", whiteSpace: "nowrap", textOverflow: "ellipsis" };
|
|
232
|
+
const CONTEXT = {
|
|
233
|
+
display: "block",
|
|
234
|
+
fontSize: "var(--ws-size-small, .75rem)",
|
|
235
|
+
lineHeight: "var(--ws-line-small, 1rem)",
|
|
236
|
+
color: "var(--ws-color-text-secondary, #616161)",
|
|
237
|
+
};
|
|
238
|
+
const EMPTY = { padding: "var(--ws-space-150, .375rem) var(--ws-space-200, .5rem)", color: "var(--ws-color-text-secondary, #616161)" };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autosolutions-os",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "One sign-in, one company switcher, one app grid. What every AutoSolutions app imports instead of copying.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"./nav": { "types": "./dist/nav.d.ts", "import": "./dist/nav.js" },
|
|
13
13
|
"./frame": { "types": "./dist/frame.d.ts", "import": "./dist/frame.js" },
|
|
14
14
|
"./federation": { "types": "./dist/federation.d.ts", "import": "./dist/federation.js" },
|
|
15
|
+
"./search": { "types": "./dist/search.d.ts", "import": "./dist/search.js" },
|
|
15
16
|
"./chrome.css": "./dist/chrome.css"
|
|
16
17
|
},
|
|
17
18
|
"files": ["dist", "CHANGELOG.md"],
|