@edenapp/solid-kit 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,97 @@
2
2
 
3
3
  High-level SolidJS UI utilities for Eden renderer apps.
4
4
 
5
+ ## Sidebars
6
+
7
+ `@edenapp/solid-kit/sidebar` wraps EdenCSS sidebar classes with Solid components.
8
+ EdenCSS supplies the styles; the components manage folding, accessible controls,
9
+ and navigation markup. Eden apps already receive the stylesheet automatically.
10
+
11
+ ```tsx
12
+ import { Sidebar, SidebarItem, SidebarSection } from "@edenapp/solid-kit/sidebar";
13
+ import { FiHome } from "solid-icons/fi";
14
+
15
+ <Sidebar
16
+ label="Navigation"
17
+ heading="Places"
18
+ size="compact"
19
+ toggleLabels={{ collapse: "Collapse sidebar", expand: "Expand sidebar" }}
20
+ >
21
+ <SidebarSection>
22
+ <SidebarItem
23
+ icon={<FiHome />}
24
+ label="Home"
25
+ selected={currentPage() === "home"}
26
+ aria-current={currentPage() === "home" ? "page" : undefined}
27
+ onClick={() => setCurrentPage("home")}
28
+ />
29
+ </SidebarSection>
30
+ </Sidebar>
31
+ ```
32
+
33
+ Pass localized labels from your app. Items retain their accessible names and
34
+ tooltips when folded. `SidebarSection` accepts an optional `title`;
35
+ `SidebarDivider` separates sections. `SidebarItem` supports `description`,
36
+ `disabled`, and an optional `action` containing a `SidebarItemAction`. Action
37
+ buttons show an ellipsis when expanded and a corner dot when folded; supply
38
+ their accessible label and click handler in the app.
39
+
40
+ Use the optional `footer` slot for activity or controls that should stay visible
41
+ while the navigation list scrolls. It inherits the sidebar's folded styling.
42
+
43
+ Sidebars automatically fold at viewport widths of 760px or less until the user
44
+ toggles them. A deliberate choice lasts for the component's lifetime, including
45
+ window resizes. Set `collapseBelow={0}` to disable the responsive default or
46
+ `defaultCollapsed` to choose an initial state. For app-managed state, pass
47
+ `collapsed` and `onCollapsedChange`. Sizes are `default` (280px), `compact`
48
+ (240px), and `wide` (320px); all fold to a 72px icon rail. Standard DOM attributes,
49
+ event handlers, `class`, and `classList` remain available.
50
+
51
+ ## Operation progress
52
+
53
+ Create an observer in your component, submit work through `run`, and render its
54
+ pending state and snapshots. `run` returns the typed completion result; thrown
55
+ failures can be displayed by your app's error UI. It stops observing when the
56
+ component is disposed while accepted work continues in Eden.
57
+
58
+ ```tsx
59
+ import { fs } from "@edenapp/client";
60
+ import { createOperation, OperationStatus } from "@edenapp/solid-kit";
61
+ import { Show } from "solid-js";
62
+
63
+ function CopyButton() {
64
+ const copy = createOperation();
65
+ const startCopy = async () => {
66
+ try {
67
+ await copy.run(() => fs.cp(
68
+ { volume: "home", path: "/report.pdf" },
69
+ { volume: "home", path: "/backup/report.pdf" },
70
+ ));
71
+ } catch (error) {
72
+ // Display the error in the app's UI.
73
+ }
74
+ };
75
+ return <>
76
+ <button class="eden-btn" disabled={copy.pending()} onClick={startCopy}>
77
+ Copy report
78
+ </button>
79
+ <Show when={copy.pending()}>
80
+ <OperationStatus label="Copying report…" snapshot={copy.snapshot()} />
81
+ </Show>
82
+ </>;
83
+ }
84
+ ```
85
+
86
+ `OperationStatus` uses EdenCSS and shows a percentage when progress includes a
87
+ positive total, or a spinner otherwise. Pass a localized `description` to show
88
+ the current stage or formatted quantities. Progress reports contain raw numbers
89
+ and units so apps can format transferred bytes as KB, MB, GB, or TB.
90
+
91
+ For cancellable operations (`snapshot().cancellable`), call `cancel()` to request
92
+ a stop. `run()` remains pending until cleanup finishes, then rejects with an
93
+ `AbortError` when cancelled. Filesystem copies remove incomplete destinations and
94
+ restore overwritten files before reaching the `cancelled` status.
95
+
5
96
  ## Dialogs
