@forgeax/app-shell 0.5.0 → 0.7.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
@@ -57,6 +57,9 @@ export function ProductShell() {
57
57
  Generic persisted sizing and pointer-capture handles use the same public entry:
58
58
 
59
59
  ```tsx
60
+ import '@forgeax/app-shell/resize.css';
61
+ import { ResizeHandle, useLocalSize } from '@forgeax/app-shell/react';
62
+
60
63
  const [width, setWidth] = useLocalSize('product.sidebar.width', 280, 180, 640);
61
64
 
62
65
  <aside style={{ width }}>
package/dist/react.d.ts CHANGED
@@ -12,9 +12,13 @@ declare function useLocalSize(key: string, initial: number, min: number, max: nu
12
12
  interface ResizeHandleProps {
13
13
  orientation: 'col' | 'row';
14
14
  onDrag: (delta: number) => void;
15
+ onDragStart?: () => void;
16
+ onDragEnd?: () => void;
17
+ className?: string;
18
+ ariaLabel?: string;
15
19
  title?: string;
16
20
  }
17
- declare function ResizeHandle({ orientation, onDrag, title }: ResizeHandleProps): react.JSX.Element;
21
+ declare function ResizeHandle({ orientation, onDrag, onDragStart, onDragEnd, className, ariaLabel, title, }: ResizeHandleProps): react.JSX.Element;
18
22
 
19
23
  type ShellSlotElement = 'aside' | 'div' | 'main' | 'section';
20
24
  interface ShellSlotProps extends HTMLAttributes<HTMLElement> {
package/dist/react.js CHANGED
@@ -192,49 +192,65 @@ function useLocalSize(key, initial, min, max) {
192
192
  };
193
193
  return [value, setValue];
194
194
  }
195
- function ResizeHandle({ orientation, onDrag, title }) {
195
+ function ResizeHandle({
196
+ orientation,
197
+ onDrag,
198
+ onDragStart,
199
+ onDragEnd,
200
+ className,
201
+ ariaLabel,
202
+ title
203
+ }) {
196
204
  const startRef = useRef(null);
205
+ const onDragEndRef = useRef(onDragEnd);
206
+ onDragEndRef.current = onDragEnd;
197
207
  const resetGlobalDragStyles = () => {
198
208
  document.body.style.cursor = "";
199
209
  document.body.style.userSelect = "";
200
210
  };
201
- useEffect2(() => () => {
202
- if (startRef.current) resetGlobalDragStyles();
203
- }, []);
211
+ const finishDrag = () => {
212
+ if (!startRef.current) return;
213
+ startRef.current = null;
214
+ resetGlobalDragStyles();
215
+ onDragEndRef.current?.();
216
+ };
217
+ useEffect2(() => finishDrag, []);
204
218
  const onPointerDown = (event) => {
219
+ if (startRef.current) return;
205
220
  event.preventDefault();
206
221
  event.currentTarget.setPointerCapture(event.pointerId);
207
- startRef.current = { x: event.clientX, y: event.clientY };
222
+ startRef.current = { pointerId: event.pointerId, x: event.clientX, y: event.clientY };
208
223
  document.body.style.cursor = orientation === "col" ? "col-resize" : "row-resize";
209
224
  document.body.style.userSelect = "none";
225
+ onDragStart?.();
210
226
  };
211
227
  const onPointerMove = (event) => {
212
- if (!startRef.current) return;
228
+ if (!startRef.current || startRef.current.pointerId !== event.pointerId) return;
213
229
  const deltaX = event.clientX - startRef.current.x;
214
230
  const deltaY = event.clientY - startRef.current.y;
215
- startRef.current = { x: event.clientX, y: event.clientY };
231
+ startRef.current = { pointerId: event.pointerId, x: event.clientX, y: event.clientY };
216
232
  onDrag(orientation === "col" ? deltaX : deltaY);
217
233
  };
218
234
  const finish = (event) => {
219
- if (!startRef.current) return;
220
- startRef.current = null;
235
+ if (!startRef.current || startRef.current.pointerId !== event.pointerId) return;
221
236
  try {
222
237
  event.currentTarget.releasePointerCapture(event.pointerId);
223
238
  } catch {
224
239
  }
225
- resetGlobalDragStyles();
240
+ finishDrag();
226
241
  };
227
242
  return /* @__PURE__ */ jsx2(
228
243
  "div",
229
244
  {
230
- className: `resize-handle resize-handle-${orientation}`,
245
+ className: `resize-handle resize-handle-${orientation}${className ? ` ${className}` : ""}`,
231
246
  onPointerDown,
232
247
  onPointerMove,
233
248
  onPointerUp: finish,
234
249
  onPointerCancel: finish,
235
250
  title,
236
251
  role: "separator",
237
- "aria-orientation": orientation === "col" ? "vertical" : "horizontal"
252
+ "aria-orientation": orientation === "col" ? "vertical" : "horizontal",
253
+ "aria-label": ariaLabel
238
254
  }
239
255
  );
240
256
  }
@@ -0,0 +1,47 @@
1
+ .resize-handle {
2
+ flex-shrink: 0;
3
+ position: relative;
4
+ background: transparent;
5
+ z-index: 5;
6
+ }
7
+
8
+ .resize-handle::after {
9
+ content: "";
10
+ position: absolute;
11
+ background: var(--color-border-default);
12
+ transition: background 150ms;
13
+ pointer-events: none;
14
+ }
15
+
16
+ .resize-handle-col {
17
+ width: 4px;
18
+ cursor: col-resize;
19
+ margin: 0 -2px;
20
+ }
21
+
22
+ .resize-handle-col::after {
23
+ top: 0;
24
+ bottom: 0;
25
+ left: 50%;
26
+ width: 1px;
27
+ transform: translateX(-50%);
28
+ }
29
+
30
+ .resize-handle-row {
31
+ height: 4px;
32
+ cursor: row-resize;
33
+ margin: -2px 0;
34
+ }
35
+
36
+ .resize-handle-row::after {
37
+ left: 0;
38
+ right: 0;
39
+ top: 50%;
40
+ height: 1px;
41
+ transform: translateY(-50%);
42
+ }
43
+
44
+ .resize-handle:hover::after,
45
+ .resize-handle:active::after {
46
+ background: var(--color-border-strong);
47
+ }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@forgeax/app-shell",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Generic Dock, Panel, Window, and Slot composition primitives",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
- "sideEffects": false,
7
+ "sideEffects": ["./dist/resize.css"],
8
8
  "files": ["dist"],
9
9
  "main": "./dist/index.js",
10
10
  "types": "./dist/index.d.ts",
@@ -20,12 +20,13 @@
20
20
  "./react": {
21
21
  "types": "./dist/react.d.ts",
22
22
  "import": "./dist/react.js"
23
- }
23
+ },
24
+ "./resize.css": "./dist/resize.css"
24
25
  },
25
26
  "scripts": {
26
27
  "typecheck": "tsc --noEmit",
27
28
  "test": "bun test test",
28
- "build": "tsup src/index.ts src/dock.ts src/react.tsx --format esm --dts --outDir dist",
29
+ "build": "tsup src/index.ts src/dock.ts src/react.tsx --format esm --dts --outDir dist && bun run scripts/copy-resize-css.ts",
29
30
  "check": "bun run typecheck && bun run test && bun run build",
30
31
  "release:preflight": "bun run scripts/release-preflight.ts"
31
32
  },