elysia-rack 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,211 @@
1
+ import {
2
+ Masthead,
3
+ Sidebar
4
+ } from "./index-0dwhzk3j.js";
5
+ import {
6
+ getRackTree
7
+ } from "./index-4wxvmd8a.js";
8
+ import {
9
+ resolveDonateProp
10
+ } from "./index-b8sq8rbd.js";
11
+ import"./index-37x76zdn.js";
12
+
13
+ // src/react/page/Dashboard.tsx
14
+ import { Fragment } from "react";
15
+ import { jsxDEV, Fragment as Fragment2 } from "react/jsx-dev-runtime";
16
+ function itemLabel(r) {
17
+ return r.metadata.pluralLabel ?? r.metadata.label ?? r.metadata.id;
18
+ }
19
+ function toSidebarItem(node, activeId) {
20
+ return {
21
+ id: node.metadata.id,
22
+ label: itemLabel(node),
23
+ icon: node.metadata.icon,
24
+ href: node.path,
25
+ active: node.metadata.id === activeId,
26
+ children: node.children.filter((c) => !c.metadata.hidden).map((c) => toSidebarItem(c, activeId))
27
+ };
28
+ }
29
+ function buildGroupsFromTree(tree, activeId) {
30
+ const byGroup = new Map;
31
+ for (const root of tree) {
32
+ if (root.metadata.hidden)
33
+ continue;
34
+ const name = root.metadata.group ?? "General";
35
+ let group = byGroup.get(name);
36
+ if (!group) {
37
+ group = { name, items: [] };
38
+ byGroup.set(name, group);
39
+ }
40
+ group.items.push(toSidebarItem(root, activeId));
41
+ }
42
+ return [...byGroup.values()].sort((a, b) => a.name.localeCompare(b.name));
43
+ }
44
+ function countNodes(nodes) {
45
+ return nodes.reduce((sum, n) => sum + 1 + countNodes(n.children), 0);
46
+ }
47
+ function operationsLabel(node) {
48
+ const op = node.operations;
49
+ const write = [op.create, op.update, op.replace, op.delete];
50
+ if (!write.some(Boolean))
51
+ return "Read only";
52
+ if (write.every(Boolean))
53
+ return "Full";
54
+ const labels = [];
55
+ if (op.create)
56
+ labels.push("Create");
57
+ if (op.update)
58
+ labels.push("Update");
59
+ if (op.replace)
60
+ labels.push("Replace");
61
+ if (op.delete)
62
+ labels.push("Delete");
63
+ return labels.join(", ");
64
+ }
65
+ function plural(count, word) {
66
+ return `${count} ${word}${count === 1 ? "" : "s"}`;
67
+ }
68
+ function ResourceRow({ node, depth = 0 }) {
69
+ return /* @__PURE__ */ jsxDEV(Fragment2, {
70
+ children: [
71
+ /* @__PURE__ */ jsxDEV("tr", {
72
+ className: "hover:bg-table-row-hover",
73
+ children: [
74
+ /* @__PURE__ */ jsxDEV("td", {
75
+ className: "border-table-border border-t px-3 py-2.5",
76
+ children: /* @__PURE__ */ jsxDEV("a", {
77
+ href: node.path,
78
+ className: "text-link hover:text-link-hover font-medium hover:underline",
79
+ style: depth > 0 ? { paddingLeft: depth * 16 } : undefined,
80
+ children: [
81
+ node.metadata.icon ? /* @__PURE__ */ jsxDEV("span", {
82
+ "aria-hidden": "true",
83
+ className: "mr-1.5",
84
+ children: node.metadata.icon
85
+ }, undefined, false, undefined, this) : null,
86
+ node.metadata.label ?? node.metadata.id
87
+ ]
88
+ }, undefined, true, undefined, this)
89
+ }, undefined, false, undefined, this),
90
+ /* @__PURE__ */ jsxDEV("td", {
91
+ className: "border-table-border text-text-muted border-t px-3 py-2.5 font-mono text-xs",
92
+ children: node.path
93
+ }, undefined, false, undefined, this),
94
+ /* @__PURE__ */ jsxDEV("td", {
95
+ className: "border-table-border text-text-muted border-t px-3 py-2.5 text-xs",
96
+ children: operationsLabel(node)
97
+ }, undefined, false, undefined, this)
98
+ ]
99
+ }, undefined, true, undefined, this),
100
+ node.children.filter((c) => !c.metadata.hidden).map((child) => /* @__PURE__ */ jsxDEV(ResourceRow, {
101
+ node: child,
102
+ depth: depth + 1
103
+ }, child.metadata.id, false, undefined, this))
104
+ ]
105
+ }, undefined, true, undefined, this);
106
+ }
107
+ async function Dashboard(props) {
108
+ const tree = getRackTree().filter((r) => !r.metadata.hidden);
109
+ const groups = buildGroupsFromTree(tree, props.resource);
110
+ const totalResources = countNodes(tree);
111
+ const totalGroups = groups.length;
112
+ const donate = resolveDonateProp(props.donate);
113
+ return /* @__PURE__ */ jsxDEV("div", {
114
+ className: "text-foreground flex min-h-screen flex-col lg:flex-row",
115
+ children: [
116
+ /* @__PURE__ */ jsxDEV(Sidebar, {
117
+ title: props.name ?? "Panel",
118
+ groups
119
+ }, undefined, false, undefined, this),
120
+ /* @__PURE__ */ jsxDEV("main", {
121
+ className: "min-w-0 flex-1",
122
+ children: /* @__PURE__ */ jsxDEV("div", {
123
+ className: "mx-auto w-full max-w-5xl px-4 py-4 sm:px-6",
124
+ children: [
125
+ /* @__PURE__ */ jsxDEV(Masthead, {
126
+ title: props.name ?? "Panel",
127
+ detail: `${plural(totalResources, "resource")} in ${plural(totalGroups, "group")}`
128
+ }, undefined, false, undefined, this),
129
+ /* @__PURE__ */ jsxDEV("div", {
130
+ className: "bg-table border-border overflow-x-auto rounded-lg border",
131
+ children: /* @__PURE__ */ jsxDEV("table", {
132
+ className: "w-full border-collapse text-left text-sm",
133
+ children: [
134
+ /* @__PURE__ */ jsxDEV("thead", {
135
+ children: /* @__PURE__ */ jsxDEV("tr", {
136
+ children: [
137
+ /* @__PURE__ */ jsxDEV("th", {
138
+ className: "border-border text-text-muted border-b px-3 py-2 text-xs font-medium",
139
+ children: "Resource"
140
+ }, undefined, false, undefined, this),
141
+ /* @__PURE__ */ jsxDEV("th", {
142
+ className: "border-border text-text-muted border-b px-3 py-2 text-xs font-medium",
143
+ children: "Path"
144
+ }, undefined, false, undefined, this),
145
+ /* @__PURE__ */ jsxDEV("th", {
146
+ className: "border-border text-text-muted border-b px-3 py-2 text-xs font-medium",
147
+ children: "Operations"
148
+ }, undefined, false, undefined, this)
149
+ ]
150
+ }, undefined, true, undefined, this)
151
+ }, undefined, false, undefined, this),
152
+ /* @__PURE__ */ jsxDEV("tbody", {
153
+ children: groups.length === 0 ? /* @__PURE__ */ jsxDEV("tr", {
154
+ children: /* @__PURE__ */ jsxDEV("td", {
155
+ colSpan: 3,
156
+ className: "text-text-muted px-4 py-10 text-center",
157
+ children: "No resources registered. Call rack() before rendering this page."
158
+ }, undefined, false, undefined, this)
159
+ }, undefined, false, undefined, this) : groups.map((group) => {
160
+ const nodes = tree.filter((r) => (r.metadata.group ?? "General") === group.name);
161
+ return /* @__PURE__ */ jsxDEV(Fragment, {
162
+ children: [
163
+ /* @__PURE__ */ jsxDEV("tr", {
164
+ className: "bg-surface-muted",
165
+ children: /* @__PURE__ */ jsxDEV("th", {
166
+ colSpan: 3,
167
+ className: "border-border text-text-muted border-b px-3 py-1.5 text-left text-xs font-medium",
168
+ children: [
169
+ group.name,
170
+ " ",
171
+ /* @__PURE__ */ jsxDEV("span", {
172
+ className: "text-text-subtle font-normal",
173
+ children: plural(countNodes(nodes), "resource")
174
+ }, undefined, false, undefined, this)
175
+ ]
176
+ }, undefined, true, undefined, this)
177
+ }, undefined, false, undefined, this),
178
+ nodes.map((node) => /* @__PURE__ */ jsxDEV(ResourceRow, {
179
+ node
180
+ }, node.metadata.id, false, undefined, this))
181
+ ]
182
+ }, group.name, true, undefined, this);
183
+ })
184
+ }, undefined, false, undefined, this)
185
+ ]
186
+ }, undefined, true, undefined, this)
187
+ }, undefined, false, undefined, this),
188
+ /* @__PURE__ */ jsxDEV("footer", {
189
+ className: "border-border text-text-muted mt-6 flex flex-wrap items-center justify-between gap-2 border-t pt-3 text-xs",
190
+ children: [
191
+ /* @__PURE__ */ jsxDEV("span", {
192
+ children: "elysia-rack"
193
+ }, undefined, false, undefined, this),
194
+ donate.enabled ? /* @__PURE__ */ jsxDEV("a", {
195
+ href: donate.url,
196
+ target: "_blank",
197
+ rel: "noopener noreferrer",
198
+ className: "hover:text-foreground underline-offset-4 hover:underline",
199
+ children: donate.label
200
+ }, undefined, false, undefined, this) : null
201
+ ]
202
+ }, undefined, true, undefined, this)
203
+ ]
204
+ }, undefined, true, undefined, this)
205
+ }, undefined, false, undefined, this)
206
+ ]
207
+ }, undefined, true, undefined, this);
208
+ }
209
+ export {
210
+ Dashboard as default
211
+ };