|
| 1 | +# CDI Previewer - Bundle Integration |
| 2 | + |
| 3 | +## Changes Made (November 2025) |
| 4 | + |
| 5 | +### ✅ Migrated to Single Bundle Architecture |
| 6 | + |
| 7 | +**What changed:** |
| 8 | +- Replaced 10+ individual JavaScript files with a single optimized bundle |
| 9 | +- Updated to use custom shacl-engine with SPARQL target support |
| 10 | +- Simplified HTML file to use single script tag |
| 11 | + |
| 12 | +### 📦 New Files |
| 13 | + |
| 14 | +1. **`lib/cdi-viewer.bundle.min.js`** (1.2 MB) |
| 15 | + - Complete CDI viewer application |
| 16 | + - Includes: N3.js, JSON-LD library, shacl-engine (with SPARQL targets) |
| 17 | + - Minified and optimized for production |
| 18 | + - Expects jQuery and Bootstrap to be loaded externally |
| 19 | + |
| 20 | +2. **`shapes/cdif-core.ttl`** (Updated) |
| 21 | + - CDIF Discovery shapes with SPARQL target support |
| 22 | + - Validates only root-level datasets (not nested ones) |
| 23 | + - Uses `sh:SPARQLTarget` for advanced node selection |
| 24 | + |
| 25 | +3. **`css/cdi-preview.css`** (Updated) |
| 26 | + - Latest styling for the viewer |
| 27 | + |
| 28 | +4. **`test-cdi-bundle.html`** |
| 29 | + - Test page to verify bundle loads correctly |
| 30 | + - Can test with example CDI files |
| 31 | + |
| 32 | +### 🗑️ Removed Files |
| 33 | + |
| 34 | +- `js/cdi-preview/` folder (10 files) - now bundled |
| 35 | +- `lib/rdf-validate-shacl.bundle.min.js` - replaced with shacl-engine |
| 36 | + |
| 37 | +### 📝 Modified Files |
| 38 | + |
| 39 | +- **`CdiPreview.html`** |
| 40 | + - Removed individual script tags |
| 41 | + - Added single `<script src="lib/cdi-viewer.bundle.min.js"></script>` |
| 42 | + - Removed external CDN links for N3.js and JSON-LD (now bundled) |
| 43 | + |
| 44 | +## How to Update the Bundle |
| 45 | + |
| 46 | +When the cdi-viewer source is updated: |
| 47 | + |
| 48 | +```bash |
| 49 | +# Build in cdi-viewer project |
| 50 | +cd /path/to/cdi-viewer |
| 51 | +npm run build |
| 52 | + |
| 53 | +# Copy to dataverse-previewers |
| 54 | +cp dist/cdi-viewer.bundle.js /path/to/dataverse-previewers/previewers/betatest/lib/cdi-viewer.bundle.min.js |
| 55 | + |
| 56 | +# Copy updated shapes if changed |
| 57 | +cp shapes/cdif-core.ttl /path/to/dataverse-previewers/previewers/betatest/shapes/cdif-core.ttl |
| 58 | + |
| 59 | +# Copy CSS if changed |
| 60 | +cp css/cdi-preview.css /path/to/dataverse-previewers/previewers/betatest/css/cdi-preview.css |
| 61 | +``` |
| 62 | + |
| 63 | +## Testing |
| 64 | + |
| 65 | +1. **Test page:** Open `test-cdi-bundle.html` in a browser |
| 66 | +2. **Full previewer:** Open `CdiPreview.html` with a CDI JSON-LD file |
| 67 | +3. **With Dataverse:** Test with `?fileUrl=...` or `?fileid=...&siteUrl=...` parameters |
| 68 | + |
| 69 | +## Key Features Now Available |
| 70 | + |
| 71 | +✅ **SPARQL Target Support** - Validates only root datasets using SPARQL queries |
| 72 | +✅ **Property Recognition** - Blue badges for SHACL-defined properties |
| 73 | +✅ **Faster Loading** - Single bundle, fewer HTTP requests |
| 74 | +✅ **Offline Capable** - No external CDN dependencies for core functionality |
| 75 | +✅ **Easier Deployment** - Just copy one bundle file |
| 76 | + |
| 77 | +## Bundle Contents |
| 78 | + |
| 79 | +The `cdi-viewer.bundle.min.js` includes: |
| 80 | + |
| 81 | +- **JSON-LD processor** - For expanding/compacting JSON-LD |
| 82 | +- **N3.js parser** - For parsing Turtle SHACL shapes |
| 83 | +- **shacl-engine** - Modified version with SPARQL target support |
| 84 | +- **All viewer modules** - Validation, rendering, editing, suggestions |
| 85 | +- **RDF utilities** - Dataset manipulation, term handling |
| 86 | + |
| 87 | +**External dependencies (not bundled):** |
| 88 | +- jQuery 3.6.0 |
| 89 | +- Bootstrap 3.3.7 |
| 90 | + |
| 91 | +These must be loaded before the bundle. |
| 92 | + |
| 93 | +## Size Comparison |
| 94 | + |
| 95 | +**Before:** |
| 96 | +- 10 individual JS files: ~200 KB (uncompressed) |
| 97 | +- External CDN dependencies: ~300 KB (N3.js + JSON-LD) |
| 98 | +- rdf-validate-shacl: ~800 KB |
| 99 | +- **Total:** ~1.3 MB + HTTP overhead (12 requests) |
| 100 | + |
| 101 | +**After:** |
| 102 | +- 1 bundle: 1.2 MB |
| 103 | +- **Total:** 1.2 MB (1 request) |
| 104 | + |
| 105 | +**Benefits:** |
| 106 | +- Fewer HTTP requests → faster loading |
| 107 | +- No CDN dependencies → works offline |
| 108 | +- All code versioned together → easier updates |
| 109 | + |
| 110 | +## Troubleshooting |
| 111 | + |
| 112 | +### Bundle doesn't load |
| 113 | +- Check browser console for errors |
| 114 | +- Verify jQuery and Bootstrap are loaded first |
| 115 | +- Check file path is correct: `lib/cdi-viewer.bundle.min.js` |
| 116 | + |
| 117 | +### Validation doesn't work |
| 118 | +- Check if SHACL shapes file exists: `shapes/cdif-core.ttl` |
| 119 | +- Verify network requests show shapes loading successfully |
| 120 | +- Check console for SPARQL target execution logs |
| 121 | + |
| 122 | +### Properties show as "EXTRA" instead of "SHACL-defined" |
| 123 | +- Verify namespace in JSON-LD matches shapes (http:// not https://) |
| 124 | +- Check if shape has `sh:targetClass` or `sh:target` for the node type |
| 125 | +- Enable debug logging to see shape matching details |
0 commit comments