@dtducas/wh-forge-viewer 1.0.6 → 1.0.8-beta
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 +253 -26
- package/dist/index.d.ts +24 -2
- package/dist/index.esm.js +256 -94
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +256 -94
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
# wh-forge-viewer
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A professional Autodesk Forge Viewer component for React with advanced PDF support, intelligent navigation, and production-ready architecture.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
+
### Core Features
|
|
7
8
|
- ✅ **Custom Toolbar** - Pre-configured toolbar with Pan, Document Browser, Download, and Pagination controls
|
|
8
|
-
- ✅ **PDF Support** - Optimized for viewing PDF documents with page navigation
|
|
9
|
-
- ✅ **
|
|
10
|
-
- ✅ **
|
|
11
|
-
- ✅ **Self-Healing** - Automatic toolbar recovery mechanism ensures UI persistence
|
|
12
|
-
- ✅ **3D/2D Models** - Full support for Autodesk Forge 3D and 2D models
|
|
9
|
+
- ✅ **Enhanced PDF Support** - Optimized for viewing PDF documents with intelligent page navigation
|
|
10
|
+
- ✅ **Smart Document Browser** - Auto-opens with adaptive panel sizing (single/multi-page)
|
|
11
|
+
- ✅ **3D/2D Models** - Full support for Autodesk Forge 3D and 2D models (DWF, DWFX)
|
|
13
12
|
- ✅ **React Integration** - Easy-to-use React component with hooks support
|
|
14
|
-
|
|
13
|
+
|
|
14
|
+
### Advanced Navigation
|
|
15
|
+
- 🚀 **No-Refresh Navigation** - Document Browser panel doesn't refresh when using pagination buttons
|
|
16
|
+
- 🚀 **Smart Thumbnail Selection** - Auto-select and scroll to current thumbnail
|
|
17
|
+
- 🚀 **Persistent State** - State survives extension unload/reload cycles
|
|
18
|
+
- 🚀 **Synchronized Button States** - Document Browser button always reflects actual panel state
|
|
19
|
+
- 🚀 **Smooth Scrolling** - Auto-scroll thumbnails to center in viewport
|
|
20
|
+
|
|
21
|
+
### Architecture & Quality
|
|
22
|
+
- 🏗️ **SOLID Architecture** - Manager pattern with clear separation of concerns
|
|
23
|
+
- 🏗️ **Type Safety** - Full TypeScript type definitions included
|
|
24
|
+
- 🏗️ **Dependency Injection** - Clean, testable, and maintainable code
|
|
25
|
+
- 🏗️ **Self-Healing Toolbar** - Automatic recovery mechanism ensures UI persistence
|
|
26
|
+
- 🏗️ **Production Ready** - Clean code, no debug logs, optimized performance
|
|
15
27
|
|
|
16
28
|
## Installation
|
|
17
29
|
|
|
@@ -47,47 +59,193 @@ function MyApp() {
|
|
|
47
59
|
|
|
48
60
|
## Custom Toolbar
|
|
49
61
|
|
|
50
|
-
The viewer includes a custom toolbar with:
|
|
62
|
+
The viewer includes a production-ready custom toolbar with two control groups:
|
|
51
63
|
|
|
52
64
|
### Tools Group
|
|
53
65
|
|
|
54
|
-
- **Pan** - Enable pan navigation
|
|
55
|
-
-
|
|
66
|
+
- **Pan Tool** - Enable pan navigation mode
|
|
67
|
+
- Auto-activates on viewer load
|
|
68
|
+
- Synced with Forge Viewer navigation state
|
|
69
|
+
|
|
70
|
+
- **Document Browser** - Toggle document tree/thumbnail view
|
|
71
|
+
- Auto-opens for all documents (single/multi-page)
|
|
72
|
+
- Positioned on right side with custom styling
|
|
73
|
+
- Default tab: Thumbnails view
|
|
74
|
+
- Adaptive panel height based on content
|
|
75
|
+
- State persists across page navigation
|
|
76
|
+
|
|
56
77
|
- **Download** - Download the current document
|
|
78
|
+
- One-click file download
|
|
79
|
+
- Preserves original filename
|
|
57
80
|
|
|
58
81
|
### Pagination Group
|
|
59
82
|
|
|
60
|
-
- **Previous Page** - Navigate to previous page
|
|
61
|
-
- **Page Counter** - Display current
|
|
62
|
-
- **Next Page** - Navigate to next page
|
|
83
|
+
- **Previous Page** ◀ - Navigate to previous page
|
|
84
|
+
- **Page Counter** - Display "current / total" pages (e.g., "3 / 9")
|
|
85
|
+
- **Next Page** ▶ - Navigate to next page
|
|
86
|
+
|
|
87
|
+
**Smart Navigation:**
|
|
88
|
+
- When Document Browser is open: Uses internal API to prevent panel refresh
|
|
89
|
+
- When Document Browser is closed: Uses standard navigation with panel restore
|
|
90
|
+
- Thumbnail selection and scroll automatically sync with current page
|
|
63
91
|
|
|
64
92
|
## Requirements
|
|
65
93
|
|
|
94
|
+
### Peer Dependencies
|
|
66
95
|
- React ^17.0.0 || ^18.0.0
|
|
67
96
|
- Ant Design ^5.0.0
|
|
68
|
-
|
|
97
|
+
|
|
98
|
+
### Browser Support
|
|
99
|
+
- Modern browsers with ES6+ support
|
|
100
|
+
- Chrome 90+, Firefox 88+, Safari 14+, Edge 90+
|
|
101
|
+
|
|
102
|
+
### Autodesk Forge Viewer
|
|
103
|
+
- Uses v7.108.0 (loaded from CDN)
|
|
104
|
+
- Pinned version for production stability
|
|
69
105
|
|
|
70
106
|
## Important Notes
|
|
71
107
|
|
|
72
108
|
### Viewer Versioning
|
|
73
109
|
|
|
74
|
-
This package uses a **specific version** of Autodesk Forge Viewer (v7.108.0) instead of wildcards (7.*) to ensure production stability and avoid unexpected breaking changes.
|
|
110
|
+
This package uses a **specific version** of Autodesk Forge Viewer (v7.108.0) loaded from CDN, instead of wildcards (7.*), to ensure production stability and avoid unexpected breaking changes.
|
|
75
111
|
|
|
76
|
-
**Why
|
|
112
|
+
**Why pinned version?**
|
|
113
|
+
- ✅ Predictable behavior in production
|
|
114
|
+
- ✅ No surprise updates from Autodesk
|
|
115
|
+
- ✅ Tested and verified functionality
|
|
116
|
+
- ✅ Easy to upgrade when ready
|
|
77
117
|
|
|
78
118
|
📖 See [docs/VERSIONING.md](docs/VERSIONING.md) for version update guide.
|
|
79
119
|
|
|
120
|
+
### Known Behaviors
|
|
121
|
+
|
|
122
|
+
**Extension Lifecycle:**
|
|
123
|
+
- Forge Viewer unloads extensions when navigating between pages
|
|
124
|
+
- This package handles this gracefully with GLOBAL_STATE persistence
|
|
125
|
+
- All states (viewables, page index, panel state) are preserved
|
|
126
|
+
|
|
127
|
+
**Document Browser Panel:**
|
|
128
|
+
- Auto-opens for both single and multi-page documents
|
|
129
|
+
- Panel height adapts to content (compact for 1 page, scrollable for many)
|
|
130
|
+
- Positioned on right side by default
|
|
131
|
+
- Uses Thumbnails tab as default view
|
|
132
|
+
|
|
80
133
|
## Architecture
|
|
81
134
|
|
|
82
|
-
This package follows **SOLID principles** and uses a modular architecture:
|
|
135
|
+
This package follows **SOLID principles** and uses a production-ready modular architecture:
|
|
136
|
+
|
|
137
|
+
### Core Components
|
|
83
138
|
|
|
84
|
-
|
|
85
|
-
-
|
|
86
|
-
-
|
|
87
|
-
-
|
|
139
|
+
**Managers** (Business Logic)
|
|
140
|
+
- `PaginationManager` - Handles page navigation, viewables management, and smart Document Browser API integration
|
|
141
|
+
- `ToolbarManager` - Creates and manages custom toolbar buttons and their states
|
|
142
|
+
- `DocumentBrowserManager` - Controls Document Browser panel visibility, styling, and state persistence
|
|
143
|
+
|
|
144
|
+
**Services** (Utilities)
|
|
145
|
+
- `EventBus` - Singleton event bus for decoupled communication between managers
|
|
146
|
+
- `FileLoader` - Loads PDF/DWF/DWFX files into viewer with viewables extraction
|
|
147
|
+
- `DownloadService` - Handles file downloads with proper filename extraction
|
|
148
|
+
|
|
149
|
+
**Extension**
|
|
150
|
+
- `ToolbarExtension` - Main extension that orchestrates all managers and services
|
|
151
|
+
|
|
152
|
+
### Key Features
|
|
153
|
+
|
|
154
|
+
**Global State Persistence**
|
|
155
|
+
- State survives Forge Viewer's extension unload/reload cycles
|
|
156
|
+
- Preserves viewables, current page index, and Document Browser state
|
|
157
|
+
- Seamless navigation without losing context
|
|
158
|
+
|
|
159
|
+
**Smart Navigation**
|
|
160
|
+
- Detects if Document Browser panel is open
|
|
161
|
+
- Uses `_changeModelFn` API when open (no panel refresh)
|
|
162
|
+
- Falls back to `loadDocumentNode` when closed (with state restoration)
|
|
163
|
+
- Automatic thumbnail selection and scroll synchronization
|
|
164
|
+
|
|
165
|
+
**Self-Healing Mechanism**
|
|
166
|
+
- Polls every 8ms to detect missing toolbar groups
|
|
167
|
+
- Automatically recreates toolbar if removed by Forge Viewer
|
|
168
|
+
- Syncs button states with actual panel visibility
|
|
169
|
+
- Ensures UI consistency at all times
|
|
88
170
|
|
|
89
171
|
📖 See [ARCHITECTURE.md](ARCHITECTURE.md) for detailed architecture documentation.
|
|
90
172
|
|
|
173
|
+
## Advanced Usage
|
|
174
|
+
|
|
175
|
+
### Accessing Viewer Instance
|
|
176
|
+
|
|
177
|
+
```jsx
|
|
178
|
+
function MyApp() {
|
|
179
|
+
const [viewer, setViewer] = useState(null);
|
|
180
|
+
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (viewer) {
|
|
183
|
+
// Access viewer API
|
|
184
|
+
console.log('Viewer loaded:', viewer);
|
|
185
|
+
|
|
186
|
+
// Listen to Forge Viewer events
|
|
187
|
+
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, () => {
|
|
188
|
+
console.log('Geometry loaded');
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}, [viewer]);
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<ViewerForgePDF
|
|
195
|
+
filePath="/path/to/document.pdf"
|
|
196
|
+
fileExt="pdf"
|
|
197
|
+
setViewer={setViewer}
|
|
198
|
+
/>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Event Bus Integration
|
|
204
|
+
|
|
205
|
+
The package exposes an EventBus for custom integrations:
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
import { EventBus } from '@dtducas/wh-forge-viewer';
|
|
209
|
+
|
|
210
|
+
const eventBus = EventBus.getInstance();
|
|
211
|
+
|
|
212
|
+
// Listen to page changes
|
|
213
|
+
eventBus.on('page:changed', (data) => {
|
|
214
|
+
console.log('Page changed to:', data.index);
|
|
215
|
+
console.log('From Document Browser:', data.fromDocBrowser);
|
|
216
|
+
console.log('From Pagination:', data.fromPagination);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// Listen to Document Browser events
|
|
220
|
+
eventBus.on('docBrowser:opened', () => {
|
|
221
|
+
console.log('Document Browser opened');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
eventBus.on('docBrowser:closed', () => {
|
|
225
|
+
console.log('Document Browser closed');
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Performance Optimizations
|
|
230
|
+
|
|
231
|
+
### No-Refresh Navigation
|
|
232
|
+
When Document Browser panel is open, pagination uses internal Forge Viewer API (`_changeModelFn`) instead of full page reload. This provides:
|
|
233
|
+
- ⚡ Faster page navigation
|
|
234
|
+
- ✨ No panel refresh/flicker
|
|
235
|
+
- 🎯 Smooth user experience
|
|
236
|
+
- 💾 Memory efficient
|
|
237
|
+
|
|
238
|
+
### Intelligent State Management
|
|
239
|
+
- Global state persists across extension lifecycles
|
|
240
|
+
- Minimal re-renders and DOM updates
|
|
241
|
+
- Efficient event-driven architecture
|
|
242
|
+
- Debounced toolbar healing checks
|
|
243
|
+
|
|
244
|
+
### Adaptive UI
|
|
245
|
+
- Panel height adjusts based on thumbnail count
|
|
246
|
+
- Single page: Compact panel
|
|
247
|
+
- Multi-page: Optimized for scrolling (max 80% viewport)
|
|
248
|
+
|
|
91
249
|
## Development
|
|
92
250
|
|
|
93
251
|
```bash
|
|
@@ -97,7 +255,17 @@ npm install
|
|
|
97
255
|
# Build package
|
|
98
256
|
npm run build
|
|
99
257
|
|
|
100
|
-
# Watch mode
|
|
258
|
+
# Watch mode for development
|
|
259
|
+
npm run dev
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Testing
|
|
263
|
+
|
|
264
|
+
A complete test app is included in `/test/app`:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
cd test/app
|
|
268
|
+
npm install
|
|
101
269
|
npm run dev
|
|
102
270
|
```
|
|
103
271
|
|
|
@@ -106,10 +274,59 @@ npm run dev
|
|
|
106
274
|
The package is automatically published to NPM when you push a version tag:
|
|
107
275
|
|
|
108
276
|
```bash
|
|
109
|
-
|
|
110
|
-
|
|
277
|
+
# Update version in package.json
|
|
278
|
+
npm version patch # or minor, major
|
|
279
|
+
|
|
280
|
+
# Push tag
|
|
281
|
+
git push origin v1.0.x
|
|
111
282
|
```
|
|
112
283
|
|
|
284
|
+
## Troubleshooting
|
|
285
|
+
|
|
286
|
+
### Browser Console Warning: "runtime.lastError"
|
|
287
|
+
|
|
288
|
+
**Error:** `Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.`
|
|
289
|
+
|
|
290
|
+
**Cause:** This comes from browser extensions (React DevTools, Redux DevTools, etc.) trying to inject into your page.
|
|
291
|
+
|
|
292
|
+
**Solution:** This is safe to ignore. It doesn't affect your application. To remove the warning:
|
|
293
|
+
- Disable browser extensions during development, OR
|
|
294
|
+
- Add error boundary to catch extension errors
|
|
295
|
+
|
|
296
|
+
### Document Browser Button Not Syncing
|
|
297
|
+
|
|
298
|
+
If the Document Browser button state doesn't match panel visibility:
|
|
299
|
+
1. Check browser console for errors
|
|
300
|
+
2. Verify Autodesk Forge Viewer version (should be v7.108.0)
|
|
301
|
+
3. Try refreshing the page
|
|
302
|
+
4. The self-healing mechanism should auto-fix within seconds
|
|
303
|
+
|
|
304
|
+
### Pagination Display Not Updating
|
|
305
|
+
|
|
306
|
+
If page numbers don't update after navigation:
|
|
307
|
+
1. Extension includes aggressive update mechanism (10+ retries)
|
|
308
|
+
2. Should auto-correct within 500ms
|
|
309
|
+
3. Check if toolbar group is being removed by other extensions
|
|
310
|
+
|
|
311
|
+
## Changelog
|
|
312
|
+
|
|
313
|
+
### v1.0.7 (Latest)
|
|
314
|
+
- ✨ Smart navigation: Document Browser panel no longer refreshes when using pagination buttons
|
|
315
|
+
- ✨ Auto-scroll thumbnails to center selected page
|
|
316
|
+
- ✨ Adaptive panel height for single vs multi-page documents
|
|
317
|
+
- ✨ Global state persistence across extension reload cycles
|
|
318
|
+
- 🐛 Fixed: Document Browser button state sync after thumbnail navigation
|
|
319
|
+
- 🐛 Fixed: Thumbnail selection not updating when using pagination buttons
|
|
320
|
+
- 🧹 Removed all debug console logs for production
|
|
321
|
+
- 📝 Full code cleanup and optimization
|
|
322
|
+
|
|
323
|
+
### v1.0.5
|
|
324
|
+
- Initial public release
|
|
325
|
+
- Custom toolbar with Pan, Document Browser, Download buttons
|
|
326
|
+
- Pagination controls for multi-page documents
|
|
327
|
+
- Self-healing toolbar mechanism
|
|
328
|
+
- SOLID architecture refactor
|
|
329
|
+
|
|
113
330
|
## License
|
|
114
331
|
|
|
115
332
|
MIT
|
|
@@ -122,6 +339,16 @@ MIT
|
|
|
122
339
|
- GitHub: [@DTDucas](https://github.com/DTDucas)
|
|
123
340
|
- LinkedIn: [dtducas](https://www.linkedin.com/in/dtducas)
|
|
124
341
|
|
|
125
|
-
## Issues
|
|
342
|
+
## Support & Issues
|
|
343
|
+
|
|
344
|
+
- 🐛 [Report bugs](https://github.com/DTDucas/wh-forge-viewer/issues)
|
|
345
|
+
- 💡 [Request features](https://github.com/DTDucas/wh-forge-viewer/issues)
|
|
346
|
+
- 📖 [View documentation](https://github.com/DTDucas/wh-forge-viewer#readme)
|
|
347
|
+
|
|
348
|
+
## Contributing
|
|
349
|
+
|
|
350
|
+
Contributions are welcome! Please read [ARCHITECTURE.md](ARCHITECTURE.md) before submitting PRs.
|
|
351
|
+
|
|
352
|
+
---
|
|
126
353
|
|
|
127
|
-
|
|
354
|
+
Made with ❤️ by [DTDucas](https://github.com/DTDucas)
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,23 @@ declare module '@dtducas/wh-forge-viewer' {
|
|
|
7
7
|
/**
|
|
8
8
|
* Supported file extensions for the Forge Viewer
|
|
9
9
|
*/
|
|
10
|
-
export type TSupportedFileExtension = 'pdf' | 'dwf' | 'dwfx';
|
|
10
|
+
export type TSupportedFileExtension = 'pdf' | 'dwf' | 'dwfx' | 'gltf' | 'glb';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Toolbar visibility options
|
|
14
|
+
*/
|
|
15
|
+
export interface IToolbarOptions {
|
|
16
|
+
/** Show Pan button (default: true) */
|
|
17
|
+
showPan?: boolean;
|
|
18
|
+
/** Show Document Browser button (default: true) */
|
|
19
|
+
showDocBrowser?: boolean;
|
|
20
|
+
/** Show Download button (default: true) */
|
|
21
|
+
showDownload?: boolean;
|
|
22
|
+
/** Show Pagination controls (default: true) */
|
|
23
|
+
showPagination?: boolean;
|
|
24
|
+
/** Master switch - show entire custom toolbar (default: true) */
|
|
25
|
+
showToolbar?: boolean;
|
|
26
|
+
}
|
|
11
27
|
/**
|
|
12
28
|
* Autodesk Forge Viewer namespace
|
|
13
29
|
* For full type definitions, see Autodesk Forge Viewer documentation
|
|
@@ -47,9 +63,14 @@ declare module '@dtducas/wh-forge-viewer' {
|
|
|
47
63
|
*/
|
|
48
64
|
filePath: string;
|
|
49
65
|
/**
|
|
50
|
-
* File extension (pdf, dwf, dwfx)
|
|
66
|
+
* File extension (pdf, dwf, dwfx, gltf, glb)
|
|
51
67
|
*/
|
|
52
68
|
fileExt: TSupportedFileExtension;
|
|
69
|
+
/**
|
|
70
|
+
* Toolbar visibility options
|
|
71
|
+
* Controls which toolbar buttons and controls are displayed
|
|
72
|
+
*/
|
|
73
|
+
toolbarOptions?: IToolbarOptions;
|
|
53
74
|
/**
|
|
54
75
|
* Callback to receive viewer instance when initialized
|
|
55
76
|
*/
|
|
@@ -69,6 +90,7 @@ declare module '@dtducas/wh-forge-viewer' {
|
|
|
69
90
|
* <ViewerForgePDF
|
|
70
91
|
* filePath="https://example.com/document.pdf"
|
|
71
92
|
* fileExt="pdf"
|
|
93
|
+
* toolbarOptions={{ showDownload: true, showDocBrowser: true }}
|
|
72
94
|
* setViewer={setViewer}
|
|
73
95
|
* />
|
|
74
96
|
* );
|