@noya-app/noya-designsystem 0.1.81 → 0.1.83

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.
@@ -9,15 +9,14 @@ import {
9
9
  PanelGroup,
10
10
  PanelResizeHandle,
11
11
  } from "../resizablePanels";
12
- import { DividerVertical } from "../Divider";
13
12
  import {
14
13
  CONTENT_AREA_ID,
15
14
  EDITOR_PANEL_GROUP_ID,
16
15
  LEFT_SIDEBAR_ID,
17
16
  RIGHT_SIDEBAR_ID,
18
17
  } from "./constants";
18
+ import { HorizontalTabBar } from "./HorizontalTabBar";
19
19
  import { LayoutProps } from "./types";
20
- import { VerticalTabMenu } from "./VerticalTabMenu";
21
20
 
22
21
  export const PanelWorkspaceLayout = memoGeneric(function PanelWorkspaceLayout<
23
22
  LeftTab extends string,
@@ -37,17 +36,21 @@ export const PanelWorkspaceLayout = memoGeneric(function PanelWorkspaceLayout<
37
36
  rightTabValue,
38
37
  onChangeLeftTab,
39
38
  onChangeRightTab,
40
- compactDrawerMenu,
39
+ onLeftSidebarStateChange,
40
+ onRightSidebarStateChange,
41
+ shouldAutoSave = true,
41
42
  }: LayoutProps<LeftTab, RightTab>) {
42
43
  const panelGroupRef = useRef<ImperativePanelGroupHandle>(null);
44
+ const containerRef = useRef<HTMLDivElement>(null);
43
45
 
44
46
  const autoSaveId = useMemo(() => {
47
+ if (!shouldAutoSave) return undefined;
45
48
  return autoSavePrefix
46
- ? `${autoSavePrefix}--v3--${EDITOR_PANEL_GROUP_ID}`
49
+ ? `${autoSavePrefix}--v5--${EDITOR_PANEL_GROUP_ID}`
47
50
  : Math.random().toString(36).substring(2, 15);
48
- }, [autoSavePrefix]);
51
+ }, [autoSavePrefix, shouldAutoSave]);
49
52
 
50
- // Track collapsed state based on layout changes
53
+ // Track collapsed state for rendering purposes (PanelGroup owns the source of truth)
51
54
  const [leftSidebarCollapsed, setLeftSidebarCollapsed] = useState(
52
55
  leftSidebarOptions.defaultCollapsed ?? false
53
56
  );
@@ -55,20 +58,72 @@ export const PanelWorkspaceLayout = memoGeneric(function PanelWorkspaceLayout<
55
58
  rightSidebarOptions.defaultCollapsed ?? false
56
59
  );
57
60
 
61
+ // Track previous sidebar state to avoid redundant callbacks
62
+ const prevLeftSidebarState = useRef<{ width: number; collapsed: boolean } | null>(null);
63
+ const prevRightSidebarState = useRef<{ width: number; collapsed: boolean } | null>(null);
64
+
58
65
  const handleLayoutChange = useCallback(
59
66
  (sizes: number[]) => {
60
67
  // Update collapsed state based on sizes
61
68
  const leftIndex = leftPanel ? 0 : -1;
62
69
  const rightIndex = rightPanel ? (leftPanel ? 2 : 1) : -1;
63
70
 
71
+ // Get container width for pixel calculation using ref
72
+ const containerWidth = containerRef.current?.clientWidth ?? 0;
73
+
74
+ // Detect if sizes are in pixels or percentages by checking if they sum to ~100 or ~containerWidth
75
+ const sizesSum = sizes.reduce((a, b) => a + b, 0);
76
+
77
+ // Skip if sizesSum is too small compared to containerWidth - this indicates incomplete data
78
+ // during initial render (react-resizable-panels may report partial sizes)
79
+ if (containerWidth > 0 && sizesSum < containerWidth * 0.5 && sizesSum > 100) {
80
+ return;
81
+ }
82
+
83
+ const isPixels = containerWidth > 0 && Math.abs(sizesSum - containerWidth) < Math.abs(sizesSum - 100);
84
+
64
85
  if (leftIndex >= 0) {
65
- setLeftSidebarCollapsed(sizes[leftIndex] === 0);
86
+ const collapsed = sizes[leftIndex] === 0;
87
+ setLeftSidebarCollapsed(collapsed);
88
+
89
+ // Calculate width in pixels - handle both percentage (0-100) and pixel formats
90
+ const widthPixels = isPixels
91
+ ? Math.round(sizes[leftIndex])
92
+ : containerWidth > 0
93
+ ? Math.round((sizes[leftIndex] / 100) * containerWidth)
94
+ : 0;
95
+
96
+ // Only call callback if state actually changed
97
+ if (
98
+ prevLeftSidebarState.current?.width !== widthPixels ||
99
+ prevLeftSidebarState.current?.collapsed !== collapsed
100
+ ) {
101
+ prevLeftSidebarState.current = { width: widthPixels, collapsed };
102
+ onLeftSidebarStateChange?.({ width: widthPixels, collapsed });
103
+ }
66
104
  }
67
105
  if (rightIndex >= 0) {
68
- setRightSidebarCollapsed(sizes[rightIndex] === 0);
106
+ const collapsed = sizes[rightIndex] === 0;
107
+ setRightSidebarCollapsed(collapsed);
108
+
109
+ // Calculate width in pixels - handle both percentage (0-100) and pixel formats
110
+ const widthPixels = isPixels
111
+ ? Math.round(sizes[rightIndex])
112
+ : containerWidth > 0
113
+ ? Math.round((sizes[rightIndex] / 100) * containerWidth)
114
+ : 0;
115
+
116
+ // Only call callback if state actually changed
117
+ if (
118
+ prevRightSidebarState.current?.width !== widthPixels ||
119
+ prevRightSidebarState.current?.collapsed !== collapsed
120
+ ) {
121
+ prevRightSidebarState.current = { width: widthPixels, collapsed };
122
+ onRightSidebarStateChange?.({ width: widthPixels, collapsed });
123
+ }
69
124
  }
70
125
  },
71
- [leftPanel, rightPanel]
126
+ [leftPanel, rightPanel, onLeftSidebarStateChange, onRightSidebarStateChange]
72
127
  );
