bdsa-react-components 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2025-10-30
9
+
10
+ ### Added
11
+ - Initial project setup with TypeScript, Vite, and Vitest
12
+ - Storybook configuration for component documentation
13
+ - Button component with variants (primary, secondary, danger, success)
14
+ - Button component with sizes (small, medium, large)
15
+ - Button component with loading state
16
+ - Card component with header and footer support
17
+ - Card component with configurable shadow and padding
18
+ - Comprehensive test suite for all components
19
+ - Storybook stories for all components
20
+ - ESLint configuration
21
+ - TypeScript type definitions
22
+ - Build system for library distribution
23
+
@@ -0,0 +1,290 @@
1
+ # bdsa-react-components - CURSOR Integration Guide
2
+
3
+ **Version:** 0.1.0 | **Generated:** 2025-11-01T17:13:05.783Z
4
+
5
+ > This document provides everything Cursor needs to integrate and use the bdsa-react-components library.
6
+ > Copy this entire document into your project's .cursorrules or docs folder.
7
+ > **Auto-generated from source code** - Updated automatically on build.
8
+
9
+ ## Quick Start
10
+
11
+ ### Published Package (when available)
12
+
13
+ ```bash
14
+ npm install bdsa-react-components
15
+ ```
16
+
17
+ ### Local Development (npm link)
18
+
19
+ If the library is local/unpublished, use npm link:
20
+
21
+ **Step 1:** In the library directory (`bdsaReactComponents`):
22
+ ```bash
23
+ npm link
24
+ ```
25
+
26
+ **Step 2:** In your project directory:
27
+ ```bash
28
+ npm link bdsa-react-components
29
+ ```
30
+
31
+ **Step 3:** Install peer dependencies in your project (if not already installed):
32
+ ```bash
33
+ npm install react@^18.0.0 react-dom@^18.0.0
34
+ ```
35
+
36
+ **Note:** After making changes to the library, rebuild it:
37
+ ```bash
38
+ # In library directory
39
+ npm run build
40
+ ```
41
+
42
+ ### Import
43
+
44
+ ```tsx
45
+ import { AnnotationManager, Button, Card, FolderBrowser, SlideViewer } from 'bdsa-react-components'
46
+ import 'bdsa-react-components/styles.css'
47
+ ```
48
+
49
+ ## Components API
50
+
51
+ ### AnnotationManager
52
+
53
+ AnnotationManager component
54
+
55
+ **Example:**
56
+
57
+ ```tsx
58
+ <AnnotationManager
59
+ imageId="6903df8dd26a6d93de19a9b2"
60
+ apiBaseUrl="http://bdsa.pathology.emory.edu:8080/api/v1"
61
+ onAnnotationsLoaded={(anns) => console.log(anns)}
62
+ />
63
+ ```
64
+
65
+ **API Endpoints:**
66
+
67
+ - `GET /annotation?itemId={id}&limit={limit}&offset=0` - Search annotations by itemId
68
+
69
+ ### Button
70
+
71
+ A versatile button component for the BDSA project
72
+
73
+ **Extends:** `React.ButtonHTMLAttributes<HTMLButtonElement>`
74
+
75
+ **Props:**
76
+
77
+ | Prop | Type | Default | Required | Description |
78
+ |------|------|---------|----------|-------------|
79
+ | `variant` | `'primary' \| 'secondary' \| 'danger' \| 'success'` | `'primary'` | No | The variant style of the button |
80
+ | `size` | `'small' \| 'medium' \| 'large'` | `'medium'` | No | The size of the button |
81
+ | `fullWidth` | `boolean` | `false` | No | Whether the button should take the full width of its container |
82
+ | `loading` | `boolean` | `false` | No | Whether the button is in a loading state |
83
+
84
+ ### Card
85
+
86
+ A flexible card component for the BDSA project
87
+
88
+ **Extends:** `React.HTMLAttributes<HTMLDivElement>`
89
+
90
+ **Props:**
91
+
92
+ | Prop | Type | Default | Required | Description |
93
+ |------|------|---------|----------|-------------|
94
+ | `header` | `React.ReactNode` | `undefined` | No | Optional header content |
95
+ | `footer` | `React.ReactNode` | `undefined` | No | Optional footer content |
96
+ | `shadow` | `'none' \| 'small' \| 'medium' \| 'large'` | `'small'` | No | Whether the card has a shadow |
97
+ | `bordered` | `boolean` | `true` | No | Whether the card has a border |
98
+ | `hoverable` | `boolean` | `false` | No | Whether the card is hoverable (shows hover effect) |
99
+ | `padding` | `'none' \| 'small' \| 'medium' \| 'large'` | `'medium'` | No | Padding size |
100
+
101
+ ### FolderBrowser
102
+
103
+ FolderBrowser component
104
+
105
+ **Example:**
106
+
107
+ ```tsx
108
+ <FolderBrowser
109
+ apiBaseUrl="http://bdsa.pathology.emory.edu:8080/api/v1"
110
+ onResourceSelect={(resource) => console.log(resource)}
111
+ />
112
+ ```
113
+
114
+ **API Endpoints:**
115
+
116
+ - `GET /collection` - List collections
117
+ - `GET /folder?parentType={type}&parentId={id}` - List folders
118
+
119
+ ### SlideViewer
120
+
121
+ A slide viewer component that integrates OpenSeadragon with Paper.js annotations for viewing Digital Slide Archive images with annotation overlays.
122
+
123
+ **Example:**
124
+
125
+ ```tsx
126
+ <SlideViewer
127
+ imageInfo={{
128
+ dziUrl: 'http://bdsa.pathology.emory.edu:8080/api/v1/item/IMAGE_ID/tiles/dzi.dzi'
129
+ }}
130
+ annotations={[]}
131
+ height="800px"
132
+ />
133
+ ```
134
+
135
+ **API Endpoints:**
136
+
137
+ - `GET /annotation/{id}` - Fetch annotation document by ID
138
+
139
+ ## Type Definitions
140
+
141
+ Import types:
142
+
143
+ ```tsx
144
+ import type {
145
+ ButtonProps,
146
+ CardProps,
147
+ SlideViewerProps,
148
+ SlideImageInfo,
149
+ AnnotationFeature,
150
+ AnnotationInfoConfig,
151
+ AnnotationInfoProperty,
152
+ AnnotationManagerProps,
153
+ AnnotationSearchResult,
154
+ FolderBrowserProps,
155
+ Collection,
156
+ Folder,
157
+ Resource,
158
+ } from 'bdsa-react-components'
159
+ ```
160
+
161
+ ### Key Types
162
+
163
+ **SlideImageInfo:**
164
+ ```typescript
165
+ interface SlideImageInfo {
166
+ imageId?: string | number
167
+ width?: number
168
+ height?: number
169
+ tileWidth?: number
170
+ levels?: number
171
+ baseUrl?: string
172
+ http: //bdsa.pathology.emory.edu:8080/api/v1/item/{itemId
173
+ }
174
+ ```
175
+
176
+ ## Authentication
177
+
178
+ Components making API calls (`SlideViewer`, `AnnotationManager`, `FolderBrowser`) support auth via:
179
+
180
+ 1. **`fetchFn` prop:** Custom fetch function `(url: string, options?: RequestInit) => Promise<Response>`
181
+ 2. **`apiHeaders` prop:** Headers object `HeadersInit`
182
+
183
+ **Example:**
184
+
185
+ ```tsx
186
+ const fetchWithAuth = async (url: string, options?: RequestInit) => {
187
+ return fetch(url, {
188
+ ...options,
189
+ headers: {
190
+ ...options?.headers,
191
+ 'Authorization': `Bearer ${token}`,
192
+ },
193
+ })
194
+ }
195
+
196
+ <SlideViewer
197
+ imageInfo={{ dziUrl: '...' }}
198
+ fetchFn={fetchWithAuth}
199
+ // OR: apiHeaders={{ 'Authorization': `Bearer ${token}` }}
200
+ />
201
+ ```
202
+
203
+ ## Common Integration Patterns
204
+
205
+ ### 1. SlideViewer with Manual Annotations
206
+
207
+ ```tsx
208
+ <SlideViewer
209
+ imageInfo={{
210
+ dziUrl: 'http://bdsa.pathology.emory.edu:8080/api/v1/item/IMAGE_ID/tiles/dzi.dzi'
211
+ }}
212
+ annotations={[
213
+ { id: 'ann-1', left: 100, top: 200, width: 150, height: 100, color: '#ff0000' }
214
+ ]}
215
+ height="800px"
216
+ onAnnotationClick={(ann) => console.log(ann)}
217
+ />
218
+ ```
219
+
220
+ ### 2. SlideViewer with API-Fetched Annotations
221
+
222
+ ```tsx
223
+ const [annotationIds, setAnnotationIds] = useState<string[]>([])
224
+ const imageId = '6903df8dd26a6d93de19a9b2'
225
+
226
+ <>
227
+ <AnnotationManager
228
+ imageId={imageId}
229
+ apiBaseUrl="http://bdsa.pathology.emory.edu:8080/api/v1"
230
+ onAnnotationsLoaded={(anns) => setAnnotationIds(anns.map(a => a._id))}
231
+ />
232
+ <SlideViewer
233
+ imageInfo={{ dziUrl: `.../item/${imageId}/tiles/dzi.dzi` }}
234
+ annotationIds={annotationIds}
235
+ apiBaseUrl="http://bdsa.pathology.emory.edu:8080/api/v1"
236
+ height="800px"
237
+ />
238
+ </>
239
+ ```
240
+
241
+ ### 3. FolderBrowser
242
+
243
+ ```tsx
244
+ <FolderBrowser
245
+ apiBaseUrl="http://bdsa.pathology.emory.edu:8080/api/v1"
246
+ showCollections={true}
247
+ onResourceSelect={(resource) => console.log(resource)}
248
+ foldersPerPage={50}
249
+ />
250
+ ```
251
+
252
+ ## Important Notes
253
+
254
+ - **SlideViewer height:** Must specify explicit `height` prop (e.g., `"600px"`, `"100vh"`) - OpenSeadragon requirement
255
+ - **DZI URL vs Manual:** Provide either `dziUrl` OR all manual fields (`imageId`, `width`, `height`, `tileWidth`, `levels`, `baseUrl`)
256
+ - **Annotations format:** Accepts `AnnotationFeature[]` or GeoJSON `FeatureCollection`
257
+ - **API Base URL:** Format: `http://bdsa.pathology.emory.edu:8080/api/v1` (no trailing slash)
258
+ - **Styles:** Always import `'bdsa-react-components/styles.css'`
259
+ - **Peer deps:** Requires React 18+
260
+
261
+ ## Troubleshooting (npm link)
262
+
263
+ **"Module not found" error:**
264
+ - Ensure `npm link` was run in the library directory
265
+ - Ensure `npm link bdsa-react-components` was run in your project
266
+ - Check that `node_modules/bdsa-react-components` is a symlink (not a regular folder)
267
+ - Try removing and re-linking: `npm unlink bdsa-react-components && npm link bdsa-react-components`
268
+
269
+ **Styles not loading:**
270
+ - Ensure you've imported `'bdsa-react-components/styles.css'`
271
+ - Check that the CSS file exists at `node_modules/bdsa-react-components/dist/style.css`
272
+
273
+ **Changes not appearing:**
274
+ - Rebuild the library: `cd /path/to/bdsaReactComponents && npm run build`
275
+ - Restart your dev server (Vite/CRA/etc) after rebuilding
276
+ - For faster iteration, run `npm run build -- --watch` in the library directory
277
+
278
+ **TypeScript errors:**
279
+ - Ensure `dist/index.d.ts` exists in the library
280
+ - Restart TypeScript server in your editor (VS Code: Cmd+Shift+P → "TypeScript: Restart TS Server")
281
+
282
+ ## Dependencies
283
+
284
+ **Peer:** react ^18.0.0, react-dom ^18.0.0
285
+
286
+ **Direct:** openseadragon ^5.0.1, osd-paperjs-annotation, paper ^0.12.18
287
+
288
+ ---
289
+
290
+ _Auto-generated from source code - Regenerate with: npm run generate:cursor-doc_
package/INTEGRATION.md ADDED
@@ -0,0 +1,189 @@
1
+ # Integration Guide for bdsa-react-components
2
+
3
+ ## Local Development Setup (Using npm link)
4
+
5
+ ### Step 1: Link the library in this repository
6
+
7
+ From the `bdsaReactComponents` directory:
8
+
9
+ ```bash
10
+ npm link
11
+ ```
12
+
13
+ This creates a global symlink to your library.
14
+
15
+ ### Step 2: Use it in your other React application
16
+
17
+ In your other React application directory:
18
+
19
+ ```bash
20
+ npm link bdsa-react-components
21
+ ```
22
+
23
+ This creates a symlink from your app's `node_modules` to the library.
24
+
25
+ ### Step 3: Install peer dependencies in your app
26
+
27
+ Your app needs React 18+:
28
+
29
+ ```bash
30
+ npm install react@^18.0.0 react-dom@^18.0.0
31
+ ```
32
+
33
+ ### Step 4: Use the components
34
+
35
+ ```tsx
36
+ import { SlideViewer, Button, Card } from 'bdsa-react-components'
37
+ import 'bdsa-react-components/styles.css'
38
+
39
+ function App() {
40
+ return (
41
+ <div style={{ width: '100%', height: '600px' }}>
42
+ <SlideViewer
43
+ imageInfo={{
44
+ dziUrl: 'http://bdsa.pathology.emory.edu:8080/api/v1/item/YOUR_IMAGE_ID/tiles/dzi.dzi'
45
+ }}
46
+ annotations={[]}
47
+ />
48
+ </div>
49
+ )
50
+ }
51
+ ```
52
+
53
+ ## Alternative: Using GitHub Repository
54
+
55
+ ### Step 1: Push to GitHub
56
+
57
+ ```bash
58
+ git init
59
+ git add .
60
+ git commit -m "Initial commit"
61
+ git remote add origin https://github.com/YOUR_USERNAME/bdsa-react-components.git
62
+ git push -u origin main
63
+ ```
64
+
65
+ ### Step 2: Install from GitHub in your app
66
+
67
+ ```bash
68
+ npm install git+https://github.com/YOUR_USERNAME/bdsa-react-components.git
69
+ ```
70
+
71
+ Or if you want to point to a specific branch:
72
+
73
+ ```bash
74
+ npm install git+https://github.com/YOUR_USERNAME/bdsa-react-components.git#main
75
+ ```
76
+
77
+ ## VSCode IntelliSense Setup
78
+
79
+ The library includes full TypeScript definitions, so VSCode should automatically provide:
80
+ - Autocomplete for component props
81
+ - Type checking
82
+ - Inline documentation
83
+ - Go to definition
84
+
85
+ If IntelliSense isn't working:
86
+
87
+ 1. **Make sure TypeScript is installed** in your project:
88
+ ```bash
89
+ npm install --save-dev typescript @types/react @types/react-dom
90
+ ```
91
+
92
+ 2. **Restart VSCode** or reload the window (Cmd+Shift+P → "Reload Window")
93
+
94
+ 3. **Check VSCode TypeScript version**:
95
+ - Open a `.tsx` file
96
+ - Click the TypeScript version in the bottom right
97
+ - Select "Use Workspace Version"
98
+
99
+ ## Component Usage Examples
100
+
101
+ ### SlideViewer
102
+
103
+ ```tsx
104
+ import { SlideViewer } from 'bdsa-react-components'
105
+ import 'bdsa-react-components/styles.css'
106
+
107
+ function MySlideView() {
108
+ const imageInfo = {
109
+ dziUrl: 'http://bdsa.pathology.emory.edu:8080/api/v1/item/6903df8dd26a6d93de19a9b2/tiles/dzi.dzi'
110
+ }
111
+
112
+ const annotations = [
113
+ {
114
+ id: 'ann-1',
115
+ left: 5000,
116
+ top: 6000,
117
+ width: 2000,
118
+ height: 1500,
119
+ color: '#ff0000',
120
+ label: 'Region of Interest'
121
+ }
122
+ ]
123
+
124
+ return (
125
+ <SlideViewer
126
+ imageInfo={imageInfo}
127
+ annotations={annotations}
128
+ height="800px"
129
+ onAnnotationClick={(annotation) => {
130
+ console.log('Clicked:', annotation)
131
+ }}
132
+ />
133
+ )
134
+ }
135
+ ```
136
+
137
+ ### Button
138
+
139
+ ```tsx
140
+ import { Button } from 'bdsa-react-components'
141
+ import 'bdsa-react-components/styles.css'
142
+
143
+ <Button variant="primary" size="large" onClick={() => alert('Clicked!')}>
144
+ Click Me
145
+ </Button>
146
+ ```
147
+
148
+ ### Card
149
+
150
+ ```tsx
151
+ import { Card } from 'bdsa-react-components'
152
+ import 'bdsa-react-components/styles.css'
153
+
154
+ <Card header="Title" footer="Footer" shadow="medium" hoverable>
155
+ Content here
156
+ </Card>
157
+ ```
158
+
159
+ ## Troubleshooting
160
+
161
+ ### "Module not found" error
162
+
163
+ Make sure you've:
164
+ 1. Run `npm link` in the library directory
165
+ 2. Run `npm link bdsa-react-components` in your app directory
166
+ 3. Installed peer dependencies (`react`, `react-dom`)
167
+
168
+ ### Styles not loading
169
+
170
+ Don't forget to import the CSS:
171
+ ```tsx
172
+ import 'bdsa-react-components/styles.css'
173
+ ```
174
+
175
+ ### OpenSeadragon not working
176
+
177
+ Make sure the SlideViewer has an explicit height:
178
+ ```tsx
179
+ <SlideViewer height="600px" ... />
180
+ ```
181
+
182
+ ## Hot Reloading with npm link
183
+
184
+ If you make changes to the library:
185
+ 1. Rebuild: `npm run build` in the library directory
186
+ 2. Your app should automatically pick up changes (if using Vite/CRA with watch mode)
187
+
188
+ For faster development, you can run `npm run build -- --watch` in one terminal while developing.
189
+