6
97
 
7
98
  `@edenapp/solid-kit/dialogs` provides local, in-renderer dialogs with a tiny promise API.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edenapp/solid-kit",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "High-level SolidJS UI primitives for Eden apps",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -15,6 +15,11 @@
15
15
  "types": "./src/dialogs.ts",
16
16
  "import": "./src/dialogs.ts",
17
17
  "default": "./src/dialogs.ts"
18
+ },
19
+ "./sidebar": {
20
+ "types": "./src/sidebar.tsx",
21
+ "import": "./src/sidebar.tsx",
22
+ "default": "./src/sidebar.tsx"
18
23
  }
19
24
  },
20
25
  "files": [
@@ -24,11 +29,12 @@
24
29
  "solid-js": "^1.9.14"
25
30
  },
26
31
  "dependencies": {
27
- "solid-icons": "^1.2.0"
32
+ "solid-icons": "^1.2.0",
33
+ "@edenapp/client": "0.15.0"
28
34
  },
29
35
  "devDependencies": {
30
36
  "typescript": "^6.0.3",
31
- "@edenapp/types": "0.13.0"
37
+ "@edenapp/types": "0.15.0"
32
38
  },
33
39
  "keywords": [
34
40
  "eden",
@@ -0,0 +1,67 @@
1
+ import type { OperationSnapshot } from "@edenapp/types";
2
+ import { Show } from "solid-js";
3
+
4
+ export function OperationStatus(props: {
5
+ label: string;
6
+ description?: string;
7
+ snapshot?: OperationSnapshot;
8
+ }) {
9
+ const active = () =>
10
+ !props.snapshot ||
11
+ props.snapshot.status === "queued" ||
12
+ props.snapshot.status === "running";
13
+ const percentage = () => {
14
+ const progress = props.snapshot?.progress;
15
+ if (!progress?.total || progress.total <= 0) return undefined;
16
+ return Math.max(
17
+ 0,
18
+ Math.min(
19
+ props.snapshot?.status === "succeeded" ? 100 : 99,
20
+ Math.floor((progress.completed / progress.total) * 100),
21
+ ),
22
+ );
23
+ };
24
+ return (
25
+ <div
26
+ class="eden-flex-col eden-gap-sm"
27
+ role="status"
28
+ aria-live="polite"
29
+ aria-busy={active()}
30
+ >
31
+ <div class="eden-flex eden-items-center eden-gap-sm">
32
+ <Show when={active() && percentage() === undefined}>
33
+ <span class="eden-spinner eden-spinner-sm" aria-hidden="true" />
34
+ </Show>
35
+ <strong>{props.label}</strong>
36
+ <Show when={percentage() !== undefined}>
37
+ <span class="eden-text-sm eden-text-secondary">{percentage()}%</span>
38
+ </Show>
39
+ </div>
40
+ <Show when={props.description}>
41
+ <span class="eden-text-sm eden-text-secondary">
42
+ {props.description}
43
+ </span>
44
+ </Show>
45
+ <Show when={percentage() !== undefined}>
46
+ <div
47
+ class="eden-progress"
48
+ role="progressbar"
49
+ aria-label={props.label}
50
+ aria-valuemin={0}
51
+ aria-valuemax={100}
52
+ aria-valuenow={percentage()}
53
+ >
54
+ <div
55
+ class="eden-progress-bar"
56
+ classList={{
57
+ "eden-progress-bar-success":
58
+ props.snapshot?.status === "succeeded",
59
+ "eden-progress-bar-danger": props.snapshot?.status === "failed",
60
+ }}
61
+ style={{ width: `${percentage()}%` }}
62
+ />
63
+ </div>
64
+ </Show>
65
+ </div>
66
+ );
67
+ }
@@ -101,7 +101,7 @@ export const DialogHost: Component<DialogHostProps> = (props) => {
101
101
 
102
102
  if (e.key === "Enter" && current.onEnter === "submit") {
103
103
  const target = e.target as HTMLElement | null;
104
- if (target?.tagName === "TEXTAREA") {
104
+ if (target?.tagName === "TEXTAREA" || target?.closest("summary")) {
105
105
  return;
106
106
  }
107
107
 
package/src/index.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export * from "./dialogs.js";
2
2
  export * from "./KeyboardButton.js";
3
+ export * from "./OperationStatus.js";
4
+ export * from "./operation.js";
3
5
  export * from "./overlayLayout.js";
6
+ export * from "./sidebar.js";
@@ -0,0 +1,90 @@
1
+ import type {
2
+ Operation,
3
+ OperationCompletion,
4
+ OperationSnapshot,
5
+ } from "@edenapp/types";
6
+ import { createSignal, onCleanup } from "solid-js";
7
+
8
+ /** Observe an operation from submission through completion within a Solid owner. */
9
+ export function createOperation() {
10
+ const [pending, setPending] = createSignal(false);
11
+ const [snapshot, setSnapshot] = createSignal<OperationSnapshot>();
12
+ let disposed = false;
13
+ let submission: Promise<Operation> | undefined;
14
+ let stop: (() => void) | undefined;
15
+ let endObservation: (() => void) | undefined;
16
+
17
+ onCleanup(() => {
18
+ disposed = true;
19
+ stop?.();
20
+ endObservation?.();
21
+ });
22
+
23
+ const run = async <C extends string>(
24
+ submit: () => Promise<Operation<C>>,
25
+ ): Promise<OperationCompletion<C>> => {
26
+ if (disposed) throw new Error("Operation owner has been disposed");
27
+ if (pending()) throw new Error("An operation is already in progress");
28
+ setPending(true);
29
+ setSnapshot(undefined);
30
+ try {
31
+ submission = submit();
32
+ const operation = (await submission) as Operation<C>;
33
+ if (disposed) throw new Error("Operation owner has been disposed");
34
+ let finish!: (
35
+ snapshot?: OperationSnapshot<C, OperationCompletion<C>>,
36
+ ) => void;
37
+ const completion = new Promise<
38
+ OperationSnapshot<C, OperationCompletion<C>> | undefined
39
+ >((resolve) => {
40
+ finish = resolve;
41
+ });
42
+ // Resolve on disposal so no listener or suspended observer outlives its UI.
43
+ endObservation = () => finish();
44
+ const unsubscribe = await operation.watch((update) => {
45
+ if (disposed) return;
46
+ setSnapshot(update);
47
+ if (
48
+ update.status === "succeeded" ||
49
+ update.status === "failed" ||
50
+ update.status === "cancelled"
51
+ )
52
+ finish(update);
53
+ });
54
+ stop = unsubscribe;
55
+ if (disposed) {
56
+ unsubscribe();
57
+ throw new Error("Operation owner has been disposed");
58
+ }
59
+ const result = await completion;
60
+ if (result?.status === "succeeded") return result.result;
61
+ if (result?.status === "cancelled") {
62
+ const error = new Error("Operation cancelled");
63
+ error.name = "AbortError";
64
+ throw error;
65
+ }
66
+ if (result?.status === "failed") {
67
+ if ("response" in result)
68
+ return result.response as OperationCompletion<C>;
69
+ const error = new Error(result.error.message);
70
+ error.name = result.error.name;
71
+ throw error;
72
+ }
73
+ throw new Error("Operation owner has been disposed");
74
+ } finally {
75
+ stop?.();
76
+ stop = undefined;
77
+ endObservation = undefined;
78
+ submission = undefined;
79
+ setPending(false);
80
+ }
81
+ };
82
+
83
+ const cancel = async () => {
84
+ if (!submission) return;
85
+ const operation = await submission;
86
+ await operation.cancel();
87
+ };
88
+
89
+ return { run, pending, snapshot, cancel };
90
+ }
@@ -1,3 +1,4 @@
1
+ import * as eden from "@edenapp/client";
1
2
  import type { ViewBounds, WindowSize } from "@edenapp/types";
2
3
  import {
3
4
  type Accessor,
@@ -56,8 +57,8 @@ export function createInterfaceScale(): Accessor<number> {
56
57
  }
57
58
  };
58
59
 
59
- void window.edenAPI
60
- .shellCommand("view/get-interface-scale", {})
60
+ void eden.view
61
+ .getInterfaceScale()
61
62
  .then((result) => {
62
63
  if (Number.isFinite(result.scale)) {
63
64
  setScale(result.scale);
@@ -67,17 +68,14 @@ export function createInterfaceScale(): Accessor<number> {
67
68
  console.error("Failed to load interface scale:", error);
68
69
  });
69
70
 
70
- void window.edenAPI
71
- .subscribe("view/interface-scale-changed", handleScaleChanged)
71
+ void eden.view
72
+ .subscribe("interface-scale-changed", handleScaleChanged)
72
73
  .catch((error) => {
73
74
  console.error("Failed to subscribe to interface scale changes:", error);
74
75
  });
75
76
 
76
77
  onCleanup(() => {
77
- window.edenAPI.unsubscribe(
78
- "view/interface-scale-changed",
79
- handleScaleChanged,
80
- );
78
+ eden.view.unsubscribe("interface-scale-changed", handleScaleChanged);
81
79
  });
82
80
  });
83
81
 
@@ -122,11 +120,9 @@ export function createOverlayLayout(
122
120
  }
123
121
 
124
122
  lastBounds = bounds;
125
- void window.edenAPI
126
- .shellCommand("view/update-bounds", { bounds })
127
- .catch((error) => {
128
- console.error("Failed to update overlay bounds:", error);
129
- });
123
+ void eden.view.updateBounds(bounds).catch((error) => {
124
+ console.error("Failed to update overlay bounds:", error);
125
+ });
130
126
  };
131
127
 
132
128
  const scheduleRefresh = () => {
@@ -173,25 +169,22 @@ export function createOverlayLayout(
173
169
  setWindowSize(data.windowSize);
174
170
  };
175
171
 
176
- void window.edenAPI
177
- .shellCommand("view/window-size", {})
172
+ void eden.view
173
+ .windowSize()
178
174
  .then(setWindowSize)
179
175
  .catch((error) => {
180
176
  console.error("Failed to load window size:", error);
181
177
  setWindowSize(DEFAULT_WINDOW_SIZE);
182
178
  });
183
179
 
184
- void window.edenAPI
185
- .subscribe("view/global-bounds-changed", handleBoundsChanged)
180
+ void eden.view
181
+ .subscribe("global-bounds-changed", handleBoundsChanged)
186
182
  .catch((error) => {
187
183
  console.error("Failed to subscribe to window bounds changes:", error);
188
184
  });
189
185
 
190
186
  onCleanup(() => {
191
- window.edenAPI.unsubscribe(
192
- "view/global-bounds-changed",
193
- handleBoundsChanged,
194
- );
187
+ eden.view.unsubscribe("global-bounds-changed", handleBoundsChanged);
195
188
  if (animationFrame !== null) {
196
189
  window.cancelAnimationFrame(animationFrame);
197
190
  }
@@ -0,0 +1,210 @@
1
+ import { FiChevronLeft, FiMoreHorizontal } from "solid-icons/fi";
2
+ import {
3
+ children,
4
+ createEffect,
5
+ createSignal,
6
+ createUniqueId,
7
+ type JSX,
8
+ onCleanup,
9
+ Show,
10
+ splitProps,
11
+ } from "solid-js";
12
+
13
+ export interface SidebarProps extends JSX.HTMLAttributes<HTMLElement> {
14
+ label: string;
15
+ heading?: JSX.Element;
16
+ footer?: JSX.Element;
17
+ size?: "default" | "compact" | "wide";
18
+ toggleLabels: { collapse: string; expand: string };
19
+ collapsed?: boolean;
20
+ defaultCollapsed?: boolean;
21
+ /** Automatically fold below this viewport width until the user toggles. Set 0 to disable. */
22
+ collapseBelow?: number;
23
+ onCollapsedChange?: (collapsed: boolean) => void;
24
+ }
25
+
26
+ export function Sidebar(props: SidebarProps) {
27
+ const [local, rest] = splitProps(props, [
28
+ "label",
29
+ "heading",
30
+ "footer",
31
+ "size",
32
+ "toggleLabels",
33
+ "collapsed",
34
+ "defaultCollapsed",
35
+ "collapseBelow",
36
+ "onCollapsedChange",
37
+ "children",
38
+ "class",
39
+ "classList",
40
+ ]);
41
+ const [manualCollapsed, setManualCollapsed] = createSignal(
42
+ local.defaultCollapsed,
43
+ );
44
+ const [narrow, setNarrow] = createSignal(false);
45
+ const collapsed = () => local.collapsed ?? manualCollapsed() ?? narrow();
46
+ const contentId = `eden-sidebar-${createUniqueId()}`;
47
+ const footer = children(() => local.footer);
48
+ const toggleLabel = () =>
49
+ collapsed() ? local.toggleLabels.expand : local.toggleLabels.collapse;
50
+
51
+ createEffect(() => {
52
+ const breakpoint = local.collapseBelow ?? 760;
53
+ if (
54
+ breakpoint <= 0 ||
55
+ typeof window === "undefined" ||
56
+ typeof window.matchMedia !== "function"
57
+ ) {
58
+ setNarrow(false);
59
+ return;
60
+ }
61
+ const query = window.matchMedia(`(max-width: ${breakpoint}px)`);
62
+ const update = () => setNarrow(query.matches);
63
+ update();
64
+ query.addEventListener("change", update);
65
+ onCleanup(() => query.removeEventListener("change", update));
66
+ });
67
+
68
+ const toggle = () => {
69
+ const next = !collapsed();
70
+ setManualCollapsed(next);
71
+ local.onCollapsedChange?.(next);
72
+ };
73
+
74
+ return (
75
+ <aside
76
+ {...rest}
77
+ aria-label={local.label}
78
+ class={`eden-sidebar ${local.class ?? ""}`}
79
+ classList={{
80
+ ...local.classList,
81
+ "eden-sidebar-compact": local.size === "compact",
82
+ "eden-sidebar-wide": local.size === "wide",
83
+ "eden-sidebar-collapsed": collapsed(),
84
+ }}
85
+ >
86
+ <div class="eden-sidebar-controls">
87
+ <Show when={local.heading}>
88
+ <span class="eden-sidebar-controls-title">{local.heading}</span>
89
+ </Show>
90
+ <button
91
+ type="button"
92
+ class="eden-btn eden-btn-ghost eden-btn-sm eden-btn-square eden-sidebar-toggle"
93
+ aria-label={toggleLabel()}
94
+ title={toggleLabel()}
95
+ aria-expanded={!collapsed()}
96
+ aria-controls={contentId}
97
+ onClick={toggle}
98
+ >
99
+ <FiChevronLeft aria-hidden="true" />
100
+ </button>
101
+ </div>
102
+ <div id={contentId} class="eden-sidebar-scroll eden-scrollbar">
103
+ {local.children}
104
+ </div>
105
+ <Show when={footer()}>
106
+ <div class="eden-sidebar-footer">{footer()}</div>
107
+ </Show>
108
+ </aside>
109
+ );
110
+ }
111
+
112
+ export function SidebarSection(props: {
113
+ title?: JSX.Element;
114
+ children?: JSX.Element;
115
+ }) {
116
+ return (
117
+ <div class="eden-sidebar-section">
118
+ <Show when={props.title}>
119
+ <div class="eden-sidebar-section-title">{props.title}</div>
120
+ </Show>
121
+ <div class="eden-sidebar-items">{props.children}</div>
122
+ </div>
123
+ );
124
+ }
125
+
126
+ export function SidebarDivider() {
127
+ return <hr class="eden-sidebar-divider" />;
128
+ }
129
+
130
+ export interface SidebarItemProps
131
+ extends Omit<JSX.ButtonHTMLAttributes<HTMLButtonElement>, "children"> {
132
+ label: string;
133
+ icon: JSX.Element;
134
+ description?: string;
135
+ selected?: boolean;
136
+ action?: JSX.Element;
137
+ }
138
+
139
+ export function SidebarItem(props: SidebarItemProps) {
140
+ const [local, rest] = splitProps(props, [
141
+ "label",
142
+ "icon",
143
+ "description",
144
+ "selected",
145
+ "action",
146
+ "class",
147
+ "classList",
148
+ "aria-label",
149
+ "title",
150
+ "disabled",
151
+ ]);
152
+ return (
153
+ <div
154
+ class="eden-sidebar-row"
155
+ classList={{ "eden-sidebar-row-with-action": Boolean(local.action) }}
156
+ >
157
+ <button
158
+ type="button"
159
+ {...rest}
160
+ disabled={local.disabled}
161
+ class={`eden-sidebar-item ${local.class ?? ""}`}
162
+ classList={{
163
+ ...local.classList,
164
+ "eden-sidebar-item-selected": local.selected,
165
+ "eden-sidebar-item-disabled": local.disabled,
166
+ }}
167
+ aria-label={local["aria-label"] ?? local.label}
168
+ title={local.title ?? local.label}
169
+ >
170
+ <span class="eden-sidebar-item-icon" aria-hidden="true">
171
+ {local.icon}
172
+ </span>
173
+ <Show
174
+ when={local.description}
175
+ fallback={<span class="eden-sidebar-item-text">{local.label}</span>}
176
+ >
177
+ <span class="eden-sidebar-item-details">
178
+ <span class="eden-sidebar-item-title">{local.label}</span>
179
+ <span class="eden-sidebar-item-subtitle">{local.description}</span>
180
+ </span>
181
+ </Show>
182
+ </button>
183
+ <Show when={local.action}>
184
+ <div class="eden-sidebar-row-action">{local.action}</div>
185
+ </Show>
186
+ </div>
187
+ );
188
+ }
189
+
190
+ export interface SidebarItemActionProps
191
+ extends JSX.ButtonHTMLAttributes<HTMLButtonElement> {
192
+ "aria-label": string;
193
+ }
194
+
195
+ export function SidebarItemAction(props: SidebarItemActionProps) {
196
+ const [local, rest] = splitProps(props, ["children", "class", "title"]);
197
+ return (
198
+ <button
199
+ type="button"
200
+ {...rest}
201
+ class={`eden-btn eden-btn-ghost eden-btn-sm eden-btn-square eden-sidebar-item-action ${local.class ?? ""}`}
202
+ title={local.title ?? props["aria-label"]}
203
+ >
204
+ <span class="eden-sidebar-item-action-expanded">
205
+ {local.children ?? <FiMoreHorizontal aria-hidden="true" />}
206
+ </span>
207
+ <span class="eden-sidebar-item-action-collapsed" aria-hidden="true" />
208
+ </button>
209
+ );
210
+ }