73
128
 
74
129
  const handleLeftTabChange = useCallback(
@@ -107,39 +162,23 @@ export const PanelWorkspaceLayout = memoGeneric(function PanelWorkspaceLayout<
107
162
  [onChangeRightTab, rightSidebarRef, rightTabValue]
108
163
  );
109
164
 
110
- const showLeftTabs =
111
- !!leftSidebarOptions.showTabs &&
112
- !!leftTabItems &&
113
- // When compact drawer UI is enabled, only show the rail when the
114
- // sidebar is collapsed (for large screens/panel layout).
115
- (!compactDrawerMenu || leftSidebarCollapsed);
165
+ const showLeftTabs = !!leftSidebarOptions.showTabs && !!leftTabItems;
116
166
 
117
167
  return (
118
- <PanelGroup
119
- ref={panelGroupRef}
120
- id={EDITOR_PANEL_GROUP_ID}
121
- className="n-flex-1"
122
- direction="horizontal"
123
- autoSaveId={autoSaveId}
124
- onLayout={handleLayoutChange}
125
- >
168
+ <div ref={containerRef} className="n-flex n-flex-1">
169
+ <PanelGroup
170
+ ref={panelGroupRef}
171
+ id={EDITOR_PANEL_GROUP_ID}
172
+ className="n-flex-1"
173
+ direction="horizontal"
174
+ autoSaveId={autoSaveId}
175
+ onLayout={handleLayoutChange}
176
+ >
126
177
  {leftPanel && (
127
178
  <>
128
- {showLeftTabs && (
129
- <VerticalTabMenu
130
- tooltipSide="right"
131
- items={leftTabItems}
132
- activeValue={leftTabValue}
133
- isSidebarCollapsed={leftSidebarCollapsed}
134
- onChange={handleLeftTabChange}
135
- />
136
- )}
137
- {showLeftTabs && !leftSidebarCollapsed && (
138
- <DividerVertical className="n-h-full" />
139
- )}
140
179
  <Panel
141
180
  id={LEFT_SIDEBAR_ID}
142
- className="n-relative"
181
+ className="n-relative n-workspace-sidebar"
143
182
  order={1}
144
183
  ref={leftSidebarRef as React.RefObject<ImperativePanelHandle>}
145
184
  defaultSize={leftSidebarOptions.initialSize}
@@ -153,9 +192,23 @@ export const PanelWorkspaceLayout = memoGeneric(function PanelWorkspaceLayout<
153
192
  collapsible
154
193
  defaultCollapsed={leftSidebarOptions.defaultCollapsed}
155
194
  >
156
- {leftSidebarCollapsed ? null : leftPanel}
195
+ {leftSidebarCollapsed ? null : (
196
+ <div className="n-flex n-flex-col n-h-full">
197
+ {showLeftTabs && (
198
+ <HorizontalTabBar
199
+ items={leftTabItems}
200
+ activeValue={leftTabValue}
201
+ onChange={handleLeftTabChange}
202
+ />
203
+ )}
204
+ <div className="n-flex-1 n-relative n-min-h-0">{leftPanel}</div>
205
+ </div>
206
+ )}
157
207
  </Panel>
158
- <PanelResizeHandle index={0} className="n-cursor-col-resize n-w-px n-h-full n-bg-divider" />
208
+ <PanelResizeHandle
209
+ index={0}
210
+ className={`n-cursor-col-resize n-w-px n-h-full ${leftSidebarCollapsed ? "" : "n-bg-divider"}`}
211
+ />
159
212
  </>
160
213
  )}
161
214
  <Panel
@@ -167,10 +220,13 @@ export const PanelWorkspaceLayout = memoGeneric(function PanelWorkspaceLayout<
167
220
  </Panel>
168
221
  {rightPanel && (
169
222
  <>
170
- <PanelResizeHandle index={1} className="n-cursor-col-resize n-w-px n-h-full n-bg-divider" />
223
+ <PanelResizeHandle
224
+ index={1}
225
+ className={`n-cursor-col-resize n-w-px n-h-full ${rightSidebarCollapsed ? "" : "n-bg-divider"}`}
226
+ />
171
227
  <Panel
172
228
  id={RIGHT_SIDEBAR_ID}
173
- className="n-relative"
229
+ className="n-relative n-workspace-sidebar"
174
230
  order={3}
175
231
  ref={rightSidebarRef as React.RefObject<ImperativePanelHandle>}
176
232
  minSize={rightSidebarOptions.minSize}
@@ -184,22 +240,24 @@ export const PanelWorkspaceLayout = memoGeneric(function PanelWorkspaceLayout<
184
240
  collapsible
185
241
  defaultCollapsed={rightSidebarOptions.defaultCollapsed}
186
242
  >
187
- {rightSidebarCollapsed ? null : rightPanel}
243
+ {rightSidebarCollapsed ? null : (
244
+ <div className="n-flex n-flex-col n-h-full">
245
+ {rightSidebarOptions.showTabs && rightTabItems && (
246
+ <HorizontalTabBar
247
+ items={rightTabItems}
248
+ activeValue={rightTabValue}
249
+ onChange={handleRightTabChange}
250
+ />
251
+ )}
252
+ <div className="n-flex-1 n-relative n-min-h-0">
253
+ {rightPanel}
254
+ </div>
255
+ </div>
256
+ )}
188
257
  </Panel>
189
- {rightSidebarOptions.showTabs &&
190
- rightTabItems &&
191
- !rightSidebarCollapsed && <DividerVertical className="n-h-full" />}
192
- {rightSidebarOptions.showTabs && rightTabItems && (
193
- <VerticalTabMenu
194
- tooltipSide="left"
195
- items={rightTabItems}
196
- activeValue={rightTabValue}
197
- isSidebarCollapsed={rightSidebarCollapsed}
198
- onChange={handleRightTabChange}
199
- />
200
- )}
201
258
  </>
202
259
  )}
203
- </PanelGroup>
260
+ </PanelGroup>
261
+ </div>
204
262
  );
205
263
  });
@@ -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 = {
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,3 +1,4 @@
1
+ import { assignRef } from "@noya-app/react-utils";
1
2
  import React from "react";
2
3
 
3
4
  /**
@@ -31,6 +32,43 @@ export function mergePropsWithEventComposition(
31
32
  }
32
33
  }
33
34
 
35
+ // Compose refs so both trigger and child refs get called
36
+ if (triggerProps.ref || childProps.ref) {
37
+ const triggerRef = triggerProps.ref as React.Ref<unknown> | undefined;
38
+ const childRef = childProps.ref as React.Ref<unknown> | undefined;
39
+ if (triggerRef && childRef) {
40
+ mergedProps.ref = (value: unknown) => {
41
+ assignRef(triggerRef as React.ForwardedRef<unknown>, value);
42
+ assignRef(childRef as React.ForwardedRef<unknown>, value);
43
+ };
44
+ } else if (childRef) {
45
+ mergedProps.ref = childRef;
46
+ }
47
+ // If only triggerRef exists, it's already in mergedProps from the spread
48
+ }
49
+
50
+ // Merge style objects (child styles take precedence)
51
+ if (
52
+ typeof triggerProps.style === "object" &&
53
+ triggerProps.style !== null &&
54
+ typeof childProps.style === "object" &&
55
+ childProps.style !== null
56
+ ) {
57
+ mergedProps.style = { ...triggerProps.style, ...childProps.style };
58
+ } else if (childProps.style !== undefined) {
59
+ mergedProps.style = childProps.style;
60
+ }
61
+
62
+ // Merge className strings
63
+ if (triggerProps.className || childProps.className) {
64
+ const classes = [triggerProps.className, childProps.className]
65
+ .filter(Boolean)
66
+ .join(" ");
67
+ if (classes) {
68
+ mergedProps.className = classes;
69
+ }
70
+ }
71
+
34
72
  return mergedProps;
35
73
  }
36
74
 
@@ -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":[]}