@protobase/ui 0.55.2 → 0.55.4
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/dist/app/create/create-page.js +11 -1
- package/dist/app/marks/marks-hook.d.ts +10 -0
- package/dist/app/nav-from-meta.js +19 -3
- package/dist/app/nav-recent.js +10 -1
- package/dist/app/pages/merge-ui.d.ts +1 -1
- package/dist/app/pages/merge-ui.js +3 -1
- package/dist/app/pages/project-ui.d.ts +4 -1
- package/dist/app/use-live-save.js +11 -4
- package/dist/app/use-nav-recent.js +10 -6
- package/dist/app-shell/index.d.ts +1 -1
- package/dist/app-shell/nav.d.ts +13 -1
- package/dist/app-shell/record-marks.js +18 -0
- package/dist/app-shell/sidebar-create-link.js +26 -0
- package/dist/app-shell/sidebar-group.js +15 -30
- package/dist/app-shell/sidebar-records.js +54 -0
- package/dist/app-shell/sidebar-rows.js +13 -0
- package/dist/app-shell/sidebar.js +11 -5
- package/dist/auth/auth-provider.d.ts +4 -0
- package/dist/auth/use-signed-in-user.d.ts +13 -0
- package/dist/auth/use-signed-in-user.js +22 -0
- package/dist/chat/chat-thread.d.ts +10 -4
- package/dist/chat/chat-thread.js +20 -6
- package/dist/chat/thread-scroll.js +4 -1
- package/dist/chat/use-read-to-end.js +32 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +2 -1
- package/dist/notifications/bell/notification-bell.js +5 -8
- package/dist/notifications/bell/unread-label.js +1 -3
- package/dist/notifications/push/push-notifications.d.ts +1 -0
- package/dist/package.js +1 -1
- package/dist/plugins/plugin-ui.js +1 -0
- package/dist/primitives/count-badge.js +20 -0
- package/dist/shell/assets/app-NiljOxYe.js +9 -0
- package/dist/shell/assets/{index-CY05Rf2z.js → index-BIUTidjX.js} +2 -2
- package/dist/shell/assets/{records-map-DA9Zv2ST.js → records-map-BwX2z-di.js} +2 -2
- package/dist/shell/assets/shared-protobase-ui-BD_5D_Ot.js +2 -0
- package/dist/shell/index.html +3 -3
- package/dist/shell/protobase.shell.json +1 -1
- package/dist/shell/protobase.sw.js +2 -2
- package/dist/shell-source-maps/assets/app-NiljOxYe.js.map +1 -0
- package/dist/shell-source-maps/assets/{index-CY05Rf2z.js.map → index-BIUTidjX.js.map} +1 -1
- package/dist/shell-source-maps/assets/{records-map-DA9Zv2ST.js.map → records-map-BwX2z-di.js.map} +1 -1
- package/dist/shell-source-maps/assets/shared-protobase-ui-BD_5D_Ot.js.map +1 -0
- package/package.json +4 -4
- package/dist/shell/assets/app-CTbX0_B2.js +0 -9
- package/dist/shell/assets/shared-protobase-ui-DjAPl6MN.js +0 -2
- package/dist/shell-source-maps/assets/app-CTbX0_B2.js.map +0 -1
- package/dist/shell-source-maps/assets/shared-protobase-ui-DjAPl6MN.js.map +0 -1
|
@@ -12,9 +12,10 @@ import { can } from "../permissions.js";
|
|
|
12
12
|
import { fetchLabels } from "../../live/relation-labels.js";
|
|
13
13
|
import { fieldErrors, fieldMessage } from "../field-errors.js";
|
|
14
14
|
import { useFocusFirstInvalid } from "../use-focus-first-invalid.js";
|
|
15
|
-
import { useLiveSave } from "../use-live-save.js";
|
|
15
|
+
import { nothingSaved, useLiveSave } from "../use-live-save.js";
|
|
16
16
|
import { CreateRecordForm } from "./create-record-form.js";
|
|
17
17
|
import { useEffect, useState } from "react";
|
|
18
|
+
import { isApiError } from "@protobase/client";
|
|
18
19
|
import { jsx } from "react/jsx-runtime";
|
|
19
20
|
import { useQueryClient } from "@tanstack/react-query";
|
|
20
21
|
//#region src/app/create/create-page.tsx
|
|
@@ -92,6 +93,15 @@ const LoadedCreate = ({ resource, values }) => {
|
|
|
92
93
|
try {
|
|
93
94
|
created = await client.create(resource, createBody(model, meta.resources, draft));
|
|
94
95
|
} catch (error) {
|
|
96
|
+
const existing = isApiError(error) ? error.existing : void 0;
|
|
97
|
+
if (existing) {
|
|
98
|
+
setNewRecord({
|
|
99
|
+
kind: "record",
|
|
100
|
+
resource,
|
|
101
|
+
key: existing.key
|
|
102
|
+
});
|
|
103
|
+
return nothingSaved;
|
|
104
|
+
}
|
|
95
105
|
const found = fieldErrors(error);
|
|
96
106
|
setErrors(found);
|
|
97
107
|
if (Object.keys(found).length > 0) setRejections((count) => count + 1);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RecordMark } from "../../app-shell/nav.js";
|
|
2
|
+
//#region src/app/marks/marks-hook.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A hook a view's `.nav({ recent: { marks: name } })` names: how each record of `resource` stands out in the sidebar
|
|
5
|
+
* for the person reading, by the record's key as its address carries it, such as an unread conversation drawn bold with a
|
|
6
|
+
* count of its mentions. The sidebar group calls it while it shows the records, so it may use the API client, live
|
|
7
|
+
* updates and queries; returning undefined, as while it loads, marks none.
|
|
8
|
+
*/
|
|
9
|
+
export type MarksHook = (resource: string) => Record<string, RecordMark> | undefined;
|
|
10
|
+
//#endregion
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { allowEverything } from "../data/meta-data.js";
|
|
1
2
|
import { humanize } from "../live/naming.js";
|
|
2
3
|
import { text } from "./messages.js";
|
|
4
|
+
import { text as text$1 } from "./create/messages.js";
|
|
3
5
|
import { iconFor } from "./icons.js";
|
|
4
6
|
import { menuIcon } from "./menu-icons.js";
|
|
7
|
+
import { createOffered } from "./create/create-offered.js";
|
|
5
8
|
import { userMenuResources } from "./user-menu-from-meta.js";
|
|
6
9
|
import { LayoutDashboard } from "lucide-react";
|
|
7
10
|
import { appPath } from "@protobase/schema";
|
|
@@ -21,10 +24,21 @@ const schemaGroup = (schema = "public") => {
|
|
|
21
24
|
if (schema === "public") return "";
|
|
22
25
|
return groupLabels[schema] ? text(groupLabels[schema]) : humanize(schema);
|
|
23
26
|
};
|
|
27
|
+
/** The link under an entry whose `nav.create` asks for one, to whoever the list would offer New. */
|
|
28
|
+
const createLink = (meta, view, nav, singular, basePath) => {
|
|
29
|
+
if (!nav?.create || !createOffered(view, meta.pages, meta.permissions[view.resource] ?? allowEverything)) return {};
|
|
30
|
+
return { create: {
|
|
31
|
+
label: nav.create === true ? text$1("title", singular) : nav.create.label,
|
|
32
|
+
href: appPath({
|
|
33
|
+
kind: "create",
|
|
34
|
+
resource: view.resource
|
|
35
|
+
}, basePath)
|
|
36
|
+
} };
|
|
37
|
+
};
|
|
24
38
|
/**
|
|
25
39
|
* One sidebar group per `nav.group` (default: the database schema, none for `public`, and "Pages" for pages); `nav.hidden` and a place in
|
|
26
40
|
* the user menu leave an entry out, `nav.order` sorts within a group, and `recent` (from `useNavRecent`) makes an entry
|
|
27
|
-
* collapsible. Groups with pages come first, so a dashboard leads the sidebar. The resources of a source that cannot be
|
|
41
|
+
* collapsible, and `create` links to the create form under it. Groups with pages come first, so a dashboard leads the sidebar. The resources of a source that cannot be
|
|
28
42
|
* read are listed under its label, each with the problem. A visitor also gets the resources whose views ask them to sign
|
|
29
43
|
* in, where those views place them, under "Account" without a group. Each named list of a view is an entry of its
|
|
30
44
|
* own, placed by its own `nav`.
|
|
@@ -73,7 +87,8 @@ const navFromMeta = (meta, basePath = "", recent = {}) => {
|
|
|
73
87
|
kind: "list",
|
|
74
88
|
resource: model.name
|
|
75
89
|
}, basePath),
|
|
76
|
-
...recent[model.name] && { recent: recent[model.name] }
|
|
90
|
+
...recent[model.name] && { recent: recent[model.name] },
|
|
91
|
+
...createLink(meta, view, view.nav, view.names?.singular ?? humanize(model.name), basePath)
|
|
77
92
|
}, view.nav?.order);
|
|
78
93
|
for (const named of view.lists ?? []) {
|
|
79
94
|
if (named.nav?.hidden) continue;
|
|
@@ -85,7 +100,8 @@ const navFromMeta = (meta, basePath = "", recent = {}) => {
|
|
|
85
100
|
kind: "list",
|
|
86
101
|
resource: model.name,
|
|
87
102
|
list: named.name
|
|
88
|
-
}, basePath)
|
|
103
|
+
}, basePath),
|
|
104
|
+
...createLink(meta, view, named.nav, named.names.singular, basePath)
|
|
89
105
|
}, named.nav?.order);
|
|
90
106
|
}
|
|
91
107
|
}
|
package/dist/app/nav-recent.js
CHANGED
|
@@ -48,5 +48,14 @@ const recentRowDiffers = (model, fields, rows, key, record) => {
|
|
|
48
48
|
const row = rows.find((entry) => encodeKey(recordKey(model, entry)) === key);
|
|
49
49
|
return row !== void 0 && fields.some((field) => !Object.is(row[field], record[field]));
|
|
50
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* The hook that marks a group's records for the reader: the project UI's `marks` hook the group names, called with its
|
|
53
|
+
* resource. None when the group names no marks, or a name no UI config registers, such as a plugin that is turned off.
|
|
54
|
+
*/
|
|
55
|
+
const recentMarks = (resource, recent, hooks) => {
|
|
56
|
+
if (recent.marks === void 0 || !hooks || !Object.hasOwn(hooks, recent.marks)) return;
|
|
57
|
+
const hook = hooks[recent.marks];
|
|
58
|
+
return () => hook(resource);
|
|
59
|
+
};
|
|
51
60
|
//#endregion
|
|
52
|
-
export { recentRecords, recentRequest, recentRowDiffers };
|
|
61
|
+
export { recentMarks, recentRecords, recentRequest, recentRowDiffers };
|
|
@@ -2,7 +2,7 @@ import { ProjectUi } from "./project-ui.js";
|
|
|
2
2
|
//#region src/app/pages/merge-ui.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* One UI config from several, each after the ones it `extends`, the last being the app's own: components, action
|
|
5
|
-
* handlers, field types, drop rules, board drops
|
|
5
|
+
* handlers, field types, drop rules, board drops, title rules and marks hooks are all kept, and one name defined by two configs is an error naming both; every shell slot
|
|
6
6
|
* and `beforeSignIn` component is drawn, the extended configs' first, except the logo and the bell, the last config's to set one.
|
|
7
7
|
*/
|
|
8
8
|
export declare const mergeUi: (...uis: ProjectUi[]) => ProjectUi;
|
|
@@ -35,7 +35,7 @@ const around = (wrappers) => {
|
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
37
|
* One UI config from several, each after the ones it `extends`, the last being the app's own: components, action
|
|
38
|
-
* handlers, field types, drop rules, board drops
|
|
38
|
+
* handlers, field types, drop rules, board drops, title rules and marks hooks are all kept, and one name defined by two configs is an error naming both; every shell slot
|
|
39
39
|
* and `beforeSignIn` component is drawn, the extended configs' first, except the logo and the bell, the last config's to set one.
|
|
40
40
|
*/
|
|
41
41
|
const mergeUi = (...uis) => {
|
|
@@ -46,6 +46,7 @@ const mergeUi = (...uis) => {
|
|
|
46
46
|
const dropRules = union("The drop rule", named, (ui) => ui.dropRules);
|
|
47
47
|
const boardDrops = union("The board drop", named, (ui) => ui.boardDrops);
|
|
48
48
|
const titles = union("The title rule", named, (ui) => ui.titles);
|
|
49
|
+
const marks = union("The marks hook", named, (ui) => ui.marks);
|
|
49
50
|
const actionSlot = slot(named.flatMap(({ ui }) => ui.shell?.actions ? [ui.shell.actions] : []));
|
|
50
51
|
const rightPanel = slot(named.flatMap(({ ui }) => ui.shell?.rightPanel ? [ui.shell.rightPanel] : []));
|
|
51
52
|
const logo = named.findLast(({ ui }) => ui.shell?.logo)?.ui.shell?.logo;
|
|
@@ -60,6 +61,7 @@ const mergeUi = (...uis) => {
|
|
|
60
61
|
...Object.keys(dropRules).length > 0 && { dropRules },
|
|
61
62
|
...Object.keys(boardDrops).length > 0 && { boardDrops },
|
|
62
63
|
...Object.keys(titles).length > 0 && { titles },
|
|
64
|
+
...Object.keys(marks).length > 0 && { marks },
|
|
63
65
|
...(actionSlot || rightPanel || logo || bell) && { shell: {
|
|
64
66
|
...actionSlot && { actions: actionSlot },
|
|
65
67
|
...rightPanel && { rightPanel },
|
|
@@ -3,6 +3,7 @@ import { FieldWidget } from "../field-types/field-widget.js";
|
|
|
3
3
|
import { BoardDrop } from "../displays/board-drop.js";
|
|
4
4
|
import { DropRule } from "../hand-order/drop-rule.js";
|
|
5
5
|
import { TitleRule } from "../titles/title-rule.js";
|
|
6
|
+
import { MarksHook } from "../marks/marks-hook.js";
|
|
6
7
|
import { ComponentType, ReactNode } from "react";
|
|
7
8
|
import { Client } from "@protobase/client";
|
|
8
9
|
import { AppAddress } from "@protobase/schema";
|
|
@@ -47,7 +48,7 @@ export type BeforeSignInProps = {
|
|
|
47
48
|
* The project's own React code for composed pages: custom components by the name their layout declares
|
|
48
49
|
* (`component('UsageChart')`) or a widget part names, handlers for named actions that have no built-in behaviour,
|
|
49
50
|
* field types by the name a view's `.widget(name)` chooses, drop rules by the name a list's `drag.rule` gives, board
|
|
50
|
-
* drops by the name a list's `drag.board` gives, title rules by the name a view's `.titleFrom` gives, and the shell's slots. `extends` lists UI configs merged in before it (see `mergeUi`), or whole `protobase.ui.tsx` modules
|
|
51
|
+
* drops by the name a list's `drag.board` gives, title rules by the name a view's `.titleFrom` gives, marks hooks by the name a view's `nav.recent.marks` gives, and the shell's slots. `extends` lists UI configs merged in before it (see `mergeUi`), or whole `protobase.ui.tsx` modules
|
|
51
52
|
* (`import * as tasksUi from '...'`), their exported components included; `name` names it in their errors.
|
|
52
53
|
*/
|
|
53
54
|
export type ProjectUi = {
|
|
@@ -63,6 +64,8 @@ export type ProjectUi = {
|
|
|
63
64
|
boardDrops?: Record<string, BoardDrop>;
|
|
64
65
|
/** A record's title for the person reading it, by the name a view's `.titleFrom` gives (see `TitleRule`). */
|
|
65
66
|
titles?: Record<string, TitleRule>;
|
|
67
|
+
/** How the sidebar marks a resource's records for the person reading, by the name a view's `nav.recent.marks` gives (see `MarksHook`). */
|
|
68
|
+
marks?: Record<string, MarksHook>;
|
|
66
69
|
/**
|
|
67
70
|
* Rendered in the shell on every page: `actions` at the end of the top bar, `rightPanel` beside the page, `logo`
|
|
68
71
|
* at the top of the sidebar in place of Protobase's (see `ShellLogoProps`), and `bell` in the top bar in place of the
|
|
@@ -5,10 +5,13 @@ import { useEffect, useRef, useState } from "react";
|
|
|
5
5
|
import { isApiError } from "@protobase/client";
|
|
6
6
|
//#region src/app/use-live-save.ts
|
|
7
7
|
const savedForMs = 2e3;
|
|
8
|
+
/** What a save's action resolves to when it wrote nothing and needs no word, such as a create that opens the record it repeats. */
|
|
9
|
+
const nothingSaved = Symbol("nothing saved");
|
|
8
10
|
/**
|
|
9
11
|
* Shows the outcome of a save the way the view asks: a toast (spinner, then check) or the state of
|
|
10
|
-
* the Save button. API errors are reported and not rethrown; anything else propagates.
|
|
11
|
-
* save went through
|
|
12
|
+
* the Save button. API errors are reported and not rethrown; anything else propagates. An action that resolves to
|
|
13
|
+
* `nothingSaved` wrote nothing and says nothing: its toast goes away. `run` resolves to whether the save went through
|
|
14
|
+
* or wrote nothing.
|
|
12
15
|
*/
|
|
13
16
|
const useLiveSave = (mode, subject) => {
|
|
14
17
|
const toast = useToast();
|
|
@@ -24,7 +27,11 @@ const useLiveSave = (mode, subject) => {
|
|
|
24
27
|
setMessage(void 0);
|
|
25
28
|
if (mode === "button") setPhase("saving");
|
|
26
29
|
try {
|
|
27
|
-
await action()
|
|
30
|
+
if (await action() === nothingSaved) {
|
|
31
|
+
if (id !== void 0) toast.dismiss(id);
|
|
32
|
+
if (mode === "button") setPhase("idle");
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
28
35
|
if (id !== void 0) toast.update(id, {
|
|
29
36
|
state: "success",
|
|
30
37
|
title: text("subjectSaved", subject)
|
|
@@ -57,4 +64,4 @@ const useLiveSave = (mode, subject) => {
|
|
|
57
64
|
};
|
|
58
65
|
};
|
|
59
66
|
//#endregion
|
|
60
|
-
export { useLiveSave };
|
|
67
|
+
export { nothingSaved, useLiveSave };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { keys } from "../data/query-keys.js";
|
|
2
2
|
import { useClient } from "../data/api-provider.js";
|
|
3
|
+
import { useProjectUi } from "./pages/project-ui.js";
|
|
3
4
|
import { useRecordTitle } from "./titles/record-titles.js";
|
|
4
5
|
import { userMenuResources } from "./user-menu-from-meta.js";
|
|
5
|
-
import { recentRecords, recentRequest, recentRowDiffers } from "./nav-recent.js";
|
|
6
|
+
import { recentMarks, recentRecords, recentRequest, recentRowDiffers } from "./nav-recent.js";
|
|
6
7
|
import { useEffect, useMemo } from "react";
|
|
7
8
|
import { useQueries, useQueryClient } from "@tanstack/react-query";
|
|
8
9
|
//#region src/app/use-nav-recent.ts
|
|
@@ -31,11 +32,12 @@ const useFollowRecords = (groups) => {
|
|
|
31
32
|
/**
|
|
32
33
|
* The records of every sidebar group (`nav.recent`), one list request each, under the `list` query key so that any
|
|
33
34
|
* write to the resource refreshes them, as does reading one of their records anew. The server applies the caller's
|
|
34
|
-
* access, as on the list page.
|
|
35
|
+
* access, as on the list page. A group that names `marks` gets the project UI's hook, which the sidebar calls.
|
|
35
36
|
*/
|
|
36
37
|
const useNavRecent = (meta, basePath, active) => {
|
|
37
38
|
const client = useClient();
|
|
38
39
|
const titleOf = useRecordTitle();
|
|
40
|
+
const { marks } = useProjectUi();
|
|
39
41
|
const groups = useMemo(() => {
|
|
40
42
|
const inMenu = userMenuResources(meta);
|
|
41
43
|
return Object.values(meta.views).flatMap((view) => {
|
|
@@ -45,23 +47,25 @@ const useNavRecent = (meta, basePath, active) => {
|
|
|
45
47
|
model,
|
|
46
48
|
view,
|
|
47
49
|
recent,
|
|
48
|
-
request: recentRequest(model, view, recent)
|
|
50
|
+
request: recentRequest(model, view, recent),
|
|
51
|
+
useMarks: recentMarks(model.name, recent, marks)
|
|
49
52
|
}] : [];
|
|
50
53
|
});
|
|
51
|
-
}, [meta]);
|
|
54
|
+
}, [meta, marks]);
|
|
52
55
|
useFollowRecords(groups);
|
|
53
56
|
const results = useQueries({ queries: groups.map((group) => ({
|
|
54
57
|
queryKey: groupKey(group),
|
|
55
58
|
queryFn: () => client.list(group.model.name, group.request)
|
|
56
59
|
})) });
|
|
57
|
-
return Object.fromEntries(groups.map(({ model, view, recent }, index) => {
|
|
60
|
+
return Object.fromEntries(groups.map(({ model, view, recent, useMarks }, index) => {
|
|
58
61
|
const result = results[index];
|
|
59
62
|
if (result.isPending) return [model.name, { state: "loading" }];
|
|
60
63
|
if (result.isError) return [model.name, { state: "error" }];
|
|
61
64
|
const activeKey = active.resource === model.name ? active.key : void 0;
|
|
62
65
|
return [model.name, {
|
|
63
66
|
state: "ready",
|
|
64
|
-
records: recentRecords(model, view, recent, result.data.items, basePath, activeKey, titleOf)
|
|
67
|
+
records: recentRecords(model, view, recent, result.data.items, basePath, activeKey, titleOf),
|
|
68
|
+
...useMarks && { useMarks }
|
|
65
69
|
}];
|
|
66
70
|
}));
|
|
67
71
|
};
|
package/dist/app-shell/nav.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
import "lucide-react";
|
|
2
|
-
import "@protobase/schema";
|
|
2
|
+
import "@protobase/schema";
|
|
3
|
+
//#region src/app-shell/nav.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* How a record under a sidebar entry stands out for the person reading, such as an unread conversation: `strong` draws
|
|
6
|
+
* its title bold, `count` a badge at the end of its row (none at 0), and `label`, such as "3 mentions", is added to its
|
|
7
|
+
* name for screen readers and its tooltip.
|
|
8
|
+
*/
|
|
9
|
+
export type RecordMark = {
|
|
10
|
+
strong?: boolean;
|
|
11
|
+
count?: number;
|
|
12
|
+
label?: string;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/app-shell/record-marks.ts
|
|
2
|
+
const markRecords = (records, marks) => records.map((record) => {
|
|
3
|
+
const mark = marks && Object.hasOwn(marks, record.id) ? marks[record.id] : void 0;
|
|
4
|
+
return mark ? {
|
|
5
|
+
...record,
|
|
6
|
+
mark
|
|
7
|
+
} : record;
|
|
8
|
+
});
|
|
9
|
+
/** What a sidebar record is called for screen readers and in its tooltip: its title, with its status and its mark's label. */
|
|
10
|
+
const recordNames = (record) => {
|
|
11
|
+
const extra = [record.status?.label, record.mark?.label].filter((part) => part !== void 0 && part !== "");
|
|
12
|
+
return {
|
|
13
|
+
ariaLabel: [record.label, ...extra].join(", "),
|
|
14
|
+
title: extra.length === 0 ? record.label : `${record.label} (${extra.join(", ")})`
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { markRecords, recordNames };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { cn } from "../lib/cn.js";
|
|
2
|
+
import { subRow, subRowIndent } from "./sidebar-rows.js";
|
|
3
|
+
import { Plus } from "lucide-react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/app-shell/sidebar-create-link.tsx
|
|
6
|
+
/** The link under a sidebar entry to its resource's create form, such as "New message", lined up with its records. */
|
|
7
|
+
const SidebarCreateLink = ({ create, mode, onNavigate }) => /* @__PURE__ */ jsx("div", {
|
|
8
|
+
className: cn("border-l border-transparent pl-1.5", subRowIndent[mode]),
|
|
9
|
+
children: /* @__PURE__ */ jsxs("a", {
|
|
10
|
+
href: create.href,
|
|
11
|
+
onClick: onNavigate && ((event) => {
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
onNavigate(create.href);
|
|
14
|
+
}),
|
|
15
|
+
className: cn("flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground", subRow[mode]),
|
|
16
|
+
children: [/* @__PURE__ */ jsx(Plus, {
|
|
17
|
+
"aria-hidden": true,
|
|
18
|
+
className: "size-3.5 shrink-0"
|
|
19
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
20
|
+
className: "truncate",
|
|
21
|
+
children: create.label
|
|
22
|
+
})]
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
//#endregion
|
|
26
|
+
export { SidebarCreateLink };
|
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
import { cn } from "../lib/cn.js";
|
|
2
2
|
import { text } from "./messages.js";
|
|
3
|
+
import { subRow, subRowIndent } from "./sidebar-rows.js";
|
|
3
4
|
import { navOpenStorageKey, readNavOpen, writeNavOpen } from "./nav-open-storage.js";
|
|
4
5
|
import { SidebarItem } from "./sidebar-item.js";
|
|
5
|
-
import {
|
|
6
|
+
import { SidebarRecords } from "./sidebar-records.js";
|
|
6
7
|
import { useId, useState } from "react";
|
|
7
8
|
import { ChevronRight } from "lucide-react";
|
|
8
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
10
|
//#region src/app-shell/sidebar-group.tsx
|
|
10
|
-
const row = {
|
|
11
|
-
"text-large": "h-8 gap-2.5 px-2.5",
|
|
12
|
-
"text-small": "h-7 gap-2 px-2 text-body"
|
|
13
|
-
};
|
|
14
|
-
/** Lines the records up under the entry's icon. */
|
|
15
|
-
const indent = {
|
|
16
|
-
"text-large": "ml-[20px]",
|
|
17
|
-
"text-small": "ml-[17px]"
|
|
18
|
-
};
|
|
19
11
|
/**
|
|
20
|
-
* A sidebar entry with a few of its records under it
|
|
21
|
-
* records (remembered in this browser), and "View all" at the end opens
|
|
12
|
+
* A sidebar entry with a few of its records under it, each marked for the reader when the group has marks. The label
|
|
13
|
+
* opens the list, the chevron shows or hides the records (remembered in this browser), and "View all" at the end opens
|
|
14
|
+
* the list too.
|
|
22
15
|
*/
|
|
23
16
|
const SidebarGroup = ({ item, recent, mode, active, onNavigate }) => {
|
|
24
17
|
const storageKey = navOpenStorageKey(item.id);
|
|
@@ -58,33 +51,25 @@ const SidebarGroup = ({ item, recent, mode, active, onNavigate }) => {
|
|
|
58
51
|
}), open && /* @__PURE__ */ jsxs("ul", {
|
|
59
52
|
id: listId,
|
|
60
53
|
"aria-label": text("recent", item.label.toLowerCase()),
|
|
61
|
-
className: cn("flex flex-col gap-0.5 border-l pl-1.5",
|
|
54
|
+
className: cn("flex flex-col gap-0.5 border-l pl-1.5", subRowIndent[mode]),
|
|
62
55
|
children: [
|
|
63
56
|
recent.state === "loading" && /* @__PURE__ */ jsx("li", {
|
|
64
|
-
className: cn("flex items-center text-faint-foreground",
|
|
57
|
+
className: cn("flex items-center text-faint-foreground", subRow[mode]),
|
|
65
58
|
children: text("loading")
|
|
66
59
|
}),
|
|
67
60
|
recent.state === "error" && /* @__PURE__ */ jsx("li", {
|
|
68
|
-
className: cn("flex items-center text-faint-foreground",
|
|
61
|
+
className: cn("flex items-center text-faint-foreground", subRow[mode]),
|
|
69
62
|
children: text("couldNotLoad")
|
|
70
63
|
}),
|
|
71
|
-
recent.state === "ready" &&
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
children: [record.status && /* @__PURE__ */ jsx(StatusDot, {
|
|
78
|
-
tone: record.status.tone,
|
|
79
|
-
pulse: record.status.pulse
|
|
80
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
81
|
-
className: "truncate",
|
|
82
|
-
children: record.label
|
|
83
|
-
})]
|
|
84
|
-
}) }, record.id)),
|
|
64
|
+
recent.state === "ready" && /* @__PURE__ */ jsx(SidebarRecords, {
|
|
65
|
+
records: recent.records,
|
|
66
|
+
useMarks: recent.useMarks,
|
|
67
|
+
mode,
|
|
68
|
+
onNavigate
|
|
69
|
+
}),
|
|
85
70
|
/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("a", {
|
|
86
71
|
...link(href),
|
|
87
|
-
className: cn("flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground",
|
|
72
|
+
className: cn("flex items-center rounded-md text-faint-foreground transition-colors hover:bg-muted hover:text-foreground", subRow[mode]),
|
|
88
73
|
children: text("viewAll")
|
|
89
74
|
}) })
|
|
90
75
|
]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { cn } from "../lib/cn.js";
|
|
2
|
+
import { subRow } from "./sidebar-rows.js";
|
|
3
|
+
import { CountBadge } from "../primitives/count-badge.js";
|
|
4
|
+
import { markRecords, recordNames } from "./record-marks.js";
|
|
5
|
+
import { StatusDot } from "./status-dot.js";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
//#region src/app-shell/sidebar-records.tsx
|
|
8
|
+
const RecordRows = ({ records, mode, onNavigate }) => records.map((record) => {
|
|
9
|
+
const { ariaLabel, title } = recordNames(record);
|
|
10
|
+
const open = onNavigate && ((event) => {
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
onNavigate(record.href);
|
|
13
|
+
});
|
|
14
|
+
const strong = record.mark?.strong === true;
|
|
15
|
+
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("a", {
|
|
16
|
+
href: record.href,
|
|
17
|
+
onClick: open,
|
|
18
|
+
"aria-label": ariaLabel,
|
|
19
|
+
title,
|
|
20
|
+
"aria-current": record.active ? "page" : void 0,
|
|
21
|
+
className: cn("flex min-w-0 items-center rounded-md transition-colors", subRow[mode], strong ? "font-bold" : "font-medium", record.active || strong ? "text-foreground" : "text-muted-foreground", record.active ? "bg-muted" : "hover:bg-muted hover:text-foreground"),
|
|
22
|
+
children: [
|
|
23
|
+
record.status && /* @__PURE__ */ jsx(StatusDot, {
|
|
24
|
+
tone: record.status.tone,
|
|
25
|
+
pulse: record.status.pulse
|
|
26
|
+
}),
|
|
27
|
+
/* @__PURE__ */ jsx("span", {
|
|
28
|
+
className: "truncate",
|
|
29
|
+
children: record.label
|
|
30
|
+
}),
|
|
31
|
+
/* @__PURE__ */ jsx(CountBadge, {
|
|
32
|
+
count: record.mark?.count,
|
|
33
|
+
className: "ml-auto shrink-0"
|
|
34
|
+
})
|
|
35
|
+
]
|
|
36
|
+
}) }, record.id);
|
|
37
|
+
});
|
|
38
|
+
const MarkedRows = ({ records, useMarks, ...rest }) => /* @__PURE__ */ jsx(RecordRows, {
|
|
39
|
+
records: markRecords(records, useMarks()),
|
|
40
|
+
...rest
|
|
41
|
+
});
|
|
42
|
+
/** The rows of a sidebar group's records, marked by the group's `useMarks` hook when it has one. */
|
|
43
|
+
const SidebarRecords = ({ records, useMarks, mode, onNavigate }) => useMarks ? /* @__PURE__ */ jsx(MarkedRows, {
|
|
44
|
+
records,
|
|
45
|
+
useMarks,
|
|
46
|
+
mode,
|
|
47
|
+
onNavigate
|
|
48
|
+
}) : /* @__PURE__ */ jsx(RecordRows, {
|
|
49
|
+
records,
|
|
50
|
+
mode,
|
|
51
|
+
onNavigate
|
|
52
|
+
});
|
|
53
|
+
//#endregion
|
|
54
|
+
export { SidebarRecords };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/app-shell/sidebar-rows.ts
|
|
2
|
+
/** The height and spacing of a row under a sidebar entry, such as a recent record or its create link. */
|
|
3
|
+
const subRow = {
|
|
4
|
+
"text-large": "h-8 gap-2.5 px-2.5",
|
|
5
|
+
"text-small": "h-7 gap-2 px-2 text-body"
|
|
6
|
+
};
|
|
7
|
+
/** Lines the rows under an entry up under the entry's icon. */
|
|
8
|
+
const subRowIndent = {
|
|
9
|
+
"text-large": "ml-[20px]",
|
|
10
|
+
"text-small": "ml-[17px]"
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { subRow, subRowIndent };
|
|
@@ -5,11 +5,13 @@ import { Logo } from "./logo.js";
|
|
|
5
5
|
import { navGroups } from "./nav.js";
|
|
6
6
|
import { ThemeSwitch } from "./theme-switch.js";
|
|
7
7
|
import { ProfileMenu } from "./profile-menu.js";
|
|
8
|
+
import { SidebarCreateLink } from "./sidebar-create-link.js";
|
|
8
9
|
import { isTextMode, sidebarWidth } from "./sidebar-mode.js";
|
|
9
10
|
import { SidebarItem } from "./sidebar-item.js";
|
|
10
11
|
import { SidebarGroup } from "./sidebar-group.js";
|
|
12
|
+
import { Fragment } from "react";
|
|
11
13
|
import { LogIn } from "lucide-react";
|
|
12
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
13
15
|
//#region src/app-shell/sidebar.tsx
|
|
14
16
|
const Sidebar = ({ mode, activeItem, user, workspace, appName, appIcon, forceExpanded, profileMenuOpen, groups = navGroups, userMenu, account, onNavigate, onSignOut, signIn, organizations, roles, theme, sticky, logo: SidebarLogo = Logo, notice }) => {
|
|
15
17
|
const expanding = mode === "icon-expand";
|
|
@@ -37,18 +39,22 @@ const Sidebar = ({ mode, activeItem, user, workspace, appName, appIcon, forceExp
|
|
|
37
39
|
children: [inline ? group.label && /* @__PURE__ */ jsx("div", {
|
|
38
40
|
className: cn("px-3 pb-1 pt-1 text-xs font-medium uppercase tracking-wide text-faint-foreground", expanding && "h-4 whitespace-nowrap py-0 opacity-0 transition-opacity group-hover/side:opacity-100 group-focus-within/side:opacity-100", expanded && "opacity-100"),
|
|
39
41
|
children: group.label
|
|
40
|
-
}) : index > 0 && /* @__PURE__ */ jsx("div", { className: "mx-auto mb-1 h-px w-6 bg-border" }), group.items.map((item) => item.recent && isTextMode(mode) ? /* @__PURE__ */ jsx(SidebarGroup, {
|
|
42
|
+
}) : index > 0 && /* @__PURE__ */ jsx("div", { className: "mx-auto mb-1 h-px w-6 bg-border" }), group.items.map((item) => /* @__PURE__ */ jsxs(Fragment, { children: [item.recent && isTextMode(mode) ? /* @__PURE__ */ jsx(SidebarGroup, {
|
|
41
43
|
item,
|
|
42
44
|
recent: item.recent,
|
|
43
45
|
mode,
|
|
44
46
|
active: item.id === activeItem,
|
|
45
47
|
onNavigate
|
|
46
|
-
}
|
|
48
|
+
}) : /* @__PURE__ */ jsx(SidebarItem, {
|
|
47
49
|
item,
|
|
48
50
|
mode,
|
|
49
51
|
active: item.id === activeItem,
|
|
50
52
|
onNavigate
|
|
51
|
-
}, item.
|
|
53
|
+
}), item.create && isTextMode(mode) && /* @__PURE__ */ jsx(SidebarCreateLink, {
|
|
54
|
+
create: item.create,
|
|
55
|
+
mode,
|
|
56
|
+
onNavigate
|
|
57
|
+
})] }, item.id))]
|
|
52
58
|
}, group.label))
|
|
53
59
|
}),
|
|
54
60
|
notice,
|
|
@@ -65,7 +71,7 @@ const Sidebar = ({ mode, activeItem, user, workspace, appName, appIcon, forceExp
|
|
|
65
71
|
organizations,
|
|
66
72
|
roles,
|
|
67
73
|
theme
|
|
68
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [theme && inline && /* @__PURE__ */ jsx(ThemeSwitch, {
|
|
74
|
+
}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [theme && inline && /* @__PURE__ */ jsx(ThemeSwitch, {
|
|
69
75
|
theme,
|
|
70
76
|
className: "flex min-h-11 w-full items-center gap-2.5 whitespace-nowrap p-1.5 text-muted-foreground md:min-h-0"
|
|
71
77
|
}), signIn && /* @__PURE__ */ jsxs(RouteLink, {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "./auth-provider.js";
|
|
2
|
+
//#region src/auth/use-signed-in-user.d.ts
|
|
3
|
+
/** Who is signed in: their user id, the id `.author()` stores and mentions hold, and their name. */
|
|
4
|
+
export type SignedInUser = {
|
|
5
|
+
id: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The signed-in person, from the session the app already holds, such as for a filter on their own user id;
|
|
10
|
+
* `undefined` while the session loads, for a visitor and when nobody is signed in.
|
|
11
|
+
*/
|
|
12
|
+
export declare const useSignedInUser: () => SignedInUser | undefined;
|
|
13
|
+
//#endregion
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useOptionalAuth } from "./auth-provider.js";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
//#region src/auth/use-signed-in-user.ts
|
|
4
|
+
/** The signed-in person of an auth state; none while it loads, for a visitor, and before the sign-in finished. */
|
|
5
|
+
const signedInUserOf = (state) => {
|
|
6
|
+
if (state?.kind !== "signed-in") return;
|
|
7
|
+
const { id, name } = state.user;
|
|
8
|
+
return {
|
|
9
|
+
id,
|
|
10
|
+
...name && { name }
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The signed-in person, from the session the app already holds, such as for a filter on their own user id;
|
|
15
|
+
* `undefined` while the session loads, for a visitor and when nobody is signed in.
|
|
16
|
+
*/
|
|
17
|
+
const useSignedInUser = () => {
|
|
18
|
+
const state = useOptionalAuth()?.state;
|
|
19
|
+
return useMemo(() => signedInUserOf(state), [state]);
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { signedInUserOf, useSignedInUser };
|
|
@@ -12,11 +12,17 @@ export type ChatThreadProps = {
|
|
|
12
12
|
loadingEarlier?: boolean;
|
|
13
13
|
/** Changes when the reader sends a message, such as a count of their sends: each change goes to the end wherever they were, and the message that arrives next follows. */
|
|
14
14
|
followKey?: string | number;
|
|
15
|
+
/**
|
|
16
|
+
* Called while the page shows and the reader is at the end of the thread: when it opens or a message arrives there,
|
|
17
|
+
* when they scroll to the end, and when the page shows again with them there. Moves a read position, for one.
|
|
18
|
+
*/
|
|
19
|
+
onReadToEnd?: () => void;
|
|
15
20
|
};
|
|
16
21
|
/**
|
|
17
|
-
* The scrolling list of a chat's messages.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
22
|
+
* The scrolling list of a chat's messages. It opens on its `ChatDivider tone="new"` line when it has one, else at the
|
|
23
|
+
* end. A reader at the end follows new messages; one who scrolled back stays where they are until `followKey` changes,
|
|
24
|
+
* and earlier messages loaded above keep them on the message they were reading. It scrolls inside itself, not with the
|
|
25
|
+
* page, since a chat keeps its composer in view beneath it.
|
|
20
26
|
*/
|
|
21
|
-
export declare const ChatThread: ({ children, empty, length, onLoadEarlier, loadingEarlier, followKey }: ChatThreadProps) => import("react").JSX.Element;
|
|
27
|
+
export declare const ChatThread: ({ children, empty, length, onLoadEarlier, loadingEarlier, followKey, onReadToEnd }: ChatThreadProps) => import("react").JSX.Element;
|
|
22
28
|
//#endregion
|