@noya-app/noya-designsystem 0.1.82 → 0.1.84

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.
@@ -25,6 +25,7 @@ import {
25
25
  RenderPanel,
26
26
  SidebarOptions,
27
27
  SidebarRef,
28
+ SidebarState,
28
29
  } from "./types";
29
30
  import { WorkspaceSideProvider } from "./WorkspaceSideContext";
30
31
 
@@ -79,10 +80,19 @@ export interface WorkspaceLayoutProps<
79
80
  sideTypeBreakpoint?: number;
80
81
  detectSize?: DetectSizeType;
81
82
  /**
82
- * Use a compact top-row menu in Drawer (mobile) layout instead of a
83
- * full-height left menu. Useful when there is only a single icon.
83
+ * Callback when left sidebar state changes (width or collapsed).
84
84
  */
85
- compactDrawerMenu?: boolean;
85
+ onLeftSidebarStateChange?: (state: SidebarState) => void;
86
+ /**
87
+ * Callback when right sidebar state changes (width or collapsed).
88
+ */
89
+ onRightSidebarStateChange?: (state: SidebarState) => void;
90
+ /**
91
+ * Whether to persist panel sizes to localStorage.
92
+ * Set to false when using external storage (e.g., cookies) for sidebar state.
93
+ * @default true
94
+ */
95
+ shouldAutoSave?: boolean;
86
96
  }
87
97
 
88
98
  export type WorkspaceLayoutRef = {
@@ -177,7 +187,9 @@ export const WorkspaceLayout = forwardRefGeneric(function WorkspaceLayout<
177
187
  showTabs: rightShowTabs = true,
178
188
  } = {},
179
189
  theme,
180
- compactDrawerMenu,
190
+ onLeftSidebarStateChange,
191
+ onRightSidebarStateChange,
192
+ shouldAutoSave,
181
193
  }: WorkspaceLayoutProps<LeftTab, RightTab>,
182
194
  forwardedRef: React.ForwardedRef<WorkspaceLayoutRef>
183
195
  ) {
@@ -450,7 +462,9 @@ export const WorkspaceLayout = forwardRefGeneric(function WorkspaceLayout<
450
462
  autoSavePrefix={autoSavePrefix}
451
463
  leftSidebarRef={leftSidebarRef}
452
464
  rightSidebarRef={rightSidebarRef}
453
- compactDrawerMenu={compactDrawerMenu}
465
+ onLeftSidebarStateChange={onLeftSidebarStateChange}
466
+ onRightSidebarStateChange={onRightSidebarStateChange}
467
+ shouldAutoSave={shouldAutoSave}
454
468
  />
455
469
  {isOverlay && (
456
470
  <OverlayToolbar
@@ -24,6 +24,11 @@ export type PanelLayoutState = {
24
24
  rightSidebarCollapsed: boolean;
25
25
  };
26
26
 
27
+ export type SidebarState = {
28
+ width: number;
29
+ collapsed: boolean;
30
+ };
31
+
27
32
  export type RenderPanel<TabValue extends string> =
28
33
  | ReactNode
29
34
  | ((props: {
@@ -54,12 +59,19 @@ export type LayoutProps<
54
59
  leftSidebarRef: React.RefObject<SidebarRef | null>;
55
60
  rightSidebarRef: React.RefObject<SidebarRef | null>;
56
61
  /**
57
- * When using the Drawer (mobile) layout, render the vertical tab menu
58
- * in a compact top row whose height equals the toolbar height.
59
- * Intended for scenarios with a single icon to avoid reserving
60
- * full-height left-side space.
62
+ * Callback when left sidebar state changes (width or collapsed).
63
+ */
64
+ onLeftSidebarStateChange?: (state: SidebarState) => void;
65
+ /**
66
+ * Callback when right sidebar state changes (width or collapsed).
67
+ */
68
+ onRightSidebarStateChange?: (state: SidebarState) => void;
69
+ /**
70
+ * Whether to persist panel sizes to localStorage.
71
+ * Set to false when using external storage (e.g., cookies) for sidebar state.
72
+ * @default true
61
73
  */
62
- compactDrawerMenu?: boolean;
74
+ shouldAutoSave?: boolean;
63
75
  };
64
76
 
65
77
  export type WorkspaceLayoutGroup = {
@@ -231,20 +231,27 @@ export const DialogProvider = function DialogProvider({
231
231
  const confirmButtonRef = useRef<HTMLButtonElement>(null);
232
232
  const dialogRef = useRef<IDialog>(null);
233
233
 
234
- // Handle auto-focus when dialog opens
234
+ // Handle auto-focus when dialog opens. The `resolve` function is created
235
+ // once per dialog instance and preserved across state updates (e.g. typing
236
+ // in the input replaces `contents` but keeps the same `resolve`), so keying
237
+ // the effect on it ensures focus is only set when a dialog opens, not on
238
+ // every keystroke.
239
+ const contentsType = contents?.type;
240
+ const contentsInstance = contents?.resolve;
241
+
235
242
  React.useEffect(() => {
236
- if (!contents) return;
243
+ if (!contentsType || !contentsInstance) return;
237
244
 
238
245
  // Use requestAnimationFrame to ensure the dialog is rendered
239
246
  requestAnimationFrame(() => {
240
- if (contents.type === "input") {
247
+ if (contentsType === "input") {
241
248
  inputRef.current?.focus();
242
249
  inputRef.current?.setSelectionRange(0, inputRef.current.value.length);
243
- } else if (contents.type === "confirmation") {
250
+ } else if (contentsType === "confirmation") {
244
251
  confirmButtonRef.current?.focus();
245
252
  }
246
253
  });
247
- }, [contents]);
254
+ }, [contentsType, contentsInstance]);
248
255
 
249
256
  const containsElement = useCallback((element: HTMLElement) => {
250
257
  if (!dialogRef.current) return false;
@@ -0,0 +1,142 @@
1
+ import { afterEach, describe, expect, mock, test } from "bun:test";
2
+ import React from "react";
3
+
4
+ // `@radix-ui/react-icons` has a nested React 18 copy in node_modules, which
5
+ // creates legacy React elements that React 19 refuses to render under
6
+ // `bun test` (app bundlers alias react, so this only affects tests). Mock the
7
+ // icon used by the Dialog close button so everything renders with one React.
8
+ const actualIcons = await import("@radix-ui/react-icons");
9
+
10
+ mock.module("@radix-ui/react-icons", () => ({
11
+ ...actualIcons,
12
+ Cross1Icon: (props: React.SVGProps<SVGSVGElement>) => (
13
+ <svg {...props} data-testid="cross-icon" />
14
+ ),
15
+ }));
16
+
17
+ const { cleanup, fireEvent, render, waitFor } = await import(
18
+ "@testing-library/react"
19
+ );
20
+ const { DialogProvider, useOpenInputDialog } = await import(
21
+ "../DialogContext"
22
+ );
23
+
24
+ const focusListeners: ((event: Event) => void)[] = [];
25
+
26
+ afterEach(() => {
27
+ cleanup();
28
+
29
+ for (const listener of focusListeners) {
30
+ document.removeEventListener("focus", listener, true);
31
+ }
32
+ focusListeners.length = 0;
33
+ });
34
+
35
+ function flushAnimationFrames() {
36
+ return new Promise<void>((resolve) => {
37
+ requestAnimationFrame(() => {
38
+ requestAnimationFrame(() => resolve());
39
+ });
40
+ });
41
+ }
42
+
43
+ function OpenDialogButton({
44
+ onResult,
45
+ }: {
46
+ onResult: (value: string | undefined) => void;
47
+ }) {
48
+ const openInputDialog = useOpenInputDialog();
49
+
50
+ return (
51
+ <button
52
+ onClick={async () => {
53
+ const result = await openInputDialog({
54
+ title: "Rename",
55
+ initialValue: "hello",
56
+ });
57
+ onResult(result);
58
+ }}
59
+ >
60
+ Open
61
+ </button>
62
+ );
63
+ }
64
+
65
+ async function openInputDialogForTest(
66
+ onResult: (value: string | undefined) => void = () => {}
67
+ ) {
68
+ const utils = render(
69
+ <DialogProvider>
70
+ <OpenDialogButton onResult={onResult} />
71
+ </DialogProvider>
72
+ );
73
+
74
+ // Count focus events on the dialog's input, attached before the dialog
75
+ // opens so the initial auto-focus is captured
76
+ let focusCount = 0;
77
+ const handleFocus = (event: Event) => {
78
+ if ((event.target as HTMLElement).tagName === "INPUT") {
79
+ focusCount++;
80
+ }
81
+ };
82
+ document.addEventListener("focus", handleFocus, true);
83
+ focusListeners.push(handleFocus);
84
+
85
+ fireEvent.click(utils.getByText("Open"));
86
+
87
+ const input = await waitFor(() => {
88
+ const element = document.querySelector<HTMLInputElement>(
89
+ 'input[type="text"], input:not([type])'
90
+ );
91
+ if (!element) throw new Error("Input not found");
92
+ return element;
93
+ });
94
+
95
+ await flushAnimationFrames();
96
+
97
+ return { ...utils, input, getFocusCount: () => focusCount };
98
+ }
99
+
100
+ describe("DialogProvider input dialog", () => {
101
+ test("focuses and selects the initial value when opened", async () => {
102
+ const { input, getFocusCount } = await openInputDialogForTest();
103
+
104
+ expect(getFocusCount()).toBeGreaterThanOrEqual(1);
105
+ expect(input.selectionStart).toEqual(0);
106
+ expect(input.selectionEnd).toEqual("hello".length);
107
+ });
108
+
109
+ test("does not re-focus or re-select on keystrokes", async () => {
110
+ const { input, getFocusCount } = await openInputDialogForTest();
111
+
112
+ const focusCountAfterOpen = getFocusCount();
113
+
114
+ fireEvent.change(input, { target: { value: "hello w" } });
115
+
116
+ // Simulate the caret position after typing (collapsed at the end)
117
+ input.setSelectionRange(input.value.length, input.value.length);
118
+
119
+ await flushAnimationFrames();
120
+
121
+ expect(input.value).toEqual("hello w");
122
+ // The focus side effect must not run again on a keystroke
123
+ expect(getFocusCount()).toEqual(focusCountAfterOpen);
124
+ // Selection must not be reset to cover the whole value
125
+ expect(input.selectionStart).toEqual(input.value.length);
126
+ expect(input.selectionEnd).toEqual(input.value.length);
127
+ });
128
+
129
+ test("submits the typed value on Enter", async () => {
130
+ let result: string | undefined;
131
+ const { input } = await openInputDialogForTest((value) => {
132
+ result = value;
133
+ });
134
+
135
+ fireEvent.change(input, { target: { value: "world" } });
136
+ fireEvent.keyDown(input, { key: "Enter" });
137
+
138
+ await waitFor(() => {
139
+ expect(result).toEqual("world");
140
+ });
141
+ });
142
+ });
package/src/index.css CHANGED
@@ -73,7 +73,7 @@
73
73
  --n-toolbar-drawer-shadow: rgba(153, 153, 153, 0.25);
74
74
  --n-canvas-background: var(--n-indigo-25);
75
75
  --n-canvas-grid: rgba(0, 0, 0, 0.05);
76
- --n-sidebar-background: rgb(255, 255, 255);
76
+ --n-sidebar-background: #fdfcff;
77
77
  --n-popover-background: rgb(252, 252, 252);
78
78
  --n-popover-divider: transparent;
79
79
  --n-listview-raised-background: rgba(0, 0, 0, 0.03);
@@ -103,7 +103,7 @@
103
103
  --n-text-link-focused: var(--n-primary-400);
104
104
  --n-inset-top: 46px;
105
105
  --n-sidebar-width: 260px;
106
- --n-toolbar-height: 46px;
106
+ --n-toolbar-height: 52px;
107
107
  --n-toolbar-separator: 8px;
108
108
  --n-inspector-h-separator: 8px;
109
109
  --n-inspector-v-separator: 10px;
@@ -267,6 +267,16 @@
267
267
  --n-cm-info: #3390ff;
268
268
  }
269
269
 
270
+ .n-workspace-sidebar {
271
+ --n-input-background: rgb(242, 240, 247);
272
+ --n-button-background: rgb(242, 240, 247);
273
+ }
274
+
275
+ [data-theme="dark"] .n-workspace-sidebar {
276
+ --n-input-background: rgb(55, 53, 65);
277
+ --n-button-background: rgb(55, 53, 65);
278
+ }
279
+
270
280
  .markdown-editor-line-placeholder::after {
271
281
  content: var(--n-markdown-editor-line-placeholder-content);
272
282
  color: var(--n-text-disabled);
@@ -1,36 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
- var __export = (target, all) => {
11
- for (var name in all)
12
- __defProp(target, name, { get: all[name], enumerable: true });
13
- };
14
- var __copyProps = (to, from, except, desc) => {
15
- if (from && typeof from === "object" || typeof from === "function") {
16
- for (let key of __getOwnPropNames(from))
17
- if (!__hasOwnProp.call(to, key) && key !== except)
18
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
- mod
29
- ));
30
-
31
- export {
32
- __commonJS,
33
- __export,
34
- __toESM
35
- };
36
- //# sourceMappingURL=chunk-D57E6H3M.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,43 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined") return require.apply(this, arguments);
11
- throw Error('Dynamic require of "' + x + '" is not supported');
12
- });
13
- var __commonJS = (cb, mod) => function __require2() {
14
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
- };
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- // If the importer is in node compatibility mode or this is not an ESM
30
- // file that has been converted to a CommonJS file using a Babel-
31
- // compatible transform (i.e. "__esModule" has not been set), then set
32
- // "default" to the CommonJS "module.exports" for node compatibility.
33
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
- mod
35
- ));
36
-
37
- export {
38
- __require,
39
- __commonJS,
40
- __export,
41
- __toESM
42
- };
43
- //# sourceMappingURL=chunk-FJ6ZGZIA.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,37 +0,0 @@
1
- import * as __noya_react__ from "react";const require=(m)=>{if(m==="react")return __noya_react__;throw new Error("Dynamic require not supported: "+m)};
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
-
32
- export {
33
- __commonJS,
34
- __export,
35
- __toESM
36
- };
37
- //# sourceMappingURL=chunk-QDV7OQMJ.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}